moi-computer 0.11.1-next.5 → 0.12.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/client/AGENTS.md +2 -2
- package/client/api/app-ui-keys.ts +1 -1
- package/client/api/workspace-keys.ts +1 -3
- package/client/app/routes/WorkspaceRoute.tsx +2 -8
- package/client/features/applets/applet-runtime.ts +11 -13
- package/client/features/chat/ChatPanel.tsx +70 -49
- package/client/features/chat/ChatPopup.tsx +81 -8
- package/client/features/chat/applet-chat-intents.ts +31 -12
- package/client/features/chat/chat-send.ts +33 -1
- package/client/features/chat/chat-store.ts +10 -0
- package/client/features/chat/composer/ChatComposer.tsx +24 -27
- package/client/features/chat/composer/ModelPicker.tsx +3 -3
- package/client/features/chat/composer/attachments/draft-attachments.ts +21 -4
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
- package/client/features/chat/connection/chat-frames.ts +14 -7
- package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
- package/client/features/chat/messages/MarkdownContent.tsx +3 -3
- package/client/features/chat/messages/fork-history.ts +14 -0
- package/client/features/chat/sessions/ChatSelector.tsx +138 -79
- package/client/features/chat/sessions/api.ts +109 -19
- package/client/features/chat/sessions/browser-tab-state.ts +30 -7
- package/client/features/chat/sessions/useSelectedSession.ts +217 -51
- package/client/features/chat/useChat.ts +43 -45
- package/client/features/collab/client.ts +10 -11
- package/client/features/collab/hooks.tsx +6 -11
- package/client/features/collab/host-state.ts +57 -128
- package/client/features/collab/provider.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +6 -27
- package/client/features/collab/workspace-users-menu.tsx +3 -7
- package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
- package/client/features/home/HomePage.tsx +2 -2
- package/client/features/overview/Overview.tsx +3 -6
- package/client/features/overview/default/ViewsWidget.tsx +5 -12
- package/client/features/overview/default/registry.tsx +2 -4
- package/client/features/views/PendingViewScreen.tsx +279 -0
- package/client/features/views/ViewManager.tsx +10 -10
- package/client/features/views/api.ts +63 -130
- package/client/features/views/useViewActions.ts +151 -0
- package/client/features/views/useViewDrafts.ts +79 -0
- package/client/features/views/view-presentation.ts +4 -5
- package/client/features/views/view-submission.ts +88 -0
- package/client/features/workspace/WorkspaceMenu.tsx +63 -0
- package/client/features/workspace/WorkspaceScreen.tsx +180 -375
- package/client/features/workspace/browser-tab-state.ts +16 -9
- package/client/features/workspace/moi-context.ts +13 -15
- package/client/features/workspace/tab-resolution.ts +16 -29
- package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
- package/client/index.tsx +5 -1
- package/client/runtime/useWorkspaceEvents.ts +7 -6
- package/client/store/ui.ts +25 -29
- package/dist/chunk-1zhnhy00.js +1 -0
- package/dist/chunk-27501vke.js +1 -0
- package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
- package/dist/chunk-am1x230f.js +2 -0
- package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
- package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
- package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
- package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
- package/dist/chunk-n33w9y38.js +10 -0
- package/dist/chunk-r63ks44z.js +68 -0
- package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
- package/dist/chunk-wd46nk26.css +1 -0
- package/dist/chunk-xgt7vxt9.js +1 -0
- package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
- package/dist/index.html +1 -1
- package/lib/ids.ts +2 -5
- package/lib/moi-context.ts +100 -73
- package/lib/navigation.ts +48 -87
- package/lib/session-drafts.ts +10 -0
- package/lib/types.ts +64 -31
- package/lib/view-build-directives.ts +12 -0
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-tabs.ts +12 -7
- package/package.json +3 -1
- package/server/agent-launcher.ts +27 -0
- package/server/api.ts +119 -209
- package/server/app-config.ts +21 -2
- package/server/applets/build-worker.ts +2 -1
- package/server/applets/view-source.ts +7 -1
- package/server/cli-env.ts +72 -50
- package/server/cli.ts +127 -70
- package/server/control.ts +82 -63
- package/server/data-dir.ts +13 -0
- package/server/functions.ts +2 -1
- package/server/harness/README.md +8 -0
- package/server/harness/acp/adapter.ts +2 -2
- package/server/harness/acp/client.ts +2 -1
- package/server/harness/acp/discovery.ts +3 -3
- package/server/harness/acp/session.ts +6 -9
- package/server/harness/claude-code/adapter.ts +13 -8
- package/server/harness/claude-code/auth.ts +3 -2
- package/server/harness/claude-code/cli.ts +3 -1
- package/server/harness/claude-code/git-worktree.ts +5 -2
- package/server/harness/claude-code/index.ts +5 -0
- package/server/harness/claude-code/mcp.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -0
- package/server/harness/claude-code/session.ts +5 -34
- package/server/harness/claude-code/sessions.ts +8 -12
- package/server/harness/codex/NOTES.md +23 -4
- package/server/harness/codex/adapter.ts +5 -3
- package/server/harness/codex/client.ts +13 -21
- package/server/harness/codex/index.ts +18 -0
- package/server/harness/codex/session.ts +6 -14
- package/server/harness/codex/thread-list.ts +74 -0
- package/server/harness/fork.ts +12 -0
- package/server/harness/openclaw/adapter.ts +3 -3
- package/server/harness/openclaw/session.ts +2 -30
- package/server/harness/session-title.ts +12 -3
- package/server/harness/types.ts +8 -3
- package/server/moi-scaffold.ts +53 -20
- package/server/pending-views.ts +164 -0
- package/server/registry.ts +14 -4
- package/server/selected-session.ts +91 -44
- package/server/service.ts +16 -2
- package/server/session-archive.ts +32 -0
- package/server/session-config.ts +16 -111
- package/server/session-lifecycle.ts +17 -0
- package/server/session-store.ts +127 -0
- package/server/status.ts +3 -1
- package/server/tabs.ts +7 -10
- package/server/view-sessions.ts +267 -0
- package/server/views.ts +30 -41
- package/server/web.ts +47 -45
- package/server/workspace-env.ts +27 -0
- package/server/workspace-init.ts +12 -5
- package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
- package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
- package/client/features/views/ViewBuilder.tsx +0 -239
- package/client/features/views/useViewBuilderActions.ts +0 -103
- package/client/features/views/useViewBuilderDrafts.ts +0 -68
- package/dist/chunk-2jncyq65.js +0 -1
- package/dist/chunk-9zpvdws4.js +0 -68
- package/dist/chunk-h2kj1ysj.js +0 -1
- package/dist/chunk-hvj7tp3y.js +0 -1
- package/dist/chunk-nzwgm8vc.css +0 -1
- package/dist/chunk-ryg9z3kn.js +0 -10
- package/dist/chunk-tpn177bt.js +0 -2
- package/lib/view-builder-directives.ts +0 -16
- package/server/chat-selection.ts +0 -22
- package/server/view-builders.ts +0 -453
package/server/moi-scaffold.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// `moi openclaw init`). Creates `.moi/widgets/`, writes the widget
|
|
3
3
|
// dependency manifest, and installs dependencies — so the agent never has to
|
|
4
4
|
// bootstrap the folder itself.
|
|
5
|
-
import { mkdir, stat } from 'node:fs/promises'
|
|
5
|
+
import { appendFile, mkdir, open, stat } from 'node:fs/promises'
|
|
6
|
+
import { tmpdir } from 'node:os'
|
|
6
7
|
import { join, resolve, sep } from 'node:path'
|
|
7
8
|
|
|
9
|
+
import { agentCommand } from './agent-launcher'
|
|
8
10
|
import { syncAppletDeclarations } from './applets/declarations'
|
|
9
11
|
|
|
10
12
|
// Dependency set available to widgets. `react`/`react-dom` are stubs — at
|
|
@@ -40,23 +42,51 @@ export const MOI_PACKAGE_JSON = {
|
|
|
40
42
|
const INSTALL_WAIT_MS = 10_000
|
|
41
43
|
const INSTALL_TIMEOUT_MS = 120_000
|
|
42
44
|
|
|
43
|
-
type InstallDependencies = (moiDir: string) => Promise<number>
|
|
45
|
+
type InstallDependencies = (moiDir: string, logPath: string) => Promise<number>
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
export function createDependencyInstallLogPath(): string {
|
|
48
|
+
return join(tmpdir(), `moi-bun-install-${crypto.randomUUID()}.log`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function runBunInstall(moiDir: string, logPath: string): Promise<number> {
|
|
52
|
+
const log = await open(logPath, 'wx', 0o600)
|
|
53
|
+
let install: Bun.Subprocess<'ignore', number, number>
|
|
54
|
+
try {
|
|
55
|
+
await log.writeFile(
|
|
56
|
+
`bun install started at ${new Date().toISOString()}\nWorking directory: ${moiDir}\n\n`
|
|
57
|
+
)
|
|
58
|
+
install = Bun.spawn(agentCommand(['bun', 'install']), {
|
|
59
|
+
cwd: moiDir,
|
|
60
|
+
stdin: 'ignore',
|
|
61
|
+
// Direct file descriptors keep capturing both streams after a
|
|
62
|
+
// short-lived CLI exits; parent-owned pipes would lose that output.
|
|
63
|
+
stdout: log.fd,
|
|
64
|
+
stderr: log.fd
|
|
65
|
+
})
|
|
66
|
+
} catch (err) {
|
|
67
|
+
await log.writeFile(
|
|
68
|
+
`\nbun install error: ${err instanceof Error ? err.message : String(err)}\n`
|
|
69
|
+
)
|
|
70
|
+
return 1
|
|
71
|
+
} finally {
|
|
72
|
+
// The child owns duplicated descriptors now. Closing the parent's handle
|
|
73
|
+
// also lets a short-lived CLI exit while the install is still running.
|
|
74
|
+
await log.close()
|
|
75
|
+
}
|
|
76
|
+
// Bun.spawn's built-in timeout keeps the parent alive even after unref().
|
|
77
|
+
// Unref both the child and our timer so a short-lived CLI can exit after
|
|
78
|
+
// its brief wait. The timeout still applies while the parent is running;
|
|
79
|
+
// after parent exit the orphaned install finishes on its own.
|
|
80
|
+
const timeout = setTimeout(() => install.kill('SIGKILL'), INSTALL_TIMEOUT_MS)
|
|
81
|
+
timeout.unref()
|
|
58
82
|
install.unref()
|
|
59
|
-
|
|
83
|
+
try {
|
|
84
|
+
const code = await install.exited
|
|
85
|
+
await appendFile(logPath, `\nbun install exited with code ${code}\n`)
|
|
86
|
+
return code
|
|
87
|
+
} finally {
|
|
88
|
+
clearTimeout(timeout)
|
|
89
|
+
}
|
|
60
90
|
}
|
|
61
91
|
|
|
62
92
|
// Keep machine-local state out of workspaces that are git repos: build output,
|
|
@@ -105,7 +135,8 @@ async function isDirectory(path: string): Promise<boolean> {
|
|
|
105
135
|
export async function scaffoldMoiDir(
|
|
106
136
|
workspacePath: string,
|
|
107
137
|
installDependencies: InstallDependencies = runBunInstall,
|
|
108
|
-
installWaitMs: number = INSTALL_WAIT_MS
|
|
138
|
+
installWaitMs: number = INSTALL_WAIT_MS,
|
|
139
|
+
installLogPath: string = createDependencyInstallLogPath()
|
|
109
140
|
): Promise<'exists' | 'installing' | number> {
|
|
110
141
|
// Backstop against the nested-workspace bug: never scaffold a `.moi/` *inside*
|
|
111
142
|
// another workspace's `.moi/` (which produces the junk `.moi/.moi`). Callers
|
|
@@ -133,7 +164,7 @@ export async function scaffoldMoiDir(
|
|
|
133
164
|
await ensureMoiGitignore(workspacePath)
|
|
134
165
|
await syncAppletDeclarations(workspacePath)
|
|
135
166
|
|
|
136
|
-
const exited = installDependencies(moiDir)
|
|
167
|
+
const exited = installDependencies(moiDir, installLogPath)
|
|
137
168
|
let timer: ReturnType<typeof setTimeout> | undefined
|
|
138
169
|
const result = await Promise.race([
|
|
139
170
|
exited,
|
|
@@ -142,12 +173,14 @@ export async function scaffoldMoiDir(
|
|
|
142
173
|
clearTimeout(timer)
|
|
143
174
|
|
|
144
175
|
if (result === 'installing') {
|
|
145
|
-
console.log(
|
|
176
|
+
console.log(
|
|
177
|
+
`[scaffold] bun install in ${moiDir} still running — continuing in the background; log: ${installLogPath}`
|
|
178
|
+
)
|
|
146
179
|
exited.then(code => {
|
|
147
180
|
if (code === 0) console.log(`[scaffold] background bun install in ${moiDir} finished`)
|
|
148
181
|
else
|
|
149
182
|
console.warn(
|
|
150
|
-
`[scaffold] background bun install in ${moiDir} failed (exit ${code}) — the agent will install deps on demand`
|
|
183
|
+
`[scaffold] background bun install in ${moiDir} failed (exit ${code}) — the agent will install deps on demand; log: ${installLogPath}`
|
|
151
184
|
)
|
|
152
185
|
})
|
|
153
186
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { mkdir, rename } from 'node:fs/promises'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
|
+
import { isAppIconId } from '@/lib/app-icons'
|
|
4
|
+
import { newViewId } from '@/lib/ids'
|
|
5
|
+
import type { PendingView, WorkspaceEntry } from '@/lib/types'
|
|
6
|
+
import { DATA_DIR } from './data-dir'
|
|
7
|
+
import { publishEvent } from './events'
|
|
8
|
+
import { archiveViewSessions } from './session-archive'
|
|
9
|
+
|
|
10
|
+
type Store = Record<string, PendingView[]>
|
|
11
|
+
let storePath = join(DATA_DIR, 'pending-views.json')
|
|
12
|
+
let writes: Promise<unknown> = Promise.resolve()
|
|
13
|
+
|
|
14
|
+
export class PendingViewError extends Error {
|
|
15
|
+
constructor(
|
|
16
|
+
message: string,
|
|
17
|
+
public status: 400 | 404 | 409 = 400
|
|
18
|
+
) {
|
|
19
|
+
super(message)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function setPendingViewStorePath(path: string) {
|
|
23
|
+
storePath = path
|
|
24
|
+
}
|
|
25
|
+
async function read(): Promise<Store> {
|
|
26
|
+
const file = Bun.file(storePath)
|
|
27
|
+
return (await file.exists()) ? file.json() : {}
|
|
28
|
+
}
|
|
29
|
+
export async function listPendingViews(path: string): Promise<PendingView[]> {
|
|
30
|
+
await writes
|
|
31
|
+
return (await read())[path] ?? []
|
|
32
|
+
}
|
|
33
|
+
export async function getPendingView(path: string, id: string) {
|
|
34
|
+
return (await listPendingViews(path)).find(view => view.id === id)
|
|
35
|
+
}
|
|
36
|
+
function changed(workspaceId: string) {
|
|
37
|
+
publishEvent({ type: 'views:changed', workspaceId })
|
|
38
|
+
}
|
|
39
|
+
async function update<T>(workspaceId: string, path: string, mutate: (views: PendingView[]) => T) {
|
|
40
|
+
const run = writes.then(async () => {
|
|
41
|
+
const store = await read()
|
|
42
|
+
const views = (store[path] ??= [])
|
|
43
|
+
const result = await mutate(views)
|
|
44
|
+
if (!views.length) delete store[path]
|
|
45
|
+
await mkdir(dirname(storePath), { recursive: true })
|
|
46
|
+
const temp = `${storePath}.${process.pid}.tmp`
|
|
47
|
+
await Bun.write(temp, JSON.stringify(store, null, 2))
|
|
48
|
+
await rename(temp, storePath)
|
|
49
|
+
changed(workspaceId)
|
|
50
|
+
return result
|
|
51
|
+
})
|
|
52
|
+
writes = run.catch(() => {})
|
|
53
|
+
return run
|
|
54
|
+
}
|
|
55
|
+
export async function createPendingView(
|
|
56
|
+
workspaceId: string,
|
|
57
|
+
path: string,
|
|
58
|
+
input: Partial<Pick<PendingView, 'status' | 'requirements' | 'executionSessionId' | 'error'>> = {}
|
|
59
|
+
) {
|
|
60
|
+
return update(workspaceId, path, views => {
|
|
61
|
+
const view: PendingView = {
|
|
62
|
+
id: newViewId(),
|
|
63
|
+
status: 'draft',
|
|
64
|
+
requirements: '',
|
|
65
|
+
...input
|
|
66
|
+
}
|
|
67
|
+
views.push(view)
|
|
68
|
+
return view
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
export async function patchPendingView(
|
|
72
|
+
workspaceId: string,
|
|
73
|
+
path: string,
|
|
74
|
+
id: string,
|
|
75
|
+
patch: Partial<Pick<PendingView, 'status' | 'requirements' | 'executionSessionId' | 'error'>>,
|
|
76
|
+
expectedStatus?: PendingView['status']
|
|
77
|
+
) {
|
|
78
|
+
return update(workspaceId, path, views => {
|
|
79
|
+
const view = views.find(view => view.id === id)
|
|
80
|
+
// A bundle can complete while a send is being accepted.
|
|
81
|
+
if (!view || (expectedStatus && view.status !== expectedStatus)) return view
|
|
82
|
+
Object.assign(view, patch)
|
|
83
|
+
return view
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
export async function beginViewBuild(
|
|
87
|
+
workspaceId: string,
|
|
88
|
+
path: string,
|
|
89
|
+
id: string,
|
|
90
|
+
requirements: string,
|
|
91
|
+
sessionId: string,
|
|
92
|
+
hasAttachments: boolean
|
|
93
|
+
) {
|
|
94
|
+
if (!requirements.trim() && !hasAttachments)
|
|
95
|
+
throw new PendingViewError('View requirements or an attachment are required')
|
|
96
|
+
return update(workspaceId, path, views => {
|
|
97
|
+
const view = views.find(view => view.id === id)
|
|
98
|
+
if (!view) throw new PendingViewError('Pending view not found', 404)
|
|
99
|
+
if (view.status !== 'draft') throw new PendingViewError('View has already been submitted', 409)
|
|
100
|
+
view.status = 'starting'
|
|
101
|
+
view.requirements = requirements.trim()
|
|
102
|
+
view.executionSessionId = sessionId
|
|
103
|
+
return view
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
export async function updatePendingView(
|
|
107
|
+
workspaceId: string,
|
|
108
|
+
path: string,
|
|
109
|
+
id: string,
|
|
110
|
+
input: { requirements?: string; title?: string; icon?: string }
|
|
111
|
+
) {
|
|
112
|
+
if (input.icon !== undefined && !isAppIconId(input.icon))
|
|
113
|
+
throw new PendingViewError(`Unknown view icon id "${input.icon}"`)
|
|
114
|
+
return update(workspaceId, path, views => {
|
|
115
|
+
const view = views.find(view => view.id === id)
|
|
116
|
+
if (!view) throw new PendingViewError('Pending view not found', 404)
|
|
117
|
+
if (input.requirements !== undefined) {
|
|
118
|
+
if (view.status !== 'draft')
|
|
119
|
+
throw new PendingViewError('Submitted view input cannot be changed', 409)
|
|
120
|
+
view.requirements = input.requirements
|
|
121
|
+
}
|
|
122
|
+
if (input.title !== undefined) view.title = input.title
|
|
123
|
+
if (input.icon !== undefined) view.icon = input.icon
|
|
124
|
+
return view
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
export async function completeViewBuild(workspaceId: string, path: string, id: string) {
|
|
128
|
+
if (!(await getPendingView(path, id))) return
|
|
129
|
+
await update(workspaceId, path, views => {
|
|
130
|
+
const index = views.findIndex(view => view.id === id)
|
|
131
|
+
if (index !== -1) views.splice(index, 1)
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
export async function renameViewExecutionSession(
|
|
135
|
+
workspaceId: string,
|
|
136
|
+
path: string,
|
|
137
|
+
from: string,
|
|
138
|
+
to: string
|
|
139
|
+
) {
|
|
140
|
+
if (!(await listPendingViews(path)).some(view => view.executionSessionId === from)) return
|
|
141
|
+
await update(workspaceId, path, views => {
|
|
142
|
+
for (const view of views) {
|
|
143
|
+
if (view.executionSessionId === from) view.executionSessionId = to
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
export async function discardPendingView(
|
|
148
|
+
ws: WorkspaceEntry,
|
|
149
|
+
id: string,
|
|
150
|
+
activeSessionIds: Set<string>
|
|
151
|
+
) {
|
|
152
|
+
await update(ws.id, ws.path, async views => {
|
|
153
|
+
const index = views.findIndex(view => view.id === id)
|
|
154
|
+
if (index === -1) throw new PendingViewError('Pending view not found', 404)
|
|
155
|
+
const view = views[index]
|
|
156
|
+
if (
|
|
157
|
+
view.status === 'starting' ||
|
|
158
|
+
(view.executionSessionId && activeSessionIds.has(view.executionSessionId))
|
|
159
|
+
)
|
|
160
|
+
throw new PendingViewError('A starting or building view can only be closed', 409)
|
|
161
|
+
await archiveViewSessions(ws, id)
|
|
162
|
+
views.splice(index, 1)
|
|
163
|
+
})
|
|
164
|
+
}
|
package/server/registry.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs'
|
|
2
2
|
import { rename, rm } from 'node:fs/promises'
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
4
|
import { join, resolve, sep } from 'path'
|
|
@@ -186,10 +186,20 @@ export function findWorkspaceForPath<T extends { path: string }>(
|
|
|
186
186
|
workspaces: T[],
|
|
187
187
|
reqPath: string
|
|
188
188
|
): T | null {
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
// Shells can resolve aliases such as macOS /tmp → /private/tmp differently.
|
|
190
|
+
function canonicalPath(path: string) {
|
|
191
|
+
try {
|
|
192
|
+
return realpathSync(path)
|
|
193
|
+
} catch {
|
|
194
|
+
return resolve(path)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const normal = canonicalPath(reqPath)
|
|
198
|
+
const matches = workspaces
|
|
199
|
+
.map(workspace => ({ workspace, path: canonicalPath(workspace.path) }))
|
|
200
|
+
.filter(w => normal === w.path || normal.startsWith(w.path + sep))
|
|
191
201
|
if (matches.length === 0) return null
|
|
192
|
-
return matches.reduce((best, w) => (w.path.length > best.path.length ? w : best))
|
|
202
|
+
return matches.reduce((best, w) => (w.path.length > best.path.length ? w : best)).workspace
|
|
193
203
|
}
|
|
194
204
|
|
|
195
205
|
// If `p` lies inside a workspace's `.moi/` directory, return the workspace root
|
|
@@ -2,8 +2,12 @@ import { mkdir, rename } from 'node:fs/promises'
|
|
|
2
2
|
import { join } from 'path'
|
|
3
3
|
|
|
4
4
|
import { DATA_DIR } from './data-dir'
|
|
5
|
+
import type { WorkspaceSessionSelection, WorkspaceTabId } from '@/lib/types'
|
|
6
|
+
import { isWorkspaceTabId } from '@/lib/workspace-tabs'
|
|
5
7
|
|
|
6
|
-
type
|
|
8
|
+
type Selection = WorkspaceSessionSelection
|
|
9
|
+
type Store = Record<string, Selection>
|
|
10
|
+
const emptySelection = (): Selection => ({ selected: {}, pinned: null })
|
|
7
11
|
|
|
8
12
|
export type SelectedSessionUpdate = {
|
|
9
13
|
changed: boolean
|
|
@@ -26,8 +30,14 @@ function rememberSessionRename(workspacePath: string, from: string, to: string):
|
|
|
26
30
|
renamedSessions.set(workspacePath, renames)
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
function resolveRenamedSession(workspacePath: string, sessionId: string): string {
|
|
30
|
-
|
|
33
|
+
export function resolveRenamedSession(workspacePath: string, sessionId: string): string {
|
|
34
|
+
const renames = renamedSessions.get(workspacePath)
|
|
35
|
+
const seen = new Set<string>()
|
|
36
|
+
while (renames?.has(sessionId) && !seen.has(sessionId)) {
|
|
37
|
+
seen.add(sessionId)
|
|
38
|
+
sessionId = renames.get(sessionId)!
|
|
39
|
+
}
|
|
40
|
+
return sessionId
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
async function readStore(): Promise<Store> {
|
|
@@ -36,9 +46,17 @@ async function readStore(): Promise<Store> {
|
|
|
36
46
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {}
|
|
37
47
|
|
|
38
48
|
const store: Store = {}
|
|
39
|
-
for (const [workspacePath,
|
|
40
|
-
if (
|
|
41
|
-
store[workspacePath] =
|
|
49
|
+
for (const [workspacePath, value] of Object.entries(parsed)) {
|
|
50
|
+
if (value === null || typeof value === 'string') {
|
|
51
|
+
store[workspacePath] = { selected: value === null ? {} : { overview: value }, pinned: null }
|
|
52
|
+
} else if (value && typeof value === 'object' && 'selected' in value) {
|
|
53
|
+
const entry = value as Selection
|
|
54
|
+
store[workspacePath] = {
|
|
55
|
+
selected: Object.fromEntries(
|
|
56
|
+
Object.entries(entry.selected ?? {}).filter(([, id]) => typeof id === 'string')
|
|
57
|
+
),
|
|
58
|
+
pinned: typeof entry.pinned === 'string' ? entry.pinned : null
|
|
59
|
+
}
|
|
42
60
|
}
|
|
43
61
|
}
|
|
44
62
|
return store
|
|
@@ -63,39 +81,53 @@ function locked<T>(operation: () => Promise<T>): Promise<T> {
|
|
|
63
81
|
}
|
|
64
82
|
|
|
65
83
|
export async function getSelectedSession(
|
|
66
|
-
workspacePath: string
|
|
67
|
-
|
|
84
|
+
workspacePath: string,
|
|
85
|
+
tabId: WorkspaceTabId = 'overview'
|
|
86
|
+
): Promise<string | undefined> {
|
|
68
87
|
const store = await readStore()
|
|
69
|
-
return
|
|
70
|
-
? store[workspacePath]
|
|
71
|
-
: undefined
|
|
88
|
+
return store[workspacePath]?.selected[tabId] ?? undefined
|
|
72
89
|
}
|
|
73
90
|
|
|
74
|
-
export async function
|
|
75
|
-
workspacePath: string
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return
|
|
91
|
+
export async function getWorkspaceSessionSelection(
|
|
92
|
+
workspacePath: string
|
|
93
|
+
): Promise<WorkspaceSessionSelection> {
|
|
94
|
+
await writeChain
|
|
95
|
+
return (await readStore())[workspacePath] ?? emptySelection()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function getPinnedSession(workspacePath: string): Promise<string | null> {
|
|
99
|
+
return (await readStore())[workspacePath]?.pinned ?? null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function pinSession(workspacePath: string, sessionId: string | null): Promise<void> {
|
|
103
|
+
await locked(async () => {
|
|
79
104
|
const store = await readStore()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
105
|
+
const selection = (store[workspacePath] ??= emptySelection())
|
|
106
|
+
selection.pinned = sessionId === null ? null : resolveRenamedSession(workspacePath, sessionId)
|
|
107
|
+
await writeStore(store)
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export async function dropSessionTab(workspacePath: string, tabId: WorkspaceTabId): Promise<void> {
|
|
112
|
+
await locked(async () => {
|
|
113
|
+
const store = await readStore()
|
|
114
|
+
const selection = store[workspacePath]
|
|
115
|
+
if (!selection || !(tabId in selection.selected)) return
|
|
116
|
+
delete selection.selected[tabId]
|
|
84
117
|
await writeStore(store)
|
|
85
|
-
return fallbackSessionId
|
|
86
118
|
})
|
|
87
119
|
}
|
|
88
120
|
|
|
89
121
|
export async function saveSelectedSession(
|
|
90
122
|
workspacePath: string,
|
|
91
123
|
sessionId: string | null,
|
|
92
|
-
previousSessionId?: string | null
|
|
124
|
+
previousSessionId?: string | null,
|
|
125
|
+
tabId: WorkspaceTabId = 'overview'
|
|
93
126
|
): Promise<SelectedSessionUpdate> {
|
|
94
127
|
return locked(async () => {
|
|
95
128
|
const store = await readStore()
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
: undefined
|
|
129
|
+
const selection = (store[workspacePath] ??= emptySelection())
|
|
130
|
+
const current = selection.selected[tabId]
|
|
99
131
|
const resolvedSessionId =
|
|
100
132
|
sessionId === null ? null : resolveRenamedSession(workspacePath, sessionId)
|
|
101
133
|
const resolvedPreviousSessionId =
|
|
@@ -103,12 +135,17 @@ export async function saveSelectedSession(
|
|
|
103
135
|
? previousSessionId
|
|
104
136
|
: resolveRenamedSession(workspacePath, previousSessionId)
|
|
105
137
|
|
|
106
|
-
if (
|
|
138
|
+
if (
|
|
139
|
+
resolvedPreviousSessionId !== undefined &&
|
|
140
|
+
(current ?? null) !== resolvedPreviousSessionId
|
|
141
|
+
) {
|
|
107
142
|
return { changed: false, sessionId: current ?? null }
|
|
108
143
|
}
|
|
109
|
-
if (current
|
|
144
|
+
if ((current ?? null) === resolvedSessionId)
|
|
145
|
+
return { changed: false, sessionId: resolvedSessionId }
|
|
110
146
|
|
|
111
|
-
|
|
147
|
+
if (resolvedSessionId === null) delete selection.selected[tabId]
|
|
148
|
+
else selection.selected[tabId] = resolvedSessionId
|
|
112
149
|
await writeStore(store)
|
|
113
150
|
return { changed: true, sessionId: resolvedSessionId }
|
|
114
151
|
})
|
|
@@ -123,14 +160,19 @@ export async function renameSelectedSession(
|
|
|
123
160
|
return locked(async () => {
|
|
124
161
|
rememberSessionRename(workspacePath, from, to)
|
|
125
162
|
const store = await readStore()
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
163
|
+
const selection = (store[workspacePath] ??= emptySelection())
|
|
164
|
+
let changed = false
|
|
165
|
+
for (const tabId of Object.keys(selection.selected).filter(isWorkspaceTabId)) {
|
|
166
|
+
if (selection.selected[tabId] !== from) continue
|
|
167
|
+
selection.selected[tabId] = to
|
|
168
|
+
changed = true
|
|
169
|
+
}
|
|
170
|
+
if (selection.pinned === from) {
|
|
171
|
+
selection.pinned = to
|
|
172
|
+
changed = true
|
|
173
|
+
}
|
|
174
|
+
if (changed) await writeStore(store)
|
|
175
|
+
return { changed, sessionId: selection.selected.overview ?? null }
|
|
134
176
|
})
|
|
135
177
|
}
|
|
136
178
|
|
|
@@ -140,13 +182,18 @@ export async function clearSelectedSession(
|
|
|
140
182
|
): Promise<SelectedSessionUpdate> {
|
|
141
183
|
return locked(async () => {
|
|
142
184
|
const store = await readStore()
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
185
|
+
const selection = (store[workspacePath] ??= emptySelection())
|
|
186
|
+
let changed = false
|
|
187
|
+
for (const tabId of Object.keys(selection.selected).filter(isWorkspaceTabId)) {
|
|
188
|
+
if (selection.selected[tabId] !== sessionId) continue
|
|
189
|
+
delete selection.selected[tabId]
|
|
190
|
+
changed = true
|
|
191
|
+
}
|
|
192
|
+
if (selection.pinned === sessionId) {
|
|
193
|
+
selection.pinned = null
|
|
194
|
+
changed = true
|
|
195
|
+
}
|
|
196
|
+
if (changed) await writeStore(store)
|
|
197
|
+
return { changed, sessionId: selection.selected.overview ?? null }
|
|
151
198
|
})
|
|
152
199
|
}
|
package/server/service.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { copyFile, mkdir, readFile, rm, stat, truncate, writeFile } from 'node:f
|
|
|
21
21
|
import { homedir, userInfo } from 'node:os'
|
|
22
22
|
import { dirname, join } from 'node:path'
|
|
23
23
|
|
|
24
|
-
import { CONTROL_URL } from './constants'
|
|
24
|
+
import { CONTROL_URL, PORT } from './constants'
|
|
25
25
|
import { DATA_DIR } from './data-dir'
|
|
26
26
|
import { mergeSearchPaths } from './harness/shell-path'
|
|
27
27
|
import { PACKAGE_ROOT } from './version'
|
|
@@ -342,7 +342,20 @@ function username(): string {
|
|
|
342
342
|
|
|
343
343
|
// ---- running-server introspection -------------------------------------------
|
|
344
344
|
|
|
345
|
-
export type ServerInfo = {
|
|
345
|
+
export type ServerInfo = {
|
|
346
|
+
version: string
|
|
347
|
+
pid: number
|
|
348
|
+
port: number
|
|
349
|
+
// Set when the web side listens on a socket file (the `unixSocket` setting)
|
|
350
|
+
// instead of `port`.
|
|
351
|
+
unixSocket?: string
|
|
352
|
+
service: boolean
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// Where the running server's web side can be reached, for CLI messages.
|
|
356
|
+
export function webAddress(info: ServerInfo | null): string {
|
|
357
|
+
return info?.unixSocket ?? `http://localhost:${info?.port || PORT}`
|
|
358
|
+
}
|
|
346
359
|
|
|
347
360
|
// Ask the running server who it is over the control port. Resolves null when
|
|
348
361
|
// no server is up — or when an older server (without `server:info`) is; pair
|
|
@@ -378,6 +391,7 @@ export function queryServerInfo(timeoutMs = 1500): Promise<ServerInfo | null> {
|
|
|
378
391
|
version: data.version,
|
|
379
392
|
pid: typeof data.pid === 'number' ? data.pid : 0,
|
|
380
393
|
port: typeof data.port === 'number' ? data.port : 0,
|
|
394
|
+
unixSocket: typeof data.unixSocket === 'string' ? data.unixSocket : undefined,
|
|
381
395
|
service: data.service === true
|
|
382
396
|
})
|
|
383
397
|
} else {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { WorkspaceEntry } from '@/lib/types'
|
|
2
|
+
import { viewTabId } from '@/lib/workspace-tabs'
|
|
3
|
+
import { publishEvent } from './events'
|
|
4
|
+
import { harnessFor } from './harness/registry'
|
|
5
|
+
import { clearSelectedSession, dropSessionTab } from './selected-session'
|
|
6
|
+
import { getSessionRecords } from './session-store'
|
|
7
|
+
import { broadcast } from './state'
|
|
8
|
+
|
|
9
|
+
export async function archiveWorkspaceSession(ws: WorkspaceEntry, sessionId: string) {
|
|
10
|
+
const harness = harnessFor(ws)
|
|
11
|
+
if (!harness.archiveSession) throw new Error('Chat archiving is not supported')
|
|
12
|
+
await harness.interrupt(ws.id, sessionId)
|
|
13
|
+
await harness.archiveSession(ws, sessionId)
|
|
14
|
+
const update = await clearSelectedSession(ws.path, sessionId)
|
|
15
|
+
if (update.changed)
|
|
16
|
+
publishEvent({
|
|
17
|
+
type: 'selected-session:updated',
|
|
18
|
+
workspaceId: ws.id,
|
|
19
|
+
sessionId: update.sessionId
|
|
20
|
+
})
|
|
21
|
+
broadcast(ws.id, { type: 'session_archived', sessionId })
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function archiveViewSessions(ws: WorkspaceEntry, viewId: string) {
|
|
25
|
+
const tabId = viewTabId(viewId)
|
|
26
|
+
const records = await getSessionRecords(ws.path)
|
|
27
|
+
for (const [sessionId, record] of Object.entries(records)) {
|
|
28
|
+
if (record.tabId === tabId) await archiveWorkspaceSession(ws, sessionId)
|
|
29
|
+
}
|
|
30
|
+
await dropSessionTab(ws.path, tabId)
|
|
31
|
+
publishEvent({ type: 'selected-session:updated', workspaceId: ws.id, sessionId: null })
|
|
32
|
+
}
|