Skip to content

C-286: OAA sovereign memory layer — signed /api/oaa/kv journal#41

Merged
kaizencycle merged 1 commit into
mainfrom
cursor/c286-oaa-sovereign-memory-49d6
Apr 19, 2026
Merged

C-286: OAA sovereign memory layer — signed /api/oaa/kv journal#41
kaizencycle merged 1 commit into
mainfrom
cursor/c286-oaa-sovereign-memory-49d6

Conversation

@kaizencycle

Copy link
Copy Markdown
Owner

Summary

This change introduces POST/GET /api/oaa/kv as the sovereign append journal for Mobius: HMAC-authenticated structured writes, deterministic SHA-256 hashing over canonical JSON, append-only persistence into OAA_MEMORY.json, and an async optional forward to Civic Protocol Core via POST …/mesh/ingest (when ledger URL + bearer token are configured).

Motivation / problem

The stack needs a signed, hash-chained memory trail separate from hot KV. OAA already owns OAA_MEMORY.json and governance surfaces; this PR implements the write contract and read surface described for C-286.

What changed

  • types/oaa-kv.tsAgentKVPayload and OaaMemoryEntry (OAA_MEMORY_ENTRY_V1).
  • lib/crypto/canonicalJson.ts — sorted-key canonical JSON for stable signing/hashing.
  • lib/crypto/hmac.ts — SHA-256 hex, HMAC sign/verify (timing-safe).
  • lib/kv/store.ts — append-only journal entries merged with existing memory file shape; getLatestHash walks from the end for the latest OAA_MEMORY_ENTRY_V1 only.
  • lib/ledger/bridge.ts — fire-and-forget sealToLedger using CIVIC_LEDGER_URL or LEDGER_BASE_URL + CIVIC_LEDGER_TOKEN or LEDGER_ADMIN_TOKEN.
  • pages/api/oaa/kv.ts — GET ?prefix= for structured entries; POST verifies HMAC over canonical { key, value, agent, cycle, intent, previousHash }.
  • render.yaml — optional KV_HMAC_SECRET and CIVIC_LEDGER_TOKEN for oaa-hub (secret also falls back to MEMORY_HMAC_SECRET / OAA_HMAC_SECRET in code).
  • vitest.config.ts + tests/oaa-kv-sovereign.test.ts — unit tests for canonical JSON and HMAC.

Breaking changes

No. New endpoint and env vars; existing memory notes remain readable.

Tests

npm ci
npm run vitest
# Test Files  1 passed (1)
# Tests  3 passed (3)

npm run lint and npm run type-check still fail on pre-existing repo issues (binary/parsing TSX files, etc.); new files pass IDE diagnostics.

Checklist

  • Implementation matches C-286 OAA PR scope (this repo only)
  • Vitest added and passing
  • Full repo lint/type-check clean (blocked by unrelated files)
Open in Web Open in Cursor 

Add HMAC-verified POST for structured agent KV writes with canonical JSON
hashing, append-only OAA_MEMORY.json entries (OAA_MEMORY_ENTRY_V1), GET
queries by key prefix, and async Civic Core mesh/ingest bridge. Document
Render env vars KV_HMAC_SECRET and CIVIC_LEDGER_TOKEN; add Vitest coverage
for canonical JSON and HMAC helpers.
@kaizencycle
kaizencycle marked this pull request as ready for review April 19, 2026 18:40
@kaizencycle
kaizencycle merged commit d8331f7 into main Apr 19, 2026
1 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants