Skip to main content

Compress shell output text through a Python API backed by Rust

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

codetool-shell is a Python library with a Rust compression engine. All compression/filter logic runs in the codetool-shell-rust helper binary; Python keeps the public API, binary discovery, and subprocess boundary.

  • backend="auto" uses the Rust CLI backend and raises a clear RustBackendUnavailable/RustBackendError if the helper cannot be found or fails.
  • backend="rust" is the same strict Rust path.
  • backend="python" is no longer supported.

Rust helper 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.3.tar.gz (193.9 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.3-py3-none-win_arm64.whl (639.9 kB view details)

Uploaded Python 3Windows ARM64

codetool_shell-0.1.3-py3-none-win_amd64.whl (696.6 kB view details)

Uploaded Python 3Windows x86-64

codetool_shell-0.1.3-py3-none-manylinux2014_x86_64.whl (841.2 kB view details)

Uploaded Python 3

codetool_shell-0.1.3-py3-none-manylinux2014_aarch64.whl (803.4 kB view details)

Uploaded Python 3

codetool_shell-0.1.3-py3-none-macosx_11_0_arm64.whl (763.7 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

codetool_shell-0.1.3-py3-none-macosx_10_12_x86_64.whl (799.6 kB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: codetool_shell-0.1.3.tar.gz
  • Upload date:
  • Size: 193.9 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.3.tar.gz
Algorithm Hash digest
SHA256 fc92586e22523a0e730c646cbb4452e19543e2ea8d1008a179b382e76f2083fc
MD5 b4f84cdb645b1352e2cc66d2daa7dac2
BLAKE2b-256 21c8d839e59a40245b3efb165724c27bdaedbf51a3ee65b395c98b6f3063f106

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.3.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.3-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.3-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 5338010d288a01d03f03f1e7b6f218dcb2343cbdaa8c973a7c789a5f1193cb2b
MD5 89dba0411c35c93e92ca263457f309f6
BLAKE2b-256 ebc3a7e3f151fa5b13660d6f9ce8c8cf42fdb219e9c4bb20bb599f82d0a839b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.3-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.3-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4823d0a2fa677cd2ba7e15ea99a929a0edba0e5d8df9f0934303193d612fbb60
MD5 7876f80bcd573bf7ca5b40fcb2cf1b0e
BLAKE2b-256 e6e3937ce7704598cd2caff0be7fc6e300bdc750d346a000b00dda49f88a7c35

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.3-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.3-py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.3-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 908568fb421d2435188f2b052515a7c7bb4c632f611740f51d8f1dcc05100b21
MD5 6474515327251c8548bdd7095c6f3226
BLAKE2b-256 b3d9bc44d754511c799b7785aedf896b61e4f5be3d9fd178075987c3680bd678

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.3-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.3-py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.3-py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 871a20c33f3e6c4cceebc4a68fcb88e180637f8cf4ec5ea8ee1e8ab832713db8
MD5 bd95912b4ac54851bd6208fc3072d34a
BLAKE2b-256 b011da158593f2aee21f9e4bc40146febfea790e5d7c415055b433105720054e

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.3-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.3-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.3-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a40b73fad3af2be35be315cd2ffa0e3ce813bbd681ea75ac15f3d43d3eeceed6
MD5 e3d4983fcc4a6148d8d18ac9ba2029c5
BLAKE2b-256 732861823a24af4f784ede3763f2c52f5339b137e3fba5c2b03b4d3034e6b6f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.3-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.3-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for codetool_shell-0.1.3-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0ebeb7fee0d0c5758bee7cc7cc2100d346c9eaf61dba13f7407d7a5e475d580f
MD5 25f9906142233b5b0a5ce8426f06fd4e
BLAKE2b-256 6f6065a808ccdf37c3073ad984c7f786d5697f72262c40107bc41d681bfbcb2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for codetool_shell-0.1.3-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