Feature/add skill recovery#985
Conversation
- Session: add `InvokedSkillRecord` and `invoked_skills` HashMap (dedup
by skill_name key with overwrite-on-repeat semantics).
- Turn loop: record `load_skill` invocations with full raw body content.
- Compaction: inject all invoked skills as a single synthetic user
message at the front of the post-compact message list (matching Claude
Code's layout: leading sentence, `### Skill: {name}` headers, `---`
separators, most-recent-first ordering, no artificial token budget).
- Cycle advance: clear `invoked_skills` alongside `compaction_summary_prompt`.
- All 4 `compact_messages_safe` call sites pass `invoked_skills`.
Tests: 17 new tests covering recording, dedup, injection format,
single-message bundling, ordering, and cycle-clear behavior.
Co-Authored-By: Opus 4.7 <noreply@anthropic.com>
Verifies on-demand loading (only invoked skills appear, not the full catalogue), deduplication (repeat calls produce one entry with latest content), and markdown structure alignment with Claude Code. Includes 5 minimal skill fixtures under tests/test_skills/. Co-Authored-By: Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request implements a system to preserve invoked skill content during message compaction by re-injecting it as a synthetic user message. It introduces the InvokedSkillRecord struct and a HashMap in the Session to track and deduplicate skill invocations, ensuring the latest content is maintained. The engine's turn loop now records successful load_skill tool calls, and the compaction logic integrates these records into the post-compaction message stream. Comprehensive unit and integration tests have been added to verify the deduplication, ordering, and recovery of skill content. I have no feedback to provide.
|
Thanks for working on this. This PR is too large or scope-mixed for review in this repo's current maintainer model. Please split it into one PR per accepted issue, each under 500 changed lines and with a concrete test plan. Changes to core compaction/session behavior need maintainer approval before implementation. This PR also needs the admission details from the contributor guide before review: a linked accepted issue, AI-use disclosure, a human-owner statement that you have read and can explain every changed file, and a clean test plan with commands that pass. I am closing this PR, but a smaller PR against an accepted issue is welcome. |
Summary
Add skill invocation tracking with deduplication and automatic post-compaction re-injection — the model no longer loses loaded skill content when context is compacted.
What changed
Session tracking (
session.rs): newInvokedSkillRecordstruct andinvoked_skills: HashMap<String, InvokedSkillRecord>field onSession. Repeatedload_skillcalls for the same skill name overwrite the previous entry — theHashMapkey is the dedup mechanism.Turn loop recording (
turn_loop.rs): when aload_skilltool call succeeds, the full raw body is recorded viaSession::record_skill_invocation()so it survives compaction.Compaction injection (
compaction.rs):inject_invoked_skills()builds a single synthetic user message from every recorded skill, placed at the front of the post-compact message list. The format follows Claude Code's layout: a leading sentence (The following skills were invoked…),### Skill: {name}markdown headers,---separators, most-recent-first ordering, and no artificial token budget.Cycle advance cleanup (
engine.rs):invoked_skillsis cleared alongsidecompaction_summary_prompton cycle boundaries.All 4
compact_messages_safecall sites (engine.rs,turn_loop.rs,capacity_flow.rs) passinvoked_skillsthrough.Files changed
crates/tui/src/core/session.rsInvokedSkillRecord, +invoked_skillsfield, +record_skill_invocation()methodcrates/tui/src/core/engine/turn_loop.rsload_skillsuccesscrates/tui/src/compaction.rsinject_invoked_skills(), new param oncompact_messages/compact_messages_safecrates/tui/src/core/engine.rsinvoked_skillsto compaction, clear on cycle advancecrates/tui/src/core/engine/capacity_flow.rsinvoked_skillsto compactioncrates/tui/src/core/engine/tests.rscrates/tui/tests/skill_compaction_recovery.rscrates/tui/tests/test_skills/Testing
cargo test -p deepseek-tui --bin deepseek-tui(2170 passed; 12 pre-existingrepl::runtimefailures unrelated to this PR)cargo test -p deepseek-tui --test skill_compaction_recovery(7/7 passed)cargo buildproduces zero new warningsChecklist