Skip to main content

Trim noisy terminal output before it reaches your AI coding agent

Project description

sniptrace

Trim noisy terminal output before it reaches your AI coding agent. Save tokens, reduce LLM costs, and keep context windows focused on what matters.

pip install sniptrace

Quick start

Filter a string you already have

from sniptrace import filter_text

raw_output = captured_stderr  # string from your agent's code execution
clean = filter_text(raw_output)
llm.complete(f"Fix this error:\n{clean}")

Run a command and get filtered output

from sniptrace import run

result = run(["pytest", "tests/"])

if not result.ok:
    llm.complete(f"Fix this error:\n{result.output}")
    # result.output has no progress bars, no site-packages frames, no noise

What gets filtered

SnipTrace removes known low-signal output patterns from:

  • Python — stdlib/venv traceback frames, pip install chatter
  • Node / JS — npm/pnpm/yarn deprecation warnings, progress lines
  • Docker — BuildKit step lines, layer pull progress
  • pytest / Jest / Vitest — session headers, progress dots, PASSED lines
  • Cargo / Gradle / Maven — compile progress, [INFO] lines
  • Generic — ANSI escape codes, progress bars, spinner frames, update banners

Lines containing error signals (error, traceback, exception, failed, cannot, etc.) are always preserved, even if they match a strip pattern.

API

filter_text(text: str) -> str

Filter an already-captured string. No CLI required — all filtering is pure Python.

from sniptrace import filter_text

clean = filter_text(raw_stderr)

run(command, *, cwd=None, env=None, timeout=None) -> SnipResult

Run a command and return filtered output. Uses the sniptrace CLI if installed (preserves telemetry), otherwise filters natively in Python.

from sniptrace import run

result = run(["pytest", "-q", "tests/"])
print(result.output)        # filtered output
print(result.ok)            # True if exit code was 0
print(result.reduction_pct) # e.g. 87.3
print(result.bytes_saved)   # original_bytes - filtered_bytes

SnipResult

@dataclass
class SnipResult:
    exit_code: int
    output: str
    original_bytes: int
    filtered_bytes: int
    reduction_pct: float
    filtered: bool      # False if filtering was skipped

    @property
    def ok(self) -> bool: ...         # exit_code == 0
    @property
    def bytes_saved(self) -> int: ... # original_bytes - filtered_bytes

is_available() -> bool

Returns True if the sniptrace CLI is installed on PATH.

Typical agent loop

from sniptrace import run

def agent_loop(task: str, llm, max_rounds: int = 5):
    code = llm.complete(f"Write Python code to: {task}")
    
    for _ in range(max_rounds):
        write_to_disk(code)
        result = run(["python", "solution.py"])
        
        if result.ok:
            return code  # done
        
        code = llm.complete(
            f"The code produced this error:\n{result.output}\n\nFix it."
        )
    
    return code

Zero dependencies

The package uses only the Python standard library. No external packages required.

Install the CLI (optional)

The CLI is optional — filter_text() and run() both work without it. The CLI adds telemetry (token savings counter) and shell wrappers for automatic filtering in your terminal.

curl -fsSL https://sniptrace.com/install.sh | sh

Links

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

sniptrace-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

sniptrace-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file sniptrace-0.1.0.tar.gz.

File metadata

  • Download URL: sniptrace-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for sniptrace-0.1.0.tar.gz
Algorithm Hash digest
SHA256 affc575d803257a9129b9bd2fb24294b3d926c6dffeafbf71f07be6614b08b96
MD5 6947a678a89a73ef8fa5c6d7f0869c2d
BLAKE2b-256 bb5860df5ad12c8c265bae891faa64f7349a2735b10fb8c9203f0d5a0ee8cbd1

See more details on using hashes here.

File details

Details for the file sniptrace-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sniptrace-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for sniptrace-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ac3e56c3c877105217fb1760d3ce217c65fbe482abacbe99547a5d20240c54f
MD5 98436b6ae1150a20b28a7dbe0d173655
BLAKE2b-256 335917cc90688016cd7acc02310627aff5eb07a168ce2960d21e411cd98b6836

See more details on using hashes here.

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