feat(event-bridge): WP-0003a — domain model, rules module, event type registry

Implements phases 7–8 of the Event Bridge architecture (custodian-WP-0003a).

Domain model (T34, T40):
- Added RuleDef, InstructionDef, ActionDef to models.py
- Updated ActivityDefinition with rules/instructions fields (task_templates deprecated)
- Formalized EventEnvelope: id, type, version, timestamp, publisher, attributes
- Added from_nats_message() and from_webhook_payload() classmethods

Rules module (T35, T36, T37):
- src/activity_core/rules/ skeleton with boundary enforcement
- evaluate_condition() — sandboxed AST walker, whitelisted nodes only, never exec()
- execute_instruction() — LLM task generation with trusted_fields injection guard
- tests/rules/test_boundary.py verifies no cross-boundary imports

Infrastructure (T38, T39):
- Alembic migrations 0004 (task_spawn_log) and 0005 (event_types)
- IssueSink ABC + IssueCoreRestSink (REST) + NullSink (testing)
- TaskSpawnLog and EventType ORM models

Event type registry (T41, T42, T43):
- event_type_registry.py: file scanner, parser, DB sync, in-process lookup
- ACTIVITY_CURATOR_GATE env var (disabled|required) + approve endpoint
- Three org event type definitions: org.repo.registered, org.workstream.completed,
  org.activity.run.completed

All 10 tests pass. Boundary test confirms rules/ isolation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-14 22:01:15 +02:00
parent ee81adb2fa
commit c3a256509b
22 changed files with 1281 additions and 137 deletions

View File

@@ -0,0 +1,66 @@
"""create_task_spawn_log
Revision ID: 0004
Revises: 0003
Create Date: 2026-05-14
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
revision: str = "0004"
down_revision: Union[str, Sequence[str], None] = "0003"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"task_spawn_log",
sa.Column(
"id",
sa.UUID(),
nullable=False,
server_default=sa.text("gen_random_uuid()"),
),
sa.Column("activity_def_id", sa.UUID(), nullable=False),
sa.Column("source_type", sa.String(20), nullable=False),
sa.Column("source_id", sa.Text(), nullable=False),
sa.Column("source_version", sa.Text(), nullable=False),
sa.Column("triggering_event_id", sa.Text(), nullable=False),
sa.Column("task_ref", sa.Text(), nullable=True),
sa.Column("condition_matched", sa.Text(), nullable=True),
sa.Column("prompt_hash", sa.CHAR(64), nullable=True),
sa.Column("model", sa.Text(), nullable=True),
sa.Column("output_validated", sa.Boolean(), nullable=True),
sa.Column("review_required", sa.Boolean(), nullable=True),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
nullable=False,
server_default=sa.text("now()"),
),
sa.ForeignKeyConstraint(
["activity_def_id"],
["activity_definitions.id"],
),
sa.PrimaryKeyConstraint("id"),
)
op.create_index(
"idx_spawn_log_event",
"task_spawn_log",
["triggering_event_id"],
)
op.create_index(
"idx_spawn_log_def",
"task_spawn_log",
["activity_def_id"],
)
def downgrade() -> None:
op.drop_index("idx_spawn_log_def", table_name="task_spawn_log")
op.drop_index("idx_spawn_log_event", table_name="task_spawn_log")
op.drop_table("task_spawn_log")

View File

@@ -0,0 +1,51 @@
"""create_event_types
Revision ID: 0005
Revises: 0004
Create Date: 2026-05-14
"""
from typing import Sequence, Union
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects.postgresql import JSONB
revision: str = "0005"
down_revision: Union[str, Sequence[str], None] = "0004"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"event_types",
sa.Column("type_id", sa.Text(), nullable=False),
sa.Column("version", sa.Text(), nullable=False),
sa.Column("publisher", sa.Text(), nullable=False),
sa.Column(
"governance",
sa.Text(),
nullable=False,
server_default="publisher-declared",
),
sa.Column(
"status",
sa.Text(),
nullable=False,
server_default="active",
),
sa.Column("attribute_schema", JSONB(), nullable=False),
sa.Column("raw_md", sa.Text(), nullable=False),
sa.Column(
"synced_at",
sa.DateTime(timezone=True),
nullable=False,
server_default=sa.text("now()"),
),
sa.PrimaryKeyConstraint("type_id"),
)
def downgrade() -> None:
op.drop_table("event_types")