feat(cli): add path query (jaq over the cache) and path kind#114
Open
benbaarber wants to merge 2 commits into
Open
feat(cli): add path query (jaq over the cache) and path kind#114benbaarber wants to merge 2 commits into
path query (jaq over the cache) and path kind#114benbaarber wants to merge 2 commits into
Conversation
`path query` loads every step in the local cache into one JSON array and
transforms it with an in-process jaq (pure-Rust jq) filter — selection,
projection, ranking, grouping, and top-N are all jaq. Each array element
wraps a Toolpath step (step/change/meta verbatim) with `cache_id`, `path`
(the parent path's id/base/meta), and `dead_end` (off the head's ancestry).
Scope flags choose which docs load: `--source`/`--id`/`--input` (file
selection) and `--project`/`--kind` (content scoping, semver-prefix kind
match). Output mirrors jq: pretty on a TTY, compact when piped (`-c`), raw
strings with `-r`. Malformed cache docs are skipped with a stderr warning;
empty results exit 0, filter errors exit 1.
`path kind` is the cold-start companion: lists the bundled kind specs, or
prints a kind's schema.json (the field reference for writing filters).
`--kind` and `path kind` share one semver-prefix selector, sourced from a
new shared `kinds` module that `schema.rs` now also reads.
BREAKING (pre-1.0): the former `path query` subcommands change. `ancestors`
moves to `path p query ancestors`; `dead-ends`/`filter` become jaq forms
(`map(select(.dead_end))`, `map(select(.step.actor | startswith("agent:")))`).
path-cli 0.14.0 -> 0.15.0; adds jaq-core/jaq-std/jaq-json.
|
🔍 Preview deployed: https://00ab4cfa.toolpath.pages.dev |
…ache `path query` no longer loads every cached step into one array up front. The executor reads the filter — it parses the jaq into jaq's own AST and picks an execution plan: - **PerFileStream** — element-wise filters (`.[] | g`, distributive for any g) run per document and print as they go; nothing accumulates. - **Decompose** — algebraic aggregations run the filter per file, concatenate the per-file outputs, then run a derived combine over them: `map` → `add`, top-N `sort_by(k) | .[:N]` → `add | sort_by(k) | .[:N]`, `length`/`add` → `add`, `min`/`max` → themselves. A global top-N is a subset of the per-file top-Ns, so the merge is exact and bounded (files × N). - **Slurp** — the always-correct fallback for anything not provably decomposable (`group_by`, `unique`, `as`-bindings, `reduce`, …). Still lean: values are held once, with no whole-cache byte buffer. Recognition is conservative (a non-distributive prefix such as `unique` before a top-N slurps), so the planner never changes an answer. Unit tests assert the streamed output equals the slurp output byte-for-byte across element-wise, top-N, and scalar-reduction filters; integration tests confirm cross-file top-N and sums end to end. `TOOLPATH_QUERY_EXPLAIN=1` prints the chosen plan to stderr. No user-facing flag — it's automatic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
path query— loads every step in the local cache into one JSON array and transforms it with an in-process jaq (pure-Rust jq) filter (selection, projection, ranking, grouping, top-N). Each element wraps a Toolpath step (step/change/metaverbatim) withcache_id,path, anddead_end. Scope flags pick which docs load (--source/--id/--input,--project/--kind); output mirrors jq (-ccompact,-rraw).Also adds
path kind— the cold-start companion that lists bundled kind specs or prints a kind'sschema.json(the field reference for writing filters).Full design and rationale:
docs/superpowers/specs/2026-06-22-path-query-command-design.mdBreaking (pre-1.0):
path query ancestors→path p query ancestors;dead-ends/filterare now jaq forms (map(select(.dead_end)),map(select(.step.actor | startswith("agent:")))).path-cli0.14.0 → 0.15.0; addsjaq-core/jaq-std/jaq-json.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.