Skip to content

feat(cli): migrate the Tranche pipeline to native Rust - #20

Merged
blackopsrepl merged 1 commit into
masterfrom
feat/rust-ratatui-cli
Oct 2, 2026
Merged

blackopsrepl merged 1 commit into
masterfrom
feat/rust-ratatui-cli

Conversation

@blackopsrepl

@blackopsrepl blackopsrepl commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Migrates Tranche to Rust: a Cargo workspace with tranche-core (the library) and
tranche-cli (the tranche binary). The other implementation is gone — nineteen
.py files removed, the Makefile's interpreter bootstrapping removed with them.

A migration, not a wrapper. No PyO3, no embedded interpreter, no subprocess. The
earlier PyO3-bridge and ratatui-TUI designs were both dropped before this landed.

out/ is the contract, and the code is judged by whether it reproduces those bytes
rather than by whether it looks right.

What runs today

tranche cluster, tranche batches and tranche info are wired. Running them
against the real corpus leaves every artifact byte-identical to the committed
files
: clusters.json, dupes.json, summary.json, batches.json,
parked.json and tranches.md.

fetch, judge, dupes, refresh, all, page and the evidence verbs
refuse with exit 1. They need transports that do not exist yet: GitHub
(gh subprocess), the Jev client (a plain HTTPS POST to
api.typesafe.ai/v1/systemone), and the workbench renderer.

So this does not yet run the full pipeline, and it should not be merged on the
basis that it does.

Format properties that are load-bearing

Three of these look like accidents and are not, because each one silently changes a
tracked artifact:

  • Insertion order, not sorted. Categories in clusters.json and the sections of
    tranches.md follow first appearance. The digests cannot catch a mistake here,
    because they sort keys explicitly — this was found only by reading the files.
  • Floats keep the shortest round-tripping form. 0.6 stays 0.6;
    0.5700000000000001 keeps all seventeen digits. Rounding to fixed places is wrong.
  • JSON separators carry a space. The stored writer puts one after each comma and
    colon, so a compact serializer restyles every artifact.

serde_json therefore needs arbitrary_precision (or a float parses to a different
double) and preserve_order (or an object is written sorted). Both are documented in
the crate manifest as required rather than incidental.

Python's sort_keys=True compares key objects, so ordering depends on the caller's
type: the report binding is keyed by PR number as an integer while the capture
generation's revision map is keyed by str(number). JSON has only string keys, so
the two are indistinguishable from the value alone and the caller states which applies.

Repository conventions

Two rules, applied throughout and recorded in docs/ARCHITECTURE.md:

  1. No source file reaches 300 lines.
  2. Tests live only in tests/, named for the outcome they protect.

No #[cfg(test)] module exists in any source file.

Verification

Run on this branch, and in CI:

  • cargo clippy --workspace --all-targets -- -D warnings — clean.
  • cargo test — 34 passing, 0 failing in a fresh checkout; 37 passing, 0
    failing
    with the local corpus (cargo test -- --ignored).
  • cargo fmt --check — clean.
  • CI on GitHub — verify and binary both pass. The binary job is the project's
    central claim as a gate: it builds the release binary, opens the command tree, and
    confirms a root without reports is refused rather than panicking.

The corpus-dependent tests are #[ignore]d rather than deleted. The full corpus is
111 MiB and stays local, so tests/fixture/ holds a committed 464 KiB slice — 12 PRs
taken from real confirmed groups, with the judgments and pair verdicts that name them.
The fixture tests run everywhere and assert byte equality against that slice; the
ignored tests pin digests against the full corpus. CI caught the original version of
this: the tests passed here only because the corpus happened to be present, and failed
in a clean checkout on an empty read.

Not included

  • The MCP server (mcp_server.py and its tests) is retained as the reference for the
    tranche-mcp port, per the plan. It cannot run as it stands — it imports modules
    that are gone.
  • The masthead GIF generator was not ported; the GIF stays as a committed asset.

Attribution

Author: Vittorio Distefano (@blackopsrepl).

Builds on Christopher's (@GreyforgeLabs) initial CLI POC, with the Rust frontend and
native integration developed and maintained in Tranche.

No corpus regeneration, paid model calls, GitHub mutation, merge or release.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0f57c89989

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main.rs Outdated
Comment on lines +32 to +33
if let Some(data) = response.data {
println!("{}", serde_json::to_string_pretty(&data).unwrap());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid printing dashboard state after the TUI exits

When tranche or tranche evidence is launched interactively, the overview response contains the full surface in response.data. After ui::run restores the terminal, this unconditional serialization prints that entire JSON object on every normal q/Escape exit, leaving users with a potentially very large dump instead of a cleanly restored shell. Only emit data for a headless or --json invocation, not after the interactive dashboard.

Useful? React with 👍 / 👎.

Comment thread src/service.py Outdated
Comment on lines +54 to +55
for batch in surface['batches']:
manifest, note = evidence.current_association(batch['id'])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Build capture associations from one report snapshot

For every batch in the default dashboard, current_association reloads and revalidates the complete report and then find_captures rescans every stored manifest. A corpus with hundreds of batches and captures therefore performs repeated full-corpus work and O(batches × captures) manifest reads on every launch or refresh. Because each iteration loads independently, a concurrent report refresh can also attach associations from a newer generation to the older surface; reuse the already validated report and index manifests once for the whole overview.

Useful? React with 👍 / 👎.

@blackopsrepl blackopsrepl changed the title feat(cli): add Rust and ratatui frontend with embedded PyO3 services feat(cli): add a Rust command line backed by embedded PyO3 services Oct 2, 2026
@blackopsrepl blackopsrepl changed the title feat(cli): add a Rust command line backed by embedded PyO3 services feat(cli): migrate the Tranche pipeline to native Rust Oct 2, 2026
@blackopsrepl
blackopsrepl force-pushed the feat/rust-ratatui-cli branch 8 times, most recently from 338a295 to e68335f Compare October 2, 2026 12:05
Tranche is a Rust project. `crates/tranche-core` holds the logic and
`crates/tranche-cli` is the `tranche` binary; the former implementation is gone,
including the Makefile's interpreter bootstrapping. There is no PyO3, no embedded
interpreter and no subprocess for pipeline work.

This lands the branch as one commit on purpose. The branch's own sequence
contains abandoned designs — an embedded-PyO3 service bridge and a ratatui
dashboard, both removed again before anything shipped — and squashing means that
narrative never reaches `master`. The reversals are recorded here because they
are worth knowing, not because anyone needs to step through them.

## What runs

Every command is wired except the `evidence` verbs, which refuse rather than
pretend.

| Command | State |
|---|---|
| `fetch` | captures open-PR membership through `gh`, `curl` or an in-process client |
| `judge` | one batched model call per unjudged PR, append-only log, resume by binding |
| `dupes` | compares outstanding candidate pairs, append-only verdict log |
| `cluster` | rebuilds `clusters.json`, `dupes.json`, `tranches.md`, `summary.json` |
| `batches` | packs batches and writes the park record |
| `page` | renders `docs/index.html` and the payload it fetches |
| `refresh` | the six steps in order, with before/after accounting and a dry run |
| `all` | judge, dupes, cluster, batches |
| `info` | the counts and digests of the report on disk |
| `evidence …` | **refuses** — capture, inspection and export are not ported |

## The on-disk format is the contract

Everything under `out/` and `docs/` is an interface every reader depends on, so
the code is judged by whether it reproduces those bytes rather than by whether it
looks right. Running the ported pipeline against the corpus leaves
`clusters.json`, `dupes.json`, `summary.json`, `batches.json`, `parked.json`,
`tranches.md`, `docs/index.html` and `docs/data/workbench.json` byte-identical to
the committed files.

Four format properties look like accidents and are not, because each one silently
changes a tracked artifact:

- **Insertion order, not sorted.** Categories in `clusters.json` and the sections
  of `tranches.md` follow first appearance. The digests cannot catch a mistake
  here, because they sort keys explicitly — this was found only by reading the
  files.
- **Floats keep the shortest round-tripping form.** `0.6` stays `0.6`;
  `0.5700000000000001` keeps all seventeen digits.
- **JSON separators carry a space.** The stored writer puts one after each comma
  and colon, so a compact serializer restyles every artifact.
- **The workbench payload is flattened to ASCII.** It is fetched and injected, so
  `&`, `<` and `>` are escaped and every non-ASCII character becomes `\uXXXX` —
  a title is untrusted text from GitHub.

`serde_json` therefore needs `arbitrary_precision` and `preserve_order`; both are
load-bearing, and the crate manifest says so.

## The workbench refuses inconsistent inputs

A report whose binding no longer matches, a `batches.json` from a different dupe
run, a park record that does not equal the one the current judgments produce: the
renderer stops rather than showing a maintainer numbers nobody can vouch for.
Eligibility stays in the pipeline's own predicates — the page arranges what the
report already says and never reclassifies a judgment.

## Conventions

1. No source file reaches 300 lines.
2. Tests live only in `tests/`, named for the outcome they protect.

No `#[cfg(test)]` module exists in any source file.

## Verification

- `cargo clippy --workspace --all-targets -- -D warnings` — clean.
- `cargo test` — 68 passing, 0 failing.
- `cargo fmt --check` — clean.
- CI on GitHub — `verify` and `binary` both pass. The `binary` job builds the
  release binary, opens the command tree, and confirms a root without reports is
  refused rather than panicking.

The tests that pin digests against the full corpus are `#[ignore]`d and run with
`cargo test -- --ignored`; the corpus is 111 MiB and stays local, so
`tests/fixture/` holds a committed 464 KiB slice that runs everywhere.

## Not included

The MCP server (`mcp_server.py` and its tests) is kept as the reference for the
`tranche-mcp` port. It cannot run as it stands — it imports modules that are
gone — which is why it is a reference rather than an implementation.

## Attribution

Author: Vittorio Distefano (@blackopsrepl).

Builds on Christopher's (@GreyforgeLabs) initial CLI POC, with the Rust frontend
and native integration developed and maintained in Tranche.
@blackopsrepl
blackopsrepl force-pushed the feat/rust-ratatui-cli branch from e68335f to 11bfa22 Compare October 2, 2026 12:08
@blackopsrepl
blackopsrepl merged commit bbfa017 into master Oct 2, 2026
2 checks passed
@blackopsrepl
blackopsrepl deleted the feat/rust-ratatui-cli branch October 2, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant