moi-computer 0.12.1-next.3 → 0.12.1-next.4
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/bunfig.toml +1 -5
- package/client/api/app-config.ts +1 -2
- package/client/api/app-ui-keys.ts +3 -1
- package/client/api/http.ts +4 -1
- package/client/api/workspace-keys.ts +3 -3
- package/client/app/app-provider.tsx +22 -2
- package/client/app/app-router.tsx +4 -0
- package/client/app/routes/home-route.tsx +14 -0
- package/client/app/routes/onboarding-route.tsx +11 -0
- package/client/app/routes/settings-route.tsx +1 -1
- package/client/app/routes/workspace-route.tsx +21 -19
- package/client/components/shared/screen-shell.tsx +23 -0
- package/client/components/shared/ultrafast-icon.tsx +61 -0
- package/client/components/shared/workspace-icon.tsx +2 -2
- package/client/features/account/account-test-utils.tsx +4 -3
- package/client/features/app-settings/api.ts +33 -0
- package/client/features/app-settings/general-settings.tsx +39 -0
- package/client/features/{settings → app-settings}/settings-page.tsx +5 -1
- package/client/features/chat/applet-chat-intents.ts +4 -20
- package/client/features/chat/chat-send.ts +17 -13
- package/client/features/chat/composer/model-order.ts +8 -4
- package/client/features/chat/composer/model-picker.tsx +88 -34
- package/client/features/chat/composer/use-workspace-composer-state.tsx +11 -3
- package/client/features/chat/composer/use-workspace-skill-updates.ts +1 -1
- package/client/features/chat/connection/chat-frames.ts +3 -15
- package/client/features/chat/messages/chat-empty-state.tsx +1 -4
- package/client/features/chat/messages/fork-history.ts +5 -5
- package/client/features/chat/messages/turn-view.tsx +3 -12
- package/client/features/chat/messages/user-message-bubble.tsx +63 -0
- package/client/features/chat/sessions/api.ts +121 -80
- package/client/features/chat/sessions/browser-tab-state.ts +14 -12
- package/client/features/chat/sessions/chat-selector.tsx +5 -6
- package/client/features/chat/sessions/use-selected-session.ts +172 -257
- package/client/features/chat/use-chat.ts +14 -19
- package/client/features/collab/workspace-users-menu.tsx +1 -1
- package/client/features/demo/demo-dialog.tsx +11 -3
- package/client/features/dev/dev-index-page.tsx +5 -0
- package/client/features/dev/dev-routes.tsx +2 -0
- package/client/features/dev/harness-debug-page.tsx +3 -3
- package/client/features/dev/onboarding-preview-page.tsx +76 -0
- package/client/features/dev/workspace-setup-mocks.ts +16 -14
- package/client/features/dev/workspace-setup-preview.tsx +11 -17
- package/client/features/harness/api.ts +45 -15
- package/client/features/harness/device-login-steps.tsx +9 -3
- package/client/features/harness/harness-login-panel.tsx +228 -0
- package/client/features/harness/harness-presentation.ts +15 -0
- package/client/features/harness/harness-selector.tsx +119 -0
- package/client/features/harness/use-harness-login.ts +77 -0
- package/client/features/home/home-page.tsx +7 -7
- package/client/features/onboarding/agent-setup-step.tsx +57 -0
- package/client/features/onboarding/api.ts +42 -0
- package/client/features/onboarding/onboarding-idea-disk.tsx +129 -0
- package/client/features/onboarding/onboarding-page.tsx +32 -0
- package/client/features/onboarding/onboarding-screen.tsx +20 -0
- package/client/features/onboarding/onboarding-status.tsx +24 -0
- package/client/features/onboarding/workspace-setup-step.tsx +239 -0
- package/client/features/overview/default/registry.tsx +2 -2
- package/client/features/overview/default/views-widget.tsx +6 -5
- package/client/features/overview/overview.tsx +9 -11
- package/client/features/overview/widget-canvas.tsx +1 -1
- package/client/features/overview/workspace-name.tsx +2 -2
- package/client/features/views/api.ts +69 -16
- package/client/features/views/pending-view-screen.tsx +30 -9
- package/client/features/views/use-view-actions.ts +19 -20
- package/client/features/views/view-presentation.ts +2 -2
- package/client/features/views/view-submission.ts +28 -41
- package/client/features/workspace/add/api.ts +3 -23
- package/client/features/workspace/add/create-workspace-dialog.tsx +6 -5
- package/client/features/workspace/add/import-workspace-dialog.tsx +3 -3
- package/client/features/workspace/add/workspace-agent-options.ts +11 -12
- package/client/features/workspace/add/workspace-agent-selector.tsx +3 -132
- package/client/features/workspace/api.ts +32 -36
- package/client/features/workspace/harness-transition.ts +88 -0
- package/client/features/{settings → workspace/settings}/api.ts +1 -34
- package/client/features/{settings → workspace/settings}/general-settings.tsx +76 -2
- package/client/features/{settings → workspace/settings}/use-env-vars.ts +1 -1
- package/client/features/{settings → workspace/settings}/workspace-icon-picker.tsx +3 -3
- package/client/features/workspace/setup/workspace-login-state.tsx +37 -156
- package/client/features/workspace/setup/workspace-recovery-states.tsx +0 -12
- package/client/features/workspace/setup/workspace-setup.tsx +34 -14
- package/client/features/workspace/setup/workspace-welcome-state.tsx +2 -2
- package/client/features/workspace/use-workspace-navigation.ts +25 -9
- package/client/features/workspace/workspace-content.tsx +11 -8
- package/client/features/workspace/workspace-frame.tsx +2 -1
- package/client/features/workspace/workspace-layout-context.tsx +5 -2
- package/client/features/workspace/workspace-menu.tsx +12 -8
- package/client/features/workspace/workspace-pending-screen.tsx +10 -10
- package/client/features/workspace/workspace-presentation.tsx +5 -13
- package/client/features/workspace/workspace-state.ts +169 -0
- package/client/features/workspace/workspace-tabs.tsx +22 -2
- package/client/index.css +2 -0
- package/client/index.tsx +3 -3
- package/client/lib/flags.ts +1 -1
- package/client/lib/{app-icon-registry.ts → identity-icon-registry.ts} +10 -14
- package/client/runtime/workspace-events.ts +21 -4
- package/client/runtime/workspace-theme.ts +9 -0
- package/client/tailwind-config.ts +43 -0
- package/dist/chunk-0mjzg20x.js +2 -0
- package/dist/chunk-2y59vrxg.js +5 -0
- package/dist/chunk-58dyt9bk.js +2 -0
- package/dist/chunk-5aj040e5.css +1 -0
- package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
- package/dist/chunk-71fn6rmj.js +546 -0
- package/dist/chunk-7yg1m8hx.js +2 -0
- package/dist/chunk-825hys3h.js +1 -0
- package/dist/chunk-9bb8m9rx.js +2 -0
- package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
- package/dist/chunk-g0tcwqxc.js +1 -0
- package/dist/chunk-n0nab26d.js +1 -0
- package/dist/chunk-nf2wkvf9.js +14 -0
- package/dist/chunk-v88n1bay.js +74 -0
- package/dist/index.html +1 -1
- package/lib/harness-instructions.ts +1 -1
- package/lib/{app-icons.ts → identity-icons.ts} +6 -7
- package/lib/onboarding.ts +41 -0
- package/lib/speed-mode.ts +5 -0
- package/lib/types.ts +71 -62
- package/lib/view-build-directives.ts +1 -2
- package/lib/workspace-icon.ts +2 -2
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-name.ts +15 -12
- package/package.json +9 -8
- package/server/README.md +27 -25
- package/server/api/harnesses.ts +31 -8
- package/server/api/index.ts +163 -126
- package/server/api/onboarding.ts +46 -0
- package/server/app-config.ts +16 -24
- package/server/app-settings.ts +6 -2
- package/server/applets/config.ts +5 -5
- package/server/applets/views.ts +19 -17
- package/server/cli/commands/init.ts +3 -3
- package/server/cli/commands/skill.ts +16 -17
- package/server/cli/commands/start.ts +8 -34
- package/server/cli/server.ts +18 -6
- package/server/collab/config.ts +1 -2
- package/server/collab/manager.ts +4 -1
- package/server/collab/skill/index.ts +1 -1
- package/server/control.ts +3 -3
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +24 -8
- package/server/harness/acp/session.ts +8 -4
- package/server/harness/auth.ts +14 -17
- package/server/harness/claude-code/NOTES.md +4 -3
- package/server/harness/claude-code/index.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -20
- package/server/harness/claude-code/run-action.ts +123 -0
- package/server/harness/claude-code/session-title.ts +5 -7
- package/server/harness/claude-code/session.ts +24 -16
- package/server/harness/codex/NOTES.md +14 -9
- package/server/harness/codex/adapter.ts +14 -17
- package/server/harness/codex/index.ts +2 -0
- package/server/harness/codex/run-action.ts +93 -0
- package/server/harness/codex/session-title.ts +6 -8
- package/server/harness/codex/session.ts +11 -11
- package/server/harness/command.ts +45 -0
- package/server/harness/executable.ts +5 -0
- package/server/harness/fork.ts +6 -4
- package/server/harness/install.ts +49 -0
- package/server/harness/openclaw/session.ts +1 -2
- package/server/harness/run-action.ts +85 -0
- package/server/harness/session-title.ts +0 -46
- package/server/harness/types.ts +26 -2
- package/server/onboarding/brief.ts +29 -0
- package/server/onboarding/ideas.ts +48 -0
- package/server/onboarding/jobs.ts +291 -0
- package/server/onboarding/prompt.md +49 -0
- package/server/sessions/archive.ts +5 -14
- package/server/sessions/config.ts +17 -16
- package/server/sessions/lifecycle.ts +15 -13
- package/server/sessions/pending-views.ts +79 -108
- package/server/sessions/selected.ts +75 -161
- package/server/sessions/store.ts +40 -113
- package/server/sessions/view-sessions.ts +128 -111
- package/server/skills/locations.ts +82 -0
- package/server/skills/lock.ts +29 -0
- package/server/skills/template.ts +36 -25
- package/server/skills/update.ts +52 -5
- package/server/skills/version.ts +17 -22
- package/server/skills/workspace.ts +121 -0
- package/server/web.ts +22 -8
- package/server/workspace-state/file.ts +177 -0
- package/server/workspace-state/index.ts +162 -0
- package/server/workspace-state/legacy-migration.ts +79 -0
- package/server/workspace-state/lock.ts +42 -0
- package/server/workspace-state/types.ts +16 -0
- package/server/workspaces/change-harness.ts +88 -0
- package/server/workspaces/harness-transition.ts +29 -0
- package/server/workspaces/init.ts +29 -6
- package/server/workspaces/layout.ts +3 -0
- package/server/workspaces/registry.ts +27 -1
- package/{workspace/.claude/skills/moi-workspace → skill}/SKILL.md +7 -5
- package/{workspace/.claude/skills/moi-workspace → skill}/references/COLLAB.md +4 -8
- package/skill/references/DESIGN.md +148 -0
- package/{workspace/.claude/skills/moi-workspace → skill}/references/SCRATCHPAD.md +2 -2
- package/{workspace/.claude/skills/moi-workspace → skill}/references/UI-COMPONENTS.md +3 -0
- package/ui-components/badge.tsx +1 -1
- package/client/accept-hmr-dependencies.ts +0 -22
- package/client/features/workspace/setup/workspace-setup-panel.tsx +0 -18
- package/dist/chunk-20ynagd4.js +0 -2
- package/dist/chunk-42tde9a6.js +0 -1
- package/dist/chunk-9w543s0r.js +0 -2
- package/dist/chunk-a5372n61.js +0 -546
- package/dist/chunk-aja9y1vn.js +0 -68
- package/dist/chunk-fvcvrh3d.css +0 -1
- package/dist/chunk-gtfjw3nx.js +0 -1
- package/dist/chunk-j39y2aky.js +0 -14
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-pja30km3.js +0 -1
- package/dist/chunk-rm894bc2.js +0 -2
- package/dist/chunk-tevvtfbk.js +0 -10
- package/dist/chunk-tgt9zd0r.js +0 -2
- package/dist/chunk-tv5k5z00.js +0 -1
- package/dist/chunk-zq2ae5dx.js +0 -2
- package/lib/experimental.ts +0 -14
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
- /package/client/features/{settings → app-settings}/profile-settings.tsx +0 -0
- /package/client/features/{settings → app-settings}/settings-section.tsx +0 -0
- /package/client/features/{settings → app-settings}/users-settings.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/connectors-settings.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/environment-settings.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/icon-picker-options.ts +0 -0
- /package/client/features/{settings → workspace/settings}/settings-layout.tsx +0 -0
- /package/client/features/{settings → workspace/settings}/workspace-settings-dialog.tsx +0 -0
- /package/{workspace/.claude/skills/moi-workspace → skill}/references/INTENTS.md +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { accessSync, constants, statSync } from 'node:fs'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
2
3
|
import { delimiter, join, resolve } from 'node:path'
|
|
3
4
|
|
|
4
5
|
import { harnessInstructionMessage } from '@/lib/harness-instructions'
|
|
@@ -19,6 +20,9 @@ type ExecutableConfig = {
|
|
|
19
20
|
const executableConfig: Record<WorkspaceType, ExecutableConfig> = {
|
|
20
21
|
'claude-code': {
|
|
21
22
|
command: 'claude',
|
|
23
|
+
fallbackPaths: [
|
|
24
|
+
join(homedir(), '.local', 'bin', process.platform === 'win32' ? 'claude.exe' : 'claude')
|
|
25
|
+
],
|
|
22
26
|
unavailableReason: harnessInstructionMessage('claude-code')
|
|
23
27
|
},
|
|
24
28
|
codex: {
|
|
@@ -27,6 +31,7 @@ const executableConfig: Record<WorkspaceType, ExecutableConfig> = {
|
|
|
27
31
|
// on PATH: probe the known macOS bundle locations (ChatGPT.app is the
|
|
28
32
|
// current home, Codex.app the legacy standalone install).
|
|
29
33
|
fallbackPaths: [
|
|
34
|
+
join(homedir(), '.local', 'bin', process.platform === 'win32' ? 'codex.exe' : 'codex'),
|
|
30
35
|
'/Applications/ChatGPT.app/Contents/Resources/codex',
|
|
31
36
|
'/Applications/Codex.app/Contents/Resources/codex'
|
|
32
37
|
],
|
package/server/harness/fork.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { StreamEvent } from '@/lib/types'
|
|
1
|
+
import type { SessionFork, StreamEvent } from '@/lib/types'
|
|
2
2
|
import { applyEvents } from '@/lib/format'
|
|
3
3
|
|
|
4
4
|
export class ForkUnsupportedError extends Error {}
|
|
5
5
|
|
|
6
|
-
export function inheritedHistoryBoundary(
|
|
6
|
+
export function inheritedHistoryBoundary(
|
|
7
|
+
events: StreamEvent[]
|
|
8
|
+
): Pick<SessionFork, 'throughMessageId' | 'noticeIds'> {
|
|
7
9
|
const view = applyEvents(events)
|
|
8
10
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
throughMessageId: view.turns.at(-1)?.id,
|
|
12
|
+
noticeIds: view.notices.map(notice => notice.id)
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HARNESS_INSTRUCTIONS } from '@/lib/harness-instructions'
|
|
2
|
+
import { getAppConfig } from '../app-config'
|
|
3
|
+
import type { WorkspaceType } from '@/lib/types'
|
|
4
|
+
import { detectInstalledHarnesses } from './executable'
|
|
5
|
+
|
|
6
|
+
const installations = new Map<WorkspaceType, Promise<void>>()
|
|
7
|
+
|
|
8
|
+
export function installHarness(type: WorkspaceType): Promise<void> {
|
|
9
|
+
const config = getAppConfig()
|
|
10
|
+
if (config.environment !== 'local' || config.demo || config.agentLauncher) {
|
|
11
|
+
throw new Error('Agents can only be installed in local Moi')
|
|
12
|
+
}
|
|
13
|
+
if (type !== 'claude-code' && type !== 'codex') {
|
|
14
|
+
throw new Error('This agent requires manual installation')
|
|
15
|
+
}
|
|
16
|
+
const pending = installations.get(type)
|
|
17
|
+
if (pending) return pending
|
|
18
|
+
const installation = (async () => {
|
|
19
|
+
if ((await detectInstalledHarnesses())[type]) return
|
|
20
|
+
const url =
|
|
21
|
+
type === 'claude-code' ? 'https://claude.ai/install' : 'https://chatgpt.com/codex/install'
|
|
22
|
+
const command =
|
|
23
|
+
process.platform === 'win32'
|
|
24
|
+
? [
|
|
25
|
+
'powershell.exe',
|
|
26
|
+
'-NoProfile',
|
|
27
|
+
'-NonInteractive',
|
|
28
|
+
'-ExecutionPolicy',
|
|
29
|
+
'Bypass',
|
|
30
|
+
'-Command',
|
|
31
|
+
`$ErrorActionPreference = 'Stop'; irm ${url}.ps1 | iex`
|
|
32
|
+
]
|
|
33
|
+
: ['bash', '-o', 'pipefail', '-c', HARNESS_INSTRUCTIONS[type].command]
|
|
34
|
+
const child = Bun.spawn(command, {
|
|
35
|
+
stdin: 'ignore',
|
|
36
|
+
stdout: 'inherit',
|
|
37
|
+
stderr: 'inherit',
|
|
38
|
+
timeout: 5 * 60_000
|
|
39
|
+
})
|
|
40
|
+
if ((await child.exited) !== 0) {
|
|
41
|
+
throw new Error('Installation failed or timed out. Try again.')
|
|
42
|
+
}
|
|
43
|
+
if (!(await detectInstalledHarnesses())[type]) {
|
|
44
|
+
throw new Error('The installer finished, but the agent could not be found. Restart Moi.')
|
|
45
|
+
}
|
|
46
|
+
})().finally(() => installations.delete(type))
|
|
47
|
+
installations.set(type, installation)
|
|
48
|
+
return installation
|
|
49
|
+
}
|
|
@@ -1338,8 +1338,7 @@ async function sendOpenClawMessageImpl(input: {
|
|
|
1338
1338
|
if (created?.sessionId && created.sessionId !== input.sessionId) {
|
|
1339
1339
|
realSessionId = created.sessionId
|
|
1340
1340
|
await renameSessionReferences(
|
|
1341
|
-
input.workspaceId,
|
|
1342
|
-
input.workspacePath,
|
|
1341
|
+
{ id: input.workspaceId, path: input.workspacePath },
|
|
1343
1342
|
input.sessionId,
|
|
1344
1343
|
realSessionId
|
|
1345
1344
|
)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
+
import { WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js'
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
import { createHarnessTempDir, removeHarnessTempDir } from './command'
|
|
5
|
+
import type { ActionModel, HarnessActionInput } from './types'
|
|
6
|
+
|
|
7
|
+
export const actionProgressServerName = 'moi_action'
|
|
8
|
+
export const actionProgressToolName = 'report_progress'
|
|
9
|
+
|
|
10
|
+
export type ActionExecution = {
|
|
11
|
+
prompt: string
|
|
12
|
+
model: ActionModel
|
|
13
|
+
resultSchema: Record<string, unknown>
|
|
14
|
+
signal: AbortSignal
|
|
15
|
+
cwd: string
|
|
16
|
+
progressUrl?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function serveProgress<T>(schema: z.ZodType<T>, report: (value: T) => void | Promise<void>) {
|
|
20
|
+
const path = `/${crypto.randomUUID()}`
|
|
21
|
+
const server = Bun.serve({
|
|
22
|
+
hostname: '127.0.0.1',
|
|
23
|
+
port: 0,
|
|
24
|
+
async fetch(request) {
|
|
25
|
+
if (new URL(request.url).pathname !== path || request.headers.has('origin'))
|
|
26
|
+
return new Response('Not found', { status: 404 })
|
|
27
|
+
const mcp = new McpServer({ name: actionProgressServerName, version: '1.0.0' })
|
|
28
|
+
mcp.registerTool(
|
|
29
|
+
actionProgressToolName,
|
|
30
|
+
{
|
|
31
|
+
description: 'Report current action progress using the supplied schema',
|
|
32
|
+
inputSchema: { progress: schema },
|
|
33
|
+
annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false }
|
|
34
|
+
},
|
|
35
|
+
async ({ progress }) => {
|
|
36
|
+
await report(progress)
|
|
37
|
+
return { content: [{ type: 'text', text: 'Progress reported' }] }
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
const transport = new WebStandardStreamableHTTPServerTransport({ enableJsonResponse: true })
|
|
41
|
+
await mcp.connect(transport)
|
|
42
|
+
try {
|
|
43
|
+
return await transport.handleRequest(request)
|
|
44
|
+
} finally {
|
|
45
|
+
await mcp.close()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
return { url: `http://127.0.0.1:${server.port}${path}`, close: () => server.stop(true) }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function executeHarnessAction<TResult, TProgress>(
|
|
53
|
+
input: HarnessActionInput<TResult, TProgress>,
|
|
54
|
+
execute: (action: ActionExecution) => Promise<unknown>
|
|
55
|
+
): Promise<TResult> {
|
|
56
|
+
if (input.signal.aborted) throw new Error('Action cancelled')
|
|
57
|
+
const cwd = await createHarnessTempDir()
|
|
58
|
+
let progress: ReturnType<typeof serveProgress> | undefined
|
|
59
|
+
const stop = () => {
|
|
60
|
+
void progress?.close()
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
if (input.signal.aborted) throw new Error('Action cancelled')
|
|
64
|
+
if (input.progressSchema) progress = serveProgress(input.progressSchema, input.onProgress)
|
|
65
|
+
input.signal.addEventListener('abort', stop, { once: true })
|
|
66
|
+
const result = await execute({
|
|
67
|
+
model: input.model ?? 'normal',
|
|
68
|
+
prompt:
|
|
69
|
+
input.prompt +
|
|
70
|
+
(progress
|
|
71
|
+
? `\n\nUse ${actionProgressServerName}/${actionProgressToolName} to report brief progress when your activity changes. Report only work you are actually doing. Return the final result through the result schema.`
|
|
72
|
+
: ''),
|
|
73
|
+
resultSchema: z.toJSONSchema(input.resultSchema, { target: 'draft-7' }),
|
|
74
|
+
signal: input.signal,
|
|
75
|
+
cwd,
|
|
76
|
+
progressUrl: progress?.url
|
|
77
|
+
})
|
|
78
|
+
if (input.signal.aborted) throw new Error('Action cancelled')
|
|
79
|
+
return input.resultSchema.parse(result)
|
|
80
|
+
} finally {
|
|
81
|
+
input.signal.removeEventListener('abort', stop)
|
|
82
|
+
await progress?.close()
|
|
83
|
+
await removeHarnessTempDir(cwd).catch(() => {})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { join } from 'node:path'
|
|
2
|
-
import { tmpdir } from 'node:os'
|
|
3
|
-
import { chmod, mkdtemp, rm } from 'node:fs/promises'
|
|
4
|
-
|
|
5
|
-
import { agentCommand } from '../agent-launcher'
|
|
6
|
-
|
|
7
1
|
const MAX_TITLE_SOURCE_LENGTH = 1_000
|
|
8
2
|
const MAX_GENERATED_TITLE_LENGTH = 64
|
|
9
3
|
|
|
@@ -63,43 +57,3 @@ export function parseGeneratedSessionTitleJson(value: string): string | null {
|
|
|
63
57
|
return null
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
|
-
|
|
67
|
-
export async function runSessionTitleCommand(input: {
|
|
68
|
-
command: readonly string[]
|
|
69
|
-
cwd: string
|
|
70
|
-
stdin?: string
|
|
71
|
-
signal: AbortSignal
|
|
72
|
-
env?: Record<string, string | undefined>
|
|
73
|
-
}): Promise<string | null> {
|
|
74
|
-
if (input.signal.aborted) return null
|
|
75
|
-
try {
|
|
76
|
-
const proc = Bun.spawn(agentCommand(input.command), {
|
|
77
|
-
cwd: input.cwd,
|
|
78
|
-
stdin: new Blob([input.stdin ?? '']),
|
|
79
|
-
stdout: 'pipe',
|
|
80
|
-
stderr: 'ignore',
|
|
81
|
-
signal: input.signal,
|
|
82
|
-
env: input.env,
|
|
83
|
-
maxBuffer: 128 * 1024
|
|
84
|
-
})
|
|
85
|
-
const [exitCode, stdout] = await Promise.all([proc.exited, new Response(proc.stdout).text()])
|
|
86
|
-
return exitCode === 0 && !input.signal.aborted ? stdout : null
|
|
87
|
-
} catch {
|
|
88
|
-
return null
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// On managed machines the title command runs as the agent's user, which is
|
|
93
|
-
// neither the folder's owner nor in its group, so the folder is open to
|
|
94
|
-
// everyone: the agent works in it and Codex writes its answer there. It holds
|
|
95
|
-
// only the schema and the title, for one run. moi stays the owner, which is
|
|
96
|
-
// what lets it remove the folder from /tmp afterwards.
|
|
97
|
-
export async function createSessionTitleTempDir(): Promise<string> {
|
|
98
|
-
const path = await mkdtemp(join(tmpdir(), 'moi-session-title-'))
|
|
99
|
-
await chmod(path, 0o777)
|
|
100
|
-
return path
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function removeSessionTitleTempDir(path: string): Promise<void> {
|
|
104
|
-
await rm(path, { recursive: true, force: true })
|
|
105
|
-
}
|
package/server/harness/types.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import type { SpeedMode } from '@/lib/types'
|
|
1
2
|
// The harness contract: what an agent backend must implement to be drivable
|
|
2
3
|
// by moi. See README.md in this folder for the full checklist and the
|
|
3
4
|
// message-type layers; each harness's index.ts exports one Harness object
|
|
4
5
|
// wrapping its session/adapter/transport modules.
|
|
5
6
|
import type { MessageAttachment } from '@/lib/types'
|
|
7
|
+
import type { ZodType } from 'zod'
|
|
6
8
|
import type { MoiContext } from '@/lib/moi-context'
|
|
7
9
|
import type {
|
|
8
10
|
HarnessAvailability,
|
|
@@ -20,7 +22,7 @@ import type {
|
|
|
20
22
|
// The superset of what any backend needs to accept a user message; harnesses
|
|
21
23
|
// ignore fields they don't support. OpenClaw honors model + effort (applied via
|
|
22
24
|
// sessions.patch) and stream (token previews), but has no Fast-mode setting so
|
|
23
|
-
// it ignores
|
|
25
|
+
// it ignores speedMode; agentId is OpenClaw-only (the gateway agent that owns
|
|
24
26
|
// the workspace).
|
|
25
27
|
export type HarnessLoginAttempt = HarnessLogin & {
|
|
26
28
|
completed?: Promise<void>
|
|
@@ -39,7 +41,7 @@ export type SendMessageInput = {
|
|
|
39
41
|
optimisticId?: string
|
|
40
42
|
model?: string
|
|
41
43
|
effort?: string
|
|
42
|
-
|
|
44
|
+
speedMode?: SpeedMode
|
|
43
45
|
stream?: boolean
|
|
44
46
|
// Structured moi context (lib/moi-context.ts). Each harness renders and
|
|
45
47
|
// injects it its own way: Claude Code as a leading system-reminder text
|
|
@@ -81,10 +83,32 @@ export type DiscoveredWorkspaceCandidate = {
|
|
|
81
83
|
|
|
82
84
|
export type HarnessWorkspace = Pick<WorkspaceEntry, 'id' | 'path' | 'type' | 'agentId'>
|
|
83
85
|
|
|
86
|
+
export type ActionModel = 'fast' | 'normal' | 'smart'
|
|
87
|
+
|
|
88
|
+
export type HarnessActionInput<TResult = unknown, TProgress = never> = {
|
|
89
|
+
prompt: string
|
|
90
|
+
// Portable model and effort choice, resolved by each harness. Defaults to normal.
|
|
91
|
+
model?: ActionModel
|
|
92
|
+
resultSchema: ZodType<TResult>
|
|
93
|
+
signal: AbortSignal
|
|
94
|
+
} & (
|
|
95
|
+
| { progressSchema?: never; onProgress?: never }
|
|
96
|
+
| {
|
|
97
|
+
progressSchema: ZodType<TProgress>
|
|
98
|
+
onProgress: (progress: TProgress) => void | Promise<void>
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
|
|
84
102
|
export type Harness = {
|
|
85
103
|
id: WorkspaceType
|
|
86
104
|
capabilities: HarnessCapabilities
|
|
87
105
|
|
|
106
|
+
// Ephemeral read/search action without a workspace or visible chat.
|
|
107
|
+
// Validates structured output against resultSchema; callers control timeout.
|
|
108
|
+
runAction?<TResult, TProgress = never>(
|
|
109
|
+
input: HarnessActionInput<TResult, TProgress>
|
|
110
|
+
): Promise<TResult>
|
|
111
|
+
|
|
88
112
|
// -- chat lifecycle ---------------------------------------------------------
|
|
89
113
|
sendMessage(input: SendMessageInput): Promise<void>
|
|
90
114
|
interrupt(workspaceId: string, sessionId: string): Promise<void>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OnboardingAppletPlan, OnboardingIdea, OnboardingViewPlan } from '@/lib/onboarding'
|
|
2
|
+
|
|
3
|
+
function appletBrief(
|
|
4
|
+
title: string,
|
|
5
|
+
applets: (OnboardingAppletPlan | OnboardingViewPlan)[]
|
|
6
|
+
): string {
|
|
7
|
+
if (!applets.length) return `## ${title}\nNone planned.`
|
|
8
|
+
return `## ${title}\n${applets
|
|
9
|
+
.map(applet =>
|
|
10
|
+
[
|
|
11
|
+
`### ${applet.name}`,
|
|
12
|
+
...('icon' in applet ? [`Use view icon: ${applet.icon}`] : []),
|
|
13
|
+
applet.description,
|
|
14
|
+
...applet.features.map(feature => `- ${feature}`)
|
|
15
|
+
].join('\n')
|
|
16
|
+
)
|
|
17
|
+
.join('\n\n')}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function composeBuildBrief(idea: OnboardingIdea): string {
|
|
21
|
+
return [
|
|
22
|
+
`Build the Moi workspace “${idea.name}”. Start implementing this plan now.`,
|
|
23
|
+
`## Workspace\n${idea.description}\nIcon: ${idea.icon} (theme background, already configured).`,
|
|
24
|
+
`## Theme\nFont: ${idea.theme.font}\nColor: ${idea.theme.color}\nThese workspace presets are already configured; use the existing theme tokens.`,
|
|
25
|
+
appletBrief('Views', idea.views),
|
|
26
|
+
appletBrief('Overview widgets', idea.widgets),
|
|
27
|
+
'Follow the workspace instructions and use the normal Moi tools to create the views and widgets. Keep this Overview chat as the main coordination chat and use each view’s own build chat. Link to the views here so the user can follow their progress. Preserve the configured workspace name and icon. Use available data sources honestly and explain any access limitations.'
|
|
28
|
+
].join('\n\n')
|
|
29
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { IDENTITY_ICON_IDS } from '@/lib/identity-icons'
|
|
3
|
+
import { COLOR_THEMES, FONT_THEMES, type ColorTheme, type FontTheme } from '@/lib/themes'
|
|
4
|
+
import type { OnboardingIdea } from '@/lib/onboarding'
|
|
5
|
+
|
|
6
|
+
const appletPlan = z
|
|
7
|
+
.object({
|
|
8
|
+
name: z.string().trim().min(1).max(100),
|
|
9
|
+
description: z.string().trim().min(1).max(500),
|
|
10
|
+
features: z.array(z.string().trim().min(1).max(500)).min(1).max(6)
|
|
11
|
+
})
|
|
12
|
+
.strict()
|
|
13
|
+
|
|
14
|
+
const idea = z
|
|
15
|
+
.object({
|
|
16
|
+
name: z.string().trim().min(1).max(24),
|
|
17
|
+
icon: z.enum(IDENTITY_ICON_IDS),
|
|
18
|
+
theme: z
|
|
19
|
+
.object({
|
|
20
|
+
font: z.enum(Object.keys(FONT_THEMES) as FontTheme[]),
|
|
21
|
+
color: z.enum(Object.keys(COLOR_THEMES) as ColorTheme[])
|
|
22
|
+
})
|
|
23
|
+
.strict(),
|
|
24
|
+
description: z.string().trim().min(1).max(200),
|
|
25
|
+
views: z
|
|
26
|
+
.array(
|
|
27
|
+
appletPlan.extend({
|
|
28
|
+
icon: z.enum(IDENTITY_ICON_IDS)
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
.length(3),
|
|
32
|
+
widgets: z.array(appletPlan).max(4)
|
|
33
|
+
})
|
|
34
|
+
.strict()
|
|
35
|
+
|
|
36
|
+
export const onboardingIdeaSchema = idea.extend({ id: z.string().uuid() })
|
|
37
|
+
export const ideasSchema = z.object({ options: z.array(idea).length(3) }).strict()
|
|
38
|
+
export function parseIdeas(value: unknown): OnboardingIdea[] {
|
|
39
|
+
const result = ideasSchema.parse(value)
|
|
40
|
+
if (new Set(result.options.map(option => option.name.toLowerCase())).size !== 3)
|
|
41
|
+
throw new Error('The agent returned duplicate ideas. Try again')
|
|
42
|
+
if (
|
|
43
|
+
new Set(result.options.map(option => option.theme.font)).size !== 3 ||
|
|
44
|
+
new Set(result.options.map(option => option.theme.color)).size !== 3
|
|
45
|
+
)
|
|
46
|
+
throw new Error('Each idea needs a different font and color. Try again')
|
|
47
|
+
return result.options.map(option => ({ ...option, id: crypto.randomUUID() }))
|
|
48
|
+
}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { mkdir, rename, readFile } from 'node:fs/promises'
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
import { basename, join } from 'node:path'
|
|
4
|
+
import type { OnboardingJobResult, IdeaDiscovery, WorkspaceBuild } from '@/lib/onboarding'
|
|
5
|
+
import { discoveryProgressSchema } from '@/lib/onboarding'
|
|
6
|
+
import { DATA_DIR } from '../data-dir'
|
|
7
|
+
import { createdWorkspacesRoot } from '../app-config'
|
|
8
|
+
import { createWorkspaceDirectory, provisionWorkspace } from '../workspaces/init'
|
|
9
|
+
import { getWorkspace, registerWorkspace } from '../workspaces/registry'
|
|
10
|
+
import { setWorkspaceConfig } from '../workspaces/config'
|
|
11
|
+
import { saveLayout } from '../workspaces/layout'
|
|
12
|
+
import { resolveWorkspaceTheme } from '@/lib/themes'
|
|
13
|
+
import { publishEvent } from '../events'
|
|
14
|
+
import { harnessFor } from '../harness/registry'
|
|
15
|
+
import { sendWorkspaceMessage } from '../sessions/view-sessions'
|
|
16
|
+
import { resolveRenamedSession, saveSelectedSession } from '../sessions/selected'
|
|
17
|
+
import { readWorkspaceState } from '../workspace-state'
|
|
18
|
+
import { ideasSchema, onboardingIdeaSchema, parseIdeas } from './ideas'
|
|
19
|
+
import { composeBuildBrief } from './brief'
|
|
20
|
+
|
|
21
|
+
type Job = OnboardingJobResult & {
|
|
22
|
+
stage?: 'sending' | 'accepted'
|
|
23
|
+
workspacePath?: string
|
|
24
|
+
}
|
|
25
|
+
const defaults = {
|
|
26
|
+
directory: join(DATA_DIR, 'onboarding'),
|
|
27
|
+
workspacesRoot: createdWorkspacesRoot,
|
|
28
|
+
provisionWorkspace,
|
|
29
|
+
registerWorkspace,
|
|
30
|
+
getWorkspace,
|
|
31
|
+
setWorkspaceConfig,
|
|
32
|
+
publishEvent,
|
|
33
|
+
harnessFor,
|
|
34
|
+
sendWorkspaceMessage,
|
|
35
|
+
saveSelectedSession,
|
|
36
|
+
resolveRenamedSession,
|
|
37
|
+
readWorkspaceState
|
|
38
|
+
}
|
|
39
|
+
export function createOnboardingJobs(overrides: Partial<typeof defaults> = {}) {
|
|
40
|
+
const deps = { ...defaults, ...overrides }
|
|
41
|
+
const active = new Map<string, AbortController>()
|
|
42
|
+
const locks = new Map<string, Promise<unknown>>()
|
|
43
|
+
function pathFor(key: string) {
|
|
44
|
+
return join(deps.directory, `${key}.json`)
|
|
45
|
+
}
|
|
46
|
+
async function read(key: string): Promise<Job | undefined> {
|
|
47
|
+
// Read through one opened descriptor: a concurrent atomic rename must not
|
|
48
|
+
// pair cached file-size metadata with the next version's contents.
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(await readFile(pathFor(key), 'utf8')) as Job
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return undefined
|
|
53
|
+
throw error
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function write(key: string, job: Job) {
|
|
57
|
+
await mkdir(deps.directory, { recursive: true })
|
|
58
|
+
const path = pathFor(key),
|
|
59
|
+
temp = `${path}.${crypto.randomUUID()}.tmp`
|
|
60
|
+
await Bun.write(temp, JSON.stringify(job))
|
|
61
|
+
await rename(temp, path)
|
|
62
|
+
}
|
|
63
|
+
function locked<T>(key: string, fn: () => Promise<T>): Promise<T> {
|
|
64
|
+
const run = (locks.get(key) ?? Promise.resolve()).catch(() => {}).then(fn)
|
|
65
|
+
locks.set(key, run)
|
|
66
|
+
void run
|
|
67
|
+
.finally(() => {
|
|
68
|
+
if (locks.get(key) === run) locks.delete(key)
|
|
69
|
+
})
|
|
70
|
+
.catch(() => {})
|
|
71
|
+
return run
|
|
72
|
+
}
|
|
73
|
+
async function cancelIdeas(id: string) {
|
|
74
|
+
const key = id
|
|
75
|
+
return locked(key, async () => {
|
|
76
|
+
active.get(key)?.abort()
|
|
77
|
+
await write(key, { status: 'failed', error: 'Discovery cancelled' })
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
async function discoverIdeas(progress: IdeaDiscovery): Promise<Job> {
|
|
81
|
+
if (!progress.runId || !progress.harness) throw new Error('Choose an agent first')
|
|
82
|
+
const key = progress.runId
|
|
83
|
+
return locked(key, async () => {
|
|
84
|
+
const saved = await read(key)
|
|
85
|
+
if (saved) {
|
|
86
|
+
if (
|
|
87
|
+
saved.status === 'done' &&
|
|
88
|
+
!saved.ideas?.every(idea => onboardingIdeaSchema.safeParse(idea).success)
|
|
89
|
+
)
|
|
90
|
+
return { status: 'failed', error: 'These ideas use an older format. Find ideas again' }
|
|
91
|
+
if (saved.status === 'running' && !active.has(key))
|
|
92
|
+
return { status: 'failed', error: 'Discovery was interrupted. Try again' }
|
|
93
|
+
return saved
|
|
94
|
+
}
|
|
95
|
+
const harness = deps.harnessFor(progress.harness)
|
|
96
|
+
if (!harness.runAction) {
|
|
97
|
+
const failed: Job = {
|
|
98
|
+
status: 'failed',
|
|
99
|
+
error: 'This agent does not support ephemeral actions'
|
|
100
|
+
}
|
|
101
|
+
await write(key, failed)
|
|
102
|
+
return failed
|
|
103
|
+
}
|
|
104
|
+
const controller = new AbortController()
|
|
105
|
+
active.set(key, controller)
|
|
106
|
+
const initial: Job = { status: 'running' }
|
|
107
|
+
try {
|
|
108
|
+
await write(key, initial)
|
|
109
|
+
} catch (error) {
|
|
110
|
+
active.delete(key)
|
|
111
|
+
throw error
|
|
112
|
+
}
|
|
113
|
+
const timeout = setTimeout(() => controller.abort(), 180_000)
|
|
114
|
+
void Promise.resolve()
|
|
115
|
+
.then(async () => {
|
|
116
|
+
const now = Date.now()
|
|
117
|
+
const dateAgo = (days: number) =>
|
|
118
|
+
new Date(now - days * 86_400_000).toISOString().slice(0, 10)
|
|
119
|
+
const dates = `Research dates (UTC): today ${dateAgo(0)}; last 30 days start ${dateAgo(30)}; last 60 days start ${dateAgo(60)}.`
|
|
120
|
+
return harness.runAction!({
|
|
121
|
+
model: 'fast',
|
|
122
|
+
prompt: `${dates}\n\n${await Bun.file(new URL('./prompt.md', import.meta.url)).text()}`,
|
|
123
|
+
resultSchema: ideasSchema,
|
|
124
|
+
progressSchema: discoveryProgressSchema,
|
|
125
|
+
onProgress: update =>
|
|
126
|
+
locked(key, async () => {
|
|
127
|
+
const current = await read(key)
|
|
128
|
+
if (!controller.signal.aborted && current?.status === 'running')
|
|
129
|
+
await write(key, { ...current, progress: update })
|
|
130
|
+
}),
|
|
131
|
+
signal: controller.signal
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
.then(value => ({ status: 'done' as const, ideas: parseIdeas(value) }))
|
|
135
|
+
.catch(error => ({
|
|
136
|
+
status: 'failed' as const,
|
|
137
|
+
error: controller.signal.aborted
|
|
138
|
+
? 'Discovery stopped. Try again'
|
|
139
|
+
: String(error instanceof Error ? error.message : error)
|
|
140
|
+
}))
|
|
141
|
+
.then(result =>
|
|
142
|
+
locked(key, async () => {
|
|
143
|
+
if ((await read(key))?.status === 'running') await write(key, result)
|
|
144
|
+
})
|
|
145
|
+
)
|
|
146
|
+
.finally(() => {
|
|
147
|
+
clearTimeout(timeout)
|
|
148
|
+
active.delete(key)
|
|
149
|
+
})
|
|
150
|
+
.catch(error => console.error('[onboarding] could not save action result', error))
|
|
151
|
+
return initial
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function createFromIdea(progress: WorkspaceBuild, retry = false): Promise<Job> {
|
|
156
|
+
const key = progress.operationId
|
|
157
|
+
return locked(key, async () => {
|
|
158
|
+
const saved = await read(key)
|
|
159
|
+
if (saved?.status === 'done' || active.has(key)) return saved!
|
|
160
|
+
if (saved?.status === 'failed' && !retry) return saved
|
|
161
|
+
const controller = new AbortController()
|
|
162
|
+
active.set(key, controller)
|
|
163
|
+
const initial: Job = {
|
|
164
|
+
...saved,
|
|
165
|
+
status: 'running',
|
|
166
|
+
error: undefined,
|
|
167
|
+
sessionId: saved?.sessionId ?? crypto.randomUUID()
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
await write(key, initial)
|
|
171
|
+
} catch (error) {
|
|
172
|
+
active.delete(key)
|
|
173
|
+
throw error
|
|
174
|
+
}
|
|
175
|
+
void build(key, progress, initial)
|
|
176
|
+
.catch(async error => {
|
|
177
|
+
await write(key, {
|
|
178
|
+
...(await read(key)),
|
|
179
|
+
status: 'failed',
|
|
180
|
+
error: error instanceof Error ? error.message : String(error)
|
|
181
|
+
})
|
|
182
|
+
})
|
|
183
|
+
.finally(() => active.delete(key))
|
|
184
|
+
.catch(error => console.error('[onboarding] could not save workspace result', error))
|
|
185
|
+
return initial
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
async function build(key: string, progress: WorkspaceBuild, job: Job) {
|
|
189
|
+
const idea = progress.idea
|
|
190
|
+
if (!job.workspacePath) {
|
|
191
|
+
const root = deps.workspacesRoot()
|
|
192
|
+
const legacyPath = join(root, `onboarding-${key}`)
|
|
193
|
+
if (existsSync(legacyPath)) job.workspacePath = legacyPath
|
|
194
|
+
else job.workspacePath = await createWorkspaceDirectory(idea.name, root, deps.getWorkspace)
|
|
195
|
+
await write(key, job)
|
|
196
|
+
}
|
|
197
|
+
const path = job.workspacePath
|
|
198
|
+
await deps.provisionWorkspace(path, progress.harness)
|
|
199
|
+
if (!job.workspaceId) {
|
|
200
|
+
const layout = await deps.setWorkspaceConfig(path, {
|
|
201
|
+
name: idea.name,
|
|
202
|
+
icon: { type: 'glyph', value: idea.icon, background: 'theme' }
|
|
203
|
+
})
|
|
204
|
+
await saveLayout(
|
|
205
|
+
{ ...layout, theme: resolveWorkspaceTheme({ ...layout.theme, ...idea.theme }) },
|
|
206
|
+
path
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
const ws = await deps.registerWorkspace(path, {
|
|
210
|
+
id: job.workspaceId ?? basename(path),
|
|
211
|
+
type: progress.harness,
|
|
212
|
+
name: idea.name
|
|
213
|
+
})
|
|
214
|
+
job.workspaceId = ws.id
|
|
215
|
+
await write(key, job)
|
|
216
|
+
const briefPath = join(path, 'onboarding-brief.md')
|
|
217
|
+
// Reconciliation must compare against the exact message originally submitted.
|
|
218
|
+
const brief = job.stage ? await Bun.file(briefPath).text() : composeBuildBrief(idea)
|
|
219
|
+
await Bun.write(briefPath, brief)
|
|
220
|
+
deps.publishEvent({ type: 'workspaces-list:updated' })
|
|
221
|
+
const harness = deps.harnessFor(ws)
|
|
222
|
+
if (job.stage === 'sending' || job.stage === 'accepted') {
|
|
223
|
+
// The provider may have accepted before a response/save was lost. This
|
|
224
|
+
// workspace belongs to this operation; look for its initial user message.
|
|
225
|
+
const sessions = await harness.listSessions(ws)
|
|
226
|
+
for (const session of sessions) {
|
|
227
|
+
const events = await harness.sessionEvents(ws, session.sessionId)
|
|
228
|
+
if (
|
|
229
|
+
events.some(
|
|
230
|
+
event =>
|
|
231
|
+
event.kind === 'turn' &&
|
|
232
|
+
event.turn.role === 'user' &&
|
|
233
|
+
event.turn.parts.some(part => part.type === 'text' && part.text.includes(brief))
|
|
234
|
+
)
|
|
235
|
+
) {
|
|
236
|
+
job.sessionId = session.sessionId
|
|
237
|
+
await deps.saveSelectedSession(ws, session.sessionId)
|
|
238
|
+
await write(key, { ...job, status: 'done', stage: 'accepted' })
|
|
239
|
+
return
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const state = await deps.readWorkspaceState(ws)
|
|
243
|
+
job.sessionId = state.selected.overview ?? job.sessionId
|
|
244
|
+
if (harness.activeSessions().some(session => session.workspaceId === ws.id))
|
|
245
|
+
throw new Error('The agent is still starting. Wait a moment and try again')
|
|
246
|
+
// Absence from a transcript is not proof a send failed. Never replay an
|
|
247
|
+
// ambiguous send automatically; the brief stays available in the workspace.
|
|
248
|
+
if (job.stage === 'sending')
|
|
249
|
+
throw new Error(
|
|
250
|
+
'Could not confirm the first message. Check the chat before sending the saved onboarding brief'
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
const availability = await harness.authStatus?.()
|
|
254
|
+
if (availability && availability.status !== 'available')
|
|
255
|
+
throw new Error('Reconnect the agent, then retry starting the workspace')
|
|
256
|
+
await deps.saveSelectedSession(ws, job.sessionId!)
|
|
257
|
+
job.stage = 'sending'
|
|
258
|
+
await write(key, job)
|
|
259
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
260
|
+
try {
|
|
261
|
+
await Promise.race([
|
|
262
|
+
deps.sendWorkspaceMessage(ws, {
|
|
263
|
+
workspaceId: ws.id,
|
|
264
|
+
workspacePath: ws.path,
|
|
265
|
+
sessionId: job.sessionId!,
|
|
266
|
+
isNew: true,
|
|
267
|
+
content: brief,
|
|
268
|
+
optimisticId: progress.operationId,
|
|
269
|
+
context: { activeTab: { id: 'overview' } }
|
|
270
|
+
}),
|
|
271
|
+
new Promise<never>((_, reject) => {
|
|
272
|
+
timer = setTimeout(
|
|
273
|
+
() =>
|
|
274
|
+
reject(
|
|
275
|
+
new Error('Could not confirm the first message. Check the chat before retrying')
|
|
276
|
+
),
|
|
277
|
+
90_000
|
|
278
|
+
)
|
|
279
|
+
})
|
|
280
|
+
])
|
|
281
|
+
} finally {
|
|
282
|
+
clearTimeout(timer)
|
|
283
|
+
}
|
|
284
|
+
job.sessionId = deps.resolveRenamedSession(ws.id, job.sessionId!)
|
|
285
|
+
await deps.saveSelectedSession(ws, job.sessionId)
|
|
286
|
+
await write(key, { ...job, status: 'done', stage: 'accepted' })
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return { discoverIdeas, cancelIdeas, createFromIdea }
|
|
290
|
+
}
|
|
291
|
+
export const { discoverIdeas, cancelIdeas, createFromIdea } = createOnboardingJobs()
|