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(core): style tour output for terminals [N10]

Corey Olson514e684243ba
diff --git a/src/tour.js b/src/tour.js
index 2ce705c9..653a8bb3 100644
--- a/src/tour.js
+++ b/src/tour.js
@@ -37,6 +37,17 @@ test('greets by name [G1]', () => assert.equal(greet('Ada'), 'Hello, Ada!'));
`;
const EDGE_TEST = `${TEST}test('a blank name greets the world [G1]', () => assert.equal(greet(' '), 'Hello, world!'));\n`;
const TRY_EDGE = ['--input-type=module', '-e', "const { greet } = await import('./src/greet.mjs'); console.log(greet(''))"];
+const PROMPT_COLOR = { coordinator: 36, 'app-1': 33, 'review-1': 35 };
+
+/** Whether this person asked for terminal colors, unless NO_COLOR explicitly disables them. */
+function colorEnabled(io) {
+ return process.env.NO_COLOR === undefined && (Boolean(io.stdout.isTTY) || Boolean(process.env.FORCE_COLOR));
+}
+
+/** Wrap text in one plain ANSI style only when terminal styling is enabled. */
+function paint(text, code, enabled) {
+ return enabled ? `\u001b[${code}m${text}\u001b[0m` : text;
+}
/**
* Arguments as a person would type them.
@@ -67,6 +78,7 @@ function pause(ms) {
* @returns {number}
*/
export function tour(io) {
+ const color = colorEnabled(io);
const pace = io.stdout.isTTY ? 1 : 0;
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-tour-')));
const shims = join(dir, '.bin');
@@ -85,9 +97,9 @@ export function tour(io) {
/**
* Run one command as an agent, show it and the lines of its output worth reading.
*/
- const run = (who, file, args, { label = `${file} ${typed(args)}`, show = /./, fails = false } = {}) => {
+ const run = (who, file, args, { label = `${file} ${typed(args)}`, show = /./, fails = false, tone } = {}) => {
pause(400 * pace);
- if (label) io.say(` ${who} $ ${label}`);
+ if (label) io.say(` ${paint(who, PROMPT_COLOR[who], color)} $ ${label}`);
const result = spawnSync(file, args, {
cwd: where[who],
encoding: 'utf8',
@@ -97,7 +109,10 @@ export function tour(io) {
const said = `${result.stdout ?? ''}${result.stderr ?? ''}${result.error?.message ?? ''}`;
throw new TourStopped(`${label || `${file} ${typed(args)}`} ${fails ? 'passed, and should have failed' : `exited ${result.status}`}\n${said}`);
}
- for (const line of result.stdout.split('\n').filter((text) => text && show?.test(text))) io.say(` ${line.replaceAll(`${dir}/`, '')}`);
+ for (const line of result.stdout.split('\n').filter((text) => text && show?.test(text))) {
+ const output = ` ${line.replaceAll(`${dir}/`, '')}`;
+ io.say(tone === 'red' ? paint(output, 31, color) : tone === 'green' ? paint(output, 32, color) : output);
+ }
return result.stdout.trim();
};
const pb = (who, args, options) => run(who, process.execPath, [BIN, ...args], { label: `pullboard ${typed(args)}`, ...options });
@@ -109,7 +124,7 @@ export function tour(io) {
};
const step = (n, text) => {
pause(1200 * pace);
- io.say(`\n${n} ${text}`);
+ io.say(`\n${paint(`${n} ${text}`, 1, color)}`);
};
io.say('pullboard tour: a coordinator and two scripted agents run real commands on a throwaway repo. No model runs.');
@@ -139,7 +154,7 @@ export function tour(io) {
pb('coordinator', ['worktree', 'review'], { show: /^made /, label: 'pullboard worktree review' });
run('review-1', 'git', ['switch', '-q', '--detach', first]);
const edge = run('review-1', process.execPath, TRY_EDGE, { label: "node -e \"greet('')\"" });
- pb('review-1', ['verify', '1', 'reject', '--reason', 'BEHAVIOR_MISMATCH', '--note', `greet('') returns "${edge}"; G1 says a blank name greets the world`]);
+ pb('review-1', ['verify', '1', 'reject', '--reason', 'BEHAVIOR_MISMATCH', '--note', `greet('') returns "${edge}"; G1 says a blank name greets the world`], { tone: 'red' });
step(5, "The builder's next session starts from the board, not from memory.");
pb('app-1', ['resume'], { show: /^sent back|^next/ });
@@ -154,9 +169,10 @@ export function tour(io) {
run('review-1', 'git', ['switch', '-q', '--detach', second]);
write('review-1', { 'src/greet.mjs': FIRST });
// Pin the summary we display: Node 24 defaults to the spec reporter even through a pipe.
- run('review-1', process.execPath, ['--test', '--test-reporter=tap'], { label: 'node --test # with the fix removed', show: /^# (pass|fail)/, fails: true });
+ run('review-1', process.execPath, ['--test', '--test-reporter=tap'], { label: 'node --test # with the fix removed', show: /^# (pass|fail)/, fails: true, tone: 'red' });
run('review-1', 'git', ['checkout', '--', 'src/greet.mjs']);
- pb('review-1', ['verify', '1', 'accept', '--note', 'removed the blank-name fix: its new test failed; restored, both pass'], { show: /^verified/ });
+ if (color) run('review-1', process.execPath, ['--test', '--test-reporter=tap'], { label: 'node --test # after restoring the fix', show: /^# (pass|fail)/, tone: 'green' });
+ pb('review-1', ['verify', '1', 'accept', '--note', 'removed the blank-name fix: its new test failed; restored, both pass'], { show: /^verified/, tone: 'green' });
step(8, 'The coordinator merges it. The ledger is the receipt.');
run('coordinator', 'git', ['merge', '-q', '--ff-only', 'app/1']);
diff --git a/test/e2e.test.js b/test/e2e.test.js
index 5e7dc058..816d1503 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -892,27 +892,52 @@ test('init adds a Claude Code session hook that runs resume, and keeps every oth
test('the tour runs a reject and its rework on a throwaway repo, in under thirty seconds [N10]', () => {
const box = sandbox();
+ const plainEnv = { ...box.env, TMPDIR: box.dir };
+ delete plainEnv.NO_COLOR;
+ delete plainEnv.FORCE_COLOR;
const started = Date.now();
- const shown = spawnSync(process.execPath, [BIN, 'tour'], { cwd: box.dir, env: { ...box.env, TMPDIR: box.dir }, encoding: 'utf8' });
+ const shown = spawnSync(process.execPath, [BIN, 'tour'], { cwd: box.dir, env: plainEnv, encoding: 'utf8' });
assert.equal(shown.status, 0, `${shown.stdout}${shown.stderr}`);
assert.ok(Date.now() - started < 30_000, 'thirty seconds');
+ assert.doesNotMatch(shown.stdout, /\u001b\[/, 'piped output stays plain');
assert.match(shown.stdout, /review-1 \$ pullboard verify 1 reject --reason BEHAVIOR_MISMATCH/);
assert.match(shown.stdout, /sent back: #1 BEHAVIOR_MISMATCH by review-1: greet\(''\) returns "Hello, !"/);
assert.match(shown.stdout, /with the fix removed\n {7}# pass 1\n {7}# fail 1/);
assert.match(shown.stdout, /verified #1: CRITERION_MET/);
assert.match(shown.stdout, /\| 1 \| app \| Greeting \| G1 \| app-1 \| review-1 \|/);
+
+ const forced = spawnSync(process.execPath, [BIN, 'tour'], { cwd: box.dir, env: { ...plainEnv, FORCE_COLOR: '1' }, encoding: 'utf8' });
+ assert.equal(forced.status, 0, `${forced.stdout}${forced.stderr}`);
+ assert.match(forced.stdout, /\u001b\[1m1 The person approved one spec row\. The coordinator files it as work\.\u001b\[0m/);
+ assert.match(forced.stdout, /\u001b\[36mcoordinator\u001b\[0m \$/);
+ assert.match(forced.stdout, /\u001b\[33mapp-1\u001b\[0m \$/);
+ assert.match(forced.stdout, /\u001b\[35mreview-1\u001b\[0m \$/);
+ assert.match(forced.stdout, /\u001b\[31m[^\n]*rejected #1/);
+ assert.match(forced.stdout, /\u001b\[31m[^\n]*# fail 1/);
+ assert.match(forced.stdout, /\u001b\[32m[^\n]*verified #1: CRITERION_MET/);
+ assert.match(forced.stdout, /\u001b\[32m[^\n]*# pass 2/);
+
+ const noColor = spawnSync(process.execPath, [BIN, 'tour'], { cwd: box.dir, env: { ...plainEnv, FORCE_COLOR: '1', NO_COLOR: '1' }, encoding: 'utf8' });
+ assert.equal(noColor.status, 0, `${noColor.stdout}${noColor.stderr}`);
+ assert.doesNotMatch(noColor.stdout, /\u001b\[/, 'NO_COLOR wins even if the environment could otherwise force color');
+ const normalizeTourRoot = (text) => text
+ .replace(/Look around: cd .* && pullboard log/, 'Look around: cd <tour> && pullboard log')
+ .replace(/\b[0-9a-f]{12}\b/g, '<sha>')
+ .replace(/claimed #1 until \S+ criterion frozen/g, 'claimed #1 until <time> criterion frozen');
+ assert.equal(normalizeTourRoot(noColor.stdout), normalizeTourRoot(shown.stdout), 'NO_COLOR preserves the plain tour output');
+
const repo = /Look around: cd (\S+) && pullboard log/.exec(shown.stdout)[1];
assert.match(box.git(repo, 'log', '--format=%an %s', '-1'), /^app-1 fix\(app\): a blank name greets the world \[G1\]$/);
const hooks = join(box.dir, 'ambient-hooks');
mkdirSync(hooks);
writeFileSync(join(hooks, 'pre-commit'), '#!/bin/sh\necho ambient hook ran >&2\nexit 1\n');
chmodSync(join(hooks, 'pre-commit'), 0o755);
- const ambient = { ...box.env, TMPDIR: box.dir, GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'core.hooksPath', GIT_CONFIG_VALUE_0: hooks, GIT_DIR: join(box.dir, 'elsewhere.git') };
+ const ambient = { ...plainEnv, GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'core.hooksPath', GIT_CONFIG_VALUE_0: hooks, GIT_DIR: join(box.dir, 'elsewhere.git') };
const isolated = spawnSync(process.execPath, [BIN, 'tour'], { cwd: box.dir, env: ambient, encoding: 'utf8' });
assert.equal(isolated.status, 0, `git settings from the environment stay out: ${isolated.stdout}`);
const empty = join(box.dir, 'empty');
mkdirSync(empty);
- const stopped = spawnSync(process.execPath, [BIN, 'tour'], { cwd: box.dir, env: { ...box.env, TMPDIR: box.dir, PATH: empty }, encoding: 'utf8' });
+ const stopped = spawnSync(process.execPath, [BIN, 'tour'], { cwd: box.dir, env: { ...plainEnv, PATH: empty }, encoding: 'utf8' });
assert.equal(stopped.status, 1);
assert.match(stopped.stdout, /The tour stopped: git init -q -b main exited null/);
});