From 9587081ab1d67b0f3341e73c3cedfe74e8a8af6d Mon Sep 17 00:00:00 2001 From: Rediet Bekele Date: Fri, 20 Feb 2026 16:16:13 +0000 Subject: [PATCH] feat(hooks): implement Pre-Hook for select_active_intent with XML intent_context injection --- apps/cli/src/ui/hooks/intentHooks.ts | 54 ++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 apps/cli/src/ui/hooks/intentHooks.ts diff --git a/apps/cli/src/ui/hooks/intentHooks.ts b/apps/cli/src/ui/hooks/intentHooks.ts new file mode 100644 index 0000000000..ce337da38c --- /dev/null +++ b/apps/cli/src/ui/hooks/intentHooks.ts @@ -0,0 +1,54 @@ +// src/hooks/intentHooks.ts +import fs from 'fs'; +import yaml from 'js-yaml'; + +interface Intent { + id: string; + name: string; + status: string; + owned_scope: string[]; + constraints: string[]; + acceptance_criteria: string[]; +} + +export class IntentHookEngine { + private intents: Record; + + constructor() { + this.intents = this.loadIntents(); + } + + private loadIntents(): Record { + const file = fs.readFileSync('.orchestration/active_intents.yaml', 'utf8'); + const data = yaml.load(file) as any; + const intents: Record = {}; + data.active_intents.forEach((intent: Intent) => { + intents[intent.id] = intent; + }); + return intents; + } + + /** + * Pre-Hook logic for select_active_intent + * - Validates intent_id + * - Injects constraints and scope + * - Returns XML block + */ + preHook(tool: string, payload: any) { + if (tool === 'select_active_intent') { + const intentId = payload.intent_id; + const intent = this.intents[intentId]; + + // Gatekeeper: block if invalid + if (!intent) { + throw new Error("You must cite a valid active Intent ID"); + } + + // Construct XML block + return ` + ${intent.constraints.join(', ')} + ${intent.owned_scope.join(', ')} + `; + } + } +}