moi-computer 0.4.0 → 0.4.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -5
- package/bin/moi.mjs +11 -0
- package/client/api/workspace-keys.ts +1 -0
- package/client/app/AppRouter.tsx +5 -1
- package/client/app/routes/WorkspaceRoute.tsx +9 -5
- package/client/app/shell/SidebarLayout.tsx +9 -7
- package/client/components/shared/BottomPanel.tsx +24 -5
- package/client/components/shared/Composer.tsx +1 -1
- package/client/components/shared/PanelHeader.tsx +1 -1
- package/client/components/ui/button.tsx +5 -5
- package/client/components/ui/dropdown-menu.tsx +6 -6
- 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 +1 -1
- package/client/components/ui/textarea.tsx +1 -1
- package/client/components/ui/tooltip.tsx +1 -1
- package/client/features/applets/applet-cache.ts +20 -1
- package/client/features/applets/applet-log.ts +10 -30
- package/client/features/applets/applet-runtime.ts +272 -0
- package/client/features/applets/useApplet.ts +36 -10
- package/client/features/chat/ChatComposer.tsx +1 -1
- package/client/features/chat/ChatEmptyState.tsx +186 -0
- package/client/features/chat/ChatPanel.tsx +95 -54
- package/client/features/chat/ChatPopup.tsx +3 -13
- package/client/features/chat/ChatPromptBubbles.tsx +74 -0
- package/client/features/chat/MarkdownContent.tsx +15 -3
- package/client/features/chat/ModelPicker.tsx +1 -1
- package/client/features/chat/TurnView.tsx +6 -17
- package/client/features/chat/chat-send.ts +26 -1
- package/client/features/chat/tool-group/CodeBlock.tsx +1 -1
- package/client/features/chat/tool-group/ReadImagePreview.tsx +1 -1
- package/client/features/chat/tool-group/SubagentCard.tsx +1 -1
- package/client/features/chat/tool-group/TimelineRow.tsx +4 -4
- package/client/features/chat/tool-group/ToolCallGroup.tsx +12 -5
- package/client/features/chat/tool-group/ToolOutput.tsx +2 -2
- package/client/features/chat/tool-group/format.ts +3 -3
- package/client/features/chat/useAppletChatMessage.ts +69 -0
- package/client/features/chat/useChat.ts +49 -14
- package/client/features/chat/useStickToBottom.ts +11 -1
- package/client/features/connectors/McpServerCards.tsx +3 -3
- package/client/features/dev/HarnessDebugPage.tsx +4 -4
- package/client/features/dev/PixelPainter.tsx +1 -1
- package/client/features/dev/PlaygroundPage.tsx +1 -1
- package/client/features/dev/ToolCallsPage.tsx +2 -2
- package/client/features/home/HomePage.tsx +17 -14
- package/client/features/home/WorkspacePreview.tsx +12 -13
- package/client/features/home/api.ts +8 -5
- package/client/features/home/workspace-presentation.tsx +1 -1
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +1 -1
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +21 -8
- package/client/features/scratchpad/Scratchpad.tsx +41 -2
- package/client/features/scratchpad/ScratchpadControls.tsx +13 -13
- package/client/features/scratchpad/useScratchpadSnapshot.tsx +1 -1
- package/client/features/settings/EnvironmentSettings.tsx +1 -1
- package/client/features/settings/IconPicker.tsx +11 -11
- package/client/features/settings/SettingsLayout.tsx +1 -1
- package/client/features/settings/WorkspaceSettings.tsx +2 -2
- package/client/features/settings/api.ts +33 -1
- package/client/features/widgets/HiddenPanel.tsx +4 -3
- package/client/features/widgets/Widgets.tsx +1 -0
- package/client/features/workspace/CustomizePanel.tsx +96 -82
- package/client/features/workspace/WorkspaceScreen.tsx +129 -107
- package/client/features/workspace/WorkspaceSkillUpdateBanner.tsx +91 -0
- package/client/features/workspace/WorkspaceTabs.tsx +1 -1
- package/client/features/workspace/api.ts +52 -0
- package/client/features/workspace/moi-context.ts +63 -17
- package/client/features/workspace/tab-resolution.ts +75 -0
- package/client/features/workspace/useWorkspaceNavigation.ts +128 -0
- package/client/features/workspace/useWorkspaceSkillUpdates.ts +160 -0
- package/client/index.css +10 -15
- package/client/lib/app-icon-registry.ts +77 -70
- package/client/lib/rate-limit.ts +77 -0
- package/client/runtime/useWorkspaceEvents.ts +15 -2
- package/client/runtime/workspace-theme.ts +115 -0
- package/client/store/ui.ts +42 -17
- package/client/theme.css +20 -15
- package/dist/{chunk-fh2mf6v9.js → chunk-3m1xe1j3.js} +94 -94
- package/dist/chunk-5vaevt8z.js +2 -0
- package/dist/{chunk-69nhbjhy.js → chunk-7bzpmtxp.js} +4 -4
- package/dist/chunk-h0hk61pm.js +9 -0
- package/dist/{chunk-35fq49qa.js → chunk-h3evrtyp.js} +1 -1
- package/dist/chunk-k5sjx9s5.js +1 -0
- package/dist/{chunk-2vaafjp4.js → chunk-m9qja0nx.js} +1 -1
- package/dist/chunk-s7za1qsv.css +1 -0
- package/dist/{chunk-72atbmh3.js → chunk-tcfa3vt3.js} +1 -1
- package/dist/chunk-v797g6ap.js +51 -0
- package/dist/chunk-xyrw8318.js +27 -0
- package/dist/index.html +1 -1
- package/lib/app-icons.ts +73 -0
- package/lib/moi-context.ts +104 -3
- package/lib/themes.ts +83 -45
- package/lib/types.ts +44 -9
- package/lib/workspace-tabs.ts +48 -0
- package/package.json +4 -1
- package/server/api.ts +57 -5
- package/server/app-settings.ts +65 -0
- package/server/applets.ts +132 -22
- package/server/bundler/build-applet.ts +74 -16
- package/server/cli.ts +144 -17
- package/server/control.ts +53 -7
- package/server/data-dir.ts +1 -1
- package/server/events.ts +1 -1
- package/server/functions-worker.ts +15 -1
- package/server/functions.ts +51 -6
- package/server/layout.ts +9 -14
- package/server/moi-scaffold.ts +37 -3
- package/server/registry.ts +1 -1
- package/server/skill-update.ts +47 -0
- package/server/skill-version.ts +2 -11
- package/server/tabs.ts +59 -0
- package/server/theme.ts +8 -14
- package/server/view-builders.ts +6 -2
- package/workspace/.claude/skills/moi-workspace/DESIGN.md +265 -107
- package/workspace/.claude/skills/moi-workspace/SKILL.md +85 -11
- package/client/features/workspace/useWorkspaceTheme.ts +0 -82
- package/dist/chunk-19g80zc9.css +0 -1
- package/dist/chunk-7mkv2gr0.js +0 -2
- package/dist/chunk-gt7n06ef.js +0 -1
- package/dist/chunk-jwmc32rp.js +0 -63
- package/dist/chunk-kh24bstm.js +0 -10
- package/dist/chunk-sfa4mbmx.js +0 -15
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +0 -22
package/server/cli.ts
CHANGED
|
@@ -7,8 +7,9 @@ import { tmpdir } from 'node:os'
|
|
|
7
7
|
import { join, resolve } from 'path'
|
|
8
8
|
import pc from './cli-pc'
|
|
9
9
|
|
|
10
|
-
import { COLOR_THEMES, FONT_THEMES } from '@/lib/themes'
|
|
10
|
+
import { COLOR_THEMES, FONT_THEMES, deriveThemeColors } from '@/lib/themes'
|
|
11
11
|
import type { ColorTheme, FontTheme } from '@/lib/themes'
|
|
12
|
+
import { isParamsRecord } from '@/lib/workspace-tabs'
|
|
12
13
|
import type {
|
|
13
14
|
AppletLogEntry,
|
|
14
15
|
ScratchArrowEnd,
|
|
@@ -18,7 +19,8 @@ import type {
|
|
|
18
19
|
ScratchOp,
|
|
19
20
|
ScratchSize,
|
|
20
21
|
ScratchStyle,
|
|
21
|
-
WorkspaceEntry
|
|
22
|
+
WorkspaceEntry,
|
|
23
|
+
WorkspaceSkillStatus
|
|
22
24
|
} from '@/lib/types'
|
|
23
25
|
|
|
24
26
|
import {
|
|
@@ -34,21 +36,20 @@ import { type OpenClawAgent, discoverOpenClawAgents } from './harness/openclaw/d
|
|
|
34
36
|
import { liftToWorkspaceRoot, registerWorkspace } from './registry'
|
|
35
37
|
import { serverCwd } from './server-cwd'
|
|
36
38
|
import {
|
|
37
|
-
type SkillStatus,
|
|
38
39
|
isBehind,
|
|
39
40
|
isMinorBehind,
|
|
40
41
|
resolveWorkspace,
|
|
41
42
|
skillStatuses,
|
|
42
43
|
staleSkillNotice
|
|
43
44
|
} from './skill-version'
|
|
44
|
-
import {
|
|
45
|
+
import { updateWorkspaceSkills } from './skill-update'
|
|
45
46
|
import {
|
|
46
47
|
getWorkspaceEnvView,
|
|
47
48
|
isValidEnvKey,
|
|
48
49
|
secretBackend,
|
|
49
50
|
updateWorkspaceEnv
|
|
50
51
|
} from './workspace-env'
|
|
51
|
-
import { provisionWorkspace
|
|
52
|
+
import { provisionWorkspace } from './workspace-init'
|
|
52
53
|
|
|
53
54
|
// ---- helpers ----------------------------------------------------------------
|
|
54
55
|
|
|
@@ -573,13 +574,27 @@ const refresh = defineCommand({
|
|
|
573
574
|
meta: {
|
|
574
575
|
name: 'refresh',
|
|
575
576
|
description:
|
|
576
|
-
'Refresh widget data without rebuilding. Use after the agent mutates underlying data.'
|
|
577
|
+
'Refresh widget and view data without rebuilding. Use after the agent mutates underlying data.'
|
|
577
578
|
},
|
|
578
|
-
|
|
579
|
+
args: {
|
|
580
|
+
only: {
|
|
581
|
+
type: 'string',
|
|
582
|
+
description: 'Narrow the refresh to "widgets" or "views" (default: both)'
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
async run({ args }) {
|
|
586
|
+
// Validate up front: a typo'd filter silently refreshing everything would
|
|
587
|
+
// read as "my filter worked".
|
|
588
|
+
if (args.only && args.only !== 'widgets' && args.only !== 'views') {
|
|
589
|
+
console.error(
|
|
590
|
+
'\n' + pc.red('✗') + ` Unknown --only value "${args.only}" — use "widgets" or "views".\n`
|
|
591
|
+
)
|
|
592
|
+
process.exit(1)
|
|
593
|
+
}
|
|
579
594
|
const notice = await staleSkillNotice(process.cwd())
|
|
580
595
|
const ws = new WebSocket(`ws://localhost:${CONTROL_PORT}`)
|
|
581
596
|
|
|
582
|
-
ws.onopen = () => ws.send(JSON.stringify({ type: '
|
|
597
|
+
ws.onopen = () => ws.send(JSON.stringify({ type: 'applets:refresh', only: args.only }))
|
|
583
598
|
|
|
584
599
|
ws.onmessage = event => {
|
|
585
600
|
const data = JSON.parse(String(event.data))
|
|
@@ -588,7 +603,9 @@ const refresh = defineCommand({
|
|
|
588
603
|
ws.close()
|
|
589
604
|
process.exit(1)
|
|
590
605
|
}
|
|
591
|
-
console.log(
|
|
606
|
+
console.log(
|
|
607
|
+
'\n' + pc.green('✓') + ' Refresh signal sent' + (args.only ? ` (${args.only})` : '') + '\n'
|
|
608
|
+
)
|
|
592
609
|
if (notice) console.log(pc.yellow(notice) + '\n')
|
|
593
610
|
ws.close()
|
|
594
611
|
process.exit(0)
|
|
@@ -615,6 +632,12 @@ function swatch(bg?: string, fg?: string): string {
|
|
|
615
632
|
return `\x1b[48;2;${br};${bgg};${bb}m\x1b[38;2;${fr};${fgg};${fb}m Aa \x1b[0m`
|
|
616
633
|
}
|
|
617
634
|
|
|
635
|
+
function themeSwatch(primary?: string): string {
|
|
636
|
+
if (!primary) return swatch()
|
|
637
|
+
const colors = deriveThemeColors(primary)
|
|
638
|
+
return swatch(colors.primary, colors.primaryForeground)
|
|
639
|
+
}
|
|
640
|
+
|
|
618
641
|
const theme = defineCommand({
|
|
619
642
|
meta: { name: 'theme', description: 'Show or set the workspace font and color themes' },
|
|
620
643
|
args: {
|
|
@@ -663,7 +686,7 @@ const theme = defineCommand({
|
|
|
663
686
|
}
|
|
664
687
|
if (res.color) {
|
|
665
688
|
const preset = COLOR_THEMES[res.color as ColorTheme]
|
|
666
|
-
const chip =
|
|
689
|
+
const chip = themeSwatch(preset.primary)
|
|
667
690
|
console.log(pc.green('✓') + ' Color set to ' + pc.bold(preset.label) + ' ' + chip)
|
|
668
691
|
}
|
|
669
692
|
console.log()
|
|
@@ -704,14 +727,13 @@ const theme = defineCommand({
|
|
|
704
727
|
selected ? pc.green('→') : ' ',
|
|
705
728
|
selected ? pc.bold(key) : key,
|
|
706
729
|
c.label,
|
|
707
|
-
|
|
708
|
-
pc.dim(c.feel)
|
|
730
|
+
themeSwatch(c.primary)
|
|
709
731
|
]
|
|
710
732
|
})
|
|
711
733
|
console.log(pc.dim(' Colors'))
|
|
712
734
|
console.log(
|
|
713
735
|
columns(
|
|
714
|
-
['', 'key', 'label', 'swatch'
|
|
736
|
+
['', 'key', 'label', 'swatch'].map(h => pc.dim(h)),
|
|
715
737
|
colorRows
|
|
716
738
|
) + '\n'
|
|
717
739
|
)
|
|
@@ -1829,6 +1851,97 @@ const debug = defineCommand({
|
|
|
1829
1851
|
subCommands: { logs: debugLogs }
|
|
1830
1852
|
})
|
|
1831
1853
|
|
|
1854
|
+
// ---- workspace tabs ----------------------------------------------------------
|
|
1855
|
+
|
|
1856
|
+
// The shared listing behind `moi tabs` and bare `moi tab`: every tab (static +
|
|
1857
|
+
// views), one per row, the saved default (`layout.tabs.active`) marked. The
|
|
1858
|
+
// output shape is documented in docs/rfc-intents-v2.md §3 — keep them in sync.
|
|
1859
|
+
function runTabsList(dir: string) {
|
|
1860
|
+
const path = resolve(dir)
|
|
1861
|
+
sendControl(path, { type: 'tabs', path }, res => {
|
|
1862
|
+
type Row = { id: string; title: string; isDefault: boolean }
|
|
1863
|
+
const rows: Row[] = Array.isArray(res.tabs) ? (res.tabs as Row[]) : []
|
|
1864
|
+
console.log(
|
|
1865
|
+
'\n' + pc.bold('moi tabs') + pc.dim(' — workspace tabs, the default one marked') + '\n'
|
|
1866
|
+
)
|
|
1867
|
+
console.log(
|
|
1868
|
+
columns(
|
|
1869
|
+
['', 'tab', 'title'].map(h => pc.dim(h)),
|
|
1870
|
+
rows.map(row => [
|
|
1871
|
+
row.isDefault ? pc.green('●') : ' ',
|
|
1872
|
+
row.isDefault ? pc.bold(row.id) : row.id,
|
|
1873
|
+
row.title
|
|
1874
|
+
])
|
|
1875
|
+
)
|
|
1876
|
+
)
|
|
1877
|
+
console.log(
|
|
1878
|
+
'\n' + pc.dim(' Focus one: moi tab focus <tab-id> [--params \'{"k":"v"}\']') + '\n'
|
|
1879
|
+
)
|
|
1880
|
+
})
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1883
|
+
const tabFocus = defineCommand({
|
|
1884
|
+
meta: { name: 'focus', description: 'Focus a workspace tab in every open client' },
|
|
1885
|
+
args: {
|
|
1886
|
+
tab: {
|
|
1887
|
+
type: 'positional',
|
|
1888
|
+
required: true,
|
|
1889
|
+
description: 'Tab id from `moi tabs`, e.g. view:orders'
|
|
1890
|
+
},
|
|
1891
|
+
params: {
|
|
1892
|
+
type: 'string',
|
|
1893
|
+
description: 'One JSON object delivered to the view as its params, e.g. \'{"order":"o-1"}\''
|
|
1894
|
+
},
|
|
1895
|
+
dir: dirArg
|
|
1896
|
+
},
|
|
1897
|
+
run({ args }) {
|
|
1898
|
+
const path = resolve(args.dir)
|
|
1899
|
+
let params: Record<string, unknown> | undefined
|
|
1900
|
+
if (args.params !== undefined) {
|
|
1901
|
+
try {
|
|
1902
|
+
const parsed: unknown = JSON.parse(args.params)
|
|
1903
|
+
if (!isParamsRecord(parsed)) throw new Error('not a JSON object')
|
|
1904
|
+
params = parsed
|
|
1905
|
+
} catch {
|
|
1906
|
+
console.error(
|
|
1907
|
+
'\n' + pc.red('✗') + ' --params must be one JSON object, e.g. \'{"order":"o-1"}\'\n'
|
|
1908
|
+
)
|
|
1909
|
+
process.exit(1)
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
sendControl(
|
|
1913
|
+
path,
|
|
1914
|
+
{ type: 'tab:focus', path, tab: args.tab, ...(params ? { params } : {}) },
|
|
1915
|
+
res => {
|
|
1916
|
+
console.log('\n' + pc.green('✓') + ' Focused ' + pc.bold(String(res.tab)) + '\n')
|
|
1917
|
+
}
|
|
1918
|
+
)
|
|
1919
|
+
}
|
|
1920
|
+
})
|
|
1921
|
+
|
|
1922
|
+
const tabSubCommands = { focus: tabFocus }
|
|
1923
|
+
|
|
1924
|
+
const tab = defineCommand({
|
|
1925
|
+
meta: { name: 'tab', description: 'List workspace tabs, or focus one: `moi tab focus <tab-id>`' },
|
|
1926
|
+
subCommands: tabSubCommands,
|
|
1927
|
+
args: { dir: dirArg },
|
|
1928
|
+
run({ args, rawArgs }) {
|
|
1929
|
+
// citty invokes the parent run even after dispatching a subcommand — only
|
|
1930
|
+
// list when none ran (same pattern as `moi env` / `moi skill`).
|
|
1931
|
+
const sub = rawArgs.find(a => !a.startsWith('-'))
|
|
1932
|
+
if (sub && Object.hasOwn(tabSubCommands, sub)) return
|
|
1933
|
+
runTabsList(args.dir)
|
|
1934
|
+
}
|
|
1935
|
+
})
|
|
1936
|
+
|
|
1937
|
+
const tabs = defineCommand({
|
|
1938
|
+
meta: { name: 'tabs', description: 'List workspace tabs (alias for `moi tab`)' },
|
|
1939
|
+
args: { dir: dirArg },
|
|
1940
|
+
run({ args }) {
|
|
1941
|
+
runTabsList(args.dir)
|
|
1942
|
+
}
|
|
1943
|
+
})
|
|
1944
|
+
|
|
1832
1945
|
// Re-copy bundled skills into a workspace, then report what changed. Pure
|
|
1833
1946
|
// filesystem op — no running server needed. Resolves the workspace root the
|
|
1834
1947
|
// same way `moi bundle` does, so it works from `.moi/` or any subdirectory.
|
|
@@ -1836,11 +1949,23 @@ async function runSkillUpdate(cwd: string): Promise<void> {
|
|
|
1836
1949
|
// Type-aware: an OpenClaw workspace keeps its skills in `skills/`, so the
|
|
1837
1950
|
// update must target the same dir the agent actually loads from.
|
|
1838
1951
|
const { root, type } = await resolveWorkspace(cwd)
|
|
1839
|
-
const before = await
|
|
1840
|
-
|
|
1841
|
-
|
|
1952
|
+
const { before, status, appletTypesWritten } = await updateWorkspaceSkills(
|
|
1953
|
+
root,
|
|
1954
|
+
type ?? 'claude-code'
|
|
1955
|
+
)
|
|
1956
|
+
const after = status.skills
|
|
1842
1957
|
|
|
1843
1958
|
console.log('\n' + pc.green('✓') + ' Skills updated in ' + pc.bold(root) + '\n')
|
|
1959
|
+
printSkillUpdateTable(before, after)
|
|
1960
|
+
if (appletTypesWritten) {
|
|
1961
|
+
console.log(pc.dim(' Ambient applet types regenerated: ') + pc.bold('.moi/applet-env.d.ts\n'))
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
function printSkillUpdateTable(
|
|
1966
|
+
before: WorkspaceSkillStatus[],
|
|
1967
|
+
after: WorkspaceSkillStatus[]
|
|
1968
|
+
): void {
|
|
1844
1969
|
console.log(
|
|
1845
1970
|
columns(
|
|
1846
1971
|
['skill', 'from', 'to'].map(h => pc.dim(h)),
|
|
@@ -1866,7 +1991,7 @@ async function runSkillUpdate(cwd: string): Promise<void> {
|
|
|
1866
1991
|
|
|
1867
1992
|
// Colored status label for one skill row: minor+ behind is actionable, a patch
|
|
1868
1993
|
// gap is informational, otherwise current.
|
|
1869
|
-
function skillState(s:
|
|
1994
|
+
function skillState(s: WorkspaceSkillStatus): string {
|
|
1870
1995
|
if (isMinorBehind(s.installed, s.bundled)) return pc.yellow('update available')
|
|
1871
1996
|
if (isBehind(s.installed, s.bundled)) return pc.dim('patch behind')
|
|
1872
1997
|
return pc.green('up to date')
|
|
@@ -1969,6 +2094,8 @@ const main = defineCommand({
|
|
|
1969
2094
|
openclaw,
|
|
1970
2095
|
scratch,
|
|
1971
2096
|
skill,
|
|
2097
|
+
tab,
|
|
2098
|
+
tabs,
|
|
1972
2099
|
version
|
|
1973
2100
|
}
|
|
1974
2101
|
})
|
package/server/control.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { stringify as devalueStringify } from 'devalue'
|
|
|
2
2
|
import { resolve } from 'path'
|
|
3
3
|
|
|
4
4
|
import type { WorkspaceEntry } from '@/lib/types'
|
|
5
|
+
import { isParamsRecord } from '@/lib/workspace-tabs'
|
|
5
6
|
|
|
6
7
|
import { clearAppletLog, getAppletLog, getAppletLogCount } from './applet-log'
|
|
7
8
|
import { serializeWorkspaceBundle } from './bundle-queue'
|
|
@@ -16,6 +17,7 @@ import { executeScratchOp } from './scratchpad-executor'
|
|
|
16
17
|
import { readScratchpadImage, readScratchpadShapes } from './scratchpad'
|
|
17
18
|
import { relayScratchOp } from './scratchpad-relay'
|
|
18
19
|
import { broadcastAll } from './state'
|
|
20
|
+
import { assembleTabRows, resolveFocusTab } from './tabs'
|
|
19
21
|
import { applyThemeUpdate, matchColorTheme } from './theme'
|
|
20
22
|
import { handleBundle } from './widgets'
|
|
21
23
|
import { getViewList, handleBundleViews, hasViewId } from './views'
|
|
@@ -263,12 +265,56 @@ export const control = Bun.serve({
|
|
|
263
265
|
return
|
|
264
266
|
}
|
|
265
267
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
268
|
+
// The workspace tab listing — `moi tabs` (and bare `moi tab`).
|
|
269
|
+
if (data.type === 'tabs') {
|
|
270
|
+
const match = await resolveWorkspace(ws, data.path)
|
|
271
|
+
if (!match) return
|
|
272
|
+
const [layout, views] = await Promise.all([
|
|
273
|
+
loadLayout(match.path),
|
|
274
|
+
getViewList(match.path)
|
|
275
|
+
])
|
|
276
|
+
ws.send(JSON.stringify({ ok: true, tabs: assembleTabRows(views, layout.tabs.active) }))
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// `moi tab focus <tab-id>` — validate the target, then publish a
|
|
281
|
+
// workspace-scoped `tab:focus` event. Every connected client of that
|
|
282
|
+
// workspace navigates (replace) with the params in navigation state.
|
|
283
|
+
if (data.type === 'tab:focus') {
|
|
284
|
+
const match = await resolveWorkspace(ws, data.path)
|
|
285
|
+
if (!match) return
|
|
286
|
+
const resolved = await resolveFocusTab(data.tab, {
|
|
287
|
+
hasView: viewId => hasViewId(match.path, viewId),
|
|
288
|
+
viewList: () => getViewList(match.path)
|
|
289
|
+
})
|
|
290
|
+
if (!resolved.ok) {
|
|
291
|
+
ws.send(JSON.stringify({ error: resolved.error }))
|
|
292
|
+
return
|
|
293
|
+
}
|
|
294
|
+
// The CLI already validated --params as one JSON object; re-check the
|
|
295
|
+
// shape here so a hand-rolled control client can't publish garbage.
|
|
296
|
+
if (data.params !== undefined && !isParamsRecord(data.params)) {
|
|
297
|
+
ws.send(JSON.stringify({ error: 'Params must be one JSON object' }))
|
|
298
|
+
return
|
|
299
|
+
}
|
|
300
|
+
publishEvent({
|
|
301
|
+
type: 'tab:focus',
|
|
302
|
+
workspaceId: match.id,
|
|
303
|
+
tab: resolved.tab,
|
|
304
|
+
...(data.params !== undefined ? { params: data.params } : {})
|
|
305
|
+
})
|
|
306
|
+
ws.send(JSON.stringify({ ok: true, tab: resolved.tab }))
|
|
307
|
+
return
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Tell every connected applet to re-import its module (cache-bust) and
|
|
311
|
+
// re-run its data fetches. No rebuild, no page reload — `useApplet`
|
|
312
|
+
// handles `applets:refresh` like `*:updated` (invalidate + reload).
|
|
313
|
+
// `only` narrows to one kind; default is both widgets and views.
|
|
314
|
+
// `widget:refresh` is the pre-filter message name older CLIs send.
|
|
315
|
+
if (data.type === 'applets:refresh' || data.type === 'widget:refresh') {
|
|
316
|
+
const only = data.only === 'widgets' || data.only === 'views' ? data.only : undefined
|
|
317
|
+
publishEvent({ type: 'applets:refresh', only })
|
|
272
318
|
ws.send(JSON.stringify({ ok: true }))
|
|
273
319
|
return
|
|
274
320
|
}
|
|
@@ -295,7 +341,7 @@ export const control = Bun.serve({
|
|
|
295
341
|
ws.send(
|
|
296
342
|
JSON.stringify({
|
|
297
343
|
currentFont: layout.theme?.font ?? 'default',
|
|
298
|
-
currentColor: matchColorTheme(layout.theme?.
|
|
344
|
+
currentColor: matchColorTheme(layout.theme?.primary)
|
|
299
345
|
})
|
|
300
346
|
)
|
|
301
347
|
return
|
package/server/data-dir.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Single source of truth for the OS data dir holding moi's global state
|
|
2
|
-
// (workspaces.json, thread-config.json, workspace-env.json, …).
|
|
2
|
+
// (workspaces.json, settings.json, thread-config.json, workspace-env.json, …).
|
|
3
3
|
//
|
|
4
4
|
// MOI_DATA_DIR overrides it wholesale. This is the isolation seam for CLI
|
|
5
5
|
// e2e tests: env-paths only honors XDG_DATA_HOME on Linux, so on macOS a
|
package/server/events.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Live-event channel: server → browser push over the `/api/workspaces/ws`
|
|
2
2
|
// socket. Bundles, the control server, and the REST API publish build/refresh/
|
|
3
|
-
// identity events (`
|
|
3
|
+
// identity events (`applets:refresh`, `theme:updated`, `workspace:updated`, …)
|
|
4
4
|
// here; every subscribed browser receives them. This is not a transport of its
|
|
5
5
|
// own — it rides the Bun WebSocket pub/sub already open for that route.
|
|
6
6
|
//
|
|
@@ -67,7 +67,8 @@ async function evictModule(name: string) {
|
|
|
67
67
|
|
|
68
68
|
type CallMessage = { id: string; type: 'call'; module: string; name: string; args: string }
|
|
69
69
|
type ReloadMessage = { type: 'reload'; modules: string[] }
|
|
70
|
-
type
|
|
70
|
+
type ShutdownMessage = { type: 'shutdown' }
|
|
71
|
+
type IncomingMessage = CallMessage | ReloadMessage | ShutdownMessage
|
|
71
72
|
|
|
72
73
|
process.on('message', async (raw: IncomingMessage) => {
|
|
73
74
|
if (raw.type === 'reload') {
|
|
@@ -77,6 +78,19 @@ process.on('message', async (raw: IncomingMessage) => {
|
|
|
77
78
|
return
|
|
78
79
|
}
|
|
79
80
|
|
|
81
|
+
// Graceful exit. The parent kills this process to pick up edited server code
|
|
82
|
+
// — evicting from moduleCache isn't enough, because a module's own imports
|
|
83
|
+
// are pinned in Bun's ESM registry with no way to invalidate them (the
|
|
84
|
+
// `?t=` buster below only busts the .server.ts itself, one level deep). Run
|
|
85
|
+
// every cached module's `dispose()` first so a hard kill doesn't strand a db
|
|
86
|
+
// handle or timer; the parent hard-kills us if we take too long.
|
|
87
|
+
if (raw.type === 'shutdown') {
|
|
88
|
+
for (const name of [...moduleCache.keys()]) {
|
|
89
|
+
await evictModule(name)
|
|
90
|
+
}
|
|
91
|
+
process.exit(0)
|
|
92
|
+
}
|
|
93
|
+
|
|
80
94
|
if (raw.type === 'call') {
|
|
81
95
|
const { id, module: moduleName, name, args } = raw
|
|
82
96
|
|
package/server/functions.ts
CHANGED
|
@@ -68,6 +68,41 @@ function killSlot(slot: Slot, reason: string) {
|
|
|
68
68
|
} catch {}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
// How long a worker gets to run its modules' `dispose()` and exit on its own
|
|
72
|
+
// before we kill it outright.
|
|
73
|
+
const SHUTDOWN_GRACE_MS = 2_000
|
|
74
|
+
|
|
75
|
+
// Same end state as killSlot — a dead worker — but the worker is asked to exit
|
|
76
|
+
// so it can run each cached module's `dispose()` first. Used when server code
|
|
77
|
+
// changed: a hard kill would strand whatever those modules hold open (db
|
|
78
|
+
// handles, timers, watchers).
|
|
79
|
+
//
|
|
80
|
+
// The slot is marked killed immediately, so a call arriving mid-shutdown spawns
|
|
81
|
+
// a fresh worker rather than queueing behind a dying one. In-flight calls are
|
|
82
|
+
// rejected rather than left to hit the 30s timeout.
|
|
83
|
+
function gracefulKillSlot(slot: Slot, reason: string) {
|
|
84
|
+
if (slot.killed) return
|
|
85
|
+
slot.killed = true
|
|
86
|
+
rejectAndClearPending(slot, reason)
|
|
87
|
+
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
try {
|
|
90
|
+
slot.worker.kill()
|
|
91
|
+
} catch {}
|
|
92
|
+
}, SHUTDOWN_GRACE_MS)
|
|
93
|
+
timer.unref?.()
|
|
94
|
+
void slot.worker.exited.then(() => clearTimeout(timer)).catch(() => clearTimeout(timer))
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
slot.worker.send({ type: 'shutdown' })
|
|
98
|
+
} catch {
|
|
99
|
+
clearTimeout(timer)
|
|
100
|
+
try {
|
|
101
|
+
slot.worker.kill()
|
|
102
|
+
} catch {}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
71
106
|
const slots = new LRUCache<string, Slot>({
|
|
72
107
|
max: MAX_WORKERS,
|
|
73
108
|
ttl: WORKER_IDLE_TTL_MS,
|
|
@@ -331,16 +366,26 @@ export function getWorkersDebugSnapshot(): WorkerDebugInfo[] {
|
|
|
331
366
|
return out
|
|
332
367
|
}
|
|
333
368
|
|
|
369
|
+
// Make edited server code take effect: recycle the workspace's worker so the
|
|
370
|
+
// next call loads it fresh.
|
|
371
|
+
//
|
|
372
|
+
// This RECYCLES THE WHOLE WORKER rather than evicting the named modules,
|
|
373
|
+
// because eviction cannot actually reload edited code. `loadModule` busts its
|
|
374
|
+
// import with `?t=<mtime>`, which only makes a new URL for the `.server.ts`
|
|
375
|
+
// itself — everything that file imports stays pinned in Bun's ESM registry
|
|
376
|
+
// with no API to invalidate it. So a module whose *dependency* changed re-
|
|
377
|
+
// executes against the old dependency, and one whose own mtime is unchanged
|
|
378
|
+
// doesn't re-execute at all. A fresh process is the only reliable reset.
|
|
379
|
+
//
|
|
380
|
+
// `modules` is the reason, not the scope: every module in the worker is
|
|
381
|
+
// dropped. Kept in the signature for the kill reason surfaced to callers.
|
|
334
382
|
export function reloadModules(modules: string[], workspacePath: string) {
|
|
335
383
|
if (modules.length === 0) return
|
|
336
384
|
// peek: don't refresh TTL just because files changed. If the worker was
|
|
337
385
|
// already idle-evicted, the next callFunction will re-spawn fresh anyway.
|
|
338
386
|
const slot = slots.peek(workspacePath)
|
|
339
387
|
if (!slot || slot.killed) return
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
// on the next call, so drop them from the introspection set too.
|
|
344
|
-
for (const m of modules) slot.modules.delete(m)
|
|
345
|
-
} catch {}
|
|
388
|
+
// No need to prune `slot.modules`: the whole slot is going away, and
|
|
389
|
+
// getStatus already skips killed slots.
|
|
390
|
+
gracefulKillSlot(slot, `Server code changed (${modules.join(', ')})`)
|
|
346
391
|
}
|
package/server/layout.ts
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
import { join } from 'path'
|
|
2
2
|
|
|
3
|
-
import type { WorkspaceLayout, WorkspacePreview
|
|
3
|
+
import type { WorkspaceLayout, WorkspacePreview } from '@/lib/types'
|
|
4
4
|
import { createDefaultWorkspaceLayout, createDefaultWorkspaceTabs } from '@/lib/workspace-layout'
|
|
5
|
-
|
|
6
|
-
function isTabId(value: unknown): value is WorkspaceTabId {
|
|
7
|
-
return (
|
|
8
|
-
value === 'agent' ||
|
|
9
|
-
value === 'widgets' ||
|
|
10
|
-
value === 'scratchpad' ||
|
|
11
|
-
(typeof value === 'string' && (/^view:.+/.test(value) || /^view-builder:.+/.test(value)))
|
|
12
|
-
)
|
|
13
|
-
}
|
|
5
|
+
import { isWorkspaceTabId } from '@/lib/workspace-tabs'
|
|
14
6
|
|
|
15
7
|
function normalizeTabs(value: unknown): WorkspaceLayout['tabs'] {
|
|
16
8
|
if (!value || typeof value !== 'object') return createDefaultWorkspaceTabs()
|
|
17
9
|
const raw = value as Record<string, unknown>
|
|
18
10
|
const open = Array.isArray(raw.open)
|
|
19
|
-
? raw.open.filter(
|
|
11
|
+
? raw.open.filter(isWorkspaceTabId).filter((tab, index, all) => all.indexOf(tab) === index)
|
|
20
12
|
: []
|
|
21
13
|
if (open.length === 0) return createDefaultWorkspaceTabs()
|
|
22
|
-
const active =
|
|
14
|
+
const active = isWorkspaceTabId(raw.active) && open.includes(raw.active) ? raw.active : open[0]
|
|
23
15
|
return { open, active }
|
|
24
16
|
}
|
|
25
17
|
|
|
@@ -140,19 +132,22 @@ export async function getWorkspacePreview(
|
|
|
140
132
|
() => undefined
|
|
141
133
|
)
|
|
142
134
|
const updatedAt = providerPreview?.updatedAt
|
|
135
|
+
const theme = layout.theme
|
|
143
136
|
|
|
144
137
|
if (includeFirstUserMessage) {
|
|
145
138
|
const firstUserMessage = normalizePreviewMessage(providerPreview?.firstUserMessage)
|
|
146
139
|
return {
|
|
147
140
|
thumbnails,
|
|
148
141
|
...(firstUserMessage ? { firstUserMessage } : {}),
|
|
149
|
-
...(updatedAt !== undefined ? { updatedAt } : {})
|
|
142
|
+
...(updatedAt !== undefined ? { updatedAt } : {}),
|
|
143
|
+
...(theme ? { theme } : {})
|
|
150
144
|
}
|
|
151
145
|
}
|
|
152
146
|
|
|
153
147
|
return {
|
|
154
148
|
thumbnails,
|
|
155
|
-
...(updatedAt !== undefined ? { updatedAt } : {})
|
|
149
|
+
...(updatedAt !== undefined ? { updatedAt } : {}),
|
|
150
|
+
...(theme ? { theme } : {})
|
|
156
151
|
}
|
|
157
152
|
} catch {
|
|
158
153
|
return { thumbnails: [] }
|
package/server/moi-scaffold.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// `moi openclaw init`). Creates `.moi/widgets/`, writes the widget
|
|
3
3
|
// dependency manifest, and installs dependencies — so the agent never has to
|
|
4
4
|
// bootstrap the folder itself.
|
|
5
|
-
import { mkdir } from 'node:fs/promises'
|
|
5
|
+
import { mkdir, stat } 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
|
|
@@ -60,12 +60,22 @@ declare module 'moi' {
|
|
|
60
60
|
// Absolute URL to a workspace file, streamed by the server. Pass a
|
|
61
61
|
// workspace-relative path (e.g. 'clips/001.mp4'). Media/asset files only.
|
|
62
62
|
export function fileUrl(path: string): string
|
|
63
|
+
// Switch the workspace to a tab (replace navigation). \`params\` reach the
|
|
64
|
+
// target view as its \`params\` prop — JSON-plain values only. No-ops outside
|
|
65
|
+
// the moi host. Tab ids: 'agent' | 'widgets' | 'scratchpad' | 'view:<id>'.
|
|
66
|
+
export function focusTab(tab: string, params?: Record<string, unknown>): void
|
|
67
|
+
// Send a chat message to the workspace's active chat, as if the user typed
|
|
68
|
+
// \`message\`. \`context\` rides along as structured data the agent sees but
|
|
69
|
+
// the user does not — JSON-plain values only. Call it from event handlers,
|
|
70
|
+
// never during render: each call starts an agent run, and repeats are
|
|
71
|
+
// rate-limited.
|
|
72
|
+
export function sendChatMessage(message: string, context?: Record<string, unknown>): void
|
|
63
73
|
export type WidgetConfig = {
|
|
64
74
|
rowSpan: 1 | 2 | 3 | 4
|
|
65
75
|
colSpan: 1 | 2 | 3 | 4
|
|
66
76
|
requiredEnv?: string[]
|
|
67
77
|
}
|
|
68
|
-
export type ViewConfig = { title?: string; requiredEnv?: string[] }
|
|
78
|
+
export type ViewConfig = { title?: string; icon?: string; requiredEnv?: string[] }
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
// Bundled asset imports (\`import logo from './logo.png'\`) resolve to a URL string.
|
|
@@ -78,6 +88,30 @@ declare module '*.avif' { const s: string; export default s }
|
|
|
78
88
|
declare module '*.svg' { const s: string; export default s }
|
|
79
89
|
`
|
|
80
90
|
|
|
91
|
+
// Write `.moi/applet-env.d.ts` from the template this CLI ships, overwriting
|
|
92
|
+
// whatever is there. The file is auto-generated and declares the `moi` module's
|
|
93
|
+
// public API, so it drifts the moment the CLI grows an applet-facing function
|
|
94
|
+
// (`focusTab`, `sendChatMessage`) while a workspace keeps the copy written at
|
|
95
|
+
// `moi init` time — leaving the agent's editor and `tsc` insisting a real API
|
|
96
|
+
// doesn't exist. Regenerated alongside skills, the other agent-facing contract
|
|
97
|
+
// moi ships. Refreshes an existing `.moi/` only — never creates one, so a
|
|
98
|
+
// directory that was never scaffolded doesn't sprout a `.moi/` holding nothing
|
|
99
|
+
// but a declaration file. Returns whether it wrote.
|
|
100
|
+
export async function writeAppletEnvDts(workspacePath: string): Promise<boolean> {
|
|
101
|
+
const moiDir = join(workspacePath, '.moi')
|
|
102
|
+
if (!(await isDirectory(moiDir))) return false
|
|
103
|
+
await Bun.write(join(moiDir, 'applet-env.d.ts'), APPLET_ENV_DTS)
|
|
104
|
+
return true
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function isDirectory(path: string): Promise<boolean> {
|
|
108
|
+
try {
|
|
109
|
+
return (await stat(path)).isDirectory()
|
|
110
|
+
} catch {
|
|
111
|
+
return false
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
81
115
|
// Bootstraps `.moi/` ONLY when it doesn't exist yet. Re-running `moi init`
|
|
82
116
|
// on an existing workspace overwrites skills but must leave the user's
|
|
83
117
|
// `.moi/` (their deps, widgets, lockfile) completely untouched.
|
|
@@ -106,7 +140,7 @@ export async function scaffoldMoiDir(
|
|
|
106
140
|
|
|
107
141
|
await mkdir(join(moiDir, 'widgets'), { recursive: true })
|
|
108
142
|
await Bun.write(packagePath, JSON.stringify(MOI_PACKAGE_JSON, null, 2) + '\n')
|
|
109
|
-
await
|
|
143
|
+
await writeAppletEnvDts(workspacePath)
|
|
110
144
|
|
|
111
145
|
const exited = installDependencies(moiDir)
|
|
112
146
|
let timer: ReturnType<typeof setTimeout> | undefined
|
package/server/registry.ts
CHANGED
|
@@ -73,7 +73,7 @@ export async function registerWorkspace(
|
|
|
73
73
|
...(opts.isDefault ? { isDefault: opts.isDefault } : {}),
|
|
74
74
|
...(opts.lastRunAt ? { lastRunAt: opts.lastRunAt } : {})
|
|
75
75
|
}
|
|
76
|
-
await writeRegistry([...entries
|
|
76
|
+
await writeRegistry([entry, ...entries])
|
|
77
77
|
return withDisplayPath(entry)
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { WorkspaceSkillsStatus, WorkspaceSkillStatus, WorkspaceType } from '@/lib/types'
|
|
2
|
+
|
|
3
|
+
import { writeAppletEnvDts } from './moi-scaffold'
|
|
4
|
+
import { isMinorBehind, skillStatuses } from './skill-version'
|
|
5
|
+
import { installBundledSkills } from './skills-template'
|
|
6
|
+
import { skillsDirFor } from './workspace-init'
|
|
7
|
+
|
|
8
|
+
export type WorkspaceSkillUpdateResult = {
|
|
9
|
+
before: WorkspaceSkillStatus[]
|
|
10
|
+
status: WorkspaceSkillsStatus
|
|
11
|
+
// False when the workspace has no `.moi/` to refresh — nothing was written.
|
|
12
|
+
appletTypesWritten: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function summarizeSkillStatuses(skills: WorkspaceSkillStatus[]): WorkspaceSkillsStatus {
|
|
16
|
+
return {
|
|
17
|
+
skills,
|
|
18
|
+
updateAvailable: skills.some(skill => isMinorBehind(skill.installed, skill.bundled))
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function getWorkspaceSkillsStatus(
|
|
23
|
+
workspaceRoot: string,
|
|
24
|
+
type?: WorkspaceType
|
|
25
|
+
): Promise<WorkspaceSkillsStatus> {
|
|
26
|
+
return summarizeSkillStatuses(await skillStatuses(workspaceRoot, type))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function updateWorkspaceSkills(
|
|
30
|
+
workspaceRoot: string,
|
|
31
|
+
type: WorkspaceType = 'claude-code'
|
|
32
|
+
): Promise<WorkspaceSkillUpdateResult> {
|
|
33
|
+
const before = await skillStatuses(workspaceRoot, type)
|
|
34
|
+
await installBundledSkills(skillsDirFor(workspaceRoot, type))
|
|
35
|
+
// The ambient applet types ship with the CLI just like the skills do, and go
|
|
36
|
+
// stale the same way — refresh both in one operation so `moi skill update`
|
|
37
|
+
// (and the UI's update button) leaves nothing behind. Skipped when the
|
|
38
|
+
// workspace has no `.moi/`: skills stand on their own, applet types don't.
|
|
39
|
+
const appletTypesWritten = await writeAppletEnvDts(workspaceRoot)
|
|
40
|
+
const skills = await skillStatuses(workspaceRoot, type)
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
before,
|
|
44
|
+
status: summarizeSkillStatuses(skills),
|
|
45
|
+
appletTypesWritten
|
|
46
|
+
}
|
|
47
|
+
}
|