mirror of
https://github.com/garrytan/gbrain.git
synced 2026-08-14 00:48:18 +00:00
* feat(mcp,context): ambient recall — context_pack + delta frozen verbs + boundary runtime (#1) Two new frozen MEMORY_VERBS (context_pack, delta) on the pull surface + a Claude Code hook boundary runtime on the push surface, sharing one stateless assembler core (assembleTurnContext mode: turn|pack|delta) and a keyset session cursor (migration v126). World-only by default; include_private gated fail-closed to trusted-local. protocol_version stays 1 (additive 5→7 verbs). Survived three adversarial review waves. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * v0.45.7.0 feat(mcp,context): ambient recall — context_pack + delta frozen verbs + boundary runtime (#1) Two new frozen MEMORY_VERBS (context_pack, delta) grow the frozen set 5→7 without a wire bump — all seven stamp protocol_version: 1. context_pack assembles a deterministic, zero-LLM, budget-packed bundle (entity cards + open threads + hot facts) for a set of standing entities; delta returns only what changed since a timestamp for cheap heartbeats, with a per-session keyset cursor for at-least-once delivery. A boundary runtime wires these into Claude Code lifecycle hooks (SessionStart warm pack, PreCompact entity banking for post-compaction rehydration); Codex and any MCP host pull the same verbs at their own boundaries. World-only by default on all arms; include_private widens only for local trusted callers. Migration v126 adds session_context_state (additive). Includes the coverage close-out wave (~55 tests): real-serve compact→ session-start round trip over the live socket, --surface verbs stdio session pinning exactly 7 tools fail-closed, HTTP-transport verb calls with per-token cursor isolation, Postgres engine-parity for keyset pagination + the session-cursor table, migration v126 shape + rewind test, sub-second latency gates, CLI-level invocations, rendered-protocol boundary assertions, and a live-Codex boundary-call check. The wave caught and fixed three real bugs: the delta CLI wedging on first wake (floating GC promise racing engine teardown), the compact hook probing the PGLite socket on a Postgres config with a leftover database_path, and the verbs-surface banner hardcoding a stale verb count. Also the /document-release sweep: stale "five verbs" → seven across the protocol doc, README, INSTALL, DEPLOY, the Claude Code MCP guide, and the query skill; deferred scope filed in TODOS. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(release): bump openclaw.plugin.json to 0.45.7.0 — the sixth version location The #4033 merge auto-resolved the OpenClaw plugin manifest at master's version while the trio moved to 0.45.7.0, failing the manifest drift test on CI shard 4. Register the file in CLAUDE.md's version-locations table (five → six) so every future ship and merge re-bumps it with the trio. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
111 lines
4.1 KiB
TypeScript
111 lines
4.1 KiB
TypeScript
/**
|
|
* MEMORY_VERBS v1 — surface-mode tests (Cathedral 1).
|
|
*
|
|
* - 'verbs' filters to EXACTLY the seven protocol verbs
|
|
* - 'full' is the identity (existing installs unchanged)
|
|
* - dispatch-layer allowedOps is FAIL-CLOSED: a hidden op is uncallable
|
|
* (unknown_tool), not merely unlisted [c2]
|
|
* - flag parsing is strict (unknown value rejects loudly)
|
|
* - resolution: flag > config mcp_surface > 'full'
|
|
*/
|
|
|
|
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
|
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
|
|
import { operations } from '../src/core/operations.ts';
|
|
import { VERB_NAMES } from '../src/core/verbs.ts';
|
|
import {
|
|
filterOpsForSurface,
|
|
allowedOpNames,
|
|
parseSurfaceFlag,
|
|
resolveSurface,
|
|
} from '../src/mcp/surface.ts';
|
|
import { dispatchToolCall } from '../src/mcp/dispatch.ts';
|
|
import { __setUsageLogPathForTests } from '../src/core/verbs/usage-log.ts';
|
|
|
|
let engine: PGLiteEngine;
|
|
let home: string;
|
|
|
|
beforeAll(async () => {
|
|
// Sidecar writes go to a temp file via the test seam — no global env mutation.
|
|
home = mkdtempSync(join(tmpdir(), 'gbrain-surface-test-'));
|
|
__setUsageLogPathForTests(join(home, 'usage.jsonl'));
|
|
engine = new PGLiteEngine();
|
|
await engine.connect({});
|
|
await engine.initSchema();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await engine.disconnect();
|
|
__setUsageLogPathForTests(null);
|
|
try { rmSync(home, { recursive: true, force: true }); } catch { /* best-effort */ }
|
|
});
|
|
|
|
describe('filterOpsForSurface', () => {
|
|
it("'verbs' returns exactly the seven protocol verbs", () => {
|
|
const names = filterOpsForSurface(operations, 'verbs').map(o => o.name).sort();
|
|
expect(names).toEqual([...VERB_NAMES].sort());
|
|
});
|
|
|
|
it("'full' is the identity — existing installs see every op", () => {
|
|
expect(filterOpsForSurface(operations, 'full')).toEqual(operations);
|
|
});
|
|
});
|
|
|
|
describe('dispatch allowedOps — fail-closed [c2]', () => {
|
|
it('a hidden op returns unknown_tool even when called by name', async () => {
|
|
const allowed = allowedOpNames(operations, 'verbs');
|
|
const res = await dispatchToolCall(engine, 'get_page', { slug: 'x' }, {
|
|
remote: true,
|
|
sourceId: 'default',
|
|
allowedOps: allowed,
|
|
surface: 'verbs',
|
|
});
|
|
expect(res.isError).toBe(true);
|
|
const body = JSON.parse(res.content[0].text);
|
|
expect(body.error).toBe('unknown_tool');
|
|
});
|
|
|
|
it('a surfaced verb still dispatches under the same allowedOps set', async () => {
|
|
const allowed = allowedOpNames(operations, 'verbs');
|
|
const res = await dispatchToolCall(engine, 'entity', { name: 'zzz-nobody' }, {
|
|
remote: true,
|
|
sourceId: 'default',
|
|
allowedOps: allowed,
|
|
surface: 'verbs',
|
|
});
|
|
expect(res.isError ?? false).toBe(false);
|
|
const body = JSON.parse(res.content[0].text);
|
|
expect(body.found).toBe(false);
|
|
});
|
|
|
|
it('without allowedOps (full surface) every op stays callable — pre-existing behavior', async () => {
|
|
const res = await dispatchToolCall(engine, 'get_stats', {}, {
|
|
remote: true,
|
|
sourceId: 'default',
|
|
});
|
|
expect(res.isError ?? false).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('parseSurfaceFlag + resolveSurface', () => {
|
|
it('parses verbs/full, rejects unknown values loudly, requires a value', () => {
|
|
expect(parseSurfaceFlag(['--surface', 'verbs'])).toBe('verbs');
|
|
expect(parseSurfaceFlag(['--surface', 'full'])).toBe('full');
|
|
expect(parseSurfaceFlag(['serve'])).toBe(null);
|
|
expect(() => parseSurfaceFlag(['--surface', 'all'])).toThrow(/Unknown --surface/);
|
|
expect(() => parseSurfaceFlag(['--surface'])).toThrow(/requires a value/);
|
|
expect(() => parseSurfaceFlag(['--surface', '--http'])).toThrow(/requires a value/);
|
|
});
|
|
|
|
it('resolution: flag > config mcp_surface > full', () => {
|
|
expect(resolveSurface('verbs', { mcp_surface: 'full' })).toBe('verbs');
|
|
expect(resolveSurface(null, { mcp_surface: 'verbs' })).toBe('verbs');
|
|
expect(resolveSurface(null, {})).toBe('full');
|
|
expect(resolveSurface(null, null)).toBe('full');
|
|
expect(resolveSurface(null, { mcp_surface: 'bogus' as never })).toBe('full');
|
|
});
|
|
});
|