@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
@@ -0,0 +1,3 @@
1
+ import { type CommandSpec } from "@nikovirtala/ledger/cli";
2
+ /** `adr reject` (design §6.3): a proposal that won't be adopted. */
3
+ export declare const rejectCommand: CommandSpec;
@@ -0,0 +1,7 @@
1
+ import { type CommandSpec } from "@nikovirtala/ledger/cli";
2
+ /**
3
+ * `adr scope <decision> --set|--clear|--add|--remove …` (design §6.8): the globs of the code a
4
+ * decision governs, written as one whole-set `scoped` event. `adr scope [<decision>]
5
+ * --follow-renames` rewrites them after staged renames and stages the events, never committing.
6
+ */
7
+ export declare const scopeCommand: CommandSpec;
@@ -1,3 +1,3 @@
1
- import type { CommandSpec } from "@nikovirtala/ledger/cli";
1
+ import { type CommandSpec } from "@nikovirtala/ledger/cli";
2
2
  /** `adr supersede <decision> --by <decision> …` (design §5.6). */
3
3
  export declare const supersedeCommand: CommandSpec;
@@ -1,16 +1,52 @@
1
+ import { type Actor } from "@nikovirtala/ledger";
2
+ import type { InitResultJson } from "../init.js";
3
+ import type { ChangedSince } from "../log.js";
4
+ import type { DecisionsForJson } from "../scope.js";
1
5
  import type { DecisionListJson, DecisionShowJson } from "../views.js";
2
- import type { WriteResultJson } from "../write.js";
6
+ import type { ScopeOffer, WriteResultJson } from "../write.js";
3
7
  /** How a decision id is shown: its display (`ADR-0007`), or the id when it has no number. */
4
8
  export type Display = (id: string) => string;
5
9
  /** `adr list`: one row per decision, `→ <effective>` when it differs from the decision. */
6
10
  export declare function listText(doc: DecisionListJson, display: Display): string;
7
11
  /**
8
- * The text of `adr new|accept|supersede` (design §5.6). `subject` names what a refused command
9
- * was about; `number` is the decision's number in the write result, if it has one now.
12
+ * `adr list --since <rev>` (design 2b D7): a heading, then each row followed by the event types
13
+ * added since `rev`; nothing at all when no decision changed, so the post-merge hook stays quiet.
14
+ */
15
+ export declare function sinceText(doc: DecisionListJson, since: ChangedSince, display: Display): string;
16
+ /**
17
+ * The stderr warning of `new` when the draft it wrote has unfilled sections (design §7.2), or
18
+ * `null` when there are none.
19
+ */
20
+ export declare function unfilledWarning(doc: WriteResultJson): string | null;
21
+ export interface FollowRenamesBefore {
22
+ readonly before: ReadonlyMap<string, readonly string[]>;
23
+ readonly renamed: boolean;
24
+ }
25
+ /**
26
+ * The text of a write command (design §5.6, §6.1). `subject` names what a refused command was
27
+ * about; `number` is the decision's number in the write result, if it has one now; `reason` is
28
+ * the reason a lifecycle exit recorded.
10
29
  */
11
30
  export declare function writeText(doc: WriteResultJson, display: Display, o: {
12
31
  readonly subject: string;
13
32
  readonly number: string | null;
33
+ readonly reason?: string | null;
34
+ /** The decision's globs before a `scope` write. */
35
+ readonly scopeBefore?: readonly string[];
36
+ /** For `scope --follow-renames`: every decision's globs before, and whether renames were staged. */
37
+ readonly followRenames?: FollowRenamesBefore;
38
+ /** The superseded scope an `accept` copied. */
39
+ readonly copied?: ScopeOffer | null;
40
+ /** Who proposed with `new`, and the log's `accept_requires_human`, for the next step. */
41
+ readonly actor?: Actor;
42
+ readonly acceptRequiresHuman?: boolean;
14
43
  }): string;
15
44
  /** `adr show`: the state header, the decision's fields and its body. */
16
45
  export declare function showText(doc: DecisionShowJson, display: Display): string;
46
+ /**
47
+ * `adr for`: per path, one row per decision (named, status, title, how it matched), its warning
48
+ * below it when it isn't in force, then the anchors that name no decision of this log.
49
+ */
50
+ export declare function forText(doc: DecisionsForJson, display: Display, keyword: string): string;
51
+ /** `adr init`: what was written and kept, then the next step; or that nothing was needed. */
52
+ export declare function initText(doc: InitResultJson): string;
@@ -0,0 +1,3 @@
1
+ import { type CommandSpec } from "@nikovirtala/ledger/cli";
2
+ /** `adr withdraw` (design §6.4): a proposal its author takes back. */
3
+ export declare const withdrawCommand: CommandSpec;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * `{action}` of a commit that writes one event of each type (design §4.3), and what the title slot
3
+ * names: the decision's title for the events that change whether it is decided, else its display.
4
+ */
5
+ export declare const ACTIONS: {
6
+ readonly proposed: {
7
+ readonly action: "propose to";
8
+ readonly names: "title";
9
+ };
10
+ readonly accepted: {
11
+ readonly action: "decide to";
12
+ readonly names: "title";
13
+ };
14
+ readonly rejected: {
15
+ readonly action: "decide not to";
16
+ readonly names: "title";
17
+ };
18
+ readonly withdrawn: {
19
+ readonly action: "withdraw the proposal to";
20
+ readonly names: "title";
21
+ };
22
+ readonly deprecated: {
23
+ readonly action: "deprecate";
24
+ readonly names: "display";
25
+ };
26
+ readonly superseded: {
27
+ readonly action: "supersede";
28
+ readonly names: "display";
29
+ };
30
+ readonly noted: {
31
+ readonly action: "add a note to";
32
+ readonly names: "display";
33
+ };
34
+ readonly linked: {
35
+ readonly action: "link";
36
+ readonly names: "display";
37
+ };
38
+ readonly scoped: {
39
+ readonly action: "set the scope of";
40
+ readonly names: "display";
41
+ };
42
+ };
43
+ /** `{action}` of `adr index --commit`, whose title slot holds `the decision index`. */
44
+ export declare const INDEX_ACTION = "regenerate";
45
+ /** What `adr index --commit`'s title slot holds. */
46
+ export declare const INDEX_TITLE = "the decision index";
47
+ /** The longest `{action}`, which `[commit] subject` must leave room for. */
48
+ export declare const LONGEST_ACTION: number;
49
+ /** The longest display: `ADR-` and up to 9 digits (`formatDecisionNumber`, kind/project.ts). */
50
+ export declare const DISPLAY_LENGTH = 13;
51
+ /** What a link's title slot names after the display when the target is in another log. */
52
+ export declare const CROSS_LOG_LINK = "to a decision in another log";
53
+ /** adr's commit-subject placeholders, each with its longest value (design §4.2). */
54
+ export declare const COMMIT_VARS: Readonly<{
55
+ action: number;
56
+ id: 8;
57
+ display: 13;
58
+ command: 9;
59
+ }>;
60
+ /**
61
+ * The names the title placeholder holds instead of a title, which are never shortened, each with
62
+ * its action: supersede's `<display> with <display>` and a link's `<display> to <display>` or
63
+ * `<display> to a decision in another log` (`planLink` in write.ts), and `adr index`'s
64
+ * `the decision index`. The shorter names (a display, at most 13 characters) always fit in the
65
+ * room a title gets.
66
+ */
67
+ export declare const COMMIT_NAMES: readonly {
68
+ length: number;
69
+ vars: {
70
+ action: number;
71
+ };
72
+ }[];
@@ -1,11 +1,13 @@
1
- import { type Severity, type ToolConfig } from "@nikovirtala/ledger";
1
+ import { type CommitTemplate, type Severity, type ToolConfig } from "@nikovirtala/ledger";
2
+ /** The default `[commit] subject`. */
3
+ export declare const DEFAULT_COMMIT_SUBJECT = "docs(adr): {action} {title}";
2
4
  /** adr's settings from `adr.toml` (design §5.3); every key is optional. */
3
5
  export interface AdrConfig {
4
6
  /** `[log] default_template`: the template `adr new` uses without `--template`. */
5
7
  readonly defaultTemplate: string;
6
8
  /** `[log] main_branch`: the ref numbers come from; `null` resolves it automatically. */
7
9
  readonly mainBranch: string | null;
8
- /** `[log] index`: validated now, used in phase 2. */
10
+ /** `[log] index`: `committed` keeps a generated `<root>/index.md` fresh and verified. */
9
11
  readonly index: "committed" | "none";
10
12
  /** `[policy] accept_requires_human`. */
11
13
  readonly acceptRequiresHuman: boolean;
@@ -15,6 +17,18 @@ export interface AdrConfig {
15
17
  readonly mcpCanDecide: boolean;
16
18
  /** `[verify] fail_on`. */
17
19
  readonly failOn: Severity;
20
+ /** `[verify] governed_by_inactive`: the severity of `decision/governed-by-inactive`. */
21
+ readonly governedByInactive: Severity;
22
+ /** `[hooks] scope_follow_renames`: what the pre-commit hook does with renames of covered files. */
23
+ readonly scopeFollowRenames: "stage" | "warn" | "off";
24
+ /** `[hooks] index`: whether the pre-commit hook only checks `index.md` or regenerates it. */
25
+ readonly hookIndex: "check" | "stage";
26
+ /** `[commit] subject`: the template of `--commit` subjects. */
27
+ readonly commitSubject: CommitTemplate;
28
+ /** `[scope] anchor_keyword`: the code-anchor keyword, `adr` in `// adr:<id>`. */
29
+ readonly anchorKeyword: string;
30
+ /** `[scope] anchor_exclude`: globs of files whose anchors are ignored (docs that show examples). */
31
+ readonly anchorExclude: readonly string[];
18
32
  }
19
33
  export declare const DEFAULT_ADR_CONFIG: AdrConfig;
20
34
  /**
@@ -0,0 +1,59 @@
1
+ import { type Finding, type HookManager, type HookName, type Severity } from "@nikovirtala/ledger";
2
+ import type { DecisionLog } from "./log.js";
3
+ /** `adr hooks … --json` (design 2b §4.3); `hooks run` prints `ledger-findings/v1` instead. */
4
+ export interface HooksResultJson {
5
+ readonly format: "adr-hooks/v1";
6
+ readonly action: "install" | "uninstall" | "print" | "trailers";
7
+ /** Repo-relative shim paths written or removed. */
8
+ readonly written: readonly string[];
9
+ readonly unchanged: readonly string[];
10
+ readonly registrations: readonly {
11
+ readonly hook: HookName;
12
+ readonly argv: readonly string[];
13
+ }[];
14
+ /** `print` only. */
15
+ readonly snippet: string | null;
16
+ /** `trailers` only: the trailers added, in order. */
17
+ readonly trailers: readonly (readonly [string, string])[];
18
+ }
19
+ /**
20
+ * adr's command per hook (design 2b D4), after `adr`. `--root <root>` comes first only when the
21
+ * root can't be found without it: no `<repo>/adr.toml` names it and it isn't `docs/adr`. So the
22
+ * hooks see the same config as a plain `adr` run, and never print the root-override note.
23
+ */
24
+ export declare function decisionHookCommands(log: DecisionLog): Partial<Record<HookName, readonly string[]>>;
25
+ /**
26
+ * Registers adr's four commands in ledger's shims, one per hook and shared with other ark tools
27
+ * (design 2b D4). With `core.hooksPath` set or a foreign hook file present, it writes the rest and
28
+ * then throws `HookConflictError` (exit 2), naming each conflict and the `print` command.
29
+ */
30
+ export declare function installDecisionHooks(log: DecisionLog): Promise<HooksResultJson>;
31
+ /** Removes adr from every shim; a shim left with no tool is deleted. */
32
+ export declare function uninstallDecisionHooks(log: DecisionLog): Promise<HooksResultJson>;
33
+ /** The config to paste into a hook manager instead of installing shims. */
34
+ export declare function printDecisionHooks(log: DecisionLog, manager: HookManager): HooksResultJson;
35
+ /**
36
+ * The `commit-msg` step (P1 §7.1): appends one `ADR`/`ADR-Event` pair per staged added event file
37
+ * of the log, by path, keeping repeats (`ifExists: "add"`). It does nothing for a message that
38
+ * already has an `ADR-Event:` trailer (an `adr … --commit` message), or during a merge, whose
39
+ * events came with their own commits' trailers. Throws `UsageError` when the file is missing.
40
+ */
41
+ export declare function addHookTrailers(log: DecisionLog, messageFile: string): Promise<HooksResultJson>;
42
+ /**
43
+ * `adr hooks run pre-commit` (design 2b D8): rename following, then the index, then `verify
44
+ * --staged`, stopping at the first step that fails. `worktree` must be opened with the work-tree
45
+ * reader, because rename following writes through `write()`; `index` with the index reader, for
46
+ * the config as staged, the index render and verify. Only the index step stages `index.md`, and
47
+ * only with `[hooks] index = "stage"`; rename following passes `index: "skip"`. Neither stages
48
+ * into a temporary index (`stagingSafe`). A step that can't run throws (exit 2).
49
+ */
50
+ export declare function runPreCommitHook(o: {
51
+ readonly worktree: DecisionLog;
52
+ readonly index: DecisionLog;
53
+ readonly env: NodeJS.ProcessEnv;
54
+ }): Promise<{
55
+ readonly exit: 0 | 1;
56
+ readonly findings: readonly Finding[];
57
+ readonly notes: readonly string[];
58
+ readonly failOn: Severity;
59
+ }>;
@@ -1,6 +1,10 @@
1
1
  export { type AdrConfig, DEFAULT_ADR_CONFIG, parseAdrConfig } from "./config.js";
2
+ export { addHookTrailers, decisionHookCommands, type HooksResultJson, installDecisionHooks, printDecisionHooks, runPreCommitHook, uninstallDecisionHooks, } from "./hooks.js";
3
+ export { type InitResultJson, initDecisionLog } from "./init.js";
2
4
  export { type AdrOptions, adrKind, DECISION_STATUSES, type DecisionEvents, type DecisionState, type DecisionStatus, type DecisionView, formatDecisionNumber, type LinkRel, parseDecisionNumber, REF, } from "./kind.js";
3
- export { type DecisionLog, type DecisionsRead, openDecisionLog, readDecisions, readDecisionsFrom, resolveDecision, } from "./log.js";
5
+ export { type ChangedSince, changedSince, type DecisionLog, type DecisionsRead, openDecisionLog, readDecisions, readDecisionsFrom, resolveDecision, } from "./log.js";
6
+ export { type IndexResultJson, indexDecisionLog, renderDecisionIndex } from "./log-index.js";
7
+ export { type DecisionForJson, type DecisionsForJson, decisionsFor, type UnresolvedAnchorJson, } from "./scope.js";
4
8
  export { adrChecks, verifyDecisions } from "./verify.js";
5
9
  export { type DecisionListJson, type DecisionShowJson, listDecisions, type NumberingJson, showDecision, stateHeader, } from "./views.js";
6
- export { acceptDecision, type ProposeInput, proposeDecision, supersedeDecision, type WriteResultJson, } from "./write.js";
10
+ export { acceptDecision, type CopyScope, deprecateDecision, followScopeRenames, type LinkInput, linkDecision, noteDecision, type ProposeInput, proposeDecision, type ReasonInput, rejectDecision, type ScopeInput, type ScopeOffer, scopeDecision, scopeToCopy, supersedeDecision, type WriteOptions, type WriteResultJson, withdrawDecision, } from "./write.js";
@@ -0,0 +1,33 @@
1
+ import type { DecisionLog } from "./log.js";
2
+ /** `adr init --json` (design §6.2). */
3
+ export interface InitResultJson {
4
+ readonly format: "adr-init/v1";
5
+ readonly root: string;
6
+ /** The config file of the log after init, repo-relative; `null` if there is none. */
7
+ readonly config: string | null;
8
+ /** Repo-relative paths written, in write order. */
9
+ readonly written: readonly string[];
10
+ /** Files that were already there and were left as they are. */
11
+ readonly kept: readonly string[];
12
+ readonly commit: string | null;
13
+ readonly notes: readonly string[];
14
+ }
15
+ /**
16
+ * What the recovery hint says about rerunning `adr init` after `git commit` failed (design 2b D5):
17
+ * init keeps existing files, so it would commit nothing.
18
+ */
19
+ export declare const INIT_RERUN = "Running adr init again won't commit them: the files exist now, so it keeps them and commits nothing.";
20
+ /**
21
+ * `adr init` (design §6.2): writes a config for the log, unless one is found, and each built-in
22
+ * template in `o.templates` (default `nygard`) to `<root>/templates/`, never overwriting a file.
23
+ * A `--root` other than `docs/adr` gets a repo-level `adr.toml` naming it, so later commands find
24
+ * the log without `--root`; when that file exists for another log, the config goes in the root.
25
+ * With `[log] index = "committed"` it also writes `<root>/index.md` unless one exists. With
26
+ * `commit` (default `[policy] auto_commit`) the written files are committed on their own;
27
+ * nothing written means nothing committed. No events are written.
28
+ */
29
+ export declare function initDecisionLog(log: DecisionLog, o?: {
30
+ readonly templates?: readonly string[];
31
+ readonly commit?: boolean;
32
+ readonly message?: string | null;
33
+ }): Promise<InitResultJson>;
@@ -0,0 +1,117 @@
1
+ import { type Check, type Finding, type Git, type IndexSpec, type LogLayout, type TreeReader } from "@nikovirtala/ledger";
2
+ import type { AdrConfig } from "./config.js";
3
+ import { type DecisionView } from "./kind.js";
4
+ import { type DecisionLog } from "./log.js";
5
+ import type { WriteOptions } from "./write.js";
6
+ /** `adr index --json` (design 2b §4.5). */
7
+ export interface IndexResultJson {
8
+ readonly format: "adr-index/v1";
9
+ /** The index file, repo-relative: `<root>/index.md`. */
10
+ readonly path: string;
11
+ readonly check: boolean;
12
+ /**
13
+ * `--check`: no finding. Otherwise: the copies the command compares (the work tree and the
14
+ * index, or HEAD's when committing) already held the render.
15
+ */
16
+ readonly fresh: boolean;
17
+ /** Repo-relative paths this command wrote. */
18
+ readonly written: readonly string[];
19
+ readonly commit: string | null;
20
+ /** `--check`'s findings; `[]` otherwise. */
21
+ readonly findings: readonly Finding[];
22
+ readonly notes: readonly string[];
23
+ }
24
+ /**
25
+ * What the recovery hint says about rerunning `adr index --commit` after `git commit` failed
26
+ * (design 2b D5). It names the file, not the path, which the hint lists above it.
27
+ */
28
+ export declare const INDEX_RERUN = "You can also run adr index --commit again once git accepts the commit; it commits index.md while it differs from HEAD's.";
29
+ /**
30
+ * The step before the manual commit when a write's second index render failed after staging
31
+ * (design 2b §4.5 step 4).
32
+ */
33
+ export declare const INDEX_BEFORE: (root: string) => string;
34
+ /**
35
+ * The step after the manual commit when the commit carried the index: the commit's render leaves
36
+ * out other decisions' uncommitted entries (design 2b D5, §4.5 step 5).
37
+ */
38
+ export declare const INDEX_AFTER: (root: string) => string;
39
+ /** The repo-relative path of a log's generated index. */
40
+ export declare const indexPath: (layout: LogLayout) => string;
41
+ /**
42
+ * adr's index spec (01:209: active decisions first), built per render so that a superseded
43
+ * decision's status can name its successor's display from `views`.
44
+ */
45
+ export declare const DECISION_INDEX: (root: string, views: ReadonlyMap<string, DecisionView>) => IndexSpec<DecisionView>;
46
+ /**
47
+ * The index `tree` must hold: its decisions, numbered as they will be once the commit holding
48
+ * `tree` (which builds on `history`: HEAD, a commit, or null on an unborn HEAD) is on main
49
+ * (design 2b D2), with `[log] main_branch`'s numbers first. A tree that isn't a commit's (the work
50
+ * tree, the index) also merges `MERGE_HEAD` while a merge is in progress. In a shallow clone the
51
+ * numbers continue from those `history`'s index recorded; `null` when there are none, so the
52
+ * numbers can't be projected.
53
+ */
54
+ export declare function renderDecisionIndex(git: Git, o: {
55
+ readonly layout: LogLayout;
56
+ readonly adr: AdrConfig;
57
+ readonly tree: TreeReader;
58
+ readonly history: string | null;
59
+ }): Promise<string | null>;
60
+ /**
61
+ * What the unstaged-files `index/stale` finding and the matching write note both start with:
62
+ * `path` lists `files` (some of them), which aren't staged.
63
+ */
64
+ export declare function unstagedIndexText(path: string, files: readonly string[]): string;
65
+ /**
66
+ * The log's event and body files whose work-tree content isn't staged (untracked or modified),
67
+ * sorted: the cause of a staged `index.md` that only the work tree's render matches.
68
+ */
69
+ export declare function unstagedLogFiles(git: Git, layout: LogLayout): Promise<string[]>;
70
+ /**
71
+ * The verify check that `<root>/index.md` is current (design 2b §4.5, "Freshness in verify"). In
72
+ * staged mode (the pre-commit hook), a stale staged copy that equals the work tree's render
73
+ * means another decision's files aren't staged: writes stage the work tree's render (D2), and
74
+ * `adr index` would change nothing. The finding then names those files and says to stage them.
75
+ */
76
+ export declare function decisionIndexCheck(log: DecisionLog): Check;
77
+ /** Whether `bytes` (null: absent) hold exactly `text`. */
78
+ export declare function holdsText(bytes: Uint8Array | null, text: string): boolean;
79
+ /** HEAD's copy of `path`; `null` when it is absent or HEAD is unborn. */
80
+ export declare function headBytes(git: Git, path: string): Promise<Uint8Array | null>;
81
+ /** HEAD's tree, or an empty tree on an unborn HEAD. */
82
+ export declare function headTree(git: Git, head: string | null): Promise<TreeReader>;
83
+ /**
84
+ * Brings the work-tree copy of `path` to `text` (atomically, when it differs) and reports whether
85
+ * the staged copy differs, so the caller stages it. `old` is the work-tree copy before the write
86
+ * (`null` when absent), for rollback.
87
+ */
88
+ export declare function writeIndexCopy(git: Git, path: string, text: string): Promise<{
89
+ readonly wrote: boolean;
90
+ readonly old: Uint8Array | null;
91
+ readonly stage: boolean;
92
+ }>;
93
+ /** The first line of an error's message, for notes and headlines. */
94
+ export declare const firstLine: (err: unknown) => string;
95
+ /** `adr index`'s result and whether the work-tree refresh after a commit changed a copy. */
96
+ export interface IndexRun {
97
+ readonly doc: IndexResultJson;
98
+ /** With a commit requested: step 5 wrote or staged the work tree's render. */
99
+ readonly refreshed: boolean;
100
+ }
101
+ /**
102
+ * `adr index` (design 2b §4.5) with what the text output needs; `indexDecisionLog` is the
103
+ * library entry.
104
+ */
105
+ export declare function runDecisionIndex(log: DecisionLog, o?: WriteOptions & {
106
+ readonly check?: boolean;
107
+ }): Promise<IndexRun>;
108
+ /**
109
+ * `adr index [--check] [--commit | --no-commit] [-m <message>]` (design 2b §4.5): renders
110
+ * `<root>/index.md` and writes and stages it where the work tree or the index differ. With
111
+ * `commit` (default `[policy] auto_commit`) it renders HEAD's tree and commits the file alone when
112
+ * HEAD's copy differs, then refreshes the work tree's copy, which may include other decisions'
113
+ * uncommitted entries. `check` writes nothing and reports `index/*` findings.
114
+ */
115
+ export declare function indexDecisionLog(log: DecisionLog, o?: WriteOptions & {
116
+ readonly check?: boolean;
117
+ }): Promise<IndexResultJson>;
@@ -33,8 +33,15 @@ export interface DecisionsRead {
33
33
  /** How the log was located (`ToolLog.notes`); `[]` for a MemoryTree read. */
34
34
  readonly notes: readonly string[];
35
35
  }
36
- /** `numberLog` on the repository, then `readDecisionsFrom(log.tree, …)`. */
36
+ /**
37
+ * `numberLog` on the repository, then `readDecisionsFrom(log.tree, …)`. In a shallow clone of a
38
+ * log with `[log] index = "committed"`, the numbers come from `<root>/index.md` in the commit
39
+ * being read (`--ref`, else HEAD, resolved when the numbers are needed), never from the work tree's
40
+ * copy, which may number acceptances that exist only there (design 2b D1, §4.6).
41
+ */
37
42
  export declare function readDecisions(log: DecisionLog): Promise<DecisionsRead>;
43
+ /** The display numbers `readDecisions` uses, with its shallow-clone fallback to `index.md`. */
44
+ export declare function numberDecisions(log: DecisionLog): Promise<Numbering>;
38
45
  /** The git-free core of `readDecisions`; tests pass a MemoryTree and a hand-made `Numbering`. */
39
46
  export declare function readDecisionsFrom(tree: TreeReader, o: {
40
47
  readonly layout: LogLayout;
@@ -44,6 +51,13 @@ export declare function readDecisionsFrom(tree: TreeReader, o: {
44
51
  readonly commit?: string | null;
45
52
  readonly notes?: readonly string[];
46
53
  }): Promise<DecisionsRead>;
54
+ /**
55
+ * The note a read command adds about where numbers come from: the shallow-clone index, or why
56
+ * they are unavailable (`unavailable: false` leaves that one out); `null` for none.
57
+ */
58
+ export declare function numberingNote(read: DecisionsRead, o: {
59
+ readonly unavailable: boolean;
60
+ }): string | null;
47
61
  /** Why numbers are unavailable, in words: `shallow clone` or `no main branch`. */
48
62
  export declare function unavailableReason(n: Numbering): string;
49
63
  /**
@@ -51,3 +65,22 @@ export declare function unavailableReason(n: Numbering): string;
51
65
  * Throws `UsageError` (exit 2) naming the reason when it names nothing.
52
66
  */
53
67
  export declare function resolveDecision(read: DecisionsRead, input: string): string;
68
+ /** The `since` key of `adr list --since <rev>` (design 2b D7). */
69
+ export interface ChangedSince {
70
+ /** The revision as given, such as `ORIG_HEAD`. */
71
+ readonly rev: string;
72
+ readonly commit: string;
73
+ /** Event files added since `rev`, sorted by path. */
74
+ readonly events: readonly {
75
+ readonly subject: string;
76
+ readonly type: string;
77
+ readonly path: string;
78
+ }[];
79
+ }
80
+ /**
81
+ * The event files in `--ref`'s tree (else HEAD's) that `rev`'s tree lacks (design 2b D7). Diffing
82
+ * trees answers "what did this pull bring" for fast-forwards and merges (`ORIG_HEAD` is the tip
83
+ * before them), and lists nothing for a rebase of your own work, whose events are in both trees.
84
+ * Throws `RefNotFoundError` when either revision doesn't resolve.
85
+ */
86
+ export declare function changedSince(log: DecisionLog, rev: string): Promise<ChangedSince>;
@@ -0,0 +1,51 @@
1
+ import { type Finding, type ScopeVia } from "@nikovirtala/ledger";
2
+ import type { DecisionStatus } from "./kind.js";
3
+ import type { DecisionLog, DecisionsRead } from "./log.js";
4
+ import { type NumberingJson } from "./views.js";
5
+ /** One decision that governs a path in `adr-for/v1` (design §6.9). */
6
+ export interface DecisionForJson {
7
+ readonly id: string;
8
+ readonly display: string;
9
+ readonly title: string;
10
+ readonly status: DecisionStatus;
11
+ readonly effective: string | null;
12
+ /** What to know before applying it: superseded, deprecated, never in force; `null` if nothing. */
13
+ readonly warning: string | null;
14
+ /** The globs that matched, then the anchor lines. */
15
+ readonly via: readonly ScopeVia[];
16
+ }
17
+ /** An anchor naming no decision of this log. */
18
+ export interface UnresolvedAnchorJson {
19
+ /** The id, or `<source>:<id>` for a qualified anchor. */
20
+ readonly ref: string;
21
+ readonly line: number;
22
+ readonly reason: "not-found" | "other-log";
23
+ }
24
+ /** `adr for <path>… --json` (design §6.9). */
25
+ export interface DecisionsForJson {
26
+ readonly format: "adr-for/v1";
27
+ readonly root: string;
28
+ readonly ref: string | null;
29
+ readonly commit: string | null;
30
+ readonly numbering: NumberingJson;
31
+ readonly paths: readonly {
32
+ readonly path: string;
33
+ /** In the index, or in the `--ref` tree. */
34
+ readonly tracked: boolean;
35
+ readonly decisions: readonly DecisionForJson[];
36
+ readonly unresolved: readonly UnresolvedAnchorJson[];
37
+ }[];
38
+ /** The read's findings of the listed decisions and of the log as a whole. */
39
+ readonly findings: readonly Finding[];
40
+ readonly notes: readonly string[];
41
+ }
42
+ /**
43
+ * Which decisions govern each path (design §6.9): globs of decisions that were ever in force, and
44
+ * comment anchors of any decision, read from the work tree or, with a `--ref` log, that commit.
45
+ * Paths are relative to `o.cwd` (default the repository root); directories and paths outside the
46
+ * repository are `UsageError`s. Paths need not be tracked.
47
+ */
48
+ export declare function decisionsFor(read: DecisionsRead, log: DecisionLog, o: {
49
+ readonly paths: readonly string[];
50
+ readonly cwd?: string;
51
+ }): Promise<DecisionsForJson>;
@@ -1,9 +1,11 @@
1
1
  import { type Check, type Finding, type VerifyMode } from "@nikovirtala/ledger";
2
- import type { DecisionLog } from "./log.js";
2
+ import { type DecisionLog } from "./log.js";
3
3
  /**
4
- * Every phase-1 check for the log: ledger's mechanical and fold checks with adr's actor policy,
5
- * and template lint against the templates in the head tree and, for older versions, the history
6
- * of `historyRef`.
4
+ * Every check for the log: ledger's mechanical and fold checks with adr's actor policy, template
5
+ * lint against the templates in the head tree and, for older versions, the history of
6
+ * `historyRef`, the scope-glob and anchor checks, and the decision checks over code
7
+ * (`decision/governed-by-inactive`, `decision/scope-narrowed`). With `[log] index = "committed"`,
8
+ * also the freshness of `<root>/index.md`.
7
9
  */
8
10
  export declare function adrChecks(log: DecisionLog, historyRef: string | null): readonly Check[];
9
11
  /** Verifies the decision log in `mode` (staged, range or full) with `adrChecks`. */
@@ -1,10 +1,10 @@
1
1
  import { type EventEnvelope, type Finding, type StateHeader } from "@nikovirtala/ledger";
2
2
  import type { DecisionStatus, DecisionView } from "./kind.js";
3
- import type { DecisionsRead } from "./log.js";
3
+ import type { ChangedSince, DecisionsRead } from "./log.js";
4
4
  /** The `numbering` key of the read documents. */
5
5
  export interface NumberingJson {
6
6
  readonly available: boolean;
7
- readonly reason: "shallow" | "no-main-ref" | null;
7
+ readonly reason: "shallow" | "no-main-ref" | "index" | null;
8
8
  readonly ref: string | null;
9
9
  }
10
10
  /** `adr list --json` (design §5.5). */
@@ -15,6 +15,8 @@ export interface DecisionListJson {
15
15
  readonly commit: string | null;
16
16
  readonly numbering: NumberingJson;
17
17
  readonly decisions: readonly DecisionView[];
18
+ /** With `--since <rev>`: the event files added since `rev`; `null` without it. */
19
+ readonly since: ChangedSince | null;
18
20
  /** Newer envelope or schema versions; upgrade adr. */
19
21
  readonly unreadable: readonly string[];
20
22
  /** First event not `proposed`, or a body with no events; run adr verify. */
@@ -37,12 +39,16 @@ export interface DecisionShowJson {
37
39
  readonly findings: readonly Finding[];
38
40
  readonly notes: readonly string[];
39
41
  }
42
+ /** The `numbering` key of `adr-list/v1`, `adr-show/v1` and `adr-for/v1`. */
43
+ export declare const numberingJson: (read: DecisionsRead) => NumberingJson;
40
44
  /**
41
- * The `adr-list/v1` document: decisions in list order, filtered by `status` and truncated to
45
+ * The `adr-list/v1` document: decisions in list order, filtered by `status` and by `since` (only
46
+ * the decisions with event files added since its revision, from `changedSince`), and truncated to
42
47
  * `limit` after ordering. `findings` are those of the listed decisions and of the log as a whole.
43
48
  */
44
49
  export declare function listDecisions(read: DecisionsRead, o?: {
45
50
  readonly status?: readonly DecisionStatus[];
51
+ readonly since?: ChangedSince | null;
46
52
  readonly limit?: number;
47
53
  }): DecisionListJson;
48
54
  /**