moi-computer 0.0.1
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/LICENSE +95 -0
- package/README.md +71 -0
- package/bin/moi.mjs +25 -0
- package/bunfig.toml +3 -0
- package/client/CLAUDE.md +12 -0
- package/client/api/workspaces.ts +158 -0
- package/client/assets/claude.svg +3 -0
- package/client/assets/favicon.png +0 -0
- package/client/assets/hermes-nous.png +0 -0
- package/client/assets/mcp/.gitkeep +0 -0
- package/client/assets/mcp/atlassian.png +0 -0
- package/client/assets/mcp/discord.png +0 -0
- package/client/assets/mcp/figma.png +0 -0
- package/client/assets/mcp/github.png +0 -0
- package/client/assets/mcp/gitlab.png +0 -0
- package/client/assets/mcp/granola.png +0 -0
- package/client/assets/mcp/hubspot.png +0 -0
- package/client/assets/mcp/linear.png +0 -0
- package/client/assets/mcp/neon.png +0 -0
- package/client/assets/mcp/notion.png +0 -0
- package/client/assets/mcp/sentry.png +0 -0
- package/client/assets/mcp/slack.png +0 -0
- package/client/assets/mcp/stripe.png +0 -0
- package/client/assets/mcp/supabase.png +0 -0
- package/client/assets/mcp/vercel.png +0 -0
- package/client/assets/moi-logo.svg +11 -0
- package/client/assets/openclaw.svg +22 -0
- package/client/components/App.tsx +35 -0
- package/client/components/BottomPanel.tsx +33 -0
- package/client/components/ChatInput.tsx +62 -0
- package/client/components/ChatPanel.tsx +206 -0
- package/client/components/ChatPopup.tsx +60 -0
- package/client/components/CustomizePanel.tsx +117 -0
- package/client/components/HiddenPanel.tsx +79 -0
- package/client/components/HomePage.tsx +17 -0
- package/client/components/MarkdownContent.tsx +41 -0
- package/client/components/ThreadSelector.tsx +88 -0
- package/client/components/TurnView.tsx +618 -0
- package/client/components/WidgetErrorBoundary.tsx +46 -0
- package/client/components/WidgetFrame.tsx +66 -0
- package/client/components/WidgetGrid.tsx +113 -0
- package/client/components/WidgetShell.tsx +44 -0
- package/client/components/Widgets.tsx +132 -0
- package/client/components/WorkspacePreview.tsx +48 -0
- package/client/components/WorkspacesPage.tsx +237 -0
- package/client/components/layout/SidebarLayout.tsx +260 -0
- package/client/components/playground/LedLogo.tsx +181 -0
- package/client/components/playground/PixelPainter.tsx +105 -0
- package/client/components/playground/PlaygroundPage.tsx +71 -0
- package/client/components/routes/workspace/[id].tsx +282 -0
- package/client/components/ui/button.tsx +48 -0
- package/client/components/ui/dropdown-menu.tsx +257 -0
- package/client/components/ui/input.tsx +21 -0
- package/client/components/ui/popover.tsx +79 -0
- package/client/components/ui/textarea.tsx +18 -0
- package/client/externalize-react.ts +29 -0
- package/client/hooks/useChat.ts +88 -0
- package/client/hooks/useFitsSidebar.ts +34 -0
- package/client/hooks/useGridReconcile.ts +73 -0
- package/client/hooks/useMeiEvents.ts +66 -0
- package/client/hooks/useScrollFade.ts +38 -0
- package/client/hooks/useWidget.ts +72 -0
- package/client/hooks/useWidgetList.ts +30 -0
- package/client/hooks/useWorkspaceTheme.ts +76 -0
- package/client/index.css +182 -0
- package/client/index.html +43 -0
- package/client/index.tsx +19 -0
- package/client/lib/WorkspaceContext.tsx +24 -0
- package/client/lib/WorkspaceLayoutContext.tsx +92 -0
- package/client/lib/cn.ts +6 -0
- package/client/lib/grid-pack.ts +35 -0
- package/client/lib/group-turns.ts +44 -0
- package/client/lib/mcp-icons.ts +53 -0
- package/client/lib/ws.ts +129 -0
- package/client/main.tsx +23 -0
- package/client/store/chat.tsx +162 -0
- package/client/store/ui.ts +21 -0
- package/client/theme.css +66 -0
- package/lib/claude-adapter.ts +602 -0
- package/lib/format.ts +212 -0
- package/lib/themes.ts +89 -0
- package/lib/types.ts +144 -0
- package/package.json +117 -0
- package/server/CLAUDE.md +6 -0
- package/server/agent.ts +132 -0
- package/server/build-widget.ts +343 -0
- package/server/cli.ts +632 -0
- package/server/constants.ts +3 -0
- package/server/control.ts +98 -0
- package/server/functions-worker.ts +89 -0
- package/server/functions.ts +171 -0
- package/server/layout.ts +83 -0
- package/server/openclaw-adapter.ts +242 -0
- package/server/openclaw-gateway.ts +255 -0
- package/server/openclaw-session.ts +485 -0
- package/server/openclaw-strip.ts +134 -0
- package/server/openclaw.ts +206 -0
- package/server/registry.ts +150 -0
- package/server/skills-template.ts +21 -0
- package/server/state.ts +87 -0
- package/server/theme.ts +55 -0
- package/server/web.ts +321 -0
- package/server/widgets.ts +254 -0
- package/tsconfig.json +21 -0
- package/workspace/.claude/skills/widgets/DESIGN.md +630 -0
- package/workspace/.claude/skills/widgets/SKILL.md +176 -0
package/lib/format.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// Display-only conversation format. Agent-agnostic.
|
|
2
|
+
// Source: dev/sdk-message-spec.md §14 (and the research PDF under dev/report).
|
|
3
|
+
// Built at ingest time from an agent's raw stream (today: Claude Agent SDK).
|
|
4
|
+
|
|
5
|
+
export type ToolCaller = 'model' | 'server-tool' | 'mcp' | 'subagent'
|
|
6
|
+
|
|
7
|
+
export type ToolState =
|
|
8
|
+
| 'pending'
|
|
9
|
+
| 'approval-pending'
|
|
10
|
+
| 'approval-denied'
|
|
11
|
+
| 'running'
|
|
12
|
+
| 'success'
|
|
13
|
+
| 'error'
|
|
14
|
+
|
|
15
|
+
export type SubagentStatus = 'running' | 'completed' | 'failed' | 'stopped'
|
|
16
|
+
|
|
17
|
+
export type SubagentRecord = {
|
|
18
|
+
taskId: string
|
|
19
|
+
description: string
|
|
20
|
+
progress: string[]
|
|
21
|
+
status: SubagentStatus
|
|
22
|
+
usage?: { totalTokens?: number; toolUses?: number; durationMs?: number }
|
|
23
|
+
transcript: Turn[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SkillRecord = {
|
|
27
|
+
skillName: string
|
|
28
|
+
body?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type ToolCall = {
|
|
32
|
+
toolCallId: string
|
|
33
|
+
name: string
|
|
34
|
+
caller: ToolCaller
|
|
35
|
+
// Origin platform — lets the UI pick the right display label and brief
|
|
36
|
+
// for the same canonical action (`read` vs `Read`, `exec` vs `Bash`).
|
|
37
|
+
// Adapters are responsible for setting it; UI defaults to a generic
|
|
38
|
+
// rendering when absent.
|
|
39
|
+
provider?: 'claude-code' | 'openclaw'
|
|
40
|
+
mcpServer?: string
|
|
41
|
+
state: ToolState
|
|
42
|
+
input: unknown
|
|
43
|
+
output?: unknown
|
|
44
|
+
errorText?: string
|
|
45
|
+
sidecar?: Record<string, unknown>
|
|
46
|
+
subagent?: SubagentRecord
|
|
47
|
+
skill?: SkillRecord
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type Citation = { url?: string; title?: string; quote?: string }
|
|
51
|
+
|
|
52
|
+
export type Part =
|
|
53
|
+
| { type: 'text'; text: string; citations?: Citation[] }
|
|
54
|
+
| { type: 'reasoning'; text: string; redacted?: boolean; signature?: string }
|
|
55
|
+
| { type: 'tool-call'; call: ToolCall }
|
|
56
|
+
| { type: 'file'; mediaType: string; url: string; filename?: string }
|
|
57
|
+
| { type: 'source-url'; url: string; title?: string; sourceId: string }
|
|
58
|
+
| { type: 'source-document'; mediaType: string; title: string; sourceId: string }
|
|
59
|
+
| { type: 'data'; name: string; data: unknown }
|
|
60
|
+
|
|
61
|
+
export type TurnOrigin =
|
|
62
|
+
| { kind: 'user-input' }
|
|
63
|
+
| { kind: 'tool-return'; toolCallId: string }
|
|
64
|
+
| {
|
|
65
|
+
kind: 'synthetic'
|
|
66
|
+
reason: 'skill-body' | 'system-reminder' | 'hook-output' | 'slash-command' | 'other'
|
|
67
|
+
}
|
|
68
|
+
| { kind: 'subagent-prompt'; parentToolCallId: string }
|
|
69
|
+
| { kind: 'inter-session' }
|
|
70
|
+
| { kind: 'replay' }
|
|
71
|
+
|
|
72
|
+
export type TurnMeta = {
|
|
73
|
+
model?: string
|
|
74
|
+
provider?: string
|
|
75
|
+
stopReason?: string
|
|
76
|
+
usage?: { inputTokens?: number; outputTokens?: number; totalTokens?: number; costUsd?: number }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type Turn = {
|
|
80
|
+
id: string
|
|
81
|
+
role: 'user' | 'assistant'
|
|
82
|
+
origin: TurnOrigin
|
|
83
|
+
parentTaskId?: string
|
|
84
|
+
parts: Part[]
|
|
85
|
+
timestamp?: string
|
|
86
|
+
// Stable monotonic ordering hint when the source provides one (OpenClaw's
|
|
87
|
+
// `__openclaw.seq`). Used as a tiebreaker when timestamps collide; the UI
|
|
88
|
+
// is free to ignore it.
|
|
89
|
+
seq?: number
|
|
90
|
+
meta?: TurnMeta
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type McpServerInfo = { name: string; status: string }
|
|
94
|
+
export type PluginInfo = { name: string; path: string }
|
|
95
|
+
|
|
96
|
+
export type SessionSnapshot = {
|
|
97
|
+
sessionId: string
|
|
98
|
+
model?: string
|
|
99
|
+
cwd?: string
|
|
100
|
+
permissionMode?: string
|
|
101
|
+
tools: string[]
|
|
102
|
+
mcpServers: McpServerInfo[]
|
|
103
|
+
plugins: PluginInfo[]
|
|
104
|
+
skills: string[]
|
|
105
|
+
slashCommands: string[]
|
|
106
|
+
agents: string[]
|
|
107
|
+
updatedAt: string
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type SystemNotice =
|
|
111
|
+
| {
|
|
112
|
+
id: string
|
|
113
|
+
kind: 'rate-limit'
|
|
114
|
+
at: string
|
|
115
|
+
info?: unknown
|
|
116
|
+
}
|
|
117
|
+
| {
|
|
118
|
+
id: string
|
|
119
|
+
kind: 'api-retry'
|
|
120
|
+
at: string
|
|
121
|
+
attempt: number
|
|
122
|
+
maxRetries: number
|
|
123
|
+
delayMs: number
|
|
124
|
+
error?: string
|
|
125
|
+
}
|
|
126
|
+
| { id: string; kind: 'compact'; at: string; metadata?: unknown }
|
|
127
|
+
| {
|
|
128
|
+
id: string
|
|
129
|
+
kind: 'hook'
|
|
130
|
+
at: string
|
|
131
|
+
hookId: string
|
|
132
|
+
hookName: string
|
|
133
|
+
event: string
|
|
134
|
+
status: 'started' | 'progress' | 'response'
|
|
135
|
+
output?: string
|
|
136
|
+
exitCode?: number
|
|
137
|
+
outcome?: 'success' | 'error' | 'cancelled'
|
|
138
|
+
}
|
|
139
|
+
| {
|
|
140
|
+
id: string
|
|
141
|
+
kind: 'session-state'
|
|
142
|
+
at: string
|
|
143
|
+
state: 'idle' | 'running' | 'requires-action'
|
|
144
|
+
}
|
|
145
|
+
| {
|
|
146
|
+
id: string
|
|
147
|
+
kind: 'files-persisted'
|
|
148
|
+
at: string
|
|
149
|
+
files: string[]
|
|
150
|
+
failed: { filename: string; error: string }[]
|
|
151
|
+
}
|
|
152
|
+
| { id: string; kind: 'elicitation'; at: string; server: string; elicitationId: string }
|
|
153
|
+
|
|
154
|
+
export type ResultSummary = {
|
|
155
|
+
subtype:
|
|
156
|
+
| 'success'
|
|
157
|
+
| 'error_during_execution'
|
|
158
|
+
| 'error_max_turns'
|
|
159
|
+
| 'error_max_budget_usd'
|
|
160
|
+
| 'error_max_structured_output_retries'
|
|
161
|
+
cost?: number
|
|
162
|
+
turns?: number
|
|
163
|
+
durationMs?: number
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Stream events emitted by the adapter.
|
|
167
|
+
// Semantics: upsert-by-id for `turn` and `snapshot`; append for `notice`; replace for `result`.
|
|
168
|
+
export type StreamEvent =
|
|
169
|
+
| { kind: 'snapshot'; snapshot: SessionSnapshot }
|
|
170
|
+
| { kind: 'turn'; turn: Turn }
|
|
171
|
+
| { kind: 'notice'; notice: SystemNotice }
|
|
172
|
+
| { kind: 'result'; result: ResultSummary }
|
|
173
|
+
|
|
174
|
+
// Materialized view state the UI renders from.
|
|
175
|
+
export type ViewState = {
|
|
176
|
+
snapshot?: SessionSnapshot
|
|
177
|
+
turns: Turn[]
|
|
178
|
+
notices: SystemNotice[]
|
|
179
|
+
result?: ResultSummary
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function emptyViewState(): ViewState {
|
|
183
|
+
return { turns: [], notices: [] }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function applyEvent(state: ViewState, ev: StreamEvent): ViewState {
|
|
187
|
+
switch (ev.kind) {
|
|
188
|
+
case 'snapshot':
|
|
189
|
+
return { ...state, snapshot: ev.snapshot }
|
|
190
|
+
case 'turn': {
|
|
191
|
+
const idx = state.turns.findIndex(t => t.id === ev.turn.id)
|
|
192
|
+
const turns =
|
|
193
|
+
idx >= 0 ? state.turns.map((t, i) => (i === idx ? ev.turn : t)) : [...state.turns, ev.turn]
|
|
194
|
+
return { ...state, turns }
|
|
195
|
+
}
|
|
196
|
+
case 'notice': {
|
|
197
|
+
if (state.notices.some(n => n.id === ev.notice.id)) {
|
|
198
|
+
return {
|
|
199
|
+
...state,
|
|
200
|
+
notices: state.notices.map(n => (n.id === ev.notice.id ? ev.notice : n))
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return { ...state, notices: [...state.notices, ev.notice] }
|
|
204
|
+
}
|
|
205
|
+
case 'result':
|
|
206
|
+
return { ...state, result: ev.result }
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function applyEvents(events: StreamEvent[]): ViewState {
|
|
211
|
+
return events.reduce(applyEvent, emptyViewState())
|
|
212
|
+
}
|
package/lib/themes.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export type FontTheme = 'default' | 'serif' | 'mono' | 'bubbly' | 'geometric' | 'retro'
|
|
2
|
+
|
|
3
|
+
export type FontThemeConfig = {
|
|
4
|
+
label: string
|
|
5
|
+
sans: string
|
|
6
|
+
mono: string
|
|
7
|
+
feel: string
|
|
8
|
+
googleFontsQuery?: string // passed as `family=` param to Google Fonts API
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const FONT_THEMES: Record<FontTheme, FontThemeConfig> = {
|
|
12
|
+
default: {
|
|
13
|
+
label: 'Default',
|
|
14
|
+
sans: 'system-ui',
|
|
15
|
+
mono: 'JetBrains Mono',
|
|
16
|
+
feel: 'Native OS, zero load',
|
|
17
|
+
googleFontsQuery: 'JetBrains+Mono:wght@400;500'
|
|
18
|
+
},
|
|
19
|
+
serif: {
|
|
20
|
+
label: 'Serif',
|
|
21
|
+
sans: 'Libre Baskerville',
|
|
22
|
+
mono: 'JetBrains Mono',
|
|
23
|
+
feel: 'Classic serif, literary',
|
|
24
|
+
googleFontsQuery: 'Libre+Baskerville:wght@400;700&family=JetBrains+Mono:wght@400;500'
|
|
25
|
+
},
|
|
26
|
+
mono: {
|
|
27
|
+
label: 'Mono',
|
|
28
|
+
sans: 'JetBrains Mono',
|
|
29
|
+
mono: 'JetBrains Mono',
|
|
30
|
+
feel: 'Full terminal, hacker',
|
|
31
|
+
googleFontsQuery: 'JetBrains+Mono:wght@400;500;600'
|
|
32
|
+
},
|
|
33
|
+
bubbly: {
|
|
34
|
+
label: 'Bubbly',
|
|
35
|
+
sans: 'Fredoka',
|
|
36
|
+
mono: 'Azeret Mono',
|
|
37
|
+
feel: 'Very round, toy-like',
|
|
38
|
+
googleFontsQuery: 'Fredoka:wght@400;500;600&family=Azeret+Mono:wght@400;500'
|
|
39
|
+
},
|
|
40
|
+
geometric: {
|
|
41
|
+
label: 'Geometric',
|
|
42
|
+
sans: 'Outfit',
|
|
43
|
+
mono: 'DM Mono',
|
|
44
|
+
feel: 'Swiss design, neutral',
|
|
45
|
+
googleFontsQuery: 'Outfit:wght@400;500;600&family=DM+Mono:wght@400;500'
|
|
46
|
+
},
|
|
47
|
+
retro: {
|
|
48
|
+
label: 'Retro',
|
|
49
|
+
sans: 'Courier Prime',
|
|
50
|
+
mono: 'Courier Prime',
|
|
51
|
+
feel: 'Typewriter nostalgia',
|
|
52
|
+
googleFontsQuery: 'Courier+Prime:wght@400;700'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type ColorTheme = 'default' | 'paper' | 'sand' | 'rose' | 'lavender' | 'mint' | 'sky'
|
|
57
|
+
|
|
58
|
+
export type ColorThemeConfig = {
|
|
59
|
+
label: string
|
|
60
|
+
// undefined background/foreground = no override, reveals :root defaults
|
|
61
|
+
background?: string
|
|
62
|
+
foreground?: string
|
|
63
|
+
feel: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const COLOR_THEMES: Record<ColorTheme, ColorThemeConfig> = {
|
|
67
|
+
default: { label: 'Default', feel: 'System neutral' },
|
|
68
|
+
paper: {
|
|
69
|
+
label: 'Paper',
|
|
70
|
+
background: '#faf8f5',
|
|
71
|
+
foreground: '#2c2825',
|
|
72
|
+
feel: 'Warm off-white'
|
|
73
|
+
},
|
|
74
|
+
sand: {
|
|
75
|
+
label: 'Sand',
|
|
76
|
+
background: '#f5f0e8',
|
|
77
|
+
foreground: '#3d3529',
|
|
78
|
+
feel: 'Beige earth tones'
|
|
79
|
+
},
|
|
80
|
+
rose: { label: 'Rose', background: '#fdf2f4', foreground: '#3b1c26', feel: 'Soft blush' },
|
|
81
|
+
lavender: {
|
|
82
|
+
label: 'Lavender',
|
|
83
|
+
background: '#f4f2fb',
|
|
84
|
+
foreground: '#2b2640',
|
|
85
|
+
feel: 'Cool violet'
|
|
86
|
+
},
|
|
87
|
+
mint: { label: 'Mint', background: '#f0faf6', foreground: '#1a3028', feel: 'Cool green' },
|
|
88
|
+
sky: { label: 'Sky', background: '#f0f6fc', foreground: '#1a2a3b', feel: 'Cool blue' }
|
|
89
|
+
}
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { StreamEvent } from './format'
|
|
2
|
+
|
|
3
|
+
export type WidgetConfig = {
|
|
4
|
+
rowSpan: 1 | 2 | 3 | 4
|
|
5
|
+
colSpan: 1 | 2 | 3 | 4
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type WidgetInfo = {
|
|
9
|
+
id: string
|
|
10
|
+
config: WidgetConfig
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Client → Server messages
|
|
14
|
+
export type ClientMessage =
|
|
15
|
+
| {
|
|
16
|
+
type: 'chat'
|
|
17
|
+
content: string
|
|
18
|
+
sessionId: string
|
|
19
|
+
isNew: boolean
|
|
20
|
+
// Client-chosen stable id for the user's turn. The server tells the
|
|
21
|
+
// adapter to use this id when the SDK echoes the user input back, so
|
|
22
|
+
// the optimistic bubble the client rendered gets upserted in place.
|
|
23
|
+
optimisticId?: string
|
|
24
|
+
}
|
|
25
|
+
| { type: 'stop'; sessionId: string }
|
|
26
|
+
|
|
27
|
+
// Session info returned by list endpoint
|
|
28
|
+
export type SessionInfo = {
|
|
29
|
+
sessionId: string
|
|
30
|
+
summary: string
|
|
31
|
+
lastModified: number
|
|
32
|
+
cwd?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Re-export the display format
|
|
36
|
+
export type {
|
|
37
|
+
Citation,
|
|
38
|
+
Part,
|
|
39
|
+
ResultSummary,
|
|
40
|
+
SessionSnapshot,
|
|
41
|
+
StreamEvent,
|
|
42
|
+
SubagentRecord,
|
|
43
|
+
SubagentStatus,
|
|
44
|
+
SystemNotice,
|
|
45
|
+
ToolCall,
|
|
46
|
+
ToolCaller,
|
|
47
|
+
ToolState,
|
|
48
|
+
Turn,
|
|
49
|
+
TurnMeta,
|
|
50
|
+
TurnOrigin,
|
|
51
|
+
ViewState
|
|
52
|
+
} from './format'
|
|
53
|
+
|
|
54
|
+
// Server → Client messages.
|
|
55
|
+
// Every conversation-related frame carries a sessionId so the client can
|
|
56
|
+
// route it to the correct session.
|
|
57
|
+
export type ServerMessage =
|
|
58
|
+
| (StreamEvent & { sessionId: string })
|
|
59
|
+
| StatusMessage
|
|
60
|
+
| SessionRenamedMessage
|
|
61
|
+
| WorkspaceSwitchMessage
|
|
62
|
+
| ErrorFrame
|
|
63
|
+
| StoppedFrame
|
|
64
|
+
|
|
65
|
+
export type WorkspaceSwitchMessage = {
|
|
66
|
+
type: 'workspace:switch'
|
|
67
|
+
workspaceId: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type WorkspaceType = 'claude-code' | 'openclaw' | 'hermes'
|
|
71
|
+
|
|
72
|
+
export type WorkspaceEntry = {
|
|
73
|
+
id: string
|
|
74
|
+
path: string
|
|
75
|
+
addedAt: string
|
|
76
|
+
type?: WorkspaceType
|
|
77
|
+
// Display name captured at add time (e.g. OpenClaw IDENTITY.md "Name:" or
|
|
78
|
+
// basename). Persisted so we don't re-probe the gateway for each listing.
|
|
79
|
+
name?: string
|
|
80
|
+
// Home-relative rendering of `path` (e.g. "~/.openclaw/workspace"). Set by
|
|
81
|
+
// the server on the wire — clients render it as-is.
|
|
82
|
+
displayPath?: string
|
|
83
|
+
// OpenClaw-specific metadata captured at add time. "lastRunAt" is a snapshot,
|
|
84
|
+
// not live — refresh on demand if it ever needs to stay accurate.
|
|
85
|
+
agentId?: string
|
|
86
|
+
isDefault?: boolean
|
|
87
|
+
lastRunAt?: string
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type DiscoveredWorkspace = {
|
|
91
|
+
path: string
|
|
92
|
+
type: WorkspaceType
|
|
93
|
+
name?: string
|
|
94
|
+
displayPath?: string
|
|
95
|
+
agentId?: string
|
|
96
|
+
isDefault?: boolean
|
|
97
|
+
lastRunAt?: string
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export type SessionRenamedMessage = {
|
|
101
|
+
type: 'session_renamed'
|
|
102
|
+
from: string
|
|
103
|
+
to: string
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type ErrorFrame = {
|
|
107
|
+
kind: 'error'
|
|
108
|
+
sessionId: string
|
|
109
|
+
content: string
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type StoppedFrame = {
|
|
113
|
+
kind: 'stopped'
|
|
114
|
+
sessionId: string
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export type StatusMessage = {
|
|
118
|
+
type: 'status'
|
|
119
|
+
sessionId: string
|
|
120
|
+
processing: boolean
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Workspace layout persistence
|
|
124
|
+
export type LayoutGridItem = { i: string; x: number; y: number }
|
|
125
|
+
|
|
126
|
+
export type ChatMode = 'sidebar' | 'floating'
|
|
127
|
+
|
|
128
|
+
export type { FontTheme, ColorTheme } from './themes'
|
|
129
|
+
|
|
130
|
+
export type WorkspaceLayout = {
|
|
131
|
+
version: 1
|
|
132
|
+
widgetGrid: LayoutGridItem[]
|
|
133
|
+
chatMode: ChatMode
|
|
134
|
+
theme?: {
|
|
135
|
+
font: import('./themes').FontTheme
|
|
136
|
+
background?: string
|
|
137
|
+
foreground?: string
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export type WorkspacePreview = {
|
|
142
|
+
cols: number
|
|
143
|
+
items: { x: number; y: number; w: number; h: number }[]
|
|
144
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "moi-computer",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
|
|
5
|
+
"license": "Elastic-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"homepage": "https://github.com/molefrog/moi#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/molefrog/moi.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/molefrog/moi/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ai",
|
|
17
|
+
"agent",
|
|
18
|
+
"claude",
|
|
19
|
+
"claude-agent-sdk",
|
|
20
|
+
"bun",
|
|
21
|
+
"workspace",
|
|
22
|
+
"cli"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"bun": ">=1.3"
|
|
26
|
+
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"moi": "./bin/moi.mjs"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"bin",
|
|
32
|
+
"server",
|
|
33
|
+
"client",
|
|
34
|
+
"lib",
|
|
35
|
+
"workspace",
|
|
36
|
+
"bunfig.toml",
|
|
37
|
+
"tsconfig.json",
|
|
38
|
+
"!**/*.test.ts",
|
|
39
|
+
"!**/*.test.tsx",
|
|
40
|
+
"!server/test",
|
|
41
|
+
"!workspace/.env",
|
|
42
|
+
"!workspace/.claude/settings.local.json",
|
|
43
|
+
"!workspace/.widgets"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"dev": "bun server/cli.ts start --dev",
|
|
47
|
+
"lint": "eslint .",
|
|
48
|
+
"lint:fix": "eslint --fix .",
|
|
49
|
+
"format": "prettier --write .",
|
|
50
|
+
"format:check": "prettier --check .",
|
|
51
|
+
"prepare": "husky"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@anthropic-ai/claude-agent-sdk": "^0.2.90",
|
|
55
|
+
"@base-ui/react": "^1.2.0",
|
|
56
|
+
"@dnd-kit/core": "^6.3.1",
|
|
57
|
+
"@tabler/icons-react": "^3.40.0",
|
|
58
|
+
"@tailwindcss/typography": "^0.5.19",
|
|
59
|
+
"@tanstack/react-query": "^5.100.1",
|
|
60
|
+
"agentation": "^2.3.3",
|
|
61
|
+
"bun-plugin-tailwind": "^0.1.2",
|
|
62
|
+
"citty": "^0.2.1",
|
|
63
|
+
"class-variance-authority": "^0.7.1",
|
|
64
|
+
"cli-table3": "^0.6.5",
|
|
65
|
+
"clsx": "^2.1.1",
|
|
66
|
+
"devalue": "^5.6.4",
|
|
67
|
+
"env-paths": "^4.0.0",
|
|
68
|
+
"highlight.js": "^10.7.3",
|
|
69
|
+
"lru-cache": "^11.3.5",
|
|
70
|
+
"motion": "^12.35.1",
|
|
71
|
+
"pathe": "^2.0.3",
|
|
72
|
+
"picocolors": "^1.1.1",
|
|
73
|
+
"react": "^19",
|
|
74
|
+
"react-dom": "^19",
|
|
75
|
+
"react-grid-layout": "^2.2.3",
|
|
76
|
+
"react-markdown": "^10.1.0",
|
|
77
|
+
"react-resizable": "^3.1.3",
|
|
78
|
+
"rehype-highlight": "^7.0.2",
|
|
79
|
+
"remark-gfm": "^4.0.1",
|
|
80
|
+
"shadcn": "^4.0.2",
|
|
81
|
+
"tailwind-merge": "^3.5.0",
|
|
82
|
+
"tailwindcss": "^4.1.11",
|
|
83
|
+
"tw-animate-css": "^1.4.0",
|
|
84
|
+
"wouter": "^3.9.0",
|
|
85
|
+
"zustand": "^5.0.12"
|
|
86
|
+
},
|
|
87
|
+
"optionalDependencies": {
|
|
88
|
+
"openclaw": "2026.4.22"
|
|
89
|
+
},
|
|
90
|
+
"lint-staged": {
|
|
91
|
+
"*.{js,jsx,ts,tsx}": [
|
|
92
|
+
"eslint --fix",
|
|
93
|
+
"prettier --write"
|
|
94
|
+
],
|
|
95
|
+
"*.{css,json,yml,yaml}": [
|
|
96
|
+
"prettier --write"
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
"devDependencies": {
|
|
100
|
+
"@eslint/js": "^9.22.0",
|
|
101
|
+
"@trivago/prettier-plugin-sort-imports": "^5.2.2",
|
|
102
|
+
"@types/bun": "latest",
|
|
103
|
+
"@types/react": "^19",
|
|
104
|
+
"@types/react-dom": "^19",
|
|
105
|
+
"@types/react-grid-layout": "^2.1.0",
|
|
106
|
+
"@typescript-eslint/typescript-estree": "^8.57.2",
|
|
107
|
+
"eslint": "^9.22.0",
|
|
108
|
+
"eslint-config-prettier": "^10.1.1",
|
|
109
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
110
|
+
"globals": "^16.0.0",
|
|
111
|
+
"husky": "^9.1.7",
|
|
112
|
+
"lint-staged": "^16.4.0",
|
|
113
|
+
"prettier": "^3.5.3",
|
|
114
|
+
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
115
|
+
"typescript-eslint": "^8.26.1"
|
|
116
|
+
}
|
|
117
|
+
}
|
package/server/CLAUDE.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Bun server on port 3000. Serves the client at `/`, upgrades `/ws` to WebSocket.
|
|
2
|
+
|
|
3
|
+
- `state.ts` holds global mutable state (messages, session, connected clients). `record()` appends, persists, and broadcasts.
|
|
4
|
+
- `agent.ts` sends prompts to Claude via `query()` from the agent SDK. Streams responses back as typed messages. Sessions are resumable.
|
|
5
|
+
- WebSocket protocol: server sends `ServerMessage`, client sends `ClientMessage` — both defined in `lib/types.ts`.
|
|
6
|
+
- Agent runs in `workspace/` with bypass permissions. Chat history persisted to `workspace/messages.json`.
|
package/server/agent.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { type Options, query } from '@anthropic-ai/claude-agent-sdk'
|
|
2
|
+
import type { McpServerStatus } from '@anthropic-ai/claude-agent-sdk'
|
|
3
|
+
|
|
4
|
+
import { ClaudeAdapter } from '@/lib/claude-adapter'
|
|
5
|
+
|
|
6
|
+
import { broadcast, getAgent, renameAgent } from './state'
|
|
7
|
+
|
|
8
|
+
function getErrorMessage(error: unknown) {
|
|
9
|
+
if (error instanceof Error) return error.message
|
|
10
|
+
return 'Unknown error'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function handleChat(
|
|
14
|
+
content: string,
|
|
15
|
+
sessionId: string,
|
|
16
|
+
isNew: boolean,
|
|
17
|
+
workspaceId: string,
|
|
18
|
+
workspacePath: string,
|
|
19
|
+
optimisticId?: string
|
|
20
|
+
) {
|
|
21
|
+
const agent = getAgent(sessionId)
|
|
22
|
+
|
|
23
|
+
if (agent.processing) {
|
|
24
|
+
broadcast(workspaceId, {
|
|
25
|
+
kind: 'error',
|
|
26
|
+
sessionId,
|
|
27
|
+
content: 'Already processing a message'
|
|
28
|
+
})
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const ctrl = new AbortController()
|
|
33
|
+
agent.processing = true
|
|
34
|
+
agent.abortController = ctrl
|
|
35
|
+
broadcast(workspaceId, { type: 'status', sessionId, processing: true })
|
|
36
|
+
|
|
37
|
+
let currentId = sessionId
|
|
38
|
+
const adapter = new ClaudeAdapter()
|
|
39
|
+
if (optimisticId) adapter.expectUserEcho(optimisticId, content)
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const options: Options = {
|
|
43
|
+
abortController: ctrl,
|
|
44
|
+
maxTurns: 50,
|
|
45
|
+
cwd: workspacePath,
|
|
46
|
+
model: 'sonnet',
|
|
47
|
+
allowedTools: [
|
|
48
|
+
'Bash',
|
|
49
|
+
'Read',
|
|
50
|
+
'Write',
|
|
51
|
+
'Edit',
|
|
52
|
+
'MultiEdit',
|
|
53
|
+
'Glob',
|
|
54
|
+
'Grep',
|
|
55
|
+
'WebSearch',
|
|
56
|
+
'WebFetch'
|
|
57
|
+
],
|
|
58
|
+
permissionMode: 'bypassPermissions',
|
|
59
|
+
allowDangerouslySkipPermissions: true,
|
|
60
|
+
settingSources: ['user', 'project'],
|
|
61
|
+
env: { ...process.env, CLAUDECODE: undefined },
|
|
62
|
+
stderr: (data: string) => console.error('[SDK stderr]', data)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!isNew) options.resume = sessionId
|
|
66
|
+
|
|
67
|
+
const q = query({ prompt: content, options })
|
|
68
|
+
|
|
69
|
+
for await (const msg of q) {
|
|
70
|
+
if (msg.type === 'system' && msg.subtype === 'init') {
|
|
71
|
+
const realId = msg.session_id
|
|
72
|
+
if (isNew && realId !== currentId) {
|
|
73
|
+
renameAgent(currentId, realId)
|
|
74
|
+
broadcast(workspaceId, { type: 'session_renamed', from: currentId, to: realId })
|
|
75
|
+
currentId = realId
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (const ev of adapter.ingest(msg)) {
|
|
80
|
+
broadcast(workspaceId, { ...ev, sessionId: currentId })
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (err: unknown) {
|
|
84
|
+
if (!(err instanceof Error && err.name === 'AbortError')) {
|
|
85
|
+
broadcast(workspaceId, {
|
|
86
|
+
kind: 'error',
|
|
87
|
+
sessionId: currentId,
|
|
88
|
+
content: getErrorMessage(err)
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
} finally {
|
|
92
|
+
const finalAgent = getAgent(currentId)
|
|
93
|
+
finalAgent.processing = false
|
|
94
|
+
finalAgent.abortController = null
|
|
95
|
+
broadcast(workspaceId, { type: 'status', sessionId: currentId, processing: false })
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function stopChat(sessionId: string, workspaceId: string) {
|
|
100
|
+
const agent = getAgent(sessionId)
|
|
101
|
+
if (agent.abortController) {
|
|
102
|
+
agent.abortController.abort()
|
|
103
|
+
broadcast(workspaceId, { kind: 'stopped', sessionId })
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Per-workspace MCP cache
|
|
108
|
+
const mcpCache = new Map<string, McpServerStatus[]>()
|
|
109
|
+
|
|
110
|
+
async function fetchMcpStatus(workspacePath: string): Promise<McpServerStatus[]> {
|
|
111
|
+
const q = query({
|
|
112
|
+
prompt: '',
|
|
113
|
+
options: {
|
|
114
|
+
cwd: workspacePath,
|
|
115
|
+
persistSession: false,
|
|
116
|
+
settingSources: ['user', 'project'],
|
|
117
|
+
env: { ...process.env, CLAUDECODE: undefined }
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
const status = await q.mcpServerStatus()
|
|
121
|
+
await q.close()
|
|
122
|
+
console.log('[mcp]', status.map(s => `${s.name}:${s.status}`).join(', '))
|
|
123
|
+
return status
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function getMcpStatus(workspacePath: string): Promise<McpServerStatus[]> {
|
|
127
|
+
const cached = mcpCache.get(workspacePath)
|
|
128
|
+
if (cached) return cached
|
|
129
|
+
const status = await fetchMcpStatus(workspacePath)
|
|
130
|
+
mcpCache.set(workspacePath, status)
|
|
131
|
+
return status
|
|
132
|
+
}
|