Skip to content

Compaction, cost tracking, -O optimization and more#5

Merged
jgarzik merged 5 commits intomainfrom
updates
Dec 28, 2025
Merged

Compaction, cost tracking, -O optimization and more#5
jgarzik merged 5 commits intomainfrom
updates

Conversation

@jgarzik
Copy link
Owner

@jgarzik jgarzik commented Dec 28, 2025

No description provided.

jgarzik and others added 4 commits December 27, 2025 22:58
- Cost tracking module (src/cost.rs): Per-model pricing, session/turn
  aggregation, /cost command, token usage in stats line and transcripts
- Add -O flag for optimization mode (terse, token-efficient output)
- Config validation: Validate targets, thresholds, hook regexes, MCP configs
- Tool filter consolidation (src/tool_filter.rs): Unified pattern matching
  for policy.rs and subagent.rs (exact, wildcards, argument patterns)
- Regex caching in plan.rs using once_cell::Lazy
- 58 tests passing, clippy clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Layer 1: Replace verbose 60-token system prompt with terse 15-token
version using positive framing ("AI-to-AI mode. Maximum information
density. Structure over prose. No narration.")

Layer 2: Add SchemaOptions struct for extensibility and implement
compressed tool schemas that strip descriptions in optimize mode
(e.g., "Read file content. Paths relative to project root." → "Read file").

Also adds IDEAS.md documenting future optimization layers (result
compression, history summarization, output style enforcement).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Features implemented:
- Context compaction: /compact command to summarize older messages and
  reclaim context space when conversations grow long
- Slash commands: User-defined markdown commands in .yo/commands/<name>.md
  with $ARGUMENTS placeholder and optional YAML frontmatter
- HTTP/SSE MCP transport: Support for HTTP and SSE transports in addition
  to stdio for Model Context Protocol servers
- force_continue: Stop hooks can now request continuation with a new prompt

New files:
- src/compact.rs: Context compaction/summarization module
- src/commands.rs: Slash commands system

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jgarzik jgarzik requested a review from Copilot December 28, 2025 05:07
@jgarzik jgarzik self-assigned this Dec 28, 2025
@jgarzik jgarzik added bug Something isn't working enhancement New feature or request labels Dec 28, 2025
@jgarzik jgarzik changed the title Updates Compaction, cost tracking, -O optimization and more Dec 28, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements multiple major features including token optimization mode (-O flag), comprehensive cost tracking, context compaction, user-defined slash commands, and HTTP/SSE transport support for MCP servers. It also consolidates tool filtering logic and adds configuration validation.

Key changes:

  • Token optimization system with compressed tool schemas and AI-to-AI communication mode
  • Session-level cost tracking with per-model pricing and turn-by-turn breakdown
  • Context compaction to manage conversation history and reduce token usage
  • User-defined slash commands loaded from .yo/commands/ directories
  • HTTP and SSE transport support for MCP servers alongside existing stdio
  • Configuration validation with detailed error reporting
  • Consolidated tool pattern matching logic into dedicated module

Reviewed changes

Copilot reviewed 28 out of 29 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
src/transcript.rs Adds token_usage logging method for tracking LLM API calls
src/tools/write.rs Implements schema optimization with terse descriptions when -O flag is set
src/tools/task.rs Adds optimized schema support for Task tool delegation
src/tools/read.rs Implements compressed schema for file reading operations
src/tools/mod.rs Introduces SchemaOptions struct for controlling schema verbosity
src/tools/grep.rs Adds schema optimization for grep search operations
src/tools/glob.rs Implements terse schema for file pattern matching
src/tools/edit.rs Adds optimized schema for file editing operations
src/tools/bash.rs Implements schema optimization and adds test for optimized mode
src/tools/activate_skill.rs Adds schema optimization for skill pack activation
src/tool_filter.rs New module consolidating tool pattern matching logic from policy and subagent
src/subagent.rs Integrates tool filtering module, adds cost tracking and optimization mode support
src/policy.rs Refactors to use consolidated tool_filter module
src/plan.rs Optimizes regex compilation with once_cell caching
src/mcp/transport.rs Adds HTTP and SSE transport implementations alongside stdio
src/mcp/manager.rs Updates to support multiple transport types (stdio/HTTP/SSE)
src/mcp/client.rs Abstracts transport layer with McpTransportImpl enum
src/main.rs Adds new modules, command index initialization, and config validation
src/llm.rs Introduces LlmClient trait for abstraction and testing
src/hooks.rs Removes trailing whitespace
src/cost.rs New comprehensive cost tracking system with model pricing and session management
src/config.rs Adds validation framework, MCP transport config, and cost tracking configuration
src/compact.rs New context compaction module for conversation history summarization
src/commands.rs New slash commands system for user-defined markdown command templates
src/cli.rs Integrates cost display, compaction, slash commands, and turn counter
src/agent.rs Adds cost tracking, optimization mode instructions, and force_continue support
IDEAS.md Documents future optimization strategies based on LLM research
Cargo.toml Adds once_cell dependency for regex caching
Cargo.lock Updates lock file with once_cell dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jgarzik jgarzik merged commit b313ace into main Dec 28, 2025
4 checks passed
@jgarzik jgarzik deleted the updates branch December 28, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants