oc_chat
Loading...
Searching...
No Matches
oc_chat.registry.cli.source Namespace Reference

Functions

None add_source_subcommands (argparse._SubParsersAction roadmap_commands)
Path _source_dir (argparse.Namespace args)
"tuple[Path | None, int | None]" _resolve_root_or_exit (argparse.Namespace args)
None _emit_envelope (SourceError error, bool as_json)
None _print_error_envelope (dict envelope, bool as_json)
"str | None" _git_status_porcelain (Path root)
int _cmd_source_format (argparse.Namespace args)
int _cmd_source_validate (argparse.Namespace args)
int _cmd_source_lint (argparse.Namespace args)
list[dict] _lint_inactive_tracks (dict categorized)
int _cmd_source_diff (argparse.Namespace args)
dict _diff_units (Path root)
"tuple[tuple, dict]" _logical_key (str kind, scanned, model)
dict _unit (str kind, dict keyobj, str path, model)
dict _compare_units (dict units_a, dict units_b)
dict _locate (dict unit)
tuple _diff_sort_key (dict record)
None _print_diff_human (dict result)
 _migration_registry_factory ()
"tuple[Path, Path]" _resolve_migrate_paths (argparse.Namespace args)
int _cmd_source_migrate (argparse.Namespace args)
None _print_migrate_success (dict payload, bool as_json, bool quiet)
int _cmd_hash_preimage (argparse.Namespace args)

Variables

dict _DIFF_KIND

Detailed Description

CLI commands for the registry AuthoredSource format (Plan 142 P1.3 + 142j R5).

Purpose
-------
Expose the §10 read-only ``source`` surface: ``format [--check]`` (the §3.2
idempotent canonicaliser, with the 142j write-mode clean-tree precondition),
``validate`` (the §5.3 steps 1–6 chain, fail-fast), ``lint`` (non-failing style
warnings), ``diff`` (a semantic diff over parsed/canonical models), and
``hash-preimage`` (the §3.2 debug preimage). The destructive ``migrate`` command
is Plan 142m.

Responsibilities
----------------
- Resolve the source tree (default ``<workspace>/oc_chat/roadmap/source``).
- Run each read-only command, emitting the §8 ``build_envelope`` on failure and
  each command's own success payload otherwise.
- Enforce the write-mode clean-tree precondition + the worker discovery guard.

Diagnostics
-----------
Domain: OC_CHAT.MAIN
Levels:
    L2 - CLI lifecycle
    L3 - command argument summaries
    L4 - subcommand dispatch details

Contracts
---------
- Read-only except ``source format`` (without ``--check``) which rewrites
  non-canonical records in place (refused on a dirty resolved-source tree).
- Non-zero exit emits the §10 envelope; ``diff`` owns 0/1/2 (exit 1 = "differs").

Dependencies
------------
- argparse (CLI parsing)
- oc_chat.registry.discovery (workspace/registry resolution + the worker guard)
- oc_diagnostics (_dbg structured logger)
- oc_chat.registry.backends.sqlite (SQLiteBackend connection for the logical-state hash preimage)
- oc_chat.registry.regenerate.cross_record (validate_cross_record, the cross-record step of validate)
- oc_chat.registry.regenerate.envelope (RegenerateError, SRC_TREE_DIRTY, build_envelope and exit_code_for)
- oc_chat.registry.regenerate.lock (acquire and release the shared regenerate lock around migrate)
- oc_chat.registry.regenerate.pipeline (_categorize, the record load and schema steps of validate and lint)
- oc_chat.registry.source.canonical (format_source_tree canonicaliser and load_record for diff and hash-preimage)
- oc_chat.registry.source.errors (SourceError and SourceScanError for the error envelopes and exit codes)
- oc_chat.registry.source.hashing (raw-source-tree and source hashes plus the hash-preimage projections)
- oc_chat.registry.source.scanner (scan_source_tree over the resolved source tree)
- oc_chat.registry.source_migrations.errors (MigrateError for the target schema version refusal)
- oc_chat.registry.source_migrations.runner (production migration provider, run_migration and target semver validation)
- yaml (YAML output for hash-preimage)
- git (not imported; run as a subprocess for rev-parse and status --porcelain, the clean-tree precondition of write-mode source format)

Function Documentation

◆ _cmd_hash_preimage()

int oc_chat.registry.cli.source._cmd_hash_preimage ( argparse.Namespace args)
protected

Definition at line 588 of file source.py.

Here is the call graph for this function:

◆ _cmd_source_diff()

int oc_chat.registry.cli.source._cmd_source_diff ( argparse.Namespace args)
protected

Definition at line 384 of file source.py.

Here is the call graph for this function:

◆ _cmd_source_format()

int oc_chat.registry.cli.source._cmd_source_format ( argparse.Namespace args)
protected

Definition at line 251 of file source.py.

Here is the call graph for this function:

◆ _cmd_source_lint()

int oc_chat.registry.cli.source._cmd_source_lint ( argparse.Namespace args)
protected

Definition at line 330 of file source.py.

Here is the call graph for this function:

◆ _cmd_source_migrate()

int oc_chat.registry.cli.source._cmd_source_migrate ( argparse.Namespace args)
protected
The ``roadmap source migrate`` handler — pipeline steps 0-2 (semver shape,
root resolution, the shared lock) + the runner (steps 3-13). Mirrors
``regenerate/pipeline`` lock choreography: step 0 in its OWN pre-lock
try/except; a separate try wrapping the runner whose
``except (SourceError, RegenerateError)`` catches BOTH the migrate refusals and
the lock's ``REGEN_LOCK_HELD``, with a ``finally`` that releases the lock
UNCONDITIONALLY.

Definition at line 515 of file source.py.

Here is the call graph for this function:

◆ _cmd_source_validate()

int oc_chat.registry.cli.source._cmd_source_validate ( argparse.Namespace args)
protected

Definition at line 302 of file source.py.

Here is the call graph for this function:

◆ _compare_units()

dict oc_chat.registry.cli.source._compare_units ( dict units_a,
dict units_b )
protected

Definition at line 447 of file source.py.

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

◆ _diff_sort_key()

tuple oc_chat.registry.cli.source._diff_sort_key ( dict record)
protected

Definition at line 474 of file source.py.

◆ _diff_units()

dict oc_chat.registry.cli.source._diff_units ( Path root)
protected
Return ``{full_key_tuple: unit}`` over the parsed models — every entity plus
each inline sub_phase / promoted item as a normalized ``sub_phase`` pseudo-record
(same key ``{identity, parent_phase}``), so an inline↔promoted move is a path
change, not add+remove (§5.6).

Definition at line 404 of file source.py.

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

◆ _emit_envelope()

None oc_chat.registry.cli.source._emit_envelope ( SourceError error,
bool as_json )
protected
The pre-142j compact envelope (no §8 hash keys) — kept for the EXISTING
``format``/``hash-preimage`` error paths (unchanged; only the new SRC_TREE_DIRTY
path uses ``build_envelope``, R7 narrow-scope).

Definition at line 201 of file source.py.

Here is the caller graph for this function:

◆ _git_status_porcelain()

"str | None" oc_chat.registry.cli.source._git_status_porcelain ( Path root)
protected
Return ``git status --porcelain`` limited to ``root``'s subtree, or ``None``
if ``root`` is not inside a git worktree (R7 write-mode clean-tree precondition;
scoped to the resolved root, so unrelated edits elsewhere never block).

Definition at line 228 of file source.py.

Here is the caller graph for this function:

◆ _lint_inactive_tracks()

list[dict] oc_chat.registry.cli.source._lint_inactive_tracks ( dict categorized)
protected
The first required lint (§3.2): a record whose ``track_codes`` reference an
inactive track. Non-failing; deterministically ordered.

Definition at line 354 of file source.py.

Here is the caller graph for this function:

◆ _locate()

dict oc_chat.registry.cli.source._locate ( dict unit)
protected

Definition at line 470 of file source.py.

Here is the caller graph for this function:

◆ _logical_key()

"tuple[tuple, dict]" oc_chat.registry.cli.source._logical_key ( str kind,
scanned,
model )
protected
Per-kind logical key (Codex-R10-P1): track→track_code; version→(route, slug);
manifest→singleton; framing/note/era/item/phase→id. Returns
``(hashable_full_key, emitted_key_object)`` (absent fields omitted).

Definition at line 429 of file source.py.

Here is the caller graph for this function:

◆ _migration_registry_factory()

oc_chat.registry.cli.source._migration_registry_factory ( )
protected
The migration-discovery seam (private, non-CLI). Default = PRODUCTION
discovery over ``registry/source_migrations/``. Tests monkeypatch THIS symbol
(the consuming namespace) to inject fakes; there is NO ``--migrations-package``
flag — a visible flag pointing migrate at arbitrary code is a production
footgun. Production CLI always uses the default.

Definition at line 495 of file source.py.

Here is the caller graph for this function:

◆ _print_diff_human()

None oc_chat.registry.cli.source._print_diff_human ( dict result)
protected

Definition at line 482 of file source.py.

Here is the caller graph for this function:

◆ _print_error_envelope()

None oc_chat.registry.cli.source._print_error_envelope ( dict envelope,
bool as_json )
protected
Print the full §8 ``build_envelope`` (with the hash-nullability keys).

Definition at line 220 of file source.py.

Here is the caller graph for this function:

◆ _print_migrate_success()

None oc_chat.registry.cli.source._print_migrate_success ( dict payload,
bool as_json,
bool quiet )
protected
Emit the migrate SUCCESS payload. ``--quiet`` suppresses ONLY the non-JSON
human success line; it NEVER suppresses the ``--json`` payload or the
journal-unresolved stderr warning.

Definition at line 570 of file source.py.

Here is the caller graph for this function:

◆ _resolve_migrate_paths()

"tuple[Path, Path]" oc_chat.registry.cli.source._resolve_migrate_paths ( argparse.Namespace args)
protected
Resolve (source_root, workspace_root) through THIS module's binding of
``discover_registry_location`` (the consuming-namespace seam the tests patch).
migrate takes NO ``--source-dir``: root = the discovered workspace's own source
tree, and the shared lock + journal key to the SAME workspace root.

Definition at line 504 of file source.py.

Here is the caller graph for this function:

◆ _resolve_root_or_exit()

"tuple[Path | None, int | None]" oc_chat.registry.cli.source._resolve_root_or_exit ( argparse.Namespace args)
protected
Resolve the source dir; on the R7 worker-guard failure (a registry-discovery
error, NOT a §8 envelope) print the stderr token and return exit 2.

Definition at line 191 of file source.py.

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

◆ _source_dir()

Path oc_chat.registry.cli.source._source_dir ( argparse.Namespace args)
protected

Definition at line 184 of file source.py.

Here is the caller graph for this function:

◆ _unit()

dict oc_chat.registry.cli.source._unit ( str kind,
dict keyobj,
str path,
model )
protected

Definition at line 443 of file source.py.

Here is the caller graph for this function:

◆ add_source_subcommands()

None oc_chat.registry.cli.source.add_source_subcommands ( argparse._SubParsersAction roadmap_commands)
Attach ``source`` (format/validate/lint/diff) + ``hash-preimage`` (§10).

Definition at line 108 of file source.py.

Variable Documentation

◆ _DIFF_KIND

dict oc_chat.registry.cli.source._DIFF_KIND
protected
Initial value:
1= {
2 "manifest": "manifest", "era": "era", "track": "track", "phase": "phase",
3 "roadmap_item": "item", "version": "version", "framing": "framing", "note": "note",
4}

Definition at line 102 of file source.py.