@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
@@ -12,26 +12,26 @@
12
12
  * omp's list under the `claude` tab would offer a model that agent cannot run,
13
13
  * and picking it would fail at the first prompt.
14
14
  *
15
- * The rule is therefore: **the active tab decides the list.** Two sources exist
16
- * and only two:
15
+ * The rule is therefore: **the active tab decides the list.** Three sources
16
+ * exist, and they are ranked:
17
17
  *
18
18
  * - `omp-rpc` — Kabmo's `/api/models` (today's list, with favorites, recents
19
19
  * and the provider plates), because that registry IS omp's;
20
- * - every ACP harness — the `models[]` its own `session/new` returned, mapped
21
- * into the same `AIModelOption` shape so the rows render identically.
20
+ * - an ACP harness with a LIVE chat — the selectors that session itself
21
+ * published (`get_state` → `configOptions`), because that is the list the
22
+ * agent is offering right now. A probe runs its OWN spawn, so it can refuse
23
+ * (codex asks for authentication in the probe while the chat that is
24
+ * already running lists its models) and its answer ages;
25
+ * - an ACP harness with no live chat — the `models[]` its own probe
26
+ * `session/new` returned, mapped into the same `AIModelOption` shape so the
27
+ * rows render identically.
22
28
  *
23
- * An unprobed ACP harness yields an EMPTY list plus the reason, never omp's
29
+ * An ACP harness with neither yields an EMPTY list plus the reason, never omp's
24
30
  * models as a stand-in.
25
31
  */
26
32
 
27
33
  import type { AIModelOption } from '@/shared/types';
28
- import type { HarnessSummary } from '@/shared/types/harness';
29
-
30
- /** An `<option>`-style pair, as `configOptions` publishes them. */
31
- export interface HarnessModelOption {
32
- value: string;
33
- name: string;
34
- }
34
+ import type { HarnessSelectorValue, HarnessSummary, LiveHarnessModels } from '@/shared/types/harness';
35
35
 
36
36
  export interface HarnessModelList {
37
37
  /** Exactly the rows to render — never a union of two harnesses' catalogs. */
@@ -56,9 +56,9 @@ function splitSelector(value: string): { provider: string; id: string } {
56
56
 
57
57
  /** Map one ACP selector value into the picker's row shape. */
58
58
  export function acpModelOption(
59
- option: HarnessModelOption,
59
+ option: HarnessSelectorValue,
60
60
  harness: string,
61
- thinking: readonly HarnessModelOption[] = [],
61
+ thinking: readonly HarnessSelectorValue[] = [],
62
62
  ): AIModelOption {
63
63
  const { provider, id } = splitSelector(option.value);
64
64
  return {
@@ -86,11 +86,15 @@ export function acpModelOption(
86
86
  * recents and the provider plates the user built up. Any other harness REPLACES
87
87
  * it — never merges: two agents' models in one list is a row the tab does not
88
88
  * describe.
89
+ *
90
+ * `live` is what the OPEN chat's own session published, when it is running on
91
+ * this harness. It wins over `probe` (see the module header).
89
92
  */
90
93
  export function harnessModels(
91
94
  harnesses: readonly HarnessSummary[],
92
95
  harness: string | undefined,
93
96
  ompModels: readonly AIModelOption[] = [],
97
+ live?: LiveHarnessModels | null,
94
98
  ): HarnessModelList {
95
99
  // No harness yet (a brand-new chat) → omp's registry, which is the default
96
100
  // agent and therefore the honest preview.
@@ -98,11 +102,22 @@ export function harnessModels(
98
102
 
99
103
  const summary = harnesses.find((entry) => entry.id === harness);
100
104
  if (!summary) return { models: [], unprobed: true };
101
- const blocked = summary.probe?.capabilities.blocked ?? summary.unavailable;
102
- if (!summary.probe) return { models: [], unprobed: true, ...(blocked ? { blocked } : {}) };
105
+
106
+ // What the OPEN CHAT published outranks what one spawn measured: the live
107
+ // session is the one about to receive the pick.
108
+ const liveModels = live?.models ?? [];
109
+ const published = liveModels.length > 0 ? liveModels : (summary.probe?.models ?? []);
110
+ const thinking = live?.thinking?.length ? live.thinking : (summary.probe?.thinking ?? []);
111
+ if (published.length === 0) {
112
+ const blocked = summary.probe?.capabilities.blocked ?? summary.unavailable;
113
+ return { models: [], unprobed: !summary.probe, ...(blocked ? { blocked } : {}) };
114
+ }
115
+ // A block is evidence about a DIFFERENT spawn; saying "Authentication
116
+ // required" beside rows the running chat is offering would contradict the list
117
+ // it sits on, so only an uninstalled harness keeps its refusal here.
118
+ const blocked = liveModels.length > 0 ? undefined : summary.unavailable;
103
119
  return {
104
- models: (summary.probe.models ?? []).map((option) =>
105
- acpModelOption(option, harness, summary.probe?.thinking ?? [])),
120
+ models: published.map((option) => acpModelOption(option, harness, thinking)),
106
121
  unprobed: false,
107
122
  ...(blocked ? { blocked } : {}),
108
123
  };
@@ -47,7 +47,7 @@ export function ModelDropdown({
47
47
  harnessEditable = true,
48
48
  isMobile,
49
49
  }: ModelDropdownProps) {
50
- const { harnesses } = useHarnesses();
50
+ const { harnesses, liveModels } = useHarnesses();
51
51
  /**
52
52
  * The harness whose list is on screen.
53
53
  *
@@ -88,8 +88,8 @@ export function ModelDropdown({
88
88
  * at the first prompt.
89
89
  */
90
90
  const harnessList = useMemo(
91
- () => harnessModels(harnesses, activeHarness, models),
92
- [harnesses, activeHarness, models],
91
+ () => harnessModels(harnesses, activeHarness, models, liveModels[activeHarness]),
92
+ [harnesses, activeHarness, models, liveModels],
93
93
  );
94
94
  /** The tabs this picker may offer, from the same rule the model rows use. */
95
95
  const tabsForPicker = pickerHarnesses(harnesses, activeHarness);
@@ -34,8 +34,11 @@ const GUTTER = 8;
34
34
  * marks, the model name, a context figure, a thinking chip and a favourite star,
35
35
  * and `Agnes-2-5-Flash - Free` measured `scrollWidth 139 / clientWidth 0` once
36
36
  * the trailing plates took their share.
37
+ *
38
+ * Exported because the About card sizes itself to this same cap: the console has
39
+ * one width class for its floating cards, and a second number there would drift.
37
40
  */
38
- const MAX_WIDTH = 512;
41
+ export const MAX_WIDTH = 512;
39
42
  /** Narrowest it is allowed to get before it stops being usable. */
40
43
  const MIN_WIDTH = 240;
41
44
  /**
@@ -1,5 +1,5 @@
1
1
  {
2
- "source": "@oh-my-pi/pi-coding-agent 10 tabs / 602 settings",
2
+ "source": "@oh-my-pi/pi-coding-agent 10 tabs / 604 settings",
3
3
  "tabs": [
4
4
  {
5
5
  "id": "appearance",
@@ -767,7 +767,7 @@
767
767
  "tab": "appearance",
768
768
  "group": "Display",
769
769
  "label": "Mouse Click-to-Focus",
770
- "description": "Capture mouse clicks in the main session so live subagent cards and HUD rows focus on click, with a hover highlight on the target, and clicks on extension-owned links reach their extension (the link-hint key picks them without the mouse). Native text selection becomes Shift+drag and wheel scroll becomes Shift+wheel while on"
770
+ "description": "Capture mouse clicks in the main session so live subagent cards and HUD rows focus on click, with a hover highlight on the target, and clicks on extension-owned links reach their extension (the link-hint key picks them without the mouse). Native text selection becomes Shift+drag while on, and mouse capture stops wheel scrolling — the terminal reports wheel ticks to omp instead — so scroll with the terminal's keyboard scrollback keys, or turn this off"
771
771
  }
772
772
  },
773
773
  "tui.tight": {
@@ -5020,7 +5020,7 @@
5020
5020
  "tab": "memory",
5021
5021
  "group": "Mnemopi",
5022
5022
  "label": "Mnemopi DB Path",
5023
- "description": "Optional SQLite DB path. Defaults to the agent memories directory.",
5023
+ "description": "Optional SQLite DB path; a leading ~ is the home directory. Defaults to the agent memories directory.",
5024
5024
  "condition": "mnemopiActive"
5025
5025
  }
5026
5026
  },
@@ -7469,7 +7469,7 @@
7469
7469
  "tab": "tasks",
7470
7470
  "group": "Subagents",
7471
7471
  "label": "Prefer Task Delegation",
7472
- "description": "How strongly to push delegating work to subagents",
7472
+ "description": "How strongly to push the main agent to delegate work; subagents keep the model's own policy",
7473
7473
  "options": [
7474
7474
  {
7475
7475
  "value": "default",
@@ -58,7 +58,7 @@ export interface ChatTimelineActionsDeps {
58
58
  /** Server-backed per-item queue ops (append/remove/reorder). */
59
59
  enqueueMessage: (item: Omit<QueuedMessage, 'id'>) => void;
60
60
  removeMessage: (id: string) => void;
61
- executeSend: (text: string, attachments: Attachment[], options?: { model?: QueuedMessageModel | null }) => Promise<PromptDispatchResult>;
61
+ executeSend: (text: string, attachments: Attachment[], options?: { model?: QueuedMessageModel | null; harness?: string | null }) => Promise<PromptDispatchResult>;
62
62
  steerOmpAgent: (text: string, attachments: Attachment[]) => Promise<PromptDispatchResult>;
63
63
  ompAgent: OmpAgentHandle;
64
64
  abortControllerRef: { current: AbortController | null };
@@ -113,7 +113,7 @@ export interface ChatTimelineActionsResult {
113
113
  handleSendNowQueueItem: (item: QueuedMessage) => Promise<void>;
114
114
  handleUndo: (msgId: string, content?: string) => Promise<boolean>;
115
115
  handleRetry: (msgId: string) => void;
116
- submitNewChat: (text: string, attachments: Attachment[]) => void;
116
+ submitNewChat: (text: string, attachments: Attachment[], harness?: string) => void;
117
117
  /** Stop the active run; returns the number of queue items held back. */
118
118
  stopGenerating: () => number;
119
119
  handleThinkingLevelChange: (level: string) => void;
@@ -42,7 +42,9 @@
42
42
  import { createContext, useContext } from 'preact/compat';
43
43
  import type { ChatMessageData } from '@/shared/types';
44
44
  import type { ExtensionUiDialogRequest } from '@/shared/types/omp/agent';
45
- import { groupAskFrames, isAskSettled, isAskToolCall, normalizeAskText, parseAskQuestions, parseAskResult, type AskQuestion } from '@/shared/lib/chat/ask-questions';
45
+ import { askQuestionForTitle, groupAskFrames, isAskSettled, isAskToolCall, normalizeAskText, parseAskQuestions } from '@/shared/lib/chat/ask-questions';
46
+ import { parseAskResult } from '@/shared/lib/chat/ask-results';
47
+ import type { AskQuestion } from '@/shared/lib/chat/ask-form/types';
46
48
  import { isApprovalGateFrame } from '@/shared/lib/chat/omp/approval-gate';
47
49
  import type { ExtensionDialogResponse } from '@/client/components/workspace/chat-timeline/tool-renderers/extension-dialog/Lazy';
48
50
 
@@ -165,15 +167,14 @@ export function splitAskFrames(
165
167
  continue;
166
168
  }
167
169
 
168
- const title = typeof request.title === 'string' ? normalizeAskText(request.title) : '';
169
170
  let owner: string | null = null;
170
- if (title) {
171
+ if (typeof request.title === 'string' && request.title) {
171
172
  // Newest first: omp asks one question at a time and blocks on it, so when
172
173
  // two live calls name the same question the later one is the one in
173
174
  // flight.
174
175
  for (let index = openAsks.length - 1; index >= 0; index -= 1) {
175
176
  const candidate = openAsks[index];
176
- if (candidate.questions.some((question) => normalizeAskText(question.question) === title)) {
177
+ if (askQuestionForTitle(candidate.questions, request.title) !== -1) {
177
178
  owner = candidate.toolId;
178
179
  break;
179
180
  }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The New Chat card's harness capture.
8
+ *
9
+ * The card has no harness picker, so the agent that owns the chat it was opened
10
+ * FROM is the only source for the new chat's spawn. A capture that read the
11
+ * current render instead of the open-time pick would silently change when the
12
+ * sidebar's harness row settles — and a capture that was never taken spawned the
13
+ * new chat on omp's RPC default.
14
+ */
15
+
16
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'bun:test';
17
+ import { Window } from 'happy-dom';
18
+ import { h, render } from 'preact';
19
+ import { act } from 'preact/test-utils';
20
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
21
+ import { useNewChatOpen, type NewChatOpen, type NewChatOpenDeps } from '@/client/hooks/chat/timeline/new-chat-open';
22
+
23
+ let container: HTMLElement | undefined;
24
+ let hook: NewChatOpen | null = null;
25
+
26
+ function Probe({ deps }: { deps: NewChatOpenDeps }) {
27
+ hook = useNewChatOpen(deps);
28
+ return null;
29
+ }
30
+
31
+ async function mount(deps: NewChatOpenDeps): Promise<void> {
32
+ container ??= document.body.appendChild(document.createElement('div'));
33
+ await act(async () => {
34
+ render(h(Probe, { deps }), container as HTMLElement);
35
+ });
36
+ await act(async () => {});
37
+ }
38
+
39
+ function deps(overrides: Partial<NewChatOpenDeps> = {}): NewChatOpenDeps {
40
+ return { folders: [], sessionId: 'sess-aaa', selectedFolderId: null, ...overrides };
41
+ }
42
+
43
+ beforeAll(() => {
44
+ installDomGlobals(new Window({ url: 'http://localhost' }));
45
+ });
46
+
47
+ afterAll(() => {
48
+ restoreDomGlobals();
49
+ });
50
+
51
+ afterEach(() => {
52
+ if (container) render(null, container);
53
+ container?.remove();
54
+ container = undefined;
55
+ hook = null;
56
+ });
57
+
58
+ describe('useNewChatOpen', () => {
59
+ test('captures the source chat harness at open time', async () => {
60
+ await mount(deps({ harness: 'opencode' }));
61
+
62
+ await act(async () => { hook?.open('halo'); });
63
+
64
+ expect(hook?.content).toBe('halo');
65
+ expect(hook?.harness).toBe('opencode');
66
+ });
67
+
68
+ test('a card opened from a chat with no resolved harness carries none', async () => {
69
+ await mount(deps());
70
+
71
+ await act(async () => { hook?.open('halo'); });
72
+
73
+ expect(hook?.content).toBe('halo');
74
+ expect(hook?.harness).toBeUndefined();
75
+ });
76
+
77
+ test('closing the card drops the capture with the content', async () => {
78
+ await mount(deps({ harness: 'omp-acp' }));
79
+ await act(async () => { hook?.open('halo'); });
80
+
81
+ await act(async () => { hook?.close(); });
82
+
83
+ expect(hook?.content).toBeNull();
84
+ expect(hook?.harness).toBeUndefined();
85
+ });
86
+ });
@@ -14,7 +14,9 @@
14
14
  *
15
15
  * The folder resolution mirrors `useNewChatSubmit` — the active session's
16
16
  * folder, else the composer's pick — because a prewarm in a different cwd is a
17
- * process the send never claims, which costs a spawn AND a kill.
17
+ * process the send never claims, which costs a spawn AND a kill. The HARNESS is
18
+ * the second half of that rule: the pool holds omp RPC children, so a card
19
+ * opened from an ACP chat (whose new chat stays on that agent) warms nothing.
18
20
  */
19
21
 
20
22
  import { useCallback, useState } from 'preact/hooks';
@@ -27,6 +29,13 @@ export interface NewChatOpen {
27
29
  content: string | null;
28
30
  /** Attachments of the row the card was opened from. */
29
31
  attachments: Attachment[];
32
+ /**
33
+ * The harness of the chat the card was opened FROM, captured at open time.
34
+ * A New Chat from an ACP answer must stay on that agent: the dialog has no
35
+ * harness picker, and a spawn that omitted it quietly started the new chat on
36
+ * omp's RPC transport instead of the agent that wrote the answer.
37
+ */
38
+ harness?: string;
30
39
  /** Open the card on `content`, warming the child for the chat it will create. */
31
40
  open: (content: string, attachments?: Attachment[]) => void;
32
41
  close: () => void;
@@ -37,24 +46,33 @@ export interface NewChatOpenDeps {
37
46
  /** Session the card was opened from — the scope the prewarm inherits. */
38
47
  sessionId: string | null;
39
48
  selectedFolderId: number | null;
49
+ /** The harness that owns `sessionId`, carried onto the new chat's spawn. */
50
+ harness?: string;
40
51
  }
41
52
 
42
- export function useNewChatOpen({ folders, sessionId, selectedFolderId }: NewChatOpenDeps): NewChatOpen {
53
+ export function useNewChatOpen({ folders, sessionId, selectedFolderId, harness }: NewChatOpenDeps): NewChatOpen {
43
54
  const [content, setContent] = useState<string | null>(null);
44
55
  const [attachments, setAttachments] = useState<Attachment[]>([]);
56
+ /** Captured on open, cleared with the card: the picker is not in the dialog. */
57
+ const [openedHarness, setOpenedHarness] = useState<string | undefined>(undefined);
45
58
 
46
59
  const open = useCallback((next: string, rows?: Attachment[]) => {
47
60
  const folderId = activeProjectForSession(folders, sessionId).folder?.id ?? selectedFolderId ?? undefined;
48
61
  const cwd = spawnCwdForNewSession(folders, sessionId, folderId);
49
- if (cwd) triggerSessionPrewarm(cwd);
62
+ // The prewarm pool holds `omp --mode rpc-ui` children only. A card opened
63
+ // from an ACP chat now spawns that same agent, so warming omp would start a
64
+ // process the send never claims (then idle-reap it).
65
+ if (cwd && (!harness || harness === 'omp-rpc')) triggerSessionPrewarm(cwd);
50
66
  setContent(next);
51
67
  setAttachments(rows ?? []);
52
- }, [folders, sessionId, selectedFolderId]);
68
+ setOpenedHarness(harness);
69
+ }, [folders, sessionId, selectedFolderId, harness]);
53
70
 
54
71
  const close = useCallback(() => {
55
72
  setContent(null);
56
73
  setAttachments([]);
74
+ setOpenedHarness(undefined);
57
75
  }, []);
58
76
 
59
- return { content, attachments, open, close };
77
+ return { content, attachments, ...(openedHarness ? { harness: openedHarness } : {}), open, close };
60
78
  }
@@ -28,7 +28,7 @@ import type { Attachment, ChatMessageData, WorkspaceFolderData } from '@/shared/
28
28
 
29
29
  let container: HTMLElement | undefined;
30
30
  /** The hook result of the most recent render. */
31
- let submit: ((text: string, attachments: Attachment[]) => void) | null = null;
31
+ let submit: ((text: string, attachments: Attachment[], harness?: string) => void) | null = null;
32
32
 
33
33
  function Probe({ deps }: { deps: NewChatSubmitDeps }) {
34
34
  submit = useNewChatSubmit(deps);
@@ -38,7 +38,7 @@ function Probe({ deps }: { deps: NewChatSubmitDeps }) {
38
38
  interface Recorded {
39
39
  /** Each send with the SCOPE the deps record carried when the callback was
40
40
  * built — the regression this hook exists for. */
41
- sends: Array<{ text: string; attachments: Attachment[]; scope: string | null }>;
41
+ sends: Array<{ text: string; attachments: Attachment[]; scope: string | null; harness?: string }>;
42
42
  messages: ChatMessageData[];
43
43
  /** The URL the hook's `setSearchParams` writes into. */
44
44
  searchParams: URLSearchParams;
@@ -64,8 +64,8 @@ function makeDeps(overrides: Partial<NewChatSubmitDeps> = {}): Recorded {
64
64
  setLocalMessages: (next) => {
65
65
  messages.splice(0, messages.length, ...(typeof next === 'function' ? next(messages) : next));
66
66
  },
67
- executeSend: async (text, attachments) => {
68
- sends.push({ text, attachments, scope });
67
+ executeSend: async (text, attachments, options) => {
68
+ sends.push({ text, attachments, scope, ...(options?.harness ? { harness: options.harness } : {}) });
69
69
  return { ok: true, busy: false };
70
70
  },
71
71
  ...overrides,
@@ -137,6 +137,34 @@ describe('useNewChatSubmit', () => {
137
137
  expect(adopted.sends).toEqual([{ text: 'halo', attachments: [], scope: pendingId }]);
138
138
  });
139
139
 
140
+ test('the parked harness rides the first send, so an ACP chat stays on its agent', async () => {
141
+ const opened = makeDeps({ sessionId: 'sess-aaa' });
142
+ const ui = await mount(opened.deps);
143
+
144
+ await act(async () => { submit?.('halo', [], 'opencode'); });
145
+ const pendingId = opened.searchParams.get('sessionId') ?? '';
146
+
147
+ const adopted = makeDeps({ sessionId: pendingId, folders: folderOwning(pendingId) });
148
+ await ui.rerender(adopted.deps);
149
+
150
+ // The dialog has no harness picker: without this the server defaulted the
151
+ // spawn to omp-rpc and the new chat lost the agent that wrote the answer.
152
+ expect(adopted.sends).toEqual([{ text: 'halo', attachments: [], scope: pendingId, harness: 'opencode' }]);
153
+ });
154
+
155
+ test('a send with no inherited harness leaves the spawn on the server default', async () => {
156
+ const opened = makeDeps({ sessionId: 'sess-aaa' });
157
+ const ui = await mount(opened.deps);
158
+
159
+ await act(async () => { submit?.('halo', []); });
160
+ const pendingId = opened.searchParams.get('sessionId') ?? '';
161
+
162
+ const adopted = makeDeps({ sessionId: pendingId, folders: folderOwning(pendingId) });
163
+ await ui.rerender(adopted.deps);
164
+
165
+ expect(adopted.sends).toEqual([{ text: 'halo', attachments: [], scope: pendingId }]);
166
+ });
167
+
140
168
  test('the pending session carries the workspace the chat was started from', async () => {
141
169
  // The first send SPAWNS an omp session in the folder's cwd. A dialog opened
142
170
  // from a session picked in the sidebar had no `folderId` in the URL, so the
@@ -37,12 +37,20 @@ export interface NewChatSubmitDeps {
37
37
  selectedFolderId: number | null;
38
38
  setSearchParams: SetSearchParams;
39
39
  setLocalMessages: Dispatch<SetStateAction<ChatMessageData[]>>;
40
- executeSend: (text: string, attachments: Attachment[]) => Promise<PromptDispatchResult>;
40
+ executeSend: (text: string, attachments: Attachment[], options?: { harness?: string | null }) => Promise<PromptDispatchResult>;
41
41
  }
42
42
 
43
- export function useNewChatSubmit(deps: NewChatSubmitDeps): (text: string, attachments: Attachment[]) => void {
43
+ /**
44
+ * The dialog's send handler. `harness` is the source chat's agent, captured by
45
+ * `useNewChatOpen` when the card opened: the dialog has no harness picker, and
46
+ * a spawn that omitted the field started the new chat on omp's RPC transport
47
+ * even when the answer came from another agent.
48
+ */
49
+ export function useNewChatSubmit(
50
+ deps: NewChatSubmitDeps,
51
+ ): (text: string, attachments: Attachment[], harness?: string) => void {
44
52
  const { sessionId, folders, selectedFolderId, setSearchParams, setLocalMessages, executeSend } = deps;
45
- const parkedRef = useRef<{ pendingId: string; text: string; attachments: Attachment[] } | null>(null);
53
+ const parkedRef = useRef<{ pendingId: string; text: string; attachments: Attachment[]; harness?: string } | null>(null);
46
54
 
47
55
  useEffect(() => {
48
56
  const parked = parkedRef.current;
@@ -51,15 +59,19 @@ export function useNewChatSubmit(deps: NewChatSubmitDeps): (text: string, attach
51
59
  // instead — it stays parked and is overwritten by the next New Chat.
52
60
  if (!parked || sessionId !== parked.pendingId) return;
53
61
  parkedRef.current = null;
54
- void executeSend(parked.text, parked.attachments);
62
+ void executeSend(
63
+ parked.text,
64
+ parked.attachments,
65
+ parked.harness ? { harness: parked.harness } : undefined,
66
+ );
55
67
  }, [sessionId, executeSend]);
56
68
 
57
- return useCallback((text, attachments) => {
69
+ return useCallback((text, attachments, harness) => {
58
70
  // The store mints the pending id and owns the row it stands for: the
59
71
  // sidebar/navbar show a default title immediately, and the row survives the
60
72
  // `new-…` → omp-UUID switch when the first send spawns.
61
73
  const pendingId = startPendingSession(activeProjectForSession(folders, sessionId).folder?.id ?? selectedFolderId);
62
- parkedRef.current = { pendingId, text, attachments };
74
+ parkedRef.current = { pendingId, text, attachments, ...(harness ? { harness } : {}) };
63
75
  setSearchParams((prev) => {
64
76
  const next = new URLSearchParams(prev);
65
77
  next.set('sessionId', pendingId);
@@ -174,11 +174,23 @@ describe('handleRetry', () => {
174
174
  expect(h.sent[0]?.attachments).toEqual([{ name: 'shot.png', preview: 'data:image/png;base64,QUJD', type: 'image/png', id: 'attachment-1' }]);
175
175
  });
176
176
 
177
- test('an ACP chat refuses Retry instead of rewinding an omp file', async () => {
177
+ test('an omp-acp chat rewinds the shared JSONL, then re-sends the turn', async () => {
178
+ // `omp-acp` writes the SAME session file as `omp-rpc`; the endpoint tears the
179
+ // ACP child down first, so the retry is a real rewind rather than a refusal.
178
180
  const h = makeHarness([user('u1'), ai('a1')], { harness: 'omp-acp' });
179
181
  h.actions.handleRetry('u1');
180
182
  await h.settled;
181
183
 
184
+ expect(h.rewinds.map((r) => r.entryId)).toEqual(['u1']);
185
+ expect(h.sent.map((s) => s.text)).toEqual(['do the thing']);
186
+ expect(h.errors).toEqual([]);
187
+ });
188
+
189
+ test('another ACP agent refuses Retry instead of truncating a file it does not read', async () => {
190
+ const h = makeHarness([user('u1'), ai('a1')], { harness: 'claude' });
191
+ h.actions.handleRetry('u1');
192
+ await h.settled;
193
+
182
194
  expect(h.rewinds).toEqual([]);
183
195
  expect(h.sent).toEqual([]);
184
196
  expect(h.errors[0]).toContain('not available on this harness');
@@ -248,6 +260,17 @@ describe('handleUndo', () => {
248
260
  expect(h.messages.map((m) => m.id)).toEqual(['u1', 'a1']);
249
261
  });
250
262
 
263
+ test('an omp-acp chat rewinds the shared JSONL and applies the truncated transcript', async () => {
264
+ const h = makeHarness([user('u1'), ai('a1'), user('u2'), ai('a2')], { harness: 'omp-acp' });
265
+ const ok = await h.actions.handleUndo('u2', 'second ask');
266
+
267
+ expect(ok).toBe(true);
268
+ expect(h.rewinds.map((r) => r.entryId)).toEqual(['u2']);
269
+ expect(h.drafts).toEqual(['second ask']);
270
+ expect(h.messages).toEqual([]);
271
+ expect(h.errors).toEqual([]);
272
+ });
273
+
251
274
  test('an ACP chat refuses Undo rather than truncating a file its agent does not read', async () => {
252
275
  const h = makeHarness([user('u1'), ai('a1')], { harness: 'claude' });
253
276
  const ok = await h.actions.handleUndo('u1', 'first ask');
@@ -13,7 +13,9 @@
13
13
  *
14
14
  * - a real omp session rewinds its JSONL first — dropping only the client's
15
15
  * rows left the abandoned turn on disk, so a reload resurrected the answer
16
- * that was supposed to be replaced;
16
+ * that was supposed to be replaced. Both omp transports share that file:
17
+ * the endpoint tears the live child down first, so an `omp-acp` chat is
18
+ * rewound exactly like an `omp-rpc` one;
17
19
  * - the id Retry receives is the run's OPENING USER row, not the AI row the
18
20
  * footer describes (a run spans thinking / tool / answer rows, so requiring
19
21
  * the owner's immediate predecessor to be a user turn made the button a
@@ -27,13 +29,15 @@
27
29
  import type { Dispatch, SetStateAction } from 'preact/compat';
28
30
  import type { Attachment, ChatMessageData, OmpAgentHandle, PromptDispatchResult } from '@/shared/types';
29
31
  import { toAttachmentList } from '@/shared/lib/chat/attachments';
32
+ import { harnessSupportsRewind } from '@/shared/lib/harness/rewind';
30
33
  import { requestRewind } from '@/client/hooks/chat/timeline/rewind';
31
34
 
32
35
  export interface RewindActionsDeps {
33
36
  isGenerating: boolean;
34
37
  isOmpSession: boolean;
35
- /** The harness behind the chat. The rewind endpoint edits an omp JSONL; an
36
- * ACP chat has none, and `omp-acp`'s file is not what its live child reads. */
38
+ /** The harness behind the chat. Only the harnesses that write omp's JSONL
39
+ * (`omp-rpc`, `omp-acp`) can be rewound; every other ACP agent keeps its own
40
+ * transcript. See `harnessSupportsRewind`. */
37
41
  harness?: string | null;
38
42
  /** Active session id; the omp paths post the rewind against it. */
39
43
  sessionId: string | null;
@@ -88,12 +92,12 @@ export function createRewindActions(deps: RewindActionsDeps): RewindActions {
88
92
  const handleUndo = async (msgId: string, content?: string): Promise<boolean> => {
89
93
  stopActiveRun();
90
94
 
91
- // ACP has no rewind of its own. The endpoint below edits an omp JSONL: a
92
- // non-omp agent has none, and `omp-acp`'s file is not what its live ACP
93
- // child reads — truncating it would leave the process running on the old
94
- // context. Refuse in words instead of a 404 or a silent divergence.
95
- if (isOmpSession && harness && harness !== 'omp-rpc') {
96
- reportActionError('Undo is not available on this harness: it has no omp transcript to rewind.');
95
+ // Both omp transports share the JSONL and can be rewound; every other ACP
96
+ // agent keeps its own transcript and has no truncation, so truncating
97
+ // Kabmo's copy would leave the child answering from turns the timeline no
98
+ // longer shows. Refuse in words instead of a 404 or a silent divergence.
99
+ if (isOmpSession && !harnessSupportsRewind(harness)) {
100
+ reportActionError('Undo is not available on this harness: its agent keeps its own transcript and Kabmo cannot truncate it.');
97
101
  return false;
98
102
  }
99
103
 
@@ -145,8 +149,8 @@ export function createRewindActions(deps: RewindActionsDeps): RewindActions {
145
149
  const handleRetry = (msgId: string) => {
146
150
  stopActiveRun();
147
151
 
148
- if (isOmpSession && harness && harness !== 'omp-rpc') {
149
- reportActionError('Retry is not available on this harness: it has no omp transcript to rewind.');
152
+ if (isOmpSession && !harnessSupportsRewind(harness)) {
153
+ reportActionError('Retry is not available on this harness: its agent keeps its own transcript and Kabmo cannot truncate it.');
150
154
  return;
151
155
  }
152
156
 
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Which model the transcript's footer names.
8
+ *
9
+ * The sidebar's `runModel` belongs to the RUN row beside it: correct while a run
10
+ * is live (it is renamed from the agent's own `get_state`), stale the moment a
11
+ * chat switches model while idle. The session's own metadata is the answer
12
+ * there, and it is what `/api/chat/:id` re-reads from the agent.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+ import { runIdentityFor } from '@/client/hooks/chat/timeline/run-identity';
17
+ import type { WorkspaceFolderData } from '@/shared/types';
18
+
19
+ const folder = (session: Record<string, unknown>): WorkspaceFolderData =>
20
+ ({ sessions: [session] }) as unknown as WorkspaceFolderData;
21
+
22
+ describe('runIdentityFor', () => {
23
+ test('an idle chat prefers the session metadata over the last run row', () => {
24
+ const identity = runIdentityFor({
25
+ folders: [folder({ id: 's1', streamStatus: 'finish', runModel: { provider: 'p', modelId: 'first' } })],
26
+ sessionId: 's1',
27
+ sessionData: { model: { provider: 'p', modelId: 'second' } },
28
+ modelNames: { second: 'Second' },
29
+ });
30
+ expect(identity).toEqual({ sessionProvider: 'p', sessionModelName: 'Second' });
31
+ });
32
+
33
+ test('a live run keeps the sidebar identity the agent is actually serving', () => {
34
+ const identity = runIdentityFor({
35
+ folders: [folder({ id: 's1', streamStatus: 'stream', runModel: { provider: 'p', modelId: 'served' } })],
36
+ sessionId: 's1',
37
+ sessionData: { model: { provider: 'p', modelId: 'stale' } },
38
+ modelNames: {},
39
+ });
40
+ expect(identity).toEqual({ sessionProvider: 'p', sessionModelName: 'served' });
41
+ });
42
+
43
+ test('falls back to the run row when the session metadata has no model', () => {
44
+ const identity = runIdentityFor({
45
+ folders: [folder({ id: 's1', streamStatus: 'finish', runModel: { provider: 'p', modelId: 'last' } })],
46
+ sessionId: 's1',
47
+ sessionData: null,
48
+ modelNames: {},
49
+ });
50
+ expect(identity).toEqual({ sessionProvider: 'p', sessionModelName: 'last' });
51
+ });
52
+ });