@descent-vtt/spec-harness 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/git.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAU9C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,MAAM,OAAO,GAAG,KAAoD,CAAC;IACrE,OAAO,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,mCAAmC,CAAC;AAC7G,CAAC;AAED,8HAA8H;AAC9H,SAAS,UAAU,CAAC,IAAuB;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAE,CAAC;AACtF,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAAC,IAAuB,EAAE,GAAW,EAAE,KAAK,GAAG,SAAS;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,uEAAuE;QACvE,+DAA+D;QAC/D,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,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BAA4B,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,GAAW;IAC5D,uEAAuE;IACvE,sEAAsE;IACtE,sCAAsC;IACtC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/**\n * The edge where the harness meets git.\n *\n * Reads, except for two things ADR-0003 allows and bounds: a temporary\n * worktree, added and always removed by the sandbox, and nothing else. Every\n * call is an argument vector, never a shell string, so a path or a ref cannot\n * become a command.\n */\n\nimport { execFile } from 'node:child_process';\n\nimport type { FileChange, LocalBranch } from './types.js';\n\nexport interface Run {\n readonly code: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\n/**\n * How long a process the harness asks a question of is given to answer:\n * git's reads, spec-brief's list of the briefs. Claude Code gives the hook's\n * entry 60 seconds, as init and the plugin write it, and cancels a hook that\n * reaches them, which before a write lets the write go ahead (ADR-0002). A\n * process that does not answer within this is stopped and its question\n * answered as one that failed, which before a write holds it, well inside\n * that minute; and the slowest such process measured, on a Windows\n * workstation under load and on GitHub's runner, answered in a fraction of\n * it.\n */\nexport const ANSWER_MS = 20_000;\n\n/**\n * How long a process that does a round's work is given: a diff of the\n * round, a worktree added for a probe or taken away, a sibling's check of\n * the repository. Its length is the repository's, and none runs before a\n * write.\n */\nexport const WORK_MS = 600_000;\n\n/**\n * Whether a process ended because the harness stopped it at its time\n * limit: Node kills it then and says so with `killed`. It kills one for\n * output past `maxBuffer` as well, and names that by its code.\n */\nexport function stoppedAtLimit(error: unknown): boolean {\n const failure = error as { killed?: unknown; code?: unknown } | null;\n return failure !== null && failure.killed === true && failure.code !== 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER';\n}\n\n/** The git command a line of arguments runs, past the `-c` settings before it: every line the harness hands git names one. */\nfunction subcommand(args: readonly string[]): string {\n return args.find((arg, index) => !arg.startsWith('-') && args[index - 1] !== '-c')!;\n}\n\n/**\n * Runs git and answers whatever it answered; a missing git is a code of -1.\n * A git that does not answer within `limit` is stopped, and rejected as a\n * `GitError` that says so: read as a failure, a question about the work\n * tree or the branch would answer as a directory in none, or a head on no\n * branch, under which the hook checks no write.\n */\nexport function git(args: readonly string[], cwd: string, limit = ANSWER_MS): Promise<Run> {\n return new Promise((resolve, reject) => {\n // windowsHide only keeps a console window from flashing up on Windows,\n // and the sweep runs on Linux, where its mutant is equivalent.\n execFile('git', [...args], { cwd, maxBuffer: 256 * 1024 * 1024, encoding: 'utf8', windowsHide: true, timeout: limit }, (error, stdout, stderr) => {\n if (stoppedAtLimit(error)) {\n reject(new GitError(`git ${subcommand(args)} did not answer within ${limit / 1000} seconds, and was stopped`));\n return;\n }\n // Every caller tells 0 from any other code, never one failure from\n // another, so which code a failure gets is equivalent to its mutants.\n const code = error === null ? 0 : typeof (error as { code?: unknown }).code === 'number' ? (error as { code: number }).code : -1;\n resolve({ code, stdout, stderr });\n });\n });\n}\n\nasync function value(args: readonly string[], cwd: string): Promise<string | null> {\n const run = await git(args, cwd);\n return run.code === 0 ? run.stdout.trim() : null;\n}\n\nexport class GitError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'GitError';\n }\n}\n\n/** The top of the work tree holding `cwd`, POSIX-separated, or `null` outside one. */\nexport async function workTreeRoot(cwd: string): Promise<string | null> {\n return value(['rev-parse', '--show-toplevel'], cwd);\n}\n\n/** The git directory every worktree of this repository shares. */\nexport async function commonDirectory(cwd: string): Promise<string | null> {\n return value(['rev-parse', '--path-format=absolute', '--git-common-dir'], cwd);\n}\n\n/** A work tree as one start of git names it: its top, and the git directory its worktrees share. */\nexport interface WorkTree {\n readonly root: string;\n readonly commonDir: string;\n}\n\n/**\n * The top of the work tree holding `cwd` and the common directory, asked of\n * git in one start where {@link workTreeRoot} and {@link commonDirectory}\n * are two: `null` outside a work tree, and `'unread'` where the one answer\n * cannot be taken for the two, which are then to be asked for as they were.\n *\n * Measured with git 2.43 and 2.55, rev-parse answers the two in the order\n * they stand on its line, a line each, and prints nothing where the first\n * fails. Its manual says of that only that `--show-toplevel` reports an\n * error where there is no working tree (git-rev-parse(1), Options for\n * Files, as git 2.55.0 has it, read 2026-10-14), so nothing is read on\n * trust. Two lines that are each what `trim` would leave, from a git that\n * did not fail, are the two answers. Nothing printed, by a git that\n * failed, is the first question failing, the one {@link workTreeRoot}\n * asks: `cwd` is in no work tree. Anything else is not read: a path that\n * holds a line break is more lines than two, and so is what a git before\n * 2.31 would print, to which `--path-format=absolute` is a flag to hand\n * back (the same manual, Options for Filtering; the option is new in the\n * release notes of 2.31.0). No such git was measured.\n *\n * `--path-format` reaches only what follows it on the line (Options for\n * Files), so the top is printed as it is where it is asked for alone. The\n * common directory is asked for from `cwd` here, and from the top by\n * {@link commonDirectory}: the same directory only where `cwd` is the top.\n */\nexport async function workTree(cwd: string): Promise<WorkTree | 'unread' | null> {\n const run = await git(['rev-parse', '--show-toplevel', '--path-format=absolute', '--git-common-dir'], cwd);\n if (run.stdout === '') return run.code === 0 ? 'unread' : null;\n const lines = run.stdout.split('\\n');\n if (run.code !== 0 || lines.length !== 3 || lines[2] !== '') return 'unread';\n const root = lines[0]!;\n const commonDir = lines[1]!;\n if (root === '' || commonDir === '' || root.trim() !== root || commonDir.trim() !== commonDir) return 'unread';\n return { root, commonDir };\n}\n\n/**\n * Where git runs the hook `name` from, absolute: `core.hooksPath` read as git\n * reads it - relative to the work tree, absolute, or under `~` - and a linked\n * worktree's shared hooks. Where git cannot say, the first line of what it\n * said instead: under a `core.hooksPath` that names a file it refuses the\n * path as one that is not a directory (measured with git 2.47 and 2.55).\n */\nexport async function hookPath(name: string, cwd: string): Promise<{ readonly path: string } | { readonly refused: string }> {\n const run = await git(['rev-parse', '--path-format=absolute', '--git-path', `hooks/${name}`], cwd);\n if (run.code === 0) return { path: run.stdout.trim() };\n return { refused: run.stderr.split(/\\r?\\n/)[0]! };\n}\n\nconst HEADS = 'refs/heads/';\n\n/**\n * The checked-out branch's name, or `null` on a detached head: what HEAD\n * points at, with `refs/heads/` taken off and nothing else. `--short` gives\n * the shortest name git reads as that ref and no other, which is another\n * name where a tag, or a ref under `refs/`, has the branch's: measured with\n * git 2.55, on `claude/brief-042-x` beside the tag `claude/brief-042-x` it\n * answers `heads/claude/brief-042-x`, which no template reads, and the\n * brief went unnamed (ADR-0005). A HEAD that points outside `refs/heads/`,\n * as `git symbolic-ref HEAD refs/tags/x` leaves it, is named as git status\n * names it, the ref whole.\n */\nexport async function currentBranch(cwd: string): Promise<string | null> {\n const ref = await value(['symbolic-ref', '--quiet', 'HEAD'], cwd);\n return ref !== null && ref.startsWith(HEADS) ? ref.slice(HEADS.length) : ref;\n}\n\n/**\n * The remote's default branch as a local ref, such as `origin/main`, or\n * `null`. This is a ref the harness hands git and spec-brief as the base, so\n * it is the short name git reads as that ref and no other: beside a local\n * branch or a tag named `origin/main`, measured with git 2.55, it is\n * `remotes/origin/main`, where `origin/main` would be read as the branch or\n * the tag (gitrevisions(7), the order a ref name is read in).\n */\nexport async function remoteDefault(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD'], cwd);\n}\n\n/**\n * Every local branch. The two are one name but where a tag, or a ref under\n * `refs/`, has the branch's: `main` beside the tag `main` is the ref\n * `heads/main`. A ref name holds no control character\n * (git-check-ref-format(1)), so a tab parts the two.\n */\nexport async function localBranches(cwd: string): Promise<LocalBranch[]> {\n const listed = await value(['for-each-ref', '--format=%(refname:lstrip=2)%09%(refname:short)', HEADS], cwd);\n // for-each-ref fails only where git itself does, outside a repository,\n // where init never runs: the null check is there for the type.\n if (listed === null || listed === '') return [];\n return listed.split('\\n').map((line) => {\n const parts = line.split('\\t');\n return { name: parts[0]!, ref: parts[1]! };\n });\n}\n\nexport async function revision(ref: string, cwd: string): Promise<string | null> {\n return value(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`], cwd);\n}\n\nexport async function mergeBase(a: string, b: string, cwd: string): Promise<string | null> {\n return value(['merge-base', a, b], cwd);\n}\n\n/** Parses `git diff --name-status -z` output. */\nexport function parseNameStatus(output: string): FileChange[] {\n const fields = output.split('\\0');\n const out: FileChange[] = [];\n for (let i = 0; i < fields.length; ) {\n const code = fields[i] as string;\n if (code === '') {\n i += 1;\n continue;\n }\n const letter = code.charAt(0);\n const status = letter as FileChange['status'];\n if (status === 'R' || status === 'C') {\n out.push({ status, from: fields[i + 1] ?? '', path: fields[i + 2] ?? '' });\n i += 3;\n } else {\n out.push({ status, path: fields[i + 1] ?? '' });\n i += 2;\n }\n }\n return out;\n}\n\n/** The files changed from one revision to another, renames found. */\nexport async function changes(from: string, to: string, cwd: string): Promise<FileChange[]> {\n const run = await git(['diff', '--name-status', '-z', '--find-renames', '--no-color', from, to, '--'], cwd, WORK_MS);\n if (run.code !== 0) throw new GitError(`git diff ${from} ${to} failed: ${run.stderr.trim()}`);\n return parseNameStatus(run.stdout);\n}\n\n/**\n * How many words stand before the path in each kind of record of\n * `git status --porcelain=v2`, as git-status(1) has them (Git for Windows\n * 2.55.0, *Porcelain Format Version 2*, read 2026-10-19): an ordinary\n * change, `1`, and seven; a rename or a copy, `2`, and eight, its path\n * followed by the path it came from as a record of its own under `-z`; an\n * unmerged path, `u`, and nine; an untracked or an ignored path, `?` or\n * `!`, and none. A header, `#`, names no path.\n */\nconst STATUS_FIELDS: Readonly<Record<string, number>> = { '1': 8, '2': 9, u: 10, '?': 1, '!': 1 };\n\n/**\n * The paths `git status --porcelain=v2 -z` names, each once, in the order\n * git gives them: a rename or a copy by both its paths. A path with a space\n * in it is the rest of its record, which `-z` prints as is.\n */\nexport function parseStatus(output: string): string[] {\n const records = output.split('\\0');\n const paths = new Set<string>();\n for (let at = 0; at < records.length; at += 1) {\n const record = records[at]!;\n const fields = STATUS_FIELDS[record.charAt(0)];\n if (fields === undefined) continue;\n paths.add(record.split(' ').slice(fields).join(' '));\n if (record.startsWith('2')) {\n at += 1;\n paths.add(records[at] ?? '');\n }\n }\n paths.delete('');\n return [...paths];\n}\n\n/**\n * Every path the work tree holds changed from HEAD: tracked files that\n * differ in the index or in the work tree, unmerged ones, and each\n * untracked file, those in an untracked directory one by one. One start of\n * git, with no optional lock taken: a status that writes the index as it\n * refreshes it holds a lock that can make another git running beside it\n * fail, and the manual has a status run in the background take none\n * (git-status(1), *Background Refresh*, and git(1), `--no-optional-locks`,\n * as Git for Windows 2.55.0 has them, read 2026-10-19).\n */\nexport async function changedPaths(cwd: string): Promise<string[]> {\n const run = await git(['--no-optional-locks', 'status', '--porcelain=v2', '-z', '--untracked-files=all'], cwd);\n if (run.code !== 0) throw new GitError(`git status failed: ${run.stderr.trim()}`);\n return parseStatus(run.stdout);\n}\n\n/** The files a commit would change: what is staged. */\nexport async function stagedChanges(cwd: string): Promise<FileChange[]> {\n const run = await git(['diff', '--cached', '--name-status', '-z', '--find-renames', '--no-color', '--'], cwd, WORK_MS);\n if (run.code !== 0) throw new GitError(`git diff --cached failed: ${run.stderr.trim()}`);\n return parseNameStatus(run.stdout);\n}\n\n/** A file's content at a revision, or `null` when it does not exist there. */\nexport async function show(ref: string, path: string, cwd: string): Promise<string | null> {\n const run = await git(['show', `${ref}:${path}`], cwd);\n return run.code === 0 ? run.stdout : null;\n}\n\n/** Whether a commit id from {@link blameLine} is the all-zero one of a line nobody committed. */\nexport function isUncommitted(sha: string): boolean {\n return /^0+$/.test(sha);\n}\n\n/**\n * The commit that last changed one line of a file, as of a revision, or of\n * the working tree when `ref` is `null` - where a line nobody committed yet\n * belongs to the all-zero commit.\n */\nexport async function blameLine(ref: string | null, path: string, line: number, cwd: string): Promise<string | null> {\n const run = await git(['blame', '--porcelain', '-L', `${line},${line}`, ...(ref === null ? [] : [ref]), '--', path], cwd);\n // A blame that fails prints nothing on stdout, which names no commit. Its\n // output opens with the commit, so the anchor is equivalent to its mutant.\n const sha = /^([0-9a-f]{40,64}) /.exec(run.stdout)?.[1];\n return sha ?? null;\n}\n\n/** A good signature names its allowed signer's principal; any other names none. */\nexport type Signature =\n | { readonly good: true; readonly principal: string; readonly detail: string }\n | { readonly good: false; readonly principal: null; readonly detail: string };\n\n/**\n * Whether a commit carries a good SSH signature by a principal in the given\n * allowed-signers file. The file is passed in, never read from the commit's\n * own tree: a round cannot vouch for itself (ADR-0006).\n */\nexport async function verifyCommit(sha: string, allowedSignersFile: string, cwd: string): Promise<Signature> {\n const run = await git(\n ['-c', `gpg.ssh.allowedSignersFile=${allowedSignersFile}`, '-c', 'gpg.format=ssh', 'verify-commit', '--raw', sha],\n cwd,\n );\n const text = `${run.stderr}\\n${run.stdout}`;\n const principal = /Good \"git\" signature for (\\S+)/.exec(text)?.[1];\n // git writes the check to stderr, so the trim changes the first line only\n // for output on stdout alone, which verify-commit does not print; and split\n // always answers a first part.\n const detail = text.trim().split('\\n')[0]!;\n // git exits 0 only for a signature by a listed principal, which it names:\n // either condition alone is equivalent to both, and both trust neither.\n return run.code === 0 && principal !== undefined ? { good: true, principal, detail } : { good: false, principal: null, detail };\n}\n\nexport async function addWorktree(path: string, rev: string, cwd: string): Promise<void> {\n const run = await git(['worktree', 'add', '--detach', '--force', path, rev], cwd, WORK_MS);\n if (run.code !== 0) throw new GitError(`git worktree add failed: ${run.stderr.trim()}`);\n}\n\n/**\n * Has git remove the worktree at `path`, and no other, with its record of it,\n * and answers whether git did. Git deletes what it can of the worktree's\n * directory and forgets the worktree even when it cannot delete it all. It\n * refuses a worktree whose directory has lost its `.git` file, and removes\n * its record of one whose directory is gone, found by the path it was added\n * at: `git worktree prune` would also forget every other worktree git has\n * lost track of, the person's among them.\n */\nexport async function removeWorktree(path: string, cwd: string): Promise<boolean> {\n // The sandbox asks again when this answers false, and git, asked again\n // about a worktree it has forgotten, changes nothing: the mutant that\n // always answers false is equivalent.\n return (await git(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AAC,IAAI,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAClI,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAAY,EAAE,GAAW,EAAE,GAAW;IACtE,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3F,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC;QAAE,MAAM,IAAI,QAAQ,CAAC,4BAA4B,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC1F,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY,EAAE,GAAW;IAC5D,uEAAuE;IACvE,sEAAsE;IACtE,sCAAsC;IACtC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC;AACvF,CAAC","sourcesContent":["/**\n * The edge where the harness meets git.\n *\n * Reads, except for two things ADR-0003 allows and bounds: a temporary\n * worktree, added and always removed by the sandbox, and nothing else. Every\n * call is an argument vector, never a shell string, so a path or a ref cannot\n * become a command.\n */\n\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { execFile } from 'node:child_process';\n\nimport type { FileChange, LocalBranch } from './types.js';\n\nexport interface Run {\n readonly code: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\n/**\n * How long a process the harness asks a question of is given to answer:\n * git's reads, spec-brief's list of the briefs. Claude Code gives the hook's\n * entry 60 seconds, as init and the plugin write it, and cancels a hook that\n * reaches them, which before a write lets the write go ahead (ADR-0002). A\n * process that does not answer within this is stopped and its question\n * answered as one that failed, which before a write holds it, well inside\n * that minute; and the slowest such process measured, on a Windows\n * workstation under load and on GitHub's runner, answered in a fraction of\n * it.\n */\nexport const ANSWER_MS = 20_000;\n\n/**\n * How long a process that does a round's work is given: a diff of the\n * round, a worktree added for a probe or taken away, a sibling's check of\n * the repository. Its length is the repository's, and none runs before a\n * write.\n */\nexport const WORK_MS = 600_000;\n\n/** The run a process is started in, where it has a budget: its length, and when it ends, as `performance.now()` reads it. */\nconst budget = new AsyncLocalStorage<{ readonly ms: number; readonly end: number }>();\n\n/** Runs `work` with every process it starts given no more than what is left of `ms` from now. */\nexport function withBudget<T>(ms: number, work: () => Promise<T>): Promise<T> {\n return budget.run({ ms, end: performance.now() + ms }, work);\n}\n\n/**\n * The time a process is given, `limit`, or what is left of the budget of\n * the run it is started in where that is less, with the words that say\n * which: the run's budget is said as such, so that a write held at it says\n * why. A run with nothing left is given 0, and starts nothing.\n */\nexport function timeFor(limit: number): { readonly ms: number; readonly said: string } {\n const run = budget.getStore();\n const left = run === undefined ? limit : run.end - performance.now();\n if (left >= limit) return { ms: limit, said: `${limit / 1000} seconds` };\n return { ms: Math.max(0, Math.ceil(left)), said: `the ${run!.ms / 1000} seconds the hook's run is given` };\n}\n\n/**\n * Whether a process ended because the harness stopped it at its time\n * limit: Node kills it then and says so with `killed`. It kills one for\n * output past `maxBuffer` as well, and names that by its code.\n */\nexport function stoppedAtLimit(error: unknown): boolean {\n const failure = error as { killed?: unknown; code?: unknown } | null;\n return failure !== null && failure.killed === true && failure.code !== 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER';\n}\n\n/** The git command a line of arguments runs, past the `-c` settings before it: every line the harness hands git names one. */\nfunction subcommand(args: readonly string[]): string {\n return args.find((arg, index) => !arg.startsWith('-') && args[index - 1] !== '-c')!;\n}\n\n/**\n * Runs git and answers whatever it answered; a missing git is a code of -1.\n * A git that does not answer within `limit` is stopped, and rejected as a\n * `GitError` that says so: read as a failure, a question about the work\n * tree or the branch would answer as a directory in none, or a head on no\n * branch, under which the hook checks no write.\n */\nexport function git(args: readonly string[], cwd: string, limit = ANSWER_MS): Promise<Run> {\n const { ms, said } = timeFor(limit);\n if (ms === 0) return Promise.reject(new GitError(`git ${subcommand(args)} was not started: ${said} had passed`));\n return new Promise((resolve, reject) => {\n // windowsHide only keeps a console window from flashing up on Windows,\n // and the sweep runs on Linux, where its mutant is equivalent.\n execFile('git', [...args], { cwd, maxBuffer: 256 * 1024 * 1024, encoding: 'utf8', windowsHide: true, timeout: ms }, (error, stdout, stderr) => {\n if (stoppedAtLimit(error)) {\n reject(new GitError(`git ${subcommand(args)} did not answer within ${said}, and was stopped`));\n return;\n }\n // Every caller tells 0 from any other code, never one failure from\n // another, so which code a failure gets is equivalent to its mutants.\n const code = error === null ? 0 : typeof (error as { code?: unknown }).code === 'number' ? (error as { code: number }).code : -1;\n resolve({ code, stdout, stderr });\n });\n });\n}\n\nasync function value(args: readonly string[], cwd: string): Promise<string | null> {\n const run = await git(args, cwd);\n return run.code === 0 ? run.stdout.trim() : null;\n}\n\nexport class GitError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'GitError';\n }\n}\n\n/** The top of the work tree holding `cwd`, POSIX-separated, or `null` outside one. */\nexport async function workTreeRoot(cwd: string): Promise<string | null> {\n return value(['rev-parse', '--show-toplevel'], cwd);\n}\n\n/** The git directory every worktree of this repository shares. */\nexport async function commonDirectory(cwd: string): Promise<string | null> {\n return value(['rev-parse', '--path-format=absolute', '--git-common-dir'], cwd);\n}\n\n/** A work tree as one start of git names it: its top, and the git directory its worktrees share. */\nexport interface WorkTree {\n readonly root: string;\n readonly commonDir: string;\n}\n\n/**\n * The top of the work tree holding `cwd` and the common directory, asked of\n * git in one start where {@link workTreeRoot} and {@link commonDirectory}\n * are two: `null` outside a work tree, and `'unread'` where the one answer\n * cannot be taken for the two, which are then to be asked for as they were.\n *\n * Measured with git 2.43 and 2.55, rev-parse answers the two in the order\n * they stand on its line, a line each, and prints nothing where the first\n * fails. Its manual says of that only that `--show-toplevel` reports an\n * error where there is no working tree (git-rev-parse(1), Options for\n * Files, as git 2.55.0 has it, read 2026-10-14), so nothing is read on\n * trust. Two lines that are each what `trim` would leave, from a git that\n * did not fail, are the two answers. Nothing printed, by a git that\n * failed, is the first question failing, the one {@link workTreeRoot}\n * asks: `cwd` is in no work tree. Anything else is not read: a path that\n * holds a line break is more lines than two, and so is what a git before\n * 2.31 would print, to which `--path-format=absolute` is a flag to hand\n * back (the same manual, Options for Filtering; the option is new in the\n * release notes of 2.31.0). No such git was measured.\n *\n * `--path-format` reaches only what follows it on the line (Options for\n * Files), so the top is printed as it is where it is asked for alone. The\n * common directory is asked for from `cwd` here, and from the top by\n * {@link commonDirectory}: the same directory only where `cwd` is the top.\n */\nexport async function workTree(cwd: string): Promise<WorkTree | 'unread' | null> {\n const run = await git(['rev-parse', '--show-toplevel', '--path-format=absolute', '--git-common-dir'], cwd);\n if (run.stdout === '') return run.code === 0 ? 'unread' : null;\n const lines = run.stdout.split('\\n');\n if (run.code !== 0 || lines.length !== 3 || lines[2] !== '') return 'unread';\n const root = lines[0]!;\n const commonDir = lines[1]!;\n if (root === '' || commonDir === '' || root.trim() !== root || commonDir.trim() !== commonDir) return 'unread';\n return { root, commonDir };\n}\n\n/**\n * Where git runs the hook `name` from, absolute: `core.hooksPath` read as git\n * reads it - relative to the work tree, absolute, or under `~` - and a linked\n * worktree's shared hooks. Where git cannot say, the first line of what it\n * said instead: under a `core.hooksPath` that names a file it refuses the\n * path as one that is not a directory (measured with git 2.47 and 2.55).\n */\nexport async function hookPath(name: string, cwd: string): Promise<{ readonly path: string } | { readonly refused: string }> {\n const run = await git(['rev-parse', '--path-format=absolute', '--git-path', `hooks/${name}`], cwd);\n if (run.code === 0) return { path: run.stdout.trim() };\n return { refused: run.stderr.split(/\\r?\\n/)[0]! };\n}\n\nconst HEADS = 'refs/heads/';\n\n/**\n * The checked-out branch's name, or `null` on a detached head: what HEAD\n * points at, with `refs/heads/` taken off and nothing else. `--short` gives\n * the shortest name git reads as that ref and no other, which is another\n * name where a tag, or a ref under `refs/`, has the branch's: measured with\n * git 2.55, on `claude/brief-042-x` beside the tag `claude/brief-042-x` it\n * answers `heads/claude/brief-042-x`, which no template reads, and the\n * brief went unnamed (ADR-0005). A HEAD that points outside `refs/heads/`,\n * as `git symbolic-ref HEAD refs/tags/x` leaves it, is named as git status\n * names it, the ref whole.\n */\nexport async function currentBranch(cwd: string): Promise<string | null> {\n const ref = await value(['symbolic-ref', '--quiet', 'HEAD'], cwd);\n return ref !== null && ref.startsWith(HEADS) ? ref.slice(HEADS.length) : ref;\n}\n\n/**\n * The remote's default branch as a local ref, such as `origin/main`, or\n * `null`. This is a ref the harness hands git and spec-brief as the base, so\n * it is the short name git reads as that ref and no other: beside a local\n * branch or a tag named `origin/main`, measured with git 2.55, it is\n * `remotes/origin/main`, where `origin/main` would be read as the branch or\n * the tag (gitrevisions(7), the order a ref name is read in).\n */\nexport async function remoteDefault(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD'], cwd);\n}\n\n/**\n * Every local branch. The two are one name but where a tag, or a ref under\n * `refs/`, has the branch's: `main` beside the tag `main` is the ref\n * `heads/main`. A ref name holds no control character\n * (git-check-ref-format(1)), so a tab parts the two.\n */\nexport async function localBranches(cwd: string): Promise<LocalBranch[]> {\n const listed = await value(['for-each-ref', '--format=%(refname:lstrip=2)%09%(refname:short)', HEADS], cwd);\n // for-each-ref fails only where git itself does, outside a repository,\n // where init never runs: the null check is there for the type.\n if (listed === null || listed === '') return [];\n return listed.split('\\n').map((line) => {\n const parts = line.split('\\t');\n return { name: parts[0]!, ref: parts[1]! };\n });\n}\n\nexport async function revision(ref: string, cwd: string): Promise<string | null> {\n return value(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`], cwd);\n}\n\nexport async function mergeBase(a: string, b: string, cwd: string): Promise<string | null> {\n return value(['merge-base', a, b], cwd);\n}\n\n/** Parses `git diff --name-status -z` output. */\nexport function parseNameStatus(output: string): FileChange[] {\n const fields = output.split('\\0');\n const out: FileChange[] = [];\n for (let i = 0; i < fields.length; ) {\n const code = fields[i] as string;\n if (code === '') {\n i += 1;\n continue;\n }\n const letter = code.charAt(0);\n const status = letter as FileChange['status'];\n if (status === 'R' || status === 'C') {\n out.push({ status, from: fields[i + 1] ?? '', path: fields[i + 2] ?? '' });\n i += 3;\n } else {\n out.push({ status, path: fields[i + 1] ?? '' });\n i += 2;\n }\n }\n return out;\n}\n\n/** The files changed from one revision to another, renames found. */\nexport async function changes(from: string, to: string, cwd: string): Promise<FileChange[]> {\n const run = await git(['diff', '--name-status', '-z', '--find-renames', '--no-color', from, to, '--'], cwd, WORK_MS);\n if (run.code !== 0) throw new GitError(`git diff ${from} ${to} failed: ${run.stderr.trim()}`);\n return parseNameStatus(run.stdout);\n}\n\n/**\n * How many words stand before the path in each kind of record of\n * `git status --porcelain=v2`, as git-status(1) has them (Git for Windows\n * 2.55.0, *Porcelain Format Version 2*, read 2026-10-19): an ordinary\n * change, `1`, and seven; a rename or a copy, `2`, and eight, its path\n * followed by the path it came from as a record of its own under `-z`; an\n * unmerged path, `u`, and nine; an untracked or an ignored path, `?` or\n * `!`, and none. A header, `#`, names no path.\n */\nconst STATUS_FIELDS: Readonly<Record<string, number>> = { '1': 8, '2': 9, u: 10, '?': 1, '!': 1 };\n\n/**\n * The paths `git status --porcelain=v2 -z` names, each once, in the order\n * git gives them: a rename or a copy by both its paths. A path with a space\n * in it is the rest of its record, which `-z` prints as is.\n */\nexport function parseStatus(output: string): string[] {\n const records = output.split('\\0');\n const paths = new Set<string>();\n for (let at = 0; at < records.length; at += 1) {\n const record = records[at]!;\n const fields = STATUS_FIELDS[record.charAt(0)];\n if (fields === undefined) continue;\n paths.add(record.split(' ').slice(fields).join(' '));\n if (record.startsWith('2')) {\n at += 1;\n paths.add(records[at] ?? '');\n }\n }\n paths.delete('');\n return [...paths];\n}\n\n/**\n * Every path the work tree holds changed from HEAD: tracked files that\n * differ in the index or in the work tree, unmerged ones, and each\n * untracked file, those in an untracked directory one by one. One start of\n * git, with no optional lock taken: a status that writes the index as it\n * refreshes it holds a lock that can make another git running beside it\n * fail, and the manual has a status run in the background take none\n * (git-status(1), *Background Refresh*, and git(1), `--no-optional-locks`,\n * as Git for Windows 2.55.0 has them, read 2026-10-19).\n */\nexport async function changedPaths(cwd: string): Promise<string[]> {\n const run = await git(['--no-optional-locks', 'status', '--porcelain=v2', '-z', '--untracked-files=all'], cwd);\n if (run.code !== 0) throw new GitError(`git status failed: ${run.stderr.trim()}`);\n return parseStatus(run.stdout);\n}\n\n/** The files a commit would change: what is staged. */\nexport async function stagedChanges(cwd: string): Promise<FileChange[]> {\n const run = await git(['diff', '--cached', '--name-status', '-z', '--find-renames', '--no-color', '--'], cwd, WORK_MS);\n if (run.code !== 0) throw new GitError(`git diff --cached failed: ${run.stderr.trim()}`);\n return parseNameStatus(run.stdout);\n}\n\n/** A file's content at a revision, or `null` when it does not exist there. */\nexport async function show(ref: string, path: string, cwd: string): Promise<string | null> {\n const run = await git(['show', `${ref}:${path}`], cwd);\n return run.code === 0 ? run.stdout : null;\n}\n\n/**\n * Whether a commit's tree holds `path`, a path from the top of the work tree\n * read as written: `true` where git lists it, `false` where git lists\n * nothing for it, and `null` where git could not say, for a commit it does\n * not have among them. {@link show} answers `null` for a file that is not\n * there and for a git that failed alike, which can only make an answer\n * stricter; this tells the two apart, so that an answer may be loosened by a\n * file that git says is not there.\n *\n * ls-tree reads its paths as patterns, from the directory it is started in\n * (git-ls-tree(1), Description, as Git for Windows 2.55.0 has it, read\n * 2026-10-24): `--full-tree` has it read them from the top, and\n * `--literal-pathspecs` with no globbing and no magic (git(1), Options), so\n * a name such as `:(top)x.md` names that file, where ls-tree would read it\n * as `x.md`.\n */\nexport async function holdsPath(commit: string, path: string, cwd: string): Promise<boolean | null> {\n const run = await git(['--literal-pathspecs', 'ls-tree', '-z', '--full-tree', '--name-only', commit, '--', path], cwd);\n return run.code === 0 ? run.stdout !== '' : null;\n}\n\n/**\n * Whether the history is cut short, as a clone or a fetch with `--depth`\n * leaves it, where a merge base git finds can be an older commit than the\n * one the whole history has; `null` where git could not say. rev-parse\n * learned the question in 2.15.0 (its release notes), and prints `true` or\n * `false` (git-rev-parse(1), Options for Files, read 2026-10-24); anything\n * else is no answer.\n */\nexport async function isShallow(cwd: string): Promise<boolean | null> {\n const answer = await value(['rev-parse', '--is-shallow-repository'], cwd);\n if (answer === 'true') return true;\n return answer === 'false' ? false : null;\n}\n\n/** Whether a commit id from {@link blameLine} is the all-zero one of a line nobody committed. */\nexport function isUncommitted(sha: string): boolean {\n return /^0+$/.test(sha);\n}\n\n/**\n * The commit that last changed one line of a file, as of a revision, or of\n * the working tree when `ref` is `null` - where a line nobody committed yet\n * belongs to the all-zero commit.\n */\nexport async function blameLine(ref: string | null, path: string, line: number, cwd: string): Promise<string | null> {\n const run = await git(['blame', '--porcelain', '-L', `${line},${line}`, ...(ref === null ? [] : [ref]), '--', path], cwd);\n // A blame that fails prints nothing on stdout, which names no commit. Its\n // output opens with the commit, so the anchor is equivalent to its mutant.\n const sha = /^([0-9a-f]{40,64}) /.exec(run.stdout)?.[1];\n return sha ?? null;\n}\n\n/** A good signature names its allowed signer's principal; any other names none. */\nexport type Signature =\n | { readonly good: true; readonly principal: string; readonly detail: string }\n | { readonly good: false; readonly principal: null; readonly detail: string };\n\n/**\n * Whether a commit carries a good SSH signature by a principal in the given\n * allowed-signers file. The file is passed in, never read from the commit's\n * own tree: a round cannot vouch for itself (ADR-0006).\n */\nexport async function verifyCommit(sha: string, allowedSignersFile: string, cwd: string): Promise<Signature> {\n const run = await git(\n ['-c', `gpg.ssh.allowedSignersFile=${allowedSignersFile}`, '-c', 'gpg.format=ssh', 'verify-commit', '--raw', sha],\n cwd,\n );\n const text = `${run.stderr}\\n${run.stdout}`;\n const principal = /Good \"git\" signature for (\\S+)/.exec(text)?.[1];\n // git writes the check to stderr, so the trim changes the first line only\n // for output on stdout alone, which verify-commit does not print; and split\n // always answers a first part.\n const detail = text.trim().split('\\n')[0]!;\n // git exits 0 only for a signature by a listed principal, which it names:\n // either condition alone is equivalent to both, and both trust neither.\n return run.code === 0 && principal !== undefined ? { good: true, principal, detail } : { good: false, principal: null, detail };\n}\n\nexport async function addWorktree(path: string, rev: string, cwd: string): Promise<void> {\n const run = await git(['worktree', 'add', '--detach', '--force', path, rev], cwd, WORK_MS);\n if (run.code !== 0) throw new GitError(`git worktree add failed: ${run.stderr.trim()}`);\n}\n\n/**\n * Has git remove the worktree at `path`, and no other, with its record of it,\n * and answers whether git did. Git deletes what it can of the worktree's\n * directory and forgets the worktree even when it cannot delete it all. It\n * refuses a worktree whose directory has lost its `.git` file, and removes\n * its record of one whose directory is gone, found by the path it was added\n * at: `git worktree prune` would also forget every other worktree git has\n * lost track of, the person's among them.\n */\nexport async function removeWorktree(path: string, cwd: string): Promise<boolean> {\n // The sandbox asks again when this answers false, and git, asked again\n // about a worktree it has forgotten, changes nothing: the mutant that\n // always answers false is equivalent.\n return (await git(['worktree', 'remove', '--force', path], cwd, WORK_MS)).code === 0;\n}\n"]}
package/dist/guard.d.ts CHANGED
@@ -11,7 +11,7 @@
11
11
  import type { OutOfScope } from './config.js';
12
12
  import type { BriefRow } from './types.js';
13
13
  export type Verdict = 'allow' | 'warn' | 'ask' | 'deny';
14
- export type Reason = 'outside-repository' | 'no-brief' | 'brief-file' | 'protected' | 'ruled' | 'unreadable-protection' | 'in-scope' | 'out-of-scope';
14
+ export type Reason = 'outside-repository' | 'no-brief' | 'brief-file' | 'protected' | 'ruled' | 'unreadable-protection' | 'in-scope' | 'out-of-scope' | 'held';
15
15
  export interface Decision {
16
16
  /** Repository-relative, or the path as given when it lies outside. */
17
17
  readonly path: string;
@@ -56,3 +56,22 @@ export declare function rooted(pattern: string): 'whole' | 'part' | null;
56
56
  export declare function rulingFor(rulings: readonly VerifiedRuling[], path: string): VerifiedRuling | undefined;
57
57
  /** Decides one path. Pure: the caller resolved the path, the brief and the rulings. */
58
58
  export declare function decide(input: GuardInput): Decision;
59
+ /**
60
+ * A path decided as it reads and as the system writes it, where a link has
61
+ * the two name two files (ADR-0005): `read` is the decision of the first,
62
+ * and `written` the input of the second. Which of the two Claude Code's
63
+ * tools write is not on its pages, so the stricter stands and no link makes
64
+ * a protected file read as another; where neither is stricter, the path is
65
+ * decided as it reads, as it was. The written decision is said with the
66
+ * path as it was given, which reads as another file.
67
+ */
68
+ export declare function decideWritten(read: Decision, written: GuardInput): Decision;
69
+ /**
70
+ * A path whose write the hook holds whatever the path is, but where it lies
71
+ * outside every work tree of the repository: what names the brief names
72
+ * none a round can work under, one spec-brief does not list or has
73
+ * archived (ADR-0004). Refused, in the words the hook holds the write with
74
+ * and its next step, so that the server's `check_path` answers the path as
75
+ * the hook decides a write of it (ADR-0008).
76
+ */
77
+ export declare function heldBy(path: string, problem: string): Decision;
package/dist/guard.js CHANGED
@@ -147,4 +147,35 @@ export function decide(input) {
147
147
  : `if the round needs it, say so in ${brief.file} and add it to affectedFiles; the archive reports every file outside the scope`,
148
148
  };
149
149
  }
150
+ /**
151
+ * The verdicts that hold a write, from the least to the most. `allow` holds
152
+ * nothing, and is read below each: `indexOf` has it at -1.
153
+ */
154
+ const STRICTNESS = ['warn', 'ask', 'deny'];
155
+ /**
156
+ * A path decided as it reads and as the system writes it, where a link has
157
+ * the two name two files (ADR-0005): `read` is the decision of the first,
158
+ * and `written` the input of the second. Which of the two Claude Code's
159
+ * tools write is not on its pages, so the stricter stands and no link makes
160
+ * a protected file read as another; where neither is stricter, the path is
161
+ * decided as it reads, as it was. The written decision is said with the
162
+ * path as it was given, which reads as another file.
163
+ */
164
+ export function decideWritten(read, written) {
165
+ const other = decide(written);
166
+ if (STRICTNESS.indexOf(other.verdict) <= STRICTNESS.indexOf(read.verdict))
167
+ return read;
168
+ return { ...other, message: `${written.given} is written to ${other.path} through a link: ${other.message}` };
169
+ }
170
+ /**
171
+ * A path whose write the hook holds whatever the path is, but where it lies
172
+ * outside every work tree of the repository: what names the brief names
173
+ * none a round can work under, one spec-brief does not list or has
174
+ * archived (ADR-0004). Refused, in the words the hook holds the write with
175
+ * and its next step, so that the server's `check_path` answers the path as
176
+ * the hook decides a write of it (ADR-0008).
177
+ */
178
+ export function heldBy(path, problem) {
179
+ return { path, verdict: 'deny', reason: 'held', because: [], message: problem, hint: 'fix the brief or the branch before writing' };
180
+ }
150
181
  //# sourceMappingURL=guard.js.map
package/dist/guard.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAmC,MAAM,qCAAqC,CAAC;AA8CnH,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC/F,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe;IACpC,IAAI,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACtD,yEAAyE;IACzE,gDAAgD;IAChD,MAA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MAAM,KAAK,GAAG,KAAK,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,UAAU,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC1H,OAAO;QACL,IAAI;QACJ,OAAO;QACP,MAAM,EAAE,cAAc;QACtB,OAAO,EAAE,YAAY,CAAC,UAAU;QAChC,OAAO,EAAE,GAAG,IAAI,qBAAqB,KAAK,CAAC,EAAE,mBAAmB,KAAK,EAAE;QACvE,IAAI,EACF,OAAO,KAAK,MAAM;YAChB,CAAC,CAAC,8BAA8B,KAAK,CAAC,IAAI,4FAA4F,QAAQ,EAAE;YAChJ,CAAC,CAAC,oCAAoC,KAAK,CAAC,IAAI,gFAAgF;KACrI,CAAC;AACJ,CAAC","sourcesContent":["/**\n * May this round write this file?\n *\n * The answer is read from the brief the round runs under: `protectedFiles`\n * are refused unless a person has ruled otherwise, `affectedFiles` are the\n * round's to write, and anything else is outside the scope the person\n * approved. A guard is a guardrail, not a boundary - an agent that writes\n * through a shell passes it - so the audit and spec-brief's archive are the\n * gates, and this is what keeps an honest agent from needing them (ADR-0005).\n */\n\nimport { globAlternatives, parseGlob, type Glob, type GlobAlternative } from './vendor/spec-core/pattern/index.js';\nimport type { OutOfScope } from './config.js';\nimport type { BriefRow } from './types.js';\n\nexport type Verdict = 'allow' | 'warn' | 'ask' | 'deny';\n\nexport type Reason =\n | 'outside-repository'\n | 'no-brief'\n | 'brief-file'\n | 'protected'\n | 'ruled'\n | 'unreadable-protection'\n | 'in-scope'\n | 'out-of-scope';\n\nexport interface Decision {\n /** Repository-relative, or the path as given when it lies outside. */\n readonly path: string;\n readonly verdict: Verdict;\n readonly reason: Reason;\n /** The patterns or ruling that decided it. */\n readonly because: readonly string[];\n readonly message: string;\n readonly hint: string;\n}\n\n/** A ruling whose signature has been verified: a person allowed these paths. */\nexport interface VerifiedRuling {\n readonly id: string;\n readonly paths: readonly string[];\n readonly signer: string;\n}\n\nexport interface GuardInput {\n /** Repository-relative POSIX path, or `null` for a path outside the repository. */\n readonly path: string | null;\n /** The path as the caller gave it, for messages. */\n readonly given: string;\n readonly brief: BriefRow | null;\n /** Why there is no brief, when there is none. */\n readonly noBrief?: string | undefined;\n readonly rulings: readonly VerifiedRuling[];\n readonly outOfScope: OutOfScope;\n}\n\nfunction compile(pattern: string): Glob | string {\n const parsed = parseGlob(pattern, { dialect: 'path', caseSensitive: true, literal: 'either' });\n return parsed.ok ? parsed.glob : parsed.error;\n}\n\n/**\n * Why the guard cannot read a pattern, in spec-core's words; `null` when it\n * can. The guard matches no path by a pattern it cannot read.\n */\nexport function whyUnreadable(pattern: string): string | null {\n const glob = compile(pattern);\n return typeof glob === 'string' ? glob : null;\n}\n\n/**\n * Whether a leading `/` roots a pattern the guard can read at the\n * filesystem's root: `whole` when every alternative is rooted, `part` when\n * some brace alternative is, `null` when none is or the pattern cannot be\n * read. The guard decides repository-relative paths, so a rooted\n * alternative matches none of them.\n */\nexport function rooted(pattern: string): 'whole' | 'part' | null {\n if (typeof compile(pattern) === 'string') return null;\n // spec-core refuses here only what its compile refuses, so a pattern the\n // guard reads always has its alternatives read.\n const { alternatives } = globAlternatives(pattern) as { readonly alternatives: readonly GlobAlternative[] };\n const roots = alternatives.filter((alternative) => alternative.rooted).length;\n if (roots === 0) return null;\n return roots === alternatives.length ? 'whole' : 'part';\n}\n\nfunction matching(patterns: readonly string[], path: string): { matched: string[]; unreadable: string[] } {\n const matched: string[] = [];\n const unreadable: string[] = [];\n for (const pattern of patterns) {\n const glob = compile(pattern);\n if (typeof glob === 'string') unreadable.push(`${pattern} (${glob})`);\n else if (glob.match(path)) matched.push(pattern);\n }\n return { matched, unreadable };\n}\n\n/** The first verified ruling whose paths cover `path`, read as the guard reads a scope. */\nexport function rulingFor(rulings: readonly VerifiedRuling[], path: string): VerifiedRuling | undefined {\n return rulings.find((candidate) => matching(candidate.paths, path).matched.length > 0);\n}\n\nconst ESCALATE =\n 'if the round cannot be done without it, stop and ask for a ruling: spec-harness escalate --path <file> --reason <why>, or the request_escalation tool';\n\n/** Decides one path. Pure: the caller resolved the path, the brief and the rulings. */\nexport function decide(input: GuardInput): Decision {\n const { path, given, brief } = input;\n if (path === null) {\n return {\n path: given,\n verdict: 'allow',\n reason: 'outside-repository',\n because: [],\n message: `${given} is outside the repository; no brief governs it`,\n hint: 'nothing to do',\n };\n }\n if (brief === null) {\n return {\n path,\n verdict: 'allow',\n reason: 'no-brief',\n because: [],\n message: `no brief governs ${path}: ${input.noBrief ?? 'no active brief'}`,\n hint: 'name the brief this work belongs to, so its scope can be checked',\n };\n }\n if (path === brief.file) {\n return {\n path,\n verdict: 'allow',\n reason: 'brief-file',\n because: [],\n message: `${path} is brief ${brief.id} itself`,\n hint: 'tick or disposition its boxes as the work lands',\n };\n }\n\n const protectedHits = matching(brief.protectedFiles, path);\n if (protectedHits.unreadable.length > 0) {\n // A protection that cannot be read cannot be honoured, and cannot be\n // assumed not to apply: refuse until the brief is fixed.\n return {\n path,\n verdict: 'deny',\n reason: 'unreadable-protection',\n because: protectedHits.unreadable,\n message: `brief ${brief.id} protects files with a pattern that cannot be read: ${protectedHits.unreadable.join('; ')}`,\n hint: `fix protectedFiles in ${brief.file} (spec-brief lint names the problem)`,\n };\n }\n if (protectedHits.matched.length > 0) {\n const ruling = rulingFor(input.rulings, path);\n if (ruling !== undefined) {\n return {\n path,\n verdict: 'allow',\n reason: 'ruled',\n because: [ruling.id],\n message: `${path} is protected by brief ${brief.id}, and ruling ${ruling.id}, signed by ${ruling.signer}, allows it`,\n hint: 'keep the change to what the ruling allows',\n };\n }\n return {\n path,\n verdict: 'deny',\n reason: 'protected',\n because: protectedHits.matched,\n message: `brief ${brief.id} does not empower this round to change ${path} (protectedFiles: ${protectedHits.matched.join(', ')})`,\n hint: ESCALATE,\n };\n }\n\n const affectedHits = matching(brief.affectedFiles, path);\n if (affectedHits.matched.length > 0) {\n return {\n path,\n verdict: 'allow',\n reason: 'in-scope',\n because: affectedHits.matched,\n message: `${path} is in brief ${brief.id}'s scope (${affectedHits.matched.join(', ')})`,\n hint: 'nothing to do',\n };\n }\n\n const verdict: Verdict = input.outOfScope;\n const scope = brief.affectedFiles.length === 0 ? 'declares no affectedFiles' : `covers ${brief.affectedFiles.join(', ')}`;\n return {\n path,\n verdict,\n reason: 'out-of-scope',\n because: affectedHits.unreadable,\n message: `${path} is outside brief ${brief.id}'s scope, which ${scope}`,\n hint:\n verdict === 'deny'\n ? `add it to affectedFiles in ${brief.file} if the round needs it, which is a change the person who approved the brief must see; or ${ESCALATE}`\n : `if the round needs it, say so in ${brief.file} and add it to affectedFiles; the archive reports every file outside the scope`,\n };\n}\n"]}
1
+ {"version":3,"file":"guard.js","sourceRoot":"","sources":["../src/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAmC,MAAM,qCAAqC,CAAC;AA+CnH,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC/F,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe;IACpC,IAAI,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,IAA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AE,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,4CAA4C,EAAE,CAAC;AACtI,CAAC","sourcesContent":["/**\n * May this round write this file?\n *\n * The answer is read from the brief the round runs under: `protectedFiles`\n * are refused unless a person has ruled otherwise, `affectedFiles` are the\n * round's to write, and anything else is outside the scope the person\n * approved. A guard is a guardrail, not a boundary - an agent that writes\n * through a shell passes it - so the audit and spec-brief's archive are the\n * gates, and this is what keeps an honest agent from needing them (ADR-0005).\n */\n\nimport { globAlternatives, parseGlob, type Glob, type GlobAlternative } from './vendor/spec-core/pattern/index.js';\nimport type { OutOfScope } from './config.js';\nimport type { BriefRow } from './types.js';\n\nexport type Verdict = 'allow' | 'warn' | 'ask' | 'deny';\n\nexport type Reason =\n | 'outside-repository'\n | 'no-brief'\n | 'brief-file'\n | 'protected'\n | 'ruled'\n | 'unreadable-protection'\n | 'in-scope'\n | 'out-of-scope'\n | 'held';\n\nexport interface Decision {\n /** Repository-relative, or the path as given when it lies outside. */\n readonly path: string;\n readonly verdict: Verdict;\n readonly reason: Reason;\n /** The patterns or ruling that decided it. */\n readonly because: readonly string[];\n readonly message: string;\n readonly hint: string;\n}\n\n/** A ruling whose signature has been verified: a person allowed these paths. */\nexport interface VerifiedRuling {\n readonly id: string;\n readonly paths: readonly string[];\n readonly signer: string;\n}\n\nexport interface GuardInput {\n /** Repository-relative POSIX path, or `null` for a path outside the repository. */\n readonly path: string | null;\n /** The path as the caller gave it, for messages. */\n readonly given: string;\n readonly brief: BriefRow | null;\n /** Why there is no brief, when there is none. */\n readonly noBrief?: string | undefined;\n readonly rulings: readonly VerifiedRuling[];\n readonly outOfScope: OutOfScope;\n}\n\nfunction compile(pattern: string): Glob | string {\n const parsed = parseGlob(pattern, { dialect: 'path', caseSensitive: true, literal: 'either' });\n return parsed.ok ? parsed.glob : parsed.error;\n}\n\n/**\n * Why the guard cannot read a pattern, in spec-core's words; `null` when it\n * can. The guard matches no path by a pattern it cannot read.\n */\nexport function whyUnreadable(pattern: string): string | null {\n const glob = compile(pattern);\n return typeof glob === 'string' ? glob : null;\n}\n\n/**\n * Whether a leading `/` roots a pattern the guard can read at the\n * filesystem's root: `whole` when every alternative is rooted, `part` when\n * some brace alternative is, `null` when none is or the pattern cannot be\n * read. The guard decides repository-relative paths, so a rooted\n * alternative matches none of them.\n */\nexport function rooted(pattern: string): 'whole' | 'part' | null {\n if (typeof compile(pattern) === 'string') return null;\n // spec-core refuses here only what its compile refuses, so a pattern the\n // guard reads always has its alternatives read.\n const { alternatives } = globAlternatives(pattern) as { readonly alternatives: readonly GlobAlternative[] };\n const roots = alternatives.filter((alternative) => alternative.rooted).length;\n if (roots === 0) return null;\n return roots === alternatives.length ? 'whole' : 'part';\n}\n\nfunction matching(patterns: readonly string[], path: string): { matched: string[]; unreadable: string[] } {\n const matched: string[] = [];\n const unreadable: string[] = [];\n for (const pattern of patterns) {\n const glob = compile(pattern);\n if (typeof glob === 'string') unreadable.push(`${pattern} (${glob})`);\n else if (glob.match(path)) matched.push(pattern);\n }\n return { matched, unreadable };\n}\n\n/** The first verified ruling whose paths cover `path`, read as the guard reads a scope. */\nexport function rulingFor(rulings: readonly VerifiedRuling[], path: string): VerifiedRuling | undefined {\n return rulings.find((candidate) => matching(candidate.paths, path).matched.length > 0);\n}\n\nconst ESCALATE =\n 'if the round cannot be done without it, stop and ask for a ruling: spec-harness escalate --path <file> --reason <why>, or the request_escalation tool';\n\n/** Decides one path. Pure: the caller resolved the path, the brief and the rulings. */\nexport function decide(input: GuardInput): Decision {\n const { path, given, brief } = input;\n if (path === null) {\n return {\n path: given,\n verdict: 'allow',\n reason: 'outside-repository',\n because: [],\n message: `${given} is outside the repository; no brief governs it`,\n hint: 'nothing to do',\n };\n }\n if (brief === null) {\n return {\n path,\n verdict: 'allow',\n reason: 'no-brief',\n because: [],\n message: `no brief governs ${path}: ${input.noBrief ?? 'no active brief'}`,\n hint: 'name the brief this work belongs to, so its scope can be checked',\n };\n }\n if (path === brief.file) {\n return {\n path,\n verdict: 'allow',\n reason: 'brief-file',\n because: [],\n message: `${path} is brief ${brief.id} itself`,\n hint: 'tick or disposition its boxes as the work lands',\n };\n }\n\n const protectedHits = matching(brief.protectedFiles, path);\n if (protectedHits.unreadable.length > 0) {\n // A protection that cannot be read cannot be honoured, and cannot be\n // assumed not to apply: refuse until the brief is fixed.\n return {\n path,\n verdict: 'deny',\n reason: 'unreadable-protection',\n because: protectedHits.unreadable,\n message: `brief ${brief.id} protects files with a pattern that cannot be read: ${protectedHits.unreadable.join('; ')}`,\n hint: `fix protectedFiles in ${brief.file} (spec-brief lint names the problem)`,\n };\n }\n if (protectedHits.matched.length > 0) {\n const ruling = rulingFor(input.rulings, path);\n if (ruling !== undefined) {\n return {\n path,\n verdict: 'allow',\n reason: 'ruled',\n because: [ruling.id],\n message: `${path} is protected by brief ${brief.id}, and ruling ${ruling.id}, signed by ${ruling.signer}, allows it`,\n hint: 'keep the change to what the ruling allows',\n };\n }\n return {\n path,\n verdict: 'deny',\n reason: 'protected',\n because: protectedHits.matched,\n message: `brief ${brief.id} does not empower this round to change ${path} (protectedFiles: ${protectedHits.matched.join(', ')})`,\n hint: ESCALATE,\n };\n }\n\n const affectedHits = matching(brief.affectedFiles, path);\n if (affectedHits.matched.length > 0) {\n return {\n path,\n verdict: 'allow',\n reason: 'in-scope',\n because: affectedHits.matched,\n message: `${path} is in brief ${brief.id}'s scope (${affectedHits.matched.join(', ')})`,\n hint: 'nothing to do',\n };\n }\n\n const verdict: Verdict = input.outOfScope;\n const scope = brief.affectedFiles.length === 0 ? 'declares no affectedFiles' : `covers ${brief.affectedFiles.join(', ')}`;\n return {\n path,\n verdict,\n reason: 'out-of-scope',\n because: affectedHits.unreadable,\n message: `${path} is outside brief ${brief.id}'s scope, which ${scope}`,\n hint:\n verdict === 'deny'\n ? `add it to affectedFiles in ${brief.file} if the round needs it, which is a change the person who approved the brief must see; or ${ESCALATE}`\n : `if the round needs it, say so in ${brief.file} and add it to affectedFiles; the archive reports every file outside the scope`,\n };\n}\n\n/**\n * The verdicts that hold a write, from the least to the most. `allow` holds\n * nothing, and is read below each: `indexOf` has it at -1.\n */\nconst STRICTNESS: readonly Verdict[] = ['warn', 'ask', 'deny'];\n\n/**\n * A path decided as it reads and as the system writes it, where a link has\n * the two name two files (ADR-0005): `read` is the decision of the first,\n * and `written` the input of the second. Which of the two Claude Code's\n * tools write is not on its pages, so the stricter stands and no link makes\n * a protected file read as another; where neither is stricter, the path is\n * decided as it reads, as it was. The written decision is said with the\n * path as it was given, which reads as another file.\n */\nexport function decideWritten(read: Decision, written: GuardInput): Decision {\n const other = decide(written);\n if (STRICTNESS.indexOf(other.verdict) <= STRICTNESS.indexOf(read.verdict)) return read;\n return { ...other, message: `${written.given} is written to ${other.path} through a link: ${other.message}` };\n}\n\n/**\n * A path whose write the hook holds whatever the path is, but where it lies\n * outside every work tree of the repository: what names the brief names\n * none a round can work under, one spec-brief does not list or has\n * archived (ADR-0004). Refused, in the words the hook holds the write with\n * and its next step, so that the server's `check_path` answers the path as\n * the hook decides a write of it (ADR-0008).\n */\nexport function heldBy(path: string, problem: string): Decision {\n return { path, verdict: 'deny', reason: 'held', because: [], message: problem, hint: 'fix the brief or the branch before writing' };\n}\n"]}
package/dist/hooks.d.ts CHANGED
@@ -56,6 +56,20 @@ export declare const SESSION_START = "SessionStart";
56
56
  * for it (ADR-0005). No tool is named.
57
57
  */
58
58
  export declare const TURN_END = "Stop";
59
+ /**
60
+ * How long a run of Claude Code's hook is given, every process it starts
61
+ * together (ADR-0002). Claude Code's hooks reference (Timeouts and Common
62
+ * fields, read 2026-10-24) has a command hook cancelled at its entry's
63
+ * `timeout`, 600 seconds where the entry gives none, and a PreToolUse hook
64
+ * it cancels blocks no tool call; init and the plugin give the entry 60.
65
+ * Each process asked a question keeps its 20 seconds (`ANSWER_MS`,
66
+ * git.ts), but several that answer slowly, none of them at that, passed the
67
+ * minute, and the write went ahead. So a run has this, from when the hook
68
+ * begins its work, and a process is given no more of it than is left;
69
+ * Node's start and the reading of the question, before it, are inside the
70
+ * margin to the minute.
71
+ */
72
+ export declare const HOOK_BUDGET_MS = 45000;
59
73
  /** Reads a Claude Code hook's stdin, or says why it cannot. */
60
74
  export declare function parseClaudeHook(raw: string): HookRequest | {
61
75
  readonly error: string;
package/dist/hooks.js CHANGED
@@ -48,6 +48,20 @@ export const SESSION_START = 'SessionStart';
48
48
  * for it (ADR-0005). No tool is named.
49
49
  */
50
50
  export const TURN_END = 'Stop';
51
+ /**
52
+ * How long a run of Claude Code's hook is given, every process it starts
53
+ * together (ADR-0002). Claude Code's hooks reference (Timeouts and Common
54
+ * fields, read 2026-10-24) has a command hook cancelled at its entry's
55
+ * `timeout`, 600 seconds where the entry gives none, and a PreToolUse hook
56
+ * it cancels blocks no tool call; init and the plugin give the entry 60.
57
+ * Each process asked a question keeps its 20 seconds (`ANSWER_MS`,
58
+ * git.ts), but several that answer slowly, none of them at that, passed the
59
+ * minute, and the write went ahead. So a run has this, from when the hook
60
+ * begins its work, and a process is given no more of it than is left;
61
+ * Node's start and the reading of the question, before it, are inside the
62
+ * margin to the minute.
63
+ */
64
+ export const HOOK_BUDGET_MS = 45_000;
51
65
  /** The events that name no tool, which the hook answers of the session and not of a write. */
52
66
  const NO_TOOL = [SESSION_START, TURN_END];
53
67
  /** Reads a Claude Code hook's stdin, or says why it cannot. */
package/dist/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;AAE/F;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;AAEnF,MAAM,WAAW,GAAsB,CAAC,WAAW,EAAE,MA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AC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpG,CAAC","sourcesContent":["/**\n * The guard, spoken in the languages that ask it: an agent's pre- and\n * post-tool hooks, and git's pre-commit.\n *\n * Claude Code sends a hook one JSON object on stdin naming the tool and its\n * input. A file-editing tool names its file under `file_path`, `path` or\n * `notebook_path` depending on the tool and the release; all three are read,\n * because a guard that missed a renamed field would allow everything.\n *\n * What the answer may not do matters as much as what it does. Returning\n * `allow` from a pre-tool hook skips the person's own permission prompt, so\n * the guard never says `allow`: it says `deny`, or `ask`, or nothing. A\n * warning - a write outside the scope when the repository asked only to be\n * warned - is told to the model after the write, through the post-tool hook's\n * additional context, where it cannot unlock anything.\n */\n\nimport type { Decision } from './guard.js';\n\n/**\n * The tools whose input names a file they write, by every name a release of\n * Claude Code has had for one. The hook reads a path from each: a name more\n * costs nothing, and a Claude Code that still has the tool may send it.\n */\nexport const WRITING_TOOLS: readonly string[] = ['Edit', 'Write', 'MultiEdit', 'NotebookEdit'];\n\n/**\n * Those of them a Claude Code the harness runs under can call\n * (`CLAUDE_CODE_MINIMUM`, versions.ts). Its tools reference\n * (https://code.claude.com/docs/en/tools-reference, read 2026-10-12) has\n * `Edit`, `Write` and `NotebookEdit` in its table of tools, and no\n * `MultiEdit`, which its permissions page calls a legacy tool; and the tool\n * inputs each release declares hold a `MultiEdit` up to 1.0.128 and none\n * from 2.0.0 on (ADR-0005). So what doctor and init say of the writes a\n * line is started for names these alone: a tool nobody can call leaves no\n * write unchecked.\n */\nexport const CALLABLE_TOOLS: readonly string[] = ['Edit', 'Write', 'NotebookEdit'];\n\nconst PATH_FIELDS: readonly string[] = ['file_path', 'path', 'notebook_path'];\n\nexport interface HookRequest {\n readonly event: string;\n readonly tool: string;\n /** The session's working directory, when the hook says. */\n readonly cwd: string | null;\n /** Files the tool writes, as the tool named them - absolute, usually. */\n readonly paths: readonly string[];\n /** The session and the tool call the question is about, when it says: `session_id` and `tool_use_id`. */\n readonly session: string | null;\n readonly call: string | null;\n}\n\ntype Json = Record<string, unknown>;\n\nfunction isObject(value: unknown): value is Json {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * The event Claude Code runs as a session starts, resumes, is cleared or\n * compacted, or is forked: no tool is named, and the hook checks what every\n * write of the session will need (ADR-0005).\n */\nexport const SESSION_START = 'SessionStart';\n\n/**\n * The event Claude Code runs as its main agent finishes a turn, under which\n * the hook reports what the work tree holds, where the configuration asks\n * for it (ADR-0005). No tool is named.\n */\nexport const TURN_END = 'Stop';\n\n/** The events that name no tool, which the hook answers of the session and not of a write. */\nconst NO_TOOL: readonly string[] = [SESSION_START, TURN_END];\n\n/** Reads a Claude Code hook's stdin, or says why it cannot. */\nexport function parseClaudeHook(raw: string): HookRequest | { readonly error: string } {\n let value: unknown;\n try {\n value = JSON.parse(raw);\n } catch {\n return { error: 'the hook input is not JSON' };\n }\n if (!isObject(value)) return { error: 'the hook input is not a JSON object' };\n const event = value['hook_event_name'];\n const tool = value['tool_name'];\n if (typeof event !== 'string' || (typeof tool !== 'string' && !NO_TOOL.includes(event))) return { error: 'the hook input names no event or tool' };\n // A session's start and a turn's end name no tool, and are read as naming none.\n const named = typeof tool === 'string' ? tool : '';\n const input = isObject(value['tool_input']) ? value['tool_input'] : {};\n const paths: string[] = [];\n if (WRITING_TOOLS.includes(named)) {\n for (const field of PATH_FIELDS) {\n const path = input[field];\n if (typeof path === 'string' && path !== '' && !paths.includes(path)) paths.push(path);\n }\n }\n const text = (field: string): string | null => {\n const found = value[field];\n return typeof found === 'string' ? found : null;\n };\n return { event, tool: named, cwd: text('cwd'), paths, session: text('session_id'), call: text('tool_use_id') };\n}\n\n/**\n * The answer as a session starts: what would hold every write of it, in\n * one line, for the person as `systemMessage` and for Claude as\n * `additionalContext`; or nothing, where all is well. Always exit 0: the\n * event cannot block, and a check that fails must not keep a session from\n * starting.\n */\nexport function sessionResponse(problem: string | null): HookResponse {\n if (problem === null) return NONE;\n const said = `spec-harness: ${problem}`;\n return { stdout: `${JSON.stringify({ systemMessage: said, hookSpecificOutput: { hookEventName: SESSION_START, additionalContext: said } })}\\n`, exitCode: 0 };\n}\n\n/**\n * The answer as a turn ends: the report, in one `systemMessage`, or\n * nothing, where there is nothing to report. Always exit 0, and never a\n * field that has Claude go on: `decision`, `additionalContext` and exit 2\n * each continue the turn under Stop, and `continue: false` would stop one\n * another hook continues. Claude Code shows a `systemMessage` to the person\n * from an entry it waits on, and hands it to Claude on the next turn from\n * one it runs in the background, as `init` writes it (ADR-0005, ADR-0012).\n */\nexport function turnResponse(report: string | null): HookResponse {\n if (report === null) return NONE;\n return { stdout: `${JSON.stringify({ systemMessage: report })}\\n`, exitCode: 0 };\n}\n\nexport interface HookResponse {\n /** What to print on stdout: JSON, or nothing. */\n readonly stdout: string;\n readonly exitCode: number;\n}\n\n/**\n * The answer before the one write a configuration that does not load lets\n * through, a write to the configuration file itself: no decision, so that\n * the person's own permission prompt stands as for any write the guard\n * passes, and the line that says why every other write is held, for the\n * person as `systemMessage` and for Claude as `additionalContext`, which\n * Claude Code's hooks reference has a PreToolUse hook's answer carry\n * (ADR-0005). Exit 0.\n */\nexport function mendResponse(said: string): HookResponse {\n const line = `spec-harness: ${said}`;\n return { stdout: `${JSON.stringify({ systemMessage: line, hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: line } })}\\n`, exitCode: 0 };\n}\n\n/** The answer that says nothing and decides nothing: the write goes on as the person's own permissions have it. */\nexport const NONE: HookResponse = { stdout: '', exitCode: 0 };\n\n/**\n * The answer where the hook checks nothing and says so, a question it cannot\n * read or a line of its own that turns the guard off: one line, as\n * `systemMessage`, which Claude Code's hooks reference has shown to the\n * person on every event the hook answers, and exit 0. It decides nothing,\n * so the call goes on as it would without the hook. It was exit 1, which\n * the reference counts as a hook that failed: under `onFailure: \"block\"`,\n * which holds the call of a hook that cannot start, it held every write of\n * a session for a line only a write can mend (ADR-0005).\n */\nexport function warningResponse(said: string): HookResponse {\n return { stdout: `${JSON.stringify({ systemMessage: `spec-harness: ${said}` })}\\n`, exitCode: 0 };\n}\n\nfunction reasonOf(decisions: readonly Warning[]): string {\n return decisions.map((decision) => `spec-harness: ${decision.message}. Next: ${decision.hint}.`).join('\\n');\n}\n\n/** What a warning after a write says: a decision's message and its next step. */\nexport type Warning = Pick<Decision, 'message' | 'hint'>;\n\n/** The answer after a write: the warnings, as additional context for the model, or nothing. */\nexport function afterResponse(warnings: readonly Warning[]): HookResponse {\n if (warnings.length === 0) return NONE;\n return {\n stdout: `${JSON.stringify({\n hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: reasonOf(warnings) },\n })}\\n`,\n exitCode: 0,\n };\n}\n\n/**\n * The answer to a Claude Code hook: a refusal or a question before a write,\n * a warning after one, or nothing.\n */\nexport function claudeResponse(event: string, decisions: readonly Decision[]): HookResponse {\n if (event === 'PreToolUse') {\n const denied = decisions.filter((decision) => decision.verdict === 'deny');\n const asked = decisions.filter((decision) => decision.verdict === 'ask');\n const decided = denied.length > 0 ? { verdict: 'deny', list: denied } : asked.length > 0 ? { verdict: 'ask', list: asked } : null;\n if (decided === null) return NONE;\n return {\n stdout: `${JSON.stringify({\n hookSpecificOutput: {\n hookEventName: 'PreToolUse',\n permissionDecision: decided.verdict,\n permissionDecisionReason: reasonOf(decided.list),\n },\n })}\\n`,\n exitCode: 0,\n };\n }\n if (event === 'PostToolUse') return afterResponse(warningsOf(decisions));\n return NONE;\n}\n\n/** The decisions a run after the write would say: those that warn, each by its message and next step. */\nexport function warningsOf(decisions: readonly Decision[]): Warning[] {\n return decisions.filter((decision) => decision.verdict === 'warn').map(({ message, hint }) => ({ message, hint }));\n}\n\n/**\n * What the hook reads besides its question and its line, as it decides: the\n * project Claude Code names, the brief the environment names, and the\n * branch a forge's CI names on a detached head (ADR-0004).\n */\nexport const CALL_VARIABLES: readonly string[] = [\n 'CLAUDE_PROJECT_DIR',\n 'SPEC_BRIEF',\n 'GITHUB_HEAD_REF',\n 'GITHUB_REF_TYPE',\n 'GITHUB_REF_NAME',\n 'CI_MERGE_REQUEST_SOURCE_BRANCH_NAME',\n 'CI_COMMIT_BRANCH',\n];\n\n/**\n * A tool call, as both of its hooks see it: the release, the session and\n * the call, the tool and its paths, the session's directory, what the\n * hook's line gives, the directory the hook was started in, and the\n * variables it reads (ADR-0002). What a run before the write keeps is\n * answered after it only to a run for which all of it is the same.\n */\nexport interface CallRecord {\n readonly release: string;\n readonly session: string;\n readonly call: string;\n readonly tool: string;\n readonly paths: readonly string[];\n readonly cwd: string | null;\n readonly line: readonly (string | null)[];\n readonly started: string;\n readonly env: readonly (string | null)[];\n}\n\n/** An id the hook names a file by: what Claude Code's ids are made of, and nothing a path could climb out by. */\nconst ID = /^[\\w-]{1,256}$/;\n\n/**\n * The session a question is in, which spec-brief's answers are kept for,\n * or `null` where it names none in the form Claude Code's ids have: such a\n * question has every answer asked for afresh (ADR-0002).\n */\nexport function sessionOf(request: HookRequest): string | null {\n // The pattern reads null as \"null\", and what is answered is the session,\n // null: the test of null is the compiler's, and its mutant equivalent.\n return request.session !== null && ID.test(request.session) ? request.session : null;\n}\n\n/**\n * The call a question is about, or `null` where it does not say which\n * session and call it is, or says it in a form no file is named by.\n */\nexport function callRecord(\n request: HookRequest,\n line: Readonly<{ root: string | undefined; brief: string | undefined; base: string | undefined }>,\n started: string,\n env: Readonly<Record<string, string | undefined>>,\n release: string,\n): CallRecord | null {\n const { session, call } = request;\n if (session === null || call === null || !ID.test(session) || !ID.test(call)) return null;\n return {\n release,\n session,\n call,\n tool: request.tool,\n paths: request.paths,\n cwd: request.cwd,\n line: [line.root ?? null, line.brief ?? null, line.base ?? null],\n started,\n env: CALL_VARIABLES.map((name) => env[name] ?? null),\n };\n}\n\n/** The name of the file a call's decisions are kept under. */\nexport function callFile(record: CallRecord): string {\n return `${record.session}.${record.call}.json`;\n}\n\n/** What a run before the write keeps for the run after it: the call, and the warnings it decided. */\nexport function keptCall(record: CallRecord, warnings: readonly Warning[]): string {\n return `${JSON.stringify({ record, warnings })}\\n`;\n}\n\nfunction isWarning(value: unknown): value is Warning {\n return isObject(value) && typeof value['message'] === 'string' && typeof value['hint'] === 'string';\n}\n\n/**\n * The warnings kept for this call, or `null` where what was kept is not\n * JSON, is another call's, or holds anything but warnings: such a call is\n * decided as it was before anything was kept (ADR-0002).\n */\nexport function warningsKept(text: string, record: CallRecord): Warning[] | null {\n let value: unknown;\n try {\n value = JSON.parse(text);\n } catch {\n // Read as an empty object, a text that is not JSON holds no record\n // either: that mutant is equivalent.\n return null;\n }\n if (!isObject(value) || JSON.stringify(value['record']) !== JSON.stringify(record)) return null;\n const warnings = value['warnings'];\n return Array.isArray(warnings) && warnings.every(isWarning) ? warnings.map(({ message, hint }) => ({ message, hint })) : null;\n}\n\n/**\n * The answer to git's pre-commit hook: every file the commit would change\n * that the round may not, and exit 1 if any is refused. A warning prints and\n * lets the commit through; a question has no one to ask in git, so it refuses.\n */\nexport function gitResponse(decisions: readonly Decision[]): { readonly text: string; readonly exitCode: number } {\n const lines: string[] = [];\n let refused = 0;\n for (const decision of decisions) {\n if (decision.verdict === 'allow') continue;\n const blocking = decision.verdict === 'deny' || decision.verdict === 'ask';\n if (blocking) refused += 1;\n lines.push(`${blocking ? 'refused' : 'warning'} ${decision.message}`, ` ${decision.hint}`);\n }\n if (refused > 0) lines.push(`spec-harness: ${refused} file(s) this round may not change; the commit was stopped`);\n return { text: lines.length === 0 ? '' : `${lines.join('\\n')}\\n`, exitCode: refused > 0 ? 1 : 0 };\n}\n"]}
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC;AAE/F;;;;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CAAC;IACD,IAAI,OAAO,GAAG,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,OAAO,4DAA4D,CAAC,CAAC;IAClH,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpG,CAAC","sourcesContent":["/**\n * The guard, spoken in the languages that ask it: an agent's pre- and\n * post-tool hooks, and git's pre-commit.\n *\n * Claude Code sends a hook one JSON object on stdin naming the tool and its\n * input. A file-editing tool names its file under `file_path`, `path` or\n * `notebook_path` depending on the tool and the release; all three are read,\n * because a guard that missed a renamed field would allow everything.\n *\n * What the answer may not do matters as much as what it does. Returning\n * `allow` from a pre-tool hook skips the person's own permission prompt, so\n * the guard never says `allow`: it says `deny`, or `ask`, or nothing. A\n * warning - a write outside the scope when the repository asked only to be\n * warned - is told to the model after the write, through the post-tool hook's\n * additional context, where it cannot unlock anything.\n */\n\nimport type { Decision } from './guard.js';\n\n/**\n * The tools whose input names a file they write, by every name a release of\n * Claude Code has had for one. The hook reads a path from each: a name more\n * costs nothing, and a Claude Code that still has the tool may send it.\n */\nexport const WRITING_TOOLS: readonly string[] = ['Edit', 'Write', 'MultiEdit', 'NotebookEdit'];\n\n/**\n * Those of them a Claude Code the harness runs under can call\n * (`CLAUDE_CODE_MINIMUM`, versions.ts). Its tools reference\n * (https://code.claude.com/docs/en/tools-reference, read 2026-10-12) has\n * `Edit`, `Write` and `NotebookEdit` in its table of tools, and no\n * `MultiEdit`, which its permissions page calls a legacy tool; and the tool\n * inputs each release declares hold a `MultiEdit` up to 1.0.128 and none\n * from 2.0.0 on (ADR-0005). So what doctor and init say of the writes a\n * line is started for names these alone: a tool nobody can call leaves no\n * write unchecked.\n */\nexport const CALLABLE_TOOLS: readonly string[] = ['Edit', 'Write', 'NotebookEdit'];\n\nconst PATH_FIELDS: readonly string[] = ['file_path', 'path', 'notebook_path'];\n\nexport interface HookRequest {\n readonly event: string;\n readonly tool: string;\n /** The session's working directory, when the hook says. */\n readonly cwd: string | null;\n /** Files the tool writes, as the tool named them - absolute, usually. */\n readonly paths: readonly string[];\n /** The session and the tool call the question is about, when it says: `session_id` and `tool_use_id`. */\n readonly session: string | null;\n readonly call: string | null;\n}\n\ntype Json = Record<string, unknown>;\n\nfunction isObject(value: unknown): value is Json {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * The event Claude Code runs as a session starts, resumes, is cleared or\n * compacted, or is forked: no tool is named, and the hook checks what every\n * write of the session will need (ADR-0005).\n */\nexport const SESSION_START = 'SessionStart';\n\n/**\n * The event Claude Code runs as its main agent finishes a turn, under which\n * the hook reports what the work tree holds, where the configuration asks\n * for it (ADR-0005). No tool is named.\n */\nexport const TURN_END = 'Stop';\n\n/**\n * How long a run of Claude Code's hook is given, every process it starts\n * together (ADR-0002). Claude Code's hooks reference (Timeouts and Common\n * fields, read 2026-10-24) has a command hook cancelled at its entry's\n * `timeout`, 600 seconds where the entry gives none, and a PreToolUse hook\n * it cancels blocks no tool call; init and the plugin give the entry 60.\n * Each process asked a question keeps its 20 seconds (`ANSWER_MS`,\n * git.ts), but several that answer slowly, none of them at that, passed the\n * minute, and the write went ahead. So a run has this, from when the hook\n * begins its work, and a process is given no more of it than is left;\n * Node's start and the reading of the question, before it, are inside the\n * margin to the minute.\n */\nexport const HOOK_BUDGET_MS = 45_000;\n\n/** The events that name no tool, which the hook answers of the session and not of a write. */\nconst NO_TOOL: readonly string[] = [SESSION_START, TURN_END];\n\n/** Reads a Claude Code hook's stdin, or says why it cannot. */\nexport function parseClaudeHook(raw: string): HookRequest | { readonly error: string } {\n let value: unknown;\n try {\n value = JSON.parse(raw);\n } catch {\n return { error: 'the hook input is not JSON' };\n }\n if (!isObject(value)) return { error: 'the hook input is not a JSON object' };\n const event = value['hook_event_name'];\n const tool = value['tool_name'];\n if (typeof event !== 'string' || (typeof tool !== 'string' && !NO_TOOL.includes(event))) return { error: 'the hook input names no event or tool' };\n // A session's start and a turn's end name no tool, and are read as naming none.\n const named = typeof tool === 'string' ? tool : '';\n const input = isObject(value['tool_input']) ? value['tool_input'] : {};\n const paths: string[] = [];\n if (WRITING_TOOLS.includes(named)) {\n for (const field of PATH_FIELDS) {\n const path = input[field];\n if (typeof path === 'string' && path !== '' && !paths.includes(path)) paths.push(path);\n }\n }\n const text = (field: string): string | null => {\n const found = value[field];\n return typeof found === 'string' ? found : null;\n };\n return { event, tool: named, cwd: text('cwd'), paths, session: text('session_id'), call: text('tool_use_id') };\n}\n\n/**\n * The answer as a session starts: what would hold every write of it, in\n * one line, for the person as `systemMessage` and for Claude as\n * `additionalContext`; or nothing, where all is well. Always exit 0: the\n * event cannot block, and a check that fails must not keep a session from\n * starting.\n */\nexport function sessionResponse(problem: string | null): HookResponse {\n if (problem === null) return NONE;\n const said = `spec-harness: ${problem}`;\n return { stdout: `${JSON.stringify({ systemMessage: said, hookSpecificOutput: { hookEventName: SESSION_START, additionalContext: said } })}\\n`, exitCode: 0 };\n}\n\n/**\n * The answer as a turn ends: the report, in one `systemMessage`, or\n * nothing, where there is nothing to report. Always exit 0, and never a\n * field that has Claude go on: `decision`, `additionalContext` and exit 2\n * each continue the turn under Stop, and `continue: false` would stop one\n * another hook continues. Claude Code shows a `systemMessage` to the person\n * from an entry it waits on, and hands it to Claude on the next turn from\n * one it runs in the background, as `init` writes it (ADR-0005, ADR-0012).\n */\nexport function turnResponse(report: string | null): HookResponse {\n if (report === null) return NONE;\n return { stdout: `${JSON.stringify({ systemMessage: report })}\\n`, exitCode: 0 };\n}\n\nexport interface HookResponse {\n /** What to print on stdout: JSON, or nothing. */\n readonly stdout: string;\n readonly exitCode: number;\n}\n\n/**\n * The answer before the one write a configuration that does not load lets\n * through, a write to the configuration file itself: no decision, so that\n * the person's own permission prompt stands as for any write the guard\n * passes, and the line that says why every other write is held, for the\n * person as `systemMessage` and for Claude as `additionalContext`, which\n * Claude Code's hooks reference has a PreToolUse hook's answer carry\n * (ADR-0005). Exit 0.\n */\nexport function mendResponse(said: string): HookResponse {\n const line = `spec-harness: ${said}`;\n return { stdout: `${JSON.stringify({ systemMessage: line, hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: line } })}\\n`, exitCode: 0 };\n}\n\n/** The answer that says nothing and decides nothing: the write goes on as the person's own permissions have it. */\nexport const NONE: HookResponse = { stdout: '', exitCode: 0 };\n\n/**\n * The answer where the hook checks nothing and says so, a question it cannot\n * read or a line of its own that turns the guard off: one line, as\n * `systemMessage`, which Claude Code's hooks reference has shown to the\n * person on every event the hook answers, and exit 0. It decides nothing,\n * so the call goes on as it would without the hook. It was exit 1, which\n * the reference counts as a hook that failed: under `onFailure: \"block\"`,\n * which holds the call of a hook that cannot start, it held every write of\n * a session for a line only a write can mend (ADR-0005).\n */\nexport function warningResponse(said: string): HookResponse {\n return { stdout: `${JSON.stringify({ systemMessage: `spec-harness: ${said}` })}\\n`, exitCode: 0 };\n}\n\nfunction reasonOf(decisions: readonly Warning[]): string {\n return decisions.map((decision) => `spec-harness: ${decision.message}. Next: ${decision.hint}.`).join('\\n');\n}\n\n/** What a warning after a write says: a decision's message and its next step. */\nexport type Warning = Pick<Decision, 'message' | 'hint'>;\n\n/** The answer after a write: the warnings, as additional context for the model, or nothing. */\nexport function afterResponse(warnings: readonly Warning[]): HookResponse {\n if (warnings.length === 0) return NONE;\n return {\n stdout: `${JSON.stringify({\n hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: reasonOf(warnings) },\n })}\\n`,\n exitCode: 0,\n };\n}\n\n/**\n * The answer to a Claude Code hook: a refusal or a question before a write,\n * a warning after one, or nothing.\n */\nexport function claudeResponse(event: string, decisions: readonly Decision[]): HookResponse {\n if (event === 'PreToolUse') {\n const denied = decisions.filter((decision) => decision.verdict === 'deny');\n const asked = decisions.filter((decision) => decision.verdict === 'ask');\n const decided = denied.length > 0 ? { verdict: 'deny', list: denied } : asked.length > 0 ? { verdict: 'ask', list: asked } : null;\n if (decided === null) return NONE;\n return {\n stdout: `${JSON.stringify({\n hookSpecificOutput: {\n hookEventName: 'PreToolUse',\n permissionDecision: decided.verdict,\n permissionDecisionReason: reasonOf(decided.list),\n },\n })}\\n`,\n exitCode: 0,\n };\n }\n if (event === 'PostToolUse') return afterResponse(warningsOf(decisions));\n return NONE;\n}\n\n/** The decisions a run after the write would say: those that warn, each by its message and next step. */\nexport function warningsOf(decisions: readonly Decision[]): Warning[] {\n return decisions.filter((decision) => decision.verdict === 'warn').map(({ message, hint }) => ({ message, hint }));\n}\n\n/**\n * What the hook reads besides its question and its line, as it decides: the\n * project Claude Code names, the brief the environment names, and the\n * branch a forge's CI names on a detached head (ADR-0004).\n */\nexport const CALL_VARIABLES: readonly string[] = [\n 'CLAUDE_PROJECT_DIR',\n 'SPEC_BRIEF',\n 'GITHUB_HEAD_REF',\n 'GITHUB_REF_TYPE',\n 'GITHUB_REF_NAME',\n 'CI_MERGE_REQUEST_SOURCE_BRANCH_NAME',\n 'CI_COMMIT_BRANCH',\n];\n\n/**\n * A tool call, as both of its hooks see it: the release, the session and\n * the call, the tool and its paths, the session's directory, what the\n * hook's line gives, the directory the hook was started in, and the\n * variables it reads (ADR-0002). What a run before the write keeps is\n * answered after it only to a run for which all of it is the same.\n */\nexport interface CallRecord {\n readonly release: string;\n readonly session: string;\n readonly call: string;\n readonly tool: string;\n readonly paths: readonly string[];\n readonly cwd: string | null;\n readonly line: readonly (string | null)[];\n readonly started: string;\n readonly env: readonly (string | null)[];\n}\n\n/** An id the hook names a file by: what Claude Code's ids are made of, and nothing a path could climb out by. */\nconst ID = /^[\\w-]{1,256}$/;\n\n/**\n * The session a question is in, which spec-brief's answers are kept for,\n * or `null` where it names none in the form Claude Code's ids have: such a\n * question has every answer asked for afresh (ADR-0002).\n */\nexport function sessionOf(request: HookRequest): string | null {\n // The pattern reads null as \"null\", and what is answered is the session,\n // null: the test of null is the compiler's, and its mutant equivalent.\n return request.session !== null && ID.test(request.session) ? request.session : null;\n}\n\n/**\n * The call a question is about, or `null` where it does not say which\n * session and call it is, or says it in a form no file is named by.\n */\nexport function callRecord(\n request: HookRequest,\n line: Readonly<{ root: string | undefined; brief: string | undefined; base: string | undefined }>,\n started: string,\n env: Readonly<Record<string, string | undefined>>,\n release: string,\n): CallRecord | null {\n const { session, call } = request;\n if (session === null || call === null || !ID.test(session) || !ID.test(call)) return null;\n return {\n release,\n session,\n call,\n tool: request.tool,\n paths: request.paths,\n cwd: request.cwd,\n line: [line.root ?? null, line.brief ?? null, line.base ?? null],\n started,\n env: CALL_VARIABLES.map((name) => env[name] ?? null),\n };\n}\n\n/** The name of the file a call's decisions are kept under. */\nexport function callFile(record: CallRecord): string {\n return `${record.session}.${record.call}.json`;\n}\n\n/** What a run before the write keeps for the run after it: the call, and the warnings it decided. */\nexport function keptCall(record: CallRecord, warnings: readonly Warning[]): string {\n return `${JSON.stringify({ record, warnings })}\\n`;\n}\n\nfunction isWarning(value: unknown): value is Warning {\n return isObject(value) && typeof value['message'] === 'string' && typeof value['hint'] === 'string';\n}\n\n/**\n * The warnings kept for this call, or `null` where what was kept is not\n * JSON, is another call's, or holds anything but warnings: such a call is\n * decided as it was before anything was kept (ADR-0002).\n */\nexport function warningsKept(text: string, record: CallRecord): Warning[] | null {\n let value: unknown;\n try {\n value = JSON.parse(text);\n } catch {\n // Read as an empty object, a text that is not JSON holds no record\n // either: that mutant is equivalent.\n return null;\n }\n if (!isObject(value) || JSON.stringify(value['record']) !== JSON.stringify(record)) return null;\n const warnings = value['warnings'];\n return Array.isArray(warnings) && warnings.every(isWarning) ? warnings.map(({ message, hint }) => ({ message, hint })) : null;\n}\n\n/**\n * The answer to git's pre-commit hook: every file the commit would change\n * that the round may not, and exit 1 if any is refused. A warning prints and\n * lets the commit through; a question has no one to ask in git, so it refuses.\n */\nexport function gitResponse(decisions: readonly Decision[]): { readonly text: string; readonly exitCode: number } {\n const lines: string[] = [];\n let refused = 0;\n for (const decision of decisions) {\n if (decision.verdict === 'allow') continue;\n const blocking = decision.verdict === 'deny' || decision.verdict === 'ask';\n if (blocking) refused += 1;\n lines.push(`${blocking ? 'refused' : 'warning'} ${decision.message}`, ` ${decision.hint}`);\n }\n if (refused > 0) lines.push(`spec-harness: ${refused} file(s) this round may not change; the commit was stopped`);\n return { text: lines.length === 0 ? '' : `${lines.join('\\n')}\\n`, exitCode: refused > 0 ? 1 : 0 };\n}\n"]}
package/dist/round.d.ts CHANGED
@@ -120,8 +120,14 @@ export declare function claudeSettings(root: string, env: CliIO['env']): Promise
120
120
  * the release, so it says that it does not report it, and it is asked only
121
121
  * where a line turns on it: where what is read of the lines differs between
122
122
  * a release that cannot be told and the newest.
123
+ *
124
+ * `doctor` also looks for the script each line runs in `places`, each
125
+ * directory `${CLAUDE_PROJECT_DIR}` can name as a session starts, and says
126
+ * a line whose script is in none as a guard that is off (reportHooks).
127
+ * `init` gives none: it writes the line that names the project's install,
128
+ * which may come after it.
123
129
  */
124
- export declare function claudeCodeWiring(root: string, io: CliIO, pattern?: PatternReader, reported?: boolean): Promise<ClaudeCodeWiring>;
130
+ export declare function claudeCodeWiring(root: string, io: CliIO, pattern?: PatternReader, reported?: boolean, places?: readonly string[] | null): Promise<ClaudeCodeWiring>;
125
131
  /**
126
132
  * The brief a round works on, as doctor reports it: its id, and what is
127
133
  * wrong with the name when no round can work under it. Every other command
@@ -134,11 +140,23 @@ export declare function claudeCodeWiring(root: string, io: CliIO, pattern?: Patt
134
140
  * setup that holds every write, as a hook's line naming such a brief is
135
141
  * (ADR-0004). A name the flag gives is the question doctor was asked, and
136
142
  * holds no write of anyone's.
143
+ *
144
+ * `holds` is whether the branch names a brief and spec-brief cannot answer
145
+ * for it: not installed, too old, or failing as it is asked. The hook asks
146
+ * spec-brief before every write under the name, and holds each write it
147
+ * cannot ask about, so that too is a setup that holds every write.
148
+ *
149
+ * `archived` is the brief the branch names where spec-brief has archived
150
+ * it, which doctor reads further in git: the branch that archived it waits
151
+ * to merge, and fails nothing (ADR-0004). It reads nothing else, and the
152
+ * problem is the one every write is held with, as before.
137
153
  */
138
154
  export declare function diagnoseBrief(workspace: Workspace, options: Pick<Options, 'brief'>, env: CliIO['env']): Promise<{
139
155
  readonly id: string | null;
140
156
  readonly problem: string | null;
141
157
  readonly branch: boolean;
158
+ readonly holds: boolean;
159
+ readonly archived: BriefRow | null;
142
160
  }>;
143
161
  export interface AuditResult {
144
162
  readonly brief: BriefRow;