@exaudeus/workrail 0.2.5-beta.5 → 0.2.5-beta.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exaudeus/workrail",
3
- "version": "0.2.5-beta.5",
3
+ "version": "0.2.5-beta.7",
4
4
  "description": "MCP server for structured workflow orchestration and step-by-step task guidance",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -25,22 +25,27 @@
25
25
  "Document I/O: create/update the file at reviewDocPath using file-writing tools. If the agent cannot write files, output the exact doc content with the intended path so the user can save it.",
26
26
  "If a function requires inputs that are missing, state exactly what is missing and pause. Otherwise, do not ask for confirmation.",
27
27
  "If prompt text and a function definition conflict, prefer the function definition for the how, and the step prompt for the what.",
28
- "collectNits(): From the current pass, extract 'Nit:' or Minor items; append to nitFindings {title, details, filePath, line, analysisDepth}; maintain nitsCount.",
29
- "prepareNitAppendix(): Group nitFindings by file; format 'filePath:line - short desc'; write markdown to nitAppendix; set nitAppendixReady=true.",
30
- "discoverModulePatterns(): Compute moduleRoot (nearest common ancestor of changed files, clamped to package/src); scan only moduleRoot to build patternCatalog + patternExamples (naming, DI, errors, logging, tests, layout).",
31
- "consolidatePatternFindings(): Compare changes to patternCatalog (scoped to moduleRoot); produce patternFindings + grouped patternAppendix; set patternAppendixReady=true.",
32
- "initReviewDoc(): Create live Markdown at project root; filename '<YYYY-MM-DD>--<ticket-or-branch>--mr-review.md'; insert section markers; set reviewDocPath; if no file I/O, output full doc and path.",
28
+ "discoverModulePatterns(): Compute moduleRoot; scan only moduleRoot to build patternCatalog.",
29
+ "discoverModulePatterns() details: moduleRoot = nearest common ancestor, clamped to package/src; catalog = naming, DI, errors, logging, tests, layout.",
30
+ "consolidatePatternFindings(): Compare changes to patternCatalog (scoped to moduleRoot).",
31
+ "consolidatePatternFindings() details: produce patternFindings + grouped patternAppendix; set patternAppendixReady=true.",
32
+ "initReviewDoc(): Create live Markdown at project root; set reviewDocPath.",
33
+ "initReviewDoc() details: filename '<YYYY-MM-DD>--<ticket-or-branch>--mr-review.md'; insert section markers; if no file I/O, output full doc and path.",
33
34
  "upsertSection(): Upsert under a known section marker; never duplicate sections; keep formatting concise.",
34
35
  "appendChangedFileRow(): Append/update Changed Files table row: File | +/- | Summary | Risk.",
35
36
  "appendFinding(): Append finding under severity (Critical/Major/Minor) with path:line, 1–2-line rationale, optional tiny diff.",
36
37
  "appendPatternResult(): Append Pattern Adherence row (Check | Result | Note); add brief per-file deviations.",
37
- "appendNit(): Append Nit grouped by file: 'path:line — nit text'.",
38
38
  "appendMRComment(): Append copy-ready MR comment: file:line, short title, rationale, optional tiny diff.",
39
39
  "logRevision(): Append timestamped message to the Revision Log describing the update.",
40
- "discoverHygieneSignals(): In moduleRoot, scan changed files + neighbors for: focused/disabled/skipped tests; no‑assert tests; commented‑out code; stale/misleading comments; TODO/FIXME/HACK/BUG w/o tickets or stale; pattern inconsistencies; ad‑hoc debug prints; unused/unreachable code.",
41
- "consolidateHygieneFindings(): Cap total ≤10 and ≤3 per category; dedupe; group by file; elevate Major only for clearly risky cases; produce category counts and capped items.",
42
- "appendHygieneFinding(): Append hygiene bullet grouped by file: 'path:line — short note (≤2 lines)'; if duplicated in Nits, reference '(linked in Nits)'.",
43
- "finalizeReviewDocument(): Trivial—brief approve summary; ≤2 hygiene; quick nits; set status=Final; log. Non‑trivial—exec summary (3 positives, 3 risks, recommendation); dedupe/sort findings; ensure sections + curated comments for Critical/Major; set status=Final; log."
40
+ "discoverHygieneSignals(): Scan moduleRoot changed files + neighbors for hygiene issues.",
41
+ "discoverHygieneSignals() details: focused/disabled/skipped tests; no‑assert tests; commented‑out code; stale/misleading comments; TODO/FIXME/HACK/BUG w/o tickets; pattern inconsistencies; debug prints; unused code.",
42
+ "consolidateHygieneFindings(): Cap total ≤10 and ≤3 per category; dedupe; group by file.",
43
+ "consolidateHygieneFindings() details: elevate Major only for clearly risky cases; produce category counts and capped items.",
44
+ "appendHygieneFinding(): Append hygiene bullet grouped by file: 'path:line — short note (≤2 lines)'.",
45
+ "appendHygieneFinding() details: if duplicated in Nits, reference '(linked in Nits)'.",
46
+ "finalizeReviewDocument(): Branch on complexity for different finalization logic.",
47
+ "finalizeReviewDocument() Trivial: brief approve summary; ≤2 hygiene; quick nits; set status=Final; log.",
48
+ "finalizeReviewDocument() Non‑trivial: exec summary (3 positives, 3 risks, recommendation); dedupe/sort findings; ensure sections + curated comments; set status=Final; log."
44
49
  ],
45
50
  "steps": [
46
51
  {
@@ -52,8 +57,7 @@
52
57
  "**[Trivial]:** For minor fixes (typos, docs). This will run a condensed, single-phase review.",
53
58
  "**[Standard]:** For typical features or bug fixes. This uses the full, multi-phase review process.",
54
59
  "**[High-Risk]:** For major architectural changes or features touching sensitive code. This follows the full process with maximum diligence."
55
- ],
56
- "functionReferences": ["initReviewDoc()", "logRevision()"]
60
+ ]
57
61
  },
58
62
  {
59
63
  "id": "phase-1-context",
@@ -64,18 +68,9 @@
64
68
  "This is a critical sanity check. If the agent's summary is incorrect, correct it now to prevent a flawed review. This step is skipped for 'Trivial' reviews."
65
69
  ],
66
70
  "runCondition": { "var": "complexity", "not_equals": "Trivial" },
67
- "requireConfirmation": true,
68
- "functionReferences": ["upsertSection()", "appendChangedFileRow()", "logRevision()"]
69
- },
70
- {
71
- "id": "phase-1-context-setup",
72
- "title": "Phase 1: Initializing Analysis State",
73
- "prompt": "Initializing state for progressive depth analysis. Setting analysisDepth = 1, analysisComplete = false, and majorIssuesFound = false.",
74
- "agentRole": "You are a state manager preparing the workflow for an iterative review process.",
75
- "guidance": ["This is an automated step to prepare for the analysis loop."],
76
- "runCondition": { "and": [ { "var": "complexity", "not_equals": "Trivial" }, { "or": [ { "var": "contextGatheringComplete", "equals": true }, { "var": "skipContextGathering", "equals": true } ] } ] },
77
- "requireConfirmation": false
71
+ "requireConfirmation": true
78
72
  },
73
+
79
74
  {
80
75
  "id": "phase-1a-llm-context-gathering",
81
76
  "title": "Phase 1a: Comprehensive Context Gathering",
@@ -85,25 +80,50 @@
85
80
  "runCondition": { "var": "complexity", "not_equals": "Trivial" },
86
81
  "requireConfirmation": true
87
82
  },
83
+ {
84
+ "id": "phase-1b-familiarization",
85
+ "title": "Phase 1b: Neighborhood, Call Graph, and Contracts Familiarization",
86
+ "prompt": "Build a lightweight understanding of surrounding code to increase review accuracy.\n\nTasks:\n1) Neighborhood Map: For each changed file, list immediate neighbors in moduleRoot (imports/exports/same-folder), co-located tests, and closest entry points (routes/endpoints/commands). Cap neighbors per file.\n2) Bounded Call Graph: For changed functions/classes, gather callers and callees up to 2 hops within moduleRoot; cap nodes/edges; prioritize edges touching changed code.\n3) Contracts & Invariants: List public symbols, API endpoints, DB/tables/messages touched nearby. Capture any stated invariants or assumptions from comments.\n\nDoc-first: Upsert sections 'Neighborhood Map', 'Bounded Call Graph', and 'Contracts & Invariants' with concise tables/bullets. Include only the highest-signal items (apply caps).",
87
+ "agentRole": "You are a codebase navigator building context around the change to improve downstream analysis.",
88
+ "guidance": [
89
+ "Initialize majorIssuesFound = false.",
90
+ "Scope strictly to moduleRoot and changed files plus immediate neighbors.",
91
+ "Cap per-file neighbors and graph size to avoid noise; prefer edges directly related to the diff.",
92
+ "Write full details to the live doc; in chat, keep output minimal.",
93
+ "Render 'ASCII Call Graphs' under 'Bounded Call Graph': edges 'A -> B', width ≤100, highlight changed as [*name*], include tiny legend.",
94
+ "Paths: for each changed symbol show top 2–3 inbound and outbound paths, depth ≤2, dedupe, shortest-first then alphabetical.",
95
+ "Caps: ≤12 nodes, ≤20 edges across graphs; if exceeded, fall back to an adjacency list with per-edge counts.",
96
+ "Flow Anchors: map entrypoints to changed symbols; table 'Anchor | Type | Target Symbol | Notes'; cap ≤5 anchors.",
97
+ "Hot-Path ranking: score edges (diff touch, anchor, ticket keyword, test ref); tag HOT if score ≥ threshold; prefer HOT paths in ASCII output.",
98
+ "Legend in doc: [*name*]=changed; HOT=high-impact; 'A -> B'=calls; 'Route -> Handler'; 'Job -> Worker'.",
99
+ "If caps exceeded, write 'Adjacency Summary': 'Node | In | Out | Notes' (top-K by degree/frequency) and add 1–2 uncertainty questions."
100
+ ],
101
+ "runCondition": { "and": [ { "var": "complexity", "not_equals": "Trivial" }, { "or": [ { "var": "contextGatheringComplete", "equals": true }, { "var": "skipContextGathering", "equals": true } ] } ] },
102
+ "functionReferences": ["upsertSection()", "logRevision()"],
103
+ "requireConfirmation": false
104
+ },
88
105
  {
89
106
  "id": "phase-2-depth-analysis-loop",
90
107
  "type": "loop",
91
108
  "title": "Phase 2: Progressive Depth Analysis",
92
109
  "runCondition": { "and": [ { "var": "complexity", "not_equals": "Trivial" }, { "or": [ { "var": "contextGatheringComplete", "equals": true }, { "var": "skipContextGathering", "equals": true } ] } ] },
93
110
  "loop": {
94
- "type": "until",
95
- "condition": { "var": "analysisComplete", "equals": true },
96
- "maxIterations": 3,
111
+ "type": "for",
112
+ "count": 4,
113
+ "maxIterations": 4,
97
114
  "iterationVar": "analysisDepth"
98
115
  },
99
116
  "body": [
100
117
  {
101
118
  "id": "discover-module-patterns",
102
119
  "title": "Discover Module Patterns (Depth 1)",
103
- "prompt": "Compute `moduleRoot` as the nearest common ancestor of changed files, clamped to the package or `src/` subtree. Scan only within `moduleRoot` to gather exemplars (naming, DI, error handling, logging, test style, file layout). Produce `patternCatalog` and `patternExamples` in context. Do not block or require confirmation.",
120
+ "prompt": "Compute `moduleRoot` as the nearest common ancestor of changed files, clamped to the package or `src/` subtree. Scan only within `moduleRoot` to gather exemplars (naming, DI, error handling, logging, test style, file layout). Exclude changed files from discovery so they cannot define patterns. Only elevate a rule to a 'pattern' when observed ≥2 times across distinct files; record singletons as 'candidate conventions'. Produce `patternCatalog` (validated patterns) and `patternExamples` (1–3 exemplars per pattern) in context. Do not block or require confirmation.",
104
121
  "agentRole": "You are a codebase pattern scout building a concise pattern catalog for the current module.",
105
122
  "guidance": [
106
123
  "Scope strictly to `moduleRoot` discovered from changed files.",
124
+ "Exclude changed files from discovery; use them only later for comparison.",
125
+ "Require ≥2 occurrences across distinct files to qualify as a pattern; otherwise mark as 'candidate convention'.",
126
+ "Capture 1–3 exemplars per validated pattern with file:line for the doc.",
107
127
  "Cap exemplars (e.g., 3–5 per concern) for speed."
108
128
  ],
109
129
  "runCondition": { "var": "analysisDepth", "equals": 1 },
@@ -112,22 +132,38 @@
112
132
  },
113
133
  {
114
134
  "id": "perform-analysis-pass",
115
- "title": "Analysis Pass {{analysisDepth}} of 3",
135
+ "title": "Analysis Pass {{analysisDepth}} of 4",
116
136
  "prompt": "Act as a Senior Staff Engineer. Your task is to review the code based on the checklist for the current analysis depth. Think step-by-step.\n\n**Current Depth: {{analysisDepth}}**\n\n**Checklist:**\n* **Depth 1 (Basic Scan):** Check for style guide violations, simple bugs (e.g., typos, unused variables), and common security vulnerabilities (OWASP Top 10).\n* **Depth 2 (Standard Review):** Check for logical errors, edge cases, adherence to SOLID principles, and maintainability issues.\n* **Depth 3 (Deep Architectural Review):** Check for alignment with system architecture, long-term impact, performance bottlenecks, and dependency risks.\n\n**Instructions:**\n1. **Summarize Focus:** State which depth level you are on and what you will focus on.\n2. **Analyze:** Perform the review based on the checklist for depth {{analysisDepth}}.\n3. **List Findings:** Document your findings, categorizing them as 'Critical', 'Major', or 'Minor'.\n4. **Set Flag:** If you find any 'Critical' or 'Major' issues, set the context variable `majorIssuesFound = true`.",
117
137
  "agentRole": "You are a Senior Staff Engineer performing a structured, multi-pass code review with increasing levels of scrutiny.",
118
138
  "guidance": [
119
139
  "At each depth, focus only on the items in that checklist.",
120
- "Use Chain-of-Thought reasoning to explain your findings."
140
+ "Use Chain-of-Thought reasoning to explain your findings (keep chat concise; write full details to the doc).",
141
+ "Retrieval bias: Prefer reading files/functions from 'Neighborhood Map' and HOT paths before broader scans.",
142
+ "Depth 2: Prefer Flow Anchors and HOT paths; walk 2–3 inbound/outbound traces; verify control/data flow vs invariants; record surprises.",
143
+ "Depth 3: On HOT paths, check module boundaries, DI patterns, performance, and consumer contracts; note potential breakages.",
144
+ "Propose tiny diffs (non-blocking) for the top 1–2 Major findings: fenced unified diff with file paths; ≤8 changed lines total and ≤2 hunks per patch; add one-line rationale; scope narrow; skip if ambiguous and state why.",
145
+ "For each proposed patch, add a matching ready-to-copy MR comment (file:line + rationale).",
146
+ "Append patches to the 'Proposed Patches' section; append MR comments and log the revision.",
147
+ "Caps per pass: ≤2 patches; ≤3 MR comments; ≤1200 chars of total patch text.",
148
+ "Self-critique: list 1–2 least-confident areas and what would increase confidence under 'Confidence & Follow-ups'."
121
149
  ],
122
- "functionReferences": ["collectNits()", "appendFinding()", "appendMRComment()", "logRevision()"],
150
+ "runCondition": { "or": [ { "var": "analysisDepth", "equals": 1 }, { "var": "analysisDepth", "equals": 2 }, { "var": "analysisDepth", "equals": 3 } ] },
151
+ "functionReferences": ["upsertSection()", "appendFinding()", "appendMRComment()", "logRevision()"],
123
152
  "requireConfirmation": false
124
153
  },
125
154
  {
126
- "id": "check-analysis-completion",
127
- "title": "Check Analysis Completion",
128
- "prompt": "Checking if the analysis is complete. If no 'Major' or 'Critical' issues were found in the last pass, or if we have reached the maximum depth (3), I will set `analysisComplete = true` to exit the loop. Otherwise, I will increment the `analysisDepth` and continue to the next level of review.",
129
- "agentRole": "You are an automated process controller determining whether to deepen the analysis or conclude this phase.",
130
- "guidance": ["This step determines the exit condition for the progressive depth loop."],
155
+ "id": "perform-nit-hunt",
156
+ "title": "Nit Hunt (Depth 4)",
157
+ "prompt": "Perform a focused nit hunt in `moduleRoot` on changed files and immediate neighbors. Be picky but objective. Provide concise, actionable nits with one-line rationale and suggested fix.",
158
+ "agentRole": "You are a meticulous reviewer surfacing small, high-signal improvements.",
159
+ "guidance": [
160
+ "Targets: naming clarity; small readability/style inconsistencies; redundant comments; commented/dead code; import/order polish; safe micro-perf; test naming/structure.",
161
+ "Quotas: if majorIssuesFound==true aim 5–8 (cap 12); else aim 8–12 (cap 15); ≤3 per category; 1–2 lines each; dedupe; group by file; prefix 'Nit:'.",
162
+ "Add ready-to-copy MR comments for the top 3 nits; log the revision.",
163
+ "Append Nit grouped by file: 'path:line — nit text'."
164
+ ],
165
+ "runCondition": { "var": "analysisDepth", "equals": 4 },
166
+ "functionReferences": ["appendMRComment()", "upsertSection()", "logRevision()"],
131
167
  "requireConfirmation": false
132
168
  }
133
169
  ]
@@ -135,11 +171,14 @@
135
171
  {
136
172
  "id": "consolidate-patterns",
137
173
  "title": "Consolidate Pattern Findings",
138
- "prompt": "Using `moduleRoot` and `patternCatalog`, compare the MR changes to local conventions. Summarize adherence and deviations, and generate a grouped `patternAppendix` (by directory/file). Set `patternAppendixReady = true`.",
174
+ "prompt": "Using `moduleRoot` and `patternCatalog`, compare the MR changes to validated patterns (patterns observed ≥2 times across distinct files). Do not use changed code to define patterns. Summarize adherence and deviations, and generate a grouped `patternAppendix` (by directory/file). If no patterns meet the threshold, state this and list 'candidate conventions' separately as informative only. Set `patternAppendixReady = true`.",
139
175
  "agentRole": "You are a senior engineer consolidating pattern adherence findings for clear reporting.",
140
176
  "guidance": [
141
177
  "Restrict to the module of the MR (`moduleRoot`).",
142
- "Avoid re-scanning if `patternCatalog` already exists; reuse it."
178
+ "Avoid re-scanning if `patternCatalog` already exists; reuse it.",
179
+ "Do not treat changed code as patterns; match only against validated patterns from `patternCatalog` (≥2 distinct occurrences).",
180
+ "Produce 'Patterns' and 'Pattern Deviations' sections: adherence table with confidence + counts; deviation ledger with file:line, rationale, and suggested alignment.",
181
+ "Include per-pattern occurrence counts in the module (excluding changed files)."
143
182
  ],
144
183
  "runCondition": { "var": "complexity", "not_equals": "Trivial" },
145
184
  "functionReferences": ["consolidatePatternFindings()", "appendPatternResult()", "upsertSection()", "logRevision()"],
@@ -148,12 +187,18 @@
148
187
  {
149
188
  "id": "phase-3-impact-analysis",
150
189
  "title": "Phase 3: Testing, Documentation & Impact Analysis",
151
- "prompt": "My goal is to assess the secondary impacts of this change.\n\n1. **Testing:** Based on the code changes, what tests would be expected (unit, integration, etc.)? Are new tests included? Are existing tests updated? Are there obvious gaps in test coverage for the new logic?\n2. **Documentation:** Is new or complex logic adequately commented? Could any external documentation (e.g., READMEs) be affected by this change?\n3. **Breaking Changes:** Are there any changes that could break backward compatibility for APIs or other parts of the codebase?",
190
+ "prompt": "My goal is to assess the secondary impacts of this change.\n\n1. **Testing:** Based on the code changes, what tests would be expected (unit, integration, etc.)? Are new tests included? Are existing tests updated? Are there obvious gaps in test coverage for the new logic?\n2. **Documentation:** Is new or complex logic adequately commented? Could any external documentation (e.g., READMEs) be affected by this change?\n3. **Breaking Changes:** Are there any changes that could break backward compatibility for APIs or other parts of the codebase?\n\nDoc-first subsections to add/update:\n- Impacted User Flows: table 'Flow/Anchor | Type | Path/ID | Handler Chain (short) | Impact | Risk(L/M/H)'.\n- Affected Consumers: table 'Consumer | Type | Breakage Risk | Migration Note'.\n- Test Gaps & Proposals: table 'Scope | Target | Purpose | Sketch'.",
152
191
  "agentRole": "You are a software quality engineer specializing in testing strategy and impact analysis. Your expertise includes identifying testing gaps, documentation requirements, and potential breaking changes that could affect system stability or user experience.",
153
192
  "guidance": [
154
- "Assessing test coverage is critical. A lack of tests for new logic is often a 'Major' or 'Critical' concern."
193
+ "Assessing test coverage is critical. A lack of tests for new logic is often a 'Major' or 'Critical' concern.",
194
+ "Derive Impacted User Flows from Flow Anchors and HOT paths (depth ≤2); cap ≤5 flows; prefer acceptance-criteria keywords.",
195
+ "List Affected Consumers (importers/API clients/message consumers); cap ≤8; rank by usage frequency and proximity to changed code.",
196
+ "Test skeletons: for top-risk flows/consumers, add concise code fences (project test style if clear) with a suggested file path comment at top; ≤25 lines per sketch; ≤6 total sketches (≤2 per top risk).",
197
+ "For data/schema/API changes, add at least one Contract test proposal; total test proposals cap ≤10.",
198
+ "Add 2 ready-to-copy MR comments for the highest-risk gaps; log the revision."
155
199
  ],
156
200
  "runCondition": { "and": [ { "var": "complexity", "not_equals": "Trivial" }, { "or": [ { "var": "contextGatheringComplete", "equals": true }, { "var": "skipContextGathering", "equals": true } ] } ] },
201
+ "functionReferences": ["upsertSection()", "appendMRComment()", "logRevision()"],
157
202
  "requireConfirmation": false
158
203
  },
159
204
  {
@@ -176,10 +221,16 @@
176
221
  "agentRole": "You are a meticulous note-taker consolidating non-blocking suggestions for clarity and follow-through.",
177
222
  "guidance": [
178
223
  "This step is non-blocking and purely for documentation quality.",
179
- "Keep items concise; avoid repeating Major concerns."
224
+ "Deterministic ordering: sort by file path ASC → line ASC → category ASC; group by file.",
225
+ "Categories: Naming; Readability; Style; Comments; Imports/Order; Tests (naming/structure); Minor Perf.",
226
+ "Row format: 'path:line — Nit: short text (≤2 lines); suggested fix: <one-liner> [category]'; optional tiny diff snippet ≤6 lines only if helpful.",
227
+ "Dedupe: identical path:line + similar text → keep one; if overlap with Hygiene/Patterns, keep in the most specific section and cross-reference in the other.",
228
+ "Caps: ≤15 total; ≤3 per category; if exceeded, append a single 'More items omitted due to caps.' line.",
229
+ "Cross-link any existing MR comments to their nit rows (e.g., 'MR: MR-##').",
230
+ "Chat: minimal recap with doc path and counts; full details live in the doc."
180
231
  ],
181
232
  "runCondition": { "and": [ { "var": "complexity", "not_equals": "Trivial" }, { "or": [ { "var": "contextGatheringComplete", "equals": true }, { "var": "skipContextGathering", "equals": true } ] } ] },
182
- "functionReferences": ["prepareNitAppendix()", "appendNit()", "upsertSection()", "logRevision()"],
233
+ "functionReferences": ["upsertSection()", "logRevision()"],
183
234
  "requireConfirmation": false
184
235
  },
185
236
  {
@@ -188,9 +239,18 @@
188
239
  "prompt": "Finalize the live review document (no new analysis).\n\nBranching:\n- If `complexity == 'Trivial'`:\n 1) Upsert a brief Executive Summary (1–2 lines) with 'Recommendation: Approve'.\n 2) Perform light hygiene (≤2 items) on changed files; write concise bullets under 'Hygiene & Inconsistencies'.\n 3) Quick Nit sweep; write bullets under 'Nit Appendix'.\n 4) Update Header: set status=Final; include final counts.\n 5) Append 'Finalized trivial review' to the Revision Log.\n\n- Otherwise (non-trivial):\n 1) Upsert Executive Summary (3 positives, 3 risks, final recommendation).\n 2) Dedupe and sort Findings (Severity → File → Line).\n 3) Ensure sections exist: Patterns, Pattern Deviations, Tests & Docs, Ideas & Alternatives, Nits, MR Comments.\n 4) Ensure every Critical/Major finding has a curated MR comment; add minimal ones if missing.\n 5) Update Header: set status=Final; include final counts and decision.\n 6) Append 'Finalized document' to the Revision Log.\n\nChat: Provide a concise recap (Trivial: 2–3 lines; Non-trivial: ≤10 lines) with decision and the doc path.",
189
240
  "agentRole": "You are a facilitator ensuring the final document is complete, accurate, and consumable.",
190
241
  "guidance": [
191
- "Write full details to the live doc; keep chat to a concise recap with the doc path."
242
+ "Write full details to the live doc; keep chat to a concise recap with the doc path.",
243
+ "Ensure sections exist: 'Executive Summary', 'Decision Criteria', 'Risk Heatmap', 'Proposed Patches', 'Test Gaps & Proposals', 'Confidence & Follow-ups'; create missing sections with stable anchors.",
244
+ "Executive Summary template: 3 positives (≤120 chars each); 3 risks (≤120 chars each); decision & rationale (≤2 lines); add links to Patterns, Deviations, Tests, Hygiene; total ≤12 lines.",
245
+ "Decision Criteria checklist: Scope fit; Tests adequate; Pattern adherence; Performance risk; Backwards compatibility; Security basics. Render as 'Criteria: [✓/✗] label — 1 phrase note' in fixed order.",
246
+ "Risk Heatmap table: rows 'Risk | Area | Likelihood(L/M/H) | Impact(L/M/H) | Mitigation(≤1 line)'; sort by Impact desc then Likelihood desc; cap ≤6 rows; add 'omitted due to caps' line if needed.",
247
+ "Dedupe patches and MR comments; ensure every Critical/Major has either a patch or a copy-ready MR comment.",
248
+ "If any Critical/Major lacks an MR comment, generate a minimal ready-to-copy comment (file:line, short title, 1–2 line rationale, optional tiny diff snippet).",
249
+ "Group MR comments by file and dedupe similar entries; add a 'Missing Comments Summary' note if any comments were auto-added.",
250
+ "Cross-link each MR comment to its related Proposed Patch when applicable ('See Proposed Patch: <title>').",
251
+ "Keep all caps deterministic; if any list exceeds its cap, add a single trailing 'More items omitted due to caps.' line."
192
252
  ],
193
- "functionReferences": ["finalizeReviewDocument()", "ensureSectionMarkers()", "upsertSection()", "curateMRComments()", "discoverHygieneSignals()", "consolidateHygieneFindings()", "appendHygieneFinding()", "logRevision()"],
253
+ "functionReferences": ["finalizeReviewDocument()", "upsertSection()", "discoverHygieneSignals()", "consolidateHygieneFindings()", "appendHygieneFinding()", "logRevision()"],
194
254
  "requireConfirmation": false
195
255
  }
196
256
  ]