Skip to content

feat(cli): --json on the guarded paid leaves (F2) - #1581

Merged
napetrov merged 27 commits into
intel:mainfrom
napetrov:feat/cli-json-paid-1
Dec 6, 2026
Merged

napetrov merged 27 commits into
intel:mainfrom
napetrov:feat/cli-json-paid-1

Conversation

@napetrov

@napetrov napetrov commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Part of #94 (F2, --json on the guarded paid leaves). #94 stays open.

Summary

Adds --json (cli_output.v1) to three paid leaves that already have --dry-run and --max-usd:

  • eval personas discover
  • eval skill-coverage
  • tools preference

skill routing and repo hits judge already have --json on main and are not touched. skill novelty analyze and catalog routing are left for a follow-up PR.

What the document says

  • Dry run: status complete, data.estimate (personas, skill-coverage) or the item counts (tools), cost.calls 0, cost.spent_usd 0, and cost.estimate_kind null.
  • Refused cap (exit 3): status budget_stopped, limits[0].code identifies the cap (max_usd or max_calls), reason = the refusal text. Exit 3 is not a cli_output error code, so there is no error object.
  • Real run: status complete. data is the leaf's payload. For tools preference this is the saved tool_preference artifact, schema_version included. artifacts.out names the report, including its actual path under --out-dir. artifacts.copy names a successful --out copy when run directories are enabled. Tool preference and skill coverage meter the calls. The envelope keeps known spend when some calls are unpriced, with a null remainder. For personas the cost is the list-price estimate of the one generation call, because generation is not metered until fix(cost): judge_metrics skips cache replays; one Spend accumulator for totals #1183.
  • Cap reached mid-run (skill-coverage): status budget_stopped with limits[0].code max_usd or max_calls, exit 1, as before. The exit code is unchanged; the document only adds the status.
  • Failed run (tools preference): status failed, or budget_stopped with exit 3 when calls were skipped: at the cap, or because a call had no list price (the max_usd limit explains that the missing price prevented cap enforcement). The payload stays under data.
  • Input error (exit 2): error.code input, and next holds the leaf's own --help as a free step, for errors raised as InputError (bad arguments, an unreadable input, an unwritable tool preference output, or an unwritable analysis file (<product>_analysis.json, saved with --save-analysis) before any paid call). This is opt-in per leaf through the input_help_next default, so no other leaf's input-error contract changes.
  • Write failure after the paid calls: an unwritable --out is error.code input (exit 2) with cost still holding what the calls spent, and next empty. A rejected save is status failed (exit 1) and retains the call cost. Malformed persona replies still emit the fallback infra document without recording the generation call. The error handling is tracked in fix(personas): eval personas discover exits 1 when its model call fails (#1555) #1583.

Evidence

  • tests/test_cli_json_paid.py exercises the CLI with model calls mocked. It tests the no-client dry runs, known spend when coverage receives mixed pricing, output-path errors, and schema rejection. It also covers the default tool preference report, a run directory, a copy, a budget stop, failed writes, and the skill-coverage call limit. Plain-mode schema rejection and persona output paths are also covered.
  • tests/test_cli_output.py: the three leaves are added to the invariant set that has no next by design.
  • docs/reference/cli-interface.json includes the three new --json entries.

Merge danger

  • cli.py _exit_with_document now adds next only when a leaf sets input_help_next. The three leaves set it. Nothing else changes.
  • cli.py main: an InputError no longer prints a second document when the leaf already printed its own (the skill-coverage write failure does).
  • tools preference records each published path. An output failure preserves call cost and any report already saved to the run directory.
  • cli_output.py adds cost_of and emit_estimate; both are new, and no existing caller changes.

🤖 Generated with Claude Code

eval personas discover, eval skill-coverage and tools preference already
had --dry-run and --max-usd. Each now also takes --json and prints one
cli_output.v1 document: the dry-run estimate (or item counts), a
--max-usd refusal as budget_stopped with exit 3, the success payload
under data, and an input error with the leaf's --help as its next step.

The input-error next is opt-in per leaf (input_help_next), so no other
leaf's contract changes. Part of intel#94.

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

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

Unpriced usage causes cost reporting to erase known spend, including in budget-stop and write-failure documents.

1 open issue
What changed in this PR

1 new finding.

Advances #94 F2 by adding structured JSON output to three guarded paid CLI commands.

Changes:

  • Adds --json for persona discovery, skill coverage, and tool preference.
  • Reports estimates, results, budget stops, and failures, preserving cost information after write failures.
  • Updates regression tests, CLI reference, documentation, and changelog.
File Description
dokimi/​tests/​test_personas_discover_output.py Updates write-error assertions.
dokimi/​tests/​test_input_refusal_exit_sites.py Adjusts the exit-site baseline.
dokimi/​tests/​test_cli_output.py Registers the three JSON leaves.
dokimi/​tests/​test_cli_json_paid.py Tests paid-command JSON outcomes.
dokimi/​scripts/​growth_baseline.json Removes the reduced function’s exception.
dokimi/​dokimi/​commands/​tools.py Adds tool-preference JSON output.
dokimi/​dokimi/​commands/​skill_coverage.py Adds skill-coverage JSON output.
dokimi/​dokimi/​commands/​personas.py Adds persona-discovery JSON output.
dokimi/​dokimi/​cli.py Adds help steps and avoids duplicate documents.
dokimi/​dokimi/​cli_output.py Adds cost and estimate helpers.
dokimi/​docs/​tool-preference.md Documents JSON output.
dokimi/​docs/​reference/​cli-interface.json Records the new flags.
dokimi/​changelog.d/​20261203_120000_napetrov_cli-json-paid.md Announces JSON support.

Review effort: Balanced

@exai-bot

exai-bot commented Dec 3, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 18 selected item(s).

CI at 0f30589: 21 passing, 4 skipped.

Review details
  • Commit reviewed: 0f30589 against merge base b1e1d6e
  • Coverage: 18 files in 5 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 683k tokens (404k from cache), 42s
  • Tool calls: 63 (46 file_read, 7 code_search, 4 local_check_results, 3 pr_threads, 1 ci_log_search, 1 ci_status, 1 file_read_diff)
  • Shared CLI JSON output and paid-command regression coverage: 7 files
  • Persona discovery output: 2 files
  • Skill coverage and treatment evaluation: 2 files
  • Tool preference commands and JSON output: 4 files
  • CLI JSON changelog and interface documentation: 3 files

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

CLI interface change detected

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

~ `dokimi eval personas discover` parameters changed:
    + added option `--json`
~ `dokimi eval skill-coverage` parameters changed:
    + added option `--json`
~ `dokimi tools preference` parameters changed:
    + added option `--json`

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

@codecov-commenter

codecov-commenter commented Dec 3, 2026 •

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 98.29787% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.44%. Comparing base (5225c2a) to head (5fb6417).

Files with missing lines Patch % Lines
dokimi/dokimi/commands/tools.py 95.34% 2 Missing and 2 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1581    +/-   ##
========================================
  Coverage   96.44%   96.44%            
========================================
  Files         575      575            
  Lines       75717    75872   +155     
  Branches    13046    13076    +30     
========================================
+ Hits        73022    73172   +150     
  Misses       1646     1646            
- Partials     1049     1054     +5     
Files with missing lines Coverage Δ
dokimi/dokimi/cli_output.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/personas.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/skill_coverage.py 98.95% <100.00%> (+1.02%) ⬆️
dokimi/dokimi/commands/tools.py 96.32% <95.34%> (+0.13%) ⬆️

... 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.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Not a clean result: some breaks or tests were left out

At 5fb6417: 74 caught · 0 missed · 6 inconclusive

This is not a clean result:

  • 197 more breaks of covered changed lines were over the limit and not tried
  • 250 candidate test files were not run
  • 27 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.

@vlad-perevezentsev vlad-perevezentsev left a comment

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.

🟡 Changes needed · reviewed 7160be4

To fix: some --json documents still lose the cost of paid calls or say "see stderr" for an input error (line comments); the doc and test gaps there are smaller.

✅ make ci-local --offline: 34,308 passed, changed lines 97% covered · ⚠️ 1 failure (eval score ragas fault contract) fails on the base too · ✅ the new tests pass 20 random orders · ✅ strict docs build

The three leaves now print one document on every exit, and the write failures after the call keep their cost.

Agreed with @Copilot: the known spend is lost when a call has no price.

Comment thread dokimi/dokimi/commands/tools.py Resolved
Comment thread dokimi/dokimi/commands/personas.py Resolved
Comment thread dokimi/dokimi/cli_output.py Resolved
Comment thread dokimi/docs/tool-preference.md Resolved
…81-dokimi-1581.Pne3Vc

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_EfDc
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_IkOj
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_IkO6
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_IkPB
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_IkPG
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_IkPL
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
…1.Pne3Vc

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRR_kwDOVBg7g88AAAABb7eAqg
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
…1.Pne3Vc

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
…1.Pne3Vc

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_EfDc

Thread: PRRT_kwDOVBg7g86_IkPB
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_EfDc
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
…581-dokimi-1581.Pne3Vc

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov

napetrov commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Re: review by vlad-perevezentsev

Some --json documents still lose the cost of paid calls or say "see stderr" for an input error.
Known spend and path errors are fixed. Malformed persona replies track #1583.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

@vlad-perevezentsev vlad-perevezentsev left a comment

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.

🟡 Changes needed · re-checked 4c3836b

To fix: the branch conflicts with current main after #1543 (--out-dir) in commands/tools.py, and --json needs to cover that new path (line comment).

✅ GitHub CI on 4c3836b: 22 jobs pass · ✅ an unwritable --out now gives cannot write /proc/nope/x.json: … with tools preference --help as the next step · ⚠️ git merge origin/main: conflicts in tools.py and tool-preference.md

The earlier points are fixed, and the generation-failure cost is fine to follow #1583.

Comment thread dokimi/dokimi/commands/tools.py Resolved
…json-paid-1

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

# Conflicts:
#	dokimi/docs/reference/cli-interface.json
#	dokimi/docs/tool-preference.md
#	dokimi/dokimi/commands/skill_coverage.py
#	dokimi/dokimi/commands/tools.py
Thread: PRRT_kwDOVBg7g86_urI6

Thread: PRR_kwDOVBg7g88AAAABcPn-Cw
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_urI6

Thread: PRR_kwDOVBg7g88AAAABcPn-Cw
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov

napetrov commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Re: review by vlad-perevezentsev

--json needs to cover that new path
Synced main. 0f30589 covers saved paths and spend.

@antonwolfy antonwolfy left a comment

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.

LGTM. The three leaves print one document on every exit, the cost survives the write failures after the paid calls, and the --out-dir path of tools preference is covered after the merge with main. No findings.

What I ran, on a Linux review host at 0f30589:

  • make ci-local: 38 passed, 0 failed, 16 skipped (matrix legs on other Pythons and org-level checks); 35,902 tests passed, 28 skipped.
  • Read the diff of cli.py, cli_output.py and the three commands against the documents the description lists (dry run, refused cap, mid-run stop, write failures).

Checked, no issues

  • Commits: every non-merge commit has a Signed-off-by.
  • Opt-in next: input_help_next is set only on the three leaves, so no other leaf's input-error document changes.
  • Unpriced calls: skill-coverage and tools preference take spend from the client's meter, so known dollars stay in cost with a null remainder.
  • Persona generation failure: a malformed reply still reports zero calls. The author tracks it in #1583 and the earlier reviewer accepted that.

@vchamarthi vchamarthi left a comment

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.

@napetrov, could you fix the 3 small things I've marked fix before merge (in the line comments) and answer my 2 questions below? I'll approve once that's done.
I'll approve once that's done.

My questions before I approve:

  • --factors , (a comma with no name) is read as no factors: a dry run with --json reports complete, an empty factors list and only the baseline items, while --factors '' gives the default factors. Decide whether a --factors list with no names should be refused like an unknown factor, and say which in --help or the docs.
  • The PR description says the tools --max-usd limit names the unpriced call, but the limit text is a call came back with no price, so --max-usd cannot be enforced and does not say which call. Change the PR description to match the text, or add the unpriced call's item id to the limit text.
Optional, non-blocking (1)
  • dokimi/dokimi/commands/personas.py:148: A persona reply with no personas key exits 5 and reports cost.calls 0, though the paid call was made.

What I checked on 0f30589:

  • When I changed the code on purpose, the tests still passed for 7 of 12 changes, and no test pins these down yet (non-blocking): dokimi/dokimi/cli.py:475 (the handled error is raised again), dokimi/dokimi/commands/personas.py:101 (the handled error is raised again), dokimi/dokimi/commands/skill_coverage.py:164 (the handled error is raised again) and 3 more.
  • The 237 changed tests pass, and fail on main as expected.
  • The full test suite passes with main merged in (40,685 tests), apart from failures main has too.
  • It merges cleanly onto main.

Comment thread dokimi/dokimi/commands/tools.py Resolved
Comment thread dokimi/dokimi/cli_output.py Resolved
Comment thread dokimi/dokimi/commands/personas.py Resolved
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AKf0o
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AKf0q
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g87AKf0t
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRR_kwDOVBg7g88AAAABcd8VMw.b
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov

napetrov commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

Re: review by vchamarthi

Should a --factors list with no names be refused?
Waiting on a decision before I change this: keep --factors , for baseline-only, or exit 2? I recommend exit 2. --factors '' still uses defaults.

The max_usd limit does not identify the unpriced call.
I corrected the description. 5fb6417 documents and tests the limit reason.

A persona reply with no personas key exits 5 and reports cost.calls 0.
Confirmed one invocation and zero reported calls. #1656 tracks keeping the estimate after #1583 lands.

@napetrov
napetrov merged commit 60948d0 into intel:main Dec 6, 2026
25 checks passed
napetrov added a commit to napetrov/dokimi that referenced this pull request Dec 6, 2026
…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>
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.

7 participants