From 8650571b606f9a439691e3208f913dad3ae9f6de Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:14:21 +0000 Subject: [PATCH 01/12] fix(workspace): start new workspaces empty and never send the demo note A first visit, an unreadable saved workspace and an unreadable encrypted workspace now start with no demo patient or encounter, so the first case never lands in a seeded record. A saved demo patient's placeholder note is no longer sent to AADI as case history. (UI flow audit P0 #1) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- src/lib/aadi/composer.ts | 4 ++-- src/lib/workspace-session.ts | 4 ++-- src/lib/workspace.ts | 7 ++++++- tests/aadi-composer.test.ts | 9 +++++++++ tests/workspace-encryption.test.ts | 3 ++- tests/workspace.test.ts | 24 ++++++++++++++++++------ 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/lib/aadi/composer.ts b/src/lib/aadi/composer.ts index d7fca22..a99f050 100644 --- a/src/lib/aadi/composer.ts +++ b/src/lib/aadi/composer.ts @@ -1,5 +1,5 @@ import type { ModeId } from "../drafts"; -import { newId, type Message, type Patient } from "../workspace"; +import { isSeedPatientNote, newId, type Message, type Patient } from "../workspace"; import type { ReviewItem } from "../workflow"; import { emptyCase, type AadiAnalysis } from "./contract"; import { aadiMessage } from "./presentation"; @@ -68,7 +68,7 @@ export function composerCase(prompt: string, context: string, patient?: Pick { it("labels only structured AADI source snapshots as AADI drafts", () => { @@ -82,3 +83,11 @@ describe("composer case strip", () => { expect(invalidCaseField("age", "")).toBe(false); }); }); + +describe("demo patient note", () => { + it("drops the seed note of a saved demo patient", () => { + const demo = initialWorkspace.patients[0]; + expect(composerCase("demam 3 hari", "", demo).anamnesis.freeText).toBeUndefined(); + expect(composerCase("demam 3 hari", "", { ...demo, notes: "Alergi amoksisilin" }).anamnesis.freeText).toBe("Catatan kasus\nAlergi amoksisilin"); + }); +}); diff --git a/tests/workspace-encryption.test.ts b/tests/workspace-encryption.test.ts index ac5b0e6..25a7c8e 100644 --- a/tests/workspace-encryption.test.ts +++ b/tests/workspace-encryption.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest"; import { createLock, isEnvelope, sealWorkspace, WrongPassphrase } from "../src/lib/workspace-crypto"; import { restoreEncrypted } from "../src/lib/workspace-session"; import { saveEncryptedWorkspace } from "../src/lib/workflow"; -import { initialWorkspace } from "../src/lib/workspace"; +import { emptyWorkspace, initialWorkspace } from "../src/lib/workspace"; // Restore and save of an encrypted workspace (docs/specs/2026-11-19-workspace-encryption-design.md). const keys = { storageKey: "w", unreadableKey: "w:unreadable" }; @@ -32,6 +32,7 @@ describe("restoreEncrypted", () => { const restored = await restoreEncrypted(storage, keys, "passphrase-uji-1"); expect(restored.unreadable).toBe(sealed); expect(restored.notice).toContain("tidak dapat dibaca"); + expect(restored.workspace).toEqual(emptyWorkspace); for (const value of storage.data.values()) { expect(value).not.toContain("rahasia"); expect(isEnvelope(value)).toBe(true); } }); }); diff --git a/tests/workspace.test.ts b/tests/workspace.test.ts index 9f926b8..0b9195a 100644 --- a/tests/workspace.test.ts +++ b/tests/workspace.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from "vitest"; -import { initialWorkspace, loadWorkspace, newEncounter, parseWorkspace, workspaceReducer } from "../src/lib/workspace"; +import { emptyWorkspace, initialWorkspace, loadWorkspace, newEncounter, parseWorkspace, workspaceReducer } from "../src/lib/workspace"; import { createDraft, draftLanguages, draftModels, modes } from "../src/lib/drafts"; import { greeting } from "../src/lib/ui-labels"; @@ -81,16 +81,16 @@ describe("storage validation", () => { expect(loadWorkspace(JSON.stringify(saved)).workspace.settings.language).toBe("English"); }); it("recovers from malformed JSON and rejects malformed nested records", () => { - expect(loadWorkspace("{broken").workspace).toEqual(initialWorkspace); - expect(loadWorkspace(JSON.stringify({ ...initialWorkspace, encounters: [{ id: "x", messages: null }] })).workspace).toEqual(initialWorkspace); - expect(loadWorkspace(JSON.stringify({ ...initialWorkspace, settings: { model: "unknown" } })).workspace).toEqual(initialWorkspace); + expect(loadWorkspace("{broken").workspace).toEqual(emptyWorkspace); + expect(loadWorkspace(JSON.stringify({ ...initialWorkspace, encounters: [{ id: "x", messages: null }] })).workspace).toEqual(emptyWorkspace); + expect(loadWorkspace(JSON.stringify({ ...initialWorkspace, settings: { model: "unknown" } })).workspace).toEqual(emptyWorkspace); }); it("keeps saved text it cannot read so the caller can back it up instead of losing it", () => { - expect(loadWorkspace(null)).toEqual({ workspace: initialWorkspace, unreadable: null }); + expect(loadWorkspace(null)).toEqual({ workspace: emptyWorkspace, unreadable: null }); const saved = JSON.stringify({ ...initialWorkspace, settings: { ...initialWorkspace.settings, language: "English" } }); expect(loadWorkspace(saved)).toEqual({ workspace: parseWorkspace(saved), unreadable: null }); const future = JSON.stringify({ ...initialWorkspace, version: 2 }); - for (const raw of ["{broken", future]) expect(loadWorkspace(raw)).toEqual({ workspace: initialWorkspace, unreadable: raw }); + for (const raw of ["{broken", future]) expect(loadWorkspace(raw)).toEqual({ workspace: emptyWorkspace, unreadable: raw }); }); it("round-trips a complete workspace", () => { expect(loadWorkspace(JSON.stringify(initialWorkspace)).workspace).toEqual(initialWorkspace); @@ -149,3 +149,15 @@ describe("agent settings fields (2026-11-04)", () => { expect(text).not.toContain("Lain."); }); }); + +describe("first visit", () => { + it("a first visit starts with no demo patient or encounter", () => { + const { workspace } = loadWorkspace(null); + expect(workspace.patients).toEqual([]); + expect(workspace.encounters).toEqual([]); + expect(workspace.activeEncounterId).toBeNull(); + }); + it("unreadable saved text also starts empty and keeps the text", () => { + expect(loadWorkspace("bukan workspace")).toEqual({ workspace: emptyWorkspace, unreadable: "bukan workspace" }); + }); +}); From 82fcba723940556269e3a5de636f62971dcc9d9c Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:15:19 +0000 Subject: [PATCH 02/12] fix(composer): keep the mode instruction out of the case text A chip still writes its opening sentence into the composer, but the sentence is removed once at submit, so it no longer becomes the SOAP note's Keluhan Utama or the AADI chief complaint. An opening with nothing after it sends nothing. (UI flow audit P0 #2) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- src/components/workspace.tsx | 7 ++++--- src/lib/studio.ts | 6 ++++++ tests/studio.test.ts | 11 ++++++++++- tests/ui/workspace-smoke.test.tsx | 12 ++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/components/workspace.tsx b/src/components/workspace.tsx index ba37008..b70ccf1 100644 --- a/src/components/workspace.tsx +++ b/src/components/workspace.tsx @@ -5,7 +5,7 @@ import { useCallback, useEffect, useReducer, useRef, useState, useSyncExternalSt import { createDraft, type ModeId } from "../lib/drafts"; import { initialWorkspace, newEncounter, workspaceReducer, type Encounter, type Message, type Patient } from "../lib/workspace"; import { localDraftMessages, shortcutFor } from "../lib/workspace-session"; -import { downloadName, headlineFor } from "../lib/studio"; +import { downloadName, headlineFor, stripOpening } from "../lib/studio"; import { insertTemplate } from "../lib/clinical-templates"; import { reviewedText } from "../lib/normal-exam"; import { compactQuery, mobileQuery } from "../lib/layout"; @@ -159,8 +159,9 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s if (analysisController.current === controller) { analysisController.current = null; setBusy(false); setPendingQuestion(null); setQueuePosition(null); pendingText.current = null; } } } - function generate(text = prompt, selectedMode = mode, useTemplate = true, local = false, fallback?: string) { - if (busy || analysisController.current || !text.trim()) return; + function generate(typed = prompt, selectedMode = mode, useTemplate = true, local = false, fallback?: string) { + const text = stripOpening(typed); + if (busy || analysisController.current || !text) return; const current: Encounter = encounter ?? newEncounter(); let content: string; const personal = useTemplate && selectedTemplate?.mode === selectedMode ? selectedTemplate : undefined; diff --git a/src/lib/studio.ts b/src/lib/studio.ts index 81416bf..5c5d2ed 100644 --- a/src/lib/studio.ts +++ b/src/lib/studio.ts @@ -27,6 +27,12 @@ export function withOpening(prompt: string, mode: ModeId): string { const current = modes.map((item) => item.opening).filter((text) => prompt.startsWith(text)).sort((a, b) => b.length - a.length)[0]; return opening + (current ? prompt.slice(current.length).replace(/^\r?\n/, "") : prompt); } +/** The case as sent: a mode's opening sentence at the very start (put there by a chip) is an instruction, not case text, + * so it never reaches the document or AADI (UI audit P0 #2). Text elsewhere is left as written. */ +export function stripOpening(prompt: string): string { + const current = modes.map((item) => item.opening).filter((text) => prompt.startsWith(text)).sort((a, b) => b.length - a.length)[0]; + return (current ? prompt.slice(current.length) : prompt).trim(); +} // The headline rotates through the intent groups, one per visit. export function headlineFor(visit: number): string { const headlines = intentGroups.map((group) => group.headline); diff --git a/tests/studio.test.ts b/tests/studio.test.ts index f94906e..d00fc19 100644 --- a/tests/studio.test.ts +++ b/tests/studio.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { intentGroups, emptySection, documentSections, documentTitle, supportingSection, replaceSection, encounterTimeline, contextFacts, composerPlaceholder, downloadName, chipShortlist, chipLabel, headlineFor, withOpening } from "../src/lib/studio"; +import { intentGroups, emptySection, documentSections, documentTitle, supportingSection, replaceSection, encounterTimeline, contextFacts, composerPlaceholder, downloadName, chipShortlist, chipLabel, headlineFor, withOpening, stripOpening } from "../src/lib/studio"; import { defaultReviewItems } from "../src/lib/workflow"; import { createDraft, modeIds, modes, type ModeId } from "../src/lib/drafts"; import { clinicalTemplates, insertTemplate, modeCategories, templateText } from "../src/lib/clinical-templates"; @@ -215,4 +215,13 @@ describe("mode openings and the chip shortlist", () => { expect(withOpening("demam 3 hari", "clinic")).toBe(`${opening("clinic")}\ndemam 3 hari`); }); it("the headline cycles through the intent headlines by visit",() => { expect(headlineFor(0)).toBe(intentGroups[0].headline); expect(headlineFor(4)).toBe(intentGroups[0].headline); expect(headlineFor(-1)).toBe(intentGroups[3].headline); }); + it("strips only a leading opening", () => { + const opening = (id: string) => modes.find((m) => m.id === id)!.opening; + expect(stripOpening(`${opening("clinic")}\nLaki-laki 45 tahun, demam 3 hari`)).toBe("Laki-laki 45 tahun, demam 3 hari"); + expect(stripOpening("demam 3 hari. Susun catatan SOAP dari kasus berikut:")).toBe("demam 3 hari. Susun catatan SOAP dari kasus berikut:"); + }); + it("opening alone is not a case", () => { + const opening = (id: string) => modes.find((m) => m.id === id)!.opening; + expect(stripOpening(`${opening("ddx")}\n `)).toBe(""); + }); }); diff --git a/tests/ui/workspace-smoke.test.tsx b/tests/ui/workspace-smoke.test.tsx index ba23174..87b6aaa 100644 --- a/tests/ui/workspace-smoke.test.tsx +++ b/tests/ui/workspace-smoke.test.tsx @@ -252,6 +252,18 @@ describe("workspace UI smoke tests", () => { expect(screen.getByRole("tab", { name: /Analisis kasus/ }).getAttribute("aria-selected")).toBe("true"); }); + it("a SOAP draft made after a chip does not carry the chip sentence", async () => { + render(); + await act(async () => { await Promise.resolve(); }); + fireEvent.click(screen.getByRole("button", { name: /Catatan Klinis \(SOAP\)/ })); + const textarea = screen.getByLabelText("Pertanyaan atau catatan klinis") as HTMLTextAreaElement; + expect(textarea.value).toContain("Susun catatan SOAP dari kasus berikut:"); + fireEvent.change(textarea, { target: { value: `${textarea.value}demam 3 hari` } }); + await act(async () => { fireEvent.keyDown(textarea, { key: "Enter" }); }); + const pane = screen.getByRole("tabpanel"); + expect(pane.textContent).toMatch(/demam (sejak )?3 hari/i); + expect(pane.textContent).not.toContain("Susun catatan SOAP dari kasus berikut:"); + }); it("shows 'tidak dapat dibaca' notice for corrupt saved workspace and preserves raw text in backup", async () => { const corruptData = "{ corrupt invalid json content"; localStorage.setItem(storageKey, corruptData); From 583524d87d2ae7ccfabc278bafc86c687af96e77 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:16:40 +0000 Subject: [PATCH 03/12] feat(composer): confirm before a different patient joins the open encounter When the open encounter already holds a case and the typed age or sex differs from what it knows (saved patient first, then its first case), nothing is sent: the composer offers Kasus baru (a new encounter without the old patient) or Tetap di encounter ini. Unknown values never block. (UI flow audit P0 #3) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- src/components/composer.tsx | 3 ++- src/components/workspace.tsx | 33 +++++++++++++++++++------------ src/lib/aadi/composer.ts | 21 +++++++++++++++++++- tests/aadi-composer.test.ts | 25 +++++++++++++++++++++-- tests/ui/workspace-smoke.test.tsx | 17 ++++++++++++++++ 5 files changed, 82 insertions(+), 17 deletions(-) diff --git a/src/components/composer.tsx b/src/components/composer.tsx index f83fcee..10f6dec 100644 --- a/src/components/composer.tsx +++ b/src/components/composer.tsx @@ -12,7 +12,7 @@ import type { PersonalTemplate } from "../lib/workflow"; import type { Encounter, Settings } from "../lib/workspace"; import { useDictation } from "./use-dictation"; -interface Props { prompt: string; onPrompt: (value: string) => void; mode: ModeId; onMode: (mode: ModeId) => void; settings: Settings; onModel: (model: Settings["model"]) => void; context: string; onContext: () => void; onScribe: () => void; encounter?: Pick; patientName?: string; templates: PersonalTemplate[]; favorites: string[]; templateKey: string | null; onTemplate: (key: string) => void; onSubmit: () => void; busy: boolean; aadiEnabled?: boolean; analysisError?: string; onCancelAnalysis?: () => void; onFallback?: () => void } +interface Props { prompt: string; onPrompt: (value: string) => void; mode: ModeId; onMode: (mode: ModeId) => void; settings: Settings; onModel: (model: Settings["model"]) => void; context: string; onContext: () => void; onScribe: () => void; encounter?: Pick; patientName?: string; templates: PersonalTemplate[]; favorites: string[]; templateKey: string | null; onTemplate: (key: string) => void; onSubmit: () => void; busy: boolean; aadiEnabled?: boolean; analysisError?: string; onCancelAnalysis?: () => void; onFallback?: () => void; mismatch?: { onNew: () => void; onKeep: () => void } | null } const modeLabel = (id: ModeId) => modes.find((item) => item.id === id)!.label; @@ -72,6 +72,7 @@ export function Composer(props: Props) { {dictation.error &&

{dictation.error}

} {props.aadiEnabled &&

Sebelum mengirim ke layanan AI, hapus identitas pasien dari pertanyaan, catatan, dan konteks.

} + {props.mismatch &&

Data usia/jenis kelamin berbeda dari encounter ini.

} {props.aadiEnabled && props.analysisError &&

{props.analysisError} {props.prompt.trim() && !props.busy && <> {props.onFallback && }}

} {/* Options are the rows themselves: focus stays in the textarea, which points at the active row. */} {slashOpen &&
{groups.map((group, g) =>
{group.options.map((item, i) => { const at = groups.slice(0, g).reduce((n, earlier) => n + earlier.options.length, 0) + i; return
event.preventDefault()} onClick={() => choose(item.key)}>{item.label}{item.key === current ? : item.hint && {item.hint}}
; })}
)}{!options.length &&

Tidak ada templat yang cocok.

}
} diff --git a/src/components/workspace.tsx b/src/components/workspace.tsx index b70ccf1..1078aa1 100644 --- a/src/components/workspace.tsx +++ b/src/components/workspace.tsx @@ -24,7 +24,7 @@ import { KnowledgeDialog } from "./knowledge-dialog"; import { diagnosisContent, aadiMessage, pcareCopies } from "../lib/aadi/presentation"; import { paneDocuments } from "../lib/document-pane"; import type { AadiAnalysis } from "../lib/aadi/contract"; -import { composerCase, composerUsesAadi, composerAadiMessages, emptyCaseFields, readCaseFields, type CaseFields } from "../lib/aadi/composer"; +import { caseMismatch, composerCase, composerUsesAadi, composerAadiMessages, emptyCaseFields, knownCaseFields, readCaseFields, type CaseFields } from "../lib/aadi/composer"; import { requestAadiAnalysis } from "../lib/aadi/client"; import { smooth } from "./smooth"; import { useMediaQuery, useToast, useWorkspacePersistence } from "./workspace-hooks"; @@ -69,6 +69,8 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s const [caseFields, setCaseFields] = useState(emptyCaseFields); const resetCaseFields = useCallback(() => setCaseFields(emptyCaseFields()), []); const [analysisError, setAnalysisError] = useState(""); + // A case whose age or sex differs from the open encounter waits here until the doctor picks where it goes (P0 #3). + const [held, setHeld] = useState<{ text: string; mode: ModeId; useTemplate: boolean; local: boolean; fallback?: string } | null>(null); // The question being analysed: shown at once as the user's message, saved only with its answer. const [pendingQuestion, setPendingQuestion] = useState(null); const [queuePosition, setQueuePosition] = useState(null); @@ -125,7 +127,7 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s } function savePatient(p: Patient) { const exists = state.patients.some((item) => item.id === p.id); dispatch({ type: exists ? "patient.edit" : "patient.add", patient: p }); if (!exists) { dispatch({ type: "encounter.add", encounter: newEncounter(p.id) }); setPrompt(""); } closeDialog(); notify(exists ? "Detail Pasien tersimpan." : "Pasien dibuat. Encounter pertama siap digunakan."); } function updatePrompt(value: string) { - setPrompt(value); setAnalysisError(""); + setPrompt(value); setAnalysisError(""); setHeld(null); // Glass's composer is one text box (Gaffer, 2026-11-04): age, sex and vitals are read from the text, never edited apart. const found = readCaseFields(value); setCaseFields({ ...emptyCaseFields(), ...found }); @@ -135,21 +137,21 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s function fallbackDraft() { if (!prompt.trim() || busy) return; const reason = analysisError; setAnalysisError(""); - generate(prompt, "clinic", false, true, reason); + generate(prompt, "clinic", false, true, reason, { confirmed: true }); // Like an answered analysis, the next case starts with an empty strip. resetCaseFields(); notify("Draf SOAP lokal disusun tanpa analisis AADI. Lengkapi dan verifikasi oleh klinisi."); } - async function analyzeMain(text: string, selectedMode: ModeId, current: Encounter) { + async function analyzeMain(text: string, selectedMode: ModeId, current: Encounter, isNew: boolean, casePatient?: Patient) { if (analysisController.current) return; const controller = new AbortController(); analysisController.current = controller; setBusy(true); setAnalysisError(""); pendingText.current = text.trim(); setPendingQuestion(text.trim()); setPrompt(""); // The home composer gives way to the chat composer; keep typing where the reader is. requestAnimationFrame(() => document.querySelector(".chat-composer textarea")?.focus()); try { - const analysis = await requestAadiAnalysis(composerCase(text, current.context, patient, caseFields), { signal: controller.signal, onQueuePosition: place => { if (analysisController.current === controller) setQueuePosition(place); } }); + const analysis = await requestAadiAnalysis(composerCase(text, current.context, casePatient, caseFields), { signal: controller.signal, onQueuePosition: place => { if (analysisController.current === controller) setQueuePosition(place); } }); if (controller.signal.aborted || analysisController.current !== controller) return; - if (!encounter) dispatch({ type: "encounter.add", encounter: { ...current, title: text.trim().slice(0, 48) } }); + if (isNew) dispatch({ type: "encounter.add", encounter: { ...current, title: text.trim().slice(0, 48) } }); dispatch({ type: "message.add", encounterId: current.id, messages: composerAadiMessages(analysis, text, selectedMode, state.reviewDefaults) }); resetCaseFields(); dispatch({ type: "encounter.select", id: current.id }); @@ -159,20 +161,24 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s if (analysisController.current === controller) { analysisController.current = null; setBusy(false); setPendingQuestion(null); setQueuePosition(null); pendingText.current = null; } } } - function generate(typed = prompt, selectedMode = mode, useTemplate = true, local = false, fallback?: string) { + // confirmed: the doctor already chose where a mismatching case goes; fresh: it starts its own encounter, without a patient. + function generate(typed = prompt, selectedMode = mode, useTemplate = true, local = false, fallback?: string, { confirmed = false, fresh = false } = {}) { const text = stripOpening(typed); if (busy || analysisController.current || !text) return; - const current: Encounter = encounter ?? newEncounter(); + const target = fresh ? undefined : encounter, targetPatient = fresh ? undefined : patient; + if (!confirmed && target?.messages.length && caseMismatch(readCaseFields(text), knownCaseFields(target, targetPatient))) { setHeld({ text, mode: selectedMode, useTemplate, local, fallback }); return; } + setHeld(null); + const current: Encounter = target ?? newEncounter(); let content: string; const personal = useTemplate && selectedTemplate?.mode === selectedMode ? selectedTemplate : undefined; if (!local && composerUsesAadi(selectedMode, !!personal)) { // No minimum-data gate (Gaffer, 2026-11-04, like Glass): the case goes as typed; the report names what is missing. - void analyzeMain(text, selectedMode, current); return; + void analyzeMain(text, selectedMode, current, !target, targetPatient); return; } - try { content = personal ? createPersonalDraft(personal, text, current.context) : createDraft({ mode: selectedMode, prompt: text, context: current.context, ...state.settings, patient, caseFields: readCaseFields(text) }); } catch (error) { notify(error instanceof Error ? error.message : "Draf tidak dapat diformat.", "error"); return; } + try { content = personal ? createPersonalDraft(personal, text, current.context) : createDraft({ mode: selectedMode, prompt: text, context: current.context, ...state.settings, patient: targetPatient, caseFields: readCaseFields(text) }); } catch (error) { notify(error instanceof Error ? error.message : "Draf tidak dapat diformat.", "error"); return; } setBusy(true); - if (!encounter) dispatch({ type: "encounter.add", encounter: { ...current, title: text.trim().slice(0, 48) } }); - const messages = localDraftMessages({ text, content, mode: selectedMode, context: current.context, patient, settings: state.settings, reviewDefaults: state.reviewDefaults, personal, fallback }); + if (!target) dispatch({ type: "encounter.add", encounter: { ...current, title: text.trim().slice(0, 48) } }); + const messages = localDraftMessages({ text, content, mode: selectedMode, context: current.context, patient: targetPatient, settings: state.settings, reviewDefaults: state.reviewDefaults, personal, fallback }); dispatch({ type: "message.add", encounterId: current.id, messages }); setPrompt(""); setBusy(false); } @@ -199,7 +205,8 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s onMakeTasks: (text: string) => { const typed = prompt; generate(text, "tasks", false); setPrompt(typed); }, }; const paneFor = (onClose: () => void) => encounter && setPane({ activeId })} overview={} tools={paneTools} onClose={onClose} dispatch={dispatch} onToast={notify} drafts={drafts} onDraft={setDraft}/>; - const composerProps: ComponentProps = { prompt, onPrompt: updatePrompt, mode, onMode: changeMode, settings: state.settings, onModel: (model) => dispatch({ type: "settings.save", settings: { ...state.settings, model } }), context, onContext: () => openDialog("context"), onScribe: () => openDialog("scribe"), encounter, patientName: patient?.name, templates: state.templates ?? [], favorites: state.favorites ?? [], templateKey, onTemplate: chooseTemplate, onSubmit: () => generate(), busy, aadiEnabled: composerUsesAadi(mode, !!selectedTemplate), analysisError, onCancelAnalysis: cancelAnalysis, onFallback: fallbackDraft }; + const composerProps: ComponentProps = { prompt, onPrompt: updatePrompt, mode, onMode: changeMode, settings: state.settings, onModel: (model) => dispatch({ type: "settings.save", settings: { ...state.settings, model } }), context, onContext: () => openDialog("context"), onScribe: () => openDialog("scribe"), encounter, patientName: patient?.name, templates: state.templates ?? [], favorites: state.favorites ?? [], templateKey, onTemplate: chooseTemplate, onSubmit: () => generate(), busy, aadiEnabled: composerUsesAadi(mode, !!selectedTemplate), analysisError, onCancelAnalysis: cancelAnalysis, onFallback: fallbackDraft, + mismatch: held && { onNew: () => generate(held.text, held.mode, held.useTemplate, held.local, held.fallback, { confirmed: true, fresh: true }), onKeep: () => generate(held.text, held.mode, held.useTemplate, held.local, held.fallback, { confirmed: true }) } }; if (restoring) return

Membuka workspace…

; if (locked) return ; diff --git a/src/lib/aadi/composer.ts b/src/lib/aadi/composer.ts index a99f050..f561354 100644 --- a/src/lib/aadi/composer.ts +++ b/src/lib/aadi/composer.ts @@ -1,5 +1,5 @@ import type { ModeId } from "../drafts"; -import { isSeedPatientNote, newId, type Message, type Patient } from "../workspace"; +import { isSeedPatientNote, newId, type Encounter, type Message, type Patient } from "../workspace"; import type { ReviewItem } from "../workflow"; import { emptyCase, type AadiAnalysis } from "./contract"; import { aadiMessage } from "./presentation"; @@ -61,6 +61,25 @@ export function readCaseFields(text: string): Partial { return found; } +type KnownCase = Pick, "age" | "sex">; +/** What the encounter already says about who the case is: the saved patient first, then the first case typed into it. */ +export function knownCaseFields(encounter: Pick, patient?: Pick): KnownCase { + const first = encounter.messages.find((message) => message.role === "user"); + const typed = first ? readCaseFields(first.content) : {}; + const sex = patient?.sex.trim().toLowerCase(); + const age = patient && ageOf(patient.age) !== undefined ? patient.age.trim() : typed.age; + const known: KnownCase = { age, sex: sex === "male" || sex === "m" ? "M" : sex === "female" || sex === "f" ? "F" : typed.sex }; + return Object.fromEntries(Object.entries(known).filter(([, value]) => value)) as KnownCase; +} + +/** A typed case that names a different sex, or an age more than a year apart, from what the encounter already knows + * (UI audit P0 #3). Anything unknown on either side is never a mismatch. */ +export function caseMismatch(typed: Partial, known: KnownCase): "sex" | "age" | null { + if (typed.sex && known.sex && typed.sex !== known.sex) return "sex"; + const a = typed.age ? ageOf(typed.age) : undefined, b = known.age ? ageOf(known.age) : undefined; + return a !== undefined && b !== undefined && Math.abs(a - b) > 1 ? "age" : null; +} + export function composerCase(prompt: string, context: string, patient?: Pick & Partial>, fields?: CaseFields) { const data = emptyCase(); data.chiefComplaint = prompt.trim(); diff --git a/tests/aadi-composer.test.ts b/tests/aadi-composer.test.ts index 89fd938..bead3eb 100644 --- a/tests/aadi-composer.test.ts +++ b/tests/aadi-composer.test.ts @@ -1,9 +1,9 @@ import { describe, expect, it } from "vitest"; -import { composerCase, composerUsesAadi, composerAadiMessages, emptyCaseFields, invalidCaseField, readCaseFields } from "../src/lib/aadi/composer"; +import { caseMismatch, knownCaseFields, composerCase, composerUsesAadi, composerAadiMessages, emptyCaseFields, invalidCaseField, readCaseFields } from "../src/lib/aadi/composer"; import { emptyCase, type AadiAnalysis } from "../src/lib/aadi/contract"; import { validCase } from "../src/lib/aadi/contract"; import { hasAadiSource } from "../src/lib/aadi/presentation"; -import { initialWorkspace } from "../src/lib/workspace"; +import { initialWorkspace, type Encounter } from "../src/lib/workspace"; describe("main clinical composer", () => { it("labels only structured AADI source snapshots as AADI drafts", () => { @@ -91,3 +91,24 @@ describe("demo patient note", () => { expect(composerCase("demam 3 hari", "", { ...demo, notes: "Alergi amoksisilin" }).anamnesis.freeText).toBe("Catatan kasus\nAlergi amoksisilin"); }); }); + +describe("case boundary", () => { + it("flags a different sex or an age more than a year apart", () => { + const known = { age: "45", sex: "M" }; + expect(caseMismatch(readCaseFields("Perempuan 30 tahun, nyeri perut"), known)).toBe("sex"); + expect(caseMismatch(readCaseFields("laki-laki 62 tahun"), known)).toBe("age"); + expect(caseMismatch(readCaseFields("laki-laki 46 tahun, kontrol"), known)).toBeNull(); + }); + it("unknown is never a mismatch", () => { + expect(caseMismatch(readCaseFields("perempuan 30 tahun"), {})).toBeNull(); + expect(caseMismatch({}, { age: "45", sex: "M" })).toBeNull(); + }); + it("durations are not ages", () => { + expect(caseMismatch(readCaseFields("demam 3 hari, batuk 2 minggu"), { age: "45" })).toBeNull(); + }); + it("reads what the encounter already knows from the patient, then the first case", () => { + const encounter = { messages: [{ id: "u", role: "user", content: "Laki-laki 45 tahun, demam", mode: "clinic", createdAt: "" }] } as Pick; + expect(knownCaseFields(encounter)).toEqual({ age: "45", sex: "M" }); + expect(knownCaseFields(encounter, { age: "50", sex: "Female" })).toEqual({ age: "50", sex: "F" }); + }); +}); diff --git a/tests/ui/workspace-smoke.test.tsx b/tests/ui/workspace-smoke.test.tsx index 87b6aaa..39ab6a1 100644 --- a/tests/ui/workspace-smoke.test.tsx +++ b/tests/ui/workspace-smoke.test.tsx @@ -264,6 +264,23 @@ describe("workspace UI smoke tests", () => { expect(pane.textContent).toMatch(/demam (sejak )?3 hari/i); expect(pane.textContent).not.toContain("Susun catatan SOAP dari kasus berikut:"); }); + it("asks before filing a different patient in the same encounter", async () => { + render(); + await act(async () => { await Promise.resolve(); }); + fireEvent.click(screen.getByRole("button", { name: /Catatan Klinis \(SOAP\)/ })); + const box = () => screen.getByLabelText("Pertanyaan atau catatan klinis") as HTMLTextAreaElement; + fireEvent.change(box(), { target: { value: "Laki-laki 45 tahun, demam 3 hari" } }); + await act(async () => { fireEvent.keyDown(box(), { key: "Enter" }); }); + fireEvent.change(box(), { target: { value: "Perempuan 30 tahun, nyeri perut" } }); + await act(async () => { fireEvent.keyDown(box(), { key: "Enter" }); }); + expect(screen.getByText("Data usia/jenis kelamin berbeda dari encounter ini.")).toBeTruthy(); + expect(screen.getByRole("button", { name: "Tetap di encounter ini" })).toBeTruthy(); + expect(screen.queryByText("Perempuan 30 tahun, nyeri perut", { selector: ".user-message div" })).toBeNull(); + await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Kasus baru" })); }); + const user = [...document.querySelectorAll(".user-message div")].map((node) => node.textContent); + expect(user).toEqual(["Perempuan 30 tahun, nyeri perut"]); + expect(screen.getAllByRole("button", { name: /Opsi untuk/ })).toHaveLength(2); + }); it("shows 'tidak dapat dibaca' notice for corrupt saved workspace and preserves raw text in backup", async () => { const corruptData = "{ corrupt invalid json content"; localStorage.setItem(storageKey, corruptData); From 30bb974db0df9565f97bac94cdd6bfeccc790aaf Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:18:13 +0000 Subject: [PATCH 04/12] feat(composer): label AI modes and local templates Each mode chip and slash-picker row now names its kind: AI for the five modes AADI analyses, Template for the thirteen that only reorganise the typed text. A local draft's chat line says it was built from the typed text without AI analysis. (UI flow audit P0 #4) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- src/app/globals.css | 1 + src/components/chip-row.tsx | 5 +++-- src/components/composer.tsx | 3 ++- src/components/message-card.tsx | 2 +- src/lib/aadi/composer.ts | 6 ++++++ tests/studio.test.ts | 5 +++++ tests/ui/chip-row.test.tsx | 22 ++++++++++++++++++---- tests/ui/draft-actions.test.tsx | 2 +- tests/ui/message-card.test.tsx | 2 +- tests/ui/normal-exam.test.tsx | 2 +- 10 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/app/globals.css b/src/app/globals.css index 358c404..7e6f6f1 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -197,6 +197,7 @@ label.button:has(input:focus-visible) { outline: 2px solid var(--workspace-focus .context-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-xs); color: var(--color-text-muted); padding-left: 2px; } .context-status .listening { color: var(--workspace-accent-ink); } .action-chip { display: flex; align-items: center; gap: 7px; flex-shrink: 0; border: 1px solid var(--color-border-subtle); border-radius: var(--radius); background: var(--workspace-white); padding: 8px 11px; font-size: var(--text-sm); height: 36px; white-space: nowrap; } +.action-chip .chip-kind { font-size: var(--text-xs); color: var(--color-text-secondary); border: 1px solid var(--color-border-subtle); border-radius: var(--radius-control); padding: 0 5px; line-height: 16px; } .action-chip:hover { border-color: var(--workspace-ink-faint); background: var(--color-background-surface); } .action-chip.active { color: var(--workspace-accent-ink); border-color: color-mix(in srgb, var(--workspace-focus), transparent 45%); background: var(--workspace-accent-soft); } .home-bottom { width: min(780px, calc(100% - 48px)); flex-shrink: 0; margin: 18px auto 16px; text-align: left; } diff --git a/src/components/chip-row.tsx b/src/components/chip-row.tsx index a025c3f..6014106 100644 --- a/src/components/chip-row.tsx +++ b/src/components/chip-row.tsx @@ -4,6 +4,7 @@ import { chipLabel, chipShortlist } from "../lib/studio"; import { modes, type ModeId } from "../lib/drafts"; import type { PersonalTemplate } from "../lib/workflow"; import type { Encounter } from "../lib/workspace"; +import { modeKind, modeKindLabel } from "../lib/aadi/composer"; /** The shortlist under the composer: one scrollable row, the active mode pressed, every chip off while an analysis runs. * When the active mode is outside the shortlist, or a personal template is active, one extra pressed chip leads the row so the doctor can see what the next answer will be. */ @@ -12,7 +13,7 @@ export function ChipRow({ encounter, mode, templateKey, templates, busy, onChip const lead = template ? template.name : chipShortlist.includes(mode) ? null : modes.find((item) => item.id === mode)!.label; return
{/* A template chip only names the active template: choosing a mode here would drop it. */} - {lead && } - {chipShortlist.map((id) => )} + {lead && } + {chipShortlist.map((id) => )}
; } diff --git a/src/components/composer.tsx b/src/components/composer.tsx index 10f6dec..e876d47 100644 --- a/src/components/composer.tsx +++ b/src/components/composer.tsx @@ -8,6 +8,7 @@ import { modes, type ModeId } from "../lib/drafts"; import { composerPlaceholder, withOpening } from "../lib/studio"; import { modeCategories } from "../lib/clinical-templates"; import { modelLabel } from "../lib/ui-labels"; +import { modeKind, modeKindLabel } from "../lib/aadi/composer"; import type { PersonalTemplate } from "../lib/workflow"; import type { Encounter, Settings } from "../lib/workspace"; import { useDictation } from "./use-dictation"; @@ -20,7 +21,7 @@ const modeLabel = (id: ModeId) => modes.find((item) => item.id === id)!.label; function slashGroups(query: string, templates: PersonalTemplate[], favorites: string[]) { const needle = query.toLowerCase(); const all = [ - ...[...new Set(modeCategories.flatMap((group) => group.modes))].map((id) => ({ key: `mode:${id}`, label: modeLabel(id), hint: `/${id}`, search: `${id} ${modeLabel(id)}` })), + ...[...new Set(modeCategories.flatMap((group) => group.modes))].map((id) => ({ key: `mode:${id}`, label: modeLabel(id), hint: `/${id} · ${modeKindLabel[modeKind(id)]}`, search: `${id} ${modeLabel(id)}` })), ...templates.map((item) => ({ key: `template:${item.id}`, label: item.name, hint: "", search: item.name })), ].filter((option) => option.search.toLowerCase().includes(needle)); return [ diff --git a/src/components/message-card.tsx b/src/components/message-card.tsx index 14a6065..2330b01 100644 --- a/src/components/message-card.tsx +++ b/src/components/message-card.tsx @@ -36,7 +36,7 @@ export function MessageCard({ message, onEdit, onToast, onReuse, onOpenDocument return
{/* A document lives in the pane; the chat keeps one line and a card that opens it. */} {paneDocument(message) ? <> - {aadi ?
{doctorSummary(content).map((line, index) => { const at = line.indexOf(":"); return

{at > 0 ? <>{line.slice(0, at + 1)}{line.slice(at + 1)} : line}

; })}
:

{`Draf ${modeName} disusun.`}

} + {aadi ?
{doctorSummary(content).map((line, index) => { const at = line.indexOf(":"); return

{at > 0 ? <>{line.slice(0, at + 1)}{line.slice(at + 1)} : line}

; })}
:

{`Template ${modeName} disusun dari teks Anda, tanpa analisis AI.`}

} {trace.length > 0 &&
Jejak analisis
    {trace.map((step, index) =>
  1. {step.stage} · {step.ms} ms{step.ok ? "" : " · gagal"}
  2. )}
} : <> diff --git a/src/lib/aadi/composer.ts b/src/lib/aadi/composer.ts index f561354..c08404d 100644 --- a/src/lib/aadi/composer.ts +++ b/src/lib/aadi/composer.ts @@ -8,6 +8,12 @@ export function composerUsesAadi(mode: ModeId, personalTemplate: boolean): boole return !personalTemplate && (["question", "ddx", "workup", "refer", "icd10"] as ModeId[]).includes(mode); } +/** What a mode is to the doctor: an AADI analysis, or a local template that only reorganises the typed text (UI audit P0 #4). */ +export function modeKind(mode: ModeId, personalTemplate = false): "ai" | "template" { + return composerUsesAadi(mode, personalTemplate) ? "ai" : "template"; +} +export const modeKindLabel = { ai: "AI", template: "Template" } as const; + // The composer's case strip (Gaffer, 2026-10-20: "Setuju semua"): age, sex and vitals as typed, so they reach the case's // structured fields instead of staying inside the complaint text. export const caseFieldKeys = ["age", "sex", "bp", "heartRate", "temperature", "respiratoryRate", "spo2"] as const; diff --git a/tests/studio.test.ts b/tests/studio.test.ts index d00fc19..b3cf047 100644 --- a/tests/studio.test.ts +++ b/tests/studio.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest"; import { intentGroups, emptySection, documentSections, documentTitle, supportingSection, replaceSection, encounterTimeline, contextFacts, composerPlaceholder, downloadName, chipShortlist, chipLabel, headlineFor, withOpening, stripOpening } from "../src/lib/studio"; import { defaultReviewItems } from "../src/lib/workflow"; import { createDraft, modeIds, modes, type ModeId } from "../src/lib/drafts"; +import { modeKind } from "../src/lib/aadi/composer"; import { clinicalTemplates, insertTemplate, modeCategories, templateText } from "../src/lib/clinical-templates"; import { initialWorkspace, workspaceReducer, type Message, type Workspace, loadWorkspace } from "../src/lib/workspace"; @@ -224,4 +225,8 @@ describe("mode openings and the chip shortlist", () => { const opening = (id: string) => modes.find((m) => m.id === id)!.opening; expect(stripOpening(`${opening("ddx")}\n `)).toBe(""); }); + it("five modes are AI, the rest are templates", () => { + expect(modes.filter((m) => modeKind(m.id) === "ai").map((m) => m.id).sort()).toEqual(["ddx", "icd10", "question", "refer", "workup"]); + }); + it("personal template is a template", () => { expect(modeKind("ddx", true)).toBe("template"); }); }); diff --git a/tests/ui/chip-row.test.tsx b/tests/ui/chip-row.test.tsx index 6ad5a54..656a06f 100644 --- a/tests/ui/chip-row.test.tsx +++ b/tests/ui/chip-row.test.tsx @@ -18,10 +18,16 @@ const composerProps = (overrides: Partial> = {}) }); describe("chip row", () => { + it("template chips carry a Template badge and AI chips an AI badge", () => { + render(); + expect(screen.getByRole("button", { name: "Catatan Klinis (SOAP)" }).querySelector(".chip-kind")?.textContent).toBe("Template"); + expect(screen.getByRole("button", { name: "Diagnosis Banding (DDx)" }).querySelector(".chip-kind")?.textContent).toBe("AI"); + }); + it("renders the shortlist as one scrollable row and marks the active mode", () => { render(); const chips = screen.getAllByRole("button"); - expect(chips.map((chip) => chip.textContent)).toEqual(chipShortlist.map((id) => chipLabel(id))); + expect(chips.map((chip) => chip.querySelector("span")?.textContent)).toEqual(chipShortlist.map((id) => chipLabel(id))); expect(screen.getByRole("button", { name: "Diagnosis Banding (DDx)" }).getAttribute("aria-pressed")).toBe("true"); expect(screen.getByRole("group", { name: "Mode" }).classList.contains("chip-row")).toBe(true); }); @@ -64,9 +70,9 @@ describe("chip row", () => { render(); const chips = screen.getAllByRole("button"); expect(chips).toHaveLength(chipShortlist.length + 1); - expect(chips[0].textContent).toBe("Pengodean Diagnosis (ICD-10)"); + expect(chips[0].querySelector("span")?.textContent).toBe("Pengodean Diagnosis (ICD-10)"); expect(chips[0].getAttribute("aria-pressed")).toBe("true"); - expect(chips.slice(1).map((chip) => chip.textContent)).toEqual(chipShortlist.map((id) => chipLabel(id))); + expect(chips.slice(1).map((chip) => chip.querySelector("span")?.textContent)).toEqual(chipShortlist.map((id) => chipLabel(id))); expect(chips.slice(1).every((chip) => chip.getAttribute("aria-pressed") === "false")).toBe(true); }); @@ -74,12 +80,20 @@ describe("chip row", () => { const templates = [{ id: "t1", name: "QA SOAP pribadi", mode: "clinic" as const, sections: [], instructions: "" }]; render(); const chips = screen.getAllByRole("button"); - expect(chips[0].textContent).toBe("QA SOAP pribadi"); + expect(chips[0].querySelector("span")?.textContent).toBe("QA SOAP pribadi"); + expect(chips[0].querySelector(".chip-kind")?.textContent).toBe("Template"); expect(chips[0].getAttribute("aria-pressed")).toBe("true"); expect(chips[0].getAttribute("aria-disabled")).toBe("true"); expect(screen.getByRole("button", { name: "Catatan Klinis (SOAP)" }).getAttribute("aria-pressed")).toBe("false"); }); + it("the slash picker names each mode's kind", () => { + render(); + const picker = within(screen.getByRole("listbox", { name: "Pilih templat" })); + expect(picker.getByRole("option", { name: /Catatan Klinis \(SOAP\)/ }).textContent).toContain("Template"); + expect(picker.getByRole("option", { name: /Diagnosis Banding \(DDx\)/ }).textContent).toContain("AI"); + }); + it("the slash picker lists every mode under Mode and personal templates under Templat pribadi", () => { const onTemplate = vi.fn(); render(); diff --git a/tests/ui/draft-actions.test.tsx b/tests/ui/draft-actions.test.tsx index 9365f4f..d36d80e 100644 --- a/tests/ui/draft-actions.test.tsx +++ b/tests/ui/draft-actions.test.tsx @@ -67,7 +67,7 @@ describe("local draft when the analysis fails", () => { expect(screen.getByRole("button", { name: "Coba lagi" })).toBeTruthy(); expect(textarea().value).toBe(complaint); await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Susun draf SOAP lokal" })); }); - expect(await screen.findByText("Draf Catatan Klinis (SOAP) disusun.")).toBeTruthy(); + expect(await screen.findByText("Template Catatan Klinis (SOAP) disusun dari teks Anda, tanpa analisis AI.")).toBeTruthy(); expect(screen.queryByText(failure)).toBeNull(); expect(textarea().value).toBe(""); expect(screen.queryByRole("group", { name: "Usia, jenis kelamin, dan tanda vital" })).toBeNull(); diff --git a/tests/ui/message-card.test.tsx b/tests/ui/message-card.test.tsx index 5301693..5448bd1 100644 --- a/tests/ui/message-card.test.tsx +++ b/tests/ui/message-card.test.tsx @@ -45,7 +45,7 @@ describe("MessageCard", () => { const h = handlers(); const message = a("clinic", "# Catatan Klinis\n\n## S\nx"); render(); - expect(screen.getByText("Draf Catatan Klinis (SOAP) disusun.")).toBeTruthy(); + expect(screen.getByText("Template Catatan Klinis (SOAP) disusun dari teks Anda, tanpa analisis AI.")).toBeTruthy(); expect(screen.queryByRole("button", { name: "Salin" })).toBeNull(); const card = screen.getByRole("button", { name: /Catatan Klinis/ }); expect(card.className).toContain("document-card"); diff --git a/tests/ui/normal-exam.test.tsx b/tests/ui/normal-exam.test.tsx index dd593e3..64e46d9 100644 --- a/tests/ui/normal-exam.test.tsx +++ b/tests/ui/normal-exam.test.tsx @@ -32,7 +32,7 @@ describe("normal exam template in the composer", () => { fireEvent.click(screen.getByRole("button", { name: "Catatan Klinis (SOAP)" })); fireEvent.change(textarea(), { target: { value: "Keluhan utama: batuk 3 hari, laki-laki 40 tahun, TD 150/90\nParu: ronki (+/+)" } }); await act(async () => { fireEvent.keyDown(textarea(), { key: "Enter" }); }); - expect(await screen.findByText("Draf Catatan Klinis (SOAP) disusun.")).toBeTruthy(); + expect(await screen.findByText("Template Catatan Klinis (SOAP) disusun dari teks Anda, tanpa analisis AI.")).toBeTruthy(); const draft = (JSON.parse(localStorage.getItem(storageKey)!) as Workspace).encounters[0].messages.find((message) => message.role === "assistant")!; expect(draft.content).toContain("| **Paru** | Ronki (+/+). |\n"); expect(draft.content).toContain("| **Tekanan darah** | 150/90 mmHg |\n"); From 7866bf75eeadf418cb7d9a620db0f168b0806946 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:20:02 +0000 Subject: [PATCH 05/12] docs: record the UI flow P0 fixes; align restore test with empty first workspace Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- docs/sentrapedia-ui.md | 11 +++++++++++ tests/workspace-session.test.ts | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/sentrapedia-ui.md b/docs/sentrapedia-ui.md index f52e792..fd0fd84 100644 --- a/docs/sentrapedia-ui.md +++ b/docs/sentrapedia-ui.md @@ -151,3 +151,14 @@ Terapi Farmakologi: "Untuk ()", satu obat per baris dengan dos ## Workspace berbentuk Glass (2026-11-04) Menggantikan Clinical Cockpit, rail "Alur kasus", jawaban diketik, dan dialog Pengaturan Agent di atas. Sidebar mengikuti urutan Glass; kanvas terbagi antara chat dan panel dokumen di atas 1200 px (sheet "Dokumen encounter" di bawahnya). Chat berisi prosa, ringkasan dokter, dan kartu dokumen; panel berisi tab Ringkasan encounter dan satu tab per dokumen. Analisis AADI dirender dari hasil mesin yang tersimpan dalam bentuk diferensial Glass (`src/lib/aadi/analysis-view.ts`, `src/components/analysis-document.tsx`): Pembahasan kasus, Kemungkinan utama, Alternatif, Jangan terlewat, Langkah diagnostik berikutnya, Rencana tata laksana (lewat gerbang bukti; dosis yang tidak terverifikasi diberi tanda "Cek dosis obat"), Edukasi dan tindak lanjut, Kutipan pedoman (kartu bernomor, tautan `[n]`). Kartu berpikir hanya melaporkan yang terjadi (permintaan diterima, detik menunggu); jejak pipeline disimpan bersama jawaban. Komposer memakai satu baris chip (8 mode) dan `/` sebagai pemilih penuh. Pengaturan Agent menjadi halaman `/agent` dengan tab Preferensi, Mode dan templat, Pengetahuan; `settings.environment` tampil sebagai pil beranda, `settings.modeInstructions` hanya dipakai draf lokal. Token radius: `--radius-control` 8 px, `--radius-structure` 12 px. Bukti: `docs/verification/glass-redesign-2026-11-04/` (1440, 1024, 375 px; axe 0 pelanggaran). + +## Alur kasus yang lebih aman (2026-11-26) + +Empat perbaikan P0 dari audit alur UI (SVI-CEO-RPT-001), status REVIEW: + +- Workspace baru, atau workspace yang tidak dapat dibaca, mulai kosong: tanpa Pasien atau Encounter contoh (`emptyWorkspace`, `src/lib/workspace.ts`). Catatan Pasien contoh yang masih tersimpan di workspace lama tidak pernah dikirim ke AADI sebagai riwayat kasus (`isSeedPatientNote`). +- Chip mode tetap menulis kalimat pembukanya di composer, tetapi kalimat itu dibuang saat kirim (`stripOpening`, `src/lib/studio.ts`), sehingga tidak menjadi Keluhan Utama atau keluhan utama AADI. +- Bila Encounter yang terbuka sudah berisi kasus dan usia/jenis kelamin yang diketik berbeda (Pasien tersimpan dulu, lalu kasus pertama), kasus belum dikirim: composer menawarkan "Kasus baru" atau "Tetap di encounter ini" (`knownCaseFields`, `caseMismatch`, `src/lib/aadi/composer.ts`). Nilai yang tidak diketahui tidak pernah memblokir. +- Chip dan pemilih `/` menandai jenis mode: AI untuk lima mode yang dianalisis AADI, Template untuk tiga belas mode yang hanya menyusun ulang teks (`modeKind`). Draf lokal menulis "Template … disusun dari teks Anda, tanpa analisis AI." + +Verifikasi: seluruh vitest 841 lulus, 23 dilewati (data privat); lint dan typecheck bersih; pemeriksaan browser `next dev` mode auth lokal pada 1440 dan 390 px. Jawaban AADI live dan layar Clerk tidak diuji di lingkungan cloud. diff --git a/tests/workspace-session.test.ts b/tests/workspace-session.test.ts index 0405629..449284e 100644 --- a/tests/workspace-session.test.ts +++ b/tests/workspace-session.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; import { freshAnswer, freshAnswerMs, markRevealed } from "../src/lib/fresh-answer"; import { localDraftMessages, restoreFromStorage, shortcutFor } from "../src/lib/workspace-session"; -import { initialWorkspace, storageKey, unreadableKey, type Message, type Patient, type Settings } from "../src/lib/workspace"; +import { emptyWorkspace, initialWorkspace, storageKey, unreadableKey, type Message, type Patient, type Settings } from "../src/lib/workspace"; import type { PersonalTemplate } from "../src/lib/workflow"; const key = (key: string, mods: { ctrl?: boolean; meta?: boolean } = {}) => ({ key, ctrlKey: !!mods.ctrl, metaKey: !!mods.meta }); @@ -31,7 +31,7 @@ describe("restoring the workspace from browser storage", () => { it("keeps unreadable saved text under its own key, offers it for download and says so", () => { const items: Record = { [storageKey]: "{broken" }; const restored = restoreFromStorage(storage(items)); - expect(restored.workspace).toEqual(initialWorkspace); + expect(restored.workspace).toEqual(emptyWorkspace); expect(restored.unreadable).toBe("{broken"); expect(items[unreadableKey]).toBe("{broken"); expect(restored.notice).toContain("tidak dapat dibaca"); From 49b86606108ff6f5795b5e3a7b3c6783434c5cb1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:25:37 +0000 Subject: [PATCH 06/12] fix(composer): keep a held case with its encounter and its text Review findings on the case-boundary guard: - a Kasus baru choice whose AADI analysis fails now sends the local SOAP fallback to a new encounter too, never to the previous patient's; - a held case belongs to the encounter it was held in, so opening another encounter voids the choice instead of filing it there unchecked; - the held text is put in the composer, so a held scribe transcript is not lost when the dialog closes or the doctor types. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- src/components/workspace.tsx | 14 +++++--- tests/ui/workspace-smoke.test.tsx | 56 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/components/workspace.tsx b/src/components/workspace.tsx index 1078aa1..e7f8d39 100644 --- a/src/components/workspace.tsx +++ b/src/components/workspace.tsx @@ -70,7 +70,11 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s const resetCaseFields = useCallback(() => setCaseFields(emptyCaseFields()), []); const [analysisError, setAnalysisError] = useState(""); // A case whose age or sex differs from the open encounter waits here until the doctor picks where it goes (P0 #3). - const [held, setHeld] = useState<{ text: string; mode: ModeId; useTemplate: boolean; local: boolean; fallback?: string } | null>(null); + // It belongs to the encounter it was held in; opening another encounter voids it (the text stays in the composer). + const [held, setHeld] = useState<{ encounterId: string; text: string; mode: ModeId; useTemplate: boolean; local: boolean; fallback?: string } | null>(null); + const heldHere = held && held.encounterId === state.activeEncounterId ? held : null; + // Whether the analysis that just failed was meant for a new encounter, so its local SOAP fallback goes there too. + const failedIntoNew = useRef(false); // The question being analysed: shown at once as the user's message, saved only with its answer. const [pendingQuestion, setPendingQuestion] = useState(null); const [queuePosition, setQueuePosition] = useState(null); @@ -137,7 +141,7 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s function fallbackDraft() { if (!prompt.trim() || busy) return; const reason = analysisError; setAnalysisError(""); - generate(prompt, "clinic", false, true, reason, { confirmed: true }); + generate(prompt, "clinic", false, true, reason, { confirmed: true, fresh: failedIntoNew.current }); // Like an answered analysis, the next case starts with an empty strip. resetCaseFields(); notify("Draf SOAP lokal disusun tanpa analisis AADI. Lengkapi dan verifikasi oleh klinisi."); @@ -156,7 +160,7 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s resetCaseFields(); dispatch({ type: "encounter.select", id: current.id }); } catch (error) { - if (!controller.signal.aborted) { setAnalysisError(error instanceof Error ? error.message : "Analisis belum tersedia. Keluhan tetap tersedia."); setPrompt(text); } + if (!controller.signal.aborted) { failedIntoNew.current = isNew; setAnalysisError(error instanceof Error ? error.message : "Analisis belum tersedia. Keluhan tetap tersedia."); setPrompt(text); } } finally { if (analysisController.current === controller) { analysisController.current = null; setBusy(false); setPendingQuestion(null); setQueuePosition(null); pendingText.current = null; } } @@ -166,7 +170,7 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s const text = stripOpening(typed); if (busy || analysisController.current || !text) return; const target = fresh ? undefined : encounter, targetPatient = fresh ? undefined : patient; - if (!confirmed && target?.messages.length && caseMismatch(readCaseFields(text), knownCaseFields(target, targetPatient))) { setHeld({ text, mode: selectedMode, useTemplate, local, fallback }); return; } + if (!confirmed && target?.messages.length && caseMismatch(readCaseFields(text), knownCaseFields(target, targetPatient))) { setHeld({ encounterId: target.id, text, mode: selectedMode, useTemplate, local, fallback }); setPrompt(text); return; } setHeld(null); const current: Encounter = target ?? newEncounter(); let content: string; @@ -206,7 +210,7 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s }; const paneFor = (onClose: () => void) => encounter && setPane({ activeId })} overview={} tools={paneTools} onClose={onClose} dispatch={dispatch} onToast={notify} drafts={drafts} onDraft={setDraft}/>; const composerProps: ComponentProps = { prompt, onPrompt: updatePrompt, mode, onMode: changeMode, settings: state.settings, onModel: (model) => dispatch({ type: "settings.save", settings: { ...state.settings, model } }), context, onContext: () => openDialog("context"), onScribe: () => openDialog("scribe"), encounter, patientName: patient?.name, templates: state.templates ?? [], favorites: state.favorites ?? [], templateKey, onTemplate: chooseTemplate, onSubmit: () => generate(), busy, aadiEnabled: composerUsesAadi(mode, !!selectedTemplate), analysisError, onCancelAnalysis: cancelAnalysis, onFallback: fallbackDraft, - mismatch: held && { onNew: () => generate(held.text, held.mode, held.useTemplate, held.local, held.fallback, { confirmed: true, fresh: true }), onKeep: () => generate(held.text, held.mode, held.useTemplate, held.local, held.fallback, { confirmed: true }) } }; + mismatch: heldHere && { onNew: () => generate(heldHere.text, heldHere.mode, heldHere.useTemplate, heldHere.local, heldHere.fallback, { confirmed: true, fresh: true }), onKeep: () => generate(heldHere.text, heldHere.mode, heldHere.useTemplate, heldHere.local, heldHere.fallback, { confirmed: true }) } }; if (restoring) return

Membuka workspace…

; if (locked) return ; diff --git a/tests/ui/workspace-smoke.test.tsx b/tests/ui/workspace-smoke.test.tsx index 39ab6a1..254eced 100644 --- a/tests/ui/workspace-smoke.test.tsx +++ b/tests/ui/workspace-smoke.test.tsx @@ -281,6 +281,62 @@ describe("workspace UI smoke tests", () => { expect(user).toEqual(["Perempuan 30 tahun, nyeri perut"]); expect(screen.getAllByRole("button", { name: /Opsi untuk/ })).toHaveLength(2); }); + const twoPatients = () => { + const at = "2026-11-26T10:00:00.000Z"; + const msg = (id: string, content: string) => [{ id: `${id}-u`, role: "user" as const, content, mode: "clinic" as const, createdAt: at }, { id: `${id}-a`, role: "assistant" as const, content: "# Catatan Klinis\n\n## S\nx", mode: "clinic" as const, createdAt: at }]; + localStorage.setItem(storageKey, JSON.stringify({ ...initialWorkspace, + patients: [{ id: "pA", name: "Budi", age: "45", sex: "Male", notes: "" }, { id: "pC", name: "Citra", age: "70", sex: "Female", notes: "" }], + encounters: [{ id: "eA", patientId: "pA", title: "Kasus Budi", createdAt: at, context: "", messages: msg("a", "Laki-laki 45 tahun, demam") }, { id: "eC", patientId: "pC", title: "Kasus Citra", createdAt: at, context: "", messages: msg("c", "Perempuan 70 tahun, sesak") }], + activeEncounterId: "eA" })); + }; + const saved = () => JSON.parse(localStorage.getItem(storageKey) ?? "{}") as { encounters: Encounter[] }; + + it("Kasus baru stays a new encounter when AADI fails and the local SOAP fallback is used", async () => { + twoPatients(); + vi.mocked(global.fetch).mockImplementation(async (input: RequestInfo | URL, init?: RequestInit) => { + const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url; + if (url.includes("/api/aadi") && init?.method === "POST") return new Response(JSON.stringify({ error: { code: "UPSTREAM", message: "Layanan analisis gagal." } }), { status: 502, headers: { "Content-Type": "application/json" } }); + return new Response(JSON.stringify({ configured: true, ready: true }), { status: 200, headers: { "Content-Type": "application/json" } }); + }); + render(); + await act(async () => { await Promise.resolve(); }); + const box = () => screen.getAllByLabelText("Pertanyaan atau catatan klinis")[0] as HTMLTextAreaElement; + fireEvent.change(box(), { target: { value: "Perempuan 30 tahun, nyeri perut kanan bawah" } }); + await act(async () => { fireEvent.keyDown(box(), { key: "Enter" }); }); + await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Kasus baru" })); }); + for (let i = 0; i < 10; i++) await act(async () => { await vi.advanceTimersByTimeAsync(500); }); + await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Susun draf SOAP lokal" })); }); + const budi = saved().encounters.find((e) => e.id === "eA")!; + expect(budi.messages.map((m) => m.content).filter((c) => c.includes("Perempuan 30"))).toEqual([]); + expect(saved().encounters).toHaveLength(3); + }); + + it("a held case is dropped from view when another encounter is opened", async () => { + twoPatients(); + render(); + await act(async () => { await Promise.resolve(); }); + fireEvent.click(screen.getByRole("button", { name: /Catatan Klinis \(SOAP\)/ })); + const box = () => screen.getAllByLabelText("Pertanyaan atau catatan klinis")[0] as HTMLTextAreaElement; + fireEvent.change(box(), { target: { value: "Perempuan 30 tahun, nyeri perut" } }); + await act(async () => { fireEvent.keyDown(box(), { key: "Enter" }); }); + expect(screen.getByRole("button", { name: "Tetap di encounter ini" })).toBeTruthy(); + await act(async () => { fireEvent.click(screen.getByText("Kasus Citra", { selector: "span" })); }); + expect(screen.queryByRole("button", { name: "Tetap di encounter ini" })).toBeNull(); + expect(saved().encounters.find((e) => e.id === "eC")!.messages).toHaveLength(2); + }); + + it("a held scribe transcript stays in the composer instead of vanishing", async () => { + twoPatients(); + render(); + await act(async () => { await Promise.resolve(); }); + await act(async () => { fireEvent.click(screen.getAllByRole("button", { name: /Mulai Scribe/ })[0]); }); + fireEvent.change(screen.getByPlaceholderText(/Tempel atau ketik percakapan/), { target: { value: "Pasien perempuan 30 tahun, nyeri perut" } }); + await act(async () => { fireEvent.click(screen.getByRole("button", { name: /Buat Scribe Note/ })); }); + expect(screen.getByRole("button", { name: "Tetap di encounter ini" })).toBeTruthy(); + const box = screen.getAllByLabelText("Pertanyaan atau catatan klinis")[0] as HTMLTextAreaElement; + expect(box.value).toBe("Pasien perempuan 30 tahun, nyeri perut"); + }); + it("shows 'tidak dapat dibaca' notice for corrupt saved workspace and preserves raw text in backup", async () => { const corruptData = "{ corrupt invalid json content"; localStorage.setItem(storageKey, corruptData); From 6c525ef3aeaacc3cf9f29c84b2c0c7250d6d54ee Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:59:46 +0000 Subject: [PATCH 07/12] fix(workspace): opening a dialog no longer cancels a running analysis Tambah Konteks, Pasien, Templat, Pusat perintah and the other dialogs now open over a running analysis instead of silently cancelling it and putting the case back in the composer. Scribe still cancels, because it starts a new draft. (UI flow audit #5) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- src/components/workspace.tsx | 4 +++- tests/ui/analysis-mode-switch.test.tsx | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/workspace.tsx b/src/components/workspace.tsx index e7f8d39..f2425cb 100644 --- a/src/components/workspace.tsx +++ b/src/components/workspace.tsx @@ -116,7 +116,9 @@ function WorkspaceState({ principalId, onSignOut, userButton }: { principalId: s useEffect(() => { const handler = (e: KeyboardEvent) => { const shortcut = shortcutFor(e, Boolean(dialog) || (mobile && mobileNavOpen)); if (!shortcut) return; e.preventDefault(); if (shortcut === "new") { dispatch({ type: "encounter.select", id: null }); setPrompt(""); changeMode("question"); } else setDialog(shortcut); }; window.addEventListener("keydown", handler); return () => window.removeEventListener("keydown", handler); }, [dialog, mobile, mobileNavOpen, changeMode]); // One dialog replacing another cross-fades; a first dialog fades in through CSS. - function openDialog(name: DialogName, id?: string) { if (analysisController.current) cancelAnalysis(); const open = () => { setDialog(name); setDialogId(id); }; if (dialog) smooth(open); else open(); } + // A dialog no longer cancels a running analysis (UI audit #5): the request already carries its case, so editing the + // context or a patient meanwhile cannot change it. Scribe is the exception: it starts a new draft, which needs the composer free. + function openDialog(name: DialogName, id?: string) { if (name === "scribe" && analysisController.current) cancelAnalysis(); const open = () => { setDialog(name); setDialogId(id); }; if (dialog) smooth(open); else open(); } function hideDialog() { setDialog(null); setDialogId(undefined); } function closeDialog() { if (dialog) smooth(hideDialog); else hideDialog(); } // Below 1200 px the pane is a sheet; opening it leaves a running analysis alone. diff --git a/tests/ui/analysis-mode-switch.test.tsx b/tests/ui/analysis-mode-switch.test.tsx index a027022..1be7a9e 100644 --- a/tests/ui/analysis-mode-switch.test.tsx +++ b/tests/ui/analysis-mode-switch.test.tsx @@ -8,6 +8,8 @@ beforeEach(() => { Object.defineProperty(window, "matchMedia", { writable: true, value: vi.fn().mockImplementation((query: string) => ({ matches: query.includes("reduce"), media: query, onchange: null, addListener: vi.fn(), removeListener: vi.fn(), addEventListener: vi.fn(), removeEventListener: vi.fn(), dispatchEvent: vi.fn() })) }); global.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} }; Element.prototype.scrollIntoView = vi.fn(); + HTMLDialogElement.prototype.showModal = vi.fn(function (this: HTMLDialogElement) { this.setAttribute("open", ""); }); + HTMLDialogElement.prototype.close = vi.fn(function (this: HTMLDialogElement) { this.removeAttribute("open"); }); // Readiness answers at once; the analysis request itself never answers, so the workspace stays busy. global.fetch = vi.fn().mockImplementation(async (_input: RequestInfo | URL, init?: RequestInit) => { if (init?.method !== "POST") return new Response(JSON.stringify({ configured: true, modelReady: true, groundingReady: true, ready: true }), { status: 200, headers: { "Content-Type": "application/json" } }); @@ -38,4 +40,15 @@ describe("a mode picked while an analysis is running", () => { expect(screen.getByText("Laki-laki 45 tahun, nyeri kepala, N 88")).toBeTruthy(); expect((global.fetch as ReturnType).mock.calls.filter(([, init]) => (init as RequestInit | undefined)?.method === "POST")).toHaveLength(1); }); + + it("opening a dialog such as Tambah Konteks leaves the running analysis alone", async () => { + render(); + await act(async () => { await Promise.resolve(); }); + fireEvent.change(screen.getByLabelText("Pertanyaan atau catatan klinis"), { target: { value: "Laki-laki 45 tahun, nyeri kepala, N 88" } }); + await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Analisis kasus" })); }); + await act(async () => { fireEvent.click(screen.getByRole("button", { name: "Tambah Konteks" })); }); + expect(screen.getByRole("button", { name: "Batalkan analisis" })).toBeTruthy(); + expect(screen.getByText("Laki-laki 45 tahun, nyeri kepala, N 88")).toBeTruthy(); + expect((screen.getByLabelText("Pertanyaan atau catatan klinis") as HTMLTextAreaElement).value).toBe(""); + }); }); From 9331345c6948445e20d0f37dda34b583ee80ed51 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 20:00:17 +0000 Subject: [PATCH 08/12] feat(document-pane): explain why Ditinjau is locked While a draft's required review marks are unticked, a line under the document head says so and opens Peninjauan, instead of a silently disabled status option. (UI flow audit #6) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- src/components/document-pane.tsx | 2 ++ tests/ui/document-pane.test.tsx | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/components/document-pane.tsx b/src/components/document-pane.tsx index 389bc0b..61080d2 100644 --- a/src/components/document-pane.tsx +++ b/src/components/document-pane.tsx @@ -68,6 +68,8 @@ export function DocumentPane({ encounter, activeId, onActive, overview, tools, o + {/* Ditinjau stays locked until the required review marks are ticked; say so instead of a silently disabled option (UI audit #6). */} + {status === "draft" && !reviewComplete(active.reviewItems) && panel !== "review" &&

Centang semua item wajib di Peninjauan untuk menandai Ditinjau.

} {panel === "history" && } {/* "Lihat bagian" goes to that section's heading in the body below. */} {panel === "review" && { setPanel(null); requestAnimationFrame(() => [...document.querySelectorAll(".pane-body h3")].find((heading) => heading.textContent === target)?.scrollIntoView({ block: "start" })); }}/>} diff --git a/tests/ui/document-pane.test.tsx b/tests/ui/document-pane.test.tsx index b799913..bf9ae23 100644 --- a/tests/ui/document-pane.test.tsx +++ b/tests/ui/document-pane.test.tsx @@ -63,6 +63,17 @@ async function seeded(messages: Message[], encounters: Encounter[] = []) { } describe("the document pane", () => { + it("says why Ditinjau is locked and opens Peninjauan from the hint", async () => { + await seeded([doc("d1", "# Catatan Klinis\n\n## S\nx")]); + expect(screen.getByText("Centang semua item wajib di Peninjauan untuk menandai Ditinjau.")).toBeTruthy(); + fireEvent.click(screen.getByRole("button", { name: "Buka Peninjauan" })); + expect(screen.getByText(/Tanda peninjauan pengguna/)).toBeTruthy(); + for (const box of screen.getAllByRole("checkbox")) fireEvent.click(box); + fireEvent.click(screen.getByRole("button", { name: "Peninjauan" })); + expect(screen.queryByText(/Tanda peninjauan pengguna/)).toBeNull(); + expect(screen.queryByText("Centang semua item wajib di Peninjauan untuk menandai Ditinjau.")).toBeNull(); + }); + it("opens the pane with the first document and keeps the chat for question answers only", async () => { render(); await act(async () => { await Promise.resolve(); }); From b513c86582331bd693445ddc888725a15cdffb75 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 20:00:53 +0000 Subject: [PATCH 09/12] feat(composer): one primary action; Format keluaran only for templates Mulai Scribe becomes a secondary button so sending is the only primary action in the composer, and the Standar/Extended select shows only for template modes, the only ones it changes. (UI flow audit #9, #10) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_012ta9C6ZqRNR17D5YJczMjw --- src/components/composer.tsx | 5 +++-- tests/ui/chip-row.test.tsx | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/composer.tsx b/src/components/composer.tsx index e876d47..1d1518f 100644 --- a/src/components/composer.tsx +++ b/src/components/composer.tsx @@ -61,11 +61,12 @@ export function Composer(props: Props) { return
{ event.preventDefault(); if (slashOpen) { if (options[slashIndex]) choose(options[slashIndex].key); } else props.onSubmit(); }}>