@kabmo-labs/kabmo 0.10.1 → 0.11.1

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 (70) hide show
  1. package/dist/client/index.html +1 -1
  2. package/dist/client/index.js +391 -391
  3. package/dist/client/static/js/{index-135sdc46.js → index-amss8pge.js} +660 -659
  4. package/dist/client/static/js/index-bq6qeayr.css +1 -0
  5. package/package.json +1 -1
  6. package/src/client/components/common/code-surface/theme.ts +11 -5
  7. package/src/client/components/workspace/chat-timeline/chat-input/access-levels.ts +11 -2
  8. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/ApprovalBody.tsx +65 -0
  9. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Header.tsx +21 -2
  10. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/SelectBody.tsx +35 -19
  11. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/approval-gate.test.tsx +145 -0
  12. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/index.tsx +32 -104
  13. package/src/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/shortcuts.tsx +166 -0
  14. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +30 -0
  15. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +33 -27
  16. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +51 -0
  17. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +6 -0
  18. package/src/client/components/workspace/diff-panel/folding.test.ts +252 -0
  19. package/src/client/components/workspace/diff-panel/folding.ts +134 -0
  20. package/src/client/components/workspace/diff-panel/merge.ts +5 -0
  21. package/src/client/components/workspace/git-panel/InitRepository.tsx +49 -0
  22. package/src/client/components/workspace/git-panel/commit-modal.test.ts +193 -0
  23. package/src/client/components/workspace/git-panel/index.test.ts +3 -125
  24. package/src/client/components/workspace/git-panel/index.tsx +7 -1
  25. package/src/client/components/workspace/git-panel/init-state.test.ts +145 -0
  26. package/src/client/data/samples/virtual-devices-session.ts +8 -2
  27. package/src/client/data/settings/omp-schema.json +25 -3
  28. package/src/client/hooks/chat/timeline/ask-frames.test.ts +33 -0
  29. package/src/client/hooks/chat/timeline/ask-frames.ts +9 -1
  30. package/src/client/hooks/chat/timeline/index.ts +1 -0
  31. package/src/client/hooks/chat/timeline/send-execute.test.ts +14 -207
  32. package/src/client/hooks/chat/timeline/send-refusal.test.ts +72 -0
  33. package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
  34. package/src/client/hooks/chat/timeline/send.test-util.ts +245 -0
  35. package/src/client/hooks/chat/timeline/send.test.ts +1 -0
  36. package/src/client/hooks/chat/timeline/send.ts +10 -0
  37. package/src/server/lib/fs/git-actions-worktree.ts +25 -2
  38. package/src/server/lib/fs/git-actions.ts +3 -3
  39. package/src/server/lib/fs/git-status-read.test.ts +20 -0
  40. package/src/server/lib/fs/git-status-read.ts +43 -2
  41. package/src/server/lib/omp/rpc/constants.ts +15 -1
  42. package/src/server/lib/omp/rpc/manager.ts +1 -1
  43. package/src/server/lib/omp/rpc/prewarm-pool.ts +166 -0
  44. package/src/server/lib/omp/rpc/session-registry.ts +80 -164
  45. package/src/server/lib/omp/session/messages.test.ts +21 -0
  46. package/src/server/lib/omp/session/resumable-model.recovery.test.ts +194 -0
  47. package/src/server/lib/omp/session/resumable-model.server.test.ts +90 -0
  48. package/src/server/lib/omp/session/resumable-model.server.ts +181 -0
  49. package/src/server/lib/omp/session/standby.server.ts +1 -1
  50. package/src/server/routes/agent/command.ts +7 -1
  51. package/src/server/routes/agent/prewarm.ts +1 -1
  52. package/src/server/routes/fs/git-action.test.ts +4 -0
  53. package/src/server/routes/fs/git-init-action.test.ts +125 -0
  54. package/src/shared/lib/chat/notice-row.test.ts +25 -0
  55. package/src/shared/lib/chat/notice-row.ts +22 -1
  56. package/src/shared/lib/chat/omp/approval-gate.test.ts +99 -0
  57. package/src/shared/lib/chat/omp/approval-gate.ts +129 -0
  58. package/src/shared/lib/omp/config/schema.test.ts +12 -0
  59. package/src/shared/lib/omp/session/job-progress.test.ts +76 -0
  60. package/src/shared/lib/omp/session/job-progress.ts +84 -0
  61. package/src/shared/lib/omp/session/mapper.ts +3 -6
  62. package/src/shared/lib/omp/session/messages-map.test.ts +15 -6
  63. package/src/shared/lib/omp/session/messages-map.ts +19 -1
  64. package/src/shared/lib/omp/session/proc.test.ts +23 -0
  65. package/src/shared/lib/omp/session/proc.ts +17 -0
  66. package/src/shared/lib/omp/session/wait.test.ts +22 -0
  67. package/src/shared/lib/omp/session/wait.ts +14 -0
  68. package/src/test-support/fake-omp-restore.ts +153 -0
  69. package/src/test-support/file-explorer.test-util.ts +1 -1
  70. package/dist/client/static/js/index-snd9wk6w.css +0 -1
@@ -10,6 +10,18 @@ interface ExtensionDialogSelectBodyProps {
10
10
  customInputRef: RefObject<HTMLInputElement>;
11
11
  onSelect: (option: string) => void;
12
12
  onConfirmOption: (option: string) => void;
13
+ /**
14
+ * Hide the free-text "Other" field.
15
+ *
16
+ * The field exists for an `ask` question, whose option list ends in
17
+ * "Other (type your own)" — a prompt to type an answer. omp's APPROVAL
18
+ * gate offers no such option: its choices are "Approve" and "Deny", and
19
+ * omp's own answer parser (`approvalAnswerForChoice`) treats ANY other
20
+ * string as a DENY. So a free-text field on a gate is a way to deny the
21
+ * call by typing near-miss text ("ok", "sure", "yep") and never to approve
22
+ * it — measured: "Approve" → allow, "yes please" → deny.
23
+ */
24
+ hideCustomAnswer?: boolean;
13
25
  }
14
26
 
15
27
  export function ExtensionDialogSelectBody({
@@ -21,6 +33,7 @@ export function ExtensionDialogSelectBody({
21
33
  customInputRef,
22
34
  onSelect,
23
35
  onConfirmOption,
36
+ hideCustomAnswer = false,
24
37
  }: ExtensionDialogSelectBodyProps) {
25
38
  return (
26
39
  <div className="space-y-2">
@@ -86,25 +99,28 @@ export function ExtensionDialogSelectBody({
86
99
  </div>
87
100
 
88
101
  {/* Free-text answer for "Other"-style options: typing here wins over the
89
- highlighted option, since the literal option text is not an answer. */}
90
- <div className="space-y-1.5 pt-1">
91
- <div className="text-[11px] font-medium tracking-wider text-ink/50 uppercase">Other — type your own answer</div>
92
- <input
93
- ref={customInputRef}
94
- type="text"
95
- value={customValue}
96
- placeholder="Type a custom answer and press Enter..."
97
- onChange={(e) => onCustomChange(e.currentTarget.value)}
98
- onKeyDown={(e) => {
99
- if (e.key === 'Enter') {
100
- e.preventDefault();
101
- e.stopPropagation();
102
- if (customValue.trim()) onConfirmOption(customValue.trim());
103
- }
104
- }}
105
- className="w-full rounded-xl border border-ink/15 bg-paper px-4 py-3 text-[13.5px] text-ink placeholder:text-ink/35 outline-none transition-all focus:border-ink focus:ring-2 focus:ring-ink/15"
106
- />
107
- </div>
102
+ highlighted option, since the literal option text is not an answer.
103
+ An approval gate has no "Other" option, so it draws no field. */}
104
+ {!hideCustomAnswer && (
105
+ <div className="space-y-1.5 pt-1">
106
+ <div className="text-[11px] font-medium tracking-wider text-ink/50 uppercase">Other — type your own answer</div>
107
+ <input
108
+ ref={customInputRef}
109
+ type="text"
110
+ value={customValue}
111
+ placeholder="Type a custom answer and press Enter..."
112
+ onChange={(e) => onCustomChange(e.currentTarget.value)}
113
+ onKeyDown={(e) => {
114
+ if (e.key === 'Enter') {
115
+ e.preventDefault();
116
+ e.stopPropagation();
117
+ if (customValue.trim()) onConfirmOption(customValue.trim());
118
+ }
119
+ }}
120
+ className="w-full rounded-xl border border-ink/15 bg-paper px-4 py-3 text-[13.5px] text-ink placeholder:text-ink/35 outline-none transition-all focus:border-ink focus:ring-2 focus:ring-ink/15"
121
+ />
122
+ </div>
123
+ )}
108
124
  </div>
109
125
  );
110
126
  }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * What omp's TOOL-APPROVAL gate looks like on screen.
8
+ *
9
+ * The gate is a `select` frame whose title is omp's whole prompt,
10
+ * newline-separated. Two things about that shape are load-bearing and each
11
+ * was measured against omp 18.13.1:
12
+ *
13
+ * - The title is a ONE-LINE field, and the header rendered it with
14
+ * `truncate`, so the reason and the path were clipped out of the only
15
+ * element that could show them. The gate read "Allow tool: read" over a
16
+ * command the user never saw — and "Approve" without the thing being
17
+ * approved is not a decision.
18
+ * - omp's answer parser reads any answer that is not one of its choice
19
+ * labels as a DENY (measured: "Approve" allows, "yes please" denies), so
20
+ * the free-text "Other" field the `ask` question needs is, on a gate, a
21
+ * way to refuse the call by typing near-miss text.
22
+ *
23
+ * The frames below are omp's own, verbatim.
24
+ */
25
+
26
+ import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
27
+ import { Window } from 'happy-dom';
28
+ import { h, render } from 'preact';
29
+ import { act } from 'preact/test-utils';
30
+ import { ExtensionDialog } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog';
31
+ import type { ExtensionUiDialogRequest } from '@/shared/types/omp/agent';
32
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
33
+
34
+ /** omp's gate for a restricted-folder read. */
35
+ const RESTRICTED_READ: ExtensionUiDialogRequest = {
36
+ type: 'extension_ui_request',
37
+ id: 'g1',
38
+ method: 'select',
39
+ title: [
40
+ 'Allow tool: read',
41
+ 'Reason: Restricted folder: /tmp/livetest/secret',
42
+ 'Path: /tmp/livetest/secret/creds.txt',
43
+ ].join('\n'),
44
+ options: ['Approve', 'Deny'],
45
+ };
46
+
47
+ /** omp's gate for a bash call under `always-ask`. */
48
+ const BASH_GATE: ExtensionUiDialogRequest = {
49
+ type: 'extension_ui_request',
50
+ id: 'g2',
51
+ method: 'select',
52
+ title: ['Allow tool: bash', 'Command: ls -la /tmp/livetest'].join('\n'),
53
+ options: ['Approve', 'Deny'],
54
+ };
55
+
56
+ /** An `ask` question's own dialog — the shape the free-text field serves. */
57
+ const QUESTION: ExtensionUiDialogRequest = {
58
+ type: 'extension_ui_request',
59
+ id: 'q1',
60
+ method: 'select',
61
+ title: 'Which language?',
62
+ options: ['Python', 'Other (type your own)'],
63
+ };
64
+
65
+ let container: HTMLElement;
66
+
67
+ beforeEach(() => {
68
+ installDomGlobals(new Window());
69
+ container = document.createElement('div');
70
+ document.body.appendChild(container);
71
+ });
72
+
73
+ afterEach(() => {
74
+ render(null, container);
75
+ container.remove();
76
+ restoreDomGlobals();
77
+ });
78
+
79
+ afterAll(() => restoreDomGlobals());
80
+
81
+ /** Mount the dialog and return the text it draws. */
82
+ function draw(request: ExtensionUiDialogRequest): string {
83
+ render(h(ExtensionDialog, { request, onRespond: () => {} }), container);
84
+ return container.textContent ?? '';
85
+ }
86
+
87
+ describe('omp\'s tool-approval gate', () => {
88
+ test('the reason and the path it approves are both on screen', () => {
89
+ const text = draw(RESTRICTED_READ);
90
+
91
+ expect(text).toContain('Restricted folder: /tmp/livetest/secret');
92
+ expect(text).toContain('/tmp/livetest/secret/creds.txt');
93
+ // The header names the TOOL, not the whole prompt.
94
+ expect(text).toContain('Allow read');
95
+ });
96
+
97
+ test('the command it approves is on screen', () => {
98
+ const text = draw(BASH_GATE);
99
+ expect(text).toContain('ls -la /tmp/livetest');
100
+ expect(text).toContain('Allow bash');
101
+ });
102
+
103
+ test('the free-text field is not offered on a gate', () => {
104
+ // omp reads any non-label answer as a DENY, so a free-text field here can
105
+ // only refuse the call.
106
+ const text = draw(RESTRICTED_READ);
107
+ expect(text).not.toContain('type your own answer');
108
+ expect(container.querySelector('input[type="text"]')).toBeNull();
109
+ });
110
+
111
+ test('an ask question still offers its free-text field', () => {
112
+ // The gate's rule must not take the question's field away: a question's
113
+ // option list ends in "Other (type your own)" and needs the escape hatch.
114
+ const text = draw(QUESTION);
115
+ expect(text).toContain('type your own answer');
116
+ });
117
+ });
118
+
119
+ describe('the gate\'s answer', () => {
120
+ test('a typed answer cannot answer a gate — it is always a deny', async () => {
121
+ const sent: unknown[] = [];
122
+ await act(async () => {
123
+ render(
124
+ h(ExtensionDialog, {
125
+ request: RESTRICTED_READ,
126
+ onRespond: (_request, response) => sent.push(response),
127
+ }),
128
+ container,
129
+ );
130
+ });
131
+
132
+ // omp reads any non-label answer as a deny, so the dialog must not even
133
+ // offer a free-text field on a gate.
134
+ expect(container.querySelector('input[type="text"]')).toBeNull();
135
+
136
+ // The chosen option is what answers, verbatim — a label omp recognises.
137
+ const submit = [...container.querySelectorAll('button')]
138
+ .find((button) => button.textContent?.includes('Select Option'));
139
+ expect(submit).toBeDefined();
140
+ await act(async () => {
141
+ submit!.click();
142
+ });
143
+ expect(sent).toEqual([{ value: 'Approve' }]);
144
+ });
145
+ });
@@ -1,10 +1,13 @@
1
1
 
2
2
  import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
3
- import { AlertCircle, CheckCircle2, FileText, HelpCircle, ListFilter, Terminal } from 'lucide-preact';
3
+ import { CheckCircle2 } from 'lucide-preact';
4
4
  import type { ExtensionUiDialogRequest } from '@/client/hooks/chat/omp';
5
5
  import { ExtensionDialogHeader } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Header';
6
6
  import { ExtensionDialogSelectBody } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/SelectBody';
7
7
  import { ExtensionDialogFooter } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Footer';
8
+ import { ApprovalBody } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/ApprovalBody';
9
+ import { dialogMethodMeta, useDialogShortcuts } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/shortcuts';
10
+ import { isApprovalGateFrame } from '@/shared/lib/chat/omp/approval-gate';
8
11
  import { MarkdownRenderer } from '@/client/components/common/MarkdownRenderer';
9
12
 
10
13
  export type ExtensionDialogResponse =
@@ -36,6 +39,11 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
36
39
 
37
40
  const options = request.options ?? [];
38
41
  const optionDetails = request.optionDetails ?? [];
42
+ // An approval gate is a `select` frame whose title is omp's approval prompt
43
+ // (see `isApprovalGateFrame`). It has no "Other" option, and omp's own
44
+ // answer parser treats any free-text answer as a DENY — so the free-text
45
+ // field is hidden for it rather than offered as a way to deny by typo.
46
+ const isApprovalGate = isApprovalGateFrame(request);
39
47
 
40
48
  // Reset for a NEW dialog only. `request` is the identity to depend on —
41
49
  // `options`/`optionDetails` above are derived arrays, re-created on every
@@ -78,7 +86,12 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
78
86
  } else if (request.method === 'select') {
79
87
  // A typed custom answer is the actual response — the "Other" option
80
88
  // label itself is not. It wins over the highlighted option.
81
- if (customValue.trim()) {
89
+ //
90
+ // An APPROVAL gate is the exception: omp's answer parser reads any
91
+ // string that is not one of its choice labels as a DENY (measured:
92
+ // "Approve" allows, "yes please" denies), so a custom answer there can
93
+ // only ever refuse. The gate answers with its chosen label.
94
+ if (customValue.trim() && !isApprovalGate) {
82
95
  onRespond(request, { value: customValue.trim() });
83
96
  } else if (selectedOption) {
84
97
  onRespond(request, { value: selectedOption });
@@ -86,7 +99,7 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
86
99
  } else {
87
100
  onRespond(request, { value });
88
101
  }
89
- }, [onRespond, request, selectedOption, value, customValue]);
102
+ }, [onRespond, request, selectedOption, value, customValue, isApprovalGate]);
90
103
 
91
104
  const handleConfirmOption = useCallback(
92
105
  (option: string) => {
@@ -114,108 +127,18 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
114
127
  []
115
128
  );
116
129
 
117
- // Keyboard navigation & shortcuts
118
- useEffect(() => {
119
- const handleKeyDown = (e: globalThis.KeyboardEvent) => {
120
- if (e.key === 'Escape') {
121
- e.preventDefault();
122
- e.stopPropagation();
123
- cancel();
124
- return;
125
- }
126
-
127
- if (request.method === 'select' && options.length > 0) {
128
- // Typing in the custom "Other" input must not trigger number/arrow/Enter
129
- // shortcuts — those keys belong to the text field while focused.
130
- const typingCustom = e.target instanceof HTMLInputElement && e.target === customInputRef.current;
131
- if (typingCustom) {
132
- return;
133
- }
130
+ // Keyboard navigation & shortcuts.
131
+ useDialogShortcuts({
132
+ method: request.method,
133
+ options,
134
+ selectedOption,
135
+ onSelectOption: setSelectedOption,
136
+ customInputRef,
137
+ onSubmit: submitValue,
138
+ onCancel: cancel,
139
+ });
134
140
 
135
- const num = parseInt(e.key, 10);
136
- if (!isNaN(num) && num >= 1 && num <= options.length) {
137
- e.preventDefault();
138
- setSelectedOption(options[num - 1]);
139
- return;
140
- }
141
-
142
- if (e.key === 'ArrowDown') {
143
- e.preventDefault();
144
- const currentIdx = options.findIndex((o) => o === selectedOption);
145
- const nextIdx = currentIdx < options.length - 1 ? currentIdx + 1 : 0;
146
- setSelectedOption(options[nextIdx]);
147
- return;
148
- }
149
- if (e.key === 'ArrowUp') {
150
- e.preventDefault();
151
- const currentIdx = options.findIndex((o) => o === selectedOption);
152
- const prevIdx = currentIdx > 0 ? currentIdx - 1 : options.length - 1;
153
- setSelectedOption(options[prevIdx]);
154
- return;
155
- }
156
-
157
- if (e.key === 'Enter' && selectedOption) {
158
- e.preventDefault();
159
- submitValue();
160
- return;
161
- }
162
- }
163
-
164
- if (request.method === 'confirm') {
165
- if (e.key === 'Enter') {
166
- e.preventDefault();
167
- submitValue();
168
- return;
169
- }
170
- }
171
-
172
- if (request.method === 'editor') {
173
- if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
174
- e.preventDefault();
175
- submitValue();
176
- return;
177
- }
178
- }
179
- };
180
-
181
- window.addEventListener('keydown', handleKeyDown);
182
- return () => window.removeEventListener('keydown', handleKeyDown);
183
- }, [cancel, submitValue, request.method, options, selectedOption]);
184
-
185
- const methodMeta = (() => {
186
- switch (request.method) {
187
- case 'select':
188
- return {
189
- icon: <ListFilter size={16} className="text-ink" />,
190
- label: 'Decision Required',
191
- badge: `${options.length} Choices`,
192
- };
193
- case 'confirm':
194
- return {
195
- icon: <AlertCircle size={16} className="text-ink" />,
196
- label: 'Confirmation Required',
197
- badge: 'Confirm Action',
198
- };
199
- case 'input':
200
- return {
201
- icon: <Terminal size={16} className="text-ink" />,
202
- label: 'Prompt Input',
203
- badge: 'Text Input',
204
- };
205
- case 'editor':
206
- return {
207
- icon: <FileText size={16} className="text-ink" />,
208
- label: 'Buffer Editor',
209
- badge: 'Multiline Buffer',
210
- };
211
- default:
212
- return {
213
- icon: <HelpCircle size={16} className="text-ink" />,
214
- label: 'Agent Request',
215
- badge: 'Input',
216
- };
217
- }
218
- })();
141
+ const methodMeta = dialogMethodMeta(request.method, options.length);
219
142
 
220
143
  return (
221
144
  <div
@@ -241,6 +164,7 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
241
164
  >
242
165
  <ExtensionDialogHeader
243
166
  title={request.title}
167
+ options={options}
244
168
  methodLabel={methodMeta.label}
245
169
  badge={methodMeta.badge}
246
170
  icon={methodMeta.icon}
@@ -248,6 +172,9 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
248
172
  />
249
173
 
250
174
  <div className="max-h-[65vh] overflow-y-auto px-6 py-5 space-y-4">
175
+ {/* The approval gate: what is being approved, and why. */}
176
+ <ApprovalBody title={request.title} options={options} />
177
+
251
178
  {/* Prompt / Context Message with Markdown */}
252
179
  {request.message && (
253
180
  <div className="rounded-xl border border-ink/8 bg-canvas/40 p-4 text-[13px] leading-relaxed text-ink/85 select-text">
@@ -266,6 +193,7 @@ export function ExtensionDialog({ request, onRespond }: ExtensionDialogProps) {
266
193
  customInputRef={customInputRef}
267
194
  onSelect={handleSelectOption}
268
195
  onConfirmOption={handleConfirmOption}
196
+ hideCustomAnswer={isApprovalGate}
269
197
  />
270
198
  )}
271
199
 
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The keyboard shortcuts of omp's blocking dialog, and the per-method chrome.
8
+ *
9
+ * Both are about WHICH dialog is on screen rather than what it draws, so they
10
+ * live here and the dialog component keeps the markup.
11
+ *
12
+ * The shortcuts are a `window` listener, not a keydown on the panel: omp
13
+ * blocks the whole agent on this dialog, and the reader's focus may be in the
14
+ * custom-answer field, in the panel itself, or nowhere — so the dialog
15
+ * answers the key wherever it lands. The one exception is a key pressed
16
+ * INSIDE the custom-answer field: those keys belong to the text the user is
17
+ * typing, not to the dialog.
18
+ */
19
+
20
+ import { useEffect } from 'preact/hooks';
21
+ import { AlertCircle, FileText, HelpCircle, ListFilter, Terminal } from 'lucide-preact';
22
+ import type { ComponentChildren, RefObject } from 'preact';
23
+
24
+ export interface DialogShortcuts {
25
+ /** The dialog's method — which shortcuts apply. */
26
+ method: string;
27
+ /** The choices a `select` offers, in order. */
28
+ options: string[];
29
+ /** The currently highlighted choice. */
30
+ selectedOption: string | null;
31
+ /** Highlight a choice. */
32
+ onSelectOption: (option: string) => void;
33
+ /** The custom-answer field, when the dialog has one. */
34
+ customInputRef: RefObject<HTMLInputElement>;
35
+ /** Answer the dialog (Enter, or ⌘↵ in an editor). */
36
+ onSubmit: () => void;
37
+ /** Dismiss the dialog (Escape). */
38
+ onCancel: () => void;
39
+ }
40
+
41
+ /** Install the dialog's keyboard shortcuts for as long as it is on screen. */
42
+ export function useDialogShortcuts({
43
+ method,
44
+ options,
45
+ selectedOption,
46
+ onSelectOption,
47
+ customInputRef,
48
+ onSubmit,
49
+ onCancel,
50
+ }: DialogShortcuts) {
51
+ useEffect(() => {
52
+ const handleKeyDown = (e: globalThis.KeyboardEvent) => {
53
+ if (e.key === 'Escape') {
54
+ e.preventDefault();
55
+ e.stopPropagation();
56
+ onCancel();
57
+ return;
58
+ }
59
+
60
+ if (method === 'select' && options.length > 0) {
61
+ // Typing in the custom "Other" input must not trigger number/arrow/Enter
62
+ // shortcuts — those keys belong to the text field while focused.
63
+ const typingCustom = e.target instanceof HTMLInputElement && e.target === customInputRef.current;
64
+ if (typingCustom) {
65
+ return;
66
+ }
67
+
68
+ const num = parseInt(e.key, 10);
69
+ if (!isNaN(num) && num >= 1 && num <= options.length) {
70
+ e.preventDefault();
71
+ onSelectOption(options[num - 1]);
72
+ return;
73
+ }
74
+
75
+ if (e.key === 'ArrowDown') {
76
+ e.preventDefault();
77
+ const currentIdx = options.findIndex((o) => o === selectedOption);
78
+ const nextIdx = currentIdx < options.length - 1 ? currentIdx + 1 : 0;
79
+ onSelectOption(options[nextIdx]);
80
+ return;
81
+ }
82
+ if (e.key === 'ArrowUp') {
83
+ e.preventDefault();
84
+ const currentIdx = options.findIndex((o) => o === selectedOption);
85
+ const prevIdx = currentIdx > 0 ? currentIdx - 1 : options.length - 1;
86
+ onSelectOption(options[prevIdx]);
87
+ return;
88
+ }
89
+
90
+ if (e.key === 'Enter' && selectedOption) {
91
+ e.preventDefault();
92
+ onSubmit();
93
+ return;
94
+ }
95
+ }
96
+
97
+ if (method === 'confirm') {
98
+ if (e.key === 'Enter') {
99
+ e.preventDefault();
100
+ onSubmit();
101
+ return;
102
+ }
103
+ }
104
+
105
+ if (method === 'editor') {
106
+ if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
107
+ e.preventDefault();
108
+ onSubmit();
109
+ return;
110
+ }
111
+ }
112
+ };
113
+
114
+ window.addEventListener('keydown', handleKeyDown);
115
+ return () => window.removeEventListener('keydown', handleKeyDown);
116
+ }, [onCancel, onSubmit, method, options, selectedOption, onSelectOption, customInputRef]);
117
+ }
118
+
119
+ /** The chrome of one dialog method: its icon, its name and its badge. */
120
+ export interface DialogMethodMeta {
121
+ icon: ComponentChildren;
122
+ label: string;
123
+ badge: string;
124
+ }
125
+
126
+ /**
127
+ * The chrome of one dialog method.
128
+ *
129
+ * The badge counts the CHOICES a `select` offers — and for an approval gate
130
+ * that count is the whole decision ("Approve", "Deny"), so it is stated the
131
+ * same way as a question's.
132
+ */
133
+ export function dialogMethodMeta(method: string, optionCount: number): DialogMethodMeta {
134
+ switch (method) {
135
+ case 'select':
136
+ return {
137
+ icon: <ListFilter size={16} className="text-ink" />,
138
+ label: 'Decision Required',
139
+ badge: `${optionCount} Choices`,
140
+ };
141
+ case 'confirm':
142
+ return {
143
+ icon: <AlertCircle size={16} className="text-ink" />,
144
+ label: 'Confirmation Required',
145
+ badge: 'Confirm Action',
146
+ };
147
+ case 'input':
148
+ return {
149
+ icon: <Terminal size={16} className="text-ink" />,
150
+ label: 'Prompt Input',
151
+ badge: 'Text Input',
152
+ };
153
+ case 'editor':
154
+ return {
155
+ icon: <FileText size={16} className="text-ink" />,
156
+ label: 'Buffer Editor',
157
+ badge: 'Multiline Buffer',
158
+ };
159
+ default:
160
+ return {
161
+ icon: <HelpCircle size={16} className="text-ink" />,
162
+ label: 'Agent Request',
163
+ badge: 'Input',
164
+ };
165
+ }
166
+ }
@@ -224,6 +224,36 @@ describe('Proc panel — a cancelled job', () => {
224
224
  });
225
225
  });
226
226
 
227
+ describe('Proc panel — running-task telemetry', () => {
228
+ // The same snapshot fields the wait card draws (omp 18.13.0). This row has no
229
+ // percent chip of its own, so the line carries the estimate too.
230
+ test('draws requests, spend, context fill and stage for a running task', async () => {
231
+ const el = await mount({
232
+ type: 'read',
233
+ name: 'read',
234
+ target: 'proc://bg_11',
235
+ input: { path: 'proc://bg_11' },
236
+ output: 'bg_11 [task] — running',
237
+ status: 'running',
238
+ details: {
239
+ proc: {
240
+ job: {
241
+ id: 'bg_11', type: 'task', status: 'running', label: 'refactor', durationMs: 90_000,
242
+ completionPercent: 55, requests: 90, cost: 18.4,
243
+ contextTokens: 163_840, contextWindow: 1_048_576, stage: 'implementing',
244
+ },
245
+ },
246
+ },
247
+ });
248
+ const text = el.textContent ?? '';
249
+ expect(text).toContain('90 req');
250
+ expect(text).toContain('$18.40');
251
+ expect(text).toContain('ctx 163.8K/1.0M');
252
+ expect(text).toContain('~55%');
253
+ expect(text).toContain('stage: implementing');
254
+ });
255
+ });
256
+
227
257
  describe('Proc panel — legacy hub tool', () => {
228
258
  test('renders a hub daemon from the top level of details', async () => {
229
259
  const el = await mount({