Repository navigation
feat(cli): migrate the Tranche pipeline to native Rust - #20
Conversation
There was a problem hiding this comment.
💡 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".
| if let Some(data) = response.data { | ||
| println!("{}", serde_json::to_string_pretty(&data).unwrap()); |
There was a problem hiding this comment.
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 👍 / 👎.
| for batch in surface['batches']: | ||
| manifest, note = evidence.current_association(batch['id']) |
There was a problem hiding this comment.
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 👍 / 👎.
338a295 to
e68335f
Compare
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.
e68335f to
11bfa22
Compare
Summary
Migrates Tranche to Rust: a Cargo workspace with
tranche-core(the library) andtranche-cli(thetranchebinary). The other implementation is gone — nineteen.pyfiles 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 bytesrather than by whether it looks right.
What runs today
tranche cluster,tranche batchesandtranche infoare wired. Running themagainst the real corpus leaves every artifact byte-identical to the committed
files:
clusters.json,dupes.json,summary.json,batches.json,parked.jsonandtranches.md.fetch,judge,dupes,refresh,all,pageand theevidenceverbsrefuse with exit 1. They need transports that do not exist yet: GitHub
(
ghsubprocess), the Jev client (a plain HTTPS POST toapi.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:
clusters.jsonand the sections oftranches.mdfollow first appearance. The digests cannot catch a mistake here,because they sort keys explicitly — this was found only by reading the files.
0.6stays0.6;0.5700000000000001keeps all seventeen digits. Rounding to fixed places is wrong.colon, so a compact serializer restyles every artifact.
serde_jsontherefore needsarbitrary_precision(or a float parses to a differentdouble) and
preserve_order(or an object is written sorted). Both are documented inthe crate manifest as required rather than incidental.
Python's
sort_keys=Truecompares key objects, so ordering depends on the caller'stype: the report binding is keyed by PR number as an integer while the capture
generation's
revisionmap is keyed bystr(number). JSON has only string keys, sothe 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: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, 0failing with the local corpus (
cargo test -- --ignored).cargo fmt --check— clean.verifyandbinaryboth pass. Thebinaryjob is the project'scentral 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 is111 MiB and stays local, so
tests/fixture/holds a committed 464 KiB slice — 12 PRstaken 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
mcp_server.pyand its tests) is retained as the reference for thetranche-mcpport, per the plan. It cannot run as it stands — it imports modulesthat are gone.
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.