handoff-check 0.9.0 → 0.10.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/CHANGELOG.md +9 -0
- package/README.md +51 -20
- package/dist/cli.js +416 -14
- package/docs/agent-integration.md +4 -4
- package/docs/architecture.md +6 -0
- package/docs/decisions/0010-explicit-local-source-checks.md +39 -0
- package/docs/development-plan.md +13 -5
- package/docs/explainability.md +4 -4
- package/docs/first-check.md +6 -6
- package/docs/lifecycle.md +4 -4
- package/docs/local-sources.md +158 -0
- package/docs/project-context.md +6 -6
- package/docs/releasing.md +4 -4
- package/docs/roadmap.md +3 -0
- package/docs/rule-reviews.md +6 -6
- package/docs/snapshot-diff-and-setup.md +5 -5
- package/docs/verified-commands.md +2 -2
- package/examples/local-sources/bindings.json +9 -0
- package/examples/local-sources/config.json +9 -0
- package/examples/local-sources/constraints.json +27 -0
- package/examples/local-sources/policy.md +4 -0
- package/examples/local-sources/sources.json +21 -0
- package/package.json +1 -1
- package/schemas/source-bindings.v1.schema.json +46 -0
- package/schemas/source-registry.v1.schema.json +67 -0
- package/schemas/source-result.v1.schema.json +278 -0
- package/skills/handoff-check/SKILL.md +17 -0
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
import { open as
|
|
5
|
-
import { resolve as
|
|
4
|
+
import { open as open7 } from "node:fs/promises";
|
|
5
|
+
import { resolve as resolve10 } from "node:path";
|
|
6
6
|
import { parseArgs } from "node:util";
|
|
7
7
|
// package.json
|
|
8
8
|
var package_default = {
|
|
9
9
|
name: "handoff-check",
|
|
10
|
-
version: "0.
|
|
10
|
+
version: "0.10.0",
|
|
11
11
|
description: "A deterministic, local CLI that verifies active constraints before a coding agent resumes work.",
|
|
12
12
|
type: "module",
|
|
13
13
|
packageManager: "bun@1.2.10",
|
|
@@ -1864,10 +1864,388 @@ Edit and review constraints before relying on them. Never refresh a baseline bef
|
|
|
1864
1864
|
}
|
|
1865
1865
|
}
|
|
1866
1866
|
|
|
1867
|
+
// src/source-cli.ts
|
|
1868
|
+
import { open as open6 } from "node:fs/promises";
|
|
1869
|
+
import { resolve as resolve9 } from "node:path";
|
|
1870
|
+
|
|
1871
|
+
// src/source-files.ts
|
|
1872
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
1873
|
+
import { constants as constants4 } from "node:fs";
|
|
1874
|
+
import { lstat as lstat4, open as open5, realpath as realpath2, stat as stat3 } from "node:fs/promises";
|
|
1875
|
+
import { isAbsolute as isAbsolute3, relative as relative3, resolve as resolve8, sep as sep3 } from "node:path";
|
|
1876
|
+
|
|
1877
|
+
// src/sources.ts
|
|
1878
|
+
var sourceLimit = 10 * 1024 * 1024;
|
|
1879
|
+
var bindingLimit = 256;
|
|
1880
|
+
function object3(input, allowed, path) {
|
|
1881
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
1882
|
+
throw new InputError(`${path}: expected an object`);
|
|
1883
|
+
const value = input;
|
|
1884
|
+
for (const key of Object.keys(value).sort())
|
|
1885
|
+
if (!allowed.includes(key))
|
|
1886
|
+
throw new InputError(`${path}: unknown field '${key}'`);
|
|
1887
|
+
return value;
|
|
1888
|
+
}
|
|
1889
|
+
function hash(input, path) {
|
|
1890
|
+
if (typeof input !== "string" || !/^sha256:[a-f0-9]{64}(?![\s\S])/.test(input))
|
|
1891
|
+
throw new InputError(`${path}: expected canonical sha256 reference`);
|
|
1892
|
+
return input;
|
|
1893
|
+
}
|
|
1894
|
+
function sourcePath(input, path = "source path") {
|
|
1895
|
+
if (typeof input !== "string" || !input || Array.from(input).length > 1024)
|
|
1896
|
+
throw new InputError(`${path}: expected a relative portable path of 1 to 1024 characters`);
|
|
1897
|
+
const parts = input.split("/");
|
|
1898
|
+
if (parts.some((part) => !part || part === "." || part === ".." || Array.from(part).length > 255 || /[\\:*?"<>|\p{Cc}\p{Cf}\p{Cs}\p{Zl}\p{Zp}]/u.test(part) || /[. ]$/.test(part) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part)))
|
|
1899
|
+
throw new InputError(`${path}: use a portable relative file path without traversal, URLs, reserved names or control characters`);
|
|
1900
|
+
return input;
|
|
1901
|
+
}
|
|
1902
|
+
function root(input, field) {
|
|
1903
|
+
const value = object3(input, [
|
|
1904
|
+
"schemaVersion",
|
|
1905
|
+
"projectId",
|
|
1906
|
+
field,
|
|
1907
|
+
...field === "sources" ? ["capturedAt"] : []
|
|
1908
|
+
], "source registry");
|
|
1909
|
+
if (value.schemaVersion !== 1)
|
|
1910
|
+
throw new InputError("source registry.schemaVersion: expected 1");
|
|
1911
|
+
if (!Array.isArray(value[field]) || value[field].length > bindingLimit)
|
|
1912
|
+
throw new InputError(`source registry.${field}: expected an array with at most ${bindingLimit} entries`);
|
|
1913
|
+
const projectId = Object.hasOwn(value, "projectId") ? identifier(value.projectId, "source registry.projectId") : undefined;
|
|
1914
|
+
return { value, ...projectId === undefined ? {} : { projectId } };
|
|
1915
|
+
}
|
|
1916
|
+
function entries(value, retained) {
|
|
1917
|
+
const seen = new Set;
|
|
1918
|
+
return value.map((input, index) => {
|
|
1919
|
+
const path = `source entries[${index}]`;
|
|
1920
|
+
const entry = object3(input, [
|
|
1921
|
+
"id",
|
|
1922
|
+
"path",
|
|
1923
|
+
...retained ? ["revision", "contentHash", "fileHash"] : []
|
|
1924
|
+
], path);
|
|
1925
|
+
const id = identifier(entry.id, `${path}.id`);
|
|
1926
|
+
if (seen.has(id))
|
|
1927
|
+
throw new InputError(`${path}: duplicate ID '${id}'`);
|
|
1928
|
+
seen.add(id);
|
|
1929
|
+
return { entry, id, path: sourcePath(entry.path, `${path}.path`) };
|
|
1930
|
+
});
|
|
1931
|
+
}
|
|
1932
|
+
function parseSourcePlan(input) {
|
|
1933
|
+
const { value, projectId } = root(input, "bindings");
|
|
1934
|
+
return {
|
|
1935
|
+
schemaVersion: 1,
|
|
1936
|
+
...projectId === undefined ? {} : { projectId },
|
|
1937
|
+
bindings: entries(value.bindings, false).map(({ id, path }) => ({ id, path }))
|
|
1938
|
+
};
|
|
1939
|
+
}
|
|
1940
|
+
function parseSourceRegistry(input) {
|
|
1941
|
+
const { value, projectId } = root(input, "sources");
|
|
1942
|
+
const capturedAt = new Date(timestamp(value.capturedAt, "source registry.capturedAt")).toISOString();
|
|
1943
|
+
const sources = entries(value.sources, true).map(({ entry, id, path }) => {
|
|
1944
|
+
if (!Number.isSafeInteger(entry.revision) || entry.revision < 1)
|
|
1945
|
+
throw new InputError(`source '${id}': expected a positive safe revision`);
|
|
1946
|
+
return {
|
|
1947
|
+
id,
|
|
1948
|
+
path,
|
|
1949
|
+
revision: entry.revision,
|
|
1950
|
+
contentHash: hash(entry.contentHash, "contentHash"),
|
|
1951
|
+
fileHash: hash(entry.fileHash, "fileHash")
|
|
1952
|
+
};
|
|
1953
|
+
});
|
|
1954
|
+
return {
|
|
1955
|
+
schemaVersion: 1,
|
|
1956
|
+
...projectId === undefined ? {} : { projectId },
|
|
1957
|
+
capturedAt,
|
|
1958
|
+
sources
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
function selection(manifest, projectId, scope, asOf) {
|
|
1962
|
+
if (checkProject(manifest) !== projectId)
|
|
1963
|
+
throw new InputError("Source metadata and manifest must have matching project binding (both bound or both unbound)");
|
|
1964
|
+
const explanation = explain(manifest, scope, asOf);
|
|
1965
|
+
const active = new Set(explanation.rules.filter((r) => r.decision === "ACTIVE").map((r) => r.id));
|
|
1966
|
+
return {
|
|
1967
|
+
explanation,
|
|
1968
|
+
active,
|
|
1969
|
+
rules: manifest.constraints.filter((r) => active.has(r.id)).sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0)
|
|
1970
|
+
};
|
|
1971
|
+
}
|
|
1972
|
+
function recordSourceTargets(manifest, plan, scope, asOf) {
|
|
1973
|
+
const selected = selection(manifest, plan.projectId, scope, asOf);
|
|
1974
|
+
const known = new Set(manifest.constraints.map((r) => r.id));
|
|
1975
|
+
for (const binding of plan.bindings)
|
|
1976
|
+
if (!known.has(binding.id))
|
|
1977
|
+
throw new InputError(`Source binding '${binding.id}' does not exist in the manifest`);
|
|
1978
|
+
if (!selected.rules.length)
|
|
1979
|
+
throw new InputError("source-record requires at least one active constraint");
|
|
1980
|
+
const paths = new Map(plan.bindings.map((b) => [b.id, b.path]));
|
|
1981
|
+
return selected.rules.map((rule) => {
|
|
1982
|
+
const path = paths.get(rule.id);
|
|
1983
|
+
if (path === undefined)
|
|
1984
|
+
throw new InputError(`Missing explicit source binding for active rule '${rule.id}'`);
|
|
1985
|
+
return { ...reference(rule), path };
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
function sourceCheckTargets(manifest, registry, scope, asOf) {
|
|
1989
|
+
const selected = selection(manifest, registry.projectId, scope, asOf);
|
|
1990
|
+
const byId = new Map(registry.sources.map((r) => [r.id, r]));
|
|
1991
|
+
return selected.rules.flatMap((rule) => {
|
|
1992
|
+
const entry = byId.get(rule.id);
|
|
1993
|
+
const expected = reference(rule);
|
|
1994
|
+
return entry && entry.revision === expected.revision && entry.contentHash === expected.contentHash ? [entry] : [];
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
function checkSources(manifest, registry, scope, asOf, observed) {
|
|
1998
|
+
const selected = selection(manifest, registry.projectId, scope, asOf);
|
|
1999
|
+
const byId = new Map(registry.sources.map((r) => [r.id, r]));
|
|
2000
|
+
const known = new Set(manifest.constraints.map((r) => r.id));
|
|
2001
|
+
const rules = selected.rules.map((rule) => {
|
|
2002
|
+
const expected = reference(rule);
|
|
2003
|
+
const entry = byId.get(rule.id);
|
|
2004
|
+
if (!entry)
|
|
2005
|
+
return { id: rule.id, expected, status: "MISSING_BINDING" };
|
|
2006
|
+
const base = {
|
|
2007
|
+
id: rule.id,
|
|
2008
|
+
expected,
|
|
2009
|
+
recorded: {
|
|
2010
|
+
id: entry.id,
|
|
2011
|
+
revision: entry.revision,
|
|
2012
|
+
contentHash: entry.contentHash
|
|
2013
|
+
},
|
|
2014
|
+
path: entry.path,
|
|
2015
|
+
expectedFileHash: entry.fileHash
|
|
2016
|
+
};
|
|
2017
|
+
if (entry.revision !== expected.revision || entry.contentHash !== expected.contentHash)
|
|
2018
|
+
return { ...base, status: "STALE_BINDING" };
|
|
2019
|
+
const observation = observed.get(entry.path);
|
|
2020
|
+
if (!observation)
|
|
2021
|
+
throw new InputError(`Missing source observation for '${rule.id}'`);
|
|
2022
|
+
if (observation.status !== "READ")
|
|
2023
|
+
return { ...base, status: observation.status };
|
|
2024
|
+
return {
|
|
2025
|
+
...base,
|
|
2026
|
+
status: observation.fileHash === entry.fileHash ? "UNCHANGED" : "SOURCE_CHANGED",
|
|
2027
|
+
observedFileHash: observation.fileHash,
|
|
2028
|
+
observedBytes: observation.bytes
|
|
2029
|
+
};
|
|
2030
|
+
});
|
|
2031
|
+
const findings = [];
|
|
2032
|
+
if (!rules.length)
|
|
2033
|
+
findings.push({ code: "NO_ACTIVE_CONSTRAINTS" });
|
|
2034
|
+
for (const rule of rules)
|
|
2035
|
+
if (rule.status !== "UNCHANGED")
|
|
2036
|
+
findings.push({ id: rule.id, code: rule.status });
|
|
2037
|
+
for (const entry of registry.sources)
|
|
2038
|
+
if (!known.has(entry.id))
|
|
2039
|
+
findings.push({ id: entry.id, code: "UNKNOWN_RULE" });
|
|
2040
|
+
findings.sort((a, b) => (a.id ?? "") < (b.id ?? "") ? -1 : (a.id ?? "") > (b.id ?? "") ? 1 : 0);
|
|
2041
|
+
return {
|
|
2042
|
+
schemaVersion: 1,
|
|
2043
|
+
kind: "source-check",
|
|
2044
|
+
status: findings.length ? "attention" : "unchanged",
|
|
2045
|
+
...manifest.projectId === undefined ? {} : { projectId: manifest.projectId },
|
|
2046
|
+
scope,
|
|
2047
|
+
asOf: selected.explanation.asOf,
|
|
2048
|
+
activeConstraintCount: rules.length,
|
|
2049
|
+
unchangedSourceCount: rules.filter((r) => r.status === "UNCHANGED").length,
|
|
2050
|
+
registryEntryCount: registry.sources.length,
|
|
2051
|
+
ignoredEntryCount: registry.sources.filter((r) => known.has(r.id) && !selected.active.has(r.id)).length,
|
|
2052
|
+
rules,
|
|
2053
|
+
findings,
|
|
2054
|
+
notice: "Explicit local whole-file byte comparison, not semantic policy validation, authenticated history or authorization. File changes signal review needed; no constraints or baselines are refreshed. Known inactive/stale bindings are not read. Other verification commands do not load this registry. Reads and filesystem checks are not an atomic sandbox against concurrent changes."
|
|
2055
|
+
};
|
|
2056
|
+
}
|
|
2057
|
+
function sourceText(result, markdown) {
|
|
2058
|
+
const safe = markdown ? markdownText : terminalText;
|
|
2059
|
+
const lines = [
|
|
2060
|
+
markdown ? `# Handoff Check local sources
|
|
2061
|
+
` : "SOURCE CHECK",
|
|
2062
|
+
`${result.status.toUpperCase()} | ${result.unchangedSourceCount}/${result.activeConstraintCount} active rule sources unchanged | scope ${safe(result.scope)} | as of ${safe(result.asOf)}${result.projectId ? ` | project ${safe(result.projectId)}` : ""}`,
|
|
2063
|
+
`${result.registryEntryCount} registry entries | ${result.ignoredEntryCount} known inactive entries ignored`
|
|
2064
|
+
];
|
|
2065
|
+
for (const rule of result.rules)
|
|
2066
|
+
lines.push(`${rule.status} ${safe(rule.id)}${rule.path ? ` | ${safe(rule.path)}` : ""}${rule.observedFileHash ? ` | ${rule.observedFileHash}` : ""}`);
|
|
2067
|
+
for (const finding of result.findings)
|
|
2068
|
+
if (!finding.id || finding.code === "UNKNOWN_RULE")
|
|
2069
|
+
lines.push(`${finding.code}${finding.id ? ` ${safe(finding.id)}` : ""}`);
|
|
2070
|
+
lines.push(safe(result.notice));
|
|
2071
|
+
return `${lines.join(markdown ? `
|
|
2072
|
+
|
|
2073
|
+
` : `
|
|
2074
|
+
`)}
|
|
2075
|
+
`;
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
// src/source-files.ts
|
|
2079
|
+
async function sourceRoot(directory) {
|
|
2080
|
+
try {
|
|
2081
|
+
const root2 = await realpath2(directory);
|
|
2082
|
+
if (!(await stat3(root2)).isDirectory())
|
|
2083
|
+
throw new Error("not directory");
|
|
2084
|
+
return root2;
|
|
2085
|
+
} catch {
|
|
2086
|
+
throw new InputError("Cannot resolve source project directory");
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
function inside(root2, path) {
|
|
2090
|
+
const value = relative3(root2, path);
|
|
2091
|
+
return value !== "" && value !== ".." && !value.startsWith(`..${sep3}`) && !isAbsolute3(value);
|
|
2092
|
+
}
|
|
2093
|
+
async function readSourceFile(root2, path) {
|
|
2094
|
+
try {
|
|
2095
|
+
sourcePath(path);
|
|
2096
|
+
} catch {
|
|
2097
|
+
return { status: "SOURCE_UNSAFE" };
|
|
2098
|
+
}
|
|
2099
|
+
let handle;
|
|
2100
|
+
const observation = await (async () => {
|
|
2101
|
+
try {
|
|
2102
|
+
let current = root2;
|
|
2103
|
+
const parts = path.split("/");
|
|
2104
|
+
let before;
|
|
2105
|
+
for (const [index, part] of parts.entries()) {
|
|
2106
|
+
current = resolve8(current, part);
|
|
2107
|
+
if (!inside(root2, current))
|
|
2108
|
+
return { status: "SOURCE_UNSAFE" };
|
|
2109
|
+
const info2 = await lstat4(current);
|
|
2110
|
+
if (info2.isSymbolicLink() || (index < parts.length - 1 ? !info2.isDirectory() : !info2.isFile()))
|
|
2111
|
+
return { status: "SOURCE_UNSAFE" };
|
|
2112
|
+
before = info2;
|
|
2113
|
+
}
|
|
2114
|
+
const resolved = await realpath2(current);
|
|
2115
|
+
if (!inside(root2, resolved))
|
|
2116
|
+
return { status: "SOURCE_UNSAFE" };
|
|
2117
|
+
handle = await open5(current, constants4.O_RDONLY | (constants4.O_NONBLOCK ?? 0) | (constants4.O_NOFOLLOW ?? 0));
|
|
2118
|
+
const info = await handle.stat();
|
|
2119
|
+
if (!info.isFile() || !before || info.dev !== before.dev || info.ino !== before.ino)
|
|
2120
|
+
return { status: "SOURCE_UNSAFE" };
|
|
2121
|
+
if (info.size > sourceLimit)
|
|
2122
|
+
return { status: "SOURCE_TOO_LARGE" };
|
|
2123
|
+
const hash2 = createHash3("sha256");
|
|
2124
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
2125
|
+
let bytes = 0;
|
|
2126
|
+
while (true) {
|
|
2127
|
+
const read = await handle.read(buffer, 0, Math.min(buffer.length, sourceLimit - bytes + 1), bytes);
|
|
2128
|
+
if (!read.bytesRead)
|
|
2129
|
+
break;
|
|
2130
|
+
bytes += read.bytesRead;
|
|
2131
|
+
if (bytes > sourceLimit)
|
|
2132
|
+
return { status: "SOURCE_TOO_LARGE" };
|
|
2133
|
+
hash2.update(buffer.subarray(0, read.bytesRead));
|
|
2134
|
+
}
|
|
2135
|
+
return {
|
|
2136
|
+
status: "READ",
|
|
2137
|
+
fileHash: `sha256:${hash2.digest("hex")}`,
|
|
2138
|
+
bytes
|
|
2139
|
+
};
|
|
2140
|
+
} catch (error) {
|
|
2141
|
+
const code = error.code;
|
|
2142
|
+
return {
|
|
2143
|
+
status: code === "ENOENT" ? "SOURCE_MISSING" : code === "ELOOP" || code === "ENOTDIR" ? "SOURCE_UNSAFE" : "SOURCE_UNREADABLE"
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2146
|
+
})();
|
|
2147
|
+
if (handle) {
|
|
2148
|
+
try {
|
|
2149
|
+
await handle.close();
|
|
2150
|
+
} catch {
|
|
2151
|
+
return { status: "SOURCE_UNREADABLE" };
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
return observation;
|
|
2155
|
+
}
|
|
2156
|
+
async function readSourceTargets(directory, targets) {
|
|
2157
|
+
const result = new Map;
|
|
2158
|
+
if (!targets.length)
|
|
2159
|
+
return result;
|
|
2160
|
+
const root2 = await sourceRoot(directory);
|
|
2161
|
+
for (const target of targets)
|
|
2162
|
+
if (!result.has(target.path))
|
|
2163
|
+
result.set(target.path, await readSourceFile(root2, target.path));
|
|
2164
|
+
return result;
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
// src/source-cli.ts
|
|
2168
|
+
async function sourceCommand(cwd, command, options) {
|
|
2169
|
+
if (options.profile !== undefined && [options.scope, options.constraints].some((v) => v !== undefined))
|
|
2170
|
+
throw new InputError("--profile cannot be combined with --scope or --constraints");
|
|
2171
|
+
for (const key of [
|
|
2172
|
+
"config",
|
|
2173
|
+
"constraints",
|
|
2174
|
+
"bindings",
|
|
2175
|
+
"sources",
|
|
2176
|
+
"output"
|
|
2177
|
+
])
|
|
2178
|
+
if (options[key] !== undefined && !options[key].trim())
|
|
2179
|
+
throw new InputError(`--${key}: expected a non-empty path`);
|
|
2180
|
+
const input = command === "source-check" ? options.sources : options.bindings;
|
|
2181
|
+
if (input === undefined)
|
|
2182
|
+
throw new InputError(command === "source-check" ? "source-check requires --sources <registry-file>" : "source-record requires --bindings <binding-plan> after reviewing the explicit local files");
|
|
2183
|
+
if (command === "source-record" && options.format === "markdown")
|
|
2184
|
+
throw new InputError("source-record supports text or json acknowledgement; its record is always JSON");
|
|
2185
|
+
const loaded = await loadConfig(cwd, options.config, true);
|
|
2186
|
+
const config = selectProfile(loaded.config, options.profile);
|
|
2187
|
+
const scope = identifier(options.scope ?? config.scope, "--scope (or config.scope)");
|
|
2188
|
+
const manifest = parseManifest(await readJson(options.constraints === undefined ? resolve9(loaded.directory, config.constraints ?? "constraints.json") : resolve9(cwd, options.constraints), true));
|
|
2189
|
+
checkProject(manifest, undefined, config.projectId);
|
|
2190
|
+
const metadata = await readJson(resolve9(cwd, input), true);
|
|
2191
|
+
const asOf = options["as-of"] ?? new Date().toISOString();
|
|
2192
|
+
timestamp(asOf, "--as-of");
|
|
2193
|
+
if (command === "source-check") {
|
|
2194
|
+
const registry2 = parseSourceRegistry(metadata);
|
|
2195
|
+
const targets2 = sourceCheckTargets(manifest, registry2, scope, asOf);
|
|
2196
|
+
const observed2 = await readSourceTargets(loaded.directory, targets2);
|
|
2197
|
+
const result = checkSources(manifest, registry2, scope, asOf, observed2);
|
|
2198
|
+
process.stdout.write(options.format === "json" ? `${JSON.stringify(result, null, 2)}
|
|
2199
|
+
` : sourceText(result, options.format === "markdown"));
|
|
2200
|
+
return result.status === "unchanged" ? 0 : 1;
|
|
2201
|
+
}
|
|
2202
|
+
const plan = parseSourcePlan(metadata);
|
|
2203
|
+
const targets = recordSourceTargets(manifest, plan, scope, asOf);
|
|
2204
|
+
const observed = await readSourceTargets(loaded.directory, targets);
|
|
2205
|
+
const sources = targets.map((target) => {
|
|
2206
|
+
const observation = observed.get(target.path);
|
|
2207
|
+
if (observation?.status !== "READ")
|
|
2208
|
+
throw new InputError(`Cannot record source for '${target.id}': ${observation?.status ?? "SOURCE_UNREADABLE"}; no record created`);
|
|
2209
|
+
return { ...target, fileHash: observation.fileHash };
|
|
2210
|
+
});
|
|
2211
|
+
const registry = parseSourceRegistry({
|
|
2212
|
+
schemaVersion: 1,
|
|
2213
|
+
...manifest.projectId === undefined ? {} : { projectId: manifest.projectId },
|
|
2214
|
+
capturedAt: asOf,
|
|
2215
|
+
sources
|
|
2216
|
+
});
|
|
2217
|
+
const content = `${JSON.stringify(registry, null, 2)}
|
|
2218
|
+
`;
|
|
2219
|
+
if (options.output === undefined)
|
|
2220
|
+
process.stdout.write(content);
|
|
2221
|
+
else {
|
|
2222
|
+
const path = resolve9(cwd, options.output);
|
|
2223
|
+
let handle;
|
|
2224
|
+
try {
|
|
2225
|
+
handle = await open6(path, "wx", 420);
|
|
2226
|
+
} catch {
|
|
2227
|
+
throw new InputError(`Cannot create source record '${path}'; choose a new file with an existing parent directory`);
|
|
2228
|
+
}
|
|
2229
|
+
try {
|
|
2230
|
+
await handle.writeFile(content, "utf8");
|
|
2231
|
+
} catch {
|
|
2232
|
+
throw new InputError(`Cannot finish source record '${path}'; the new file may be partial. Inspect it before retrying.`);
|
|
2233
|
+
} finally {
|
|
2234
|
+
await handle.close();
|
|
2235
|
+
}
|
|
2236
|
+
process.stdout.write(options.format === "json" ? `${JSON.stringify({ schemaVersion: 1, status: "recorded", path, entries: registry.sources.length })}
|
|
2237
|
+
` : `RECORDED ${terminalText(path)} | ${registry.sources.length} local source references
|
|
2238
|
+
`);
|
|
2239
|
+
}
|
|
2240
|
+
return 0;
|
|
2241
|
+
}
|
|
2242
|
+
|
|
1867
2243
|
// src/cli.ts
|
|
1868
2244
|
var help = `Handoff Check
|
|
1869
2245
|
|
|
1870
2246
|
Usage: handoff-check verify --scope <scope> [options]
|
|
2247
|
+
handoff-check source-check --sources <source-registry> [options]
|
|
2248
|
+
handoff-check source-record --bindings <binding-plan> [--output <new-file>] [options]
|
|
1871
2249
|
handoff-check review --registry <review-file> [--profile <name>] [--format text|json|markdown]
|
|
1872
2250
|
handoff-check review-record --owner <owner> --review-by <UTC time> [--output <new-file>] [options]
|
|
1873
2251
|
handoff-check run [--profile <name> | --scope <scope>] [--config <path>] -- <executable> [args...]
|
|
@@ -1881,6 +2259,8 @@ Usage: handoff-check verify --scope <scope> [options]
|
|
|
1881
2259
|
handoff-check hook --host claude --config <absolute-path> [--require-active]
|
|
1882
2260
|
|
|
1883
2261
|
Options:
|
|
2262
|
+
--sources <path> source-check: explicit local-source registry (cwd relative)
|
|
2263
|
+
--bindings <path> source-record: explicit rule/path binding plan (cwd relative)
|
|
1884
2264
|
--registry <path> review: explicit review registry (resolved from cwd)
|
|
1885
2265
|
--owner <owner> review-record: owner of explicitly reviewed active rules
|
|
1886
2266
|
--review-by <UTC> review-record: review deadline, later than capture time
|
|
@@ -1897,9 +2277,9 @@ Options:
|
|
|
1897
2277
|
--require-content verify: require a v2/v3/v4 content-aware handoff
|
|
1898
2278
|
--require-active verify: fail if empty; hook/hook-config: opt-in nonempty policy
|
|
1899
2279
|
--task <task> snapshot: task description (required)
|
|
1900
|
-
--output <path> snapshot/review-record:
|
|
2280
|
+
--output <path> snapshot/review-record/source-record: new file, never overwrite
|
|
1901
2281
|
--include-content snapshot: retain old rule text in unbound v3/bound v4 (opt-in)
|
|
1902
|
-
--format text|json|markdown Markdown
|
|
2282
|
+
--format text|json|markdown Markdown: verify/explain/diff/review/source-check (default: text)
|
|
1903
2283
|
--agent <agent> init: codex, claude, both (default), or none
|
|
1904
2284
|
--host <host> doctor: integration target; hook/hook-config: claude
|
|
1905
2285
|
--dry-run init/setup: preview proposed files without writes
|
|
@@ -1909,6 +2289,7 @@ Options:
|
|
|
1909
2289
|
|
|
1910
2290
|
Exit codes: verify 0 verified / 1 mismatch; diff 0 unchanged / 1 different; doctor 0 healthy / 1 attention.
|
|
1911
2291
|
Review: 0 current maintenance / 1 attention (including zero active); never changes verify/run policy.
|
|
2292
|
+
Source-check: 0 unchanged / 1 attention (including zero active); no implicit source reads by verify/run.
|
|
1912
2293
|
Run: mandatory content/nonempty/current-clock preflight; 1 blocked / 2 invalid or launch error.
|
|
1913
2294
|
After launch run returns the child exit code (or 128 + signal); diagnostics use stderr.
|
|
1914
2295
|
Hook 0 means advisory response delivered (may report FAIL/INVALID), not verified.
|
|
@@ -1950,7 +2331,9 @@ async function main() {
|
|
|
1950
2331
|
after: { type: "string" },
|
|
1951
2332
|
registry: { type: "string" },
|
|
1952
2333
|
owner: { type: "string" },
|
|
1953
|
-
"review-by": { type: "string" }
|
|
2334
|
+
"review-by": { type: "string" },
|
|
2335
|
+
sources: { type: "string" },
|
|
2336
|
+
bindings: { type: "string" }
|
|
1954
2337
|
}
|
|
1955
2338
|
});
|
|
1956
2339
|
format = values.format;
|
|
@@ -1977,11 +2360,30 @@ async function main() {
|
|
|
1977
2360
|
"setup",
|
|
1978
2361
|
"run",
|
|
1979
2362
|
"review",
|
|
1980
|
-
"review-record"
|
|
2363
|
+
"review-record",
|
|
2364
|
+
"source-check",
|
|
2365
|
+
"source-record"
|
|
1981
2366
|
].includes(positionals[0] ?? ""))
|
|
1982
|
-
throw new InputError("Expected command: verify, snapshot, explain, init, setup, diff, run, review, review-record, doctor, hook or hook-config (use --help for usage)");
|
|
2367
|
+
throw new InputError("Expected command: verify, snapshot, explain, init, setup, diff, run, review, review-record, source-check, source-record, doctor, hook or hook-config (use --help for usage)");
|
|
1983
2368
|
const cwd = process.cwd();
|
|
1984
2369
|
const command = positionals[0];
|
|
2370
|
+
if (command === "source-check" || command === "source-record") {
|
|
2371
|
+
const allowed = [
|
|
2372
|
+
"config",
|
|
2373
|
+
"profile",
|
|
2374
|
+
"scope",
|
|
2375
|
+
"constraints",
|
|
2376
|
+
"as-of",
|
|
2377
|
+
"format",
|
|
2378
|
+
...command === "source-check" ? ["sources"] : ["bindings", "output"]
|
|
2379
|
+
];
|
|
2380
|
+
for (const key of Object.keys(values))
|
|
2381
|
+
if (!allowed.includes(key))
|
|
2382
|
+
throw new InputError(`--${key} is not supported by ${command}`);
|
|
2383
|
+
return await sourceCommand(cwd, command, values);
|
|
2384
|
+
}
|
|
2385
|
+
if (values.sources !== undefined || values.bindings !== undefined)
|
|
2386
|
+
throw new InputError("--sources and --bindings are source-check/source-record-only");
|
|
1985
2387
|
if (command === "review" || command === "review-record") {
|
|
1986
2388
|
const allowed = [
|
|
1987
2389
|
"config",
|
|
@@ -2025,8 +2427,8 @@ async function main() {
|
|
|
2025
2427
|
}
|
|
2026
2428
|
if (!values.before?.trim() || !values.after?.trim())
|
|
2027
2429
|
throw new InputError("diff requires --before <snapshot> and --after <snapshot>");
|
|
2028
|
-
const before = parseHandoff((await readJsonRecord(
|
|
2029
|
-
const after = parseHandoff((await readJsonRecord(
|
|
2430
|
+
const before = parseHandoff((await readJsonRecord(resolve10(cwd, values.before))).input);
|
|
2431
|
+
const after = parseHandoff((await readJsonRecord(resolve10(cwd, values.after))).input);
|
|
2030
2432
|
const result2 = diffSnapshots(before, after);
|
|
2031
2433
|
process.stdout.write(format === "json" ? `${JSON.stringify(result2, null, 2)}
|
|
2032
2434
|
` : diffText(result2, format === "markdown"));
|
|
@@ -2177,7 +2579,7 @@ ${result2.notice}
|
|
|
2177
2579
|
for (const key of ["constraints", "handoff", "config"])
|
|
2178
2580
|
if (values[key] !== undefined && !values[key].trim())
|
|
2179
2581
|
throw new InputError(`--${key}: expected a non-empty path`);
|
|
2180
|
-
const manifestRecord = await readJsonRecord(values.constraints !== undefined ?
|
|
2582
|
+
const manifestRecord = await readJsonRecord(values.constraints !== undefined ? resolve10(cwd, values.constraints) : resolve10(directory, config.constraints ?? "constraints.json"));
|
|
2181
2583
|
const manifest = parseManifest(manifestRecord.input);
|
|
2182
2584
|
checkProject(manifest, undefined, config.projectId);
|
|
2183
2585
|
if (command === "explain") {
|
|
@@ -2202,10 +2604,10 @@ ${result2.notice}
|
|
|
2202
2604
|
else {
|
|
2203
2605
|
if (!values.output.trim())
|
|
2204
2606
|
throw new InputError("--output: expected a non-empty path");
|
|
2205
|
-
const path =
|
|
2607
|
+
const path = resolve10(cwd, values.output);
|
|
2206
2608
|
let handle;
|
|
2207
2609
|
try {
|
|
2208
|
-
handle = await
|
|
2610
|
+
handle = await open7(path, "wx", 420);
|
|
2209
2611
|
} catch {
|
|
2210
2612
|
throw new InputError(`Cannot create snapshot '${path}'; choose a new file with an existing parent directory`);
|
|
2211
2613
|
}
|
|
@@ -2228,7 +2630,7 @@ ${result2.notice}
|
|
|
2228
2630
|
}
|
|
2229
2631
|
if (values.task !== undefined || values.output !== undefined)
|
|
2230
2632
|
throw new InputError("--task and --output are only supported by snapshot");
|
|
2231
|
-
const handoffRecord = await readJsonRecord(values.handoff !== undefined ?
|
|
2633
|
+
const handoffRecord = await readJsonRecord(values.handoff !== undefined ? resolve10(cwd, values.handoff) : resolve10(directory, config.handoff ?? "handoff.json"));
|
|
2232
2634
|
const handoff = parseHandoff(handoffRecord.input);
|
|
2233
2635
|
if (values["require-content"] && handoff.schemaVersion === 1)
|
|
2234
2636
|
throw new InputError("Content tracking requires a schemaVersion 2, 3 or 4 handoff; review current rules and capture a snapshot before resuming");
|
|
@@ -9,8 +9,8 @@ infers rules from a summary.
|
|
|
9
9
|
From the consuming repository root:
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
npx handoff-check@0.
|
|
13
|
-
npx handoff-check@0.
|
|
12
|
+
npx handoff-check@0.10.0 init --scope staging --agent both --dry-run
|
|
13
|
+
npx handoff-check@0.10.0 init --scope staging --agent both
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
Choose `codex`, `claude`, `both` (default), or `none`. Generated integrations:
|
|
@@ -39,8 +39,8 @@ npm pack
|
|
|
39
39
|
From a separate consuming project, substitute the actual absolute tarball path:
|
|
40
40
|
|
|
41
41
|
```sh
|
|
42
|
-
npx --offline --yes --package=/absolute/path/handoff-check-0.
|
|
43
|
-
npx --offline --yes --package=/absolute/path/handoff-check-0.
|
|
42
|
+
npx --offline --yes --package=/absolute/path/handoff-check-0.10.0.tgz handoff-check init --scope staging --agent both
|
|
43
|
+
npx --offline --yes --package=/absolute/path/handoff-check-0.10.0.tgz handoff-check verify --format json --require-content
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
Bun is not required for these consumer commands. Generated agent commands use the
|
package/docs/architecture.md
CHANGED
|
@@ -48,6 +48,12 @@ active selection and never modifies applicability. Review-record explicitly
|
|
|
48
48
|
captures selected active references without merging or refreshing handoffs.
|
|
49
49
|
Neither verify/run nor lifecycle/doctor load the registry. See ADR 0009.
|
|
50
50
|
|
|
51
|
+
Source inspection is another explicit adapter. Pure source selection/checking
|
|
52
|
+
accepts CLI-supplied observations; only the filesystem adapter resolves declared
|
|
53
|
+
local bindings and streams bounded raw-byte hashes. Independent plan/registry/
|
|
54
|
+
result schemas preserve existing rule hashes and policy. Default commands do not
|
|
55
|
+
read these files. See ADR 0010 for path, byte, race and OS/platform limits.
|
|
56
|
+
|
|
51
57
|
Exit codes: 0 for verified IDs, 1 for rule mismatches, 2 for invalid input or an
|
|
52
58
|
unreadable input file. JSON output is intended for agent adapters and automation.
|
|
53
59
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# ADR 0010: explicit bounded whole-file source checks
|
|
2
|
+
|
|
3
|
+
Status: accepted for 0.10.0.
|
|
4
|
+
|
|
5
|
+
Keep source inspection separate from default verification. A v1 binding plan
|
|
6
|
+
declares rule IDs and portable project-relative paths; source-record captures
|
|
7
|
+
selected/global active rules into a v1 registry with existing rule revision/hash,
|
|
8
|
+
whole-file SHA-256 and informational capturedAt. Both metadata formats support
|
|
9
|
+
strict matching optional project binding without evolving old manifest/handoff/
|
|
10
|
+
review contracts. No URL, source-reference or directory-scan inference.
|
|
11
|
+
|
|
12
|
+
Source-check uses explain's lifecycle selection and validates current rule
|
|
13
|
+
references before file I/O. Missing/stale/inactive/orphan entries do not trigger
|
|
14
|
+
source reads. Orphan registry IDs need attention project-wide; known inactive
|
|
15
|
+
ones are ignored/count. Empty active sets need attention. Source-record requires
|
|
16
|
+
every selected active rule mapped and rejects unknown plan IDs before reading.
|
|
17
|
+
Capture is explicit after review, stdout or exclusive new output only; no merge,
|
|
18
|
+
adoption, overwrite, baseline refresh or implicit enforcement.
|
|
19
|
+
|
|
20
|
+
Files resolve below the canonical config-directory project root. Portable path
|
|
21
|
+
validation, component symlink rejection, realpath containment, nonblocking /
|
|
22
|
+
no-follow open where available, regular-file and device/inode agreement provide
|
|
23
|
+
ordinary filesystem safeguards. Bound reads stream raw bytes up to an inclusive
|
|
24
|
+
10 MiB with growth enforcement; metadata allows at most 256 entries. Cache each
|
|
25
|
+
exact path string's observation (including failures) once per invocation. Source
|
|
26
|
+
text is never rendered/retained; no semantic diff, mtime shortcuts or sections.
|
|
27
|
+
|
|
28
|
+
Source-check exits 0 unchanged, 1 attention, 2 invalid metadata/invocation. Source
|
|
29
|
+
unavailability/unsafe/oversize is per-file attention; capture failure is invalid
|
|
30
|
+
and produces no registry. Report JSON is independently versioned. Existing verify,
|
|
31
|
+
run, review, doctor and lifecycle behavior must not implicitly load these files.
|
|
32
|
+
|
|
33
|
+
This is not authentication, permission or a race-free sandbox. Root symlinks may
|
|
34
|
+
resolve to an explicitly selected project; descendants reject links. OS/platform/
|
|
35
|
+
hard-link semantics and concurrent replacement/writes remain limitations, with no
|
|
36
|
+
atomic historical read or guaranteed timeout for stuck OS I/O. Fixed as-of affects
|
|
37
|
+
rule selection only; file bytes are current, capturedAt unauthenticated metadata.
|
|
38
|
+
Pilot measurements, section bindings and relationship diagnostics remain future
|
|
39
|
+
work, not validation claims attached to this implementation.
|
package/docs/development-plan.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Development plan
|
|
2
2
|
|
|
3
|
-
Status: milestones through 0.
|
|
3
|
+
Status: milestones through 0.10 are implemented; later milestones remain proposed.
|
|
4
4
|
Research reviewed: 2026-11-24. Version labels below are targets, not release promises.
|
|
5
5
|
|
|
6
6
|
## Product direction
|
|
@@ -152,13 +152,21 @@ See [usage](rule-reviews.md). No human identity/time authentication, implicit
|
|
|
152
152
|
notifications, baseline refresh or automatic registry merge. Pilot evidence and
|
|
153
153
|
real-world maintenance measurements remain future work.
|
|
154
154
|
|
|
155
|
-
##
|
|
155
|
+
## 0.10: explicit local source changes (implemented)
|
|
156
|
+
|
|
157
|
+
Implemented under [ADR 0010](decisions/0010-explicit-local-source-checks.md): explicit
|
|
158
|
+
binding plans, source-record capture and source-check reports for bounded raw
|
|
159
|
+
whole-file hashes. Rule/reference/project/lifecycle checks precede explicit file
|
|
160
|
+
reads. No URL fetching, semantic diff, automatic refresh or implicit enforcement.
|
|
161
|
+
See [usage and filesystem limits](local-sources.md). Section bindings and actual
|
|
162
|
+
pilot measurements remain future work.
|
|
163
|
+
|
|
164
|
+
## Later: relationship maintenance, gated by pilot demand
|
|
156
165
|
|
|
157
166
|
Priority: medium. Keep source inspection separate from normal verify semantics.
|
|
158
167
|
|
|
159
|
-
-
|
|
160
|
-
|
|
161
|
-
rule's meaning changed. Decide full-file versus section binding deliberately.
|
|
168
|
+
- Whole-file source bindings shipped in 0.10. Consider section-level bindings only
|
|
169
|
+
with pilot demand and explicit versioned parsing/normalization semantics.
|
|
162
170
|
- Ownership/review-by shipped in 0.9 in a separate registry. Revisit team-specific
|
|
163
171
|
policies only with pilot demand, keeping overdue review distinct from expiry.
|
|
164
172
|
- Consider explicitly declared relationships such as conflicts/requires. Validate
|
package/docs/explainability.md
CHANGED
|
@@ -6,8 +6,8 @@ No service, model call or API key is needed.
|
|
|
6
6
|
## Understand the active set
|
|
7
7
|
|
|
8
8
|
```sh
|
|
9
|
-
npx handoff-check@0.
|
|
10
|
-
npx handoff-check@0.
|
|
9
|
+
npx handoff-check@0.10.0 explain --format json
|
|
10
|
+
npx handoff-check@0.10.0 explain --scope production --format markdown
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Explain reads the manifest but not the handoff. Every rule has an applicability
|
|
@@ -20,8 +20,8 @@ exits 0 even with zero active rules: use verify to compare a handoff.
|
|
|
20
20
|
At a reviewed handoff creation, after upgrading all consumers to 0.4+:
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
|
-
npx handoff-check@0.
|
|
24
|
-
npx handoff-check@0.
|
|
23
|
+
npx handoff-check@0.10.0 snapshot --task "Review staging migrations" --include-content --output handoff.reviewed.json
|
|
24
|
+
npx handoff-check@0.10.0 verify --handoff handoff.reviewed.json --require-content --require-active --format markdown
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
Review the new file before explicitly adopting it in config. Snapshot never
|