oct
Loading...
Searching...
No Matches
oct.cli Namespace Reference

Classes

class  OctGroup

Functions

click.Command|None _resolve_leaf_command (click.Group group, list[str] args)
list[str] _expand_windows_args (click.Group group, list[str] args)
None _start_diagnostics ()
None cli (click.Context ctx, str|None root_dir, bool allow_outside_project, bool strict_config, bool log_output)
None lint (click.Context ctx, tuple[str,...] args)
None format (click.Context ctx, tuple[str,...] args)
None agent (tuple[str,...] args)
None new (click.Context ctx, str path, bool force, bool test, bool dry_run, bool verbose)
None scaffold (str name, bool dry_run, bool no_venv, bool with_claude)
str|None _workspace_subproject_name (Path project_root)
None docs (click.Context ctx, bool sphinx_mode, bool doxygen_mode, bool typedoc_mode, bool all_mode, bool clean_mode, bool dry_run, bool no_workspace, bool init_doxygen, bool force, str|None callgraph, int|None depth, bool trace_mode, tuple[str,...] trace_args)
bool _pytest_missing (str combined_output)
None _run_pytest (Path project_root, tuple args, bool json_mode=False)
Path|None _map_source_to_test (Path source, Path project_root)
tuple[str,...] _cache_args (bool cached, bool cache_clear)
None _record_cached_run (click.Context ctx, Path project_root)
None test (click.Context ctx, bool json_mode, bool changed, bool cached, bool cache_clear, tuple[str,...] args)
None export_source (click.Context ctx, bool verbose, bool clean, bool single_dir, bool allow_outside_project, bool warn_secrets, bool block_secrets, str|None diff_ref, str|None path)
None export_skeleton (click.Context ctx, bool json_mode, bool verbose, bool single_dir, bool no_diagnostics, bool clean, bool allow_outside_project, str|None path)
None clean (click.Context ctx, str|None path, bool dry_run, bool allow_outside_project)
None health (click.Context ctx, bool json_mode, bool verbose, bool run_tests, int|None test_timeout, bool timing, int timing_last, bool write_baseline, bool force_host, Path|None session)
None deps (click.Context ctx, tuple[str,...] args)
None install_hooks_cmd (click.Context ctx, bool force)
None typecheck (click.Context ctx, bool json_mode, tuple[str,...] args)
None diag (click.Context ctx)
None diag_validate_config (click.Context ctx, bool strict)
None diag_list_domains (click.Context ctx)
None diag_set_level (click.Context ctx, str domain, int level, bool dry_run)
None diag_restore (click.Context ctx)
None diag_migrate_config (click.Context ctx, Path|None config_path, bool dry_run)
None install_mcp (click.Context ctx, str host, bool dry_run)

Variables

dict _COMMAND_FLAGS
str TIMING_SAMPLE_KEY = "oct.timing.sample"
str NO_GLOB_EXPANSION_ATTR = "no_glob_expansion"
tuple _PYTEST_INSTALL_HINT
 _git_group
 name
 _migrate_group
 _audit_cmd
 _oct_install_cmd

Detailed Description

Purpose
-------
Provide the main command-line interface for the OCT (Option C Tools) ecosystem.

Responsibilities
----------------
- Define top-level commands: oct lint, oct format, oct new, oct scaffold, oct docs,
  oct test, oct export-source, oct clean, oct health.
- Delegate work to the appropriate OCT modules.
- Scaffold new Option C projects with a correct ``oc_diagnostics/debug_config.json``
  pre-configured for use with ``oc_diagnostics``.
- Set up Sphinx documentation templates in ``docs/``.
- Ensure consistent behavior across all projects.

Diagnostics
-----------
Domain: OCT-CLI
Levels:
    L2 - lifecycle
    L3 - semantic details
    L4 - deep tracing

Contracts
---------
- Must be installed as the console entry point for the OCT package.
- Must not contain business logic; only dispatching.
- Scaffolded ``debug_config.json`` must be a valid ``oc_diagnostics`` configuration.

Dependencies
------------
- oct (package version)
- oct.core.project_root (project root detection)
- oct.linter.oct_lint (linter command implementation)
- oct.formatter.oct_format (formatter command implementation)
- oct.health.oct_health (health dashboard command)
- oct.generator.new_python_file (new file scaffolding)
- oct.diag.oct_diag (diagnostics config commands)
- oct.deps.oct_deps (dependency graph command)
- oct.hooks.oct_hooks (pre-commit hooks generator)
- oct.typecheck.oct_typecheck (type-checking wrapper)
- click (CLI framework)
- oct.complexity.command (complexity command)
- oct.mutation.command (mutate command)
- oct.git (git_group - the git command group)
- oct.migrate (migrate_group - the migrate command group)
- oct.audit (audit_group - the audit command)
- oct.install.oct_install (oct_install_cmd - the install command)
- oct.core.diagnostics (_dbg structured logger)
- oc_diagnostics (lazy; init with file-only output before each command)
- oct.timing.ledger (lazy; the timing stage around each command)
- oct.core.compat (lazy; oc_diagnostics compatibility warning for scaffold)
- oct.scaffold (lazy; run_scaffold for the scaffold command)
- oct.scaffold.oct_scaffold (lazy; Claude Code skills copy for scaffold --with-claude)
- oct.core.workspace (lazy; manifest subproject name for the Doxyfile PROJECT_NAME)
- oct.docs.callgraph_command (lazy; docs --callgraph)
- oct.docs.doxyfile_init (lazy; Doxyfile writer for docs --init-doxygen)
- oct.docs.oct_docs (lazy; Sphinx, Doxygen, all-tier and clean docs runs, project name fallback)
- oct.docs.typedoc (lazy; docs --typedoc)
- oct.testing.cache (lazy; pytest cache plugin flags and the cached run's file count)
- oct.core.git (lazy; changed-file discovery for test --changed)
- oct.tools.source_exporter (lazy; export-source, and source export and pycache removal for clean)
- oct.tools.skeleton_exporter (lazy; export-skeleton, and skeleton export removal for clean)
- oct.tools.build_artifacts (lazy; build and dist tree removal for clean)
- oct.git.oct_git (lazy; enhanced hooks template for the deprecated install-hooks)
- oct.tools.install_mcp (lazy; install-mcp command)
- oc_chat.registry (not imported; run as python -m oc_chat.registry by the agent command)
- pytest (not imported; run as python -m pytest by the test command)

Function Documentation

◆ _cache_args()

tuple[str, ...] oct.cli._cache_args ( bool cached,
bool cache_clear )
protected
Pytest arguments that drive the Plan 249 content-hashed cache.

``-p oct.testing.cache`` loads the plugin for ANY project, so the
flags work whether or not the project's root conftest wires the
seams itself; the plugin registers its options at most once.

Definition at line 988 of file cli.py.

Here is the caller graph for this function:

◆ _expand_windows_args()

list[str] oct.cli._expand_windows_args ( click.Group group,
list[str] args )
protected
Apply Click's Windows shell-expansion unless the target opts out.

Click's ``Command.main`` runs ``_expand_args`` over the whole argv on
Windows - ``~``, ``$VAR`` and globs - because cmd and PowerShell do
none of that themselves, and ``oct lint oct/*.py`` relies on it. But
the expansion cannot tell a path from a pattern: ``oct git ignore
"**/docs/html/"`` had its one argument replaced by the fourteen
directories it happened to match, every one of which the pattern
validator then rejected (2026-09-27). A command that takes patterns
sets :data:`NO_GLOB_EXPANSION_ATTR` and receives its argv verbatim;
every other command keeps the expansion it always had.

Definition at line 395 of file cli.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _map_source_to_test()

Path | None oct.cli._map_source_to_test ( Path source,
Path project_root )
protected
Heuristic: map a source .py file to its likely test file.

Tries several common patterns and returns the first existing match,
or ``None`` if no test file is found.

Definition at line 953 of file cli.py.

Here is the caller graph for this function:

◆ _pytest_missing()

bool oct.cli._pytest_missing ( str combined_output)
protected
Detect the 'No module named pytest' signature in combined output.

Definition at line 855 of file cli.py.

Here is the caller graph for this function:

◆ _record_cached_run()

None oct.cli._record_cached_run ( click.Context ctx,
Path project_root )
protected
Put the cached run's file count in the timing ledger (P5).

``files`` is the number of files that actually RAN, so the saving
a cache produced is visible in ``oct health --timing`` beside the
uncached runs of the same stage.

Definition at line 1007 of file cli.py.

Here is the caller graph for this function:

◆ _resolve_leaf_command()

click.Command | None oct.cli._resolve_leaf_command ( click.Group group,
list[str] args )
protected
Return the command *args* would dispatch to, parsing nothing else.

Walks the group tree with ``resilient_parsing`` contexts, so option
callbacks never run and a malformed command line resolves to ``None``
rather than raising - the real parse that follows reports the error
properly. Used before Click's Windows argument expansion to find out
whether the target command wants that expansion at all.

Definition at line 360 of file cli.py.

Here is the caller graph for this function:

◆ _run_pytest()

None oct.cli._run_pytest ( Path project_root,
tuple args,
bool json_mode = False )
protected
Run pytest in *project_root* and exit on failure.

When *json_mode* is True, captures pytest output, parses the summary
line, and emits a machine-readable JSON object to stdout:
``{"tool": "test", "passed": N, "failed": N, "errors": N,
   "warnings": N, "output": "...", "exit_code": N}``

OI-511: pytest is now declared in the ``[project.optional-dependencies].test``
extra rather than as a runtime dependency; if ``python -m pytest`` reports
it is not importable, emit the install hint above and exit 1.

Definition at line 860 of file cli.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _start_diagnostics()

None oct.cli._start_diagnostics ( )
protected
Start oc_diagnostics for this process: exception hook, no stream capture.

Output goes to the log file only, so oct's terminal output stays its
own. The file's FORMAT is left to the config's ``log_format`` (text, or
``jsonl`` for machine reading; oc_diagnostics >= 2.2.0 keeps the two
independent). Idempotent; a no-op without oc_diagnostics.

Definition at line 415 of file cli.py.

Here is the caller graph for this function:

◆ _workspace_subproject_name()

str | None oct.cli._workspace_subproject_name ( Path project_root)
protected
Return the manifest name of the subproject at *project_root*, if any.

``None`` when *project_root* is not inside a workspace, the manifest
does not load, or no subproject entry contains it.

Definition at line 667 of file cli.py.

Here is the caller graph for this function:

◆ agent()

None oct.cli.agent ( tuple[str, ...] args)
Delegate to the OC Chat registry agent CLI.

A thin subprocess facade over ``python -m oc_chat.registry`` (Plan 151
T6). oct NEVER imports oc_chat - the CLI-boundary rule; all arguments,
stdin/stdout/stderr, the JSON envelope, and the exit-code contract
(0 ok, 1 source-validation, 2 build/refusal/scope, 3 not-byte-stable,
5 stale schema) are preserved verbatim by delegating to the child
process. Requires oc_chat to be importable on the interpreter running
the facade (the monorepo workspace install).

Definition at line 578 of file cli.py.

◆ clean()

None oct.cli.clean ( click.Context ctx,
str | None path,
bool dry_run,
bool allow_outside_project )
Remove _source_code-*, _skeleton_code-* export dirs, __pycache__ dirs
and packaging build/ and dist/ trees.

A build/ or dist/ directory is only removed when it sits beside a
pyproject.toml / setup.py / setup.cfg AND contains nothing but
packaging output. One that fails either test is kept and the reason
printed, because both are ordinary words and a project is entitled to
a source directory called either.

Definition at line 1272 of file cli.py.

◆ cli()

None oct.cli.cli ( click.Context ctx,
str | None root_dir,
bool allow_outside_project,
bool strict_config,
bool log_output )
OCT - Option C Tools

Definition at line 530 of file cli.py.

◆ deps()

None oct.cli.deps ( click.Context ctx,
tuple[str, ...] args )
Analyse inter-module dependencies.

Definition at line 1366 of file cli.py.

◆ diag()

None oct.cli.diag ( click.Context ctx)
oc_diagnostics configuration tools.

Definition at line 1433 of file cli.py.

◆ diag_list_domains()

None oct.cli.diag_list_domains ( click.Context ctx)
List configured domains with their levels and colors.

Definition at line 1468 of file cli.py.

◆ diag_migrate_config()

None oct.cli.diag_migrate_config ( click.Context ctx,
Path | None config_path,
bool dry_run )
OI-508 / FS-515: upgrade a legacy v1 debug_config.json to v2.0.

When PATH is omitted, migrates the project's own debug_config.json.
Writes ``<path>.bk`` before overwriting; idempotent - running twice
over an already-v2 file is a no-op.

Definition at line 1548 of file cli.py.

◆ diag_restore()

None oct.cli.diag_restore ( click.Context ctx)
OI-528: restore debug_config.json from its .bk backup.

Definition at line 1525 of file cli.py.

◆ diag_set_level()

None oct.cli.diag_set_level ( click.Context ctx,
str domain,
int level,
bool dry_run )
Set a domain's debug level (0-9).

OI-528: the write is always preceded by a ``<path>.bk`` backup so
``oct diag restore`` can undo a bad edit. ``--dry-run`` prints the
would-be post-edit config to stdout and skips both writes.

Definition at line 1496 of file cli.py.

◆ diag_validate_config()

None oct.cli.diag_validate_config ( click.Context ctx,
bool strict )
Validate debug_config.json against the expected schema.

Definition at line 1446 of file cli.py.

◆ docs()

None oct.cli.docs ( click.Context ctx,
bool sphinx_mode,
bool doxygen_mode,
bool typedoc_mode,
bool all_mode,
bool clean_mode,
bool dry_run,
bool no_workspace,
bool init_doxygen,
bool force,
str | None callgraph,
int | None depth,
bool trace_mode,
tuple[str, ...] trace_args )
Validate or build Option C documentation.

Definition at line 723 of file cli.py.

Here is the call graph for this function:

◆ export_skeleton()

None oct.cli.export_skeleton ( click.Context ctx,
bool json_mode,
bool verbose,
bool single_dir,
bool no_diagnostics,
bool clean,
bool allow_outside_project,
str | None path )
Export structural skeletons of source files for AI inspection.

Definition at line 1224 of file cli.py.

◆ export_source()

None oct.cli.export_source ( click.Context ctx,
bool verbose,
bool clean,
bool single_dir,
bool allow_outside_project,
bool warn_secrets,
bool block_secrets,
str | None diff_ref,
str | None path )
Export consolidated source-code files for inspection.

Definition at line 1153 of file cli.py.

◆ format()

None oct.cli.format ( click.Context ctx,
tuple[str, ...] args )
Auto-fix Option C compliance violations in Python files.

Definition at line 570 of file cli.py.

◆ health()

None oct.cli.health ( click.Context ctx,
bool json_mode,
bool verbose,
bool run_tests,
int | None test_timeout,
bool timing,
int timing_last,
bool write_baseline,
bool force_host,
Path | None session )
Display project compliance dashboard.

Definition at line 1336 of file cli.py.

◆ install_hooks_cmd()

None oct.cli.install_hooks_cmd ( click.Context ctx,
bool force )
[DEPRECATED] Use 'oct git hooks install' instead.

Definition at line 1377 of file cli.py.

◆ install_mcp()

None oct.cli.install_mcp ( click.Context ctx,
str host,
bool dry_run )
Install oct-mcp into an AI host's MCP config (Claude Code, Cursor, VS Code).

Definition at line 1589 of file cli.py.

◆ lint()

None oct.cli.lint ( click.Context ctx,
tuple[str, ...] args )
Run the Option C linter.

Definition at line 559 of file cli.py.

◆ new()

None oct.cli.new ( click.Context ctx,
str path,
bool force,
bool test,
bool dry_run,
bool verbose )
Create a new Option C-compliant Python file.

Definition at line 615 of file cli.py.

◆ scaffold()

None oct.cli.scaffold ( str name,
bool dry_run,
bool no_venv,
bool with_claude )
Create a new Option C project.

Definition at line 636 of file cli.py.

◆ test()

None oct.cli.test ( click.Context ctx,
bool json_mode,
bool changed,
bool cached,
bool cache_clear,
tuple[str, ...] args )
Run the project's test suite.

Definition at line 1037 of file cli.py.

Here is the call graph for this function:

◆ typecheck()

None oct.cli.typecheck ( click.Context ctx,
bool json_mode,
tuple[str, ...] args )
Run type checking (pyright or mypy).

Definition at line 1401 of file cli.py.

Variable Documentation

◆ _audit_cmd

oct.cli._audit_cmd
protected

Definition at line 1423 of file cli.py.

◆ _COMMAND_FLAGS

dict oct.cli._COMMAND_FLAGS
protected

Definition at line 101 of file cli.py.

◆ _git_group

oct.cli._git_group
protected

Definition at line 1415 of file cli.py.

◆ _migrate_group

oct.cli._migrate_group
protected

Definition at line 1419 of file cli.py.

◆ _oct_install_cmd

oct.cli._oct_install_cmd
protected

Definition at line 1428 of file cli.py.

◆ _PYTEST_INSTALL_HINT

tuple oct.cli._PYTEST_INSTALL_HINT
protected
Initial value:
1= (
2 "pytest is not installed. Install it with one of:\n"
3 " pip install oct[test] # installs OCT's test extras\n"
4 " pip install pytest # install pytest directly"
5)

Definition at line 848 of file cli.py.

◆ name

oct.cli.name

Definition at line 1415 of file cli.py.

◆ NO_GLOB_EXPANSION_ATTR

str oct.cli.NO_GLOB_EXPANSION_ATTR = "no_glob_expansion"

Definition at line 357 of file cli.py.

◆ TIMING_SAMPLE_KEY

str oct.cli.TIMING_SAMPLE_KEY = "oct.timing.sample"

Definition at line 351 of file cli.py.