moi-computer 0.3.0-next.1 → 0.3.0-next.3

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 (206) hide show
  1. package/README.md +1 -1
  2. package/bunfig.toml +5 -1
  3. package/client/AGENTS.md +17 -2
  4. package/client/accept-hmr-dependencies.ts +22 -0
  5. package/client/api/http.ts +31 -0
  6. package/client/api/query-options.ts +6 -0
  7. package/client/api/workspace-keys.ts +18 -0
  8. package/client/app/AppRouter.tsx +44 -0
  9. package/client/app/routes/HomeRoute.tsx +13 -0
  10. package/client/app/routes/WorkspaceRoute.tsx +95 -0
  11. package/client/app/shell/SidebarLayout.tsx +196 -0
  12. package/client/assets/openai.svg +3 -0
  13. package/client/assets.d.ts +9 -0
  14. package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +2 -2
  15. package/client/components/shared/PanelHeader.tsx +9 -0
  16. package/client/components/shared/ReorderableList.tsx +199 -0
  17. package/client/components/ui/button.tsx +11 -7
  18. package/client/components/ui/collapsible.tsx +15 -0
  19. package/client/components/ui/dialog.tsx +2 -2
  20. package/client/components/ui/dropdown-menu.tsx +5 -5
  21. package/client/components/ui/hover-card.tsx +1 -1
  22. package/client/components/ui/input.tsx +1 -1
  23. package/client/components/ui/popover.tsx +1 -1
  24. package/client/components/ui/skeleton.tsx +13 -0
  25. package/client/components/ui/tooltip.tsx +1 -1
  26. package/client/externalize-react.ts +7 -1
  27. package/client/features/applets/AppletMount.tsx +44 -0
  28. package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
  29. package/client/{components → features/applets}/WidgetShell.tsx +5 -2
  30. package/client/{lib → features/applets}/applet-cache.ts +8 -0
  31. package/client/features/applets/applet-styles.ts +61 -0
  32. package/client/{hooks → features/applets}/useApplet.ts +6 -7
  33. package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +30 -24
  34. package/client/features/chat/ChatPanel.tsx +171 -0
  35. package/client/{components → features/chat}/ChatPopup.tsx +24 -13
  36. package/client/{components/ThreadSelector.tsx → features/chat/ChatSelector.tsx} +15 -13
  37. package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
  38. package/client/{components → features/chat}/ModelPicker.tsx +68 -17
  39. package/client/{components → features/chat}/TurnView.tsx +17 -11
  40. package/client/features/chat/api.ts +78 -0
  41. package/client/features/chat/chat-connection.ts +107 -0
  42. package/client/features/chat/chat-frames.ts +131 -0
  43. package/client/features/chat/chat-send.ts +57 -0
  44. package/client/{lib → features/chat}/preview-turn.ts +1 -1
  45. package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
  46. package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
  47. package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
  48. package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +14 -5
  49. package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
  50. package/client/{components → features/chat}/tool-group/format.ts +117 -0
  51. package/client/{hooks → features/chat}/useChat.ts +16 -44
  52. package/client/features/connectors/ConnectorsPage.tsx +92 -0
  53. package/client/features/connectors/McpMenu.tsx +145 -0
  54. package/client/features/connectors/api.ts +28 -0
  55. package/client/features/dev/DevRoutes.tsx +18 -0
  56. package/client/features/dev/HarnessDebugPage.tsx +468 -0
  57. package/client/{components/playground → features/dev}/PixelPainter.tsx +10 -21
  58. package/client/{components/playground → features/dev}/PlaygroundPage.tsx +10 -12
  59. package/client/{components/playground → features/dev}/ToolCallsPage.tsx +9 -11
  60. package/client/features/home/CreateWorkspaceDialog.tsx +130 -0
  61. package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
  62. package/client/features/home/HomeLogo.tsx +344 -0
  63. package/client/features/home/HomePage.tsx +214 -0
  64. package/client/{components → features/home}/WorkspacePreview.tsx +4 -4
  65. package/client/features/home/api.ts +156 -0
  66. package/client/features/home/workspace-presentation.tsx +44 -0
  67. package/client/features/scratchpad/Scratchpad.tsx +312 -0
  68. package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
  69. package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
  70. package/client/features/settings/EnvironmentSettings.tsx +149 -0
  71. package/client/features/settings/GeneralSettings.tsx +90 -0
  72. package/client/{components → features}/settings/IconPicker.tsx +76 -224
  73. package/client/features/settings/SettingsLayout.tsx +53 -0
  74. package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
  75. package/client/features/settings/api.ts +88 -0
  76. package/client/features/settings/icon-picker-options.ts +30 -0
  77. package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
  78. package/client/features/views/ViewBuilderTab.tsx +153 -0
  79. package/client/features/views/api.ts +124 -0
  80. package/client/features/views/useViewBuilderActions.ts +72 -0
  81. package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
  82. package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
  83. package/client/{components → features/widgets}/WidgetGrid.tsx +38 -29
  84. package/client/features/widgets/Widgets.tsx +265 -0
  85. package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
  86. package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
  87. package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
  88. package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +16 -15
  89. package/client/features/workspace/WorkspaceScreen.tsx +675 -0
  90. package/client/features/workspace/WorkspaceTabs.tsx +205 -0
  91. package/client/features/workspace/api.ts +56 -0
  92. package/client/features/workspace/useFitsSplitLayout.ts +37 -0
  93. package/client/global.d.ts +5 -0
  94. package/client/index.css +6 -45
  95. package/client/index.html +2 -2
  96. package/client/index.tsx +14 -31
  97. package/client/lib/app-icon-registry.ts +145 -0
  98. package/client/main.tsx +2 -2
  99. package/client/runtime/hmr-watchdog.ts +39 -0
  100. package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +12 -7
  101. package/client/store/ui.ts +5 -1
  102. package/client/theme.css +1 -3
  103. package/dist/chunk-11cab5dq.css +1 -0
  104. package/dist/chunk-4vf1t6v1.js +10 -0
  105. package/dist/chunk-6c24yndg.js +61 -0
  106. package/dist/chunk-6c8cwpzc.js +1 -0
  107. package/dist/chunk-b4b276wx.js +15 -0
  108. package/dist/chunk-cs8vbert.js +546 -0
  109. package/dist/chunk-cwqmay73.css +1 -0
  110. package/dist/chunk-kxmvv1ax.js +48 -0
  111. package/dist/chunk-pcnahct1.js +5 -0
  112. package/dist/chunk-rq0ar7vp.js +1 -0
  113. package/dist/chunk-tqd3pkg8.css +1 -0
  114. package/dist/chunk-vkvb3hjm.js +2 -0
  115. package/dist/chunk-zpxrb1ce.js +2 -0
  116. package/dist/index.html +3 -3
  117. package/dist/openai-h13pza4b.svg +3 -0
  118. package/lib/format.ts +2 -2
  119. package/lib/types.ts +56 -9
  120. package/lib/view-builder-meta.ts +35 -0
  121. package/lib/workspace-layout.ts +14 -0
  122. package/lib/workspace-name.ts +14 -0
  123. package/package.json +4 -2
  124. package/server/AGENTS.md +3 -3
  125. package/server/api.ts +279 -60
  126. package/server/applets.ts +1 -1
  127. package/server/bundle-queue.ts +19 -0
  128. package/server/bundler/applet-css.ts +50 -0
  129. package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
  130. package/server/cli.ts +90 -7
  131. package/server/control.ts +106 -8
  132. package/server/env-apply.ts +2 -2
  133. package/server/harness/README.md +228 -0
  134. package/server/harness/claude-code/NOTES.md +578 -0
  135. package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
  136. package/server/harness/claude-code/index.ts +124 -0
  137. package/server/{mcp.ts → harness/claude-code/mcp.ts} +73 -16
  138. package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
  139. package/server/harness/claude-code/sessions.ts +42 -0
  140. package/server/harness/codex/NOTES.md +239 -0
  141. package/server/harness/codex/adapter.ts +414 -0
  142. package/server/harness/codex/client.ts +343 -0
  143. package/server/harness/codex/index.ts +68 -0
  144. package/server/harness/codex/probe.ts +186 -0
  145. package/server/harness/codex/session.ts +617 -0
  146. package/server/harness/debug.ts +57 -0
  147. package/server/harness/openclaw/NOTES.md +316 -0
  148. package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
  149. package/server/harness/openclaw/index.ts +93 -0
  150. package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
  151. package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
  152. package/server/harness/registry.ts +36 -0
  153. package/server/harness/types.ts +87 -0
  154. package/server/layout.ts +36 -11
  155. package/server/moi-scaffold.ts +56 -11
  156. package/server/registry.ts +30 -52
  157. package/server/state.ts +5 -38
  158. package/server/status.ts +7 -46
  159. package/server/vendor.ts +1 -1
  160. package/server/view-builders.ts +428 -0
  161. package/server/views.ts +0 -0
  162. package/server/web.ts +19 -40
  163. package/server/workspace-init.ts +11 -25
  164. package/tsconfig.json +1 -1
  165. package/workspace/.claude/skills/moi-workspace/DESIGN.md +2 -1
  166. package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
  167. package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
  168. package/client/api/workspaces.ts +0 -427
  169. package/client/assets/hermes-nous.png +0 -0
  170. package/client/components/App.tsx +0 -41
  171. package/client/components/ChatPanel.tsx +0 -275
  172. package/client/components/HomePage.tsx +0 -17
  173. package/client/components/McpMenu.tsx +0 -125
  174. package/client/components/Scratchpad.tsx +0 -935
  175. package/client/components/Widgets.tsx +0 -132
  176. package/client/components/WorkspacesPage.tsx +0 -245
  177. package/client/components/layout/SidebarLayout.tsx +0 -258
  178. package/client/components/routes/workspace/[id].tsx +0 -675
  179. package/client/components/routes/workspace/create.tsx +0 -155
  180. package/client/components/settings/SettingsPages.tsx +0 -255
  181. package/client/hooks/useFitsSidebar.ts +0 -34
  182. package/client/hooks/useScrollFade.ts +0 -38
  183. package/client/lib/connection.ts +0 -238
  184. package/dist/chunk-07qf2tv1.css +0 -1
  185. package/dist/chunk-w18801vn.js +0 -672
  186. package/dist/hermes-nous-pznd63x9.png +0 -0
  187. /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
  188. /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
  189. /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
  190. /package/client/{lib → features/chat}/group-turns.ts +0 -0
  191. /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
  192. /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
  193. /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
  194. /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
  195. /package/client/{components → features/chat}/tool-group/index.ts +0 -0
  196. /package/client/{lib → features/chat}/uploads.ts +0 -0
  197. /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
  198. /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
  199. /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
  200. /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
  201. /package/client/{lib → features/settings}/render-icon.ts +0 -0
  202. /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
  203. /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
  204. /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
  205. /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
  206. /package/server/{openclaw-gateway.ts → harness/openclaw/gateway.ts} +0 -0
package/server/layout.ts CHANGED
@@ -1,12 +1,36 @@
1
1
  import { readdir } from 'node:fs/promises'
2
2
  import { join } from 'path'
3
3
 
4
- import type { WidgetConfig, WorkspaceLayout, WorkspacePreview } from '@/lib/types'
4
+ import type { WidgetConfig, WorkspaceLayout, WorkspacePreview, WorkspaceTabId } from '@/lib/types'
5
+ import { createDefaultWorkspaceLayout, createDefaultWorkspaceTabs } from '@/lib/workspace-layout'
5
6
 
6
- const DEFAULT: WorkspaceLayout = {
7
- version: 1,
8
- widgetGrid: [],
9
- chatMode: 'sidebar'
7
+ function isTabId(value: unknown): value is WorkspaceTabId {
8
+ return (
9
+ value === 'agent' ||
10
+ value === 'widgets' ||
11
+ value === 'scratchpad' ||
12
+ (typeof value === 'string' && (/^view:.+/.test(value) || /^view-builder:.+/.test(value)))
13
+ )
14
+ }
15
+
16
+ function normalizeTabs(value: unknown): WorkspaceLayout['tabs'] {
17
+ if (!value || typeof value !== 'object') return createDefaultWorkspaceTabs()
18
+ const raw = value as Record<string, unknown>
19
+ const open = Array.isArray(raw.open)
20
+ ? raw.open.filter(isTabId).filter((tab, index, all) => all.indexOf(tab) === index)
21
+ : []
22
+ if (open.length === 0) return createDefaultWorkspaceTabs()
23
+ const active = isTabId(raw.active) && open.includes(raw.active) ? raw.active : open[0]
24
+ return { open, active }
25
+ }
26
+
27
+ function normalizeLayout(parsed: Record<string, unknown>): WorkspaceLayout {
28
+ const layout = { ...createDefaultWorkspaceLayout(), ...parsed } as Record<string, unknown>
29
+ if (layout.layoutMode !== 'split') layout.layoutMode = 'fullscreen'
30
+ layout.tabs = normalizeTabs(layout.tabs)
31
+ delete layout.sectionMode
32
+ delete layout.chatMode
33
+ return layout as unknown as WorkspaceLayout
10
34
  }
11
35
 
12
36
  const DEFAULT_WIDGET_CONFIG: WidgetConfig = { rowSpan: 1, colSpan: 2 }
@@ -21,9 +45,9 @@ export async function loadLayout(workspacePath: string): Promise<WorkspaceLayout
21
45
  try {
22
46
  const text = await Bun.file(getLayoutPath(workspacePath)).text()
23
47
  const parsed = JSON.parse(text)
24
- if (parsed?.version === 1) return parsed as WorkspaceLayout
48
+ if (parsed?.version === 1) return normalizeLayout(parsed)
25
49
  } catch {}
26
- return { ...DEFAULT }
50
+ return createDefaultWorkspaceLayout()
27
51
  }
28
52
 
29
53
  export async function saveLayout(layout: WorkspaceLayout, workspacePath: string): Promise<void> {
@@ -32,10 +56,11 @@ export async function saveLayout(layout: WorkspaceLayout, workspacePath: string)
32
56
 
33
57
  // Merge a client-submitted layout over the stored one for persistence.
34
58
  //
35
- // Everything (grid, chat mode, theme, AND identity) shares one `.workspace.json`,
36
- // but the grid editor and `moi config` own different fields. The client's layout
37
- // PUT is authoritative for the editor fields (widgetGrid, chatMode, theme,
38
- // selectedModel) — but it strips `name` and round-trips a possibly-stale `icon`.
59
+ // Everything (grid, layout mode, theme, AND identity) shares one
60
+ // `.workspace.json`, but the grid editor and `moi config` own different fields.
61
+ // The client's layout PUT is authoritative for the editor fields (widgetGrid,
62
+ // layoutMode, theme, selectedModel) — but it strips `name` and round-trips a
63
+ // possibly-stale `icon`.
39
64
  // A blind overwrite therefore erases a `moi config`-set name (and could revert an
40
65
  // icon). So drop whatever identity the body carries and re-apply the server-owned
41
66
  // `name`/`icon` from `existing` — conditionally, so an absent field never
@@ -6,7 +6,7 @@ import { mkdir } from 'node:fs/promises'
6
6
  import { join, resolve, sep } from 'node:path'
7
7
 
8
8
  // Dependency set available to widgets. `react`/`react-dom` are stubs — at
9
- // runtime they resolve to Moi's locally-vendored ESM via the browser importmap
9
+ // runtime they resolve to moi's locally-vendored ESM via the browser importmap
10
10
  // (/vendor/react); they're listed so editors pick up the correct types.
11
11
  export const MOI_PACKAGE_JSON = {
12
12
  name: 'widgets',
@@ -23,6 +23,32 @@ export const MOI_PACKAGE_JSON = {
23
23
  }
24
24
  } as const
25
25
 
26
+ // Dependency installation is helpful for editor types and widget builds, but
27
+ // it's not critical — the agent installs on demand if it's missing. So it must
28
+ // never block workspace creation: we wait briefly, then let it finish in the
29
+ // background, with a hard kill as a backstop against a hung registry.
30
+ const INSTALL_WAIT_MS = 10_000
31
+ const INSTALL_TIMEOUT_MS = 120_000
32
+
33
+ type InstallDependencies = (moiDir: string) => Promise<number>
34
+
35
+ async function runBunInstall(moiDir: string): Promise<number> {
36
+ const install = Bun.spawn(['bun', 'install'], {
37
+ cwd: moiDir,
38
+ stdout: 'ignore',
39
+ stderr: 'inherit',
40
+ timeout: INSTALL_TIMEOUT_MS,
41
+ killSignal: 'SIGKILL'
42
+ })
43
+ // Don't hold the event loop open for a backgrounded install: a short-lived
44
+ // CLI (`moi init`) must exit after the wait, not linger until the child
45
+ // does. The child survives parent exit and finishes the install on its own
46
+ // (verified: orphaned bun processes complete; only the 2-minute kill is no
47
+ // longer enforced once the parent is gone).
48
+ install.unref()
49
+ return install.exited
50
+ }
51
+
26
52
  // Ambient types for applets (widgets & views). Editor DX only — the moi
27
53
  // bundler resolves the `moi` module and asset imports at build time without any
28
54
  // declarations. Lives at `.moi/` root, NOT inside widgets/views, so it isn't
@@ -55,8 +81,13 @@ declare module '*.svg' { const s: string; export default s }
55
81
  // Bootstraps `.moi/` ONLY when it doesn't exist yet. Re-running `moi init`
56
82
  // on an existing workspace overwrites skills but must leave the user's
57
83
  // `.moi/` (their deps, widgets, lockfile) completely untouched.
58
- // Returns 'exists' when skipped, otherwise the `bun install` exit code.
59
- export async function scaffoldMoiDir(workspacePath: string): Promise<'exists' | number> {
84
+ // Returns 'exists' when skipped, 'installing' when `bun install` outlived the
85
+ // wait and continues in the background, otherwise the install exit code.
86
+ export async function scaffoldMoiDir(
87
+ workspacePath: string,
88
+ installDependencies: InstallDependencies = runBunInstall,
89
+ installWaitMs: number = INSTALL_WAIT_MS
90
+ ): Promise<'exists' | 'installing' | number> {
60
91
  // Backstop against the nested-workspace bug: never scaffold a `.moi/` *inside*
61
92
  // another workspace's `.moi/` (which produces the junk `.moi/.moi`). Callers
62
93
  // (`moi init`) lift to the workspace root via `liftToWorkspaceRoot` first, so
@@ -68,18 +99,32 @@ export async function scaffoldMoiDir(workspacePath: string): Promise<'exists' |
68
99
  )
69
100
  }
70
101
  const moiDir = join(workspacePath, '.moi')
71
- if (await Bun.file(join(moiDir, 'package.json')).exists()) return 'exists'
102
+ const packagePath = join(moiDir, 'package.json')
103
+ if (await Bun.file(packagePath).exists()) return 'exists'
72
104
  // A bare `.moi/` dir without package.json counts as not-bootstrapped —
73
105
  // fill in the missing pieces.
74
106
 
75
107
  await mkdir(join(moiDir, 'widgets'), { recursive: true })
76
- await Bun.write(join(moiDir, 'package.json'), JSON.stringify(MOI_PACKAGE_JSON, null, 2) + '\n')
108
+ await Bun.write(packagePath, JSON.stringify(MOI_PACKAGE_JSON, null, 2) + '\n')
77
109
  await Bun.write(join(moiDir, 'applet-env.d.ts'), APPLET_ENV_DTS)
78
110
 
79
- const install = Bun.spawn(['bun', 'install'], {
80
- cwd: moiDir,
81
- stdout: 'ignore',
82
- stderr: 'inherit'
83
- })
84
- return await install.exited
111
+ const exited = installDependencies(moiDir)
112
+ let timer: ReturnType<typeof setTimeout> | undefined
113
+ const result = await Promise.race([
114
+ exited,
115
+ new Promise<'installing'>(r => (timer = setTimeout(() => r('installing'), installWaitMs)))
116
+ ])
117
+ clearTimeout(timer)
118
+
119
+ if (result === 'installing') {
120
+ console.log(`[scaffold] bun install in ${moiDir} still running — continuing in the background`)
121
+ exited.then(code => {
122
+ if (code === 0) console.log(`[scaffold] background bun install in ${moiDir} finished`)
123
+ else
124
+ console.warn(
125
+ `[scaffold] background bun install in ${moiDir} failed (exit ${code}) — the agent will install deps on demand`
126
+ )
127
+ })
128
+ }
129
+ return result
85
130
  }
@@ -5,7 +5,7 @@ import { join, resolve, sep } from 'path'
5
5
  import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
6
6
 
7
7
  import { DATA_DIR } from './data-dir'
8
- import { type OpenClawAgent, discoverOpenClawAgents } from './openclaw'
8
+ import { allHarnesses } from './harness/registry'
9
9
 
10
10
  // Replace the home-dir prefix with `~` for display. Keeps the original
11
11
  // absolute path in place; callers should put the result in `displayPath`.
@@ -92,6 +92,22 @@ export async function listWorkspaces(): Promise<WorkspaceEntry[]> {
92
92
  return entries.map(withDisplayPath)
93
93
  }
94
94
 
95
+ export async function reorderWorkspaces(ids: string[]): Promise<WorkspaceEntry[]> {
96
+ const entries = await readRegistry()
97
+ if (ids.length !== entries.length) throw new Error('Workspace order must include every workspace')
98
+
99
+ const unique = new Set(ids)
100
+ if (unique.size !== ids.length) throw new Error('Workspace order contains duplicate ids')
101
+
102
+ const byId = new Map(entries.map(e => [e.id, e]))
103
+ const next = ids.map(id => byId.get(id))
104
+ if (next.some(e => !e)) throw new Error('Workspace order contains unknown ids')
105
+
106
+ const ordered = next as WorkspaceEntry[]
107
+ await writeRegistry(ordered)
108
+ return ordered.map(withDisplayPath)
109
+ }
110
+
95
111
  // Resolve a path to the registered workspace that *contains* it: the entry
96
112
  // whose path equals `reqPath` or is its nearest ancestor (longest matching
97
113
  // prefix, git-style). This lets workspace-scoped commands (e.g. `moi bundle`)
@@ -122,58 +138,20 @@ export function liftToWorkspaceRoot(p: string): string {
122
138
  return segments.slice(0, i).join(sep) || sep
123
139
  }
124
140
 
125
- // Discover CC-active directories not yet in the registry
126
- async function discoverFromCC(registeredPaths: Set<string>): Promise<string[]> {
127
- try {
128
- const { listSessions } = await import('@anthropic-ai/claude-agent-sdk')
129
- const sessions = await listSessions({})
130
- const { stat } = await import('node:fs/promises')
131
- const paths = new Set<string>()
132
-
133
- for (const s of sessions) {
134
- if (!s.cwd || registeredPaths.has(s.cwd)) continue
135
- try {
136
- const info = await stat(s.cwd)
137
- if (info.isDirectory()) paths.add(s.cwd)
138
- } catch {}
139
- }
140
-
141
- return [...paths]
142
- } catch {
143
- return []
144
- }
145
- }
146
-
147
- // Discover OpenClaw agents via the gateway WebSocket (2s timeout). Returns []
148
- // if the gateway is unreachable, auth is missing, or probes time out.
149
- async function discoverFromOpenClaw(registeredPaths: Set<string>): Promise<OpenClawAgent[]> {
150
- const agents = await discoverOpenClawAgents()
151
- return agents.filter(a => !registeredPaths.has(a.path))
152
- }
153
-
141
+ // Ask every harness for workspaces it knows about that aren't registered yet.
142
+ // Precedence: entries from a specific backend (OpenClaw agents, Codex threads)
143
+ // win over Claude Code's generic session-history scan when they claim the
144
+ // same path — CC sessions exist in most directories an agent ever ran in.
154
145
  export async function discoverWorkspaces(): Promise<DiscoveredWorkspace[]> {
155
146
  const registeredPaths = new Set((await readRegistry()).map(e => e.path))
156
- const [ccPaths, openclawAgents] = await Promise.all([
157
- discoverFromCC(registeredPaths),
158
- discoverFromOpenClaw(registeredPaths)
159
- ])
160
- const openclawByPath = new Map(openclawAgents.map(a => [a.path, a]))
161
- const out: DiscoveredWorkspace[] = []
162
- for (const a of openclawAgents) {
163
- out.push(
164
- withDisplayPath({
165
- path: a.path,
166
- type: 'openclaw',
167
- ...(a.name ? { name: a.name } : {}),
168
- ...(a.agentId ? { agentId: a.agentId } : {}),
169
- ...(a.isDefault ? { isDefault: a.isDefault } : {}),
170
- ...(a.lastRunAt ? { lastRunAt: a.lastRunAt } : {})
171
- })
147
+ const perHarness = await Promise.all(
148
+ allHarnesses().map(
149
+ h => h.discoverWorkspaces?.(registeredPaths).catch(() => []) ?? Promise.resolve([])
172
150
  )
173
- }
174
- for (const p of ccPaths) {
175
- if (openclawByPath.has(p)) continue
176
- out.push(withDisplayPath({ path: p, type: 'claude-code' }))
177
- }
178
- return out
151
+ )
152
+ const found = perHarness.flat()
153
+ const specific = found.filter(w => w.type !== 'claude-code')
154
+ const specificPaths = new Set(specific.map(w => w.path))
155
+ const generic = found.filter(w => w.type === 'claude-code' && !specificPaths.has(w.path))
156
+ return [...specific, ...generic].map(withDisplayPath)
179
157
  }
package/server/state.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { getSessionMessages, listSessions } from '@anthropic-ai/claude-agent-sdk'
1
+ import type { BroadcastFrame, ServerMessage } from '@/lib/types'
2
2
 
3
- import { ClaudeAdapter } from '@/lib/claude-adapter'
4
- import type { BroadcastFrame, ServerMessage, SessionInfo, StreamEvent } from '@/lib/types'
3
+ import { tapClientFrame } from './harness/debug'
5
4
 
6
5
  // The chat socket is app-wide (one per client tab, not per workspace), so a
7
6
  // single set of all connected chat clients is enough. Each broadcast frame
@@ -23,7 +22,10 @@ export function getClientCount(): number {
23
22
 
24
23
  // Stamp `workspaceId` onto the frame and fan it out to every connected chat
25
24
  // client. (Phase 1: broadcast-all; Phase 2 will scope by topic subscription.)
25
+ // Every frame is also tapped into the per-workspace debug ring so the
26
+ // /playground/harness page can show exactly what clients received.
26
27
  export function broadcast(workspaceId: string, frame: BroadcastFrame) {
28
+ tapClientFrame(workspaceId, { ...frame, workspaceId })
27
29
  const json = JSON.stringify({ ...frame, workspaceId })
28
30
  for (const ws of chatClients) ws.send(json)
29
31
  }
@@ -36,38 +38,3 @@ export function broadcastAll(msg: ServerMessage) {
36
38
  export function sendToClient(ws: Bun.ServerWebSocket<unknown>, msg: ServerMessage) {
37
39
  ws.send(JSON.stringify(msg))
38
40
  }
39
-
40
- export async function getSessions(workspacePath: string): Promise<SessionInfo[]> {
41
- const sessions = await listSessions({ dir: workspacePath })
42
- return sessions.map(s => ({
43
- sessionId: s.sessionId,
44
- summary: s.summary,
45
- lastModified: s.lastModified,
46
- cwd: s.cwd
47
- }))
48
- }
49
-
50
- /**
51
- * Replay a session's persisted raw messages through a fresh adapter and
52
- * return the resulting StreamEvents. Events are carefully NOT deduplicated —
53
- * the client reducer is idempotent under upsert-by-id.
54
- */
55
- export async function getSessionEvents(
56
- sessionId: string,
57
- workspacePath: string
58
- ): Promise<StreamEvent[]> {
59
- const adapter = new ClaudeAdapter()
60
- const events: StreamEvent[] = []
61
- try {
62
- const raw = await getSessionMessages(sessionId, { dir: workspacePath })
63
- for (const msg of raw) {
64
- // Disk replay carries no `stream_event` messages, so the adapter never
65
- // produces previews here — filter defensively to keep this the pure,
66
- // persisted StreamEvent path that reconnect-healing trusts.
67
- for (const ev of adapter.ingest(msg)) if (ev.kind !== 'preview') events.push(ev)
68
- }
69
- } catch {
70
- // session file missing or unreadable — return whatever we have (often [])
71
- }
72
- return events
73
- }
package/server/status.ts CHANGED
@@ -5,11 +5,10 @@
5
5
  // chat appears stuck (loader spinning) and you want to know whether the server
6
6
  // still holds a live session for that thread, or when a widget's server call
7
7
  // hangs and you want to see whether its worker is alive and what it has loaded.
8
- import { type CCDebugSession, SESSION_LIMITS, getCCDebugSnapshot } from './cc-session'
9
8
  import { CONTROL_PORT, PORT } from './constants'
10
9
  import { debugEnabled } from './debug'
11
10
  import { WORKER_LIMITS, type WorkerDebugInfo, getWorkersDebugSnapshot } from './functions'
12
- import { getOpenClawRunningSessions } from './openclaw-session'
11
+ import { allHarnesses } from './harness/registry'
13
12
  import { tildify } from './registry'
14
13
  import { getClientCount } from './state'
15
14
 
@@ -64,31 +63,8 @@ function workerLine(w: WorkerDebugInfo, now: number): string {
64
63
  return line
65
64
  }
66
65
 
67
- function sessionLine(s: CCDebugSession, now: number): string {
68
- const mark = s.busy ? '▶ busy' : s.closed ? '✗ closed' : '○ idle'
69
- const bits = [
70
- mark.padEnd(8),
71
- `ws=${s.workspaceId}`,
72
- `session=${s.sessionId}`,
73
- `model=${s.model ?? 'default'}`,
74
- `effort=${s.effort ?? 'default'}`,
75
- `stream=${s.stream ? 'on' : 'off'}`,
76
- `pending=${s.pendingTurns}`,
77
- `age=${fmtDuration(now - s.createdAt)}`,
78
- `lastActivity=${fmtAgo(s.lastActivityAt, now)}`
79
- ]
80
- if (s.desiredEffort !== s.effort) bits.push(`desiredEffort=${s.desiredEffort ?? 'default'}`)
81
- if (s.desiredStream !== s.stream) bits.push(`desiredStream=${s.desiredStream ? 'on' : 'off'}`)
82
- if (!s.busy && !s.hasIdleTimer) bits.push('(no idle timer)')
83
- let line = ' ' + bits.join(' ')
84
- if (s.lastUserText) line += `\n last: ${JSON.stringify(s.lastUserText)}`
85
- return line
86
- }
87
-
88
66
  export function renderStatus(): string {
89
67
  const now = Date.now()
90
- const cc = getCCDebugSnapshot()
91
- const openclawRunning = getOpenClawRunningSessions()
92
68
 
93
69
  const lines: string[] = []
94
70
  lines.push('moi server status')
@@ -101,28 +77,13 @@ export function renderStatus(): string {
101
77
  lines.push(`connected tabs ${getClientCount()}`)
102
78
  lines.push('')
103
79
 
104
- const busy = cc.sessions.filter(s => s.busy).length
105
- lines.push(
106
- `live CC sessions ${cc.sessions.length}/${SESSION_LIMITS.maxLive} ` +
107
- `(${busy} busy, ${cc.sessions.length - busy} idle, ${cc.aliases} alias${cc.aliases === 1 ? '' : 'es'}, ` +
108
- `idle TTL ${fmtDuration(SESSION_LIMITS.idleTtlMs)})`
109
- )
110
- if (cc.sessions.length === 0) {
111
- lines.push(' (none held in memory — next message will resume from disk)')
112
- } else {
113
- // Busiest / most-recently-active first.
114
- const sorted = [...cc.sessions].sort(
115
- (a, b) => Number(b.busy) - Number(a.busy) || b.lastActivityAt - a.lastActivityAt
116
- )
117
- for (const s of sorted) lines.push(sessionLine(s, now))
118
- }
119
- lines.push('')
120
-
121
- lines.push(`live OpenClaw runs ${openclawRunning.length}`)
122
- for (const r of openclawRunning) {
123
- lines.push(` ▶ busy ws=${r.workspaceId} session=${r.sessionId}`)
80
+ // One section per harness — each formats its own live-session view.
81
+ for (const h of allHarnesses()) {
82
+ const section = h.statusLines?.(now)
83
+ if (!section?.length) continue
84
+ lines.push(...section)
85
+ lines.push('')
124
86
  }
125
- lines.push('')
126
87
 
127
88
  const workers = getWorkersDebugSnapshot()
128
89
  lines.push(
package/server/vendor.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Serves the locally-vendored React ESM (client/vendor/react, generated by
2
2
  // scripts/build-vendor.ts) behind the stable `/vendor/react/*` URLs the
3
- // importmap in client/index.html points at. This is what makes Moi run offline
3
+ // importmap in client/index.html points at. This is what makes moi run offline
4
4
  // — no esm.sh fetch.
5
5
  //
6
6
  // The importmap URLs carry no dev/prod distinction; we pick the build here so