@nikovirtala/adr 0.1.0 → 0.3.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 (40) hide show
  1. package/README.md +70 -9
  2. package/dist/cli.js +821 -61
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.js +3 -3
  5. package/dist/{kind-DqFhApu7.js → kind-DjvA3dyA.js} +10 -23
  6. package/dist/kind-DjvA3dyA.js.map +1 -0
  7. package/dist/kind.js +1 -1
  8. package/dist/scope-CLqH-q1y.js +2873 -0
  9. package/dist/scope-CLqH-q1y.js.map +1 -0
  10. package/dist/types/cli/accept.d.ts +2 -2
  11. package/dist/types/cli/deprecate.d.ts +3 -0
  12. package/dist/types/cli/for.d.ts +3 -0
  13. package/dist/types/cli/hooks.d.ts +6 -0
  14. package/dist/types/cli/index-command.d.ts +3 -0
  15. package/dist/types/cli/init.d.ts +3 -0
  16. package/dist/types/cli/link.d.ts +3 -0
  17. package/dist/types/cli/list.d.ts +1 -1
  18. package/dist/types/cli/new.d.ts +1 -1
  19. package/dist/types/cli/note.d.ts +3 -0
  20. package/dist/types/cli/open.d.ts +2 -2
  21. package/dist/types/cli/reject.d.ts +3 -0
  22. package/dist/types/cli/scope.d.ts +7 -0
  23. package/dist/types/cli/supersede.d.ts +1 -1
  24. package/dist/types/cli/text.d.ts +39 -3
  25. package/dist/types/cli/withdraw.d.ts +3 -0
  26. package/dist/types/commit-actions.d.ts +72 -0
  27. package/dist/types/config.d.ts +16 -2
  28. package/dist/types/hooks.d.ts +59 -0
  29. package/dist/types/index.d.ts +6 -2
  30. package/dist/types/init.d.ts +33 -0
  31. package/dist/types/log-index.d.ts +117 -0
  32. package/dist/types/log.d.ts +34 -1
  33. package/dist/types/scope.d.ts +51 -0
  34. package/dist/types/verify.d.ts +6 -4
  35. package/dist/types/views.d.ts +9 -3
  36. package/dist/types/write.d.ts +206 -26
  37. package/package.json +2 -2
  38. package/dist/kind-DqFhApu7.js.map +0 -1
  39. package/dist/write-C3IW5WrA.js +0 -1011
  40. package/dist/write-C3IW5WrA.js.map +0 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Architecture decision records kept as event logs in git, built on [`@nikovirtala/ledger`](https://www.npmjs.com/package/@nikovirtala/ledger). A decision is a Markdown body plus append-only event files. Its status (proposed, accepted, rejected, withdrawn, deprecated, superseded) is computed from the events, the body is frozen by its hash once accepted, and supersession chains always lead to the decision in force. See the [design doc](https://github.com/nikovirtala/ark/blob/main/docs/01-adr-v1.md).
4
4
 
5
- This is phase 1 ("Core"), released at 0.x: the decision kind, the library and the `adr` CLI with `new`, `accept`, `supersede`, `list`, `show` and `verify`.
5
+ Released at 0.x. Phase 1 ("Core") brought the decision kind, the library and the `adr` CLI with `new`, `accept`, `supersede`, `list`, `show` and `verify`. Phase 2a ("Commands and Scope") adds `init`, `reject`, `withdraw`, `deprecate`, `note`, `link`, `scope` and `for`, `accept --copy-scope`, Conventional Commits messages for `--commit`, and `ARK_ON_BEHALF_OF` for agents. Phase 2b ("Guardrails") adds git hooks (`adr hooks`), a generated `index.md` that every write keeps fresh (`adr index`), display numbers in shallow clones read from that index, `list --since`, a recovery hint when git refuses a `--commit`, and verify checks for scope globs, code anchors, changes under inactive decisions and narrowed scopes.
6
6
 
7
7
  ## Install
8
8
 
@@ -11,11 +11,14 @@ npm install --save-dev @nikovirtala/adr # Node 24 or newer, git 2.32.0 or newe
11
11
  npx @nikovirtala/adr --help # or run it without installing
12
12
  ```
13
13
 
14
+ adr needs Node 24 or newer (`engines: >=24`). On older Node, npm prints an `EBADENGINE` warning and adr isn't supported.
15
+
14
16
  ## Layout
15
17
 
16
18
  ```
17
19
  docs/adr/
18
20
  adr.toml # optional config (or adr.toml at the repository root)
21
+ index.md # generated, with [log] index = "committed"
19
22
  decisions/k3f9q8a1-use-aurora-for-orders.md
20
23
  events/k3f9q8a1/20261016T081030Z-p4d2-proposed.yaml
21
24
  events/k3f9q8a1/20261016T091512Z-7aq5-accepted.yaml
@@ -27,6 +30,9 @@ Each decision has a canonical id (`k3f9q8a1`). Accepted decisions also get a num
27
30
  ## Commands
28
31
 
29
32
  ```sh
33
+ # Set up: write adr.toml and starter templates; never overwrites a file.
34
+ adr init --template nygard --template madr --commit
35
+
30
36
  # Propose: render a draft from a template, write the body and the proposed event, and stage them.
31
37
  adr new "Use Aurora for orders" --section context="We need SQL." --section scope=services/orders
32
38
  adr new "Use Aurora Serverless" --supersedes ADR-0002 --template madr --edit
@@ -37,8 +43,27 @@ adr accept k3f9q8a1 --commit
37
43
  # Supersede an accepted decision by another accepted one.
38
44
  adr supersede ADR-0001 --by ADR-0002 --reason "Aurora fits the query load" --commit
39
45
 
46
+ # End a decision's life: reject or withdraw a proposal, deprecate an accepted decision.
47
+ adr reject k3f9q8a1 --reason "Too early" --commit
48
+ adr withdraw k3f9q8a1 --commit # --reason is optional
49
+ adr deprecate ADR-0003 --reason "Moving to a managed service" --commit
50
+
51
+ # Annotate: a note in any state, and typed links (relates-to, refines, depends-on).
52
+ adr note ADR-0003 "Benchmarks are in the wiki" --commit
53
+ adr link ADR-0004 ADR-0002 --rel refines --commit
54
+ adr link ADR-0004 platform:k3f9q8a1 # a decision in a configured [[sources]] log
55
+
56
+ # Scope: the code a decision governs, as globs, and which decisions govern a file.
57
+ adr scope ADR-0004 --set 'services/orders/**' --set 'libs/db/**'
58
+ adr scope ADR-0004 --add 'services/billing/**' --remove 'libs/db/**' --commit
59
+ adr scope ADR-0004 --clear
60
+ adr scope --follow-renames # after git mv: update the globs, stage, never commit
61
+ adr for services/orders/api.ts
62
+ adr for services/orders/api.ts --ref v1.2.0
63
+
40
64
  # Read: list with computed status, show one decision with its state header.
41
65
  adr list --status accepted
66
+ adr list --since ORIG_HEAD # only decisions with events added since a revision
42
67
  adr show ADR-0001 --history
43
68
  adr list --ref v1.2.0 # time travel: the log as of any ref
44
69
 
@@ -46,10 +71,28 @@ adr list --ref v1.2.0 # time travel: the log as of any ref
46
71
  adr verify
47
72
  adr verify --base origin/main --format github
48
73
  adr verify --staged
74
+
75
+ # The generated index (with [log] index = "committed"): regenerate it, or check that it is current.
76
+ adr index
77
+ adr index --check
78
+
79
+ # Git hooks: install adr in ledger's shared hook shims, or print the config for a hook manager.
80
+ adr hooks install
81
+ adr hooks print --manager lefthook
49
82
  ```
50
83
 
51
84
  - `new` takes `--template <name>` (default `nygard`; built-ins `nygard`, `madr`, `y-statement`, or your own `<root>/templates/<name>.md`), `--section <id>=<markdown>` (repeatable), `--supersedes <decision>` (repeatable), and `--edit`/`--no-edit`. It opens `$VISUAL` or `$EDITOR` with `--edit`, or by default in an interactive terminal; an editor failure never loses your edits and never commits content you didn't confirm.
85
+ - `new --no-edit --commit` (or `--commit` with no editor) refuses a draft with unfilled required sections: exit 1, nothing written. Without `--commit` the draft is staged with a warning on stderr; after an editor, a draft that still has unfilled sections stays staged and isn't committed.
86
+ - `accept` of a decision that supersedes others offers their scope globs: `--copy-scope` copies them in the same write, `--no-copy-scope` doesn't, and without either it asks `[y/N]` in a terminal and otherwise prints the `adr scope … --add …` command that would copy them.
87
+ - `scope` takes `--set <glob>` (repeatable; replaces the set), `--add`/`--remove <glob>` (repeatable) or `--clear`, and stores the set sorted and deduplicated. It notes a glob that matches no tracked file and a narrowing of an accepted decision. verify requires the globs of proposed and accepted decisions to match tracked files (`scope/glob-unmatched`), so with hooks installed `adr scope <proposed> --set 'src/payments/**' --commit` for code not written yet writes and stages the scope, then fails in pre-commit with the recovery hint below, and its note says so. To finish it, commit the code the glob should match first (`git add` it, then `git commit -m "<subject>" -- <its paths>`) and then run the printed command, or `git add` the code and append its paths after `--` in the printed command. `scope --follow-renames [<decision>]` updates the globs of every decision (or one) for the staged renames, so a moved file stays governed, and only stages.
88
+ - `for <path>…` lists the decisions governing each file, from scope globs and code anchors, with a warning for decisions that aren't in force. A code anchor is a comment such as `// adr:<id>` or `# adr:<source>:<id>`: the token counts only after a comment leader on the same line (a heuristic), and anchors in binary files, submodules, the log directory and files matched by `[scope] anchor_exclude` are not found.
52
89
  - Writes stage their files and don't commit, unless you pass `--commit` or set `auto_commit`. A commit holds every file of the decisions it touches (body, events, template), so `adr verify --ref <commit>` is clean, and never your unrelated staged work. It refuses with exit 2 when a file it needs has unstaged changes or isn't tracked. Its `ADR: <id>` and `ADR-Event: <type>` trailers name one event each, in a fixed order, whatever your `trailer.*` config.
90
+ - `--commit` messages follow Conventional Commits: the subject comes from `[commit] subject` (default `docs(adr): {action} {title}`, for example `docs(adr): propose to use Aurora for orders`, `docs(adr): decide to use Aurora for orders`, `docs(adr): set the scope of ADR-0003`). The description starts with a lowercase letter and the rest keeps its natural casing (`Use` becomes `use`; `CLI`, `ARK_AGENT`, `GraphQL` and `Node 24` stay). `new`, `accept`, `reject` and `withdraw` name the decision by its title (`propose to`, `decide to`, `decide not to`, `withdraw the proposal to`), while `deprecate`, `supersede`, `note`, `link` and `scope` name it by its number or id. A title that would make the description longer than 72 characters is shortened with `…`, at a word boundary when one is near the limit, the body then starts with `Full title: <title>`, and a note says so; numbers and ids are never shortened. `-m/--message <text>` replaces the subject and body as given; a message that ends in its own trailer block as git reads it, such as `Co-authored-by:` or `Refs:` lines, gets adr's trailers appended to that paragraph. The trailers are always the last paragraph, so `git log --grep "ADR: <id>"` finds a decision's commits.
91
+ - When git refuses a `--commit` (a failing hook, signing), the write stays written and staged, and adr exits 2 (`commit-failed`) with a recovery hint: git's error, the staged paths, the trailers, and the exact command that makes the commit, `git -C <top> commit --cleanup=whitespace -F <git dir>/ark/COMMIT_MSG --only -- <paths>`, with the full message saved in that file (edit it if needed, but keep the trailers). Don't run the adr command again: the log already holds the change, so a rerun would be refused, do nothing, or write it a second time. When `index.md` is among the paths, the hint ends with `Then run adr index --no-commit to restore other decisions' entries in docs/adr/index.md.` The notes the write would have reported are printed as warnings before the hint.
92
+ - With `[log] index = "committed"`, every write keeps `<root>/index.md` current: the accepted and proposed decisions, then the superseded, deprecated, rejected and withdrawn ones, each with its number, linked title, status and date, and a last line recording the numbers. A `--commit` renders it from exactly the tree the commit holds and includes it whenever the commit changes it; the work-tree copy keeps other decisions' uncommitted entries. Numbers are projected: on a branch they are the numbers its acceptances will get once it merges, after main's (`[log] main_branch`), also when main was merged into the branch. When a write leaves the staged `index.md` listing another decision's untracked or unstaged files, it notes them, since the next plain commit's hook reports `index/stale` until they are staged. `adr index` regenerates and stages it, `adr index --commit` commits it as `docs(adr): regenerate the decision index`, and `adr index --check` exits 1 when it is stale or missing.
93
+ - `list --since <rev>` lists only the decisions with event files added between `<rev>` and HEAD (or `--ref`), each with the new event types, such as `[new: accepted]`; it prints nothing when the log didn't change.
94
+ - In a shallow clone, numbers need history the clone lacks. With a committed index, adr reads them from `index.md` in the commit being read (`--ref`, else HEAD) and notes `numbers come from docs/adr/index.md (shallow clone)`; without one, decisions display by id until you run `git fetch --unshallow`. Nothing is fetched automatically.
95
+ - `hooks install` registers adr in ledger's shims, one per hook and shared with other ark tools: `pre-commit` runs `adr hooks run pre-commit`, `commit-msg` runs `adr hooks trailers` (adds `ADR:` and `ADR-Event:` trailers when event files are staged, unless the message has them or a merge is in progress), `pre-push` runs `adr verify --base @{upstream} --ref HEAD`, which checks the current branch's commits against its upstream whichever refs the push names (without an upstream, against `origin`'s default branch; with no remote, the whole log), and `post-merge` runs `adr list --since ORIG_HEAD`. It never overwrites a foreign hook (it writes the other hooks, exits 2 and names the line to add to that hook) and writes nothing when `core.hooksPath` is set (exit 2, pointing to `adr hooks print --manager lefthook|husky|pre-commit` for the hook manager in use). `hooks uninstall` removes adr from the shims. The pre-commit steps are rename following (`[hooks] scope_follow_renames`), the index (checked, or regenerated and staged with `[hooks] index = "stage"`), then `verify --staged`. The hook stages only into the commit's own index: for `git commit <paths>`, a rename that changes a decision's scope stops the commit and names the command to run. When the staged `index.md` lists decision files that aren't staged, the `index/stale` finding names them; stage them, or move them out of the work tree and run `adr index`.
53
96
  - `show` leads with a state header. A decision that isn't in force says so and names what to read instead, for example `SUPERSEDED by ADR-0002 (accepted 2026-10-18). Do not apply this decision; read ADR-0002 instead.`
54
97
 
55
98
  Every command takes `--json`, `--root <dir>` (the log directory) and `--help`; reads also take `--ref <ref>`, and writes refuse it.
@@ -57,10 +100,10 @@ Every command takes `--json`, `--root <dir>` (the log directory) and `--help`; r
57
100
  ## Exit codes and JSON
58
101
 
59
102
  - **0**: success.
60
- - **1**: failing findings from `verify`, or a write the log's rules forbid (an illegal transition, a draft that fails its template lint, an agent's acceptance, an unaccepted successor). Nothing is written, and the findings are in the output.
61
- - **2**: bad usage (unknown command, flag or decision, a missing argument, `--ref` on a write), and config or environment errors.
103
+ - **1**: failing findings from `verify` (or `index --check`, or a hook), or a write the log's rules forbid (an illegal transition, a draft that fails its template lint, an agent's acceptance, an unaccepted successor). Nothing is written, and the findings are in the output.
104
+ - **2**: the tool can't run: bad usage (unknown command, flag or decision, a missing argument, `--ref` on a write), config, environment or internal errors. Nothing is written, except when git refuses a `--commit` (`commit-failed`): the write is then staged and the error says how to finish the commit.
62
105
 
63
- With `--json`, stdout carries exactly one JSON document: `adr-list/v1`, `adr-show/v1`, `adr-write/v1` (for `new`, `accept` and `supersede`), ledger's `ledger-findings/v1` for `verify`, or `ark-error/v1` (`{ "format": "ark-error/v1", "error": { "code", "message" } }`) when the command exits 2. Every key is always present, with `null` where a value is unknown. Warnings and notes go to stderr.
106
+ With `--json`, stdout carries exactly one JSON document: `adr-list/v1` (with `since`, `null` without `--since`), `adr-show/v1`, `adr-write/v1` (for every write command), `adr-for/v1`, `adr-init/v1`, `adr-index/v1`, `adr-hooks/v1`, ledger's `ledger-findings/v1` for `verify`, or `ark-error/v1` (`{ "format": "ark-error/v1", "error": { "code", "message" } }`) when the command exits 2; a `commit-failed` error also has the write's `notes`. Every key is always present, with `null` where a value is unknown. A `numbering` object's `reason` is `"index"` when a shallow clone's numbers come from `index.md`. In a shallow clone with a committed index, `adr-write/v1`'s `decision.number` comes from the index in HEAD, which on a branch is the number the acceptance will get once the branch merges. Warnings and notes go to stderr.
64
107
 
65
108
  ## Config (`adr.toml`)
66
109
 
@@ -71,7 +114,7 @@ Every key is optional.
71
114
  root = "docs/adr" # read from <repo>/adr.toml; the default
72
115
  default_template = "nygard"
73
116
  main_branch = "origin/main" # the ref numbers come from; default origin/HEAD, origin/main, main, …
74
- index = "none" # validated now, used in phase 2
117
+ index = "none" # or "committed": adr index, fresh on every write, checked in verify
75
118
 
76
119
  [policy]
77
120
  accept_requires_human = true # refuse acceptances by an agent
@@ -80,13 +123,31 @@ mcp_can_decide = false # validated now, used in phase 3
80
123
 
81
124
  [verify]
82
125
  fail_on = "error" # or "warning"
126
+ governed_by_inactive = "warning" # or "error": a change under a superseded or deprecated decision
127
+
128
+ [commit]
129
+ subject = "docs(adr): {action} {title}" # the default; --message overrides it
130
+
131
+ [scope]
132
+ anchor_keyword = "adr" # the default: anchors read adr:<id>
133
+ anchor_exclude = ["**/*.md"] # files never searched for anchors (docs that show examples); default []
134
+
135
+ [hooks]
136
+ scope_follow_renames = "stage" # stage, warn or off: pre-commit's rename following
137
+ index = "check" # check, or stage to regenerate index.md in pre-commit
83
138
  ```
84
139
 
140
+ verify also checks code against the log: `scope/glob-invalid` (error) for a stored glob that doesn't parse, `scope/glob-unmatched` (error) for a glob of a proposed or accepted decision that matches no tracked file, `scope/anchor-missing` (error) for an `adr:<id>` anchor naming no decision in the log (qualified anchors are checked in ark's step 4), `decision/governed-by-inactive` (a warning, or an error with `governed_by_inactive = "error"`) for a changed file governed by a superseded or deprecated decision, and `decision/scope-narrowed` (warning) when a new scope stops covering files that still exist. Deprecated decisions' globs no longer have to match files. With `index = "committed"`, `index/missing` and `index/stale` are errors, and `index/unchecked` warns in a shallow clone without a recorded index.
141
+
142
+ `[commit] subject` is one line with `{title}` (what names the decision: its title with an ordinary capitalized first word lowercased (`Use` → `use`, so a single-capital proper noun such as `Aurora` loses that capital; `CLI`, `GraphQL` and `ARK_AGENT` stay), or its number or id), `{raw_title}` (the same with its case kept), `{action}`, `{id}`, `{display}` and `{command}`. It is checked when the config is read: at most one title placeholder, after the type and scope, and room within 72 characters for the title (20 characters) and, uncut, for the longest number-based name (`ADR-0001 to a decision in another log`); an invalid template exits 2. Whatever the template, the description's first letter is lowercased.
143
+
85
144
  The config is `<repo>/adr.toml`, whose `[log] root` chooses the log directory, or `<root>/adr.toml`. `--root` uses a repository-level file that names the same root, and overrides one that names another root with a warning.
86
145
 
87
146
  ## Agents
88
147
 
89
- An agent using the CLI sets `ARK_AGENT=<agent-id>`. Its events are recorded as the agent, acting on behalf of the git user, and with `accept_requires_human` on (the default) `adr accept` refuses them with exit 1 (`decision/agent-accepted`). The git identity comes from `user.name` and `user.email` and is never guessed.
148
+ An agent using the CLI sets `ARK_AGENT=<agent-id>`, and `ARK_ON_BEHALF_OF=<email>` for the person it acts for. Its events are recorded as the agent, acting on behalf of that address. Without `ARK_ON_BEHALF_OF` they are recorded on behalf of the git user, and every write says so in a note on stderr and in the JSON `notes`: `on_behalf_of taken from the git identity <email>; set ARK_ON_BEHALF_OF to name who you act for`. An `ARK_ON_BEHALF_OF` that isn't an email address exits 2 before anything is written; without `ARK_AGENT` it is ignored, with a note. With `accept_requires_human` on (the default), `adr accept` refuses an agent with exit 1 (`decision/agent-accepted`), and `adr new` tells the agent to ask a human to review and accept.
149
+
150
+ The git identity is git's author identity (`git var GIT_AUTHOR_IDENT` with `user.useConfigOnly`): `GIT_AUTHOR_NAME` and `GIT_AUTHOR_EMAIL` when set, else `user.name` and `user.email`; it is never guessed. Setting `GIT_AUTHOR_*` also changes the author of `--commit` commits, which is why agents should use `ARK_ON_BEHALF_OF` instead. `--commit` also needs a committer identity, and exits 2 before writing without one.
90
151
 
91
152
  ## Library
92
153
 
@@ -101,7 +162,7 @@ const { decisions } = listDecisions(read, { status: ["accepted"] });
101
162
  const findings = await verifyDecisions(log, { type: "full" });
102
163
  ```
103
164
 
104
- `proposeDecision`, `acceptDecision` and `supersedeDecision` write, `resolveDecision` turns an id or number into an id, and `stateHeader` gives the header `show` prints.
165
+ `initDecisionLog`, `proposeDecision`, `acceptDecision`, `rejectDecision`, `withdrawDecision`, `deprecateDecision`, `supersedeDecision`, `noteDecision`, `linkDecision`, `scopeDecision` and `followScopeRenames` write, `decisionsFor` answers `adr for`, `resolveDecision` turns an id or number into an id, and `stateHeader` gives the header `show` prints. `indexDecisionLog` and `renderDecisionIndex` regenerate or render the index, and `installDecisionHooks`, `uninstallDecisionHooks`, `printDecisionHooks`, `runPreCommitHook` and `addHookTrailers` are the hook commands.
105
166
 
106
167
  `@nikovirtala/adr/kind` exports only the decision kind (`adrKind`, made with ledger's `defineKind`) and its types, without any CLI code, for tools that fold decision logs themselves, such as issues linking to decisions:
107
168
 
@@ -111,6 +172,6 @@ import { adrKind } from "@nikovirtala/adr/kind";
111
172
 
112
173
  ## Not yet included
113
174
 
114
- - **Reference checks are local in phase 1.** `verify` checks that `supersedes`, `superseded.by` and `linked.to` name decisions in the same log. Qualified references to other logs (`<source>:<id>`) are skipped; no phase 1 command writes them.
115
- - **Phase 2:** `init`, `reject`, `withdraw`, `deprecate`, `note`, `link`, `scope` and `for`; git hooks; a generated index (and the number fallback for shallow clones); scope globs and code anchors; cross-log reference checks and listing across sources.
175
+ - **Reference checks are local.** `verify` checks that `supersedes`, `superseded.by` and `linked.to` name decisions in the same log. Qualified references to other logs (`<source>:<id>`, written by `adr link`) and qualified anchors are skipped until ark's step 4.
116
176
  - **Phase 3:** an MCP server, a SKILL.md for agents, and search.
177
+ - **ark's step 4, with issues:** cross-log reference checks at the pinned ref and listing across sources; until then `link` stores a qualified target unchecked.