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.

refactor(board): isolate event projection append [R2,C7]

Corey Olsonc72dce5edefb
diff --git a/src/board-event-log.js b/src/board-event-log.js
new file mode 100644
index 00000000..e656536c
--- /dev/null
+++ b/src/board-event-log.js
@@ -0,0 +1,39 @@
+/** Append native events and their rebuildable proof projection in the same transaction [R2]. */
+import { ENGINE_VERSION } from './machine.js';
+import { agentModel } from './seats.js';
+import { appendProofCounter } from './proof-counters.js';
+import { ensureProofCounters } from './proof-counters.js';
+
+/**
+ * Append one move to the event log (R2), retaining its exact row for an API response (A2).
+ * Exported for the board's own split modules, such as milestones.js, which record moves the same way.
+ *
+ * @param {any} board
+ * @param {string} by
+ * @param {string} kind
+ * @param {number | null} itemId
+ * @param {object} [detail]
+ * @param {Date} [at] An enabled move may share one instant with its deadline.
+ */
+export function logEvent(board, by, kind, itemId, detail = {}, at) {
+ board.db.exec('SAVEPOINT proof_event_append');
+ try {
+ ensureProofCounters(board);
+ const model = agentModel(board, by);
+ const isAgent = Boolean(board.db.prepare('SELECT 1 FROM agent WHERE agent_id = ?').get(by));
+ const recorded = { ...detail, ...((board.executionEngineVersion ?? ENGINE_VERSION) >= 8 && isAgent ? { model: model ?? 'unknown' } : {}),
+ ...(board.movePerson ? { person: board.movePerson } : {}) }; // The person behind a relayed move, from engine 73 (engine.js) [E3].
+ const inserted = board.db
+ .prepare('INSERT INTO event (event_at, event_by, event_kind, item_id, event_detail) VALUES (?, ?, ?, ?, ?)')
+ .run(at ? at.toISOString() : board.clock.now().toISOString(), by, kind, itemId, JSON.stringify(recorded));
+ const event = board.db.prepare('SELECT * FROM event WHERE event_id = ?').get(inserted.lastInsertRowid);
+ appendProofCounter(board, event);
+ board.db.exec('RELEASE proof_event_append');
+ board.lastEvent = event;
+ (board.emittedEvents ??= []).push(event);
+ } catch (error) {
+ board.db.exec('ROLLBACK TO proof_event_append; RELEASE proof_event_append');
+ throw error;
+ }
+}
+
diff --git a/src/board.js b/src/board.js
index 5809a5aa..0887bd87 100644
--- a/src/board.js
+++ b/src/board.js
@@ -1,5 +1,5 @@
-import { appendProofCounter } from './proof-counters.js';
-import { ensureProofCounters } from './proof-counters.js';
+import { logEvent } from './board-event-log.js';
+export { logEvent };
/**
* The board (B1–B7, V1–V8, R1–R3): items, claims, submissions, verdicts and shouts in one SQLite
* file in the git common dir, so every worktree sees the same board and nothing is committed.
@@ -85,7 +85,6 @@ import {
export { ROUTES, canTake };
import {
agentAt,
- agentModel,
listAgents,
newSeatId,
routeOf,
@@ -512,39 +511,6 @@ export function atomic(board, work) {
}
}
-/**
- * Append one move to the event log (R2), retaining its exact row for an API response (A2).
- * Exported for the board's own split modules, such as milestones.js, which record moves the same way.
- *
- * @param {any} board
- * @param {string} by
- * @param {string} kind
- * @param {number | null} itemId
- * @param {object} [detail]
- * @param {Date} [at] An enabled move may share one instant with its deadline.
- */
-export function logEvent(board, by, kind, itemId, detail = {}, at) {
- board.db.exec('SAVEPOINT proof_event_append');
- try {
- ensureProofCounters(board);
- const model = agentModel(board, by);
- const isAgent = Boolean(board.db.prepare('SELECT 1 FROM agent WHERE agent_id = ?').get(by));
- const recorded = { ...detail, ...((board.executionEngineVersion ?? ENGINE_VERSION) >= 8 && isAgent ? { model: model ?? 'unknown' } : {}),
- ...(board.movePerson ? { person: board.movePerson } : {}) }; // The person behind a relayed move, from engine 73 (engine.js) [E3].
- const inserted = board.db
- .prepare('INSERT INTO event (event_at, event_by, event_kind, item_id, event_detail) VALUES (?, ?, ?, ?, ?)')
- .run(at ? at.toISOString() : now(board), by, kind, itemId, JSON.stringify(recorded));
- const event = board.db.prepare('SELECT * FROM event WHERE event_id = ?').get(inserted.lastInsertRowid);
- appendProofCounter(board, event);
- board.db.exec('RELEASE proof_event_append');
- board.lastEvent = event;
- (board.emittedEvents ??= []).push(event);
- } catch (error) {
- board.db.exec('ROLLBACK TO proof_event_append; RELEASE proof_event_append');
- throw error;
- }
-}
-
/** Log an authenticated relay refusal without making an item, shout or verdict move [H2,H16]. */
export function recordRelayRefusal(board, { by, sequence, kind, operation, actor, code, itemId = null, person = null }) {
logEvent(board, by, 'relay_refused', itemId, { sequence, kind, operation, actor, code, ...(person ? { person } : {}) }); // who tried it, from engine 73 [E3]