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:
parent
ee81adb2fa
commit
c3a256509b
22 changed files with 1281 additions and 137 deletions
|
|
@ -14,6 +14,7 @@ from sqlalchemy import (
|
|||
DateTime,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
func,
|
||||
)
|
||||
|
|
@ -75,6 +76,48 @@ class ActivityRun(Base):
|
|||
version_used: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
|
||||
|
||||
class TaskSpawnLog(Base):
|
||||
__tablename__ = "task_spawn_log"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
|
||||
)
|
||||
activity_def_id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("activity_definitions.id"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
source_type: Mapped[str] = mapped_column(String(20), nullable=False)
|
||||
source_id: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
source_version: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
triggering_event_id: Mapped[str] = mapped_column(Text, nullable=False, index=True)
|
||||
task_ref: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
condition_matched: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
prompt_hash: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
model: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
output_validated: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
|
||||
review_required: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||||
)
|
||||
|
||||
|
||||
class EventType(Base):
|
||||
__tablename__ = "event_types"
|
||||
|
||||
type_id: Mapped[str] = mapped_column(Text, primary_key=True)
|
||||
version: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
publisher: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
governance: Mapped[str] = mapped_column(Text, nullable=False, default="publisher-declared")
|
||||
status: Mapped[str] = mapped_column(Text, nullable=False, default="active")
|
||||
attribute_schema: Mapped[dict] = mapped_column(JSONB, nullable=False)
|
||||
raw_md: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
synced_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||||
)
|
||||
|
||||
|
||||
class TaskInstance(Base):
|
||||
__tablename__ = "task_instances"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue