@webpieces/rules-config 0.4.472 → 0.4.474
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/package.json +1 -1
- package/src/checklist-config.d.ts +7 -21
- package/src/checklist-config.js +21 -45
- package/src/checklist-config.js.map +1 -1
- package/src/checklist-docs-validator.d.ts +5 -6
- package/src/checklist-docs-validator.js +7 -8
- package/src/checklist-docs-validator.js.map +1 -1
- package/src/checklist-manifest.d.ts +17 -0
- package/src/checklist-manifest.js +120 -0
- package/src/checklist-manifest.js.map +1 -0
- package/src/index.d.ts +5 -4
- package/src/index.js +8 -10
- package/src/index.js.map +1 -1
- package/src/pr-gate-config.d.ts +2 -3
- package/src/pr-gate-config.js +10 -11
- package/src/pr-gate-config.js.map +1 -1
- package/src/review-json.d.ts +16 -24
- package/src/review-json.js +94 -134
- package/src/review-json.js.map +1 -1
- package/src/subagent-provenance.d.ts +2 -0
- package/src/subagent-provenance.js +41 -8
- package/src/subagent-provenance.js.map +1 -1
- package/src/validate-config.d.ts +1 -1
- package/src/validate-config.js +21 -77
- package/src/validate-config.js.map +1 -1
- package/templates/webpieces.review-checklists.md +65 -0
package/src/review-json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-json.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/review-json.ts"],"names":[],"mappings":";;;AA+YA,4BAEC;AAGD,wCAEC;AAGD,oDAEC;AAGD,wCAEC;;AAhaD,+CAAyB;AACzB,mDAA6B;AAC7B,yCAA2D;AAC3D,2CAA+D;AAC/D,yDAAqD;AACrD,uDAAkD;AAClD,yCAAqC;AAErC,sGAAsG;AACtG,wGAAwG;AACxG,MAAa,YAAY;IACrB,EAAE,CAAS;IACX,YAAY,CAAU;IACtB,KAAK,CAAW,CAAC,oEAAoE;IAErF,YAAY,EAAU,EAAE,YAAqB,EAAE,KAAe;QAC1D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC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Aa,CAAC,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAClE,CAAC;AAED,wIAAwI;AACxI,SAAgB,cAAc,CAAC,QAAgB,EAAE,WAAyC,EAAE;IACxF,OAAO,aAAa,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { WEBPIECES_TMP_DIR, PR_REVIEW_DIR } from './constants';\nimport { CHECKLIST_BLOCK } from './checklist-config';\nimport { InformAiError } from './inform-ai-error';\nimport { toError } from './to-error';\n\n// One entry the AI writes into review.json's `checklists[]`: \"I read the doc for <id> and walked it\".\n// acknowledged: true is the AI attesting it did the walk — a SURFACING/AUDIT signal, not authorization.\nexport class ChecklistAck {\n id: string;\n acknowledged: boolean;\n notes: string[]; // per-item findings the AI chose to record (optional; [] when none)\n\n constructor(id: string, acknowledged: boolean, notes: string[]) {\n this.id = id;\n this.acknowledged = acknowledged;\n this.notes = notes;\n }\n}\n\n// The verdict a reviewer wrote into a PER-CHECKLIST file `.webpieces/pr-review/<branch>/review-<id>.json`,\n// one per triggered checklist. Replaces the single shared `checklists[]` array so concurrent reviewer\n// subagents never clobber one file. Unlike ChecklistAck's bare boolean, this records the OUTCOME:\n// success:true → PASS\n// success:false + override non-empty → OVERRIDDEN (pass; the free-text justification reaches the PR)\n// success:false + no override → FAIL (refuse; `output` is printed verbatim)\n// `override` is deliberately free text, not a boolean — it forces the bypass to be stated in words and\n// surfaces it on the dashboard, where a human sees it. Data-only (per CLAUDE.md).\nexport class ChecklistResult {\n id: string;\n success: boolean;\n output: string; // what the reviewer found; printed verbatim when a BLOCK checklist fails\n override: string; // '' = no override; non-empty = ship-anyway justification (renders 🟡 overridden)\n\n constructor(id: string, success: boolean, output: string, override: string) {\n this.id = id;\n this.success = success;\n this.output = output;\n this.override = override;\n }\n}\n\n// What the CALLER (the pr-gate command) computed from the diff: the checklists this branch triggered.\n// Drives BOTH review.json validation (BLOCK must be acknowledged) AND the printed schema hint (so the\n// AI is told, at the moment it writes review.json, exactly which docs to read). Data-only.\nexport class RequiredChecklist {\n id: string;\n title: string;\n severity: string; // 'BLOCK' | 'WARN'\n docs: string[];\n blockMessage: string;\n matchedFiles: string[]; // the changed files that triggered it (for the dashboard + hint)\n subagent: string; // expected reviewer agentType ('' = no provenance requirement); enforced by finish\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(id: string, title: string, severity: string, docs: string[], blockMessage: string, matchedFiles: string[], subagent = '') {\n this.id = id;\n this.title = title;\n this.severity = severity;\n this.docs = docs;\n this.blockMessage = blockMessage;\n this.matchedFiles = matchedFiles;\n this.subagent = subagent;\n }\n}\n\n// The AI-authored review for a PR. The AI writes this file itself between `wp-start-upsert-pr` (which\n// prints the schema) and `wp-finish-upsert-pr` (which reads it). Data-only (per CLAUDE.md).\nexport class ReviewJson {\n title: string; // human PR title describing the change; used as the `gh pr` title (empty → caller falls back)\n riskScore: number; // 0–100, drives the risk bar\n riskLevel: string; // 'green' | 'yellow' | 'red'\n riskEmoji: string; // '🟢' | '🟡' | '🔴' — derived from riskLevel when omitted\n summary: string; // rendered in the dashboard Summary section\n violations: string[]; // pattern/architecture violations; length = the Pattern Violations count\n risks: string[];\n filesToReview: string[];\n checklists: ChecklistAck[]; // legacy inline acknowledgments (back-compat); [] when none written\n results: ChecklistResult[]; // resolved per-checklist verdicts (from review-<id>.json); [] when none\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n title: string,\n riskScore: number,\n riskLevel: string,\n riskEmoji: string,\n summary: string,\n violations: string[],\n risks: string[],\n filesToReview: string[],\n checklists: ChecklistAck[] = [],\n results: ChecklistResult[] = [],\n ) {\n this.title = title;\n this.riskScore = riskScore;\n this.riskLevel = riskLevel;\n this.riskEmoji = riskEmoji;\n this.summary = summary;\n this.violations = violations;\n this.risks = risks;\n this.filesToReview = filesToReview;\n this.checklists = checklists;\n this.results = results;\n }\n}\n\n// A checklist's resolved outcome, shared by review.json enforcement and the dashboard so both agree.\nexport const CK_PASS = 'pass'; // review-<id>.json success:true\nexport const CK_OVERRIDDEN = 'overridden'; // review-<id>.json success:false + non-empty override → 🟡\nexport const CK_FAIL = 'fail'; // review-<id>.json success:false + no override → refuse\nexport const CK_MISSING = 'missing'; // no verdict file and no inline ack → refuse (BLOCK)\nexport const CK_ACKED = 'acknowledged'; // legacy inline checklists[] ack satisfied (back-compat)\n\nexport class ChecklistVerdict {\n id: string;\n status: string; // one of CK_PASS | CK_OVERRIDDEN | CK_FAIL | CK_MISSING | CK_ACKED\n detail: string; // reviewer output / override justification / ack notes (for the dashboard + errors)\n\n constructor(id: string, status: string, detail: string) {\n this.id = id;\n this.status = status;\n this.detail = detail;\n }\n}\n\nconst RISK_LEVELS = ['green', 'yellow', 'red'] as const;\nconst EMOJI_FOR_LEVEL: Record<string, string> = { green: '🟢', yellow: '🟡', red: '🔴' };\n\n/** Locates + loads/validates the AI-authored review.json. `@injectable(bindingScopeValues.Singleton)` so it's drawn in the design. */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewJsonService {\n // The per-feature PR working dir: `.webpieces/pr-review/<feature>`.\n prDirFor(repoRoot: string, featureName: string): string {\n return path.join(repoRoot, WEBPIECES_TMP_DIR, PR_REVIEW_DIR, featureName);\n }\n\n // Absolute path of the review.json for a feature — beside pr-body.md, keyed by branch name.\n reviewJsonPath(repoRoot: string, featureName: string): string {\n return path.join(this.prDirFor(repoRoot, featureName), 'review.json');\n }\n\n // Copy-paste schema both commands print (write it / fix it). `required` is the set of consumer\n // checklists the diff triggered; when it is empty the output is byte-identical to before this\n // feature existed (non-adopting repos see no change). When non-empty it grows a `checklists` line\n // in the JSON shape PLUS an instruction block naming the docs to read — diff-derived instructions\n // injected at exactly the moment the AI writes review.json.\n reviewJsonSchemaHint(filePath: string, required: readonly RequiredChecklist[] = []): string {\n return (\n `Write your PR review to:\\n ${filePath}\\n\\n` +\n `with this exact JSON shape (riskEmoji optional — derived from riskLevel):\\n\\n` +\n `{\\n` +\n ` \"title\": \"concise PR title describing the change (imperative, no branch names)\",\\n` +\n ` \"riskScore\": 0, // integer 0–100 (higher = riskier)\\n` +\n ` \"riskLevel\": \"green | yellow | red\",\\n` +\n ` \"summary\": \"5–10 sentence review summary\",\\n` +\n ` \"violations\": [\"pattern/architecture violations you found (empty array if none)\"],\\n` +\n ` \"risks\": [\"notable risks (empty array if none)\"],\\n` +\n ` \"filesToReview\": [\"paths a human should look at (empty array if none)\"]\\n` +\n `}` +\n this.requiredChecklistHint(filePath, required)\n );\n }\n\n // The per-checklist review file path that sits beside review.json: review-<id>.json.\n checklistResultPath(reviewJsonFilePath: string, checklistId: string): string {\n return path.join(path.dirname(reviewJsonFilePath), `review-${checklistId}.json`);\n }\n\n // The diff-triggered instruction block, appended ONLY when the branch triggered a checklist. This is\n // the consumer's review process, re-injected: read doc Y because the diff touched X, then write ONE\n // file per checklist — `review-<id>.json` — so concurrent reviewer subagents never clobber a shared\n // file. A BLOCK checklist with success:false and no override refuses to open the PR.\n private requiredChecklistHint(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): string {\n if (required.length === 0) return '';\n const lines: string[] = ['', '', 'This branch triggered company review checklist(s). For EACH one below: READ its docs, walk'];\n lines.push('the items against your diff, then write a SEPARATE file `review-<id>.json` beside review.json');\n lines.push('with this shape (override optional — a free-text ship-anyway justification):');\n lines.push('');\n lines.push(' { \"success\": true, \"output\": \"what you checked / what you found\", \"override\": \"\" }');\n lines.push('');\n for (const req of required) {\n const gate = req.severity === CHECKLIST_BLOCK\n ? 'BLOCK — success:false with no \"override\" will NOT open the PR'\n : 'WARN — recorded on the dashboard; never blocks';\n lines.push(` • [${req.id}] ${req.title} (${gate})`);\n lines.push(` write: ${this.checklistResultPath(reviewJsonFilePath, req.id)}`);\n lines.push(` docs to read: ${req.docs.join(', ')}`);\n if (req.subagent.trim() !== '') lines.push(` must be reviewed by the \"${req.subagent.trim()}\" subagent (its independent run is verified from the harness).`);\n if (req.blockMessage.trim() !== '') lines.push(` ${req.blockMessage.trim()}`);\n if (req.matchedFiles.length > 0) lines.push(` triggered by: ${req.matchedFiles.slice(0, 5).join(', ')}`);\n }\n return lines.join('\\n');\n }\n\n /**\n * Load + validate the AI-authored review.json. Throws InformAiError (with the schema) when missing,\n * unparseable, or structurally wrong. Returns a fully-populated ReviewJson on success.\n *\n * `required` is the set of consumer checklists the diff triggered (empty for non-adopting repos, in\n * which case this behaves byte-identically to before the feature). Every BLOCK entry must appear in\n * review.json's `checklists[]` with `acknowledged: true`, or a validation error is raised alongside\n * the usual ones so the AI gets ONE message. WARN entries are never validated; unknown ids in\n * `checklists[]` are ignored (forward-compat).\n */\n // webpieces-disable max-lines-new-methods -- one cohesive load+validate pass over the review fields\n loadReviewJson(filePath: string, required: readonly RequiredChecklist[] = []): ReviewJson {\n if (!fs.existsSync(filePath)) {\n throw new InformAiError(\n `Required review.json not found.\\n\\n${this.reviewJsonSchemaHint(filePath, required)}\\n\\n` +\n `Then re-run: pnpm wp-finish-upsert-pr`,\n );\n }\n\n const raw = this.parseReviewJson(fs.readFileSync(filePath, 'utf8'), filePath, required);\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw new InformAiError(`review.json must be a JSON object.\\n\\n${this.reviewJsonSchemaHint(filePath, required)}`);\n }\n\n const errors: string[] = [];\n\n const riskScore = raw['riskScore'];\n if (typeof riskScore !== 'number' || !Number.isFinite(riskScore) || riskScore < 0 || riskScore > 100) {\n errors.push(`\"riskScore\" must be a number 0–100, got ${JSON.stringify(riskScore)}.`);\n }\n\n const riskLevel = raw['riskLevel'];\n if (typeof riskLevel !== 'string' || !RISK_LEVELS.includes(riskLevel as typeof RISK_LEVELS[number])) {\n errors.push(`\"riskLevel\" must be one of: ${RISK_LEVELS.join(', ')}.`);\n }\n\n const title = typeof raw['title'] === 'string' ? (raw['title'] as string).trim() : '';\n if (title === '') {\n errors.push('\"title\" must be a non-empty, imperative PR title describing the change (no branch names).');\n }\n\n const acks = this.parseChecklistAcks(raw['checklists']);\n const results = this.loadChecklistResults(filePath, required);\n for (const err of this.requiredChecklistErrors(required, acks, results)) errors.push(err);\n\n if (errors.length > 0) {\n throw new InformAiError(\n `review.json has ${errors.length} error(s) — fix ALL, then re-run pnpm wp-finish-upsert-pr:\\n\\n` +\n errors.map((e: string): string => ` • ${e}`).join('\\n') +\n `\\n\\n${this.reviewJsonSchemaHint(filePath, required)}`,\n );\n }\n\n const level = riskLevel as string;\n const emoji = typeof raw['riskEmoji'] === 'string' && raw['riskEmoji'] !== ''\n ? (raw['riskEmoji'] as string)\n : (EMOJI_FOR_LEVEL[level] ?? '🟡');\n const summary = typeof raw['summary'] === 'string' ? (raw['summary'] as string) : '';\n\n return new ReviewJson(\n title,\n riskScore as number,\n level,\n emoji,\n summary,\n this.asStringArray(raw['violations']),\n this.asStringArray(raw['risks']),\n this.asStringArray(raw['filesToReview']),\n acks,\n results,\n );\n }\n\n // Parse the AI-authored `checklists[]` into typed ChecklistAck[]. Tolerant of a missing/garbage\n // field (→ []) and of non-object entries (skipped) — malformed acks simply fail to satisfy a BLOCK\n // requirement rather than crashing the load.\n // webpieces-disable no-any-unknown -- opaque parsed JSON value, narrowed here\n private parseChecklistAcks(value: unknown): ChecklistAck[] {\n if (!Array.isArray(value)) return [];\n const acks: ChecklistAck[] = [];\n for (const entry of value) {\n if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) continue;\n // webpieces-disable no-any-unknown -- one opaque ack entry, narrowed field-by-field\n const e = entry as Record<string, unknown>;\n const id = typeof e['id'] === 'string' ? (e['id'] as string) : '';\n if (id === '') continue;\n acks.push(new ChecklistAck(id, e['acknowledged'] === true, this.asStringArray(e['notes'])));\n }\n return acks;\n }\n\n // Read the per-checklist verdict files `review-<id>.json` that sit beside review.json — one per\n // triggered checklist. Tolerant like parseChecklistAcks: a missing file is simply absent from the\n // result (→ falls back to the inline ack / counts as unmet for a BLOCK), and a malformed one is\n // skipped (an unknown/stale review-<id>.json never wedges the branch).\n loadChecklistResults(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): ChecklistResult[] {\n const results: ChecklistResult[] = [];\n for (const req of required) {\n const p = this.checklistResultPath(reviewJsonFilePath, req.id);\n if (!fs.existsSync(p)) continue;\n const parsed = this.parseChecklistResult(p, req.id);\n if (parsed) results.push(parsed);\n }\n return results;\n }\n\n // Resolve ONE checklist's verdict from its per-file result (preferred) or its legacy inline ack.\n // Central so review.json enforcement AND the finish-command dashboard agree on the outcome.\n resolveVerdict(req: RequiredChecklist, acks: readonly ChecklistAck[], results: readonly ChecklistResult[]): ChecklistVerdict {\n const result = results.find((r: ChecklistResult): boolean => r.id === req.id);\n if (result) {\n if (result.success) return new ChecklistVerdict(req.id, CK_PASS, result.output);\n if (result.override.trim() !== '') return new ChecklistVerdict(req.id, CK_OVERRIDDEN, result.override.trim());\n return new ChecklistVerdict(req.id, CK_FAIL, result.output);\n }\n const ack = acks.find((a: ChecklistAck): boolean => a.id === req.id);\n if (ack && ack.acknowledged) return new ChecklistVerdict(req.id, CK_ACKED, ack.notes.join('; '));\n return new ChecklistVerdict(req.id, CK_MISSING, '');\n }\n\n // BLOCK requirements whose verdict is FAIL (reviewed, found a problem, no override) or MISSING (no\n // verdict written at all) → one error each. WARN never blocks. Uses the consumer's blockMessage /\n // the reviewer's `output` verbatim so the consumer owns the wording and webpieces owns the mechanism.\n private requiredChecklistErrors(required: readonly RequiredChecklist[], acks: readonly ChecklistAck[], results: readonly ChecklistResult[]): string[] {\n const errors: string[] = [];\n for (const req of required) {\n if (req.severity !== CHECKLIST_BLOCK) continue;\n const verdict = this.resolveVerdict(req, acks, results);\n if (verdict.status === CK_FAIL) {\n const msg = req.blockMessage.trim() !== '' ? `${req.blockMessage.trim()} ` : '';\n errors.push(\n `Checklist \"${req.id}\" (${req.title}) FAILED review. ${msg}` +\n `The reviewer wrote:\\n ${verdict.detail.split('\\n').join('\\n ')}\\n` +\n ` Fix it, then re-run; or set a non-empty \"override\" in ${this.checklistFileName(req.id)} to ship anyway with a stated justification.`,\n );\n } else if (verdict.status === CK_MISSING) {\n const docs = req.docs.length > 0 ? ` Read: ${req.docs.join(', ')}.` : '';\n const msg = req.blockMessage.trim() !== '' ? `${req.blockMessage.trim()} ` : '';\n errors.push(\n `Checklist \"${req.id}\" (${req.title}) is REQUIRED for this diff but has no verdict. ${msg}` +\n `Write ${this.checklistFileName(req.id)} with {\"success\":true,\"output\":\"…\"} once you have walked it.${docs}`,\n );\n }\n }\n return errors;\n }\n\n private checklistFileName(checklistId: string): string {\n return `review-${checklistId}.json`;\n }\n\n // Parse one review-<id>.json into a ChecklistResult, or null when malformed. Tolerant: missing\n // `success` counts as false (fail-closed), `output`/`override` default to ''.\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field\n private parseChecklistResult(filePath: string, id: string): ChecklistResult | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a malformed per-checklist file is skipped, not fatal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed below\n const raw = JSON.parse(fs.readFileSync(filePath, 'utf8')) as Record<string, unknown>;\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return null;\n const success = raw['success'] === true;\n const output = typeof raw['output'] === 'string' ? (raw['output'] as string) : '';\n const override = typeof raw['override'] === 'string' ? (raw['override'] as string) : '';\n return new ChecklistResult(id, success, output, override);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- opaque parsed JSON value, narrowed to string[] here\n private asStringArray(value: unknown): string[] {\n if (!Array.isArray(value)) return [];\n // webpieces-disable no-any-unknown -- element of an opaque JSON array, narrowed by the type guard\n return value.filter((v: unknown): v is string => typeof v === 'string');\n }\n\n // Parse opaque AI-authored JSON, converting a SyntaxError into a readable InformAiError. `required`\n // is threaded through so a JSON syntax error still prints the checklist instructions the AI needs —\n // exactly when it most needs them — rather than the bare schema.\n // webpieces-disable no-any-unknown -- returns the opaque parsed object; loadReviewJson narrows each field\n private parseReviewJson(raw: string, filePath: string, required: readonly RequiredChecklist[]): Record<string, unknown> {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: convert JSON.parse SyntaxError to an InformAiError for the AI\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed by the caller\n return JSON.parse(raw) as Record<string, unknown>;\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `review.json is not valid JSON (${error.message}).\\n\\n${this.reviewJsonSchemaHint(filePath, required)}\\n\\n` +\n `Then re-run: pnpm wp-finish-upsert-pr`,\n );\n }\n }\n}\n\n// Temporary migration delegators to ReviewJsonService — removed once consumers inject it.\nconst reviewJsonSvc = new ReviewJsonService();\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function prDirFor(repoRoot: string, featureName: string): string {\n return reviewJsonSvc.prDirFor(repoRoot, featureName);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function reviewJsonPath(repoRoot: string, featureName: string): string {\n return reviewJsonSvc.reviewJsonPath(repoRoot, featureName);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function reviewJsonSchemaHint(filePath: string, required: readonly RequiredChecklist[] = []): string {\n return reviewJsonSvc.reviewJsonSchemaHint(filePath, required);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function loadReviewJson(filePath: string, required: readonly RequiredChecklist[] = []): ReviewJson {\n return reviewJsonSvc.loadReviewJson(filePath, required);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"review-json.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/review-json.ts"],"names":[],"mappings":";;;AA2WA,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* as path from 'path';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { WEBPIECES_TMP_DIR, PR_REVIEW_DIR } from './constants';\nimport { InformAiError } from './inform-ai-error';\nimport { toError } from './to-error';\n\n// The verdict a reviewer SUBAGENT writes into `.webpieces/pr-review/<branch>/review-<id>.json`, one per\n// matched checklist. One file per checklist so N concurrent reviewer subagents never clobber a shared\n// file. It records the OUTCOME:\n// success:true → PASS\n// success:false + override non-empty → OVERRIDDEN (pass; the free-text justification reaches the PR)\n// success:false + no override → FAIL (refuse; `output` is printed verbatim)\n// `override` is deliberately free text, not a boolean — it forces the ship-anyway decision to be stated\n// in words and surfaces it on the dashboard, where a human sees it. Data-only (per CLAUDE.md).\nexport class ChecklistResult {\n id: string;\n success: boolean;\n output: string; // what the reviewer found; printed verbatim when the checklist fails\n override: string; // '' = no override; non-empty = ship-anyway justification (renders 🟡 overridden)\n\n constructor(id: string, success: boolean, output: string, override: string) {\n this.id = id;\n this.success = success;\n this.output = output;\n this.override = override;\n }\n}\n\n// What the pr-gate command computed from the diff: a checklist this branch MATCHED (its patterns hit the\n// diff, so its reviewer subagent must run). Drives review-<id>.json enforcement, provenance, the schema\n// hint, and the dashboard. Data-only.\nexport class RequiredChecklist {\n id: string; // = subagent name; keys review-<id>.json\n subagent: string; // reviewer agent that must run (agentType the harness stamps)\n doc: string; // guidance doc the reviewer reads ('' → it reads the manifest doc)\n matchedFiles: string[]; // the changed files that matched it (for the dashboard + hint)\n\n constructor(id: string, subagent: string, doc: string, matchedFiles: string[]) {\n this.id = id;\n this.subagent = subagent;\n this.doc = doc;\n this.matchedFiles = matchedFiles;\n }\n}\n\n// The AI-authored review for a PR. The AI writes review.json itself between `wp-start-upsert-pr` (which\n// prints the schema) and `wp-finish-upsert-pr` (which reads it); reviewer subagents write the per-checklist\n// review-<id>.json files. Data-only (per CLAUDE.md).\nexport class ReviewJson {\n title: string; // human PR title describing the change; used as the `gh pr` title (empty → caller falls back)\n riskScore: number; // 0–100, drives the risk bar\n riskLevel: string; // 'green' | 'yellow' | 'red'\n riskEmoji: string; // '🟢' | '🟡' | '🔴' — derived from riskLevel when omitted\n summary: string; // rendered in the dashboard Summary section\n violations: string[]; // pattern/architecture violations; length = the Pattern Violations count\n risks: string[];\n filesToReview: string[];\n results: ChecklistResult[]; // resolved per-checklist verdicts (from review-<id>.json); [] when none\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n title: string,\n riskScore: number,\n riskLevel: string,\n riskEmoji: string,\n summary: string,\n violations: string[],\n risks: string[],\n filesToReview: string[],\n results: ChecklistResult[] = [],\n ) {\n this.title = title;\n this.riskScore = riskScore;\n this.riskLevel = riskLevel;\n this.riskEmoji = riskEmoji;\n this.summary = summary;\n this.violations = violations;\n this.risks = risks;\n this.filesToReview = filesToReview;\n this.results = results;\n }\n}\n\n// A checklist's resolved outcome, shared by review.json enforcement and the dashboard so both agree.\nexport const CK_PASS = 'pass'; // review-<id>.json success:true\nexport const CK_OVERRIDDEN = 'overridden'; // review-<id>.json success:false + non-empty override → 🟡\nexport const CK_FAIL = 'fail'; // review-<id>.json success:false + no override → refuse\nexport const CK_MISSING = 'missing'; // no review-<id>.json written → refuse\n\nexport class ChecklistVerdict {\n id: string;\n status: string; // one of CK_PASS | CK_OVERRIDDEN | CK_FAIL | CK_MISSING\n detail: string; // reviewer output / override justification (for the dashboard + errors)\n\n constructor(id: string, status: string, detail: string) {\n this.id = id;\n this.status = status;\n this.detail = detail;\n }\n}\n\n// The PR's diff context, written by wp-start-upsert-pr into `.webpieces/pr-review/<branch>/pr-context.json`\n// so a reviewer subagent knows the exact 3-point base the gate used and the full changed-file set — then\n// reads any file's actual diff with `git diff <base> HEAD -- <file>`. This is what lets a checklist match\n// coarsely by path (in the manifest) while the subagent makes the fine, content-level judgment. Data-only.\nexport class PrContext {\n base: string; // the 3-point merge-base sha the gate diffs against\n head: string; // HEAD sha\n changedFiles: string[]; // every file changed base..head (NOT tsOnly — includes .sql/.gql/Dockerfile/…)\n\n constructor(base: string, head: string, changedFiles: string[]) {\n this.base = base;\n this.head = head;\n this.changedFiles = changedFiles;\n }\n}\n\nconst RISK_LEVELS = ['green', 'yellow', 'red'] as const;\nconst EMOJI_FOR_LEVEL: Record<string, string> = { green: '🟢', yellow: '🟡', red: '🔴' };\n\n/** Locates + loads/validates the AI-authored review.json. `@injectable(bindingScopeValues.Singleton)` so it's drawn in the design. */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewJsonService {\n // The per-feature PR working dir: `.webpieces/pr-review/<feature>`.\n prDirFor(repoRoot: string, featureName: string): string {\n return path.join(repoRoot, WEBPIECES_TMP_DIR, PR_REVIEW_DIR, featureName);\n }\n\n // Absolute path of the review.json for a feature — beside pr-body.md, keyed by branch name.\n reviewJsonPath(repoRoot: string, featureName: string): string {\n return path.join(this.prDirFor(repoRoot, featureName), 'review.json');\n }\n\n // Absolute path of the pr-context.json for a feature (the diff base/head + changed files).\n prContextPath(repoRoot: string, featureName: string): string {\n return path.join(this.prDirFor(repoRoot, featureName), 'pr-context.json');\n }\n\n // Persist the PR's diff context so reviewer subagents can read the changed-file set + the exact base\n // sha (then `git diff <base> HEAD -- <file>` for content). Returns the file path written.\n writePrContext(repoRoot: string, featureName: string, context: PrContext): string {\n const dir = this.prDirFor(repoRoot, featureName);\n fs.mkdirSync(dir, { recursive: true });\n const p = this.prContextPath(repoRoot, featureName);\n fs.writeFileSync(p, JSON.stringify(context, null, 2) + '\\n');\n return p;\n }\n\n // Copy-paste schema both commands print. `required` is the set of checklists the diff MATCHED; empty\n // ⇒ output identical to a repo with no checklists. Non-empty ⇒ appends per-checklist instructions\n // naming the reviewer subagent + doc + the review-<id>.json to write.\n reviewJsonSchemaHint(filePath: string, required: readonly RequiredChecklist[] = []): string {\n return (\n `Write your PR review to:\\n ${filePath}\\n\\n` +\n `with this exact JSON shape (riskEmoji optional — derived from riskLevel):\\n\\n` +\n `{\\n` +\n ` \"title\": \"concise PR title describing the change (imperative, no branch names)\",\\n` +\n ` \"riskScore\": 0, // integer 0–100 (higher = riskier)\\n` +\n ` \"riskLevel\": \"green | yellow | red\",\\n` +\n ` \"summary\": \"5–10 sentence review summary\",\\n` +\n ` \"violations\": [\"pattern/architecture violations you found (empty array if none)\"],\\n` +\n ` \"risks\": [\"notable risks (empty array if none)\"],\\n` +\n ` \"filesToReview\": [\"paths a human should look at (empty array if none)\"]\\n` +\n `}` +\n this.requiredChecklistHint(filePath, required)\n );\n }\n\n // The per-checklist review file path that sits beside review.json: review-<id>.json.\n checklistResultPath(reviewJsonFilePath: string, checklistId: string): string {\n return path.join(path.dirname(reviewJsonFilePath), `review-${checklistId}.json`);\n }\n\n // The matched-checklist instruction block, appended ONLY when the diff matched a checklist. Each matched\n // checklist must be reviewed by its OWN subagent (a distinct one), which writes review-<id>.json.\n private requiredChecklistHint(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): string {\n if (required.length === 0) return '';\n const lines: string[] = ['', '', 'This diff MATCHED company review checklist(s). Spawn EACH named subagent as a SEPARATE'];\n lines.push('subagent (a different one per checklist — the coding agent may NOT self-certify). Each reads its');\n lines.push('doc + the diff and writes its own review-<id>.json with this shape:');\n lines.push('');\n lines.push(' { \"id\": \"<id>\", \"success\": true, \"output\": \"what you checked / found\", \"override\": \"\" }');\n lines.push(' (success:false with no non-empty \"override\" refuses the PR; a non-empty override ships it 🟡.)');\n lines.push('');\n for (const req of required) {\n lines.push(` • [${req.id}] reviewer subagent: ${req.subagent}`);\n lines.push(` write: ${this.checklistResultPath(reviewJsonFilePath, req.id)}`);\n if (req.doc.trim() !== '') lines.push(` doc to read: ${req.doc}`);\n if (req.matchedFiles.length > 0) lines.push(` matched: ${req.matchedFiles.slice(0, 5).join(', ')}`);\n }\n return lines.join('\\n');\n }\n\n /**\n * Load + validate the AI-authored review.json. Throws InformAiError (with the schema) when missing,\n * unparseable, or structurally wrong. `required` is the set of checklists the diff matched: every one\n * must have a well-formed, passing (or overridden) review-<id>.json or a validation error is raised\n * alongside the usual ones so the AI gets ONE message.\n */\n // webpieces-disable max-lines-new-methods -- one cohesive load+validate pass over the review fields\n loadReviewJson(filePath: string, required: readonly RequiredChecklist[] = []): ReviewJson {\n if (!fs.existsSync(filePath)) {\n throw new InformAiError(\n `Required review.json not found.\\n\\n${this.reviewJsonSchemaHint(filePath, required)}\\n\\n` +\n `Then re-run: pnpm wp-finish-upsert-pr`,\n );\n }\n\n const raw = this.parseReviewJson(fs.readFileSync(filePath, 'utf8'), filePath, required);\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw new InformAiError(`review.json must be a JSON object.\\n\\n${this.reviewJsonSchemaHint(filePath, required)}`);\n }\n\n const errors: string[] = [];\n\n const riskScore = raw['riskScore'];\n if (typeof riskScore !== 'number' || !Number.isFinite(riskScore) || riskScore < 0 || riskScore > 100) {\n errors.push(`\"riskScore\" must be a number 0–100, got ${JSON.stringify(riskScore)}.`);\n }\n\n const riskLevel = raw['riskLevel'];\n if (typeof riskLevel !== 'string' || !RISK_LEVELS.includes(riskLevel as typeof RISK_LEVELS[number])) {\n errors.push(`\"riskLevel\" must be one of: ${RISK_LEVELS.join(', ')}.`);\n }\n\n const title = typeof raw['title'] === 'string' ? (raw['title'] as string).trim() : '';\n if (title === '') {\n errors.push('\"title\" must be a non-empty, imperative PR title describing the change (no branch names).');\n }\n\n const results = this.loadChecklistResults(filePath, required);\n for (const err of this.requiredChecklistErrors(required, results)) errors.push(err);\n\n if (errors.length > 0) {\n throw new InformAiError(\n `review.json has ${errors.length} error(s) — fix ALL, then re-run pnpm wp-finish-upsert-pr:\\n\\n` +\n errors.map((e: string): string => ` • ${e}`).join('\\n') +\n `\\n\\n${this.reviewJsonSchemaHint(filePath, required)}`,\n );\n }\n\n const level = riskLevel as string;\n const emoji = typeof raw['riskEmoji'] === 'string' && raw['riskEmoji'] !== ''\n ? (raw['riskEmoji'] as string)\n : (EMOJI_FOR_LEVEL[level] ?? '🟡');\n const summary = typeof raw['summary'] === 'string' ? (raw['summary'] as string) : '';\n\n return new ReviewJson(\n title,\n riskScore as number,\n level,\n emoji,\n summary,\n this.asStringArray(raw['violations']),\n this.asStringArray(raw['risks']),\n this.asStringArray(raw['filesToReview']),\n results,\n );\n }\n\n // Read the per-checklist verdict files `review-<id>.json` beside review.json — one per matched checklist.\n // A missing file is simply absent from the result (→ counts as MISSING for that checklist); a malformed\n // one is skipped (a stale review-<id>.json never wedges the branch).\n loadChecklistResults(reviewJsonFilePath: string, required: readonly RequiredChecklist[]): ChecklistResult[] {\n const results: ChecklistResult[] = [];\n for (const req of required) {\n const p = this.checklistResultPath(reviewJsonFilePath, req.id);\n if (!fs.existsSync(p)) continue;\n const parsed = this.parseChecklistResult(p, req.id);\n if (parsed) results.push(parsed);\n }\n return results;\n }\n\n // Resolve ONE checklist's verdict from its review-<id>.json. Central so review.json enforcement AND the\n // finish-command dashboard agree on the outcome.\n resolveVerdict(req: RequiredChecklist, results: readonly ChecklistResult[]): ChecklistVerdict {\n const result = results.find((r: ChecklistResult): boolean => r.id === req.id);\n if (!result) return new ChecklistVerdict(req.id, CK_MISSING, '');\n if (result.success) return new ChecklistVerdict(req.id, CK_PASS, result.output);\n if (result.override.trim() !== '') return new ChecklistVerdict(req.id, CK_OVERRIDDEN, result.override.trim());\n return new ChecklistVerdict(req.id, CK_FAIL, result.output);\n }\n\n // Every matched checklist whose verdict is FAIL (reviewed, found a problem, no override) or MISSING (no\n // review-<id>.json written) → one error each, printing the reviewer's `output` verbatim.\n private requiredChecklistErrors(required: readonly RequiredChecklist[], results: readonly ChecklistResult[]): string[] {\n const errors: string[] = [];\n for (const req of required) {\n const verdict = this.resolveVerdict(req, results);\n if (verdict.status === CK_FAIL) {\n errors.push(\n `Checklist \"${req.id}\" FAILED review. The reviewer (${req.subagent}) wrote:\\n ` +\n `${verdict.detail.split('\\n').join('\\n ')}\\n` +\n ` Fix it, then re-run; or set a non-empty \"override\" in ${this.checklistFileName(req.id)} to ship anyway with a stated justification.`,\n );\n } else if (verdict.status === CK_MISSING) {\n const doc = req.doc.trim() !== '' ? ` Read: ${req.doc}.` : '';\n errors.push(\n `Checklist \"${req.id}\" MATCHED this diff but has no verdict. Spawn the \"${req.subagent}\" subagent to review it, ` +\n `then write ${this.checklistFileName(req.id)} with {\"id\":\"${req.id}\",\"success\":true,\"output\":\"…\"}.${doc}`,\n );\n }\n }\n return errors;\n }\n\n private checklistFileName(checklistId: string): string {\n return `review-${checklistId}.json`;\n }\n\n // Parse one review-<id>.json into a ChecklistResult, or null when malformed. Tolerant: missing\n // `success` counts as false (fail-closed), `output`/`override` default to ''.\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field\n private parseChecklistResult(filePath: string, id: string): ChecklistResult | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a malformed per-checklist file is skipped, not fatal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed below\n const raw = JSON.parse(fs.readFileSync(filePath, 'utf8')) as Record<string, unknown>;\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return null;\n const success = raw['success'] === true;\n const output = typeof raw['output'] === 'string' ? (raw['output'] as string) : '';\n const override = typeof raw['override'] === 'string' ? (raw['override'] as string) : '';\n return new ChecklistResult(id, success, output, override);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- opaque parsed JSON value, narrowed to string[] here\n private asStringArray(value: unknown): string[] {\n if (!Array.isArray(value)) return [];\n // webpieces-disable no-any-unknown -- element of an opaque JSON array, narrowed by the type guard\n return value.filter((v: unknown): v is string => typeof v === 'string');\n }\n\n // Parse opaque AI-authored JSON, converting a SyntaxError into a readable InformAiError. `required`\n // is threaded through so a JSON syntax error still prints the checklist instructions the AI needs.\n // webpieces-disable no-any-unknown -- returns the opaque parsed object; loadReviewJson narrows each field\n private parseReviewJson(raw: string, filePath: string, required: readonly RequiredChecklist[]): Record<string, unknown> {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: convert JSON.parse SyntaxError to an InformAiError for the AI\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed by the caller\n return JSON.parse(raw) as Record<string, unknown>;\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(\n `review.json is not valid JSON (${error.message}).\\n\\n${this.reviewJsonSchemaHint(filePath, required)}\\n\\n` +\n `Then re-run: pnpm wp-finish-upsert-pr`,\n );\n }\n }\n}\n\n// Temporary migration delegators to ReviewJsonService — removed once consumers inject it.\nconst reviewJsonSvc = new ReviewJsonService();\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function prDirFor(repoRoot: string, featureName: string): string {\n return reviewJsonSvc.prDirFor(repoRoot, featureName);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function reviewJsonPath(repoRoot: string, featureName: string): string {\n return reviewJsonSvc.reviewJsonPath(repoRoot, featureName);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function reviewJsonSchemaHint(filePath: string, required: readonly RequiredChecklist[] = []): string {\n return reviewJsonSvc.reviewJsonSchemaHint(filePath, required);\n}\n\n// webpieces-disable no-function-outside-class -- temporary back-compat delegator to ReviewJsonService; removed once consumers inject it\nexport function loadReviewJson(filePath: string, required: readonly RequiredChecklist[] = []): ReviewJson {\n return reviewJsonSvc.loadReviewJson(filePath, required);\n}\n"]}
|
|
@@ -27,6 +27,8 @@ export declare class ProvenanceResult {
|
|
|
27
27
|
*/
|
|
28
28
|
export declare class SubagentProvenanceService {
|
|
29
29
|
verify(expectedAgentType: string, branch: string): ProvenanceResult;
|
|
30
|
+
verifyDistinct(expectedAgentTypes: readonly string[], branch: string): ProvenanceResult;
|
|
31
|
+
private findMatchingAgentId;
|
|
30
32
|
private findSubagentsDir;
|
|
31
33
|
private metaFiles;
|
|
32
34
|
private agentIdOf;
|
|
@@ -51,21 +51,54 @@ let SubagentProvenanceService = class SubagentProvenanceService {
|
|
|
51
51
|
if (dir === '') {
|
|
52
52
|
return new ProvenanceResult(exports.PROVENANCE_MISSING, `No subagents recorded for this session — the "${expectedAgentType}" reviewer subagent must run on this branch before the PR can open.`);
|
|
53
53
|
}
|
|
54
|
+
const agentId = this.findMatchingAgentId(dir, expectedAgentType, branch);
|
|
55
|
+
return agentId !== ''
|
|
56
|
+
? new ProvenanceResult(exports.PROVENANCE_OK, `verified "${expectedAgentType}" reviewer subagent ran (agent ${agentId}).`)
|
|
57
|
+
: new ProvenanceResult(exports.PROVENANCE_MISSING, `No "${expectedAgentType}" reviewer subagent ran on this branch — a separate reviewer of that type must review this checklist.`);
|
|
58
|
+
}
|
|
59
|
+
// Verify EVERY expected reviewer subagent ran on `branch` as a DISTINCT run — the coding agent may not
|
|
60
|
+
// self-certify, and one reviewer may not stand in for several. SKIPPED (pass) without a session id.
|
|
61
|
+
verifyDistinct(expectedAgentTypes, branch) {
|
|
62
|
+
if (expectedAgentTypes.length === 0)
|
|
63
|
+
return new ProvenanceResult(exports.PROVENANCE_OK, 'no reviewer subagents required');
|
|
64
|
+
const sessionId = process.env['CLAUDE_CODE_SESSION_ID'] ?? '';
|
|
65
|
+
if (sessionId.trim() === '') {
|
|
66
|
+
return new ProvenanceResult(exports.PROVENANCE_SKIPPED, `CLAUDE_CODE_SESSION_ID not set — cannot verify reviewer subagents ran (plain terminal / CI). Skipping the provenance check.`);
|
|
67
|
+
}
|
|
68
|
+
const dir = this.findSubagentsDir(sessionId);
|
|
69
|
+
if (dir === '') {
|
|
70
|
+
return new ProvenanceResult(exports.PROVENANCE_MISSING, `No subagents recorded for this session — each checklist must be reviewed by its own subagent: ${expectedAgentTypes.join(', ')}.`);
|
|
71
|
+
}
|
|
72
|
+
const missing = [];
|
|
73
|
+
const usedAgentIds = new Set();
|
|
74
|
+
for (const type of expectedAgentTypes) {
|
|
75
|
+
const agentId = this.findMatchingAgentId(dir, type, branch, usedAgentIds);
|
|
76
|
+
if (agentId === '')
|
|
77
|
+
missing.push(type);
|
|
78
|
+
else
|
|
79
|
+
usedAgentIds.add(agentId);
|
|
80
|
+
}
|
|
81
|
+
return missing.length === 0
|
|
82
|
+
? new ProvenanceResult(exports.PROVENANCE_OK, `verified ${expectedAgentTypes.length} distinct reviewer subagent(s) ran`)
|
|
83
|
+
: new ProvenanceResult(exports.PROVENANCE_MISSING, `these reviewer subagents did not run on this branch (spawn each as its OWN subagent — do not self-certify): ${missing.join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
// The agentId of a matching subagent run for `agentType` on `branch`, or '' if none. `exclude` skips
|
|
86
|
+
// agentIds already credited to another checklist so one run can't satisfy two.
|
|
87
|
+
findMatchingAgentId(dir, agentType, branch, exclude = new Set()) {
|
|
54
88
|
for (const metaFile of this.metaFiles(dir)) {
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
89
|
+
const agentId = this.agentIdOf(metaFile);
|
|
90
|
+
if (exclude.has(agentId))
|
|
57
91
|
continue;
|
|
58
|
-
|
|
92
|
+
const meta = this.readJson(path.join(dir, metaFile));
|
|
93
|
+
if (!meta || meta['agentType'] !== agentType)
|
|
59
94
|
continue;
|
|
60
95
|
const spawnDepth = meta['spawnDepth'];
|
|
61
96
|
if (typeof spawnDepth !== 'number' || spawnDepth < 1)
|
|
62
97
|
continue;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return new ProvenanceResult(exports.PROVENANCE_OK, `verified "${expectedAgentType}" reviewer subagent ran (agent ${agentId}).`);
|
|
66
|
-
}
|
|
98
|
+
if (this.sidechainOnBranch(dir, agentId, branch))
|
|
99
|
+
return agentId;
|
|
67
100
|
}
|
|
68
|
-
return
|
|
101
|
+
return '';
|
|
69
102
|
}
|
|
70
103
|
// Find the subagents dir for `sessionId` by its UNIQUE id, so the cwd-slug never has to be guessed.
|
|
71
104
|
findSubagentsDir(sessionId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent-provenance.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/subagent-provenance.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,+CAAyB;AACzB,yCAA2D;AAC3D,yCAAqC;AAErC,iCAAiC;AACpB,QAAA,aAAa,GAAG,IAAI,CAAC,CAAW,+DAA+D;AAC/F,QAAA,kBAAkB,GAAG,SAAS,CAAC,CAAC,0EAA0E;AAC1G,QAAA,kBAAkB,GAAG,SAAS,CAAC,CAAC,gEAAgE;AAE7G,MAAa,gBAAgB;IACzB,MAAM,CAAS,CAAC,0DAA0D;IAC1E,MAAM,CAAS,CAAC,6DAA6D;IAE7E,YAAY,MAAc,EAAE,MAAc;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AARD,4CAQC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AAEI,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAClC,iGAAiG;IACjG,yFAAyF;IACzF,MAAM,CAAC,iBAAyB,EAAE,MAAc;QAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,IAAI,EAAE,CAAC;QAC9D,IAAI,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC1B,OAAO,IAAI,gBAAgB,CAAC,0BAAkB,EAC1C,uDAAuD,iBAAiB,2EAA2E,CAAC,CAAC;QAC7J,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;YACb,OAAO,IAAI,gBAAgB,CAAC,0BAAkB,EAC1C,iDAAiD,iBAAiB,qEAAqE,CAAC,CAAC;QACjJ,CAAC;QACD,KAAK,MAAM,QAAQ,IAA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ChB,CAAC;IACL,CAAC;IAED,uFAAuF;IAC/E,SAAS,CAAC,IAAY;QAC1B,yFAAyF;QACzF,8DAA8D;QAC9D,IAAI,CAAC;YACD,yFAAyF;YACzF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAA4B,CAAC;QACvD,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CACJ,CAAA;AA5HY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,yBAAyB,CA4HrC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from 'os';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { toError } from './to-error';\n\n// Outcome of a provenance check.\nexport const PROVENANCE_OK = 'ok'; // a matching reviewer subagent demonstrably ran on this branch\nexport const PROVENANCE_MISSING = 'missing'; // session known, but no matching subagent artifact found → refuse (BLOCK)\nexport const PROVENANCE_SKIPPED = 'skipped'; // no CLAUDE_CODE_SESSION_ID (plain terminal / CI) → warn + pass\n\nexport class ProvenanceResult {\n status: string; // PROVENANCE_OK | PROVENANCE_MISSING | PROVENANCE_SKIPPED\n detail: string; // human-readable explanation for the warning/error/dashboard\n\n constructor(status: string, detail: string) {\n this.status = status;\n this.detail = detail;\n }\n}\n\n/**\n * Verifies — from the Claude Code harness's OWN artifacts, never from anything the model asserts — that\n * a subagent of a given `agentType` actually ran during the current session on the current branch. Used\n * to enforce a checklist's optional `subagent:` field: that an INDEPENDENT reviewer looked, rather than\n * the coding agent self-certifying.\n *\n * The harness writes, beside each subagent transcript:\n * ~/.claude/projects/<cwd-slug>/<sessionId>/subagents/agent-<id>.meta.json → { agentType, spawnDepth, … }\n * ~/.claude/projects/<cwd-slug>/<sessionId>/subagents/agent-<id>.jsonl → record 0 { isSidechain, gitBranch, … }\n * `agentType`/`spawnDepth`/`isSidechain` are written by Claude Code, not by the model. We locate the dir\n * by the unique sessionId (globbing `projects/*/<sessionId>/subagents`), so the cwd-slug never has to be\n * derived/guessed.\n *\n * IMPORTANT — this is NOT tamper-proof. A determined agent can `cat >` a fake agent-*.meta.json. This\n * raises the bar from \"trust the model's word\" to \"deliberate, auditable forgery outside the repo\"; it\n * is not cryptographic. Say so wherever `subagent:` is documented.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and injected by type.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class SubagentProvenanceService {\n // Verify a subagent of `expectedAgentType` ran on `branch`. Absent CLAUDE_CODE_SESSION_ID (plain\n // terminal / CI) returns SKIPPED — the feature must not break non-Claude-Code consumers.\n verify(expectedAgentType: string, branch: string): ProvenanceResult {\n const sessionId = process.env['CLAUDE_CODE_SESSION_ID'] ?? '';\n if (sessionId.trim() === '') {\n return new ProvenanceResult(PROVENANCE_SKIPPED,\n `CLAUDE_CODE_SESSION_ID not set — cannot verify the \"${expectedAgentType}\" reviewer subagent (plain terminal / CI). Skipping the provenance check.`);\n }\n const dir = this.findSubagentsDir(sessionId);\n if (dir === '') {\n return new ProvenanceResult(PROVENANCE_MISSING,\n `No subagents recorded for this session — the \"${expectedAgentType}\" reviewer subagent must run on this branch before the PR can open.`);\n }\n for (const metaFile of this.metaFiles(dir)) {\n const meta = this.readJson(path.join(dir, metaFile));\n if (!meta) continue;\n if (meta['agentType'] !== expectedAgentType) continue;\n const spawnDepth = meta['spawnDepth'];\n if (typeof spawnDepth !== 'number' || spawnDepth < 1) continue;\n const agentId = this.agentIdOf(metaFile);\n if (this.sidechainOnBranch(dir, agentId, branch)) {\n return new ProvenanceResult(PROVENANCE_OK,\n `verified \"${expectedAgentType}\" reviewer subagent ran (agent ${agentId}).`);\n }\n }\n return new ProvenanceResult(PROVENANCE_MISSING,\n `No \"${expectedAgentType}\" reviewer subagent ran on this branch — a separate reviewer of that type must review this checklist.`);\n }\n\n // Find the subagents dir for `sessionId` by its UNIQUE id, so the cwd-slug never has to be guessed.\n private findSubagentsDir(sessionId: string): string {\n const projects = path.join(os.homedir(), '.claude', 'projects');\n if (!fs.existsSync(projects)) return '';\n for (const proj of this.readDir(projects)) {\n const candidate = path.join(projects, proj, sessionId, 'subagents');\n if (fs.existsSync(candidate)) return candidate;\n }\n return '';\n }\n\n private metaFiles(dir: string): string[] {\n return this.readDir(dir).filter((f: string): boolean => f.endsWith('.meta.json'));\n }\n\n // agent-<id>.meta.json → <id>\n private agentIdOf(metaFile: string): string {\n return metaFile.replace(/^agent-/, '').replace(/\\.meta\\.json$/, '');\n }\n\n // Cross-check the sibling transcript's record 0: isSidechain true (a real subagent, not the main\n // loop) and, when recorded, the same branch. Lenient on branch drift (a leftover …wpN suffix from a\n // mid-flight branch rename) and on a missing jsonl (meta already matched — accept, best-effort).\n private sidechainOnBranch(dir: string, agentId: string, branch: string): boolean {\n const jsonl = path.join(dir, `agent-${agentId}.jsonl`);\n if (!fs.existsSync(jsonl)) return true;\n const first = this.firstNonEmptyLine(jsonl);\n if (first === '') return true;\n const rec = this.parseLine(first);\n if (!rec) return true;\n if (rec['isSidechain'] !== true) return false;\n const gitBranch = rec['gitBranch'];\n if (typeof gitBranch !== 'string' || gitBranch === '') return true;\n return this.stripWp(gitBranch) === this.stripWp(branch);\n }\n\n private stripWp(branch: string): string {\n return branch.replace(/-?wp\\d+$/i, '');\n }\n\n private readDir(dir: string): string[] {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable dir yields [] (best-effort provenance)\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.readdirSync(dir);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n }\n\n private firstNonEmptyLine(filePath: string): string {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unreadable transcript → '' (best-effort)\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n for (const line of fs.readFileSync(filePath, 'utf8').split('\\n')) {\n if (line.trim() !== '') return line;\n }\n return '';\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return '';\n }\n }\n\n // webpieces-disable no-any-unknown -- opaque parsed JSON object, keys read by the caller\n private readJson(filePath: string): Record<string, unknown> | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: malformed meta.json → null (skipped)\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed by the caller\n return JSON.parse(fs.readFileSync(filePath, 'utf8')) as Record<string, unknown>;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSONL record, keys read by the caller\n private parseLine(line: string): Record<string, unknown> | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: malformed JSONL record → null\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed by the caller\n return JSON.parse(line) as Record<string, unknown>;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"subagent-provenance.js","sourceRoot":"","sources":["../../../../../packages/tooling/rules-config/src/subagent-provenance.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,+CAAyB;AACzB,yCAA2D;AAC3D,yCAAqC;AAErC,iCAAiC;AACpB,QAAA,aAAa,GAAG,IAAI,CAAC,CAAW,+DAA+D;AAC/F,QAAA,kBAAkB,GAAG,SAAS,CAAC,CAAC,0EAA0E;AAC1G,QAAA,kBAAkB,GAAG,SAAS,CAAC,CAAC,gEAAgE;AAE7G,MAAa,gBAAgB;IACzB,MAAM,CAAS,CAAC,0DAA0D;IAC1E,MAAM,CAAS,CAAC,6DAA6D;IAE7E,YAAY,MAAc,EAAE,MAAc;QACtC,IAAI,CAAC,MAAM,GAA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AAI,CAA4B,CAAC;QACvD,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,IAAA,kBAAO,EAAC,GAAG,CAAC,CAAC;YAC3B,KAAK,KAAK,CAAC;YACX,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CACJ,CAAA;AA7JY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,yBAAyB,CA6JrC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from 'os';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { toError } from './to-error';\n\n// Outcome of a provenance check.\nexport const PROVENANCE_OK = 'ok'; // a matching reviewer subagent demonstrably ran on this branch\nexport const PROVENANCE_MISSING = 'missing'; // session known, but no matching subagent artifact found → refuse (BLOCK)\nexport const PROVENANCE_SKIPPED = 'skipped'; // no CLAUDE_CODE_SESSION_ID (plain terminal / CI) → warn + pass\n\nexport class ProvenanceResult {\n status: string; // PROVENANCE_OK | PROVENANCE_MISSING | PROVENANCE_SKIPPED\n detail: string; // human-readable explanation for the warning/error/dashboard\n\n constructor(status: string, detail: string) {\n this.status = status;\n this.detail = detail;\n }\n}\n\n/**\n * Verifies — from the Claude Code harness's OWN artifacts, never from anything the model asserts — that\n * a subagent of a given `agentType` actually ran during the current session on the current branch. Used\n * to enforce a checklist's optional `subagent:` field: that an INDEPENDENT reviewer looked, rather than\n * the coding agent self-certifying.\n *\n * The harness writes, beside each subagent transcript:\n * ~/.claude/projects/<cwd-slug>/<sessionId>/subagents/agent-<id>.meta.json → { agentType, spawnDepth, … }\n * ~/.claude/projects/<cwd-slug>/<sessionId>/subagents/agent-<id>.jsonl → record 0 { isSidechain, gitBranch, … }\n * `agentType`/`spawnDepth`/`isSidechain` are written by Claude Code, not by the model. We locate the dir\n * by the unique sessionId (globbing `projects/*/<sessionId>/subagents`), so the cwd-slug never has to be\n * derived/guessed.\n *\n * IMPORTANT — this is NOT tamper-proof. A determined agent can `cat >` a fake agent-*.meta.json. This\n * raises the bar from \"trust the model's word\" to \"deliberate, auditable forgery outside the repo\"; it\n * is not cryptographic. Say so wherever `subagent:` is documented.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and injected by type.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class SubagentProvenanceService {\n // Verify a subagent of `expectedAgentType` ran on `branch`. Absent CLAUDE_CODE_SESSION_ID (plain\n // terminal / CI) returns SKIPPED — the feature must not break non-Claude-Code consumers.\n verify(expectedAgentType: string, branch: string): ProvenanceResult {\n const sessionId = process.env['CLAUDE_CODE_SESSION_ID'] ?? '';\n if (sessionId.trim() === '') {\n return new ProvenanceResult(PROVENANCE_SKIPPED,\n `CLAUDE_CODE_SESSION_ID not set — cannot verify the \"${expectedAgentType}\" reviewer subagent (plain terminal / CI). Skipping the provenance check.`);\n }\n const dir = this.findSubagentsDir(sessionId);\n if (dir === '') {\n return new ProvenanceResult(PROVENANCE_MISSING,\n `No subagents recorded for this session — the \"${expectedAgentType}\" reviewer subagent must run on this branch before the PR can open.`);\n }\n const agentId = this.findMatchingAgentId(dir, expectedAgentType, branch);\n return agentId !== ''\n ? new ProvenanceResult(PROVENANCE_OK, `verified \"${expectedAgentType}\" reviewer subagent ran (agent ${agentId}).`)\n : new ProvenanceResult(PROVENANCE_MISSING,\n `No \"${expectedAgentType}\" reviewer subagent ran on this branch — a separate reviewer of that type must review this checklist.`);\n }\n\n // Verify EVERY expected reviewer subagent ran on `branch` as a DISTINCT run — the coding agent may not\n // self-certify, and one reviewer may not stand in for several. SKIPPED (pass) without a session id.\n verifyDistinct(expectedAgentTypes: readonly string[], branch: string): ProvenanceResult {\n if (expectedAgentTypes.length === 0) return new ProvenanceResult(PROVENANCE_OK, 'no reviewer subagents required');\n const sessionId = process.env['CLAUDE_CODE_SESSION_ID'] ?? '';\n if (sessionId.trim() === '') {\n return new ProvenanceResult(PROVENANCE_SKIPPED,\n `CLAUDE_CODE_SESSION_ID not set — cannot verify reviewer subagents ran (plain terminal / CI). Skipping the provenance check.`);\n }\n const dir = this.findSubagentsDir(sessionId);\n if (dir === '') {\n return new ProvenanceResult(PROVENANCE_MISSING,\n `No subagents recorded for this session — each checklist must be reviewed by its own subagent: ${expectedAgentTypes.join(', ')}.`);\n }\n const missing: string[] = [];\n const usedAgentIds = new Set<string>();\n for (const type of expectedAgentTypes) {\n const agentId = this.findMatchingAgentId(dir, type, branch, usedAgentIds);\n if (agentId === '') missing.push(type);\n else usedAgentIds.add(agentId);\n }\n return missing.length === 0\n ? new ProvenanceResult(PROVENANCE_OK, `verified ${expectedAgentTypes.length} distinct reviewer subagent(s) ran`)\n : new ProvenanceResult(PROVENANCE_MISSING,\n `these reviewer subagents did not run on this branch (spawn each as its OWN subagent — do not self-certify): ${missing.join(', ')}`);\n }\n\n // The agentId of a matching subagent run for `agentType` on `branch`, or '' if none. `exclude` skips\n // agentIds already credited to another checklist so one run can't satisfy two.\n private findMatchingAgentId(dir: string, agentType: string, branch: string, exclude: ReadonlySet<string> = new Set()): string {\n for (const metaFile of this.metaFiles(dir)) {\n const agentId = this.agentIdOf(metaFile);\n if (exclude.has(agentId)) continue;\n const meta = this.readJson(path.join(dir, metaFile));\n if (!meta || meta['agentType'] !== agentType) continue;\n const spawnDepth = meta['spawnDepth'];\n if (typeof spawnDepth !== 'number' || spawnDepth < 1) continue;\n if (this.sidechainOnBranch(dir, agentId, branch)) return agentId;\n }\n return '';\n }\n\n // Find the subagents dir for `sessionId` by its UNIQUE id, so the cwd-slug never has to be guessed.\n private findSubagentsDir(sessionId: string): string {\n const projects = path.join(os.homedir(), '.claude', 'projects');\n if (!fs.existsSync(projects)) return '';\n for (const proj of this.readDir(projects)) {\n const candidate = path.join(projects, proj, sessionId, 'subagents');\n if (fs.existsSync(candidate)) return candidate;\n }\n return '';\n }\n\n private metaFiles(dir: string): string[] {\n return this.readDir(dir).filter((f: string): boolean => f.endsWith('.meta.json'));\n }\n\n // agent-<id>.meta.json → <id>\n private agentIdOf(metaFile: string): string {\n return metaFile.replace(/^agent-/, '').replace(/\\.meta\\.json$/, '');\n }\n\n // Cross-check the sibling transcript's record 0: isSidechain true (a real subagent, not the main\n // loop) and, when recorded, the same branch. Lenient on branch drift (a leftover …wpN suffix from a\n // mid-flight branch rename) and on a missing jsonl (meta already matched — accept, best-effort).\n private sidechainOnBranch(dir: string, agentId: string, branch: string): boolean {\n const jsonl = path.join(dir, `agent-${agentId}.jsonl`);\n if (!fs.existsSync(jsonl)) return true;\n const first = this.firstNonEmptyLine(jsonl);\n if (first === '') return true;\n const rec = this.parseLine(first);\n if (!rec) return true;\n if (rec['isSidechain'] !== true) return false;\n const gitBranch = rec['gitBranch'];\n if (typeof gitBranch !== 'string' || gitBranch === '') return true;\n return this.stripWp(gitBranch) === this.stripWp(branch);\n }\n\n private stripWp(branch: string): string {\n return branch.replace(/-?wp\\d+$/i, '');\n }\n\n private readDir(dir: string): string[] {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable dir yields [] (best-effort provenance)\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return fs.readdirSync(dir);\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n }\n\n private firstNonEmptyLine(filePath: string): string {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unreadable transcript → '' (best-effort)\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n for (const line of fs.readFileSync(filePath, 'utf8').split('\\n')) {\n if (line.trim() !== '') return line;\n }\n return '';\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return '';\n }\n }\n\n // webpieces-disable no-any-unknown -- opaque parsed JSON object, keys read by the caller\n private readJson(filePath: string): Record<string, unknown> | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: malformed meta.json → null (skipped)\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed by the caller\n return JSON.parse(fs.readFileSync(filePath, 'utf8')) as Record<string, unknown>;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSONL record, keys read by the caller\n private parseLine(line: string): Record<string, unknown> | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: malformed JSONL record → null\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed by the caller\n return JSON.parse(line) as Record<string, unknown>;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n}\n"]}
|
package/src/validate-config.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare function validateWebpiecesConfig(rawRules: Record<string, Record<
|
|
|
8
8
|
* `repoRoot` (when known) lets the `checklists[].docs` existence check run.
|
|
9
9
|
*/
|
|
10
10
|
export declare function validatePrGateSection(section: unknown, repoRoot?: string): string[];
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function validateChecklistsSection(value: unknown, repoRoot?: string): string[];
|
|
12
12
|
/**
|
|
13
13
|
* Validate the REQUIRED top-level `excludePaths` block: two independent glob lists (`rules`,
|
|
14
14
|
* `guards`) that suppress hook enforcement per file path. Required so every client upgrading is
|
package/src/validate-config.js
CHANGED
|
@@ -3,17 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.allRuleNames = allRuleNames;
|
|
4
4
|
exports.validateWebpiecesConfig = validateWebpiecesConfig;
|
|
5
5
|
exports.validatePrGateSection = validatePrGateSection;
|
|
6
|
-
exports.
|
|
6
|
+
exports.validateChecklistsSection = validateChecklistsSection;
|
|
7
7
|
exports.validateExcludePaths = validateExcludePaths;
|
|
8
8
|
exports.validateMatchRulesSection = validateMatchRulesSection;
|
|
9
9
|
exports.validateSectionPlacement = validateSectionPlacement;
|
|
10
10
|
exports.validateCommandsSection = validateCommandsSection;
|
|
11
|
-
const tslib_1 = require("tslib");
|
|
12
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
13
|
-
const path = tslib_1.__importStar(require("path"));
|
|
14
11
|
const sections_1 = require("./sections");
|
|
15
12
|
const rule_configs_1 = require("./rule-configs");
|
|
16
|
-
const
|
|
13
|
+
const checklist_manifest_1 = require("./checklist-manifest");
|
|
17
14
|
const match_rules_config_1 = require("./match-rules-config");
|
|
18
15
|
const to_error_1 = require("./to-error");
|
|
19
16
|
const rule_configs_2 = require("./rule-configs");
|
|
@@ -247,56 +244,6 @@ function validateGate(gate, index) {
|
|
|
247
244
|
errors.push(`[pr-gate] gates[${index}].disabled must be a boolean (example/inactive gate kept in the file).`);
|
|
248
245
|
return errors;
|
|
249
246
|
}
|
|
250
|
-
// One `checklists[]` entry, validated field-by-field (mirrors validateGate + validateMatchRule). When
|
|
251
|
-
// `repoRoot` is supplied, each doc path must EXIST — a checklist pointing at a deleted doc is otherwise
|
|
252
|
-
// a silent no-op, which is exactly the failure mode this whole feature exists to prevent.
|
|
253
|
-
// webpieces-disable no-any-unknown -- one checklist entry from opaque consumer JSON, validated field-by-field
|
|
254
|
-
// webpieces-disable no-function-outside-class -- module-level config validator, matches validateGate/validateMatchRule
|
|
255
|
-
function validateChecklist(entry, index, repoRoot) {
|
|
256
|
-
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
257
|
-
return [`[pr-gate] checklists[${index}] must be an object { id, title, patterns, contentPatterns, docs, severity, blockMessage, disabled? }.`];
|
|
258
|
-
}
|
|
259
|
-
// webpieces-disable no-any-unknown -- narrowing one opaque checklist entry from consumer JSON
|
|
260
|
-
const c = entry;
|
|
261
|
-
const label = typeof c['id'] === 'string' && c['id'] !== '' ? `"${c['id']}"` : `checklists[${index}]`;
|
|
262
|
-
const errors = [];
|
|
263
|
-
if (typeof c['id'] !== 'string' || c['id'].trim() === '')
|
|
264
|
-
errors.push(`[pr-gate] checklists[${index}].id must be a non-empty string (it is the key echoed in review.json).`);
|
|
265
|
-
if (typeof c['title'] !== 'string' || c['title'].trim() === '')
|
|
266
|
-
errors.push(`[pr-gate] ${label}.title must be a non-empty string (the dashboard label).`);
|
|
267
|
-
if (c['patterns'] !== undefined && !isStringArray(c['patterns']))
|
|
268
|
-
errors.push(`[pr-gate] ${label}.patterns must be a string[] of path globs (omit or [] to match any changed file).`);
|
|
269
|
-
if (c['contentPatterns'] !== undefined && !isStringArray(c['contentPatterns'])) {
|
|
270
|
-
errors.push(`[pr-gate] ${label}.contentPatterns must be a string[] of regexes (omit or [] for a path-only trigger).`);
|
|
271
|
-
}
|
|
272
|
-
else if (isStringArray(c['contentPatterns'])) {
|
|
273
|
-
c['contentPatterns'].forEach((p, pi) => {
|
|
274
|
-
const rxErr = regexError(p);
|
|
275
|
-
if (rxErr)
|
|
276
|
-
errors.push(`[pr-gate] ${label}.contentPatterns[${pi}] is not a valid regex: ${rxErr}`);
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
if (!isStringArray(c['docs']) || c['docs'].length === 0) {
|
|
280
|
-
errors.push(`[pr-gate] ${label}.docs must be a non-empty string[] of repo-relative doc paths the AI must read.`);
|
|
281
|
-
}
|
|
282
|
-
else if (repoRoot !== undefined) {
|
|
283
|
-
c['docs'].forEach((doc) => {
|
|
284
|
-
if (!fs.existsSync(path.join(repoRoot, doc)))
|
|
285
|
-
errors.push(`[pr-gate] ${label}.docs references "${doc}", which does not exist — a checklist pointing at a missing doc silently never fires.`);
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
if (typeof c['severity'] !== 'string' || !checklist_config_1.CHECKLIST_SEVERITIES.includes(c['severity']))
|
|
289
|
-
errors.push(`[pr-gate] ${label}.severity must be one of: ${checklist_config_1.CHECKLIST_SEVERITIES.join(', ')}.`);
|
|
290
|
-
if (c['severity'] === checklist_config_1.CHECKLIST_BLOCK && (typeof c['blockMessage'] !== 'string' || c['blockMessage'].trim() === ''))
|
|
291
|
-
errors.push(`[pr-gate] ${label}.blockMessage is required for a ${checklist_config_1.CHECKLIST_BLOCK} checklist — it is the wording shown when the PR is refused.`);
|
|
292
|
-
if (c['blockMessage'] !== undefined && typeof c['blockMessage'] !== 'string')
|
|
293
|
-
errors.push(`[pr-gate] ${label}.blockMessage must be a string.`);
|
|
294
|
-
if (c['disabled'] !== undefined && typeof c['disabled'] !== 'boolean')
|
|
295
|
-
errors.push(`[pr-gate] ${label}.disabled must be a boolean (example/inactive checklist kept in the file).`);
|
|
296
|
-
if (c['subagent'] !== undefined && typeof c['subagent'] !== 'string')
|
|
297
|
-
errors.push(`[pr-gate] ${label}.subagent must be a string (the expected reviewer agentType, e.g. "morpheus-reviewer"; omit for no provenance requirement).`);
|
|
298
|
-
return errors;
|
|
299
|
-
}
|
|
300
247
|
/**
|
|
301
248
|
* Validate the top-level `pr-gate` section. It is REQUIRED (a client that opts out sets mode "OFF").
|
|
302
249
|
* `buildCommand` is required unless mode is "OFF". Returns human-readable, copy-paste-friendly errors
|
|
@@ -353,10 +300,10 @@ function validatePrGateSection(section, repoRoot) {
|
|
|
353
300
|
}
|
|
354
301
|
}
|
|
355
302
|
}
|
|
356
|
-
// Optional extension point:
|
|
357
|
-
//
|
|
303
|
+
// Optional extension point: company review checklists. The config only points at ONE manifest doc —
|
|
304
|
+
// { "doc": "..." } — and the checklist SET lives in that doc. Absent ⇒ no checklists.
|
|
358
305
|
if ('checklists' in s)
|
|
359
|
-
errors.push(...
|
|
306
|
+
errors.push(...validateChecklistsSection(s['checklists'], repoRoot));
|
|
360
307
|
// Optional server-token salt. Absent ⇒ no token minted, CI enforcement is a no-op. Present ⇒ must be
|
|
361
308
|
// a non-empty string (an empty salt would mint a token anyone can forge from a known-empty secret).
|
|
362
309
|
if ('gateSalt' in s) {
|
|
@@ -367,27 +314,24 @@ function validatePrGateSection(section, repoRoot) {
|
|
|
367
314
|
}
|
|
368
315
|
return errors;
|
|
369
316
|
}
|
|
370
|
-
// The `checklists`
|
|
371
|
-
//
|
|
317
|
+
// The `checklists` section of a pr-gate config: { "doc": "<path to the manifest doc>" }. The manifest
|
|
318
|
+
// itself (the list of { subagent, doc?, patterns? }) lives in that doc's <!-- webpieces:checklists -->
|
|
319
|
+
// block and is validated by ChecklistManifestService. Exported so the isolated validate-checklist-docs
|
|
320
|
+
// target reuses it. `repoRoot` (when known) lets the doc + manifest existence checks run.
|
|
372
321
|
// webpieces-disable no-any-unknown -- `value` is opaque consumer JSON until narrowed below
|
|
373
322
|
// webpieces-disable no-function-outside-class -- module-level config validator, matches the rest of this file
|
|
374
|
-
function
|
|
375
|
-
if (
|
|
376
|
-
return [`[pr-gate] "checklists" must be an
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
errors.push(`[pr-gate] duplicate checklist id "${id}" — each checklists[].id must be unique.`);
|
|
387
|
-
seenIds.add(id);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
return errors;
|
|
323
|
+
function validateChecklistsSection(value, repoRoot) {
|
|
324
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
325
|
+
return [`[pr-gate] "checklists" must be an object { "doc": "<path to the review manifest doc>" }.`];
|
|
326
|
+
}
|
|
327
|
+
// webpieces-disable no-any-unknown -- narrowing the opaque checklists section
|
|
328
|
+
const doc = value['doc'];
|
|
329
|
+
if (typeof doc !== 'string' || doc.trim() === '') {
|
|
330
|
+
return [`[pr-gate] "checklists.doc" must be a non-empty string — the repo-relative markdown doc carrying the <!-- webpieces:checklists [...] --> manifest.`];
|
|
331
|
+
}
|
|
332
|
+
if (repoRoot === undefined)
|
|
333
|
+
return [];
|
|
334
|
+
return new checklist_manifest_1.ChecklistManifestService().validate(repoRoot, doc);
|
|
391
335
|
}
|
|
392
336
|
function excludePathsExample() {
|
|
393
337
|
return '"excludePaths": {\n' +
|