@grimoire-cc/cli 0.7.0 → 0.7.2
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/packs/dev-pack/agents/gr.tdd-specialist.md +1 -1
- package/packs/docs-pack/skills/gr.business-logic-docs/SKILL.md +155 -18
- package/packs/docs-pack/skills/gr.business-logic-docs/references/audit-checklist.md +48 -0
- package/packs/docs-pack/skills/gr.business-logic-docs/references/tier2-template.md +56 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: grimoire:tdd-specialist
|
|
3
3
|
description: "Language-agnostic TDD and unit testing specialist. Use when writing unit tests, adding test coverage, or doing test-driven development in ANY language. Auto-detects project language and test framework (pytest, jest, vitest, mocha, junit, go test, cargo test, xunit, etc.). Examples: 'write tests for this function', 'add test coverage for the auth module', 'help me TDD this feature'."
|
|
4
4
|
tools: Read, Edit, Write, Grep, Glob, Skill, Bash
|
|
5
|
-
model:
|
|
5
|
+
model: inherit
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# TDD Specialist Agent
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: grimoire:business-logic-docs
|
|
3
|
-
description: "Create and
|
|
3
|
+
description: "Create, update, and audit structured business logic documentation for AI assistants and developers. Use when documenting business rules, domain knowledge, invariants, workflows, state machines, entity relationships, decision logs, building a business logic knowledge base, or reviewing docs for staleness."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Business Logic Documentation
|
|
7
7
|
|
|
8
|
-
Guide Claude through creating and
|
|
8
|
+
Guide Claude through creating, updating, and auditing a structured knowledge base of a project's business logic. The knowledge base serves two audiences: AI coding assistants (so they understand domain context and make better decisions) and human developers (so they can recall and reason about business rules).
|
|
9
9
|
|
|
10
10
|
All generated documentation lives in `docs/business-logic/` by default. Ask the developer if they prefer a different path before generating.
|
|
11
11
|
|
|
12
|
+
**Core principle: business rules drive code, not vice versa.** Business logic documentation captures decisions that drive code changes — not descriptions of what code does. The flow is always: business decision → documentation → code implementation.
|
|
13
|
+
|
|
12
14
|
## Workflow 1 — Create the Initial Knowledge Base
|
|
13
15
|
|
|
14
16
|
Use this when a project has no business logic docs yet.
|
|
@@ -31,8 +33,9 @@ Surface business rules that aren't obvious from code alone. Ask focused question
|
|
|
31
33
|
1. **Domain terminology** — "What terms does your team use that have precise meanings? Any terms that are commonly confused?"
|
|
32
34
|
2. **User roles and permissions** — "What roles exist, and what can each role do or not do?"
|
|
33
35
|
3. **Critical invariants** — "What must always be true? What must never happen?"
|
|
34
|
-
4. **
|
|
35
|
-
5. **
|
|
36
|
+
4. **Hard constraints** — "What things MUST NEVER happen in the system? What would cause the most damage if violated?"
|
|
37
|
+
5. **Non-obvious edge cases** — "What scenarios have caused bugs or confusion before?"
|
|
38
|
+
6. **Regulatory or legal rules** — "Are any business rules driven by compliance requirements?"
|
|
36
39
|
|
|
37
40
|
After each batch of answers, ask follow-up questions if something needs clarification. Move to the next domain area once coverage feels sufficient.
|
|
38
41
|
|
|
@@ -41,7 +44,7 @@ After each batch of answers, ask follow-up questions if something needs clarific
|
|
|
41
44
|
Create the three-tier structure described below. For each domain area identified:
|
|
42
45
|
|
|
43
46
|
1. Create the Tier 2 file using the template from [references/tier2-template.md](references/tier2-template.md)
|
|
44
|
-
2. Fill in what you learned from code analysis
|
|
47
|
+
2. Fill in what you learned from the interview. For rules surfaced from code analysis (not confirmed by the developer), mark with `[SOURCE: code-audit — unconfirmed]` — these MUST be confirmed before being treated as business rules.
|
|
45
48
|
3. Mark sections where information is incomplete with `<!-- TODO: clarify with team -->`
|
|
46
49
|
|
|
47
50
|
Then create the `_overview.md` (Tier 1) and `_decision-log.md` (Tier 3) files.
|
|
@@ -52,17 +55,104 @@ Add a reference to the knowledge base in the project's `CLAUDE.md` (create one i
|
|
|
52
55
|
|
|
53
56
|
## Workflow 2 — Update the Existing Knowledge Base
|
|
54
57
|
|
|
55
|
-
Use this when business logic changes.
|
|
58
|
+
Use this when business logic changes. Updates are driven by text input — user stories, change requests, discussion transcripts/summaries — not by code analysis.
|
|
59
|
+
|
|
60
|
+
### Step 1: Understand the Change
|
|
61
|
+
|
|
62
|
+
Read the provided input (user story, change request, discussion transcript/summary). Extract:
|
|
63
|
+
|
|
64
|
+
- What business rules are being added, modified, or removed
|
|
65
|
+
- Which domain area(s) and Tier 2 file(s) are affected
|
|
66
|
+
|
|
67
|
+
Do NOT look at code to infer business rules — the provided input is the single source of truth. If the input is ambiguous or incomplete, ask the user for clarification before proceeding.
|
|
68
|
+
|
|
69
|
+
### Step 2: Review Existing Documentation
|
|
70
|
+
|
|
71
|
+
Read the affected Tier 2 file(s). For each change from Step 1, check:
|
|
72
|
+
|
|
73
|
+
- Does it contradict any existing rule?
|
|
74
|
+
- Does it modify an existing rule or add a new one?
|
|
75
|
+
- Does it affect workflows, entities, or integration points?
|
|
76
|
+
- Does it invalidate any existing constraints, examples, or counterexamples?
|
|
77
|
+
|
|
78
|
+
Flag any conflicts or ambiguities to the user before making changes.
|
|
79
|
+
|
|
80
|
+
### Step 3: Clarify Uncertainties
|
|
81
|
+
|
|
82
|
+
If anything from the input is unclear, contradicts existing docs, or leaves gaps, ask the user targeted questions. Examples:
|
|
83
|
+
|
|
84
|
+
- "The user story says X, but the current docs say Y — which is correct?"
|
|
85
|
+
- "This change implies Z — is that intended?"
|
|
86
|
+
- "Are there edge cases for this new rule?"
|
|
87
|
+
- "Does this replace the existing rule or add a new exception?"
|
|
88
|
+
|
|
89
|
+
NEVER proceed with uncertain information. NEVER fill gaps by guessing from code.
|
|
90
|
+
|
|
91
|
+
### Step 4: Apply the Updates
|
|
92
|
+
|
|
93
|
+
Only add information you are certain about from the provided input.
|
|
94
|
+
|
|
95
|
+
- **Modified rules**: Replace the old rule with the new one. Don't annotate what changed — git tracks history.
|
|
96
|
+
- **New rules**: Use the template format from [references/tier2-template.md](references/tier2-template.md). Include Source marker.
|
|
97
|
+
- **Removed rules**: Delete them. Only keep a note about the removal if it carries business context that other rules depend on (e.g., "we no longer support gift cards" is useful if other rules reference gift cards).
|
|
98
|
+
- **New domain areas**: Create a new Tier 2 file and add it to the table of contents in `_overview.md`.
|
|
99
|
+
- **"Enforced in" fields**: Leave empty or mark with `<!-- TODO: add code location after implementation -->` — code locations are filled in after implementation, not before.
|
|
100
|
+
- **Diagrams and glossary**: Update as needed to reflect changes.
|
|
101
|
+
|
|
102
|
+
### Step 5: Validate and Present
|
|
103
|
+
|
|
104
|
+
Verify:
|
|
105
|
+
|
|
106
|
+
- No contradictions introduced across files
|
|
107
|
+
- Diagrams reflect the changes
|
|
108
|
+
- Table of contents is accurate
|
|
109
|
+
- Terminology is consistent with the glossary
|
|
110
|
+
- Decision log entry added if the change involves a non-obvious decision
|
|
111
|
+
|
|
112
|
+
Present a summary to the user showing exactly what was changed and why, so they can confirm accuracy.
|
|
113
|
+
|
|
114
|
+
## Workflow 3 — Audit Knowledge Base
|
|
115
|
+
|
|
116
|
+
Use only when the user explicitly requests an audit or review of existing documentation.
|
|
117
|
+
|
|
118
|
+
This is the one workflow where code comparison is appropriate — but only to flag potential gaps, never to infer new business rules.
|
|
119
|
+
|
|
120
|
+
### Step 1: Review Documentation Completeness
|
|
56
121
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
122
|
+
Check for structural issues using [references/audit-checklist.md](references/audit-checklist.md):
|
|
123
|
+
|
|
124
|
+
- Unresolved `<!-- TODO -->` markers
|
|
125
|
+
- Empty or placeholder sections
|
|
126
|
+
- Rules missing "Why" explanations
|
|
127
|
+
- Critical rules without counterexamples
|
|
128
|
+
- Constraints section empty or missing
|
|
129
|
+
|
|
130
|
+
### Step 2: Check Code Alignment
|
|
131
|
+
|
|
132
|
+
**Only when the user explicitly asks to compare docs against code.** Check:
|
|
133
|
+
|
|
134
|
+
- "Enforced in" references still point to existing code
|
|
135
|
+
- State diagram transitions match actual code behavior
|
|
136
|
+
- Entity attributes match current schema
|
|
137
|
+
|
|
138
|
+
Flag undocumented code behavior as questions, not assertions: "This code seems to enforce X, but it's not documented — is this a business rule that should be captured?" Mark any rules surfaced this way with `[SOURCE: code-audit — unconfirmed]`.
|
|
139
|
+
|
|
140
|
+
### Step 3: Check Terminology Consistency
|
|
141
|
+
|
|
142
|
+
- Extract all glossary terms from `_overview.md`
|
|
143
|
+
- Search Tier 2 files for inconsistent usage (synonyms, abbreviations, variant spellings)
|
|
144
|
+
- Report inconsistencies in the format described in [references/audit-checklist.md](references/audit-checklist.md)
|
|
145
|
+
|
|
146
|
+
### Step 4: Produce Audit Report
|
|
147
|
+
|
|
148
|
+
Structured output with sections:
|
|
149
|
+
|
|
150
|
+
1. **Incomplete Items** — Missing Why, missing examples, empty sections, unresolved TODOs
|
|
151
|
+
2. **Terminology Issues** — Inconsistent term usage across files
|
|
152
|
+
3. **Structural Issues** — ToC mismatches, missing template sections, duplicated rules
|
|
153
|
+
4. **Potential Documentation Gaps** *(only if Step 2 was performed)* — Code behavior not reflected in docs
|
|
154
|
+
|
|
155
|
+
Ask the developer to review and confirm before making any changes.
|
|
66
156
|
|
|
67
157
|
## Three-Tier Documentation Structure
|
|
68
158
|
|
|
@@ -82,8 +172,10 @@ E.g., `orders.md`, `payments.md`, `inventory.md`. Each follows the template in [
|
|
|
82
172
|
|
|
83
173
|
- **Purpose** — What this area does and why it exists.
|
|
84
174
|
- **Key Entities** — Core entities, attributes, relationships. Use mermaid for non-trivial relationships.
|
|
85
|
-
- **
|
|
175
|
+
- **Constraints** — The highest-value content. MUST and MUST NOT rules with business reasons.
|
|
176
|
+
- **Business Rules & Invariants** — Each rule states: what the rule is, why it exists (the business reason), where it's enforced in code, a concrete example including an edge case, and for critical rules a counterexample.
|
|
86
177
|
- **Workflows & State Transitions** — Key processes with mermaid state diagrams for anything with 3+ states. Specify triggers and validations.
|
|
178
|
+
- **Decision Trees** — Sequential if-then format for multi-branch conditional logic.
|
|
87
179
|
- **Integration Points** — External systems, APIs, other domain areas. Note contracts and assumptions.
|
|
88
180
|
- **Edge Cases & Known Gotchas** — Non-obvious behaviors that have caused bugs or confusion.
|
|
89
181
|
|
|
@@ -96,7 +188,7 @@ Each entry follows:
|
|
|
96
188
|
```markdown
|
|
97
189
|
## YYYY-MM-DD — [Short title]
|
|
98
190
|
**Context:** What situation prompted this decision.
|
|
99
|
-
**Decision:**
|
|
191
|
+
**Decision:** [Chosen option] because [justification], to achieve [desired outcome], accepting [tradeoff].
|
|
100
192
|
**Alternatives considered:** What else was evaluated and why it was rejected.
|
|
101
193
|
**Affected areas:** Which Tier 2 files are impacted.
|
|
102
194
|
```
|
|
@@ -107,7 +199,7 @@ Follow these when writing or updating business logic docs:
|
|
|
107
199
|
|
|
108
200
|
1. **Write for reasoning, not just reading.** Always include the "why" behind a rule. Instead of "Users can't delete invoices," write "Users can't delete invoices because downstream accounting reconciliation depends on invoice immutability. Soft-delete via `deleted_at` is used instead." The causal chain enables correct inferences.
|
|
109
201
|
|
|
110
|
-
2. **Be explicit about invariants.** Things that must always or never be true are the highest-value content. Call them out prominently in every domain area file.
|
|
202
|
+
2. **Be explicit about invariants.** Things that must always or never be true are the highest-value content. Call them out prominently in the Constraints section of every domain area file.
|
|
111
203
|
|
|
112
204
|
3. **Link business concepts to code landmarks.** Don't describe implementation details, but do say "Order state transitions are enforced in `OrderStateMachine` — never manipulate `order.status` directly." This bridges conceptual and concrete.
|
|
113
205
|
|
|
@@ -119,6 +211,49 @@ Follow these when writing or updating business logic docs:
|
|
|
119
211
|
|
|
120
212
|
7. **Group by domain area, not by technical layer.** Everything about orders (validation, state machine, permissions, integrations) goes in `orders.md`, not split across "validations.md" and "permissions.md".
|
|
121
213
|
|
|
214
|
+
8. **Constraints before capabilities.** Document what MUST NOT happen before documenting what should happen. Use explicit RFC-2119 language (MUST, MUST NOT, SHOULD, SHOULD NOT) for rules that carry enforcement weight.
|
|
215
|
+
|
|
216
|
+
9. **Include counterexamples for critical rules.** For every invariant and constraint, show the wrong behavior and why it fails. Format: what the correct behavior is, what the incorrect behavior looks like, and why it matters.
|
|
217
|
+
|
|
218
|
+
10. **Use decision trees for complex conditional logic.** Any logic with 3+ branches MUST use sequential if-then format. Mark mutually exclusive paths explicitly. No prose-only descriptions for multi-branch logic.
|
|
219
|
+
|
|
220
|
+
11. **Mark information sources.** Tag rules with their origin: `[SOURCE: user-story]`, `[SOURCE: discussion]`, `[SOURCE: change-request]`. During audits (Workflow 3 only), rules surfaced from code analysis get `[SOURCE: code-audit — unconfirmed]` and MUST be confirmed with the user before being treated as business rules. Incorrect docs are worse than missing docs.
|
|
221
|
+
|
|
222
|
+
12. **State machines over prose for workflows.** Any process with 3+ states MUST use a mermaid stateDiagram plus a transition table. No prose-only workflow descriptions for stateful processes.
|
|
223
|
+
|
|
224
|
+
## Documentation Clarity
|
|
225
|
+
|
|
226
|
+
Docs describe the current state, not history:
|
|
227
|
+
|
|
228
|
+
- When a rule changes, **replace it** — don't annotate what it used to be. Git tracks history.
|
|
229
|
+
- No "previously was", "changed from X to Y", "before it was" language.
|
|
230
|
+
- Remove rules that no longer apply. Only keep a note about the removal if it carries business context other rules depend on (e.g., "we no longer support gift cards" is useful if other rules reference gift cards).
|
|
231
|
+
- Use `<!-- TODO -->` markers only for genuinely incomplete information that needs user input.
|
|
232
|
+
- Every statement in the docs should describe what IS true right now.
|
|
233
|
+
|
|
234
|
+
## ALWAYS / NEVER
|
|
235
|
+
|
|
236
|
+
### ALWAYS
|
|
237
|
+
|
|
238
|
+
- ALWAYS confirm the output path before generating files
|
|
239
|
+
- ALWAYS include "Why" for every rule and constraint
|
|
240
|
+
- ALWAYS ask for clarification when input is ambiguous or incomplete
|
|
241
|
+
- ALWAYS verify new information doesn't contradict existing rules
|
|
242
|
+
- ALWAYS present a summary of all changes for user confirmation
|
|
243
|
+
- ALWAYS update the Table of Contents when files are added or removed
|
|
244
|
+
- ALWAYS add a decision log entry for non-obvious changes
|
|
245
|
+
- ALWAYS leave "Enforced in" empty when the code location is unknown
|
|
246
|
+
|
|
247
|
+
### NEVER
|
|
248
|
+
|
|
249
|
+
- NEVER guess or infer business rules from code — business rules drive code, not vice versa
|
|
250
|
+
- NEVER add information you are not certain about
|
|
251
|
+
- NEVER proceed when the input contradicts existing documentation — ask first
|
|
252
|
+
- NEVER reverse-engineer business rules from code changes unless the user explicitly requests it
|
|
253
|
+
- NEVER use "previously was" / "changed from X to Y" / history annotations — docs describe current state, git tracks history
|
|
254
|
+
- NEVER leave diagrams contradicting documented transitions
|
|
255
|
+
- NEVER duplicate rules across files — reference the canonical location instead
|
|
256
|
+
|
|
122
257
|
## CLAUDE.md Integration
|
|
123
258
|
|
|
124
259
|
Add (or update) the following section in the project's `CLAUDE.md`:
|
|
@@ -129,6 +264,7 @@ Before modifying business logic, read the relevant file in `docs/business-logic/
|
|
|
129
264
|
When your changes affect business rules, update the corresponding doc in the same commit.
|
|
130
265
|
If no file exists for the domain area, create one following the structure of existing files.
|
|
131
266
|
Start with `docs/business-logic/_overview.md` for domain orientation.
|
|
267
|
+
Rules marked `[SOURCE: code-audit — unconfirmed]` need human confirmation before relying on them.
|
|
132
268
|
```
|
|
133
269
|
|
|
134
270
|
If the developer chose a custom docs path, adjust the paths accordingly.
|
|
@@ -137,5 +273,6 @@ If the developer chose a custom docs path, adjust the paths accordingly.
|
|
|
137
273
|
|
|
138
274
|
- This skill provides guidance for creating documentation, not executable code.
|
|
139
275
|
- The knowledge base captures business rules at a point in time — it requires human input for rules that aren't visible in code.
|
|
276
|
+
- Rules inferred from code (`[SOURCE: code-audit — unconfirmed]`) require human verification before they should be treated as authoritative business rules.
|
|
140
277
|
- Mermaid diagrams may not render in all environments (they work in GitHub, VS Code, and most modern markdown viewers).
|
|
141
278
|
- The decision log is only as valuable as the team's discipline in maintaining it.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Audit Checklist
|
|
2
|
+
|
|
3
|
+
Use this checklist with [Workflow 3 — Audit Knowledge Base](../SKILL.md#workflow-3--audit-knowledge-base).
|
|
4
|
+
|
|
5
|
+
## Code Alignment Checks
|
|
6
|
+
|
|
7
|
+
Only perform when the user explicitly requests code comparison.
|
|
8
|
+
|
|
9
|
+
- [ ] Every "Enforced in" reference points to a file/class/function that still exists
|
|
10
|
+
- [ ] Mermaid state diagrams match actual state transitions in code
|
|
11
|
+
- [ ] Entity attributes listed in docs match the current schema/model definitions
|
|
12
|
+
- [ ] Integration contracts (endpoints, payloads) match actual API implementations
|
|
13
|
+
- [ ] Decision trees match actual conditional logic in code
|
|
14
|
+
|
|
15
|
+
Present findings as questions, not assertions. Example: "This code seems to enforce X, but it's not documented — is this a business rule that should be captured?"
|
|
16
|
+
|
|
17
|
+
## Content Quality Checks
|
|
18
|
+
|
|
19
|
+
- [ ] Every business rule has a "Why" explanation
|
|
20
|
+
- [ ] Critical rules (invariants, constraints) have counterexamples
|
|
21
|
+
- [ ] No unconfirmed `[SOURCE: code-audit — unconfirmed]` markers older than 30 days
|
|
22
|
+
- [ ] Decision trees exist for multi-branch logic (3+ paths)
|
|
23
|
+
- [ ] Constraints section populated with MUST / MUST NOT items
|
|
24
|
+
- [ ] Examples use concrete values, not abstract descriptions
|
|
25
|
+
|
|
26
|
+
## Structural Checks
|
|
27
|
+
|
|
28
|
+
- [ ] Table of Contents in `_overview.md` lists all Tier 2 files
|
|
29
|
+
- [ ] Each Tier 2 file has all template sections (even if marked TODO)
|
|
30
|
+
- [ ] Glossary terms in `_overview.md` are consistent across all files
|
|
31
|
+
- [ ] No business rules duplicated across multiple Tier 2 files
|
|
32
|
+
- [ ] All `<!-- TODO -->` markers reviewed — resolve or confirm still pending
|
|
33
|
+
- [ ] Decision log entries reference correct Tier 2 files in "Affected areas"
|
|
34
|
+
|
|
35
|
+
## Terminology Consistency Check
|
|
36
|
+
|
|
37
|
+
For each term in the glossary:
|
|
38
|
+
|
|
39
|
+
1. Search all Tier 2 files for the term
|
|
40
|
+
2. Search for common synonyms or abbreviations
|
|
41
|
+
3. Flag any file that uses a synonym instead of the glossary term
|
|
42
|
+
4. Check that the term's definition still matches how it's used in context
|
|
43
|
+
|
|
44
|
+
Report format:
|
|
45
|
+
|
|
46
|
+
| Term | Expected | Found | File | Line |
|
|
47
|
+
|---|---|---|---|---|
|
|
48
|
+
| `[glossary term]` | `[glossary term]` | `[synonym found]` | `[file]` | `[line]` |
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# [Domain Area Name]
|
|
2
2
|
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [Purpose](#purpose)
|
|
6
|
+
- [Key Entities](#key-entities)
|
|
7
|
+
- [Constraints](#constraints)
|
|
8
|
+
- [Business Rules & Invariants](#business-rules--invariants)
|
|
9
|
+
- [Workflows & State Transitions](#workflows--state-transitions)
|
|
10
|
+
- [Decision Trees](#decision-trees)
|
|
11
|
+
- [Integration Points](#integration-points)
|
|
12
|
+
- [Edge Cases & Known Gotchas](#edge-cases--known-gotchas)
|
|
13
|
+
|
|
3
14
|
## Purpose
|
|
4
15
|
|
|
5
16
|
One-paragraph summary of what this area does and why it exists.
|
|
@@ -23,14 +34,32 @@ erDiagram
|
|
|
23
34
|
}
|
|
24
35
|
```
|
|
25
36
|
|
|
37
|
+
## Constraints
|
|
38
|
+
|
|
39
|
+
The highest-value content — what MUST and MUST NOT happen in this domain area.
|
|
40
|
+
|
|
41
|
+
### MUST
|
|
42
|
+
|
|
43
|
+
- **Constraint**: State what must always be true.
|
|
44
|
+
- **Why**: Business reason this constraint exists.
|
|
45
|
+
- **Enforced in**: File, class, or function name.
|
|
46
|
+
|
|
47
|
+
### MUST NOT
|
|
48
|
+
|
|
49
|
+
- **Constraint**: State what must never happen.
|
|
50
|
+
- **Why**: Business reason — what goes wrong if violated.
|
|
51
|
+
- **Enforced in**: File, class, or function name.
|
|
52
|
+
|
|
26
53
|
## Business Rules & Invariants
|
|
27
54
|
|
|
28
55
|
Each rule follows this pattern:
|
|
29
56
|
|
|
30
57
|
- **Rule**: State the rule clearly.
|
|
31
58
|
- **Why**: Explain the business reason (this enables AI to reason correctly in adjacent code).
|
|
32
|
-
- **Enforced in**: Point to where in the codebase this is enforced (file, class, or function name).
|
|
59
|
+
- **Enforced in**: Point to where in the codebase this is enforced (file, class, or function name). Leave empty or use `<!-- TODO: add code location after implementation -->` if not yet implemented.
|
|
33
60
|
- **Example**: A concrete scenario illustrating the rule, including at least one edge case.
|
|
61
|
+
- **Counterexample** *(critical rules)*: Show the wrong behavior and why it fails.
|
|
62
|
+
- **Source**: `[SOURCE: user-story]`, `[SOURCE: discussion]`, `[SOURCE: change-request]`, or `[SOURCE: code-audit — unconfirmed]`.
|
|
34
63
|
|
|
35
64
|
---
|
|
36
65
|
|
|
@@ -38,6 +67,8 @@ Each rule follows this pattern:
|
|
|
38
67
|
- **Why**: Downstream logistics systems snapshot the order at shipment time; modifications would cause fulfillment mismatches.
|
|
39
68
|
- **Enforced in**: `OrderStateMachine.validateTransition()` rejects edits on shipped orders.
|
|
40
69
|
- **Example**: A customer tries to change their shipping address 5 minutes after shipment. The system returns a 409 Conflict with instructions to contact support for a redirect request instead.
|
|
70
|
+
- **Counterexample**: If the system allowed edits after shipment, the warehouse would ship to the old address while the customer sees the new one — causing a lost package and a support ticket.
|
|
71
|
+
- **Source**: `[SOURCE: user-story]`
|
|
41
72
|
|
|
42
73
|
## Workflows & State Transitions
|
|
43
74
|
|
|
@@ -61,6 +92,22 @@ stateDiagram-v2
|
|
|
61
92
|
| Pending -> Rejected | Admin rejects | Rejection reason is required |
|
|
62
93
|
| Approved -> Completed | System fulfills | External service confirms fulfillment |
|
|
63
94
|
|
|
95
|
+
## Decision Trees
|
|
96
|
+
|
|
97
|
+
Use sequential if-then format for multi-branch conditional logic. Mark mutually exclusive paths explicitly.
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
IF [condition A]
|
|
101
|
+
THEN [action/outcome 1]
|
|
102
|
+
ELSE IF [condition B] ← mutually exclusive with A
|
|
103
|
+
IF [sub-condition B1]
|
|
104
|
+
THEN [action/outcome 2]
|
|
105
|
+
ELSE
|
|
106
|
+
THEN [action/outcome 3]
|
|
107
|
+
ELSE ← default / fallback
|
|
108
|
+
THEN [action/outcome 4]
|
|
109
|
+
```
|
|
110
|
+
|
|
64
111
|
## Integration Points
|
|
65
112
|
|
|
66
113
|
External systems, APIs, webhooks, or other domain areas this module interacts with. Note any contracts or assumptions.
|
|
@@ -72,3 +119,11 @@ External systems, APIs, webhooks, or other domain areas this module interacts wi
|
|
|
72
119
|
Non-obvious behaviors that have caused bugs or confusion before. These are extremely high-value for AI assistants.
|
|
73
120
|
|
|
74
121
|
- **[Gotcha title]**: Description of the non-obvious behavior, why it exists, and what to watch out for when modifying related code.
|
|
122
|
+
|
|
123
|
+
<!--
|
|
124
|
+
Staleness markers — use these in comments to flag items for review:
|
|
125
|
+
|
|
126
|
+
<!-- TODO: clarify with team -->
|
|
127
|
+
<!-- TODO: add code location after implementation -->
|
|
128
|
+
<!-- STALE? last verified YYYY-MM-DD — needs review -->
|
|
129
|
+
-->
|