dsh-rig 0.4.1 → 0.6.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/CHANGELOG.md +35 -0
- package/lib/client.js +17 -4
- package/lib/http/routes.js +20 -0
- package/lib/lab/install.js +59 -0
- package/lib/lab/plugins.js +66 -0
- package/lib/lab/spawn-plan.js +8 -0
- package/lib/lab/supervisor.js +12 -11
- package/lib/tools/lab-tool.js +18 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,41 @@
|
|
|
3
3
|
本项目的所有重要改动都会记在这里。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),
|
|
4
4
|
版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
|
|
5
5
|
|
|
6
|
+
## [0.6.0] - 2026-11-26
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **卸载**:「装插件」那一行加了「卸载」按钮,填包名点它 —— `dsh plugin remove`。
|
|
11
|
+
- **已装计数**:同一行末尾显示 `已装 N` / `未装`,鼠标悬停能看完整清单(`name spec` 每行一个)。
|
|
12
|
+
- `plugin_lab` 新增两个动作:`plugins`(列清单)、`uninstall`(带 `spec`)。
|
|
13
|
+
- HTTP:`GET /labs/:id/plugins`、`POST /labs/:id/plugins`(卸载)。
|
|
14
|
+
- 三条操作在宿主侧合成一个 `supervisor.pluginOp(id, 'install'|'list'|'remove', spec)` —— supervisor 已贴行数上限。
|
|
15
|
+
|
|
16
|
+
### Verified
|
|
17
|
+
|
|
18
|
+
- 真机完整往返:装一个 `file:` 本地最小插件 → 清单立刻出现 → 卸载 → 清单清空,两步都 `exit 0`。
|
|
19
|
+
- 顺带确认两件事实:实验室 profile 的 `dependencies` 才是「用户装的插件」,内核在 `dsh.profile.bundles`(`base` + `web-app`),
|
|
20
|
+
所以初始清单为 0 是正常的;装进去若没声明 `dsh.bundle`,DSH 会警告
|
|
21
|
+
`installed as a plain dependency, not a profile layer` —— 「装了却没生效」先看这句。
|
|
22
|
+
|
|
23
|
+
## [0.5.0] - 2026-11-26
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- **面板里能装插件**:新增一行输入框,填包名 / `github:owner/repo` / `file:路径` / 本地目录,点「安装」。
|
|
28
|
+
装进的是**实验室自己的 profile**,不是宿主。
|
|
29
|
+
- `plugin_lab` 新增 `action: 'install'`(参数 `spec`),智能体也能装。**没有新增工具** ——
|
|
30
|
+
这个工具常驻,加一个 enum 几乎不花 token;新工具会让每轮都多背一份 schema。
|
|
31
|
+
- 底层走 DSH 自己的路:`DSH_HOME=<实验室 home> dsh plugin --profile <p> add <spec>` ——
|
|
32
|
+
与界面「插件」页的「添加插件」是同一套(那条命令就是把参数转发给 pnpm)。
|
|
33
|
+
- 装完**不会自动生效**:DSH 的插件注入表是进程启动时收集一次的,日志会提示「重启实验室后生效」。
|
|
34
|
+
|
|
35
|
+
### Verified
|
|
36
|
+
|
|
37
|
+
- 真机:装一个不存在的包 → pnpm 回 `ERR_PNPM_FETCH_404`,工具返回 `{ok:false, exit:1, reason:'exit-nonzero'}`,
|
|
38
|
+
日志带完整错误与实验室自己的 `.plugin-manager/logs/operation-*/pnpm.log` 路径。
|
|
39
|
+
- `npm test` 68 条全绿。
|
|
40
|
+
|
|
6
41
|
## [0.4.1] - 2026-11-24
|
|
7
42
|
|
|
8
43
|
### Fixed
|
package/lib/client.js
CHANGED
|
@@ -69,6 +69,7 @@ window.__ModuleLoader__.load({
|
|
|
69
69
|
shieldTag: { fontSize: 11, padding: '2px 8px', borderRadius: 999, border: '1px solid var(--dsw-alias-border-l2)', background: 'var(--dsw-alias-bg-overlay)', color: 'var(--dsw-alias-label-secondary)' },
|
|
70
70
|
logbox: { flex: 1, minHeight: 0, overflow: 'auto', margin: '0 12px 10px', border: BOX, borderRadius: 8, padding: '6px 8px', background: 'var(--dsw-alias-bg-layer-1)', fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace', fontSize: 11, lineHeight: 1.55, display: 'flex', flexDirection: 'column', gap: 2 },
|
|
71
71
|
btnLg: { padding: '6px 14px', fontSize: 13, fontWeight: 600, minWidth: 72, justifyContent: 'center' },
|
|
72
|
+
input: { flex: '1 1 120px', minWidth: 80, height: 26, boxSizing: 'border-box', padding: '0 8px', fontSize: 12, color: 'var(--dsw-alias-label-primary)', background: 'var(--dsw-alias-bg-layer-1)', border: BOX, borderRadius: 6 },
|
|
72
73
|
line: { whiteSpace: 'pre-wrap', wordBreak: 'break-all', color: 'var(--dsw-alias-label-secondary)' },
|
|
73
74
|
lineErr: { color: 'var(--dsw-alias-state-error-primary)' },
|
|
74
75
|
note: { fontSize: 11, color: 'var(--dsw-alias-label-secondary)', padding: '2px 0' },
|
|
@@ -358,19 +359,32 @@ window.__ModuleLoader__.load({
|
|
|
358
359
|
const [busy, setBusy] = useState('')
|
|
359
360
|
const [confirming, setConfirming] = useState(false)
|
|
360
361
|
const [draftLimit, setDraftLimit] = useState(null)
|
|
362
|
+
const [spec, setSpec] = useState('')
|
|
363
|
+
const [plugins, setPlugins] = useState([])
|
|
361
364
|
const limitTimer = useRef(null)
|
|
362
365
|
|
|
363
366
|
const lab = view.labs.length > 0 ? view.labs[0] : null
|
|
364
367
|
const entries = lab ? view.logs[lab.id] || [] : []
|
|
365
368
|
const status = lab ? lab.status : 'created'
|
|
366
369
|
const live = status === 'running' || status === 'starting'
|
|
367
|
-
// 没有 lab
|
|
368
|
-
// foreign = 这条实验室是**别处**在跑(记录里的 pid 还活着):只能看。
|
|
370
|
+
// 没有 lab / 没有会话 id / 主人是自己 → 都能动;foreign = 记录里的 pid 还活着(别处正在跑)。
|
|
369
371
|
const foreign = Boolean(lab && lab.foreign)
|
|
370
372
|
const mine = !foreign && (!lab || !lab.ownerSessionId || sessionId === '' || lab.ownerSessionId === sessionId)
|
|
371
373
|
const canView = Boolean(lab && lab.url)
|
|
372
374
|
const fallbackLimit = (view.memory && view.memory.fallback) || 2048
|
|
373
375
|
const shownLimit = draftLimit ?? (lab && lab.memoryLimitMb) ?? fallbackLimit
|
|
376
|
+
// 已装插件清单:装/卸载之后都重拉一次(现读 profile 的 package.json,不做缓存)。
|
|
377
|
+
const reloadPlugins = () => { if (lab) void request(`/labs/${lab.id}/plugins`).then((d) => setPlugins(d.plugins || [])).catch(() => {}) }
|
|
378
|
+
useEffect(reloadPlugins, [lab && lab.id])
|
|
379
|
+
|
|
380
|
+
/** 装/卸插件:同一个底层(dsh plugin add|remove),都要重启实验室才生效。 */
|
|
381
|
+
const pluginOp = (op, target) => run(op === 'remove' ? '卸载' : '安装', async () => {
|
|
382
|
+
const data = await post(op === 'remove' ? `/labs/${lab.id}/plugins` : `/labs/${lab.id}/install`, { spec: target, sessionId })
|
|
383
|
+
if (data && data.result && data.result.ok === false) throw new Error(data.result.reason || '失败')
|
|
384
|
+
setSpec('')
|
|
385
|
+
reloadPlugins()
|
|
386
|
+
})
|
|
387
|
+
|
|
374
388
|
/** 滑块拖动时先本地反馈,停手 250ms 才落盘(每一格都发请求会打爆宿主)。 */
|
|
375
389
|
const commitLimit = (mb) => {
|
|
376
390
|
setDraftLimit(mb)
|
|
@@ -400,7 +414,6 @@ window.__ModuleLoader__.load({
|
|
|
400
414
|
await post('/ui-mode', { enabled: next })
|
|
401
415
|
})
|
|
402
416
|
|
|
403
|
-
// 面板后开:补一次历史(事件流只推「之后」的行)。
|
|
404
417
|
const labId = lab ? lab.id : ''
|
|
405
418
|
useEffect(() => {
|
|
406
419
|
void labStore.seedLogs(labId)
|
|
@@ -412,7 +425,6 @@ window.__ModuleLoader__.load({
|
|
|
412
425
|
? { label: T.act.stop, title: T.act.stopTip, run: () => drive('stop') }
|
|
413
426
|
: { label: T.act.start, tone: 'primary', run: () => drive('start') }
|
|
414
427
|
|
|
415
|
-
// 销毁的二次确认:单独一行,不打断操作带。
|
|
416
428
|
const confirmBar = lab && confirming
|
|
417
429
|
? h('div', { style: S.band },
|
|
418
430
|
h('span', { style: S.note }, T.destroyWarn),
|
|
@@ -449,6 +461,7 @@ window.__ModuleLoader__.load({
|
|
|
449
461
|
h('span', { style: S.grow }),
|
|
450
462
|
lab ? h('span', { style: S.note }, `${T.logs.title} · ${entries.length}`) : null),
|
|
451
463
|
lab ? h(MemoryBar, { value: shownLimit, rss: lab.rssMb, range: view.memory, onChange: commitLimit }) : null,
|
|
464
|
+
lab ? h('div', { style: S.band }, h('span', { style: S.note }, '装插件'), h('input', { value: spec, placeholder: '包名 / github:owner/repo / file:路径', style: S.input, onChange: (e) => setSpec(e.currentTarget.value) }), h(Btn, { disabled: busy !== '' || spec.trim() === '', onClick: () => void pluginOp('install', spec.trim()) }, '安装'), h(Btn, { disabled: busy !== '' || spec.trim() === '' || !live, onClick: () => void pluginOp('remove', spec.trim()) }, '卸载'), h('span', { style: S.note, title: plugins.map((p) => ` `).join('\n') }, plugins.length ? `已装 ` : '未装')) : null,
|
|
452
465
|
view.error ? h('div', { style: S.error }, view.error) : null,
|
|
453
466
|
lab ? h(LogPanel, { entries }) : h(EmptyCard, { busy, onCreate: create }),
|
|
454
467
|
)
|
package/lib/http/routes.js
CHANGED
|
@@ -284,6 +284,26 @@ export function mountRoutes(ctx, { supervisor, frameSig, titleOf }) {
|
|
|
284
284
|
json(res, 200, { report: await supervisor.report(reportTarget[1]) })
|
|
285
285
|
return
|
|
286
286
|
}
|
|
287
|
+
const installTarget = /^\/labs\/([a-z0-9-]+)\/install$/u.exec(tail)
|
|
288
|
+
if (method === 'POST' && installTarget) {
|
|
289
|
+
const body = await readBody(req)
|
|
290
|
+
if (!(await requireDrive(res, installTarget[1], body))) return
|
|
291
|
+
const result = await supervisor.pluginOp(installTarget[1], 'install', String(body.spec || ''))
|
|
292
|
+
json(res, result.ok ? 200 : 400, { result })
|
|
293
|
+
return
|
|
294
|
+
}
|
|
295
|
+
const pluginsTarget = /^\/labs\/([a-z0-9-]+)\/plugins$/u.exec(tail)
|
|
296
|
+
if (method === 'GET' && pluginsTarget) {
|
|
297
|
+
json(res, 200, { plugins: await supervisor.pluginOp(pluginsTarget[1], 'list') })
|
|
298
|
+
return
|
|
299
|
+
}
|
|
300
|
+
if (method === 'POST' && pluginsTarget) {
|
|
301
|
+
const body = await readBody(req)
|
|
302
|
+
if (!(await requireDrive(res, pluginsTarget[1], body))) return
|
|
303
|
+
const result = await supervisor.pluginOp(pluginsTarget[1], 'remove', String(body.spec || ''))
|
|
304
|
+
json(res, result.ok ? 200 : 400, { result })
|
|
305
|
+
return
|
|
306
|
+
}
|
|
287
307
|
const limitTarget = /^\/labs\/([a-z0-9-]+)\/limit$/u.exec(tail)
|
|
288
308
|
if (method === 'POST' && limitTarget) {
|
|
289
309
|
const body = await readBody(req)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-rig · 往实验室的 profile 里装插件(IO 层)
|
|
3
|
+
*
|
|
4
|
+
* 走的是 DSH 自己的路:`dsh plugin --profile <p> add <spec>` ——
|
|
5
|
+
* 与界面「插件」页的「添加插件」是同一套底层(那条命令就是把参数转发给 pnpm)。
|
|
6
|
+
* 我们只负责把 `DSH_HOME` 指到实验室、把输出接进它的日志环形缓冲。
|
|
7
|
+
*
|
|
8
|
+
* 为什么不让宿主代劳:宿主自己的 `plugin_manager` 装的是**宿主 profile**。
|
|
9
|
+
* 实验室有独立 `DSH_HOME` 与独立 profile,必须由实验室那一侧装,否则装到宿主身上就白装了。
|
|
10
|
+
*
|
|
11
|
+
* 装完**不会自动生效**:DSH 的插件注入表是进程启动时收集一次的,所以调用方要提示重启实验室。
|
|
12
|
+
*/
|
|
13
|
+
import { buildPluginPlan } from './spawn-plan.js'
|
|
14
|
+
import { resolveCoreBin } from './core-bin.js'
|
|
15
|
+
import { runOnce } from './seed.js'
|
|
16
|
+
|
|
17
|
+
/** pnpm 装包可能很慢(拉 tarball、跑 build),给足时间但别无限。 */
|
|
18
|
+
const INSTALL_TIMEOUT_MS = 300_000
|
|
19
|
+
|
|
20
|
+
/** 只接受看起来像包装说明的字符串:空、超长、带换行的直接拒。 */
|
|
21
|
+
export function normalizeSpec(spec) {
|
|
22
|
+
const value = typeof spec === 'string' ? spec.trim() : ''
|
|
23
|
+
if (value === '') return { ok: false, reason: 'empty' }
|
|
24
|
+
if (value.length > 512) return { ok: false, reason: 'too-long' }
|
|
25
|
+
if (/[\r\n]/u.test(value)) return { ok: false, reason: 'invalid' }
|
|
26
|
+
return { ok: true, value }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @returns {Promise<{ok: boolean, exit: number|null, timedOut: boolean, reason: string|null}>}
|
|
31
|
+
*/
|
|
32
|
+
export async function installPlugin(options) {
|
|
33
|
+
const { lab, home, workspace, execPath, isElectron, version, root, env, log } = options
|
|
34
|
+
const spec = normalizeSpec(options.spec)
|
|
35
|
+
if (!spec.ok) return { ok: false, exit: null, timedOut: false, reason: spec.reason }
|
|
36
|
+
|
|
37
|
+
let coreBin
|
|
38
|
+
try {
|
|
39
|
+
coreBin = await resolveCoreBin({ version, root, env })
|
|
40
|
+
} catch (err) {
|
|
41
|
+
log('rig', `装插件失败:找不到宿主 core(${err?.message ?? err})`)
|
|
42
|
+
return { ok: false, exit: null, timedOut: false, reason: 'core-missing' }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const plan = buildPluginPlan({ execPath, isElectron, coreBin, profile: lab.profile, spec: spec.value, cwd: workspace, home, env })
|
|
46
|
+
log('rig', `装插件:${spec.value}(profile=${lab.profile})`)
|
|
47
|
+
const result = await runOnce(plan, {
|
|
48
|
+
timeoutMs: INSTALL_TIMEOUT_MS,
|
|
49
|
+
onLine: (stream, line) => {
|
|
50
|
+
// pnpm 的输出很吵,只留错误与安装结果这类有信息量的行。
|
|
51
|
+
if (stream === 'err' || /added|up to date|already|installed|ERR_|error/iu.test(line)) log(stream, line)
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const timedOut = Boolean(result.timedOut)
|
|
56
|
+
const ok = result.code === 0
|
|
57
|
+
log('rig', ok ? `插件装好了:${spec.value}(重启实验室后生效)` : `装插件失败:exit ${result.code ?? 'null'}${timedOut ? ',超时' : ''}`)
|
|
58
|
+
return { ok, exit: result.code ?? null, timedOut, reason: ok ? null : timedOut ? 'timeout' : 'exit-nonzero' }
|
|
59
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-rig · 实验室的插件清单与卸载(IO 层)
|
|
3
|
+
*
|
|
4
|
+
* 三件事放一起(安装仍在 install.js):它们都只碰实验室自己的 profile 目录,
|
|
5
|
+
* 且都是「一次性命令 + 一次读盘」,与生命周期无关 —— 所以不塞进 supervisor。
|
|
6
|
+
*
|
|
7
|
+
* 列清单**现读** `profiles/<p>/package.json` 的 dependencies,不做缓存:
|
|
8
|
+
* 装/卸载本来就不频繁,而缓存会引入一类「界面说装了、实际没装」的错觉。
|
|
9
|
+
*/
|
|
10
|
+
import { readFile } from 'node:fs/promises'
|
|
11
|
+
import { join } from 'node:path'
|
|
12
|
+
import { buildPluginPlan } from './spawn-plan.js'
|
|
13
|
+
import { resolveCoreBin } from './core-bin.js'
|
|
14
|
+
import { runOnce } from './seed.js'
|
|
15
|
+
import { normalizeSpec } from './install.js'
|
|
16
|
+
|
|
17
|
+
/** pnpm remove 也可能要联网(更新 lockfile),给同样的上限。 */
|
|
18
|
+
const REMOVE_TIMEOUT_MS = 300_000
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 实验室已装的插件。
|
|
22
|
+
* @returns {Promise<Array<{name: string, spec: string}>>}
|
|
23
|
+
*/
|
|
24
|
+
export async function listPlugins({ home, lab }) {
|
|
25
|
+
const file = join(home, 'profiles', lab.profile, 'package.json')
|
|
26
|
+
try {
|
|
27
|
+
const raw = JSON.parse(await readFile(file, 'utf8'))
|
|
28
|
+
const deps = raw && typeof raw.dependencies === 'object' && raw.dependencies !== null ? raw.dependencies : {}
|
|
29
|
+
return Object.entries(deps)
|
|
30
|
+
.map(([name, spec]) => ({ name, spec: String(spec) }))
|
|
31
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
32
|
+
} catch {
|
|
33
|
+
// profile 还没建、或文件坏:当作「一个都没有」,不要把面板打成错误态。
|
|
34
|
+
return []
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 从实验室 profile 卸掉一个插件。
|
|
40
|
+
* @returns {Promise<{ok: boolean, exit: number|null, reason: string|null}>}
|
|
41
|
+
*/
|
|
42
|
+
export async function removePlugin(options) {
|
|
43
|
+
const { lab, home, workspace, execPath, isElectron, version, root, env, log } = options
|
|
44
|
+
const spec = normalizeSpec(options.spec)
|
|
45
|
+
if (!spec.ok) return { ok: false, exit: null, reason: spec.reason }
|
|
46
|
+
|
|
47
|
+
let coreBin
|
|
48
|
+
try {
|
|
49
|
+
coreBin = await resolveCoreBin({ version, root, env })
|
|
50
|
+
} catch (err) {
|
|
51
|
+
log('rig', `卸载失败:找不到宿主 core(${err?.message ?? err})`)
|
|
52
|
+
return { ok: false, exit: null, reason: 'core-missing' }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const plan = buildPluginPlan({ action: 'remove', execPath, isElectron, coreBin, profile: lab.profile, spec: spec.value, cwd: workspace, home, env })
|
|
56
|
+
log('rig', `卸载插件:${spec.value}(profile=${lab.profile})`)
|
|
57
|
+
const result = await runOnce(plan, {
|
|
58
|
+
timeoutMs: REMOVE_TIMEOUT_MS,
|
|
59
|
+
onLine: (stream, line) => {
|
|
60
|
+
if (stream === 'err' || /removed|already|not found|ERR_|error/iu.test(line)) log(stream, line)
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
const ok = result.code === 0
|
|
64
|
+
log('rig', ok ? `已卸载 ${spec.value}(重启实验室后生效)` : `卸载失败:exit ${result.code ?? 'null'}`)
|
|
65
|
+
return { ok, exit: result.code ?? null, reason: ok ? null : result.timedOut ? 'timeout' : 'exit-nonzero' }
|
|
66
|
+
}
|
package/lib/lab/spawn-plan.js
CHANGED
|
@@ -106,6 +106,14 @@ export function buildSeedPlan({ execPath, isElectron, coreBin, profile, cwd, hom
|
|
|
106
106
|
return { command: execPath, args, cwd, env: sanitizeEnv(env, extra) }
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** 装插件的计划:dsh plugin --profile <p> add <spec>(本质是把参数转发给 pnpm),DSH_HOME 指到实验室。 */
|
|
110
|
+
export function buildPluginPlan({ action = 'add', execPath, isElectron, coreBin, profile, spec, cwd, home, env }) {
|
|
111
|
+
const args = [coreBin, 'plugin', '--profile', profile, action, spec]
|
|
112
|
+
const extra = { DSH_HOME: home, DSH_TELEMETRY_DISABLED: '1' }
|
|
113
|
+
if (isElectron) extra.ELECTRON_RUN_AS_NODE = '1'
|
|
114
|
+
return { command: execPath, args, cwd, env: sanitizeEnv(env, extra) }
|
|
115
|
+
}
|
|
116
|
+
|
|
109
117
|
/** 从实验室 stdout 里抓 URL 与 token。抓不到返回 null,由调用方走兜底。 */
|
|
110
118
|
export function parseLabUrl(line) {
|
|
111
119
|
const m = /http:\/\/127\.0\.0\.1:(\d+)\/\?token=([A-Za-z0-9_-]+)/u.exec(String(line || ''))
|
package/lib/lab/supervisor.js
CHANGED
|
@@ -15,9 +15,10 @@ import { buildStartPlan, parseLabUrl } from './spawn-plan.js'
|
|
|
15
15
|
import { buildDiagnostics } from './diagnostics.js'
|
|
16
16
|
import { isPortFree, pickFreePort } from './port.js'
|
|
17
17
|
import { resolveCoreBin } from './core-bin.js'
|
|
18
|
-
import { planVersionChange } from './versioning.js'
|
|
19
18
|
import { copyCredentials, ensureProfile } from './provision.js'
|
|
20
19
|
import { startLimitGuard } from './limit-guard.js'
|
|
20
|
+
import { installPlugin } from './install.js'
|
|
21
|
+
import { listPlugins, removePlugin } from './plugins.js'
|
|
21
22
|
import { attachLines, isAlive, killTree, spawnChild } from './process.js'
|
|
22
23
|
import { waitHealthy } from './health.js'
|
|
23
24
|
import { addLab, describeLab, emptyState, findLab, removeLab } from './registry.js'
|
|
@@ -231,8 +232,7 @@ export class LabSupervisor {
|
|
|
231
232
|
})
|
|
232
233
|
}
|
|
233
234
|
|
|
234
|
-
/** 把「这条记录现在被谁跑着」写进盘:跨进程判归属只认它(见 merge.isForeign)。
|
|
235
|
-
* 落盘失败只记日志,不让一次写盘失败把启动流程带垮。 */
|
|
235
|
+
/** 把「这条记录现在被谁跑着」写进盘:跨进程判归属只认它(见 merge.isForeign)。 */
|
|
236
236
|
async #stampPid(id, pid) {
|
|
237
237
|
const lab = findLab(this.#state, id)
|
|
238
238
|
if (!lab) return
|
|
@@ -368,17 +368,18 @@ export class LabSupervisor {
|
|
|
368
368
|
return this.get(id)
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
|
|
372
|
-
async setVersion(id, version) {
|
|
371
|
+
async pluginOp(id, op, spec) {
|
|
373
372
|
const lab = findLab(this.#state, id)
|
|
374
373
|
if (!lab) throw new Error(`没有实验室 ${id}`)
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
374
|
+
const paths = labPaths(this.#root, id)
|
|
375
|
+
const ctx = {
|
|
376
|
+
lab, spec, home: paths.home, workspace: paths.workspace,
|
|
377
|
+
execPath: this.#execPath, isElectron: this.#isElectron, version: lab.version, root: this.#root, env: this.#env,
|
|
378
|
+
log: (stream, line) => this.#rt.pushLog(id, stream, line),
|
|
379
|
+
}
|
|
380
|
+
if (op === 'list') return listPlugins(ctx)
|
|
381
|
+
return op === 'remove' ? removePlugin(ctx) : installPlugin(ctx)
|
|
380
382
|
}
|
|
381
|
-
|
|
382
383
|
async restart(id) {
|
|
383
384
|
await this.stop(id)
|
|
384
385
|
return this.start(id)
|
package/lib/tools/lab-tool.js
CHANGED
|
@@ -15,7 +15,7 @@ import { guardDrive, isDriveAction } from '../lab/drive-guard.js'
|
|
|
15
15
|
|
|
16
16
|
const text = (s) => [{ type: 'text', text: String(s ?? '') }]
|
|
17
17
|
|
|
18
|
-
const ACTIONS = ['list', 'create', 'start', 'stop', 'restart', 'destroy', 'status', 'logs', 'report', 'orphans', 'reap']
|
|
18
|
+
const ACTIONS = ['list', 'create', 'start', 'stop', 'restart', 'destroy', 'status', 'logs', 'report', 'install', 'uninstall', 'plugins', 'orphans', 'reap']
|
|
19
19
|
|
|
20
20
|
function renderLab(lab) {
|
|
21
21
|
const head = `[${lab.id}] ${lab.name} · ${lab.status}${lab.port ? ` · :${lab.port}` : ''}`
|
|
@@ -37,6 +37,7 @@ export function createLabTool(supervisor) {
|
|
|
37
37
|
name: { type: 'string', description: 'create 时的显示名' },
|
|
38
38
|
since: { type: 'integer', minimum: 0, description: 'logs 的起点序号,默认 0' },
|
|
39
39
|
lines: { type: 'integer', minimum: 1, maximum: 200, description: 'logs 最多返回多少行,默认 40' },
|
|
40
|
+
spec: { type: 'string', description: 'install 要装的插件:包名 / github:owner/repo / file:路径 / 本地目录' },
|
|
40
41
|
force: { type: 'boolean', description: '实验室被别人驾驶时强行接手(会中断对方正在进行的操作)' },
|
|
41
42
|
},
|
|
42
43
|
required: ['action'],
|
|
@@ -95,6 +96,22 @@ export function createLabTool(supervisor) {
|
|
|
95
96
|
const report = await supervisor.report(id)
|
|
96
97
|
return { ok: true, text: renderReport(report) }
|
|
97
98
|
}
|
|
99
|
+
if (action === 'install') {
|
|
100
|
+
if (!args?.spec) return { ok: false, error: 'install 需要 spec(包名 / GitHub 地址 / 本地路径 / file:tgz)' }
|
|
101
|
+
const result = await supervisor.pluginOp(id, 'install', String(args.spec))
|
|
102
|
+
return result.ok
|
|
103
|
+
? { ok: true, text: `已装 ${args.spec};重启实验室后生效(面板点「重启」)。` }
|
|
104
|
+
: { ok: false, error: `装插件失败:${result.reason}(exit ${result.exit ?? 'null'})` }
|
|
105
|
+
}
|
|
106
|
+
if (action === 'plugins') {
|
|
107
|
+
const list = await supervisor.pluginOp(id, 'list')
|
|
108
|
+
return { ok: true, text: list.length === 0 ? '实验室还没装任何插件。' : list.map((p) => `${p.name} ${p.spec}`).join('\n') }
|
|
109
|
+
}
|
|
110
|
+
if (action === 'uninstall') {
|
|
111
|
+
if (!args?.spec) return { ok: false, error: 'uninstall 需要 spec(要卸的包名)' }
|
|
112
|
+
const result = await supervisor.pluginOp(id, 'remove', String(args.spec))
|
|
113
|
+
return result.ok ? { ok: true, text: `已卸载 ${args.spec};重启实验室后生效。` } : { ok: false, error: `卸载失败:${result.reason}` }
|
|
114
|
+
}
|
|
98
115
|
if (action === 'orphans' || action === 'reap') {
|
|
99
116
|
const tracked = supervisor.list().filter((lab) => lab.status === 'running' || lab.status === 'starting')
|
|
100
117
|
const result = await reapOrphans({
|
package/package.json
CHANGED