dsh-agent-team-playbook 1.36.1 → 1.37.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,15 @@
4
4
 
5
5
  ## 插件包
6
6
 
7
+ ### 1.37.0
8
+
9
+ - **原生界面并入主包**:`package.json` 增加顶层 `dshGo` 清单,桥接代码移到 `lib/dshgo.js`
10
+ - 市场装一次即同时拥有:Web/桌面 chip + 面板、手机原生胶囊 + 两个面板、`/atp` 命令
11
+ - 不再需要单独安装 `local-atp`;也不再依赖主插件提供服务(直接调 `lib/install.js`)
12
+ - 删掉不再使用的 `agentTeamPlaybook` 服务
13
+ - 退役 `dsh-go/local-atp`(源码删除,`dsh-go/README.md` 说明新位置)
14
+ - `npm run check:dshgo` 改为校验主包;单测新增 H3b/H3c(dshGo 清单 + 桥接模块可加载)
15
+
7
16
  ### 1.36.1
8
17
 
9
18
  - 修 dsh-go「处理同名文件」面板文案误导:已装过且内容一致时,原来显示「没有同名冲突,可以直接安装」,
package/CONTRIBUTING.md CHANGED
@@ -12,6 +12,7 @@ playbook/ 发布用副本(由 scripts/sync-playbook.mjs
12
12
  lib/index.js DSH 命令插件入口(/atp)
13
13
  lib/install.js 原子安装器(scan / inspectConflict / installAtomic)
14
14
  bin/cli.mjs CLI 入口(init 系列)
15
+ lib/dshgo.js dsh-go 手机原生界面桥接(可选能力,见 package.json 的 dshGo)
15
16
  client.js 浏览器半身(ModuleLoader bundle,无构建)
16
17
  scripts/sync-playbook.mjs AGENTS.md + docs → playbook/ 同步
17
18
  scripts/smoke-install.mjs 安装自检(真实 dsh plugin add)
@@ -84,10 +85,25 @@ npm 令牌不入库:放在仓库外的 `.secrets/`,用临时 `--userconfig`
84
85
 
85
86
  样式全用**内联 style 对象**:早期用 `<style>` 注入曾整体不生效(菜单横排、弹窗不限高),内联没有这个问题。仅保留一条 `div:has(> .atp-wrap)` 调整 chip 左对齐。
86
87
 
88
+ ## 原生界面(dshGo)
89
+
90
+ 同一份包同时提供三个界面:`dsh.bundle`(命令)、`dsh.client`(Web/桌面)、`dshGo`(手机原生)。
91
+ 桥接代码在 `lib/dshgo.js`,由 `lib/index.js` 里 `ctx.inject(['dshGo'], …)` 接入——Web-only 主机上永不激活。
92
+
93
+ App 桥接会**静默丢弃不合法效果**(表现为"点了没反应"),所以改完必须跑:
94
+
95
+ ```bash
96
+ npm run check:dshgo # 用桥接自己的校验器跑遍每个按钮
97
+ node "$DSH_HOME/skills/dsh-go-plugin/kit/bin/check.mjs" . --load # 视图能否被画出来
98
+ ```
99
+
100
+ 踩过的坑:`{ command: 'atp install' }` 会被拒(命令名不能含空格),必须写 `{ command: { name: 'atp', args: 'install' } }`。
101
+
87
102
  ## 发布前检查清单
88
103
 
89
104
  - [ ] `npm run check`(playbook 与源文档一致)
90
105
  - [ ] `npm run smoke:pack` 通过
106
+ - [ ] `npm run check:dshgo` 通过(原生按钮效果合法)
91
107
  - [ ] 版本号已升,CHANGELOG 已记
92
108
  - [ ] `cordis.patch.yml` 注释与实际命令一致
93
109
  - [ ] `engines.dsh` 与实测运行时相符
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 panels that install, inspect, and resolve conflicts item by item, see [`dsh-go/`](dsh-go/README.md).)
103
+ **The dsh-go mobile app is covered by the same package**: after installing, a "Playbook" capsule appears above the composer with native panels for install, conflict inspection and item-by-item resolution — no second package needed.
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 手机 App 也自动带着**:同一个包装好后,输入框上方会出现「协作规程」胶囊,点开是原生面板(安装 / 检查冲突 / 逐项处理),不需要再装第二个包。
104
104
 
105
105
  ### 方式 B:装成"常驻上下文"(会写文件,核心价值)
106
106
 
package/dsh-go/README.md CHANGED
@@ -1,30 +1,31 @@
1
- # dsh-go 原生界面插件
1
+ # dsh-go 手机原生界面
2
2
 
3
- `local-atp/` 是给 **dsh-go 手机 App 原生界面**用的小插件(不是 Cordis bundle):输入框上方加「协作规程」胶囊,点开是原生面板,按钮直接执行 `/atp` 命令。
3
+ > **状态:已并入主包(1.37.0 起)。** 这里不再有独立插件。
4
4
 
5
- ## 为什么另做一份
5
+ 原生界面现在是主包的一部分,装一次市场版就有两个界面:
6
6
 
7
- 浏览器半身(仓库根的 `client.js`)只在 Web / 桌面端加载;dsh-go 原生界面不加载它。所以手机上的入口改用 App 的插件桥:
8
-
9
- | 界面 | 入口 | 实现 |
7
+ | 界面 | 入口 | 由什么提供 |
10
8
  |---|---|---|
11
- | Web / 桌面端 | 首页 chip + 设置面板 | `client.js`(Cordis client half) |
12
- | dsh-go 原生 | 输入框上方胶囊 + 原生面板 | `dsh-go/local-atp`(App 插件桥) |
9
+ | Web / 桌面端 | 首页 chip + 设置面板 + 冲突弹窗 | `client.js`(`dsh.client`) |
10
+ | dsh-go 手机原生 | 输入框上方「协作规程」胶囊 + 两个面板 | `lib/dshgo.js`(`package.json` 的 `dshGo` 清单) |
11
+ | 命令(所有界面) | `/atp …` | `lib/index.js`(`dsh.bundle`) |
13
12
 
14
- 两者的动作都落到同一条 `/atp` 命令上,不重复实现安装逻辑。
13
+ 三个界面共用同一套后端逻辑:冲突比对在 `lib/install.js`,执行都走 `/atp` 命令。
15
14
 
16
- ## 安装
15
+ ## 为什么合并
17
16
 
18
- ```bash
19
- # 1. 放到 App 的插件目录(引擎重置会保留)
20
- P="${DSH_HOME:-$HOME/.dsh}/dsh-go/plugins/local-atp"
21
- mkdir -p "$(dirname "$P")" && cp -r dsh-go/local-atp "$P"
17
+ 之前原生界面是独立包 `local-atp`,问题有两个:
18
+
19
+ 1. 市场用户装主包拿不到手机入口,得手动装第二个包;
20
+ 2. 原生面板依赖主插件提供的服务,主插件缺失时显示「未就绪」。
22
21
 
23
- # 2. 自查(--load 会在隔离环境里加载代码并校验视图)
24
- node "${DSH_HOME:-$HOME/.dsh}/skills/dsh-go-plugin/kit/bin/check.mjs" "$P" --load
22
+ 合并后没有跨包依赖,也不需要用户装两次。
25
23
 
26
- # 3. 装进当前 profile(装的是链接,目录不能删)
27
- dsh plugin --profile web add "$P"
24
+ ## 验证
25
+
26
+ ```bash
27
+ npm run check:dshgo # 用 App 桥接自己的校验器检查所有按钮的效果
28
+ node "$DSH_HOME/skills/dsh-go-plugin/kit/bin/check.mjs" . --load # 视图能否被 App 画出来
28
29
  ```
29
30
 
30
- 改了 `lib/` 里的代码后,需要在 App 的「引擎」页重启引擎才生效;只改 `package.json` 清单会自动重读。
31
+ > 改了 `lib/` 代码后,需在 App 的「引擎」页重启引擎;只改 `package.json` 清单会自动重读。
package/lib/dshgo.js ADDED
@@ -0,0 +1,245 @@
1
+ /**
2
+ * dsh-go 手机 App 原生界面的桥接(可选能力)。
3
+ *
4
+ * 同一份 npm 包同时提供三个界面:
5
+ * · dsh.bundle → Cordis 命令 `/atp`
6
+ * · dsh.client → Web / 桌面端 chip + 面板 + 弹窗
7
+ * · dshGo → 手机原生胶囊 + 面板(本文件)
8
+ *
9
+ * 只在装了 dsh-go 桥接的主机上生效;Web-only 主机上这段永远不会被激活。
10
+ * 冲突比对直接调 `lib/install.js`,不依赖任何外部服务。
11
+ */
12
+ import { existsSync, readFileSync } from 'node:fs'
13
+ import path from 'node:path'
14
+ import { scan, CORE_FILE, DOCS_DIR, OURS_SIGNATURE } from './install.js'
15
+
16
+ /** 每个会话的决策:sessionId -> { key, map: Map<冲突序号, 'overwrite'|'backup'> } */
17
+ const sessions = new Map()
18
+
19
+ const SPEC_LABEL = { overwrite: '覆盖', backup: '备份' }
20
+
21
+ /** 读文件内容,失败返回空串。 */
22
+ function readSafe(file) {
23
+ try {
24
+ return readFileSync(file, 'utf8')
25
+ } catch {
26
+ return ''
27
+ }
28
+ }
29
+
30
+ /** 工作区状态:冲突清单 + 是否已安装(按内容判定,与 scan 同一套规则)。 */
31
+ export async function inspectWorkspace(playbookDir, targetDir) {
32
+ const { conflicts } = await scan({ sourceRoot: playbookDir, targetDir })
33
+ const coreInstalled = existsSync(path.join(targetDir, CORE_FILE)) && readSafe(path.join(targetDir, CORE_FILE)).includes(OURS_SIGNATURE)
34
+ const docsInstalled = existsSync(path.join(targetDir, DOCS_DIR, 'workflow', 'rules', '01-总纲细则.md'))
35
+ return {
36
+ conflicts: conflicts.map((c) => ({ rel: c.rel, reason: c.reason, ours: c.ours === true })),
37
+ installed: coreInstalled && docsInstalled,
38
+ }
39
+ }
40
+
41
+ /** 由决策生成 `/atp apply` 的参数串(与命令层同一套编号规则)。 */
42
+ export function applyArgs(count, decisions) {
43
+ const parts = decisions.map((d, i) => `${i + 1}=${SPEC_LABEL[d] ?? '覆盖'}`)
44
+ return `apply count=${count} ${parts.join(' ')}`
45
+ }
46
+
47
+ /**
48
+ * 在 dsh-go 主机上注册原生界面。
49
+ * @param {object} ctx 已注入 dshGo 的 cordis 上下文
50
+ * @param {{ playbookDir: string }} options
51
+ */
52
+ export function attachDshGo(ctx, { playbookDir }) {
53
+ const optional = (name) => (typeof ctx.get === 'function' ? ctx.get(name) : undefined)
54
+ const isEn = (event) => String(event?.locale ?? '').startsWith('en')
55
+
56
+ /** 当前会话的工作区绝对路径;拿不到返回 undefined。 */
57
+ const workingDirOf = (scope) => {
58
+ try {
59
+ const agent = optional('agents')?.get?.(scope?.sessionId ?? '')
60
+ if (agent === undefined) return undefined
61
+ const dir = optional('workingDirectory')?.get?.(agent.session)
62
+ return typeof dir === 'string' && dir !== '' ? dir : undefined
63
+ } catch {
64
+ return undefined
65
+ }
66
+ }
67
+
68
+ const readState = async (scope) => {
69
+ const dir = workingDirOf(scope)
70
+ if (dir === undefined) return { state: 'no-workspace' }
71
+ try {
72
+ return { state: 'ok', dir, ...(await inspectWorkspace(playbookDir, dir)) }
73
+ } catch (error) {
74
+ return { state: 'error', message: String(error?.message ?? error) }
75
+ }
76
+ }
77
+
78
+ const decisionState = (scope, key) => {
79
+ const id = String(scope?.sessionId ?? '')
80
+ let entry = sessions.get(id)
81
+ if (entry === undefined || entry.key !== key) {
82
+ entry = { key, map: new Map() }
83
+ sessions.set(id, entry)
84
+ }
85
+ return entry
86
+ }
87
+
88
+ // 输入框上方的胶囊
89
+ ctx.dshGo.on('open-playbook', () => ({ open: 'panel:playbook' }))
90
+
91
+ ctx.dshGo.panel('playbook', {
92
+ view: (scope, caps) => {
93
+ const en = String(caps?.locale ?? '').startsWith('en')
94
+ return {
95
+ type: 'stack',
96
+ title: en ? 'Collaboration playbook' : '多智能体协作规程',
97
+ children: [
98
+ {
99
+ type: 'text',
100
+ text: en
101
+ ? 'Install the workflow into this workspace as AGENTS.md plus referenced docs, then the agent follows it every turn.'
102
+ : '把工作流以 AGENTS.md + 引用文档的形式装进当前工作区,装好后 agent 每轮都会按它协作。',
103
+ },
104
+ {
105
+ type: 'actions',
106
+ items: [
107
+ { label: en ? 'Install' : '安装到工作区', action: 'install', style: 'primary', icon: 'download' },
108
+ { label: en ? 'Check conflicts' : '检查冲突…', action: 'open-conflicts', icon: 'todo' },
109
+ { label: en ? 'Overwrite' : '覆盖式安装', action: 'force', icon: 'refresh' },
110
+ { label: en ? 'Copy command' : '复制命令', action: 'copy', icon: 'copy' },
111
+ ],
112
+ },
113
+ {
114
+ type: 'callout',
115
+ tone: 'info',
116
+ text: en
117
+ ? 'Existing files are never overwritten silently: check conflicts first, then decide per item.'
118
+ : '不会静默覆盖:先点「检查冲突…」,再逐项决定覆盖或备份。',
119
+ },
120
+ {
121
+ type: 'actions',
122
+ items: [
123
+ { label: en ? 'Read the core' : '读取核心全文', action: 'core', style: 'plain' },
124
+ { label: en ? 'Paths' : '分册路径', action: 'paths', style: 'plain' },
125
+ ],
126
+ },
127
+ ],
128
+ }
129
+ },
130
+ actions: {
131
+ install: (scope, event) => ({
132
+ command: { name: 'atp', args: 'install' },
133
+ toast: isEn(event) ? 'Install started; conflicts will be listed' : '已发起安装,冲突会在对话里列出',
134
+ }),
135
+ force: (scope, event) => ({
136
+ command: { name: 'atp', args: 'install force' },
137
+ toast: isEn(event) ? 'Overwrite install started (originals stashed)' : '已发起覆盖式安装(原件会暂存,可回滚)',
138
+ }),
139
+ 'open-conflicts': () => ({ open: 'panel:conflicts' }),
140
+ core: (scope, event) => ({ command: { name: 'atp', args: 'core' }, toast: isEn(event) ? 'Core printed' : '已输出核心全文' }),
141
+ paths: (scope, event) => ({ command: { name: 'atp', args: 'paths' }, toast: isEn(event) ? 'Paths listed' : '已列出分册路径' }),
142
+ copy: (scope, event) => ({ copy: '/atp install', toast: isEn(event) ? 'Copied /atp install' : '已复制 /atp install' }),
143
+ },
144
+ })
145
+
146
+ ctx.dshGo.panel('conflicts', {
147
+ view: (scope, caps) => {
148
+ const en = String(caps?.locale ?? '').startsWith('en')
149
+ return {
150
+ type: 'stack',
151
+ title: en ? 'Resolve conflicts' : '处理同名文件',
152
+ children: [
153
+ { type: 'text', text: { $: 'data.headline' } },
154
+ {
155
+ type: 'keyValue',
156
+ items: [
157
+ [en ? 'Workspace' : '工作区', { $: 'data.dir' }],
158
+ [en ? 'Remaining' : '剩余', { $: 'data.remaining' }],
159
+ [en ? 'Current' : '当前', { $: 'data.current' }],
160
+ ],
161
+ },
162
+ { type: 'text', text: { $: 'data.reason' }, tone: 'muted' },
163
+ {
164
+ type: 'actions',
165
+ items: [
166
+ { label: en ? 'Overwrite' : '覆盖', action: 'overwrite', style: 'primary', icon: 'check' },
167
+ { label: en ? 'Back up' : '备份', action: 'backup', icon: 'save' },
168
+ { label: en ? 'Refresh' : '刷新', action: 'reload', style: 'plain', icon: 'refresh' },
169
+ ],
170
+ },
171
+ { type: 'callout', tone: 'info', text: { $: 'data.hint' } },
172
+ ],
173
+ }
174
+ },
175
+ data: async (scope, emit) => {
176
+ const got = await readState(scope)
177
+ if (got.state !== 'ok') {
178
+ emit({
179
+ headline:
180
+ got.state === 'no-workspace'
181
+ ? '拿不到当前工作区:请在这个对话里打开一个项目'
182
+ : `扫描失败:${got.message ?? ''}`,
183
+ dir: '—',
184
+ remaining: '—',
185
+ current: '—',
186
+ reason: '',
187
+ hint: '也可以直接用命令:/atp install',
188
+ })
189
+ return () => {}
190
+ }
191
+ const key = got.conflicts.map((c) => c.rel).join('|')
192
+ const entry = decisionState(scope, key)
193
+ const total = got.conflicts.length
194
+ const pending = got.conflicts.map((c, i) => ({ ...c, index: i })).filter((c) => !entry.map.has(c.index))
195
+ const current = pending[0]
196
+ const notInstalled = total === 0 && got.installed === false
197
+ const installedClean = total === 0 && got.installed === true
198
+ emit({
199
+ headline: notInstalled
200
+ ? '未安装:点「安装到工作区」即可写入。'
201
+ : installedClean
202
+ ? '已安装,且内容与当前版本一致——重复安装不会改动任何文件。'
203
+ : `共 ${total} 项冲突,已决定 ${total - pending.length} 项`,
204
+ dir: got.dir,
205
+ remaining: `${pending.length} / ${total}`,
206
+ current: current === undefined ? '—' : `${current.index + 1}. ${current.rel}`,
207
+ reason: current?.reason ?? '',
208
+ hint: notInstalled
209
+ ? '回到「协作规程」面板点「安装到工作区」。'
210
+ : installedClean
211
+ ? '想把文件强制刷成当前版本,用「协作规程」里的「覆盖式安装」。'
212
+ : '每点一项即定案;全部定案后自动执行 /atp apply。要改名请用命令:/atp apply 1=改名:新名字',
213
+ })
214
+ return () => {}
215
+ },
216
+ actions: {
217
+ reload: () => ({ refresh: true }),
218
+ overwrite: (scope, event) => decide(scope, event, 'overwrite'),
219
+ backup: (scope, event) => decide(scope, event, 'backup'),
220
+ },
221
+ })
222
+
223
+ /** 记一项决策;全部定案后执行 `/atp apply`。 */
224
+ async function decide(scope, event, action) {
225
+ const got = await readState(scope)
226
+ if (got.state !== 'ok') return { refresh: true, toast: isEn(event) ? 'Workspace unavailable' : '拿不到工作区' }
227
+ const key = got.conflicts.map((c) => c.rel).join('|')
228
+ const entry = decisionState(scope, key)
229
+ const index = got.conflicts.map((_, i) => i).find((i) => !entry.map.has(i))
230
+ if (index === undefined) return { refresh: true }
231
+ entry.map.set(index, action)
232
+ const remaining = got.conflicts.filter((_, i) => !entry.map.has(i)).length
233
+ if (remaining > 0) {
234
+ return { refresh: true, toast: isEn(event) ? `Recorded #${index + 1}` : `已记下:第 ${index + 1} 项${SPEC_LABEL[action] ?? ''}` }
235
+ }
236
+ const decisions = got.conflicts.map((_, i) => entry.map.get(i) ?? 'overwrite')
237
+ const args = applyArgs(got.conflicts.length, decisions)
238
+ sessions.delete(String(scope?.sessionId ?? ''))
239
+ return [
240
+ { command: { name: 'atp', args } },
241
+ { refresh: true },
242
+ { toast: isEn(event) ? 'All decisions applied' : '已按你的决定执行安装' },
243
+ ]
244
+ }
245
+ }
package/lib/index.js CHANGED
@@ -19,6 +19,7 @@ import path from 'node:path'
19
19
  import { fileURLToPath } from 'node:url'
20
20
  import { installAtomic, scan, CORE_FILE, DOCS_DIR, OURS_SIGNATURE } from './install.js'
21
21
  import { rejectionFor, connectionAdmissionView } from './trust.js'
22
+ import { attachDshGo } from './dshgo.js'
22
23
 
23
24
  export const name = 'dsh-agent-team-playbook'
24
25
 
@@ -463,44 +464,13 @@ export function apply(ctx) {
463
464
  }
464
465
  }
465
466
 
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
- * 工作区状态:冲突清单 + 是否已安装(按内容判定,与 scan 同一套规则)。
477
- * 面板据此区分「未安装 / 已安装且一致 / 有冲突」,避免把幂等误说成"无冲突"。
478
- * @param {string} targetDir 工作区绝对路径
479
- */
480
- async inspect(targetDir) {
481
- const { conflicts } = await scan({ sourceRoot: PLAYBOOK_DIR, targetDir })
482
- const corePath = path.join(targetDir, CORE_FILE)
483
- const coreInstalled = existsSync(corePath) && readFileSyncSafe(corePath).includes(OURS_SIGNATURE)
484
- const docsInstalled = existsSync(path.join(targetDir, DOCS_DIR, 'workflow', 'rules', '01-总纲细则.md'))
485
- return {
486
- conflicts: conflicts.map((c) => ({ rel: c.rel, reason: c.reason, target: c.target, ours: c.ours === true })),
487
- coreInstalled,
488
- docsInstalled,
489
- installed: coreInstalled && docsInstalled,
490
- }
491
- },
492
- /**
493
- * 由决策生成 `/atp apply` 的参数串——与命令层同一套编号规则,
494
- * 下游(如 dsh-go 面板)只负责收集决策,不自己拼格式。
495
- * @param {number} count 冲突总数
496
- * @param {Array<'overwrite'|'backup'>} decisions 按冲突顺序的决策
497
- */
498
- applyArgs(count, decisions) {
499
- const label = { overwrite: '覆盖', backup: '备份' }
500
- const parts = decisions.map((d, i) => `${i + 1}=${label[d] ?? '覆盖'}`)
501
- return `apply count=${count} ${parts.join(' ')}`
502
- },
503
- })
467
+ // dsh-go 手机原生界面(仅装了桥接的主机上生效;Web-only 主机上不会激活)
468
+ if (typeof ctx.inject === 'function') {
469
+ try {
470
+ ctx.inject(['dshGo'], (scoped) => attachDshGo(scoped, { playbookDir: PLAYBOOK_DIR }))
471
+ } catch (error) {
472
+ ctx.logger?.warn?.(`agent-team-playbook: 原生界面未挂载(${error?.message ?? error})`)
473
+ }
504
474
  }
505
475
 
506
476
  ctx.commands.register({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agent-team-playbook",
3
- "version": "1.36.1",
3
+ "version": "1.37.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",
@@ -64,5 +64,53 @@
64
64
  ".": "./lib/index.js",
65
65
  "./client": "./client.js",
66
66
  "./package.json": "./package.json"
67
+ },
68
+ "dshGo": {
69
+ "v": 1,
70
+ "title": {
71
+ "zh": "协作规程",
72
+ "en": "Playbook"
73
+ },
74
+ "icon": "bookmark",
75
+ "contributes": {
76
+ "composer.actions": [
77
+ {
78
+ "id": "open-playbook",
79
+ "label": {
80
+ "zh": "协作规程",
81
+ "en": "Playbook"
82
+ },
83
+ "icon": "bookmark"
84
+ }
85
+ ],
86
+ "panels": [
87
+ {
88
+ "id": "playbook",
89
+ "title": {
90
+ "zh": "协作规程",
91
+ "en": "Playbook"
92
+ },
93
+ "icon": "bookmark",
94
+ "placement": [
95
+ "session.tab",
96
+ "features",
97
+ "chat.panel"
98
+ ]
99
+ },
100
+ {
101
+ "id": "conflicts",
102
+ "title": {
103
+ "zh": "处理同名文件",
104
+ "en": "Conflicts"
105
+ },
106
+ "icon": "todo",
107
+ "placement": [
108
+ "session.tab",
109
+ "features",
110
+ "chat.panel"
111
+ ]
112
+ }
113
+ ]
114
+ }
67
115
  }
68
116
  }
@@ -17,7 +17,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url'
17
17
 
18
18
  const BRIDGE = '/opt/dsh-go/dsh-go-bridge/lib/native/effects.js'
19
19
  const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
20
- const PLUGIN = path.join(ROOT, 'dsh-go', 'local-atp')
20
+ const PLUGIN = ROOT // 原生界面已并入主包:清单在 package.json,代码在 lib/dshgo.js
21
21
 
22
22
  if (!existsSync(BRIDGE)) {
23
23
  console.log('跳过:找不到 dsh-go 桥接(不在手机主机上)')
@@ -25,14 +25,14 @@ if (!existsSync(BRIDGE)) {
25
25
  }
26
26
 
27
27
  const { normalize } = await import(pathToFileURL(BRIDGE).href)
28
- const mod = await import(pathToFileURL(path.join(PLUGIN, 'lib/index.js')).href)
28
+ const mod = await import(pathToFileURL(path.join(PLUGIN, 'lib/dshgo.js')).href)
29
29
 
30
30
  const handlers = new Map()
31
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
- })
32
+ mod.attachDshGo(
33
+ { dshGo: { on: (id, fn) => handlers.set(id, fn), panel: (id, def) => panels.set(id, def) }, get: () => undefined },
34
+ { playbookDir: path.join(ROOT, 'playbook') },
35
+ )
36
36
 
37
37
  const opts = { panels: new Set(panels.keys()) }
38
38
  const results = []
@@ -1,4 +0,0 @@
1
- # id: any unique id; name: must equal "name" in package.json.
2
- - insert:
3
- - id: local-atp
4
- name: local-atp
@@ -1,222 +0,0 @@
1
- // 协作规程(agent-team-playbook)的 dsh-go 原生界面小插件。
2
- //
3
- // 这个插件**只做桥接**,不重复实现任何后端逻辑:
4
- // · 冲突扫描 ← agentTeamPlaybook.scan(cwd) (Cordis 插件的服务)
5
- // · apply 参数 ← agentTeamPlaybook.applyArgs(count, 决策)(同一套编号规则)
6
- // · 真正执行 ← command 效果跑 /atp install|apply (同一条命令链路)
7
- // 工作区路径取自引擎的 agents + workingDirectory 服务。
8
- export const name = 'local-atp'
9
-
10
- /** 每个会话的决策状态:sessionId -> { key, map: Map<冲突序号, 'overwrite'|'backup'> } */
11
- const sessions = new Map()
12
-
13
- export function apply(ctx) {
14
- // 仅在有 dsh-go 桥接的主机上出现;写 ['dshGo'],不要写 ['dshGo?']。
15
- ctx.inject(['dshGo'], (ctx) => {
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
- /** 读工作区状态(后端服务 inspect:冲突 + 是否已安装);返回结构化状态供视图使用。 */
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 info = typeof svc.inspect === 'function' ? await svc.inspect(dir) : { conflicts: await svc.scan(dir), installed: false }
41
- return { state: 'ok', dir, conflicts: info.conflicts ?? [], installed: info.installed === true, 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
- }
57
-
58
- // 输入框上方的胶囊:打开面板
59
- ctx.dshGo.on('open-playbook', () => ({ open: 'panel:playbook' }))
60
-
61
- ctx.dshGo.panel('playbook', {
62
- view: (scope, caps) => {
63
- const en = String(caps?.locale ?? '').startsWith('en')
64
- return {
65
- type: 'stack',
66
- title: en ? 'Collaboration playbook' : '多智能体协作规程',
67
- children: [
68
- {
69
- type: 'text',
70
- text: en
71
- ? 'Install the workflow into this workspace as AGENTS.md plus referenced docs, then the agent follows it every turn.'
72
- : '把工作流以 AGENTS.md + 引用文档的形式装进当前工作区,装好后 agent 每轮都会按它协作。',
73
- },
74
- {
75
- type: 'actions',
76
- items: [
77
- { label: en ? 'Install' : '安装到工作区', action: 'install', style: 'primary', icon: 'download' },
78
- { label: en ? 'Check conflicts' : '检查冲突…', action: 'open-conflicts', icon: 'todo' },
79
- { label: en ? 'Overwrite' : '覆盖式安装', action: 'force', icon: 'refresh' },
80
- { label: en ? 'Copy command' : '复制命令', action: 'copy', icon: 'copy' },
81
- ],
82
- },
83
- {
84
- type: 'callout',
85
- tone: 'info',
86
- text: en
87
- ? 'Existing files are never overwritten silently: check conflicts first, then decide per item.'
88
- : '不会静默覆盖:先点「检查冲突…」,再逐项决定覆盖或备份。',
89
- },
90
- {
91
- type: 'actions',
92
- items: [
93
- { label: en ? 'Read the core' : '读取核心全文', action: 'core', style: 'plain' },
94
- { label: en ? 'Paths' : '分册路径', action: 'paths', style: 'plain' },
95
- ],
96
- },
97
- ],
98
- }
99
- },
100
- actions: {
101
- install: (scope, event) => ({
102
- command: { name: 'atp', args: 'install' },
103
- toast: isEn(event) ? 'Install started; conflicts will be listed' : '已发起安装,冲突会在对话里列出',
104
- }),
105
- force: (scope, event) => ({
106
- command: { name: 'atp', args: 'install force' },
107
- toast: isEn(event) ? 'Overwrite install started (originals stashed)' : '已发起覆盖式安装(原件会暂存,可回滚)',
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' }),
113
- },
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
- const notInstalled = total === 0 && got.installed === false
170
- const installedClean = total === 0 && got.installed === true
171
- emit({
172
- headline: notInstalled
173
- ? '未安装:点「安装到工作区」即可写入。'
174
- : installedClean
175
- ? '已安装,且内容与当前版本一致——重复安装不会改动任何文件。'
176
- : `共 ${total} 项冲突,已决定 ${total - pending.length} 项`,
177
- dir: got.dir,
178
- remaining: `${pending.length} / ${total}`,
179
- current: current === undefined ? '—' : `${current.index + 1}. ${current.rel}`,
180
- reason: current?.reason ?? '',
181
- hint: notInstalled
182
- ? '回到「协作规程」面板点「安装到工作区」。'
183
- : installedClean
184
- ? '想把文件强制刷成当前版本,用「协作规程」里的「覆盖式安装」。'
185
- : '每点一项即定案;全部定案后自动执行 /atp apply。要改名请用命令:/atp apply 1=改名:新名字',
186
- })
187
- return () => {}
188
- },
189
- actions: {
190
- reload: () => ({ refresh: true }),
191
- overwrite: (scope, event) => decide(scope, event, 'overwrite'),
192
- backup: (scope, event) => decide(scope, event, 'backup'),
193
- },
194
- })
195
-
196
- /** 记一项决策;全部定案后用后端的 applyArgs 生成参数并执行。 */
197
- async function decide(scope, event, action) {
198
- const got = await readConflicts(scope)
199
- if (got.state !== 'ok') {
200
- return { refresh: true, toast: isEn(event) ? 'Workspace unavailable' : '拿不到工作区' }
201
- }
202
- const key = got.conflicts.map((c) => c.rel).join('|')
203
- const entry = decisionState(scope, key)
204
- const index = got.conflicts.map((_, i) => i).find((i) => !entry.map.has(i))
205
- if (index === undefined) return { refresh: true }
206
- entry.map.set(index, action)
207
- const remaining = got.conflicts.filter((_, i) => !entry.map.has(i)).length
208
- if (remaining > 0) {
209
- const label = action === 'backup' ? '备份' : '覆盖'
210
- return { refresh: true, toast: isEn(event) ? `Recorded #${index + 1}` : `已记下:第 ${index + 1} 项${label}` }
211
- }
212
- const decisions = got.conflicts.map((_, i) => entry.map.get(i) ?? 'overwrite')
213
- const args = got.svc.applyArgs(got.conflicts.length, decisions)
214
- sessions.delete(String(scope?.sessionId ?? ''))
215
- return [
216
- { command: { name: 'atp', args } },
217
- { refresh: true },
218
- { toast: isEn(event) ? 'All decisions applied' : '已按你的决定执行安装' },
219
- ]
220
- }
221
- })
222
- }
@@ -1,63 +0,0 @@
1
- {
2
- "name": "local-atp",
3
- "version": "0.1.0",
4
- "private": true,
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "dsh": {
8
- "bundle": {
9
- "patch": "./cordis.patch.yml"
10
- }
11
- },
12
- "engines": {
13
- "dsh": ">=0.2.1-rc.2 <0.3.0-0"
14
- },
15
- "dshGo": {
16
- "v": 1,
17
- "title": {
18
- "zh": "协作规程",
19
- "en": "Playbook"
20
- },
21
- "icon": "bookmark",
22
- "contributes": {
23
- "composer.actions": [
24
- {
25
- "id": "open-playbook",
26
- "label": {
27
- "zh": "协作规程",
28
- "en": "Playbook"
29
- },
30
- "icon": "bookmark"
31
- }
32
- ],
33
- "panels": [
34
- {
35
- "id": "playbook",
36
- "title": {
37
- "zh": "协作规程",
38
- "en": "Playbook"
39
- },
40
- "icon": "bookmark",
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
- ]
59
- }
60
- ]
61
- }
62
- }
63
- }