Skip to content

feat(query): per-project config.json defaults for budget/depth (#1654)#1664

Open
TPAteeq wants to merge 2 commits into
Graphify-Labs:v8from
TPAteeq:feat/per-project-query-config
Open

feat(query): per-project config.json defaults for budget/depth (#1654)#1664
TPAteeq wants to merge 2 commits into
Graphify-Labs:v8from
TPAteeq:feat/per-project-query-config

Conversation

@TPAteeq

@TPAteeq TPAteeq commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #1654

What

Adds an optional per-project config sidecar so graphify query defaults for
budget 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=2 passed as a literal into both _query_graph_text(...) and
querylog.log_query(...)), and the query command had no --depth flag at
all — depth was not overridable from the CLI.

Config file shape

Location: graphify-out/config.json (honours the GRAPHIFY_OUT override, same
as every other sidecar). Documented shape — a nested query object:

{ "query": { "default_budget": 4000, "default_depth": 3 } }

Flat top-level keys are also accepted for convenience, and either spelling
works (default_budget/default_depth or bare budget/depth):

{ "budget": 4000, "depth": 3 }

When both a nested and a flat value are present, the nested query object
wins. Only positive integers are honoured.

Precedence

built-in default  <  graphify-out/config.json  <  CLI flag
  • No config, no flag → unchanged behavior (budget 2000, depth 2).
  • Config present → its values seed budget/depth before flag parsing.
  • A CLI flag (--budget N, --depth N, or the --budget=N/--depth=N form)
    always overrides the config.

Changes

  • graphify/paths.py — new query_config_defaults() reader. A missing
    file, 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 — seed budget/depth from the config before the
    arg loop; add --depth N / --depth=N parsing to the query command; use
    the resolved depth in both the _query_graph_text(...) and
    querylog.log_query(...) calls (replacing the literal 2s); update the
    usage line and --help block to document --depth and the config file.

This also resolves a latent inconsistency: the CLI forced depth=2 while
serve._query_graph_text's own default is depth=3. Rather than silently
change behavior, depth is now explicit and configurable — the effective CLI
default stays 2, but users can raise it via config or --depth. No changes
to 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 via main(): config sets budget/depth
    and they reach both _query_graph_text and log_query; a CLI flag overrides
    the config; absence of config → current defaults (2000/2); malformed config →
    falls back without error.

Run:

uv run python -m pytest tests/test_query_cli.py tests/test_paths.py tests/test_querylog.py -q

Result: 65 passed. (Broader related run — test_serve.py included — 141 passed.)

Notes

TPAteeq and others added 2 commits July 5, 2026 00:01
…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>
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.

Feature: per-project config for query defaults (budget, depth)

1 participant