/** * @fileoverview Control Plane Gatekeeper — intercepts and routes user messages * through registered gate decisions before they reach the agent. Implements * the blocking/non-blocking gate pattern from the control plane architecture. * * Phase 61 — CP-01, CP-02, CP-03, CP-04 */ import { type PrimitiveEntry } from "../primitive-registry.js"; import { GateDecisionType } from "./gate-decision.js"; /** * A single gate decision definition that can be registered with the gatekeeper. */ export interface GateDecision { /** Unique identifier for this gate. */ id: string; /** Human-readable description of what this gate checks. */ description: string; /** Whether this gate blocks on denial. */ blocking: boolean; /** Evaluates the gate given a message context. */ evaluate: (context: GateEvaluationContext) => GateEvaluationResult | Promise; } /** * Context provided to gate evaluation functions. */ export interface GateEvaluationContext { /** The user message content. */ message: string; /** The current session ID. */ sessionId: string; /** Optional tool name if this is a tool-use evaluation. */ toolName?: string; /** Optional tool arguments if this is a tool-use evaluation. */ toolArgs?: Record; } /** * Result of a single gate evaluation. */ export interface GateEvaluationResult { /** The decision type. */ decision: GateDecisionType; /** Human-readable reason for the decision. */ reason: string; } /** * Aggregated result from evaluating all registered gates. */ export interface GateResult { /** Whether the message is allowed through. */ allowed: boolean; /** Individual gate evaluation results. */ decisions: Array<{ gateId: string; decision: GateDecisionType; reason: string; blocking: boolean; }>; /** Warnings from non-blocking gates. */ warnings: string[]; /** The gate that blocked the message, if any. */ blockingGate?: string; /** Total evaluation time in milliseconds. */ evaluationTimeMs: number; } /** * The gatekeeper interface returned by createGatekeeper. */ export interface Gatekeeper { /** Register a new gate decision. */ registerGate: (gate: GateDecision) => void; /** Get all registered gates. */ getRegisteredGates: () => GateDecision[]; /** Evaluate all gates against a message context. */ evaluate: (context: GateEvaluationContext) => Promise; /** Detect primitives from the project root. */ detectPrimitives: () => Promise; } /** * Gates that block message delivery on denial. */ export declare const BLOCKING_GATES: string[]; /** * Gates that allow the message through but may produce warnings. */ export declare const NON_BLOCKING_GATES: string[]; /** * Creates a new gatekeeper instance with built-in gates pre-registered. * * @param options - Configuration for the gatekeeper. * @returns A {@link Gatekeeper} instance. * * @example * ```ts * const gatekeeper = createGatekeeper({ projectRoot: "/path/to/project" }) * gatekeeper.registerGate(myCustomGate) * const result = await gatekeeper.evaluate({ message: "hello", sessionId: "s1" }) * if (!result.allowed) { * console.error("Blocked by:", result.blockingGate) * } * ``` */ export declare function createGatekeeper(options: { projectRoot: string; }): Gatekeeper; //# sourceMappingURL=gatekeeper.d.ts.map