@descent-vtt/spec-harness 0.17.0 → 0.18.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +103 -0
- package/README.md +7 -1
- package/dist/cli.d.ts +15 -1
- package/dist/cli.js +62 -36
- package/dist/cli.js.map +1 -1
- package/dist/commands.js +12 -2
- package/dist/commands.js.map +1 -1
- package/dist/configure.d.ts +90 -6
- package/dist/configure.js +183 -39
- package/dist/configure.js.map +1 -1
- package/dist/fs.d.ts +10 -0
- package/dist/fs.js +14 -0
- package/dist/fs.js.map +1 -1
- package/dist/git.d.ts +31 -0
- package/dist/git.js +38 -0
- package/dist/git.js.map +1 -1
- package/dist/round.d.ts +25 -4
- package/dist/round.js +92 -33
- package/dist/round.js.map +1 -1
- package/dist/setup.d.ts +7 -0
- package/dist/setup.js +57 -12
- package/dist/setup.js.map +1 -1
- package/dist/usage.d.ts +46 -2
- package/dist/usage.js +35 -0
- package/dist/usage.js.map +1 -1
- package/dist/workspace.js +25 -10
- package/dist/workspace.js.map +1 -1
- package/package.json +1 -1
package/dist/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE9E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAsB,MAAM,aAAa,CAAC;AA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meets the disk: the configuration, the state\n * directory outside the work tree, and paths as the filesystem spells them.\n */\n\nimport { existsSync, realpathSync, statSync } from 'node:fs';\nimport { mkdir, readFile, rename, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';\n\nimport { ConfigError, CONFIG_FILE, DEFAULT_CONFIG, parseConfig, type HarnessConfig } from './config.js';\n\n/** Reads `.spec-harness.json` at the root, or the defaults when there is none. */\nexport async function loadConfig(root: string): Promise<{ config: HarnessConfig; file: string | null }> {\n const file = join(root, CONFIG_FILE);\n if (!existsSync(file)) return { config: DEFAULT_CONFIG, file: null };\n let raw: unknown;\n try {\n // A Buffer parses as its text, so the encoding is equivalent to its mutant.\n raw = JSON.parse(await readFile(file, 'utf8'));\n } catch (error) {\n // A directory under the file's name is not JSON that went wrong, and\n // Node's words for it, EISDIR, are not the harness's.\n if ((error as NodeJS.ErrnoException).code === 'EISDIR') throw new ConfigError(`${CONFIG_FILE} is a directory, not a configuration file`);\n throw new ConfigError(`${CONFIG_FILE} is not valid JSON: ${(error as Error).message}`);\n }\n return { config: parseConfig(raw), file };\n}\n\n/**\n * The real spelling of a path: links resolved and, on a filesystem that\n * ignores case, the case the directory entries have. A path that does not\n * exist yet is resolved through its nearest existing ancestor.\n *\n * This is what stops `SRC/db/schema.ts` from walking past a protection on\n * `src/db/schema.ts` on Windows or macOS, where both name one file.\n */\nexport function realSpelling(path: string): string {\n const missing: string[] = [];\n let current = resolve(path);\n for (;;) {\n try {\n // join leaves a real path as it is, and reads a segment's leading\n // separator as the one between it and the last.\n return join(realpathSync.native(current), ...missing.reverse());\n } catch {\n const parent = dirname(current);\n // Only a root that does not exist fails at the top, a drive Windows\n // does not have; everywhere else the loop ends in the try.\n if (parent === current) return resolve(path);\n missing.push(current.slice(parent.length));\n current = parent;\n }\n }\n}\n\n/**\n * A path as the repository names it - relative to the root, POSIX-separated,\n * real spelling - or `null` when it lies outside the root.\n */\nexport function repositoryPath(given: string, root: string, cwd: string): string | null {\n const absolute = isAbsolute(given) ? given : resolve(cwd, given);\n const real = realSpelling(absolute);\n const realRoot = realSpelling(root);\n const rel = relative(realRoot, real);\n // `..env` at the root is inside it; only a `..` segment climbs out.\n if (rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return null;\n return rel.split(sep).join('/');\n}\n\n/** The harness's own directory under the git common directory, created on demand (ADR-0003). */\nexport async function stateDirectory(commonDir: string, ...parts: string[]): Promise<string> {\n const directory = join(commonDir, 'spec-harness', ...parts);\n await mkdir(directory, { recursive: true });\n return directory;\n}\n\n/** Writes a file whole or not at all: a temporary file renamed over the target. */\nexport async function writeAtomic(file: string, content: string): Promise<void> {\n await mkdir(dirname(file), { recursive: true });\n const temporary = `${file}.${process.pid}.tmp`;\n // utf8 is writeFile's own default, so naming it is equivalent to its mutant.\n await writeFile(temporary, content, 'utf8');\n await rename(temporary, file);\n}\n\n/** A JSON object from a file: `null` when there is no file, `'unreadable'` when it holds anything else. */\nexport async function readJsonObject(file: string): Promise<Record<string, unknown> | null | 'unreadable'> {\n if (!existsSync(file)) return null;\n try {\n // A Buffer parses as its text, so the encoding is equivalent to its mutant.\n const value: unknown = JSON.parse(await readFile(file, 'utf8'));\n return typeof value === 'object' && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : 'unreadable';\n } catch {\n return 'unreadable';\n }\n}\n\n/** Whether a path names a directory that is there; one that cannot be read names none. */\nexport function isDirectory(path: string): boolean {\n try {\n return statSync(path).isDirectory();\n } catch {\n // Each caller reads the answer with `!`, so the mutant that answers\n // nothing here is equivalent.\n return false;\n }\n}\n\nexport async function readText(file: string): Promise<string | null> {\n try {\n return await readFile(file, 'utf8');\n } catch {\n return null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D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AO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAiC,CAAC,CAAC,CAAC,YAAY,CAAC;IAClI,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,YAAY,CAAC;IACtB,CAAC;AACH,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,oEAAoE;QACpE,8BAA8B;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAY;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/**\n * The edge where the harness meets the disk: the configuration, the state\n * directory outside the work tree, and paths as the filesystem spells them.\n */\n\nimport { existsSync, realpathSync, statSync } from 'node:fs';\nimport { mkdir, readFile, rename, writeFile } from 'node:fs/promises';\nimport { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';\n\nimport { ConfigError, CONFIG_FILE, DEFAULT_CONFIG, parseConfig, type HarnessConfig } from './config.js';\n\n/** Reads `.spec-harness.json` at the root, or the defaults when there is none. */\nexport async function loadConfig(root: string): Promise<{ config: HarnessConfig; file: string | null }> {\n const file = join(root, CONFIG_FILE);\n if (!existsSync(file)) return { config: DEFAULT_CONFIG, file: null };\n let raw: unknown;\n try {\n // A Buffer parses as its text, so the encoding is equivalent to its mutant.\n raw = JSON.parse(await readFile(file, 'utf8'));\n } catch (error) {\n // A directory under the file's name is not JSON that went wrong, and\n // Node's words for it, EISDIR, are not the harness's.\n if ((error as NodeJS.ErrnoException).code === 'EISDIR') throw new ConfigError(`${CONFIG_FILE} is a directory, not a configuration file`);\n throw new ConfigError(`${CONFIG_FILE} is not valid JSON: ${(error as Error).message}`);\n }\n return { config: parseConfig(raw), file };\n}\n\n/**\n * The real spelling of a path: links resolved and, on a filesystem that\n * ignores case, the case the directory entries have. A path that does not\n * exist yet is resolved through its nearest existing ancestor.\n *\n * This is what stops `SRC/db/schema.ts` from walking past a protection on\n * `src/db/schema.ts` on Windows or macOS, where both name one file.\n */\nexport function realSpelling(path: string): string {\n const missing: string[] = [];\n let current = resolve(path);\n for (;;) {\n try {\n // join leaves a real path as it is, and reads a segment's leading\n // separator as the one between it and the last.\n return join(realpathSync.native(current), ...missing.reverse());\n } catch {\n const parent = dirname(current);\n // Only a root that does not exist fails at the top, a drive Windows\n // does not have; everywhere else the loop ends in the try.\n if (parent === current) return resolve(path);\n missing.push(current.slice(parent.length));\n current = parent;\n }\n }\n}\n\n/**\n * Whether `directory` is the one git names as the top of a work tree: the\n * two spelled alike once the filesystem has spelled the directory, links\n * and short names resolved, as git spells a top. A spelling that differs is\n * read as another directory: what git said from the one is then not taken\n * for what it would say from the other.\n */\nexport function isTop(directory: string, top: string): boolean {\n return realSpelling(directory).split(sep).join('/') === top;\n}\n\n/** Whether a `.git` stands in `directory`, a repository's or the file that names one, as at the top of a work tree. */\nexport function holdsGit(directory: string): boolean {\n return existsSync(join(directory, '.git'));\n}\n\n/**\n * A path as the repository names it - relative to the root, POSIX-separated,\n * real spelling - or `null` when it lies outside the root.\n */\nexport function repositoryPath(given: string, root: string, cwd: string): string | null {\n const absolute = isAbsolute(given) ? given : resolve(cwd, given);\n const real = realSpelling(absolute);\n const realRoot = realSpelling(root);\n const rel = relative(realRoot, real);\n // `..env` at the root is inside it; only a `..` segment climbs out.\n if (rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) return null;\n return rel.split(sep).join('/');\n}\n\n/** The harness's own directory under the git common directory, created on demand (ADR-0003). */\nexport async function stateDirectory(commonDir: string, ...parts: string[]): Promise<string> {\n const directory = join(commonDir, 'spec-harness', ...parts);\n await mkdir(directory, { recursive: true });\n return directory;\n}\n\n/** Writes a file whole or not at all: a temporary file renamed over the target. */\nexport async function writeAtomic(file: string, content: string): Promise<void> {\n await mkdir(dirname(file), { recursive: true });\n const temporary = `${file}.${process.pid}.tmp`;\n // utf8 is writeFile's own default, so naming it is equivalent to its mutant.\n await writeFile(temporary, content, 'utf8');\n await rename(temporary, file);\n}\n\n/** A JSON object from a file: `null` when there is no file, `'unreadable'` when it holds anything else. */\nexport async function readJsonObject(file: string): Promise<Record<string, unknown> | null | 'unreadable'> {\n if (!existsSync(file)) return null;\n try {\n // A Buffer parses as its text, so the encoding is equivalent to its mutant.\n const value: unknown = JSON.parse(await readFile(file, 'utf8'));\n return typeof value === 'object' && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : 'unreadable';\n } catch {\n return 'unreadable';\n }\n}\n\n/** Whether a path names a directory that is there; one that cannot be read names none. */\nexport function isDirectory(path: string): boolean {\n try {\n return statSync(path).isDirectory();\n } catch {\n // Each caller reads the answer with `!`, so the mutant that answers\n // nothing here is equivalent.\n return false;\n }\n}\n\nexport async function readText(file: string): Promise<string | null> {\n try {\n return await readFile(file, 'utf8');\n } catch {\n return null;\n }\n}\n"]}
|
package/dist/git.d.ts
CHANGED
|
@@ -21,6 +21,37 @@ export declare class GitError extends Error {
|
|
|
21
21
|
export declare function workTreeRoot(cwd: string): Promise<string | null>;
|
|
22
22
|
/** The git directory every worktree of this repository shares. */
|
|
23
23
|
export declare function commonDirectory(cwd: string): Promise<string | null>;
|
|
24
|
+
/** A work tree as one start of git names it: its top, and the git directory its worktrees share. */
|
|
25
|
+
export interface WorkTree {
|
|
26
|
+
readonly root: string;
|
|
27
|
+
readonly commonDir: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The top of the work tree holding `cwd` and the common directory, asked of
|
|
31
|
+
* git in one start where {@link workTreeRoot} and {@link commonDirectory}
|
|
32
|
+
* are two: `null` outside a work tree, and `'unread'` where the one answer
|
|
33
|
+
* cannot be taken for the two, which are then to be asked for as they were.
|
|
34
|
+
*
|
|
35
|
+
* Measured with git 2.43 and 2.55, rev-parse answers the two in the order
|
|
36
|
+
* they stand on its line, a line each, and prints nothing where the first
|
|
37
|
+
* fails. Its manual says of that only that `--show-toplevel` reports an
|
|
38
|
+
* error where there is no working tree (git-rev-parse(1), Options for
|
|
39
|
+
* Files, as git 2.55.0 has it, read 2026-10-14), so nothing is read on
|
|
40
|
+
* trust. Two lines that are each what `trim` would leave, from a git that
|
|
41
|
+
* did not fail, are the two answers. Nothing printed, by a git that
|
|
42
|
+
* failed, is the first question failing, the one {@link workTreeRoot}
|
|
43
|
+
* asks: `cwd` is in no work tree. Anything else is not read: a path that
|
|
44
|
+
* holds a line break is more lines than two, and so is what a git before
|
|
45
|
+
* 2.31 would print, to which `--path-format=absolute` is a flag to hand
|
|
46
|
+
* back (the same manual, Options for Filtering; the option is new in the
|
|
47
|
+
* release notes of 2.31.0). No such git was measured.
|
|
48
|
+
*
|
|
49
|
+
* `--path-format` reaches only what follows it on the line (Options for
|
|
50
|
+
* Files), so the top is printed as it is where it is asked for alone. The
|
|
51
|
+
* common directory is asked for from `cwd` here, and from the top by
|
|
52
|
+
* {@link commonDirectory}: the same directory only where `cwd` is the top.
|
|
53
|
+
*/
|
|
54
|
+
export declare function workTree(cwd: string): Promise<WorkTree | 'unread' | null>;
|
|
24
55
|
/**
|
|
25
56
|
* Where git runs the hook `name` from, absolute: `core.hooksPath` read as git
|
|
26
57
|
* reads it - relative to the work tree, absolute, or under `~` - and a linked
|
package/dist/git.js
CHANGED
|
@@ -38,6 +38,44 @@ export async function workTreeRoot(cwd) {
|
|
|
38
38
|
export async function commonDirectory(cwd) {
|
|
39
39
|
return value(['rev-parse', '--path-format=absolute', '--git-common-dir'], cwd);
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The top of the work tree holding `cwd` and the common directory, asked of
|
|
43
|
+
* git in one start where {@link workTreeRoot} and {@link commonDirectory}
|
|
44
|
+
* are two: `null` outside a work tree, and `'unread'` where the one answer
|
|
45
|
+
* cannot be taken for the two, which are then to be asked for as they were.
|
|
46
|
+
*
|
|
47
|
+
* Measured with git 2.43 and 2.55, rev-parse answers the two in the order
|
|
48
|
+
* they stand on its line, a line each, and prints nothing where the first
|
|
49
|
+
* fails. Its manual says of that only that `--show-toplevel` reports an
|
|
50
|
+
* error where there is no working tree (git-rev-parse(1), Options for
|
|
51
|
+
* Files, as git 2.55.0 has it, read 2026-10-14), so nothing is read on
|
|
52
|
+
* trust. Two lines that are each what `trim` would leave, from a git that
|
|
53
|
+
* did not fail, are the two answers. Nothing printed, by a git that
|
|
54
|
+
* failed, is the first question failing, the one {@link workTreeRoot}
|
|
55
|
+
* asks: `cwd` is in no work tree. Anything else is not read: a path that
|
|
56
|
+
* holds a line break is more lines than two, and so is what a git before
|
|
57
|
+
* 2.31 would print, to which `--path-format=absolute` is a flag to hand
|
|
58
|
+
* back (the same manual, Options for Filtering; the option is new in the
|
|
59
|
+
* release notes of 2.31.0). No such git was measured.
|
|
60
|
+
*
|
|
61
|
+
* `--path-format` reaches only what follows it on the line (Options for
|
|
62
|
+
* Files), so the top is printed as it is where it is asked for alone. The
|
|
63
|
+
* common directory is asked for from `cwd` here, and from the top by
|
|
64
|
+
* {@link commonDirectory}: the same directory only where `cwd` is the top.
|
|
65
|
+
*/
|
|
66
|
+
export async function workTree(cwd) {
|
|
67
|
+
const run = await git(['rev-parse', '--show-toplevel', '--path-format=absolute', '--git-common-dir'], cwd);
|
|
68
|
+
if (run.stdout === '')
|
|
69
|
+
return run.code === 0 ? 'unread' : null;
|
|
70
|
+
const lines = run.stdout.split('\n');
|
|
71
|
+
if (run.code !== 0 || lines.length !== 3 || lines[2] !== '')
|
|
72
|
+
return 'unread';
|
|
73
|
+
const root = lines[0];
|
|
74
|
+
const commonDir = lines[1];
|
|
75
|
+
if (root === '' || commonDir === '' || root.trim() !== root || commonDir.trim() !== commonDir)
|
|
76
|
+
return 'unread';
|
|
77
|
+
return { root, commonDir };
|
|
78
|
+
}
|
|
41
79
|
/**
|
|
42
80
|
* Where git runs the hook `name` from, absolute: `core.hooksPath` read as git
|
|
43
81
|
* reads it - relative to the work tree, absolute, or under `~` - and a linked
|
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,gFAAgF;AAChF,MAAM,UAAU,GAAG,CAAC,IAAuB,EAAE,GAAW;IACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,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,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAC/H,mEAAmE;YACnE,sEAAsE;YACtE,MAAM,IAAI,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAE,KAA0B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACjI,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,KAAK,CAAC,IAAuB,EAAE,GAAW;IACvD,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC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UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC;AAC9E,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 } from './types.js';\n\nexport interface Run {\n readonly code: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\n/** Runs git and answers whatever it answered; a missing git is a code of -1. */\nexport function git(args: readonly string[], cwd: string): Promise<Run> {\n return new Promise((resolve) => {\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 }, (error, stdout, stderr) => {\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/**\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. `null` when git cannot say, before 2.31.\n */\nexport async function hookPath(name: string, cwd: string): Promise<string | null> {\n return value(['rev-parse', '--path-format=absolute', '--git-path', `hooks/${name}`], cwd);\n}\n\n/** The checked-out branch's short name, or `null` on a detached head. */\nexport async function currentBranch(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'HEAD'], cwd);\n}\n\n/** The remote's default branch as a local ref, such as `origin/main`, or `null`. */\nexport async function remoteDefault(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD'], cwd);\n}\n\n/** Every local branch, by its short name. */\nexport async function localBranches(cwd: string): Promise<string[]> {\n const listed = await value(['for-each-ref', '--format=%(refname:short)', 'refs/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 return listed === null || listed === '' ? [] : listed.split('\\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);\n if (run.code !== 0) throw new GitError(`git diff ${from} ${to} failed: ${run.stderr.trim()}`);\n return parseNameStatus(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);\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);\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)).code === 0;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAU9C,gFAAgF;AAChF,MAAM,UAAU,GAAG,CAAC,IAAuB,EAAE,GAAW;IACtD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,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,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAC/H,mEAAmE;YACnE,sEAAs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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,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC;AAC9E,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 } from './types.js';\n\nexport interface Run {\n readonly code: number;\n readonly stdout: string;\n readonly stderr: string;\n}\n\n/** Runs git and answers whatever it answered; a missing git is a code of -1. */\nexport function git(args: readonly string[], cwd: string): Promise<Run> {\n return new Promise((resolve) => {\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 }, (error, stdout, stderr) => {\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. `null` when git cannot say, before 2.31.\n */\nexport async function hookPath(name: string, cwd: string): Promise<string | null> {\n return value(['rev-parse', '--path-format=absolute', '--git-path', `hooks/${name}`], cwd);\n}\n\n/** The checked-out branch's short name, or `null` on a detached head. */\nexport async function currentBranch(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'HEAD'], cwd);\n}\n\n/** The remote's default branch as a local ref, such as `origin/main`, or `null`. */\nexport async function remoteDefault(cwd: string): Promise<string | null> {\n return value(['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD'], cwd);\n}\n\n/** Every local branch, by its short name. */\nexport async function localBranches(cwd: string): Promise<string[]> {\n const listed = await value(['for-each-ref', '--format=%(refname:short)', 'refs/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 return listed === null || listed === '' ? [] : listed.split('\\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);\n if (run.code !== 0) throw new GitError(`git diff ${from} ${to} failed: ${run.stderr.trim()}`);\n return parseNameStatus(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);\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);\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)).code === 0;\n}\n"]}
|
package/dist/round.d.ts
CHANGED
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
* share. Each gathers what a pure module needs - from git, the disk and the
|
|
4
4
|
* siblings - and hands it over; the decisions are made in `context.ts`,
|
|
5
5
|
* `audit.ts`, `guard.ts` and `rulings.ts`.
|
|
6
|
+
*
|
|
7
|
+
* The hook loads this module before every write it decides, so what only
|
|
8
|
+
* an audit, a verified ruling or `doctor` runs is imported where it runs:
|
|
9
|
+
* the audit's judgement, which brings the Markdown scanner with it, the
|
|
10
|
+
* hash a copy of the signers is named by, and what asks Claude Code its
|
|
11
|
+
* release.
|
|
6
12
|
*/
|
|
7
|
-
import {
|
|
13
|
+
import type { AuditReport } from './audit.js';
|
|
8
14
|
import { type BaseSource, type ClaudeCodeWiring, type ClaudeSettings, type PatternReader, type PluginState } from './configure.js';
|
|
9
15
|
import { type ContextPacket } from './context.js';
|
|
10
16
|
import type { DocumentReader } from './document.js';
|
|
@@ -42,8 +48,13 @@ export interface RulingCheck {
|
|
|
42
48
|
*/
|
|
43
49
|
export declare function checkRulings(workspace: Workspace, brief: Pick<BriefRow, 'file'>, text: string, reader: DocumentReader, base: Base): Promise<RulingCheck>;
|
|
44
50
|
export declare function briefText(workspace: Workspace, brief: BriefRow): Promise<string>;
|
|
45
|
-
/**
|
|
46
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Decides paths against the brief, with the rulings verified against the
|
|
53
|
+
* base `baseFlag` names, or the configured one. The reader may be given as
|
|
54
|
+
* what makes one: it is asked for where a ruling is read, and a caller that
|
|
55
|
+
* decides every write need not load a scanner for those that read none.
|
|
56
|
+
*/
|
|
57
|
+
export declare function checkPaths(workspace: Workspace, brief: BriefRow | null, noBrief: string | undefined, given: readonly string[], cwd: string, reader: DocumentReader | (() => Promise<DocumentReader>), baseFlag: string | undefined): Promise<Decision[]>;
|
|
47
58
|
export declare function buildContext(workspace: Workspace, brief: BriefRow, briefs: readonly BriefRow[], reader: DocumentReader, baseFlag: string | undefined): Promise<ContextPacket>;
|
|
48
59
|
/**
|
|
49
60
|
* Whether a path spec-brief's `plugins` names, read from the root, is this
|
|
@@ -99,8 +110,18 @@ export declare function claudeSettings(root: string, env: CliIO['env']): Promise
|
|
|
99
110
|
* `init` reads the wiring through this too, so that it and `doctor` say
|
|
100
111
|
* the same of every tree, and hands it the reader it reads the matchers of
|
|
101
112
|
* the same files with, so that the two read each pattern once between them.
|
|
113
|
+
*
|
|
114
|
+
* A matcher that lists names with a comma is read as the Claude Code on
|
|
115
|
+
* `PATH` reads it, which turns on its release (configure.ts). `doctor`
|
|
116
|
+
* reports the release, and asks it wherever something wires the guard,
|
|
117
|
+
* since one too old for the hooks lets every write through: the lines are
|
|
118
|
+
* first read as a release that cannot be told reads them, under which a
|
|
119
|
+
* line that may be started counts as wiring. `init` has no other use for
|
|
120
|
+
* the release, so it says that it does not report it, and it is asked only
|
|
121
|
+
* where a line turns on it: where what is read of the lines differs between
|
|
122
|
+
* a release that cannot be told and the newest.
|
|
102
123
|
*/
|
|
103
|
-
export declare function claudeCodeWiring(root: string, io: CliIO, pattern?: PatternReader): Promise<ClaudeCodeWiring>;
|
|
124
|
+
export declare function claudeCodeWiring(root: string, io: CliIO, pattern?: PatternReader, reported?: boolean): Promise<ClaudeCodeWiring>;
|
|
104
125
|
/**
|
|
105
126
|
* The brief a round works on, as doctor reports it: its id, and what is
|
|
106
127
|
* wrong with the name when no round can work under it. Every other command
|
package/dist/round.js
CHANGED
|
@@ -3,27 +3,32 @@
|
|
|
3
3
|
* share. Each gathers what a pure module needs - from git, the disk and the
|
|
4
4
|
* siblings - and hands it over; the decisions are made in `context.ts`,
|
|
5
5
|
* `audit.ts`, `guard.ts` and `rulings.ts`.
|
|
6
|
+
*
|
|
7
|
+
* The hook loads this module before every write it decides, so what only
|
|
8
|
+
* an audit, a verified ruling or `doctor` runs is imported where it runs:
|
|
9
|
+
* the audit's judgement, which brings the Markdown scanner with it, the
|
|
10
|
+
* hash a copy of the signers is named by, and what asks Claude Code its
|
|
11
|
+
* release.
|
|
6
12
|
*/
|
|
7
|
-
import { createHash } from 'node:crypto';
|
|
8
13
|
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
9
14
|
import { readdir, readFile, rm } from 'node:fs/promises';
|
|
10
15
|
import { join, resolve } from 'node:path';
|
|
11
16
|
import { fileURLToPath } from 'node:url';
|
|
12
17
|
import { readArchivePlan, readGuardRun } from './answers.js';
|
|
13
|
-
import { audit, tally } from './audit.js';
|
|
14
18
|
import { SiblingOutputError } from './briefs.js';
|
|
15
19
|
import { sameId } from './branch.js';
|
|
16
|
-
import { enabledPlugin, exportedFile, handedLines, hooksDisabled, HOSTED_REGISTRY, isStarted, loadsPlugin, MARKETPLACE_REGISTRY, patternReader, pluginMarketplace, pluginPresence, PROJECT_SETTINGS, registersServer, reportHooks, SPEC_BRIEF_CONFIGS, } from './configure.js';
|
|
20
|
+
import { commasUnder, enabledPlugin, exportedFile, handedLines, hooksDisabled, HOSTED_REGISTRY, isStarted, loadsPlugin, MARKETPLACE_REGISTRY, patternReader, pluginMarketplace, pluginPresence, PROJECT_SETTINGS, registersServer, reportHooks, SPEC_BRIEF_CONFIGS, wiringState, } from './configure.js';
|
|
17
21
|
import { readRules, renderContext } from './context.js';
|
|
18
22
|
import { isDirectory, readJsonObject, readText, repositoryPath, stateDirectory, writeAtomic } from './fs.js';
|
|
19
|
-
import { blameLine, changes, isUncommitted, mergeBase, remoteDefault, revision, show, verifyCommit, workTreeRoot } from './git.js';
|
|
23
|
+
import { blameLine, changes, commonDirectory, isUncommitted, mergeBase, remoteDefault, revision, show, verifyCommit, workTreeRoot } from './git.js';
|
|
20
24
|
import { decide } from './guard.js';
|
|
21
25
|
import { diffManifest, ecosystemOf, readManifestNames } from './manifests.js';
|
|
22
26
|
import { addRulingRow, nextId, readRulings, renderMemo, renderRow, } from './rulings.js';
|
|
23
27
|
import { compileGlob } from './vendor/spec-core/pattern/index.js';
|
|
24
28
|
import { dirname, isRelativeReference, resolveInside, splitReference } from './vendor/spec-core/path/index.js';
|
|
25
29
|
import { SiblingError } from './siblings.js';
|
|
26
|
-
import { claudeHookLine, emptyValue, heldHookLine, isBlank, outsideHookLine } from './usage.js';
|
|
30
|
+
import { claudeHookLine, elsewhereHookLine, emptyValue, heldHookLine, holderHookLine, isBlank, outsideHookLine } from './usage.js';
|
|
31
|
+
import { checkClaudeCode } from './versions.js';
|
|
27
32
|
import { activeBrief, describeActive, namedId, openWorkspace, parseOptions, UsageError } from './workspace.js';
|
|
28
33
|
/** What the round is measured from: the flag, the configuration, then the remote's default branch. */
|
|
29
34
|
export async function resolveBase(workspace, flag) {
|
|
@@ -78,6 +83,7 @@ export async function checkRulings(workspace, brief, text, reader, base) {
|
|
|
78
83
|
// with no encoding names the file by its bytes, which a path refuses when
|
|
79
84
|
// one of them is NUL: a sweep counts that mutant killed now and then.
|
|
80
85
|
const directory = await stateDirectory(workspace.commonDir, 'signers');
|
|
86
|
+
const { createHash } = await import('node:crypto');
|
|
81
87
|
const file = join(directory, `${createHash('sha256').update(signers).digest('hex').slice(0, 16)}`);
|
|
82
88
|
await writeAtomic(file, signers);
|
|
83
89
|
const verified = [];
|
|
@@ -106,20 +112,35 @@ export async function briefText(workspace, brief) {
|
|
|
106
112
|
throw new UsageError(`${brief.file} cannot be read`);
|
|
107
113
|
return text;
|
|
108
114
|
}
|
|
109
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Decides paths against the brief, with the rulings verified against the
|
|
117
|
+
* base `baseFlag` names, or the configured one. The reader may be given as
|
|
118
|
+
* what makes one: it is asked for where a ruling is read, and a caller that
|
|
119
|
+
* decides every write need not load a scanner for those that read none.
|
|
120
|
+
*/
|
|
110
121
|
export async function checkPaths(workspace, brief, noBrief, given, cwd, reader, baseFlag) {
|
|
111
122
|
const resolved = given.map((path) => ({ given: path, path: repositoryPath(path, workspace.root, cwd) }));
|
|
112
123
|
const decideAll = (rulings) => resolved.map(({ path, given: g }) => decide({ path, given: g, brief, noBrief, rulings, outOfScope: workspace.config.outOfScope }));
|
|
113
124
|
const first = decideAll([]);
|
|
114
|
-
// Rulings cost
|
|
115
|
-
// when a write reaches a protected file. Read
|
|
116
|
-
// since a ruling allows only a protected
|
|
117
|
-
//
|
|
118
|
-
//
|
|
125
|
+
// Rulings cost the reader of a brief, and a blame and a signature check
|
|
126
|
+
// each, so they are read only when a write reaches a protected file. Read
|
|
127
|
+
// anyway, they decide the same, since a ruling allows only a protected
|
|
128
|
+
// path: what a mutant that always reads them changes is what is loaded
|
|
129
|
+
// for a write no brief protects (loads.test.ts). With no brief nothing is
|
|
130
|
+
// protected, so the null check is there for the type.
|
|
119
131
|
if (brief === null || !first.some((decision) => decision.reason === 'protected'))
|
|
120
132
|
return first;
|
|
133
|
+
const text = await briefText(workspace, brief);
|
|
134
|
+
const documents = typeof reader === 'function' ? await reader() : reader;
|
|
135
|
+
// The base is where the allowed signers are read, and only a row that
|
|
136
|
+
// allows something is checked against them: where none does, git is asked
|
|
137
|
+
// nothing of the base, three processes of a refusal, and what was decided
|
|
138
|
+
// without a ruling stands.
|
|
139
|
+
const { rulings } = readRulings(documents.sectionTables(text, workspace.config.rulings.section).tables);
|
|
140
|
+
if (!rulings.some((row) => row.decision === 'allow'))
|
|
141
|
+
return first;
|
|
121
142
|
const base = await resolveBase(workspace, baseFlag);
|
|
122
|
-
return decideAll((await checkRulings(workspace, brief,
|
|
143
|
+
return decideAll((await checkRulings(workspace, brief, text, documents, base)).verified);
|
|
123
144
|
}
|
|
124
145
|
/* ----------------------------------------------------------------- context */
|
|
125
146
|
/**
|
|
@@ -399,15 +420,24 @@ export async function claudeSettings(root, env) {
|
|
|
399
420
|
* `init` reads the wiring through this too, so that it and `doctor` say
|
|
400
421
|
* the same of every tree, and hands it the reader it reads the matchers of
|
|
401
422
|
* the same files with, so that the two read each pattern once between them.
|
|
423
|
+
*
|
|
424
|
+
* A matcher that lists names with a comma is read as the Claude Code on
|
|
425
|
+
* `PATH` reads it, which turns on its release (configure.ts). `doctor`
|
|
426
|
+
* reports the release, and asks it wherever something wires the guard,
|
|
427
|
+
* since one too old for the hooks lets every write through: the lines are
|
|
428
|
+
* first read as a release that cannot be told reads them, under which a
|
|
429
|
+
* line that may be started counts as wiring. `init` has no other use for
|
|
430
|
+
* the release, so it says that it does not report it, and it is asked only
|
|
431
|
+
* where a line turns on it: where what is read of the lines differs between
|
|
432
|
+
* a release that cannot be told and the newest.
|
|
402
433
|
*/
|
|
403
|
-
export async function claudeCodeWiring(root, io, pattern = patternReader()) {
|
|
434
|
+
export async function claudeCodeWiring(root, io, pattern = patternReader(), reported = true) {
|
|
404
435
|
const sources = await claudeSettings(root, io.env);
|
|
405
436
|
// Each line is read once, before any is reported: what the brief on one
|
|
406
437
|
// names is spec-brief's to say, and the report itself asks nothing.
|
|
407
438
|
const read = new Map();
|
|
408
439
|
for (const words of handedLines(sources, root))
|
|
409
440
|
read.set(JSON.stringify(words), await hookLineHere(words, root, io));
|
|
410
|
-
const lines = reportHooks(sources, root, (words) => read.get(JSON.stringify(words)), pattern);
|
|
411
441
|
const plugin = enabledPlugin(sources);
|
|
412
442
|
// An id that names no marketplace has no directory to look in, and is said
|
|
413
443
|
// as one that cannot be told whatever is on disk: pluginPresence answers
|
|
@@ -415,27 +445,40 @@ export async function claudeCodeWiring(root, io, pattern = patternReader()) {
|
|
|
415
445
|
// equivalent to its mutant.
|
|
416
446
|
const marketplace = plugin === null ? null : pluginMarketplace(plugin.id);
|
|
417
447
|
const roots = marketplace === null ? [] : await Promise.all(pluginDirectories(io.env).map((directory) => pluginsRoot(directory, marketplace)));
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
448
|
+
const presence = plugin === null ? null : pluginPresence(plugin, sources, roots);
|
|
449
|
+
const server = registersServer(await readJsonObject(join(root, '.mcp.json')));
|
|
450
|
+
const under = (release) => {
|
|
451
|
+
const lines = reportHooks(sources, root, (words) => read.get(JSON.stringify(words)), pattern, commasUnder(release));
|
|
422
452
|
// A line Claude Code starts for no write, before one or after, is in no
|
|
423
453
|
// one's way: it is said, and the file is not counted for it.
|
|
424
|
-
hooks
|
|
425
|
-
|
|
426
|
-
|
|
454
|
+
const hooks = sources.map(({ file }) => file).filter((file) => lines.some((line) => line.file === file && (isStarted(line.before) || isStarted(line.after))));
|
|
455
|
+
// In the order a document has them, which a script may compare by the byte.
|
|
456
|
+
return { plugin, presence, hooksOff: hooksDisabled(sources), hooks, lines, server, release };
|
|
427
457
|
};
|
|
458
|
+
const untold = under(null);
|
|
459
|
+
const asked = reported ? wiringState(untold) !== 'none' : JSON.stringify(untold.lines) !== JSON.stringify(reportHooks(sources, root, (words) => read.get(JSON.stringify(words)), pattern));
|
|
460
|
+
// Read again under the release, where it was asked: what is read without
|
|
461
|
+
// one is what is read under one that cannot be told. What asks it is
|
|
462
|
+
// loaded here, where it is asked: the hook loads these operations for
|
|
463
|
+
// every write, and asks no release.
|
|
464
|
+
return under(asked ? checkClaudeCode(await (await import('./host.js')).claudeVersion(io.env)) : null);
|
|
428
465
|
}
|
|
429
466
|
/**
|
|
430
467
|
* What the hook does with the words a session started at `root` hands it:
|
|
431
|
-
* its own reading of the line (usage.ts), and
|
|
432
|
-
* line guards. The hook opens the work tree its root is
|
|
433
|
-
* is a directory in none, it reads a session outside a
|
|
434
|
-
* write and says nothing (ADR-0005): git is asked here
|
|
435
|
-
* and the line is one under which the guard is off.
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
468
|
+
* its own reading of the line (usage.ts), and what follows from where its
|
|
469
|
+
* root is, where the line guards. The hook opens the work tree its root is
|
|
470
|
+
* in. Where the root is a directory in none, it reads a session outside a
|
|
471
|
+
* work tree, checks no write and says nothing (ADR-0005): git is asked here
|
|
472
|
+
* as the hook asks it, and the line is one under which the guard is off.
|
|
473
|
+
* Where the root is in another work tree than the project's, the hook
|
|
474
|
+
* decides by that work tree's briefs, and a file outside it is none of its
|
|
475
|
+
* repository's: so a work tree that does not hold the project leaves every
|
|
476
|
+
* write to a file of the project unchecked, and one that holds it checks
|
|
477
|
+
* them, by its own briefs. Where the line names a brief, the hook asks
|
|
478
|
+
* spec-brief in the work tree it opened which brief the name is, and holds
|
|
479
|
+
* every write under a name that is none (ADR-0004). So this asks the same,
|
|
480
|
+
* of the same work tree, and a line that holds every write is said as that
|
|
481
|
+
* wherever its root is.
|
|
439
482
|
*/
|
|
440
483
|
async function hookLineHere(words, root, io) {
|
|
441
484
|
const line = claudeHookLine(words, parseOptions, root, (path) => isDirectory(resolve(root, path)));
|
|
@@ -443,15 +486,30 @@ async function hookLineHere(words, root, io) {
|
|
|
443
486
|
// check of its state is the compiler's, and its mutant is equivalent.
|
|
444
487
|
if (line === null || line.state !== 'guards')
|
|
445
488
|
return line;
|
|
489
|
+
let told = line;
|
|
446
490
|
// With no root on its line the hook opens the project, which is the work
|
|
447
491
|
// tree this runs in: git is asked only about a root the line gives.
|
|
448
|
-
if (line.root !== undefined
|
|
449
|
-
|
|
492
|
+
if (line.root !== undefined) {
|
|
493
|
+
const top = await workTreeRoot(resolve(root, line.root));
|
|
494
|
+
if (top === null)
|
|
495
|
+
return outsideHookLine(line.root);
|
|
496
|
+
// The project's top as the root's work tree names it: nothing where the
|
|
497
|
+
// two are one work tree, which is every root in the project, and
|
|
498
|
+
// `null` where the project is not in it.
|
|
499
|
+
const path = repositoryPath(root, top, root);
|
|
500
|
+
if (path !== '') {
|
|
501
|
+
// One repository's work trees share a git directory, and no two
|
|
502
|
+
// repositories do.
|
|
503
|
+
const [theirs, ours] = await Promise.all([commonDirectory(top), commonDirectory(root)]);
|
|
504
|
+
const tree = { top, ours: theirs === ours };
|
|
505
|
+
told = path === null ? elsewhereHookLine(line.root, tree) : holderHookLine(line, tree, path);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
450
508
|
if (line.brief === undefined)
|
|
451
|
-
return
|
|
509
|
+
return told;
|
|
452
510
|
const workspace = await openWorkspace({ root: line.root === undefined ? root : resolve(root, line.root) }, io);
|
|
453
511
|
const { problem } = await diagnoseBrief(workspace, { brief: line.brief }, io.env);
|
|
454
|
-
return problem === null ?
|
|
512
|
+
return problem === null ? told : heldHookLine(problem);
|
|
455
513
|
}
|
|
456
514
|
/**
|
|
457
515
|
* The brief a round works on, as doctor reports it: its id, and what is
|
|
@@ -511,6 +569,7 @@ async function briefAssertions(workspace, brief, text, reader) {
|
|
|
511
569
|
return { outcomes, unreadable };
|
|
512
570
|
}
|
|
513
571
|
export async function runAudit(workspace, brief, reader, baseFlag) {
|
|
572
|
+
const { audit, tally } = await import('./audit.js');
|
|
514
573
|
const base = await resolveBase(workspace, baseFlag);
|
|
515
574
|
const text = await briefText(workspace, brief);
|
|
516
575
|
const [dependencies, archive, assertions, rulings, plugin] = await Promise.all([
|