refactor(hooks)!: rename anthropic-context-window-limit-recovery to generic provider-agnostic context-window-limit-recovery (P2.2) - #68
Merged
Conversation
…eneric provider-agnostic context-window-limit-recovery (P2.2) BREAKING CHANGE: HookName `anthropic-context-window-limit-recovery` renamed to `context-window-limit-recovery`. Deprecated alias shim via z.union transform keeps backwards compat until v2.7 (disabled_hooks auto-migrated via src/shared/migration/hook-names.ts). Provider-agnostic parser (parseTokenLimitError + deprecated parseAnthropicTokenLimitError alias, GenericErrorData), storage unified (tool-result-store 199 LOC), empty-content 58+48 LOC via session-recovery delegation, shared context-limits (70% monitor, 78% preemptive). Docs + schema regenerated, tests renamed, mock-heavy synced. 51 files, +738/-1330. Co-Authored-By: internal-model
…rable via experimental Adds experimental.context_warning_threshold (default 0.70) and experimental.preemptive_compaction_threshold (default 0.78), Zod-validated 0.1-0.95. Resolvers in shared/context-limits.ts fall back to existing consts; monitor + preemptive trigger consume them (no bare literals left). Misordering logs a warning instead of crashing. Schema regenerated, docs updated. Co-Authored-By: internal-model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Renames
anthropic-context-window-limit-recovery(20 files, 1788 LOC) to provider-agnosticcontext-window-limit-recovery(17 files, 1267 LOC, -29%) and makes the implementation lighter and generic. Follow-up to P2.1 (#67). No behavior removal — reactive recovery is kept, provider coupling removed.Plan:
.matrixx/plans/p2.2-generic-recovery-refactor.md(5 tasks / 3 waves, all complete).BREAKING CHANGE
Hook name
anthropic-context-window-limit-recoveryrenamed tocontext-window-limit-recovery.Migration is automatic:
HookNameSchemaaccepts the legacy name viaz.uniontransform and normalizes it to the new name (61 entries preserved).src/shared/migration/hook-names.tsmaps legacydisabled_hooksentries to the new name.createAnthropicContextWindowLimitRecoveryHook,parseAnthropicTokenLimitError,AnthropicErrorData. Removal in v2.7.Users with
"anthropic-context-window-limit-recovery"indisabled_hooksneed no action.What changed
src/hooks/anthropic-context-window-limit-recovery/->src/hooks/context-window-limit-recovery/;tests/hooks/...renamed likewise (4 files, 1 SDK test deleted with its source).src/config/schema/hooks.ts(76 LOC) union shim;src/shared/migration/hook-names.tsNEW (34 LOC).parser.ts209 -> 161 LOC +parser-patterns.tsNEW (58 LOC).parseTokenLimitErrorprimary,AnthropicErrorData->GenericErrorDataalias.providerIDlogging-only, no gating. Thinking-block errors still excluded (routed tosession-recovery).tool-result-storage.ts+-sdk.ts(239) -> unifiedtool-result-store.ts(199) viaisSqliteBackend()+truncateResultsLoop; deletedmessage-storage-directory.ts/storage-paths.ts;target-token-truncation.ts196 -> 37.empty-content-recovery.ts126 -> 89 viasession-recovery/storagedelegation (SDK file deleted);message-builder.ts169 -> 86; capsmaxTruncateAttempts: 5,maxAttempts: 2(worst-case API calls 22 -> ~7).src/shared/context-limits.tsNEW (50 LOC) single-sourcesCONTEXT_WARNING_THRESHOLD=0.70/PREEMPTIVE_COMPACTION_THRESHOLD=0.78+ limits; consumed bycontext-window-monitor.tsandpreemptive-compaction*.ts. Boundary documented: monitor 70% warn (read-only) -> preemptive 78% proactive (60s summarize/cooldown) -> recovery reactive (error-parse only).create-session-hooks.ts,hooks/index.ts,plugin/event.tsrenamed with deprecated re-exports.context-management.md§3.5,configurations.md,cost-performance-proposals.md,features.md,headroom.ts,hooks/AGENTS.mdupdated;assets/dist matrixx.schema.jsonregenerated viabun run build:schema.script/mock-heavy-list.txtsynced (single source, no duplication).Verification
bun run typecheck->tsc --noEmit, exit 0bun run lint->Checked 959 files, No fixes, exit 0bun run build->Bundled 1138 + 155 modules, schema regenerated, exit 0bun test tests/hooks/context-window-limit-recovery/-> 21 pass, 0 failbun test tests/hooks/preemptive-compaction.test.ts tests/plugin/tool-execute-before.test.ts-> 15 pass, 0 failrg anthropic-context-window-limit-recovery src/-> onlyhooks.ts:72shim +migration/hook-names.ts:4bun -e: generic parse150000 > 128000correct,context_length_exceededhandled, thinking-block returnsnull, legacy alias identical, legacydisabled_hooksnormalizes, thresholds0.7 / 0.78Known gaps
bun testsuite not run (affected + adjacent only); no live long-sessionsession.summarizee2e, parser-level trigger only.Checklist
dev(nevermaster), merge commit onlyrefactor/p2.2-generic-recovery, Bun 1.4.0as any/@ts-ignore, nosrc/index.tsexports, notodo-continuation-enforcertouchgit mvback,build:schema, restore tests + mock list (see plan §Rollback)