Skip to content

feature: /compact for context compression - #306

Merged
will-lamerton merged 4 commits into
Nano-Collective:mainfrom
Pahari47:compact
Jan 19, 2026
Merged

will-lamerton merged 4 commits into
Nano-Collective:mainfrom
Pahari47:compact

Conversation

@Pahari47

Copy link
Copy Markdown
Contributor

Description

closes #13
Implements a message compression system with manual /compact command and automatic context management via auto-compact. Reduces token usage by compressing conversation history while preserving essential information, enabling longer conversations within model context limits.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Features implemented

Manual compression command (/compact)

  1. Compress message history on demand with compression statistics
  2. Multiple modes: --aggressive, --conservative, --default, --preview
  3. Session overrides: --auto-on, --auto-off, --threshold <n>
  4. In memory backup/restore
  5. Preserves recent messages at full detail
  6. Tool result compression: keeps facts, drops noise (logs, verbose output)
  7. Never re-runs tools from compressed context (tool results are history, not instructions)

Auto-compact feature

  1. Automatic compression when context usage reaches configurable threshold
  2. Configurable via /compact --threshold <n> and agents.config:
{
    "nanocoder": {
      "autoCompact": {
        "enabled": true,
        "threshold": 60,
        "mode": "conservative",
        "notifyUser": true
      }
    }
  }
  1. Default: enabled at 60% threshold with conservative mode
  2. Runs asynchronously without blocking conversation
  3. Shows notifications when auto-compact triggers

Status command enhancement

  1. Displays current context usage (tokens/percentage)
  2. Shows auto-compact settings (enabled, threshold, mode)
  3. Indicates session overrides when active
  4. /compact
Screenshot 2026-01-15 171413
  1. /status
Screenshot 2026-01-15 171438
  1. /compact --preview
Screenshot 2026-01-15 171350

Compression strategy

  1. Smart tool result compression: extracts key facts, error details (type, file, line), success/failure status
  2. Message summarization for verbose content
  3. Preserves conversation state separately (ConversationStateManager untouched)
  4. Maintains conversation continuity and context flow

Testing

Automated Tests

  • All existing tests pass (pnpm test:all completes successfully)
  • New features include passing tests in .spec.ts/tsx files
    Note: Test coverage for compression utilities can be added
  • Code follows project style guidelines (Biome formatting applied)

Manual Testing

  • Tested manual /compact command with different modes
  • Tested auto-compact triggering at threshold
  • Tested session overrides (--auto-on, --auto-off, --threshold)
  • Tested /status command showing context usage
  • Verified tool result compression preserves essential information
  • Verified conversation state is preserved separately from messages

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

@Pahari47
Pahari47 marked this pull request as draft January 15, 2026 13:29
Comment thread source/config/index.ts Resolved
@Avtrkrb

Avtrkrb commented Jan 15, 2026

Copy link
Copy Markdown
Member

Also @Pahari47 you seem to have quite a few checks failing, please resolve them when you get the time.

@Pahari47

Copy link
Copy Markdown
Contributor Author

Also @Pahari47 you seem to have quite a few checks failing, please resolve them when you get the time.

actually There is problem in source/test-utils/cli-test-harness.ts this getCurrentStdout() function defined two time with same name, thats why everything failing, @Avtrkrb, can you check which one should keep.

@Avtrkrb

Avtrkrb commented Jan 15, 2026

Copy link
Copy Markdown
Member

Also @Pahari47 you seem to have quite a few checks failing, please resolve them when you get the time.

actually There is problem in source/test-utils/cli-test-harness.ts this getCurrentStdout() function defined two time with same name, thats why everything failing, @Avtrkrb, can you check which one should keep.

Sure let me take a look. @will-lamerton FYI

@Avtrkrb

Avtrkrb commented Jan 15, 2026 •

Copy link
Copy Markdown
Member

Also @Pahari47 you seem to have quite a few checks failing, please resolve them when you get the time.

actually There is problem in source/test-utils/cli-test-harness.ts this getCurrentStdout() function defined two time with same name, thats why everything failing, @Avtrkrb, can you check which one should keep.

@Pahari47
Removing the getCurrentStdout() defined in lines 294 to 298 should do it I guess: https://github.com/Pahari47/nanocoder/blob/0799be5fe99f3eac838048b71425ef6cec58352e/source/test-utils/cli-test-harness.ts#L294

Since the definition below it is much neater.. I feel the definition in lines 294 to 298 can be removed.

@will-lamerton

Copy link
Copy Markdown
Member

Hey @Pahari47, you might want to merge in upstream changes as these test cases were fixed and I can see you branch is behind them :)

@Pahari47

Copy link
Copy Markdown
Contributor Author

Hey @Pahari47, you might want to merge in upstream changes as these test cases were fixed and I can see you branch is behind them :)

I will fix it then Open the PR

@Pahari47
Pahari47 marked this pull request as ready for review January 16, 2026 15:39
@will-lamerton
will-lamerton merged commit ca83f9c into Nano-Collective:main Jan 19, 2026
will-lamerton pushed a commit that referenced this pull request Jan 20, 2026
Document critical issues (race condition, inconsistent token counting),
significant issues, and action items for the context compression feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add "/compact" Command for Context Compression

3 participants