@yesod/core 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/events.ts","../src/bus.ts","../src/vantage.ts","../src/storage.ts"],"sourcesContent":["export { EventType } from \"./events.js\";\nexport type { YesodEvent } from \"./events.js\";\n\nexport { EventBus } from \"./bus.js\";\nexport type { EventHandler, EventFilter } from \"./bus.js\";\n\nexport { VantageEngine } from \"./vantage.js\";\nexport type {\n Subscription,\n SubscriptionCondition,\n NotificationEvent,\n} from \"./vantage.js\";\n\nexport { InMemoryStorageAdapter } from \"./storage.js\";\nexport type { StorageAdapter, StorageQuery } from \"./storage.js\";\n\nexport type {\n SessionState,\n SessionControl,\n CodingSession,\n} from \"./session.js\";\n\nexport type { Scheduler, ReadyStep } from \"./scheduler.js\";\n\nexport type { Router, RuntimeRecommendation } from \"./router.js\";\n\nexport type { Workflow, WorkflowStep, WorkflowState } from \"./workflow.js\";\n","export enum EventType {\n OrchestrationStarted = \"orchestration.started\",\n TaskCreated = \"task.created\",\n TaskDependency = \"task.dependency\",\n SessionSpawned = \"session.spawned\",\n SessionEvent = \"session.event\",\n SessionSteered = \"session.steered\",\n SessionArtifact = \"session.artifact\",\n SessionCompleted = \"session.completed\",\n TaskCompleted = \"task.completed\",\n OrchestrationCompleted = \"orchestration.completed\",\n SubscriptionTriggered = \"subscription.triggered\",\n}\n\nexport interface YesodEvent {\n id: string;\n type: EventType;\n timestamp: string;\n sessionId?: string;\n orchestrationId?: string;\n taskId?: string;\n payload: Record<string, unknown>;\n}\n","import type { YesodEvent, EventType } from \"./events.js\";\n\nexport type EventHandler = (event: YesodEvent) => void | Promise<void>;\n\nexport interface EventFilter {\n type?: EventType;\n sessionId?: string;\n orchestrationId?: string;\n}\n\nexport class EventBus {\n private handlers = new Map<string, { filter: EventFilter; handler: EventHandler }>();\n private nextId = 0;\n\n subscribe(filter: EventFilter, handler: EventHandler): string {\n const id = String(this.nextId++);\n this.handlers.set(id, { filter, handler });\n return id;\n }\n\n unsubscribe(id: string): void {\n this.handlers.delete(id);\n }\n\n async emit(event: YesodEvent): Promise<void> {\n const promises: Promise<void>[] = [];\n for (const [, { filter, handler }] of this.handlers) {\n if (this.matches(event, filter)) {\n const result = handler(event);\n if (result instanceof Promise) {\n promises.push(result);\n }\n }\n }\n await Promise.all(promises);\n }\n\n private matches(event: YesodEvent, filter: EventFilter): boolean {\n if (filter.type && event.type !== filter.type) return false;\n if (filter.sessionId && event.sessionId !== filter.sessionId) return false;\n if (filter.orchestrationId && event.orchestrationId !== filter.orchestrationId) return false;\n return true;\n }\n}\n","import type { YesodEvent, EventType } from \"./events.js\";\n\nexport interface SubscriptionCondition {\n sessionId?: string;\n eventType: EventType;\n filter?: Record<string, unknown>;\n}\n\nexport interface Subscription {\n id: string;\n orchestratorSession: string;\n conditions: SubscriptionCondition[];\n mode: \"any\" | \"all\";\n}\n\nexport interface NotificationEvent {\n type: \"subscription.triggered\";\n subscriptionId: string;\n matchedEvents: YesodEvent[];\n}\n\nexport class VantageEngine {\n private subscriptions = new Map<string, Subscription>();\n\n register(subscription: Subscription): void {\n this.subscriptions.set(subscription.id, subscription);\n }\n\n remove(subscriptionId: string): void {\n this.subscriptions.delete(subscriptionId);\n }\n\n /** Evaluate an incoming event against all subscriptions. Returns notifications for any triggered subscriptions. */\n evaluate(_event: YesodEvent): NotificationEvent[] {\n // Stub — will implement condition matching and barrier tracking\n return [];\n }\n\n getSubscription(id: string): Subscription | undefined {\n return this.subscriptions.get(id);\n }\n\n listSubscriptions(): Subscription[] {\n return Array.from(this.subscriptions.values());\n }\n}\n","export interface StorageQuery {\n type?: string;\n sessionId?: string;\n orchestrationId?: string;\n from?: string;\n to?: string;\n limit?: number;\n}\n\nexport interface StorageAdapter {\n get(key: string): Promise<unknown | undefined>;\n put(key: string, value: unknown): Promise<void>;\n query(query: StorageQuery): Promise<unknown[]>;\n delete(key: string): Promise<boolean>;\n}\n\nexport class InMemoryStorageAdapter implements StorageAdapter {\n private store = new Map<string, unknown>();\n\n async get(key: string): Promise<unknown | undefined> {\n return this.store.get(key);\n }\n\n async put(key: string, value: unknown): Promise<void> {\n this.store.set(key, value);\n }\n\n async query(_query: StorageQuery): Promise<unknown[]> {\n // Stub — returns all values; real implementation would filter\n return Array.from(this.store.values());\n }\n\n async delete(key: string): Promise<boolean> {\n return this.store.delete(key);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,kBAAe;AACf,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,mBAAgB;AAChB,EAAAA,WAAA,4BAAyB;AACzB,EAAAA,WAAA,2BAAwB;AAXd,SAAAA;AAAA,GAAA;;;ACUL,IAAM,WAAN,MAAe;AAAA,EACZ,WAAW,oBAAI,IAA4D;AAAA,EAC3E,SAAS;AAAA,EAEjB,UAAU,QAAqB,SAA+B;AAC5D,UAAM,KAAK,OAAO,KAAK,QAAQ;AAC/B,SAAK,SAAS,IAAI,IAAI,EAAE,QAAQ,QAAQ,CAAC;AACzC,WAAO;AAAA,EACT;AAAA,EAEA,YAAY,IAAkB;AAC5B,SAAK,SAAS,OAAO,EAAE;AAAA,EACzB;AAAA,EAEA,MAAM,KAAK,OAAkC;AAC3C,UAAM,WAA4B,CAAC;AACnC,eAAW,CAAC,EAAE,EAAE,QAAQ,QAAQ,CAAC,KAAK,KAAK,UAAU;AACnD,UAAI,KAAK,QAAQ,OAAO,MAAM,GAAG;AAC/B,cAAM,SAAS,QAAQ,KA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}
1
+ {"version":3,"sources":["../src/index.ts","../src/events.ts","../src/bus.ts","../src/vantage.ts","../src/storage.ts","../src/scheduler.ts","../src/engine.ts","../src/tools.ts"],"sourcesContent":["export { EventType } from \"./events.js\";\nexport type { YesodEvent, CostRecord } from \"./events.js\";\n\nexport { EventBus } from \"./bus.js\";\nexport type { EventHandler, EventFilter } from \"./bus.js\";\n\nexport { VantageEngine } from \"./vantage.js\";\nexport type {\n Subscription,\n SubscriptionCondition,\n NotificationEvent,\n} from \"./vantage.js\";\n\nexport { InMemoryStorageAdapter } from \"./storage.js\";\nexport type { StorageAdapter, StorageQuery } from \"./storage.js\";\n\nexport type {\n SessionState,\n SessionControl,\n CodingSession,\n} from \"./session.js\";\n\nexport { SimpleScheduler } from \"./scheduler.js\";\nexport type { Scheduler, ReadyStep, StepState } from \"./scheduler.js\";\n\nexport type {\n Workflow,\n WorkflowStep,\n WorkflowState,\n WorkflowInput,\n WorkflowTrigger,\n} from \"./workflow.js\";\n\nexport { OrchestrationEngine } from \"./engine.js\";\nexport type {\n WorkflowExecution,\n EngineWorkflowState,\n WorkflowStatus,\n CostSummary,\n} from \"./engine.js\";\n\nexport { YESOD_TOOLS } from \"./tools.js\";\n\nexport type {\n RuntimeAdapter,\n SpawnOptions,\n CodingSpawnOptions,\n TaskSpec,\n ResultSpec,\n RuntimeDecision,\n SessionHandle,\n SessionStatus,\n StepResult,\n StructuredOutput,\n SummaryOutput,\n DiffOutput,\n ReviewOutput,\n TestOutput,\n StructuredFieldsOutput,\n RawFallbackOutput,\n RetryPolicy,\n} from \"./runtime.js\";\n","export enum EventType {\n // Orchestration lifecycle\n OrchestrationStarted = \"orchestration.started\",\n OrchestrationCompleted = \"orchestration.completed\",\n\n // Workflow lifecycle\n WorkflowStarted = \"workflow.started\",\n WorkflowCompleted = \"workflow.completed\",\n WorkflowFailed = \"workflow.failed\",\n WorkflowStepStarted = \"workflow.step.started\",\n WorkflowStepCompleted = \"workflow.step.completed\",\n WorkflowStepFailed = \"workflow.step.failed\",\n\n // Task lifecycle\n TaskCreated = \"task.created\",\n TaskDependency = \"task.dependency\",\n TaskCompleted = \"task.completed\",\n\n // Session lifecycle\n SessionSpawned = \"session.spawned\",\n SessionMessage = \"session.message\",\n SessionEvent = \"session.event\",\n SessionSteered = \"session.steered\",\n SessionArtifact = \"session.artifact\",\n SessionCompleted = \"session.completed\",\n SessionFailed = \"session.failed\",\n SessionKilled = \"session.killed\",\n\n // Cost\n CostIncurred = \"cost.incurred\",\n\n // Subscriptions\n SubscriptionTriggered = \"subscription.triggered\",\n}\n\nexport interface CostRecord {\n tokens: {\n input: number;\n output: number;\n cacheRead?: number;\n cacheWrite?: number;\n };\n usd: number;\n runtime?: string;\n}\n\nexport interface YesodEvent {\n id: string;\n type: EventType;\n source: string;\n timestamp: number;\n sessionId?: string;\n orchestrationId?: string;\n taskId?: string;\n workflowId?: string;\n stepId?: string;\n payload: Record<string, unknown>;\n metadata?: {\n cost?: CostRecord;\n duration?: number;\n };\n}\n","import type { YesodEvent, EventType } from \"./events.js\";\n\nexport type EventHandler = (event: YesodEvent) => void | Promise<void>;\n\nexport interface EventFilter {\n type?: EventType | EventType[];\n sessionId?: string;\n orchestrationId?: string;\n workflowId?: string;\n}\n\nexport class EventBus {\n private handlers = new Map<\n string,\n { filter: EventFilter; handler: EventHandler }\n >();\n private nextId = 0;\n\n subscribe(filter: EventFilter, handler: EventHandler): string {\n const id = String(this.nextId++);\n this.handlers.set(id, { filter, handler });\n return id;\n }\n\n subscribeAll(handler: EventHandler): string {\n return this.subscribe({}, handler);\n }\n\n unsubscribe(id: string): void {\n this.handlers.delete(id);\n }\n\n async emit(event: YesodEvent): Promise<void> {\n const promises: Promise<void>[] = [];\n for (const [, { filter, handler }] of this.handlers) {\n if (this.matches(event, filter)) {\n const result = handler(event);\n if (result instanceof Promise) {\n promises.push(result);\n }\n }\n }\n await Promise.all(promises);\n }\n\n private matches(event: YesodEvent, filter: EventFilter): boolean {\n if (filter.type) {\n if (Array.isArray(filter.type)) {\n if (!filter.type.includes(event.type)) return false;\n } else {\n if (event.type !== filter.type) return false;\n }\n }\n if (filter.sessionId && event.sessionId !== filter.sessionId) return false;\n if (\n filter.orchestrationId &&\n event.orchestrationId !== filter.orchestrationId\n )\n return false;\n if (filter.workflowId && event.workflowId !== filter.workflowId)\n return false;\n return true;\n }\n}\n","import type { YesodEvent, EventType } from \"./events.js\";\n\nexport interface SubscriptionCondition {\n sessionId?: string;\n eventType: EventType;\n filter?: Record<string, unknown>;\n}\n\nexport interface Subscription {\n id: string;\n orchestratorSession: string;\n conditions: SubscriptionCondition[];\n mode: \"any\" | \"all\";\n once?: boolean;\n ttl?: number;\n registeredAt?: number;\n}\n\nexport interface NotificationEvent {\n type: \"subscription.triggered\";\n subscriptionId: string;\n matchedEvents: YesodEvent[];\n}\n\nexport class VantageEngine {\n private subscriptions = new Map<string, Subscription>();\n private barrierState = new Map<string, Map<number, YesodEvent[]>>();\n\n register(subscription: Subscription): void {\n const sub = { ...subscription, registeredAt: subscription.registeredAt ?? Date.now() };\n this.subscriptions.set(sub.id, sub);\n if (sub.mode === \"all\") {\n this.barrierState.set(sub.id, new Map());\n }\n }\n\n remove(subscriptionId: string): void {\n this.subscriptions.delete(subscriptionId);\n this.barrierState.delete(subscriptionId);\n }\n\n evaluate(event: YesodEvent): NotificationEvent[] {\n const notifications: NotificationEvent[] = [];\n const toRemove: string[] = [];\n\n for (const [id, sub] of this.subscriptions) {\n // TTL expiration\n if (sub.ttl && sub.registeredAt) {\n if (Date.now() - sub.registeredAt > sub.ttl) {\n toRemove.push(id);\n continue;\n }\n }\n\n if (sub.mode === \"any\") {\n const matched = this.matchAny(event, sub);\n if (matched) {\n notifications.push({\n type: \"subscription.triggered\",\n subscriptionId: id,\n matchedEvents: [event],\n });\n if (sub.once) toRemove.push(id);\n }\n } else {\n // \"all\" — barrier mode\n const notification = this.matchBarrier(event, sub);\n if (notification) {\n notifications.push(notification);\n if (sub.once) toRemove.push(id);\n }\n }\n }\n\n for (const id of toRemove) {\n this.remove(id);\n }\n\n return notifications;\n }\n\n getSubscription(id: string): Subscription | undefined {\n return this.subscriptions.get(id);\n }\n\n listSubscriptions(): Subscription[] {\n return Array.from(this.subscriptions.values());\n }\n\n activeCount(): number {\n return this.subscriptions.size;\n }\n\n private matchAny(event: YesodEvent, sub: Subscription): boolean {\n return sub.conditions.some((cond) => this.matchCondition(event, cond));\n }\n\n private matchBarrier(\n event: YesodEvent,\n sub: Subscription,\n ): NotificationEvent | null {\n let barrier = this.barrierState.get(sub.id);\n if (!barrier) {\n barrier = new Map();\n this.barrierState.set(sub.id, barrier);\n }\n\n // Check each condition — if this event matches, record it\n for (let i = 0; i < sub.conditions.length; i++) {\n if (barrier.has(i)) continue; // already satisfied\n if (this.matchCondition(event, sub.conditions[i])) {\n barrier.set(i, [event]);\n }\n }\n\n // Check if all conditions are now satisfied\n if (barrier.size === sub.conditions.length) {\n const allEvents: YesodEvent[] = [];\n for (const events of barrier.values()) {\n allEvents.push(...events);\n }\n this.barrierState.delete(sub.id);\n return {\n type: \"subscription.triggered\",\n subscriptionId: sub.id,\n matchedEvents: allEvents,\n };\n }\n\n return null;\n }\n\n private matchCondition(\n event: YesodEvent,\n cond: SubscriptionCondition,\n ): boolean {\n if (event.type !== cond.eventType) return false;\n if (cond.sessionId && event.sessionId !== cond.sessionId) return false;\n if (cond.filter) {\n for (const [key, value] of Object.entries(cond.filter)) {\n if (event.payload[key] !== value) return false;\n }\n }\n return true;\n }\n}\n","export interface StorageQuery {\n type?: string;\n sessionId?: string;\n orchestrationId?: string;\n from?: string;\n to?: string;\n limit?: number;\n}\n\nexport interface StorageAdapter {\n get(key: string): Promise<unknown | undefined>;\n put(key: string, value: unknown): Promise<void>;\n query(query: StorageQuery): Promise<unknown[]>;\n delete(key: string): Promise<boolean>;\n}\n\nexport class InMemoryStorageAdapter implements StorageAdapter {\n private store = new Map<string, unknown>();\n\n async get(key: string): Promise<unknown | undefined> {\n return this.store.get(key);\n }\n\n async put(key: string, value: unknown): Promise<void> {\n this.store.set(key, value);\n }\n\n async query(_query: StorageQuery): Promise<unknown[]> {\n // Stub — returns all values; real implementation would filter\n return Array.from(this.store.values());\n }\n\n async delete(key: string): Promise<boolean> {\n return this.store.delete(key);\n }\n}\n","import type { WorkflowStep } from \"./workflow.js\";\n\nexport interface ReadyStep {\n step: WorkflowStep;\n reason: string;\n}\n\nexport interface Scheduler {\n getReadySteps(): ReadyStep[];\n}\n\nexport type StepState = \"pending\" | \"running\" | \"completed\" | \"failed\";\n\nexport class SimpleScheduler implements Scheduler {\n private stepStates = new Map<string, StepState>();\n private stepMap = new Map<string, WorkflowStep>();\n\n constructor(steps: WorkflowStep[]) {\n for (const step of steps) {\n this.stepMap.set(step.id, step);\n this.stepStates.set(step.id, \"pending\");\n }\n }\n\n getReadySteps(): ReadyStep[] {\n const ready: ReadyStep[] = [];\n for (const [id, state] of this.stepStates) {\n if (state !== \"pending\") continue;\n const step = this.stepMap.get(id)!;\n const deps = step.dependsOn ?? [];\n const allDepsCompleted = deps.every(\n (depId) => this.stepStates.get(depId) === \"completed\",\n );\n if (allDepsCompleted) {\n const reason =\n deps.length === 0\n ? \"No dependencies\"\n : `Dependencies satisfied: ${deps.join(\", \")}`;\n ready.push({ step, reason });\n }\n }\n return ready;\n }\n\n markRunning(stepId: string): void {\n this.stepStates.set(stepId, \"running\");\n }\n\n markCompleted(stepId: string): void {\n this.stepStates.set(stepId, \"completed\");\n }\n\n markFailed(stepId: string): void {\n this.stepStates.set(stepId, \"failed\");\n }\n\n getState(stepId: string): StepState | undefined {\n return this.stepStates.get(stepId);\n }\n\n isComplete(): boolean {\n for (const state of this.stepStates.values()) {\n if (state !== \"completed\" && state !== \"failed\") return false;\n }\n return true;\n }\n\n allSucceeded(): boolean {\n for (const state of this.stepStates.values()) {\n if (state !== \"completed\") return false;\n }\n return true;\n }\n\n /**\n * Mark any pending step whose dependencies include a failed step as failed.\n * Returns IDs of newly failed steps.\n */\n markUnreachable(): string[] {\n const failed: string[] = [];\n let changed = true;\n while (changed) {\n changed = false;\n for (const [id, state] of this.stepStates) {\n if (state !== \"pending\") continue;\n const step = this.stepMap.get(id)!;\n const deps = step.dependsOn ?? [];\n const hasFailedDep = deps.some(\n (depId) => this.stepStates.get(depId) === \"failed\",\n );\n if (hasFailedDep) {\n this.stepStates.set(id, \"failed\");\n failed.push(id);\n changed = true;\n }\n }\n }\n return failed;\n }\n}\n","import { EventType } from \"./events.js\";\nimport type { YesodEvent, CostRecord } from \"./events.js\";\nimport type {\n RuntimeAdapter,\n SpawnOptions,\n SessionHandle,\n StepResult,\n TaskSpec,\n} from \"./runtime.js\";\nimport type { Workflow, WorkflowStep } from \"./workflow.js\";\nimport type { StorageAdapter } from \"./storage.js\";\nimport { EventBus } from \"./bus.js\";\nimport { SimpleScheduler } from \"./scheduler.js\";\n\nlet idCounter = 0;\nfunction uid(): string {\n return `evt-${Date.now()}-${++idCounter}`;\n}\n\nexport type EngineWorkflowState = \"created\" | \"running\" | \"completed\" | \"failed\";\n\nexport interface WorkflowExecution {\n workflow: Workflow;\n state: EngineWorkflowState;\n scheduler: SimpleScheduler;\n stepResults: Map<string, StepResult>;\n activeSessions: Map<string, SessionHandle>; // stepId -> handle\n startedAt: number;\n completedAt?: number;\n}\n\nexport interface WorkflowStatus {\n workflowId: string;\n state: EngineWorkflowState;\n steps: Array<{\n stepId: string;\n state: string;\n result?: StepResult;\n }>;\n startedAt: number;\n completedAt?: number;\n}\n\nexport interface CostSummary {\n totalUsd: number;\n totalTokens: { input: number; output: number };\n perStep: Array<{\n stepId: string;\n cost: CostRecord;\n durationMs: number;\n }>;\n}\n\nexport class OrchestrationEngine {\n private executions = new Map<string, WorkflowExecution>();\n\n constructor(\n private adapter: RuntimeAdapter,\n private bus: EventBus,\n private storage: StorageAdapter,\n ) {\n // Listen for session completions from the adapter\n this.adapter.onEvent((event) => this.handleAdapterEvent(event));\n }\n\n createWorkflow(def: Workflow): Workflow {\n const workflow: Workflow = {\n ...def,\n id: def.id || uid(),\n state: \"created\",\n createdAt: Date.now(),\n };\n\n const scheduler = new SimpleScheduler(workflow.steps);\n this.executions.set(workflow.id, {\n workflow,\n state: \"created\",\n scheduler,\n stepResults: new Map(),\n activeSessions: new Map(),\n startedAt: 0,\n });\n\n return workflow;\n }\n\n async startWorkflow(workflowId: string): Promise<void> {\n const exec = this.executions.get(workflowId);\n if (!exec) throw new Error(`Unknown workflow: ${workflowId}`);\n if (exec.state !== \"created\") {\n throw new Error(`Workflow ${workflowId} is already ${exec.state}`);\n }\n\n exec.state = \"running\";\n exec.startedAt = Date.now();\n\n await this.bus.emit({\n id: uid(),\n type: EventType.WorkflowStarted,\n source: \"engine\",\n timestamp: Date.now(),\n workflowId,\n payload: { name: exec.workflow.name },\n });\n\n await this.advanceWorkflow(workflowId);\n }\n\n async cancelWorkflow(workflowId: string): Promise<void> {\n const exec = this.executions.get(workflowId);\n if (!exec) throw new Error(`Unknown workflow: ${workflowId}`);\n\n // Kill all active sessions\n for (const [stepId, handle] of exec.activeSessions) {\n try {\n await this.adapter.kill(handle);\n } catch {\n // best effort\n }\n exec.scheduler.markFailed(stepId);\n }\n exec.activeSessions.clear();\n\n exec.state = \"failed\";\n exec.completedAt = Date.now();\n\n await this.bus.emit({\n id: uid(),\n type: EventType.WorkflowFailed,\n source: \"engine\",\n timestamp: Date.now(),\n workflowId,\n payload: { reason: \"cancelled\" },\n });\n }\n\n getWorkflowStatus(workflowId: string): WorkflowStatus {\n const exec = this.executions.get(workflowId);\n if (!exec) throw new Error(`Unknown workflow: ${workflowId}`);\n\n return {\n workflowId,\n state: exec.state,\n steps: exec.workflow.steps.map((step) => ({\n stepId: step.id,\n state: exec.scheduler.getState(step.id) ?? \"pending\",\n result: exec.stepResults.get(step.id),\n })),\n startedAt: exec.startedAt,\n completedAt: exec.completedAt,\n };\n }\n\n getCostSummary(workflowId?: string): CostSummary {\n let results: StepResult[] = [];\n\n if (workflowId) {\n const exec = this.executions.get(workflowId);\n if (exec) {\n results = Array.from(exec.stepResults.values());\n }\n } else {\n for (const exec of this.executions.values()) {\n results.push(...exec.stepResults.values());\n }\n }\n\n let totalUsd = 0;\n let totalInput = 0;\n let totalOutput = 0;\n const perStep: CostSummary[\"perStep\"] = [];\n\n for (const r of results) {\n totalUsd += r.meta.cost.usd;\n totalInput += r.meta.cost.tokens.input;\n totalOutput += r.meta.cost.tokens.output;\n perStep.push({\n stepId: r.stepId,\n cost: r.meta.cost,\n durationMs: r.meta.durationMs,\n });\n }\n\n return {\n totalUsd,\n totalTokens: { input: totalInput, output: totalOutput },\n perStep,\n };\n }\n\n // --- Internal ---\n\n private async advanceWorkflow(workflowId: string): Promise<void> {\n const exec = this.executions.get(workflowId);\n if (!exec || exec.state !== \"running\") return;\n\n const readySteps = exec.scheduler.getReadySteps();\n\n for (const { step } of readySteps) {\n exec.scheduler.markRunning(step.id);\n try {\n await this.spawnStep(exec, step, workflowId);\n } catch (err) {\n exec.scheduler.markFailed(step.id);\n await this.bus.emit({\n id: uid(),\n type: EventType.WorkflowStepFailed,\n source: \"engine\",\n timestamp: Date.now(),\n workflowId,\n stepId: step.id,\n payload: {\n error: err instanceof Error ? err.message : String(err),\n },\n });\n }\n }\n\n // Mark steps that can never run due to failed dependencies\n exec.scheduler.markUnreachable();\n\n // Check if workflow is done (no more ready steps and nothing running)\n if (exec.scheduler.isComplete()) {\n exec.state = exec.scheduler.allSucceeded() ? \"completed\" : \"failed\";\n exec.completedAt = Date.now();\n\n const eventType = exec.state === \"completed\"\n ? EventType.WorkflowCompleted\n : EventType.WorkflowFailed;\n\n await this.bus.emit({\n id: uid(),\n type: eventType,\n source: \"engine\",\n timestamp: Date.now(),\n workflowId,\n payload: {\n duration: exec.completedAt - exec.startedAt,\n },\n });\n }\n }\n\n private async spawnStep(\n exec: WorkflowExecution,\n step: WorkflowStep,\n workflowId: string,\n ): Promise<void> {\n // Collect prior context from dependencies\n const priorContext: StepResult[] = [];\n for (const depId of step.dependsOn ?? []) {\n const depResult = exec.stepResults.get(depId);\n if (depResult) priorContext.push(depResult);\n }\n\n const taskSpec: TaskSpec = {\n instruction: step.task,\n expectedResult: step.expectedResult,\n priorContext: priorContext.length > 0 ? priorContext : undefined,\n };\n\n const spawnOpts: SpawnOptions = {\n task: taskSpec,\n runtime: step.runtime,\n decision: step.decision,\n timeout: step.timeout,\n context: { workflowId, stepId: step.id, attempt: 1 },\n };\n\n await this.bus.emit({\n id: uid(),\n type: EventType.WorkflowStepStarted,\n source: \"engine\",\n timestamp: Date.now(),\n workflowId,\n stepId: step.id,\n payload: { runtime: step.runtime },\n });\n\n const handle = await this.adapter.spawn(spawnOpts);\n exec.activeSessions.set(step.id, handle);\n }\n\n private async handleAdapterEvent(event: YesodEvent): Promise<void> {\n // Forward all adapter events through the bus\n await this.bus.emit(event);\n\n if (event.type === EventType.SessionCompleted && event.stepId) {\n await this.handleStepCompleted(event);\n } else if (event.type === EventType.SessionFailed && event.stepId) {\n await this.handleStepFailed(event);\n }\n }\n\n private async handleStepCompleted(event: YesodEvent): Promise<void> {\n const workflowId = event.workflowId;\n const stepId = event.stepId;\n if (!workflowId || !stepId) return;\n\n const exec = this.executions.get(workflowId);\n if (!exec) return;\n\n const stepResult = event.payload.stepResult as StepResult | undefined;\n if (stepResult) {\n exec.stepResults.set(stepId, stepResult);\n }\n\n exec.activeSessions.delete(stepId);\n exec.scheduler.markCompleted(stepId);\n\n await this.bus.emit({\n id: uid(),\n type: EventType.WorkflowStepCompleted,\n source: \"engine\",\n timestamp: Date.now(),\n workflowId,\n stepId,\n payload: { result: stepResult },\n });\n\n // Continue advancing the workflow\n await this.advanceWorkflow(workflowId);\n }\n\n private async handleStepFailed(event: YesodEvent): Promise<void> {\n const workflowId = event.workflowId;\n const stepId = event.stepId;\n if (!workflowId || !stepId) return;\n\n const exec = this.executions.get(workflowId);\n if (!exec) return;\n\n exec.activeSessions.delete(stepId);\n exec.scheduler.markFailed(stepId);\n\n await this.bus.emit({\n id: uid(),\n type: EventType.WorkflowStepFailed,\n source: \"engine\",\n timestamp: Date.now(),\n workflowId,\n stepId,\n payload: { error: event.payload.error },\n });\n\n await this.advanceWorkflow(workflowId);\n }\n}\n","/**\n * MCP tool JSON Schema definitions for Yesod agent-facing tools.\n */\n\nexport const YESOD_TOOLS = {\n yesod_create_workflow: {\n name: \"yesod_create_workflow\",\n description:\n \"Create and start a multi-step workflow. Define the steps, their dependencies, and expected output formats. Yesod will orchestrate execution, spawn child agents, and chain results automatically.\",\n inputSchema: {\n type: \"object\" as const,\n properties: {\n name: {\n type: \"string\",\n description: \"Human-readable name for the workflow\",\n },\n steps: {\n type: \"array\",\n description: \"Workflow steps to execute\",\n items: {\n type: \"object\",\n properties: {\n id: {\n type: \"string\",\n description: \"Unique step identifier\",\n },\n name: {\n type: \"string\",\n description: \"Human-readable step name\",\n },\n task: {\n type: \"string\",\n description: \"Instruction for the agent performing this step\",\n },\n expectedResult: {\n type: \"object\",\n description: \"Expected output format\",\n properties: {\n format: {\n type: \"string\",\n enum: [\"summary\", \"structured\", \"diff\", \"review\", \"test\"],\n },\n fields: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Fields to include (for structured format)\",\n },\n maxLength: {\n type: \"number\",\n description: \"Max output length in characters\",\n },\n },\n required: [\"format\"],\n },\n runtime: {\n type: \"string\",\n description:\n \"Runtime to use (e.g. claude-code, codex)\",\n },\n decision: {\n type: \"object\",\n description: \"Why this runtime was chosen\",\n properties: {\n reason: { type: \"string\" },\n considered: {\n type: \"array\",\n items: { type: \"string\" },\n },\n chosen: { type: \"string\" },\n },\n required: [\"reason\", \"considered\", \"chosen\"],\n },\n dependsOn: {\n type: \"array\",\n items: { type: \"string\" },\n description: \"Step IDs this step depends on\",\n },\n timeout: {\n type: \"number\",\n description: \"Timeout in milliseconds\",\n },\n },\n required: [\n \"id\",\n \"name\",\n \"task\",\n \"expectedResult\",\n \"runtime\",\n \"decision\",\n ],\n },\n },\n },\n required: [\"name\", \"steps\"],\n },\n },\n\n yesod_workflow_status: {\n name: \"yesod_workflow_status\",\n description:\n \"Check the current status of a running workflow, including per-step progress and results.\",\n inputSchema: {\n type: \"object\" as const,\n properties: {\n workflowId: {\n type: \"string\",\n description: \"ID of the workflow to check\",\n },\n },\n required: [\"workflowId\"],\n },\n },\n\n yesod_cancel_workflow: {\n name: \"yesod_cancel_workflow\",\n description:\n \"Cancel a running workflow. Kills all active sessions and marks the workflow as failed.\",\n inputSchema: {\n type: \"object\" as const,\n properties: {\n workflowId: {\n type: \"string\",\n description: \"ID of the workflow to cancel\",\n },\n },\n required: [\"workflowId\"],\n },\n },\n\n yesod_cost_summary: {\n name: \"yesod_cost_summary\",\n description:\n \"Get a cost breakdown showing token usage and USD cost, optionally filtered to a specific workflow.\",\n inputSchema: {\n type: \"object\" as const,\n properties: {\n workflowId: {\n type: \"string\",\n description: \"Optional: filter to a specific workflow\",\n },\n },\n },\n },\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAK,YAAL,kBAAKA,eAAL;AAEL,EAAAA,WAAA,0BAAuB;AACvB,EAAAA,WAAA,4BAAyB;AAGzB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,uBAAoB;AACpB,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,yBAAsB;AACtB,EAAAA,WAAA,2BAAwB;AACxB,EAAAA,WAAA,wBAAqB;AAGrB,EAAAA,WAAA,iBAAc;AACd,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,mBAAgB;AAGhB,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,kBAAe;AACf,EAAAA,WAAA,oBAAiB;AACjB,EAAAA,WAAA,qBAAkB;AAClB,EAAAA,WAAA,sBAAmB;AACnB,EAAAA,WAAA,mBAAgB;AAChB,EAAAA,WAAA,mBAAgB;AAGhB,EAAAA,WAA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,MAAM,SAAS;AAAA,gBACxB,aAAa;AAAA,cACf;AAAA,cACA,SAAS;AAAA,gBACP,MAAM;AAAA,gBACN,aAAa;AAAA,cACf;AAAA,YACF;AAAA,YACA,UAAU;AAAA,cACR;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,UAAU,CAAC,QAAQ,OAAO;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,uBAAuB;AAAA,IACrB,MAAM;AAAA,IACN,aACE;AAAA,IACF,aAAa;AAAA,MACX,MAAM;AAAA,MACN,YAAY;AAAA,QACV,YAAY;AAAA,UACV,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,MACA,UAAU,CAAC,YAAY;AAAA,IACzB;AAAA,EACF;AAAA,EAEA,uBAAuB;AAAA,IACrB,MAAM;AAAA,IACN,aACE;AAAA,IACF,aAAa;AAAA,MACX,MAAM;AAAA,MACN,YAAY;AAAA,QACV,YAAY;AAAA,UACV,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,MACA,UAAU,CAAC,YAAY;AAAA,IACzB;AAAA,EACF;AAAA,EAEA,oBAAoB;AAAA,IAClB,MAAM;AAAA,IACN,aACE;AAAA,IACF,aAAa;AAAA,MACX,MAAM;AAAA,MACN,YAAY;AAAA,QACV,YAAY;AAAA,UACV,MAAM;AAAA,UACN,aAAa;AAAA,QACf;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["EventType"]}
package/dist/index.d.cts CHANGED
@@ -1,36 +1,65 @@
1
1
  declare enum EventType {
2
2
  OrchestrationStarted = "orchestration.started",
3
+ OrchestrationCompleted = "orchestration.completed",
4
+ WorkflowStarted = "workflow.started",
5
+ WorkflowCompleted = "workflow.completed",
6
+ WorkflowFailed = "workflow.failed",
7
+ WorkflowStepStarted = "workflow.step.started",
8
+ WorkflowStepCompleted = "workflow.step.completed",
9
+ WorkflowStepFailed = "workflow.step.failed",
3
10
  TaskCreated = "task.created",
4
11
  TaskDependency = "task.dependency",
12
+ TaskCompleted = "task.completed",
5
13
  SessionSpawned = "session.spawned",
14
+ SessionMessage = "session.message",
6
15
  SessionEvent = "session.event",
7
16
  SessionSteered = "session.steered",
8
17
  SessionArtifact = "session.artifact",
9
18
  SessionCompleted = "session.completed",
10
- TaskCompleted = "task.completed",
11
- OrchestrationCompleted = "orchestration.completed",
19
+ SessionFailed = "session.failed",
20
+ SessionKilled = "session.killed",
21
+ CostIncurred = "cost.incurred",
12
22
  SubscriptionTriggered = "subscription.triggered"
13
23
  }
24
+ interface CostRecord {
25
+ tokens: {
26
+ input: number;
27
+ output: number;
28
+ cacheRead?: number;
29
+ cacheWrite?: number;
30
+ };
31
+ usd: number;
32
+ runtime?: string;
33
+ }
14
34
  interface YesodEvent {
15
35
  id: string;
16
36
  type: EventType;
17
- timestamp: string;
37
+ source: string;
38
+ timestamp: number;
18
39
  sessionId?: string;
19
40
  orchestrationId?: string;
20
41
  taskId?: string;
42
+ workflowId?: string;
43
+ stepId?: string;
21
44
  payload: Record<string, unknown>;
45
+ metadata?: {
46
+ cost?: CostRecord;
47
+ duration?: number;
48
+ };
22
49
  }
23
50
 
24
51
  type EventHandler = (event: YesodEvent) => void | Promise<void>;
25
52
  interface EventFilter {
26
- type?: EventType;
53
+ type?: EventType | EventType[];
27
54
  sessionId?: string;
28
55
  orchestrationId?: string;
56
+ workflowId?: string;
29
57
  }
30
58
  declare class EventBus {
31
59
  private handlers;
32
60
  private nextId;
33
61
  subscribe(filter: EventFilter, handler: EventHandler): string;
62
+ subscribeAll(handler: EventHandler): string;
34
63
  unsubscribe(id: string): void;
35
64
  emit(event: YesodEvent): Promise<void>;
36
65
  private matches;
@@ -46,6 +75,9 @@ interface Subscription {
46
75
  orchestratorSession: string;
47
76
  conditions: SubscriptionCondition[];
48
77
  mode: "any" | "all";
78
+ once?: boolean;
79
+ ttl?: number;
80
+ registeredAt?: number;
49
81
  }
50
82
  interface NotificationEvent {
51
83
  type: "subscription.triggered";
@@ -54,12 +86,16 @@ interface NotificationEvent {
54
86
  }
55
87
  declare class VantageEngine {
56
88
  private subscriptions;
89
+ private barrierState;
57
90
  register(subscription: Subscription): void;
58
91
  remove(subscriptionId: string): void;
59
- /** Evaluate an incoming event against all subscriptions. Returns notifications for any triggered subscriptions. */
60
- evaluate(_event: YesodEvent): NotificationEvent[];
92
+ evaluate(event: YesodEvent): NotificationEvent[];
61
93
  getSubscription(id: string): Subscription | undefined;
62
94
  listSubscriptions(): Subscription[];
95
+ activeCount(): number;
96
+ private matchAny;
97
+ private matchBarrier;
98
+ private matchCondition;
63
99
  }
64
100
 
65
101
  interface StorageQuery {
@@ -84,6 +120,120 @@ declare class InMemoryStorageAdapter implements StorageAdapter {
84
120
  delete(key: string): Promise<boolean>;
85
121
  }
86
122
 
123
+ interface SessionHandle {
124
+ id: string;
125
+ adapter: string;
126
+ metadata: Record<string, unknown>;
127
+ }
128
+ type SessionStatus = "running" | "completed" | "failed" | "timeout" | "killed" | "unknown";
129
+ interface RuntimeDecision {
130
+ reason: string;
131
+ considered: string[];
132
+ chosen: string;
133
+ }
134
+ interface TaskSpec {
135
+ instruction: string;
136
+ expectedResult: ResultSpec;
137
+ priorContext?: StepResult[];
138
+ }
139
+ interface ResultSpec {
140
+ format: "summary" | "structured" | "diff" | "review" | "test";
141
+ fields?: string[];
142
+ maxLength?: number;
143
+ }
144
+ interface StepResult {
145
+ stepId: string;
146
+ status: "completed" | "failed" | "timeout";
147
+ output: StructuredOutput;
148
+ meta: {
149
+ runtime: string;
150
+ decision: RuntimeDecision;
151
+ cost: CostRecord;
152
+ durationMs: number;
153
+ retries: number;
154
+ };
155
+ }
156
+ type StructuredOutput = SummaryOutput | DiffOutput | ReviewOutput | TestOutput | StructuredFieldsOutput | RawFallbackOutput;
157
+ interface SummaryOutput {
158
+ format: "summary";
159
+ summary: string;
160
+ }
161
+ interface DiffOutput {
162
+ format: "diff";
163
+ summary: string;
164
+ filesChanged: Array<{
165
+ path: string;
166
+ linesAdded: number;
167
+ linesRemoved: number;
168
+ }>;
169
+ }
170
+ interface ReviewOutput {
171
+ format: "review";
172
+ summary: string;
173
+ findings: Array<{
174
+ severity: "critical" | "high" | "medium" | "low" | "info";
175
+ location: string;
176
+ issue: string;
177
+ }>;
178
+ filesReviewed: string[];
179
+ }
180
+ interface TestOutput {
181
+ format: "test";
182
+ summary: string;
183
+ passed: number;
184
+ failed: number;
185
+ skipped: number;
186
+ failures: Array<{
187
+ test: string;
188
+ error: string;
189
+ }>;
190
+ }
191
+ interface StructuredFieldsOutput {
192
+ format: "structured";
193
+ fields: Record<string, unknown>;
194
+ }
195
+ interface RawFallbackOutput {
196
+ format: "raw";
197
+ raw: string;
198
+ parseError?: string;
199
+ }
200
+ interface SpawnOptions {
201
+ task: TaskSpec;
202
+ runtime: string;
203
+ decision: RuntimeDecision;
204
+ mode?: "run" | "session";
205
+ cwd?: string;
206
+ timeout?: number;
207
+ labels?: Record<string, string>;
208
+ context?: {
209
+ workflowId: string;
210
+ stepId: string;
211
+ attempt: number;
212
+ };
213
+ adapterConfig?: Record<string, unknown>;
214
+ }
215
+ interface CodingSpawnOptions extends SpawnOptions {
216
+ repo?: string;
217
+ branch?: string;
218
+ files?: string[];
219
+ }
220
+ interface RetryPolicy {
221
+ maxAttempts: number;
222
+ backoffMs?: number;
223
+ backoffMultiplier?: number;
224
+ retryOn?: string[];
225
+ }
226
+ interface RuntimeAdapter {
227
+ readonly name: string;
228
+ readonly description?: string;
229
+ spawn(opts: SpawnOptions): Promise<SessionHandle>;
230
+ send(session: SessionHandle, message: string): Promise<void>;
231
+ kill(session: SessionHandle): Promise<void>;
232
+ status(session: SessionHandle): Promise<SessionStatus | null>;
233
+ onEvent(handler: (event: YesodEvent) => void): void;
234
+ dispose(): Promise<void>;
235
+ }
236
+
87
237
  type SessionState = "pending" | "running" | "yielded" | "completed" | "failed" | "cancelled";
88
238
  interface SessionControl {
89
239
  maxTurns?: number;
@@ -99,8 +249,10 @@ interface CodingSession {
99
249
  parentSessionId?: string;
100
250
  state: SessionState;
101
251
  controls: SessionControl;
102
- startedAt?: string;
103
- completedAt?: string;
252
+ runtimeDecision?: RuntimeDecision;
253
+ stepResult?: StepResult;
254
+ startedAt?: number;
255
+ completedAt?: number;
104
256
  result?: Record<string, unknown>;
105
257
  }
106
258
 
@@ -108,19 +260,44 @@ type WorkflowState = "created" | "running" | "paused" | "completed" | "failed";
108
260
  interface WorkflowStep {
109
261
  id: string;
110
262
  name: string;
263
+ task: string;
264
+ expectedResult: ResultSpec;
265
+ runtime: string;
266
+ decision: RuntimeDecision;
267
+ dependsOn?: string[];
268
+ condition?: string;
269
+ retry?: RetryPolicy;
270
+ timeout?: number;
271
+ config?: Record<string, unknown>;
272
+ outputMapping?: Record<string, string>;
273
+ }
274
+ interface WorkflowInput {
275
+ name: string;
276
+ type: "string" | "number" | "boolean";
277
+ required?: boolean;
278
+ default?: unknown;
111
279
  description?: string;
112
- dependsOn: string[];
113
- taskId?: string;
114
- state: WorkflowState;
280
+ }
281
+ interface WorkflowTrigger {
282
+ type: "event" | "schedule" | "manual";
283
+ config: Record<string, unknown>;
115
284
  }
116
285
  interface Workflow {
117
286
  id: string;
118
- orchestrationId: string;
119
287
  name: string;
288
+ description?: string;
289
+ version?: string;
290
+ inputs?: WorkflowInput[];
120
291
  steps: WorkflowStep[];
292
+ triggers?: WorkflowTrigger[];
293
+ defaults?: {
294
+ runtime?: string;
295
+ timeout?: number;
296
+ retry?: RetryPolicy;
297
+ };
121
298
  state: WorkflowState;
122
- createdAt: string;
123
- completedAt?: string;
299
+ createdAt: number;
300
+ completedAt?: number;
124
301
  }
125
302
 
126
303
  interface ReadyStep {
@@ -128,19 +305,215 @@ interface ReadyStep {
128
305
  reason: string;
129
306
  }
130
307
  interface Scheduler {
131
- /** Reports which steps have all dependencies satisfied and are ready to execute. The agent decides what to actually run. */
132
- getReadySteps(workflowId: string): ReadyStep[];
308
+ getReadySteps(): ReadyStep[];
309
+ }
310
+ type StepState = "pending" | "running" | "completed" | "failed";
311
+ declare class SimpleScheduler implements Scheduler {
312
+ private stepStates;
313
+ private stepMap;
314
+ constructor(steps: WorkflowStep[]);
315
+ getReadySteps(): ReadyStep[];
316
+ markRunning(stepId: string): void;
317
+ markCompleted(stepId: string): void;
318
+ markFailed(stepId: string): void;
319
+ getState(stepId: string): StepState | undefined;
320
+ isComplete(): boolean;
321
+ allSucceeded(): boolean;
322
+ /**
323
+ * Mark any pending step whose dependencies include a failed step as failed.
324
+ * Returns IDs of newly failed steps.
325
+ */
326
+ markUnreachable(): string[];
133
327
  }
134
328
 
135
- interface RuntimeRecommendation {
136
- runtimeId: string;
137
- name: string;
138
- score: number;
139
- reason: string;
329
+ type EngineWorkflowState = "created" | "running" | "completed" | "failed";
330
+ interface WorkflowExecution {
331
+ workflow: Workflow;
332
+ state: EngineWorkflowState;
333
+ scheduler: SimpleScheduler;
334
+ stepResults: Map<string, StepResult>;
335
+ activeSessions: Map<string, SessionHandle>;
336
+ startedAt: number;
337
+ completedAt?: number;
338
+ }
339
+ interface WorkflowStatus {
340
+ workflowId: string;
341
+ state: EngineWorkflowState;
342
+ steps: Array<{
343
+ stepId: string;
344
+ state: string;
345
+ result?: StepResult;
346
+ }>;
347
+ startedAt: number;
348
+ completedAt?: number;
140
349
  }
141
- interface Router {
142
- /** Recommends available runtimes for a given task. The agent decides which to use. */
143
- recommend(taskType: string): RuntimeRecommendation[];
350
+ interface CostSummary {
351
+ totalUsd: number;
352
+ totalTokens: {
353
+ input: number;
354
+ output: number;
355
+ };
356
+ perStep: Array<{
357
+ stepId: string;
358
+ cost: CostRecord;
359
+ durationMs: number;
360
+ }>;
144
361
  }
362
+ declare class OrchestrationEngine {
363
+ private adapter;
364
+ private bus;
365
+ private storage;
366
+ private executions;
367
+ constructor(adapter: RuntimeAdapter, bus: EventBus, storage: StorageAdapter);
368
+ createWorkflow(def: Workflow): Workflow;
369
+ startWorkflow(workflowId: string): Promise<void>;
370
+ cancelWorkflow(workflowId: string): Promise<void>;
371
+ getWorkflowStatus(workflowId: string): WorkflowStatus;
372
+ getCostSummary(workflowId?: string): CostSummary;
373
+ private advanceWorkflow;
374
+ private spawnStep;
375
+ private handleAdapterEvent;
376
+ private handleStepCompleted;
377
+ private handleStepFailed;
378
+ }
379
+
380
+ /**
381
+ * MCP tool JSON Schema definitions for Yesod agent-facing tools.
382
+ */
383
+ declare const YESOD_TOOLS: {
384
+ readonly yesod_create_workflow: {
385
+ readonly name: "yesod_create_workflow";
386
+ readonly description: "Create and start a multi-step workflow. Define the steps, their dependencies, and expected output formats. Yesod will orchestrate execution, spawn child agents, and chain results automatically.";
387
+ readonly inputSchema: {
388
+ readonly type: "object";
389
+ readonly properties: {
390
+ readonly name: {
391
+ readonly type: "string";
392
+ readonly description: "Human-readable name for the workflow";
393
+ };
394
+ readonly steps: {
395
+ readonly type: "array";
396
+ readonly description: "Workflow steps to execute";
397
+ readonly items: {
398
+ readonly type: "object";
399
+ readonly properties: {
400
+ readonly id: {
401
+ readonly type: "string";
402
+ readonly description: "Unique step identifier";
403
+ };
404
+ readonly name: {
405
+ readonly type: "string";
406
+ readonly description: "Human-readable step name";
407
+ };
408
+ readonly task: {
409
+ readonly type: "string";
410
+ readonly description: "Instruction for the agent performing this step";
411
+ };
412
+ readonly expectedResult: {
413
+ readonly type: "object";
414
+ readonly description: "Expected output format";
415
+ readonly properties: {
416
+ readonly format: {
417
+ readonly type: "string";
418
+ readonly enum: readonly ["summary", "structured", "diff", "review", "test"];
419
+ };
420
+ readonly fields: {
421
+ readonly type: "array";
422
+ readonly items: {
423
+ readonly type: "string";
424
+ };
425
+ readonly description: "Fields to include (for structured format)";
426
+ };
427
+ readonly maxLength: {
428
+ readonly type: "number";
429
+ readonly description: "Max output length in characters";
430
+ };
431
+ };
432
+ readonly required: readonly ["format"];
433
+ };
434
+ readonly runtime: {
435
+ readonly type: "string";
436
+ readonly description: "Runtime to use (e.g. claude-code, codex)";
437
+ };
438
+ readonly decision: {
439
+ readonly type: "object";
440
+ readonly description: "Why this runtime was chosen";
441
+ readonly properties: {
442
+ readonly reason: {
443
+ readonly type: "string";
444
+ };
445
+ readonly considered: {
446
+ readonly type: "array";
447
+ readonly items: {
448
+ readonly type: "string";
449
+ };
450
+ };
451
+ readonly chosen: {
452
+ readonly type: "string";
453
+ };
454
+ };
455
+ readonly required: readonly ["reason", "considered", "chosen"];
456
+ };
457
+ readonly dependsOn: {
458
+ readonly type: "array";
459
+ readonly items: {
460
+ readonly type: "string";
461
+ };
462
+ readonly description: "Step IDs this step depends on";
463
+ };
464
+ readonly timeout: {
465
+ readonly type: "number";
466
+ readonly description: "Timeout in milliseconds";
467
+ };
468
+ };
469
+ readonly required: readonly ["id", "name", "task", "expectedResult", "runtime", "decision"];
470
+ };
471
+ };
472
+ };
473
+ readonly required: readonly ["name", "steps"];
474
+ };
475
+ };
476
+ readonly yesod_workflow_status: {
477
+ readonly name: "yesod_workflow_status";
478
+ readonly description: "Check the current status of a running workflow, including per-step progress and results.";
479
+ readonly inputSchema: {
480
+ readonly type: "object";
481
+ readonly properties: {
482
+ readonly workflowId: {
483
+ readonly type: "string";
484
+ readonly description: "ID of the workflow to check";
485
+ };
486
+ };
487
+ readonly required: readonly ["workflowId"];
488
+ };
489
+ };
490
+ readonly yesod_cancel_workflow: {
491
+ readonly name: "yesod_cancel_workflow";
492
+ readonly description: "Cancel a running workflow. Kills all active sessions and marks the workflow as failed.";
493
+ readonly inputSchema: {
494
+ readonly type: "object";
495
+ readonly properties: {
496
+ readonly workflowId: {
497
+ readonly type: "string";
498
+ readonly description: "ID of the workflow to cancel";
499
+ };
500
+ };
501
+ readonly required: readonly ["workflowId"];
502
+ };
503
+ };
504
+ readonly yesod_cost_summary: {
505
+ readonly name: "yesod_cost_summary";
506
+ readonly description: "Get a cost breakdown showing token usage and USD cost, optionally filtered to a specific workflow.";
507
+ readonly inputSchema: {
508
+ readonly type: "object";
509
+ readonly properties: {
510
+ readonly workflowId: {
511
+ readonly type: "string";
512
+ readonly description: "Optional: filter to a specific workflow";
513
+ };
514
+ };
515
+ };
516
+ };
517
+ };
145
518
 
146
- export { type CodingSession, EventBus, type EventFilter, type EventHandler, EventType, InMemoryStorageAdapter, type NotificationEvent, type ReadyStep, type Router, type RuntimeRecommendation, type Scheduler, type SessionControl, type SessionState, type StorageAdapter, type StorageQuery, type Subscription, type SubscriptionCondition, VantageEngine, type Workflow, type WorkflowState, type WorkflowStep, type YesodEvent };
519
+ export { type CodingSession, type CodingSpawnOptions, type CostRecord, type CostSummary, type DiffOutput, type EngineWorkflowState, EventBus, type EventFilter, type EventHandler, EventType, InMemoryStorageAdapter, type NotificationEvent, OrchestrationEngine, type RawFallbackOutput, type ReadyStep, type ResultSpec, type RetryPolicy, type ReviewOutput, type RuntimeAdapter, type RuntimeDecision, type Scheduler, type SessionControl, type SessionHandle, type SessionState, type SessionStatus, SimpleScheduler, type SpawnOptions, type StepResult, type StepState, type StorageAdapter, type StorageQuery, type StructuredFieldsOutput, type StructuredOutput, type Subscription, type SubscriptionCondition, type SummaryOutput, type TaskSpec, type TestOutput, VantageEngine, type Workflow, type WorkflowExecution, type WorkflowInput, type WorkflowState, type WorkflowStatus, type WorkflowStep, type WorkflowTrigger, YESOD_TOOLS, type YesodEvent };