moi-computer 0.12.0 → 0.12.1-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/client/AGENTS.md +2 -2
- package/client/api/app-ui-keys.ts +1 -1
- package/client/api/workspace-keys.ts +1 -3
- package/client/app/routes/WorkspaceRoute.tsx +2 -8
- package/client/features/applets/applet-runtime.ts +11 -13
- package/client/features/chat/ChatPanel.tsx +70 -49
- package/client/features/chat/ChatPopup.tsx +81 -8
- package/client/features/chat/applet-chat-intents.ts +31 -12
- package/client/features/chat/chat-send.ts +33 -1
- package/client/features/chat/chat-store.ts +10 -0
- package/client/features/chat/composer/ChatComposer.tsx +24 -27
- package/client/features/chat/composer/ModelPicker.tsx +3 -3
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +3 -3
- package/client/features/chat/connection/chat-frames.ts +14 -7
- package/client/features/chat/messages/ChatEmptyState.tsx +33 -19
- package/client/features/chat/messages/MarkdownContent.tsx +3 -3
- package/client/features/chat/messages/fork-history.ts +14 -0
- package/client/features/chat/sessions/ChatSelector.tsx +138 -79
- package/client/features/chat/sessions/api.ts +109 -19
- package/client/features/chat/sessions/browser-tab-state.ts +30 -7
- package/client/features/chat/sessions/useSelectedSession.ts +217 -51
- package/client/features/chat/useChat.ts +43 -45
- package/client/features/collab/client.ts +10 -11
- package/client/features/collab/hooks.tsx +6 -11
- package/client/features/collab/host-state.ts +57 -128
- package/client/features/collab/provider.tsx +3 -3
- package/client/features/collab/testing/fake-engine.ts +6 -27
- package/client/features/collab/workspace-users-menu.tsx +3 -7
- package/client/features/drawings/{useViewBuilderSketch.ts → useViewSketch.ts} +7 -7
- package/client/features/home/HomePage.tsx +2 -2
- package/client/features/overview/Overview.tsx +3 -6
- package/client/features/overview/default/ViewsWidget.tsx +5 -12
- package/client/features/overview/default/registry.tsx +2 -4
- package/client/features/views/PendingViewScreen.tsx +279 -0
- package/client/features/views/ViewManager.tsx +10 -10
- package/client/features/views/api.ts +63 -130
- package/client/features/views/useViewActions.ts +151 -0
- package/client/features/views/useViewDrafts.ts +79 -0
- package/client/features/views/view-presentation.ts +4 -5
- package/client/features/views/view-submission.ts +88 -0
- package/client/features/workspace/WorkspaceMenu.tsx +63 -0
- package/client/features/workspace/WorkspaceScreen.tsx +180 -375
- package/client/features/workspace/browser-tab-state.ts +16 -9
- package/client/features/workspace/moi-context.ts +13 -15
- package/client/features/workspace/tab-resolution.ts +16 -29
- package/client/features/workspace/useWorkspaceNavigation.ts +146 -104
- package/client/index.tsx +5 -1
- package/client/runtime/useWorkspaceEvents.ts +7 -6
- package/client/store/ui.ts +25 -29
- package/dist/chunk-1zhnhy00.js +1 -0
- package/dist/chunk-27501vke.js +1 -0
- package/dist/{chunk-jf6czgrz.js → chunk-9xtv6djt.js} +2 -2
- package/dist/chunk-am1x230f.js +2 -0
- package/dist/{chunk-nez8sdta.js → chunk-darpsw65.js} +1 -1
- package/dist/{chunk-97eg9mjn.js → chunk-gps4qc38.js} +1 -1
- package/dist/{chunk-3a48fyf7.js → chunk-hzwr8dp8.js} +4 -4
- package/dist/{chunk-efdyz6xp.js → chunk-j905va8r.js} +1 -1
- package/dist/chunk-n33w9y38.js +10 -0
- package/dist/chunk-r63ks44z.js +68 -0
- package/dist/{chunk-vfpsc75k.js → chunk-vqpkqtdr.js} +1 -1
- package/dist/chunk-wd46nk26.css +1 -0
- package/dist/chunk-xgt7vxt9.js +1 -0
- package/dist/{chunk-z3byfve5.js → chunk-yvzhwtfa.js} +2 -2
- package/dist/index.html +1 -1
- package/lib/ids.ts +2 -5
- package/lib/moi-context.ts +100 -73
- package/lib/navigation.ts +48 -87
- package/lib/session-drafts.ts +10 -0
- package/lib/types.ts +64 -31
- package/lib/view-build-directives.ts +12 -0
- package/lib/workspace-layout.ts +1 -1
- package/lib/workspace-tabs.ts +12 -7
- package/package.json +3 -1
- package/server/agent-launcher.ts +27 -0
- package/server/api.ts +119 -209
- package/server/app-config.ts +21 -2
- package/server/applets/build-worker.ts +2 -1
- package/server/applets/view-source.ts +7 -1
- package/server/cli-env.ts +72 -50
- package/server/cli.ts +101 -64
- package/server/control.ts +82 -63
- package/server/data-dir.ts +13 -0
- package/server/functions.ts +2 -1
- package/server/harness/README.md +8 -0
- package/server/harness/acp/adapter.ts +2 -2
- package/server/harness/acp/client.ts +2 -1
- package/server/harness/acp/discovery.ts +3 -3
- package/server/harness/acp/session.ts +6 -9
- package/server/harness/claude-code/adapter.ts +13 -8
- package/server/harness/claude-code/auth.ts +3 -2
- package/server/harness/claude-code/cli.ts +3 -1
- package/server/harness/claude-code/git-worktree.ts +5 -2
- package/server/harness/claude-code/index.ts +5 -0
- package/server/harness/claude-code/mcp.ts +2 -0
- package/server/harness/claude-code/models.ts +2 -0
- package/server/harness/claude-code/session.ts +5 -34
- package/server/harness/claude-code/sessions.ts +8 -12
- package/server/harness/codex/NOTES.md +23 -4
- package/server/harness/codex/adapter.ts +5 -3
- package/server/harness/codex/client.ts +13 -21
- package/server/harness/codex/index.ts +18 -0
- package/server/harness/codex/session.ts +6 -14
- package/server/harness/codex/thread-list.ts +74 -0
- package/server/harness/fork.ts +12 -0
- package/server/harness/openclaw/adapter.ts +3 -3
- package/server/harness/openclaw/session.ts +2 -30
- package/server/harness/session-title.ts +12 -3
- package/server/harness/types.ts +8 -3
- package/server/moi-scaffold.ts +2 -1
- package/server/pending-views.ts +164 -0
- package/server/registry.ts +14 -4
- package/server/selected-session.ts +91 -44
- package/server/service.ts +16 -2
- package/server/session-archive.ts +32 -0
- package/server/session-config.ts +16 -111
- package/server/session-lifecycle.ts +17 -0
- package/server/session-store.ts +127 -0
- package/server/status.ts +3 -1
- package/server/tabs.ts +7 -10
- package/server/view-sessions.ts +267 -0
- package/server/views.ts +30 -41
- package/server/web.ts +47 -45
- package/server/workspace-env.ts +27 -0
- package/server/workspace-init.ts +6 -2
- package/workspace/.claude/skills/moi-workspace/SKILL.md +49 -20
- package/workspace/.claude/skills/moi-workspace/references/COLLAB.md +2 -5
- package/client/features/views/ViewBuilder.tsx +0 -239
- package/client/features/views/useViewBuilderActions.ts +0 -103
- package/client/features/views/useViewBuilderDrafts.ts +0 -68
- package/dist/chunk-2jncyq65.js +0 -1
- package/dist/chunk-e2q5ken7.js +0 -68
- package/dist/chunk-h2kj1ysj.js +0 -1
- package/dist/chunk-nzwgm8vc.css +0 -1
- package/dist/chunk-ph0h6h86.js +0 -1
- package/dist/chunk-ryg9z3kn.js +0 -10
- package/dist/chunk-tpn177bt.js +0 -2
- package/lib/view-builder-directives.ts +0 -16
- package/server/chat-selection.ts +0 -22
- package/server/view-builders.ts +0 -453
package/server/moi-scaffold.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { appendFile, mkdir, open, stat } from 'node:fs/promises'
|
|
|
6
6
|
import { tmpdir } from 'node:os'
|
|
7
7
|
import { join, resolve, sep } from 'node:path'
|
|
8
8
|
|
|
9
|
+
import { agentCommand } from './agent-launcher'
|
|
9
10
|
import { syncAppletDeclarations } from './applets/declarations'
|
|
10
11
|
|
|
11
12
|
// Dependency set available to widgets. `react`/`react-dom` are stubs — at
|
|
@@ -54,7 +55,7 @@ async function runBunInstall(moiDir: string, logPath: string): Promise<number> {
|
|
|
54
55
|
await log.writeFile(
|
|
55
56
|
`bun install started at ${new Date().toISOString()}\nWorking directory: ${moiDir}\n\n`
|
|
56
57
|
)
|
|
57
|
-
install = Bun.spawn(['bun', 'install'], {
|
|
58
|
+
install = Bun.spawn(agentCommand(['bun', 'install']), {
|
|
58
59
|
cwd: moiDir,
|
|
59
60
|
stdin: 'ignore',
|
|
60
61
|
// Direct file descriptors keep capturing both streams after a
|
|
@@ -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
|
+
}
|
package/server/session-config.ts
CHANGED
|
@@ -1,136 +1,41 @@
|
|
|
1
|
-
import { mkdir, rename } from 'node:fs/promises'
|
|
2
|
-
import { join } from 'path'
|
|
3
|
-
|
|
4
1
|
import type { SessionConfig } from '@/lib/types'
|
|
2
|
+
import { getSessionRecords, updateSessionRecords } from './session-store'
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// Per-session model/effort/Fast-mode overrides. Stored OUTSIDE
|
|
9
|
-
// the user's workspace (no repo churn) in ONE global JSON file in moi's data
|
|
10
|
-
// dir, alongside the workspace registry. Keyed by workspace path then sessionId:
|
|
11
|
-
// { "<workspacePath>": { "<sessionId>": { model?, effort?, fastMode? } } }
|
|
12
|
-
// Path (not registry id) is the key so config survives re-registration and lines
|
|
13
|
-
// up with the SDK's path-based session storage.
|
|
14
|
-
|
|
15
|
-
// A patch may clear a field with `null` (vs `undefined`, which leaves it alone).
|
|
4
|
+
// null clears a setting; undefined leaves it unchanged.
|
|
16
5
|
export type SessionConfigPatch = {
|
|
17
6
|
model?: string | null
|
|
18
7
|
effort?: string | null
|
|
19
8
|
fastMode?: boolean | null
|
|
20
9
|
}
|
|
21
10
|
|
|
22
|
-
type Store = Record<string, Record<string, SessionConfig>>
|
|
23
|
-
|
|
24
|
-
export const DEFAULT_SESSION_CONFIG_PATH = join(DATA_DIR, 'session-config.json')
|
|
25
|
-
|
|
26
|
-
let storePath = DEFAULT_SESSION_CONFIG_PATH
|
|
27
|
-
|
|
28
|
-
// Test seam: point the store at a scratch file (mirrors registry.setRegistryPath).
|
|
29
|
-
export function setSessionConfigPath(path: string): void {
|
|
30
|
-
storePath = path
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function clean(cfg: SessionConfig | undefined): SessionConfig {
|
|
34
|
-
const out: SessionConfig = {}
|
|
35
|
-
if (typeof cfg?.model === 'string') out.model = cfg.model
|
|
36
|
-
if (typeof cfg?.effort === 'string') out.effort = cfg.effort
|
|
37
|
-
if (typeof cfg?.fastMode === 'boolean') out.fastMode = cfg.fastMode
|
|
38
|
-
return out
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function isEmpty(cfg: SessionConfig): boolean {
|
|
42
|
-
return cfg.model === undefined && cfg.effort === undefined && cfg.fastMode === undefined
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function readStoreFile(path: string): Promise<Store | null> {
|
|
46
|
-
try {
|
|
47
|
-
const parsed = JSON.parse(await Bun.file(path).text())
|
|
48
|
-
return parsed && typeof parsed === 'object' ? (parsed as Store) : {}
|
|
49
|
-
} catch {
|
|
50
|
-
return null
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function writeStore(store: Store): Promise<void> {
|
|
55
|
-
await mkdir(join(storePath, '..'), { recursive: true })
|
|
56
|
-
const tmp = `${storePath}.${process.pid}.tmp`
|
|
57
|
-
await Bun.write(tmp, JSON.stringify(store, null, 2))
|
|
58
|
-
await rename(tmp, storePath)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function readStore(): Promise<Store> {
|
|
62
|
-
return (await readStoreFile(storePath)) ?? {}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Serialize read-modify-write so concurrent save/rename calls can't clobber the
|
|
66
|
-
// single shared file (last writer would otherwise drop the other's update).
|
|
67
|
-
let writeChain: Promise<unknown> = Promise.resolve()
|
|
68
|
-
function locked<T>(fn: () => Promise<T>): Promise<T> {
|
|
69
|
-
const run = writeChain.then(fn, fn)
|
|
70
|
-
writeChain = run.catch(() => {})
|
|
71
|
-
return run
|
|
72
|
-
}
|
|
73
|
-
|
|
74
11
|
export async function getSessionConfig(
|
|
75
12
|
workspacePath: string,
|
|
76
13
|
sessionId: string
|
|
77
14
|
): Promise<SessionConfig> {
|
|
78
|
-
return
|
|
79
|
-
const store = await readStore()
|
|
80
|
-
return clean(store[workspacePath]?.[sessionId])
|
|
81
|
-
})
|
|
15
|
+
return (await getSessionRecords(workspacePath))[sessionId]?.config ?? {}
|
|
82
16
|
}
|
|
83
17
|
|
|
84
18
|
export async function hasSessionConfig(workspacePath: string, sessionId: string): Promise<boolean> {
|
|
85
|
-
return
|
|
19
|
+
return Object.keys(await getSessionConfig(workspacePath, sessionId)).length > 0
|
|
86
20
|
}
|
|
87
21
|
|
|
88
|
-
// Merge a patch over the stored config and write it back. `null` clears a field,
|
|
89
|
-
// `undefined` leaves it untouched, and a typed value sets it. An emptied entry
|
|
90
|
-
// is dropped to keep the file tidy. Returns the merged config.
|
|
91
22
|
export async function saveSessionConfig(
|
|
92
23
|
workspacePath: string,
|
|
93
24
|
sessionId: string,
|
|
94
25
|
patch: SessionConfigPatch
|
|
95
26
|
): Promise<SessionConfig> {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
for (const key of ['model', 'effort'] as const) {
|
|
101
|
-
|
|
102
|
-
if (value === undefined) continue
|
|
103
|
-
if (value === null) delete next[key]
|
|
104
|
-
else next[key] = value
|
|
27
|
+
let config: SessionConfig = {}
|
|
28
|
+
await updateSessionRecords(workspacePath, sessions => {
|
|
29
|
+
const record = (sessions[sessionId] ??= {})
|
|
30
|
+
config = { ...record.config }
|
|
31
|
+
for (const key of ['model', 'effort', 'fastMode'] as const) {
|
|
32
|
+
if (patch[key] === null) delete config[key]
|
|
105
33
|
}
|
|
106
|
-
if (patch.
|
|
107
|
-
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
else store[workspacePath] = sessions
|
|
112
|
-
await writeStore(store)
|
|
113
|
-
return next
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Move a session's config from one id to another (temp id → SDK real id on
|
|
118
|
-
// rename). Merges onto whatever the destination already holds (destination wins,
|
|
119
|
-
// so a concurrent write under the real id isn't lost) and removes the source.
|
|
120
|
-
export async function renameSessionConfig(
|
|
121
|
-
workspacePath: string,
|
|
122
|
-
from: string,
|
|
123
|
-
to: string
|
|
124
|
-
): Promise<void> {
|
|
125
|
-
if (from === to) return
|
|
126
|
-
await locked(async () => {
|
|
127
|
-
const store = await readStore()
|
|
128
|
-
const sessions = store[workspacePath]
|
|
129
|
-
const src = clean(sessions?.[from])
|
|
130
|
-
if (isEmpty(src)) return
|
|
131
|
-
sessions![to] = { ...src, ...clean(sessions![to]) }
|
|
132
|
-
delete sessions![from]
|
|
133
|
-
store[workspacePath] = sessions!
|
|
134
|
-
await writeStore(store)
|
|
34
|
+
if (typeof patch.model === 'string') config.model = patch.model
|
|
35
|
+
if (typeof patch.effort === 'string') config.effort = patch.effort
|
|
36
|
+
if (typeof patch.fastMode === 'boolean') config.fastMode = patch.fastMode
|
|
37
|
+
if (Object.keys(config).length) record.config = config
|
|
38
|
+
else delete record.config
|
|
135
39
|
})
|
|
40
|
+
return config
|
|
136
41
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { renameSessionRecord } from './session-store'
|
|
2
|
+
import { renameSelectedSession } from './selected-session'
|
|
3
|
+
import { renameViewExecutionSession } from './pending-views'
|
|
4
|
+
import { broadcast } from './state'
|
|
5
|
+
|
|
6
|
+
export async function renameSessionReferences(
|
|
7
|
+
workspaceId: string,
|
|
8
|
+
workspacePath: string,
|
|
9
|
+
from: string,
|
|
10
|
+
to: string
|
|
11
|
+
) {
|
|
12
|
+
if (from === to) return
|
|
13
|
+
await renameSessionRecord(workspacePath, from, to)
|
|
14
|
+
await renameSelectedSession(workspacePath, from, to)
|
|
15
|
+
await renameViewExecutionSession(workspaceId, workspacePath, from, to)
|
|
16
|
+
broadcast(workspaceId, { type: 'session_renamed', from, to })
|
|
17
|
+
}
|