oc_chat
Loading...
Searching...
No Matches
operations.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# oc_chat/registry/roadmap/operations.py
4
5# OCT-LINT: disable=tests_exist reason="Covered by oc_chat/tests/registry/roadmap/test_operations.py"
6"""
7Roadmap registry operation executors.
8
9Purpose
10-------
11Expose typed helpers for the roadmap v0.3 operation catalog.
12
13Responsibilities
14----------------
15- Build versioned payloads for roadmap item, version, phase, section, and
16 plan-link operations.
17- Require HMAC proof for non-system callers before invoking the registry seam.
18- Keep SQL ownership inside the SQLite backend projection layer.
19
20Diagnostics
21-----------
22Domain: OC_CHAT.MAIN
23Levels:
24 L2 - operation helper lifecycle
25 L3 - payload construction details
26 L4 - preflight validation details
27
28Contracts
29---------
30- Every mutating helper calls Registry.execute_domain_command.
31- The module performs no direct SQL, filesystem, subprocess, or clock work.
32
33Dependencies
34------------
35- oc_chat.registry.api (Registry facade)
36- oc_chat.registry.errors (HMAC preflight error)
37- oc_chat.registry.backends.base (OperationLogRow type returned by each helper)
38- oc_diagnostics (structured debug logging via _dbg)
39"""
40from __future__ import annotations
41
42from typing import Literal, Mapping
43
44from oc_diagnostics import _dbg
45
46from oc_chat.registry.api import Registry
47from oc_chat.registry.backends.base import OperationLogRow
48from oc_chat.registry.errors import HmacVerifyError
49
50_dbg("OC_CHAT.MAIN", "module", "loaded", 4)
51
52ActorType = Literal["human_operator", "orchestrator_agent", "worker_agent"]
53RoadmapStatus = Literal["todo", "in_progress", "done", "deferred", "blocked", "superseded"]
54RoadmapPriority = Literal["critical", "high", "medium", "lower"]
55RoadmapTrackKind = Literal["m_phase", "backlog", "vision", "git_workflow", "pre_m0_era"]
56DependencyKind = Literal["blocks", "enables", "gates", "part_of"]
57ContributionKind = Literal["full", "partial", "context_only"]
58
59
61 registry: Registry,
62 *,
63 item_id: str,
64 title: str,
65 actor_slot: str,
66 actor_type: ActorType,
67 track_kind: RoadmapTrackKind = "m_phase",
68 phase_code: str | None = None,
69 phase_label: str | None = None,
70 parent_item_id: str | None = None,
71 prose: str | None = None,
72 prose_path: str | None = None,
73 status: RoadmapStatus = "todo",
74 priority: RoadmapPriority | None = None,
75 sort_order: int = 0,
76 target_version: str | None = None,
77 introduced_in_version_id: str | None = None,
78 closed_in_version_id: str | None = None,
79 closed_round_no: int | None = None,
80 superseded_by_item_id: str | None = None,
81 command: str | None = None,
82 auth_proof: Mapping[str, object] | None = None,
83 system_actor: bool = False,
84) -> OperationLogRow:
85 """Create or upsert a roadmap item through the registry seam."""
86
87 _require_auth(auth_proof, system_actor, command or "roadmap_item.create", actor_slot)
88 return registry.execute_domain_command(
89 "roadmap_item.create",
90 actor_slot,
91 {
92 "version": 1,
93 "item_id": item_id,
94 "title": title,
95 "track_kind": track_kind,
96 "phase_code": phase_code,
97 "phase_label": phase_label,
98 "parent_item_id": parent_item_id,
99 "prose": prose,
100 "prose_path": prose_path,
101 "status": status,
102 "priority": priority,
103 "sort_order": sort_order,
104 "target_version": target_version,
105 "introduced_in_version_id": introduced_in_version_id,
106 "closed_in_version_id": closed_in_version_id,
107 "closed_round_no": closed_round_no,
108 "superseded_by_item_id": superseded_by_item_id,
109 },
110 actor_type=actor_type,
111 command=command,
112 auth_proof=auth_proof,
113 system_actor=system_actor,
114 )
115
116
118 registry: Registry,
119 *,
120 item_id: str,
121 from_status: RoadmapStatus | None,
122 to_status: RoadmapStatus,
123 actor_slot: str,
124 actor_type: ActorType,
125 in_version_id: str | None = None,
126 closed_round_no: int | None = None,
127 superseded_by_item_id: str | None = None,
128 note: str | None = None,
129 command: str | None = None,
130 auth_proof: Mapping[str, object] | None = None,
131 system_actor: bool = False,
132) -> OperationLogRow:
133 """Set a roadmap item status and append a roadmap item event."""
134
135 _require_auth(auth_proof, system_actor, command or "roadmap_item.set_status", actor_slot)
136 return registry.execute_domain_command(
137 "roadmap_item.set_status",
138 actor_slot,
139 {
140 "version": 1,
141 "item_id": item_id,
142 "from_status": from_status,
143 "to_status": to_status,
144 "in_version_id": in_version_id,
145 "closed_round_no": closed_round_no,
146 "superseded_by_item_id": superseded_by_item_id,
147 "note": note,
148 },
149 actor_type=actor_type,
150 command=command,
151 auth_proof=auth_proof,
152 system_actor=system_actor,
153 )
154
155
157 registry: Registry,
158 *,
159 from_item_id: str,
160 to_item_id: str,
161 actor_slot: str,
162 actor_type: ActorType,
163 kind: DependencyKind = "gates",
164 in_version_id: str | None = None,
165 note: str | None = None,
166 command: str | None = None,
167 auth_proof: Mapping[str, object] | None = None,
168 system_actor: bool = False,
169) -> OperationLogRow:
170 """Create an item-to-item dependency."""
171
172 if from_item_id == to_item_id:
173 raise ValueError("roadmap dependency cannot point to itself")
174 _require_auth(auth_proof, system_actor, command or "roadmap_item.add_dependency", actor_slot)
175 return registry.execute_domain_command(
176 "roadmap_item.add_dependency",
177 actor_slot,
178 {
179 "version": 1,
180 "from_item_id": from_item_id,
181 "to_item_id": to_item_id,
182 "kind": kind,
183 "in_version_id": in_version_id,
184 "note": note,
185 },
186 actor_type=actor_type,
187 command=command,
188 auth_proof=auth_proof,
189 system_actor=system_actor,
190 )
191
192
194 registry: Registry,
195 *,
196 from_version_id: str | None,
197 to_version_id: str,
198 actor_slot: str,
199 actor_type: ActorType,
200 bump_kind: Literal["patch", "minor", "major", "out_of_round_revision"] = "patch",
201 era_id: str | None = None,
202 status: Literal["draft", "current", "superseded"] = "draft",
203 released_at: str | None = None,
204 last_updated_at: str | None = None,
205 source_round_no: int | None = None,
206 notes: str | None = None,
207 command: str | None = None,
208 auth_proof: Mapping[str, object] | None = None,
209 system_actor: bool = False,
210) -> OperationLogRow:
211 """Create a new roadmap version row."""
212
213 _require_auth(auth_proof, system_actor, command or "roadmap_version.bump", actor_slot)
214 return registry.execute_domain_command(
215 "roadmap_version.bump",
216 actor_slot,
217 {
218 "version": 1,
219 "from_version_id": from_version_id,
220 "to_version_id": to_version_id,
221 "era_id": era_id,
222 "status": status,
223 "released_at": released_at,
224 "last_updated_at": last_updated_at,
225 "source_round_no": source_round_no,
226 "bump_kind": bump_kind,
227 "notes": notes,
228 },
229 actor_type=actor_type,
230 command=command,
231 auth_proof=auth_proof,
232 system_actor=system_actor,
233 )
234
235
237 registry: Registry,
238 *,
239 phase_code: str,
240 actor_slot: str,
241 actor_type: ActorType,
242 in_version_id: str | None = None,
243 note: str | None = None,
244 command: str | None = None,
245 auth_proof: Mapping[str, object] | None = None,
246 system_actor: bool = False,
247) -> OperationLogRow:
248 """Mark a roadmap phase complete."""
249
250 _require_auth(auth_proof, system_actor, command or "roadmap_phase.complete", actor_slot)
251 return registry.execute_domain_command(
252 "roadmap_phase.complete",
253 actor_slot,
254 {
255 "version": 1,
256 "phase_code": phase_code,
257 "in_version_id": in_version_id,
258 "note": note,
259 },
260 actor_type=actor_type,
261 command=command,
262 auth_proof=auth_proof,
263 system_actor=system_actor,
264 )
265
266
268 registry: Registry,
269 *,
270 file_kind: str,
271 section_path: str,
272 sort_order: int,
273 query_kind: str,
274 actor_slot: str,
275 actor_type: ActorType,
276 query_params_json: str | None = None,
277 required_min_version: str | None = None,
278 active: bool = True,
279 command: str | None = None,
280 auth_proof: Mapping[str, object] | None = None,
281 system_actor: bool = False,
282) -> OperationLogRow:
283 """Upsert roadmap render-section configuration."""
284
285 _require_auth(auth_proof, system_actor, command or "roadmap_section.upsert", actor_slot)
286 return registry.execute_domain_command(
287 "roadmap_section.upsert",
288 actor_slot,
289 {
290 "version": 1,
291 "file_kind": file_kind,
292 "section_path": section_path,
293 "sort_order": sort_order,
294 "query_kind": query_kind,
295 "query_params_json": query_params_json,
296 "required_min_version": required_min_version,
297 "active": active,
298 },
299 actor_type=actor_type,
300 command=command,
301 auth_proof=auth_proof,
302 system_actor=system_actor,
303 )
304
305
307 registry: Registry,
308 *,
309 plan_id: str,
310 item_id: str,
311 actor_slot: str,
312 actor_type: ActorType,
313 contribution: ContributionKind = "partial",
314 command: str | None = None,
315 auth_proof: Mapping[str, object] | None = None,
316 system_actor: bool = False,
317) -> OperationLogRow:
318 """Link a plan to a roadmap item."""
319
320 _require_auth(auth_proof, system_actor, command or "roadmap_plan_link.create", actor_slot)
321 return registry.execute_domain_command(
322 "roadmap_plan_link.create",
323 actor_slot,
324 {
325 "version": 1,
326 "plan_id": plan_id,
327 "item_id": item_id,
328 "contribution": contribution,
329 },
330 actor_type=actor_type,
331 command=command,
332 related_plan_id=plan_id,
333 auth_proof=auth_proof,
334 system_actor=system_actor,
335 )
336
337
339 auth_proof: Mapping[str, object] | None,
340 system_actor: bool,
341 command: str,
342 actor_slot: str,
343) -> None:
344 if system_actor or auth_proof is not None:
345 return
346 raise HmacVerifyError(
347 attempted_slot=actor_slot,
348 hmac_key_id=None,
349 command=command,
350 failure_reason="missing_auth_proof",
351 )
OperationLogRow roadmap_section_upsert(Registry registry, *, str file_kind, str section_path, int sort_order, str query_kind, str actor_slot, ActorType actor_type, str|None query_params_json=None, str|None required_min_version=None, bool active=True, str|None command=None, Mapping[str, object]|None auth_proof=None, bool system_actor=False)
OperationLogRow roadmap_version_bump(Registry registry, *, str|None from_version_id, str to_version_id, str actor_slot, ActorType actor_type, Literal["patch", "minor", "major", "out_of_round_revision"] bump_kind="patch", str|None era_id=None, Literal["draft", "current", "superseded"] status="draft", str|None released_at=None, str|None last_updated_at=None, int|None source_round_no=None, str|None notes=None, str|None command=None, Mapping[str, object]|None auth_proof=None, bool system_actor=False)
OperationLogRow roadmap_item_create(Registry registry, *, str item_id, str title, str actor_slot, ActorType actor_type, RoadmapTrackKind track_kind="m_phase", str|None phase_code=None, str|None phase_label=None, str|None parent_item_id=None, str|None prose=None, str|None prose_path=None, RoadmapStatus status="todo", RoadmapPriority|None priority=None, int sort_order=0, str|None target_version=None, str|None introduced_in_version_id=None, str|None closed_in_version_id=None, int|None closed_round_no=None, str|None superseded_by_item_id=None, str|None command=None, Mapping[str, object]|None auth_proof=None, bool system_actor=False)
Definition operations.py:84
OperationLogRow roadmap_item_set_status(Registry registry, *, str item_id, RoadmapStatus|None from_status, RoadmapStatus to_status, str actor_slot, ActorType actor_type, str|None in_version_id=None, int|None closed_round_no=None, str|None superseded_by_item_id=None, str|None note=None, str|None command=None, Mapping[str, object]|None auth_proof=None, bool system_actor=False)
OperationLogRow roadmap_item_add_dependency(Registry registry, *, str from_item_id, str to_item_id, str actor_slot, ActorType actor_type, DependencyKind kind="gates", str|None in_version_id=None, str|None note=None, str|None command=None, Mapping[str, object]|None auth_proof=None, bool system_actor=False)
None _require_auth(Mapping[str, object]|None auth_proof, bool system_actor, str command, str actor_slot)
OperationLogRow roadmap_phase_complete(Registry registry, *, str phase_code, str actor_slot, ActorType actor_type, str|None in_version_id=None, str|None note=None, str|None command=None, Mapping[str, object]|None auth_proof=None, bool system_actor=False)
OperationLogRow roadmap_plan_link_create(Registry registry, *, str plan_id, str item_id, str actor_slot, ActorType actor_type, ContributionKind contribution="partial", str|None command=None, Mapping[str, object]|None auth_proof=None, bool system_actor=False)