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(board): a read-only board refuses by name [I1,L3,P4]
Corey Olson9d164f530478
diff --git a/src/board-access.js b/src/board-access.jsnew file mode 100644index 00000000..f4235a31--- /dev/null+++ b/src/board-access.js@@ -0,0 +1,20 @@+/** Name a board this process cannot write, such as one inside a read-only agent sandbox [I1,P4]. */+import { dirname } from 'node:path';+import { Refused } from './refused.js';++/**+ * Turn SQLite's bare readonly or cannot-open error, or a file-system access error, into a named+ * refusal that says which folder to open up; any other error comes back unchanged.+ * Why: an agent shown the raw readonly-database trace tends to read board.sqlite directly instead+ * (blueprint trial, #738), so the refusal names the folder and the access that gets past it.+ *+ * @param {string} file the board file+ * @param {Error & { errcode?: number, code?: string }} error+ * @returns {Error}+ */+export function boardNotWritable(file, error) {+ const sqliteCode = Number.isInteger(error?.errcode) ? error.errcode & 0xff : null;+ if (sqliteCode !== 8 && sqliteCode !== 14 && !['EACCES', 'EPERM', 'EROFS'].includes(error?.code ?? '')) return error;+ return new Refused('BOARD_NOT_WRITABLE',+ `Cannot write the board in "${dirname(file)}". Give the agent write access to that folder, the repo's .git/pullboard, or run the command outside the sandbox.`);+}diff --git a/src/board.js b/src/board.jsindex 0bf0fbca..a0f677e4 100644--- a/src/board.js+++ b/src/board.js@@ -10,6 +10,7 @@ import { randomBytes, randomUUID } from 'node:crypto';import { existsSync, mkdirSync } from 'node:fs';import { dirname } from 'node:path';import { DatabaseSync } from 'node:sqlite';+import { boardNotWritable } from './board-access.js';import { briefFiles, briefSections } from './brief.js';import { COORDINATOR } from './config.js';import { ENGINE_VERSION, GUARDS, IN_STATE, MOVES, STATES, UNKNOWN_MOVE, effectiveGuards, storeTriggers } from './machine.js';@@ -191,7 +192,7 @@ export function openBoard(file, clock = systemClock, { isMain } = {}) {boardVersion = current.prepare('PRAGMA user_version').get().user_version;logVersion = readEventLogVersion(current);} catch (error) {- throw boardBusyError(file, startedAt, error);+ throw boardNotWritable(file, boardBusyError(file, startedAt, error));} finally {current?.close();}@@ -222,7 +223,7 @@ export function openBoard(file, clock = systemClock, { isMain } = {}) {return board;} catch (error) {try { db?.close(); } catch {}- throw boardBusyError(file, startedAt, error);+ throw boardNotWritable(file, boardBusyError(file, startedAt, error));}}diff --git a/src/next-steps.js b/src/next-steps.jsindex d8afe8fe..99cb0608 100644--- a/src/next-steps.js+++ b/src/next-steps.js@@ -69,6 +69,7 @@ export const NEXT_STEPS = Object.freeze({BLUEPRINT_EXISTS: 'choose a file that does not exist: pullboard blueprint save <new-file>',BLUEPRINT_URL: 'download and read the blueprint yourself, then run pullboard blueprint add <local-file>',BOARD_BUSY: 'wait for the other pullboard process to finish, then retry',+ BOARD_NOT_WRITABLE: 'give the agent write access to the repo\'s .git/pullboard folder, or run the command outside the sandbox',BOARD_SCOPE_UNAVAILABLE: 'link the board: pullboard relay on',BOARD_UNAVAILABLE: 'restore the repo, or drop it: pullboard forget <path>',BRIEF_LANE: 'split the item by lane, or add the other lane\'s part as its own item and wait on it with --after',diff --git a/test/machine-home.test.js b/test/machine-home.test.jsindex 51df3167..6f9e43de 100644--- a/test/machine-home.test.js+++ b/test/machine-home.test.js@@ -1,9 +1,12 @@+/** @pullboard-test-input source-tree *//** Real machine-storage permission refusals preserve the shared queue location [I1,C7,Q4]. */import assert from 'node:assert/strict';-import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { chmodSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { join } from 'node:path';import { after, test } from 'node:test';import { createE2eHelpers } from './e2e-helpers.js';+import { runFixtureChild } from './fixture-child.js';+import { RECORDED_GENERIC_NEXT } from '../src/recorded-refusal.js';const { sandbox, project, cleanup } = createE2eHelpers();after(cleanup);@@ -65,3 +68,57 @@ test('an unwritable machine home is refused by name [I1,C7,Q4]', async (t) => {} finally { chmodSync(parent, 0o700); }});});++/** Make the shared board folder and every file in it read-only, as a read-only sandbox sees it. */+function lockBoard(folder) {+ for (const name of readdirSync(folder)) chmodSync(join(folder, name), 0o444);+ chmodSync(folder, 0o555);+}++/** Give the board folder and its files write access again. */+function unlockBoard(folder) {+ chmodSync(folder, 0o755);+ for (const name of readdirSync(folder)) chmodSync(join(folder, name), 0o644);+}++/**+ * Copy this checkout's CLI outside any Git repo, as npm installs it, and return a runner for it.+ * Code outside a worktree opens the board directly; code in a worktree first probes it read-only,+ * so both paths to the board meet the read-only folder.+ */+function installedCli(p) {+ const cli = join(p.dir, 'installed-pullboard');+ for (const part of ['src', 'bin', 'skills', 'package.json', 'CHANGELOG.md']) cpSync(join(import.meta.dirname, '..', part), join(cli, part), { recursive: true });+ return (cwd, ...args) => {+ const result = runFixtureChild(process.execPath, [join(cli, 'bin', 'pullboard.js'), ...args], { cwd, env: p.env, encoding: 'utf8' });+ return { code: result.status, out: result.stdout, err: result.failure ?? result.stderr };+ };+}++test('a read-only board refuses resume by name [I1,L3,P4]', () => {+ const p = project();+ const installed = installedCli(p);+ const folder = join(p.repo, '.git', 'pullboard');+ assert.equal(installed(p.repo, 'resume').code, 0, 'the installed CLI opens the board before it is locked');+ lockBoard(folder);+ try {+ assert.throws(() => writeFileSync(join(folder, 'permission-sentinel'), ''), { code: 'EACCES' });+ const runs = [['installed pullboard', installed, p.repo], ['main checkout', p.run, p.repo], ['lane worktree', p.run, p.web]];+ for (const [label, run, cwd] of runs) {+ const text = run(cwd, 'resume');+ const output = text.out + text.err;+ assert.notEqual(text.code, 0, `${label}: ${output}`);+ assert.match(output, /BOARD_NOT_WRITABLE/u, `${label} names the refusal`);+ assert.ok(output.includes(folder), `${label} names the board folder: ${output}`);+ assert.doesNotMatch(output, /readonly database|at Module\.|ERR_SQLITE_ERROR/iu, `${label} prints no raw database trace`);+ const json = run(cwd, 'resume', '--json');+ assert.notEqual(json.code, 0, `${label} --json: ${json.out}${json.err}`);+ const { error } = JSON.parse(json.out);+ assert.equal(error.code, 'BOARD_NOT_WRITABLE', `${label} --json carries the code`);+ assert.match(error.next, /write access to .*\.git\/pullboard.*outside the sandbox/u, `${label} --json next names the step`);+ assert.doesNotMatch(error.next, /service owner/u, `${label} --json next is not the unknown-code footer`);+ assert.notEqual(error.next, RECORDED_GENERIC_NEXT, `${label} --json next is not the generic footer`);+ }+ } finally { unlockBoard(folder); }+ assert.equal(p.run(p.repo, 'resume').code, 0, 'restoring write access, the step it names, lets resume run');+});diff --git a/test/machine.test.js b/test/machine.test.jsindex fc0aada7..86bc20d7 100644--- a/test/machine.test.js+++ b/test/machine.test.js@@ -68,6 +68,7 @@ const NOT_MOVES = {REMOTE_COORDINATOR_MODEL: 'a linked replica cannot redeclare the coordinator model; use the coordinator checkout',EVENT_LOG_VERSION: 'the local board format is checked before opening it for an item move',BOARD_BUSY: 'the board connection is opened or read before an item move can begin',+ BOARD_NOT_WRITABLE: 'the board folder must be writable before a command opens it for an item move',NOT_YOUR_CHECKOUT: 'the caller owns the checkout session, checked before any item move',CHECKOUT_SESSION: 'the checkout-local session binding is readable before any item move',UNMERGED_SCHEMA: 'shared-board schema compatibility checked before a command opens the database',