Skip to content

feat(pr2): compress-md, caveman persona, squeez update, track-result hook#11

Closed
claudioemmanuel wants to merge 1 commit intofeat/context-enginefrom
feat/compress-md-persona-update
Closed

feat(pr2): compress-md, caveman persona, squeez update, track-result hook#11
claudioemmanuel wants to merge 1 commit intofeat/context-enginefrom
feat/compress-md-persona-update

Conversation

@claudioemmanuel
Copy link
Copy Markdown
Owner

Summary

PR2 of two implementing the squeez token-optimizer roadmap. Stacks on #10 (PR1: context engine). Lands the user-facing pieces that make squeez attack input + output + memory-file tokens at maximum aggression by default.

Merge order: merge #10 first; this PR will then re-target develop and become a clean diff.

What's in PR2

squeez compress-md — pure-Rust caveman markdown compressor

  • Line-based state machine (Text / FencedCode / Table) walks input once
  • Preserves verbatim: fenced code blocks, inline code, URLs (bare + markdown link targets), headings, tables, list markers, version strings
  • Compresses prose only: drops articles, fillers, pleasantries, hedging
  • --ultra adds substitutions: with→w/, function→fn, configuration→config, repository→repo, because→b/c, etc.
  • Damage heuristic aborts the write if any code block, URL, or heading was lost
  • Backups at <stem>.original.md; never overwritten on subsequent runs
  • Targets via --all: ~/.claude/CLAUDE.md, ~/.copilot/copilot-instructions.md, $PWD/CLAUDE.md, $PWD/AGENTS.md, $PWD/.github/copilot-instructions.md

Caveman persona (default Ultra)

  • Three intensity levels (lite/full/ultra) shipped via include_str! from assets/persona_*.md
  • Injected into squeez init banner (Claude Code) and <!-- squeez:start --> ... <!-- squeez:end --> block in ~/.copilot/copilot-instructions.md
  • Squeez can't intercept the model's output stream from the hook layer — persona injection is the honest path

auto_compress_md=true (default)

  • squeez init runs compress-md --all silently on every session start
  • Idempotent: backup written once, integrity check guarantees safety, second run is a no-op when input is already compressed

squeez update

  • Self-updater shells out to curl + sha256sum/shasum -a 256 (both already required by install.sh) — zero new dependencies
  • Atomic on Unix (.new + rename); on Windows, writes .new + prints move instructions
  • --check reports without installing; --insecure skips checksum verification
  • SQUEEZ_UPDATE_URL_OVERRIDE for test injection

squeez track-result + posttooluse.sh extension

  • New PostToolUse hook tail pipes raw tool JSON into squeez track-result <tool>
  • Extracts file paths + errors from Read/Grep/LS/Glob/Bash results into SessionContext
  • Future bash calls dedup against this state via the cross-call hint added in PR1
  • Always exits 0 — never blocks the agent, even on malformed input

Config additions

persona = ultra              # off|lite|full|ultra (default ultra)
auto_compress_md = true      # default true

Both opt-out — set persona = off and auto_compress_md = false to disable.

Test plan

  • cargo test230 passing (was 162). Added: test_compress_md.rs (13), test_persona.rs (8), test_track_result.rs (6), test_update.rs (8) + inline unit tests in each new module.
  • cargo build --release — clean
  • bench/run.sh14/14 fixtures pass, including new mdcompress_claude_md (23%) and mdcompress_prose (27%) at <5ms latency
  • bench/run_context.sh3/3 (PR1 features still work)
  • target/release/squeez init — banner shows Persona: ultra + the full persona text
  • target/release/squeez compress-md --dry-run --ultra <file> — preserves code/URLs/headings, compresses prose, reports stats
  • target/release/squeez track-result Read with synthetic stdin — file path lands in seen_files
  • target/release/squeez update --check — fails gracefully (no GitHub releases yet); will work after first release published

Compression numbers

Fixture Before After Reduction Latency
mdcompress_claude_md.txt (mixed prose + code) 316 tk 246 tk -23% 3 ms
mdcompress_prose.txt (pure prose) 187 tk 138 tk -27% 3 ms

Caveman's LLM-based compressor reports ~45% on similar files, but at the cost of an Anthropic API roundtrip per file. squeez does the local pass deterministically in <5ms with no network call.

Risks & mitigations

Risk Mitigation
compress-md corrupting CLAUDE.md always-on damage heuristic + backup-on-first-write + integrity check on every output
Auto-compress on every session re-running idempotent: second pass produces no further reduction; backup never clobbered
Ultra persona too aggressive configurable via persona = lite|full|off
squeez update on Windows can't replace running .exe documented .new + manual move shim
track-result slowing PostToolUse content truncated to 256 KB; pure-Rust scanning; ≤5ms

🤖 Generated with Claude Code

PR2 of two. Stacks on the context engine from PR1 and lands the user-facing
features that make squeez attack input + output + memory-file tokens at
maximum aggression by default.

Highlights:

- squeez compress-md — pure-Rust, zero-LLM caveman-style markdown
  compressor. Line-based state machine preserves fenced code blocks,
  inline code, URLs (bare + markdown link targets), headings, tables,
  list markers, and version strings; only natural-language prose is
  compressed. Drops articles + fillers + pleasantries + hedging
  everywhere. --ultra additionally substitutes with→w/, function→fn,
  configuration→config, repository→repo, etc. Damage heuristic aborts
  the write if any code block, URL, or heading was lost. Backups go
  to <stem>.original.md and are never overwritten.

- Caveman persona — three intensity levels (lite/full/ultra) shipped
  via include_str!. Default is Ultra. Injected into the squeez init
  banner (Claude Code) and into the <!-- squeez:start --> block in
  ~/.copilot/copilot-instructions.md (Copilot CLI).

- auto_compress_md=true — squeez init runs compress-md --all silently
  on every session start. Idempotent: backup is only written once and
  the integrity check guarantees safety.

- squeez update — self-updater. Shells out to curl + sha256sum/shasum
  (both already required by install.sh) so we stay zero-dep. Atomic
  on Unix via .new + rename; documented .new + manual move on Windows.
  Override base URL via SQUEEZ_UPDATE_URL_OVERRIDE for tests.
  --check reports without installing; --insecure skips checksum.

- squeez track-result + posttooluse hook update — PostToolUse now
  pipes the raw JSON for every tool call (Read, Grep, LS, Glob, ...)
  into squeez track-result, which extracts file paths + errors from
  the result content and feeds them into SessionContext. Future bash
  calls dedup against this state via the cross-call hint added in PR1.

- Config additions: persona (default Ultra), auto_compress_md (default
  true). Both opt-out via config.ini.

Tests: 230 passing (was 162). New integration tests for compress_md
(13), persona (8), track_result (6), update (8). New mdcompress_*
bench fixtures show ~22-27% reduction (caveman LLM gets ~45% with API
calls; we get ~25% with zero API calls in <5ms).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claudioemmanuel claudioemmanuel deleted the branch feat/context-engine April 7, 2026 03:56
@claudioemmanuel claudioemmanuel deleted the feat/compress-md-persona-update branch April 7, 2026 03:58
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.

1 participant