@nurix/etna 0.1.3 → 0.2.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 (30) hide show
  1. package/README.md +34 -27
  2. package/bin/etna.js +82 -56
  3. package/data/harness-index.json +0 -7
  4. package/data/harnesses/code/agents/change-review.md +80 -0
  5. package/data/harnesses/code/agents/contract-monitor.md +65 -0
  6. package/data/harnesses/code/agents/dep-health.md +148 -0
  7. package/data/harnesses/code/agents/git-history.md +201 -0
  8. package/data/harnesses/code/agents/maintenance.md +112 -0
  9. package/data/harnesses/code/agents/review.md +109 -0
  10. package/data/harnesses/code/agents/spec-mode.md +56 -0
  11. package/data/harnesses/code/rules/general.md +96 -0
  12. package/data/harnesses/code/rules/nomenclature.md +34 -0
  13. package/data/harnesses/code/scripts/build-ownership-index.sh +138 -0
  14. package/data/harnesses/code/scripts/check-doc-drift.sh +125 -0
  15. package/data/harnesses/code/skills/documentation/SKILL.md +238 -0
  16. package/data/harnesses/code/skills/documentation/references/examples.md +193 -0
  17. package/data/harnesses/code/skills/documentation/references/style-guide.md +288 -0
  18. package/data/harnesses/code/skills/documentation/references/templates.md +901 -0
  19. package/data/harnesses/code/skills/introspect/SKILL.md +135 -0
  20. package/data/harnesses/code/skills/workflow-mapper/SKILL.md +430 -0
  21. package/data/harnesses/code/skills/workflow-mapper/references/patterns.md +214 -0
  22. package/data/harnesses/kb-agi/agents/kb-agi-init.md +276 -0
  23. package/data/harnesses/kb-agi/agents/kb-catch-stale.md +22 -0
  24. package/data/harnesses/kb-agi/agents/kb-find-gaps.md +27 -0
  25. package/data/harnesses/kb-agi/agents/kb-fix-links.md +22 -0
  26. package/data/harnesses/kb-agi/agents/kb-refresh-frontdoor.md +22 -0
  27. package/data/harnesses/kb-agi/agents/kb-refresh-summaries.md +22 -0
  28. package/data/harnesses/kb-agi/agents/kb-sync-metadata.md +25 -0
  29. package/data/harnesses/kb-agi/rules/kb.md +13 -0
  30. package/package.json +1 -1
@@ -0,0 +1,901 @@
1
+ # Documentation Templates
2
+
3
+ Templates for all documentation needs.
4
+
5
+ ---
6
+
7
+ ## 1. docs/README.md (Documentation Root)
8
+
9
+ Use for: the entry point for all documentation in a repo. Created during baseline audit.
10
+
11
+ ```
12
+ # {Project Name} Documentation
13
+
14
+ Technical documentation for {project description}.
15
+
16
+ > For documentation organization, authority map, and folder rules, see **[structure.md](structure.md)**.
17
+
18
+ ---
19
+
20
+ ## Quick Links
21
+
22
+ | Document | Description |
23
+ | --------------------------------- | ------------------------------------ |
24
+ | [Structure](structure.md) | Documentation entry point and rules |
25
+ | [Setup](operations/setup.md) | Installation and configuration guide |
26
+
27
+ ---
28
+
29
+ ## Architecture
30
+
31
+ System design, patterns, and technical decisions.
32
+
33
+ - [system-design.md](architecture/system-design.md) - High-level system architecture
34
+ {list all architecture docs}
35
+
36
+ ---
37
+
38
+ ## Features
39
+
40
+ Living reference docs for implemented features (how things currently work).
41
+
42
+ - [feature-name.md](features/feature-name.md) - Feature description
43
+ {list all feature docs}
44
+
45
+ ---
46
+
47
+ ## Operations
48
+
49
+ How to run, develop, and deploy.
50
+
51
+ - [setup.md](operations/setup.md) - Installation and configuration guide
52
+ {list all operations docs}
53
+
54
+ ---
55
+
56
+ ## History
57
+
58
+ Everything frozen or append-only.
59
+
60
+ - [CHANGELOG.md](history/CHANGELOG.md) - Master changelog index
61
+ - [changelog/](history/changelog/) - Individual changelog entries
62
+ - [plans/](history/plans/) - Historical implementation plans
63
+ - [backlog.md](history/backlog.md) - Tracked work items and technical debt
64
+
65
+ ---
66
+
67
+ ## Contributing
68
+
69
+ See [CLAUDE.md](../CLAUDE.md) for documentation guidelines.
70
+ ```
71
+
72
+ ---
73
+
74
+ ## 2. docs/structure.md (Authority Map)
75
+
76
+ Use for: defining which folder owns which topic and how docs are maintained.
77
+
78
+ ```
79
+ # Documentation Structure
80
+
81
+ > This file is the entry point for understanding the docs folder.
82
+
83
+ ## Authority Map
84
+
85
+ Each topic has one canonical location. Read from here, not from plans or changelogs.
86
+
87
+ | Topic | Authority | Key Files |
88
+ | ----- | --------- | --------- |
89
+ | System architecture | `docs/architecture/` | {key files} |
90
+ | Feature behavior | `docs/features/` | {key files} |
91
+ | Setup & development | `docs/operations/` | {key files} |
92
+ | Historical plans | `docs/history/plans/` | YYYY-MM-DD-name.md |
93
+ | Change records | `docs/history/changelog/` | Individual entries |
94
+ | Backlog | `docs/history/` | backlog.md |
95
+
96
+ ## Document Lifecycle
97
+
98
+ Plan (Status: Draft) → Implementation → Feature Doc or Architecture Update → Changelog Entry
99
+
100
+ - Plans freeze at completion — never updated to reflect current code
101
+ - Changelogs summarize + link to feature docs — no duplicated schemas
102
+ - Feature docs are the living reference — updated when code changes
103
+
104
+ ## Folder Rules
105
+
106
+ - `docs/features/`: Living reference for implemented features. Each spec includes YAML frontmatter with `owns`, `touches`, `depends_on` fields declaring code ownership.
107
+ - `docs/architecture/`: System-wide patterns and technical decisions. Update when cross-cutting concerns change.
108
+ - `docs/operations/`: How-to procedures for setup, development, and deployment. Update when workflows change.
109
+ - `docs/history/plans/`: Historical. Must have `Status:` field. Never modify after completion.
110
+ - `docs/history/changelog/`: Historical. Append-only.
111
+ - `docs/history/backlog.md`: Tracked work items. Append new items under appropriate priority.
112
+
113
+ ## Health Log
114
+
115
+ <!-- Updated by maintenance agent -->
116
+ | Date | Review Summary |
117
+ | ---- | -------------- |
118
+ | {today} | Initial baseline — 6-folder structure established |
119
+ ```
120
+
121
+ ---
122
+
123
+ ## 3. Feature Ownership Frontmatter
124
+
125
+ Use for: every feature doc in `docs/features/`. Declares which source files this doc is authoritative for.
126
+
127
+ ```yaml
128
+ ---
129
+ owns:
130
+ - src/feature-name/**
131
+ - app/feature-name/**
132
+ touches:
133
+ - src/shared/utils/feature-helper.js
134
+ depends_on:
135
+ - docs/architecture/system-design.md
136
+ ---
137
+ ```
138
+
139
+ - `owns`: Glob patterns for files this feature doc is the canonical reference for
140
+ - `touches`: Files this feature interacts with but doesn't own
141
+ - `depends_on`: Other docs that must be read for full context
142
+
143
+ ---
144
+
145
+ ## 4. Scaffold Files (create if missing)
146
+
147
+ These standard files must exist after every baseline. Create them with these scaffolds if the repo doesn't already have them.
148
+
149
+ ### docs/history/CHANGELOG.md
150
+
151
+ ```
152
+ # Changelog
153
+
154
+ All notable changes to {Project Name} will be documented in this file.
155
+
156
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
157
+
158
+ ---
159
+
160
+ ## [Unreleased]
161
+
162
+ {entries added here as work proceeds}
163
+
164
+ ---
165
+
166
+ ## Links
167
+
168
+ - [Setup Guide](../operations/setup.md)
169
+ - [Architecture](../architecture/)
170
+
171
+ ---
172
+
173
+ ## How to Update This Changelog
174
+
175
+ 1. Create a dated change file in `docs/history/changelog/`:
176
+ `docs/history/changelog/YYYY-MM-DD-feature-name.md`
177
+
178
+ 2. Update this CHANGELOG.md with a high-level summary linking to the detail file
179
+
180
+ 3. Follow Keep a Changelog categories:
181
+ - **Added** for new features
182
+ - **Changed** for changes in existing functionality
183
+ - **Deprecated** for soon-to-be removed features
184
+ - **Removed** for now removed features
185
+ - **Fixed** for bug fixes
186
+ - **Security** for security improvements
187
+ ```
188
+
189
+ ### docs/history/backlog.md
190
+
191
+ ```
192
+ # Backlog
193
+
194
+ Tracked work items, technical debt, and planned improvements. Append new items under the appropriate priority.
195
+
196
+ ---
197
+
198
+ ## Format
199
+
200
+ - **[P0]** Description — discovered by [plan-name or agent-name]
201
+
202
+ ---
203
+
204
+ ## P0 — Critical
205
+
206
+ {items here}
207
+
208
+ ## P1 — High
209
+
210
+ {items here}
211
+
212
+ ## P2 — Medium
213
+
214
+ {items here}
215
+
216
+ ## P3 — Low
217
+
218
+ {items here}
219
+ ```
220
+
221
+ ### docs/memory/index.md
222
+
223
+ ```
224
+ ---
225
+ type: cross-session-learnings
226
+ description: Shared knowledge accumulated across agent sessions. All agents should consult and update this file.
227
+ ---
228
+
229
+ # Cross-Session Learnings
230
+
231
+ ## Documentation Baseline
232
+
233
+ - **Baselined:** {today}
234
+ - **Structure:** 6-folder (architecture, features, operations, history, memory, tests)
235
+
236
+ ## Learnings
237
+
238
+ {Agents append learnings here as they discover gotchas, patterns, and architecture notes}
239
+ ```
240
+
241
+ ### docs/memory/main.md
242
+
243
+ ```
244
+ ---
245
+ type: project-memory
246
+ owner: main-agent
247
+ description: Project-wide patterns and conventions confirmed in this codebase. Project facts only — user-centric facts go in ~/.claude/.
248
+ ---
249
+
250
+ # Main Agent — Project Memory
251
+
252
+ Append entries below, oldest at bottom. Format:
253
+
254
+ ## YYYY-MM-DD — {topic}
255
+
256
+ {1-3 line fact, with file paths or references where relevant}
257
+
258
+ ---
259
+
260
+ ## {today} — Baseline
261
+
262
+ Memory file initialized during documentation baseline.
263
+ ```
264
+
265
+ ### docs/OWNERSHIP_INDEX.md
266
+
267
+ ```
268
+ # Ownership Index
269
+
270
+ Auto-generated by the maintenance agent (Step 0). Do not edit by hand.
271
+
272
+ **Generated:** {today}
273
+
274
+ | Doc | Owns | Touches | Depends On |
275
+ |-----|------|---------|------------|
276
+ | [features/{name}.md](features/{name}.md) | `glob1`, `glob2` | `path` | `doc1`, `doc2` |
277
+
278
+ ## Unowned Docs
279
+
280
+ {Feature docs missing frontmatter, listed here so they can be backfilled}
281
+ ```
282
+
283
+ ---
284
+
285
+ ## 5. docs/operations/guardrails.md (Cascading Failure Boundaries)
286
+
287
+ Use for: documenting contracts, shapes, and coupling points where a change in one module silently breaks another. Created during baseline audit. Updated when new cross-module contracts are discovered.
288
+
289
+ ### What belongs in guardrails
290
+
291
+ A guardrail is something where **the failure is silent and crosses module boundaries**. The developer working in module A has no reason to know that module B will break. No import error, no runtime exception — just wrong behavior.
292
+
293
+ Test: "If an agent edits this while working on a single feature, could it silently break something in a different feature?" If yes, it's a guardrail.
294
+
295
+ **Include:**
296
+
297
+ - **Shared state shapes** — Redux store slices, persisted state, global context. Any shape that multiple modules read. Document every key, its type, and what reads it. Call out which slices are persisted and how rehydration handles shape changes (e.g., new fields become `undefined` for existing users).
298
+ - **Entity registration checklists** — When adding a new entity/resource type requires touching N files across N modules to avoid silent data loss. List every file and what breaks if skipped.
299
+ - **Cross-entity references by value** — When entity A stores entity B's identifier (slug, name, ID) as a plain value with no referential integrity. Document which fields reference what, and that renaming the target never propagates to the source.
300
+ - **Format contracts** — When two systems produce identifiers in different formats (e.g., server returns `[a-z0-9]+`, client generates `[a-z0-9_]+`). Document both formats, where each is used, and what breaks on mismatch (e.g., lookup by key returns `undefined`, key-splitting logic produces wrong matches).
301
+ - **Cross-module string coupling** — Action types, event names, status enums, or document type strings referenced by raw string literal instead of imported constant. List every file that hard-codes the string and what breaks if the source is renamed.
302
+ - **Pipeline ordering dependencies** — Multi-step pipelines where Step N assumes Step N-1 has already written data to shared state. Document the implicit dependency and what happens if ordering changes (silent quality degradation vs. hard failure vs. hang).
303
+ - **Completion signal contracts** — When modules communicate via return values, status fields, or Redux state transitions. Document the expected shape/type (e.g., `Promise<boolean>`, status enum values) and what happens if the contract changes (e.g., returning `undefined` instead of `true` causes permanent "failed" status).
304
+ - **Host/plugin contracts** — Config objects consumed by a framework/host where some fields are validated and others aren't. Document which fields are unvalidated and what breaks silently if they change.
305
+ - **Persistence shape safety** — How the persistence layer handles schema evolution. Document what happens when you add, remove, or rename a field in persisted state (e.g., no migration → stale data, new fields default to `undefined`).
306
+
307
+ **Exclude:**
308
+
309
+ - Module-internal architecture (well-encapsulated, no cross-module blast radius)
310
+ - Authentication/authorization flows (behind adapters, feature code doesn't touch them)
311
+ - Hook taxonomies and API reference (useful docs, but not guardrails — they don't cause cascading failures)
312
+ - Networking details (WebSocket, HTTP client setup) — unless the event routing has cross-module string coupling
313
+ - Feature folder conventions and code style (conventions, not breakage vectors)
314
+ - Anything where failure produces an import error, a clear runtime exception, or a visible UI error — those are self-diagnosing and don't need guardrails
315
+
316
+ ### How to research guardrails
317
+
318
+ When creating or updating `docs/operations/guardrails.md`, use sub-agents to investigate:
319
+
320
+ 1. **Shared state consumers** — For each Redux slice/context, find all files that read from it. Flag any file reading a slice it doesn't own (cross-module dependency).
321
+ 2. **String-coupled actions** — Grep for Redux action type strings referenced as raw strings rather than imported constants. These are invisible breakage points.
322
+ 3. **Entity lifecycle** — For each entity type, trace the full lifecycle: creation → change tracking → save payload → API → server. Identify every file that must be touched to support a new entity type.
323
+ 4. **Identifier format mismatches** — Compare how identifiers are generated (server vs. client) and how they're used as keys. Look for format divergence.
324
+ 5. **Pipeline data dependencies** — For multi-step processes, check what each step reads from shared state and what previous step wrote it. Test: "If I reorder these steps, does it fail loudly or silently?"
325
+ 6. **Persistence rehydration** — Check what reconciler is used, whether transforms exist, and what happens to existing users when a persisted shape changes.
326
+
327
+ ### Template
328
+
329
+ ```markdown
330
+ # Guardrails
331
+
332
+ Things that silently break across modules if touched wrong. Each section explains what the contract is, where it's consumed, and what goes wrong if violated.
333
+
334
+ ---
335
+
336
+ ## 1. [Contract Name]
337
+
338
+ [One-line description of what this contract governs.]
339
+
340
+ ### The contract
341
+
342
+ [Describe the shape, format, or protocol. Show code if it's a data shape.]
343
+
344
+ ### Where it's consumed
345
+
346
+ [Table or list of every file/module that depends on this contract.]
347
+
348
+ ### What breaks if violated
349
+
350
+ [Specific failure modes. "Silent data loss", "lookup returns undefined", "pipeline hangs", etc.]
351
+
352
+ ### Checklist (if applicable)
353
+
354
+ [Step-by-step list of files to touch when extending this contract. Mark which steps cause silent failures if skipped.]
355
+
356
+ ---
357
+
358
+ ## N. [Next Contract]
359
+
360
+ ...
361
+
362
+ ---
363
+
364
+ ## Reference: [Shapes / Enums / Defaults]
365
+
366
+ [Put stable reference material (store shapes, entity defaults, API envelopes) at the bottom. These support the guardrails above but aren't guardrails themselves.]
367
+ ```
368
+
369
+ ---
370
+
371
+ ## 6. Feature Documentation (docs/features/{feature}.md)
372
+
373
+ Use for: every feature in `docs/features/`. The same file persists from design (Status: Draft) through implementation to live reference (Status: Active). Sections fill in as the feature matures — no template swap.
374
+
375
+ The four research-derived sections (**Affected Modules**, **Conventions to Follow**, **Current Behavior**, **Ownership Conflicts**) map 1:1 to spec-mode's return shape. The orchestrator drops spec-mode's findings into those slots without restructuring.
376
+
377
+ ```yaml
378
+ ---
379
+ owns:
380
+ - src/feature-name/** # projected at Draft, confirmed at Active
381
+ touches:
382
+ - src/shared/state/feature.js
383
+ depends_on:
384
+ - docs/features/related-feature.md
385
+ ---
386
+ ```
387
+
388
+ ```
389
+ # {Feature Name}
390
+
391
+ **Status:** Draft | Active <!-- Draft: in design or in flight. Active: implemented and maintained. -->
392
+ **Plan:** [history/plans/YYYY-MM-DD-feature-name.md](../history/plans/YYYY-MM-DD-feature-name.md) <!-- added once a plan exists -->
393
+
394
+ ## Goal
395
+
396
+ One sentence. What this feature accomplishes, in user-facing terms.
397
+
398
+ ## Goals & Non-Goals
399
+
400
+ **In scope**
401
+ - Bullet 1
402
+ - Bullet 2
403
+
404
+ **Out of scope**
405
+ - Bullet 1
406
+
407
+ ## Background
408
+
409
+ Why this feature exists. The user need, the business trigger, the constraint that pushed it above the line. One paragraph.
410
+
411
+ (For Product-level work, also include: problem statement, key hypotheses, open questions.)
412
+
413
+ ## Approach
414
+
415
+ High-level shape of the solution. ASCII diagram if it helps. Implementation specifics belong in the plan.
416
+
417
+ ## Affected Modules
418
+
419
+ (From spec-mode research) Files, routes, components, slices this feature involves. Group by module.
420
+
421
+ | Module | Path | Role in this feature |
422
+ |--------|------|----------------------|
423
+
424
+ ## Conventions to Follow
425
+
426
+ (From spec-mode research) Naming patterns, structural patterns, doc-fit heuristics confirmed for the area being touched. Cite the source file(s) where the convention is established.
427
+
428
+ ## Current Behavior
429
+
430
+ (From spec-mode research) How the relevant part of the system works *today*, before this feature lands. Without this baseline the design intent is hard to evaluate.
431
+
432
+ ## Ownership Conflicts
433
+
434
+ (From spec-mode research) Existing feature docs whose `owns` or `touches` overlap with the projected scope. Resolve per row before the plan starts — leave nothing unresolved.
435
+
436
+ | Conflicting doc | Overlapping path(s) | Resolution |
437
+ |-----------------|---------------------|------------|
438
+
439
+ ## Architecture
440
+
441
+ [ASCII diagram. Fill once implementation lands. See style-guide.md for box-drawing patterns.]
442
+
443
+ ## Key Functions
444
+
445
+ ### `functionName(param1, param2)`
446
+ **Goal:** What it accomplishes
447
+ **Input:**
448
+ - `param1` (type) - Description
449
+ - `param2` (type) - Description
450
+ **Output:** Return type and shape
451
+ **Side Effects:** DB writes, API calls, state updates
452
+
453
+ ### `hookName(config)`
454
+ **Goal:** What it provides
455
+ **Returns:** `{ data, loading, error }`
456
+ **Triggers:** On mount, on change, manual
457
+
458
+ ## State
459
+
460
+ **Frontend (at persistence):**
461
+ {
462
+ "data": [],
463
+ "changes": { "added": [], "updated": [], "removed": [] }
464
+ // "cache": {} // UNUSED: Deprecated
465
+ }
466
+
467
+ **Storage:** localStorage `app_state`
468
+
469
+ **Backend:**
470
+ model Resource {
471
+ id String @id
472
+ data Json
473
+ // oldField String? // UNUSED: Legacy
474
+ }
475
+
476
+ **API Shape:**
477
+ { "status": 1, "data": {...} }
478
+
479
+ ## Redux (if applicable)
480
+
481
+ **Slice:** `sliceName`
482
+
483
+ **Actions:**
484
+ - `setData(payload)` - Replace all data
485
+ - `upsertItem(item)` - Add or update single item
486
+
487
+ **Selectors:**
488
+ - `selectAll(state)` → `Array<Item>`
489
+ - `selectById(state, id)` → `Item | undefined`
490
+
491
+ ## Files
492
+
493
+ - `src/path/to/main.js` - Core logic
494
+ - `src/path/to/hooks.js` - React hooks
495
+
496
+ ## Open Questions
497
+
498
+ - Question — who decides, by when
499
+ - (Resolved questions: fold the resolution into Background.)
500
+
501
+ ## Risks
502
+
503
+ - Risk — likelihood / impact / mitigation
504
+ ```
505
+
506
+ ### Section evolution
507
+
508
+ Sections fill in across the feature's lifecycle. No template swap — they accumulate in place.
509
+
510
+ | When | Sections written | Source |
511
+ |------|------------------|--------|
512
+ | Status: Draft (design) | Goal, Goals & Non-Goals, Background, Approach, Open Questions, Risks | User interview |
513
+ | Status: Draft (research) | Affected Modules, Conventions to Follow, Current Behavior, Ownership Conflicts | spec-mode agent |
514
+ | Status: Draft → Active (implementation lands) | Architecture, Key Functions, State, Redux, Files; frontmatter `owns`/`touches` confirmed against real code | Main agent (from actual code) |
515
+
516
+ Resolved Open Questions can be summarized into Background; unresolved ones stay visible.
517
+
518
+ ---
519
+
520
+ ## 7. Changelog
521
+
522
+ Use for: recording code changes with function-level detail.
523
+
524
+ ```
525
+ # YYYY-MM-DD - [Title]
526
+
527
+ ## Summary
528
+
529
+ Brief description of what changed and why.
530
+
531
+ ## Changes
532
+
533
+ ### Added
534
+ - `newFunction(params)` in `path/to/file.js`
535
+ - Purpose: What it does
536
+ - Used by: Where it's called
537
+
538
+ ### Modified
539
+ - `existingFunction()` in `path/to/file.js`
540
+ - Changed: What's different
541
+ - Reason: Why it changed
542
+ - Migration: What callers must do
543
+
544
+ ### Removed
545
+ - `oldFunction()` from `path/to/file.js`
546
+ - Replaced by: `newFunction()`
547
+
548
+ ## Breaking Changes
549
+
550
+ ⚠️ **[Change description]**
551
+ - Old: Previous behavior
552
+ - New: Current behavior
553
+ - Impact: What breaks
554
+ - Migration: How to fix
555
+
556
+ ## Migration Steps
557
+
558
+ - [ ] Step 1
559
+ - [ ] Step 2
560
+
561
+ ## Files Changed
562
+
563
+ - `src/path/file1.js` - Core changes
564
+ - `src/path/file2.js` - Supporting updates
565
+ ```
566
+
567
+ ---
568
+
569
+ ## 8. Plan (docs/history/plans/YYYY-MM-DD-feature-name.md)
570
+
571
+ Use for: every implementation plan. Plans are created here directly with `Status: Draft`, flip to `Status: In Progress` when work starts, and freeze at `Status: Complete` or `Status: Abandoned`. Once frozen, never edit — write a new dated plan if scope changes.
572
+
573
+ The `introspect` skill parses the **Proposed Changes** sections to check guardrail impact. Keep that structure stable — section headings and bullet shape are load-bearing for the parser.
574
+
575
+ ```
576
+ # {Feature Name}
577
+
578
+ **Status:** Draft | In Progress | Complete | Abandoned
579
+ **Spec:** [docs/features/{feature}.md](../../features/{feature}.md)
580
+ **Started:** YYYY-MM-DD
581
+ **Completed:** YYYY-MM-DD <!-- fill when status flips to Complete -->
582
+
583
+ ## Background
584
+
585
+ Why this work is happening *now*. Link to the spec for *what* we're building; this section is the motivation and the trigger. One paragraph.
586
+
587
+ ## Proposed Changes
588
+
589
+ ### New Files
590
+
591
+ - `src/path/new-file.js` — purpose
592
+
593
+ ### Modified Files
594
+
595
+ - `src/path/existing.js` — what changes and why
596
+
597
+ ### New Entities / State
598
+
599
+ - `entities.foo` — new Redux slice / DB table / persisted shape
600
+ - Persisted state addition: `state.bar.baz` (default `null` for existing users on rehydrate)
601
+
602
+ ### API Changes
603
+
604
+ - `POST /api/foo` — new route, request `{...}`, response `{status, data}`
605
+ - `PUT /api/bar` — request shape changes; see Migration
606
+
607
+ ### Cross-Module Contracts Affected
608
+
609
+ - List which guardrails (from `docs/operations/guardrails.md`) this plan touches by name
610
+ - "None" is a valid answer and means introspect will pass cleanly
611
+
612
+ ## Implementation Steps
613
+
614
+ 1. Concrete, ordered, testable
615
+ 2. Each step ends with something verifiable
616
+ 3. ...
617
+
618
+ ## Done Criteria
619
+
620
+ - [ ] Implementation complete and verified
621
+ - [ ] Affected docs updated (use `docs/routing.md` to find them)
622
+ - [ ] Changelog entry created in `docs/history/changelog/`
623
+ - [ ] Plan marked `Status: Complete`, **Completed:** date filled
624
+
625
+ ## Open Questions
626
+
627
+ - Question — who decides, by when
628
+
629
+ ## Risks
630
+
631
+ - Risk — likelihood / impact / mitigation
632
+ ```
633
+
634
+ ---
635
+
636
+ ## 9. Protected Files
637
+
638
+ Use for: documenting critical files that need approval before modification.
639
+
640
+ ```
641
+ # Protected Files
642
+
643
+ Critical files requiring approval before modification.
644
+
645
+ ## File List
646
+
647
+ # Category 1 - Description
648
+ path/to/critical/file1.js
649
+ path/to/critical/file2.js
650
+
651
+ # Category 2 - Description
652
+ path/to/another/file.js
653
+
654
+ ## Risk Summary
655
+
656
+ | Category | Risk if Broken |
657
+ |------------|-----------------|
658
+ | Category 1 | Specific impact |
659
+ | Category 2 | Specific impact |
660
+
661
+ ## Critical Logic
662
+
663
+ ### Category 1: [Name]
664
+
665
+ **Purpose:** What these files do
666
+
667
+ **Key Functions:**
668
+
669
+ | Function | Input | Output | Purpose |
670
+ |------------|-------|--------|----------------|
671
+ | `func1()` | Type | Type | What it does |
672
+ | `func2()` | Type | Type | What it does |
673
+
674
+ **Critical Behavior:**
675
+ - Important point 1
676
+ - Important point 2
677
+ ```
678
+
679
+ ---
680
+
681
+ ## 10. Architecture Decision Record (ADR)
682
+
683
+ Use for: capturing a single, point-in-time architectural decision with its context, alternatives considered, and consequences. Lives in `docs/architecture/adr/`.
684
+
685
+ ### When to write an ADR
686
+
687
+ Write an ADR when **all three** apply:
688
+
689
+ 1. The decision is architectural — affects system shape, contracts, or substrate choice, not internal implementation
690
+ 2. Alternatives were genuinely considered and rejected
691
+ 3. Future maintainers will ask "why did we do it this way?"
692
+
693
+ Don't write an ADR for:
694
+
695
+ - Standing principles or style preferences (those are stances, not decisions — put them in `docs/architecture/`)
696
+ - Routine implementation choices with no rejected alternatives
697
+ - Anything you'd be happy reversing without ceremony
698
+
699
+ ### Lifecycle
700
+
701
+ `Proposed` → `Accepted` → `Deprecated` → `Superseded by ADR-NNN`
702
+
703
+ ADRs are **immutable after acceptance**. If the decision changes, write a new ADR that supersedes it. Update only the old ADR's `status` frontmatter field — never its body.
704
+
705
+ ### Naming
706
+
707
+ `ADR-NNN-short-title.md` — three-digit zero-padded number, kebab-case title. Numbers are assigned sequentially across the project and never reused.
708
+
709
+ ### Structure
710
+
711
+ Three sections are required: **Decision**, **Context**, **Consequences**. Everything else is optional — include only when warranted. Decision-first: readers should see the answer in the first paragraph.
712
+
713
+ ### Template
714
+
715
+ ```markdown
716
+ ---
717
+ title: "ADR-NNN: Short title in sentence case"
718
+ status: Accepted # Proposed | Accepted | Deprecated | Superseded by ADR-NNN
719
+ date: YYYY-MM-DD
720
+ decision-owner: Name
721
+ reviewers: [] # optional
722
+ supersedes: # optional, e.g., ADR-005
723
+ tags: [adr]
724
+ ---
725
+
726
+ # ADR-NNN: Short Title
727
+
728
+ ## Decision
729
+
730
+ [One paragraph, active voice. "We will…" Lead with the answer.]
731
+
732
+ ## Context
733
+
734
+ [The forces in play. What is the problem? Why does it need a decision now? Technical, political, social, and project-local pressures.]
735
+
736
+ ## Consequences
737
+
738
+ **Positive:**
739
+ - [What becomes easier]
740
+
741
+ **Negative:**
742
+ - [What becomes harder, what we accept reluctantly]
743
+
744
+ **Risks:**
745
+ - [Second-order effects you can already see, with mitigations if known]
746
+
747
+ <!-- Optional sections below. Include only when warranted by the decision's weight. -->
748
+
749
+ ## Decision Drivers
750
+
751
+ [Hard non-negotiables vs. strong levers. Include when alternatives exist and the criteria aren't self-evident from Context.]
752
+
753
+ ## Options Considered
754
+
755
+ | Option | Pros | Cons | Outcome |
756
+ |---|---|---|---|
757
+ | **Option A** | … | … | **CHOSEN** |
758
+ | Option B | … | … | Eliminated — [reason] |
759
+
760
+ ## Deep Comparison
761
+
762
+ [Honest framing of the strongest alternative(s). Include when the table doesn't make the reasoning obvious. State the *real* reason each was rejected — not a strawman.]
763
+
764
+ ## Architecture in Detail
765
+
766
+ [Diagrams, code shape, layer responsibilities. Include when the decision implies non-trivial structure that readers need to understand alongside the *why*.]
767
+
768
+ ## Implementation Plan
769
+
770
+ | Phase | Scope | Duration |
771
+ |---|---|---|
772
+ | 1 | … | … |
773
+
774
+ ## Open Questions
775
+
776
+ 1. **[Question]** — *Default*: [stated default until resolved].
777
+
778
+ ## Acknowledgements
779
+
780
+ [Credit reviewers; name what they corrected. Include when reviewers materially shaped the doc.]
781
+
782
+ ## References
783
+
784
+ - [External link or cross-reference]
785
+ ```
786
+
787
+ ### Rules
788
+
789
+ - One decision per ADR. If you find yourself describing two decisions, split into two ADRs.
790
+ - Decision-first. The first paragraph after the heading is the answer; readers should not need to scroll.
791
+ - No section numbering (`§5.1.1`). Use markdown headings only — inserting a section shouldn't renumber everything.
792
+ - Frontmatter `status` is the single source of truth for lifecycle. Don't also write "Status: Accepted" in the body.
793
+ - When superseding, set the old ADR's `status: "Superseded by ADR-NNN"` and the new ADR's `supersedes: ADR-OLD`.
794
+ - The body is frozen at `Accepted`. Corrections to facts that were wrong at the time get a new ADR; typos and formatting fixes are fine.
795
+
796
+ ---
797
+
798
+ ## 11. Project Root README
799
+
800
+ Use for: the human-facing entry point at the repository root (`/README.md`) — what visitors and new contributors land on. Distinct from `docs/README.md` (the agent/doc index — see §1). The two coexist; don't merge them.
801
+
802
+ ### Strategy
803
+
804
+ The root README answers, in order:
805
+
806
+ 1. **What is this?** — one to two sentences, no marketing claims
807
+ 2. **What do I get if I install it?** — capability families
808
+ 3. **What's it built on?** — terse stack list with versions
809
+ 4. **How do I run it?** — the three or four scripts that matter
810
+ 5. **How is it laid out?** — directory tree, one-liner per significant folder
811
+ 6. **How do I extend it?** — numbered contribution checklist
812
+ 7. **What state is it in?** — pre-publish, beta, stable, internal
813
+
814
+ Skip any section that doesn't apply. Don't pad to fill the template.
815
+
816
+ ### Writing rules
817
+
818
+ - **Sentence-case headings.** "Getting started", not "Getting Started".
819
+ - **Concrete over abstract.** Real versions, real paths, real commands. No "leverages cutting-edge…".
820
+ - **The tagline answers "what is this?"** — not "why is it great?". Two sentences max.
821
+ - **Tables for enumeration** (routes, commands, endpoints). **Bullets for families and categories.**
822
+ - **Directory tree as a code block**, not a nested markdown list.
823
+ - **Numbered checklist** for "how to add a thing" — readers should be able to follow it top-to-bottom without re-reading.
824
+ - **Point to `docs/` for depth.** The root README links into deep docs; it doesn't host them.
825
+ - **Detect the package manager from the lockfile** (`pnpm-lock.yaml` → pnpm, `yarn.lock` → yarn, otherwise npm) and write commands accordingly. Don't hardcode `npm` if the repo uses pnpm.
826
+
827
+ ### Template
828
+
829
+ ```markdown
830
+ # {package-name}
831
+
832
+ {One- to two-sentence positioning. What it is and what scope it covers. No superlatives, no value claims.}
833
+
834
+ ## What's in the box
835
+
836
+ - **{Family 1}** — {what's in it; a few specific items, comma-listed.}
837
+ - **{Family 2}** — {what's in it.}
838
+ - **{Family 3}** — {what's in it.}
839
+
840
+ The full surface lives in [`{path/to/public-index}`]({path/to/public-index}). ← optional pointer for libraries
841
+
842
+ ## Stack
843
+
844
+ - {Framework} {version} · {Language} {version}
845
+ - {Build tool} {version}
846
+ - {Other load-bearing deps}
847
+
848
+ ## Getting started
849
+
850
+ \`\`\`bash
851
+ {pm} install
852
+ {pm} run dev # what it does (port, URL)
853
+ {pm} run build # what it does
854
+ {pm} run preview # what it does (omit if not applicable)
855
+ \`\`\`
856
+
857
+ {Optional one-liner about first-run behavior — e.g., "Dev server lands on /playground."}
858
+
859
+ ## {Runtime entry point} ← optional; e.g., "The playground", "CLI", "API endpoints"
860
+
861
+ {Brief description of the dev/runtime surface.}
862
+
863
+ | {Thing} | {What it shows / does} |
864
+ | -------------------- | -------------------------- |
865
+ | `{route or command}` | {description} |
866
+
867
+ ## Layout
868
+
869
+ \`\`\`
870
+ src/
871
+ ├── {entry-file} # {purpose}
872
+ ├── {folder}/ # {purpose}
873
+ │ └── ...
874
+ └── {folder}/ # {purpose}
875
+ \`\`\`
876
+
877
+ ## Adding a {primary unit}
878
+
879
+ 1. {Drop the source under the right family/folder.}
880
+ 2. {Re-export from the public surface.}
881
+ 3. {Wire into the playground / example app / test harness so reviewers can see it render.}
882
+ 4. {Document any divergence from upstream in `docs/{...}`.}
883
+
884
+ ## Styling ← optional; replace with whichever cross-cutting concern matters most
885
+
886
+ {Configuration notes that affect every consumer — design tokens, conventions, opt-outs.}
887
+
888
+ ## Status
889
+
890
+ {Pre-publish, beta, stable, internal-only. State what's stable and what's still moving — readers should know whether the API can be relied on.}
891
+
892
+ ## License
893
+
894
+ {License name — scope. e.g., "UNLICENSED — internal use only", "MIT".}
895
+ ```
896
+
897
+ ### Baseline scaffolding behavior
898
+
899
+ The baseline audit **does** scaffold the project root README when missing. The risk this template guards against — template-shaped placeholders that look abandoned — is mitigated by the writing rules above: fill every section with concrete details from the repo (real package manager from the lockfile, real scripts, real layout, real status). Skip sections that genuinely don't apply rather than leaving stubs.
900
+
901
+ **Never overwrite an existing root README** during a baseline. If one is present — even sparse or outdated — leave it untouched. Treat updates to a pre-existing root README as a separate, explicit request.