moi-computer 0.11.0 → 0.11.1-next.1
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/client/AGENTS.md +2 -2
- package/client/components/ui/button.tsx +1 -53
- package/client/components/ui/collapsible.tsx +1 -15
- package/client/components/ui/dialog.tsx +1 -58
- package/client/components/ui/dropdown-menu.tsx +1 -254
- package/client/components/ui/hover-card.tsx +1 -44
- package/client/components/ui/input.tsx +1 -21
- package/client/components/ui/popover.tsx +1 -88
- package/client/components/ui/resizable.tsx +1 -40
- package/client/components/ui/skeleton.tsx +1 -13
- package/client/components/ui/slider.tsx +1 -70
- package/client/components/ui/spinner.tsx +1 -18
- package/client/components/ui/switch.tsx +1 -23
- package/client/components/ui/tabs.tsx +1 -0
- package/client/components/ui/textarea.tsx +1 -18
- package/client/components/ui/tooltip.tsx +1 -51
- package/client/features/chat/ChatPanel.tsx +6 -6
- package/client/features/chat/ChatPopup.tsx +3 -4
- package/client/features/chat/TurnView.tsx +5 -4
- package/client/features/chat/api.ts +5 -14
- package/client/features/chat/chat-frames.ts +5 -2
- package/client/features/chat/composer/ChatComposer.tsx +5 -1
- package/client/features/chat/composer/ModelPicker.tsx +4 -3
- package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
- package/client/features/chat/group-turns.ts +11 -0
- package/client/features/chat/session-view.ts +53 -0
- package/client/features/chat/useChat.ts +5 -1
- package/client/features/dev/ChatStatesPage.tsx +3 -1
- package/client/features/dev/DevIndexPage.tsx +5 -0
- package/client/features/dev/DevRoutes.tsx +2 -0
- package/client/features/dev/HarnessDebugPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +834 -0
- package/client/features/dev/UiComponentsPage.tsx +60 -0
- package/client/features/home/WorkspacePreview.tsx +1 -1
- package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
- package/client/features/settings/SettingsLayout.tsx +1 -1
- package/client/features/settings/WorkspaceSettings.tsx +4 -1
- package/client/features/views/ViewManager.tsx +14 -9
- package/client/features/widgets/WidgetFrame.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +1 -3
- package/client/features/workspace/WorkspaceScreen.tsx +5 -1
- package/client/features/workspace/WorkspaceSplitLayout.tsx +6 -1
- package/client/features/workspace/api.ts +2 -4
- package/client/index.css +22 -29
- package/dist/{chunk-tny85yt2.js → chunk-4s15axjs.js} +2 -2
- package/dist/{chunk-c9pjqx9m.js → chunk-53a7pxcz.js} +1 -1
- package/dist/chunk-6664vxpk.css +1 -0
- package/dist/{chunk-104m57qw.js → chunk-87thzbtw.js} +2 -2
- package/dist/chunk-a6jad1a6.js +1 -0
- package/dist/chunk-dghwstd2.js +9 -0
- package/dist/chunk-eg120aca.js +1 -0
- package/dist/{chunk-v7wr1df4.js → chunk-j3wvxjr7.js} +1 -1
- package/dist/chunk-vwjeezeb.js +1 -0
- package/dist/chunk-w482ew2c.js +546 -0
- package/dist/chunk-yc471zah.js +70 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +49 -1
- package/lib/themes.ts +6 -6
- package/lib/types.ts +5 -7
- package/package.json +17 -7
- package/registry.json +643 -0
- package/server/AGENTS.md +1 -0
- package/server/agent.ts +1 -1
- package/server/api.ts +25 -29
- package/server/applets.ts +30 -29
- package/server/bundler/applet-css.ts +6 -1
- package/server/bundler/build-applet.ts +5 -1
- package/server/bundler/build-worker.ts +178 -0
- package/server/cli-ui-components.ts +28 -33
- package/server/cli.ts +6 -11
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +13 -9
- package/server/harness/acp/NOTES.md +426 -0
- package/server/harness/acp/discovery.ts +27 -30
- package/server/harness/acp/model-state.ts +57 -0
- package/server/harness/acp/session.ts +18 -6
- package/server/harness/claude-code/NOTES.md +47 -12
- package/server/harness/claude-code/cli.ts +40 -0
- package/server/harness/claude-code/index.ts +11 -5
- package/server/harness/claude-code/models.ts +72 -19
- package/server/harness/claude-code/session.ts +408 -299
- package/server/harness/hermes/NOTES.md +18 -0
- package/server/harness/hermes/discovery.ts +20 -0
- package/server/harness/hermes/index.ts +9 -0
- package/server/harness/hermes/models.ts +28 -8
- package/server/harness/types.ts +4 -2
- package/server/moi-scaffold.ts +1 -1
- package/server/preview.ts +3 -1
- package/server/registry.ts +63 -41
- package/server/scratchpad-executor.ts +79 -56
- package/server/scratchpad-shape-defaults.ts +82 -0
- package/server/tldraw-package.d.ts +4 -0
- package/server/ui-components.ts +101 -434
- package/server/view-builders.ts +2 -1
- package/server/web.ts +9 -5
- package/server/workspace-env.ts +3 -2
- package/tsconfig.json +0 -1
- package/ui-components/accordion.tsx +71 -0
- package/ui-components/alert-dialog.tsx +165 -0
- package/ui-components/alert.tsx +68 -0
- package/ui-components/attachment.tsx +195 -0
- package/ui-components/avatar.tsx +90 -0
- package/ui-components/badge.tsx +49 -0
- package/ui-components/button-group.tsx +78 -0
- package/ui-components/button.tsx +55 -0
- package/ui-components/calendar.tsx +180 -0
- package/ui-components/card.tsx +84 -0
- package/ui-components/carousel.tsx +235 -0
- package/ui-components/chart.tsx +338 -0
- package/ui-components/checkbox.tsx +27 -0
- package/ui-components/collapsible.tsx +15 -0
- package/ui-components/combobox.tsx +265 -0
- package/ui-components/context-menu.tsx +244 -0
- package/ui-components/dialog.tsx +138 -0
- package/ui-components/docs/accordion.md +463 -0
- package/ui-components/docs/alert-dialog.md +481 -0
- package/ui-components/docs/alert.md +301 -0
- package/ui-components/docs/attachment.md +689 -0
- package/ui-components/docs/avatar.md +495 -0
- package/ui-components/docs/badge.md +258 -0
- package/ui-components/docs/button-group.md +879 -0
- package/ui-components/docs/button.md +26 -0
- package/ui-components/docs/calendar.md +862 -0
- package/ui-components/docs/card.md +265 -0
- package/ui-components/docs/carousel.md +627 -0
- package/ui-components/docs/chart.md +1256 -0
- package/ui-components/docs/checkbox.md +477 -0
- package/ui-components/docs/collapsible.md +446 -0
- package/ui-components/docs/combobox.md +1003 -0
- package/ui-components/docs/context-menu.md +860 -0
- package/ui-components/docs/data-table.md +1580 -0
- package/ui-components/docs/date-picker.md +614 -0
- package/ui-components/docs/dialog.md +414 -0
- package/ui-components/docs/drawer.md +51 -0
- package/ui-components/docs/dropdown-menu.md +1000 -0
- package/ui-components/docs/field.md +1192 -0
- package/ui-components/docs/hover-card.md +275 -0
- package/ui-components/docs/input-group.md +866 -0
- package/ui-components/docs/input.md +456 -0
- package/ui-components/docs/label.md +295 -0
- package/ui-components/docs/pagination.md +416 -0
- package/ui-components/docs/popover.md +348 -0
- package/ui-components/docs/progress.md +214 -0
- package/ui-components/docs/radio-group.md +389 -0
- package/ui-components/docs/resizable.md +265 -0
- package/ui-components/docs/select.md +616 -0
- package/ui-components/docs/separator.md +216 -0
- package/ui-components/docs/skeleton.md +205 -0
- package/ui-components/docs/slider.md +226 -0
- package/ui-components/docs/spinner.md +332 -0
- package/ui-components/docs/switch.md +236 -0
- package/ui-components/docs/table.md +551 -0
- package/ui-components/docs/tabs.md +379 -0
- package/ui-components/docs/textarea.md +187 -0
- package/ui-components/docs/toggle-group.md +370 -0
- package/ui-components/docs/toggle.md +91 -0
- package/ui-components/docs/tooltip.md +290 -0
- package/ui-components/drawer.tsx +213 -0
- package/ui-components/dropdown-menu.tsx +263 -0
- package/ui-components/field.tsx +224 -0
- package/ui-components/hover-card.tsx +46 -0
- package/ui-components/input-group.tsx +146 -0
- package/ui-components/input.tsx +20 -0
- package/ui-components/label.tsx +17 -0
- package/ui-components/pagination.tsx +124 -0
- package/ui-components/popover.tsx +81 -0
- package/ui-components/progress.tsx +63 -0
- package/ui-components/radio-group.tsx +37 -0
- package/ui-components/resizable.tsx +40 -0
- package/ui-components/scoped-portal.tsx +31 -0
- package/ui-components/select.tsx +195 -0
- package/ui-components/separator.tsx +18 -0
- package/ui-components/skeleton.tsx +15 -0
- package/ui-components/slider.tsx +75 -0
- package/ui-components/spinner.tsx +20 -0
- package/ui-components/switch.tsx +26 -0
- package/ui-components/table.tsx +86 -0
- package/ui-components/tabs.tsx +75 -0
- package/ui-components/textarea.tsx +17 -0
- package/ui-components/toggle-group.tsx +85 -0
- package/ui-components/toggle.tsx +42 -0
- package/ui-components/tooltip.tsx +61 -0
- package/ui-components/utils.ts +8 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +11 -20
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +4 -3
- package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
- package/dist/chunk-59zf0m6n.js +0 -1
- package/dist/chunk-bj3akjs2.js +0 -1
- package/dist/chunk-j2w2vak4.js +0 -546
- package/dist/chunk-k2r9c95m.js +0 -10
- package/dist/chunk-kmbxhgwv.js +0 -1
- package/dist/chunk-p1yqa71k.js +0 -83
- package/dist/chunk-r5xrenjy.css +0 -1
|
@@ -32,9 +32,10 @@ import {
|
|
|
32
32
|
toolTurnId
|
|
33
33
|
} from './adapter'
|
|
34
34
|
import { type AcpClient, type AcpSpawnSpec, getAcpClient } from './client'
|
|
35
|
+
import { cacheAcpModelState } from './model-state'
|
|
35
36
|
import { appendRunDuration, runDurations } from './run-durations'
|
|
36
37
|
import {
|
|
37
|
-
type
|
|
38
|
+
type AcpModelState,
|
|
38
39
|
type AcpNewSessionResult,
|
|
39
40
|
type AcpPromptBlock,
|
|
40
41
|
type ContentChunk,
|
|
@@ -71,11 +72,18 @@ export type AcpProviderConfig = {
|
|
|
71
72
|
noPromptModeId?: string
|
|
72
73
|
// Does the backend send images as base64 content blocks?
|
|
73
74
|
supportsImages?: boolean
|
|
74
|
-
// How the backend's model
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
//
|
|
78
|
-
|
|
75
|
+
// How the backend's model state becomes picker rows. ACP says nothing about
|
|
76
|
+
// how `name`/`description` are formatted, so a backend that packs extra
|
|
77
|
+
// structure into them (Hermes: the provider) unpacks it here. The full state
|
|
78
|
+
// also preserves a structured provider default such as `currentModelId`.
|
|
79
|
+
// Defaults to a straight catalog passthrough.
|
|
80
|
+
mapModels?: (state: AcpModelState) => Model[]
|
|
81
|
+
// Version stamp for the external inputs behind the model state (Hermes: the
|
|
82
|
+
// profile's config file mtimes). The cached catalog is reused while it
|
|
83
|
+
// matches and rediscovered when it changes, so a default edited outside moi
|
|
84
|
+
// reaches the picker without a throwaway session per snapshot. Omit for
|
|
85
|
+
// backends whose state is stable for the process lifetime.
|
|
86
|
+
modelStateFingerprint?: (ctx: AcpSpawnContext) => Promise<string | undefined>
|
|
79
87
|
}
|
|
80
88
|
|
|
81
89
|
type QueuedSend = { blocks: AcpPromptBlock[]; turnId: string }
|
|
@@ -607,10 +615,14 @@ export async function sendAcpMessage(
|
|
|
607
615
|
try {
|
|
608
616
|
if (input.isNew) {
|
|
609
617
|
const client = await getAcpClient(await config.spawn(input))
|
|
618
|
+
const fingerprint = await config.modelStateFingerprint?.(input)
|
|
610
619
|
const created = await client.rpc<AcpNewSessionResult>('session/new', {
|
|
611
620
|
cwd: input.workspacePath,
|
|
612
621
|
mcpServers: []
|
|
613
622
|
})
|
|
623
|
+
// A real session start carries the same model state the picker would
|
|
624
|
+
// otherwise open a throwaway session for — keep the cache current.
|
|
625
|
+
cacheAcpModelState(input.workspacePath, created.models, fingerprint)
|
|
614
626
|
const realId = created.sessionId
|
|
615
627
|
const model = input.model ?? created.models?.currentModelId
|
|
616
628
|
if (realId !== input.sessionId) {
|
|
@@ -5,16 +5,13 @@ display abstraction (`lib/format.ts`, implemented by `adapter.ts` here).
|
|
|
5
5
|
Originally research for the message-display abstraction; kept as the reference
|
|
6
6
|
spec for the CC adapter.
|
|
7
7
|
|
|
8
|
-
> **Status note.** The
|
|
9
|
-
>
|
|
10
|
-
>
|
|
11
|
-
>
|
|
12
|
-
> `
|
|
13
|
-
> `
|
|
14
|
-
>
|
|
15
|
-
> `adapter.ts`), and `MessageBlock.tsx` was replaced by
|
|
16
|
-
> `client/components/TurnView.tsx`. Read those sections as historical
|
|
17
|
-
> context, not as descriptions of today's code.
|
|
8
|
+
> **Status note.** The runtime section below describes the current lifecycle.
|
|
9
|
+
> The numbered sections preserve the original display-abstraction research;
|
|
10
|
+
> their wire examples are not an exhaustive list of today's SDK messages, and
|
|
11
|
+
> the migration proposed in §14 has shipped. Current display types live in
|
|
12
|
+
> `lib/format.ts`, mapping in `adapter.ts`, and rendering in
|
|
13
|
+
> `client/features/chat/TurnView.tsx`. Use the installed `sdk.d.ts` for current
|
|
14
|
+
> wire types.
|
|
18
15
|
|
|
19
16
|
Evidence drawn from:
|
|
20
17
|
|
|
@@ -38,6 +35,44 @@ and version-manager shims. There is no SDK bundled-executable fallback. If the
|
|
|
38
35
|
command is missing, setup and existing workspaces report:
|
|
39
36
|
`Run curl -fsSL https://claude.ai/install.sh | sh in your terminal to install Claude`.
|
|
40
37
|
|
|
38
|
+
**In-place updates.** Claude Code can replace its binary at the same path
|
|
39
|
+
while moi keeps running, changing which models are available.
|
|
40
|
+
|
|
41
|
+
- Every spawn resolves the executable afresh, so new sessions run the new
|
|
42
|
+
binary. A live session keeps the subprocess it started with until it is torn
|
|
43
|
+
down (idle TTL, eviction, env change).
|
|
44
|
+
- The model catalog (`models.ts`) is keyed by executable path and the first
|
|
45
|
+
line of `claude --version`. Each lookup probes that identity again. Changes
|
|
46
|
+
refetch the catalog; a failed version probe at the same path retains it.
|
|
47
|
+
- On a changed identity, `index.ts` marks existing subprocesses `staleCli`
|
|
48
|
+
(`retireCCSessionsOnCliChange`). Invalidation never interrupts work. Before
|
|
49
|
+
the next message, the dispatcher waits for the current turn and background
|
|
50
|
+
jobs to finish, replaces the subprocess, and resumes the same session from
|
|
51
|
+
disk. Replacement happens on demand.
|
|
52
|
+
- Pending messages and their model, effort, fast-mode, and streaming settings
|
|
53
|
+
stay in moi's per-session queue. Only one user message enters the SDK per
|
|
54
|
+
turn. Matching result IDs prevent an autonomous background turn from
|
|
55
|
+
releasing a waiting user prompt. When the CLI emits lifecycle events,
|
|
56
|
+
dispatch also waits for `idle`. The queue follows session ID renames and
|
|
57
|
+
survives planned subprocess replacement.
|
|
58
|
+
- Settings apply immediately before dispatch. Rejected setters fail the send.
|
|
59
|
+
Model uses `setModel`; effort and fast mode use `applyFlagSettings` together.
|
|
60
|
+
An absent effort or fast-mode value clears that flag with `null`, restoring
|
|
61
|
+
provider defaults.
|
|
62
|
+
- Background jobs retain their subprocess. Messages requiring a replacement
|
|
63
|
+
wait in moi until those jobs finish, including replacements for streaming
|
|
64
|
+
changes. `background_tasks_changed` replaces the complete task set, including
|
|
65
|
+
backgrounded subagents and ambient watchers. Task start/update/completion
|
|
66
|
+
events are a fallback only until the process emits its first snapshot; their
|
|
67
|
+
ordering relative to snapshots is unspecified. A new process starts with an
|
|
68
|
+
empty set and resets that fallback. Background work alone does not make the
|
|
69
|
+
chat busy.
|
|
70
|
+
- Stop cancels queued messages and waits for interrupt acknowledgement and
|
|
71
|
+
turn completion. An unexpected process exit rejects pending sends.
|
|
72
|
+
- The picker gets the new lineup on the client's next `/agent` refetch (window
|
|
73
|
+
focus, reconnect). `moi status` prints the version the catalog was probed
|
|
74
|
+
for next to the executable path.
|
|
75
|
+
|
|
41
76
|
---
|
|
42
77
|
|
|
43
78
|
## 1. Three layers
|
|
@@ -55,7 +90,7 @@ Two filters between L1 and L2 are responsible for everything the UI currently ca
|
|
|
55
90
|
|
|
56
91
|
---
|
|
57
92
|
|
|
58
|
-
## 2. Layer 1 —
|
|
93
|
+
## 2. Layer 1 — Recorded `SDKMessage` variants
|
|
59
94
|
|
|
60
95
|
Discriminated primarily by `type`, then `subtype` for `'system'` and `'result'`.
|
|
61
96
|
|
|
@@ -283,7 +318,7 @@ CLOSED have since been handled; see adapter.ts / session.ts):
|
|
|
283
318
|
- **MCP tool calls proper** (`mcp_tool_use` / `mcp_tool_result` blocks) — dropped. Regular `Task`/`Bash` MCP tools happen to survive because they wear the plain `tool_use` shape.
|
|
284
319
|
- **Streaming** — CLOSED: `stream_event` drives live token previews (`preview` frames) when the client opts into streaming.
|
|
285
320
|
- **Session lifecycle signals** — partially CLOSED: `system/init` feeds the session snapshot; `system/session_state_changed` mirrors into `SessionActivity` (note: current CLIs don't emit it in streaming-input mode — `result` is the everyday turn-over fallback); `requires-action` reaches the wire but has no UI yet. `system/status` (`requesting`/`compacting`) still dropped.
|
|
286
|
-
- **Sub-agent nesting** — CLOSED: `task_started`/`task_progress`/`task_notification` build nested subagent records; `
|
|
321
|
+
- **Sub-agent nesting** — CLOSED: `task_started`/`task_progress`/`task_notification` build nested subagent records; `background_tasks_changed` snapshots track live background tasks for the idle-eviction keep-alive (session.ts `bgTasks`), with task events as the fallback for older CLIs.
|
|
287
322
|
- **Hooks / rate limits / api_retry** — CLOSED: surfaced as notices.
|
|
288
323
|
- **MessageBlock switch exhaustiveness** — the UI layer this referred to (`MessageBlock.tsx`) no longer exists; turns render via `TurnView`/`ToolCallGroup`.
|
|
289
324
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Include the version in CLI identity: auto-updates can replace the binary
|
|
2
|
+
// without changing its path.
|
|
3
|
+
|
|
4
|
+
export type ClaudeCli = {
|
|
5
|
+
executable: string
|
|
6
|
+
// First line of `claude --version` (e.g. `2.1.263 (Claude Code)`), or null
|
|
7
|
+
// when the probe failed or timed out.
|
|
8
|
+
version: string | null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const VERSION_PROBE_TIMEOUT_MS = 5_000
|
|
12
|
+
|
|
13
|
+
// Keep the reported line intact for identity comparisons and status output.
|
|
14
|
+
export function parseClaudeVersion(output: string): string | null {
|
|
15
|
+
const line = output.split('\n').find(l => l.trim().length > 0)
|
|
16
|
+
return line ? line.trim() : null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function claudeCliKey(cli: ClaudeCli): string {
|
|
20
|
+
return `${cli.executable}\n${cli.version ?? '?'}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Probe failures yield an unknown version so callers can retain cached data.
|
|
24
|
+
export async function probeClaudeCli(executable: string): Promise<ClaudeCli> {
|
|
25
|
+
let timeout: ReturnType<typeof setTimeout> | undefined
|
|
26
|
+
try {
|
|
27
|
+
const proc = Bun.spawn([executable, '--version'], {
|
|
28
|
+
stdin: 'ignore',
|
|
29
|
+
stdout: 'pipe',
|
|
30
|
+
stderr: 'ignore'
|
|
31
|
+
})
|
|
32
|
+
timeout = setTimeout(() => proc.kill(), VERSION_PROBE_TIMEOUT_MS)
|
|
33
|
+
const [output, exitCode] = await Promise.all([new Response(proc.stdout).text(), proc.exited])
|
|
34
|
+
return { executable, version: exitCode === 0 ? parseClaudeVersion(output) : null }
|
|
35
|
+
} catch {
|
|
36
|
+
return { executable, version: null }
|
|
37
|
+
} finally {
|
|
38
|
+
clearTimeout(timeout)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -9,7 +9,7 @@ import { findHarnessExecutable, pathHarnessAvailability } from '../executable'
|
|
|
9
9
|
import { getClaudeAuthReadiness, startClaudeLogin } from './auth'
|
|
10
10
|
import { isLinkedGitWorktree } from './git-worktree'
|
|
11
11
|
import { getMcpStatus } from './mcp'
|
|
12
|
-
import { getClaudeModels } from './models'
|
|
12
|
+
import { getClaudeModels, lastProbedClaudeCli, onClaudeCliChanged } from './models'
|
|
13
13
|
import {
|
|
14
14
|
SESSION_LIMITS,
|
|
15
15
|
getCCDebugSnapshot,
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
interruptCCSession,
|
|
18
18
|
killAllCCSessions,
|
|
19
19
|
restartWorkspaceSessions,
|
|
20
|
+
retireCCSessionsOnCliChange,
|
|
20
21
|
sendCCMessage
|
|
21
22
|
} from './session'
|
|
22
23
|
import {
|
|
@@ -73,13 +74,17 @@ async function discoverWorkspaces(
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
// Keep future sends on the CLI version that supplied the model catalog.
|
|
78
|
+
// Active turns and background work finish before the dispatcher replaces it.
|
|
79
|
+
onClaudeCliChanged(() => retireCCSessionsOnCliChange())
|
|
80
|
+
|
|
76
81
|
export const claudeCodeHarness: Harness = {
|
|
77
82
|
id: 'claude-code',
|
|
78
83
|
capabilities: {
|
|
79
84
|
supportsStreaming: true,
|
|
80
85
|
imagesInline: 'base64',
|
|
81
86
|
liveModelSwitch: true,
|
|
82
|
-
liveEffortSwitch:
|
|
87
|
+
liveEffortSwitch: true,
|
|
83
88
|
nativeUserEcho: false // streaming-input never echoes; the server synthesizes the turn
|
|
84
89
|
},
|
|
85
90
|
|
|
@@ -111,7 +116,8 @@ export const claudeCodeHarness: Harness = {
|
|
|
111
116
|
const cc = getCCDebugSnapshot()
|
|
112
117
|
const busy = cc.sessions.filter(s => s.activity !== 'idle').length
|
|
113
118
|
const lines = [
|
|
114
|
-
`claude executable ${findHarnessExecutable('claude-code') ?? '(not found)'}
|
|
119
|
+
`claude executable ${findHarnessExecutable('claude-code') ?? '(not found)'}` +
|
|
120
|
+
` (${lastProbedClaudeCli()?.version ?? 'version not probed yet'})`,
|
|
115
121
|
`live CC sessions ${cc.sessions.length}/${SESSION_LIMITS.maxLive} ` +
|
|
116
122
|
`(${busy} busy, ${cc.sessions.length - busy} idle, ${cc.aliases} alias${cc.aliases === 1 ? '' : 'es'}, ` +
|
|
117
123
|
`idle TTL ${fmtDuration(SESSION_LIMITS.idleTtlMs)})`
|
|
@@ -146,8 +152,8 @@ export const claudeCodeHarness: Harness = {
|
|
|
146
152
|
`lastActivity=${fmtAgo(s.lastActivityAt, now)}`
|
|
147
153
|
]
|
|
148
154
|
if (s.bgTasks > 0) bits.push(`bgTasks=${s.bgTasks}`)
|
|
149
|
-
if (s.
|
|
150
|
-
if (s.
|
|
155
|
+
if (s.queuedMessages > 0) bits.push(`queued=${s.queuedMessages}`)
|
|
156
|
+
if (s.staleCli) bits.push('CLI update pending')
|
|
151
157
|
if (s.activity === 'idle' && !s.hasIdleTimer) bits.push('(no idle timer)')
|
|
152
158
|
let line = ' ' + bits.join(' ')
|
|
153
159
|
if (s.lastUserText) line += `\n last: ${JSON.stringify(s.lastUserText)}`
|
|
@@ -4,20 +4,15 @@ import type { ModelInfo } from '@anthropic-ai/claude-agent-sdk'
|
|
|
4
4
|
import type { Model } from '@/lib/types'
|
|
5
5
|
|
|
6
6
|
import { requireHarnessExecutable } from '../executable'
|
|
7
|
+
import { type ClaudeCli, claudeCliKey, probeClaudeCli } from './cli'
|
|
7
8
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
// backend for the model list — spins up a throwaway `query()` and reads metadata.
|
|
11
|
-
|
|
12
|
-
// Claude's available models come from the account/CLI, not the workspace, so
|
|
13
|
-
// the list is identical everywhere. We still need a `cwd` to spin up a probe
|
|
14
|
-
// query, but cache the result process-wide.
|
|
15
|
-
async function fetchClaudeModels(cwd: string): Promise<ModelInfo[]> {
|
|
9
|
+
// The metadata query needs a cwd; its catalog is cached across workspaces.
|
|
10
|
+
async function fetchClaudeModels(cwd: string, executable: string): Promise<ModelInfo[]> {
|
|
16
11
|
const q = query({
|
|
17
12
|
prompt: '',
|
|
18
13
|
options: {
|
|
19
14
|
cwd,
|
|
20
|
-
pathToClaudeCodeExecutable:
|
|
15
|
+
pathToClaudeCodeExecutable: executable,
|
|
21
16
|
persistSession: false,
|
|
22
17
|
settingSources: ['user', 'project'],
|
|
23
18
|
env: { ...process.env, CLAUDECODE: undefined }
|
|
@@ -25,24 +20,81 @@ async function fetchClaudeModels(cwd: string): Promise<ModelInfo[]> {
|
|
|
25
20
|
})
|
|
26
21
|
const models = await q.supportedModels()
|
|
27
22
|
await q.close()
|
|
28
|
-
// Raw SDK shape, passed through to the client as-is.
|
|
29
23
|
return models
|
|
30
24
|
}
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
export type ClaudeCliChangeListener = (next: ClaudeCli, previous: ClaudeCli) => void
|
|
27
|
+
|
|
28
|
+
export type ClaudeCatalogOptions = {
|
|
29
|
+
probe: (executable: string) => Promise<ClaudeCli>
|
|
30
|
+
fetch: (cwd: string, executable: string) => Promise<ModelInfo[]>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type CatalogEntry = {
|
|
34
|
+
key: string
|
|
35
|
+
cli: ClaudeCli
|
|
36
|
+
models: Promise<ModelInfo[]>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Recheck CLI identity on each lookup. Callers share the model-fetch promise
|
|
40
|
+
// until the identity changes; failed fetches are dropped so they can be retried.
|
|
41
|
+
export function createClaudeCatalog(options: ClaudeCatalogOptions) {
|
|
42
|
+
let entry: CatalogEntry | null = null
|
|
43
|
+
const listeners = new Set<ClaudeCliChangeListener>()
|
|
35
44
|
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
claudeModelsPromise = null
|
|
45
|
+
function store(cli: ClaudeCli, cwd: string): Promise<ModelInfo[]> {
|
|
46
|
+
const models = options.fetch(cwd, cli.executable).catch(err => {
|
|
47
|
+
if (entry?.models === models) entry = null
|
|
40
48
|
throw err
|
|
41
49
|
})
|
|
50
|
+
entry = { key: claudeCliKey(cli), cli, models }
|
|
51
|
+
return models
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function models(cwd: string, executable: string): Promise<ModelInfo[]> {
|
|
55
|
+
const cli = await options.probe(executable)
|
|
56
|
+
const current = entry
|
|
57
|
+
if (current) {
|
|
58
|
+
if (current.key === claudeCliKey(cli)) return current.models
|
|
59
|
+
// A failed version probe says nothing about the CLI. Keep serving the
|
|
60
|
+
// catalog we have instead of re-spawning a probe query per request.
|
|
61
|
+
if (cli.version === null && current.cli.executable === executable) return current.models
|
|
62
|
+
}
|
|
63
|
+
const next = store(cli, cwd)
|
|
64
|
+
if (current) {
|
|
65
|
+
console.log(
|
|
66
|
+
`[claude-code] claude changed (${describe(current.cli)} → ${describe(cli)}); refreshing the model catalog`
|
|
67
|
+
)
|
|
68
|
+
for (const listener of listeners) listener(cli, current.cli)
|
|
69
|
+
}
|
|
70
|
+
return next
|
|
42
71
|
}
|
|
43
|
-
|
|
72
|
+
|
|
73
|
+
// Initial discovery is not a CLI change.
|
|
74
|
+
function onCliChanged(listener: ClaudeCliChangeListener): () => void {
|
|
75
|
+
listeners.add(listener)
|
|
76
|
+
return () => {
|
|
77
|
+
listeners.delete(listener)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Cached identity for diagnostics; model lookups still need a fresh probe.
|
|
82
|
+
function current(): ClaudeCli | undefined {
|
|
83
|
+
return entry?.cli
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return { models, onCliChanged, current }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function describe(cli: ClaudeCli): string {
|
|
90
|
+
return `${cli.version ?? 'unknown version'} at ${cli.executable}`
|
|
44
91
|
}
|
|
45
92
|
|
|
93
|
+
const catalog = createClaudeCatalog({ probe: probeClaudeCli, fetch: fetchClaudeModels })
|
|
94
|
+
|
|
95
|
+
export const onClaudeCliChanged = catalog.onCliChanged
|
|
96
|
+
export const lastProbedClaudeCli = catalog.current
|
|
97
|
+
|
|
46
98
|
export function withClaudeFastModeDefault(
|
|
47
99
|
models: readonly ModelInfo[],
|
|
48
100
|
defaultFastMode: boolean
|
|
@@ -53,8 +105,9 @@ export function withClaudeFastModeDefault(
|
|
|
53
105
|
}
|
|
54
106
|
|
|
55
107
|
export async function getClaudeModels(cwd: string): Promise<Model[]> {
|
|
108
|
+
const executable = requireHarnessExecutable('claude-code')
|
|
56
109
|
const [models, settings] = await Promise.all([
|
|
57
|
-
|
|
110
|
+
catalog.models(cwd, executable),
|
|
58
111
|
resolveSettings({ cwd, settingSources: ['user', 'project'] })
|
|
59
112
|
])
|
|
60
113
|
const defaultFastMode =
|