YeonGyu-Kim 33d39597ae docs(agents): regenerate AGENTS.md hierarchy with updated metrics and model configs
- 1208→1243 TS files (+35), 143k→155k LOC (+12k)
- Update all agent models: Sisyphus, Hephaestus, Oracle, Librarian, Atlas, Metis, Momus
- Add 6 new hook directories (39→45 dirs): beast-mode-system, hashline-edit-diff-enhancer, anthropic-image-context, task-reminder, compaction-todo-preserver, runtime-fallback
- Update category models: visual-engineering/artistry gemini-3-pro→gemini-3.1-pro
- Add 2 config schema files: fallback-models.ts, runtime-fallback.ts
- Timestamp: 2026-03-02 | Commit: 1c2caa09

🤖 Generated with assistance of [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode)
2026-03-02 23:40:38 +09:00

2.1 KiB
Raw Blame History

src/hooks/anthropic-context-window-limit-recovery/ — Multi-Strategy Context Recovery

Generated: 2026-03-02

OVERVIEW

31 files (~2232 LOC). Most complex hook. Recovers from context window limit errors via multiple strategies applied in sequence.

RECOVERY STRATEGIES (in priority order)

Strategy File Mechanism
Empty content recovery empty-content-recovery.ts Handle empty/null content blocks in messages
Deduplication deduplication-recovery.ts Remove duplicate tool results from context
Target-token truncation target-token-truncation.ts Truncate largest tool outputs to fit target ratio
Aggressive truncation aggressive-truncation-strategy.ts Last-resort truncation with minimal output preservation
Summarize retry summarize-retry-strategy.ts Compaction + summarization then retry

KEY FILES

File Purpose
recovery-hook.ts Main hook entry — session.error handler, strategy orchestration
executor.ts Execute recovery strategies in sequence
parser.ts Parse Anthropic token limit error messages
state.ts AutoCompactState — per-session retry/truncation tracking
types.ts ParsedTokenLimitError, RetryState, TruncateState, config constants
storage.ts Persist tool results for later truncation
tool-result-storage.ts Store/retrieve individual tool call results
message-builder.ts Build retry messages after recovery

RETRY CONFIG

  • Max attempts: 2
  • Initial delay: 2s, backoff ×2, max 30s
  • Max truncation attempts: 20
  • Target token ratio: 0.5 (truncate to 50% of limit)
  • Chars per token estimate: 4

PRUNING SYSTEM

pruning-*.ts files handle intelligent output pruning:

  • pruning-deduplication.ts — Remove duplicate content across tool results
  • pruning-tool-output-truncation.ts — Truncate oversized tool outputs
  • pruning-types.ts — Pruning-specific type definitions

SDK VARIANTS

empty-content-recovery-sdk.ts and tool-result-storage-sdk.ts provide SDK-based implementations for OpenCode client interactions.