mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-12 23:01:21 +00:00
feat(hooks): implement Pre-Hook for select_active_intent with XML intent_context injection
This commit is contained in:
parent
09114e7c02
commit
9587081ab1
1 changed files with 54 additions and 0 deletions
54
apps/cli/src/ui/hooks/intentHooks.ts
Normal file
54
apps/cli/src/ui/hooks/intentHooks.ts
Normal file
|
|
@ -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<string, Intent>;
|
||||
|
||||
constructor() {
|
||||
this.intents = this.loadIntents();
|
||||
}
|
||||
|
||||
private loadIntents(): Record<string, Intent> {
|
||||
const file = fs.readFileSync('.orchestration/active_intents.yaml', 'utf8');
|
||||
const data = yaml.load(file) as any;
|
||||
const intents: Record<string, Intent> = {};
|
||||
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 <intent_context> 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_context>
|
||||
<constraints>${intent.constraints.join(', ')}</constraints>
|
||||
<scope>${intent.owned_scope.join(', ')}</scope>
|
||||
</intent_context>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue