/** * correction-detector.ts * * Shared pattern-matching logic for the hook-correction and hook-ambient * commands. Exported so it can be unit-tested without spawning the CLI process. * * TWO-GATE DESIGN * ────────────── * A prompt is captured only when BOTH gates fire: * • CORRECTION gate: text contradicts or negates something the agent did * • BEHAVIORAL gate: text implies a durable rule, not a one-time task redirect * * INVARIANT (C1 review, 2026-07-03): a pattern must live in exactly ONE gate. * If the same phrase fires both gates, the two-gate design filters nothing for * that phrase and it self-captures — measured 10/13 FP on realistic daily * traffic (scheduling reminders, research prose, encouragement). When a signal * is genuinely both corrective and durable, narrow it with context (accusatory * frame, format-domain scope) so the generic uses stay out. * * C1 FIX (2026-07-02, revised 2026-07-03): root causes of 11/17 durable misses: * RC1 — Behavioral gate was too strict: required explicit frequency language * ("again", "every time", "you always"). Durable rules stated ONCE as * absolute commands were killed by the behavioral gate. Added signals * for single-occurrence rule forms. * RC2 — Correction patterns missed indirect phrasing: "you actually did * not", "there is no X" (feature denial), "I should have", * "this is not a website". * Known regex-hard misses (accepted): pure positive instructions (E10), * autonomy grants (E41), bare one-off preference redirects (E57 — lost when * "i don't want you to" was scoped to a single gate; see test file). */ export interface DetectionResult { /** True when both the correction gate and behavioral gate fire (and prompt is non-trivial) */ captured: boolean; /** String form of the correction pattern that fired, or null */ correctionHit: string | null; /** String form of the behavioral pattern that fired, or null */ behavioralHit: string | null; } /** * Patterns that indicate the user is negating or correcting an agent output. * Necessary but not sufficient — a behavioral signal must also fire to * distinguish durable rules from one-time task redirects. * * SCOPE NOTE (2026-07-25, Codex audit follow-up): this gate's contract is * "the agent's output/action was wrong," not "here is a standing rule." A * pure forward-looking prohibition with no reference to something already * done — e.g. "不要在未经用户确认的情况下发布代码" ("do not publish code * without user confirmation first") — is prescriptive, not corrective: it * does not describe an agent output being negated, so it deliberately has * NO entry here. The nearest existing precedent, the "don't do that" / * "do not do that" family below, only qualifies because "that" is * anaphoric — it refers to a specific thing already said or done in * context. Generalizing this gate to fire on any bare prohibition would * mean treating "rule/policy statement" as synonymous with "correction of a * past action," which is not what this gate means; it would also reopen the * exact self-capture failure mode the two-gate INVARIANT above exists to * prevent (a prohibition is exactly the kind of phrase that also tends to * satisfy BEHAVIORAL_SIGNALS). Such prompts are still intentionally * uncapturable via this gate — see BEHAVIORAL_SIGNALS below for the CJK * absolute-prohibition additions that DO apply to them, and * correction-detector's own tests for what that leaves captured vs. not. */ export declare const CORRECTION_PATTERNS: readonly RegExp[]; /** * Patterns that indicate the correction encodes a reusable rule, not a * one-time task redirect. Both a correction AND a behavioral signal must fire * for the prompt to be stored in the alignment log. */ export declare const BEHAVIORAL_SIGNALS: readonly RegExp[]; /** * Determine whether a user prompt should be captured as a behavioral correction. * * Note: `correctionHit`/`behavioralHit` are reported even for prompts of * length ≤ 3 (hook-ambient uses the correction gate alone as a feedback * signal, e.g. a bare "不对" reply); only `captured` enforces the length floor. * * @param prompt The raw user message text. * @returns DetectionResult with `captured=true` when both gates fire. */ export declare function detectCorrection(prompt: string): DetectionResult; //# sourceMappingURL=correction-detector.d.ts.map