Skip to main content

Parcoblatta

Parcoblatta Logo

  • (n) A Pennsylvania Wood Cockroach
  • (n) A not so obvious and definitely over-reaching pun (tree(sitter) + roach (Kafka's "The Metamorphosis"))
  • (this) a structural code search tool for kicking off focused pipelines

Given a codebase, Parcoblatta runs user-provided Tree-sitter queries and publishes the matches to JSONL files, stdout, or Kafka topics.

That sounds boring. Good.

The point is to use deterministic structural queries to find the exact code you care about, then hand that bounded slice to whatever comes next: a linter, a script, a GNU tool, a queue, a dashboard, or an agent that badly needs less room to wander.

For the longer rant, see WHY.md. For concrete examples, see USES.md.

What it is for

Parcoblatta turns this:

read the repo, find all the places where this pattern happens, and then...

into this:

Tree-sitter query
  -> match event
  -> JSONL / Kafka / prompt
  -> focused downstream work

It is especially useful when the downstream worker is an AI coding agent. Agents are much better when the task is already boxed in:

  • review this function
  • fix this capture
  • explain this class
  • reject this bad pattern
  • generate a test for this one scope
  • validate that this exact structural issue is gone

Tree-sitter chooses the scope. Parcoblatta packages it. The agent, script, or human gets a small thing to deal with.

Usage

Run a flow config:

uv run parcoblatta run examples/flows/functions_and_classes.yml

A config has shared code input and one or more rules. Each rule has one or more Tree-sitter queries and outputs.

code:
  file: src/parcoblatta

rules:
  - query:
      file: queries/functions.scm
    output:
      file: functions.jsonl

  - query:
      text: |
        (class_definition) @class
    output:
      file: classes.jsonl

Each JSONL line is a MatchEvent: one Tree-sitter query match with grouped captures, full contiguous source context, compact source context, and quickfix-style location metadata.

{
  "file": "src/parcoblatta/scanner/scanner.py",
  "language": "python",
  "query": "functions",
  "match_index": 0,
  "pattern_index": 0,
  "full_text": "...",
  "compact_text": "...",
  "captures": []
}

Prompt rendering

Parcoblatta can also render prompt events from match events. It does not call an LLM. It prepares the next event for whatever worker consumes it.

uv run parcoblatta run examples/flows/review_functions.yml

That example emits one prompt per matched function, with instructions to stay inside the captured scope.

Prompt templates use Python string.Template syntax. Available variables include:

  • $file
  • $language
  • $query
  • $match_index
  • $pattern_index
  • $full_text
  • $compact_text
  • $quickfix
  • $captures_json
  • $event_json

Example:

rules:
  query:
    file: queries/functions.scm
  prompt:
    text: |
      You are reviewing one $language match from $file.
      Stay inside this scope.

      $compact_text
    output:
      file: prompts.jsonl

Linting

Parcoblatta also includes a small Tree-sitter-query-based linter.

uv run parcoblatta lint examples/lint/demo_violations.py

Built-in example rules live in queries/lint/, including bare except, mutable defaults, eval / exec, debug print, and production assert patterns.

By default, linting skips common generated/vendor directories such as .venv, venv, site-packages, node_modules, dist, and cache directories. Add more ignores with --exclude or in pyproject.toml:

[tool.parcoblatta.lint]
code = ["."]
exclude = [".venv", "venv", "site-packages", "_scratch", "generated"]

Kafka output

If you have Kafka or Redpanda listening on localhost:9092:

uv run parcoblatta run examples/flows/kafka.yml

Example output config:

output:
  topic: parcoblatta.matches
  kafka:
    bootstrap_servers: localhost:9092
    client_id: parcoblatta-example

Why Kafka? Why JSONL?

Kafka is for fan-out, replay, queues, and longer-running pipelines. JSONL is for when that is obviously too much.

Both are just ways to keep Parcoblatta from becoming a giant swiss-army-knife tool. It finds structural matches and emits events. What happens after that is your business.

Writing queries

A few Python queries are provided to get started. The real power begins when you write your own.

If you were hoping for non-Python-centric queries, sorry, ask an LLM I guess. Or better yet, learn Tree-sitter's scheme-like query syntax. It's not hard, and it's worth it.

Metadata

Release files for parcoblatta 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parcoblatta 0.4.1
File Size Uploaded
parcoblatta-0.4.1.tar.gz 569.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for parcoblatta 0.4.1
File Interpreter ABI Platform
parcoblatta-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 593.6 kB

Release files / parcoblatta-0.4.1.tar.gz

Download URL parcoblatta-0.4.1.tar.gz
Size 569.6 kB
Tags Source
SHA-256 checksum
How to use checksums
34646c14837b0aa90a41333017be0ec513955494eab96c031ce283504fcfbb81
BLAKE2b-256 checksum
How to use checksums
83339af09fb6673aa3e497054d4cd8f9bd60baa33c6146e0306fd104cc114a8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release files / parcoblatta-0.4.1-py3-none-any.whl

Download URL parcoblatta-0.4.1-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3dc6ef28a124b571e1846ef2babdbfd4711ef3a835636cf34882b74793f2cfec
BLAKE2b-256 checksum
How to use checksums
01ca601c89e93d6b4b933198d1c1202d64bdfa827330765ad3878de944f4eb44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Release history Release notifications | RSS feed

0.6.0

1 release file

0.5.2

1 release file

This release

0.4.1 This release

2 release files

0.4.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page