forgedock 1.1.1 → 1.1.3

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 (174) hide show
  1. package/README.md +53 -8
  2. package/bin/batch-runner.mjs +339 -0
  3. package/bin/demo.mjs +92 -7
  4. package/bin/engine/phases.mjs +24 -2
  5. package/bin/engine/state.mjs +8 -3
  6. package/bin/engine-cli.mjs +177 -5
  7. package/bin/forgedock.mjs +409 -26
  8. package/bin/hooks/interactive-engine.mjs +509 -0
  9. package/bin/hooks/pre-tool-use.mjs +498 -0
  10. package/bin/hooks/subagent-stop-enforce.mjs +197 -0
  11. package/bin/journey.mjs +72 -14
  12. package/bin/registry.mjs +139 -0
  13. package/bin/report.mjs +447 -0
  14. package/bin/runner.mjs +70 -20
  15. package/bin/settings-hook.mjs +235 -1
  16. package/commands/adopt.md +4 -1
  17. package/commands/analytics.md +4 -1
  18. package/commands/audit-agents.md +110 -27
  19. package/commands/audit.md +20 -1
  20. package/commands/autopilot.md +518 -361
  21. package/commands/changelog.md +2 -1
  22. package/commands/ci-audit.md +2 -1
  23. package/commands/cleanup.md +161 -1
  24. package/commands/compat-audit.md +2 -1
  25. package/commands/deploy-info.md +58 -1
  26. package/commands/deploy-pr.md +485 -0
  27. package/commands/design-bench.md +5 -1
  28. package/commands/design-render-critique-loop.md +1 -1
  29. package/commands/diagnose.md +2 -1
  30. package/commands/explain.md +2 -1
  31. package/commands/fix-ci.md +577 -0
  32. package/commands/forge-stats.md +121 -2
  33. package/commands/forgedock-init.md +1 -1
  34. package/commands/geo-audit.md +3 -0
  35. package/commands/incident-response.md +2 -1
  36. package/commands/issue.md +23 -2
  37. package/commands/milestone.md +77 -12
  38. package/commands/optimize.md +2 -1
  39. package/commands/orchestrate/config.md +67 -0
  40. package/commands/orchestrate/phase-1-resolve.md +159 -0
  41. package/commands/orchestrate/phase-2-triage.md +126 -0
  42. package/commands/orchestrate/phase-2.5-synthesis.md +156 -0
  43. package/commands/orchestrate/phase-3-dependency.md +591 -0
  44. package/commands/orchestrate/phase-4-execution.md +962 -0
  45. package/commands/orchestrate/phase-5-cleanup.md +47 -0
  46. package/commands/orchestrate/phase-6-report.md +198 -0
  47. package/commands/orchestrate/safety.md +62 -0
  48. package/commands/orchestrate.md +25 -2045
  49. package/commands/pipeline-health/config.md +34 -0
  50. package/commands/pipeline-health/phase-1-context.md +180 -0
  51. package/commands/pipeline-health/phase-2-metrics.md +1729 -0
  52. package/commands/pipeline-health/phase-3-analyze.md +204 -0
  53. package/commands/pipeline-health/phase-4-proposals.md +117 -0
  54. package/commands/pipeline-health/phase-5-report.md +284 -0
  55. package/commands/pipeline-health/phase-6-summary.md +52 -0
  56. package/commands/pipeline-health.md +25 -2401
  57. package/commands/pipeline-resume.md +24 -1
  58. package/commands/pipeline-status.md +65 -0
  59. package/commands/qa-sweep.md +4 -1
  60. package/commands/quality-gate.md +248 -10
  61. package/commands/recover-orphans.md +576 -0
  62. package/commands/replay.md +2 -1
  63. package/commands/review-pr-agents/api.md +135 -0
  64. package/commands/review-pr-agents/auth.md +137 -0
  65. package/commands/review-pr-agents/billing.md +101 -0
  66. package/commands/review-pr-agents/concurrency.md +145 -0
  67. package/commands/review-pr-agents/database.md +103 -0
  68. package/commands/review-pr-agents/frontend.md +89 -0
  69. package/commands/review-pr-agents/infra.md +385 -0
  70. package/commands/review-pr-agents/protocols.md +185 -0
  71. package/commands/review-pr-agents/scraper.md +185 -0
  72. package/commands/review-pr-agents/security.md +406 -0
  73. package/commands/review-pr-agents.md +45 -1722
  74. package/commands/review-pr-staging.md +196 -40
  75. package/commands/review-pr.md +591 -52
  76. package/commands/rollback.md +2 -1
  77. package/commands/scope.md +2 -1
  78. package/commands/security-audit.md +2 -1
  79. package/commands/signal-planner.md +623 -0
  80. package/commands/sync-ecosystem.md +1 -0
  81. package/commands/test-gate.md +17 -1
  82. package/commands/validate.md +2 -1
  83. package/commands/work-on/build/architect.md +28 -0
  84. package/commands/work-on/build/context.md +2 -0
  85. package/commands/work-on/build/implement.md +3 -1
  86. package/commands/work-on/build/validate.md +26 -7
  87. package/commands/work-on/build.md +163 -24
  88. package/commands/work-on/close.md +130 -3
  89. package/commands/work-on/decompose.md +19 -1
  90. package/commands/work-on/investigate.md +117 -2
  91. package/commands/work-on/review.md +24 -4
  92. package/commands/work-on-monolithic.md +7 -2
  93. package/commands/work-on.md +202 -4
  94. package/docs/BRAND.md +14 -7
  95. package/docs/CI.md +16 -2
  96. package/docs/CODEX.md +36 -1
  97. package/docs/CONFIG.md +5 -8
  98. package/docs/FORGE-PROTOCOL.md +15 -1064
  99. package/docs/anthropic-devrel-outreach.md +2 -2
  100. package/docs/articles/command-decomposition-token-savings.md +214 -0
  101. package/docs/articles/model-release-playbook.md +131 -0
  102. package/docs/articles/per-repo-adaptive-scripts-token-savings.md +27 -25
  103. package/docs/claude-breakpoints.json +75 -5
  104. package/docs/design/abc-benchmark.md +1 -1
  105. package/docs/design/design-spec-schema.md +1 -1
  106. package/docs/design/divergent-generation.md +1 -1
  107. package/docs/design/eval-gate-runbook.md +178 -0
  108. package/docs/design/show-hn-draft.md +26 -1
  109. package/docs/design/token-cost-baseline-1298.md +59 -0
  110. package/docs/eval/README.md +120 -0
  111. package/docs/eval/corpus/seed-v1.json +6 -0
  112. package/docs/eval/published/claude-sonnet-4-6-2026-07-04.json +33 -0
  113. package/docs/site/annotations-explained.md +24 -0
  114. package/docs/site/command-learning-path.md +51 -14
  115. package/docs/site/command-reference.md +386 -111
  116. package/docs/site/for-companies.md +95 -0
  117. package/docs/site/forge-annotation-protocol.md +12 -256
  118. package/docs/site/getting-started.md +43 -4
  119. package/docs/site/github-is-the-memory.md +113 -0
  120. package/docs/site/how-it-works.md +3 -13
  121. package/docs/site/index.md +9 -1
  122. package/docs/spec/eval-run-result.md +147 -0
  123. package/docs/spec/forge-protocol-v1.md +441 -18
  124. package/docs/spec/label-state-machine.md +55 -0
  125. package/docs/spec/review-protocol.md +158 -0
  126. package/docs/spec-graph-schema.md +28 -0
  127. package/docs/superpowers/specs/2026-07-04-economic-self-governance-design.md +181 -0
  128. package/docs/superpowers/specs/2026-07-04-provenance-trail-design.md +189 -0
  129. package/examples/forgedock-demo/README.md +41 -22
  130. package/examples/forgedock-demo/issues/06-bug-tags-type-validation.md +43 -0
  131. package/examples/forgedock-demo/issues/07-bug-negative-offset-pagination.md +42 -0
  132. package/examples/forgedock-demo/issues/08-bug-patch-mass-assignment.md +49 -0
  133. package/examples/forgedock-demo/issues/09-bug-count-injection.md +47 -0
  134. package/examples/forgedock-demo/issues/10-feature-sort-param.md +39 -0
  135. package/examples/forgedock-demo/issues/11-feature-patch-tags.md +37 -0
  136. package/examples/forgedock-demo/issues/12-feature-bulk-create.md +42 -0
  137. package/examples/forgedock-demo/issues/13-feature-archive-notes.md +46 -0
  138. package/examples/forgedock-demo/issues/14-refactor-extract-title-validation.md +41 -0
  139. package/examples/forgedock-demo/issues/15-refactor-protected-route-flag.md +43 -0
  140. package/examples/forgedock-demo/issues/16-refactor-extract-store.md +45 -0
  141. package/examples/forgedock-demo/issues/17-perf-tags-dedup-set.md +35 -0
  142. package/examples/forgedock-demo/issues/18-perf-remove-redundant-sort.md +37 -0
  143. package/examples/forgedock-demo/issues/19-docs-api-reference-full.md +53 -0
  144. package/examples/forgedock-demo/issues/20-docs-intentional-flaw-convention.md +46 -0
  145. package/examples/forgedock-demo/scripts/smoke.js +18 -1
  146. package/examples/forgedock-demo/src/db.js +36 -11
  147. package/examples/forgedock-demo/src/routes/notes.js +106 -9
  148. package/examples/forgedock-demo/src/server.js +4 -1
  149. package/package.json +3 -1
  150. package/packages/protocol/LICENSE +21 -0
  151. package/packages/protocol/src/cli.js +135 -0
  152. package/packages/protocol/src/emit.js +146 -0
  153. package/packages/protocol/src/index.js +43 -0
  154. package/packages/protocol/src/parse.js +254 -0
  155. package/packages/protocol/src/types.js +171 -0
  156. package/packages/protocol/src/validate.js +122 -0
  157. package/scripts/bench-topology-cost.mjs +372 -0
  158. package/scripts/check-command-docs-drift.sh +198 -0
  159. package/scripts/check-protocol-restatements.sh +176 -0
  160. package/scripts/check-registry/README.md +72 -0
  161. package/scripts/check-registry/manifest.json +6 -0
  162. package/scripts/code-index.sh +454 -0
  163. package/scripts/conformance-check.mjs +168 -0
  164. package/scripts/doctor-pipeline-state.sh +484 -0
  165. package/scripts/eval-gate-baseline.json +17 -0
  166. package/scripts/eval-gate-scorecard.mjs +242 -0
  167. package/scripts/eval-scorecard-aggregator.mjs +252 -0
  168. package/scripts/flaky-quarantine.sh +241 -0
  169. package/scripts/forge-annotation.sh +567 -0
  170. package/scripts/issue-dedup.sh +236 -0
  171. package/scripts/validate-annotation-node.mjs +233 -0
  172. package/scripts/worktree-lifecycle.sh +3 -3
  173. package/templates/devdocs/agent/using-forgedock.md +14 -0
  174. package/docs/site/.vitepress/config.mjs +0 -85
@@ -0,0 +1,185 @@
1
+ ---
2
+ install: internal
3
+ ---
4
+ <!-- SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios -->
5
+ <!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
6
+
7
+ # Shared Review Protocols
8
+
9
+ This file contains the shared protocols that ALL review agents must follow.
10
+ It is read alongside individual persona files during Phase 3C agent dispatch.
11
+ Canonical source: `docs/spec/review-protocol.md` — sync changes there first.
12
+
13
+
14
+ ## Per-Agent Input Scoping
15
+
16
+ **Each domain agent receives only the diff slice relevant to its domain**, not the full PR changeset. The orchestrator (Phase 3C of `review-pr.md`) pre-computes these slices and substitutes `[DOMAIN_DIFF_SLICE]` in each agent's prompt before dispatch.
17
+
18
+ **Rationale**: Passing the full changeset to every agent inflates per-child input cost on large PRs. A billing agent reviewing auth code produces noise, not signal. Scoped inputs reduce cost and improve focus.
19
+
20
+ **Fallback rule**: If a domain's file pattern matches nothing in the PR (slice is empty), the orchestrator falls back to the full diff — ensuring no agent is launched with an empty context. This preserves review coverage on PRs where domain boundaries are blurry.
21
+
22
+ **Security agent exception**: The General Security agent ALWAYS receives the full diff — security vulnerabilities are cross-cutting and cannot be safely scoped to a file-path filter.
23
+
24
+ ## Tool-Result Truncation Discipline
25
+
26
+ All tool results consumed by agents — including diff slices, file reads, and command outputs — are capped at **~100K characters**. This mirrors the runner's built-in 100K-char tool-result cap (`bin/runner.mjs`).
27
+
28
+ **Agents must NOT re-fetch `gh pr diff` in full** — use the pre-supplied `[DOMAIN_DIFF_SLICE]` instead. If an agent needs to read a specific file in full (e.g., to trace an import), cap the read at the relevant section using `head -N` or `sed -n 'X,Yp'`. Never pipe unbounded command output into context without a `| head -N` guard.
29
+
30
+ Rationale: agents receiving oversized context perform worse, not better — attention dilutes across irrelevant content, and token limits risk truncating the structured findings block that the triage phase depends on.
31
+
32
+ ---
33
+
34
+ ## Evidence-Based Review Protocol (ALL Agents Follow) <!-- allowlist:check-protocol-restatements -->
35
+
36
+ Every agent MUST follow this protocol:
37
+
38
+ ### 1. Start From the PR Diff
39
+
40
+ **Input scoping**: You have been given a pre-computed diff slice containing only the files relevant to your domain (`[DOMAIN_DIFF_SLICE]`). Do NOT re-fetch `gh pr diff [PR_NUMBER]` in full — use the slice provided. This is capped at ~100K chars, mirroring the runner's tool-result limit.
41
+
42
+ ```bash
43
+ # Verify review is still current before reading diff
44
+ CURRENT_SHA=$(gh pr view [PR_NUMBER] --json headRefOid --jq '.headRefOid')
45
+ if [ "$CURRENT_SHA" != "[REVIEW_SHA]" ]; then
46
+ echo "WARNING: PR HEAD changed during review. Review may be stale."
47
+ echo "Review pinned to: [REVIEW_SHA_SHORT]"
48
+ echo "Current HEAD: $(echo $CURRENT_SHA | cut -c1-7)"
49
+ fi
50
+
51
+ # List files in your domain slice
52
+ gh pr diff [PR_NUMBER] --name-only
53
+
54
+ # Use the pre-computed domain diff slice supplied by the orchestrator:
55
+ # [DOMAIN_DIFF_SLICE]
56
+ ```
57
+
58
+ **Tool-result truncation**: When reading individual files or running commands for deeper investigation, always cap output: `cat file.py | head -200`, `grep ... | head -50`. Never pipe unbounded output into context.
59
+
60
+ **Hot-spot prior**:
61
+ [CHURN_CONTEXT]
62
+
63
+ If a file you are reviewing is listed above as a hot-spot, apply deeper scrutiny to it — high historical churn correlates with defect density. Prefer tracing that file's full code paths (Evidence-Based Review Protocol §2) over a quick pattern scan, and weight ambiguous findings in hot-spot files toward LIKELY rather than POSSIBLE.
64
+
65
+ ### 2. Dynamic Exploration
66
+ - From each changed file, follow imports and function calls
67
+ - Trace data flows across service boundaries (API → Redis → Worker)
68
+ - Search for related code: `grep -rn "function_name" services/`
69
+
70
+ ### 3. Validation Before Reporting
71
+
72
+ | Confidence | Criteria | Action |
73
+ |------------|----------|--------|
74
+ | **CONFIRMED** | Traced the full code path, found specific lines proving the bug | Report as blocking — P1 issue |
75
+ | **LIKELY** | Code pattern suggests issue but mitigations might exist elsewhere | Report with caveat — P2 issue |
76
+ | **POSSIBLE** | Suspicious pattern but couldn't trace the full flow | Report as informational — P3 advisory (non-blocking) |
77
+ | **UNFOUNDED** | Looked for the issue but found mitigations/correct handling | Do NOT report |
78
+
79
+ ### 3.5 REPRODUCTION GATE — Required Before CONFIRMED Classification
80
+
81
+ **MANDATORY**: Before classifying any finding as CONFIRMED, you MUST document one of the following forms of reproduction evidence in your report. A pattern match alone is not sufficient.
82
+
83
+ **Acceptable reproduction evidence (one of)**:
84
+ - **(a) Full code path trace**: List the execution chain from PR-changed code to the failure point. Minimum: 3 steps with specific file + line for each. Example: `src/api/routers/billing.py:142 → credits.py:check_balance():87 → returns None → caller at billing.py:148 raises AttributeError`. The chain must terminate at the actual failure — not at "and then it could fail."
85
+ - **(b) Specific input demonstration**: Provide concrete input values that trigger the failure. Example: `POST /api/v1/scrape with {"url": "http://internal:6432/"}` → `requests.get()` hits internal DB port → SSRF confirmed. The values must be specific (not "if an attacker provides a malicious URL") and must map to actual code in the PR diff.
86
+
87
+ **Downgrade rule**: If you cannot produce either (a) or (b) after a reasonable trace attempt, you MUST classify the finding as **POSSIBLE** — not CONFIRMED or LIKELY. Do NOT use CONFIRMED when the finding is based on:
88
+ - A suspicious pattern without tracing whether the condition is reachable via changed code
89
+ - A theoretical exploit path not grounded in specific lines from the diff
90
+ - A heuristic ("this type of code often has X bug") without verification
91
+
92
+ **POSSIBLE findings are informational advisories** — they are logged and tracked but do NOT block merge and do NOT trigger mandatory fix PRs. When in doubt, POSSIBLE is the correct classification. <!-- Added: forge#371 -->
93
+
94
+ ### 4. SEVERITY CLASSIFICATION — TRACE THE IMPACT
95
+
96
+ **CRITICAL RULE: Never dismiss a finding as "minor", "cosmetic", or "harmless" without tracing its downstream impact.** If you spot something unusual (redundant code, odd patterns, duplicated values), ask: "Does this cause a runtime error, data corruption, or wrong behavior in any code path that touches it?" Trace forward through every consumer of the construct.
97
+
98
+ **Severity decision tree:**
99
+ 1. Will this error at runtime? → **HIGH or CRITICAL** (not "minor redundancy")
100
+ 2. Will this produce wrong data silently? → **HIGH**
101
+ 3. Will this cause degraded performance? → **MEDIUM**
102
+ 4. Is it genuinely cosmetic with no runtime impact after tracing all consumers? → **LOW**
103
+
104
+ If you're unsure whether something is cosmetic or a runtime error, **assume it's a runtime error** and flag it for investigation. A false positive costs a minute of review time. A missed runtime error costs production downtime.
105
+
106
+ ### 5. INTERACTION ANALYSIS — "Pre-existing" Is Not "Safe"
107
+
108
+ **CRITICAL RULE: Never dismiss a finding as "pre-existing, not introduced by this PR" without checking whether NEW code in the PR interacts with the pre-existing construct to create a bug.**
109
+
110
+ A redundant import, an unused variable, or a duplicated constant may be harmless in isolation. But new code added in the same scope can turn it into a crash. Example: a local `import os` inside a function is harmless until new code above it calls `os.getenv()` — Python treats `os` as local for the entire function scope, causing `UnboundLocalError` before the import line is reached.
111
+
112
+ **Before dismissing anything as "pre-existing":**
113
+ 1. List every NEW line in the PR that references the pre-existing construct
114
+ 2. For each reference, ask: "Does the pre-existing construct cause this new line to fail at runtime?"
115
+ 3. If yes → CONFIRMED finding, not a dismissal
116
+
117
+ ### 6. FALSE POSITIVE PREVENTION
118
+
119
+ **Before claiming variable scope issues:** Read the FULL function, count indentation levels, check if/else structure.
120
+
121
+ **Before claiming type/unit mismatches:** Trace the variable to its source. Check if naming is misleading (e.g., `balanceCents` might hold microcents).
122
+
123
+ **Before claiming missing functions/imports:** `grep -rn "functionName" .` — check re-exports, aliases.
124
+
125
+ **Before claiming unreachable code:** Check all callers, dynamic dispatch, test code.
126
+
127
+ **Before dismissing redundant imports as harmless:** In Python, a local `import X` inside a function makes `X` a local variable for the ENTIRE function scope. Any use of `X` before that import line will raise `UnboundLocalError`. Check whether any code (existing or new) references `X` before the local import. This is a CONFIRMED CRITICAL if found — it crashes at runtime.
128
+
129
+ ### 7. Report Format
130
+
131
+ Every finding must include:
132
+ - **File:Line** — Exact location
133
+ - **Code snippet** — The problematic code
134
+ - **Evidence** — Why this is a bug (show the code path)
135
+ - **Confidence** — CONFIRMED/LIKELY/POSSIBLE
136
+ - **What you checked** — List files you read to verify
137
+
138
+ ---
139
+
140
+ ## Structured Findings Protocol
141
+
142
+ **All review agents MUST include a machine-readable findings block at the end of their PR comment.** This is NON-OPTIONAL. Without structured findings, the review system cannot create GitHub issues, and findings die as unread PR comments. Every finding that doesn't become a GitHub issue is a finding that will never be addressed.
143
+
144
+ ### Format
145
+
146
+ Append this block at the very end of your comment (after the `---` footer line, still inside the EOF heredoc). It uses HTML comments so it's invisible in rendered markdown:
147
+
148
+ `<!-- REVIEW-FINDINGS-START -->`
149
+ `<!-- FINDING:PREFIX-N|CONFIDENCE|SEVERITY|file.py:line|One-line summary -->`
150
+ `<!-- REVIEW-FINDINGS-END -->`
151
+
152
+ ### Rules
153
+
154
+ 1. **Include ALL findings at CONFIRMED, LIKELY, and POSSIBLE confidence** — every finding becomes a GitHub issue. Nothing stays as just a PR comment. **POSSIBLE findings are informational advisories (P3/non-blocking)** — they are tracked but do not require a fix PR and do not block merge. CONFIRMED and LIKELY findings are blocking at P1/P2 respectively.
155
+ 2. **One line per finding** — sequential numbering (PREFIX-1, PREFIX-2, ...)
156
+ 3. **Confidence**: `CONFIRMED`, `LIKELY`, or `POSSIBLE`
157
+ 4. **Severity**: `CRITICAL`, `HIGH`, `MEDIUM`, or `LOW`
158
+ 5. **Location**: Exact `file:line` reference
159
+ 6. **Summary**: Concise one-line description (no pipe `|` characters in summary)
160
+ 7. **Empty block**: If no findings at all, include just the START/END markers
161
+ 8. **HTML comments**: The block is invisible in rendered markdown but parseable by the review system
162
+
163
+ ### Domain Prefixes
164
+
165
+ | Agent | Prefix |
166
+ |-------|--------|
167
+ | General Security | `SEC` |
168
+ | Auth Conventions | `AUTH` |
169
+ | Billing Integrity | `BILL` |
170
+ | Concurrency | `CONC` |
171
+ | Scraper Logic | `SCRP` |
172
+ | Frontend Quality | `FE` |
173
+ | API Design | `API` |
174
+ | Database & Migration | `DB` |
175
+ | Infrastructure | `INFRA` |
176
+ ### Example
177
+
178
+ `<!-- REVIEW-FINDINGS-START -->`
179
+ `<!-- FINDING:SEC-1|CONFIRMED|HIGH|src/api/routers/upload.py:45|SQL injection via unsanitized user input in query parameter -->`
180
+ `<!-- FINDING:SEC-2|LIKELY|MEDIUM|src/worker/jobs/process.py:312|Potential SSRF through user-controlled proxy URL -->`
181
+ `<!-- REVIEW-FINDINGS-END -->`
182
+
183
+ ---
184
+
185
+ ## Agent Catalog
@@ -0,0 +1,185 @@
1
+ ---
2
+ install: internal
3
+ ---
4
+ <!-- SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios -->
5
+ <!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
6
+
7
+ # Agent: Domain Logic Auditor
8
+
9
+ > Read `review-pr-agents/protocols.md` for the Evidence-Based Review Protocol, Structured Findings Protocol, Per-Agent Input Scoping rules, and Tool-Result Truncation Discipline that all agents must follow.
10
+
11
+ **Note**: This agent is for projects with a web-scraping or browser-automation domain. It only spawns when `review.domains.scraping` is set in `forge.yaml`. Projects using Playwright solely for E2E testing do not spawn this agent.
12
+
13
+ **Trigger**: SCRAPING domain detected AND `review.domains.scraping` is configured in forge.yaml
14
+ **Type**: `codebase-explorer` | **Model**: `sonnet`
15
+
16
+ **Prompt template:**
17
+ ```
18
+ You are auditing PR #[PR_NUMBER] for domain-specific logic correctness in [PROJECT_NAME].
19
+
20
+ ## Project Domain Architecture
21
+
22
+ [DOMAIN_CONTEXT]
23
+
24
+ If no domain context is configured above, derive the architecture from the changed files: read the primary consumer/worker/handler files to understand the execution model.
25
+
26
+ ## What to Verify
27
+ 1. **Tier/level selection**: Is the starting tier or execution level correct? Does escalation logic work?
28
+ 2. **Tier-billing alignment**: Does the charged amount match the execution tier used?
29
+ 3. **Timeout handling**: Are timeouts configured correctly per tier/level?
30
+ 4. **Error propagation**: Do execution failures propagate correctly?
31
+ 5. **Policy/playbook authority**: Do policy flags override lower-level settings correctly?
32
+ 6. **Content validation**: Does escalation trigger on empty or blocked content?
33
+ 7. **Detection keyword consistency** (when the PR modifies frozenset/tuple/list identifiers used for bot detection, WAF markers, or anti-detection tokens):
34
+ - **Cross-reference sibling sets**: List all other detection-related constants in the same module. For each entry in the modified set, verify it appears in all relevant sibling sets. Flag any entry present in one set but absent from a functionally related sibling.
35
+ - **Intra-file comment/code drift**: Read the full file. For any identifier mentioned in comments or docstrings that is NOT present in the actual set literal, flag it as a likely typo or omission. This is CONFIRMED HIGH — comments describe the intended state; the code contradicts it.
36
+ - **Vendor documentation alignment**: If the PR mentions a specific vendor (Akamai, Cloudflare, DataDome, etc.), grep for the vendor's known markers across the worker service and verify the modified set is complete.
37
+ 8. **Capacity constants**: Any hardcoded numeric constant defining memory limits, pool sizes, timeouts, or thresholds (e.g., `MAX_BROWSERS = 5`, `POOL_SIZE = 10`, `ESTIMATED_MB = 200`):
38
+ - Does the PR or commit message cite a measurement source (e.g., "observed peak 744-890MB", "benchmarked at N req/s", linked issue/PR)?
39
+ - Search git history for prior art that may contradict the constant:
40
+ ```bash
41
+ # Search git log for related measurements — adapt keywords to the constant's domain
42
+ git log --all -20 --oneline --grep="memory" --grep="browser" 2>/dev/null | head -10
43
+ git log --all -20 --oneline --grep="$(echo {CONSTANT_NAME} | tr '_' ' ' | tr '[:upper:]' '[:lower:]')" 2>/dev/null | head -5
44
+ # Check recent PRs that touched the same file for prior measurement context
45
+ git log --oneline --all -20 -- {CHANGED_FILE} 2>/dev/null | head -10
46
+ ```
47
+ - If no measurement source is cited and git history contains contradicting data (e.g., a prior PR documenting real observed values): flag as **CONFIRMED** with note "Hardcoded constant contradicts measured data in git history — verify against production metrics before deploy"
48
+ - If no measurement source is cited and no contradicting git history found: flag as **POSSIBLE** with note "Hardcoded constant without measurement annotation — verify against production metrics"
49
+ - If a measurement source IS cited (comment, commit message, or linked issue): no flag needed
50
+ 9. **API gate semantic correctness** (conditional — trigger: PR modifies any router file that gates existing request parameters behind a new condition):
51
+ When a PR adds or changes a condition that gates a set of request fields behind a resource requirement (API key, feature flag, tier check), **verify independently for EACH parameter in the condition** whether it actually requires the gated resource:
52
+ - For each field in the gate condition (`if request.X or request.Y:`, `if X and Y`): ask "Was this field previously handled without this gate? What is the behavioral change for existing users who send this field without satisfying the gate?"
53
+ - Distinguish resource-dependent fields (e.g., those that invoke an external LLM or BYOK key at execution time) from resource-independent fields (those processed deterministically without the gated resource). A gate that covers both classes is incorrect — the resource-independent field must be routed separately.
54
+ - Inspect the pre-existing code path for each field: search the router and worker files for the field's pre-change handling. If the pre-existing path did NOT require the gated resource, the inclusion of that field in the gate is a **CONFIRMED HIGH** behavioral regression for existing callers.
55
+ - If different fields in the condition reach different execution paths (one resource-dependent, one not), the condition must be split — gate only the fields that require the resource.
56
+
57
+ ```bash
58
+ # Identify gate conditions in changed router files
59
+ ROUTER_FILES=$(gh pr diff [PR_NUMBER] --name-only | grep -E "(router|route|endpoint|handler)" | head -10)
60
+ gh pr diff [PR_NUMBER] -- $ROUTER_FILES | grep "^\+" | grep -E "if request\.|if.*or.*request\." | head -20
61
+
62
+ # For each gated field, check its pre-existing handling path
63
+ git log --all --oneline -10 -- $ROUTER_FILES | head -10
64
+ grep -rn "FIELD_NAME" $(git ls-files | grep -E "\.(py|ts|js)$") | grep -v "^\s*#" | head -20
65
+ ```
66
+ <!-- Added: forge#382 -->
67
+ 10. **Cross-component gate tracing** (conditional — trigger: PR touches both a router file that injects a field into a job payload AND a worker file that reads that field at execution time):
68
+ When a worker-layer review identifies that a resource field (API key, credential, config value) is resolved at use-time from a job payload, the review MUST also trace to the API-layer gate condition that controls injection of that field. A gate can fail at the API layer for logic that executes at the worker layer — both components must be reviewed together.
69
+ - Find the API router that creates the job payload and injects the field. Read the condition that controls whether the field is populated.
70
+ - Verify the gate condition is semantically correct for ALL request fields that flow through it — not just the primary feature field.
71
+ - If the API gate fires before job enqueue and the worker gate fires after dequeue, a misconfigured API gate will silently reject valid requests before the worker ever sees them.
72
+
73
+ ```bash
74
+ # Find all sites where the key/credential field is injected into the job payload
75
+ # Adapt the grep pattern to the project's credential field names (from [DOMAIN_CONTEXT])
76
+ grep -rn "api_key\|credential\|resource_key\|config_key" \
77
+ $(git ls-files | grep -E "(router|route|api|endpoint)" | grep -E "\.(py|ts|js)$") | grep -v "^\s*#" | head -20
78
+
79
+ # Check the worker consumption site for the same field
80
+ grep -rn "api_key\|credential\|resource_key\|config_key" \
81
+ $(git ls-files | grep -E "(worker|job|task|handler)" | grep -E "\.(py|ts|js)$") | grep -v "^\s*#" | head -20
82
+ ```
83
+ <!-- Added: forge#382 -->
84
+
85
+ ```bash
86
+ # Find all detection-related string constants
87
+ WORKER_FILES=$(git ls-files | grep -E "(worker|consumer|browser|detection)" | grep -E "\.(py|ts|js)$")
88
+ grep -rn "^[A-Z_]* = frozenset\(\|^[A-Z_]* = tuple(\|^[A-Z_]* = \[" $WORKER_FILES 2>/dev/null
89
+
90
+ # For each modified set, check if its entries appear in sibling detection files
91
+ for f in [CHANGED_ANTI_DETECTION_FILES]; do
92
+ grep -oE "'[a-z_][a-z0-9_-]{3,}'" "$f" | tr -d "'" | sort -u | while read entry; do
93
+ grep -rl "'$entry'\|\"$entry\"" $WORKER_FILES | grep -v "^$f$" | grep -E '\.(py|ts|js)$' || \
94
+ echo "SCRP: '$entry' in $f not found in any sibling worker file — verify if cross-module sync needed"
95
+ done
96
+ # Check comment vs set drift
97
+ grep -oE "#.*\`_?[a-z][a-z0-9_-]+\`" "$f" | grep -oE "\`[^']+\`" | tr -d '`' | while read ref; do
98
+ grep -q "'$ref'\|\"$ref\"" "$f" || \
99
+ echo "SCRP: '$ref' mentioned in comment in $f but absent from string sets — possible typo or omission (HIGH)"
100
+ done
101
+ done
102
+ ```
103
+
104
+ ## Cross-Service Consistency
105
+ - API-side: Job creation, initial tier selection
106
+ - Worker-side: Actual execution, tier escalation, result handling
107
+ - Verify consistency between services
108
+
109
+ ## Post Findings
110
+ ```bash
111
+ gh pr comment [PR_NUMBER] --body "$(cat <<'EOF'
112
+ ## Domain Logic Audit
113
+
114
+ ### Components Affected: [list the specific service/worker/api components touched — e.g. job-queue/rate-limiter/validation/gate-semantics/cross-component-gate]
115
+
116
+ ### Tier Flow Analysis
117
+ [Trace the tier selection and escalation with file:line references]
118
+
119
+ ### Detection Keyword Consistency
120
+ [If any detection set was modified: table of sibling sets checked, entries present/absent in each, comment/code drift found]
121
+ | Set Name | File | Entries | Missing from Sibling? | Comment Drift? |
122
+ |----------|------|---------|----------------------|----------------|
123
+ | CHALLENGE_KEYWORDS | file:line | N entries | [list missing] | [yes/no] |
124
+
125
+ ### Capacity Constants
126
+ [If any capacity constants were added or modified: list each constant, its value, whether a measurement source was cited, and any contradicting git history]
127
+ | Constant | Value | Measurement Source Cited? | Git History Finding |
128
+ |----------|-------|--------------------------|---------------------|
129
+ | [CONSTANT_NAME] | [value] | Yes/No | [any prior measured values from git log] |
130
+
131
+ ### API Gate Semantic Correctness
132
+ [If any router file gates request fields behind a new condition: for each field in the condition, state whether it requires the gated resource and whether the pre-existing behavior is preserved. "N/A — no gate condition changes in diff" is acceptable if no gate conditions changed.]
133
+
134
+ ### Cross-Component Gate Tracing
135
+ [If worker layer injects or reads a resource field from the job payload: state the API-layer gate condition that controls injection, the fields it gates, and whether each field genuinely requires the gated resource. "N/A — no cross-component key/gate flow in diff" is acceptable if not triggered.]
136
+
137
+ ### Findings
138
+ | Category | Issue | Location | Confidence |
139
+ |----------|-------|----------|------------|
140
+ | Tier logic | [issue] | file:line | CONFIRMED |
141
+ | Detection keywords | [issue] | file:line | CONFIRMED |
142
+ | Capacity constant | [issue] | file:line | POSSIBLE |
143
+ | API gate semantics | [issue] | file:line | CONFIRMED |
144
+ | Cross-component gate | [issue] | file:line | CONFIRMED |
145
+
146
+ ### Cross-Service Consistency
147
+ [If changes span services, verify they're consistent]
148
+
149
+ ### Files Reviewed
150
+ [List files checked]
151
+
152
+ ---
153
+ *Domain logic audit*
154
+
155
+ <!-- REVIEW-FINDINGS-START -->
156
+ <!-- FINDING:SCRP-1|CONFIDENCE|SEVERITY|file.py:line|Summary -->
157
+ <!-- (add one FINDING line per issue found — include ALL confidence levels) -->
158
+ <!-- REVIEW-FINDINGS-END -->
159
+ EOF
160
+ )"
161
+ ```
162
+
163
+ **Structured Findings**: Include the structured findings block above at the end of your comment. Your prefix: `SCRP`. See the Structured Findings Protocol section above for format rules.
164
+ ```
165
+
166
+ ### Coverage Matrix — SCRP Agent
167
+
168
+ | Defect Category | Check Item(s) | Status | Ref |
169
+ |----------------|---------------|--------|-----|
170
+ | Tier selection correctness | Item 1 | COVERED | |
171
+ | Tier-billing alignment | Item 2 | COVERED | |
172
+ | Timeout configuration per tier | Item 3 | COVERED | |
173
+ | Error propagation on scrape failure | Item 4 | COVERED | |
174
+ | Playbook authority logic | Item 5 | COVERED | |
175
+ | Content validation / escalation trigger | Item 6 | COVERED | |
176
+ | Detection keyword cross-set consistency | Item 7 | COVERED | |
177
+ | Capacity constant measurement verification | Item 8 | COVERED | |
178
+ | Cross-service consistency — tier logic (API vs Worker) | Cross-Service section | COVERED | |
179
+ | API gate semantic correctness per parameter | Item 9 | COVERED | forge#382 |
180
+ | Cross-component gate tracing (API gate ↔ worker injection) | Item 10 | COVERED | forge#382 |
181
+ | Playwright resource cleanup on failure | — | GAP | |
182
+ | Domain playbook override conflicts | — | GAP | |
183
+
184
+ ---
185
+