dsh-agent-team-playbook 1.25.0 → 1.27.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
@@ -105,8 +105,13 @@ dsh plugin --profile web add dsh-agent-team-playbook
105
105
  | `/atp paths` | 各分册的绝对路径,按需查阅 |
106
106
  | `/atp install` | 把 playbook **原子安装进当前工作区**(有同名内容则拒绝,不覆盖) |
107
107
  | `/atp install force` | 覆盖同名内容后安装(先暂存原件,失败自动回滚) |
108
+ | `/atp apply 1=覆盖 2=备份 3=改名:x` | 对 install 列出的冲突**逐项决定**(覆盖 / 备份你的文件 / 我们这侧改名并同步引用) |
108
109
  | `/atp help` | 用法 |
109
110
 
111
+ **Web / 桌面端还会多一个设置面板**(设置 → 协作规程):显示当前工作区是否已安装、有无同名冲突,并可一键复制建议的处理命令。面板**只读**,不改你任何文件;真正的写入仍走 `/atp install` / `/atp apply`(可见、可审计)。
112
+
113
+ > dsh-go 手机原生界面不加载浏览器半身,因此没有这个面板——在那边用命令即可。
114
+
110
115
  插件**不写任何文件**、也**不挂 skill**——skill 的目录摘要会常驻占用上下文(约 300 tokens/轮),而分册本来就不会自动进上下文,用命令按需取更划算。
111
116
 
112
117
  ### ② 装成"常驻上下文"(会写文件,核心价值)
package/bin/cli.mjs CHANGED
@@ -283,7 +283,8 @@ async function main() {
283
283
  // ── 2. 决策 ────────────────────────────────────────────────────────
284
284
  const renames = []
285
285
  const defaultSuffix = `.bak-${new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14)}`
286
- let onConflict = 'overwrite'
286
+ let onConflict = 'proceed'
287
+ let backupAllConflicts = false
287
288
  let backupSuffix
288
289
  let install = true
289
290
  const interactive = stdin.isTTY && stdout.isTTY
@@ -327,7 +328,7 @@ async function main() {
327
328
  install = false
328
329
  console.log(C.dim(' --skip-conflicts:整体跳过(不会只装一半)'))
329
330
  } else if (opts.backupExisting) {
330
- onConflict = 'backup'
331
+ backupAllConflicts = true
331
332
  backupSuffix = defaultSuffix
332
333
  console.log(C.dim(` --backup-existing:已有冲突项改名为 *${defaultSuffix} 后安装`))
333
334
  } else if (!interactive) {
@@ -353,7 +354,7 @@ async function main() {
353
354
  console.error(C.red(' 后缀只能含字母数字点下划线横线,已中止。'))
354
355
  process.exit(1)
355
356
  }
356
- onConflict = 'backup'
357
+ backupAllConflicts = true
357
358
  backupSuffix = suffix
358
359
  } else if (answer === 'r') {
359
360
  for (const unit of new Set(unresolved.map((c) => c.unit))) {
@@ -401,6 +402,7 @@ async function main() {
401
402
  targetDir: opts.dir,
402
403
  onConflict,
403
404
  renames,
405
+ backupTargets: backupAllConflicts ? conflicts.map((c) => c.target) : [],
404
406
  backupSuffix,
405
407
  })
406
408
 
package/client.js ADDED
@@ -0,0 +1,167 @@
1
+ /**
2
+ * dsh-agent-team-playbook — 浏览器半身(Step 1:只读面板)
3
+ *
4
+ * 形态照抄官方内置插件(如 @deepseek-ai/dsh-client-ui-open-in-app):
5
+ * 手写 window.__ModuleLoader__.load({ id, factory }),无构建步骤,
6
+ * require 由 shell 提供(react / primitives / slots …)。
7
+ *
8
+ * 本步只做**只读**面板:
9
+ * · 显示当前工作区是否已安装、有无同名冲突
10
+ * · 冲突项可一键复制建议命令(真正的写入仍由用户执行 /atp apply,可见可审计)
11
+ * 不做任何写操作,也不直接调用命令。
12
+ */
13
+ window.__ModuleLoader__.load({
14
+ id: 'dsh-agent-team-playbook',
15
+ factory: (require) => {
16
+ const module = { exports: {} }
17
+ const exports = module.exports
18
+
19
+ const React = require('react')
20
+ const primitives = require('@deepseek-ai/dsh-client-ui-primitives')
21
+
22
+ const h = React.createElement
23
+ const { useCallback, useEffect, useMemo, useState } = React
24
+
25
+ const NAME = 'dsh-agent-team-playbook'
26
+ const API = '/api/agent-team-playbook/status'
27
+ const Button = primitives?.Button
28
+
29
+ /** 读一次状态;cwd 为空时只验证连通性。 */
30
+ async function fetchStatus(cwd) {
31
+ const url = cwd ? `${API}?cwd=${encodeURIComponent(cwd)}` : API
32
+ const res = await fetch(url, { credentials: 'same-origin', headers: { accept: 'application/json' } })
33
+ if (!res.ok) throw new Error(`HTTP ${res.status}`)
34
+ return res.json()
35
+ }
36
+
37
+ /** 取"当前正在看的会话"的 cwd(客户端 sessions 快照里就有)。 */
38
+ function currentCwd(ctx) {
39
+ try {
40
+ const rows = ctx?.sessions?.list?.getSnapshot?.()?.byId ?? {}
41
+ const list = Object.values(rows)
42
+ const active = list.find((row) => (row?.retainedBy?.mainView ?? 0) > 0) ?? list.find((row) => typeof row?.cwd === 'string')
43
+ return typeof active?.cwd === 'string' ? active.cwd : undefined
44
+ } catch {
45
+ return undefined
46
+ }
47
+ }
48
+
49
+ /** 一行小字 + 值。 */
50
+ function Row({ label, children }) {
51
+ return h(
52
+ 'div',
53
+ { style: { display: 'flex', gap: 8, alignItems: 'baseline', margin: '2px 0' } },
54
+ h('span', { style: { opacity: 0.65, minWidth: 72 } }, label),
55
+ h('span', null, children),
56
+ )
57
+ }
58
+
59
+ function LinkButton({ onClick, children }) {
60
+ if (typeof Button === 'function') return h(Button, { onClick, variant: 'secondary' }, children)
61
+ return h('button', { type: 'button', onClick }, children)
62
+ }
63
+
64
+ function Panel() {
65
+ const [state, setState] = useState({ phase: 'loading' })
66
+ const [copied, setCopied] = useState('')
67
+
68
+ const refresh = useCallback(async () => {
69
+ setState({ phase: 'loading' })
70
+ try {
71
+ const cwd = currentCwd(Panel.ctx)
72
+ const data = await fetchStatus(cwd)
73
+ setState({ phase: 'ready', data, cwd })
74
+ } catch (error) {
75
+ setState({ phase: 'error', message: String(error?.message ?? error) })
76
+ }
77
+ }, [])
78
+
79
+ useEffect(() => {
80
+ void refresh()
81
+ }, [refresh])
82
+
83
+ const conflicts = state.phase === 'ready' ? state.data?.conflicts ?? [] : []
84
+
85
+ const suggestion = useMemo(() => {
86
+ if (conflicts.length === 0) return ''
87
+ return `/atp apply ${conflicts.map((_, i) => `${i + 1}=覆盖`).join(' ')}`
88
+ }, [conflicts])
89
+
90
+ const copy = useCallback(async (text) => {
91
+ try {
92
+ await navigator.clipboard.writeText(text)
93
+ setCopied(text)
94
+ setTimeout(() => setCopied(''), 1500)
95
+ } catch {
96
+ setCopied('')
97
+ }
98
+ }, [])
99
+
100
+ const children = []
101
+ children.push(h('div', { key: 'title', style: { fontWeight: 600, marginBottom: 4 } }, '多智能体协作规程(agent-team-playbook)'))
102
+
103
+ if (state.phase === 'loading') {
104
+ children.push(h(Row, { key: 'loading', label: '状态' }, '检测中…'))
105
+ } else if (state.phase === 'error') {
106
+ children.push(h(Row, { key: 'err', label: '状态' }, `无法连接:${state.message}`))
107
+ } else {
108
+ const d = state.data ?? {}
109
+ children.push(h(Row, { key: 'conn', label: '接口' }, d.connected ? '已连通' : '未连通'))
110
+ children.push(h(Row, { key: 'cwd', label: '工作区' }, d.cwd ?? '(未取到当前会话目录)'))
111
+ children.push(
112
+ h(Row, { key: 'inst', label: '安装状态' }, d.installed ? '已安装(AGENTS.md + docs/ 都在)' : '未安装'),
113
+ )
114
+ if (conflicts.length > 0) {
115
+ children.push(
116
+ h('div', { key: 'conf', style: { marginTop: 8, marginBottom: 4, color: 'var(--dsh-warning, #b8862b)' } },
117
+ `检测到 ${conflicts.length} 处同名内容(不会被自动覆盖):`),
118
+ )
119
+ conflicts.forEach((c, i) => {
120
+ children.push(
121
+ h('div', { key: `c${i}`, style: { paddingLeft: 12, margin: '2px 0' } },
122
+ `${i + 1}. ${c.rel} — ${c.reason}`),
123
+ )
124
+ })
125
+ children.push(
126
+ h('div', { key: 'sug', style: { marginTop: 8 } },
127
+ h('div', { style: { opacity: 0.65, marginBottom: 4 } }, '逐项决定后执行(可改 覆盖→备份 / 改名:新名):'),
128
+ h('code', { style: { display: 'block', padding: 6, borderRadius: 6, background: 'rgba(127,127,127,0.12)' } }, suggestion),
129
+ h('div', { style: { marginTop: 6 } },
130
+ h(LinkButton, { onClick: () => void copy(suggestion) }, copied === suggestion ? '已复制 ✓' : '复制命令')),
131
+ ),
132
+ )
133
+ } else if (d.installed) {
134
+ children.push(h('div', { key: 'ok', style: { marginTop: 8, opacity: 0.8 } }, '没有同名冲突。'))
135
+ }
136
+ }
137
+
138
+ children.push(
139
+ h('div', { key: 'actions', style: { marginTop: 10, display: 'flex', gap: 8 } },
140
+ h(LinkButton, { onClick: () => void refresh() }, '重新检测'),
141
+ h(LinkButton, { onClick: () => void copy('/atp install') }, copied === '/atp install' ? '已复制 ✓' : '复制 /atp install')),
142
+ )
143
+
144
+ children.push(
145
+ h('div', { key: 'hint', style: { marginTop: 10, opacity: 0.6, fontSize: 12 } },
146
+ '面板只读:不会修改你的文件。安装/覆盖/改名仍通过 /atp install 与 /atp apply 执行(可见、可审计)。'),
147
+ )
148
+
149
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 2 } }, children)
150
+ }
151
+
152
+ function apply(ctx) {
153
+ Panel.ctx = ctx
154
+ ctx.slots.inject('settings.section', () => ctx.slots.register({
155
+ name: 'settings.section',
156
+ id: 'agent-team-playbook',
157
+ order: 36,
158
+ label: () => '协作规程',
159
+ }, () => h(Panel, null)))
160
+ }
161
+
162
+ exports.apply = apply
163
+ exports.inject = ['slots', 'sessions']
164
+ exports.name = NAME
165
+ return module.exports
166
+ },
167
+ })
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
  import { readFileSync, existsSync, readdirSync } from 'node:fs'
18
18
  import path from 'node:path'
19
19
  import { fileURLToPath } from 'node:url'
20
- import { installAtomic } from './install.js'
20
+ import { installAtomic, scan, CORE_FILE, DOCS_DIR } from './install.js'
21
21
 
22
22
  export const name = 'dsh-agent-team-playbook'
23
23
 
@@ -60,7 +60,7 @@ const INSTALL_HINT = [
60
60
  '让规程变成每轮的固定上下文(本命令只是按需调用):',
61
61
  '',
62
62
  ' /atp install 装进当前工作区(AGENTS.md + docs/)',
63
- ' /atp install force 已有同名内容时覆盖(先暂存,可回滚)',
63
+ ' /atp apply 1=覆盖 2=备份 3=改名:x 逐项处理冲突(install 会列出编号)',
64
64
  ' npx dsh-agent-team-playbook init --global 全局指针区块',
65
65
  ' npx dsh-agent-team-playbook init --global --inline-core 全局内联核心全文',
66
66
  ].join('\n')
@@ -120,6 +120,129 @@ function isUnsafeTarget(dir) {
120
120
  return unsafe.some((u) => dir === u)
121
121
  }
122
122
 
123
+ /** 冲突按路径排序后编号,保证 install 与 apply 一致。 */
124
+ function numberedConflicts(conflicts) {
125
+ return [...conflicts].sort((a, b) => a.rel.localeCompare(b.rel))
126
+ }
127
+
128
+ /** 冲突属于哪个单元(核心 / 分册)。 */
129
+ function unitOfRel(rel) {
130
+ return rel === CORE_FILE ? CORE_FILE : DOCS_DIR
131
+ }
132
+
133
+ /** 解析 /atp apply 的决策串。 */
134
+ function parseApplySpec(raw) {
135
+ const tokens = String(raw).trim().split(/[\s,,]+/).filter(Boolean)
136
+ const perIndex = new Map()
137
+ const globals = []
138
+ for (const tk of tokens) {
139
+ const m = /^(\d+|all)=(.+)$/i.exec(tk)
140
+ if (!m) return { error: `无法识别「${tk}」。格式:1=覆盖 / 2=备份 / 3=改名:名字 / all=覆盖` }
141
+ const idx = m[1].toLowerCase()
142
+ const body = m[2].trim()
143
+ const rm = /^(覆盖|overwrite|备份|backup|改名|rename)(?::(.+))?$/i.exec(body)
144
+ if (!rm) return { error: `无法识别的动作「${body}」。可用:覆盖 / 备份 / 改名:名字` }
145
+ const action = /overwrite|覆盖/i.test(rm[1]) ? 'overwrite' : /backup|备份/i.test(rm[1]) ? 'backup' : 'rename'
146
+ const name = rm[2]?.trim()
147
+ if (action === 'rename' && !name) return { error: `改名需要给出新名字:${tk}` }
148
+ if (name !== undefined && !/^[^/\\]+$/.test(name)) return { error: `名字不能含路径分隔符:${name}` }
149
+ if (idx === 'all') globals.push({ action, name })
150
+ else perIndex.set(Number(idx), { action, name })
151
+ }
152
+ return { perIndex, globals }
153
+ }
154
+
155
+ /** 处理 /atp apply:对当前冲突逐项决定后安装。 */
156
+ async function handleApply(ctx, rawInput, invocation) {
157
+ const targetDir = resolveWorkspace(ctx, invocation)
158
+ if (targetDir === null) {
159
+ return { kind: 'error', text: '无法确定当前工作区目录,已拒绝(避免写到你没预期的地方)。' }
160
+ }
161
+ if (isUnsafeTarget(targetDir)) {
162
+ return { kind: 'error', text: `拒绝安装到 ${targetDir}:这看起来是 DSH 主目录或插件自身目录。` }
163
+ }
164
+
165
+ const specText = rawInput.replace(/^apply\s*/i, '')
166
+ if (specText.trim() === '') {
167
+ return { kind: 'error', text: `缺少决策。先运行 /atp install 看编号,再 /atp apply 1=覆盖 2=备份 …` }
168
+ }
169
+ const parsed = parseApplySpec(specText)
170
+ if (parsed.error) return { kind: 'error', text: parsed.error }
171
+
172
+ const { conflicts } = await scan({ sourceRoot: PLAYBOOK_DIR, targetDir })
173
+ if (conflicts.length === 0) {
174
+ const r = await installAtomic({ sourceRoot: PLAYBOOK_DIR, targetDir, onConflict: 'proceed' })
175
+ return r.ok
176
+ ? { kind: 'success', text: `没有冲突,已安装 ${r.installed.length} 个文件到 ${targetDir}` }
177
+ : { kind: 'error', text: `安装失败:${r.message}` }
178
+ }
179
+
180
+ const list = numberedConflicts(conflicts)
181
+ const decisions = []
182
+ const missing = []
183
+ const renameByUnit = new Map()
184
+ for (let i = 0; i < list.length; i += 1) {
185
+ const c = list[i]
186
+ const idx = i + 1
187
+ const d = parsed.perIndex.get(idx) ?? parsed.globals[0]
188
+ if (d === undefined) {
189
+ missing.push(idx)
190
+ continue
191
+ }
192
+ if (d.action === 'rename') {
193
+ const unit = unitOfRel(c.rel)
194
+ const prev = renameByUnit.get(unit)
195
+ if (prev !== undefined && prev !== d.name) {
196
+ return { kind: 'error', text: `同一单元(${unit})不能改两个名字:${prev} / ${d.name}` }
197
+ }
198
+ renameByUnit.set(unit, d.name)
199
+ }
200
+ decisions.push({ conflict: c, action: d.action })
201
+ }
202
+ if (missing.length > 0) {
203
+ return {
204
+ kind: 'error',
205
+ text: [
206
+ `还有 ${missing.length} 项没决定:${missing.join('、')}`,
207
+ '',
208
+ ...list.map((c, i) => ` ${i + 1}. ${c.rel}(${c.reason})`),
209
+ '',
210
+ '补齐后再执行,例如:/atp apply 1=覆盖 2=备份 3=改名:team-docs',
211
+ ].join('\n'),
212
+ }
213
+ }
214
+
215
+ // 改名若与已存在路径冲突,提前报错
216
+ for (const [unit, name] of renameByUnit) {
217
+ const probe = path.join(targetDir, name)
218
+ if (existsSync(probe)) return { kind: 'error', text: `改名目标已存在:${name}` }
219
+ }
220
+
221
+ const renames = []
222
+ for (const [unit, name] of renameByUnit) {
223
+ if (unit === DOCS_DIR) renames.push({ from: `${DOCS_DIR}/`, to: `${name}/` })
224
+ else renames.push({ from: CORE_FILE, to: name })
225
+ }
226
+ const backupTargets = decisions.filter((d) => d.action === 'backup').map((d) => d.conflict.target)
227
+
228
+ const result = await installAtomic({
229
+ sourceRoot: PLAYBOOK_DIR,
230
+ targetDir,
231
+ onConflict: 'proceed',
232
+ renames,
233
+ backupTargets,
234
+ backupSuffix: `.bak-${new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14)}`,
235
+ })
236
+
237
+ if (!result.ok) return { kind: 'error', text: `安装失败并已回滚:${result.message}` }
238
+
239
+ const lines = [`已安装到:${targetDir}(${result.installed.length} 个文件,核心与分册整体落地)`]
240
+ if (result.backups.length > 0) lines.push(`已备份你的文件:${result.backups.map((b) => path.relative(targetDir, b.to)).join(',')}`)
241
+ if (renames.length > 0) lines.push(`按你的改名安装:${renames.map((r) => `${r.from} → ${r.to}`).join(',')}(文档内引用已同步)`)
242
+ lines.push('', '工作区 AGENTS.md 会被 DSH 每轮自动注入,重载会话后生效。')
243
+ return { kind: 'success', text: lines.join('\n') }
244
+ }
245
+
123
246
  async function handleInstall(ctx, rawInput, invocation) {
124
247
  const force = /\bforce\b|\b--force\b/i.test(rawInput)
125
248
  const targetDir = resolveWorkspace(ctx, invocation)
@@ -150,23 +273,21 @@ async function handleInstall(ctx, rawInput, invocation) {
150
273
 
151
274
  if (!result.ok) {
152
275
  if (result.code === 'conflict') {
153
- const list = result.conflicts
154
- .slice(0, 6)
155
- .map((c) => ` · ${path.relative(targetDir, c.target)}(${c.reason})`)
156
- .join('\n')
276
+ const list = numberedConflicts(result.conflicts)
277
+ const rows = list.map((c, i) => ` ${i + 1}. ${c.rel}(${c.reason})`)
157
278
  return {
158
279
  kind: 'error',
159
280
  text: [
160
- `未安装:${targetDir} 已存在同名内容。`,
161
- list,
162
- result.conflicts.length > 6 ? ` ……共 ${result.conflicts.length} 处` : '',
281
+ `未安装:${targetDir} 有 ${list.length} 处同名内容。`,
282
+ '',
283
+ ...rows,
284
+ '',
285
+ '逐项决定后安装(动作:覆盖 / 备份(你的文件加后缀保留) / 改名:新名(我们这侧换名)):',
286
+ ` /atp apply ${list.map((_, i) => `${i + 1}=覆盖`).join(' ')}`,
287
+ ' 例:/atp apply 1=备份 2=改名:team-docs',
163
288
  '',
164
- '可选做法:',
165
- ' /atp install force 覆盖(先暂存原件,失败自动回滚)',
166
- ' 或用 CLI 交互式处理(可改名/备份):npx dsh-agent-team-playbook init',
167
- ]
168
- .filter((l) => l !== '')
169
- .join('\n'),
289
+ '或一次性覆盖:/atp install force',
290
+ ].join('\n'),
170
291
  }
171
292
  }
172
293
  return { kind: 'error', text: `安装失败并已回滚:${result.message}` }
@@ -204,15 +325,73 @@ function handleCommand(ctx, invocation) {
204
325
  return { kind: 'success', text: core }
205
326
  }
206
327
  if (sub === 'install' || sub.startsWith('install ')) return handleInstall(ctx, raw, invocation)
328
+ if (sub === 'apply' || sub.startsWith('apply ')) return handleApply(ctx, raw, invocation)
207
329
 
208
330
  return { kind: 'error', text: `未知参数:${raw}\n\n${USAGE}` }
209
331
  }
210
332
 
333
+ /**
334
+ * 只读状态接口的 handler(供 Web 面板调用)。
335
+ *
336
+ * 安全边界:
337
+ * - 平台在 handler 之前已做 Host/Origin 校验与会话凭据校验(非白名单路由一律鉴权)
338
+ * - 本 handler 只报告"我们关心的几个相对路径是否存在",不做任意目录列举
339
+ *
340
+ * @param {import('node:http').IncomingMessage} req
341
+ * @param {import('node:http').ServerResponse} res
342
+ */
343
+ export function createStatusHandler() {
344
+ return async function statusHandler(req, res) {
345
+ const send = (status, payload) => {
346
+ res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
347
+ res.end(JSON.stringify(payload))
348
+ }
349
+ try {
350
+ const url = new URL(req.url ?? '/', 'http://localhost')
351
+ const cwd = url.searchParams.get('cwd')
352
+ if (cwd === null || cwd === '') {
353
+ return send(200, { ok: true, connected: true, needsCwd: true, playbookDir: PLAYBOOK_DIR })
354
+ }
355
+ const targetDir = path.resolve(cwd)
356
+ if (!path.isAbsolute(targetDir) || !existsSync(targetDir)) {
357
+ return send(400, { ok: false, error: 'cwd 不存在或不是绝对路径' })
358
+ }
359
+ const { conflicts } = await scan({ sourceRoot: PLAYBOOK_DIR, targetDir })
360
+ const installed = existsSync(path.join(targetDir, CORE_FILE)) && existsSync(path.join(targetDir, DOCS_DIR, 'workflow', 'rules'))
361
+ return send(200, {
362
+ ok: true,
363
+ connected: true,
364
+ cwd: targetDir,
365
+ installed,
366
+ conflicts: conflicts.map((c) => ({ rel: c.rel, reason: c.reason })),
367
+ })
368
+ } catch (error) {
369
+ return send(500, { ok: false, error: String(error?.message ?? error) })
370
+ }
371
+ }
372
+ }
373
+
211
374
  /**
212
375
  * Plugin entry point.
213
376
  * @param {import('@deepseek-ai/cordis').Context} ctx
214
377
  */
215
378
  export function apply(ctx) {
379
+ // Web 面板用的只读接口。
380
+ // 防御:精简 composition 可能没有 inject/webServer/effect —— 静默跳过,不影响命令注册。
381
+ if (typeof ctx.inject === 'function') {
382
+ try {
383
+ ctx.inject(['webServer'], (scoped) => {
384
+ const server = scoped?.webServer
385
+ const handler = createStatusHandler()
386
+ const register = () => server.register({ kind: 'prefix', path: '/api/agent-team-playbook', handler })
387
+ if (typeof scoped?.effect === 'function') scoped.effect(register, 'agent-team-playbook: status api')
388
+ else register()
389
+ })
390
+ } catch (error) {
391
+ ctx.logger?.warn?.(`agent-team-playbook: 状态接口未挂载(${error?.message ?? error})`)
392
+ }
393
+ }
394
+
216
395
  ctx.commands.register({
217
396
  definitionId: 'dsh-agent-team-playbook',
218
397
  name: 'atp',
package/lib/install.js CHANGED
@@ -109,15 +109,16 @@ export async function scan({ sourceRoot, targetDir }) {
109
109
  * @param {object} args
110
110
  * @param {string} args.sourceRoot 包内 playbook 目录
111
111
  * @param {string} args.targetDir 目标工作区
112
- * @param {'error'|'overwrite'|'backup'} args.onConflict 冲突策略
112
+ * @param {'error'|'proceed'} args.onConflict 冲突时是拒绝还是继续
113
+ * @param {string[]} [args.backupTargets] 需要"备份(改名保留)"的已有路径(绝对路径)
114
+ * @param {string} [args.backupSuffix] 备份后缀
113
115
  * @param {Array<{from: string, to: string}>} [args.renames] 我们这侧的改名(会改写引用)
114
- * @param {string} [args.backupSuffix] onConflict==='backup' 时用的后缀
115
116
  * @param {(phase: string, detail?: any) => void} [args.onProgress] 进度回调(可选)
116
117
  * @returns {Promise<{ok: boolean, code?: 'conflict'|'failed', message?: string,
117
118
  * installed: string[], backups: Array<{from:string,to:string}>,
118
119
  * conflicts?: any[]}>}
119
120
  */
120
- export async function installAtomic({ sourceRoot, targetDir, onConflict, renames = [], backupSuffix, onProgress = () => {} }) {
121
+ export async function installAtomic({ sourceRoot, targetDir, onConflict, renames = [], backupTargets = [], backupSuffix, onProgress = () => {} }) {
121
122
  const scanned = await scan({ sourceRoot, targetDir })
122
123
  const { units, docRels, conflicts } = scanned
123
124
 
@@ -149,9 +150,11 @@ export async function installAtomic({ sourceRoot, targetDir, onConflict, renames
149
150
 
150
151
  // 2. 备份(改名已有项)
151
152
  const backups = []
152
- if (conflicts.length > 0 && onConflict === 'backup') {
153
- if (!backupSuffix) throw new Error('onConflict=backup 需要 backupSuffix')
153
+ if (backupTargets.length > 0) {
154
+ if (!backupSuffix) throw new Error('backupTargets 需要 backupSuffix')
155
+ const wanted = new Set(backupTargets.map((p) => path.resolve(p)))
154
156
  for (const c of conflicts) {
157
+ if (!wanted.has(path.resolve(c.target))) continue
155
158
  const to = uniqueBackupPath(c.target, backupSuffix)
156
159
  await mkdir(path.dirname(to), { recursive: true })
157
160
  await rename(c.target, to)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agent-team-playbook",
3
- "version": "1.25.0",
3
+ "version": "1.27.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",
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "main": "lib/index.js",
17
17
  "files": [
18
+ "client.js",
18
19
  "lib",
19
20
  "bin",
20
21
  "scripts",
@@ -27,6 +28,10 @@
27
28
  "dsh": {
28
29
  "bundle": {
29
30
  "patch": "./cordis.patch.yml"
31
+ },
32
+ "client": {
33
+ "platform": "web",
34
+ "inject": []
30
35
  }
31
36
  },
32
37
  "keywords": [
@@ -45,5 +50,10 @@
45
50
  "sync": "node scripts/sync-playbook.mjs",
46
51
  "check": "node scripts/sync-playbook.mjs --check",
47
52
  "prepack": "node scripts/sync-playbook.mjs"
53
+ },
54
+ "exports": {
55
+ ".": "./lib/index.js",
56
+ "./client": "./client.js",
57
+ "./package.json": "./package.json"
48
58
  }
49
59
  }