Files
oh-my-opencode/src/hooks/anthropic-context-window-limit-recovery/AGENTS.md
T
YeonGyu-Kim 1e7a7600a2 docs(agents-md): regenerate hierarchical AGENTS.md knowledge base for v4.1.1
Refresh all AGENTS.md files to reflect codebase state at 5ffbe0e24 (was cd31d2a1a, 197 commits behind).

Key drift corrections across 45 modified + 1 new file:

Root AGENTS.md:
- TS file counts: 1967 -> 2034 in src/ (1337 source + 697 test)
- LOC: 278k -> 292k
- Barrel index.ts: 120 -> 122
- Hook tier composition: 52/59 -> 54/61 (base/with team-mode)
- Tool Guard hooks: 14 -> 16 (add fsync-skip-warning, bash-file-read-guard)
- Add boulder feature, agent-ordering schema, .agents/ directory, v4.1.1 release tag
- Add generated/ directory entry

src/AGENTS.md:
- Subsystem inventory: agents 96->102, hooks 570->581, tools 306->314,
  features 389->400, shared 258->278, cli 150->158, plugin 55->56
- LOC totals refreshed for every subsystem
- Schema files: 32 -> 30

src/hooks/AGENTS.md:
- Tier 2 (Tool Guard): 14 -> 16 hooks, add fsyncSkipWarning row
- Total: 52 base / 59 team-mode -> 54 base / 61 team-mode
- zauc-mocks count: 7 -> 5

src/features/AGENTS.md:
- background-agent: 47 -> 57 files, mention archive fallback
- opencode-skill-loader: 33 -> 30
- tmux-subagent: 34 -> 32

src/plugin/AGENTS.md:
- Tool Guard composer count: 14 -> 16
- Aggregator total: 43 -> 45

src/cli/AGENTS.md:
- Add new boulder subcommand (BoulderState inspector)
- Command count: 6 -> 7

NEW: src/features/boulder-state/AGENTS.md
- Document the new Boulder work tracking feature
- Schema v2 with BoulderState/BoulderWorkState/TaskSessionState
- Lifecycle, storage, integration points with atlas/ralph-loop hooks

All other AGENTS.md files: Generated date 2026-05-08 -> 2026-05-14.
2026-05-14 12:57:46 +09:00

2.1 KiB
Raw Blame History

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

Generated: 2026-05-14

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.