moi-computer 0.3.1-next.0 → 0.4.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 +49 -12
- 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 +22 -7
- 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/dev/HarnessDebugPage.tsx +210 -74
- 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 +16 -5
- package/dist/chunk-19g80zc9.css +1 -0
- package/dist/{chunk-jen6xcm1.js → chunk-2vaafjp4.js} +1 -1
- package/dist/{chunk-vkvb3hjm.js → chunk-35fq49qa.js} +1 -1
- package/dist/chunk-69nhbjhy.js +50 -0
- package/dist/{chunk-axszxe4c.js → chunk-72atbmh3.js} +1 -1
- package/dist/{chunk-zpxrb1ce.js → chunk-7mkv2gr0.js} +2 -2
- package/dist/{chunk-cs8vbert.js → chunk-fh2mf6v9.js} +3 -3
- package/dist/chunk-gt7n06ef.js +1 -0
- package/dist/chunk-jwmc32rp.js +63 -0
- package/dist/chunk-kh24bstm.js +10 -0
- package/dist/chunk-sfa4mbmx.js +15 -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 +33 -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 +121 -16
- package/server/harness/codex/client.ts +67 -18
- package/server/harness/codex/discovery.ts +114 -0
- package/server/harness/codex/index.ts +10 -5
- package/server/harness/codex/probe.ts +4 -2
- package/server/harness/codex/session.ts +89 -13
- 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-6c8cwpzc.js +0 -1
- package/dist/chunk-b3ynfk4g.js +0 -62
- package/dist/chunk-b4b276wx.js +0 -15
- package/dist/chunk-kxmvv1ax.js +0 -48
- package/dist/chunk-npwq6jmr.css +0 -1
- package/dist/openai-h13pza4b.svg +0 -3
- package/lib/view-builder-meta.ts +0 -35
|
@@ -16,19 +16,26 @@
|
|
|
16
16
|
// `clientUserMessageId` as `clientId`, so the optimistic-id rendezvous is
|
|
17
17
|
// first-class (no text matching like OpenClaw needs).
|
|
18
18
|
import { appendAttachmentNote } from '@/lib/attachment-note'
|
|
19
|
+
import {
|
|
20
|
+
type MoiContext,
|
|
21
|
+
appendMoiContext,
|
|
22
|
+
renderMoiContext,
|
|
23
|
+
renderMoiContextBody
|
|
24
|
+
} from '@/lib/moi-context'
|
|
19
25
|
import { type Part, type SubagentRecord, type Turn, applyEvent, emptyViewState } from '@/lib/format'
|
|
20
|
-
import type { StreamEvent, ViewState } from '@/lib/types'
|
|
26
|
+
import type { SessionActivity, StreamEvent, ViewState } from '@/lib/types'
|
|
21
27
|
|
|
22
28
|
import {
|
|
23
29
|
type CodexThread,
|
|
24
30
|
type CodexThreadItem,
|
|
25
31
|
type CodexTokenUsage,
|
|
26
32
|
type CodexTurn,
|
|
33
|
+
type SubagentReplay,
|
|
27
34
|
codexItemToNotice,
|
|
28
35
|
codexItemToTurn,
|
|
29
36
|
codexThreadToEvents
|
|
30
37
|
} from './adapter'
|
|
31
|
-
import { type CodexClient, getCodexClient } from './client'
|
|
38
|
+
import { type CodexClient, getCodexClient, readSubagentRecords } from './client'
|
|
32
39
|
import { debug } from '../../debug'
|
|
33
40
|
import { broadcast } from '../../state'
|
|
34
41
|
import { hasThreadConfig, renameThreadConfig, saveThreadConfig } from '../../thread-config'
|
|
@@ -91,10 +98,20 @@ function liveKey(workspaceId: string, sessionId: string): string {
|
|
|
91
98
|
return real ? recKey(workspaceId, real) : direct
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
export function
|
|
95
|
-
|
|
101
|
+
export function getCodexActiveSessions(): {
|
|
102
|
+
workspaceId: string
|
|
103
|
+
sessionId: string
|
|
104
|
+
activity: SessionActivity
|
|
105
|
+
}[] {
|
|
106
|
+
const out: { workspaceId: string; sessionId: string; activity: SessionActivity }[] = []
|
|
96
107
|
for (const s of sessions.values()) {
|
|
97
|
-
|
|
108
|
+
// Codex never surfaces `requires-action`: approvals are designed out
|
|
109
|
+
// (APPROVAL_POLICY 'never' + transport auto-accept in client.ts). If that
|
|
110
|
+
// policy is ever relaxed, `*requestApproval` / `elicitation` server
|
|
111
|
+
// requests are the signals to map to it.
|
|
112
|
+
if (s.processing) {
|
|
113
|
+
out.push({ workspaceId: s.workspaceId, sessionId: s.sessionId, activity: 'running' })
|
|
114
|
+
}
|
|
98
115
|
}
|
|
99
116
|
return out
|
|
100
117
|
}
|
|
@@ -103,7 +120,11 @@ function setProcessing(rec: SessionRecord, processing: boolean, turnId: string |
|
|
|
103
120
|
rec.activeTurnId = turnId
|
|
104
121
|
if (rec.processing === processing) return
|
|
105
122
|
rec.processing = processing
|
|
106
|
-
broadcast(rec.workspaceId, {
|
|
123
|
+
broadcast(rec.workspaceId, {
|
|
124
|
+
type: 'status',
|
|
125
|
+
sessionId: rec.sessionId,
|
|
126
|
+
activity: processing ? 'running' : 'idle'
|
|
127
|
+
})
|
|
107
128
|
}
|
|
108
129
|
|
|
109
130
|
function emitTurnEvent(rec: SessionRecord, ev: StreamEvent) {
|
|
@@ -160,6 +181,10 @@ function handleChildNotification(
|
|
|
160
181
|
if (method === 'item/started' || method === 'item/completed') {
|
|
161
182
|
const item = params.item as CodexThreadItem | undefined
|
|
162
183
|
if (!item) return
|
|
184
|
+
// The child's own `subAgentActivity` (its send-back to the parent) would
|
|
185
|
+
// render as a cryptic nested agent card — skip it, matching the replay
|
|
186
|
+
// path (childThreadToSubagentRecord).
|
|
187
|
+
if (item.type === 'subAgentActivity') return
|
|
163
188
|
const turn = codexItemToTurn(item, childThreadId)
|
|
164
189
|
if (!turn) return
|
|
165
190
|
const idx = child.record.transcript.findIndex(t => t.id === turn.id)
|
|
@@ -269,6 +294,15 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
|
|
|
269
294
|
forwardPreview(rec, params.itemId as string, 'reasoning', String(params.delta ?? ''))
|
|
270
295
|
return
|
|
271
296
|
}
|
|
297
|
+
case 'item/reasoning/summaryPartAdded': {
|
|
298
|
+
// Each part is a new summary section; without a break the sections
|
|
299
|
+
// concatenate into one run-on paragraph. Skip the first part (no
|
|
300
|
+
// preview text yet) so the reasoning doesn't open with a blank line.
|
|
301
|
+
if (rec.previews.has(params.itemId as string)) {
|
|
302
|
+
forwardPreview(rec, params.itemId as string, 'reasoning', '\n')
|
|
303
|
+
}
|
|
304
|
+
return
|
|
305
|
+
}
|
|
272
306
|
case 'thread/tokenUsage/updated': {
|
|
273
307
|
rec.lastUsage = (params.tokenUsage ?? null) as CodexTokenUsage | null
|
|
274
308
|
return
|
|
@@ -290,6 +324,11 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
|
|
|
290
324
|
content: turn.error.message
|
|
291
325
|
})
|
|
292
326
|
}
|
|
327
|
+
// An externally-interrupted turn otherwise ends silently, identical to a
|
|
328
|
+
// clean completion — surface the stop so the client can render it.
|
|
329
|
+
if (turn?.status === 'interrupted') {
|
|
330
|
+
broadcast(rec.workspaceId, { kind: 'stopped', sessionId: rec.sessionId })
|
|
331
|
+
}
|
|
293
332
|
return
|
|
294
333
|
}
|
|
295
334
|
case 'error': {
|
|
@@ -298,6 +337,9 @@ function handleNotification(rec: SessionRecord, method: string, params: Record<s
|
|
|
298
337
|
if (message) {
|
|
299
338
|
broadcast(rec.workspaceId, { kind: 'error', sessionId: rec.sessionId, content: message })
|
|
300
339
|
}
|
|
340
|
+
// A top-level error without a following turn/completed would otherwise
|
|
341
|
+
// leave the session busy forever — the error is terminal for the turn.
|
|
342
|
+
setProcessing(rec, false, null)
|
|
301
343
|
return
|
|
302
344
|
}
|
|
303
345
|
// Codex hooks (~/.codex/hooks.json) — surface as hook notices, parity
|
|
@@ -387,9 +429,13 @@ function createRecord(input: {
|
|
|
387
429
|
}
|
|
388
430
|
|
|
389
431
|
// Seed a record's view from a resumed thread payload (turns included).
|
|
390
|
-
function seedFromThread(
|
|
432
|
+
function seedFromThread(
|
|
433
|
+
rec: SessionRecord,
|
|
434
|
+
thread: CodexThread,
|
|
435
|
+
subagents?: Map<string, SubagentReplay>
|
|
436
|
+
) {
|
|
391
437
|
let view = emptyViewState()
|
|
392
|
-
for (const ev of codexThreadToEvents(thread)) view = applyEvent(view, ev)
|
|
438
|
+
for (const ev of codexThreadToEvents(thread, subagents)) view = applyEvent(view, ev)
|
|
393
439
|
rec.view = view
|
|
394
440
|
}
|
|
395
441
|
|
|
@@ -405,7 +451,12 @@ async function resumeSession(input: {
|
|
|
405
451
|
threadId: input.sessionId
|
|
406
452
|
})
|
|
407
453
|
const rec = createRecord({ ...input, sessionId: resumed.thread.id, client })
|
|
408
|
-
|
|
454
|
+
// Rebuild child-agent transcripts from their own threads and register them
|
|
455
|
+
// as live children, so a mid-run resume keeps routing child frames into
|
|
456
|
+
// the same records the replay attached.
|
|
457
|
+
const subagents = await readSubagentRecords(client, resumed.thread)
|
|
458
|
+
for (const [childId, sub] of subagents) rec.children.set(childId, sub)
|
|
459
|
+
seedFromThread(rec, resumed.thread, subagents)
|
|
409
460
|
return rec
|
|
410
461
|
}
|
|
411
462
|
|
|
@@ -452,6 +503,11 @@ export async function sendCodexMessage(input: {
|
|
|
452
503
|
model?: string
|
|
453
504
|
effort?: string
|
|
454
505
|
stream?: boolean
|
|
506
|
+
// Structured moi context (lib/moi-context.ts), rendered here. Servers
|
|
507
|
+
// >= 0.135 take it via `additionalContext` (never enters userMessage
|
|
508
|
+
// items); older ones get it appended to the text item, stripped from
|
|
509
|
+
// echoes by the adapter.
|
|
510
|
+
context?: MoiContext
|
|
455
511
|
}): Promise<void> {
|
|
456
512
|
const uploads = input.attachments?.length
|
|
457
513
|
? resolveUploads(input.workspaceId, input.attachments)
|
|
@@ -496,6 +552,9 @@ export async function sendCodexMessage(input: {
|
|
|
496
552
|
rec = await resumeSession(input)
|
|
497
553
|
}
|
|
498
554
|
} catch (err) {
|
|
555
|
+
// No session record exists to run setProcessing through — clear the
|
|
556
|
+
// client's optimistic spinner explicitly or it sticks until reconnect.
|
|
557
|
+
broadcast(input.workspaceId, { type: 'status', sessionId: input.sessionId, activity: 'idle' })
|
|
499
558
|
broadcast(input.workspaceId, {
|
|
500
559
|
kind: 'error',
|
|
501
560
|
sessionId: input.sessionId,
|
|
@@ -524,16 +583,32 @@ export async function sendCodexMessage(input: {
|
|
|
524
583
|
setProcessing(rec, true, rec.activeTurnId)
|
|
525
584
|
try {
|
|
526
585
|
const client = await getCodexClient(input.workspacePath)
|
|
586
|
+
// Native context channel: diffed per key server-side (unchanged values
|
|
587
|
+
// inject nothing) and never echoed back in userMessage items. The entry
|
|
588
|
+
// key becomes the tag, so ship the unwrapped body. Older servers silently
|
|
589
|
+
// drop the field, so append to the text item there instead.
|
|
590
|
+
const additionalContext =
|
|
591
|
+
input.context && client.supportsAdditionalContext
|
|
592
|
+
? { 'moi-context': { value: renderMoiContextBody(input.context), kind: 'application' } }
|
|
593
|
+
: undefined
|
|
594
|
+
if (input.context && !additionalContext) {
|
|
595
|
+
const envelope = renderMoiContext(input.context)
|
|
596
|
+
const last = userInput[userInput.length - 1]
|
|
597
|
+
if (last?.type === 'text') last.text = appendMoiContext(last.text, envelope)
|
|
598
|
+
else userInput.push({ type: 'text', text: envelope })
|
|
599
|
+
}
|
|
527
600
|
const turnParams = {
|
|
528
601
|
threadId: rec.sessionId,
|
|
529
602
|
clientUserMessageId: turnId,
|
|
530
603
|
input: userInput,
|
|
604
|
+
...(additionalContext ? { additionalContext } : {}),
|
|
531
605
|
// Without an explicit summary mode Codex still reasons but emits the
|
|
532
606
|
// reasoning item with EMPTY summary/content (verified on the wire —
|
|
533
|
-
// scripts/codex-probe.ts), so no thinking ever reaches the UI. '
|
|
534
|
-
// makes summaries stream
|
|
535
|
-
//
|
|
536
|
-
|
|
607
|
+
// scripts/codex-probe.ts), so no thinking ever reaches the UI. 'detailed'
|
|
608
|
+
// (vs 'auto') makes the summaries longer and stream in more frequent
|
|
609
|
+
// item/reasoning/summaryTextDelta bursts while the model is still
|
|
610
|
+
// thinking — 'auto' tends to emit one short blob near the end.
|
|
611
|
+
summary: 'detailed',
|
|
537
612
|
...(input.model ? { model: input.model } : {}),
|
|
538
613
|
...(input.effort ? { effort: input.effort } : {})
|
|
539
614
|
}
|
|
@@ -545,6 +620,7 @@ export async function sendCodexMessage(input: {
|
|
|
545
620
|
threadId: rec.sessionId,
|
|
546
621
|
clientUserMessageId: turnId,
|
|
547
622
|
input: userInput,
|
|
623
|
+
...(additionalContext ? { additionalContext } : {}),
|
|
548
624
|
expectedTurnId: rec.activeTurnId
|
|
549
625
|
})
|
|
550
626
|
} catch {
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { accessSync, constants, statSync } from 'node:fs'
|
|
2
|
+
|
|
3
|
+
import type { HarnessAvailability, WorkspaceType } from '@/lib/types'
|
|
4
|
+
|
|
5
|
+
import { cachedLoginShellPath, loginShellPath, mergeSearchPaths } from './shell-path'
|
|
6
|
+
|
|
7
|
+
type PathWorkspaceType = Extract<WorkspaceType, 'claude-code' | 'codex'>
|
|
8
|
+
|
|
9
|
+
type ExecutableConfig = {
|
|
10
|
+
command: string
|
|
11
|
+
unavailableReason: string
|
|
12
|
+
// Absolute locations probed when the PATH lookup misses. PATH wins, so a
|
|
13
|
+
// deliberately installed CLI is never shadowed by an app-bundled copy.
|
|
14
|
+
fallbackPaths?: readonly string[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const executableConfig: Record<PathWorkspaceType, ExecutableConfig> = {
|
|
18
|
+
'claude-code': {
|
|
19
|
+
command: 'claude',
|
|
20
|
+
unavailableReason:
|
|
21
|
+
'Run curl -fsSL https://claude.ai/install.sh | sh in your terminal to install Claude'
|
|
22
|
+
},
|
|
23
|
+
codex: {
|
|
24
|
+
command: 'codex',
|
|
25
|
+
// Codex Desktop manages an app-internal binary and does not put `codex`
|
|
26
|
+
// on PATH: probe the known macOS bundle locations (ChatGPT.app is the
|
|
27
|
+
// current home, Codex.app the legacy standalone install).
|
|
28
|
+
fallbackPaths: [
|
|
29
|
+
'/Applications/ChatGPT.app/Contents/Resources/codex',
|
|
30
|
+
'/Applications/Codex.app/Contents/Resources/codex'
|
|
31
|
+
],
|
|
32
|
+
unavailableReason:
|
|
33
|
+
'Run curl -fsSL https://chatgpt.com/codex/install.sh | sh in your terminal to install Codex'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Resolve the login-shell PATH eagerly so sync lookups on the spawn path see
|
|
38
|
+
// it settled long before the first session starts.
|
|
39
|
+
void loginShellPath()
|
|
40
|
+
|
|
41
|
+
function isExecutableFile(path: string): boolean {
|
|
42
|
+
try {
|
|
43
|
+
accessSync(path, constants.X_OK)
|
|
44
|
+
return statSync(path).isFile()
|
|
45
|
+
} catch {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function firstExecutable(paths: readonly string[]): string | null {
|
|
51
|
+
return paths.find(isExecutableFile) ?? null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// `path` is a test seam: when given, only that PATH is searched — no
|
|
55
|
+
// login-shell merge, no bundle fallbacks.
|
|
56
|
+
export function findHarnessExecutable(type: PathWorkspaceType, path?: string): string | null {
|
|
57
|
+
const config = executableConfig[type]
|
|
58
|
+
if (path !== undefined) return Bun.which(config.command, { PATH: path })
|
|
59
|
+
return (
|
|
60
|
+
Bun.which(config.command, {
|
|
61
|
+
PATH: mergeSearchPaths(cachedLoginShellPath(), process.env.PATH)
|
|
62
|
+
}) ?? firstExecutable(config.fallbackPaths ?? [])
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function requireHarnessExecutable(type: PathWorkspaceType, path?: string): string {
|
|
67
|
+
const executable = findHarnessExecutable(type, path)
|
|
68
|
+
if (!executable) throw new Error(executableConfig[type].unavailableReason)
|
|
69
|
+
return executable
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function pathHarnessAvailability(
|
|
73
|
+
type: PathWorkspaceType,
|
|
74
|
+
path?: string
|
|
75
|
+
): Promise<HarnessAvailability> {
|
|
76
|
+
// Availability is asked per request (and long after startup), but await the
|
|
77
|
+
// probe anyway so the very first request can't report a false negative.
|
|
78
|
+
if (path === undefined) await loginShellPath()
|
|
79
|
+
return findHarnessExecutable(type, path)
|
|
80
|
+
? { available: true }
|
|
81
|
+
: { available: false, reason: executableConfig[type].unavailableReason }
|
|
82
|
+
}
|
|
@@ -25,11 +25,18 @@ import type {
|
|
|
25
25
|
OpenClawSessionDetail,
|
|
26
26
|
OpenClawSessionRow
|
|
27
27
|
} from './discovery'
|
|
28
|
+
import { stripMoiContextLoose } from '@/lib/moi-context'
|
|
28
29
|
import { stripUserMessageMetadata } from './strip'
|
|
29
30
|
|
|
30
31
|
export function toSessionInfo(row: OpenClawSessionRow, cwd: string): SessionInfo {
|
|
32
|
+
// Gateway previews carry the raw stored message — for a user send that
|
|
33
|
+
// includes the appended context envelope, and truncation can cut it open,
|
|
34
|
+
// so clean with the loose strip like the Codex previews do.
|
|
31
35
|
const summary =
|
|
32
|
-
row.lastMessagePreview
|
|
36
|
+
stripMoiContextLoose(row.lastMessagePreview ?? '').trim() ||
|
|
37
|
+
row.displayName?.trim() ||
|
|
38
|
+
row.label?.trim() ||
|
|
39
|
+
''
|
|
33
40
|
return {
|
|
34
41
|
sessionId: row.sessionId,
|
|
35
42
|
summary,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
// OpenClaw as a Harness. Thin wiring over this folder's modules — see
|
|
2
2
|
// ../types.ts for the contract and ../README.md for the architecture.
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
import type { Harness } from '../types'
|
|
3
|
+
import type { DiscoveredWorkspaceCandidate, Harness } from '../types'
|
|
6
4
|
import { toSessionInfo, toStreamEvents } from './adapter'
|
|
7
5
|
import {
|
|
8
6
|
discoverOpenClawAgents,
|
|
@@ -15,7 +13,7 @@ import {
|
|
|
15
13
|
abortOpenClawRun,
|
|
16
14
|
ensureOpenClawSessionLive,
|
|
17
15
|
getLiveOpenClawEvents,
|
|
18
|
-
|
|
16
|
+
getOpenClawActiveSessions,
|
|
19
17
|
sendOpenClawMessage
|
|
20
18
|
} from './session'
|
|
21
19
|
|
|
@@ -36,7 +34,7 @@ export const openclawHarness: Harness = {
|
|
|
36
34
|
return sendOpenClawMessage({ ...input, agentId: input.agentId })
|
|
37
35
|
},
|
|
38
36
|
interrupt: (workspaceId, sessionId) => abortOpenClawRun({ workspaceId, sessionId }),
|
|
39
|
-
|
|
37
|
+
activeSessions: () => getOpenClawActiveSessions(),
|
|
40
38
|
|
|
41
39
|
listSessions: async ws => {
|
|
42
40
|
const rows = await getOpenClawSessions(ws.path, ws.agentId)
|
|
@@ -73,13 +71,9 @@ export const openclawHarness: Harness = {
|
|
|
73
71
|
return agents
|
|
74
72
|
.filter(a => !registeredPaths.has(a.path))
|
|
75
73
|
.map(
|
|
76
|
-
(a):
|
|
74
|
+
(a): DiscoveredWorkspaceCandidate => ({
|
|
77
75
|
path: a.path,
|
|
78
|
-
type: 'openclaw'
|
|
79
|
-
...(a.name ? { name: a.name } : {}),
|
|
80
|
-
...(a.agentId ? { agentId: a.agentId } : {}),
|
|
81
|
-
...(a.isDefault ? { isDefault: a.isDefault } : {}),
|
|
82
|
-
...(a.lastRunAt ? { lastRunAt: a.lastRunAt } : {})
|
|
76
|
+
type: 'openclaw'
|
|
83
77
|
})
|
|
84
78
|
)
|
|
85
79
|
},
|
|
@@ -87,10 +81,10 @@ export const openclawHarness: Harness = {
|
|
|
87
81
|
skillsDir: workspaceRoot => `${workspaceRoot}/skills`,
|
|
88
82
|
|
|
89
83
|
statusLines: () => {
|
|
90
|
-
const
|
|
84
|
+
const active = getOpenClawActiveSessions()
|
|
91
85
|
return [
|
|
92
|
-
`live OpenClaw runs ${
|
|
93
|
-
...
|
|
86
|
+
`live OpenClaw runs ${active.length}`,
|
|
87
|
+
...active.map(r => ` ▶ busy ws=${r.workspaceId} session=${r.sessionId}`)
|
|
94
88
|
]
|
|
95
89
|
}
|
|
96
90
|
}
|
|
@@ -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
|