cyberine
UsageRun recipes

ContextBrain — Code-Context 3-Act adapter (LocalBrain / ContextQBrain, T441/T454)

Separate from the memory-preamble backend above, the ContextBrain port (src/core/contextBrain.ts) is the seam behind the Code-Context 3-Act architecture (docs/design/code-context-3act.md) used by WorkflowEngine and cyberine loop (AutonomyLoop): one method per act.

  • boot (Act 1 SCOPE) — supply the worker a candidate file set + invariants + prior lessons before it starts.
  • recall (Act 2 STEER) — committed-state lookup on a verify failure (never live edits).
  • carry (Act 3 CARRY) — sink the post-judge capsule so future boots start warmer.

Two adapters, selected automatically by createContextBrain() (src/adapters/ContextQBrain.ts) — no code change needed, same CYBERINE_CONTEXTQ switch as the memory backend above:

  • LocalBrain (default, offline) — repo skeleton + git co-change signal + local MemoryStore lessons for boot/recall; writes the capsule to .local/runs/<runId>/context.md for carry.
  • ContextQBrain (CYBERINE_CONTEXTQ=1) — boot calls POST /api/agent/boot for a token-budgeted repo-map + lessons; recall calls POST /api/retrieve for a kNN lesson/passage lookup on a verify error; carry pushes the capsule to POST /api/contexts/bulk-upsert. LocalBrain's own output is always computed first as the offline floor — ContextQ's response only augments repoMap/lessons when it succeeds. Every method is best-effort: any network/HTTP failure (timeout, non-2xx, server down) degrades silently back to the LocalBrain result — a run must NEVER fail because ContextQ is unreachable.
export CYBERINE_CONTEXTQ=1                          # same master switch as the memory backend
export CYBERINE_CONTEXTQ_URL=http://localhost:38200  # ContextQ base URL
export CYBERINE_CONTEXTQ_API_KEY=sk_live_xxx        # scope read + write
npm run wf -- --sample                         # boot/recall/carry now round-trip through ContextQ
npm run selftest:contextq-brain                # offline smoke: stub server, no live ContextQ needed

Callers that explicitly inject a contextBrain/brain option (e.g. tests) still override the factory's choice.