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(agents): the agents view lives in its own file [N2,B13]

Corey Olson63ae3cbc867d
diff --git a/src/agent-session.js b/src/agent-session.js
index 9ee118a3..6a9f44f3 100644
--- a/src/agent-session.js
+++ b/src/agent-session.js
@@ -149,6 +149,11 @@ export function recordParentSession(info, { parent, digest }) {
renameSync(pending, file);
}
+/** Record the parent of a just-made helper seat; a note that cannot be written never undoes the seat. */
+export function noteHelperParent(info, link) {
+ try { recordParentSession(info, link); } catch { /* The seat still works without its parent note. */ }
+}
+
/** Walk the board's linked checkouts and hand each registered agent's Git directory to visit. */
function eachSeatGitDir(info, agents, visit) {
const directory = join(info.commonDir, 'worktrees');
diff --git a/src/agent-tree.js b/src/agent-tree.js
new file mode 100644
index 00000000..e5f8c9f9
--- /dev/null
+++ b/src/agent-tree.js
@@ -0,0 +1,56 @@
+/** The agents view: each agent with its seats, helpers and holds, from the board and this machine's parent notes [N2,B13]. */
+import { COORDINATOR } from './config.js';
+import { displayAgentName } from './agent-names.js';
+import { seatLinks } from './agent-session.js';
+import * as store from './board.js';
+
+/**
+ * Every joined agent with its seats, its helpers and what each holds, helpers nested under the agent that opened them
+ * [N2,B13]. The parent links are read from this machine's checkouts; a helper whose parent is gone is listed on its own.
+ *
+ * @param {any} info - the checkout's repository info
+ * @param {any} config
+ * @param {any} board
+ * @returns {any[]}
+ */
+export function agentTree(info, config, board) {
+ const agents = store.listAgents(board).filter((agent) => agent.agent_lane !== COORDINATOR);
+ const { parents, digests } = seatLinks(info, agents);
+ const held = new Map();
+ for (const item of store.listItems(board)) {
+ if (!item.item_owner || !['claimed', 'submitted'].includes(item.item_status)) continue;
+ held.set(item.item_owner, [...(held.get(item.item_owner) ?? []), { item: item.item_id, status: item.item_status }]);
+ }
+ const known = new Set(agents.map((agent) => agent.agent_id));
+ const row = (agent, seen) => ({
+ id: agent.agent_id, displayName: displayAgentName(agent, config.agents.names), lane: agent.agent_lane, path: agent.agent_path,
+ seats: agents.filter((seat) => seat.agent_id === agent.agent_id || (digests.has(agent.agent_id) && digests.get(seat.agent_id) === digests.get(agent.agent_id)))
+ .map((seat) => ({ id: seat.agent_id, path: seat.agent_path })),
+ holds: held.get(agent.agent_id) ?? [],
+ helpers: agents.filter((helper) => parents.get(helper.agent_id) === agent.agent_id && !seen.has(helper.agent_id))
+ .map((helper) => row(helper, new Set([...seen, helper.agent_id]))),
+ });
+ const parentId = (agent) => parents.get(agent.agent_id);
+ return agents.filter((agent) => !known.has(parentId(agent))).map((agent) => row(agent, new Set([agent.agent_id])));
+}
+
+/**
+ * The text view of an agent tree: one line per agent, helpers indented beneath their parent.
+ *
+ * @param {any[]} tree
+ * @returns {string[]}
+ */
+export function agentTreeLines(tree, indent = '') {
+ if (!indent && !tree.length) return ['no agents have joined'];
+ return tree.flatMap((agent) => {
+ const held = agent.holds.map((hold) => `#${hold.item} (${hold.status})`).join(', ');
+ return [`${indent}${agent.displayName} (${agent.lane} lane) at ${agent.path}${held ? `: ${held}` : ''}`, ...agentTreeLines(agent.helpers, indent + ' ')];
+ });
+}
+
+/** Print the agents view, in text and as the stable agents:array JSON field. */
+export function agentsReport(io, tree) {
+ io.result?.({ agents: tree });
+ for (const line of agentTreeLines(tree)) io.say(line);
+ return 0;
+}
diff --git a/src/cli.js b/src/cli.js
index 66a32d50..391022f3 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -59,6 +59,10 @@ import {
loadConfig,
} from './config.js';
import { displayAgentName } from './agent-names.js';
+import {
+ agentTree,
+ agentsReport,
+} from './agent-tree.js';
import {
doctrineHistory,
loadDoctrine,
@@ -88,8 +92,7 @@ import {
HOOK_CHECKOUT_WAIT_MS,
localSessionMatches,
localSessionSeats,
- recordParentSession,
- seatLinks,
+ noteHelperParent,
} from './agent-session.js';
import {
decisionAnswer,
@@ -2185,7 +2188,7 @@ function setupCommands(io, { first, second, rest = [], values }) {
* @param {string} route
* @param {string | null} family
* @param {string | undefined} model
- * @param {boolean} helper - true when the seat is for another agent, so it records the session that opened it as its parent [N2,B13]; `next` opens the caller's own seat and passes false
+ * @param {boolean} helper - false for the caller's own seat (`next`); a helper's seat records its parent [N2,B13]
* @returns {Promise<number>}
*/
async function worktreeFor(io, lane, route, family = null, model, helper = true) {
@@ -2225,13 +2228,8 @@ async function worktreeFor(io, lane, route, family = null, model, helper = true)
throw error;
}
const digest = helper ? agentSessionDigest() : null;
- if (digest) {
- // A local note beside the new checkout; a failure to write it never undoes the seat that was made.
- const parent = ctx.info.isMain ? COORDINATOR : withBoard(ctx, (board) => store.agentAt(board, ctx.info.root)?.agent_id);
- if (parent) {
- try { recordParentSession(repoInfo(root), { parent, digest }); } catch { /* The seat still works without its parent note. */ }
- }
- }
+ const parent = digest ? (ctx.info.isMain ? COORDINATOR : withBoard(ctx, (board) => store.agentAt(board, ctx.info.root)?.agent_id)) : null;
+ if (parent) noteHelperParent(repoInfo(root), { parent, digest });
const displayName = displayAgentName({ agent_id: id, agent_model: model }, ctx.config.agents.names);
const modelWord = shellWord(model);
const prompt = `You are ${displayName}, in the ${lane} lane. Work only in ${shellWord(root)}, and start every command with ${cdTo(root)}\nModel: ${modelWord}. This worktree joined with --model ${modelWord}. For another worktree using the same model, pass --model ${modelWord} or set PULLBOARD_MODEL=${modelWord}; for a different agent, use that agent's actual model label.\nRead ${shellWord(join(root, 'AGENTS.md'))} first. Its rules govern this work, over any other repo's instructions you were given.`;
@@ -2250,35 +2248,6 @@ async function worktreeFor(io, lane, route, family = null, model, helper = true)
return 0;
}
-/**
- * Every joined agent with its seats, its helpers and what each holds, helpers nested under the agent that opened them
- * [N2,B13]. The parent links are read from this machine's checkouts; a helper whose parent is gone is listed on its own.
- *
- * @param {any} ctx
- * @param {any} board
- * @returns {any[]}
- */
-function agentTree(ctx, board) {
- const agents = store.listAgents(board).filter((agent) => agent.agent_lane !== COORDINATOR);
- const { parents, digests } = seatLinks(ctx.info, agents);
- const held = new Map();
- for (const item of store.listItems(board)) {
- if (!item.item_owner || !['claimed', 'submitted'].includes(item.item_status)) continue;
- held.set(item.item_owner, [...(held.get(item.item_owner) ?? []), { item: item.item_id, status: item.item_status }]);
- }
- const known = new Set(agents.map((agent) => agent.agent_id));
- const row = (agent, seen) => ({
- id: agent.agent_id, displayName: displayAgentName(agent, ctx.config.agents.names), lane: agent.agent_lane, path: agent.agent_path,
- seats: agents.filter((seat) => seat.agent_id === agent.agent_id || (digests.has(agent.agent_id) && digests.get(seat.agent_id) === digests.get(agent.agent_id)))
- .map((seat) => ({ id: seat.agent_id, path: seat.agent_path })),
- holds: held.get(agent.agent_id) ?? [],
- helpers: agents.filter((helper) => parents.get(helper.agent_id) === agent.agent_id && !seen.has(helper.agent_id))
- .map((helper) => row(helper, new Set([...seen, helper.agent_id]))),
- });
- const parentId = (agent) => parents.get(agent.agent_id);
- return agents.filter((agent) => !known.has(parentId(agent))).map((agent) => row(agent, new Set([agent.agent_id])));
-}
-
/** Describe the active configured location for new agent worktrees. */
function worktreeLocation(mainRoot, config) {
return config.worktrees === 'inside'
@@ -2457,19 +2426,7 @@ function readCommands(io, { first, second, rest, values }) {
io.say(`${me.displayName} (${me.lane} lane${me.route === 'light' ? ', light route' : ''}) at ${ctx.info.root}`);
return 0;
},
- agents: () => {
- const ctx = context(io);
- const listed = withBoard(ctx, (board) => agentTree(ctx, board));
- io.result?.({ agents: listed });
- if (!listed.length) io.say('no agents have joined');
- const show = (agent, indent) => {
- const held = agent.holds.map((hold) => `#${hold.item} (${hold.status})`).join(', ');
- io.say(`${indent}${agent.displayName} (${agent.lane} lane) at ${agent.path}${held ? `: ${held}` : ''}`);
- for (const helper of agent.helpers) show(helper, indent + ' ');
- };
- for (const agent of listed) show(agent, '');
- return 0;
- },
+ agents: () => agentsReport(io, withBoard(context(io), (board) => agentTree(context(io).info, context(io).config, board))),
lanes: () => {
const { config } = context(io);
io.result?.({ lanes: config.lanes, shared: config.shared, coordinator: COORDINATOR });