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): edit item dependencies [B3,V2]

Corey Olson9f5eb0fa5133
diff --git a/src/board.js b/src/board.js
index 1f214cde..7c4c7b14 100644
--- a/src/board.js
+++ b/src/board.js
@@ -682,6 +682,29 @@ export function addItem(board, { by, lane, title, criterion = '', specIds = [],
});
}
+/** Validate that dependencies exist, remain usable, and cannot lead back to the edited item. */
+function validateItemDependencies(board, itemId, after) {
+ const direct = after.map((dependency) => itemById(board, dependency));
+ const withdrawn = direct.find((dependency) => dependency.item_status === 'withdrawn');
+ if (withdrawn) {
+ throw new Refused('WITHDRAWN', `item #${withdrawn.item_id} is withdrawn; nothing can wait on it`);
+ }
+ if (itemId === null) return;
+
+ const visited = new Set();
+ const pending = [...after];
+ while (pending.length) {
+ const dependency = pending.pop();
+ if (dependency === itemId) {
+ throw new Refused('DEPENDENCY_CYCLE', `item #${itemId} cannot wait on itself through its dependencies; change --after to remove the cycle`);
+ }
+ if (visited.has(dependency)) continue;
+ const item = itemById(board, dependency);
+ visited.add(dependency);
+ pending.push(...(item.item_after ? item.item_after.split(',').map(Number) : []));
+ }
+}
+
/** Validate an addition before its sender runs a new check, and again when the ordered move applies. */
export function validateItemAddition(board, { by, lane, title, criterion = '', parentId = null, after = [], brief = '', route = 'strong', check }) {
const command = coordinatorCheck(by, check) ?? '';
@@ -698,32 +721,29 @@ export function validateItemAddition(board, { by, lane, title, criterion = '', p
throw new Refused('PARENT_CLOSED', `item #${parentId} is ${parent.item_status}`);
}
}
- for (const dependency of after) {
- if (itemById(board, dependency).item_status === 'withdrawn') {
- throw new Refused('WITHDRAWN', `item #${dependency} is withdrawn; nothing can wait on it`);
- }
- }
+ validateItemDependencies(board, null, after);
return { command, cleanTitle };
}
/**
- * Change an item's brief, route, criterion or check (B10, B13, B14). The coordinator may make a
- * claimed criterion/check correction at engine 8; the live holder must refreeze before renewal or
- * submission, and keeps the claim while adopting the new frozen bar.
+ * Change an item's brief, route, criterion, check or dependencies (B10, B13, B14). At engine 8 the
+ * coordinator may correct a claimed criterion, check or dependency; its holder refreezes before
+ * renewal or submission and keeps the claim while adopting the correction.
*
* @param {any} board
* @param {number} id
- * @param {{ agentId: string, brief?: string, route?: string, criterion?: string, check?: string }} change
+ * @param {{ agentId: string, brief?: string, route?: string, criterion?: string, check?: string, after?: number[] }} change
*/
-export function editItem(board, id, { agentId, brief, route, criterion, check, checkBaseline }) {
+export function editItem(board, id, { agentId, brief, route, criterion, check, after, checkBaseline }) {
atomic(board, () => {
const stored = itemById(board, id);
const expiredHolder = stored.item_status === 'claimed' && !isHeld(board, stored) ? stored.item_owner : null;
- const { item, next, command, unfreeze } = validateItemEdit(board, id, { agentId, brief, route, criterion, check });
+ const { item, next, command, unfreeze } = validateItemEdit(board, id, { agentId, brief, route, criterion, check, after });
const baseline = normalizeCheckBaseline(agentId, command, checkBaseline);
const pendingFields = [
...(next.item_criterion !== item.item_criterion ? ['criterion'] : []),
...(command !== undefined && next.item_check !== item.item_check ? ['check'] : []),
+ ...(next.item_after !== item.item_after ? ['after'] : []),
];
const pendingRefreeze = (board.executionEngineVersion ?? ENGINE_VERSION) >= 8
&& item.item_status === 'claimed' && agentId === COORDINATOR && pendingFields.length > 0;
@@ -738,6 +758,7 @@ export function editItem(board, id, { agentId, brief, route, criterion, check, c
...(next.item_route !== item.item_route ? { route: next.item_route } : {}),
...(next.item_criterion !== item.item_criterion ? { criterion: next.item_criterion } : {}),
...(command !== undefined ? { check: next.item_check } : {}),
+ ...(next.item_after !== item.item_after ? { after: next.item_after ? next.item_after.split(',').map(Number) : [] } : {}),
...(baseline ? { checkBaseline: baseline } : {}),
...(pendingRefreeze ? { pendingRefreeze: pendingFields } : {}),
...(clearFrozen && item.item_frozen_digest ? { unfrozen: item.item_frozen_digest } : {}),
@@ -755,14 +776,14 @@ export function editItem(board, id, { agentId, brief, route, criterion, check, c
}
/** Validate an edit without side effects, so a refused change never starts a shell baseline. */
-export function validateItemEdit(board, id, { agentId, brief, route, criterion, check }) {
+export function validateItemEdit(board, id, { agentId, brief, route, criterion, check, after }) {
let item = (board.executionEngineVersion ?? ENGINE_VERSION) >= 8 ? current(board, itemById(board, id)) : null;
if (item?.item_status === 'claimed' && agentId !== COORDINATOR) {
throw new Refused('HELD', `item #${id} is claimed; only the coordinator may edit it while held; shout coordinator`);
}
const command = coordinatorCheck(agentId, check);
- if ([brief, route, criterion, check].every((value) => value === undefined)) {
- throw new Refused('USAGE', 'say what changes: --brief "...", --brief-file <file>, --route light|mid|strong, --criterion "..." or --check "<command>"');
+ if ([brief, route, criterion, check, after].every((value) => value === undefined)) {
+ throw new Refused('USAGE', 'say what changes: --brief "...", --brief-file <file>, --route light|mid|strong, --criterion "...", --check "<command>" or --after <ids|none>');
}
item ??= current(board, itemById(board, id));
if (agentId !== COORDINATOR && agentId !== item.item_created_by) {
@@ -771,18 +792,20 @@ export function validateItemEdit(board, id, { agentId, brief, route, criterion,
if (['verified', 'withdrawn'].includes(item.item_status)) {
throw new Refused('CLOSED', `item #${id} is ${item.item_status}`);
}
+ if (after !== undefined) validateItemDependencies(board, id, after);
const next = {
item_brief: brief === undefined ? item.item_brief : brief.trim(),
item_route: route ?? item.item_route,
item_criterion: criterion === undefined ? item.item_criterion : criterion.trim(),
item_check: command === undefined ? item.item_check : command,
+ item_after: after === undefined ? item.item_after : after.join(','),
};
checkRoute(next.item_route);
- const moved = ['item_route', 'item_criterion', 'item_check'].filter((key) => next[key] !== item[key]);
+ const moved = ['item_route', 'item_criterion', 'item_check', 'item_after'].filter((key) => next[key] !== item[key]);
const routeChanged = next.item_route !== item.item_route;
const correctionWhileClaimed = (board.executionEngineVersion ?? ENGINE_VERSION) >= 8
&& item.item_status === 'claimed' && agentId === COORDINATOR
- && (next.item_criterion !== item.item_criterion || next.item_check !== item.item_check);
+ && (next.item_criterion !== item.item_criterion || next.item_check !== item.item_check || next.item_after !== item.item_after);
if (moved.length && item.item_status !== 'open' && (routeChanged || !correctionWhileClaimed)) {
throw new Refused('HELD', `item #${id} is ${item.item_status}; change its route, criterion or check only while it is open`);
}
@@ -1601,7 +1624,7 @@ export function pendingRefreeze(board, id) {
const fields = new Set();
for (const edit of edits) {
const details = JSON.parse(edit.event_detail);
- for (const field of details.pendingRefreeze ?? []) if (['criterion', 'check'].includes(field)) fields.add(field);
+ for (const field of details.pendingRefreeze ?? []) if (['after', 'criterion', 'check'].includes(field)) fields.add(field);
}
return [...fields].sort();
}
diff --git a/src/cli.js b/src/cli.js
index abd16ac3..a232c41b 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -325,6 +325,17 @@ function idArg(text, what = 'an item id') {
*/
const idList = (text) => (text ?? '').split(',').map((id) => id.trim()).filter(Boolean);
+/** Parse an edit's dependency replacement, with the explicit word `none` meaning clear all. */
+function editAfter(text) {
+ if (text === undefined) return undefined;
+ if (text.trim() === 'none') return [];
+ const parts = text.split(',').map((part) => part.trim());
+ if (!text.trim() || parts.some((part) => !part || part === 'none')) {
+ throw new Refused('USAGE', 'use --after <id>[,<id>...] or --after none');
+ }
+ return parts.map((part) => idArg(part, 'an item id after --after'));
+}
+
/**
* Text a command was given as --<name> "..." or as --<name>-file <file>, or undefined when neither.
* A file carries text past the shell exactly: backticks, dollar signs and quotes included.
@@ -2409,6 +2420,7 @@ function workCommands(io, args) {
route: values.route,
criterion: values.criterion,
check: values.check,
+ after: editAfter(values.after),
};
const { item, command } = store.validateItemEdit(board, id, change);
if (command && command !== item.item_check) change.checkBaseline = values.wait ? checkBaseline(ctx.info.root, command) : prepareCheckBaseline(ctx.info.root, command);
diff --git a/test/pending-refreeze.test.js b/test/pending-refreeze.test.js
index c5df6447..4d354aeb 100644
--- a/test/pending-refreeze.test.js
+++ b/test/pending-refreeze.test.js
@@ -117,6 +117,77 @@ test("the coordinator corrects a claimed item's criterion without release [V2]",
});
+test("edit adds and clears an item's dependencies [B3,V2]", (t) => {
+ const box = e2e.project('true');
+ t.after(e2e.cleanup);
+ const board = store.openBoard(join(box.repo, '.git/pullboard/board.sqlite'));
+ t.after(() => store.closeBoard(board));
+ /** Add one independent item through the real CLI and return its public id. */
+ const add = (title) => {
+ const result = box.run(box.repo, 'add', 'web', title, '--criterion', title, '--json');
+ assert.equal(result.code, 0, result.err || result.out);
+ return JSON.parse(result.out).item.item_id;
+ };
+ const first = add('First dependency');
+ const second = add('Second dependency');
+ const target = add('Dependency target');
+
+ const added = box.run(box.repo, 'edit', String(target), '--after', `${first},${second}`, '--json');
+ assert.equal(added.code, 0, added.err || added.out);
+ assert.equal(store.getItem(board, target).item_after, `${first},${second}`, 'edit stores both dependency ids in order');
+ const addEvent = store.events(board, { itemId: target }).findLast((event) => event.event_kind === 'edit');
+ assert.deepEqual(JSON.parse(addEvent.event_detail).after, [first, second], 'history records the dependency replacement');
+
+ const cleared = box.run(box.repo, 'edit', String(target), '--after', 'none', '--json');
+ assert.equal(cleared.code, 0, cleared.err || cleared.out);
+ assert.equal(store.getItem(board, target).item_after, '', 'none clears all dependencies');
+ const clearEvent = store.events(board, { itemId: target }).findLast((event) => event.event_kind === 'edit');
+ assert.deepEqual(JSON.parse(clearEvent.event_detail).after, [], 'history records a clear distinctly from an omitted edit');
+
+ const unchanged = store.getItem(board, target);
+ const eventCount = store.events(board, { itemId: target }).length;
+ refusal(box.run(box.repo, 'edit', String(target), '--after', '999999', '--json'), 'NO_ITEM');
+ assert.equal(store.getItem(board, target).item_after, unchanged.item_after, 'a missing dependency leaves the item unchanged');
+ assert.equal(store.events(board, { itemId: target }).length, eventCount, 'a refused dependency creates no history event');
+
+ assert.equal(box.run(box.repo, 'edit', String(first), '--after', String(second), '--json').code, 0);
+ const cycle = box.run(box.repo, 'edit', String(second), '--after', String(first), '--json');
+ refusal(cycle, 'DEPENDENCY_CYCLE');
+ assert.equal(store.getItem(board, second).item_after, '', 'a refused cycle leaves the edge unchanged');
+
+ const claimed = add('Claimed dependency target');
+ const claim = box.run(box.web, 'claim', String(claimed), '--json');
+ assert.equal(claim.code, 0, claim.err || claim.out);
+ const beforeCorrection = store.getItem(board, claimed);
+ const correction = box.run(box.repo, 'edit', String(claimed), '--after', String(first), '--json');
+ assert.equal(correction.code, 0, correction.err || correction.out);
+ const pending = store.getItem(board, claimed);
+ assert.equal(pending.item_after, String(first));
+ assert.equal(pending.item_owner, beforeCorrection.item_owner);
+ assert.equal(pending.item_lease_until, beforeCorrection.item_lease_until);
+ assert.equal(pending.item_claim_head, beforeCorrection.item_claim_head);
+ assert.equal(pending.item_frozen_digest, beforeCorrection.item_frozen_digest, 'the holder keeps the old frozen bar until refreeze');
+ assert.deepEqual(store.pendingRefreeze(board, claimed), ['after']);
+ const correctionEvent = store.events(board, { itemId: claimed }).findLast((event) => event.event_kind === 'edit');
+ assert.deepEqual(JSON.parse(correctionEvent.event_detail).pendingRefreeze, ['after']);
+ assert.deepEqual(JSON.parse(correctionEvent.event_detail).after, [first]);
+ assert.ok(store.inbox(board, beforeCorrection.item_owner).some((entry) =>
+ entry.shout_text.includes(`pending after correction for #${claimed}`)
+ && entry.shout_text.endsWith(`next: pullboard refreeze ${claimed}`)), 'the holder receives the pending-correction instruction');
+ refusal(box.run(box.web, 'submit', String(claimed), '--json'), 'PENDING_REFREEZE', claimed, ['after']);
+
+ const refrozen = box.run(box.web, 'refreeze', String(claimed), '--json');
+ assert.equal(refrozen.code, 0, refrozen.err || refrozen.out);
+ assert.equal(JSON.parse(refrozen.out).retainedClaim, true, 'the holder adopts the corrected bar without losing the claim');
+ const adopted = store.getItem(board, claimed);
+ assert.equal(adopted.item_status, 'claimed');
+ assert.equal(adopted.item_after, String(first));
+ assert.equal(adopted.item_owner, beforeCorrection.item_owner);
+ assert.equal(adopted.item_lease_until, beforeCorrection.item_lease_until);
+ assert.equal(store.pendingRefreeze(board, claimed).length, 0);
+ assert.ok(store.events(board, { itemId: claimed }).some((event) => event.event_kind === 'refreeze'), 'the holder refreeze is recorded in history');
+});
+
test('ordered refreeze corrections retain engine-7 history and engine-8 live claims [V2,H16]', (t) => {
const replicaDirectory = mkdtempSync(join(tmpdir(), 'pullboard-refreeze-replicas-'));
const replicaBoards = [];