@oalo-ai/cli 0.5.1 → 0.7.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.
- package/README.md +45 -10
- package/man/oalo.1 +359 -16
- package/package.json +2 -2
- package/plugin/.claude-plugin/plugin.json +2 -2
- package/plugin/skills/oalo/SKILL.md +124 -30
- package/src/agents/harness.js +357 -0
- package/src/agents/roles.js +339 -0
- package/src/agents/worktree.js +155 -0
- package/src/commands/auto.js +239 -0
- package/src/commands/bots.js +2 -2
- package/src/commands/crm.js +114 -0
- package/src/commands/db.js +2 -1
- package/src/commands/heal.js +141 -0
- package/src/commands/inbox.js +127 -0
- package/src/commands/link.js +1 -1
- package/src/commands/race.js +390 -0
- package/src/commands/ralph.js +302 -0
- package/src/commands/review.js +233 -0
- package/src/commands/serve.js +1 -1
- package/src/commands/skill.js +15 -5
- package/src/commands/swarm.js +457 -0
- package/src/commands/switches.js +32 -1
- package/src/commands/usage.js +66 -0
- package/src/coord-release.json +9 -9
- package/src/help.js +225 -15
- package/src/index.js +36 -0
- package/src/mcp/describe.js +3 -2
- package/src/mcp/tools.js +84 -2
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy 5: `oalo swarm` — Lightweight multi-role Blackboard Swarm for
|
|
3
|
+
* open-ended exploration, architecture design, audits, and triage BEFORE
|
|
4
|
+
* committing to a DAG.
|
|
5
|
+
*
|
|
6
|
+
* Roles inspect the repo independently (read-only by default), post structured
|
|
7
|
+
* findings to an append-only blackboard across N rounds, challenge each other,
|
|
8
|
+
* and synthesize both a markdown report (`report.md`) and a promotable
|
|
9
|
+
* `oalo coord` draft plan (`plan.json`) via `oalo swarm promote`.
|
|
10
|
+
*/
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
import { runAgent, parseHarnessSpec, detectDefaultHarness, extractJsonObject } from "../agents/harness.js";
|
|
16
|
+
import {
|
|
17
|
+
BUILTIN_TEAMS,
|
|
18
|
+
loadRoleRegistry,
|
|
19
|
+
getRole,
|
|
20
|
+
saveRole,
|
|
21
|
+
deleteRole,
|
|
22
|
+
resolveRoleSpecs,
|
|
23
|
+
} from "../agents/roles.js";
|
|
24
|
+
import { requireProjectRoot } from "../agents/worktree.js";
|
|
25
|
+
import { coordBinary } from "./coord-bin.js";
|
|
26
|
+
|
|
27
|
+
const USAGE = `usage:
|
|
28
|
+
oalo swarm "<goal>" [--team <preset>] [--roles r1[@harness],r2,...] [--rounds <n>] [--harness <spec>] [--readonly] [--budget <usd>] [--timeout <s>] [--json]
|
|
29
|
+
oalo swarm status [<run-id>] [--json]
|
|
30
|
+
oalo swarm promote [<run-id>] [--json]
|
|
31
|
+
oalo swarm roles list [--json]
|
|
32
|
+
oalo swarm roles show <name> [--json]
|
|
33
|
+
oalo swarm roles add <name> --focus "<text>" [--checklist "a,b,c"] [--harness <spec>] [--global] [--json]
|
|
34
|
+
oalo swarm roles rm <name> [--global] [--json]
|
|
35
|
+
|
|
36
|
+
examples:
|
|
37
|
+
oalo swarm "Design local AutoResearch pipeline" --team research --rounds 2
|
|
38
|
+
oalo swarm "Audit checkout" --roles architect@claude:sonnet,security,skeptic
|
|
39
|
+
oalo swarm roles add ml-bench --focus "Leak-free ML benchmarks" --checklist "Fixed seeds,Runtime cap"
|
|
40
|
+
oalo swarm promote`;
|
|
41
|
+
|
|
42
|
+
function swarmsDir(root) {
|
|
43
|
+
return join(root, ".oalo", "swarms");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function loadSwarm(root, runId) {
|
|
47
|
+
const dir = swarmsDir(root);
|
|
48
|
+
if (!existsSync(dir)) throw new Error("no swarms found in this repo");
|
|
49
|
+
let id = runId;
|
|
50
|
+
if (!id) {
|
|
51
|
+
const dirs = readdirSync(dir)
|
|
52
|
+
.filter((d) => existsSync(join(dir, d, "board.json")))
|
|
53
|
+
.sort()
|
|
54
|
+
.reverse();
|
|
55
|
+
if (!dirs.length) throw new Error("no swarms found in this repo");
|
|
56
|
+
id = dirs[0];
|
|
57
|
+
}
|
|
58
|
+
const boardPath = join(dir, id, "board.json");
|
|
59
|
+
if (!existsSync(boardPath)) throw new Error(`swarm not found: ${id}`);
|
|
60
|
+
return { dir: join(dir, id), boardPath, data: JSON.parse(readFileSync(boardPath, "utf8")) };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function renderBoardMd(board) {
|
|
64
|
+
const lines = [`# Oalo Swarm Blackboard: ${board.run_id}`, "", `**Goal:** ${board.goal}`, `**Roles:** ${board.roles.join(", ")}`, ""];
|
|
65
|
+
for (const post of board.posts) {
|
|
66
|
+
lines.push(`## Round ${post.round} — ${post.role} (${post.harness})`, "");
|
|
67
|
+
lines.push(post.content, "");
|
|
68
|
+
}
|
|
69
|
+
if (board.report_md) {
|
|
70
|
+
lines.push("---", "", "# Synthesis", "", board.report_md);
|
|
71
|
+
}
|
|
72
|
+
return lines.join("\n");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function buildRolePrompt({ goal, roleSpec, roleNames, round, totalRounds, priorPosts }) {
|
|
76
|
+
const lines = [
|
|
77
|
+
`# Swarm Blackboard — Role: ${roleSpec.name} (Round ${round}/${totalRounds})`,
|
|
78
|
+
"",
|
|
79
|
+
`You are the **${roleSpec.name}** specialist in a peer swarm with roles: ${roleNames.join(", ")}.`,
|
|
80
|
+
"Inspect the repository as needed. Do NOT modify files.",
|
|
81
|
+
];
|
|
82
|
+
if (roleSpec.focus) {
|
|
83
|
+
lines.push("", "## Specialist Lens", roleSpec.focus);
|
|
84
|
+
}
|
|
85
|
+
if (roleSpec.checklist?.length) {
|
|
86
|
+
lines.push("", "## Role Checklist", ...roleSpec.checklist.map((item) => `- ${item}`));
|
|
87
|
+
}
|
|
88
|
+
lines.push("", "## Goal", goal);
|
|
89
|
+
if (priorPosts.length) {
|
|
90
|
+
lines.push("", "## Blackboard Posts from Earlier Rounds");
|
|
91
|
+
for (const p of priorPosts) {
|
|
92
|
+
lines.push(`\n### [Round ${p.round} — ${p.role}]\n${p.content.slice(0, 2500)}`);
|
|
93
|
+
}
|
|
94
|
+
lines.push(
|
|
95
|
+
"",
|
|
96
|
+
"## Round Instructions",
|
|
97
|
+
"- Read your peers' findings above. Challenge weak assumptions, fill blind spots, resolve disagreements, and refine concrete file paths / task boundaries.",
|
|
98
|
+
);
|
|
99
|
+
} else {
|
|
100
|
+
lines.push(
|
|
101
|
+
"",
|
|
102
|
+
"## Round 1 Instructions",
|
|
103
|
+
"- Investigate the codebase from your specialist angle.",
|
|
104
|
+
"- Report: (1) key findings with exact file paths, (2) risks/edge cases, (3) concrete recommendations.",
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
lines.push("- Keep your post dense, specific, and under 350 words.");
|
|
108
|
+
return lines.join("\n");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function buildSynthPrompt({ goal, roles, posts }) {
|
|
112
|
+
const boardText = posts.map((p) => `### [Round ${p.round} — ${p.role}]\n${p.content}`).join("\n\n");
|
|
113
|
+
return [
|
|
114
|
+
"# Swarm Synthesizer",
|
|
115
|
+
"",
|
|
116
|
+
`Synthesize the ${roles.length}-role blackboard discussion below into a clear report AND an executable \`oalo coord\` draft task plan.`,
|
|
117
|
+
"",
|
|
118
|
+
`## Goal`,
|
|
119
|
+
goal,
|
|
120
|
+
"",
|
|
121
|
+
"## Blackboard",
|
|
122
|
+
boardText,
|
|
123
|
+
"",
|
|
124
|
+
"## Output Format (STRICT JSON ONLY)",
|
|
125
|
+
"Return a single JSON object:",
|
|
126
|
+
"```json",
|
|
127
|
+
JSON.stringify(
|
|
128
|
+
{
|
|
129
|
+
summary: "Concise executive summary",
|
|
130
|
+
report_md: "Markdown report covering findings, consensus decisions, and open risks",
|
|
131
|
+
design: "Short technical design for `oalo coord` (components, interfaces, data changes)",
|
|
132
|
+
tasks: [
|
|
133
|
+
{
|
|
134
|
+
title: "Short task title",
|
|
135
|
+
spec: "Exact what & why for an isolated worker",
|
|
136
|
+
writes: ["src/example/**"],
|
|
137
|
+
acceptance: ["Concrete checkable criterion"],
|
|
138
|
+
depends_on: [],
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
null,
|
|
143
|
+
2,
|
|
144
|
+
),
|
|
145
|
+
"```",
|
|
146
|
+
"`depends_on` may reference 0-based indices of earlier tasks in `tasks` (e.g. `[0]`). Keep task `writes` globs disjoint whenever tasks can run in parallel.",
|
|
147
|
+
].join("\n");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function runSwarm(opts) {
|
|
151
|
+
const goal = String(opts.goal || "").trim();
|
|
152
|
+
if (!goal) throw new Error("swarm requires a goal");
|
|
153
|
+
|
|
154
|
+
const cwd = opts.cwd || process.cwd();
|
|
155
|
+
const root = opts.root || requireProjectRoot(cwd);
|
|
156
|
+
const defaultHarness = opts.harness || detectDefaultHarness();
|
|
157
|
+
const harness = parseHarnessSpec(defaultHarness);
|
|
158
|
+
const roleSpecs = resolveRoleSpecs({
|
|
159
|
+
root,
|
|
160
|
+
roles: opts.roles || null,
|
|
161
|
+
team: opts.team || null,
|
|
162
|
+
defaultHarness,
|
|
163
|
+
});
|
|
164
|
+
const roles = roleSpecs.map((r) => r.name);
|
|
165
|
+
const rounds = Math.max(1, Number(opts.rounds || 2));
|
|
166
|
+
const readonly = opts.readonly !== false;
|
|
167
|
+
const timeoutMs = Math.max(5, Number(opts.timeoutS || 300)) * 1000;
|
|
168
|
+
const budgetUsd = opts.budgetUsd != null ? Number(opts.budgetUsd) : null;
|
|
169
|
+
const quiet = !!opts.quiet;
|
|
170
|
+
|
|
171
|
+
const runId = `swarm-${Date.now().toString(36)}`;
|
|
172
|
+
const dir = join(swarmsDir(root), runId);
|
|
173
|
+
mkdirSync(dir, { recursive: true });
|
|
174
|
+
|
|
175
|
+
const log = (msg) => {
|
|
176
|
+
if (!quiet) console.error(`[swarm] ${msg}`);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const startedAt = Date.now();
|
|
180
|
+
const posts = [];
|
|
181
|
+
let totalCostUsd = 0;
|
|
182
|
+
|
|
183
|
+
for (let round = 1; round <= rounds; round++) {
|
|
184
|
+
if (budgetUsd != null && totalCostUsd >= budgetUsd) {
|
|
185
|
+
log(`budget cap $${budgetUsd.toFixed(2)} reached before round ${round}`);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
log(`round ${round}/${rounds}: running ${roleSpecs.map((r) => `${r.name} (${r.harness.label})`).join(", ")}`);
|
|
189
|
+
const priorSnapshot = [...posts];
|
|
190
|
+
|
|
191
|
+
const roundPosts = await Promise.all(
|
|
192
|
+
roleSpecs.map(async (roleSpec) => {
|
|
193
|
+
const res = await runAgent({
|
|
194
|
+
harness: roleSpec.harness,
|
|
195
|
+
prompt: buildRolePrompt({ goal, roleSpec, roleNames: roles, round, totalRounds: rounds, priorPosts: priorSnapshot }),
|
|
196
|
+
cwd: root,
|
|
197
|
+
readonly,
|
|
198
|
+
maxBudgetUsd: budgetUsd != null ? Math.max(0.01, (budgetUsd - totalCostUsd) / roleSpecs.length) : null,
|
|
199
|
+
timeoutMs,
|
|
200
|
+
env: {
|
|
201
|
+
OALO_SWARM_RUN_ID: runId,
|
|
202
|
+
OALO_SWARM_ROLE: roleSpec.name,
|
|
203
|
+
OALO_SWARM_ROLE_SOURCE: roleSpec.source,
|
|
204
|
+
OALO_SWARM_ROUND: String(round),
|
|
205
|
+
OALO_SWARM_PHASE: "discuss",
|
|
206
|
+
OALO_SWARM_GOAL: goal,
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
return {
|
|
210
|
+
round,
|
|
211
|
+
role: roleSpec.name,
|
|
212
|
+
role_source: roleSpec.source,
|
|
213
|
+
harness: res.label,
|
|
214
|
+
ok: res.ok,
|
|
215
|
+
cost_usd: Number((res.costUsd || 0).toFixed(6)),
|
|
216
|
+
duration_ms: res.durationMs,
|
|
217
|
+
content: (res.text || res.stderr || "(no output)").trim(),
|
|
218
|
+
};
|
|
219
|
+
}),
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
for (const p of roundPosts) {
|
|
223
|
+
totalCostUsd += p.cost_usd;
|
|
224
|
+
posts.push(p);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
log("synthesizing blackboard into report.md and promotable plan.json");
|
|
229
|
+
const synthRes = await runAgent({
|
|
230
|
+
harness,
|
|
231
|
+
prompt: buildSynthPrompt({ goal, roles, posts }),
|
|
232
|
+
cwd: root,
|
|
233
|
+
readonly: true,
|
|
234
|
+
timeoutMs,
|
|
235
|
+
env: {
|
|
236
|
+
OALO_SWARM_RUN_ID: runId,
|
|
237
|
+
OALO_SWARM_ROLE: "synthesizer",
|
|
238
|
+
OALO_SWARM_ROUND: String(rounds + 1),
|
|
239
|
+
OALO_SWARM_PHASE: "synthesize",
|
|
240
|
+
OALO_SWARM_GOAL: goal,
|
|
241
|
+
},
|
|
242
|
+
});
|
|
243
|
+
totalCostUsd += synthRes.costUsd || 0;
|
|
244
|
+
|
|
245
|
+
const synthJson = extractJsonObject(synthRes.text) || {
|
|
246
|
+
summary: (synthRes.text || "").slice(0, 400),
|
|
247
|
+
report_md: synthRes.text || "",
|
|
248
|
+
design: (synthRes.text || "").slice(0, 1500),
|
|
249
|
+
tasks: [],
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const plan = {
|
|
253
|
+
source_swarm: runId,
|
|
254
|
+
goal,
|
|
255
|
+
design: String(synthJson.design || synthJson.summary || goal),
|
|
256
|
+
tasks: Array.isArray(synthJson.tasks) ? synthJson.tasks : [],
|
|
257
|
+
};
|
|
258
|
+
const reportMd = String(synthJson.report_md || synthJson.summary || synthRes.text || "");
|
|
259
|
+
|
|
260
|
+
const board = {
|
|
261
|
+
run_id: runId,
|
|
262
|
+
goal,
|
|
263
|
+
team: opts.team || null,
|
|
264
|
+
roles,
|
|
265
|
+
role_configs: roleSpecs.map((r) => ({ name: r.name, source: r.source, harness: r.harness.label })),
|
|
266
|
+
rounds,
|
|
267
|
+
harness: harness.label,
|
|
268
|
+
readonly,
|
|
269
|
+
created_at: new Date().toISOString(),
|
|
270
|
+
duration_ms: Date.now() - startedAt,
|
|
271
|
+
total_cost_usd: Number(totalCostUsd.toFixed(6)),
|
|
272
|
+
summary: String(synthJson.summary || ""),
|
|
273
|
+
report_md: reportMd,
|
|
274
|
+
plan_tasks: plan.tasks.length,
|
|
275
|
+
posts,
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
writeFileSync(join(dir, "board.json"), JSON.stringify(board, null, 2) + "\n");
|
|
279
|
+
writeFileSync(join(dir, "board.md"), renderBoardMd(board));
|
|
280
|
+
writeFileSync(join(dir, "report.md"), reportMd + "\n");
|
|
281
|
+
writeFileSync(join(dir, "plan.json"), JSON.stringify(plan, null, 2) + "\n");
|
|
282
|
+
|
|
283
|
+
return { ...board, dir, plan_file: join(dir, "plan.json"), report_file: join(dir, "report.md") };
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Invoke `oalo coord` (via Bun source if available, else installed coord binary). */
|
|
287
|
+
export function runCoordCli(root, coordArgs) {
|
|
288
|
+
const srcMain = fileURLToPath(new URL("../coord/main.ts", import.meta.url));
|
|
289
|
+
if (existsSync(srcMain)) {
|
|
290
|
+
const bunCheck = spawnSync("bun", ["--version"], { stdio: "ignore" });
|
|
291
|
+
if (bunCheck.status === 0) {
|
|
292
|
+
return spawnSync("bun", [srcMain, ...coordArgs], { cwd: root, encoding: "utf8" });
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const relPath = fileURLToPath(new URL("../coord-release.json", import.meta.url));
|
|
296
|
+
if (existsSync(relPath)) {
|
|
297
|
+
const rel = JSON.parse(readFileSync(relPath, "utf8"));
|
|
298
|
+
const bin = coordBinary(rel.version);
|
|
299
|
+
if (existsSync(bin)) {
|
|
300
|
+
return spawnSync(bin, coordArgs, { cwd: root, encoding: "utf8" });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
throw new Error("oalo coord runtime not found (need bun in dev or `oalo coord install`)");
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export function promoteSwarm({ root, runId = null }) {
|
|
307
|
+
const { dir, data } = loadSwarm(root, runId);
|
|
308
|
+
const planFile = join(dir, "plan.json");
|
|
309
|
+
if (!existsSync(planFile)) throw new Error(`no plan.json found for ${data.run_id}`);
|
|
310
|
+
const plan = JSON.parse(readFileSync(planFile, "utf8"));
|
|
311
|
+
if (!Array.isArray(plan.tasks) || !plan.tasks.length) {
|
|
312
|
+
throw new Error(`swarm ${data.run_id} produced 0 tasks in plan.json`);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Initialize board if not yet initialized.
|
|
316
|
+
if (!existsSync(join(root, ".oalo", "coord.json"))) {
|
|
317
|
+
const init = runCoordCli(root, ["coord", "init"]);
|
|
318
|
+
if (init.status !== 0) throw new Error(`oalo coord init failed: ${init.stderr || init.stdout}`);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const imp = runCoordCli(root, ["coord", "import-plan", planFile, "--json"]);
|
|
322
|
+
if (imp.status !== 0) {
|
|
323
|
+
throw new Error(`oalo coord import-plan failed: ${imp.stderr || imp.stdout}`);
|
|
324
|
+
}
|
|
325
|
+
return { run_id: data.run_id, plan_file: planFile, imported: JSON.parse(imp.stdout) };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export async function swarm(flags, rest) {
|
|
329
|
+
const sub = rest[1];
|
|
330
|
+
if (flags.help || !sub || sub === "help") {
|
|
331
|
+
console.log(USAGE);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
const root = requireProjectRoot(process.cwd());
|
|
335
|
+
|
|
336
|
+
if (sub === "roles") {
|
|
337
|
+
const action = rest[2] || "list";
|
|
338
|
+
if (action === "list") {
|
|
339
|
+
const reg = loadRoleRegistry(root);
|
|
340
|
+
const roles = Object.values(reg).sort((a, b) => a.category.localeCompare(b.category) || a.name.localeCompare(b.name));
|
|
341
|
+
const teams = Object.entries(BUILTIN_TEAMS).map(([name, t]) => ({ name, ...t }));
|
|
342
|
+
if (flags.json) {
|
|
343
|
+
console.log(JSON.stringify({ roles, teams }, null, 2));
|
|
344
|
+
} else {
|
|
345
|
+
console.log("Roles:");
|
|
346
|
+
for (const r of roles) {
|
|
347
|
+
const h = r.harness ? ` [harness: ${r.harness}]` : "";
|
|
348
|
+
console.log(` ${r.name.padEnd(18)} [${r.source.padEnd(7)} / ${r.category}] ${r.focus}${h}`);
|
|
349
|
+
}
|
|
350
|
+
console.log("\nTeams (--team <name>):");
|
|
351
|
+
for (const t of teams) {
|
|
352
|
+
console.log(` ${t.name.padEnd(14)} ${t.roles.join(", ")} (${t.description})`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (action === "show") {
|
|
358
|
+
const name = rest[3];
|
|
359
|
+
if (!name) {
|
|
360
|
+
console.error("usage: oalo swarm roles show <name>");
|
|
361
|
+
process.exit(2);
|
|
362
|
+
}
|
|
363
|
+
const role = getRole(root, name);
|
|
364
|
+
if (!role) {
|
|
365
|
+
console.error(`oalo swarm roles: unknown role \`${name}\``);
|
|
366
|
+
process.exit(1);
|
|
367
|
+
}
|
|
368
|
+
if (flags.json) console.log(JSON.stringify(role, null, 2));
|
|
369
|
+
else {
|
|
370
|
+
console.log(`${role.name} [${role.source} / ${role.category}]`);
|
|
371
|
+
console.log(`Focus: ${role.focus}`);
|
|
372
|
+
if (role.harness) console.log(`Default harness: ${role.harness}`);
|
|
373
|
+
if (role.checklist.length) {
|
|
374
|
+
console.log("Checklist:");
|
|
375
|
+
for (const item of role.checklist) console.log(` - ${item}`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (action === "add") {
|
|
381
|
+
const name = rest[3];
|
|
382
|
+
if (!name || typeof flags.focus !== "string") {
|
|
383
|
+
console.error('usage: oalo swarm roles add <name> --focus "<text>" [--checklist "a,b,c"] [--harness <spec>] [--global]');
|
|
384
|
+
process.exit(2);
|
|
385
|
+
}
|
|
386
|
+
const saved = saveRole({
|
|
387
|
+
root,
|
|
388
|
+
name,
|
|
389
|
+
focus: flags.focus,
|
|
390
|
+
checklist: typeof flags.checklist === "string" ? flags.checklist : [],
|
|
391
|
+
harness: typeof flags.harness === "string" ? flags.harness : null,
|
|
392
|
+
category: typeof flags.category === "string" ? flags.category : "custom",
|
|
393
|
+
global: !!flags.global,
|
|
394
|
+
});
|
|
395
|
+
if (flags.json) console.log(JSON.stringify(saved, null, 2));
|
|
396
|
+
else console.log(`saved role \`${saved.name}\` (${saved.source}): ${saved.file}`);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (action === "rm" || action === "remove" || action === "delete") {
|
|
400
|
+
const name = rest[3];
|
|
401
|
+
if (!name) {
|
|
402
|
+
console.error("usage: oalo swarm roles rm <name> [--global]");
|
|
403
|
+
process.exit(2);
|
|
404
|
+
}
|
|
405
|
+
const res = deleteRole({ root, name, global: !!flags.global });
|
|
406
|
+
if (flags.json) console.log(JSON.stringify(res, null, 2));
|
|
407
|
+
else console.log(`removed custom role \`${res.deleted}\` (${res.scope})`);
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
console.error(`unknown swarm roles action: ${action}\n\n${USAGE}`);
|
|
411
|
+
process.exit(2);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (sub === "status") {
|
|
415
|
+
const { data, dir } = loadSwarm(root, rest[2] || null);
|
|
416
|
+
if (flags.json) console.log(JSON.stringify(data, null, 2));
|
|
417
|
+
else {
|
|
418
|
+
console.log(`Swarm ${data.run_id}: ${data.goal}`);
|
|
419
|
+
console.log(` roles: ${data.roles.join(", ")} rounds: ${data.rounds} posts: ${data.posts.length} tasks: ${data.plan_tasks} cost: $${data.total_cost_usd.toFixed(4)}`);
|
|
420
|
+
console.log(` report: ${join(dir, "report.md")}`);
|
|
421
|
+
}
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (sub === "promote") {
|
|
426
|
+
const res = promoteSwarm({ root, runId: rest[2] || null });
|
|
427
|
+
if (flags.json) console.log(JSON.stringify(res, null, 2));
|
|
428
|
+
else {
|
|
429
|
+
console.log(`promoted swarm ${res.run_id} -> ${res.imported.created.length} draft task(s) submitted to oalo coord`);
|
|
430
|
+
console.log("Next: review and approve in your terminal with `oalo coord approve plan`");
|
|
431
|
+
}
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const goal = typeof flags.goal === "string" ? flags.goal : rest.slice(1).join(" ").trim();
|
|
436
|
+
const res = await runSwarm({
|
|
437
|
+
root,
|
|
438
|
+
goal,
|
|
439
|
+
team: typeof flags.team === "string" ? flags.team : null,
|
|
440
|
+
roles: typeof flags.roles === "string" ? flags.roles : null,
|
|
441
|
+
rounds: flags.rounds ? Number(flags.rounds) : 2,
|
|
442
|
+
harness: typeof flags.harness === "string" ? flags.harness : null,
|
|
443
|
+
readonly: flags.readonly !== false,
|
|
444
|
+
budgetUsd: flags.budget ? Number(flags.budget) : null,
|
|
445
|
+
timeoutS: flags.timeout ? Number(flags.timeout) : 300,
|
|
446
|
+
quiet: !!flags.json,
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
if (flags.json) {
|
|
450
|
+
console.log(JSON.stringify(res, null, 2));
|
|
451
|
+
} else {
|
|
452
|
+
console.log(`\nSwarm ${res.run_id} finished (${res.posts.length} posts, ${res.plan_tasks} draft tasks, $${res.total_cost_usd.toFixed(4)})`);
|
|
453
|
+
if (res.summary) console.log(`\n${res.summary}`);
|
|
454
|
+
console.log(`\nReport: ${res.report_file}`);
|
|
455
|
+
if (res.plan_tasks > 0) console.log(`Promote to oalo coord: oalo swarm promote ${res.run_id}`);
|
|
456
|
+
}
|
|
457
|
+
}
|
package/src/commands/switches.js
CHANGED
|
@@ -19,9 +19,10 @@ import { appIdFor } from "../app-ref.js";
|
|
|
19
19
|
export async function loops(flags, rest, opts = {}) {
|
|
20
20
|
const [, sub, name] = rest;
|
|
21
21
|
if (sub === "runs") return runs(flags, name, opts);
|
|
22
|
+
if (sub === "replay") return replay(flags, name, opts);
|
|
22
23
|
if (sub === "list") return list(flags, opts);
|
|
23
24
|
if (!["test", "on", "off", "delete"].includes(sub) || !name) {
|
|
24
|
-
return fail("usage: oalo loops list, oalo loops test|on|off|delete <name>,
|
|
25
|
+
return fail("usage: oalo loops list, oalo loops test|on|off|delete <name>, oalo loops runs [<name>] [--id <run>], or oalo loops replay <run-id> --from <node-id> [--input <json|@file>]", 2, flags);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
// `emit` and `run loop` take --payload; `loops test` silently ran with an
|
|
@@ -127,6 +128,36 @@ async function runs(flags, name, opts) {
|
|
|
127
128
|
});
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
/** `oalo loops replay <run-id> --from <node-id> [--input <json|@file>]`: replay from a step. */
|
|
132
|
+
async function replay(flags, rawRunId, opts) {
|
|
133
|
+
const runId = Number(rawRunId);
|
|
134
|
+
const nodeId = typeof flags.from === "string" ? flags.from.trim() : "";
|
|
135
|
+
if (!Number.isInteger(runId) || runId <= 0 || !nodeId) {
|
|
136
|
+
return fail("usage: oalo loops replay <run-id> --from <node-id> [--input <json|@file>] [--json]", 2, flags);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let input;
|
|
140
|
+
if (flags.input !== undefined) {
|
|
141
|
+
try {
|
|
142
|
+
input = readInput(flags.input);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
return fail(e.message, 2, flags);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return withChannel(flags, opts, async (ch) => {
|
|
149
|
+
const params = {
|
|
150
|
+
run_id: runId,
|
|
151
|
+
node_id: nodeId,
|
|
152
|
+
...(input !== undefined ? { input } : {}),
|
|
153
|
+
};
|
|
154
|
+
const r = await ch.call("loops:replay_from_step", params);
|
|
155
|
+
if (flags.json) return void console.log(JSON.stringify(r, null, 2));
|
|
156
|
+
console.log(`replayed ${r.loop_name || "loop"} from ${r.node_id || nodeId} (new run ${r.run_id})`);
|
|
157
|
+
console.error(dim(`inspect the new run: oalo loops runs --id ${r.run_id}`));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
130
161
|
function printTest(r) {
|
|
131
162
|
console.log(`${r.status}${r.error ? `: ${r.error}` : ""} ${dim(`(run ${r.run_id})`)}`);
|
|
132
163
|
for (const s of r.steps || []) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { OaloChannel } from "../channel.js";
|
|
2
|
+
import { resolve as resolveConfig, controlPlane, HOW_TO_CONNECT } from "../config.js";
|
|
3
|
+
import { dim } from "../events.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `oalo usage`: calendar month-to-date AI spend attribution by bot, by workflow
|
|
7
|
+
* loop, and top-spending conversations (`usage:ledger`).
|
|
8
|
+
*/
|
|
9
|
+
export async function usage(flags, _rest, opts = {}) {
|
|
10
|
+
const cfg = resolveConfig(flags);
|
|
11
|
+
const { url, token } = controlPlane(cfg);
|
|
12
|
+
if (!url || !token) return fail(`oalo usage needs a CLI token.\n\n${HOW_TO_CONNECT}`, 2, flags);
|
|
13
|
+
|
|
14
|
+
const ch = (opts.channel || ((o) => new OaloChannel(o)))({ url, token });
|
|
15
|
+
try {
|
|
16
|
+
await ch.connect();
|
|
17
|
+
const r = await ch.call("usage:ledger", {});
|
|
18
|
+
if (flags.json) return void console.log(JSON.stringify(r, null, 2));
|
|
19
|
+
|
|
20
|
+
const mtd = Number(r?.mtd?.cost_usd ?? r?.mtd ?? 0);
|
|
21
|
+
console.log(`MTD estimated AI spend: $${mtd.toFixed(4)}`);
|
|
22
|
+
|
|
23
|
+
const bots = r?.by_bot || [];
|
|
24
|
+
if (bots.length) {
|
|
25
|
+
console.log("\nBy bot:");
|
|
26
|
+
for (const b of bots) {
|
|
27
|
+
const name = b.bot_name || b.name || b.public_bot_id || `bot #${b.bot_id}`;
|
|
28
|
+
const cost = Number(b.cost_usd ?? 0).toFixed(4);
|
|
29
|
+
const turns = b.turns ?? b.messages ?? "";
|
|
30
|
+
console.log(` ${String(name).padEnd(32)} $${cost}${turns !== "" ? dim(` (${turns} turns)`) : ""}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const loops = r?.by_loop || [];
|
|
35
|
+
if (loops.length) {
|
|
36
|
+
console.log("\nBy workflow:");
|
|
37
|
+
for (const l of loops) {
|
|
38
|
+
const name = l.loop_name || l.name || "workflow";
|
|
39
|
+
const cost = Number(l.cost_usd ?? 0).toFixed(4);
|
|
40
|
+
const runs = l.runs ?? "";
|
|
41
|
+
console.log(` ${String(name).padEnd(32)} $${cost}${runs !== "" ? dim(` (${runs} runs)`) : ""}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const convs = r?.top_conversations || [];
|
|
46
|
+
if (convs.length) {
|
|
47
|
+
console.log("\nTop conversations:");
|
|
48
|
+
for (const c of convs.slice(0, 10)) {
|
|
49
|
+
const id = `#${c.conversation_id ?? c.id}`;
|
|
50
|
+
const who = c.contact_name || c.external_ref || c.bot_name || "";
|
|
51
|
+
const cost = Number(c.cost_usd ?? 0).toFixed(4);
|
|
52
|
+
console.log(` ${id.padEnd(10)} ${String(who).slice(0, 26).padEnd(26)} $${cost}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return fail(e.message, 1, flags);
|
|
57
|
+
} finally {
|
|
58
|
+
ch.close();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function fail(msg, code, flags) {
|
|
63
|
+
if (flags?.json) console.log(JSON.stringify({ error: msg }));
|
|
64
|
+
else console.error(msg);
|
|
65
|
+
process.exitCode = code;
|
|
66
|
+
}
|
package/src/coord-release.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.7.0",
|
|
3
3
|
"targets": {
|
|
4
4
|
"darwin-arm64": {
|
|
5
5
|
"file": "oalo-coord-darwin-arm64.gz",
|
|
6
|
-
"sha256": "
|
|
7
|
-
"bytes":
|
|
6
|
+
"sha256": "e689f1a38178d13cc1a10f4d50ce15927da58ca7484e3e963d82bcb73e581893",
|
|
7
|
+
"bytes": 24874385
|
|
8
8
|
},
|
|
9
9
|
"darwin-x64": {
|
|
10
10
|
"file": "oalo-coord-darwin-x64.gz",
|
|
11
|
-
"sha256": "
|
|
12
|
-
"bytes":
|
|
11
|
+
"sha256": "c9d7a43b292de653526cd73139e97f5683b5f5cf4fb07392439fdbe32a2e5f81",
|
|
12
|
+
"bytes": 27013652
|
|
13
13
|
},
|
|
14
14
|
"linux-x64": {
|
|
15
15
|
"file": "oalo-coord-linux-x64.gz",
|
|
16
|
-
"sha256": "
|
|
17
|
-
"bytes":
|
|
16
|
+
"sha256": "dad3c5e0dd9a794c200ec2824fbf7a3786700b96f9c46ad18a53b873db645983",
|
|
17
|
+
"bytes": 36905376
|
|
18
18
|
},
|
|
19
19
|
"linux-arm64": {
|
|
20
20
|
"file": "oalo-coord-linux-arm64.gz",
|
|
21
|
-
"sha256": "
|
|
22
|
-
"bytes":
|
|
21
|
+
"sha256": "e58aeadf446af3d09806e6525e2edc29888337dd84592e863e82545ed96eb352",
|
|
22
|
+
"bytes": 37145971
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|