doctrina-cli 0.12.0 → 0.14.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 (68) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -2
  3. package/src/commands/adapter.js +205 -0
  4. package/src/commands/analyze.js +76 -19
  5. package/src/commands/change.js +341 -44
  6. package/src/commands/clarify.js +40 -19
  7. package/src/commands/close.js +119 -11
  8. package/src/commands/completion.js +6 -0
  9. package/src/commands/constitution.js +8 -1
  10. package/src/commands/context.js +359 -53
  11. package/src/commands/contract.js +17 -24
  12. package/src/commands/coverage.js +16 -4
  13. package/src/commands/decision.js +172 -40
  14. package/src/commands/doctor.js +38 -7
  15. package/src/commands/handoff.js +8 -1
  16. package/src/commands/hooks.js +6 -0
  17. package/src/commands/index-rebuild.js +8 -1
  18. package/src/commands/init.js +152 -6
  19. package/src/commands/intake.js +11 -2
  20. package/src/commands/intent.js +8 -1
  21. package/src/commands/metrics.js +80 -7
  22. package/src/commands/next.js +14 -2
  23. package/src/commands/prime.js +8 -1
  24. package/src/commands/report.js +8 -1
  25. package/src/commands/review.js +8 -1
  26. package/src/commands/search.js +8 -1
  27. package/src/commands/show.js +8 -1
  28. package/src/commands/skill.js +16 -6
  29. package/src/commands/spec.js +13 -6
  30. package/src/commands/status.js +14 -2
  31. package/src/commands/templates.js +277 -40
  32. package/src/commands/trace.js +15 -3
  33. package/src/commands/upgrade.js +23 -12
  34. package/src/commands/validate.js +93 -3
  35. package/src/commands/verify.js +12 -2
  36. package/src/commands/watch.js +8 -1
  37. package/src/commands/why.js +10 -24
  38. package/src/commands/work.js +69 -7
  39. package/src/index.js +60 -6
  40. package/src/lib/adapters.js +140 -0
  41. package/src/lib/adr-guard.js +47 -0
  42. package/src/lib/args.js +10 -0
  43. package/src/lib/clarity.js +1 -0
  44. package/src/lib/colors.js +1 -0
  45. package/src/lib/commands.js +314 -3
  46. package/src/lib/criteria.js +1 -0
  47. package/src/lib/dates.js +1 -0
  48. package/src/lib/diff.js +1 -0
  49. package/src/lib/doc-model.js +287 -0
  50. package/src/lib/docs-impact.js +167 -0
  51. package/src/lib/ears.js +1 -0
  52. package/src/lib/exit-codes.js +103 -0
  53. package/src/lib/flag-catalog.js +106 -0
  54. package/src/lib/fs-ops.js +1 -0
  55. package/src/lib/gates.js +123 -0
  56. package/src/lib/git.js +97 -0
  57. package/src/lib/index-json.js +14 -6
  58. package/src/lib/json-out.js +83 -0
  59. package/src/lib/prompt.js +18 -1
  60. package/src/lib/scan.js +81 -33
  61. package/src/lib/spec-ops.js +228 -3
  62. package/src/lib/suggest.js +1 -0
  63. package/src/lib/templates.js +89 -0
  64. package/src/lib/usage.js +89 -0
  65. package/src/lib/version.js +1 -0
  66. package/templates/.gitkeep +0 -0
  67. package/templates/AGENTS.md.template +71 -75
  68. package/templates/change/spec-delta.md.template +13 -7
@@ -22,41 +22,54 @@ prompt and approves; do not make them run the CLI or hand-author artifacts.
22
22
  spec each, `doctrina clarify --all` + `doctrina validate`, then flip the
23
23
  intake to `Status: converted`). After conversion the specs are the only
24
24
  source of truth — never edit `intake.md` to change requirements.
25
- - **Day-to-day.** Turn any request into a change with `doctrina work
26
- "<prompt>"` and follow the printed playbook (spec delta → tasks →
27
- implement → analyze → apply → archive → validate). Unsure what to do
28
- next? Run `doctrina next`. Need to read? Run `doctrina context`. Ask the
29
- human only on genuine ambiguity.
30
-
31
- ## Doctrina command surface (reach for these — don't hand-author)
32
-
33
- The CLI scaffolds from canonical templates and keeps `index.json` in sync,
34
- so prefer it over writing artifacts by hand. Full list: `doctrina --help`.
35
-
36
- - **Read / orient (any task, first & last):** `doctrina status` (health) ·
37
- `doctrina context [<cap>] --concat` (read pack) · `doctrina next` (what's
38
- next) · `doctrina why <cap>` (provenance) · `doctrina constitution`
39
- (standing rules) · `doctrina spec list` · `doctrina decision list` ·
40
- `doctrina search <query>`
41
- - **Start:** `doctrina work "<prompt>"` · `--from-diff` (backfill from
42
- existing code) · `--chore` (no-spec infra/docs/build)
43
- - **Scaffold (manual creation stays available):** `doctrina spec new <cap>`
44
- (`--bug`) · `doctrina decision new "<title>"` · `doctrina change new <id>`
45
- · `doctrina contract new <id>` · `doctrina skill new <slug>` · `doctrina
46
- intent add "<text>"` (new product anchor post-intake)
47
- - **Advance / close:** `doctrina change apply|archive|diff <id>` · `doctrina
48
- decision accept|land|supersede <n>` · `doctrina spec set <cap> [...]` ·
49
- `doctrina close <id>` (whole close in one pass, coverage scoped to the
50
- change)
51
- - **Gates (ground truth, not guesses):** `doctrina validate` (`--fix`) ·
52
- `doctrina verify` · `doctrina review` (conformance vs specs/ADRs) ·
53
- `doctrina coverage --strict` (`--run` executes cited proof) ·
54
- `doctrina trace --strict` · `doctrina contract check` ·
55
- `doctrina clarify --all` · `doctrina analyze <id>`
56
-
57
- Continuous: `doctrina watch` re-syncs and re-orients on every save.
58
- Capture lessons: `doctrina skill suggest` surfaces skills worth writing.
59
- After a CLI update: `doctrina upgrade --write` brings this project up.
25
+ - **Day-to-day.** Start every session with `doctrina prime` (gates, rules,
26
+ open work in one read). Turn any request into a change with `doctrina
27
+ work "<prompt>"` and follow the printed playbook (spec delta → tasks →
28
+ implement → close). Preview a close with `doctrina change check <id>`;
29
+ close with `doctrina close <id>`. Unsure what's next? `doctrina next`.
30
+ Before compaction or handover: `doctrina handoff`. Ask the human only on
31
+ genuine ambiguity.
32
+
33
+ <!-- doctrina:surface:begin — CLI-owned block, generated from the installed command catalog. Refreshed by `doctrina upgrade --write`; edits inside are overwritten. -->
34
+ ## Doctrina command surface (generated — reach for these, don't hand-author)
35
+
36
+ Every command, with the moment you reach for it. The CLI scaffolds from
37
+ canonical templates and keeps `index.json` in sync — prefer it over
38
+ hand-authoring. Flags and detail: `doctrina <command> --help`.
39
+ **Bootstrap**
40
+ - `doctrina init` — scaffold AGENTS.md and .doctrina/. *When:* starting a project that has no AGENTS.md yet.
41
+ - `doctrina intake` — store the intent and print the bootstrap playbook. *When:* you have a full project description and no specs yet.
42
+ - `doctrina adapter list|add|remove` — install/remove agent adapters (additive). *When:* adding or removing an agent's pointer files.
43
+ **Orient**
44
+ - `doctrina prime (session start)` — gates, standing rules, and open work in one read. *When:* at the START of every session.
45
+ - `doctrina context [<cap>] --for "<task>" --concat` — the read pack, assembled to fit a token budget. *When:* before working on any task, to load the right files.
46
+ - `doctrina show` — point-read a single artifact by reference. *When:* you need one requirement, criterion, or ADR, not a file.
47
+ - `doctrina search` — search the artifact tree, grouped by category. *When:* you do not know which artifact mentions a term.
48
+ - `doctrina status` — index, coverage, trace, and artifact counts. *When:* you need the health of the tree at a glance.
49
+ - `doctrina next` — the recommended next workflow action. *When:* you finished something and do not know what follows.
50
+ - `doctrina why` — provenance: intent, proof, ADRs, and history. *When:* you need to justify or trace a capability's existence.
51
+ - `doctrina handoff (before compaction/handover)` — a resume note: open work, task state, next command. *When:* BEFORE compaction or handing over to another session.
52
+ - `doctrina constitution` — accepted ADRs and product non-goals. *When:* you need the standing rules before deciding something.
53
+ **Change**
54
+ - `doctrina work "<prompt>" (--capability · --chore · --from-diff · --quiet)` — scaffold a change and print the playbook to execute. *When:* any request arrives that changes behaviour.
55
+ - `doctrina spec new|list|set` — create, list, and edit capability specs. *When:* a capability needs creating or its headers advancing.
56
+ - `doctrina change new|apply|archive|check|tick|diff|abandon` — new / apply / archive / check / tick / diff / abandon. *When:* driving a change through its lifecycle by hand.
57
+ - `doctrina contract new|list|check` — own and verify the integration surface. *When:* the change touches ports, env vars, or public endpoints.
58
+ - `doctrina decision new|accept|land|supersede|list|scope` — record, accept, land, scope, and supersede ADRs. *When:* the change decides something a later session must not relitigate.
59
+ - `doctrina skill new|list|sync|suggest` — capture on-demand procedural memory. *When:* a lesson is worth not relearning.
60
+ - `doctrina intent add|list` — append and list product intent anchors. *When:* new product intent appears after the intake.
61
+ **Gate**
62
+ - `doctrina analyze` — structural pre-flight on a change folder. *When:* before applying a change.
63
+ - `doctrina clarify --all (--lang pt|en)` — smell-test Markdown for ambiguity. *When:* before applying, or before opening a PR.
64
+ - `doctrina validate (--fix)` — schema, structure, EARS, and index drift. *When:* after any artifact edit, and before considering work done.
65
+ - `doctrina coverage --strict` — acceptance criteria against cited evidence. *When:* before claiming a capability is proven.
66
+ - `doctrina trace --strict` — intent provenance across the tree. *When:* checking that product intent still maps to capabilities.
67
+ - `doctrina review` — conformance of your changes vs specs/ADRs/contracts. *When:* before handing work back, to self-review it.
68
+ - `doctrina verify` — the project's declared typecheck/test/build checks. *When:* the real build gate must run.
69
+ - `doctrina close <id...>` — the whole closing sequence in one attested pass. *When:* a change is implemented and ready to finish.
70
+ - `doctrina doctor` — aggregate diagnostic with per-finding remedies. *When:* something looks wrong and you do not know which gate to ask.
71
+ **Maintain** (triggers: `doctrina <command> --help`) — `doctrina templates list|check|update` · `doctrina hooks install` · `doctrina index rebuild` · `doctrina watch` · `doctrina metrics` · `doctrina report` · `doctrina completion` · `doctrina upgrade --write`
72
+ <!-- doctrina:surface:end -->
60
73
 
61
74
  ## Stack and tooling
62
75
 
@@ -88,55 +101,38 @@ After a CLI update: `doctrina upgrade --write` brings this project up.
88
101
  - Archived changes in `.doctrina/changes/archive/` are out of the default
89
102
  read path; consult only when explicitly debugging history.
90
103
 
91
- ## Artifact invariants (verbatim — `doctrina validate` enforces these)
92
-
93
- Scaffold artifacts with the CLI (`doctrina decision new`, `doctrina work`),
94
- which writes from the canonical templates. Do NOT hand-author these files
95
- from memory. If you must write one by hand, match these exactly:
96
-
97
- - **Metadata headers come in two forms — do not mix them up:**
98
- - ADRs, change proposals, and the intake use **list items**:
99
- `- **Status:** accepted`, `- **Date:** 2026-06-13`.
100
- - Specs use **bare bold** (no leading `- `):
101
- `**Status:** active`, `**Version:** 0.1.0`.
102
- Match the template for the artifact you are writing.
103
- - **ADR filename** must be `NNNN-slug.md` — four digits, e.g.
104
- `0001-jwt-algorithm.md`. `ADR-001-...md` or `1-...md` is invisible to
105
- `doctrina decision accept`, the index, and the orphan check.
106
- - **Change folder** at `.doctrina/changes/<id>/` must contain a file named
107
- exactly `proposal.md` (not `change.md`, not `README.md`). `tasks.md` and
108
- `design.md` are optional siblings.
109
- - **Spec** lives at `.doctrina/specs/<capability>/spec.md` and its
110
- `**Version:**` header must equal the `version` recorded for it in
111
- `.doctrina/index.json`.
112
- - **Every artifact on disk** must be registered in `.doctrina/index.json`,
113
- and every path in `index.json` must exist on disk. Update the index in
114
- the same change that adds or moves a file.
115
-
116
- Always finish by running `doctrina validate` and resolving every `error:`
117
- before considering work done.
104
+ ## Artifact invariants (`doctrina validate` enforces these)
105
+
106
+ Scaffold with the CLI; do not hand-author from memory. If you must:
107
+
108
+ - **Headers:** ADRs / proposals / intake use list items
109
+ (`- **Status:** accepted`); specs use bare bold (`**Status:** active`).
110
+ - **ADR filename:** `NNNN-slug.md`, four digits. Other shapes are invisible
111
+ to `decision accept`, the index, and the orphan check.
112
+ - **Change folder:** `.doctrina/changes/<id>/proposal.md`, that exact name.
113
+ - **Spec:** `.doctrina/specs/<cap>/spec.md`; its `**Version:**` must equal
114
+ the version recorded in `index.json`.
115
+ - **Every artifact** is registered in `index.json`, and every indexed path
116
+ exists. Update the index in the same change.
117
+
118
+ Finish by running `doctrina validate` and resolving every `error:`.
118
119
 
119
120
  ## How to read context efficiently
120
121
 
121
122
  `doctrina context [<capability>] --concat` assembles the read pack in one
122
- call, in order: this `AGENTS.md` → `.doctrina/product.md` → the capability
123
- spec → open `.doctrina/changes/<id>/` → `.doctrina/decisions/` filtered to
124
- `Status: accepted`. Run it for ANY task, not only `doctrina work`; it skips
125
- `changes/archive/` (history — read only when debugging it).
123
+ call: this `AGENTS.md` → `product.md` → the capability spec → open changes →
124
+ accepted ADRs. Run it for ANY task. It skips `changes/archive/` (history).
126
125
 
127
- On demand only: if the task matches a skill in `.doctrina/skills/`, read its
128
- `description:` / `when:` frontmatter; load the full body when the trigger fires.
126
+ Skills are on demand: read the `description:` / `when:` frontmatter in
127
+ `.doctrina/skills/`; load a body only when its trigger fires.
129
128
 
130
- Keep this file under 150 lines. Density beats prose. Use exact commands.
129
+ Keep this file under 150 lines. Density beats prose.
131
130
 
132
131
  ## Definition of done
133
132
 
134
- A change is done when:
135
- - All tasks in the change's `tasks.md` are checked.
136
- - Deltas have been merged into affected spec files.
137
- - The change folder has been moved to `.doctrina/changes/archive/`.
138
- - Any architectural decisions are recorded as ADRs with `Status: accepted`.
139
- - `.doctrina/index.json` has been updated.
133
+ `doctrina close <id>` is the definition: tasks checked, deltas merged into
134
+ specs, gates green, ADRs recorded and accepted, change archived, index
135
+ updated. If close refuses, the change is not done.
140
136
 
141
137
  ## What never goes in this file
142
138
 
@@ -7,21 +7,27 @@
7
7
  For ADDED: include the full new spec body below. On apply, the body is
8
8
  written verbatim to the target path.
9
9
 
10
- For MODIFIED: include only the sections that change, with clear
11
- before/after markers. Bookkeeping edits (flip a criterion, bump the
12
- version, set a header) can be made mechanical by adding a fenced `ops`
13
- block — on apply the CLI executes it against the target spec, all ops or
14
- none (ADR 0007). Anything the ops verbs cannot express (rewriting prose)
15
- stays a by-hand merge; a MODIFIED delta with no `ops` block prints a
16
- manual-merge pointer.
10
+ For MODIFIED: prefer a fenced `ops` block — on apply the CLI executes it
11
+ against the target spec, all ops or none (ADR 0007). The verbs cover
12
+ headers, acceptance criteria, AND the EARS requirement bullets, so a
13
+ typical delta applies mechanically end to end; only free-prose rewrites
14
+ (Purpose, Maturity, ...) stay a by-hand merge. A MODIFIED delta with no
15
+ `ops` block prints a manual-merge pointer.
17
16
 
18
17
  ```ops
19
18
  set-header Implementation: verified — durable adapter (`src/db.ts`)
20
19
  bump-version minor
21
20
  set-criterion 1: verified
22
21
  append-criterion [unverified] new signal — verified by `test/x.test.ts`
22
+ append-requirement event: When <trigger>, the system shall <action>.
23
+ replace-requirement ubiquitous 2: The system shall <action>.
23
24
  ```
24
25
 
26
+ Requirement sections: ubiquitous | event | state | unwanted | optional.
27
+ append-* ops resolve numbering/position at APPLY time, so several open
28
+ changes appending to the same spec never collide on numbers — order of
29
+ application decides.
30
+
25
31
  For REMOVED: the body may be empty; on apply, the target spec file is
26
32
  deleted and the capability is recorded in the change archive only.
27
33
  -->