@kabmo-labs/kabmo 0.55.0 → 0.57.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-k96gtstv.js} +1 -1
- package/dist/client/static/js/{CsvGrid-ppj80brw.js → CsvGrid-t84xmbk9.js} +1 -1
- package/dist/client/static/js/{DocxView-ef0bd2pg.js → DocxView-4jda3szm.js} +1 -1
- package/dist/client/static/js/{DrawioView-44tpkzbd.js → DrawioView-9qvvtnvt.js} +1 -1
- package/dist/client/static/js/{HtmlPreview-w654aykz.js → HtmlPreview-4pba1ys5.js} +1 -1
- package/dist/client/static/js/{ImageView-kg0skt5s.js → ImageView-0gf5xdsv.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-qepkrtd8.js → LayoutWrapper-pwbq5syv.js} +2 -2
- package/dist/client/static/js/MergeDiffView-m4jkr786.js +1 -0
- package/dist/client/static/js/{Modal-8d299emm.js → Modal-yjszc3vy.js} +12 -12
- package/dist/client/static/js/{PdfView-eq7fnqa2.js → PdfView-sny55sne.js} +1 -1
- package/dist/client/static/js/{SessionsView-tedh2es3.js → SessionsView-q3800n83.js} +1 -1
- package/dist/client/static/js/{SheetView-5xm33kgk.js → SheetView-ezqak2b4.js} +1 -1
- package/dist/client/static/js/{SvgPreview-tp1m8r4t.js → SvgPreview-q1cvdf4s.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-xppr9jf1.js → abnfDiagram-O67JEVCF-ftm2qwa3.js} +1 -1
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-s23e6vtk.js → architectureDiagram-NJMV4G6O-j8kqfzmf.js} +3 -3
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-7ws8yq9e.js → blockDiagram-BEXU5L5S-m3zpsp9h.js} +3 -3
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-517yhfzj.js → c4Diagram-YGBWAQC7-myshvbrx.js} +2 -2
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-tcad3rst.js → classDiagram-v2-NBCMYWYE-s0cwmsj4.js} +1 -1
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-a76vf82p.js → cose-bilkent-JH36ORCC-t5t02sfr.js} +1 -1
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-9kety453.js → cynefinDiagram-VND7K2PF-6yxd72sh.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-6g6gsp6b.js → dagre-6A5THRUB-vft5103m.js} +1 -1
- package/dist/client/static/js/{diagram-22UHCM2B-ngj4fyg3.js → diagram-22UHCM2B-yy2jfvxt.js} +1 -1
- package/dist/client/static/js/{diagram-3UASUU5V-xw2m99qa.js → diagram-3UASUU5V-1xqhzq20.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-hz3bd083.js → diagram-ATOU4E4O-f11cxgvm.js} +1 -1
- package/dist/client/static/js/{diagram-CDSNMT55-vfhtemve.js → diagram-CDSNMT55-gqmkfcp7.js} +3 -3
- package/dist/client/static/js/{diagram-MLGK6HIB-22cjvj5g.js → diagram-MLGK6HIB-1fg7304a.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-xv8fsecp.js → diagram-MPIPVDR6-mem80369.js} +1 -1
- package/dist/client/static/js/{dockerfile-491tyqmj.js → dockerfile-jarjwxp9.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-m6mkn986.js → ebnfDiagram-ZINNZB2B-4rcbvfrj.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-jccw706n.js → elk-276RUBZZ-ykd0stxz.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-rxk86jsf.js → erDiagram-OPXOYQCR-b2th9bk4.js} +1 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-f3bdtc1z.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-veweech7.js → ganttDiagram-FUAMR5RP-64p5r7cx.js} +2 -2
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-7dyqcj8r.js → gitGraphDiagram-X574FWY7-z3yc333r.js} +1 -1
- package/dist/client/static/js/{index-wa234c7k.js → index-1mm7kyjd.js} +1 -1
- package/dist/client/static/js/{index-sx5x2q80.js → index-2gf593e3.js} +1 -1
- package/dist/client/static/js/{index-xm3691yp.js → index-3w18s59k.js} +1 -1
- package/dist/client/static/js/{index-60fjqzdw.js → index-3x3nhs8n.js} +1 -1
- package/dist/client/static/js/{index-2asa0faw.js → index-5m0se6fk.js} +2 -2
- package/dist/client/static/js/{index-tk1vr8q2.js → index-6m5n8b6w.js} +4 -4
- package/dist/client/static/js/{index-2cfw7wem.js → index-77wznmg5.js} +1 -1
- package/dist/client/static/js/{index-e6tjaccf.js → index-bwwgtesb.js} +1 -1
- package/dist/client/static/js/{index-5701gj1f.js → index-c2vc6znd.js} +1 -1
- package/dist/client/static/js/{index-d9dz0wt0.js → index-dxx49b9m.js} +1 -1
- package/dist/client/static/js/{index-4kchzh9y.js → index-e4yj4kbe.js} +8 -8
- package/dist/client/static/js/{index-twjq786a.js → index-ebnd5hnr.js} +1 -1
- package/dist/client/static/js/{index-zjc8yfbe.js → index-ep353yxd.js} +1 -1
- package/dist/client/static/js/{index-wvqwzgpx.js → index-ewtv8gg7.js} +1 -1
- package/dist/client/static/js/{index-na95tr1k.js → index-g71wn1pr.js} +2 -2
- package/dist/client/static/js/{index-bhst1c2x.js → index-gr07t5c4.js} +1 -1
- package/dist/client/static/js/{index-r51fqzb5.js → index-h4qmywn5.js} +1 -1
- package/dist/client/static/js/{index-x3g8fwkc.js → index-hge0y4vn.js} +2 -2
- package/dist/client/static/js/{index-nzjc24v9.js → index-hmjb96kb.js} +1 -1
- package/dist/client/static/js/{index-gsw1zh30.js → index-jd2h5tvh.js} +1 -1
- package/dist/client/static/js/{index-637my5h0.js → index-k57bandz.js} +1 -1
- package/dist/client/static/js/{index-xq78fj64.js → index-k6wms0kx.js} +1 -1
- package/dist/client/static/js/{index-39mr4tym.js → index-k9v6477a.js} +1 -1
- package/dist/client/static/js/{index-pqmvhqmj.js → index-kbaffwp1.js} +21 -21
- package/dist/client/static/js/{index-3x88fxzj.js → index-mdmtxh1c.js} +1 -1
- package/dist/client/static/js/{index-cz80n8yc.js → index-mv83hpva.js} +1 -1
- package/dist/client/static/js/{index-xbvjpa60.js → index-n71ffk62.js} +3 -3
- package/dist/client/static/js/{index-7ckzdf4r.js → index-nr5gwny1.js} +178 -178
- package/dist/client/static/js/{index-j0qt8gaj.js → index-q9gbwqbe.js} +3 -3
- package/dist/client/static/js/{index-0qmpqtp2.js → index-rqpbva78.js} +1 -1
- package/dist/client/static/js/{index-0xh8402w.js → index-sw370sk7.js} +1 -1
- package/dist/client/static/js/{index-0ak5wdz1.js → index-t415df0c.js} +1 -1
- package/dist/client/static/js/index-taz2nfym.css +1 -0
- package/dist/client/static/js/{index-dg714jam.js → index-w659dhe5.js} +1 -1
- package/dist/client/static/js/{index-trpn9gxs.js → index-wgcgshdh.js} +1 -1
- package/dist/client/static/js/{index-kfcpkx7h.js → index-x6945djv.js} +1 -1
- package/dist/client/static/js/{index-088gwjbz.js → index-y5mf2w81.js} +1 -1
- package/dist/client/static/js/{index-wp7tsava.js → index-y69cbdvd.js} +1 -1
- package/dist/client/static/js/{index-bfy437re.js → index-y6qtx68e.js} +1 -1
- package/dist/client/static/js/{index-4m94cbms.js → index-yktwxghr.js} +1 -1
- package/dist/client/static/js/{index-7ehep28z.js → index-zj65csnm.js} +2 -2
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-ksz9cvq3.js → infoDiagram-VRGFBTTK-59xq3n1b.js} +2 -2
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-g8symmrp.js → ishikawaDiagram-OU5B5YK6-v18q4qt7.js} +2 -2
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-qs2e3hdf.js → journeyDiagram-ZHPQQLJL-etazj0p8.js} +2 -2
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-pzef80sz.js → kanban-definition-PNTS6WVX-ph15e5p2.js} +1 -1
- package/dist/client/static/js/{mermaid.core-chfcvkkc.js → mermaid.core-7ygd161b.js} +2 -2
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-sds2e243.js → mindmap-definition-NLK3R4M7-j5xsftrf.js} +1 -1
- package/dist/client/static/js/one-dark-pro-4s2rr12v.js +1 -0
- package/dist/client/static/js/one-light-3bkk59ww.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-m8199cy0.js → pegDiagram-GJSIUBJH-09nvb70v.js} +1 -1
- package/dist/client/static/js/{pieDiagram-5QR66LMP-wqz5k5w6.js → pieDiagram-5QR66LMP-6ymh1960.js} +2 -2
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-rjszd8an.js → quadrantDiagram-O4NWA36T-hk61avw2.js} +2 -2
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-qv0be7dh.js → railroadDiagram-XR7U4H2S-3jvqrfnb.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-b87kqbr7.js → requirementDiagram-PLB6GJNP-zthfj48k.js} +1 -1
- package/dist/client/static/js/{rust-m7ma3tq9.js → rust-q7n7q6dy.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-dh5we479.js → sankeyDiagram-IPEJSGJF-nh5d6xte.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-e6fg0x45.js → sequenceDiagram-PO4LG4MO-crej9b40.js} +4 -4
- package/dist/client/static/js/{sizeCapture-INFHLROL-mam6cagq.js → sizeCapture-INFHLROL-nvvxw58j.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-htwar22v.js → stateDiagram-v2-GCMORJYK-e6tztjnj.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-5g26cnkr.js → swimlanes-2SLR337P-xhdqjqmf.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-rseba3zs.js → swimlanesDiagram-TC7HE7FX-hbwg3m3k.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-5km8n8mj.js → timeline-definition-EJHVYXUP-9cve31zc.js} +1 -1
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-0vt6ms5g.js → usecaseDiagram-POWQR4AR-asycstwe.js} +1 -1
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-k425105a.js → vennDiagram-UO4OBE2U-gbzk6era.js} +4 -4
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-s0gd4jg1.js → wardleyDiagram-VNRHLVJA-1swwfszr.js} +2 -2
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-2nrdzp7p.js → xychartDiagram-PMCCYNJV-v7qkwv0b.js} +3 -3
- package/package.json +4 -4
- 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/FormAsk.tsx +25 -62
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FormDialog.test.tsx +40 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FormDialog.tsx +41 -2
- 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/QuestionList.tsx +117 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/SwipeDeck.tsx +220 -0
- 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/data/settings/omp-schema.json +59 -7
- 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-form.test.ts +29 -0
- 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-form/data.ts +25 -6
- package/src/shared/lib/chat/ask-form/deck.ts +80 -0
- package/src/shared/lib/chat/ask-form/fields.ts +26 -1
- package/src/shared/lib/chat/ask-form/index.ts +18 -310
- package/src/shared/lib/chat/ask-form/types.ts +14 -2
- package/src/shared/lib/chat/ask-form/walker.ts +350 -0
- package/src/shared/lib/chat/ask-form.test.ts +41 -0
- 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/src/shared/lib/omp/config/schema-releases-19-4.test.ts +47 -0
- package/src/shared/lib/omp/config/schema-releases.test.ts +4 -2
- 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
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The token walker for the `ask` form parser (`index.ts`): walks one `<form>`
|
|
8
|
+
* in document order and collects the field drafts `fields.ts` turns into
|
|
9
|
+
* questions. Everything mutated lives in one context object, so the walk,
|
|
10
|
+
* the control collectors and the `<booldeck>` deck share it.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { DraftField, DraftOption } from '@/shared/lib/chat/ask-form/fields';
|
|
14
|
+
import { addDeck } from '@/shared/lib/chat/ask-form/deck';
|
|
15
|
+
import { IGNORED_INPUTS } from '@/shared/lib/chat/ask-form/labels';
|
|
16
|
+
import {
|
|
17
|
+
BLOCK,
|
|
18
|
+
findChild,
|
|
19
|
+
hasControl,
|
|
20
|
+
HEADING,
|
|
21
|
+
matchingClose,
|
|
22
|
+
nameLabel,
|
|
23
|
+
oneLine,
|
|
24
|
+
SKIPPED,
|
|
25
|
+
textOf,
|
|
26
|
+
type Token,
|
|
27
|
+
} from '@/shared/lib/chat/ask-form/tokens';
|
|
28
|
+
|
|
29
|
+
/** Everything the walk mutates while it collects one form. */
|
|
30
|
+
export interface WalkContext {
|
|
31
|
+
tokens: Token[];
|
|
32
|
+
labelFor: Map<string, string>;
|
|
33
|
+
fields: DraftField[];
|
|
34
|
+
groups: Map<string, DraftField>;
|
|
35
|
+
section: string;
|
|
36
|
+
caption: string;
|
|
37
|
+
inline: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Flush the pending inline run into the caption (one text block at a time). */
|
|
41
|
+
export function flush(ctx: WalkContext): void {
|
|
42
|
+
const text = oneLine(ctx.inline);
|
|
43
|
+
ctx.inline = '';
|
|
44
|
+
if (text) ctx.caption = text;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Add one field draft. The text block immediately before a control is its
|
|
49
|
+
* caption (omp's `fieldQuestions`), so the pending inline run must be flushed
|
|
50
|
+
* BEFORE the field is built — flushing after left `<span>Which?</span><select>`
|
|
51
|
+
* with the control's own name as its question.
|
|
52
|
+
*/
|
|
53
|
+
export function addField(ctx: WalkContext, field: DraftField): void {
|
|
54
|
+
flush(ctx);
|
|
55
|
+
field.caption = ctx.caption;
|
|
56
|
+
ctx.fields.push(field);
|
|
57
|
+
ctx.caption = '';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
function controlLabel(ctx: WalkContext, attrs: Record<string, string>, wrapping: string | undefined): string {
|
|
62
|
+
const own = wrapping !== undefined ? oneLine(wrapping) : '';
|
|
63
|
+
if (own) return own;
|
|
64
|
+
const detached = attrs.id ? ctx.labelFor.get(attrs.id) : undefined;
|
|
65
|
+
return detached ? oneLine(detached) : '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function addInput(ctx: WalkContext, attrs: Record<string, string>, wrapping: string | undefined): void {
|
|
69
|
+
const type = (attrs.type ?? 'text').toLowerCase();
|
|
70
|
+
if (IGNORED_INPUTS[type]) return;
|
|
71
|
+
const name = attrs.name ?? '';
|
|
72
|
+
if (type === 'radio' || type === 'checkbox') {
|
|
73
|
+
const value = attrs.value ?? 'on';
|
|
74
|
+
const option: DraftOption = {
|
|
75
|
+
value,
|
|
76
|
+
// omp's fallback is the RAW `value` attribute, else the name — not the
|
|
77
|
+
// `on` default a valueless checkbox submits. Using `on` made a lone
|
|
78
|
+
// checkbox's question "on" while omp's dialog title was its name.
|
|
79
|
+
label: controlLabel(ctx, attrs, wrapping) || attrs.value || name,
|
|
80
|
+
checked: 'checked' in attrs,
|
|
81
|
+
disabled: 'disabled' in attrs,
|
|
82
|
+
};
|
|
83
|
+
const key = `${type}\u0000${name}`;
|
|
84
|
+
const group = ctx.groups.get(key);
|
|
85
|
+
if (group) {
|
|
86
|
+
group.options.push(option);
|
|
87
|
+
// omp does the same (`group.field.required ||= required`): one member of
|
|
88
|
+
// the group marking it required makes the whole group required. Since
|
|
89
|
+
// 19.2.0 that only labels the group — a submission without a pick is
|
|
90
|
+
// accepted, and the model gets the rest of the form.
|
|
91
|
+
group.required ||= 'required' in attrs;
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const field: DraftField = {
|
|
95
|
+
name,
|
|
96
|
+
kind: 'choice',
|
|
97
|
+
multi: type === 'checkbox',
|
|
98
|
+
select: false,
|
|
99
|
+
label: '',
|
|
100
|
+
options: [option],
|
|
101
|
+
value: '',
|
|
102
|
+
multiline: false,
|
|
103
|
+
caption: ctx.caption,
|
|
104
|
+
section: ctx.section,
|
|
105
|
+
required: 'required' in attrs,
|
|
106
|
+
};
|
|
107
|
+
ctx.groups.set(key, field);
|
|
108
|
+
addField(ctx, field);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
addField(ctx, {
|
|
112
|
+
name,
|
|
113
|
+
kind: 'text',
|
|
114
|
+
multi: false,
|
|
115
|
+
select: false,
|
|
116
|
+
label: controlLabel(ctx, attrs, wrapping) || nameLabel(name),
|
|
117
|
+
options: [],
|
|
118
|
+
value: attrs.value ?? '',
|
|
119
|
+
multiline: false,
|
|
120
|
+
caption: ctx.caption,
|
|
121
|
+
section: ctx.section,
|
|
122
|
+
required: 'required' in attrs,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function addSelect(ctx: WalkContext, attrs: Record<string, string>, inner: Token[], wrapping: string | undefined): void {
|
|
127
|
+
const options: DraftOption[] = [];
|
|
128
|
+
for (let index = 0; index < inner.length; index += 1) {
|
|
129
|
+
const token = inner[index];
|
|
130
|
+
if (token.kind !== 'open' || token.tag !== 'option') continue;
|
|
131
|
+
const end = token.selfClosing ? index + 1 : matchingClose(inner, index, 'option');
|
|
132
|
+
const text = textOf(inner, index + 1, end);
|
|
133
|
+
options.push({
|
|
134
|
+
value: token.attrs.value ?? text,
|
|
135
|
+
label: text,
|
|
136
|
+
checked: 'selected' in token.attrs,
|
|
137
|
+
disabled: 'disabled' in token.attrs,
|
|
138
|
+
});
|
|
139
|
+
index = end;
|
|
140
|
+
}
|
|
141
|
+
const multi = 'multiple' in attrs;
|
|
142
|
+
if (!multi && options.length > 0 && !options.some((option) => option.checked)) {
|
|
143
|
+
const first = options.find((option) => !option.disabled);
|
|
144
|
+
if (first) first.checked = true;
|
|
145
|
+
}
|
|
146
|
+
addField(ctx, {
|
|
147
|
+
name: attrs.name ?? '',
|
|
148
|
+
kind: 'choice',
|
|
149
|
+
multi,
|
|
150
|
+
select: true,
|
|
151
|
+
label: controlLabel(ctx, attrs, wrapping),
|
|
152
|
+
options,
|
|
153
|
+
value: '',
|
|
154
|
+
multiline: false,
|
|
155
|
+
caption: ctx.caption,
|
|
156
|
+
section: ctx.section,
|
|
157
|
+
required: 'required' in attrs,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Walk a token range. `quiet` is a `<label>` that wraps controls: its text is
|
|
163
|
+
* the control's LABEL (already passed as `wrapping`), never a block of the
|
|
164
|
+
* form, so it must not caption the field it names.
|
|
165
|
+
*/
|
|
166
|
+
/** A `<fieldset>`: its legend titles the section at the top level. */
|
|
167
|
+
function walkFieldset(
|
|
168
|
+
ctx: WalkContext,
|
|
169
|
+
start: number,
|
|
170
|
+
close: number,
|
|
171
|
+
wrapping: string | undefined,
|
|
172
|
+
depth: number,
|
|
173
|
+
quiet: boolean,
|
|
174
|
+
): void {
|
|
175
|
+
const legendAt = findChild(ctx.tokens, start, close, 'legend');
|
|
176
|
+
if (depth === 0 && !quiet) {
|
|
177
|
+
// omp starts a NEW section at a top-level fieldset: the blocks before
|
|
178
|
+
// it (a `<p>` caption included) do not reach the fields inside, which
|
|
179
|
+
// borrow the legend instead. Keeping the caption made a form's
|
|
180
|
+
// explanatory paragraph caption the first field — and since that
|
|
181
|
+
// paragraph is not the title omp shows, the live dialog could not be
|
|
182
|
+
// matched back to the question.
|
|
183
|
+
ctx.caption = '';
|
|
184
|
+
ctx.section = legendAt === -1 ? '' : textOf(ctx.tokens, legendAt + 1, matchingClose(ctx.tokens, legendAt, 'legend'));
|
|
185
|
+
if (legendAt === -1) {
|
|
186
|
+
walk(ctx, start, close, wrapping, depth + 1);
|
|
187
|
+
} else {
|
|
188
|
+
walk(ctx, start, legendAt, wrapping, depth + 1);
|
|
189
|
+
walk(ctx, matchingClose(ctx.tokens, legendAt, 'legend') + 1, close, wrapping, depth + 1);
|
|
190
|
+
}
|
|
191
|
+
ctx.section = '';
|
|
192
|
+
} else {
|
|
193
|
+
walk(ctx, start, close, wrapping, depth + 1, quiet);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function walk(
|
|
198
|
+
ctx: WalkContext,
|
|
199
|
+
start: number,
|
|
200
|
+
end: number,
|
|
201
|
+
wrapping: string | undefined,
|
|
202
|
+
depth: number,
|
|
203
|
+
quiet = false,
|
|
204
|
+
): void {
|
|
205
|
+
const settle = () => {
|
|
206
|
+
if (!quiet) flush(ctx);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
for (let index = start; index < end; index += 1) {
|
|
210
|
+
const token = ctx.tokens[index];
|
|
211
|
+
if (token.kind === 'text') {
|
|
212
|
+
if (!quiet) ctx.inline += token.text;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const tag = token.tag;
|
|
216
|
+
if (tag.startsWith('/')) {
|
|
217
|
+
if (BLOCK[tag.slice(1)] || HEADING[tag.slice(1)] || tag === '/legend' || tag === '/pre' || tag === '/table') {
|
|
218
|
+
settle();
|
|
219
|
+
}
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (token.selfClosing) {
|
|
223
|
+
if (tag === 'br' && !quiet) ctx.inline += '\n';
|
|
224
|
+
else if (tag === 'hr') settle();
|
|
225
|
+
else if (tag === 'input') addInput(ctx, token.attrs, wrapping);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
// An unclosed tag (`<span class="truncate">` written literally inside a
|
|
229
|
+
// code span) has no `</span>`; `matchingClose` then answers the end of the
|
|
230
|
+
// document, and walking to it re-walked every field after the enclosing
|
|
231
|
+
// block — the same question appeared twice and the frame could not be
|
|
232
|
+
// placed. Clamp to the range this walk owns.
|
|
233
|
+
const close = Math.min(matchingClose(ctx.tokens, index, tag), end);
|
|
234
|
+
if (SKIPPED[tag]) {
|
|
235
|
+
index = close;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (tag === 'label') {
|
|
239
|
+
const target = token.attrs.for;
|
|
240
|
+
if (target && ctx.labelFor.has(target)) {
|
|
241
|
+
index = close;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
walk(ctx, index + 1, close, textOf(ctx.tokens, index + 1, close), depth, true);
|
|
245
|
+
index = close;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (tag === 'fieldset') {
|
|
249
|
+
settle();
|
|
250
|
+
walkFieldset(ctx, index + 1, close, wrapping, depth, quiet);
|
|
251
|
+
settle();
|
|
252
|
+
index = close;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (tag === 'legend' || HEADING[tag]) {
|
|
256
|
+
settle();
|
|
257
|
+
walk(ctx, index + 1, close, wrapping, depth, quiet);
|
|
258
|
+
settle();
|
|
259
|
+
index = close;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
if (BLOCK[tag]) {
|
|
263
|
+
settle();
|
|
264
|
+
walk(ctx, index + 1, close, wrapping, depth, quiet);
|
|
265
|
+
settle();
|
|
266
|
+
index = close;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
// A `<table>` of controls (a decision matrix) is LAYOUT: omp walks it, so
|
|
270
|
+
// the row's text captions the control and the field survives. Treating
|
|
271
|
+
// every table as prose dropped the fields entirely, and a tool call whose
|
|
272
|
+
// questions never parsed cannot claim its dialogs — the whole ask fell to
|
|
273
|
+
// the modal.
|
|
274
|
+
if (tag === 'table') {
|
|
275
|
+
settle();
|
|
276
|
+
if (hasControl(ctx.tokens, index + 1, close)) walk(ctx, index + 1, close, wrapping, depth, quiet);
|
|
277
|
+
else if (!quiet) ctx.caption = '';
|
|
278
|
+
settle();
|
|
279
|
+
index = close;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (tag === 'ul' || tag === 'ol' || tag === 'pre') {
|
|
283
|
+
settle();
|
|
284
|
+
// A list of controls is layout; any other list is a block, which clears
|
|
285
|
+
// the caption the next field would otherwise borrow.
|
|
286
|
+
if ((tag === 'ul' || tag === 'ol') && hasControl(ctx.tokens, index + 1, close)) {
|
|
287
|
+
walk(ctx, index + 1, close, wrapping, depth, quiet);
|
|
288
|
+
} else if (!quiet) {
|
|
289
|
+
ctx.caption = '';
|
|
290
|
+
}
|
|
291
|
+
settle();
|
|
292
|
+
index = close;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
// Cell boundaries separate one cell's text from the next; without them
|
|
296
|
+
// every cell in a row ran together into one caption.
|
|
297
|
+
if (tag === 'td' || tag === 'th' || tag === 'tr') {
|
|
298
|
+
settle();
|
|
299
|
+
walk(ctx, index + 1, close, wrapping, depth, quiet);
|
|
300
|
+
settle();
|
|
301
|
+
index = close;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (tag === 'input') {
|
|
305
|
+
addInput(ctx, token.attrs, wrapping);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (tag === 'select') {
|
|
309
|
+
addSelect(ctx, token.attrs, ctx.tokens.slice(index + 1, close), wrapping);
|
|
310
|
+
index = close;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (tag === 'booldeck') {
|
|
314
|
+
addDeck(ctx, token.attrs, index + 1, close);
|
|
315
|
+
index = close;
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
if (tag === 'card') {
|
|
319
|
+
// A card outside a deck carries nothing omp would answer: its name
|
|
320
|
+
// has no deck to submit into, so it is not a question.
|
|
321
|
+
index = close;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (tag === 'textarea') {
|
|
325
|
+
addField(ctx, {
|
|
326
|
+
name: token.attrs.name ?? '',
|
|
327
|
+
kind: 'text',
|
|
328
|
+
multi: false,
|
|
329
|
+
select: false,
|
|
330
|
+
label: controlLabel(ctx, token.attrs, wrapping) || nameLabel(token.attrs.name ?? ''),
|
|
331
|
+
options: [],
|
|
332
|
+
value: textOf(ctx.tokens, index + 1, close),
|
|
333
|
+
multiline: true,
|
|
334
|
+
caption: ctx.caption,
|
|
335
|
+
section: ctx.section,
|
|
336
|
+
required: 'required' in token.attrs,
|
|
337
|
+
});
|
|
338
|
+
index = close;
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (tag === 'img') {
|
|
342
|
+
settle();
|
|
343
|
+
if (!quiet) ctx.caption = '';
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
// Inline markup (`code`, `strong`, `em`, `a`, `span`, …): keep its text.
|
|
347
|
+
walk(ctx, index + 1, close, wrapping, depth, quiet);
|
|
348
|
+
index = close;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
@@ -187,6 +187,47 @@ describe('parseAskForm', () => {
|
|
|
187
187
|
expect(questions[0].options.map((option) => option.label)).toEqual(['A']);
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
+
test('a booldeck parses each card as a card question with yes/no/skip rows', () => {
|
|
191
|
+
// omp 19.4.0's `<booldeck>`: every `<card name>` is one swipe card whose
|
|
192
|
+
// question is its first text block and whose verdicts submit as
|
|
193
|
+
// booleans. Without this the whole form parsed to nothing and the live
|
|
194
|
+
// dialog could never be drawn.
|
|
195
|
+
const questions = parseAskForm(`<form>
|
|
196
|
+
<booldeck>
|
|
197
|
+
<card name="finding-one">Refactor the auth helper?</card>
|
|
198
|
+
<card name="finding-two">Lower the cache TTL?</card>
|
|
199
|
+
</booldeck>
|
|
200
|
+
</form>`);
|
|
201
|
+
expect(questions).toHaveLength(2);
|
|
202
|
+
expect(questions.map((question) => question.id)).toEqual(['finding-one', 'finding-two']);
|
|
203
|
+
expect(questions[0].kind).toBe('card');
|
|
204
|
+
expect(questions[0].question).toBe('Refactor the auth helper?');
|
|
205
|
+
expect(questions[0].options.map((option) => [option.label, option.value])).toEqual([
|
|
206
|
+
['Yes', 'yes'],
|
|
207
|
+
['No', 'no'],
|
|
208
|
+
['Skip', 'skip'],
|
|
209
|
+
]);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('a booldeck read only its first text block as the card question', () => {
|
|
213
|
+
const questions = parseAskForm(`<form><booldeck><card name="c"><p>First block</p><p>Second block</p></card></booldeck></form>`);
|
|
214
|
+
expect(questions[0].question).toBe('First block');
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('a booldeck resolves side labels per card over the deck', () => {
|
|
218
|
+
const questions = parseAskForm(
|
|
219
|
+
`<form><booldeck yes="Fix" no="Ignore"><card name="a">Leak?</card><card name="b" yes="Keep">TTL?</card></booldeck></form>`,
|
|
220
|
+
);
|
|
221
|
+
expect(questions[0].options.map((option) => option.label)).toEqual(['Fix', 'Ignore', 'Skip']);
|
|
222
|
+
expect(questions[1].options.map((option) => option.label)).toEqual(['Keep', 'Ignore', 'Skip']);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('a card without a name is not a question, and a card outside a deck is not either', () => {
|
|
226
|
+
const questions = parseAskForm(`<form><booldeck><card>Nameless?</card><card name="named">Named?</card></booldeck></form>`);
|
|
227
|
+
expect(questions.map((question) => question.id)).toEqual(['named']);
|
|
228
|
+
expect(parseAskForm(`<form><card name="stray">Stray?</card></form>`)).toEqual([]);
|
|
229
|
+
});
|
|
230
|
+
|
|
190
231
|
test('a lone checkbox with no value asks its name, not the submitted "on"', () => {
|
|
191
232
|
const questions = parseAskForm(`<form><input type="checkbox" name="ok"> I agree</form>`);
|
|
192
233
|
expect(questions[0].question).toBe('ok');
|
|
@@ -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> = {
|