@lincyaw/cli 1.0.0-rc.80 → 1.0.0-rc.82
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/package.json +6 -6
- package/src/cli.ts +7 -3
- package/src/mcp-workspace.ts +77 -0
- package/src/messages.ts +10 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincyaw/cli",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.82",
|
|
4
4
|
"description": "The presmium command: build, dev, ir, check and serve for Presmium documents",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"micromark-extension-gfm": "3.0.0",
|
|
43
43
|
"micromark-extension-math": "3.1.0",
|
|
44
44
|
"yaml": "^2.9.1",
|
|
45
|
-
"@lincyaw/compiler": "1.0.0-rc.
|
|
46
|
-
"@lincyaw/
|
|
47
|
-
"@lincyaw/
|
|
48
|
-
"@lincyaw/
|
|
49
|
-
"@lincyaw/
|
|
45
|
+
"@lincyaw/compiler": "1.0.0-rc.82",
|
|
46
|
+
"@lincyaw/workspace": "1.0.0-rc.82",
|
|
47
|
+
"@lincyaw/skills": "1.0.0-rc.82",
|
|
48
|
+
"@lincyaw/kernel": "1.0.0-rc.82",
|
|
49
|
+
"@lincyaw/server": "1.0.0-rc.82"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/cli.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { CLI_MESSAGES, systemLocale } from './messages.ts'
|
|
|
23
23
|
import { exportScript, importScript, ScriptError } from './script.ts'
|
|
24
24
|
import { runSpeechKey, SpeechKeyFailure } from './speech-key.ts'
|
|
25
25
|
import { runVoiceover, VoiceoverFailure } from './voiceover.ts'
|
|
26
|
+
import { mcpWorkspaceSession } from './mcp-workspace.ts'
|
|
26
27
|
|
|
27
28
|
const BUNDLED = fileURLToPath(new URL('..', import.meta.url))
|
|
28
29
|
const PRESMIUM_BIN = fileURLToPath(new URL('../bin/presmium.mjs', import.meta.url))
|
|
@@ -96,7 +97,7 @@ export async function main(argv: string[], options: MainOptions = {}): Promise<n
|
|
|
96
97
|
case 'serve': return await runServeCommand(command, bundled)
|
|
97
98
|
}
|
|
98
99
|
} catch (error) {
|
|
99
|
-
process.stderr.write(`presmium: ${errorMessage(error)}\n`)
|
|
100
|
+
process.stderr.write(`presmium: ${typeof error === 'object' && error !== null && 'code' in error && error.code === 'workspace-service-already-running' ? t.workspaceServiceBusy('url' in error && typeof error.url === 'string' ? error.url : undefined) : errorMessage(error)}\n`)
|
|
100
101
|
return 2
|
|
101
102
|
}
|
|
102
103
|
}
|
|
@@ -530,8 +531,11 @@ async function runMcpCommand(argv: string[], bundled: string): Promise<number> {
|
|
|
530
531
|
return 2
|
|
531
532
|
}
|
|
532
533
|
console.log = console.info = console.debug = console.error
|
|
533
|
-
const
|
|
534
|
-
|
|
534
|
+
const workspace = mcpWorkspaceSession(bundled)
|
|
535
|
+
const { main: mcpMain } = await createJiti(import.meta.url).import<{ main(argv: string[], options: { bundled: string, startWorkspace: typeof workspace.startWorkspace }): Promise<number | undefined> }>(entry)
|
|
536
|
+
try { return await mcpMain(argv, { bundled, startWorkspace: workspace.startWorkspace }) ?? 0 }
|
|
537
|
+
catch (error) { return fail(errorMessage(error), 2) }
|
|
538
|
+
finally { await workspace.close() }
|
|
535
539
|
}
|
|
536
540
|
|
|
537
541
|
function networkLines(listenAddress: string | undefined, url: string): string {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { setTimeout as delay } from 'node:timers/promises'
|
|
4
|
+
import { findWorkspaceRoot, WORKSPACE_CONFIG } from '@lincyaw/compiler'
|
|
5
|
+
import { findWorkspaceServiceState, readServiceState, serveStateDir, tryAcquireServiceHostLease } from '@lincyaw/kernel/node'
|
|
6
|
+
import type { ApprovalKind } from '@lincyaw/kernel'
|
|
7
|
+
import type { ServiceHostLease, ServiceState } from '@lincyaw/kernel/node'
|
|
8
|
+
import { serveWorkspace } from '@lincyaw/workspace'
|
|
9
|
+
import type { WorkspaceServer } from '@lincyaw/workspace'
|
|
10
|
+
|
|
11
|
+
interface WorkspaceTarget { mcp: string, token: string, pid: number }
|
|
12
|
+
export interface McpWorkspaceConnection { target: WorkspaceTarget, close(): Promise<void> }
|
|
13
|
+
|
|
14
|
+
/** One stdio session may own the shared host; every other session borrows its published endpoint. */
|
|
15
|
+
export function mcpWorkspaceSession(bundled: string) {
|
|
16
|
+
let root: Promise<string> | undefined, owned: { server: WorkspaceServer, lease: ServiceHostLease } | undefined
|
|
17
|
+
let closed = false, pending: Promise<McpWorkspaceConnection> | undefined, closing: Promise<void> | undefined
|
|
18
|
+
const closeOwned = async () => {
|
|
19
|
+
const current = owned
|
|
20
|
+
owned = undefined
|
|
21
|
+
await current?.server.close()
|
|
22
|
+
}
|
|
23
|
+
const close = (): Promise<void> => closing ??= Promise.resolve().then(async () => {
|
|
24
|
+
closed = true
|
|
25
|
+
await pending?.catch(() => undefined)
|
|
26
|
+
await closeOwned()
|
|
27
|
+
})
|
|
28
|
+
const target = (state: ServiceState): WorkspaceTarget => ({ mcp: state.mcp, token: state.token, pid: state.pid })
|
|
29
|
+
return {
|
|
30
|
+
startWorkspace(dir: string, allow: readonly ApprovalKind[], signal: AbortSignal): Promise<McpWorkspaceConnection> {
|
|
31
|
+
if (pending) return pending
|
|
32
|
+
const work = async () => {
|
|
33
|
+
signal.throwIfAborted()
|
|
34
|
+
if (closed) throw new Error('mcp-workspace-session-closed')
|
|
35
|
+
if (!root) {
|
|
36
|
+
const existing = findWorkspaceServiceState(dir)
|
|
37
|
+
root = existing ? Promise.resolve(existing.root) : findWorkspaceRoot(dir).then(found => realpathSync(existsSync(join(found, WORKSPACE_CONFIG)) ? found : dir))
|
|
38
|
+
}
|
|
39
|
+
const directory = await root, file = join(serveStateDir(directory), 'server.json')
|
|
40
|
+
const deadline = Date.now() + 30_000
|
|
41
|
+
for (;;) {
|
|
42
|
+
signal.throwIfAborted()
|
|
43
|
+
if (closed) throw new Error('mcp-workspace-session-closed')
|
|
44
|
+
if (owned?.lease.signal.aborted) await closeOwned()
|
|
45
|
+
const state = readServiceState(file)
|
|
46
|
+
if (state) return { target: target(state), close }
|
|
47
|
+
if (Date.now() >= deadline) throw new Error('mcp-workspace-start-timeout')
|
|
48
|
+
const lease = await tryAcquireServiceHostLease(directory)
|
|
49
|
+
if (!lease) { await delay(100, undefined, { signal }); continue }
|
|
50
|
+
// A previous host may have published while this process was waiting for its lease.
|
|
51
|
+
const appeared = readServiceState(file)
|
|
52
|
+
if (appeared) { await lease.release(); return { target: target(appeared), close } }
|
|
53
|
+
let server: WorkspaceServer | undefined
|
|
54
|
+
const startup = AbortSignal.any([signal, AbortSignal.timeout(Math.max(1, deadline - Date.now()))])
|
|
55
|
+
try {
|
|
56
|
+
signal.throwIfAborted()
|
|
57
|
+
server = await serveWorkspace({ dir: directory, bundled, port: 0, listenAddress: '127.0.0.1', allow: [...allow], hostLease: lease, signal: startup })
|
|
58
|
+
startup.throwIfAborted()
|
|
59
|
+
if (closed) throw new Error('mcp-workspace-session-closed')
|
|
60
|
+
const ready = readServiceState(file)
|
|
61
|
+
if (!ready || ready.pid !== process.pid || ready.mcp !== server.mcp.url) throw new Error('mcp-workspace-state-unavailable')
|
|
62
|
+
owned = { server, lease }
|
|
63
|
+
return { target: target(ready), close }
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (server) await server.close()
|
|
66
|
+
else await lease.release()
|
|
67
|
+
if (!signal.aborted && startup.aborted) throw new Error('mcp-workspace-start-timeout')
|
|
68
|
+
throw error
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
pending = work().finally(() => { pending = undefined })
|
|
73
|
+
return pending
|
|
74
|
+
},
|
|
75
|
+
close,
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/messages.ts
CHANGED
|
@@ -29,6 +29,7 @@ export interface CliMessages {
|
|
|
29
29
|
newMissing: string
|
|
30
30
|
studioMissing: string
|
|
31
31
|
mcpMissing: string
|
|
32
|
+
workspaceServiceBusy(url?: string): string
|
|
32
33
|
noProblems: string
|
|
33
34
|
counts(errors: number, warnings: number, infos: number): string
|
|
34
35
|
severity: Record<'error' | 'warning' | 'info', string>
|
|
@@ -187,9 +188,9 @@ export const CLI_MESSAGES: Record<Locale, CliMessages> = {
|
|
|
187
188
|
的地址用它给出;带路径时代理原样转发该路径,服务的全部内容都在它下面
|
|
188
189
|
--allow <种类> 无需询问即允许的操作:operate、spend、write、agent(默认在打开的
|
|
189
190
|
Presmium 窗口中询问)
|
|
190
|
-
mcp
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
mcp 以标准输入输出提供原生 MCP,供 Claude Code、Codex 等 AI 工具一次配置连接。
|
|
192
|
+
默认启动或复用工作区服务,初始化后即可编辑与截帧;--compiler-only 显式独立编译。
|
|
193
|
+
收费、源文件写入与浏览器操作保留审批。详见 presmium mcp --help
|
|
193
194
|
studio 启动 Presmium Studio(实验性):浏览器中的编辑应用与这个目录(工作区的
|
|
194
195
|
根目录或一份文稿)的工作区服务,只打印一个要打开的网址。随 Presmium 一起安装
|
|
195
196
|
--port <端口> Presmium Studio 的端口(默认为 4320,被占用时取空闲端口)
|
|
@@ -220,6 +221,7 @@ export const CLI_MESSAGES: Record<Locale, CliMessages> = {
|
|
|
220
221
|
newMissing: 'presmium new: 没有安装 create-presmium。它随 presmium 一起安装,请运行 pnpm add -g @lincyaw/presmium。',
|
|
221
222
|
studioMissing: 'presmium studio: 没有安装 Presmium Studio。它随 Presmium 一起安装,请运行 pnpm add -g @lincyaw/presmium。',
|
|
222
223
|
mcpMissing: 'presmium mcp: 没有安装 @lincyaw/mcp。它随 Presmium 一起安装,请运行 pnpm add -g @lincyaw/presmium。',
|
|
224
|
+
workspaceServiceBusy: url => `这个工作区已有作者服务${url ? `:${url}` : '正在启动'}。请使用已运行的服务。`,
|
|
223
225
|
noProblems: '没有问题',
|
|
224
226
|
counts: (errors, warnings, infos) => `${errors} 个错误,${warnings} 个警告,${infos} 条信息`,
|
|
225
227
|
severity: { error: '错误', warning: '警告', info: '信息' },
|
|
@@ -417,9 +419,10 @@ Commands:
|
|
|
417
419
|
proxy forwards that path unchanged and everything the service serves is below it
|
|
418
420
|
--allow <kinds> approvals given without asking: operate, spend, write, agent (by default
|
|
419
421
|
they are asked in an open Presmium window)
|
|
420
|
-
mcp MCP on stdio for AI tools such as Claude Code and Codex
|
|
421
|
-
|
|
422
|
-
|
|
422
|
+
mcp Native MCP on stdio for AI tools such as Claude Code and Codex, configured once.
|
|
423
|
+
Starts or reuses a workspace service with editing and captures ready at initialization;
|
|
424
|
+
--compiler-only explicitly selects standalone compilation. Paid operations, source-file
|
|
425
|
+
writes and browser control retain approval. See presmium mcp --help
|
|
423
426
|
studio Presmium Studio (experimental): the editing app in the browser and the workspace service
|
|
424
427
|
of the directory (the workspace root, or a deck); prints the one address to open.
|
|
425
428
|
Included with Presmium
|
|
@@ -451,6 +454,7 @@ Exit Codes: 0 no errors, 1 error findings, 2 usage or internal error.`,
|
|
|
451
454
|
newMissing: 'presmium new: create-presmium is not installed. It comes with the presmium package: run pnpm add -g @lincyaw/presmium.',
|
|
452
455
|
studioMissing: 'presmium studio: Presmium Studio is not installed. It comes with Presmium: run pnpm add -g @lincyaw/presmium.',
|
|
453
456
|
mcpMissing: 'presmium mcp: @lincyaw/mcp is not installed. It comes with Presmium: run pnpm add -g @lincyaw/presmium.',
|
|
457
|
+
workspaceServiceBusy: url => `This workspace already has an authoring service${url ? `: ${url}` : ' starting'}. Use the existing service.`,
|
|
454
458
|
noProblems: 'no problems',
|
|
455
459
|
counts: (errors, warnings, infos) => `${errors} errors, ${warnings} warnings, ${infos} infos`,
|
|
456
460
|
severity: { error: 'error', warning: 'warning', info: 'info' },
|