wave-agent-sdk 0.17.1 → 0.17.3

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.
Files changed (173) hide show
  1. package/builtin/skills/deep-research/SKILL.md +90 -0
  2. package/builtin/skills/settings/ENV.md +6 -3
  3. package/dist/agent.d.ts +28 -1
  4. package/dist/agent.d.ts.map +1 -1
  5. package/dist/agent.js +128 -34
  6. package/dist/constants/goalPrompts.d.ts +2 -0
  7. package/dist/constants/goalPrompts.d.ts.map +1 -0
  8. package/dist/constants/goalPrompts.js +10 -0
  9. package/dist/constants/tools.d.ts +1 -0
  10. package/dist/constants/tools.d.ts.map +1 -1
  11. package/dist/constants/tools.js +1 -0
  12. package/dist/managers/aiManager.d.ts +7 -0
  13. package/dist/managers/aiManager.d.ts.map +1 -1
  14. package/dist/managers/aiManager.js +77 -41
  15. package/dist/managers/backgroundTaskManager.d.ts.map +1 -1
  16. package/dist/managers/backgroundTaskManager.js +10 -2
  17. package/dist/managers/goalManager.d.ts +43 -0
  18. package/dist/managers/goalManager.d.ts.map +1 -0
  19. package/dist/managers/goalManager.js +177 -0
  20. package/dist/managers/messageManager.d.ts +2 -2
  21. package/dist/managers/messageManager.d.ts.map +1 -1
  22. package/dist/managers/messageQueue.d.ts +10 -0
  23. package/dist/managers/messageQueue.d.ts.map +1 -1
  24. package/dist/managers/messageQueue.js +53 -1
  25. package/dist/managers/pluginManager.d.ts.map +1 -1
  26. package/dist/managers/pluginManager.js +7 -1
  27. package/dist/managers/skillManager.d.ts +2 -0
  28. package/dist/managers/skillManager.d.ts.map +1 -1
  29. package/dist/managers/skillManager.js +19 -9
  30. package/dist/managers/slashCommandManager.d.ts +6 -0
  31. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  32. package/dist/managers/slashCommandManager.js +105 -0
  33. package/dist/managers/toolManager.d.ts.map +1 -1
  34. package/dist/managers/toolManager.js +5 -0
  35. package/dist/managers/workflowManager.d.ts +65 -0
  36. package/dist/managers/workflowManager.d.ts.map +1 -0
  37. package/dist/managers/workflowManager.js +380 -0
  38. package/dist/prompts/index.d.ts +2 -1
  39. package/dist/prompts/index.d.ts.map +1 -1
  40. package/dist/prompts/index.js +3 -3
  41. package/dist/services/MarketplaceService.d.ts +2 -2
  42. package/dist/services/MarketplaceService.d.ts.map +1 -1
  43. package/dist/services/MarketplaceService.js +11 -32
  44. package/dist/services/aiService.d.ts +23 -0
  45. package/dist/services/aiService.d.ts.map +1 -1
  46. package/dist/services/aiService.js +102 -9
  47. package/dist/services/configurationService.d.ts +1 -1
  48. package/dist/services/configurationService.d.ts.map +1 -1
  49. package/dist/services/configurationService.js +3 -16
  50. package/dist/services/hook.d.ts.map +1 -1
  51. package/dist/services/hook.js +4 -0
  52. package/dist/services/session.d.ts +9 -1
  53. package/dist/services/session.d.ts.map +1 -1
  54. package/dist/services/session.js +28 -1
  55. package/dist/tools/bashTool.d.ts.map +1 -1
  56. package/dist/tools/bashTool.js +49 -7
  57. package/dist/tools/readTool.d.ts.map +1 -1
  58. package/dist/tools/readTool.js +1 -1
  59. package/dist/tools/taskManagementTools.d.ts.map +1 -1
  60. package/dist/tools/taskManagementTools.js +103 -157
  61. package/dist/tools/types.d.ts +2 -0
  62. package/dist/tools/types.d.ts.map +1 -1
  63. package/dist/tools/webFetchTool.d.ts.map +1 -1
  64. package/dist/tools/webFetchTool.js +0 -9
  65. package/dist/tools/workflowTool.d.ts +11 -0
  66. package/dist/tools/workflowTool.d.ts.map +1 -0
  67. package/dist/tools/workflowTool.js +190 -0
  68. package/dist/types/agent.d.ts +2 -0
  69. package/dist/types/agent.d.ts.map +1 -1
  70. package/dist/types/commands.d.ts +4 -0
  71. package/dist/types/commands.d.ts.map +1 -1
  72. package/dist/types/config.d.ts +2 -2
  73. package/dist/types/config.d.ts.map +1 -1
  74. package/dist/types/core.d.ts +1 -1
  75. package/dist/types/core.d.ts.map +1 -1
  76. package/dist/types/hooks.d.ts +2 -0
  77. package/dist/types/hooks.d.ts.map +1 -1
  78. package/dist/types/index.d.ts +1 -0
  79. package/dist/types/index.d.ts.map +1 -1
  80. package/dist/types/index.js +1 -0
  81. package/dist/types/messaging.d.ts +2 -2
  82. package/dist/types/messaging.d.ts.map +1 -1
  83. package/dist/types/processes.d.ts +6 -2
  84. package/dist/types/processes.d.ts.map +1 -1
  85. package/dist/types/workflow.d.ts +2 -0
  86. package/dist/types/workflow.d.ts.map +1 -0
  87. package/dist/types/workflow.js +1 -0
  88. package/dist/utils/cacheControlUtils.d.ts +13 -8
  89. package/dist/utils/cacheControlUtils.d.ts.map +1 -1
  90. package/dist/utils/cacheControlUtils.js +73 -102
  91. package/dist/utils/containerSetup.d.ts.map +1 -1
  92. package/dist/utils/containerSetup.js +7 -0
  93. package/dist/utils/markdownParser.d.ts.map +1 -1
  94. package/dist/utils/markdownParser.js +21 -6
  95. package/dist/utils/messageOperations.d.ts +2 -2
  96. package/dist/utils/messageOperations.d.ts.map +1 -1
  97. package/dist/utils/notificationXml.d.ts.map +1 -1
  98. package/dist/workflow/budgetTracker.d.ts +12 -0
  99. package/dist/workflow/budgetTracker.d.ts.map +1 -0
  100. package/dist/workflow/budgetTracker.js +30 -0
  101. package/dist/workflow/concurrencyLimiter.d.ts +14 -0
  102. package/dist/workflow/concurrencyLimiter.d.ts.map +1 -0
  103. package/dist/workflow/concurrencyLimiter.js +39 -0
  104. package/dist/workflow/journal.d.ts +19 -0
  105. package/dist/workflow/journal.d.ts.map +1 -0
  106. package/dist/workflow/journal.js +74 -0
  107. package/dist/workflow/progressReporter.d.ts +21 -0
  108. package/dist/workflow/progressReporter.d.ts.map +1 -0
  109. package/dist/workflow/progressReporter.js +118 -0
  110. package/dist/workflow/runState.d.ts +16 -0
  111. package/dist/workflow/runState.d.ts.map +1 -0
  112. package/dist/workflow/runState.js +57 -0
  113. package/dist/workflow/scriptRuntime.d.ts +35 -0
  114. package/dist/workflow/scriptRuntime.d.ts.map +1 -0
  115. package/dist/workflow/scriptRuntime.js +196 -0
  116. package/dist/workflow/structuredOutput.d.ts +27 -0
  117. package/dist/workflow/structuredOutput.d.ts.map +1 -0
  118. package/dist/workflow/structuredOutput.js +106 -0
  119. package/dist/workflow/types.d.ts +81 -0
  120. package/dist/workflow/types.d.ts.map +1 -0
  121. package/dist/workflow/types.js +1 -0
  122. package/dist/workflow/workflowApis.d.ts +46 -0
  123. package/dist/workflow/workflowApis.d.ts.map +1 -0
  124. package/dist/workflow/workflowApis.js +280 -0
  125. package/package.json +1 -1
  126. package/src/agent.ts +144 -34
  127. package/src/constants/goalPrompts.ts +10 -0
  128. package/src/constants/tools.ts +1 -0
  129. package/src/managers/aiManager.ts +91 -47
  130. package/src/managers/backgroundTaskManager.ts +16 -4
  131. package/src/managers/goalManager.ts +232 -0
  132. package/src/managers/messageManager.ts +2 -2
  133. package/src/managers/messageQueue.ts +59 -1
  134. package/src/managers/pluginManager.ts +8 -1
  135. package/src/managers/skillManager.ts +20 -9
  136. package/src/managers/slashCommandManager.ts +119 -0
  137. package/src/managers/toolManager.ts +7 -0
  138. package/src/managers/workflowManager.ts +491 -0
  139. package/src/prompts/index.ts +4 -2
  140. package/src/services/MarketplaceService.ts +14 -38
  141. package/src/services/aiService.ts +166 -12
  142. package/src/services/configurationService.ts +2 -22
  143. package/src/services/hook.ts +5 -0
  144. package/src/services/session.ts +42 -2
  145. package/src/tools/bashTool.ts +64 -9
  146. package/src/tools/readTool.ts +1 -2
  147. package/src/tools/taskManagementTools.ts +146 -195
  148. package/src/tools/types.ts +2 -0
  149. package/src/tools/webFetchTool.ts +0 -12
  150. package/src/tools/workflowTool.ts +205 -0
  151. package/src/types/agent.ts +6 -0
  152. package/src/types/commands.ts +4 -0
  153. package/src/types/config.ts +2 -2
  154. package/src/types/core.ts +3 -3
  155. package/src/types/hooks.ts +2 -0
  156. package/src/types/index.ts +1 -0
  157. package/src/types/messaging.ts +2 -2
  158. package/src/types/processes.ts +10 -2
  159. package/src/types/workflow.ts +5 -0
  160. package/src/utils/cacheControlUtils.ts +106 -131
  161. package/src/utils/containerSetup.ts +9 -0
  162. package/src/utils/markdownParser.ts +26 -8
  163. package/src/utils/messageOperations.ts +2 -2
  164. package/src/utils/notificationXml.ts +6 -1
  165. package/src/workflow/budgetTracker.ts +34 -0
  166. package/src/workflow/concurrencyLimiter.ts +47 -0
  167. package/src/workflow/journal.ts +95 -0
  168. package/src/workflow/progressReporter.ts +141 -0
  169. package/src/workflow/runState.ts +65 -0
  170. package/src/workflow/scriptRuntime.ts +274 -0
  171. package/src/workflow/structuredOutput.ts +123 -0
  172. package/src/workflow/types.ts +95 -0
  173. package/src/workflow/workflowApis.ts +412 -0
@@ -0,0 +1,274 @@
1
+ import type { WorkflowMeta } from "./types.js";
2
+ import { logger } from "../utils/globalLogger.js";
3
+
4
+ /** Patterns that are banned in workflow scripts for safety and determinism */
5
+ const BANNED_PATTERNS = [
6
+ {
7
+ pattern: /\brequire\s*\(/,
8
+ message: "require() is not available in workflow scripts",
9
+ },
10
+ {
11
+ pattern: /\bprocess\./,
12
+ message: "process.* is not available in workflow scripts",
13
+ },
14
+ {
15
+ pattern: /\beval\s*\(/,
16
+ message: "eval() is not available in workflow scripts",
17
+ },
18
+ {
19
+ pattern: /\bimport\s+/,
20
+ message: "import statements are not available in workflow scripts",
21
+ },
22
+ {
23
+ pattern: /\bDate\.now\s*\(/,
24
+ message: "Date.now() would break resume determinism",
25
+ },
26
+ {
27
+ pattern: /\bMath\.random\s*\(/,
28
+ message: "Math.random() would break resume determinism",
29
+ },
30
+ {
31
+ pattern: /\bnew\s+Date\s*\(\s*\)/,
32
+ message: "argless new Date() would break resume determinism",
33
+ },
34
+ {
35
+ pattern: /\brequire\s*\(\s*['"]fs['"]\s*\)/,
36
+ message: "filesystem access is not available in workflow scripts",
37
+ },
38
+ {
39
+ pattern: /\bfs\.\w+/,
40
+ message: "filesystem access is not available in workflow scripts",
41
+ },
42
+ {
43
+ pattern: /\bchild_process\b/,
44
+ message: "child_process is not available in workflow scripts",
45
+ },
46
+ {
47
+ pattern: /\b__dirname\b/,
48
+ message: "__dirname is not available in workflow scripts",
49
+ },
50
+ {
51
+ pattern: /\b__filename\b/,
52
+ message: "__filename is not available in workflow scripts",
53
+ },
54
+ {
55
+ pattern: /\bglobal\./,
56
+ message: "global.* is not available in workflow scripts",
57
+ },
58
+ {
59
+ pattern: /\bglobalThis\b/,
60
+ message: "globalThis is not available in workflow scripts",
61
+ },
62
+ ];
63
+
64
+ export interface ParsedScript {
65
+ meta: WorkflowMeta;
66
+ body: string;
67
+ }
68
+
69
+ export interface ScriptValidationResult {
70
+ valid: boolean;
71
+ errors: string[];
72
+ }
73
+
74
+ /**
75
+ * Validate a workflow script for banned patterns and required structure
76
+ */
77
+ export function validateScript(script: string): ScriptValidationResult {
78
+ const errors: string[] = [];
79
+
80
+ // Check for export const meta = {...}
81
+ if (!/export\s+const\s+meta\s*=/.test(script)) {
82
+ errors.push("Script must start with 'export const meta = {...}'");
83
+ }
84
+
85
+ // Check banned patterns
86
+ for (const { pattern, message } of BANNED_PATTERNS) {
87
+ if (pattern.test(script)) {
88
+ errors.push(message);
89
+ }
90
+ }
91
+
92
+ return { valid: errors.length === 0, errors };
93
+ }
94
+
95
+ /**
96
+ * Parse a workflow script into meta and body.
97
+ * Extracts the `export const meta = {...}` declaration and the rest of the script.
98
+ */
99
+ export function parseScript(script: string): ParsedScript {
100
+ // Match: export const meta = { ... }
101
+ // We need to find the matching closing brace for the meta object
102
+ const metaStartMatch = script.match(/export\s+const\s+meta\s*=\s*/);
103
+ if (!metaStartMatch) {
104
+ throw new Error("Script must contain 'export const meta = {...}'");
105
+ }
106
+
107
+ const metaStartIndex = metaStartMatch.index! + metaStartMatch[0].length;
108
+
109
+ // Find the matching closing brace for the meta object
110
+ let depth = 0;
111
+ let metaEndIndex = -1;
112
+ let inString: string | null = null;
113
+ let escaped = false;
114
+
115
+ for (let i = metaStartIndex; i < script.length; i++) {
116
+ const char = script[i];
117
+
118
+ if (escaped) {
119
+ escaped = false;
120
+ continue;
121
+ }
122
+
123
+ if (char === "\\") {
124
+ escaped = true;
125
+ continue;
126
+ }
127
+
128
+ if (inString) {
129
+ if (char === inString) {
130
+ inString = null;
131
+ }
132
+ continue;
133
+ }
134
+
135
+ if (char === '"' || char === "'" || char === "`") {
136
+ inString = char;
137
+ continue;
138
+ }
139
+
140
+ if (char === "{") {
141
+ depth++;
142
+ } else if (char === "}") {
143
+ depth--;
144
+ if (depth === 0) {
145
+ metaEndIndex = i + 1;
146
+ break;
147
+ }
148
+ }
149
+ }
150
+
151
+ if (metaEndIndex === -1) {
152
+ throw new Error("Could not find matching closing brace for meta object");
153
+ }
154
+
155
+ const metaString = script.slice(metaStartIndex, metaEndIndex);
156
+
157
+ // Parse meta as JSON (allowing JS object syntax — unquoted keys, trailing commas)
158
+ // We use a safe approach: wrap in parentheses and use Function to evaluate
159
+ let meta: WorkflowMeta;
160
+ try {
161
+ // Remove trailing comma before closing brace/bracket (common in JS objects)
162
+ const cleaned = metaString.replace(/,\s*([}\]])/g, "$1");
163
+ // Wrap unquoted keys with double quotes
164
+ const quoted = cleaned.replace(/(\w+)\s*:/g, '"$1":');
165
+ meta = JSON.parse(quoted);
166
+ } catch {
167
+ // Fallback: use Function constructor for safe evaluation
168
+ try {
169
+ const fn = new Function(`"use strict"; return (${metaString});`);
170
+ meta = fn();
171
+ } catch (e) {
172
+ throw new Error(
173
+ `Failed to parse meta object: ${e instanceof Error ? e.message : String(e)}`,
174
+ );
175
+ }
176
+ }
177
+
178
+ // Validate required meta fields
179
+ if (!meta.name || typeof meta.name !== "string") {
180
+ throw new Error("meta.name is required and must be a string");
181
+ }
182
+ if (!meta.description || typeof meta.description !== "string") {
183
+ throw new Error("meta.description is required and must be a string");
184
+ }
185
+
186
+ // Body is everything after the meta declaration (and any trailing semicolons/newlines)
187
+ const bodyStart = metaEndIndex;
188
+ const body = script.slice(bodyStart).replace(/^\s*;?\s*/, "");
189
+
190
+ return { meta, body };
191
+ }
192
+
193
+ /**
194
+ * Execute a workflow script with the given API closures.
195
+ * The script body is wrapped in an async IIFE and executed via new Function().
196
+ */
197
+ export async function executeScript(
198
+ script: string,
199
+ apis: {
200
+ agent: (prompt: string, opts?: Record<string, unknown>) => Promise<unknown>;
201
+ parallel: (thunks: Array<() => Promise<unknown>>) => Promise<unknown[]>;
202
+ pipeline: (
203
+ items: unknown[],
204
+ ...stages: Array<
205
+ (prev: unknown, item: unknown, index: number) => Promise<unknown>
206
+ >
207
+ ) => Promise<unknown[]>;
208
+ phase: (title: string) => void;
209
+ log: (message: string) => void;
210
+ args: unknown;
211
+ budget: unknown;
212
+ },
213
+ abortSignal?: AbortSignal,
214
+ ): Promise<{ meta: WorkflowMeta; result: unknown }> {
215
+ // Validate first
216
+ const validation = validateScript(script);
217
+ if (!validation.valid) {
218
+ throw new Error(
219
+ `Script validation failed:\n${validation.errors.join("\n")}`,
220
+ );
221
+ }
222
+
223
+ // Parse script
224
+ const { meta, body } = parseScript(script);
225
+
226
+ logger.info(
227
+ `[Workflow] Executing script "${meta.name}": ${meta.description}`,
228
+ );
229
+
230
+ // Wrap the body in an async function and inject API closures
231
+ const fn = new Function(
232
+ "agent",
233
+ "parallel",
234
+ "pipeline",
235
+ "phase",
236
+ "log",
237
+ "args",
238
+ "budget",
239
+ `"use strict"; return (async () => { ${body} })();`,
240
+ );
241
+
242
+ // Execute with abort support
243
+ const scriptPromise = fn(
244
+ apis.agent,
245
+ apis.parallel,
246
+ apis.pipeline,
247
+ apis.phase,
248
+ apis.log,
249
+ apis.args,
250
+ apis.budget,
251
+ );
252
+
253
+ let result: unknown;
254
+ if (abortSignal) {
255
+ result = await Promise.race([
256
+ scriptPromise,
257
+ new Promise<never>((_, reject) => {
258
+ if (abortSignal.aborted) {
259
+ reject(new Error("Workflow aborted"));
260
+ return;
261
+ }
262
+ abortSignal.addEventListener(
263
+ "abort",
264
+ () => reject(new Error("Workflow aborted")),
265
+ { once: true },
266
+ );
267
+ }),
268
+ ]);
269
+ } else {
270
+ result = await scriptPromise;
271
+ }
272
+
273
+ return { meta, result };
274
+ }
@@ -0,0 +1,123 @@
1
+ import type { ToolPlugin, ToolResult } from "../tools/types.js";
2
+
3
+ const STRUCTURED_OUTPUT_TOOL_NAME = "StructuredOutput";
4
+
5
+ /**
6
+ * Creates a system prompt addition that instructs the agent to use structured output
7
+ */
8
+ export function createStructuredOutputPrompt(schema: object): string {
9
+ return `\n\nIMPORTANT: You MUST call the ${STRUCTURED_OUTPUT_TOOL_NAME} tool with your final answer. Do not just write the answer as text — call the tool with a JSON object matching this schema:\n${JSON.stringify(schema, null, 2)}\n\nCall this tool exactly once with your complete answer.`;
10
+ }
11
+
12
+ /**
13
+ * Creates a StructuredOutput ToolPlugin that enforces the given schema
14
+ */
15
+ export function createStructuredOutputTool(schema: object): ToolPlugin {
16
+ return {
17
+ name: STRUCTURED_OUTPUT_TOOL_NAME,
18
+ config: {
19
+ type: "function" as const,
20
+ function: {
21
+ name: STRUCTURED_OUTPUT_TOOL_NAME,
22
+ description:
23
+ "Output structured data matching the required schema. Call this with your final answer.",
24
+ parameters: schema as Record<string, unknown>,
25
+ },
26
+ },
27
+ execute: async (args: Record<string, unknown>): Promise<ToolResult> => {
28
+ // The tool just returns the args as-is — the real validation happens
29
+ // in extractStructuredResult after the agent completes
30
+ return {
31
+ success: true,
32
+ content: JSON.stringify(args),
33
+ };
34
+ },
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Extract structured result from a completed subagent's messages.
40
+ * Looks for StructuredOutput tool calls in the messages.
41
+ * Falls back to JSON.parse on the last assistant message text.
42
+ */
43
+ export function extractStructuredResult(
44
+ messages: Array<{
45
+ role: string;
46
+ content?: string;
47
+ tool_calls?: Array<{ function: { name: string; arguments: string } }>;
48
+ }>,
49
+ schema: object,
50
+ ): unknown | null {
51
+ // Search messages in reverse for a StructuredOutput tool call
52
+ for (let i = messages.length - 1; i >= 0; i--) {
53
+ const msg = messages[i];
54
+ if (msg.tool_calls) {
55
+ for (const tc of msg.tool_calls) {
56
+ if (tc.function.name === STRUCTURED_OUTPUT_TOOL_NAME) {
57
+ try {
58
+ const parsed = JSON.parse(tc.function.arguments);
59
+ if (validateAgainstSchema(parsed, schema)) {
60
+ return parsed;
61
+ }
62
+ } catch {
63
+ // Parse error — continue searching
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ // Fallback: try to extract JSON from the last assistant message
71
+ for (let i = messages.length - 1; i >= 0; i--) {
72
+ const msg = messages[i];
73
+ if (msg.role === "assistant" && msg.content) {
74
+ // Try to find JSON in the content
75
+ const jsonMatch = msg.content.match(/```json\n([\s\S]*?)\n```/);
76
+ if (jsonMatch) {
77
+ try {
78
+ const parsed = JSON.parse(jsonMatch[1]);
79
+ if (validateAgainstSchema(parsed, schema)) {
80
+ return parsed;
81
+ }
82
+ } catch {
83
+ // Parse error — continue
84
+ }
85
+ }
86
+
87
+ // Try parsing the entire content as JSON
88
+ try {
89
+ const parsed = JSON.parse(msg.content);
90
+ if (validateAgainstSchema(parsed, schema)) {
91
+ return parsed;
92
+ }
93
+ } catch {
94
+ // Not JSON — continue
95
+ }
96
+ }
97
+ }
98
+
99
+ return null;
100
+ }
101
+
102
+ /**
103
+ * Basic schema validation — checks that required fields exist.
104
+ * This is intentionally lightweight; full JSON Schema validation
105
+ * would require a dependency like ajv.
106
+ */
107
+ function validateAgainstSchema(data: unknown, schema: object): boolean {
108
+ if (!data || typeof data !== "object") return false;
109
+ const schemaObj = schema as {
110
+ properties?: Record<string, unknown>;
111
+ required?: string[];
112
+ };
113
+ if (schemaObj.required && Array.isArray(schemaObj.required)) {
114
+ for (const field of schemaObj.required) {
115
+ if (!(field in (data as Record<string, unknown>))) {
116
+ return false;
117
+ }
118
+ }
119
+ }
120
+ return true;
121
+ }
122
+
123
+ export { STRUCTURED_OUTPUT_TOOL_NAME };
@@ -0,0 +1,95 @@
1
+ export interface WorkflowMetaPhase {
2
+ title: string;
3
+ detail?: string;
4
+ model?: string;
5
+ }
6
+
7
+ export interface WorkflowMeta {
8
+ name: string;
9
+ description: string;
10
+ whenToUse?: string;
11
+ phases?: WorkflowMetaPhase[];
12
+ }
13
+
14
+ export interface WorkflowPhaseState {
15
+ title: string;
16
+ agentCount: number;
17
+ tokens: number;
18
+ elapsed: number;
19
+ startTime: number;
20
+ }
21
+
22
+ export interface WorkflowRun {
23
+ runId: string;
24
+ meta: WorkflowMeta;
25
+ status: "running" | "paused" | "completed" | "failed" | "aborted";
26
+ scriptPath: string;
27
+ args?: unknown;
28
+ startTime: number;
29
+ endTime?: number;
30
+ phases: WorkflowPhaseState[];
31
+ totalAgents: number;
32
+ totalTokens: number;
33
+ result?: unknown;
34
+ error?: string;
35
+ /** Resolves when the background execution finishes (completed/failed/aborted) */
36
+ completionPromise?: Promise<void>;
37
+ /** If set, this run resumes from a previous run's journal */
38
+ resumeFromRunId?: string;
39
+ /** Index of the agent that caused the workflow to fail */
40
+ failedAgentIndex?: number;
41
+ /** Error message from the failed agent */
42
+ failedAgentError?: string;
43
+ }
44
+
45
+ export interface JournalEntry {
46
+ agentIndex: number;
47
+ prompt: string;
48
+ opts: Record<string, unknown>;
49
+ result: unknown;
50
+ tokens: number;
51
+ /** Subagent instance ID for linking to the full conversation transcript */
52
+ subagentId?: string;
53
+ /** Path to the subagent's transcript JSONL file */
54
+ transcriptPath?: string;
55
+ }
56
+
57
+ export interface AgentMeta {
58
+ agentType: string;
59
+ subagentId: string;
60
+ transcriptPath: string;
61
+ label?: string;
62
+ phase?: string;
63
+ }
64
+
65
+ export interface LogEntry {
66
+ type: "log";
67
+ message: string;
68
+ }
69
+
70
+ export interface AgentFailedEntry {
71
+ type: "agent_failed";
72
+ agentIndex: number;
73
+ error: string;
74
+ }
75
+
76
+ export type JournalLine = JournalEntry | LogEntry | AgentFailedEntry;
77
+
78
+ export interface BudgetInfo {
79
+ total: number | null;
80
+ spent: () => number;
81
+ remaining: () => number;
82
+ }
83
+
84
+ export interface WorkflowProgressEvent {
85
+ type:
86
+ | "phase_started"
87
+ | "phase_completed"
88
+ | "agent_started"
89
+ | "agent_completed"
90
+ | "agent_failed";
91
+ runId: string;
92
+ phaseIndex: number;
93
+ agentIndex?: number;
94
+ timestamp: number;
95
+ }