Skip to content

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.

fix(init): preserve distinct staged setup versions [I1,I2]

Corey Olson0a8b40ed9280
diff --git a/src/init-finish.js b/src/init-finish.js
index 400da2ff..8c05a8fd 100644
--- a/src/init-finish.js
+++ b/src/init-finish.js
@@ -46,6 +46,11 @@ import { Refused } from './refused.js';
export const SETUP_COMMIT_QUESTION = 'Commit Pullboard setup now? [Y/n] ';
export const SETUP_COMMIT_LATER = "To commit Pullboard's files: pullboard init --yes";
+/** Bind content to the executable mode Git records. */
+function setupFingerprint(mode, content) {
+ return createHash('sha256').update(mode + ':').update(content).digest('hex');
+}
+
/** Hash regular files and Git's executable bit, refusing external paths and symlink targets. */
function setupFile(root, name) {
if (typeof name !== 'string' || isAbsolute(name) || name.includes('\0')) return null;
@@ -56,21 +61,37 @@ function setupFile(root, name) {
if (!stat.isFile()) return null;
const physical = relative(root, realpathSync(path));
if (physical === '..' || physical.startsWith('..' + sep)) return null;
- return createHash('sha256').update(stat.mode & 0o111 ? '100755:' : '100644:').update(readFileSync(path)).digest('hex');
+ return setupFingerprint(stat.mode & 0o111 ? '100755' : '100644', readFileSync(path));
} catch (error) { if (error.code === 'ENOENT') return null; throw error; }
}
+/** Read a regular stage-zero index entry without replacing either version of a partial edit. */
+function indexedSetupFile(root, name) {
+ const entry = tryGit(root, ['ls-files', '--stage', '-z', '--', `:(literal)${name}`]);
+ const match = /^(100644|100755) ([a-f0-9]{40,64}) 0\t[^\0]+\0$/u.exec(entry.stdout);
+ if (entry.status !== 0 || !match) return null;
+ const blob = spawnSync('git', ['--no-replace-objects', 'cat-file', 'blob', match[2]],
+ { cwd: root, maxBuffer: 32 * 1024 * 1024 });
+ return blob.status === 0 ? setupFingerprint(match[1], blob.stdout) : null;
+}
+
/** Capture existing edits before init writes, and retain only unchanged previous setup receipts. */
export function beginInitCommit(info) {
const status = spawnSync('git', ['--no-replace-objects', 'status', '--porcelain=v1', '-z', '--untracked-files=all', '--ignored=matching'],
{ cwd: info.root, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });
if (status.status !== 0) throw new Refused('NOT_COMMITTED', 'Git could not read the existing changes; fix Git before running pullboard init again');
- const entries = status.stdout.split('\0'), blocked = new Set();
+ const entries = status.stdout.split('\0'), blocked = new Set(), staged = new Set();
for (let index = 0; index < entries.length; index++) {
const entry = entries[index];
if (!entry) continue;
- blocked.add(entry.slice(3));
- if (/[RC]/u.test(entry.slice(0, 2))) blocked.add(entries[++index]);
+ const name = entry.slice(3), indexChanged = ![' ', '?', '!'].includes(entry[0]);
+ blocked.add(name);
+ if (indexChanged) staged.add(name);
+ if (/[RC]/u.test(entry.slice(0, 2))) {
+ const previousName = entries[++index];
+ blocked.add(previousName);
+ if (indexChanged) staged.add(previousName);
+ }
}
const file = join(info.commonDir, 'pullboard', 'setup-written-files.json');
let previous = {};
@@ -81,7 +102,7 @@ export function beginInitCommit(info) {
const files = new Map(), skipped = new Set();
for (const [name, hash] of Object.entries(previous)) {
const actual = setupFile(info.root, name);
- if (hash && actual === hash) files.set(name, hash);
+ if (hash && actual === hash && (!staged.has(name) || indexedSetupFile(info.root, name) === hash)) files.set(name, hash);
else if (actual) skipped.add(name);
}
const owned = new Set(files.keys());
diff --git a/test/init-ignore.test.js b/test/init-ignore.test.js
index 34b2c767..387cdad4 100644
--- a/test/init-ignore.test.js
+++ b/test/init-ignore.test.js
@@ -127,6 +127,24 @@ test('setup confirmation leaves a later executable-mode edit uncommitted [I1,I2]
assert.match(box.git('diff', '--summary'), /mode change/u);
});
+test('setup confirmation preserves a different version staged from its saved working bytes [I1,I2]', t => {
+ const box = fixture(t);
+ rmSync(join(box.root, 'pullboard.json'));
+ writeFileSync(join(box.root, 'README.md'), '# Existing repository\n');
+ box.git('add', 'README.md'); box.git('commit', '-q', '-m', 'chore: initial repository');
+ assert.equal(box.cli('init').code, 0);
+ const file = join(box.root, 'SPEC.md'), original = readFileSync(file, 'utf8');
+ const staged = original + '\nA note held only in the index.\n';
+ writeFileSync(file, staged); box.git('add', 'SPEC.md');
+ writeFileSync(file, original);
+ const before = box.git('diff', '--cached', '--binary', '--', 'SPEC.md');
+ const confirmed = box.cli('init', '--yes');
+ assert.equal(confirmed.code, 0, confirmed.stderr);
+ assert.equal(box.git('show', ':SPEC.md'), staged.trimEnd(), 'the distinct staged version survives');
+ assert.equal(box.git('diff', '--cached', '--binary', '--', 'SPEC.md'), before, 'the staged patch remains exact');
+ assert.equal(readFileSync(file, 'utf8'), original, 'the working version remains exact too');
+});
+
test('a fresh init tells the person and the agent how to start [I9,I1]', t => {
const box = fixture(t);
rmSync(join(box.root, 'pullboard.json'));