Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(map): verify consumed input bytes against main objects [C7,A1]
Corey Olson52779f5958fd
diff --git a/docs/api.md b/docs/api.mdindex bca33720..c08afc6d 100644--- a/docs/api.md+++ b/docs/api.md@@ -75,7 +75,7 @@ For example: `flow: review wait average 61 min (1 measured; > 60 min); bottlenec`merged <id> <commit>` records only a commit reachable from the primary checkout's branch that contains the item's submitted commit or has the same stable patch id as the item's change from its claim base. Other commits are refused with `NOT_MERGED`; `--note "why"` records an exceptional receipt and keeps the note in that item's `merged` event.-`map --json`, `map <module or function> --json`, and `map --for <item> --json` return the same envelope: `main` is the scanned primary-main commit and `map` is the rendered overview, card, or bounded item slice. Ordinary text output is that same map text. Fresh scans require `src/`, `bin/`, and `test/` to match committed main: changed, untracked, and ignored entries in those directories refuse the scan. Ignore rules alone do not refuse it. A cached committed map does not incorporate later working-tree changes. The scanner reports unobserved effects as `not detected`; the map is source context, not proof that an effect cannot occur.+`map --json`, `map <module or function> --json`, and `map --for <item> --json` return the same envelope: `main` is the scanned primary-main commit and `map` is the rendered overview, card, or bounded item slice. Ordinary text output is that same map text. Fresh scans require `src/`, `bin/`, and `test/` to match committed main: changed, untracked, and ignored entries in those directories refuse the scan. Ignore rules alone do not refuse it. Every scanned path, regular-file mode and consumed byte is checked against the committed Git object, including edits hidden by index flags; symbolic input files refuse instead of reading their external targets. A cached committed map does not incorporate later working-tree changes. The scanner reports unobserved effects as `not detected`; the map is source context, not proof that an effect cannot occur.<!-- api-command-shapes:start -->`status --json` and local API state carry `ruleCounts`: `approved`, `gated` (approved rows naming a gate), `ungated`, `proven`, `unproven`, and `contradicted`. Proof requires a green configured full-gate receipt on the current trunk whose supported test selection includes the row's test files. Opaque or unsupported coverage remains unproven. Contradicted counts approved rows whose gate files failed on the trunk in the last seven days; it is independent of proven, so a row can count in both after a later green. The API refreshes this window when evidence ages out, even without a board move.diff --git a/src/code-map.js b/src/code-map.jsindex 9c0af050..19a0d786 100644--- a/src/code-map.js+++ b/src/code-map.js@@ -5,8 +5,10 @@import {execFileSync,} from 'node:child_process';+import { createHash } from 'node:crypto';import {existsSync,+ lstatSync,mkdirSync,readFileSync,readdirSync,@@ -329,6 +331,40 @@ function requireSourcePin(root, commit) {}}+/** Read committed modes and object IDs once; NUL records preserve unusual input path names. */+function committedInputs(root, commit) {+ const inputs = new Map();+ for (const record of gitText(root, ['ls-tree', '-r', '-z', commit, '--', 'src', 'bin', 'test']).split('\0')) {+ if (!record) continue;+ const separator = record.indexOf('\t');+ const path = record.slice(separator + 1);+ if (!/^(?:src|bin)\/.*\.m?js$/u.test(path) && !/^test\/.*\.test\.m?js$/u.test(path)) continue;+ const metadata = record.slice(0, separator).split(' ');+ if (separator < 0 || metadata.length !== 3 || metadata[1] !== 'blob'+ || !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/u.test(metadata[2])) {+ throw new Error(`${path} differs from the committed main source`);+ }+ inputs.set(path, { mode: metadata[0], object: metadata[2] });+ }+ return inputs;+}++/** Validate the exact bytes consumed, including index-hidden edits and external symbolic targets. */+function readPinnedInput(root, path, inputs) {+ const expected = inputs.get(path);+ const file = join(root, path);+ const mode = lstatSync(file);+ if (!expected || !['100644', '100755'].includes(expected.mode) || !mode.isFile()+ || Boolean(mode.mode & 0o111) !== (expected.mode === '100755')) {+ throw new Error(`${path} differs from the committed main source`);+ }+ const bytes = readFileSync(file);+ const object = createHash(expected.object.length === 64 ? 'sha256' : 'sha1')+ .update(`blob ${bytes.length}\0`).update(bytes).digest('hex');+ if (object !== expected.object) throw new Error(`${path} differs from the committed main source`);+ return bytes.toString('utf8');+}+/** Resolve one relative import to a scanned source module; external packages stay unresolved. */function resolveModule(from, specifier, modules) {if (!specifier.startsWith('.')) return null;@@ -363,8 +399,8 @@ function exportedDefiner(modules, modulePath, name, seen = new Set()) {}/** Read only syntactic test imports, ignoring import-shaped text in comments and strings. */-function testImports(root, testPath, modules) {- const source = readFileSync(join(root, testPath), 'utf8');+function testImports(root, testPath, modules, inputs) {+ const source = readPinnedInput(root, testPath, inputs);const { masked } = mask(source);const found = new Set();const pattern = /(?:^|\n)\s*import\s+(?:[\s\S]*?\s+from\s+)?(['"])([^'"\r\n]+)\1/gu;@@ -385,10 +421,15 @@ export function buildCodeMap(root, mainCommit) {if (!/^[\da-f]{40,64}$/u.test(commit)) throw new Error('a full main commit is required to stamp the map');requireSourcePin(sourceRoot, commit);const files = [...listJavaScript(sourceRoot, 'src'), ...listJavaScript(sourceRoot, 'bin')].sort();+ const testPaths = listJavaScript(sourceRoot, 'test').filter(path => /\.test\.m?js$/u.test(path));+ const inputs = committedInputs(sourceRoot, commit);+ if (JSON.stringify([...inputs.keys()].sort()) !== JSON.stringify([...files, ...testPaths].sort())) {+ throw new Error('the scanned input paths differ from the committed main source');+ }const modules = new Map();let sourceChars = 0;for (const path of files) {- const source = readFileSync(join(sourceRoot, path), 'utf8');+ const source = readPinnedInput(sourceRoot, path, inputs);sourceChars += source.length;modules.set(path, scanSource(path, source));}@@ -459,9 +500,8 @@ export function buildCodeMap(root, mainCommit) {}} catch { /* Missing history leaves churn unknown at zero; source edges remain available. */ }- const testPaths = listJavaScript(sourceRoot, 'test').filter(path => /\.test\.m?js$/u.test(path));const testsByModule = new Map([...modules.keys()].map(path => [path, []]));- for (const testPath of testPaths) for (const target of testImports(sourceRoot, testPath, modules)) testsByModule.get(target)?.push(testPath);+ for (const testPath of testPaths) for (const target of testImports(sourceRoot, testPath, modules, inputs)) testsByModule.get(target)?.push(testPath);const serializedModules = [...modules.values()].map(module => ({path: module.path,job: module.job,