@locusai/sdk 0.4.5 → 0.4.9
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/dist/index-node.js +1590 -20
- package/dist/index.js +429 -121
- package/dist/orchestrator.d.ts.map +1 -1
- package/package.json +12 -23
- package/dist/agent/artifact-syncer.js +0 -77
- package/dist/agent/codebase-indexer-service.js +0 -55
- package/dist/agent/index.js +0 -5
- package/dist/agent/sprint-planner.js +0 -68
- package/dist/agent/task-executor.js +0 -60
- package/dist/agent/worker.js +0 -252
- package/dist/ai/anthropic-client.js +0 -70
- package/dist/ai/claude-runner.js +0 -71
- package/dist/ai/index.js +0 -2
- package/dist/core/config.js +0 -15
- package/dist/core/index.js +0 -3
- package/dist/core/indexer.js +0 -113
- package/dist/core/prompt-builder.js +0 -83
- package/dist/events.js +0 -15
- package/dist/modules/auth.js +0 -23
- package/dist/modules/base.js +0 -8
- package/dist/modules/ci.js +0 -7
- package/dist/modules/docs.js +0 -38
- package/dist/modules/invitations.js +0 -22
- package/dist/modules/organizations.js +0 -39
- package/dist/modules/sprints.js +0 -34
- package/dist/modules/tasks.js +0 -56
- package/dist/modules/workspaces.js +0 -49
- package/dist/orchestrator.js +0 -356
- package/dist/utils/colors.js +0 -54
- package/dist/utils/retry.js +0 -37
- package/src/agent/artifact-syncer.ts +0 -111
- package/src/agent/codebase-indexer-service.ts +0 -71
- package/src/agent/index.ts +0 -5
- package/src/agent/sprint-planner.ts +0 -86
- package/src/agent/task-executor.ts +0 -85
- package/src/agent/worker.ts +0 -322
- package/src/ai/anthropic-client.ts +0 -93
- package/src/ai/claude-runner.ts +0 -86
- package/src/ai/index.ts +0 -2
- package/src/core/config.ts +0 -21
- package/src/core/index.ts +0 -3
- package/src/core/indexer.ts +0 -131
- package/src/core/prompt-builder.ts +0 -91
- package/src/events.ts +0 -35
- package/src/index-node.ts +0 -23
- package/src/index.ts +0 -159
- package/src/modules/auth.ts +0 -48
- package/src/modules/base.ts +0 -9
- package/src/modules/ci.ts +0 -12
- package/src/modules/docs.ts +0 -84
- package/src/modules/invitations.ts +0 -45
- package/src/modules/organizations.ts +0 -90
- package/src/modules/sprints.ts +0 -69
- package/src/modules/tasks.ts +0 -110
- package/src/modules/workspaces.ts +0 -94
- package/src/orchestrator.ts +0 -473
- package/src/utils/colors.ts +0 -63
- package/src/utils/retry.ts +0 -56
package/dist/orchestrator.js
DELETED
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
4
|
-
import { TaskPriority, TaskStatus } from "@locusai/shared";
|
|
5
|
-
import { EventEmitter } from "events";
|
|
6
|
-
import { LocusClient } from "./index.js";
|
|
7
|
-
import { c } from "./utils/colors.js";
|
|
8
|
-
export class AgentOrchestrator extends EventEmitter {
|
|
9
|
-
client;
|
|
10
|
-
config;
|
|
11
|
-
agents = new Map();
|
|
12
|
-
isRunning = false;
|
|
13
|
-
processedTasks = new Set();
|
|
14
|
-
resolvedSprintId = null;
|
|
15
|
-
constructor(config) {
|
|
16
|
-
super();
|
|
17
|
-
this.config = config;
|
|
18
|
-
this.client = new LocusClient({
|
|
19
|
-
baseUrl: config.apiBase,
|
|
20
|
-
token: config.apiKey,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Resolve the sprint ID - use provided or find active sprint
|
|
25
|
-
*/
|
|
26
|
-
async resolveSprintId() {
|
|
27
|
-
if (this.config.sprintId) {
|
|
28
|
-
return this.config.sprintId;
|
|
29
|
-
}
|
|
30
|
-
// Try to find active sprint in workspace
|
|
31
|
-
try {
|
|
32
|
-
const sprint = await this.client.sprints.getActive(this.config.workspaceId);
|
|
33
|
-
if (sprint?.id) {
|
|
34
|
-
console.log(c.info(`📋 Using active sprint: ${sprint.name}`));
|
|
35
|
-
return sprint.id;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
// No active sprint found, will work with all tasks
|
|
40
|
-
}
|
|
41
|
-
console.log(c.dim("ℹ No sprint specified, working with all workspace tasks"));
|
|
42
|
-
return "";
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Start the orchestrator with N agents
|
|
46
|
-
*/
|
|
47
|
-
async start() {
|
|
48
|
-
if (this.isRunning) {
|
|
49
|
-
throw new Error("Orchestrator is already running");
|
|
50
|
-
}
|
|
51
|
-
this.isRunning = true;
|
|
52
|
-
this.processedTasks.clear();
|
|
53
|
-
try {
|
|
54
|
-
await this.orchestrationLoop();
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
this.emit("error", error);
|
|
58
|
-
throw error;
|
|
59
|
-
}
|
|
60
|
-
finally {
|
|
61
|
-
await this.cleanup();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Main orchestration loop - runs 1 agent continuously
|
|
66
|
-
*/
|
|
67
|
-
async orchestrationLoop() {
|
|
68
|
-
// Resolve sprint ID first
|
|
69
|
-
this.resolvedSprintId = await this.resolveSprintId();
|
|
70
|
-
this.emit("started", {
|
|
71
|
-
timestamp: new Date(),
|
|
72
|
-
config: this.config,
|
|
73
|
-
sprintId: this.resolvedSprintId,
|
|
74
|
-
});
|
|
75
|
-
console.log(`\n${c.primary("🤖 Locus Agent Orchestrator")}`);
|
|
76
|
-
console.log(c.dim("----------------------------------------------"));
|
|
77
|
-
console.log(`${c.bold("Workspace:")} ${this.config.workspaceId}`);
|
|
78
|
-
if (this.resolvedSprintId) {
|
|
79
|
-
console.log(`${c.bold("Sprint:")} ${this.resolvedSprintId}`);
|
|
80
|
-
}
|
|
81
|
-
console.log(`${c.bold("API Base:")} ${this.config.apiBase}`);
|
|
82
|
-
console.log(c.dim("----------------------------------------------\n"));
|
|
83
|
-
// Check if there are tasks to work on before spawning
|
|
84
|
-
const tasks = await this.getAvailableTasks();
|
|
85
|
-
if (tasks.length === 0) {
|
|
86
|
-
console.log(c.dim("ℹ No available tasks found in the backlog."));
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
// Spawn single agent
|
|
90
|
-
await this.spawnAgent();
|
|
91
|
-
// Wait for agent to complete
|
|
92
|
-
while (this.agents.size > 0 && this.isRunning) {
|
|
93
|
-
await this.reapAgents();
|
|
94
|
-
if (this.agents.size === 0) {
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
await this.sleep(2000);
|
|
98
|
-
}
|
|
99
|
-
console.log(`\n${c.success("✅ Orchestrator finished")}`);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Find the package root by looking for package.json
|
|
103
|
-
*/
|
|
104
|
-
findPackageRoot(startPath) {
|
|
105
|
-
let currentDir = startPath;
|
|
106
|
-
while (currentDir !== "/") {
|
|
107
|
-
if (existsSync(join(currentDir, "package.json"))) {
|
|
108
|
-
return currentDir;
|
|
109
|
-
}
|
|
110
|
-
currentDir = dirname(currentDir);
|
|
111
|
-
}
|
|
112
|
-
// Fallback to startPath if not found
|
|
113
|
-
return startPath;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Spawn a single agent process
|
|
117
|
-
*/
|
|
118
|
-
async spawnAgent() {
|
|
119
|
-
const agentId = `agent-${Date.now()}-${Math.random()
|
|
120
|
-
.toString(36)
|
|
121
|
-
.slice(2, 9)}`;
|
|
122
|
-
const agentState = {
|
|
123
|
-
id: agentId,
|
|
124
|
-
status: "IDLE",
|
|
125
|
-
currentTaskId: null,
|
|
126
|
-
tasksCompleted: 0,
|
|
127
|
-
tasksFailed: 0,
|
|
128
|
-
lastHeartbeat: new Date(),
|
|
129
|
-
};
|
|
130
|
-
this.agents.set(agentId, agentState);
|
|
131
|
-
console.log(`${c.primary("🚀 Agent started:")} ${c.bold(agentId)}\n`);
|
|
132
|
-
// Build arguments for agent worker
|
|
133
|
-
// Try multiple resolution strategies
|
|
134
|
-
const potentialPaths = [];
|
|
135
|
-
// Strategy 1: Use import.meta.resolve to find the installed SDK package
|
|
136
|
-
try {
|
|
137
|
-
// Resolve the SDK's index to find the package location
|
|
138
|
-
const sdkIndexPath = import.meta.resolve("@locusai/sdk");
|
|
139
|
-
const sdkDir = dirname(sdkIndexPath.replace("file://", ""));
|
|
140
|
-
// In production, files are in dist/; sdkDir points to dist/ or src/
|
|
141
|
-
const sdkRoot = this.findPackageRoot(sdkDir);
|
|
142
|
-
potentialPaths.push(join(sdkRoot, "dist", "agent", "worker.js"), join(sdkRoot, "src", "agent", "worker.ts"));
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
// import.meta.resolve failed, continue with fallback strategies
|
|
146
|
-
}
|
|
147
|
-
// Strategy 2: Find package root from __dirname (works in dev/local)
|
|
148
|
-
const packageRoot = this.findPackageRoot(__dirname);
|
|
149
|
-
potentialPaths.push(join(packageRoot, "dist", "agent", "worker.js"), join(packageRoot, "src", "agent", "worker.ts"), join(__dirname, "agent", "worker.ts"), join(__dirname, "agent", "worker.js"));
|
|
150
|
-
const workerPath = potentialPaths.find((p) => existsSync(p));
|
|
151
|
-
// Verify worker file exists
|
|
152
|
-
if (!workerPath) {
|
|
153
|
-
throw new Error(`Worker file not found. Checked: ${potentialPaths.join(", ")}. ` +
|
|
154
|
-
`Make sure the SDK is properly built and installed.`);
|
|
155
|
-
}
|
|
156
|
-
const workerArgs = [
|
|
157
|
-
"--agent-id",
|
|
158
|
-
agentId,
|
|
159
|
-
"--workspace-id",
|
|
160
|
-
this.config.workspaceId,
|
|
161
|
-
"--api-base",
|
|
162
|
-
this.config.apiBase,
|
|
163
|
-
"--api-key",
|
|
164
|
-
this.config.apiKey,
|
|
165
|
-
"--project-path",
|
|
166
|
-
this.config.projectPath,
|
|
167
|
-
];
|
|
168
|
-
// Add anthropic API key if provided
|
|
169
|
-
if (this.config.anthropicApiKey) {
|
|
170
|
-
workerArgs.push("--anthropic-api-key", this.config.anthropicApiKey);
|
|
171
|
-
}
|
|
172
|
-
// Add model if specified
|
|
173
|
-
if (this.config.model) {
|
|
174
|
-
workerArgs.push("--model", this.config.model);
|
|
175
|
-
}
|
|
176
|
-
// Add sprint ID if resolved
|
|
177
|
-
if (this.resolvedSprintId) {
|
|
178
|
-
workerArgs.push("--sprint-id", this.resolvedSprintId);
|
|
179
|
-
}
|
|
180
|
-
// Use node to run the worker script
|
|
181
|
-
const agentProcess = spawn(process.execPath, [workerPath, ...workerArgs]);
|
|
182
|
-
agentState.process = agentProcess;
|
|
183
|
-
agentProcess.on("message", (msg) => {
|
|
184
|
-
if (msg.type === "stats") {
|
|
185
|
-
agentState.tasksCompleted = msg.tasksCompleted || 0;
|
|
186
|
-
agentState.tasksFailed = msg.tasksFailed || 0;
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
agentProcess.stdout?.on("data", (data) => {
|
|
190
|
-
process.stdout.write(data.toString());
|
|
191
|
-
});
|
|
192
|
-
agentProcess.stderr?.on("data", (data) => {
|
|
193
|
-
process.stderr.write(`[${agentId}] ERR: ${data.toString()}`);
|
|
194
|
-
});
|
|
195
|
-
agentProcess.on("exit", (code) => {
|
|
196
|
-
console.log(`\n${agentId} finished (exit code: ${code})`);
|
|
197
|
-
const agent = this.agents.get(agentId);
|
|
198
|
-
if (agent) {
|
|
199
|
-
agent.status = code === 0 ? "COMPLETED" : "FAILED";
|
|
200
|
-
// Ensure CLI gets the absolute latest stats
|
|
201
|
-
this.emit("agent:completed", {
|
|
202
|
-
agentId,
|
|
203
|
-
status: agent.status,
|
|
204
|
-
tasksCompleted: agent.tasksCompleted,
|
|
205
|
-
tasksFailed: agent.tasksFailed,
|
|
206
|
-
});
|
|
207
|
-
// Remove from active tracking after emitting
|
|
208
|
-
this.agents.delete(agentId);
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
this.emit("agent:spawned", { agentId });
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Reap completed agents
|
|
215
|
-
*/
|
|
216
|
-
async reapAgents() {
|
|
217
|
-
// No-op: agents now remove themselves in the 'exit' listener
|
|
218
|
-
// to ensure events are emitted with correct stats before deletion.
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Get available tasks in sprint
|
|
222
|
-
*/
|
|
223
|
-
async getAvailableTasks() {
|
|
224
|
-
try {
|
|
225
|
-
const tasks = await this.client.tasks.getAvailable(this.config.workspaceId, this.resolvedSprintId || undefined);
|
|
226
|
-
return tasks.filter((task) => !this.processedTasks.has(task.id));
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
this.emit("error", error);
|
|
230
|
-
return [];
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Assign task to agent
|
|
235
|
-
*/
|
|
236
|
-
async assignTaskToAgent(agentId) {
|
|
237
|
-
const agent = this.agents.get(agentId);
|
|
238
|
-
if (!agent)
|
|
239
|
-
return null;
|
|
240
|
-
try {
|
|
241
|
-
const tasks = await this.getAvailableTasks();
|
|
242
|
-
const priorityOrder = [
|
|
243
|
-
TaskPriority.CRITICAL,
|
|
244
|
-
TaskPriority.HIGH,
|
|
245
|
-
TaskPriority.MEDIUM,
|
|
246
|
-
TaskPriority.LOW,
|
|
247
|
-
];
|
|
248
|
-
// Find task with highest priority
|
|
249
|
-
let task = tasks.sort((a, b) => priorityOrder.indexOf(a.priority) - priorityOrder.indexOf(b.priority))[0];
|
|
250
|
-
// Fallback: any available task
|
|
251
|
-
if (!task && tasks.length > 0) {
|
|
252
|
-
task = tasks[0];
|
|
253
|
-
}
|
|
254
|
-
if (!task)
|
|
255
|
-
return null;
|
|
256
|
-
agent.currentTaskId = task.id;
|
|
257
|
-
agent.status = "WORKING";
|
|
258
|
-
this.emit("task:assigned", {
|
|
259
|
-
agentId,
|
|
260
|
-
taskId: task.id,
|
|
261
|
-
title: task.title,
|
|
262
|
-
});
|
|
263
|
-
return task;
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
this.emit("error", error);
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Mark task as completed by agent
|
|
272
|
-
*/
|
|
273
|
-
async completeTask(taskId, agentId, summary) {
|
|
274
|
-
try {
|
|
275
|
-
await this.client.tasks.update(taskId, this.config.workspaceId, {
|
|
276
|
-
status: TaskStatus.VERIFICATION,
|
|
277
|
-
});
|
|
278
|
-
if (summary) {
|
|
279
|
-
await this.client.tasks.addComment(taskId, this.config.workspaceId, {
|
|
280
|
-
author: agentId,
|
|
281
|
-
text: `✅ Task completed\n\n${summary}`,
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
this.processedTasks.add(taskId);
|
|
285
|
-
const agent = this.agents.get(agentId);
|
|
286
|
-
if (agent) {
|
|
287
|
-
agent.tasksCompleted += 1;
|
|
288
|
-
agent.currentTaskId = null;
|
|
289
|
-
agent.status = "IDLE";
|
|
290
|
-
}
|
|
291
|
-
this.emit("task:completed", { agentId, taskId });
|
|
292
|
-
}
|
|
293
|
-
catch (error) {
|
|
294
|
-
this.emit("error", error);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Mark task as failed
|
|
299
|
-
*/
|
|
300
|
-
async failTask(taskId, agentId, error) {
|
|
301
|
-
try {
|
|
302
|
-
await this.client.tasks.update(taskId, this.config.workspaceId, {
|
|
303
|
-
status: TaskStatus.BACKLOG,
|
|
304
|
-
assignedTo: null,
|
|
305
|
-
});
|
|
306
|
-
await this.client.tasks.addComment(taskId, this.config.workspaceId, {
|
|
307
|
-
author: agentId,
|
|
308
|
-
text: `❌ Agent failed: ${error}`,
|
|
309
|
-
});
|
|
310
|
-
const agent = this.agents.get(agentId);
|
|
311
|
-
if (agent) {
|
|
312
|
-
agent.tasksFailed += 1;
|
|
313
|
-
agent.currentTaskId = null;
|
|
314
|
-
agent.status = "IDLE";
|
|
315
|
-
}
|
|
316
|
-
this.emit("task:failed", { agentId, taskId, error });
|
|
317
|
-
}
|
|
318
|
-
catch (error) {
|
|
319
|
-
this.emit("error", error);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Stop orchestrator
|
|
324
|
-
*/
|
|
325
|
-
async stop() {
|
|
326
|
-
this.isRunning = false;
|
|
327
|
-
await this.cleanup();
|
|
328
|
-
this.emit("stopped", { timestamp: new Date() });
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Cleanup - kill all agent processes
|
|
332
|
-
*/
|
|
333
|
-
async cleanup() {
|
|
334
|
-
for (const [agentId, agent] of this.agents.entries()) {
|
|
335
|
-
if (agent.process && !agent.process.killed) {
|
|
336
|
-
console.log(`Killing agent: ${agentId}`);
|
|
337
|
-
agent.process.kill();
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
this.agents.clear();
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Get orchestrator stats
|
|
344
|
-
*/
|
|
345
|
-
getStats() {
|
|
346
|
-
return {
|
|
347
|
-
activeAgents: this.agents.size,
|
|
348
|
-
processedTasks: this.processedTasks.size,
|
|
349
|
-
totalTasksCompleted: Array.from(this.agents.values()).reduce((sum, agent) => sum + agent.tasksCompleted, 0),
|
|
350
|
-
totalTasksFailed: Array.from(this.agents.values()).reduce((sum, agent) => sum + agent.tasksFailed, 0),
|
|
351
|
-
};
|
|
352
|
-
}
|
|
353
|
-
sleep(ms) {
|
|
354
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
355
|
-
}
|
|
356
|
-
}
|
package/dist/utils/colors.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple ANSI color utility for terminal output
|
|
3
|
-
* Dependency-free and works in Node.js/Bun environments
|
|
4
|
-
*/
|
|
5
|
-
const ESC = "\u001b[";
|
|
6
|
-
const RESET = `${ESC}0m`;
|
|
7
|
-
const colors = {
|
|
8
|
-
reset: RESET,
|
|
9
|
-
bold: `${ESC}1m`,
|
|
10
|
-
dim: `${ESC}2m`,
|
|
11
|
-
italic: `${ESC}3m`,
|
|
12
|
-
underline: `${ESC}4m`,
|
|
13
|
-
// Foreground colors
|
|
14
|
-
black: `${ESC}30m`,
|
|
15
|
-
red: `${ESC}31m`,
|
|
16
|
-
green: `${ESC}32m`,
|
|
17
|
-
yellow: `${ESC}33m`,
|
|
18
|
-
blue: `${ESC}34m`,
|
|
19
|
-
magenta: `${ESC}35m`,
|
|
20
|
-
cyan: `${ESC}36m`,
|
|
21
|
-
white: `${ESC}37m`,
|
|
22
|
-
gray: `${ESC}90m`,
|
|
23
|
-
// Foreground bright colors
|
|
24
|
-
brightRed: `${ESC}91m`,
|
|
25
|
-
brightGreen: `${ESC}92m`,
|
|
26
|
-
brightYellow: `${ESC}93m`,
|
|
27
|
-
brightBlue: `${ESC}94m`,
|
|
28
|
-
brightMagenta: `${ESC}95m`,
|
|
29
|
-
brightCyan: `${ESC}96m`,
|
|
30
|
-
brightWhite: `${ESC}97m`,
|
|
31
|
-
};
|
|
32
|
-
export const c = {
|
|
33
|
-
text: (text, ...colorNames) => {
|
|
34
|
-
const codes = colorNames.map((name) => colors[name]).join("");
|
|
35
|
-
return `${codes}${text}${RESET}`;
|
|
36
|
-
},
|
|
37
|
-
// Shortcuts
|
|
38
|
-
bold: (t) => c.text(t, "bold"),
|
|
39
|
-
dim: (t) => c.text(t, "dim"),
|
|
40
|
-
red: (t) => c.text(t, "red"),
|
|
41
|
-
green: (t) => c.text(t, "green"),
|
|
42
|
-
yellow: (t) => c.text(t, "yellow"),
|
|
43
|
-
blue: (t) => c.text(t, "blue"),
|
|
44
|
-
magenta: (t) => c.text(t, "magenta"),
|
|
45
|
-
cyan: (t) => c.text(t, "cyan"),
|
|
46
|
-
gray: (t) => c.text(t, "gray"),
|
|
47
|
-
// Combinations
|
|
48
|
-
success: (t) => c.text(t, "green", "bold"),
|
|
49
|
-
error: (t) => c.text(t, "red", "bold"),
|
|
50
|
-
warning: (t) => c.text(t, "yellow", "bold"),
|
|
51
|
-
info: (t) => c.text(t, "cyan", "bold"),
|
|
52
|
-
primary: (t) => c.text(t, "blue", "bold"),
|
|
53
|
-
underline: (t) => c.text(t, "underline"),
|
|
54
|
-
};
|
package/dist/utils/retry.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { isAxiosError } from "axios";
|
|
2
|
-
export const DEFAULT_RETRY_OPTIONS = {
|
|
3
|
-
maxRetries: 3,
|
|
4
|
-
initialDelay: 1000,
|
|
5
|
-
maxDelay: 5000,
|
|
6
|
-
factor: 2,
|
|
7
|
-
retryCondition: (error) => {
|
|
8
|
-
// Retry on network errors or 5xx server errors
|
|
9
|
-
if (isAxiosError(error)) {
|
|
10
|
-
if (!error.response)
|
|
11
|
-
return true; // Network error
|
|
12
|
-
return error.response.status >= 500;
|
|
13
|
-
}
|
|
14
|
-
return true; // Retry on other unknown errors
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Retries an async function with exponential backoff
|
|
19
|
-
*/
|
|
20
|
-
export async function withRetry(fn, options = {}) {
|
|
21
|
-
const config = { ...DEFAULT_RETRY_OPTIONS, ...options };
|
|
22
|
-
let lastError;
|
|
23
|
-
for (let attempt = 0; attempt <= config.maxRetries; attempt++) {
|
|
24
|
-
try {
|
|
25
|
-
return await fn();
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
lastError = error;
|
|
29
|
-
if (attempt === config.maxRetries || !config.retryCondition(error)) {
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
const delay = Math.min(config.initialDelay * Math.pow(config.factor, attempt), config.maxDelay);
|
|
33
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
throw lastError;
|
|
37
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
existsSync,
|
|
3
|
-
mkdirSync,
|
|
4
|
-
readdirSync,
|
|
5
|
-
readFileSync,
|
|
6
|
-
statSync,
|
|
7
|
-
} from "node:fs";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { getLocusPath } from "../core/config.js";
|
|
10
|
-
import type { LocusClient } from "../index.js";
|
|
11
|
-
|
|
12
|
-
export interface ArtifactSyncerDeps {
|
|
13
|
-
client: LocusClient;
|
|
14
|
-
workspaceId: string;
|
|
15
|
-
projectPath: string;
|
|
16
|
-
log: (message: string, level?: "info" | "success" | "warn" | "error") => void;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Handles syncing local artifacts to the platform
|
|
21
|
-
*/
|
|
22
|
-
export class ArtifactSyncer {
|
|
23
|
-
constructor(private deps: ArtifactSyncerDeps) {}
|
|
24
|
-
|
|
25
|
-
private async getOrCreateArtifactsGroup(): Promise<string> {
|
|
26
|
-
try {
|
|
27
|
-
const groups = await this.deps.client.docs.listGroups(
|
|
28
|
-
this.deps.workspaceId
|
|
29
|
-
);
|
|
30
|
-
const artifactsGroup = groups.find((g) => g.name === "Artifacts");
|
|
31
|
-
|
|
32
|
-
if (artifactsGroup) {
|
|
33
|
-
return artifactsGroup.id;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Create the Artifacts group
|
|
37
|
-
const newGroup = await this.deps.client.docs.createGroup(
|
|
38
|
-
this.deps.workspaceId,
|
|
39
|
-
{
|
|
40
|
-
name: "Artifacts",
|
|
41
|
-
order: 999, // Place at the end
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
this.deps.log(
|
|
45
|
-
"Created 'Artifacts' group for agent-generated docs",
|
|
46
|
-
"info"
|
|
47
|
-
);
|
|
48
|
-
return newGroup.id;
|
|
49
|
-
} catch (error) {
|
|
50
|
-
this.deps.log(`Failed to get/create Artifacts group: ${error}`, "error");
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async sync(): Promise<void> {
|
|
56
|
-
const artifactsDir = getLocusPath(this.deps.projectPath, "artifactsDir");
|
|
57
|
-
if (!existsSync(artifactsDir)) {
|
|
58
|
-
mkdirSync(artifactsDir, { recursive: true });
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const files = readdirSync(artifactsDir);
|
|
64
|
-
if (files.length === 0) return;
|
|
65
|
-
|
|
66
|
-
this.deps.log(`Syncing ${files.length} artifacts to server...`, "info");
|
|
67
|
-
|
|
68
|
-
// Get or create the Artifacts group
|
|
69
|
-
const artifactsGroupId = await this.getOrCreateArtifactsGroup();
|
|
70
|
-
|
|
71
|
-
// Get existing docs to check for updates
|
|
72
|
-
const existingDocs = await this.deps.client.docs.list(
|
|
73
|
-
this.deps.workspaceId
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
for (const file of files) {
|
|
77
|
-
const filePath = join(artifactsDir, file);
|
|
78
|
-
if (statSync(filePath).isFile()) {
|
|
79
|
-
const content = readFileSync(filePath, "utf-8");
|
|
80
|
-
const title = file.replace(/\.md$/, "").trim();
|
|
81
|
-
if (!title) continue;
|
|
82
|
-
|
|
83
|
-
const existing = existingDocs.find((d) => d.title === title);
|
|
84
|
-
|
|
85
|
-
if (existing) {
|
|
86
|
-
if (
|
|
87
|
-
existing.content !== content ||
|
|
88
|
-
existing.groupId !== artifactsGroupId
|
|
89
|
-
) {
|
|
90
|
-
await this.deps.client.docs.update(
|
|
91
|
-
existing.id,
|
|
92
|
-
this.deps.workspaceId,
|
|
93
|
-
{ content, groupId: artifactsGroupId }
|
|
94
|
-
);
|
|
95
|
-
this.deps.log(`Updated artifact: ${file}`, "success");
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
await this.deps.client.docs.create(this.deps.workspaceId, {
|
|
99
|
-
title,
|
|
100
|
-
content,
|
|
101
|
-
groupId: artifactsGroupId,
|
|
102
|
-
});
|
|
103
|
-
this.deps.log(`Created artifact: ${file}`, "success");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
} catch (error) {
|
|
108
|
-
this.deps.log(`Failed to sync artifacts: ${error}`, "error");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { AnthropicClient } from "../ai/anthropic-client.js";
|
|
2
|
-
import type { ClaudeRunner } from "../ai/claude-runner.js";
|
|
3
|
-
import { CodebaseIndexer } from "../core/indexer.js";
|
|
4
|
-
|
|
5
|
-
export interface CodebaseIndexerServiceDeps {
|
|
6
|
-
anthropicClient: AnthropicClient | null;
|
|
7
|
-
claudeRunner: ClaudeRunner;
|
|
8
|
-
projectPath: string;
|
|
9
|
-
log: (message: string, level?: "info" | "success" | "warn" | "error") => void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Handles codebase indexing with AI analysis
|
|
14
|
-
*/
|
|
15
|
-
export class CodebaseIndexerService {
|
|
16
|
-
private indexer: CodebaseIndexer;
|
|
17
|
-
|
|
18
|
-
constructor(private deps: CodebaseIndexerServiceDeps) {
|
|
19
|
-
this.indexer = new CodebaseIndexer(deps.projectPath);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async reindex(): Promise<void> {
|
|
23
|
-
try {
|
|
24
|
-
this.deps.log("Reindexing codebase...", "info");
|
|
25
|
-
|
|
26
|
-
const index = await this.indexer.index(
|
|
27
|
-
(msg) => this.deps.log(msg, "info"),
|
|
28
|
-
async (tree: string) => {
|
|
29
|
-
const prompt = `You are a codebase analysis expert. Analyze the file tree and extract:
|
|
30
|
-
1. Key symbols (classes, functions, types) and their locations
|
|
31
|
-
2. Responsibilities of each directory/file
|
|
32
|
-
3. Overall project structure
|
|
33
|
-
|
|
34
|
-
Analyze this file tree and provide a JSON response with:
|
|
35
|
-
- "symbols": object mapping symbol names to file paths (array)
|
|
36
|
-
- "responsibilities": object mapping paths to brief descriptions
|
|
37
|
-
|
|
38
|
-
File tree:
|
|
39
|
-
${tree}
|
|
40
|
-
|
|
41
|
-
Return ONLY valid JSON, no markdown formatting.`;
|
|
42
|
-
|
|
43
|
-
let response: string;
|
|
44
|
-
|
|
45
|
-
if (this.deps.anthropicClient) {
|
|
46
|
-
// Use Anthropic SDK with caching for faster indexing
|
|
47
|
-
response = await this.deps.anthropicClient.run({
|
|
48
|
-
systemPrompt:
|
|
49
|
-
"You are a codebase analysis expert specialized in extracting structure and symbols from file trees.",
|
|
50
|
-
userPrompt: prompt,
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
// Fallback to Claude CLI
|
|
54
|
-
response = await this.deps.claudeRunner.run(prompt, true);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Extract JSON from response (handle markdown code blocks)
|
|
58
|
-
const jsonMatch = response.match(/\{[\s\S]*\}/);
|
|
59
|
-
if (jsonMatch) {
|
|
60
|
-
return JSON.parse(jsonMatch[0]);
|
|
61
|
-
}
|
|
62
|
-
return { symbols: {}, responsibilities: {}, lastIndexed: "" };
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
this.indexer.saveIndex(index);
|
|
66
|
-
this.deps.log("Codebase reindexed successfully", "success");
|
|
67
|
-
} catch (error) {
|
|
68
|
-
this.deps.log(`Failed to reindex codebase: ${error}`, "error");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
package/src/agent/index.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { ArtifactSyncer } from "./artifact-syncer.js";
|
|
2
|
-
export { CodebaseIndexerService } from "./codebase-indexer-service.js";
|
|
3
|
-
export { SprintPlanner } from "./sprint-planner.js";
|
|
4
|
-
export { TaskExecutor } from "./task-executor.js";
|
|
5
|
-
export { AgentWorker, type WorkerConfig } from "./worker.js";
|