oc_chat
Loading...
Searching...
No Matches
oc_chat.registry.migrate Namespace Reference

Classes

class  RoundEvidence
class  MigrationOptions
class  ImportResult
class  VerifyResult
class  RollbackResult
class  CutoverResult
class  StatusSource
class  PlanHeader
class  QueueEntry
class  MigrationProjection

Functions

MigrationProjection build_projection (Registry registry, MigrationOptions options)
ImportResult run_import (Registry registry, MigrationOptions options, *, bool dry_run=False)
VerifyResult run_verify (Registry registry, MigrationOptions options)
RollbackResult run_rollback (Registry registry, MigrationOptions options)
CutoverResult run_cutover_stub ()
dict[str, object] audit_null_closed_round_backfills (Registry registry)
list[dict[str, object]] _build_agent_rows ()
tuple[dict[str, QueueEntry], dict[str, str]] _read_queue_entries (Path queue_path, Path root)
dict[str, PlanHeader] _read_plan_headers (Path plan_dir, Path root)
dict[str, StatusSource] _read_status_sources (tuple[Path,...]|None explicit_paths, Path root, str observed_at, list[str] warnings)
StatusSource _read_status_source (Path path, Path root, str observed_at)
list[Path] _discover_status_paths (Path root)
dict[str, RoundEvidence] _round_evidence_by_plan (MigrationOptions options, Path root)
list[RoundEvidence] _discover_round_evidence (Path root)
str|None _main_sha (Path root)
str _select_legacy_status (str plan_id, PlanHeader header, StatusSource|None source, Mapping[str, QueueEntry] pending, Mapping[str, str] completed)
set[str] _dedupe_plan_ids_by_number (set[str] plan_ids, Mapping[str, PlanHeader] headers, Mapping[str, QueueEntry] pending, Mapping[str, str] completed, Mapping[str, StatusSource] status_sources, list[str] warnings)
int _plan_number (str plan_id, Mapping[str, PlanHeader] headers)
tuple[int, str] _plan_priority (str plan_id, Mapping[str, QueueEntry] pending, Mapping[str, str] completed, Mapping[str, StatusSource] status_sources)
dict[str, object]|None _map_legacy_status (str plan_id, int plan_number, str legacy_status, StatusSource|None source, RoundEvidence|None evidence, str|None discovered_sha, list[str] errors)
dict[str, object] _plan_payload (str plan_id, PlanHeader header, str legacy_status, Mapping[str, object] mapped, str source_file)
dict[str, object] _round_row (RoundEvidence evidence)
PlanHeader _placeholder_header (str plan_id, Path plan_dir, Path root)
str|None _assigned_slot (QueueEntry|None queue_entry, StatusSource|None source, str|None completed_slot)
tuple[str|None, str|None, str|None] _select_overrides (PlanHeader header, StatusSource|None source, QueueEntry|None queue_entry)
str _parse_title (str text, str plan_id)
str|None _header_value (str text, str name)
tuple[str|None, str|None, str|None] _parse_suggested_model (str text)
str|None _clean_header_value (str|None value)
str|None _normalise_branch (str|None value)
None _clear_duplicate_branches (Sequence[dict[str, object]] plan_rows, list[str] warnings)
str _normalise_legacy_status (object value)
str|None _normalise_header_status (object value)
str _agent_label (str value)
str _agent_label_to_slot (str label)
str|None _first_model (object value)
bool _looks_small_model (str|None model)
str|None _provider_from_model (str|None model)
str _display_path (Path path, Path root)
str|None _string_timestamp (object value)
str|None _optional_text (object value)
str|None _first_text (*object values)
str|None _first_nonempty_line (str text)
tuple[int, str] _plan_sort_key (str plan_id)
Path _backup_dir (Path root)
Path _backup_path (Path root, str now)
SQLiteBackend _sqlite_backend (Registry registry)
list[dict[str, object]] _comparable_agents (Sequence[Mapping[str, object]] rows)
list[dict[str, object]] _comparable_plans (Sequence[Mapping[str, object]] rows)
list[dict[str, object]] _comparable_queue_entries (Sequence[Mapping[str, object]] rows)
list[dict[str, object]] _comparable_rounds (Sequence[Mapping[str, object]] rows)
list[dict[str, object]] _comparable_round_plans (Sequence[Mapping[str, object]] rows)
dict[str, object] _snapshot_diff (Mapping[str, object] expected, Mapping[str, object] actual)
dict[str, object] _result_dict (object value)

Variables

 PLAN_ID_RE = re.compile(r"^(?P<number>\d{3})-(?P<slug>.+)$")
 LEGACY_PLAN_ID_RE = re.compile(r"\b\d{3}-[A-Za-z0-9][A-Za-z0-9_.-]*\b")
 ROUND_RE = re.compile(r"\bround[-\s]*(?P<round>\d+)\b", re.IGNORECASE)
dict HEADER_PATTERNS
 H1_RE = re.compile(r"^#\s+(?P<value>.+?)\s*$", re.MULTILINE)
dict VALID_LEGACY_STATUSES
dict STATUS_NORMALISATIONS
int PRE_ROUND_SYSTEM_PLAN_CEILING = 50

Detailed Description

Legacy queue/status migration into the M11 registry.

Purpose
-------
Project the Markdown-era orchestration state into the SQLite registry
without making the registry depend on those legacy files afterward.

Responsibilities
----------------
- Parse the legacy agent queue, plan headers, status files, and git evidence.
- Map legacy lifecycle names onto the ADR-00Z registry statuses.
- Build a deterministic projection for dry-run, import, verify, and rollback.
- Delegate all current-state SQL and operation-log writes to SQLiteBackend.

Diagnostics
-----------
Domain: OC_CHAT.MAIN
Levels:
    L2 - lifecycle events
    L3 - semantic details
    L4 - deep tracing

Contracts
---------
- No raw wall-clock imports are used here; timestamps come from the backend Clock.
- Import uses one SQLite transaction for projected rows and audit rows.
- Unknown legacy statuses fail the import before writing audit rows.

Dependencies
------------
- oc_diagnostics (structured debug logging via _dbg)
- oc_chat.registry._legacy_queue (read-only legacy queue parser; plan 223
  moved it here when the queue machinery retired)
- oc_chat.scripts.plan_status (legacy status file parser)
- oc_chat.registry.backends.sqlite (SQL owner for migration writes)
- oc_chat.registry (Registry facade passed to the import, verify and rollback entry points)
- yaml (fallback parse of legacy status-file frontmatter)
- git (not imported; run as a subprocess for worktree list, the first-parent log of main and rev-parse main, the legacy status-file and round evidence)

Function Documentation

◆ _agent_label()

str oc_chat.registry.migrate._agent_label ( str value)
protected

Definition at line 1110 of file migrate.py.

Here is the caller graph for this function:

◆ _agent_label_to_slot()

str oc_chat.registry.migrate._agent_label_to_slot ( str label)
protected

Definition at line 1121 of file migrate.py.

Here is the caller graph for this function:

◆ _assigned_slot()

str | None oc_chat.registry.migrate._assigned_slot ( QueueEntry | None queue_entry,
StatusSource | None source,
str | None completed_slot )
protected

Definition at line 1004 of file migrate.py.

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

◆ _backup_dir()

Path oc_chat.registry.migrate._backup_dir ( Path root)
protected

Definition at line 1209 of file migrate.py.

Here is the caller graph for this function:

◆ _backup_path()

Path oc_chat.registry.migrate._backup_path ( Path root,
str now )
protected

Definition at line 1213 of file migrate.py.

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

◆ _build_agent_rows()

list[dict[str, object]] oc_chat.registry.migrate._build_agent_rows ( )
protected

Definition at line 562 of file migrate.py.

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

◆ _clean_header_value()

str | None oc_chat.registry.migrate._clean_header_value ( str | None value)
protected

Definition at line 1058 of file migrate.py.

Here is the caller graph for this function:

◆ _clear_duplicate_branches()

None oc_chat.registry.migrate._clear_duplicate_branches ( Sequence[dict[str, object]] plan_rows,
list[str] warnings )
protected

Definition at line 1074 of file migrate.py.

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

◆ _comparable_agents()

list[dict[str, object]] oc_chat.registry.migrate._comparable_agents ( Sequence[Mapping[str, object]] rows)
protected

Definition at line 1225 of file migrate.py.

Here is the caller graph for this function:

◆ _comparable_plans()

list[dict[str, object]] oc_chat.registry.migrate._comparable_plans ( Sequence[Mapping[str, object]] rows)
protected

Definition at line 1241 of file migrate.py.

Here is the caller graph for this function:

◆ _comparable_queue_entries()

list[dict[str, object]] oc_chat.registry.migrate._comparable_queue_entries ( Sequence[Mapping[str, object]] rows)
protected

Definition at line 1268 of file migrate.py.

Here is the caller graph for this function:

◆ _comparable_round_plans()

list[dict[str, object]] oc_chat.registry.migrate._comparable_round_plans ( Sequence[Mapping[str, object]] rows)
protected

Definition at line 1297 of file migrate.py.

Here is the caller graph for this function:

◆ _comparable_rounds()

list[dict[str, object]] oc_chat.registry.migrate._comparable_rounds ( Sequence[Mapping[str, object]] rows)
protected

Definition at line 1281 of file migrate.py.

Here is the caller graph for this function:

◆ _dedupe_plan_ids_by_number()

set[str] oc_chat.registry.migrate._dedupe_plan_ids_by_number ( set[str] plan_ids,
Mapping[str, PlanHeader] headers,
Mapping[str, QueueEntry] pending,
Mapping[str, str] completed,
Mapping[str, StatusSource] status_sources,
list[str] warnings )
protected

Definition at line 837 of file migrate.py.

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

◆ _discover_round_evidence()

list[RoundEvidence] oc_chat.registry.migrate._discover_round_evidence ( Path root)
protected

Definition at line 756 of file migrate.py.

Here is the caller graph for this function:

◆ _discover_status_paths()

list[Path] oc_chat.registry.migrate._discover_status_paths ( Path root)
protected

Definition at line 722 of file migrate.py.

Here is the caller graph for this function:

◆ _display_path()

str oc_chat.registry.migrate._display_path ( Path path,
Path root )
protected

Definition at line 1163 of file migrate.py.

Here is the caller graph for this function:

◆ _first_model()

str | None oc_chat.registry.migrate._first_model ( object value)
protected

Definition at line 1132 of file migrate.py.

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

◆ _first_nonempty_line()

str | None oc_chat.registry.migrate._first_nonempty_line ( str text)
protected

Definition at line 1196 of file migrate.py.

Here is the caller graph for this function:

◆ _first_text()

str | None oc_chat.registry.migrate._first_text ( *object values)
protected

Definition at line 1188 of file migrate.py.

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

◆ _header_value()

str | None oc_chat.registry.migrate._header_value ( str text,
str name )
protected

Definition at line 1033 of file migrate.py.

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

◆ _looks_small_model()

bool oc_chat.registry.migrate._looks_small_model ( str | None model)
protected

Definition at line 1143 of file migrate.py.

Here is the caller graph for this function:

◆ _main_sha()

str | None oc_chat.registry.migrate._main_sha ( Path root)
protected

Definition at line 801 of file migrate.py.

Here is the caller graph for this function:

◆ _map_legacy_status()

dict[str, object] | None oc_chat.registry.migrate._map_legacy_status ( str plan_id,
int plan_number,
str legacy_status,
StatusSource | None source,
RoundEvidence | None evidence,
str | None discovered_sha,
list[str] errors )
protected

Definition at line 885 of file migrate.py.

Here is the caller graph for this function:

◆ _normalise_branch()

str | None oc_chat.registry.migrate._normalise_branch ( str | None value)
protected

Definition at line 1065 of file migrate.py.

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

◆ _normalise_header_status()

str | None oc_chat.registry.migrate._normalise_header_status ( object value)
protected

Definition at line 1103 of file migrate.py.

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

◆ _normalise_legacy_status()

str oc_chat.registry.migrate._normalise_legacy_status ( object value)
protected

Definition at line 1095 of file migrate.py.

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

◆ _optional_text()

str | None oc_chat.registry.migrate._optional_text ( object value)
protected

Definition at line 1179 of file migrate.py.

Here is the caller graph for this function:

◆ _parse_suggested_model()

tuple[str | None, str | None, str | None] oc_chat.registry.migrate._parse_suggested_model ( str text)
protected

Definition at line 1042 of file migrate.py.

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

◆ _parse_title()

str oc_chat.registry.migrate._parse_title ( str text,
str plan_id )
protected

Definition at line 1028 of file migrate.py.

Here is the caller graph for this function:

◆ _placeholder_header()

PlanHeader oc_chat.registry.migrate._placeholder_header ( str plan_id,
Path plan_dir,
Path root )
protected

Definition at line 983 of file migrate.py.

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

◆ _plan_number()

int oc_chat.registry.migrate._plan_number ( str plan_id,
Mapping[str, PlanHeader] headers )
protected

Definition at line 864 of file migrate.py.

Here is the caller graph for this function:

◆ _plan_payload()

dict[str, object] oc_chat.registry.migrate._plan_payload ( str plan_id,
PlanHeader header,
str legacy_status,
Mapping[str, object] mapped,
str source_file )
protected

Definition at line 949 of file migrate.py.

Here is the caller graph for this function:

◆ _plan_priority()

tuple[int, str] oc_chat.registry.migrate._plan_priority ( str plan_id,
Mapping[str, QueueEntry] pending,
Mapping[str, str] completed,
Mapping[str, StatusSource] status_sources )
protected

Definition at line 872 of file migrate.py.

Here is the caller graph for this function:

◆ _plan_sort_key()

tuple[int, str] oc_chat.registry.migrate._plan_sort_key ( str plan_id)
protected

Definition at line 1204 of file migrate.py.

◆ _provider_from_model()

str | None oc_chat.registry.migrate._provider_from_model ( str | None model)
protected

Definition at line 1150 of file migrate.py.

Here is the caller graph for this function:

◆ _read_plan_headers()

dict[str, PlanHeader] oc_chat.registry.migrate._read_plan_headers ( Path plan_dir,
Path root )
protected

Definition at line 629 of file migrate.py.

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

◆ _read_queue_entries()

tuple[dict[str, QueueEntry], dict[str, str]] oc_chat.registry.migrate._read_queue_entries ( Path queue_path,
Path root )
protected

Definition at line 602 of file migrate.py.

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

◆ _read_status_source()

StatusSource oc_chat.registry.migrate._read_status_source ( Path path,
Path root,
str observed_at )
protected

Definition at line 679 of file migrate.py.

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

◆ _read_status_sources()

dict[str, StatusSource] oc_chat.registry.migrate._read_status_sources ( tuple[Path, ...] | None explicit_paths,
Path root,
str observed_at,
list[str] warnings )
protected

Definition at line 659 of file migrate.py.

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

◆ _result_dict()

dict[str, object] oc_chat.registry.migrate._result_dict ( object value)
protected

Definition at line 1328 of file migrate.py.

Here is the caller graph for this function:

◆ _round_evidence_by_plan()

dict[str, RoundEvidence] oc_chat.registry.migrate._round_evidence_by_plan ( MigrationOptions options,
Path root )
protected

Definition at line 743 of file migrate.py.

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

◆ _round_row()

dict[str, object] oc_chat.registry.migrate._round_row ( RoundEvidence evidence)
protected

Definition at line 971 of file migrate.py.

Here is the caller graph for this function:

◆ _select_legacy_status()

str oc_chat.registry.migrate._select_legacy_status ( str plan_id,
PlanHeader header,
StatusSource | None source,
Mapping[str, QueueEntry] pending,
Mapping[str, str] completed )
protected

Definition at line 819 of file migrate.py.

Here is the caller graph for this function:

◆ _select_overrides()

tuple[str | None, str | None, str | None] oc_chat.registry.migrate._select_overrides ( PlanHeader header,
StatusSource | None source,
QueueEntry | None queue_entry )
protected

Definition at line 1016 of file migrate.py.

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

◆ _snapshot_diff()

dict[str, object] oc_chat.registry.migrate._snapshot_diff ( Mapping[str, object] expected,
Mapping[str, object] actual )
protected

Definition at line 1310 of file migrate.py.

Here is the caller graph for this function:

◆ _sqlite_backend()

SQLiteBackend oc_chat.registry.migrate._sqlite_backend ( Registry registry)
protected

Definition at line 1218 of file migrate.py.

Here is the caller graph for this function:

◆ _string_timestamp()

str | None oc_chat.registry.migrate._string_timestamp ( object value)
protected

Definition at line 1170 of file migrate.py.

Here is the caller graph for this function:

◆ audit_null_closed_round_backfills()

dict[str, object] oc_chat.registry.migrate.audit_null_closed_round_backfills ( Registry registry)
Check the migration backfill marker post-condition.

Definition at line 555 of file migrate.py.

Here is the call graph for this function:

◆ build_projection()

MigrationProjection oc_chat.registry.migrate.build_projection ( Registry registry,
MigrationOptions options )
Build the deterministic legacy-to-registry projection.

Definition at line 277 of file migrate.py.

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

◆ run_cutover_stub()

CutoverResult oc_chat.registry.migrate.run_cutover_stub ( )
Return the v0.2.x cutover placeholder.

Definition at line 545 of file migrate.py.

◆ run_import()

ImportResult oc_chat.registry.migrate.run_import ( Registry registry,
MigrationOptions options,
* ,
bool dry_run = False )
Dry-run or apply the legacy migration projection.

Definition at line 436 of file migrate.py.

Here is the call graph for this function:

◆ run_rollback()

RollbackResult oc_chat.registry.migrate.run_rollback ( Registry registry,
MigrationOptions options )
Restore the most recent pre-migration backup.

Definition at line 525 of file migrate.py.

Here is the call graph for this function:

◆ run_verify()

VerifyResult oc_chat.registry.migrate.run_verify ( Registry registry,
MigrationOptions options )
Compare the projected legacy state with the registry tables.

Definition at line 498 of file migrate.py.

Here is the call graph for this function:

Variable Documentation

◆ H1_RE

oc_chat.registry.migrate.H1_RE = re.compile(r"^#\s+(?P<value>.+?)\s*$", re.MULTILINE)

Definition at line 96 of file migrate.py.

◆ HEADER_PATTERNS

dict oc_chat.registry.migrate.HEADER_PATTERNS
Initial value:
1= {
2 "branch": re.compile(
3 # OCT-LINT: disable=no_hardcoded_secrets reason="Regexes and model-family literals are parser fixtures, not secrets"
4 r"^\*\*Branch:\*\*\s*(?:`(?P<ticks>[^`\n]+)`|(?P<plain>\S+))",
5 re.IGNORECASE | re.MULTILINE,
6 ),
7 "worktree": re.compile(
8 # OCT-LINT: disable=no_hardcoded_secrets reason="Regexes and model-family literals are parser fixtures, not secrets"
9 r"^\*\*Worktree:\*\*\s*(?:`(?P<ticks>[^`\n]+)`|(?P<plain>\S+))",
10 re.IGNORECASE | re.MULTILINE,
11 ),
12 "plan_type": re.compile(
13 r"^\*\*Plan Type:\*\*\s*(?P<value>.+?)\s*$",
14 re.IGNORECASE | re.MULTILINE,
15 ),
16 "status": re.compile(
17 r"^\*\*Status:\*\*\s*(?P<value>.+?)\s*$",
18 re.IGNORECASE | re.MULTILINE,
19 ),
20 "suggested_model": re.compile(
21 r"^\*\*Suggested model:\*\*\s*(?P<value>.+?)\s*$",
22 re.IGNORECASE | re.MULTILINE,
23 ),
24}

Definition at line 72 of file migrate.py.

◆ LEGACY_PLAN_ID_RE

oc_chat.registry.migrate.LEGACY_PLAN_ID_RE = re.compile(r"\b\d{3}-[A-Za-z0-9][A-Za-z0-9_.-]*\b")

Definition at line 70 of file migrate.py.

◆ PLAN_ID_RE

oc_chat.registry.migrate.PLAN_ID_RE = re.compile(r"^(?P<number>\d{3})-(?P<slug>.+)$")

Definition at line 69 of file migrate.py.

◆ PRE_ROUND_SYSTEM_PLAN_CEILING

int oc_chat.registry.migrate.PRE_ROUND_SYSTEM_PLAN_CEILING = 50

Definition at line 118 of file migrate.py.

◆ ROUND_RE

oc_chat.registry.migrate.ROUND_RE = re.compile(r"\bround[-\s]*(?P<round>\d+)\b", re.IGNORECASE)

Definition at line 71 of file migrate.py.

◆ STATUS_NORMALISATIONS

dict oc_chat.registry.migrate.STATUS_NORMALISATIONS
Initial value:
1= {
2 "queued": "Pending",
3 "queue": "Pending",
4 "pending": "Pending",
5 "implementing": "In Progress",
6 "in progress": "In Progress",
7 "in-progress": "In Progress",
8 "completed": "Completed",
9 "partially completed": "Partial",
10 "partial": "Partial",
11 "failed": "Failed",
12 "blocked": "Blocked",
13}

Definition at line 105 of file migrate.py.

◆ VALID_LEGACY_STATUSES

dict oc_chat.registry.migrate.VALID_LEGACY_STATUSES
Initial value:
1= {
2 "Completed",
3 "In Progress",
4 "Blocked",
5 "Failed",
6 "Partial",
7 "Pending",
8}

Definition at line 97 of file migrate.py.