From 2db1a917a4379780330dabb76553212e75a3fd6c Mon Sep 17 00:00:00 2001 From: kidist demessie Date: Wed, 18 Feb 2026 19:26:13 +0300 Subject: [PATCH] Fix WBSContext types and align IntentManager --- src/hooks/IntentManager.ts | 55 +++++++++++++++++++++++--------------- src/hooks/types.ts | 19 +++++++------ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/hooks/IntentManager.ts b/src/hooks/IntentManager.ts index cb50d4f011..99a5c1bd36 100644 --- a/src/hooks/IntentManager.ts +++ b/src/hooks/IntentManager.ts @@ -7,55 +7,66 @@ export class IntentManager { private activeIntent: WBSContext | null = null private orchestrationPath = path.join(process.cwd(), ".orchestration", "active_intents.yaml") - /** - * Stage 1: The Handshake. - * Loads the What-Boundaries-Success (WBS) framework constraints - * for the selected requirement (Bora, 2024). - */ async loadIntentContext(intentId: string): Promise { try { const fileContent = await fs.readFile(this.orchestrationPath, "utf8") const data: any = yaml.load(fileContent) + if (!data?.active_intents) { + throw new Error("No active_intents section found in YAML") + } + const intent = data.active_intents.find((i: any) => i.id === intentId) if (!intent) { throw new Error(`Intent ID ${intentId} not found in .orchestration/active_intents.yaml`) } - this.activeIntent = intent + // Ensure all arrays are properly typed + const what: string[] = Array.isArray(intent.what) ? intent.what : [String(intent.what)] + const constraints: string[] = Array.isArray(intent.constraints) + ? intent.constraints + : [String(intent.constraints)] + const acceptance_criteria: string[] = Array.isArray(intent.acceptance_criteria) + ? intent.acceptance_criteria + : [String(intent.acceptance_criteria)] + const owned_scope: string[] = Array.isArray(intent.owned_scope) + ? intent.owned_scope + : [String(intent.owned_scope)] + + // Map to full WBSContext type + this.activeIntent = { + id: intent.id, + what, + constraints, + acceptance_criteria, + owned_scope, + boundaries: constraints, + success: acceptance_criteria, + } as WBSContext - // Inject Level 3 Black-Box Functional Model constraints (Navarro et al., 2001) return ` ID: ${intent.id} -WHAT: ${intent.what.join(", ")} -BOUNDARIES: ${intent.constraints.join(", ")} -SUCCESS: ${intent.acceptance_criteria.join(", ")} -OWNED_SCOPE: ${intent.owned_scope.join(", ")} +WHAT: ${what.join(", ")} +BOUNDARIES: ${constraints.join(", ")} +SUCCESS: ${acceptance_criteria.join(", ")} +OWNED_SCOPE: ${owned_scope.join(", ")} ` } catch (error: any) { throw new Error(`Intent Handshake Failed: ${error.message}`) } } - /** - * Returns the ID of the currently active intent, or null if none. - */ getActiveIntent(): string | null { return this.activeIntent?.id || null } - /** - * Scope Enforcement: Verifies if the target file is within - * the authorized 'owned_scope' of the active intent. - */ verifyScope(targetPath: string): void { if (!this.activeIntent) return - // Simplified glob matching; implement full 'picomatch' or 'minimatch' for production - const isAuthorized = this.activeIntent.owned_scope.some((pattern) => - targetPath.includes(pattern.replace("/**", "")), - ) + const ownedScope: string[] = this.activeIntent.owned_scope ?? [] + + const isAuthorized = ownedScope.some((pattern: string) => targetPath.includes(pattern.replace("/**", ""))) if (!isAuthorized) { throw new Error(`Scope Violation: Intent ${this.activeIntent.id} is not authorized to edit ${targetPath}`) diff --git a/src/hooks/types.ts b/src/hooks/types.ts index 8cabbb2e6b..c0e1737e5e 100644 --- a/src/hooks/types.ts +++ b/src/hooks/types.ts @@ -9,14 +9,14 @@ export enum MutationClass { /** * WBSContext formalizes the "What-Boundaries-Success" framework - * to reduce the LLM's solution space through structured constraints.[1] + * to reduce the LLM's solution space through structured constraints. */ export interface WBSContext { id: string // e.g., "INT-001" - owned_scope: string // Glob patterns of authorized files - what: string // Functional requirements - boundaries: string // "Soft constraints" to prevent hallucinations [1] - success: string // Measurable criteria for the "Definition of Done" + owned_scope: string[] // Glob patterns of authorized files + what: string[] // Functional requirements + boundaries: string[] // "Soft constraints" to prevent hallucinations + success: string[] // Measurable criteria for "Definition of Done" } /** @@ -24,12 +24,12 @@ export interface WBSContext { * a position-independent audit log of AI contributions. */ export interface TraceRecord { - version: string // Specification version (e.g., "1.0") - id: string // Unique UUID for the trace event - timestamp: string // ISO 8601 recorded time + version: string + id: string + timestamp: string vcs?: { type: "git" | "jj" | "hg" | "svn" - revision: string // VCS-specific revision hash + revision: string } files: Array<{ path: string @@ -41,7 +41,6 @@ export interface TraceRecord { ranges: Array<{ start_line: number end_line: number - // Content hash H for spatial independence content_hash?: string }> }>