/** * Per-session CLEO_OWNER_OVERRIDE cap with waiver-doc requirement (T1501 / P0-5). * * Enforces a hard cap (default: 10) on how many times `CLEO_OWNER_OVERRIDE` may * be used within a single session. Above the cap the call is rejected with * `E_OVERRIDE_CAP_EXCEEDED` unless the operator sets: * * `CLEO_OWNER_OVERRIDE_WAIVER=` * * The waiver file must exist and contain `cap-waiver: true` (YAML front-matter * or a plain line in the file). * * The running count is persisted in * `.cleo/audit/session-override-count..json` so it survives across * multiple CLI invocations within the same session (each invocation is its own * process). * * ## Worktree-context exemption (T1504) * * Overrides that originate from a worktree-orchestrate workflow are tagged with * `workTreeContext: true` and excluded from the per-session cap counter. They * are still logged in full to force-bypass.jsonl for audit purposes. * * Detection: the `command` argument contains a path segment matching the * canonical worktree layout (`/worktrees/`). This heuristic is controlled by * the `CLEO_OVERRIDE_EXEMPT_WORKTREE` env var (defaults to `true`). * * @adr ADR-059 * @task T1501 * @task T1504 */ /** * Default maximum CLEO_OWNER_OVERRIDE uses per session (T1501 / P0-5). * * Raised from 3 → 10 by T1504: orchestrate sessions legitimately spawn multiple * workers that each re-verify, so the original 3 was too low. */ export declare const DEFAULT_OVERRIDE_CAP_PER_SESSION = 10; /** * Canonical worktree path segment used to detect worktree-orchestrate context * (T1504 / ADR-059 §D3). * * When a `command` string contains this segment the override is considered * originating from an orchestrate worktree and is exempt from the per-session * cap counter (but still logged). */ export declare const WORKTREE_PATH_SEGMENT = "/worktrees/"; /** * Whether worktree-context overrides are exempt from the per-session cap counter. * * Controlled by the `CLEO_OVERRIDE_EXEMPT_WORKTREE` environment variable. * Defaults to `true`. Set to `"0"` or `"false"` to disable the exemption. * * @task T1504 */ export declare function isWorktreeExemptionEnabled(): boolean; /** * Detect whether a CLI command string originates from a worktree-orchestrate * workflow by checking for the canonical worktree path segment. * * @param command - The CLI command line string (e.g. from `process.argv`). * @returns `true` when the command path contains `/worktrees/`. * * @task T1504 */ export declare function isWorktreeContext(command: string): boolean; /** * Resolve the path of the per-session override count file. * * @param projectRoot - Absolute path to the project root. * @param sessionId - Active session ID (use "global" when no session). * @returns Absolute path to `.cleo/audit/session-override-count..json`. * * @task T1501 */ export declare function getSessionOverrideCountPath(projectRoot: string, sessionId: string): string; /** * Read the persisted override count for a session. * * Returns 0 when the file does not exist (new session or first override). * * @param projectRoot - Absolute path to the project root. * @param sessionId - Active session ID. * @returns Current override count for the session. * * @task T1501 */ export declare function readSessionOverrideCount(projectRoot: string, sessionId: string): number; /** * Persist the override count for a session. * * Errors are swallowed — persistence failures must not block the override * write. The count file is advisory; the real audit trail is force-bypass.jsonl. * * @param projectRoot - Absolute path to the project root. * @param sessionId - Active session ID. * @param count - Updated count to persist. * * @task T1501 */ export declare function writeSessionOverrideCount(projectRoot: string, sessionId: string, count: number): void; /** * Clear the persisted override count for a session. * * Called at session end to reset the counter so a subsequent session always * starts at zero (T9505 — BUG #5: override-cap session-end cleanup). * * Errors are swallowed — a missing or already-deleted file is treated as * already cleared. Clearing failures must never block session end. * * @param projectRoot - Absolute path to the project root. * @param sessionId - The session ID whose counter file should be removed. * * @task T9505 */ export declare function clearSessionOverrideCount(projectRoot: string, sessionId: string): void; /** * Validate that a waiver document exists and contains the required marker. * * The waiver file must: * 1. Exist at the absolute path specified by `CLEO_OWNER_OVERRIDE_WAIVER`. * 2. Contain the string `cap-waiver: true` (any position in the file). * * @param waiverPath - Absolute path to the waiver document. * @returns `{ valid: true }` when the waiver is accepted, or * `{ valid: false, reason: string }` when it is rejected. * * @task T1501 */ export declare function validateWaiverDoc(waiverPath: string): { valid: boolean; reason?: string; }; /** Result of the override cap check. */ export interface OverrideCapResult { /** Whether the override is permitted. */ allowed: boolean; /** Error code when not allowed (E_OVERRIDE_CAP_EXCEEDED). */ errorCode?: string; /** Human-readable message. */ errorMessage?: string; /** 1-based ordinal of this override within the session (populated on success). */ sessionOverrideOrdinal?: number; /** * True when the override was exempt from the cap counter because it originated * from a worktree-orchestrate workflow (T1504 / ADR-059 §D3). * * Worktree-context overrides are still logged in force-bypass.jsonl. */ workTreeContext?: boolean; } /** * Check and enforce the per-session CLEO_OWNER_OVERRIDE cap. * * Reads the persisted count, checks it against the cap, validates the waiver * doc when required, increments the count on success, and returns the ordinal. * * ## Worktree-context exemption (T1504 / ADR-059 §D3) * * When `command` contains `/worktrees/` AND `CLEO_OVERRIDE_EXEMPT_WORKTREE` is * not disabled, the override is permitted without counting against the cap. It * is still logged in force-bypass.jsonl with `workTreeContext: true`. * * @param projectRoot - Absolute path to the project root. * @param sessionId - Active session ID ("global" when no session is active). * @param cap - Maximum overrides allowed per session (default: 10). * @param command - CLI command string used for worktree-context detection (optional). * @returns `OverrideCapResult` indicating whether the override is permitted. * * @task T1501 * @task T1504 * @adr ADR-059 */ export declare function checkAndIncrementOverrideCap(projectRoot: string, sessionId: string, cap?: number, command?: string): OverrideCapResult; //# sourceMappingURL=override-cap.d.ts.map