moi-computer 0.9.1-next.3 → 0.9.1-next.5
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/client/app/shell/SidebarLayout.tsx +15 -2
- package/client/assets/floppy-disk.webp +0 -0
- package/client/assets.d.ts +5 -0
- package/client/components/ui/button.tsx +2 -1
- package/client/features/chat/tool-group/format/claude.ts +2 -1
- package/client/features/chat/tool-group/format/codex.ts +2 -1
- package/client/features/chat/tool-group/format/hermes.ts +2 -1
- package/client/features/chat/tool-group/format/mcp.ts +7 -3
- package/client/features/chat/tool-group/format/openclaw.ts +6 -2
- package/client/features/chat/tool-group/format/shell.ts +162 -0
- package/client/features/dev/DevIndexPage.tsx +5 -0
- package/client/features/dev/DevRoutes.tsx +2 -0
- package/client/features/dev/TextureLabPage.tsx +149 -0
- package/client/features/home/HomePage.tsx +5 -5
- package/client/features/home/workspace-setup/CreateWorkspaceDialog.tsx +3 -3
- package/client/features/home/workspace-setup/DemoDialog.tsx +239 -0
- package/client/features/settings/GeneralSettings.tsx +27 -23
- package/client/features/widgets/WidgetFrame.tsx +1 -0
- package/client/index.css +2 -2
- package/client/runtime/workspace-theme.ts +12 -4
- package/client/theme.css +26 -22
- package/dist/{chunk-b959mdkj.js → chunk-0pcdwjkp.js} +1 -1
- package/dist/chunk-4xmcsjjv.js +1 -0
- package/dist/chunk-9m59hf8p.js +10 -0
- package/dist/{chunk-zbeq02yc.js → chunk-9y2zbzqz.js} +1 -1
- package/dist/chunk-dfs36zgc.js +1 -0
- package/dist/chunk-hffvjnmj.js +85 -0
- package/dist/chunk-pq93pv5z.js +1 -0
- package/dist/{chunk-zcyvyebg.js → chunk-te5sfhvx.js} +2 -2
- package/dist/chunk-xtr8kvqx.css +1 -0
- package/dist/{chunk-zfz3b4xg.js → chunk-yhj9bg1s.js} +2 -2
- package/dist/{chunk-zbt8emsw.js → chunk-yt2qjn3m.js} +2 -2
- package/dist/floppy-disk-wmjs0n85.webp +0 -0
- package/dist/index.html +1 -1
- package/lib/ids.ts +27 -0
- package/lib/themes.ts +12 -12
- package/lib/types.ts +2 -2
- package/package.json +2 -1
- package/server/api.ts +1 -1
- package/server/app-config.ts +2 -2
- package/server/bundler/build-applet.ts +2 -3
- package/server/cli.ts +23 -1
- package/server/harness/codex/client.ts +23 -0
- package/server/harness/codex/index.ts +8 -8
- package/server/harness/codex/session.ts +12 -4
- package/server/harness/codex/status.ts +31 -0
- package/server/registry.ts +37 -2
- package/client/features/home/workspace-setup/InstallMoiDialog.tsx +0 -245
- package/dist/chunk-87q78504.js +0 -1
- package/dist/chunk-8s41nd3g.js +0 -1
- package/dist/chunk-cagtq45k.js +0 -1
- package/dist/chunk-ek6zde7t.js +0 -10
- package/dist/chunk-n8tq2494.js +0 -82
- package/dist/chunk-v82nefjq.css +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{t as
|
|
1
|
+
import{Uc as H,Vc as w}from"/chunk-9y2zbzqz.js";var t=w((S,b)=>{b.exports=globalThis.__esm.react});var a=H(t(),1);function y(o){return`${location.protocol==="https:"?"wss":"ws"}://${location.host}${o}`}var i=new Set,T=new Set,$=!1,p=null,h=!1;function u(){if(p||h)return;h=!0;let o=new WebSocket(y("/api/workspaces/ws"));o.onopen=()=>{if(p=o,h=!1,$)for(let m of T)m();$=!0},o.onmessage=(m)=>{try{let g=JSON.parse(m.data);for(let x of i)x(g)}catch{}},o.onclose=()=>{if(p=null,h=!1,i.size>0)setTimeout(u,2000)},o.onerror=()=>{o.close()}}function B(o){return T.add(o),()=>{T.delete(o)}}function P(o){let m=a.useRef(o);m.current=o,a.useEffect(()=>{let g=(x)=>m.current(x);return i.add(g),u(),()=>{if(i.delete(g),i.size===0&&p)p.close(),p=null}},[])}
|
|
2
|
+
export{t as Qc,y as Rc,B as Sc,P as Tc};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{u as
|
|
1
|
+
import{Qc as w,Sc as s}from"/chunk-yhj9bg1s.js";import{Uc as q}from"/chunk-9y2zbzqz.js";var R=q(w(),1);async function i(o,t){let a=await o.text();return Error(a||t)}async function u(o,t,a="Request failed"){let n=await fetch(o,t);if(!n.ok)throw await i(n,a);return n.json()}async function T(o,t,a="Request failed"){let n=await fetch(o,t);if(!n.ok)throw await i(n,a)}function y(o,t){return{method:o,headers:{"Content-Type":"application/json"},body:t===void 0?void 0:JSON.stringify(t)}}var r={cloudDemo:!1,experiments:[],demoInstallUrl:"https://moi.computer"},d=r,e=new Set;function I(o){return e.add(o),()=>{e.delete(o)}}async function f(){try{d=await u("/api/config");for(let o of e)o()}catch{}}async function c(){await f(),s(()=>{f()})}function h(){return R.useSyncExternalStore(I,()=>d)}
|
|
2
|
+
export{u as Lc,T as Mc,y as Nc,c as Oc,h as Pc};
|
|
Binary file
|
package/dist/index.html
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
|
-
<link rel="stylesheet" crossorigin href="/chunk-
|
|
24
|
+
<link rel="stylesheet" crossorigin href="/chunk-xtr8kvqx.css"><script type="module" crossorigin src="/chunk-pq93pv5z.js"></script></head>
|
|
25
25
|
<body>
|
|
26
26
|
<div id="root"></div>
|
|
27
27
|
|
package/lib/ids.ts
CHANGED
|
@@ -8,6 +8,33 @@ const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz'
|
|
|
8
8
|
// whole life. 10 chars (~52 bits) stays collision-free at any realistic count.
|
|
9
9
|
export const newWorkspaceId = customAlphabet(ALPHABET, 10)
|
|
10
10
|
|
|
11
|
+
// Ids no workspace can hold, because a URL carrying one never reaches it:
|
|
12
|
+
// `/api/workspaces/:id` is registered after the literal collection routes, so
|
|
13
|
+
// `create`, `discover` and `order` match those instead, and `ws` is claimed by
|
|
14
|
+
// the live-event WebSocket upgrade in `server/web.ts` before Hono sees the
|
|
15
|
+
// request. A workspace registered under one of these would persist fine and
|
|
16
|
+
// then be unreachable in the app. `server/api-reserved-ids.test.ts` re-derives
|
|
17
|
+
// this list from the router so a new collection route cannot outgrow it.
|
|
18
|
+
export const RESERVED_WORKSPACE_IDS = ['create', 'discover', 'order', 'ws']
|
|
19
|
+
|
|
20
|
+
// Ids may also be chosen by hand (`moi init --id <id>`), so they are validated
|
|
21
|
+
// rather than assumed. Slightly wider than the generated alphabet — dashes and
|
|
22
|
+
// underscores read well in a URL — but never leading with a dash, so an id
|
|
23
|
+
// cannot be mistaken for a CLI flag.
|
|
24
|
+
export function validateWorkspaceId(id: string): string | null {
|
|
25
|
+
if (!id) return 'Workspace id is required'
|
|
26
|
+
if (id.length > 64) return 'Workspace id is too long (max 64 characters)'
|
|
27
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(id)) {
|
|
28
|
+
return 'Use letters, numbers, dashes and underscores, starting with a letter or number'
|
|
29
|
+
}
|
|
30
|
+
// Case-insensitive: only the exact-case spelling collides with a route, but
|
|
31
|
+
// accepting `Create` while refusing `create` reads as a bug, not a rule.
|
|
32
|
+
if (RESERVED_WORKSPACE_IDS.includes(id.toLowerCase())) {
|
|
33
|
+
return `Workspace id ${id} is reserved (${RESERVED_WORKSPACE_IDS.join(', ')})`
|
|
34
|
+
}
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
11
38
|
// Builder handles are copied onto the command line (`moi builder set …
|
|
12
39
|
// --builder <id>`), and only need to be unique among a workspace's handful of
|
|
13
40
|
// builders — so 6 chars (~31 bits) keeps the command short while staying
|
package/lib/themes.ts
CHANGED
|
@@ -104,24 +104,24 @@ const THEME_COLOR_DERIVATIONS = {
|
|
|
104
104
|
workspace: {
|
|
105
105
|
primary: primary => primary,
|
|
106
106
|
primaryForeground: primary => foregroundForPrimary(primary),
|
|
107
|
-
background: () => 'color-mix(in
|
|
108
|
-
foreground: () => 'color-mix(in
|
|
109
|
-
muted: () => 'color-mix(in
|
|
110
|
-
mutedForeground: () => 'color-mix(in
|
|
111
|
-
accent: () => 'color-mix(in
|
|
107
|
+
background: () => 'color-mix(in srgb, var(--primary) 3%, oklch(1 0 0) 97%)',
|
|
108
|
+
foreground: () => 'color-mix(in srgb, var(--primary) 20%, oklch(0 0 0) 80%)',
|
|
109
|
+
muted: () => 'color-mix(in srgb, var(--background) 97%, var(--foreground) 3%)',
|
|
110
|
+
mutedForeground: () => 'color-mix(in srgb, var(--background) 50%, var(--foreground) 50%)',
|
|
111
|
+
accent: () => 'color-mix(in srgb, var(--primary) 4%, var(--foreground) 4%)',
|
|
112
112
|
accentForeground: () => 'var(--foreground)',
|
|
113
|
-
border: () => 'color-mix(in
|
|
113
|
+
border: () => 'color-mix(in srgb, var(--foreground) 7%, transparent)'
|
|
114
114
|
},
|
|
115
115
|
widget: {
|
|
116
116
|
background: primary => primary,
|
|
117
117
|
foreground: primary => foregroundForPrimary(primary),
|
|
118
|
-
primary: () => 'color-mix(in
|
|
119
|
-
primaryForeground: () => 'color-mix(in
|
|
120
|
-
muted: () => 'color-mix(in
|
|
121
|
-
mutedForeground: () => 'color-mix(in
|
|
122
|
-
accent: () => 'color-mix(in
|
|
118
|
+
primary: () => 'color-mix(in srgb, var(--background) 3%, oklch(1 0 0) 97%)',
|
|
119
|
+
primaryForeground: () => 'color-mix(in srgb, var(--background) 20%, oklch(0 0 0) 80%)',
|
|
120
|
+
muted: () => 'color-mix(in srgb, var(--background) 97%, var(--foreground) 3%)',
|
|
121
|
+
mutedForeground: () => 'color-mix(in srgb, var(--background) 50%, var(--foreground) 50%)',
|
|
122
|
+
accent: () => 'color-mix(in srgb, var(--primary) 4%, var(--foreground) 4%)',
|
|
123
123
|
accentForeground: () => 'var(--foreground)',
|
|
124
|
-
border: () => 'color-mix(in
|
|
124
|
+
border: () => 'color-mix(in srgb, var(--foreground) 15%, transparent)'
|
|
125
125
|
}
|
|
126
126
|
} satisfies Record<ThemeColorMode, Record<string, (primary: string) => string>>
|
|
127
127
|
|
package/lib/types.ts
CHANGED
|
@@ -291,11 +291,11 @@ export type AppSettings = {
|
|
|
291
291
|
// forever. See server/app-config.ts.
|
|
292
292
|
export type ClientAppConfig = {
|
|
293
293
|
// Cloud demo deployment: workspace creation is blocked; the UI offers the
|
|
294
|
-
//
|
|
294
|
+
// cloud-demo promo dialog instead.
|
|
295
295
|
cloudDemo: boolean
|
|
296
296
|
// Enabled experimental features, checked by slug.
|
|
297
297
|
experiments: string[]
|
|
298
|
-
// Link target for the
|
|
298
|
+
// Link target for the cloud-demo promo dialog.
|
|
299
299
|
demoInstallUrl: string
|
|
300
300
|
}
|
|
301
301
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "moi-computer",
|
|
3
|
-
"version": "0.9.1-next.
|
|
3
|
+
"version": "0.9.1-next.5",
|
|
4
4
|
"description": "Local AI workspace powered by the Claude Agent SDK, Bun, React, and Tailwind. Requires Bun.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"remark-gfm": "^4.0.1",
|
|
95
95
|
"shadcn": "^4.13.0",
|
|
96
96
|
"sharp": "^0.35.1",
|
|
97
|
+
"shell-quote": "^1.10.0",
|
|
97
98
|
"sugar-high": "^1.2.1",
|
|
98
99
|
"tailwind-merge": "^3.6.0",
|
|
99
100
|
"tailwindcss": "^4.3.3",
|
package/server/api.ts
CHANGED
|
@@ -945,7 +945,7 @@ workspaces.put('/order', async c => {
|
|
|
945
945
|
|
|
946
946
|
// One message for both creation routes: in the cloud demo the instance is
|
|
947
947
|
// provisioned with its workspaces; the UI never sends these requests (it opens
|
|
948
|
-
// the
|
|
948
|
+
// the cloud demo promo dialog instead), so a 403 here means the API was called
|
|
949
949
|
// directly.
|
|
950
950
|
const DEMO_CREATE_BLOCKED = 'Workspace creation is not available in the moi demo'
|
|
951
951
|
|
package/server/app-config.ts
CHANGED
|
@@ -16,11 +16,11 @@ import { DATA_DIR } from './data-dir'
|
|
|
16
16
|
// per-key, so a broken config never takes the CLI or server down with it.
|
|
17
17
|
export type AppConfig = {
|
|
18
18
|
// Cloud demo deployment: workspace creation is blocked (UI shows the
|
|
19
|
-
//
|
|
19
|
+
// cloud-demo promo dialog instead) and `moi` system commands are disabled.
|
|
20
20
|
cloudDemo: boolean
|
|
21
21
|
// Gated experimental features, checked by slug.
|
|
22
22
|
experiments: string[]
|
|
23
|
-
// Link target for the
|
|
23
|
+
// Link target for the cloud-demo promo dialog.
|
|
24
24
|
demoInstallUrl: string
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -452,9 +452,8 @@ async function writeSyntheticTailwindCss(
|
|
|
452
452
|
// back to `@media (prefers-color-scheme: dark)`, which diverges from the
|
|
453
453
|
// host and injects OS-preference media queries into the page.
|
|
454
454
|
`@custom-variant dark (&:is(.dark *));`,
|
|
455
|
-
//
|
|
456
|
-
|
|
457
|
-
`@custom-variant dark-or-widget (&:is(.dark *, [data-widget-chrome] *));`,
|
|
455
|
+
// Dark themes and vivid surfaces use the stronger texture treatment.
|
|
456
|
+
`@custom-variant dark-or-vivid (&:is(.dark *, [data-vivid], [data-vivid] *));`,
|
|
458
457
|
`@source "${sourceDir}";`
|
|
459
458
|
].join('\n')
|
|
460
459
|
await Bun.write(cssPath, contents)
|
package/server/cli.ts
CHANGED
|
@@ -58,7 +58,12 @@ import {
|
|
|
58
58
|
matchHermesProfile
|
|
59
59
|
} from './harness/hermes/discovery'
|
|
60
60
|
import { type OpenClawAgent, discoverOpenClawAgents } from './harness/openclaw/discovery'
|
|
61
|
-
import {
|
|
61
|
+
import {
|
|
62
|
+
assertWorkspaceIdAvailable,
|
|
63
|
+
liftToWorkspaceRoot,
|
|
64
|
+
listWorkspaces,
|
|
65
|
+
registerWorkspace
|
|
66
|
+
} from './registry'
|
|
62
67
|
import { serverCwd } from './server-cwd'
|
|
63
68
|
import {
|
|
64
69
|
isBehind,
|
|
@@ -324,6 +329,11 @@ const init = defineCommand({
|
|
|
324
329
|
type: 'boolean',
|
|
325
330
|
default: false,
|
|
326
331
|
description: 'Start the web server if not already running'
|
|
332
|
+
},
|
|
333
|
+
id: {
|
|
334
|
+
type: 'string',
|
|
335
|
+
description:
|
|
336
|
+
'Register under this id instead of a generated one — fails if the workspace is already registered'
|
|
327
337
|
}
|
|
328
338
|
},
|
|
329
339
|
async run({ args }) {
|
|
@@ -358,6 +368,17 @@ const init = defineCommand({
|
|
|
358
368
|
)
|
|
359
369
|
}
|
|
360
370
|
|
|
371
|
+
// A chosen id is only assignable at first registration, so refuse it here —
|
|
372
|
+
// before any skills are copied or `.moi/` is scaffolded.
|
|
373
|
+
if (args.id) {
|
|
374
|
+
try {
|
|
375
|
+
await assertWorkspaceIdAvailable(target, args.id)
|
|
376
|
+
} catch (err) {
|
|
377
|
+
console.error('\n' + pc.red('✗') + ' ' + (err as Error).message + '\n')
|
|
378
|
+
process.exit(1)
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
361
382
|
const projectRoot = join(import.meta.dir, '..')
|
|
362
383
|
const isInteractive = process.stdout.isTTY
|
|
363
384
|
|
|
@@ -383,6 +404,7 @@ const init = defineCommand({
|
|
|
383
404
|
|
|
384
405
|
// Always register the workspace in the persistent registry
|
|
385
406
|
const entry = await registerWorkspace(target, {
|
|
407
|
+
...(args.id ? { id: args.id } : {}),
|
|
386
408
|
type,
|
|
387
409
|
...(agent
|
|
388
410
|
? {
|
|
@@ -44,6 +44,12 @@ export type CodexProcessInfo = {
|
|
|
44
44
|
binary: string | null
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
export type CodexProcessSnapshot = {
|
|
48
|
+
workspacePath: string
|
|
49
|
+
pid: number
|
|
50
|
+
startedAt: number
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
export function getCodexProcessInfo(workspacePath: string): Promise<CodexProcessInfo> {
|
|
48
54
|
const rec = clients.get(workspacePath)
|
|
49
55
|
const binary = findHarnessExecutable('codex')
|
|
@@ -87,11 +93,26 @@ type ClientRecord = {
|
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
const clients = new Map<string, Promise<ClientRecord>>() // key: workspacePath
|
|
96
|
+
const liveProcesses = new Map<
|
|
97
|
+
string,
|
|
98
|
+
{ proc: ReturnType<typeof Bun.spawn>; startedAt: number; isAlive: () => boolean }
|
|
99
|
+
>()
|
|
100
|
+
|
|
101
|
+
export function getCodexProcessSnapshot(): CodexProcessSnapshot[] {
|
|
102
|
+
return [...liveProcesses.entries()]
|
|
103
|
+
.filter(([, process]) => process.isAlive())
|
|
104
|
+
.map(([workspacePath, process]) => ({
|
|
105
|
+
workspacePath,
|
|
106
|
+
pid: process.proc.pid,
|
|
107
|
+
startedAt: process.startedAt
|
|
108
|
+
}))
|
|
109
|
+
}
|
|
90
110
|
|
|
91
111
|
async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
92
112
|
const bin = requireHarnessExecutable('codex')
|
|
93
113
|
|
|
94
114
|
const workspaceEnv = await resolveWorkspaceEnv(workspacePath)
|
|
115
|
+
const startedAt = Date.now()
|
|
95
116
|
const proc = Bun.spawn([bin, 'app-server'], {
|
|
96
117
|
cwd: workspacePath,
|
|
97
118
|
stdin: 'pipe',
|
|
@@ -202,6 +223,7 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
202
223
|
} finally {
|
|
203
224
|
alive = false
|
|
204
225
|
if (clients.get(workspacePath) === recordPromise) clients.delete(workspacePath)
|
|
226
|
+
if (liveProcesses.get(workspacePath)?.proc === proc) liveProcesses.delete(workspacePath)
|
|
205
227
|
for (const [, p] of pending) {
|
|
206
228
|
clearTimeout(p.timer)
|
|
207
229
|
p.reject(new Error('codex app-server exited'))
|
|
@@ -237,6 +259,7 @@ async function startClient(workspacePath: string): Promise<ClientRecord> {
|
|
|
237
259
|
}
|
|
238
260
|
const record: ClientRecord = { client, proc }
|
|
239
261
|
const recordPromise = Promise.resolve(record)
|
|
262
|
+
liveProcesses.set(workspacePath, { proc, startedAt, isAlive: client.isAlive })
|
|
240
263
|
|
|
241
264
|
void readLoop()
|
|
242
265
|
void drainStderr()
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
getCodexMcpStatus,
|
|
9
9
|
getCodexModels,
|
|
10
10
|
getCodexProcessInfo,
|
|
11
|
+
getCodexProcessSnapshot,
|
|
11
12
|
getCodexSessions,
|
|
12
13
|
getCodexThreadEvents,
|
|
13
14
|
getCodexWorkspacePreview,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
interruptCodexRun,
|
|
23
24
|
sendCodexMessage
|
|
24
25
|
} from './session'
|
|
26
|
+
import { formatCodexStatusLines } from './status'
|
|
25
27
|
|
|
26
28
|
export const codexHarness: Harness = {
|
|
27
29
|
id: 'codex',
|
|
@@ -72,12 +74,10 @@ export const codexHarness: Harness = {
|
|
|
72
74
|
debugInfo: ws => getCodexProcessInfo(ws.path),
|
|
73
75
|
wireScope: ws => ws.path,
|
|
74
76
|
|
|
75
|
-
statusLines: () =>
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
]
|
|
82
|
-
}
|
|
77
|
+
statusLines: () =>
|
|
78
|
+
formatCodexStatusLines({
|
|
79
|
+
executable: findHarnessExecutable('codex'),
|
|
80
|
+
processes: getCodexProcessSnapshot(),
|
|
81
|
+
active: getCodexActiveSessions()
|
|
82
|
+
})
|
|
83
83
|
}
|
|
@@ -108,19 +108,27 @@ function liveKey(workspaceId: string, sessionId: string): string {
|
|
|
108
108
|
return real ? recKey(workspaceId, real) : direct
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
export
|
|
111
|
+
export type CodexActiveSession = {
|
|
112
112
|
workspaceId: string
|
|
113
|
+
workspacePath: string
|
|
113
114
|
sessionId: string
|
|
114
115
|
activity: SessionActivity
|
|
115
|
-
}
|
|
116
|
-
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function getCodexActiveSessions(): CodexActiveSession[] {
|
|
119
|
+
const out: CodexActiveSession[] = []
|
|
117
120
|
for (const s of sessions.values()) {
|
|
118
121
|
// Codex never surfaces `requires-action`: approvals are designed out
|
|
119
122
|
// (APPROVAL_POLICY 'never' + transport auto-accept in client.ts). If that
|
|
120
123
|
// policy is ever relaxed, `*requestApproval` / `elicitation` server
|
|
121
124
|
// requests are the signals to map to it.
|
|
122
125
|
if (s.processing) {
|
|
123
|
-
out.push({
|
|
126
|
+
out.push({
|
|
127
|
+
workspaceId: s.workspaceId,
|
|
128
|
+
workspacePath: s.workspacePath,
|
|
129
|
+
sessionId: s.sessionId,
|
|
130
|
+
activity: 'running'
|
|
131
|
+
})
|
|
124
132
|
}
|
|
125
133
|
}
|
|
126
134
|
return out
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CodexProcessSnapshot } from './client'
|
|
2
|
+
import type { CodexActiveSession } from './session'
|
|
3
|
+
|
|
4
|
+
type CodexStatusInput = {
|
|
5
|
+
executable: string | null
|
|
6
|
+
processes: CodexProcessSnapshot[]
|
|
7
|
+
active: CodexActiveSession[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function formatCodexStatusLines({
|
|
11
|
+
executable,
|
|
12
|
+
processes,
|
|
13
|
+
active
|
|
14
|
+
}: CodexStatusInput): string[] {
|
|
15
|
+
const busyWorkspacePaths = new Set(active.map(run => run.workspacePath))
|
|
16
|
+
const busyProcesses = processes.filter(process => busyWorkspacePaths.has(process.workspacePath))
|
|
17
|
+
const processLines = processes
|
|
18
|
+
.toSorted((a, b) => a.workspacePath.localeCompare(b.workspacePath))
|
|
19
|
+
.map(process => {
|
|
20
|
+
const state = busyWorkspacePaths.has(process.workspacePath) ? '▶ busy' : '○ idle'
|
|
21
|
+
return ` ${state} ws=${process.workspacePath} pid=${process.pid}`
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return [
|
|
25
|
+
`codex executable ${executable ?? '(not found)'}`,
|
|
26
|
+
`codex app-servers ${processes.length} (${busyProcesses.length} busy, ${processes.length - busyProcesses.length} idle)`,
|
|
27
|
+
...(processLines.length ? processLines : [' (none running)']),
|
|
28
|
+
`active Codex turns ${active.length}`,
|
|
29
|
+
...active.map(run => ` ▶ busy ws=${run.workspaceId} session=${run.sessionId}`)
|
|
30
|
+
]
|
|
31
|
+
}
|
package/server/registry.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { mkdir } from 'node:fs/promises'
|
|
|
2
2
|
import { homedir } from 'node:os'
|
|
3
3
|
import { join, resolve, sep } from 'path'
|
|
4
4
|
|
|
5
|
-
import { newWorkspaceId } from '@/lib/ids'
|
|
5
|
+
import { newWorkspaceId, validateWorkspaceId } from '@/lib/ids'
|
|
6
6
|
import type { DiscoveredWorkspace, WorkspaceEntry, WorkspaceType } from '@/lib/types'
|
|
7
7
|
import { orderWorkspaceTypes } from '@/lib/workspace-types'
|
|
8
8
|
|
|
@@ -48,6 +48,9 @@ async function writeRegistry(entries: WorkspaceEntry[]): Promise<void> {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export type RegisterOptions = {
|
|
51
|
+
// Register under this id instead of a generated one. Only accepted while the
|
|
52
|
+
// workspace is unregistered — see `workspaceIdError`.
|
|
53
|
+
id?: string
|
|
51
54
|
type?: WorkspaceType
|
|
52
55
|
name?: string
|
|
53
56
|
agentId?: string
|
|
@@ -55,16 +58,48 @@ export type RegisterOptions = {
|
|
|
55
58
|
lastRunAt?: string
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
// Why a chosen id can be refused. An id is baked into `/workspace/<id>` URLs
|
|
62
|
+
// and outlives the registration, so it is assigned once: a workspace that
|
|
63
|
+
// already carries an id keeps it, and no two workspaces may share one.
|
|
64
|
+
function workspaceIdError(
|
|
65
|
+
entries: WorkspaceEntry[],
|
|
66
|
+
normalPath: string,
|
|
67
|
+
id: string
|
|
68
|
+
): string | null {
|
|
69
|
+
const invalid = validateWorkspaceId(id)
|
|
70
|
+
if (invalid) return invalid
|
|
71
|
+
const existing = entries.find(e => e.path === normalPath)
|
|
72
|
+
if (existing && existing.id !== id) {
|
|
73
|
+
return `${normalPath} is already registered with id ${existing.id}`
|
|
74
|
+
}
|
|
75
|
+
if (entries.some(e => e.id === id && e.path !== normalPath)) {
|
|
76
|
+
return `Workspace id ${id} is already taken`
|
|
77
|
+
}
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Check a chosen id against the registry without registering anything, so a
|
|
82
|
+
// caller can fail before doing expensive setup work. `registerWorkspace`
|
|
83
|
+
// re-checks, so this is a courtesy, not the enforcement point.
|
|
84
|
+
export async function assertWorkspaceIdAvailable(absPath: string, id: string): Promise<void> {
|
|
85
|
+
const error = workspaceIdError(await readRegistry(), resolve(absPath), id)
|
|
86
|
+
if (error) throw new Error(error)
|
|
87
|
+
}
|
|
88
|
+
|
|
58
89
|
export async function registerWorkspace(
|
|
59
90
|
absPath: string,
|
|
60
91
|
opts: RegisterOptions = {}
|
|
61
92
|
): Promise<WorkspaceEntry> {
|
|
62
93
|
const normalPath = resolve(absPath)
|
|
63
94
|
const entries = await readRegistry()
|
|
95
|
+
if (opts.id) {
|
|
96
|
+
const error = workspaceIdError(entries, normalPath, opts.id)
|
|
97
|
+
if (error) throw new Error(error)
|
|
98
|
+
}
|
|
64
99
|
const existing = entries.find(e => e.path === normalPath)
|
|
65
100
|
if (existing) return existing
|
|
66
101
|
const entry: WorkspaceEntry = {
|
|
67
|
-
id: newWorkspaceId(),
|
|
102
|
+
id: opts.id ?? newWorkspaceId(),
|
|
68
103
|
path: normalPath,
|
|
69
104
|
addedAt: new Date().toISOString(),
|
|
70
105
|
...(opts.type ? { type: opts.type } : {}),
|