#!/usr/bin/env node /** * Forgen — Context Guard Hook * * Claude Code Stop 훅으로 등록. * context window limit, edit error 등 실행 중 에러를 감지하여 * 사용자에게 경고하고 상태를 보존합니다. * * 또한 UserPromptSubmit에서 현재 대화 길이를 추적하여 * context 한계에 접근 시 preemptive 경고를 제공합니다. */ export declare const TOKEN_LIMIT_REGEX: RegExp; export declare const RATE_LIMIT_REGEX: RegExp; /** * Best-effort reset 시각 파서 (ADR-008 §2). * * 5 패턴 시도, 모두 실패 시 null. 실제 메시지 포맷은 Claude/Codex CLI 의 * 공식 contract 가 아니므로 hotfix 가능한 best-effort. * * @param msg stderr/error message text * @param now epoch ms (테스트 결정성 위해 주입 가능) * @returns ISO timestamp 또는 null */ export declare function parseRateLimitResetAt(msg: string, now?: number): string | null; /** 경고 표시 여부 판정 (순수 함수) */ export declare function shouldWarn(contextPercent: { promptCount: number; totalChars: number; lastWarningAt: number; }, thresholds?: { promptThreshold?: number; charsThreshold?: number; cooldownMs?: number; }): boolean; /** auto-compact 트리거 여부 판정 (순수 함수) */ export declare function shouldAutoCompact(state: { totalChars: number; lastAutoCompactAt: number; }, thresholds?: { charsThreshold?: number; cooldownMs?: number; }): boolean; /** auto-compact 지시 메시지 생성 (순수 함수) */ export declare function buildAutoCompactMessage(totalChars: number): string; /** 경고 메시지 생성 (순수 함수) */ export declare function buildContextWarningMessage(promptCount: number, totalChars: number): string; export declare function main(): Promise; /** * 세션 종료 시 forgen *활동*을 요약 (관찰 — 인과 효과/절약 미주장). * solution-cache 에서 이번 세션 주입된 compound 수·상위 솔루션·주입 대화 비율을 보여준다. * honest-null (positioning #74): "forgen 없었으면 ~N분 절약" 카운터팩추얼은 은퇴. */ export declare function buildSessionSummary(sessionId: string, promptCount: number): string; export declare function effectiveCooldownMs(parsed: { extractedSolutions?: number; promotedRules?: number; userPatternFound?: boolean; promptCount?: number; }, currentPromptCount?: number): number; /** * forge-loop 활성 시 미완료 스토리가 있으면 Stop을 차단하고 지속 메시지 주입. * OMC의 persistent-mode.cjs 패턴 참고. * * @param sessionId 호출한 Stop hook 의 세션 ID. 미지정 시(레거시 호출) 세션 * 바인딩을 건너뛰고 기존처럼 전역으로 평가한다. */ export declare function checkForgeLoopActive(sessionId?: string): string | null;