| feat(context): land Phase 1.5–6 context module + dual-parity probes
Implements all six phases of the context module rewrite per
docs/politdeck-context-refactor-development-guide.md:
- Phase 1.5: CanonicalModelErrorCode (PTL/RTL/MOR), case-insensitive
PTL classification on both Anthropic and OpenAI protocols, anthropic
signature_delta → CanonicalThinkingBlock.signature, control_boundary
schema with compactMetadata + microcompactMetadata, transcript
recordControlBoundary + replay slicing, ProjectSessionStorage
toolResultsDir.
- Phase 2: ContextRuntime full protocol, 5-section PromptAssembler
(default / user / system / custom / append), MessageProjector with
tool-call/result pairing repair + sliding window, DefaultContextRuntime.
- Phase 3: ToolResultBudget replaces oversized tool_results with the
new CanonicalToolResultReferenceBlock and persists originals to disk
(write-exclusive flag).
- Phase 4: InputProcessor three-layer slash-command dispatch driven by
ExtensionResolver, AttachmentResolver for text / base64 image / pdf
size estimation (intentional difference vs poppler/sharp).
- Phase 5: TokenBudgetManager (char/4 + multimedia constant),
CompactionEngine with legacy buildPostCompactMessages ordering
(B→S→K→A→H), AutoCompactionPolicy thresholds, MicroCompactionEngine
time-based path, ContextOverflowRecovery (50% / 25% / give_up).
- Phase 6: PluginRuntimeExtensionResolver bridging
PolitDeckLoadedPlugin commands/skills, MemoryAttachmentBuilder
feeding MemoryResolver output into the prompt.
Adds a dual-parity test suite (tests/context/parity +
tests/fixtures/context/dual-parity) covering rough_token estimation,
findLastCompactBoundaryIndex, buildPostCompactMessages ordering,
truncateHead keepRatio, and PTL classification — each scenario cites
its legacy source path so updates can be retraced.
New module 245/245 unit tests pass; OpenRouter Kimi K2.6 e2e for both
agent tool-use and DefaultContextRuntime prompt flow are green.
Also bundles the previously uncommitted TUI e2e tracing helpers
(scripts/tui-e2e-record.tsx Proxy wrapWithTrace, ActivityLine spinner)
that supported the context refactor debugging.
Co-authored-by: Cursor <cursoragent@cursor.com>
| 25 天前 |