Repository navigation
feat: add /autocompact with per-model modelSettings trigger - #550
Open
yujiachen-y wants to merge 2 commits into
Open
yujiachen-y wants to merge 2 commits into
yujiachen-y wants to merge 2 commits into
Conversation
Align with Claude Code's /autocompact and modelSettings.<model>.autoCompactWindow, building on contextManagement.compactionTriggerAt (#493). - config: new top-level modelSettings["<provider>/<model>"].autoCompactWindow, an integer token count above 1 or "auto". Precedence: per-model value, then contextManagement.compactionTriggerAt, then the built-in trigger; the result is still min()ed with the built-in trigger. "auto" returns the model to the built-in trigger and ignores the global value. Invalid entries are warned once and ignored. - runtime: the automatic compactor reads the setting for the Turn's model selection rather than the Pi provider alias, which differs for custom_provider OAuth routes. A session-scoped process-local read/write computes the effective trigger from the same agent/model preparation and budget as the compactor; writes are lock-protected and apply from the next request. - TUI/ACP: /autocompact [auto|<tokens>] with Claude Code's value grammar (500k, 1.5M, bare 100-1000 as thousands) but no 100K floor; /context shows the auto-compact trigger and its source. - docs: update the automatic compaction trigger section. Refs #488
CodeQL flagged fraction.replace(/0+$/u, '') in parseAutoCompactWindowInput as a polynomial regular expression on user input: a long run of zeros followed by a non-zero digit backtracks quadratically. Strip trailing zeros with a loop and cover a 100,000-zero input.
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.
Change
Adds a Claude Code-style
/autocompactcommand and per-model storage for the automatic compaction trigger, building oncontextManagement.compactionTriggerAt(#493). Refs #488.modelSettings.<model>.autoCompactWindow. The key is the Session's selectedprovider/model.autoCompactWindow, then the globalcompactionTriggerAt, then the built-in trigger. The selected value is stillmin()ed with the built-in trigger, so it can only start compaction earlier.autoreturns the model to the built-in trigger and ignores the global value. No lower bound (same decision as feat: add contextManagement.compactionTriggerAt to lower the auto-compaction trigger #493). Invalid entries are logged once and ignored./autocompact [auto|<tokens>]uses Claude Code's value grammar (300000,500k,1.5M, a bare 100-1000 means thousands) without its 100K floor. Without an argument it shows the current trigger, its share of the window, and its source. Invalid input or no active Session changes nothing. ACP clients get the same command./contextnow shows the Auto-compact line (trigger and source); it was never rendered because the threshold was hard-coded tonull. The trigger is read only when/contextis opened, not on status refreshes.custom_provider:OAuth routes use the bare provider key as the Pi provider. The read path uses the same agent/model preparation and budget as the compactor, so the shown value is the line compaction actually uses; a save applies from the next model request without a restart.config.yamlwith the existing locked writer, so comment formatting is not retained (same as/statusline); documented.Not included: a launch flag or environment variable override, and any Desktop UI.
Validation
pnpm verify(full profile) on51b963b, darwin: 15 gates passed;test:windowsandtest:release-packagenot applicable locally. ThecapabilityVitest group also passed separately (223 files).auto-compact-window.test.ts), the per-model writer, compactor selection vs provider alias, production compactor wiring with a real temporaryconfig.yaml(a save changes the very next probe; the read matches the probe boundary), the session-scoped read/write, the host forwarding the model selection,/autocompactin the TUI and ACP, and the/contextline.Publication and contribution checks
release/public-source.json; new tests are declared intest/vitest-suites.jsonwhere applicable.Maintainer handoff
Publication scope or license changes (if any): 7 new source/test files, no license changes.
Shared-source port: complete (internal counterpart exists; the internal version keeps config comments because it has a comment-preserving writer).
Need help on this PR? Tag
@codesmith-botwith what you need.