moi-computer 0.3.1-next.1 → 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 +85 -12
- 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 +25 -4
- 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 +213 -77
- 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/main.tsx +10 -2
- 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-1dfbr7n2.js → chunk-3m1xe1j3.js} +94 -94
- package/dist/chunk-5vaevt8z.js +2 -0
- package/dist/chunk-7bzpmtxp.js +50 -0
- package/dist/chunk-h0hk61pm.js +9 -0
- package/dist/{chunk-vkvb3hjm.js → chunk-h3evrtyp.js} +1 -1
- package/dist/chunk-k5sjx9s5.js +1 -0
- package/dist/{chunk-jen6xcm1.js → chunk-m9qja0nx.js} +1 -1
- package/dist/chunk-s7za1qsv.css +1 -0
- package/dist/{chunk-sxbfh73c.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/harness/claude-code/index.ts +2 -1
- package/server/harness/codex/adapter.ts +100 -9
- package/server/harness/codex/client.ts +34 -1
- package/server/harness/codex/index.ts +2 -1
- package/server/harness/codex/session.ts +32 -8
- 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-339jds4x.js +0 -15
- package/dist/chunk-3xsvsnhr.css +0 -1
- package/dist/chunk-6c8cwpzc.js +0 -1
- package/dist/chunk-anqmsbjt.js +0 -2
- package/dist/chunk-hbvfb6sk.js +0 -63
- package/dist/chunk-qwm5f6qk.js +0 -48
- package/dist/chunk-yp4srgqt.js +0 -10
- package/workspace/.claude/skills/moi-workspace/VIEW-DESIGN.md +0 -22
|
@@ -15,9 +15,12 @@ import type { McpServer, Model, SessionInfo, StreamEvent } from '@/lib/types'
|
|
|
15
15
|
import {
|
|
16
16
|
type CodexModel,
|
|
17
17
|
type CodexThread,
|
|
18
|
+
type SubagentReplay,
|
|
19
|
+
childThreadToSubagentRecord,
|
|
18
20
|
codexModelToModel,
|
|
19
21
|
codexThreadToEvents,
|
|
20
22
|
codexThreadToSessionInfo,
|
|
23
|
+
collectSubagentActivities,
|
|
21
24
|
selectCodexWorkspacePreview
|
|
22
25
|
} from './adapter'
|
|
23
26
|
import type { WorkspaceActivityPreview } from '../types'
|
|
@@ -376,6 +379,35 @@ export async function getCodexMcpStatus(workspacePath: string): Promise<McpServe
|
|
|
376
379
|
}
|
|
377
380
|
}
|
|
378
381
|
|
|
382
|
+
// Rebuild the SubagentRecords for a replayed parent thread: read each child
|
|
383
|
+
// thread announced by a `subAgentActivity` item and fold its transcript into
|
|
384
|
+
// a replay record. A child that can't be read just leaves its bare card.
|
|
385
|
+
export async function readSubagentRecords(
|
|
386
|
+
client: CodexClient,
|
|
387
|
+
thread: CodexThread
|
|
388
|
+
): Promise<Map<string, SubagentReplay>> {
|
|
389
|
+
const map = new Map<string, SubagentReplay>()
|
|
390
|
+
const parentTurnIds = new Set((thread.turns ?? []).map(t => t.id))
|
|
391
|
+
for (const activity of collectSubagentActivities(thread)) {
|
|
392
|
+
const childId = activity.agentThreadId
|
|
393
|
+
if (!childId) continue
|
|
394
|
+
try {
|
|
395
|
+
const res = await client.rpc<{ thread?: CodexThread }>('thread/read', {
|
|
396
|
+
threadId: childId,
|
|
397
|
+
includeTurns: true
|
|
398
|
+
})
|
|
399
|
+
if (!res.thread) continue
|
|
400
|
+
map.set(childId, {
|
|
401
|
+
toolCallId: activity.id,
|
|
402
|
+
record: childThreadToSubagentRecord(res.thread, activity, parentTurnIds)
|
|
403
|
+
})
|
|
404
|
+
} catch {
|
|
405
|
+
// child thread unreadable (deleted, other cwd) — keep the plain card
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return map
|
|
409
|
+
}
|
|
410
|
+
|
|
379
411
|
// Static history replay for the REST events endpoint (no live subscription).
|
|
380
412
|
export async function getCodexThreadEvents(
|
|
381
413
|
workspacePath: string,
|
|
@@ -387,7 +419,8 @@ export async function getCodexThreadEvents(
|
|
|
387
419
|
threadId,
|
|
388
420
|
includeTurns: true
|
|
389
421
|
})
|
|
390
|
-
|
|
422
|
+
if (!res.thread) return []
|
|
423
|
+
return codexThreadToEvents(res.thread, await readSubagentRecords(client, res.thread))
|
|
391
424
|
} catch {
|
|
392
425
|
return []
|
|
393
426
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Codex as a Harness. Thin wiring over this folder's modules — see
|
|
2
2
|
// ../types.ts for the contract and ../README.md for the architecture.
|
|
3
3
|
import type { Harness } from '../types'
|
|
4
|
-
import { pathHarnessAvailability } from '../executable'
|
|
4
|
+
import { findHarnessExecutable, pathHarnessAvailability } from '../executable'
|
|
5
5
|
import {
|
|
6
6
|
getCodexMcpStatus,
|
|
7
7
|
getCodexModels,
|
|
@@ -68,6 +68,7 @@ export const codexHarness: Harness = {
|
|
|
68
68
|
statusLines: () => {
|
|
69
69
|
const active = getCodexActiveSessions()
|
|
70
70
|
return [
|
|
71
|
+
`codex executable ${findHarnessExecutable('codex') ?? '(not found)'}`,
|
|
71
72
|
`live Codex runs ${active.length}`,
|
|
72
73
|
...active.map(r => ` ▶ busy ws=${r.workspaceId} session=${r.sessionId}`)
|
|
73
74
|
]
|
|
@@ -30,11 +30,12 @@ import {
|
|
|
30
30
|
type CodexThreadItem,
|
|
31
31
|
type CodexTokenUsage,
|
|
32
32
|
type CodexTurn,
|
|
33
|
+
type SubagentReplay,
|
|
33
34
|
codexItemToNotice,
|
|
34
35
|
codexItemToTurn,
|
|
35
36
|
codexThreadToEvents
|
|
36
37
|
} from './adapter'
|
|
37
|
-
import { type CodexClient, getCodexClient } from './client'
|
|
38
|
+
import { type CodexClient, getCodexClient, readSubagentRecords } from './client'
|
|
38
39
|
import { debug } from '../../debug'
|
|
39
40
|
import { broadcast } from '../../state'
|
|
40
41
|
import { hasThreadConfig, renameThreadConfig, saveThreadConfig } from '../../thread-config'
|
|
@@ -180,6 +181,10 @@ function handleChildNotification(
|
|
|
180
181
|
if (method === 'item/started' || method === 'item/completed') {
|
|
181
182
|
const item = params.item as CodexThreadItem | undefined
|
|
182
183
|
if (!item) return
|
|
184
|
+
// The child's own `subAgentActivity` (its send-back to the parent) would
|
|
185
|
+
// render as a cryptic nested agent card — skip it, matching the replay
|
|
186
|
+
// path (childThreadToSubagentRecord).
|
|
187
|
+
if (item.type === 'subAgentActivity') return
|
|
183
188
|
const turn = codexItemToTurn(item, childThreadId)
|
|
184
189
|
if (!turn) return
|
|
185
190
|
const idx = child.record.transcript.findIndex(t => t.id === turn.id)
|
|
@@ -289,6 +294,15 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
|
|
|
289
294
|
forwardPreview(rec, params.itemId as string, 'reasoning', String(params.delta ?? ''))
|
|
290
295
|
return
|
|
291
296
|
}
|
|
297
|
+
case 'item/reasoning/summaryPartAdded': {
|
|
298
|
+
// Each part is a new summary section; without a break the sections
|
|
299
|
+
// concatenate into one run-on paragraph. Skip the first part (no
|
|
300
|
+
// preview text yet) so the reasoning doesn't open with a blank line.
|
|
301
|
+
if (rec.previews.has(params.itemId as string)) {
|
|
302
|
+
forwardPreview(rec, params.itemId as string, 'reasoning', '\n')
|
|
303
|
+
}
|
|
304
|
+
return
|
|
305
|
+
}
|
|
292
306
|
case 'thread/tokenUsage/updated': {
|
|
293
307
|
rec.lastUsage = (params.tokenUsage ?? null) as CodexTokenUsage | null
|
|
294
308
|
return
|
|
@@ -415,9 +429,13 @@ function createRecord(input: {
|
|
|
415
429
|
}
|
|
416
430
|
|
|
417
431
|
// Seed a record's view from a resumed thread payload (turns included).
|
|
418
|
-
function seedFromThread(
|
|
432
|
+
function seedFromThread(
|
|
433
|
+
rec: SessionRecord,
|
|
434
|
+
thread: CodexThread,
|
|
435
|
+
subagents?: Map<string, SubagentReplay>
|
|
436
|
+
) {
|
|
419
437
|
let view = emptyViewState()
|
|
420
|
-
for (const ev of codexThreadToEvents(thread)) view = applyEvent(view, ev)
|
|
438
|
+
for (const ev of codexThreadToEvents(thread, subagents)) view = applyEvent(view, ev)
|
|
421
439
|
rec.view = view
|
|
422
440
|
}
|
|
423
441
|
|
|
@@ -433,7 +451,12 @@ async function resumeSession(input: {
|
|
|
433
451
|
threadId: input.sessionId
|
|
434
452
|
})
|
|
435
453
|
const rec = createRecord({ ...input, sessionId: resumed.thread.id, client })
|
|
436
|
-
|
|
454
|
+
// Rebuild child-agent transcripts from their own threads and register them
|
|
455
|
+
// as live children, so a mid-run resume keeps routing child frames into
|
|
456
|
+
// the same records the replay attached.
|
|
457
|
+
const subagents = await readSubagentRecords(client, resumed.thread)
|
|
458
|
+
for (const [childId, sub] of subagents) rec.children.set(childId, sub)
|
|
459
|
+
seedFromThread(rec, resumed.thread, subagents)
|
|
437
460
|
return rec
|
|
438
461
|
}
|
|
439
462
|
|
|
@@ -581,10 +604,11 @@ export async function sendCodexMessage(input: {
|
|
|
581
604
|
...(additionalContext ? { additionalContext } : {}),
|
|
582
605
|
// Without an explicit summary mode Codex still reasons but emits the
|
|
583
606
|
// reasoning item with EMPTY summary/content (verified on the wire —
|
|
584
|
-
// scripts/codex-probe.ts), so no thinking ever reaches the UI. '
|
|
585
|
-
// makes summaries stream
|
|
586
|
-
//
|
|
587
|
-
|
|
607
|
+
// scripts/codex-probe.ts), so no thinking ever reaches the UI. 'detailed'
|
|
608
|
+
// (vs 'auto') makes the summaries longer and stream in more frequent
|
|
609
|
+
// item/reasoning/summaryTextDelta bursts while the model is still
|
|
610
|
+
// thinking — 'auto' tends to emit one short blob near the end.
|
|
611
|
+
summary: 'detailed',
|
|
588
612
|
...(input.model ? { model: input.model } : {}),
|
|
589
613
|
...(input.effort ? { effort: input.effort } : {})
|
|
590
614
|
}
|
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
|
+
}
|
package/server/skill-version.ts
CHANGED
|
@@ -7,21 +7,12 @@
|
|
|
7
7
|
import { readdir } from 'node:fs/promises'
|
|
8
8
|
import { join } from 'node:path'
|
|
9
9
|
|
|
10
|
-
import type { WorkspaceType } from '@/lib/types'
|
|
10
|
+
import type { WorkspaceSkillStatus, WorkspaceType } from '@/lib/types'
|
|
11
11
|
|
|
12
12
|
import { findWorkspaceForPath, liftToWorkspaceRoot, listWorkspaces } from './registry'
|
|
13
13
|
import { BUNDLED_SKILLS_DIR } from './skills-template'
|
|
14
14
|
import { skillsDirFor } from './workspace-init'
|
|
15
15
|
|
|
16
|
-
export type SkillStatus = {
|
|
17
|
-
name: string
|
|
18
|
-
// Version stamped in the workspace's copy. `null` means absent — either the
|
|
19
|
-
// skill isn't installed or it predates skill versioning (treated as behind).
|
|
20
|
-
installed: string | null
|
|
21
|
-
// Version shipped with this CLI. `null` only if a bundled skill lacks a stamp.
|
|
22
|
-
bundled: string | null
|
|
23
|
-
}
|
|
24
|
-
|
|
25
16
|
// The version is stamped as a self-contained marker in SKILL.md, e.g.
|
|
26
17
|
// `<moi-skill version="0.1.0" />`, rather than in YAML frontmatter. SKILL.md
|
|
27
18
|
// frontmatter is NOT reliably strict YAML — the free-text `description` routinely
|
|
@@ -99,7 +90,7 @@ export async function bundledSkillNames(): Promise<string[]> {
|
|
|
99
90
|
export async function skillStatuses(
|
|
100
91
|
workspaceRoot: string,
|
|
101
92
|
type?: WorkspaceType
|
|
102
|
-
): Promise<
|
|
93
|
+
): Promise<WorkspaceSkillStatus[]> {
|
|
103
94
|
const names = await bundledSkillNames()
|
|
104
95
|
const skillsDir = skillsDirFor(workspaceRoot, type)
|
|
105
96
|
return Promise.all(
|
package/server/tabs.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// `moi tabs` / `moi tab focus` server logic: assemble the tab listing and
|
|
2
|
+
// validate a focus target. Pure given its inputs — the control handler wires
|
|
3
|
+
// in the workspace lookups (see control.ts), tests pass fakes.
|
|
4
|
+
import type { ViewInfo, WorkspaceTabId } from '@/lib/types'
|
|
5
|
+
import { viewIdFromTab, viewTabId } from '@/lib/workspace-tabs'
|
|
6
|
+
|
|
7
|
+
// One row of `moi tabs`. `isDefault` marks the workspace's saved default tab
|
|
8
|
+
// (`layout.tabs.active`) — where a bare `/workspace/:id` lands.
|
|
9
|
+
export type TabRow = {
|
|
10
|
+
id: WorkspaceTabId
|
|
11
|
+
title: string
|
|
12
|
+
isDefault: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// The always-present tabs, titled like the tab bar renders them.
|
|
16
|
+
const STATIC_TABS: { id: WorkspaceTabId; title: string }[] = [
|
|
17
|
+
{ id: 'agent', title: 'Agent' },
|
|
18
|
+
{ id: 'widgets', title: 'Widgets' },
|
|
19
|
+
{ id: 'scratchpad', title: 'Scratchpad' }
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
// The `moi tabs` listing: static tabs plus each built view, the saved default
|
|
23
|
+
// marked. View builders are transient build-state, not addressable tabs, so
|
|
24
|
+
// they don't list (and a builder default simply marks no row).
|
|
25
|
+
export function assembleTabRows(views: ViewInfo[], defaultTab: WorkspaceTabId): TabRow[] {
|
|
26
|
+
return [
|
|
27
|
+
...STATIC_TABS,
|
|
28
|
+
...views.map(view => ({ id: viewTabId(view.id), title: view.config.title || view.id }))
|
|
29
|
+
].map(row => ({ ...row, isDefault: row.id === defaultTab }))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type FocusTabDeps = {
|
|
33
|
+
// Whether a view id exists in the workspace (source or built) — hasViewId.
|
|
34
|
+
hasView: (viewId: string) => Promise<boolean>
|
|
35
|
+
// The built views, for the error message's valid-id list — getViewList.
|
|
36
|
+
viewList: () => Promise<ViewInfo[]>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type FocusTabResult = { ok: true; tab: WorkspaceTabId } | { ok: false; error: string }
|
|
40
|
+
|
|
41
|
+
// Validate a `moi tab focus` target: static ids pass as-is, `view:<id>` must
|
|
42
|
+
// name a real view. Anything else — including view-builder tabs — fails with
|
|
43
|
+
// the list of valid ids. Addressing is by tab id, never by title.
|
|
44
|
+
export async function resolveFocusTab(raw: unknown, deps: FocusTabDeps): Promise<FocusTabResult> {
|
|
45
|
+
const tab = typeof raw === 'string' ? raw.trim() : ''
|
|
46
|
+
if (STATIC_TABS.some(row => row.id === tab)) return { ok: true, tab: tab as WorkspaceTabId }
|
|
47
|
+
|
|
48
|
+
const viewId = tab.startsWith('view:') ? viewIdFromTab(tab as WorkspaceTabId) : null
|
|
49
|
+
if (viewId && (await deps.hasView(viewId))) return { ok: true, tab: tab as WorkspaceTabId }
|
|
50
|
+
|
|
51
|
+
const validIds = [
|
|
52
|
+
...STATIC_TABS.map(row => row.id),
|
|
53
|
+
...(await deps.viewList()).map(view => viewTabId(view.id))
|
|
54
|
+
]
|
|
55
|
+
return {
|
|
56
|
+
ok: false,
|
|
57
|
+
error: `Unknown tab "${tab || String(raw ?? '')}". Valid tabs: ${validIds.join(', ')}`
|
|
58
|
+
}
|
|
59
|
+
}
|
package/server/theme.ts
CHANGED
|
@@ -8,9 +8,8 @@ export type ThemeUpdateResult =
|
|
|
8
8
|
| { ok: true; theme: ThemeShape; applied: { font?: FontTheme; color?: ColorTheme } }
|
|
9
9
|
| { ok: false; error: string }
|
|
10
10
|
|
|
11
|
-
// Pure merge + validation for a theme update.
|
|
12
|
-
//
|
|
13
|
-
// `undefined` bg/fg, which JSON.stringify drops on save.
|
|
11
|
+
// Pure merge + validation for a theme update. The workspace stores only the
|
|
12
|
+
// selected font and primary; all other color tokens are derived at runtime.
|
|
14
13
|
export function applyThemeUpdate(
|
|
15
14
|
current: WorkspaceLayout['theme'],
|
|
16
15
|
update: ThemeUpdate
|
|
@@ -22,15 +21,10 @@ export function applyThemeUpdate(
|
|
|
22
21
|
return { ok: false, error: `Unknown color theme: ${update.color}` }
|
|
23
22
|
}
|
|
24
23
|
|
|
24
|
+
const primary = update.color ? COLOR_THEMES[update.color as ColorTheme].primary : current?.primary
|
|
25
25
|
const theme: ThemeShape = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (update.color) {
|
|
31
|
-
const preset = COLOR_THEMES[update.color as ColorTheme]
|
|
32
|
-
theme.background = preset.background
|
|
33
|
-
theme.foreground = preset.foreground
|
|
26
|
+
font: (update.font as FontTheme) ?? current?.font ?? 'default',
|
|
27
|
+
...(primary ? { primary } : {})
|
|
34
28
|
}
|
|
35
29
|
|
|
36
30
|
return {
|
|
@@ -43,13 +37,13 @@ export function applyThemeUpdate(
|
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
|
|
46
|
-
// Reverse-lookup: resolve stored
|
|
47
|
-
export function matchColorTheme(
|
|
40
|
+
// Reverse-lookup: resolve the stored primary to a preset key, or null for custom colors.
|
|
41
|
+
export function matchColorTheme(primary: string | undefined): ColorTheme | null {
|
|
48
42
|
for (const [key, preset] of Object.entries(COLOR_THEMES) as [
|
|
49
43
|
ColorTheme,
|
|
50
44
|
(typeof COLOR_THEMES)[ColorTheme]
|
|
51
45
|
][]) {
|
|
52
|
-
if (preset.
|
|
46
|
+
if (preset.primary === primary) return key
|
|
53
47
|
}
|
|
54
48
|
return null
|
|
55
49
|
}
|
package/server/view-builders.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, rename } from 'node:fs/promises'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
|
|
4
|
+
import { APP_ICON_IDS, isAppIconId } from '@/lib/app-icons'
|
|
4
5
|
import { newBuilderId } from '@/lib/ids'
|
|
5
6
|
import type { AppletKind, ViewBuilder, ViewInfo } from '@/lib/types'
|
|
6
7
|
|
|
@@ -193,8 +194,11 @@ export async function setBuilder(
|
|
|
193
194
|
if (!/^[a-z0-9][a-z0-9_-]*$/.test(appletId)) {
|
|
194
195
|
throw new ViewBuilderError('Invalid applet id', 400)
|
|
195
196
|
}
|
|
196
|
-
if (input.icon !== undefined &&
|
|
197
|
-
throw new ViewBuilderError(
|
|
197
|
+
if (input.icon !== undefined && !isAppIconId(input.icon)) {
|
|
198
|
+
throw new ViewBuilderError(
|
|
199
|
+
`Unknown view icon id "${input.icon}". Use one of: ${APP_ICON_IDS.join(', ')}`,
|
|
200
|
+
400
|
|
201
|
+
)
|
|
198
202
|
}
|
|
199
203
|
// Views and widgets are separate applet namespaces, so an id is only unique
|
|
200
204
|
// within a kind — a view and a widget may both be called "stats".
|