Skip to content

feat: add /autocompact with per-model modelSettings trigger - #550

Open
yujiachen-y wants to merge 2 commits into
mainfrom
feat/autocompact-command
Open

yujiachen-y wants to merge 2 commits into
mainfrom
feat/autocompact-command

Conversation

@yujiachen-y

@yujiachen-y yujiachen-y commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Change

Adds a Claude Code-style /autocompact command and per-model storage for the automatic compaction trigger, building on contextManagement.compactionTriggerAt (#493). Refs #488.

modelSettings:
  "minimax/MiniMax-M3":
    autoCompactWindow: 400000   # an integer token count above 1, or "auto"
contextManagement:
  compactionTriggerAt: 0.8      # existing global default, unchanged
  • Same shape as Claude Code's modelSettings.<model>.autoCompactWindow. The key is the Session's selected provider/model.
  • Precedence: the current model's autoCompactWindow, then the global compactionTriggerAt, then the built-in trigger. The selected value is still min()ed with the built-in trigger, so it can only start compaction earlier. auto returns 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.
  • /context now shows the Auto-compact line (trigger and source); it was never rendered because the threshold was hard-coded to null. The trigger is read only when /context is opened, not on status refreshes.
  • The automatic compactor keys the setting by the Turn's model selection, not the Pi provider alias, because 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.
  • Saving reserializes config.yaml with 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

  • Checks run and results: pnpm verify (full profile) on 51b963b, darwin: 15 gates passed; test:windows and test:release-package not applicable locally. The capability Vitest group also passed separately (223 files).
  • New/changed tests cover the parser and selection (auto-compact-window.test.ts), the per-model writer, compactor selection vs provider alias, production compactor wiring with a real temporary config.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, /autocompact in the TUI and ACP, and the /context line.
  • Performance: basic. No history construction, serialization, or token-estimation changes; the compactor already read config per call.
  • NOT RUN: a live long session against a real model; a real ACP client; Linux/Windows locally (CI covers them).

Publication and contribution checks

  • I have permission to contribute these changes under the existing licenses applicable to the changed files/packages; imported material and its provenance are identified and existing notices are preserved.
  • No credentials, account data, real user content, internal source history or private review material is included.
  • Added/removed source files were reviewed before regenerating release/public-source.json; new tests are declared in test/vitest-suites.json where applicable.
  • Shared English/Chinese documentation and capability/verification records are updated where applicable. Mock/offline results are not described as live-service acceptance.

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).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

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
@yujiachen-y yujiachen-y added enhancement New feature or request tui Interactive terminal UI (TUI) cli Standalone mcode: TUI, headless, ACP and source builds/tooling labels Oct 26, 2026
Comment thread packages/config/src/auto-compact-window.ts Fixed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli Standalone mcode: TUI, headless, ACP and source builds/tooling enhancement New feature or request tui Interactive terminal UI (TUI)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants