feat(query): per-project config.json defaults for budget/depth (#1654)#1664
Open
TPAteeq wants to merge 2 commits into
Open
feat(query): per-project config.json defaults for budget/depth (#1654)#1664TPAteeq wants to merge 2 commits into
TPAteeq wants to merge 2 commits into
Conversation
…ify-Labs#1654) Read optional query defaults from graphify-out/config.json and seed the query CLI's budget/depth before flag parsing, so CLI flags still override. Adds a --depth flag to the query command (it had none), which also makes the latent CLI-forced-depth-2 vs library-default-3 gap explicit and tunable. The reader (graphify.paths.query_config_defaults) accepts a nested {"query": {"default_budget": N, "default_depth": N}} object or flat keys, and degrades to built-in defaults (budget 2000, depth 2) on a missing, unreadable, malformed, or ill-typed config so a bad file never crashes a query. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… defaults (Graphify-Labs#1654 follow-up) Review follow-up on the per-project query config feature. - The new query `--depth` flag now rejects non-positive values (`--depth 0`, `--depth -1`) with a clean exit-1 `error: --depth must be a positive integer`, matching the config reader which already rejected `depth<=0`. A non-integer value still errors like the affected command (`--depth must be an integer`). `--budget` is left as-is (out of scope). - `query_config_defaults` now coerces a whole-valued float (`4000.0` -> `4000`) from a hand-written config, while still rejecting a fractional float (`4000.5`), bool, string, null, and non-positive values. - Tests: `--depth notanint`/`0`/`-1` rejected and trailing `--depth` handled gracefully (test_query_cli.py); whole-float accepted / `4000.5` rejected and absolute-`GRAPHIFY_OUT` config resolution (test_paths.py). - CHANGELOG: `## Unreleased` entry for the feature (Graphify-Labs#1654, thanks @Ns2384-star). Defaults with no config and no flags stay budget 2000 / depth 2. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #1654
What
Adds an optional per-project config sidecar so
graphify querydefaults forbudget and depth can be set once per repo instead of being retyped on
every invocation. CLI flags still win.
Previously both values were hardcoded in the query handler (
budget = 2000,and
depth=2passed as a literal into both_query_graph_text(...)andquerylog.log_query(...)), and thequerycommand had no--depthflag atall — depth was not overridable from the CLI.
Config file shape
Location:
graphify-out/config.json(honours theGRAPHIFY_OUToverride, sameas every other sidecar). Documented shape — a nested
queryobject:{ "query": { "default_budget": 4000, "default_depth": 3 } }Flat top-level keys are also accepted for convenience, and either spelling
works (
default_budget/default_depthor barebudget/depth):{ "budget": 4000, "depth": 3 }When both a nested and a flat value are present, the nested
queryobjectwins. Only positive integers are honoured.
Precedence
--budget N,--depth N, or the--budget=N/--depth=Nform)always overrides the config.
Changes
graphify/paths.py— newquery_config_defaults()reader. A missingfile, unreadable file, malformed JSON, wrong top-level type, or
non-positive/non-integer values all degrade to built-in defaults, so a bad
config can never crash a query.
graphify/__main__.py— seedbudget/depthfrom the config before thearg loop; add
--depth N/--depth=Nparsing to thequerycommand; usethe resolved
depthin both the_query_graph_text(...)andquerylog.log_query(...)calls (replacing the literal2s); update theusage line and
--helpblock to document--depthand the config file.This also resolves a latent inconsistency: the CLI forced
depth=2whileserve._query_graph_text's own default isdepth=3. Rather than silentlychange behavior, depth is now explicit and configurable — the effective CLI
default stays
2, but users can raise it via config or--depth. No changesto
serve.py.Tests
tests/test_paths.py— unit tests for the reader: nested object, flat keys,partial config, nested-wins-over-flat, missing file, malformed JSON, bad
value types (string/bool/zero/negative rejected), and non-dict top level.
tests/test_query_cli.py— end-to-end viamain(): config sets budget/depthand they reach both
_query_graph_textandlog_query; a CLI flag overridesthe config; absence of config → current defaults (2000/2); malformed config →
falls back without error.
Run:
Result: 65 passed. (Broader related run —
test_serve.pyincluded — 141 passed.)Notes