feat: hard-exclude important user messages from compression#79
Open
ranxianglei wants to merge 2 commits into
Open
feat: hard-exclude important user messages from compression#79ranxianglei wants to merge 2 commits into
ranxianglei wants to merge 2 commits into
Conversation
Add regex-based importance detector (lib/messages/importance-detector.ts) that classifies user messages as important based on 5 categories of markers in both Chinese and English: importance, imperative, correction, reminder, non-negotiable. The detector uses a two-stage approach: 1. Gate: exclude data input (logs, code, diffs, tool output, structured data) 2. Detect: check remaining natural-language text for importance markers When a user message is classified as important, it is hard-excluded from the compression range — the message survives intact in visible context, never enters a summary block, and is never subject to GC truncation. New config option: compress.protectImportantUserMessages (default: true). This prevents the gradual degradation problem where important instructions get compressed into summaries, then progressively lost across successive compression cycles. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
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
lib/messages/importance-detector.ts) that classifies user messages as important using 5 categories of markers in both Chinese and Englishcompress.protectImportantUserMessages(default:true)Problem (issue #16)
Important user messages (instructions, corrections, constraints) could be compressed into summaries, then progressively lost across successive compression cycles. The "似是而非" (seems right but isn't) problem: content degrades with each compression round.
Solution
Two-stage classifier:
isLikelyDataInput()excludes logs, code blocks, diffs, tool output, structured dataCode blocks are stripped before detection so keywords inside code don't false-positive.
Architecture
Follows the exact same hard-exclusion pattern as protected tools (PR #75):
filterImportantUserMessages()inprotected-content.ts— same structure asfilterProtectedToolMessages()range.tsafterfilterProtectedToolMessages()message-utils.tsalongside protected tool checkcompress.protectImportantUserMessages: true(default on)Test plan
npm run typecheck— 0 errorstests/importance-detector.test.tsnpm run buildsucceedsCloses #16