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.
- package/README.md +1 -1
- package/bunfig.toml +5 -1
- package/client/AGENTS.md +17 -2
- package/client/accept-hmr-dependencies.ts +22 -0
- package/client/api/http.ts +31 -0
- package/client/api/query-options.ts +6 -0
- package/client/api/workspace-keys.ts +18 -0
- package/client/app/AppRouter.tsx +44 -0
- package/client/app/routes/HomeRoute.tsx +13 -0
- package/client/app/routes/WorkspaceRoute.tsx +95 -0
- package/client/app/shell/SidebarLayout.tsx +196 -0
- package/client/assets/openai.svg +3 -0
- package/client/assets.d.ts +9 -0
- package/client/components/{BottomPanel.tsx → shared/BottomPanel.tsx} +2 -2
- package/client/components/shared/PanelHeader.tsx +9 -0
- package/client/components/shared/ReorderableList.tsx +199 -0
- package/client/components/ui/button.tsx +11 -7
- package/client/components/ui/collapsible.tsx +15 -0
- package/client/components/ui/dialog.tsx +2 -2
- package/client/components/ui/dropdown-menu.tsx +5 -5
- package/client/components/ui/hover-card.tsx +1 -1
- package/client/components/ui/input.tsx +1 -1
- package/client/components/ui/popover.tsx +1 -1
- package/client/components/ui/skeleton.tsx +13 -0
- package/client/components/ui/tooltip.tsx +1 -1
- package/client/externalize-react.ts +7 -1
- package/client/features/applets/AppletMount.tsx +44 -0
- package/client/{components → features/applets}/WidgetErrorBoundary.tsx +1 -1
- package/client/{components → features/applets}/WidgetShell.tsx +5 -2
- package/client/{lib → features/applets}/applet-cache.ts +8 -0
- package/client/features/applets/applet-styles.ts +61 -0
- package/client/{hooks → features/applets}/useApplet.ts +6 -7
- package/client/{components/ChatInput.tsx → features/chat/ChatComposer.tsx} +30 -24
- package/client/features/chat/ChatPanel.tsx +171 -0
- package/client/{components → features/chat}/ChatPopup.tsx +24 -13
- package/client/{components/ThreadSelector.tsx → features/chat/ChatSelector.tsx} +15 -13
- package/client/{components → features/chat}/MarkdownContent.tsx +1 -1
- package/client/{components → features/chat}/ModelPicker.tsx +68 -17
- package/client/{components → features/chat}/TurnView.tsx +17 -11
- package/client/features/chat/api.ts +78 -0
- package/client/features/chat/chat-connection.ts +107 -0
- package/client/features/chat/chat-frames.ts +131 -0
- package/client/features/chat/chat-send.ts +57 -0
- package/client/{lib → features/chat}/preview-turn.ts +1 -1
- package/client/{components → features/chat}/tool-group/ReadImagePreview.tsx +1 -1
- package/client/{components → features/chat}/tool-group/SubagentCard.tsx +12 -10
- package/client/{components → features/chat}/tool-group/TimelineRow.tsx +5 -5
- package/client/{components → features/chat}/tool-group/ToolCallGroup.tsx +14 -5
- package/client/{components → features/chat}/tool-group/ToolOutput.tsx +12 -18
- package/client/{components → features/chat}/tool-group/format.ts +117 -0
- package/client/{hooks → features/chat}/useChat.ts +16 -44
- package/client/features/connectors/ConnectorsPage.tsx +92 -0
- package/client/features/connectors/McpMenu.tsx +145 -0
- package/client/features/connectors/api.ts +28 -0
- package/client/features/dev/DevRoutes.tsx +18 -0
- package/client/features/dev/HarnessDebugPage.tsx +468 -0
- package/client/{components/playground → features/dev}/PixelPainter.tsx +10 -21
- package/client/{components/playground → features/dev}/PlaygroundPage.tsx +10 -12
- package/client/{components/playground → features/dev}/ToolCallsPage.tsx +9 -11
- package/client/features/home/CreateWorkspaceDialog.tsx +130 -0
- package/client/features/home/CreateWorkspaceDialogSteps.tsx +234 -0
- package/client/features/home/HomeLogo.tsx +344 -0
- package/client/features/home/HomePage.tsx +214 -0
- package/client/{components → features/home}/WorkspacePreview.tsx +4 -4
- package/client/features/home/api.ts +156 -0
- package/client/features/home/workspace-presentation.tsx +44 -0
- package/client/features/scratchpad/Scratchpad.tsx +312 -0
- package/client/features/scratchpad/ScratchpadControls.tsx +503 -0
- package/client/features/scratchpad/useScratchpadSnapshot.tsx +115 -0
- package/client/features/settings/EnvironmentSettings.tsx +149 -0
- package/client/features/settings/GeneralSettings.tsx +90 -0
- package/client/{components → features}/settings/IconPicker.tsx +76 -224
- package/client/features/settings/SettingsLayout.tsx +53 -0
- package/client/{components → features}/settings/WorkspaceSettings.tsx +12 -16
- package/client/features/settings/api.ts +88 -0
- package/client/features/settings/icon-picker-options.ts +30 -0
- package/client/{hooks → features/settings}/useEnvVars.ts +4 -4
- package/client/features/views/ViewBuilderTab.tsx +153 -0
- package/client/features/views/api.ts +124 -0
- package/client/features/views/useViewBuilderActions.ts +72 -0
- package/client/{components → features/widgets}/HiddenPanel.tsx +3 -3
- package/client/{components → features/widgets}/WidgetFrame.tsx +3 -8
- package/client/{components → features/widgets}/WidgetGrid.tsx +38 -29
- package/client/features/widgets/Widgets.tsx +265 -0
- package/client/{lib/grid-pack.ts → features/widgets/grid.ts} +7 -1
- package/client/{hooks → features/widgets}/useGridReconcile.ts +1 -1
- package/client/{components → features/workspace}/CustomizePanel.tsx +5 -6
- package/client/{lib → features/workspace}/WorkspaceLayoutContext.tsx +16 -15
- package/client/features/workspace/WorkspaceScreen.tsx +675 -0
- package/client/features/workspace/WorkspaceTabs.tsx +205 -0
- package/client/features/workspace/api.ts +56 -0
- package/client/features/workspace/useFitsSplitLayout.ts +37 -0
- package/client/global.d.ts +5 -0
- package/client/index.css +6 -45
- package/client/index.html +2 -2
- package/client/index.tsx +14 -31
- package/client/lib/app-icon-registry.ts +145 -0
- package/client/main.tsx +2 -2
- package/client/runtime/hmr-watchdog.ts +39 -0
- package/client/{hooks/useMeiEvents.ts → runtime/useWorkspaceEvents.ts} +12 -7
- package/client/store/ui.ts +5 -1
- package/client/theme.css +1 -3
- package/dist/chunk-11cab5dq.css +1 -0
- package/dist/chunk-4vf1t6v1.js +10 -0
- package/dist/chunk-6c24yndg.js +61 -0
- package/dist/chunk-6c8cwpzc.js +1 -0
- package/dist/chunk-b4b276wx.js +15 -0
- package/dist/chunk-cs8vbert.js +546 -0
- package/dist/chunk-cwqmay73.css +1 -0
- package/dist/chunk-kxmvv1ax.js +48 -0
- package/dist/chunk-pcnahct1.js +5 -0
- package/dist/chunk-rq0ar7vp.js +1 -0
- package/dist/chunk-tqd3pkg8.css +1 -0
- package/dist/chunk-vkvb3hjm.js +2 -0
- package/dist/chunk-zpxrb1ce.js +2 -0
- package/dist/index.html +3 -3
- package/dist/openai-h13pza4b.svg +3 -0
- package/lib/format.ts +2 -2
- package/lib/types.ts +56 -9
- package/lib/view-builder-meta.ts +35 -0
- package/lib/workspace-layout.ts +14 -0
- package/lib/workspace-name.ts +14 -0
- package/package.json +4 -2
- package/server/AGENTS.md +3 -3
- package/server/api.ts +279 -60
- package/server/applets.ts +1 -1
- package/server/bundle-queue.ts +19 -0
- package/server/bundler/applet-css.ts +50 -0
- package/server/{build-applet.ts → bundler/build-applet.ts} +36 -26
- package/server/cli.ts +90 -7
- package/server/control.ts +106 -8
- package/server/env-apply.ts +2 -2
- package/server/harness/README.md +228 -0
- package/server/harness/claude-code/NOTES.md +578 -0
- package/{lib/claude-adapter.ts → server/harness/claude-code/adapter.ts} +67 -5
- package/server/harness/claude-code/index.ts +124 -0
- package/server/{mcp.ts → harness/claude-code/mcp.ts} +73 -16
- package/server/{cc-session.ts → harness/claude-code/session.ts} +42 -14
- package/server/harness/claude-code/sessions.ts +42 -0
- package/server/harness/codex/NOTES.md +239 -0
- package/server/harness/codex/adapter.ts +414 -0
- package/server/harness/codex/client.ts +343 -0
- package/server/harness/codex/index.ts +68 -0
- package/server/harness/codex/probe.ts +186 -0
- package/server/harness/codex/session.ts +617 -0
- package/server/harness/debug.ts +57 -0
- package/server/harness/openclaw/NOTES.md +316 -0
- package/server/{openclaw-adapter.ts → harness/openclaw/adapter.ts} +2 -2
- package/server/harness/openclaw/index.ts +93 -0
- package/server/{openclaw-session.ts → harness/openclaw/session.ts} +44 -9
- package/server/{openclaw-strip.ts → harness/openclaw/strip.ts} +3 -1
- package/server/harness/registry.ts +36 -0
- package/server/harness/types.ts +87 -0
- package/server/layout.ts +36 -11
- package/server/moi-scaffold.ts +56 -11
- package/server/registry.ts +30 -52
- package/server/state.ts +5 -38
- package/server/status.ts +7 -46
- package/server/vendor.ts +1 -1
- package/server/view-builders.ts +428 -0
- package/server/views.ts +0 -0
- package/server/web.ts +19 -40
- package/server/workspace-init.ts +11 -25
- package/tsconfig.json +1 -1
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +2 -1
- package/workspace/.claude/skills/moi-workspace/SKILL.md +28 -7
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +1 -1
- package/client/api/workspaces.ts +0 -427
- package/client/assets/hermes-nous.png +0 -0
- package/client/components/App.tsx +0 -41
- package/client/components/ChatPanel.tsx +0 -275
- package/client/components/HomePage.tsx +0 -17
- package/client/components/McpMenu.tsx +0 -125
- package/client/components/Scratchpad.tsx +0 -935
- package/client/components/Widgets.tsx +0 -132
- package/client/components/WorkspacesPage.tsx +0 -245
- package/client/components/layout/SidebarLayout.tsx +0 -258
- package/client/components/routes/workspace/[id].tsx +0 -675
- package/client/components/routes/workspace/create.tsx +0 -155
- package/client/components/settings/SettingsPages.tsx +0 -255
- package/client/hooks/useFitsSidebar.ts +0 -34
- package/client/hooks/useScrollFade.ts +0 -38
- package/client/lib/connection.ts +0 -238
- package/dist/chunk-07qf2tv1.css +0 -1
- package/dist/chunk-w18801vn.js +0 -672
- package/dist/hermes-nous-pznd63x9.png +0 -0
- /package/client/components/{playground → shared}/LedLogo.tsx +0 -0
- /package/client/{components → features/chat}/ShimmerText.tsx +0 -0
- /package/client/{store/live.ts → features/chat/chat-store.ts} +0 -0
- /package/client/{lib → features/chat}/group-turns.ts +0 -0
- /package/client/{components → features/chat}/tool-group/CodeBlock.tsx +0 -0
- /package/client/{components → features/chat}/tool-group/Collapse.tsx +0 -0
- /package/client/{components → features/chat}/tool-group/detect.ts +0 -0
- /package/client/{components → features/chat}/tool-group/fixtures.ts +0 -0
- /package/client/{components → features/chat}/tool-group/index.ts +0 -0
- /package/client/{lib → features/chat}/uploads.ts +0 -0
- /package/client/{hooks → features/chat}/useStickToBottom.ts +0 -0
- /package/client/{components → features/connectors}/IconMcp.tsx +0 -0
- /package/client/{lib → features/connectors}/mcp-icons.ts +0 -0
- /package/client/{lib → features/scratchpad}/scratch-executor.ts +0 -0
- /package/client/{lib → features/settings}/render-icon.ts +0 -0
- /package/client/{lib → features/workspace}/WorkspaceContext.tsx +0 -0
- /package/client/{hooks → features/workspace}/useWorkspaceTheme.ts +0 -0
- /package/server/{agent.ts → harness/claude-code/models.ts} +0 -0
- /package/server/{openclaw.ts → harness/openclaw/discovery.ts} +0 -0
- /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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
48
|
+
if (parsed?.version === 1) return normalizeLayout(parsed)
|
|
25
49
|
} catch {}
|
|
26
|
-
return
|
|
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,
|
|
36
|
-
// but the grid editor and `moi config` own different fields.
|
|
37
|
-
// PUT is authoritative for the editor fields (widgetGrid,
|
|
38
|
-
// selectedModel) — but it strips `name` and round-trips a
|
|
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
|
package/server/moi-scaffold.ts
CHANGED
|
@@ -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
|
|
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,
|
|
59
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
}
|
package/server/registry.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return
|
|
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 {
|
|
1
|
+
import type { BroadcastFrame, ServerMessage } from '@/lib/types'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
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
|