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(worktree): suggest an install only when there are deps [I1,L3]

Corey Olson26904e5b1701
diff --git a/src/cli.js b/src/cli.js
index cbebab1c..a93c0f08 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -93,6 +93,7 @@ import { relayJoin, relayPair } from './relay-pairing-client.js';
import { executePersonRequests } from './relay-request-execution.js';
import { engineReceipt } from './engine.js';
import { land, landingRemote, landingSubject } from './land.js';
+import { installStep } from './worktree.js';
const CHECKOUT_LEASES = new WeakMap();
const CHECKOUT_BOARD_ONLY = new WeakMap();
@@ -1786,7 +1787,8 @@ async function worktreeFor(io, lane, route, family = null, model) {
io.result?.({ agent: id, lane, route, path: root, branch: `${lane}/${n}`, model, displayName, prompt });
io.say(`made ${root} on branch ${lane}/${n}, joined as ${displayName} in the ${lane} lane${route === 'light' ? ', on the light route' : ''}${family ? ` (family ${family})` : ''}`);
io.say(`Work only in that folder. A shell that starts each command in the main checkout acts as the coordinator there, so start every command with: ${cdTo(root)}`);
- if (existsSync(join(root, 'package.json'))) io.say(` ${cdTo(root)} npm install (its own install, so its tests run its own code)`);
+ const install = installStep(root);
+ if (install) io.say(` ${cdTo(root)} ${install.command} (${install.note})`);
io.say(` ${cdTo(root)} pullboard inbox`);
io.say(` ${cdTo(root)} pullboard next`);
// A subagent inherits the instructions of the session that launched it, often another repo's (I7).
diff --git a/src/worktree.js b/src/worktree.js
new file mode 100644
index 00000000..1191163d
--- /dev/null
+++ b/src/worktree.js
@@ -0,0 +1,58 @@
+import { existsSync, readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { cleanGitEnvironment, tryGit } from './git.js';
+
+/** The npm lockfiles `npm ci` installs from, in the order npm itself prefers them. */
+const NPM_LOCKFILES = ['npm-shrinkwrap.json', 'package-lock.json'];
+
+/**
+ * Count the packages a package.json declares under dependencies and devDependencies.
+ *
+ * An unreadable or malformed package.json counts as none: an install would fail on it anyway.
+ *
+ * @param {string} root
+ * @returns {number}
+ */
+function declaredDependencies(root) {
+ const file = join(root, 'package.json');
+ if (!existsSync(file)) return 0;
+ let manifest;
+ try { manifest = JSON.parse(readFileSync(file, 'utf8')); } catch { return 0; }
+ if (!manifest || typeof manifest !== 'object') return 0;
+ const count = (field) => (field && typeof field === 'object' && !Array.isArray(field) ? Object.keys(field).length : 0);
+ return count(manifest.dependencies) + count(manifest.devDependencies);
+}
+
+/**
+ * Name the npm lockfile git tracks in `root`, or null when none is committed.
+ *
+ * A lockfile counts only when git tracks it: one that merely sits on disk is what an earlier
+ * install wrote, and `npm ci` from it would install something the commit does not record.
+ *
+ * @param {string} root
+ * @returns {string | null}
+ */
+function committedLockfile(root) {
+ const listed = tryGit(root, ['ls-files', '-z', '--', ...NPM_LOCKFILES], { env: cleanGitEnvironment() });
+ if (listed.status !== 0) return null;
+ const tracked = new Set(listed.stdout.split('\0').filter(Boolean));
+ return NPM_LOCKFILES.find((name) => tracked.has(name)) ?? null;
+}
+
+/**
+ * The install step a new worktree's next steps suggest, or null when the project needs none.
+ *
+ * A zero-dependency project gets no step, because `npm install` there only writes a
+ * package-lock.json the first submit then refuses as UNTRACKED (I1, L3). A committed lockfile
+ * gets `npm ci`, which installs exactly what it records and writes nothing. Without one,
+ * `npm install` is still the step, with a note that the lockfile it writes must be committed.
+ *
+ * @param {string} root - The new worktree's top level.
+ * @returns {{ command: string, note: string } | null}
+ */
+export function installStep(root) {
+ if (declaredDependencies(root) === 0) return null;
+ const lockfile = committedLockfile(root);
+ if (lockfile) return { command: 'npm ci', note: `its own install from the committed ${lockfile}, so its tests run its own code` };
+ return { command: 'npm install', note: 'its own install; it writes package-lock.json, so commit that file or the first submit is refused UNTRACKED' };
+}
diff --git a/test/worktree-start.test.js b/test/worktree-start.test.js
index 6a7b83fa..027d7d0c 100644
--- a/test/worktree-start.test.js
+++ b/test/worktree-start.test.js
@@ -1,9 +1,11 @@
/** A fresh main checkout uses its declared model for an agent worktree [I1,I2]. */
import assert from 'node:assert/strict';
+import { mkdirSync, writeFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { after, test } from 'node:test';
import { createE2eHelpers } from './e2e-helpers.js';
import { runFixtureChild } from './fixture-child.js';
+import { installStep } from '../src/worktree.js';
const e2e = createE2eHelpers();
after(e2e.cleanup);
@@ -69,3 +71,56 @@ test("the README's worktree command works in a fresh repo [I1,I2]", () => {
assert.equal(JSON.parse(missingJoinJson.out).error.next,
'run pullboard join api --model "<model name>"');
});
+
+test('worktree suggests no install for a zero-dependency project [I1,L3]', () => {
+ const box = sandbox();
+ // Git selectors inherited from a hook would point the fixture's git at the outer repository.
+ for (const key of Object.keys(box.env)) if (key.startsWith('GIT_') && !key.startsWith('GIT_CONFIG_') && !/^GIT_(?:AUTHOR|COMMITTER)_/u.test(key)) delete box.env[key];
+ const { repo } = project('true', box);
+ box.env.CODEX_THREAD_ID = 'main-owner-session';
+ box.env.PULLBOARD_MODEL = 'Install Step Model';
+ const coordinator = box.run(repo, 'join', 'coordinator');
+ assert.equal(coordinator.code, 0, coordinator.err || coordinator.out);
+ /** Commit files on main as the coordinator, then make a web worktree and return its output. */
+ const worktreeAfter = (files) => {
+ for (const [name, text] of Object.entries(files)) writeFileSync(join(repo, name), text);
+ box.git(repo, 'add', '-A');
+ box.git(repo, 'commit', '-q', '-m', 'chore: change the package');
+ const made = box.run(repo, 'worktree', 'web');
+ assert.equal(made.code, 0, made.err || made.out);
+ return made.out;
+ };
+
+ const none = worktreeAfter({ 'package.json': JSON.stringify({ name: 'demo', scripts: { test: 'true' }, dependencies: {}, devDependencies: {} }) });
+ assert.doesNotMatch(none, /\bnpm (?:install|ci)\b/u, 'a package.json without dependencies gets no install step');
+ assert.match(none, /pullboard inbox\n/u, 'the other next steps still print');
+
+ const locked = worktreeAfter({
+ 'package.json': JSON.stringify({ name: 'demo', devDependencies: { 'left-pad': '1.3.0' } }),
+ 'package-lock.json': JSON.stringify({ name: 'demo', lockfileVersion: 3, packages: {} }),
+ });
+ assert.match(locked, /\bnpm (?:install|ci)\b/u, 'devDependencies alone count as dependencies');
+ assert.match(locked, /&& npm ci {4}\(its own install from the committed package-lock\.json, so its tests run its own code\)\n/u,
+ 'a committed lockfile gets npm ci');
+ assert.doesNotMatch(locked, /\bnpm install\b/u, 'npm install would rewrite the committed lockfile');
+
+ box.git(repo, 'rm', '-q', 'package-lock.json');
+ const unlocked = worktreeAfter({ 'package.json': JSON.stringify({ name: 'demo', dependencies: { 'left-pad': '1.3.0' } }) });
+ assert.match(unlocked, /&& npm install {4}\(its own install; it writes package-lock\.json, so commit that file or the first submit is refused UNTRACKED\)\n/u,
+ 'without a committed lockfile the step is npm install, with the lockfile it writes named for commit');
+ assert.doesNotMatch(unlocked, /\bnpm ci\b/u, 'npm ci fails without a lockfile');
+
+ // A lockfile on disk that git does not track is not committed; a tracked shrinkwrap is.
+ const loose = join(box.dir, 'loose');
+ mkdirSync(loose);
+ box.git(loose, 'init', '-q', '-b', 'main');
+ writeFileSync(join(loose, 'package.json'), JSON.stringify({ name: 'loose', dependencies: { 'left-pad': '1.3.0' } }));
+ box.git(loose, 'add', 'package.json');
+ box.git(loose, 'commit', '-q', '-m', 'chore: package');
+ writeFileSync(join(loose, 'package-lock.json'), '{}');
+ assert.equal(installStep(loose)?.command, 'npm install', 'an untracked package-lock.json does not count as committed');
+ writeFileSync(join(loose, 'npm-shrinkwrap.json'), '{}');
+ box.git(loose, 'add', 'npm-shrinkwrap.json');
+ assert.deepEqual(installStep(loose), { command: 'npm ci', note: 'its own install from the committed npm-shrinkwrap.json, so its tests run its own code' },
+ 'a tracked npm-shrinkwrap.json is a committed lockfile');
+});