mandrel 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/.agents/README.md +104 -330
  2. package/.agents/agents/auditor.md +135 -0
  3. package/.agents/agents/plan-critic.md +80 -0
  4. package/.agents/audit-checklists/dependencies.md +7 -0
  5. package/.agents/audit-checklists/documentation.md +1 -0
  6. package/.agents/docs/SDLC.md +69 -162
  7. package/.agents/docs/configuration.md +133 -499
  8. package/.agents/docs/quality-gates.md +59 -180
  9. package/.agents/instructions.md +170 -295
  10. package/.agents/rules/changelog-style.md +8 -66
  11. package/.agents/rules/ci-remediation.md +65 -124
  12. package/.agents/rules/gherkin-standards.md +10 -31
  13. package/.agents/rules/git-conventions-reference.md +28 -61
  14. package/.agents/rules/git-conventions.md +1 -1
  15. package/.agents/rules/orchestration-error-handling.md +5 -15
  16. package/.agents/rules/security-baseline.md +7 -13
  17. package/.agents/rules/shell-conventions.md +4 -13
  18. package/.agents/rules/test-seams.md +2 -2
  19. package/.agents/rules/testing-standards.md +7 -17
  20. package/.agents/scripts/lib/feedback-loop/audit-results-graduator.js +7 -2
  21. package/.agents/scripts/lib/feedback-loop/graduator-core.js +144 -12
  22. package/.agents/scripts/lib/feedback-loop/retro-proposals-graduator.js +11 -1
  23. package/.agents/scripts/lib/observability/runtime-friction.js +97 -36
  24. package/.agents/scripts/lib/orchestration/single-story-close/phases/post-land.js +29 -5
  25. package/.agents/skills/core/api-and-interface-design/SKILL.md +23 -297
  26. package/.agents/skills/core/api-and-interface-design/reference.md +76 -0
  27. package/.agents/skills/core/browser-testing-with-devtools/SKILL.md +20 -327
  28. package/.agents/skills/core/browser-testing-with-devtools/reference.md +74 -0
  29. package/.agents/skills/core/code-review-and-quality/reference.md +16 -398
  30. package/.agents/skills/core/debugging-and-error-recovery/reference.md +14 -281
  31. package/.agents/skills/core/documentation-and-adrs/reference.md +42 -338
  32. package/.agents/skills/core/git-workflow-and-versioning/SKILL.md +28 -326
  33. package/.agents/skills/core/idea-refinement/SKILL.md +67 -193
  34. package/.agents/skills/core/security-and-hardening/SKILL.md +15 -31
  35. package/.agents/skills/core/security-and-hardening/reference.md +15 -273
  36. package/.agents/skills/skills.index.json +5 -5
  37. package/.agents/skills/stack/qa/gherkin-authoring/SKILL.md +16 -222
  38. package/.agents/skills/stack/qa/gherkin-authoring/reference.md +157 -0
  39. package/.agents/skills/stack/qa/playwright/SKILL.md +0 -29
  40. package/.agents/skills/stack/qa/qa-explore-driving/SKILL.md +19 -23
  41. package/.agents/skills/stack/qa/qa-harness/SKILL.md +35 -53
  42. package/.agents/skills/stack/qa/vitest/SKILL.md +0 -29
  43. package/.agents/workflows/audit-accessibility.md +34 -108
  44. package/.agents/workflows/audit-architecture.md +35 -123
  45. package/.agents/workflows/audit-clean-code.md +19 -78
  46. package/.agents/workflows/audit-data-model.md +32 -100
  47. package/.agents/workflows/audit-dependencies.md +47 -111
  48. package/.agents/workflows/audit-devops.md +16 -83
  49. package/.agents/workflows/audit-documentation.md +46 -93
  50. package/.agents/workflows/audit-navigability.md +26 -80
  51. package/.agents/workflows/audit-performance.md +40 -106
  52. package/.agents/workflows/audit-privacy.md +17 -80
  53. package/.agents/workflows/audit-quality.md +35 -99
  54. package/.agents/workflows/audit-security.md +20 -78
  55. package/.agents/workflows/audit-seo.md +20 -98
  56. package/.agents/workflows/audit-sre.md +20 -88
  57. package/.agents/workflows/audit-to-stories.md +1 -8
  58. package/.agents/workflows/audit-ux-ui.md +17 -80
  59. package/.agents/workflows/deliver.md +54 -9
  60. package/.agents/workflows/git-cleanup.md +50 -275
  61. package/.agents/workflows/helpers/audit-lens-core.md +230 -0
  62. package/.agents/workflows/helpers/code-review.md +11 -23
  63. package/.agents/workflows/helpers/deliver-story-reference.md +114 -17
  64. package/.agents/workflows/helpers/deliver-story.md +26 -186
  65. package/.agents/workflows/helpers/qa-core.md +174 -0
  66. package/.agents/workflows/helpers/qa-run-scenario-reference.md +35 -0
  67. package/.agents/workflows/helpers/qa-run-scenario.md +11 -25
  68. package/.agents/workflows/helpers/worktree-lifecycle.md +6 -67
  69. package/.agents/workflows/mandrel-update.md +7 -13
  70. package/.agents/workflows/plan.md +17 -15
  71. package/.agents/workflows/qa-assist.md +140 -269
  72. package/.agents/workflows/qa-explore.md +125 -316
  73. package/.agents/workflows/qa-run.md +180 -380
  74. package/docs/CHANGELOG.md +18 -0
  75. package/package.json +1 -1
  76. package/.agents/workflows/helpers/audit-dual-path.md +0 -59
  77. package/.agents/workflows/helpers/audit-self-check.md +0 -70
  78. package/.agents/workflows/helpers/audit-severity-scale.md +0 -19
@@ -4,47 +4,31 @@ description: Audit architectural boundaries, module coupling, and layering viola
4
4
 
5
5
  # Architecture & Clean Code Audit
6
6
 
7
- ## Role
7
+ You are a Staff Software Engineer & Architecture Reviewer performing a read-only
8
+ review that prioritizes maintainability and readability without altering
9
+ external APIs or business logic. The shared lens machinery — read-only
10
+ constraint, scope interpretation, report envelope + finding-block skeleton,
11
+ severity scale, self-cross-check, and execution strategy — lives in
12
+ [`helpers/audit-lens-core.md`](helpers/audit-lens-core.md). Write the report to
13
+ `{{auditOutputDir}}/audit-architecture-results.md`. Each finding carries an
14
+ **Impact:** and a **Category:** (`Quick Win | Structural Change`); the report
15
+ adds a **Triage Summary** (Quick Wins / Structural Changes) and an
16
+ **Architecture Guardrail Coverage** section.
8
17
 
9
- Staff Software Engineer & Architecture Reviewer
18
+ ## Scope
10
19
 
11
- ## Context & Objective
12
-
13
- You are performing a comprehensive, read-only architectural and clean-code
14
- review of this codebase. Your goal is to identify areas of unnecessary
15
- abstraction, premature optimization, high cognitive load, and over-engineering.
16
- You must prioritize maintainability and readability without altering any
17
- existing external APIs or business logic.
18
-
19
- ## Execution strategy (dual-path)
20
-
21
- This lens runs along one of two execution paths (orchestrated dynamic-workflow
22
- or sequential single-pass). Both emit the **identical** Step 3 report contract;
23
- downstream consumers (`audit-to-stories`) are agnostic to which path produced
24
- it. See [`helpers/audit-dual-path.md`](helpers/audit-dual-path.md) for strategy
25
- selection, the forcing flags, and the read-only guarantee — read `audit-<lens>`
26
- there as this lens's name.
27
-
28
- ## Scope (Story / plan-run mode)
29
-
30
- When this lens is invoked from `/deliver` close lenses (or a plan-run audit), the
31
- following block is populated with the Story (or plan-run) change-set file list.
32
- Otherwise — for any manual `/audit-<dimension>` invocation — the block
33
- renders the literal substitution token and you MUST treat it as **no
34
- scope filter — run the lens codebase-wide** exactly as you would have
35
- before this section existed.
20
+ Interpret this lens's change-set fence per the core's Scope interpretation:
36
21
 
37
22
  ```text
38
23
  {{changedFiles}}
39
24
  ```
40
25
 
41
- - If the block above contains a newline-delimited list of file paths,
42
- restrict your analysis to those files (and their direct dependencies
43
- when the lens explicitly calls for cross-file reasoning).
44
- - If the block above renders as the literal string `{{changedFiles}}`
45
- (i.e. no substitution was supplied), ignore this section entirely and
46
- proceed with the full codebase-wide scan defined in the remaining
47
- steps.
26
+ ## Execution strategy
27
+
28
+ This is a **heavyweight lens**: dispatch it as a single `subagent_type: auditor`
29
+ call, or fan its dimensions out per-dimension across parallel `auditor`
30
+ subagents (parallel-tooling Rule 3) and merge under the self-cross-check.
31
+ Sequential inline execution is the fallback (see the core's Execution strategy).
48
32
 
49
33
  ## Step 0: Tool-first detection (mandatory — run before any LLM dimension)
50
34
 
@@ -98,8 +82,6 @@ broken) rather than skipping the step silently.
98
82
 
99
83
  ## Step 1: Context Gathering (Read-Only Scan)
100
84
 
101
- > Apply [`helpers/parallel-tooling.md`](helpers/parallel-tooling.md) when batching the scan below — independent reads belong in one turn, long shells run via `run_in_background` + `Monitor`.
102
-
103
85
  Before generating the report, silently scan the core application logic. Pay
104
86
  special attention to:
105
87
 
@@ -142,15 +124,13 @@ Structural Change can be Medium. As a loose default, Quick Wins typically land
142
124
  High (cheap to fix, real payoff) and Structural Changes Medium/High, but grade
143
125
  Impact on the risk itself rather than deriving it mechanically from Category.
144
126
 
145
- > **Ceded to audit-clean-code.** The five clean-code-overlapping dimensions
146
- > this lens historically enumerated Over-Engineering & Abstractions,
147
- > Cognitive Load & Nesting, Dead Code & Redundancy, Naming &
148
- > Self-Documentation, and Coupling & Cohesion — are now owned by
149
- > [`audit-clean-code`](audit-clean-code.md). Do **not** duplicate them here: a
150
- > smell in one of those five belongs in the clean-code report, and the
151
- > dead-export candidates from Step 0 flow into audit-clean-code's Dead Code
152
- > dimension. This lens keeps only the two structural dimensions no other lens
153
- > owns — the testable-surface boundary and the automated-guardrail maturity.
127
+ > **Boundary with `audit-clean-code`.** The clean-code-overlapping smells
128
+ > (over-engineering & abstractions, cognitive load & nesting, dead code &
129
+ > redundancy, naming & self-documentation, coupling & cohesion) are owned by
130
+ > [`audit-clean-code`](audit-clean-code.md); the Step 0 dead-export candidates
131
+ > flow into its Dead Code dimension. Do **not** duplicate them here. This lens
132
+ > keeps only the two structural dimensions no other lens owns the
133
+ > testable-surface boundary and the automated-guardrail maturity.
154
134
 
155
135
  Evaluate the gathered context against the following architecture dimensions:
156
136
 
@@ -220,7 +200,7 @@ Evaluate the gathered context against the following architecture dimensions:
220
200
  harness subsystems under this dimension.
221
201
 
222
202
  **Scope-mode behavior.** When this lens is invoked in Story scope (the
223
- `{{changedFiles}}` block above is populated with a file list), the
203
+ `{{changedFiles}}` fence is populated with a file list), the
224
204
  maturity assessment for this dimension is a repo-wide property that
225
205
  cannot be represented by a small changeset. In that case, render the
226
206
  `Architecture Guardrail Coverage` report section with maturity
@@ -241,98 +221,30 @@ evidence supports.
241
221
  | **Missing** | Neither documented boundaries nor automated checks exist for a codebase whose shape (layered, multi-package, server/client split, feature-sliced) would benefit from them. |
242
222
  | **Not Applicable** | The codebase has no meaningful architectural layering to guard (e.g., a single-package utility repo, a one-file script, a flat content repo). |
243
223
 
244
- ## Step 3: Output Requirements
245
-
246
- Generate and save a highly structured Markdown audit report to
247
- `{{auditOutputDir}}/audit-architecture-results.md`, using the exact template
248
- below.
224
+ ## Report additions
249
225
 
250
- > Grade every finding's severity on the shared
251
- > [`Critical | High | Medium | Low` scale](helpers/audit-severity-scale.md).
226
+ Beyond the shared skeleton (Executive Summary + Detailed Findings from the
227
+ core), this lens's report carries its own title and two lens-specific sections:
252
228
 
253
229
  ```markdown
254
230
  # Architecture & Clean Code Review
255
231
 
256
- ## Executive Summary
257
-
258
- [Provide a brief overview of the codebase's health, highlighting the primary
259
- architectural pain points and areas for simplification.]
260
-
261
232
  ## Triage Summary
262
233
 
263
234
  ### Quick Wins (Low Effort, High Impact)
264
235
 
265
- - [List 2–3 immediate, safe refactors — e.g., deleting dead code, renaming
266
- variables, extracting simple utilities.]
236
+ - [List 2–3 immediate, safe refactors.]
267
237
 
268
238
  ### Structural Changes (Medium/High Effort, Architectural Impact)
269
239
 
270
- - [List 2–3 larger refactors — e.g., decoupling services, flattening complex
271
- module hierarchies, removing unnecessary design patterns.]
240
+ - [List 2–3 larger refactors.]
272
241
 
273
242
  ## Architecture Guardrail Coverage
274
243
 
275
- [Codebase-wide mode: complete this section using the maturity rubric in
276
- Step 2. Story-scoped run: set `Current Maturity` to
277
- `Not Assessed — scoped run` and leave the remaining fields empty or
278
- marked `n/a`.]
279
-
280
244
  - **Current Maturity:** [Strong | Partial | Missing | Not Applicable | Not Assessed — scoped run]
281
- - **Documented Boundaries:** [Files / sections that name the architecture
282
- boundaries — e.g., `docs/architecture.md § Layering`, ADR-0007. State
283
- `none found` if absent.]
284
- - **Automated Checks Found:** [Tooling and config paths — e.g.,
285
- `dependency-cruiser` at `.dependency-cruiser.cjs`,
286
- `eslint-plugin-boundaries` rules in `eslint.config.js`,
287
- `tsconfig.json` `references`. State `none found` if absent.]
288
- - **CI Enforcement:** [Whether a CI job runs the checks and fails the
289
- build on violation — name the workflow file and job. State `not
290
- enforced in CI` if the check runs only locally, or `n/a` if no check
291
- exists.]
292
- - **Axes Covered:** [Tick the axes from Step 2 that have at least one
293
- automated check — layer direction, feature/module boundaries,
294
- server/client separation, workspace package boundaries, public
295
- entrypoints, circular dependencies, forbidden deep imports. Mark
296
- axes that don't apply to this codebase's shape as `n/a`.]
297
- - **Recommended Next Step:** [The single lightest fitting project-local
298
- improvement — e.g., "add `dependency-cruiser` with a
299
- `no-circular` rule and wire `npm run check:arch` into the existing
300
- CI lint job". Advisory only; the consumer project owns adoption. Do
301
- not propose Mandrel-owned harness changes.]
302
-
303
- ## Detailed Findings
304
-
305
- [For every gap identified, use the following strict structure. Lead each title
306
- with the primary file the finding lives in:]
307
-
308
- ### `path/to/primary-file.ext` — [Short title of the issue]
309
-
310
- - **Impact:** [Critical | High | Medium | Low]
311
- - **Category:** [Quick Win | Structural Change]
312
- - **Dimension:** [e.g., Cognitive Load & Nesting | Testable Surface (Humble-Object Boundary) | Automated Architecture Guardrails]
313
- - **Location:** `path/to/primary-file.ext:line`
314
- - **Current State:** [The specific file/function and why it is problematic]
315
- - **Recommendation & Rationale:** [The specific refactor strategy and how it
316
- improves readability or maintainability]
317
- - **Acceptance signal:** [the command or observable that proves this finding is remediated — e.g. a maintainability-index re-check, `npm test`, or a re-run of this lens]
318
- - **Agent Prompt:**
319
- `[A copy-pasteable, highly specific prompt to execute this refactor independently. Must explicitly state NOT to change external APIs.]`
245
+ - **Documented Boundaries / Automated Checks Found / CI Enforcement / Axes Covered / Recommended Next Step:** [per the Maturity Rubric — a single lightest project-local improvement, advisory only, no Mandrel-owned harness changes]
320
246
  ```
321
247
 
322
- ---
323
-
324
- ## Constraint
325
-
326
- Do NOT execute any code modifications, edit files, create branches, or implement
327
- changes. This is strictly a read-only analysis. Ensure all recommendations
328
- preserve existing functionality and external APIs. Output the report and stop.
329
-
330
- ## Self-cross-check (mandatory — filter false positives before you finalize)
331
-
332
- Before you write the report artifact from the previous step, run the shared
333
- adversarial self-cross-check over your Detailed Findings — see
334
- [`helpers/audit-self-check.md`](helpers/audit-self-check.md). It defines the
335
- per-finding evidence bar, the exclusion list, and the final re-open-and-drop
336
- pass whose `kept <k> / dropped <d>` counts you record in the Executive
337
- Summary, so the sequential single-pass path filters unverified findings just as
338
- the orchestrated path's adversarial reviewer does.
248
+ In a Story-scoped run set `Current Maturity` to `Not Assessed — scoped run` and
249
+ mark the remaining fields `n/a`; the full maturity assessment runs only in
250
+ codebase-wide mode.
@@ -4,46 +4,29 @@ description: Audit code smells, dead code, complexity hotspots, and maintainabil
4
4
 
5
5
  # Clean Code & Maintainability Audit
6
6
 
7
- ## Role
7
+ You are a Principal Software Engineer & Code Quality Lead auditing
8
+ maintainability — code smells, technical debt, and clean-code violations (SOLID,
9
+ DRY, KISS) that hinder long-term velocity. The shared lens machinery — read-only
10
+ constraint, scope interpretation, report envelope + finding-block skeleton,
11
+ severity scale, self-cross-check, and execution strategy — lives in
12
+ [`helpers/audit-lens-core.md`](helpers/audit-lens-core.md). Write the report to
13
+ `{{auditOutputDir}}/audit-clean-code-results.md`. The report adds a **Dead Code
14
+ Inventory** table (File / Symbol / Type / Estimated LOC) and a **Technical Debt
15
+ Backlog** section.
8
16
 
9
- Principal Software Engineer & Code Quality Lead
17
+ ## Scope
10
18
 
11
- ## Context & Objective
12
-
13
- You are performing a deep-dive audit into the codebase's maintainability and
14
- quality. Your objective is to identify "code smells," technical debt, and
15
- violations of clean code principles (SOLID, DRY, KISS) that hinder long-term
16
- velocity.
17
-
18
- ## Scope (Story / plan-run mode)
19
-
20
- When this lens is invoked from `/deliver` close lenses (or a plan-run audit), the
21
- following block is populated with the Story (or plan-run) change-set file list.
22
- Otherwise — for any manual `/audit-<dimension>` invocation — the block
23
- renders the literal substitution token and you MUST treat it as **no
24
- scope filter — run the lens codebase-wide** exactly as you would have
25
- before this section existed.
19
+ Interpret this lens's change-set fence per the core's Scope interpretation:
26
20
 
27
21
  ```text
28
22
  {{changedFiles}}
29
23
  ```
30
24
 
31
- - If the block above contains a newline-delimited list of file paths,
32
- restrict your analysis to those files (and their direct dependencies
33
- when the lens explicitly calls for cross-file reasoning).
34
- - If the block above renders as the literal string `{{changedFiles}}`
35
- (i.e. no substitution was supplied), ignore this section entirely and
36
- proceed with the full codebase-wide scan defined in the remaining
37
- steps.
38
-
39
- ## Execution strategy (dual-path)
25
+ ## Execution strategy
40
26
 
41
- This lens runs along one of two execution paths (orchestrated dynamic-workflow
42
- or sequential single-pass). Both emit the **identical** Step 3 report contract;
43
- downstream consumers (`audit-to-stories`) are agnostic to which path produced
44
- it. See [`helpers/audit-dual-path.md`](helpers/audit-dual-path.md) for strategy
45
- selection, the forcing flags, and the read-only guarantee — read `audit-<lens>`
46
- there as this lens's name.
27
+ Run this lens as a single `subagent_type: auditor` dispatch returning the report
28
+ path + Executive Summary; sequential inline execution is the fallback (see the
29
+ core's Execution strategy).
47
30
 
48
31
  ## Step 0: Tool-first detection (mandatory — measure before you judge)
49
32
 
@@ -109,8 +92,6 @@ run the tools first.
109
92
 
110
93
  ## Step 1: Quality Scan
111
94
 
112
- > Apply [`helpers/parallel-tooling.md`](helpers/parallel-tooling.md) when batching the scan below — independent reads belong in one turn, long shells run via `run_in_background` + `Monitor`.
113
-
114
95
  Analyze the repository with a focus on:
115
96
 
116
97
  - **Logic Complexity:** Apply the cyclomatic / Maintainability-Index ceilings
@@ -151,40 +132,15 @@ Analyze the repository with a focus on:
151
132
  6. **Documentation:** Does the code explain "why" through its structure, or does
152
133
  it require extensive comments?
153
134
 
154
- ## Step 3: Output Requirements
155
-
156
- Generate and save a highly structured Markdown audit report to
157
- `{{auditOutputDir}}/audit-clean-code-results.md`, using the exact template
158
- below.
135
+ ## Report additions
159
136
 
160
- > Grade every finding's severity on the shared
161
- > [`Critical | High | Medium | Low` scale](helpers/audit-severity-scale.md).
137
+ Beyond the shared skeleton (Executive Summary + Detailed Findings from the
138
+ core), this lens's report carries its own title, a Dead Code Inventory table,
139
+ and a Technical Debt Backlog:
162
140
 
163
141
  ```markdown
164
142
  # Clean Code Audit Report
165
143
 
166
- ## Executive Summary
167
-
168
- [Brief overview of the codebase's maintainability index (High/Medium/Low) and
169
- primary themes.]
170
-
171
- ## Detailed Findings
172
-
173
- [For every gap identified, use the following strict structure. Lead each title
174
- with the primary file the finding lives in:]
175
-
176
- ### `path/to/primary-file.ext` — [Short title of the issue]
177
-
178
- - **Dimension:** [e.g., SOLID Principles | DRY | KISS | Dead Code]
179
- - **Impact:** [Critical | High | Medium | Low]
180
- - **Location:** `path/to/primary-file.ext:line`
181
- - **Current State:** [Problematic code snippet, file, or pattern description]
182
- - **Recommendation & Rationale:** [The specific refactor strategy and how it
183
- improves long-term velocity]
184
- - **Acceptance signal:** [the command or observable that proves this finding is remediated — e.g. a duplication re-check, `npm test`, or a re-run of this lens]
185
- - **Agent Prompt:**
186
- `[A copy-pasteable, highly specific prompt to execute this refactor independently]`
187
-
188
144
  ## Dead Code Inventory
189
145
 
190
146
  | File | Symbol / Block | Type | Estimated LOC |
@@ -196,18 +152,3 @@ with the primary file the finding lives in:]
196
152
  [List specific files or modules that require significant rework to meet quality
197
153
  standards.]
198
154
  ```
199
-
200
- ## Constraint
201
-
202
- This workflow is **read-only**. Provide the analysis and the roadmap, but do not
203
- apply changes.
204
-
205
- ## Self-cross-check (mandatory — filter false positives before you finalize)
206
-
207
- Before you write the report artifact from the previous step, run the shared
208
- adversarial self-cross-check over your Detailed Findings — see
209
- [`helpers/audit-self-check.md`](helpers/audit-self-check.md). It defines the
210
- per-finding evidence bar, the exclusion list, and the final re-open-and-drop
211
- pass whose `kept <k> / dropped <d>` counts you record in the Executive
212
- Summary, so the sequential single-pass path filters unverified findings just as
213
- the orchestrated path's adversarial reviewer does.
@@ -4,18 +4,20 @@ description: Audit the persistence layer as a first-class artifact — model↔m
4
4
 
5
5
  # Data Model & Persistence Audit
6
6
 
7
- ## Role
8
-
9
- Data Modeler & Database Reliability Engineer
10
-
11
- ## Context & Objective
12
-
13
- Analyze the project's persistence layer — its ORM model definitions, the schema
14
- migrations those definitions are supposed to produce, and the seed data that
15
- populates them — as a first-class artifact. Your goal is to find where the
16
- model, the migrations, and the runtime schema silently disagree, where an
17
- invariant the application assumes is not actually enforced by a constraint, and
18
- where a migration is unsafe to run against a live database.
7
+ You are a Data Modeler & Database Reliability Engineer analyzing the persistence
8
+ layer — ORM model definitions, the migrations they should produce, and the seed
9
+ data as a first-class artifact, finding where model, migrations, and runtime
10
+ schema silently disagree, where an assumed invariant is not enforced by a
11
+ constraint, and where a migration is unsafe against a live database. The shared
12
+ lens machinery — read-only constraint, scope interpretation, report envelope +
13
+ finding-block skeleton, severity scale, self-cross-check, and execution
14
+ strategy lives in
15
+ [`helpers/audit-lens-core.md`](helpers/audit-lens-core.md). Write the report to
16
+ `{{auditOutputDir}}/audit-data-model-results.md`. Dimension values:
17
+ `Drift | Constraint Completeness | Migration Hygiene | Type Fidelity |
18
+ Access-Pattern Fit`; the report adds a **Low-Hanging Fruit** section.
19
+
20
+ ## Applicability
19
21
 
20
22
  This lens is **only applicable to a project that has a persistence layer.** A
21
23
  repository with no ORM dependency, no migrations directory, and no tracked
@@ -28,47 +30,28 @@ by `target: "data-model"` in
28
30
  automatically in `/deliver` and plan-run modes; in a manual invocation you MUST
29
31
  make the same determination yourself before reading anything else.
30
32
 
31
- ## Scope (Story / plan-run mode)
33
+ ## Scope
32
34
 
33
- When this lens is invoked from `/deliver` close lenses (or a plan-run audit), the
34
- following block is populated with the Story (or plan-run) change-set file list.
35
- Otherwisefor any manual `/audit-<dimension>` invocation the block
36
- renders the literal substitution token and you MUST treat it as **no
37
- scope filter run the lens codebase-wide** exactly as you would have
38
- before this section existed.
35
+ Interpret this lens's change-set fence per the core's Scope interpretation. In
36
+ scoped mode, restrict analysis to the changed models and migrations plus their
37
+ **direct dependents** a model related to a changed model, a migration ordered
38
+ after a changed one. A Story that adds a destructive migration is the canonical
39
+ routed case: the change set names the migration and the models it rewrites, and
40
+ this lens inspects exactly that surface.
39
41
 
40
42
  ```text
41
43
  {{changedFiles}}
42
44
  ```
43
45
 
44
- - If the block above contains a newline-delimited list of file paths,
45
- restrict your analysis to those files (and their direct dependencies
46
- when the lens explicitly calls for cross-file reasoning).
47
- - If the block above renders as the literal string `{{changedFiles}}`
48
- (i.e. no substitution was supplied), ignore this section entirely and
49
- proceed with the full codebase-wide scan defined in the remaining
50
- steps.
51
-
52
- ## Execution strategy (dual-path)
53
-
54
- This lens runs along one of two execution paths (orchestrated dynamic-workflow
55
- or sequential single-pass). Both emit the **identical** Step 3 report contract;
56
- downstream consumers (`audit-to-stories`) are agnostic to which path produced
57
- it. See [`helpers/audit-dual-path.md`](helpers/audit-dual-path.md) for strategy
58
- selection, the forcing flags, and the read-only guarantee — read `audit-<lens>`
59
- there as this lens's name.
60
-
61
- In scoped mode, restrict analysis to the changed models and migrations plus
62
- their **direct dependents** — a model related to a changed model, a migration
63
- ordered after a changed one. A Story that adds a destructive migration is the
64
- canonical routed case: the change set names the migration and the models it
65
- rewrites, and this lens inspects exactly that surface.
46
+ ## Execution strategy
66
47
 
67
- ## Step 1: Applicability & Persistence-Surface Discovery
48
+ Run this lens as a single `subagent_type: auditor` dispatch returning the report
49
+ path + Executive Summary; sequential inline execution is the fallback (see the
50
+ core's Execution strategy).
68
51
 
69
- > Apply [`helpers/parallel-tooling.md`](helpers/parallel-tooling.md) when batching the scan below — independent reads belong in one turn, long shells run via `run_in_background` + `Monitor`.
52
+ ## Step 1: Applicability & Persistence-Surface Discovery
70
53
 
71
- First confirm the project **has a persistence layer** (see Context above). If it
54
+ First confirm the project **has a persistence layer** (see Applicability). If it
72
55
  does not, stop and emit the not-applicable report. If it does, discover the
73
56
  persistence surface, preferring **tool-first** detection over hand-reading where
74
57
  the consumer ships the tooling:
@@ -118,51 +101,10 @@ Evaluate the persistence layer along these five dimensions:
118
101
  force N+1 access, and soft-delete rows that leak through default queries
119
102
  because no default scope excludes them.
120
103
 
121
- ## Step 3: Output Requirements
122
-
123
- Generate and save a highly structured Markdown audit report to
124
- `{{auditOutputDir}}/audit-data-model-results.md`, using the exact template
125
- below.
126
-
127
- > Grade every finding's severity on the shared
128
- > [`Critical | High | Medium | Low` scale](helpers/audit-severity-scale.md).
129
-
130
- When the project **has a persistence layer**, use the findings template:
131
-
132
- ```markdown
133
- # Data Model & Persistence Audit Report
134
-
135
- ## Executive Summary
104
+ ## Not-applicable report
136
105
 
137
- [Overview of the persistence layer's health, plus the `kept <k> / dropped <d>`
138
- self-cross-check counts from the mandatory step below.]
139
-
140
- ## Detailed Findings
141
-
142
- [For every issue identified, use the following strict structure. Lead each
143
- title with the primary file the issue lives in:]
144
-
145
- ### `path/to/migration-or-model.ext` — [Short title of the issue]
146
-
147
- - **Dimension:** [e.g., Drift | Constraint Completeness | Migration Hygiene | Type Fidelity | Access-Pattern Fit]
148
- - **Impact:** [Critical | High | Medium | Low]
149
- - **Location:** `path/to/migration-or-model.ext:line`
150
- - **Current State:** [Technical explanation of the drift, missing constraint,
151
- or unsafe migration step — cite the model definition and the migration it
152
- disagrees with]
153
- - **Recommendation & Rationale:** [The specific corrective migration or
154
- constraint, and the failure it prevents]
155
- - **Acceptance signal:** [the command or observable that proves this finding is remediated — e.g. `prisma migrate status` clean, a constraint present in the schema, or a re-run of this lens]
156
- - **Agent Prompt:**
157
- `[A copy-pasteable, highly specific prompt to execute this fix independently]`
158
-
159
- ## Low-Hanging Fruit
160
-
161
- - [List up to 3 low-risk schema/constraint fixes that provide immediate safety gains.]
162
- ```
163
-
164
- When the project has **no persistence layer**, emit the explicit
165
- not-applicable report instead — never empty findings — and stop:
106
+ When the project has **no persistence layer**, emit this explicit report instead
107
+ of empty findings and stop:
166
108
 
167
109
  ```text
168
110
  # Data Model & Persistence Audit Report
@@ -178,21 +120,11 @@ data-model lens has nothing to inspect and was skipped.
178
120
  _None — lens not applicable._
179
121
  ```
180
122
 
181
- ## Constraint
123
+ ## Constraint (lens-specific carve-out)
182
124
 
183
- This is a **read-only** audit over repo-observable state only — schema files,
125
+ This lens is read-only over **repo-observable state only** — schema files,
184
126
  migrations, ORM config, and read-only ORM drift/status commands. It MUST NOT
185
127
  connect to, read from, or mutate a production database; it MUST NOT run a
186
128
  migration or a destructive ORM command. API-contract/serialization coverage is
187
129
  out of scope (deferred `audit-contract-compat` territory), and runtime query
188
130
  profiling belongs to `audit-performance`, which owns measured behavior.
189
-
190
- ## Self-cross-check (mandatory — filter false positives before you finalize)
191
-
192
- Before you write the report artifact from the previous step, run the shared
193
- adversarial self-cross-check over your Detailed Findings — see
194
- [`helpers/audit-self-check.md`](helpers/audit-self-check.md). It defines the
195
- per-finding evidence bar, the exclusion list, and the final re-open-and-drop
196
- pass whose `kept <k> / dropped <d>` counts you record in the Executive
197
- Summary, so the sequential single-pass path filters unverified findings just as
198
- the orchestrated path's adversarial reviewer does.