Repository navigation
refactor(commands): share command helpers publicly, one safe filename helper - #1413
Conversation
CLI interface change detectedThis PR changes dokimi's user-facing CLI surface (commands and/or options): ~ `dokimi eval graph` parameters changed:
~ changed option `--extract-model`: type: 'dokimi.commands.repo_hits._judge_ref#f8f456f0565f' -> 'dokimi.commands._shared.judge_ref#2304e1942183'
~ `dokimi repo hits judge` parameters changed:
~ changed option `--judge`: type: 'dokimi.commands.repo_hits._judge_ref#f8f456f0565f' -> 'dokimi.commands._shared.judge_ref#2304e1942183'Updated on every push; the |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1413 +/- ##
==========================================
- Coverage 96.50% 96.48% -0.02%
==========================================
Files 534 535 +1
Lines 71550 71572 +22
Branches 12362 12362
==========================================
+ Hits 69046 69056 +10
- Misses 1530 1536 +6
- Partials 974 980 +6
🚀 New features to boost your workflow:
|
Mutation of changed linesAt 4789d42: 34 caught · 0 missed · 7 inconclusive · 39 not tried in time This is not a clean result:
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
|
OpenCodeReview: Commit 4789d42 was not reviewed. This PR has reached its review limit (6 reviews). CI at `4789d42`: 10 still running, 11 passing, 3 skipped
To review this commit: re-request review from exai-bot in the Reviewers list. Last review (948a3ce): no findingsOpen threads from the bot: 0 |
vchamarthi
left a comment
There was a problem hiding this comment.
@napetrov, could you fix the problem I found and the small thing I've marked fix before merge (in the line comments)? Then push and I'll take another look.
Also holding my approval:
- A check of the change fails on this head.
Optional, non-blocking (1)
dokimi/dokimi/repos/compare.py:586: Input: three patterns near 1e9,1e9 + 1/3,1e9 + 0.1,2e9 + 0.2, with paired deltasa, b, c, a, -b, a, b(main has it too).
What I checked on 509ff05:
- The full test suite fails with main merged in, at
tests/test_answers_command.py::test_top_k_flag_below_one_is_refused[-1],tests/test_answers_command.py::test_top_k_flag_below_one_is_refused[0],tests/test_benchmark_command_question_set.py::test_preflight_check_failure_alone_stays_1. - When I changed the code on purpose, the tests still passed for 10 of 12 changes, and no test pins these down yet (non-blocking):
dokimi/dokimi/commands/_shared.py:37(the condition is negated),dokimi/dokimi/commands/_shared.py:74(the condition is negated),dokimi/dokimi/commands/_shared.py:212(the handled error is raised again) and 6 more. - The 1286 changed tests pass, and fail on main as expected.
- It merges cleanly onto main.
|
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
1 open issue
What changed in this PR
Refactors command-layer helpers to reduce cross-module imports of private names by centralizing shared utilities in dokimi/commands/_shared.py, and deduplicates filename sanitization into dokimi.artifacts.safe_file_name.
Changes:
- Added
dokimi/commands/_shared.pyand migrated multiple helpers (argparse flag builders, repo scan helpers, source parsing, ragas helpers, etc.) to public names. - Replaced duplicated
_safe_nameimplementations withdokimi.artifacts.safe_file_nameand updated callers accordingly. - Updated tests and docs (including regenerated CLI interface snapshot) to import/patch the new public helpers.
| File | Description |
|---|---|
| dokimi/tests/test_saved_self_judge_warning.py | Updates monkeypatch targets for renamed/moved judge + ragas helpers. |
| dokimi/tests/test_repo_source_exit_2.py | Switches tests to use refuse_typed public helper. |
| dokimi/tests/test_repo_l0_typecheck.py | Switches tests to use typecheck_or_exit shared helper. |
| dokimi/tests/test_repo_environment.py | Switches tests to use normalize_whitespace shared helper. |
| dokimi/tests/test_repo_cache_env_usable.py | Switches tests to use cache_dir_from_args shared helper. |
| dokimi/tests/test_repo_cache_dir_usable.py | Switches tests to use cache_dir_from_args shared helper. |
| dokimi/tests/test_ragas_runtime.py | Switches to shared run_ragas_eval and adds coverage for runtime failure handling. |
| dokimi/tests/test_questions_generate_inputs.py | Updates monkeypatching from answers._load_runtime_config to shared load_runtime_config. |
| dokimi/tests/test_pipeline_empty_question_set.py | Updates registry loader monkeypatch to benchmark.load_registry. |
| dokimi/tests/test_novelty_routing_spend_cap_partial.py | Updates to partial_destinations public helper. |
| dokimi/tests/test_llm_cli.py | Updates registry loader monkeypatch to benchmark.load_registry. |
| dokimi/tests/test_input_devices.py | Updates registry loader monkeypatch to benchmark.load_registry. |
| dokimi/tests/test_exit_codes_boundaries.py | Updates monkeypatch targets for manifest loader, registry loader, and ragas requirement. |
| dokimi/tests/test_eval_writers_save_artifact.py | Switches to shared run_ragas_eval. |
| dokimi/tests/test_eval_output_write_errors.py | Switches to shared run_ragas_eval. |
| dokimi/tests/test_empty_question_rule.py | Switches to shared run_ragas_eval. |
| dokimi/tests/test_cli_output.py | Switches to shared scan_reason. |
| dokimi/tests/test_benchmark_command_question_set.py | Updates registry loader monkeypatch to benchmark.load_registry. |
| dokimi/tests/test_answers_command.py | Updates to answers.load_runtime_config public name. |
| dokimi/dokimi/repos/compare.py | Removes trailing blank line (format-only change). |
| dokimi/dokimi/eval/matrix_rollup.py | Replaces local _safe_name with artifacts.safe_file_name. |
| dokimi/dokimi/commands/tasks_generate.py | Uses shared helpers for repo parsing, code index loading, scan/run error handling. |
| dokimi/dokimi/commands/subjects.py | Switches output directory sanitization to safe_file_name. |
| dokimi/dokimi/commands/skill_sensitivity.py | Uses novelty.default_dir public helper. |
| dokimi/dokimi/commands/skill.py | Switches novelty argparse flag helpers to shared public versions. |
| dokimi/dokimi/commands/runs.py | Switches baseline manifest helper to baseline_index. |
| dokimi/dokimi/commands/repo_scan.py | Exposes loaded_with_default publicly and removes moved helpers. |
| dokimi/dokimi/commands/repo_run.py | Exposes refuse_typed publicly and uses shared run_errors and cache/source helpers. |
| dokimi/dokimi/commands/repo_hits.py | Reuses shared judge_ref type parser. |
| dokimi/dokimi/commands/repo.py | Uses shared helpers for cache/source parsing, scan output, typecheck selection, code index loading. |
| dokimi/dokimi/commands/questions.py | Uses shared load_runtime_config. |
| dokimi/dokimi/commands/novelty_routing_report.py | Exposes partial_destinations publicly and updates call sites/docs. |
| dokimi/dokimi/commands/novelty_routing.py | Uses novelty.default_dir public helper. |
| dokimi/dokimi/commands/novelty_flags.py | Removes file; its content moved into _shared.py. |
| dokimi/dokimi/commands/novelty_budget.py | Updates import to partial_destinations public helper. |
| dokimi/dokimi/commands/novelty.py | Uses shared novelty helpers and exposes default_dir publicly. |
| dokimi/dokimi/commands/library.py | Makes registry loader public as load_registry. |
| dokimi/dokimi/commands/judge_reliability.py | Reuses shared pairwise_judges helper. |
| dokimi/dokimi/commands/evaluate.py | Uses shared require_ragas + run_ragas_eval. |
| dokimi/dokimi/commands/eval_graph.py | Reuses shared judge_ref (aliased). |
| dokimi/dokimi/commands/catalog_novelty.py | Uses shared novelty settings/arms/bundle + shared flag helpers. |
| dokimi/dokimi/commands/benchmark.py | Switches to library.load_registry public helper. |
| dokimi/dokimi/commands/baseline.py | Makes baseline manifest loader public as baseline_index. |
| dokimi/dokimi/commands/arms.py | Switches to artifacts.safe_file_name for cell artifact names. |
| dokimi/dokimi/commands/answers.py | Uses shared ragas helpers and shared runtime config loader. |
| dokimi/dokimi/commands/_shared.py | New shared helper module hosting refactored cross-command utilities. |
| dokimi/dokimi/artifacts.py | Adds safe_file_name helper shared across layers. |
| dokimi/docs/skill-novelty.md | Updates dependency list from removed novelty_flags.py to _shared.py. |
| dokimi/docs/skill-novelty-walkthrough.md | Updates dependency list from removed novelty_flags.py to _shared.py. |
| dokimi/docs/reference/cli-interface.json | Regenerates CLI snapshot to reference shared helper module paths. |
| dokimi/changelog.d/20261129_120000_napetrov_shared-command-helpers.md | Adds changelog entry describing shared helpers + filename normalization consolidation. |
Review effort: Lite
| def safe_file_name(name: str) -> str: | ||
| """A file-name piece for a cell or product name: other characters become ``-``, ``cell`` if none is left.""" | ||
| safe = "".join(c if c.isalnum() or c in ("-", "_", ".") else "-" for c in name) | ||
| return safe.strip("-") or "cell" |
There was a problem hiding this comment.
This is main's _safe_name, moved unchanged. Both directory uses refuse ./.. before writing (_safe_subject_id, _validate_unique_product_output_dirs; tests in test_subjects.py). The other calls add a suffix. Mapping .. to cell would hide those refusals.
|
|
Command modules imported about 25 private names from each other. Each helper now has a public name in commands/_shared.py, which holds only code that moved unchanged (plus the renames). A name used by one module stays where it is, and owner modules expose their cross-module names without the underscore. _safe_name existed twice (commands/arms.py and eval/matrix_rollup.py). It is now dokimi.artifacts.safe_file_name, the lowest layer both callers may import; the eval layer cannot import commands. No behaviour change. The CLI interface snapshot records the new home of the judge_ref type, so docs/reference/cli-interface.json is regenerated. 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>
Thread: PRRT_kwDOVBg7g86-G26W Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-G26j Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
The cache-dir refusal, parse_source and the code-index helpers moved from commands/repo.py to commands/_shared.py. List the new module in the contract's depends_on so the docs-review prompt names the page. Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
…oader Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: IC_kwDOVBg7g88AAAABtTnOTg Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟡 Changes needed · reviewed 2d27cdc
To fix: the branch conflicts with main since #1497, and its ignored count has to move into _shared.print_scan_text, or the console line loses it (line comments). The changelog wording and the small leftovers there are quick.
✅ make ci-local --offline: 33,316 passed, 27 checks pass · ✅ the moved helpers match their originals, the three _safe_name copies were identical · ✅ no command module imports another's private name now
The helpers are now public and shared, with no change to flags, output or exit codes.
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com> # Conflicts: # dokimi/dokimi/commands/novelty.py # dokimi/dokimi/commands/novelty_flags.py # dokimi/dokimi/commands/repo_scan.py # dokimi/dokimi/commands/skill.py # dokimi/tests/test_saved_self_judge_warning.py
Thread: PRRT_kwDOVBg7g86-mbhm Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-mbh8 Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-mbh1 Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-mbiG Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-mbiM Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86-equs: already fixed in 2d27cdc Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Review: PRR_kwDOVBg7g88AAAABbpwsVw Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
|
Re: review by vlad-perevezentsev
|
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com> (cherry picked from commit e249323eb321bbc70ac425c03170071d835a143c)
antonwolfy
left a comment
There was a problem hiding this comment.
LGTM. The moved helpers keep their bodies, no module imports another's private name any more, and a search of the tree finds no caller of a removed name. safe_file_name is the old _safe_name unchanged, and the one directory use is guarded.
What I ran, on a Linux review host at 5e4ce5f:
make ci-local: 38 passed, 0 failed, 16 skipped. The skips are jobs that need the GitHub runner or other Python versions.- A search of the tree for every removed name from the PR description: the only hits are a local helper of the same name in
test_ragas_real_runtime.pyand the pinned-base verifier in.agent-eval/tasks/rename-cli-flag/check.py, which importsbenchmarkfrom the historical base on purpose. - All 17 non-merge commits carry a
Signed-off-by.
Checked, no issues
- Changelog and label: the fragment now says the refactor changes no flags, output, file names or exit codes, and
skip-changelogis on the PR. - CLI snapshot:
cli-interface.jsondiffers from the base only in thejudge_reftype path of--extract-modeland--judge, as the CLI-surface comment shows. - Earlier review points: the
ignoredcount is inprint_scan_text(_shared.py:88), the generic RAGAS failure has a test (test_ragas_runtime.py), theraising=Falsepatch is gone, and_default_dircallers usedefault_dir.
Bot points I checked that no longer apply at this head (1)
- Copilot's point on
safe_file_namereturning.or..does not apply: the one call that makes a directory,subjects.py:197, runs after_validate_unique_product_output_dirs(subjects.py:523,551-560) has refused any product that maps to.or... The other calls append.jsonor a suffix. The function is the base's_safe_name, moved without a change.
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com> # Conflicts: # dokimi/dokimi/commands/evaluate.py # dokimi/dokimi/commands/skill.py
xaleryb
left a comment
There was a problem hiding this comment.
Approved on 4789d42. Command helpers are shared publicly with one safe filename helper; CLI help, repo scan text and json are identical to main, the (N ignored) count is back, and subjects code from #1494 runs on the new names. Merge note for #1406: keep AskOutcomeError re-raised in _shared.run_ragas_eval. Windows smoke had not started (the hosted Windows queue was stuck); every other check passed.

Summary
Command modules imported about 25 private names from each other. This PR gives them public names in a new
commands/_shared.py, and owners expose their cross-module names without the underscore._safe_nameexisted twice (commands/arms.py,eval/matrix_rollup.py) and now lives once asdokimi.artifacts.safe_file_name, the lowest layer both callers may import (the eval layer cannot import commands).No behaviour change. Moved bodies are unchanged except for their names.
Evidence
judge_refnow lives under_shared) and a timed-out-scenario test that passes serially (parallel flake under-n 8).ruff check --select Fclean.scripts/check_growth.pypasses.tests/test_import_architecture.pypasses._cache_dirtocache_dir_from_argsrename insideparse_source.safe_file_namematches both old_safe_namecopies on 17 inputs (0 mismatches).51953c7.Merge danger
Every cross-module private name below is removed with no alias, so an open PR that still uses the old name fails with ImportError, AttributeError or ruff F821 once both are on
main. To check a branch, grep its added lines for the left column._add_bundle_args,_add_model_args(novelty_flags, deleted)_(_shared)_add_cache_dir,_add_common(novelty_flags)add_cache_dir_arg,add_common_args(_shared)_arms,_settings,_bundle_from_args(novelty)arms_from_spec,settings_from_args,bundle_from_args(_shared)_default_dir(novelty)default_dir(novelty)_cache_dir,_code_index(repo)cache_dir_from_args,code_index_for(_shared)_parse_source,_normalize_whitespace(repo)_(_shared)_load_manifest,_source_tree(repo)manifest_for_tree,source_tree(repo)_baseline_manifest(baseline)baseline_index(baseline)_errors(repo_run)run_errors(_shared)_refuse_typed(repo_run)refuse_typed(repo_run)_judge_ref(repo_hits;redteamkeeps its own)judge_ref(_shared)_load_runtime_config(answers)load_runtime_config(_shared)_require_ragas,_run_ragas_eval(evaluate)_(_shared)_pairwise_judges(judge_reliability)pairwise_judges(_shared)_print_scan_text,_scan_gate,_scan_reason,_typecheck_or_exit(repo_scan)_(_shared)_loaded_with_default(repo_scan)loaded_with_default(repo_scan)_load_registry(library)load_registry(library)_partial_destinations(novelty_routing_report)partial_destinations(novelty_routing_report)_safe_name(commands.arms,eval.matrix_rollup)safe_file_name(dokimi.artifacts)All modules are
dokimi.commands.*unless named in full. The map comes from thedeflines this PR removes and adds (base0eeaaf9c0).evaluate._require_ragasbecomesevaluate.require_ragas.docs/reference/cli-interface.jsonis regenerated here. A later change to the module path of a CLI type makes it stale again.Open PRs that use old names (checked at their current heads, against this head)
_safe_namecalls insubjects.pyare renamed in this PR's merge commitmonkeypatch.setattr(evaluate, "_require_ragas", ...)intest_expected_outcome.pycommands/evaluate.py_baseline_manifest()incommands/baseline.pycommands/baseline.py_code_index(...)incommands/repo.pycommands/repo.py_add_bundle_args,_add_cache_dir,_add_common,_add_model_argsfromnovelty_flagsand adds_add_extractor_argtherenovelty.py,novelty_flags.py(deleted here),skill.py,growth_baseline.json, a test; it already conflicts withmainnovelty_flags.py(deleted here: its help text moves to_shared.py),skill.pyMerge order
Each of these PRs conflicts textually with this one, so whichever lands second resolves the conflict either way. Two orders work:
main, fixes one conflicted file and renames 0 to 4 names using the map. The feat(subjects): subjects run writes a run directory with its plan and result #1494 integration required threesafe_file_namecalls insubjects.py. Waiting on more PRs adds a sync round here for each one, and Part of #94 (F1b, model + judge) #1197 already conflicts withmain.mainand renames the onerequire_ragaspatch site intest_expected_outcome.py.The order is the author's call. Either way, #1522, #1328, #1197 and #1420 update their branches and rename after this PR lands.
🤖 Generated with Claude Code