Skip to content

feat(cli): simplify the path CLI#18

Closed
eliothedeman wants to merge 3 commits intomainfrom
eliot/busy-babbage-fa7bdc
Closed

feat(cli): simplify the path CLI#18
eliothedeman wants to merge 3 commits intomainfrom
eliot/busy-babbage-fa7bdc

Conversation

@eliothedeman
Copy link
Copy Markdown
Collaborator

@eliothedeman eliothedeman commented Apr 16, 2026

Summary

Simplify the path CLI by collapsing query subcommands, unifying stdin conventions, and extracting shared I/O helpers. Net diff in the refactor commit: −444 / +338 LOC.

Version bump deferred — publishing is manual via scripts/release.sh, so the toolpath-cli version stays at 0.3.0 for now and the CHANGELOG entry will land with the eventual publish commit.

Changes

Breaking (minor)

  • query subcommands collapsed into a single command with composable flags:
    • path query ancestors --input f.json --step-id s3path query -i f.json --ancestors-of s3
    • path query dead-ends --input f.jsonpath query -i f.json --dead-ends
    • path query filter --input f.json --actor human:path query -i f.json --actor human:
  • validate --input is now optional. Omit it or pass - to read from stdin.

Non-breaking

  • Unified stdin convention: render, merge, query, validate all accept -i - (or omit -i) to read from stdin.
  • New io module centralizes document read/write, stdin/stdout handling, and pretty-print — replaces ad-hoc fs::read_to_string + Document::from_json + to_json_pretty ternaries duplicated across six commands.
  • New source::require_native helper centralizes WebAssembly guard messaging. Emscripten guards refactored from in-body #[cfg] branches to function-level splits — native bodies no longer indented under a cfg(not(emscripten)) block.

Preserved

  • haiku command and rand dependency — CTO mandate.
  • track's 8 sub-ops untouched. Internal refactor (split cmd_track.rs into a module) flagged for a follow-up PR.
  • list, derive, render, merge, validate keep their existing command surfaces.

Test plan

  • cargo test --workspace — all 161 CLI tests pass (137 unit + 12 integration + 12 snapshot), workspace-wide green.
  • cargo clippy --workspace -- -D warnings — clean.
  • Smoke: derive git | validate -i - — stdin round-trip works.
  • Smoke: all three query forms (--ancestors-of, --dead-ends, --actor) return expected results.
  • Smoke: all 12 example JSON docs still validate.
  • Smoke: path haiku still prints verse (CTO-mandated).

Deferred

Internal refactor of cmd_track.rs (2,433 LOC → src/track/{state,session_io,ops}.rs) is a worthwhile follow-up but was scoped out of this PR — it needs a deeper read before committing.

- Collapse `query` subcommands into single command with composable flags
  (`--ancestors-of`, `--dead-ends`, filter flags). Old subcommand forms
  replaced.
- Unify stdin convention across `render`, `merge`, `query`, `validate`:
  omit `-i` or pass `-` to read from stdin. `validate --input` now optional.
- Extract shared `io` module for document read/write and pretty-print,
  replacing ad-hoc `fs::read_to_string` + `Document::from_json` + pretty
  ternaries duplicated across six commands.
- Extract `source::require_native` helper and refactor emscripten guards
  from in-body `#[cfg]` branches to function-level splits — native bodies
  no longer indented under a `cfg(not(emscripten))` block.
- Preserve `haiku` command per CTO mandate.

Net diff: -444/+338 LOC. All 161 CLI tests pass; clippy clean.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 16, 2026

🔍 Preview deployed: https://d7073ccd.toolpath.pages.dev

Version bump deferred — publishing is manual via scripts/release.sh,
so we don't need to bump here. The 0.4.0 entry in CHANGELOG can land
with the eventual publish commit.
@eliothedeman eliothedeman changed the title feat(cli): simplify toolpath-cli to 0.4.0 feat(cli): simplify the path CLI Apr 16, 2026
Copy link
Copy Markdown
Contributor

@akesling akesling left a comment

Choose a reason for hiding this comment

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

One design consideration/concern, otherwise LGTM

Comment thread crates/toolpath-cli/src/cmd_query.rs Outdated
let (steps, _) = extract_steps(&doc);

fn apply_filters<'a>(
steps: &'a [toolpath::v1::Step],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Won't this mean that actor entries, etc. won't be filtered as we're operating on slice step only and not other sections?

Is that what we were doing already? If so, we can punt but maybe we should fix it while we're here? Up to you.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch — yes, that was pre-existing behavior (only the first inline path in a Graph was inspected). Fixed in 3d3ca65: collect_paths now returns a view per inline path, and each of --dead-ends, --ancestors-of, and the filter flags iterate all views and union results (deduped by step id). Added regression tests for the multi-path Graph case.

Previously `query` on a Graph only inspected the first inline path —
subsequent paths' steps were invisible to `--dead-ends`, `--ancestors-of`,
and filter flags. This was pre-existing behavior but the reviewer
flagged it as worth fixing while we're here.

- Replace `extract_steps` (returned one slice) with `collect_paths`
  which returns a view per inline path.
- `collect_ancestors` / `collect_dead_ends` / `collect_filtered` each
  iterate all views and union results, deduplicating by step id.
- Rewrite filter logic as a single predicate over steps instead of three
  intersect-by-id passes, trimming allocations.
- Add regression tests for the multi-path Graph case: dead-ends union,
  filter union, ancestors-of lookup across paths, duplicate-id dedup.
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.

2 participants