@sudocode-ai/local-server 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +105 -0
- package/dist/cli.js.map +7 -0
- package/dist/execution/engine/engine.d.ts +103 -0
- package/dist/execution/engine/engine.d.ts.map +1 -0
- package/dist/execution/engine/simple-engine.d.ts +190 -0
- package/dist/execution/engine/simple-engine.d.ts.map +1 -0
- package/dist/execution/engine/types.d.ts +116 -0
- package/dist/execution/engine/types.d.ts.map +1 -0
- package/dist/execution/output/ag-ui-adapter.d.ts +176 -0
- package/dist/execution/output/ag-ui-adapter.d.ts.map +1 -0
- package/dist/execution/output/ag-ui-integration.d.ts +96 -0
- package/dist/execution/output/ag-ui-integration.d.ts.map +1 -0
- package/dist/execution/output/claude-code-output-processor.d.ts +321 -0
- package/dist/execution/output/claude-code-output-processor.d.ts.map +1 -0
- package/dist/execution/output/index.d.ts +18 -0
- package/dist/execution/output/index.d.ts.map +1 -0
- package/dist/execution/output/types.d.ts +421 -0
- package/dist/execution/output/types.d.ts.map +1 -0
- package/dist/execution/process/builders/claude.d.ts +86 -0
- package/dist/execution/process/builders/claude.d.ts.map +1 -0
- package/dist/execution/process/index.d.ts +15 -0
- package/dist/execution/process/index.d.ts.map +1 -0
- package/dist/execution/process/manager.d.ts +133 -0
- package/dist/execution/process/manager.d.ts.map +1 -0
- package/dist/execution/process/simple-manager.d.ts +102 -0
- package/dist/execution/process/simple-manager.d.ts.map +1 -0
- package/dist/execution/process/types.d.ts +105 -0
- package/dist/execution/process/types.d.ts.map +1 -0
- package/dist/execution/process/utils.d.ts +53 -0
- package/dist/execution/process/utils.d.ts.map +1 -0
- package/dist/execution/resilience/circuit-breaker.d.ts +170 -0
- package/dist/execution/resilience/circuit-breaker.d.ts.map +1 -0
- package/dist/execution/resilience/executor.d.ts +109 -0
- package/dist/execution/resilience/executor.d.ts.map +1 -0
- package/dist/execution/resilience/index.d.ts +14 -0
- package/dist/execution/resilience/index.d.ts.map +1 -0
- package/dist/execution/resilience/resilient-executor.d.ts +86 -0
- package/dist/execution/resilience/resilient-executor.d.ts.map +1 -0
- package/dist/execution/resilience/retry.d.ts +161 -0
- package/dist/execution/resilience/retry.d.ts.map +1 -0
- package/dist/execution/resilience/types.d.ts +226 -0
- package/dist/execution/resilience/types.d.ts.map +1 -0
- package/dist/execution/transport/event-buffer.d.ts +119 -0
- package/dist/execution/transport/event-buffer.d.ts.map +1 -0
- package/dist/execution/transport/index.d.ts +10 -0
- package/dist/execution/transport/index.d.ts.map +1 -0
- package/dist/execution/transport/sse-transport.d.ts +146 -0
- package/dist/execution/transport/sse-transport.d.ts.map +1 -0
- package/dist/execution/transport/transport-manager.d.ts +176 -0
- package/dist/execution/transport/transport-manager.d.ts.map +1 -0
- package/dist/execution/workflow/index.d.ts +13 -0
- package/dist/execution/workflow/index.d.ts.map +1 -0
- package/dist/execution/workflow/linear-orchestrator.d.ts +216 -0
- package/dist/execution/workflow/linear-orchestrator.d.ts.map +1 -0
- package/dist/execution/workflow/memory-storage.d.ts +54 -0
- package/dist/execution/workflow/memory-storage.d.ts.map +1 -0
- package/dist/execution/workflow/orchestrator.d.ts +158 -0
- package/dist/execution/workflow/orchestrator.d.ts.map +1 -0
- package/dist/execution/workflow/types.d.ts +172 -0
- package/dist/execution/workflow/types.d.ts.map +1 -0
- package/dist/execution/workflow/utils.d.ts +89 -0
- package/dist/execution/workflow/utils.d.ts.map +1 -0
- package/dist/execution/worktree/config.d.ts +74 -0
- package/dist/execution/worktree/config.d.ts.map +1 -0
- package/dist/execution/worktree/git-cli.d.ts +151 -0
- package/dist/execution/worktree/git-cli.d.ts.map +1 -0
- package/dist/execution/worktree/index.d.ts +16 -0
- package/dist/execution/worktree/index.d.ts.map +1 -0
- package/dist/execution/worktree/manager.d.ts +184 -0
- package/dist/execution/worktree/manager.d.ts.map +1 -0
- package/dist/execution/worktree/types.d.ts +90 -0
- package/dist/execution/worktree/types.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +104 -0
- package/dist/index.js.map +7 -0
- package/dist/public/assets/index-C4SmlXoo.js +568 -0
- package/dist/public/assets/index-C4SmlXoo.js.map +1 -0
- package/dist/public/assets/index-DE59j7ti.css +1 -0
- package/dist/public/assets/react-vendor-LX0UoTxg.js +60 -0
- package/dist/public/assets/react-vendor-LX0UoTxg.js.map +1 -0
- package/dist/public/assets/ui-vendor-_cxVHaqZ.js +54 -0
- package/dist/public/assets/ui-vendor-_cxVHaqZ.js.map +1 -0
- package/dist/public/favicon.ico +0 -0
- package/dist/public/index.html +16 -0
- package/dist/public/logo.png +0 -0
- package/dist/routes/executions-stream.d.ts +24 -0
- package/dist/routes/executions-stream.d.ts.map +1 -0
- package/dist/routes/executions.d.ts +19 -0
- package/dist/routes/executions.d.ts.map +1 -0
- package/dist/routes/feedback.d.ts +7 -0
- package/dist/routes/feedback.d.ts.map +1 -0
- package/dist/routes/issues.d.ts +7 -0
- package/dist/routes/issues.d.ts.map +1 -0
- package/dist/routes/relationships.d.ts +7 -0
- package/dist/routes/relationships.d.ts.map +1 -0
- package/dist/routes/specs.d.ts +7 -0
- package/dist/routes/specs.d.ts.map +1 -0
- package/dist/services/db.d.ts +33 -0
- package/dist/services/db.d.ts.map +1 -0
- package/dist/services/execution-lifecycle.d.ts +108 -0
- package/dist/services/execution-lifecycle.d.ts.map +1 -0
- package/dist/services/execution-service.d.ts +185 -0
- package/dist/services/execution-service.d.ts.map +1 -0
- package/dist/services/executions.d.ts +59 -0
- package/dist/services/executions.d.ts.map +1 -0
- package/dist/services/export.d.ts +24 -0
- package/dist/services/export.d.ts.map +1 -0
- package/dist/services/feedback.d.ts +40 -0
- package/dist/services/feedback.d.ts.map +1 -0
- package/dist/services/issues.d.ts +27 -0
- package/dist/services/issues.d.ts.map +1 -0
- package/dist/services/prompt-template-engine.d.ts +108 -0
- package/dist/services/prompt-template-engine.d.ts.map +1 -0
- package/dist/services/prompt-templates.d.ts +97 -0
- package/dist/services/prompt-templates.d.ts.map +1 -0
- package/dist/services/relationships.d.ts +35 -0
- package/dist/services/relationships.d.ts.map +1 -0
- package/dist/services/specs.d.ts +27 -0
- package/dist/services/specs.d.ts.map +1 -0
- package/dist/services/watcher.d.ts +50 -0
- package/dist/services/watcher.d.ts.map +1 -0
- package/dist/services/websocket.d.ts +127 -0
- package/dist/services/websocket.d.ts.map +1 -0
- package/dist/utils/sudocode-dir.d.ts +6 -0
- package/dist/utils/sudocode-dir.d.ts.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Process Manager Implementation
|
|
3
|
+
*
|
|
4
|
+
* A straightforward implementation of IProcessManager that spawns a fresh
|
|
5
|
+
* process for each task. This is the "simple first" approach that will later
|
|
6
|
+
* be upgraded to support process pooling.
|
|
7
|
+
*
|
|
8
|
+
* Supports any CLI tool/agent (Claude Code, Codex, Gemini CLI, etc.)
|
|
9
|
+
*
|
|
10
|
+
* Key features:
|
|
11
|
+
* - One process per task (no pooling)
|
|
12
|
+
* - Event-based I/O streaming
|
|
13
|
+
* - Graceful termination (SIGTERM → SIGKILL)
|
|
14
|
+
* - Automatic cleanup
|
|
15
|
+
* - Metrics tracking
|
|
16
|
+
* - Agent-agnostic design
|
|
17
|
+
*
|
|
18
|
+
* @module execution/process/simple-manager
|
|
19
|
+
*/
|
|
20
|
+
import type { ManagedProcess, ProcessConfig, ProcessMetrics, OutputHandler, ErrorHandler } from "./types.js";
|
|
21
|
+
import type { IProcessManager } from "./manager.js";
|
|
22
|
+
/**
|
|
23
|
+
* Simple process manager that spawns one process per task
|
|
24
|
+
*
|
|
25
|
+
* This implementation follows the "simple first" principle - it provides
|
|
26
|
+
* a production-ready process manager without the complexity of pooling.
|
|
27
|
+
*
|
|
28
|
+
* Works with any CLI tool/agent by accepting executable path and args.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Claude Code example
|
|
33
|
+
* const manager = new SimpleProcessManager({
|
|
34
|
+
* executablePath: 'claude',
|
|
35
|
+
* args: ['--print', '--output-format', 'stream-json'],
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const process = await manager.acquireProcess({
|
|
39
|
+
* executablePath: 'claude',
|
|
40
|
+
* args: ['--print', '--output-format', 'stream-json'],
|
|
41
|
+
* workDir: '/path/to/project',
|
|
42
|
+
* timeout: 300000,
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // Codex example
|
|
46
|
+
* const codexProcess = await manager.acquireProcess({
|
|
47
|
+
* executablePath: 'codex',
|
|
48
|
+
* args: ['--mode', 'agent', '--json'],
|
|
49
|
+
* workDir: '/path/to/project',
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class SimpleProcessManager implements IProcessManager {
|
|
54
|
+
private readonly _defaultConfig;
|
|
55
|
+
private _activeProcesses;
|
|
56
|
+
private _cleanupTimers;
|
|
57
|
+
private _metrics;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new SimpleProcessManager
|
|
60
|
+
*
|
|
61
|
+
* @param defaultConfig - Default configuration to merge with per-process config
|
|
62
|
+
*/
|
|
63
|
+
constructor(_defaultConfig?: Partial<ProcessConfig>);
|
|
64
|
+
acquireProcess(config: ProcessConfig): Promise<ManagedProcess>;
|
|
65
|
+
/**
|
|
66
|
+
* Spawn a process with the given configuration
|
|
67
|
+
*
|
|
68
|
+
* @param config - Process configuration
|
|
69
|
+
* @returns ChildProcess instance
|
|
70
|
+
*/
|
|
71
|
+
private spawnProcess;
|
|
72
|
+
/**
|
|
73
|
+
* Set up event handlers for a managed process
|
|
74
|
+
*
|
|
75
|
+
* Handles lifecycle events:
|
|
76
|
+
* - exit: Process terminated normally or abnormally
|
|
77
|
+
* - error: Process encountered an error
|
|
78
|
+
* - stdout/stderr data: Track activity for idle detection
|
|
79
|
+
*
|
|
80
|
+
* @param managedProcess - The managed process to set up handlers for
|
|
81
|
+
* @param config - Process configuration (for timeout)
|
|
82
|
+
*/
|
|
83
|
+
private setupProcessHandlers;
|
|
84
|
+
releaseProcess(processId: string): Promise<void>;
|
|
85
|
+
terminateProcess(processId: string, signal?: NodeJS.Signals): Promise<void>;
|
|
86
|
+
sendInput(processId: string, input: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Close stdin stream for a process
|
|
89
|
+
*
|
|
90
|
+
* Signals EOF to the process, useful for programs that wait for stdin to close.
|
|
91
|
+
*
|
|
92
|
+
* @param processId - ID of the process
|
|
93
|
+
*/
|
|
94
|
+
closeInput(processId: string): void;
|
|
95
|
+
onOutput(processId: string, handler: OutputHandler): void;
|
|
96
|
+
onError(processId: string, handler: ErrorHandler): void;
|
|
97
|
+
getProcess(processId: string): ManagedProcess | null;
|
|
98
|
+
getActiveProcesses(): ManagedProcess[];
|
|
99
|
+
getMetrics(): ProcessMetrics;
|
|
100
|
+
shutdown(): Promise<void>;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=simple-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simple-manager.d.ts","sourceRoot":"","sources":["../../../src/execution/process/simple-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,oBAAqB,YAAW,eAAe;IAgB9C,OAAO,CAAC,QAAQ,CAAC,cAAc;IAf3C,OAAO,CAAC,gBAAgB,CAAqC;IAC7D,OAAO,CAAC,cAAc,CAAqC;IAC3D,OAAO,CAAC,QAAQ,CAMd;IAEF;;;;OAIG;gBAC0B,cAAc,GAAE,OAAO,CAAC,aAAa,CAAM;IAElE,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAsDpE;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAapB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,oBAAoB;IA8FtB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD,gBAAgB,CACpB,SAAS,EAAE,MAAM,EACjB,MAAM,GAAE,MAAM,CAAC,OAAmB,GACjC,OAAO,CAAC,IAAI,CAAC;IAkDV,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAchE;;;;;;OAMG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IASnC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI;IAezD,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAWvD,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAIpD,kBAAkB,IAAI,cAAc,EAAE;IAItC,UAAU,IAAI,cAAc;IAKtB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAahC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process Layer Types
|
|
3
|
+
*
|
|
4
|
+
* Core types and interfaces for the Process Layer (Layer 1) of the execution system.
|
|
5
|
+
* Defines generic types for managing any CLI tool/agent process lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* @module execution/process/types
|
|
8
|
+
*/
|
|
9
|
+
import type { ChildProcess } from 'child_process';
|
|
10
|
+
import type { Readable, Writable } from 'stream';
|
|
11
|
+
/**
|
|
12
|
+
* Status of a managed process throughout its lifecycle
|
|
13
|
+
*/
|
|
14
|
+
export type ProcessStatus = 'spawning' | 'idle' | 'busy' | 'terminating' | 'crashed' | 'completed';
|
|
15
|
+
/**
|
|
16
|
+
* Configuration for spawning a new process
|
|
17
|
+
* Generic interface that works with any CLI tool/agent
|
|
18
|
+
*/
|
|
19
|
+
export interface ProcessConfig {
|
|
20
|
+
/** Path to the executable (e.g., 'claude', 'codex', 'node') */
|
|
21
|
+
executablePath: string;
|
|
22
|
+
/** Command-line arguments to pass to the executable */
|
|
23
|
+
args: string[];
|
|
24
|
+
/** Working directory for the process */
|
|
25
|
+
workDir: string;
|
|
26
|
+
/** Environment variables to pass to the process */
|
|
27
|
+
env?: Record<string, string>;
|
|
28
|
+
/** Maximum execution time in milliseconds */
|
|
29
|
+
timeout?: number;
|
|
30
|
+
/** Maximum idle time before cleanup (pool only) */
|
|
31
|
+
idleTimeout?: number;
|
|
32
|
+
/** Retry configuration for failed spawns */
|
|
33
|
+
retry?: {
|
|
34
|
+
/** Maximum number of retry attempts */
|
|
35
|
+
maxAttempts: number;
|
|
36
|
+
/** Initial backoff delay in milliseconds */
|
|
37
|
+
backoffMs: number;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Represents a single managed process instance with its lifecycle state
|
|
42
|
+
* Can be any CLI tool/agent (Claude Code, Codex, Gemini CLI, etc.)
|
|
43
|
+
*/
|
|
44
|
+
export interface ManagedProcess {
|
|
45
|
+
/** Unique process identifier */
|
|
46
|
+
id: string;
|
|
47
|
+
/** Operating system process ID */
|
|
48
|
+
pid: number;
|
|
49
|
+
/** Current status of the process */
|
|
50
|
+
status: ProcessStatus;
|
|
51
|
+
/** When the process was spawned */
|
|
52
|
+
spawnedAt: Date;
|
|
53
|
+
/** Last I/O activity timestamp */
|
|
54
|
+
lastActivity: Date;
|
|
55
|
+
/** Exit code if process has exited */
|
|
56
|
+
exitCode: number | null;
|
|
57
|
+
/** Signal that terminated the process if applicable */
|
|
58
|
+
signal: string | null;
|
|
59
|
+
/** Node.js ChildProcess handle */
|
|
60
|
+
process: ChildProcess;
|
|
61
|
+
/** Process I/O streams */
|
|
62
|
+
streams: {
|
|
63
|
+
stdout: Readable;
|
|
64
|
+
stderr: Readable;
|
|
65
|
+
stdin: Writable;
|
|
66
|
+
};
|
|
67
|
+
/** Process execution metrics */
|
|
68
|
+
metrics: {
|
|
69
|
+
/** Total duration in milliseconds */
|
|
70
|
+
totalDuration: number;
|
|
71
|
+
/** Number of tasks completed */
|
|
72
|
+
tasksCompleted: number;
|
|
73
|
+
/** Success rate (0-1) */
|
|
74
|
+
successRate: number;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Handler for process output (stdout/stderr)
|
|
79
|
+
*
|
|
80
|
+
* @param data - Output data buffer
|
|
81
|
+
* @param type - Stream type
|
|
82
|
+
*/
|
|
83
|
+
export type OutputHandler = (data: Buffer, type: 'stdout' | 'stderr') => void;
|
|
84
|
+
/**
|
|
85
|
+
* Handler for process errors
|
|
86
|
+
*
|
|
87
|
+
* @param error - Error that occurred
|
|
88
|
+
*/
|
|
89
|
+
export type ErrorHandler = (error: Error) => void;
|
|
90
|
+
/**
|
|
91
|
+
* Aggregate metrics for all processes managed by a ProcessManager
|
|
92
|
+
*/
|
|
93
|
+
export interface ProcessMetrics {
|
|
94
|
+
/** Total number of processes spawned */
|
|
95
|
+
totalSpawned: number;
|
|
96
|
+
/** Number of currently active processes */
|
|
97
|
+
currentlyActive: number;
|
|
98
|
+
/** Total number of successfully completed processes */
|
|
99
|
+
totalCompleted: number;
|
|
100
|
+
/** Total number of failed processes */
|
|
101
|
+
totalFailed: number;
|
|
102
|
+
/** Average process duration in milliseconds */
|
|
103
|
+
averageDuration: number;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/execution/process/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,UAAU,GACV,MAAM,GACN,MAAM,GACN,aAAa,GACb,SAAS,GACT,WAAW,CAAC;AAEhB;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,cAAc,EAAE,MAAM,CAAC;IAEvB,uDAAuD;IACvD,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAEhB,mDAAmD;IACnD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE7B,6CAA6C;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,4CAA4C;IAC5C,KAAK,CAAC,EAAE;QACN,uCAAuC;QACvC,WAAW,EAAE,MAAM,CAAC;QACpB,4CAA4C;QAC5C,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAE7B,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IAGZ,oCAAoC;IACpC,MAAM,EAAE,aAAa,CAAC;IACtB,mCAAmC;IACnC,SAAS,EAAE,IAAI,CAAC;IAChB,kCAAkC;IAClC,YAAY,EAAE,IAAI,CAAC;IACnB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,uDAAuD;IACvD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAGtB,kCAAkC;IAClC,OAAO,EAAE,YAAY,CAAC;IACtB,0BAA0B;IAC1B,OAAO,EAAE;QACP,MAAM,EAAE,QAAQ,CAAC;QACjB,MAAM,EAAE,QAAQ,CAAC;QACjB,KAAK,EAAE,QAAQ,CAAC;KACjB,CAAC;IAGF,gCAAgC;IAChC,OAAO,EAAE;QACP,qCAAqC;QACrC,aAAa,EAAE,MAAM,CAAC;QACtB,gCAAgC;QAChC,cAAc,EAAE,MAAM,CAAC;QACvB,yBAAyB;QACzB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,GAAG,QAAQ,KAAK,IAAI,CAAC;AAE9E;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,eAAe,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,cAAc,EAAE,MAAM,CAAC;IACvB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,eAAe,EAAE,MAAM,CAAC;CACzB"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process Layer Utilities
|
|
3
|
+
*
|
|
4
|
+
* Helper functions for the Process Layer including ID generation,
|
|
5
|
+
* formatting, and validation utilities.
|
|
6
|
+
*
|
|
7
|
+
* @module execution/process/utils
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Generate a unique process ID with a prefix
|
|
11
|
+
*
|
|
12
|
+
* Creates URL-safe, unique identifiers for processes. Uses nanoid for
|
|
13
|
+
* cryptographically strong random IDs.
|
|
14
|
+
*
|
|
15
|
+
* @param prefix - Prefix for the ID (e.g., 'process', 'task')
|
|
16
|
+
* @returns Unique ID string in format: `{prefix}-{randomId}`
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const id = generateId('process');
|
|
21
|
+
* // Returns: 'process-a1b2c3d4'
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateId(prefix: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Format duration in milliseconds to human-readable string
|
|
27
|
+
*
|
|
28
|
+
* @param ms - Duration in milliseconds
|
|
29
|
+
* @returns Formatted duration string
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* formatDuration(1500); // "1.5s"
|
|
34
|
+
* formatDuration(65000); // "1m 5s"
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatDuration(ms: number): string;
|
|
38
|
+
/**
|
|
39
|
+
* Validate that a signal name is valid for Node.js
|
|
40
|
+
*
|
|
41
|
+
* @param signal - Signal name to validate
|
|
42
|
+
* @returns True if signal is valid
|
|
43
|
+
*/
|
|
44
|
+
export declare function isValidSignal(signal: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Format error message from process exit
|
|
47
|
+
*
|
|
48
|
+
* @param exitCode - Process exit code
|
|
49
|
+
* @param signal - Signal that terminated the process
|
|
50
|
+
* @returns Formatted error message
|
|
51
|
+
*/
|
|
52
|
+
export declare function formatProcessError(exitCode: number | null, signal: string | null): string;
|
|
53
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/execution/process/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKjD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAuBjD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAUrD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,MAAM,EAAE,MAAM,GAAG,IAAI,GACpB,MAAM,CAQR"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Circuit Breaker Implementation
|
|
3
|
+
*
|
|
4
|
+
* Implements the circuit breaker pattern for preventing cascading failures.
|
|
5
|
+
* Tracks failures and successes, automatically opening when thresholds are
|
|
6
|
+
* exceeded and recovering through half-open state.
|
|
7
|
+
*
|
|
8
|
+
* @module execution/resilience/circuit-breaker
|
|
9
|
+
*/
|
|
10
|
+
import type { CircuitBreaker, CircuitState } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* CircuitBreakerManager - Manages multiple circuit breakers
|
|
13
|
+
*
|
|
14
|
+
* Maintains a collection of circuit breakers, typically one per task type
|
|
15
|
+
* or service. Provides methods for checking state, recording outcomes,
|
|
16
|
+
* and managing circuit lifecycle.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const manager = new CircuitBreakerManager();
|
|
21
|
+
* const breaker = manager.getOrCreate('issue-executor', {
|
|
22
|
+
* failureThreshold: 5,
|
|
23
|
+
* successThreshold: 2,
|
|
24
|
+
* timeout: 60000,
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* if (manager.canExecute('issue-executor')) {
|
|
28
|
+
* // Execute task
|
|
29
|
+
* const success = await executeTask();
|
|
30
|
+
* if (success) {
|
|
31
|
+
* manager.recordSuccess('issue-executor');
|
|
32
|
+
* } else {
|
|
33
|
+
* manager.recordFailure('issue-executor', new Error('Task failed'));
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class CircuitBreakerManager {
|
|
39
|
+
private breakers;
|
|
40
|
+
/**
|
|
41
|
+
* Get an existing circuit breaker by name
|
|
42
|
+
*
|
|
43
|
+
* @param name - Circuit breaker name
|
|
44
|
+
* @returns Circuit breaker or null if not found
|
|
45
|
+
*/
|
|
46
|
+
get(name: string): CircuitBreaker | null;
|
|
47
|
+
/**
|
|
48
|
+
* Get or create a circuit breaker
|
|
49
|
+
*
|
|
50
|
+
* If a circuit breaker with the given name exists, returns it.
|
|
51
|
+
* Otherwise creates a new one with the provided configuration.
|
|
52
|
+
*
|
|
53
|
+
* @param name - Circuit breaker name (typically task type)
|
|
54
|
+
* @param config - Configuration for new circuit breaker
|
|
55
|
+
* @returns Circuit breaker instance
|
|
56
|
+
*/
|
|
57
|
+
getOrCreate(name: string, config?: CircuitBreaker['config']): CircuitBreaker;
|
|
58
|
+
/**
|
|
59
|
+
* Check if a circuit breaker allows execution
|
|
60
|
+
*
|
|
61
|
+
* Returns false if circuit is open and timeout hasn't elapsed yet.
|
|
62
|
+
* Returns true for closed and half-open states.
|
|
63
|
+
*
|
|
64
|
+
* @param name - Circuit breaker name
|
|
65
|
+
* @returns True if execution is allowed
|
|
66
|
+
*/
|
|
67
|
+
canExecute(name: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Record a successful execution
|
|
70
|
+
*
|
|
71
|
+
* Updates metrics and may transition circuit from half-open to closed
|
|
72
|
+
* if success threshold is met.
|
|
73
|
+
*
|
|
74
|
+
* @param name - Circuit breaker name
|
|
75
|
+
*/
|
|
76
|
+
recordSuccess(name: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* Record a failed execution
|
|
79
|
+
*
|
|
80
|
+
* Updates metrics and may transition circuit from closed/half-open to open
|
|
81
|
+
* if failure threshold is met.
|
|
82
|
+
*
|
|
83
|
+
* @param name - Circuit breaker name
|
|
84
|
+
* @param error - Error that occurred
|
|
85
|
+
*/
|
|
86
|
+
recordFailure(name: string, error: Error): void;
|
|
87
|
+
/**
|
|
88
|
+
* Reset a circuit breaker to closed state
|
|
89
|
+
*
|
|
90
|
+
* Clears all failure counts and returns circuit to closed state.
|
|
91
|
+
* Useful for manual recovery or after fixing underlying issues.
|
|
92
|
+
*
|
|
93
|
+
* @param name - Circuit breaker name
|
|
94
|
+
*/
|
|
95
|
+
reset(name: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Get all circuit breakers
|
|
98
|
+
*
|
|
99
|
+
* @returns Map of circuit breaker name to breaker instance
|
|
100
|
+
*/
|
|
101
|
+
getAll(): Map<string, CircuitBreaker>;
|
|
102
|
+
/**
|
|
103
|
+
* Check if enough time has passed to transition from open to half-open
|
|
104
|
+
*
|
|
105
|
+
* @param breaker - Circuit breaker to check
|
|
106
|
+
* @returns True if timeout has elapsed
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
private shouldTransitionToHalfOpen;
|
|
110
|
+
/**
|
|
111
|
+
* Get count of consecutive successes
|
|
112
|
+
*
|
|
113
|
+
* In a production implementation, this would track a sliding window
|
|
114
|
+
* of recent attempts. For simplicity, we use total successful requests.
|
|
115
|
+
*
|
|
116
|
+
* @param breaker - Circuit breaker to check
|
|
117
|
+
* @returns Number of consecutive successes
|
|
118
|
+
* @private
|
|
119
|
+
*/
|
|
120
|
+
private getConsecutiveSuccesses;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a new circuit breaker instance
|
|
124
|
+
*
|
|
125
|
+
* Helper function to create a properly configured circuit breaker.
|
|
126
|
+
*
|
|
127
|
+
* @param name - Circuit breaker name
|
|
128
|
+
* @param config - Circuit breaker configuration
|
|
129
|
+
* @returns New circuit breaker instance
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const breaker = createCircuitBreaker('api-calls', {
|
|
134
|
+
* failureThreshold: 10,
|
|
135
|
+
* successThreshold: 3,
|
|
136
|
+
* timeout: 30000,
|
|
137
|
+
* });
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function createCircuitBreaker(name: string, config?: CircuitBreaker['config']): CircuitBreaker;
|
|
141
|
+
/**
|
|
142
|
+
* Check if a circuit breaker is in a specific state
|
|
143
|
+
*
|
|
144
|
+
* @param breaker - Circuit breaker to check
|
|
145
|
+
* @param state - State to check for
|
|
146
|
+
* @returns True if breaker is in the specified state
|
|
147
|
+
*/
|
|
148
|
+
export declare function isInState(breaker: CircuitBreaker, state: CircuitState): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Get the current state of a circuit breaker
|
|
151
|
+
*
|
|
152
|
+
* @param breaker - Circuit breaker to check
|
|
153
|
+
* @returns Current state
|
|
154
|
+
*/
|
|
155
|
+
export declare function getState(breaker: CircuitBreaker): CircuitState;
|
|
156
|
+
/**
|
|
157
|
+
* Calculate failure rate for a circuit breaker
|
|
158
|
+
*
|
|
159
|
+
* @param breaker - Circuit breaker to analyze
|
|
160
|
+
* @returns Failure rate (0-1) or 0 if no requests
|
|
161
|
+
*/
|
|
162
|
+
export declare function getFailureRate(breaker: CircuitBreaker): number;
|
|
163
|
+
/**
|
|
164
|
+
* Calculate success rate for a circuit breaker
|
|
165
|
+
*
|
|
166
|
+
* @param breaker - Circuit breaker to analyze
|
|
167
|
+
* @returns Success rate (0-1) or 0 if no requests
|
|
168
|
+
*/
|
|
169
|
+
export declare function getSuccessRate(breaker: CircuitBreaker): number;
|
|
170
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../../src/execution/resilience/circuit-breaker.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAqC;IAErD;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAIxC;;;;;;;;;OASG;IACH,WAAW,CACT,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,cAAc,CAAC,QAAQ,CAI9B,GACA,cAAc;IAqBjB;;;;;;;;OAQG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAkBjC;;;;;;;OAOG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAuBjC;;;;;;;;OAQG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAuB/C;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAWzB;;;;OAIG;IACH,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC;IAIrC;;;;;;OAMG;IACH,OAAO,CAAC,0BAA0B;IAWlC;;;;;;;;;OASG;IACH,OAAO,CAAC,uBAAuB;CAKhC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,cAAc,CAAC,QAAQ,CAI9B,GACA,cAAc,CAWhB;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,cAAc,EACvB,KAAK,EAAE,YAAY,GAClB,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,YAAY,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAM9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAM9D"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resilient Executor Interface
|
|
3
|
+
*
|
|
4
|
+
* Core abstraction for resilient task execution. Provides methods for
|
|
5
|
+
* executing tasks with retry logic, circuit breakers, and fault tolerance.
|
|
6
|
+
*
|
|
7
|
+
* @module execution/resilience/executor
|
|
8
|
+
*/
|
|
9
|
+
import type { ExecutionTask } from '../engine/types.js';
|
|
10
|
+
import type { RetryPolicy, CircuitBreaker, RetryMetrics, ResilientExecutionResult, RetryAttemptHandler, CircuitOpenHandler } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* IResilientExecutor - Interface for resilient task execution
|
|
13
|
+
*
|
|
14
|
+
* Defines the contract for executors that add resilience patterns
|
|
15
|
+
* (retry, circuit breaker) to task execution. Implementations wrap
|
|
16
|
+
* the Engine Layer with fault tolerance mechanisms.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const executor = new ResilientExecutor(engine, {
|
|
21
|
+
* maxAttempts: 3,
|
|
22
|
+
* backoff: {
|
|
23
|
+
* type: 'exponential',
|
|
24
|
+
* baseDelayMs: 1000,
|
|
25
|
+
* maxDelayMs: 30000,
|
|
26
|
+
* jitter: true,
|
|
27
|
+
* },
|
|
28
|
+
* retryableErrors: ['timeout', 'ECONNREFUSED'],
|
|
29
|
+
* retryableExitCodes: [1],
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* const result = await executor.executeTask(task);
|
|
33
|
+
* console.log(`Success after ${result.totalAttempts} attempts`);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface IResilientExecutor {
|
|
37
|
+
/**
|
|
38
|
+
* Execute a single task with retry and circuit breaker
|
|
39
|
+
*
|
|
40
|
+
* Attempts to execute the task, retrying on transient failures according
|
|
41
|
+
* to the retry policy. Checks circuit breaker before execution to prevent
|
|
42
|
+
* cascading failures.
|
|
43
|
+
*
|
|
44
|
+
* @param task - The task to execute
|
|
45
|
+
* @param policy - Optional retry policy (uses default if not provided)
|
|
46
|
+
* @returns Promise resolving to enhanced result with retry information
|
|
47
|
+
* @throws Error if circuit breaker is open or max retries exceeded
|
|
48
|
+
*/
|
|
49
|
+
executeTask(task: ExecutionTask, policy?: RetryPolicy): Promise<ResilientExecutionResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Execute multiple tasks with retry and circuit breaker
|
|
52
|
+
*
|
|
53
|
+
* Executes all tasks in parallel, each with its own retry logic.
|
|
54
|
+
* Tasks of the same type share a circuit breaker.
|
|
55
|
+
*
|
|
56
|
+
* @param tasks - Array of tasks to execute
|
|
57
|
+
* @param policy - Optional retry policy for all tasks
|
|
58
|
+
* @returns Promise resolving to array of enhanced results
|
|
59
|
+
*/
|
|
60
|
+
executeTasks(tasks: ExecutionTask[], policy?: RetryPolicy): Promise<ResilientExecutionResult[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Get circuit breaker by name
|
|
63
|
+
*
|
|
64
|
+
* Circuit breakers are typically named by task type (e.g., 'issue', 'spec').
|
|
65
|
+
* Returns null if no circuit breaker exists for the given name.
|
|
66
|
+
*
|
|
67
|
+
* @param name - Name of the circuit breaker
|
|
68
|
+
* @returns Circuit breaker or null if not found
|
|
69
|
+
*/
|
|
70
|
+
getCircuitBreaker(name: string): CircuitBreaker | null;
|
|
71
|
+
/**
|
|
72
|
+
* Reset a circuit breaker to closed state
|
|
73
|
+
*
|
|
74
|
+
* Manually resets a circuit breaker, clearing failure counts and
|
|
75
|
+
* returning it to the closed state. Useful for recovery after
|
|
76
|
+
* fixing underlying issues.
|
|
77
|
+
*
|
|
78
|
+
* @param name - Name of the circuit breaker to reset
|
|
79
|
+
*/
|
|
80
|
+
resetCircuitBreaker(name: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Get aggregate retry metrics
|
|
83
|
+
*
|
|
84
|
+
* Returns statistics about retry behavior across all tasks,
|
|
85
|
+
* including circuit breaker states.
|
|
86
|
+
*
|
|
87
|
+
* @returns Retry metrics (defensive copy)
|
|
88
|
+
*/
|
|
89
|
+
getRetryMetrics(): RetryMetrics;
|
|
90
|
+
/**
|
|
91
|
+
* Register handler for retry attempt events
|
|
92
|
+
*
|
|
93
|
+
* Called whenever a task is retried after a failure. Useful for
|
|
94
|
+
* logging, alerting, or monitoring retry patterns.
|
|
95
|
+
*
|
|
96
|
+
* @param handler - Callback function to invoke on each retry
|
|
97
|
+
*/
|
|
98
|
+
onRetryAttempt(handler: RetryAttemptHandler): void;
|
|
99
|
+
/**
|
|
100
|
+
* Register handler for circuit breaker open events
|
|
101
|
+
*
|
|
102
|
+
* Called when a circuit breaker transitions from closed/half-open
|
|
103
|
+
* to open state. Useful for alerting on service degradation.
|
|
104
|
+
*
|
|
105
|
+
* @param handler - Callback function to invoke when circuit opens
|
|
106
|
+
*/
|
|
107
|
+
onCircuitOpen(handler: CircuitOpenHandler): void;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/execution/resilience/executor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,kBAAkB;IAKjC;;;;;;;;;;;OAWG;IACH,WAAW,CACT,IAAI,EAAE,aAAa,EACnB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAErC;;;;;;;;;OASG;IACH,YAAY,CACV,KAAK,EAAE,aAAa,EAAE,EACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;IAMvC;;;;;;;;OAQG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC;IAEvD;;;;;;;;OAQG;IACH,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAMxC;;;;;;;OAOG;IACH,eAAe,IAAI,YAAY,CAAC;IAEhC;;;;;;;OAOG;IACH,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;IAEnD;;;;;;;OAOG;IACH,aAAa,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAClD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resilience Layer Exports
|
|
3
|
+
*
|
|
4
|
+
* Layer 3: Task Execution Layer - Resilience & Retry
|
|
5
|
+
*
|
|
6
|
+
* @module execution/resilience
|
|
7
|
+
*/
|
|
8
|
+
export type { RetryPolicy, CircuitState, CircuitBreaker, ExecutionAttempt, ResilientExecutionResult, RetryMetrics, RetryAttemptHandler, CircuitOpenHandler, } from './types.js';
|
|
9
|
+
export { DEFAULT_RETRY_POLICY } from './types.js';
|
|
10
|
+
export type { IResilientExecutor } from './executor.js';
|
|
11
|
+
export { ResilientExecutor } from './resilient-executor.js';
|
|
12
|
+
export { calculateBackoff, isRetryableError, isRetryableExitCode, isRetryableResult, sleep, createAttempt, calculateTotalRetryDelay, } from './retry.js';
|
|
13
|
+
export { CircuitBreakerManager, createCircuitBreaker, isInState, getState, getFailureRate, getSuccessRate, } from './circuit-breaker.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/execution/resilience/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGlD,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,EACL,aAAa,EACb,wBAAwB,GACzB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,SAAS,EACT,QAAQ,EACR,cAAc,EACd,cAAc,GACf,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resilient Executor Implementation
|
|
3
|
+
*
|
|
4
|
+
* Implements resilient task execution with retry logic and circuit breakers.
|
|
5
|
+
* Wraps the Engine Layer with fault tolerance mechanisms.
|
|
6
|
+
*
|
|
7
|
+
* @module execution/resilience/resilient-executor
|
|
8
|
+
*/
|
|
9
|
+
import type { IExecutionEngine } from "../engine/engine.js";
|
|
10
|
+
import type { ExecutionTask } from "../engine/types.js";
|
|
11
|
+
import type { IResilientExecutor } from "./executor.js";
|
|
12
|
+
import type { RetryPolicy, CircuitBreaker, RetryMetrics, ResilientExecutionResult, RetryAttemptHandler, CircuitOpenHandler } from "./types.js";
|
|
13
|
+
/**
|
|
14
|
+
* ResilientExecutor - Main implementation of resilient task execution
|
|
15
|
+
*
|
|
16
|
+
* Provides retry logic and circuit breaker protection for task execution.
|
|
17
|
+
* Wraps an IExecutionEngine with fault tolerance mechanisms.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const engine = new SimpleExecutionEngine(processManager);
|
|
22
|
+
* const executor = new ResilientExecutor(engine);
|
|
23
|
+
*
|
|
24
|
+
* const task: ExecutionTask = {
|
|
25
|
+
* id: 'task-1',
|
|
26
|
+
* type: 'issue',
|
|
27
|
+
* prompt: 'Fix the bug in authentication',
|
|
28
|
+
* workDir: '/path/to/project',
|
|
29
|
+
* priority: 0,
|
|
30
|
+
* dependencies: [],
|
|
31
|
+
* createdAt: new Date(),
|
|
32
|
+
* config: {},
|
|
33
|
+
* };
|
|
34
|
+
*
|
|
35
|
+
* const result = await executor.executeTask(task);
|
|
36
|
+
* console.log(`Completed after ${result.totalAttempts} attempts`);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare class ResilientExecutor implements IResilientExecutor {
|
|
40
|
+
private _engine;
|
|
41
|
+
private _circuitManager;
|
|
42
|
+
private _defaultPolicy;
|
|
43
|
+
private _metrics;
|
|
44
|
+
private _retryHandlers;
|
|
45
|
+
private _circuitOpenHandlers;
|
|
46
|
+
constructor(engine: IExecutionEngine, defaultPolicy?: RetryPolicy);
|
|
47
|
+
/**
|
|
48
|
+
* Execute a single task with retry and circuit breaker protection
|
|
49
|
+
*/
|
|
50
|
+
executeTask(task: ExecutionTask, policy?: RetryPolicy): Promise<ResilientExecutionResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Execute multiple tasks with retry and circuit breaker protection
|
|
53
|
+
*/
|
|
54
|
+
executeTasks(tasks: ExecutionTask[], policy?: RetryPolicy): Promise<ResilientExecutionResult[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Get circuit breaker by name
|
|
57
|
+
*/
|
|
58
|
+
getCircuitBreaker(name: string): CircuitBreaker | null;
|
|
59
|
+
/**
|
|
60
|
+
* Reset a circuit breaker to closed state
|
|
61
|
+
*/
|
|
62
|
+
resetCircuitBreaker(name: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Get aggregate retry metrics
|
|
65
|
+
*/
|
|
66
|
+
getRetryMetrics(): RetryMetrics;
|
|
67
|
+
/**
|
|
68
|
+
* Register handler for retry attempt events
|
|
69
|
+
*/
|
|
70
|
+
onRetryAttempt(handler: RetryAttemptHandler): void;
|
|
71
|
+
/**
|
|
72
|
+
* Register handler for circuit breaker open events
|
|
73
|
+
*/
|
|
74
|
+
onCircuitOpen(handler: CircuitOpenHandler): void;
|
|
75
|
+
/**
|
|
76
|
+
* Helper to create ResilientExecutionResult from engine result
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
private _createResilientResult;
|
|
80
|
+
/**
|
|
81
|
+
* Helper to update average attempts to success metric
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
private _updateAverageAttempts;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=resilient-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resilient-executor.d.ts","sourceRoot":"","sources":["../../../src/execution/resilience/resilient-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAmB,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,wBAAwB,EAExB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAWpB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,iBAAkB,YAAW,kBAAkB;IAC1D,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAe;IAG/B,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,oBAAoB,CAA4B;gBAGtD,MAAM,EAAE,gBAAgB,EACxB,aAAa,GAAE,WAAkC;IAcnD;;OAEG;IACG,WAAW,CACf,IAAI,EAAE,aAAa,EACnB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,wBAAwB,CAAC;IAkLpC;;OAEG;IACG,YAAY,CAChB,KAAK,EAAE,aAAa,EAAE,EACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAMtC;;OAEG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI;IAItD;;OAEG;IACH,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIvC;;OAEG;IACH,eAAe,IAAI,YAAY;IAW/B;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAIlD;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAIhD;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;CAQ/B"}
|