moi-computer 0.12.0 → 0.12.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.
Files changed (140) hide show
  1. package/README.md +1 -1
  2. package/client/AGENTS.md +2 -2
  3. package/client/api/app-ui-keys.ts +1 -1
  4. package/client/api/workspace-keys.ts +1 -3
  5. package/client/app/routes/WorkspaceRoute.tsx +2 -8
  6. package/client/features/applets/applet-runtime.ts +11 -13
  7. package/client/features/chat/ChatPanel.tsx +70 -49
  8. package/client/features/chat/ChatPopup.tsx +81 -8
  9. package/client/features/chat/applet-chat-intents.ts +31 -12
  10. package/client/features/chat/chat-send.ts +33 -1
  11. package/client/features/chat/chat-store.ts +10 -0
  12. package/client/features/chat/composer/ChatComposer.tsx +24 -27
  13. package/client/features/chat/composer/ModelPicker.tsx +3 -3
  14. package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
  15. package/client/features/chat/connection/chat-frames.ts +14 -7
  16. package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
  17. package/client/features/chat/messages/MarkdownContent.tsx +3 -3
  18. package/client/features/chat/messages/fork-history.ts +14 -0
  19. package/client/features/chat/sessions/ChatSelector.tsx +138 -79
  20. package/client/features/chat/sessions/api.ts +109 -19
  21. package/client/features/chat/sessions/browser-tab-state.ts +30 -7
  22. package/client/features/chat/sessions/useSelectedSession.ts +217 -51
  23. package/client/features/chat/useChat.ts +43 -45
  24. package/client/features/collab/client.ts +10 -11
  25. package/client/features/collab/hooks.tsx +6 -11
  26. package/client/features/collab/host-state.ts +57 -128
  27. package/client/features/collab/provider.tsx +3 -3
  28. package/client/features/collab/testing/fake-engine.ts +6 -27
  29. package/client/features/collab/workspace-users-menu.tsx +3 -7
  30. package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
  31. package/client/features/home/HomePage.tsx +2 -2
  32. package/client/features/overview/Overview.tsx +3 -6
  33. package/client/features/overview/default/ViewsWidget.tsx +5 -12
  34. package/client/features/overview/default/registry.tsx +2 -4
  35. package/client/features/views/PendingViewScreen.tsx +279 -0
  36. package/client/features/views/ViewManager.tsx +10 -10
  37. package/client/features/views/api.ts +63 -130
  38. package/client/features/views/useViewActions.ts +151 -0
  39. package/client/features/views/useViewDrafts.ts +79 -0
  40. package/client/features/views/view-presentation.ts +4 -5
  41. package/client/features/views/view-submission.ts +88 -0
  42. package/client/features/workspace/WorkspaceMenu.tsx +63 -0
  43. package/client/features/workspace/WorkspaceScreen.tsx +180 -375
  44. package/client/features/workspace/browser-tab-state.ts +16 -9
  45. package/client/features/workspace/moi-context.ts +13 -15
  46. package/client/features/workspace/tab-resolution.ts +16 -29
  47. package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
  48. package/client/index.tsx +5 -1
  49. package/client/runtime/useWorkspaceEvents.ts +7 -6
  50. package/client/store/ui.ts +25 -29
  51. package/dist/chunk-1zhnhy00.js +1 -0
  52. package/dist/chunk-27501vke.js +1 -0
  53. package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
  54. package/dist/chunk-am1x230f.js +2 -0
  55. package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
  56. package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
  57. package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
  58. package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
  59. package/dist/chunk-n33w9y38.js +10 -0
  60. package/dist/chunk-r63ks44z.js +68 -0
  61. package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
  62. package/dist/chunk-wd46nk26.css +1 -0
  63. package/dist/chunk-xgt7vxt9.js +1 -0
  64. package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
  65. package/dist/index.html +1 -1
  66. package/lib/ids.ts +2 -5
  67. package/lib/moi-context.ts +100 -73
  68. package/lib/navigation.ts +48 -87
  69. package/lib/session-drafts.ts +10 -0
  70. package/lib/types.ts +64 -31
  71. package/lib/view-build-directives.ts +12 -0
  72. package/lib/workspace-layout.ts +1 -1
  73. package/lib/workspace-tabs.ts +12 -7
  74. package/package.json +3 -1
  75. package/server/agent-launcher.ts +27 -0
  76. package/server/api.ts +119 -209
  77. package/server/app-config.ts +21 -2
  78. package/server/applets/build-worker.ts +2 -1
  79. package/server/applets/view-source.ts +7 -1
  80. package/server/cli-env.ts +72 -50
  81. package/server/cli.ts +101 -64
  82. package/server/control.ts +82 -63
  83. package/server/data-dir.ts +13 -0
  84. package/server/functions.ts +2 -1
  85. package/server/harness/README.md +8 -0
  86. package/server/harness/acp/adapter.ts +2 -2
  87. package/server/harness/acp/client.ts +2 -1
  88. package/server/harness/acp/discovery.ts +3 -3
  89. package/server/harness/acp/session.ts +6 -9
  90. package/server/harness/claude-code/adapter.ts +13 -8
  91. package/server/harness/claude-code/auth.ts +3 -2
  92. package/server/harness/claude-code/cli.ts +3 -1
  93. package/server/harness/claude-code/git-worktree.ts +5 -2
  94. package/server/harness/claude-code/index.ts +5 -0
  95. package/server/harness/claude-code/mcp.ts +2 -0
  96. package/server/harness/claude-code/models.ts +2 -0
  97. package/server/harness/claude-code/session.ts +5 -34
  98. package/server/harness/claude-code/sessions.ts +8 -12
  99. package/server/harness/codex/NOTES.md +23 -4
  100. package/server/harness/codex/adapter.ts +5 -3
  101. package/server/harness/codex/client.ts +13 -21
  102. package/server/harness/codex/index.ts +18 -0
  103. package/server/harness/codex/session.ts +6 -14
  104. package/server/harness/codex/thread-list.ts +74 -0
  105. package/server/harness/fork.ts +12 -0
  106. package/server/harness/openclaw/adapter.ts +3 -3
  107. package/server/harness/openclaw/session.ts +2 -30
  108. package/server/harness/session-title.ts +12 -3
  109. package/server/harness/types.ts +8 -3
  110. package/server/moi-scaffold.ts +2 -1
  111. package/server/pending-views.ts +164 -0
  112. package/server/registry.ts +14 -4
  113. package/server/selected-session.ts +91 -44
  114. package/server/service.ts +16 -2
  115. package/server/session-archive.ts +32 -0
  116. package/server/session-config.ts +16 -111
  117. package/server/session-lifecycle.ts +17 -0
  118. package/server/session-store.ts +127 -0
  119. package/server/status.ts +3 -1
  120. package/server/tabs.ts +7 -10
  121. package/server/view-sessions.ts +267 -0
  122. package/server/views.ts +30 -41
  123. package/server/web.ts +47 -45
  124. package/server/workspace-env.ts +27 -0
  125. package/server/workspace-init.ts +6 -2
  126. package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
  127. package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
  128. package/client/features/views/ViewBuilder.tsx +0 -239
  129. package/client/features/views/useViewBuilderActions.ts +0 -103
  130. package/client/features/views/useViewBuilderDrafts.ts +0 -68
  131. package/dist/chunk-2jncyq65.js +0 -1
  132. package/dist/chunk-e2q5ken7.js +0 -68
  133. package/dist/chunk-h2kj1ysj.js +0 -1
  134. package/dist/chunk-nzwgm8vc.css +0 -1
  135. package/dist/chunk-ph0h6h86.js +0 -1
  136. package/dist/chunk-ryg9z3kn.js +0 -10
  137. package/dist/chunk-tpn177bt.js +0 -2
  138. package/lib/view-builder-directives.ts +0 -16
  139. package/server/chat-selection.ts +0 -22
  140. package/server/view-builders.ts +0 -453
package/server/control.ts CHANGED
@@ -4,9 +4,11 @@ import { resolve } from 'path'
4
4
  import { parseAppletSelector } from '@/lib/applet-selector'
5
5
  import { resolveWorkspaceTheme } from '@/lib/themes'
6
6
  import type { WorkspaceEntry } from '@/lib/types'
7
- import { moiHref, parseMoiHref } from '@/lib/navigation'
7
+ import { resolveUrl } from '@/lib/navigation'
8
+ import { isWorkspaceTabId } from '@/lib/workspace-tabs'
8
9
  import { navigationRelay } from './navigation-relay'
9
10
 
11
+ import { getAppConfig } from './app-config'
10
12
  import { clearAppletLog, getAppletLog, getAppletLogCount } from './applet-log'
11
13
  import { serializeWorkspaceBundle } from './bundle-queue'
12
14
  import { CONTROL_HOST, CONTROL_PORT, PORT } from './constants'
@@ -16,6 +18,7 @@ import { processIcon } from './icon'
16
18
  import { loadLayout, saveLayout } from './layout'
17
19
  import { publishEvent } from './events'
18
20
  import { findWorkspaceForPath, listWorkspaces, registerWorkspace } from './registry'
21
+ import { requiredEnvFor } from './required-env'
19
22
  import { executeScratchOp } from './scratchpad-executor'
20
23
  import { readScratchpadImage, readScratchpadShapes } from './scratchpad'
21
24
  import { relayScratchOp } from './scratchpad-relay'
@@ -23,19 +26,22 @@ import { broadcastAll } from './state'
23
26
  import { assembleTabRows, assertNavigableTab } from './tabs'
24
27
  import { applyThemeUpdate } from './theme'
25
28
  import { handleBundle } from './widgets'
26
- import { getViewList, handleBundleViews, hasViewId } from './views'
27
- import {
28
- ViewBuilderError,
29
- listViewBuilders,
30
- reconcileViewBuilders,
31
- setBuilder
32
- } from './view-builders'
29
+ import { getWorkspaceViews, handleBundleViews } from './views'
30
+ import { updatePendingView, PendingViewError } from './pending-views'
31
+ import { createViewFromSession, ViewStartupError } from './view-sessions'
33
32
  import {
34
33
  getWorkspaceConfig,
35
34
  setWorkspaceConfig,
36
35
  type WorkspaceConfigPatch
37
36
  } from './workspace-config'
38
37
  import { VERSION } from './version'
38
+ import {
39
+ getWorkspaceEnvView,
40
+ parseEnvUpdate,
41
+ resolveWorkspaceEnv,
42
+ secretBackend,
43
+ updateWorkspaceEnv
44
+ } from './workspace-env'
39
45
 
40
46
  type ControlSocket = { send(data: string): void }
41
47
 
@@ -104,6 +110,7 @@ export const control = Bun.serve({
104
110
  version: VERSION,
105
111
  pid: process.pid,
106
112
  port: PORT,
113
+ unixSocket: getAppConfig().unixSocket ?? undefined,
107
114
  service: !!process.env.MOI_SERVICE
108
115
  })
109
116
  )
@@ -118,9 +125,6 @@ export const control = Bun.serve({
118
125
  if (!match) return
119
126
  const workspacePath = match.path
120
127
  const force = !!data.force
121
- // `--no-status`: compile without advancing any view builder to `ready`
122
- // (status stays whatever the agent last reported).
123
- const skipStatus = data.noStatus === true
124
128
  const only = typeof data.only === 'string' ? parseAppletSelector(data.only) : undefined
125
129
  if (data.only && !only) {
126
130
  ws.send(JSON.stringify({ error: `Invalid applet selector "${data.only}"` }))
@@ -146,7 +150,6 @@ export const control = Bun.serve({
146
150
  match.id,
147
151
  workspacePath,
148
152
  force,
149
- skipStatus,
150
153
  only?.id
151
154
  )) {
152
155
  if (!only?.id || r.name === only.id) {
@@ -240,18 +243,44 @@ export const control = Bun.serve({
240
243
  return
241
244
  }
242
245
 
243
- if (data.type === 'builder:set') {
246
+ if (data.type === 'view:create') {
247
+ const match = await resolveWorkspace(ws, data.path)
248
+ if (!match) return
249
+ try {
250
+ if (typeof data.requirements !== 'string')
251
+ throw new Error('View requirements are required')
252
+ if (data.fromSessionId !== undefined && typeof data.fromSessionId !== 'string')
253
+ throw new Error('Invalid session id')
254
+ const result = await createViewFromSession(match, data.fromSessionId, data.requirements)
255
+ let warning: string | undefined
256
+ try {
257
+ await navigationRelay.navigate(match.id, `moi:/views/${result.viewId}`)
258
+ } catch (error) {
259
+ const message = error instanceof Error ? error.message : 'Navigation failed'
260
+ warning = `View was created, but could not open it: ${message}. Open it with moi navigate 'moi:/views/${result.viewId}'.`
261
+ }
262
+ ws.send(JSON.stringify({ ok: true, ...result, ...(warning ? { warning } : {}) }))
263
+ } catch (error) {
264
+ ws.send(
265
+ JSON.stringify({
266
+ error: error instanceof Error ? error.message : 'Couldn’t start view',
267
+ ...(error instanceof ViewStartupError
268
+ ? { sessionId: error.sessionId, viewId: error.viewId }
269
+ : {})
270
+ })
271
+ )
272
+ }
273
+ return
274
+ }
275
+
276
+ if (data.type === 'view:set') {
244
277
  const match = await resolveWorkspace(ws, data.path)
245
278
  if (!match) return
246
279
  const appletId = typeof data.id === 'string' ? data.id.trim() : ''
247
- const builderId = typeof data.builder === 'string' ? data.builder.trim() : ''
248
- const kind = data.kind === 'widget' ? 'widget' : 'view'
249
- const status =
250
- data.status === 'building' || data.status === 'waiting' ? data.status : undefined
251
280
  const title = typeof data.title === 'string' ? data.title.trim() : undefined
252
281
  const icon = typeof data.icon === 'string' ? data.icon.trim() : undefined
253
282
  if (!appletId) {
254
- ws.send(JSON.stringify({ error: 'A view or widget id is required' }))
283
+ ws.send(JSON.stringify({ error: 'A view id is required' }))
255
284
  return
256
285
  }
257
286
  if (!/^[a-z0-9][a-z0-9_-]*$/.test(appletId)) {
@@ -271,29 +300,15 @@ export const control = Bun.serve({
271
300
  return
272
301
  }
273
302
  try {
274
- // A view can't claim an id that already exists on disk (unless this
275
- // builder already owns it). Widgets live in a separate namespace.
276
- if (kind === 'view') {
277
- const current = (await listViewBuilders(match.path)).find(builder =>
278
- builderId ? builder.id === builderId : builder.viewId === appletId
279
- )
280
- if (current?.viewId !== appletId && (await hasViewId(match.path, appletId))) {
281
- ws.send(JSON.stringify({ error: `View id "${appletId}" already exists` }))
282
- return
283
- }
284
- }
285
- const builder = await setBuilder(match.id, match.path, appletId, {
286
- builderId: builderId || undefined,
287
- kind,
288
- status,
303
+ const view = await updatePendingView(match.id, match.path, appletId, {
289
304
  title,
290
305
  icon
291
306
  })
292
- ws.send(JSON.stringify({ ok: true, builder, workspacePath: match.path }))
307
+ ws.send(JSON.stringify({ ok: true, viewId: view.id }))
293
308
  } catch (err) {
294
309
  ws.send(
295
310
  JSON.stringify({
296
- error: err instanceof ViewBuilderError ? err.message : 'Could not set builder'
311
+ error: err instanceof PendingViewError ? err.message : 'Couldn’t update view'
297
312
  })
298
313
  )
299
314
  }
@@ -306,7 +321,7 @@ export const control = Bun.serve({
306
321
  if (!match) return
307
322
  const [layout, views] = await Promise.all([
308
323
  loadLayout(match.path),
309
- getViewList(match.path)
324
+ getWorkspaceViews(match.path)
310
325
  ])
311
326
  ws.send(JSON.stringify({ ok: true, tabs: assembleTabRows(views, layout.tabs.active) }))
312
327
  return
@@ -317,9 +332,11 @@ export const control = Bun.serve({
317
332
  const match = await resolveWorkspace(ws, data.path)
318
333
  if (!match) return
319
334
  try {
320
- const address = parseMoiHref(data.href)
321
- const href = moiHref(address.tab, address.search)
322
- assertNavigableTab(address.tab, await getViewList(match.path))
335
+ const href = resolveUrl(data.href)
336
+ if (!href.startsWith('moi:/') || href.startsWith('moi:/files/'))
337
+ throw new Error('Navigation needs a workspace page address')
338
+ const tab = href.slice(5).split('?', 1)[0]
339
+ if (isWorkspaceTabId(tab)) assertNavigableTab(tab, await getWorkspaceViews(match.path))
323
340
  await navigationRelay.navigate(match.id, href)
324
341
  ws.send(JSON.stringify({ ok: true, href }))
325
342
  } catch (error) {
@@ -355,13 +372,35 @@ export const control = Bun.serve({
355
372
  return
356
373
  }
357
374
 
358
- if (data.type === 'env:changed') {
359
- // A CLI env write (`moi env set`/`unset`) already landed on disk —
360
- // reap + broadcast so it takes effect (same path as PUT /env).
375
+ // `moi env` reads and writes the workspace env only through here, so a
376
+ // write takes effect at once (same path as PUT /env), and the agent on
377
+ // a managed machine, which can't open moi's data folder, can use it.
378
+ if (data.type === 'env:view') {
361
379
  const match = await resolveWorkspace(ws, data.path)
362
380
  if (!match) return
381
+ const view = await getWorkspaceEnvView(match.path, requiredEnvFor(match.path))
382
+ ws.send(JSON.stringify({ view }))
383
+ return
384
+ }
385
+
386
+ if (data.type === 'env:update') {
387
+ const match = await resolveWorkspace(ws, data.path)
388
+ if (!match) return
389
+ const patch = parseEnvUpdate(data.patch)
390
+ if (typeof patch === 'string') {
391
+ ws.send(JSON.stringify({ error: patch }))
392
+ return
393
+ }
394
+ await updateWorkspaceEnv(match.path, patch)
363
395
  applyEnvChanged(match)
364
- ws.send(JSON.stringify({ ok: true }))
396
+ ws.send(JSON.stringify({ ok: true, backend: await secretBackend() }))
397
+ return
398
+ }
399
+
400
+ if (data.type === 'env:resolve') {
401
+ const match = await resolveWorkspace(ws, data.path)
402
+ if (!match) return
403
+ ws.send(JSON.stringify({ env: await resolveWorkspaceEnv(match.path) }))
365
404
  return
366
405
  }
367
406
 
@@ -505,23 +544,3 @@ export const control = Bun.serve({
505
544
  }
506
545
  }
507
546
  })
508
-
509
- // On boot, correct any builder a previous process left mid-flight. With no live
510
- // sessions yet, a persisted `building` record is by definition stale, so
511
- // reconcile hands it back to `waiting` — or promotes it to `ready` if its view
512
- // actually reached disk. GET-time reconcile would eventually do this too, but
513
- // only once a client reopens the workspace; this makes the stored state correct
514
- // even if no one does.
515
- async function reconcileBuildersOnBoot(): Promise<void> {
516
- const workspaces = await listWorkspaces()
517
- await Promise.all(
518
- workspaces.map(async entry => {
519
- try {
520
- await reconcileViewBuilders(entry.id, entry.path, await getViewList(entry.path), new Set())
521
- } catch (err) {
522
- console.error('[control] boot reconcile failed', entry.path, err)
523
- }
524
- })
525
- )
526
- }
527
- void reconcileBuildersOnBoot()
@@ -5,5 +5,18 @@
5
5
  // e2e tests: env-paths only honors XDG_DATA_HOME on Linux, so on macOS a
6
6
  // spawned CLI would otherwise read the developer's real data dir.
7
7
  import envPaths from 'env-paths'
8
+ import { accessSync, constants } from 'node:fs'
8
9
 
9
10
  export const DATA_DIR = process.env.MOI_DATA_DIR || envPaths('moi', { suffix: '' }).data
11
+
12
+ // Can this process open moi's data folder? Not when it's the agent's own OS
13
+ // user on a managed machine (docs/config.md): such callers go through
14
+ // the running server instead. A folder that doesn't exist yet counts as usable.
15
+ export function canUseDataDir(): boolean {
16
+ try {
17
+ accessSync(DATA_DIR, constants.R_OK | constants.W_OK | constants.X_OK)
18
+ return true
19
+ } catch (err) {
20
+ return (err as NodeJS.ErrnoException).code === 'ENOENT'
21
+ }
22
+ }
@@ -20,6 +20,7 @@ import { readFileSync } from 'node:fs'
20
20
  import { tmpdir } from 'node:os'
21
21
  import { join } from 'path'
22
22
 
23
+ import { agentCommand } from './agent-launcher'
23
24
  import { resolveWorkspaceEnv } from './workspace-env'
24
25
 
25
26
  const WORKER_PATH = join(import.meta.dir, 'functions-worker.ts')
@@ -132,7 +133,7 @@ function spawnSlot(workspacePath: string, workspaceEnv: Record<string, string>):
132
133
  modules: new Set()
133
134
  }
134
135
 
135
- slot.worker = Bun.spawn([process.execPath, WORKER_PATH], {
136
+ slot.worker = Bun.spawn(agentCommand([process.execPath, WORKER_PATH]), {
136
137
  // Neutral cwd so Bun doesn't auto-load the workspace's `.env`; the worker
137
138
  // chdir()s to MEI_WORKSPACE_ROOT at startup to restore cwd = workspace root.
138
139
  cwd: tmpdir(),
@@ -47,6 +47,8 @@ Socket-protocol notes the layers rely on (all defined in `lib/types.ts`):
47
47
  uuid, then rekeyed to the backend's real session/thread id.
48
48
  - **`sessions_changed`** — a provider changed session-list metadata such as a
49
49
  generated session title; clients refresh that workspace's session list.
50
+ - **`session_archived`** — a chat was archived; clients remove it from caches and
51
+ clear its selections and pin, including browser-local Collab selections.
50
52
  - **Optimistic-id rendezvous** — the client sends `optimisticId` with each
51
53
  chat; the user's bubble must upsert under that id. Backends differ: Codex
52
54
  echoes it natively (`clientUserMessageId` → `clientId`), Claude Code never
@@ -244,6 +246,12 @@ doubles as the evaluation rubric for new harnesses.
244
246
 
245
247
  ### Per-request configuration
246
248
 
249
+ - **Fork settings** — shared orchestration snapshots the source `SessionConfig`,
250
+ passes it to native `forkSession`, saves it on the child, and uses it for the
251
+ first send. Model, effort, and fast mode are inherited together. Adapters only
252
+ translate settings their native fork needs at creation; they do not read or
253
+ copy stored settings themselves. The fresh-chat fallback follows the same
254
+ rule when native forking is unavailable. Hermes currently has no effort control.
247
255
  - **List supported models**, including per-model metadata such as supported
248
256
  effort levels (drives the picker).
249
257
  - **Set model** — ideally live mid-session.
@@ -18,7 +18,7 @@ import {
18
18
  type Usage,
19
19
  toolContentToText
20
20
  } from './wire'
21
- import type { SessionInfo } from '@/lib/types'
21
+ import type { SessionSummary } from '@/lib/types'
22
22
 
23
23
  export type AcpProviderId = NonNullable<ToolCall['provider']>
24
24
 
@@ -115,7 +115,7 @@ export function replayedUserParts(raw: string, images: readonly Part[] = []): Pa
115
115
  return replayAttachmentParts([...images, { type: 'text', text: raw }])
116
116
  }
117
117
 
118
- export function acpSessionToSessionInfo(entry: AcpSessionListEntry): SessionInfo {
118
+ export function acpSessionToSessionInfo(entry: AcpSessionListEntry): SessionSummary {
119
119
  const updated = entry.updatedAt ? Date.parse(entry.updatedAt) : NaN
120
120
  return {
121
121
  sessionId: entry.sessionId,
@@ -10,6 +10,7 @@
10
10
  // is protocol. See ./wire.ts for the message shapes.
11
11
  import type { InitializeResponse, RequestPermissionRequest } from './wire'
12
12
 
13
+ import { agentCommand } from '../../agent-launcher'
13
14
  import { debug } from '../../debug'
14
15
  import { tapWire } from '../debug'
15
16
  import { resolveWorkspaceEnv } from '../../workspace-env'
@@ -76,7 +77,7 @@ const CLIENT_CAPABILITIES = { fs: { readTextFile: false, writeTextFile: false }
76
77
  async function startClient(spec: AcpSpawnSpec): Promise<ClientRecord> {
77
78
  const { provider, command, args, workspacePath } = spec
78
79
  const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
79
- const proc = Bun.spawn([command, ...args], {
80
+ const proc = Bun.spawn(agentCommand([command, ...args]), {
80
81
  cwd: workspacePath,
81
82
  stdin: 'pipe',
82
83
  stdout: 'pipe',
@@ -1,5 +1,5 @@
1
1
  // Session list, model catalog and home-card preview over ACP. Provider-agnostic.
2
- import type { Model, SessionInfo } from '@/lib/types'
2
+ import type { Model, SessionSummary } from '@/lib/types'
3
3
 
4
4
  import { type AcpProviderConfig, type AcpSpawnContext } from './session'
5
5
  import { acpSessionToSessionInfo } from './adapter'
@@ -17,13 +17,13 @@ const PAGE_LIMIT = 5
17
17
  export async function listAcpSessions(
18
18
  config: AcpProviderConfig,
19
19
  ctx: AcpSpawnContext
20
- ): Promise<SessionInfo[]> {
20
+ ): Promise<SessionSummary[]> {
21
21
  try {
22
22
  const client = await getAcpClient(await config.spawn(ctx))
23
23
  // Archiving is moi-side (see ./archived.ts) — the backend still lists the
24
24
  // chat, so it is filtered here rather than by the agent.
25
25
  const archived = await archivedAcpSessions(ctx.workspacePath)
26
- const out: SessionInfo[] = []
26
+ const out: SessionSummary[] = []
27
27
  let cursor: string | undefined
28
28
  for (let page = 0; page < PAGE_LIMIT; page++) {
29
29
  const res: ListSessionsResponse = await client.rpc('session/list', {
@@ -52,9 +52,8 @@ import {
52
52
  import { agentStore } from '../../agent'
53
53
  import { debug } from '../../debug'
54
54
  import { broadcast } from '../../state'
55
- import { renameSelectedSession } from '../../selected-session'
56
- import { hasSessionConfig, renameSessionConfig, saveSessionConfig } from '../../session-config'
57
- import { renameViewBuilderSession } from '../../view-builders'
55
+ import { hasSessionConfig, saveSessionConfig } from '../../session-config'
56
+ import { renameSessionReferences } from '../../session-lifecycle'
58
57
 
59
58
  export type AcpSpawnContext = {
60
59
  workspaceId: string
@@ -541,11 +540,12 @@ async function runPrompt(
541
540
  content: err instanceof Error ? err.message : 'send failed'
542
541
  })
543
542
  refreshAvailability(rec, config.id)
543
+ throw err
544
544
  } finally {
545
545
  void appendRunDuration(rec.workspacePath, rec.sessionId, Date.now() - startedAt)
546
546
  const next = rec.queue.shift()
547
547
  if (next) {
548
- void runPrompt(config, rec, next.blocks)
548
+ void runPrompt(config, rec, next.blocks).catch(() => {})
549
549
  } else {
550
550
  setProcessing(rec, false)
551
551
  }
@@ -608,15 +608,12 @@ export async function sendAcpMessage(
608
608
  const model = input.model ?? created.models?.currentModelId
609
609
  if (realId !== input.sessionId) {
610
610
  aliases.set(recKey(input.workspaceId, input.sessionId), realId)
611
- await renameSessionConfig(input.workspacePath, input.sessionId, realId)
612
- await renameSelectedSession(input.workspacePath, input.sessionId, realId)
613
- await renameViewBuilderSession(
611
+ await renameSessionReferences(
614
612
  input.workspaceId,
615
613
  input.workspacePath,
616
614
  input.sessionId,
617
615
  realId
618
616
  )
619
- broadcast(input.workspaceId, { type: 'session_renamed', from: input.sessionId, to: realId })
620
617
  }
621
618
  rec = createRecord({
622
619
  workspaceId: input.workspaceId,
@@ -650,7 +647,7 @@ export async function sendAcpMessage(
650
647
  { workspaceId: input.workspaceId, workspacePath: input.workspacePath },
651
648
  config.id
652
649
  )
653
- return
650
+ throw err
654
651
  }
655
652
 
656
653
  rec.stream = input.stream === true
@@ -267,7 +267,7 @@ export class ClaudeAdapter {
267
267
  events.push({
268
268
  kind: 'notice',
269
269
  notice: {
270
- id: noticeId('rate-limit'),
270
+ id: msg.uuid ?? noticeId('rate-limit'),
271
271
  kind: 'rate-limit',
272
272
  at: new Date().toISOString(),
273
273
  info: msg.rate_limit_info
@@ -774,20 +774,25 @@ export class ClaudeAdapter {
774
774
  // -----------------------------------------------------------------------
775
775
 
776
776
  private buildSystemNotice(msg: SdkMessage): SystemNotice | undefined {
777
- const at = new Date().toISOString()
777
+ const at = msg.timestamp ?? new Date().toISOString()
778
778
  switch (msg.subtype) {
779
779
  case 'session_state_changed':
780
780
  return {
781
- id: noticeId('session-state'),
781
+ id: msg.uuid ?? noticeId('session-state'),
782
782
  kind: 'session-state',
783
783
  at,
784
784
  state: (msg.state as 'idle' | 'running' | 'requires-action') ?? 'idle'
785
785
  }
786
786
  case 'compact_boundary':
787
- return { id: noticeId('compact'), kind: 'compact', at, metadata: msg.compact_metadata }
787
+ return {
788
+ id: msg.uuid ?? noticeId('compact'),
789
+ kind: 'compact',
790
+ at,
791
+ metadata: msg.compact_metadata
792
+ }
788
793
  case 'api_retry':
789
794
  return {
790
- id: noticeId('api-retry'),
795
+ id: msg.uuid ?? noticeId('api-retry'),
791
796
  kind: 'api-retry',
792
797
  at,
793
798
  attempt: msg.attempt ?? 0,
@@ -799,7 +804,7 @@ export class ClaudeAdapter {
799
804
  case 'hook_progress':
800
805
  case 'hook_response':
801
806
  return {
802
- id: noticeId('hook'),
807
+ id: msg.uuid ?? noticeId('hook'),
803
808
  kind: 'hook',
804
809
  at,
805
810
  hookId: msg.hook_id ?? '',
@@ -817,7 +822,7 @@ export class ClaudeAdapter {
817
822
  }
818
823
  case 'files_persisted':
819
824
  return {
820
- id: noticeId('files-persisted'),
825
+ id: msg.uuid ?? noticeId('files-persisted'),
821
826
  kind: 'files-persisted',
822
827
  at,
823
828
  files: (msg.files ?? []).map(f => f.filename),
@@ -825,7 +830,7 @@ export class ClaudeAdapter {
825
830
  }
826
831
  case 'elicitation_complete':
827
832
  return {
828
- id: noticeId('elicitation'),
833
+ id: msg.uuid ?? noticeId('elicitation'),
829
834
  kind: 'elicitation',
830
835
  at,
831
836
  server: msg.mcp_server_name ?? '',
@@ -1,5 +1,6 @@
1
1
  import type { HarnessAvailability, HarnessLogin } from '@/lib/types'
2
2
 
3
+ import { agentCommand } from '../../agent-launcher'
3
4
  import { resolveWorkspaceEnv } from '../../workspace-env'
4
5
  import { findHarnessExecutable } from '../executable'
5
6
 
@@ -33,7 +34,7 @@ export async function getClaudeAuthReadiness(workspacePath: string): Promise<Har
33
34
  if (!executable) return unavailable('Claude is not installed')
34
35
 
35
36
  const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
36
- const proc = Bun.spawn([executable, 'auth', 'status'], {
37
+ const proc = Bun.spawn(agentCommand([executable, 'auth', 'status']), {
37
38
  cwd: workspacePath,
38
39
  env: { ...process.env, ...workspaceEnv },
39
40
  stdin: 'ignore',
@@ -58,7 +59,7 @@ export async function startClaudeLogin(workspacePath: string): Promise<HarnessLo
58
59
  if (!executable) throw new Error('Claude is not installed')
59
60
 
60
61
  const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
61
- Bun.spawn([executable, 'auth', 'login'], {
62
+ Bun.spawn(agentCommand([executable, 'auth', 'login']), {
62
63
  cwd: workspacePath,
63
64
  env: { ...process.env, ...workspaceEnv },
64
65
  stdin: 'ignore',
@@ -1,3 +1,5 @@
1
+ import { agentCommand } from '../../agent-launcher'
2
+
1
3
  // Include the version in CLI identity: auto-updates can replace the binary
2
4
  // without changing its path.
3
5
 
@@ -24,7 +26,7 @@ export function claudeCliKey(cli: ClaudeCli): string {
24
26
  export async function probeClaudeCli(executable: string): Promise<ClaudeCli> {
25
27
  let timeout: ReturnType<typeof setTimeout> | undefined
26
28
  try {
27
- const proc = Bun.spawn([executable, '--version'], {
29
+ const proc = Bun.spawn(agentCommand([executable, '--version']), {
28
30
  stdin: 'ignore',
29
31
  stdout: 'pipe',
30
32
  stderr: 'ignore'
@@ -3,8 +3,11 @@
3
3
  // Claude Code accumulates session history in every directory an agent ever ran
4
4
  // in, including the throwaway checkouts created for worktree-isolated runs.
5
5
  // Those derived directories shouldn't surface as importable workspaces in the
6
- // discovery list, so we filter them out. moi doesn't support running inside a
7
- // worktree yet — see docs/git-worktrees.md.
6
+ // discovery list, so we filter them out. This is a filter on discovery only:
7
+ // moi doesn't support running inside a linked worktree as a workspace, and a
8
+ // worktree that was already imported stays registered until removed by hand.
9
+ // Detection fails open — a read error means "not a worktree" — so a transient
10
+ // filesystem hiccup can let a worktree through but never hides a real repo.
8
11
  import { readFile } from 'node:fs/promises'
9
12
  import { join } from 'node:path'
10
13
 
@@ -1,6 +1,7 @@
1
1
  // Claude Code as a Harness. Thin wiring over this folder's modules — see
2
2
  // ../types.ts for the contract and ../README.md for the architecture.
3
3
  import { join } from 'node:path'
4
+ import { forkSession } from '@anthropic-ai/claude-agent-sdk'
4
5
 
5
6
  import type { McpServer } from '@/lib/types'
6
7
 
@@ -92,6 +93,10 @@ export const claudeCodeHarness: Harness = {
92
93
  sendMessage: input => sendCCMessage(input),
93
94
  interrupt: (workspaceId, sessionId) => interruptCCSession(workspaceId, sessionId),
94
95
  archiveSession: (ws, sessionId) => archiveClaudeSession(sessionId, ws.path),
96
+ forkSession: async (ws, sourceId) => {
97
+ const { sessionId } = await forkSession(sourceId, { dir: ws.path })
98
+ return sessionId
99
+ },
95
100
  activeSessions: () => getCCActiveSessions(),
96
101
 
97
102
  listSessions: ws => getSessions(ws.path),
@@ -1,6 +1,7 @@
1
1
  import { query } from '@anthropic-ai/claude-agent-sdk'
2
2
  import type { McpServerStatus, SDKUserMessage } from '@anthropic-ai/claude-agent-sdk'
3
3
 
4
+ import { claudeCodeSpawn } from '../../agent-launcher'
4
5
  import { debugEnabled } from '../../debug'
5
6
  import { requireHarnessExecutable } from '../executable'
6
7
 
@@ -62,6 +63,7 @@ async function probeMcpStatus(workspacePath: string): Promise<McpServerStatus[]>
62
63
  options: {
63
64
  cwd: workspacePath,
64
65
  pathToClaudeCodeExecutable: requireHarnessExecutable('claude-code'),
66
+ spawnClaudeCodeProcess: claudeCodeSpawn(),
65
67
  persistSession: false,
66
68
  settingSources: ['user', 'project'],
67
69
  env: { ...process.env, CLAUDECODE: undefined }
@@ -3,6 +3,7 @@ import type { ModelInfo } from '@anthropic-ai/claude-agent-sdk'
3
3
 
4
4
  import type { Model } from '@/lib/types'
5
5
 
6
+ import { claudeCodeSpawn } from '../../agent-launcher'
6
7
  import { requireHarnessExecutable } from '../executable'
7
8
  import { type ClaudeCli, claudeCliKey, probeClaudeCli } from './cli'
8
9
 
@@ -13,6 +14,7 @@ async function fetchClaudeModels(cwd: string, executable: string): Promise<Model
13
14
  options: {
14
15
  cwd,
15
16
  pathToClaudeCodeExecutable: executable,
17
+ spawnClaudeCodeProcess: claudeCodeSpawn(),
16
18
  persistSession: false,
17
19
  settingSources: ['user', 'project'],
18
20
  env: { ...process.env, CLAUDECODE: undefined }