Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
543 changes: 532 additions & 11 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ tranche dupes # compare candidate pairs
tranche cluster # build clusters, dupes, tranches.md, summary
tranche batches # pack batches, write the park record
tranche page # render the workbench
tranche page --export-json --export-xlsx # optionally write standalone exports
```

`tranche refresh` runs those stages in that fixed order and reuses whatever its
Expand Down Expand Up @@ -119,7 +120,7 @@ tranche dupes [--max-pairs N] # candidate-pair comparisons
tranche cluster [--allow-unbound] # offline; no model, no network
tranche batches # offline; packs batches from the report
tranche info # read the current report's numbers
tranche page # render docs/index.html
tranche page [--export-json] [--export-xlsx] # render, with optional standalone exports
tranche refresh [--max-pairs N] [--no-page] [--dry-run]
tranche all # judge --resume, dupes, cluster, batches
```
Expand Down Expand Up @@ -176,7 +177,9 @@ Everything lands in `out/`, and all of it is tracked in this repository:
| `batches.json` | Merge batches bound to the `dupes.json` digest. |
| `parked.json` | PRs held out of batches, each with its named unblock path. |
| `summary.json` | Counts, token usage, report binding and output digests. |
| `docs/index.html`, `docs/data/workbench.json` | The rendered workbench. |
| `docs/index.html`, `docs/data/workbench.json` | The rendered workbench and its private client payload. |
| `docs/data/report.json` | Optional versioned standalone JSON export; see [the export schema](docs/PAGE_EXPORT.md). |
| `docs/data/report.xlsx` | Optional filterable Excel export. |

Review-candidate thresholds: risk ≤ 1.5, finished_form ≥ 1.8, is_fix ≥ 0.6,
security_flag < 0.5, current judgment, not a draft, outside a candidate group. A
Expand Down
3 changes: 3 additions & 0 deletions crates/tranche-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ path = "src/main.rs"
clap = { version = "4.6.7", features = ["derive"] }
serde = { workspace = true }
serde_json = { workspace = true }
rust_xlsxwriter = "0.99"
tranche-core = { path = "../tranche-core" }
time = { version = "0.3", features = ["formatting"] }
tokio = { version = "1", features = ["macros", "rt", "time"] }

[dev-dependencies]
tempfile = { workspace = true }
jsonschema = { version = "0.58.4", default-features = false }
zip = { version = "8.6", default-features = false, features = ["deflate"] }
13 changes: 12 additions & 1 deletion crates/tranche-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub enum Command {
/// Serve the read-only MCP stdio surface over the bound report.
Mcp,
/// Render the workbench from the bound reports.
Page,
Page(Page),
/// Capture, inspect and export public PR evidence.
#[command(subcommand_required = true, arg_required_else_help = true)]
Evidence {
Expand Down Expand Up @@ -114,6 +114,17 @@ pub struct Cluster {
pub allow_unbound: bool,
}

#[derive(Debug, Args)]
pub struct Page {
/// Also write the standalone JSON report to docs/data/report.json.
#[arg(long)]
pub export_json: bool,

/// Also write the filterable Excel workbook to docs/data/report.xlsx.
#[arg(long)]
pub export_xlsx: bool,
}

#[derive(Debug, Args)]
pub struct Refresh {
/// Cap the number of pair comparisons this pass.
Expand Down
7 changes: 6 additions & 1 deletion crates/tranche-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ pub fn run(cli: &Cli) -> Outcome {
&mut |line: &str| println!("{line}"),
),
Command::All(args) => run_all(&root, args.limit, args.max_pairs),
Command::Page => crate::workbench::page(&root, &mut |line: &str| println!("{line}")),
Command::Page(args) => crate::workbench::page(
&root,
args.export_json,
args.export_xlsx,
&mut |line: &str| println!("{line}"),
),
Command::Mcp => match crate::mcp::serve(&root) {
Ok(()) => Outcome::success(String::new()),
Err(error) => Outcome::refusal(error, 1),
Expand Down
2 changes: 1 addition & 1 deletion crates/tranche-cli/src/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn refresh(
"dupes" => crate::dupes::dupes(root, max_pairs, &mut say).map(|_| ()),
"cluster" => outcome_of(cluster_report(root, false, false)),
"batches" => outcome_of(build_batches(root, false)),
"page" => outcome_of(crate::workbench::page(root, &mut say)),
"page" => outcome_of(crate::workbench::page(root, false, false, &mut say)),
other => Err(format!("unknown step {other}")),
};
if let Err(error) = outcome {
Expand Down
18 changes: 18 additions & 0 deletions crates/tranche-cli/src/workbench/export_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use serde_json::{Value, json};
use tranche_core::report::REPOSITORY;

/// Stable standalone export envelope; the workbench payload remains private to the page.
pub(super) fn document(payload: &Value, report_binding: &str) -> Value {
json!({
"format": "tranche.page-export",
"schema_version": 1,
"repository": REPOSITORY,
"report_binding": report_binding,
"pull_requests": payload["prs"].clone(),
"categories": payload["categories"].clone(),
"groups": payload["groups"].clone(),
"batches_available": payload["batches_available"].clone(),
"batches": payload["batches"].clone(),
"parked": payload["parked"].clone(),
})
}
14 changes: 14 additions & 0 deletions crates/tranche-cli/src/workbench/json_export.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde_json::Value;
use tranche_core::report::Root;
use tranche_core::util::{atomic_write, indented_json};

/// Write the versioned standalone JSON contract.
pub(super) fn write(root: &Root, payload: &Value, report_binding: &str) -> Result<usize, String> {
let document = super::export_data::document(payload, report_binding);
let mut encoded = indented_json(&document).map_err(|error| error.to_string())?;
encoded.push('\n');
let path = root.docs_dir().join("data/report.json");
atomic_write(&path, encoded.as_bytes())
.map_err(|error| format!("cannot write {}: {error}", path.display()))?;
Ok(encoded.len())
}
3 changes: 3 additions & 0 deletions crates/tranche-cli/src/workbench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
//! Eligibility stays in the pipeline's own predicates. This never reclassifies a
//! judgment; it arranges what the report already says.

mod export_data;
mod json_export;
mod labels;
mod page;
mod payload;
mod writing;
mod xlsx_export;

pub use labels::CATEGORY_LABELS;
pub use page::page;
54 changes: 41 additions & 13 deletions crates/tranche-cli/src/workbench/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ use crate::commands::Outcome;
use crate::report_files::read_json;

/// Render the workbench from the bound reports.
pub fn page(root: &Root, report: &mut dyn FnMut(&str)) -> Outcome {
pub fn page(
root: &Root,
export_json: bool,
export_xlsx: bool,
report: &mut dyn FnMut(&str),
) -> Outcome {
let corpus: Prs = match load_prs(root, REPOSITORY) {
Ok(corpus) => corpus,
Err(error) => return Outcome::refusal(format!("corpus: {}", error.0), 1),
Expand Down Expand Up @@ -118,17 +123,40 @@ pub fn page(root: &Root, report: &mut dyn FnMut(&str)) -> Outcome {
parked.as_ref(),
root,
);
match super::writing::write(root, built) {
Ok((html, json_bytes)) => {
report(&format!(
"wrote {}/index.html ({} KB) and {}/data/workbench.json ({} KB)",
root.docs_dir().display(),
html / 1024,
root.docs_dir().display(),
json_bytes / 1024
));
Outcome::success(String::new())
}
Err(error) => Outcome::refusal(error, 1),
let (html, json_bytes) = match super::writing::write(root, &built) {
Ok(sizes) => sizes,
Err(error) => return Outcome::refusal(error, 1),
};

let mut message = format!(
"wrote {}/index.html ({} KB) and {}/data/workbench.json ({} KB)",
root.docs_dir().display(),
html / 1024,
root.docs_dir().display(),
json_bytes / 1024
);
if export_json {
let bytes = match super::json_export::write(root, &built, &binding) {
Ok(bytes) => bytes,
Err(error) => return Outcome::refusal(error, 1),
};
message.push_str(&format!(
" and {}/data/report.json ({} KB)",
root.docs_dir().display(),
bytes / 1024
));
}
if export_xlsx {
let bytes = match super::xlsx_export::write(root, &built, &binding) {
Ok(bytes) => bytes,
Err(error) => return Outcome::refusal(error, 1),
};
message.push_str(&format!(
" and {}/data/report.xlsx ({} KB)",
root.docs_dir().display(),
bytes / 1024
));
}
report(&message);
Outcome::success(String::new())
}
2 changes: 1 addition & 1 deletion crates/tranche-cli/src/workbench/writing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tranche_core::report::Root;
use super::CATEGORY_LABELS;

/// Write the page and its payload, and report the sizes.
pub(super) fn write(root: &Root, payload: Value) -> Result<(usize, usize), String> {
pub(super) fn write(root: &Root, payload: &Value) -> Result<(usize, usize), String> {
let template = std::fs::read_to_string(root.template_path())
.map_err(|error| format!("cannot read {}: {error}", root.template_path().display()))?;
let options: String = CATEGORY_LABELS
Expand Down
Loading
Loading