Skip to content

Commit ae483fa

Browse files
hyperpolymathclaude
andcommitted
feat(local-coord-mcp): Tasks #2 + #7b — wire boj_cartridge_invoke + VeriSimDB seam
Task #2: Replace Grade-D stub boj_cartridge_invoke with real FFI dispatch. All 20 cartridge tools now parse JSON args (page_allocator) and call the appropriate coord_* functions directly. Output matches local_coord_adapter.zig exactly. 60/60 tests pass; two stub tests updated for real arg validation. Task #7b: Wire VeriSimDB supplementary durability backend in coord_durability.zig. BOJ_VERISIMDB_ENDPOINT env var arms the backend; vdb_append_event() / vdb_replay_events() establish the seam. Real API calls stubbed pending verisimdb-mcp FFI exposing a streaming append-log endpoint beyond the current octad-level interface. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 67d6dbc commit ae483fa

2 files changed

Lines changed: 895 additions & 44 deletions

File tree

cartridges/local-coord-mcp/ffi/coord_durability.zig

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,51 @@ pub const EventType = enum(u16) {
6464
const ENV_VAR = "BOJ_COORD_STATE_DIR";
6565
const LOG_FILE_NAME = "coord.log";
6666

67+
// ── VeriSimDB backend (Task #7b) ──────────────────────────────────────
68+
//
69+
// When BOJ_VERISIMDB_ENDPOINT is set, events are also forwarded to VeriSimDB
70+
// alongside the local file backend. The local file backend remains the
71+
// primary durability store; VeriSimDB adds cross-restart queryability and
72+
// multi-modality provenance.
73+
//
74+
// Current status: infrastructure wired, VeriSimDB API call stubs pending.
75+
// Completion requires verisimdb-mcp FFI to expose an append-log API beyond
76+
// the current octad-level interface (verisimdb_store_octad / verisimdb_get_octad
77+
// are too coarse for per-event streaming). This wiring establishes the seam.
78+
79+
const VDB_ENV_VAR = "BOJ_VERISIMDB_ENDPOINT";
80+
const VDB_ENDPOINT_MAX = 128;
81+
82+
var vdb_endpoint: [VDB_ENDPOINT_MAX]u8 = undefined;
83+
var vdb_endpoint_len: usize = 0;
84+
85+
/// True when the VeriSimDB endpoint is configured.
86+
pub fn vdbEnabled() bool {
87+
return vdb_endpoint_len > 0;
88+
}
89+
90+
/// Forward one event to VeriSimDB. Stub: real impl will call verisimdb-mcp
91+
/// FFI once that exposes a streaming append-log endpoint. Errors are swallowed
92+
/// — VeriSimDB is supplementary; the local file log is authoritative.
93+
fn vdb_append_event(event: EventType, payload: []const u8) void {
94+
if (!vdbEnabled()) return;
95+
// TODO(Task #7b): call verisimdb_store_octad or a future
96+
// verisimdb_append_event once the FFI exposes a log-entry API.
97+
// Key: std.fmt.bufPrint("coord-event-{d}-{d}", .{@intFromEnum(event), timestamp})
98+
// Data: binary payload or A2ML-encoded event record.
99+
_ = event;
100+
_ = payload;
101+
}
102+
103+
/// Query VeriSimDB for all coord events and replay them via cb.
104+
/// Stub: real impl will use verisimdb query-by-tag once the FFI is richer.
105+
fn vdb_replay_events(cb: ReplayCb) void {
106+
if (!vdbEnabled()) return;
107+
// TODO(Task #7b): query verisimdb for events with prefix "coord-event-"
108+
// ordered by timestamp and call cb for each valid record.
109+
_ = cb;
110+
}
111+
67112
var log_file: ?std.fs.File = null;
68113
var mutex: std.Thread.Mutex = .{};
69114

@@ -101,7 +146,16 @@ pub fn openWithDir(dir: []const u8) bool {
101146
}
102147

103148
/// Open the log using BOJ_COORD_STATE_DIR. No-op if unset / empty.
149+
/// Also arms the VeriSimDB supplementary backend if BOJ_VERISIMDB_ENDPOINT
150+
/// is set (Task #7b). VeriSimDB does not gate file-backend success.
104151
pub fn open() bool {
152+
// Arm VeriSimDB supplementary backend.
153+
if (std.posix.getenv(VDB_ENV_VAR)) |ep| {
154+
if (ep.len > 0 and ep.len <= VDB_ENDPOINT_MAX) {
155+
@memcpy(vdb_endpoint[0..ep.len], ep);
156+
vdb_endpoint_len = ep.len;
157+
}
158+
}
105159
const env = std.posix.getenv(ENV_VAR) orelse return false;
106160
if (env.len == 0) return false;
107161
return openWithDir(env);
@@ -132,10 +186,14 @@ pub fn truncate() void {
132186

133187
/// Append a typed event. Silently no-ops when the log is closed; errors
134188
/// during write are swallowed — durability is best-effort and must not
135-
/// block the coord hot path.
189+
/// block the coord hot path. Also forwards to VeriSimDB if configured.
136190
pub fn append(event: EventType, payload: []const u8) void {
137191
if (payload.len > MAX_PAYLOAD) return;
138192

193+
// Forward to VeriSimDB supplementary backend (Task #7b).
194+
// Runs before the mutex so VeriSimDB can have its own concurrency model.
195+
vdb_append_event(event, payload);
196+
139197
mutex.lock();
140198
defer mutex.unlock();
141199
const f = log_file orelse return;

0 commit comments

Comments
 (0)