Fix WBSContext types and align IntentManager

This commit is contained in:
kidist demessie 2026-02-18 19:26:13 +03:00
parent a87d239cf2
commit 2db1a917a4
2 changed files with 42 additions and 32 deletions

View file

@ -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<string> {
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 `<intent_context>
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(", ")}
</intent_context>`
} 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}`)

View file

@ -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
}>
}>