moi-computer 0.12.1-next.2 → 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 +6 -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 +10 -0
- package/client/app/routes/workspace-route.tsx +21 -19
- package/client/app/shell/sidebar-layout.tsx +34 -53
- 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-menu.tsx +96 -0
- package/client/features/account/account-provider.tsx +142 -0
- package/client/features/account/account-test-utils.tsx +294 -0
- package/client/features/account/api.ts +142 -0
- package/client/features/account/identity.ts +23 -0
- package/client/features/app-settings/api.ts +33 -0
- package/client/features/app-settings/general-settings.tsx +39 -0
- package/client/features/app-settings/profile-settings.tsx +95 -0
- package/client/features/app-settings/settings-page.tsx +48 -0
- package/client/features/app-settings/settings-section.tsx +26 -0
- package/client/features/app-settings/users-settings.tsx +195 -0
- 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/applet-api.ts +15 -14
- package/client/features/collab/components/cursors.tsx +61 -24
- package/client/features/collab/components/presence-avatars.tsx +25 -12
- package/client/features/collab/components/presence-frame.tsx +20 -24
- package/client/features/collab/components/presence-group.tsx +15 -7
- package/client/features/collab/components/user-avatar-group.tsx +21 -8
- package/client/features/collab/components/user-avatar.tsx +38 -7
- package/client/features/collab/components/user.tsx +31 -12
- package/client/features/collab/users.ts +0 -5
- package/client/features/collab/workspace-users-menu.tsx +4 -4
- package/client/features/demo/demo-dialog.tsx +11 -3
- package/client/features/dev/collab/collab-playground.tsx +7 -7
- package/client/features/dev/collab/local-user-settings.tsx +7 -53
- 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/update/update-control.tsx +1 -1
- 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 +11 -7
- 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}/connectors-settings.tsx +3 -3
- package/client/features/{settings → workspace/settings}/environment-settings.tsx +3 -3
- package/client/features/{settings → workspace/settings}/general-settings.tsx +77 -3
- 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/lib/user-display-name.ts +6 -0
- package/client/main.tsx +4 -1
- 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 +72 -63
- 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 +164 -131
- package/server/api/onboarding.ts +46 -0
- package/server/app-config.ts +23 -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 +23 -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 -16
- package/server/workspaces/layout.ts +3 -0
- package/server/workspaces/registry.ts +58 -10
- 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-00rh9df4.js +0 -2
- package/dist/chunk-4nh7y1hq.css +0 -1
- package/dist/chunk-am4agx6v.js +0 -2
- package/dist/chunk-d7cbm65e.js +0 -2
- package/dist/chunk-hbpdv7vd.js +0 -1
- package/dist/chunk-hmka9rt5.js +0 -2
- package/dist/chunk-hvh9f5h0.js +0 -14
- package/dist/chunk-mjjregkn.js +0 -10
- package/dist/chunk-pcnahct1.js +0 -5
- package/dist/chunk-rt30jbcm.js +0 -1
- package/dist/chunk-vt6zybej.js +0 -2
- package/dist/chunk-wbkwf6cc.js +0 -68
- package/dist/chunk-xjyfyz64.js +0 -1
- package/dist/chunk-y8nbwp21.js +0 -546
- package/dist/chunk-ysfdcew7.js +0 -1
- package/lib/experimental.ts +0 -14
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +0 -157
- /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
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Moi's per-workspace state, one `state.json` per workspace id under
|
|
2
|
+
// `DATA_DIR/workspaces/`. Reads come from a write-through cache: the server is
|
|
3
|
+
// the only process that writes these files (the CLI goes through the control
|
|
4
|
+
// port), so the cache never goes stale. Writes for one workspace run one at a
|
|
5
|
+
// time, each as a synchronous change applied to a copy and saved atomically.
|
|
6
|
+
// Every saved change is published to browsers as `state:changed`.
|
|
7
|
+
import { existsSync } from 'node:fs'
|
|
8
|
+
import { readdir, rm } from 'node:fs/promises'
|
|
9
|
+
import { join } from 'node:path'
|
|
10
|
+
|
|
11
|
+
import type { WorkspaceState } from '@/lib/types'
|
|
12
|
+
import { DATA_DIR } from '../data-dir'
|
|
13
|
+
import { publishEvent } from '../events'
|
|
14
|
+
import {
|
|
15
|
+
compactWorkspaceState,
|
|
16
|
+
emptyWorkspaceState,
|
|
17
|
+
readStateFile,
|
|
18
|
+
writeStateFile,
|
|
19
|
+
WorkspaceStateVersionError,
|
|
20
|
+
type LoadedState
|
|
21
|
+
} from './file'
|
|
22
|
+
import { createKeyedLock } from './lock'
|
|
23
|
+
import type { StoredWorkspaceState, WorkspaceRef } from './types'
|
|
24
|
+
|
|
25
|
+
export { LockTimeoutError } from './lock'
|
|
26
|
+
export { WorkspaceStateVersionError } from './file'
|
|
27
|
+
export type { StoredWorkspaceState, WorkspaceRef } from './types'
|
|
28
|
+
|
|
29
|
+
const STATE_FILE = 'state.json'
|
|
30
|
+
// Long enough for a slow disk, short enough that one stuck write does not
|
|
31
|
+
// freeze the workspace's chats.
|
|
32
|
+
const LOCK_TIMEOUT_MS = 10_000
|
|
33
|
+
|
|
34
|
+
export const DEFAULT_WORKSPACE_STATE_ROOT = join(DATA_DIR, 'workspaces')
|
|
35
|
+
|
|
36
|
+
let root = DEFAULT_WORKSPACE_STATE_ROOT
|
|
37
|
+
const cache = new Map<string, Promise<LoadedState>>()
|
|
38
|
+
const withLock = createKeyedLock(LOCK_TIMEOUT_MS)
|
|
39
|
+
|
|
40
|
+
// Test seam: keep state in a scratch folder.
|
|
41
|
+
export function setWorkspaceStateRoot(dir: string): void {
|
|
42
|
+
root = dir
|
|
43
|
+
cache.clear()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function statePath(workspaceId: string): string {
|
|
47
|
+
return join(root, workspaceId, STATE_FILE)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function load(ws: WorkspaceRef): Promise<LoadedState> {
|
|
51
|
+
let loaded = cache.get(ws.id)
|
|
52
|
+
if (!loaded) {
|
|
53
|
+
const loading = readStateFile(statePath(ws.id), ws.path).then(
|
|
54
|
+
found => found ?? { state: emptyWorkspaceState(ws.path), writable: true }
|
|
55
|
+
)
|
|
56
|
+
loading.catch(() => {
|
|
57
|
+
if (cache.get(ws.id) === loading) cache.delete(ws.id)
|
|
58
|
+
})
|
|
59
|
+
cache.set(ws.id, loading)
|
|
60
|
+
loaded = loading
|
|
61
|
+
}
|
|
62
|
+
return loaded
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// A copy of the current state. Changing it changes nothing on disk.
|
|
66
|
+
export async function readWorkspaceState(ws: WorkspaceRef): Promise<StoredWorkspaceState> {
|
|
67
|
+
return structuredClone((await load(ws)).state)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The state as clients see it, without the file's bookkeeping.
|
|
71
|
+
export function toWorkspaceState(stored: StoredWorkspaceState): WorkspaceState {
|
|
72
|
+
const { version: _version, workspacePath: _workspacePath, ...state } = stored
|
|
73
|
+
return state
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function getWorkspaceState(ws: WorkspaceRef): Promise<WorkspaceState> {
|
|
77
|
+
return toWorkspaceState(await readWorkspaceState(ws))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Applies `change` to a copy of the state and saves the result in one atomic
|
|
81
|
+
// write. Keep `change` synchronous and free of I/O: it runs while every other
|
|
82
|
+
// write to this workspace waits. Throwing from it leaves the state untouched;
|
|
83
|
+
// a change that leaves the state as it was skips the write.
|
|
84
|
+
export async function updateWorkspaceState<T>(
|
|
85
|
+
ws: WorkspaceRef,
|
|
86
|
+
change: (draft: StoredWorkspaceState) => T
|
|
87
|
+
): Promise<T> {
|
|
88
|
+
return withLock(ws.id, async lease => {
|
|
89
|
+
const loaded = await load(ws)
|
|
90
|
+
const draft = structuredClone(loaded.state)
|
|
91
|
+
const result = change(draft)
|
|
92
|
+
if (result instanceof Promise)
|
|
93
|
+
throw new TypeError('Workspace state changes must be synchronous')
|
|
94
|
+
draft.workspacePath = ws.path
|
|
95
|
+
draft.revision = loaded.state.revision
|
|
96
|
+
compactWorkspaceState(draft)
|
|
97
|
+
if (JSON.stringify(draft) === JSON.stringify(loaded.state)) return result
|
|
98
|
+
if (!loaded.writable) throw new WorkspaceStateVersionError(statePath(ws.id))
|
|
99
|
+
draft.revision++
|
|
100
|
+
await writeStateFile(statePath(ws.id), draft, lease)
|
|
101
|
+
loaded.state = draft
|
|
102
|
+
publishEvent({ type: 'state:changed', workspaceId: ws.id, state: toWorkspaceState(draft) })
|
|
103
|
+
return result
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function hasWorkspaceState(workspaceId: string): boolean {
|
|
108
|
+
return existsSync(statePath(workspaceId))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function listStateIds(): Promise<string[]> {
|
|
112
|
+
try {
|
|
113
|
+
const entries = await readdir(root, { withFileTypes: true })
|
|
114
|
+
return entries.filter(entry => entry.isDirectory()).map(entry => entry.name)
|
|
115
|
+
} catch {
|
|
116
|
+
return []
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Read-only on purpose: the CLI calls this while registering a workspace, and
|
|
121
|
+
// only the server may change state files.
|
|
122
|
+
async function peekWorkspacePath(workspaceId: string): Promise<string | undefined> {
|
|
123
|
+
try {
|
|
124
|
+
const parsed: unknown = JSON.parse(await Bun.file(statePath(workspaceId)).text())
|
|
125
|
+
if (typeof parsed !== 'object' || parsed === null) return undefined
|
|
126
|
+
const { workspacePath } = parsed as { workspacePath?: unknown }
|
|
127
|
+
return typeof workspacePath === 'string' ? workspacePath : undefined
|
|
128
|
+
} catch {
|
|
129
|
+
return undefined
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The id a removed workspace had, so re-adding the same folder brings back its
|
|
134
|
+
// chats, pin and settings.
|
|
135
|
+
export async function findStateIdForPath(workspacePath: string): Promise<string | undefined> {
|
|
136
|
+
for (const id of await listStateIds()) {
|
|
137
|
+
if ((await peekWorkspacePath(id)) === workspacePath) return id
|
|
138
|
+
}
|
|
139
|
+
return undefined
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Startup housekeeping: drop temp files a killed process left behind, and the
|
|
143
|
+
// state of removed workspaces whose folders no longer exist. A removed
|
|
144
|
+
// workspace whose folder still exists keeps its state for re-adding.
|
|
145
|
+
export async function prepareWorkspaceStates(registered: readonly WorkspaceRef[]): Promise<void> {
|
|
146
|
+
const registeredIds = new Set(registered.map(ws => ws.id))
|
|
147
|
+
for (const id of await listStateIds()) {
|
|
148
|
+
const dir = join(root, id)
|
|
149
|
+
if (!registeredIds.has(id)) {
|
|
150
|
+
const workspacePath = await peekWorkspacePath(id)
|
|
151
|
+
if (workspacePath && !existsSync(workspacePath)) {
|
|
152
|
+
await rm(dir, { recursive: true, force: true })
|
|
153
|
+
continue
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const files = await readdir(dir).catch(() => [])
|
|
157
|
+
for (const file of files) {
|
|
158
|
+
if (file.startsWith(`${STATE_FILE}.`) && file.endsWith('.tmp'))
|
|
159
|
+
await rm(join(dir, file), { force: true })
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// One-time import of the pre-0.13 global stores into per-workspace state,
|
|
2
|
+
// keyed by workspace path. Imports registered workspaces only, then deletes
|
|
3
|
+
// the old files. Delete this file after v0.14.
|
|
4
|
+
import { rm } from 'node:fs/promises'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
|
|
7
|
+
import { DATA_DIR } from '../data-dir'
|
|
8
|
+
import { normalizeWorkspaceState } from './file'
|
|
9
|
+
import { hasWorkspaceState, updateWorkspaceState } from './index'
|
|
10
|
+
import type { WorkspaceRef } from './types'
|
|
11
|
+
|
|
12
|
+
type LegacySession = {
|
|
13
|
+
tabId?: string
|
|
14
|
+
config?: unknown
|
|
15
|
+
forkedFromSessionId?: string
|
|
16
|
+
forkedThroughMessageId?: string
|
|
17
|
+
forkedNoticeIds?: string[]
|
|
18
|
+
}
|
|
19
|
+
type LegacySelection = { selected?: unknown; pinned?: unknown }
|
|
20
|
+
type LegacyView = { id: string; executionSessionId?: string }
|
|
21
|
+
|
|
22
|
+
export const LEGACY_FILES = [
|
|
23
|
+
'sessions.json',
|
|
24
|
+
'session-config.json',
|
|
25
|
+
'selected-sessions.json',
|
|
26
|
+
'pending-views.json',
|
|
27
|
+
'view-builders.json'
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
function readLegacy<T>(dataDir: string, name: string): Promise<Record<string, T>> {
|
|
31
|
+
return Bun.file(join(dataDir, name))
|
|
32
|
+
.json()
|
|
33
|
+
.catch(() => ({}))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function migrateLegacyWorkspaceState(
|
|
37
|
+
workspaces: readonly WorkspaceRef[],
|
|
38
|
+
dataDir = DATA_DIR
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
const sessions = await readLegacy<Record<string, LegacySession>>(dataDir, 'sessions.json')
|
|
41
|
+
const selections = await readLegacy<LegacySelection>(dataDir, 'selected-sessions.json')
|
|
42
|
+
const pendingViews = await readLegacy<LegacyView[]>(dataDir, 'pending-views.json')
|
|
43
|
+
|
|
44
|
+
for (const ws of workspaces) {
|
|
45
|
+
if (hasWorkspaceState(ws.id)) continue
|
|
46
|
+
const state = normalizeWorkspaceState(
|
|
47
|
+
{
|
|
48
|
+
pinnedSessionId: selections[ws.path]?.pinned,
|
|
49
|
+
selected: selections[ws.path]?.selected,
|
|
50
|
+
sessions: Object.fromEntries(
|
|
51
|
+
Object.entries(sessions[ws.path] ?? {}).map(([id, session]) => [
|
|
52
|
+
id,
|
|
53
|
+
{
|
|
54
|
+
tabId: session.tabId,
|
|
55
|
+
config: session.config,
|
|
56
|
+
fork: session.forkedFromSessionId && {
|
|
57
|
+
fromSessionId: session.forkedFromSessionId,
|
|
58
|
+
throughMessageId: session.forkedThroughMessageId,
|
|
59
|
+
noticeIds: session.forkedNoticeIds
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
])
|
|
63
|
+
),
|
|
64
|
+
pendingViews: Object.fromEntries(
|
|
65
|
+
(pendingViews[ws.path] ?? []).map(({ id, executionSessionId, ...view }) => [
|
|
66
|
+
id,
|
|
67
|
+
{ ...view, buildSessionId: executionSessionId }
|
|
68
|
+
])
|
|
69
|
+
)
|
|
70
|
+
},
|
|
71
|
+
ws.path
|
|
72
|
+
)
|
|
73
|
+
await updateWorkspaceState(ws, draft => {
|
|
74
|
+
Object.assign(draft, state)
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const name of LEGACY_FILES) await rm(join(dataDir, name), { force: true })
|
|
79
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// One holder per key at a time. A holder that runs past the timeout stops
|
|
2
|
+
// blocking the queue: the next waiter starts, and the stale holder's lease
|
|
3
|
+
// reports it is no longer current so it can refuse to commit late.
|
|
4
|
+
|
|
5
|
+
export type Lease = {
|
|
6
|
+
isCurrent(): boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class LockTimeoutError extends Error {
|
|
10
|
+
constructor(key: string) {
|
|
11
|
+
super(`Lock on ${key} expired before the write could commit`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createKeyedLock(timeoutMs: number) {
|
|
16
|
+
const tails = new Map<string, Promise<void>>()
|
|
17
|
+
const owners = new Map<string, number>()
|
|
18
|
+
let lastToken = 0
|
|
19
|
+
|
|
20
|
+
return async function withLock<T>(key: string, run: (lease: Lease) => Promise<T>): Promise<T> {
|
|
21
|
+
const previous = tails.get(key) ?? Promise.resolve()
|
|
22
|
+
let release!: () => void
|
|
23
|
+
const released = new Promise<void>(resolve => (release = resolve))
|
|
24
|
+
tails.set(key, released)
|
|
25
|
+
await previous
|
|
26
|
+
|
|
27
|
+
const token = ++lastToken
|
|
28
|
+
owners.set(key, token)
|
|
29
|
+
const expiry = setTimeout(release, timeoutMs)
|
|
30
|
+
expiry.unref?.()
|
|
31
|
+
try {
|
|
32
|
+
return await run({ isCurrent: () => owners.get(key) === token })
|
|
33
|
+
} finally {
|
|
34
|
+
clearTimeout(expiry)
|
|
35
|
+
release()
|
|
36
|
+
if (tails.get(key) === released) {
|
|
37
|
+
tails.delete(key)
|
|
38
|
+
owners.delete(key)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { WorkspaceEntry, WorkspaceState } from '@/lib/types'
|
|
2
|
+
|
|
3
|
+
export const WORKSPACE_STATE_VERSION = 1
|
|
4
|
+
|
|
5
|
+
// What the store needs to find a workspace's file and stamp its folder path.
|
|
6
|
+
export type WorkspaceRef = Pick<WorkspaceEntry, 'id' | 'path'>
|
|
7
|
+
|
|
8
|
+
// `state.json` on disk: the state clients see, plus the file format version
|
|
9
|
+
// and the folder it belongs to. Chat titles and history stay in each
|
|
10
|
+
// harness's transcripts.
|
|
11
|
+
export type StoredWorkspaceState = WorkspaceState & {
|
|
12
|
+
version: typeof WORKSPACE_STATE_VERSION
|
|
13
|
+
// A re-added workspace (new registration) finds its old id through it, and
|
|
14
|
+
// startup prunes state for deleted folders.
|
|
15
|
+
workspacePath: string
|
|
16
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { loadLayout, saveLayout } from './layout'
|
|
2
|
+
import type { WorkspaceEntry, WorkspaceType } from '@/lib/types'
|
|
3
|
+
import { harnessFor } from '../harness/registry'
|
|
4
|
+
import { harnessStore } from '../harness/auth'
|
|
5
|
+
import { getWorkspaceSkillsStatus } from '../skills/update'
|
|
6
|
+
import { publishEvent } from '../events'
|
|
7
|
+
import { updateWorkspaceState } from '../workspace-state'
|
|
8
|
+
import { getWorkspace, updateWorkspaceHarness } from './registry'
|
|
9
|
+
import { HarnessTransitionError, withHarnessTransition } from './harness-transition'
|
|
10
|
+
import { installWorkspaceSkills } from '../skills/workspace'
|
|
11
|
+
|
|
12
|
+
// Keep successful preparation for this server lifetime; failed attempts can retry.
|
|
13
|
+
const preparation = new Map<string, Promise<void>>()
|
|
14
|
+
export function prepareWorkspaceHarness(ws: WorkspaceEntry): Promise<void> {
|
|
15
|
+
const key = `${ws.path}:${ws.type ?? 'claude-code'}`
|
|
16
|
+
let pending = preparation.get(key)
|
|
17
|
+
if (!pending) {
|
|
18
|
+
pending = getWorkspaceSkillsStatus(ws.path, ws.type)
|
|
19
|
+
.then(async status => {
|
|
20
|
+
if (status.skills.some(skill => !skill.installed))
|
|
21
|
+
await installWorkspaceSkills(ws.path, ws.type)
|
|
22
|
+
})
|
|
23
|
+
.catch(error => {
|
|
24
|
+
preparation.delete(key)
|
|
25
|
+
throw error
|
|
26
|
+
})
|
|
27
|
+
preparation.set(key, pending)
|
|
28
|
+
}
|
|
29
|
+
return pending
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function changeWorkspaceHarness(ws: WorkspaceEntry, type: WorkspaceType) {
|
|
33
|
+
return withHarnessTransition(ws, async () => {
|
|
34
|
+
const current = await getWorkspace(ws.id)
|
|
35
|
+
if (!current) throw new HarnessTransitionError('Workspace not found')
|
|
36
|
+
const previousType = current.type ?? 'claude-code'
|
|
37
|
+
const harness = harnessFor(current)
|
|
38
|
+
if (
|
|
39
|
+
!['claude-code', 'codex'].includes(previousType) ||
|
|
40
|
+
!['claude-code', 'codex'].includes(type)
|
|
41
|
+
)
|
|
42
|
+
throw new HarnessTransitionError('This workspace’s agent cannot be changed')
|
|
43
|
+
if (type === previousType) return current
|
|
44
|
+
if (harness.activeSessions().some(session => session.workspaceId === ws.id))
|
|
45
|
+
throw new HarnessTransitionError('Wait for the agent to finish before changing it')
|
|
46
|
+
const layoutBefore = await loadLayout(current.path)
|
|
47
|
+
const before = await updateWorkspaceState(current, state => {
|
|
48
|
+
const before = structuredClone(state)
|
|
49
|
+
state.selected = {}
|
|
50
|
+
delete state.pinnedSessionId
|
|
51
|
+
for (const view of Object.values(state.pendingViews)) {
|
|
52
|
+
delete view.buildSessionId
|
|
53
|
+
view.status = 'draft'
|
|
54
|
+
delete view.error
|
|
55
|
+
}
|
|
56
|
+
return before
|
|
57
|
+
})
|
|
58
|
+
let updated: WorkspaceEntry
|
|
59
|
+
try {
|
|
60
|
+
const layout = { ...layoutBefore }
|
|
61
|
+
delete layout.selectedModel
|
|
62
|
+
delete layout.selectedEffort
|
|
63
|
+
delete layout.selectedSpeedMode
|
|
64
|
+
await saveLayout(layout, current.path)
|
|
65
|
+
updated = await updateWorkspaceHarness(ws.id, type)
|
|
66
|
+
} catch (error) {
|
|
67
|
+
const recovery = await Promise.allSettled([
|
|
68
|
+
saveLayout(layoutBefore, current.path),
|
|
69
|
+
updateWorkspaceState(current, state => Object.assign(state, before))
|
|
70
|
+
])
|
|
71
|
+
for (const result of recovery) {
|
|
72
|
+
if (result.status === 'rejected')
|
|
73
|
+
console.error('Could not restore workspace state', result.reason)
|
|
74
|
+
}
|
|
75
|
+
throw error
|
|
76
|
+
}
|
|
77
|
+
// Capture and dispose the old runtime before allowing another transition.
|
|
78
|
+
// stopWorkspace only signals local processes; it does not wait for their exit.
|
|
79
|
+
try {
|
|
80
|
+
harness.stopWorkspace?.(current.path)
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error('Could not stop previous workspace runtime', error)
|
|
83
|
+
}
|
|
84
|
+
harnessStore.invalidate(current)
|
|
85
|
+
publishEvent({ type: 'workspace-harness:switched', workspaceId: ws.id, harness: type })
|
|
86
|
+
return updated
|
|
87
|
+
})
|
|
88
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { WorkspaceEntry } from '@/lib/types'
|
|
2
|
+
|
|
3
|
+
const operations = new Map<string, number>()
|
|
4
|
+
const switching = new Set<string>()
|
|
5
|
+
export class HarnessTransitionError extends Error {}
|
|
6
|
+
|
|
7
|
+
export function reserveWorkspaceOperation(id: string): () => void {
|
|
8
|
+
if (switching.has(id)) throw new HarnessTransitionError('Agent is changing. Try again')
|
|
9
|
+
operations.set(id, (operations.get(id) ?? 0) + 1)
|
|
10
|
+
return () => {
|
|
11
|
+
const count = (operations.get(id) ?? 1) - 1
|
|
12
|
+
if (count) operations.set(id, count)
|
|
13
|
+
else operations.delete(id)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function withHarnessTransition<T>(
|
|
18
|
+
ws: WorkspaceEntry,
|
|
19
|
+
operation: () => Promise<T>
|
|
20
|
+
): Promise<T> {
|
|
21
|
+
if (switching.has(ws.id) || operations.has(ws.id))
|
|
22
|
+
throw new HarnessTransitionError('Workspace is busy. Try again when the agent is idle')
|
|
23
|
+
switching.add(ws.id)
|
|
24
|
+
try {
|
|
25
|
+
return await operation()
|
|
26
|
+
} finally {
|
|
27
|
+
switching.delete(ws.id)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -4,16 +4,37 @@
|
|
|
4
4
|
// create) all provision through here, so a workspace set up from the UI is
|
|
5
5
|
// indistinguishable from one set up via the CLI.
|
|
6
6
|
import { mkdir } from 'node:fs/promises'
|
|
7
|
-
import { homedir } from 'node:os'
|
|
8
7
|
import { join } from 'node:path'
|
|
9
8
|
|
|
10
9
|
import type { WorkspaceType } from '@/lib/types'
|
|
11
|
-
|
|
10
|
+
import { workspaceIdFromName } from '@/lib/workspace-name'
|
|
11
|
+
import { validateWorkspaceId } from '@/lib/ids'
|
|
12
|
+
import { getWorkspace } from './registry'
|
|
12
13
|
|
|
13
|
-
import { getAppConfig } from '../app-config'
|
|
14
14
|
import { harnessFor } from '../harness/registry'
|
|
15
15
|
import { createDependencyInstallLogPath, scaffoldMoiDir } from './scaffold'
|
|
16
|
-
import {
|
|
16
|
+
import { installWorkspaceSkills } from '../skills/workspace'
|
|
17
|
+
|
|
18
|
+
// Reserve a unique folder whose basename is also its workspace ID.
|
|
19
|
+
export async function createWorkspaceDirectory(
|
|
20
|
+
name: string,
|
|
21
|
+
root: string,
|
|
22
|
+
lookup = getWorkspace
|
|
23
|
+
): Promise<string> {
|
|
24
|
+
const base = workspaceIdFromName(name)
|
|
25
|
+
await mkdir(root, { recursive: true })
|
|
26
|
+
for (let suffix = 1; ; suffix++) {
|
|
27
|
+
const id = suffix === 1 ? base : `${base}-${suffix}`
|
|
28
|
+
if (validateWorkspaceId(id) || (await lookup(id))) continue
|
|
29
|
+
const path = join(root, id)
|
|
30
|
+
try {
|
|
31
|
+
await mkdir(path)
|
|
32
|
+
return path
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
17
38
|
|
|
18
39
|
// Where each backend loads skills from — the harness owns the answer
|
|
19
40
|
// (Claude Code: `.claude/skills/`; OpenClaw: `<workspace>/skills/`; Codex:
|
|
@@ -23,14 +44,6 @@ export function skillsDirFor(workspaceRoot: string, type?: WorkspaceType): strin
|
|
|
23
44
|
return harnessFor(type).skillsDir?.(workspaceRoot) ?? join(workspaceRoot, '.claude', 'skills')
|
|
24
45
|
}
|
|
25
46
|
|
|
26
|
-
// Folder that holds workspaces created from the UI (`/workspace/create`) — a
|
|
27
|
-
// visible home-dir folder, mirroring how Cowork keeps its session folders under
|
|
28
|
-
// the user's home rather than an app-data dir. Managed machines set their own
|
|
29
|
-
// (`workspacesDir` in config.json).
|
|
30
|
-
export function createdWorkspacesRoot(): string {
|
|
31
|
-
return getAppConfig().workspacesDir ?? join(homedir(), 'moi')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
47
|
export type ProvisionResult = {
|
|
35
48
|
// Where the skills were installed (backend-dependent, see skillsDirFor).
|
|
36
49
|
skillsDir: string
|
|
@@ -42,9 +55,9 @@ export type ProvisionResult = {
|
|
|
42
55
|
installLogPath: string
|
|
43
56
|
}
|
|
44
57
|
|
|
45
|
-
// Lay down everything a workspace needs:
|
|
46
|
-
// skills
|
|
47
|
-
//
|
|
58
|
+
// Lay down everything a workspace needs: reset Claude/Codex's shared skill
|
|
59
|
+
// (or copy skills to other backends' own destinations), and bootstrap `.moi/`.
|
|
60
|
+
// Re-running refreshes skills and leaves an existing `.moi/` untouched.
|
|
48
61
|
// Registration in the workspace registry is a separate, caller-owned step.
|
|
49
62
|
export async function provisionWorkspace(
|
|
50
63
|
workspaceRoot: string,
|
|
@@ -52,7 +65,7 @@ export async function provisionWorkspace(
|
|
|
52
65
|
): Promise<ProvisionResult> {
|
|
53
66
|
const skillsDir = skillsDirFor(workspaceRoot, type)
|
|
54
67
|
await mkdir(workspaceRoot, { recursive: true })
|
|
55
|
-
await
|
|
68
|
+
await installWorkspaceSkills(workspaceRoot, type)
|
|
56
69
|
const installLogPath = createDependencyInstallLogPath()
|
|
57
70
|
const scaffold = await scaffoldMoiDir(workspaceRoot, undefined, undefined, installLogPath)
|
|
58
71
|
return { skillsDir, scaffold, installLogPath }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join } from 'path'
|
|
2
|
+
import { isSpeedMode } from '@/lib/speed-mode'
|
|
2
3
|
|
|
3
4
|
import type {
|
|
4
5
|
AppletKind,
|
|
@@ -18,6 +19,8 @@ function normalizeLayout(parsed: Record<string, unknown>): WorkspaceLayout {
|
|
|
18
19
|
layout.layoutMode = defaults.layoutMode
|
|
19
20
|
}
|
|
20
21
|
layout.tabs = normalizeWorkspaceTabs(layout.tabs)
|
|
22
|
+
if (!isSpeedMode(layout.selectedSpeedMode)) delete layout.selectedSpeedMode
|
|
23
|
+
delete layout.selectedFastMode
|
|
21
24
|
if (typeof layout.icon === 'string') {
|
|
22
25
|
layout.icon = { type: 'upload', value: layout.icon }
|
|
23
26
|
} else if (layout.icon !== undefined && !isWorkspaceIcon(layout.icon)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, realpathSync } from 'node:fs'
|
|
2
|
-
import { rename, rm } from 'node:fs/promises'
|
|
2
|
+
import { readdir, rename, rm, stat } from 'node:fs/promises'
|
|
3
3
|
import { homedir } from 'node:os'
|
|
4
4
|
import { join, resolve, sep } from 'path'
|
|
5
5
|
|
|
@@ -10,6 +10,8 @@ import { orderWorkspaceTypes } from '@/lib/workspace-types'
|
|
|
10
10
|
import { DATA_DIR } from '../data-dir'
|
|
11
11
|
import { allHarnesses } from '../harness/registry'
|
|
12
12
|
import type { DiscoveredWorkspaceCandidate } from '../harness/types'
|
|
13
|
+
import { createdWorkspacesRoot } from '../app-config'
|
|
14
|
+
import { findStateIdForPath } from '../workspace-state'
|
|
13
15
|
|
|
14
16
|
// Replace the home-dir prefix with `~` for display. Keeps the original
|
|
15
17
|
// absolute path in place; callers should put the result in `displayPath`.
|
|
@@ -70,6 +72,17 @@ function locked<T>(operation: () => Promise<T>): Promise<T> {
|
|
|
70
72
|
return run
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
// A removed workspace keeps its state folder. Re-adding the same folder takes
|
|
76
|
+
// its old id back, and with it the pinned chat, selections and chat settings.
|
|
77
|
+
async function previousWorkspaceId(
|
|
78
|
+
entries: WorkspaceEntry[],
|
|
79
|
+
normalPath: string
|
|
80
|
+
): Promise<string | undefined> {
|
|
81
|
+
const id = await findStateIdForPath(normalPath)
|
|
82
|
+
if (!id || validateWorkspaceId(id) || entries.some(e => e.id === id)) return undefined
|
|
83
|
+
return id
|
|
84
|
+
}
|
|
85
|
+
|
|
73
86
|
export type RegisterOptions = {
|
|
74
87
|
// Register under this id instead of a generated one. Only accepted while the
|
|
75
88
|
// workspace is unregistered — see `workspaceIdError`.
|
|
@@ -123,7 +136,7 @@ export async function registerWorkspace(
|
|
|
123
136
|
const existing = entries.find(e => e.path === normalPath)
|
|
124
137
|
if (existing) return existing
|
|
125
138
|
const entry: WorkspaceEntry = {
|
|
126
|
-
id: opts.id ?? newWorkspaceId(),
|
|
139
|
+
id: opts.id ?? (await previousWorkspaceId(entries, normalPath)) ?? newWorkspaceId(),
|
|
127
140
|
path: normalPath,
|
|
128
141
|
addedAt: new Date().toISOString(),
|
|
129
142
|
...(opts.type ? { type: opts.type } : {}),
|
|
@@ -216,7 +229,7 @@ export function liftToWorkspaceRoot(p: string): string {
|
|
|
216
229
|
return segments.slice(0, i).join(sep) || sep
|
|
217
230
|
}
|
|
218
231
|
|
|
219
|
-
async function
|
|
232
|
+
async function discoverHarnessWorkspaces(
|
|
220
233
|
registeredPaths: Set<string>
|
|
221
234
|
): Promise<DiscoveredWorkspaceCandidate[]> {
|
|
222
235
|
const perHarness = await Promise.all(
|
|
@@ -227,8 +240,25 @@ async function collectDiscoveredWorkspaces(
|
|
|
227
240
|
return perHarness.flat()
|
|
228
241
|
}
|
|
229
242
|
|
|
230
|
-
|
|
231
|
-
|
|
243
|
+
// Only inspect immediate children of the workspace root, never the whole disk.
|
|
244
|
+
export async function discoverWorkspaceFolders(
|
|
245
|
+
root = createdWorkspacesRoot()
|
|
246
|
+
): Promise<{ path: string }[]> {
|
|
247
|
+
const entries = await readdir(root, { withFileTypes: true }).catch(() => [])
|
|
248
|
+
const candidates = await Promise.all(
|
|
249
|
+
entries
|
|
250
|
+
.filter(entry => entry.isDirectory() || entry.isSymbolicLink())
|
|
251
|
+
.map(async entry => {
|
|
252
|
+
const path = resolve(root, entry.name)
|
|
253
|
+
const moi = await stat(join(path, '.moi')).catch(() => undefined)
|
|
254
|
+
return moi?.isDirectory() ? { path } : undefined
|
|
255
|
+
})
|
|
256
|
+
)
|
|
257
|
+
return candidates.filter(candidate => candidate !== undefined)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function mergeWorkspaceCandidates(
|
|
261
|
+
candidates: { path: string; type?: WorkspaceType }[],
|
|
232
262
|
registeredPaths: Set<string> = new Set()
|
|
233
263
|
): DiscoveredWorkspace[] {
|
|
234
264
|
const normalizedRegisteredPaths = new Set([...registeredPaths].map(path => resolve(path)))
|
|
@@ -238,7 +268,7 @@ export function groupDiscoveredWorkspaces(
|
|
|
238
268
|
const path = resolve(candidate.path)
|
|
239
269
|
if (normalizedRegisteredPaths.has(path)) continue
|
|
240
270
|
const types = byPath.get(path) ?? new Set<WorkspaceType>()
|
|
241
|
-
types.add(candidate.type)
|
|
271
|
+
if (candidate.type) types.add(candidate.type)
|
|
242
272
|
byPath.set(path, types)
|
|
243
273
|
}
|
|
244
274
|
|
|
@@ -248,10 +278,28 @@ export function groupDiscoveredWorkspaces(
|
|
|
248
278
|
}))
|
|
249
279
|
}
|
|
250
280
|
|
|
251
|
-
//
|
|
252
|
-
// then combine providers that claim the same normalized folder.
|
|
281
|
+
// Combine agent history with Moi folders that may not have any chats yet.
|
|
253
282
|
export async function discoverWorkspaces(): Promise<DiscoveredWorkspace[]> {
|
|
254
283
|
const registeredPaths = new Set((await readRegistry()).map(e => e.path))
|
|
255
|
-
const
|
|
256
|
-
|
|
284
|
+
const [harnessWorkspaces, workspaceFolders] = await Promise.all([
|
|
285
|
+
discoverHarnessWorkspaces(registeredPaths),
|
|
286
|
+
discoverWorkspaceFolders()
|
|
287
|
+
])
|
|
288
|
+
return mergeWorkspaceCandidates([...harnessWorkspaces, ...workspaceFolders], registeredPaths).map(
|
|
289
|
+
withDisplayPath
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export async function updateWorkspaceHarness(
|
|
294
|
+
id: string,
|
|
295
|
+
type: WorkspaceType
|
|
296
|
+
): Promise<WorkspaceEntry> {
|
|
297
|
+
return locked(async () => {
|
|
298
|
+
const entries = await readRegistry()
|
|
299
|
+
const entry = entries.find(entry => entry.id === id)
|
|
300
|
+
if (!entry) throw new Error('Workspace not found')
|
|
301
|
+
entry.type = type
|
|
302
|
+
await writeRegistry(entries)
|
|
303
|
+
return withDisplayPath(entry)
|
|
304
|
+
})
|
|
257
305
|
}
|
|
@@ -343,8 +343,7 @@ moi views set <view-id> --title "<title>" --icon <icon-id>
|
|
|
343
343
|
Choose from the available view icons in the hidden context when that list is present. Then write
|
|
344
344
|
`.moi/views/<view-id>.tsx` and use the same title and icon in its config. Run
|
|
345
345
|
`moi check --only views/<view-id>` before `moi bundle --only views/<view-id>`. A successful bundle
|
|
346
|
-
replaces the pending screen in the same tab.
|
|
347
|
-
`moi:/views/<view-id>` link.
|
|
346
|
+
replaces the pending screen in the same tab.
|
|
348
347
|
|
|
349
348
|
### Styling and UI components
|
|
350
349
|
|
|
@@ -453,8 +452,11 @@ After the final successful checks, hand off the result according to the task:
|
|
|
453
452
|
|
|
454
453
|
- After building or editing a widget, run `moi navigate 'moi:/overview'`.
|
|
455
454
|
- After editing an existing view, run `moi navigate 'moi:/views/<view-id>'`.
|
|
456
|
-
- After a pending view build, keep the current tab open
|
|
457
|
-
|
|
455
|
+
- After a pending view build, keep the current tab open.
|
|
456
|
+
|
|
457
|
+
Use the chat's owning tab from the hidden context to decide whether a view link is useful.
|
|
458
|
+
In a view's own chat, summarize the result without linking back to that same view. Include
|
|
459
|
+
`moi:/views/<view-id>` links when replying from Overview or pointing to another view.
|
|
458
460
|
|
|
459
461
|
Keep the final reply brief and user-facing. Do not include file or storage links, file paths, or
|
|
460
462
|
bundle, test, and runtime-log summaries.
|
|
@@ -520,4 +522,4 @@ This skill is installed with Moi (via the CLI or the UI) and can fall behind whe
|
|
|
520
522
|
- **Then** — if you updated, mention it.
|
|
521
523
|
|
|
522
524
|
<!-- moi skill version marker — read by `moi skill` to detect drift; do not edit by hand -->
|
|
523
|
-
<moi-skill version="0.20.
|
|
525
|
+
<moi-skill version="0.20.1" />
|