@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
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A prompt failure the timeline must DRAW.
8
+ *
9
+ * ACP's silent turn emits `prompt_error` with no `message_end`; before this the
10
+ * callback only logged it, so the assistant bubble stayed empty and the reason
11
+ * was invisible. These cases pin where the failure lands: the optimistic row it
12
+ * would have streamed into, or a dedicated row when the run already answered.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+ import type { ChatMessageData } from '@/shared/types';
17
+ import { reportPromptError, type PromptErrorDeps } from '@/shared/lib/chat/timeline/prompt-error';
18
+ import {
19
+ createOmpAgentCallbacks,
20
+ type OmpAgentCallbacksDeps,
21
+ } from '@/shared/lib/chat/timeline/omp-callbacks';
22
+
23
+ interface MountedPromptError {
24
+ deps: PromptErrorDeps;
25
+ ref: { current: string | null };
26
+ rows: () => ChatMessageData[];
27
+ persisted: () => ChatMessageData[][];
28
+ }
29
+
30
+ function mount(messages: ChatMessageData[], placeholderId: string | null = null): MountedPromptError {
31
+ let rows = messages;
32
+ const persisted: ChatMessageData[][] = [];
33
+ const ref = { current: placeholderId };
34
+ const deps = {
35
+ setLocalMessages: (update: ChatMessageData[] | ((prev: ChatMessageData[]) => ChatMessageData[])) => {
36
+ rows = typeof update === 'function' ? update(rows) : update;
37
+ },
38
+ aiPlaceholderIdRef: ref,
39
+ persistMessages: (next: ChatMessageData[]) => {
40
+ persisted.push(next);
41
+ },
42
+ };
43
+ return {
44
+ deps,
45
+ ref,
46
+ rows: () => rows,
47
+ persisted: () => persisted,
48
+ };
49
+ }
50
+
51
+ const userRow: ChatMessageData = { id: 'u1', role: 'user', content: 'hello' };
52
+
53
+ describe('reportPromptError', () => {
54
+ test('marks the empty optimistic row and disarms the placeholder', () => {
55
+ const probe = mount([userRow, { id: 'ai1', role: 'ai', content: '' }], 'ai1');
56
+ reportPromptError('The agent ended the turn without sending an answer', probe.deps);
57
+
58
+ expect(probe.ref.current).toBeNull();
59
+ expect(probe.rows()).toHaveLength(2);
60
+ expect(probe.rows()[1]?.error).toEqual({ message: 'The agent ended the turn without sending an answer' });
61
+ expect(probe.persisted()).toHaveLength(1);
62
+ });
63
+
64
+ test('a completed answer is not relabelled as the failure', () => {
65
+ const probe = mount([userRow, { id: 'ai1', role: 'ai', content: 'the answer' }]);
66
+ reportPromptError('agent crashed', probe.deps);
67
+
68
+ expect(probe.rows()).toHaveLength(3);
69
+ expect(probe.rows()[1]?.error).toBeUndefined();
70
+ expect(probe.rows()[2]?.error).toEqual({ message: 'agent crashed' });
71
+ });
72
+
73
+ test('a blank trailing row adopts the error instead of stacking a card', () => {
74
+ const probe = mount([userRow, { id: 'ai1', role: 'ai', content: '' }]);
75
+ reportPromptError('agent crashed', probe.deps);
76
+
77
+ expect(probe.rows()).toHaveLength(2);
78
+ expect(probe.rows()[1]?.error).toEqual({ message: 'agent crashed' });
79
+ });
80
+
81
+ test('the same failure arriving twice does not stack two cards', () => {
82
+ const probe = mount([userRow, { id: 'ai1', role: 'ai', content: 'the answer' }]);
83
+ reportPromptError('agent crashed', probe.deps);
84
+ reportPromptError('agent crashed', probe.deps);
85
+
86
+ expect(probe.rows()).toHaveLength(3);
87
+ });
88
+
89
+ test('the first, specific reason survives a later generic one', () => {
90
+ const probe = mount([userRow, { id: 'ai1', role: 'ai', content: '' }], 'ai1');
91
+ reportPromptError('401 Unauthorized', probe.deps);
92
+ reportPromptError('The agent ended the turn without sending an answer', probe.deps);
93
+
94
+ expect(probe.rows()[1]?.error).toEqual({ message: '401 Unauthorized' });
95
+ });
96
+ });
97
+
98
+ /** The callbacks with every dep defaulted, wiring the three the row needs into
99
+ * this file's state probe. */
100
+ function callbacksFor(probe: MountedPromptError) {
101
+ const deps: OmpAgentCallbacksDeps = {
102
+ setGenerating: () => {},
103
+ setGeneratingVerb: () => {},
104
+ activityRef: { current: '' },
105
+ scrollToBottom: () => {},
106
+ adoptedSessionIdRef: { current: null },
107
+ sessionIdRef: { current: 'sess-1' },
108
+ metaRefreshedRef: { current: null },
109
+ refreshSessionMeta: () => {},
110
+ setLocalMessages: probe.deps.setLocalMessages,
111
+ aiPlaceholderIdRef: probe.ref,
112
+ optimisticUserIdRef: { current: null },
113
+ pendingUserDisplaysRef: { current: [] },
114
+ persistMessages: probe.deps.persistMessages,
115
+ abortControllerRef: { current: null },
116
+ appSettings: {},
117
+ enqueueExtensionDialog: () => {},
118
+ withdrawExtensionDialog: () => {},
119
+ reloadMessages: () => {},
120
+ needsReloadRef: { current: false },
121
+ };
122
+ return createOmpAgentCallbacks(deps);
123
+ }
124
+
125
+ describe('prompt_error / notice wiring', () => {
126
+ test('a silent ACP failure marks the empty assistant row and persists it', () => {
127
+ const probe = mount([userRow, { id: 'ai1', role: 'ai', content: '' }], 'ai1');
128
+ callbacksFor(probe).onPromptError?.('The agent ended the turn without sending an answer');
129
+
130
+ expect(probe.ref.current).toBeNull();
131
+ expect(probe.rows()[1]?.error).toEqual({ message: 'The agent ended the turn without sending an answer' });
132
+ expect(probe.persisted()).toHaveLength(1);
133
+ });
134
+
135
+ test('a warning notice becomes a row; an info notice does not', () => {
136
+ const probe = mount([userRow]);
137
+ const callbacks = callbacksFor(probe);
138
+
139
+ callbacks.onNotice?.('warning', 'provider refused the request');
140
+ callbacks.onNotice?.('info', 'model warmed');
141
+
142
+ expect(probe.rows().filter((row) => row.notice)).toEqual([
143
+ expect.objectContaining({ notice: 'provider refused the request' }),
144
+ ]);
145
+ });
146
+ });
@@ -0,0 +1,88 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Turn a `prompt_error` frame into a row the timeline DRAWS.
8
+ *
9
+ * The frame used to reach `onPromptError` only, which logged it and cleared the
10
+ * generating flag. On an ACP harness a silent failure therefore left the
11
+ * optimistic AI bubble exactly as it was — an empty answer — and the reason
12
+ * lived in the console. The row the answer would have streamed into is where
13
+ * the error belongs: `MessageItem` already draws `msg.error` as the
14
+ * Provider/API Error alert for omp's transcript rows, so this path reuses that
15
+ * renderer instead of inventing a second error card.
16
+ *
17
+ * The placeholder is consumed even when it never received a byte; leaving it
18
+ * armed would let a late frame fill an empty bubble after the error.
19
+ */
20
+
21
+ import type { Dispatch, SetStateAction } from 'preact/compat';
22
+ import type { ChatMessageData } from '@/shared/types';
23
+ import { isNoticeRow } from '@/shared/lib/chat/notice-row';
24
+ import { formatClock } from '@/shared/lib/format/time';
25
+
26
+ export interface PromptErrorDeps {
27
+ setLocalMessages: Dispatch<SetStateAction<ChatMessageData[]>>;
28
+ aiPlaceholderIdRef: { current: string | null };
29
+ persistMessages: (messages: ChatMessageData[]) => void;
30
+ }
31
+
32
+ /** A row with nothing the timeline renders: no text, no thinking, no tool. */
33
+ function isBlankAnswer(msg: ChatMessageData): boolean {
34
+ if (typeof msg.content === 'string' && msg.content.trim()) return false;
35
+ if (msg.thinking || msg.monologue) return false;
36
+ return !(msg.toolCalls?.length || msg.actions?.length || msg.actions2?.length);
37
+ }
38
+
39
+ /** Tail-most rendered AI row IF it is still blank, else -1. */
40
+ function blankAssistantIndex(messages: ChatMessageData[]): number {
41
+ for (let index = messages.length - 1; index >= 0; index--) {
42
+ const msg = messages[index];
43
+ if (msg.role === 'user' || isNoticeRow(msg)) continue;
44
+ return isBlankAnswer(msg) ? index : -1;
45
+ }
46
+ return -1;
47
+ }
48
+
49
+ function errorRow(message: string): ChatMessageData {
50
+ return {
51
+ id: `prompt-error-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
52
+ role: 'ai',
53
+ date: `Today, ${formatClock()}`,
54
+ content: '',
55
+ error: { message },
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Attach the failure to the run's own row, or append a dedicated error row when
61
+ * the run already produced an answer (an agent that dies after replying must
62
+ * not relabel that reply as the failure).
63
+ */
64
+ export function reportPromptError(errorMessage: string, deps: PromptErrorDeps): void {
65
+ const message = errorMessage.trim() || 'Prompt failed';
66
+ const placeholderId = deps.aiPlaceholderIdRef.current;
67
+ deps.aiPlaceholderIdRef.current = null;
68
+ const row = errorRow(message);
69
+
70
+ deps.setLocalMessages((prev) => {
71
+ const placeholderIndex = placeholderId ? prev.findIndex((msg) => msg.id === placeholderId) : -1;
72
+ const targetIndex = placeholderIndex !== -1 ? placeholderIndex : blankAssistantIndex(prev);
73
+ if (targetIndex === -1) {
74
+ // Two failure frames for one run must not stack two identical cards.
75
+ if (prev[prev.length - 1]?.error?.message === message) return prev;
76
+ const next = [...prev, row];
77
+ deps.persistMessages(next);
78
+ return next;
79
+ }
80
+ const next = prev.map((msg, index) =>
81
+ index === targetIndex
82
+ ? { ...msg, error: { ...(msg.error ?? {}), message: msg.error?.message || message } }
83
+ : msg,
84
+ );
85
+ deps.persistMessages(next);
86
+ return next;
87
+ });
88
+ }
@@ -24,7 +24,7 @@
24
24
 
25
25
  import { describe, expect, test } from 'bun:test';
26
26
  import { HARNESS_CATALOG, HARNESS_IDS, harnessDescriptor } from '@/shared/lib/harness/catalog';
27
- import { HARNESS_LAUNCH } from '@/server/lib/harness/launch';
27
+ import { HARNESS_LAUNCH } from '@/server/lib/harness/launch-table';
28
28
 
29
29
  describe('harness catalog after the Gemini retirement', () => {
30
30
  test('gemini is not a harness this build offers', () => {
@@ -104,6 +104,10 @@ describe('the env box speaks the agent’s own vocabulary', () => {
104
104
  expect(plan.envHint).toContain('ANTHROPIC_AUTH_TOKEN');
105
105
  expect(plan.envPlaceholder).toContain('ANTHROPIC_BASE_URL');
106
106
  expect(plan.envPlaceholder).not.toContain('GEMINI');
107
+ // The picker's aliases need their own variables, or a gateway answers the
108
+ // vendor's ids with 400.
109
+ expect(plan.envHint).toContain('ANTHROPIC_DEFAULT_SONNET_MODEL');
110
+ expect(plan.envPlaceholder).toContain('ANTHROPIC_DEFAULT_OPUS_MODEL');
107
111
  // And it says what a provider here even IS.
108
112
  expect(plan.notes.join(' ')).toContain('no provider registry');
109
113
  });
@@ -85,11 +85,26 @@ function providersOf(models: readonly { value: string }[]): string[] {
85
85
  function environmentFacts(id: HarnessId): { hint: string; placeholder: string; notes: string[] } {
86
86
  const facts = providerFacts(id);
87
87
  if (facts.env) {
88
- const names = [facts.env.baseUrl, facts.env.apiKey, facts.env.model].filter(Boolean).join(', ');
88
+ const { env } = facts;
89
+ const names = [env.baseUrl, env.apiKey, env.model].filter(Boolean).join(', ');
90
+ const aliases = env.modelAliases ?? [];
91
+ const aliasNames = aliases.map((alias) => alias.env).join(', ');
89
92
  return {
90
- hint: `The variables that point this agent at one endpoint: ${names}. Setting them REPLACES its own provider.`,
91
- placeholder: `${facts.env.baseUrl}=https://…\n${facts.env.apiKey}=…`,
92
- notes: ['This agent has no provider registry — a provider here is an endpoint and a key, nothing else.'],
93
+ hint: aliases.length > 0
94
+ ? `The variables that point this agent at one endpoint: ${names}. A picker alias still resolves to the vendor's model id unless ${aliasNames} pins it to an id this endpoint serves; unpinned aliases answer 400. Setting them REPLACES its own provider.`
95
+ : `The variables that point this agent at one endpoint: ${names}. Setting them REPLACES its own provider.`,
96
+ placeholder: [
97
+ `${env.baseUrl}=https://…`,
98
+ `${env.apiKey}=…`,
99
+ ...(env.model ? [`${env.model}=…`] : []),
100
+ ...(aliases[0] ? [`${aliases[0].env}=…`] : []),
101
+ ].join('\n'),
102
+ notes: [
103
+ 'This agent has no provider registry — a provider here is an endpoint and a key, nothing else.',
104
+ ...(aliases.length > 0
105
+ ? ['A picker alias with no default-model variable keeps the vendor’s model id; a custom endpoint answers that id with 400.']
106
+ : []),
107
+ ],
93
108
  };
94
109
  }
95
110
  if (facts.registry.kind === 'none') {
@@ -129,4 +129,12 @@ describe('supportedProtocols', () => {
129
129
  expect(supportedProtocols('none')).toEqual([]);
130
130
  expect(supportedProtocols('agent-managed')).toEqual([]);
131
131
  });
132
+
133
+ test('zcode carries its three documented wire types, not Gemini', () => {
134
+ expect(supportedProtocols('zcode-provider-rules')).toEqual([
135
+ 'openai-chat', 'openai-responses', 'anthropic-messages',
136
+ ]);
137
+ // The registry has no Google route: an import must refuse, not mislabel.
138
+ expect(dialectFor('zcode-provider-rules', 'google-genai')).toBeNull();
139
+ });
132
140
  });
@@ -73,6 +73,8 @@ const SOURCE_DIALECTS: Readonly<Record<string, CanonicalProtocol>> = {
73
73
  chat: 'openai-chat',
74
74
  'chat-completions': 'openai-chat',
75
75
  chatcompletions: 'openai-chat',
76
+ 'openai-chat-completions': 'openai-chat',
77
+ 'openaichatcompletions': 'openai-chat',
76
78
  'ai-sdk-openai-compatible': 'openai-chat',
77
79
  'opencode-ai-providers-openai-compatible': 'openai-chat',
78
80
  kimi: 'openai-chat',
@@ -170,6 +172,16 @@ export function dialectFor(kind: ProviderRegistryKind, protocol: CanonicalProtoc
170
172
  'google-genai': 'gemini',
171
173
  'vertex-ai': 'vertex-ai',
172
174
  }[protocol];
175
+ case 'zcode-provider-rules':
176
+ // ZCode's own enum (`config.api.type`). Google has no route in its
177
+ // registry, so a Gemini endpoint is refused instead of mislabelled.
178
+ return {
179
+ 'openai-chat': 'openai-chat-completions',
180
+ 'openai-responses': 'openai-responses',
181
+ 'anthropic-messages': 'anthropic-messages',
182
+ 'google-genai': null,
183
+ 'vertex-ai': null,
184
+ }[protocol];
173
185
  default:
174
186
  return null;
175
187
  }
@@ -46,6 +46,7 @@ const WRITABLE: Record<string, string> = {
46
46
  pi: 'json-providers',
47
47
  kimi: 'toml-providers',
48
48
  qwen: 'json-model-providers',
49
+ zcode: 'zcode-provider-rules',
49
50
  };
50
51
 
51
52
  describe('the measured registry table', () => {
@@ -86,18 +87,26 @@ describe('the measured registry table', () => {
86
87
  expect(managesProviders('minimax')).toBe(false);
87
88
  });
88
89
 
89
- test('zcode credentials belong to the ZCode app, never to Kabmo', () => {
90
- // The ACP bridge reads the app's own config.json / acp-accounts.json. An
91
- // editor that rewrote either would break the install it is driving.
90
+ test('zcode writes personal providers beside the app, never the app config', () => {
91
+ // 3.12+ stores user-added providers in `provider_config.json`; the legacy
92
+ // `config.json` map is the desktop app's and keeps its credentials. Writing
93
+ // THAT file is how a signed-in install stops signing in.
92
94
  const registry = providerFacts('zcode').registry;
93
- expect(registry.kind).toBe('agent-managed');
94
- expect(registry.file).toBe('.zcode/v2/config.json');
95
- expect(registry.writable).toBe(false);
96
- expect(managesProviders('zcode')).toBe(false);
95
+ expect(registry.kind).toBe('zcode-provider-rules');
96
+ expect(registry.file).toBe('.zcode/v2/provider_config.json');
97
+ expect(registry.file).not.toBe('.zcode/v2/config.json');
98
+ expect(registry.pointer).toBe('config.providerConfigRules.providerRules');
99
+ expect(registry.baseUrlField).toBe('config.api.baseUrl');
100
+ expect(registry.apiKeyField).toBe('config.access.apiKey');
101
+ expect(registry.dialectField).toBe('config.api.type');
102
+ expect(registry.writable).toBe(true);
103
+ expect(managesProviders('zcode')).toBe(true);
97
104
  });
98
105
 
99
106
  test('the env-only harnesses keep their vendor variable names', () => {
100
- expect(providerFacts('claude').env).toEqual({
107
+ // The alias table is asserted in `providerEnv` below; this is the endpoint
108
+ // and key each vendor documents.
109
+ expect(providerFacts('claude').env).toMatchObject({
101
110
  baseUrl: 'ANTHROPIC_BASE_URL', apiKey: 'ANTHROPIC_AUTH_TOKEN', model: 'ANTHROPIC_MODEL',
102
111
  });
103
112
  expect(providerFacts('antigravity').env).toEqual({
@@ -154,6 +163,10 @@ describe('labels a reader can check against the vendor docs', () => {
154
163
  expect(dialectChoices('toml-providers').map((d) => d.value)).toContain('openai_legacy');
155
164
  // qwen routes by protocol id, so it has no dialect field of its own.
156
165
  expect(dialectChoices('json-model-providers')).toEqual([]);
166
+ // ZCode documents exactly these three wire types; Gemini has no route there.
167
+ expect(dialectChoices('zcode-provider-rules').map((d) => d.value)).toEqual([
168
+ 'anthropic-messages', 'openai-chat-completions', 'openai-responses',
169
+ ]);
157
170
  });
158
171
  });
159
172
 
@@ -163,6 +176,17 @@ describe('providerEnv', () => {
163
176
  .toEqual({ ANTHROPIC_BASE_URL: 'https://gw', ANTHROPIC_AUTH_TOKEN: 'sk-1', ANTHROPIC_MODEL: 'claude-sonnet-5' });
164
177
  });
165
178
 
179
+ test('claude pins every picker alias, so a gateway id can replace the vendor’s', () => {
180
+ // Measured: `--model sonnet` against a gateway listing `claude-sonnet-5-5`
181
+ // answered `400 model not found: sonnet` until the alias variable existed.
182
+ expect(providerFacts('claude').env?.modelAliases).toEqual([
183
+ { family: 'opus', env: 'ANTHROPIC_DEFAULT_OPUS_MODEL' },
184
+ { family: 'sonnet', env: 'ANTHROPIC_DEFAULT_SONNET_MODEL' },
185
+ { family: 'haiku', env: 'ANTHROPIC_DEFAULT_HAIKU_MODEL' },
186
+ { family: 'fable', env: 'ANTHROPIC_DEFAULT_FABLE_MODEL' },
187
+ ]);
188
+ });
189
+
166
190
  test('a blank field writes no variable at all', () => {
167
191
  // An empty env var is a real thing to set, so the form must not do it by
168
192
  // accident.
@@ -34,7 +34,7 @@
34
34
  * | minimax | its own BYOK store, written by `mcode` | not a file Kabmo may edit |
35
35
  * | claude | env only | `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN` |
36
36
  * | antigravity | env only | `GOOGLE_GEMINI_BASE_URL`, `GEMINI_API_KEY` |
37
- * | zcode | `~/.zcode/v2/config.json` | written by the ZCode app, not by an editor |
37
+ * | zcode | `~/.zcode/v2/provider_config.json` | `config.providerConfigRules.providerRules` (3.12+ personal providers) |
38
38
  * | cursor, dsh | none Kabmo can write | the launch line and its env |
39
39
  *
40
40
  * A file Kabmo may READ but must not WRITE is marked `readOnly`: minimax keeps its
@@ -59,6 +59,9 @@ export type ProviderRegistryKind =
59
59
  | 'toml-providers'
60
60
  /** A JSON settings document with `modelProviders` (qwen). */
61
61
  | 'json-model-providers'
62
+ /** ZCode's personal-provider rules: arrays under `config.providerConfigRules`
63
+ * and `config.modelConfigRules` (3.12+). */
64
+ | 'zcode-provider-rules'
62
65
  /** No provider registry this build writes; an env contract instead. */
63
66
  | 'env'
64
67
  /** A registry that exists but belongs to the agent's own writer. */
@@ -97,11 +100,23 @@ export interface ProviderRegistry {
97
100
  modelsAreRows?: boolean;
98
101
  }
99
102
 
103
+ /**
104
+ * One picker alias a vendor SDK resolves from the environment. Claude Code's
105
+ * `opus`/`sonnet`/`haiku`/`fable` aliases resolve to ids the VENDOR ships
106
+ * unless `ANTHROPIC_DEFAULT_<FAMILY>_MODEL` pins them; a gateway that lists
107
+ * only its own ids answers the vendor ids with `400 model not found`.
108
+ */
109
+ export interface EnvModelAlias {
110
+ family: string;
111
+ env: string;
112
+ }
113
+
100
114
  /** The env names an `environment` harness reads, in the order its docs list. */
101
115
  export interface EnvProviderContract {
102
116
  baseUrl: string;
103
117
  apiKey: string;
104
118
  model?: string;
119
+ modelAliases?: readonly EnvModelAlias[];
105
120
  }
106
121
 
107
122
  export interface HarnessProviderFacts {
@@ -239,7 +254,20 @@ export const HARNESS_PROVIDER_FACTS: Readonly<Partial<Record<HarnessId, HarnessP
239
254
  kind: 'env', file: null, pointer: 'environment',
240
255
  writable: true, baseUrlField: null, apiKeyField: null, modelsField: null,
241
256
  },
242
- env: { baseUrl: 'ANTHROPIC_BASE_URL', apiKey: 'ANTHROPIC_AUTH_TOKEN', model: 'ANTHROPIC_MODEL' },
257
+ env: {
258
+ baseUrl: 'ANTHROPIC_BASE_URL',
259
+ apiKey: 'ANTHROPIC_AUTH_TOKEN',
260
+ model: 'ANTHROPIC_MODEL',
261
+ // The picker's aliases resolve through these variables. Set only the ones
262
+ // the gateway serves: an unmapped alias keeps resolving to the vendor's
263
+ // id, which a custom endpoint answers with `400 model not found`.
264
+ modelAliases: [
265
+ { family: 'opus', env: 'ANTHROPIC_DEFAULT_OPUS_MODEL' },
266
+ { family: 'sonnet', env: 'ANTHROPIC_DEFAULT_SONNET_MODEL' },
267
+ { family: 'haiku', env: 'ANTHROPIC_DEFAULT_HAIKU_MODEL' },
268
+ { family: 'fable', env: 'ANTHROPIC_DEFAULT_FABLE_MODEL' },
269
+ ],
270
+ },
243
271
  // Claude Code speaks Anthropic Messages only, and appends `/v1/messages`
244
272
  // itself — measured: BASE_URL with `/v1` still on it requested
245
273
  // `/v1/v1/messages` and answered with an empty turn.
@@ -279,17 +307,24 @@ export const HARNESS_PROVIDER_FACTS: Readonly<Partial<Record<HarnessId, HarnessP
279
307
  },
280
308
  zcode: {
281
309
  registry: {
282
- // MEASURED against the bridge's own reference: it reads credentials and
283
- // providers from the ZCode app's `config.json` (or the private
284
- // `acp-accounts.json` written by `zcode-acp setup`). Rewriting the app's
285
- // file from an editor is how a signed-in install stops signing in, so the
286
- // entry is readable in principle and writable by nobody but the app.
287
- kind: 'agent-managed', file: '.zcode/v2/config.json', pointer: '—',
288
- writable: false, baseUrlField: null, apiKeyField: null, modelsField: null,
310
+ // MEASURED against the bridge's own reference and the installed 0.82.3
311
+ // bundle: `~/.zcode/v2/config.json` is the LEGACY provider map, and the
312
+ // personal providers a user adds in the 3.12+ desktop app (or the CLI's
313
+ // setup wizard) live in `provider_config.json`. The bridge reads both: the
314
+ // rule arrays are authoritative for custom providers, while `config.json`
315
+ // keeps builtin credentials. Writing `provider_config.json` is supported by
316
+ // the runtime (`provider-config.ts` writes it through a file lock and the
317
+ // backend absorbs external edits on a ~1s poll), so this registry is
318
+ // writable — unlike `config.json`, which the app owns.
319
+ kind: 'zcode-provider-rules', file: '.zcode/v2/provider_config.json',
320
+ pointer: 'config.providerConfigRules.providerRules',
321
+ writable: true, baseUrlField: 'config.api.baseUrl',
322
+ apiKeyField: 'config.access.apiKey', dialectField: 'config.api.type',
323
+ modelsField: 'config.personalModelIds', modelsAreRows: true,
289
324
  },
290
325
  createsChoice: true,
291
- importFrom: [],
292
- summary: 'ZCode keeps providers and credentials in ~/.zcode/v2/config.json, written by the app (or `zcode-acp setup`). Kabmo reads what they publish and never rewrites the file.',
326
+ importFrom: ['omp-rpc', 'opencode', 'codex', 'pi', 'kimi', 'qwen'],
327
+ summary: 'ZCode keeps user-added providers in ~/.zcode/v2/provider_config.json (3.12+), as provider rules plus one model rule per id. Kabmo merges one provider into that file and leaves the app’s legacy config.json untouched. Chats still need a ZCode runtime: the desktop app, or `zcode-app-cli` on PATH (`ZCODE_BIN` for a custom install).',
293
328
  },
294
329
  };
295
330
 
@@ -36,6 +36,7 @@ export function registryLabel(id: string | null | undefined): string {
36
36
  case 'json-providers': return 'models.json (pi)';
37
37
  case 'toml-providers': return 'config.toml (kimi)';
38
38
  case 'json-model-providers': return 'settings.json (qwen)';
39
+ case 'zcode-provider-rules': return 'provider_config.json (zcode)';
39
40
  case 'agent-managed': return "the agent's own provider command";
40
41
  case 'env': return 'environment variables';
41
42
  default: return 'launch command and env';
@@ -134,6 +135,14 @@ export function dialectChoices(kind: ProviderRegistryKind): readonly { value: st
134
135
  { value: 'kimi', label: 'Kimi' },
135
136
  { value: 'vertexai', label: 'Google Vertex AI' },
136
137
  ];
138
+ case 'zcode-provider-rules':
139
+ // The three wire types ZCode's provider reference documents. Google is
140
+ // absent from its own enum, so it is not offered as a choice here.
141
+ return [
142
+ { value: 'anthropic-messages', label: 'Anthropic Messages' },
143
+ { value: 'openai-chat-completions', label: 'OpenAI Chat Completions' },
144
+ { value: 'openai-responses', label: 'OpenAI Responses' },
145
+ ];
137
146
  default:
138
147
  return [];
139
148
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which harnesses Kabmo can rewind IN PLACE.
8
+ *
9
+ * Undo and Retry truncate the conversation and then re-run a turn, so the
10
+ * agent's own context must be truncatable with it. That is only true where the
11
+ * transcript is the JSONL omp writes — `omp-rpc` and `omp-acp` are the same
12
+ * product over two transports, and the ACP child is torn down before the file
13
+ * is rewritten (the next prompt resumes it over RPC).
14
+ *
15
+ * Every other ACP agent keeps the conversation in its own store, and ACP
16
+ * defines no truncation verb (`session/load` replays the whole history, a fork
17
+ * copies it). Truncating Kabmo's copy there would leave the agent answering
18
+ * from turns the timeline no longer shows — a silent divergence, not a rewind.
19
+ * An UNKNOWN harness keeps the historical allow: the caller has not resolved it
20
+ * yet, and the endpoint answers the real refusal.
21
+ */
22
+ export function harnessSupportsRewind(harness: string | null | undefined): boolean {
23
+ return !harness || harness === 'omp-rpc' || harness === 'omp-acp';
24
+ }
@@ -19,7 +19,12 @@
19
19
  */
20
20
 
21
21
  import { describe, expect, test } from 'bun:test';
22
- import { planHarnessUpdate, type UpdatePlanState } from '@/shared/lib/harness/update-plan';
22
+ import {
23
+ planHarnessUpdate,
24
+ repointAdapterLaunch,
25
+ type HarnessUpdateStep,
26
+ type UpdatePlanState,
27
+ } from '@/shared/lib/harness/update-plan';
23
28
  import { harnessUpdateFacts } from '@/shared/lib/harness/updates';
24
29
 
25
30
  const CLAUDE = harnessUpdateFacts('claude');
@@ -33,6 +38,32 @@ function state(overrides: Partial<UpdatePlanState> = {}): UpdatePlanState {
33
38
  };
34
39
  }
35
40
 
41
+ describe('repointing a launch line after an adapter install', () => {
42
+ const install: HarnessUpdateStep = {
43
+ part: 'adapter',
44
+ command: 'npm install -g @agentclientprotocol/claude-agent-acp@0.101.0',
45
+ argv: ['npm', 'install', '-g', '@agentclientprotocol/claude-agent-acp@0.101.0'],
46
+ };
47
+
48
+ test('a pinned npx adapter is pointed at the binary the install wrote', () => {
49
+ // The launch requests 0.100.0; the install wrote 0.101.0. Without this, the
50
+ // press reports success and every new session still starts the pinned build.
51
+ expect(repointAdapterLaunch(CLAUDE, [install], '', true)).toBe('claude-agent-acp');
52
+ });
53
+
54
+ test('a user command is never replaced', () => {
55
+ expect(repointAdapterLaunch(CLAUDE, [install], '/opt/bin/my-claude-wrapper', true)).toBeNull();
56
+ });
57
+
58
+ test('no install step, no repoint', () => {
59
+ expect(repointAdapterLaunch(CLAUDE, [], '', true)).toBeNull();
60
+ });
61
+
62
+ test('a binary that did not land on PATH is not claimed', () => {
63
+ expect(repointAdapterLaunch(CLAUDE, [install], '', false)).toBeNull();
64
+ });
65
+ });
66
+
36
67
  describe('planning a harness update', () => {
37
68
  test('both parts behind runs the install AND the CLI updater, in that order', () => {
38
69
  const steps = planHarnessUpdate('claude', CLAUDE, state(), '0.100.0');
@@ -99,6 +130,25 @@ describe('planning a harness update', () => {
99
130
  expect(steps[0].argv[0]).toBe('npm');
100
131
  });
101
132
 
133
+ test('an npm CLI with no vendor updater moves through its own package', () => {
134
+ // `dsh` reports the ACP surface (0.0.1) while `dsh --version` is 0.2.2-rc.1;
135
+ // the CLI carries the package and has no `dsh update`. Leaving this half out
136
+ // made every press compare the adapter's version to the CLI's package.
137
+ const steps = planHarnessUpdate(
138
+ 'deepseek-harness',
139
+ harnessUpdateFacts('dsh'),
140
+ {
141
+ installed: true,
142
+ agent: { version: '0.0.1', latest: null },
143
+ cli: { name: 'deepseek-harness', version: '0.2.2-rc.1', latest: '0.3.0' },
144
+ },
145
+ '0.0.1',
146
+ );
147
+ expect(steps).toHaveLength(1);
148
+ expect(steps[0].part).toBe('deepseek-harness');
149
+ expect(steps[0].argv).toEqual(['npm', 'install', '-g', '@deepseek-ai/dsh@0.3.0']);
150
+ });
151
+
102
152
  test('a plain npm harness names itself, not "adapter"', () => {
103
153
  const steps = planHarnessUpdate(
104
154
  'qwen',