@boyingliu01/xp-gate 0.38.74 → 0.38.76

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 (38) hide show
  1. package/bin/xp-gate.js +17 -1
  2. package/lib/__tests__/doctor-signature-stability.test.js +55 -0
  3. package/lib/__tests__/doctor.test.js +6 -1
  4. package/lib/__tests__/gate2-verdict.test.js +126 -0
  5. package/lib/__tests__/issue-566-sync-hooks-backup.test.js +23 -16
  6. package/lib/__tests__/jscpd-entry-resolution.test.js +143 -0
  7. package/lib/__tests__/tsx-resolution.test.js +89 -0
  8. package/lib/doctor.js +99 -3
  9. package/lib/gate-runner.js +275 -41
  10. package/lib/mattpocock-license-verdict.json +1 -1
  11. package/lib/tsx-resolve.js +48 -0
  12. package/package.json +1 -1
  13. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  14. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  15. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  16. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  17. package/plugins/dsh/lib/hooks.d.ts +10 -1
  18. package/plugins/dsh/lib/hooks.d.ts.map +1 -1
  19. package/plugins/dsh/lib/hooks.js +56 -5
  20. package/plugins/dsh/lib/index.js +6 -1
  21. package/plugins/dsh/package.json +1 -1
  22. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  23. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  24. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  25. package/plugins/dsh/src/hooks.test.ts +70 -0
  26. package/plugins/dsh/src/hooks.ts +66 -5
  27. package/plugins/dsh/src/index.ts +6 -1
  28. package/plugins/opencode/package.json +1 -1
  29. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  30. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  31. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  32. package/plugins/qoder/plugin.json +1 -1
  33. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  34. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  35. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  36. package/skills/delphi-review/AGENTS.md +1 -1
  37. package/skills/sprint-flow/AGENTS.md +1 -1
  38. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -175,3 +175,73 @@ describe("delphiGuardDecision deadlock", () => {
175
175
  }
176
176
  })
177
177
  })
178
+
179
+ /**
180
+ * @test REQ-DSH-016 worktrees do not gate each other
181
+ * @intent 复现并锁定「worktree 互锁」:判定只读会话 cwd 下的 .sprint-state,
182
+ * 不看目标文件属于哪个 worktree,导致 A worktree 的未通过评审
183
+ * 拦住 B worktree 的写入(反之亦然)。
184
+ * @covers AC-DSH-016-01 AC-DSH-016-02
185
+ *
186
+ * `.sprint-state/` is gitignored, so every worktree carries its OWN copy and every
187
+ * sprint runs its review inside its own worktree. Measured against a real session
188
+ * before the fix: with the session cwd in a REQUEST_CHANGES worktree, an edit aimed
189
+ * at a *different* worktree that had already reached APPROVED was still denied --
190
+ * the two sprints jailed each other. Only one could be unblocked at a time, and
191
+ * running a second review made it worse rather than better.
192
+ */
193
+ describe("delphiGuardDecision across worktrees", () => {
194
+ /** Build a checkout-shaped directory with a given verdict. */
195
+ function checkout(verdict: "APPROVED" | "REQUEST_CHANGES" | "none"): string {
196
+ const root = mkdtempSync(join(dir, "wt-"))
197
+ if (verdict === "none") return root
198
+ try {
199
+ mkdirSync(join(root, ".sprint-state"), { recursive: true })
200
+ writeFileSync(
201
+ join(root, ".sprint-state", "delphi-reviewed.json"),
202
+ JSON.stringify({ verdict, timestamp: "2026-10-27T10:00:00.000Z" }),
203
+ "utf8",
204
+ )
205
+ } catch (error) {
206
+ throw new Error(`cannot build scratch worktree: ${(error as Error).message}`)
207
+ }
208
+ return root
209
+ }
210
+
211
+ it("judges the worktree the file belongs to, not the one the session opened in", () => {
212
+ // The failing worktree opened first; the approved one is the actual target.
213
+ const rejected = checkout("REQUEST_CHANGES")
214
+ const approved = checkout("APPROVED")
215
+ const target = join(approved, "src", "impl.ts")
216
+
217
+ expect(
218
+ delphiGuardDecision(rejected, "edit", { path: target }),
219
+ "a write into the APPROVED worktree must not be stopped by another worktree's rejection",
220
+ ).toBeUndefined()
221
+
222
+ // And the converse still holds: the rejected worktree stays gated from itself.
223
+ expect(
224
+ delphiGuardDecision(rejected, "edit", { path: join(rejected, "src", "impl.ts") }),
225
+ "the REQUEST_CHANGES worktree must still gate its own writes",
226
+ ).toBeDefined()
227
+ })
228
+
229
+ it("does not let an approved worktree authorise writes elsewhere", () => {
230
+ // Without this, the fix would be a hole: opening the session in an approved
231
+ // worktree would unlock every other checkout on disk.
232
+ const approved = checkout("APPROVED")
233
+ const rejected = checkout("REQUEST_CHANGES")
234
+
235
+ expect(
236
+ delphiGuardDecision(approved, "edit", { path: join(rejected, "src", "impl.ts") }),
237
+ "an APPROVED verdict must not travel to another worktree",
238
+ ).toBeDefined()
239
+ })
240
+
241
+ it("keeps the session cwd as the fallback when the tool names no target", () => {
242
+ // `bash` carries no file_path. It must still be judged against the session's
243
+ // worktree, which is the only root the guard can attribute it to.
244
+ const rejected = checkout("REQUEST_CHANGES")
245
+ expect(delphiGuardDecision(rejected, "bash")).toBeDefined()
246
+ })
247
+ })
@@ -20,7 +20,7 @@
20
20
  */
21
21
 
22
22
  import { existsSync, readFileSync } from "node:fs"
23
- import { join } from "node:path"
23
+ import { dirname, isAbsolute, join, resolve } from "node:path"
24
24
 
25
25
  /**
26
26
  * Tools the sprint guard must never block. Everything else is gated.
@@ -80,6 +80,58 @@ export interface GuardDenial {
80
80
  readonly reason: string
81
81
  }
82
82
 
83
+ /** Where a tool call is aimed, when it names a file. */
84
+ export interface GuardTarget {
85
+ /** Absolute or cwd-relative path of the file being written. */
86
+ readonly path?: string
87
+ }
88
+
89
+ /**
90
+ * The filesystem root that should be judged for this call.
91
+ *
92
+ * `.sprint-state/` is gitignored, so EVERY worktree carries its own copy and every
93
+ * sprint runs its review inside its own worktree. Judging by the session cwd
94
+ * instead has two consequences, both measured against a real session:
95
+ *
96
+ * - sprints jail each other: one worktree's REQUEST_CHANGES blocked writes into a
97
+ * DIFFERENT worktree that had already reached APPROVED, so only one sprint could
98
+ * be unblocked at a time;
99
+ * - an APPROVED verdict leaks: a session opened in an approved worktree would
100
+ * authorise writes into any other checkout on disk.
101
+ *
102
+ * So the target file decides when there is one. Tools that name no file (`bash`)
103
+ * keep the session cwd, which is the only root they can honestly be attributed to.
104
+ */
105
+ function guardRoot(cwd: string, target?: GuardTarget): string {
106
+ if (!target?.path) return cwd
107
+ const absolute = isAbsolute(target.path) ? target.path : resolve(cwd, target.path)
108
+ return findWorktreeRoot(dirname(absolute)) ?? resolveWorktreeRoot(cwd)
109
+ }
110
+
111
+ /**
112
+ * Walk up from `start` to the nearest directory holding `.sprint-state`, and report
113
+ * the worktree root that directory belongs to.
114
+ *
115
+ * Stopping at the first `.sprint-state` is what keeps two worktrees apart: each has
116
+ * its own, so the walk finds the closest one rather than a parent checkout's.
117
+ */
118
+ function findWorktreeRoot(start: string): string | undefined {
119
+ let dir = start
120
+ // Bounded: a malformed tree must not spin, and a real path never needs more.
121
+ for (let depth = 0; depth < 64; depth += 1) {
122
+ if (existsSync(join(dir, SPRINT_STATE_DIR))) return dir
123
+ const parent = dirname(dir)
124
+ if (parent === dir) break
125
+ dir = parent
126
+ }
127
+ return undefined
128
+ }
129
+
130
+ /** The worktree root a cwd sits in, whether or not it has sprint state yet. */
131
+ function resolveWorktreeRoot(cwd: string): string {
132
+ return findWorktreeRoot(cwd) ?? cwd
133
+ }
134
+
83
135
  /** The file extensions the principles engine actually covers. */
84
136
  const CHECKABLE_EXTENSIONS: ReadonlySet<string> = new Set([
85
137
  ".ts",
@@ -155,12 +207,21 @@ function readVerdict(root: string): { verdict?: string; unreadable?: string } {
155
207
  * Decide whether an edit may proceed.
156
208
  *
157
209
  * Returns undefined to mean "allow" so the caller can `if (denial) return denial`.
210
+ *
211
+ * `target` is what the call is aimed at. When it names a file, that file's worktree
212
+ * decides -- passing the session cwd alone is what let concurrent sprints jail each
213
+ * other; see {@link guardRoot}.
158
214
  */
159
- export function delphiGuardDecision(root: string, toolName: string): GuardDenial | undefined {
215
+ export function delphiGuardDecision(
216
+ root: string,
217
+ toolName: string,
218
+ target?: GuardTarget,
219
+ ): GuardDenial | undefined {
160
220
  if (!mayModifyFiles(toolName)) return undefined
161
- if (!existsSync(join(root, SPRINT_STATE_DIR))) return undefined
221
+ const stateRoot = guardRoot(root, target)
222
+ if (!existsSync(join(stateRoot, SPRINT_STATE_DIR))) return undefined
162
223
 
163
- const verdictFile = join(root, SPRINT_STATE_DIR, VERDICT_FILE)
224
+ const verdictFile = join(stateRoot, SPRINT_STATE_DIR, VERDICT_FILE)
164
225
  if (!existsSync(verdictFile)) {
165
226
  return {
166
227
  kind: "deny",
@@ -170,7 +231,7 @@ export function delphiGuardDecision(root: string, toolName: string): GuardDenial
170
231
  }
171
232
  }
172
233
 
173
- const { verdict, unreadable } = readVerdict(root)
234
+ const { verdict, unreadable } = readVerdict(stateRoot)
174
235
  if (unreadable !== undefined) {
175
236
  return {
176
237
  kind: "deny",
@@ -629,8 +629,13 @@ function registerHooks(
629
629
  if (cfg.delphiGuard !== "off") {
630
630
  ctx.on("tools/pre-execute", async (exec, next) => {
631
631
  const cwd = sessionCwd(exec) ?? process.cwd()
632
+ // The file decides which worktree is judged when the call names one: sprints
633
+ // run in separate worktrees with their own `.sprint-state`, so judging by the
634
+ // session cwd alone let one sprint block another (and let one APPROVED verdict
635
+ // authorise writes anywhere). See guardRoot in hooks.ts.
636
+ const target = { path: writtenPath(exec.arguments) }
632
637
  // Deny before dispatch so the edit never reaches the filesystem.
633
- return delphiGuardDecision(cwd, exec.name) ?? next()
638
+ return delphiGuardDecision(cwd, exec.name, target) ?? next()
634
639
  })
635
640
  }
636
641
  if (cfg.principlesCheck !== "off") {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@boyingliu01/opencode-plugin",
3
- "version": "0.38.74",
3
+ "version": "0.38.76",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "XP-Gate quality gates + AI workflow skills for OpenCode",
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xp-gate",
3
- "version": "0.38.74",
3
+ "version": "0.38.76",
4
4
  "displayName": "XP-Gate",
5
5
  "description": "Extreme Programming quality gates + AI workflow skills for Qoder. Includes 12 pre-commit gates (Gate 0-11), 8 pre-push gates, Sprint Flow (6 phases), and Delphi multi-expert review (>=90% consensus).",
6
6
  "author": {
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Delphi Consensus Review — multi-round anonymous expert review (≥90% threshold, exactly 3 experts with distinct executable model IDs). Supports design, requirements, and code-walkthrough modes.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  **6-phase** development pipeline (v2.0 compact redesign, Issue #290): PREP → DESIGN → BUILD → VERIFY → SHIP → CLOSE. Phase 3/6 BUILD default build mode is **ralph-loop** (REQ-level iteration; each REQ starts from a clean context instead of accumulating one across REQs). HARD-GATE between DESIGN (2/6) and BUILD (3/6): design must pass Delphi review (≥90% consensus) before any coding.
@@ -3,7 +3,7 @@
3
3
  **Generated:** 2026-11-04
4
4
  **Commit:** eb2097b0
5
5
  **Branch:** sprint/2026-11-03-02
6
- **Version:** 0.38.74.0
6
+ **Version:** 0.38.76.0
7
7
 
8
8
  ## OVERVIEW
9
9
  Test-Specification Alignment Engine — two-stage validation ensuring tests accurately reflect requirements and design specs.