@kabmo-labs/kabmo 0.55.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +466 -466
- package/dist/client/static/js/{Body-a4dwe3hh.js → Body-jfy4bhk2.js} +1 -1
- package/dist/client/static/js/{CsvGrid-ppj80brw.js → CsvGrid-4c5t668z.js} +1 -1
- package/dist/client/static/js/{DocxView-ef0bd2pg.js → DocxView-3x7whtvq.js} +1 -1
- package/dist/client/static/js/{DrawioView-44tpkzbd.js → DrawioView-tbkc5dfz.js} +1 -1
- package/dist/client/static/js/{HtmlPreview-w654aykz.js → HtmlPreview-egxkayya.js} +1 -1
- package/dist/client/static/js/{ImageView-kg0skt5s.js → ImageView-swhzvw2p.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-qepkrtd8.js → LayoutWrapper-sangsrt5.js} +2 -2
- package/dist/client/static/js/MergeDiffView-bv00y63x.js +1 -0
- package/dist/client/static/js/{Modal-8d299emm.js → Modal-1fj8kvme.js} +7 -7
- package/dist/client/static/js/{PdfView-eq7fnqa2.js → PdfView-0k2egsbz.js} +1 -1
- package/dist/client/static/js/{SessionsView-tedh2es3.js → SessionsView-t547rqeb.js} +1 -1
- package/dist/client/static/js/{SheetView-5xm33kgk.js → SheetView-anb3gavm.js} +1 -1
- package/dist/client/static/js/{SvgPreview-tp1m8r4t.js → SvgPreview-e2wrj2hj.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-xppr9jf1.js → abnfDiagram-O67JEVCF-0rs86b68.js} +1 -1
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-s23e6vtk.js → architectureDiagram-NJMV4G6O-0k3zzxz1.js} +3 -3
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-7ws8yq9e.js → blockDiagram-BEXU5L5S-t1n1fx96.js} +1 -1
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-517yhfzj.js → c4Diagram-YGBWAQC7-93b7eds9.js} +1 -1
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-tcad3rst.js → classDiagram-v2-NBCMYWYE-bnf85z0f.js} +1 -1
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-a76vf82p.js → cose-bilkent-JH36ORCC-e290161f.js} +1 -1
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-9kety453.js → cynefinDiagram-VND7K2PF-s13ra9ag.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-6g6gsp6b.js → dagre-6A5THRUB-83wshh5e.js} +1 -1
- package/dist/client/static/js/{diagram-22UHCM2B-ngj4fyg3.js → diagram-22UHCM2B-ywh4wqna.js} +1 -1
- package/dist/client/static/js/{diagram-3UASUU5V-xw2m99qa.js → diagram-3UASUU5V-cb53z698.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-hz3bd083.js → diagram-ATOU4E4O-btf55c44.js} +1 -1
- package/dist/client/static/js/{diagram-CDSNMT55-vfhtemve.js → diagram-CDSNMT55-p6tbbm1n.js} +1 -1
- package/dist/client/static/js/{diagram-MLGK6HIB-22cjvj5g.js → diagram-MLGK6HIB-6kzssf4y.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-xv8fsecp.js → diagram-MPIPVDR6-4v0yncvv.js} +1 -1
- package/dist/client/static/js/{dockerfile-491tyqmj.js → dockerfile-r422htmd.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-m6mkn986.js → ebnfDiagram-ZINNZB2B-mw1gh30z.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-jccw706n.js → elk-276RUBZZ-1pe786ap.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-rxk86jsf.js → erDiagram-OPXOYQCR-x7rk70q6.js} +1 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-kfwaac44.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-veweech7.js → ganttDiagram-FUAMR5RP-j3m5km4p.js} +1 -1
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-7dyqcj8r.js → gitGraphDiagram-X574FWY7-fd1kebdy.js} +1 -1
- package/dist/client/static/js/{index-wa234c7k.js → index-004x0a3p.js} +1 -1
- package/dist/client/static/js/{index-637my5h0.js → index-0mhxw0a1.js} +1 -1
- package/dist/client/static/js/{index-dg714jam.js → index-22frp78d.js} +1 -1
- package/dist/client/static/js/{index-trpn9gxs.js → index-29b1ysz6.js} +1 -1
- package/dist/client/static/js/{index-bfy437re.js → index-3hrvhyym.js} +1 -1
- package/dist/client/static/js/{index-3x88fxzj.js → index-3k45gspr.js} +1 -1
- package/dist/client/static/js/{index-bhst1c2x.js → index-473wm10a.js} +1 -1
- package/dist/client/static/js/{index-d9dz0wt0.js → index-4acka5fn.js} +1 -1
- package/dist/client/static/js/{index-sx5x2q80.js → index-4dzvjfkd.js} +1 -1
- package/dist/client/static/js/{index-pqmvhqmj.js → index-4fpyzg5e.js} +7 -7
- package/dist/client/static/js/{index-xm3691yp.js → index-4jg10xtp.js} +1 -1
- package/dist/client/static/js/{index-0qmpqtp2.js → index-4nyajpeg.js} +1 -1
- package/dist/client/static/js/{index-4m94cbms.js → index-5fxm2tpg.js} +1 -1
- package/dist/client/static/js/{index-kfcpkx7h.js → index-72v57e07.js} +1 -1
- package/dist/client/static/js/{index-39mr4tym.js → index-7tsdw8wt.js} +1 -1
- package/dist/client/static/js/{index-0ak5wdz1.js → index-8e66p2a7.js} +1 -1
- package/dist/client/static/js/{index-7ehep28z.js → index-8n4qwd64.js} +2 -2
- package/dist/client/static/js/{index-2cfw7wem.js → index-bnamrpm6.js} +1 -1
- package/dist/client/static/js/{index-twjq786a.js → index-bxhszdcz.js} +1 -1
- package/dist/client/static/js/{index-e6tjaccf.js → index-cbbwq25c.js} +1 -1
- package/dist/client/static/js/{index-xq78fj64.js → index-dfha2z56.js} +1 -1
- package/dist/client/static/js/{index-r51fqzb5.js → index-drsy400d.js} +1 -1
- package/dist/client/static/js/{index-4kchzh9y.js → index-e4yj4kbe.js} +8 -8
- package/dist/client/static/js/{index-zjc8yfbe.js → index-g84dwmvr.js} +1 -1
- package/dist/client/static/js/index-gedsa0z7.css +1 -0
- package/dist/client/static/js/{index-x3g8fwkc.js → index-hge0y4vn.js} +2 -2
- package/dist/client/static/js/{index-cz80n8yc.js → index-hgsjynb0.js} +1 -1
- package/dist/client/static/js/{index-2asa0faw.js → index-j1prebvy.js} +2 -2
- package/dist/client/static/js/{index-wp7tsava.js → index-jbaceghb.js} +1 -1
- package/dist/client/static/js/{index-na95tr1k.js → index-jtyzeynv.js} +2 -2
- package/dist/client/static/js/{index-tk1vr8q2.js → index-kbk0vmex.js} +4 -4
- package/dist/client/static/js/{index-0xh8402w.js → index-q178zgxp.js} +1 -1
- package/dist/client/static/js/{index-gsw1zh30.js → index-q4t5j3x7.js} +1 -1
- package/dist/client/static/js/{index-xbvjpa60.js → index-qdabc51h.js} +3 -3
- package/dist/client/static/js/{index-7ckzdf4r.js → index-qrwjxqdh.js} +168 -168
- package/dist/client/static/js/{index-j0qt8gaj.js → index-rm5b3kn8.js} +1 -1
- package/dist/client/static/js/{index-nzjc24v9.js → index-s4v3vcsn.js} +1 -1
- package/dist/client/static/js/{index-wvqwzgpx.js → index-s6nv35dv.js} +1 -1
- package/dist/client/static/js/{index-088gwjbz.js → index-satnfvaz.js} +1 -1
- package/dist/client/static/js/{index-60fjqzdw.js → index-tcp5cp53.js} +1 -1
- package/dist/client/static/js/{index-5701gj1f.js → index-zkef5q39.js} +1 -1
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-ksz9cvq3.js → infoDiagram-VRGFBTTK-1m0br602.js} +1 -1
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-g8symmrp.js → ishikawaDiagram-OU5B5YK6-zryzhpq6.js} +1 -1
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-qs2e3hdf.js → journeyDiagram-ZHPQQLJL-6apqr7h4.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-pzef80sz.js → kanban-definition-PNTS6WVX-am385c1e.js} +1 -1
- package/dist/client/static/js/{mermaid.core-chfcvkkc.js → mermaid.core-k937exrm.js} +2 -2
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-sds2e243.js → mindmap-definition-NLK3R4M7-hx8qq866.js} +1 -1
- package/dist/client/static/js/one-dark-pro-phxqe9mx.js +1 -0
- package/dist/client/static/js/one-light-vhwh499y.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-m8199cy0.js → pegDiagram-GJSIUBJH-1hasj2h7.js} +1 -1
- package/dist/client/static/js/{pieDiagram-5QR66LMP-wqz5k5w6.js → pieDiagram-5QR66LMP-x5nwff8r.js} +1 -1
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-rjszd8an.js → quadrantDiagram-O4NWA36T-gmrcr5jb.js} +1 -1
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-qv0be7dh.js → railroadDiagram-XR7U4H2S-rdznfhfb.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-b87kqbr7.js → requirementDiagram-PLB6GJNP-v9wb3ppf.js} +1 -1
- package/dist/client/static/js/{rust-m7ma3tq9.js → rust-9cgnbbcs.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-dh5we479.js → sankeyDiagram-IPEJSGJF-3p4ddd2h.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-e6fg0x45.js → sequenceDiagram-PO4LG4MO-wfcqxjfq.js} +1 -1
- package/dist/client/static/js/{sizeCapture-INFHLROL-mam6cagq.js → sizeCapture-INFHLROL-g02k0k8x.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-htwar22v.js → stateDiagram-v2-GCMORJYK-7k449yvg.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-5g26cnkr.js → swimlanes-2SLR337P-zkf2bgm8.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-rseba3zs.js → swimlanesDiagram-TC7HE7FX-yex8g4fx.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-5km8n8mj.js → timeline-definition-EJHVYXUP-qsfpjr1c.js} +1 -1
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-0vt6ms5g.js → usecaseDiagram-POWQR4AR-b2vprhsr.js} +1 -1
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-k425105a.js → vennDiagram-UO4OBE2U-x0ffeg2t.js} +1 -1
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-s0gd4jg1.js → wardleyDiagram-VNRHLVJA-hsnhaf4f.js} +1 -1
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-2nrdzp7p.js → xychartDiagram-PMCCYNJV-90f9aadp.js} +1 -1
- package/package.json +3 -3
- package/src/client/components/settings/categories/chat-settings/ToolRenderSection.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/block-chrome.test.tsx +5 -3
- package/src/client/components/workspace/chat-timeline/index.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +41 -21
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +16 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.test.ts +105 -2
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +59 -8
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AgentAdmin.test.tsx +0 -13
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/AgentAdmin.tsx +6 -23
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/agent-admin-rows.test.ts +1 -39
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/agent-admin-rows.ts +11 -46
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.test.tsx +36 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/styles/Tui.tsx +10 -5
- package/src/client/hooks/chat/timeline/ask-frame-buckets.ts +14 -4
- package/src/client/hooks/chat/timeline/ask-frames-context.ts +3 -1
- package/src/client/hooks/chat/timeline/ask-frames-grouped.test.ts +31 -0
- package/src/client/hooks/chat/timeline/ask-frames.ts +12 -3
- package/src/client/hooks/chat/timeline/send-props.ts +1 -2
- package/src/server/lib/harness/acp/client-capabilities.test.ts +3 -2
- package/src/server/lib/sessions/last-opened.server.test.ts +26 -7
- package/src/server/lib/sessions/last-opened.server.ts +19 -4
- package/src/shared/lib/chat/ask-questions.test.ts +29 -0
- package/src/shared/lib/chat/ask-questions.ts +44 -3
- package/src/shared/lib/chat/ask-results.test.ts +66 -0
- package/src/shared/lib/chat/ask-results.ts +58 -0
- package/src/shared/lib/chat/timeline/block-chrome.ts +4 -4
- package/tsconfig.json +6 -0
- package/dist/client/static/js/MergeDiffView-n2h8vv0j.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-aegwx04w.js +0 -1
- package/dist/client/static/js/index-4m2d73m3.css +0 -1
- package/dist/client/static/js/one-dark-pro-5fvhpb1t.js +0 -1
- package/dist/client/static/js/one-light-pwj40vbr.js +0 -1
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
* defect — the head then reads as one undifferentiated run of text.
|
|
20
20
|
* - Facts are terminal text (`599ms · exit 0`), not pills, and a diff keeps
|
|
21
21
|
* `+4` green and `−1` red inside one statement.
|
|
22
|
+
* - The status line is PACKED: the subject hugs its clip instead of growing,
|
|
23
|
+
* and the toggle follows the data, so a pre-clipped `…` never floats far
|
|
24
|
+
* from the outcome and facts on its right.
|
|
22
25
|
* - The head is the toggle, with the SHARED wording (`toolToggleLabel`), so
|
|
23
26
|
* `chat.e2e.ts`'s `[aria-label^="Expand "]` collection and `mobile.e2e.ts`'s
|
|
24
27
|
* `/^Expand Bash/` click still work, and the section's per-call intent
|
|
@@ -99,6 +102,20 @@ const EDIT_TOOL: ToolCallData = {
|
|
|
99
102
|
details: { diff: 'a\n+b\n+c\n-d\n' },
|
|
100
103
|
} as ToolCallData;
|
|
101
104
|
|
|
105
|
+
/** A command longer than the header's 80-char clip, so its subtitle already
|
|
106
|
+
* ends in `…` before CSS touches it. */
|
|
107
|
+
const LONG_COMMAND_TOOL: ToolCallData = {
|
|
108
|
+
id: 'tui-long',
|
|
109
|
+
type: 'bash',
|
|
110
|
+
name: 'bash',
|
|
111
|
+
title: 'Bash',
|
|
112
|
+
status: 'success',
|
|
113
|
+
command: `bun test ${'--filter '.repeat(14)}`,
|
|
114
|
+
detail: `bun test ${'--filter '.repeat(14)}`,
|
|
115
|
+
input: { command: `bun test ${'--filter '.repeat(14)}` },
|
|
116
|
+
output: '',
|
|
117
|
+
} as ToolCallData;
|
|
118
|
+
|
|
102
119
|
async function mount(tools: ToolCallData[]): Promise<HTMLElement> {
|
|
103
120
|
await act(async () => {
|
|
104
121
|
render(
|
|
@@ -133,7 +150,10 @@ describe('the tui style', () => {
|
|
|
133
150
|
expect(el.querySelector('[data-tool-section]')?.getAttribute('data-tool-style')).toBe('tui');
|
|
134
151
|
|
|
135
152
|
const frame = row(el);
|
|
136
|
-
|
|
153
|
+
// The row is the transcript's own type, at the same size as every other
|
|
154
|
+
// style — not a monospace island inside the answer.
|
|
155
|
+
expect(frame.className).not.toContain('font-mono');
|
|
156
|
+
expect(head(el).className).toContain('text-[12px]');
|
|
137
157
|
// No card: no border, no fill, no rounded frame on the row.
|
|
138
158
|
expect(frame.className).not.toContain('border');
|
|
139
159
|
expect(frame.className).not.toContain('rounded');
|
|
@@ -152,6 +172,21 @@ describe('the tui style', () => {
|
|
|
152
172
|
expect(head(el).querySelector('.sr-only')?.textContent).toBe('Done');
|
|
153
173
|
});
|
|
154
174
|
|
|
175
|
+
test('the subject hugs its clip, so the ellipsis sits beside the outcome', async () => {
|
|
176
|
+
const el = await mount([LONG_COMMAND_TOOL]);
|
|
177
|
+
const children = Array.from(head(el).children) as HTMLElement[];
|
|
178
|
+
const subject = children.find((node) => node.className.includes('text-meta'));
|
|
179
|
+
if (!subject) throw new Error('no subject span in the head');
|
|
180
|
+
// A pre-clipped subject already ends in `…`; a growing box (`flex-1`) would
|
|
181
|
+
// park that ellipsis far from the outcome and facts on its right.
|
|
182
|
+
expect(subject.className).not.toContain('flex-1');
|
|
183
|
+
expect(subject.className).toContain('truncate');
|
|
184
|
+
expect(subject.textContent?.endsWith('…')).toBe(true);
|
|
185
|
+
expect(subject.nextElementSibling?.textContent).toContain('[done]');
|
|
186
|
+
// The toggle follows the data too, instead of being pushed to the far edge.
|
|
187
|
+
expect(children.at(-1)?.className).not.toContain('ml-auto');
|
|
188
|
+
});
|
|
189
|
+
|
|
155
190
|
test('title and subject are different colours', async () => {
|
|
156
191
|
const el = await mount([OK_TOOL]);
|
|
157
192
|
const classes = headClasses(el);
|
|
@@ -130,7 +130,7 @@ export const TuiRow = memo(function TuiRow({ tool, isOpen, onToggle, defaultExpa
|
|
|
130
130
|
}, [onToggle, tool.id]);
|
|
131
131
|
|
|
132
132
|
return (
|
|
133
|
-
<div data-tool-row="tui"
|
|
133
|
+
<div data-tool-row="tui">
|
|
134
134
|
{/* The status line itself: glyph, name, subject, outcome, facts. Text
|
|
135
135
|
only — the colours separate the three claims (what ran, on what, how
|
|
136
136
|
it ended), which is what the terminal does with SGR and what a box
|
|
@@ -144,7 +144,7 @@ export const TuiRow = memo(function TuiRow({ tool, isOpen, onToggle, defaultExpa
|
|
|
144
144
|
aria-label={
|
|
145
145
|
canToggle ? toolToggleLabel(view.header.title, view.subtitle, isExpanded) : undefined
|
|
146
146
|
}
|
|
147
|
-
className={`flex min-w-0 flex-1 flex-
|
|
147
|
+
className={`flex min-w-0 flex-1 flex-nowrap items-baseline gap-x-1 rounded px-1 py-0.5 text-left text-[12px] leading-[1.55] transition-colors ${
|
|
148
148
|
canToggle ? 'cursor-pointer hover:bg-ink/[0.03]' : 'cursor-default'
|
|
149
149
|
} focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ink/20`}
|
|
150
150
|
>
|
|
@@ -156,7 +156,12 @@ export const TuiRow = memo(function TuiRow({ tool, isOpen, onToggle, defaultExpa
|
|
|
156
156
|
{view.subtitle && (
|
|
157
157
|
<>
|
|
158
158
|
<span className="shrink-0 text-ink/25">:</span>
|
|
159
|
-
|
|
159
|
+
{/* The subject HUGS its text instead of growing (`flex-1`): a
|
|
160
|
+
pre-clipped command already ends in `…`, and a growing box
|
|
161
|
+
parked that ellipsis far from the outcome and facts on its
|
|
162
|
+
right. A long subject still shrinks and CSS-ellipsizes at the
|
|
163
|
+
box edge, so the ellipsis always sits beside the data. */}
|
|
164
|
+
<span className="min-w-0 shrink truncate font-mono text-[10.5px] text-meta">{view.subtitle}</span>
|
|
160
165
|
</>
|
|
161
166
|
)}
|
|
162
167
|
<span className={`shrink-0 font-semibold ${tone}`}>{`[${status.word.toLowerCase()}]`}</span>
|
|
@@ -167,7 +172,7 @@ export const TuiRow = memo(function TuiRow({ tool, isOpen, onToggle, defaultExpa
|
|
|
167
172
|
// The whole group carries the tooltip with every fact, so a clipped
|
|
168
173
|
// tail is still recoverable.
|
|
169
174
|
<span
|
|
170
|
-
className="min-w-0 shrink truncate text-[
|
|
175
|
+
className="min-w-0 shrink truncate font-mono text-[10px]"
|
|
171
176
|
title={facts.map((fact) => fact.label).join(' · ')}
|
|
172
177
|
>
|
|
173
178
|
<span className="text-ink/25">· </span>
|
|
@@ -175,7 +180,7 @@ export const TuiRow = memo(function TuiRow({ tool, isOpen, onToggle, defaultExpa
|
|
|
175
180
|
</span>
|
|
176
181
|
)}
|
|
177
182
|
{canToggle && (
|
|
178
|
-
<span className="
|
|
183
|
+
<span className="shrink-0 pl-1 text-ink/40" aria-hidden="true">
|
|
179
184
|
{isExpanded ? '▾' : '▸'}
|
|
180
185
|
</span>
|
|
181
186
|
)}
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
import type { ExtensionUiDialogRequest } from '@kabmo-labs/kabmo-chat/contracts/agent';
|
|
28
28
|
import type { AskQuestion } from '@/shared/lib/chat/ask-form/types';
|
|
29
|
-
import { groupAskFrames } from '@/shared/lib/chat/ask-questions';
|
|
29
|
+
import { askQuestionForTitle, groupAskFrames } from '@/shared/lib/chat/ask-questions';
|
|
30
30
|
|
|
31
31
|
export interface BucketedFrames {
|
|
32
32
|
/** One bucket per question, in form order. */
|
|
@@ -53,10 +53,20 @@ export function bucketAskFrames(
|
|
|
53
53
|
const unplaced: ExtensionUiDialogRequest[] = [];
|
|
54
54
|
for (const frame of frames) {
|
|
55
55
|
if (Array.isArray(frame.questions) && frame.questions.length > 0) {
|
|
56
|
+
const indexes = new Set<number>();
|
|
56
57
|
for (const grouped of frame.questions) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const byId = questions.findIndex((question) => question.id === grouped.id);
|
|
59
|
+
const index = byId >= 0 ? byId : askQuestionForTitle(questions, grouped.question);
|
|
60
|
+
if (index >= 0) indexes.add(index);
|
|
61
|
+
}
|
|
62
|
+
// A grouped frame covers every question it names. An ACP elicitation's
|
|
63
|
+
// ids are schema names (`q0`), so the tool call's question text is often
|
|
64
|
+
// the only shared key; if even that missed, the first bucket draws the
|
|
65
|
+
// card and `GroupedAsk` renders the frame's whole question set.
|
|
66
|
+
if (indexes.size === 0) {
|
|
67
|
+
if (placed[0]) placed[0].push(frame);
|
|
68
|
+
} else {
|
|
69
|
+
for (const index of indexes) placed[index].push(frame);
|
|
60
70
|
}
|
|
61
71
|
continue;
|
|
62
72
|
}
|
|
@@ -48,7 +48,9 @@ export interface AskFramesHandle {
|
|
|
48
48
|
orphanAsks: AskFramesSplit['orphanAsks'];
|
|
49
49
|
/** The ask's whole-form dialog, when it has one (see `formByTool`). */
|
|
50
50
|
formByTool: AskFramesSplit['formByTool'];
|
|
51
|
-
/**
|
|
51
|
+
/** The chat's harness. An ACP chat has no ask dialog frames; an `ask`
|
|
52
|
+
* tool call there answers from the next user message, not the card. */
|
|
53
|
+
harness?: string; /** Answer one ask dialog and drop it from the pending queue. */
|
|
52
54
|
respond: (request: ExtensionUiDialogRequest, response: ExtensionDialogResponse) => void;
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -104,6 +104,37 @@ describe('splitAskFrames with a grouped ask frame', () => {
|
|
|
104
104
|
expect(split.modalRequest).toBeNull();
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
test('an ACP elicitation claims its tool call by toolCallId', () => {
|
|
108
|
+
// opencode sends `question` as a normal tool call and the form separately;
|
|
109
|
+
// its schema ids (`q0`) are not the tool's arguments. The explicit
|
|
110
|
+
// toolCallId is the only exact key, and it must win over text matching.
|
|
111
|
+
const tool = {
|
|
112
|
+
id: 'call-question',
|
|
113
|
+
type: 'custom' as const,
|
|
114
|
+
title: 'question',
|
|
115
|
+
name: 'question',
|
|
116
|
+
status: 'running' as const,
|
|
117
|
+
input: { questions: [{ question: 'Which color should I use?', options: [{ label: 'Red' }, { label: 'Blue' }] }] },
|
|
118
|
+
};
|
|
119
|
+
const frame: ExtensionUiDialogRequest = {
|
|
120
|
+
type: 'extension_ui_request',
|
|
121
|
+
id: '9',
|
|
122
|
+
method: 'ask',
|
|
123
|
+
title: 'Questions',
|
|
124
|
+
toolCallId: 'call-question',
|
|
125
|
+
questions: [
|
|
126
|
+
{ id: 'q0', question: 'Which color should I use?', options: [{ label: 'Red' }, { label: 'Blue' }] },
|
|
127
|
+
{ id: 'q0_custom', question: 'Type your own answer', options: [] },
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
const history = { id: 'm1', role: 'ai', content: '', toolCalls: [tool] } as unknown as ChatMessageData;
|
|
131
|
+
|
|
132
|
+
const split = splitAskFrames([history], [frame], true);
|
|
133
|
+
expect(split.framesByTool.get('call-question')?.flat()).toEqual([frame]);
|
|
134
|
+
expect(split.orphanAsks).toEqual([]);
|
|
135
|
+
expect(split.modalRequest).toBeNull();
|
|
136
|
+
});
|
|
137
|
+
|
|
107
138
|
test('a grouped frame matches its card by question text when ids differ', () => {
|
|
108
139
|
const retitled: ExtensionUiDialogRequest = {
|
|
109
140
|
...grouped,
|
|
@@ -105,10 +105,19 @@ export function splitAskFrames(
|
|
|
105
105
|
continue;
|
|
106
106
|
}
|
|
107
107
|
if (grouped) {
|
|
108
|
+
// The ACP elicitation names the tool call outright; that is the exact
|
|
109
|
+
// owner and it survives a schema whose question text differs from the
|
|
110
|
+
// tool's own arguments.
|
|
111
|
+
const addressed = typeof request.toolCallId === 'string' ? request.toolCallId : '';
|
|
108
112
|
const ids = new Set(grouped.map((question) => question.id).filter(Boolean));
|
|
109
|
-
let groupedOwner =
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
let groupedOwner = addressed
|
|
114
|
+
? [...openAsks].reverse().find((candidate) => candidate.toolId === addressed)
|
|
115
|
+
: undefined;
|
|
116
|
+
if (!groupedOwner) {
|
|
117
|
+
groupedOwner = [...openAsks].reverse().find((candidate) =>
|
|
118
|
+
candidate.questions.some((question) => question.id && ids.has(question.id)),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
112
121
|
// The id walk is the exact key, but it is not the only one omp gives us:
|
|
113
122
|
// a call whose questions carry no `id` (measured on 2 of 161 real `ask`
|
|
114
123
|
// calls) yields an empty id set, and the frame then matched nothing and
|
|
@@ -25,10 +25,11 @@ describe('client capabilities', () => {
|
|
|
25
25
|
expect(KABMO_CLIENT_CAPABILITIES.session.notices).toEqual({});
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
-
test('
|
|
28
|
+
test('advertises the form elicitation the ask card can draw, but not URL mode', () => {
|
|
29
29
|
const advertised = KABMO_CLIENT_CAPABILITIES as Record<string, unknown>;
|
|
30
30
|
expect(advertised.terminal).toBeUndefined();
|
|
31
|
-
expect(advertised.elicitation).
|
|
31
|
+
expect(advertised.elicitation).toEqual({ form: {} });
|
|
32
|
+
expect((advertised.elicitation as { url?: unknown }).url).toBeUndefined();
|
|
32
33
|
});
|
|
33
34
|
});
|
|
34
35
|
|
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
const SESSION_ID = '42';
|
|
31
31
|
const CLIENT = '11111111-2222-4333-8444-555555555555';
|
|
32
32
|
const OTHER_CLIENT = '99999999-8888-4777-8666-555555555555';
|
|
33
|
+
/** No session is held by another process in these cases; ownership has its own. */
|
|
34
|
+
const free = async () => false;
|
|
33
35
|
let db: DbClient;
|
|
34
36
|
let priorMock: string | undefined;
|
|
35
37
|
|
|
@@ -58,13 +60,13 @@ afterAll(() => {
|
|
|
58
60
|
|
|
59
61
|
describe('lastOpenedSession', () => {
|
|
60
62
|
test('no record yet means no session to restore', async () => {
|
|
61
|
-
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
63
|
+
expect(await lastOpenedSession(CLIENT, free)).toBeNull();
|
|
62
64
|
});
|
|
63
65
|
|
|
64
66
|
test('a recorded session that still exists is restored', async () => {
|
|
65
67
|
expect(await recordLastOpenedSession(CLIENT, SESSION_ID)).toBe(true);
|
|
66
68
|
expect(await readLastOpenedSessionId(CLIENT)).toBe(SESSION_ID);
|
|
67
|
-
expect(await lastOpenedSession(CLIENT)).toBe(SESSION_ID);
|
|
69
|
+
expect(await lastOpenedSession(CLIENT, free)).toBe(SESSION_ID);
|
|
68
70
|
});
|
|
69
71
|
|
|
70
72
|
test('two clients keep separate pointers at one console', async () => {
|
|
@@ -72,15 +74,32 @@ describe('lastOpenedSession', () => {
|
|
|
72
74
|
|
|
73
75
|
// The second install never opened anything, so it restores the landing even
|
|
74
76
|
// though the first install has a record.
|
|
75
|
-
expect(await lastOpenedSession(OTHER_CLIENT)).toBeNull();
|
|
77
|
+
expect(await lastOpenedSession(OTHER_CLIENT, free)).toBeNull();
|
|
76
78
|
expect(await readLastOpenedSessionId(OTHER_CLIENT)).toBeNull();
|
|
77
79
|
});
|
|
78
80
|
|
|
81
|
+
// A session another instance is running must not be restored HERE: the tab
|
|
82
|
+
// would be redirected to that owner, and a password-protected owner turns the
|
|
83
|
+
// shell's launch into a navigation the user cannot complete — the reported
|
|
84
|
+
// reload loop. The row is NOT deleted: the session is valid, just unavailable
|
|
85
|
+
// until the writer lets it go.
|
|
86
|
+
test('a session another instance is writing is skipped and kept', async () => {
|
|
87
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
88
|
+
expect(await lastOpenedSession(CLIENT, async () => true)).toBeNull();
|
|
89
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBe(SESSION_ID);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('the same record restores once the other instance releases it', async () => {
|
|
93
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
94
|
+
expect(await lastOpenedSession(CLIENT, async () => true)).toBeNull();
|
|
95
|
+
expect(await lastOpenedSession(CLIENT, free)).toBe(SESSION_ID);
|
|
96
|
+
});
|
|
97
|
+
|
|
79
98
|
test('an archived session is refused and its record cleared', async () => {
|
|
80
99
|
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
81
100
|
await db.run('INSERT OR IGNORE INTO archived_sessions (session_id) VALUES (?)', [SESSION_ID]);
|
|
82
101
|
|
|
83
|
-
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
102
|
+
expect(await lastOpenedSession(CLIENT, free)).toBeNull();
|
|
84
103
|
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
85
104
|
});
|
|
86
105
|
|
|
@@ -88,7 +107,7 @@ describe('lastOpenedSession', () => {
|
|
|
88
107
|
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
89
108
|
await db.run('INSERT OR IGNORE INTO deleted_sessions (session_id) VALUES (?)', [SESSION_ID]);
|
|
90
109
|
|
|
91
|
-
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
110
|
+
expect(await lastOpenedSession(CLIENT, free)).toBeNull();
|
|
92
111
|
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
93
112
|
});
|
|
94
113
|
|
|
@@ -96,14 +115,14 @@ describe('lastOpenedSession', () => {
|
|
|
96
115
|
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
97
116
|
await db.run('DELETE FROM sessions WHERE id = ?', [SESSION_ID]);
|
|
98
117
|
|
|
99
|
-
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
118
|
+
expect(await lastOpenedSession(CLIENT, free)).toBeNull();
|
|
100
119
|
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
101
120
|
});
|
|
102
121
|
|
|
103
122
|
test('clearing leaves the next launch on the empty workspace', async () => {
|
|
104
123
|
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
105
124
|
await clearLastOpenedSession(CLIENT);
|
|
106
|
-
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
125
|
+
expect(await lastOpenedSession(CLIENT, free)).toBeNull();
|
|
107
126
|
});
|
|
108
127
|
});
|
|
109
128
|
|
|
@@ -46,6 +46,7 @@ import { isMockMode } from '@kabmo-labs/kabmo-runtime-flags';
|
|
|
46
46
|
import { isSinglePathSegment } from '@kabmo-labs/kabmo-paths/path-segment';
|
|
47
47
|
import { getDb } from '@/server/db.server';
|
|
48
48
|
import { isSessionArchived, sessionExists } from '@/server/lib/sessions/resolve.server';
|
|
49
|
+
import { isSessionOwnedElsewhere } from '@/server/lib/omp/session/ownership.server';
|
|
49
50
|
|
|
50
51
|
/** The stored id for one client, or null when there is none. */
|
|
51
52
|
export async function readLastOpenedSessionId(clientId: string): Promise<string | null> {
|
|
@@ -119,11 +120,25 @@ async function sessionCanOpen(sessionId: string): Promise<boolean> {
|
|
|
119
120
|
*
|
|
120
121
|
* A stale record is DELETED, not merely skipped: every later launch would
|
|
121
122
|
* otherwise repeat the same check for a session that can never come back.
|
|
123
|
+
*
|
|
124
|
+
* A session another process is WRITING is skipped but KEPT. Restoring it would
|
|
125
|
+
* bounce the tab to the owning instance — and when that peer is a
|
|
126
|
+
* password-protected Kabmo, the shell's launch has already been consumed by a
|
|
127
|
+
* navigation the user cannot complete, which reads as a reload loop on every
|
|
128
|
+
* start. The answer is the empty workspace, and the next launch after the owner
|
|
129
|
+
* lets the session go restores it again: the record is still valid, only
|
|
130
|
+
* unavailable now.
|
|
122
131
|
*/
|
|
123
|
-
export async function lastOpenedSession(
|
|
132
|
+
export async function lastOpenedSession(
|
|
133
|
+
clientId: string,
|
|
134
|
+
ownedElsewhere: (sessionId: string) => Promise<boolean> = isSessionOwnedElsewhere,
|
|
135
|
+
): Promise<string | null> {
|
|
124
136
|
const sessionId = await readLastOpenedSessionId(clientId);
|
|
125
137
|
if (!sessionId) return null;
|
|
126
|
-
if (await sessionCanOpen(sessionId))
|
|
127
|
-
|
|
128
|
-
|
|
138
|
+
if (!(await sessionCanOpen(sessionId))) {
|
|
139
|
+
await clearLastOpenedSession(clientId);
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (await ownedElsewhere(sessionId)) return null;
|
|
143
|
+
return sessionId;
|
|
129
144
|
}
|
|
@@ -9,6 +9,7 @@ import type { ToolCallData } from '@/shared/types';
|
|
|
9
9
|
import type { ExtensionUiDialogRequest } from '@kabmo-labs/kabmo-chat/contracts/agent';
|
|
10
10
|
import {
|
|
11
11
|
groupAskFrames,
|
|
12
|
+
isExternalAskTool,
|
|
12
13
|
parseAskQuestions,
|
|
13
14
|
normalizeAskText,
|
|
14
15
|
} from '@/shared/lib/chat/ask-questions';
|
|
@@ -54,6 +55,34 @@ describe('parseAskQuestions', () => {
|
|
|
54
55
|
const questions = parseAskQuestions(askTool({ questions: [{ id: 'a' }, { id: 'b', question: ' Keep me ' }] }));
|
|
55
56
|
expect(questions).toEqual([expect.objectContaining({ id: 'b', question: 'Keep me' })]);
|
|
56
57
|
});
|
|
58
|
+
|
|
59
|
+
test('reads a non-omp ask, including claude’s multiSelect and a single question', () => {
|
|
60
|
+
const claude = parseAskQuestions(askTool(
|
|
61
|
+
{ questions: [{ header: 'Approach', question: 'Which strategy?', multiSelect: true, options: [{ label: 'Balanced' }] }] },
|
|
62
|
+
{ name: 'AskUserQuestion' },
|
|
63
|
+
));
|
|
64
|
+
expect(claude).toEqual([expect.objectContaining({ header: 'Approach', question: 'Which strategy?', multi: true })]);
|
|
65
|
+
|
|
66
|
+
const single = parseAskQuestions(askTool(
|
|
67
|
+
{ question: 'Lanjut tes yang mana?', options: ['Image generation', 'Selesai'] },
|
|
68
|
+
{ name: 'ask_question' },
|
|
69
|
+
));
|
|
70
|
+
expect(single).toEqual([expect.objectContaining({
|
|
71
|
+
question: 'Lanjut tes yang mana?',
|
|
72
|
+
options: [{ label: 'Image generation' }, { label: 'Selesai' }],
|
|
73
|
+
})]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('keeps the legacy omp single-question payload out of the ask card', () => {
|
|
77
|
+
expect(parseAskQuestions(askTool({ question: 'single legacy shape', options: ['A'] }))).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('classifies only the adapter ask names as external', () => {
|
|
81
|
+
for (const name of ['ask_question', 'question', 'AskUserQuestion', 'ask_user', 'ask_user_question', 'request_user_input']) {
|
|
82
|
+
expect(isExternalAskTool({ ...askTool(undefined), name })).toBe(true);
|
|
83
|
+
}
|
|
84
|
+
expect(isExternalAskTool(askTool(undefined))).toBe(false);
|
|
85
|
+
});
|
|
57
86
|
});
|
|
58
87
|
|
|
59
88
|
describe('the 18.18.3 html form shape', () => {
|
|
@@ -108,10 +108,28 @@ function readOption(raw: unknown): AskOption | null {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
/** True for a tool call
|
|
111
|
+
/** True for a tool call whose question an ask frame may answer. */
|
|
112
112
|
export function isAskToolCall(tool: ToolCallData): boolean {
|
|
113
113
|
const name = typeof tool.name === 'string' && tool.name ? tool.name : tool.type;
|
|
114
|
-
return name === 'ask' || tool.title === 'ask';
|
|
114
|
+
return name === 'ask' || tool.title === 'ask' || isExternalAskTool(tool);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The names non-omp ACP adapters use for their own ask tool. The panel table
|
|
118
|
+
* maps every one to the ask card; the raw name is kept so the card knows the
|
|
119
|
+
* harness exposes no dialog and cannot be waited on. */
|
|
120
|
+
const EXTERNAL_ASK_NAMES: Readonly<Record<string, true>> = {
|
|
121
|
+
ask_question: true,
|
|
122
|
+
question: true,
|
|
123
|
+
askuserquestion: true,
|
|
124
|
+
ask_user: true,
|
|
125
|
+
ask_user_question: true,
|
|
126
|
+
request_user_input: true,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/** True when this call is an ACP agent's own ask, not omp's `ask`. */
|
|
130
|
+
export function isExternalAskTool(tool: ToolCallData): boolean {
|
|
131
|
+
const name = typeof tool.name === 'string' && tool.name ? tool.name : '';
|
|
132
|
+
return EXTERNAL_ASK_NAMES[name.toLowerCase()] === true;
|
|
115
133
|
}
|
|
116
134
|
|
|
117
135
|
/**
|
|
@@ -225,12 +243,35 @@ export function parseAskQuestions(tool: ToolCallData): AskQuestion[] {
|
|
|
225
243
|
options: Array.isArray(question.options)
|
|
226
244
|
? question.options.map(readOption).filter((option): option is AskOption => option !== null)
|
|
227
245
|
: [],
|
|
228
|
-
|
|
246
|
+
// claude's AskUserQuestion spells the flag `multiSelect`, antigravity
|
|
247
|
+
// `is_multi_select`; omp spells it `multi`.
|
|
248
|
+
multi: question.multi === true || question.multiSelect === true || question.is_multi_select === true,
|
|
229
249
|
recommended: typeof question.recommended === 'number' ? question.recommended : undefined,
|
|
230
250
|
kind: 'choice',
|
|
231
251
|
});
|
|
232
252
|
}
|
|
233
253
|
|
|
254
|
+
// A non-omp adapter may spell one question as a single object rather than
|
|
255
|
+
// an array. That shape never means anything for omp's own `ask` (the legacy
|
|
256
|
+
// single-question payload is deliberately ignored), so it is read only for
|
|
257
|
+
// the external names — the difference between a question card and raw JSON.
|
|
258
|
+
if (questions.length === 0 && record && isExternalAskTool(tool)) {
|
|
259
|
+
const text = typeof record.question === 'string' ? record.question.trim() : '';
|
|
260
|
+
const options = Array.isArray(record.options)
|
|
261
|
+
? record.options
|
|
262
|
+
: Array.isArray(record.choices) ? record.choices : [];
|
|
263
|
+
if (text) {
|
|
264
|
+
questions.push({
|
|
265
|
+
id: typeof record.id === 'string' ? record.id : undefined,
|
|
266
|
+
header: typeof record.header === 'string' && record.header.trim() ? record.header.trim() : undefined,
|
|
267
|
+
question: text,
|
|
268
|
+
options: options.map(readOption).filter((option): option is AskOption => option !== null),
|
|
269
|
+
multi: record.multi === true || record.multiSelect === true || record.is_multi_select === true,
|
|
270
|
+
kind: 'choice',
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
234
275
|
return questions;
|
|
235
276
|
}
|
|
236
277
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The result shapes the ACP adapters actually send.
|
|
8
|
+
*
|
|
9
|
+
* opencode records the picked labels positionally in
|
|
10
|
+
* `rawOutput.metadata.answers` and prints `"question"="answer"` prose; claude
|
|
11
|
+
* only prints the prose. Both completed the tool, so the card must show the
|
|
12
|
+
* answer it already delivered instead of redrawing the question as unanswered.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
import { parseAskResult } from './ask-results';
|
|
17
|
+
import type { ToolCallData } from '@/shared/types';
|
|
18
|
+
|
|
19
|
+
const QUESTIONS = [
|
|
20
|
+
{ question: 'Koneksi ini buat ngoding stack apa?', header: 'Stack', options: [{ label: 'TypeScript / JS' }, { label: 'Go' }] },
|
|
21
|
+
{ question: 'Gaya respons yang kamu mau?', header: 'Gaya Respons', options: [{ label: 'Singkat & langsung (Recommended)' }, { label: 'Detail' }] },
|
|
22
|
+
{ question: 'Mau aku lanjut ngerjain apa setelah ini?', header: 'Lanjutan', options: [{ label: 'Cek repo/folder ini dulu' }] },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function askTool(overrides: Record<string, unknown>): ToolCallData {
|
|
26
|
+
return {
|
|
27
|
+
id: 'call_question',
|
|
28
|
+
type: 'other',
|
|
29
|
+
title: 'question',
|
|
30
|
+
name: 'question',
|
|
31
|
+
status: 'success',
|
|
32
|
+
input: { questions: QUESTIONS },
|
|
33
|
+
...overrides,
|
|
34
|
+
} as ToolCallData;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('parseAskResult', () => {
|
|
38
|
+
test('opencode: positional metadata.answers align with the questions', () => {
|
|
39
|
+
const answers = parseAskResult(askTool({
|
|
40
|
+
details: {
|
|
41
|
+
answers: [
|
|
42
|
+
['TypeScript / JS'],
|
|
43
|
+
['Singkat & langsung (Recommended)'],
|
|
44
|
+
['Cek repo/folder ini dulu'],
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
}), QUESTIONS as never);
|
|
48
|
+
expect(answers).toEqual([
|
|
49
|
+
{ selectedOptions: ['TypeScript / JS'], timedOut: false },
|
|
50
|
+
{ selectedOptions: ['Singkat & langsung (Recommended)'], timedOut: false },
|
|
51
|
+
{ selectedOptions: ['Cek repo/folder ini dulu'], timedOut: false },
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('opencode/claude: the `"question"="answer"` prose is parsed when metadata is absent', () => {
|
|
56
|
+
const answers = parseAskResult(askTool({
|
|
57
|
+
name: 'AskUserQuestion',
|
|
58
|
+
output: 'Your questions have been answered: "Koneksi ini buat ngoding stack apa?"="TypeScript / JS", "Gaya respons yang kamu mau?"="Singkat & langsung (Recommended)", "Mau aku lanjut ngerjain apa setelah ini?"="Cek repo/folder ini dulu". You can now continue with the user\'s answers in mind.',
|
|
59
|
+
}), QUESTIONS as never);
|
|
60
|
+
expect(answers.map((answer) => answer?.selectedOptions[0])).toEqual([
|
|
61
|
+
'TypeScript / JS',
|
|
62
|
+
'Singkat & langsung (Recommended)',
|
|
63
|
+
'Cek repo/folder ini dulu',
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -55,6 +55,33 @@ function toAnswer(value: string, multi: boolean): AskAnswer {
|
|
|
55
55
|
*/
|
|
56
56
|
/** The form result's prose: the submitted JSON is the last `{…}` in the text. */
|
|
57
57
|
const FORM_RESULT = /(?:User answers:|submitted the form's current values:)[\s\S]*?(\{[\s\S]*\})\s*$/;
|
|
58
|
+
/** opencode and claude both print `"question"="answer"` pairs after a marker. */
|
|
59
|
+
const ANSWER_PAIRS = /"((?:[^"\\]|\\.)*)"\s*=\s*"((?:[^"\\]|\\.)*)"/g;
|
|
60
|
+
const ANSWER_PAIRS_MARKER = /(?:answered your questions|questions have been answered)/i;
|
|
61
|
+
|
|
62
|
+
function unescapePair(value: string): string {
|
|
63
|
+
return value.replace(/\\(["\\])/g, '$1');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** One picked/custom answer in the `"Q"="A"` prose shape. */
|
|
67
|
+
function fromProseAnswer(question: AskQuestion, raw: string): AskAnswer | null {
|
|
68
|
+
const answer = unescapePair(raw).trim();
|
|
69
|
+
if (!answer) return null;
|
|
70
|
+
const other = OTHER_ANSWER.exec(answer);
|
|
71
|
+
if (other) return { selectedOptions: [], customInput: other[1].trim() || undefined };
|
|
72
|
+
const parts = question.multi ? answer.split(', ') : [answer];
|
|
73
|
+
const selectedOptions: string[] = [];
|
|
74
|
+
const typed: string[] = [];
|
|
75
|
+
for (const part of parts) {
|
|
76
|
+
const label = question.options.find((option) => option.label === part.trim())?.label;
|
|
77
|
+
if (label) selectedOptions.push(label);
|
|
78
|
+
else if (part.trim()) typed.push(part.trim());
|
|
79
|
+
}
|
|
80
|
+
if (selectedOptions.length > 0 || question.options.length === 0) {
|
|
81
|
+
return { selectedOptions, ...(typed.length > 0 ? { customInput: typed.join(', ') } : {}) };
|
|
82
|
+
}
|
|
83
|
+
return { selectedOptions: [], customInput: typed.join(', ') || answer };
|
|
84
|
+
}
|
|
58
85
|
|
|
59
86
|
function parseAskOutputAnswers(output: string, questions: AskQuestion[]): (AskAnswer | null)[] {
|
|
60
87
|
const answers = questions.map((): AskAnswer | null => null);
|
|
@@ -76,6 +103,24 @@ function parseAskOutputAnswers(output: string, questions: AskQuestion[]): (AskAn
|
|
|
76
103
|
}
|
|
77
104
|
}
|
|
78
105
|
|
|
106
|
+
if (ANSWER_PAIRS_MARKER.test(text)) {
|
|
107
|
+
let cursor = 0;
|
|
108
|
+
let matched = false;
|
|
109
|
+
for (const pair of text.matchAll(ANSWER_PAIRS)) {
|
|
110
|
+
const questionText = unescapePair(pair[1]);
|
|
111
|
+
let index = questions.findIndex((question) => normalizeAskText(question.question) === normalizeAskText(questionText));
|
|
112
|
+
if (index === -1) index = questions.findIndex((question) => question.header && normalizeAskText(question.header) === normalizeAskText(questionText));
|
|
113
|
+
if (index === -1) index = cursor;
|
|
114
|
+
cursor = index + 1;
|
|
115
|
+
const answer = fromProseAnswer(questions[index], pair[2]);
|
|
116
|
+
if (answer) {
|
|
117
|
+
answers[index] = answer;
|
|
118
|
+
matched = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (matched) return answers;
|
|
122
|
+
}
|
|
123
|
+
|
|
79
124
|
const byId = new Map<string, AskAnswer>();
|
|
80
125
|
for (const line of text.split('\n')) {
|
|
81
126
|
const match = ANSWER_LINE.exec(line.trim());
|
|
@@ -161,6 +206,19 @@ export function parseAskResult(tool: ToolCallData, questions: AskQuestion[]): (A
|
|
|
161
206
|
const formAnswers = Array.isArray(details.answers) ? (details.answers as Record<string, unknown>[]) : null;
|
|
162
207
|
if (formAnswers && formAnswers.length > 0) {
|
|
163
208
|
const timedOut = details.timedOut === true;
|
|
209
|
+
// opencode's question tool records `metadata.answers` as one string[] per
|
|
210
|
+
// question, in order. Read positionally before the named-row shape below.
|
|
211
|
+
if (formAnswers.every((row) => Array.isArray(row))) {
|
|
212
|
+
for (let index = 0; index < answers.length; index += 1) {
|
|
213
|
+
const row = formAnswers[index];
|
|
214
|
+
if (!Array.isArray(row)) continue;
|
|
215
|
+
answers[index] = {
|
|
216
|
+
selectedOptions: row.filter((label): label is string => typeof label === 'string' && label.length > 0),
|
|
217
|
+
timedOut,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return answers;
|
|
221
|
+
}
|
|
164
222
|
for (const row of formAnswers) {
|
|
165
223
|
if (!row || typeof row !== 'object') continue;
|
|
166
224
|
const name = typeof row.name === 'string' ? row.name : '';
|
|
@@ -95,7 +95,7 @@ const MINIMAL: BlockChrome = {
|
|
|
95
95
|
/**
|
|
96
96
|
* `tui` — omp's terminal transcript. A block is a LINE of coloured text, not a
|
|
97
97
|
* box: the tool row draws its own status line (`styles/Tui.tsx`), and a
|
|
98
|
-
* thinking block or a notice wears the same frameless shape in the
|
|
98
|
+
* thinking block or a notice wears the same frameless shape, in the transcript's
|
|
99
99
|
* own type, with its name in the accent and its subject in the meta hue. The
|
|
100
100
|
* body hangs off a hairline rule, the way a terminal prints output under the
|
|
101
101
|
* command that produced it.
|
|
@@ -103,11 +103,11 @@ const MINIMAL: BlockChrome = {
|
|
|
103
103
|
const TUI: BlockChrome = {
|
|
104
104
|
root: '',
|
|
105
105
|
frame: '',
|
|
106
|
-
header: 'flex w-full items-center gap-2 px-1 py-0.5 text-left transition-colors
|
|
106
|
+
header: 'flex w-full items-center gap-2 px-1 py-0.5 text-left transition-colors',
|
|
107
107
|
icon: 'flex shrink-0 items-center justify-center',
|
|
108
|
-
title: 'shrink-0 text-[
|
|
108
|
+
title: 'shrink-0 text-[12px] font-semibold text-info',
|
|
109
109
|
subtitle: 'min-w-0 truncate font-mono text-[10.5px] text-meta',
|
|
110
|
-
body: 'my-1.5 ml-2 overflow-hidden border-l border-ink/10 py-1.5 pl-3
|
|
110
|
+
body: 'my-1.5 ml-2 overflow-hidden border-l border-ink/10 py-1.5 pl-3',
|
|
111
111
|
};
|
|
112
112
|
|
|
113
113
|
const BY_MODE: Record<ToolRenderMode, BlockChrome> = {
|