feat(state-hub): CUST-WP-0040 — NATS lifecycle event publishing for activity-core

Makes the state hub an event publisher so activity-core can drive
maintenance automation declaratively via ActivityDefinitions, rather
than the hub creating tasks itself.

- api/events/: lazy JetStream publisher + EventEnvelope mirroring
  activity-core's contract; no-op when NATS_URL unset, fire-and-forget
  with logged failures so publishing never breaks an API request.
- Wired publishers on the five v1.0 lifecycle events:
    org.statehub.repo.registered        (POST /repos/)
    org.statehub.workstream.completed   (PATCH /workstreams/* on transition)
    org.statehub.decision.resolved      (POST /decisions/*/resolve)
    org.statehub.domain.goal.activated  (POST /domain-goals/*/activate)
    org.statehub.task.stale             (scripts/cleanup_stale_tasks.py)
- docs/nats-event-subjects.md: subject naming convention + catalog.
- docs/cron-migration.md: design stub for replacing custodian-sync
  systemd timer and cleanup-stale cron with ActivityDefinitions
  (depends on activity-core WP-0003).
- docs/activity-core-delegation.md: protocol, invariants, cutover plan.
- SCOPE.md: declares activity-core as downstream event consumer and
  restates that the state hub stays a read model, not a task factory.

Workplan: workplans/CUST-WP-0040-state-hub-nats-activity-core-integration.md
242 tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-17 05:49:29 +02:00
parent 2bc7fd8ce7
commit ca8a09ed04
16 changed files with 770 additions and 9 deletions

View File

@@ -3,33 +3,33 @@ id: CUST-WP-0040
type: workplan
domain: custodian
repo: the-custodian
status: active
status: completed
state_hub_workstream_id: d8ac100b-a844-46a5-9684-415df0d32539
tasks:
- id: T01
title: Connect state hub event publisher to NATS JetStream
state_hub_task_id: c4bfa299-54dd-4ede-b5fa-9ae27dce5b2c
status: todo
status: done
- id: T02
title: Define NATS subject schema for state hub lifecycle events
state_hub_task_id: 2ae236a4-8a16-4998-92dc-83bc48378d3d
status: todo
status: done
- id: T03
title: Implement state hub lifecycle events as NATS EventEnvelopes
state_hub_task_id: ccb5a3fb-d5e5-4781-9e5d-552ad09477f5
status: todo
status: done
- id: T04
title: Migrate state hub maintenance crons to activity-core ActivityDefinitions (design stub)
state_hub_task_id: 933b2a80-cbd6-436f-b092-c39dc6f1c9c4
status: todo
status: done
- id: T05
title: Document state hub → activity-core delegation protocol
state_hub_task_id: b261d4b8-4039-4610-aaad-eb45bf3a51de
status: todo
status: done
- id: T06
title: Update SCOPE.md to reflect activity-core delegation
state_hub_task_id: 356682e6-e608-4f58-b418-cdef2b9435f2
status: todo
status: done
created: "2026-05-14"
---
@@ -168,3 +168,8 @@ T06 (independent — SCOPE.md update)
- v0.1 (2026-05-14): Stub created by activity-core agent during WP-0003 planning.
Local agent to flesh out and implement.
- v0.2 (2026-05-17): All tasks complete. NATS publisher landed at
`state-hub/api/events/`, lifecycle events wired in repos/workstreams/
decisions/domain_goals routers + cleanup_stale_tasks.py. Subject
schema, cron-migration design stub, delegation protocol docs, and
SCOPE.md updates committed.