5# OCT-LINT: disable=tests_exist reason="Covered by tests/test_270_standalone_dispatch.py (no observers reached) and oc_chat's plan-257 registry-mirror witnesses"
6"""
7Plan-state observation seam for the dispatch layer.
8
9Purpose
10-------
11Plan 257 P1 (A7, cut 1). The worker status tool used to reach into
12``oc_chat.registry`` directly to mirror every ``.PLAN_STATUS.md``
13lifecycle event into the orchestration registry. That coupling is the
14single largest edge out of the dispatch layer, and it is the one the
15orchestrator-extraction measurement keeps having to model as a cut.
16
17This module inverts it. The dispatch layer now announces what happened
18to a plan and knows nothing about who is listening; the registry side
19supplies a listener that does the mirroring. Nothing observable
20changes, because the status tool still registers that listener by
21default.
22
23Responsibilities
24----------------
25- :class:`StateObserver` -- the callback contract a listener implements.
26 Two callbacks, derived from what the status tool actually emits: a
27 plan was created, and a plan's status changed.
28- :data:`NO_OBSERVERS` -- the empty default, for callers that want the
29 dispatch layer to touch nothing but the status file.
30
31Diagnostics
32-----------
33Domain: OC_CHAT.MAIN
34Levels:
35 L2 - lifecycle events (module load)
36 L3 - semantic details
37 L4 - deep tracing
38
39Contracts
40---------
41- A callback returns a process exit code: ``0`` when the observation was
42 recorded or deliberately skipped, non-zero when the caller should
43 abort with that code. This mirrors the pre-257 ``_mirror_*`` helpers
44 byte for byte: a mirroring failure is reported and returns ``2``, it
45 never raises into the status tool.
46- Every argument is a plain string, integer or ``None``. The contract
47 carries no dispatch-layer type, so an implementation on the registry
48 side needs no import back into ``oc_chat.scripts``.
49- This module imports nothing from ``oc_chat.registry`` and nothing
50 from ``oc_chat.core`` -- it is a leaf of the dispatch layer.
51
52Dependencies
53------------
54- oc_diagnostics (structured debug logging via _dbg)