@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
@@ -19,7 +19,7 @@
19
19
  */
20
20
 
21
21
  import type { ChatMessageData } from '@/shared/types';
22
- import { isReminderTag, unwrapXmlEnvelope } from '@/shared/lib/chat/xml-envelope';
22
+ import { isReminderTag, stripNoticeTags, unwrapXmlEnvelope } from '@/shared/lib/chat/xml-envelope';
23
23
 
24
24
  /** Tag that identifies a notice payload rather than prose. A notice keeps its
25
25
  * wrapper — that tag is the field's identity, and `SystemNotice` reads it to
@@ -56,6 +56,27 @@ export function reminderPartIndex(parts: string[]): number | undefined {
56
56
  return index === -1 ? undefined : index;
57
57
  }
58
58
 
59
+ /**
60
+ * The notice text of an omp `developer`/`system` turn — harness context omp
61
+ * injected (a rule violation, the DSML tool-call failure nudge, a resume
62
+ * prompt), never the model's own answer. Returns `undefined` for any other
63
+ * role.
64
+ *
65
+ * A wrapper-bearing turn keeps its envelope (the tag is the card's identity;
66
+ * `SystemNotice` reads it for the label); plain text has its notice tags
67
+ * stripped. Empty text is not a notice. Both mappers ask this — the live
68
+ * `mapper.ts` and the JSONL reload `messages-map.ts` — so the same row cannot
69
+ * render as a card while streaming and as the assistant's prose after a
70
+ * reload.
71
+ */
72
+ export function developerTurnNotice(role: string | undefined, textParts: string[]): string | undefined {
73
+ if (role !== 'developer' && role !== 'system') return undefined;
74
+ const envelopeIdx = reminderPartIndex(textParts);
75
+ const source = envelopeIdx !== undefined ? textParts[envelopeIdx] : textParts.join('\n');
76
+ const notice = (envelopeIdx !== undefined ? source : stripNoticeTags(source)).trim();
77
+ return notice || undefined;
78
+ }
79
+
59
80
  /** True when the row's `notice` is the assistant answer omp diverted there. */
60
81
  export function noticeIsAssistantText(
61
82
  msg: ChatMessageData | null | undefined,
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The approval gate, as omp actually sends it.
8
+ *
9
+ * Over RPC the gate is a `select` frame, not a `confirm`: omp's RPC UI context
10
+ * has no `approve` member, so `requestApproval` falls back to its `select`
11
+ * branch. The title carries omp's WHOLE prompt, newline-separated, and the
12
+ * options are the approval choices. Both shapes are measured against omp
13
+ * 18.13.1 — the frames below are the ones it produces, verbatim.
14
+ */
15
+
16
+ import { describe, expect, test } from 'bun:test';
17
+
18
+ import { isApprovalGateFrame, parseApprovalPrompt } from '@/shared/lib/chat/omp/approval-gate';
19
+
20
+ /** omp's gate for a restricted-folder read, as `requestApproval` builds it. */
21
+ const RESTRICTED_READ = [
22
+ 'Allow tool: read',
23
+ 'Reason: Restricted folder: /tmp/livetest/secret',
24
+ 'Path: /tmp/livetest/secret/creds.txt',
25
+ ].join('\n');
26
+
27
+ /** omp's gate for a bash call under `always-ask`. */
28
+ const BASH_GATE = ['Allow tool: bash', 'Command: ls -la /tmp/livetest'].join('\n');
29
+
30
+ describe('isApprovalGateFrame', () => {
31
+ test('an approval prompt is a gate', () => {
32
+ expect(isApprovalGateFrame({ title: RESTRICTED_READ, options: ['Approve', 'Deny'] })).toBe(true);
33
+ expect(isApprovalGateFrame({ title: BASH_GATE, options: ['Approve', 'Deny'] })).toBe(true);
34
+ });
35
+
36
+ test('an ask question is not a gate', () => {
37
+ // The question's own title, which is what a card claims a dialog by.
38
+ expect(isApprovalGateFrame({ title: 'Which language?', options: ['Python', 'Other (type your own)'] })).toBe(false);
39
+ // omp's grouped ask frame carries NO title at all.
40
+ expect(isApprovalGateFrame({ title: '', options: [] })).toBe(false);
41
+ expect(isApprovalGateFrame({ title: undefined })).toBe(false);
42
+ expect(isApprovalGateFrame({ title: null })).toBe(false);
43
+ });
44
+
45
+ test('the match is on omp\'s own prefix, not on a substring', () => {
46
+ // A question that merely CONTAINS the words is not a gate.
47
+ expect(isApprovalGateFrame({ title: 'Should I allow tool: write here?', options: ['Approve', 'Deny'] })).toBe(false);
48
+ // The prefix must lead, after trimming and case folding.
49
+ expect(isApprovalGateFrame({ title: ' allow tool: read\nPath: /tmp/x', options: ['Approve', 'Deny'] })).toBe(true);
50
+ expect(isApprovalGateFrame({ title: 'ALLOW TOOL: read', options: ['Approve', 'Deny'] })).toBe(true);
51
+ });
52
+
53
+ test('the CHOICES must be omp\'s approval choices', () => {
54
+ // A model-authored question can carry the same title; it is still a
55
+ // question, and it is answered through its own card with its own options.
56
+ expect(isApprovalGateFrame({ title: RESTRICTED_READ, options: ['Yes', 'No'] })).toBe(false);
57
+ // A gate always carries its choices.
58
+ expect(isApprovalGateFrame({ title: RESTRICTED_READ, options: [] })).toBe(false);
59
+ expect(isApprovalGateFrame({ title: RESTRICTED_READ })).toBe(false);
60
+ });
61
+ });
62
+
63
+ describe('parseApprovalPrompt', () => {
64
+ test('splits the tool, the reason and the details', () => {
65
+ const prompt = parseApprovalPrompt(RESTRICTED_READ);
66
+ expect(prompt).not.toBeNull();
67
+ expect(prompt?.tool).toBe('read');
68
+ expect(prompt?.reason).toBe('Restricted folder: /tmp/livetest/secret');
69
+ expect(prompt?.details).toEqual(['Path: /tmp/livetest/secret/creds.txt']);
70
+ });
71
+
72
+ test('a gate with no reason keeps its details', () => {
73
+ const prompt = parseApprovalPrompt(BASH_GATE);
74
+ expect(prompt?.tool).toBe('bash');
75
+ expect(prompt?.reason).toBeUndefined();
76
+ expect(prompt?.details).toEqual(['Command: ls -la /tmp/livetest']);
77
+ });
78
+
79
+ test('a title that is not an approval prompt is not one', () => {
80
+ expect(parseApprovalPrompt('Which language?')).toBeNull();
81
+ expect(parseApprovalPrompt('')).toBeNull();
82
+ expect(parseApprovalPrompt(undefined)).toBeNull();
83
+ expect(parseApprovalPrompt(null)).toBeNull();
84
+ });
85
+
86
+ test('the reason is not repeated among the details', () => {
87
+ // The reason is omp's own line; leaving it in the details too would
88
+ // print it twice.
89
+ const prompt = parseApprovalPrompt(RESTRICTED_READ);
90
+ expect(prompt?.details.some((detail) => detail.startsWith('Reason:'))).toBe(false);
91
+ });
92
+
93
+ test('every detail line survives the split', () => {
94
+ const prompt = parseApprovalPrompt(
95
+ ['Allow tool: write', 'Reason: Restricted folder: /tmp/x', 'Path: /tmp/x/a.txt', 'Content: 3 lines'].join('\n'),
96
+ );
97
+ expect(prompt?.details).toEqual(['Path: /tmp/x/a.txt', 'Content: 3 lines']);
98
+ });
99
+ });
@@ -0,0 +1,129 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * Is this dialog omp's TOOL-APPROVAL gate, rather than a question it asked?
8
+ *
9
+ * Over RPC the gate is NOT a `confirm` frame. omp's RPC UI context
10
+ * (`RpcExtensionUIContext`) has no `approve` member, so `requestApproval`
11
+ * falls back to its `select` branch (`approval.ts`: `if (ui.approve) … else
12
+ * ui.select(full, approvalChoiceLabels(choices))`). The gate therefore
13
+ * arrives as a `select` frame whose TITLE is omp's approval prompt and whose
14
+ * OPTIONS are the approval choices — measured against 18.13.1:
15
+ *
16
+ * title: "Allow tool: read\nReason: Restricted folder: /tmp/secret\nPath: …"
17
+ * options: ["Approve", "Deny"]
18
+ *
19
+ * A mode-raised prompt (the ordinary `always-ask` gate) carries the same
20
+ * shape, so the TITLE PREFIX is what separates the two.
21
+ *
22
+ * This matters because an approval gate and an `ask` question are both
23
+ * `select` frames, and the routing that decides which one gets the dialog
24
+ * (`splitAskFrames`) claims a `select` by its title. omp's approval title
25
+ * names no question, so the gate used to fall through to the "last ask
26
+ * spoke" walk and land on an unrelated QUESTION's card — where it renders as
27
+ * that question's answer options ("Approve" / "Deny" offered as answers to
28
+ * "Which language?"), and the answer is posted to the wrong tool call.
29
+ *
30
+ * The prefix is omp's own (`approvalHeader`: `Allow tool: ${tool.name}`) and
31
+ * has been in that shape since well before 18.13.1 — 18.13.1 does not change
32
+ * it, it only adds a NEW WAY to raise the gate (`tools.restrictedFolders`),
33
+ * which makes the misrouting reachable in a session that never asks anything.
34
+ */
35
+
36
+ /** omp's approval-prompt title prefix (`approval.ts`: `Allow tool: <tool>`). */
37
+ const APPROVAL_TITLE_PREFIX = 'allow tool:';
38
+
39
+ /**
40
+ * The choices omp's approval gate offers, in every shape it can take.
41
+ *
42
+ * Measured against omp 18.13.1's own resolver, across all three approval
43
+ * modes and with a restricted folder in force: the gate's option list is
44
+ * ALWAYS exactly `["Approve", "Deny"]`. A mode-raised prompt adds
45
+ * "Approve write for this session" — but only when `sessionApprovalScope`
46
+ * grants it, and a RESTRICTED call carries source `restriction`, for which
47
+ * upstream returns NO scope. So the list is two labels either way.
48
+ *
49
+ * The labels are omp's own (`approvalChoiceLabels`), and they are what the
50
+ * answer parser compares against — anything else is a deny.
51
+ */
52
+ const APPROVAL_CHOICES = ['approve', 'deny'];
53
+
54
+ /**
55
+ * True for a frame omp raised as a tool-approval gate.
56
+ *
57
+ * TWO facts have to hold, and both are omp's own:
58
+ *
59
+ * - the TITLE is omp's approval prompt (it leads with "Allow tool: <tool>");
60
+ * - the OPTIONS are the approval choices.
61
+ *
62
+ * The title alone would be enough for omp's own frames, but a model-authored
63
+ * `ask` question can also be titled "Allow tool: …" — and that question is
64
+ * answered through the QUESTION's card, with its own options. Requiring the
65
+ * choice labels as well is what keeps such a question a question.
66
+ */
67
+ export function isApprovalGateFrame(frame: { title?: string | null; options?: readonly string[] }): boolean {
68
+ const title = typeof frame.title === 'string' ? frame.title.trim().toLowerCase() : '';
69
+ if (!title.startsWith(APPROVAL_TITLE_PREFIX)) return false;
70
+ const options = frame.options;
71
+ // A frame with no option list cannot be an approval gate: omp's gate always
72
+ // carries its choices.
73
+ if (!options || options.length === 0) return false;
74
+ return options.every((option) => APPROVAL_CHOICES.includes(option.trim().toLowerCase()));
75
+ }
76
+
77
+ /** The approval prompt, split into the parts a reader needs. */
78
+ export interface ApprovalPrompt {
79
+ /** The tool the gate is about ("read", "bash"). */
80
+ tool: string;
81
+ /** Why the gate asks ("Restricted folder: /tmp/secret") — omp's own line. */
82
+ reason?: string;
83
+ /**
84
+ * The tool's own detail rows — the path, the command, whatever omp's tool
85
+ * supplies. These are lines the gate is ABOUT, and the reason the user
86
+ * needs them: "Approve" without the command it approves is not a decision.
87
+ */
88
+ details: string[];
89
+ }
90
+
91
+ /**
92
+ * omp's approval prompt, split into its parts.
93
+ *
94
+ * omp sends the whole prompt as ONE title, newline-separated
95
+ * (`approvalHeader` + `approvalDetails` joined with `\n`):
96
+ *
97
+ * Allow tool: read
98
+ * Reason: Restricted folder: /tmp/livetest/secret
99
+ * Path: /tmp/livetest/secret/creds.txt
100
+ *
101
+ * A title is a single-line field, and the dialog's header renders it with
102
+ * `truncate` — so the REASON and the PATH were clipped out of the one
103
+ * element that could show them, leaving a gate that said only "Allow tool:
104
+ * read" over a "Path: …" the user could not see. Splitting the prompt is
105
+ * what lets the dialog show what it is approving.
106
+ *
107
+ * This reads the TITLE's shape. Whether the frame IS a gate is
108
+ * `isApprovalGateFrame`'s question, and it needs the option list too — so a
109
+ * caller must decide that first and then split the title it accepted.
110
+ *
111
+ * A title that is not an approval prompt yields `null`; a prompt with no
112
+ * detail rows yields an empty `details` list, never a missing one.
113
+ */
114
+ export function parseApprovalPrompt(title: string | null | undefined): ApprovalPrompt | null {
115
+ const text = typeof title === 'string' ? title : '';
116
+ if (!text.trim().toLowerCase().startsWith(APPROVAL_TITLE_PREFIX)) return null;
117
+ const lines = text
118
+ .split('\n')
119
+ .map((line) => line.trim())
120
+ .filter(Boolean);
121
+ // The first line is omp's own header: "Allow tool: <tool>".
122
+ const tool = lines[0]?.slice(APPROVAL_TITLE_PREFIX.length).trim() ?? '';
123
+ const rest = lines.slice(1);
124
+ // The reason is omp's own labelled line, and only when it wrote one.
125
+ const reasonLine = rest.find((line) => line.toLowerCase().startsWith('reason:'));
126
+ const reason = reasonLine ? reasonLine.slice('reason:'.length).trim() : undefined;
127
+ const details = rest.filter((line) => line !== reasonLine);
128
+ return { tool, ...(reason ? { reason } : {}), details };
129
+ }
@@ -74,6 +74,18 @@ describe('OMP_SCHEMA', () => {
74
74
  // binary rejects.
75
75
  expect(OMP_SCHEMA.entries['task.completionProbeMs']).toBeUndefined();
76
76
  });
77
+
78
+ test('the folders that always ask are offered (omp 18.13.1)', () => {
79
+ // `tools.restrictedFolders` is where every read, write, edit, search or
80
+ // command asks in EVERY approval mode. The panel is the only place a user
81
+ // can set it, so a schema regenerated without the row makes the feature
82
+ // unreachable from the console.
83
+ const entry = OMP_SCHEMA.entries['tools.restrictedFolders'];
84
+ expect(entry).toBeDefined();
85
+ expect(entry?.type).toBe('array');
86
+ expect(entry?.ui.tab).toBe('interaction');
87
+ expect(entry?.ui.group).toBe('Approvals');
88
+ });
77
89
  });
78
90
 
79
91
  describe('ALL_SCHEMA_ENTRIES', () => {
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The one formatter for omp's running-task telemetry (`wait` / `proc://` job
8
+ * rows). Measured against omp 18.13.0's own suffix:
9
+ * `— 90 req · $18.40 · ctx 160K/1M · stage: implementing`.
10
+ */
11
+
12
+ import { describe, expect, test } from 'bun:test';
13
+ import { jobProgressLine, jobProgressParts } from '@/shared/lib/omp/session/job-progress';
14
+
15
+ const RUNNING = {
16
+ status: 'running',
17
+ requests: 90,
18
+ cost: 18.4,
19
+ contextTokens: 163_840,
20
+ contextWindow: 1_048_576,
21
+ stage: 'implementing',
22
+ };
23
+
24
+ describe('jobProgressParts', () => {
25
+ test('reads every field omp reports on a running task', () => {
26
+ expect(jobProgressParts(RUNNING)).toEqual([
27
+ '90 req',
28
+ '$18.40',
29
+ 'ctx 163.8K/1.0M',
30
+ 'stage: implementing',
31
+ ]);
32
+ });
33
+
34
+ test('a sub-cent spend is reported as a ceiling, not as $0.00', () => {
35
+ expect(jobProgressParts({ status: 'running', cost: 0.004 })).toEqual(['<$0.01']);
36
+ expect(jobProgressParts({ status: 'running', cost: 0.005 })).toEqual(['$0.01']);
37
+ });
38
+
39
+ test('context fill without a window prints one number', () => {
40
+ expect(jobProgressParts({ status: 'running', contextTokens: 1_600 })).toEqual(['ctx 1.6K']);
41
+ });
42
+
43
+ test('the estimated percent is opt-in, because the wait row already shows it', () => {
44
+ const job = { ...RUNNING, completionPercent: 40 };
45
+ expect(jobProgressParts(job)).not.toContain('~40%');
46
+ expect(jobProgressParts(job, { includePercent: true })).toContain('~40%');
47
+ });
48
+
49
+ test('a settled row reports nothing, so a stored snapshot cannot look live', () => {
50
+ expect(jobProgressParts({ ...RUNNING, status: 'completed' })).toEqual([]);
51
+ expect(jobProgressParts({ ...RUNNING, status: undefined })).toEqual([]);
52
+ });
53
+
54
+ test('zero values are omissions, not measurements', () => {
55
+ expect(jobProgressParts({ status: 'running', requests: 0, cost: 0 })).toEqual([]);
56
+ });
57
+
58
+ test('a multi-line stage is collapsed', () => {
59
+ expect(jobProgressParts({ status: 'running', stage: 'writing\n the report' })).toEqual([
60
+ 'stage: writing the report',
61
+ ]);
62
+ });
63
+ });
64
+
65
+ describe('jobProgressLine', () => {
66
+ test('joins the parts with omp\'s separator', () => {
67
+ expect(jobProgressLine({ ...RUNNING, requests: 90, stage: undefined })).toBe(
68
+ '90 req · $18.40 · ctx 163.8K/1.0M',
69
+ );
70
+ });
71
+
72
+ test('is undefined when there is nothing to say', () => {
73
+ expect(jobProgressLine({ status: 'running' })).toBeUndefined();
74
+ expect(jobProgressLine({ status: 'failed', requests: 12 })).toBeUndefined();
75
+ });
76
+ });
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ /**
7
+ * The live telemetry omp reports on a RUNNING task row.
8
+ *
9
+ * omp 18.13.0 copies `stage`, `requests`, `cost`, `contextTokens` and
10
+ * `contextWindow` out of a subagent task's progress record into the job
11
+ * snapshot behind `wait` and `read proc://`, which is what lets omp's own card
12
+ * read `5h7m · 90 req · $18.40 · ctx 160K/1M · stage: implementing`. The values
13
+ * exist only while the job runs — omp omits them from a settled row — so a
14
+ * finished row keeps its plain shape.
15
+ *
16
+ * Stated once because the wait card and the proc card read the SAME snapshot,
17
+ * and a per-surface formatter is how one of them ends up printing
18
+ * `ctx 163840` beside the other's `ctx 160K`.
19
+ *
20
+ * The FIELDS and their order are omp's; the token rounding is Kabmo's own
21
+ * (`formatCompactTokens`, one decimal above 1000: `163.8K`, `1.0M`) rather than
22
+ * omp's rounded `164K`/`1M`, because every other token label in this console —
23
+ * the context ring, the usage bars — reads that way, and a job row that
24
+ * disagreed with the ring beside it would look like a second measurement.
25
+ */
26
+
27
+ import { formatCompactTokens } from '@/shared/lib/format/number';
28
+
29
+ /** The progress fields omp reports on a task job. */
30
+ export interface JobProgressFields {
31
+ status?: string;
32
+ requests?: number;
33
+ cost?: number;
34
+ contextTokens?: number;
35
+ contextWindow?: number;
36
+ completionPercent?: number;
37
+ stage?: string;
38
+ }
39
+
40
+ export interface JobProgressOptions {
41
+ /** Draw the subagent's self-estimated percent; off where the row already shows it. */
42
+ includePercent?: boolean;
43
+ }
44
+
45
+ /** `$18.40`, or `<$0.01` below half a cent — the same cutoff omp's own row uses. */
46
+ function costLabel(cost: number): string | undefined {
47
+ if (!Number.isFinite(cost) || cost <= 0) return undefined;
48
+ return cost < 0.005 ? '<$0.01' : `$${cost.toFixed(2)}`;
49
+ }
50
+
51
+ /**
52
+ * The progress pieces for one job, in omp's order: requests, cost, context
53
+ * fill, estimated percent, stage.
54
+ *
55
+ * Gated on `status === 'running'` for the same reason omp gates its own
56
+ * suffix: a stored snapshot must never paint a live counter over a row that has
57
+ * already finished.
58
+ */
59
+ export function jobProgressParts(job: JobProgressFields, options: JobProgressOptions = {}): string[] {
60
+ if (job.status !== 'running') return [];
61
+ const parts: string[] = [];
62
+ if (job.requests !== undefined && job.requests > 0) parts.push(`${job.requests} req`);
63
+ if (job.cost !== undefined) {
64
+ const cost = costLabel(job.cost);
65
+ if (cost) parts.push(cost);
66
+ }
67
+ const tokens = formatCompactTokens(job.contextTokens);
68
+ if (tokens) {
69
+ const window = formatCompactTokens(job.contextWindow);
70
+ parts.push(window ? `ctx ${tokens}/${window}` : `ctx ${tokens}`);
71
+ }
72
+ if (options.includePercent && job.completionPercent !== undefined) {
73
+ parts.push(`~${Math.round(job.completionPercent)}%`);
74
+ }
75
+ const stage = job.stage?.replace(/\s+/g, ' ').trim();
76
+ if (stage) parts.push(`stage: ${stage}`);
77
+ return parts;
78
+ }
79
+
80
+ /** The progress line for a job row, or undefined when it has nothing to say. */
81
+ export function jobProgressLine(job: JobProgressFields, options: JobProgressOptions = {}): string | undefined {
82
+ const parts = jobProgressParts(job, options);
83
+ return parts.length > 0 ? parts.join(' · ') : undefined;
84
+ }
@@ -14,8 +14,7 @@
14
14
 
15
15
  import type { ChatMessageData, ToolCallData } from '@/shared/types';
16
16
  import { extractInlinedTextAttachments, extractText, extractUserImageAttachments, parseMessageBlocks, stripInlinedTextAttachments, toToolCallData } from '@/shared/lib/omp/session/parse-message-blocks';
17
- import { reminderPartIndex } from '@/shared/lib/chat/notice-row';
18
- import { stripNoticeTags } from '@/shared/lib/chat/xml-envelope';
17
+ import { developerTurnNotice, reminderPartIndex } from '@/shared/lib/chat/notice-row';
19
18
  import { deriveTurnError } from '@/shared/lib/omp/session/turn-error';
20
19
  import { formatClock } from '@/shared/lib/format/time';
21
20
  import { toEpochMs } from '@/shared/lib/omp/session/timestamps';
@@ -81,10 +80,8 @@ export function toChatMessage(raw: Record<string, unknown>, streaming = true): C
81
80
  // label the card and strips it before markdown, and the JSONL path stores
82
81
  // it the same way so a live row and its reloaded twin are identical.
83
82
  // Developer/system turns are notices by role and have no wrapper to keep.
84
- const source = reminderIdx !== undefined ? parsed.textParts[reminderIdx] : parsed.textParts.join('\n');
85
- const notice = reminderIdx !== undefined
86
- ? source.trim()
87
- : stripNoticeTags(source).trim();
83
+ const notice = developerTurnNotice(typeof raw.role === 'string' ? raw.role : undefined, parsed.textParts)
84
+ ?? (reminderIdx !== undefined ? parsed.textParts[reminderIdx].trim() : undefined);
88
85
  if (!notice) return null;
89
86
  return {
90
87
  id,
@@ -35,6 +35,7 @@ import {
35
35
  } from '@/shared/lib/omp/session/messages-map';
36
36
  import { parseAssistantContent, resultOutput, roleFor } from '@/shared/lib/omp/session/messages-parse';
37
37
  import type { OmpMessageEntry } from '@/shared/lib/omp/session/messages-parse';
38
+ import { isNoticeRow } from '@/shared/lib/chat/notice-row';
38
39
  import { loadSessionMessages } from '@/server/lib/omp/session/messages';
39
40
 
40
41
  const entry = (message: Record<string, unknown>, extra: Record<string, unknown> = {}): OmpMessageEntry =>
@@ -47,8 +48,9 @@ describe('roleFor', () => {
47
48
  });
48
49
 
49
50
  test('folds developer, custom, toolResult and system onto assistant', () => {
50
- // omp spells these roles differently; Kabmo has no such rows, and
51
- // the fold is what lets a developer turn render as an assistant notice.
51
+ // omp spells these roles differently; the fold is the base-role fallback
52
+ // for a JSONL row. A developer/system turn then becomes a notice row by
53
+ // role (the notice branch overrides), never assistant content.
52
54
  expect(roleFor('developer')).toBe('assistant');
53
55
  expect(roleFor('custom')).toBe('assistant');
54
56
  expect(roleFor('toolResult')).toBe('assistant');
@@ -165,10 +167,17 @@ describe('toChatMessage — reload entry shape', () => {
165
167
  expect(msg?.content).toBe('body');
166
168
  });
167
169
 
168
- test('a developer turn keeps its parsed text as assistant content', () => {
169
- const msg = toChatMessage(entry({ role: 'developer', content: [{ type: 'text', text: 'rule' }] }));
170
- expect(msg?.role).toBe('assistant');
171
- expect(msg?.content).toBe('rule');
170
+ test('a developer turn is a notice row, never assistant prose', () => {
171
+ // omp writes harness nudges (a malformed tool call, a rule reminder) as
172
+ // role `developer`; the live mapper renders them as a notice card, and
173
+ // the reload path must agree — as assistant content the raw prompt (and
174
+ // its DSML markup) showed up as if the model had said it.
175
+ const nudge = 'Tool call failed: your previous response tried to invoke a tool, but the tool-call markup was malformed, so it arrived as plain text, no tool was executed.\n\n```\n<|DSML|tool_calls>\n```';
176
+ const msg = toChatMessage(entry({ role: 'developer', content: [{ type: 'text', text: nudge }] }));
177
+ expect(msg?.role).toBe('ai');
178
+ expect(msg?.content).toBe('');
179
+ expect(msg?.notice).toBe(nudge);
180
+ expect(isNoticeRow(msg)).toBe(true);
172
181
  });
173
182
 
174
183
  test('an errored turn with no text is kept so the failure stays visible', () => {
@@ -8,7 +8,7 @@ import { extractInlinedTextAttachments, extractText, extractUserImageAttachments
8
8
  import { extractToolImages, type ToolImageRef } from '@/shared/lib/omp/session/tool-images';
9
9
  import { isRecord } from '@/shared/lib/util/guards';
10
10
  import { normalizeNoticeText } from '@/shared/lib/chat/notice-text';
11
- import { reminderPartIndex } from '@/shared/lib/chat/notice-row';
11
+ import { developerTurnNotice, reminderPartIndex } from '@/shared/lib/chat/notice-row';
12
12
  import { deriveTurnError } from '@/shared/lib/omp/session/turn-error';
13
13
  import { toEpochMs } from '@/shared/lib/omp/session/timestamps';
14
14
  import { CHAMBER_GOAL_STATE_ENTRY, CHAMBER_PLAN_STATE_ENTRY, KABMO_GOAL_STATE_ENTRY, KABMO_PLAN_STATE_ENTRY } from '@/shared/lib/omp/mode/types';
@@ -77,6 +77,24 @@ export function toChatMessage(entry: OmpMessageEntry): ChatMessageData | null {
77
77
  return { ...base, role: 'assistant', systemNote: toolName ? `[${toolName}] ${text}` : text };
78
78
  }
79
79
 
80
+ // A developer/system turn is the HARNESS talking, never the model's answer:
81
+ // omp injects these (a malformed tool call, a rule-violation reminder, a
82
+ // compaction resume prompt) as agent-attributed context. The live mapper
83
+ // (mapper.ts) renders them as a notice row; the reload path must agree or
84
+ // the raw harness prompt — DSML markup included — shows up as if the model
85
+ // had said it (measured: 5 DSML-leak nudges across this install's store).
86
+ if (role === 'developer' || role === 'system') {
87
+ const notice = developerTurnNotice(role, parseAssistantContent(content).textParts);
88
+ if (!notice) return null;
89
+ return {
90
+ id: base.id,
91
+ role: 'ai',
92
+ date: base.date,
93
+ content: '',
94
+ notice,
95
+ };
96
+ }
97
+
80
98
  // Assistant / developer / custom: parse the rich block structure.
81
99
  const parsed = parseAssistantContent(content);
82
100
  const turnError = deriveTurnError(msg);
@@ -157,6 +157,29 @@ describe('procViewOf — read', () => {
157
157
  expect(view?.daemon).toBeUndefined();
158
158
  });
159
159
 
160
+ test('reads the running-task telemetry omp 18.13.0 adds', () => {
161
+ const view = procViewOf({
162
+ target: 'proc://bg_11',
163
+ details: {
164
+ proc: {
165
+ job: {
166
+ id: 'bg_11', type: 'task', status: 'running', label: 'refactor', durationMs: 90_000,
167
+ completionPercent: 55, requests: 90, cost: 18.4,
168
+ contextTokens: 163_840, contextWindow: 1_048_576, stage: 'implementing',
169
+ },
170
+ },
171
+ },
172
+ });
173
+ expect(view?.job).toMatchObject({
174
+ completionPercent: 55,
175
+ requests: 90,
176
+ cost: 18.4,
177
+ contextTokens: 163_840,
178
+ contextWindow: 1_048_576,
179
+ stage: 'implementing',
180
+ });
181
+ });
182
+
160
183
  test('reads a job cancellation', () => {
161
184
  const view = procViewOf({
162
185
  target: 'proc://bg_2/kill',
@@ -95,6 +95,17 @@ export interface ProcJob {
95
95
  label?: string;
96
96
  durationMs?: number;
97
97
  exitCode?: number;
98
+ /** Self-estimated completion of a subagent task (0–100). */
99
+ completionPercent?: number;
100
+ /** Model requests a RUNNING task has made (omp 18.13.0). */
101
+ requests?: number;
102
+ /** Spend of a running task, in USD (omp 18.13.0). */
103
+ cost?: number;
104
+ /** Context fill of a running task, and the window it fills (omp 18.13.0). */
105
+ contextTokens?: number;
106
+ contextWindow?: number;
107
+ /** The stage a running task reports. */
108
+ stage?: string;
98
109
  resolvedModel?: string;
99
110
  resultText?: string;
100
111
  errorText?: string;
@@ -172,6 +183,12 @@ function jobOf(value: unknown): ProcJob | undefined {
172
183
  label: asString(value.label),
173
184
  durationMs: asNumber(value.durationMs),
174
185
  exitCode: asNumber(value.exitCode),
186
+ completionPercent: asNumber(value.completionPercent),
187
+ requests: asNumber(value.requests),
188
+ cost: asNumber(value.cost),
189
+ contextTokens: asNumber(value.contextTokens),
190
+ contextWindow: asNumber(value.contextWindow),
191
+ stage: asString(value.stage),
175
192
  resolvedModel: asString(value.resolvedModel),
176
193
  resultText: asString(value.resultText),
177
194
  errorText: asString(value.errorText),
@@ -53,6 +53,28 @@ describe('waitViewOf', () => {
53
53
  expect(view?.jobs[1]).toMatchObject({ completionPercent: 40, resolvedModel: 'deepseek-v4-1-flash' });
54
54
  });
55
55
 
56
+ test('reads the running-task telemetry omp 18.13.0 adds', () => {
57
+ // omp copies these out of a task's progress record into the job snapshot;
58
+ // they are the numbers behind `90 req · $18.40 · ctx 160K/1M · stage: …`.
59
+ const view = waitViewOf({
60
+ details: {
61
+ op: 'wait',
62
+ jobs: [{
63
+ id: 'bg_3', type: 'task', status: 'running', label: 'refactor', durationMs: 18_446_000,
64
+ completionPercent: 55, requests: 90, cost: 18.4,
65
+ contextTokens: 163_840, contextWindow: 1_048_576, stage: 'implementing',
66
+ }],
67
+ },
68
+ });
69
+ expect(view?.jobs[0]).toMatchObject({
70
+ requests: 90,
71
+ cost: 18.4,
72
+ contextTokens: 163_840,
73
+ contextWindow: 1_048_576,
74
+ stage: 'implementing',
75
+ });
76
+ });
77
+
56
78
  test('an empty job list is an answer, not an absence', () => {
57
79
  // `{op:'wait', jobs:[]}` is what omp returns when the 30-minute cap elapses
58
80
  // and when a SERVICE rather than a job woke the call.