dsh-agent-team-playbook 1.33.2 → 1.34.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.en.md ADDED
@@ -0,0 +1,145 @@
1
+ # Agent Team Playbook · Multi-Agent Collaboration Workflow
2
+
3
+ [中文](README.md) | English
4
+
5
+ > [![npm version](https://img.shields.io/npm/v/dsh-agent-team-playbook)](https://www.npmjs.com/package/dsh-agent-team-playbook)
6
+ > [![license](https://img.shields.io/npm/l/dsh-agent-team-playbook)](LICENSE)
7
+ > ![DSH](https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.1%20%3C0.3.0-2f6f4f)
8
+
9
+ A complete collaboration protocol for teams of one Lead plus several AI teammates: how to size a task, split the work, write a brief, audit, accept, and retro.
10
+
11
+ Not a prompt collection — **executable process and gates**: every rule maps to a checkable action and a file where its result lands.
12
+
13
+ ```
14
+ dsh plugin --profile web add dsh-agent-team-playbook # command + web panel (writes nothing)
15
+ npx dsh-agent-team-playbook init # or install as resident context (writes AGENTS.md + docs/)
16
+ ```
17
+
18
+ ## What it fixes
19
+
20
+ Multi-agent work rarely fails because the model is not smart enough. It fails because:
21
+
22
+ - no completion criteria were set, so the work is discovered to be wrong only at the end
23
+ - no write-scope exclusivity, so two teammates overwrite each other's file
24
+ - auditing is skipped and the debugging cost is pushed onto real hardware
25
+ - conclusions live only in the chat and are gone by the next round
26
+ - the same pit is stepped in three times because nobody did a root-cause pass
27
+
28
+ This repository turns those lessons into clauses, templates and checklists.
29
+
30
+ ## Structure
31
+
32
+ ```
33
+ AGENTS.md resident core (<=8k chars): charter, iron rules, tier table, hard clauses, index
34
+ docs/workflow/rules/ detail volumes, read on demand (9 of them)
35
+ docs/workflow/practices/ experience library, organised by problem type
36
+ ```
37
+
38
+ Design rule: **the core file only does three things — state principles, give quick reference, point the way**. Low-frequency detail moves down into volumes, the core keeps a trigger line.
39
+
40
+ ### Volumes
41
+
42
+ | # | Contents |
43
+ |---|---|
44
+ | 01 | Charter in detail |
45
+ | 02 | Efficiency and tiering |
46
+ | 03 | Pipeline S0–S6 (incl. S1 investigation, S4 severity and reflow), audit checklist, incident aftermath |
47
+ | 04 | Task brief template |
48
+ | 05 | Task board |
49
+ | 06 | Collaboration rules (Lead/teammate duties, communication) |
50
+ | 07 | User interaction and metrics |
51
+ | 08 | Anti-patterns and quick reference |
52
+ | 09 | Environment adaptation and change log |
53
+
54
+ ## Core mechanics
55
+
56
+ 1. **Charter: feedback-driven** — keep collecting feedback while working, then remove or weaken obstacles, adjust and improve according to it; the object includes both *the project* and *the workflow itself*; plan first, then execute.
57
+ 2. **Flow tiers** — Quick (single point, reversible, 15–30 min) / Standard (regular features and fixes, half a day) / Strict (data, payments, security, irreversible, 1–2 days). Escalate on: touching data, changing an external contract, touching shared files, failing twice in the same place, adding a dependency, unexplained real-device failure.
58
+ 3. **Three kinds of feedback** — negative: find the root cause and remove it; positive: distil and amplify (into templates, checklist items, tests); direction: weigh value against cost.
59
+ 4. **Six-stage pipeline** — S0 goal and acceptance → S1 investigation and planning → S2 review (four questions) → S3 implementation → S4 audit (systematic + root cause, issues graded high/medium/low) → S5 CI gate and real-device verification (parallel, AND-joined) → S6 retro and codification.
60
+ 5. **Experience must land** — route by frequency into core clauses / volumes / experience library; every entry must name *where it was codified*.
61
+
62
+ Details live in [`AGENTS.md`](AGENTS.md) and its §8 index.
63
+
64
+ ## Architecture
65
+
66
+ ![Architecture](docs/assets/architecture.svg)
67
+
68
+ One picture: the **self-feedback evolution loop** (top, the highest principle) → **three-layer structure and artefacts** (middle) → **six-stage pipeline S0–S6** (bottom) → **issue reflow and failure loops** (dashed).
69
+
70
+ ## When it fits, when it does not
71
+
72
+ **Fits**: multi-file changes, parallel teammates, data or release risk, work handed across rounds.
73
+
74
+ **Does not fit**: one-off scripts and exploratory spikes — use the Quick tier and do not add process for its own sake.
75
+
76
+ ## Install
77
+
78
+ ### Option A: DSH plugin (command + panel, writes nothing)
79
+
80
+ ```bash
81
+ dsh plugin --profile web add dsh-agent-team-playbook
82
+ ```
83
+
84
+ Adds an `/atp` command; on web and desktop there is also a panel.
85
+
86
+ | Command | Purpose |
87
+ |---|---|
88
+ | `/atp` | Protocol summary (tiers, four review questions, three retro questions) plus install options |
89
+ | `/atp core` | Print the full core text and follow it for the current turn |
90
+ | `/atp paths` | Absolute paths of the volumes, to read on demand |
91
+ | `/atp install` | Install the playbook into the current workspace, atomically |
92
+ | `/atp install force` | Overwrite same-name content and install |
93
+ | `/atp apply 1=overwrite 2=backup 3=rename:x` | Decide conflicts item by item |
94
+ | `/atp help` | Usage |
95
+
96
+ **Panel** (web / desktop): a “Playbook” chip on the home row (with a count when conflicts exist) and Settings → Playbook.
97
+
98
+ 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.
99
+
100
+ 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.
101
+ (The dsh-go native mobile UI does not load browser halves; use the command there.)
102
+
103
+ ### Option B: install as resident context (writes files, the real payoff)
104
+
105
+ ```bash
106
+ npx dsh-agent-team-playbook init --dry-run # see the plan first
107
+ npx dsh-agent-team-playbook init # install into the current project
108
+ npx dsh-agent-team-playbook init --global # user-global: managed block (pointer)
109
+ npx dsh-agent-team-playbook init --global --inline-core # user-global: inlined core (truly resident)
110
+ ```
111
+
112
+ | Mode | Effect | Resident cost |
113
+ |---|---|---|
114
+ | `init` (project) | Writes `<project>/AGENTS.md` + `docs/`, injected by DSH every turn | ~5.3k chars/turn |
115
+ | `init --global` | Copies to `$DSH_HOME/agent-team-playbook/`, maintains a managed block in `$DSH_HOME/AGENTS.md` (pointer) | ~300 chars/turn |
116
+ | `init --global --inline-core` | Same, but the block inlines the core text | ~6.3k chars/turn |
117
+
118
+ When a same-name file exists you are asked **item by item** (overwrite / rename / skip / all overwrite / abort); nothing is overwritten silently, and non-interactive contexts abort by default. Choosing rename rewrites references inside the documents, so no links break.
119
+
120
+ ### Which option to use
121
+
122
+ | You want | Use |
123
+ |---|---|
124
+ | Look up the protocol now and then, without paying context | Option A (zero context cost) |
125
+ | The agent to **follow it every turn** | Option B (truly resident) |
126
+ | It applied globally, not per project | `init --global` |
127
+
128
+ ## Quick start
129
+
130
+ 1. Install (Option A or B)
131
+ 2. Adjust environment-specific parts per `docs/workflow/rules/09-环境适配与变更记录.md`
132
+ 3. Start the first task on the Standard tier; after one round, trim or tighten based on the retro
133
+ 4. Read volumes on demand through the `AGENTS.md` §8 index — full reading is not required
134
+
135
+ ## More
136
+
137
+ | | |
138
+ |---|---|
139
+ | Version history | [CHANGELOG](CHANGELOG.md) · [Releases](https://github.com/ChongCyrus/agent-team-playbook/releases) |
140
+ | Development | [CONTRIBUTING](CONTRIBUTING.md) (self-check, compatibility range, release flow) |
141
+ | Full protocol | [`AGENTS.md`](AGENTS.md) · [`docs/workflow/`](docs/workflow/) |
142
+
143
+ ## License
144
+
145
+ MIT, see [LICENSE](LICENSE).
package/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Agent Team Playbook · 多智能体协作工作流
2
2
 
3
+ 中文 | [English](README.en.md)
4
+
5
+ > [![npm version](https://img.shields.io/npm/v/dsh-agent-team-playbook)](https://www.npmjs.com/package/dsh-agent-team-playbook)
6
+ > [![license](https://img.shields.io/npm/l/dsh-agent-team-playbook)](LICENSE)
7
+ > ![DSH](https://img.shields.io/badge/DSH-%3E%3D0.2.2--rc.1%20%3C0.3.0-2f6f4f)
8
+
3
9
  给「Lead + 多名 AI 队友」用的一整套协作规程:怎么定档、怎么分工、怎么写任务书、怎么审计、怎么验收、怎么复盘。
4
10
 
5
11
  不是提示词合集,而是**可执行的流程与门禁**——每条规则都对应一个可判真假的动作和落点文件。
@@ -89,6 +95,8 @@ dsh plugin --profile web add dsh-agent-team-playbook
89
95
 
90
96
  **面板**(Web / 桌面端):首页 chip 行的「协作规程」(有冲突时显示数量)+ 设置 → 协作规程。
91
97
 
98
+ 面板只读接口 `/api/agent-team-playbook/status` 走 DSH 的准入校验(同源 + loopback + 宿主认证),跨站请求一律 403;只接受 GET。
99
+
92
100
  遇到同名文件时不会静默覆盖:会列出冲突,让你逐项选 **覆盖 / 备份 / 改名**,处理完自动执行。
93
101
  (dsh-go 手机原生界面不加载浏览器半身,那边用命令即可。)
94
102
 
package/lib/index.js CHANGED
@@ -18,6 +18,7 @@ import { readFileSync, existsSync, readdirSync } from 'node:fs'
18
18
  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
+ import { rejectionFor, connectionAdmissionView } from './trust.js'
21
22
 
22
23
  export const name = 'dsh-agent-team-playbook'
23
24
 
@@ -392,12 +393,22 @@ function readFileSyncSafe(file) {
392
393
  }
393
394
  }
394
395
 
395
- export function createStatusHandler() {
396
+ export function createStatusHandler({ connection } = {}) {
396
397
  return async function statusHandler(req, res) {
397
398
  const send = (status, payload) => {
398
399
  res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
399
400
  res.end(JSON.stringify(payload))
400
401
  }
402
+ // 准入校验:本路由比内核的 /api 更长,会抢在 connection 服务之前执行,必须自己把关。
403
+ // 传入的可能是准入视图、也可能直接是 connection 服务,统一包一层(幂等)。
404
+ const rejection = rejectionFor(req, connectionAdmissionView(() => connection))
405
+ if (rejection !== undefined) {
406
+ return send(rejection, { ok: false, error: rejection === 503 ? 'admission unavailable' : 'forbidden' })
407
+ }
408
+ if (String(req.method ?? 'GET').toUpperCase() !== 'GET') {
409
+ res.setHeader?.('allow', 'GET')
410
+ return send(405, { ok: false, error: 'method not allowed' })
411
+ }
401
412
  try {
402
413
  const url = new URL(req.url ?? '/', 'http://localhost')
403
414
  const cwd = url.searchParams.get('cwd')
@@ -435,11 +446,14 @@ export function createStatusHandler() {
435
446
  export function apply(ctx) {
436
447
  // Web 面板用的只读接口。
437
448
  // 防御:精简 composition 可能没有 inject/webServer/effect —— 静默跳过,不影响命令注册。
449
+ // connection 可能在插件加载后才发布,所以传 thunk 按请求读取
450
+ const optionalService = (name) => (typeof ctx.get === 'function' ? ctx.get(name) : undefined)
451
+ const fenceConnection = connectionAdmissionView(() => optionalService('connection'))
438
452
  if (typeof ctx.inject === 'function') {
439
453
  try {
440
454
  ctx.inject(['webServer'], (scoped) => {
441
455
  const server = scoped?.webServer
442
- const handler = createStatusHandler()
456
+ const handler = createStatusHandler({ connection: fenceConnection })
443
457
  const register = () => server.register({ kind: 'prefix', path: '/api/agent-team-playbook', handler })
444
458
  if (typeof scoped?.effect === 'function') scoped.effect(register, 'agent-team-playbook: status api')
445
459
  else register()
package/lib/trust.js ADDED
@@ -0,0 +1,124 @@
1
+ /**
2
+ * HTTP 准入校验(trust fence)——插件自己注册的路由必须自己把关。
3
+ *
4
+ * 为什么需要:`webServer.register({kind:'prefix'})` 的路由按「最长前缀优先」派发,
5
+ * 我们的 `/api/agent-team-playbook/...` 比内核的 `/api` 更长,因此会**抢在**
6
+ * connection 服务的准入检查之前执行。若不自行校验,同一台机器上任意浏览器页面
7
+ * 都能直接调用(跨站请求、Origin 不匹配都不拦)。
8
+ *
9
+ * 两层,依次尝试:
10
+ * 1. 组合里存在 `connection` 服务时,使用内核自己的准入判定
11
+ * (`admit(req)` 返回 `{rejection}`,旧版本宿主用 `requestRejection(req)` 返回裸状态码);
12
+ * 2. 否则用结构复刻:只允许 loopback Host、拒绝跨站请求、Origin/Referer 必须与 Host 同源
13
+ * (桌面端 `dsh-app://app` 中继的 Referer 例外)。
14
+ *
15
+ * 思路与 `dsh-get-it-for-free` 的 src/trust.js 一致;此处按本插件需要精简重写。
16
+ */
17
+
18
+ const LOOPBACK_NAMES = new Set(['127.0.0.1', '[::1]', '::1', 'localhost'])
19
+
20
+ /**
21
+ * 把 connection 服务包装成 `{admit}` 视图。
22
+ * 传入 thunk:服务可能在插件加载之后才发布,必须按请求重新读取。
23
+ * @param {object|(() => object|undefined)} service
24
+ * @returns {{admit?: (req: object) => ({rejection: number}|undefined)}}
25
+ */
26
+ export function connectionAdmissionView(service) {
27
+ return {
28
+ get admit() {
29
+ const current = typeof service === 'function' ? service() : service
30
+ if (current === undefined || current === null) return undefined
31
+ if (typeof current.admit !== 'function' && typeof current.requestRejection === 'function') {
32
+ return (req) => {
33
+ const status = current.requestRejection(req)
34
+ return status === undefined ? undefined : { rejection: status }
35
+ }
36
+ }
37
+ if (typeof current.admit !== 'function') return undefined
38
+ return (req) => current.admit(req)
39
+ },
40
+ }
41
+ }
42
+
43
+ /**
44
+ * 判定一次请求。
45
+ * @param {import('node:http').IncomingMessage} req
46
+ * @param {object} [connection] 准入视图(可省略)
47
+ * @param {(d: {status: number, source: string, reason: string}) => void} [onRejection] 仅固定字段,不含请求内容
48
+ * @returns {number|undefined} 拒绝用的 HTTP 状态码;`undefined` 表示放行
49
+ */
50
+ export function rejectionFor(req, connection, onRejection) {
51
+ let decision
52
+ try {
53
+ const admit = connection?.admit
54
+ if (typeof admit === 'function') {
55
+ const admission = admit(req)
56
+ const status = admission && typeof admission === 'object' ? admission.rejection : undefined
57
+ if (status === undefined) return undefined
58
+ decision = { status, source: 'connection', reason: 'host-rejected' }
59
+ }
60
+ } catch {
61
+ // 宿主服务异常时绝不跳过浏览器认证:按 503 拒绝
62
+ decision = { status: 503, source: 'connection', reason: 'admission-error' }
63
+ }
64
+ if (decision === undefined) {
65
+ const reason = structuralReason(req)
66
+ if (reason === undefined) return undefined
67
+ decision = { status: 403, source: 'structural', reason }
68
+ }
69
+ try {
70
+ onRejection?.(decision)
71
+ } catch {
72
+ /* 诊断是旁路;打日志失败不改变 HTTP 结论 */
73
+ }
74
+ return decision.status
75
+ }
76
+
77
+ /** 不看连接服务时的结构判定:只放行同源 loopback 请求。 */
78
+ function structuralReason(req) {
79
+ const headers = req?.headers ?? {}
80
+ const host = authorityOf(headers.host, 'http')
81
+ if (host === null || !LOOPBACK_NAMES.has(host.hostname)) return 'host-not-loopback'
82
+ const site = String(headers['sec-fetch-site'] ?? '').toLowerCase()
83
+ if (site === 'cross-site') return 'cross-site'
84
+ for (const header of ['origin', 'referer']) {
85
+ const raw = headers[header]
86
+ if (typeof raw !== 'string' || raw.trim() === '') continue
87
+ if (header === 'referer' && isDesktopRelayReferer(raw)) {
88
+ // 桌面端转发时保留这个 Referer:它不是 Origin 授权,也不能覆盖宿主的认证结论
89
+ if (headers.origin !== undefined || headers['sec-fetch-site'] !== undefined) return 'desktop-relay-markers'
90
+ continue
91
+ }
92
+ const authority = authorityOf(raw.trim())
93
+ if (authority === null) return `${header}-invalid`
94
+ if (authority.scheme !== host.scheme || authority.hostname !== host.hostname || authority.port !== host.port) {
95
+ return `${header}-mismatch`
96
+ }
97
+ }
98
+ return undefined
99
+ }
100
+
101
+ /** 只认桌面端自己的应用页,不接受任意自定义协议页。 */
102
+ function isDesktopRelayReferer(value) {
103
+ try {
104
+ const url = new URL(value)
105
+ return url.protocol === 'dsh-app:' && url.hostname === 'app' && url.port === ''
106
+ && url.username === '' && url.password === ''
107
+ } catch {
108
+ return false
109
+ }
110
+ }
111
+
112
+ /** 拆 `Host/Origin/Referer` 为 {scheme, hostname, port};端口按协议补默认值。 */
113
+ function authorityOf(value, defaultScheme) {
114
+ if (typeof value !== 'string' || value.trim() === '') return null
115
+ let url
116
+ try {
117
+ url = new URL(value.includes('://') ? value.trim() : `${defaultScheme ?? 'http'}://${value.trim()}`)
118
+ } catch {
119
+ return null
120
+ }
121
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') return null
122
+ const port = url.port === '' ? (url.protocol === 'https:' ? '443' : '80') : url.port
123
+ return { scheme: url.protocol.replace(':', ''), hostname: url.hostname.toLowerCase(), port }
124
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agent-team-playbook",
3
- "version": "1.33.2",
3
+ "version": "1.34.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",
@@ -23,6 +23,7 @@
23
23
  "assets",
24
24
  "playbook",
25
25
  "README.md",
26
+ "README.en.md",
26
27
  "CONTRIBUTING.md",
27
28
  "CHANGELOG.md",
28
29
  "LICENSE"