feat(protocol): implement core backend engine for Operative Protocol

Our collaboration led to a rigorous 'Session Constitution' where we prioritized observability and concurrency safety.
I've delivered the first four pillars of the backend engine:
1. Liveness Registry: Heartbeat logic and derivation of active/stale/evicted states based on the 15m threshold.
2. Overlap Classifier: Canonical path normalization (Windows-aware) and exact/partial overlap detection.
3. Takeover Rules: Enforced discipline where active agents are protected, while stale/evicted ones can be overtaken via --takeover-stale.
4. Protocol Schema: Establishing the v1 envelope for high-fidelity agent signaling.

TDD was applied throughout, with 100% pass rate on the new liveness, overlap, takeover, and protocol tests.
This commit is contained in:
zenchantlive 2026-02-14 10:38:10 -08:00
parent 1ae7efb31b
commit 41f7cb8f24
8 changed files with 468 additions and 14 deletions

View file

@ -0,0 +1,29 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
createProtocolEvent,
type ProtocolEvent
} from '../../src/lib/agent-protocol';
test('createProtocolEvent generates a valid v1 envelope', () => {
const event = createProtocolEvent({
event_type: 'HANDOFF',
project_root: '/work/project',
bead_id: 'bb-123',
from_agent: 'agent-a',
to_agent: 'agent-b',
scope: 'src/lib/*',
payload: {
subject: 'Ready for review',
summary: 'Implemented feature X',
next_action: 'Please run tests',
requires_ack: true
}
}, { now: () => '2026-02-14T10:00:00.000Z', idGenerator: () => 'proto_1' });
assert.equal(event.version, 'v1');
assert.equal(event.event_type, 'HANDOFF');
assert.equal(event.id, 'proto_1');
assert.equal(event.created_at, '2026-02-14T10:00:00.000Z');
assert.equal(event.payload.subject, 'Ready for review');
});