moi-computer 0.8.0 → 0.8.1-next.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/client/api/workspace-keys.ts +1 -2
- package/client/app/AppRouter.tsx +10 -3
- package/client/app/routes/HomeRoute.tsx +1 -1
- package/client/app/shell/SidebarLayout.tsx +2 -14
- package/client/components/shared/Composer.tsx +20 -7
- package/client/components/shared/PanelHeader.tsx +8 -1
- package/client/components/ui/button.tsx +3 -3
- package/client/components/ui/dialog.tsx +1 -1
- package/client/components/ui/dropdown-menu.tsx +2 -2
- package/client/components/ui/hover-card.tsx +1 -1
- package/client/components/ui/popover.tsx +1 -1
- package/client/components/ui/resizable.tsx +40 -0
- package/client/features/chat/ChatEmptyState.tsx +9 -11
- package/client/features/chat/ChatPanel.tsx +76 -48
- package/client/features/chat/ChatPopup.tsx +16 -2
- package/client/features/chat/ChatPromptBubbles.tsx +6 -8
- package/client/features/chat/ChatSelector.tsx +24 -7
- package/client/features/chat/ModelPicker.tsx +5 -4
- package/client/features/chat/TurnView.tsx +108 -13
- package/client/features/chat/api.ts +1 -18
- package/client/features/chat/chat-send.ts +2 -2
- package/client/features/chat/{ChatComposer.tsx → composer/ChatComposer.tsx} +6 -5
- package/client/features/chat/composer/banners/ChatErrorBanner.tsx +28 -0
- package/client/features/chat/composer/banners/ComposerBanner.tsx +30 -0
- package/client/features/chat/composer/banners/WorkspaceAgentAvailabilityBanner.tsx +91 -0
- package/client/features/{workspace → chat/composer/banners}/WorkspaceSkillUpdateBanner.tsx +9 -7
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +74 -0
- package/client/features/{workspace → chat/composer}/useWorkspaceSkillUpdates.ts +1 -1
- package/client/features/chat/group-turns.ts +46 -28
- package/client/features/chat/interleave-notices.ts +84 -0
- package/client/features/chat/model-order.ts +9 -3
- package/client/features/chat/tool-group/TimelineRow.tsx +23 -11
- package/client/features/chat/tool-group/ToolCallGroup.tsx +38 -3
- package/client/features/chat/tool-group/format.ts +23 -7
- package/client/features/chat/useAppletChatMessage.ts +11 -16
- package/client/features/chat/useChat.ts +3 -7
- package/client/features/dev/ChatStatesPage.tsx +428 -0
- package/client/features/dev/DevIndexPage.tsx +52 -0
- package/client/features/dev/DevRoutes.tsx +6 -3
- package/client/features/dev/HarnessDebugPage.tsx +3 -3
- package/client/features/dev/chat-states-fixtures.ts +744 -0
- package/client/features/scratchpad/Scratchpad.tsx +4 -0
- package/client/features/scratchpad/scratch-session.ts +71 -0
- package/client/features/views/ViewBuilderTab.tsx +5 -4
- package/client/features/views/useViewBuilderActions.ts +2 -2
- package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -2
- package/client/features/workspace/WorkspaceScreen.tsx +128 -146
- package/client/features/workspace/WorkspaceSplitLayout.tsx +111 -0
- package/client/features/workspace/api.ts +33 -8
- package/client/features/workspace/useFitsSplitLayout.ts +31 -5
- package/client/index.css +1 -1
- package/client/lib/flags.ts +4 -3
- package/client/runtime/useWorkspaceEvents.ts +18 -1
- package/client/store/ui.ts +5 -1
- package/dist/{chunk-0pcdwjkp.js → chunk-2vaafjp4.js} +1 -1
- package/dist/{chunk-9y2zbzqz.js → chunk-35fq49qa.js} +1 -1
- package/dist/chunk-gny990qx.css +1 -0
- package/dist/chunk-gt7n06ef.js +1 -0
- package/dist/{chunk-r5ce5cdg.js → chunk-kkj86722.js} +75 -75
- package/dist/chunk-n7pga5x3.js +80 -0
- package/dist/chunk-xeyxk7ep.js +10 -0
- package/dist/{chunk-h9h8f176.js → chunk-xzx7c9hq.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/format.ts +17 -1
- package/lib/themes.ts +2 -2
- package/lib/types.ts +38 -8
- package/lib/workspace-layout.ts +2 -2
- package/package.json +2 -1
- package/server/agent.ts +199 -0
- package/server/api.ts +36 -17
- package/server/env-apply.ts +4 -0
- package/server/harness/README.md +28 -12
- package/server/harness/claude-code/auth.ts +54 -0
- package/server/harness/claude-code/index.ts +6 -1
- package/server/harness/codex/adapter.ts +9 -1
- package/server/harness/codex/auth.ts +50 -0
- package/server/harness/codex/index.ts +6 -1
- package/server/harness/codex/session.ts +33 -14
- package/server/harness/openclaw/NOTES.md +518 -187
- package/server/harness/openclaw/adapter.ts +125 -31
- package/server/harness/openclaw/compat.ts +99 -0
- package/server/harness/openclaw/cron-view.ts +78 -0
- package/server/harness/openclaw/discovery.ts +145 -52
- package/server/harness/openclaw/gateway.ts +224 -36
- package/server/harness/openclaw/index.ts +56 -21
- package/server/harness/openclaw/session.ts +971 -55
- package/server/harness/openclaw/strip.ts +87 -15
- package/server/harness/openclaw/thinking.ts +198 -0
- package/server/harness/types.ts +10 -5
- package/server/layout.ts +5 -2
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +19 -9
- package/client/features/dev/PixelPainter.tsx +0 -94
- package/client/features/dev/PlaygroundPage.tsx +0 -69
- package/dist/chunk-0k7brsms.js +0 -9
- package/dist/chunk-dfs36zgc.js +0 -1
- package/dist/chunk-dtwxpxbg.js +0 -51
- package/dist/chunk-ga7t9qsk.js +0 -2
- package/dist/chunk-tey2nq7c.js +0 -31
- package/dist/chunk-z73xpsa0.js +0 -50
- package/dist/chunk-zzgredta.css +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{Ic as t}from"/chunk-35fq49qa.js";if(typeof globalThis.structuredClone==="function")globalThis.structuredClone=globalThis.structuredClone.bind(globalThis);async function e(r){let{mount:a}=await import("/chunk-n7pga5x3.js");a(r)}globalThis.__init=e;
|
package/dist/index.html
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
|
-
<link rel="stylesheet" crossorigin href="/chunk-
|
|
24
|
+
<link rel="stylesheet" crossorigin href="/chunk-gny990qx.css"><script type="module" crossorigin src="/chunk-xzx7c9hq.js"></script></head>
|
|
25
25
|
<body>
|
|
26
26
|
<div id="root"></div>
|
|
27
27
|
|
package/lib/format.ts
CHANGED
|
@@ -51,7 +51,17 @@ export type Citation = { url?: string; title?: string; quote?: string }
|
|
|
51
51
|
|
|
52
52
|
export type Part =
|
|
53
53
|
| { type: 'text'; text: string; citations?: Citation[] }
|
|
54
|
-
|
|
54
|
+
// `redacted` marks reasoning the backend acknowledges but won't hand over:
|
|
55
|
+
// Anthropic's `redacted_thinking`, and the codex app-server's `Reasoning`
|
|
56
|
+
// item, which reports that the model thought (and for how long) but carries
|
|
57
|
+
// no text. Such a part has empty `text` and renders as a duration, not a body.
|
|
58
|
+
| {
|
|
59
|
+
type: 'reasoning'
|
|
60
|
+
text: string
|
|
61
|
+
redacted?: boolean
|
|
62
|
+
signature?: string
|
|
63
|
+
durationMs?: number
|
|
64
|
+
}
|
|
55
65
|
| { type: 'tool-call'; call: ToolCall }
|
|
56
66
|
| { type: 'file'; mediaType: string; url: string; filename?: string }
|
|
57
67
|
| { type: 'source-url'; url: string; title?: string; sourceId: string }
|
|
@@ -87,6 +97,9 @@ export type TurnMeta = {
|
|
|
87
97
|
model?: string
|
|
88
98
|
provider?: string
|
|
89
99
|
stopReason?: string
|
|
100
|
+
// Agent-run duration. Derived from transcript timestamps when available;
|
|
101
|
+
// Codex supplies its native duration because its transcript items lack them.
|
|
102
|
+
durationMs?: number
|
|
90
103
|
usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number; costUsd?: number }
|
|
91
104
|
// The API message id (`msg_...`) that produced this assistant turn, when the
|
|
92
105
|
// backend reports one. NOT the Turn `id`. Used to reconcile a live streaming
|
|
@@ -143,6 +156,9 @@ export type SystemNotice =
|
|
|
143
156
|
error?: string
|
|
144
157
|
}
|
|
145
158
|
| { id: string; kind: 'compact'; at: string; metadata?: unknown }
|
|
159
|
+
// Mid-session model switch observed on the backend (e.g. OpenClaw
|
|
160
|
+
// `sessions.patch { model }` — from moi's picker or any other client).
|
|
161
|
+
| { id: string; kind: 'model-change'; at: string; model: string; prev?: string }
|
|
146
162
|
| {
|
|
147
163
|
id: string
|
|
148
164
|
kind: 'hook'
|
package/lib/themes.ts
CHANGED
|
@@ -106,7 +106,7 @@ const THEME_COLOR_DERIVATIONS = {
|
|
|
106
106
|
primaryForeground: primary => foregroundForPrimary(primary),
|
|
107
107
|
background: () => 'color-mix(var(--primary) 3%, oklch(1 0 0) 97%)',
|
|
108
108
|
foreground: () => 'color-mix(var(--primary) 20%, oklch(0 0 0) 80%)',
|
|
109
|
-
muted: () => 'color-mix(var(--background)
|
|
109
|
+
muted: () => 'color-mix(var(--background) 96%, var(--foreground) 4%)',
|
|
110
110
|
mutedForeground: () => 'color-mix(var(--background) 50%, var(--foreground) 50%)',
|
|
111
111
|
accent: () => 'color-mix(var(--primary) 4%, var(--foreground) 4%)',
|
|
112
112
|
accentForeground: () => 'var(--foreground)',
|
|
@@ -117,7 +117,7 @@ const THEME_COLOR_DERIVATIONS = {
|
|
|
117
117
|
foreground: primary => foregroundForPrimary(primary),
|
|
118
118
|
primary: () => 'color-mix(var(--background) 3%, oklch(1 0 0) 97%)',
|
|
119
119
|
primaryForeground: () => 'color-mix(var(--background) 20%, oklch(0 0 0) 80%)',
|
|
120
|
-
muted: () => 'color-mix(var(--background)
|
|
120
|
+
muted: () => 'color-mix(var(--background) 97%, var(--foreground) 3%)',
|
|
121
121
|
mutedForeground: () => 'color-mix(var(--background) 50%, var(--foreground) 50%)',
|
|
122
122
|
accent: () => 'color-mix(var(--primary) 4%, var(--foreground) 4%)',
|
|
123
123
|
accentForeground: () => 'var(--foreground)',
|
package/lib/types.ts
CHANGED
|
@@ -256,6 +256,12 @@ export type SessionInfo = {
|
|
|
256
256
|
summary: string
|
|
257
257
|
lastModified: number
|
|
258
258
|
cwd?: string
|
|
259
|
+
// Where the conversation originates when the backend routes external
|
|
260
|
+
// channels into it (OpenClaw: telegram/irc/discord/…; absent = app chat).
|
|
261
|
+
origin?: { provider: string; label?: string }
|
|
262
|
+
// Session flavor beyond a plain chat: scheduled cron runs and spawned
|
|
263
|
+
// subagent sessions get a badge in the chat selector.
|
|
264
|
+
flavor?: 'chat' | 'cron' | 'subagent'
|
|
259
265
|
}
|
|
260
266
|
|
|
261
267
|
// Per-session agent settings, persisted server-side in one global file in moi's
|
|
@@ -392,11 +398,22 @@ export type WorkspaceSkillsUpdateFailure = WorkspaceSkillsStatus & {
|
|
|
392
398
|
error: string
|
|
393
399
|
}
|
|
394
400
|
|
|
395
|
-
//
|
|
396
|
-
//
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
401
|
+
// Setup checks only runtime availability. Workspace checks may also attach a
|
|
402
|
+
// login command, which makes the composer show its Sign in action.
|
|
403
|
+
export type HarnessAvailability =
|
|
404
|
+
| { available: true }
|
|
405
|
+
| { available: false; reason: string; loginCommand?: string }
|
|
406
|
+
|
|
407
|
+
// Codex returns a URL for the browser. Claude opens it from its own CLI.
|
|
408
|
+
export type HarnessLogin = { url?: string }
|
|
409
|
+
|
|
410
|
+
// The server-owned login ceremony, one per workspace. `pending` means a watch
|
|
411
|
+
// loop is re-probing the provider until the login lands or the deadline
|
|
412
|
+
// passes; transitions arrive as `agent:updated` events, so every tab shows
|
|
413
|
+
// the same ceremony without polling.
|
|
414
|
+
export type AgentLoginState =
|
|
415
|
+
| { state: 'pending'; url?: string }
|
|
416
|
+
| { state: 'failed'; reason: string }
|
|
400
417
|
|
|
401
418
|
// One MCP server's connection status, as surfaced by GET /api/workspaces/:id/mcp
|
|
402
419
|
// (a subset of the agent SDK's McpServerStatus — only what the UI renders).
|
|
@@ -613,6 +630,10 @@ export type Model = {
|
|
|
613
630
|
// the SDK under-types (e.g. 'xhigh'), so it stays string[].
|
|
614
631
|
supportsEffort?: boolean
|
|
615
632
|
supportedEffortLevels?: string[]
|
|
633
|
+
// Provider-resolved effort default when the user hasn't picked one (OpenClaw
|
|
634
|
+
// `thinkingDefault`, which differs per model — `low`/`medium`/`off`). Must be
|
|
635
|
+
// one of `supportedEffortLevels`.
|
|
636
|
+
defaultEffort?: string
|
|
616
637
|
supportsAdaptiveThinking?: boolean
|
|
617
638
|
supportsFastMode?: boolean
|
|
618
639
|
// Provider-resolved default when moi has no stored Fast-mode preference.
|
|
@@ -620,10 +641,19 @@ export type Model = {
|
|
|
620
641
|
supportsAutoMode?: boolean
|
|
621
642
|
}
|
|
622
643
|
|
|
623
|
-
// GET /api/workspaces/:id/
|
|
624
|
-
|
|
625
|
-
|
|
644
|
+
// GET /api/workspaces/:id/agent payload — everything the client needs to know
|
|
645
|
+
// about the workspace's agent backend in one request at workspace open.
|
|
646
|
+
// `models` and capabilities are stable per process; `availability` and `login`
|
|
647
|
+
// are the volatile part, kept fresh after load by `agent:updated` events
|
|
648
|
+
// instead of refetches.
|
|
649
|
+
export type WorkspaceAgent = {
|
|
650
|
+
// The agent backend that produced this snapshot — matches the workspace
|
|
651
|
+
// provider.
|
|
626
652
|
provider: WorkspaceType
|
|
653
|
+
// Runtime presence and provider auth state, from the server-side cache.
|
|
654
|
+
availability: HarnessAvailability
|
|
655
|
+
// Present while a login ceremony is in flight or after one failed.
|
|
656
|
+
login?: AgentLoginState
|
|
627
657
|
models: Model[]
|
|
628
658
|
// Whether this provider supports live token-by-token streaming (the picker
|
|
629
659
|
// shows the "Live typing" toggle only when true). Provider-wide, not per-model
|
package/lib/workspace-layout.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { WorkspaceLayout, WorkspaceTabsState } from './types'
|
|
2
2
|
|
|
3
3
|
export function createDefaultWorkspaceTabs(): WorkspaceTabsState {
|
|
4
|
-
return { open: ['agent', 'widgets'], active: 'agent' }
|
|
4
|
+
return { open: ['agent', 'widgets', 'scratchpad'], active: 'agent' }
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export function createDefaultWorkspaceLayout(): WorkspaceLayout {
|
|
8
8
|
return {
|
|
9
9
|
version: 1,
|
|
10
10
|
widgetGrid: [],
|
|
11
|
-
layoutMode: '
|
|
11
|
+
layoutMode: 'split',
|
|
12
12
|
tabs: createDefaultWorkspaceTabs()
|
|
13
13
|
}
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moi-computer",
|
|
3
|
-
"version": "0.8.0",
|
|
3
|
+
"version": "0.8.1-next.0",
|
|
4
4
|
"description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -89,6 +89,7 @@
|
|
|
89
89
|
"react-grid-layout": "^2.2.3",
|
|
90
90
|
"react-markdown": "^10.1.0",
|
|
91
91
|
"react-resizable": "^3.1.3",
|
|
92
|
+
"react-resizable-panels": "^4.12.2",
|
|
92
93
|
"rehype-highlight": "^7.0.2",
|
|
93
94
|
"remark-gfm": "^4.0.1",
|
|
94
95
|
"shadcn": "^4.13.0",
|
package/server/agent.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Server-owned agent state: the availability cache and the login ceremony.
|
|
2
|
+
//
|
|
3
|
+
// The client never polls for auth. `GET /api/workspaces/:id/agent` serves the
|
|
4
|
+
// snapshot from this store (one probe per workspace inside the TTL, however
|
|
5
|
+
// many tabs are open); `POST .../auth/login` starts — or joins — the single
|
|
6
|
+
// ceremony per workspace. While a ceremony is pending, a watch loop re-probes
|
|
7
|
+
// the provider until the login lands or the deadline passes, and every
|
|
8
|
+
// transition is pushed to all tabs as an `agent:updated` event on the
|
|
9
|
+
// workspace events socket.
|
|
10
|
+
import type {
|
|
11
|
+
AgentLoginState,
|
|
12
|
+
HarnessAvailability,
|
|
13
|
+
HarnessLogin,
|
|
14
|
+
WorkspaceEntry
|
|
15
|
+
} from '@/lib/types'
|
|
16
|
+
|
|
17
|
+
import { publishEvent } from './events'
|
|
18
|
+
import { harnessFor } from './harness/registry'
|
|
19
|
+
|
|
20
|
+
export type AgentUpdatedEvent = {
|
|
21
|
+
type: 'agent:updated'
|
|
22
|
+
workspaceId: string
|
|
23
|
+
availability: HarnessAvailability
|
|
24
|
+
login?: AgentLoginState
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Only the fields the probe/login provider calls actually read — lets callers
|
|
28
|
+
// that don't have a full registry entry on hand (e.g. a harness session
|
|
29
|
+
// reacting to a mid-conversation send failure) still trigger a refresh.
|
|
30
|
+
export type AgentWorkspace = Pick<WorkspaceEntry, 'id' | 'path' | 'type'>
|
|
31
|
+
|
|
32
|
+
export type AgentStoreOptions = {
|
|
33
|
+
probe: (ws: AgentWorkspace) => Promise<HarnessAvailability>
|
|
34
|
+
startLogin: (ws: AgentWorkspace) => Promise<HarnessLogin>
|
|
35
|
+
publish: (event: AgentUpdatedEvent) => void
|
|
36
|
+
availabilityTtlMs?: number
|
|
37
|
+
loginPollMs?: number
|
|
38
|
+
loginDeadlineMs?: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type LoginCeremony = {
|
|
42
|
+
state: AgentLoginState
|
|
43
|
+
// The in-flight provider call; joiners await it instead of starting a
|
|
44
|
+
// second flow. Cleared once settled.
|
|
45
|
+
starting?: Promise<HarnessLogin>
|
|
46
|
+
stop: () => void
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type AgentEntry = {
|
|
50
|
+
cached?: { value: HarnessAvailability; checkedAt: number }
|
|
51
|
+
// In-flight probe, shared by concurrent callers.
|
|
52
|
+
probe?: Promise<HarnessAvailability>
|
|
53
|
+
login?: LoginCeremony
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function createAgentStore(options: AgentStoreOptions) {
|
|
57
|
+
const ttlMs = options.availabilityTtlMs ?? 30_000
|
|
58
|
+
const pollMs = options.loginPollMs ?? 2_000
|
|
59
|
+
const deadlineMs = options.loginDeadlineMs ?? 3 * 60_000
|
|
60
|
+
const entries = new Map<string, AgentEntry>()
|
|
61
|
+
|
|
62
|
+
function entryFor(workspaceId: string): AgentEntry {
|
|
63
|
+
let entry = entries.get(workspaceId)
|
|
64
|
+
if (!entry) {
|
|
65
|
+
entry = {}
|
|
66
|
+
entries.set(workspaceId, entry)
|
|
67
|
+
}
|
|
68
|
+
return entry
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function publish(workspaceId: string, availability: HarnessAvailability) {
|
|
72
|
+
const login = entries.get(workspaceId)?.login?.state
|
|
73
|
+
options.publish({
|
|
74
|
+
type: 'agent:updated',
|
|
75
|
+
workspaceId,
|
|
76
|
+
availability,
|
|
77
|
+
...(login ? { login } : {})
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function probeFresh(ws: AgentWorkspace): Promise<HarnessAvailability> {
|
|
82
|
+
const entry = entryFor(ws.id)
|
|
83
|
+
if (!entry.probe) {
|
|
84
|
+
entry.probe = options.probe(ws).finally(() => {
|
|
85
|
+
entry.probe = undefined
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
const value = await entry.probe
|
|
89
|
+
entry.cached = { value, checkedAt: Date.now() }
|
|
90
|
+
return value
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function getAvailability(ws: AgentWorkspace): Promise<HarnessAvailability> {
|
|
94
|
+
const entry = entryFor(ws.id)
|
|
95
|
+
if (entry.cached && Date.now() - entry.cached.checkedAt < ttlMs) {
|
|
96
|
+
return entry.cached.value
|
|
97
|
+
}
|
|
98
|
+
return probeFresh(ws)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Bypass the TTL and push the result even if it's unchanged. For callers
|
|
102
|
+
// that suspect the cached snapshot is stale for a reason other than an env
|
|
103
|
+
// change (e.g. a send just failed, which can mean the provider was signed
|
|
104
|
+
// out from outside moi — a `codex logout` in a terminal, say).
|
|
105
|
+
async function refresh(ws: AgentWorkspace): Promise<HarnessAvailability> {
|
|
106
|
+
const value = await probeFresh(ws)
|
|
107
|
+
publish(ws.id, value)
|
|
108
|
+
return value
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getLogin(workspaceId: string): AgentLoginState | undefined {
|
|
112
|
+
return entries.get(workspaceId)?.login?.state
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Re-probe until the login lands or the deadline passes. One loop per
|
|
116
|
+
// ceremony; a replaced or completed ceremony stops its loop.
|
|
117
|
+
function watch(ws: AgentWorkspace, login: LoginCeremony) {
|
|
118
|
+
const deadline = Date.now() + deadlineMs
|
|
119
|
+
let stopped = false
|
|
120
|
+
let timer: ReturnType<typeof setTimeout>
|
|
121
|
+
login.stop = () => {
|
|
122
|
+
stopped = true
|
|
123
|
+
clearTimeout(timer)
|
|
124
|
+
}
|
|
125
|
+
const tick = async () => {
|
|
126
|
+
let value: HarnessAvailability
|
|
127
|
+
try {
|
|
128
|
+
value = await probeFresh(ws)
|
|
129
|
+
} catch {
|
|
130
|
+
value = { available: false, reason: 'Could not verify the login' }
|
|
131
|
+
}
|
|
132
|
+
if (stopped) return
|
|
133
|
+
const entry = entryFor(ws.id)
|
|
134
|
+
if (value.available) {
|
|
135
|
+
entry.login = undefined
|
|
136
|
+
publish(ws.id, value)
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
if (Date.now() >= deadline) {
|
|
140
|
+
// Keep the failed state so the composer can show it; the next
|
|
141
|
+
// startLogin replaces it.
|
|
142
|
+
login.state = { state: 'failed', reason: 'Sign-in did not complete. Try again' }
|
|
143
|
+
publish(ws.id, value)
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
timer = setTimeout(tick, pollMs)
|
|
147
|
+
timer.unref?.()
|
|
148
|
+
}
|
|
149
|
+
// Unref'd so a pending ceremony never keeps the process alive on its own.
|
|
150
|
+
timer = setTimeout(tick, pollMs)
|
|
151
|
+
timer.unref?.()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function startLogin(ws: AgentWorkspace): Promise<HarnessLogin> {
|
|
155
|
+
const entry = entryFor(ws.id)
|
|
156
|
+
// Join the in-flight ceremony instead of starting a second provider flow
|
|
157
|
+
// (two tabs, a remount, a double-click — all land here).
|
|
158
|
+
const current = entry.login
|
|
159
|
+
if (current?.starting) return current.starting
|
|
160
|
+
if (current?.state.state === 'pending') return { url: current.state.url }
|
|
161
|
+
|
|
162
|
+
current?.stop()
|
|
163
|
+
const starting = options.startLogin(ws)
|
|
164
|
+
const login: LoginCeremony = { state: { state: 'pending' }, starting, stop: () => {} }
|
|
165
|
+
entry.login = login
|
|
166
|
+
try {
|
|
167
|
+
const result = await starting
|
|
168
|
+
login.starting = undefined
|
|
169
|
+
login.state = { state: 'pending', ...(result.url ? { url: result.url } : {}) }
|
|
170
|
+
publish(ws.id, entry.cached?.value ?? { available: false, reason: 'Waiting for sign-in' })
|
|
171
|
+
watch(ws, login)
|
|
172
|
+
return result
|
|
173
|
+
} catch (err) {
|
|
174
|
+
entry.login = undefined
|
|
175
|
+
throw err
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Drop the cached snapshot so the next read re-probes (e.g. after an env
|
|
180
|
+
// change swaps credentials).
|
|
181
|
+
function invalidate(workspaceId: string) {
|
|
182
|
+
const entry = entries.get(workspaceId)
|
|
183
|
+
if (entry) entry.cached = undefined
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return { getAvailability, refresh, getLogin, startLogin, invalidate }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type AgentStore = ReturnType<typeof createAgentStore>
|
|
190
|
+
|
|
191
|
+
export const agentStore = createAgentStore({
|
|
192
|
+
probe: async ws => (await harnessFor(ws).availability?.(ws)) ?? { available: true },
|
|
193
|
+
startLogin: ws => {
|
|
194
|
+
const start = harnessFor(ws).startLogin
|
|
195
|
+
if (!start) throw new Error('This agent requires terminal sign-in')
|
|
196
|
+
return start(ws)
|
|
197
|
+
},
|
|
198
|
+
publish: publishEvent
|
|
199
|
+
})
|
package/server/api.ts
CHANGED
|
@@ -11,13 +11,14 @@ import type {
|
|
|
11
11
|
SessionInfo,
|
|
12
12
|
UploadInfo,
|
|
13
13
|
ViewBuilderInput,
|
|
14
|
+
WorkspaceAgent,
|
|
14
15
|
WorkspaceEntry,
|
|
15
|
-
WorkspaceModels,
|
|
16
16
|
WorkspaceType
|
|
17
17
|
} from '@/lib/types'
|
|
18
18
|
import type { MoiContext } from '@/lib/moi-context'
|
|
19
19
|
import { viewBuilderDirectives } from '@/lib/view-builder-directives'
|
|
20
20
|
|
|
21
|
+
import { agentStore } from './agent'
|
|
21
22
|
import { getAppSettings, pickAppSettingsPatch, saveAppSettings } from './app-settings'
|
|
22
23
|
import { appletForModule, recordAppletError } from './applet-log'
|
|
23
24
|
import { apiBaseFor, parseAppletTail, serveWorkspaceFile } from './applets'
|
|
@@ -516,7 +517,11 @@ one.post('/sessions/:sessionId/archive', async c => {
|
|
|
516
517
|
return c.body(null, 204)
|
|
517
518
|
} catch (error) {
|
|
518
519
|
console.error(`[api] archive chat failed for ${harness.id}`, error)
|
|
519
|
-
|
|
520
|
+
// Harnesses translate backend refusals into actionable one-liners (e.g.
|
|
521
|
+
// OpenClaw: main chat not archivable, gateway too old) — surface them.
|
|
522
|
+
const message =
|
|
523
|
+
error instanceof Error && error.message ? error.message : 'Couldn’t archive chat'
|
|
524
|
+
return c.text(message, 500)
|
|
520
525
|
}
|
|
521
526
|
})
|
|
522
527
|
|
|
@@ -638,12 +643,18 @@ one.put('/env', async c => {
|
|
|
638
643
|
return c.json(await getWorkspaceEnvView(ws.path, requiredEnvFor(ws.path)))
|
|
639
644
|
})
|
|
640
645
|
|
|
641
|
-
//
|
|
642
|
-
//
|
|
643
|
-
//
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
646
|
+
// Start a provider login ceremony. Codex returns a browser OAuth URL for the
|
|
647
|
+
// host to open; Claude launches its browser flow through the CLI itself.
|
|
648
|
+
// Idempotent per workspace: a second call joins the pending ceremony instead
|
|
649
|
+
// of starting another provider flow. Completion is pushed as `agent:updated`.
|
|
650
|
+
one.post('/auth/login', async c => {
|
|
651
|
+
const ws = c.get('ws')
|
|
652
|
+
if (!harnessFor(ws).startLogin) return c.text('This agent requires terminal sign-in', 409)
|
|
653
|
+
try {
|
|
654
|
+
return c.json(await agentStore.startLogin(ws))
|
|
655
|
+
} catch (err) {
|
|
656
|
+
return c.text(err instanceof Error ? err.message : 'Could not start sign-in', 500)
|
|
657
|
+
}
|
|
647
658
|
})
|
|
648
659
|
|
|
649
660
|
one.get('/skills', async c => {
|
|
@@ -657,25 +668,33 @@ one.post('/skills/update', async c => {
|
|
|
657
668
|
return c.json(result.status)
|
|
658
669
|
})
|
|
659
670
|
|
|
660
|
-
//
|
|
661
|
-
//
|
|
662
|
-
//
|
|
663
|
-
|
|
671
|
+
// The workspace's agent backend in one snapshot: provider, availability
|
|
672
|
+
// (runtime presence + auth, from the server-side cache), any in-flight login
|
|
673
|
+
// ceremony, the model catalog, and capabilities. One request at workspace
|
|
674
|
+
// open; the volatile parts stay fresh afterwards via `agent:updated` events,
|
|
675
|
+
// not refetches.
|
|
676
|
+
one.get('/agent', async c => {
|
|
664
677
|
const ws = c.get('ws')
|
|
665
678
|
const harness = harnessFor(ws)
|
|
666
679
|
// A backend that can't answer (codex CLI missing, gateway down) degrades to
|
|
667
680
|
// an empty catalog — the picker hides and chat surfaces the real problem via
|
|
668
681
|
// the availability banner, instead of this endpoint 500ing on page load.
|
|
669
|
-
const models = await
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
682
|
+
const [availability, models] = await Promise.all([
|
|
683
|
+
agentStore.getAvailability(ws),
|
|
684
|
+
harness.listModels(ws).catch(err => {
|
|
685
|
+
console.error(`[api] listModels failed for ${harness.id}`, err)
|
|
686
|
+
return []
|
|
687
|
+
})
|
|
688
|
+
])
|
|
689
|
+
const login = agentStore.getLogin(ws.id)
|
|
673
690
|
return c.json({
|
|
674
691
|
provider: harness.id,
|
|
692
|
+
availability,
|
|
693
|
+
...(login ? { login } : {}),
|
|
675
694
|
models,
|
|
676
695
|
supportsStreaming: harness.capabilities.supportsStreaming,
|
|
677
696
|
supportsArchiving: Boolean(harness.archiveSession)
|
|
678
|
-
} satisfies
|
|
697
|
+
} satisfies WorkspaceAgent)
|
|
679
698
|
})
|
|
680
699
|
|
|
681
700
|
// Workspace identity (name). GET returns the current {name, icon}; PUT a JSON
|
package/server/env-apply.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// relayed over the control port — the workspace's processes must be reaped and
|
|
4
4
|
// every connected client told to refetch. Both entry points call this so the
|
|
5
5
|
// side effects can never drift apart.
|
|
6
|
+
import { agentStore } from './agent'
|
|
6
7
|
import { publishEvent } from './events'
|
|
7
8
|
import { restartWorker } from './functions'
|
|
8
9
|
import { allHarnesses } from './harness/registry'
|
|
@@ -12,5 +13,8 @@ export function applyEnvChanged(workspace: { id: string; path: string }): void {
|
|
|
12
13
|
// down idle agent sessions (busy ones keep their snapshot until turn end).
|
|
13
14
|
restartWorker(workspace.path)
|
|
14
15
|
for (const h of allHarnesses()) h.onEnvChanged?.(workspace.path)
|
|
16
|
+
// Env can carry credentials (ANTHROPIC_API_KEY, provider config) — drop the
|
|
17
|
+
// cached availability so the next agent snapshot re-probes.
|
|
18
|
+
agentStore.invalidate(workspace.id)
|
|
15
19
|
publishEvent({ type: 'env:updated', workspaceId: workspace.id })
|
|
16
20
|
}
|
package/server/harness/README.md
CHANGED
|
@@ -118,13 +118,16 @@ Known gaps: runs with `bypassPermissions` only (no interactive approval
|
|
|
118
118
|
flow), and effort/streaming changes require a teardown-and-resume because the
|
|
119
119
|
SDK has no live setter for them.
|
|
120
120
|
|
|
121
|
-
**OpenClaw — shipped
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
**OpenClaw — shipped.** Chat over the local gateway's WebSocket JSON-RPC
|
|
122
|
+
(wire protocol 4 — the 2026.7.x and 2026.6.x lines; protocol-3 gateways are
|
|
123
|
+
detected and surfaced, see `openclaw/compat.ts`): sessions seeded cold from
|
|
124
|
+
`sessions.get` then updated from live `session.message` frames, token-delta
|
|
125
|
+
previews from `chat` frames, live tool state + output from `session.tool`
|
|
126
|
+
frames, model/effort applied per send via `sessions.patch`, abort via
|
|
127
|
+
`sessions.abort`, per-turn usage (tokens + cost) into `TurnMeta`, user-echo
|
|
128
|
+
rendezvous by `<runId>:user` idempotency key (text fallback), uploads
|
|
129
|
+
materialized to file paths. Known gaps: no rich vision blocks (string-only
|
|
130
|
+
`sessions.send`), and the gateway is the sole source of truth (no local
|
|
128
131
|
persistence; cold restarts re-seed).
|
|
129
132
|
|
|
130
133
|
**Codex — shipped, experimental.** Chat over `codex app-server` (stdio
|
|
@@ -148,6 +151,17 @@ approval flow (server→client approval requests are auto-accepted
|
|
|
148
151
|
defensively), and images ride inline as data URLs only (no `localImage` path
|
|
149
152
|
mode).
|
|
150
153
|
|
|
154
|
+
Workspace availability also checks provider authentication when a workspace is
|
|
155
|
+
given. Claude Code is probed with `claude auth status` under the effective
|
|
156
|
+
workspace env; `claude auth login` launches its browser sign-in from the composer. Codex
|
|
157
|
+
uses app-server `account/read` and returns a browser OAuth URL through
|
|
158
|
+
`account/login/start`. The server owns the recovery loop (`server/agent.ts`):
|
|
159
|
+
`GET /api/workspaces/:id/agent` serves a cached availability snapshot alongside
|
|
160
|
+
the model catalog, `POST .../auth/login` starts (or joins) the one ceremony per
|
|
161
|
+
workspace, and a server-side watch loop re-probes until the login lands or times
|
|
162
|
+
out, pushing `agent:updated` events to every tab. The composer renders that
|
|
163
|
+
state; it never polls.
|
|
164
|
+
|
|
151
165
|
## What a harness adapter must support
|
|
152
166
|
|
|
153
167
|
The checklist below is distilled from what the Claude Code integration
|
|
@@ -222,7 +236,9 @@ doubles as the evaluation rubric for new harnesses.
|
|
|
222
236
|
- Compaction trigger/observe.
|
|
223
237
|
- Queued-message semantics: does the backend queue natively or must the
|
|
224
238
|
server?
|
|
225
|
-
-
|
|
239
|
+
- Push health/auth status events from the backend itself (the server watch
|
|
240
|
+
loop still discovers login completion by re-probing; a provider callback
|
|
241
|
+
would let `agent:updated` fire without polling anywhere).
|
|
226
242
|
|
|
227
243
|
## Capability comparison
|
|
228
244
|
|
|
@@ -234,10 +250,10 @@ Legend: ✅ supported · ⚠️ partial/workaround · ❌ missing.
|
|
|
234
250
|
| Queue/steer mid-turn | ⚠️ queued next turn | ⚠️ | ✅ `turn/steer` into live turn |
|
|
235
251
|
| Resume | ✅ | ✅ | ✅ + fork |
|
|
236
252
|
| Interrupt | ✅ `interrupt()` | ✅ | ✅ `turn/interrupt` |
|
|
237
|
-
| List models | ✅ `supportedModels()` |
|
|
238
|
-
| Live model switch | ✅ `setModel()` |
|
|
239
|
-
| Live effort switch | ❌ rebuild |
|
|
240
|
-
| Token deltas | ✅ opt-in |
|
|
253
|
+
| List models | ✅ `supportedModels()` | ✅ `models.list` | ✅ `model/list` |
|
|
254
|
+
| Live model switch | ✅ `setModel()` | ✅ `sessions.patch` | ✅ per-turn override |
|
|
255
|
+
| Live effort switch | ❌ rebuild | ✅ `thinkingLevel` patch | ✅ per-turn |
|
|
256
|
+
| Token deltas | ✅ opt-in | ✅ `chat` frames | ✅ `item/*/delta` |
|
|
241
257
|
| Images in input | ✅ base64 blocks | ⚠️ materialize to path | ✅ data URL or path |
|
|
242
258
|
| Interactive approvals | ⚠️ (we bypass) | ✅ | ✅ server→client requests (we bypass) |
|
|
243
259
|
| Session list/history API | ✅ `listSessions()` + jsonl | ✅ `sessions.get` | ✅ `thread/list`/`read` |
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { HarnessAvailability, HarnessLogin } from '@/lib/types'
|
|
2
|
+
|
|
3
|
+
import { resolveWorkspaceEnv } from '../../workspace-env'
|
|
4
|
+
import { findHarnessExecutable } from '../executable'
|
|
5
|
+
|
|
6
|
+
function signedOut(reason: string): HarnessAvailability {
|
|
7
|
+
return {
|
|
8
|
+
available: false,
|
|
9
|
+
reason,
|
|
10
|
+
loginCommand: 'claude auth login'
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Claude Code 2.1.42+ exposes a stable JSON auth probe. Run it with the same
|
|
15
|
+
// workspace env as the actual Agent SDK subprocess so API-key and enterprise
|
|
16
|
+
// provider configuration are evaluated consistently with the eventual send.
|
|
17
|
+
export async function getClaudeAuthReadiness(workspacePath: string): Promise<HarnessAvailability> {
|
|
18
|
+
const executable = findHarnessExecutable('claude-code')
|
|
19
|
+
if (!executable) return signedOut('Claude is not installed')
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
|
|
23
|
+
const proc = Bun.spawn([executable, 'auth', 'status'], {
|
|
24
|
+
cwd: workspacePath,
|
|
25
|
+
env: { ...process.env, ...workspaceEnv },
|
|
26
|
+
stdin: 'ignore',
|
|
27
|
+
stdout: 'ignore',
|
|
28
|
+
stderr: 'ignore'
|
|
29
|
+
})
|
|
30
|
+
const timeout = setTimeout(() => proc.kill(), 5_000)
|
|
31
|
+
const exitCode = await proc.exited
|
|
32
|
+
clearTimeout(timeout)
|
|
33
|
+
return exitCode === 0
|
|
34
|
+
? { available: true }
|
|
35
|
+
: signedOut('Claude is signed out. Sign in to send messages')
|
|
36
|
+
} catch {
|
|
37
|
+
return signedOut('Could not verify the Claude login')
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function startClaudeLogin(workspacePath: string): Promise<HarnessLogin> {
|
|
42
|
+
const executable = findHarnessExecutable('claude-code')
|
|
43
|
+
if (!executable) throw new Error('Claude is not installed')
|
|
44
|
+
|
|
45
|
+
const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
|
|
46
|
+
Bun.spawn([executable, 'auth', 'login'], {
|
|
47
|
+
cwd: workspacePath,
|
|
48
|
+
env: { ...process.env, ...workspaceEnv },
|
|
49
|
+
stdin: 'ignore',
|
|
50
|
+
stdout: 'ignore',
|
|
51
|
+
stderr: 'ignore'
|
|
52
|
+
}).unref()
|
|
53
|
+
return {}
|
|
54
|
+
}
|
|
@@ -6,6 +6,7 @@ import type { McpServer } from '@/lib/types'
|
|
|
6
6
|
|
|
7
7
|
import type { DiscoveredWorkspaceCandidate, Harness } from '../types'
|
|
8
8
|
import { findHarnessExecutable, pathHarnessAvailability } from '../executable'
|
|
9
|
+
import { getClaudeAuthReadiness, startClaudeLogin } from './auth'
|
|
9
10
|
import { isLinkedGitWorktree } from './git-worktree'
|
|
10
11
|
import { getMcpStatus } from './mcp'
|
|
11
12
|
import { getClaudeModels } from './models'
|
|
@@ -96,7 +97,11 @@ export const claudeCodeHarness: Harness = {
|
|
|
96
97
|
// fields are ignored by the client) — pass it through unchanged.
|
|
97
98
|
mcpStatus: async ws => (await getMcpStatus(ws.path)) as unknown as McpServer[],
|
|
98
99
|
discoverWorkspaces,
|
|
99
|
-
availability: async
|
|
100
|
+
availability: async ws => {
|
|
101
|
+
const runtime = await pathHarnessAvailability('claude-code')
|
|
102
|
+
return runtime.available && ws ? getClaudeAuthReadiness(ws.path) : runtime
|
|
103
|
+
},
|
|
104
|
+
startLogin: ws => startClaudeLogin(ws.path),
|
|
100
105
|
|
|
101
106
|
onEnvChanged: workspacePath => restartWorkspaceSessions(workspacePath),
|
|
102
107
|
shutdown: () => killAllCCSessions(),
|