Merge pull request 'feat(voice): meaningful leftover speech fills the note' (#126) from feat/voice/leftover-comment into master
All checks were successful
Registry — build, push, deploy / build-and-push (push) Successful in 9m31s
Registry — build, push, deploy / deploy (push) Successful in 59s

Reviewed-on: #126
Reviewed-by: admin <admin@localhost>
This commit was merged in pull request #126.
This commit is contained in:
2026-11-11 13:26:44 +03:30
10 changed files with 105 additions and 714 deletions

View File

@@ -10,26 +10,25 @@ const LOCALE_NOTES: Record<string, string> = {
'"شش بالا راست" = upper right six -> arch "upper", side "patient_right", position 6.', '"شش بالا راست" = upper right six -> arch "upper", side "patient_right", position 6.',
'A jaw is spoken as "فک بالا" (upper jaw) or "فک پایین" (lower jaw), sometimes just', 'A jaw is spoken as "فک بالا" (upper jaw) or "فک پایین" (lower jaw), sometimes just',
'"بالا"/"پایین" in context, or "هر دو فک" (both jaws).', '"بالا"/"پایین" in context, or "هر دو فک" (both jaws).',
'A note is asked for with "بنویس", "بنویس که", "یادداشت کن", "این را یادداشت کن",', 'Speech that fits no field is the note — "بیمار دیابتیه" is a note. Asking words',
'or by naming the field the words go into: "یادداشت", "یادداشت‌ها", "توضیحات",', 'like "بنویس", "بنویس که", "یادداشت کن", "توی توضیحات بنویس" introduce a note; keep',
'"کامنت", "کامنت‌ها" — as in "توی یادداشت‌ها بنویس", "در توضیحات بنویس",', 'them out of its text. Greetings and thanks ("سلام", "مرسی") are filler, not notes.',
'"یادداشت: ...". Anything else the clinician says is not a note.',
].join(' '), ].join(' '),
nl: [ nl: [
'The clinician is speaking Dutch, where FDI is standard. "zesentwintig" and "26" are', 'The clinician is speaking Dutch, where FDI is standard. "zesentwintig" and "26" are',
'tooth 26. The descriptive form is "rechtsboven zes" = upper right six. A jaw is', 'tooth 26. The descriptive form is "rechtsboven zes" = upper right six. A jaw is',
'"bovenkaak" (upper) or "onderkaak" (lower), or "beide kaken" (both).', '"bovenkaak" (upper) or "onderkaak" (lower), or "beide kaken" (both).',
'A note is asked for with "schrijf op", "noteer", "zet in de notities", or by naming', 'Speech that fits no field is the note. Asking words like "schrijf op", "noteer",',
'the field the words go into ("notitie", "notities", "opmerkingen"). Anything else', '"zet in de notities" introduce a note; keep them out of its text. Greetings and',
'the clinician says is not a note.', 'thanks are filler, not notes.',
].join(' '), ].join(' '),
en: [ en: [
'The clinician is speaking English and uses FDI. "twenty-six", "two six" and "26" are', 'The clinician is speaking English and uses FDI. "twenty-six", "two six" and "26" are',
'all tooth 26. The descriptive form is "upper right six". A jaw is "upper jaw"/"lower', 'all tooth 26. The descriptive form is "upper right six". A jaw is "upper jaw"/"lower',
'jaw", or "both jaws".', 'jaw", or "both jaws".',
'A note is asked for with "write this in the notes", "note that", "add a note",', 'Speech that fits no field is the note. Asking words like "write this in the notes",',
'"put in the comments", or by naming the field the words go into ("note", "notes",', '"note that", "put in the comments" introduce a note; keep them out of its text.',
'"comments", "remarks"). Anything else the clinician says is not a note.', 'Greetings and thanks are filler, not notes.',
].join(' '), ].join(' '),
}; };
@@ -120,9 +119,11 @@ export function buildExtractionPrompt(
' one is not.', ' one is not.',
'6. A whole jaw is not a tooth. Never put a jaw in the "teeth" list. A jaw appears only', '6. A whole jaw is not a tooth. Never put a jaw in the "teeth" list. A jaw appears only',
' as a prosthesis[].targets entry with "arch" set and "position" null.', ' as a prosthesis[].targets entry with "arch" set and "position" null.',
'7. Never decide something is a note. Fill "comment" only when the clinician asked for', '7. "comment" holds the meaningful speech that fits no other field — observations,',
' one, and report the words they used in "commentTrigger". Speech you cannot place in', ' patient context, anything worth keeping that is not a treatmentType, tooth,',
' a field is simply not reported — it is never a note.', ' prosthesis, lab or deadline. Filler and small talk (greetings, thanks, "ok") are',
' dropped entirely, never noted. When the clinician asked for a note, keep the asking',
' words out of its text.',
'8. pontic is a per-tooth role, never a material and never a jaw. Never stack pontic with', '8. pontic is a per-tooth role, never a material and never a jaw. Never stack pontic with',
' another type on the same tooth. Put "pontic" in types[] only when the clinician said', ' another type on the same tooth. Put "pontic" in types[] only when the clinician said',
' pontic / pontic / پونتیک. Do not invent pontics on unnamed teeth between crowns in a', ' pontic / pontic / پونتیک. Do not invent pontics on unnamed teeth between crowns in a',
@@ -182,19 +183,16 @@ export function buildExtractionPrompt(
'', '',
'OTHER FIELDS', 'OTHER FIELDS',
'- connectedSpans: only for bridges or splinted units. Endpoints inclusive.', '- connectedSpans: only for bridges or splinted units. Endpoints inclusive.',
'- comment + commentTrigger: a note is written ONLY when the clinician asked for one.', '- comment: the meaningful speech that fits no other field, in the spoken language —',
' "commentTrigger" is the exact words that asked, copied from the transcript. "comment"', ' observations, patient context, anything worth keeping. Filler and small talk are',
' is what they then dictated, WITHOUT those words: for "بنویس که بیمار حساسیت به سرما', ' dropped entirely: "مرسی", "سلام چطوری" produce no note. When the clinician asked',
' دارد", commentTrigger is "بنویس که" and comment is "بیمار حساسیت به سرما دارد".', ' for a note, the asking words stay out of its text: for "بنویس که بیمار حساسیت به',
' If nobody asked, BOTH are null. Never sweep up leftover speech, filler, small talk or', ' سرما دارد", comment is "بیمار حساسیت به سرما دارد".',
' a diagnosis nobody asked you to record. A comment without a trigger is discarded, so', ' WHERE THE NOTE ENDS: a clause you also reported in another field — a lab, a tooth,',
' guessing costs the clinician the note.', ' a prosthesis, a deadline — is that instruction, so it never belongs in "comment" as',
' WHERE THE NOTE ENDS: the dictated words end where the next instruction begins. Any', ' well. Nothing may appear in two fields. Example: "توی توضیحات بنویس رنگ دندون A2',
' clause you also reported in another field — a lab, a tooth, a prosthesis, a deadline —', ' هست و بفرست برای لابراتوآر سانشاین" -> comment "رنگ دندون A2 هست", and the lab',
' is that instruction, so it never belongs in "comment" as well. Nothing may appear in', ' goes to labId. "و بفرست برای لابراتوآر سانشاین" is an instruction, not the note.',
' two fields. Example: "توی توضیحات بنویس سلام چطوری و بفرست برای لابراتوآر سانشاین" ->',
' commentTrigger "توی توضیحات بنویس", comment "سلام چطوری", and the lab goes to labId.',
' "و بفرست برای لابراتوآر سانشاین" is an instruction, not part of the note.',
'- labMatchExact: true only when the spoken name matched a lab name exactly.', '- labMatchExact: true only when the spoken name matched a lab name exactly.',
].join('\n'); ].join('\n');

View File

@@ -526,7 +526,6 @@ describe('resolveVoiceIntent', () => {
teeth: [tooth('14'), tooth('15')], teeth: [tooth('14'), tooth('15')],
connectedSpans: [], connectedSpans: [],
comment: ' حساسیت به سرما ', comment: ' حساسیت به سرما ',
commentTrigger: 'بنویس که',
prosthesis: [], prosthesis: [],
labId: null, labId: null,
labMatchExact: false, labMatchExact: false,
@@ -701,40 +700,24 @@ describe('resolveVoiceIntent', () => {
); );
}); });
it('drops a note the clinician never asked for', () => { it('keeps leftover speech as a note, with no asking words required', () => {
// The whole point: leftover speech the model decided was a note is discarded. Before this // Decision 55: the note is the meaningful speech that fits no other field. The old
// rule the prompt told it to sweep up "the parts already captured" as a comment. // gate discarded a comment with no commentTrigger; this test fails if it returns.
const result = resolveVoiceIntent( const result = resolveVoiceIntent(
{ ...base, comment: 'بیمار عصبی بود', commentTrigger: null }, { ...base, comment: 'بیمار عصبی بود' },
CTX, CTX,
); );
expect(result.comment).toBeNull(); expect(result.comment).toBe('بیمار عصبی بود');
}); });
it('drops a note whose trigger is only whitespace', () => { it('keeps a note trimmed', () => {
const result = resolveVoiceIntent( const result = resolveVoiceIntent(
{ ...base, comment: 'بیمار عصبی بود', commentTrigger: ' ' }, { ...base, comment: ' حساسیت به سرما ' },
CTX,
);
expect(result.comment).toBeNull();
});
it('keeps a note that was asked for, trimmed', () => {
const result = resolveVoiceIntent(
{ ...base, comment: ' حساسیت به سرما ', commentTrigger: 'بنویس که' },
CTX, CTX,
); );
expect(result.comment).toBe('حساسیت به سرما'); expect(result.comment).toBe('حساسیت به سرما');
}); });
it('reports no note when the trigger was heard but nothing followed it', () => {
const result = resolveVoiceIntent(
{ ...base, comment: ' ', commentTrigger: 'بنویس که' },
CTX,
);
expect(result.comment).toBeNull();
});
it('resolves a due date through the same context', () => { it('resolves a due date through the same context', () => {
const result = resolveVoiceIntent( const result = resolveVoiceIntent(
{ ...base, due: { kind: 'weekday', weekday: 'thursday', which: 'this' } }, { ...base, due: { kind: 'weekday', weekday: 'thursday', which: 'this' } },

View File

@@ -545,15 +545,11 @@ export function resolveVoiceIntent(
const due = resolveDueDate(intent?.due, ctx.todayIso, ctx.weekStartJs); const due = resolveDueDate(intent?.due, ctx.todayIso, ctx.weekStartJs);
if (due.unresolved) unresolved.push(due.unresolved); if (due.unresolved) unresolved.push(due.unresolved);
// A note is written only when the clinician asked for one. The model reports the words that // The note is the meaningful speech that fits no other field (decision 55). What counts
// asked ("بنویس که", "write this in the notes"); without them, whatever it put in `comment` // as filler, where the note ends, and stripping the asking words are prompt rules; the
// is leftover speech it decided was a note, and it is dropped. Matching the phrase itself // resolver only trims, and an empty note resolves to null.
// stays in the prompt, so this check needs no per-locale vocabulary.
const commentAsked =
typeof intent?.commentTrigger === 'string' &&
intent.commentTrigger.trim().length > 0;
const comment = const comment =
commentAsked && typeof intent?.comment === 'string' && intent.comment.trim() typeof intent?.comment === 'string' && intent.comment.trim()
? intent.comment.trim() ? intent.comment.trim()
: null; : null;

View File

@@ -23,7 +23,6 @@ const wire = (overrides: Partial<WireVoiceIntent> = {}): WireVoiceIntent => ({
teeth: [], teeth: [],
connectedSpans: [], connectedSpans: [],
comment: null, comment: null,
commentTrigger: null,
prosthesis: [], prosthesis: [],
labId: null, labId: null,
labMatchExact: false, labMatchExact: false,

View File

@@ -50,7 +50,6 @@ export type WireVoiceIntent = {
teeth: WireToothIntent[]; teeth: WireToothIntent[];
connectedSpans: { from: WireToothIntent; to: WireToothIntent }[]; connectedSpans: { from: WireToothIntent; to: WireToothIntent }[];
comment: string | null; comment: string | null;
commentTrigger: string | null;
prosthesis: WireProsthesisAssignment[]; prosthesis: WireProsthesisAssignment[];
labId: string | null; labId: string | null;
labMatchExact: boolean; labMatchExact: boolean;
@@ -126,7 +125,6 @@ export const VOICE_INTENT_JSON_SCHEMA = {
'teeth', 'teeth',
'connectedSpans', 'connectedSpans',
'comment', 'comment',
'commentTrigger',
'prosthesis', 'prosthesis',
'labId', 'labId',
'labMatchExact', 'labMatchExact',
@@ -157,19 +155,12 @@ export const VOICE_INTENT_JSON_SCHEMA = {
comment: { comment: {
type: ['string', 'null'], type: ['string', 'null'],
description: description:
'The note the clinician explicitly dictated, in the spoken language, WITHOUT the ' + 'The meaningful speech that fits no other field, in the spoken language — ' +
'words that asked for it. Null unless they actually asked for a note. Never put ' + 'observations, patient context, anything worth keeping. Never filler: greetings, ' +
'leftover speech here. It ends where the next instruction begins: a clause you ' + 'thanks and "ok" are dropped entirely, not noted. When the clinician asked for a ' +
'also reported as a lab, a tooth, a prosthesis or a deadline is that instruction, ' + 'note, the asking words stay out of this text. It ends where the next instruction ' +
'and must not appear here too.', 'begins: a clause you also reported as a lab, a tooth, a prosthesis or a deadline ' +
}, 'is that instruction, and must not appear here too.',
commentTrigger: {
type: ['string', 'null'],
description:
'The exact words that asked for a note, copied from the transcript (e.g. ' +
'"بنویس که", "توی یادداشت‌ها بنویس", "write this in the notes"). Naming the field ' +
'itself counts as asking ("یادداشت", "توضیحات", "notes", "comments"). Null when ' +
'nobody asked. A comment with no trigger is discarded.',
}, },
prosthesis: { prosthesis: {
type: 'array', type: 'array',
@@ -313,7 +304,6 @@ export function toVoiceIntent(wire: WireVoiceIntent): VoiceIntent {
teeth: teeth.map(toToothIntent), teeth: teeth.map(toToothIntent),
connectedSpans, connectedSpans,
comment: wire?.comment ?? null, comment: wire?.comment ?? null,
commentTrigger: wire?.commentTrigger ?? null,
prosthesis: assignments.map(toProsthesisAssignment), prosthesis: assignments.map(toProsthesisAssignment),
labId: wire?.labId ?? null, labId: wire?.labId ?? null,
labMatchExact: wire?.labMatchExact === true, labMatchExact: wire?.labMatchExact === true,

View File

@@ -27,7 +27,6 @@ const EMPTY_INTENT = {
teeth: [], teeth: [],
connectedSpans: [], connectedSpans: [],
comment: null, comment: null,
commentTrigger: null,
prosthesis: [], prosthesis: [],
labId: null, labId: null,
labMatchExact: false, labMatchExact: false,

View File

@@ -65,13 +65,11 @@ export type VoiceIntent = {
treatmentType: string | null; treatmentType: string | null;
teeth: ToothIntent[]; teeth: ToothIntent[];
connectedSpans: ConnectedSpanIntent[]; connectedSpans: ConnectedSpanIntent[];
comment: string | null;
/** /**
* The exact spoken words that asked for a note — "بنویس که", "write this in the notes". * The meaningful speech that fits no other field — the resolver only trims it. What
* Null when nothing asked. The resolver keeps `comment` only when this is present, so the * counts as filler and where the note ends are prompt rules (decision 55).
* model cannot decide on its own that leftover speech was a note.
*/ */
commentTrigger: string | null; comment: string | null;
/** Empty array, never null. */ /** Empty array, never null. */
prosthesis: ProsthesisAssignment[]; prosthesis: ProsthesisAssignment[];
/** Must be one of the linked-lab ids supplied in the prompt, or null. */ /** Must be one of the linked-lab ids supplied in the prompt, or null. */

View File

@@ -16,8 +16,9 @@ aliases: [voice lab case, lab dictation, case line voice, lab mic]
# Voice entry for a lab case line # Voice entry for a lab case line
**Area:** Cases tab (LAB orgs) — `CaseCreatePanel` **Area:** Cases tab (LAB orgs) — `CaseCreatePanel`
**Created:** 2026-09-16 **Created:** 2026-09-16 · **Revised:** 2026-11-10 (decision 16 — the note rule changed
**Depends on:** [`voice-treatment-entry`](voice-treatment-entry/spec.md), already merged underneath this spec)
**Depends on:** [`voice-treatment-entry`](voice-treatment-entry.md), already merged
to `master`. Every resolver, the prompt, the review sheet and the stack rules come from to `master`. Every resolver, the prompt, the review sheet and the stack rules come from
there unchanged. This spec records only what differs. there unchanged. This spec records only what differs.
@@ -289,7 +290,10 @@ Nothing changes. The transcript never leaves the server and is logged there at i
(`voice-treatment-entry` §10). `logTelemetry` stays patient-free. (`voice-treatment-entry` §10). `logTelemetry` stays patient-free.
The lab side does not weaken that: no extracted field carries a name, because the header is The lab side does not weaken that: no extracted field carries a name, because the header is
out of scope (§1) and the catalog is narrowed (§4). out of scope (§1) and the catalog is narrowed (§4). One exception, added 2026-11-10: since
the note became leftover speech (decision 55 in `voice-treatment-entry`), a dictated phrase
that mentions a person can reach `line.comment`. The review sheet shows the note before
apply, so the clinician can untick it.
--- ---
@@ -376,3 +380,4 @@ Recorded so the first manual pass does not read them as bugs.
| 13 | `narrowCatalogForOrgType` is extracted and unit tested | `voice.service` has never been unit tested; this is the one decision in it worth pinning (§4, §10) | | 13 | `narrowCatalogForOrgType` is extracted and unit tested | `voice.service` has never been unit tested; this is the one decision in it worth pinning (§4, §10) |
| 14 | No new i18n keys | Every voice string is under `treatment.*`, and `CaseCreatePanel` already holds that namespace (§3) | | 14 | No new i18n keys | Every voice string is under `treatment.*`, and `CaseCreatePanel` already holds that namespace (§3) |
| 15 | `PERMISSION_EDIT_CASES` is added rather than reusing `PERMISSION_ACCESS_CASES` | The check is on an edit permission; "no access to cases" is false for a `TAB_CASES_READ` holder and points them at the wrong setting (§5) | | 15 | `PERMISSION_EDIT_CASES` is added rather than reusing `PERMISSION_ACCESS_CASES` | The check is on an edit permission; "no access to cases" is false for a `TAB_CASES_READ` holder and points them at the wrong setting (§5) |
| 16 | The line comment inherits the leftover-speech note rule (`voice-treatment-entry` decision 55) | The prompt and resolver are shared, so `line.comment` now holds meaningful phrases that fit no field; a dictated phrase naming a person can reach it, and the sheet previews the note before apply (§8) |

View File

@@ -10,6 +10,13 @@ repos:
role: extraction contract + resolvers + review sheet role: extraction contract + resolvers + review sheet
spec_slug: voice-treatment-entry spec_slug: voice-treatment-entry
merge_after: [] merge_after: []
- repo: dyolink
path: ~/PersonalProjects/dyolink
branch: feat/voice/leftover-comment
base: origin/master
role: the note becomes meaningful leftover speech (decision 55)
spec_slug: voice-treatment-entry
merge_after: []
aliases: [voice treatment entry, voice input, dictation, mic] aliases: [voice treatment entry, voice input, dictation, mic]
--- ---
@@ -17,14 +24,17 @@ aliases: [voice treatment entry, voice input, dictation, mic]
**Status:** v1 is merged to `master` (`c07f550`…`dc10d8d`). The treatment form was then **Status:** v1 is merged to `master` (`c07f550`…`dc10d8d`). The treatment form was then
overhauled on top of it (`a3c14a1`, `7f92e73`, `72f885d`, `5d3597f`): one prosthesis type overhauled on top of it (`a3c14a1`, `7f92e73`, `72f885d`, `5d3597f`): one prosthesis type
per tooth became **stacked jobs**, **jaw-level appliances** and a **category tree**. Voice per tooth became **stacked jobs**, **jaw-level appliances** and a **category tree**. The
still compiles against that model but can no longer express it, and in two places now revision adapting the extraction contract (§5), the resolvers (§6) and the review sheet
writes data the form itself refuses. This revision adapts the extraction contract (§5), (§7) to that model — decisions 34–50, plus two recording defects found on Safari (§2, §9) —
the resolvers (§6) and the review sheet (§7), and carries two recording defects found on is merged to `master` as well.
Safari (§2, §9). A second revision (2026-11-10, `feat/voice/leftover-comment`) reverses decision 54: the
note is now the **meaningful speech that fits no other field** (decision 55, §5) — filler
is dropped, asking words are stripped, `commentTrigger` is removed from the contract, and
the review sheet is the remaining junk filter.
Still blocked on the ASR spike (§11 item 1) before it is trustworthy in front of patients Still blocked on the ASR spike (§11 item 1) before it is trustworthy in front of patients
**Area:** Treatment workspace (CLINIC orgs) **Area:** Treatment workspace (CLINIC orgs)
**Created:** 2026-08-20 · **Revised:** 2026-09-07 **Created:** 2026-08-20 · **Revised:** 2026-09-07, 2026-11-10
Fill a `TreatmentDetail` — including its lab dispatch — by speaking, instead of by Fill a `TreatmentDetail` — including its lab dispatch — by speaking, instead of by
tapping through the type dropdown, the FDI chart, the prosthesis job popover and the lab tapping through the type dropdown, the FDI chart, the prosthesis job popover and the lab
@@ -48,7 +58,7 @@ One recording produces **exactly one** `TreatmentDetail`, and may fill every fie
| `treatmentType` | catalog code, matched against locale labels | | `treatmentType` | catalog code, matched against locale labels |
| `teeth` | FDI codes, via tooth-intent resolver | | `teeth` | FDI codes, via tooth-intent resolver |
| `toothSelectionGroups` | connected (bridge) / single spans | | `toothSelectionGroups` | connected (bridge) / single spans |
| `comment` | cleaned dictated notes | | `comment` | meaningful leftover speech — filler dropped, asking words stripped |
| lab: `LabCaseToothProsthesis` rows | one assignment list — a target is a tooth **or a jaw**, and carries a **stack** of job codes | | lab: `LabCaseToothProsthesis` rows | one assignment list — a target is a tooth **or a jaw**, and carries a **stack** of job codes |
| lab: `destinationOrganizationId` | matched against the clinic's linked labs | | lab: `destinationOrganizationId` | matched against the clinic's linked labs |
| lab: `dueDate` | via due-date intent resolver | | lab: `dueDate` | via due-date intent resolver |
@@ -411,8 +421,7 @@ type VoiceIntent = {
treatmentType: string | null; // catalog code, from the supplied closed list treatmentType: string | null; // catalog code, from the supplied closed list
teeth: ToothIntent[]; teeth: ToothIntent[];
connectedSpans: { from: ToothIntent; to: ToothIntent }[]; connectedSpans: { from: ToothIntent; to: ToothIntent }[];
comment: string | null; // only when asked for — see below comment: string | null; // meaningful leftover speech, trimmed by the resolver
commentTrigger: string | null; // the words that asked; null discards the comment
prosthesis: ProsthesisAssignment[]; // empty array, never null prosthesis: ProsthesisAssignment[]; // empty array, never null
labId: string | null; // must be one of the supplied linked-lab ids labId: string | null; // must be one of the supplied linked-lab ids
labMatchExact: boolean; labMatchExact: boolean;
@@ -518,38 +527,39 @@ The `sub_*` key set is wider than the subcategory set — it also carries techni
> the print layout, none of which this task otherwise opens. The seed is written from the message > the print layout, none of which this task otherwise opens. The seed is written from the message
> files precisely so the two agree at the point they diverge. > files precisely so the two agree at the point they diverge.
### A note is written only when the clinician asks for one ### A note is the meaningful speech that fits no other field
The model does not decide that something was a note. It reports the exact words that asked — **Revised 2026-11-10 (decision 55), superseding decision 54.** The model now puts leftover
«بنویس که», "write this in the notes" — in `commentTrigger`, and `comment` holds what was speech into `comment`: any phrase that is not a treatment type, tooth, prosthesis, lab or
dictated after them, without the asking words. The resolver keeps `comment` only when a trigger deadline, and is worth keeping — «بیمار دیابتیه» after a restoration dictation becomes a
is present, so the rule is enforced by code rather than trusted to the prompt. note. `commentTrigger` is removed from the contract; nothing consumed it once the gate was
gone.
The instruction this replaces said "clinical notes, in the language spoken. Omit the parts Decision 54 required the clinician to ask for the note («بنویس که», "write this in the
already captured as treatment type, teeth, prosthesis work or deadline" — which told the model to notes") and enforced it in the resolver: a comment with no trigger was discarded. That
sweep up whatever was left over. Filler, small talk and an unrequested diagnosis all became a replaced an earlier leftover-sweep rule under which filler, small talk and unrequested
persisted clinical note, and `comment` is the one durable trace of a recording (§10). diagnoses became persisted clinical notes. This revision takes the sweep back, with two
constraints, and moves the judgment back to the prompt:
Speech that fits no field and was not asked to be a note is simply not reported. The sheet shows - **Filler is dropped, not noted.** Greetings, thanks and small talk («سلام چطوری», «مرسی»)
what was captured, so nothing is hidden by leaving it out. are not a note. Deciding what is filler is a prompt rule with no code enforcement — the
accepted trade of this revision.
- **Asking words are still stripped.** When the clinician did ask («توی توضیحات بنویس …»),
the asking words stay out of the note text. The per-locale asking vocabulary remains in
the prompt's locale notes in this reduced role.
Per-locale trigger vocabulary lives in the prompt's locale notes, exactly like the tooth The resolver no longer gates the comment; it trims it, and an empty note resolves to null.
vocabulary. The resolver only checks that a trigger was reported, so it needs no per-locale The review sheet is the remaining filter: the note row is ticked by default and the
knowledge and stays locale-neutral by construction (§6). The vocabulary covers two shapes: a clinician can untick it before apply, so junk costs a tap, not a record.
verb that asks («بنویس که», "noteer") and the *name of the field* the words go into («یادداشت»,
«یادداشت‌ها», «توضیحات», "notes", "comments"). Naming the field is how a clinician usually asks,
and the first version listed only the verbs, so «توی یادداشت‌ها بنویس» produced no trigger and
the note was discarded.
Where the dictated note ends is a second question, and the model answered it inconsistently: for Where the dictated note ends keeps its 2026-09-11 rule: the note ends where the next
«توی توضیحات بنویس سلام چطوری و بفرست برای لابراتوآر سانشاین» the note sometimes ran to the end instruction begins, stated as a no-overlap invariant — a clause reported as a lab, a tooth,
of the sentence and swallowed the lab dispatch. The rule is that the note ends where the next a prosthesis or a deadline is that instruction and must not also appear in `comment`. It
instruction begins, stated as a no-overlap invariant: a clause reported as a lab, a tooth, a lives in both the prompt and the JSON-schema field description, because the schema
prosthesis or a deadline is that instruction and must not also appear in `comment`. It lives in description is what the model reads while it fills the field. This is a prompt-side rule
both the prompt and the JSON-schema field description, because the schema description is what the with no code enforcement — stripping an already-extracted clause out of the note text by
model reads while it fills the field. This is a prompt-side rule with no code enforcement — string matching would be guesswork on free speech, and the review sheet shows the note
stripping an already-extracted clause out of the note text by string matching would be guesswork before it is saved.
on free speech, and the review sheet shows the note before it is saved.
### Prosthesis work implies the treatment type ### Prosthesis work implies the treatment type
@@ -1213,4 +1223,10 @@ Notes made explicit on 2026-09-10.
| # | Question | Decision | | # | Question | Decision |
|---|---|---| |---|---|---|
| 54 | What becomes a note | Only what the clinician explicitly asked to be written. The model reports the asking words in `commentTrigger`; the resolver discards `comment` without one, so a prompt drift cannot quietly persist unrequested speech as a clinical note (§5) | | 54 | What becomes a note | Only what the clinician explicitly asked to be written. The model reports the asking words in `commentTrigger`; the resolver discards `comment` without one, so a prompt drift cannot quietly persist unrequested speech as a clinical note (§5). **Superseded by 55** |
Notes revised on 2026-11-10.
| # | Question | Decision |
|---|----------|----------|
| 55 | What becomes a note | The meaningful speech that fits no other field (decision 54 reversed at Amin's request). Filler and small talk are dropped, asking words are stripped, the no-overlap rule stays, and `commentTrigger` is removed from the contract. All three rules are prompt-side now — the resolver only trims, and the review sheet is the remaining filter (§5) |

View File

@@ -1,593 +0,0 @@
---
type: task-progress
status: active
repos:
- repo: dyolink
path: ~/PersonalProjects/dyolink
branch: feat/treatment/add-voice-input-for-new-treatment-form
base: origin/master
role: extraction contract + resolvers + review sheet
spec_slug: voice-treatment-entry
merge_after: []
---
# PROGRESS — Voice Treatment Entry
Spec: [spec.md](./spec.md)
Adapting the merged voice feature to the overhauled prosthesis model (spec §5–§7,
decisions 34–46). v1 shipped on `master`; this branch revises it.
Status legend: ⬜ not started · 🟡 in progress · ✅ done · ⛔ blocked
| # | Work item | Repo | Status | Notes / refs |
|---|-----------|------|--------|--------------|
| 1 | `pickRecordingMimeType` falls back to the empty hint instead of `null` | `dyolink` | ✅ | §9. `frontend/src/lib/voice/audioFormat.ts` — the final `return null` after the loop is now `return ''` |
| 2 | `voiceForEditor` also checks `isMediaRecorderSupported()` | `dyolink` | ✅ | §2 render policy, `TreatmentWorkspace.tsx` |
| 3 | Add Vitest for the frontend's pure helpers; update `CLAUDE.md` | `dyolink` | ✅ | §12. `vitest@3.2.7`, `frontend/vitest.config.ts`, `npm run test` script; `CLAUDE.md` Tests section rewritten |
| 4 | `buildCatalog` passes `category` / `subcategory` / `chartRegion` / `stackGroup` through | `dyolink` | ✅ | §5. `voice.service.ts` now forwards the full `ProsthesisTypeCatalogEntry[]` plus category/subcategory lists |
| 5 | Wire schema: `prosthesisAssignments`, `arch: 'both'`; drop default + overrides | `dyolink` | ✅ | §5, `extraction.wire.ts` — `prosthesis: WireProsthesisAssignment[]` |
| 6 | Resolver: assignments, arch derivation, leaf-vs-category classification | `dyolink` | ✅ | §5, §6, `extraction.resolver.ts` — `resolveProsthesisAssignment`, `resolveAssignmentTarget`, `classifyTypeCode` |
| 7 | Resolver: new unresolved reasons; retire `tooth_not_selected` | `dyolink` | ✅ | §6 reason table — `voice.types.ts` |
| 8 | Resolver: a resolved assignment forces `treatmentType` to `prosthesis` | `dyolink` | ✅ | §5. `resolveVoiceIntent` — `hasResolvedAssignment` |
| 9 | Prompt: present the catalog as a tree; teach stacks and jaw-level codes | `dyolink` | ✅ | §5, `extraction.prompt.ts` — `prosthesisTree()` renders CATEGORY/SUBCATEGORY/leaf from data, no hardcoded catalog knowledge |
| 10 | Backend Jest suites for items 6–8, including the namespace-disjointness assertion | `dyolink` | ✅ | §12. `extraction.resolver.spec.ts` — disjointness test reads `catalog-seed-data.ts`'s live `PROSTHESIS_TYPES`, not a written count |
| 11 | Frontend types follow the new `ResolvedExtraction` | `dyolink` | ✅ | `types/voice.ts` — `VoiceProsthesisAssignment[]`, `assignmentIndex` |
| 12 | `voiceReviewRows`: merged row, chip folding, retire `complete` as a blocker | `dyolink` | ✅ | §6, §7 — `prosthesisTargetLines`, `joblessProsthesisTargets`, `withChosenArch`/`withChosenProsthesisLeaf` |
| 13 | `VoiceReviewSheet`: merged row, chart colours, three chip kinds | `dyolink` | ✅ | §7. Merged "Teeth and prosthesis" row; tooth / jaw / material chip kinds |
| 14 | `applyVoiceResult` writes through `applyLeafToJobs`; handles arch rows | `dyolink` | ✅ | §6, §7 — via `prosthesisTargetLines`, which routes every stack through `applyLeafToJobs` |
| 15 | Vitest specs for `prosthesisTree.ts` and `voiceReviewRows.ts` | `dyolink` | ✅ | §12. 37 tests total, `npx vitest run` green |
| 16 | New user-visible strings in `en.json`, `fa.json`, `nl.json` | `dyolink` | ✅ | i18n is mandatory, not a follow-up — new `voiceUnresolved.*` reasons, `voiceTeethAndProsthesis`, `voicePickJaw`, `voiceNoProsthesisHeard`, `voiceStackRefused`; retired `voiceProsthesisIncomplete` (all-or-nothing gone) |
| 17 | Run every gate in §12, then the manual pass including Safari and iPad | `dyolink` | 🟡 | Every machine gate green, migration and seed now applied and verified (2026-09-07 entry below). **Manual pass still not run** — Safari, iPad, and the stack / jaw / chip flows in `fa` |
| 18 | `PROSTHESIS_CATEGORY` + `PROSTHESIS_SUBCATEGORY` in `CatalogEntityKind`; migration; seed fa/en/nl translations | `dyolink` | ✅ | §5, decision 47. Applied via `migrate deploy` and seeded: enum carries both kinds, 7 categories + 5 subcategories per locale, `crown` → `روکش‌ها` |
| 19 | Unresolved items carry `assignmentIndex`; a picked chip inherits that assignment's jobs | `dyolink` | ✅ | §6, decision 50. `UnresolvedItem.assignmentIndex`; `VoiceReviewSheet` chips inherit via `withChosenTeeth(...,index)` / `withChosenArch` / `withChosenProsthesisLeaf` |
## Key decisions
Full table in the spec's §13, rows 34–46. The load-bearing ones:
- **One assignment list, no default type.** A default plus per-tooth overrides has a
precedence rule, and that rule already mis-filled tooth 13 once.
- **An arch target is derived from the code's `chartRegion`, not declared on the wire.**
The catalog already answers it, and `partial_denture` already carries `chartRegion: 'crown'`.
- **Stack rules stay frontend-only.** The backend's dispatch check knows nothing about
stacking; porting `canStackLeaf` would make voice stricter than the manual path and create
a second copy of a rule that must never disagree.
- **Teeth and prosthesis merge into one sheet row for lab-dependent types.** Two ticks can
save an empty detail today, because `persistDraft` prunes lab-dependent details to their jobs.
- **Nothing is guessed.** A missing material, a missing jaw and a missing quadrant all become
chips. A jobless tooth is named and left out.
- **Categories become real catalog entities** (decision 47). Two new `CatalogEntityKind` values
and seeded translations, rather than bare untranslated codes in the prompt on `fa`.
- **A chip must inherit its assignment's jobs** (decision 50), or it resolves to a jobless tooth
and the tap does nothing.
## Deviations from spec
(none yet)
## Next steps / open questions
- Re-run `/orchestrate --dry` with a `gapNote`, so the surveyor re-runs instead of replaying its
cached `gaps_found` verdict.
- Amin reviews and approves this spec revision. That approval is the only human gate before
`/orchestrate --dry`.
- Open items 15 and 16 in §11 are carried forward unchanged and are **not** in this branch:
the pre-authentication body limit on the voice path, and transcript salvage still being
specified but not built.
- `feat/voice-treatment-entry` and `backup/pre-rebase-voice` are stale local branches from the
v1 work. Safe to delete once this lands.
---
## 2026-09-07 — Gap-check halted (nothing built, nothing pushed)
- **Phase:** Gap-check
- **Reason:** the spec has 1 gap that blocks implementation — nothing was built.
- **Repo:** dyolink @ `feat/treatment/add-voice-input-for-new-treatment-form`
### Blocking gap 1 — `missing_constraint` (dyolink)
**Summary:** The prompt must present prosthesis categories and subcategories so the model can
return `crown` for "روکش", but no localized label for a category or subcategory exists anywhere
the backend can read. `CatalogEntityKind` has only TREATMENT_TYPE / PROSTHESIS_TYPE /
LAB_WORKFLOW_STEP, and the only category labels in the repo are frontend message keys
(`category_crown`, `sub_night_guard`) plus a hardcoded single-locale map in a dev export script.
**Spec quotes:**
> **The prosthesis list is no longer flat.** `buildCatalog` already receives `category`, `subcategory`, `chartRegion` and `stackGroup` from `ProsthesisCatalogService` and throws all four away. It now passes them through, so the prompt presents the catalog as the tree it is and marks which codes are jaw-level. Still no catalog knowledge hardcoded in the prompt — the shape comes from the data.
> Treatment types and prosthesis types come from `CatalogLabelService` in the actor's locale, so the model sees "پروتز" and "زیرکونیا مونولیتیک" as the spoken forms of `prosthesis` and `monolithic_zirconia` rather than being asked to translate. Catalog entities store a stable `code` and no label — never hardcode a label.
> "روکش" is *crown* — a category with nine leaves, not a material. The model returns the category code it actually heard rather than guessing `pfm_crown`, and the review sheet offers the leaves as chips (§7).
**Why blocking:** Work item 9 ("Prompt: present the catalog as a tree") cannot be built.
`ProsthesisCatalogService.list()` returns `category` and `subcategory` as bare codes with no label
(prosthesis-catalog.service.ts:82-95), and `CatalogLabelService` cannot resolve them because
`CatalogEntityKind` has no category kind (schema.prisma:331-335). The three ways out have
different costs and one breaks an explicit repo rule, so a builder cannot choose: (a) add
PROSTHESIS_CATEGORY / PROSTHESIS_SUBCATEGORY to the enum plus a migration and seeded translations
— a schema change the spec never mentions; (b) hardcode a fa/en/nl label map in the backend, which
the spec and CLAUDE.md both forbid; (c) send bare codes only, which makes the whole category
feature unmeasured on the weakest locale.
**Question:** Where do the localized labels for the 7 prosthesis categories and 5 subcategories
come from for the extraction prompt: a new `CatalogEntityKind` (PROSTHESIS_CATEGORY /
PROSTHESIS_SUBCATEGORY) with a migration and seeded `CatalogTranslation` rows, or bare codes with
no labels in the prompt?
**Suggested spec change:** Add to §5: "Category and subcategory labels have no backend source
today — `CatalogEntityKind` covers only TREATMENT_TYPE, PROSTHESIS_TYPE and LAB_WORKFLOW_STEP, and
`category_*` / `sub_*` exist only in `frontend/messages/*.json`. Add `PROSTHESIS_CATEGORY` and
`PROSTHESIS_SUBCATEGORY` to `CatalogEntityKind` (one migration), seed their fa/en/nl translations
from the existing message keys, and resolve them through `CatalogLabelService` like every other
catalog label."
**Evidence:** backend/prisma/schema.prisma:331; backend/src/modules/prosthesis-catalog/prosthesis-catalog.service.ts:82; frontend/messages/en.json:1124; backend/prisma/export-prosthesis-catalog.ts:16
### Non-blocking notes
**Note 1 — `ambiguity` (dyolink).** An unresolved item carries only `spoken`, `reason` and
`candidates`, with no link back to the assignment it came from. On a prosthesis detail a
`tooth_missing_quadrant` chip therefore resolves to a tooth with no job, which the "tooth with no
job is named and left out" rule then discards — so tapping the chip does nothing.
> **A single digit alone is never resolved.** "دندون دو" names four teeth. It is reported as `tooth_missing_quadrant` **with the candidate codes attached**
> **A tooth with no job is named and left out.**
> Picking one folds the choice into the result, so an under-specified item is one tap from resolved instead of a dead end.
*Why not blocking:* a builder can add an assignment reference to the unresolved item. But §6's
reason table reads as a complete contract and its "Carries" column names only `candidates`, so a
builder following it literally ships a dead chip on exactly the prosthesis flow §12 asks them to
test.
*Question:* Should `VoiceUnresolvedItem` gain an assignment reference (for example
`assignmentIndex`) so a chosen quadrant chip inherits that assignment's job stack?
*Suggested spec change:* In §6's reason table, add: "`tooth_missing_quadrant` and
`arch_not_spoken` also carry the index of the assignment they came from, so a picked chip inherits
that assignment's `types[]` rather than becoming a jobless tooth."
*Evidence:* frontend/src/types/voice.ts:15-25; frontend/src/components/treatment/voiceReviewRows.ts:66
**Note 2 — `ambiguity` (dyolink).** "The resolver confirms [jaw vs tooth] against the
`chartRegion` of the assignment's codes" is undefined when `types[]` holds a category whose leaves
have mixed regions. `removable` is exactly that: `complete_denture` and `overdenture` are
`chartRegion: 'arch'`, `partial_denture` is `'crown'`.
> A target that names an arch and no position is a jaw, and the resolver confirms that against the `chartRegion` of the assignment's codes.
> `partial_denture` — a `removable` code that is nonetheless assigned per tooth — already ships with `chartRegion: 'crown'` in `catalog-seed-data.ts`, so the exception needs no special case either.
> A code whose region contradicts its target is reported, never coerced.
*Why not blocking:* deferring the region check until the ambiguity chip is picked is a reasonable
default. Worth stating so the builder does not emit `code_not_valid_for_target` for a category that
has not been narrowed yet.
*Question:* When `types[]` holds a category whose leaves span both `crown` and `arch` regions (only
`removable` today), is the region check deferred until the clinician picks a leaf chip?
*Suggested spec change:* In §5 under "A target is a tooth or a jaw": "When `types[]` holds a
category whose leaves have more than one `chartRegion`, the region check is deferred — the item
resolves to `prosthesis_type_ambiguous` and the region is confirmed against the leaf the clinician
picks."
*Evidence:* backend/prisma/catalog-seed-data.ts:266-288
**Note 3 — `brownfield` (dyolink).** §3 names the endpoint `POST /treatments/voice-extract`; the
shipped route is `POST /voice/extract` (`@Controller('voice')` + `@Post('extract')`), and
`common/body-parsers.ts` hardcodes `/api/voice/extract` to select the 10 MB body limit.
> `POST /treatments/voice-extract`
*Why not blocking:* no work item asks to move the route. But if a builder aligned the route with
§3, `isVoiceExtractPath` would stop matching and every real recording would 413 against the 100 kb
default, which reads as a broken microphone rather than a route change.
*Question:* Should §3 be corrected to the shipped path `POST /voice/extract`, since no work item
moves the route?
*Suggested spec change:* Change §3's heading to `POST /voice/extract` and note that
`VOICE_EXTRACT_PATH` in `common/body-parsers.ts` must move with it if it ever changes.
*Evidence:* backend/src/modules/voice/voice.controller.ts:23,36; backend/src/common/body-parsers.ts:10
**Note 4 — `contradiction` (dyolink).** §11 item 13 says v1 ships with "no availability endpoint",
but §4 requires the frontend to learn enabled locales from the API, and `GET /voice/availability`
exists and is what `voiceForEditor` reads today.
> ~~**Availability API**~~ — **resolved for v1:** voice ships **open to everyone** with a configured locale profile. No plan check, no availability endpoint.
> The frontend must learn which locales are enabled **from the API**, not from a `NEXT_PUBLIC_*` var
*Why not blocking:* work item 2 ("`voiceForEditor` also checks `isMediaRecorderSupported()`")
presupposes `voiceAvailability` stays, so the working reading is obvious. The stale line just needs
correcting so nobody deletes a live endpoint.
*Question:* Confirm the availability endpoint stays in v1 and only the plan check is deferred?
*Suggested spec change:* Reword item 13 to "no plan check; the availability endpoint ships and
reports configured locales and `maxRecordingMs` only."
*Evidence:* backend/src/modules/voice/voice.controller.ts:28; frontend/src/components/ui/treatment/TreatmentWorkspace.tsx:625
**Note 5 — `brownfield` (dyolink).** §5's disjointness counts are slightly off: the seed defines 41
distinct prosthesis codes (not 42) and 5 subcategory names — veneer, inlay, onlay, overlay,
night_guard (not 4). The disjointness claim itself holds: no leaf code equals any category or
subcategory name.
> This needs no extra field because the namespaces are disjoint: 42 leaf codes against 7 category names and 4 subcategory names, no collisions.
*Why not blocking:* the test asserts disjointness, not counts, and disjointness is true against the
current seed. Flagged so the builder writes the test against the live catalog rather than a
hardcoded 42/7/4.
*Question:* May the disjointness test assert against the live catalog instead of the counts written
in §5?
*Suggested spec change:* Drop the exact counts and keep only "the leaf, category and subcategory
namespaces are disjoint; a test asserts it against the live catalog".
*Evidence:* backend/prisma/catalog-seed-data.ts:121-400
### Files read during the gap-check
`docs/specs/voice-treatment-entry/spec.md`, `docs/specs/voice-treatment-entry/progress.md`,
`backend/src/modules/voice/extraction.prompt.ts`, `backend/src/modules/voice/extraction.wire.ts`,
`backend/src/modules/voice/voice.providers.ts`, `backend/src/modules/voice/voice.service.ts:243`,
`backend/src/modules/voice/voice.controller.ts:23`,
`backend/src/modules/prosthesis-catalog/prosthesis-catalog.service.ts:72`,
`backend/prisma/catalog-seed-data.ts`, `backend/prisma/schema.prisma:331`,
`backend/prisma/export-prosthesis-catalog.ts:16`, `backend/src/common/fdi.ts`,
`backend/src/common/body-parsers.ts:10`,
`backend/src/modules/treatments/lab-case-send.validation.ts:116`,
`frontend/src/components/treatment/prosthesisTree.ts`,
`frontend/src/components/treatment/voiceReviewRows.ts`, `frontend/src/types/voice.ts`,
`frontend/src/lib/voice/audioFormat.ts`, `frontend/src/lib/voice/useVoiceCapture.ts:157`,
`frontend/src/components/ui/treatment/TreatmentWorkspace.tsx:625` and `:2184`,
`frontend/src/components/ui/treatment/FdiToothChart.tsx:218`,
`frontend/src/components/ui/treatment/ProsthesisJobPopover.tsx:200`,
`frontend/messages/en.json:1124`, `frontend/package.json`
(all paths relative to `/Users/aminmsvi/PersonalProjects/dyolink`)
### How to resume
Close the gaps in the spec, then re-run. Pass `gapNote` describing what you changed, or the
analyst replays this same verdict from cache.
---
## 2026-09-07 — Gaps closed, ready to re-run
All five findings are now answered in the spec. Nothing was built in the halted run, so there is
no code to revisit.
| Finding | Resolution | Spec |
|---|---|---|
| **Blocking** — no backend source for category labels | Add `PROSTHESIS_CATEGORY` + `PROSTHESIS_SUBCATEGORY` to `CatalogEntityKind`, one migration, seed fa/en/nl from the existing `prosthesis.category_*` / `sub_*` keys, resolve via `CatalogLabelService`. Frontend keeps its own keys — migrating it is out of scope | §5, decisions 47–48 |
| Note 1 — chip with no assignment link | Unresolved items raised inside an assignment carry `assignmentIndex`; a picked chip inherits that assignment's `types[]` | §6, decision 50 |
| Note 2 — mixed-region category | `removable` defers its region check to the picked leaf; never `code_not_valid_for_target` while still a category | §5, decision 49 |
| Note 3 — wrong endpoint path in §3 | Corrected to `POST /voice/extract`, with the `body-parsers.ts` coupling called out. No work item moves the route | §3 |
| Note 4 — availability endpoint contradiction | §11 item 13 corrected: the endpoint exists, only the plan check is deferred | §11 |
| Note 5 — disjointness counts | Verified independently: **42** leaf codes (the surveyor's 41 missed `screw_retained`, a multi-line `implant(` call) and **5** subcategories (the spec said 4, missing `night_guard`). The test now asserts against the live catalog, not a written count | §5, §12 |
Referee relays: 0. Gate repairs: 0. Neither phase was reached.
---
## 2026-09-07 — Implementation (dyolink, extraction contract + resolvers + review sheet)
All 19 work items above are built. Nothing committed or pushed — that is the orchestrator's job.
### Backend
- `backend/prisma/schema.prisma` — `PROSTHESIS_CATEGORY`, `PROSTHESIS_SUBCATEGORY` added to
`CatalogEntityKind` (additive, no data loss).
- `backend/prisma/migrations/20260907120000_prosthesis_category_catalog_kinds/migration.sql` —
hand-written `ALTER TYPE ... ADD VALUE` migration, following the exact pattern of the repo's
one precedent (`20260718180000_lab_case_activity_task_assigned`). **Not applied** — see
"Not run" below.
- `backend/prisma/catalog-seed-data.ts` — `PROSTHESIS_CATEGORY_LABELS` (7) and
`PROSTHESIS_SUBCATEGORY_LABELS` (5), worded from the frontend's existing `category_*`/`sub_*`
message keys (decision 47/48), folded into `CATALOG_TRANSLATIONS`.
- `backend/src/common/fdi.ts` — `ARCH_TOOTH_UPPER`/`ARCH_TOOTH_LOWER` sentinels, mirroring the
frontend's `prosthesisTree.ts` convention so both sides speak the same jaw target.
- `backend/src/modules/voice/voice.types.ts` — `ProsthesisAssignment` replaces
`ProsthesisIntent` (default+overrides retired, decision 35); `UnresolvedReason` gains
`prosthesis_type_ambiguous`, `arch_not_spoken`, `code_not_valid_for_target`, loses
`tooth_not_selected`; `UnresolvedItem.assignmentIndex` added (decision 50).
- `backend/src/modules/voice/extraction.wire.ts` — wire schema carries `prosthesis:
WireProsthesisAssignment[]`; `WireToothIntent.arch` gains `'both'`.
- `backend/src/modules/voice/extraction.resolver.ts` — rewritten: `resolveAssignmentTarget`
(tooth vs. jaw, mirrors the old `tooth_missing_quadrant`/new `arch_not_spoken` split),
`classifyTypeCode` (leaf / category / subcategory, disjoint namespaces), and
`resolveProsthesisAssignment` composing both plus the region-validity check (deferred for a
mixed-region category — `removable` today, decision 49 — computed generically from the
catalog's own chart regions rather than hardcoding the category name). `resolveVoiceIntent`
forces `treatmentType` to `prosthesis` when any assignment resolves a target (decision 41).
`resolveProsthesis`/`ResolvedProsthesis` retired outright.
- `backend/src/modules/voice/extraction.prompt.ts` — `prosthesisTree()` renders the catalog as
CATEGORY → (SUBCATEGORY →) leaf from the data `buildCatalog` supplies; no catalog knowledge
hardcoded in the prompt text itself.
- `backend/src/modules/voice/voice.providers.ts`, `voice.service.ts` — `ExtractionCatalog`
carries the full leaf shape plus `prosthesisCategories`/`prosthesisSubcategories`;
`buildCatalog` no longer strips `category`/`subcategory`/`chartRegion`/`stackGroup`.
- `backend/src/modules/prosthesis-catalog/prosthesis-catalog.service.ts` —
`listCategories()`/`listSubcategories()`, resolved through `CatalogLabelService` like every
other catalog label.
- Jest: `extraction.resolver.spec.ts` rewritten around `resolveProsthesisAssignment` (stacks,
jaw targets, both-jaws, leaf/category/subcategory classification, disjointness against the
live `PROSTHESIS_TYPES`, region validity both ways, the `removable` deferral, assignment-index
attribution); `extraction.wire.spec.ts` and `openrouter.provider.spec.ts` updated for the new
wire shape. 209 backend tests pass (121 in `modules/voice`).
### Frontend
- `frontend/src/lib/voice/audioFormat.ts` — `pickRecordingMimeType`'s final fallback is now `''`
instead of `null` (item 1's Safari fix — modern Safari's `isTypeSupported` can reject every
preferred container yet still record when let choose).
- `frontend/src/components/ui/treatment/TreatmentWorkspace.tsx` — `voiceForEditor` now also
requires `isMediaRecorderSupported()`; `applyVoiceResult` rewritten: teeth vs. prosthesis are
mutually exclusive per `isLabDependentResult`, the prosthesis stack is built through
`prosthesisTargetLines` (which routes every leaf through `applyLeafToJobs`), and jaw targets
write `LabCaseToothProsthesisDraft` rows keyed on the `UA`/`LA` sentinels — no separate
arch-specific code path needed beyond what `prosthesisTree.ts` already provides.
- `frontend/src/types/voice.ts` — `VoiceProsthesisAssignment[]` replaces the byTooth map;
`VoiceUnresolvedItem.assignmentIndex`.
- `frontend/src/components/treatment/voiceReviewRows.ts` — rewritten: `isLabDependentResult`,
merged-row `voiceRowAvailability`, `withChosenArch`/`withChosenProsthesisLeaf` (decision 50),
`prosthesisTargetLines` (previews the stack via `applyLeafToJobs`, names refused jobs),
`joblessProsthesisTargets` (decision 40 — named, struck through, never silently dropped or
silently applied), `prosthesisChartData` (crown/root/arch tints for the merged row's chart).
- `frontend/src/components/ui/treatment/VoiceReviewSheet.tsx` — merged "Teeth and prosthesis"
row for a labDependent type; three independent candidate-chip kinds (tooth, jaw, leaf) each
folding through their own `voiceReviewRows` helper; `voiceProsthesisIncomplete` warning
removed (all-or-nothing retired).
- i18n: `en.json`/`fa.json`/`nl.json` — `voiceUnresolved.*` updated for the new/retired reasons,
`voiceTeethAndProsthesis`, `voicePickJaw`, `voiceNoProsthesisHeard`, `voiceStackRefused` added,
`voiceProsthesisIncomplete` removed.
- `frontend/package.json`, `frontend/vitest.config.ts` — `vitest@3.2.7` (pinned to a version
whose peer `@types/node` range still includes the repo's `^20`; vitest 4/5 require `>=22`),
`npm run test` → `vitest run`, alias-only config (`@` → `src/`).
- `frontend/src/components/treatment/prosthesisTree.spec.ts`,
`voiceReviewRows.spec.ts` — 37 Vitest cases covering stack legality, `applyLeafToJobs`
precedence, `toothRegionColors`, row availability, chip folding, the merged-row preview, and
the jobless/pending distinction.
- `CLAUDE.md` — Tests section rewritten; frontend command table gains `npx vitest run`.
### Verification run
- `cd backend && npm test` — 209/209 pass (121 in `modules/voice`).
- `cd backend && npm run build` — clean (after `npm install`, which pulled in `@sentry/nestjs`
that `node_modules` was missing — unrelated to this change, pre-existing on this checkout).
- `cd backend && npx prisma generate` — succeeds against the updated schema (no DB needed);
confirms `CatalogEntityKind.PROSTHESIS_CATEGORY`/`PROSTHESIS_SUBCATEGORY` compile everywhere
they're used.
- `cd frontend && npx tsc --noEmit` — clean.
- `cd frontend && npx vitest run` — 37/37 pass.
- `cd frontend && npm run build` — production build succeeds.
- ESLint on every touched file — 0 errors, 0 new warnings (pre-existing warnings elsewhere in
`TreatmentWorkspace.tsx`, unrelated to this change, left untouched).
### Not run (environment limitation, not a design gap)
- `npm run prisma:migrate && npm run prisma:seed` against a live Postgres — this sandbox has no
running Docker daemon (`docker info` never came up after several minutes and `open -a Docker`
did not launch it), so the migration was never applied to a database and the new
`CatalogTranslation` rows were never seeded. The migration SQL and seed data are written and
reviewed against the one existing precedent in this repo; **run both before merging**.
- The full manual pass in §12 (Safari/iPad recording, live extraction against the real OpenRouter
API, the specific stack/jaw/ambiguity scenarios) — needs a browser and a live backend, neither
available in this session.
### Deviations from spec / judgement calls made while implementing
- **A target with empty `types[]` still resolves as a target**, with `types: []` on its
assignment — not excluded from the assignment's `targets` array. The sheet (frontend) treats
`types.length === 0` with no matching `prosthesis_type_ambiguous` unresolved item as "jobless,
struck through" (decision 40), and the same empty-types-plus-ambiguous-item combination as
"pending a material pick" instead. This keeps the wire contract simple (no extra field) at the
cost of the frontend doing that one bit of inference from `unresolved` — documented in both
`extraction.resolver.ts` and `voiceReviewRows.ts`.
- **The mixed-region deferral (decision 49) is computed generically** from each category's
actual leaf chart-regions (`regions.size === 1` → validate immediately, else defer) rather than
special-cased for `removable` by name. This also defers `implant` (which spans `root` and
`crown` via `screw_retained`) — the spec's prose says "only `removable` today" as an
observation about the current catalog, not an instruction to hardcode that name, and deferring
a category no test forbids deferring is the safer default.
- **`voice.dto.ts`/`voice.controller.ts` needed no changes.** The scout's item 6 ("validation for
new schema shape") does not apply: the DTO validates the client's audio submission
(`audio`/`format`/`timeZone`/`durationMs`/`locale`), which is unrelated to the LLM's structured
output shape that changed. Confirmed by reading both files; not a silent skip.
---
## 2026-09-07 — Re-run reached Ship; stopped, and the challenge phase is incomplete
Recorded by hand: the `record-stop:Ship` agent failed on the session spend limit before it
could write this.
**Stop reason:** `no MR template found in dyolink — refusing to invent a description.` Expected
and flagged at preflight: `.gitea/` holds only `workflows/`, and the remote is Gitea, not GitLab.
A `--dry` run pushes nothing regardless.
| Phase | Result |
|---|---|
| Gap-check | **clear** — the five gaps closed in `77e2ed4` were accepted |
| Scout | 1 of 3 Explore sweeps returned; 2 ended without structured output |
| Implement | **done** — all 19 work items, ~3,100 insertions across 25 files + 4 new files |
| Gate | **green** — backend 16 suites / 209 tests, `nest build` 0, `prisma validate` ok; frontend Vitest 2 files / 37 tests, `tsc --noEmit` 0, `next build` 0 |
| Refute | **incomplete** — `correctness` refuted with 2 findings; `regression-risk` never ran (spend limit) |
| Ship | stopped, no template. `clerk` also failed on the spend limit |
Gate repairs: 0. Referee relays: 0. Nothing committed, nothing pushed.
### Two confirmed findings — verified by hand, not taken on the critic's word
1. **`VoiceReviewSheet.tsx:169` — a picked tooth chip is silently dropped.** `pickCandidate`
sets `teeth: prev.teeth || available.teeth`, but `available` is memoised from `effective`,
which depends on `chosenTeeth`. Both `setChosenTeeth` and `setSelection` run in the same
handler, so the updater closes over the pre-pick `available`, where `available.teeth` is
`false` because `result.teeth` is empty. `prev.teeth` is false too, so it stays false
permanently. The row then renders with the tooth on the chart and the box unticked, and Apply
drops it. This is a variant of the original live-test failure — "ترمیم برای دندون دو".
2. **`VoiceReviewSheet.tsx:213` + `TreatmentWorkspace.tsx:2215` — decision 41 not implemented.**
The treatmentType row is a plain `toggle('treatmentType')` with no lock, and
`applyVoiceResult` derives `labDependent` from `result.treatmentType` rather than the
`detail.treatmentType` it writes. Untick the type row on a forced-prosthesis recording and a
`restoration` detail is saved carrying prosthesis lab rows — the state decision 41 exists to
make unreachable.
### Lint
Backend touched files: 0 errors, 0 warnings. Frontend touched files: 10 warnings, all
pre-existing in `TreatmentWorkspace.tsx`. The repo-wide backend baseline (1,288 errors, 1,107
prettier-fixable) is untouched by this diff.
## Next steps / open questions
- The diff is **unreviewed on the `regression-risk` lens**. Green gate plus one refuting lens is
not the design's bar; the script continued only because the threshold counts refusals and the
second critic errored rather than refused.
- Fix the two findings, then resume from Refute so both lenses grade the same diff.
- The Ship phase cannot pass in this repo until there is an MR template, or until the MR is
opened by hand. Opening one is gated regardless.
---
## 2026-09-07 — Second refute round, both lenses, on the repaired diff
Ran both critics directly rather than resuming the workflow: a resume would have replayed the
`correctness` verdict from cache against a diff that had changed, and re-run the Ship phase that
cannot pass in this repo anyway.
**`correctness` refuted with 4 findings — all confirmed by hand, all fixed in `f1a4594`.**
Three were the same root cause: the region check never actually ran. Each wrote a job the manual
chart cannot produce, and each passed all 209 tests.
| Finding | Effect |
|---|---|
| The deferred region check had nothing to complete it | "پروتز متحرک برای دندون ۱۲" wrote a complete denture onto tooth 12 |
| `some` over a stack's regions | `['pfm_crown','night_guard_soft']` on tooth 12 wrote a night guard onto that tooth |
| `regions.size === 1` also deferred `implant` (root + crown, both tooth regions) | an implant aimed at a jaw resolved as a `UA` target |
| The `e271858` lock ticked the row and the payload but not the count | the sheet read "Apply 1 field" while two landed |
Fix: targets resolve **before** types, so the target kind narrows a category's candidates and an
impossible leaf is never offered. The deferral concept is gone. Region validation is now
`every`, and a category with no usable leaf drops the assignment's targets rather than leaving
them jobless. Four tests added.
**`regression-risk` refuted with 2 findings.**
1. Already fixed in `f1a4594` — the spec file's `filter(Boolean)` left two `tsc` errors. It added
a fact worth keeping: **`.gitea/workflows/*` run no test, lint or typecheck step at all.**
`nest build` excludes `**/*spec.ts` and ts-jest runs transpile-only under
`isolatedModules`, so nothing in this repo would ever have caught it. Repo-wide gap, not this
branch's.
2. **Open — needs a decision, not a fix.** See below.
### Open question: teeth are unreachable when the merged row is unticked
On a forced-prosthesis result `voiceRowAvailability` sets `teeth: false`, so no teeth row renders
and `selection.teeth` can never become true. Untick the merged prosthesis row (which releases the
decision-41 lock) and then untick the type row, and both write paths in `applyVoiceResult` are
skipped — the detail is appended with `teeth: []`. `master` kept the teeth here, because the rows
were separate.
This is decision 39 behaving exactly as approved: teeth and prosthesis apply together. But it
means a clinician who wants only the teeth from a prosthesis dictation, intending to pick
materials by hand, has no way to get them. Not a spec violation — an unstated consequence.
Deliberately not changed unilaterally.
---
## 2026-09-07 — Migration and seed proven against dev Postgres
The last unverified gate. The inspector had run `prisma validate`, which only parses the schema;
the build compiled solely because the generated client in `node_modules` already carried the new
enum values.
Found five migrations pending, not one — this dev database had not been migrated since the
prosthesis overhaul landed on `master` on 1 September (`a3c14a1`, `72f885d`). Prisma applies in
order, so proving one required applying all five.
Used **`prisma migrate deploy`, not `migrate dev`**: `deploy` applies pending migrations and never
offers to reset, so there is no path where a drift prompt drops dev data. §12 should say `deploy`
for this reason.
Counted the `DELETE` in `…_prosthesis_tree_multi_type` before applying rather than trusting its
own "no-op for current data" comment: **0 rows matched**, against 2 rows total in
`lab_case_tooth_prosthesis`. Both login accounts survived (`users` = 2).
Verified after seeding:
| Check | Result |
|---|---|
| `enum_range(CatalogEntityKind)` | now 5 values, including `PROSTHESIS_CATEGORY` and `PROSTHESIS_SUBCATEGORY` |
| Seeded `PROSTHESIS_CATEGORY` rows | 7 per locale × fa/en/nl |
| Seeded `PROSTHESIS_SUBCATEGORY` rows | 5 per locale × fa/en/nl |
| `crown` in `fa` | `روکش‌ها` — the label that makes "روکش" resolvable to a category |
| Code path | `prosthesis-catalog.service.ts:108,119` resolves both kinds via `CatalogLabelService` |
**Repo-wide gap worth acting on separately:** `.gitea/workflows/*` run no test, lint or typecheck
step — only build and deploy. Combined with `nest build` excluding `**/*spec.ts` and ts-jest
running transpile-only under `isolatedModules`, nothing in this repo would ever catch a type error
in a spec file. That is how two of them reached this branch unnoticed.
## 2026-09-11 — note triggers and where a note ends (dyolink)
Two reports from live dictation in `fa`, both prompt-side, no resolver change.
1. «یادداشت» / «یادداشت‌ها» produced no trigger, so the note was discarded. The locale notes
listed only verbs that ask («بنویس», «یادداشت کن»); naming the field itself was not in the
vocabulary. Added the field-name shape for all three locales — fa «یادداشت/یادداشت‌ها/توضیحات/
کامنت», en "note/notes/comments/remarks", nl "notitie/notities/opmerkingen".
2. The note swallowed the next instruction. For «توی توضیحات بنویس سلام چطوری و بفرست برای
لابراتوآر سانشاین» the model sometimes put the whole tail in `comment`, sometimes only
«سلام چطوری». Added a no-overlap invariant: a clause reported as a lab, tooth, prosthesis or
deadline is an instruction and must not also appear in `comment`, plus that exact sentence as
a worked example.
Both rules are stated twice on purpose — in `extraction.prompt.ts` and in the `comment` /
`commentTrigger` descriptions in `extraction.wire.ts`, since the schema description is what the
model reads while filling the field.
No code enforcement for (2). Stripping an extracted clause out of free-speech note text by string
matching is guesswork, and the review sheet shows the note before it is saved.
Files: `backend/src/modules/voice/extraction.prompt.ts`,
`backend/src/modules/voice/extraction.wire.ts`, `docs/specs/voice-treatment-entry/spec.md`.
Verified: `npx eslint src/modules/voice/**/*.ts` clean, `npm test -- extraction` 74/74.
No unit test — both are prompt text, which the extraction specs deliberately do not assert on.
## 2026-09-11 — the apply decision is now testable (dyolink)
Pulled the decision out of `applyVoiceResult` into
`frontend/src/components/treatment/voiceApply.ts` — `buildVoiceApplyPlan(result, selection, ctx)`
returns `{ detail, labCaseDraft }` and writes nothing. The callback shrank from ~115 lines to the
commit it always should have been: two `setState`s, two ref writes, and the save order.
`newDetail` / `newLabCaseDraft` moved from `TreatmentWorkspace.tsx` to `treatmentDetailRules.ts`,
so the pure module can build a draft without importing a component.
21 new tests in `voiceApply.spec.ts`. Proved they bite by reverting each bug in place:
| Reintroduced bug | Failing tests |
|---|---|
| `labDependent` read from `result.treatmentType` (decision 41) | 1 |
| plain `teeth` merged onto a prosthesis detail (decision 40) | 2 |
One group of tests asserts an invariant that belongs to the *backend*: every `toothProsthesis`
row naming a real tooth must appear in `detail.teeth`. That is
`TREATMENT_TOOTH_NOT_ON_DETAIL` (`treatments.service.ts:806`) — the error the clinic saw — now
checked on the client side of the wire, across the four shapes that produced it: two separated
teeth, one tooth, a two-code stack, and a jaw plus a tooth.
Still not covered, and still manual (§12): the `labCaseDraftsRef` timing, which needs a real
render, and the persist ordering.
Gate: `tsc --noEmit` clean, `vitest run` 73/73 (was 52), `next build` compiled, eslint back to its
pre-change 10 warnings (the 11th was an import I had orphaned).
Files: `frontend/src/components/treatment/voiceApply.ts` (new),
`frontend/src/components/treatment/voiceApply.spec.ts` (new),
`frontend/src/components/treatment/treatmentDetailRules.ts`,
`frontend/src/components/ui/treatment/TreatmentWorkspace.tsx`,
`docs/specs/voice-treatment-entry/spec.md`, `CLAUDE.md`.
## Remaining before this is shippable
- The **manual pass in §12** — none of it has been run. Safari and iPad especially, since that is
the report that started the revision, and the stack / jaw / chip flows in `fa`.
- The Ship phase cannot pass in this repo: no MR template exists, and opening a merge request is
gated regardless.