sub-agents-mcp 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +12 -0
  2. package/dist/index.js +0 -0
  3. package/package.json +1 -1
  4. package/dist/execution/ExecutionLimits.d.ts +0 -141
  5. package/dist/execution/ExecutionLimits.d.ts.map +0 -1
  6. package/dist/execution/ExecutionLimits.js +0 -231
  7. package/dist/execution/ExecutionLimits.js.map +0 -1
  8. package/dist/execution/McpRequestTimeout.d.ts +0 -166
  9. package/dist/execution/McpRequestTimeout.d.ts.map +0 -1
  10. package/dist/execution/McpRequestTimeout.js +0 -278
  11. package/dist/execution/McpRequestTimeout.js.map +0 -1
  12. package/dist/execution/PromptController.d.ts +0 -92
  13. package/dist/execution/PromptController.d.ts.map +0 -1
  14. package/dist/execution/PromptController.js +0 -130
  15. package/dist/execution/PromptController.js.map +0 -1
  16. package/dist/execution/TimeoutManager.d.ts +0 -159
  17. package/dist/execution/TimeoutManager.d.ts.map +0 -1
  18. package/dist/execution/TimeoutManager.js +0 -283
  19. package/dist/execution/TimeoutManager.js.map +0 -1
  20. package/dist/session/ToonConverter.d.ts +0 -172
  21. package/dist/session/ToonConverter.d.ts.map +0 -1
  22. package/dist/session/ToonConverter.js +0 -593
  23. package/dist/session/ToonConverter.js.map +0 -1
  24. package/dist/session/ToonUtils.d.ts +0 -23
  25. package/dist/session/ToonUtils.d.ts.map +0 -1
  26. package/dist/session/ToonUtils.js +0 -75
  27. package/dist/session/ToonUtils.js.map +0 -1
  28. package/dist/types/ServerConfig.d.ts +0 -39
  29. package/dist/types/ServerConfig.d.ts.map +0 -1
  30. package/dist/types/ServerConfig.js +0 -3
  31. package/dist/types/ServerConfig.js.map +0 -1
  32. package/dist/types/index.d.ts +0 -19
  33. package/dist/types/index.d.ts.map +0 -1
  34. package/dist/types/index.js +0 -3
  35. package/dist/types/index.js.map +0 -1
@@ -1,278 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.McpRequestTimeout = exports.DEFAULT_MCP_TIMEOUT_CONFIG = void 0;
4
- const Logger_1 = require("../utils/Logger");
5
- /**
6
- * Default timeout configuration for MCP requests
7
- * Based on MCP best practices and LLM operation characteristics
8
- */
9
- exports.DEFAULT_MCP_TIMEOUT_CONFIG = {
10
- defaultTimeoutMs: 360000, // 6 minutes - considering complex agent operations
11
- maxTimeoutMs: 660000, // 11 minutes - absolute maximum for AI->MCP
12
- progressResetEnabled: true,
13
- warningThresholdMs: 60000, // 1 minute - send progress notification
14
- enableDebugLogging: false,
15
- };
16
- /**
17
- * McpRequestTimeout manages timeout behavior for MCP server requests
18
- * Implements MCP specification recommendations for handling long-running operations
19
- *
20
- * This class handles AI -> MCP level timeouts, separate from MCP -> AI (AgentExecutor) timeouts
21
- * Following MCP best practices:
22
- * - Progressive timeout with reset on progress
23
- * - Maximum absolute timeout enforcement
24
- * - Progress notifications for better UX
25
- * - Graceful cancellation support
26
- */
27
- class McpRequestTimeout {
28
- /**
29
- * Creates a new McpRequestTimeout instance
30
- *
31
- * @param config - Optional timeout configuration
32
- * @param logger - Optional logger instance
33
- */
34
- constructor(config, logger) {
35
- this.contexts = new Map();
36
- this.config = { ...exports.DEFAULT_MCP_TIMEOUT_CONFIG, ...config };
37
- this.logger = logger || new Logger_1.Logger(process.env['LOG_LEVEL'] || 'info');
38
- }
39
- /**
40
- * Start timeout tracking for a request
41
- *
42
- * @param requestId - Unique request identifier
43
- * @param onTimeout - Callback when timeout occurs
44
- * @param onProgress - Optional callback for progress notifications
45
- * @returns TimeoutContext for the request
46
- */
47
- startTimeout(requestId, onTimeout, onProgress) {
48
- // Clear any existing timeout for this request
49
- this.clearTimeout(requestId);
50
- const context = {
51
- requestId,
52
- startTime: Date.now(),
53
- currentTimeout: null,
54
- warningTimeout: null,
55
- maxTimeout: null,
56
- progressCount: 0,
57
- lastProgressTime: Date.now(),
58
- isCompleted: false,
59
- isCancelled: false,
60
- onTimeout,
61
- ...(onProgress && { onProgress }),
62
- };
63
- // Set warning timeout (for progress notification)
64
- if (onProgress && this.config.warningThresholdMs > 0) {
65
- context.warningTimeout = setTimeout(() => {
66
- if (!context.isCompleted && !context.isCancelled) {
67
- this.sendProgressNotification(context, onProgress, 'Processing is taking longer than expected');
68
- }
69
- }, this.config.warningThresholdMs);
70
- }
71
- // Set default timeout
72
- context.currentTimeout = setTimeout(() => {
73
- if (!context.isCompleted && !context.isCancelled) {
74
- this.handleTimeout(context, onTimeout);
75
- }
76
- }, this.config.defaultTimeoutMs);
77
- // Set maximum absolute timeout (cannot be reset)
78
- context.maxTimeout = setTimeout(() => {
79
- if (!context.isCompleted && !context.isCancelled) {
80
- this.logger.warn('Maximum timeout reached, forcing termination', {
81
- requestId,
82
- elapsedMs: Date.now() - context.startTime,
83
- maxTimeoutMs: this.config.maxTimeoutMs,
84
- });
85
- this.handleTimeout(context, onTimeout);
86
- }
87
- }, this.config.maxTimeoutMs);
88
- this.contexts.set(requestId, context);
89
- if (this.config.enableDebugLogging) {
90
- this.logger.debug('Timeout tracking started', {
91
- requestId,
92
- defaultTimeoutMs: this.config.defaultTimeoutMs,
93
- maxTimeoutMs: this.config.maxTimeoutMs,
94
- });
95
- }
96
- return context;
97
- }
98
- /**
99
- * Report progress and optionally reset timeout
100
- * Following MCP specification: MAY reset timeout on progress, but enforce maximum
101
- *
102
- * @param requestId - Request identifier
103
- * @param message - Progress message
104
- * @param percentage - Optional completion percentage
105
- */
106
- reportProgress(requestId, message, percentage) {
107
- const context = this.contexts.get(requestId);
108
- if (!context || context.isCompleted || context.isCancelled) {
109
- return;
110
- }
111
- context.progressCount++;
112
- context.lastProgressTime = Date.now();
113
- if (this.config.enableDebugLogging) {
114
- this.logger.debug('Progress reported', {
115
- requestId,
116
- message,
117
- percentage,
118
- progressCount: context.progressCount,
119
- elapsedMs: Date.now() - context.startTime,
120
- });
121
- }
122
- // Reset timeout if enabled (but maximum timeout remains)
123
- if (this.config.progressResetEnabled && context.currentTimeout) {
124
- clearTimeout(context.currentTimeout);
125
- // Calculate remaining time before max timeout
126
- const elapsedMs = Date.now() - context.startTime;
127
- const remainingMs = this.config.maxTimeoutMs - elapsedMs;
128
- const newTimeoutMs = Math.min(this.config.defaultTimeoutMs, remainingMs);
129
- if (newTimeoutMs > 0 && context.onTimeout) {
130
- context.currentTimeout = setTimeout(() => {
131
- if (!context.isCompleted && !context.isCancelled) {
132
- this.handleTimeout(context, context.onTimeout);
133
- }
134
- }, newTimeoutMs);
135
- this.logger.info('Timeout reset due to progress', {
136
- requestId,
137
- newTimeoutMs,
138
- remainingBeforeMaxMs: remainingMs,
139
- });
140
- }
141
- }
142
- }
143
- /**
144
- * Mark request as completed and clear timeouts
145
- *
146
- * @param requestId - Request identifier
147
- */
148
- complete(requestId) {
149
- const context = this.contexts.get(requestId);
150
- if (!context) {
151
- return;
152
- }
153
- context.isCompleted = true;
154
- this.clearTimeouts(context);
155
- const totalTime = Date.now() - context.startTime;
156
- this.logger.info('Request completed within timeout', {
157
- requestId,
158
- totalTimeMs: totalTime,
159
- progressCount: context.progressCount,
160
- });
161
- this.contexts.delete(requestId);
162
- }
163
- /**
164
- * Cancel request and clear timeouts
165
- * Following MCP specification for cancellation
166
- *
167
- * @param requestId - Request identifier
168
- * @param reason - Cancellation reason
169
- */
170
- cancel(requestId, reason) {
171
- const context = this.contexts.get(requestId);
172
- if (!context) {
173
- return;
174
- }
175
- context.isCancelled = true;
176
- this.clearTimeouts(context);
177
- this.logger.info('Request cancelled', {
178
- requestId,
179
- reason,
180
- elapsedMs: Date.now() - context.startTime,
181
- });
182
- this.contexts.delete(requestId);
183
- }
184
- /**
185
- * Clear timeout for a request
186
- *
187
- * @param requestId - Request identifier
188
- */
189
- clearTimeout(requestId) {
190
- const context = this.contexts.get(requestId);
191
- if (context) {
192
- this.clearTimeouts(context);
193
- this.contexts.delete(requestId);
194
- }
195
- }
196
- /**
197
- * Check if request has timed out
198
- *
199
- * @param requestId - Request identifier
200
- * @returns true if timed out
201
- */
202
- hasTimedOut(requestId) {
203
- const context = this.contexts.get(requestId);
204
- if (!context) {
205
- return false;
206
- }
207
- const elapsedMs = Date.now() - context.startTime;
208
- return elapsedMs >= this.config.maxTimeoutMs;
209
- }
210
- /**
211
- * Get timeout statistics for monitoring
212
- *
213
- * @returns Current timeout statistics
214
- */
215
- getStats() {
216
- const activeContexts = Array.from(this.contexts.values()).filter((c) => !c.isCompleted && !c.isCancelled);
217
- const now = Date.now();
218
- const longestRunningMs = activeContexts.reduce((max, c) => Math.max(max, now - c.startTime), 0);
219
- const averageProgressCount = activeContexts.length > 0
220
- ? activeContexts.reduce((sum, c) => sum + c.progressCount, 0) / activeContexts.length
221
- : 0;
222
- return {
223
- activeRequests: activeContexts.length,
224
- averageProgressCount,
225
- longestRunningMs,
226
- };
227
- }
228
- /**
229
- * Handle timeout event
230
- *
231
- * @private
232
- */
233
- handleTimeout(context, onTimeout) {
234
- const elapsedMs = Date.now() - context.startTime;
235
- this.logger.warn('Request timeout occurred', {
236
- requestId: context.requestId,
237
- elapsedMs,
238
- progressCount: context.progressCount,
239
- lastProgressMs: Date.now() - context.lastProgressTime,
240
- });
241
- onTimeout(context);
242
- this.clearTimeouts(context);
243
- }
244
- /**
245
- * Send progress notification
246
- *
247
- * @private
248
- */
249
- sendProgressNotification(context, onProgress, message) {
250
- const notification = {
251
- requestId: context.requestId,
252
- message,
253
- timestamp: Date.now(),
254
- };
255
- onProgress(notification);
256
- }
257
- /**
258
- * Clear all timeouts for a context
259
- *
260
- * @private
261
- */
262
- clearTimeouts(context) {
263
- if (context.currentTimeout) {
264
- clearTimeout(context.currentTimeout);
265
- context.currentTimeout = null;
266
- }
267
- if (context.warningTimeout) {
268
- clearTimeout(context.warningTimeout);
269
- context.warningTimeout = null;
270
- }
271
- if (context.maxTimeout) {
272
- clearTimeout(context.maxTimeout);
273
- context.maxTimeout = null;
274
- }
275
- }
276
- }
277
- exports.McpRequestTimeout = McpRequestTimeout;
278
- //# sourceMappingURL=McpRequestTimeout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"McpRequestTimeout.js","sourceRoot":"","sources":["../../src/execution/McpRequestTimeout.ts"],"names":[],"mappings":";;;AAAA,6CAAwD;AAqCxD;;;GAGG;AACU,QAAA,0BAA0B,GAAqB;IAC1D,gBAAgB,EAAE,MAAM,EAAE,mDAAmD;IAC7E,YAAY,EAAE,MAAM,EAAE,4CAA4C;IAClE,oBAAoB,EAAE,IAAI;IAC1B,kBAAkB,EAAE,KAAK,EAAE,wCAAwC;IACnE,kBAAkB,EAAE,KAAK;CAC1B,CAAA;AAuCD;;;;;;;;;;GAUG;AACH,MAAa,iBAAiB;IAK5B;;;;;OAKG;IACH,YAAY,MAAkC,EAAE,MAAe;QAR9C,aAAQ,GAAgC,IAAI,GAAG,EAAE,CAAA;QAShE,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,kCAA0B,EAAE,GAAG,MAAM,EAAE,CAAA;QAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,IAAI,IAAI,eAAM,CAAE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAc,IAAI,MAAM,CAAC,CAAA;IACtF,CAAC;IAED;;;;;;;OAOG;IACH,YAAY,CACV,SAAiB,EACjB,SAA0B,EAC1B,UAA6B;QAE7B,8CAA8C;QAC9C,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;QAE5B,MAAM,OAAO,GAAmB;YAC9B,SAAS;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,cAAc,EAAE,IAAI;YACpB,cAAc,EAAE,IAAI;YACpB,UAAU,EAAE,IAAI;YAChB,aAAa,EAAE,CAAC;YAChB,gBAAgB,EAAE,IAAI,CAAC,GAAG,EAAE;YAC5B,WAAW,EAAE,KAAK;YAClB,WAAW,EAAE,KAAK;YAClB,SAAS;YACT,GAAG,CAAC,UAAU,IAAI,EAAE,UAAU,EAAE,CAAC;SAClC,CAAA;Q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AS,EAAE,OAAO,CAAC,SAAS;YAC5B,OAAO;YACP,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAA;QAED,UAAU,CAAC,YAAY,CAAC,CAAA;IAC1B,CAAC;IAED;;;;OAIG;IACK,aAAa,CAAC,OAAuB;QAC3C,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;YAC3B,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;YACpC,OAAO,CAAC,cAAc,GAAG,IAAI,CAAA;QAC/B,CAAC;QACD,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;YAC3B,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;YACpC,OAAO,CAAC,cAAc,GAAG,IAAI,CAAA;QAC/B,CAAC;QACD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;YAChC,OAAO,CAAC,UAAU,GAAG,IAAI,CAAA;QAC3B,CAAC;IACH,CAAC;CACF;AAnTD,8CAmTC"}
@@ -1,92 +0,0 @@
1
- import type { ExecutionParams } from '../types/ExecutionParams';
2
- /**
3
- * Configuration options for recursion prevention warnings.
4
- * Allows customization of warning messages and formatting.
5
- */
6
- export interface RecursionWarningConfig {
7
- /**
8
- * The warning message template to add to prompts.
9
- * Should contain clear instructions to prevent recursion.
10
- */
11
- warningTemplate: string;
12
- /**
13
- * Whether to format the warning with visual separators.
14
- * Defaults to true for better readability.
15
- */
16
- useFormatting: boolean;
17
- }
18
- /**
19
- * Default configuration for recursion prevention warnings.
20
- * Uses clear English instructions to prevent sub-agents-mcp MCP tool usage.
21
- */
22
- export declare const DEFAULT_RECURSION_WARNING_CONFIG: RecursionWarningConfig;
23
- /**
24
- * Controller class for enhancing prompts with recursion prevention instructions.
25
- * Implements the security strategy defined in ADR-0001 for preventing infinite loops
26
- * in agent-to-agent communication through prompt control.
27
- */
28
- export declare class PromptController {
29
- private readonly config;
30
- /**
31
- * Creates a new PromptController instance.
32
- *
33
- * @param config - Optional configuration for recursion warning behavior
34
- */
35
- constructor(config?: RecursionWarningConfig);
36
- /**
37
- * Adds recursion prevention warning to a prompt string.
38
- *
39
- * This method implements the prompt control strategy defined in ADR-0001
40
- * to prevent infinite loops in agent-to-agent communication. It preserves
41
- * the original prompt content while adding clear security instructions
42
- * that explicitly prohibit the use of sub-agents-mcp MCP tools.
43
- *
44
- * @param originalPrompt - The original user prompt to enhance
45
- * @returns Enhanced prompt with recursion prevention instructions appended
46
- * @throws {Error} When originalPrompt is empty or contains only whitespace
47
- *
48
- * @example
49
- * ```typescript
50
- * const controller = new PromptController()
51
- * const enhanced = controller.addRecursionWarning("Help me debug this code")
52
- * console.log(enhanced)
53
- * // Output: "Help me debug this code\n============...===========\nIMPORTANT RECURSION PREVENTION INSTRUCTIONS:\n- Do NOT use sub-agents-mcp MCP tools..."
54
- * ```
55
- */
56
- addRecursionWarning(originalPrompt: string): string;
57
- /**
58
- * Formats the warning message according to the current configuration.
59
- *
60
- * @private
61
- * @returns Formatted warning message with or without visual separators
62
- */
63
- private formatWarningMessage;
64
- /**
65
- * Enhances ExecutionParams by adding recursion prevention to the prompt field.
66
- *
67
- * This method is the primary interface for integrating prompt enhancement
68
- * into the agent execution pipeline. It creates a new ExecutionParams object
69
- * with an enhanced prompt while preserving all other execution parameters.
70
- * The enhanced prompt includes ADR-0001 compliant security instructions.
71
- *
72
- * @param params - Original execution parameters to enhance
73
- * @returns New ExecutionParams object with enhanced prompt field
74
- * @throws {Error} When params is invalid or prompt enhancement fails
75
- *
76
- * @example
77
- * ```typescript
78
- * const controller = new PromptController()
79
- * const original = {
80
- * agent: "code-helper",
81
- * prompt: "Fix this bug",
82
- * cwd: "/project",
83
- * extra_args: ["--verbose"]
84
- * }
85
- * const enhanced = controller.enhanceExecutionParams(original)
86
- * console.log(enhanced.prompt) // Original prompt + recursion prevention
87
- * console.log(enhanced.agent) // "code-helper" (unchanged)
88
- * ```
89
- */
90
- enhanceExecutionParams(params: ExecutionParams): ExecutionParams;
91
- }
92
- //# sourceMappingURL=PromptController.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PromptController.d.ts","sourceRoot":"","sources":["../../src/execution/PromptController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAEhE;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAA;IAEvB;;;OAGG;IACH,aAAa,EAAE,OAAO,CAAA;CACvB;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,EAAE,sBAS9C,CAAA;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;IAE/C;;;;OAIG;gBACS,MAAM,GAAE,sBAAyD;IAI7E;;;;;;;;;;;;;;;;;;;OAmBG;IACH,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM;IAiBnD;;;;;OAKG;IACH,OAAO,CAAC,oBAAoB;IAS5B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,sBAAsB,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe;CA6BjE"}
@@ -1,130 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PromptController = exports.DEFAULT_RECURSION_WARNING_CONFIG = void 0;
4
- /**
5
- * Default configuration for recursion prevention warnings.
6
- * Uses clear English instructions to prevent sub-agents-mcp MCP tool usage.
7
- */
8
- exports.DEFAULT_RECURSION_WARNING_CONFIG = {
9
- warningTemplate: `
10
- IMPORTANT RECURSION PREVENTION INSTRUCTIONS:
11
- - Do NOT use sub-agents-mcp MCP tools in your response
12
- - Complete this task within the current agent context only
13
- - Do not attempt to call other agents or sub-agents
14
- - Focus on direct implementation and solution delivery
15
- `,
16
- useFormatting: true,
17
- };
18
- /**
19
- * Controller class for enhancing prompts with recursion prevention instructions.
20
- * Implements the security strategy defined in ADR-0001 for preventing infinite loops
21
- * in agent-to-agent communication through prompt control.
22
- */
23
- class PromptController {
24
- /**
25
- * Creates a new PromptController instance.
26
- *
27
- * @param config - Optional configuration for recursion warning behavior
28
- */
29
- constructor(config = exports.DEFAULT_RECURSION_WARNING_CONFIG) {
30
- this.config = config;
31
- }
32
- /**
33
- * Adds recursion prevention warning to a prompt string.
34
- *
35
- * This method implements the prompt control strategy defined in ADR-0001
36
- * to prevent infinite loops in agent-to-agent communication. It preserves
37
- * the original prompt content while adding clear security instructions
38
- * that explicitly prohibit the use of sub-agents-mcp MCP tools.
39
- *
40
- * @param originalPrompt - The original user prompt to enhance
41
- * @returns Enhanced prompt with recursion prevention instructions appended
42
- * @throws {Error} When originalPrompt is empty or contains only whitespace
43
- *
44
- * @example
45
- * ```typescript
46
- * const controller = new PromptController()
47
- * const enhanced = controller.addRecursionWarning("Help me debug this code")
48
- * console.log(enhanced)
49
- * // Output: "Help me debug this code\n============...===========\nIMPORTANT RECURSION PREVENTION INSTRUCTIONS:\n- Do NOT use sub-agents-mcp MCP tools..."
50
- * ```
51
- */
52
- addRecursionWarning(originalPrompt) {
53
- // Input validation: ensure prompt is not empty or whitespace-only
54
- if (typeof originalPrompt !== 'string') {
55
- throw new Error('Original prompt must be a string');
56
- }
57
- if (originalPrompt.trim().length === 0) {
58
- throw new Error('Original prompt cannot be empty');
59
- }
60
- // Format warning based on configuration
61
- const warning = this.formatWarningMessage();
62
- // Concatenate original prompt with warning
63
- return `${originalPrompt}${warning}`;
64
- }
65
- /**
66
- * Formats the warning message according to the current configuration.
67
- *
68
- * @private
69
- * @returns Formatted warning message with or without visual separators
70
- */
71
- formatWarningMessage() {
72
- if (this.config.useFormatting) {
73
- const separator = '='.repeat(60);
74
- return `\n${separator}\n${this.config.warningTemplate}\n${separator}\n`;
75
- }
76
- return this.config.warningTemplate;
77
- }
78
- /**
79
- * Enhances ExecutionParams by adding recursion prevention to the prompt field.
80
- *
81
- * This method is the primary interface for integrating prompt enhancement
82
- * into the agent execution pipeline. It creates a new ExecutionParams object
83
- * with an enhanced prompt while preserving all other execution parameters.
84
- * The enhanced prompt includes ADR-0001 compliant security instructions.
85
- *
86
- * @param params - Original execution parameters to enhance
87
- * @returns New ExecutionParams object with enhanced prompt field
88
- * @throws {Error} When params is invalid or prompt enhancement fails
89
- *
90
- * @example
91
- * ```typescript
92
- * const controller = new PromptController()
93
- * const original = {
94
- * agent: "code-helper",
95
- * prompt: "Fix this bug",
96
- * cwd: "/project",
97
- * extra_args: ["--verbose"]
98
- * }
99
- * const enhanced = controller.enhanceExecutionParams(original)
100
- * console.log(enhanced.prompt) // Original prompt + recursion prevention
101
- * console.log(enhanced.agent) // "code-helper" (unchanged)
102
- * ```
103
- */
104
- enhanceExecutionParams(params) {
105
- // Input validation: ensure params is valid ExecutionParams object
106
- if (!params || typeof params !== 'object') {
107
- throw new Error('ExecutionParams must be a valid object');
108
- }
109
- if (!params.agent || typeof params.agent !== 'string') {
110
- throw new Error('ExecutionParams must have a valid agent field');
111
- }
112
- if (!params.prompt || typeof params.prompt !== 'string') {
113
- throw new Error('ExecutionParams must have a valid prompt field');
114
- }
115
- try {
116
- // Enhance the prompt with recursion prevention instructions
117
- const enhancedPrompt = this.addRecursionWarning(params.prompt);
118
- // Return new object with enhanced prompt, preserving all other fields
119
- return {
120
- ...params,
121
- prompt: enhancedPrompt,
122
- };
123
- }
124
- catch (error) {
125
- throw new Error(`Failed to enhance execution parameters: ${error instanceof Error ? error.message : 'Unknown error'}`);
126
- }
127
- }
128
- }
129
- exports.PromptController = PromptController;
130
- //# sourceMappingURL=PromptController.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PromptController.js","sourceRoot":"","sources":["../../src/execution/PromptController.ts"],"names":[],"mappings":";;;AAoBA;;;GAGG;AACU,QAAA,gCAAgC,GAA2B;IACtE,eAAe,EAAE;;;;;;CAMlB;IACC,aAAa,EAAE,IAAI;CACpB,CAAA;AAED;;;;GAIG;AACH,MAAa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CAAA;QAClE,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAA;QACnE,CAAC;QAED,IAAI,CAAC;YACH,4DAA4D;YAC5D,MAAM,cAAc,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAE9D,sEAAsE;YACtE,OAAO;gBACL,GAAG,MAAM;gBACT,MAAM,EAAE,cAAc;aACvB,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,2CAA2C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CACtG,CAAA;QACH,CAAC;IACH,CAAC;CACF;AAvHD,4CAuHC"}
@@ -1,159 +0,0 @@
1
- /**
2
- * Timeout management for agent execution with configurable limits and cleanup.
3
- *
4
- * Provides timeout enforcement with warning mechanisms, graceful cleanup,
5
- * and integration with agent execution processes.
6
- */
7
- /**
8
- * Configuration interface for timeout management.
9
- */
10
- export interface TimeoutConfig {
11
- /** Default timeout in milliseconds (default: 30000) */
12
- defaultTimeoutMs: number;
13
- /** Warning threshold as percentage of timeout (default: 0.8 for 80%) */
14
- warningThresholdPercent: number;
15
- /** Enable timeout warnings (default: true) */
16
- enableWarnings: boolean;
17
- /** Grace period for cleanup in milliseconds (default: 5000) */
18
- cleanupGracePeriodMs: number;
19
- }
20
- /**
21
- * Timeout execution context for tracking active operations.
22
- */
23
- export interface TimeoutContext {
24
- /** Unique identifier for the operation */
25
- operationId: string;
26
- /** Start time of the operation */
27
- startTime: Date;
28
- /** Timeout duration in milliseconds */
29
- timeoutMs: number;
30
- /** Warning callback function */
31
- onWarning?: (remainingMs: number) => void;
32
- /** Cleanup callback function */
33
- onCleanup?: () => Promise<void>;
34
- }
35
- /**
36
- * Default timeout configuration.
37
- */
38
- export declare const DEFAULT_TIMEOUT_CONFIG: TimeoutConfig;
39
- /**
40
- * Timeout manager for execution time monitoring and enforcement.
41
- *
42
- * Manages timeout enforcement with configurable limits, warning mechanisms,
43
- * and graceful cleanup for agent execution processes.
44
- */
45
- export declare class TimeoutManager {
46
- private readonly config;
47
- private readonly activeTimeouts;
48
- /**
49
- * Creates a new TimeoutManager instance.
50
- *
51
- * @param config - Timeout configuration (uses defaults if not provided)
52
- */
53
- constructor(config?: Partial<TimeoutConfig>);
54
- /**
55
- * Starts timeout monitoring for an operation.
56
- *
57
- * @param context - Timeout context for the operation
58
- * @returns Operation ID for tracking
59
- * @throws {Error} If operation ID is already being tracked
60
- */
61
- startTimeout(context: TimeoutContext): string;
62
- /**
63
- * Clears timeout monitoring for an operation.
64
- *
65
- * @param operationId - Operation ID to clear
66
- * @returns True if timeout was cleared, false if not found
67
- */
68
- clearTimeout(operationId: string): boolean;
69
- /**
70
- * Gets the remaining time for an operation.
71
- *
72
- * @param operationId - Operation ID to check
73
- * @returns Remaining time in milliseconds, or null if not found
74
- */
75
- getRemainingTime(operationId: string): number | null;
76
- /**
77
- * Gets the elapsed time for an operation.
78
- *
79
- * @param operationId - Operation ID to check
80
- * @returns Elapsed time in milliseconds, or null if not found
81
- */
82
- getElapsedTime(operationId: string): number | null;
83
- /**
84
- * Checks if an operation is currently being tracked.
85
- *
86
- * @param operationId - Operation ID to check
87
- * @returns True if operation is being tracked
88
- */
89
- isActive(operationId: string): boolean;
90
- /**
91
- * Gets all active operation IDs.
92
- *
93
- * @returns Array of active operation IDs
94
- */
95
- getActiveOperations(): string[];
96
- /**
97
- * Creates a timeout context with default values.
98
- *
99
- * @param operationId - Unique operation identifier
100
- * @param timeoutMs - Timeout duration (uses default if not provided)
101
- * @param options - Additional context options
102
- * @returns Timeout context
103
- */
104
- createContext(operationId: string, timeoutMs?: number, options?: {
105
- onWarning?: (remainingMs: number) => void;
106
- onCleanup?: () => Promise<void>;
107
- }): TimeoutContext;
108
- /**
109
- * Gets the current configuration.
110
- *
111
- * @returns Timeout configuration
112
- */
113
- getConfig(): TimeoutConfig;
114
- /**
115
- * Clears all active timeouts.
116
- *
117
- * @returns Number of timeouts cleared
118
- */
119
- clearAllTimeouts(): number;
120
- /**
121
- * Gets timeout statistics for monitoring and optimization.
122
- *
123
- * @returns Timeout statistics
124
- */
125
- getTimeoutStats(): {
126
- activeOperations: number;
127
- totalOperationsStarted: number;
128
- averageCompletionTime: number;
129
- timeoutRate: number;
130
- };
131
- /**
132
- * Suggests optimal timeout based on historical data.
133
- *
134
- * @param operationType - Type of operation for historical analysis (reserved for future use)
135
- * @returns Suggested timeout in milliseconds
136
- */
137
- suggestOptimalTimeout(operationType?: string): number;
138
- /**
139
- * Updates timeout statistics.
140
- *
141
- * @param operationId - Operation that completed/timed out
142
- * @param completed - Whether operation completed successfully
143
- * @private
144
- */
145
- private updateStats;
146
- /**
147
- * Handles timeout event with cleanup and error throwing.
148
- *
149
- * @param context - Timeout context
150
- * @private
151
- */
152
- private handleTimeout;
153
- /**
154
- * Statistics tracking for timeout optimization.
155
- * @private
156
- */
157
- private stats;
158
- }
159
- //# sourceMappingURL=TimeoutManager.d.ts.map