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(', ')} + `; + } + } +}