@nikovirtala/adr 0.1.0 → 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.
- package/README.md +47 -7
- package/dist/cli.js +634 -47
- package/dist/cli.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/{kind-DqFhApu7.js → kind-BcHjCHvi.js} +9 -18
- package/dist/kind-BcHjCHvi.js.map +1 -0
- package/dist/kind.js +1 -1
- package/dist/types/cli/accept.d.ts +2 -2
- package/dist/types/cli/deprecate.d.ts +3 -0
- package/dist/types/cli/for.d.ts +3 -0
- package/dist/types/cli/init.d.ts +3 -0
- package/dist/types/cli/link.d.ts +3 -0
- package/dist/types/cli/new.d.ts +1 -1
- package/dist/types/cli/note.d.ts +3 -0
- package/dist/types/cli/open.d.ts +0 -2
- package/dist/types/cli/reject.d.ts +3 -0
- package/dist/types/cli/scope.d.ts +7 -0
- package/dist/types/cli/supersede.d.ts +1 -1
- package/dist/types/cli/text.d.ts +33 -3
- package/dist/types/cli/withdraw.d.ts +3 -0
- package/dist/types/config.d.ts +9 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/init.d.ts +27 -0
- package/dist/types/scope.d.ts +51 -0
- package/dist/types/views.d.ts +2 -0
- package/dist/types/write.d.ts +179 -17
- package/dist/write-9IaqHRrY.js +1986 -0
- package/dist/write-9IaqHRrY.js.map +1 -0
- package/package.json +2 -2
- package/dist/kind-DqFhApu7.js.map +0 -1
- package/dist/write-C3IW5WrA.js +0 -1011
- package/dist/write-C3IW5WrA.js.map +0 -1
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli/open.ts","../src/cli/text.ts","../src/cli/accept.ts","../src/cli/list.ts","../src/cli/editor.ts","../src/cli/new.ts","../src/cli/show.ts","../src/cli/supersede.ts","../src/cli/commands.ts","../src/cli.ts"],"sourcesContent":["import type { CliIO, GlobalFlags } from \"@nikovirtala/ledger/cli\";\nimport { type DecisionLog, openDecisionLog, readDecisions } from \"../log.js\";\nimport type { Display } from \"./text.js\";\n\n/**\n * The decision log a command works on: `--root` and `--ref` from the globals, git run with the\n * CLI's environment.\n */\nexport function openForCli(\n io: CliIO,\n flags: GlobalFlags,\n o: { readonly reader?: \"worktree\" | \"index\" } = {},\n): Promise<DecisionLog> {\n return openDecisionLog({\n cwd: io.cwd,\n root: flags.root,\n ref: flags.ref,\n ...(o.reader === undefined ? {} : { reader: o.reader }),\n gitOptions: { env: io.env },\n });\n}\n\n/**\n * How other decisions display in a write's text, read again from the work tree, like the write\n * result's own views: a commit on the main ref has numbered the decisions it accepted.\n */\nexport async function displayAfterWrite(log: DecisionLog): Promise<{ readonly display: Display }> {\n const read = await readDecisions(log);\n return { display: (id) => read.projection.views.get(id)?.display ?? id };\n}\n\n/** `--commit`/`--no-commit` when given, else `[policy] auto_commit`. */\nexport function commitRequested(log: DecisionLog, values: Readonly<Record<string, unknown>>) {\n return typeof values.commit === \"boolean\" ? values.commit : log.adr.autoCommit;\n}\n","import { type EventEnvelope, type Finding, renderStateHeader } from \"@nikovirtala/ledger\";\nimport type { DecisionView } from \"../kind.js\";\nimport type { DecisionListJson, DecisionShowJson } from \"../views.js\";\nimport type { WriteResultJson } from \"../write.js\";\n\n/** How a decision id is shown: its display (`ADR-0007`), or the id when it has no number. */\nexport type Display = (id: string) => string;\n\n/** A table: each column padded to its widest value, trailing spaces removed. */\nfunction columns(rows: readonly (readonly string[])[]): string {\n const widths: number[] = [];\n for (const row of rows) {\n row.forEach((cell, i) => {\n widths[i] = Math.max(widths[i] ?? 0, cell.length);\n });\n }\n return rows\n .map((row) =>\n row\n .map((cell, i) => (i === row.length - 1 ? cell : cell.padEnd(widths[i] ?? 0)))\n .join(\" \")\n .trimEnd(),\n )\n .join(\"\\n\");\n}\n\n/** `adr list`: one row per decision, `→ <effective>` when it differs from the decision. */\nexport function listText(doc: DecisionListJson, display: Display): string {\n if (doc.decisions.length === 0) return \"No decisions.\";\n return columns(\n doc.decisions.map((v) => {\n const arrow =\n v.effective === null\n ? \"→ (cycle)\"\n : v.effective === v.id\n ? \"\"\n : `→ ${display(v.effective)}`;\n return [v.number === null ? \"-\" : v.display, v.id, v.status, v.title, arrow];\n }),\n );\n}\n\n/** `ADR-0003 (m2x7p4d2)`, or the id alone when it has no number. */\nfunction named(id: string, display: Display): string {\n const shown = display(id);\n return shown === id ? id : `${shown} (${id})`;\n}\n\nconst day = (at: string | null) => (at ?? \"\").slice(0, 10);\nconst list = (ids: readonly string[], display: Display) =>\n ids.length === 0 ? \"none\" : ids.map((id) => named(id, display)).join(\", \");\n\nfunction bodyLine(v: DecisionView): string {\n if (v.body_path === null) return \"missing\";\n if (v.body_intact === null) return v.body_path;\n return `${v.body_path} (${v.body_intact ? \"intact\" : \"changed after acceptance\"})`;\n}\n\nfunction actorText(e: EventEnvelope): string {\n const a = e.actor;\n return a.kind === \"agent\" ? `${a.name} (agent ${a.agent} for ${a.on_behalf_of})` : a.name;\n}\n\n/** The second line of an event in `show --history`: its reason, else a summary of its data. */\nfunction eventDetail(e: EventEnvelope): string | null {\n if (typeof e.reason === \"string\") return `reason: ${e.reason}`;\n const entries = Object.entries(e.data);\n if (entries.length === 0) return null;\n return entries\n .map(([k, v]) => `${k}: ${typeof v === \"string\" ? v : JSON.stringify(v)}`)\n .join(\", \");\n}\n\nfunction historyLines(events: readonly EventEnvelope[]): string[] {\n const width = Math.max(...events.map((e) => e.type.length));\n return events.flatMap((e) => {\n const detail = eventDetail(e);\n return [\n ` ${e.at} ${e.type.padEnd(width)} ${actorText(e)}`,\n ...(detail === null ? [] : [` ${detail}`]),\n ];\n });\n}\n\nconst SECTION_FINDING =\n /^(?:required )?section (.+?) (is missing|is empty|still contains its guidance text)$/;\nconst REASONS: Readonly<Record<string, string>> = {\n \"is missing\": \"missing\",\n \"is empty\": \"empty\",\n \"still contains its guidance text\": \"guidance text left\",\n};\n\n/**\n * The draft lint of `new` as advice: `Fill in N sections before accepting: A, B (why)` for the\n * section findings, and one line per other finding.\n */\nfunction draftAdvice(findings: readonly Finding[]): string[] {\n const headings: string[] = [];\n const reasons: string[] = [];\n const other: string[] = [];\n for (const f of findings) {\n const m = SECTION_FINDING.exec(f.message);\n if (m === null) {\n other.push(`Draft: ${f.message} [${f.rule}]`);\n continue;\n }\n const [, heading = \"\", what = \"\"] = m;\n const reason = REASONS[what] ?? what;\n if (!headings.includes(heading)) headings.push(heading);\n if (!reasons.includes(reason)) reasons.push(reason);\n }\n const n = headings.length;\n return [\n ...(n === 0\n ? []\n : [\n `Fill in ${n === 1 ? \"1 section\" : `${n} sections`} before accepting: ${headings.join(\", \")} (${reasons.join(\", \")})`,\n ]),\n ...other,\n ];\n}\n\nfunction findingLines(findings: readonly Finding[]): string[] {\n return findings.map((f) => ` ${f.file === null ? \"\" : `${f.file}: `}${f.message} [${f.rule}]`);\n}\n\nconst short = (sha: string) => sha.slice(0, 7);\n\n/**\n * The text of `adr new|accept|supersede` (design §5.6). `subject` names what a refused command\n * was about; `number` is the decision's number in the write result, if it has one now.\n */\nexport function writeText(\n doc: WriteResultJson,\n display: Display,\n o: { readonly subject: string; readonly number: string | null },\n): string {\n const verb = { new: \"proposed\", accept: \"accepted\", supersede: \"superseded\" }[doc.command];\n if (!doc.ok) return [`Not ${verb}: ${o.subject}`, ...findingLines(doc.findings)].join(\"\\n\");\n const v = doc.decision;\n if (v === null) return \"\";\n const committed = doc.commit === null ? null : `Committed ${short(doc.commit)}`;\n switch (doc.command) {\n case \"new\":\n return [\n `Proposed ${v.id}: ${v.title}`,\n ...doc.written.map((p) => ` ${p}`),\n ...draftAdvice(doc.findings),\n ...(committed === null ? [] : [`${committed}.`]),\n `Next: adr accept ${v.id}`,\n ].join(\"\\n\");\n case \"accept\":\n return [\n `Accepted ${v.id}: ${v.title}`,\n ...doc.affected.map((a) => `Superseded ${named(a.id, display)}: ${a.title}`),\n committed === null\n ? \"Staged; commit to record it.\"\n : o.number === null\n ? `${committed}. The number is assigned when this commit lands on main.`\n : `${committed} as ${o.number}.`,\n ].join(\"\\n\");\n case \"supersede\":\n return [\n `Superseded ${named(v.id, display)}: ${v.title}`,\n ` by ${named(v.superseded_by ?? \"\", display)}`,\n committed === null ? \"Staged; commit to record it.\" : `${committed}.`,\n ].join(\"\\n\");\n }\n}\n\n/** `adr show`: the state header, the decision's fields and its body. */\nexport function showText(doc: DecisionShowJson, display: Display): string {\n const v = doc.decision;\n const supersedes =\n v.supersedes.length === 0 && v.declared_supersedes.length > 0\n ? `none (declared: ${list(v.declared_supersedes, display)})`\n : list(v.supersedes, display);\n const fields: [string, string][] = [\n [\"Title\", v.title],\n [\"Status\", `${v.status} (${day(v.status_at)})`],\n [\"Effective\", v.effective === null ? \"none (supersession cycle)\" : named(v.effective, display)],\n [\"Chain\", v.chain.map(display).join(\" → \")],\n [\"Supersedes\", supersedes],\n [\"Applies to\", v.applies_to.length === 0 ? \"none\" : v.applies_to.join(\", \")],\n [\"Body\", bodyLine(v)],\n ];\n if (doc.events === null) fields.push([\"History\", v.history.join(\" · \")]);\n const width = Math.max(...fields.map(([k]) => k.length)) + 2;\n const lines = fields.map(([k, value]) => `${`${k}:`.padEnd(width)}${value}`);\n if (doc.events !== null) lines.push(\"History:\", ...historyLines(doc.events));\n const body = doc.body === null ? \"\" : `\\n${doc.body.endsWith(\"\\n\") ? doc.body : `${doc.body}\\n`}`;\n return `${renderStateHeader(doc.header)}\\n${lines.join(\"\\n\")}\\n${body}`;\n}\n","import { type JsonValue, resolveActor } from \"@nikovirtala/ledger\";\nimport type { CommandSpec } from \"@nikovirtala/ledger/cli\";\nimport { acceptDecision } from \"../write.js\";\nimport { commitRequested, displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\n/** `adr accept <decision> [--commit | --no-commit]` (design §5.6). */\nexport const acceptCommand: CommandSpec = {\n name: \"accept\",\n summary: \"accept a proposed decision, superseding the decisions it declares\",\n usage: \"accept <decision> [--commit | --no-commit]\",\n options: { commit: { type: \"boolean\" } },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const input = positionals[0] ?? \"\";\n const log = await openForCli(io, flags);\n const actor = await resolveActor(log.git, { env: io.env });\n const doc = await acceptDecision(\n log,\n { id: input, actor },\n { commit: commitRequested(log, values) },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: v === null || doc.commit === null || v.number === null ? null : v.display,\n }),\n notes: doc.notes,\n };\n },\n};\n","import { type JsonValue, UsageError } from \"@nikovirtala/ledger\";\nimport type { CommandSpec } from \"@nikovirtala/ledger/cli\";\nimport { DECISION_STATUSES, type DecisionStatus } from \"../kind.js\";\nimport { readDecisions, unavailableReason } from \"../log.js\";\nimport { listDecisions } from \"../views.js\";\nimport { openForCli } from \"./open.js\";\nimport { listText } from \"./text.js\";\n\nconst plural = (n: number, one: string, many: string) => (n === 1 ? `1 ${one}` : `${n} ${many}`);\n\nfunction statuses(values: Readonly<Record<string, unknown>>): DecisionStatus[] {\n const given = Array.isArray(values.status) ? (values.status as string[]) : [];\n return given.map((s) => {\n if (!(DECISION_STATUSES as readonly string[]).includes(s)) {\n throw new UsageError(\n `unknown status ${JSON.stringify(s)}; use one of ${DECISION_STATUSES.join(\", \")}`,\n );\n }\n return s as DecisionStatus;\n });\n}\n\n/** `adr list [--status <status>]…` (design §5.6). */\nexport const listCommand: CommandSpec = {\n name: \"list\",\n summary: \"list decisions with their computed status\",\n usage: \"list [--status <status>]…\",\n options: { status: { type: \"string\", multiple: true } },\n positionals: { min: 0, max: 0, names: [] },\n ref: \"read\",\n async run({ io, flags, values }) {\n const status = statuses(values);\n const read = await readDecisions(await openForCli(io, flags));\n const doc = listDecisions(read, { status });\n const notes = [...doc.notes];\n if (!read.numbering.available && doc.decisions.length > 0) {\n notes.push(\n `numbers are unavailable (${unavailableReason(read.numbering)}); decisions display by id`,\n );\n }\n if (doc.findings.length > 0) {\n notes.push(\n `the decision log has ${plural(doc.findings.length, \"problem\", \"problems\")}; run adr verify`,\n );\n }\n if (doc.unreadable.length > 0) {\n notes.push(\n `${plural(doc.unreadable.length, \"decision uses\", \"decisions use\")} a newer format; upgrade adr`,\n );\n }\n if (doc.unfoldable.length > 0) {\n notes.push(\n `${plural(doc.unfoldable.length, \"decision\", \"decisions\")} can't be read; run adr verify`,\n );\n }\n const display = (id: string) => read.projection.views.get(id)?.display ?? id;\n return { exit: 0, json: doc as unknown as JsonValue, text: listText(doc, display), notes };\n },\n};\n","import { spawn } from \"node:child_process\";\n\n/** The `edit` callback of `proposeDecision`: `null` when the editor exited 0, else a note. */\nexport type Edit = (absPath: string) => Promise<string | null>;\n\n/**\n * The user's editor as an `edit` callback (design §5.7), or `null` when neither `VISUAL` nor\n * `EDITOR` is set. The editor string is run by `sh -c` the way git runs `core.editor`, with the\n * path as the positional parameter `$1`, never interpolated. When stdout isn't a TTY (piped\n * `--json`, say), the editor's stdout goes to stderr so the CLI's stdout stays one document.\n * The callback never throws: a spawn error or a non-zero exit becomes the note.\n */\nexport function editorFor(\n env: NodeJS.ProcessEnv,\n o: { readonly stdoutIsTTY: boolean },\n): Edit | null {\n const editor = [env.VISUAL, env.EDITOR].map((v) => v?.trim() ?? \"\").find((v) => v !== \"\");\n if (editor === undefined) return null;\n return (absPath) =>\n new Promise((resolve) => {\n const fail = (e: unknown) =>\n resolve(`could not start the editor: ${e instanceof Error ? e.message : String(e)}`);\n try {\n const child = spawn(\"sh\", [\"-c\", `${editor} \"$1\"`, \"sh\", absPath], {\n env,\n stdio: o.stdoutIsTTY ? \"inherit\" : [\"inherit\", 2, \"inherit\"],\n });\n child.on(\"error\", fail);\n child.on(\"close\", (code, signal) => {\n if (code === 0) resolve(null);\n else {\n const how =\n code === null\n ? `was killed by ${signal ?? \"a signal\"}`\n : `exited with status ${code}`;\n resolve(`the editor ${how}; the draft is staged as rendered`);\n }\n });\n } catch (e) {\n fail(e);\n }\n });\n}\n","import { type JsonValue, resolveActor, UsageError } from \"@nikovirtala/ledger\";\nimport type { CommandSpec } from \"@nikovirtala/ledger/cli\";\nimport { proposeDecision } from \"../write.js\";\nimport { editorFor } from \"./editor.js\";\nimport { commitRequested, displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\nconst strings = (v: unknown): string[] => (Array.isArray(v) ? (v as string[]) : []);\n\n/** `--section <id>=<markdown>` values, split at the first `=`; each id at most once. */\nfunction sections(values: readonly string[]): Record<string, string> {\n const out: Record<string, string> = {};\n for (const value of values) {\n const at = value.indexOf(\"=\");\n const id = at < 0 ? \"\" : value.slice(0, at).trim();\n if (id === \"\") {\n throw new UsageError(`--section needs <id>=<markdown>, not ${JSON.stringify(value)}`);\n }\n if (Object.hasOwn(out, id)) throw new UsageError(`--section ${id} is given twice`);\n out[id] = value.slice(at + 1);\n }\n return out;\n}\n\n/**\n * `adr new <title> …` (design §5.6). The editor runs with `--edit`, or without `--no-edit` when\n * the terminal is interactive and an editor is set.\n */\nexport const newCommand: CommandSpec = {\n name: \"new\",\n summary: \"propose a decision from a template and stage it\",\n usage:\n \"new <title> [--template <name>] [--supersedes <decision>]… [--section <id>=<markdown>]… [--edit | --no-edit] [--commit | --no-commit]\",\n options: {\n template: { type: \"string\" },\n supersedes: { type: \"string\", multiple: true },\n section: { type: \"string\", multiple: true },\n edit: { type: \"boolean\" },\n commit: { type: \"boolean\" },\n },\n positionals: { min: 1, max: 1, names: [\"title\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const title = positionals[0] ?? \"\";\n const given = sections(strings(values.section));\n const log = await openForCli(io, flags);\n const actor = await resolveActor(log.git, { env: io.env });\n // Design review NIT 1: the skip notes say \"not committed\" only when a commit was asked for.\n const requested = commitRequested(log, values);\n const notes: string[] = [];\n const editor = editorFor(io.env, { stdoutIsTTY: io.stdoutIsTTY });\n const wantsEdit = values.edit === true || (values.edit === undefined && io.interactive);\n if (values.edit === true && editor === null) notes.push(\"no editor: set VISUAL or EDITOR\");\n const edit =\n wantsEdit && editor !== null\n ? async (abs: string) => {\n const note = await editor(abs);\n if (note !== null) notes.push(note);\n return note;\n }\n : undefined;\n const doc = await proposeDecision(\n log,\n {\n title,\n sections: given,\n supersedes: strings(values.supersedes),\n actor,\n ...(typeof values.template === \"string\" ? { template: values.template } : {}),\n },\n {\n commit: requested,\n ...(edit === undefined ? {} : { edit }),\n onNote: (note) => notes.push(requested ? `not committed: ${note}` : note),\n },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: title.trim(),\n number: v === null || v.number === null ? null : v.display,\n }),\n notes: [...doc.notes, ...notes],\n };\n },\n};\n","import type { JsonValue } from \"@nikovirtala/ledger\";\nimport type { CommandSpec } from \"@nikovirtala/ledger/cli\";\nimport { readDecisions, resolveDecision } from \"../log.js\";\nimport { showDecision } from \"../views.js\";\nimport { openForCli } from \"./open.js\";\nimport { showText } from \"./text.js\";\n\n/** `adr show <decision> [--history]` (design §5.6). */\nexport const showCommand: CommandSpec = {\n name: \"show\",\n summary: \"show a decision with its state header, chain, history and body\",\n usage: \"show <decision> [--history]\",\n options: { history: { type: \"boolean\" } },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"read\",\n async run({ io, flags, values, positionals }) {\n const read = await readDecisions(await openForCli(io, flags));\n const id = resolveDecision(read, positionals[0] ?? \"\");\n const doc = await showDecision(read, id, { history: values.history === true });\n const display = (s: string) => read.projection.views.get(s)?.display ?? s;\n return {\n exit: 0,\n json: doc as unknown as JsonValue,\n text: showText(doc, display),\n notes: doc.notes,\n };\n },\n};\n","import { type JsonValue, resolveActor, UsageError } from \"@nikovirtala/ledger\";\nimport type { CommandSpec } from \"@nikovirtala/ledger/cli\";\nimport { supersedeDecision } from \"../write.js\";\nimport { commitRequested, displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\nconst USAGE = \"supersede <decision> --by <decision> [--reason <text>] [--commit | --no-commit]\";\n\n/** `adr supersede <decision> --by <decision> …` (design §5.6). */\nexport const supersedeCommand: CommandSpec = {\n name: \"supersede\",\n summary: \"mark an accepted decision as superseded by another accepted one\",\n usage: USAGE,\n options: { by: { type: \"string\" }, reason: { type: \"string\" }, commit: { type: \"boolean\" } },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const input = positionals[0] ?? \"\";\n if (typeof values.by !== \"string\") {\n throw new UsageError(`missing --by <decision>; usage: adr ${USAGE}`);\n }\n const log = await openForCli(io, flags);\n const actor = await resolveActor(log.git, { env: io.env });\n const doc = await supersedeDecision(\n log,\n {\n id: input,\n by: values.by,\n actor,\n ...(typeof values.reason === \"string\" ? { reason: values.reason } : {}),\n },\n { commit: commitRequested(log, values) },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n }),\n notes: doc.notes,\n };\n },\n};\n","import { templateHistoryRef } from \"@nikovirtala/ledger\";\nimport { type ToolCli, verifyCommand } from \"@nikovirtala/ledger/cli\";\nimport { adrKind } from \"../kind.js\";\nimport { adrChecks } from \"../verify.js\";\nimport { acceptCommand } from \"./accept.js\";\nimport { listCommand } from \"./list.js\";\nimport { newCommand } from \"./new.js\";\nimport { openForCli } from \"./open.js\";\nimport { showCommand } from \"./show.js\";\nimport { supersedeCommand } from \"./supersede.js\";\n\n/**\n * ledger's shared `verify`: the log as the mode reads it (the index for `--staged`, else the\n * `--ref` tree or the work tree), every phase-1 check, and `[verify] fail_on`.\n */\nconst verify = verifyCommand({\n async open({ io, flags, mode }) {\n const log = await openForCli(io, flags, {\n reader: mode.type === \"staged\" ? \"index\" : \"worktree\",\n });\n return {\n git: log.git,\n kind: adrKind,\n layout: log.layout,\n checks: adrChecks(log, await templateHistoryRef(log.git, mode)),\n failOn: log.adr.failOn,\n notes: log.notes,\n };\n },\n});\n\n/** The `adr` tool: its commands, for ledger's `runCli`. */\nexport function adrCli(version: string): ToolCli {\n return {\n name: \"adr\",\n version,\n summary: \"Architecture decision records kept as event logs in git.\",\n commands: [newCommand, acceptCommand, supersedeCommand, listCommand, showCommand, verify],\n };\n}\n","#!/usr/bin/env node\nimport { createRequire } from \"node:module\";\nimport { processIO, runCli } from \"@nikovirtala/ledger/cli\";\nimport { adrCli } from \"./cli/commands.js\";\n\n// Read at run time, relative to dist/cli.js (or src/cli.ts): both sit next to ../package.json.\nconst { version } = createRequire(import.meta.url)(\"../package.json\") as { version: string };\n\nprocess.exitCode = await runCli(adrCli(version), processIO());\n"],"mappings":";;;;;;;;;;;;AAQA,SAAgB,WACd,IACA,OACA,IAAgD,CAAC,GAC3B;CACtB,OAAO,gBAAgB;EACrB,KAAK,GAAG;EACR,MAAM,MAAM;EACZ,KAAK,MAAM;EACX,GAAI,EAAE,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO;EACrD,YAAY,EAAE,KAAK,GAAG,IAAI;CAC5B,CAAC;AACH;;;;;AAMA,eAAsB,kBAAkB,KAA0D;CAChG,MAAM,OAAO,MAAM,cAAc,GAAG;CACpC,OAAO,EAAE,UAAU,OAAO,KAAK,WAAW,MAAM,IAAI,EAAE,CAAC,EAAE,WAAW,GAAG;AACzE;;AAGA,SAAgB,gBAAgB,KAAkB,QAA2C;CAC3F,OAAO,OAAO,OAAO,WAAW,YAAY,OAAO,SAAS,IAAI,IAAI;AACtE;;;ACzBA,SAAS,QAAQ,MAA8C;CAC7D,MAAM,SAAmB,CAAC;CAC1B,KAAK,MAAM,OAAO,MAChB,IAAI,SAAS,MAAM,MAAM;EACvB,OAAO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pE,QAAQ,WAAW,MAAM,OAAO,OAAO,OAAO,GAAG,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.js","names":["USAGE","strings","USAGE","USAGE","USAGE"],"sources":["../src/cli/open.ts","../src/cli/text.ts","../src/cli/accept.ts","../src/cli/deprecate.ts","../src/cli/for.ts","../src/cli/init.ts","../src/cli/link.ts","../src/cli/list.ts","../src/cli/editor.ts","../src/cli/new.ts","../src/cli/note.ts","../src/cli/reject.ts","../src/cli/scope.ts","../src/cli/show.ts","../src/cli/supersede.ts","../src/cli/withdraw.ts","../src/cli/commands.ts","../src/cli.ts"],"sourcesContent":["import type { CliIO, GlobalFlags } from \"@nikovirtala/ledger/cli\";\nimport { type DecisionLog, openDecisionLog, readDecisions } from \"../log.js\";\nimport type { Display } from \"./text.js\";\n\n/**\n * The decision log a command works on: `--root` and `--ref` from the globals, git run with the\n * CLI's environment.\n */\nexport function openForCli(\n io: CliIO,\n flags: GlobalFlags,\n o: { readonly reader?: \"worktree\" | \"index\" } = {},\n): Promise<DecisionLog> {\n return openDecisionLog({\n cwd: io.cwd,\n root: flags.root,\n ref: flags.ref,\n ...(o.reader === undefined ? {} : { reader: o.reader }),\n gitOptions: { env: io.env },\n });\n}\n\n/**\n * How other decisions display in a write's text, read again from the work tree, like the write\n * result's own views: a commit on the main ref has numbered the decisions it accepted.\n */\nexport async function displayAfterWrite(log: DecisionLog): Promise<{ readonly display: Display }> {\n const read = await readDecisions(log);\n return { display: (id) => read.projection.views.get(id)?.display ?? id };\n}\n","import {\n type Actor,\n type EventEnvelope,\n type Finding,\n renderStateHeader,\n} from \"@nikovirtala/ledger\";\nimport type { InitResultJson } from \"../init.js\";\nimport { adrKind, type DecisionView } from \"../kind.js\";\nimport type { DecisionsForJson } from \"../scope.js\";\nimport type { DecisionListJson, DecisionShowJson } from \"../views.js\";\nimport type { ScopeOffer, WriteResultJson } from \"../write.js\";\n\n/** How a decision id is shown: its display (`ADR-0007`), or the id when it has no number. */\nexport type Display = (id: string) => string;\n\n/** A table: each column padded to its widest value, trailing spaces removed. */\nfunction columns(rows: readonly (readonly string[])[]): string {\n const widths: number[] = [];\n for (const row of rows) {\n row.forEach((cell, i) => {\n widths[i] = Math.max(widths[i] ?? 0, cell.length);\n });\n }\n return rows\n .map((row) =>\n row\n .map((cell, i) => (i === row.length - 1 ? cell : cell.padEnd(widths[i] ?? 0)))\n .join(\" \")\n .trimEnd(),\n )\n .join(\"\\n\");\n}\n\n/** `adr list`: one row per decision, `→ <effective>` when it differs from the decision. */\nexport function listText(doc: DecisionListJson, display: Display): string {\n if (doc.decisions.length === 0) return \"No decisions.\";\n return columns(\n doc.decisions.map((v) => {\n const arrow =\n v.effective === null\n ? \"→ (cycle)\"\n : v.effective === v.id\n ? \"\"\n : `→ ${display(v.effective)}`;\n return [v.number === null ? \"-\" : v.display, v.id, v.status, v.title, arrow];\n }),\n );\n}\n\n/** `ADR-0003 (m2x7p4d2)`, or the id alone when it has no number. */\nfunction named(id: string, display: Display): string {\n const shown = display(id);\n return shown === id ? id : `${shown} (${id})`;\n}\n\nconst day = (at: string | null) => (at ?? \"\").slice(0, 10);\nconst list = (ids: readonly string[], display: Display) =>\n ids.length === 0 ? \"none\" : ids.map((id) => named(id, display)).join(\", \");\n\nfunction bodyLine(v: DecisionView): string {\n if (v.body_path === null) return \"missing\";\n if (v.body_intact === null) return v.body_path;\n return `${v.body_path} (${v.body_intact ? \"intact\" : \"changed after acceptance\"})`;\n}\n\nfunction actorText(e: EventEnvelope): string {\n const a = e.actor;\n return a.kind === \"agent\" ? `${a.name} (agent ${a.agent} for ${a.on_behalf_of})` : a.name;\n}\n\n/** The second line of an event in `show --history`: its reason, else a summary of its data. */\nfunction eventDetail(e: EventEnvelope): string | null {\n if (typeof e.reason === \"string\") return `reason: ${e.reason}`;\n const entries = Object.entries(e.data);\n if (entries.length === 0) return null;\n return entries\n .map(([k, v]) => `${k}: ${typeof v === \"string\" ? v : JSON.stringify(v)}`)\n .join(\", \");\n}\n\nfunction historyLines(events: readonly EventEnvelope[]): string[] {\n const width = Math.max(...events.map((e) => e.type.length));\n return events.flatMap((e) => {\n const detail = eventDetail(e);\n return [\n ` ${e.at} ${e.type.padEnd(width)} ${actorText(e)}`,\n ...(detail === null ? [] : [` ${detail}`]),\n ];\n });\n}\n\nconst SECTION_FINDING =\n /^(?:required )?section (.+?) (is missing|is empty|still contains its guidance text)$/;\nconst REASONS: Readonly<Record<string, string>> = {\n \"is missing\": \"missing\",\n \"is empty\": \"empty\",\n \"still contains its guidance text\": \"guidance text left\",\n};\n\n/** The section findings of a draft lint as headings and reasons, and the other findings. */\nfunction sectionGaps(findings: readonly Finding[]): {\n headings: string[];\n reasons: string[];\n other: Finding[];\n} {\n const headings: string[] = [];\n const reasons: string[] = [];\n const other: Finding[] = [];\n for (const f of findings) {\n const m = SECTION_FINDING.exec(f.message);\n if (m === null) {\n other.push(f);\n continue;\n }\n const [, heading = \"\", what = \"\"] = m;\n const reason = REASONS[what] ?? what;\n if (!headings.includes(heading)) headings.push(heading);\n if (!reasons.includes(reason)) reasons.push(reason);\n }\n return { headings, reasons, other };\n}\n\n/**\n * The draft lint of `new` as advice: `Fill in N sections before accepting: A, B (why)` for the\n * section findings, and one line per other finding.\n */\nfunction draftAdvice(findings: readonly Finding[]): string[] {\n const { headings, reasons, other } = sectionGaps(findings);\n const n = headings.length;\n return [\n ...(n === 0\n ? []\n : [\n `Fill in ${n === 1 ? \"1 section\" : `${n} sections`} before accepting: ${headings.join(\", \")} (${reasons.join(\", \")})`,\n ]),\n ...other.map((f) => `Draft: ${f.message} [${f.rule}]`),\n ];\n}\n\n/**\n * The stderr warning of `new` when the draft it wrote has unfilled sections (design §7.2), or\n * `null` when there are none.\n */\nexport function unfilledWarning(doc: WriteResultJson): string | null {\n if (doc.command !== \"new\" || !doc.ok || doc.written.length === 0) return null;\n const { headings, reasons } = sectionGaps(doc.findings);\n const n = headings.length;\n const path = doc.findings.find((f) => f.file !== null)?.file ?? doc.decision?.body_path ?? null;\n if (n === 0 || path === null) return null;\n return `${path}: fill in ${n === 1 ? \"1 required section\" : `${n} required sections`} before committing or accepting: ${headings.join(\", \")} (${reasons.join(\", \")}); adr verify reports this until then`;\n}\n\nfunction findingLines(findings: readonly Finding[]): string[] {\n return findings.map((f) => ` ${f.file === null ? \"\" : `${f.file}: `}${f.message} [${f.rule}]`);\n}\n\nconst short = (sha: string) => sha.slice(0, 7);\n\nexport interface FollowRenamesBefore {\n readonly before: ReadonlyMap<string, readonly string[]>;\n readonly renamed: boolean;\n}\n\n/**\n * `adr scope --follow-renames`: one `<named>: <old globs> → <new globs>` line per changed\n * decision (`affected`), whether or not a decision was given.\n */\nfunction followRenamesText(doc: WriteResultJson, display: Display, o: FollowRenamesBefore): string {\n if (!o.renamed) return \"No staged renames.\";\n if (doc.affected.length === 0) return \"No scope globs follow the staged renames.\";\n const lines = doc.affected.map((v) => {\n const before = o.before.get(v.id) ?? [];\n const old = before.filter((g) => !v.applies_to.includes(g));\n const now = v.applies_to.filter((g) => !before.includes(g));\n const change =\n old.length === 0 ? `+ ${now.join(\", \")}` : `${old.join(\", \")} → ${now.join(\", \")}`;\n return `${named(v.id, display)}: ${change}`;\n });\n return [...lines, \"Staged; commit the scoped events with the renames.\"].join(\"\\n\");\n}\n\n/** The past participle of each write command, for `Not <verb>: …`. */\nconst VERBS: Readonly<Record<WriteResultJson[\"command\"], string>> = {\n new: \"proposed\",\n accept: \"accepted\",\n supersede: \"superseded\",\n reject: \"rejected\",\n withdraw: \"withdrawn\",\n deprecate: \"deprecated\",\n note: \"noted\",\n link: \"linked\",\n scope: \"scoped\",\n};\n\n/**\n * The text of a write command (design §5.6, §6.1). `subject` names what a refused command was\n * about; `number` is the decision's number in the write result, if it has one now; `reason` is\n * the reason a lifecycle exit recorded.\n */\nexport function writeText(\n doc: WriteResultJson,\n display: Display,\n o: {\n readonly subject: string;\n readonly number: string | null;\n readonly reason?: string | null;\n /** The decision's globs before a `scope` write. */\n readonly scopeBefore?: readonly string[];\n /** For `scope --follow-renames`: every decision's globs before, and whether renames were staged. */\n readonly followRenames?: FollowRenamesBefore;\n /** The superseded scope an `accept` copied. */\n readonly copied?: ScopeOffer | null;\n /** Who proposed with `new`, and the log's `accept_requires_human`, for the next step. */\n readonly actor?: Actor;\n readonly acceptRequiresHuman?: boolean;\n },\n): string {\n const verb = VERBS[doc.command];\n if (!doc.ok) {\n // `new --commit` without an editor refuses a draft with unfilled sections (design §7.2).\n const unfilled = doc.command === \"new\" && sectionGaps(doc.findings).headings.length > 0;\n return [\n `Not ${verb}: ${o.subject}`,\n ...findingLines(doc.findings),\n ...(unfilled\n ? [\n \"Fill them in with --section <id>=<markdown>, or run without --commit and edit the draft.\",\n ]\n : []),\n ].join(\"\\n\");\n }\n // Before the null-decision guard: without a <decision>, `decision` is null (design-review L1).\n if (o.followRenames !== undefined) return followRenamesText(doc, display, o.followRenames);\n const v = doc.decision;\n if (v === null) return \"\";\n const committed = doc.commit === null ? null : `Committed ${short(doc.commit)}`;\n const recorded = committed === null ? \"Staged; commit to record it.\" : `${committed}.`;\n switch (doc.command) {\n case \"new\":\n return [\n `Proposed ${v.id}: ${v.title}`,\n ...doc.written.map((p) => ` ${p}`),\n ...draftAdvice(doc.findings),\n ...(committed === null ? [] : [`${committed}.`]),\n // An agent can't accept under accept_requires_human, so don't tell it to (design §7.1).\n o.actor?.kind === \"agent\" && o.acceptRequiresHuman === true\n ? `Next: ask a human to review and accept it (adr accept ${v.id})`\n : `Next: adr accept ${v.id}`,\n ].join(\"\\n\");\n case \"accept\":\n return [\n `Accepted ${v.id}: ${v.title}`,\n ...doc.affected.map((a) => `Superseded ${named(a.id, display)}: ${a.title}`),\n ...(o.copied === undefined || o.copied === null\n ? []\n : [`Copied scope from ${o.copied.displays.join(\", \")}: ${o.copied.globs.join(\", \")}`]),\n committed === null\n ? \"Staged; commit to record it.\"\n : o.number === null\n ? `${committed}. The number is assigned when this commit lands on main.`\n : `${committed} as ${o.number}.`,\n ].join(\"\\n\");\n case \"supersede\":\n return [\n `Superseded ${named(v.id, display)}: ${v.title}`,\n ` by ${named(v.superseded_by ?? \"\", display)}`,\n recorded,\n ].join(\"\\n\");\n case \"reject\":\n case \"withdraw\":\n case \"deprecate\":\n return [\n `${verb.charAt(0).toUpperCase()}${verb.slice(1)} ${named(v.id, display)}: ${v.title}`,\n ...(o.reason === undefined || o.reason === null ? [] : [` reason: ${o.reason}`]),\n recorded,\n ].join(\"\\n\");\n case \"note\":\n return [`Noted on ${named(v.id, display)}: ${v.title}`, recorded].join(\"\\n\");\n case \"link\": {\n // The reducer appends a new link, so the one written is the last.\n const link = doc.written.length === 0 ? undefined : v.links.at(-1);\n if (link === undefined) return `Links of ${named(v.id, display)} unchanged`;\n return [\n `Linked ${named(v.id, display)} ${link.rel} ${named(link.to, display)}`,\n recorded,\n ].join(\"\\n\");\n }\n case \"scope\": {\n const before = new Set(o.scopeBefore ?? []);\n const after = new Set(v.applies_to);\n const globs = v.applies_to.length === 0 ? \"no globs\" : v.applies_to.join(\", \");\n if (doc.written.length === 0) return `Scope of ${named(v.id, display)} unchanged: ${globs}`;\n return [\n `Scope of ${named(v.id, display)}: ${v.title}`,\n ...v.applies_to.filter((g) => !before.has(g)).map((g) => ` + ${g}`),\n ...[...before].filter((g) => !after.has(g)).map((g) => ` - ${g}`),\n ` = ${globs}`,\n recorded,\n ].join(\"\\n\");\n }\n }\n}\n\n/**\n * \"Applies to\" without globs: nothing is recorded, which isn't \"governs nothing\" (design §7.3),\n * with the command that adds globs while the decision can still take them.\n */\nfunction noGlobs(v: DecisionView, display: Display): string {\n return adrKind.machine.allowed(v.status, \"scoped\")\n ? `no globs recorded; add them with adr scope ${display(v.id)} --add <glob>`\n : \"no globs recorded\";\n}\n\n/** `adr show`: the state header, the decision's fields and its body. */\nexport function showText(doc: DecisionShowJson, display: Display): string {\n const v = doc.decision;\n const supersedes =\n v.supersedes.length === 0 && v.declared_supersedes.length > 0\n ? `none (declared: ${list(v.declared_supersedes, display)})`\n : list(v.supersedes, display);\n const fields: [string, string][] = [\n [\"Title\", v.title],\n [\"Status\", `${v.status} (${day(v.status_at)})`],\n [\"Effective\", v.effective === null ? \"none (supersession cycle)\" : named(v.effective, display)],\n [\"Chain\", v.chain.map(display).join(\" → \")],\n [\"Supersedes\", supersedes],\n [\"Applies to\", v.applies_to.length === 0 ? noGlobs(v, display) : v.applies_to.join(\", \")],\n [\"Body\", bodyLine(v)],\n ];\n if (doc.events === null) fields.push([\"History\", v.history.join(\" · \")]);\n const width = Math.max(...fields.map(([k]) => k.length)) + 2;\n const lines = fields.map(([k, value]) => `${`${k}:`.padEnd(width)}${value}`);\n if (doc.events !== null) lines.push(\"History:\", ...historyLines(doc.events));\n const body = doc.body === null ? \"\" : `\\n${doc.body.endsWith(\"\\n\") ? doc.body : `${doc.body}\\n`}`;\n return `${renderStateHeader(doc.header)}\\n${lines.join(\"\\n\")}\\n${body}`;\n}\n\n/**\n * `adr for`: per path, one row per decision (named, status, title, how it matched), its warning\n * below it when it isn't in force, then the anchors that name no decision of this log.\n */\nexport function forText(doc: DecisionsForJson, display: Display, keyword: string): string {\n const lines: string[] = [];\n for (const p of doc.paths) {\n lines.push(p.tracked ? p.path : `${p.path} (not tracked)`);\n if (p.decisions.length === 0 && p.unresolved.length === 0) lines.push(\" no decisions\");\n const rows = columns(\n p.decisions.map((d) => [\n named(d.id, display),\n d.status,\n d.title,\n d.via\n .map((v) => (v.type === \"glob\" ? `glob ${v.glob}` : `anchor line ${v.line}`))\n .join(\", \"),\n ]),\n ).split(\"\\n\");\n p.decisions.forEach((d, i) => {\n lines.push(` ${rows[i] ?? \"\"}`);\n if (d.warning !== null) lines.push(` ${d.warning}`);\n });\n for (const u of p.unresolved) {\n const why = u.reason === \"other-log\" ? \"in another log\" : \"not in this log\";\n lines.push(` unresolved: ${keyword}:${u.ref} (line ${u.line}, ${why})`);\n }\n }\n return lines.join(\"\\n\");\n}\n\n/** `adr init`: what was written and kept, then the next step; or that nothing was needed. */\nexport function initText(doc: InitResultJson): string {\n if (doc.written.length === 0) {\n return `Already initialized: ${doc.root} (kept ${doc.kept.join(\", \")})`;\n }\n return [\n `Initialized ${doc.root}`,\n ...doc.written.map((p) => ` ${p}`),\n ...doc.kept.map((p) => `Kept ${p}`),\n ...(doc.commit === null ? [] : [`Committed ${short(doc.commit)}.`]),\n 'Next: adr new \"<title>\"',\n ].join(\"\\n\");\n}\n","import { type JsonValue, resolveAttribution } from \"@nikovirtala/ledger\";\nimport {\n type CliIO,\n COMMIT_OPTIONS,\n type CommandSpec,\n commitChoice,\n confirm,\n} from \"@nikovirtala/ledger/cli\";\nimport { acceptDecision, type CopyScope, type ScopeOffer } from \"../write.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\nconst MAX_LISTED = 5;\n\n/** `Copy the scope of ADR-0002 (src/a/**, src/b/**) to k3f9q8a1? [y/N] ` (design §6.10). */\nfunction question(id: string, offer: ScopeOffer): string {\n const shown = offer.globs.slice(0, MAX_LISTED).join(\", \");\n const more = offer.globs.length - MAX_LISTED;\n const globs = more > 0 ? `${shown} and ${more} more` : shown;\n const ds = offer.displays;\n const sources = ds.length === 1 ? ds[0] : `${ds.slice(0, -1).join(\", \")} and ${ds.at(-1)}`;\n const list = ds.length === 1 ? globs : `${offer.globs.length} globs: ${globs}`;\n return `Copy the scope of ${sources} (${list}) to ${id}? [y/N] `;\n}\n\n/**\n * The flags decide; without them a person at a terminal is asked, and everyone else (scripts,\n * hooks, CI, `--json`) gets the note with the `adr scope` command (design §6.10, D-e). `seen`\n * receives the offer that was copied, for the text.\n */\nfunction copyChoice(\n io: CliIO,\n json: boolean,\n value: unknown,\n seen: (offer: ScopeOffer) => void,\n): CopyScope {\n const copy = async (offer: ScopeOffer) => {\n seen(offer);\n return true;\n };\n if (value === true) return copy;\n if (value === false) return \"skip\";\n if (json || !io.interactive) return \"suggest\";\n return async (offer) => {\n const yes = await confirm(io, question(offer.id, offer), { json });\n if (yes) seen(offer);\n return yes;\n };\n}\n\n/** `adr accept <decision> [--copy-scope | --no-copy-scope] …` (design §5.6, §6.10). */\nexport const acceptCommand: CommandSpec = {\n name: \"accept\",\n summary: \"accept a proposed decision, superseding the decisions it declares\",\n usage:\n \"accept <decision> [--copy-scope | --no-copy-scope] [--commit | --no-commit] [-m <message>]\",\n options: { \"copy-scope\": { type: \"boolean\" }, ...COMMIT_OPTIONS },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const input = positionals[0] ?? \"\";\n const log = await openForCli(io, flags);\n const { actor, notes: attribution } = await resolveAttribution(log.git, { env: io.env });\n const seen: { offer: ScopeOffer | null } = { offer: null };\n const copyScope = copyChoice(io, flags.json, values[\"copy-scope\"], (offer) => {\n seen.offer = offer;\n });\n const doc = await acceptDecision(\n log,\n { id: input, actor },\n {\n ...commitChoice(values, { autoCommit: log.adr.autoCommit }),\n notes: attribution,\n copyScope,\n },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: v === null || doc.commit === null || v.number === null ? null : v.display,\n copied: doc.ok ? seen.offer : null,\n }),\n notes: doc.notes,\n };\n },\n};\n","import { type JsonValue, resolveAttribution, UsageError } from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { deprecateDecision } from \"../write.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\nconst USAGE = \"deprecate <decision> --reason <text> [--commit | --no-commit] [-m <message>]\";\n\n/** `adr deprecate` (design §6.5): an accepted decision no longer in force. */\nexport const deprecateCommand: CommandSpec = {\n name: \"deprecate\",\n summary: \"deprecate an accepted decision\",\n usage: USAGE,\n options: { reason: { type: \"string\" }, ...COMMIT_OPTIONS },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const input = positionals[0] ?? \"\";\n if (typeof values.reason !== \"string\" || values.reason.trim() === \"\") {\n throw new UsageError(`missing --reason <text>; usage: adr ${USAGE}`);\n }\n const reason = typeof values.reason === \"string\" ? values.reason.trim() : null;\n const log = await openForCli(io, flags);\n const { actor, notes } = await resolveAttribution(log.git, { env: io.env });\n const doc = await deprecateDecision(\n log,\n { id: input, reason, actor },\n { ...commitChoice(values, { autoCommit: log.adr.autoCommit }), notes },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n reason,\n }),\n notes: doc.notes,\n };\n },\n};\n","import type { JsonValue } from \"@nikovirtala/ledger\";\nimport type { CommandSpec } from \"@nikovirtala/ledger/cli\";\nimport { readDecisions } from \"../log.js\";\nimport { decisionsFor } from \"../scope.js\";\nimport { openForCli } from \"./open.js\";\nimport { forText } from \"./text.js\";\n\n/** `adr for <path>… [--ref <ref>]` (design §6.9): the decisions that govern each file. */\nexport const forCommand: CommandSpec = {\n name: \"for\",\n summary: \"list the decisions that govern files, by scope glob and code anchor\",\n usage: \"for <path>…\",\n options: {},\n positionals: { min: 1, max: 100, names: [\"path\"] },\n ref: \"read\",\n async run({ io, flags, positionals }) {\n const log = await openForCli(io, flags);\n const read = await readDecisions(log);\n const doc = await decisionsFor(read, log, { paths: positionals, cwd: io.cwd });\n const display = (id: string) => read.projection.views.get(id)?.display ?? id;\n return {\n exit: 0,\n json: doc as unknown as JsonValue,\n text: forText(doc, display, read.adr.anchorKeyword),\n notes: doc.notes,\n };\n },\n};\n","import type { JsonValue } from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { initDecisionLog } from \"../init.js\";\nimport { openForCli } from \"./open.js\";\nimport { initText } from \"./text.js\";\n\n/** `adr init [--template <name>]… [--commit | --no-commit] [-m <message>]` (design §6.2). */\nexport const initCommand: CommandSpec = {\n name: \"init\",\n summary: \"set up a decision log: a config file and starter templates\",\n usage: \"init [--template <name>]… [--commit | --no-commit] [-m <message>]\",\n options: { template: { type: \"string\", multiple: true }, ...COMMIT_OPTIONS },\n positionals: { min: 0, max: 0, names: [] },\n ref: \"reject\",\n async run({ io, flags, values }) {\n const templates = Array.isArray(values.template) ? (values.template as string[]) : undefined;\n const log = await openForCli(io, flags);\n const doc = await initDecisionLog(log, {\n ...(templates === undefined ? {} : { templates }),\n ...commitChoice(values, { autoCommit: log.adr.autoCommit }),\n });\n return { exit: 0, json: doc as unknown as JsonValue, text: initText(doc), notes: doc.notes };\n },\n};\n","import { type JsonValue, resolveAttribution } from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { linkDecision } from \"../write.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\n/** `adr link <decision> <target> [--rel <rel>]` (design §6.7): a typed link, in any state. */\nexport const linkCommand: CommandSpec = {\n name: \"link\",\n summary: \"link a decision to another one, here or in a configured source\",\n usage:\n \"link <decision> <target> [--rel relates-to|refines|depends-on] [--commit | --no-commit] [-m <message>]\",\n options: { rel: { type: \"string\" }, ...COMMIT_OPTIONS },\n positionals: { min: 2, max: 2, names: [\"decision\", \"target\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const [input = \"\", to = \"\"] = positionals;\n const rel = typeof values.rel === \"string\" ? values.rel : \"relates-to\";\n const log = await openForCli(io, flags);\n const { actor, notes } = await resolveAttribution(log.git, { env: io.env });\n const doc = await linkDecision(\n log,\n { id: input, to, rel, actor },\n { ...commitChoice(values, { autoCommit: log.adr.autoCommit }), notes },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n }),\n notes: doc.notes,\n };\n },\n};\n","import { type JsonValue, UsageError } from \"@nikovirtala/ledger\";\nimport type { CommandSpec } from \"@nikovirtala/ledger/cli\";\nimport { DECISION_STATUSES, type DecisionStatus } from \"../kind.js\";\nimport { readDecisions, unavailableReason } from \"../log.js\";\nimport { listDecisions } from \"../views.js\";\nimport { openForCli } from \"./open.js\";\nimport { listText } from \"./text.js\";\n\nconst plural = (n: number, one: string, many: string) => (n === 1 ? `1 ${one}` : `${n} ${many}`);\n\nfunction statuses(values: Readonly<Record<string, unknown>>): DecisionStatus[] {\n const given = Array.isArray(values.status) ? (values.status as string[]) : [];\n return given.map((s) => {\n if (!(DECISION_STATUSES as readonly string[]).includes(s)) {\n throw new UsageError(\n `unknown status ${JSON.stringify(s)}; use one of ${DECISION_STATUSES.join(\", \")}`,\n );\n }\n return s as DecisionStatus;\n });\n}\n\n/** `adr list [--status <status>]…` (design §5.6). */\nexport const listCommand: CommandSpec = {\n name: \"list\",\n summary: \"list decisions with their computed status\",\n usage: \"list [--status <status>]…\",\n options: { status: { type: \"string\", multiple: true } },\n positionals: { min: 0, max: 0, names: [] },\n ref: \"read\",\n async run({ io, flags, values }) {\n const status = statuses(values);\n const read = await readDecisions(await openForCli(io, flags));\n const doc = listDecisions(read, { status });\n const notes = [...doc.notes];\n if (!read.numbering.available && doc.decisions.length > 0) {\n notes.push(\n `numbers are unavailable (${unavailableReason(read.numbering)}); decisions display by id`,\n );\n }\n if (doc.findings.length > 0) {\n notes.push(\n `the decision log has ${plural(doc.findings.length, \"problem\", \"problems\")}; run adr verify`,\n );\n }\n if (doc.unreadable.length > 0) {\n notes.push(\n `${plural(doc.unreadable.length, \"decision uses\", \"decisions use\")} a newer format; upgrade adr`,\n );\n }\n if (doc.unfoldable.length > 0) {\n notes.push(\n `${plural(doc.unfoldable.length, \"decision\", \"decisions\")} can't be read; run adr verify`,\n );\n }\n const display = (id: string) => read.projection.views.get(id)?.display ?? id;\n return { exit: 0, json: doc as unknown as JsonValue, text: listText(doc, display), notes };\n },\n};\n","import { spawn } from \"node:child_process\";\n\n/** The `edit` callback of `proposeDecision`: `null` when the editor exited 0, else a note. */\nexport type Edit = (absPath: string) => Promise<string | null>;\n\n/**\n * The user's editor as an `edit` callback (design §5.7), or `null` when neither `VISUAL` nor\n * `EDITOR` is set. The editor string is run by `sh -c` the way git runs `core.editor`, with the\n * path as the positional parameter `$1`, never interpolated. When stdout isn't a TTY (piped\n * `--json`, say), the editor's stdout goes to stderr so the CLI's stdout stays one document.\n * The callback never throws: a spawn error or a non-zero exit becomes the note.\n */\nexport function editorFor(\n env: NodeJS.ProcessEnv,\n o: { readonly stdoutIsTTY: boolean },\n): Edit | null {\n const editor = [env.VISUAL, env.EDITOR].map((v) => v?.trim() ?? \"\").find((v) => v !== \"\");\n if (editor === undefined) return null;\n return (absPath) =>\n new Promise((resolve) => {\n const fail = (e: unknown) =>\n resolve(`could not start the editor: ${e instanceof Error ? e.message : String(e)}`);\n try {\n const child = spawn(\"sh\", [\"-c\", `${editor} \"$1\"`, \"sh\", absPath], {\n env,\n stdio: o.stdoutIsTTY ? \"inherit\" : [\"inherit\", 2, \"inherit\"],\n });\n child.on(\"error\", fail);\n child.on(\"close\", (code, signal) => {\n if (code === 0) resolve(null);\n else {\n const how =\n code === null\n ? `was killed by ${signal ?? \"a signal\"}`\n : `exited with status ${code}`;\n resolve(`the editor ${how}; the draft is staged as rendered`);\n }\n });\n } catch (e) {\n fail(e);\n }\n });\n}\n","import { type JsonValue, resolveAttribution, UsageError } from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { proposeDecision } from \"../write.js\";\nimport { editorFor } from \"./editor.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { unfilledWarning, writeText } from \"./text.js\";\n\nconst strings = (v: unknown): string[] => (Array.isArray(v) ? (v as string[]) : []);\n\n/** `--section <id>=<markdown>` values, split at the first `=`; each id at most once. */\nfunction sections(values: readonly string[]): Record<string, string> {\n const out: Record<string, string> = {};\n for (const value of values) {\n const at = value.indexOf(\"=\");\n const id = at < 0 ? \"\" : value.slice(0, at).trim();\n if (id === \"\") {\n throw new UsageError(`--section needs <id>=<markdown>, not ${JSON.stringify(value)}`);\n }\n if (Object.hasOwn(out, id)) throw new UsageError(`--section ${id} is given twice`);\n out[id] = value.slice(at + 1);\n }\n return out;\n}\n\n/**\n * `adr new <title> …` (design §5.6). The editor runs with `--edit`, or without `--no-edit` when\n * the terminal is interactive and an editor is set.\n */\nexport const newCommand: CommandSpec = {\n name: \"new\",\n summary: \"propose a decision from a template and stage it\",\n usage:\n \"new <title> [--template <name>] [--supersedes <decision>]… [--section <id>=<markdown>]… [--edit | --no-edit] [--commit | --no-commit] [-m <message>]\",\n options: {\n template: { type: \"string\" },\n supersedes: { type: \"string\", multiple: true },\n section: { type: \"string\", multiple: true },\n edit: { type: \"boolean\" },\n ...COMMIT_OPTIONS,\n },\n positionals: { min: 1, max: 1, names: [\"title\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const title = positionals[0] ?? \"\";\n const given = sections(strings(values.section));\n const log = await openForCli(io, flags);\n const { actor, notes: attribution } = await resolveAttribution(log.git, { env: io.env });\n // Design review NIT 1: the skip notes say \"not committed\" only when a commit was asked for.\n const { commit: requested, message } = commitChoice(values, {\n autoCommit: log.adr.autoCommit,\n });\n const notes: string[] = [];\n const editor = editorFor(io.env, { stdoutIsTTY: io.stdoutIsTTY });\n const wantsEdit = values.edit === true || (values.edit === undefined && io.interactive);\n if (values.edit === true && editor === null) notes.push(\"no editor: set VISUAL or EDITOR\");\n const edit =\n wantsEdit && editor !== null\n ? async (abs: string) => {\n const note = await editor(abs);\n if (note !== null) notes.push(note);\n return note;\n }\n : undefined;\n const doc = await proposeDecision(\n log,\n {\n title,\n sections: given,\n supersedes: strings(values.supersedes),\n actor,\n ...(typeof values.template === \"string\" ? { template: values.template } : {}),\n },\n {\n commit: requested,\n message,\n notes: attribution,\n ...(edit === undefined ? {} : { edit }),\n onNote: (note) => notes.push(requested ? `not committed: ${note}` : note),\n },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n const unfilled = unfilledWarning(doc);\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: title.trim(),\n number: v === null || v.number === null ? null : v.display,\n actor,\n acceptRequiresHuman: log.adr.acceptRequiresHuman,\n }),\n notes: [...doc.notes, ...notes, ...(unfilled === null ? [] : [unfilled])],\n };\n },\n};\n","import { type JsonValue, resolveAttribution } from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { noteDecision } from \"../write.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\n/** `adr note <decision> <text>` (design §6.6): a note on a decision in any state. */\nexport const noteCommand: CommandSpec = {\n name: \"note\",\n summary: \"add a note to a decision, in any state\",\n usage: \"note <decision> <text> [--commit | --no-commit] [-m <message>]\",\n options: { ...COMMIT_OPTIONS },\n positionals: { min: 2, max: 2, names: [\"decision\", \"text\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const [input = \"\", text = \"\"] = positionals;\n const log = await openForCli(io, flags);\n const { actor, notes } = await resolveAttribution(log.git, { env: io.env });\n const doc = await noteDecision(\n log,\n { id: input, text, actor },\n { ...commitChoice(values, { autoCommit: log.adr.autoCommit }), notes },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n }),\n notes: doc.notes,\n };\n },\n};\n","import { type JsonValue, resolveAttribution, UsageError } from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { rejectDecision } from \"../write.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\nconst USAGE = \"reject <decision> --reason <text> [--commit | --no-commit] [-m <message>]\";\n\n/** `adr reject` (design §6.3): a proposal that won't be adopted. */\nexport const rejectCommand: CommandSpec = {\n name: \"reject\",\n summary: \"reject a proposed decision\",\n usage: USAGE,\n options: { reason: { type: \"string\" }, ...COMMIT_OPTIONS },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const input = positionals[0] ?? \"\";\n if (typeof values.reason !== \"string\" || values.reason.trim() === \"\") {\n throw new UsageError(`missing --reason <text>; usage: adr ${USAGE}`);\n }\n const reason = typeof values.reason === \"string\" ? values.reason.trim() : null;\n const log = await openForCli(io, flags);\n const { actor, notes } = await resolveAttribution(log.git, { env: io.env });\n const doc = await rejectDecision(\n log,\n { id: input, reason, actor },\n { ...commitChoice(values, { autoCommit: log.adr.autoCommit }), notes },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n reason,\n }),\n notes: doc.notes,\n };\n },\n};\n","import {\n type JsonValue,\n resolveAttribution,\n type SetOp,\n stagedRenames,\n UsageError,\n} from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { readDecisions, resolveDecision } from \"../log.js\";\nimport { followScopeRenames, scopeDecision } from \"../write.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\nconst USAGE =\n \"scope <decision> ([--set <glob>]… | --clear | [--add <glob>]… [--remove <glob>]…) [--commit | --no-commit] [-m <message>] | scope [<decision>] --follow-renames\";\n/** The flag names `applySetOp` uses in its messages (design §3.2). */\nconst NAMES = { set: \"--set\", add: \"--add\", remove: \"--remove\", clear: \"--clear\" } as const;\n\nconst strings = (v: unknown): string[] => (Array.isArray(v) ? (v as string[]) : []);\n\n/** `--set`/`--clear`/`--add`/`--remove` as a set operation; `--clear` is `{ set: [] }`. */\nfunction setOp(values: Readonly<Record<string, unknown>>): SetOp {\n const set = strings(values.set);\n const add = strings(values.add);\n const remove = strings(values.remove);\n if (values.clear === true) {\n if (set.length > 0 || add.length > 0 || remove.length > 0) {\n throw new UsageError(\"--clear can't be combined with --set, --add or --remove\");\n }\n return { set: [] };\n }\n return { ...(set.length > 0 ? { set } : {}), add, remove };\n}\n\n/**\n * `--follow-renames` alone: no set operation, no commit and no message, all refused before\n * `commitChoice` so the answer doesn't depend on `auto_commit` (design §6.8).\n */\nfunction checkFollowRenames(values: Readonly<Record<string, unknown>>): void {\n const op = [\"set\", \"add\", \"remove\"].some((k) => strings(values[k]).length > 0);\n if (op || values.clear === true) {\n throw new UsageError(\n \"--follow-renames can't be combined with --set, --clear, --add or --remove\",\n );\n }\n if (values.commit === true) {\n throw new UsageError(\n \"--follow-renames stages its events for the commit that contains the renames; commit them together\",\n );\n }\n if (typeof values.message === \"string\") {\n throw new UsageError(\"--follow-renames never commits, so it takes no --message\");\n }\n}\n\n/**\n * `adr scope <decision> --set|--clear|--add|--remove …` (design §6.8): the globs of the code a\n * decision governs, written as one whole-set `scoped` event. `adr scope [<decision>]\n * --follow-renames` rewrites them after staged renames and stages the events, never committing.\n */\nexport const scopeCommand: CommandSpec = {\n name: \"scope\",\n summary: \"set, add or remove the globs of the code a decision governs\",\n usage: USAGE,\n options: {\n set: { type: \"string\", multiple: true },\n add: { type: \"string\", multiple: true },\n remove: { type: \"string\", multiple: true },\n clear: { type: \"boolean\" },\n \"follow-renames\": { type: \"boolean\" },\n ...COMMIT_OPTIONS,\n },\n positionals: { min: 0, max: 1, names: [\"decision\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const input = positionals[0];\n if (values[\"follow-renames\"] === true) {\n checkFollowRenames(values);\n const log = await openForCli(io, flags);\n const { actor, notes } = await resolveAttribution(log.git, { env: io.env });\n const read = await readDecisions(log);\n const before = new Map([...read.projection.views].map(([id, v]) => [id, v.applies_to]));\n const renamed = (await stagedRenames(log.git)).length > 0;\n const doc = await followScopeRenames(\n log,\n { ...(input === undefined ? {} : { id: input }), actor },\n { notes },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? (input ?? \"\").trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n followRenames: { before, renamed },\n }),\n notes: doc.notes,\n };\n }\n const op = setOp(values);\n if (input === undefined)\n throw new UsageError(`missing argument <decision>; usage: adr ${USAGE}`);\n const log = await openForCli(io, flags);\n const { actor, notes } = await resolveAttribution(log.git, { env: io.env });\n const choice = commitChoice(values, { autoCommit: log.adr.autoCommit });\n const read = await readDecisions(log);\n const before = read.projection.views.get(resolveDecision(read, input))?.applies_to ?? [];\n const doc = await scopeDecision(\n log,\n { id: input, op, actor, names: NAMES },\n { ...choice, notes },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n scopeBefore: before,\n }),\n notes: doc.notes,\n };\n },\n};\n","import type { JsonValue } from \"@nikovirtala/ledger\";\nimport type { CommandSpec } from \"@nikovirtala/ledger/cli\";\nimport { readDecisions, resolveDecision } from \"../log.js\";\nimport { showDecision } from \"../views.js\";\nimport { openForCli } from \"./open.js\";\nimport { showText } from \"./text.js\";\n\n/** `adr show <decision> [--history]` (design §5.6). */\nexport const showCommand: CommandSpec = {\n name: \"show\",\n summary: \"show a decision with its state header, chain, history and body\",\n usage: \"show <decision> [--history]\",\n options: { history: { type: \"boolean\" } },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"read\",\n async run({ io, flags, values, positionals }) {\n const read = await readDecisions(await openForCli(io, flags));\n const id = resolveDecision(read, positionals[0] ?? \"\");\n const doc = await showDecision(read, id, { history: values.history === true });\n const display = (s: string) => read.projection.views.get(s)?.display ?? s;\n return {\n exit: 0,\n json: doc as unknown as JsonValue,\n text: showText(doc, display),\n notes: doc.notes,\n };\n },\n};\n","import { type JsonValue, resolveAttribution, UsageError } from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { supersedeDecision } from \"../write.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\nconst USAGE =\n \"supersede <decision> --by <decision> [--reason <text>] [--commit | --no-commit] [-m <message>]\";\n\n/** `adr supersede <decision> --by <decision> …` (design §5.6). */\nexport const supersedeCommand: CommandSpec = {\n name: \"supersede\",\n summary: \"mark an accepted decision as superseded by another accepted one\",\n usage: USAGE,\n options: { by: { type: \"string\" }, reason: { type: \"string\" }, ...COMMIT_OPTIONS },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const input = positionals[0] ?? \"\";\n if (typeof values.by !== \"string\") {\n throw new UsageError(`missing --by <decision>; usage: adr ${USAGE}`);\n }\n const log = await openForCli(io, flags);\n const { actor, notes: attribution } = await resolveAttribution(log.git, { env: io.env });\n const doc = await supersedeDecision(\n log,\n {\n id: input,\n by: values.by,\n actor,\n ...(typeof values.reason === \"string\" ? { reason: values.reason } : {}),\n },\n { ...commitChoice(values, { autoCommit: log.adr.autoCommit }), notes: attribution },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n }),\n notes: doc.notes,\n };\n },\n};\n","import { type JsonValue, resolveAttribution, UsageError } from \"@nikovirtala/ledger\";\nimport { COMMIT_OPTIONS, type CommandSpec, commitChoice } from \"@nikovirtala/ledger/cli\";\nimport { withdrawDecision } from \"../write.js\";\nimport { displayAfterWrite, openForCli } from \"./open.js\";\nimport { writeText } from \"./text.js\";\n\nconst USAGE = \"withdraw <decision> [--reason <text>] [--commit | --no-commit] [-m <message>]\";\n\n/** `adr withdraw` (design §6.4): a proposal its author takes back. */\nexport const withdrawCommand: CommandSpec = {\n name: \"withdraw\",\n summary: \"withdraw a proposed decision\",\n usage: USAGE,\n options: { reason: { type: \"string\" }, ...COMMIT_OPTIONS },\n positionals: { min: 1, max: 1, names: [\"decision\"] },\n ref: \"reject\",\n async run({ io, flags, values, positionals }) {\n const input = positionals[0] ?? \"\";\n if (typeof values.reason === \"string\" && values.reason.trim() === \"\") {\n throw new UsageError(\"--reason must not be empty\");\n }\n const reason = typeof values.reason === \"string\" ? values.reason.trim() : null;\n const log = await openForCli(io, flags);\n const { actor, notes } = await resolveAttribution(log.git, { env: io.env });\n const doc = await withdrawDecision(\n log,\n { id: input, reason, actor },\n { ...commitChoice(values, { autoCommit: log.adr.autoCommit }), notes },\n );\n const { display } = await displayAfterWrite(log);\n const v = doc.decision;\n return {\n exit: doc.ok ? 0 : 1,\n json: doc as unknown as JsonValue,\n text: writeText(doc, display, {\n subject: v === null ? input.trim() : `${display(v.id)}: ${v.title}`,\n number: null,\n reason,\n }),\n notes: doc.notes,\n };\n },\n};\n","import { templateHistoryRef } from \"@nikovirtala/ledger\";\nimport { type ToolCli, verifyCommand } from \"@nikovirtala/ledger/cli\";\nimport { adrKind } from \"../kind.js\";\nimport { adrChecks } from \"../verify.js\";\nimport { acceptCommand } from \"./accept.js\";\nimport { deprecateCommand } from \"./deprecate.js\";\nimport { forCommand } from \"./for.js\";\nimport { initCommand } from \"./init.js\";\nimport { linkCommand } from \"./link.js\";\nimport { listCommand } from \"./list.js\";\nimport { newCommand } from \"./new.js\";\nimport { noteCommand } from \"./note.js\";\nimport { openForCli } from \"./open.js\";\nimport { rejectCommand } from \"./reject.js\";\nimport { scopeCommand } from \"./scope.js\";\nimport { showCommand } from \"./show.js\";\nimport { supersedeCommand } from \"./supersede.js\";\nimport { withdrawCommand } from \"./withdraw.js\";\n\n/**\n * ledger's shared `verify`: the log as the mode reads it (the index for `--staged`, else the\n * `--ref` tree or the work tree), every phase-1 check, and `[verify] fail_on`.\n */\nconst verify = verifyCommand({\n async open({ io, flags, mode }) {\n const log = await openForCli(io, flags, {\n reader: mode.type === \"staged\" ? \"index\" : \"worktree\",\n });\n return {\n git: log.git,\n kind: adrKind,\n layout: log.layout,\n checks: adrChecks(log, await templateHistoryRef(log.git, mode)),\n failOn: log.adr.failOn,\n notes: log.notes,\n };\n },\n});\n\n/** The `adr` tool: its commands, for ledger's `runCli`. */\nexport function adrCli(version: string): ToolCli {\n return {\n name: \"adr\",\n version,\n summary: \"Architecture decision records kept as event logs in git.\",\n commands: [\n initCommand,\n newCommand,\n acceptCommand,\n rejectCommand,\n withdrawCommand,\n deprecateCommand,\n supersedeCommand,\n noteCommand,\n linkCommand,\n scopeCommand,\n forCommand,\n listCommand,\n showCommand,\n verify,\n ],\n };\n}\n","#!/usr/bin/env node\nimport { createRequire } from \"node:module\";\nimport { processIO, runCli } from \"@nikovirtala/ledger/cli\";\nimport { adrCli } from \"./cli/commands.js\";\n\n// Read at run time, relative to dist/cli.js (or src/cli.ts): both sit next to ../package.json.\nconst { version } = createRequire(import.meta.url)(\"../package.json\") as { version: string };\n\nprocess.exitCode = await runCli(adrCli(version), processIO());\n"],"mappings":";;;;;;;;;;;;AAQA,SAAgB,WACd,IACA,OACA,IAAgD,CAAC,GAC3B;CACtB,OAAO,gBAAgB;EACrB,KAAK,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AM,SAAS,cAAc,EAC3B,MAAM,KAAK,EAAE,IAAI,OAAO,QAAQ;CAC9B,MAAM,MAAM,MAAM,WAAW,IAAI,OAAO,EACtC,QAAQ,KAAK,SAAS,WAAW,UAAU,WAC7C,CAAC;CACD,OAAO;EACL,KAAK,IAAI;EACT,MAAM;EACN,QAAQ,IAAI;EACZ,QAAQ,UAAU,KAAK,MAAM,mBAAmB,IAAI,KAAK,IAAI,CAAC;EAC9D,QAAQ,IAAI,IAAI;EAChB,OAAO,IAAI;CACb;AACF,EACF,CAAC;;AAGD,SAAgB,OAAO,SAA0B;CAC/C,OAAO;EACL,MAAM;EACN;EACA,SAAS;EACT,UAAU;GACR;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF;CACF;AACF;;ACxDA,MAAM,EAAE,YAAY,cAAc,YAAY,GAAG,CAAC,CAAC,iBAAiB;AAEpE,QAAQ,WAAW,MAAM,OAAO,OAAO,OAAO,GAAG,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { a as
|
|
3
|
-
export { DECISION_STATUSES, DEFAULT_ADR_CONFIG, REF, acceptDecision, adrChecks, adrKind, formatDecisionNumber, listDecisions, openDecisionLog, parseAdrConfig, parseDecisionNumber, proposeDecision, readDecisions, readDecisionsFrom, resolveDecision, showDecision, stateHeader, supersedeDecision, verifyDecisions };
|
|
1
|
+
import { a as parseDecisionNumber, i as formatDecisionNumber, n as DECISION_STATUSES, r as REF, t as adrKind } from "./kind-BcHjCHvi.js";
|
|
2
|
+
import { C as initDecisionLog, T as parseAdrConfig, _ as stateHeader, a as noteDecision, b as readDecisionsFrom, c as scopeDecision, d as withdrawDecision, f as adrChecks, g as showDecision, h as listDecisions, i as linkDecision, l as scopeToCopy, m as decisionsFor, n as deprecateDecision, o as proposeDecision, p as verifyDecisions, r as followScopeRenames, s as rejectDecision, t as acceptDecision, u as supersedeDecision, v as openDecisionLog, w as DEFAULT_ADR_CONFIG, x as resolveDecision, y as readDecisions } from "./write-9IaqHRrY.js";
|
|
3
|
+
export { DECISION_STATUSES, DEFAULT_ADR_CONFIG, REF, acceptDecision, adrChecks, adrKind, decisionsFor, deprecateDecision, followScopeRenames, formatDecisionNumber, initDecisionLog, linkDecision, listDecisions, noteDecision, openDecisionLog, parseAdrConfig, parseDecisionNumber, proposeDecision, readDecisions, readDecisionsFrom, rejectDecision, resolveDecision, scopeDecision, scopeToCopy, showDecision, stateHeader, supersedeDecision, verifyDecisions, withdrawDecision };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineKind, eventType } from "@nikovirtala/ledger";
|
|
1
|
+
import { defineKind, eventType, setEventType } from "@nikovirtala/ledger";
|
|
2
2
|
// src/kind/project.ts
|
|
3
3
|
const NUMBER = /^(?:adr-?)?0*([1-9][0-9]{0,8})$/i;
|
|
4
4
|
/** `ADR-0007`: at least 4 digits, growing past 9999. */
|
|
@@ -341,27 +341,18 @@ const decisionEvents = {
|
|
|
341
341
|
allowedIn: "any",
|
|
342
342
|
to: null
|
|
343
343
|
}),
|
|
344
|
-
scoped:
|
|
345
|
-
|
|
346
|
-
type: "
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
type: "array",
|
|
350
|
-
items: {
|
|
351
|
-
type: "string",
|
|
352
|
-
minLength: 1,
|
|
353
|
-
maxLength: 500
|
|
354
|
-
},
|
|
355
|
-
uniqueItems: true,
|
|
356
|
-
maxItems: 200
|
|
357
|
-
} }
|
|
344
|
+
scoped: setEventType({
|
|
345
|
+
item: {
|
|
346
|
+
type: "string",
|
|
347
|
+
minLength: 1,
|
|
348
|
+
maxLength: 500
|
|
358
349
|
},
|
|
350
|
+
maxItems: 200,
|
|
359
351
|
allowedIn: [
|
|
360
352
|
"proposed",
|
|
361
353
|
"accepted",
|
|
362
354
|
"deprecated"
|
|
363
|
-
]
|
|
364
|
-
to: null
|
|
355
|
+
]
|
|
365
356
|
})
|
|
366
357
|
};
|
|
367
358
|
// src/kind.ts
|
|
@@ -421,4 +412,4 @@ const adrKind = defineKind({
|
|
|
421
412
|
});
|
|
422
413
|
export { parseDecisionNumber as a, formatDecisionNumber as i, DECISION_STATUSES as n, REF as r, adrKind as t };
|
|
423
414
|
|
|
424
|
-
//# sourceMappingURL=kind-
|
|
415
|
+
//# sourceMappingURL=kind-BcHjCHvi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kind-BcHjCHvi.js","names":[],"sources":["../src/kind/project.ts","../src/kind/reduce.ts","../src/kind/rules.ts","../src/kind/schemas.ts","../src/kind.ts"],"sourcesContent":["import type { FoldedSubject, ProjectContext } from \"@nikovirtala/ledger\";\nimport type { DecisionState } from \"./reduce.js\";\nimport type { DecisionEvents, DecisionStatus } from \"./schemas.js\";\n\n/** One decision as the CLI, the library and MCP show it (01:173–192, plus the added fields). */\nexport interface DecisionView {\n readonly id: string;\n readonly number: number | null;\n /** `ADR-0007`, or the id when unnumbered. */\n readonly display: string;\n readonly title: string;\n readonly status: DecisionStatus;\n readonly superseded_by: string | null;\n /** Ids whose applied `superseded.by` is this id, sorted. */\n readonly supersedes: readonly string[];\n /** The proposal's intent (01:164). */\n readonly declared_supersedes: readonly string[];\n /** Head of the `superseded_by` chain; `null` only on a cycle. */\n readonly effective: string | null;\n /** `[id, …, effective]`, following `superseded_by` forward. */\n readonly chain: readonly string[];\n readonly template: { readonly name: string; readonly version: number };\n readonly body_path: string | null;\n /** Recorded at acceptance. */\n readonly body_sha256: string | null;\n /** `null` until accepted; whether the current body hash equals the recorded one. */\n readonly body_intact: boolean | null;\n readonly links: readonly { readonly to: string; readonly rel: string }[];\n readonly applies_to: readonly string[];\n readonly notes: number;\n readonly proposed_at: string;\n readonly decided_at: string | null;\n readonly status_at: string;\n /** `proposed 2026-03-12`: state-changing events, in fold order. */\n readonly history: readonly string[];\n}\n\ntype Subject = FoldedSubject<DecisionStatus, DecisionState, DecisionEvents>;\ntype Context = ProjectContext<DecisionStatus, DecisionState, DecisionEvents>;\n\nconst NUMBER = /^(?:adr-?)?0*([1-9][0-9]{0,8})$/i;\n\n/** `ADR-0007`: at least 4 digits, growing past 9999. */\nexport function formatDecisionNumber(n: number): string {\n return `ADR-${String(n).padStart(4, \"0\")}`;\n}\n\n/** `7`, `0007`, `ADR-7`, `adr-0007` → 7; `null` for anything else. */\nexport function parseDecisionNumber(s: string): number | null {\n const m = NUMBER.exec(s.trim());\n return m === null ? null : Number(m[1]);\n}\n\n/**\n * Follows `superseded_by` from `id`. A visited set stops on a cycle (`effective: null`); a\n * reference to a subject that isn't folded ends the chain there.\n */\nfunction chainOf(id: string, ctx: Context): { chain: string[]; effective: string | null } {\n const chain = [id];\n let cur = id;\n for (;;) {\n const next = ctx.log.subjects.get(cur)?.state?.supersededBy ?? null;\n if (next === null) return { chain, effective: cur };\n if (chain.includes(next)) return { chain, effective: null };\n chain.push(next);\n cur = next;\n }\n}\n\n/** Pure: the view of one folded decision. */\nexport function project(subject: Subject, ctx: Context): DecisionView {\n const { id } = subject;\n const s = subject.state;\n if (s === null || subject.status === null) {\n throw new Error(`decision ${id} is not folded`);\n }\n const supersedes = [...ctx.log.subjects.values()]\n .filter((o) => o.id !== id && o.state?.supersededBy === id)\n .map((o) => o.id)\n .sort();\n const { chain, effective } = chainOf(id, ctx);\n const current = ctx.bodySha256(id);\n return {\n id,\n number: ctx.number(id),\n display: ctx.display(id),\n title: s.title,\n status: subject.status,\n superseded_by: s.supersededBy,\n supersedes,\n declared_supersedes: s.declaredSupersedes,\n effective,\n chain,\n template: s.template,\n body_path: subject.loaded.body?.path ?? subject.loaded.bodyPaths[0] ?? null,\n body_sha256: s.bodySha256,\n body_intact: s.bodySha256 === null ? null : current === s.bodySha256,\n links: s.links,\n applies_to: s.appliesTo,\n notes: s.notes,\n proposed_at: s.proposedAt,\n decided_at: s.decidedAt,\n status_at: s.statusAt,\n history: s.history.map((h) => `${h.type} ${h.at.slice(0, 10)}`),\n };\n}\n","import type { Actor, FoldEvent } from \"@nikovirtala/ledger\";\nimport type { DecisionEvents } from \"./schemas.js\";\n\n/** A decision's own state, maintained by `reduce` over its applied events. */\nexport interface DecisionState {\n readonly title: string;\n readonly template: { readonly name: string; readonly version: number };\n readonly declaredSupersedes: readonly string[];\n /** From the applied `accepted` event. */\n readonly bodySha256: string | null;\n readonly acceptedBy: Actor | null;\n readonly supersededBy: string | null;\n /** In fold order, duplicates kept once. */\n readonly links: readonly { readonly to: string; readonly rel: string }[];\n /** The latest `scoped` set (latest wins). */\n readonly appliesTo: readonly string[];\n readonly notes: number;\n /** State-changing events only, in fold order. */\n readonly history: readonly { readonly type: string; readonly at: string }[];\n readonly proposedAt: string;\n /** `at` of `accepted`, `rejected` or `withdrawn`. */\n readonly decidedAt: string | null;\n /** `at` of the latest state-changing event. */\n readonly statusAt: string;\n}\n\nconst EMPTY: DecisionState = {\n title: \"\",\n template: { name: \"\", version: 0 },\n declaredSupersedes: [],\n bodySha256: null,\n acceptedBy: null,\n supersededBy: null,\n links: [],\n appliesTo: [],\n notes: 0,\n history: [],\n proposedAt: \"\",\n decidedAt: null,\n statusAt: \"\",\n};\n\n/** Pure: the state after one applied event. The fold only passes events the machine allows. */\nexport function reduce(state: DecisionState | null, e: FoldEvent<DecisionEvents>): DecisionState {\n const s = state ?? EMPTY;\n const changed = (extra: Partial<DecisionState> = {}): DecisionState => ({\n ...s,\n ...extra,\n history: [...s.history, { type: e.type, at: e.at }],\n statusAt: e.at,\n });\n switch (e.type) {\n case \"proposed\":\n return changed({\n title: e.data.title,\n template: { name: e.data.template, version: e.data.template_version },\n declaredSupersedes: [...(e.data.supersedes ?? [])],\n proposedAt: e.at,\n });\n case \"accepted\":\n return changed({ bodySha256: e.data.body_sha256, acceptedBy: e.actor, decidedAt: e.at });\n case \"rejected\":\n case \"withdrawn\":\n return changed({ decidedAt: e.at });\n case \"deprecated\":\n return changed();\n case \"superseded\":\n return changed({ supersededBy: e.data.by });\n case \"noted\":\n return { ...s, notes: s.notes + 1 };\n case \"linked\": {\n const { to, rel } = e.data;\n const known = s.links.some((l) => l.to === to && l.rel === rel);\n return known ? s : { ...s, links: [...s.links, { to, rel }] };\n }\n case \"scoped\":\n return { ...s, appliesTo: [...e.data.set] };\n }\n}\n","import type { FoldedLog, FoldedSubject, KindFinding } from \"@nikovirtala/ledger\";\nimport type { DecisionState } from \"./reduce.js\";\nimport type { DecisionEvents, DecisionStatus } from \"./schemas.js\";\n\n/** Options of the decision kind's `invariants` and `relate`. */\nexport interface AdrOptions {\n /** Default `true`: an agent may propose, but only a human may accept (01:98). */\n readonly acceptRequiresHuman: boolean;\n}\n\ntype Subject = FoldedSubject<DecisionStatus, DecisionState, DecisionEvents>;\ntype Log = FoldedLog<DecisionStatus, DecisionState, DecisionEvents>;\n\n/** `decision/agent-accepted`: an applied `accepted` event written by an agent under the human policy. */\nexport function invariants(subject: Subject, options: AdrOptions): readonly KindFinding[] {\n if (!options.acceptRequiresHuman) return [];\n return subject.applied.flatMap(({ event }) =>\n event.type === \"accepted\" && event.actor.kind === \"agent\"\n ? [\n {\n severity: \"error\" as const,\n rule: \"decision/agent-accepted\",\n message: `accepted by agent ${event.actor.name}; accept_requires_human needs a human`,\n subject: subject.id,\n event: event.id,\n },\n ]\n : [],\n );\n}\n\n/**\n * Qualified ids (`<source>:<id>`) name decisions in other logs. Phase 1 checks local references\n * only and skips qualified ones, which only hand-written events can hold; CI checks them at the\n * pinned ref in phase 2 (design §E).\n */\nconst isQualified = (ref: string) => ref.includes(\":\");\n\n/**\n * Cross-subject rules: `decision/reference-missing` for a local `supersedes`, `superseded.by` or\n * `linked.to` naming no subject in the log; `decision/superseded-by-unaccepted` when the target of\n * an applied `superseded.by` has no applied `accepted` event in this tree; and\n * `decision/supersession-cycle`, once per cycle on its smallest id.\n */\nexport function relate(log: Log): readonly KindFinding[] {\n const out: KindFinding[] = [];\n const isAccepted = (id: string) =>\n log.subjects.get(id)?.applied.some((a) => a.event.type === \"accepted\") ?? false;\n const missing = (subject: string, event: string, ref: string, what: string) => {\n if (isQualified(ref) || log.subjects.has(ref)) return false;\n out.push({\n severity: \"error\",\n rule: \"decision/reference-missing\",\n message: `${what} ${ref}, which is not in the log`,\n subject,\n event,\n related: [ref],\n });\n return true;\n };\n\n for (const [id, s] of log.subjects) {\n for (const { event } of s.applied) {\n switch (event.type) {\n case \"proposed\":\n for (const ref of event.data.supersedes ?? []) missing(id, event.id, ref, \"supersedes\");\n break;\n case \"superseded\": {\n const by = event.data.by;\n if (missing(id, event.id, by, \"superseded by\") || isQualified(by)) break;\n if (!isAccepted(by)) {\n out.push({\n severity: \"error\",\n rule: \"decision/superseded-by-unaccepted\",\n message: `superseded by ${by}, which is not accepted`,\n subject: id,\n event: event.id,\n related: [by],\n });\n }\n break;\n }\n case \"linked\":\n missing(id, event.id, event.data.to, \"links to\");\n break;\n default:\n break;\n }\n }\n }\n\n const next = (id: string) => log.subjects.get(id)?.state?.supersededBy ?? null;\n const reported = new Set<string>();\n for (const start of log.subjects.keys()) {\n const path: string[] = [];\n let cur: string | null = start;\n while (cur !== null && !path.includes(cur)) {\n path.push(cur);\n cur = next(cur);\n }\n if (cur === null) continue;\n const cycle = path.slice(path.indexOf(cur));\n const smallest = [...cycle].sort()[0];\n if (smallest === undefined || reported.has(smallest)) continue;\n reported.add(smallest);\n const from = cycle.indexOf(smallest);\n const ordered = [...cycle.slice(from), ...cycle.slice(0, from), smallest];\n const event = log.subjects.get(smallest)?.applied.find((a) => a.event.type === \"superseded\")\n ?.event.id;\n out.push({\n severity: \"error\",\n rule: \"decision/supersession-cycle\",\n message: `supersession cycle: ${ordered.join(\" → \")}`,\n subject: smallest,\n ...(event === undefined ? {} : { event }),\n related: [...cycle].sort(),\n });\n }\n return out;\n}\n","import { eventType, setEventType } from \"@nikovirtala/ledger\";\n\n/** A decision's computed status. */\nexport type DecisionStatus =\n | \"proposed\"\n | \"accepted\"\n | \"rejected\"\n | \"withdrawn\"\n | \"deprecated\"\n | \"superseded\";\n\n/** Every status, in lifecycle order. */\nexport const DECISION_STATUSES: readonly DecisionStatus[] = Object.freeze([\n \"proposed\",\n \"accepted\",\n \"rejected\",\n \"withdrawn\",\n \"deprecated\",\n \"superseded\",\n]);\n\n/** A local subject id, or a qualified `<source>:<id>` one. */\nexport const REF = \"^(?:[a-z][a-z0-9-]*:)?[0-9a-hjkmnp-tv-z]{8}$\";\n\nconst ref = { type: \"string\", pattern: REF } as const;\nconst SINGLE_LINE = \"^[^\\\\r\\\\n]*$\";\n\n/** How a `linked` decision relates to its target. */\nexport type LinkRel = \"relates-to\" | \"refines\" | \"depends-on\";\n\n/** The decision kind's event types (01:128–136): data schemas, allowed states and targets. */\nexport const decisionEvents = {\n proposed: eventType<{\n title: string;\n template: string;\n template_version: number;\n supersedes?: string[];\n }>()({\n data: {\n type: \"object\",\n required: [\"title\", \"template\", \"template_version\"],\n properties: {\n title: { type: \"string\", minLength: 1, maxLength: 200, pattern: SINGLE_LINE },\n template: { type: \"string\", pattern: \"^[a-z][a-z0-9-]*$\" },\n template_version: { type: \"integer\", minimum: 1 },\n supersedes: { type: \"array\", items: ref, uniqueItems: true, maxItems: 20 },\n },\n },\n allowedIn: [],\n to: \"proposed\",\n }),\n accepted: eventType<{ body_sha256: string }>()({\n data: {\n type: \"object\",\n required: [\"body_sha256\"],\n properties: { body_sha256: { type: \"string\", pattern: \"^[0-9a-f]{64}$\" } },\n },\n allowedIn: [\"proposed\"],\n to: \"accepted\",\n }),\n rejected: eventType()({\n data: { type: \"object\" },\n allowedIn: [\"proposed\"],\n to: \"rejected\",\n reason: \"required\",\n }),\n withdrawn: eventType()({ data: { type: \"object\" }, allowedIn: [\"proposed\"], to: \"withdrawn\" }),\n deprecated: eventType()({\n data: { type: \"object\" },\n allowedIn: [\"accepted\"],\n to: \"deprecated\",\n reason: \"required\",\n }),\n superseded: eventType<{ by: string }>()({\n data: { type: \"object\", required: [\"by\"], properties: { by: ref } },\n allowedIn: [\"accepted\", \"deprecated\"],\n to: \"superseded\",\n }),\n noted: eventType<{ text: string }>()({\n data: {\n type: \"object\",\n required: [\"text\"],\n properties: { text: { type: \"string\", minLength: 1 } },\n },\n allowedIn: \"any\",\n to: null,\n }),\n linked: eventType<{ to: string; rel: LinkRel }>()({\n data: {\n type: \"object\",\n required: [\"to\", \"rel\"],\n properties: { to: ref, rel: { enum: [\"relates-to\", \"refines\", \"depends-on\"] } },\n },\n allowedIn: \"any\",\n to: null,\n }),\n // ledger's whole-set event (G11): the same schema as before, so decision/v1 is unchanged.\n scoped: setEventType({\n item: { type: \"string\", minLength: 1, maxLength: 500 },\n maxItems: 200,\n allowedIn: [\"proposed\", \"accepted\", \"deprecated\"],\n }),\n} as const;\n\nexport type DecisionEvents = typeof decisionEvents;\n","import { defineKind, type Kind } from \"@nikovirtala/ledger\";\nimport {\n type DecisionView,\n formatDecisionNumber,\n parseDecisionNumber,\n project,\n} from \"./kind/project.js\";\nimport { type DecisionState, reduce } from \"./kind/reduce.js\";\nimport { type AdrOptions, invariants, relate } from \"./kind/rules.js\";\nimport { type DecisionEvents, type DecisionStatus, decisionEvents } from \"./kind/schemas.js\";\n\nexport type { DecisionView } from \"./kind/project.js\";\nexport { formatDecisionNumber, parseDecisionNumber } from \"./kind/project.js\";\nexport type { DecisionState } from \"./kind/reduce.js\";\nexport type { AdrOptions } from \"./kind/rules.js\";\nexport {\n DECISION_STATUSES,\n type DecisionEvents,\n type DecisionStatus,\n type LinkRel,\n REF,\n} from \"./kind/schemas.js\";\n\n/**\n * The decision kind (01:128–194), as imported by other tools through `@nikovirtala/adr/kind`.\n *\n * Decisions are proposed, then accepted (which freezes the body and earns a number on main),\n * rejected or withdrawn; accepted ones can be deprecated or superseded. This module imports only\n * `@nikovirtala/ledger` and `./kind/*`, so importing the kind never loads CLI or MCP code.\n */\nexport const adrKind: Kind<\n DecisionStatus,\n DecisionEvents,\n DecisionState,\n DecisionView,\n AdrOptions\n> = defineKind<DecisionStatus, DecisionEvents, DecisionState, DecisionView, AdrOptions>({\n name: \"decision\",\n schema: \"decision/v1\",\n states: [\"proposed\", \"accepted\", \"rejected\", \"withdrawn\", \"deprecated\", \"superseded\"],\n events: decisionEvents,\n initial: \"proposed\",\n reduce,\n invariants,\n relate,\n project,\n body: { freezeOn: \"accepted\" },\n layout: { bodies: \"decisions\", events: \"events\" },\n defaultRoot: \"docs/adr\",\n sourceName: \"adr\",\n numbering: { on: \"accepted\", format: formatDecisionNumber, parse: parseDecisionNumber },\n templates: {\n dir: \"templates\",\n nameField: \"template\",\n versionField: \"template_version\",\n lintIn: [\"proposed\"],\n lintOn: \"accepted\",\n requireSections: [\"scope\"],\n },\n scope: { event: \"scoped\", activeIn: [\"proposed\", \"accepted\", \"deprecated\"] },\n options: Object.freeze({ acceptRequiresHuman: true }),\n});\n"],"mappings":";;AAwCA,MAAM,SAAS;;AAGf,SAAgB,qBAAqB,GAAmB;CACtD,OAAO,OAAO,OAAO,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG;AACzC;;AAGA,SAAgB,oBAAoB,GAA0B;CAC5D,MAAM,IAAI,OAAO,KAAK,EAAE,KAAK,CAAC;CAC9B,OAAO,MAAM,OAAO,OAAO,OAAO,EAAE,EAAE;AACxC;;;;;AAMA,SAAS,QAAQ,IAAY,KAA6D;CACxF,MAAM,QAAQ,CAAC,EAAE;CACjB,IAAI,MAAM;CACV,SAAS;EACP,MAAM,OAAO,IAAI,IAAI,SAAS,IAAI,GAAG,CAAC,EAAE,OAAO,gBAAgB;EAC/D,IAAI,SAAS,MAAM,OAAO;GAAE;GAAO,WAAW;EAAI;EAClD,IAAI,MAAM,SAAS,IAAI,GAAG,OAAO;GAAE;GAAO,WAAW;EAAK;EAC1D,MAAM,KAAK,IAAI;EACf,MAAM;CACR;AACF;;AAGA,SAAgB,QAAQ,SAAkB,KAA4B;CACpE,MAAM,EAAE,OAAO;CACf,MAAM,IAAI,QAAQ;CAClB,IAAI,MAAM,QAAQ,QAAQ,WAAW,MACnC,MAAM,I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,CAAC;CAED,QAAQ,aAAa;EACnB,MAAM;GAAE,MAAM;GAAU,WAAW;GAAG,WAAW;EAAI;EACrD,UAAU;EACV,WAAW;GAAC;GAAY;GAAY;EAAY;CAClD,CAAC;AACH;;;;;;;;;ACxEA,MAAa,UAMT,WAAoF;CACtF,MAAM;CACN,QAAQ;CACR,QAAQ;EAAC;EAAY;EAAY;EAAY;EAAa;EAAc;CAAY;CACpF,QAAQ;CACR,SAAS;CACT;CACA;CACA;CACA;CACA,MAAM,EAAE,UAAU,WAAW;CAC7B,QAAQ;EAAE,QAAQ;EAAa,QAAQ;CAAS;CAChD,aAAa;CACb,YAAY;CACZ,WAAW;EAAE,IAAI;EAAY,QAAQ;EAAsB,OAAO;CAAoB;CACtF,WAAW;EACT,KAAK;EACL,WAAW;EACX,cAAc;EACd,QAAQ,CAAC,UAAU;EACnB,QAAQ;EACR,iBAAiB,CAAC,OAAO;CAC3B;CACA,OAAO;EAAE,OAAO;EAAU,UAAU;GAAC;GAAY;GAAY;EAAY;CAAE;CAC3E,SAAS,OAAO,OAAO,EAAE,qBAAqB,KAAK,CAAC;AACtD,CAAC"}
|
package/dist/kind.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as DECISION_STATUSES, r as REF, t as adrKind, i as formatDecisionNumber, a as parseDecisionNumber } from "./kind-
|
|
1
|
+
export { n as DECISION_STATUSES, r as REF, t as adrKind, i as formatDecisionNumber, a as parseDecisionNumber } from "./kind-BcHjCHvi.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
/** `adr accept <decision> [--
|
|
1
|
+
import { type CommandSpec } from "@nikovirtala/ledger/cli";
|
|
2
|
+
/** `adr accept <decision> [--copy-scope | --no-copy-scope] …` (design §5.6, §6.10). */
|
|
3
3
|
export declare const acceptCommand: CommandSpec;
|
package/dist/types/cli/new.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CommandSpec } from "@nikovirtala/ledger/cli";
|
|
2
2
|
/**
|
|
3
3
|
* `adr new <title> …` (design §5.6). The editor runs with `--edit`, or without `--no-edit` when
|
|
4
4
|
* the terminal is interactive and an editor is set.
|
package/dist/types/cli/open.d.ts
CHANGED
|
@@ -15,5 +15,3 @@ export declare function openForCli(io: CliIO, flags: GlobalFlags, o?: {
|
|
|
15
15
|
export declare function displayAfterWrite(log: DecisionLog): Promise<{
|
|
16
16
|
readonly display: Display;
|
|
17
17
|
}>;
|
|
18
|
-
/** `--commit`/`--no-commit` when given, else `[policy] auto_commit`. */
|
|
19
|
-
export declare function commitRequested(log: DecisionLog, values: Readonly<Record<string, unknown>>): boolean;
|
|
@@ -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;
|
package/dist/types/cli/text.d.ts
CHANGED
|
@@ -1,16 +1,46 @@
|
|
|
1
|
+
import { type Actor } from "@nikovirtala/ledger";
|
|
2
|
+
import type { InitResultJson } from "../init.js";
|
|
3
|
+
import type { DecisionsForJson } from "../scope.js";
|
|
1
4
|
import type { DecisionListJson, DecisionShowJson } from "../views.js";
|
|
2
|
-
import type { WriteResultJson } from "../write.js";
|
|
5
|
+
import type { ScopeOffer, WriteResultJson } from "../write.js";
|
|
3
6
|
/** How a decision id is shown: its display (`ADR-0007`), or the id when it has no number. */
|
|
4
7
|
export type Display = (id: string) => string;
|
|
5
8
|
/** `adr list`: one row per decision, `→ <effective>` when it differs from the decision. */
|
|
6
9
|
export declare function listText(doc: DecisionListJson, display: Display): string;
|
|
7
10
|
/**
|
|
8
|
-
* The
|
|
9
|
-
*
|
|
11
|
+
* The stderr warning of `new` when the draft it wrote has unfilled sections (design §7.2), or
|
|
12
|
+
* `null` when there are none.
|
|
13
|
+
*/
|
|
14
|
+
export declare function unfilledWarning(doc: WriteResultJson): string | null;
|
|
15
|
+
export interface FollowRenamesBefore {
|
|
16
|
+
readonly before: ReadonlyMap<string, readonly string[]>;
|
|
17
|
+
readonly renamed: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The text of a write command (design §5.6, §6.1). `subject` names what a refused command was
|
|
21
|
+
* about; `number` is the decision's number in the write result, if it has one now; `reason` is
|
|
22
|
+
* the reason a lifecycle exit recorded.
|
|
10
23
|
*/
|
|
11
24
|
export declare function writeText(doc: WriteResultJson, display: Display, o: {
|
|
12
25
|
readonly subject: string;
|
|
13
26
|
readonly number: string | null;
|
|
27
|
+
readonly reason?: string | null;
|
|
28
|
+
/** The decision's globs before a `scope` write. */
|
|
29
|
+
readonly scopeBefore?: readonly string[];
|
|
30
|
+
/** For `scope --follow-renames`: every decision's globs before, and whether renames were staged. */
|
|
31
|
+
readonly followRenames?: FollowRenamesBefore;
|
|
32
|
+
/** The superseded scope an `accept` copied. */
|
|
33
|
+
readonly copied?: ScopeOffer | null;
|
|
34
|
+
/** Who proposed with `new`, and the log's `accept_requires_human`, for the next step. */
|
|
35
|
+
readonly actor?: Actor;
|
|
36
|
+
readonly acceptRequiresHuman?: boolean;
|
|
14
37
|
}): string;
|
|
15
38
|
/** `adr show`: the state header, the decision's fields and its body. */
|
|
16
39
|
export declare function showText(doc: DecisionShowJson, display: Display): string;
|
|
40
|
+
/**
|
|
41
|
+
* `adr for`: per path, one row per decision (named, status, title, how it matched), its warning
|
|
42
|
+
* below it when it isn't in force, then the anchors that name no decision of this log.
|
|
43
|
+
*/
|
|
44
|
+
export declare function forText(doc: DecisionsForJson, display: Display, keyword: string): string;
|
|
45
|
+
/** `adr init`: what was written and kept, then the next step; or that nothing was needed. */
|
|
46
|
+
export declare function initText(doc: InitResultJson): string;
|
package/dist/types/config.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
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`. */
|
|
@@ -15,6 +17,12 @@ export interface AdrConfig {
|
|
|
15
17
|
readonly mcpCanDecide: boolean;
|
|
16
18
|
/** `[verify] fail_on`. */
|
|
17
19
|
readonly failOn: Severity;
|
|
20
|
+
/** `[commit] subject`: the template of `--commit` subjects. */
|
|
21
|
+
readonly commitSubject: CommitTemplate;
|
|
22
|
+
/** `[scope] anchor_keyword`: the code-anchor keyword, `adr` in `// adr:<id>`. */
|
|
23
|
+
readonly anchorKeyword: string;
|
|
24
|
+
/** `[scope] anchor_exclude`: globs of files whose anchors are ignored (docs that show examples). */
|
|
25
|
+
readonly anchorExclude: readonly string[];
|
|
18
26
|
}
|
|
19
27
|
export declare const DEFAULT_ADR_CONFIG: AdrConfig;
|
|
20
28
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { type AdrConfig, DEFAULT_ADR_CONFIG, parseAdrConfig } from "./config.js";
|
|
2
|
+
export { type InitResultJson, initDecisionLog } from "./init.js";
|
|
2
3
|
export { type AdrOptions, adrKind, DECISION_STATUSES, type DecisionEvents, type DecisionState, type DecisionStatus, type DecisionView, formatDecisionNumber, type LinkRel, parseDecisionNumber, REF, } from "./kind.js";
|
|
3
4
|
export { type DecisionLog, type DecisionsRead, openDecisionLog, readDecisions, readDecisionsFrom, resolveDecision, } from "./log.js";
|
|
5
|
+
export { type DecisionForJson, type DecisionsForJson, decisionsFor, type UnresolvedAnchorJson, } from "./scope.js";
|
|
4
6
|
export { adrChecks, verifyDecisions } from "./verify.js";
|
|
5
7
|
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";
|
|
8
|
+
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,27 @@
|
|
|
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
|
+
* `adr init` (design §6.2): writes a config for the log, unless one is found, and each built-in
|
|
17
|
+
* template in `o.templates` (default `nygard`) to `<root>/templates/`, never overwriting a file.
|
|
18
|
+
* A `--root` other than `docs/adr` gets a repo-level `adr.toml` naming it, so later commands find
|
|
19
|
+
* the log without `--root`; when that file exists for another log, the config goes in the root.
|
|
20
|
+
* With `commit` (default `[policy] auto_commit`) the written files are committed on their own;
|
|
21
|
+
* nothing written means nothing committed. No events are written.
|
|
22
|
+
*/
|
|
23
|
+
export declare function initDecisionLog(log: DecisionLog, o?: {
|
|
24
|
+
readonly templates?: readonly string[];
|
|
25
|
+
readonly commit?: boolean;
|
|
26
|
+
readonly message?: string | null;
|
|
27
|
+
}): Promise<InitResultJson>;
|