dsh-agent-team-playbook 1.27.0 → 1.29.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.
Files changed (3) hide show
  1. package/README.md +8 -1
  2. package/client.js +231 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -108,7 +108,14 @@ 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 / 桌面端还会多一个设置面板**(设置 → 协作规程):显示当前工作区是否已安装、有无同名冲突,并可一键复制建议的处理命令。面板**只读**,不改你任何文件;真正的写入仍走 `/atp install` / `/atp apply`(可见、可审计)。
111
+ **Web / 桌面端还会多一个设置面板**(设置 → 协作规程):
112
+
113
+ - 显示当前工作区是否已安装、有无同名冲突
114
+ - 点「**安装到工作区**」:无冲突直接装;**有冲突会直接弹出处理对话框**(不用先执行命令)
115
+ - 打开面板时若已存在冲突,也会**自动弹一次**
116
+ - 对话框每项可选 **覆盖 / 备份 / 改名**,底部「应用」
117
+ - 应用时会执行一条 `/atp apply …` 命令(与手动输入**等价**,会在会话里留下审计记录),因此插件**不新增任何写文件接口**
118
+ - 也可以只复制建议命令,自己粘贴执行
112
119
 
113
120
  > dsh-go 手机原生界面不加载浏览器半身,因此没有这个面板——在那边用命令即可。
114
121
 
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,35 @@ 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
+ let autoOpened = ''
47
+ const useStore = () => {
48
+ const [snap, setSnap] = React.useState(readStore)
49
+ React.useEffect(() => subscribeStore(() => setSnap(readStore())), [])
50
+ return snap
51
+ }
52
+
53
+ /** 把逐项选择拼成一条 /atp apply 命令(导出给测试)。 */
54
+ function buildApplySpec(choices) {
55
+ const parts = choices.map((c, i) => {
56
+ if (c.action === 'backup') return `${i + 1}=备份`
57
+ if (c.action === 'rename') return `${i + 1}=改名:${c.name}`
58
+ return `${i + 1}=覆盖`
59
+ })
60
+ return `/atp apply ${parts.join(' ')}`
61
+ }
28
62
 
29
63
  /** 读一次状态;cwd 为空时只验证连通性。 */
30
64
  async function fetchStatus(cwd) {
@@ -61,6 +95,144 @@ window.__ModuleLoader__.load({
61
95
  return h('button', { type: 'button', onClick }, children)
62
96
  }
63
97
 
98
+ /** 解析"当前会话"的 cwd 与 sessionId(客户端 sessions 快照)。 */
99
+ function currentSession(ctx) {
100
+ try {
101
+ const rows = ctx?.sessions?.list?.getSnapshot?.()?.byId ?? {}
102
+ const entries = Object.entries(rows)
103
+ const active = entries.find(([, row]) => (row?.retainedBy?.mainView ?? 0) > 0) ?? entries.find(([, row]) => typeof row?.cwd === 'string')
104
+ if (active === undefined) return {}
105
+ const [sessionId, row] = active
106
+ return { sessionId, cwd: typeof row?.cwd === 'string' ? row.cwd : undefined }
107
+ } catch {
108
+ return {}
109
+ }
110
+ }
111
+
112
+ /** 单个冲突的选择行:覆盖 / 备份 / 改名 + 名字输入。 */
113
+ function ChoiceRow({ index, conflict, choice, onChoose, renameEnabled, onRename }) {
114
+ const btn = (action, text) => {
115
+ const active = choice?.action === action
116
+ const props = { key: action, onClick: () => onChoose(index, action) }
117
+ if (typeof Button === 'function') return h(Button, { ...props, variant: active ? 'primary' : 'outline' }, text)
118
+ return h('button', { ...props, type: 'button', style: { fontWeight: active ? 700 : 400 } }, text)
119
+ }
120
+ const children = [
121
+ h('div', { key: 'label', style: { wordBreak: 'break-all', marginBottom: 4 } }, `${index + 1}. ${conflict.rel}`),
122
+ h('div', { key: 'reason', style: { opacity: 0.6, fontSize: 12, marginBottom: 6 } }, conflict.reason),
123
+ h('div', { key: 'btns', style: { display: 'flex', gap: 6, flexWrap: 'wrap' } },
124
+ btn('overwrite', '覆盖'),
125
+ btn('backup', '备份'),
126
+ renameEnabled ? btn('rename', '改名…') : null),
127
+ ]
128
+ if (choice?.action === 'rename') {
129
+ children.push(
130
+ h('div', { key: 'rename', style: { marginTop: 6 } },
131
+ h('input', {
132
+ value: choice.name ?? '',
133
+ placeholder: '新名字(如 team-docs / AGENTS.team.md)',
134
+ onChange: (e) => onRename(index, e.target.value),
135
+ style: { width: '100%', padding: '6px 8px', borderRadius: 6, border: '1px solid rgba(127,127,127,0.4)', background: 'transparent', color: 'inherit' },
136
+ }),
137
+ h('div', { style: { opacity: 0.55, fontSize: 12, marginTop: 4 } }, '整份改名:同一类(核心/分册)只需填一次'),
138
+ ),
139
+ )
140
+ }
141
+ return h('div', { key: `row${index}`, style: { padding: '8px 0', borderTop: index === 0 ? 'none' : '1px solid rgba(127,127,127,0.18)' } }, children)
142
+ }
143
+
144
+ /** 冲突处理弹窗(挂在 shell.overlay 上,关闭时渲染 null)。 */
145
+ function ResolveDialog() {
146
+ const state = useStore()
147
+ const [choices, setChoices] = React.useState([])
148
+ const [error, setError] = React.useState('')
149
+
150
+ React.useEffect(() => {
151
+ if (!state.open) return
152
+ setError('')
153
+ setChoices((state.conflicts ?? []).map(() => ({ action: 'overwrite' })))
154
+ }, [state.open, state.conflicts])
155
+
156
+ if (!state.open) return null
157
+
158
+ const isCoreRel = (rel) => rel === 'AGENTS.md'
159
+ const onChoose = (i, action) => {
160
+ setChoices((prev) => {
161
+ const next = [...prev]
162
+ next[i] = { ...(next[i] ?? {}), action }
163
+ return next
164
+ })
165
+ }
166
+ const onRename = (i, name) => {
167
+ setChoices((prev) => {
168
+ const next = [...prev]
169
+ next[i] = { ...(next[i] ?? {}), action: 'rename', name }
170
+ // 同一单元(核心/分册)共享同一个改名值
171
+ const unit = isCoreRel((state.conflicts ?? [])[i]?.rel ?? '')
172
+ next.forEach((c, j) => {
173
+ if (j !== i && isCoreRel((state.conflicts ?? [])[j]?.rel ?? '') === unit) next[j] = { ...(next[j] ?? {}), name }
174
+ })
175
+ return next
176
+ })
177
+ }
178
+
179
+ const apply = async () => {
180
+ const conflicts = state.conflicts ?? []
181
+ const missing = choices.findIndex((c, i) => c?.action === 'rename' && !String(c.name ?? '').trim())
182
+ if (missing >= 0) {
183
+ setError(`第 ${missing + 1} 项选了改名但没填名字`)
184
+ return
185
+ }
186
+ if (!state.sessionId || typeof state.execute !== 'function') {
187
+ setError('拿不到当前会话,无法执行;请改用 /atp apply 命令')
188
+ return
189
+ }
190
+ try {
191
+ writeStore({ busy: true })
192
+ const line = buildApplySpec(choices)
193
+ const result = await state.execute(state.sessionId, line)
194
+ if (result && result.ok === false) throw new Error(result?.error?.message ?? '命令执行失败')
195
+ writeStore({ open: false, busy: false, message: `已执行:${line}` })
196
+ if (typeof state.afterApply === 'function') await state.afterApply()
197
+ } catch (e) {
198
+ setError(String(e?.message ?? e))
199
+ writeStore({ busy: false })
200
+ }
201
+ }
202
+
203
+ const footer = h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end' } },
204
+ typeof Button === 'function'
205
+ ? h(Button, { variant: 'outline', onClick: () => writeStore({ open: false }) }, '取消')
206
+ : h('button', { type: 'button', onClick: () => writeStore({ open: false }) }, '取消'),
207
+ typeof Button === 'function'
208
+ ? h(Button, { variant: 'primary', disabled: state.busy, onClick: () => void apply() }, state.busy ? '执行中…' : '应用')
209
+ : h('button', { type: 'button', disabled: state.busy, onClick: () => void apply() }, '应用'),
210
+ )
211
+
212
+ const body = [
213
+ h('div', { key: 'cwd', style: { opacity: 0.65, fontSize: 12, marginBottom: 10, wordBreak: 'break-all' } }, state.cwd),
214
+ ...(state.conflicts ?? []).map((conflict, i) =>
215
+ h(ChoiceRow, {
216
+ key: `c${i}`,
217
+ index: i,
218
+ conflict,
219
+ choice: choices[i],
220
+ onChoose,
221
+ renameEnabled: true,
222
+ onRename,
223
+ })),
224
+ error ? h('div', { key: 'err', style: { color: 'var(--dsh-danger, #c0563b)', marginTop: 10 } }, error) : null,
225
+ h('div', { key: 'hint', style: { opacity: 0.55, fontSize: 12, marginTop: 12 } },
226
+ '点"应用"会执行一条 /atp apply 命令(与手动输入等价,可在会话里看到审计记录)。'),
227
+ ].filter(Boolean)
228
+
229
+ if (typeof Modal !== 'function') {
230
+ return h('div', { style: { position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.5)', zIndex: 9999, padding: 20, overflow: 'auto' } },
231
+ h('div', { style: { background: 'var(--dsh-surface, #1b1b1b)', padding: 16, borderRadius: 10 } }, body, footer))
232
+ }
233
+ return h(Modal, { open: true, onClose: () => writeStore({ open: false }), title: '处理同名内容', closeLabel: '取消', footer }, body)
234
+ }
235
+
64
236
  function Panel() {
65
237
  const [state, setState] = useState({ phase: 'loading' })
66
238
  const [copied, setCopied] = useState('')
@@ -80,6 +252,20 @@ window.__ModuleLoader__.load({
80
252
  void refresh()
81
253
  }, [refresh])
82
254
 
255
+ // 首次进入且已有冲突 → 自动弹一次;同一组冲突只自动弹一次
256
+ useEffect(() => {
257
+ if (state.phase !== 'ready') return
258
+ const found = state.data?.conflicts ?? []
259
+ if (found.length === 0) return
260
+ const fingerprint = `${state.cwd ?? ''}|${found.map((c) => c.rel).join(',')}`
261
+ if (autoOpened === fingerprint) return
262
+ autoOpened = fingerprint
263
+ const ctx = Panel.ctx
264
+ const { sessionId, cwd } = currentSession(ctx)
265
+ const execute = async (sid, line) => ctx?.remote?.commands?.execute?.(sid, line, [])
266
+ writeStore({ open: true, conflicts: found, cwd: cwd ?? '', sessionId: sessionId ?? '', execute, afterApply: refresh })
267
+ }, [state, refresh])
268
+
83
269
  const conflicts = state.phase === 'ready' ? state.data?.conflicts ?? [] : []
84
270
 
85
271
  const suggestion = useMemo(() => {
@@ -122,6 +308,20 @@ window.__ModuleLoader__.load({
122
308
  `${i + 1}. ${c.rel} — ${c.reason}`),
123
309
  )
124
310
  })
311
+ children.push(
312
+ h('div', { key: 'resolve', style: { marginTop: 8 } },
313
+ typeof Button === 'function'
314
+ ? h(Button, {
315
+ variant: 'primary',
316
+ onClick: () => {
317
+ const ctx = Panel.ctx
318
+ const { sessionId, cwd } = currentSession(ctx)
319
+ const execute = async (sid, line) => ctx?.remote?.commands?.execute?.(sid, line, [])
320
+ writeStore({ open: true, conflicts, cwd: cwd ?? '', sessionId: sessionId ?? '', execute, afterApply: refresh })
321
+ },
322
+ }, '逐项处理冲突…')
323
+ : null),
324
+ )
125
325
  children.push(
126
326
  h('div', { key: 'sug', style: { marginTop: 8 } },
127
327
  h('div', { style: { opacity: 0.65, marginBottom: 4 } }, '逐项决定后执行(可改 覆盖→备份 / 改名:新名):'),
@@ -135,8 +335,28 @@ window.__ModuleLoader__.load({
135
335
  }
136
336
  }
137
337
 
338
+ // 安装:无冲突直接装;有冲突**直接弹窗**(等价于"install 后自动弹 UI")
339
+ const install = useCallback(async () => {
340
+ const ctx = Panel.ctx
341
+ const { sessionId, cwd } = currentSession(ctx)
342
+ const execute = (line) => ctx?.remote?.commands?.execute?.(sessionId, line, [])
343
+ try {
344
+ const data = await fetchStatus(cwd)
345
+ const found = data?.conflicts ?? []
346
+ if (found.length > 0) {
347
+ writeStore({ open: true, conflicts: found, cwd: cwd ?? '', sessionId: sessionId ?? '', execute, afterApply: refresh })
348
+ return
349
+ }
350
+ await execute('/atp install')
351
+ await refresh()
352
+ } catch (error) {
353
+ setState({ phase: 'error', message: String(error?.message ?? error) })
354
+ }
355
+ }, [refresh])
356
+
138
357
  children.push(
139
- h('div', { key: 'actions', style: { marginTop: 10, display: 'flex', gap: 8 } },
358
+ h('div', { key: 'actions', style: { marginTop: 10, display: 'flex', gap: 8, flexWrap: 'wrap' } },
359
+ h(LinkButton, { onClick: () => void install() }, '安装到工作区'),
140
360
  h(LinkButton, { onClick: () => void refresh() }, '重新检测'),
141
361
  h(LinkButton, { onClick: () => void copy('/atp install') }, copied === '/atp install' ? '已复制 ✓' : '复制 /atp install')),
142
362
  )
@@ -157,11 +377,19 @@ window.__ModuleLoader__.load({
157
377
  order: 36,
158
378
  label: () => '协作规程',
159
379
  }, () => h(Panel, null)))
380
+
381
+ // 冲突处理弹窗:常驻挂载,关闭时渲染 null
382
+ ctx.slots.inject('shell.overlay', () => ctx.slots.register({
383
+ name: 'shell.overlay',
384
+ id: 'agent-team-playbook.resolve',
385
+ }, () => h(ResolveDialog, null)))
160
386
  }
161
387
 
162
388
  exports.apply = apply
163
- exports.inject = ['slots', 'sessions']
389
+ exports.inject = ['slots', 'sessions', 'remote.commands']
164
390
  exports.name = NAME
391
+ // 测试缝:拼命令是纯函数,单独可测
392
+ exports.__test = { buildApplySpec }
165
393
  return module.exports
166
394
  },
167
395
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agent-team-playbook",
3
- "version": "1.27.0",
3
+ "version": "1.29.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",