copilot-flow 0.3.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 (95) hide show
  1. package/README.md +300 -0
  2. package/bin/copilot-flow.js +13 -0
  3. package/dist/agents/executor.d.ts +24 -0
  4. package/dist/agents/executor.d.ts.map +1 -0
  5. package/dist/agents/executor.js +85 -0
  6. package/dist/agents/executor.js.map +1 -0
  7. package/dist/agents/pool.d.ts +22 -0
  8. package/dist/agents/pool.d.ts.map +1 -0
  9. package/dist/agents/pool.js +84 -0
  10. package/dist/agents/pool.js.map +1 -0
  11. package/dist/agents/registry.d.ts +16 -0
  12. package/dist/agents/registry.d.ts.map +1 -0
  13. package/dist/agents/registry.js +140 -0
  14. package/dist/agents/registry.js.map +1 -0
  15. package/dist/commands/agent.d.ts +3 -0
  16. package/dist/commands/agent.d.ts.map +1 -0
  17. package/dist/commands/agent.js +105 -0
  18. package/dist/commands/agent.js.map +1 -0
  19. package/dist/commands/doctor.d.ts +3 -0
  20. package/dist/commands/doctor.d.ts.map +1 -0
  21. package/dist/commands/doctor.js +119 -0
  22. package/dist/commands/doctor.js.map +1 -0
  23. package/dist/commands/hooks.d.ts +3 -0
  24. package/dist/commands/hooks.d.ts.map +1 -0
  25. package/dist/commands/hooks.js +75 -0
  26. package/dist/commands/hooks.js.map +1 -0
  27. package/dist/commands/index.d.ts +5 -0
  28. package/dist/commands/index.d.ts.map +1 -0
  29. package/dist/commands/index.js +31 -0
  30. package/dist/commands/index.js.map +1 -0
  31. package/dist/commands/init.d.ts +3 -0
  32. package/dist/commands/init.d.ts.map +1 -0
  33. package/dist/commands/init.js +37 -0
  34. package/dist/commands/init.js.map +1 -0
  35. package/dist/commands/memory.d.ts +3 -0
  36. package/dist/commands/memory.d.ts.map +1 -0
  37. package/dist/commands/memory.js +109 -0
  38. package/dist/commands/memory.js.map +1 -0
  39. package/dist/commands/route.d.ts +3 -0
  40. package/dist/commands/route.d.ts.map +1 -0
  41. package/dist/commands/route.js +36 -0
  42. package/dist/commands/route.js.map +1 -0
  43. package/dist/commands/status.d.ts +3 -0
  44. package/dist/commands/status.d.ts.map +1 -0
  45. package/dist/commands/status.js +58 -0
  46. package/dist/commands/status.js.map +1 -0
  47. package/dist/commands/swarm.d.ts +3 -0
  48. package/dist/commands/swarm.d.ts.map +1 -0
  49. package/dist/commands/swarm.js +106 -0
  50. package/dist/commands/swarm.js.map +1 -0
  51. package/dist/config.d.ts +16 -0
  52. package/dist/config.d.ts.map +1 -0
  53. package/dist/config.js +95 -0
  54. package/dist/config.js.map +1 -0
  55. package/dist/core/client-manager.d.ts +19 -0
  56. package/dist/core/client-manager.d.ts.map +1 -0
  57. package/dist/core/client-manager.js +69 -0
  58. package/dist/core/client-manager.js.map +1 -0
  59. package/dist/core/error-handler.d.ts +25 -0
  60. package/dist/core/error-handler.d.ts.map +1 -0
  61. package/dist/core/error-handler.js +135 -0
  62. package/dist/core/error-handler.js.map +1 -0
  63. package/dist/core/retry.d.ts +56 -0
  64. package/dist/core/retry.d.ts.map +1 -0
  65. package/dist/core/retry.js +107 -0
  66. package/dist/core/retry.js.map +1 -0
  67. package/dist/hooks/executor.d.ts +25 -0
  68. package/dist/hooks/executor.d.ts.map +1 -0
  69. package/dist/hooks/executor.js +57 -0
  70. package/dist/hooks/executor.js.map +1 -0
  71. package/dist/hooks/registry.d.ts +22 -0
  72. package/dist/hooks/registry.d.ts.map +1 -0
  73. package/dist/hooks/registry.js +36 -0
  74. package/dist/hooks/registry.js.map +1 -0
  75. package/dist/index.d.ts +20 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +52 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/memory/store.d.ts +32 -0
  80. package/dist/memory/store.d.ts.map +1 -0
  81. package/dist/memory/store.js +149 -0
  82. package/dist/memory/store.js.map +1 -0
  83. package/dist/output.d.ts +26 -0
  84. package/dist/output.d.ts.map +1 -0
  85. package/dist/output.js +157 -0
  86. package/dist/output.js.map +1 -0
  87. package/dist/swarm/coordinator.d.ts +20 -0
  88. package/dist/swarm/coordinator.d.ts.map +1 -0
  89. package/dist/swarm/coordinator.js +129 -0
  90. package/dist/swarm/coordinator.js.map +1 -0
  91. package/dist/types.d.ts +99 -0
  92. package/dist/types.d.ts.map +1 -0
  93. package/dist/types.js +22 -0
  94. package/dist/types.js.map +1 -0
  95. package/package.json +50 -0
package/README.md ADDED
@@ -0,0 +1,300 @@
1
+ # copilot-flow
2
+
3
+ Multi-agent orchestration framework for **GitHub Copilot CLI** — inspired by [Ruflo (claude-flow)](https://github.com/ruvnet/claude-flow).
4
+
5
+ copilot-flow brings the same multi-agent swarm patterns as Ruflo to the GitHub Copilot ecosystem, using the official [`@github/copilot-sdk`](https://github.com/github/copilot-sdk) to programmatically control the `copilot` CLI.
6
+
7
+ ---
8
+
9
+ ## Prerequisites
10
+
11
+ - **Node.js** >= 20
12
+ - **GitHub Copilot CLI** (`copilot`) installed and authenticated
13
+ - A GitHub account with Copilot access
14
+
15
+ ```bash
16
+ # Install and authenticate Copilot CLI
17
+ # Follow instructions at https://github.com/github/copilot
18
+ copilot login
19
+ ```
20
+
21
+ ---
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install -g copilot-flow
27
+ # or run without installing:
28
+ npx copilot-flow <command>
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Quick Start
34
+
35
+ ```bash
36
+ # 1. Initialise in your project
37
+ copilot-flow init
38
+
39
+ # 2. Run a single agent
40
+ copilot-flow agent spawn --type coder --task "Write a REST API endpoint for user registration" --stream
41
+
42
+ # 3. Run a multi-agent swarm
43
+ copilot-flow swarm start --task "Build a JWT authentication module" --stream
44
+
45
+ # 4. Check system health
46
+ copilot-flow doctor
47
+ ```
48
+
49
+ ---
50
+
51
+ ## Commands
52
+
53
+ ### `init`
54
+ Scaffold a `.copilot-flow/config.json` configuration file.
55
+
56
+ ```bash
57
+ copilot-flow init
58
+ copilot-flow init --model gpt-4o --topology hierarchical --max-agents 6
59
+ ```
60
+
61
+ ### `agent`
62
+
63
+ ```bash
64
+ # Spawn an agent for a task (auto-routes to best agent type)
65
+ copilot-flow agent spawn --task "Fix the authentication bug" --stream
66
+
67
+ # Specify the agent type explicitly
68
+ copilot-flow agent spawn --type security-auditor --task "Audit the auth module"
69
+
70
+ # With custom retry settings
71
+ copilot-flow agent spawn --type coder --task "..." \
72
+ --max-retries 5 \
73
+ --retry-delay 2000 \
74
+ --retry-strategy exponential
75
+
76
+ # Disable retries entirely
77
+ copilot-flow agent spawn --type coder --task "..." --no-retry
78
+
79
+ # List agent states
80
+ copilot-flow agent list
81
+ copilot-flow agent types
82
+ ```
83
+
84
+ ### `swarm`
85
+
86
+ ```bash
87
+ # Run a hierarchical swarm (researcher → coder → reviewer pipeline by default)
88
+ copilot-flow swarm start --task "Implement OAuth2 login flow" --stream
89
+
90
+ # Specify agent pipeline manually
91
+ copilot-flow swarm start --task "..." --agents researcher,coder,tester,reviewer
92
+
93
+ # Choose topology
94
+ copilot-flow swarm start --task "..." --topology mesh
95
+ copilot-flow swarm start --task "..." --topology sequential
96
+
97
+ # Configure swarm defaults
98
+ copilot-flow swarm init --topology hierarchical --max-agents 8
99
+ copilot-flow swarm status
100
+ ```
101
+
102
+ ### `memory`
103
+
104
+ ```bash
105
+ copilot-flow memory store --namespace project --key architecture --value "microservices"
106
+ copilot-flow memory retrieve --namespace project --key architecture
107
+ copilot-flow memory search --namespace project --query "auth"
108
+ copilot-flow memory list --namespace project
109
+ copilot-flow memory delete --namespace project --key architecture
110
+ copilot-flow memory clear --namespace project
111
+
112
+ # With TTL (entry expires after 1 hour)
113
+ copilot-flow memory store --namespace project --key temp --value "..." --ttl 3600000
114
+ ```
115
+
116
+ ### `hooks`
117
+
118
+ ```bash
119
+ copilot-flow hooks fire pre-task --data '{"task":"implement login"}'
120
+ copilot-flow hooks fire post-task --data '{"success":true}'
121
+ copilot-flow hooks pre-task
122
+ copilot-flow hooks post-task
123
+ copilot-flow hooks session-start
124
+ copilot-flow hooks session-end
125
+ copilot-flow hooks list
126
+ ```
127
+
128
+ ### `route`
129
+
130
+ ```bash
131
+ # Find the best agent type for a task
132
+ copilot-flow route task --task "Fix a null pointer exception in authentication"
133
+ # → suggests: debugger
134
+
135
+ copilot-flow route list-agents
136
+ ```
137
+
138
+ ### `status` / `doctor`
139
+
140
+ ```bash
141
+ copilot-flow status
142
+ copilot-flow doctor
143
+ ```
144
+
145
+ ---
146
+
147
+ ## Retry System
148
+
149
+ Every command that makes Copilot API calls supports configurable retry with multiple backoff strategies:
150
+
151
+ | Flag | Default | Description |
152
+ |------|---------|-------------|
153
+ | `--max-retries <n>` | 3 | Maximum retry attempts |
154
+ | `--retry-delay <ms>` | 1000 | Initial delay before first retry |
155
+ | `--retry-strategy <type>` | `exponential` | `exponential` \| `linear` \| `constant` \| `fibonacci` |
156
+ | `--no-retry` | — | Disable retries entirely |
157
+
158
+ **Backoff strategies:**
159
+ - `exponential`: `delay = initialDelay × 2^(attempt-1)` — doubles each time
160
+ - `linear`: `delay = initialDelay × attempt` — grows linearly
161
+ - `constant`: `delay = initialDelay` — fixed interval
162
+ - `fibonacci`: `delay = initialDelay × fib(attempt)` — Fibonacci sequence
163
+
164
+ All strategies apply ±10% jitter by default to prevent thundering herd.
165
+
166
+ **Retried automatically:** network errors (`ECONNRESET`, `ETIMEDOUT`), rate limits (429), server errors (5xx), session crashes, timeouts.
167
+
168
+ **Not retried:** authentication errors (401), authorization errors (403), not found (404), validation errors.
169
+
170
+ ---
171
+
172
+ ## Agent Types
173
+
174
+ | Agent | Best For |
175
+ |-------|---------|
176
+ | `coder` | Implementation, refactoring |
177
+ | `researcher` | Investigation, information gathering |
178
+ | `tester` | Unit/integration tests, TDD |
179
+ | `reviewer` | Code review, quality analysis |
180
+ | `architect` | System design, architecture decisions |
181
+ | `coordinator` | Multi-agent workflow decomposition |
182
+ | `analyst` | Requirements, specifications |
183
+ | `debugger` | Bug diagnosis, root cause analysis |
184
+ | `documenter` | README, API docs, inline comments |
185
+ | `optimizer` | Performance, memory efficiency |
186
+ | `security-auditor` | Vulnerability scanning, OWASP |
187
+ | `performance-engineer` | Benchmarking, scalability |
188
+
189
+ If you don't specify `--type`, copilot-flow automatically routes based on keywords in your task description.
190
+
191
+ ---
192
+
193
+ ## Swarm Topologies
194
+
195
+ | Topology | Behaviour |
196
+ |----------|-----------|
197
+ | `hierarchical` | Independent tasks run in parallel; tasks with dependencies wait. Best for most workloads. |
198
+ | `mesh` | All tasks run concurrently with shared memory. Best for independent parallel work. |
199
+ | `sequential` | Tasks run one at a time in order. Best for strictly ordered pipelines. |
200
+
201
+ ---
202
+
203
+ ## Programmatic API
204
+
205
+ ```typescript
206
+ import {
207
+ runAgentTask,
208
+ runSwarm,
209
+ withRetry,
210
+ RetryPredicates,
211
+ getMemoryStore,
212
+ globalHooks,
213
+ } from 'copilot-flow';
214
+
215
+ // Run a single agent
216
+ const result = await runAgentTask('coder', 'Write a binary search function', {
217
+ retryConfig: {
218
+ maxAttempts: 3,
219
+ backoffStrategy: 'exponential',
220
+ onRetry: (err, attempt) => console.log(`Retry ${attempt}: ${err.message}`),
221
+ },
222
+ onChunk: chunk => process.stdout.write(chunk),
223
+ });
224
+
225
+ // Run a swarm
226
+ const results = await runSwarm([
227
+ { id: 'research', agentType: 'researcher', prompt: 'Research OAuth2 best practices' },
228
+ { id: 'implement', agentType: 'coder', prompt: 'Implement OAuth2 login', dependsOn: ['research'] },
229
+ { id: 'test', agentType: 'tester', prompt: 'Write tests for OAuth2 flow', dependsOn: ['implement'] },
230
+ ], 'hierarchical');
231
+
232
+ // Use memory between runs
233
+ const mem = getMemoryStore();
234
+ mem.store('project', 'context', 'e-commerce platform with React + Node.js');
235
+
236
+ // Register hooks
237
+ globalHooks.on('post-task', async ctx => {
238
+ console.log('Task completed:', ctx.data);
239
+ });
240
+
241
+ // Use retry directly
242
+ const result2 = await withRetry(
243
+ () => fetch('https://api.example.com/data').then(r => r.json()),
244
+ { maxAttempts: 5, backoffStrategy: 'fibonacci', retryOn: RetryPredicates.networkErrors }
245
+ );
246
+ ```
247
+
248
+ ---
249
+
250
+ ## Configuration
251
+
252
+ `.copilot-flow/config.json`:
253
+
254
+ ```json
255
+ {
256
+ "version": "1.0.0",
257
+ "defaultModel": "gpt-4o",
258
+ "swarm": {
259
+ "topology": "hierarchical",
260
+ "maxAgents": 8
261
+ },
262
+ "memory": {
263
+ "backend": "sqlite",
264
+ "path": ".copilot-flow/memory.db"
265
+ },
266
+ "retry": {
267
+ "maxAttempts": 3,
268
+ "initialDelayMs": 1000,
269
+ "maxDelayMs": 30000,
270
+ "backoffStrategy": "exponential",
271
+ "multiplier": 2,
272
+ "jitter": true
273
+ },
274
+ "hooks": {
275
+ "enabled": true,
276
+ "timeoutMs": 5000
277
+ }
278
+ }
279
+ ```
280
+
281
+ Environment variable overrides:
282
+ ```bash
283
+ GITHUB_TOKEN=ghp_... # GitHub token (uses logged-in user by default)
284
+ COPILOT_FLOW_DEFAULT_MODEL=gpt-4o
285
+ COPILOT_FLOW_MAX_RETRIES=3
286
+ COPILOT_FLOW_RETRY_DELAY_MS=1000
287
+ COPILOT_FLOW_LOG_LEVEL=info # debug | info | warn | error | silent
288
+ ```
289
+
290
+ ---
291
+
292
+ ## Attribution
293
+
294
+ > copilot-flow is inspired by **[Ruflo (claude-flow)](https://github.com/ruvnet/claude-flow)** — the multi-agent orchestration framework for Claude. copilot-flow brings the same swarm coordination patterns, memory system, hooks, and retry engine to the GitHub Copilot ecosystem using the official `@github/copilot-sdk`.
295
+
296
+ ---
297
+
298
+ ## License
299
+
300
+ MIT
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ require('dotenv/config');
5
+
6
+ // Register ts-node for development (no-op in production with compiled dist/)
7
+ try {
8
+ require('../dist/commands/index.js');
9
+ } catch {
10
+ // Fallback to ts-node in dev
11
+ require('ts-node/register');
12
+ require('../src/commands/index.ts');
13
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Agent executor — creates a Copilot session for an agent type and runs a task,
3
+ * wrapping everything with retry logic and streaming support.
4
+ */
5
+ import type { AgentType, AgentResult } from '../types.js';
6
+ import type { RetryConfig } from '../core/retry.js';
7
+ export type { AgentType, AgentResult };
8
+ export interface RunTaskOptions {
9
+ /** Override the model from the agent registry. */
10
+ model?: string;
11
+ /** Session timeout in ms. Default: 120_000 (2 minutes). */
12
+ timeoutMs?: number;
13
+ /** Retry configuration override. */
14
+ retryConfig?: Partial<RetryConfig>;
15
+ /** Called with each streamed text delta (for live output). */
16
+ onChunk?: (text: string) => void;
17
+ }
18
+ /**
19
+ * Run a task using a specific agent type.
20
+ * Creates a fresh Copilot session, sends the prompt, collects the response,
21
+ * and disconnects. Retries on transient failures.
22
+ */
23
+ export declare function runAgentTask(agentType: AgentType, task: string, options?: RunTaskOptions): Promise<AgentResult>;
24
+ //# sourceMappingURL=executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/agents/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;AAEvC,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,WAAW,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IACnC,8DAA8D;IAC9D,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,WAAW,CAAC,CAmFtB"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /**
3
+ * Agent executor — creates a Copilot session for an agent type and runs a task,
4
+ * wrapping everything with retry logic and streaming support.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.runAgentTask = runAgentTask;
8
+ const copilot_sdk_1 = require("@github/copilot-sdk");
9
+ const client_manager_js_1 = require("../core/client-manager.js");
10
+ const retry_js_1 = require("../core/retry.js");
11
+ const error_handler_js_1 = require("../core/error-handler.js");
12
+ const output_js_1 = require("../output.js");
13
+ const registry_js_1 = require("./registry.js");
14
+ /**
15
+ * Run a task using a specific agent type.
16
+ * Creates a fresh Copilot session, sends the prompt, collects the response,
17
+ * and disconnects. Retries on transient failures.
18
+ */
19
+ async function runAgentTask(agentType, task, options = {}) {
20
+ const def = (0, registry_js_1.getAgentDefinition)(agentType);
21
+ const model = options.model ?? def.model;
22
+ const timeoutMs = options.timeoutMs ?? 120_000;
23
+ const startTime = Date.now();
24
+ let attempts = 0;
25
+ const onRetry = (err, attempt, nextDelay) => {
26
+ output_js_1.output.warn(`[${agentType}] Retry ${attempt} in ${nextDelay}ms — ${err.message.slice(0, 80)}`);
27
+ };
28
+ let sessionId = '';
29
+ try {
30
+ const output_text = await (0, retry_js_1.withRetry)(async () => {
31
+ attempts++;
32
+ const client = await client_manager_js_1.clientManager.getClient();
33
+ const session = await client.createSession({
34
+ model,
35
+ systemMessage: { content: def.systemMessage },
36
+ onPermissionRequest: copilot_sdk_1.approveAll,
37
+ });
38
+ sessionId = session.sessionId;
39
+ output_js_1.output.debug(`[${agentType}] Session started: ${sessionId}`);
40
+ let collected = '';
41
+ if (options.onChunk) {
42
+ session.on('assistant.message_delta', (e) => {
43
+ const chunk = e.data.deltaContent ?? '';
44
+ options.onChunk(chunk);
45
+ collected += chunk;
46
+ });
47
+ }
48
+ const result = await session.sendAndWait({ prompt: task }, timeoutMs);
49
+ // Prefer the full message from sendAndWait; fall back to streamed text
50
+ const finalText = result?.data?.content ??
51
+ collected;
52
+ await session.disconnect();
53
+ output_js_1.output.debug(`[${agentType}] Session completed: ${sessionId}`);
54
+ return finalText;
55
+ }, {
56
+ ...options.retryConfig,
57
+ retryOn: options.retryConfig?.retryOn ?? retry_js_1.RetryPredicates.copilotErrors,
58
+ onRetry: options.retryConfig?.onRetry ?? onRetry,
59
+ });
60
+ return {
61
+ agentType,
62
+ agentId: `${agentType}-${Date.now()}`,
63
+ sessionId,
64
+ output: output_text,
65
+ durationMs: Date.now() - startTime,
66
+ attempts,
67
+ success: true,
68
+ };
69
+ }
70
+ catch (err) {
71
+ const classified = (0, error_handler_js_1.classifyError)(err);
72
+ output_js_1.output.error(`[${agentType}] Failed after ${attempts} attempt(s): ${classified.message}`);
73
+ return {
74
+ agentType,
75
+ agentId: `${agentType}-${Date.now()}`,
76
+ sessionId,
77
+ output: '',
78
+ durationMs: Date.now() - startTime,
79
+ attempts,
80
+ success: false,
81
+ error: classified.message,
82
+ };
83
+ }
84
+ }
85
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/agents/executor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA8BH,oCAuFC;AAnHD,qDAAiD;AACjD,iEAA0D;AAC1D,+CAA8D;AAC9D,+DAAyD;AACzD,4CAAsC;AACtC,+CAAmD;AAkBnD;;;;GAIG;AACI,KAAK,UAAU,YAAY,CAChC,SAAoB,EACpB,IAAY,EACZ,UAA0B,EAAE;IAE5B,MAAM,GAAG,GAAG,IAAA,gCAAkB,EAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC;IACzC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC;IAC/C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,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entType } from '../types.js';
5
+ export declare const agentPool: {
6
+ /** Register a new agent state. */
7
+ register(state: AgentState): void;
8
+ /** Update an existing agent state (partial). */
9
+ update(id: string, patch: Partial<AgentState>): void;
10
+ /** Get a single agent state by ID. */
11
+ get(id: string): AgentState | null;
12
+ /** List all agent states. */
13
+ list(filter?: {
14
+ type?: AgentType;
15
+ status?: AgentState["status"];
16
+ }): AgentState[];
17
+ /** Remove an agent state from disk. */
18
+ remove(id: string): void;
19
+ /** Remove all terminated/errored agents older than maxAgeMs. */
20
+ gc(maxAgeMs?: number): void;
21
+ };
22
+ //# sourceMappingURL=pool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../src/agents/pool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAczD,eAAO,MAAM,SAAS;IACpB,kCAAkC;oBAClB,UAAU,GAAG,IAAI;IAKjC,gDAAgD;eACrC,MAAM,SAAS,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI;IAOpD,sCAAsC;YAC9B,MAAM,GAAG,UAAU,GAAG,IAAI;IAUlC,6BAA6B;kBACf;QAAE,IAAI,CAAC,EAAE,SAAS,CAAC;QAAC,MAAM,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAA;KAAE,GAAG,UAAU,EAAE;IAkBhF,uCAAuC;eAC5B,MAAM,GAAG,IAAI;IAKxB,gEAAgE;2BAC3B,IAAI;CAW1C,CAAC"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * Agent pool — tracks active agent states in memory and persists them to disk.
4
+ */
5
+ var __importDefault = (this && this.__importDefault) || function (mod) {
6
+ return (mod && mod.__esModule) ? mod : { "default": mod };
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.agentPool = void 0;
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const AGENTS_DIR = path_1.default.join('.copilot-flow', 'agents');
13
+ function ensureDir() {
14
+ if (!fs_1.default.existsSync(AGENTS_DIR)) {
15
+ fs_1.default.mkdirSync(AGENTS_DIR, { recursive: true });
16
+ }
17
+ }
18
+ function agentPath(id) {
19
+ return path_1.default.join(AGENTS_DIR, `${id}.json`);
20
+ }
21
+ exports.agentPool = {
22
+ /** Register a new agent state. */
23
+ register(state) {
24
+ ensureDir();
25
+ fs_1.default.writeFileSync(agentPath(state.id), JSON.stringify(state, null, 2));
26
+ },
27
+ /** Update an existing agent state (partial). */
28
+ update(id, patch) {
29
+ const existing = exports.agentPool.get(id);
30
+ if (!existing)
31
+ return;
32
+ const updated = { ...existing, ...patch };
33
+ fs_1.default.writeFileSync(agentPath(id), JSON.stringify(updated, null, 2));
34
+ },
35
+ /** Get a single agent state by ID. */
36
+ get(id) {
37
+ const p = agentPath(id);
38
+ if (!fs_1.default.existsSync(p))
39
+ return null;
40
+ try {
41
+ return JSON.parse(fs_1.default.readFileSync(p, 'utf-8'));
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ },
47
+ /** List all agent states. */
48
+ list(filter) {
49
+ ensureDir();
50
+ const files = fs_1.default.readdirSync(AGENTS_DIR).filter(f => f.endsWith('.json'));
51
+ const agents = files.flatMap(f => {
52
+ try {
53
+ return [JSON.parse(fs_1.default.readFileSync(path_1.default.join(AGENTS_DIR, f), 'utf-8'))];
54
+ }
55
+ catch {
56
+ return [];
57
+ }
58
+ });
59
+ return agents.filter(a => {
60
+ if (filter?.type && a.type !== filter.type)
61
+ return false;
62
+ if (filter?.status && a.status !== filter.status)
63
+ return false;
64
+ return true;
65
+ });
66
+ },
67
+ /** Remove an agent state from disk. */
68
+ remove(id) {
69
+ const p = agentPath(id);
70
+ if (fs_1.default.existsSync(p))
71
+ fs_1.default.unlinkSync(p);
72
+ },
73
+ /** Remove all terminated/errored agents older than maxAgeMs. */
74
+ gc(maxAgeMs = 24 * 60 * 60 * 1_000) {
75
+ const now = Date.now();
76
+ for (const agent of exports.agentPool.list()) {
77
+ if ((agent.status === 'terminated' || agent.status === 'error') &&
78
+ now - agent.startedAt > maxAgeMs) {
79
+ exports.agentPool.remove(agent.id);
80
+ }
81
+ }
82
+ },
83
+ };
84
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../src/agents/pool.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;AAEH,4CAAoB;AACpB,gDAAwB;AAGxB,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;AAExD,SAAS,SAAS;IAChB,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,YAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,EAAU;IAC3B,OAAO,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC;AAEY,QAAA,SAAS,GAAG;IACvB,kCAAkC;IAClC,QAAQ,CAAC,KAAiB;QACxB,SAAS,EAAE,CAAC;QACZ,YAAE,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED,gDAAgD;IAChD,MAAM,CAAC,EAAU,EAAE,KAA0B;QAC3C,MAAM,QAAQ,GAAG,iBAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,MAAM,OAAO,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC;QAC1C,YAAE,CAAC,aAAa,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,KAAK,MAAM,CAAC,MAAM;gBAAE,OAAO,KAAK,CAAC;YAC/D,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAED,uCAAuC;IACvC,MAAM,CAAC,EAAU;QACf,MAAM,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,YAAE,CAAC,UAAU,CAAC,CAAC,CAAC;YAAE,YAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,gEAAgE;IAChE,EAAE,CAAC,QAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK;QAChC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,KAAK,MAAM,KAAK,IAAI,iBAAS,CAAC,IAAI,EAAE,EAAE,CAAC;YACrC,IACE,CAAC,KAAK,CAAC,MAAM,KAAK,YAAY,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC;gBAC3D,GAAG,GAAG,KAAK,CAAC,SAAS,GAAG,QAAQ,EAChC,CAAC;gBACD,iBAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Agent type registry — defines system prompts and capabilities for each
3
+ * built-in agent type. Inspired by Ruflo's 12 agent types.
4
+ */
5
+ import type { AgentDefinition, AgentType } from '../types.js';
6
+ export declare const AGENT_REGISTRY: Record<AgentType, AgentDefinition>;
7
+ /** Get the definition for an agent type, or throw if unknown. */
8
+ export declare function getAgentDefinition(type: AgentType): AgentDefinition;
9
+ /** Return all agent types as an array. */
10
+ export declare function listAgentTypes(): AgentType[];
11
+ /**
12
+ * Suggest the best agent type for a given task description.
13
+ * Simple keyword-based routing — no ML required.
14
+ */
15
+ export declare function routeTask(task: string): AgentType;
16
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/agents/registry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,eAAe,CA8G7D,CAAC;AAEF,iEAAiE;AACjE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,GAAG,eAAe,CAInE;AAED,0CAA0C;AAC1C,wBAAgB,cAAc,IAAI,SAAS,EAAE,CAE5C;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAgBjD"}