dsh-agent-team-playbook 1.35.0 → 1.36.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/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@
4
4
 
5
5
  ## 插件包
6
6
 
7
+ ### 1.36.0
8
+
9
+ - dsh-go 原生界面加「处理同名文件」面板:逐项点 覆盖 / 备份,全部定案后自动执行 `/atp apply`
10
+ - 原则:**只桥接、不重做逻辑** —— 冲突清单来自 Cordis 插件新提供的 `agentTeamPlaybook.scan(cwd)`,
11
+ apply 参数来自同服务的 `applyArgs(count, decisions)`,真正执行仍走 `/atp apply` 命令链路
12
+ - 工作区路径取自引擎的 `agents` + `workingDirectory` 服务(按 sessionId 解析)
13
+ - `scripts/check-dshgo.mjs` 覆盖到面板按钮:10/10 通过(桥接自己的校验器)
14
+
15
+ ### 1.35.1
16
+
17
+ - 修 dsh-go 插件:所有按钮**点了没反应** —— 桥接把 `command` 校验成「命令名 + 独立参数」
18
+ (`name` 必须匹配 `^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$`),我们写成了整串 `'atp install'`,
19
+ 效果被静默丢弃。改为 `{ command: { name: 'atp', args: 'install' } }`
20
+ - 新增 `scripts/check-dshgo.mjs`(`npm run check:dshgo`):调用桥接自己的校验器,
21
+ 跑遍每个 handler 与面板按钮,任何 violation 即失败——防止再次出现"点了没反应"
22
+
7
23
  ### 1.35.0
8
24
 
9
25
  - 新增 `dsh-go/`:给 **dsh-go 手机 App 原生界面**的插件(App 插件桥,不是 Cordis bundle)
package/README.en.md CHANGED
@@ -100,7 +100,7 @@ Adds an `/atp` command; on web and desktop there is also a panel.
100
100
  The panel's read-only endpoint `/api/agent-team-playbook/status` goes through DSH's admission check (same-origin, loopback and host authentication); cross-site requests get 403, and only GET is accepted.
101
101
 
102
102
  Existing files are never overwritten silently: you get a conflict list and choose **overwrite / back up / rename** per item, and the run is applied after you finish.
103
- (The dsh-go native mobile UI does not load browser halves; it gets a native capsule instead — "Playbook" above the composer opens a panel that installs and inspects, see [`dsh-go/`](dsh-go/README.md).)
103
+ (The dsh-go native mobile UI does not load browser halves; it gets a native capsule instead — "Playbook" above the composer opens panels that install, inspect, and resolve conflicts item by item, see [`dsh-go/`](dsh-go/README.md).)
104
104
 
105
105
  ### Option B: install as resident context (writes files, the real payoff)
106
106
 
package/README.md CHANGED
@@ -100,7 +100,7 @@ dsh plugin --profile web add dsh-agent-team-playbook
100
100
  面板只读接口 `/api/agent-team-playbook/status` 走 DSH 的准入校验(同源 + loopback + 宿主认证),跨站请求一律 403;只接受 GET。
101
101
 
102
102
  遇到同名文件时不会静默覆盖:会列出冲突,让你逐项选 **覆盖 / 备份 / 改名**,处理完自动执行。
103
- (dsh-go 手机原生界面不加载浏览器半身,另有原生胶囊入口:输入框上方「协作规程」→ 面板里直接装/查,见 [`dsh-go/`](dsh-go/README.md)。)
103
+ (dsh-go 手机原生界面不加载浏览器半身,另有原生入口:输入框上方「协作规程」→ 装/查;点「检查冲突…」还会打开逐项处理面板,见 [`dsh-go/`](dsh-go/README.md)。)
104
104
 
105
105
  ### 方式 B:装成"常驻上下文"(会写文件,核心价值)
106
106
 
@@ -1,11 +1,59 @@
1
1
  // 协作规程(agent-team-playbook)的 dsh-go 原生界面小插件。
2
- // App 只画 package.json 里 dshGo 声明的内容;这里的处理在引擎(Node)里执行。
2
+ //
3
+ // 这个插件**只做桥接**,不重复实现任何后端逻辑:
4
+ // · 冲突扫描 ← agentTeamPlaybook.scan(cwd) (Cordis 插件的服务)
5
+ // · apply 参数 ← agentTeamPlaybook.applyArgs(count, 决策)(同一套编号规则)
6
+ // · 真正执行 ← command 效果跑 /atp install|apply (同一条命令链路)
7
+ // 工作区路径取自引擎的 agents + workingDirectory 服务。
3
8
  export const name = 'local-atp'
4
9
 
10
+ /** 每个会话的决策状态:sessionId -> { key, map: Map<冲突序号, 'overwrite'|'backup'> } */
11
+ const sessions = new Map()
12
+
5
13
  export function apply(ctx) {
6
14
  // 仅在有 dsh-go 桥接的主机上出现;写 ['dshGo'],不要写 ['dshGo?']。
7
15
  ctx.inject(['dshGo'], (ctx) => {
8
- const zh = (event) => !String(event?.locale ?? '').startsWith('en')
16
+ const optional = (name) => (typeof ctx.get === 'function' ? ctx.get(name) : undefined)
17
+ const isEn = (event) => String(event?.locale ?? '').startsWith('en')
18
+
19
+ /** 当前会话的工作区绝对路径;拿不到返回 undefined。 */
20
+ const workingDirOf = (scope) => {
21
+ try {
22
+ const agents = optional('agents')
23
+ const wd = optional('workingDirectory')
24
+ const agent = agents?.get?.(scope?.sessionId ?? '')
25
+ if (agent === undefined) return undefined
26
+ const dir = wd?.get?.(agent.session)
27
+ return typeof dir === 'string' && dir !== '' ? dir : undefined
28
+ } catch {
29
+ return undefined
30
+ }
31
+ }
32
+
33
+ /** 读冲突清单(后端服务);返回结构化状态供视图使用。 */
34
+ const readConflicts = async (scope) => {
35
+ const svc = optional('agentTeamPlaybook')
36
+ if (svc === undefined) return { state: 'service-missing' }
37
+ const dir = workingDirOf(scope)
38
+ if (dir === undefined) return { state: 'no-workspace' }
39
+ try {
40
+ const conflicts = await svc.scan(dir)
41
+ return { state: 'ok', dir, conflicts, svc }
42
+ } catch (error) {
43
+ return { state: 'error', message: String(error?.message ?? error) }
44
+ }
45
+ }
46
+
47
+ /** 当前会话的决策容器;冲突清单变化时自动失效,避免序号错位。 */
48
+ const decisionState = (scope, key) => {
49
+ const id = String(scope?.sessionId ?? '')
50
+ let entry = sessions.get(id)
51
+ if (entry === undefined || entry.key !== key) {
52
+ entry = { key, map: new Map() }
53
+ sessions.set(id, entry)
54
+ }
55
+ return entry
56
+ }
9
57
 
10
58
  // 输入框上方的胶囊:打开面板
11
59
  ctx.dshGo.on('open-playbook', () => ({ open: 'panel:playbook' }))
@@ -20,20 +68,14 @@ export function apply(ctx) {
20
68
  {
21
69
  type: 'text',
22
70
  text: en
23
- ? 'Install the workflow into this workspace as AGENTS.md plus docs, then the agent follows it every turn.'
71
+ ? 'Install the workflow into this workspace as AGENTS.md plus referenced docs, then the agent follows it every turn.'
24
72
  : '把工作流以 AGENTS.md + 引用文档的形式装进当前工作区,装好后 agent 每轮都会按它协作。',
25
73
  },
26
- {
27
- type: 'keyValue',
28
- items: [
29
- [en ? 'Source' : '来源', 'agent-team-playbook'],
30
- [en ? 'Command' : '命令', '/atp'],
31
- ],
32
- },
33
74
  {
34
75
  type: 'actions',
35
76
  items: [
36
77
  { label: en ? 'Install' : '安装到工作区', action: 'install', style: 'primary', icon: 'download' },
78
+ { label: en ? 'Check conflicts' : '检查冲突…', action: 'open-conflicts', icon: 'todo' },
37
79
  { label: en ? 'Overwrite' : '覆盖式安装', action: 'force', icon: 'refresh' },
38
80
  { label: en ? 'Copy command' : '复制命令', action: 'copy', icon: 'copy' },
39
81
  ],
@@ -42,8 +84,8 @@ export function apply(ctx) {
42
84
  type: 'callout',
43
85
  tone: 'info',
44
86
  text: en
45
- ? 'Existing files are never overwritten silently: the command lists conflicts and you decide per item.'
46
- : '不会静默覆盖:已有同名文件时命令会列出冲突,由你逐项决定(覆盖 / 备份 / 改名)。',
87
+ ? 'Existing files are never overwritten silently: check conflicts first, then decide per item.'
88
+ : '不会静默覆盖:先点「检查冲突…」,再逐项决定覆盖或备份。',
47
89
  },
48
90
  {
49
91
  type: 'actions',
@@ -56,28 +98,121 @@ export function apply(ctx) {
56
98
  }
57
99
  },
58
100
  actions: {
59
- // 执行斜杠命令:在当前对话里跑 /atp 的安装流程,冲突时会列出清单
60
101
  install: (scope, event) => ({
61
- command: 'atp install',
62
- toast: zh(event) ? '已发起安装,冲突会在对话里列出' : 'Install started; conflicts will be listed',
102
+ command: { name: 'atp', args: 'install' },
103
+ toast: isEn(event) ? 'Install started; conflicts will be listed' : '已发起安装,冲突会在对话里列出',
63
104
  }),
64
105
  force: (scope, event) => ({
65
- command: 'atp install force',
66
- toast: zh(event) ? '已发起覆盖式安装(原件会暂存,可回滚)' : 'Overwrite install started (originals are stashed)',
67
- }),
68
- core: (scope, event) => ({
69
- command: 'atp core',
70
- toast: zh(event) ? '已输出核心全文' : 'Core text printed',
71
- }),
72
- paths: (scope, event) => ({
73
- command: 'atp paths',
74
- toast: zh(event) ? '已列出分册路径' : 'Volume paths listed',
75
- }),
76
- copy: (scope, event) => ({
77
- copy: '/atp install',
78
- toast: zh(event) ? '已复制 /atp install' : 'Copied /atp install',
106
+ command: { name: 'atp', args: 'install force' },
107
+ toast: isEn(event) ? 'Overwrite install started (originals stashed)' : '已发起覆盖式安装(原件会暂存,可回滚)',
79
108
  }),
109
+ 'open-conflicts': () => ({ open: 'panel:conflicts' }),
110
+ core: (scope, event) => ({ command: { name: 'atp', args: 'core' }, toast: isEn(event) ? 'Core printed' : '已输出核心全文' }),
111
+ paths: (scope, event) => ({ command: { name: 'atp', args: 'paths' }, toast: isEn(event) ? 'Paths listed' : '已列出分册路径' }),
112
+ copy: (scope, event) => ({ copy: '/atp install', toast: isEn(event) ? 'Copied /atp install' : '已复制 /atp install' }),
80
113
  },
81
114
  })
115
+
116
+ // ── 冲突面板:一次一项,全部定案后执行 /atp apply ──────────────────────
117
+ ctx.dshGo.panel('conflicts', {
118
+ view: (scope, caps) => {
119
+ const en = String(caps?.locale ?? '').startsWith('en')
120
+ return {
121
+ type: 'stack',
122
+ title: en ? 'Resolve conflicts' : '处理同名文件',
123
+ children: [
124
+ { type: 'text', text: { $: 'data.headline' } },
125
+ {
126
+ type: 'keyValue',
127
+ items: [
128
+ [en ? 'Workspace' : '工作区', { $: 'data.dir' }],
129
+ [en ? 'Remaining' : '剩余', { $: 'data.remaining' }],
130
+ [en ? 'Current' : '当前', { $: 'data.current' }],
131
+ ],
132
+ },
133
+ { type: 'text', text: { $: 'data.reason' }, tone: 'muted' },
134
+ {
135
+ type: 'actions',
136
+ items: [
137
+ { label: en ? 'Overwrite' : '覆盖', action: 'overwrite', style: 'primary', icon: 'check' },
138
+ { label: en ? 'Back up' : '备份', action: 'backup', icon: 'save' },
139
+ { label: en ? 'Refresh' : '刷新', action: 'reload', style: 'plain', icon: 'refresh' },
140
+ ],
141
+ },
142
+ { type: 'callout', tone: 'info', text: { $: 'data.hint' } },
143
+ ],
144
+ }
145
+ },
146
+ data: async (scope, emit) => {
147
+ const got = await readConflicts(scope)
148
+ if (got.state !== 'ok') {
149
+ emit({
150
+ headline:
151
+ got.state === 'service-missing'
152
+ ? '后端插件未就绪:请先安装 dsh-agent-team-playbook 插件'
153
+ : got.state === 'no-workspace'
154
+ ? '拿不到当前工作区:请在这个对话里打开一个项目'
155
+ : `扫描失败:${got.message ?? ''}`,
156
+ dir: '—',
157
+ remaining: '—',
158
+ current: '—',
159
+ reason: '',
160
+ hint: '也可以直接用命令:/atp install',
161
+ })
162
+ return () => {}
163
+ }
164
+ const key = got.conflicts.map((c) => c.rel).join('|')
165
+ const entry = decisionState(scope, key)
166
+ const total = got.conflicts.length
167
+ const pending = got.conflicts.map((c, i) => ({ ...c, index: i })).filter((c) => !entry.map.has(c.index))
168
+ const current = pending[0]
169
+ emit({
170
+ headline:
171
+ total === 0
172
+ ? '没有同名冲突,可以直接安装。'
173
+ : `共 ${total} 项冲突,已决定 ${total - pending.length} 项`,
174
+ dir: got.dir,
175
+ remaining: `${pending.length} / ${total}`,
176
+ current: current === undefined ? '—' : `${current.index + 1}. ${current.rel}`,
177
+ reason: current?.reason ?? '',
178
+ hint:
179
+ total === 0
180
+ ? '回到「协作规程」面板点「安装到工作区」即可。'
181
+ : '每点一项即定案;全部定案后自动执行 /atp apply。要改名请用命令:/atp apply 1=改名:新名字',
182
+ })
183
+ return () => {}
184
+ },
185
+ actions: {
186
+ reload: () => ({ refresh: true }),
187
+ overwrite: (scope, event) => decide(scope, event, 'overwrite'),
188
+ backup: (scope, event) => decide(scope, event, 'backup'),
189
+ },
190
+ })
191
+
192
+ /** 记一项决策;全部定案后用后端的 applyArgs 生成参数并执行。 */
193
+ async function decide(scope, event, action) {
194
+ const got = await readConflicts(scope)
195
+ if (got.state !== 'ok') {
196
+ return { refresh: true, toast: isEn(event) ? 'Workspace unavailable' : '拿不到工作区' }
197
+ }
198
+ const key = got.conflicts.map((c) => c.rel).join('|')
199
+ const entry = decisionState(scope, key)
200
+ const index = got.conflicts.map((_, i) => i).find((i) => !entry.map.has(i))
201
+ if (index === undefined) return { refresh: true }
202
+ entry.map.set(index, action)
203
+ const remaining = got.conflicts.filter((_, i) => !entry.map.has(i)).length
204
+ if (remaining > 0) {
205
+ const label = action === 'backup' ? '备份' : '覆盖'
206
+ return { refresh: true, toast: isEn(event) ? `Recorded #${index + 1}` : `已记下:第 ${index + 1} 项${label}` }
207
+ }
208
+ const decisions = got.conflicts.map((_, i) => entry.map.get(i) ?? 'overwrite')
209
+ const args = got.svc.applyArgs(got.conflicts.length, decisions)
210
+ sessions.delete(String(scope?.sessionId ?? ''))
211
+ return [
212
+ { command: { name: 'atp', args } },
213
+ { refresh: true },
214
+ { toast: isEn(event) ? 'All decisions applied' : '已按你的决定执行安装' },
215
+ ]
216
+ }
82
217
  })
83
218
  }
@@ -14,18 +14,48 @@
14
14
  },
15
15
  "dshGo": {
16
16
  "v": 1,
17
- "title": { "zh": "协作规程", "en": "Playbook" },
17
+ "title": {
18
+ "zh": "协作规程",
19
+ "en": "Playbook"
20
+ },
18
21
  "icon": "bookmark",
19
22
  "contributes": {
20
23
  "composer.actions": [
21
- { "id": "open-playbook", "label": { "zh": "协作规程", "en": "Playbook" }, "icon": "bookmark" }
24
+ {
25
+ "id": "open-playbook",
26
+ "label": {
27
+ "zh": "协作规程",
28
+ "en": "Playbook"
29
+ },
30
+ "icon": "bookmark"
31
+ }
22
32
  ],
23
33
  "panels": [
24
34
  {
25
35
  "id": "playbook",
26
- "title": { "zh": "协作规程", "en": "Playbook" },
36
+ "title": {
37
+ "zh": "协作规程",
38
+ "en": "Playbook"
39
+ },
27
40
  "icon": "bookmark",
28
- "placement": ["session.tab", "features", "chat.panel"]
41
+ "placement": [
42
+ "session.tab",
43
+ "features",
44
+ "chat.panel"
45
+ ]
46
+ },
47
+ {
48
+ "id": "conflicts",
49
+ "title": {
50
+ "zh": "处理同名文件",
51
+ "en": "Conflicts"
52
+ },
53
+ "icon": "todo",
54
+ "placement": [
55
+ "session.tab",
56
+ "features",
57
+ "chat.panel"
58
+ ]
29
59
  }
30
60
  ]
31
61
  }
package/lib/index.js CHANGED
@@ -463,6 +463,29 @@ export function apply(ctx) {
463
463
  }
464
464
  }
465
465
 
466
+ // 给 dsh-go 原生插件用的查询服务:冲突扫描只有一份实现(lib/install.js),
467
+ // 手机端面板通过它取数据,不重复实现比对逻辑。
468
+ if (typeof ctx.provide === 'function') {
469
+ ctx.provide('agentTeamPlaybook', {
470
+ /** @param {string} targetDir 工作区绝对路径 */
471
+ async scan(targetDir) {
472
+ const { conflicts } = await scan({ sourceRoot: PLAYBOOK_DIR, targetDir })
473
+ return conflicts.map((c) => ({ rel: c.rel, reason: c.reason, target: c.target, ours: c.ours === true }))
474
+ },
475
+ /**
476
+ * 由决策生成 `/atp apply` 的参数串——与命令层同一套编号规则,
477
+ * 下游(如 dsh-go 面板)只负责收集决策,不自己拼格式。
478
+ * @param {number} count 冲突总数
479
+ * @param {Array<'overwrite'|'backup'>} decisions 按冲突顺序的决策
480
+ */
481
+ applyArgs(count, decisions) {
482
+ const label = { overwrite: '覆盖', backup: '备份' }
483
+ const parts = decisions.map((d, i) => `${i + 1}=${label[d] ?? '覆盖'}`)
484
+ return `apply count=${count} ${parts.join(' ')}`
485
+ },
486
+ })
487
+ }
488
+
466
489
  ctx.commands.register({
467
490
  definitionId: 'dsh-agent-team-playbook',
468
491
  name: 'atp',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agent-team-playbook",
3
- "version": "1.35.0",
3
+ "version": "1.36.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",
@@ -57,7 +57,8 @@
57
57
  "smoke": "node scripts/smoke-install.mjs",
58
58
  "smoke:pack": "node scripts/smoke-install.mjs --pack",
59
59
  "prepack": "node scripts/sync-playbook.mjs",
60
- "prepublishOnly": "node scripts/smoke-install.mjs --pack"
60
+ "prepublishOnly": "node scripts/smoke-install.mjs --pack",
61
+ "check:dshgo": "node scripts/check-dshgo.mjs"
61
62
  },
62
63
  "exports": {
63
64
  ".": "./lib/index.js",
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * 校验 dsh-go 原生插件的「效果」是否合法。
4
+ *
5
+ * 为什么需要:App 的桥接层会丢弃不合法的效果,**表现是"点了没反应"**,没有任何提示。
6
+ * 我们踩过:`{ command: 'atp install' }` 因为命令名含空格被拒(桥接要求
7
+ * name 匹配 ^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$,参数走独立的 args)。
8
+ *
9
+ * 这个脚本调用**桥接自己的校验器**(/opt/dsh-go/dsh-go-bridge/lib/native/effects.js),
10
+ * 把插件注册的每个 handler / 面板按钮都跑一遍,任何 violation 都算失败。
11
+ *
12
+ * 不在手机上(没有 /opt/dsh-go)时跳过,退出码 0。
13
+ */
14
+ import { existsSync } from 'node:fs'
15
+ import path from 'node:path'
16
+ import { fileURLToPath, pathToFileURL } from 'node:url'
17
+
18
+ const BRIDGE = '/opt/dsh-go/dsh-go-bridge/lib/native/effects.js'
19
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
20
+ const PLUGIN = path.join(ROOT, 'dsh-go', 'local-atp')
21
+
22
+ if (!existsSync(BRIDGE)) {
23
+ console.log('跳过:找不到 dsh-go 桥接(不在手机主机上)')
24
+ process.exit(0)
25
+ }
26
+
27
+ const { normalize } = await import(pathToFileURL(BRIDGE).href)
28
+ const mod = await import(pathToFileURL(path.join(PLUGIN, 'lib/index.js')).href)
29
+
30
+ const handlers = new Map()
31
+ const panels = new Map()
32
+ mod.apply({
33
+ inject: (_services, cb) =>
34
+ cb({ dshGo: { on: (id, fn) => handlers.set(id, fn), panel: (id, def) => panels.set(id, def) } }),
35
+ })
36
+
37
+ const opts = { panels: new Set(panels.keys()) }
38
+ const results = []
39
+ const check = (label, result, extra = {}) => {
40
+ const out = normalize(result, { ...opts, ...extra })
41
+ const violations = (out.issues ?? []).filter((i) => i.violation)
42
+ results.push({ label, ok: violations.length === 0, detail: violations.map((v) => v.message).join('; ') || JSON.stringify(out.effects) })
43
+ }
44
+
45
+ for (const [id, fn] of handlers) check(`handler ${id}`, fn({}, { id, locale: 'zh-CN' }))
46
+ for (const [panelId, def] of panels) {
47
+ for (const [actionId, fn] of Object.entries(def.actions ?? {})) {
48
+ check(`panel ${panelId} · ${actionId}`, fn({}, { surface: 'panel', id: actionId, locale: 'zh-CN' }), { source: panelId })
49
+ }
50
+ }
51
+
52
+ const failed = results.filter((r) => !r.ok)
53
+ for (const r of results) console.log(`${r.ok ? '✓' : '✗'} ${r.label}${r.ok ? '' : ` — ${r.detail}`}`)
54
+ console.log(`\n通过 ${results.length - failed.length} / ${results.length}`)
55
+ if (failed.length > 0) {
56
+ console.log('\n有关键效果被桥接拒绝——App 里会表现为"点了没反应"。')
57
+ process.exit(1)
58
+ }