moi-computer 0.13.1-next.3 → 0.13.1-next.4

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 (82) hide show
  1. package/client/app/app-provider.tsx +14 -20
  2. package/client/app/app-router.tsx +5 -8
  3. package/client/app/routes/workspace-route.tsx +28 -11
  4. package/client/app/shell/sidebar-layout.tsx +5 -10
  5. package/client/features/app-settings/api.ts +3 -3
  6. package/client/features/applets/applet-cache.ts +1 -2
  7. package/client/features/applets/use-applet.ts +18 -20
  8. package/client/features/chat/chat-store.ts +1 -1
  9. package/client/features/chat/connection/chat-connection.ts +25 -68
  10. package/client/features/chat/connection/chat-frames.ts +20 -32
  11. package/client/features/chat/sessions/api.ts +2 -2
  12. package/client/features/collab/presence/client.ts +63 -83
  13. package/client/features/collab/presence/provider.tsx +8 -2
  14. package/client/features/dev/chat-states-page.tsx +1 -1
  15. package/client/features/dev/harness-debug-page.tsx +2 -2
  16. package/client/features/scratchpad/scratchpad.tsx +29 -20
  17. package/client/features/views/api.ts +5 -6
  18. package/client/features/workspace/api.ts +6 -11
  19. package/client/features/workspace/harness-transition.ts +3 -5
  20. package/client/features/workspace/remote.ts +9 -0
  21. package/client/features/workspace/settings/use-env-vars.ts +4 -4
  22. package/client/features/workspace/use-workspace-navigation.ts +1 -1
  23. package/client/features/workspace/use-workspace-socket.ts +51 -0
  24. package/client/features/workspace/workspace-content.tsx +3 -7
  25. package/client/features/workspace/workspace-layout-context.tsx +6 -13
  26. package/client/features/workspace/workspace-state.ts +17 -6
  27. package/client/runtime/app-context.ts +2 -2
  28. package/client/runtime/app-events.ts +75 -0
  29. package/client/runtime/reconnecting-socket.ts +115 -0
  30. package/client/runtime/{use-workspace-events.ts → use-client-events.ts} +9 -10
  31. package/dist/{chunk-f44cs6mw.js → chunk-0t8m1ehd.js} +2 -2
  32. package/dist/chunk-851bx8ss.js +72 -0
  33. package/dist/{chunk-xj1pjhng.js → chunk-c8g5x288.js} +1 -1
  34. package/dist/chunk-cty37f3v.js +1 -0
  35. package/dist/chunk-dy6f6h3e.js +5 -0
  36. package/dist/chunk-j6928pwm.js +1 -0
  37. package/dist/{chunk-r95acex1.js → chunk-k32585ne.js} +70 -70
  38. package/dist/chunk-qtkv7hp8.js +2 -0
  39. package/dist/chunk-rh58dc0y.js +2 -0
  40. package/dist/{chunk-a865c7x4.js → chunk-wjbejzek.js} +1 -1
  41. package/dist/index.html +1 -1
  42. package/lib/events.ts +61 -0
  43. package/lib/ids.ts +2 -8
  44. package/lib/types.ts +12 -15
  45. package/package.json +1 -1
  46. package/server/AGENTS.md +3 -3
  47. package/server/README.md +29 -15
  48. package/server/api/index.ts +54 -35
  49. package/server/applets/views.ts +15 -14
  50. package/server/applets/widgets.ts +4 -3
  51. package/server/cli/commands/refresh.ts +2 -5
  52. package/server/control.ts +24 -33
  53. package/server/events.ts +14 -13
  54. package/server/harness/README.md +7 -7
  55. package/server/harness/acp/session.ts +9 -5
  56. package/server/harness/auth.ts +7 -30
  57. package/server/harness/claude-code/session.ts +8 -4
  58. package/server/harness/codex/NOTES.md +1 -1
  59. package/server/harness/codex/session.ts +18 -10
  60. package/server/harness/hermes/NOTES.md +3 -3
  61. package/server/harness/openclaw/session.ts +9 -5
  62. package/server/onboarding/jobs.ts +7 -7
  63. package/server/operations/commands.ts +1 -1
  64. package/server/scratchpad/executor.ts +2 -2
  65. package/server/scratchpad/relay.ts +3 -3
  66. package/server/sessions/archive.ts +1 -1
  67. package/server/sessions/lifecycle.ts +1 -1
  68. package/server/sessions/pending-views.ts +17 -11
  69. package/server/web.ts +40 -30
  70. package/server/workspace-state/index.ts +15 -4
  71. package/server/workspaces/config.ts +14 -13
  72. package/server/workspaces/env-apply.ts +1 -1
  73. package/server/workspaces/layout.ts +40 -7
  74. package/server/workspaces/shared.ts +1 -1
  75. package/client/features/scratchpad/scratch-executor.ts +0 -20
  76. package/client/runtime/workspace-events.ts +0 -168
  77. package/dist/chunk-0h4zypgf.js +0 -1
  78. package/dist/chunk-1tksq43z.js +0 -72
  79. package/dist/chunk-6gxf0xr8.js +0 -5
  80. package/dist/chunk-h3qag4a6.js +0 -2
  81. package/dist/chunk-q2tpy0h7.js +0 -2
  82. package/dist/chunk-w5h9grdr.js +0 -1
@@ -1,3 +1,4 @@
1
+ import type { ServerEvent } from '@/lib/events'
1
2
  import { existsSync } from 'node:fs'
2
3
 
3
4
  import type { CompiledView, ViewConfig, ViewInfo, WorkspaceEntry } from '@/lib/types'
@@ -179,13 +180,13 @@ export async function getWorkspaceViews(ws: WorkspaceRef): Promise<ViewInfo[]> {
179
180
  }
180
181
 
181
182
  // The API lists compiled views only; clients read pending views from the
182
- // workspace state, which `state:changed` keeps current.
183
+ // workspace state, which `personal-state:changed` keeps current.
183
184
  export async function listViews(workspacePath: string): Promise<Response> {
184
185
  return Response.json({ views: await listCompiledViews(workspacePath) })
185
186
  }
186
187
 
187
188
  export async function handleBundleViews(
188
- publish: (msg: unknown) => void,
189
+ publish: (msg: ServerEvent) => void,
189
190
  workspaceId: string,
190
191
  workspacePath: string,
191
192
  force = false,
@@ -207,21 +208,21 @@ export async function handleBundleViews(
207
208
  [...beforeBuilt].some(n => !afterBuilt.has(n)) ||
208
209
  [...afterBuilt].some(n => !beforeBuilt.has(n))
209
210
 
210
- // Install compiled views in the browser before removing their pending entries.
211
- // Otherwise tab cleanup can mistake the handoff for a deleted view.
211
+ let views: CompiledView[] = []
212
212
  if (results.some(r => r.status === 'built') || orderChanged || membershipChanged) {
213
- publish({
214
- type: 'view-layout:updated',
215
- workspaceId,
216
- views: await listCompiledViews(workspacePath)
217
- })
213
+ views = await listCompiledViews(workspacePath)
214
+ publish({ type: 'views-list:changed', workspaceId, views })
218
215
  }
219
216
 
220
217
  const changedServerModules = new Set<string>()
221
218
  for (const r of results) {
222
219
  if (r.status === 'built') {
223
- publish({ type: 'view:updated', workspaceId, name: r.name, config: r.config ?? null })
224
- await completeViewBuild({ id: workspaceId, path: workspacePath }, r.name)
220
+ publish({ type: 'view:changed', workspaceId, name: r.name })
221
+ await completeViewBuild(
222
+ { id: workspaceId, path: workspacePath },
223
+ r.name,
224
+ views.find(view => view.id === r.name)
225
+ )
225
226
  for (const m of r.serverModules ?? []) changedServerModules.add(m)
226
227
  }
227
228
  }
@@ -234,7 +235,7 @@ export async function handleBundleViews(
234
235
  }
235
236
 
236
237
  export async function updateViewTitle(
237
- publish: (msg: unknown) => void,
238
+ publish: (msg: ServerEvent) => void,
238
239
  workspaceId: string,
239
240
  workspacePath: string,
240
241
  viewId: string,
@@ -288,7 +289,7 @@ export async function updateViewTitle(
288
289
  }
289
290
 
290
291
  export async function deleteView(
291
- publish: (msg: unknown) => void,
292
+ publish: (msg: ServerEvent) => void,
292
293
  ws: WorkspaceEntry,
293
294
  viewId: string
294
295
  ): Promise<void> {
@@ -306,7 +307,7 @@ export async function deleteView(
306
307
  reloadModules([`views/${viewId}`], workspacePath)
307
308
  await completeViewBuild(ws, viewId)
308
309
  publish({ type: 'view:deleted', workspaceId, name: viewId })
309
- publish({ type: 'workspace:updated', workspaceId })
310
+ publish({ type: 'workspace-config:changed', workspaceId })
310
311
  await handleBundleViews(publish, workspaceId, workspacePath, false, viewId)
311
312
  })
312
313
  }
@@ -1,3 +1,4 @@
1
+ import type { ServerEvent } from '@/lib/events'
1
2
  import { existsSync } from 'node:fs'
2
3
 
3
4
  import type { WidgetConfig, WidgetInfo } from '@/lib/types'
@@ -122,7 +123,7 @@ export async function listWidgets(workspacePath: string): Promise<Response> {
122
123
  }
123
124
 
124
125
  export async function handleBundle(
125
- publish: (msg: unknown) => void,
126
+ publish: (msg: ServerEvent) => void,
126
127
  workspaceId: string,
127
128
  workspacePath: string,
128
129
  force = false,
@@ -152,7 +153,7 @@ export async function handleBundle(
152
153
  const changedServerModules = new Set<string>()
153
154
  for (const r of results) {
154
155
  if (r.status === 'built') {
155
- publish({ type: 'widget:updated', workspaceId, name: r.name, config: r.config ?? null })
156
+ publish({ type: 'widget:changed', workspaceId, name: r.name })
156
157
  for (const m of r.serverModules ?? []) changedServerModules.add(m)
157
158
  }
158
159
  }
@@ -163,7 +164,7 @@ export async function handleBundle(
163
164
 
164
165
  if (layoutChanged) {
165
166
  const widgets = await getWidgetList(workspacePath)
166
- publish({ type: 'widget-layout:updated', workspaceId, widgets })
167
+ publish({ type: 'widgets-list:changed', workspaceId, widgets })
167
168
  }
168
169
 
169
170
  return results
@@ -1,4 +1,3 @@
1
- import { currentRemoteWorkspace } from '../../remote/workspace'
2
1
  import { defineCommand } from 'citty'
3
2
  import { CONTROL_URL } from '../../constants'
4
3
  import { staleSkillNotice } from '../../skills/version'
@@ -9,8 +8,7 @@ import pc from '../pc'
9
8
  export const refresh = defineCommand({
10
9
  meta: {
11
10
  name: 'refresh',
12
- description:
13
- 'Refresh widget and view data without rebuilding. Use after the agent mutates underlying data.'
11
+ description: 'Refresh widget and view data in your tabs for the current workspace.'
14
12
  },
15
13
  args: {
16
14
  only: appletOnlyArg
@@ -18,7 +16,6 @@ export const refresh = defineCommand({
18
16
  async run({ args }) {
19
17
  const only = readAppletSelector(args.only)
20
18
  const notice = await staleSkillNotice(process.cwd())
21
- const linked = await currentRemoteWorkspace()
22
19
  const ws = new WebSocket(CONTROL_URL)
23
20
 
24
21
  ws.onopen = () =>
@@ -26,7 +23,7 @@ export const refresh = defineCommand({
26
23
  JSON.stringify({
27
24
  type: 'applets:refresh',
28
25
  only,
29
- path: linked?.path ?? process.env.MOI_REMOTE_WORKSPACE
26
+ path: process.cwd()
30
27
  })
31
28
  )
32
29
 
package/server/control.ts CHANGED
@@ -15,14 +15,13 @@ import { CONTROL_HOST, CONTROL_PORT, PORT } from './constants'
15
15
  import { applyEnvChanged } from './workspaces/env-apply'
16
16
  import { callFunctionEphemeral, parseFunctionPath } from './applets/functions'
17
17
  import { processIcon } from './workspaces/icon'
18
- import { loadLayout, saveLayout } from './workspaces/layout'
18
+ import { loadLayout, updateLayout } from './workspaces/layout'
19
19
  import { publishEvent } from './events'
20
20
  import { findWorkspaceForPath, listWorkspaces, registerWorkspace } from './workspaces/registry'
21
21
  import { requiredEnvFor } from './workspaces/required-env'
22
22
  import { executeScratchOp } from './scratchpad/executor'
23
23
  import { readScratchpadImage, readScratchpadShapes } from './scratchpad/document'
24
24
  import { relayScratchOp } from './scratchpad/relay'
25
- import { broadcastAll } from './state'
26
25
  import { assembleTabRows, assertNavigableTab } from './workspaces/tabs'
27
26
  import { applyThemeUpdate } from './workspaces/theme'
28
27
  import { handleBundle } from './applets/widgets'
@@ -101,7 +100,7 @@ export const control = Bun.serve({
101
100
  if (data.type === 'workspace:register') {
102
101
  const absPath = resolve(String(data.path))
103
102
  const entry = await registerWorkspace(absPath)
104
- broadcastAll({ type: 'workspace:switch', workspaceId: entry.id })
103
+ publishEvent({ type: 'workspace:open-requested', workspaceId: entry.id })
105
104
  ws.send(JSON.stringify({ id: entry.id, path: entry.path }))
106
105
  return
107
106
  }
@@ -375,34 +374,24 @@ export const control = Bun.serve({
375
374
  return
376
375
  }
377
376
 
378
- // Tell every connected applet to re-import its module (cache-bust) and
379
- // re-run its data fetches. No rebuild, no page reload — `useApplet`
380
- // handles `applets:refresh` like `*:updated` (invalidate + reload).
381
- // `only` narrows to one kind or applet; default is both kinds.
382
- // `widget:refresh` is the pre-filter message name older CLIs send.
383
- if (data.type === 'applets:refresh' || data.type === 'widget:refresh') {
384
- const match = data.path ? await resolveWorkspace(ws, data.path) : undefined
385
- if (data.path && !match) return
386
- const scope = match ? { workspaceId: match.id } : {}
377
+ if (data.type === 'applets:refresh') {
378
+ if (typeof data.path !== 'string' || !data.path) {
379
+ ws.send(JSON.stringify({ error: 'Refresh requires a workspace path' }))
380
+ return
381
+ }
382
+ const workspace = await resolveWorkspace(ws, data.path)
383
+ if (!workspace) return
387
384
  const only = typeof data.only === 'string' ? parseAppletSelector(data.only) : undefined
388
- if (data.only && !only) {
385
+ if (data.only !== undefined && !only) {
389
386
  ws.send(JSON.stringify({ error: `Invalid applet selector "${data.only}"` }))
390
387
  return
391
388
  }
392
- // No `workspaceId`: `moi refresh` names no workspace, so every open one reloads.
393
- if (only?.id) {
394
- publishEvent({
395
- type: only.segment === 'widgets' ? 'widget:updated' : 'view:updated',
396
- ...scope,
397
- name: only.id
398
- })
399
- } else {
400
- publishEvent({
401
- type: 'applets:refresh',
402
- ...scope,
403
- ...(data.only ? { only: data.only } : {})
404
- })
405
- }
389
+ publishEvent({
390
+ type: 'applets:refresh',
391
+ workspaceId: workspace.id,
392
+ only: only?.segment,
393
+ name: only?.id
394
+ })
406
395
  ws.send(JSON.stringify({ ok: true }))
407
396
  return
408
397
  }
@@ -444,11 +433,10 @@ export const control = Bun.serve({
444
433
  const match = await resolveWorkspace(ws, data.path)
445
434
  if (!match) return
446
435
  const workspacePath = match.path
447
- const layout = await loadLayout(workspacePath)
448
436
 
449
437
  // Listing mode — no theme setting requested
450
438
  if (!data.font && !data.color && !data.radius && !data.agent) {
451
- const theme = resolveWorkspaceTheme(layout.theme)
439
+ const theme = resolveWorkspaceTheme((await loadLayout(workspacePath)).theme)
452
440
  ws.send(
453
441
  JSON.stringify({
454
442
  currentFont: theme.font,
@@ -460,7 +448,7 @@ export const control = Bun.serve({
460
448
  return
461
449
  }
462
450
 
463
- const result = applyThemeUpdate(layout.theme, {
451
+ const result = applyThemeUpdate(undefined, {
464
452
  font: data.font,
465
453
  color: data.color,
466
454
  radius: data.radius,
@@ -471,8 +459,11 @@ export const control = Bun.serve({
471
459
  return
472
460
  }
473
461
 
474
- await saveLayout({ ...layout, theme: result.theme }, workspacePath)
475
- publishEvent({ type: 'theme:updated', workspaceId: match.id })
462
+ await updateLayout(workspacePath, layout => ({
463
+ ...layout,
464
+ theme: resolveWorkspaceTheme({ ...layout.theme, ...result.applied })
465
+ }))
466
+ publishEvent({ type: 'workspace-config:changed', workspaceId: match.id })
476
467
  ws.send(JSON.stringify({ ok: true, ...result.applied }))
477
468
  return
478
469
  }
@@ -515,7 +506,7 @@ export const control = Bun.serve({
515
506
  }
516
507
 
517
508
  await setWorkspaceConfig(workspacePath, patch)
518
- publishEvent({ type: 'workspace:updated', workspaceId: match.id })
509
+ publishEvent({ type: 'workspace-config:changed', workspaceId: match.id })
519
510
  ws.send(
520
511
  JSON.stringify({
521
512
  ok: true,
package/server/events.ts CHANGED
@@ -1,24 +1,25 @@
1
- // Live-event channel: server → browser push over the `/api/workspaces/ws`
2
- // socket. Bundles, the control server, and the REST API publish build/refresh/
3
- // identity events (`applets:refresh`, `theme:updated`, `workspace:updated`, …)
4
- // here; every subscribed browser receives them. This is not a transport of its
5
- // own — it rides the Bun WebSocket pub/sub already open for that route.
6
- //
7
- // The publisher is the Bun.serve instance created in web.ts, wired in via
8
- // `setEventServer` once it exists. Keeping `publishEvent` in its own module lets
9
- // web.ts, control.ts, and the Hono API all publish without forming an import
10
- // cycle through web.ts (which binds ports on load).
1
+ import { isSharedWorkspaceEvent, type ServerEvent } from '@/lib/events'
11
2
 
12
3
  export const EVENTS_TOPIC = 'events'
4
+ export const HARNESS_EVENTS_TOPIC = 'harness-events'
5
+ export const workspaceEventsTopic = (workspaceId: string) => `workspace-events:${workspaceId}`
13
6
 
14
7
  type EventPublisher = { publish: (topic: string, data: string) => unknown }
15
-
16
8
  let publisher: EventPublisher | null = null
17
9
 
18
10
  export function setEventServer(server: EventPublisher) {
19
11
  publisher = server
20
12
  }
21
13
 
22
- export function publishEvent(msg: unknown) {
23
- publisher?.publish(EVENTS_TOPIC, JSON.stringify(msg))
14
+ export function publishEvent(msg: ServerEvent) {
15
+ if (isSharedWorkspaceEvent(msg)) {
16
+ const { workspaceId, ...event } = msg
17
+ publisher?.publish(workspaceEventsTopic(workspaceId), JSON.stringify(event))
18
+ if (msg.type === 'workspace-config:changed') {
19
+ publisher?.publish(EVENTS_TOPIC, JSON.stringify({ type: 'workspaces-list:changed' }))
20
+ }
21
+ } else {
22
+ const harness = msg.type === 'harness:changed' || msg.type === 'workspace-harness:switched'
23
+ publisher?.publish(harness ? HARNESS_EVENTS_TOPIC : EVENTS_TOPIC, JSON.stringify(msg))
24
+ }
24
25
  }
@@ -43,24 +43,24 @@ mirrors upstream code verbatim and stays in `openclaw/strip.ts`.)
43
43
 
44
44
  Socket-protocol notes the layers rely on (all defined in `lib/types.ts`):
45
45
 
46
- - **`session_renamed`** — a new thread is created under the client's temporary
46
+ - **`session:renamed`** — a new thread is created under the client's temporary
47
47
  uuid, then rekeyed to the backend's real session/thread id.
48
- - **`sessions_changed`** — a provider changed session-list metadata such as a
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
50
+ - **`session:archived`** — a chat was archived; clients remove it from caches and
51
51
  clear its selections and pin, including browser-local Collab selections.
52
52
  - **Optimistic-id rendezvous** — the client sends `optimisticId` with each
53
53
  chat; the user's bubble must upsert under that id. Backends differ: Codex
54
54
  echoes it natively (`clientUserMessageId` → `clientId`), Claude Code never
55
55
  echoes (the server synthesizes the turn), OpenClaw echoes lagged (matched
56
56
  by text).
57
- - **`status` / `status_snapshot`** — per-session `activity`
57
+ - **`session:status` / `sessions:status-snapshot`** — per-session `activity`
58
58
  (`idle | running | requires-action`), mirrored from the backend's native
59
59
  lifecycle signal — never derived by counting sends vs results. The snapshot
60
60
  (sent on connect and re-broadcast periodically) is authoritative: the client
61
61
  rebuilds its whole activity map from it, so a lost terminal frame self-heals.
62
62
  `requires-action` suppresses the loader.
63
- - **`preview`** — live token frames, cumulative text, never persisted;
63
+ - **`session:preview`** — live token frames, cumulative text, never persisted;
64
64
  cleared when the turn with matching `meta.apiMessageId` lands.
65
65
 
66
66
  ## Folder layout & conventions
@@ -184,7 +184,7 @@ built on the provider-agnostic `acp/` layer. Session create/resume with temp-id
184
184
  rename, `session/load` history replay, interrupt via `session/cancel`, per-turn
185
185
  token usage, token streaming for thinking _and_ text, inline base64 images,
186
186
  per-chat model switching from the catalog `session/new` returns inline, and
187
- backend-generated session titles surfaced through `sessions_changed`. Agents are
187
+ backend-generated session titles surfaced through `sessions:changed`. Agents are
188
188
  Hermes **profiles** — discovered from `$HERMES_HOME`, imported with
189
189
  `moi hermes init <profile>`, never created from the UI (OpenClaw's model).
190
190
  Sessions run in Hermes's `dont_ask` mode to match Moi's bypass-permissions trust
@@ -235,7 +235,7 @@ code. The attempt ID rejects submissions from an older login. Startup reports
235
235
 
236
236
  During login, the server rechecks readiness until the provider confirms
237
237
  completion and readiness succeeds, or the attempt fails or reaches its
238
- ten-minute deadline. Shutdown cancels active attempts. Auth changes publish `harness-status:changed` once for all consumers. The client
238
+ ten-minute deadline. Shutdown cancels active attempts. Auth changes publish `harness:changed` once for all consumers. The client
239
239
  shares one status query across onboarding and workspace navigation. It
240
240
  reads cached status on focus, reconnect, and authentication changes, and polls only during
241
241
  an active login.
@@ -12,7 +12,7 @@ import type { MessageAttachment } from '@/lib/types'
12
12
  //
13
13
  // Lifecycle notes:
14
14
  // - A brand-new session is created under the client's temporary uuid, then
15
- // renamed to the agent's real session id (`session_renamed`) — same flow
15
+ // renamed to the agent's real session id (`session:renamed`) — same flow
16
16
  // as the Claude Code, OpenClaw and Codex paths.
17
17
  // - ACP has no steer: a send that lands mid-turn is queued and flushed when
18
18
  // the running turn resolves.
@@ -159,7 +159,7 @@ function setProcessing(rec: SessionRecord, processing: boolean) {
159
159
  if (rec.processing === processing) return
160
160
  rec.processing = processing
161
161
  broadcast(rec.workspaceId, {
162
- type: 'status',
162
+ type: 'session:status',
163
163
  sessionId: rec.sessionId,
164
164
  activity: processing ? 'running' : 'idle'
165
165
  })
@@ -184,7 +184,7 @@ function emitTurnEvent(rec: SessionRecord, ev: StreamEvent) {
184
184
  function forwardPreview(rec: SessionRecord) {
185
185
  if (!rec.stream || rec.replaying) return
186
186
  broadcast(rec.workspaceId, {
187
- type: 'preview',
187
+ type: 'session:preview',
188
188
  sessionId: rec.sessionId,
189
189
  messageId: rec.acc.currentId,
190
190
  parentToolUseId: null,
@@ -323,7 +323,7 @@ function handleSessionUpdate(rec: SessionRecord, update: SessionUpdate, provider
323
323
  case 'session_info_update': {
324
324
  // The backend generated or refreshed a session title.
325
325
  if (!rec.replaying) {
326
- broadcast(rec.workspaceId, { type: 'sessions_changed', sessionId: rec.sessionId })
326
+ broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
327
327
  }
328
328
  return
329
329
  }
@@ -641,7 +641,11 @@ export async function sendAcpMessage(
641
641
  }
642
642
  }
643
643
  } catch (err) {
644
- broadcast(input.workspaceId, { type: 'status', sessionId: input.sessionId, activity: 'idle' })
644
+ broadcast(input.workspaceId, {
645
+ type: 'session:status',
646
+ sessionId: input.sessionId,
647
+ activity: 'idle'
648
+ })
645
649
  broadcast(input.workspaceId, {
646
650
  kind: 'error',
647
651
  sessionId: input.sessionId,
@@ -7,12 +7,6 @@ import { publishEvent } from '../events'
7
7
  import { harnessFor } from './registry'
8
8
  import type { HarnessWorkspace, HarnessLoginAttempt } from './types'
9
9
 
10
- export type HarnessUpdatedEvent = {
11
- type: 'harness:updated'
12
- workspaceId: string
13
- availability: HarnessAvailability
14
- }
15
-
16
10
  // Readiness can target a harness account or an individual workspace.
17
11
  type HarnessTarget = HarnessType | HarnessWorkspace
18
12
 
@@ -23,8 +17,7 @@ function entryKey(context: HarnessTarget): string {
23
17
  export type HarnessStoreOptions = {
24
18
  probe: (ws: HarnessTarget) => Promise<HarnessAvailability>
25
19
  startLogin: (harness: HarnessType) => Promise<HarnessLoginAttempt>
26
- publish: (event: HarnessUpdatedEvent) => void
27
- onAuthChanged?: (harness: HarnessType, availability: HarnessAvailability) => Promise<void>
20
+ publish: () => void
28
21
  availabilityTtlMs?: number
29
22
  loginPollMs?: number
30
23
  loginDeadlineMs?: number
@@ -77,15 +70,6 @@ export function createHarnessStore(options: HarnessStoreOptions) {
77
70
  return entry
78
71
  }
79
72
 
80
- async function publish(context: HarnessTarget, availability: HarnessAvailability) {
81
- if (typeof context === 'string') return options.onAuthChanged?.(context, availability)
82
- options.publish({
83
- type: 'harness:updated',
84
- workspaceId: context.id,
85
- availability
86
- })
87
- }
88
-
89
73
  async function probeFresh(ws: HarnessTarget): Promise<HarnessAvailability> {
90
74
  const entry = entryFor(ws)
91
75
  if (!entry.probe) {
@@ -115,7 +99,7 @@ export function createHarnessStore(options: HarnessStoreOptions) {
115
99
  // out from outside moi — a `codex logout` in a terminal, say).
116
100
  async function refresh(ws: HarnessTarget): Promise<HarnessAvailability> {
117
101
  const value = await probeFresh(ws)
118
- await publish(ws, value)
102
+ options.publish()
119
103
  return value
120
104
  }
121
105
 
@@ -144,7 +128,7 @@ export function createHarnessStore(options: HarnessStoreOptions) {
144
128
  const entry = entryFor(harness)
145
129
  if (value.status === 'available' && (!login.attempt?.completed || login.completed)) {
146
130
  entry.login = undefined
147
- await publish(harness, value)
131
+ options.publish()
148
132
  return
149
133
  }
150
134
  if (Date.now() >= deadline) {
@@ -152,12 +136,12 @@ export function createHarnessStore(options: HarnessStoreOptions) {
152
136
  // startLogin replaces it.
153
137
  stopLogin(login)
154
138
  login.state = { state: 'failed', reason: 'Sign-in did not complete. Try again' }
155
- await publish(harness, value)
139
+ options.publish()
156
140
  return
157
141
  }
158
142
  if (!sameAvailability(value, publishedAvailability)) {
159
143
  publishedAvailability = value
160
- await publish(harness, value)
144
+ options.publish()
161
145
  }
162
146
  timer = setTimeout(tick, pollMs)
163
147
  timer.unref?.()
@@ -208,7 +192,7 @@ export function createHarnessStore(options: HarnessStoreOptions) {
208
192
  status: 'login-required',
209
193
  reason: 'Waiting for sign-in'
210
194
  }
211
- await publish(harness, availability)
195
+ options.publish()
212
196
  if (login.state.state === 'pending') watch(harness, login, availability)
213
197
  return result
214
198
  } catch (err) {
@@ -284,12 +268,5 @@ export const harnessStore = createHarnessStore({
284
268
  if (!start) throw new Error('This agent requires terminal sign-in')
285
269
  return start()
286
270
  },
287
- publish: publishEvent,
288
- onAuthChanged: async (harness, availability) => {
289
- publishEvent({
290
- type: 'harness-status:changed',
291
- harness: harness,
292
- status: { availability, login: harnessStore.getLogin(harness) }
293
- })
294
- }
271
+ publish: () => publishEvent({ type: 'harness:changed' })
295
272
  })
@@ -287,7 +287,11 @@ function publishMessageActivity(messages: SessionMessages) {
287
287
  const activity = messageActivity(messages)
288
288
  if (messages.publishedActivity === activity) return
289
289
  messages.publishedActivity = activity
290
- broadcast(messages.workspaceId, { type: 'status', sessionId: messages.sessionId, activity })
290
+ broadcast(messages.workspaceId, {
291
+ type: 'session:status',
292
+ sessionId: messages.sessionId,
293
+ activity
294
+ })
291
295
  }
292
296
 
293
297
  function clearIdle(s: LiveSession) {
@@ -372,7 +376,7 @@ function startClaudeSessionTitleJob(s: LiveSession) {
372
376
  isCurrent: () => isCurrentLiveSession(s, abort)
373
377
  })
374
378
  if (!renamed || !isCurrentLiveSession(s, abort)) return
375
- broadcast(s.workspaceId, { type: 'sessions_changed', sessionId: s.sessionId })
379
+ broadcast(s.workspaceId, { type: 'sessions:changed', sessionId: s.sessionId })
376
380
  debug(
377
381
  `cc session title ws=${s.workspaceId} session=${s.sessionId} title=${JSON.stringify(title)}`
378
382
  )
@@ -443,7 +447,7 @@ async function consume(s: LiveSession) {
443
447
  if (ev.kind === 'preview') {
444
448
  // Token previews are transient and stay outside transcript history.
445
449
  broadcast(s.workspaceId, {
446
- type: 'preview',
450
+ type: 'session:preview',
447
451
  sessionId: s.sessionId,
448
452
  messageId: ev.preview.messageId,
449
453
  parentToolUseId: ev.preview.parentToolUseId,
@@ -521,7 +525,7 @@ async function consume(s: LiveSession) {
521
525
  debug(`cc result ws=${s.workspaceId} session=${s.sessionId} subtype=${msg.subtype}`)
522
526
  if (s.refreshSessionsOnResult) {
523
527
  s.refreshSessionsOnResult = false
524
- broadcast(s.workspaceId, { type: 'sessions_changed', sessionId: s.sessionId })
528
+ broadcast(s.workspaceId, { type: 'sessions:changed', sessionId: s.sessionId })
525
529
  }
526
530
  // Without state events, only a result that finishes the active prompt
527
531
  // (or an autonomous turn when none is active) can release the queue.
@@ -55,7 +55,7 @@ reach the harness's 30-second RPC timeout before Bun closes the connection.
55
55
  ## Session lifecycle
56
56
 
57
57
  - A new chat starts under a temporary Moi id. `thread/start` supplies the real
58
- id; `session_renamed` rekeys the chat, saved settings, and pending-build references.
58
+ id; `session:renamed` rekeys the chat, saved settings, and pending-build references.
59
59
  - View handoffs pass the source chat's saved model to `thread/fork`. Codex 0.160.0
60
60
  otherwise starts the fork with the configured default; switching an active-source
61
61
  fork to `gpt-6.1-sol` on its first turn can fail with a `rustponsesapi` model error.
@@ -97,7 +97,7 @@ type SessionRecord = {
97
97
  }
98
98
 
99
99
  const sessions = new Map<string, SessionRecord>() // key: `${workspaceId}:${sessionId}`
100
- // `${workspaceId}:${tempId}` -> native thread id after session_renamed.
100
+ // `${workspaceId}:${tempId}` -> native thread id after session:renamed.
101
101
  const aliases = new Map<string, string>()
102
102
  const resumes = new Map<string, Promise<SessionRecord>>()
103
103
  type SendLane = { tail: Promise<void>; generation: number }
@@ -206,7 +206,7 @@ function publishActivity(rec: SessionRecord) {
206
206
  if (rec.activity === activity) return
207
207
  rec.activity = activity
208
208
  broadcast(rec.workspaceId, {
209
- type: 'status',
209
+ type: 'session:status',
210
210
  sessionId: rec.sessionId,
211
211
  activity
212
212
  })
@@ -349,7 +349,7 @@ function flushPreviews(rec: SessionRecord) {
349
349
  const entry = rec.previews.get(itemId)
350
350
  if (!entry) continue
351
351
  broadcast(rec.workspaceId, {
352
- type: 'preview',
352
+ type: 'session:preview',
353
353
  sessionId: rec.sessionId,
354
354
  messageId: itemId,
355
355
  parentToolUseId: null,
@@ -629,7 +629,7 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
629
629
  setProcessing(rec, false, null)
630
630
  if (rec.refreshSessionsOnTurnComplete) {
631
631
  rec.refreshSessionsOnTurnComplete = false
632
- broadcast(rec.workspaceId, { type: 'sessions_changed', sessionId: rec.sessionId })
632
+ broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
633
633
  }
634
634
  if (turn?.status === 'failed' && turn.error?.message) {
635
635
  broadcast(rec.workspaceId, {
@@ -682,7 +682,7 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
682
682
  if (status?.type === 'active') setProcessing(rec, true, rec.activeTurnId)
683
683
  else if (status?.type === 'notLoaded') {
684
684
  releaseSession(rec, 'ChatGPT unloaded this chat')
685
- broadcast(rec.workspaceId, { type: 'sessions_changed', sessionId: rec.sessionId })
685
+ broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
686
686
  } else if (status?.type === 'idle' || status?.type === 'systemError') {
687
687
  flushCommandOutput(rec)
688
688
  setProcessing(rec, false, null)
@@ -694,12 +694,12 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
694
694
  case 'thread/archived':
695
695
  case 'thread/deleted': {
696
696
  releaseSession(rec, 'ChatGPT closed this chat')
697
- broadcast(rec.workspaceId, { type: 'sessions_changed', sessionId: rec.sessionId })
697
+ broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
698
698
  return
699
699
  }
700
700
  case 'thread/unarchived':
701
701
  case 'thread/name/updated': {
702
- broadcast(rec.workspaceId, { type: 'sessions_changed', sessionId: rec.sessionId })
702
+ broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
703
703
  return
704
704
  }
705
705
  // Reuse the notice id so completion updates the hook's started row.
@@ -765,7 +765,7 @@ function startCodexSessionTitleJob(rec: SessionRecord, client: CodexClient) {
765
765
  isCurrent: () => isCurrentCodexSession(rec, abort)
766
766
  })
767
767
  if (!renamed || !isCurrentCodexSession(rec, abort)) return
768
- broadcast(rec.workspaceId, { type: 'sessions_changed', sessionId: rec.sessionId })
768
+ broadcast(rec.workspaceId, { type: 'sessions:changed', sessionId: rec.sessionId })
769
769
  debug(
770
770
  `codex session title ws=${rec.workspaceId} thread=${rec.sessionId} title=${JSON.stringify(title)}`
771
771
  )
@@ -989,7 +989,11 @@ async function sendMessage(
989
989
  } catch (err) {
990
990
  // No session record exists to run setProcessing through — clear the
991
991
  // client's optimistic spinner explicitly or it sticks until reconnect.
992
- broadcast(input.workspaceId, { type: 'status', sessionId: input.sessionId, activity: 'idle' })
992
+ broadcast(input.workspaceId, {
993
+ type: 'session:status',
994
+ sessionId: input.sessionId,
995
+ activity: 'idle'
996
+ })
993
997
  broadcast(input.workspaceId, {
994
998
  kind: 'error',
995
999
  sessionId: input.sessionId,
@@ -1144,7 +1148,11 @@ export async function interruptCodexRun(input: {
1144
1148
  broadcast(input.workspaceId, { kind: 'stopped', sessionId: rec?.sessionId ?? input.sessionId })
1145
1149
  if (rec) setProcessing(rec, false, null)
1146
1150
  else
1147
- broadcast(input.workspaceId, { type: 'status', sessionId: input.sessionId, activity: 'idle' })
1151
+ broadcast(input.workspaceId, {
1152
+ type: 'session:status',
1153
+ sessionId: input.sessionId,
1154
+ activity: 'idle'
1155
+ })
1148
1156
  return
1149
1157
  }
1150
1158
  try {
@@ -211,7 +211,7 @@ rediscovered on the next snapshot instead of on every one.
211
211
  | `agent_thought_chunk` | token deltas | thinking parts |
212
212
  | `tool_call` | `toolCallId`, `title`, `kind`, `locations`, `content` | `ToolCall` start |
213
213
  | `tool_call_update` | `status: completed\|failed`, `content` | `ToolCall` result |
214
- | `session_info_update` | generated `title`, `updatedAt` | `sessions_changed` |
214
+ | `session_info_update` | generated `title`, `updatedAt` | `sessions:changed` |
215
215
  | `available_commands_update` | slash commands | init metadata |
216
216
  | `usage_update` | context `size` / `used` | context meter |
217
217
  | `user_message_chunk` | replayed user turns | history only (§3.6) |
@@ -807,14 +807,14 @@ returns `{}` but only drops the live session; the chat still lists. There is no
807
807
  `session/archive` at all.
808
808
 
809
809
  Hermes _does_ have the right primitive internally —
810
- `hermes_state.SessionDB.set_session_archived(session_id, archived)`, a soft hide
810
+ `hermes_state.SessionDB.set_session:archived(session_id, archived)`, a soft hide
811
811
  that keeps every message and walks the whole compression chain (archiving only
812
812
  the visible tip lets the still-unarchived root resurrect it). Its `sessions`
813
813
  table has an `archived` column, and `list_sessions_rich` takes
814
814
  `include_archived: bool = False`, which the ACP adapter never overrides — so an
815
815
  archived session would drop out of `session/list` for free.
816
816
 
817
- The problem is reach: the only callers of `set_session_archived` are HTTP routes
817
+ The problem is reach: the only callers of `set_session:archived` are HTTP routes
818
818
  on `hermes serve` and the gateway API server, daemons Moi deliberately does not
819
819
  run (§6). The `hermes sessions archive` CLI is filter-based (age, source, title,
820
820
  cwd — no session id), and `hermes sessions delete <id>` is a real delete.