@kabmo-labs/kabmo 0.24.0 → 0.25.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 +579 -510
- package/dist/client/static/js/index-bc9aa4mx.css +1 -0
- package/dist/client/static/js/{index-jcr5twtp.js → index-ga8cbpt4.js} +1072 -1174
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
- package/src/client/components/common/session-actions-menu/index.tsx +33 -2
- package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
- package/src/client/components/common/session-row/index.tsx +27 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +36 -5
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +28 -35
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +3 -1
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +1 -1
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +12 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/send-execute.test.ts +39 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-steer.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.test-util.ts +7 -1
- package/src/client/hooks/chat/timeline/send.test.ts +3 -1
- package/src/client/hooks/chat/timeline/send.ts +51 -50
- package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
- package/src/client/hooks/models/use-harness-update.test.ts +193 -0
- package/src/client/hooks/models/use-harness-update.ts +202 -0
- package/src/client/hooks/workspace/child-expansion.ts +33 -0
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/tailwind.css +17 -11
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/client.ts +2 -2
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
- package/src/server/lib/harness/acp/session-handshake.ts +27 -1
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-requests.ts +47 -0
- package/src/server/lib/harness/acp/session-turns.ts +20 -5
- package/src/server/lib/harness/acp/session.test-util.ts +23 -1
- package/src/server/lib/harness/acp/session.ts +59 -59
- package/src/server/lib/harness/acp/turn.test.ts +81 -0
- package/src/server/lib/harness/acp/turn.ts +26 -9
- package/src/server/lib/harness/acp/verbs.ts +12 -2
- package/src/server/lib/harness/launch.ts +3 -1
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +126 -0
- package/src/server/lib/harness/update-job-store.ts +109 -0
- package/src/server/lib/harness/update-job.server.ts +203 -0
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +197 -0
- package/src/server/lib/lifecycle/paths.ts +23 -0
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
- package/src/server/lib/omp/session/delete-flow.server.ts +47 -0
- package/src/server/lib/omp/session/delete.server.ts +5 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +209 -0
- package/src/server/lib/sessions/fork.server.ts +304 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +196 -0
- package/src/server/lib/sessions/spawn.server.ts +310 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +6 -0
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +4 -0
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/update-status.ts +26 -0
- package/src/server/routes/harness/update.test.ts +119 -0
- package/src/server/routes/harness/update.ts +59 -147
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +74 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/session.ts +4 -0
- package/src/server/routes/sessions/spawn.ts +134 -0
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/provider-facts.test.ts +27 -0
- package/src/shared/lib/harness/providers.ts +35 -1
- package/src/shared/lib/harness/update-job.ts +33 -0
- package/src/shared/lib/harness/update-plan.test.ts +21 -6
- package/src/shared/lib/harness/update-plan.ts +12 -4
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/theme.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +65 -0
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/harness-table.test-util.ts +15 -1
- package/dist/client/static/js/index-z3w7n85q.css +0 -1
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One authenticated GET against a provider's own balance/usage endpoint.
|
|
8
|
+
*
|
|
9
|
+
* Every balance source needs the same three answers — key rejected, request
|
|
10
|
+
* failed, response is not JSON — and they must read the same on every card, so
|
|
11
|
+
* the status handling lives here rather than in each adapter.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const FETCH_TIMEOUT_MS = 10_000;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Fetch and parse JSON, or throw an error whose message is safe to show in the
|
|
18
|
+
* provider card (it names the provider, never the credential).
|
|
19
|
+
*/
|
|
20
|
+
export async function fetchProviderJson(url: string, apiKey: string, label: string): Promise<unknown> {
|
|
21
|
+
let response: Response;
|
|
22
|
+
try {
|
|
23
|
+
response = await fetch(url, {
|
|
24
|
+
headers: { Authorization: `Bearer ${apiKey}`, Accept: 'application/json' },
|
|
25
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
26
|
+
});
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error(error instanceof Error ? error.message : `${label} balance request failed`);
|
|
29
|
+
}
|
|
30
|
+
if (response.status === 401 || response.status === 403) {
|
|
31
|
+
throw new Error(`${label} rejected the API key (HTTP ${response.status}).`);
|
|
32
|
+
}
|
|
33
|
+
if (response.status < 200 || response.status >= 300) {
|
|
34
|
+
throw new Error(`${label} balance request failed (HTTP ${response.status}).`);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
return await response.json();
|
|
38
|
+
} catch {
|
|
39
|
+
throw new Error(`${label} returned an unreadable balance response.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The USD window shape every provider-reported credit source produces
|
|
8
|
+
* (OpenRouter's key limits, a New API gateway's billing endpoints, …).
|
|
9
|
+
*
|
|
10
|
+
* One builder: `remaining` means the same thing on every card, and a
|
|
11
|
+
* vendor-specific copy drifts the moment one of them is "fixed".
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { UsageLimitWindow, UsageWindowStatus } from '@/shared/types';
|
|
15
|
+
|
|
16
|
+
/** A finite number from a JSON value, including the numeric strings vendors send. */
|
|
17
|
+
export function num(value: unknown): number | undefined {
|
|
18
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
|
19
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
20
|
+
const parsed = Number(value);
|
|
21
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Status for a credit window: exhausted at zero remaining, else ok. */
|
|
27
|
+
function balanceStatus(remaining: number | undefined): UsageWindowStatus {
|
|
28
|
+
if (remaining === undefined) return 'unknown';
|
|
29
|
+
return remaining <= 0 ? 'exhausted' : 'ok';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** One USD window from a balance; `limit` is omitted when the vendor has none. */
|
|
33
|
+
export function usdWindow(input: {
|
|
34
|
+
id: string;
|
|
35
|
+
label: string;
|
|
36
|
+
used?: number;
|
|
37
|
+
limit?: number;
|
|
38
|
+
remaining?: number;
|
|
39
|
+
note?: string;
|
|
40
|
+
}): UsageLimitWindow {
|
|
41
|
+
const usedFraction = input.limit && input.limit > 0 && input.used !== undefined
|
|
42
|
+
? input.used / input.limit
|
|
43
|
+
: undefined;
|
|
44
|
+
return {
|
|
45
|
+
id: input.id,
|
|
46
|
+
label: input.label,
|
|
47
|
+
unit: 'usd',
|
|
48
|
+
status: balanceStatus(input.remaining),
|
|
49
|
+
...(input.used !== undefined ? { used: input.used } : {}),
|
|
50
|
+
...(input.limit !== undefined ? { limit: input.limit } : {}),
|
|
51
|
+
...(input.remaining !== undefined ? { remaining: input.remaining } : {}),
|
|
52
|
+
...(usedFraction !== undefined ? { usedFraction } : {}),
|
|
53
|
+
...(input.note ? { notes: [input.note] } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -11,6 +11,7 @@ import { assertBtwIdle } from '@/server/lib/btw/service.server';
|
|
|
11
11
|
import { loadPersistedModes } from '@/server/lib/omp/session/modes';
|
|
12
12
|
import { isModeCommandType, modeCommandPrompt, parseModeRequest, parseModeSelection } from '@/server/lib/omp/mode/request';
|
|
13
13
|
import { kabmoModeEnv } from '@/server/lib/omp/extensions/locator';
|
|
14
|
+
import { mintAgentEnvironment, rememberAgentToken } from '@/server/lib/sessions/agent-token.server';
|
|
14
15
|
import { resetGoalDriverState } from '@/server/lib/omp/session/goal-driver.server';
|
|
15
16
|
import { forwardToPeer, isPeerRelayed, peerOriginForSession } from '@/server/lib/omp/rpc/peer-proxy.server';
|
|
16
17
|
import { applyHarnessMode, resumeRecordedHarnessSession } from '@/server/routes/agent/harness-command';
|
|
@@ -176,7 +177,19 @@ export async function sendCommand({ params, request }: ActionFunctionArgs) {
|
|
|
176
177
|
const asked = body.type === 'set_model' && typeof body.provider === 'string' && typeof body.modelId === 'string'
|
|
177
178
|
? { provider: body.provider, modelId: body.modelId }
|
|
178
179
|
: undefined;
|
|
179
|
-
const {
|
|
180
|
+
const { token, env: agentEnv } = mintAgentEnvironment();
|
|
181
|
+
const { session } = await startRpcSession(
|
|
182
|
+
sessionId,
|
|
183
|
+
filePath,
|
|
184
|
+
cwd,
|
|
185
|
+
recordedCwd,
|
|
186
|
+
spawnMode,
|
|
187
|
+
{ ...(modeEnv ?? {}), ...agentEnv },
|
|
188
|
+
asked,
|
|
189
|
+
);
|
|
190
|
+
await rememberAgentToken(sessionId, token).catch((cause: unknown) => {
|
|
191
|
+
console.error(`[sessions] could not record the agent token for ${sessionId}:`, cause);
|
|
192
|
+
});
|
|
180
193
|
const result = await session.send(forwarded);
|
|
181
194
|
// Same Resume nudge as the live path: a resumed goal must not sit idle
|
|
182
195
|
// waiting for the operator's next message.
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import { freshProbe } from '@/server/lib/harness/probe-cache.server';
|
|
17
17
|
import { startAcpSession } from '@/server/lib/harness/spawn.server';
|
|
18
|
+
import { mintAgentEnvironment, rememberAgentToken } from '@/server/lib/sessions/agent-token.server';
|
|
18
19
|
import { knownHarness, loadHarnessSession, repointHarnessSession } from '@/server/lib/harness/session-store.server';
|
|
19
20
|
import { selectValues } from '@/server/lib/harness/launch';
|
|
20
21
|
import { harnessOfSession } from '@/server/lib/omp/rpc/session-registry';
|
|
@@ -65,6 +66,7 @@ export async function resumeRecordedHarnessSession(
|
|
|
65
66
|
if (probe?.capabilities.loadSession === false) {
|
|
66
67
|
throw new Error(`${label} cannot restore this chat: it does not support session/load.`);
|
|
67
68
|
}
|
|
69
|
+
const { token, env } = mintAgentEnvironment();
|
|
68
70
|
const { session, realSessionId } = await startAcpSession({
|
|
69
71
|
harness,
|
|
70
72
|
sessionId,
|
|
@@ -77,6 +79,10 @@ export async function resumeRecordedHarnessSession(
|
|
|
77
79
|
resumeAgentSessionId: record.agentSessionId || sessionId,
|
|
78
80
|
cwd: record.cwd,
|
|
79
81
|
accessMode,
|
|
82
|
+
env,
|
|
83
|
+
});
|
|
84
|
+
await rememberAgentToken(sessionId, token).catch((cause: unknown) => {
|
|
85
|
+
console.error(`[sessions] could not record the agent token for ${sessionId}:`, cause);
|
|
80
86
|
});
|
|
81
87
|
// A forking load answers a NEW agent id, and the spawn recorded that id as its
|
|
82
88
|
// own row — a second sidebar row for one conversation. The chat keeps ITS id
|
|
@@ -10,6 +10,8 @@ import { parseModeSelection } from '@/server/lib/omp/mode/request';
|
|
|
10
10
|
import { projectModelForCwd } from '@/server/lib/workspace/project-model.server';
|
|
11
11
|
import { HARNESS_IDS, type HarnessId } from '@/shared/lib/harness/catalog';
|
|
12
12
|
import { startAcpSession } from '@/server/lib/harness/spawn.server';
|
|
13
|
+
import { mintAgentEnvironment, rememberAgentToken } from '@/server/lib/sessions/agent-token.server';
|
|
14
|
+
import { isMockMode } from '@/server/mock.server';
|
|
13
15
|
|
|
14
16
|
/** The model-dropdown persists its selection here (actionType 'selectModel');
|
|
15
17
|
* a spawn that arrives without an explicit provider/modelId falls back to it. */
|
|
@@ -40,6 +42,14 @@ async function loadPersistedModel(): Promise<{ provider: string; modelId: string
|
|
|
40
42
|
// omp itself, so Kabmo adopts it via the URL param after the response.
|
|
41
43
|
export async function action({ request }: ActionFunctionArgs) {
|
|
42
44
|
try {
|
|
45
|
+
// MOCK mode has no agent process to start, and saying so with a CODE is what
|
|
46
|
+
// lets the composer take its simulated path instead of reporting "Prompt not
|
|
47
|
+
// sent: omp binary not found" — measured in the demo shell on a host without
|
|
48
|
+
// omp, where the landing composer silently did nothing. Real spawn failures
|
|
49
|
+
// still report, because they carry no `mock_mode`.
|
|
50
|
+
if (isMockMode()) {
|
|
51
|
+
return json({ error: 'Mock mode runs no agent process', code: 'mock_mode' }, { status: 400 });
|
|
52
|
+
}
|
|
43
53
|
const body = await request.json().catch(() => null);
|
|
44
54
|
if (!body || typeof body.type !== 'string' || !body.type.trim()) {
|
|
45
55
|
return json({ error: 'command type is required', code: 'command_type_required' }, { status: 400 });
|
|
@@ -151,6 +161,7 @@ async function startAcpChat({ harness, cwd, body, model, accessMode }: {
|
|
|
151
161
|
const projectModel = await projectModelForCwd(await getDb(), cwd);
|
|
152
162
|
const thinkingLevel = typeof body.thinkingLevel === 'string' ? body.thinkingLevel : null;
|
|
153
163
|
const mode = harnessModeSelection(body);
|
|
164
|
+
const { token, env: agentEnv } = mintAgentEnvironment();
|
|
154
165
|
const { session, realSessionId } = await startAcpSession({
|
|
155
166
|
harness,
|
|
156
167
|
sessionId: `__new__${Bun.randomUUIDv7()}`,
|
|
@@ -159,6 +170,10 @@ async function startAcpChat({ harness, cwd, body, model, accessMode }: {
|
|
|
159
170
|
thinkingLevel,
|
|
160
171
|
mode,
|
|
161
172
|
accessMode,
|
|
173
|
+
env: agentEnv,
|
|
174
|
+
});
|
|
175
|
+
await rememberAgentToken(realSessionId, token).catch((cause: unknown) => {
|
|
176
|
+
console.error(`[sessions] could not record the agent token for ${realSessionId}:`, cause);
|
|
162
177
|
});
|
|
163
178
|
|
|
164
179
|
if (type === 'ensure_session') {
|
|
@@ -198,11 +198,19 @@ describe('adding a provider to an environment harness', () => {
|
|
|
198
198
|
}));
|
|
199
199
|
const payload = await response.json() as { config?: { env: string }; envWritten?: string[]; error?: string };
|
|
200
200
|
expect(payload.error).toBeUndefined();
|
|
201
|
-
expect(payload.envWritten).toEqual([
|
|
201
|
+
expect(payload.envWritten).toEqual([
|
|
202
|
+
'ANTHROPIC_BASE_URL',
|
|
203
|
+
'ANTHROPIC_AUTH_TOKEN',
|
|
204
|
+
'ANTHROPIC_MODEL',
|
|
205
|
+
'ANTHROPIC_DEFAULT_SONNET_MODEL',
|
|
206
|
+
]);
|
|
202
207
|
// `/v1` stripped: the SDK appends `/v1/messages` itself.
|
|
203
208
|
expect(payload.config?.env).toContain(`ANTHROPIC_BASE_URL=${baseUrl.replace(/\/v1$/, '')}`);
|
|
204
209
|
expect(payload.config?.env).toContain('ANTHROPIC_AUTH_TOKEN=sk-claude');
|
|
205
210
|
expect(payload.config?.env).toContain('ANTHROPIC_MODEL=claude-sonnet-5');
|
|
211
|
+
// The picker's `sonnet` alias now resolves to the id this endpoint serves;
|
|
212
|
+
// unpinned it would send the literal alias and answer 400.
|
|
213
|
+
expect(payload.config?.env).toContain('ANTHROPIC_DEFAULT_SONNET_MODEL=claude-sonnet-5');
|
|
206
214
|
});
|
|
207
215
|
|
|
208
216
|
test('no name is refused before anything is written', async () => {
|
|
@@ -185,6 +185,10 @@ export async function applyProvider(target: HarnessId, candidate: Candidate, sou
|
|
|
185
185
|
baseUrl: adaptBaseUrl(draft.baseUrl ?? '', 'root'),
|
|
186
186
|
apiKey: draft.apiKey ?? '',
|
|
187
187
|
...(pinnedModel(planned, draft.models) ? { model: pinnedModel(planned, draft.models)! } : {}),
|
|
188
|
+
// The endpoint's own listing decides what each picker alias resolves to.
|
|
189
|
+
// Without it Claude Code sends the literal alias as the model id and the
|
|
190
|
+
// gateway answers 400.
|
|
191
|
+
models: draft.models,
|
|
188
192
|
});
|
|
189
193
|
if (Object.keys(env).length === 0) {
|
|
190
194
|
return json({ error: `Nothing to write: "${candidate.id}" has no endpoint or key.` }, { status: 400 });
|
|
@@ -132,7 +132,7 @@ describe('importing a custom provider into claude', () => {
|
|
|
132
132
|
// even though the source declares openai-completions.
|
|
133
133
|
expect(payload.protocol).toBe('anthropic-messages');
|
|
134
134
|
expect(payload.envWritten).toEqual(
|
|
135
|
-
['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_MODEL'],
|
|
135
|
+
['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_MODEL', 'ANTHROPIC_DEFAULT_SONNET_MODEL'],
|
|
136
136
|
);
|
|
137
137
|
// The stub's `/v1` is stripped: the SDK appends `/v1/messages` itself.
|
|
138
138
|
expect(payload.config?.env).toContain(`ANTHROPIC_BASE_URL=${baseUrl.replace(/\/v1$/, '')}`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { actionBindings, type HandlerBinding } from '@/server/lib/route-adapter';
|
|
1
|
+
import { actionBindings, bindingsFor, type HandlerBinding } from '@/server/lib/route-adapter';
|
|
2
2
|
import * as harnessRoot from '@/server/routes/harness/root';
|
|
3
3
|
import * as harnessUpdate from '@/server/routes/harness/update';
|
|
4
|
+
import * as harnessUpdateStatus from '@/server/routes/harness/update-status';
|
|
4
5
|
import * as harnessVersions from '@/server/routes/harness/versions';
|
|
5
6
|
|
|
6
7
|
export const harnessBindings: HandlerBinding[] = [
|
|
@@ -8,6 +9,9 @@ export const harnessBindings: HandlerBinding[] = [
|
|
|
8
9
|
// Static paths registered as their own routes. A `/api/harness/:id` parameter
|
|
9
10
|
// route sharing this position is the shape that makes the parameter win the
|
|
10
11
|
// match and hide the real handler behind a 405.
|
|
12
|
+
// The update's BACKGROUND progress is its own GET: `/api/harness/update` keeps
|
|
13
|
+
// answering the version rows for compatibility.
|
|
14
|
+
...bindingsFor(harnessUpdateStatus, '/api/harness/update/status'),
|
|
11
15
|
...actionBindings(harnessUpdate.action, '/api/harness/update', harnessVersions.loader),
|
|
12
16
|
...actionBindings(harnessRoot.action, '/api/harness/versions', harnessVersions.loader),
|
|
13
17
|
];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `GET /api/harness/update/status` — the background update the POST started.
|
|
8
|
+
*
|
|
9
|
+
* The POST answers `202` in milliseconds and the install keeps running in a
|
|
10
|
+
* detached worker, so this is how the dialog learns where it is and whether it
|
|
11
|
+
* finished. A poll is also where the SERVER applies the post-install side
|
|
12
|
+
* effects (`finalizeUpdateJob`): the caches and the launch line live in this
|
|
13
|
+
* process, not in the worker.
|
|
14
|
+
*
|
|
15
|
+
* `null` is a real answer — no update has ever run — and it must not be a 404:
|
|
16
|
+
* the About card asks this on every open, and a "not found" would read as a
|
|
17
|
+
* broken route rather than "nothing is running".
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { json, NO_STORE_HEADERS } from '@/server/lib/remix-compat';
|
|
21
|
+
import { finalizeUpdateJob } from '@/server/lib/harness/update-job.server';
|
|
22
|
+
|
|
23
|
+
export async function loader() {
|
|
24
|
+
const job = await finalizeUpdateJob();
|
|
25
|
+
return json({ job }, { headers: NO_STORE_HEADERS });
|
|
26
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `POST /api/harness/update` and `GET /api/harness/update/status`.
|
|
8
|
+
*
|
|
9
|
+
* The route used to run the installs itself; it now starts a background worker
|
|
10
|
+
* and answers `202`. These cases pin the answers that do NOT spawn anything —
|
|
11
|
+
* the refusals and the progress read — because those are the shapes the dialog
|
|
12
|
+
* branches on, and a wrong status there either starts a competing install or
|
|
13
|
+
* reports success it never observed.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
import { action } from '@/server/routes/harness/update';
|
|
21
|
+
import { loader as statusLoader } from '@/server/routes/harness/update-status';
|
|
22
|
+
import { writeUpdateJob } from '@/server/lib/harness/update-job-store';
|
|
23
|
+
import type { HarnessUpdateJob } from '@/shared/types/harness-update';
|
|
24
|
+
|
|
25
|
+
let dir = '';
|
|
26
|
+
let originalDataDir: string | undefined;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
originalDataDir = Bun.env.KABMO_DATA_DIR;
|
|
30
|
+
dir = mkdtempSync(join(tmpdir(), 'kabmo-update-route-'));
|
|
31
|
+
Bun.env.KABMO_DATA_DIR = dir;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
if (originalDataDir === undefined) delete Bun.env.KABMO_DATA_DIR;
|
|
36
|
+
else Bun.env.KABMO_DATA_DIR = originalDataDir;
|
|
37
|
+
rmSync(dir, { recursive: true, force: true });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function post(harness: string): Parameters<typeof action>[0] {
|
|
41
|
+
return {
|
|
42
|
+
request: new Request('http://localhost/api/harness/update', {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: { 'content-type': 'application/json' },
|
|
45
|
+
body: JSON.stringify({ harness }),
|
|
46
|
+
}),
|
|
47
|
+
params: {},
|
|
48
|
+
} as Parameters<typeof action>[0];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function job(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
|
|
52
|
+
return {
|
|
53
|
+
harness: 'claude',
|
|
54
|
+
label: 'claude',
|
|
55
|
+
startedAt: Date.now(),
|
|
56
|
+
finishedAt: null,
|
|
57
|
+
pid: process.pid,
|
|
58
|
+
steps: [{ part: 'adapter', command: 'npm install -g x', argv: ['npm', 'install', '-g', 'x'], state: 'running', code: null }],
|
|
59
|
+
output: '',
|
|
60
|
+
ok: null,
|
|
61
|
+
message: null,
|
|
62
|
+
applied: false,
|
|
63
|
+
repointed: null,
|
|
64
|
+
...overrides,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('POST /api/harness/update', () => {
|
|
69
|
+
test('an unknown harness is refused before anything runs', async () => {
|
|
70
|
+
const response = (await action(post('nope'))) as Response;
|
|
71
|
+
expect(response.status).toBe(400);
|
|
72
|
+
expect(((await response.json()) as { error: string }).error).toBe('Unknown harness');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('a vendor-managed harness is refused with the reason', async () => {
|
|
76
|
+
// `cursor` is updated by its own installer; Kabmo replacing it would be an
|
|
77
|
+
// install it did not make.
|
|
78
|
+
const response = (await action(post('cursor'))) as Response;
|
|
79
|
+
expect(response.status).toBe(400);
|
|
80
|
+
const payload = (await response.json()) as { error: string; code: string };
|
|
81
|
+
expect(payload.code).toBe('vendor_managed');
|
|
82
|
+
expect(payload.error).toContain('installed by its vendor');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('a second press while a run is in flight is a 409 that names the run', async () => {
|
|
86
|
+
// Measured corruption vector: a reload forgot the run and offered the button,
|
|
87
|
+
// so two `npm install -g` wrote the same prefix at once. The record on disk is
|
|
88
|
+
// what refuses it now.
|
|
89
|
+
await writeUpdateJob(job());
|
|
90
|
+
const response = (await action(post('claude'))) as Response;
|
|
91
|
+
expect(response.status).toBe(409);
|
|
92
|
+
const payload = (await response.json()) as { error: string; job: HarnessUpdateJob };
|
|
93
|
+
expect(payload.error).toContain('already running');
|
|
94
|
+
expect(payload.job.harness).toBe('claude');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('GET /api/harness/update/status', () => {
|
|
99
|
+
test('no run ever started is null, not a 404', async () => {
|
|
100
|
+
const response = (await statusLoader()) as Response;
|
|
101
|
+
expect(response.status).toBe(200);
|
|
102
|
+
expect(((await response.json()) as { job: unknown }).job).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('a finished run is reported with its message', async () => {
|
|
106
|
+
const done = job({
|
|
107
|
+
pid: null,
|
|
108
|
+
finishedAt: Date.now(),
|
|
109
|
+
ok: true,
|
|
110
|
+
applied: true,
|
|
111
|
+
message: 'claude updated (adapter) — check its status to read the new version',
|
|
112
|
+
});
|
|
113
|
+
await writeUpdateJob(done);
|
|
114
|
+
const response = (await statusLoader()) as Response;
|
|
115
|
+
const payload = (await response.json()) as { job: HarnessUpdateJob };
|
|
116
|
+
expect(payload.job.ok).toBe(true);
|
|
117
|
+
expect(payload.job.message).toContain('claude updated');
|
|
118
|
+
});
|
|
119
|
+
});
|