@nikovirtala/adr 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +77 -13
  2. package/dist/cli.js +348 -46
  3. package/dist/cli.js.map +1 -1
  4. package/dist/index.js +5 -3
  5. package/dist/init-YgW7g9Fx.js +588 -0
  6. package/dist/init-YgW7g9Fx.js.map +1 -0
  7. package/dist/{kind-BcHjCHvi.js → kind-DjvA3dyA.js} +2 -6
  8. package/dist/{kind-BcHjCHvi.js.map → kind-DjvA3dyA.js.map} +1 -1
  9. package/dist/kind.js +1 -1
  10. package/dist/list-Dt4KGxvj.js +58 -0
  11. package/dist/list-Dt4KGxvj.js.map +1 -0
  12. package/dist/{write-9IaqHRrY.js → search-CwIPlNGd.js} +1339 -560
  13. package/dist/search-CwIPlNGd.js.map +1 -0
  14. package/dist/server-CXCO5zfp.js +938 -0
  15. package/dist/server-CXCO5zfp.js.map +1 -0
  16. package/dist/types/cli/hooks.d.ts +6 -0
  17. package/dist/types/cli/index-command.d.ts +3 -0
  18. package/dist/types/cli/init.d.ts +5 -2
  19. package/dist/types/cli/list.d.ts +1 -1
  20. package/dist/types/cli/mcp.d.ts +6 -0
  21. package/dist/types/cli/open.d.ts +2 -0
  22. package/dist/types/cli/search.d.ts +3 -0
  23. package/dist/types/cli/text.d.ts +12 -0
  24. package/dist/types/commit-actions.d.ts +74 -0
  25. package/dist/types/config.d.ts +7 -1
  26. package/dist/types/hooks.d.ts +59 -0
  27. package/dist/types/index.d.ts +7 -2
  28. package/dist/types/init.d.ts +23 -2
  29. package/dist/types/log-index.d.ts +117 -0
  30. package/dist/types/log.d.ts +44 -1
  31. package/dist/types/mcp/policy.d.ts +33 -0
  32. package/dist/types/mcp/prompt.d.ts +7 -0
  33. package/dist/types/mcp/resources.d.ts +16 -0
  34. package/dist/types/mcp/server.d.ts +16 -0
  35. package/dist/types/mcp/text.d.ts +42 -0
  36. package/dist/types/mcp/tools.d.ts +27 -0
  37. package/dist/types/scope.d.ts +3 -1
  38. package/dist/types/search.d.ts +61 -0
  39. package/dist/types/skill.d.ts +5 -0
  40. package/dist/types/templates/list.d.ts +31 -0
  41. package/dist/types/verify.d.ts +6 -4
  42. package/dist/types/views.d.ts +9 -3
  43. package/dist/types/write.d.ts +65 -9
  44. package/package.json +5 -2
  45. package/dist/write-9IaqHRrY.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-CXCO5zfp.js","names":[],"sources":["../src/mcp/policy.ts","../src/mcp/resources.ts","../src/mcp/text.ts","../src/mcp/tools.ts","../src/mcp/prompt.ts","../src/mcp/server.ts"],"sourcesContent":["import type { Actor, Finding } from \"@nikovirtala/ledger\";\nimport type { AdrConfig } from \"../config.js\";\nimport { adrKind, type DecisionView } from \"../kind.js\";\nimport type { DecisionsRead } from \"../log.js\";\n\n/** The tools that decide; listed only with `[policy] mcp_can_decide = true`. */\nexport const DECISION_TOOLS = [\n \"adr_accept\",\n \"adr_reject\",\n \"adr_deprecate\",\n \"adr_supersede\",\n] as const;\n\n/** Whether `adr mcp` offers the decision tools (design §7.5, Table A). */\nexport function decisionToolsAvailable(adr: AdrConfig): boolean {\n return adr.mcpCanDecide;\n}\n\n/**\n * Who a proposal is for (design D5): its `proposed` event's actor, `on_behalf_of` for an agent\n * and `email` for a human, lower-cased; `null` when the event or the address is missing.\n */\nexport function proposalOwner(read: DecisionsRead, id: string): string | null {\n const proposed = read.folded.subjects\n .get(id)\n ?.applied.find((a) => a.event.type === adrKind.machine.initial.type);\n const actor = proposed?.event.actor;\n if (actor === undefined) return null;\n const owner = actor.kind === \"agent\" ? actor.on_behalf_of : actor.email;\n return typeof owner === \"string\" && owner.trim() !== \"\" ? owner.trim().toLowerCase() : null;\n}\n\n/** The writes `mcpWriteRefusal` judges: the ones whose ownership matters. */\nexport type PolicyTool = \"adr_scope\" | \"adr_update_draft\" | \"adr_withdraw\";\n\n/**\n * The MCP policy (design §7.5, Table B): `null` when the write may go ahead, else the\n * `decision/mcp-cannot-decide` finding. Without `mcp_can_decide` an agent may scope, edit and\n * withdraw only the proposals made for the person it acts for, and rescope no accepted or\n * deprecated decision.\n * Writes the state machine forbids anyway get `null`, so the library refuses them with the real\n * reason.\n */\nexport function mcpWriteRefusal(o: {\n readonly tool: PolicyTool;\n readonly view: DecisionView;\n readonly owner: string | null;\n readonly actor: Actor;\n readonly mcpCanDecide: boolean;\n readonly display: (id: string) => string;\n /** The finding's file when the decision has no body: its events directory. */\n readonly eventsDir: string;\n}): Finding | null {\n const { view } = o;\n if (o.tool === \"adr_scope\" && !adrKind.machine.allowed(view.status, \"scoped\")) return null;\n if (o.tool === \"adr_update_draft\" && view.status !== \"proposed\") return null;\n if (o.tool === \"adr_withdraw\" && !adrKind.machine.allowed(view.status, \"withdrawn\")) return null;\n if (o.mcpCanDecide) return null;\n const me = o.actor.on_behalf_of?.trim().toLowerCase() ?? null;\n if (view.status === \"proposed\" && o.owner !== null && o.owner === me) return null;\n const shown = o.display(view.id);\n const named = shown === view.id ? view.id : `${shown} (${view.id})`;\n const verb = o.tool === \"adr_withdraw\" ? \"withdrawing\" : \"changing\";\n const message =\n view.status === \"proposed\"\n ? `${named} was proposed for ${o.owner ?? \"someone else\"}, and you act for ${o.actor.on_behalf_of ?? \"nobody\"}; ${verb} another person's proposal needs [policy] mcp_can_decide = true. Add a note with adr_note instead.`\n : `${named} is ${view.status}; rescoping it needs [policy] mcp_can_decide = true, because narrowing a scope can switch a decision off. Ask a human to run adr scope ${shown} …, or propose a superseding decision.`;\n return {\n severity: \"error\",\n rule: \"decision/mcp-cannot-decide\",\n message,\n file: view.body_path ?? o.eventsDir,\n line: null,\n subject: view.id,\n kind: adrKind.name,\n };\n}\n","import { renderIndex, resolveSubjectInput, UsageError } from \"@nikovirtala/ledger\";\nimport type { McpResource, McpResourceTemplate } from \"@nikovirtala/ledger/mcp\";\nimport { adrKind } from \"../kind.js\";\nimport { type DecisionsRead, readDecisions, resolveDecision } from \"../log.js\";\nimport { DECISION_INDEX } from \"../log-index.js\";\nimport { showDecision } from \"../views.js\";\nimport { mcpHeader } from \"./text.js\";\nimport { type AdrMcpEnv, openLog } from \"./tools.js\";\n\nconst MAX_ID = 64;\n\n/**\n * Where an MCP client reads a decision: `adr://decision/ADR-0012` when numbered, else\n * `adr://decision/<id>`. The `refer` of every header the MCP texts show.\n */\nexport function decisionUri(read: DecisionsRead): (id: string) => string {\n return (id) => `adr://decision/${read.projection.views.get(id)?.display ?? id}`;\n}\n\n/** `adr://index`: the index table, numbered like every other read (design §7.7). */\nexport function indexResource(e: AdrMcpEnv): McpResource {\n return {\n uri: \"adr://index\",\n name: \"index\",\n title: \"Decision index\",\n description: \"All decisions, grouped by status, with numbers and dates\",\n mimeType: \"text/markdown\",\n async read() {\n const read = await readDecisions(await openLog(e));\n const views = read.projection.views;\n return {\n header: null,\n text: renderIndex(DECISION_INDEX(read.root, views), [...views.values()], read.numbering),\n };\n },\n };\n}\n\n/**\n * `adr://decision/{id}`: the decision's state header, then its body. `{id}` is the id, the number\n * (`12`, `0012`) or `ADR-0012`; an unknown one is not found, a malformed or qualified one is the\n * caller's error.\n */\nexport function decisionResource(e: AdrMcpEnv): McpResourceTemplate {\n return {\n uriTemplate: \"adr://decision/{id}\",\n name: \"decision\",\n title: \"Decision\",\n description:\n \"One decision: its state header, then its body. {id} is the id (k3f9q8a1), the number (12) or ADR-0012\",\n mimeType: \"text/markdown\",\n async read({ id = \"\" }) {\n if (id.length > MAX_ID) {\n throw new UsageError(\n `invalid decision ${JSON.stringify(`${id.slice(0, MAX_ID)}…`)}: an id or number is at most ${MAX_ID} characters`,\n );\n }\n const read = await readDecisions(await openLog(e));\n const r = resolveSubjectInput(id, {\n subjects: new Set(read.folded.subjects.keys()),\n kind: adrKind,\n numbering: read.numbering,\n });\n if (!r.ok && r.reason === \"not-found\") return null;\n const doc = await showDecision(read, resolveDecision(read, id));\n return {\n header: mcpHeader(doc.decision, read),\n text: doc.body === null ? \"(no body file)\\n\" : doc.body,\n };\n },\n };\n}\n","/**\n * The readable text of each MCP tool result (design §7.4, last column). The documents are the\n * CLI's; these texts are MCP's own, and their state headers point at `adr://decision/…`.\n */\nimport {\n type EventEnvelope,\n type Finding,\n renderStateHeader,\n type StateHeader,\n} from \"@nikovirtala/ledger\";\nimport type { McpToolResult } from \"@nikovirtala/ledger/mcp\";\nimport type { DecisionView } from \"../kind.js\";\nimport type { DecisionsRead } from \"../log.js\";\nimport type { DecisionsForJson } from \"../scope.js\";\nimport type { DecisionSearchJson } from \"../search.js\";\nimport type { TemplatesJson } from \"../templates/list.js\";\nimport { type DecisionListJson, type DecisionShowJson, stateHeader } from \"../views.js\";\nimport type { WriteResultJson } from \"../write.js\";\nimport { decisionUri } from \"./resources.js\";\n\ntype Text = Omit<McpToolResult, \"document\">;\n\nconst display = (read: DecisionsRead) => (id: string) =>\n read.projection.views.get(id)?.display ?? id;\n\nfunction named(read: DecisionsRead, id: string): string {\n const shown = display(read)(id);\n return shown === id ? id : `${shown} (${id})`;\n}\n\n/** The decision's state header with MCP's `adr://` references. */\nexport function mcpHeader(view: DecisionView, read: DecisionsRead): StateHeader {\n return stateHeader(view, read, { refer: decisionUri(read) });\n}\n\n/** `adr_search`: each result's header, title and excerpt, then the counts. */\nexport function searchText(doc: DecisionSearchJson, read: DecisionsRead): Text {\n if (doc.results.length === 0) {\n const more =\n doc.inactive_omitted > 0\n ? [`${inactiveLine(doc.inactive_omitted)}; pass include_inactive`]\n : [];\n return { headers: [], text: [\"No decisions match.\", ...more].join(\"\\n\") };\n }\n const lines: string[] = [];\n for (const r of doc.results) {\n lines.push(renderStateHeader(mcpHeader(r.decision, read)).trimEnd());\n lines.push(` ${r.decision.title}`);\n const where = r.matched.filter((f) => f === \"id\" || f === \"title\").join(\" and \");\n lines.push(r.excerpt === null ? ` (${where} match)` : ` ${r.excerpt}`);\n }\n lines.push(`${doc.results.length} of ${doc.total} shown`);\n if (doc.inactive_omitted > 0) {\n lines.push(`${inactiveLine(doc.inactive_omitted)}; pass include_inactive`);\n }\n return { headers: [], text: lines.join(\"\\n\") };\n}\n\nconst inactiveLine = (k: number) =>\n k === 1 ? \"1 inactive decision also matches\" : `${k} inactive decisions also match`;\n\nfunction listOf(read: DecisionsRead, ids: readonly string[]): string {\n return ids.length === 0 ? \"none\" : ids.map((id) => named(read, id)).join(\", \");\n}\n\nfunction historyLines(events: readonly EventEnvelope[]): string[] {\n return events.map((e) => {\n const a = e.actor;\n const who = a.kind === \"agent\" ? `${a.name} (agent for ${a.on_behalf_of})` : a.name;\n const why = typeof e.reason === \"string\" ? ` — ${e.reason}` : \"\";\n return ` ${e.at} ${e.type} ${who}${why}`;\n });\n}\n\n/** `adr_get`: the header, the decision's fields as `adr show` lists them, then the body. */\nexport function getText(doc: DecisionShowJson, read: DecisionsRead): Text {\n const v = doc.decision;\n const lines = [\n `Title: ${v.title}`,\n `Status: ${v.status} (${v.status_at.slice(0, 10)})`,\n `Effective: ${v.effective === null ? \"none (supersession cycle)\" : named(read, v.effective)}`,\n `Chain: ${v.chain.map(display(read)).join(\" → \")}`,\n `Supersedes: ${listOf(read, v.supersedes)}`,\n `Applies to: ${v.applies_to.length === 0 ? \"no globs recorded\" : v.applies_to.join(\", \")}`,\n ];\n if (doc.events !== null) lines.push(\"History:\", ...historyLines(doc.events));\n lines.push(\"\", doc.body === null ? \"(no body file)\" : doc.body.trimEnd());\n return { headers: [mcpHeader(v, read)], text: lines.join(\"\\n\") };\n}\n\n/** `adr_list`: one line per decision. */\nexport function listText(doc: DecisionListJson, read: DecisionsRead): Text {\n if (doc.decisions.length === 0) return { headers: [], text: \"No decisions.\" };\n const lines = doc.decisions.map((v) => {\n const head = v.number === null ? v.id : `${v.display} (${v.id})`;\n const to =\n v.effective !== null && v.effective !== v.id ? ` → ${display(read)(v.effective)}` : \"\";\n return `${head} · ${v.status} · ${v.title}${to}`;\n });\n return { headers: [], text: lines.join(\"\\n\") };\n}\n\n/** `adr_templates`: each template, then its sections. */\nexport function templatesText(doc: TemplatesJson): Text {\n const lines = doc.templates.flatMap((t) => [\n `${t.name} v${t.version} (${t.source})${t.name === doc.default ? \" default\" : \"\"}`,\n ...t.sections.map(\n (s) =>\n ` ${s.id}: ${s.heading} (${s.required ? \"required\" : \"optional\"})${s.guidance === null ? \"\" : ` — ${s.guidance}`}`,\n ),\n ]);\n return { headers: [], text: lines.length === 0 ? \"No templates.\" : lines.join(\"\\n\") };\n}\n\n/** `adr_for_path`: per path, each decision's header and how it matched. */\nexport function forText(doc: DecisionsForJson, read: DecisionsRead): Text {\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 for (const d of p.decisions) {\n const view = read.projection.views.get(d.id);\n const h =\n view === undefined\n ? { line: `${named(read, d.id)} · ${d.status}`, warning: d.warning }\n : mcpHeader(view, read);\n lines.push(` ${h.line}`);\n if (h.warning !== null) lines.push(` ${h.warning}`);\n for (const via of d.via) {\n lines.push(\n via.type === \"glob\" ? ` via glob ${via.glob}` : ` via anchor line ${via.line}`,\n );\n }\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: ${u.ref} (line ${u.line}, ${why})`);\n }\n }\n return { headers: [], text: lines.join(\"\\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\",\n};\n\n/** Lint findings as `Fill in: <heading> (<reason>)`, others as `Draft: <message> [<rule>]`. */\nfunction lintLines(findings: readonly Finding[]): string[] {\n return findings.map((f) => {\n const m = SECTION_FINDING.exec(f.message);\n if (m === null) return `Draft: ${f.message} [${f.rule}]`;\n const [, heading = \"\", what = \"\"] = m;\n return `Fill in: ${heading} (${REASONS[what] ?? what})`;\n });\n}\n\nconst noteLines = (doc: WriteResultJson) => doc.notes.map((n) => `Note: ${n}`);\n\n/** What a write's text needs besides the document. */\nexport interface WriteTextOptions {\n /** The log read after the write, for the headers and how decisions display. */\n readonly read: DecisionsRead;\n /** For `adr_propose`: whether a human must accept. */\n readonly acceptRequiresHuman?: boolean;\n /** For `adr_scope`: the globs before the write. */\n readonly scopeBefore?: readonly string[];\n /** For `adr_update_draft`: the section ids sent. */\n readonly sections?: readonly string[];\n /** The tool, for the refusal's last line. */\n readonly tool: string;\n}\n\n/** A write's text: `Refused:` and the findings, or what was written; then the notes. */\nexport function writeText(doc: WriteResultJson, o: WriteTextOptions): Text {\n const { read } = o;\n const view =\n doc.decision === null ? null : (read.projection.views.get(doc.decision.id) ?? doc.decision);\n const headers = view === null ? [] : [mcpHeader(view, read), ...affectedHeaders(doc, read)];\n if (!doc.ok) {\n const lint =\n doc.findings.length > 0 && doc.findings.every((f) => f.rule.startsWith(\"template/\"));\n const again =\n lint && (o.tool === \"adr_propose\" || o.tool === \"adr_update_draft\")\n ? [`Fill in every required section and call ${o.tool} again.`]\n : [];\n const lines = [\n \"Refused:\",\n ...doc.findings.map(\n (f) => ` ${f.file === null ? \"\" : `${f.file}: `}${f.message} [${f.rule}]`,\n ),\n ...again,\n ...noteLines(doc),\n ];\n return { headers, text: lines.join(\"\\n\") };\n }\n if (view === null) return { headers, text: noteLines(doc).join(\"\\n\") };\n const lines = bodyLines(doc, view, o);\n return { headers, text: [...lines, ...noteLines(doc)].join(\"\\n\") };\n}\n\nfunction bodyLines(doc: WriteResultJson, v: DecisionView, o: WriteTextOptions): string[] {\n const { read } = o;\n const who = named(read, v.id);\n const recorded = doc.commit === null ? [] : [`Committed ${doc.commit.slice(0, 7)}.`];\n switch (doc.command) {\n case \"new\":\n return [\n `Proposed ${v.id}: ${v.title}`,\n ...(v.body_path === null ? [] : [` ${v.body_path}`]),\n ...lintLines(doc.findings),\n ...recorded,\n o.acceptRequiresHuman === true\n ? `Next: ask a human to review and accept it (adr accept ${v.id})`\n : `Next: adr_accept or adr accept ${v.id}`,\n ];\n case \"update\":\n return doc.written.length === 0\n ? [\"Unchanged\"]\n : [\n `Updated the draft of ${who}: ${(o.sections ?? []).join(\", \")}`,\n ...lintLines(doc.findings),\n ...recorded,\n ];\n case \"note\":\n return [`Noted on ${who}`, ...recorded];\n case \"link\": {\n const link = doc.written.length === 0 ? undefined : v.links.at(-1);\n if (link === undefined) return [`Links of ${who} unchanged`];\n return [`Linked ${who} ${link.rel} ${named(read, link.to)}`, ...recorded];\n }\n case \"scope\": {\n const before = new Set(o.scopeBefore ?? []);\n const after = new Set(v.applies_to);\n if (doc.written.length === 0) return [\"unchanged\"];\n return [\n ...v.applies_to.filter((g) => !before.has(g)).map((g) => `+ ${g}`),\n ...[...before].filter((g) => !after.has(g)).map((g) => `- ${g}`),\n `= ${v.applies_to.length === 0 ? \"no globs\" : v.applies_to.join(\", \")}`,\n ...recorded,\n ];\n }\n case \"accept\":\n return [\n `Accepted ${who}: ${v.title}`,\n ...doc.affected.map((a) => `Superseded ${named(read, a.id)}: ${a.title}`),\n ...recorded,\n ];\n case \"reject\":\n return [`Rejected ${who}`, ...recorded];\n case \"withdraw\":\n return [`Withdrawn ${who}`, ...recorded];\n case \"deprecate\":\n return [`Deprecated ${who}`, ...recorded];\n case \"supersede\":\n return [`Superseded ${who} by ${named(read, v.superseded_by ?? \"\")}`, ...recorded];\n default:\n return [`${doc.command} ${who}`, ...recorded];\n }\n}\n\n/** The headers of the decisions a write affected (superseded), other than its own. */\nfunction affectedHeaders(doc: WriteResultJson, read: DecisionsRead): StateHeader[] {\n return doc.affected\n .filter((a) => a.id !== doc.decision?.id)\n .map((a) => mcpHeader(read.projection.views.get(a.id) ?? a, read));\n}\n","import {\n type Attribution,\n eventDir,\n type JsonValue,\n MAX_GLOB_LENGTH,\n UsageError,\n} from \"@nikovirtala/ledger\";\nimport { type McpTool, type McpToolResult, mcpAttribution } from \"@nikovirtala/ledger/mcp\";\nimport { DECISION_STATUSES, type DecisionStatus } from \"../kind.js\";\nimport {\n type DecisionLog,\n type DecisionsRead,\n openDecisionLog,\n readDecisions,\n resolveDecision,\n} from \"../log.js\";\nimport { decisionsFor } from \"../scope.js\";\nimport { searchDecisions } from \"../search.js\";\nimport { listTemplates } from \"../templates/list.js\";\nimport { listDecisions, showDecision } from \"../views.js\";\nimport {\n acceptDecision,\n deprecateDecision,\n linkDecision,\n noteDecision,\n proposeDecision,\n rejectDecision,\n scopeDecision,\n supersedeDecision,\n updateDraft,\n type WriteResultJson,\n withdrawDecision,\n} from \"../write.js\";\nimport { mcpWriteRefusal, type PolicyTool, proposalOwner } from \"./policy.js\";\nimport {\n forText,\n getText,\n listText,\n searchText,\n templatesText,\n type WriteTextOptions,\n writeText,\n} from \"./text.js\";\n\n/** Where `adr mcp` runs: every call opens the log afresh from here (design D2). */\nexport interface AdrMcpEnv {\n readonly cwd: string;\n readonly root: string | null;\n readonly env: NodeJS.ProcessEnv;\n}\n\ntype Schema = Readonly<Record<string, JsonValue>>;\n\nexport const ID: Schema = { type: \"string\", minLength: 1, maxLength: 64 };\nconst TEXT: Schema = { type: \"string\", minLength: 1, maxLength: 65_536 };\nconst SECTIONS: Schema = {\n type: \"object\",\n propertyNames: { type: \"string\", pattern: \"^[a-z][a-z0-9-]*$\", maxLength: 64 },\n additionalProperties: { type: \"string\", maxLength: 65_536 },\n maxProperties: 50,\n};\nconst GLOBS: Schema = {\n type: \"array\",\n items: { type: \"string\", minLength: 1, maxLength: MAX_GLOB_LENGTH },\n maxItems: 200,\n};\n\nconst object = (properties: Record<string, Schema>, required: string[] = []): Schema => ({\n type: \"object\",\n properties,\n ...(required.length === 0 ? {} : { required }),\n additionalProperties: false,\n});\n\nexport const READ = { readOnlyHint: true, openWorldHint: false } as const;\nexport const WRITE = { readOnlyHint: false, destructiveHint: false, openWorldHint: false } as const;\n\n/** The log for one call, opened again so outside edits and `[policy]` changes are seen. */\nexport const openLog = (e: AdrMcpEnv, ref: string | null = null): Promise<DecisionLog> =>\n openDecisionLog({ cwd: e.cwd, root: e.root, ref, gitOptions: { env: e.env } });\n\nconst str = (v: JsonValue | undefined): string | undefined =>\n typeof v === \"string\" ? v : undefined;\nconst strings = (v: JsonValue | undefined): string[] | undefined =>\n Array.isArray(v) ? v.filter((x): x is string => typeof x === \"string\") : undefined;\nconst sectionsOf = (v: JsonValue | undefined): Record<string, string> =>\n typeof v === \"object\" && v !== null && !Array.isArray(v)\n ? Object.fromEntries(\n Object.entries(v).flatMap(([k, x]) => (typeof x === \"string\" ? [[k, x]] : [])),\n )\n : {};\n\nconst doc = (d: unknown): JsonValue => d as JsonValue;\n\n/**\n * A write tool's result: the library's document, and its text rendered from a read of the log\n * after the write.\n */\nasync function writeResult(\n log: DecisionLog,\n d: WriteResultJson,\n o: Omit<WriteTextOptions, \"read\">,\n): Promise<McpToolResult> {\n const read = await readDecisions(log);\n return { document: doc(d), ...writeText(d, { ...o, read }) };\n}\n\n/** The `adr-write/v1` command of each policy tool, as the CLI names it. */\nconst COMMAND: Record<PolicyTool, WriteResultJson[\"command\"]> = {\n adr_scope: \"scope\",\n adr_update_draft: \"update\",\n adr_withdraw: \"withdraw\",\n};\n\n/**\n * The MCP policy step of `adr_scope`, `adr_update_draft` and `adr_withdraw` (design §7.5): the refusal document\n * when the agent may not make this write, else `null`.\n */\nfunction policyRefusal(\n log: DecisionLog,\n read: DecisionsRead,\n tool: PolicyTool,\n id: string,\n attribution: Attribution,\n): WriteResultJson | null {\n const view = read.projection.views.get(id);\n if (view === undefined) return null;\n const finding = mcpWriteRefusal({\n tool,\n view,\n owner: proposalOwner(read, id),\n actor: attribution.actor,\n mcpCanDecide: log.adr.mcpCanDecide,\n display: (x) => read.projection.views.get(x)?.display ?? x,\n eventsDir: eventDir(read.layout, id),\n });\n if (finding === null) return null;\n return {\n format: \"adr-write/v1\",\n command: COMMAND[tool],\n ok: false,\n decision: view,\n affected: [],\n written: [],\n commit: null,\n findings: [finding],\n notes: [...log.notes, ...attribution.notes],\n };\n}\n\n/** The eleven tools `adr mcp` always lists (design §7.4). */\nexport function alwaysOnTools(e: AdrMcpEnv): McpTool[] {\n return [\n {\n name: \"adr_search\",\n title: \"Search decisions\",\n description:\n \"Full-text search of the decision log: every word must appear in a decision's id, title, body or notes. Returns active (proposed or accepted) decisions unless include_inactive is true, each with its state header and an excerpt.\",\n inputSchema: object(\n {\n query: { type: \"string\", minLength: 1, maxLength: 200 },\n include_inactive: { type: \"boolean\" },\n limit: { type: \"integer\", minimum: 1, maximum: 100 },\n },\n [\"query\"],\n ),\n annotations: READ,\n async run(input) {\n const read = await readDecisions(await openLog(e));\n const d = searchDecisions(read, {\n query: str(input.query) ?? \"\",\n includeInactive: input.include_inactive === true,\n limit: typeof input.limit === \"number\" ? input.limit : 10,\n });\n return { document: doc(d), ...searchText(d, read) };\n },\n },\n {\n name: \"adr_get\",\n title: \"Get a decision\",\n description:\n \"One decision with its state header, computed status, supersession chain, effective decision and body. Use this or adr://decision/{id} instead of reading files under docs/adr. A SUPERSEDED or DEPRECATED header means: don't apply it, follow the warning.\",\n inputSchema: object(\n {\n id: ID,\n include_history: { type: \"boolean\" },\n ref: { type: \"string\", minLength: 1, maxLength: 256 },\n },\n [\"id\"],\n ),\n annotations: READ,\n async run(input) {\n const read = await readDecisions(await openLog(e, str(input.ref) ?? null));\n const id = resolveDecision(read, str(input.id) ?? \"\");\n const d = await showDecision(read, id, { history: input.include_history === true });\n return { document: doc(d), ...getText(d, read) };\n },\n },\n {\n name: \"adr_list\",\n title: \"List decisions\",\n description:\n \"All decisions with their computed status, for orientation. Filter by status; limit truncates.\",\n inputSchema: object({\n status: {\n type: \"array\",\n items: { type: \"string\", enum: [...DECISION_STATUSES] },\n uniqueItems: true,\n minItems: 1,\n maxItems: DECISION_STATUSES.length,\n },\n limit: { type: \"integer\", minimum: 1, maximum: 1000 },\n }),\n annotations: READ,\n async run(input) {\n const read = await readDecisions(await openLog(e));\n const status = strings(input.status) as DecisionStatus[] | undefined;\n const d = listDecisions(read, {\n ...(status === undefined ? {} : { status }),\n ...(typeof input.limit === \"number\" ? { limit: input.limit } : {}),\n });\n return { document: doc(d), ...listText(d, read) };\n },\n },\n {\n name: \"adr_templates\",\n title: \"List templates\",\n description:\n \"The templates adr_propose can use, with each section's id, heading, whether it is required, and guidance for filling it in.\",\n inputSchema: object({}),\n annotations: READ,\n async run() {\n const d = await listTemplates(await readDecisions(await openLog(e)));\n return { document: doc(d), ...templatesText(d) };\n },\n },\n {\n name: \"adr_propose\",\n title: \"Propose a decision\",\n description:\n \"Propose a decision: give the title and a sections map (section id → markdown) for the template; the tool renders and stages the draft. Lint findings come back in findings: fix them with adr_update_draft. With auto_commit on, an incomplete draft is refused; send every required section. You can't accept your own proposal; tell the user its id.\",\n inputSchema: object(\n {\n title: { type: \"string\", minLength: 1, maxLength: 200 },\n template: { type: \"string\", pattern: \"^[a-z][a-z0-9-]*$\", maxLength: 64 },\n sections: SECTIONS,\n supersedes: { type: \"array\", items: ID, maxItems: 20 },\n },\n [\"title\"],\n ),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await openLog(e);\n const { actor, notes } = await mcpAttribution(log.git, ctx);\n const template = str(input.template);\n const supersedes = strings(input.supersedes);\n const d = await proposeDecision(\n log,\n {\n title: str(input.title) ?? \"\",\n sections: sectionsOf(input.sections),\n actor,\n ...(template === undefined ? {} : { template }),\n ...(supersedes === undefined ? {} : { supersedes }),\n },\n { notes },\n );\n return writeResult(log, d, {\n tool: \"adr_propose\",\n acceptRequiresHuman: log.adr.acceptRequiresHuman,\n });\n },\n },\n {\n name: \"adr_update_draft\",\n title: \"Update a draft\",\n description:\n \"Replace sections of a proposed decision's draft (section id → markdown). Only your own proposals unless mcp_can_decide is on. Returns the lint result. With auto_commit on, an incomplete draft is refused; send every required section.\",\n inputSchema: object({ id: ID, sections: { ...SECTIONS, minProperties: 1 } }, [\n \"id\",\n \"sections\",\n ]),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await openLog(e);\n const read = await readDecisions(log);\n const id = resolveDecision(read, str(input.id) ?? \"\");\n const attribution = await mcpAttribution(log.git, ctx);\n const sections = sectionsOf(input.sections);\n const o = { tool: \"adr_update_draft\", sections: Object.keys(sections) };\n const refused = policyRefusal(log, read, \"adr_update_draft\", id, attribution);\n if (refused !== null) return writeResult(log, refused, o);\n const d = await updateDraft(log, { id, sections }, { notes: attribution.notes });\n return writeResult(log, d, o);\n },\n },\n {\n name: \"adr_note\",\n title: \"Note on a decision\",\n description:\n \"Add a note to a decision in any state. Notes clarify; a changed decision needs a superseding proposal.\",\n inputSchema: object({ id: ID, text: TEXT }, [\"id\", \"text\"]),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await openLog(e);\n const { actor, notes } = await mcpAttribution(log.git, ctx);\n const d = await noteDecision(\n log,\n { id: str(input.id) ?? \"\", text: str(input.text) ?? \"\", actor },\n { notes },\n );\n return writeResult(log, d, { tool: \"adr_note\" });\n },\n },\n {\n name: \"adr_link\",\n title: \"Link decisions\",\n description:\n \"Record a relation (relates-to, refines, depends-on) from one decision to another.\",\n inputSchema: object(\n {\n id: ID,\n to: { type: \"string\", minLength: 1, maxLength: 100 },\n rel: { type: \"string\", enum: [\"relates-to\", \"refines\", \"depends-on\"] },\n },\n [\"id\", \"to\"],\n ),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await openLog(e);\n const { actor, notes } = await mcpAttribution(log.git, ctx);\n const rel = str(input.rel);\n const d = await linkDecision(\n log,\n {\n id: str(input.id) ?? \"\",\n to: str(input.to) ?? \"\",\n actor,\n ...(rel === undefined ? {} : { rel }),\n },\n { notes },\n );\n return writeResult(log, d, { tool: \"adr_link\" });\n },\n },\n {\n name: \"adr_for_path\",\n title: \"Decisions for paths\",\n description:\n \"The decisions that govern each file, from scope globs and code anchors. Inactive ones carry a warning.\",\n inputSchema: object(\n {\n paths: {\n type: \"array\",\n items: { type: \"string\", minLength: 1, maxLength: 4096 },\n minItems: 1,\n maxItems: 100,\n },\n },\n [\"paths\"],\n ),\n annotations: READ,\n async run(input) {\n const log = await openLog(e);\n const read = await readDecisions(log);\n const d = await decisionsFor(read, log, { paths: strings(input.paths) ?? [] });\n return { document: doc(d), ...forText(d, read) };\n },\n },\n {\n name: \"adr_scope\",\n title: \"Scope a decision\",\n description:\n \"Set, add or remove the globs that map a decision to code. Allowed on your own proposals; rescoping someone else's proposal or an accepted or deprecated decision needs mcp_can_decide. If the decision's Scope section would no longer read true, propose a superseding decision instead.\",\n inputSchema: {\n ...object({ id: ID, set: GLOBS, add: GLOBS, remove: GLOBS }, [\"id\"]),\n minProperties: 2,\n },\n inputHint: \"adr_scope needs id and at least one of set, add or remove\",\n annotations: WRITE,\n async run(input, ctx) {\n const log = await openLog(e);\n const read = await readDecisions(log);\n const id = resolveDecision(read, str(input.id) ?? \"\");\n const attribution = await mcpAttribution(log.git, ctx);\n const scopeBefore = read.projection.views.get(id)?.applies_to ?? [];\n const o = { tool: \"adr_scope\", scopeBefore };\n const refused = policyRefusal(log, read, \"adr_scope\", id, attribution);\n if (refused !== null) return writeResult(log, refused, o);\n const set = strings(input.set);\n const op = {\n ...(set === undefined ? {} : { set }),\n add: strings(input.add) ?? [],\n remove: strings(input.remove) ?? [],\n };\n const d = await scopeDecision(\n log,\n { id, op, actor: attribution.actor },\n { notes: attribution.notes },\n );\n return writeResult(log, d, o);\n },\n },\n {\n name: \"adr_withdraw\",\n title: \"Withdraw a proposal\",\n description:\n \"Withdraw a proposed decision, with an optional reason, for example your own proposal when the user decides against it. Withdrawing someone else's proposal needs mcp_can_decide. Only proposals can be withdrawn; an accepted decision needs a superseding proposal.\",\n inputSchema: object({ id: ID, reason: TEXT }, [\"id\"]),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await openLog(e);\n const read = await readDecisions(log);\n const id = resolveDecision(read, str(input.id) ?? \"\");\n const attribution = await mcpAttribution(log.git, ctx);\n const o = { tool: \"adr_withdraw\" };\n const refused = policyRefusal(log, read, \"adr_withdraw\", id, attribution);\n if (refused !== null) return writeResult(log, refused, o);\n const d = await withdrawDecision(\n log,\n { id, reason: str(input.reason) ?? null, actor: attribution.actor },\n { notes: attribution.notes },\n );\n return writeResult(log, d, o);\n },\n },\n ];\n}\n\n/**\n * The log for a decision tool's call. The tool list was fixed at startup, so a call after\n * `mcp_can_decide` was turned off is a usage error telling the user to restart (design §7.3).\n */\nasync function decidingLog(e: AdrMcpEnv): Promise<DecisionLog> {\n const log = await openLog(e);\n if (!log.adr.mcpCanDecide) {\n throw new UsageError(\n `[policy] mcp_can_decide is now false in ${log.configPath ?? \"adr.toml (not present)\"}; restart adr mcp to update its tool list`,\n );\n }\n return log;\n}\n\n/** The four tools `adr mcp` lists only with `[policy] mcp_can_decide = true` (design §7.4). */\nexport function decisionTools(e: AdrMcpEnv): McpTool[] {\n return [\n {\n name: \"adr_accept\",\n title: \"Accept a decision\",\n description:\n \"Accept a proposed decision (lints it, freezes the body, supersedes what it declares). Refused for agents while accept_requires_human is on.\",\n inputSchema: object({ id: ID, copy_scope: { type: \"boolean\" } }, [\"id\"]),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await decidingLog(e);\n const { actor, notes } = await mcpAttribution(log.git, ctx);\n const copyScope =\n input.copy_scope === true ? \"copy\" : input.copy_scope === false ? \"skip\" : \"suggest\";\n const d = await acceptDecision(\n log,\n { id: str(input.id) ?? \"\", actor },\n { notes, copyScope },\n );\n return writeResult(log, d, { tool: \"adr_accept\" });\n },\n },\n {\n name: \"adr_reject\",\n title: \"Reject a decision\",\n description: \"Reject a proposed decision, with a reason.\",\n inputSchema: object({ id: ID, reason: TEXT }, [\"id\", \"reason\"]),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await decidingLog(e);\n const { actor, notes } = await mcpAttribution(log.git, ctx);\n const d = await rejectDecision(\n log,\n { id: str(input.id) ?? \"\", reason: str(input.reason) ?? \"\", actor },\n { notes },\n );\n return writeResult(log, d, { tool: \"adr_reject\" });\n },\n },\n {\n name: \"adr_deprecate\",\n title: \"Deprecate a decision\",\n description: \"Deprecate an accepted decision that nothing replaces, with a reason.\",\n inputSchema: object({ id: ID, reason: TEXT }, [\"id\", \"reason\"]),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await decidingLog(e);\n const { actor, notes } = await mcpAttribution(log.git, ctx);\n const d = await deprecateDecision(\n log,\n { id: str(input.id) ?? \"\", reason: str(input.reason) ?? \"\", actor },\n { notes },\n );\n return writeResult(log, d, { tool: \"adr_deprecate\" });\n },\n },\n {\n name: \"adr_supersede\",\n title: \"Supersede a decision\",\n description: \"Mark an accepted or deprecated decision superseded by an accepted one.\",\n inputSchema: object({ id: ID, by: ID, reason: TEXT }, [\"id\", \"by\"]),\n annotations: WRITE,\n async run(input, ctx) {\n const log = await decidingLog(e);\n const { actor, notes } = await mcpAttribution(log.git, ctx);\n const reason = str(input.reason);\n const d = await supersedeDecision(\n log,\n {\n id: str(input.id) ?? \"\",\n by: str(input.by) ?? \"\",\n actor,\n ...(reason === undefined ? {} : { reason }),\n },\n { notes },\n );\n return writeResult(log, d, { tool: \"adr_supersede\" });\n },\n },\n ];\n}\n","import { UsageError } from \"@nikovirtala/ledger\";\nimport type { McpPrompt } from \"@nikovirtala/ledger/mcp\";\nimport { readDecisions, resolveDecision } from \"../log.js\";\nimport { listTemplates } from \"../templates/list.js\";\nimport { type AdrMcpEnv, openLog } from \"./tools.js\";\n\n/**\n * `adr_draft_from_discussion` (design §7.8): the steps from a discussion to a proposal, with the\n * template's sections spelled out, ending with a human's `adr accept`.\n */\nexport function draftPrompt(e: AdrMcpEnv): McpPrompt {\n return {\n name: \"adr_draft_from_discussion\",\n title: \"Draft a decision from the discussion\",\n description:\n \"Turn the current discussion into a proposed architecture decision, checking the existing ones first.\",\n arguments: [\n { name: \"title\", description: \"Working title of the decision\", required: false },\n {\n name: \"template\",\n description: \"Template name; default [log] default_template\",\n required: false,\n },\n {\n name: \"supersedes\",\n description: \"A decision this proposal replaces: id or number\",\n required: false,\n },\n ],\n async get(args) {\n const read = await readDecisions(await openLog(e));\n const templates = await listTemplates(read);\n const name = args.template ?? templates.default;\n const t = templates.templates.find((x) => x.name === name);\n if (t === undefined)\n throw new UsageError(`unknown template ${name}; adr_templates lists them`);\n const replaced =\n args.supersedes === undefined ? null : resolveDecision(read, args.supersedes);\n const shown = (id: string) => {\n const display = read.projection.views.get(id)?.display ?? id;\n return display === id ? id : `${display} (${id})`;\n };\n const title =\n args.title === undefined\n ? 'a short title that states the decision, such as \"Use PostgreSQL for orders\"'\n : JSON.stringify(args.title);\n return [\n \"Turn the current discussion into an architecture decision proposal with adr.\",\n \"\",\n \"1. Call adr_search with the main subject of the discussion, and adr_for_path for the files it concerns. If an accepted decision already covers this, tell the user which one, and ask whether the proposal should supersede it.\",\n ...(replaced === null\n ? []\n : [\n `1a. The user named ${shown(replaced)} as the decision this replaces; read it with adr_get first.`,\n ]),\n `2. Use the template ${t.name} (version ${t.version}). Its sections:`,\n ...t.sections.map(\n (s) =>\n ` - ${s.id}: ${s.heading}, ${s.required ? \"required\" : \"optional\"}.${s.guidance === null ? \"\" : ` ${s.guidance}`}`,\n ),\n \"3. Fill every required section with facts from the discussion and the code only. Where something wasn't settled, write it as an open question in that section instead of inventing an answer. If the template has an options section, list at least two options with their trade-offs, including those the discussion rejected.\",\n `4. Call adr_propose with the title ${title}, template \"${t.name}\", the sections map${replaced === null ? \"\" : `, and supersedes [\"${replaced}\"]`}.`,\n \"5. If the result has ok: true with findings, fix those sections with adr_update_draft and the new decision's id. If it was refused (ok: false), fill in every section the findings name and call adr_propose again.\",\n \"6. Don't accept the proposal. Tell the user its id, and that they can review it and run: adr accept <id>\",\n ].join(\"\\n\");\n },\n };\n}\n","import { parseOnBehalfOf } from \"@nikovirtala/ledger\";\nimport { type McpServeOptions, serveMcp } from \"@nikovirtala/ledger/mcp\";\nimport { openDecisionLog } from \"../log.js\";\nimport { DECISION_TOOLS, decisionToolsAvailable } from \"./policy.js\";\nimport { draftPrompt } from \"./prompt.js\";\nimport { decisionResource, indexResource } from \"./resources.js\";\nimport { type AdrMcpEnv, alwaysOnTools, decisionTools } from \"./tools.js\";\n\nexport const INSTRUCTIONS =\n \"Architecture decisions in this repository are managed by adr. Decision files don't show their status: read decisions with adr_get or adr://decision/{id}, check adr_for_path and adr_search before changing architecture, and propose changes with adr_propose; a human accepts them.\";\n\n/**\n * `adr mcp` (design §7.2): checks `ARK_ON_BEHALF_OF` and opens the log first, so a bad\n * environment exits 2 before serving, then serves adr's tools over stdio until the client goes.\n */\nexport async function serveAdrMcp(o: {\n readonly cwd: string;\n readonly root: string | null;\n readonly env: NodeJS.ProcessEnv;\n readonly version: string;\n readonly stderr: { write(s: string): void };\n readonly transport?: McpServeOptions[\"transport\"];\n}): Promise<void> {\n parseOnBehalfOf(o.env.ARK_ON_BEHALF_OF);\n const log = await openDecisionLog({ cwd: o.cwd, root: o.root, gitOptions: { env: o.env } });\n const e: AdrMcpEnv = { cwd: o.cwd, root: o.root, env: o.env };\n const decide = decisionToolsAvailable(log.adr);\n const tools = [...alwaysOnTools(e), ...(decide ? decisionTools(e) : [])];\n const unavailable: Record<string, string> = {};\n if (decide && log.adr.acceptRequiresHuman) {\n o.stderr.write(\n \"adr: warning: adr_accept refuses agents while [policy] accept_requires_human is true\\n\",\n );\n }\n if (!decide) {\n const where = log.configPath ?? \"adr.toml (not present)\";\n for (const name of DECISION_TOOLS) {\n unavailable[name] =\n `[policy] mcp_can_decide is false in ${where}; a human decides with the adr CLI, or set it to true and restart adr mcp`;\n }\n }\n await serveMcp(\n {\n name: \"adr\",\n version: o.version,\n instructions: INSTRUCTIONS,\n tools,\n unavailable,\n resources: [indexResource(e)],\n resourceTemplates: [decisionResource(e)],\n prompts: [draftPrompt(e)],\n },\n {\n env: o.env,\n stderr: o.stderr,\n ...(o.transport === undefined ? {} : { transport: o.transport }),\n },\n );\n}\n"],"mappings":";;;;;;;AAMA,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;AACF;;AA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CAAsC,MAAM,cAAc,EAAE,KAAK,qBAAqB,aAAa,OAAO,KAAK,sBAAsB,SAAS,IAAI;IAClJ;IACA;GACF,CAAC,CAAC,KAAK,IAAI;EACb;CACF;AACF;;AC3DA,MAAa,eACX;;;;;AAMF,eAAsB,YAAY,GAOhB;CAChB,gBAAgB,EAAE,IAAI,gBAAgB;CACtC,MAAM,MAAM,MAAM,gBAAgB;EAAE,KAAK,EAAE;EAAK,MAAM,EAAE;EAAM,YAAY,EAAE,KAAK,EAAE,IAAI;CAAE,CAAC;CAC1F,MAAM,IAAe;EAAE,KAAK,EAAE;EAAK,MAAM,EAAE;EAAM,KAAK,EAAE;CAAI;CAC5D,MAAM,SAAS,uBAAuB,IAAI,GAAG;CAC7C,MAAM,QAAQ,CAAC,GAAG,cAAc,CAAC,GAAG,GAAI,SAAS,cAAc,CAAC,IAAI,CAAC,CAAE;CACvE,MAAM,cAAsC,CAAC;CAC7C,IAAI,UAAU,IAAI,IAAI,qBACpB,EAAE,OAAO,MACP,wFACF;CAEF,IAAI,CAAC,QAAQ;EACX,MAAM,QAAQ,IAAI,cAAc;EAChC,KAAK,MAAM,QAAQ,gBACjB,YAAY,QACV,uCAAuC,MAAM;CAEnD;CACA,MAAM,SACJ;EACE,MAAM;EACN,SAAS,EAAE;EACX,cAAc;EACd;EACA;EACA,WAAW,CAAC,cAAc,CAAC,CAAC;EAC5B,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;EACvC,SAAS,CAAC,YAAY,CAAC,CAAC;CAC1B,GACA;EACE,KAAK,EAAE;EACP,QAAQ,EAAE;EACV,GAAI,EAAE,cAAc,KAAA,IAAY,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU;CAChE,CACF;AACF"}
@@ -0,0 +1,6 @@
1
+ import type { CommandSpec } from "@nikovirtala/ledger/cli";
2
+ /**
3
+ * `adr hooks install | uninstall | print --manager … | run pre-commit | trailers <message-file>`
4
+ * (design 2b D4, D8, §4.3): adr's git hooks through ledger's shims, shared with other ark tools.
5
+ */
6
+ export declare const hooksCommand: CommandSpec;
@@ -0,0 +1,3 @@
1
+ import { type CommandSpec } from "@nikovirtala/ledger/cli";
2
+ /** `adr index [--check] [--commit | --no-commit] [-m <message>]` (design 2b §4.5). */
3
+ export declare const indexCommand: CommandSpec;
@@ -1,3 +1,6 @@
1
1
  import { type CommandSpec } from "@nikovirtala/ledger/cli";
2
- /** `adr init [--template <name>]… [--commit | --no-commit] [-m <message>]` (design §6.2). */
3
- export declare const initCommand: CommandSpec;
2
+ /**
3
+ * `adr init [--template <name>]… [--skill [--skill-dir <path>]] [--commit | --no-commit]
4
+ * [-m <message>]` (design §6.2, phase 3 §9).
5
+ */
6
+ export declare function initCommand(version: string): CommandSpec;
@@ -1,3 +1,3 @@
1
1
  import type { CommandSpec } from "@nikovirtala/ledger/cli";
2
- /** `adr list [--status <status>]…` (design §5.6). */
2
+ /** `adr list [--status <status>]… [--since <rev>]` (design §5.6, 2b D7). */
3
3
  export declare const listCommand: CommandSpec;
@@ -0,0 +1,6 @@
1
+ import type { CommandSpec } from "@nikovirtala/ledger/cli";
2
+ /**
3
+ * `adr mcp` (design §7.1): the MCP server over stdio. Loaded with a dynamic import, so no other
4
+ * command loads the MCP SDK.
5
+ */
6
+ export declare function mcpCommand(version: string): CommandSpec;
@@ -15,3 +15,5 @@ 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
+ /** `notes` with `note` appended when there is one. */
19
+ export declare const notesWith: (notes: readonly string[], note: string | null) => readonly string[];
@@ -0,0 +1,3 @@
1
+ import type { CommandSpec } from "@nikovirtala/ledger/cli";
2
+ /** `adr search <query>… [--all]` (design §8.2): words are joined, and every one must match. */
3
+ export declare const searchCommand: CommandSpec;
@@ -1,12 +1,19 @@
1
1
  import { type Actor } from "@nikovirtala/ledger";
2
2
  import type { InitResultJson } from "../init.js";
3
+ import type { ChangedSince } from "../log.js";
3
4
  import type { DecisionsForJson } from "../scope.js";
5
+ import type { DecisionSearchJson } from "../search.js";
4
6
  import type { DecisionListJson, DecisionShowJson } from "../views.js";
5
7
  import type { ScopeOffer, WriteResultJson } from "../write.js";
6
8
  /** How a decision id is shown: its display (`ADR-0007`), or the id when it has no number. */
7
9
  export type Display = (id: string) => string;
8
10
  /** `adr list`: one row per decision, `→ <effective>` when it differs from the decision. */
9
11
  export declare function listText(doc: DecisionListJson, display: Display): string;
12
+ /**
13
+ * `adr list --since <rev>` (design 2b D7): a heading, then each row followed by the event types
14
+ * added since `rev`; nothing at all when no decision changed, so the post-merge hook stays quiet.
15
+ */
16
+ export declare function sinceText(doc: DecisionListJson, since: ChangedSince, display: Display): string;
10
17
  /**
11
18
  * The stderr warning of `new` when the draft it wrote has unfilled sections (design §7.2), or
12
19
  * `null` when there are none.
@@ -42,5 +49,10 @@ export declare function showText(doc: DecisionShowJson, display: Display): strin
42
49
  * below it when it isn't in force, then the anchors that name no decision of this log.
43
50
  */
44
51
  export declare function forText(doc: DecisionsForJson, display: Display, keyword: string): string;
52
+ /**
53
+ * `adr search`: one padded row per result with its excerpt (or which field matched) under it, and
54
+ * an inactive result's warning; then the count.
55
+ */
56
+ export declare function searchText(doc: DecisionSearchJson): string;
45
57
  /** `adr init`: what was written and kept, then the next step; or that nothing was needed. */
46
58
  export declare function initText(doc: InitResultJson): string;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * `{action}` of a commit that writes one event of each type (design §4.3), and what the title slot
3
+ * names: the decision's title for the events that change whether it is decided, else its display.
4
+ */
5
+ export declare const ACTIONS: {
6
+ readonly proposed: {
7
+ readonly action: "propose to";
8
+ readonly names: "title";
9
+ };
10
+ readonly accepted: {
11
+ readonly action: "decide to";
12
+ readonly names: "title";
13
+ };
14
+ readonly rejected: {
15
+ readonly action: "decide not to";
16
+ readonly names: "title";
17
+ };
18
+ readonly withdrawn: {
19
+ readonly action: "withdraw the proposal to";
20
+ readonly names: "title";
21
+ };
22
+ readonly deprecated: {
23
+ readonly action: "deprecate";
24
+ readonly names: "display";
25
+ };
26
+ readonly superseded: {
27
+ readonly action: "supersede";
28
+ readonly names: "display";
29
+ };
30
+ readonly noted: {
31
+ readonly action: "add a note to";
32
+ readonly names: "display";
33
+ };
34
+ readonly linked: {
35
+ readonly action: "link";
36
+ readonly names: "display";
37
+ };
38
+ readonly scoped: {
39
+ readonly action: "set the scope of";
40
+ readonly names: "display";
41
+ };
42
+ };
43
+ /** `{action}` of `adr index --commit`, whose title slot holds `the decision index`. */
44
+ export declare const INDEX_ACTION = "regenerate";
45
+ /** What `adr index --commit`'s title slot holds. */
46
+ export declare const INDEX_TITLE = "the decision index";
47
+ /** `{action}` of a draft update (`adr_update_draft`), whose title slot holds the display. */
48
+ export declare const DRAFT_ACTION = "update the draft of";
49
+ /** The longest `{action}`, which `[commit] subject` must leave room for. */
50
+ export declare const LONGEST_ACTION: number;
51
+ /** The longest display: `ADR-` and up to 9 digits (`formatDecisionNumber`, kind/project.ts). */
52
+ export declare const DISPLAY_LENGTH = 13;
53
+ /** What a link's title slot names after the display when the target is in another log. */
54
+ export declare const CROSS_LOG_LINK = "to a decision in another log";
55
+ /** adr's commit-subject placeholders, each with its longest value (design §4.2). */
56
+ export declare const COMMIT_VARS: Readonly<{
57
+ action: number;
58
+ id: 8;
59
+ display: 13;
60
+ command: 9;
61
+ }>;
62
+ /**
63
+ * The names the title placeholder holds instead of a title, which are never shortened, each with
64
+ * its action: supersede's `<display> with <display>` and a link's `<display> to <display>` or
65
+ * `<display> to a decision in another log` (`planLink` in write.ts), and `adr index`'s
66
+ * `the decision index`. The shorter names (a display, at most 13 characters) always fit in the
67
+ * room a title gets.
68
+ */
69
+ export declare const COMMIT_NAMES: readonly {
70
+ length: number;
71
+ vars: {
72
+ action: number;
73
+ };
74
+ }[];
@@ -7,7 +7,7 @@ export interface AdrConfig {
7
7
  readonly defaultTemplate: string;
8
8
  /** `[log] main_branch`: the ref numbers come from; `null` resolves it automatically. */
9
9
  readonly mainBranch: string | null;
10
- /** `[log] index`: validated now, used in phase 2. */
10
+ /** `[log] index`: `committed` keeps a generated `<root>/index.md` fresh and verified. */
11
11
  readonly index: "committed" | "none";
12
12
  /** `[policy] accept_requires_human`. */
13
13
  readonly acceptRequiresHuman: boolean;
@@ -17,6 +17,12 @@ export interface AdrConfig {
17
17
  readonly mcpCanDecide: boolean;
18
18
  /** `[verify] fail_on`. */
19
19
  readonly failOn: Severity;
20
+ /** `[verify] governed_by_inactive`: the severity of `decision/governed-by-inactive`. */
21
+ readonly governedByInactive: Severity;
22
+ /** `[hooks] scope_follow_renames`: what the pre-commit hook does with renames of covered files. */
23
+ readonly scopeFollowRenames: "stage" | "warn" | "off";
24
+ /** `[hooks] index`: whether the pre-commit hook only checks `index.md` or regenerates it. */
25
+ readonly hookIndex: "check" | "stage";
20
26
  /** `[commit] subject`: the template of `--commit` subjects. */
21
27
  readonly commitSubject: CommitTemplate;
22
28
  /** `[scope] anchor_keyword`: the code-anchor keyword, `adr` in `// adr:<id>`. */
@@ -0,0 +1,59 @@
1
+ import { type Finding, type HookManager, type HookName, type Severity } from "@nikovirtala/ledger";
2
+ import type { DecisionLog } from "./log.js";
3
+ /** `adr hooks … --json` (design 2b §4.3); `hooks run` prints `ledger-findings/v1` instead. */
4
+ export interface HooksResultJson {
5
+ readonly format: "adr-hooks/v1";
6
+ readonly action: "install" | "uninstall" | "print" | "trailers";
7
+ /** Repo-relative shim paths written or removed. */
8
+ readonly written: readonly string[];
9
+ readonly unchanged: readonly string[];
10
+ readonly registrations: readonly {
11
+ readonly hook: HookName;
12
+ readonly argv: readonly string[];
13
+ }[];
14
+ /** `print` only. */
15
+ readonly snippet: string | null;
16
+ /** `trailers` only: the trailers added, in order. */
17
+ readonly trailers: readonly (readonly [string, string])[];
18
+ }
19
+ /**
20
+ * adr's command per hook (design 2b D4), after `adr`. `--root <root>` comes first only when the
21
+ * root can't be found without it: no `<repo>/adr.toml` names it and it isn't `docs/adr`. So the
22
+ * hooks see the same config as a plain `adr` run, and never print the root-override note.
23
+ */
24
+ export declare function decisionHookCommands(log: DecisionLog): Partial<Record<HookName, readonly string[]>>;
25
+ /**
26
+ * Registers adr's four commands in ledger's shims, one per hook and shared with other ark tools
27
+ * (design 2b D4). With `core.hooksPath` set or a foreign hook file present, it writes the rest and
28
+ * then throws `HookConflictError` (exit 2), naming each conflict and the `print` command.
29
+ */
30
+ export declare function installDecisionHooks(log: DecisionLog): Promise<HooksResultJson>;
31
+ /** Removes adr from every shim; a shim left with no tool is deleted. */
32
+ export declare function uninstallDecisionHooks(log: DecisionLog): Promise<HooksResultJson>;
33
+ /** The config to paste into a hook manager instead of installing shims. */
34
+ export declare function printDecisionHooks(log: DecisionLog, manager: HookManager): HooksResultJson;
35
+ /**
36
+ * The `commit-msg` step (P1 §7.1): appends one `ADR`/`ADR-Event` pair per staged added event file
37
+ * of the log, by path, keeping repeats (`ifExists: "add"`). It does nothing for a message that
38
+ * already has an `ADR-Event:` trailer (an `adr … --commit` message), or during a merge, whose
39
+ * events came with their own commits' trailers. Throws `UsageError` when the file is missing.
40
+ */
41
+ export declare function addHookTrailers(log: DecisionLog, messageFile: string): Promise<HooksResultJson>;
42
+ /**
43
+ * `adr hooks run pre-commit` (design 2b D8): rename following, then the index, then `verify
44
+ * --staged`, stopping at the first step that fails. `worktree` must be opened with the work-tree
45
+ * reader, because rename following writes through `write()`; `index` with the index reader, for
46
+ * the config as staged, the index render and verify. Only the index step stages `index.md`, and
47
+ * only with `[hooks] index = "stage"`; rename following passes `index: "skip"`. Neither stages
48
+ * into a temporary index (`stagingSafe`). A step that can't run throws (exit 2).
49
+ */
50
+ export declare function runPreCommitHook(o: {
51
+ readonly worktree: DecisionLog;
52
+ readonly index: DecisionLog;
53
+ readonly env: NodeJS.ProcessEnv;
54
+ }): Promise<{
55
+ readonly exit: 0 | 1;
56
+ readonly findings: readonly Finding[];
57
+ readonly notes: readonly string[];
58
+ readonly failOn: Severity;
59
+ }>;
@@ -1,8 +1,13 @@
1
1
  export { type AdrConfig, DEFAULT_ADR_CONFIG, parseAdrConfig } from "./config.js";
2
+ export { addHookTrailers, decisionHookCommands, type HooksResultJson, installDecisionHooks, printDecisionHooks, runPreCommitHook, uninstallDecisionHooks, } from "./hooks.js";
2
3
  export { type InitResultJson, initDecisionLog } from "./init.js";
3
4
  export { type AdrOptions, adrKind, DECISION_STATUSES, type DecisionEvents, type DecisionState, type DecisionStatus, type DecisionView, formatDecisionNumber, type LinkRel, parseDecisionNumber, REF, } from "./kind.js";
4
- export { type DecisionLog, type DecisionsRead, openDecisionLog, readDecisions, readDecisionsFrom, resolveDecision, } from "./log.js";
5
+ export { type ChangedSince, changedSince, type DecisionLog, type DecisionsRead, openDecisionLog, readDecisions, readDecisionsFrom, resolveDecision, sourcesNote, } from "./log.js";
6
+ export { type IndexResultJson, indexDecisionLog, renderDecisionIndex } from "./log-index.js";
5
7
  export { type DecisionForJson, type DecisionsForJson, decisionsFor, type UnresolvedAnchorJson, } from "./scope.js";
8
+ export { type DecisionSearchJson, type DecisionSearchResultJson, searchDecisions, } from "./search.js";
9
+ export { SKILL_MD } from "./skill.js";
10
+ export { listTemplates, type TemplatesJson } from "./templates/list.js";
6
11
  export { adrChecks, verifyDecisions } from "./verify.js";
7
12
  export { type DecisionListJson, type DecisionShowJson, listDecisions, type NumberingJson, showDecision, stateHeader, } from "./views.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";
13
+ export { acceptDecision, type CopyScope, deprecateDecision, followScopeRenames, type LinkInput, linkDecision, noteDecision, type ProposeInput, proposeDecision, type ReasonInput, rejectDecision, type ScopeInput, type ScopeOffer, scopeDecision, scopeToCopy, supersedeDecision, type UpdateDraftInput, updateDraft, type WriteOptions, type WriteResultJson, withdrawDecision, } from "./write.js";
@@ -9,19 +9,40 @@ export interface InitResultJson {
9
9
  readonly written: readonly string[];
10
10
  /** Files that were already there and were left as they are. */
11
11
  readonly kept: readonly string[];
12
+ /** With `--skill`, the SKILL.md path (written or kept); else `null`. */
13
+ readonly skill: string | null;
12
14
  readonly commit: string | null;
13
15
  readonly notes: readonly string[];
14
16
  }
17
+ /**
18
+ * What the recovery hint says about rerunning `adr init` after `git commit` failed (design 2b D5):
19
+ * init keeps existing files, so it would commit nothing.
20
+ */
21
+ export declare const INIT_RERUN = "Running adr init again won't commit them: the files exist now, so it keeps them and commits nothing.";
22
+ /** The line `adr init --skill` adds to AGENTS.md for tools that don't load skills. */
23
+ export declare const agentsPointer: (skill: string) => string;
15
24
  /**
16
25
  * `adr init` (design §6.2): writes a config for the log, unless one is found, and each built-in
17
26
  * template in `o.templates` (default `nygard`) to `<root>/templates/`, never overwriting a file.
18
27
  * A `--root` other than `docs/adr` gets a repo-level `adr.toml` naming it, so later commands find
19
28
  * 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.
29
+ * With `[log] index = "committed"` it also writes `<root>/index.md` unless one exists. With
30
+ * `commit` (default `[policy] auto_commit`) the written files are committed on their own;
31
+ * nothing written means nothing committed. No events are written. With `o.skill` it also writes
32
+ * the agent skill, unless a SKILL.md is there, and adds the pointer line to `AGENTS.md`, unless a
33
+ * line already names the skill; an AGENTS.md with unstaged changes or not tracked is refused
34
+ * with a commit and left unstaged without one.
22
35
  */
23
36
  export declare function initDecisionLog(log: DecisionLog, o?: {
24
37
  readonly templates?: readonly string[];
25
38
  readonly commit?: boolean;
26
39
  readonly message?: string | null;
40
+ /**
41
+ * Also write `<dir>/SKILL.md` (`dir` repo-relative, `""` for the root) and the AGENTS.md
42
+ * pointer (design §9); `version` is adr's, for the note on a SKILL.md that differs.
43
+ */
44
+ readonly skill?: {
45
+ readonly dir: string;
46
+ readonly version: string;
47
+ };
27
48
  }): Promise<InitResultJson>;
@@ -0,0 +1,117 @@
1
+ import { type Check, type Finding, type Git, type IndexSpec, type LogLayout, type TreeReader } from "@nikovirtala/ledger";
2
+ import type { AdrConfig } from "./config.js";
3
+ import { type DecisionView } from "./kind.js";
4
+ import { type DecisionLog } from "./log.js";
5
+ import type { WriteOptions } from "./write.js";
6
+ /** `adr index --json` (design 2b §4.5). */
7
+ export interface IndexResultJson {
8
+ readonly format: "adr-index/v1";
9
+ /** The index file, repo-relative: `<root>/index.md`. */
10
+ readonly path: string;
11
+ readonly check: boolean;
12
+ /**
13
+ * `--check`: no finding. Otherwise: the copies the command compares (the work tree and the
14
+ * index, or HEAD's when committing) already held the render.
15
+ */
16
+ readonly fresh: boolean;
17
+ /** Repo-relative paths this command wrote. */
18
+ readonly written: readonly string[];
19
+ readonly commit: string | null;
20
+ /** `--check`'s findings; `[]` otherwise. */
21
+ readonly findings: readonly Finding[];
22
+ readonly notes: readonly string[];
23
+ }
24
+ /**
25
+ * What the recovery hint says about rerunning `adr index --commit` after `git commit` failed
26
+ * (design 2b D5). It names the file, not the path, which the hint lists above it.
27
+ */
28
+ export declare const INDEX_RERUN = "You can also run adr index --commit again once git accepts the commit; it commits index.md while it differs from HEAD's.";
29
+ /**
30
+ * The step before the manual commit when a write's second index render failed after staging
31
+ * (design 2b §4.5 step 4).
32
+ */
33
+ export declare const INDEX_BEFORE: (root: string) => string;
34
+ /**
35
+ * The step after the manual commit when the commit carried the index: the commit's render leaves
36
+ * out other decisions' uncommitted entries (design 2b D5, §4.5 step 5).
37
+ */
38
+ export declare const INDEX_AFTER: (root: string) => string;
39
+ /** The repo-relative path of a log's generated index. */
40
+ export declare const indexPath: (layout: LogLayout) => string;
41
+ /**
42
+ * adr's index spec (01:209: active decisions first), built per render so that a superseded
43
+ * decision's status can name its successor's display from `views`.
44
+ */
45
+ export declare const DECISION_INDEX: (root: string, views: ReadonlyMap<string, DecisionView>) => IndexSpec<DecisionView>;
46
+ /**
47
+ * The index `tree` must hold: its decisions, numbered as they will be once the commit holding
48
+ * `tree` (which builds on `history`: HEAD, a commit, or null on an unborn HEAD) is on main
49
+ * (design 2b D2), with `[log] main_branch`'s numbers first. A tree that isn't a commit's (the work
50
+ * tree, the index) also merges `MERGE_HEAD` while a merge is in progress. In a shallow clone the
51
+ * numbers continue from those `history`'s index recorded; `null` when there are none, so the
52
+ * numbers can't be projected.
53
+ */
54
+ export declare function renderDecisionIndex(git: Git, o: {
55
+ readonly layout: LogLayout;
56
+ readonly adr: AdrConfig;
57
+ readonly tree: TreeReader;
58
+ readonly history: string | null;
59
+ }): Promise<string | null>;
60
+ /**
61
+ * What the unstaged-files `index/stale` finding and the matching write note both start with:
62
+ * `path` lists `files` (some of them), which aren't staged.
63
+ */
64
+ export declare function unstagedIndexText(path: string, files: readonly string[]): string;
65
+ /**
66
+ * The log's event and body files whose work-tree content isn't staged (untracked or modified),
67
+ * sorted: the cause of a staged `index.md` that only the work tree's render matches.
68
+ */
69
+ export declare function unstagedLogFiles(git: Git, layout: LogLayout): Promise<string[]>;
70
+ /**
71
+ * The verify check that `<root>/index.md` is current (design 2b §4.5, "Freshness in verify"). In
72
+ * staged mode (the pre-commit hook), a stale staged copy that equals the work tree's render
73
+ * means another decision's files aren't staged: writes stage the work tree's render (D2), and
74
+ * `adr index` would change nothing. The finding then names those files and says to stage them.
75
+ */
76
+ export declare function decisionIndexCheck(log: DecisionLog): Check;
77
+ /** Whether `bytes` (null: absent) hold exactly `text`. */
78
+ export declare function holdsText(bytes: Uint8Array | null, text: string): boolean;
79
+ /** HEAD's copy of `path`; `null` when it is absent or HEAD is unborn. */
80
+ export declare function headBytes(git: Git, path: string): Promise<Uint8Array | null>;
81
+ /** HEAD's tree, or an empty tree on an unborn HEAD. */
82
+ export declare function headTree(git: Git, head: string | null): Promise<TreeReader>;
83
+ /**
84
+ * Brings the work-tree copy of `path` to `text` (atomically, when it differs) and reports whether
85
+ * the staged copy differs, so the caller stages it. `old` is the work-tree copy before the write
86
+ * (`null` when absent), for rollback.
87
+ */
88
+ export declare function writeIndexCopy(git: Git, path: string, text: string): Promise<{
89
+ readonly wrote: boolean;
90
+ readonly old: Uint8Array | null;
91
+ readonly stage: boolean;
92
+ }>;
93
+ /** The first line of an error's message, for notes and headlines. */
94
+ export declare const firstLine: (err: unknown) => string;
95
+ /** `adr index`'s result and whether the work-tree refresh after a commit changed a copy. */
96
+ export interface IndexRun {
97
+ readonly doc: IndexResultJson;
98
+ /** With a commit requested: step 5 wrote or staged the work tree's render. */
99
+ readonly refreshed: boolean;
100
+ }
101
+ /**
102
+ * `adr index` (design 2b §4.5) with what the text output needs; `indexDecisionLog` is the
103
+ * library entry.
104
+ */
105
+ export declare function runDecisionIndex(log: DecisionLog, o?: WriteOptions & {
106
+ readonly check?: boolean;
107
+ }): Promise<IndexRun>;
108
+ /**
109
+ * `adr index [--check] [--commit | --no-commit] [-m <message>]` (design 2b §4.5): renders
110
+ * `<root>/index.md` and writes and stages it where the work tree or the index differ. With
111
+ * `commit` (default `[policy] auto_commit`) it renders HEAD's tree and commits the file alone when
112
+ * HEAD's copy differs, then refreshes the work tree's copy, which may include other decisions'
113
+ * uncommitted entries. `check` writes nothing and reports `index/*` findings.
114
+ */
115
+ export declare function indexDecisionLog(log: DecisionLog, o?: WriteOptions & {
116
+ readonly check?: boolean;
117
+ }): Promise<IndexResultJson>;