oc_chat
Loading...
Searching...
No Matches
__init__.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# oc_chat/registry/render/__init__.py
4
5# OCT-LINT: disable=tests_exist reason="Covered by oc_chat/tests/registry/test_render_determinism.py and test_sync_cli.py"
6"""
7Registry render orchestration.
8
9Purpose
10-------
11Expose the public `render_all` orchestration entry point for registry-backed
12filesystem artifacts.
13
14Responsibilities
15----------------
16- Dispatch to each artifact renderer in a deterministic order.
17- Apply shared `prefer_local`, `dry_run`, and artifact filtering options.
18- Return an aggregate `RenderReport` for CLI and doctor consumers.
19
20Diagnostics
21-----------
22Domain: OC_CHAT.MAIN
23Levels:
24 L2 - render-all lifecycle events
25 L3 - artifact selection details
26 L4 - per-artifact dispatch tracing
27
28Contracts
29---------
30- `render_all` mutates files only through artifact writers.
31- Registry state is read-only during rendering.
32
33Dependencies
34------------
35- oc_diagnostics (structured debug logging via _dbg)
36- oc_chat.registry.api (Registry facade the artifacts are rendered from)
37- oc_chat.registry.render._common (RenderReport, RenderResult and the worktree plan rows)
38- oc_chat.registry.render.plan_header (plan header artifact writer)
39- oc_chat.registry.render.plan_status (plan status artifact writer)
40"""
41from __future__ import annotations
42
43from pathlib import Path
44from typing import Iterable
45
46from oc_diagnostics import _dbg
47
48from oc_chat.registry.api import Registry
50 RenderReport,
51 RenderResult,
52 iter_worktree_plans,
53)
54from oc_chat.registry.render.plan_header import write_plan_header
55from oc_chat.registry.render.plan_status import write_plan_status
56
57# The legacy versioned roadmap artifacts are retired (Plan 142 cutover): the living
58# set is rendered by `oc_chat.registry.roadmap render` (write_living_set), NOT by
59# render_all. ``ROADMAP_ARTIFACTS`` was empty, so the old render_all roadmap branch
60# was dead — removed here.
61#
62# The ``agent_queue`` and ``launch_prompt`` artifacts retired with the queue
63# machinery (plan 223 P3, design §4.8). The first re-materialised the Markdown
64# queue that is now archived history; the second wrote the slot-named
65# ``.oc_chat/launch/agent-<x>.md`` files whose staleness was the F33
66# duplicate-launch failure class. Launch files are rendered per PLAN by
67# ``plan_manage dispatch`` from the one committed template, and the pool is a
68# registry view (``plan_manage agents active``), not a rendered file.
69
70_dbg("OC_CHAT.MAIN", "module", "loaded", 4)
71
72DEFAULT_ARTIFACTS = frozenset({"plan_status", "plan_header"})
73ALL_ARTIFACTS = DEFAULT_ARTIFACTS
74
75
77 registry: Registry,
78 *,
79 target_root: Path,
80 prefer_local: bool = False,
81 dry_run: bool = False,
82 artifacts: Iterable[str] | None = None,
83) -> RenderReport:
84 """Render all requested registry-backed filesystem artifacts."""
85
86 selected = set(DEFAULT_ARTIFACTS if artifacts is None else artifacts)
87 results: list[RenderResult] = []
88 worktree_rows = list(iter_worktree_plans(registry))
89 if "plan_status" in selected:
90 for row in worktree_rows:
91 worktree = row.get("worktree")
92 if worktree:
93 results.append(
94 write_plan_status(
95 registry,
96 worktree=Path(str(worktree)),
97 prefer_local=prefer_local,
98 dry_run=dry_run,
99 )
100 )
101 if "plan_header" in selected:
102 for row in worktree_rows:
103 body_path = row.get("body_path")
104 if body_path:
105 results.append(
106 write_plan_header(
107 registry,
108 plan_id=str(row["plan_id"]),
109 plan_file=target_root / str(body_path),
110 prefer_local=prefer_local,
111 dry_run=dry_run,
112 )
113 )
114 return RenderReport(tuple(results))
115
116
117__all__ = [
118 "DEFAULT_ARTIFACTS",
119 "ALL_ARTIFACTS",
120 "RenderReport",
121 "RenderResult",
122 "render_all",
123]
RenderReport render_all(Registry registry, *, Path target_root, bool prefer_local=False, bool dry_run=False, Iterable[str]|None artifacts=None)
Definition __init__.py:83