@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.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +679 -679
- package/dist/client/static/js/{index-ph0q59rs.js → index-jcr5twtp.js} +769 -767
- package/dist/client/static/js/index-z3w7n85q.css +1 -0
- package/package.json +1 -1
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +23 -7
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +27 -11
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/index.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- package/src/client/data/settings/omp-schema.json +4 -4
- package/src/client/hooks/chat/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +17 -0
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -3
- package/src/client/hooks/chat/timeline/send.test-util.ts +1 -1
- package/src/client/hooks/chat/timeline/send.test.ts +1 -3
- package/src/client/hooks/chat/timeline/send.ts +8 -3
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +10 -3
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/tailwind.css +9 -1
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- package/src/server/lib/harness/acp/mapper.ts +6 -4
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-handshake.ts +9 -2
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session.test-util.ts +31 -2
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +20 -20
- package/src/server/lib/harness/acp/turn.ts +31 -7
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +13 -115
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/session/delete-flow.server.ts +15 -8
- package/src/server/lib/omp/session/delete.server.ts +12 -0
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/import-action.ts +18 -4
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update.ts +49 -7
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/harness/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +32 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +9 -0
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-plan.test.ts +51 -1
- package/src/shared/lib/harness/update-plan.ts +47 -7
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +25 -9
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +6 -3
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
|
@@ -27,7 +27,7 @@ import { AcpTurns } from '@/server/lib/harness/acp/turn';
|
|
|
27
27
|
import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
|
|
28
28
|
import type { AcpConfigOption, AcpId } from '@/server/lib/harness/acp/protocol';
|
|
29
29
|
import { promptBlocks } from '@/server/lib/harness/acp/prompt';
|
|
30
|
-
import {
|
|
30
|
+
import { adoptConfigAnswer, publishConfigChange, settlePermissionDialog, stampMessageModel } from '@/server/lib/harness/acp/session-config';
|
|
31
31
|
import { beginAcpTurn, settleAcpTurn } from '@/server/lib/harness/acp/session-turns';
|
|
32
32
|
import { driveAcpGoalAfterTurn } from '@/server/lib/harness/acp/acp-goal-driver.server';
|
|
33
33
|
import { handshakeAcpSession } from '@/server/lib/harness/acp/session-handshake';
|
|
@@ -37,27 +37,16 @@ import { handleSessionNotification } from '@/server/lib/harness/acp/session-noti
|
|
|
37
37
|
import { AcpUsageMeter, type AcpContextUsage } from '@/server/lib/harness/acp/session-usage';
|
|
38
38
|
import { answerPermissionRequest } from '@/server/lib/harness/acp/session-permissions';
|
|
39
39
|
import { acpWebState } from '@/server/lib/harness/acp/session-web-state';
|
|
40
|
+
import { acpIdleReaper } from '@/server/lib/harness/acp/session-idle';
|
|
40
41
|
import { DEFAULT_APPROVAL_MODE, isApprovalMode, type ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
41
42
|
import { dispatchCommand, type AcpCommandHost } from '@/server/lib/harness/acp/commands';
|
|
42
43
|
import { markStreamStatus } from '@/shared/lib/omp/session/stream-state.server';
|
|
44
|
+
import type { AcpSessionOptions } from '@/server/lib/harness/acp/session-options';
|
|
43
45
|
import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
|
|
44
46
|
import type { HarnessSession } from '@/server/lib/harness/session';
|
|
45
47
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
46
48
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
47
|
-
|
|
48
|
-
export interface AcpSessionOptions {
|
|
49
|
-
harness: HarnessId;
|
|
50
|
-
command: string[];
|
|
51
|
-
env?: Record<string, string>;
|
|
52
|
-
/** Provider/model this session starts on, applied with
|
|
53
|
-
* `session/set_config_option` right after `session/new`. */
|
|
54
|
-
model?: { provider: string; modelId: string } | null;
|
|
55
|
-
thinkingLevel?: string | null;
|
|
56
|
-
mode?: string | null;
|
|
57
|
-
/** The composer's access pick. ACP has no spawn flag for it, so the session
|
|
58
|
-
* answers `session/request_permission` itself according to this tier. */
|
|
59
|
-
accessMode?: ApprovalMode | null;
|
|
60
|
-
}
|
|
49
|
+
import type { IdleReaper } from '@/server/lib/omp/rpc/idle-reaper';
|
|
61
50
|
|
|
62
51
|
export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
63
52
|
readonly harness: HarnessId;
|
|
@@ -100,8 +89,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
100
89
|
accessMode: ApprovalMode = DEFAULT_APPROVAL_MODE;
|
|
101
90
|
capabilities: HarnessCapabilities = capabilitiesFrom({ protocolVersion: 1 }, [], { usage: false, plan: false });
|
|
102
91
|
configOptions: AcpConfigOption[] = [];
|
|
103
|
-
|
|
104
92
|
private readonly proc: AcpProcess;
|
|
93
|
+
/** The quiet-window reclaim; the rules live in `session-idle.ts`. */
|
|
94
|
+
readonly idle: IdleReaper;
|
|
105
95
|
private readonly mapper = new AcpFrameMapper();
|
|
106
96
|
private readonly listeners = new Set<(event: AgentEvent) => void>();
|
|
107
97
|
private readonly permissions = new PendingPermissions();
|
|
@@ -123,6 +113,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
123
113
|
onClientRequest: (id, method, params) => this.onClientRequest(id, method, params),
|
|
124
114
|
onExit: (info) => this.onExit(info),
|
|
125
115
|
});
|
|
116
|
+
this.idle = acpIdleReaper(this, options.idleDestroyMs);
|
|
126
117
|
this.turns = new AcpTurns({
|
|
127
118
|
emit: (event) => this.emit(event),
|
|
128
119
|
prompt: (message, images) =>
|
|
@@ -130,7 +121,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
130
121
|
cancelAgent: () => this.proc.cancel(this.sessionId),
|
|
131
122
|
abandonPrompt: () => this.proc.abandonPrompt(this.sessionId),
|
|
132
123
|
resetMapper: () => this.mapper.reset(),
|
|
133
|
-
closeMessage: () => this.mapper.closeMessage(),
|
|
124
|
+
closeMessage: () => this.mapper.closeMessage().map((event) => stampMessageModel(event, this.runModel)),
|
|
134
125
|
openCalls: () => this.mapper.openCalls(),
|
|
135
126
|
// The follow-up queue is armed from the turn's END, exactly as the omp
|
|
136
127
|
// wrapper arms it from its own terminal settle. Without this an ACP chat's
|
|
@@ -157,6 +148,8 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
157
148
|
{ model: this.requestedModel, thinking: this.requestedThinking, mode: this.requestedMode },
|
|
158
149
|
sessionIdToLoad,
|
|
159
150
|
);
|
|
151
|
+
// A slow handshake is not idleness: the window starts once it is usable.
|
|
152
|
+
this.idle.reset(true);
|
|
160
153
|
return { sessionId: this.sessionId };
|
|
161
154
|
}
|
|
162
155
|
|
|
@@ -211,6 +204,8 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
211
204
|
}
|
|
212
205
|
|
|
213
206
|
async send(command: Record<string, unknown>): Promise<unknown> {
|
|
207
|
+
// A command is the clearest sign the session is still wanted.
|
|
208
|
+
this.idle.reset();
|
|
214
209
|
return dispatchCommand(this, command);
|
|
215
210
|
}
|
|
216
211
|
|
|
@@ -254,7 +249,8 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
254
249
|
* `session-config.ts` for why the AGENT's resolved value is what is kept. */
|
|
255
250
|
async setConfig(configId: string, value: string | boolean): Promise<unknown> {
|
|
256
251
|
const result = await this.proc.setConfigOption(this.sessionId, configId, value);
|
|
257
|
-
|
|
252
|
+
adoptConfigAnswer(this, result, { configId, value });
|
|
253
|
+
publishConfigChange(this, configId);
|
|
258
254
|
return result;
|
|
259
255
|
}
|
|
260
256
|
|
|
@@ -293,6 +289,8 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
293
289
|
}
|
|
294
290
|
|
|
295
291
|
private onNotification(method: string, params: Record<string, unknown>): void {
|
|
292
|
+
// A long turn emits no commands but plenty of `session/update` frames.
|
|
293
|
+
this.idle.reset();
|
|
296
294
|
handleSessionNotification(this, method, params);
|
|
297
295
|
}
|
|
298
296
|
|
|
@@ -302,13 +300,13 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
302
300
|
|
|
303
301
|
mapUpdate(update: Record<string, unknown>): AgentEvent[] { return this.mapper.mapUpdate(update); }
|
|
304
302
|
|
|
305
|
-
/** Agent→client requests
|
|
306
|
-
* parks the turn, which is the failure this method exists to prevent. */
|
|
303
|
+
/** Agent→client requests: every branch answers or refuses — an unanswered call parks the turn. */
|
|
307
304
|
private onClientRequest(
|
|
308
305
|
id: AcpId,
|
|
309
306
|
method: string,
|
|
310
307
|
params: Record<string, unknown>,
|
|
311
308
|
): Promise<{ answered: true; result: unknown } | { answered: false; message: string } | { answered: false; deferred: true }> {
|
|
309
|
+
this.idle.reset();
|
|
312
310
|
if (method === 'session/request_permission') {
|
|
313
311
|
return answerPermissionRequest({
|
|
314
312
|
sessionId: this.sessionId,
|
|
@@ -322,6 +320,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
322
320
|
|
|
323
321
|
private onExit(info: { code: number | null; stderrTail: string }): void {
|
|
324
322
|
this.destroyed = true;
|
|
323
|
+
this.idle.stop();
|
|
325
324
|
if (this.closing) {
|
|
326
325
|
this.destroyHook?.();
|
|
327
326
|
return;
|
|
@@ -343,6 +342,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
343
342
|
if (this.destroyed) return;
|
|
344
343
|
this.destroyed = true;
|
|
345
344
|
this.closing = true;
|
|
345
|
+
this.idle.stop();
|
|
346
346
|
this.permissions.clear();
|
|
347
347
|
await this.proc.dispose().catch(() => {});
|
|
348
348
|
this.destroyHook?.();
|
|
@@ -90,7 +90,10 @@ export class AcpTurns {
|
|
|
90
90
|
type: 'prompt_error',
|
|
91
91
|
errorMessage: error instanceof Error ? error.message : String(error),
|
|
92
92
|
});
|
|
93
|
-
|
|
93
|
+
// The agent's own error is the reason. `finish` must not append its
|
|
94
|
+
// generic "no answer" verdict on top of it — the second frame lands
|
|
95
|
+
// last on the client and replaced the useful message.
|
|
96
|
+
this.finish(undefined, true);
|
|
94
97
|
}),
|
|
95
98
|
)
|
|
96
99
|
.finally(() => {
|
|
@@ -139,8 +142,10 @@ export class AcpTurns {
|
|
|
139
142
|
|
|
140
143
|
/** Flush the open message, fail abandoned cards, emit the terminal frame. A
|
|
141
144
|
* call left open by a cancelled turn would spin forever — the agent is never
|
|
142
|
-
* going to report an end for work it abandoned.
|
|
143
|
-
|
|
145
|
+
* going to report an end for work it abandoned. `reported` says the caller
|
|
146
|
+
* already emitted the failure reason, so only this module's generic silent
|
|
147
|
+
* verdict is suppressed. */
|
|
148
|
+
private finish(result: { stopReason?: string } | undefined, reported = false): void {
|
|
144
149
|
const flushed = this.seams.closeMessage();
|
|
145
150
|
for (const event of flushed) this.seams.emit(event);
|
|
146
151
|
const closed = flushed.find((event) => event.type === 'message_end')?.message;
|
|
@@ -152,11 +157,13 @@ export class AcpTurns {
|
|
|
152
157
|
// most agents (measured on pi-acp: it answers `session/prompt` with `{}` and
|
|
153
158
|
// sends no frames at all when its provider call fails). Reporting it beats
|
|
154
159
|
// leaving an empty bubble that reads as "the agent had nothing to say".
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
|
|
160
|
+
// Whitespace-only chunks are the same failure with a frame attached: the
|
|
161
|
+
// row renders no text, so the operator still sees nothing. Slash commands
|
|
162
|
+
// are exempt: an extension command is answered locally and correctly
|
|
163
|
+
// produces nothing, and a user's Stop is not a failure either.
|
|
164
|
+
const answered = hasRenderableAnswer(closed) || abandoned.length > 0;
|
|
158
165
|
const cancelled = result?.stopReason === 'cancelled';
|
|
159
|
-
if (!answered && !cancelled && !this.promptText.trimStart().startsWith('/')) {
|
|
166
|
+
if (!answered && !cancelled && !reported && !this.promptText.trimStart().startsWith('/')) {
|
|
160
167
|
this.seams.emit({
|
|
161
168
|
type: 'prompt_error',
|
|
162
169
|
errorMessage: 'The agent ended the turn without sending an answer',
|
|
@@ -173,3 +180,20 @@ export class AcpTurns {
|
|
|
173
180
|
});
|
|
174
181
|
}
|
|
175
182
|
}
|
|
183
|
+
|
|
184
|
+
/** Does the closed message carry anything the timeline draws? A whitespace-only
|
|
185
|
+
* chunk (or one that carried only an empty text block) opens a message row
|
|
186
|
+
* that renders nothing, which is the same operator-visible failure as no frame
|
|
187
|
+
* at all. Thinking and tool calls are content: they render as their own
|
|
188
|
+
* blocks. */
|
|
189
|
+
function hasRenderableAnswer(message: unknown): boolean {
|
|
190
|
+
if (!message || typeof message !== 'object' || !('content' in message)) return false;
|
|
191
|
+
const content = message.content;
|
|
192
|
+
if (!Array.isArray(content)) return false;
|
|
193
|
+
return content.some((block) => {
|
|
194
|
+
if (!block || typeof block !== 'object') return false;
|
|
195
|
+
if ('text' in block && typeof block.text === 'string') return block.text.trim().length > 0;
|
|
196
|
+
if ('thinking' in block && typeof block.thinking === 'string') return block.thinking.trim().length > 0;
|
|
197
|
+
return 'type' in block && block.type === 'toolCall';
|
|
198
|
+
});
|
|
199
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The boot pass: every restart re-checks the harnesses the user keeps ON.
|
|
8
|
+
*
|
|
9
|
+
* The requirement is a ROSTER question before it is a probe question, so the
|
|
10
|
+
* cases here hold the selection: off means not spawned, built-in means not
|
|
11
|
+
* spawned, a missing launch command means not spawned. Only then "and the answer
|
|
12
|
+
* is stored" — the settings card reads the cache, not this pass.
|
|
13
|
+
*
|
|
14
|
+
* The seams (`ids`, `available`, `probe`) exist for these tests: a real probe
|
|
15
|
+
* spawns an agent, and a suite that depends on which binaries a runner happens to
|
|
16
|
+
* have is a suite that fails only on CI. The production defaults are the real
|
|
17
|
+
* catalog, `commandAvailable` and `probeWithConfig`.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
21
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
22
|
+
import {
|
|
23
|
+
autoProbeTargets,
|
|
24
|
+
runAutoProbe,
|
|
25
|
+
type AutoProbeOptions,
|
|
26
|
+
} from '@/server/lib/harness/auto-probe.server';
|
|
27
|
+
import type { HarnessProbe } from '@/server/lib/harness/capabilities';
|
|
28
|
+
import { loadProbes, probes } from '@/server/lib/harness/probe-cache.server';
|
|
29
|
+
import { saveHarnessEnabled } from '@/server/lib/harness/enabled.server';
|
|
30
|
+
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
31
|
+
|
|
32
|
+
function probe(id: HarnessId): HarnessProbe {
|
|
33
|
+
return {
|
|
34
|
+
harness: id,
|
|
35
|
+
capabilities: {
|
|
36
|
+
configModel: 5, configThinking: 6, configMode: 5, modeValues: ['plan'],
|
|
37
|
+
loadSession: true, listSessions: true, forkSession: true, deleteSession: false,
|
|
38
|
+
resumeSession: true, closeSession: true, hasUsage: false, hasPlan: false, steerMode: null,
|
|
39
|
+
agentVersion: '1.0.0',
|
|
40
|
+
},
|
|
41
|
+
models: [], thinking: [], modes: [], probedAt: Date.now(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const allAvailable = (): boolean => true;
|
|
46
|
+
|
|
47
|
+
beforeEach(async () => {
|
|
48
|
+
await isolateDb();
|
|
49
|
+
probes().clear();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(async () => {
|
|
53
|
+
await releaseDb();
|
|
54
|
+
probes().clear();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterAll(async () => {
|
|
58
|
+
await releaseDb();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('autoProbeTargets', () => {
|
|
62
|
+
test('skips a switched-off harness and the built-in transport', async () => {
|
|
63
|
+
await saveHarnessEnabled('claude', false);
|
|
64
|
+
const checked: string[] = [];
|
|
65
|
+
const targets = await autoProbeTargets({
|
|
66
|
+
ids: ['omp-rpc', 'omp-acp', 'claude'],
|
|
67
|
+
available: (id) => {
|
|
68
|
+
checked.push(id);
|
|
69
|
+
return true;
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
expect(targets).toEqual(['omp-acp']);
|
|
73
|
+
// The built-in transport never reaches the availability check: there is no
|
|
74
|
+
// agent behind it to ask about.
|
|
75
|
+
expect(checked).toEqual(['omp-acp']);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('skips a harness whose launch command is not resolvable', async () => {
|
|
79
|
+
const targets = await autoProbeTargets({
|
|
80
|
+
ids: ['omp-acp', 'claude', 'cursor'],
|
|
81
|
+
available: (id) => id === 'omp-acp',
|
|
82
|
+
});
|
|
83
|
+
expect(targets).toEqual(['omp-acp']);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('runAutoProbe', () => {
|
|
88
|
+
test('probes every target and stores each answer', async () => {
|
|
89
|
+
const seen: HarnessId[] = [];
|
|
90
|
+
const options: AutoProbeOptions = {
|
|
91
|
+
ids: ['omp-acp', 'claude'],
|
|
92
|
+
cwd: '/tmp',
|
|
93
|
+
available: allAvailable,
|
|
94
|
+
probe: async (id, cwd) => {
|
|
95
|
+
expect(cwd).toBe('/tmp');
|
|
96
|
+
seen.push(id);
|
|
97
|
+
return probe(id);
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const outcome = await runAutoProbe(options);
|
|
101
|
+
expect(outcome.failed).toEqual([]);
|
|
102
|
+
expect(outcome.probed).toEqual(['omp-acp', 'claude']);
|
|
103
|
+
expect(seen).toEqual(['omp-acp', 'claude']);
|
|
104
|
+
expect((await loadProbes()).get('claude')?.capabilities.agentVersion).toBe('1.0.0');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('a probe that throws is reported and does not stop the pass', async () => {
|
|
108
|
+
const outcome = await runAutoProbe({
|
|
109
|
+
ids: ['omp-acp', 'claude'],
|
|
110
|
+
available: allAvailable,
|
|
111
|
+
probe: async (id) => {
|
|
112
|
+
if (id === 'omp-acp') throw new Error('boom');
|
|
113
|
+
return probe(id);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
expect(outcome.failed).toEqual([{ id: 'omp-acp', error: 'boom' }]);
|
|
117
|
+
expect(outcome.probed).toEqual(['claude']);
|
|
118
|
+
expect(probes().has('omp-acp')).toBe(false);
|
|
119
|
+
expect(probes().has('claude')).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Running a harness probe, and the boot pass that refreshes every ON harness.
|
|
8
|
+
*
|
|
9
|
+
* Three callers need the config-aware probe: the settings route's Check status,
|
|
10
|
+
* switching a harness on, and this module's startup pass. It cannot live in a
|
|
11
|
+
* route (`routes/harness/root.ts` used to own it) because the boot clock is not
|
|
12
|
+
* a request and a route must not be the import of the startup path.
|
|
13
|
+
*
|
|
14
|
+
* **The startup pass is per PROCESS, not per module evaluation.** A `bun --hot`
|
|
15
|
+
* reload re-runs the server entry, and a probe spawns an agent process; without
|
|
16
|
+
* the `globalThis` pid guard every edit during development would start one agent
|
|
17
|
+
* per enabled harness. A real restart is a new pid and therefore a fresh pass,
|
|
18
|
+
* which is the moment the requirement names: every Kabmo restart re-checks the
|
|
19
|
+
* harnesses the user keeps ON.
|
|
20
|
+
*
|
|
21
|
+
* It runs in the BACKGROUND. A probe can take a minute (an agent that has to
|
|
22
|
+
* authenticate, a wrapper that resolves a container), and the listener is
|
|
23
|
+
* already accepting requests — boot must not wait for twelve agents to answer.
|
|
24
|
+
*
|
|
25
|
+
* Which harnesses are checked:
|
|
26
|
+
*
|
|
27
|
+
* - switched OFF (`omp_harness_disabled`) is skipped — the roster is the user's
|
|
28
|
+
* answer, and probing an agent they hid would start a process for a tab they
|
|
29
|
+
* never see;
|
|
30
|
+
* - the built-in `omp-rpc` transport is skipped: there is no agent to spawn;
|
|
31
|
+
* - a harness whose launch command is not resolvable is skipped for the same
|
|
32
|
+
* measured reason as the toggle route: the card already says "not installed",
|
|
33
|
+
* and spawning a missing binary only reports that fact again.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import type { HarnessProbe } from '@/server/lib/harness/capabilities';
|
|
37
|
+
import {
|
|
38
|
+
launchFromConfig,
|
|
39
|
+
loadHarnessConfig,
|
|
40
|
+
resolveLaunch,
|
|
41
|
+
} from '@/server/lib/harness/config.server';
|
|
42
|
+
import type { HarnessConfig } from '@/shared/lib/harness/config';
|
|
43
|
+
import { loadDisabledHarnesses } from '@/server/lib/harness/enabled.server';
|
|
44
|
+
import { blockedProbe, probeHarness } from '@/server/lib/harness/launch';
|
|
45
|
+
import { HARNESS_LAUNCH, harnessRequirementMet, type HarnessLaunch } from '@/server/lib/harness/launch-table';
|
|
46
|
+
import { resolveOmpBin } from '@/server/lib/omp/core/cli';
|
|
47
|
+
import { rememberProbe } from '@/server/lib/harness/probe-cache.server';
|
|
48
|
+
import { HARNESS_IDS, harnessDescriptor, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
49
|
+
import { harnessEnabled } from '@/shared/lib/harness/enabled';
|
|
50
|
+
|
|
51
|
+
declare global {
|
|
52
|
+
// eslint-disable-next-line no-var
|
|
53
|
+
var __kabmoHarnessAutoProbePid: number | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Is a launch command first-token resolvable? The omp binary has its own
|
|
58
|
+
* resolver (KABMO_OMP_BIN, then PATH) and is never "missing" through PATH alone.
|
|
59
|
+
*
|
|
60
|
+
* The USER's command override decides this, not the build's table: a harness
|
|
61
|
+
* whose binary lives behind a wrapper, a container (`docker run … agy acp`) or an
|
|
62
|
+
* absolute path read as "not installed" and could not even be switched on, while
|
|
63
|
+
* a spawn of that same configured command worked.
|
|
64
|
+
*/
|
|
65
|
+
export function commandAvailable(id: HarnessId, config?: HarnessConfig): boolean {
|
|
66
|
+
if (id === 'omp-acp') return Boolean(resolveOmpBin());
|
|
67
|
+
let launch: HarnessLaunch | undefined = HARNESS_LAUNCH[id];
|
|
68
|
+
if (config) {
|
|
69
|
+
try {
|
|
70
|
+
const configured = launchFromConfig(id, config);
|
|
71
|
+
if (configured) launch = configured;
|
|
72
|
+
} catch {
|
|
73
|
+
// An unusable env line is reported by the probe; availability falls back
|
|
74
|
+
// to the build's table rather than claiming "not installed".
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const [binary] = launch?.command ?? [];
|
|
78
|
+
if (!binary) return false;
|
|
79
|
+
// An adapter can need a binary it SPAWNS rather than execs: the zcode bridge
|
|
80
|
+
// starts `zcode app-server --stdio`, so `npx` being present says nothing.
|
|
81
|
+
if (!harnessRequirementMet(launch?.requires, launch?.env)) return false;
|
|
82
|
+
if (binary === 'npx') return Boolean(Bun.which('npx') ?? Bun.which('node'));
|
|
83
|
+
return Boolean(Bun.which(binary));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Probe a harness the way a SPAWN would launch it: the user's command and env
|
|
88
|
+
* override are part of what is being measured.
|
|
89
|
+
*
|
|
90
|
+
* Without this, a harness that only works with its configured env — `CODEX_HOME`,
|
|
91
|
+
* a provider base URL, a wrapper that logs in — probed as "Authentication
|
|
92
|
+
* required" in Settings while its chats ran fine. A launch line that cannot even
|
|
93
|
+
* be resolved (an invalid env line) answers a `blocked` record instead of a 500.
|
|
94
|
+
*/
|
|
95
|
+
export async function probeWithConfig(id: HarnessId, cwd: string): Promise<HarnessProbe> {
|
|
96
|
+
try {
|
|
97
|
+
const configured = await loadHarnessConfig(id);
|
|
98
|
+
return await probeHarness(id, cwd, resolveLaunch(id, configured));
|
|
99
|
+
} catch (cause) {
|
|
100
|
+
return blockedProbe(id, cause instanceof Error ? cause.message : String(cause));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Seams for the tests: the real catalog, availability and probe by default. */
|
|
105
|
+
export interface AutoProbeOptions {
|
|
106
|
+
cwd?: string;
|
|
107
|
+
ids?: readonly HarnessId[];
|
|
108
|
+
available?: (id: HarnessId, config: HarnessConfig) => boolean;
|
|
109
|
+
probe?: (id: HarnessId, cwd: string) => Promise<HarnessProbe>;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The harnesses the user keeps ON that this machine can actually launch. */
|
|
113
|
+
export async function autoProbeTargets(
|
|
114
|
+
options: Pick<AutoProbeOptions, 'ids' | 'available'> = {},
|
|
115
|
+
): Promise<HarnessId[]> {
|
|
116
|
+
const ids = options.ids ?? HARNESS_IDS;
|
|
117
|
+
const available = options.available ?? commandAvailable;
|
|
118
|
+
const disabled = await loadDisabledHarnesses();
|
|
119
|
+
const targets: HarnessId[] = [];
|
|
120
|
+
for (const id of ids) {
|
|
121
|
+
if (harnessDescriptor(id)?.builtIn) continue;
|
|
122
|
+
if (!harnessEnabled(id, disabled)) continue;
|
|
123
|
+
const config = await loadHarnessConfig(id);
|
|
124
|
+
if (!available(id, config)) continue;
|
|
125
|
+
targets.push(id);
|
|
126
|
+
}
|
|
127
|
+
return targets;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** What one boot pass did, for the log line and for the tests. */
|
|
131
|
+
export interface AutoProbeOutcome {
|
|
132
|
+
probed: HarnessId[];
|
|
133
|
+
failed: Array<{ id: HarnessId; error: string }>;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Probe every target, one at a time, and write each answer to the cache.
|
|
138
|
+
*
|
|
139
|
+
* Sequential on purpose: these are agent processes, and a boot that starts one
|
|
140
|
+
* per installed harness at once competes with the chat the user just opened. A
|
|
141
|
+
* failure on one harness is recorded and the pass continues — the others still
|
|
142
|
+
* deserve their answer.
|
|
143
|
+
*/
|
|
144
|
+
export async function runAutoProbe(options: AutoProbeOptions = {}): Promise<AutoProbeOutcome> {
|
|
145
|
+
const cwd = options.cwd ?? process.cwd();
|
|
146
|
+
const probe = options.probe ?? probeWithConfig;
|
|
147
|
+
const targets = await autoProbeTargets(options);
|
|
148
|
+
const outcome: AutoProbeOutcome = { probed: [], failed: [] };
|
|
149
|
+
for (const id of targets) {
|
|
150
|
+
try {
|
|
151
|
+
await rememberProbe(id, await probe(id, cwd));
|
|
152
|
+
outcome.probed.push(id);
|
|
153
|
+
} catch (error) {
|
|
154
|
+
outcome.failed.push({ id, error: error instanceof Error ? error.message : String(error) });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return outcome;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Start the boot pass. Idempotent within one process — a `bun --hot` reload must
|
|
162
|
+
* not spawn the agents again — and never awaited, because boot does not wait for
|
|
163
|
+
* an agent to answer.
|
|
164
|
+
*/
|
|
165
|
+
export function startHarnessAutoProbe(): void {
|
|
166
|
+
if (globalThis.__kabmoHarnessAutoProbePid === process.pid) return;
|
|
167
|
+
globalThis.__kabmoHarnessAutoProbePid = process.pid;
|
|
168
|
+
void runAutoProbe()
|
|
169
|
+
.then(({ probed, failed }) => {
|
|
170
|
+
if (probed.length > 0) console.log(`[harness] probed on boot: ${probed.join(', ')}`);
|
|
171
|
+
for (const failure of failed) {
|
|
172
|
+
console.error(`[harness] ${failure.id}: boot probe failed — ${failure.error}`);
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
.catch((error) => {
|
|
176
|
+
console.error('[harness] boot probe skipped:', error);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
@@ -21,7 +21,7 @@ import { afterAll, afterEach, beforeEach, describe, expect, test } from 'bun:tes
|
|
|
21
21
|
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
22
22
|
import { EMPTY_HARNESS_CONFIG, parseHarnessConfig } from '@/shared/lib/harness/config';
|
|
23
23
|
import { loadHarnessConfig, resolveLaunch, saveHarnessConfig } from '@/server/lib/harness/config.server';
|
|
24
|
-
import { HARNESS_LAUNCH } from '@/server/lib/harness/launch';
|
|
24
|
+
import { HARNESS_LAUNCH } from '@/server/lib/harness/launch-table';
|
|
25
25
|
|
|
26
26
|
beforeEach(async () => {
|
|
27
27
|
await isolateDb();
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { getDb } from '@/server/db.server';
|
|
18
18
|
import { readSettingsJson, writeSettingsJson } from '@/server/lib/db/settings-store';
|
|
19
|
-
import { HARNESS_LAUNCH, type HarnessLaunch } from '@/server/lib/harness/launch';
|
|
19
|
+
import { HARNESS_LAUNCH, type HarnessLaunch } from '@/server/lib/harness/launch-table';
|
|
20
20
|
import {
|
|
21
21
|
harnessConfigKey,
|
|
22
22
|
isHarnessConfigured,
|