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.

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.0

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.0
File Size Uploaded
parcoblatta-0.4.0.tar.gz 569.5 kB Details

Built distribution (wheel)

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

Total release size: 592.8 kB

Release files / parcoblatta-0.4.0.tar.gz

Download URL parcoblatta-0.4.0.tar.gz
Size 569.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ff98c604747b3f6069973d9deaffb53b13a6a93947eb041c27416690718b170f
BLAKE2b-256 checksum
How to use checksums
169b2db6b6cbecb7746634636016b6c6e37a1f0de87136fa81655d2be5f10776
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.0-py3-none-any.whl

Download URL parcoblatta-0.4.0-py3-none-any.whl
Size 23.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0581556e5ff36d1b313eb411d7848d49c2be68e06eae6254dd32f3fc0a01980e
BLAKE2b-256 checksum
How to use checksums
b589986379dfc922473055e9559b18288dba1bab8b237b2a86a37f82c5274ff9
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

0.4.1

2 release files

This release

0.4.0 This release

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