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.

feat(init): install project agent permissions [I1,I2]

Corey Olsonfec6dc2abfd0
diff --git a/src/cli.js b/src/cli.js
index 9ccc8f9c..5660965b 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -232,6 +232,7 @@ const OPTIONS = {
project: { type: 'boolean' },
export: { type: 'string' },
'no-open': { type: 'boolean' },
+ 'no-permissions': { type: 'boolean' },
note: { type: 'string' },
'note-file': { type: 'string' },
by: { type: 'string' },
@@ -1584,6 +1585,7 @@ function setupCommands(io, { first, values }) {
const notes = initRepo({
info,
model,
+ permissions: !values['no-permissions'],
openBoardHere: () => store.openBoard(join(info.commonDir, 'pullboard', 'board.sqlite'), io.clock, { isMain: codeIsFromMain() }),
/** Keep a linked coordinator's canonical identity without writing a clone-local path. */
register: (board, options) => {
diff --git a/src/help.js b/src/help.js
index d2485849..1ef28eba 100644
--- a/src/help.js
+++ b/src/help.js
@@ -10,7 +10,7 @@ Nothing ships until a second agent verifies it.
Set up
pullboard tour see it work: a reject and its rework, scripted, in thirty seconds
- pullboard init [--model <name>] config, SPEC.md, agent instructions, git hooks, board; optional coordinator model
+ pullboard init [--model <name>] [--no-permissions] config, spec, agent instructions, hooks, board and project agent rules; optional coordinator model
pullboard worktree <lane> --model <name> [--route light] [--family <name>] make and join a worktree for a new agent
pullboard join <lane> --model <name> [--route light] [--family <name>] register this worktree as an agent
A model is required (or set PULLBOARD_MODEL); family is a separate declaration
diff --git a/src/init.js b/src/init.js
index 8a5b1567..40ed9586 100644
--- a/src/init.js
+++ b/src/init.js
@@ -11,7 +11,10 @@ import { loadDoctrine } from './doctrine.js';
import { installHooks } from './hooks.js';
import { Refused } from './refused.js';
import { installSkills } from './skills.js';
-import { AGENTS_END, AGENTS_START, agentsBlock, configTemplate, practiceTemplate, specTemplate } from './templates.js';
+import {
+ AGENTS_END, AGENTS_START, agentsBlock, claudeLoopRules, codexLoopRules, configTemplate,
+ plainGateWords, practiceTemplate, specTemplate,
+} from './templates.js';
const NPM_DEFAULT_TEST = 'echo "Error: no test specified" && exit 1';
@@ -185,13 +188,81 @@ function writeSessionHook(root, onWrite) {
return 'added a Claude Code session hook: pullboard resume at every start and compaction';
}
+/**
+ * Merge only missing Claude project allow rules, preserving every unrelated setting and rule.
+ *
+ * @param {string} root
+ * @param {string} gate
+ * @param {(path: string) => void} onWrite
+ * @returns {string} A concise setup note.
+ */
+function writeClaudeLoopPermissions(root, gate, onWrite) {
+ const file = join(root, '.claude', 'settings.json');
+ let settings = {};
+ if (existsSync(file)) {
+ try {
+ settings = JSON.parse(readFileSync(file, 'utf8'));
+ } catch {
+ settings = null;
+ }
+ if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
+ return 'kept .claude/settings.json because it is not a JSON object; add the Pullboard allow rules manually';
+ }
+ }
+ const current = settings.permissions;
+ if (current !== undefined && (!current || typeof current !== 'object' || Array.isArray(current))) {
+ return 'kept .claude/settings.json because permissions is not an object; add the Pullboard allow rules manually';
+ }
+ const permissions = current ?? {};
+ const allow = permissions.allow;
+ if (allow !== undefined && !Array.isArray(allow)) {
+ return 'kept .claude/settings.json because permissions.allow is not an array; add the Pullboard allow rules manually';
+ }
+ const existing = allow ?? [];
+ const requested = claudeLoopRules({ gate });
+ const missing = requested.filter(rule => !existing.includes(rule));
+ if (!missing.length) return 'kept the existing Claude Code Pullboard permissions';
+ settings.permissions = { ...permissions, allow: [...existing, ...missing] };
+ mkdirSync(join(root, '.claude'), { recursive: true });
+ writeFileSync(file, `${JSON.stringify(settings, null, 2)}\n`);
+ onWrite('.claude/settings.json');
+ const gateWords = plainGateWords(gate);
+ const gateNote = gateWords ? `, and the detected gate (${gateWords.join(' ')})` : gate ? '; the configured shell gate was left for manual approval' : '';
+ const editNote = requested.some(rule => rule.startsWith('Edit(')) ? ', plus edits within this worktree' : '';
+ return `allowed Claude Code's Pullboard loop and listed Git commands${gateNote}${editNote}; existing deny and ask rules still apply`;
+}
+
+/**
+ * Write project-local Codex command rules without touching the user's home or active-session config.
+ *
+ * @param {string} root
+ * @param {string} gate
+ * @param {(path: string) => void} onWrite
+ * @returns {string} A concise setup note.
+ */
+function writeCodexLoopRules(root, gate, onWrite) {
+ const file = join(root, '.codex', 'rules', 'pullboard.rules');
+ const rules = codexLoopRules(gate);
+ let contents = '';
+ if (existsSync(file)) contents = readFileSync(file, 'utf8');
+ const lines = new Set(contents.split(/\r?\n/u));
+ const missing = rules.filter(rule => !lines.has(rule));
+ if (!missing.length) return 'kept the existing Codex project rules';
+ mkdirSync(join(root, '.codex', 'rules'), { recursive: true });
+ const prefix = contents && !contents.endsWith('\n') ? `${contents}\n` : contents;
+ writeFileSync(file, `${prefix}${missing.join('\n')}\n`);
+ onWrite('.codex/rules/pullboard.rules');
+ const gateNote = plainGateWords(gate) ? '' : gate ? '; the configured shell gate was left for manual approval' : '';
+ return `added trusted-project Codex rules for Pullboard and the listed Git commands${gateNote}; trust this project and restart the session to load them`;
+}
+
/**
* Set the repo up. Must run in the main checkout, which becomes the coordinator.
*
- * @param {{ info: { root: string, isMain: boolean }, openBoardHere: () => any, register: Function, closeBoard: Function, model?: string }} context
+ * @param {{ info: { root: string, isMain: boolean }, openBoardHere: () => any, register: Function, closeBoard: Function, model?: string, permissions?: boolean }} context
* @returns {string[]} What happened, one line each.
*/
-export function initRepo({ info, openBoardHere, register, closeBoard, model }) {
+export function initRepo({ info, openBoardHere, register, closeBoard, model, permissions = true }) {
if (!info.isMain) {
throw new Refused('NOT_MAIN', 'run init in the main checkout; worktrees join a lane instead');
}
@@ -200,7 +271,7 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model }) {
const gate = detectGate(root);
const written = [];
/** Record only paths setup actually writes; unrelated files never enter its staging command. */
- const onWrite = (path) => written.push(path);
+ const onWrite = (path) => { if (!written.includes(path)) written.push(path); };
const notes = [
writeNew(join(root, CONFIG_FILE), configTemplate(gate, detectFixers(root)), CONFIG_FILE, onWrite),
writeNew(join(root, 'SPEC.md'), specTemplate(basename(root), gate), 'SPEC.md', onWrite),
@@ -211,6 +282,11 @@ export function initRepo({ info, openBoardHere, register, closeBoard, model }) {
...installSkills(root, onWrite),
writeSessionHook(root, onWrite),
];
+ if (permissions) {
+ const gateForPermissions = configuredGate(root) || gate;
+ notes.push(writeClaudeLoopPermissions(root, gateForPermissions, onWrite));
+ notes.push(writeCodexLoopRules(root, gateForPermissions, onWrite));
+ }
const board = openBoardHere();
try {
register(board, { lane: COORDINATOR, path: root, model });
diff --git a/src/templates.js b/src/templates.js
index 4ca3e3fe..0d2e4d64 100644
--- a/src/templates.js
+++ b/src/templates.js
@@ -135,3 +135,49 @@ If your item needs code another lane owns and it is not there yet, shout that la
${AGENTS_END}
`;
}
+
+/** Git subcommands used directly by Pullboard's documented agent loop, never all Git commands. */
+export const PULLBOARD_LOOP_GIT_COMMANDS = Object.freeze([
+ 'status', 'diff', 'log', 'add', 'commit', 'merge', 'rebase', 'switch', 'checkout', 'worktree',
+]);
+
+/**
+ * Return gate argv only when the configured command is plain words; shell syntax is never widened
+ * into an allow rule that could hide other commands.
+ *
+ * @param {string} gate
+ * @returns {string[] | null}
+ */
+export function plainGateWords(gate) {
+ const text = String(gate ?? '').trim();
+ return /^[A-Za-z0-9_./:=@+-]+(?: [A-Za-z0-9_./:=@+-]+)*$/u.test(text) ? text.split(' ') : null;
+}
+
+/**
+ * Rules Claude Code can add to this project without changing the person's home or session settings.
+ *
+ * @param {{ gate?: string }} options
+ * @returns {string[]}
+ */
+export function claudeLoopRules({ gate = '' }) {
+ const rules = ['Bash(pullboard:*)', ...PULLBOARD_LOOP_GIT_COMMANDS.map(command => `Bash(git ${command}:*)`)];
+ const words = plainGateWords(gate);
+ if (words) rules.push(`Bash(${words.join(' ')})`);
+ // Project-relative rules follow each linked worktree's primary working directory.
+ rules.push('Edit(/**)');
+ return rules;
+}
+
+/**
+ * Codex project-local rules use argv prefixes and apply only after the project is trusted. Each
+ * pattern is intentionally scoped to one product command or one listed Git verb.
+ *
+ * @param {string} gate
+ * @returns {string[]}
+ */
+export function codexLoopRules(gate = '') {
+ const patterns = [['pullboard'], ...PULLBOARD_LOOP_GIT_COMMANDS.map(command => ['git', command])];
+ const words = plainGateWords(gate);
+ if (words) patterns.push(words);
+ return patterns.map(pattern => `prefix_rule(pattern=${JSON.stringify(pattern)}, decision="allow", justification="Run the Pullboard project loop.")`);
+}
diff --git a/test/init-permissions.test.js b/test/init-permissions.test.js
new file mode 100644
index 00000000..28181bef
--- /dev/null
+++ b/test/init-permissions.test.js
@@ -0,0 +1,136 @@
+/** Init adds only the requested project-local agent loop permissions and can skip them [I1,I2]. */
+import assert from 'node:assert/strict';
+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+import { test } from 'node:test';
+import { runFixtureChild, runFixtureGit } from './fixture-child.js';
+
+const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
+
+/** Create a real private Git project with isolated board and machine homes. */
+function initFixture(t, { existingSettings, existingCodexRules } = {}) {
+ const temp = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-init-permissions-')));
+ t.after(() => rmSync(temp, { recursive: true, force: true }));
+ const root = join(temp, 'repo');
+ const bin = join(temp, 'bin');
+ mkdirSync(root);
+ mkdirSync(bin);
+ const env = {
+ ...process.env,
+ HOME: join(temp, 'home'),
+ PULLBOARD_HOME: join(temp, 'board-home'),
+ PULLBOARD_MACHINE_HOME: join(temp, 'machine-home'),
+ PATH: `${bin}:${process.env.PATH ?? ''}`,
+ GIT_CONFIG_GLOBAL: '/dev/null',
+ GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'Init Permissions Fixture',
+ GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'Init Permissions Fixture',
+ GIT_COMMITTER_EMAIL: '[email protected]',
+ };
+ for (const key of Object.keys(env)) if (key.startsWith('GIT_') && !['GIT_CONFIG_GLOBAL', 'GIT_CONFIG_NOSYSTEM', 'GIT_AUTHOR_NAME', 'GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_NAME', 'GIT_COMMITTER_EMAIL'].includes(key)) delete env[key];
+ for (const key of ['PULLBOARD_RELAY_TOKEN', 'PULLBOARD_AGENT', 'PULLBOARD_AGENT_ID']) delete env[key];
+ writeFileSync(join(bin, 'pullboard'), `#!/bin/sh\nexec "${process.execPath}" "${BIN}" "$@"\n`);
+ chmodSync(join(bin, 'pullboard'), 0o755);
+ runFixtureGit(['init', '-q', '-b', 'main'], { cwd: root, env });
+ writeFileSync(join(root, 'package.json'), JSON.stringify({ name: 'init-permissions-fixture', scripts: { test: 'node --test' } }));
+ if (existingSettings !== undefined) {
+ mkdirSync(join(root, '.claude'), { recursive: true });
+ writeFileSync(join(root, '.claude', 'settings.json'), `${JSON.stringify(existingSettings, null, 2)}\n`);
+ }
+ if (existingCodexRules !== undefined) {
+ mkdirSync(join(root, '.codex', 'rules'), { recursive: true });
+ writeFileSync(join(root, '.codex', 'rules', 'pullboard.rules'), existingCodexRules);
+ }
+ /** Invoke the real init command in JSON mode and preserve its status/document. */
+ function init(...args) {
+ const child = runFixtureChild(process.execPath, [BIN, 'init', ...args, '--json'], { cwd: root, env, encoding: 'utf8' });
+ return { code: child.status, document: child.stdout ? JSON.parse(child.stdout) : null, stderr: child.failure ?? child.stderr };
+ }
+ return { root, init };
+}
+
+/** Parse Codex argv-prefix rules without depending on JSON whitespace. */
+function codexPrefixes(contents) {
+ return contents.split(/\r?\n/u)
+ .filter(line => line.startsWith('prefix_rule('))
+ .map((line) => {
+ const match = line.match(/^prefix_rule\(pattern=(\[[^\]]*\]), decision="allow"/u);
+ assert.ok(match, `Codex rule has a parseable prefix: ${line}`);
+ return JSON.parse(match[1]);
+ });
+}
+
+test('init grants the agent the permissions the Pullboard loop needs [I1,I2]', t => {
+ const fresh = initFixture(t);
+ const freshInit = fresh.init();
+ assert.equal(freshInit.code, 0, freshInit.stderr);
+ const freshSettings = JSON.parse(readFileSync(join(fresh.root, '.claude', 'settings.json'), 'utf8'));
+ assert.ok(freshSettings.permissions?.allow?.includes('Bash(pullboard:*)'), 'fresh projects receive Claude loop rules');
+ const freshCodexRules = readFileSync(join(fresh.root, '.codex', 'rules', 'pullboard.rules'), 'utf8');
+ assert.deepEqual(codexPrefixes(freshCodexRules), [['pullboard'], ['git', 'status'], ['git', 'diff'], ['git', 'log'], ['git', 'add'], ['git', 'commit'], ['git', 'merge'], ['git', 'rebase'], ['git', 'switch'], ['git', 'checkout'], ['git', 'worktree'], ['npm', 'test']], 'fresh projects receive only the required Codex command prefixes');
+
+ const existing = {
+ custom: { keep: true },
+ hooks: { UserPromptSubmit: [{ matcher: '', hooks: [{ type: 'command', command: 'existing-hook' }] }] },
+ permissions: {
+ allow: ['Bash(existing command *)'],
+ ask: ['Bash(git push *)'],
+ deny: ['Bash(rm -rf *)'],
+ },
+ };
+ const box = initFixture(t, { existingSettings: existing, existingCodexRules: '# user rule stays\n' });
+ const initialized = box.init();
+ assert.equal(initialized.code, 0, initialized.stderr);
+
+ const settingsPath = join(box.root, '.claude', 'settings.json');
+ const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
+ assert.deepEqual(settings.custom, existing.custom, 'unrelated settings remain unchanged');
+ assert.deepEqual(settings.hooks.UserPromptSubmit, existing.hooks.UserPromptSubmit, 'existing hooks remain unchanged');
+ assert.ok(settings.hooks.SessionStart, 'the existing Pullboard resume hook remains installed');
+ assert.deepEqual(settings.permissions.ask, existing.permissions.ask, 'existing ask rules remain unchanged');
+ assert.deepEqual(settings.permissions.deny, existing.permissions.deny, 'existing deny rules remain unchanged');
+ const claudeRules = settings.permissions.allow;
+ for (const rule of [
+ 'Bash(pullboard:*)',
+ 'Bash(git status:*)', 'Bash(git diff:*)', 'Bash(git log:*)', 'Bash(git add:*)',
+ 'Bash(git commit:*)', 'Bash(git merge:*)', 'Bash(git rebase:*)', 'Bash(git switch:*)',
+ 'Bash(git checkout:*)', 'Bash(git worktree:*)', 'Bash(npm test)',
+ 'Edit(/**)',
+ ]) assert.ok(claudeRules.includes(rule), `Claude project allow rules include ${rule}`);
+ assert.equal(claudeRules.includes('Bash(*)'), false, 'all shell commands are never allowed');
+ assert.equal(claudeRules.includes('Bash(git:*)'), false, 'all Git commands are never allowed');
+
+ const codexPath = join(box.root, '.codex', 'rules', 'pullboard.rules');
+ const codexRules = readFileSync(codexPath, 'utf8');
+ assert.ok(codexRules.startsWith('# user rule stays\n'), 'existing project Codex rules are preserved');
+ assert.deepEqual(codexPrefixes(codexRules), [['pullboard'], ['git', 'status'], ['git', 'diff'], ['git', 'log'], ['git', 'add'], ['git', 'commit'], ['git', 'merge'], ['git', 'rebase'], ['git', 'switch'], ['git', 'checkout'], ['git', 'worktree'], ['npm', 'test']], 'Codex rules stay scoped to the exact loop commands');
+ assert.ok(initialized.document.notes.some(note => /Claude Code.*Pullboard loop/u.test(note)), 'init says what Claude rules it added');
+ assert.ok(initialized.document.notes.some(note => /trusted-project Codex rules.*trust this project and restart the session/u.test(note)), 'init explains trust and session restart for Codex rules');
+
+ const settingsBytes = readFileSync(settingsPath, 'utf8');
+ const codexBytes = readFileSync(codexPath, 'utf8');
+ const second = box.init();
+ assert.equal(second.code, 0, second.stderr);
+ assert.equal(readFileSync(settingsPath, 'utf8'), settingsBytes, 'repeat init does not duplicate or rewrite Claude rules');
+ assert.equal(readFileSync(codexPath, 'utf8'), codexBytes, 'repeat init does not duplicate or rewrite Codex rules');
+
+ const skipFresh = initFixture(t);
+ const skipFreshResult = skipFresh.init('--no-permissions');
+ assert.equal(skipFreshResult.code, 0, skipFreshResult.stderr);
+ const skipFreshSettings = JSON.parse(readFileSync(join(skipFresh.root, '.claude', 'settings.json'), 'utf8'));
+ assert.equal(skipFreshSettings.permissions, undefined, '--no-permissions leaves fresh Claude permissions unset');
+ assert.equal(existsSync(join(skipFresh.root, '.codex', 'rules', 'pullboard.rules')), false, '--no-permissions creates no Codex rules file');
+ assert.equal(skipFreshResult.document.notes.some(note => /permission rules|trusted-project Codex/u.test(note)), false, '--no-permissions does not claim it installed agent rules');
+
+ const skipExisting = initFixture(t, { existingSettings: existing, existingCodexRules: '# user rule stays\n' });
+ const skipSettingsPath = join(skipExisting.root, '.claude', 'settings.json');
+ const skipCodexPath = join(skipExisting.root, '.codex', 'rules', 'pullboard.rules');
+ const skipPermissions = JSON.parse(readFileSync(skipSettingsPath, 'utf8')).permissions;
+ const skipCodexBytes = readFileSync(skipCodexPath, 'utf8');
+ const skipExistingResult = skipExisting.init('--no-permissions');
+ assert.equal(skipExistingResult.code, 0, skipExistingResult.stderr);
+ assert.deepEqual(JSON.parse(readFileSync(skipSettingsPath, 'utf8')).permissions, skipPermissions, '--no-permissions preserves existing Claude permissions');
+ assert.equal(readFileSync(skipCodexPath, 'utf8'), skipCodexBytes, '--no-permissions preserves existing Codex rules byte-for-byte');
+});