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(git): scope committed source facts to resume [C7,N19]
Corey Olson3a92aaa87469
diff --git a/src/cli-main.js b/src/cli-main.jsindex 2698a048..18758082 100644--- a/src/cli-main.js+++ b/src/cli-main.js@@ -255,7 +255,7 @@ export async function main(argv, streams) {// Version and help ask Git nothing, so they never load it.if (asksGitNothing(argv)) return runMain(argv, streams);const { withGitFacts } = await import('./git.js');- return withGitFacts(() => runMain(argv, streams));+ return withGitFacts(() => runMain(argv, streams), { resumeSources: argv[0] === 'resume' });}/** Parse and execute one CLI command, binding its checkout session and Git-fact scope. */diff --git a/src/git.js b/src/git.jsindex 875021bd..cbd57945 100644--- a/src/git.js+++ b/src/git.js@@ -48,8 +48,8 @@ export function withGitReadFacts(work) {* @param {() => unknown} work* @returns {Promise<unknown>}*/-export async function withGitFacts(work) {- const cache = { active: true, facts: new Map() };+export async function withGitFacts(work, { resumeSources = false } = {}) {+ const cache = { active: true, facts: new Map(), resumeSources };const run = () => gitFacts.run(cache, async () => {try { return await work(); }finally {@@ -547,21 +547,26 @@ export function repoInfo(cwd, { env } = {}) {*/function readRepoInfo(cwd, env) {const combined = !env && gitFacts.getStore()?.active && plainRepositoryEnvironment();- const primary = combined ? ['HEAD^{commit}', 'main-worktree/HEAD^{commit}', '--git-path', 'hooks', 'main-worktree/HEAD:pullboard.json', 'main-worktree/HEAD:DOCTRINE.md', '--symbolic-full-name', 'main-worktree/HEAD'] : [];+ const resumeSources = combined && gitFacts.getStore().resumeSources;+ const optional = ['main-worktree/HEAD:pullboard.json', 'main-worktree/HEAD:DOCTRINE.md'];+ const primary = combined ? ['HEAD^{commit}', 'main-worktree/HEAD^{commit}', '--git-path', 'hooks',+ ...(resumeSources ? optional : []), '--symbolic-full-name', 'main-worktree/HEAD'] : [];const info = tryGit(cwd, ['rev-parse', '--path-format=absolute', '--show-toplevel', '--git-dir', '--git-common-dir', ...primary], { env });const fields = info.stdout.split('\n');/** Recognize full SHA-1 or SHA-256 object identities before accepting a partial optional response. */const oid = value => /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/u.test(value ?? '');const baseValid = fields.length >= 6 && fields.slice(0, 3).every(isAbsolute)&& oid(fields[3]) && oid(fields[4]) && isAbsolute(fields[5]);- const optional = ['main-worktree/HEAD:pullboard.json', 'main-worktree/HEAD:DOCTRINE.md'];- const missingOptional = info.status !== 0 && (fields.length === 7 && fields[6] === optional[0]+ const missingOptional = resumeSources && info.status !== 0 && (fields.length === 7 && fields[6] === optional[0]|| fields.length === 8 && oid(fields[6]) && fields[7] === optional[1]);- if (combined && (!baseValid || info.status !== 0 && !missingOptional)) return readRepoInfo(cwd, process.env);+ if (combined && info.stdout && (!baseValid || info.status !== 0 && !missingOptional)) return readRepoInfo(cwd, process.env);if (combined && baseValid) {- const [root, , , head, commit, hooks, config, doctrine, branch] = fields;- const suffixValid = missingOptional || (fields.length === 8 || fields.length === 9)- && oid(config) && oid(doctrine) && (branch === undefined || branch.startsWith('refs/'));+ const [root, , , head, commit, hooks] = fields;+ const [config, doctrine] = resumeSources ? fields.slice(6, 8) : [];+ const branch = fields[resumeSources ? 8 : 6];+ const suffixValid = missingOptional || (resumeSources+ ? (fields.length === 8 || fields.length === 9) && oid(config) && oid(doctrine)+ : fields.length === 6 || fields.length === 7) && (branch === undefined || branch.startsWith('refs/'));if (!suffixValid) return readRepoInfo(cwd, process.env);const { facts } = gitFacts.getStore();facts.set(`gitPath:${JSON.stringify([resolve(root), 'hooks'])}`, resolve(root, hooks));diff --git a/test/git-calls.test.js b/test/git-calls.test.jsindex 70a85c51..50f3444c 100644--- a/test/git-calls.test.js+++ b/test/git-calls.test.js@@ -169,12 +169,29 @@ test('ordinary resume reads its indexed work card with at most four Git processeassert.match(renamed.result.stdout, /2 files uncommitted/u, 'a renamed path with whitespace counts once alongside the new file');});+/** Unrelated reads retain the original one-process repository miss and never request resume-only blobs. */+test('ordinary Git scopes skip resume blobs and empty repository failures do not retry [C7,N19]', t => {+ const box = fixture(t);+ const standard = readFactScenario(box, box.worker, `const { repoInfo, mainSourceBlobs } = await import(${JSON.stringify(GIT_MODULE)});+ console.log(JSON.stringify(await withGitFacts(() => { const info = repoInfo(process.argv[1]);+ return { head: headCommit(info.root), blobs: mainSourceBlobs(info.root) }; })));`);+ assert.equal(standard.head, box.git(box.worker, 'rev-parse', 'HEAD'));+ assert.equal(standard.blobs, null, 'only explicit resume scopes request committed source identities');+ writeFileSync(box.calls, '');+ const outside = readFactScenario(box, box.dir, `const { repoInfo } = await import(${JSON.stringify(GIT_MODULE)});+ console.log(JSON.stringify(await withGitFacts(() => { try { repoInfo(process.argv[1]); return null; }+ catch (error) { return error.code; } })));`);+ assert.equal(outside, 'NOT_A_REPO');+ assert.equal(readFileSync(box.calls, 'utf8').trim().split('\n').filter(Boolean).length, 1,+ 'an empty failed rev-parse goes directly to the filesystem bare-check rather than retrying Git');+});+/** Optional committed-source facts never replace Git's repository or detached-HEAD semantics. */test('combined Git source facts retain repository identity when optional doctrine is missing [C7,N19]', t => {const box = fixture(t);const script = `const { repoInfo, mainSourceBlobs, mainCheckout } = await import(${JSON.stringify(GIT_MODULE)});console.log(JSON.stringify(await withGitFacts(() => { const info = repoInfo(process.argv[1]);- return { info, head: headCommit(info.root), main: mainCheckout(info.root), blobs: mainSourceBlobs(info.root) }; })));`;+ return { info, head: headCommit(info.root), main: mainCheckout(info.root), blobs: mainSourceBlobs(info.root) }; }, { resumeSources: true })));`;const present = readFactScenario(box, box.worker, script);assert.equal(present.head, box.git(box.worker, 'rev-parse', 'HEAD'));assert.equal(present.blobs.config, box.git(box.repo, 'rev-parse', 'HEAD:pullboard.json'));