Configurable Auto-Compact Threshold Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.
Goal: Add persisted auto-compaction threshold presets to the interactive TUI settings.
Architecture: Keep automatic triggering in packages/agent/modes. Thread an optional integer percentage from persisted agent.Config into modes.InteractiveConfig, normalize missing or invalid values to 85%, and let zero disable only percentage-based triggers. Reuse the settings dialog's existing fixed-option picker and settings-store persistence path.
Step 1: Write failing normalization and decision tests
Add table-driven tests proving nil and invalid values resolve to 85, supported presets survive unchanged, zero disables percentage checks, and 70/80/85/90 trigger exactly at their boundaries.
funcTestNormalizeAutoCompactThreshold(t*testing.T){tests:=[]struct{namestringvalue*intwantint}{{name:"missing",value:nil,want:85},{name:"off",value:intPtr(0),want:0},{name:"seventy",value:intPtr(70),want:70},{name:"invalid",value:intPtr(42),want:85},}// Assert normalizeAutoCompactThreshold(test.value) == test.want.}funcTestShouldAutoCompactUsesConfiguredThreshold(t*testing.T){ifshouldAutoCompact(84,100,85){t.Fatal("84% must remain below an 85% threshold")}if!shouldAutoCompact(85,100,85){t.Fatal("85% must trigger an 85% threshold")}ifshouldAutoCompact(100,100,0){t.Fatal("off must disable percentage-triggered compaction")}}
Step 2: Run tests and verify RED
Run:
go test ./packages/agent/modes -run 'TestNormalizeAutoCompactThreshold|TestShouldAutoCompactUsesConfiguredThreshold' -count=1
Expected: compilation failure because the normalization and decision helpers do not exist.
Step 3: Add optional configuration and minimal helpers
Add AutoCompactThreshold *int with JSON name auto_compact_threshold to both configuration structs. Implement normalization for exactly 0, 70, 80, 85, and 90, defaulting all other values to 85. Replace the hard-coded fraction check with the normalized percentage helper and pass the config field through cli.go.
Step 4: Run focused tests and verify GREEN
Run:
go test ./packages/agent/modes -run 'TestNormalizeAutoCompactThreshold|TestShouldAutoCompactUsesConfiguredThreshold' -count=1
Step 1: Write failing persistence and settings-item tests
Add a settings-store test that writes 70 into an isolated $ZOT_HOME and verifies auto_compact_threshold plus an unrelated config field. Add a modes test that opens settings with missing configuration and verifies the option values are 0, 70, 80, 85, 90 with 85 selected.
go test ./packages/agent ./packages/agent/modes -run 'AutoCompactThreshold|SettingsDialog.*AutoCompact' -count=1
Expected: compilation or assertion failure because persistence and the picker row do not exist.
Step 3: Implement persistence and live setting application
Add the settings-store method, fixed picker options, choice resolution, action routing, integer parsing, live InteractiveConfig update, and status message. Persist only values exposed by the picker; normalize the live value defensively before use.
Step 4: Run focused tests and verify GREEN
Run:
go test ./packages/agent ./packages/agent/modes -run 'AutoCompactThreshold|SettingsDialog.*AutoCompact' -count=1
Document off, 70%, 80%, 85% default, and 90% in the /settings section. Update /compact to state that threshold-based auto-compaction is configurable and that payload-too-large recovery remains active when the percentage trigger is off.
Push to the appropriate writable GitHub remote with upstream tracking.
Step 5: Open a ready pull request
Target the upstream default branch. Include the behavior, compatibility, user impact, and exact validation commands in the PR body.
source
1# Configurable Auto-Compact Threshold Implementation Plan23> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.45**Goal:** Add persisted auto-compaction threshold presets to the interactive TUI settings.67**Architecture:** Keep automatic triggering in `packages/agent/modes`. Thread an optional integer percentage from persisted `agent.Config` into `modes.InteractiveConfig`, normalize missing or invalid values to 85%, and let zero disable only percentage-based triggers. Reuse the settings dialog's existing fixed-option picker and settings-store persistence path.89**Tech Stack:** Go, standard library, Zot's existing TUI settings dialog, JSON configuration.1011## Global Constraints1213- Supported values are `0` (off), `70`, `80`, `85`, and `90`.14- Missing or invalid persisted values resolve to `85`.15- Disabling the threshold does not disable manual compaction or HTTP 413 recovery.16- Do not add dependencies or change non-interactive compaction behavior.17- Preserve unrelated working-tree changes and stage only this feature.1819---2021### Task 1: Configuration and threshold decision2223**Files:**24- Modify: `packages/agent/config.go`25- Modify: `packages/agent/modes/interactive.go`26- Create: `packages/agent/modes/auto_compact_test.go`27- Modify: `packages/agent/cli.go`2829**Interfaces:**30- Produces: `Config.AutoCompactThreshold *int`31- Produces: `InteractiveConfig.AutoCompactThreshold *int`32- Produces: `normalizeAutoCompactThreshold(*int) int`33- Produces: `shouldAutoCompact(inputTokens, contextWindow, thresholdPercent int) bool`3435- [ ]**Step 1: Write failing normalization and decision tests**3637Add table-driven tests proving nil and invalid values resolve to 85, supported presets survive unchanged, zero disables percentage checks, and 70/80/85/90 trigger exactly at their boundaries.3839```go40funcTestNormalizeAutoCompactThreshold(t*testing.T){41tests:=[]struct{42namestring43value*int44wantint45}{46{name:"missing",value:nil,want:85},47{name:"off",value:intPtr(0),want:0},48{name:"seventy",value:intPtr(70),want:70},49{name:"invalid",value:intPtr(42),want:85},50}51// Assert normalizeAutoCompactThreshold(test.value) == test.want.52}5354funcTestShouldAutoCompactUsesConfiguredThreshold(t*testing.T){55ifshouldAutoCompact(84,100,85){56t.Fatal("84% must remain below an 85% threshold")57}58if!shouldAutoCompact(85,100,85){59t.Fatal("85% must trigger an 85% threshold")60}61ifshouldAutoCompact(100,100,0){62t.Fatal("off must disable percentage-triggered compaction")63}64}65```6667- [ ]**Step 2: Run tests and verify RED**6869Run:7071```sh72go test ./packages/agent/modes -run 'TestNormalizeAutoCompactThreshold|TestShouldAutoCompactUsesConfiguredThreshold' -count=173```7475Expected: compilation failure because the normalization and decision helpers do not exist.7677- [ ]**Step 3: Add optional configuration and minimal helpers**7879Add `AutoCompactThreshold *int` with JSON name `auto_compact_threshold` to both configuration structs. Implement normalization for exactly `0`, `70`, `80`, `85`, and `90`, defaulting all other values to `85`. Replace the hard-coded fraction check with the normalized percentage helper and pass the config field through `cli.go`.8081- [ ]**Step 4: Run focused tests and verify GREEN**8283Run:8485```sh86go test ./packages/agent/modes -run 'TestNormalizeAutoCompactThreshold|TestShouldAutoCompactUsesConfiguredThreshold' -count=187```8889Expected: PASS.9091### Task 2: Persistence and TUI preset picker9293**Files:**94- Modify: `packages/agent/settings_store.go`95- Modify: `packages/agent/settings_store_test.go`96- Modify: `packages/agent/modes/interactive.go`97- Modify: `packages/agent/modes/auto_compact_test.go`9899**Interfaces:**100- Extends: `SettingsStore.SetAutoCompactThreshold(percent int) error`101- Consumes: `normalizeAutoCompactThreshold(*int) int`102103- [ ]**Step 1: Write failing persistence and settings-item tests**104105Add a settings-store test that writes `70` into an isolated `$ZOT_HOME` and verifies `auto_compact_threshold` plus an unrelated config field. Add a modes test that opens settings with missing configuration and verifies the option values are `0`, `70`, `80`, `85`, `90` with `85` selected.106107```go108funcTestConfigSettingsStorePersistsAutoCompactThreshold(t*testing.T){109t.Setenv("ZOT_HOME",t.TempDir())110iferr:=SaveConfig(Config{Theme:"dark"});err!=nil{111t.Fatal(err)112}113iferr:=(configSettingsStore{}).SetAutoCompactThreshold(70);err!=nil{114t.Fatal(err)115}116cfg,err:=LoadConfig()117iferr!=nil{118t.Fatal(err)119}120ifcfg.AutoCompactThreshold==nil||*cfg.AutoCompactThreshold!=70{121t.Fatalf("auto_compact_threshold = %v, want 70",cfg.AutoCompactThreshold)122}123ifcfg.Theme!="dark"{124t.Fatalf("unrelated config changed: theme = %q, want dark",cfg.Theme)125}126}127```128129- [ ]**Step 2: Run tests and verify RED**130131Run:132133```sh134go test ./packages/agent ./packages/agent/modes -run 'AutoCompactThreshold|SettingsDialog.*AutoCompact' -count=1135```136137Expected: compilation or assertion failure because persistence and the picker row do not exist.138139- [ ]**Step 3: Implement persistence and live setting application**140141Add the settings-store method, fixed picker options, choice resolution, action routing, integer parsing, live `InteractiveConfig` update, and status message. Persist only values exposed by the picker; normalize the live value defensively before use.142143- [ ]**Step 4: Run focused tests and verify GREEN**144145Run:146147```sh148go test ./packages/agent ./packages/agent/modes -run 'AutoCompactThreshold|SettingsDialog.*AutoCompact' -count=1149```150151Expected: PASS.152153### Task 3: Documentation and full verification154155**Files:**156- Modify: `README.md`157- Review: `docs/superpowers/specs/2026-07-28-configurable-auto-compact-threshold-design.md`158- Review: `docs/superpowers/plans/2026-07-28-configurable-auto-compact-threshold.md`159160**Interfaces:**161- Documents: `auto_compact_threshold`162- Documents: `/settings` presets and `off` semantics163164- [ ]**Step 1: Update user documentation**165166Document `off`, `70%`, `80%`, `85%` default, and `90%` in the `/settings` section. Update `/compact` to state that threshold-based auto-compaction is configurable and that payload-too-large recovery remains active when the percentage trigger is off.167168- [ ]**Step 2: Format changed Go files**169170Run:171172```sh173gofmt -w packages/agent/config.go packages/agent/settings_store.go packages/agent/settings_store_test.go packages/agent/cli.go packages/agent/modes/interactive.go packages/agent/modes/auto_compact_test.go174```175176- [ ]**Step 3: Run the complete test suite**177178Run:179180```sh181go test ./...182```183184Expected: PASS.185186- [ ]**Step 4: Run static analysis**187188Run:189190```sh191go vet ./...192```193194Expected: PASS.195196- [ ]**Step 5: Inspect the final change**197198Run:199200```sh201git diff --check202git status --short203git diff204```205206Confirm only the configuration, TUI, tests, README, design, and plan belong to the feature.207208### Task 4: Publish the pull request209210**Files:**211- Stage only the files listed in Tasks 1-3.212213**Interfaces:**214- Produces: branch `codex/configurable-auto-compact-threshold`215- Produces: one feature commit and a ready GitHub pull request216217- [ ]**Step 1: Create the feature branch**218219```sh220git switch -c codex/configurable-auto-compact-threshold221```222223- [ ]**Step 2: Stage explicit feature paths and review**224225Stage only the implementation, tests, README, design, and plan. Review `git diff --cached --check` and `git diff --cached`.226227- [ ]**Step 3: Commit**228229```sh230git commit -m "Make auto-compact threshold configurable"231```232233- [ ]**Step 4: Push the branch**234235Push to the appropriate writable GitHub remote with upstream tracking.236237- [ ]**Step 5: Open a ready pull request**238239Target the upstream default branch. Include the behavior, compatibility, user impact, and exact validation commands in the PR body.