🧠the-brain

Hook System

Event-driven plugin system powering the-brain's cognitive layers

All plugins communicate through hooks defined in @the-brain/core.

Hook Events

HookWhenConsumer
HARVESTER_POLLDaemon polls IDE logsHarvesters
HARVESTER_NEW_DATANew interaction foundAll layers
BEFORE_PROMPTBefore prompt reaches LLMGraph Memory
AFTER_RESPONSEAfter LLM respondsSPM Curator
ON_INTERACTIONEvery interactionSPM Curator
SELECTION_EVALUATEEvaluate for promotionSPM Curator
SELECTION_PROMOTEPromote to deeper layerSPM Curator → DEEP
DEEP_CONSOLIDATEDeep layer consolidationMLX Trainer, Auto-Wiki
TRAINING_STARTMLX training beginsIdentity Anchor
TRAINING_COMPLETEMLX training finishesNotifications
DAEMON_STARTDaemon startupAll plugins
DAEMON_STOPDaemon shutdownCleanup

Registration

import { definePlugin, HookEvent } from "@the-brain/core";

export default definePlugin({
  name: "my-plugin",
  setup(hooks) {
    hooks.hook(HookEvent.AFTER_RESPONSE, async (ctx) => {
      // ctx.interaction, ctx.fragments, ctx.promoteToDeep()
    });
  },
});

Execution

  • Handlers execute serially in registration order
  • Errors in one handler don't stop others
  • Powered by hookable — lightweight, async-safe

Layer Routing

const router = new LayerRouter();
router.registerInstant(graphMemory);    // ⚡ Layer 1
router.registerSelection(spmCurator);   // ⚖️ Layer 2
router.registerDeep(mlxTrainer);       // 🌌 Layer 3

await router.runInstant(promptCtx);     // Inject context
await router.runSelection(ctx);         // Evaluate + promote
await router.runDeep(ctx);              // Train + wiki

On this page