import type { V1HarnessContext } from './harness.js'; import type { RuntimeHost } from './types.js'; /** runAutoCompound 결과 — sweep(무인 cron)이 실제 spawn 만 기록하도록 상태 반환. */ export type AutoCompoundStatus = 'spawned' | 'skipped-inflight' | 'skipped-dedup' | 'failed'; /** * 세션 종료 후 자동 compound 추출을 백그라운드(detached)로 시작. * * 과거에는 execFileSync 로 동기 실행하여 세션 종료가 최대 ~210초(haiku LLM 3회 * 순차: 솔루션 추출 90s + behavior 60s + 세션 학습 60s) 동안 블록되었다. 같은 * 작업을 context-guard Stop 훅(maybeSpawnAutoCompound)과 session-recovery 가 이미 * detached 로 spawn 하므로, 여기서도 detached + unref 로 전환해 세션 종료를 막지 * 않는다. 결과(추출 솔루션/패턴)는 다음 세션 시작 시 session-recovery 가 surface 한다. * * dedup: last-auto-compound.json 을 Stop 훅과 공유 — 같은 세션의 최근 run 이 있으면 * skip 하여 detached spawn 의 double-run 을 방지한다. */ /** * per-session in-flight 슬롯 확보 (spawn *전* 표식). 이미 in-flight(TTL 내)면 false 반환 → skip. * runAutoCompound 와 context-guard.maybeSpawnAutoCompound 가 **공유**해 이중 spawn(중복 Haiku * 과금)을 막는다 (리뷰 SEV-2 #3: 완료-게이트 단일슬롯만으로는 부족). */ export declare function claimAutoCompoundInflight(sessionId: string, now?: number): boolean; /** in-flight 슬롯 해제 (spawn 실패 시 재시도 가능하도록). */ export declare function releaseAutoCompoundInflight(sessionId: string): void; export declare function runAutoCompound(cwd: string, transcriptPath: string, sessionId: string, promptCount?: number): AutoCompoundStatus; /** * Plan B-1: 세션 transcript 사후 스캔으로 rate-limit 감지. * * stdio='inherit' 라 Claude 출력을 직접 캡처할 수 없으므로, * 세션 종료 후 transcript JSONL 의 마지막 N 라인을 읽어 * RATE_LIMIT_REGEX 매칭 여부를 확인한다. * * - transcript 없음 / 빈 파일 / parse 실패 → matched: false (fail-open) * - 이미 pending-resume.json 존재 시 hook 이 먼저 잡은 것이므로 덮어쓰지 않음 * * @param transcriptPath JSONL 파일 경로 * @param tailLines 검사할 마지막 라인 수 (기본 5) */ export declare function scanTranscriptForRateLimit(transcriptPath: string, tailLines?: number): Promise<{ matched: boolean; resetAt: string | null; }>; /** Claude Code를 하네스 환경으로 실행. exit code를 반환. */ export declare function spawnClaude(args: string[], context: V1HarnessContext, runtime?: RuntimeHost): Promise; declare const MAX_RESUMES = 3; /** * Exponential backoff for rate-limit when resetAt 파싱 실패. * 1m → 5m → 15m → 30m → 1h → 2h cap. 합 ≤ 6h. */ export declare function rateLimitBackoffMs(attempt: number): number; /** * 토큰 한도 / API rate-limit 도달 시 자동 재시작을 지원하는 claude 실행 래퍼. * context-guard가 pending-resume.json 마커를 생성하면 reason 별 정책으로 처리. * * - reason='token-limit': 30s 쿨다운, MAX_RESUMES_TOKEN=3 * - reason='rate-limit': resetAt 정밀 sleep (+60s 버퍼) 또는 exponential backoff, * MAX_RESUMES_RATE=10, hard cap 6h */ export declare function spawnClaudeWithResume(args: string[], context: V1HarnessContext, contextFactory: () => Promise, runtime?: RuntimeHost): Promise; export { MAX_RESUMES };