|
| tuple[str, str]|None | parse_plan_filename (str name) |
| Path|None | _find_plan_file (Path plans_dir, str plan_id) |
| None | _rename_to_state (Path plans_dir, str plan_id, str new_status) |
| tuple[PlanInventory, Path] | _resolve_inventory (PlanInventory|None inventory, Path plans_dir) |
| tuple[str, Path] | create_plan (str description, str|None session_name=None, *, PlanInventory|None inventory=None, Path|None plans_dir=None) |
| PlanRecord | _transition (str plan_id, str new_status, PlanInventory|None inventory, Path|None plans_dir) |
| PlanRecord | pause_plan (str plan_id, *, PlanInventory|None inventory=None, Path|None plans_dir=None) |
| PlanRecord | continue_plan (str plan_id, *, PlanInventory|None inventory=None, Path|None plans_dir=None) |
| PlanRecord | complete_plan (str plan_id, *, PlanInventory|None inventory=None, Path|None plans_dir=None) |
| PlanRecord | abort_plan (str plan_id, *, PlanInventory|None inventory=None, Path|None plans_dir=None) |
| list[PlanRecord] | list_plans (*, PlanInventory|None inventory=None) |
| PlanRecord|None | find_plan_by_id (str plan_id_or_prefix, *, PlanInventory|None inventory=None) |
| str|None | get_plan_status (str plan_id, *, PlanInventory|None inventory=None) |
High-level plan operations on top of the plan inventory.
Purpose
-------
Public functions that combine inventory writes with filename mirroring.
Every state-change operation follows the protocol:
1. Inventory write FIRST (atomic).
2. Filename rename SECOND.
3. On filename failure, inventory still correct; next call's
reconcile() heals the filename.
Responsibilities
----------------
- :func:`create_plan` — allocate next prefix, generate kebab-case stem,
register inventory record, return ``(plan_id, path)``. Does NOT
create the file on disk; the agent is expected to ``write_file`` it.
- :func:`pause_plan`, :func:`continue_plan`, :func:`complete_plan`,
:func:`abort_plan` — lifecycle transitions.
- :func:`list_plans` — return all records (from inventory), grouped or
not by status as the caller wishes.
- :func:`find_plan_by_id` — resolve a 3-digit prefix OR full stem to a
``PlanRecord``. Returns ``None`` for ambiguous prefix.
- :func:`get_plan_status` — convenience wrapper for ``inventory.get(id).status``.
- :func:`parse_plan_filename` — regex helper exposed for callers.
Diagnostics
-----------
Domain: OC_CHAT.MAIN
Levels:
L2 — high-level operation lifecycle
L3 — semantic details (plan_id, prefix, status transition)
L4 — deep tracing (filesystem rename attempts, reconcile diffs)
Contracts
---------
- All public mutators raise :class:`KeyError` for unknown plan_ids.
- :func:`continue_plan` raises :class:`ValueError` if the plan is not
currently paused. :func:`complete_plan` / :func:`abort_plan` raise on
terminal-to-terminal transitions.
- :func:`create_plan` writes to inventory and chooses a filename, but
does NOT create the file on disk.
- :func:`find_plan_by_id` returns the matching record or ``None``.
Raises :class:`ValueError` only when the input is ambiguous
(multiple matches by prefix).
Dependencies
------------
- oc_diagnostics (structured debug logging via _dbg)
- oc_orchestrator.plan_inventory (PlanInventory, get_inventory, reconcile)
- oc_orchestrator.wordgen (random_plan_filename)