juno-code 1.0.46 → 1.0.49
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/README.md +44 -8
- package/dist/bin/cli.d.mts +17 -0
- package/dist/bin/cli.d.ts +17 -0
- package/dist/bin/cli.js +5601 -17505
- package/dist/bin/cli.js.map +1 -1
- package/dist/bin/cli.mjs +5640 -17542
- package/dist/bin/cli.mjs.map +1 -1
- package/dist/bin/feedback-collector.d.mts +2 -0
- package/dist/bin/feedback-collector.d.ts +2 -0
- package/dist/bin/feedback-collector.js.map +1 -1
- package/dist/bin/feedback-collector.mjs.map +1 -1
- package/dist/index.d.mts +2107 -0
- package/dist/index.d.ts +2107 -0
- package/dist/index.js +3760 -14728
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3761 -14536
- package/dist/index.mjs.map +1 -1
- package/dist/templates/extensions/pi/juno-skill-preprocessor.ts +239 -0
- package/dist/templates/scripts/__pycache__/github.cpython-313.pyc +0 -0
- package/dist/templates/scripts/__pycache__/parallel_runner.cpython-313.pyc +0 -0
- package/dist/templates/scripts/__pycache__/slack_respond.cpython-313.pyc +0 -0
- package/dist/templates/scripts/kanban.sh +18 -4
- package/dist/templates/scripts/parallel_runner.sh +2242 -0
- package/dist/templates/services/README.md +61 -1
- package/dist/templates/services/__pycache__/claude.cpython-313.pyc +0 -0
- package/dist/templates/services/__pycache__/codex.cpython-313.pyc +0 -0
- package/dist/templates/services/__pycache__/pi.cpython-313.pyc +0 -0
- package/dist/templates/services/claude.py +132 -33
- package/dist/templates/services/codex.py +179 -66
- package/dist/templates/services/gemini.py +117 -27
- package/dist/templates/services/pi.py +1753 -0
- package/dist/templates/skills/claude/plan-kanban-tasks/SKILL.md +14 -7
- package/dist/templates/skills/claude/ralph-loop/SKILL.md +18 -22
- package/dist/templates/skills/claude/ralph-loop/references/first_check.md +15 -14
- package/dist/templates/skills/claude/ralph-loop/references/implement.md +17 -17
- package/dist/templates/skills/claude/ralph-loop/scripts/kanban.sh +18 -4
- package/dist/templates/skills/claude/understand-project/SKILL.md +14 -7
- package/dist/templates/skills/codex/ralph-loop/SKILL.md +18 -22
- package/dist/templates/skills/codex/ralph-loop/references/first_check.md +15 -14
- package/dist/templates/skills/codex/ralph-loop/references/implement.md +17 -17
- package/dist/templates/skills/codex/ralph-loop/scripts/kanban.sh +18 -4
- package/dist/templates/skills/pi/.gitkeep +0 -0
- package/dist/templates/skills/pi/plan-kanban-tasks/SKILL.md +32 -0
- package/dist/templates/skills/pi/ralph-loop/SKILL.md +39 -0
- package/dist/templates/skills/pi/ralph-loop/references/first_check.md +21 -0
- package/dist/templates/skills/pi/ralph-loop/references/implement.md +99 -0
- package/dist/templates/skills/pi/understand-project/SKILL.md +46 -0
- package/package.json +20 -42
- package/dist/templates/scripts/__pycache__/attachment_downloader.cpython-38.pyc +0 -0
- package/dist/templates/scripts/__pycache__/github.cpython-38.pyc +0 -0
- package/dist/templates/scripts/__pycache__/slack_fetch.cpython-38.pyc +0 -0
- package/dist/templates/scripts/__pycache__/slack_state.cpython-38.pyc +0 -0
- package/dist/templates/services/__pycache__/claude.cpython-38.pyc +0 -0
- package/dist/templates/services/__pycache__/codex.cpython-38.pyc +0 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2107 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Core type definitions for juno-code
|
|
6
|
+
*/
|
|
7
|
+
type SubagentType = 'claude' | 'cursor' | 'codex' | 'gemini' | 'pi';
|
|
8
|
+
type BackendType = 'shell';
|
|
9
|
+
type SessionStatus = 'running' | 'completed' | 'failed' | 'cancelled';
|
|
10
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
11
|
+
type OnHourlyLimit = 'wait' | 'raise';
|
|
12
|
+
type HookType$1 = 'START_RUN' | 'START_ITERATION' | 'END_ITERATION' | 'END_RUN' | 'ON_STALE';
|
|
13
|
+
interface Hook$1 {
|
|
14
|
+
commands: string[];
|
|
15
|
+
}
|
|
16
|
+
type Hooks = Record<HookType$1, Hook$1>;
|
|
17
|
+
type ProgressEventType$1 = 'tool_start' | 'tool_result' | 'thinking' | 'error' | 'info';
|
|
18
|
+
interface JunoTaskConfig {
|
|
19
|
+
defaultSubagent: SubagentType;
|
|
20
|
+
defaultMaxIterations: number;
|
|
21
|
+
defaultModel?: string;
|
|
22
|
+
defaultBackend: BackendType;
|
|
23
|
+
mainTask?: string;
|
|
24
|
+
logLevel: LogLevel;
|
|
25
|
+
logFile?: string;
|
|
26
|
+
verbose: boolean;
|
|
27
|
+
quiet: boolean;
|
|
28
|
+
mcpTimeout: number;
|
|
29
|
+
mcpRetries: number;
|
|
30
|
+
mcpServerPath?: string;
|
|
31
|
+
mcpServerName?: string;
|
|
32
|
+
hookCommandTimeout?: number;
|
|
33
|
+
onHourlyLimit: OnHourlyLimit;
|
|
34
|
+
interactive: boolean;
|
|
35
|
+
headlessMode: boolean;
|
|
36
|
+
workingDirectory: string;
|
|
37
|
+
sessionDirectory: string;
|
|
38
|
+
hooks?: Hooks;
|
|
39
|
+
skipHooks?: boolean;
|
|
40
|
+
}
|
|
41
|
+
declare global {
|
|
42
|
+
const __VERSION__: string;
|
|
43
|
+
const __DEV__: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Core configuration module for juno-code
|
|
48
|
+
*
|
|
49
|
+
* Provides comprehensive configuration management with multi-source loading,
|
|
50
|
+
* validation, and environment variable support.
|
|
51
|
+
*
|
|
52
|
+
* @module core/config
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Environment variable mapping for configuration options
|
|
57
|
+
* All config options can be set via JUNO_CODE_* environment variables
|
|
58
|
+
* Uses JUNO_CODE_* environment variables
|
|
59
|
+
*/
|
|
60
|
+
declare const ENV_VAR_MAPPING: {
|
|
61
|
+
readonly JUNO_CODE_DEFAULT_SUBAGENT: "defaultSubagent";
|
|
62
|
+
readonly JUNO_CODE_DEFAULT_BACKEND: "defaultBackend";
|
|
63
|
+
readonly JUNO_CODE_DEFAULT_MAX_ITERATIONS: "defaultMaxIterations";
|
|
64
|
+
readonly JUNO_CODE_DEFAULT_MODEL: "defaultModel";
|
|
65
|
+
readonly JUNO_CODE_LOG_LEVEL: "logLevel";
|
|
66
|
+
readonly JUNO_CODE_LOG_FILE: "logFile";
|
|
67
|
+
readonly JUNO_CODE_VERBOSE: "verbose";
|
|
68
|
+
readonly JUNO_CODE_QUIET: "quiet";
|
|
69
|
+
readonly JUNO_CODE_MCP_TIMEOUT: "mcpTimeout";
|
|
70
|
+
readonly JUNO_CODE_MCP_RETRIES: "mcpRetries";
|
|
71
|
+
readonly JUNO_CODE_MCP_SERVER_PATH: "mcpServerPath";
|
|
72
|
+
readonly JUNO_CODE_MCP_SERVER_NAME: "mcpServerName";
|
|
73
|
+
readonly JUNO_CODE_HOOK_COMMAND_TIMEOUT: "hookCommandTimeout";
|
|
74
|
+
readonly JUNO_CODE_ON_HOURLY_LIMIT: "onHourlyLimit";
|
|
75
|
+
readonly JUNO_CODE_INTERACTIVE: "interactive";
|
|
76
|
+
readonly JUNO_CODE_HEADLESS_MODE: "headlessMode";
|
|
77
|
+
readonly JUNO_CODE_WORKING_DIRECTORY: "workingDirectory";
|
|
78
|
+
readonly JUNO_CODE_SESSION_DIRECTORY: "sessionDirectory";
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Zod schema for validating JunoTaskConfig
|
|
82
|
+
* Provides runtime validation with detailed error messages
|
|
83
|
+
*/
|
|
84
|
+
declare const JunoTaskConfigSchema: z.ZodObject<{
|
|
85
|
+
defaultSubagent: z.ZodEnum<["claude", "cursor", "codex", "gemini", "pi"]>;
|
|
86
|
+
defaultBackend: z.ZodEnum<["shell"]>;
|
|
87
|
+
defaultMaxIterations: z.ZodNumber;
|
|
88
|
+
defaultModel: z.ZodOptional<z.ZodString>;
|
|
89
|
+
mainTask: z.ZodOptional<z.ZodString>;
|
|
90
|
+
logLevel: z.ZodEnum<["error", "warn", "info", "debug", "trace"]>;
|
|
91
|
+
logFile: z.ZodOptional<z.ZodString>;
|
|
92
|
+
verbose: z.ZodBoolean;
|
|
93
|
+
quiet: z.ZodBoolean;
|
|
94
|
+
mcpTimeout: z.ZodNumber;
|
|
95
|
+
mcpRetries: z.ZodNumber;
|
|
96
|
+
mcpServerPath: z.ZodOptional<z.ZodString>;
|
|
97
|
+
mcpServerName: z.ZodOptional<z.ZodString>;
|
|
98
|
+
hookCommandTimeout: z.ZodOptional<z.ZodNumber>;
|
|
99
|
+
onHourlyLimit: z.ZodEnum<["wait", "raise"]>;
|
|
100
|
+
interactive: z.ZodBoolean;
|
|
101
|
+
headlessMode: z.ZodBoolean;
|
|
102
|
+
workingDirectory: z.ZodString;
|
|
103
|
+
sessionDirectory: z.ZodString;
|
|
104
|
+
hooks: z.ZodOptional<z.ZodRecord<z.ZodEnum<["START_RUN", "START_ITERATION", "END_ITERATION", "END_RUN", "ON_STALE"]>, z.ZodObject<{
|
|
105
|
+
commands: z.ZodArray<z.ZodString, "many">;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
commands?: string[];
|
|
108
|
+
}, {
|
|
109
|
+
commands?: string[];
|
|
110
|
+
}>>>;
|
|
111
|
+
skipHooks: z.ZodOptional<z.ZodBoolean>;
|
|
112
|
+
}, "strict", z.ZodTypeAny, {
|
|
113
|
+
defaultSubagent?: "claude" | "cursor" | "codex" | "gemini" | "pi";
|
|
114
|
+
defaultBackend?: "shell";
|
|
115
|
+
defaultMaxIterations?: number;
|
|
116
|
+
defaultModel?: string;
|
|
117
|
+
logLevel?: "error" | "warn" | "info" | "debug" | "trace";
|
|
118
|
+
logFile?: string;
|
|
119
|
+
verbose?: boolean;
|
|
120
|
+
quiet?: boolean;
|
|
121
|
+
mcpTimeout?: number;
|
|
122
|
+
mcpRetries?: number;
|
|
123
|
+
mcpServerPath?: string;
|
|
124
|
+
mcpServerName?: string;
|
|
125
|
+
hookCommandTimeout?: number;
|
|
126
|
+
onHourlyLimit?: "wait" | "raise";
|
|
127
|
+
interactive?: boolean;
|
|
128
|
+
headlessMode?: boolean;
|
|
129
|
+
workingDirectory?: string;
|
|
130
|
+
sessionDirectory?: string;
|
|
131
|
+
mainTask?: string;
|
|
132
|
+
hooks?: Partial<Record<"START_RUN" | "START_ITERATION" | "END_ITERATION" | "END_RUN" | "ON_STALE", {
|
|
133
|
+
commands?: string[];
|
|
134
|
+
}>>;
|
|
135
|
+
skipHooks?: boolean;
|
|
136
|
+
}, {
|
|
137
|
+
defaultSubagent?: "claude" | "cursor" | "codex" | "gemini" | "pi";
|
|
138
|
+
defaultBackend?: "shell";
|
|
139
|
+
defaultMaxIterations?: number;
|
|
140
|
+
defaultModel?: string;
|
|
141
|
+
logLevel?: "error" | "warn" | "info" | "debug" | "trace";
|
|
142
|
+
logFile?: string;
|
|
143
|
+
verbose?: boolean;
|
|
144
|
+
quiet?: boolean;
|
|
145
|
+
mcpTimeout?: number;
|
|
146
|
+
mcpRetries?: number;
|
|
147
|
+
mcpServerPath?: string;
|
|
148
|
+
mcpServerName?: string;
|
|
149
|
+
hookCommandTimeout?: number;
|
|
150
|
+
onHourlyLimit?: "wait" | "raise";
|
|
151
|
+
interactive?: boolean;
|
|
152
|
+
headlessMode?: boolean;
|
|
153
|
+
workingDirectory?: string;
|
|
154
|
+
sessionDirectory?: string;
|
|
155
|
+
mainTask?: string;
|
|
156
|
+
hooks?: Partial<Record<"START_RUN" | "START_ITERATION" | "END_ITERATION" | "END_RUN" | "ON_STALE", {
|
|
157
|
+
commands?: string[];
|
|
158
|
+
}>>;
|
|
159
|
+
skipHooks?: boolean;
|
|
160
|
+
}>;
|
|
161
|
+
/**
|
|
162
|
+
* Default configuration values
|
|
163
|
+
* These are used as fallbacks when no other configuration is provided
|
|
164
|
+
*/
|
|
165
|
+
declare const DEFAULT_CONFIG: JunoTaskConfig;
|
|
166
|
+
/**
|
|
167
|
+
* ConfigLoader class for multi-source configuration loading
|
|
168
|
+
*
|
|
169
|
+
* Implements configuration precedence: CLI args > Environment Variables > Project Config > Global Config Files > Profile > Defaults
|
|
170
|
+
*/
|
|
171
|
+
declare class ConfigLoader {
|
|
172
|
+
private baseDir;
|
|
173
|
+
private configSources;
|
|
174
|
+
/**
|
|
175
|
+
* Create a new ConfigLoader instance
|
|
176
|
+
*
|
|
177
|
+
* @param baseDir - Base directory for relative path resolution
|
|
178
|
+
*/
|
|
179
|
+
constructor(baseDir?: string);
|
|
180
|
+
/**
|
|
181
|
+
* Load configuration from environment variables
|
|
182
|
+
*
|
|
183
|
+
* @returns This ConfigLoader instance for method chaining
|
|
184
|
+
*/
|
|
185
|
+
fromEnvironment(): this;
|
|
186
|
+
/**
|
|
187
|
+
* Load configuration from a specific file
|
|
188
|
+
*
|
|
189
|
+
* @param filePath - Path to configuration file
|
|
190
|
+
* @returns This ConfigLoader instance for method chaining
|
|
191
|
+
*/
|
|
192
|
+
fromFile(filePath: string): Promise<this>;
|
|
193
|
+
/**
|
|
194
|
+
* Load configuration from project-specific config file
|
|
195
|
+
* Loads from .juno_task/config.json with highest precedence for project settings
|
|
196
|
+
*
|
|
197
|
+
* @returns This ConfigLoader instance for method chaining
|
|
198
|
+
*/
|
|
199
|
+
fromProjectConfig(): Promise<this>;
|
|
200
|
+
/**
|
|
201
|
+
* Automatically discover and load configuration files
|
|
202
|
+
* Searches for both project-specific and global config files in the base directory
|
|
203
|
+
* Project-specific config (.juno_task/config.json) takes precedence over global configs
|
|
204
|
+
*
|
|
205
|
+
* @returns This ConfigLoader instance for method chaining
|
|
206
|
+
*/
|
|
207
|
+
autoDiscoverFile(): Promise<this>;
|
|
208
|
+
/**
|
|
209
|
+
* Load configuration from CLI arguments
|
|
210
|
+
*
|
|
211
|
+
* @param cliConfig - Configuration object from CLI argument parsing
|
|
212
|
+
* @returns This ConfigLoader instance for method chaining
|
|
213
|
+
*/
|
|
214
|
+
fromCli(cliConfig: Partial<JunoTaskConfig>): this;
|
|
215
|
+
/**
|
|
216
|
+
* Merge all configuration sources according to precedence
|
|
217
|
+
* CLI args > Environment Variables > Project Config > Global Config Files > Defaults
|
|
218
|
+
*
|
|
219
|
+
* @returns Merged configuration object
|
|
220
|
+
*/
|
|
221
|
+
merge(): JunoTaskConfig;
|
|
222
|
+
/**
|
|
223
|
+
* Load and merge configuration from all sources
|
|
224
|
+
* Convenience method that performs auto-discovery and returns validated config
|
|
225
|
+
*
|
|
226
|
+
* @param cliConfig - Optional CLI configuration
|
|
227
|
+
* @returns Promise resolving to validated configuration
|
|
228
|
+
*/
|
|
229
|
+
loadAll(cliConfig?: Partial<JunoTaskConfig>): Promise<JunoTaskConfig>;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Validate configuration object against schema
|
|
233
|
+
*
|
|
234
|
+
* @param config - Configuration object to validate
|
|
235
|
+
* @returns Validated configuration object
|
|
236
|
+
* @throws Error if validation fails
|
|
237
|
+
*/
|
|
238
|
+
declare function validateConfig(config: unknown): JunoTaskConfig;
|
|
239
|
+
/**
|
|
240
|
+
* Load and validate configuration from all sources
|
|
241
|
+
*
|
|
242
|
+
* This is the main entry point for configuration loading.
|
|
243
|
+
* It performs auto-discovery, merging, and validation.
|
|
244
|
+
*
|
|
245
|
+
* @param options - Configuration loading options
|
|
246
|
+
* @param options.baseDir - Base directory for relative path resolution
|
|
247
|
+
* @param options.configFile - Specific configuration file to load
|
|
248
|
+
* @param options.cliConfig - CLI configuration override
|
|
249
|
+
* @returns Promise resolving to validated configuration
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* // Load with auto-discovery
|
|
254
|
+
* const config = await loadConfig();
|
|
255
|
+
*
|
|
256
|
+
* // Load with specific file
|
|
257
|
+
* const config = await loadConfig({
|
|
258
|
+
* configFile: './my-config.json'
|
|
259
|
+
* });
|
|
260
|
+
*
|
|
261
|
+
* // Load with CLI overrides
|
|
262
|
+
* const config = await loadConfig({
|
|
263
|
+
* cliConfig: { verbose: true, logLevel: 'debug' }
|
|
264
|
+
* });
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare function loadConfig(options?: {
|
|
268
|
+
baseDir?: string;
|
|
269
|
+
configFile?: string;
|
|
270
|
+
cliConfig?: Partial<JunoTaskConfig>;
|
|
271
|
+
}): Promise<JunoTaskConfig>;
|
|
272
|
+
/**
|
|
273
|
+
* Type export for configuration loading options
|
|
274
|
+
*/
|
|
275
|
+
type ConfigLoadOptions = Parameters<typeof loadConfig>[0];
|
|
276
|
+
/**
|
|
277
|
+
* Type export for environment variable mapping
|
|
278
|
+
*/
|
|
279
|
+
type EnvVarMapping = typeof ENV_VAR_MAPPING;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Default hooks template configuration
|
|
283
|
+
*
|
|
284
|
+
* This module provides default hook commands that are shipped with juno-code.
|
|
285
|
+
* These hooks are automatically configured during project initialization (init command).
|
|
286
|
+
*
|
|
287
|
+
* Hook Types:
|
|
288
|
+
* - START_RUN: Executes at the beginning of a run (before all iterations)
|
|
289
|
+
* - START_ITERATION: Executes at the start of each iteration
|
|
290
|
+
* - END_ITERATION: Executes at the end of each iteration
|
|
291
|
+
* - END_RUN: Executes at the end of a run (after all iterations)
|
|
292
|
+
*
|
|
293
|
+
* To modify default hooks:
|
|
294
|
+
* 1. Update the commands in this file
|
|
295
|
+
* 2. Rebuild the project (npm run build)
|
|
296
|
+
* 3. New installations will use the updated defaults
|
|
297
|
+
*
|
|
298
|
+
* @module templates/default-hooks
|
|
299
|
+
*/
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Default hooks configuration template
|
|
303
|
+
*
|
|
304
|
+
* All hook types are included so users can see available hooks without reading documentation.
|
|
305
|
+
* Empty command arrays indicate hooks that are available but not configured by default.
|
|
306
|
+
*
|
|
307
|
+
* These hooks provide useful default behaviors:
|
|
308
|
+
* - File size monitoring for CLAUDE.md, AGENTS.md, .juno_task/plan.md, .juno_task/tasks.md
|
|
309
|
+
* - Alerts via juno-kanban when documentation/task files become too large
|
|
310
|
+
*
|
|
311
|
+
* Users can customize these hooks by editing .juno_task/config.json after initialization
|
|
312
|
+
*/
|
|
313
|
+
declare const DEFAULT_HOOKS: Hooks;
|
|
314
|
+
/**
|
|
315
|
+
* Get default hooks configuration
|
|
316
|
+
*
|
|
317
|
+
* Returns a copy of the default hooks to prevent mutation of the template.
|
|
318
|
+
* This function can be used during initialization to populate the config.json file.
|
|
319
|
+
*
|
|
320
|
+
* @returns A copy of the default hooks configuration
|
|
321
|
+
*/
|
|
322
|
+
declare function getDefaultHooks(): Hooks;
|
|
323
|
+
/**
|
|
324
|
+
* Get default hooks as formatted JSON string for config.json
|
|
325
|
+
*
|
|
326
|
+
* @param indent - Number of spaces for indentation (default: 2)
|
|
327
|
+
* @returns Formatted JSON string of default hooks
|
|
328
|
+
*/
|
|
329
|
+
declare function getDefaultHooksJson(indent?: number): string;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Execution error definitions for juno-task-ts
|
|
333
|
+
*
|
|
334
|
+
* Provides comprehensive error classes and utilities for execution operations,
|
|
335
|
+
* including error codes, context tracking, recovery suggestions, and
|
|
336
|
+
* specialized error types for different failure scenarios.
|
|
337
|
+
*
|
|
338
|
+
* Originally migrated from the MCP error module. The MCP system has been
|
|
339
|
+
* removed; these are now the canonical execution error definitions.
|
|
340
|
+
* Deprecated MCP-prefixed aliases are retained below for backward compatibility.
|
|
341
|
+
*
|
|
342
|
+
* @module core/errors
|
|
343
|
+
* @version 2.0.0
|
|
344
|
+
*/
|
|
345
|
+
/**
|
|
346
|
+
* Execution error categories for targeted error handling
|
|
347
|
+
*/
|
|
348
|
+
declare enum ExecutionErrorType {
|
|
349
|
+
CONNECTION = "connection",
|
|
350
|
+
TIMEOUT = "timeout",
|
|
351
|
+
RATE_LIMIT = "rate_limit",
|
|
352
|
+
TOOL_EXECUTION = "tool_execution",
|
|
353
|
+
VALIDATION = "validation",
|
|
354
|
+
SERVER_NOT_FOUND = "server_not_found",
|
|
355
|
+
PROTOCOL = "protocol",
|
|
356
|
+
AUTHENTICATION = "authentication"
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Error codes for specific error conditions
|
|
360
|
+
*/
|
|
361
|
+
declare enum ExecutionErrorCode {
|
|
362
|
+
CONNECTION_FAILED = "MCP_CONNECTION_FAILED",
|
|
363
|
+
CONNECTION_TIMEOUT = "MCP_CONNECTION_TIMEOUT",
|
|
364
|
+
CONNECTION_REFUSED = "MCP_CONNECTION_REFUSED",
|
|
365
|
+
CONNECTION_LOST = "MCP_CONNECTION_LOST",
|
|
366
|
+
RECONNECTION_FAILED = "MCP_RECONNECTION_FAILED",
|
|
367
|
+
TOOL_NOT_FOUND = "MCP_TOOL_NOT_FOUND",
|
|
368
|
+
TOOL_EXECUTION_FAILED = "MCP_TOOL_EXECUTION_FAILED",
|
|
369
|
+
TOOL_TIMEOUT = "MCP_TOOL_TIMEOUT",
|
|
370
|
+
TOOL_INVALID_ARGUMENTS = "MCP_TOOL_INVALID_ARGUMENTS",
|
|
371
|
+
RATE_LIMIT_EXCEEDED = "MCP_RATE_LIMIT_EXCEEDED",
|
|
372
|
+
RATE_LIMIT_HOURLY = "MCP_RATE_LIMIT_HOURLY",
|
|
373
|
+
RATE_LIMIT_DAILY = "MCP_RATE_LIMIT_DAILY",
|
|
374
|
+
VALIDATION_FAILED = "MCP_VALIDATION_FAILED",
|
|
375
|
+
INVALID_REQUEST = "MCP_INVALID_REQUEST",
|
|
376
|
+
MISSING_PARAMETERS = "MCP_MISSING_PARAMETERS",
|
|
377
|
+
INVALID_PARAMETERS = "MCP_INVALID_PARAMETERS",
|
|
378
|
+
SERVER_NOT_FOUND = "MCP_SERVER_NOT_FOUND",
|
|
379
|
+
SERVER_NOT_EXECUTABLE = "MCP_SERVER_NOT_EXECUTABLE",
|
|
380
|
+
SERVER_STARTUP_FAILED = "MCP_SERVER_STARTUP_FAILED",
|
|
381
|
+
SERVER_CRASHED = "MCP_SERVER_CRASHED",
|
|
382
|
+
PROTOCOL_ERROR = "MCP_PROTOCOL_ERROR",
|
|
383
|
+
INVALID_RESPONSE = "MCP_INVALID_RESPONSE",
|
|
384
|
+
VERSION_MISMATCH = "MCP_VERSION_MISMATCH",
|
|
385
|
+
AUTHENTICATION_FAILED = "MCP_AUTHENTICATION_FAILED",
|
|
386
|
+
UNAUTHORIZED = "MCP_UNAUTHORIZED",
|
|
387
|
+
TOKEN_EXPIRED = "MCP_TOKEN_EXPIRED"
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Base error options for execution errors
|
|
391
|
+
*/
|
|
392
|
+
interface ExecutionErrorOptions {
|
|
393
|
+
/** Error code for programmatic handling */
|
|
394
|
+
readonly code?: ExecutionErrorCode | undefined;
|
|
395
|
+
/** Operation context when error occurred */
|
|
396
|
+
readonly context?: string | undefined;
|
|
397
|
+
/** Retry information */
|
|
398
|
+
readonly retryInfo?: RetryInfo | undefined;
|
|
399
|
+
/** Recovery suggestions for the user */
|
|
400
|
+
readonly recoverySuggestions?: readonly string[] | undefined;
|
|
401
|
+
/** Cause error for error chaining */
|
|
402
|
+
readonly cause?: Error | undefined;
|
|
403
|
+
/** Additional metadata */
|
|
404
|
+
readonly metadata?: Readonly<Record<string, unknown>> | undefined;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Retry information for error context
|
|
408
|
+
*/
|
|
409
|
+
interface RetryInfo {
|
|
410
|
+
/** Current attempt number */
|
|
411
|
+
readonly attempt: number;
|
|
412
|
+
/** Maximum attempts allowed */
|
|
413
|
+
readonly maxAttempts: number;
|
|
414
|
+
/** Next retry time */
|
|
415
|
+
readonly nextRetryTime?: Date;
|
|
416
|
+
/** Retry strategy used */
|
|
417
|
+
readonly strategy: string;
|
|
418
|
+
/** Backoff delay in milliseconds */
|
|
419
|
+
readonly backoffDelay?: number;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Base execution error class with enhanced context and recovery information
|
|
423
|
+
*/
|
|
424
|
+
declare abstract class ExecutionError extends Error {
|
|
425
|
+
/** Error type classification */
|
|
426
|
+
readonly type: ExecutionErrorType;
|
|
427
|
+
/** Error code for programmatic handling */
|
|
428
|
+
readonly code: ExecutionErrorCode;
|
|
429
|
+
/** Error timestamp */
|
|
430
|
+
readonly timestamp: Date;
|
|
431
|
+
/** Operation context */
|
|
432
|
+
readonly context?: string | undefined;
|
|
433
|
+
/** Retry information */
|
|
434
|
+
readonly retryInfo?: RetryInfo | undefined;
|
|
435
|
+
/** Recovery suggestions */
|
|
436
|
+
readonly recoverySuggestions?: readonly string[] | undefined;
|
|
437
|
+
/** Additional metadata */
|
|
438
|
+
readonly metadata?: Readonly<Record<string, unknown>> | undefined;
|
|
439
|
+
/** Cause error for error chaining */
|
|
440
|
+
readonly cause?: Error | undefined;
|
|
441
|
+
constructor(message: string, type: ExecutionErrorType, code: ExecutionErrorCode, options?: ExecutionErrorOptions);
|
|
442
|
+
/**
|
|
443
|
+
* Get user-friendly error message
|
|
444
|
+
*/
|
|
445
|
+
getUserMessage(): string;
|
|
446
|
+
/**
|
|
447
|
+
* Get technical error details
|
|
448
|
+
*/
|
|
449
|
+
getTechnicalDetails(): string;
|
|
450
|
+
/**
|
|
451
|
+
* Check if error is retryable
|
|
452
|
+
*/
|
|
453
|
+
isRetryable(): boolean;
|
|
454
|
+
/**
|
|
455
|
+
* Get time until next retry
|
|
456
|
+
*/
|
|
457
|
+
getRetryDelay(): number;
|
|
458
|
+
/**
|
|
459
|
+
* Serialize error to JSON
|
|
460
|
+
*/
|
|
461
|
+
toJSON(): Record<string, unknown>;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Progress event types from Roundtable server format
|
|
466
|
+
*/
|
|
467
|
+
declare enum ProgressEventType {
|
|
468
|
+
TOOL_START = "tool_start",
|
|
469
|
+
TOOL_RESULT = "tool_result",
|
|
470
|
+
THINKING = "thinking",
|
|
471
|
+
ERROR = "error",
|
|
472
|
+
INFO = "info",
|
|
473
|
+
DEBUG = "debug"
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Tool execution status for tracking
|
|
477
|
+
*/
|
|
478
|
+
declare enum ToolExecutionStatus {
|
|
479
|
+
PENDING = "pending",
|
|
480
|
+
RUNNING = "running",
|
|
481
|
+
COMPLETED = "completed",
|
|
482
|
+
FAILED = "failed",
|
|
483
|
+
CANCELLED = "cancelled",
|
|
484
|
+
TIMEOUT = "timeout"
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Progress event interface matching Roundtable server format
|
|
488
|
+
* Format: "Backend #count: event_type => content"
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```typescript
|
|
492
|
+
* const progressEvent: ProgressEvent = {
|
|
493
|
+
* sessionId: 'session-123',
|
|
494
|
+
* timestamp: new Date(),
|
|
495
|
+
* backend: 'claude',
|
|
496
|
+
* count: 1,
|
|
497
|
+
* type: ProgressEventType.TOOL_START,
|
|
498
|
+
* content: 'Starting code analysis...',
|
|
499
|
+
* toolId: 'claude_1',
|
|
500
|
+
* metadata: {
|
|
501
|
+
* duration: 150,
|
|
502
|
+
* tokens: 1024
|
|
503
|
+
* }
|
|
504
|
+
* };
|
|
505
|
+
* ```
|
|
506
|
+
*/
|
|
507
|
+
interface ProgressEvent {
|
|
508
|
+
/** Unique session identifier for correlation */
|
|
509
|
+
readonly sessionId: string;
|
|
510
|
+
/** Event timestamp */
|
|
511
|
+
readonly timestamp: Date;
|
|
512
|
+
/** Subagent backend name (claude, cursor, codex, gemini) */
|
|
513
|
+
readonly backend: string;
|
|
514
|
+
/** Sequential event number within session */
|
|
515
|
+
readonly count: number;
|
|
516
|
+
/** Progress event classification */
|
|
517
|
+
readonly type: ProgressEventType;
|
|
518
|
+
/** Event content/message from subagent */
|
|
519
|
+
readonly content: string;
|
|
520
|
+
/** Generated tool correlation ID for tracking */
|
|
521
|
+
readonly toolId: string;
|
|
522
|
+
/** Additional event metadata */
|
|
523
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
524
|
+
/** Parent event ID for nested operations */
|
|
525
|
+
readonly parentId?: string;
|
|
526
|
+
/** Event priority level */
|
|
527
|
+
readonly priority?: 'low' | 'normal' | 'high';
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Progress callback function signature
|
|
531
|
+
* Callbacks must never throw errors to avoid breaking execution flow
|
|
532
|
+
*
|
|
533
|
+
* @param event - The progress event to handle
|
|
534
|
+
* @returns Promise<void> - Should handle errors internally
|
|
535
|
+
*/
|
|
536
|
+
type ProgressCallback = (event: ProgressEvent) => Promise<void> | void;
|
|
537
|
+
/**
|
|
538
|
+
* Tool call request structure
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* ```typescript
|
|
542
|
+
* const request: ToolCallRequest = {
|
|
543
|
+
* toolName: 'claude_subagent',
|
|
544
|
+
* arguments: {
|
|
545
|
+
* instruction: 'Analyze this code',
|
|
546
|
+
* project_path: '/path/to/project',
|
|
547
|
+
* model: 'sonnet-4'
|
|
548
|
+
* },
|
|
549
|
+
* timeout: 30000,
|
|
550
|
+
* priority: 'high',
|
|
551
|
+
* metadata: {
|
|
552
|
+
* userId: 'user-123',
|
|
553
|
+
* sessionId: 'session-456'
|
|
554
|
+
* }
|
|
555
|
+
* };
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
interface ToolCallRequest {
|
|
559
|
+
/** Tool name (mapped from subagent name) */
|
|
560
|
+
readonly toolName: string;
|
|
561
|
+
/** Tool arguments object */
|
|
562
|
+
readonly arguments: Readonly<Record<string, unknown>>;
|
|
563
|
+
/** Request timeout in milliseconds */
|
|
564
|
+
readonly timeout?: number;
|
|
565
|
+
/** Request priority level */
|
|
566
|
+
readonly priority?: 'low' | 'normal' | 'high';
|
|
567
|
+
/** Additional request metadata */
|
|
568
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
569
|
+
/** Callback for progress events */
|
|
570
|
+
readonly progressCallback?: ProgressCallback;
|
|
571
|
+
/** Unique request identifier */
|
|
572
|
+
readonly requestId?: string;
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Tool call result structure
|
|
576
|
+
*/
|
|
577
|
+
interface ToolCallResult {
|
|
578
|
+
/** Tool execution result content */
|
|
579
|
+
readonly content: string;
|
|
580
|
+
/** Execution status */
|
|
581
|
+
readonly status: ToolExecutionStatus;
|
|
582
|
+
/** Execution start time */
|
|
583
|
+
readonly startTime: Date;
|
|
584
|
+
/** Execution end time */
|
|
585
|
+
readonly endTime: Date;
|
|
586
|
+
/** Total execution duration in milliseconds */
|
|
587
|
+
readonly duration: number;
|
|
588
|
+
/** Any error that occurred during execution */
|
|
589
|
+
readonly error?: Error;
|
|
590
|
+
/** Progress events generated during execution */
|
|
591
|
+
readonly progressEvents: readonly ProgressEvent[];
|
|
592
|
+
/** Tool execution metadata */
|
|
593
|
+
readonly metadata?: ToolExecutionMetadata;
|
|
594
|
+
/** Request that generated this result */
|
|
595
|
+
readonly request: ToolCallRequest;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Tool execution metadata
|
|
599
|
+
*/
|
|
600
|
+
interface ToolExecutionMetadata {
|
|
601
|
+
/** Number of tokens used */
|
|
602
|
+
readonly tokensUsed?: number;
|
|
603
|
+
/** Estimated cost */
|
|
604
|
+
readonly estimatedCost?: number;
|
|
605
|
+
/** Model used for execution */
|
|
606
|
+
readonly model?: string;
|
|
607
|
+
/** Server version */
|
|
608
|
+
readonly serverVersion?: string;
|
|
609
|
+
/** Performance metrics */
|
|
610
|
+
readonly performanceMetrics?: ToolPerformanceMetrics;
|
|
611
|
+
/** Raw subagent response payload (for programmatic capture / session resume) */
|
|
612
|
+
readonly subAgentResponse?: any;
|
|
613
|
+
/** Indicates the content string is structured (e.g., JSON) and safe to parse */
|
|
614
|
+
readonly structuredOutput?: boolean;
|
|
615
|
+
/** Content type for the tool output (e.g., application/json) */
|
|
616
|
+
readonly contentType?: string;
|
|
617
|
+
/** Original raw output emitted by the tool (pre-structuring) */
|
|
618
|
+
readonly rawOutput?: string;
|
|
619
|
+
/** Quota limit information detected during execution */
|
|
620
|
+
readonly quotaLimitInfo?: any;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Tool performance metrics
|
|
624
|
+
*/
|
|
625
|
+
interface ToolPerformanceMetrics {
|
|
626
|
+
/** CPU usage during execution */
|
|
627
|
+
readonly cpuUsage: number;
|
|
628
|
+
/** Memory usage during execution */
|
|
629
|
+
readonly memoryUsage: number;
|
|
630
|
+
/** Network usage in bytes */
|
|
631
|
+
readonly networkUsage: number;
|
|
632
|
+
/** Processing time breakdown */
|
|
633
|
+
readonly timingBreakdown: Record<string, number>;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Session context (renamed from MCPSessionContext)
|
|
637
|
+
*/
|
|
638
|
+
interface SessionContext {
|
|
639
|
+
/** Unique session identifier */
|
|
640
|
+
readonly sessionId: string;
|
|
641
|
+
/** Session start time */
|
|
642
|
+
readonly startTime: Date;
|
|
643
|
+
/** User identifier */
|
|
644
|
+
readonly userId?: string;
|
|
645
|
+
/** Session metadata */
|
|
646
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
647
|
+
/** Active tool calls */
|
|
648
|
+
readonly activeToolCalls: readonly string[];
|
|
649
|
+
/** Session state */
|
|
650
|
+
readonly state: SessionState;
|
|
651
|
+
/** Last activity time */
|
|
652
|
+
readonly lastActivity: Date;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Session state
|
|
656
|
+
*/
|
|
657
|
+
declare enum SessionState {
|
|
658
|
+
INITIALIZING = "initializing",
|
|
659
|
+
ACTIVE = "active",
|
|
660
|
+
IDLE = "idle",
|
|
661
|
+
SUSPENDED = "suspended",
|
|
662
|
+
COMPLETED = "completed",
|
|
663
|
+
FAILED = "failed"
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* Core execution engine module for juno-task-ts
|
|
668
|
+
*
|
|
669
|
+
* This module provides the main execution orchestration engine that manages
|
|
670
|
+
* the entire workflow for AI task execution, including session management,
|
|
671
|
+
* backend integration, progress tracking, error handling, and cancellation.
|
|
672
|
+
*
|
|
673
|
+
* The implementation closely matches the Python budi-cli execution patterns,
|
|
674
|
+
* including rate limit handling, iteration logic, and progress tracking.
|
|
675
|
+
*
|
|
676
|
+
* @module core/engine
|
|
677
|
+
* @since 1.0.0
|
|
678
|
+
*/
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Execution request interface for starting task execution
|
|
682
|
+
*/
|
|
683
|
+
interface ExecutionRequest {
|
|
684
|
+
/** Unique request identifier */
|
|
685
|
+
readonly requestId: string;
|
|
686
|
+
/** Task instruction or prompt text */
|
|
687
|
+
readonly instruction: string;
|
|
688
|
+
/** Subagent to use for execution */
|
|
689
|
+
readonly subagent: SubagentType;
|
|
690
|
+
/** Backend to use for execution */
|
|
691
|
+
readonly backend: BackendType;
|
|
692
|
+
/** Working directory for execution */
|
|
693
|
+
readonly workingDirectory: string;
|
|
694
|
+
/** Maximum number of iterations (-1 for unlimited) */
|
|
695
|
+
readonly maxIterations: number;
|
|
696
|
+
/** Optional specific model to use */
|
|
697
|
+
readonly model?: string;
|
|
698
|
+
/** Optional timeout in milliseconds (overrides config) */
|
|
699
|
+
readonly timeoutMs?: number;
|
|
700
|
+
/** Session metadata */
|
|
701
|
+
readonly sessionMetadata?: Record<string, unknown>;
|
|
702
|
+
/** Custom progress callbacks */
|
|
703
|
+
readonly progressCallbacks?: ProgressCallback[];
|
|
704
|
+
/** Request priority level */
|
|
705
|
+
readonly priority?: 'low' | 'normal' | 'high';
|
|
706
|
+
/** MCP server name (for MCP backend) */
|
|
707
|
+
readonly mcpServerName?: string;
|
|
708
|
+
/** Available tools from built-in set (only works with --print mode, forwarded to shell backend) */
|
|
709
|
+
readonly tools?: string[];
|
|
710
|
+
/** Permission-based filtering of specific tool instances (forwarded to shell backend) */
|
|
711
|
+
readonly allowedTools?: string[];
|
|
712
|
+
/** Disallowed tools (forwarded to shell backend) */
|
|
713
|
+
readonly disallowedTools?: string[];
|
|
714
|
+
/** Append tools to default allowed-tools list (forwarded to shell backend) */
|
|
715
|
+
readonly appendAllowedTools?: string[];
|
|
716
|
+
/** Agents configuration (forwarded to shell backend) */
|
|
717
|
+
readonly agents?: string;
|
|
718
|
+
/** Resume a conversation by session ID (forwarded to shell backend) */
|
|
719
|
+
readonly resume?: string;
|
|
720
|
+
/** Continue the most recent conversation (forwarded to shell backend) */
|
|
721
|
+
readonly continueConversation?: boolean;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Execution result interface for completed executions
|
|
725
|
+
*/
|
|
726
|
+
interface ExecutionResult {
|
|
727
|
+
/** Request that generated this result */
|
|
728
|
+
readonly request: ExecutionRequest;
|
|
729
|
+
/** Execution status */
|
|
730
|
+
readonly status: ExecutionStatus;
|
|
731
|
+
/** Execution start time */
|
|
732
|
+
readonly startTime: Date;
|
|
733
|
+
/** Execution end time */
|
|
734
|
+
readonly endTime: Date;
|
|
735
|
+
/** Total execution duration in milliseconds */
|
|
736
|
+
readonly duration: number;
|
|
737
|
+
/** All iteration results */
|
|
738
|
+
readonly iterations: readonly IterationResult[];
|
|
739
|
+
/** Final execution statistics */
|
|
740
|
+
readonly statistics: ExecutionStatistics;
|
|
741
|
+
/** Any error that terminated execution */
|
|
742
|
+
readonly error?: ExecutionError;
|
|
743
|
+
/** Session context information */
|
|
744
|
+
readonly sessionContext: SessionContext;
|
|
745
|
+
/** All progress events captured during execution */
|
|
746
|
+
readonly progressEvents: readonly ProgressEvent[];
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Individual iteration result
|
|
750
|
+
*/
|
|
751
|
+
interface IterationResult {
|
|
752
|
+
/** Iteration number (1-based) */
|
|
753
|
+
readonly iterationNumber: number;
|
|
754
|
+
/** Iteration success status */
|
|
755
|
+
readonly success: boolean;
|
|
756
|
+
/** Iteration start time */
|
|
757
|
+
readonly startTime: Date;
|
|
758
|
+
/** Iteration end time */
|
|
759
|
+
readonly endTime: Date;
|
|
760
|
+
/** Iteration duration in milliseconds */
|
|
761
|
+
readonly duration: number;
|
|
762
|
+
/** Tool call result */
|
|
763
|
+
readonly toolResult: ToolCallResult;
|
|
764
|
+
/** Iteration-specific progress events */
|
|
765
|
+
readonly progressEvents: readonly ProgressEvent[];
|
|
766
|
+
/** Any error that occurred during iteration */
|
|
767
|
+
readonly error?: Error;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Execution status enumeration
|
|
771
|
+
*/
|
|
772
|
+
declare enum ExecutionStatus {
|
|
773
|
+
PENDING = "pending",
|
|
774
|
+
RUNNING = "running",
|
|
775
|
+
COMPLETED = "completed",
|
|
776
|
+
FAILED = "failed",
|
|
777
|
+
CANCELLED = "cancelled",
|
|
778
|
+
TIMEOUT = "timeout",
|
|
779
|
+
RATE_LIMITED = "rate_limited"
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Execution statistics for performance tracking
|
|
783
|
+
*/
|
|
784
|
+
interface ExecutionStatistics {
|
|
785
|
+
/** Total iterations attempted */
|
|
786
|
+
totalIterations: number;
|
|
787
|
+
/** Number of successful iterations */
|
|
788
|
+
successfulIterations: number;
|
|
789
|
+
/** Number of failed iterations */
|
|
790
|
+
failedIterations: number;
|
|
791
|
+
/** Average iteration duration in milliseconds */
|
|
792
|
+
averageIterationDuration: number;
|
|
793
|
+
/** Total tool calls made */
|
|
794
|
+
totalToolCalls: number;
|
|
795
|
+
/** Total progress events processed */
|
|
796
|
+
totalProgressEvents: number;
|
|
797
|
+
/** Rate limit encounters */
|
|
798
|
+
rateLimitEncounters: number;
|
|
799
|
+
/** Total rate limit wait time in milliseconds */
|
|
800
|
+
rateLimitWaitTime: number;
|
|
801
|
+
/** Quota limit encounters (Claude-specific) */
|
|
802
|
+
quotaLimitEncounters: number;
|
|
803
|
+
/** Total quota limit wait time in milliseconds */
|
|
804
|
+
quotaLimitWaitTime: number;
|
|
805
|
+
/** Error breakdown by type */
|
|
806
|
+
errorBreakdown: Record<string, number>;
|
|
807
|
+
/** Performance metrics */
|
|
808
|
+
performanceMetrics: PerformanceMetrics;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Performance metrics for detailed analysis
|
|
812
|
+
*/
|
|
813
|
+
interface PerformanceMetrics {
|
|
814
|
+
/** CPU usage percentage during execution */
|
|
815
|
+
cpuUsage: number;
|
|
816
|
+
/** Memory usage in bytes */
|
|
817
|
+
memoryUsage: number;
|
|
818
|
+
/** Network requests made */
|
|
819
|
+
networkRequests: number;
|
|
820
|
+
/** File system operations */
|
|
821
|
+
fileSystemOperations: number;
|
|
822
|
+
/** Throughput metrics */
|
|
823
|
+
throughput: ThroughputMetrics;
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Throughput metrics
|
|
827
|
+
*/
|
|
828
|
+
interface ThroughputMetrics {
|
|
829
|
+
/** Iterations per minute */
|
|
830
|
+
iterationsPerMinute: number;
|
|
831
|
+
/** Progress events per second */
|
|
832
|
+
progressEventsPerSecond: number;
|
|
833
|
+
/** Tool calls per minute */
|
|
834
|
+
toolCallsPerMinute: number;
|
|
835
|
+
}
|
|
836
|
+
/**
|
|
837
|
+
* Rate limit information for handling
|
|
838
|
+
*/
|
|
839
|
+
interface RateLimitInfo {
|
|
840
|
+
/** Whether currently rate limited */
|
|
841
|
+
readonly isRateLimited: boolean;
|
|
842
|
+
/** Rate limit reset time */
|
|
843
|
+
readonly resetTime?: Date;
|
|
844
|
+
/** Remaining requests in current window */
|
|
845
|
+
readonly remaining: number;
|
|
846
|
+
/** Time to wait before next request in milliseconds */
|
|
847
|
+
readonly waitTimeMs: number;
|
|
848
|
+
/** Rate limit tier/category */
|
|
849
|
+
readonly tier?: string;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Error recovery strategy configuration
|
|
853
|
+
*/
|
|
854
|
+
interface ErrorRecoveryConfig {
|
|
855
|
+
/** Maximum recovery attempts per error type */
|
|
856
|
+
readonly maxAttempts: Record<string, number>;
|
|
857
|
+
/** Retry delays by error type in milliseconds */
|
|
858
|
+
readonly retryDelays: Record<string, number>;
|
|
859
|
+
/** Whether to continue on specific error types */
|
|
860
|
+
readonly continueOnError: Record<string, boolean>;
|
|
861
|
+
/** Custom recovery strategies */
|
|
862
|
+
readonly customStrategies: Record<string, (error: ExecutionError) => Promise<boolean>>;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* Execution engine configuration
|
|
866
|
+
*/
|
|
867
|
+
interface ExecutionEngineConfig {
|
|
868
|
+
/** Base configuration */
|
|
869
|
+
readonly config: JunoTaskConfig;
|
|
870
|
+
/** No longer uses BackendManager; engine creates ShellBackend directly */
|
|
871
|
+
/** Error recovery configuration */
|
|
872
|
+
readonly errorRecovery: ErrorRecoveryConfig;
|
|
873
|
+
/** Rate limit handling configuration */
|
|
874
|
+
readonly rateLimitConfig: RateLimitHandlingConfig;
|
|
875
|
+
/** Progress tracking configuration */
|
|
876
|
+
readonly progressConfig: ProgressTrackingConfig;
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Rate limit handling configuration
|
|
880
|
+
*/
|
|
881
|
+
interface RateLimitHandlingConfig {
|
|
882
|
+
/** Enable automatic rate limit handling */
|
|
883
|
+
readonly enabled: boolean;
|
|
884
|
+
/** Maximum wait time for rate limits in milliseconds */
|
|
885
|
+
readonly maxWaitTimeMs: number;
|
|
886
|
+
/** Rate limit detection patterns */
|
|
887
|
+
readonly detectionPatterns: readonly RegExp[];
|
|
888
|
+
/** Custom rate limit parsers */
|
|
889
|
+
readonly customParsers: readonly RateLimitParser[];
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Rate limit parser interface
|
|
893
|
+
*/
|
|
894
|
+
interface RateLimitParser {
|
|
895
|
+
/** Pattern to match rate limit messages */
|
|
896
|
+
readonly pattern: RegExp;
|
|
897
|
+
/** Parse function to extract reset time */
|
|
898
|
+
readonly parse: (message: string) => Date | null;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Progress tracking configuration
|
|
902
|
+
*/
|
|
903
|
+
interface ProgressTrackingConfig {
|
|
904
|
+
/** Enable progress tracking */
|
|
905
|
+
readonly enabled: boolean;
|
|
906
|
+
/** Buffer size for progress events */
|
|
907
|
+
readonly bufferSize: number;
|
|
908
|
+
/** Progress event filters */
|
|
909
|
+
readonly filters: readonly ProgressEventFilter[];
|
|
910
|
+
/** Custom progress processors */
|
|
911
|
+
readonly processors: readonly ProgressEventProcessor[];
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Progress event filter
|
|
915
|
+
*/
|
|
916
|
+
interface ProgressEventFilter {
|
|
917
|
+
/** Filter type */
|
|
918
|
+
readonly type: ProgressEventType$1 | 'custom';
|
|
919
|
+
/** Filter predicate */
|
|
920
|
+
readonly predicate: (event: ProgressEvent) => boolean;
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Progress event processor
|
|
924
|
+
*/
|
|
925
|
+
interface ProgressEventProcessor {
|
|
926
|
+
/** Processor name */
|
|
927
|
+
readonly name: string;
|
|
928
|
+
/** Process function */
|
|
929
|
+
readonly process: (event: ProgressEvent) => Promise<void>;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Default error recovery configuration
|
|
933
|
+
*/
|
|
934
|
+
declare const DEFAULT_ERROR_RECOVERY_CONFIG: ErrorRecoveryConfig;
|
|
935
|
+
/**
|
|
936
|
+
* Default rate limit handling configuration
|
|
937
|
+
*/
|
|
938
|
+
declare const DEFAULT_RATE_LIMIT_CONFIG: RateLimitHandlingConfig;
|
|
939
|
+
/**
|
|
940
|
+
* Default progress tracking configuration
|
|
941
|
+
*/
|
|
942
|
+
declare const DEFAULT_PROGRESS_CONFIG: ProgressTrackingConfig;
|
|
943
|
+
/**
|
|
944
|
+
* Main execution engine class for orchestrating AI task execution
|
|
945
|
+
*
|
|
946
|
+
* This class manages the complete execution lifecycle including:
|
|
947
|
+
* - Session creation and management
|
|
948
|
+
* - Iteration loop with rate limit handling
|
|
949
|
+
* - Progress tracking and statistics collection
|
|
950
|
+
* - Error handling with recovery strategies
|
|
951
|
+
* - Cancellation and cleanup
|
|
952
|
+
*
|
|
953
|
+
* @example
|
|
954
|
+
* ```typescript
|
|
955
|
+
* const engine = createExecutionEngine(await loadConfig());
|
|
956
|
+
*
|
|
957
|
+
* const request: ExecutionRequest = {
|
|
958
|
+
* requestId: 'req-123',
|
|
959
|
+
* instruction: 'Implement a new feature',
|
|
960
|
+
* subagent: 'claude',
|
|
961
|
+
* workingDirectory: '/path/to/project',
|
|
962
|
+
* maxIterations: 10,
|
|
963
|
+
* };
|
|
964
|
+
*
|
|
965
|
+
* const result = await engine.execute(request);
|
|
966
|
+
* ```
|
|
967
|
+
*/
|
|
968
|
+
declare class ExecutionEngine extends EventEmitter {
|
|
969
|
+
private readonly engineConfig;
|
|
970
|
+
private readonly activeExecutions;
|
|
971
|
+
private readonly progressCallbacks;
|
|
972
|
+
private readonly cleanupTasks;
|
|
973
|
+
private isShuttingDown;
|
|
974
|
+
private currentBackend;
|
|
975
|
+
/**
|
|
976
|
+
* Create a new ExecutionEngine instance
|
|
977
|
+
*
|
|
978
|
+
* @param config - Engine configuration
|
|
979
|
+
*/
|
|
980
|
+
constructor(config: ExecutionEngineConfig);
|
|
981
|
+
/**
|
|
982
|
+
* Execute a task request with comprehensive orchestration
|
|
983
|
+
*
|
|
984
|
+
* @param request - Execution request parameters
|
|
985
|
+
* @param abortSignal - Optional abort signal for cancellation
|
|
986
|
+
* @returns Promise resolving to execution result
|
|
987
|
+
*/
|
|
988
|
+
execute(request: ExecutionRequest, abortSignal?: AbortSignal): Promise<ExecutionResult>;
|
|
989
|
+
/**
|
|
990
|
+
* Add a progress callback for all executions
|
|
991
|
+
*
|
|
992
|
+
* @param callback - Progress callback function
|
|
993
|
+
* @returns Cleanup function to remove the callback
|
|
994
|
+
*/
|
|
995
|
+
onProgress(callback: ProgressCallback): () => void;
|
|
996
|
+
/**
|
|
997
|
+
* Get current rate limit information
|
|
998
|
+
*
|
|
999
|
+
* @returns Current rate limit status
|
|
1000
|
+
*/
|
|
1001
|
+
getRateLimitInfo(): Promise<RateLimitInfo>;
|
|
1002
|
+
/**
|
|
1003
|
+
* Cancel all active executions and shutdown gracefully
|
|
1004
|
+
*
|
|
1005
|
+
* @param timeoutMs - Maximum time to wait for cleanup
|
|
1006
|
+
*/
|
|
1007
|
+
shutdown(timeoutMs?: number): Promise<void>;
|
|
1008
|
+
/**
|
|
1009
|
+
* Get statistics for all executions
|
|
1010
|
+
*
|
|
1011
|
+
* @returns Aggregate execution statistics
|
|
1012
|
+
*/
|
|
1013
|
+
getExecutionStatistics(): ExecutionStatistics;
|
|
1014
|
+
/**
|
|
1015
|
+
* Setup error handling for the engine
|
|
1016
|
+
*/
|
|
1017
|
+
private setupErrorHandling;
|
|
1018
|
+
/**
|
|
1019
|
+
* Setup progress tracking for the engine
|
|
1020
|
+
*/
|
|
1021
|
+
private setupProgressTracking;
|
|
1022
|
+
/**
|
|
1023
|
+
* Initialize backend for execution request.
|
|
1024
|
+
* Directly creates and configures a ShellBackend (no factory indirection).
|
|
1025
|
+
*/
|
|
1026
|
+
private initializeBackend;
|
|
1027
|
+
/**
|
|
1028
|
+
* Validate execution request parameters
|
|
1029
|
+
*/
|
|
1030
|
+
private validateRequest;
|
|
1031
|
+
/**
|
|
1032
|
+
* Create execution context for a request
|
|
1033
|
+
*/
|
|
1034
|
+
private createExecutionContext;
|
|
1035
|
+
/**
|
|
1036
|
+
* Create initial statistics object
|
|
1037
|
+
*/
|
|
1038
|
+
private createInitialStatistics;
|
|
1039
|
+
/**
|
|
1040
|
+
* Create session context for execution
|
|
1041
|
+
*/
|
|
1042
|
+
private createSessionContext;
|
|
1043
|
+
/**
|
|
1044
|
+
* Internal execution implementation
|
|
1045
|
+
*/
|
|
1046
|
+
private executeInternal;
|
|
1047
|
+
/**
|
|
1048
|
+
* Run the main iteration loop
|
|
1049
|
+
*/
|
|
1050
|
+
private runIterationLoop;
|
|
1051
|
+
/**
|
|
1052
|
+
* Execute a single iteration
|
|
1053
|
+
* @returns QuotaLimitInfo if a quota limit was detected, null otherwise
|
|
1054
|
+
*/
|
|
1055
|
+
private executeIteration;
|
|
1056
|
+
/**
|
|
1057
|
+
* Handle rate limit errors with automatic retry
|
|
1058
|
+
*/
|
|
1059
|
+
private handleRateLimit;
|
|
1060
|
+
/**
|
|
1061
|
+
* Calculate wait time for rate limit reset
|
|
1062
|
+
*/
|
|
1063
|
+
private calculateRateLimitWaitTime;
|
|
1064
|
+
/**
|
|
1065
|
+
* Handle Claude quota limit with automatic sleep and retry
|
|
1066
|
+
* @returns true if we should retry the iteration, false otherwise
|
|
1067
|
+
*/
|
|
1068
|
+
private handleQuotaLimit;
|
|
1069
|
+
/**
|
|
1070
|
+
* Sleep with periodic progress updates
|
|
1071
|
+
*/
|
|
1072
|
+
private sleepWithProgress;
|
|
1073
|
+
/**
|
|
1074
|
+
* Check if tool result indicates a quota limit error
|
|
1075
|
+
*/
|
|
1076
|
+
private extractQuotaLimitInfo;
|
|
1077
|
+
/**
|
|
1078
|
+
* Handle iteration errors with recovery strategies
|
|
1079
|
+
*/
|
|
1080
|
+
private handleIterationError;
|
|
1081
|
+
/**
|
|
1082
|
+
* Process individual progress events
|
|
1083
|
+
*/
|
|
1084
|
+
private processProgressEvent;
|
|
1085
|
+
/**
|
|
1086
|
+
* Update execution statistics
|
|
1087
|
+
*/
|
|
1088
|
+
private updateStatistics;
|
|
1089
|
+
/**
|
|
1090
|
+
* Update performance metrics
|
|
1091
|
+
*/
|
|
1092
|
+
private updatePerformanceMetrics;
|
|
1093
|
+
/**
|
|
1094
|
+
* Check if iteration loop should stop
|
|
1095
|
+
*/
|
|
1096
|
+
private shouldStopIterating;
|
|
1097
|
+
/**
|
|
1098
|
+
* Check abort signal and throw if aborted
|
|
1099
|
+
*/
|
|
1100
|
+
private checkAbortSignal;
|
|
1101
|
+
/**
|
|
1102
|
+
* Get tool name for subagent
|
|
1103
|
+
*/
|
|
1104
|
+
private getToolNameForSubagent;
|
|
1105
|
+
/**
|
|
1106
|
+
* Wrap unknown errors as execution errors
|
|
1107
|
+
*/
|
|
1108
|
+
private wrapError;
|
|
1109
|
+
/**
|
|
1110
|
+
* Determine execution status from error
|
|
1111
|
+
*/
|
|
1112
|
+
private determineErrorStatus;
|
|
1113
|
+
/**
|
|
1114
|
+
* Create final execution result
|
|
1115
|
+
*/
|
|
1116
|
+
private createExecutionResult;
|
|
1117
|
+
/**
|
|
1118
|
+
* Cancel an execution
|
|
1119
|
+
*/
|
|
1120
|
+
private cancelExecution;
|
|
1121
|
+
/**
|
|
1122
|
+
* Cleanup execution resources
|
|
1123
|
+
*/
|
|
1124
|
+
private cleanupExecution;
|
|
1125
|
+
/**
|
|
1126
|
+
* Calculate average iteration duration across contexts
|
|
1127
|
+
*/
|
|
1128
|
+
private calculateAverageIterationDuration;
|
|
1129
|
+
/**
|
|
1130
|
+
* Aggregate error breakdown across contexts
|
|
1131
|
+
*/
|
|
1132
|
+
private aggregateErrorBreakdown;
|
|
1133
|
+
/**
|
|
1134
|
+
* Calculate performance metrics across contexts
|
|
1135
|
+
*/
|
|
1136
|
+
private calculatePerformanceMetrics;
|
|
1137
|
+
/**
|
|
1138
|
+
* Sleep utility for delays
|
|
1139
|
+
*/
|
|
1140
|
+
private sleep;
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Create an execution engine with default configuration
|
|
1144
|
+
*
|
|
1145
|
+
* @param config - Base juno-task configuration
|
|
1146
|
+
* @returns Configured execution engine
|
|
1147
|
+
*/
|
|
1148
|
+
declare function createExecutionEngine(config: JunoTaskConfig): ExecutionEngine;
|
|
1149
|
+
/**
|
|
1150
|
+
* Create an execution request with defaults
|
|
1151
|
+
*
|
|
1152
|
+
* @param options - Request options
|
|
1153
|
+
* @returns Execution request
|
|
1154
|
+
*/
|
|
1155
|
+
declare function createExecutionRequest(options: {
|
|
1156
|
+
instruction: string;
|
|
1157
|
+
subagent?: SubagentType;
|
|
1158
|
+
backend?: BackendType;
|
|
1159
|
+
workingDirectory?: string;
|
|
1160
|
+
maxIterations?: number;
|
|
1161
|
+
model?: string;
|
|
1162
|
+
agents?: string;
|
|
1163
|
+
tools?: string[];
|
|
1164
|
+
allowedTools?: string[];
|
|
1165
|
+
appendAllowedTools?: string[];
|
|
1166
|
+
disallowedTools?: string[];
|
|
1167
|
+
requestId?: string;
|
|
1168
|
+
mcpServerName?: string;
|
|
1169
|
+
resume?: string;
|
|
1170
|
+
continueConversation?: boolean;
|
|
1171
|
+
}): ExecutionRequest;
|
|
1172
|
+
|
|
1173
|
+
/** Session metadata */
|
|
1174
|
+
interface SessionInfo {
|
|
1175
|
+
id: string;
|
|
1176
|
+
name?: string;
|
|
1177
|
+
status: SessionStatus;
|
|
1178
|
+
subagent: SubagentType;
|
|
1179
|
+
createdAt: Date;
|
|
1180
|
+
updatedAt: Date;
|
|
1181
|
+
completedAt?: Date;
|
|
1182
|
+
workingDirectory: string;
|
|
1183
|
+
config: Partial<JunoTaskConfig>;
|
|
1184
|
+
tags: string[];
|
|
1185
|
+
metadata: Record<string, any>;
|
|
1186
|
+
}
|
|
1187
|
+
/** Session statistics - essential counters only */
|
|
1188
|
+
interface SessionStatistics {
|
|
1189
|
+
duration: number;
|
|
1190
|
+
iterations: number;
|
|
1191
|
+
toolCalls: number;
|
|
1192
|
+
errorCount: number;
|
|
1193
|
+
}
|
|
1194
|
+
/** Complete session state */
|
|
1195
|
+
interface Session {
|
|
1196
|
+
info: SessionInfo;
|
|
1197
|
+
context: {
|
|
1198
|
+
workingDirectory: string;
|
|
1199
|
+
config: JunoTaskConfig;
|
|
1200
|
+
};
|
|
1201
|
+
statistics: SessionStatistics;
|
|
1202
|
+
history: SessionHistoryEntry[];
|
|
1203
|
+
result?: {
|
|
1204
|
+
success: boolean;
|
|
1205
|
+
output?: string;
|
|
1206
|
+
error?: string;
|
|
1207
|
+
finalState?: any;
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
/** History entry for conversation tracking */
|
|
1211
|
+
interface SessionHistoryEntry {
|
|
1212
|
+
id: string;
|
|
1213
|
+
timestamp: Date;
|
|
1214
|
+
type: 'prompt' | 'response' | 'tool_call' | 'error' | 'system';
|
|
1215
|
+
content: string;
|
|
1216
|
+
data?: any;
|
|
1217
|
+
duration?: number;
|
|
1218
|
+
iteration?: number;
|
|
1219
|
+
}
|
|
1220
|
+
/** Persistence layer abstraction */
|
|
1221
|
+
interface SessionStorage {
|
|
1222
|
+
saveSession(session: Session): Promise<void>;
|
|
1223
|
+
loadSession(sessionId: string): Promise<Session | null>;
|
|
1224
|
+
listSessions(filter?: SessionListFilter): Promise<SessionInfo[]>;
|
|
1225
|
+
removeSession(sessionId: string): Promise<void>;
|
|
1226
|
+
sessionExists(sessionId: string): Promise<boolean>;
|
|
1227
|
+
cleanup(options: CleanupOptions): Promise<void>;
|
|
1228
|
+
}
|
|
1229
|
+
/** Filter criteria for listing sessions */
|
|
1230
|
+
interface SessionListFilter {
|
|
1231
|
+
status?: SessionStatus[];
|
|
1232
|
+
subagent?: SubagentType[];
|
|
1233
|
+
dateRange?: {
|
|
1234
|
+
start?: Date;
|
|
1235
|
+
end?: Date;
|
|
1236
|
+
};
|
|
1237
|
+
tags?: string[];
|
|
1238
|
+
limit?: number;
|
|
1239
|
+
offset?: number;
|
|
1240
|
+
sortBy?: 'createdAt' | 'updatedAt' | 'name';
|
|
1241
|
+
sortOrder?: 'asc' | 'desc';
|
|
1242
|
+
}
|
|
1243
|
+
/** Options for storage cleanup */
|
|
1244
|
+
interface CleanupOptions {
|
|
1245
|
+
removeEmpty?: boolean;
|
|
1246
|
+
removeOlderThanDays?: number;
|
|
1247
|
+
removeStatus?: SessionStatus[];
|
|
1248
|
+
dryRun?: boolean;
|
|
1249
|
+
}
|
|
1250
|
+
/** File-based session storage implementation */
|
|
1251
|
+
declare class FileSessionStorage implements SessionStorage {
|
|
1252
|
+
private readonly baseDir;
|
|
1253
|
+
private readonly sessionsDir;
|
|
1254
|
+
constructor(baseDir: string);
|
|
1255
|
+
initialize(): Promise<void>;
|
|
1256
|
+
private getSessionPath;
|
|
1257
|
+
saveSession(session: Session): Promise<void>;
|
|
1258
|
+
loadSession(sessionId: string): Promise<Session | null>;
|
|
1259
|
+
listSessions(filter?: SessionListFilter): Promise<SessionInfo[]>;
|
|
1260
|
+
removeSession(sessionId: string): Promise<void>;
|
|
1261
|
+
sessionExists(sessionId: string): Promise<boolean>;
|
|
1262
|
+
cleanup(options: CleanupOptions): Promise<void>;
|
|
1263
|
+
}
|
|
1264
|
+
/** Session manager - plain class for session lifecycle management */
|
|
1265
|
+
declare class SessionManager {
|
|
1266
|
+
private storage;
|
|
1267
|
+
private activeSessions;
|
|
1268
|
+
constructor(storage: SessionStorage);
|
|
1269
|
+
createSession(options: {
|
|
1270
|
+
name?: string;
|
|
1271
|
+
subagent: SubagentType;
|
|
1272
|
+
config: JunoTaskConfig;
|
|
1273
|
+
tags?: string[];
|
|
1274
|
+
metadata?: Record<string, any>;
|
|
1275
|
+
}): Promise<Session>;
|
|
1276
|
+
updateSession(sessionId: string, updates: {
|
|
1277
|
+
status?: SessionStatus;
|
|
1278
|
+
name?: string;
|
|
1279
|
+
tags?: string[];
|
|
1280
|
+
metadata?: Record<string, any>;
|
|
1281
|
+
statistics?: Partial<SessionStatistics>;
|
|
1282
|
+
result?: Session['result'];
|
|
1283
|
+
}): Promise<void>;
|
|
1284
|
+
completeSession(sessionId: string, result: {
|
|
1285
|
+
success: boolean;
|
|
1286
|
+
output?: string;
|
|
1287
|
+
error?: string;
|
|
1288
|
+
finalState?: any;
|
|
1289
|
+
}): Promise<void>;
|
|
1290
|
+
cancelSession(sessionId: string): Promise<void>;
|
|
1291
|
+
getSession(sessionId: string): Promise<Session | null>;
|
|
1292
|
+
listSessions(filter?: SessionListFilter): Promise<SessionInfo[]>;
|
|
1293
|
+
removeSession(sessionId: string): Promise<void>;
|
|
1294
|
+
cleanupSessions(options: CleanupOptions): Promise<void>;
|
|
1295
|
+
addHistoryEntry(sessionId: string, entry: Omit<SessionHistoryEntry, 'id' | 'timestamp'>): Promise<void>;
|
|
1296
|
+
updateStatistics(sessionId: string, stats: Partial<SessionStatistics>): Promise<void>;
|
|
1297
|
+
recordToolCall(sessionId: string, toolCall: {
|
|
1298
|
+
name: string;
|
|
1299
|
+
duration: number;
|
|
1300
|
+
success: boolean;
|
|
1301
|
+
}): Promise<void>;
|
|
1302
|
+
getSessionContext(sessionId: string, options?: {
|
|
1303
|
+
includeHistory?: boolean;
|
|
1304
|
+
includeStats?: boolean;
|
|
1305
|
+
maxHistoryEntries?: number;
|
|
1306
|
+
}): Promise<string>;
|
|
1307
|
+
getSessionSummary(sessionId: string): Promise<{
|
|
1308
|
+
info: SessionInfo;
|
|
1309
|
+
statistics: SessionStatistics;
|
|
1310
|
+
summary: {
|
|
1311
|
+
totalDuration: string;
|
|
1312
|
+
iterationsPerMinute: number;
|
|
1313
|
+
toolCallsPerIteration: number;
|
|
1314
|
+
errorRate: number;
|
|
1315
|
+
};
|
|
1316
|
+
} | null>;
|
|
1317
|
+
private formatDuration;
|
|
1318
|
+
}
|
|
1319
|
+
/** Create a session manager with file storage */
|
|
1320
|
+
declare function createSessionManager(config: JunoTaskConfig): Promise<SessionManager>;
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Environment Utilities Module for juno-task-ts
|
|
1324
|
+
*
|
|
1325
|
+
* Provides comprehensive environment variable handling and detection utilities
|
|
1326
|
+
* for the juno-task-ts CLI tool. This module includes environment detection,
|
|
1327
|
+
* terminal capabilities, platform information, configuration directories,
|
|
1328
|
+
* and MCP server path detection.
|
|
1329
|
+
*
|
|
1330
|
+
* @module utils/environment
|
|
1331
|
+
*/
|
|
1332
|
+
/**
|
|
1333
|
+
* Color support levels for terminal output
|
|
1334
|
+
*/
|
|
1335
|
+
type ColorSupport = 'none' | 'basic' | '256' | 'truecolor';
|
|
1336
|
+
/**
|
|
1337
|
+
* Node.js environment types
|
|
1338
|
+
*/
|
|
1339
|
+
type NodeEnvironment = 'development' | 'production' | 'test';
|
|
1340
|
+
/**
|
|
1341
|
+
* Operating system platforms
|
|
1342
|
+
*/
|
|
1343
|
+
type Platform = 'win32' | 'darwin' | 'linux' | 'freebsd' | 'openbsd' | 'sunos' | 'aix';
|
|
1344
|
+
/**
|
|
1345
|
+
* System architectures
|
|
1346
|
+
*/
|
|
1347
|
+
type Architecture = 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x64';
|
|
1348
|
+
/**
|
|
1349
|
+
* Shell types
|
|
1350
|
+
*/
|
|
1351
|
+
type ShellType = 'bash' | 'zsh' | 'fish' | 'cmd' | 'powershell' | 'unknown';
|
|
1352
|
+
/**
|
|
1353
|
+
* Process information interface
|
|
1354
|
+
*/
|
|
1355
|
+
interface ProcessInfo {
|
|
1356
|
+
pid: number;
|
|
1357
|
+
ppid: number;
|
|
1358
|
+
platform: Platform;
|
|
1359
|
+
arch: Architecture;
|
|
1360
|
+
nodeVersion: string;
|
|
1361
|
+
uptime: number;
|
|
1362
|
+
cwd: string;
|
|
1363
|
+
execPath: string;
|
|
1364
|
+
argv: string[];
|
|
1365
|
+
env: Record<string, string | undefined>;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Memory usage information
|
|
1369
|
+
*/
|
|
1370
|
+
interface MemoryUsage {
|
|
1371
|
+
rss: number;
|
|
1372
|
+
heapTotal: number;
|
|
1373
|
+
heapUsed: number;
|
|
1374
|
+
external: number;
|
|
1375
|
+
arrayBuffers: number;
|
|
1376
|
+
}
|
|
1377
|
+
/**
|
|
1378
|
+
* CPU usage information
|
|
1379
|
+
*/
|
|
1380
|
+
interface CpuUsage {
|
|
1381
|
+
user: number;
|
|
1382
|
+
system: number;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* MCP server environment configuration
|
|
1386
|
+
*/
|
|
1387
|
+
interface MCPServerEnvironment {
|
|
1388
|
+
PATH: string;
|
|
1389
|
+
NODE_ENV: string;
|
|
1390
|
+
[key: string]: string;
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Detect if running in a headless/CI environment where interactive prompts should be avoided.
|
|
1394
|
+
* Based on the Python implementation patterns from budi-cli.
|
|
1395
|
+
*
|
|
1396
|
+
* @returns True if running in headless/CI environment
|
|
1397
|
+
*
|
|
1398
|
+
* @example
|
|
1399
|
+
* ```typescript
|
|
1400
|
+
* if (isHeadlessEnvironment()) {
|
|
1401
|
+
* console.log('Using non-interactive mode');
|
|
1402
|
+
* }
|
|
1403
|
+
* ```
|
|
1404
|
+
*/
|
|
1405
|
+
declare function isHeadlessEnvironment(): boolean;
|
|
1406
|
+
/**
|
|
1407
|
+
* Detect if running in a continuous integration environment.
|
|
1408
|
+
*
|
|
1409
|
+
* @returns True if running in CI environment
|
|
1410
|
+
*
|
|
1411
|
+
* @example
|
|
1412
|
+
* ```typescript
|
|
1413
|
+
* if (isCIEnvironment()) {
|
|
1414
|
+
* console.log('Running in CI environment');
|
|
1415
|
+
* }
|
|
1416
|
+
* ```
|
|
1417
|
+
*/
|
|
1418
|
+
declare function isCIEnvironment(): boolean;
|
|
1419
|
+
/**
|
|
1420
|
+
* Check if terminal supports interactive input/output.
|
|
1421
|
+
*
|
|
1422
|
+
* @returns True if terminal supports interaction
|
|
1423
|
+
*
|
|
1424
|
+
* @example
|
|
1425
|
+
* ```typescript
|
|
1426
|
+
* if (isInteractiveTerminal()) {
|
|
1427
|
+
* // Show interactive prompts
|
|
1428
|
+
* }
|
|
1429
|
+
* ```
|
|
1430
|
+
*/
|
|
1431
|
+
declare function isInteractiveTerminal(): boolean;
|
|
1432
|
+
/**
|
|
1433
|
+
* Detect if running in development mode.
|
|
1434
|
+
*
|
|
1435
|
+
* @returns True if in development mode
|
|
1436
|
+
*
|
|
1437
|
+
* @example
|
|
1438
|
+
* ```typescript
|
|
1439
|
+
* if (isDevelopmentMode()) {
|
|
1440
|
+
* console.log('Debug logging enabled');
|
|
1441
|
+
* }
|
|
1442
|
+
* ```
|
|
1443
|
+
*/
|
|
1444
|
+
declare function isDevelopmentMode(): boolean;
|
|
1445
|
+
/**
|
|
1446
|
+
* Get Node.js environment type.
|
|
1447
|
+
*
|
|
1448
|
+
* @returns The Node.js environment type
|
|
1449
|
+
*
|
|
1450
|
+
* @example
|
|
1451
|
+
* ```typescript
|
|
1452
|
+
* const env = getNodeEnvironment();
|
|
1453
|
+
* console.log(`Running in ${env} mode`);
|
|
1454
|
+
* ```
|
|
1455
|
+
*/
|
|
1456
|
+
declare function getNodeEnvironment(): NodeEnvironment;
|
|
1457
|
+
/**
|
|
1458
|
+
* Get environment variable with optional type conversion.
|
|
1459
|
+
*
|
|
1460
|
+
* @param key - Environment variable name
|
|
1461
|
+
* @param defaultValue - Default value if variable is not set
|
|
1462
|
+
* @returns Environment variable value or default
|
|
1463
|
+
*
|
|
1464
|
+
* @example
|
|
1465
|
+
* ```typescript
|
|
1466
|
+
* const port = getEnvVar('PORT', '3000');
|
|
1467
|
+
* const timeout = getEnvVar('TIMEOUT', '30');
|
|
1468
|
+
* ```
|
|
1469
|
+
*/
|
|
1470
|
+
declare function getEnvVar(key: string, defaultValue?: string): string | undefined;
|
|
1471
|
+
/**
|
|
1472
|
+
* Get environment variable with fallback value.
|
|
1473
|
+
*
|
|
1474
|
+
* @param key - Environment variable name
|
|
1475
|
+
* @param defaultValue - Default value if variable is not set
|
|
1476
|
+
* @returns Environment variable value or default
|
|
1477
|
+
*
|
|
1478
|
+
* @example
|
|
1479
|
+
* ```typescript
|
|
1480
|
+
* const logLevel = getEnvVarWithDefault('LOG_LEVEL', 'info');
|
|
1481
|
+
* ```
|
|
1482
|
+
*/
|
|
1483
|
+
declare function getEnvVarWithDefault(key: string, defaultValue: string): string;
|
|
1484
|
+
/**
|
|
1485
|
+
* Set environment variable safely.
|
|
1486
|
+
*
|
|
1487
|
+
* @param key - Environment variable name
|
|
1488
|
+
* @param value - Value to set
|
|
1489
|
+
*
|
|
1490
|
+
* @example
|
|
1491
|
+
* ```typescript
|
|
1492
|
+
* setEnvVar('DEBUG', 'true');
|
|
1493
|
+
* ```
|
|
1494
|
+
*/
|
|
1495
|
+
declare function setEnvVar(key: string, value: string): void;
|
|
1496
|
+
/**
|
|
1497
|
+
* Parse boolean value from environment variable string.
|
|
1498
|
+
*
|
|
1499
|
+
* @param value - Environment variable value
|
|
1500
|
+
* @param defaultValue - Default boolean value
|
|
1501
|
+
* @returns Parsed boolean value
|
|
1502
|
+
*
|
|
1503
|
+
* @example
|
|
1504
|
+
* ```typescript
|
|
1505
|
+
* const isVerbose = parseEnvBoolean(process.env.VERBOSE, false);
|
|
1506
|
+
* const isEnabled = parseEnvBoolean('true'); // returns true
|
|
1507
|
+
* ```
|
|
1508
|
+
*/
|
|
1509
|
+
declare function parseEnvBoolean(value: string | undefined, defaultValue?: boolean): boolean;
|
|
1510
|
+
/**
|
|
1511
|
+
* Parse number value from environment variable string.
|
|
1512
|
+
*
|
|
1513
|
+
* @param value - Environment variable value
|
|
1514
|
+
* @param defaultValue - Default number value
|
|
1515
|
+
* @returns Parsed number value
|
|
1516
|
+
*
|
|
1517
|
+
* @example
|
|
1518
|
+
* ```typescript
|
|
1519
|
+
* const port = parseEnvNumber(process.env.PORT, 3000);
|
|
1520
|
+
* const timeout = parseEnvNumber('30'); // returns 30
|
|
1521
|
+
* ```
|
|
1522
|
+
*/
|
|
1523
|
+
declare function parseEnvNumber(value: string | undefined, defaultValue?: number): number;
|
|
1524
|
+
/**
|
|
1525
|
+
* Parse array from delimited environment variable string.
|
|
1526
|
+
*
|
|
1527
|
+
* @param value - Environment variable value
|
|
1528
|
+
* @param delimiter - Delimiter to split on
|
|
1529
|
+
* @param defaultValue - Default array value
|
|
1530
|
+
* @returns Parsed array
|
|
1531
|
+
*
|
|
1532
|
+
* @example
|
|
1533
|
+
* ```typescript
|
|
1534
|
+
* const paths = parseEnvArray(process.env.SEARCH_PATHS, ':', []);
|
|
1535
|
+
* const hosts = parseEnvArray('host1,host2,host3', ','); // returns ['host1', 'host2', 'host3']
|
|
1536
|
+
* ```
|
|
1537
|
+
*/
|
|
1538
|
+
declare function parseEnvArray(value: string | undefined, delimiter?: string, defaultValue?: string[]): string[];
|
|
1539
|
+
/**
|
|
1540
|
+
* Get terminal width for formatting output.
|
|
1541
|
+
*
|
|
1542
|
+
* @returns Terminal width in columns
|
|
1543
|
+
*
|
|
1544
|
+
* @example
|
|
1545
|
+
* ```typescript
|
|
1546
|
+
* const width = getTerminalWidth();
|
|
1547
|
+
* console.log(`Terminal width: ${width} columns`);
|
|
1548
|
+
* ```
|
|
1549
|
+
*/
|
|
1550
|
+
declare function getTerminalWidth(): number;
|
|
1551
|
+
/**
|
|
1552
|
+
* Get terminal height for formatting output.
|
|
1553
|
+
*
|
|
1554
|
+
* @returns Terminal height in rows
|
|
1555
|
+
*
|
|
1556
|
+
* @example
|
|
1557
|
+
* ```typescript
|
|
1558
|
+
* const height = getTerminalHeight();
|
|
1559
|
+
* console.log(`Terminal height: ${height} rows`);
|
|
1560
|
+
* ```
|
|
1561
|
+
*/
|
|
1562
|
+
declare function getTerminalHeight(): number;
|
|
1563
|
+
/**
|
|
1564
|
+
* Check if terminal supports color output.
|
|
1565
|
+
*
|
|
1566
|
+
* @returns True if terminal supports colors
|
|
1567
|
+
*
|
|
1568
|
+
* @example
|
|
1569
|
+
* ```typescript
|
|
1570
|
+
* if (supportsColor()) {
|
|
1571
|
+
* console.log('\x1b[32mGreen text\x1b[0m');
|
|
1572
|
+
* }
|
|
1573
|
+
* ```
|
|
1574
|
+
*/
|
|
1575
|
+
declare function supportsColor(): boolean;
|
|
1576
|
+
/**
|
|
1577
|
+
* Get color capability level of the terminal.
|
|
1578
|
+
*
|
|
1579
|
+
* @returns Color support level
|
|
1580
|
+
*
|
|
1581
|
+
* @example
|
|
1582
|
+
* ```typescript
|
|
1583
|
+
* const colorSupport = getColorSupport();
|
|
1584
|
+
* if (colorSupport === 'truecolor') {
|
|
1585
|
+
* // Use RGB colors
|
|
1586
|
+
* }
|
|
1587
|
+
* ```
|
|
1588
|
+
*/
|
|
1589
|
+
declare function getColorSupport(): ColorSupport;
|
|
1590
|
+
/**
|
|
1591
|
+
* Detect if running inside a Docker container.
|
|
1592
|
+
*
|
|
1593
|
+
* @returns True if running in Docker
|
|
1594
|
+
*
|
|
1595
|
+
* @example
|
|
1596
|
+
* ```typescript
|
|
1597
|
+
* if (isInDocker()) {
|
|
1598
|
+
* console.log('Running in Docker container');
|
|
1599
|
+
* }
|
|
1600
|
+
* ```
|
|
1601
|
+
*/
|
|
1602
|
+
declare function isInDocker(): boolean;
|
|
1603
|
+
/**
|
|
1604
|
+
* Get operating system platform information.
|
|
1605
|
+
*
|
|
1606
|
+
* @returns Platform information
|
|
1607
|
+
*
|
|
1608
|
+
* @example
|
|
1609
|
+
* ```typescript
|
|
1610
|
+
* const platform = getPlatform();
|
|
1611
|
+
* console.log(`Running on ${platform}`);
|
|
1612
|
+
* ```
|
|
1613
|
+
*/
|
|
1614
|
+
declare function getPlatform(): Platform;
|
|
1615
|
+
/**
|
|
1616
|
+
* Get system architecture information.
|
|
1617
|
+
*
|
|
1618
|
+
* @returns System architecture
|
|
1619
|
+
*
|
|
1620
|
+
* @example
|
|
1621
|
+
* ```typescript
|
|
1622
|
+
* const arch = getArchitecture();
|
|
1623
|
+
* console.log(`System architecture: ${arch}`);
|
|
1624
|
+
* ```
|
|
1625
|
+
*/
|
|
1626
|
+
declare function getArchitecture(): Architecture;
|
|
1627
|
+
/**
|
|
1628
|
+
* Detect user's shell (bash, zsh, fish, etc.).
|
|
1629
|
+
*
|
|
1630
|
+
* @returns Detected shell type
|
|
1631
|
+
*
|
|
1632
|
+
* @example
|
|
1633
|
+
* ```typescript
|
|
1634
|
+
* const shell = getShell();
|
|
1635
|
+
* console.log(`User shell: ${shell}`);
|
|
1636
|
+
* ```
|
|
1637
|
+
*/
|
|
1638
|
+
declare function getShell(): ShellType;
|
|
1639
|
+
/**
|
|
1640
|
+
* Get user home directory path.
|
|
1641
|
+
*
|
|
1642
|
+
* @returns User home directory path
|
|
1643
|
+
*
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```typescript
|
|
1646
|
+
* const home = getHomeDirectory();
|
|
1647
|
+
* console.log(`Home directory: ${home}`);
|
|
1648
|
+
* ```
|
|
1649
|
+
*/
|
|
1650
|
+
declare function getHomeDirectory(): string;
|
|
1651
|
+
/**
|
|
1652
|
+
* Get system temporary directory path.
|
|
1653
|
+
*
|
|
1654
|
+
* @returns System temp directory path
|
|
1655
|
+
*
|
|
1656
|
+
* @example
|
|
1657
|
+
* ```typescript
|
|
1658
|
+
* const temp = getTempDirectory();
|
|
1659
|
+
* console.log(`Temp directory: ${temp}`);
|
|
1660
|
+
* ```
|
|
1661
|
+
*/
|
|
1662
|
+
declare function getTempDirectory(): string;
|
|
1663
|
+
/**
|
|
1664
|
+
* Get user configuration directory path.
|
|
1665
|
+
* Follows XDG Base Directory specification on Unix systems.
|
|
1666
|
+
*
|
|
1667
|
+
* @param appName - Application name for subdirectory
|
|
1668
|
+
* @returns Configuration directory path
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
* ```typescript
|
|
1672
|
+
* const configDir = getConfigDirectory('juno-task');
|
|
1673
|
+
* // Returns: ~/.config/juno-task (Linux), ~/Library/Application Support/juno-task (macOS), etc.
|
|
1674
|
+
* ```
|
|
1675
|
+
*/
|
|
1676
|
+
declare function getConfigDirectory(appName?: string): string;
|
|
1677
|
+
/**
|
|
1678
|
+
* Get user data directory path.
|
|
1679
|
+
*
|
|
1680
|
+
* @param appName - Application name for subdirectory
|
|
1681
|
+
* @returns Data directory path
|
|
1682
|
+
*
|
|
1683
|
+
* @example
|
|
1684
|
+
* ```typescript
|
|
1685
|
+
* const dataDir = getDataDirectory('juno-task');
|
|
1686
|
+
* ```
|
|
1687
|
+
*/
|
|
1688
|
+
declare function getDataDirectory(appName?: string): string;
|
|
1689
|
+
/**
|
|
1690
|
+
* Get user cache directory path.
|
|
1691
|
+
*
|
|
1692
|
+
* @param appName - Application name for subdirectory
|
|
1693
|
+
* @returns Cache directory path
|
|
1694
|
+
*
|
|
1695
|
+
* @example
|
|
1696
|
+
* ```typescript
|
|
1697
|
+
* const cacheDir = getCacheDirectory('juno-task');
|
|
1698
|
+
* ```
|
|
1699
|
+
*/
|
|
1700
|
+
declare function getCacheDirectory(appName?: string): string;
|
|
1701
|
+
/**
|
|
1702
|
+
* Create directory if it doesn't exist.
|
|
1703
|
+
*
|
|
1704
|
+
* @param dirPath - Directory path to create
|
|
1705
|
+
* @returns Promise that resolves when directory is created
|
|
1706
|
+
*
|
|
1707
|
+
* @example
|
|
1708
|
+
* ```typescript
|
|
1709
|
+
* await createDirectoryIfNotExists('/path/to/config');
|
|
1710
|
+
* ```
|
|
1711
|
+
*/
|
|
1712
|
+
declare function createDirectoryIfNotExists(dirPath: string): Promise<void>;
|
|
1713
|
+
/**
|
|
1714
|
+
* Get current process information.
|
|
1715
|
+
*
|
|
1716
|
+
* @returns Process information object
|
|
1717
|
+
*
|
|
1718
|
+
* @example
|
|
1719
|
+
* ```typescript
|
|
1720
|
+
* const info = getProcessInfo();
|
|
1721
|
+
* console.log(`Process ID: ${info.pid}`);
|
|
1722
|
+
* ```
|
|
1723
|
+
*/
|
|
1724
|
+
declare function getProcessInfo(): ProcessInfo;
|
|
1725
|
+
/**
|
|
1726
|
+
* Check if running with root/administrator privileges.
|
|
1727
|
+
*
|
|
1728
|
+
* @returns True if running as root
|
|
1729
|
+
*
|
|
1730
|
+
* @example
|
|
1731
|
+
* ```typescript
|
|
1732
|
+
* if (isRunningAsRoot()) {
|
|
1733
|
+
* console.warn('Running with elevated privileges');
|
|
1734
|
+
* }
|
|
1735
|
+
* ```
|
|
1736
|
+
*/
|
|
1737
|
+
declare function isRunningAsRoot(): boolean;
|
|
1738
|
+
/**
|
|
1739
|
+
* Get process memory usage information.
|
|
1740
|
+
*
|
|
1741
|
+
* @returns Memory usage information
|
|
1742
|
+
*
|
|
1743
|
+
* @example
|
|
1744
|
+
* ```typescript
|
|
1745
|
+
* const memory = getMemoryUsage();
|
|
1746
|
+
* console.log(`Heap used: ${(memory.heapUsed / 1024 / 1024).toFixed(2)} MB`);
|
|
1747
|
+
* ```
|
|
1748
|
+
*/
|
|
1749
|
+
declare function getMemoryUsage(): MemoryUsage;
|
|
1750
|
+
/**
|
|
1751
|
+
* Get CPU usage information.
|
|
1752
|
+
*
|
|
1753
|
+
* @returns CPU usage information
|
|
1754
|
+
*
|
|
1755
|
+
* @example
|
|
1756
|
+
* ```typescript
|
|
1757
|
+
* const cpu = getCpuUsage();
|
|
1758
|
+
* console.log(`User CPU time: ${cpu.user}μs`);
|
|
1759
|
+
* ```
|
|
1760
|
+
*/
|
|
1761
|
+
declare function getCpuUsage(): CpuUsage;
|
|
1762
|
+
/**
|
|
1763
|
+
* Auto-discover MCP server location.
|
|
1764
|
+
* Searches common installation paths and PATH environment variable.
|
|
1765
|
+
*
|
|
1766
|
+
* @param serverName - MCP server executable name
|
|
1767
|
+
* @returns Promise that resolves to server path or null if not found
|
|
1768
|
+
*
|
|
1769
|
+
* @example
|
|
1770
|
+
* ```typescript
|
|
1771
|
+
* const serverPath = await findMCPServerPath('mcp-server');
|
|
1772
|
+
* if (serverPath) {
|
|
1773
|
+
* console.log(`Found MCP server at: ${serverPath}`);
|
|
1774
|
+
* }
|
|
1775
|
+
* ```
|
|
1776
|
+
*/
|
|
1777
|
+
declare function findMCPServerPath(serverName?: string): Promise<string | null>;
|
|
1778
|
+
/**
|
|
1779
|
+
* Verify MCP server path is executable.
|
|
1780
|
+
*
|
|
1781
|
+
* @param serverPath - Path to MCP server executable
|
|
1782
|
+
* @returns Promise that resolves to true if valid and executable
|
|
1783
|
+
*
|
|
1784
|
+
* @example
|
|
1785
|
+
* ```typescript
|
|
1786
|
+
* const isValid = await validateMCPServerPath('/usr/local/bin/mcp-server');
|
|
1787
|
+
* if (isValid) {
|
|
1788
|
+
* console.log('MCP server is valid and executable');
|
|
1789
|
+
* }
|
|
1790
|
+
* ```
|
|
1791
|
+
*/
|
|
1792
|
+
declare function validateMCPServerPath(serverPath: string): Promise<boolean>;
|
|
1793
|
+
/**
|
|
1794
|
+
* Get environment configuration for MCP server.
|
|
1795
|
+
*
|
|
1796
|
+
* @param additionalEnv - Additional environment variables
|
|
1797
|
+
* @returns MCP server environment configuration
|
|
1798
|
+
*
|
|
1799
|
+
* @example
|
|
1800
|
+
* ```typescript
|
|
1801
|
+
* const env = getMCPServerEnvironment({ DEBUG: 'true' });
|
|
1802
|
+
* console.log('MCP server environment:', env);
|
|
1803
|
+
* ```
|
|
1804
|
+
*/
|
|
1805
|
+
declare function getMCPServerEnvironment(additionalEnv?: Record<string, string>): MCPServerEnvironment;
|
|
1806
|
+
|
|
1807
|
+
declare enum LogContext {
|
|
1808
|
+
CLI = "CLI",
|
|
1809
|
+
MCP = "MCP",
|
|
1810
|
+
ENGINE = "ENGINE",
|
|
1811
|
+
SESSION = "SESSION",
|
|
1812
|
+
TEMPLATE = "TEMPLATE",
|
|
1813
|
+
CONFIG = "CONFIG",
|
|
1814
|
+
PERFORMANCE = "PERFORMANCE",
|
|
1815
|
+
SYSTEM = "SYSTEM"
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
/**
|
|
1819
|
+
* Hook execution utility module for juno-task-ts
|
|
1820
|
+
*
|
|
1821
|
+
* Provides robust hook execution functionality with comprehensive logging,
|
|
1822
|
+
* error handling, and execution context tracking.
|
|
1823
|
+
*
|
|
1824
|
+
* @module utils/hooks
|
|
1825
|
+
*/
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* Supported hook types for lifecycle execution
|
|
1829
|
+
*/
|
|
1830
|
+
type HookType = 'START_RUN' | 'START_ITERATION' | 'END_ITERATION' | 'END_RUN' | 'ON_STALE';
|
|
1831
|
+
/**
|
|
1832
|
+
* Hook configuration interface
|
|
1833
|
+
*/
|
|
1834
|
+
interface Hook {
|
|
1835
|
+
/** List of bash commands to execute for this hook */
|
|
1836
|
+
commands: string[];
|
|
1837
|
+
}
|
|
1838
|
+
/**
|
|
1839
|
+
* Complete hooks configuration mapping hook types to their configurations
|
|
1840
|
+
*/
|
|
1841
|
+
interface HooksConfig {
|
|
1842
|
+
[key: string]: Hook;
|
|
1843
|
+
}
|
|
1844
|
+
/**
|
|
1845
|
+
* Execution context for hooks - provides information about the current execution state
|
|
1846
|
+
*/
|
|
1847
|
+
interface HookExecutionContext {
|
|
1848
|
+
/** Current iteration number (for iteration-based hooks) */
|
|
1849
|
+
iteration?: number;
|
|
1850
|
+
/** Session ID for tracking */
|
|
1851
|
+
sessionId?: string;
|
|
1852
|
+
/** Working directory for command execution */
|
|
1853
|
+
workingDirectory?: string;
|
|
1854
|
+
/** Additional metadata */
|
|
1855
|
+
metadata?: Record<string, any>;
|
|
1856
|
+
/** Run ID for tracking across hooks */
|
|
1857
|
+
runId?: string;
|
|
1858
|
+
/** Total iterations planned */
|
|
1859
|
+
totalIterations?: number;
|
|
1860
|
+
}
|
|
1861
|
+
/**
|
|
1862
|
+
* Result of a single command execution within a hook
|
|
1863
|
+
*/
|
|
1864
|
+
interface CommandExecutionResult {
|
|
1865
|
+
/** The command that was executed */
|
|
1866
|
+
command: string;
|
|
1867
|
+
/** Exit code (0 for success) */
|
|
1868
|
+
exitCode: number;
|
|
1869
|
+
/** Standard output */
|
|
1870
|
+
stdout: string;
|
|
1871
|
+
/** Standard error output */
|
|
1872
|
+
stderr: string;
|
|
1873
|
+
/** Execution duration in milliseconds */
|
|
1874
|
+
duration: number;
|
|
1875
|
+
/** Whether the command succeeded */
|
|
1876
|
+
success: boolean;
|
|
1877
|
+
/** Error if execution failed */
|
|
1878
|
+
error?: Error;
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Result of executing all commands in a hook
|
|
1882
|
+
*/
|
|
1883
|
+
interface HookExecutionResult {
|
|
1884
|
+
/** Hook type that was executed */
|
|
1885
|
+
hookType: HookType;
|
|
1886
|
+
/** Total execution duration for all commands */
|
|
1887
|
+
totalDuration: number;
|
|
1888
|
+
/** Results for each command */
|
|
1889
|
+
commandResults: CommandExecutionResult[];
|
|
1890
|
+
/** Overall success (true if all commands succeeded) */
|
|
1891
|
+
success: boolean;
|
|
1892
|
+
/** Number of commands executed */
|
|
1893
|
+
commandsExecuted: number;
|
|
1894
|
+
/** Number of commands that failed */
|
|
1895
|
+
commandsFailed: number;
|
|
1896
|
+
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Hook execution options
|
|
1899
|
+
*/
|
|
1900
|
+
interface HookExecutionOptions {
|
|
1901
|
+
/** Maximum timeout per command in milliseconds (default: 300000 = 5 minutes) */
|
|
1902
|
+
commandTimeout?: number | undefined;
|
|
1903
|
+
/** Environment variables to pass to commands */
|
|
1904
|
+
env?: Record<string, string> | undefined;
|
|
1905
|
+
/** Whether to continue executing commands if one fails (default: true) */
|
|
1906
|
+
continueOnError?: boolean | undefined;
|
|
1907
|
+
/** Custom logger context (default: 'SYSTEM') */
|
|
1908
|
+
logContext?: LogContext | undefined;
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Execute a specific hook type with the provided context
|
|
1912
|
+
*
|
|
1913
|
+
* This is the main entry point for hook execution. It handles:
|
|
1914
|
+
* - Hook existence validation
|
|
1915
|
+
* - Sequential command execution
|
|
1916
|
+
* - Comprehensive logging with execution context
|
|
1917
|
+
* - Robust error handling (log but don't throw)
|
|
1918
|
+
* - Performance tracking
|
|
1919
|
+
*
|
|
1920
|
+
* @param hookType - The type of hook to execute
|
|
1921
|
+
* @param hooks - The complete hooks configuration
|
|
1922
|
+
* @param context - Execution context with iteration, session info, etc.
|
|
1923
|
+
* @param options - Additional execution options
|
|
1924
|
+
* @returns Promise that resolves when all commands complete (never throws)
|
|
1925
|
+
*
|
|
1926
|
+
* @example
|
|
1927
|
+
* ```typescript
|
|
1928
|
+
* const hooks = {
|
|
1929
|
+
* START_ITERATION: {
|
|
1930
|
+
* commands: ['echo "Starting iteration $ITERATION"', 'npm test']
|
|
1931
|
+
* }
|
|
1932
|
+
* };
|
|
1933
|
+
*
|
|
1934
|
+
* const context = {
|
|
1935
|
+
* iteration: 1,
|
|
1936
|
+
* sessionId: 'session-123',
|
|
1937
|
+
* workingDirectory: '/path/to/project'
|
|
1938
|
+
* };
|
|
1939
|
+
*
|
|
1940
|
+
* await executeHook('START_ITERATION', hooks, context);
|
|
1941
|
+
* ```
|
|
1942
|
+
*/
|
|
1943
|
+
declare function executeHook(hookType: HookType, hooks: HooksConfig, context?: HookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult>;
|
|
1944
|
+
/**
|
|
1945
|
+
* Execute multiple hooks in sequence
|
|
1946
|
+
*
|
|
1947
|
+
* Convenience function for executing multiple hooks with the same context.
|
|
1948
|
+
* Each hook is executed independently - failure of one hook does not stop
|
|
1949
|
+
* execution of subsequent hooks.
|
|
1950
|
+
*
|
|
1951
|
+
* @param hookTypes - Array of hook types to execute
|
|
1952
|
+
* @param hooks - The complete hooks configuration
|
|
1953
|
+
* @param context - Execution context
|
|
1954
|
+
* @param options - Execution options
|
|
1955
|
+
* @returns Promise resolving to array of hook execution results
|
|
1956
|
+
*/
|
|
1957
|
+
declare function executeHooks(hookTypes: HookType[], hooks: HooksConfig, context?: HookExecutionContext, options?: HookExecutionOptions): Promise<HookExecutionResult[]>;
|
|
1958
|
+
/**
|
|
1959
|
+
* Validate hooks configuration
|
|
1960
|
+
*
|
|
1961
|
+
* Checks that all hook configurations are valid and provides warnings
|
|
1962
|
+
* for common issues.
|
|
1963
|
+
*
|
|
1964
|
+
* @param hooks - Hooks configuration to validate
|
|
1965
|
+
* @returns Validation result with any issues found
|
|
1966
|
+
*/
|
|
1967
|
+
declare function validateHooksConfig(hooks: HooksConfig): {
|
|
1968
|
+
valid: boolean;
|
|
1969
|
+
issues: string[];
|
|
1970
|
+
warnings: string[];
|
|
1971
|
+
};
|
|
1972
|
+
|
|
1973
|
+
/**
|
|
1974
|
+
* Validation Utilities Module for juno-code
|
|
1975
|
+
*
|
|
1976
|
+
* Provides Zod-based validation for configuration values.
|
|
1977
|
+
*
|
|
1978
|
+
* @module utils/validation
|
|
1979
|
+
*/
|
|
1980
|
+
|
|
1981
|
+
/**
|
|
1982
|
+
* Schema for validating subagent types with alias support
|
|
1983
|
+
*/
|
|
1984
|
+
declare const SubagentSchema: z.ZodEffects<z.ZodEffects<z.ZodString, "claude" | "cursor" | "codex" | "gemini" | "pi", string>, SubagentType, string>;
|
|
1985
|
+
/**
|
|
1986
|
+
* Schema for validating log levels
|
|
1987
|
+
*/
|
|
1988
|
+
declare const LogLevelSchema: z.ZodEnum<["error", "warn", "info", "debug", "trace"]>;
|
|
1989
|
+
/**
|
|
1990
|
+
* Schema for validating session status
|
|
1991
|
+
*/
|
|
1992
|
+
declare const SessionStatusSchema: z.ZodEnum<["running", "completed", "failed", "cancelled"]>;
|
|
1993
|
+
/**
|
|
1994
|
+
* Schema for validating iteration counts
|
|
1995
|
+
*/
|
|
1996
|
+
declare const IterationsSchema: z.ZodEffects<z.ZodEffects<z.ZodNumber, number, number>, number, number>;
|
|
1997
|
+
/**
|
|
1998
|
+
* Schema for validating model names (subagent-specific)
|
|
1999
|
+
*/
|
|
2000
|
+
declare const ModelSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
2001
|
+
/**
|
|
2002
|
+
* Schema for runtime configuration validation
|
|
2003
|
+
*/
|
|
2004
|
+
declare const ConfigValidationSchema: z.ZodObject<{
|
|
2005
|
+
defaultSubagent: z.ZodEnum<["claude", "cursor", "codex", "gemini", "pi"]>;
|
|
2006
|
+
defaultBackend: z.ZodEnum<["shell"]>;
|
|
2007
|
+
defaultMaxIterations: z.ZodNumber;
|
|
2008
|
+
defaultModel: z.ZodOptional<z.ZodString>;
|
|
2009
|
+
mainTask: z.ZodOptional<z.ZodString>;
|
|
2010
|
+
logLevel: z.ZodEnum<["error", "warn", "info", "debug", "trace"]>;
|
|
2011
|
+
logFile: z.ZodOptional<z.ZodString>;
|
|
2012
|
+
verbose: z.ZodBoolean;
|
|
2013
|
+
quiet: z.ZodBoolean;
|
|
2014
|
+
mcpTimeout: z.ZodNumber;
|
|
2015
|
+
mcpRetries: z.ZodNumber;
|
|
2016
|
+
mcpServerPath: z.ZodOptional<z.ZodString>;
|
|
2017
|
+
mcpServerName: z.ZodOptional<z.ZodString>;
|
|
2018
|
+
hookCommandTimeout: z.ZodOptional<z.ZodNumber>;
|
|
2019
|
+
onHourlyLimit: z.ZodEnum<["wait", "raise"]>;
|
|
2020
|
+
interactive: z.ZodBoolean;
|
|
2021
|
+
headlessMode: z.ZodBoolean;
|
|
2022
|
+
workingDirectory: z.ZodString;
|
|
2023
|
+
sessionDirectory: z.ZodString;
|
|
2024
|
+
hooks: z.ZodOptional<z.ZodRecord<z.ZodEnum<["START_RUN", "START_ITERATION", "END_ITERATION", "END_RUN", "ON_STALE"]>, z.ZodObject<{
|
|
2025
|
+
commands: z.ZodArray<z.ZodString, "many">;
|
|
2026
|
+
}, "strip", z.ZodTypeAny, {
|
|
2027
|
+
commands?: string[];
|
|
2028
|
+
}, {
|
|
2029
|
+
commands?: string[];
|
|
2030
|
+
}>>>;
|
|
2031
|
+
skipHooks: z.ZodOptional<z.ZodBoolean>;
|
|
2032
|
+
}, "strict", z.ZodTypeAny, {
|
|
2033
|
+
defaultSubagent?: "claude" | "cursor" | "codex" | "gemini" | "pi";
|
|
2034
|
+
defaultBackend?: "shell";
|
|
2035
|
+
defaultMaxIterations?: number;
|
|
2036
|
+
defaultModel?: string;
|
|
2037
|
+
logLevel?: "error" | "warn" | "info" | "debug" | "trace";
|
|
2038
|
+
logFile?: string;
|
|
2039
|
+
verbose?: boolean;
|
|
2040
|
+
quiet?: boolean;
|
|
2041
|
+
mcpTimeout?: number;
|
|
2042
|
+
mcpRetries?: number;
|
|
2043
|
+
mcpServerPath?: string;
|
|
2044
|
+
mcpServerName?: string;
|
|
2045
|
+
hookCommandTimeout?: number;
|
|
2046
|
+
onHourlyLimit?: "wait" | "raise";
|
|
2047
|
+
interactive?: boolean;
|
|
2048
|
+
headlessMode?: boolean;
|
|
2049
|
+
workingDirectory?: string;
|
|
2050
|
+
sessionDirectory?: string;
|
|
2051
|
+
mainTask?: string;
|
|
2052
|
+
hooks?: Partial<Record<"START_RUN" | "START_ITERATION" | "END_ITERATION" | "END_RUN" | "ON_STALE", {
|
|
2053
|
+
commands?: string[];
|
|
2054
|
+
}>>;
|
|
2055
|
+
skipHooks?: boolean;
|
|
2056
|
+
}, {
|
|
2057
|
+
defaultSubagent?: "claude" | "cursor" | "codex" | "gemini" | "pi";
|
|
2058
|
+
defaultBackend?: "shell";
|
|
2059
|
+
defaultMaxIterations?: number;
|
|
2060
|
+
defaultModel?: string;
|
|
2061
|
+
logLevel?: "error" | "warn" | "info" | "debug" | "trace";
|
|
2062
|
+
logFile?: string;
|
|
2063
|
+
verbose?: boolean;
|
|
2064
|
+
quiet?: boolean;
|
|
2065
|
+
mcpTimeout?: number;
|
|
2066
|
+
mcpRetries?: number;
|
|
2067
|
+
mcpServerPath?: string;
|
|
2068
|
+
mcpServerName?: string;
|
|
2069
|
+
hookCommandTimeout?: number;
|
|
2070
|
+
onHourlyLimit?: "wait" | "raise";
|
|
2071
|
+
interactive?: boolean;
|
|
2072
|
+
headlessMode?: boolean;
|
|
2073
|
+
workingDirectory?: string;
|
|
2074
|
+
sessionDirectory?: string;
|
|
2075
|
+
mainTask?: string;
|
|
2076
|
+
hooks?: Partial<Record<"START_RUN" | "START_ITERATION" | "END_ITERATION" | "END_RUN" | "ON_STALE", {
|
|
2077
|
+
commands?: string[];
|
|
2078
|
+
}>>;
|
|
2079
|
+
skipHooks?: boolean;
|
|
2080
|
+
}>;
|
|
2081
|
+
/**
|
|
2082
|
+
* Validate and normalize subagent names including aliases
|
|
2083
|
+
*/
|
|
2084
|
+
declare function validateSubagent(subagent: string): SubagentType;
|
|
2085
|
+
/**
|
|
2086
|
+
* Validate model names for specific subagents
|
|
2087
|
+
*/
|
|
2088
|
+
declare function validateModel(model: string, _subagent?: SubagentType): string;
|
|
2089
|
+
/**
|
|
2090
|
+
* Validate iteration counts (positive integers or -1 for infinite)
|
|
2091
|
+
*/
|
|
2092
|
+
declare function validateIterations(iterations: number): number;
|
|
2093
|
+
/**
|
|
2094
|
+
* Validate log level strings
|
|
2095
|
+
*/
|
|
2096
|
+
declare function validateLogLevel(logLevel: string): LogLevel;
|
|
2097
|
+
/**
|
|
2098
|
+
* Environment variable validation
|
|
2099
|
+
*/
|
|
2100
|
+
declare function validateEnvironmentVars(envVars: Record<string, string | undefined>): Partial<JunoTaskConfig>;
|
|
2101
|
+
|
|
2102
|
+
/**
|
|
2103
|
+
* Version information for juno-task-ts
|
|
2104
|
+
*/
|
|
2105
|
+
declare const version: string;
|
|
2106
|
+
|
|
2107
|
+
export { type Architecture, type BackendType, type CleanupOptions, type ColorSupport, type CommandExecutionResult, type ConfigLoadOptions, ConfigLoader, ConfigValidationSchema, type CpuUsage, DEFAULT_CONFIG, DEFAULT_ERROR_RECOVERY_CONFIG, DEFAULT_HOOKS, DEFAULT_PROGRESS_CONFIG, DEFAULT_RATE_LIMIT_CONFIG, ENV_VAR_MAPPING, type EnvVarMapping, type ErrorRecoveryConfig, ExecutionEngine, type ExecutionEngineConfig, type ExecutionRequest, type ExecutionResult, type ExecutionStatistics, ExecutionStatus, FileSessionStorage, type Hook$1 as Hook, type HookExecutionContext, type HookExecutionOptions, type HookExecutionResult, type HookType$1 as HookType, type Hooks, type HooksConfig, type IterationResult, IterationsSchema, type JunoTaskConfig, JunoTaskConfigSchema, type LogLevel, LogLevelSchema, type MCPServerEnvironment, type MemoryUsage, ModelSchema, type NodeEnvironment, type OnHourlyLimit, type PerformanceMetrics, type Platform, type ProcessInfo, type ProgressEventFilter, type ProgressEventProcessor, type ProgressEventType$1 as ProgressEventType, type ProgressTrackingConfig, type RateLimitHandlingConfig, type RateLimitInfo, type RateLimitParser, type Session, type SessionHistoryEntry, type SessionInfo, type SessionListFilter, SessionManager, type SessionStatistics, type SessionStatus, SessionStatusSchema, type SessionStorage, type ShellType, SubagentSchema, type SubagentType, type ThroughputMetrics, createDirectoryIfNotExists, createExecutionEngine, createExecutionRequest, createSessionManager, executeHook, executeHooks, findMCPServerPath, getArchitecture, getCacheDirectory, getColorSupport, getConfigDirectory, getCpuUsage, getDataDirectory, getDefaultHooks, getDefaultHooksJson, getEnvVar, getEnvVarWithDefault, getHomeDirectory, getMCPServerEnvironment, getMemoryUsage, getNodeEnvironment, getPlatform, getProcessInfo, getShell, getTempDirectory, getTerminalHeight, getTerminalWidth, isCIEnvironment, isDevelopmentMode, isHeadlessEnvironment, isInDocker, isInteractiveTerminal, isRunningAsRoot, loadConfig, parseEnvArray, parseEnvBoolean, parseEnvNumber, setEnvVar, supportsColor, validateConfig, validateEnvironmentVars, validateHooksConfig, validateIterations, validateLogLevel, validateMCPServerPath, validateModel, validateSubagent, version };
|