mcp-agent-foundry 1.3.1 → 2.0.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.
Files changed (104) hide show
  1. package/README.md +232 -1
  2. package/dist/background/index.d.ts +33 -0
  3. package/dist/background/index.d.ts.map +1 -0
  4. package/dist/background/index.js +33 -0
  5. package/dist/background/index.js.map +1 -0
  6. package/dist/background/task-runner.d.ts +177 -0
  7. package/dist/background/task-runner.d.ts.map +1 -0
  8. package/dist/background/task-runner.js +551 -0
  9. package/dist/background/task-runner.js.map +1 -0
  10. package/dist/background/types.d.ts +135 -0
  11. package/dist/background/types.d.ts.map +1 -0
  12. package/dist/background/types.js +8 -0
  13. package/dist/background/types.js.map +1 -0
  14. package/dist/failover/health-tracker.d.ts +81 -1
  15. package/dist/failover/health-tracker.d.ts.map +1 -1
  16. package/dist/failover/health-tracker.js +229 -1
  17. package/dist/failover/health-tracker.js.map +1 -1
  18. package/dist/hooks/hook-executor.d.ts +77 -0
  19. package/dist/hooks/hook-executor.d.ts.map +1 -0
  20. package/dist/hooks/hook-executor.js +308 -0
  21. package/dist/hooks/hook-executor.js.map +1 -0
  22. package/dist/hooks/hook-manager.d.ts +140 -0
  23. package/dist/hooks/hook-manager.d.ts.map +1 -0
  24. package/dist/hooks/hook-manager.js +520 -0
  25. package/dist/hooks/hook-manager.js.map +1 -0
  26. package/dist/hooks/index.d.ts +10 -0
  27. package/dist/hooks/index.d.ts.map +1 -0
  28. package/dist/hooks/index.js +10 -0
  29. package/dist/hooks/index.js.map +1 -0
  30. package/dist/hooks/types.d.ts +221 -0
  31. package/dist/hooks/types.d.ts.map +1 -0
  32. package/dist/hooks/types.js +31 -0
  33. package/dist/hooks/types.js.map +1 -0
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +1 -1
  36. package/dist/mcp/auto-mode.d.ts +221 -0
  37. package/dist/mcp/auto-mode.d.ts.map +1 -0
  38. package/dist/mcp/auto-mode.js +436 -0
  39. package/dist/mcp/auto-mode.js.map +1 -0
  40. package/dist/mcp/index.d.ts +14 -0
  41. package/dist/mcp/index.d.ts.map +1 -0
  42. package/dist/mcp/index.js +22 -0
  43. package/dist/mcp/index.js.map +1 -0
  44. package/dist/mcp/tools/tasks/delete-task.d.ts +25 -0
  45. package/dist/mcp/tools/tasks/delete-task.d.ts.map +1 -0
  46. package/dist/mcp/tools/tasks/delete-task.js +148 -0
  47. package/dist/mcp/tools/tasks/delete-task.js.map +1 -0
  48. package/dist/mcp/tools/tasks/index.d.ts +2 -0
  49. package/dist/mcp/tools/tasks/index.d.ts.map +1 -1
  50. package/dist/mcp/tools/tasks/index.js +6 -0
  51. package/dist/mcp/tools/tasks/index.js.map +1 -1
  52. package/dist/observability/debug-logger.d.ts +209 -0
  53. package/dist/observability/debug-logger.d.ts.map +1 -0
  54. package/dist/observability/debug-logger.js +430 -0
  55. package/dist/observability/debug-logger.js.map +1 -0
  56. package/dist/observability/index.d.ts +12 -0
  57. package/dist/observability/index.d.ts.map +1 -0
  58. package/dist/observability/index.js +12 -0
  59. package/dist/observability/index.js.map +1 -0
  60. package/dist/observability/logger.d.ts +180 -0
  61. package/dist/observability/logger.d.ts.map +1 -1
  62. package/dist/observability/logger.js +158 -0
  63. package/dist/observability/logger.js.map +1 -1
  64. package/dist/router/context-manager.d.ts +214 -1
  65. package/dist/router/context-manager.d.ts.map +1 -1
  66. package/dist/router/context-manager.js +759 -2
  67. package/dist/router/context-manager.js.map +1 -1
  68. package/dist/router/context-types.d.ts +182 -0
  69. package/dist/router/context-types.d.ts.map +1 -0
  70. package/dist/router/context-types.js +8 -0
  71. package/dist/router/context-types.js.map +1 -0
  72. package/dist/server.d.ts +41 -0
  73. package/dist/server.d.ts.map +1 -1
  74. package/dist/server.js +165 -0
  75. package/dist/server.js.map +1 -1
  76. package/dist/skills/hot-reloader.d.ts +104 -0
  77. package/dist/skills/hot-reloader.d.ts.map +1 -0
  78. package/dist/skills/hot-reloader.js +314 -0
  79. package/dist/skills/hot-reloader.js.map +1 -0
  80. package/dist/skills/index.d.ts +14 -0
  81. package/dist/skills/index.d.ts.map +1 -0
  82. package/dist/skills/index.js +16 -0
  83. package/dist/skills/index.js.map +1 -0
  84. package/dist/skills/skill-executor.d.ts +96 -0
  85. package/dist/skills/skill-executor.d.ts.map +1 -0
  86. package/dist/skills/skill-executor.js +289 -0
  87. package/dist/skills/skill-executor.js.map +1 -0
  88. package/dist/skills/skill-loader.d.ts +147 -0
  89. package/dist/skills/skill-loader.d.ts.map +1 -0
  90. package/dist/skills/skill-loader.js +579 -0
  91. package/dist/skills/skill-loader.js.map +1 -0
  92. package/dist/skills/types.d.ts +198 -0
  93. package/dist/skills/types.d.ts.map +1 -0
  94. package/dist/skills/types.js +21 -0
  95. package/dist/skills/types.js.map +1 -0
  96. package/dist/tasks/coordinator.d.ts +22 -1
  97. package/dist/tasks/coordinator.d.ts.map +1 -1
  98. package/dist/tasks/coordinator.js +83 -0
  99. package/dist/tasks/coordinator.js.map +1 -1
  100. package/dist/tasks/state-coordinator.d.ts +19 -0
  101. package/dist/tasks/state-coordinator.d.ts.map +1 -1
  102. package/dist/tasks/state-coordinator.js +40 -0
  103. package/dist/tasks/state-coordinator.js.map +1 -1
  104. package/package.json +1 -1
package/README.md CHANGED
@@ -24,6 +24,11 @@ Agent Foundry extends Claude Code with multi-provider AI orchestration and git w
24
24
  - **State Persistence** - Survives server restarts with automatic state recovery
25
25
  - **Crash Recovery** - Orphan detection, stuck worktree handling, and cleanup commands
26
26
  - **Intelligent Failover** - Automatic provider switching with health tracking, circuit breakers, and cost-aware routing
27
+ - **Context Manager** - Token tracking per provider/model with 40+ model limits, auto-compact at 90%, blocking at 98%
28
+ - **Hooks System** - 9 event types for customizing agent behavior with variable substitution and hot-reload
29
+ - **Background Task Runner** - Queue-based async task execution with AbortController cancellation and progress tracking
30
+ - **MCP Auto Mode** - Intelligent tool selection under context pressure with priority-based deferral
31
+ - **Skills Hot-Reload** - Custom skill definitions with auto-discovery from user and project directories
27
32
 
28
33
  ---
29
34
 
@@ -153,6 +158,166 @@ Agent Foundry includes automatic provider failover with health tracking:
153
158
  - **Circuit Breakers** - Prevents cascading failures
154
159
  - **Cost-Aware Routing** - Optionally prefer cheaper providers
155
160
  - **Configurable Error Codes** - Define which errors trigger failover
161
+ - **Rate Limit Warnings** - Proactive warnings at 70% capacity with header parsing for OpenAI/Anthropic/generic formats
162
+
163
+ ---
164
+
165
+ ## Hooks System
166
+
167
+ Agent Foundry provides a flexible hooks system that lets you customize agent behavior by running commands at key lifecycle events.
168
+
169
+ ### Supported Events
170
+
171
+ | Event | Description |
172
+ |-------|-------------|
173
+ | `PreToolUse` | Before a tool is invoked |
174
+ | `PostToolUse` | After a tool completes |
175
+ | `Setup` | During agent initialization |
176
+ | `ToolError` | When a tool encounters an error |
177
+ | `TaskStart` | When a task begins execution |
178
+ | `TaskComplete` | When a task finishes successfully |
179
+ | `TaskFail` | When a task fails |
180
+ | `ProviderError` | When an AI provider returns an error |
181
+ | `Failover` | When switching to a fallback provider |
182
+
183
+ ### Configuration
184
+
185
+ ```yaml
186
+ # In ~/.config/agent-foundry/config.yaml
187
+ hooks:
188
+ enabled: true
189
+ configPath: ~/.agent-foundry/hooks.yaml
190
+ events:
191
+ PreToolUse:
192
+ - command: "echo 'Tool: ${TOOL_NAME}'"
193
+ timeout_ms: 5000
194
+ filter:
195
+ tools: ["execute_task", "invoke_agent"]
196
+ TaskComplete:
197
+ - command: "./notify.sh ${TASK_ID}"
198
+ timeout_ms: 10000
199
+ ProviderError:
200
+ - command: "logger -t agent-foundry 'Provider ${PROVIDER} failed: ${ERROR}'"
201
+ ```
202
+
203
+ ### Variable Substitution
204
+
205
+ Hooks support variable substitution with context-specific values:
206
+ - `${TOOL_NAME}` - Name of the tool being invoked
207
+ - `${TASK_ID}` - Current task identifier
208
+ - `${PROVIDER}` - AI provider name
209
+ - `${ERROR}` - Error message (for error events)
210
+ - `${RESULT}` - Result data (for post-completion events)
211
+
212
+ ### Features
213
+
214
+ - **Filtering** - Run hooks only for specific tools, providers, or roles
215
+ - **Timeouts** - Configurable per-hook timeouts prevent blocking
216
+ - **Hot-Reload** - Changes to hooks.yaml are picked up automatically
217
+
218
+ ---
219
+
220
+ ## Skills Hot-Reload
221
+
222
+ Define custom skills that extend agent capabilities with automatic discovery and hot-reload.
223
+
224
+ ### Skill Locations
225
+
226
+ Skills are loaded from:
227
+ 1. `~/.agent-foundry/skills/` - User-level skills (shared across projects)
228
+ 2. `.agent-foundry/skills/` - Project-level skills (project-specific)
229
+
230
+ ### Skill Definition
231
+
232
+ ```yaml
233
+ # ~/.agent-foundry/skills/code-review.yaml
234
+ name: code-review
235
+ description: Comprehensive code review skill
236
+ context_mode: inherit # inherit | fork | isolated
237
+
238
+ prompts:
239
+ system: |
240
+ You are an expert code reviewer focusing on:
241
+ - Security vulnerabilities
242
+ - Performance issues
243
+ - Best practices
244
+ - Code clarity
245
+
246
+ triggers:
247
+ - pattern: "review this code"
248
+ - pattern: "code review"
249
+
250
+ actions:
251
+ - type: invoke_agent
252
+ role: reviewer
253
+ ```
254
+
255
+ ### Context Modes
256
+
257
+ | Mode | Description |
258
+ |------|-------------|
259
+ | `inherit` | Skill runs in the parent agent's context |
260
+ | `fork` | Skill gets a copy of the parent context |
261
+ | `isolated` | Skill runs with a fresh, empty context |
262
+
263
+ ### Features
264
+
265
+ - **Auto-Discovery** - Skills are automatically loaded on startup
266
+ - **Hot-Reload** - Changes to skill files are picked up without restart
267
+ - **Priority Ordering** - Project skills override user skills with the same name
268
+
269
+ ---
270
+
271
+ ## Context Manager
272
+
273
+ Agent Foundry includes intelligent context management to prevent token limit issues and optimize AI provider usage.
274
+
275
+ ### Features
276
+
277
+ - **Token Tracking** - Tracks token usage per provider/model with 40+ pre-configured model limits
278
+ - **Auto-Compact** - Automatically compacts context when reaching 90% capacity
279
+ - **Blocking Threshold** - Blocks new requests at 98% to prevent errors
280
+ - **Visualization** - Context usage visible in debug logs and status commands
281
+
282
+ ### Configuration
283
+
284
+ ```yaml
285
+ # In ~/.config/agent-foundry/config.yaml
286
+ context:
287
+ autoCompact: true
288
+ compactThreshold: 0.9 # Trigger compaction at 90%
289
+ blockThreshold: 0.98 # Block new requests at 98%
290
+ ```
291
+
292
+ ### Supported Model Limits
293
+
294
+ Pre-configured limits for 40+ models including:
295
+ - OpenAI: GPT-4o (128K), GPT-4 Turbo (128K), o1 (200K)
296
+ - Anthropic: Claude 3.5/4 (200K)
297
+ - Google: Gemini 2.5 Pro (1M), Gemini 2.5 Flash (1M)
298
+ - DeepSeek: DeepSeek R1 (64K), DeepSeek Chat (128K)
299
+ - And many more...
300
+
301
+ ---
302
+
303
+ ## MCP Auto Mode
304
+
305
+ When context pressure builds, MCP Auto Mode intelligently manages tool availability.
306
+
307
+ ### How It Works
308
+
309
+ 1. **Context Budget** - Tool descriptions are deferred when exceeding 10% of context budget
310
+ 2. **Priority-Based Selection** - High-priority tools remain available; lower-priority tools are deferred
311
+ 3. **Automatic Restoration** - Deferred tools become available again when context decreases
312
+
313
+ ### Tool Priorities
314
+
315
+ | Priority | Tools |
316
+ |----------|-------|
317
+ | Critical | `invoke_agent`, `execute_task` |
318
+ | High | `list_agents`, `get_task_status` |
319
+ | Medium | `execute_pipeline`, `compare_agents` |
320
+ | Low | `cleanup_worktrees`, `list_worktrees` |
156
321
 
157
322
  ---
158
323
 
@@ -174,6 +339,7 @@ Agent Foundry includes automatic provider failover with health tracking:
174
339
  | `cleanup_worktrees` | Clean up stale or orphaned worktrees |
175
340
  | `resolve_conflicts` | Resolve merge conflicts using various strategies |
176
341
  | `get_worktree_status` | Get detailed status of a specific worktree |
342
+ | `delete_task` | Delete a task from the queue |
177
343
 
178
344
  ---
179
345
 
@@ -279,6 +445,31 @@ worktrees:
279
445
  enabled: true
280
446
  minAvailable: 2
281
447
  maxSize: 5
448
+
449
+ # Hooks configuration
450
+ hooks:
451
+ enabled: true
452
+ configPath: ~/.agent-foundry/hooks.yaml
453
+ events:
454
+ PreToolUse:
455
+ - command: "echo 'Tool: ${TOOL_NAME}'"
456
+ timeout_ms: 5000
457
+ TaskComplete:
458
+ - command: "./notify.sh ${TASK_ID}"
459
+
460
+ # Skills configuration
461
+ skills:
462
+ enabled: true
463
+ directories:
464
+ - ~/.agent-foundry/skills
465
+ - .agent-foundry/skills
466
+ hotReload: true
467
+
468
+ # Context management
469
+ context:
470
+ autoCompact: true
471
+ compactThreshold: 0.9 # Auto-compact at 90% capacity
472
+ blockThreshold: 0.98 # Block new requests at 98% capacity
282
473
  ```
283
474
 
284
475
  ### Environment Variables
@@ -305,6 +496,11 @@ export FIREWORKS_API_KEY="..."
305
496
 
306
497
  # Web Search
307
498
  export PERPLEXITY_API_KEY="pplx-..."
499
+
500
+ # Debug/Observability
501
+ export AGENT_FOUNDRY_DEBUG=true # Enable debug logging
502
+ export AGENT_FOUNDRY_DEBUG_FILE=/path/to/debug.log # Write debug logs to file
503
+ export AGENT_FOUNDRY_DEBUG_VERBOSE=true # Include verbose details
308
504
  ```
309
505
 
310
506
  ---
@@ -455,7 +651,8 @@ agent-foundry/
455
651
  │ ├── cli/ # CLI command implementations
456
652
  │ ├── mcp/
457
653
  │ │ ├── tools/ # MCP tool implementations
458
- │ │ └── transport/ # stdio transport
654
+ │ │ ├── transport/ # stdio transport
655
+ │ │ └── auto-mode.ts # MCP Auto Mode - intelligent tool selection
459
656
  │ ├── worktrees/
460
657
  │ │ ├── manager.ts # Worktree lifecycle
461
658
  │ │ ├── branch.ts # Branch operations
@@ -482,6 +679,18 @@ agent-foundry/
482
679
  │ │ ├── orchestrator.ts # Retry and failover logic
483
680
  │ │ ├── health-tracker.ts # Provider health monitoring
484
681
  │ │ └── pricing.ts # Cost-aware routing
682
+ │ ├── background/ # Background task execution
683
+ │ │ └── task-runner.ts # Queue-based async task runner
684
+ │ ├── hooks/ # Hook system
685
+ │ │ ├── hook-executor.ts # Hook command execution
686
+ │ │ └── hook-manager.ts # Hook registration and dispatch
687
+ │ ├── skills/ # Skills hot-reload
688
+ │ │ ├── skill-loader.ts # Skill file discovery and parsing
689
+ │ │ ├── skill-executor.ts # Skill action execution
690
+ │ │ └── hot-reloader.ts # File watcher for hot-reload
691
+ │ ├── observability/ # Logging and debugging
692
+ │ │ ├── logger.ts # Structured logging
693
+ │ │ └── debug-logger.ts # Debug output with environment control
485
694
  │ ├── persistence/ # State persistence
486
695
  │ ├── config/ # Configuration management
487
696
  │ └── router/ # Routing engine
@@ -516,6 +725,28 @@ pnpm lint:fix
516
725
  pnpm typecheck
517
726
  ```
518
727
 
728
+ ### Debug Logging
729
+
730
+ Agent Foundry provides enhanced debug logging controlled via environment variables:
731
+
732
+ ```bash
733
+ # Enable debug logging
734
+ export AGENT_FOUNDRY_DEBUG=true
735
+
736
+ # Write debug logs to a file
737
+ export AGENT_FOUNDRY_DEBUG_FILE=/path/to/debug.log
738
+
739
+ # Include verbose details (API payloads, full stack traces)
740
+ export AGENT_FOUNDRY_DEBUG_VERBOSE=true
741
+ ```
742
+
743
+ Debug logging includes:
744
+ - Provider API calls and responses
745
+ - Failover decisions and health tracking
746
+ - Hook execution and timing
747
+ - Skill loading and hot-reload events
748
+ - Context manager token tracking
749
+
519
750
  ---
520
751
 
521
752
  ## Security
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Background Module
3
+ *
4
+ * Provides background task execution for non-blocking agent invocations
5
+ * and pipeline steps. Supports concurrency control, cancellation,
6
+ * progress tracking, and event-based notifications.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { BackgroundTaskRunner } from './background/index.js';
11
+ *
12
+ * const runner = new BackgroundTaskRunner({ maxConcurrent: 3 }, logger);
13
+ *
14
+ * // Submit a background agent invocation
15
+ * const taskId = await runner.run(
16
+ * 'agent_invocation',
17
+ * 'Review authentication code',
18
+ * async () => {
19
+ * return await orchestrator.executeWithFailover('reviewer', messages, options);
20
+ * },
21
+ * { role: 'reviewer', provider: 'openai' }
22
+ * );
23
+ *
24
+ * // Check status later
25
+ * const task = runner.getTask(taskId);
26
+ *
27
+ * // Or wait for completion
28
+ * const completed = await runner.waitFor(taskId, 60000);
29
+ * ```
30
+ */
31
+ export * from './types.js';
32
+ export { BackgroundTaskRunner } from './task-runner.js';
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/background/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Background Module
3
+ *
4
+ * Provides background task execution for non-blocking agent invocations
5
+ * and pipeline steps. Supports concurrency control, cancellation,
6
+ * progress tracking, and event-based notifications.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { BackgroundTaskRunner } from './background/index.js';
11
+ *
12
+ * const runner = new BackgroundTaskRunner({ maxConcurrent: 3 }, logger);
13
+ *
14
+ * // Submit a background agent invocation
15
+ * const taskId = await runner.run(
16
+ * 'agent_invocation',
17
+ * 'Review authentication code',
18
+ * async () => {
19
+ * return await orchestrator.executeWithFailover('reviewer', messages, options);
20
+ * },
21
+ * { role: 'reviewer', provider: 'openai' }
22
+ * );
23
+ *
24
+ * // Check status later
25
+ * const task = runner.getTask(taskId);
26
+ *
27
+ * // Or wait for completion
28
+ * const completed = await runner.waitFor(taskId, 60000);
29
+ * ```
30
+ */
31
+ export * from './types.js';
32
+ export { BackgroundTaskRunner } from './task-runner.js';
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/background/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Background Task Runner
3
+ *
4
+ * Manages background task execution for non-blocking agent invocations
5
+ * and pipeline steps. Supports concurrency limits, cancellation,
6
+ * progress tracking, and event-based notifications.
7
+ */
8
+ import { EventEmitter } from 'events';
9
+ import type { Logger } from '../observability/logger.js';
10
+ import type { BackgroundTask, BackgroundTaskConfig, BackgroundTaskType, SubmitTaskOptions, SerializedBackgroundTask } from './types.js';
11
+ /**
12
+ * Manages background task execution with concurrency control.
13
+ *
14
+ * Features:
15
+ * - Queue-based execution with configurable concurrency
16
+ * - Task cancellation via AbortController
17
+ * - Progress tracking and notifications
18
+ * - Event emission for task lifecycle
19
+ * - Automatic cleanup of old tasks
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const runner = new BackgroundTaskRunner({ maxConcurrent: 3 }, logger);
24
+ *
25
+ * // Submit a background task
26
+ * const taskId = await runner.run(
27
+ * 'agent_invocation',
28
+ * 'Review authentication code',
29
+ * async () => {
30
+ * return await orchestrator.executeWithFailover('reviewer', messages, options);
31
+ * },
32
+ * { role: 'reviewer', provider: 'openai' }
33
+ * );
34
+ *
35
+ * // Check status later
36
+ * const task = runner.getTask(taskId);
37
+ * if (task?.status === 'completed') {
38
+ * console.log('Result:', task.result);
39
+ * }
40
+ *
41
+ * // Or wait for completion
42
+ * const completed = await runner.waitFor(taskId, 60000);
43
+ * ```
44
+ */
45
+ export declare class BackgroundTaskRunner extends EventEmitter {
46
+ private readonly tasks;
47
+ private readonly queue;
48
+ private runningCount;
49
+ private readonly config;
50
+ private readonly logger;
51
+ private isEnabled;
52
+ private isShuttingDown;
53
+ constructor(config: Partial<BackgroundTaskConfig>, logger: Logger);
54
+ /**
55
+ * Check if background tasks are enabled.
56
+ * Respects AGENT_FOUNDRY_DISABLE_BACKGROUND_TASKS env var.
57
+ */
58
+ isBackgroundEnabled(): boolean;
59
+ /**
60
+ * Enable or disable background task execution.
61
+ */
62
+ setEnabled(enabled: boolean): void;
63
+ /**
64
+ * Submit a task to run in the background.
65
+ * Returns immediately with task ID.
66
+ *
67
+ * @param task - Task definition (without id, status, createdAt)
68
+ * @returns Task ID for tracking
69
+ */
70
+ submit(task: Omit<BackgroundTask, 'id' | 'status' | 'createdAt'>): string;
71
+ /**
72
+ * Execute a function as a background task.
73
+ *
74
+ * @param type - Task type
75
+ * @param description - Task description
76
+ * @param fn - Async function to execute
77
+ * @param options - Additional options
78
+ * @returns Task ID for tracking
79
+ */
80
+ run<T>(type: BackgroundTaskType, description: string, fn: () => Promise<T>, options?: SubmitTaskOptions): Promise<string>;
81
+ /**
82
+ * Get task by ID.
83
+ */
84
+ getTask(taskId: string): BackgroundTask | undefined;
85
+ /**
86
+ * Get all tasks.
87
+ */
88
+ getAllTasks(): BackgroundTask[];
89
+ /**
90
+ * Get running tasks.
91
+ */
92
+ getRunningTasks(): BackgroundTask[];
93
+ /**
94
+ * Get pending tasks in queue.
95
+ */
96
+ getPendingTasks(): BackgroundTask[];
97
+ /**
98
+ * Get completed tasks.
99
+ */
100
+ getCompletedTasks(): BackgroundTask[];
101
+ /**
102
+ * Cancel a running or pending task.
103
+ *
104
+ * @param taskId - ID of task to cancel
105
+ * @returns true if task was cancelled, false if not found or already complete
106
+ */
107
+ cancel(taskId: string): boolean;
108
+ /**
109
+ * Wait for a task to complete.
110
+ *
111
+ * @param taskId - ID of task to wait for
112
+ * @param timeout - Maximum time to wait in ms (default: 60000)
113
+ * @returns The completed task
114
+ * @throws Error if task not found or timeout exceeded
115
+ */
116
+ waitFor(taskId: string, timeout?: number): Promise<BackgroundTask>;
117
+ /**
118
+ * Update task progress.
119
+ *
120
+ * @param taskId - ID of task to update
121
+ * @param progress - Progress percentage (0-100)
122
+ * @param message - Optional progress message
123
+ */
124
+ updateProgress(taskId: string, progress: number, message?: string): void;
125
+ /**
126
+ * Clean up completed/failed tasks older than specified age.
127
+ *
128
+ * @param maxAgeMs - Maximum age in ms (default: 1 hour)
129
+ * @returns Number of tasks cleaned up
130
+ */
131
+ cleanup(maxAgeMs?: number): number;
132
+ /**
133
+ * Shutdown the runner - cancel pending tasks and wait for running tasks.
134
+ *
135
+ * @param timeout - Maximum time to wait for running tasks in ms (default: 30000)
136
+ */
137
+ shutdown(timeout?: number): Promise<void>;
138
+ /**
139
+ * Get statistics about the task runner.
140
+ */
141
+ getStats(): {
142
+ pending: number;
143
+ running: number;
144
+ completed: number;
145
+ failed: number;
146
+ cancelled: number;
147
+ total: number;
148
+ queueLength: number;
149
+ maxConcurrent: number;
150
+ };
151
+ /**
152
+ * Serialize tasks for persistence.
153
+ * Only serializes metadata, not results or errors.
154
+ */
155
+ serializeTasks(): SerializedBackgroundTask[];
156
+ /**
157
+ * Process the task queue, starting tasks up to maxConcurrent.
158
+ */
159
+ private processQueue;
160
+ /**
161
+ * Execute a single task.
162
+ */
163
+ private executeTask;
164
+ /**
165
+ * Mark a task as completed.
166
+ */
167
+ private markCompleted;
168
+ /**
169
+ * Mark a task as failed.
170
+ */
171
+ private markFailed;
172
+ /**
173
+ * Send a notification if enabled.
174
+ */
175
+ private notify;
176
+ }
177
+ //# sourceMappingURL=task-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-runner.d.ts","sourceRoot":"","sources":["../../src/background/task-runner.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EAEpB,kBAAkB,EAGlB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAwBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,oBAAqB,SAAQ,YAAY;IACpD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0C;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwB;IAC9C,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QA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