dsh-agent-team-playbook 1.32.3 → 1.33.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/README.md CHANGED
@@ -216,6 +216,25 @@ npx dsh-agent-team-playbook init --global --inline-core # 用户全局:内
216
216
  - v1.7:拆分为「常驻核心 + 9 分册」
217
217
  - 完整历史见 `docs/workflow/rules/09-环境适配与变更记录.md`
218
218
 
219
+ ## 发版自检
220
+
221
+ ```bash
222
+ npm run smoke:pack # 本地打包 → 真实安装一遍(发版前跑这个)
223
+ npm run smoke -- --version 1.32.3 # 从 npm 装已发布版本,验证线上产物
224
+ ```
225
+
226
+ 脚本用一个**全新的 `DSH_HOME`** 走真实 `dsh plugin add`,7 项检查:
227
+
228
+ 1. 安装成功(pnpm 解析 + 下载)
229
+ 2. 装到版本正确,且 `dsh.bundle` / `dsh.client` / `exports["./client"]` / `engines.dsh` 齐全
230
+ 3. 组合配置里出现本插件(bundle patch 真的被激活)
231
+ 4. `cordis.patch.yml` 与实际命令一致(防止注释过期)
232
+ 5. host 半身加载并注册 `/atp`
233
+ 6. client 半身能被 ModuleLoader 装配(三个插槽都在)
234
+ 7. `bin` 可执行
235
+
236
+ `npm publish` 前会自动跑第 0–7 项(`prepublishOnly`),**不通过就不发布**。
237
+
219
238
  ## 兼容性
220
239
 
221
240
  插件包在 `package.json` 里声明了对 DSH 运行时(`dsh-app-boot` 版本)的要求:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agent-team-playbook",
3
- "version": "1.32.3",
3
+ "version": "1.33.0",
4
4
  "description": "DeepSeek Harness plugin that brings an executable multi-agent collaboration workflow (charter, triage tiers, six-stage pipeline, audit gates, experience library): a read-only /agent-team command plus a collision-aware installer for the documents.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -50,7 +50,10 @@
50
50
  "scripts": {
51
51
  "sync": "node scripts/sync-playbook.mjs",
52
52
  "check": "node scripts/sync-playbook.mjs --check",
53
- "prepack": "node scripts/sync-playbook.mjs"
53
+ "smoke": "node scripts/smoke-install.mjs",
54
+ "smoke:pack": "node scripts/smoke-install.mjs --pack",
55
+ "prepack": "node scripts/sync-playbook.mjs",
56
+ "prepublishOnly": "node scripts/smoke-install.mjs --pack"
54
57
  },
55
58
  "exports": {
56
59
  ".": "./lib/index.js",
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 安装自检(smoke install)——验证"用户真的能装上、装完真的能用"。
4
+ *
5
+ * 为什么需要它:单测只覆盖源码,`npm pack` 只验证包内容;真正会坏的是
6
+ * 安装链路(registry 解析、bundle patch 激活、engines 校验、bin 可执行)。
7
+ * 这里用一个**干净的 DSH_HOME** 走一遍真实 `dsh plugin add`。
8
+ *
9
+ * 两种模式:
10
+ * node scripts/smoke-install.mjs # 从 npm 装当前 version
11
+ * node scripts/smoke-install.mjs --pack # 先 npm pack 本地,再装 tarball
12
+ * node scripts/smoke-install.mjs --version 1.32.3 # 指定版本
13
+ * node scripts/smoke-install.mjs --registry https://registry.npmjs.org/
14
+ *
15
+ * 退出码 0 = 全部通过;非 0 = 有检查失败(可直接用于发版前门禁)。
16
+ */
17
+ import { execFileSync, spawnSync } from 'node:child_process'
18
+ import { mkdtempSync, readFileSync, existsSync, rmSync, writeFileSync } from 'node:fs'
19
+ import { tmpdir } from 'node:os'
20
+ import path from 'node:path'
21
+ import { fileURLToPath, pathToFileURL } from 'node:url'
22
+
23
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
24
+ const args = process.argv.slice(2)
25
+ const flag = (name, fallback) => {
26
+ const i = args.indexOf(`--${name}`)
27
+ return i >= 0 && args[i + 1] !== undefined ? args[i + 1] : fallback
28
+ }
29
+ const has = (name) => args.includes(`--${name}`)
30
+
31
+ const PKG = JSON.parse(readFileSync(path.join(ROOT, 'package.json'), 'utf8'))
32
+ const EXPECTED = flag('version', PKG.version)
33
+ const REGISTRY = flag('registry', 'https://registry.npmjs.org/')
34
+ const USE_PACK = has('pack')
35
+
36
+ const results = []
37
+ const pass = (name, detail = '') => results.push({ name, ok: true, detail })
38
+ const fail = (name, detail = '') => results.push({ name, ok: false, detail })
39
+
40
+ function run(cmd, argv, options = {}) {
41
+ return spawnSync(cmd, argv, { encoding: 'utf8', timeout: 240_000, ...options })
42
+ }
43
+
44
+ function check(name, body) {
45
+ try {
46
+ const detail = body()
47
+ pass(name, typeof detail === 'string' ? detail : '')
48
+ } catch (error) {
49
+ fail(name, String(error?.message ?? error).slice(0, 220))
50
+ }
51
+ }
52
+ function assert(condition, message) {
53
+ if (!condition) throw new Error(message)
54
+ }
55
+
56
+ const home = mkdtempSync(path.join(tmpdir(), 'atp-smoke-'))
57
+ const profile = 'smoke'
58
+ const profileDir = path.join(home, 'profiles', profile)
59
+ const env = { ...process.env, DSH_HOME: home }
60
+
61
+ console.log(`\n安装自检:${PKG.name}`)
62
+ console.log(` 期望版本:${EXPECTED}`)
63
+ console.log(` registry:${REGISTRY}`)
64
+ console.log(` 模式:${USE_PACK ? '本地 npm pack → tarball' : 'npm registry'}`)
65
+ console.log(` 沙箱:${home}\n`)
66
+
67
+ let spec = null
68
+ try {
69
+ // ── 0. 解析安装目标 ──────────────────────────────────────────────
70
+ if (USE_PACK) {
71
+ check('0. npm pack 本地打包', () => {
72
+ // npm publish 会把 --dry-run 等经 npm_config_* 传给子进程:不清掉的话嵌套 pack 不产出文件
73
+ const cleanEnv = { ...process.env }
74
+ for (const key of Object.keys(cleanEnv)) {
75
+ if (key.startsWith('npm_lifecycle_')) delete cleanEnv[key]
76
+ if (/^npm_config_(dry[-_]?run|json|silent)$/i.test(key)) delete cleanEnv[key]
77
+ }
78
+ // 先显式同步 playbook,再用 --ignore-scripts 打包:否则 prepack 的进度输出会混进 --json 的 stdout
79
+ const sync = run(process.execPath, ['scripts/sync-playbook.mjs'], { cwd: ROOT, env: cleanEnv })
80
+ assert(sync.status === 0, `playbook 同步失败:${(sync.stderr || sync.stdout || '').trim().slice(0, 160)}`)
81
+ const out = run('npm', ['pack', '--json', '--ignore-scripts', '--pack-destination', home], { cwd: ROOT, env: cleanEnv })
82
+ assert(out.status === 0, `npm pack 失败:${(out.stderr || out.stdout || '').trim().slice(0, 200)}`)
83
+ let parsed
84
+ try {
85
+ parsed = JSON.parse(out.stdout.trim())
86
+ } catch {
87
+ throw new Error(`npm pack 输出无法解析:${out.stdout.trim().slice(0, 160)}`)
88
+ }
89
+ const tgz = Array.isArray(parsed) && parsed[0]?.filename
90
+ assert(typeof tgz === 'string' && tgz.endsWith('.tgz'), `未拿到 tarball 名:${String(tgz)}`)
91
+ spec = path.join(home, tgz)
92
+ assert(existsSync(spec), `tarball 不存在:${spec}`)
93
+ return path.basename(spec)
94
+ })
95
+ } else {
96
+ spec = `${PKG.name}@${EXPECTED}`
97
+ }
98
+
99
+ // ── 1. 真实安装 ──────────────────────────────────────────────────
100
+ check('1. dsh plugin add 安装成功', () => {
101
+ assert(spec !== null, '安装目标未就绪')
102
+ const out = run('dsh', ['plugin', '--profile', profile, 'add', spec, '--registry', REGISTRY], { env })
103
+ assert(out.status === 0, `安装失败:${(out.stderr || out.stdout || '').trim().slice(-300)}`)
104
+ return 'pnpm 安装完成'
105
+ })
106
+
107
+ const installedDir = path.join(profileDir, 'node_modules', PKG.name)
108
+ const manifestPath = path.join(installedDir, 'package.json')
109
+
110
+ // ── 2. 装的版本与声明 ────────────────────────────────────────────
111
+ check(`2. 装到的版本是 ${EXPECTED}`, () => {
112
+ assert(existsSync(manifestPath), 'node_modules 里没有该包')
113
+ const installed = JSON.parse(readFileSync(manifestPath, 'utf8'))
114
+ assert(installed.version === EXPECTED, `实际装上 ${installed.version}`)
115
+ assert(typeof installed.dsh?.bundle?.patch === 'string', '缺少 dsh.bundle.patch')
116
+ assert(typeof installed.dsh?.client?.platform === 'string', '缺少 dsh.client.platform')
117
+ assert(typeof installed.exports?.['./client'] === 'string', '缺少 exports["./client"]')
118
+ assert(typeof installed.engines?.dsh === 'string', '缺少 engines.dsh(DSH 无法判兼容)')
119
+ return `engines.dsh = ${installed.engines.dsh}`
120
+ })
121
+
122
+ // ── 3. bundle patch 被激活 ───────────────────────────────────────
123
+ check('3. profile 配置里出现本插件条目', () => {
124
+ const out = run('dsh', ['--profile', profile, '--dump-config'], { env })
125
+ assert(out.status === 0, `dump-config 失败:${(out.stderr || '').trim().slice(0, 160)}`)
126
+ assert(out.stdout.includes(PKG.name), '组合后的配置里没有本插件')
127
+ return 'bundle patch 已生效'
128
+ })
129
+
130
+ // ── 4. patch 文件本身可解析且不自相矛盾 ──────────────────────────
131
+ check('4. cordis.patch.yml 与实际命令一致', () => {
132
+ const patchPath = path.join(installedDir, 'cordis.patch.yml')
133
+ assert(existsSync(patchPath), '包内没有 cordis.patch.yml')
134
+ const text = readFileSync(patchPath, 'utf8')
135
+ assert(/insert:/.test(text), 'patch 里没有 insert 段')
136
+ for (const cmd of ['/atp install', '/atp apply']) {
137
+ assert(text.includes(cmd), `patch 注释缺少命令 ${cmd}`)
138
+ }
139
+ assert(!/不写任何文件/.test(text), 'patch 注释仍写着"不写任何文件"(与实际 install/apply 矛盾)')
140
+ return '命令列表与写入边界一致'
141
+ })
142
+
143
+ // ── 5. 从装好的包加载 host 半身 ──────────────────────────────────
144
+ check('5. host 半身加载并注册 /atp', () => {
145
+ const probe = path.join(home, 'probe-host.mjs')
146
+ writeFileSync(probe, `
147
+ const m = await import(${JSON.stringify(pathToFileURL(path.join(installedDir, 'lib/index.js')).href)})
148
+ const regs = []
149
+ m.apply({ commands: { register: (d) => regs.push(d) }, logger: { warn() {} }, inject: () => {}, effect: () => {}, get: () => undefined })
150
+ const cmd = regs[0]
151
+ if (cmd === undefined) throw new Error('没有注册任何命令')
152
+ if (cmd.name !== 'atp') throw new Error('命令名不是 atp,而是 ' + cmd.name)
153
+ if (typeof cmd.handler !== 'function') throw new Error('命令没有 handler')
154
+ console.log(cmd.name + '|' + JSON.stringify(m.inject ?? []))
155
+ `)
156
+ const out = run(process.execPath, [probe])
157
+ assert(out.status === 0, `${(out.stderr || '').trim().slice(-200)}`)
158
+ return out.stdout.trim()
159
+ })
160
+
161
+ // ── 6. client 半身契约 ───────────────────────────────────────────
162
+ check('6. client 半身可被 ModuleLoader 装配', () => {
163
+ const probe = path.join(home, 'probe-client.mjs')
164
+ writeFileSync(probe, `
165
+ let captured = null
166
+ globalThis.window = { __ModuleLoader__: { load: (m) => { captured = m } } }
167
+ await import(${JSON.stringify(pathToFileURL(path.join(installedDir, 'client.js')).href)})
168
+ if (captured === null) throw new Error('bundle 没有调用 __ModuleLoader__.load')
169
+ if (captured.id !== ${JSON.stringify(PKG.name)}) throw new Error('bundle id 不是包名:' + captured.id)
170
+ const React = { createElement: (t, p, ...c) => ({ t, p, c }), useState: (v) => [typeof v === 'function' ? v() : v, () => {}], useEffect: () => {}, useCallback: (f) => f, useMemo: (f) => f(), useRef: (v) => ({ current: v }) }
171
+ const mod = captured.factory((n) => ({ react: React, '@deepseek-ai/dsh-client-ui-primitives': {} })[n] ?? {})
172
+ if (typeof mod.apply !== 'function') throw new Error('client 没有导出 apply')
173
+ const slots = []
174
+ mod.apply({ slots: { inject: (n, cb) => cb(), register: (d) => { slots.push(d.name); return () => {} } }, sessions: { list: { getSnapshot: () => ({ byId: {} }) } }, get: () => undefined })
175
+ console.log(JSON.stringify({ inject: mod.inject, slots }))
176
+ `)
177
+ const out = run(process.execPath, [probe])
178
+ assert(out.status === 0, `${(out.stderr || '').trim().slice(-200)}`)
179
+ const parsed = JSON.parse(out.stdout.trim())
180
+ assert(parsed.slots.includes('settings.section'), '没有注册设置面板')
181
+ assert(parsed.slots.includes('conversation.hero.options'), '没有注册首页入口')
182
+ assert(parsed.slots.includes('shell.overlay'), '没有注册弹窗层')
183
+ return parsed.slots.join(', ')
184
+ })
185
+
186
+ // ── 7. CLI 可执行 ────────────────────────────────────────────────
187
+ check('7. bin 可执行(--help)', () => {
188
+ const cliPath = path.join(installedDir, 'bin', 'cli.mjs')
189
+ assert(existsSync(cliPath), '包里没有 bin/cli.mjs')
190
+ const out = run(process.execPath, [cliPath, '--help'])
191
+ assert(out.status === 0, `--help 退出码 ${out.status}`)
192
+ assert(/init/.test(out.stdout), '--help 输出里没有 init')
193
+ return '用法输出正常'
194
+ })
195
+ } finally {
196
+ rmSync(home, { recursive: true, force: true })
197
+ }
198
+
199
+ const failed = results.filter((r) => !r.ok)
200
+ console.log('')
201
+ for (const r of results) console.log(`${r.ok ? '✓' : '✗'} ${r.name}${r.detail ? ` — ${r.detail}` : ''}`)
202
+ console.log(`\n通过 ${results.length - failed.length} / ${results.length}`)
203
+ if (failed.length > 0) {
204
+ console.log('\n安装自检未通过——不要发版。')
205
+ process.exit(1)
206
+ }
207
+ console.log('\n安装链路正常。')