Skip to main content

Compress shell output text with Python and optional Rust backends

Project description

codetool-shell

Python interface library for compressing plain shell-output text before it is returned to an LLM/tool consumer.

from codetool_shell import compress_text

compressed = compress_text("one  \n\n\n two\t\n")
print(compressed)

The core pipeline is intentionally conservative:

  • normalize CRLF/CR line endings to LF
  • trim trailing whitespace on each line
  • run dedicated output filters only when they make the text smaller
  • collapse repeated blank lines to max_blank_lines (default: 1)

Initial dedicated filters cover:

  • git output: short and long status, tabbed name-status, diff stats, and patch hunks/binary-patch payloads with verbose unchanged or encoded context summarized
  • test-runner output: conservative ANSI-aware pytest (including quiet progress/summary output), unittest-like, vitest-like, Playwright, and cargo-test summaries that preserve failure identifiers, assertion/error text, source locations, artifacts/traces, and final totals
  • CI/job logs: conservative GitHub Actions / gh run-style summaries that collapse repeated timestamped step noise while preserving step names, annotations, warnings/errors, file locations, artifact/URL/path references, and job/workflow conclusions
  • standalone Python tracebacks: conservative traceback summaries that preserve exception type/message, file stack frames, chained-exception separators, source/caret context, and small command noise while collapsing repeated or internal stack frames
  • structured tables: conservative psql, SQLite/column, MySQL boxed, and long Markdown pipe table summaries that preserve headers, footers, first/last rows, and warning/error/URL/path/ID rows while counting omitted middle rows
  • file/tree/listing output: conservative path-only, tree, and safe ls -R reducers that render repeated path prefixes as compact trees while preserving visible summary totals and leaving metadata-rich listings unchanged
  • ripgrep output: direct path:line[:column]:text, heading-mode, context-mode path-line-context with -- separators, and ANSI-colored matches grouped into a compact path tree when repeated paths or prefixes would otherwise be duplicated, while diagnostic/table/prose-looking output is left alone
  • generic application logs: conservative long timestamp/level-prefixed log summaries that collapse repeated INFO/DEBUG/TRACE patterns while preserving first/last context, warnings/errors/fatal/panic/exception lines, file paths/URLs, failure summaries, and unusual levels
  • package-manager logs: conservative uv/pip, npm, bun, and cargo package install/update summaries that collapse progress/download/resolve/install noise while preserving warnings/errors, package summaries, versions, lock/frozen conflicts, audit/vulnerability summaries, hints, paths, and URLs
  • build/compiler diagnostics: conservative cargo/rustc, tsc, ESLint, and mypy-like reducers that collapse build progress while preserving warnings/errors, codes, file spans, source/caret snippets, notes/help, rule IDs, and final summaries

Backends

  • backend="python" uses the pure-Python implementation.
  • backend="rust" requires the optional Rust CLI backend.
  • backend="auto" prefers Rust when a compatible binary is discoverable and falls back to Python otherwise.

Rust discovery order:

  1. CODETOOL_SHELL_RUST_BINARY
  2. packaged wheel binaries under codetool_shell/bin/<platform>/
  3. development binaries under rust/target/{release,debug}/
  4. PATH

Build and stage the Rust CLI before creating a target wheel with:

python scripts/package_rust_binary.py --target-runtime linux-x86_64

Then build the Python distributions with:

uv build

During local development you can also rely on the development build directly:

cd rust
cargo build

Packaging and release

codetool-shell publishes target-specific wheels that include one matching Rust helper binary under codetool_shell/bin/<runtime>/. Supported runtime keys are:

  • linux-x86_64
  • linux-aarch64
  • macos-x86_64
  • macos-arm64
  • windows-x86_64
  • windows-arm64

To build a Linux x86_64 wheel locally (replace the runtime key for other targets):

uv run python scripts/package_rust_binary.py --target-runtime linux-x86_64
CODETOOL_SHELL_TARGET_RUNTIME=linux-x86_64 uv build --wheel

The release workflow builds an sdist, manylinux wheels, native macOS/Windows wheels, checks the distributions, and publishes to PyPI via trusted publishing for tagged releases (v*) or manual dispatch with publish=true.

Development

uv sync --dev
uv run pytest
uv run python benchmarks/benchmark_compress_text.py
uv run python scripts/benchmark_filters.py --iterations 1000

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codetool_shell-0.1.1.tar.gz (247.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

codetool_shell-0.1.1-py3-none-win_arm64.whl (594.4 kB view details)

Uploaded Python 3Windows ARM64

codetool_shell-0.1.1-py3-none-win_amd64.whl (634.6 kB view details)

Uploaded Python 3Windows x86-64

codetool_shell-0.1.1-py3-none-manylinux2014_x86_64.whl (771.9 kB view details)

Uploaded Python 3

codetool_shell-0.1.1-py3-none-manylinux2014_aarch64.whl (750.6 kB view details)

Uploaded Python 3

codetool_shell-0.1.1-py3-none-macosx_11_0_arm64.whl (713.6 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

codetool_shell-0.1.1-py3-none-macosx_10_12_x86_64.whl (734.9 kB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file codetool_shell-0.1.1.tar.gz.

File metadata

  • Download URL: codetool_shell-0.1.1.tar.gz
  • Upload date:
  • Size: 247.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for codetool_shell-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5173bd72f5b103866fdccddfc4fc6181ae9ee3214bc9e3e049b9d768161b8d56
MD5 81a4980be37666cfed67b685c60a52ab
BLAKE2b-256 a9a85f2f1e30c79b4f5effbb3a9eb2390cd932909cb93cad969f4053fd173b93

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.1.tar.gz:

Publisher: release.yml on pbi-agent/codetool-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetool_shell-0.1.1-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.1-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 1cbe0b276de069f18ee06a27d9835e4cb8feb23f058d8b5c571070493b696ea9
MD5 2c0f416ad2323c5e7cc9692ea5c606d3
BLAKE2b-256 e6eb91ff22c785d31092c348fc44abd129ad8d54b46cc54be15a4b504502071a

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.1-py3-none-win_arm64.whl:

Publisher: release.yml on pbi-agent/codetool-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetool_shell-0.1.1-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 8dd9e8aa3475e5eba281e96998bc451cd80050efb8f6fc108ca72152a993b3df
MD5 e4db5c41b31d9232677dd08e8c962660
BLAKE2b-256 f99087e0750903e72d5ca037a33f5729f1701c21e25fd2304e63ba586375a87a

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.1-py3-none-win_amd64.whl:

Publisher: release.yml on pbi-agent/codetool-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetool_shell-0.1.1-py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.1-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f81a922804a78027123c6e92247f28c0b929f8fa73fd6d1dd61fb8075e4d1ec4
MD5 ef89dfeebf8193225cf9495f988bc23c
BLAKE2b-256 ff618407e013eae559656351087c5a5043dee8a2bc194cb148537b456b1e391b

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.1-py3-none-manylinux2014_x86_64.whl:

Publisher: release.yml on pbi-agent/codetool-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetool_shell-0.1.1-py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.1-py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 91370ae7f6f82d472e0d8ccb7f1e60f6a917b46412610cb8d77875f9bbf68b9d
MD5 7ff722c998040849a05e347ee526c311
BLAKE2b-256 ec8a31d67e94f7d1d1ea4ac48a984695c435b8d7b23bca1ae30af9f39e12dd01

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.1-py3-none-manylinux2014_aarch64.whl:

Publisher: release.yml on pbi-agent/codetool-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetool_shell-0.1.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e79553d1ae9e9beedd2357e206889233a9fb6559aa8276c4bb8423dd68f632d2
MD5 43cd4de7092a2a46c1262140c858b463
BLAKE2b-256 e4dc32eaae4c34abf64b6e15985f5460b73b878c4abf58d18bf7ced821c24359

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.1-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on pbi-agent/codetool-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file codetool_shell-0.1.1-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.1-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b7155d8f91530321796ab3fb12da5c46e93a049c5a01697b913d296febd013fb
MD5 82f9fc23328aab8320349d80f6b326b3
BLAKE2b-256 92c47ff03ab6a695b728d436b1c4bff4ab0e29bc8ee66d2629e5f4d2b35f54fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.1-py3-none-macosx_10_12_x86_64.whl:

Publisher: release.yml on pbi-agent/codetool-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page