@kiwidata/grimoire 0.1.4 → 0.1.6

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 (112) hide show
  1. package/.claude-plugin/plugin.json +2 -2
  2. package/AGENTS.md +21 -25
  3. package/LICENSE +36 -0
  4. package/README.md +86 -61
  5. package/dist/cli/index.js +2 -43
  6. package/dist/cli/index.js.map +1 -1
  7. package/dist/cli/program.d.ts +4 -0
  8. package/dist/cli/program.d.ts.map +1 -0
  9. package/dist/cli/program.js +45 -0
  10. package/dist/cli/program.js.map +1 -0
  11. package/dist/commands/configure.d.ts.map +1 -1
  12. package/dist/commands/configure.js +2 -1
  13. package/dist/commands/configure.js.map +1 -1
  14. package/dist/core/check.d.ts.map +1 -1
  15. package/dist/core/check.js +47 -11
  16. package/dist/core/check.js.map +1 -1
  17. package/dist/core/ci.d.ts.map +1 -1
  18. package/dist/core/ci.js +2 -2
  19. package/dist/core/ci.js.map +1 -1
  20. package/dist/core/doc-style.d.ts.map +1 -1
  21. package/dist/core/doc-style.js +76 -0
  22. package/dist/core/doc-style.js.map +1 -1
  23. package/dist/core/docs.d.ts.map +1 -1
  24. package/dist/core/docs.js +93 -74
  25. package/dist/core/docs.js.map +1 -1
  26. package/dist/core/health.d.ts +6 -0
  27. package/dist/core/health.d.ts.map +1 -1
  28. package/dist/core/health.js +78 -21
  29. package/dist/core/health.js.map +1 -1
  30. package/dist/core/hooks.d.ts.map +1 -1
  31. package/dist/core/hooks.js +17 -19
  32. package/dist/core/hooks.js.map +1 -1
  33. package/dist/core/list.d.ts.map +1 -1
  34. package/dist/core/list.js +4 -7
  35. package/dist/core/list.js.map +1 -1
  36. package/dist/core/pr.d.ts.map +1 -1
  37. package/dist/core/pr.js +0 -8
  38. package/dist/core/pr.js.map +1 -1
  39. package/dist/core/risk-register.d.ts +17 -0
  40. package/dist/core/risk-register.d.ts.map +1 -0
  41. package/dist/core/risk-register.js +73 -0
  42. package/dist/core/risk-register.js.map +1 -0
  43. package/dist/core/shared-setup.d.ts.map +1 -1
  44. package/dist/core/shared-setup.js +5 -4
  45. package/dist/core/shared-setup.js.map +1 -1
  46. package/dist/core/status.d.ts.map +1 -1
  47. package/dist/core/status.js +3 -3
  48. package/dist/core/status.js.map +1 -1
  49. package/dist/core/trace.d.ts.map +1 -1
  50. package/dist/core/trace.js +37 -35
  51. package/dist/core/trace.js.map +1 -1
  52. package/dist/core/update.d.ts.map +1 -1
  53. package/dist/core/update.js +1 -10
  54. package/dist/core/update.js.map +1 -1
  55. package/dist/index.d.ts +0 -3
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +0 -3
  58. package/dist/index.js.map +1 -1
  59. package/package.json +19 -2
  60. package/skills/grimoire-apply/SKILL.md +40 -37
  61. package/skills/grimoire-audit/SKILL.md +4 -1
  62. package/skills/grimoire-bug/SKILL.md +7 -3
  63. package/skills/grimoire-commit/SKILL.md +1 -1
  64. package/skills/grimoire-design/SKILL.md +3 -3
  65. package/skills/grimoire-discover/SKILL.md +77 -110
  66. package/skills/grimoire-draft/SKILL.md +55 -18
  67. package/skills/grimoire-plan/SKILL.md +58 -52
  68. package/skills/grimoire-pr/SKILL.md +7 -8
  69. package/skills/grimoire-pr-review/SKILL.md +2 -1
  70. package/skills/grimoire-refactor/SKILL.md +3 -3
  71. package/skills/grimoire-review/SKILL.md +13 -1
  72. package/skills/grimoire-verify/SKILL.md +19 -7
  73. package/skills/grimoire-vuln-remediate/SKILL.md +107 -0
  74. package/skills/grimoire-vuln-triage/SKILL.md +109 -0
  75. package/skills/references/artifact-map.md +44 -0
  76. package/skills/references/code-quality.md +41 -9
  77. package/skills/references/container-scan-triage.md +102 -0
  78. package/skills/references/dependency-vuln-triage.md +236 -0
  79. package/skills/references/principles.md +82 -0
  80. package/skills/references/refactor-scan-categories.md +2 -2
  81. package/skills/references/review-personas.md +13 -6
  82. package/skills/references/test-baseline.md +55 -0
  83. package/skills/references/testing-contracts.md +1 -1
  84. package/templates/accepted-risks.yml +47 -0
  85. package/templates/constraints.md +25 -0
  86. package/dist/commands/archive.d.ts +0 -3
  87. package/dist/commands/archive.d.ts.map +0 -1
  88. package/dist/commands/archive.js +0 -22
  89. package/dist/commands/archive.js.map +0 -1
  90. package/dist/commands/log.d.ts +0 -3
  91. package/dist/commands/log.d.ts.map +0 -1
  92. package/dist/commands/log.js +0 -15
  93. package/dist/commands/log.js.map +0 -1
  94. package/dist/commands/map.d.ts +0 -3
  95. package/dist/commands/map.d.ts.map +0 -1
  96. package/dist/commands/map.js +0 -16
  97. package/dist/commands/map.js.map +0 -1
  98. package/dist/core/archive.d.ts +0 -9
  99. package/dist/core/archive.d.ts.map +0 -1
  100. package/dist/core/archive.js +0 -81
  101. package/dist/core/archive.js.map +0 -1
  102. package/dist/core/log.d.ts +0 -8
  103. package/dist/core/log.d.ts.map +0 -1
  104. package/dist/core/log.js +0 -140
  105. package/dist/core/log.js.map +0 -1
  106. package/dist/core/map.d.ts +0 -22
  107. package/dist/core/map.d.ts.map +0 -1
  108. package/dist/core/map.js +0 -365
  109. package/dist/core/map.js.map +0 -1
  110. package/templates/dupignore +0 -93
  111. package/templates/mapignore +0 -58
  112. package/templates/mapkeys +0 -65
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: grimoire-discover
3
- description: Generate area docs and data schema from a codebase snapshot. Use when initializing grimoire on an existing project or when codebase structure has changed significantly.
3
+ description: Generate intent-focused area docs and data schema by querying the codebase graph. Use when initializing grimoire on an existing project or when an area's intent/boundaries have changed.
4
4
  compatibility: Designed for Claude Code (or similar products)
5
5
  metadata:
6
6
  author: kiwi-data
@@ -9,13 +9,15 @@ metadata:
9
9
 
10
10
  # grimoire-discover
11
11
 
12
- Generate a structured project map in `.grimoire/docs/` from a codebase snapshot. This map helps LLMs understand the codebase layout, find reusable code, and follow existing patterns preventing duplicate code and misplaced files.
12
+ Generate **intent-focused** area docs and a data schema in `.grimoire/docs/`. Area docs capture what the graph can't know an area's *purpose, boundaries, and conventions* — and point at the codebase-memory-mcp graph for everything structural (symbols, key files, call graphs, reusable code). The graph is the live source of structure; discover does not freeze it into a doc that drifts.
13
13
 
14
14
  ## Triggers
15
- - User wants to document or map the codebase structure
16
- - User asks about coding standards, patterns, or conventions
17
- - User wants to prevent duplicate code or find existing utilities
18
- - Loose match: "discover", "map", "standards", "conventions", "DRY", "utilities", "codebase layout"
15
+ - User wants to document an area's purpose, boundaries, or conventions
16
+ - User asks about coding standards or where new code of a type should go
17
+ - User is onboarding an existing project to grimoire
18
+ - Loose match: "discover", "standards", "conventions", "boundaries", "onboard codebase"
19
+
20
+ Note: "find existing utilities", "what calls what", "codebase layout/structure" are **graph** queries, not discover — use codebase-memory-mcp (`search_graph`, `get_architecture`, `trace_path`) directly.
19
21
 
20
22
  ## Routing
21
23
  - Want to document existing behavior as Gherkin features → `grimoire-audit`
@@ -24,85 +26,63 @@ Generate a structured project map in `.grimoire/docs/` from a codebase snapshot.
24
26
 
25
27
  ## Prerequisites
26
28
 
27
- **Structural snapshot:** Run `grimoire map` first. This produces `.grimoire/docs/.snapshot.json` a structural scan of the directory tree, key files, and file extension counts. The snapshot is the input for directory structure; this skill adds the semantic layer.
28
-
29
- If `.snapshot.json` doesn't exist or is stale, tell the user to run `grimoire map` (or `grimoire map --refresh` to diff against existing docs).
30
-
31
- **Symbol intelligence (recommended):** If `codebase-memory-mcp` is available as an MCP server, use its graph tools (`search_graph`, `get_architecture`, `query_graph`) to query symbols, call graphs, and architecture instead of reading source files manually. This provides AST-parsed symbols across 66 languages, call-path tracing, and dead code detection — far more accurate than regex extraction.
29
+ **The codebase graph is the structure source.** `codebase-memory-mcp` should be indexed for this project discover reads directory layout, symbols, key files, and call graphs from it (`get_architecture`, `search_graph`, `trace_path`), not from a filesystem snapshot. There is no `grimoire map` step and no `.snapshot.json` (both retired).
32
30
 
33
- If `codebase-memory-mcp` is not available, fall back to reading source files directly to identify symbols and patterns.
31
+ If `codebase-memory-mcp` is not indexed, run `index_repository` first. Only if the graph is genuinely unavailable, fall back to reading source files directly to identify boundaries and conventions.
34
32
 
35
33
  ## What It Produces
36
34
 
37
35
  `.grimoire/docs/` with:
38
- - **`index.yml`** — master index of all documented areas with descriptions and directory mappings
39
- - **Area docs** — one markdown file per area of the codebase, each covering:
40
- - Purpose and boundaries of the module/area
41
- - Key files and their responsibilities
42
- - Reusable utilities, helpers, and shared functions (the "reuse inventory")
43
- - Naming conventions and patterns in use
36
+ - **`index.yml`** — registry of documented areas (descriptions + directory mappings) and the functional-story map that groups capabilities in the OVERVIEW
37
+ - **Area docs** — one markdown file per significant area, **intent only**:
38
+ - Purpose of the area
39
+ - Boundaries (what belongs here, what doesn't, where related code lives)
40
+ - Conventions (naming + structural patterns, with example file references)
44
41
  - Where new code of this type should go
45
- - Example references (point to specific files as exemplars, don't duplicate code)
46
-
47
- ## Workflow
48
-
49
- ### 1. Load Snapshot and Graph
50
- Read `.grimoire/docs/.snapshot.json`. This gives you:
51
- - **directories** — every directory with file counts, extensions, key files, and subdirectories
52
- - **keyFiles** — significant files (entry points, configs, route files, etc.) with their detected type
53
- - **undocumented** — directories not yet covered by existing docs (only present on `--refresh`)
54
- - **removed** — directories that have docs but no longer exist (only present on `--refresh`)
55
42
 
56
- Use this as your roadmap. The snapshot tells you WHERE to look; you add WHAT it means.
43
+ Area docs do NOT contain Key Files, a reusable-code inventory, or duplicate listings — those are structure, and the graph regenerates them live on demand (and would drift if frozen here). When a reader needs symbols or reuse candidates, they query the graph, not the doc.
57
44
 
58
- If the snapshot includes a `duplicates` section (from `grimoire map --duplicates`), use it to populate "Known Duplicates" sections in area docs. This tells the plan skill where code is already duplicated so it can consolidate rather than add more.
45
+ ## Workflow
59
46
 
60
- **If `codebase-memory-mcp` is available**, also query the graph for each area:
61
- - `search_graph` find all symbols (functions, classes, types) in a directory
62
- - `trace_call_path` — understand how modules connect (inbound/outbound calls)
63
- - `get_architecture` — get a high-level module/dependency overview
64
- - `query_graph` — Cypher-like queries for specific relationships (e.g., `MATCH (f:Function)-[:CALLS]->(g) WHERE f.file STARTS WITH 'src/api/' RETURN f.name, g.name`)
47
+ ### 1. Load the Graph
48
+ Query `codebase-memory-mcp` to understand the codebase live:
49
+ - `get_architecture` — high-level module/dependency overview and directory layout (your roadmap of WHERE the areas are)
50
+ - `search_graph` — symbols (functions, classes, types) in a directory, with signatures
51
+ - `trace_path` — how modules connect (inbound/outbound calls)
52
+ - `query_graph` — specific relationships (e.g., `MATCH (f:Function)-[:CALLS]->(g) WHERE f.file STARTS WITH 'src/api/' RETURN f.name, g.name`)
65
53
 
66
- This replaces the need to manually read every source file to extract symbols. The graph gives you AST-accurate function signatures, call relationships, and dead code detection across 66 languages.
54
+ The graph gives AST-accurate structure across many languages. You use it to *understand* each area so you can write its intent doc — you do NOT copy its output into the doc (that's what regenerating live avoids).
67
55
 
68
56
  ### 2. Determine Scope
69
57
  Ask the user what to document (or accept the scope passed in by a calling skill):
70
- - **Full scan** — document all areas from the snapshot (default for first run)
58
+ - **Full scan** — document all significant areas (default for first run); use `get_architecture` to enumerate them
71
59
  - **Area scan** — document specific directories (e.g., "just the API layer")
72
- - **Gap fill** — only document areas flagged as `undocumented` in the snapshot
73
- - **Targeted refresh** — a list of directories is passed in (from `grimoire-precommit-review` doc freshness check or `grimoire-plan` staleness gate). Skip the full snapshot walk. Go directly to step 3 for each named directory, regenerate only those area docs, and update their `last_updated` entries in `index.yml`. This is the fast-path mode for post-change maintenance — it does not touch areas outside the passed list.
60
+ - **Targeted refresh** — a list of directories is passed in (e.g. from `grimoire-plan`'s staleness gate). Regenerate only those area docs and update their `last_updated` entries in `index.yml`. Fast-path for when an area's *intent* changed; does not touch areas outside the passed list.
74
61
 
75
- Check `.grimoire/docs/index.yml` if it exists — don't redo work unless refreshing.
62
+ Check `.grimoire/docs/index.yml` if it exists — don't redo work unless refreshing. Remember discover runs when **intent** changes (new area, shifted boundary), not on every code change — structure is always live from the graph.
76
63
 
77
64
  ### 3. Analyze Each Area
78
- For each directory cluster in the snapshot, read the actual code to understand:
79
-
80
- **From the snapshot (already known):**
81
- - Directory path and file counts
82
- - File extensions (tells you the language/type mix)
83
- - Key files (tells you what framework patterns are in use)
84
-
85
- **From `codebase-memory-mcp` graph (if available):**
86
- - All symbols in the area: functions, classes, types, constants with signatures
87
- - Call graph: what calls what, both inbound and outbound
88
- - Dead code: functions with zero callers
89
- - Cross-service HTTP links: REST routes and their callers
90
-
91
- **From reading the code (your job — or to supplement the graph):**
92
- - What the module/area is responsible for
93
- - Reusable functions, classes, utilities that other code should import
94
- - Naming conventions and structural patterns
95
- - Where new code of this type should be created
96
- - Import relationships with other areas
97
- - **Data models and schemas** in or owned by this area (see Data Layer below)
65
+ For each area, use the graph to understand it, then distill the **intent** a reader can't get from the graph:
66
+
67
+ **From the graph (read, don't transcribe):**
68
+ - Symbols, signatures, call relationships, dead code — context for understanding what the area does
69
+ - Cross-area import/HTTP links informs the Boundaries section
70
+
71
+ **What you write down (the graph can't infer this):**
72
+ - What the area is *responsible for* (Purpose)
73
+ - What belongs here vs. where related code lives (Boundaries)
74
+ - Naming and structural conventions in use, with an exemplar file reference
75
+ - Where new code of this type should go
76
+ - **Data models and schemas** owned by this area (see Data Layer below)
98
77
 
99
78
  ### 4. Generate Area Docs
100
79
  For each significant area, create a doc file in `.grimoire/docs/`.
101
80
 
102
- **Area doc format:**
81
+ **Area doc format (intent only — no structure tables):**
103
82
 
104
83
  ```markdown
105
84
  # <Area Name>
85
+ > Last updated: YYYY-MM-DD
106
86
 
107
87
  ## Purpose
108
88
  <1-2 sentences: what this area of the codebase is responsible for>
@@ -110,41 +90,28 @@ For each significant area, create a doc file in `.grimoire/docs/`.
110
90
  ## Boundaries
111
91
  <What belongs here and what doesn't. Where related code lives instead.>
112
92
 
113
- ## Key Files
114
- | File | Responsibility |
115
- |------|---------------|
116
- | `path/to/file.py` | <what it does> |
117
- | `path/to/other.py` | <what it does> |
118
-
119
- ## Reusable Code
120
- Utilities and helpers in this area that MUST be reused (not re-implemented):
121
-
122
- | Function/Class | Location | What It Does |
123
- |----------------|----------|-------------|
124
- | `format_currency()` | `utils/formatters.py:42` | Formats decimal as currency string |
125
- | `BaseAPIView` | `api/base.py:15` | Base view with auth, pagination, error handling |
126
-
127
- ## Patterns
128
- <How things are done in this area. Reference specific files as exemplars.>
93
+ ## Conventions
94
+ <How things are done in this area. Reference specific files as exemplars — don't list every file.>
129
95
 
130
96
  ### Naming
131
- - <naming convention with example>
97
+ - <naming convention with one example file>
132
98
 
133
99
  ### Structure
134
- - <structural pattern with example file>
100
+ - <structural pattern with one exemplar file>
135
101
 
136
102
  ## Where New Code Goes
137
103
  - New <type> → `path/to/directory/`
138
104
  - New <type> → `path/to/other/`
139
105
 
140
- ## Known Duplicates
141
- <Only if duplicates data exists in snapshot. List clones that touch this area.>
142
-
143
- | Files | Lines | What's Duplicated |
144
- |-------|-------|------------------|
145
- | `views.py:42-68` ↔ `api/views.py:15-41` | 26 | Request validation logic |
106
+ ## Structure (live)
107
+ For key files, symbols, reusable utilities, call graphs, and duplicates in this area,
108
+ query the graph — it is always current:
109
+ - `get_architecture(area="<dir>")` · `search_graph(qn_pattern="<dir>.*")`
110
+ - duplicates: `grimoire health` (config-driven `duplicates` metric)
146
111
  ```
147
112
 
113
+ Do not hand-list files, functions, or "reusable code" — that's the graph's job, and a frozen copy drifts. The single pointer above replaces the old Key Files / Reusable Code / Known Duplicates tables.
114
+
148
115
  ### 5. Generate Data Schema
149
116
 
150
117
  Scan the codebase for data models, ORM definitions, migration files, and schema declarations. Produce `.grimoire/docs/data/schema.yml` documenting the current data layer.
@@ -290,9 +257,22 @@ areas:
290
257
  path: .grimoire/docs/utils.md
291
258
  directory: src/utils
292
259
  description: Shared utilities, helpers, formatters
260
+
261
+ # Functional stories — how capabilities group for a human reader.
262
+ # `grimoire docs` uses this to group the OVERVIEW's Capabilities section.
263
+ # `features` lists feature-file basenames (no .feature extension).
264
+ stories:
265
+ chat-qa:
266
+ title: Chat & Q&A
267
+ features: [ai-chat, a2ui-integration, search]
268
+ extraction:
269
+ title: Document extraction
270
+ features: [document-pipeline, bbd-validation-rules]
293
271
  ```
294
272
 
295
- The `directory` field links each doc back to the source directory — this is what `grimoire map --refresh` uses to detect gaps.
273
+ The `directory` field links each doc back to the source directory — it's how a targeted refresh maps a changed directory to the area doc that describes it.
274
+
275
+ **Generate the `stories:` map.** Walk `features/`, then group the feature files by *functional story* — the user-facing capability area they serve, not the source directory. Propose the grouping to the user and let them rename/merge stories before writing. A feature not yet assigned to a story falls back to its feature-directory group in the OVERVIEW, so partial maps are fine. `stories` is the one place that grouping lives (DRY) — `grimoire docs` reads it, nothing else defines it.
296
276
 
297
277
  ### Freshness Tracking
298
278
 
@@ -323,38 +303,25 @@ areas:
323
303
  ### 8. Present Summary
324
304
  After generating, show the user:
325
305
  - How many areas documented
326
- - How many reusable utilities inventoried
327
- - Any areas that seem under-organized or have pattern inconsistencies
306
+ - Any areas whose boundaries seem unclear or whose conventions are inconsistent
328
307
  - Suggest which area docs are most critical for the plan skill to read
329
308
 
330
- ## Config Files
331
-
332
- Users can customize what gets scanned by editing files in `.grimoire/`:
333
-
334
- - **`.grimoire/mapignore`** — directories/patterns to skip during scanning (like .gitignore). Edit to exclude vendor code, generated files, etc.
335
- - **`.grimoire/mapkeys`** — key file definitions (format: `filename = type`). Edit to add project-specific indicators like `factories.py = test-factories` or `signals.py = django-signals`.
336
-
337
- These are read by `grimoire map` and affect the snapshot this skill consumes.
338
-
339
309
  ## Integration with Other Skills
340
310
 
341
- - The **plan** skill should read `.grimoire/docs/` before generating tasks look for existing utilities in the reuse inventory, follow documented patterns
342
- - The **verify** skill can check new code against documented patterns
311
+ - The **plan** skill reads `.grimoire/docs/` for Purpose/Boundaries/Conventions before generating tasks, and queries the **graph** for symbols and reusable utilities
312
+ - The **verify** skill can check new code against documented conventions
343
313
  - The **audit** skill can trigger a discover pass as part of onboarding
344
314
  - The **design** skill reads `.grimoire/docs/components.md` first to avoid generating duplicate components
345
- - The **precommit-review** skill checks area doc freshness on every commit and invokes discover in targeted refresh mode for stale dirs this is the primary maintenance trigger, not a periodic manual task
346
- - The **plan** skill gates on staleness for level 3-4 changes and directs the user to run targeted refresh before planning
315
+ - The **plan** skill gates on staleness for level 3-4 changes (when an area's *intent* doc lags its directory) and directs the user to run a targeted refresh before planning
347
316
 
348
317
  ## Important
349
- - **Start from the snapshot.** Don't scan the filesystem yourself — `grimoire map` already did that. Read `.snapshot.json` for structure, then use `codebase-memory-mcp` graph queries for symbols and call graphs (if available), and read actual code files for meaning.
350
- - **Prefer graph queries over file reads.** If `codebase-memory-mcp` is available, use `search_graph` and `query_graph` to find symbols, call paths, and architecture rather than reading every source file. This is faster, more accurate (AST-parsed), and uses fewer tokens.
351
- - **Document what IS, not what should be.** This is a map of the actual codebase, not aspirational standards. If the code is inconsistent, note it — don't paper over it.
352
- - **Point, don't copy.** Reference files and line numbers as exemplars. Don't duplicate code into the docs — it goes stale.
353
- - **Focus on what helps LLMs.** The goal is preventing duplicate code and misplaced files. Prioritize: reusable utilities > file placement > naming conventions > architectural patterns.
354
- - **Keep docs lean.** Each area doc should be scannable in 30 seconds. If it's too long, split it.
355
- - **The reuse inventory is the most valuable output.** An LLM that knows `format_currency()` exists in `utils/formatters.py` won't write a new one.
356
- - **Don't document the obvious.** Skip areas that are self-explanatory from file names alone. Focus on areas where an LLM would make mistakes.
357
- - **Update, don't accumulate.** When refreshing, replace stale docs rather than appending. The docs should reflect the current codebase, not its history.
318
+ - **Start from the graph.** Use `get_architecture` to enumerate areas and `search_graph`/`trace_path` to understand each one. Read source files only to pin down intent the graph can't express.
319
+ - **Intent only never transcribe structure.** Do not write Key Files lists, reusable-code inventories, or symbol tables into area docs. Those are derivable from the graph and would drift. The doc captures purpose, boundaries, and conventions; the doc points at the graph for everything else (DRY one home per fact).
320
+ - **Document what IS, not what should be.** This describes the actual codebase, not aspirational standards. If the code is inconsistent, note it — don't paper over it.
321
+ - **Point, don't copy.** Reference one exemplar file per convention. Don't duplicate code into the docs.
322
+ - **Keep docs lean.** Each area doc should be scannable in 30 seconds. If it's too long, it's probably transcribing structure cut it back to intent.
323
+ - **Don't document the obvious.** Skip areas self-explanatory from file names. Focus on areas where intent or boundaries are non-obvious.
324
+ - **Update, don't accumulate.** When refreshing, replace stale docs rather than appending.
358
325
 
359
326
  ## Done
360
327
  When area docs, schema, context, and index are generated, the workflow is complete. Suggest `grimoire-audit` to document existing features and decisions as Gherkin specs and ADRs.
@@ -21,21 +21,37 @@ Draft or update Gherkin features and MADR architecture decisions collaboratively
21
21
  - Bug report ("something is broken") → `grimoire-bug` or `grimoire-bug-report`
22
22
  - Pure refactoring (no behavior change) → no grimoire artifact needed. Suggest an ADR only if architecturally significant.
23
23
  - Config, deps, formatting → not grimoire territory. Just do it.
24
- - If unclear after one clarifying question, default to drafting a feature.
24
+ - If unclear, apply the jurisdiction table + admission test in step 1. Do NOT default to drafting a feature — default to finding the fact's correct home, and ask one clarifying question if the test is inconclusive.
25
25
 
26
26
  ## Workflow
27
27
 
28
- ### 1. Qualify the Request
29
- Before doing anything, determine what kind of change this is:
28
+ ### 1. Qualify the Request — Jurisdiction
30
29
 
31
- - **Behavioral** (Given/When/Then expressible) draft `.feature` files
32
- - **Architectural** (trade-off, choice, structural) → draft MADR decision record
33
- - **Both** → draft features AND decision records
34
- - **Bug fix** → STOP. Tell the user: "The feature file already describes the correct behavior. Let's just fix the code."
35
- - **Refactoring** → STOP. No behavior change = no grimoire artifact. Suggest an ADR only if it's a significant architectural shift.
36
- - **Config/deps/formatting** → STOP. Not grimoire territory.
30
+ Before doing anything, route the change to the **one** artifact type that owns it. Each fact has exactly one home (see `../references/principles.md` — one right way, DRY). **The default is NOT "draft a feature."** The default is: figure out which home this fact belongs in.
37
31
 
38
- If unclear, ask the user one clarifying question to route correctly. **Do not guess the routing and proceed.** A wrong routing wastes both your context and the user's time — one question costs less.
32
+ | What the change is | Home | Not |
33
+ |--------------------|------|-----|
34
+ | **Actor-observable behavior** — an external actor does something and observes a result | `.feature` (Gherkin) | — |
35
+ | **Constraint** — security control, NFR, performance budget, observability/logging guarantee, compliance rule | `.grimoire/docs/constraints.md` (assertion + rationale + how-verified) | NOT a `.feature` |
36
+ | **Architecture decision** — a trade-off or structural choice | MADR in `.grimoire/decisions/` | NOT a `.feature` |
37
+ | **Data model / external API contract** | data schema | NOT a `.feature` |
38
+ | **Both behavior + decision** | features AND a MADR | — |
39
+ | **Bug fix** | STOP → `grimoire-bug`. "The spec already describes correct behavior; just fix the code." | — |
40
+ | **Refactoring** (no behavior change) | STOP. No artifact. Suggest an ADR only if architecturally significant. | — |
41
+ | **Config / deps / formatting** | STOP. Not grimoire territory. | — |
42
+
43
+ #### The feature-file admission test
44
+
45
+ A scenario may be written **only if it passes all four gates.** If it fails any, it is not a feature — route it to the home above.
46
+
47
+ 1. **External actor** — a user, operator, or external system does the thing. "As a developer, I want structured logs" / "the system retries" → fails. The actor is internal → it's a constraint or a decision, not a feature.
48
+ 2. **Observable** — the actor can see the outcome without reading code or logs. "logs are scrubbed of PII", "request completes in <200ms" → fails (not observable by an actor) → constraint.
49
+ 3. **Domain language** — the scenario uses domain nouns, zero implementation detail. If a step names a library, log level, function, table, or framework (`loguru`, `INFO`, `bcrypt`, `users` table) → fails → it's leaking implementation; rewrite declaratively or move to a constraint/MADR.
50
+ 4. **Survives reimplementation** — if the internals were rewritten from scratch, would the scenario still read the same? If it would change, it's pinned to implementation → not a feature.
51
+
52
+ Common slop this catches (all belong in `constraints.md`, not `.feature`): "PII is scrubbed from logs", "all endpoints require auth", "responses are gzipped", "errors are logged with a trace id". These are invariants, not behaviors.
53
+
54
+ If unclear after applying the test, ask the user one clarifying question to route correctly. **Do not guess the routing and proceed.** A wrong routing wastes both your context and the user's time — one question costs less.
39
55
 
40
56
  ### 2. Score Complexity
41
57
 
@@ -108,6 +124,7 @@ Never silently fill in an open question. Either ask, defer to a non-goal, or rec
108
124
  Present a Requirements Summary (template in the reference) and wait for user confirmation before proceeding.
109
125
 
110
126
  ### 5. Check Existing State
127
+ See `../references/artifact-map.md` for what each artifact is and the reading discipline.
111
128
  - Read `features/` to understand the current behavioral baseline
112
129
  - Read `.grimoire/decisions/` to understand existing architecture decisions
113
130
  - Read `.grimoire/docs/context.yml` (if it exists) to understand the deployment environment, related services, and infrastructure — this tells you what's available (caches, queues, sibling services) and what constraints apply (deployment target, environments)
@@ -117,7 +134,8 @@ Present a Requirements Summary (template in the reference) and wait for user con
117
134
 
118
135
  ### 6. Scaffold the Change
119
136
  - Choose a `change-id`: kebab-case, verb-led (`add-`, `update-`, `remove-`)
120
- - Create `.grimoire/changes/<change-id>/`
137
+ - Ensure you're on a feature branch for this change (`grimoire-branch-guard` usually created it). The branch is where all artifacts are edited live.
138
+ - Create `.grimoire/changes/<change-id>/` — this folder holds **only ephemeral process scaffolding**: `manifest.md` (and later `tasks.md`). It does NOT hold copies of features, decisions, or constraints — those are edited live in their real locations and tracked by `git diff`. The folder is deleted at finalize; the branch + PR + git log are the durable record.
121
139
 
122
140
  ### 7. Draft Artifacts
123
141
  **For behavioral changes:**
@@ -151,15 +169,17 @@ Scenario triage:
151
169
 
152
170
  Do not proceed to writing until this table is complete. If unsure about a match, default to extend.
153
171
 
154
- **Step 3 — Execute**
172
+ **Step 3 — Execute (edit live on the branch)**
155
173
 
156
- - **Extend:** copy the matching baseline file to `.grimoire/changes/<change-id>/features/<same-relative-path>/` and add scenarios there.
157
- - **New file (requires justification):** state which existing files were considered and why none fit. Then create `.grimoire/changes/<change-id>/features/<capability>/<name>.feature`.
174
+ Artifacts are edited **directly in their real locations** on the feature branch. The branch is the isolation; `git diff` is the staging area. There is no copy into `.grimoire/changes/` and no promote step (see `../references/principles.md` — don't reinvent git).
175
+
176
+ - **Extend:** add scenarios directly to the live `features/<same-relative-path>` file.
177
+ - **New file (requires justification):** state which existing files were considered and why none fit. Then create `features/<capability>/<name>.feature` directly.
158
178
 
159
179
  Signals a scenario belongs in an existing file: same actor, same domain object, same entry point, same HTTP resource or screen.
160
180
  Signals a genuinely new file: new actor type with no existing file, entirely new domain object, or existing file's Feature title would need "and" to cover both.
161
181
 
162
- - If modifying an existing feature, copy the current baseline first, then modify
182
+ - Every scenario must have passed the **admission test** in step 1. If you catch yourself writing a step that names a library/log-level/table, stop — that fact belongs in `constraints.md`, not here.
163
183
  - Follow Gherkin best practices:
164
184
  - Feature title + user story (As a / I want / So that)
165
185
  - Background for shared preconditions
@@ -170,7 +190,7 @@ Signals a genuinely new file: new actor type with no existing file, entirely new
170
190
  **When design data was provided (step 4.0):**
171
191
  - If a Figma snapshot or `grimoire-design` output is available, propose Gherkin scenarios per (component × state) grounded in those artifacts. Walk the component list and the enumerated states; emit one Scenario per pair.
172
192
  - Present the proposed scenarios for user review before writing to `.feature` files — accept all / accept some / edit / reject any. Rejected scenarios are not written.
173
- - If `grimoire-design` already produced user-accepted scenarios under `.grimoire/changes/<change-id>/features/`, do NOT re-propose them; treat them as the baseline and only fill gaps (e.g., new components not yet covered).
193
+ - If `grimoire-design` already produced user-accepted scenarios under `.grimoire/changes/<change-id>/designs/scenarios.feature`, do NOT re-propose them; write the accepted ones live into `features/` (applying the admission test) and only fill gaps (e.g., new components not yet covered).
174
194
 
175
195
  **Brand-tokens grounding:**
176
196
  - When Figma variables map to tokens that also appear in `.grimoire/brand/tokens.json`, scenarios referencing visual properties must use token names, not hex values. Example: write `Then the submit button uses color.primary` not `Then the submit button is #0066ff`.
@@ -183,10 +203,23 @@ Signals a genuinely new file: new actor type with no existing file, entirely new
183
203
  **Security tags on scenarios:**
184
204
  Apply Gherkin tags per `../references/security-compliance.md` (section "Security Tags"). Tags drive stricter checks in plan, review, and verify stages. Apply compliance-specific tags only when `project.compliance` is configured. If no compliance frameworks and no security surface, don't add tags.
185
205
 
206
+ **For constraints (security / NFR / observability / compliance):**
207
+
208
+ Anything that failed the feature admission test because it's an invariant rather than an actor-observable behavior goes here — **not** into a `.feature`.
209
+
210
+ - Append to the live `.grimoire/docs/constraints.md` (create it from `templates/constraints.md` if absent).
211
+ - One row per constraint: **assertion · rationale · how-verified · links**. The assertion is a flat statement of what must always hold ("Log output never contains PII or secrets"), not a Given/When/Then.
212
+ - `how-verified` names the test that proves it (a `unit-invariant` test the plan stage will create) — never a Gherkin scenario.
213
+ - If the constraint stems from a decision, link the MADR; don't restate the decision (DRY).
214
+
186
215
  **For architecture decisions:**
187
- - Write MADR record in `.grimoire/changes/<change-id>/decisions/`
216
+
217
+ - **Novelty gate — record only novel decisions.** A MADR is for a decision with a real, project-specific trade-off between viable alternatives. It is NOT for industry-default tooling picks (the standard test runner, CLI parser, git wrapper, linter) or for conventions the ecosystem forces (ESM `.js` import suffix, where the framework expects files). If the honest "Considered Options" would be "the obvious default vs. things nobody would pick here", do not write an ADR. Before writing one, ask: *would a competent engineer on this stack make a different choice, and would they need our reasoning to understand ours?* If no, skip it.
218
+ - **Obvious tooling/conventions go in the baseline record, not their own ADR.** When you do need to write down a default pick (e.g. a new dev dependency), add a row to the existing `Tooling and convention baseline` ADR (one line: choice → why) rather than minting a new sequential record. Reserve sequential ADRs for genuine trade-offs.
219
+ - Write the MADR record directly into the live `.grimoire/decisions/` with the next sequential number (`NNNN-title.md`)
188
220
  - Use the template from `.grimoire/decisions/template.md` or the AGENTS.md format
189
221
  - Include considered options, decision drivers, and consequences
222
+ - Draft status `proposed`; `grimoire-apply` flips it to `accepted` at finalize
190
223
 
191
224
  **For changes that touch data:**
192
225
  - Check `.grimoire/docs/data/schema.yml` for the current data schema (if it exists)
@@ -271,10 +304,14 @@ This is the contract. Downstream skills (plan, review, verify) use it to generat
271
304
  - Every Feature has a user story
272
305
  - Every Scenario has at least Given + When + Then
273
306
  - No implementation details leaked into features
307
+ - **Re-run the admission test on every scenario you wrote** (step 1): external actor, observable, domain language, survives reimplementation. Any scenario that now fails is slop — move it to `constraints.md` or a MADR before proceeding.
308
+ - **Principles gate** (`../references/principles.md`): no fact written to two homes (DRY), no second way to do an existing thing (one right way), no reinvented wheel (don't reinvent), no artifact created past the stated scope (KISS).
274
309
 
275
310
  ## Important
276
311
  - ONE change at a time. Don't combine unrelated changes.
277
- - Features describe behavior, not implementation. If you catch yourself writing step-level implementation details, you've gone too far.
312
+ - **Features describe actor-observable behavior, not implementation, and not invariants.** If a scenario has no external actor, isn't observable, or names a library/log-level/table, it is not a feature — it's a constraint (→ `constraints.md`) or a decision (→ MADR). This is the #1 source of feature-file slop.
313
+ - **One fact, one home** (`../references/principles.md`). A capability lives in one `.feature`; a control lives in one constraint row; a decision lives in one MADR. Never the same fact in two places.
314
+ - Artifacts are edited **live on the branch** — never copied into `.grimoire/changes/`. git diff is the staging area.
278
315
  - The manifest is lightweight glue — don't over-document. Just enough to capture why.
279
316
  - Always check if a capability/feature already exists before creating a new one.
280
317
  - **Figma access token is read from `FIGMA_ACCESS_TOKEN` env var by the MCP server.** Never log the token, never write it to config, never include it in `manifest.md`, `consult.md`, `figma-snapshot.json`, or any other artifact. The MCP server handles authentication transparently — grimoire-draft never needs to see the token value.