moi-computer 0.3.1-next.0 → 0.3.1-next.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/client/api/workspace-keys.ts +2 -2
- package/client/app/AppRouter.tsx +0 -2
- package/client/app/shell/SidebarLayout.tsx +3 -16
- package/client/assets/openai.svg +1 -3
- package/client/components/shared/Composer.tsx +53 -2
- package/client/components/ui/button.tsx +1 -1
- package/client/components/ui/tooltip.tsx +12 -15
- package/client/features/chat/ChatComposer.tsx +25 -15
- package/client/features/chat/ChatPanel.tsx +5 -2
- package/client/features/chat/MarkdownContent.tsx +20 -2
- package/client/features/chat/ModelPicker.tsx +5 -3
- package/client/features/chat/TurnView.tsx +2 -2
- package/client/features/chat/chat-frames.ts +13 -6
- package/client/features/chat/chat-send.ts +1 -1
- package/client/features/chat/chat-store.ts +22 -17
- package/client/features/chat/tool-group/ToolOutput.tsx +4 -12
- package/client/features/chat/tool-group/format.ts +0 -6
- package/client/features/chat/useChat.ts +11 -2
- package/client/features/connectors/McpServerCards.tsx +95 -0
- package/client/features/connectors/api.ts +0 -11
- package/client/features/home/HomePage.tsx +33 -28
- package/client/features/home/api.ts +24 -12
- package/client/features/home/workspace-presentation.tsx +17 -15
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +243 -0
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +95 -0
- package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +230 -0
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +35 -0
- package/client/features/home/workspace-setup/useWorkspaceImport.ts +61 -0
- package/client/features/settings/ConnectorsSettings.tsx +89 -0
- package/client/features/settings/SettingsLayout.tsx +2 -2
- package/client/features/settings/WorkspaceSettings.tsx +8 -4
- package/client/features/views/ViewBuilderTab.tsx +19 -15
- package/client/features/views/useViewBuilderActions.ts +1 -1
- package/client/features/workspace/WorkspaceLayoutContext.tsx +3 -4
- package/client/features/workspace/WorkspaceScreen.tsx +11 -3
- package/client/features/workspace/api.ts +19 -1
- package/client/features/workspace/moi-context.ts +85 -0
- package/client/main.tsx +7 -4
- package/dist/{chunk-cs8vbert.js → chunk-1dfbr7n2.js} +2 -2
- package/dist/chunk-339jds4x.js +15 -0
- package/dist/chunk-3xsvsnhr.css +1 -0
- package/dist/{chunk-zpxrb1ce.js → chunk-anqmsbjt.js} +2 -2
- package/dist/chunk-hbvfb6sk.js +63 -0
- package/dist/{chunk-kxmvv1ax.js → chunk-qwm5f6qk.js} +1 -1
- package/dist/{chunk-axszxe4c.js → chunk-sxbfh73c.js} +1 -1
- package/dist/chunk-yp4srgqt.js +10 -0
- package/dist/index.html +1 -1
- package/dist/openai-ep9ht2pq.svg +1 -0
- package/lib/ids.ts +15 -0
- package/lib/moi-context.ts +170 -0
- package/lib/types.ts +29 -11
- package/lib/view-builder-directives.ts +16 -0
- package/lib/workspace-types.ts +12 -0
- package/package.json +2 -1
- package/server/api.ts +92 -30
- package/server/harness/README.md +25 -9
- package/server/harness/claude-code/NOTES.md +20 -6
- package/server/harness/claude-code/adapter.ts +2 -2
- package/server/harness/claude-code/git-worktree.ts +32 -0
- package/server/harness/claude-code/index.ts +32 -12
- package/server/harness/claude-code/mcp.ts +16 -65
- package/server/harness/claude-code/models.ts +3 -0
- package/server/harness/claude-code/session.ts +196 -61
- package/server/harness/codex/NOTES.md +41 -11
- package/server/harness/codex/adapter.ts +21 -7
- package/server/harness/codex/client.ts +33 -17
- package/server/harness/codex/discovery.ts +114 -0
- package/server/harness/codex/index.ts +9 -5
- package/server/harness/codex/probe.ts +4 -2
- package/server/harness/codex/session.ts +57 -5
- package/server/harness/executable.ts +82 -0
- package/server/harness/openclaw/adapter.ts +8 -1
- package/server/harness/openclaw/index.ts +8 -14
- package/server/harness/openclaw/session.ts +50 -10
- package/server/harness/openclaw/strip.ts +2 -2
- package/server/harness/shell-path.ts +79 -0
- package/server/harness/types.ts +22 -5
- package/server/registry.ts +57 -12
- package/server/view-builders.ts +3 -2
- package/server/web.ts +24 -8
- package/server/workspace-import.ts +45 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +3 -3
- package/client/features/connectors/ConnectorsPage.tsx +0 -92
- package/client/features/connectors/McpMenu.tsx +0 -145
- package/client/features/home/CreateWorkspaceDialog.tsx +0 -130
- package/client/features/home/CreateWorkspaceDialogSteps.tsx +0 -234
- package/dist/chunk-4vf1t6v1.js +0 -10
- package/dist/chunk-b3ynfk4g.js +0 -62
- package/dist/chunk-b4b276wx.js +0 -15
- package/dist/chunk-npwq6jmr.css +0 -1
- package/dist/openai-h13pza4b.svg +0 -3
- package/lib/view-builder-meta.ts +0 -35
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
// - Disk persistence — the gateway is the source of truth; we re-seed from
|
|
13
13
|
// `sessions.get` on cold start.
|
|
14
14
|
import { appendAttachmentNote } from '@/lib/attachment-note'
|
|
15
|
-
import {
|
|
15
|
+
import { type MoiContext, appendMoiContext, renderMoiContext } from '@/lib/moi-context'
|
|
16
16
|
import { applyEvent, emptyViewState } from '@/lib/format'
|
|
17
|
-
import type { StreamEvent, ViewState } from '@/lib/types'
|
|
17
|
+
import type { SessionActivity, StreamEvent, ViewState } from '@/lib/types'
|
|
18
18
|
|
|
19
19
|
import {
|
|
20
20
|
type OpenClawMessage,
|
|
@@ -82,20 +82,46 @@ onGatewayReconnected(async () => {
|
|
|
82
82
|
console.error('[openclaw-session] reconcile-on-reconnect failed', err)
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
// Lifecycle frames emitted during the disconnect window are gone for good —
|
|
86
|
+
// a run that ended while we were away would leave its session busy forever.
|
|
87
|
+
// Re-derive every busy flag from the gateway's own `sessions.list` status.
|
|
88
|
+
try {
|
|
89
|
+
const busy = [...sessions.values()].filter(rec =>
|
|
90
|
+
isOpenClawProcessing(rec.workspaceId, rec.sessionId)
|
|
91
|
+
)
|
|
92
|
+
if (busy.length === 0) return
|
|
93
|
+
const gw = await getGateway()
|
|
94
|
+
const res = await gw.rpc<{ sessions: { key: string; status?: string }[] }>('sessions.list', {
|
|
95
|
+
includeGlobal: true
|
|
96
|
+
})
|
|
97
|
+
const running = new Set(
|
|
98
|
+
(res?.sessions ?? []).filter(row => row.status === 'running').map(row => row.key)
|
|
99
|
+
)
|
|
100
|
+
for (const rec of busy) {
|
|
101
|
+
if (!running.has(rec.sessionKey)) setProcessing(rec, false, null)
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.error('[openclaw-session] busy-flag reconcile failed', err)
|
|
105
|
+
}
|
|
85
106
|
})
|
|
86
107
|
|
|
87
108
|
function recKey(workspaceId: string, sessionId: string): string {
|
|
88
109
|
return `${workspaceId}:${sessionId}`
|
|
89
110
|
}
|
|
90
111
|
|
|
91
|
-
// All
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
112
|
+
// All non-idle OpenClaw sessions across every workspace, for the status
|
|
113
|
+
// snapshot. Key is `${workspaceId}:${sessionId}` (both are colon-free). The
|
|
114
|
+
// protocol has no "waiting for user input" concept, so activity is binary.
|
|
115
|
+
export function getOpenClawActiveSessions(): {
|
|
116
|
+
workspaceId: string
|
|
117
|
+
sessionId: string
|
|
118
|
+
activity: SessionActivity
|
|
119
|
+
}[] {
|
|
120
|
+
const out: { workspaceId: string; sessionId: string; activity: SessionActivity }[] = []
|
|
95
121
|
for (const [k, v] of openclawAgents) {
|
|
96
122
|
if (!v.processing) continue
|
|
97
123
|
const i = k.indexOf(':')
|
|
98
|
-
out.push({ workspaceId: k.slice(0, i), sessionId: k.slice(i + 1) })
|
|
124
|
+
out.push({ workspaceId: k.slice(0, i), sessionId: k.slice(i + 1), activity: 'running' })
|
|
99
125
|
}
|
|
100
126
|
return out
|
|
101
127
|
}
|
|
@@ -113,7 +139,11 @@ function setProcessing(rec: SessionRecord, processing: boolean, runId: string |
|
|
|
113
139
|
activeRunId: runId
|
|
114
140
|
})
|
|
115
141
|
if (existing?.processing === processing) return
|
|
116
|
-
broadcast(rec.workspaceId, {
|
|
142
|
+
broadcast(rec.workspaceId, {
|
|
143
|
+
type: 'status',
|
|
144
|
+
sessionId: rec.sessionId,
|
|
145
|
+
activity: processing ? 'running' : 'idle'
|
|
146
|
+
})
|
|
117
147
|
if (processing) {
|
|
118
148
|
void markViewBuilderBuildingBySession(rec.workspaceId, rec.workspacePath, rec.sessionId)
|
|
119
149
|
} else {
|
|
@@ -385,6 +415,10 @@ export async function sendOpenClawMessage(input: {
|
|
|
385
415
|
// (see dev/file-uploads.md).
|
|
386
416
|
attachments?: string[]
|
|
387
417
|
optimisticId?: string
|
|
418
|
+
// Structured moi context (lib/moi-context.ts), rendered and appended at
|
|
419
|
+
// the gateway send only — `content` stays clean so the optimistic-id echo
|
|
420
|
+
// rendezvous keeps matching on the user's text.
|
|
421
|
+
context?: MoiContext
|
|
388
422
|
}): Promise<void> {
|
|
389
423
|
// Fold any attachments into the message text as file-path references.
|
|
390
424
|
let content = input.content
|
|
@@ -411,6 +445,7 @@ async function sendOpenClawMessageImpl(input: {
|
|
|
411
445
|
isNew: boolean
|
|
412
446
|
content: string
|
|
413
447
|
optimisticId?: string
|
|
448
|
+
context?: MoiContext
|
|
414
449
|
}): Promise<void> {
|
|
415
450
|
// New threads: ask the gateway to create one, then rename the client's
|
|
416
451
|
// tentative UUID to the real session id. Mirrors the Claude Code flow
|
|
@@ -463,7 +498,7 @@ async function sendOpenClawMessageImpl(input: {
|
|
|
463
498
|
if (input.optimisticId) {
|
|
464
499
|
rec.pendingUserEchoes.push({
|
|
465
500
|
optimisticId: input.optimisticId,
|
|
466
|
-
text:
|
|
501
|
+
text: input.content
|
|
467
502
|
})
|
|
468
503
|
if (rec.pendingUserEchoes.length > MAX_PENDING_USER_ECHOES) {
|
|
469
504
|
rec.pendingUserEchoes.shift()
|
|
@@ -477,7 +512,9 @@ async function sendOpenClawMessageImpl(input: {
|
|
|
477
512
|
const gw = await getGateway()
|
|
478
513
|
const resp = await gw.rpc<{ runId?: string; status?: string }>('sessions.send', {
|
|
479
514
|
key: rec.sessionKey,
|
|
480
|
-
message: input.
|
|
515
|
+
message: input.context
|
|
516
|
+
? appendMoiContext(input.content, renderMoiContext(input.context))
|
|
517
|
+
: input.content
|
|
481
518
|
})
|
|
482
519
|
if (resp?.runId) setProcessing(rec, true, resp.runId)
|
|
483
520
|
} catch (err) {
|
|
@@ -522,6 +559,9 @@ export async function abortOpenClawRun(input: {
|
|
|
522
559
|
sessionId: rec.sessionId,
|
|
523
560
|
content: err instanceof Error ? err.message : 'abort failed'
|
|
524
561
|
})
|
|
562
|
+
// Stop is the user's escape hatch from a stuck spinner — clear the busy
|
|
563
|
+
// flag even when the abort RPC fails (the run may already be gone).
|
|
564
|
+
setProcessing(rec, false, null)
|
|
525
565
|
}
|
|
526
566
|
}
|
|
527
567
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { stripMoiContext } from '@/lib/moi-context'
|
|
2
2
|
|
|
3
3
|
// Strip OpenClaw-injected inbound metadata from user-role message text.
|
|
4
4
|
//
|
|
@@ -132,5 +132,5 @@ export function stripBootstrapPreamble(text: string): string {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
export function stripUserMessageMetadata(text: string): string {
|
|
135
|
-
return
|
|
135
|
+
return stripMoiContext(stripInboundMetadata(stripBootstrapPreamble(text)))
|
|
136
136
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { userInfo } from 'node:os'
|
|
2
|
+
import { delimiter } from 'node:path'
|
|
3
|
+
|
|
4
|
+
// The moi server does not always start from a terminal (GUI launcher, service
|
|
5
|
+
// manager), and a non-shell parent's PATH misses exactly the dirs agent CLIs
|
|
6
|
+
// install to: ~/.local/bin, ~/.bun/bin, homebrew, version-manager shims. Probe
|
|
7
|
+
// the user's login shell for its PATH once and merge it into every executable
|
|
8
|
+
// lookup — the same recovery VS Code and Superset use, minus the PTY.
|
|
9
|
+
|
|
10
|
+
const MARKER = '__moi_env__'
|
|
11
|
+
const TIMEOUT_MS = 3000
|
|
12
|
+
|
|
13
|
+
function configuredShell(): string | null {
|
|
14
|
+
if (process.platform === 'win32') return null
|
|
15
|
+
try {
|
|
16
|
+
const shell = userInfo().shell
|
|
17
|
+
if (shell) return shell
|
|
18
|
+
} catch {
|
|
19
|
+
// userInfo() throws when the account has no passwd entry (containers).
|
|
20
|
+
}
|
|
21
|
+
return process.env.SHELL || null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// `/usr/bin/env` instead of `echo $PATH`: fish joins list variables with
|
|
25
|
+
// spaces, and rc files are free to print noise — the markers isolate env's
|
|
26
|
+
// output so only the real PATH line is parsed.
|
|
27
|
+
async function detectLoginShellPath(): Promise<string | null> {
|
|
28
|
+
const shell = configuredShell()
|
|
29
|
+
if (!shell) return null
|
|
30
|
+
const proc = Bun.spawn(
|
|
31
|
+
[shell, '-l', '-c', `printf '%s' '${MARKER}'; /usr/bin/env; printf '%s' '${MARKER}'`],
|
|
32
|
+
{ stdin: 'ignore', stdout: 'pipe', stderr: 'ignore' }
|
|
33
|
+
)
|
|
34
|
+
const timeout = setTimeout(() => proc.kill(), TIMEOUT_MS)
|
|
35
|
+
try {
|
|
36
|
+
const [out] = await Promise.all([new Response(proc.stdout).text(), proc.exited])
|
|
37
|
+
const start = out.indexOf(MARKER)
|
|
38
|
+
const end = out.lastIndexOf(MARKER)
|
|
39
|
+
if (start === -1 || end <= start) return null
|
|
40
|
+
const env = out.slice(start + MARKER.length, end)
|
|
41
|
+
for (const line of env.split('\n')) {
|
|
42
|
+
if (line.startsWith('PATH=')) return line.slice('PATH='.length) || null
|
|
43
|
+
}
|
|
44
|
+
return null
|
|
45
|
+
} catch {
|
|
46
|
+
return null
|
|
47
|
+
} finally {
|
|
48
|
+
clearTimeout(timeout)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let cached: string | null = null
|
|
53
|
+
let pending: Promise<string | null> | null = null
|
|
54
|
+
|
|
55
|
+
// Start (or join) the login-shell PATH probe. Failure is not an error —
|
|
56
|
+
// lookups just fall back to the server's own PATH.
|
|
57
|
+
export function loginShellPath(): Promise<string | null> {
|
|
58
|
+
pending ??= detectLoginShellPath()
|
|
59
|
+
.catch(() => null)
|
|
60
|
+
.then(path => (cached = path))
|
|
61
|
+
return pending
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Last resolved value, for sync callers on the spawn path. Null until the
|
|
65
|
+
// probe settles; executable.ts kicks it off at module load, so real spawns
|
|
66
|
+
// (always later than server start) see the resolved value.
|
|
67
|
+
export function cachedLoginShellPath(): string | null {
|
|
68
|
+
return cached
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function mergeSearchPaths(...paths: Array<string | null | undefined>): string {
|
|
72
|
+
const seen = new Set<string>()
|
|
73
|
+
for (const path of paths) {
|
|
74
|
+
for (const dir of (path ?? '').split(delimiter)) {
|
|
75
|
+
if (dir) seen.add(dir)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [...seen].join(delimiter)
|
|
79
|
+
}
|
package/server/harness/types.ts
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// by moi. See README.md in this folder for the full checklist and the
|
|
3
3
|
// message-type layers; each harness's index.ts exports one Harness object
|
|
4
4
|
// wrapping its session/adapter/transport modules.
|
|
5
|
+
import type { MoiContext } from '@/lib/moi-context'
|
|
5
6
|
import type {
|
|
6
|
-
|
|
7
|
+
HarnessAvailability,
|
|
7
8
|
McpServer,
|
|
8
9
|
Model,
|
|
10
|
+
SessionActivity,
|
|
9
11
|
SessionInfo,
|
|
10
12
|
StreamEvent,
|
|
11
13
|
WorkspaceEntry,
|
|
@@ -28,6 +30,12 @@ export type SendMessageInput = {
|
|
|
28
30
|
model?: string
|
|
29
31
|
effort?: string
|
|
30
32
|
stream?: boolean
|
|
33
|
+
// Structured moi context (lib/moi-context.ts). Each harness renders and
|
|
34
|
+
// injects it its own way: Claude Code as a leading system-reminder text
|
|
35
|
+
// block, Codex >= 0.135 via the native additionalContext channel (appended
|
|
36
|
+
// to the text below that), OpenClaw appended after the text at the gateway
|
|
37
|
+
// send.
|
|
38
|
+
context?: MoiContext
|
|
31
39
|
// OpenClaw: the gateway agent that owns the workspace.
|
|
32
40
|
agentId?: string
|
|
33
41
|
}
|
|
@@ -55,6 +63,11 @@ export type WorkspaceActivityPreview = {
|
|
|
55
63
|
updatedAt?: number
|
|
56
64
|
}
|
|
57
65
|
|
|
66
|
+
export type DiscoveredWorkspaceCandidate = {
|
|
67
|
+
path: string
|
|
68
|
+
type: WorkspaceType
|
|
69
|
+
}
|
|
70
|
+
|
|
58
71
|
export type Harness = {
|
|
59
72
|
id: WorkspaceType
|
|
60
73
|
capabilities: HarnessCapabilities
|
|
@@ -62,9 +75,10 @@ export type Harness = {
|
|
|
62
75
|
// -- chat lifecycle ---------------------------------------------------------
|
|
63
76
|
sendMessage(input: SendMessageInput): Promise<void>
|
|
64
77
|
interrupt(workspaceId: string, sessionId: string): Promise<void>
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
|
|
78
|
+
// Every session whose activity is not `idle`, across all workspaces (drives
|
|
79
|
+
// the status snapshot and view-builder reconciliation). Activity is mirrored
|
|
80
|
+
// from the backend's native lifecycle signal, never derived by counting.
|
|
81
|
+
activeSessions(): { workspaceId: string; sessionId: string; activity: SessionActivity }[]
|
|
68
82
|
|
|
69
83
|
// -- discovery / metadata ---------------------------------------------------
|
|
70
84
|
listSessions(ws: WorkspaceEntry): Promise<SessionInfo[]>
|
|
@@ -81,7 +95,10 @@ export type Harness = {
|
|
|
81
95
|
// MCP server status for the connectors UI; absent = backend has no MCP story.
|
|
82
96
|
mcpStatus?(ws: WorkspaceEntry): Promise<McpServer[]>
|
|
83
97
|
// Workspaces this backend knows about that aren't registered yet.
|
|
84
|
-
discoverWorkspaces?(registeredPaths: Set<string>): Promise<
|
|
98
|
+
discoverWorkspaces?(registeredPaths: Set<string>): Promise<DiscoveredWorkspaceCandidate[]>
|
|
99
|
+
// Is the backend's runtime present on this machine? Absent = always
|
|
100
|
+
// available. Cheap enough to call per request (a PATH lookup, not a probe).
|
|
101
|
+
availability?(): Promise<HarnessAvailability>
|
|
85
102
|
|
|
86
103
|
// -- host integration hooks -------------------------------------------------
|
|
87
104
|
// Env is frozen at spawn everywhere; this reaps idle sessions/processes so
|
package/server/registry.ts
CHANGED
|
@@ -2,10 +2,13 @@ import { mkdir } from 'node:fs/promises'
|
|
|
2
2
|
import { homedir } from 'node:os'
|
|
3
3
|
import { join, resolve, sep } from 'path'
|
|
4
4
|
|
|
5
|
+
import { newWorkspaceId } from '@/lib/ids'
|
|
5
6
|
import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
|
|
7
|
+
import { orderWorkspaceTypes } from '@/lib/workspace-types'
|
|
6
8
|
|
|
7
9
|
import { DATA_DIR } from './data-dir'
|
|
8
10
|
import { allHarnesses } from './harness/registry'
|
|
11
|
+
import type { DiscoveredWorkspaceCandidate } from './harness/types'
|
|
9
12
|
|
|
10
13
|
// Replace the home-dir prefix with `~` for display. Keeps the original
|
|
11
14
|
// absolute path in place; callers should put the result in `displayPath`.
|
|
@@ -61,7 +64,7 @@ export async function registerWorkspace(
|
|
|
61
64
|
const existing = entries.find(e => e.path === normalPath)
|
|
62
65
|
if (existing) return existing
|
|
63
66
|
const entry: WorkspaceEntry = {
|
|
64
|
-
id:
|
|
67
|
+
id: newWorkspaceId(),
|
|
65
68
|
path: normalPath,
|
|
66
69
|
addedAt: new Date().toISOString(),
|
|
67
70
|
...(opts.type ? { type: opts.type } : {}),
|
|
@@ -138,20 +141,62 @@ export function liftToWorkspaceRoot(p: string): string {
|
|
|
138
141
|
return segments.slice(0, i).join(sep) || sep
|
|
139
142
|
}
|
|
140
143
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
// same path — CC sessions exist in most directories an agent ever ran in.
|
|
145
|
-
export async function discoverWorkspaces(): Promise<DiscoveredWorkspace[]> {
|
|
146
|
-
const registeredPaths = new Set((await readRegistry()).map(e => e.path))
|
|
144
|
+
async function collectDiscoveredWorkspaces(
|
|
145
|
+
registeredPaths: Set<string>
|
|
146
|
+
): Promise<DiscoveredWorkspaceCandidate[]> {
|
|
147
147
|
const perHarness = await Promise.all(
|
|
148
148
|
allHarnesses().map(
|
|
149
149
|
h => h.discoverWorkspaces?.(registeredPaths).catch(() => []) ?? Promise.resolve([])
|
|
150
150
|
)
|
|
151
151
|
)
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
return perHarness.flat()
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function groupDiscoveredWorkspaces(
|
|
156
|
+
candidates: DiscoveredWorkspaceCandidate[],
|
|
157
|
+
registeredPaths: Set<string> = new Set()
|
|
158
|
+
): DiscoveredWorkspace[] {
|
|
159
|
+
const normalizedRegisteredPaths = new Set([...registeredPaths].map(path => resolve(path)))
|
|
160
|
+
const byPath = new Map<string, Set<WorkspaceType>>()
|
|
161
|
+
|
|
162
|
+
for (const candidate of candidates) {
|
|
163
|
+
const path = resolve(candidate.path)
|
|
164
|
+
if (normalizedRegisteredPaths.has(path)) continue
|
|
165
|
+
const types = byPath.get(path) ?? new Set<WorkspaceType>()
|
|
166
|
+
types.add(candidate.type)
|
|
167
|
+
byPath.set(path, types)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return [...byPath].map(([path, types]) => ({
|
|
171
|
+
path,
|
|
172
|
+
types: orderWorkspaceTypes(types)
|
|
173
|
+
}))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function discoveredWorkspaceForPath(
|
|
177
|
+
path: string,
|
|
178
|
+
candidates: DiscoveredWorkspaceCandidate[]
|
|
179
|
+
): DiscoveredWorkspace {
|
|
180
|
+
const normalizedPath = resolve(path)
|
|
181
|
+
return (
|
|
182
|
+
groupDiscoveredWorkspaces(candidates).find(workspace => workspace.path === normalizedPath) ?? {
|
|
183
|
+
path: normalizedPath,
|
|
184
|
+
types: []
|
|
185
|
+
}
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Ask every harness for workspaces it knows about that aren't registered yet,
|
|
190
|
+
// then combine providers that claim the same normalized folder.
|
|
191
|
+
export async function discoverWorkspaces(): Promise<DiscoveredWorkspace[]> {
|
|
192
|
+
const registeredPaths = new Set((await readRegistry()).map(e => e.path))
|
|
193
|
+
const found = await collectDiscoveredWorkspaces(registeredPaths)
|
|
194
|
+
return groupDiscoveredWorkspaces(found, registeredPaths).map(withDisplayPath)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Inspect one folder through the same provider discovery used by the home
|
|
198
|
+
// suggestions. An empty types list means no provider recognized the folder.
|
|
199
|
+
export async function discoverWorkspace(path: string): Promise<DiscoveredWorkspace> {
|
|
200
|
+
const found = await collectDiscoveredWorkspaces(new Set())
|
|
201
|
+
return withDisplayPath(discoveredWorkspaceForPath(path, found))
|
|
157
202
|
}
|
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 { newBuilderId } from '@/lib/ids'
|
|
4
5
|
import type { AppletKind, ViewBuilder, ViewInfo } from '@/lib/types'
|
|
5
6
|
|
|
6
7
|
import { DATA_DIR } from './data-dir'
|
|
@@ -107,7 +108,7 @@ export async function createViewBuilder(
|
|
|
107
108
|
const builder = await mutateBuilders(workspacePath, builders => {
|
|
108
109
|
const now = Date.now()
|
|
109
110
|
const created: ViewBuilder = {
|
|
110
|
-
id:
|
|
111
|
+
id: newBuilderId(),
|
|
111
112
|
kind: 'view',
|
|
112
113
|
status: 'draft',
|
|
113
114
|
input: { requirements: '' },
|
|
@@ -215,7 +216,7 @@ export async function setBuilder(
|
|
|
215
216
|
const now = Date.now()
|
|
216
217
|
const status = input.status ?? 'building'
|
|
217
218
|
const created: ViewBuilder = {
|
|
218
|
-
id:
|
|
219
|
+
id: newBuilderId(),
|
|
219
220
|
kind,
|
|
220
221
|
status,
|
|
221
222
|
input: { requirements: '' },
|
package/server/web.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ClientMessage } from '@/lib/types'
|
|
1
|
+
import type { ClientMessage, StatusSnapshotMessage } from '@/lib/types'
|
|
2
|
+
import { isMoiContext } from '@/lib/moi-context'
|
|
2
3
|
|
|
3
4
|
import index from '../client/index.html'
|
|
4
5
|
import { api } from './api'
|
|
@@ -10,7 +11,7 @@ import { startScratchpadSweeper } from './scratchpad'
|
|
|
10
11
|
import { resolveScratchOp } from './scratchpad-relay'
|
|
11
12
|
import { allHarnesses, harnessFor } from './harness/registry'
|
|
12
13
|
import { getWorkspace } from './registry'
|
|
13
|
-
import { addClient, removeClient, sendToClient } from './state'
|
|
14
|
+
import { addClient, broadcastAll, getClientCount, removeClient, sendToClient } from './state'
|
|
14
15
|
import { distShell, prebuilt } from './static'
|
|
15
16
|
import { renderStatus } from './status'
|
|
16
17
|
import { serveVendorEmojibase, serveVendorReact } from './vendor'
|
|
@@ -29,6 +30,7 @@ function isClientMessage(value: unknown): value is ClientMessage {
|
|
|
29
30
|
model?: unknown
|
|
30
31
|
effort?: unknown
|
|
31
32
|
stream?: unknown
|
|
33
|
+
context?: unknown
|
|
32
34
|
attachments?: unknown
|
|
33
35
|
opId?: unknown
|
|
34
36
|
}
|
|
@@ -42,6 +44,7 @@ function isClientMessage(value: unknown): value is ClientMessage {
|
|
|
42
44
|
(v.model === undefined || typeof v.model === 'string') &&
|
|
43
45
|
(v.effort === undefined || typeof v.effort === 'string') &&
|
|
44
46
|
(v.stream === undefined || typeof v.stream === 'boolean') &&
|
|
47
|
+
(v.context === undefined || isMoiContext(v.context)) &&
|
|
45
48
|
(v.attachments === undefined ||
|
|
46
49
|
(Array.isArray(v.attachments) && v.attachments.every(a => typeof a === 'string')))
|
|
47
50
|
)
|
|
@@ -55,6 +58,13 @@ function isClientMessage(value: unknown): value is ClientMessage {
|
|
|
55
58
|
// stays here, in the routes table, so Bun's dev bundler keys off it.
|
|
56
59
|
const shell = prebuilt ? distShell : index
|
|
57
60
|
|
|
61
|
+
// Authoritative activity snapshot across all harnesses. Sent on chat-socket
|
|
62
|
+
// connect and re-broadcast periodically (below) so a spinner whose terminal
|
|
63
|
+
// status frame was lost self-heals without a reconnect.
|
|
64
|
+
function statusSnapshot(): StatusSnapshotMessage {
|
|
65
|
+
return { type: 'status_snapshot', sessions: allHarnesses().flatMap(h => h.activeSessions()) }
|
|
66
|
+
}
|
|
67
|
+
|
|
58
68
|
type Upgradable = { upgrade(req: Request, opts: { data: WsData }): boolean }
|
|
59
69
|
|
|
60
70
|
function upgrade(server: Upgradable, req: Request, data: WsData) {
|
|
@@ -89,7 +99,6 @@ export const app = Bun.serve<WsData>({
|
|
|
89
99
|
|
|
90
100
|
// Client-side routes — serve the SPA shell.
|
|
91
101
|
'/': shell,
|
|
92
|
-
'/connectors': shell,
|
|
93
102
|
'/dev': shell,
|
|
94
103
|
'/dev/*': shell,
|
|
95
104
|
'/workspace/*': shell,
|
|
@@ -111,11 +120,10 @@ export const app = Bun.serve<WsData>({
|
|
|
111
120
|
open(ws) {
|
|
112
121
|
if (ws.data.channel === 'chat') {
|
|
113
122
|
addClient(ws)
|
|
114
|
-
// Authoritative snapshot of every
|
|
115
|
-
// so the client can light/clear spinners correctly even for
|
|
116
|
-
// status transitions it missed while disconnected.
|
|
117
|
-
|
|
118
|
-
sendToClient(ws, { type: 'status_snapshot', running })
|
|
123
|
+
// Authoritative snapshot of every non-idle session across all
|
|
124
|
+
// harnesses so the client can light/clear spinners correctly even for
|
|
125
|
+
// runs whose status transitions it missed while disconnected.
|
|
126
|
+
sendToClient(ws, statusSnapshot())
|
|
119
127
|
} else {
|
|
120
128
|
ws.subscribe(EVENTS_TOPIC)
|
|
121
129
|
}
|
|
@@ -144,6 +152,7 @@ export const app = Bun.serve<WsData>({
|
|
|
144
152
|
model: data.model,
|
|
145
153
|
effort: data.effort,
|
|
146
154
|
stream: data.stream,
|
|
155
|
+
context: data.context,
|
|
147
156
|
agentId: workspace.agentId
|
|
148
157
|
})
|
|
149
158
|
.catch(() => {})
|
|
@@ -173,6 +182,13 @@ export const app = Bun.serve<WsData>({
|
|
|
173
182
|
// importing web.ts (which binds ports on load).
|
|
174
183
|
setEventServer(app)
|
|
175
184
|
|
|
185
|
+
// The snapshot heartbeat: the client's reconcile fully replaces its activity
|
|
186
|
+
// map from each snapshot, so any stale spinner clears within one interval.
|
|
187
|
+
const SNAPSHOT_INTERVAL_MS = 30_000
|
|
188
|
+
setInterval(() => {
|
|
189
|
+
if (getClientCount() > 0) broadcastAll(statusSnapshot())
|
|
190
|
+
}, SNAPSHOT_INTERVAL_MS)
|
|
191
|
+
|
|
176
192
|
// Periodically reclaim scratchpad asset files nothing references anymore —
|
|
177
193
|
// deleting an image in the browser (or an upload whose tab died) otherwise
|
|
178
194
|
// leaves its file behind forever. See sweepOrphanAssets.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import type { WorkspaceType } from '@/lib/types'
|
|
4
|
+
|
|
5
|
+
import { discoverOpenClawAgents } from './harness/openclaw/discovery'
|
|
6
|
+
import type { OpenClawAgent } from './harness/openclaw/discovery'
|
|
7
|
+
|
|
8
|
+
export type WorkspaceImportMetadata = {
|
|
9
|
+
name?: string
|
|
10
|
+
agentId?: string
|
|
11
|
+
isDefault?: boolean
|
|
12
|
+
lastRunAt?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type DiscoverOpenClawAgents = () => Promise<OpenClawAgent[]>
|
|
16
|
+
|
|
17
|
+
function compareOpenClawAgents(a: OpenClawAgent, b: OpenClawAgent): number {
|
|
18
|
+
if (a.isDefault !== b.isDefault) return a.isDefault ? -1 : 1
|
|
19
|
+
const byLastRun = (b.lastRunAt ?? '').localeCompare(a.lastRunAt ?? '')
|
|
20
|
+
return byLastRun || a.agentId.localeCompare(b.agentId)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function resolveWorkspaceImportMetadata(
|
|
24
|
+
path: string,
|
|
25
|
+
type: WorkspaceType,
|
|
26
|
+
discoverAgents: DiscoverOpenClawAgents = discoverOpenClawAgents
|
|
27
|
+
): Promise<WorkspaceImportMetadata> {
|
|
28
|
+
if (type !== 'openclaw') return {}
|
|
29
|
+
|
|
30
|
+
const normalizedPath = resolve(path)
|
|
31
|
+
const agent = (await discoverAgents())
|
|
32
|
+
.filter(candidate => resolve(candidate.path) === normalizedPath)
|
|
33
|
+
.sort(compareOpenClawAgents)[0]
|
|
34
|
+
|
|
35
|
+
if (!agent) {
|
|
36
|
+
throw new Error('OpenClaw is not initialized for this folder')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
...(agent.name ? { name: agent.name } : {}),
|
|
41
|
+
agentId: agent.agentId,
|
|
42
|
+
...(agent.isDefault ? { isDefault: true } : {}),
|
|
43
|
+
...(agent.lastRunAt ? { lastRunAt: agent.lastRunAt } : {})
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: moi-workspace
|
|
3
|
-
description: The moi workspace — the web UI the user chats from, extended with agent-authored applets (widgets, views) plus theme & config. Read this FIRST in two cases. (a) A message carries hidden <moi>…</moi>
|
|
3
|
+
description: The moi workspace — the web UI the user chats from, extended with agent-authored applets (widgets, views) plus theme & config. Read this FIRST in two cases. (a) A message carries a hidden <moi-context>…</moi-context> envelope: it was fired from a moi workspace, so you are running inside one even if nothing else says so. (b) The user uses moi vocab — workspace, applet, widget, view, scratchpad, dashboard, or a `moi` command — or asks to build, edit, customize, or theme the workspace UI or its layout.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Workspace
|
|
@@ -289,7 +289,7 @@ Full-screen apps, one per nav tab — the user switches tabs; there is no routin
|
|
|
289
289
|
|
|
290
290
|
## View builder requests
|
|
291
291
|
|
|
292
|
-
When the
|
|
292
|
+
When the message's hidden `<moi-context>` envelope is marked `View builder request`, this chat is
|
|
293
293
|
linked to a pending view tab. Before reading files, planning, or writing code, infer a short stable
|
|
294
294
|
id, a clear sentence-case title, and a relevant icon from the requirements. Capitalize only the
|
|
295
295
|
first word of the title. Your first action must claim them:
|
|
@@ -328,4 +328,4 @@ This skill is installed with moi (via the CLI or the UI) and can fall behind whe
|
|
|
328
328
|
- **Then** — if you updated, mention it.
|
|
329
329
|
|
|
330
330
|
<!-- moi skill version marker — read by `moi skill` to detect drift; do not edit by hand -->
|
|
331
|
-
<moi-skill version="0.
|
|
331
|
+
<moi-skill version="0.7.0" />
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { IconPlugConnected } from '@tabler/icons-react'
|
|
2
|
-
|
|
3
|
-
import { useUserMcp } from './api'
|
|
4
|
-
import { McpServerCard, sortMcpServers } from '@/client/features/connectors/McpMenu'
|
|
5
|
-
import { SidebarLayout } from '@/client/app/shell/SidebarLayout'
|
|
6
|
-
import { Button } from '@/client/components/ui/button'
|
|
7
|
-
import { Skeleton } from '@/client/components/ui/skeleton'
|
|
8
|
-
|
|
9
|
-
const CONNECTOR_SKELETONS = Array.from({ length: 6 }, (_, index) => index)
|
|
10
|
-
|
|
11
|
-
export function ConnectorsPage() {
|
|
12
|
-
return (
|
|
13
|
-
<SidebarLayout panel="flat">
|
|
14
|
-
<div className="min-h-0 flex-1 overflow-y-auto">
|
|
15
|
-
<UserConnectorsPage />
|
|
16
|
-
</div>
|
|
17
|
-
</SidebarLayout>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function UserConnectorsPage() {
|
|
22
|
-
const connectorsQuery = useUserMcp()
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<div className="mx-auto w-full max-w-3xl px-8 pt-14 pb-16">
|
|
26
|
-
<div className="mb-4 flex items-center justify-between gap-2">
|
|
27
|
-
<h1 className="text-sm font-medium text-foreground">Connectors</h1>
|
|
28
|
-
</div>
|
|
29
|
-
|
|
30
|
-
<ConnectorsContent connectorsQuery={connectorsQuery} />
|
|
31
|
-
</div>
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type ConnectorsContentProps = {
|
|
36
|
-
connectorsQuery: ReturnType<typeof useUserMcp>
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function ConnectorsContent({ connectorsQuery }: ConnectorsContentProps) {
|
|
40
|
-
if (connectorsQuery.isPending) {
|
|
41
|
-
return (
|
|
42
|
-
<div
|
|
43
|
-
role="status"
|
|
44
|
-
aria-label="Loading connectors"
|
|
45
|
-
className="grid grid-cols-1 gap-3 sm:grid-cols-2"
|
|
46
|
-
>
|
|
47
|
-
{CONNECTOR_SKELETONS.map(index => (
|
|
48
|
-
<div
|
|
49
|
-
key={index}
|
|
50
|
-
className="flex min-h-20 items-center gap-3 rounded-xl border border-border bg-card px-4 py-3"
|
|
51
|
-
>
|
|
52
|
-
<Skeleton className="size-10 shrink-0 rounded-sm" />
|
|
53
|
-
<div className="flex min-w-0 flex-1 flex-col gap-2">
|
|
54
|
-
<Skeleton className="h-4 w-36" />
|
|
55
|
-
<Skeleton className="h-3 w-20" />
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
))}
|
|
59
|
-
</div>
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (connectorsQuery.isError) {
|
|
64
|
-
return (
|
|
65
|
-
<div className="flex min-h-48 flex-col items-center justify-center gap-3 rounded-xl border border-dashed border-border px-8 py-12 text-center">
|
|
66
|
-
<p className="text-sm text-muted-foreground">Could not load connectors.</p>
|
|
67
|
-
<Button variant="outline" size="sm" onClick={() => connectorsQuery.refetch()}>
|
|
68
|
-
Retry
|
|
69
|
-
</Button>
|
|
70
|
-
</div>
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const connectors = sortMcpServers(connectorsQuery.data)
|
|
75
|
-
|
|
76
|
-
if (connectors.length === 0) {
|
|
77
|
-
return (
|
|
78
|
-
<div className="flex min-h-48 flex-col items-center justify-center gap-3 rounded-xl border border-dashed border-border px-8 py-12 text-center">
|
|
79
|
-
<IconPlugConnected size={24} stroke={1.5} className="text-muted-foreground" />
|
|
80
|
-
<p className="mx-auto max-w-md text-sm text-foreground">No user connectors configured.</p>
|
|
81
|
-
</div>
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
|
87
|
-
{connectors.map(connector => (
|
|
88
|
-
<McpServerCard key={connector.name} server={connector} />
|
|
89
|
-
))}
|
|
90
|
-
</div>
|
|
91
|
-
)
|
|
92
|
-
}
|