moi-computer 0.12.0 → 0.12.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 +1 -1
- package/client/AGENTS.md +2 -2
- package/client/api/app-ui-keys.ts +1 -1
- package/client/api/workspace-keys.ts +1 -3
- package/client/app/routes/WorkspaceRoute.tsx +2 -8
- package/client/features/applets/applet-runtime.ts +11 -13
- package/client/features/chat/ChatPanel.tsx +70 -49
- package/client/features/chat/ChatPopup.tsx +81 -8
- package/client/features/chat/applet-chat-intents.ts +31 -12
- package/client/features/chat/chat-send.ts +33 -1
- package/client/features/chat/chat-store.ts +10 -0
- package/client/features/chat/composer/ChatComposer.tsx +24 -27
- package/client/features/chat/composer/ModelPicker.tsx +3 -3
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
- package/client/features/chat/connection/chat-frames.ts +14 -7
- package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
- package/client/features/chat/messages/MarkdownContent.tsx +3 -3
- package/client/features/chat/messages/fork-history.ts +14 -0
- package/client/features/chat/sessions/ChatSelector.tsx +138 -79
- package/client/features/chat/sessions/api.ts +109 -19
- package/client/features/chat/sessions/browser-tab-state.ts +30 -7
- package/client/features/chat/sessions/useSelectedSession.ts +217 -51
- package/client/features/chat/useChat.ts +43 -45
- package/client/features/collab/client.ts +10 -11
- package/client/features/collab/hooks.tsx +6 -11
- package/client/features/collab/host-state.ts +57 -128
- package/client/features/collab/provider.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +6 -27
- package/client/features/collab/workspace-users-menu.tsx +3 -7
- package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
- package/client/features/home/HomePage.tsx +2 -2
- package/client/features/overview/Overview.tsx +3 -6
- package/client/features/overview/default/ViewsWidget.tsx +5 -12
- package/client/features/overview/default/registry.tsx +2 -4
- package/client/features/views/PendingViewScreen.tsx +279 -0
- package/client/features/views/ViewManager.tsx +10 -10
- package/client/features/views/api.ts +63 -130
- package/client/features/views/useViewActions.ts +151 -0
- package/client/features/views/useViewDrafts.ts +79 -0
- package/client/features/views/view-presentation.ts +4 -5
- package/client/features/views/view-submission.ts +88 -0
- package/client/features/workspace/WorkspaceMenu.tsx +63 -0
- package/client/features/workspace/WorkspaceScreen.tsx +180 -375
- package/client/features/workspace/browser-tab-state.ts +16 -9
- package/client/features/workspace/moi-context.ts +13 -15
- package/client/features/workspace/tab-resolution.ts +16 -29
- package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
- package/client/index.tsx +5 -1
- package/client/runtime/useWorkspaceEvents.ts +7 -6
- package/client/store/ui.ts +25 -29
- package/dist/chunk-1zhnhy00.js +1 -0
- package/dist/chunk-27501vke.js +1 -0
- package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
- package/dist/chunk-am1x230f.js +2 -0
- package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
- package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
- package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
- package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
- package/dist/chunk-n33w9y38.js +10 -0
- package/dist/chunk-r63ks44z.js +68 -0
- package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
- package/dist/chunk-wd46nk26.css +1 -0
- package/dist/chunk-xgt7vxt9.js +1 -0
- package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
- package/dist/index.html +1 -1
- package/lib/ids.ts +2 -5
- package/lib/moi-context.ts +100 -73
- package/lib/navigation.ts +48 -87
- package/lib/session-drafts.ts +10 -0
- package/lib/types.ts +64 -31
- package/lib/view-build-directives.ts +12 -0
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-tabs.ts +12 -7
- package/package.json +3 -1
- package/server/agent-launcher.ts +27 -0
- package/server/api.ts +119 -209
- package/server/app-config.ts +21 -2
- package/server/applets/build-worker.ts +2 -1
- package/server/applets/view-source.ts +7 -1
- package/server/cli-env.ts +72 -50
- package/server/cli.ts +101 -64
- package/server/control.ts +82 -63
- package/server/data-dir.ts +13 -0
- package/server/functions.ts +2 -1
- package/server/harness/README.md +8 -0
- package/server/harness/acp/adapter.ts +2 -2
- package/server/harness/acp/client.ts +2 -1
- package/server/harness/acp/discovery.ts +3 -3
- package/server/harness/acp/session.ts +6 -9
- package/server/harness/claude-code/adapter.ts +13 -8
- package/server/harness/claude-code/auth.ts +3 -2
- package/server/harness/claude-code/cli.ts +3 -1
- package/server/harness/claude-code/git-worktree.ts +5 -2
- package/server/harness/claude-code/index.ts +5 -0
- package/server/harness/claude-code/mcp.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -0
- package/server/harness/claude-code/session.ts +5 -34
- package/server/harness/claude-code/sessions.ts +8 -12
- package/server/harness/codex/NOTES.md +23 -4
- package/server/harness/codex/adapter.ts +5 -3
- package/server/harness/codex/client.ts +13 -21
- package/server/harness/codex/index.ts +18 -0
- package/server/harness/codex/session.ts +6 -14
- package/server/harness/codex/thread-list.ts +74 -0
- package/server/harness/fork.ts +12 -0
- package/server/harness/openclaw/adapter.ts +3 -3
- package/server/harness/openclaw/session.ts +2 -30
- package/server/harness/session-title.ts +12 -3
- package/server/harness/types.ts +8 -3
- package/server/moi-scaffold.ts +2 -1
- package/server/pending-views.ts +164 -0
- package/server/registry.ts +14 -4
- package/server/selected-session.ts +91 -44
- package/server/service.ts +16 -2
- package/server/session-archive.ts +32 -0
- package/server/session-config.ts +16 -111
- package/server/session-lifecycle.ts +17 -0
- package/server/session-store.ts +127 -0
- package/server/status.ts +3 -1
- package/server/tabs.ts +7 -10
- package/server/view-sessions.ts +267 -0
- package/server/views.ts +30 -41
- package/server/web.ts +47 -45
- package/server/workspace-env.ts +27 -0
- package/server/workspace-init.ts +6 -2
- package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
- package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
- package/client/features/views/ViewBuilder.tsx +0 -239
- package/client/features/views/useViewBuilderActions.ts +0 -103
- package/client/features/views/useViewBuilderDrafts.ts +0 -68
- package/dist/chunk-2jncyq65.js +0 -1
- package/dist/chunk-e2q5ken7.js +0 -68
- package/dist/chunk-h2kj1ysj.js +0 -1
- package/dist/chunk-nzwgm8vc.css +0 -1
- package/dist/chunk-ph0h6h86.js +0 -1
- package/dist/chunk-ryg9z3kn.js +0 -10
- package/dist/chunk-tpn177bt.js +0 -2
- package/lib/view-builder-directives.ts +0 -16
- package/server/chat-selection.ts +0 -22
- package/server/view-builders.ts +0 -453
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"/chunk-pcnahct1.js";import"/chunk-gps4qc38.js";export{a as sanitizeSvg};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{U as
|
|
1
|
+
import{Yc as J,Zc as Z}from"/chunk-gps4qc38.js";var U=Z((O,G)=>{G.exports=globalThis.__esm.react});var B=J(U(),1);var $=J(U(),1);function K(m){let h=$.useRef(m);return $.useLayoutEffect(()=>{h.current=m},[m]),h}function Q(m){return`${location.protocol==="https:"?"wss":"ws"}://${location.host}${m}`}var y=new Set,j=new Set,S=!1,T=null,u=!1,q=1000,X=30000,z=0;function D(){let m=Math.min(q*2**z,X);z++,setTimeout(V,m)}function V(){if(T||u)return;u=!0;let m=new WebSocket(Q("/api/workspaces/ws"));m.onopen=()=>{if(T=m,u=!1,z=0,b(),S)for(let h of j)h();S=!0},m.onmessage=(h)=>{try{let x=JSON.parse(h.data);for(let f of y)f(x)}catch{}},m.onclose=()=>{if(T=null,u=!1,y.size>0)D()},m.onerror=()=>{m.close()}}function _(m){return j.add(m),()=>{j.delete(m)}}function L(m){let h=K(m);B.useEffect(()=>{let x=(f)=>h.current(f);return y.add(x),V(),()=>{if(y.delete(x),y.size===0&&T)T.close(),T=null}},[h])}var H=null;function b(){if(T?.readyState!==WebSocket.OPEN)return;T.send(JSON.stringify({type:"navigation:presence",workspaceId:H,focused:document.visibilityState==="visible"&&document.hasFocus()}))}function g(m,h){B.useEffect(()=>{return H=m,b(),window.addEventListener("focus",b),document.addEventListener("visibilitychange",b),()=>{H=null,b(),window.removeEventListener("focus",b),document.removeEventListener("visibilitychange",b)}},[m]),L(async(x)=>{if(x.type!=="navigation:request"||x.workspaceId!==m)return;let f=T;try{if(H!==m)throw Error("The browser switched workspaces.");await h(x.href),f?.send(JSON.stringify({type:"navigation:result",requestId:x.requestId,ok:!0}))}catch(F){f?.send(JSON.stringify({type:"navigation:result",requestId:x.requestId,error:F instanceof Error?F.message:"Navigation failed"}))}})}
|
|
2
|
+
export{U as Sc,Q as Tc,K as Uc,_ as Vc,L as Wc,g as Xc};
|
package/dist/index.html
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
}
|
|
37
37
|
</script>
|
|
38
38
|
|
|
39
|
-
<link rel="stylesheet" crossorigin href="/chunk-
|
|
39
|
+
<link rel="stylesheet" crossorigin href="/chunk-wd46nk26.css"><script type="module" crossorigin src="/chunk-27501vke.js"></script></head>
|
|
40
40
|
<body>
|
|
41
41
|
<div id="root"></div>
|
|
42
42
|
|
package/lib/ids.ts
CHANGED
|
@@ -35,8 +35,5 @@ export function validateWorkspaceId(id: string): string | null {
|
|
|
35
35
|
return null
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
// builders — so 6 chars (~31 bits) keeps the command short while staying
|
|
41
|
-
// collision-free at that scale.
|
|
42
|
-
export const newBuilderId = customAlphabet(ALPHABET, 6)
|
|
38
|
+
// A view keeps this ID from its pending tab through its compiled file.
|
|
39
|
+
export const newViewId = customAlphabet(ALPHABET, 6)
|
package/lib/moi-context.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
//
|
|
8
8
|
// Flow: a structured `MoiContext` is assembled at send time — by the client
|
|
9
9
|
// for chat sends (client/features/workspace/moi-context.ts, sent as the chat
|
|
10
|
-
// frame's `context`), by the server for view
|
|
11
|
-
// the optional collab reference
|
|
12
|
-
// the transform matching its conventions:
|
|
10
|
+
// frame's `context`), by the server for pending-view requests. The server adds
|
|
11
|
+
// the session snapshot and optional collab reference before the harness renders
|
|
12
|
+
// the context with the transform matching its conventions:
|
|
13
13
|
// - Claude Code — `moiContextSystemReminder` as its own leading text block
|
|
14
14
|
// (mirrors how Claude Code itself injects ambient context; a string
|
|
15
15
|
// prefix would defeat the SDK's first-prompt extraction, which skips
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
// - OpenClaw — `appendMoiContext` after the user's text
|
|
21
21
|
// Display paths strip with `stripMoiContext` so the envelope never surfaces
|
|
22
22
|
// in a bubble, live or replayed from a transcript.
|
|
23
|
-
import type { WorkspaceTabId } from './types'
|
|
23
|
+
import type { AppletKind, WorkspaceTabId } from './types'
|
|
24
24
|
import { isParamsRecord } from './workspace-tabs'
|
|
25
25
|
|
|
26
26
|
const MOI_CONTEXT_OPEN = '<moi-context>'
|
|
@@ -34,36 +34,40 @@ const SYSTEM_REMINDER_OPEN = '<system-reminder>'
|
|
|
34
34
|
const SYSTEM_REMINDER_CLOSE = '</system-reminder>'
|
|
35
35
|
|
|
36
36
|
// A chat message fired from applet UI (`sendChatMessage`) rather than typed.
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
// Identity is stamped host-side from the bridge the applet was attached with.
|
|
38
|
+
export type AppletContext = {
|
|
39
|
+
kind: AppletKind
|
|
40
|
+
id: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type SessionContext = {
|
|
44
|
+
id: string
|
|
45
|
+
tabId?: WorkspaceTabId
|
|
46
|
+
pinned: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type TabContext = {
|
|
50
|
+
id: WorkspaceTabId
|
|
51
|
+
title?: string
|
|
52
|
+
// URL parameters of the currently visible view, when present.
|
|
53
|
+
params?: Record<string, unknown>
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
// The structured form built at send time — by the client for chat sends, by
|
|
45
|
-
// the server for programmatic
|
|
57
|
+
// the server for programmatic pending-view sends. Extend this (and
|
|
46
58
|
// `renderMoiContext`) when new ambient fields land.
|
|
47
59
|
export type MoiContext = {
|
|
48
60
|
// Server-resolved path to the installed COLLAB.md reference for this workspace.
|
|
49
61
|
collabReference?: string
|
|
50
|
-
// The workspace tab the user is on when they hit send
|
|
51
|
-
//
|
|
52
|
-
activeTab
|
|
53
|
-
// UI label of the active tab when it differs from the id — a view's
|
|
54
|
-
// configured title (e.g. "Grading review" for `views/color-studio`), or a
|
|
55
|
-
// view builder's claimed title while the build runs. The tab bar falls
|
|
56
|
-
// back to the id when unset; so does the envelope.
|
|
57
|
-
tabTitle?: string
|
|
58
|
-
// The params the active view is rendering with right now, straight from
|
|
59
|
-
// URL query strings. The emitter side of the same contract (`navigate`) sets
|
|
60
|
-
// them, so the agent sees a view's addressable state in both directions.
|
|
61
|
-
// Absent for tabs that take no params (overview, scratchpad, agent).
|
|
62
|
-
tabParams?: Record<string, unknown>
|
|
62
|
+
// The workspace tab the user is on when they hit send.
|
|
63
|
+
// Omitted for programmatic sends when the visible tab is unknown.
|
|
64
|
+
activeTab?: TabContext
|
|
63
65
|
// Set when this message came from applet UI instead of the composer.
|
|
64
|
-
applet?:
|
|
65
|
-
//
|
|
66
|
-
|
|
66
|
+
applet?: AppletContext
|
|
67
|
+
// Added by the server before sending to the harness.
|
|
68
|
+
session?: SessionContext
|
|
69
|
+
// One-shot imperative lines for this message only (e.g. pending-view build
|
|
70
|
+
// instructions from lib/view-build-directives.ts).
|
|
67
71
|
directives?: string[]
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -98,44 +102,27 @@ function renderTabParams(value: Record<string, unknown>): string | null {
|
|
|
98
102
|
return escapeTags(capped)
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (source.startsWith('widget:')) {
|
|
106
|
-
const name = escapeTags(source.slice('widget:'.length))
|
|
107
|
-
return `"${name}" widget (.moi/widgets/${name}.tsx)`
|
|
108
|
-
}
|
|
109
|
-
if (source.startsWith('view:')) {
|
|
110
|
-
const name = escapeTags(source.slice('view:'.length))
|
|
111
|
-
return `"${name}" view (.moi/views/${name}.tsx)`
|
|
112
|
-
}
|
|
113
|
-
return `"${escapeTags(source)}" applet`
|
|
105
|
+
function describeApplet(applet: AppletContext): string {
|
|
106
|
+
const id = escapeTags(applet.id)
|
|
107
|
+
const directory = applet.kind === 'view' ? 'views' : 'widgets'
|
|
108
|
+
return `The "${id}" ${applet.kind} (.moi/${directory}/${id}.tsx)`
|
|
114
109
|
}
|
|
115
110
|
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
// set` needs). A view tab also names its backing file: the user speaks in
|
|
111
|
+
// Describe a tab using the labels the user sees in the tab bar. A view
|
|
112
|
+
// tab also names its backing file: the user speaks in
|
|
119
113
|
// titles ("fix the Grading review page") while the agent edits
|
|
120
114
|
// `.moi/views/<id>.tsx` — this line connects the two.
|
|
121
|
-
function describeTab(tab:
|
|
115
|
+
function describeTab(tab: Pick<TabContext, 'id' | 'title'>): string {
|
|
122
116
|
// Titles come from applet config, so they carry the same forgery risk as any
|
|
123
117
|
// other applet-authored string in here.
|
|
124
|
-
const title =
|
|
125
|
-
if (tab === '
|
|
126
|
-
if (tab === '
|
|
127
|
-
if (tab
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return title
|
|
131
|
-
? `The user is building a new view "${title}". Builder id "${id}".`
|
|
132
|
-
: `The user is building a new view. Builder id "${id}".`
|
|
118
|
+
const title = tab.title === undefined ? undefined : escapeTags(tab.title)
|
|
119
|
+
if (tab.id === 'overview') return 'the "Overview" tab'
|
|
120
|
+
if (tab.id === 'scratchpad') return 'the "Scratchpad" tab'
|
|
121
|
+
if (tab.id.startsWith('views/')) {
|
|
122
|
+
const id = escapeTags(tab.id.slice('views/'.length))
|
|
123
|
+
return `the "${title ?? id}" view tab (.moi/views/${id}.tsx)`
|
|
133
124
|
}
|
|
134
|
-
|
|
135
|
-
const id = tab.slice('views/'.length)
|
|
136
|
-
return `The user is on the "${title ?? id}" view tab (.moi/views/${id}.tsx).`
|
|
137
|
-
}
|
|
138
|
-
return `The user is on the "${tab}" tab.`
|
|
125
|
+
return `the "${escapeTags(tab.id)}" tab`
|
|
139
126
|
}
|
|
140
127
|
|
|
141
128
|
// Format (modeled on Claude Code's system-reminder context blocks): a short
|
|
@@ -149,25 +136,44 @@ export function renderMoiContextBody(ctx: MoiContext): string {
|
|
|
149
136
|
`${MOI_CONTEXT_MARKER} — a shared UI the user chats with you from, which you can extend and customize.`,
|
|
150
137
|
'Read the **`moi-workspace` skill** before responding — even to a simple question — unless you already read it in this chat.'
|
|
151
138
|
].join('\n')
|
|
152
|
-
const
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
139
|
+
const sections: string[] = []
|
|
140
|
+
const appletIsActiveView =
|
|
141
|
+
ctx.applet?.kind === 'view' && ctx.activeTab?.id === `views/${ctx.applet.id}`
|
|
142
|
+
if (ctx.activeTab) {
|
|
143
|
+
const tabLines = [`The user is on ${describeTab(ctx.activeTab)}.`]
|
|
144
|
+
if (appletIsActiveView) tabLines.push('This view sent the message above from its UI.')
|
|
145
|
+
const tabParams = ctx.activeTab.params ? renderTabParams(ctx.activeTab.params) : null
|
|
146
|
+
if (tabParams) tabLines.push(`Params it is rendering with right now: ${tabParams}`)
|
|
147
|
+
sections.push(`# Active tab\n${tabLines.join('\n')}`)
|
|
148
|
+
}
|
|
156
149
|
if (ctx.collabReference)
|
|
157
150
|
sections.push(
|
|
158
151
|
`# Collab\nThe collab runtime is available. Before writing collaborative applets, read ${escapeTags(ctx.collabReference)}.`
|
|
159
152
|
)
|
|
160
|
-
if (ctx.applet) {
|
|
153
|
+
if (ctx.applet && !appletIsActiveView) {
|
|
161
154
|
sections.push(
|
|
162
|
-
`# Applet message\
|
|
155
|
+
`# Applet message\n${describeApplet(ctx.applet)} sent the message above from its UI.`
|
|
163
156
|
)
|
|
164
157
|
}
|
|
158
|
+
if (ctx.session) {
|
|
159
|
+
const sessionLines = [`Session id: \`${escapeTags(ctx.session.id)}\``]
|
|
160
|
+
if (ctx.session.tabId) {
|
|
161
|
+
sessionLines.push(
|
|
162
|
+
ctx.session.tabId === ctx.activeTab?.id
|
|
163
|
+
? 'This chat belongs to the active tab.'
|
|
164
|
+
: `This chat belongs to ${describeTab({ id: ctx.session.tabId })}.`
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
sessionLines.push(`Pinned: ${ctx.session.pinned ? 'yes' : 'no'}.`)
|
|
168
|
+
sections.push(`# Session\n${sessionLines.join('\n')}`)
|
|
169
|
+
}
|
|
165
170
|
if (ctx.directives?.length) {
|
|
166
171
|
sections.push(`# This message only\n${ctx.directives.join('\n')}`)
|
|
167
172
|
}
|
|
168
173
|
const footer = [
|
|
169
174
|
'IMPORTANT: This context comes from moi, not from the user, and the user does not see it.',
|
|
170
|
-
'Only the newest
|
|
175
|
+
'Only the newest workspace and chat state is current. Do not respond to this block directly.',
|
|
176
|
+
'Keep build requests and unfinished work in task summaries and compaction; omit the ambient workspace and chat context.'
|
|
171
177
|
].join('\n')
|
|
172
178
|
return [preamble, ...sections, footer].join('\n\n')
|
|
173
179
|
}
|
|
@@ -178,29 +184,50 @@ export function renderMoiContext(ctx: MoiContext): string {
|
|
|
178
184
|
|
|
179
185
|
// Wire-shape guard for the chat frame's `context` field (see web.ts).
|
|
180
186
|
export function isMoiContext(value: unknown): value is MoiContext {
|
|
181
|
-
if (
|
|
187
|
+
if (!isParamsRecord(value)) return false
|
|
182
188
|
const v = value as {
|
|
183
189
|
collabReference?: unknown
|
|
184
190
|
activeTab?: unknown
|
|
185
|
-
tabTitle?: unknown
|
|
186
|
-
tabParams?: unknown
|
|
187
191
|
applet?: unknown
|
|
192
|
+
session?: unknown
|
|
188
193
|
directives?: unknown
|
|
189
194
|
}
|
|
190
195
|
return (
|
|
191
|
-
|
|
196
|
+
(v.activeTab === undefined || isTabContext(v.activeTab)) &&
|
|
192
197
|
(v.collabReference === undefined || typeof v.collabReference === 'string') &&
|
|
193
|
-
(v.
|
|
194
|
-
(v.
|
|
195
|
-
(v.applet === undefined || isMoiAppletMessage(v.applet)) &&
|
|
198
|
+
(v.applet === undefined || isAppletContext(v.applet)) &&
|
|
199
|
+
(v.session === undefined || isSessionContext(v.session)) &&
|
|
196
200
|
(v.directives === undefined ||
|
|
197
201
|
(Array.isArray(v.directives) && v.directives.every(d => typeof d === 'string')))
|
|
198
202
|
)
|
|
199
203
|
}
|
|
200
204
|
|
|
201
|
-
function
|
|
205
|
+
function isTabContext(value: unknown): value is TabContext {
|
|
206
|
+
if (!isParamsRecord(value)) return false
|
|
207
|
+
return (
|
|
208
|
+
typeof value.id === 'string' &&
|
|
209
|
+
(value.title === undefined || typeof value.title === 'string') &&
|
|
210
|
+
(value.params === undefined || isParamsRecord(value.params))
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function isAppletContext(value: unknown): value is AppletContext {
|
|
202
215
|
if (!isParamsRecord(value)) return false
|
|
203
|
-
return
|
|
216
|
+
return (
|
|
217
|
+
(value.kind === 'view' || value.kind === 'widget') &&
|
|
218
|
+
typeof value.id === 'string' &&
|
|
219
|
+
value.id.length > 0
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function isSessionContext(value: unknown): value is SessionContext {
|
|
224
|
+
if (!isParamsRecord(value)) return false
|
|
225
|
+
return (
|
|
226
|
+
typeof value.id === 'string' &&
|
|
227
|
+
value.id.length > 0 &&
|
|
228
|
+
(value.tabId === undefined || typeof value.tabId === 'string') &&
|
|
229
|
+
typeof value.pinned === 'boolean'
|
|
230
|
+
)
|
|
204
231
|
}
|
|
205
232
|
|
|
206
233
|
// Claude Code: the envelope rides as its OWN text block wrapped in
|
package/lib/navigation.ts
CHANGED
|
@@ -1,99 +1,60 @@
|
|
|
1
|
-
import type { WorkspaceTabId } from './types'
|
|
2
1
|
import { isWorkspaceTabId } from './workspace-tabs'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
export function parseMoiHref(href: unknown): WorkspaceAddress {
|
|
10
|
-
if (typeof href !== 'string' || !href.startsWith('moi:/') || href.startsWith('moi://')) {
|
|
11
|
-
throw new Error('Expected a workspace address such as moi:/views/events?eventId=123')
|
|
12
|
-
}
|
|
13
|
-
const path = href.slice(5).split(/[?#]/, 1)[0]
|
|
14
|
-
if (href.includes('#') || /[\s\\]/.test(path)) throw new Error('Invalid workspace address')
|
|
15
|
-
const tab = tabFromPath(path)
|
|
16
|
-
if (!tab || tab === 'agent' || tab.startsWith('view-builders/')) {
|
|
17
|
-
throw new Error(`Unsupported workspace destination: ${path}`)
|
|
18
|
-
}
|
|
19
|
-
const query = href.indexOf('?')
|
|
20
|
-
const search = query < 0 ? '' : canonicalSearch(href.slice(query + 1))
|
|
21
|
-
return { tab, search }
|
|
3
|
+
type ResolveUrlContext = {
|
|
4
|
+
workspaceId?: string
|
|
5
|
+
base?: string
|
|
6
|
+
// Applet bundles know their file endpoint before the host attaches a bridge.
|
|
7
|
+
apiBase?: string
|
|
22
8
|
}
|
|
23
9
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function tabFromPath(path: string): WorkspaceTabId | null {
|
|
38
|
-
try {
|
|
39
|
-
const tab = decodeURIComponent(path)
|
|
40
|
-
return isWorkspaceTabId(tab) ? tab : null
|
|
41
|
-
} catch {
|
|
42
|
-
return null
|
|
10
|
+
// Without a workspace, validates and normalizes a portable address (used by the CLI).
|
|
11
|
+
export function resolveUrl(
|
|
12
|
+
url: unknown,
|
|
13
|
+
{ workspaceId, base = '', apiBase }: ResolveUrlContext = {}
|
|
14
|
+
): string {
|
|
15
|
+
if (typeof url !== 'string') throw new Error('A URL is required')
|
|
16
|
+
if (!url.startsWith('moi:')) {
|
|
17
|
+
const resolved = new URL(url)
|
|
18
|
+
if (resolved.protocol !== 'https:' && resolved.protocol !== 'http:')
|
|
19
|
+
throw new Error('Unsupported URL')
|
|
20
|
+
return resolved.href
|
|
43
21
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Compatibility for old browser bookmarks only; saved tab state uses paths.
|
|
47
|
-
export function legacyTabFromPath(path: string): WorkspaceTabId | null {
|
|
48
|
-
const match = /^(view|view-builder):(.+)$/.exec(path)
|
|
49
|
-
return match ? tabFromPath(`${match[1]}s/${match[2]}`) : null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function moiHref(tab: WorkspaceTabId, search = ''): string {
|
|
53
|
-
return `moi:/${tab}${canonicalSearch(search)}`
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Deployment-specific addressing is confined to this host adapter. Callers
|
|
57
|
-
// may supply the router base; portable links never contain it.
|
|
58
|
-
export function workspacePath(workspaceId: string, base = ''): string {
|
|
59
|
-
return `${base.replace(/\/$/, '')}/workspace/${encodeURIComponent(workspaceId)}`
|
|
60
|
-
}
|
|
22
|
+
if (!url.startsWith('moi:/') || url.startsWith('moi://'))
|
|
23
|
+
throw new Error('Expected a workspace address such as moi:/views/events?eventId=123')
|
|
61
24
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
25
|
+
const tail = url.slice(5)
|
|
26
|
+
const suffixIndex = tail.search(/[?#]/)
|
|
27
|
+
const pathname = suffixIndex < 0 ? tail : tail.slice(0, suffixIndex)
|
|
28
|
+
const suffix = suffixIndex < 0 ? '' : tail.slice(suffixIndex)
|
|
29
|
+
const segments = pathname.split('/').map(decodeURIComponent)
|
|
30
|
+
if (
|
|
31
|
+
segments.some(
|
|
32
|
+
segment => !segment || segment === '.' || segment === '..' || /[/\\\0]/.test(segment)
|
|
33
|
+
)
|
|
34
|
+
)
|
|
35
|
+
throw new Error('Invalid workspace address')
|
|
65
36
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
37
|
+
const id = workspaceId === undefined ? undefined : encodeURIComponent(workspaceId)
|
|
38
|
+
if (segments[0] === 'files') {
|
|
39
|
+
if (segments.length < 2) throw new Error('Invalid workspace file path')
|
|
40
|
+
const prefix = apiBase ?? (id === undefined ? 'moi:' : `/api/workspaces/${id}`)
|
|
41
|
+
return `${prefix}/files/${segments.slice(1).map(encodeURIComponent).join('/')}${suffix}`
|
|
42
|
+
}
|
|
69
43
|
|
|
70
|
-
|
|
44
|
+
const path = segments.join('/')
|
|
45
|
+
if (url.includes('#') || /\s/.test(path)) throw new Error('Invalid workspace address')
|
|
46
|
+
if (
|
|
47
|
+
path !== 'chat' &&
|
|
48
|
+
!isWorkspaceTabId(path) &&
|
|
49
|
+
!(segments[0] === 'chats' && segments.length === 2)
|
|
50
|
+
)
|
|
51
|
+
throw new Error(`Unsupported workspace destination: ${path}`)
|
|
71
52
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const suffix = suffixIndex < 0 ? '' : tail.slice(suffixIndex)
|
|
78
|
-
const segments = pathname.split('/').map(segment => {
|
|
79
|
-
const decoded = decodeURIComponent(segment)
|
|
80
|
-
if (!decoded || decoded === '.' || decoded === '..' || /[/\\\0]/.test(decoded)) {
|
|
81
|
-
throw new Error('Invalid workspace file path')
|
|
82
|
-
}
|
|
83
|
-
return encodeURIComponent(decoded)
|
|
84
|
-
})
|
|
85
|
-
return `${context.apiBase}/files/${segments.join('/')}${suffix}`
|
|
86
|
-
}
|
|
87
|
-
if (url.startsWith('moi:')) {
|
|
88
|
-
const { tab, search } = parseMoiHref(url)
|
|
89
|
-
return context.workspacePath ? `${context.workspacePath}/${tab}${search}` : ''
|
|
90
|
-
}
|
|
91
|
-
// Only explicit ordinary web addresses may leave the workspace through the
|
|
92
|
-
// imperative API. Native anchors keep their existing protocol policy.
|
|
93
|
-
const resolved = new URL(url)
|
|
94
|
-
if (resolved.protocol !== 'https:' && resolved.protocol !== 'http:')
|
|
95
|
-
throw new Error('Unsupported URL')
|
|
96
|
-
return resolved.href
|
|
53
|
+
const params = new URLSearchParams(suffix)
|
|
54
|
+
params.sort()
|
|
55
|
+
const search = params.toString()
|
|
56
|
+
const prefix = id === undefined ? 'moi:' : `${base.replace(/\/$/, '')}/workspace/${id}`
|
|
57
|
+
return `${prefix}/${segments.map(encodeURIComponent).join('/')}${search ? `?${search}` : ''}`
|
|
97
58
|
}
|
|
98
59
|
|
|
99
60
|
export type NavigationRequest = {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WorkspaceTabId } from './types'
|
|
2
|
+
|
|
3
|
+
// Each tab gets a temporary draft id for unsent text and attachments.
|
|
4
|
+
// This id never goes to a harness; the first send creates a real session.
|
|
5
|
+
export function draftSessionId(tabId: WorkspaceTabId): string {
|
|
6
|
+
return `draft:${tabId}`
|
|
7
|
+
}
|
|
8
|
+
export function composerDraftKey(workspaceId: string, sessionId: string): string {
|
|
9
|
+
return JSON.stringify([workspaceId, sessionId])
|
|
10
|
+
}
|
package/lib/types.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { AppIconId } from './app-icons'
|
|
|
3
3
|
import type { ExperimentalFeatures } from './experimental'
|
|
4
4
|
import type { MoiContext } from './moi-context'
|
|
5
5
|
import type { WorkspaceTheme } from './themes'
|
|
6
|
-
import type { AttachmentInput,
|
|
6
|
+
import type { AttachmentInput, WidgetConfig } from 'moi'
|
|
7
7
|
|
|
8
8
|
export type { AttachmentInput, ViewConfig, WidgetConfig } from 'moi'
|
|
9
9
|
|
|
@@ -33,33 +33,28 @@ export type WidgetInfo = AppletInfo & {
|
|
|
33
33
|
// A view is a full-screen, agent-authored "app" (`.moi/views/<name>.tsx`),
|
|
34
34
|
// shown one-at-a-time in the workspace nav. Same build/RPC machinery as a
|
|
35
35
|
// widget, minus the grid: no sizing, the view owns its own layout and scroll.
|
|
36
|
-
export type
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export type ViewBuilderInput = {
|
|
36
|
+
export type PendingView = {
|
|
37
|
+
id: string
|
|
38
|
+
status: 'draft' | 'starting' | 'submitted' | 'failed'
|
|
39
|
+
title?: string
|
|
40
|
+
icon?: string
|
|
43
41
|
requirements: string
|
|
42
|
+
// Execution reference only. Ownership lives in SessionRecord.tabId.
|
|
43
|
+
executionSessionId?: string
|
|
44
|
+
error?: string
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
export type
|
|
47
|
+
export type CompiledView = {
|
|
47
48
|
id: string
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
input: ViewBuilderInput
|
|
51
|
-
sessionId: string
|
|
52
|
-
viewId?: string
|
|
53
|
-
title?: string
|
|
49
|
+
status: 'compiled'
|
|
50
|
+
title: string
|
|
54
51
|
icon?: string
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// to demote a build that has been running too long (a hung/abandoned turn).
|
|
58
|
-
buildingSince?: number
|
|
59
|
-
createdAt: number
|
|
60
|
-
updatedAt: number
|
|
52
|
+
requiredEnv?: string[]
|
|
53
|
+
revision?: string
|
|
61
54
|
}
|
|
62
55
|
|
|
56
|
+
export type ViewInfo = PendingView | CompiledView
|
|
57
|
+
|
|
63
58
|
// ---- Applet error journal (see docs/self-correction.md) ------------------
|
|
64
59
|
|
|
65
60
|
// Where an applet error was observed. `build` and `rpc` are recorded
|
|
@@ -281,8 +276,8 @@ export type ClientMessage =
|
|
|
281
276
|
// op's correlation id so the server settles the right pending CLI request.
|
|
282
277
|
| { type: 'scratchpad:op-result'; opId: string; result?: ScratchOpResult; error?: string }
|
|
283
278
|
|
|
284
|
-
// Session
|
|
285
|
-
export type
|
|
279
|
+
// Session details supplied by the agent backend.
|
|
280
|
+
export type SessionSummary = {
|
|
286
281
|
sessionId: string
|
|
287
282
|
summary: string
|
|
288
283
|
lastModified: number
|
|
@@ -306,10 +301,45 @@ export type SessionConfig = {
|
|
|
306
301
|
fastMode?: boolean
|
|
307
302
|
}
|
|
308
303
|
|
|
304
|
+
type SessionForkFields =
|
|
305
|
+
| {
|
|
306
|
+
forkedFromSessionId?: undefined
|
|
307
|
+
forkedThroughMessageId?: never
|
|
308
|
+
forkedNoticeIds?: never
|
|
309
|
+
}
|
|
310
|
+
| {
|
|
311
|
+
forkedFromSessionId: string
|
|
312
|
+
// Last copied turn in the child. Without a cutoff, show its full history.
|
|
313
|
+
forkedThroughMessageId?: string
|
|
314
|
+
forkedNoticeIds?: string[]
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Local session fields shared by the saved record and session-list rows.
|
|
318
|
+
type SessionMetadata = {
|
|
319
|
+
tabId?: WorkspaceTabId
|
|
320
|
+
} & SessionForkFields
|
|
321
|
+
|
|
322
|
+
export type SessionRecord = SessionMetadata & {
|
|
323
|
+
config?: SessionConfig
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export type SessionRecordPatch = Partial<Pick<SessionRecord, 'tabId' | 'config'>> &
|
|
327
|
+
SessionForkFields
|
|
328
|
+
|
|
329
|
+
// List row returned to the client after local metadata is added.
|
|
330
|
+
export type SessionInfo = SessionSummary & SessionMetadata
|
|
331
|
+
|
|
309
332
|
export type SelectedSessionState = {
|
|
310
333
|
sessionId: string | null
|
|
311
334
|
}
|
|
312
335
|
|
|
336
|
+
export type WorkspaceSessionSelection = {
|
|
337
|
+
// A browser tab can explicitly choose an empty chat (null). An absent key
|
|
338
|
+
// inherits the server selection, including CLI-created view handoffs.
|
|
339
|
+
selected: Partial<Record<WorkspaceTabId, string | null>>
|
|
340
|
+
pinned: string | null
|
|
341
|
+
}
|
|
342
|
+
|
|
313
343
|
// App-wide settings, persisted server-side as `settings.json` in moi's data
|
|
314
344
|
// dir and exposed via GET/PATCH /api/settings. Every key has a default, so
|
|
315
345
|
// GET always returns a complete object.
|
|
@@ -373,6 +403,7 @@ export type ServerMessage =
|
|
|
373
403
|
| StatusMessage
|
|
374
404
|
| SessionRenamedMessage
|
|
375
405
|
| SessionsChangedMessage
|
|
406
|
+
| SessionArchivedMessage
|
|
376
407
|
| WorkspaceSwitchMessage
|
|
377
408
|
| ErrorFrame
|
|
378
409
|
| StoppedFrame
|
|
@@ -417,6 +448,7 @@ export type BroadcastFrame =
|
|
|
417
448
|
| Omit<StatusMessage, 'workspaceId'>
|
|
418
449
|
| Omit<SessionRenamedMessage, 'workspaceId'>
|
|
419
450
|
| Omit<SessionsChangedMessage, 'workspaceId'>
|
|
451
|
+
| Omit<SessionArchivedMessage, 'workspaceId'>
|
|
420
452
|
| Omit<ErrorFrame, 'workspaceId'>
|
|
421
453
|
| Omit<StoppedFrame, 'workspaceId'>
|
|
422
454
|
|
|
@@ -528,6 +560,12 @@ export type SessionsChangedMessage = {
|
|
|
528
560
|
sessionId: string
|
|
529
561
|
}
|
|
530
562
|
|
|
563
|
+
export type SessionArchivedMessage = {
|
|
564
|
+
type: 'session_archived'
|
|
565
|
+
workspaceId: string
|
|
566
|
+
sessionId: string
|
|
567
|
+
}
|
|
568
|
+
|
|
531
569
|
export type ErrorFrame = {
|
|
532
570
|
kind: 'error'
|
|
533
571
|
workspaceId: string
|
|
@@ -564,16 +602,11 @@ export type StatusMessage = {
|
|
|
564
602
|
export type LayoutGridItem = { i: string; x: number; y: number }
|
|
565
603
|
|
|
566
604
|
// Persisted layout of the workspace panel:
|
|
567
|
-
// fullscreen —
|
|
568
|
-
// split —
|
|
605
|
+
// fullscreen — full-width workspace with chat in a floating popup
|
|
606
|
+
// split — workspace content with a docked chat sidebar on the right
|
|
569
607
|
export type LayoutMode = 'fullscreen' | 'split'
|
|
570
608
|
|
|
571
|
-
export type WorkspaceTabId =
|
|
572
|
-
| 'agent'
|
|
573
|
-
| 'overview'
|
|
574
|
-
| 'scratchpad'
|
|
575
|
-
| `views/${string}`
|
|
576
|
-
| `view-builders/${string}`
|
|
609
|
+
export type WorkspaceTabId = 'overview' | 'scratchpad' | `views/${string}`
|
|
577
610
|
|
|
578
611
|
// Open tabs plus the workspace's saved DEFAULT tab. `active` is not live focus
|
|
579
612
|
// state — the live active tab is each browser tab's URL (`/workspace/:id/<tab>`).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// One-time instructions when a chat starts working on a pending view.
|
|
2
|
+
// The moi-workspace skill owns the general build workflow.
|
|
3
|
+
export function viewBuildDirectives(viewId: string, availableIcons: readonly string[]): string[] {
|
|
4
|
+
return [
|
|
5
|
+
'Build a new view from this message. Follow the pending view steps in the moi-workspace skill.',
|
|
6
|
+
`The view id is \`${viewId}\`. Write the view source to \`.moi/views/${viewId}.tsx\`.`,
|
|
7
|
+
`Before building, set a provisional title and icon: \`moi views set ${viewId} --title "<title>" --icon <icon-id>\`. Use sentence case for the title.`,
|
|
8
|
+
`Available view icons: ${availableIcons.join(', ')}`,
|
|
9
|
+
'If the user asks for an additional view, create it with: `moi views create --requirements "<complete requirements>"`.',
|
|
10
|
+
`When done, do not navigate. Keep the user's current tab open and end your reply with \`[Open the view](moi:/views/${viewId})\`.`
|
|
11
|
+
]
|
|
12
|
+
}
|
package/lib/workspace-layout.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { WorkspaceLayout, WorkspaceTabsState } from './types'
|
|
|
3
3
|
import { isWorkspaceTabId } from './workspace-tabs'
|
|
4
4
|
|
|
5
5
|
export function createDefaultWorkspaceTabs(): WorkspaceTabsState {
|
|
6
|
-
return { open: ['overview', '
|
|
6
|
+
return { open: ['overview', 'scratchpad'], active: 'overview' }
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function normalizeWorkspaceTabs(value: unknown): WorkspaceTabsState {
|