/** * PRI-482 Phase 3 — Production RuleContext v2 assembler * * Converts raw TrajectoryDatabase rows into a validated RuleHistoryWindow, * and provides buildProductionRuleContext for gate integration. * * ERR prevention: * - ERR-001: every row field is validated as unknown. No `as` bypass on * parsed params_json or outcome. * - ERR-024: buildProductionRuleContext fail-soft — query failure returns * unavailable, never throws. * - ERR-025: callers use recordToolCall → getRuleHostContextRows → this * assembler, covering the full production chain. * * Spec: docs/superpowers/specs/2026-06-27-rulecode-context-vision-design.md §5. */ import type { RuleContextV2, RuleHistoryWindow } from '@principles/core/runtime-v2'; import type { RuleHostContextResult, RuleHostContextRow } from './trajectory-types.js'; /** * Minimal interface for the data source that TrajectoryDatabase satisfies. * Allows testing buildProductionRuleContext without a real DB. */ export interface RuleContextDataSource { getRuleHostContextRows(sessionId: string, limit: number): RuleHostContextResult; } /** * Convert raw DB rows into a validated RuleHistoryWindow. * * If ANY row is malformed (bad params_json, invalid outcome, empty tool_name), * the entire window is marked unavailable (fail loud, spec §5.2). * * ERR-001: row fields are validated as unknown. params_json is JSON.parsed * then structurally checked (must be a non-array object). No `as` bypass. */ export declare function assembleHistoryFromRows(rows: readonly RuleHostContextRow[], truncated: boolean, projectDir: string): RuleHistoryWindow; /** * Build a RuleContextV2 from the production data source (TrajectoryDatabase). * * ERR-024: if the query or assembly fails, returns an unavailable context * (fail-soft). Never throws. * * sameActionBlockCount is always null in this version (spec §5.4: * session-tracker.blockedAttempts is a session total, not per-action). */ export declare function buildProductionRuleContext(sessionId: string | null | undefined, targetPath: string | null, source: RuleContextDataSource, projectDir: string, limit?: number): RuleContextV2;