dsh-rig 0.5.0 → 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 CHANGED
@@ -3,6 +3,23 @@
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
+
6
23
  ## [0.5.0] - 2026-11-26
7
24
 
8
25
  ### Added
package/lib/client.js CHANGED
@@ -360,24 +360,29 @@ window.__ModuleLoader__.load({
360
360
  const [confirming, setConfirming] = useState(false)
361
361
  const [draftLimit, setDraftLimit] = useState(null)
362
362
  const [spec, setSpec] = useState('')
363
+ const [plugins, setPlugins] = useState([])
363
364
  const limitTimer = useRef(null)
364
365
 
365
366
  const lab = view.labs.length > 0 ? view.labs[0] : null
366
367
  const entries = lab ? view.logs[lab.id] || [] : []
367
368
  const status = lab ? lab.status : 'created'
368
369
  const live = status === 'running' || status === 'starting'
369
- // 没有 lab、没有会话 id(拿不到身份)、或主人就是自己 → 都算「我能动」。
370
- // foreign = 这条实验室是**别处**在跑(记录里的 pid 还活着):只能看。
370
+ // 没有 lab / 没有会话 id / 主人是自己 → 都能动;foreign = 记录里的 pid 还活着(别处正在跑)。
371
371
  const foreign = Boolean(lab && lab.foreign)
372
372
  const mine = !foreign && (!lab || !lab.ownerSessionId || sessionId === '' || lab.ownerSessionId === sessionId)
373
373
  const canView = Boolean(lab && lab.url)
374
374
  const fallbackLimit = (view.memory && view.memory.fallback) || 2048
375
375
  const shownLimit = draftLimit ?? (lab && lab.memoryLimitMb) ?? fallbackLimit
376
- /** 往实验室 profile 里装插件:和「插件」页同一个底层(dsh plugin add),装完要重启才生效。 */
377
- const installSpec = (target) => run('安装', async () => {
378
- const data = await post(`/labs/${lab.id}/install`, { spec: target, sessionId })
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 })
379
383
  if (data && data.result && data.result.ok === false) throw new Error(data.result.reason || '失败')
380
384
  setSpec('')
385
+ reloadPlugins()
381
386
  })
382
387
 
383
388
  /** 滑块拖动时先本地反馈,停手 250ms 才落盘(每一格都发请求会打爆宿主)。 */
@@ -409,7 +414,6 @@ window.__ModuleLoader__.load({
409
414
  await post('/ui-mode', { enabled: next })
410
415
  })
411
416
 
412
- // 面板后开:补一次历史(事件流只推「之后」的行)。
413
417
  const labId = lab ? lab.id : ''
414
418
  useEffect(() => {
415
419
  void labStore.seedLogs(labId)
@@ -421,7 +425,6 @@ window.__ModuleLoader__.load({
421
425
  ? { label: T.act.stop, title: T.act.stopTip, run: () => drive('stop') }
422
426
  : { label: T.act.start, tone: 'primary', run: () => drive('start') }
423
427
 
424
- // 销毁的二次确认:单独一行,不打断操作带。
425
428
  const confirmBar = lab && confirming
426
429
  ? h('div', { style: S.band },
427
430
  h('span', { style: S.note }, T.destroyWarn),
@@ -458,7 +461,7 @@ window.__ModuleLoader__.load({
458
461
  h('span', { style: S.grow }),
459
462
  lab ? h('span', { style: S.note }, `${T.logs.title} · ${entries.length}`) : null),
460
463
  lab ? h(MemoryBar, { value: shownLimit, rss: lab.rssMb, range: view.memory, onChange: commitLimit }) : null,
461
- 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 installSpec(spec.trim()) }, '安装')) : 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,
462
465
  view.error ? h('div', { style: S.error }, view.error) : null,
463
466
  lab ? h(LogPanel, { entries }) : h(EmptyCard, { busy, onCreate: create }),
464
467
  )
@@ -288,7 +288,19 @@ export function mountRoutes(ctx, { supervisor, frameSig, titleOf }) {
288
288
  if (method === 'POST' && installTarget) {
289
289
  const body = await readBody(req)
290
290
  if (!(await requireDrive(res, installTarget[1], body))) return
291
- const result = await supervisor.install(installTarget[1], String(body.spec || ''))
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 || ''))
292
304
  json(res, result.ok ? 200 : 400, { result })
293
305
  return
294
306
  }
@@ -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
+ }
@@ -107,8 +107,8 @@ export function buildSeedPlan({ execPath, isElectron, coreBin, profile, cwd, hom
107
107
  }
108
108
 
109
109
  /** 装插件的计划:dsh plugin --profile <p> add <spec>(本质是把参数转发给 pnpm),DSH_HOME 指到实验室。 */
110
- export function buildPluginPlan({ execPath, isElectron, coreBin, profile, spec, cwd, home, env }) {
111
- const args = [coreBin, 'plugin', '--profile', profile, 'add', spec]
110
+ export function buildPluginPlan({ action = 'add', execPath, isElectron, coreBin, profile, spec, cwd, home, env }) {
111
+ const args = [coreBin, 'plugin', '--profile', profile, action, spec]
112
112
  const extra = { DSH_HOME: home, DSH_TELEMETRY_DISABLED: '1' }
113
113
  if (isElectron) extra.ELECTRON_RUN_AS_NODE = '1'
114
114
  return { command: execPath, args, cwd, env: sanitizeEnv(env, extra) }
@@ -18,6 +18,7 @@ import { resolveCoreBin } from './core-bin.js'
18
18
  import { copyCredentials, ensureProfile } from './provision.js'
19
19
  import { startLimitGuard } from './limit-guard.js'
20
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,16 +368,17 @@ export class LabSupervisor {
368
368
  return this.get(id)
369
369
  }
370
370
 
371
- /** 装插件:与「插件」页同一条路(dsh plugin add),装完要重启实验室才生效。 */
372
- async install(id, spec) {
371
+ async pluginOp(id, op, spec) {
373
372
  const lab = findLab(this.#state, id)
374
373
  if (!lab) throw new Error(`没有实验室 ${id}`)
375
374
  const paths = labPaths(this.#root, id)
376
- return installPlugin({
375
+ const ctx = {
377
376
  lab, spec, home: paths.home, workspace: paths.workspace,
378
377
  execPath: this.#execPath, isElectron: this.#isElectron, version: lab.version, root: this.#root, env: this.#env,
379
378
  log: (stream, line) => this.#rt.pushLog(id, stream, line),
380
- })
379
+ }
380
+ if (op === 'list') return listPlugins(ctx)
381
+ return op === 'remove' ? removePlugin(ctx) : installPlugin(ctx)
381
382
  }
382
383
  async restart(id) {
383
384
  await this.stop(id)
@@ -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', 'install', '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}` : ''}`
@@ -98,11 +98,20 @@ export function createLabTool(supervisor) {
98
98
  }
99
99
  if (action === 'install') {
100
100
  if (!args?.spec) return { ok: false, error: 'install 需要 spec(包名 / GitHub 地址 / 本地路径 / file:tgz)' }
101
- const result = await supervisor.install(id, String(args.spec))
101
+ const result = await supervisor.pluginOp(id, 'install', String(args.spec))
102
102
  return result.ok
103
103
  ? { ok: true, text: `已装 ${args.spec};重启实验室后生效(面板点「重启」)。` }
104
104
  : { ok: false, error: `装插件失败:${result.reason}(exit ${result.exit ?? 'null'})` }
105
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
+ }
106
115
  if (action === 'orphans' || action === 'reap') {
107
116
  const tracked = supervisor.list().filter((lab) => lab.status === 'running' || lab.status === 'starting')
108
117
  const result = await reapOrphans({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-rig",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Right-sidebar plugin lab for DeepSeek Harness: start an isolated DSH instance and drive it in the sidebar browser tab.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",