dsh-agent-team-playbook 1.27.0 → 1.28.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 +6 -1
- package/client.js +195 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,7 +108,12 @@ dsh plugin --profile web add dsh-agent-team-playbook
|
|
|
108
108
|
| `/atp apply 1=覆盖 2=备份 3=改名:x` | 对 install 列出的冲突**逐项决定**(覆盖 / 备份你的文件 / 我们这侧改名并同步引用) |
|
|
109
109
|
| `/atp help` | 用法 |
|
|
110
110
|
|
|
111
|
-
**Web / 桌面端还会多一个设置面板**(设置 →
|
|
111
|
+
**Web / 桌面端还会多一个设置面板**(设置 → 协作规程):
|
|
112
|
+
|
|
113
|
+
- 显示当前工作区是否已安装、有无同名冲突
|
|
114
|
+
- 有冲突时点「**逐项处理冲突…**」弹出对话框:每项可选 **覆盖 / 备份 / 改名**,底部「应用」
|
|
115
|
+
- 应用时会执行一条 `/atp apply …` 命令(与手动输入**等价**,会在会话里留下审计记录),因此插件**不新增任何写文件接口**
|
|
116
|
+
- 也可以只复制建议命令,自己粘贴执行
|
|
112
117
|
|
|
113
118
|
> dsh-go 手机原生界面不加载浏览器半身,因此没有这个面板——在那边用命令即可。
|
|
114
119
|
|
package/client.js
CHANGED
|
@@ -5,7 +5,12 @@
|
|
|
5
5
|
* 手写 window.__ModuleLoader__.load({ id, factory }),无构建步骤,
|
|
6
6
|
* require 由 shell 提供(react / primitives / slots …)。
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* 两步中的第二步:面板 + 冲突处理弹窗。
|
|
9
|
+
* 弹窗里逐项选择 覆盖 / 备份 / 改名,点"应用"后**通过 official Remote 执行**
|
|
10
|
+
* `remote.commands.execute(sessionId, '/atp apply …')` —— 与手动输入等价、有审计记录,
|
|
11
|
+
* 因此不需要任何自定义写文件接口。
|
|
12
|
+
*
|
|
13
|
+
* 面板本身仍然只读:
|
|
9
14
|
* · 显示当前工作区是否已安装、有无同名冲突
|
|
10
15
|
* · 冲突项可一键复制建议命令(真正的写入仍由用户执行 /atp apply,可见可审计)
|
|
11
16
|
* 不做任何写操作,也不直接调用命令。
|
|
@@ -25,6 +30,34 @@ window.__ModuleLoader__.load({
|
|
|
25
30
|
const NAME = 'dsh-agent-team-playbook'
|
|
26
31
|
const API = '/api/agent-team-playbook/status'
|
|
27
32
|
const Button = primitives?.Button
|
|
33
|
+
const Modal = primitives?.Modal
|
|
34
|
+
|
|
35
|
+
// ── 极简 store:面板与弹窗共享"待处理冲突"状态 ─────────────────────────
|
|
36
|
+
const store = { state: { open: false, cwd: '', sessionId: '', conflicts: [], busy: false, message: '' }, listeners: new Set() }
|
|
37
|
+
const readStore = () => store.state
|
|
38
|
+
const writeStore = (patch) => {
|
|
39
|
+
store.state = { ...store.state, ...patch }
|
|
40
|
+
for (const fn of store.listeners) fn()
|
|
41
|
+
}
|
|
42
|
+
const subscribeStore = (fn) => {
|
|
43
|
+
store.listeners.add(fn)
|
|
44
|
+
return () => store.listeners.delete(fn)
|
|
45
|
+
}
|
|
46
|
+
const useStore = () => {
|
|
47
|
+
const [snap, setSnap] = React.useState(readStore)
|
|
48
|
+
React.useEffect(() => subscribeStore(() => setSnap(readStore())), [])
|
|
49
|
+
return snap
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 把逐项选择拼成一条 /atp apply 命令(导出给测试)。 */
|
|
53
|
+
function buildApplySpec(choices) {
|
|
54
|
+
const parts = choices.map((c, i) => {
|
|
55
|
+
if (c.action === 'backup') return `${i + 1}=备份`
|
|
56
|
+
if (c.action === 'rename') return `${i + 1}=改名:${c.name}`
|
|
57
|
+
return `${i + 1}=覆盖`
|
|
58
|
+
})
|
|
59
|
+
return `/atp apply ${parts.join(' ')}`
|
|
60
|
+
}
|
|
28
61
|
|
|
29
62
|
/** 读一次状态;cwd 为空时只验证连通性。 */
|
|
30
63
|
async function fetchStatus(cwd) {
|
|
@@ -61,6 +94,144 @@ window.__ModuleLoader__.load({
|
|
|
61
94
|
return h('button', { type: 'button', onClick }, children)
|
|
62
95
|
}
|
|
63
96
|
|
|
97
|
+
/** 解析"当前会话"的 cwd 与 sessionId(客户端 sessions 快照)。 */
|
|
98
|
+
function currentSession(ctx) {
|
|
99
|
+
try {
|
|
100
|
+
const rows = ctx?.sessions?.list?.getSnapshot?.()?.byId ?? {}
|
|
101
|
+
const entries = Object.entries(rows)
|
|
102
|
+
const active = entries.find(([, row]) => (row?.retainedBy?.mainView ?? 0) > 0) ?? entries.find(([, row]) => typeof row?.cwd === 'string')
|
|
103
|
+
if (active === undefined) return {}
|
|
104
|
+
const [sessionId, row] = active
|
|
105
|
+
return { sessionId, cwd: typeof row?.cwd === 'string' ? row.cwd : undefined }
|
|
106
|
+
} catch {
|
|
107
|
+
return {}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** 单个冲突的选择行:覆盖 / 备份 / 改名 + 名字输入。 */
|
|
112
|
+
function ChoiceRow({ index, conflict, choice, onChoose, renameEnabled, onRename }) {
|
|
113
|
+
const btn = (action, text) => {
|
|
114
|
+
const active = choice?.action === action
|
|
115
|
+
const props = { key: action, onClick: () => onChoose(index, action) }
|
|
116
|
+
if (typeof Button === 'function') return h(Button, { ...props, variant: active ? 'primary' : 'outline' }, text)
|
|
117
|
+
return h('button', { ...props, type: 'button', style: { fontWeight: active ? 700 : 400 } }, text)
|
|
118
|
+
}
|
|
119
|
+
const children = [
|
|
120
|
+
h('div', { key: 'label', style: { wordBreak: 'break-all', marginBottom: 4 } }, `${index + 1}. ${conflict.rel}`),
|
|
121
|
+
h('div', { key: 'reason', style: { opacity: 0.6, fontSize: 12, marginBottom: 6 } }, conflict.reason),
|
|
122
|
+
h('div', { key: 'btns', style: { display: 'flex', gap: 6, flexWrap: 'wrap' } },
|
|
123
|
+
btn('overwrite', '覆盖'),
|
|
124
|
+
btn('backup', '备份'),
|
|
125
|
+
renameEnabled ? btn('rename', '改名…') : null),
|
|
126
|
+
]
|
|
127
|
+
if (choice?.action === 'rename') {
|
|
128
|
+
children.push(
|
|
129
|
+
h('div', { key: 'rename', style: { marginTop: 6 } },
|
|
130
|
+
h('input', {
|
|
131
|
+
value: choice.name ?? '',
|
|
132
|
+
placeholder: '新名字(如 team-docs / AGENTS.team.md)',
|
|
133
|
+
onChange: (e) => onRename(index, e.target.value),
|
|
134
|
+
style: { width: '100%', padding: '6px 8px', borderRadius: 6, border: '1px solid rgba(127,127,127,0.4)', background: 'transparent', color: 'inherit' },
|
|
135
|
+
}),
|
|
136
|
+
h('div', { style: { opacity: 0.55, fontSize: 12, marginTop: 4 } }, '整份改名:同一类(核心/分册)只需填一次'),
|
|
137
|
+
),
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
return h('div', { key: `row${index}`, style: { padding: '8px 0', borderTop: index === 0 ? 'none' : '1px solid rgba(127,127,127,0.18)' } }, children)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** 冲突处理弹窗(挂在 shell.overlay 上,关闭时渲染 null)。 */
|
|
144
|
+
function ResolveDialog() {
|
|
145
|
+
const state = useStore()
|
|
146
|
+
const [choices, setChoices] = React.useState([])
|
|
147
|
+
const [error, setError] = React.useState('')
|
|
148
|
+
|
|
149
|
+
React.useEffect(() => {
|
|
150
|
+
if (!state.open) return
|
|
151
|
+
setError('')
|
|
152
|
+
setChoices((state.conflicts ?? []).map(() => ({ action: 'overwrite' })))
|
|
153
|
+
}, [state.open, state.conflicts])
|
|
154
|
+
|
|
155
|
+
if (!state.open) return null
|
|
156
|
+
|
|
157
|
+
const isCoreRel = (rel) => rel === 'AGENTS.md'
|
|
158
|
+
const onChoose = (i, action) => {
|
|
159
|
+
setChoices((prev) => {
|
|
160
|
+
const next = [...prev]
|
|
161
|
+
next[i] = { ...(next[i] ?? {}), action }
|
|
162
|
+
return next
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
const onRename = (i, name) => {
|
|
166
|
+
setChoices((prev) => {
|
|
167
|
+
const next = [...prev]
|
|
168
|
+
next[i] = { ...(next[i] ?? {}), action: 'rename', name }
|
|
169
|
+
// 同一单元(核心/分册)共享同一个改名值
|
|
170
|
+
const unit = isCoreRel((state.conflicts ?? [])[i]?.rel ?? '')
|
|
171
|
+
next.forEach((c, j) => {
|
|
172
|
+
if (j !== i && isCoreRel((state.conflicts ?? [])[j]?.rel ?? '') === unit) next[j] = { ...(next[j] ?? {}), name }
|
|
173
|
+
})
|
|
174
|
+
return next
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const apply = async () => {
|
|
179
|
+
const conflicts = state.conflicts ?? []
|
|
180
|
+
const missing = choices.findIndex((c, i) => c?.action === 'rename' && !String(c.name ?? '').trim())
|
|
181
|
+
if (missing >= 0) {
|
|
182
|
+
setError(`第 ${missing + 1} 项选了改名但没填名字`)
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
if (!state.sessionId || typeof state.execute !== 'function') {
|
|
186
|
+
setError('拿不到当前会话,无法执行;请改用 /atp apply 命令')
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
writeStore({ busy: true })
|
|
191
|
+
const line = buildApplySpec(choices)
|
|
192
|
+
const result = await state.execute(state.sessionId, line)
|
|
193
|
+
if (result && result.ok === false) throw new Error(result?.error?.message ?? '命令执行失败')
|
|
194
|
+
writeStore({ open: false, busy: false, message: `已执行:${line}` })
|
|
195
|
+
if (typeof state.afterApply === 'function') await state.afterApply()
|
|
196
|
+
} catch (e) {
|
|
197
|
+
setError(String(e?.message ?? e))
|
|
198
|
+
writeStore({ busy: false })
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const footer = h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end' } },
|
|
203
|
+
typeof Button === 'function'
|
|
204
|
+
? h(Button, { variant: 'outline', onClick: () => writeStore({ open: false }) }, '取消')
|
|
205
|
+
: h('button', { type: 'button', onClick: () => writeStore({ open: false }) }, '取消'),
|
|
206
|
+
typeof Button === 'function'
|
|
207
|
+
? h(Button, { variant: 'primary', disabled: state.busy, onClick: () => void apply() }, state.busy ? '执行中…' : '应用')
|
|
208
|
+
: h('button', { type: 'button', disabled: state.busy, onClick: () => void apply() }, '应用'),
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
const body = [
|
|
212
|
+
h('div', { key: 'cwd', style: { opacity: 0.65, fontSize: 12, marginBottom: 10, wordBreak: 'break-all' } }, state.cwd),
|
|
213
|
+
...(state.conflicts ?? []).map((conflict, i) =>
|
|
214
|
+
h(ChoiceRow, {
|
|
215
|
+
key: `c${i}`,
|
|
216
|
+
index: i,
|
|
217
|
+
conflict,
|
|
218
|
+
choice: choices[i],
|
|
219
|
+
onChoose,
|
|
220
|
+
renameEnabled: true,
|
|
221
|
+
onRename,
|
|
222
|
+
})),
|
|
223
|
+
error ? h('div', { key: 'err', style: { color: 'var(--dsh-danger, #c0563b)', marginTop: 10 } }, error) : null,
|
|
224
|
+
h('div', { key: 'hint', style: { opacity: 0.55, fontSize: 12, marginTop: 12 } },
|
|
225
|
+
'点"应用"会执行一条 /atp apply 命令(与手动输入等价,可在会话里看到审计记录)。'),
|
|
226
|
+
].filter(Boolean)
|
|
227
|
+
|
|
228
|
+
if (typeof Modal !== 'function') {
|
|
229
|
+
return h('div', { style: { position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.5)', zIndex: 9999, padding: 20, overflow: 'auto' } },
|
|
230
|
+
h('div', { style: { background: 'var(--dsh-surface, #1b1b1b)', padding: 16, borderRadius: 10 } }, body, footer))
|
|
231
|
+
}
|
|
232
|
+
return h(Modal, { open: true, onClose: () => writeStore({ open: false }), title: '处理同名内容', closeLabel: '取消', footer }, body)
|
|
233
|
+
}
|
|
234
|
+
|
|
64
235
|
function Panel() {
|
|
65
236
|
const [state, setState] = useState({ phase: 'loading' })
|
|
66
237
|
const [copied, setCopied] = useState('')
|
|
@@ -122,6 +293,20 @@ window.__ModuleLoader__.load({
|
|
|
122
293
|
`${i + 1}. ${c.rel} — ${c.reason}`),
|
|
123
294
|
)
|
|
124
295
|
})
|
|
296
|
+
children.push(
|
|
297
|
+
h('div', { key: 'resolve', style: { marginTop: 8 } },
|
|
298
|
+
typeof Button === 'function'
|
|
299
|
+
? h(Button, {
|
|
300
|
+
variant: 'primary',
|
|
301
|
+
onClick: () => {
|
|
302
|
+
const ctx = Panel.ctx
|
|
303
|
+
const { sessionId, cwd } = currentSession(ctx)
|
|
304
|
+
const execute = async (sid, line) => ctx?.remote?.commands?.execute?.(sid, line, [])
|
|
305
|
+
writeStore({ open: true, conflicts, cwd: cwd ?? '', sessionId: sessionId ?? '', execute, afterApply: refresh })
|
|
306
|
+
},
|
|
307
|
+
}, '逐项处理冲突…')
|
|
308
|
+
: null),
|
|
309
|
+
)
|
|
125
310
|
children.push(
|
|
126
311
|
h('div', { key: 'sug', style: { marginTop: 8 } },
|
|
127
312
|
h('div', { style: { opacity: 0.65, marginBottom: 4 } }, '逐项决定后执行(可改 覆盖→备份 / 改名:新名):'),
|
|
@@ -157,11 +342,19 @@ window.__ModuleLoader__.load({
|
|
|
157
342
|
order: 36,
|
|
158
343
|
label: () => '协作规程',
|
|
159
344
|
}, () => h(Panel, null)))
|
|
345
|
+
|
|
346
|
+
// 冲突处理弹窗:常驻挂载,关闭时渲染 null
|
|
347
|
+
ctx.slots.inject('shell.overlay', () => ctx.slots.register({
|
|
348
|
+
name: 'shell.overlay',
|
|
349
|
+
id: 'agent-team-playbook.resolve',
|
|
350
|
+
}, () => h(ResolveDialog, null)))
|
|
160
351
|
}
|
|
161
352
|
|
|
162
353
|
exports.apply = apply
|
|
163
|
-
exports.inject = ['slots', 'sessions']
|
|
354
|
+
exports.inject = ['slots', 'sessions', 'remote.commands']
|
|
164
355
|
exports.name = NAME
|
|
356
|
+
// 测试缝:拼命令是纯函数,单独可测
|
|
357
|
+
exports.__test = { buildApplySpec }
|
|
165
358
|
return module.exports
|
|
166
359
|
},
|
|
167
360
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-agent-team-playbook",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.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",
|