Conversation
Design for k-neighbor exploration, colored output, and shell completions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
10-task plan covering shell completions, colored output, and k-neighbor graph exploration for the pred CLI tool. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #84 +/- ##
==========================================
+ Coverage 96.33% 96.36% +0.03%
==========================================
Files 197 197
Lines 27037 27210 +173
==========================================
+ Hits 26047 26222 +175
+ Misses 990 988 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… exploration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
GiggleLiu
left a comment
There was a problem hiding this comment.
please reply give me some using examples of cli to reflect this change. Must be reproducible by user, and please update all documents.
problemreductions-cli/src/cli.rs
Outdated
| Reduce(ReduceArgs), | ||
| /// Solve a problem instance | ||
| Solve(SolveArgs), | ||
| /// Generate shell completions for bash, zsh, fish, etc. |
There was a problem hiding this comment.
if completion requires manul setup, then it seems not useful.
There was a problem hiding this comment.
Removed the completions command and the clap_complete dependency since it requires manual shell setup.
| let mut text = format!( | ||
| "Registered problems: {} types, {} reductions, {} variant nodes\n\n", | ||
| // Collect data for each problem | ||
| struct Row { |
There was a problem hiding this comment.
needs to check the visual outout. please run the command line and comment under pr.
There was a problem hiding this comment.
Posted CLI output examples as a PR comment above.
| let aliases = aliases_for(name); | ||
| if aliases.is_empty() { | ||
| text.push_str(&format!(" {name}\n")); | ||
| let mut text = String::new(); |
There was a problem hiding this comment.
a lot of places used table formating, consider wrapping it into a function.
There was a problem hiding this comment.
Extracted table formatting into a reusable format_table() helper in output.rs. The list command now uses it.
src/rules/graph.rs
Outdated
| } | ||
|
|
||
| /// Find the NodeIndex for a specific (name, variant) pair. | ||
| pub fn find_node_index( |
There was a problem hiding this comment.
Check if we have an existing function for this type of query?
There was a problem hiding this comment.
Yes — there's an existing private lookup_node() method (line 402) with identical logic. Refactored find_node_index() to delegate to self.lookup_node(name, variant).
There was a problem hiding this comment.
Pull request overview
This pull request implements three CLI v2 features for the pred tool: shell completions, colored terminal output, and k-neighbor graph exploration.
Changes:
- Added BFS-based k-neighbor exploration to
ReductionGraphin the core library withk_neighbors()method and supporting types (NeighborInfo,TraversalDirection) - Added colored terminal output support using
owo-colorswith TTY detection andNO_COLORenvironment variable respect - Added shell completions command using
clap_completefor bash, zsh, and fish - Enhanced
pred listwith aligned table layout showing variant and reduction counts - Extended
pred showwith--hopsand--directionflags for neighbor exploration with tree rendering - Added comprehensive test coverage: 5 new library unit tests for k-neighbors BFS, 8 new CLI integration tests (3 completions + 5 k-neighbor)
Reviewed changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/rules/graph.rs | Added k_neighbors() BFS method and helper methods (find_node_index, neighbor_indices, node_name) for graph traversal |
| src/rules/mod.rs | Exported new NeighborInfo and TraversalDirection types |
| src/unit_tests/reduction_graph.rs | Added 5 unit tests for k-neighbor BFS covering different directions and edge cases |
| problemreductions-cli/Cargo.toml | Added clap_complete, owo-colors, and petgraph dependencies |
| problemreductions-cli/src/output.rs | Added color helper functions with TTY and NO_COLOR support |
| problemreductions-cli/src/cli.rs | Added Completions command and --hops/--direction flags to Show command |
| problemreductions-cli/src/main.rs | Added dispatch for completions command and updated show command signature |
| problemreductions-cli/src/commands/graph.rs | Implemented aligned column layout for list, colors for show and path, and tree rendering for k-neighbor exploration |
| problemreductions-cli/tests/cli_tests.rs | Added 8 integration tests for completions and k-neighbor features |
| Various test files | Formatting improvements (line breaks) for better readability |
| Examples | Minor import reordering for consistency |
| docs/plans/*.md | Added detailed design and implementation plan documents |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
problemreductions-cli/src/output.rs
Outdated
| /// Format an outgoing arrow (green when color is enabled). | ||
| pub fn fmt_arrow_out() -> &'static str { | ||
| // We return static str, so we use ANSI directly for the arrow | ||
| "\u{2192}" | ||
| } | ||
|
|
There was a problem hiding this comment.
The function fmt_arrow_out() is defined but never used in the codebase. This is dead code that should be removed. The code uses fmt_outgoing() with a Unicode arrow character directly instead of calling this function.
| /// Format an outgoing arrow (green when color is enabled). | |
| pub fn fmt_arrow_out() -> &'static str { | |
| // We return static str, so we use ANSI directly for the arrow | |
| "\u{2192}" | |
| } |
There was a problem hiding this comment.
Removed fmt_arrow_out() dead code.
CLI Output Examples
|
- Remove unused `fmt_arrow_out()` dead code (Copilot review) - Deduplicate `find_node_index()` by delegating to existing `lookup_node()` - Extract table formatting into reusable `format_table()` helper in output.rs - Remove `completions` command and `clap_complete` dependency (manual setup not useful) - Update CLI documentation with new table output and k-neighbor exploration examples Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Shell argument is now optional — auto-detects from $SHELL env. Setup is just one line: eval "$(pred completions)" Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Custom ProblemNameParser provides all registered problem names and aliases as completion candidates while still accepting any string (so MIS/UnitDiskGraph variant syntax works). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Makes direction immediately clear: → for outgoing, ← for incoming. Both arrows use green for visual consistency. Removes unused fmt_incoming() function. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The target problem is already in the path file, so --to is redundant. Now: pred reduce problem.json --via path.json -o reduced.json Either --to or --via must be provided; error if neither is given. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use consistent Problem/Solver/Solution/Evaluation format for both direct problem solving and reduction bundle solving. Bundle solver shows "via <target>" in solver description. Add hint about -o flag for JSON output with intermediate results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move the -o hint eprintln to after emit_with_default_name so the hint appears at the last line of terminal output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Suppress the "Hint: use -o to save full solution details as JSON." message when stderr is piped, so scripts and non-interactive usage are not cluttered with the hint. Interactive terminal users still see it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When solving a non-ILP problem with the ILP solver, the human text output now shows "Solver: ilp (via ILP)" to indicate that auto-reduction occurred. Previously this information was only visible in JSON output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add a -q/--quiet global flag that suppresses all informational messages on stderr (hints, "Wrote..." messages, summary messages). Only errors still go to stderr in quiet mode. This enables clean scripting usage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously `pred create MIS --edges 0-1,1-2` printed "Created MaximumIndependentSet instance" but discarded the actual data. Now it prints the problem JSON to stdout, consistent with how `reduce` works and enabling piping to other commands. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add "Did you mean ...?" suggestions when a problem name is not recognized, using Levenshtein edit distance. All "Unknown problem" error sites now also suggest running `pred list`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Support random Erdos-Renyi graph generation for graph-based problems via `pred create <PROBLEM> --random --num-vertices N [--edge-prob P] [--seed S]`. Uses a simple LCG PRNG with no external dependencies. Supported for MIS, MVC, MaxCut, MaxClique, MaximumMatching, MinimumDominatingSet, SpinGlass, KColoring, and TravelingSalesman. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nsistency Remaining changes from CLI UX improvement plan: - P4: export-graph uses global -o flag instead of positional arg - P7: accept - for stdin in solve, evaluate, reduce - P2: human-readable reduce output by default, --json flag for raw JSON - F1: new inspect command for problem/bundle introspection Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…commands
Split neighbor exploration out of `pred show` into dedicated subcommands:
- `pred to MIS --hops 2` for outgoing neighbors
- `pred from QUBO --hops 1` for incoming neighbors
Tree output now shows variant-level information (e.g., `MIS {graph=SimpleGraph, weight=i32}`)
instead of just problem names. The `pred show` command is simplified to only inspect
problem details (variants, fields, reductions).
Resolves H2 from the CLI UX improvements audit.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- P8: Support `pred create Factoring --target 15 --bits-m 4 --bits-n 4` with all three flags required (replaces unhelpful bail message) - H3: Add `--timeout <seconds>` to `pred solve` using thread+channel pattern (default 0 = no limit, process exits on timeout) - Add 6 CLI tests for Factoring creation and timeout behavior - Update cli-demo, docs, and audit file Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 37 out of 38 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/rules/graph.rs
Outdated
| /// Find the NodeIndex for a specific (name, variant) pair. | ||
| pub fn find_node_index( | ||
| &self, | ||
| name: &str, | ||
| variant: &BTreeMap<String, String>, | ||
| ) -> Option<NodeIndex> { | ||
| self.lookup_node(name, variant) | ||
| } | ||
|
|
||
| /// Get neighbors of a node in a specific direction. | ||
| pub fn neighbor_indices(&self, idx: NodeIndex, dir: petgraph::Direction) -> Vec<NodeIndex> { | ||
| self.graph.neighbors_directed(idx, dir).collect() | ||
| } | ||
|
|
||
| /// Get the problem name for a node index. | ||
| pub fn node_name(&self, idx: NodeIndex) -> &str { | ||
| self.nodes[self.graph[idx]].name | ||
| } | ||
|
|
||
| /// Get the variant map for a node index. | ||
| pub fn node_variant(&self, idx: NodeIndex) -> &BTreeMap<String, String> { | ||
| &self.nodes[self.graph[idx]].variant | ||
| } |
There was a problem hiding this comment.
find_node_index/neighbor_indices/node_name/node_variant expose petgraph types (NodeIndex, petgraph::Direction) in the public problemreductions API. This couples downstream users to the exact petgraph version and makes future refactors harder. Consider keeping these pub(crate) and adding a higher-level API for tree building (e.g., returning neighbors with parent links) so the CLI doesn’t need to depend on graph internals.
- Add fmt_node() as single source of truth for "bold name + plain variant" - Move neighbor tree BFS from CLI into ReductionGraph::k_neighbor_tree() - Add NeighborTree type to core library - Remove petgraph-exposing helpers (find_node_index, neighbor_indices, etc.) - Remove petgraph dependency from CLI crate - Fix path header not formatting names as bold Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Latest changes (902d31c)Addresses review feedback: 1. Unified name+variant formattingAdded Fixed: 2. Move tree-building into core library (Copilot review item)
3. Removed dimming on aliasesAliases in All 93 CLI tests + 1506 lib tests pass, clippy clean. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All commands now support --json to print JSON to stdout. Previously only `create` (always JSON) and `reduce` (per-command --json) did. - Add `--json` as a global CLI flag on OutputConfig - Update emit_with_default_name to handle -o / --json / human-text - Remove per-command --json from ReduceArgs (now global) - Wire path and path --all through emit or --json branch - Update docs and after_help Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Comprehensive CLI UX improvements based on systematic analysis of pitfalls, missing features, and HCI violations (plan:
docs/plans/2026-02-19-cli-ux-improvements.md).Pitfall Fixes
createwithout-onow prints JSON to stdout (data no longer lost)reduceshows human-readable summary by default,--jsonflag for raw JSONexport-graphuses global-oflag instead of positional arg (consistency)Solver: ilp (via ILP))-for stdin insolve,evaluate,reduce(enables piping)New Features
pred inspectcommand for problem/bundle introspection (type, size, solvers, reductions)-q/--quietflag to suppress informational stderr messagespred create --randomfor random graph instance generation (Erdos-Renyi model)HCI Improvements
Additional
cli-demoMakefile target for end-to-end CLI testingTest plan
make test— all tests passmake clippy— no warningsmake fmt-check— formatting cleancreate | solve -,create | evaluate -,create | reduce -,create | inspect -🤖 Generated with Claude Code