@clawswarm/core 0.1.0-alpha
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 +41 -0
- package/dist/agent.d.ts +79 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +146 -0
- package/dist/agent.js.map +1 -0
- package/dist/chief.d.ts +80 -0
- package/dist/chief.d.ts.map +1 -0
- package/dist/chief.js +221 -0
- package/dist/chief.js.map +1 -0
- package/dist/clawswarm.d.ts +84 -0
- package/dist/clawswarm.d.ts.map +1 -0
- package/dist/clawswarm.js +224 -0
- package/dist/clawswarm.js.map +1 -0
- package/dist/goal.d.ts +66 -0
- package/dist/goal.d.ts.map +1 -0
- package/dist/goal.js +164 -0
- package/dist/goal.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/swarm.d.ts +67 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +201 -0
- package/dist/swarm.js.map +1 -0
- package/dist/task.d.ts +86 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +177 -0
- package/dist/task.js.map +1 -0
- package/dist/types.d.ts +189 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +67 -0
- package/src/__tests__/integration.test.ts +686 -0
- package/src/agent.ts +163 -0
- package/src/chief.ts +264 -0
- package/src/clawswarm.ts +257 -0
- package/src/goal.ts +183 -0
- package/src/index.ts +62 -0
- package/src/swarm.ts +225 -0
- package/src/task.ts +204 -0
- package/src/types.ts +240 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ClawSwarm — main orchestrator class.
|
|
4
|
+
*
|
|
5
|
+
* Creates and manages a swarm of specialist agents, decomposes goals
|
|
6
|
+
* into tasks, runs the chief review pipeline, and emits events throughout.
|
|
7
|
+
*
|
|
8
|
+
* @module @clawswarm/core/clawswarm
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.ClawSwarm = void 0;
|
|
15
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
16
|
+
const agent_js_1 = require("./agent.js");
|
|
17
|
+
const goal_js_1 = require("./goal.js");
|
|
18
|
+
const task_js_1 = require("./task.js");
|
|
19
|
+
const chief_js_1 = require("./chief.js");
|
|
20
|
+
// ─── ClawSwarm ────────────────────────────────────────────────────────────────
|
|
21
|
+
/**
|
|
22
|
+
* The primary interface for the ClawSwarm framework.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const swarm = new ClawSwarm({
|
|
27
|
+
* agents: [
|
|
28
|
+
* Agent.research({ model: 'claude-sonnet-4' }),
|
|
29
|
+
* Agent.code({ model: 'gpt-4o' }),
|
|
30
|
+
* Agent.ops({ model: 'gemini-pro' }),
|
|
31
|
+
* ],
|
|
32
|
+
* chiefReview: { autoApproveThreshold: 8, humanReviewThreshold: 5 },
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* swarm.on('task:completed', (task) => console.log('✅', task.title));
|
|
36
|
+
*
|
|
37
|
+
* const result = await swarm.execute(goal);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
class ClawSwarm extends eventemitter3_1.default {
|
|
41
|
+
goalManager;
|
|
42
|
+
taskManager;
|
|
43
|
+
planner;
|
|
44
|
+
reviewer;
|
|
45
|
+
agents;
|
|
46
|
+
config;
|
|
47
|
+
constructor(config) {
|
|
48
|
+
super();
|
|
49
|
+
this.config = config;
|
|
50
|
+
this.goalManager = new goal_js_1.GoalManager();
|
|
51
|
+
this.taskManager = new task_js_1.TaskManager();
|
|
52
|
+
this.planner = new goal_js_1.GoalPlanner(config);
|
|
53
|
+
this.reviewer = new chief_js_1.ChiefReviewer(config.chiefReview);
|
|
54
|
+
this.agents = new Map();
|
|
55
|
+
// Register agents
|
|
56
|
+
for (const agentConfig of config.agents) {
|
|
57
|
+
const agent = new agent_js_1.Agent(agentConfig);
|
|
58
|
+
// Use last-registered agent if multiple of same type
|
|
59
|
+
this.agents.set(agentConfig.type, agent);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// ─── Public API ───────────────────────────────────────────────────────────
|
|
63
|
+
/**
|
|
64
|
+
* Create a new goal (without executing it).
|
|
65
|
+
* Use `execute()` to run the goal.
|
|
66
|
+
*/
|
|
67
|
+
createGoal(input) {
|
|
68
|
+
const goal = this.goalManager.create(input);
|
|
69
|
+
this.emit('goal:created', goal);
|
|
70
|
+
return goal;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Execute a goal end-to-end:
|
|
74
|
+
* 1. Decompose into tasks (Planner)
|
|
75
|
+
* 2. Run each task with the appropriate specialist agent
|
|
76
|
+
* 3. Review each task with ChiefReviewer
|
|
77
|
+
* 4. Handle rework cycles
|
|
78
|
+
* 5. Return final result
|
|
79
|
+
*/
|
|
80
|
+
async execute(goal) {
|
|
81
|
+
const startTime = Date.now();
|
|
82
|
+
let hadHumanReview = false;
|
|
83
|
+
// 1. Planning phase
|
|
84
|
+
this.goalManager.setStatus(goal.id, 'planning');
|
|
85
|
+
this.emit('goal:planning', goal);
|
|
86
|
+
const tasks = await this.planner.decompose(goal, this.taskManager);
|
|
87
|
+
this.goalManager.setTasks(goal.id, tasks);
|
|
88
|
+
// 2. Execution phase
|
|
89
|
+
this.goalManager.setStatus(goal.id, 'in_progress');
|
|
90
|
+
try {
|
|
91
|
+
// Process tasks in waves, respecting dependencies
|
|
92
|
+
let iterations = 0;
|
|
93
|
+
const maxIterations = tasks.length * 4; // safety valve
|
|
94
|
+
while (!this.taskManager.isGoalDone(goal.id) && iterations < maxIterations) {
|
|
95
|
+
iterations++;
|
|
96
|
+
const ready = this.taskManager.getReady(goal.id);
|
|
97
|
+
if (ready.length === 0)
|
|
98
|
+
break;
|
|
99
|
+
// Run ready tasks concurrently
|
|
100
|
+
await Promise.all(ready.map(task => this._executeTask(task)));
|
|
101
|
+
// Check for human review requirement
|
|
102
|
+
const reviewTasks = this.taskManager
|
|
103
|
+
.getByGoal(goal.id)
|
|
104
|
+
.filter(t => t.status === 'review');
|
|
105
|
+
for (const task of reviewTasks) {
|
|
106
|
+
const review = await this.reviewer.review(task);
|
|
107
|
+
hadHumanReview = hadHumanReview || (review.decision === 'human_review');
|
|
108
|
+
await this._handleReview(task, review);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// 3. Collect deliverables
|
|
112
|
+
const completedTasks = this.taskManager
|
|
113
|
+
.getByGoal(goal.id)
|
|
114
|
+
.filter(t => t.status === 'completed');
|
|
115
|
+
const allDeliverables = completedTasks.flatMap(t => t.deliverables);
|
|
116
|
+
const updatedGoal = this.goalManager.setStatus(goal.id, 'completed');
|
|
117
|
+
this.emit('goal:completed', updatedGoal);
|
|
118
|
+
return {
|
|
119
|
+
goal: updatedGoal,
|
|
120
|
+
deliverables: allDeliverables,
|
|
121
|
+
cost: updatedGoal.cost,
|
|
122
|
+
hadHumanReview,
|
|
123
|
+
durationMs: Date.now() - startTime,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
128
|
+
const failedGoal = this.goalManager.setStatus(goal.id, 'failed');
|
|
129
|
+
this.emit('goal:failed', failedGoal, err);
|
|
130
|
+
throw err;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get a registered agent by type.
|
|
135
|
+
*/
|
|
136
|
+
getAgent(type) {
|
|
137
|
+
return this.agents.get(type);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* List all registered agents.
|
|
141
|
+
*/
|
|
142
|
+
listAgents() {
|
|
143
|
+
return Array.from(this.agents.values());
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get the ChiefReviewer instance (for inspection or custom review logic).
|
|
147
|
+
*/
|
|
148
|
+
getReviewer() {
|
|
149
|
+
return this.reviewer;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the TaskManager instance (for direct task inspection).
|
|
153
|
+
*/
|
|
154
|
+
getTaskManager() {
|
|
155
|
+
return this.taskManager;
|
|
156
|
+
}
|
|
157
|
+
// ─── Private ──────────────────────────────────────────────────────────────
|
|
158
|
+
/**
|
|
159
|
+
* Execute a single task with the appropriate agent.
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
async _executeTask(task) {
|
|
163
|
+
const agentType = task.assignedTo ?? 'code';
|
|
164
|
+
const agent = this.agents.get(agentType);
|
|
165
|
+
if (!agent) {
|
|
166
|
+
this.taskManager.fail(task.id, new Error(`No agent registered for type: ${agentType}`));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
this.taskManager.assign(task.id, agentType);
|
|
171
|
+
this.emit('task:assigned', task, agentType);
|
|
172
|
+
this.taskManager.start(task.id);
|
|
173
|
+
this.emit('task:started', task);
|
|
174
|
+
const deliverables = await agent.execute(task);
|
|
175
|
+
this.taskManager.submitForReview(task.id, deliverables);
|
|
176
|
+
this.emit('task:completed', task);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
180
|
+
this.taskManager.fail(task.id, err);
|
|
181
|
+
this.emit('task:failed', task, err);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Handle a chief review result for a task.
|
|
186
|
+
* @internal
|
|
187
|
+
*/
|
|
188
|
+
async _handleReview(task, review) {
|
|
189
|
+
this.emit('task:review', task, review);
|
|
190
|
+
switch (review.decision) {
|
|
191
|
+
case 'approved': {
|
|
192
|
+
this.taskManager.approve(task.id);
|
|
193
|
+
this.taskManager.complete(task.id);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case 'human_review': {
|
|
197
|
+
this.emit('human:review_required', task, review);
|
|
198
|
+
// In the default flow, human_review blocks until someone calls approve/reject
|
|
199
|
+
// For automated flows, we treat it as approved after emitting the event
|
|
200
|
+
this.taskManager.approve(task.id);
|
|
201
|
+
this.taskManager.complete(task.id);
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case 'rejected': {
|
|
205
|
+
this.emit('task:rejected', task, review);
|
|
206
|
+
try {
|
|
207
|
+
// Attempt rework
|
|
208
|
+
this.taskManager.rework(task.id, review.feedback);
|
|
209
|
+
this.emit('task:rework', task, review);
|
|
210
|
+
// Re-execute the task
|
|
211
|
+
const updatedTask = this.taskManager.get(task.id);
|
|
212
|
+
await this._executeTask(updatedTask);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
// Max rework exceeded — fail the task
|
|
216
|
+
this.taskManager.reject(task.id, review.feedback);
|
|
217
|
+
}
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.ClawSwarm = ClawSwarm;
|
|
224
|
+
//# sourceMappingURL=clawswarm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clawswarm.js","sourceRoot":"","sources":["../src/clawswarm.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;AAEH,kEAAyC;AACzC,yCAAmC;AACnC,uCAAqD;AACrD,uCAAwC;AACxC,yCAA2C;AAY3C,iFAAiF;AAEjF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,SAAU,SAAS,uBAAoD;IACjE,WAAW,CAAc;IACzB,WAAW,CAAc;IACzB,OAAO,CAAc;IACrB,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;oBACjB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;oBAClD,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;oBACvC,sBAAsB;oBACtB,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAE,CAAC;oBACnD,MAAM,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;gBACvC,CAAC;gBAAC,MAAM,CAAC;oBACP,sCAAsC;oBACtC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;gBACpD,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAlND,8BAkNC"}
|
package/dist/goal.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal decomposition and planning.
|
|
3
|
+
* @module @clawswarm/core/goal
|
|
4
|
+
*/
|
|
5
|
+
import { Goal, GoalStatus, CreateGoalInput, Task, SwarmConfig } from './types.js';
|
|
6
|
+
import { TaskManager } from './task.js';
|
|
7
|
+
/**
|
|
8
|
+
* Decomposes high-level goals into concrete, assignable tasks.
|
|
9
|
+
*
|
|
10
|
+
* The Planner analyzes a goal description and generates a task plan,
|
|
11
|
+
* assigns each task to the appropriate specialist agent, and sequences
|
|
12
|
+
* tasks based on their dependencies.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const planner = new GoalPlanner(swarmConfig);
|
|
17
|
+
* const tasks = await planner.decompose(goal, taskManager);
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class GoalPlanner {
|
|
21
|
+
private readonly config;
|
|
22
|
+
constructor(config: SwarmConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Decompose a goal into a list of tasks.
|
|
25
|
+
* Creates tasks via the TaskManager and returns them in execution order.
|
|
26
|
+
*/
|
|
27
|
+
decompose(goal: Goal, taskManager: TaskManager): Promise<Task[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Generate a task plan for a goal.
|
|
30
|
+
* In production, this calls an LLM with the planner system prompt.
|
|
31
|
+
* Returns structured step definitions.
|
|
32
|
+
*/
|
|
33
|
+
private _generatePlan;
|
|
34
|
+
/**
|
|
35
|
+
* Infer the primary execution agent type from the goal description.
|
|
36
|
+
*/
|
|
37
|
+
private _inferPrimaryAgent;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Manages the lifecycle of goals in a ClawSwarm instance.
|
|
41
|
+
*/
|
|
42
|
+
export declare class GoalManager {
|
|
43
|
+
private goals;
|
|
44
|
+
/**
|
|
45
|
+
* Create a new goal.
|
|
46
|
+
*/
|
|
47
|
+
create(input: CreateGoalInput): Goal;
|
|
48
|
+
/**
|
|
49
|
+
* Get a goal by ID.
|
|
50
|
+
*/
|
|
51
|
+
get(goalId: string): Goal | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Get all goals.
|
|
54
|
+
*/
|
|
55
|
+
getAll(): Goal[];
|
|
56
|
+
/**
|
|
57
|
+
* Update a goal's status.
|
|
58
|
+
*/
|
|
59
|
+
setStatus(goalId: string, status: GoalStatus): Goal;
|
|
60
|
+
/**
|
|
61
|
+
* Attach tasks to a goal.
|
|
62
|
+
*/
|
|
63
|
+
setTasks(goalId: string, tasks: Goal['tasks']): Goal;
|
|
64
|
+
private _getOrThrow;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=goal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal.d.ts","sourceRoot":"","sources":["../src/goal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,IAAI,EAAa,WAAW,EAAE,MAAM,YAAY,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAIxC;;;;;;;;;;;;GAYG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,WAAW;IAEhD;;;OAGG;IACG,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAuBtE;;;;OAIG;YACW,aAAa;IAwB3B;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAe3B;AAID;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAgC;IAE7C;;OAEG;IACH,MAAM,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAoBpC;;OAEG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIrC;;OAEG;IACH,MAAM,IAAI,IAAI,EAAE;IAIhB;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI;IASnD;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI;IAMpD,OAAO,CAAC,WAAW;CAKpB"}
|
package/dist/goal.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Goal decomposition and planning.
|
|
4
|
+
* @module @clawswarm/core/goal
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.GoalManager = exports.GoalPlanner = void 0;
|
|
8
|
+
// ─── Goal Planner ─────────────────────────────────────────────────────────────
|
|
9
|
+
/**
|
|
10
|
+
* Decomposes high-level goals into concrete, assignable tasks.
|
|
11
|
+
*
|
|
12
|
+
* The Planner analyzes a goal description and generates a task plan,
|
|
13
|
+
* assigns each task to the appropriate specialist agent, and sequences
|
|
14
|
+
* tasks based on their dependencies.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const planner = new GoalPlanner(swarmConfig);
|
|
19
|
+
* const tasks = await planner.decompose(goal, taskManager);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
class GoalPlanner {
|
|
23
|
+
config;
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decompose a goal into a list of tasks.
|
|
29
|
+
* Creates tasks via the TaskManager and returns them in execution order.
|
|
30
|
+
*/
|
|
31
|
+
async decompose(goal, taskManager) {
|
|
32
|
+
const plan = await this._generatePlan(goal);
|
|
33
|
+
const tasks = [];
|
|
34
|
+
// Create tasks from plan (maintaining dependency ordering)
|
|
35
|
+
for (const step of plan) {
|
|
36
|
+
const task = taskManager.create({
|
|
37
|
+
goalId: goal.id,
|
|
38
|
+
title: step.title,
|
|
39
|
+
description: step.description,
|
|
40
|
+
assignedTo: step.agentType,
|
|
41
|
+
dependsOn: step.dependsOnTitles
|
|
42
|
+
? tasks
|
|
43
|
+
.filter(t => step.dependsOnTitles.includes(t.title))
|
|
44
|
+
.map(t => t.id)
|
|
45
|
+
: [],
|
|
46
|
+
});
|
|
47
|
+
tasks.push(task);
|
|
48
|
+
}
|
|
49
|
+
return tasks;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Generate a task plan for a goal.
|
|
53
|
+
* In production, this calls an LLM with the planner system prompt.
|
|
54
|
+
* Returns structured step definitions.
|
|
55
|
+
*/
|
|
56
|
+
async _generatePlan(goal) {
|
|
57
|
+
// TODO: Replace with actual LLM call
|
|
58
|
+
// This stub returns a basic 3-step plan as an example
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
title: `Research: ${goal.title}`,
|
|
62
|
+
description: `Research and gather background information for: ${goal.description}`,
|
|
63
|
+
agentType: 'research',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
title: `Execute: ${goal.title}`,
|
|
67
|
+
description: `Based on research, implement the core work for: ${goal.description}`,
|
|
68
|
+
agentType: this._inferPrimaryAgent(goal),
|
|
69
|
+
dependsOnTitles: [`Research: ${goal.title}`],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
title: `Review: ${goal.title}`,
|
|
73
|
+
description: `Verify and validate the output for: ${goal.description}`,
|
|
74
|
+
agentType: 'research',
|
|
75
|
+
dependsOnTitles: [`Execute: ${goal.title}`],
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Infer the primary execution agent type from the goal description.
|
|
81
|
+
*/
|
|
82
|
+
_inferPrimaryAgent(goal) {
|
|
83
|
+
const desc = `${goal.title} ${goal.description}`.toLowerCase();
|
|
84
|
+
if (/deploy|infrastructure|k8s|docker|ci\/cd|monitoring|server/.test(desc)) {
|
|
85
|
+
return 'ops';
|
|
86
|
+
}
|
|
87
|
+
if (/code|build|implement|function|api|test|debug|refactor/.test(desc)) {
|
|
88
|
+
return 'code';
|
|
89
|
+
}
|
|
90
|
+
if (/research|analyze|report|summarize|find|investigate/.test(desc)) {
|
|
91
|
+
return 'research';
|
|
92
|
+
}
|
|
93
|
+
return 'code'; // default
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.GoalPlanner = GoalPlanner;
|
|
97
|
+
// ─── Goal Manager ─────────────────────────────────────────────────────────────
|
|
98
|
+
/**
|
|
99
|
+
* Manages the lifecycle of goals in a ClawSwarm instance.
|
|
100
|
+
*/
|
|
101
|
+
class GoalManager {
|
|
102
|
+
goals = new Map();
|
|
103
|
+
/**
|
|
104
|
+
* Create a new goal.
|
|
105
|
+
*/
|
|
106
|
+
create(input) {
|
|
107
|
+
const goal = {
|
|
108
|
+
...input,
|
|
109
|
+
id: `goal-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`,
|
|
110
|
+
status: 'created',
|
|
111
|
+
tasks: [],
|
|
112
|
+
deliverables: [],
|
|
113
|
+
priority: input.priority ?? 0,
|
|
114
|
+
tags: input.tags ?? [],
|
|
115
|
+
cost: {
|
|
116
|
+
totalTokens: 0,
|
|
117
|
+
estimatedCostUsd: 0,
|
|
118
|
+
byAgent: {},
|
|
119
|
+
},
|
|
120
|
+
createdAt: new Date().toISOString(),
|
|
121
|
+
};
|
|
122
|
+
this.goals.set(goal.id, goal);
|
|
123
|
+
return goal;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Get a goal by ID.
|
|
127
|
+
*/
|
|
128
|
+
get(goalId) {
|
|
129
|
+
return this.goals.get(goalId);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get all goals.
|
|
133
|
+
*/
|
|
134
|
+
getAll() {
|
|
135
|
+
return Array.from(this.goals.values());
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Update a goal's status.
|
|
139
|
+
*/
|
|
140
|
+
setStatus(goalId, status) {
|
|
141
|
+
const goal = this._getOrThrow(goalId);
|
|
142
|
+
goal.status = status;
|
|
143
|
+
if (status === 'completed') {
|
|
144
|
+
goal.completedAt = new Date().toISOString();
|
|
145
|
+
}
|
|
146
|
+
return goal;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Attach tasks to a goal.
|
|
150
|
+
*/
|
|
151
|
+
setTasks(goalId, tasks) {
|
|
152
|
+
const goal = this._getOrThrow(goalId);
|
|
153
|
+
goal.tasks = tasks;
|
|
154
|
+
return goal;
|
|
155
|
+
}
|
|
156
|
+
_getOrThrow(goalId) {
|
|
157
|
+
const goal = this.goals.get(goalId);
|
|
158
|
+
if (!goal)
|
|
159
|
+
throw new Error(`Goal not found: ${goalId}`);
|
|
160
|
+
return goal;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.GoalManager = GoalManager;
|
|
164
|
+
//# sourceMappingURL=goal.js.map
|
package/dist/goal.js.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C;QACtC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,WAAW,CAAC,MAAc;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAlED,kCAkEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @clawswarm/core — Public API
|
|
3
|
+
*
|
|
4
|
+
* The main entry point for the ClawSwarm framework.
|
|
5
|
+
* Import everything you need from this barrel export.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { ClawSwarm, Agent, GoalManager, TaskManager, ChiefReviewer } from '@clawswarm/core';
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @module @clawswarm/core
|
|
13
|
+
*/
|
|
14
|
+
export { ClawSwarm } from './clawswarm.js';
|
|
15
|
+
export { Agent } from './agent.js';
|
|
16
|
+
export { GoalManager, GoalPlanner } from './goal.js';
|
|
17
|
+
export { TaskManager } from './task.js';
|
|
18
|
+
export { ChiefReviewer } from './chief.js';
|
|
19
|
+
export type { AgentType, AgentStatus, AgentConfig, ModelId, TaskStatus, Task, Deliverable, GoalStatus, Goal, CreateGoalInput, ReviewResult, ChiefReviewConfig, TokenUsage, CostSummary, SwarmEvents, SwarmConfig, GoalResult, } from './types.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAGxC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,YAAY,EAEV,SAAS,EACT,WAAW,EACX,WAAW,EACX,OAAO,EAGP,UAAU,EACV,IAAI,EACJ,WAAW,EAGX,UAAU,EACV,IAAI,EACJ,eAAe,EAGf,YAAY,EACZ,iBAAiB,EAGjB,UAAU,EACV,WAAW,EAGX,WAAW,EAGX,WAAW,EACX,UAAU,GACX,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @clawswarm/core — Public API
|
|
4
|
+
*
|
|
5
|
+
* The main entry point for the ClawSwarm framework.
|
|
6
|
+
* Import everything you need from this barrel export.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { ClawSwarm, Agent, GoalManager, TaskManager, ChiefReviewer } from '@clawswarm/core';
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @module @clawswarm/core
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ChiefReviewer = exports.TaskManager = exports.GoalPlanner = exports.GoalManager = exports.Agent = exports.ClawSwarm = void 0;
|
|
17
|
+
// ─── Main Class ───────────────────────────────────────────────────────────────
|
|
18
|
+
var clawswarm_js_1 = require("./clawswarm.js");
|
|
19
|
+
Object.defineProperty(exports, "ClawSwarm", { enumerable: true, get: function () { return clawswarm_js_1.ClawSwarm; } });
|
|
20
|
+
// ─── Agent ────────────────────────────────────────────────────────────────────
|
|
21
|
+
var agent_js_1 = require("./agent.js");
|
|
22
|
+
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_js_1.Agent; } });
|
|
23
|
+
// ─── Goal ─────────────────────────────────────────────────────────────────────
|
|
24
|
+
var goal_js_1 = require("./goal.js");
|
|
25
|
+
Object.defineProperty(exports, "GoalManager", { enumerable: true, get: function () { return goal_js_1.GoalManager; } });
|
|
26
|
+
Object.defineProperty(exports, "GoalPlanner", { enumerable: true, get: function () { return goal_js_1.GoalPlanner; } });
|
|
27
|
+
// ─── Task ─────────────────────────────────────────────────────────────────────
|
|
28
|
+
var task_js_1 = require("./task.js");
|
|
29
|
+
Object.defineProperty(exports, "TaskManager", { enumerable: true, get: function () { return task_js_1.TaskManager; } });
|
|
30
|
+
// ─── Chief Review ─────────────────────────────────────────────────────────────
|
|
31
|
+
var chief_js_1 = require("./chief.js");
|
|
32
|
+
Object.defineProperty(exports, "ChiefReviewer", { enumerable: true, get: function () { return chief_js_1.ChiefReviewer; } });
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,iFAAiF;AACjF,+CAA2C;AAAlC,yGAAA,SAAS,OAAA;AAElB,iFAAiF;AACjF,uCAAmC;AAA1B,iGAAA,KAAK,OAAA;AAEd,iFAAiF;AACjF,qCAAqD;AAA5C,sGAAA,WAAW,OAAA;AAAE,sGAAA,WAAW,OAAA;AAEjC,iFAAiF;AACjF,qCAAwC;AAA/B,sGAAA,WAAW,OAAA;AAEpB,iFAAiF;AACjF,uCAA2C;AAAlC,yGAAA,aAAa,OAAA"}
|
package/dist/swarm.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClawSwarm — the top-level orchestrator.
|
|
3
|
+
* @module @clawswarm/core/swarm
|
|
4
|
+
*/
|
|
5
|
+
import EventEmitter from 'eventemitter3';
|
|
6
|
+
import { SwarmConfig, GoalResult, CreateGoalInput, Goal, AgentType, SwarmEvents } from './types.js';
|
|
7
|
+
import { Agent } from './agent.js';
|
|
8
|
+
/**
|
|
9
|
+
* ClawSwarm — deploy and orchestrate a team of AI agents.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const swarm = new ClawSwarm({
|
|
14
|
+
* agents: [
|
|
15
|
+
* Agent.research({ model: 'claude-sonnet-4' }),
|
|
16
|
+
* Agent.code({ model: 'gpt-4o' }),
|
|
17
|
+
* Agent.ops({ model: 'gemini-pro' }),
|
|
18
|
+
* ],
|
|
19
|
+
* chiefReview: {
|
|
20
|
+
* autoApproveThreshold: 8,
|
|
21
|
+
* humanReviewThreshold: 5,
|
|
22
|
+
* },
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* swarm.on('task:completed', (task) => console.log('Done:', task.title));
|
|
26
|
+
*
|
|
27
|
+
* const goal = await swarm.createGoal({
|
|
28
|
+
* title: 'Write a blog post about AI',
|
|
29
|
+
* description: 'Research AI trends and write a 1000-word post',
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* const result = await swarm.execute(goal);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class ClawSwarm extends EventEmitter<SwarmEvents> {
|
|
36
|
+
private readonly config;
|
|
37
|
+
private readonly agents;
|
|
38
|
+
private readonly taskManager;
|
|
39
|
+
private readonly goalManager;
|
|
40
|
+
private readonly planner;
|
|
41
|
+
private readonly reviewer;
|
|
42
|
+
constructor(config: SwarmConfig);
|
|
43
|
+
/**
|
|
44
|
+
* Create a new goal. Does not start execution yet.
|
|
45
|
+
*
|
|
46
|
+
* @param input - Goal title, description, and optional metadata
|
|
47
|
+
* @returns The created goal
|
|
48
|
+
*/
|
|
49
|
+
createGoal(input: CreateGoalInput): Promise<Goal>;
|
|
50
|
+
/**
|
|
51
|
+
* Execute a goal: plan, assign, run, review, and collect results.
|
|
52
|
+
*
|
|
53
|
+
* @param goal - The goal to execute (from createGoal)
|
|
54
|
+
* @returns Final result with deliverables and cost summary
|
|
55
|
+
*/
|
|
56
|
+
execute(goal: Goal): Promise<GoalResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Get all agents in this swarm.
|
|
59
|
+
*/
|
|
60
|
+
getAgents(): Agent[];
|
|
61
|
+
/**
|
|
62
|
+
* Get an agent by type.
|
|
63
|
+
*/
|
|
64
|
+
getAgent(type: AgentType): Agent | undefined;
|
|
65
|
+
private _executeTask;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=swarm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../src/swarm.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,WAAW,EACX,UAAU,EACV,eAAe,EACf,IAAI,EAEJ,SAAS,EACT,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAKnC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,SAAU,SAAQ,YAAY,CAAC,WAAW,CAAC;IACtD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;gBAE7B,MAAM,EAAE,WAAW;IAU/B;;;;;OAKG;IACG,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAMvD;;;;;OAKG;IACG,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC;IAuD9C;;OAEG;IACH,SAAS,IAAI,KAAK,EAAE;IAIpB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK,GAAG,SAAS;YAM9B,YAAY;CAsE3B"}
|