Skip to main content

Event log library with Lamport clocks and systematic error tracking

Project description

spec-kitty-events

Event log library with Lamport clocks, CRDT merge, and canonical event contracts for distributed systems.

Version: 2.9.0 | SCHEMA_VERSION: 2.0.0 | Python: >= 3.10

Features

  • Lamport Clocks: Establish causal ordering in distributed systems
  • Event Immutability: Events are immutable (frozen Pydantic models)
  • Conflict Detection: Detect concurrent events with is_concurrent()
  • CRDT Merge Rules: Merge grow-only sets and counters with CRDT semantics
  • State-Machine Merge: Resolve state conflicts with priority-based selection
  • Status State Model: 8-lane canonical lifecycle (Lane) with transition validation and reducer
  • Lane Mapping Contract: SyncLaneV1 preserves the legacy 4-lane consumer view, while SyncLaneV2 exposes the explicit approved lane
  • Gate Observability: Typed payloads for GitHub check_run gate events
  • Lifecycle Events: Mission lifecycle contracts with typed payloads and reducer
  • Collaboration Events: N-participant mission collaboration with advisory coordination (soft locks, not hard locks), 14 event types, dual-mode reducer
  • Mission-Next Runtime Events: Run-scoped execution contracts (7 event types, 6 payloads, deterministic reducer) with RuntimeActorIdentity and decision lifecycle tracking
  • Conformance Suite: Dual-layer validation (Pydantic + JSON Schema), manifest-driven fixtures, pytest-runnable conformance tests
  • JSON Schemas: 44 committed schema artifacts generated from Pydantic models
  • Error Logging: Systematic error tracking with retention policies
  • Storage Adapters: Abstract storage interfaces (bring your own database)
  • Type Safety: Full mypy --strict compliance with py.typed marker

Installation

From PyPI

pip install "spec-kitty-events>=2.1.0,<3.0.0"

With conformance testing support (adds jsonschema):

pip install "spec-kitty-events[conformance]>=2.0.0rc1,<3.0.0"

From Git

pip install "git+https://github.com/Priivacy-ai/spec-kitty-events.git@v2.1.0"

Development Installation

git clone https://github.com/Priivacy-ai/spec-kitty-events.git
cd spec-kitty-events
pip install -e ".[dev,conformance]"

Quick Start

Lane Mapping (New in 2.0.0)

from spec_kitty_events import Lane, SyncLaneV1, SyncLaneV2, canonical_to_sync_v1, canonical_to_sync_v2

# Convert canonical 8-lane model to the legacy 4-lane consumer view
sync_lane = canonical_to_sync_v1(Lane.IN_PROGRESS)
assert sync_lane == SyncLaneV1.DOING

sync_lane = canonical_to_sync_v1(Lane.BLOCKED)
assert sync_lane == SyncLaneV1.DOING  # blocked collapses to doing

# Preserve explicit review approval in the V2 sync view
sync_lane = canonical_to_sync_v2(Lane.APPROVED)
assert sync_lane == SyncLaneV2.APPROVED

Event Emission

import uuid
from datetime import datetime
from spec_kitty_events import (
    Event,
    LamportClock,
    InMemoryClockStorage,
    InMemoryEventStore,
)

clock_storage = InMemoryClockStorage()
event_store = InMemoryEventStore()
clock = LamportClock(node_id="alice", storage=clock_storage)

clock.tick()
event = Event(
    event_id="01ARZ3NDEKTSV4RRFFQ69G5FAV",
    event_type="WPStatusChanged",
    aggregate_id="WP001",
    timestamp=datetime.now(),
    node_id="alice",
    lamport_clock=clock.current(),
    project_uuid=uuid.uuid4(),
    correlation_id="01ARZ3NDEKTSV4RRFFQ69G5FAV",
    payload={"state": "doing"},
)
event_store.save_event(event)

Conformance Validation

from spec_kitty_events.conformance import validate_event

payload = {
    "feature_slug": "005-my-feature",
    "wp_id": "WP01",
    "to_lane": "in_progress",
    "actor": "ci-bot",
    "execution_mode": "worktree",
}
result = validate_event(payload, "WPStatusChanged")
assert result.valid

Collaboration Events (New in 2.1.0)

N-participant mission collaboration with advisory coordination. Soft locks, not hard locks -- warnings are informational and participants decide how to respond.

14 event types grouped by category:

Category Event Types
Participant Lifecycle ParticipantInvited, ParticipantJoined, ParticipantLeft, PresenceHeartbeat
Drive Intent & Focus DriveIntentSet, FocusChanged
Step Execution PromptStepExecutionStarted, PromptStepExecutionCompleted
Advisory Warnings ConcurrentDriverWarning, PotentialStepCollisionDetected, WarningAcknowledged
Communication CommentPosted, DecisionCaptured
Session SessionLinked

Key exports: ParticipantIdentity, FocusTarget, reduce_collaboration_events, ReducedCollaborationState, UnknownParticipantError, CollaborationAnomaly

from spec_kitty_events import (
    Event,
    ParticipantIdentity,
    ParticipantJoinedPayload,
    PARTICIPANT_JOINED,
    reduce_collaboration_events,
    FocusTarget,
)

# Construct a participant identity
identity = ParticipantIdentity(
    participant_id="p-abc123",
    participant_type="human",
    display_name="Alice",
)

# Construct a typed payload
payload = ParticipantJoinedPayload(
    participant_id="p-abc123",
    participant_identity=identity,
    mission_id="mission/M042",
)

# Reduce collaboration events into materialized state
state = reduce_collaboration_events([])
assert state.event_count == 0

See COMPATIBILITY.md for the full collaboration event contracts, reducer pipeline details, and SaaS-authoritative participation model.

Mission-Next Runtime Events (New in 2.3.0)

Run-scoped execution contracts for the spec-kitty-runtime engine. 7 event types with typed payloads and a deterministic reducer for state materialization.

from spec_kitty_events import (
    RuntimeActorIdentity,
    MissionRunStartedPayload,
    reduce_mission_next_events,
    MissionRunStatus,
)

# Construct an actor identity
actor = RuntimeActorIdentity(
    actor_id="agent-claude",
    actor_type="llm",
    provider="anthropic",
    model="claude-opus-4-6",
)

# Build a run-started payload
payload = MissionRunStartedPayload(
    run_id="run-001",
    mission_key="feature-login",
    actor=actor,
)

# Reduce events into materialized run state
state = reduce_mission_next_events([])
assert state.run_status is None  # no events yet

See COMPATIBILITY.md for event type reference, the MissionCompleted vs MissionRunCompleted distinction table, and migration notes.

Conflict Detection and Resolution

from spec_kitty_events import is_concurrent, state_machine_merge

# Detect concurrent events
if is_concurrent(event1, event2):
    priority_map = {"done": 4, "for_review": 3, "doing": 2, "planned": 1}
    resolution = state_machine_merge([event1, event2], priority_map)
    winner = resolution.merged_event

Documentation

  • CHANGELOG.md: Version history and migration notes
  • COMPATIBILITY.md: Lane mapping table, field reference, versioning policy, CI integration guide
  • Type hints: Full mypy --strict compliance (source is the documentation)
  • Conformance suite: pytest --pyargs spec_kitty_events.conformance -v

Public API (126 Exports)

The spec_kitty_events package exports 126 symbols covering:

Category Count Key Exports
Core models 4 Event, ErrorEntry, ConflictResolution
Exceptions 4 SpecKittyEventsError, StorageError, ValidationError, CyclicDependencyError
Storage 6 EventStore, ClockStorage, ErrorStorage, InMemory*
Clocks 1 LamportClock
Conflict detection 3 is_concurrent, total_order_key, topological_sort
Merge functions 3 merge_gset, merge_counter, state_machine_merge
Error logging 1 ErrorLog
Gate observability 5 GatePayloadBase, GatePassedPayload, GateFailedPayload, map_check_run_conclusion, UnknownConclusionError
Lifecycle events 15 SCHEMA_VERSION, MissionStatus, payload models, reducer, constants
Status model 25 Lane, SyncLaneV1, canonical_to_sync_v1, StatusTransitionPayload, reducer, validators
Collaboration events 36 ParticipantIdentity, FocusTarget, payload models, reducer, constants, warnings
Version 1 __version__

Testing

Run the full test suite (790 tests, 98% coverage):

pytest --cov --cov-report=html

Run conformance tests only:

pytest --pyargs spec_kitty_events.conformance -v

Type checking:

mypy src/spec_kitty_events --strict

Schema drift check:

python -m spec_kitty_events.schemas.generate --check

Requirements

  • Python >= 3.10
  • Pydantic >= 2.0.0, < 3.0.0
  • python-ulid >= 1.1.0
  • jsonschema >= 4.21.0, < 5.0.0 (optional, for [conformance] extra)

Release and Publishing

This repository uses GitHub Actions trusted publishing:

  1. publish-testpypi.yml: Manual TestPyPI dry run.
  2. publish-pypi.yml: Publish on v* tags (or manual dispatch) to PyPI.

Release flow:

  1. Update project.version in pyproject.toml.
  2. Commit to main.
  3. Create and push matching tag (e.g., v2.1.0 for version = "2.1.0").
  4. Approve the pypi GitHub environment (if required).
  5. Verify package on PyPI and install in a clean environment.

License

All rights reserved. This is a private repository owned by Priivacy AI.


Generated with Spec Kitty

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spec_kitty_events-2.9.0.tar.gz (153.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spec_kitty_events-2.9.0-py3-none-any.whl (221.5 kB view details)

Uploaded Python 3

File details

Details for the file spec_kitty_events-2.9.0.tar.gz.

File metadata

  • Download URL: spec_kitty_events-2.9.0.tar.gz
  • Upload date:
  • Size: 153.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spec_kitty_events-2.9.0.tar.gz
Algorithm Hash digest
SHA256 a418dc80f678daa047ce600850093aaaf7a5b253127205537271c8502778c5f3
MD5 bd386dda7690af4bff27563dc948a863
BLAKE2b-256 8146f21175b62fd63d26397377272cd491a2f7a37bb21d58a870f82166ff166c

See more details on using hashes here.

Provenance

The following attestation bundles were made for spec_kitty_events-2.9.0.tar.gz:

Publisher: publish-pypi.yml on Priivacy-ai/spec-kitty-events

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spec_kitty_events-2.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spec_kitty_events-2.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4813d4a198ca6aedf4949a675ae0dcaf34e360c9bd00c60e229612161326aa1d
MD5 e8693a43bba685c70d3cd4ab08e0cd74
BLAKE2b-256 fc15b4b1d3e9012f98a028a9fcade52efff825f72f9eb431c43a42961cd4cd5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for spec_kitty_events-2.9.0-py3-none-any.whl:

Publisher: publish-pypi.yml on Priivacy-ai/spec-kitty-events

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page