Loop Engine

Packages

@loop-engine/events

@loop-engine/events defines the event contract and ships an in-memory event bus implementation.

Install

1npm install @loop-engine/events

Event catalog

The exported LOOP_EVENT_TYPES constants map to:

  • loop.started
  • loop.transition.requested
  • loop.transition.executed
  • loop.transition.blocked
  • loop.guard.failed
  • loop.completed
  • loop.error
  • loop.spawned
  • loop.signal.received
  • loop.outcome.recorded

Every event extends:

1interface LoopEventBase {
2 eventId: string
3 loopId: LoopId
4 aggregateId: AggregateId
5 orgId: string
6 occurredAt: string
7 correlationId: CorrelationId
8 causationId?: string
9}

InMemoryEventBus

1class InMemoryEventBus {
2 emit(event: LoopEvent): Promise<void>
3 subscribe(handler: (event: LoopEvent) => Promise<void>): () => void
4}

subscribe() returns an unsubscribe callback, and handler failures do not block other subscribers.

1import { InMemoryEventBus } from "@loop-engine/events"
2 
3const bus = new InMemoryEventBus()
4const unsubscribe = bus.subscribe(async (event) => {
5 if (event.type === "loop.transition.executed") {
6 console.log(event.transitionId, event.actor.type)
7 }
8})
9 
10unsubscribe()

Learning signal extraction

1extractLearningSignal(
2 completed: LoopCompletedEvent,
3 history: TransitionRecord[],
4 predicted?: Record<string, unknown>
5): LearningSignal

This helper derives actual, predicted, and numeric delta fields from completion history.