Skip to main content
  • Version 0.1.0
  • Purity pure zero-dep (browser-safe; no workspace or external deps, no node:*)
  • Purpose Cut verbose tool output before it re-enters an agent’s context, with two guarantees: pass-through-safe (tiny inputs / low-savings return untouched) and failure-preserving (an error line in the input is guaranteed to survive into the output).
  • Workspace deps none
  • External deps none
Runs client-side or server-side between an adapter’s tool-result and context insertion. The whole package is pure string transforms, no process spawning, no I/O. The single . entry point has no subpath exports. UTF-8 byte length is measured via the global TextEncoder (Node 22+/browsers). The two invariants in code: compactToolOutput returns the original (with applied: false) when the input is below minBytes (default 512), when the compaction would drop a failure line, or when savings fall below minSavings (default 0.05). Every call returns stats so a bad rule is auditable.

Public API

Functions

Types & interfaces

Classes

None; this package exports only functions, types, and constants.

Constants

Failure-preserving is enforced at the package boundary, not by trusting each rule. After a rule transforms the output, compactToolOutput re-runs failureLines over the original and falls back to the untouched input (failure-preserve-fallback) if any failure line did not survive as a substring. A buggy overlay rule cannot silently swallow an error.

Used by

  • @clawboo/db; tools/broker.ts runs compactToolOutput(call.name, raw).text over a brokered tool call’s result (unless opts.compact === false), so the broker pipeline compacts tool output before it returns.
  • apps/web (server); lib/executorRunner.ts passes compactToolResultMarkdown(text).text as the runner’s compact dep, applied to a child’s report-up summary before it becomes a board comment / [Task Update].
  • apps/web (server); lib/teamChat/teamOrchestrator.ts wires compactToolResultMarkdown(text).text as the server-side team orchestrator’s compact dep.

Source

Barrel: packages/compaction/src/index.ts (re-exports ./compact, ./rules, and the ./types types).

See also

Last modified on July 9, 2026