Skip to content

feat(tui): Compact Mode Phase 2 - Compression Engine Integration #9018

Closed

Description

@apto-as

Summary

Implement Phase 2 of Compact Mode: Compression engine for actual token reduction.

Background

Phase 1 provides UI compression (display only). Phase 2 adds actual token reduction sent to LLM APIs.

Phase 2 Scope (4 weeks)

Compression Technologies (Vendor-Agnostic Only)

Technology Token Reduction Implementation
LLMLingua-2 Up to 20x Python sidecar
Conversation Pruning 30-50% Native
Tool Output Truncation Variable Native
TOON Format 35-50% vs JSON Native

Quality vs Compression Trade-off

Ratio Quality Retention Risk
2x-5x 95-98% ✅ Recommended
5x-10x 90-95% ⚠️ Caution
10x-20x 85-95% ⚠️ Task-dependent

Deliverables

  • LLMLingua-2 Python sidecar integration
  • Sidecar lifecycle management (lazy loading, timeout cleanup)
  • Conversation pruning logic (keep recent N, compress older)
  • TOON format serializer for structured data
  • Compression threshold configuration
  • Quality preservation settings (protect entities, numbers)
  • Compression metrics display (tokens saved)

Technical Notes

  • LLM Understanding Impact: 2-5% at recommended settings
  • Vendor Agnostic: ✅ All techniques work with any LLM
  • Excluded: Anthropic Token-Efficient Tools (Claude-only)
  • Excluded: Provider-specific Prompt Caching (non-interoperable)

Best Practices

  1. Preserve named entities and numbers explicitly
  2. Use extractive (LLMLingua-2) over abstractive methods
  3. Never compress recent 3 messages
  4. Set maximum compression threshold at 80%

Files to Create/Modify

  • packages/opencode/script/llmlingua-sidecar.py - Python compression service
  • packages/opencode/src/session/compression.ts - Compression client
  • packages/opencode/src/session/compaction.ts - Enhance existing pruning

Dependencies

Success Criteria

  • 50-70% token reduction achieved
  • Quality retention >95% on standard tasks
  • Sidecar starts/stops correctly
  • Metrics displayed in TUI

Related


Generated by Trinitas Full Mode Analysis

Activity

  1. github-actions commented on Jan 17, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or closely related to existing issues. Please check:

    Feel free to ignore if none of these address your specific implementation approach for Phase 2.

  2. rekram1-node commented on Jan 17, 2026

    @rekram1-node
    Collaborator

    closing - spam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions