dsh-agent-team-playbook 1.33.3 → 1.34.1

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 CHANGED
@@ -63,7 +63,9 @@ Details live in [`AGENTS.md`](AGENTS.md) and its §8 index.
63
63
 
64
64
  ## Architecture
65
65
 
66
- ![Architecture](docs/assets/architecture.svg)
66
+ ![Architecture](https://cdn.jsdelivr.net/gh/ChongCyrus/agent-team-playbook@main/docs/assets/architecture.svg)
67
+
68
+ > Served through the jsDelivr CDN: raw.githubusercontent is often unreachable from mainland China, and npm does not resolve relative image paths. The file itself is [`docs/assets/architecture.svg`](docs/assets/architecture.svg).
67
69
 
68
70
  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
71
 
@@ -95,6 +97,8 @@ Adds an `/atp` command; on web and desktop there is also a panel.
95
97
 
96
98
  **Panel** (web / desktop): a “Playbook” chip on the home row (with a count when conflicts exist) and Settings → Playbook.
97
99
 
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
+
98
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.
99
103
  (The dsh-go native mobile UI does not load browser halves; use the command there.)
100
104
 
package/README.md CHANGED
@@ -63,7 +63,9 @@ docs/workflow/practices/ 经验与做法库(按问题类型组织)
63
63
 
64
64
  ## 架构总览
65
65
 
66
- ![架构总览](docs/assets/architecture.svg)
66
+ ![架构总览](https://cdn.jsdelivr.net/gh/ChongCyrus/agent-team-playbook@main/docs/assets/architecture.svg)
67
+
68
+ > 图片走 jsDelivr CDN(GitHub raw 在国内常不可达,npm 也不解析相对路径)。文件本体在 [`docs/assets/architecture.svg`](docs/assets/architecture.svg)。
67
69
 
68
70
  一张图看懂:**自反馈进化环**(顶部,全文最高原则)→ **三层结构与产物落点**(中部)→ **六阶段流水线 S0–S6**(下部)→ **问题回流与失败回环**(虚线)。
69
71
 
@@ -95,6 +97,8 @@ dsh plugin --profile web add dsh-agent-team-playbook
95
97
 
96
98
  **面板**(Web / 桌面端):首页 chip 行的「协作规程」(有冲突时显示数量)+ 设置 → 协作规程。
97
99
 
100
+ 面板只读接口 `/api/agent-team-playbook/status` 走 DSH 的准入校验(同源 + loopback + 宿主认证),跨站请求一律 403;只接受 GET。
101
+
98
102
  遇到同名文件时不会静默覆盖:会列出冲突,让你逐项选 **覆盖 / 备份 / 改名**,处理完自动执行。
99
103
  (dsh-go 手机原生界面不加载浏览器半身,那边用命令即可。)
100
104
 
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.3",
3
+ "version": "1.34.1",
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",