Skip to content

feat(cli): --json on five more paid leaves; tools preference names its next step (#94) - #1668

Open
napetrov wants to merge 1 commit into
intel:mainfrom
napetrov:feat/cli-json-paid-2
Open

napetrov wants to merge 1 commit into
intel:mainfrom
napetrov:feat/cli-json-paid-2

Conversation

@napetrov

@napetrov napetrov commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Part of #94 (F2 --json slice 2). #94 stays open.

Summary

Adds --json (the cli_output.v1 document) to five paid leaves, and closes the #1581 nit where a refused
tools preference path after the model calls exited 2 with an empty next.

Leaf Dry run (--dry-run) Stop (exit 3 / exit 1) Input error next
skill novelty analyze estimate, complete exit 3: budget_stopped, partial record kept (artifacts null); exit 1 after a failed call: partial, file kept --help
catalog routing estimate, complete exit 3 / exit 1: the saved result, budget_stopped or partial --help
skill sensitivity estimate, complete exit 3 / exit 1: the saved result, budget_stopped or partial --help
eval questions analyze estimate, complete refusal before the first call: budget_stopped. Cap reached mid-run: failed, no report, cost kept --help
eval questions review estimate, complete refusal before the first call: budget_stopped. Cap reached with reviews saved: budget_stopped with the saved reviews. None saved: failed --help
tools preference (nit) n/a refused --out/--items-out after the calls: exit 2, now names --help --help

Kept rows: a success prints no next (the five are in LEAVES_WITHOUT_NEXT_BY_DESIGN). --json is a new
flag on five leaves: docs/reference/cli-interface.json regenerated (make cli-snapshot).

stop_document takes an explicit reason: an int-coded stop (SystemExit(3)) reads "the run stopped (exit 3)"
instead of "3", and a stop with no kept result is failed, not partial.

Evidence

  • tests/test_cli_json_novelty.py (new): dry-run document and no file written; input error names --help;
    budget stop keeps cost and exits 3; finished run with a failed call is partial; spend cap inside the run
    is documented as the stop it is; questions analyze dry run, CLI-login refusal, and a cap reached mid-run
    (failed, cost kept); sensitivity dry run; int-coded stop reason; stop with no result is failed; a write
    failing after the calls keeps their cost (wrapper and through cli.main: one document, exit 5); a finished
    run's cost includes the --judge2 regrade's calls; a skill sensitivity with a failed saved result.
  • tests/test_cli_json_paid.py: the tools preference post-call path assertion now requires the help step
    (was next == []).
  • tests/test_cli_output.py: five leaves added to the next-step sets.
  • Status mapping of catalog routing / skill routing documents: unit test of _emit_saved (exit 3 budget, exit 1 partial via PartialStop(msg, 1)).
  • No dedicated CLI-level test yet for eval questions review --json or catalog routing --json; the surface and
    next-step sets cover them.
  • Affected test files green (684 passed); mypy and ruff clean on the changed files; full suite run with the
    API environment variables unset and clients mocked.

Merge Danger

  • _emit_analyze and the other wrappers run the command under quiet_stdout(): human output moves to stderr
    only with --json. Without the flag the path is unchanged.
  • cli.py exit-2 fallback: a leaf marked input_help_next now gets the --help step on every exit-2 input
    error, not only the five leaves in this PR (the --json leaves already had it; this makes it general).
  • print_estimate_only now returns its estimate dict (was None); only the analyze wrapper reads it.
  • skill routing --json dry run now emits an estimate document (was data: null). Its stop documents now take
    the status from the exit code (exit 3 budget_stopped, exit 1 partial), and reason is the full stop message;
    before, a no_price stop (exit 3) read partial.
  • A write that fails after the paid calls (skill novelty analyze, catalog routing) now prints one document
    that keeps the calls' cost (failed, or input with the help step for exit 2), then exits as before.
  • cli.py crash handler (exit 5): it no longer prints a second document when the leaf already printed its own
    (cli_output.printed()), so stdout keeps one cli_output.v1 document.
  • skill sensitivity with a saved result of status: failed (every selector call failed) prints a failed document.
  • eval questions analyze exit 2 after its calls (unwritable output) is an input document with the help step.
  • catalog routing --json and eval questions review --json have no CLI-level test yet (see Evidence).

🤖 Generated with Claude Code

…s next step (intel#94)

Test-narrowed: the tools preference post-call refusal now names its --help step (the intel#1581 nit), so the old
next == [] expectation is replaced by the help-step asserts; that test now has four asserts where it had three.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Copilot AI balanced review requested due to automatic review settings December 6, 2026 07:41
@napetrov
napetrov requested a review from a team as a code owner December 6, 2026 07:41
@napetrov napetrov added the cli-interface-change Changes dokimi's user-facing CLI surface label Dec 6, 2026
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

CLI interface change detected

This PR changes dokimi's user-facing CLI surface (commands and/or options):

~ `dokimi catalog routing` parameters changed:
    + added option `--json`
~ `dokimi eval questions analyze` parameters changed:
    + added option `--json`
~ `dokimi eval questions review` parameters changed:
    + added option `--json`
~ `dokimi skill novelty analyze` parameters changed:
    + added option `--json`
~ `dokimi skill sensitivity` parameters changed:
    + added option `--json`

Updated on every push; the cli-interface-change label is on while the diff is non-empty.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 84.12698% with 40 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.39%. Comparing base (19e5222) to head (976c1ee).

Files with missing lines Patch % Lines
dokimi/dokimi/commands/questions.py 77.77% 10 Missing and 4 partials ⚠️
dokimi/dokimi/commands/novelty_routing.py 83.05% 8 Missing and 2 partials ⚠️
dokimi/dokimi/commands/skill_sensitivity.py 77.14% 6 Missing and 2 partials ⚠️
dokimi/dokimi/cli_output.py 78.26% 4 Missing and 1 partial ⚠️
dokimi/dokimi/commands/novelty.py 96.22% 1 Missing and 1 partial ⚠️
dokimi/dokimi/spend_preview.py 50.00% 0 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1668      +/-   ##
==========================================
- Coverage   96.44%   96.39%   -0.05%     
==========================================
  Files         585      585              
  Lines       76600    76817     +217     
  Branches    13175    13209      +34     
==========================================
+ Hits        73876    74047     +171     
- Misses       1671     1701      +30     
- Partials     1053     1069      +16     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/novelty_budget.py 97.36% <100.00%> (+0.01%) ⬆️
dokimi/dokimi/commands/novelty_routing_report.py 99.44% <100.00%> (+<0.01%) ⬆️
dokimi/dokimi/commands/routing_parser.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/skill.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/tools.py 96.35% <100.00%> (+0.02%) ⬆️
dokimi/dokimi/spend_preview.py 97.91% <50.00%> (-2.09%) ⬇️
dokimi/dokimi/commands/novelty.py 97.99% <96.22%> (-0.33%) ⬇️
dokimi/dokimi/cli_output.py 94.62% <78.26%> (-5.38%) ⬇️
dokimi/dokimi/commands/skill_sensitivity.py 86.27% <77.14%> (-5.16%) ⬇️
dokimi/dokimi/commands/novelty_routing.py 93.44% <83.05%> (-4.52%) ⬇️
... and 1 more

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Cost reporting loses known spend for mixed priced/unpriced calls and reports zero calls and spend when skill-sensitivity result saving fails.

2 open issues
What changed in this PR

2 new findings. This advances #94 by extending dokimi’s structured CLI output to five more paid commands and addressing the follow-up from #1581.

Changes:

  • Adds --json output for novelty analysis, catalog routing, sensitivity, and question analysis/review.
  • Adds estimate, stop, and failure documents; supplies help steps for input errors.
  • Updates regression tests, the CLI snapshot, and release notes.
File Description
dokimi/​tests/​test_cli_output.py Registers the five commands’ next-step expectations.
dokimi/​tests/​test_cli_json_paid.py Requires help after preference output errors.
dokimi/​tests/​test_cli_json_novelty.py Tests JSON estimates, stops, costs, and failures.
dokimi/​dokimi/​spend_preview.py Exposes estimates and refusals to wrappers.
dokimi/​dokimi/​commands/​tools.py Adds help steps after output-path refusals.
dokimi/​dokimi/​commands/​skill.py Registers novelty analysis JSON output.
dokimi/​dokimi/​commands/​skill_sensitivity.py Emits sensitivity result and estimate documents.
dokimi/​dokimi/​commands/​routing_parser.py Registers routing and sensitivity JSON flags.
dokimi/​dokimi/​commands/​questions.py Wraps question analysis and review output.
dokimi/​dokimi/​commands/​novelty.py Emits novelty documents with run costs.
dokimi/​dokimi/​commands/​novelty_routing.py Adds catalog documents and shared routing emission.
dokimi/​dokimi/​commands/​novelty_routing_report.py Returns routing estimates for JSON output.
dokimi/​dokimi/​commands/​novelty_budget.py Returns novelty dry-run estimates.
dokimi/​dokimi/​cli.py Adds fallback help and prevents duplicate crash documents.
dokimi/​dokimi/​cli_output.py Adds stop and write-failure document helpers.
dokimi/​docs/​reference/​cli-interface.json Records the five new flags.
dokimi/​changelog.d/​20261205_120000_napetrov_cli-json-paid-2.md Documents expanded JSON support and preference help.

Review effort: Balanced

Comment on lines +64 to +65
rolled = roll_up_cost(state["clients"])
return cli_output.cost_of(spent_usd=rolled.get("usd"), calls=rolled.get("llm_calls", 0), cap_usd=args.max_usd)
Comment on lines +38 to +40
except SystemExit as stop:
_emit(args, state, stop)
raise
@exai-bot

exai-bot commented Dec 6, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 1 issue(s) in this PR.

CI at `976c1ee`: 3 failing, 15 passing, 9 skipped

Not fully read: log of Test Linux Python 3.14: longer than 8000000 bytes, only the start was read; log of Test Linux Wheels Python 3.14: longer than 8000000 bytes, only the start was read

One confirmed regression changes the JSON reason for capped skill-routing runs; a small reason override restores the existing contract while keeping exit-based status handling. The other two failing checks have truncated logs without a failure diagnostic, so their causes cannot be determined from the available evidence. Local lint and type checks passed.

Check Status Assessment
Test Linux Python 3.14 failing at step Install the package and run ci/test.py Cause unclear. The available log is truncated at roughly 75% test progress and contains no actual failure diagnostic. It is not possible to attribute this check's failure to the change or to infrastructure.
Test Linux Wheels Python 3.14 failing at step Install the wheel and run ci/test.py Cause unclear. The available wheel-test log is truncated at roughly 75% progress, before any failure summary. There is insufficient evidence to establish whether it shares the confirmed regression in the other test job.
Tests (py3.14) failing at step Run tests Caused by this PR. The new _emit_saved path calls stop_document without a reason override, replacing the prior partial['message'] with the human-readable exit message, including call counts and the output path. This breaks the existing capped-routing JSON reason assertion; overriding the reason only for budget... Fix proposed, not run: novelty_routing.py:292-293.

By label: 1 should fix

Label Location Finding
should fix skill_sensitivity.py:112 Impact: a post-call write failure produces a JSON document claiming zero calls and zero spend, losing the paid run's accounting.
Test notes (2)
  • dokimi/dokimi/commands/novelty.py:41: With stop = exc changed to stop = exc raise, the tests still pass: dokimi/tests/test_cli_json_novelty.py, dokimi/tests/test_cli_json_paid.py, dokimi/tests/test_cli_output.py. If this condition matters, a test should pin it.
  • dokimi/dokimi/commands/novelty_routing.py:126: With except RoutingStopped as stop: done, stopped = stop.result, stop changed to except RoutingStopped as stop: done, stopped = stop.result, stop raise, the tests still pass: dokimi/tests/test_cli_json_novelty.py, dokimi/tests/test_cli_json_paid.py, dokimi/tests/test_cli_output.py, dokimi/tests/test_novelty_routing.py. If this condition matters, a test should pin it.
Review details
  • Commit reviewed: 976c1ee against merge base 19e5222
  • Coverage: 17 files in 3 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 1.28M tokens (993k from cache), 1m14s
  • Tool calls: 99 (71 file_read, 18 code_search, 4 file_read_diff, 3 pr_comments, 1 code_comment, 1 file_find, 1 local_check_results)
  • CLI JSON output infrastructure and documentation: 5 files
  • Novelty JSON output, budgets, and routing: 6 files
  • Paid command JSON output and spend previews: 6 files

"cost": roll_up_cost([selector]),
}
out = save_result(payload, out, result)
state.update(payload=payload, out=out)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · should fix
Impact: a post-call write failure produces a JSON document claiming zero calls and zero spend, losing the paid run's accounting.

Trigger: skill sensitivity ... --json completes selector calls but save_result() raises an OSError (for example, disk full).

Evidence: state is populated only after saving, the wrapper catches only SystemExit, and cli.main's exception fallback builds a document with the default zero cost. Capture the selector/accounting before saving and handle write exceptions with write_failure_document, as the catalog-routing wrapper does; do not advertise an artifact that was not saved.

Fix: Add a regression test forcing the save to fail after mocked paid calls.

Workaround: use a writable destination with sufficient space; there is no accounting recovery in this response once the write fails.

Should fix: A run shows it; it was not judged to be met in ordinary use.

This proof replaces part of the code with stand-ins (monkeypatch): it shows the code path, not the real dependency or platform.

Shown by running: exit 1 (at the head) · exit 1 (at the merge base, which cannot run it) · exit 0 (at the head with the fix)

python -m pytest -q -p no:randomly -p no:cacheprovider tests/test_verify_sensitivity_write_accounting.py

What the proof does: Calls the real sensitivity CLI with a transport supplying priced replies and a simulated disk-full write, and checks that its failure document retains both calls and their cost.

The problem shows as the output sensitivity write failure lost paid accounting.

Script: dokimi/tests/test_verify_sensitivity_write_accounting.py (55 lines).

        assert stopped.value.code == 5
        assert doc['status'] == 'failed' and doc['error']['code'] == 'infra'
>       assert doc['cost']['calls'] == 2 and doc['cost']['spent_usd'] == pytest.approx(0.02), 'sensitivity write failure lost paid accounting'
E       AssertionError: sensitivity write failure lost paid accounting
E       assert (0 == 2)

tests/test_verify_sensitivity_write_accounting.py:53: AssertionError
=========================== short test summary info ============================
FAILED tests/test_verify_sensitivity_write_accounting.py::test_write_failure_retains_paid_accounting
1 failed in 1.15s

@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 6 of 80 small breaks of the lines this PR changes, and the check was not complete

At 976c1ee: 58 caught · 6 missed · 16 inconclusive

Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/commands/novelty_routing.py:67 delete-statement args.cost_clients = [selector] if selector is not None else None → pass 47
dokimi/dokimi/commands/novelty_routing.py:112 return-none payload, out, None → None 34
dokimi/dokimi/commands/novelty_routing.py:136 bump-int 0 → 1 1
dokimi/dokimi/commands/novelty_routing.py:195 delete-statement args.cost_clients = [selector] → pass 41
dokimi/dokimi/commands/novelty_routing.py:276 drop-clause payload.get("lexical") or {} → (payload.get("lexical")) 3
dokimi/dokimi/commands/novelty_routing.py:285 delete-statement summary.update(queries_self_derived=payload["queries_self_derived"], → pass 2

Not the whole picture:

  • 217 more breaks of covered changed lines were over the limit and not tried
  • 244 candidate test files were not run
  • 77 changed lines were not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

Comment on lines +292 to +293
cli_output.emit(cli_output.stop_document(kind, payload, stopped, limit_code=cli_output.limit_code_of(payload),
**fields))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CI check Tests (py3.14) fails: The new _emit_saved path calls stop_document without a reason override, replacing the prior partial['message'] with the human-readable exit message, including call counts and the output path. This breaks the existing capped-routing JSON reason assertion; overriding the reason only for budget exits preserves the new failed-call status behavior. Proposed fix, not run by the bot.

Suggested change
cli_output.emit(cli_output.stop_document(kind, payload, stopped, limit_code=cli_output.limit_code_of(payload),
**fields))
reason = (payload.get("partial") or {}).get("message") if stopped.code == 3 else None
cli_output.emit(cli_output.stop_document(kind, payload, stopped, limit_code=cli_output.limit_code_of(payload),
reason=reason, **fields))

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-interface-change Changes dokimi's user-facing CLI surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants