@nikovirtala/adr 0.5.6 → 0.5.8
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 +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.js +3 -3
- package/dist/{init-9e0diCz3.js → init-C7yFfIgA.js} +2 -2
- package/dist/{init-9e0diCz3.js.map → init-C7yFfIgA.js.map} +1 -1
- package/dist/{list-BnLU8Mis.js → list-Z7UhybR0.js} +2 -2
- package/dist/{list-BnLU8Mis.js.map → list-Z7UhybR0.js.map} +1 -1
- package/dist/{search-Ciix0IwS.js → search-BzoRvSEH.js} +18 -9
- package/dist/search-BzoRvSEH.js.map +1 -0
- package/dist/{server-BA8WZ9Jq.js → server-CHA0l2sS.js} +3 -3
- package/dist/{server-BA8WZ9Jq.js.map → server-CHA0l2sS.js.map} +1 -1
- package/dist/types/log.d.ts +7 -3
- package/dist/types/search.d.ts +5 -1
- package/dist/types/views.d.ts +1 -1
- package/package.json +2 -2
- package/dist/search-Ciix0IwS.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-BA8WZ9Jq.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 { readSourceDecisions } from \"../sources.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 `source` input of `adr_list` and `adr_search`: a `[[sources]]` name, read from the cache. */\nconst SOURCE = { type: \"string\", pattern: \"^[a-z][a-z0-9-]{0,31}$\" } as const;\n\n/** The local log, or with `source` that `[[sources]]` entry's cached log. */\nasync function readFor(e: AdrMcpEnv, source: string | null) {\n const log = await openLog(e);\n return source === null ? readDecisions(log) : readSourceDecisions(log, source);\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 source: SOURCE,\n },\n [\"query\"],\n ),\n annotations: READ,\n async run(input) {\n const read = await readFor(e, str(input.source) ?? null);\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 source: SOURCE,\n }),\n annotations: READ,\n async run(input) {\n const read = await readFor(e, str(input.source) ?? null);\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;;AAGA,SAAgB,uBAAuB,KAAyB;CAC9D,OAAO,IAAI;AACb;;;;;AAMA,SAAgB,cAAc,MAAqB,IAA2B;CAI5E,MAAM,SAHW,KAAK,OAAO,SAC1B,IAAI,EAAE,CAAC,EACN,QAAQ,MAAM,MAAM,EAAE,MAAM,SAAS,QAAQ,QAAQ,QAAQ,IAAI,EAAA,EAC7C,MAAM;CAC9B,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,QAAQ,MAAM,SAAS,UAAU,MAAM,eAAe,MAAM;CAClE,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,CAAC,CAAC,YAAY,IAAI;AACzF;;;;;;;;;AAaA,SAAgB,gBAAgB,GASb;CACjB,MAAM,EAAE,SAAS;CACjB,IAAI,EAAE,SAAS,eAAe,CAAC,QAAQ,QA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E;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"}
|
|
1
|
+
{"version":3,"file":"server-CHA0l2sS.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 { readSourceDecisions } from \"../sources.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 `source` input of `adr_list` and `adr_search`: a `[[sources]]` name, read from the cache. */\nconst SOURCE = { type: \"string\", pattern: \"^[a-z][a-z0-9-]{0,31}$\" } as const;\n\n/** The local log, or with `source` that `[[sources]]` entry's cached log. */\nasync function readFor(e: AdrMcpEnv, source: string | null) {\n const log = await openLog(e);\n return source === null ? readDecisions(log) : readSourceDecisions(log, source);\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 source: SOURCE,\n },\n [\"query\"],\n ),\n annotations: READ,\n async run(input) {\n const read = await readFor(e, str(input.source) ?? null);\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 source: SOURCE,\n }),\n annotations: READ,\n async run(input) {\n const read = await readFor(e, str(input.source) ?? null);\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;;AAGA,SAAgB,uBAAuB,KAAyB;CAC9D,OAAO,IAAI;AACb;;;;;AAMA,SAAgB,cAAc,MAAqB,IAA2B;CAI5E,MAAM,SAHW,KAAK,OAAO,SAC1B,IAAI,EAAE,CAAC,EACN,QAAQ,MAAM,MAAM,EAAE,MAAM,SAAS,QAAQ,QAAQ,QAAQ,IAAI,EAAA,EAC7C,MAAM;CAC9B,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,QAAQ,MAAM,SAAS,UAAU,MAAM,eAAe,MAAM;CAClE,OAAO,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,CAAC,CAAC,YAAY,IAAI;AACzF;;;;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;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"}
|
package/dist/types/log.d.ts
CHANGED
|
@@ -66,13 +66,17 @@ export declare function sourcesNote(read: DecisionsRead): string | null;
|
|
|
66
66
|
export declare function listingNotes(read: DecisionsRead): readonly string[];
|
|
67
67
|
/**
|
|
68
68
|
* The note a read command adds about where numbers come from: the shallow-clone index, or why
|
|
69
|
-
* they are unavailable (`unavailable: false` leaves that one out
|
|
69
|
+
* they are unavailable (`unavailable: false` leaves that one out, except for a `--source` log
|
|
70
|
+
* without a committed index); `null` for none.
|
|
70
71
|
*/
|
|
71
72
|
export declare function numberingNote(read: DecisionsRead, o: {
|
|
72
73
|
readonly unavailable: boolean;
|
|
73
74
|
}): string | null;
|
|
74
|
-
/**
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Why numbers are unavailable, in words: `shallow clone`, `<source> has no committed index.md`
|
|
77
|
+
* (`the log` without a source name) or `no main branch`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function unavailableReason(n: Numbering, source?: string | null): string;
|
|
76
80
|
/**
|
|
77
81
|
* The id a decision argument names: an id, or a number in any form `parseDecisionNumber` takes.
|
|
78
82
|
* Throws `UsageError` (exit 2) naming the reason when it names nothing.
|
package/dist/types/search.d.ts
CHANGED
|
@@ -13,7 +13,11 @@ export interface DecisionSearchResultJson {
|
|
|
13
13
|
readonly score: number;
|
|
14
14
|
/** The fields with a hit, in the order id, title, body, notes (the display number is `id`). */
|
|
15
15
|
readonly matched: readonly SearchField[];
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* The best matching line of the body or a note, cut to about 160 characters; a `#` heading
|
|
18
|
+
* line of the body only when no other line matches; `null` if none (then every term matched
|
|
19
|
+
* the id or the title).
|
|
20
|
+
*/
|
|
17
21
|
readonly excerpt: string | null;
|
|
18
22
|
}
|
|
19
23
|
/** `adr search <query>… --json` and `adr_search` (design §6.4). */
|
package/dist/types/views.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type ChangedSince, type DecisionsRead } from "./log.js";
|
|
|
4
4
|
/** The `numbering` key of the read documents. */
|
|
5
5
|
export interface NumberingJson {
|
|
6
6
|
readonly available: boolean;
|
|
7
|
-
readonly reason: "shallow" | "no-main-ref" | "index" | null;
|
|
7
|
+
readonly reason: "shallow" | "no-main-ref" | "no-index" | "index" | null;
|
|
8
8
|
readonly ref: string | null;
|
|
9
9
|
}
|
|
10
10
|
/** `adr list --json` (design §5.5). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nikovirtala/adr",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"description": "Architecture decision records kept as event logs in git: frozen bodies, computed status and supersession chains. CLI and library.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adr",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"provenance": true
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@nikovirtala/ledger": "^0.
|
|
48
|
+
"@nikovirtala/ledger": "^0.12.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@modelcontextprotocol/sdk": "1.32.2"
|