@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,128 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * A provider write republishes the `models` topic, and the harness catalog is
8
+ * stale in exactly the same way: the server re-probed the ACP harnesses on that
9
+ * write. The hook therefore re-reads `GET /api/harness` when the topic fires —
10
+ * without this, the composer picker kept the pre-write probe until a reload.
11
+ *
12
+ * A real listener on a real socket, because the bug is frame delivery, not the
13
+ * fetch: a stubbed socket would only prove the fake's timing.
14
+ */
15
+
16
+ import { afterEach, beforeEach, 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
+
21
+ import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
22
+ import { useHarnesses } from '@/client/hooks/models/use-harnesses';
23
+ import type { HarnessesController } from '@/client/hooks/models/use-harnesses-controller';
24
+ import { TOPIC_MODELS } from '@/shared/lib/realtime/protocol';
25
+ import { resetRealtimeClient } from '@/shared/lib/realtime/client';
26
+ import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
27
+ import { startRealtimeTestServer, type RealtimeTestServer } from '@/test-support/realtime-server';
28
+
29
+ const UNPROBED = { id: 'omp-acp', label: 'omp ACP', transport: 'acp', canLaunch: true, probe: null };
30
+ const PROBED = {
31
+ id: 'omp-acp',
32
+ label: 'omp ACP',
33
+ transport: 'acp',
34
+ canLaunch: true,
35
+ probe: {
36
+ harness: 'omp-acp',
37
+ capabilities: {
38
+ configModel: 2, configThinking: 0, configMode: 0, modeValues: [],
39
+ loadSession: true, listSessions: true, forkSession: true, deleteSession: true,
40
+ resumeSession: true, closeSession: true, hasUsage: false, hasPlan: false, steerMode: null,
41
+ },
42
+ models: [
43
+ { value: 'minimax/MiniMax-M2', name: 'MiniMax M2' },
44
+ { value: 'kimi/kimi-k2', name: 'Kimi K2' },
45
+ ],
46
+ thinking: [],
47
+ modes: [],
48
+ probedAt: Date.now(),
49
+ },
50
+ };
51
+
52
+ const realFetch = Bun.fetch;
53
+ let server: RealtimeTestServer;
54
+ let container: HTMLElement;
55
+ let catalogReads = 0;
56
+ /** The server's answer changed only when the write lands. */
57
+ let written = false;
58
+
59
+ beforeEach(async () => {
60
+ server = await startRealtimeTestServer(new Map([[TOPIC_MODELS, async () => ({ modelList: [] })]]));
61
+ installDomGlobals(new Window({ url: `http://127.0.0.1:${server.port}` }));
62
+ resetHarnessesStore();
63
+ catalogReads = 0;
64
+ written = false;
65
+ (globalThis as unknown as Record<string, unknown>).fetch = async (input: unknown) => {
66
+ const url = String(input);
67
+ if (!url.includes('/api/harness')) return new Response('{}', { status: 200 });
68
+ catalogReads += 1;
69
+ const body = { harnesses: [written ? PROBED : UNPROBED], configs: {}, providerSupport: {} };
70
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
71
+ };
72
+ container = document.createElement('div');
73
+ document.body.append(container);
74
+ });
75
+
76
+ afterEach(() => {
77
+ render(null, container);
78
+ container.remove();
79
+ resetRealtimeClient();
80
+ server.stop();
81
+ restoreDomGlobals();
82
+ (globalThis as unknown as Record<string, unknown>).fetch = realFetch;
83
+ });
84
+
85
+ function mount(): { read: () => HarnessesController } {
86
+ const box = { latest: null as HarnessesController | null };
87
+ function Consumer() {
88
+ box.latest = useHarnesses();
89
+ return null;
90
+ }
91
+ const host = document.createElement('div');
92
+ container.appendChild(host);
93
+ act(() => render(h(Consumer, {}), host));
94
+ return {
95
+ read: () => {
96
+ if (!box.latest) throw new Error('consumer did not render');
97
+ return box.latest;
98
+ },
99
+ };
100
+ }
101
+
102
+ describe('the harness catalog follows the models topic', () => {
103
+ test('a models-changed frame re-reads the catalog and shows the new probe', async () => {
104
+ const consumer = mount();
105
+ await act(async () => {});
106
+ await server.waitForTopic(TOPIC_MODELS, (value) => value !== null);
107
+ expect(consumer.read().harnesses[0]?.probe).toBeNull();
108
+ // Mounting costs one read; the subscription's opening snapshot costs the
109
+ // second. That snapshot is the same catalog, so the probe is still absent.
110
+ expect(catalogReads).toBe(2);
111
+
112
+ written = true;
113
+ server.publish(TOPIC_MODELS, { modelList: [{ value: 'minimax/MiniMax-M2' }] });
114
+ // Wait on the client's own notification: the delta is a socket task, so a
115
+ // microtask drain alone could assert before the frame is even decoded.
116
+ await server.waitForTopic<{ modelList: { value: string }[] }>(
117
+ TOPIC_MODELS,
118
+ (value) => value?.modelList.length === 1,
119
+ );
120
+ // The subscriber's fetch starts from that notification; drain until the
121
+ // store's render reflects the post-write answer.
122
+ for (let i = 0; i < 20 && !consumer.read().harnesses[0]?.probe; i += 1) await act(async () => {});
123
+ await act(async () => {});
124
+
125
+ expect(catalogReads).toBeGreaterThan(2);
126
+ expect(consumer.read().harnesses[0]?.probe?.models).toHaveLength(2);
127
+ });
128
+ });
@@ -27,7 +27,8 @@ import { Window } from 'happy-dom';
27
27
  import { h, render } from 'preact';
28
28
  import { act } from 'preact/test-utils';
29
29
 
30
- import { resetHarnessesStore, useHarnesses } from '@/client/hooks/models/use-harnesses';
30
+ import { resetHarnessesStore } from '@/client/hooks/models/harness-catalog';
31
+ import { useHarnesses } from '@/client/hooks/models/use-harnesses';
31
32
  import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
32
33
 
33
34
  const OPENCODE_UNPROBED = {
@@ -22,114 +22,57 @@
22
22
  */
23
23
 
24
24
  import { useEffect, useState } from 'preact/hooks';
25
- import type {
26
- HarnessConfig, HarnessImportOutcome, HarnessProviderSupport, HarnessesPayload, HarnessSummary,
27
- } from '@/shared/types/harness';
28
- import type { AddProviderInput } from '@/client/components/settings/categories/harness-settings/AddProviderForm';
25
+ import type { HarnessConfig, HarnessSummary, LiveHarnessModels } from '@/shared/types/harness';
26
+ import type { HarnessesController } from '@/client/hooks/models/use-harnesses-controller';
27
+ import {
28
+ emit, invalidateCatalog, listeners, loadCatalog, store,
29
+ } from '@/client/hooks/models/harness-catalog';
29
30
  import { addProvider, importProvider } from '@/client/hooks/models/provider-writes';
31
+ import { subscribeModelsUpdated } from '@/shared/lib/models/client';
30
32
 
31
- export interface HarnessesController {
32
- harnesses: HarnessSummary[];
33
- /** Per-harness config, keyed by id. Empty until the catalog is read. */
34
- configs: Record<string, HarnessConfig>;
35
- /** Persist one harness's config; resolves to the server's refusal, or null. */
36
- saveConfig: (id: string, config: HarnessConfig) => Promise<string | null>;
37
- /** What each harness can do about other providers, keyed by id. */
38
- providerSupport: Record<string, HarnessProviderSupport>;
39
- /** Copy one provider from a source registry into a harness.
40
- *
41
- * The ROW travels with the id: the writer needs the endpoint, dialect and
42
- * model list, and the server would otherwise have to look them up again. The
43
- * credential is not in the row — the server reads that from the source file. */
44
- importProvider: (
45
- id: string,
46
- sourceId: string,
47
- entry: HarnessProviderSupport['importable'][number],
48
- ) => Promise<HarnessImportOutcome>;
49
- /** Add a provider by typing its endpoint and key. */
50
- addProvider: (id: string, input: AddProviderInput) => Promise<HarnessImportOutcome>;
51
- isLoading: boolean;
52
- error: string | null;
53
- /** Re-read the catalog. */
54
- reload: () => void;
55
- /** Probe one harness (spawns that agent once) and merge the answer in. */
56
- probe: (id: string, cwd?: string) => Promise<string | null>;
57
- /** Switch one harness on or off. Switching ON also probes it once, server-side,
58
- * so its models are ready for the composer. Resolves to the refusal, or null. */
59
- setEnabled: (id: string, enabled: boolean) => Promise<string | null>;
33
+ /**
34
+ * Record the selectors a LIVE chat published for its harness.
35
+ *
36
+ * Called by the session loader on every session read, so the guard matters: an
37
+ * unchanged list must not notify every picker subscriber (the metadata refresh
38
+ * runs a few times per chat).
39
+ */
40
+ export function publishLiveModels(id: string, live: LiveHarnessModels): void {
41
+ if (!id || live.models.length === 0) return;
42
+ const current = store.liveModels[id];
43
+ if (current && sameSelectors(current, live)) return;
44
+ emit({ liveModels: { ...store.liveModels, [id]: live } });
60
45
  }
61
46
 
62
- interface HarnessStore {
63
- harnesses: HarnessSummary[];
64
- configs: Record<string, HarnessConfig>;
65
- providerSupport: Record<string, HarnessProviderSupport>;
66
- isLoading: boolean;
67
- error: string | null;
68
- /** Bumped on every change, so `useSyncExternalStore`-style subscribers can
69
- * detect it without holding the arrays themselves. */
70
- version: number;
71
- }
72
-
73
- const store: HarnessStore = {
74
- harnesses: [], configs: {}, providerSupport: {}, isLoading: true, error: null, version: 0,
75
- };
76
- /** Has the catalog been read at least once? A later mount must NOT re-fetch: the
77
- * answer is a property of the installed agents, and `reload()` is the explicit
78
- * way to re-read it. */
79
- let loaded = false;
80
- const listeners = new Set<() => void>();
81
- /** One in-flight catalog read shared by every mount; a second mount joins it
82
- * rather than firing its own `GET /api/harness`. */
83
- let inflight: Promise<void> | null = null;
84
-
85
- function emit(patch: Partial<HarnessStore>): void {
86
- Object.assign(store, patch);
87
- store.version += 1;
88
- for (const listener of listeners) listener();
47
+ function sameSelectors(a: LiveHarnessModels, b: LiveHarnessModels): boolean {
48
+ const keys = (list?: readonly { value: string; name: string }[]) =>
49
+ (list ?? []).map((entry) => `${entry.value}\u0000${entry.name}`).join('\u0001');
50
+ return a.models.length === b.models.length
51
+ && keys(a.models) === keys(b.models)
52
+ && keys(a.thinking) === keys(b.thinking);
89
53
  }
90
54
 
91
55
  /** Fold a landed provider write back into the store and re-read the catalog. */
92
- function announceProviderWrite(id: string, config?: HarnessConfig): void {
56
+ function announceProviderWrite(
57
+ id: string,
58
+ config?: HarnessConfig,
59
+ probeInvalidated?: readonly string[],
60
+ ): void {
93
61
  if (config) emit({ configs: { ...store.configs, [id]: config } });
94
62
  // The write landed in a FILE, which is the only thing that proves it, so the
95
63
  // list is re-read rather than patched: a card that kept the previous list would
96
64
  // show "nothing added" after a successful add. The store caches its first
97
65
  // answer on purpose, so the re-read has to clear it.
98
- loaded = false;
99
- void loadCatalog();
100
- }
101
-
102
- async function loadCatalog(): Promise<void> {
103
- if (inflight) return inflight;
104
- if (loaded) return;
105
- emit({ isLoading: true });
106
- inflight = fetch('/api/harness')
107
- .then(async (response) => {
108
- if (!response.ok) throw new Error(`GET /api/harness answered ${response.status}`);
109
- return (await response.json()) as HarnessesPayload;
110
- })
111
- .then((payload) => {
112
- loaded = true;
113
- emit({
114
- harnesses: Array.isArray(payload.harnesses) ? payload.harnesses : [],
115
- // Absent from an answer written before per-harness config existed: an
116
- // empty map is the honest reading, and every card then shows "not set".
117
- configs: payload.configs ?? {},
118
- providerSupport: payload.providerSupport ?? {},
119
- error: null,
120
- isLoading: false,
121
- });
122
- })
123
- .catch((cause: unknown) => {
124
- emit({
125
- error: cause instanceof Error ? cause.message : 'Could not read the harness list',
126
- isLoading: false,
127
- });
128
- })
129
- .finally(() => {
130
- inflight = null;
131
- });
132
- return inflight;
66
+ void invalidateCatalog().then(() => {
67
+ // The server names every tab whose probe measured the OLD file. Ask each
68
+ // launchable one to answer now, so the picker offers the new models without
69
+ // a manual "Check status". The built-in transport has no agent to probe.
70
+ for (const target of probeInvalidated ?? []) {
71
+ const entry = store.harnesses.find((harness) => harness.id === target);
72
+ if (!entry || entry.builtIn || entry.unavailable) continue;
73
+ void probeHarness(target);
74
+ }
75
+ });
133
76
  }
134
77
 
135
78
  /** One probe, shared: the settings page's "check status" and the tab strip's
@@ -241,8 +184,15 @@ export function useHarnesses(): HarnessesController {
241
184
  // first one already loaded, or the second surface renders empty forever.
242
185
  sync();
243
186
  void loadCatalog();
187
+ // A provider/model write republishes the `models` topic. The ACP pickers read
188
+ // PROBES, which the server refreshed on the same write, so the cached
189
+ // catalog is stale in exactly the same way the model list is.
190
+ const offModels = subscribeModelsUpdated(() => {
191
+ void invalidateCatalog();
192
+ });
244
193
  return () => {
245
194
  listeners.delete(sync);
195
+ offModels();
246
196
  };
247
197
  }, []);
248
198
 
@@ -251,31 +201,15 @@ export function useHarnesses(): HarnessesController {
251
201
  configs: snapshot.configs,
252
202
  saveConfig: saveHarnessConfig,
253
203
  providerSupport: snapshot.providerSupport,
204
+ liveModels: snapshot.liveModels,
254
205
  importProvider: (id, sourceId, entry) => importProvider(id, sourceId, entry, announceProviderWrite),
255
206
  addProvider: (id, input) => addProvider(id, input, announceProviderWrite),
256
207
  isLoading: snapshot.isLoading,
257
208
  error: snapshot.error,
258
209
  reload: () => {
259
- loaded = false;
260
- void loadCatalog();
210
+ void invalidateCatalog();
261
211
  },
262
212
  probe: probeHarness,
263
213
  setEnabled: setHarnessEnabled,
264
214
  };
265
215
  }
266
-
267
- /**
268
- * Forget everything this process learned about the harnesses.
269
- *
270
- * Two callers, one meaning: a test file starts from a cold store, and
271
- * `bun --hot` re-evaluates this module while the old store may still describe
272
- * agents that have since been installed or removed.
273
- */
274
- export function resetHarnessesStore(): void {
275
- inflight = null;
276
- loaded = false;
277
- Object.assign(store, {
278
- harnesses: [], configs: {}, providerSupport: {}, isLoading: true, error: null, version: 0,
279
- });
280
- for (const listener of listeners) listener();
281
- }
@@ -809,10 +809,18 @@
809
809
  .prose-content td, .prose-content th { line-height: inherit; overflow-wrap: break-word; }
810
810
  .prose-content th { background: color-mix(in srgb, var(--theme-ink) 5%, transparent); border-bottom: 1px solid color-mix(in srgb, var(--theme-ink) 15%, transparent); padding: 0.375rem 0.75rem; font-weight: 600; }
811
811
  .prose-content td { border-bottom: 1px solid color-mix(in srgb, var(--theme-ink) 10%, transparent); padding: 0.375rem 0.75rem; }
812
+ /* The chip's fill is its OWN, opaque colour (`--theme-code-fill`, ink at 8% over
813
+ * the palette's paper). It used to be `color-mix(… 8%, transparent)`, an ALPHA:
814
+ * whatever was painted behind the chip showed through, so a hovered block's tint
815
+ * changed the code's colour mid-hover and with it the code/chip contrast —
816
+ * measured on a real session in the browser: `#e4e9ed` at rest against
817
+ * `#dce2e5` with the hover tint behind it. One solved colour per palette also
818
+ * removes lightningcss's `color-mix` fallback, which was
819
+ * `background: var(--theme-ink)` — a solid ink slab with ink text on it. */
812
820
  .prose-content code.inline-code {
813
821
  font-family: 'Fira Code', monospace; font-size: 0.75rem;
814
822
  padding: 0.0125rem 0.275rem; border-radius: 0.375rem;
815
- background: color-mix(in srgb, var(--theme-ink) 8%, transparent);
823
+ background: var(--theme-code-fill);
816
824
  color: var(--theme-ink);
817
825
  overflow-wrap: break-word;
818
826
  }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The wait that turns opencode's five-second plugin-activation refusal into a
8
+ * session, without turning a real refusal into a two-minute hang.
9
+ *
10
+ * Measured on 2.2.5: `session/new` answered `ServiceUnavailableError` at +6 s
11
+ * while the Claude-bridge plugin list was still activating, and the same
12
+ * process answered a real session at +80 s.
13
+ */
14
+
15
+ import { describe, expect, test } from 'bun:test';
16
+ import {
17
+ newSessionAfterActivation,
18
+ pluginActivationPending,
19
+ } from '@/server/lib/harness/acp/activation';
20
+
21
+ const pending = () => new Error(
22
+ 'Internal error: Internal service failure: {"errorName":"ServiceUnavailableError"}',
23
+ );
24
+
25
+ describe('pluginActivationPending', () => {
26
+ test('names the wire error the transport folds into the message', () => {
27
+ expect(pluginActivationPending(pending())).toBe(true);
28
+ expect(pluginActivationPending(new Error('Authentication required'))).toBe(false);
29
+ expect(pluginActivationPending('ServiceUnavailableError')).toBe(true);
30
+ });
31
+ });
32
+
33
+ describe('newSessionAfterActivation', () => {
34
+ test('retries the same process while opencode activates its plugins', async () => {
35
+ let calls = 0;
36
+ const result = await newSessionAfterActivation(
37
+ 'opencode',
38
+ '/tmp/work',
39
+ async (cwd, timeoutMs) => {
40
+ calls += 1;
41
+ expect(cwd).toBe('/tmp/work');
42
+ expect(timeoutMs).toBe(120_000);
43
+ if (calls < 3) throw pending();
44
+ return { sessionId: 'ses_1' };
45
+ },
46
+ { retryMs: 1 },
47
+ );
48
+ expect(result.sessionId).toBe('ses_1');
49
+ expect(calls).toBe(3);
50
+ });
51
+
52
+ test('a non-activation refusal is final', async () => {
53
+ let calls = 0;
54
+ const failure = newSessionAfterActivation('opencode', '/tmp/work', async () => {
55
+ calls += 1;
56
+ throw new Error('Authentication required');
57
+ });
58
+ await expect(failure).rejects.toThrow('Authentication required');
59
+ expect(calls).toBe(1);
60
+ });
61
+
62
+ test('other harnesses are never retried', async () => {
63
+ let calls = 0;
64
+ const failure = newSessionAfterActivation('omp-acp', '/tmp/work', async () => {
65
+ calls += 1;
66
+ throw pending();
67
+ }, { retryMs: 1 });
68
+ await expect(failure).rejects.toThrow('ServiceUnavailableError');
69
+ expect(calls).toBe(1);
70
+ });
71
+
72
+ test('a plugin that never activates still ends in a stated refusal', async () => {
73
+ let calls = 0;
74
+ const failure = newSessionAfterActivation('opencode', '/tmp/work', async () => {
75
+ calls += 1;
76
+ throw pending();
77
+ }, { retryMs: 1, totalMs: 0 });
78
+ await expect(failure).rejects.toThrow('plugin activation did not finish within 0s');
79
+ expect(calls).toBe(1);
80
+ });
81
+ });
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * Wait out opencode's plugin activation before asking it for a session.
8
+ *
9
+ * opencode 2.x boots "Location plugins" per directory asynchronously and guards
10
+ * every request that needs them with a HARD five-second wait
11
+ * (`Location plugins did not finish activating` -> `ServiceUnavailableError`).
12
+ * The activation itself is unbounded: measured 2.2.5 on a real config, one
13
+ * Claude-bridge plugin finished at ~30 s and the full plugin list at ~80 s, so a
14
+ * single `session/new` answered at +6 s with `ServiceUnavailableError` and the
15
+ * probe card read as blocked while the agent was still booting.
16
+ *
17
+ * Retrying the SAME process is the fix, not respawning: the activation is
18
+ * per-process state, and a fresh agent restarts the clock. The wait is bounded
19
+ * because a plugin that never settles must still end in a refusal, with a
20
+ * reason the settings card can show.
21
+ */
22
+
23
+ import type { AcpSessionNewResult } from '@/server/lib/harness/acp/protocol';
24
+ import type { HarnessId } from '@/shared/lib/harness/catalog';
25
+
26
+ /** Enough headroom over the measured 80 s, not an open-ended probe. */
27
+ export const ACTIVATION_TIMEOUT_MS = 150_000;
28
+ /** Each retry only needs to let the five-second gate expire. */
29
+ const ACTIVATION_RETRY_MS = 3_000;
30
+
31
+ /** Is this the agent's "plugins are still activating" refusal? The ACP error
32
+ * carries the name in `data`, which the transport folds into the message. */
33
+ export function pluginActivationPending(error: unknown): boolean {
34
+ const message = error instanceof Error ? error.message : String(error);
35
+ return message.includes('ServiceUnavailableError');
36
+ }
37
+
38
+ export interface ActivationWait {
39
+ totalMs?: number;
40
+ retryMs?: number;
41
+ perAttemptMs?: number;
42
+ }
43
+
44
+ /**
45
+ * `session/new`, retried while opencode reports pending plugin activation.
46
+ *
47
+ * Only opencode has this gate. Every other harness's first refusal is final —
48
+ * retrying an `Authentication required` would hide it behind a two-minute wait.
49
+ */
50
+ export async function newSessionAfterActivation(
51
+ harness: HarnessId,
52
+ cwd: string,
53
+ newSession: (cwd: string, timeoutMs?: number) => Promise<AcpSessionNewResult>,
54
+ wait: ActivationWait = {},
55
+ ): Promise<AcpSessionNewResult> {
56
+ const { totalMs = ACTIVATION_TIMEOUT_MS, retryMs = ACTIVATION_RETRY_MS, perAttemptMs = 120_000 } = wait;
57
+ if (harness !== 'opencode') return newSession(cwd, perAttemptMs);
58
+
59
+ const giveUpAt = Date.now() + totalMs;
60
+ for (;;) {
61
+ try {
62
+ return await newSession(cwd, perAttemptMs);
63
+ } catch (error) {
64
+ if (!pluginActivationPending(error)) throw error;
65
+ if (Date.now() >= giveUpAt) {
66
+ const reason = error instanceof Error ? error.message : String(error);
67
+ throw new Error(`${reason} (plugin activation did not finish within ${Math.round(totalMs / 1000)}s)`);
68
+ }
69
+ await Bun.sleep(retryMs);
70
+ }
71
+ }
72
+ }
@@ -11,7 +11,8 @@
11
11
  * - `tool_call_update` arrives as a PATCH, so a `completed` update carrying
12
12
  * only `status` must not blank the card it completes;
13
13
  * - `messageId` is the ONLY message delimiter (ACP has no `message_end`), so a
14
- * changed id must close the previous row instead of appending into it;
14
+ * changed id must close the previous row instead of appending into it; an
15
+ * ABSENT id (antigravity 1.5.3) must still yield one stable row per turn;
15
16
  * - `kind` must reach `ToolCallData.type`, because omp's `ToolType` is what the
16
17
  * renderers switch on;
17
18
  * - `usage_update` exists on some agents only, so its absence must emit
@@ -33,6 +34,19 @@ const textChunk = (text: string, messageId = 'm1') => ({
33
34
  messageId,
34
35
  });
35
36
 
37
+ /** ACP v1 allows `messageId` to be absent; antigravity 1.5.3 sends none. */
38
+ const anonymousChunk = (text: string) => ({
39
+ sessionUpdate: 'agent_message_chunk',
40
+ content: { type: 'text', text },
41
+ });
42
+
43
+ const messageIdOf = (frame: unknown): string | undefined => {
44
+ if (!frame || typeof frame !== 'object' || !('message' in frame)) return undefined;
45
+ const message = frame.message;
46
+ if (!message || typeof message !== 'object' || !('id' in message)) return undefined;
47
+ return typeof message.id === 'string' ? message.id : undefined;
48
+ };
49
+
36
50
  describe('acp frame mapper — assistant text', () => {
37
51
  test('accumulates chunks into ONE message rather than one row per delta', () => {
38
52
  const mapper = new AcpFrameMapper();
@@ -43,6 +57,41 @@ describe('acp frame mapper — assistant text', () => {
43
57
  expect(message.content[0]).toEqual({ type: 'text', text: 'hello world' });
44
58
  });
45
59
 
60
+ test('chunks without a messageId still update ONE row', () => {
61
+ const mapper = new AcpFrameMapper();
62
+ const first = mapper.mapUpdate(anonymousChunk('hello '));
63
+ const second = mapper.mapUpdate(anonymousChunk('world'));
64
+ const firstId = messageIdOf(first[0]);
65
+ expect(typeof firstId).toBe('string');
66
+ expect(messageIdOf(second[0])).toBe(firstId);
67
+ // The final frame must carry that SAME id, or the client appends the
68
+ // completed answer beside the streamed one.
69
+ const ended = mapper.closeMessage();
70
+ expect(messageIdOf(ended[0])).toBe(firstId);
71
+ });
72
+
73
+ test('a tool call before the first chunk keeps that identity too', () => {
74
+ const mapper = new AcpFrameMapper();
75
+ const opened = mapper.mapUpdate({
76
+ sessionUpdate: 'tool_call',
77
+ toolCallId: 't1',
78
+ title: 'Read',
79
+ status: 'in_progress',
80
+ });
81
+ const chunk = mapper.mapUpdate(anonymousChunk('done'));
82
+ const openedId = messageIdOf(opened[0]);
83
+ expect(typeof openedId).toBe('string');
84
+ expect(messageIdOf(chunk[0])).toBe(openedId);
85
+ });
86
+
87
+ test('a new turn gets a fresh identity when the agent sends no id', () => {
88
+ const mapper = new AcpFrameMapper();
89
+ const first = mapper.mapUpdate(anonymousChunk('one'));
90
+ mapper.reset();
91
+ const second = mapper.mapUpdate(anonymousChunk('two'));
92
+ expect(messageIdOf(second[0])).not.toBe(messageIdOf(first[0]));
93
+ });
94
+
46
95
  test('a changed messageId closes the previous row first', () => {
47
96
  const mapper = new AcpFrameMapper();
48
97
  mapper.mapUpdate(textChunk('first', 'm1'));
@@ -16,9 +16,11 @@
16
16
  *
17
17
  * Three ACP facts drive the state kept here:
18
18
  *
19
- * - **`messageId` delimits messages.** There is no `message_end`: one answer is
20
- * many chunks sharing an id (measured 6 chunks for a five-word answer, 168
21
- * for a long one). A changed id closes the row and opens the next.
19
+ * - **`messageId` delimits messages, but is OPTIONAL.** One answer is many
20
+ * chunks sharing an id (measured 6 chunks for a five-word answer, 168 for a
21
+ * long one); a changed id closes the row and opens the next. An agent that
22
+ * sends no id at all (measured on antigravity 1.5.3) gets one synthesized
23
+ * identity per turn, so its chunks still update ONE row.
22
24
  * - **`tool_call_update` is a PATCH.** A `status:completed` update carries no
23
25
  * `content`, so the card's body lives in the accumulated block; replacing it
24
26
  * blanks the card at the exact moment it finishes.
@@ -144,11 +146,21 @@ export class AcpFrameMapper {
144
146
  return [{ type: 'message_end', message }];
145
147
  }
146
148
 
147
- /** The accumulated message in omp's wire shape. */
149
+ /**
150
+ * The accumulated message in omp's wire shape.
151
+ *
152
+ * `messageId` is OPTIONAL in ACP v1, and an agent that omits it (measured on
153
+ * antigravity 1.5.3: every chunk carried only `sessionUpdate` + `content`)
154
+ * still needs one identity for the whole turn. Without it, `toChatMessage`
155
+ * minted `msg-<Date.now()>-ai` per frame, so every chunk after the first
156
+ * APPENDED a new row instead of updating the streaming one — the turn showed
157
+ * as duplicate bubbles and the final answer again at `message_end`.
158
+ */
148
159
  private snapshot(): Record<string, unknown> {
160
+ const id = this.messageId ??= `acp-${crypto.randomUUID()}`;
149
161
  return {
150
162
  role: 'assistant',
151
- ...(this.messageId ? { id: this.messageId } : {}),
163
+ id,
152
164
  content: this.blocks.map((block) => ({ ...block })),
153
165
  };
154
166
  }
@@ -21,10 +21,12 @@
21
21
  * 2. **`tool_call_update` is a PATCH.** A `status:completed` update carries no
22
22
  * `content`, so replacing the card blanks it at the exact moment it
23
23
  * finishes. The mapper merges into the accumulated call.
24
- * 3. **`messageId` delimits messages.** ACP has no `message_end`: one answer is
25
- * many `agent_message_chunk` frames sharing an id (measured 6 chunks for a
26
- * five-word answer, 168 for a long one). Without the id, one answer becomes
27
- * 168 rows.
24
+ * 3. **`messageId` delimits messages, when present.** ACP has no
25
+ * `message_end`: one answer is many `agent_message_chunk` frames sharing an
26
+ * id (measured 6 chunks for a five-word answer, 168 for a long one). Without
27
+ * the id, one answer becomes 168 rows. The id is optional in ACP v1, so an
28
+ * agent that omits it (antigravity 1.5.3) gets one synthesized identity for
29
+ * the turn rather than a fresh one per frame.
28
30
  * 4. **`usage_update` is optional.** Only omp emits it; the mapper forwards it
29
31
  * when present and emits nothing when absent, so the panels can say
30
32
  * "not reported" instead of showing a fabricated number.