moi-computer 0.5.2-next.1 → 0.6.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/README.md +39 -0
- package/client/AGENTS.md +9 -0
- package/client/api/app-ui-keys.ts +4 -0
- package/client/api/workspace-keys.ts +2 -2
- package/client/app/routes/WorkspaceRoute.tsx +8 -28
- package/client/components/shared/Composer.tsx +3 -6
- package/client/components/shared/IconGhost.tsx +130 -0
- package/client/components/ui/dropdown-menu.tsx +1 -1
- package/client/components/ui/spinner.tsx +18 -0
- package/client/components/ui/toast.tsx +220 -0
- package/client/features/chat/ChatComposer.tsx +3 -2
- package/client/features/chat/ChatPanel.tsx +7 -6
- package/client/features/chat/ChatPopup.tsx +10 -4
- package/client/features/chat/ChatSelector.tsx +263 -48
- package/client/features/chat/ModelPicker.tsx +13 -18
- package/client/features/chat/api.ts +36 -9
- package/client/features/chat/chat-frames.ts +35 -6
- package/client/features/chat/chat-send.ts +25 -1
- package/client/features/chat/chat-store.ts +43 -18
- package/client/features/chat/useChat.ts +54 -52
- package/client/features/chat/useSelectedSession.ts +151 -0
- package/client/features/chat/useStickToBottom.ts +3 -3
- package/client/features/home/api.ts +0 -2
- package/client/features/scratchpad/ScratchpadControls.tsx +2 -2
- package/client/features/settings/WorkspaceSettings.tsx +6 -6
- package/client/features/views/ViewBuilderTab.tsx +3 -4
- package/client/features/views/useViewBuilderActions.ts +3 -1
- package/client/features/workspace/WorkspaceScreen.tsx +38 -17
- package/client/features/workspace/WorkspaceTabs.tsx +10 -1
- package/client/main.tsx +2 -0
- package/client/runtime/useWorkspaceEvents.ts +1 -0
- package/client/store/ui.ts +2 -2
- package/dist/{chunk-zs4mte79.js → chunk-0pcdwjkp.js} +1 -1
- package/dist/chunk-175bm057.js +27 -0
- package/dist/chunk-55sh4dty.js +2 -0
- package/dist/{chunk-tzz101ea.js → chunk-9y2zbzqz.js} +1 -1
- package/dist/{chunk-jvhvme3z.js → chunk-afgbg75t.js} +1 -1
- package/dist/chunk-agtetn7n.css +1 -0
- package/dist/chunk-dfs36zgc.js +1 -0
- package/dist/chunk-exj6hr30.js +9 -0
- package/dist/{chunk-bcrkdhwe.js → chunk-m11ckkxd.js} +1 -1
- package/dist/{chunk-kfw1qwqe.js → chunk-rxvx4ta9.js} +3 -3
- package/dist/{chunk-xwhya7kb.js → chunk-w3tnv51j.js} +1 -1
- package/dist/index.html +1 -1
- package/lib/attachment-note.ts +18 -0
- package/lib/chat-title.ts +6 -0
- package/lib/types.ts +24 -10
- package/package.json +1 -1
- package/server/agent-caller.ts +16 -0
- package/server/api.ts +90 -9
- package/server/app-settings.ts +1 -1
- package/server/cli.ts +628 -45
- package/server/control.ts +18 -1
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +6 -0
- package/server/harness/claude-code/adapter.ts +2 -2
- package/server/harness/claude-code/index.ts +7 -1
- package/server/harness/claude-code/session-title.ts +106 -0
- package/server/harness/claude-code/session.ts +107 -17
- package/server/harness/claude-code/sessions.ts +63 -4
- package/server/harness/codex/client.ts +33 -13
- package/server/harness/codex/index.ts +2 -0
- package/server/harness/codex/session-title.ts +149 -0
- package/server/harness/codex/session.ts +84 -11
- package/server/harness/openclaw/adapter.ts +4 -2
- package/server/harness/openclaw/discovery.ts +2 -0
- package/server/harness/openclaw/session.ts +15 -7
- package/server/harness/session-title.ts +96 -0
- package/server/harness/types.ts +2 -0
- package/server/selected-session.ts +132 -0
- package/server/service.ts +786 -0
- package/server/{thread-config.ts → session-config.ts} +57 -39
- package/server/status.ts +2 -0
- package/server/update.ts +141 -0
- package/server/version.ts +41 -0
- package/server/web.ts +17 -1
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +16 -26
- package/workspace/.claude/skills/moi-workspace/SKILL.md +8 -2
- package/dist/chunk-94m3q9ce.js +0 -1
- package/dist/chunk-k9dcnd73.js +0 -27
- package/dist/chunk-pk11vfzs.js +0 -9
- package/dist/chunk-r2bqaege.js +0 -2
- package/dist/chunk-y4g8j7mv.css +0 -1
package/server/control.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { isParamsRecord } from '@/lib/workspace-tabs'
|
|
|
6
6
|
|
|
7
7
|
import { clearAppletLog, getAppletLog, getAppletLogCount } from './applet-log'
|
|
8
8
|
import { serializeWorkspaceBundle } from './bundle-queue'
|
|
9
|
-
import { CONTROL_PORT } from './constants'
|
|
9
|
+
import { CONTROL_PORT, PORT } from './constants'
|
|
10
10
|
import { applyEnvChanged } from './env-apply'
|
|
11
11
|
import { callFunctionEphemeral, parseFunctionPath } from './functions'
|
|
12
12
|
import { processIcon } from './icon'
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
setBuilder
|
|
29
29
|
} from './view-builders'
|
|
30
30
|
import { getWorkspaceConfig, setWorkspaceConfig } from './workspace-config'
|
|
31
|
+
import { VERSION } from './version'
|
|
31
32
|
|
|
32
33
|
type ControlSocket = { send(data: string): void }
|
|
33
34
|
|
|
@@ -86,6 +87,22 @@ export const control = Bun.serve({
|
|
|
86
87
|
return
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
// Identity of the running server, for the CLI (`moi status`, `moi
|
|
91
|
+
// update`, `moi service`). VERSION is snapshotted at boot, so this
|
|
92
|
+
// reports the code actually running even after the install tree on
|
|
93
|
+
// disk was replaced by an update.
|
|
94
|
+
if (data.type === 'server:info') {
|
|
95
|
+
ws.send(
|
|
96
|
+
JSON.stringify({
|
|
97
|
+
version: VERSION,
|
|
98
|
+
pid: process.pid,
|
|
99
|
+
port: PORT,
|
|
100
|
+
service: !!process.env.MOI_SERVICE
|
|
101
|
+
})
|
|
102
|
+
)
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
89
106
|
if (data.type === 'bundle') {
|
|
90
107
|
// Resolve to the real workspace root (works from `.moi/` or any
|
|
91
108
|
// subdir; errors when outside every registered workspace) so a bundle
|
package/server/data-dir.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Single source of truth for the OS data dir holding moi's global state
|
|
2
|
-
// (workspaces.json, settings.json,
|
|
2
|
+
// (workspaces.json, settings.json, session-config.json, selected-sessions.json, …).
|
|
3
3
|
//
|
|
4
4
|
// MOI_DATA_DIR overrides it wholesale. This is the isolation seam for CLI
|
|
5
5
|
// e2e tests: env-paths only honors XDG_DATA_HOME on Linux, so on macOS a
|
package/server/harness/README.md
CHANGED
|
@@ -34,6 +34,8 @@ Socket-protocol notes the layers rely on (all defined in `lib/types.ts`):
|
|
|
34
34
|
|
|
35
35
|
- **`session_renamed`** — a new thread is created under the client's temporary
|
|
36
36
|
uuid, then rekeyed to the backend's real session/thread id.
|
|
37
|
+
- **`sessions_changed`** — a provider changed session-list metadata such as a
|
|
38
|
+
generated session title; clients refresh that workspace's session list.
|
|
37
39
|
- **Optimistic-id rendezvous** — the client sends `optimisticId` with each
|
|
38
40
|
chat; the user's bubble must upsert under that id. Backends differ: Codex
|
|
39
41
|
echoes it natively (`clientUserMessageId` → `clientId`), Claude Code never
|
|
@@ -69,6 +71,10 @@ server/harness/
|
|
|
69
71
|
```
|
|
70
72
|
|
|
71
73
|
- Nothing inside one harness folder imports from a sibling harness.
|
|
74
|
+
- Internal harness metadata and helpers use session naming, including
|
|
75
|
+
`sessionTitle`, `generateSessionTitle`, and `session-title.ts`. Chat naming is
|
|
76
|
+
for client and UI labels. Thread naming stays at provider wire and RPC
|
|
77
|
+
boundaries.
|
|
72
78
|
- Outside code imports only this folder's top level. Documented exceptions:
|
|
73
79
|
`cli.ts` (`moi openclaw init` provisioning) imports
|
|
74
80
|
`harness/openclaw/discovery.ts`; tests may import harness internals.
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
TurnOrigin
|
|
15
15
|
} from '@/lib/format'
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { isAttachmentOnlyPlaceholder, splitAttachmentNote } from '@/lib/attachment-note'
|
|
18
18
|
import { stripMoiContext } from '@/lib/moi-context'
|
|
19
19
|
|
|
20
20
|
// Loose SDK message shape — we don't pull in the full SDK type tree; the
|
|
@@ -532,7 +532,7 @@ export class ClaudeAdapter {
|
|
|
532
532
|
}
|
|
533
533
|
// An attachment-only message carries a synthesized placeholder
|
|
534
534
|
// prompt; the bubble should show just the attachments.
|
|
535
|
-
if (text
|
|
535
|
+
if (isAttachmentOnlyPlaceholder(text) && parts.some(p => p.type === 'file')) {
|
|
536
536
|
text = ''
|
|
537
537
|
}
|
|
538
538
|
}
|
|
@@ -18,7 +18,12 @@ import {
|
|
|
18
18
|
restartWorkspaceSessions,
|
|
19
19
|
sendCCMessage
|
|
20
20
|
} from './session'
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
archiveClaudeSession,
|
|
23
|
+
getSessionEvents,
|
|
24
|
+
getSessions,
|
|
25
|
+
getSessionWorkspacePreview
|
|
26
|
+
} from './sessions'
|
|
22
27
|
|
|
23
28
|
function fmtDuration(ms: number): string {
|
|
24
29
|
const s = Math.floor(ms / 1000)
|
|
@@ -79,6 +84,7 @@ export const claudeCodeHarness: Harness = {
|
|
|
79
84
|
|
|
80
85
|
sendMessage: input => sendCCMessage(input),
|
|
81
86
|
interrupt: (workspaceId, sessionId) => interruptCCSession(workspaceId, sessionId),
|
|
87
|
+
archiveSession: (ws, sessionId) => archiveClaudeSession(sessionId, ws.path),
|
|
82
88
|
activeSessions: () => getCCActiveSessions(),
|
|
83
89
|
|
|
84
90
|
listSessions: ws => getSessions(ws.path),
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { getSessionInfo, renameSession, type SDKSessionInfo } from '@anthropic-ai/claude-agent-sdk'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
SESSION_TITLE_SCHEMA,
|
|
5
|
+
SESSION_TITLE_SYSTEM_PROMPT,
|
|
6
|
+
SESSION_TITLE_TIMEOUT_MS,
|
|
7
|
+
createSessionTitleTempDir,
|
|
8
|
+
parseGeneratedSessionTitle,
|
|
9
|
+
removeSessionTitleTempDir,
|
|
10
|
+
runSessionTitleCommand
|
|
11
|
+
} from '../session-title'
|
|
12
|
+
import { requireHarnessExecutable } from '../executable'
|
|
13
|
+
|
|
14
|
+
export function claudeSessionTitleCommand(executable: string): string[] {
|
|
15
|
+
return [
|
|
16
|
+
executable,
|
|
17
|
+
'-p',
|
|
18
|
+
'--model',
|
|
19
|
+
'haiku',
|
|
20
|
+
'--effort',
|
|
21
|
+
'low',
|
|
22
|
+
'--max-turns',
|
|
23
|
+
'1',
|
|
24
|
+
'--tools',
|
|
25
|
+
'',
|
|
26
|
+
'--safe-mode',
|
|
27
|
+
'--no-session-persistence',
|
|
28
|
+
'--disable-slash-commands',
|
|
29
|
+
'--strict-mcp-config',
|
|
30
|
+
'--setting-sources',
|
|
31
|
+
'',
|
|
32
|
+
'--permission-mode',
|
|
33
|
+
'dontAsk',
|
|
34
|
+
'--system-prompt',
|
|
35
|
+
SESSION_TITLE_SYSTEM_PROMPT,
|
|
36
|
+
'--output-format',
|
|
37
|
+
'json',
|
|
38
|
+
'--json-schema',
|
|
39
|
+
JSON.stringify(SESSION_TITLE_SCHEMA)
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function parseClaudeSessionTitleOutput(value: string): string | null {
|
|
44
|
+
try {
|
|
45
|
+
const result = JSON.parse(value) as { structured_output?: unknown }
|
|
46
|
+
return parseGeneratedSessionTitle(result.structured_output)
|
|
47
|
+
} catch {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function generateClaudeSessionTitle(input: {
|
|
53
|
+
source: string
|
|
54
|
+
abortController: AbortController
|
|
55
|
+
timeoutMs?: number
|
|
56
|
+
}): Promise<string | null> {
|
|
57
|
+
if (!input.source || input.abortController.signal.aborted) return null
|
|
58
|
+
const timer = setTimeout(
|
|
59
|
+
() => input.abortController.abort(),
|
|
60
|
+
input.timeoutMs ?? SESSION_TITLE_TIMEOUT_MS
|
|
61
|
+
)
|
|
62
|
+
let tempDir: string | undefined
|
|
63
|
+
try {
|
|
64
|
+
tempDir = await createSessionTitleTempDir()
|
|
65
|
+
const output = await runSessionTitleCommand({
|
|
66
|
+
command: claudeSessionTitleCommand(requireHarnessExecutable('claude-code')),
|
|
67
|
+
cwd: tempDir,
|
|
68
|
+
stdin: JSON.stringify({ sessionTitleSource: input.source }),
|
|
69
|
+
signal: input.abortController.signal,
|
|
70
|
+
env: { ...process.env, CLAUDECODE: undefined, DISABLE_AUTOUPDATER: '1' }
|
|
71
|
+
})
|
|
72
|
+
return output ? parseClaudeSessionTitleOutput(output) : null
|
|
73
|
+
} finally {
|
|
74
|
+
clearTimeout(timer)
|
|
75
|
+
if (tempDir) await removeSessionTitleTempDir(tempDir).catch(() => {})
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type ClaudeSessionTitleRenameTransport = {
|
|
80
|
+
getSessionInfo: (sessionId: string, workspacePath: string) => Promise<SDKSessionInfo | undefined>
|
|
81
|
+
renameSession: (sessionId: string, title: string, workspacePath: string) => Promise<void>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const defaultSessionTitleRenameTransport: ClaudeSessionTitleRenameTransport = {
|
|
85
|
+
getSessionInfo: (sessionId, workspacePath) => getSessionInfo(sessionId, { dir: workspacePath }),
|
|
86
|
+
renameSession: (sessionId, title, workspacePath) =>
|
|
87
|
+
renameSession(sessionId, title, { dir: workspacePath })
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function renameClaudeSessionIfUnchanged(
|
|
91
|
+
input: {
|
|
92
|
+
sessionId: string
|
|
93
|
+
workspacePath: string
|
|
94
|
+
title: string
|
|
95
|
+
isCurrent?: () => boolean
|
|
96
|
+
},
|
|
97
|
+
transport: ClaudeSessionTitleRenameTransport = defaultSessionTitleRenameTransport
|
|
98
|
+
): Promise<boolean> {
|
|
99
|
+
const info = await transport.getSessionInfo(input.sessionId, input.workspacePath)
|
|
100
|
+
if (!info || info.customTitle || !info.firstPrompt || info.summary !== info.firstPrompt) {
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
if (input.isCurrent && !input.isCurrent()) return false
|
|
104
|
+
await transport.renameSession(input.sessionId, input.title, input.workspacePath)
|
|
105
|
+
return true
|
|
106
|
+
}
|
|
@@ -18,8 +18,11 @@ import {
|
|
|
18
18
|
query
|
|
19
19
|
} from '@anthropic-ai/claude-agent-sdk'
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import { appendAttachmentNote, attachmentOnlyPlaceholder } from '@/lib/attachment-note'
|
|
22
|
+
import { buildSessionTitleSource } from '../session-title'
|
|
22
23
|
import { ClaudeAdapter } from './adapter'
|
|
24
|
+
import { claudeSessionExists } from './sessions'
|
|
25
|
+
import { generateClaudeSessionTitle, renameClaudeSessionIfUnchanged } from './session-title'
|
|
23
26
|
import type { Part } from '@/lib/format'
|
|
24
27
|
import type { SessionActivity } from '@/lib/types'
|
|
25
28
|
import { type MoiContext, moiContextSystemReminder, renderMoiContext } from '@/lib/moi-context'
|
|
@@ -27,7 +30,8 @@ import { type MoiContext, moiContextSystemReminder, renderMoiContext } from '@/l
|
|
|
27
30
|
import { debug } from '../../debug'
|
|
28
31
|
import { tapWire } from '../debug'
|
|
29
32
|
import { broadcast } from '../../state'
|
|
30
|
-
import {
|
|
33
|
+
import { renameSelectedSession } from '../../selected-session'
|
|
34
|
+
import { hasSessionConfig, renameSessionConfig, saveSessionConfig } from '../../session-config'
|
|
31
35
|
import { type StoredUpload, resolveUploads, uploadToDisplayPart } from '../../uploads'
|
|
32
36
|
import {
|
|
33
37
|
markViewBuilderBuildingBySession,
|
|
@@ -80,11 +84,11 @@ export function buildUserMessage(
|
|
|
80
84
|
|
|
81
85
|
const files = uploads.filter(u => u.kind === 'file' && u.path)
|
|
82
86
|
const agentText = appendAttachmentNote(
|
|
83
|
-
text,
|
|
87
|
+
text || attachmentOnlyPlaceholder(uploads.map(upload => upload.filename)),
|
|
84
88
|
files.map(f => ({ filename: f.filename, path: f.path! }))
|
|
85
89
|
)
|
|
86
90
|
// Always end with a text block so an image-only message still has a prompt.
|
|
87
|
-
blocks.push({ type: 'text', text: agentText
|
|
91
|
+
blocks.push({ type: 'text', text: agentText })
|
|
88
92
|
return { content: blocks, parts }
|
|
89
93
|
}
|
|
90
94
|
|
|
@@ -121,6 +125,7 @@ type InputQueue = {
|
|
|
121
125
|
type LiveSession = {
|
|
122
126
|
workspaceId: string
|
|
123
127
|
workspacePath: string
|
|
128
|
+
workspaceEnv: Record<string, string>
|
|
124
129
|
sessionId: string // current real id (rekeyed on rename)
|
|
125
130
|
q: Query
|
|
126
131
|
adapter: ClaudeAdapter
|
|
@@ -166,6 +171,9 @@ type LiveSession = {
|
|
|
166
171
|
createdAt: number
|
|
167
172
|
lastActivityAt: number
|
|
168
173
|
lastUserText: string | undefined
|
|
174
|
+
refreshSessionsOnResult: boolean
|
|
175
|
+
sessionTitleSource: string | undefined
|
|
176
|
+
sessionTitleAbort: AbortController | null
|
|
169
177
|
}
|
|
170
178
|
|
|
171
179
|
const sessions = new Map<string, LiveSession>()
|
|
@@ -333,6 +341,8 @@ function teardown(s: LiveSession) {
|
|
|
333
341
|
setActivity(s, 'idle')
|
|
334
342
|
s.closed = true
|
|
335
343
|
clearIdle(s)
|
|
344
|
+
s.sessionTitleAbort?.abort()
|
|
345
|
+
s.sessionTitleAbort = null
|
|
336
346
|
s.input.close()
|
|
337
347
|
try {
|
|
338
348
|
s.q.close?.()
|
|
@@ -345,17 +355,59 @@ function teardown(s: LiveSession) {
|
|
|
345
355
|
}
|
|
346
356
|
}
|
|
347
357
|
|
|
358
|
+
function isCurrentLiveSession(s: LiveSession, abort: AbortController): boolean {
|
|
359
|
+
return (
|
|
360
|
+
!s.closed && !abort.signal.aborted && sessions.get(recKey(s.workspaceId, s.sessionId)) === s
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function startClaudeSessionTitleJob(s: LiveSession) {
|
|
365
|
+
if (!s.sessionTitleSource || s.closed) return
|
|
366
|
+
const source = s.sessionTitleSource
|
|
367
|
+
s.sessionTitleSource = undefined
|
|
368
|
+
const abort = new AbortController()
|
|
369
|
+
s.sessionTitleAbort = abort
|
|
370
|
+
|
|
371
|
+
void (async () => {
|
|
372
|
+
try {
|
|
373
|
+
const title = await generateClaudeSessionTitle({
|
|
374
|
+
source,
|
|
375
|
+
abortController: abort
|
|
376
|
+
})
|
|
377
|
+
if (!title || !isCurrentLiveSession(s, abort)) return
|
|
378
|
+
|
|
379
|
+
const renamed = await renameClaudeSessionIfUnchanged({
|
|
380
|
+
sessionId: s.sessionId,
|
|
381
|
+
workspacePath: s.workspacePath,
|
|
382
|
+
title,
|
|
383
|
+
isCurrent: () => isCurrentLiveSession(s, abort)
|
|
384
|
+
})
|
|
385
|
+
if (!renamed || !isCurrentLiveSession(s, abort)) return
|
|
386
|
+
broadcast(s.workspaceId, { type: 'sessions_changed', sessionId: s.sessionId })
|
|
387
|
+
debug(
|
|
388
|
+
`cc session title ws=${s.workspaceId} session=${s.sessionId} title=${JSON.stringify(title)}`
|
|
389
|
+
)
|
|
390
|
+
} catch (err) {
|
|
391
|
+
debug(
|
|
392
|
+
`cc session title failed ws=${s.workspaceId} session=${s.sessionId}: ${err instanceof Error ? err.message : String(err)}`
|
|
393
|
+
)
|
|
394
|
+
} finally {
|
|
395
|
+
if (s.sessionTitleAbort === abort) s.sessionTitleAbort = null
|
|
396
|
+
}
|
|
397
|
+
})()
|
|
398
|
+
}
|
|
399
|
+
|
|
348
400
|
// On `system/init` the SDK reports the real session id. For a brand-new session
|
|
349
401
|
// that differs from the client's temporary id, so we rekey the registry and
|
|
350
402
|
// tell the client to move its optimistic state. Subsequent inits report the
|
|
351
403
|
// same id and no-op.
|
|
352
|
-
function renameSession(s: LiveSession, realId: string) {
|
|
404
|
+
function renameSession(s: LiveSession, realId: string): string {
|
|
353
405
|
const from = s.sessionId
|
|
354
406
|
sessions.delete(recKey(s.workspaceId, from))
|
|
355
407
|
s.sessionId = realId
|
|
356
408
|
sessions.set(recKey(s.workspaceId, realId), s)
|
|
357
409
|
aliases.set(recKey(s.workspaceId, from), realId)
|
|
358
|
-
|
|
410
|
+
return from
|
|
359
411
|
}
|
|
360
412
|
|
|
361
413
|
// The session just went idle (state event, or `result` on a CLI without state
|
|
@@ -380,21 +432,27 @@ async function consume(s: LiveSession) {
|
|
|
380
432
|
if (msg.type === 'system' && msg.subtype === 'init') {
|
|
381
433
|
const realId = msg.session_id
|
|
382
434
|
if (realId && realId !== s.sessionId) {
|
|
383
|
-
const from = s
|
|
384
|
-
renameSession(s, realId)
|
|
435
|
+
const from = renameSession(s, realId)
|
|
385
436
|
// Carry any config the picker wrote under the temp id to the real id.
|
|
386
|
-
await
|
|
437
|
+
await renameSessionConfig(s.workspacePath, from, s.sessionId)
|
|
438
|
+
await renameSelectedSession(s.workspacePath, from, s.sessionId)
|
|
387
439
|
await renameViewBuilderSession(s.workspaceId, s.workspacePath, from, s.sessionId)
|
|
440
|
+
broadcast(s.workspaceId, {
|
|
441
|
+
type: 'session_renamed',
|
|
442
|
+
from,
|
|
443
|
+
to: s.sessionId
|
|
444
|
+
})
|
|
388
445
|
}
|
|
389
|
-
|
|
446
|
+
startClaudeSessionTitleJob(s)
|
|
447
|
+
// Seed the session's config from what it actually ran with — but only if
|
|
390
448
|
// it has none yet, so an explicit user PUT (or a migrated temp-id edit)
|
|
391
449
|
// always wins. A default run leaves no file and falls back to the
|
|
392
450
|
// workspace defaults.
|
|
393
451
|
if (
|
|
394
452
|
(s.model || s.effort || s.fastMode !== undefined) &&
|
|
395
|
-
!(await
|
|
453
|
+
!(await hasSessionConfig(s.workspacePath, s.sessionId))
|
|
396
454
|
) {
|
|
397
|
-
await
|
|
455
|
+
await saveSessionConfig(s.workspacePath, s.sessionId, {
|
|
398
456
|
model: s.model,
|
|
399
457
|
effort: s.effort,
|
|
400
458
|
fastMode: s.fastMode
|
|
@@ -475,6 +533,10 @@ async function consume(s: LiveSession) {
|
|
|
475
533
|
? undefined
|
|
476
534
|
: msg.errors.join('\n') || msg.subtype.replaceAll('_', ' ')
|
|
477
535
|
debug(`cc result ws=${s.workspaceId} session=${s.sessionId} subtype=${msg.subtype}`)
|
|
536
|
+
if (s.refreshSessionsOnResult) {
|
|
537
|
+
s.refreshSessionsOnResult = false
|
|
538
|
+
broadcast(s.workspaceId, { type: 'sessions_changed', sessionId: s.sessionId })
|
|
539
|
+
}
|
|
478
540
|
// Fallback for CLIs that never emit `session_state_changed`: treat
|
|
479
541
|
// every result as turn-over. With state events, `idle` follows the
|
|
480
542
|
// result and drives the same path.
|
|
@@ -530,6 +592,7 @@ function createLiveSession(input: {
|
|
|
530
592
|
// Resolved workspace env (.env + UI custom overrides), injected so the agent's
|
|
531
593
|
// Bash tool can use workspace secrets. Frozen at spawn — see restartWorkspaceSessions.
|
|
532
594
|
workspaceEnv: Record<string, string>
|
|
595
|
+
sessionTitleSource: string | undefined
|
|
533
596
|
}): LiveSession {
|
|
534
597
|
evictIfNeeded()
|
|
535
598
|
|
|
@@ -562,7 +625,9 @@ function createLiveSession(input: {
|
|
|
562
625
|
permissionMode: 'bypassPermissions',
|
|
563
626
|
allowDangerouslySkipPermissions: true,
|
|
564
627
|
settingSources: ['user', 'project'],
|
|
565
|
-
|
|
628
|
+
// MOI_AGENT marks every shell this session spawns as agent-driven (the
|
|
629
|
+
// moi CLI reads it — see agent-caller.ts), surviving the CLAUDECODE strip.
|
|
630
|
+
env: { ...process.env, ...input.workspaceEnv, CLAUDECODE: undefined, MOI_AGENT: '1' },
|
|
566
631
|
stderr: (data: string) => console.error('[SDK stderr]', data)
|
|
567
632
|
}
|
|
568
633
|
if (!input.isNew) options.resume = input.sessionId
|
|
@@ -570,6 +635,7 @@ function createLiveSession(input: {
|
|
|
570
635
|
const session: LiveSession = {
|
|
571
636
|
workspaceId: input.workspaceId,
|
|
572
637
|
workspacePath: input.workspacePath,
|
|
638
|
+
workspaceEnv: input.workspaceEnv,
|
|
573
639
|
sessionId: input.sessionId,
|
|
574
640
|
q: query({ prompt: queue.iterator, options }),
|
|
575
641
|
adapter: new ClaudeAdapter(),
|
|
@@ -589,7 +655,10 @@ function createLiveSession(input: {
|
|
|
589
655
|
lastBuilderError: undefined,
|
|
590
656
|
createdAt: Date.now(),
|
|
591
657
|
lastActivityAt: Date.now(),
|
|
592
|
-
lastUserText: undefined
|
|
658
|
+
lastUserText: undefined,
|
|
659
|
+
refreshSessionsOnResult: input.isNew,
|
|
660
|
+
sessionTitleSource: input.sessionTitleSource,
|
|
661
|
+
sessionTitleAbort: null
|
|
593
662
|
}
|
|
594
663
|
sessions.set(recKey(session.workspaceId, session.sessionId), session)
|
|
595
664
|
debug(
|
|
@@ -686,17 +755,37 @@ export async function sendCCMessage(input: {
|
|
|
686
755
|
}
|
|
687
756
|
}
|
|
688
757
|
if (!s) {
|
|
758
|
+
// The agent only sees secrets scoped to the 'agent' sink (plus .env).
|
|
759
|
+
// Resolved before the probe below so both see the same env.
|
|
760
|
+
const workspaceEnv = await resolveWorkspaceEnv(input.workspacePath)
|
|
761
|
+
// Resuming a session with no file on disk hard-fails the CLI with "No
|
|
762
|
+
// conversation found" — and a dangling id can be selected forever (a
|
|
763
|
+
// brand-new chat whose first turn died before init persisted anything,
|
|
764
|
+
// or session files cleaned up externally), wedging the chat. Start fresh
|
|
765
|
+
// instead: the init rename then migrates this id to the real one
|
|
766
|
+
// everywhere (selected session, session config, view builders, client).
|
|
767
|
+
const isNew =
|
|
768
|
+
input.isNew ||
|
|
769
|
+
!(await claudeSessionExists(input.sessionId, input.workspacePath, workspaceEnv))
|
|
770
|
+
if (isNew !== input.isNew) {
|
|
771
|
+
debug(`cc resume-missing ws=${input.workspaceId} session=${input.sessionId} — starting fresh`)
|
|
772
|
+
}
|
|
689
773
|
s = createLiveSession({
|
|
690
774
|
workspaceId: input.workspaceId,
|
|
691
775
|
workspacePath: input.workspacePath,
|
|
692
776
|
sessionId: input.sessionId,
|
|
693
|
-
isNew
|
|
777
|
+
isNew,
|
|
694
778
|
model: input.model,
|
|
695
779
|
effort: input.effort,
|
|
696
780
|
fastMode: input.fastMode,
|
|
697
781
|
stream: wantStream,
|
|
698
|
-
|
|
699
|
-
|
|
782
|
+
sessionTitleSource: isNew
|
|
783
|
+
? buildSessionTitleSource(
|
|
784
|
+
input.content,
|
|
785
|
+
uploads.map(upload => upload.filename)
|
|
786
|
+
)
|
|
787
|
+
: undefined,
|
|
788
|
+
workspaceEnv
|
|
700
789
|
})
|
|
701
790
|
}
|
|
702
791
|
// Streaming-input mode does NOT echo the pushed user message back in the
|
|
@@ -771,6 +860,7 @@ export async function interruptCCSession(workspaceId: string, sessionId: string)
|
|
|
771
860
|
}
|
|
772
861
|
} catch (err) {
|
|
773
862
|
console.error('[cc-session] interrupt failed', err)
|
|
863
|
+
teardown(s)
|
|
774
864
|
} finally {
|
|
775
865
|
clearTimeout(timer)
|
|
776
866
|
}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
// Session discovery + history replay for Claude Code workspaces, backed by
|
|
2
2
|
// the Agent SDK's persisted `.jsonl` session files.
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
getSessionInfo,
|
|
5
|
+
getSessionMessages,
|
|
6
|
+
listSessions,
|
|
7
|
+
tagSession
|
|
8
|
+
} from '@anthropic-ai/claude-agent-sdk'
|
|
9
|
+
import type { SDKSessionInfo } from '@anthropic-ai/claude-agent-sdk'
|
|
4
10
|
|
|
11
|
+
import {
|
|
12
|
+
attachmentOnlyFilenames,
|
|
13
|
+
isAttachmentOnlyPlaceholder,
|
|
14
|
+
splitAttachmentNote
|
|
15
|
+
} from '@/lib/attachment-note'
|
|
5
16
|
import type { SessionInfo, StreamEvent } from '@/lib/types'
|
|
6
17
|
|
|
7
18
|
import { ClaudeAdapter } from './adapter'
|
|
8
19
|
|
|
20
|
+
export const MOI_ARCHIVED_SESSION_TAG = 'moi:archived'
|
|
21
|
+
|
|
9
22
|
export type SessionFirstPromptCandidate = {
|
|
10
23
|
sessionId: string
|
|
11
24
|
firstPrompt?: string
|
|
@@ -18,11 +31,27 @@ export type SessionWorkspacePreview = {
|
|
|
18
31
|
updatedAt?: number
|
|
19
32
|
}
|
|
20
33
|
|
|
34
|
+
export function claudeSessionSummary(
|
|
35
|
+
session: Pick<SDKSessionInfo, 'customTitle' | 'firstPrompt' | 'summary'>
|
|
36
|
+
): string {
|
|
37
|
+
if (session.customTitle || !session.firstPrompt || session.summary !== session.firstPrompt) {
|
|
38
|
+
return session.summary
|
|
39
|
+
}
|
|
40
|
+
const split = splitAttachmentNote(session.firstPrompt)
|
|
41
|
+
return isAttachmentOnlyPlaceholder(split.text)
|
|
42
|
+
? attachmentOnlyFilenames(split.text).join(', ')
|
|
43
|
+
: session.summary
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function visibleClaudeSessions<T extends Pick<SDKSessionInfo, 'tag'>>(sessions: T[]): T[] {
|
|
47
|
+
return sessions.filter(session => session.tag !== MOI_ARCHIVED_SESSION_TAG)
|
|
48
|
+
}
|
|
49
|
+
|
|
21
50
|
export async function getSessions(workspacePath: string): Promise<SessionInfo[]> {
|
|
22
|
-
const sessions = await listSessions({ dir: workspacePath })
|
|
51
|
+
const sessions = visibleClaudeSessions(await listSessions({ dir: workspacePath }))
|
|
23
52
|
return sessions.map(s => ({
|
|
24
53
|
sessionId: s.sessionId,
|
|
25
|
-
summary: s
|
|
54
|
+
summary: claudeSessionSummary(s),
|
|
26
55
|
lastModified: s.lastModified,
|
|
27
56
|
cwd: s.cwd
|
|
28
57
|
}))
|
|
@@ -55,7 +84,7 @@ export async function getSessionWorkspacePreview(
|
|
|
55
84
|
workspacePath: string,
|
|
56
85
|
includeFirstUserMessage: boolean
|
|
57
86
|
): Promise<SessionWorkspacePreview> {
|
|
58
|
-
const sessions = await listSessions({ dir: workspacePath })
|
|
87
|
+
const sessions = visibleClaudeSessions(await listSessions({ dir: workspacePath }))
|
|
59
88
|
const updatedAt = selectLatestSessionUpdatedAt(sessions)
|
|
60
89
|
const firstUserMessage = includeFirstUserMessage
|
|
61
90
|
? selectOldestSessionFirstUserMessage(sessions)
|
|
@@ -67,6 +96,36 @@ export async function getSessionWorkspacePreview(
|
|
|
67
96
|
}
|
|
68
97
|
}
|
|
69
98
|
|
|
99
|
+
// Whether the session's file exists on disk in this workspace's project dir —
|
|
100
|
+
// i.e. whether `resume` can possibly succeed. Reads only that session's file
|
|
101
|
+
// (unlike listSessions). Fails open — a probe that can't answer reliably
|
|
102
|
+
// counts as existing, so the resume is still attempted instead of silently
|
|
103
|
+
// forking a new chat:
|
|
104
|
+
// - a transient fs error, and
|
|
105
|
+
// - a workspace env that redirects CLAUDE_CONFIG_DIR: the CLI subprocess gets
|
|
106
|
+
// workspaceEnv on top of process.env, so its session store is somewhere
|
|
107
|
+
// this process (and the SDK's ambient-env resolution) can't see.
|
|
108
|
+
export async function claudeSessionExists(
|
|
109
|
+
sessionId: string,
|
|
110
|
+
workspacePath: string,
|
|
111
|
+
workspaceEnv: Record<string, string> = {}
|
|
112
|
+
): Promise<boolean> {
|
|
113
|
+
const override = workspaceEnv.CLAUDE_CONFIG_DIR
|
|
114
|
+
if (override && override !== process.env.CLAUDE_CONFIG_DIR) return true
|
|
115
|
+
try {
|
|
116
|
+
return (await getSessionInfo(sessionId, { dir: workspacePath })) !== undefined
|
|
117
|
+
} catch {
|
|
118
|
+
return true
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function archiveClaudeSession(
|
|
123
|
+
sessionId: string,
|
|
124
|
+
workspacePath: string
|
|
125
|
+
): Promise<void> {
|
|
126
|
+
await tagSession(sessionId, MOI_ARCHIVED_SESSION_TAG, { dir: workspacePath })
|
|
127
|
+
}
|
|
128
|
+
|
|
70
129
|
/**
|
|
71
130
|
* Replay a session's persisted raw messages through a fresh adapter and
|
|
72
131
|
* return the resulting StreamEvents. Events are carefully NOT deduplicated —
|
|
@@ -97,7 +97,9 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
97
97
|
stdin: 'pipe',
|
|
98
98
|
stdout: 'pipe',
|
|
99
99
|
stderr: 'pipe',
|
|
100
|
-
|
|
100
|
+
// MOI_AGENT marks the agent's shells as agent-driven for the moi CLI
|
|
101
|
+
// (see agent-caller.ts).
|
|
102
|
+
env: { ...process.env, ...workspaceEnv, MOI_AGENT: '1' }
|
|
101
103
|
})
|
|
102
104
|
|
|
103
105
|
let alive = true
|
|
@@ -320,6 +322,25 @@ export async function getCodexSessions(workspacePath: string): Promise<SessionIn
|
|
|
320
322
|
}
|
|
321
323
|
}
|
|
322
324
|
|
|
325
|
+
export async function archiveCodexThread(
|
|
326
|
+
client: Pick<CodexClient, 'rpc'>,
|
|
327
|
+
threadId: string
|
|
328
|
+
): Promise<void> {
|
|
329
|
+
await client.rpc('thread/archive', { threadId })
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
export async function interruptCodexTurn(
|
|
333
|
+
client: Pick<CodexClient, 'rpc'>,
|
|
334
|
+
threadId: string,
|
|
335
|
+
turnId: string
|
|
336
|
+
): Promise<void> {
|
|
337
|
+
await client.rpc('turn/interrupt', { threadId, turnId })
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export async function archiveCodexSession(workspacePath: string, threadId: string): Promise<void> {
|
|
341
|
+
await archiveCodexThread(await getCodexClient(workspacePath), threadId)
|
|
342
|
+
}
|
|
343
|
+
|
|
323
344
|
// Home-page card preview. Peek-only: with no live app-server the card simply
|
|
324
345
|
// omits the activity fields until the workspace is opened once.
|
|
325
346
|
export async function getCodexWorkspacePreview(
|
|
@@ -341,21 +362,22 @@ export async function getCodexWorkspacePreview(
|
|
|
341
362
|
|
|
342
363
|
// Account-wide model catalog (identical for every workspace); cached like the
|
|
343
364
|
// Claude list in agent.ts, cleared on failure so a later call can retry. Keep
|
|
344
|
-
// the raw
|
|
345
|
-
|
|
365
|
+
// the raw rows so internal helpers can read isDefault and effort ordering.
|
|
366
|
+
// The effective service tier is cwd-scoped and applied after reading the cache.
|
|
367
|
+
let codexModelCatalogPromise: Promise<CodexModel[]> | null = null
|
|
346
368
|
|
|
347
|
-
function
|
|
348
|
-
if (!
|
|
349
|
-
|
|
369
|
+
export function getCodexModelCatalog(workspacePath: string): Promise<CodexModel[]> {
|
|
370
|
+
if (!codexModelCatalogPromise) {
|
|
371
|
+
codexModelCatalogPromise = (async () => {
|
|
350
372
|
const client = await getCodexClient(workspacePath)
|
|
351
373
|
const res = await client.rpc<{ data?: CodexModel[] }>('model/list', {})
|
|
352
|
-
return res.data ?? []
|
|
374
|
+
return (res.data ?? []).filter(model => !model.hidden)
|
|
353
375
|
})().catch(err => {
|
|
354
|
-
|
|
376
|
+
codexModelCatalogPromise = null
|
|
355
377
|
throw err
|
|
356
378
|
})
|
|
357
379
|
}
|
|
358
|
-
return
|
|
380
|
+
return codexModelCatalogPromise
|
|
359
381
|
}
|
|
360
382
|
|
|
361
383
|
async function getCodexConfiguredServiceTier(
|
|
@@ -378,12 +400,10 @@ async function getCodexConfiguredServiceTier(
|
|
|
378
400
|
|
|
379
401
|
export async function getCodexModels(workspacePath: string): Promise<Model[]> {
|
|
380
402
|
const [models, configuredServiceTier] = await Promise.all([
|
|
381
|
-
|
|
403
|
+
getCodexModelCatalog(workspacePath),
|
|
382
404
|
getCodexConfiguredServiceTier(workspacePath)
|
|
383
405
|
])
|
|
384
|
-
return models
|
|
385
|
-
.filter(model => !model.hidden)
|
|
386
|
-
.map(model => codexModelToModel(model, configuredServiceTier))
|
|
406
|
+
return models.map(model => codexModelToModel(model, configuredServiceTier))
|
|
387
407
|
}
|
|
388
408
|
|
|
389
409
|
// MCP servers as Codex sees them (from ~/.codex/config.toml), for the
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { Harness } from '../types'
|
|
4
4
|
import { findHarnessExecutable, pathHarnessAvailability } from '../executable'
|
|
5
5
|
import {
|
|
6
|
+
archiveCodexSession,
|
|
6
7
|
getCodexMcpStatus,
|
|
7
8
|
getCodexModels,
|
|
8
9
|
getCodexProcessInfo,
|
|
@@ -33,6 +34,7 @@ export const codexHarness: Harness = {
|
|
|
33
34
|
|
|
34
35
|
sendMessage: input => sendCodexMessage(input),
|
|
35
36
|
interrupt: (workspaceId, sessionId) => interruptCodexRun({ workspaceId, sessionId }),
|
|
37
|
+
archiveSession: (ws, sessionId) => archiveCodexSession(ws.path, sessionId),
|
|
36
38
|
activeSessions: () => getCodexActiveSessions(),
|
|
37
39
|
|
|
38
40
|
listSessions: ws => getCodexSessions(ws.path),
|