dsh-rig 0.4.0 → 0.5.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,32 @@
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.5.0] - 2026-11-26
7
+
8
+ ### Added
9
+
10
+ - **面板里能装插件**:新增一行输入框,填包名 / `github:owner/repo` / `file:路径` / 本地目录,点「安装」。
11
+ 装进的是**实验室自己的 profile**,不是宿主。
12
+ - `plugin_lab` 新增 `action: 'install'`(参数 `spec`),智能体也能装。**没有新增工具** ——
13
+ 这个工具常驻,加一个 enum 几乎不花 token;新工具会让每轮都多背一份 schema。
14
+ - 底层走 DSH 自己的路:`DSH_HOME=<实验室 home> dsh plugin --profile <p> add <spec>` ——
15
+ 与界面「插件」页的「添加插件」是同一套(那条命令就是把参数转发给 pnpm)。
16
+ - 装完**不会自动生效**:DSH 的插件注入表是进程启动时收集一次的,日志会提示「重启实验室后生效」。
17
+
18
+ ### Verified
19
+
20
+ - 真机:装一个不存在的包 → pnpm 回 `ERR_PNPM_FETCH_404`,工具返回 `{ok:false, exit:1, reason:'exit-nonzero'}`,
21
+ 日志带完整错误与实验室自己的 `.plugin-manager/logs/operation-*/pnpm.log` 路径。
22
+ - `npm test` 68 条全绿。
23
+
24
+ ## [0.4.1] - 2026-11-24
25
+
26
+ ### Fixed
27
+
28
+ - **「在右侧栏打开」实际打开了系统浏览器**。`browserOpener` 只在 `openLab()`(智能体首次驱动、自动展开那条路)里赋值,
29
+ 而用户直接点面板按钮时它还是 `null`,于是走了兜底的 `window.open` —— 两个按钮行为一模一样。
30
+ 现在 `apply()` 里就 `inject(['sidebarRight'])` 并接上入口,不等任何事件。
31
+
6
32
  ## [0.4.0] - 2026-11-24
7
33
 
8
34
  ### Added
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,6 +359,7 @@ 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('')
361
363
  const limitTimer = useRef(null)
362
364
 
363
365
  const lab = view.labs.length > 0 ? view.labs[0] : null
@@ -371,6 +373,13 @@ window.__ModuleLoader__.load({
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 里装插件:和「插件」页同一个底层(dsh plugin add),装完要重启才生效。 */
377
+ const installSpec = (target) => run('安装', async () => {
378
+ const data = await post(`/labs/${lab.id}/install`, { spec: target, sessionId })
379
+ if (data && data.result && data.result.ok === false) throw new Error(data.result.reason || '失败')
380
+ setSpec('')
381
+ })
382
+
374
383
  /** 滑块拖动时先本地反馈,停手 250ms 才落盘(每一格都发请求会打爆宿主)。 */
375
384
  const commitLimit = (mb) => {
376
385
  setDraftLimit(mb)
@@ -449,6 +458,7 @@ window.__ModuleLoader__.load({
449
458
  h('span', { style: S.grow }),
450
459
  lab ? h('span', { style: S.note }, `${T.logs.title} · ${entries.length}`) : null),
451
460
  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,
452
462
  view.error ? h('div', { style: S.error }, view.error) : null,
453
463
  lab ? h(LogPanel, { entries }) : h(EmptyCard, { busy, onCreate: create }),
454
464
  )
@@ -570,6 +580,23 @@ window.__ModuleLoader__.load({
570
580
  inject: ['slots'],
571
581
  apply(ctx) {
572
582
  try {
583
+ // 先把「开进右栏浏览器标签」的入口拿到 —— 面板按钮随时可能被点,
584
+ // 不能等到 openLab()(自动展开那条路)才赋值,否则第一次点会静默退回系统浏览器。
585
+ try {
586
+ ctx.inject(['sidebarRight'], (inner) => {
587
+ const nav = inner.sidebarRight
588
+ if (!nav || typeof nav.openTab !== 'function') return
589
+ browserOpener = (url) => {
590
+ try {
591
+ nav.openTab('browser', { params: { url } })
592
+ } catch {
593
+ window.open(url, '_blank', 'noopener,noreferrer')
594
+ }
595
+ }
596
+ })
597
+ } catch {
598
+ /* 没有 sidebarRight 就退回系统浏览器 */
599
+ }
573
600
  // 页级连接先起来:面板没打开时也要能收到 `open-lab`,否则「自动展开」无从触发。
574
601
  labStore.configure({ onOpenLab: (sessionId) => autoOpen(ctx, sessionId) })
575
602
  labStore.start()
@@ -284,6 +284,14 @@ 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.install(installTarget[1], String(body.spec || ''))
292
+ json(res, result.ok ? 200 : 400, { result })
293
+ return
294
+ }
287
295
  const limitTarget = /^\/labs\/([a-z0-9-]+)\/limit$/u.exec(tail)
288
296
  if (method === 'POST' && limitTarget) {
289
297
  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
+ }
@@ -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({ execPath, isElectron, coreBin, profile, spec, cwd, home, env }) {
111
+ const args = [coreBin, 'plugin', '--profile', profile, 'add', 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 || ''))
@@ -15,9 +15,9 @@ 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
21
  import { attachLines, isAlive, killTree, spawnChild } from './process.js'
22
22
  import { waitHealthy } from './health.js'
23
23
  import { addLab, describeLab, emptyState, findLab, removeLab } from './registry.js'
@@ -368,17 +368,17 @@ export class LabSupervisor {
368
368
  return this.get(id)
369
369
  }
370
370
 
371
- /** 切版本:只改声明并落盘;真正生效要重启(面板/工具会提示)。 */
372
- async setVersion(id, version) {
371
+ /** 装插件:与「插件」页同一条路(dsh plugin add),装完要重启实验室才生效。 */
372
+ async install(id, spec) {
373
373
  const lab = findLab(this.#state, id)
374
374
  if (!lab) throw new Error(`没有实验室 ${id}`)
375
- const next = await planVersionChange({ lab, version, root: this.#root, env: this.#env })
376
- await this.#save()
377
- this.#rt.emit({ type: 'labs', at: new Date().toISOString() })
378
- this.#rt.pushLog(id, 'rig', `版本已切换为 ${next}(重启后生效)`)
379
- return this.get(id)
375
+ const paths = labPaths(this.#root, id)
376
+ return installPlugin({
377
+ lab, spec, home: paths.home, workspace: paths.workspace,
378
+ execPath: this.#execPath, isElectron: this.#isElectron, version: lab.version, root: this.#root, env: this.#env,
379
+ log: (stream, line) => this.#rt.pushLog(id, stream, line),
380
+ })
380
381
  }
381
-
382
382
  async restart(id) {
383
383
  await this.stop(id)
384
384
  return this.start(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', 'orphans', 'reap']
18
+ const ACTIONS = ['list', 'create', 'start', 'stop', 'restart', 'destroy', 'status', 'logs', 'report', 'install', '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,13 @@ 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.install(id, String(args.spec))
102
+ return result.ok
103
+ ? { ok: true, text: `已装 ${args.spec};重启实验室后生效(面板点「重启」)。` }
104
+ : { ok: false, error: `装插件失败:${result.reason}(exit ${result.exit ?? 'null'})` }
105
+ }
98
106
  if (action === 'orphans' || action === 'reap') {
99
107
  const tracked = supervisor.list().filter((lab) => lab.status === 'running' || lab.status === 'starting')
100
108
  const result = await reapOrphans({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-rig",
3
- "version": "0.4.0",
3
+ "version": "0.5.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",