Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ All notable changes to Bobby are documented here. The format is based on
`dashboard.executor` and sending you to an absolute path that key never takes.

### Added
- **Disk floor and worktree reaper in `bobby conductor` (BOB-189).** New required key
`governor.min_free_disk_gb`: `check lane|stack` and `conductor next` refuse below it
(free space of the volume holding the studio, one `statfs` call), and `status` MACHINE shows
`DISK`. `status` also lists WORKTREES by ticket stage (every repo in `.bobbyrc.yml` plus the
studio repo, from `git worktree list --porcelain`); sizes (`du`, slow) show only from the cache
or after `status --sizes`. `conductor reap --worktrees` (dry run unless `--apply`, M4 only)
removes a worktree with `git worktree remove --force` (branch kept) only when every ticket named
in its folder name is done, `git status --porcelain -uno` is empty, no live session's cwd is
inside it and a detached HEAD is already on a branch; folders that are not git worktrees are listed, never touched. `--sizes` measures the
candidates. A failing git or claude is an error.
- **`bobby conductor` (BOB-174): read-only studio status board.** `bobby conductor init`
writes `.bobby/conductor.yml` with every key explicit and refuses to overwrite it;
`bobby conductor status [--json]` lists background and interactive sessions from
Expand Down
34 changes: 26 additions & 8 deletions commands/conductor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// `bobby conductor`: the studio's control board. `init` writes conductor.yml;
// `status` and `check` only read (they never change a session, a ticket or a
// container). `reap` is dry-run unless `--apply`, and is the one command that
// ends sessions (see lib/conductor/reaper.js).
// ends sessions (see lib/conductor/reaper.js), stops stacks and removes worktrees.

import path from 'path';
import { findStudioRoot, initConductorConfig, loadConductorConfig } from '../lib/conductor/config.js';
Expand All @@ -13,6 +13,8 @@ import { readStacks } from '../lib/conductor/stacks.js';
import { checkLane, checkStack } from '../lib/conductor/governor.js';
import { reap, renderReap } from '../lib/conductor/reaper.js';
import { reapStacks, renderStackReap } from '../lib/conductor/stack-reaper.js';
import { reapWorktrees, renderWorktreeReap } from '../lib/conductor/worktree-reaper.js';
import { readDisk } from '../lib/conductor/disk.js';
import { assertM4Host } from '../lib/conductor/host.js';
import { readAgents } from '../lib/conductor/sessions.js';
import {
Expand Down Expand Up @@ -45,7 +47,7 @@ export function registerConductor(program) {
success(`Wrote ${path.relative(root, file)}`);
console.log(dim(` projects: ${values.projects.join(', ')}`));
console.log(dim(` hook_state_dir: ${values.hook_state_dir}`));
console.log(dim(` governor: min_free_ram_mb ${values.governor.min_free_ram_mb}, max_docker_stacks ${values.governor.max_docker_stacks}`));
console.log(dim(` governor: min_free_ram_mb ${values.governor.min_free_ram_mb}, max_docker_stacks ${values.governor.max_docker_stacks}, min_free_disk_gb ${values.governor.min_free_disk_gb}`));
console.log(dim(` reaper: stack_idle_hours ${values.reaper.stack_idle_hours}`));
console.log(dim(` wip: max_lanes ${values.wip.max_lanes}; claims: ttl_minutes ${values.claims.ttl_minutes}`));
console.log(dim(` inbox: stale_minutes ${values.inbox.stale_minutes}`));
Expand All @@ -56,11 +58,12 @@ export function registerConductor(program) {

conductor
.command('status')
.description('Lanes by state, WAITING ON CC, handoff markers, ticket counts, free RAM and docker stacks')
.description('Lanes by state, WAITING ON CC, handoff markers, ticket counts, free RAM and disk, worktrees by stage, docker stacks')
.option('--json', 'Print the same data as JSON')
.option('--sizes', 'Measure worktree sizes with du (slow: minutes) and cache them; without it only cached sizes show')
.action((opts) => {
try {
const status = buildStatus(findStudioRoot());
const status = buildStatus(findStudioRoot(), { sizes: Boolean(opts.sizes) });
console.log(opts.json ? JSON.stringify(status, null, 2) : renderStatus(status));
} catch (e) {
fail(e);
Expand All @@ -75,11 +78,13 @@ export function registerConductor(program) {
if (kind !== 'lane' && kind !== 'stack') {
throw new Error(`Unknown check "${kind}". Use: bobby conductor check lane | stack`);
}
const config = loadConductorConfig(findStudioRoot());
const studioRoot = findStudioRoot();
const config = loadConductorConfig(studioRoot);
const memory = readMemory();
const disk = readDisk(studioRoot);
const result = kind === 'lane'
? checkLane(config, memory)
: checkStack(config, memory, readStacks().stacks.length);
? checkLane(config, memory, disk)
: checkStack(config, memory, disk, readStacks().stacks.length);
if (!result.ok) {
error(`${kind} refused: ${result.reason}`);
process.exit(1);
Expand All @@ -92,15 +97,28 @@ export function registerConductor(program) {

conductor
.command('reap')
.description('List finished background sessions to end, keeping their transcripts (--stacks: idle per-ticket docker stacks instead). Dry run unless --apply. M4 only')
.description('List finished background sessions to end, keeping their transcripts (--stacks: idle docker stacks; --worktrees: clean worktrees of done tickets). Dry run unless --apply. M4 only')
.option('--apply', 'Do it (default: print the list and change nothing)')
.option('--stacks', 'Reap idle per-ticket docker stacks (compose project, containers kept) instead of sessions')
.option('--worktrees', 'Remove git worktrees of done tickets (clean tracked files, no live session inside; branches kept) instead of sessions')
.option('--sizes', 'With --worktrees: measure the candidates with du (slow)')
.action((opts) => {
try {
if (opts.stacks && opts.worktrees) throw new Error('Pick one of --stacks and --worktrees.');
if (opts.sizes && !opts.worktrees) throw new Error('--sizes only applies to --worktrees.');
assertM4Host();
const studioRoot = findStudioRoot();
const config = loadConductorConfig(studioRoot);
const apply = Boolean(opts.apply);
if (opts.worktrees) {
const report = reapWorktrees({ studioRoot, config, apply, measure: Boolean(opts.sizes) });
console.log(renderWorktreeReap(report, { apply }));
if (report.failed > 0) {
error(`${report.failed} worktree(s) could not be checked or removed`);
process.exit(1);
}
return;
}
if (opts.stacks) {
const report = reapStacks({ studioRoot, config, apply });
console.log(renderStackReap(report, { apply, idleHours: config.reaper.stack_idle_hours }));
Expand Down
6 changes: 4 additions & 2 deletions lib/conductor/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const CONDUCTOR_FILE = 'conductor.yml';

// The numbers `conductor init` writes. CC's decision, recorded on BOB-173 (2026-11-08),
// for the M4 (48 GB). This is the only place they are chosen; loading never falls back to them.
const INIT_GOVERNOR = { min_free_ram_mb: 4096, max_docker_stacks: 4 };
// BOB-189: CC set 50 GB free disk (2026-11-08, the day the disk hit 99%).
const INIT_GOVERNOR = { min_free_ram_mb: 4096, max_docker_stacks: 4, min_free_disk_gb: 50 };
// BOB-177: CC set 2 hours in the BOB-173 scope.
const INIT_REAPER = { stack_idle_hours: 2 };
// BOB-180: CC set 6 lanes (BOB-173 decision, 2026-11-08). The claim TTL was not named by CC;
Expand Down Expand Up @@ -110,7 +111,7 @@ function validateReaper(reaper, file) {
return { stack_idle_hours: h };
}

const GOVERNOR_KEYS = ['min_free_ram_mb', 'max_docker_stacks'];
const GOVERNOR_KEYS = ['min_free_ram_mb', 'max_docker_stacks', 'min_free_disk_gb'];

function validateGovernor(governor, file) {
if (governor === undefined || governor === null) throw fail(file, `governor.${GOVERNOR_KEYS[0]}`, 'is missing');
Expand Down Expand Up @@ -171,6 +172,7 @@ export function initConductorConfig(studioRoot, { projects } = {}) {
'# hook_state_dir: where session hooks write <sessionId>.handoff markers.',
'# governor.min_free_ram_mb: `conductor check` refuses below this much free RAM (CC, 2026-11-08).',
'# governor.max_docker_stacks: `conductor check stack` refuses at this many running stacks (CC, 2026-11-08).',
'# governor.min_free_disk_gb: `conductor check` and `conductor next` refuse below this much free disk on the studio volume (CC, 2026-11-08).',
'# reaper.stack_idle_hours: `conductor reap --stacks` stops a ticket stack idle this long with no working lane (CC, 2026-11-08).',
'# wip.max_lanes: `conductor next` refuses when this many live lane sessions (working or waiting on CC) exist (CC, 2026-11-08).',
'# claims.ttl_minutes: a ticket `conductor next` handed out is not handed out again for this long.',
Expand Down
29 changes: 29 additions & 0 deletions lib/conductor/disk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// lib/conductor/disk.js
//
// Free disk on the volume that holds the studio (BOB-189). Read-only: one statfs call,
// which is instant (unlike measuring directory sizes). `bavail` is what a normal process
// can still write, so APFS purgeable space is not counted as free.
//
// Any unreadable or implausible figure throws; there is no fallback value.

import fs from 'fs';

const GB = 1024 ** 3;

/** { path, total_gb, free_gb } for the volume holding `studioRoot`, GB with one decimal. */
export function readDisk(studioRoot, { statfs = fs.statfsSync } = {}) {
let st;
try {
st = statfs(studioRoot);
} catch (e) {
throw new Error(`Cannot read free disk space for ${studioRoot}: ${e.message}`);
}
const free = Number(st.bavail) * Number(st.bsize);
const total = Number(st.blocks) * Number(st.bsize);
if (!Number.isFinite(free) || !Number.isFinite(total) || total <= 0 || free < 0 || free > total) {
throw new Error(`statfs of ${studioRoot} returned implausible figures (free ${free} bytes of ${total} bytes); refusing to trust the reading`);
}
// Free is floored to a tenth, so a reading never passes the floor by rounding up.
const tenths = (bytes, round) => round((bytes / GB) * 10) / 10;
return { path: studioRoot, total_gb: tenths(total, Math.round), free_gb: tenths(free, Math.floor) };
}
26 changes: 17 additions & 9 deletions lib/conductor/governor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
// Yes/no answers for "may I start a lane / a docker stack?". It only answers; it
// never acts on the machine.

/** { ok, reason, numbers } for starting a lane: free RAM must reach governor.min_free_ram_mb. */
export function checkLane(config, memory) {
const min = config.governor.min_free_ram_mb;
const ok = memory.free_mb >= min;
/**
* { ok, reason, numbers } for starting a lane: free RAM must reach governor.min_free_ram_mb
* and free disk on the studio volume must reach governor.min_free_disk_gb (BOB-189).
* Both numbers are always reported, so a refusal for one never hides the other.
*/
export function checkLane(config, memory, disk) {
const minRam = config.governor.min_free_ram_mb;
const minDisk = config.governor.min_free_disk_gb;
const ramOk = memory.free_mb >= minRam;
const diskOk = disk.free_gb >= minDisk;
const ramText = `free RAM ${memory.free_mb} MB ${ramOk ? '>=' : '<'} min ${minRam} MB`;
const diskText = `free disk ${disk.free_gb} GB ${diskOk ? '>=' : '<'} min ${minDisk} GB`;
return {
ok,
reason: ok ? `free RAM ${memory.free_mb} MB >= min ${min} MB` : `free RAM ${memory.free_mb} MB < min ${min} MB`,
numbers: { free_ram_mb: memory.free_mb, min_free_ram_mb: min },
ok: ramOk && diskOk,
reason: `${ramText}; ${diskText}`,
numbers: { free_ram_mb: memory.free_mb, min_free_ram_mb: minRam, free_disk_gb: disk.free_gb, min_free_disk_gb: minDisk },
};
}

/** { ok, reason, numbers } for starting a docker stack: the lane check, then stack count < governor.max_docker_stacks. */
export function checkStack(config, memory, stackCount) {
const lane = checkLane(config, memory);
export function checkStack(config, memory, disk, stackCount) {
const lane = checkLane(config, memory, disk);
const cap = config.governor.max_docker_stacks;
const numbers = { ...lane.numbers, docker_stacks: stackCount, max_docker_stacks: cap };
if (!lane.ok) return { ok: false, reason: lane.reason, numbers };
Expand Down
5 changes: 3 additions & 2 deletions lib/conductor/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import YAML from 'yaml';
import { readAgents, classifySessions } from './sessions.js';
import { boardTickets, laneStateFor } from './stacks.js';
import { checkLane } from './governor.js';
import { readDisk } from './disk.js';
import { readMemory } from './resources.js';
import { run as defaultRun } from './exec.js';
import { STAGE_ORDER } from '../tickets.js';
Expand Down Expand Up @@ -174,7 +175,7 @@ function snapshot({ studioRoot, config, run, now }) {
* { kind: 'picked', ticket: { id, project, stage, position }, hint, skipped }
* Throws on any unreadable input; a failing probe is never read as "nothing to do".
*/
export function pickNext({ studioRoot, config, run = defaultRun, now = Date.now(), lane = null, memory = null }) {
export function pickNext({ studioRoot, config, run = defaultRun, now = Date.now(), lane = null, memory = null, disk = null }) {
const { sessions, resolved } = snapshot({ studioRoot, config, run, now });
if (resolved.length === 0) return { kind: 'empty' };

Expand All @@ -183,7 +184,7 @@ export function pickNext({ studioRoot, config, run = defaultRun, now = Date.now(
if (active >= cap) {
return { kind: 'refused', reason: `${active} live lane session(s) (working or waiting on CC) >= wip.max_lanes ${cap}` };
}
const governor = checkLane(config, memory || readMemory({ run }));
const governor = checkLane(config, memory || readMemory({ run }), disk || readDisk(studioRoot));
if (!governor.ok) return { kind: 'refused', reason: governor.reason };

const claims = readClaims(studioRoot);
Expand Down
36 changes: 34 additions & 2 deletions lib/conductor/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@ import { readAgents, classifySessions, groupSessions } from './sessions.js';
import { boardCounts } from './board.js';
import { loadConductorConfig } from './config.js';
import { readMemory } from './resources.js';
import { readDisk } from './disk.js';
import { scanWorktrees, readSizeCache, measureSizes, worktreeSummary, formatKb } from './worktrees.js';
import { readStacks, readStoppedStacks, boardTickets, mapStacks, mapStoppedStacks } from './stacks.js';
import { inboxDir, inboxStatus } from './inbox.js';
import { shipBoardTickets, shipLanesView } from './ship-lane.js';
import { bold, dim } from '../colors.js';

export function buildStatus(studioRoot, { run, now = Date.now() } = {}) {
/**
* `sizes: true` runs `du` over every worktree whose folder exists (slow, minutes; a prunable one is gone and `du` on it fails) and refreshes the cache; without it
* the worktree section shows only the sizes already cached and never measures anything.
*/
export function buildStatus(studioRoot, { run, now = Date.now(), sizes = false, home, statfs } = {}) {
const config = loadConductorConfig(studioRoot);
const sessions = classifySessions(readAgents({ run }), { hookStateDir: config.hook_state_dir, now });
const groups = groupSessions(sessions);
const memory = readMemory({ run });
const disk = readDisk(studioRoot, { statfs });
const scan = scanWorktrees(studioRoot, { run, home });
const sizeCache = sizes
? measureSizes(scan.worktrees.filter(w => !w.prunable).map(w => w.path), { hookStateDir: config.hook_state_dir, run, now })
: readSizeCache(config.hook_state_dir);
const docker = readStacks({ run, now });
const tickets = boardTickets(studioRoot, config.projects);
const stacks = mapStacks(docker.stacks, { tickets, sessions });
Expand All @@ -38,7 +49,14 @@ export function buildStatus(studioRoot, { run, now = Date.now() } = {}) {
inbox: inboxStatus(inboxDir(studioRoot), sessions, { now, staleMinutes: config.inbox.stale_minutes }),
ship_lanes: shipLanesView({ studioRoot, sessions, tickets: shipBoardTickets(studioRoot, config.projects), now }),
board: boardCounts(studioRoot, config.projects),
machine: { ...memory, min_free_ram_mb: config.governor.min_free_ram_mb },
machine: {
...memory,
min_free_ram_mb: config.governor.min_free_ram_mb,
disk_total_gb: disk.total_gb,
disk_free_gb: disk.free_gb,
min_free_disk_gb: config.governor.min_free_disk_gb,
},
worktrees: worktreeSummary(scan, sizeCache),
stacks: { max: config.governor.max_docker_stacks, standalone_containers: docker.standalone_containers, list: stacks, stopped },
};
}
Expand Down Expand Up @@ -148,9 +166,23 @@ export function renderStatus(status) {
const m = status.machine;
lines.push(bold('MACHINE'));
lines.push(` RAM free ${m.free_mb} MB of ${m.total_mb} MB ${dim(`(lane floor ${m.min_free_ram_mb} MB)`)}`);
lines.push(` DISK free ${m.disk_free_gb} GB of ${m.disk_total_gb} GB ${dim(`(lane floor ${m.min_free_disk_gb} GB)`)}${m.disk_free_gb < m.min_free_disk_gb ? ` ${bold('below the floor: lanes refused')}` : ''}`);
lines.push(` compressor holds ${m.compressed_mb} MB, takes ${m.compressor_mb} MB of RAM`);
lines.push('');

const wt = status.worktrees;
lines.push(`${bold('WORKTREES')} ${dim(`(${wt.total} across ${wt.repos} repos; ${wt.non_worktree_folders.length} other folder(s) that are not git worktrees; reap with \`conductor reap --worktrees\`)`)}`);
if (wt.by_stage.length === 0) lines.push(dim(' none'));
for (const g of wt.by_stage) {
let size = '';
if (g.sized === g.count) size = ` ${dim(formatKb(g.size_kb))}`;
else if (g.sized > 0) size = ` ${dim(`${formatKb(g.size_kb)} (${g.sized} of ${g.count} sized)`)}`;
lines.push(` ${g.stage} ${g.count}${size}`);
}
if (wt.sizes_measured_at) lines.push(dim(` sizes: du, nominal, cached ${wt.sizes_measured_at}; refresh with \`conductor status --sizes\` (slow)`));
else lines.push(dim(' sizes: not measured; `conductor status --sizes` measures them (slow) and caches the result'));
lines.push('');

const st = status.stacks;
lines.push(`${bold('STACKS')} ${dim(`(${st.list.length} of max ${st.max})`)}`);
if (st.list.length === 0) lines.push(dim(' none'));
Expand Down
Loading
Loading