@yesod/core 0.0.1 → 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.
package/dist/index.d.ts 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 };