Add OpenCode skill waste detectors (closes #54)#160
Merged
willwashburn merged 4 commits intomainfrom Apr 28, 2026
Merged
Conversation
Two new burn waste --patterns detectors gated to source === 'opencode':
- opencode-skill-recall: flags repeated skill({name}) calls whose content
is not deduplicated by the agent, reporting callCount, turn range, and cost.
- opencode-skill-pruning: tracks skill tool results that ride in the cache
indefinitely (prune-protected by OpenCode's compaction), reporting
ridingTurns, lastCachedTurnIndex, and cost.
Also populates ToolCall.skillName in the OpenCode reader so downstream
detectors can group skill invocations without re-parsing args.
Estimates the fixed prefix tax (system prompt + skill catalog) on the first turn of an OpenCode session by subtracting the first user message size from cacheCreate. Reports estimatedSystemPromptTokens, ridingTurns, and total cost. Requires userTurnsBySession in DetectPatternsOptions. New pattern kind: opencode-system-prompt. Renders in burn waste --patterns and burn diagnose alongside the other detectors.
- `burn diagnose` now passes `userTurnsBySession` into `detectPatterns`, so the OpenCode system-prompt-tax detector actually runs (the diagnose call was previously silently emitting `(none)` because the detector bails when user-turn data is absent). - Drop the dead `compactionTurnIndexes` set built but never used in `detectSkillPruningProtectionForSession`; skill tool results are prune-protected, so compaction boundaries don't bound riding-turn counts. The function no longer takes a `compactions` parameter.
`detectSystemPromptTaxForSession` was iterating over every turn including the first when computing `ridingTurns`. The header comment says "subsequent" — and the sister `detectSkillPruningProtectionForSession` correctly skips its anchor turn. On a resumed OpenCode session the first turn can carry `cacheRead > 0`, which would otherwise inflate both the riding count and totalCost. Added a regression test for the resumed-session shape.
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
burn waste --patternsdetectors gated tosource === 'opencode':opencode-skill-recall— flags repeatedskill({name})calls whose content is not deduplicated by OpenCode, reporting call count, turn range, and cost.opencode-skill-pruning— tracks skill tool results that ride in the cache indefinitely (prune-protected by OpenCode's compaction), reporting riding turns, last cached turn, and cost.ToolCall.skillNamepopulated by the OpenCode reader so downstream detectors can group skill invocations without re-parsing args.burn diagnoserenders the new pattern types;burn waste --patterns --jsonincludes them in output.SessionPatternSummarygainsskillRecallDupCountandskillPruningProtectionCount.Files changed
@relayburn/readerToolCall.skillNamefield; OpenCode reader extracts skill name from tool input@relayburn/analyzeSkillRecallDup+SkillPruningProtectioninterfaces + detectors;detectPatterns,PatternsResult,SessionPatternSummaryextended@relayburn/cliPATTERN_KINDSgainsopencode-skill-recallandopencode-skill-pruning; rendering tables;burn diagnoseupdatedTests
634 tests pass (8 new test cases for the skill detectors).