dsh-agent-team-playbook 1.31.1 → 1.32.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 +10 -1
- package/client.js +88 -16
- package/lib/index.js +65 -8
- package/lib/install.js +36 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,11 +103,20 @@ dsh plugin --profile web add dsh-agent-team-playbook
|
|
|
103
103
|
| `/atp` | 规程摘要(档位、四问、收尾三问)+ 安装方式 |
|
|
104
104
|
| `/atp core` | 输出核心全文,读完即在本轮按它协作 |
|
|
105
105
|
| `/atp paths` | 各分册的绝对路径,按需查阅 |
|
|
106
|
-
| `/atp install` | 把 playbook
|
|
106
|
+
| `/atp install` | 把 playbook **原子安装进当前工作区**(内容相同视为已安装,可重复执行;内容不同则列出冲突,不覆盖) |
|
|
107
107
|
| `/atp install force` | 覆盖同名内容后安装(先暂存原件,失败自动回滚) |
|
|
108
108
|
| `/atp apply 1=覆盖 2=备份 3=改名:x` | 对 install 列出的冲突**逐项决定**(覆盖 / 备份你的文件 / 我们这侧改名并同步引用) |
|
|
109
109
|
| `/atp help` | 用法 |
|
|
110
110
|
|
|
111
|
+
**行为说明(已实测)**:
|
|
112
|
+
|
|
113
|
+
- **重复安装是幂等的**:内容相同不算冲突,`/atp install` 可以反复跑
|
|
114
|
+
- **改名是整份改名**:分册→整个 `docs/`,核心→`AGENTS.md`;你的同名文件原样保留,文档内引用会自动改写
|
|
115
|
+
- **改名后的核心不会被自动加载**:DSH 只读 `AGENTS.md` / `CLAUDE.md` 等固定文件名,把核心改名等于放弃常驻注入(命令会明确告警)
|
|
116
|
+
- **编号漂移保护**:命令带 `count=N`,如果两次之间工作区变了会拒绝执行,避免决策套到别的文件上
|
|
117
|
+
- **改名遇同名目标会拒绝**(不覆盖);名字不能是 `.`/`..`、不能含 `/`;含空格的名字用引号
|
|
118
|
+
- **失败会自动回滚**:安装中途失败会恢复你的原件,不留残留
|
|
119
|
+
|
|
111
120
|
**Web / 桌面端有两个入口**:
|
|
112
121
|
|
|
113
122
|
1. **首页 chip 行**(与「音乐制作 / 标准模式」并排)的「协作规程」——有冲突时角标显示数量,点一下:有冲突弹出处理框、无冲突直接安装
|
package/client.js
CHANGED
|
@@ -80,10 +80,14 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
80
80
|
function buildApplySpec(choices) {
|
|
81
81
|
const parts = choices.map((c, i) => {
|
|
82
82
|
if (c.action === 'backup') return `${i + 1}=备份`
|
|
83
|
-
if (c.action === 'rename')
|
|
83
|
+
if (c.action === 'rename') {
|
|
84
|
+
const name = String(c.name)
|
|
85
|
+
return `${i + 1}=改名:${/\s/.test(name) ? `"${name}"` : name}`
|
|
86
|
+
}
|
|
84
87
|
return `${i + 1}=覆盖`
|
|
85
88
|
})
|
|
86
|
-
|
|
89
|
+
// count 让后端校验"冲突清单没变过",避免决策套到别的文件上
|
|
90
|
+
return `/atp apply count=${choices.length} ${parts.join(' ')}`
|
|
87
91
|
}
|
|
88
92
|
|
|
89
93
|
/** 读一次状态;cwd 为空时只验证连通性。 */
|
|
@@ -116,9 +120,26 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
116
120
|
)
|
|
117
121
|
}
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
/** 文字链式按钮(无边框),hover 出淡底;primary 用主色加粗。 */
|
|
124
|
+
function LinkButton({ onClick, children, primary = false }) {
|
|
125
|
+
const [hover, setHover] = React.useState(false)
|
|
126
|
+
return h('button', {
|
|
127
|
+
type: 'button',
|
|
128
|
+
style: {
|
|
129
|
+
border: 0,
|
|
130
|
+
borderRadius: 6,
|
|
131
|
+
background: hover ? 'var(--dsw-alias-interactive-bg-hover, rgba(127,127,127,.18))' : 'none',
|
|
132
|
+
color: primary ? 'var(--dsw-alias-label-primary, inherit)' : 'var(--dsw-alias-label-secondary, #98a2b3)',
|
|
133
|
+
font: 'inherit',
|
|
134
|
+
fontSize: 13,
|
|
135
|
+
fontWeight: primary ? 600 : 400,
|
|
136
|
+
padding: '4px 8px',
|
|
137
|
+
cursor: 'pointer',
|
|
138
|
+
},
|
|
139
|
+
onMouseEnter: () => setHover(true),
|
|
140
|
+
onMouseLeave: () => setHover(false),
|
|
141
|
+
onClick,
|
|
142
|
+
}, children)
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
/** 解析"当前会话"的 cwd 与 sessionId(客户端 sessions 快照)。 */
|
|
@@ -162,7 +183,10 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
162
183
|
writeStore({ open: true, conflicts: found, cwd: cwd ?? '', sessionId: sessionId ?? '', execute, afterApply: onDone })
|
|
163
184
|
return { started: true, conflicts: found.length }
|
|
164
185
|
}
|
|
165
|
-
await execute(sessionId, '/atp install')
|
|
186
|
+
const result = await execute(sessionId, '/atp install')
|
|
187
|
+
if (result && result.ok === false) {
|
|
188
|
+
return { started: false, conflicts: 0, error: result?.error?.message ?? '安装命令执行失败' }
|
|
189
|
+
}
|
|
166
190
|
if (typeof onDone === 'function') await onDone()
|
|
167
191
|
return { started: true, conflicts: 0 }
|
|
168
192
|
} catch (error) {
|
|
@@ -177,10 +201,13 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
177
201
|
const [renaming, setRenaming] = React.useState(false)
|
|
178
202
|
const [name, setName] = React.useState('')
|
|
179
203
|
|
|
204
|
+
const [hoverKey, setHoverKey] = React.useState('')
|
|
180
205
|
const pill = (text, onClick, key) => h('button', {
|
|
181
206
|
key,
|
|
182
207
|
type: 'button',
|
|
183
|
-
style: S.pill,
|
|
208
|
+
style: { ...S.pill, ...(hoverKey === key ? S.pillHover : null) },
|
|
209
|
+
onMouseEnter: () => setHoverKey(key),
|
|
210
|
+
onMouseLeave: () => setHoverKey(''),
|
|
184
211
|
onClick,
|
|
185
212
|
}, text)
|
|
186
213
|
|
|
@@ -196,7 +223,16 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
196
223
|
}),
|
|
197
224
|
pill('确定', () => {
|
|
198
225
|
const clean = String(name).trim()
|
|
199
|
-
if (clean
|
|
226
|
+
if (clean === '') return
|
|
227
|
+
if (/[/\\]/.test(clean)) {
|
|
228
|
+
setName(`${clean}!名字不能含 / 或 \\`)
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
if (clean === '.' || clean === '..') {
|
|
232
|
+
setName('..!名字不能是 . 或 ..')
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
onDecide(index, 'rename', clean)
|
|
200
236
|
}, 'ok'),
|
|
201
237
|
pill('取消', () => setRenaming(false), 'no'))
|
|
202
238
|
}
|
|
@@ -207,7 +243,9 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
207
243
|
shortName(conflict.rel)),
|
|
208
244
|
h('div', { style: S.actions },
|
|
209
245
|
pill('覆盖', () => onDecide(index, 'overwrite'), 'ow'),
|
|
246
|
+
h('span', { key: 's1', style: S.sep }, '·'),
|
|
210
247
|
pill('备份', () => onDecide(index, 'backup'), 'bk'),
|
|
248
|
+
h('span', { key: 's2', style: S.sep }, '·'),
|
|
211
249
|
pill('改名', () => setRenaming(true), 'rn')))
|
|
212
250
|
}
|
|
213
251
|
|
|
@@ -251,13 +289,24 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
251
289
|
runningRef.current = false
|
|
252
290
|
return
|
|
253
291
|
}
|
|
292
|
+
// 同一单元只能有一个名字;出现两个不同名字时拦下来,别让后者被静默覆盖
|
|
293
|
+
const coreNames = new Set(choices.filter((c, i) => c.action === 'rename' && conflicts[i].rel === 'AGENTS.md').map((c) => String(c.name).trim()))
|
|
294
|
+
const docsNames = new Set(choices.filter((c, i) => c.action === 'rename' && conflicts[i].rel !== 'AGENTS.md').map((c) => String(c.name).trim()))
|
|
295
|
+
if (coreNames.size > 1 || docsNames.size > 1) {
|
|
296
|
+
setError('同一类(核心 / 分册)只能填一个名字')
|
|
297
|
+
runningRef.current = false
|
|
298
|
+
return
|
|
299
|
+
}
|
|
254
300
|
const line = buildApplySpec(normalized)
|
|
255
301
|
const result = await state.execute(state.sessionId, line)
|
|
256
302
|
if (result && result.ok === false) throw new Error(result?.error?.message ?? '命令执行失败')
|
|
257
303
|
writeStore({ open: false })
|
|
258
304
|
if (typeof state.afterApply === 'function') await state.afterApply()
|
|
259
305
|
} catch (e) {
|
|
260
|
-
setError(String(e?.message ?? e))
|
|
306
|
+
setError(`${String(e?.message ?? e)}(已恢复清单,可重新选择)`)
|
|
307
|
+
// 恢复列表:否则用户看着错误但无行可点,只能取消重来
|
|
308
|
+
decidedRef.current = new Map()
|
|
309
|
+
setDecidedCount(0)
|
|
261
310
|
runningRef.current = false
|
|
262
311
|
}
|
|
263
312
|
}
|
|
@@ -277,6 +326,7 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
277
326
|
}
|
|
278
327
|
|
|
279
328
|
const remaining = conflicts.length - decidedCount
|
|
329
|
+
const anyRename = [...decidedRef.current.values()].some((c) => c.action === 'rename')
|
|
280
330
|
const rows = conflicts
|
|
281
331
|
.map((conflict, index) => ({ conflict, index }))
|
|
282
332
|
.filter(({ index }) => !decidedRef.current.has(index))
|
|
@@ -290,10 +340,14 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
290
340
|
const body = [
|
|
291
341
|
h('div', { key: 'bar', style: S.toolbar },
|
|
292
342
|
h('span', { style: S.muted }, `还剩 ${remaining} 项`),
|
|
293
|
-
h('button', { type: 'button', style: S.pill, onClick: () => decideAll('overwrite') }, '全部覆盖'),
|
|
294
|
-
h('button', { type: 'button', style: S.pill, onClick: () => decideAll('backup') }, '全部备份')),
|
|
343
|
+
h('button', { type: 'button', style: { ...S.pill, color: 'var(--dsw-alias-label-primary, inherit)' }, onClick: () => decideAll('overwrite') }, '全部覆盖'),
|
|
344
|
+
h('button', { type: 'button', style: { ...S.pill, color: 'var(--dsw-alias-label-primary, inherit)' }, onClick: () => decideAll('backup') }, '全部备份')),
|
|
295
345
|
h('div', { key: 'list', style: S.dialogBody },
|
|
296
346
|
rows.length > 0 ? rows : h('div', { style: S.muted }, '已全部决定,正在执行…')),
|
|
347
|
+
anyRename
|
|
348
|
+
? h('div', { key: 'rn', style: { ...S.muted, marginTop: 6, lineHeight: 1.5 } },
|
|
349
|
+
'改名是「整份改名」:分册→整个 docs 目录,核心→AGENTS.md。改名后的核心不会被 DSH 自动注入。')
|
|
350
|
+
: null,
|
|
297
351
|
error ? h('div', { key: 'err', style: { color: 'var(--dsw-alias-label-danger, #e06c5a)', marginTop: 8, fontSize: 12 } }, error) : null,
|
|
298
352
|
h('div', { key: 'hint', style: { ...S.muted, marginTop: 8, lineHeight: 1.4 } },
|
|
299
353
|
'点一项即定案,全部决定后自动执行一条 /atp apply。'),
|
|
@@ -338,11 +392,14 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
338
392
|
},
|
|
339
393
|
fileName: { flex: '1 1 auto', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', fontSize: 13 },
|
|
340
394
|
actions: { flex: 'none', display: 'flex', gap: 4 },
|
|
395
|
+
// 极简文字操作:默认只是灰色小字,悬停才出淡底(无边框、无灰块)
|
|
341
396
|
pill: {
|
|
342
|
-
minHeight:
|
|
343
|
-
|
|
344
|
-
|
|
397
|
+
minHeight: 22, padding: '0 6px', borderRadius: 6, border: 0, background: 'none',
|
|
398
|
+
color: 'var(--dsw-alias-label-secondary, #98a2b3)', font: 'inherit', fontSize: 12,
|
|
399
|
+
cursor: 'pointer', lineHeight: '22px', whiteSpace: 'nowrap',
|
|
345
400
|
},
|
|
401
|
+
pillHover: { background: 'var(--dsw-alias-interactive-bg-hover, rgba(127,127,127,.18))', color: 'var(--dsw-alias-label-primary, inherit)' },
|
|
402
|
+
sep: { opacity: 0.28, fontSize: 12, userSelect: 'none' },
|
|
346
403
|
muted: { fontSize: 12, opacity: 0.6 },
|
|
347
404
|
}
|
|
348
405
|
|
|
@@ -390,14 +447,29 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
390
447
|
return () => document.removeEventListener('pointerdown', onDown, true)
|
|
391
448
|
}, [open])
|
|
392
449
|
|
|
450
|
+
const refreshBadge = async () => {
|
|
451
|
+
try {
|
|
452
|
+
const { cwd } = currentSession(HeroEntry.ctx)
|
|
453
|
+
const data = await fetchStatus(cwd)
|
|
454
|
+
const n = data?.conflicts?.length ?? 0
|
|
455
|
+
setBadge(n > 0 ? ` · ${n}` : '')
|
|
456
|
+
} catch {
|
|
457
|
+
/* 静默 */
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
393
461
|
const run = async (fn) => {
|
|
394
462
|
setOpen(false)
|
|
395
463
|
if (busy) return
|
|
396
464
|
setBusy(true)
|
|
397
465
|
try {
|
|
398
|
-
await fn()
|
|
466
|
+
const res = await fn()
|
|
467
|
+
if (res !== undefined && res !== null && res.started === false && res.error) {
|
|
468
|
+
console.warn('agent-team-playbook:', res.error)
|
|
469
|
+
}
|
|
399
470
|
} finally {
|
|
400
471
|
setBusy(false)
|
|
472
|
+
void refreshBadge()
|
|
401
473
|
}
|
|
402
474
|
}
|
|
403
475
|
|
|
@@ -569,7 +641,7 @@ div:has(> .atp-wrap){ margin-left: 0 !important; }
|
|
|
569
641
|
|
|
570
642
|
children.push(
|
|
571
643
|
h('div', { key: 'actions', style: { marginTop: 10, display: 'flex', gap: 8, flexWrap: 'wrap' } },
|
|
572
|
-
h(LinkButton, { onClick: () => void install() }, '安装到工作区'),
|
|
644
|
+
h(LinkButton, { onClick: () => void install(), primary: true }, '安装到工作区'),
|
|
573
645
|
h(LinkButton, { onClick: () => void refresh() }, '重新检测'),
|
|
574
646
|
h(LinkButton, { onClick: () => void copy('/atp install') }, copied === '/atp install' ? '已复制 ✓' : '复制 /atp install')),
|
|
575
647
|
)
|
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, scan, CORE_FILE, DOCS_DIR } from './install.js'
|
|
20
|
+
import { installAtomic, scan, CORE_FILE, DOCS_DIR, OURS_SIGNATURE } from './install.js'
|
|
21
21
|
|
|
22
22
|
export const name = 'dsh-agent-team-playbook'
|
|
23
23
|
|
|
@@ -132,10 +132,37 @@ function unitOfRel(rel) {
|
|
|
132
132
|
|
|
133
133
|
/** 解析 /atp apply 的决策串。 */
|
|
134
134
|
function parseApplySpec(raw) {
|
|
135
|
-
|
|
135
|
+
// 分词:逐字符解析,引号内允许空格(/atp apply 3=改名:"team docs")
|
|
136
|
+
const tokenize = (text) => {
|
|
137
|
+
const tokens = []
|
|
138
|
+
let cur = ''
|
|
139
|
+
let inQuote = false
|
|
140
|
+
for (const ch of String(text)) {
|
|
141
|
+
if (ch === '"') {
|
|
142
|
+
inQuote = !inQuote
|
|
143
|
+
continue
|
|
144
|
+
}
|
|
145
|
+
if (!inQuote && (/\s/.test(ch) || ch === ',' || ch === ',')) {
|
|
146
|
+
if (cur !== '') tokens.push(cur)
|
|
147
|
+
cur = ''
|
|
148
|
+
continue
|
|
149
|
+
}
|
|
150
|
+
cur += ch
|
|
151
|
+
}
|
|
152
|
+
if (cur !== '') tokens.push(cur)
|
|
153
|
+
return tokens
|
|
154
|
+
}
|
|
155
|
+
const tokens = tokenize(raw)
|
|
136
156
|
const perIndex = new Map()
|
|
137
157
|
const globals = []
|
|
158
|
+
let expectedCount
|
|
159
|
+
|
|
138
160
|
for (const tk of tokens) {
|
|
161
|
+
const countMatch = /^count=(\d+)$/i.exec(tk)
|
|
162
|
+
if (countMatch !== null) {
|
|
163
|
+
expectedCount = Number(countMatch[1])
|
|
164
|
+
continue
|
|
165
|
+
}
|
|
139
166
|
const m = /^(\d+|all)=(.+)$/i.exec(tk)
|
|
140
167
|
if (!m) return { error: `无法识别「${tk}」。格式:1=覆盖 / 2=备份 / 3=改名:名字 / all=覆盖` }
|
|
141
168
|
const idx = m[1].toLowerCase()
|
|
@@ -146,10 +173,11 @@ function parseApplySpec(raw) {
|
|
|
146
173
|
const name = rm[2]?.trim()
|
|
147
174
|
if (action === 'rename' && !name) return { error: `改名需要给出新名字:${tk}` }
|
|
148
175
|
if (name !== undefined && !/^[^/\\]+$/.test(name)) return { error: `名字不能含路径分隔符:${name}` }
|
|
176
|
+
if (name === '.' || name === '..') return { error: `名字不能是 . 或 ..` }
|
|
149
177
|
if (idx === 'all') globals.push({ action, name })
|
|
150
178
|
else perIndex.set(Number(idx), { action, name })
|
|
151
179
|
}
|
|
152
|
-
return { perIndex, globals }
|
|
180
|
+
return { perIndex, globals, expectedCount }
|
|
153
181
|
}
|
|
154
182
|
|
|
155
183
|
/** 处理 /atp apply:对当前冲突逐项决定后安装。 */
|
|
@@ -178,6 +206,16 @@ async function handleApply(ctx, rawInput, invocation) {
|
|
|
178
206
|
}
|
|
179
207
|
|
|
180
208
|
const list = numberedConflicts(conflicts)
|
|
209
|
+
// 编号漂移保护:清单在 install 之后变过,就拒绝执行(否则决策会套到别的文件上)
|
|
210
|
+
if (parsed.expectedCount !== undefined && parsed.expectedCount !== list.length) {
|
|
211
|
+
return {
|
|
212
|
+
kind: 'error',
|
|
213
|
+
text: [
|
|
214
|
+
`冲突清单已变化(当时 ${parsed.expectedCount} 项,现在 ${list.length} 项),已拒绝执行以免套错文件。`,
|
|
215
|
+
'请重新运行 /atp install 或点面板「重新检测」后再决定。',
|
|
216
|
+
].join('\n'),
|
|
217
|
+
}
|
|
218
|
+
}
|
|
181
219
|
const decisions = []
|
|
182
220
|
const missing = []
|
|
183
221
|
const renameByUnit = new Map()
|
|
@@ -239,7 +277,12 @@ async function handleApply(ctx, rawInput, invocation) {
|
|
|
239
277
|
const lines = [`已安装到:${targetDir}(${result.installed.length} 个文件,核心与分册整体落地)`]
|
|
240
278
|
if (result.backups.length > 0) lines.push(`已备份你的文件:${result.backups.map((b) => path.relative(targetDir, b.to)).join(',')}`)
|
|
241
279
|
if (renames.length > 0) lines.push(`按你的改名安装:${renames.map((r) => `${r.from} → ${r.to}`).join(',')}(文档内引用已同步)`)
|
|
242
|
-
|
|
280
|
+
if (renameByUnit.has(CORE_FILE)) {
|
|
281
|
+
lines.push('', `注意:核心已改名为 ${renameByUnit.get(CORE_FILE)}。DSH 只会自动注入 AGENTS.md / CLAUDE.md 等固定文件名,改名后的核心不会被自动加载——如需常驻生效,请把它改回 AGENTS.md 或手动引用。`)
|
|
282
|
+
}
|
|
283
|
+
lines.push('', renameByUnit.has(CORE_FILE)
|
|
284
|
+
? '重载会话后生效;核心改名后需要你手动引用,或把它改回 AGENTS.md。'
|
|
285
|
+
: '工作区 AGENTS.md 会被 DSH 每轮自动注入,重载会话后生效。')
|
|
243
286
|
return { kind: 'success', text: lines.join('\n') }
|
|
244
287
|
}
|
|
245
288
|
|
|
@@ -283,7 +326,7 @@ async function handleInstall(ctx, rawInput, invocation) {
|
|
|
283
326
|
...rows,
|
|
284
327
|
'',
|
|
285
328
|
'逐项决定后安装(动作:覆盖 / 备份(你的文件加后缀保留) / 改名:新名(我们这侧换名)):',
|
|
286
|
-
` /atp apply ${list.map((_, i) => `${i + 1}=覆盖`).join(' ')}`,
|
|
329
|
+
` /atp apply count=${list.length} ${list.map((_, i) => `${i + 1}=覆盖`).join(' ')}`,
|
|
287
330
|
' 例:/atp apply 1=备份 2=改名:team-docs',
|
|
288
331
|
'',
|
|
289
332
|
'或一次性覆盖:/atp install force',
|
|
@@ -340,6 +383,15 @@ function handleCommand(ctx, invocation) {
|
|
|
340
383
|
* @param {import('node:http').IncomingMessage} req
|
|
341
384
|
* @param {import('node:http').ServerResponse} res
|
|
342
385
|
*/
|
|
386
|
+
/** 读文件内容,失败返回空串(不动用异常路径)。 */
|
|
387
|
+
function readFileSyncSafe(file) {
|
|
388
|
+
try {
|
|
389
|
+
return readFileSync(file, 'utf8')
|
|
390
|
+
} catch {
|
|
391
|
+
return ''
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
343
395
|
export function createStatusHandler() {
|
|
344
396
|
return async function statusHandler(req, res) {
|
|
345
397
|
const send = (status, payload) => {
|
|
@@ -357,13 +409,18 @@ export function createStatusHandler() {
|
|
|
357
409
|
return send(400, { ok: false, error: 'cwd 不存在或不是绝对路径' })
|
|
358
410
|
}
|
|
359
411
|
const { conflicts } = await scan({ sourceRoot: PLAYBOOK_DIR, targetDir })
|
|
360
|
-
|
|
412
|
+
// 已安装判定按内容签名,而不是"路径存在"——否则改名安装会被误判成未安装
|
|
413
|
+
const corePath = path.join(targetDir, CORE_FILE)
|
|
414
|
+
const coreOurs = existsSync(corePath) && readFileSyncSafe(corePath).includes(OURS_SIGNATURE)
|
|
415
|
+
const docsOurs = existsSync(path.join(targetDir, DOCS_DIR, 'workflow', 'rules', '01-总纲细则.md'))
|
|
361
416
|
return send(200, {
|
|
362
417
|
ok: true,
|
|
363
418
|
connected: true,
|
|
364
419
|
cwd: targetDir,
|
|
365
|
-
installed,
|
|
366
|
-
|
|
420
|
+
installed: coreOurs && docsOurs,
|
|
421
|
+
coreInstalled: coreOurs,
|
|
422
|
+
docsInstalled: docsOurs,
|
|
423
|
+
conflicts: conflicts.map((c) => ({ rel: c.rel, reason: c.reason, ours: c.ours === true })),
|
|
367
424
|
})
|
|
368
425
|
} catch (error) {
|
|
369
426
|
return send(500, { ok: false, error: String(error?.message ?? error) })
|
package/lib/install.js
CHANGED
|
@@ -15,6 +15,8 @@ import { existsSync } from 'node:fs'
|
|
|
15
15
|
import path from 'node:path'
|
|
16
16
|
|
|
17
17
|
/** 会被安装进用户项目的单元:核心文件 + 分册目录。 */
|
|
18
|
+
/** 我们自己写下的核心文件里必然出现的签名,用于识别「已安装 / 已改名安装」。 */
|
|
19
|
+
export const OURS_SIGNATURE = '# AGENTS.md(常驻核心'
|
|
18
20
|
export const CORE_FILE = 'AGENTS.md'
|
|
19
21
|
export const DOCS_DIR = 'docs'
|
|
20
22
|
|
|
@@ -43,12 +45,41 @@ export async function listFiles(rootDir, relDir) {
|
|
|
43
45
|
* 检测目标路径的冲突。`target` 是"改已有项"时要动的路径。
|
|
44
46
|
* @returns {Promise<null | {reason: string, kind: 'file'|'dir'|'parent-file', target: string}>}
|
|
45
47
|
*/
|
|
46
|
-
|
|
48
|
+
/**
|
|
49
|
+
* 判断一个目标路径是否构成"冲突"。
|
|
50
|
+
*
|
|
51
|
+
* 关键:**内容完全相同不算冲突**。否则重复安装时会把上一次装好的我们自己的文件
|
|
52
|
+
* 也报成冲突(用户看到"15 处同名内容"却全是自己刚装的),既困惑又阻碍幂等。
|
|
53
|
+
*
|
|
54
|
+
* @param {string} destAbs 目标绝对路径
|
|
55
|
+
* @param {string} [sourceAbs] 对应源文件绝对路径;给了就做内容比对
|
|
56
|
+
*/
|
|
57
|
+
export async function inspectConflict(destAbs, sourceAbs) {
|
|
47
58
|
if (existsSync(destAbs)) {
|
|
48
59
|
const s = await stat(destAbs)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
if (s.isDirectory()) return { reason: '同名位置已是目录', kind: 'dir', target: destAbs }
|
|
61
|
+
if (typeof sourceAbs === 'string' && existsSync(sourceAbs)) {
|
|
62
|
+
try {
|
|
63
|
+
const src = await readFile(sourceAbs)
|
|
64
|
+
const dst = await readFile(destAbs)
|
|
65
|
+
if (src.length === dst.length && src.equals(dst)) return null
|
|
66
|
+
} catch {
|
|
67
|
+
/* 读不了就按冲突处理(保守) */
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// 内容不同:区分「用户自己的文件」与「本插件之前装的(引用已按改名改写)」
|
|
71
|
+
let ours = false
|
|
72
|
+
try {
|
|
73
|
+
ours = (await readFile(destAbs, 'utf8')).includes(OURS_SIGNATURE)
|
|
74
|
+
} catch {
|
|
75
|
+
/* 读不了就当不是我们的 */
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
reason: ours ? '本插件之前装的版本(引用已按改名改写)' : '文件内容不同',
|
|
79
|
+
kind: 'file',
|
|
80
|
+
target: destAbs,
|
|
81
|
+
ours,
|
|
82
|
+
}
|
|
52
83
|
}
|
|
53
84
|
let p = path.dirname(destAbs)
|
|
54
85
|
while (p && p !== path.dirname(p)) {
|
|
@@ -96,7 +127,7 @@ export async function scan({ sourceRoot, targetDir }) {
|
|
|
96
127
|
const conflicts = []
|
|
97
128
|
for (const u of units) {
|
|
98
129
|
for (const rel of u.files) {
|
|
99
|
-
const c = await inspectConflict(path.join(targetDir, rel))
|
|
130
|
+
const c = await inspectConflict(path.join(targetDir, rel), path.join(sourceRoot, rel))
|
|
100
131
|
if (c !== null) conflicts.push({ unit: u.key, rel, ...c })
|
|
101
132
|
}
|
|
102
133
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-agent-team-playbook",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.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",
|