@kabmo-labs/kabmo 0.23.0 → 0.24.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.
Files changed (151) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +679 -679
  3. package/dist/client/static/js/{index-ph0q59rs.js → index-jcr5twtp.js} +769 -767
  4. package/dist/client/static/js/index-z3w7n85q.css +1 -0
  5. package/package.json +1 -1
  6. package/src/client/components/common/Modal.tsx +2 -6
  7. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
  8. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
  9. package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +23 -7
  10. package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
  11. package/src/client/components/layout/session-sidebar/about-modal/index.tsx +27 -11
  12. package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
  13. package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
  14. package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
  15. package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
  16. package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
  17. package/src/client/components/workspace/chat-timeline/index.tsx +2 -1
  18. package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
  19. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
  20. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
  21. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
  22. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
  23. package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
  24. package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
  25. package/src/client/components/workspace/file-explorer/index.tsx +9 -3
  26. package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
  27. package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
  28. package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
  29. package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
  30. package/src/client/data/settings/omp-schema.json +4 -4
  31. package/src/client/hooks/chat/timeline/actions.ts +2 -2
  32. package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
  33. package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
  34. package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
  35. package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
  36. package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
  37. package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
  38. package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
  39. package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
  40. package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
  41. package/src/client/hooks/chat/timeline/send-execute.test.ts +17 -0
  42. package/src/client/hooks/chat/timeline/send-props.ts +5 -3
  43. package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -3
  44. package/src/client/hooks/chat/timeline/send.test-util.ts +1 -1
  45. package/src/client/hooks/chat/timeline/send.test.ts +1 -3
  46. package/src/client/hooks/chat/timeline/send.ts +8 -3
  47. package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
  48. package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
  49. package/src/client/hooks/chat/timeline/session-load.ts +6 -14
  50. package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
  51. package/src/client/hooks/models/harness-catalog.ts +114 -0
  52. package/src/client/hooks/models/provider-writes.test.ts +81 -0
  53. package/src/client/hooks/models/provider-writes.ts +10 -3
  54. package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
  55. package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
  56. package/src/client/hooks/models/use-harnesses.test.ts +2 -1
  57. package/src/client/hooks/models/use-harnesses.ts +48 -114
  58. package/src/client/tailwind.css +9 -1
  59. package/src/server/lib/harness/acp/activation.test.ts +81 -0
  60. package/src/server/lib/harness/acp/activation.ts +72 -0
  61. package/src/server/lib/harness/acp/frames.test.ts +50 -1
  62. package/src/server/lib/harness/acp/frames.ts +17 -5
  63. package/src/server/lib/harness/acp/mapper.ts +6 -4
  64. package/src/server/lib/harness/acp/session-config.test.ts +73 -0
  65. package/src/server/lib/harness/acp/session-config.ts +87 -6
  66. package/src/server/lib/harness/acp/session-handshake.ts +9 -2
  67. package/src/server/lib/harness/acp/session-idle.ts +51 -0
  68. package/src/server/lib/harness/acp/session-notifications.ts +19 -3
  69. package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
  70. package/src/server/lib/harness/acp/session-options.ts +33 -0
  71. package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
  72. package/src/server/lib/harness/acp/session.test-util.ts +31 -2
  73. package/src/server/lib/harness/acp/session.test.ts +65 -3
  74. package/src/server/lib/harness/acp/session.ts +20 -20
  75. package/src/server/lib/harness/acp/turn.ts +31 -7
  76. package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
  77. package/src/server/lib/harness/auto-probe.server.ts +178 -0
  78. package/src/server/lib/harness/config.server.test.ts +1 -1
  79. package/src/server/lib/harness/config.server.ts +1 -1
  80. package/src/server/lib/harness/launch-table.ts +195 -0
  81. package/src/server/lib/harness/launch.test.ts +37 -0
  82. package/src/server/lib/harness/launch.ts +13 -115
  83. package/src/server/lib/harness/provider-entry.ts +32 -0
  84. package/src/server/lib/harness/provider-file.server.ts +3 -0
  85. package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
  86. package/src/server/lib/harness/provider-sources.server.ts +26 -2
  87. package/src/server/lib/harness/provider-write.server.ts +21 -32
  88. package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
  89. package/src/server/lib/harness/provider-zcode.server.ts +324 -0
  90. package/src/server/lib/harness/update-state.server.ts +15 -20
  91. package/src/server/lib/lifecycle/after-listen.ts +7 -0
  92. package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
  93. package/src/server/lib/models/registry-refresh.server.ts +98 -0
  94. package/src/server/lib/omp/rpc/child-config.ts +5 -4
  95. package/src/server/lib/omp/rpc/constants.test.ts +2 -1
  96. package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
  97. package/src/server/lib/omp/session/delete-flow.server.ts +15 -8
  98. package/src/server/lib/omp/session/delete.server.ts +12 -0
  99. package/src/server/routes/chat/rewind.test.ts +147 -0
  100. package/src/server/routes/chat/rewind.ts +29 -7
  101. package/src/server/routes/chat/session.test.ts +165 -10
  102. package/src/server/routes/chat/session.ts +60 -7
  103. package/src/server/routes/harness/import-action.ts +18 -4
  104. package/src/server/routes/harness/root.ts +8 -49
  105. package/src/server/routes/harness/toggle.test.ts +20 -0
  106. package/src/server/routes/harness/update.ts +49 -7
  107. package/src/server/routes/harness/versions.ts +5 -1
  108. package/src/server/routes/sessions/delete-acp.test.ts +227 -0
  109. package/src/server/routes/settings/model-override.ts +5 -2
  110. package/src/server/routes/settings/provider-entry.ts +2 -2
  111. package/src/server/routes/settings/provider-model.ts +2 -2
  112. package/src/server/routes/settings/provider-models.ts +2 -2
  113. package/src/server/routes/settings/provider-refresh.ts +6 -4
  114. package/src/server/routes/settings/providers.ts +3 -1
  115. package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
  116. package/src/shared/lib/chat/ask-form/fields.ts +76 -0
  117. package/src/shared/lib/chat/ask-form/index.ts +323 -0
  118. package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
  119. package/src/shared/lib/chat/ask-form/types.ts +43 -0
  120. package/src/shared/lib/chat/ask-form.test.ts +137 -0
  121. package/src/shared/lib/chat/ask-questions.test.ts +65 -1
  122. package/src/shared/lib/chat/ask-questions.ts +51 -145
  123. package/src/shared/lib/chat/ask-results.ts +198 -0
  124. package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
  125. package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
  126. package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
  127. package/src/shared/lib/harness/catalog.test.ts +1 -1
  128. package/src/shared/lib/harness/config-fields.test.ts +4 -0
  129. package/src/shared/lib/harness/config-fields.ts +19 -4
  130. package/src/shared/lib/harness/dialects.test.ts +8 -0
  131. package/src/shared/lib/harness/dialects.ts +12 -0
  132. package/src/shared/lib/harness/provider-facts.test.ts +32 -8
  133. package/src/shared/lib/harness/provider-facts.ts +46 -11
  134. package/src/shared/lib/harness/providers.ts +9 -0
  135. package/src/shared/lib/harness/rewind.ts +24 -0
  136. package/src/shared/lib/harness/update-plan.test.ts +51 -1
  137. package/src/shared/lib/harness/update-plan.ts +47 -7
  138. package/src/shared/lib/harness/updates.test.ts +22 -0
  139. package/src/shared/lib/harness/updates.ts +24 -1
  140. package/src/shared/lib/models/client.ts +10 -1
  141. package/src/shared/lib/omp/dialog-methods.ts +4 -3
  142. package/src/shared/lib/theme/css.ts +2 -0
  143. package/src/shared/lib/theme/ink-scale.ts +21 -1
  144. package/src/shared/lib/theme/theme.test.ts +25 -9
  145. package/src/shared/lib/ui/safe-area.test.ts +28 -0
  146. package/src/shared/lib/ui/safe-area.ts +42 -0
  147. package/src/shared/types/harness.ts +30 -4
  148. package/src/test-support/file-explorer-render.test-util.ts +37 -0
  149. package/src/test-support/file-explorer.test-util.ts +20 -18
  150. package/src/test-support/harness-table.test-util.ts +6 -3
  151. package/dist/client/static/js/index-jhmg4w91.css +0 -1
@@ -10,9 +10,9 @@ import type { ExtensionUiDialogRequest } from '@/shared/types/omp/agent';
10
10
  import {
11
11
  groupAskFrames,
12
12
  parseAskQuestions,
13
- parseAskResult,
14
13
  normalizeAskText,
15
14
  } from '@/shared/lib/chat/ask-questions';
15
+ import { parseAskResult } from '@/shared/lib/chat/ask-results';
16
16
 
17
17
  function askTool(input: unknown, extra: Partial<ToolCallData> = {}): ToolCallData {
18
18
  return { id: 'call_ask_1', type: 'ask', title: 'ask', name: 'ask', input: input as Record<string, unknown>, ...extra };
@@ -56,6 +56,70 @@ describe('parseAskQuestions', () => {
56
56
  });
57
57
  });
58
58
 
59
+ describe('the 18.18.3 html form shape', () => {
60
+ const FORM = `<form>
61
+ <p>Which store?</p>
62
+ <label><input type="radio" name="store" value="sqlite" checked> SQLite</label>
63
+ <label><input type="radio" name="store" value="redis"> Redis</label>
64
+ <label>Days <input type="number" name="days" value="30"></label>
65
+ <p>Sources?</p>
66
+ <label><input type="checkbox" name="sources" value="git"> Git</label>
67
+ <label><input type="checkbox" name="sources" value="jira"> Jira</label>
68
+ </form>`;
69
+ const questions = parseAskQuestions(askTool({ html: FORM }));
70
+
71
+ test('reads every named control as a question, in form order', () => {
72
+ expect(questions.map((question) => question.id)).toEqual(['store', 'days', 'sources']);
73
+ expect(questions.map((question) => question.question)).toEqual(['Which store?', 'Days', 'Sources?']);
74
+ expect(questions[0].options.map((option) => option.label)).toEqual([
75
+ 'SQLite',
76
+ 'Redis',
77
+ 'Other (type your own)',
78
+ ]);
79
+ expect(questions[2].multi).toBe(true);
80
+ });
81
+
82
+ test('reads details.answers by control name', () => {
83
+ const answers = parseAskResult(askTool({ html: FORM }, {
84
+ details: {
85
+ answers: [
86
+ { name: 'store', question: 'Which store?', answer: 'Redis' },
87
+ { name: 'days', question: 'Days', answer: '45' },
88
+ { name: 'sources', question: 'Sources?', answer: 'Git, Other: bitbucket' },
89
+ ],
90
+ },
91
+ }), questions);
92
+
93
+ expect(answers[0]).toEqual({ selectedOptions: ['Redis'], customInput: undefined, timedOut: false });
94
+ expect(answers[1]).toEqual({ selectedOptions: [], customInput: '45', timedOut: false });
95
+ expect(answers[2]).toEqual({ selectedOptions: ['Git'], customInput: 'bitbucket', timedOut: false });
96
+ });
97
+
98
+ test('flags the recorded answers when the timeout submitted the defaults', () => {
99
+ const answers = parseAskResult(askTool({ html: FORM }, {
100
+ details: { timedOut: true, answers: [{ name: 'store', question: 'Which store?', answer: 'SQLite' }] },
101
+ }), questions);
102
+ expect(answers[0]?.timedOut).toBe(true);
103
+ });
104
+
105
+ test('recovers the raw form data from the result text when details were dropped', () => {
106
+ const output = `User answers:\n{\n "store": "redis",\n "days": 45,\n "sources": ["git", "jira"]\n}`;
107
+ const answers = parseAskResult(askTool({ html: FORM }, { output }), questions);
108
+ expect(answers.map((answer) => answer?.selectedOptions)).toEqual([['Redis'], [], ['Git', 'Jira']]);
109
+ expect(answers[1]?.customInput).toBe('45');
110
+ });
111
+
112
+ test('puts a re-asked field, decorated with its validation error, on the same question', () => {
113
+ const frames: ExtensionUiDialogRequest[] = [
114
+ selectFrame('f1', 'Which store?'),
115
+ { type: 'extension_ui_request', id: 'f2', method: 'input', title: 'Days (Enter a number)' },
116
+ selectFrame('f3', '(1 selected) Sources?'),
117
+ ];
118
+ const groups = groupAskFrames(questions, frames);
119
+ expect(groups.map((group) => group.map((frame) => frame.id))).toEqual([['f1'], ['f2'], ['f3']]);
120
+ });
121
+ });
122
+
59
123
  describe('normalizeAskText', () => {
60
124
  test('strips the progress suffix and the multi-select prefix omp decorates titles with', () => {
61
125
  expect(normalizeAskText('Which language? (2/3)')).toBe('which language?');
@@ -4,52 +4,29 @@
4
4
  */
5
5
 
6
6
  /**
7
- * Pure helpers for omp's `ask` tool: read its `questions` payload, pair the
8
- * per-question dialogs omp raises for them back to the question they belong to,
9
- * and read the recorded answers out of the tool result.
7
+ * Pure helpers for omp's `ask` tool: read the questions it asked and pair the
8
+ * per-question dialogs omp raises for them back to the question they belong to.
9
+ * The answers live in `ask-results.ts`.
10
10
  *
11
- * The pairing is load-bearing, and there are TWO shapes to pair against.
12
- * `configureChild` opts the child into the rich dialog with
13
- * `set_ask_dialog {enabled:true}`, so omp's `AskTool` takes its `askDialog`
14
- * path and a multi-question ask arrives as ONE frame (`method:"ask"`) carrying
15
- * every question — matched by the question IDS it shares with the tool call's
16
- * arguments, which is what `ask-frames.ts` does.
11
+ * TWO payload shapes reach this file. Since 18.18.3 the tool takes ONE
12
+ * `{ html }` form (`ask-form/` parses it into questions) and the RPC host
13
+ * walks its named fields one dialog at a time — a `select`/`input`/`editor`
14
+ * per field, with the question as its title. Before that, the tool took
15
+ * `questions[]`, and a host that opted in with `set_ask_dialog` got every
16
+ * question in ONE `method:"ask"` frame matched by question ids. Persisted
17
+ * sessions keep the old shape, so both are still read; `set_ask_dialog` now
18
+ * only reaches extensions and omp's ratchet, not this tool.
17
19
  *
18
- * The per-question loop is still reachable (a host that never opted in, or a
19
- * build without the command), and there a multi-question ask reaches the
20
- * Kabmo as ONE blocking `select` frame per question, in order. That frame
21
- * carries the question as its `title` (plus a ` (2/3)` progress suffix and a
22
- * `(2 selected) ` prefix for multi-select questions), which is what lets the
23
- * inline card put each frame back on the question it asked. Both shapes must
24
- * keep working: the frame-ownership split knows each one.
20
+ * The title pairing is load-bearing: omp decorates a select's title with a
21
+ * `(2 selected) ` prefix and a ` (2/3)` progress suffix, and a rejected text
22
+ * answer re-asks as `question (Enter a number)`. What is left is what lets the
23
+ * inline card put each frame back on the question it asked.
25
24
  */
26
25
 
27
26
  import type { ToolCallData } from '@/shared/types';
28
27
  import type { ExtensionUiDialogRequest } from '@/shared/types/omp/agent';
29
-
30
- export interface AskOption {
31
- label: string;
32
- description?: string;
33
- preview?: string;
34
- }
35
-
36
- export interface AskQuestion {
37
- id?: string;
38
- /** Short chip omp shows above the question ("Authentication"). */
39
- header?: string;
40
- question: string;
41
- options: AskOption[];
42
- multi: boolean;
43
- /** Index of the option omp marks ` (Recommended)`. */
44
- recommended?: number;
45
- }
46
-
47
- export interface AskAnswer {
48
- selectedOptions: string[];
49
- customInput?: string;
50
- /** omp auto-selected the answer after `ask.timeout` elapsed. */
51
- timedOut?: boolean;
52
- }
28
+ import { parseAskForm } from '@/shared/lib/chat/ask-form';
29
+ import type { AskOption, AskQuestion } from '@/shared/lib/chat/ask-form/types';
53
30
 
54
31
  /** The free-text escape hatch omp appends to every question's option list. */
55
32
  const OTHER_OPTION = /^other\b/i;
@@ -75,6 +52,31 @@ export function normalizeAskText(value: string): string {
75
52
  .toLowerCase();
76
53
  }
77
54
 
55
+ /**
56
+ * Index of the question a dialog title names.
57
+ *
58
+ * Exact after the decorations are stripped, else the longest question the
59
+ * title starts with followed by ` (` — the shape omp's field-by-field walk
60
+ * uses for a rejected text answer (`question (Enter a number)`). Longest wins
61
+ * so `Pick a colour (light)` is not captured by an `Pick a colour` beside it.
62
+ */
63
+ export function askQuestionForTitle(questions: AskQuestion[], title: unknown): number {
64
+ if (typeof title !== 'string') return -1;
65
+ const needle = normalizeAskText(title);
66
+ if (!needle) return -1;
67
+ let best = -1;
68
+ let longest = 0;
69
+ for (let index = 0; index < questions.length; index += 1) {
70
+ const candidate = normalizeAskText(questions[index].question);
71
+ if (!candidate || candidate.length <= longest) continue;
72
+ if (needle === candidate || needle.startsWith(`${candidate} (`)) {
73
+ best = index;
74
+ longest = candidate.length;
75
+ }
76
+ }
77
+ return best;
78
+ }
79
+
78
80
  function readOption(raw: unknown): AskOption | null {
79
81
  if (typeof raw === 'string') {
80
82
  const label = raw.trim();
@@ -112,13 +114,18 @@ export function isAskSettled(tool: ToolCallData): boolean {
112
114
  }
113
115
 
114
116
  /**
115
- * The `questions` array from an `ask` tool call's arguments. Empty when the tool
116
- * is not an ask call or its arguments were truncated — callers fall back to the
117
+ * The questions of an `ask` tool call: parsed from its `html` form (18.18.3+),
118
+ * else from the `questions` array an older call carried. Empty when the tool is
119
+ * not an ask call or its arguments were truncated — callers fall back to the
117
120
  * raw arguments/output rendering in that case.
118
121
  */
119
122
  export function parseAskQuestions(tool: ToolCallData): AskQuestion[] {
120
123
  const input = tool.input;
121
124
  const record = typeof input === 'object' && input !== null ? (input as Record<string, unknown>) : null;
125
+ if (record && typeof record.html === 'string') {
126
+ const fromForm = parseAskForm(record.html);
127
+ if (fromForm.length > 0) return fromForm;
128
+ }
122
129
  const raw = record && Array.isArray(record.questions) ? record.questions : [];
123
130
  const questions: AskQuestion[] = [];
124
131
 
@@ -136,112 +143,13 @@ export function parseAskQuestions(tool: ToolCallData): AskQuestion[] {
136
143
  : [],
137
144
  multi: question.multi === true,
138
145
  recommended: typeof question.recommended === 'number' ? question.recommended : undefined,
146
+ kind: 'choice',
139
147
  });
140
148
  }
141
149
 
142
150
  return questions;
143
151
  }
144
152
 
145
- function readAnswer(row: Record<string, unknown>): AskAnswer {
146
- return {
147
- selectedOptions: Array.isArray(row.selectedOptions)
148
- ? row.selectedOptions.filter((value): value is string => typeof value === 'string')
149
- : [],
150
- customInput: typeof row.customInput === 'string' && row.customInput ? row.customInput : undefined,
151
- timedOut: row.timedOut === true,
152
- };
153
- }
154
-
155
- /** One `<id>: <answer>` line of a multi-question result. */
156
- const ANSWER_LINE = /^([\w.-]+):\s*(.+)$/;
157
- /** The single-question result's two prose shapes. */
158
- const SELECTED_LINE = /^User selected:\s*(.+)$/m;
159
- const CUSTOM_LINE = /^User provided custom input:\s*([\s\S]+)$/m;
160
-
161
- /** `value` as omp renders it: a quoted string is typed input, a bare one is a
162
- * picked label (comma-joined when the question allows several). */
163
- function toAnswer(value: string, multi: boolean): AskAnswer {
164
- const text = value.trim();
165
- if (/^"[\s\S]*"$/.test(text)) return { selectedOptions: [], customInput: text.slice(1, -1) };
166
- const labels = multi && text.includes(', ') ? text.split(', ') : [text];
167
- return { selectedOptions: labels.map((label) => label.trim()).filter(Boolean) };
168
- }
169
-
170
- /**
171
- * Answers recovered from the tool's rendered text, used when `details` never
172
- * reached this client. `details` is the richer source, but it is dropped by the
173
- * live `tool_execution_end` frame on some omp builds; the text is the one part
174
- * of a settled result every path carries, and it names each answer by question
175
- * id (`language: Python`) or as a single sentence for a one-question ask.
176
- */
177
- function parseAskOutputAnswers(output: string, questions: AskQuestion[]): (AskAnswer | null)[] {
178
- const answers = questions.map((): AskAnswer | null => null);
179
- const text = output.trim();
180
- if (!text) return answers;
181
-
182
- const byId = new Map<string, AskAnswer>();
183
- for (const line of text.split('\n')) {
184
- const match = ANSWER_LINE.exec(line.trim());
185
- if (match) byId.set(match[1], toAnswer(match[2], questions.some((question) => question.multi)));
186
- }
187
- if (byId.size > 0) {
188
- const ordered = [...byId.values()];
189
- for (let index = 0; index < questions.length; index += 1) {
190
- // The question id is the key omp prints; position is what is left when a
191
- // payload carries no ids at all (omp requires them, so this is defensive).
192
- const id = questions[index].id;
193
- answers[index] = (id ? byId.get(id) : undefined) ?? ordered[index] ?? null;
194
- }
195
- return answers;
196
- }
197
-
198
- const selected = SELECTED_LINE.exec(text);
199
- if (selected) {
200
- answers[0] = toAnswer(selected[1], questions[0].multi);
201
- return answers;
202
- }
203
- const custom = CUSTOM_LINE.exec(text);
204
- if (custom) {
205
- answers[0] = { selectedOptions: [], customInput: custom[1].trim() };
206
- return answers;
207
- }
208
- if (questions.length === 1 && !text.includes('\n')) {
209
- answers[0] = { selectedOptions: [text] };
210
- }
211
- return answers;
212
- }
213
-
214
- /**
215
- * Answers recorded in an `ask` tool result, positionally aligned with
216
- * `questions`. omp returns `details.results[]` for a multi-question ask and the
217
- * bare answer fields for a single-question one; the rendered text backs both up.
218
- */
219
- export function parseAskResult(tool: ToolCallData, questions: AskQuestion[]): (AskAnswer | null)[] {
220
- const answers = questions.map((): AskAnswer | null => null);
221
- if (questions.length === 0) return answers;
222
-
223
- const details = tool.details ?? {};
224
- const results = Array.isArray(details.results) ? (details.results as Record<string, unknown>[]) : null;
225
- if (results) {
226
- for (let index = 0; index < answers.length; index += 1) {
227
- const row = results[index];
228
- if (row && typeof row === 'object') answers[index] = readAnswer(row);
229
- }
230
- return answers;
231
- }
232
-
233
- if (typeof details.selectedOptions !== 'undefined' || typeof details.customInput === 'string') {
234
- answers[0] = readAnswer(details);
235
- return answers;
236
- }
237
-
238
- // A failed/cancelled ask answers nothing; its text is the reason, which would
239
- // otherwise read as an answer for whichever id its first sentence names.
240
- if (isAskSettled(tool) || tool.isError) return answers;
241
-
242
- return parseAskOutputAnswers(typeof tool.output === 'string' ? tool.output : '', questions);
243
- }
244
-
245
153
  /**
246
154
  * Bucket the ask's dialogs by question index.
247
155
  *
@@ -258,12 +166,10 @@ export function groupAskFrames(
258
166
  ): ExtensionUiDialogRequest[][] {
259
167
  const groups = questions.map((): ExtensionUiDialogRequest[] => []);
260
168
  if (questions.length === 0) return groups;
261
- const titles = questions.map((question) => normalizeAskText(question.question));
262
169
 
263
170
  let cursor = 0;
264
171
  for (const frame of frames) {
265
- const title = typeof frame.title === 'string' ? normalizeAskText(frame.title) : '';
266
- const index = titles.indexOf(title);
172
+ const index = askQuestionForTitle(questions, frame.title);
267
173
  if (index > cursor) {
268
174
  cursor = index;
269
175
  } else if (
@@ -0,0 +1,198 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Reads the answers out of an `ask` tool result.
8
+ *
9
+ * The 18.18.3 form shape records them in `details.answers[]` — `{ name,
10
+ * question, answer }` — and prints the submitted data as JSON in the result
11
+ * text; the older tool returned `details.results[]` for a multi-question ask
12
+ * and bare answer fields for a single-question one, with `id: answer` prose as
13
+ * the fallback. All three are read because persisted sessions keep the old
14
+ * shapes, and `details` is dropped by the live `tool_execution_end` frame on
15
+ * some builds, which is what the text fallback exists for.
16
+ */
17
+
18
+ import type { ToolCallData } from '@/shared/types';
19
+ import type { AskAnswer, AskQuestion } from '@/shared/lib/chat/ask-form/types';
20
+ import { isAskSettled, normalizeAskText } from '@/shared/lib/chat/ask-questions';
21
+
22
+ function readAnswer(row: Record<string, unknown>): AskAnswer {
23
+ return {
24
+ selectedOptions: Array.isArray(row.selectedOptions)
25
+ ? row.selectedOptions.filter((value): value is string => typeof value === 'string')
26
+ : [],
27
+ customInput: typeof row.customInput === 'string' && row.customInput ? row.customInput : undefined,
28
+ timedOut: row.timedOut === true,
29
+ };
30
+ }
31
+
32
+ /** One `<id>: <answer>` line of a multi-question result. */
33
+ const ANSWER_LINE = /^([\w.-]+):\s*(.+)$/;
34
+ /** The single-question result's two prose shapes. */
35
+ const SELECTED_LINE = /^User selected:\s*(.+)$/m;
36
+ const CUSTOM_LINE = /^User provided custom input:\s*([\s\S]+)$/m;
37
+
38
+ /** `value` as omp renders it: a quoted string is typed input, a bare one is a
39
+ * picked label (comma-joined when the question allows several). */
40
+ function toAnswer(value: string, multi: boolean): AskAnswer {
41
+ const text = value.trim();
42
+ if (/^"[\s\S]*"$/.test(text)) return { selectedOptions: [], customInput: text.slice(1, -1) };
43
+ const labels = multi && text.includes(', ') ? text.split(', ') : [text];
44
+ return { selectedOptions: labels.map((label) => label.trim()).filter(Boolean) };
45
+ }
46
+
47
+ /**
48
+ * Answers recovered from the tool's rendered text, used when `details` never
49
+ * reached this client. `details` is the richer source, but it is dropped by the
50
+ * live `tool_execution_end` frame on some omp builds; the text is the one part
51
+ * of a settled result every path carries. The form shape prints the submitted
52
+ * data as JSON after a marker line; the older tool named each answer by
53
+ * question id (`language: Python`) or drew a single sentence for a one-question
54
+ * ask.
55
+ */
56
+ /** The form result's prose: the submitted JSON is the last `{…}` in the text. */
57
+ const FORM_RESULT = /(?:User answers:|submitted the form's current values:)[\s\S]*?(\{[\s\S]*\})\s*$/;
58
+
59
+ function parseAskOutputAnswers(output: string, questions: AskQuestion[]): (AskAnswer | null)[] {
60
+ const answers = questions.map((): AskAnswer | null => null);
61
+ const text = output.trim();
62
+ if (!text) return answers;
63
+
64
+ const form = FORM_RESULT.exec(text);
65
+ if (form) {
66
+ try {
67
+ const data = JSON.parse(form[1]) as Record<string, unknown>;
68
+ const timedOut = text.startsWith('No answer before the timeout');
69
+ for (const [name, value] of Object.entries(data)) {
70
+ const index = questions.findIndex((question) => question.id === name);
71
+ if (index >= 0) answers[index] = { ...fromFormData(questions[index], value), timedOut };
72
+ }
73
+ return answers;
74
+ } catch {
75
+ // Not the form's JSON; the prose shapes below still get a chance.
76
+ }
77
+ }
78
+
79
+ const byId = new Map<string, AskAnswer>();
80
+ for (const line of text.split('\n')) {
81
+ const match = ANSWER_LINE.exec(line.trim());
82
+ if (match) byId.set(match[1], toAnswer(match[2], questions.some((question) => question.multi)));
83
+ }
84
+ if (byId.size > 0) {
85
+ const ordered = [...byId.values()];
86
+ for (let index = 0; index < questions.length; index += 1) {
87
+ // The question id is the key omp prints; position is what is left when a
88
+ // payload carries no ids at all (omp requires them, so this is defensive).
89
+ const id = questions[index].id;
90
+ answers[index] = (id ? byId.get(id) : undefined) ?? ordered[index] ?? null;
91
+ }
92
+ return answers;
93
+ }
94
+
95
+ const selected = SELECTED_LINE.exec(text);
96
+ if (selected) {
97
+ answers[0] = toAnswer(selected[1], questions[0].multi);
98
+ return answers;
99
+ }
100
+ const custom = CUSTOM_LINE.exec(text);
101
+ if (custom) {
102
+ answers[0] = { selectedOptions: [], customInput: custom[1].trim() };
103
+ return answers;
104
+ }
105
+ if (questions.length === 1 && !text.includes('\n')) {
106
+ answers[0] = { selectedOptions: [text] };
107
+ }
108
+ return answers;
109
+ }
110
+
111
+ /**
112
+ * The 18.18.3 result carries `details.answers[]` — one row per named control,
113
+ * `{ name, question, answer }` — with `answer` rendered the way omp's own
114
+ * `formAnswers` does: a picked option by its LABEL, `Other: <typed>` for free
115
+ * text, and ", "-joined labels for a checkbox group. Alignment is by control
116
+ * name, falling back to the question text.
117
+ */
118
+ const OTHER_ANSWER = /^Other:\s*([\s\S]*)$/i;
119
+
120
+ function fromFormAnswer(question: AskQuestion, answer: string): AskAnswer {
121
+ if (question.kind === 'text') return { selectedOptions: [], customInput: answer.trim() || undefined };
122
+ const parts = question.multi ? answer.split(', ') : [answer];
123
+ const selectedOptions: string[] = [];
124
+ let customInput: string | undefined;
125
+ for (const part of parts) {
126
+ const other = OTHER_ANSWER.exec(part.trim());
127
+ if (other) customInput = other[1].trim() || undefined;
128
+ else if (part.trim()) selectedOptions.push(part.trim());
129
+ }
130
+ return { selectedOptions, customInput };
131
+ }
132
+
133
+ /** Answers recovered from the raw form data in the tool's text, `{ name: value }`. */
134
+ function fromFormData(question: AskQuestion, value: unknown): AskAnswer {
135
+ if (question.kind === 'text') {
136
+ const text = typeof value === 'number' ? String(value) : typeof value === 'string' ? value.trim() : '';
137
+ return { selectedOptions: [], customInput: text || undefined };
138
+ }
139
+ const raw = Array.isArray(value) ? value.map((entry) => String(entry)) : value === undefined ? [] : [String(value)];
140
+ const selectedOptions: string[] = [];
141
+ const typed: string[] = [];
142
+ for (const entry of raw) {
143
+ const label = question.options.find((option) => option.value === entry)?.label;
144
+ if (label) selectedOptions.push(label);
145
+ else if (entry) typed.push(entry);
146
+ }
147
+ return { selectedOptions, customInput: typed.length > 0 ? typed.join(', ') : undefined };
148
+ }
149
+
150
+ /**
151
+ * Answers recorded in an `ask` tool result, positionally aligned with
152
+ * `questions`. The form shape records them in `details.answers[]`; the older
153
+ * tool returned `details.results[]` for a multi-question ask and the bare
154
+ * answer fields for a single-question one. The rendered text backs both up.
155
+ */
156
+ export function parseAskResult(tool: ToolCallData, questions: AskQuestion[]): (AskAnswer | null)[] {
157
+ const answers = questions.map((): AskAnswer | null => null);
158
+ if (questions.length === 0) return answers;
159
+
160
+ const details = tool.details ?? {};
161
+ const formAnswers = Array.isArray(details.answers) ? (details.answers as Record<string, unknown>[]) : null;
162
+ if (formAnswers && formAnswers.length > 0) {
163
+ const timedOut = details.timedOut === true;
164
+ for (const row of formAnswers) {
165
+ if (!row || typeof row !== 'object') continue;
166
+ const name = typeof row.name === 'string' ? row.name : '';
167
+ let index = name ? questions.findIndex((question) => question.id === name) : -1;
168
+ if (index === -1 && typeof row.question === 'string') {
169
+ const title = normalizeAskText(row.question);
170
+ index = questions.findIndex((question) => normalizeAskText(question.question) === title);
171
+ }
172
+ if (index === -1) continue;
173
+ const answer = typeof row.answer === 'string' ? row.answer : '';
174
+ answers[index] = { ...fromFormAnswer(questions[index], answer), timedOut };
175
+ }
176
+ return answers;
177
+ }
178
+
179
+ const results = Array.isArray(details.results) ? (details.results as Record<string, unknown>[]) : null;
180
+ if (results) {
181
+ for (let index = 0; index < answers.length; index += 1) {
182
+ const row = results[index];
183
+ if (row && typeof row === 'object') answers[index] = readAnswer(row);
184
+ }
185
+ return answers;
186
+ }
187
+
188
+ if (typeof details.selectedOptions !== 'undefined' || typeof details.customInput === 'string') {
189
+ answers[0] = readAnswer(details);
190
+ return answers;
191
+ }
192
+
193
+ // A failed/cancelled ask answers nothing; its text is the reason, which would
194
+ // otherwise read as an answer for whichever id its first sentence names.
195
+ if (isAskSettled(tool) || tool.isError) return answers;
196
+
197
+ return parseAskOutputAnswers(typeof tool.output === 'string' ? tool.output : '', questions);
198
+ }
@@ -23,6 +23,7 @@ import {
23
23
  queueStreamingUpdate,
24
24
  } from '@/shared/lib/chat/timeline/stream-coalescer';
25
25
  import { appendNoticeRow } from '@/shared/lib/chat/timeline/command-output';
26
+ import { reportPromptError } from '@/shared/lib/chat/timeline/prompt-error';
26
27
  import { retryNotice } from '@/shared/lib/chat/timeline/provider-retry';
27
28
  import { handleAgentStart, handleResumeStream, handleTurnStart } from '@/shared/lib/chat/timeline/run-signals';
28
29
  import { isAnswerableUiRequest } from '@/shared/lib/omp/dialog-methods';
@@ -271,8 +272,13 @@ export function createOmpAgentCallbacks(deps: OmpAgentCallbacksDeps): OmpAgentCa
271
272
  if (sid) setTimeout(() => refreshSessionMeta(sid), 150);
272
273
  },
273
274
  onPromptError: (errorMessage) => {
275
+ // Drop queued stream updates first: any frame from the failed run that
276
+ // has not been folded yet would resurrect partial content beside the row
277
+ // this error is about to mark.
278
+ disposeStreamingCoalescer();
274
279
  setGenerating(false);
275
280
  abortControllerRef.current = null;
281
+ reportPromptError(errorMessage, deps);
276
282
  console.error('OMP prompt error:', errorMessage);
277
283
  },
278
284
  // The prompt ran a built-in slash command (omp answered on the command
@@ -312,8 +318,14 @@ export function createOmpAgentCallbacks(deps: OmpAgentCallbacksDeps): OmpAgentCa
312
318
  const sid = adoptedSessionIdRef.current ?? sessionIdRef.current;
313
319
  if (sid) refreshSessionMeta(sid);
314
320
  },
315
- onNotice: (_level, message) => {
321
+ onNotice: (level, message) => {
316
322
  console.info('OMP notice:', message);
323
+ // A warning/error notice is the only place some transports report why a
324
+ // turn went nowhere (ACP can push an error `notice` instead of failing
325
+ // the prompt). A console line is not a surface the operator reads.
326
+ if ((level === 'error' || level === 'warning') && message.trim()) {
327
+ appendNoticeRow(message, deps);
328
+ }
317
329
  },
318
330
  onExtensionUiRequest: (request: IncomingExtensionUiRequest) => {
319
331
  // The blocking-method list is SHARED with the server