sentinelayer-cli 0.1.1 → 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.
- package/README.md +996 -996
- package/bin/create-sentinelayer.js +5 -5
- package/bin/sentinelayer-cli.js +4 -4
- package/bin/sl.js +5 -5
- package/package.json +62 -54
- package/src/agents/jules/config/definition.js +209 -209
- package/src/agents/jules/config/system-prompt.js +175 -175
- package/src/agents/jules/error-intake.js +51 -51
- package/src/agents/jules/fix-cycle.js +377 -377
- package/src/agents/jules/loop.js +367 -367
- package/src/agents/jules/pulse.js +319 -319
- package/src/agents/jules/stream.js +186 -186
- package/src/agents/jules/swarm/file-scanner.js +74 -74
- package/src/agents/jules/swarm/index.js +11 -11
- package/src/agents/jules/swarm/orchestrator.js +362 -362
- package/src/agents/jules/swarm/pattern-hunter.js +123 -123
- package/src/agents/jules/swarm/sub-agent.js +308 -308
- package/src/agents/jules/tools/auth-audit.js +226 -222
- package/src/agents/jules/tools/dispatch.js +327 -327
- package/src/agents/jules/tools/file-edit.js +180 -180
- package/src/agents/jules/tools/file-read.js +100 -100
- package/src/agents/jules/tools/frontend-analyze.js +570 -570
- package/src/agents/jules/tools/glob.js +168 -168
- package/src/agents/jules/tools/grep.js +228 -228
- package/src/agents/jules/tools/index.js +29 -29
- package/src/agents/jules/tools/path-guards.js +161 -161
- package/src/agents/jules/tools/runtime-audit.js +493 -493
- package/src/agents/jules/tools/shell.js +383 -383
- package/src/ai/aidenid.js +972 -945
- package/src/ai/client.js +508 -508
- package/src/ai/domain-target-store.js +268 -268
- package/src/ai/identity-store.js +270 -270
- package/src/ai/site-store.js +145 -145
- package/src/audit/agents/architecture.js +180 -180
- package/src/audit/agents/compliance.js +179 -179
- package/src/audit/agents/documentation.js +165 -165
- package/src/audit/agents/performance.js +145 -145
- package/src/audit/agents/security.js +215 -215
- package/src/audit/agents/testing.js +172 -172
- package/src/audit/orchestrator.js +557 -557
- package/src/audit/package.js +204 -204
- package/src/audit/registry.js +284 -284
- package/src/audit/replay.js +103 -103
- package/src/auth/http.js +113 -113
- package/src/auth/service.js +891 -848
- package/src/auth/session-store.js +359 -345
- package/src/cli.js +252 -252
- package/src/commands/ai/identity-lifecycle.js +1338 -1337
- package/src/commands/ai/provision-governance.js +1272 -1246
- package/src/commands/ai/shared.js +147 -147
- package/src/commands/ai.js +11 -11
- package/src/commands/apply.js +12 -12
- package/src/commands/audit.js +1166 -1147
- package/src/commands/auth.js +375 -366
- package/src/commands/chat.js +191 -191
- package/src/commands/config.js +184 -184
- package/src/commands/cost.js +311 -311
- package/src/commands/daemon/core.js +850 -850
- package/src/commands/daemon/extended.js +1048 -1048
- package/src/commands/daemon/shared.js +213 -213
- package/src/commands/daemon.js +11 -11
- package/src/commands/guide.js +174 -174
- package/src/commands/ingest.js +58 -58
- package/src/commands/init.js +55 -55
- package/src/commands/legacy-args.js +10 -10
- package/src/commands/mcp.js +461 -404
- package/src/commands/omargate.js +15 -15
- package/src/commands/persona.js +20 -20
- package/src/commands/plugin.js +260 -260
- package/src/commands/policy.js +132 -132
- package/src/commands/prompt.js +238 -238
- package/src/commands/review.js +704 -704
- package/src/commands/scan.js +866 -788
- package/src/commands/spec.js +716 -716
- package/src/commands/swarm.js +651 -651
- package/src/commands/telemetry.js +202 -202
- package/src/commands/watch.js +510 -510
- package/src/config/agent-dictionary.js +182 -182
- package/src/config/io.js +56 -56
- package/src/config/paths.js +18 -18
- package/src/config/schema.js +55 -55
- package/src/config/service.js +184 -184
- package/src/cost/budget.js +235 -235
- package/src/cost/history.js +188 -188
- package/src/cost/tracker.js +171 -171
- package/src/daemon/artifact-lineage.js +534 -534
- package/src/daemon/assignment-ledger.js +770 -770
- package/src/daemon/ast-parser-layer.js +258 -258
- package/src/daemon/budget-governor.js +633 -633
- package/src/daemon/callgraph-overlay.js +646 -646
- package/src/daemon/error-worker.js +626 -626
- package/src/daemon/hybrid-mapper.js +929 -929
- package/src/daemon/ingest-refresh.js +195 -0
- package/src/daemon/jira-lifecycle.js +632 -632
- package/src/daemon/operator-control.js +657 -657
- package/src/daemon/reliability-lane.js +471 -471
- package/src/daemon/watchdog.js +971 -971
- package/src/guide/generator.js +316 -316
- package/src/ingest/engine.js +918 -918
- package/src/interactive/action-menu.js +132 -0
- package/src/interactive/auto-ingest.js +111 -0
- package/src/interactive/index.js +95 -0
- package/src/interactive/workspace.js +92 -0
- package/src/legacy-cli.js +2548 -2435
- package/src/mcp/registry.js +695 -695
- package/src/memory/blackboard.js +301 -301
- package/src/memory/retrieval.js +581 -581
- package/src/plugin/manifest.js +553 -553
- package/src/policy/packs.js +144 -144
- package/src/prompt/generator.js +118 -106
- package/src/review/ai-review.js +669 -669
- package/src/review/local-review.js +1284 -1284
- package/src/review/replay.js +235 -235
- package/src/review/report.js +664 -664
- package/src/review/spec-binding.js +487 -487
- package/src/scaffold/generator.js +67 -0
- package/src/scaffold/templates.js +150 -0
- package/src/scan/generator.js +418 -351
- package/src/scan/gh-secrets.js +107 -0
- package/src/spec/generator.js +519 -519
- package/src/spec/regenerate.js +237 -237
- package/src/spec/templates.js +91 -91
- package/src/swarm/dashboard.js +247 -247
- package/src/swarm/factory.js +363 -363
- package/src/swarm/pentest.js +934 -934
- package/src/swarm/registry.js +419 -419
- package/src/swarm/report.js +158 -158
- package/src/swarm/runtime.js +576 -576
- package/src/swarm/scenario-dsl.js +272 -272
- package/src/telemetry/ledger.js +302 -302
- package/src/telemetry/session-tracker.js +118 -0
- package/src/telemetry/sync.js +190 -0
- package/src/ui/markdown.js +220 -220
package/src/swarm/registry.js
CHANGED
|
@@ -1,419 +1,419 @@
|
|
|
1
|
-
import fsp from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
const DEFAULT_BUDGET = Object.freeze({
|
|
5
|
-
maxCostUsd: 0.5,
|
|
6
|
-
maxOutputTokens: 3000,
|
|
7
|
-
maxRuntimeMs: 300000,
|
|
8
|
-
maxToolCalls: 40,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const BUILTIN_SWARM_AGENTS = Object.freeze([
|
|
12
|
-
{
|
|
13
|
-
id: "omar",
|
|
14
|
-
persona: "Omar Gate",
|
|
15
|
-
role: "orchestrator",
|
|
16
|
-
domain: "Autonomous Governance",
|
|
17
|
-
tools: ["planner", "budget-governor", "handoff-router"],
|
|
18
|
-
permissionMode: "plan",
|
|
19
|
-
maxTurns: 12,
|
|
20
|
-
confidenceFloor: 0.9,
|
|
21
|
-
allowedPaths: ["."],
|
|
22
|
-
networkMode: "restricted",
|
|
23
|
-
defaultBudget: {
|
|
24
|
-
maxCostUsd: 1.5,
|
|
25
|
-
maxOutputTokens: 10000,
|
|
26
|
-
maxRuntimeMs: 900000,
|
|
27
|
-
maxToolCalls: 120,
|
|
28
|
-
},
|
|
29
|
-
evidenceRequirements: ["scope_constraints", "handoff_manifest", "gate_decision"],
|
|
30
|
-
escalationTargets: ["security", "reliability", "release"],
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
id: "security",
|
|
34
|
-
persona: "Nina Patel",
|
|
35
|
-
role: "specialist",
|
|
36
|
-
domain: "Security",
|
|
37
|
-
tools: ["read", "grep", "dependency-audit"],
|
|
38
|
-
permissionMode: "plan",
|
|
39
|
-
maxTurns: 8,
|
|
40
|
-
confidenceFloor: 0.85,
|
|
41
|
-
allowedPaths: ["."],
|
|
42
|
-
networkMode: "restricted",
|
|
43
|
-
defaultBudget: {
|
|
44
|
-
maxCostUsd: 0.8,
|
|
45
|
-
maxOutputTokens: 4000,
|
|
46
|
-
maxRuntimeMs: 480000,
|
|
47
|
-
maxToolCalls: 60,
|
|
48
|
-
},
|
|
49
|
-
evidenceRequirements: ["file_line_reference", "repro_steps"],
|
|
50
|
-
escalationTargets: ["release", "reliability"],
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
id: "architecture",
|
|
54
|
-
persona: "Maya Volkov",
|
|
55
|
-
role: "specialist",
|
|
56
|
-
domain: "Architecture",
|
|
57
|
-
tools: ["read", "grep", "structure-map"],
|
|
58
|
-
permissionMode: "plan",
|
|
59
|
-
maxTurns: 8,
|
|
60
|
-
confidenceFloor: 0.82,
|
|
61
|
-
allowedPaths: ["."],
|
|
62
|
-
networkMode: "restricted",
|
|
63
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
64
|
-
evidenceRequirements: ["component_map", "impact_summary"],
|
|
65
|
-
escalationTargets: ["performance", "testing"],
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
id: "testing",
|
|
69
|
-
persona: "Priya Raman",
|
|
70
|
-
role: "specialist",
|
|
71
|
-
domain: "Testing",
|
|
72
|
-
tools: ["read", "grep", "test-runner"],
|
|
73
|
-
permissionMode: "plan",
|
|
74
|
-
maxTurns: 6,
|
|
75
|
-
confidenceFloor: 0.8,
|
|
76
|
-
allowedPaths: ["."],
|
|
77
|
-
networkMode: "restricted",
|
|
78
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
79
|
-
evidenceRequirements: ["coverage_gaps", "failing_paths"],
|
|
80
|
-
escalationTargets: ["architecture"],
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
id: "performance",
|
|
84
|
-
persona: "Arjun Mehta",
|
|
85
|
-
role: "specialist",
|
|
86
|
-
domain: "Performance",
|
|
87
|
-
tools: ["read", "grep", "profiler-hints"],
|
|
88
|
-
permissionMode: "plan",
|
|
89
|
-
maxTurns: 6,
|
|
90
|
-
confidenceFloor: 0.8,
|
|
91
|
-
allowedPaths: ["."],
|
|
92
|
-
networkMode: "restricted",
|
|
93
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
94
|
-
evidenceRequirements: ["latency_paths", "runtime_assumptions"],
|
|
95
|
-
escalationTargets: ["architecture", "reliability"],
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
id: "compliance",
|
|
99
|
-
persona: "Leila Farouk",
|
|
100
|
-
role: "specialist",
|
|
101
|
-
domain: "Compliance",
|
|
102
|
-
tools: ["read", "grep", "control-map"],
|
|
103
|
-
permissionMode: "plan",
|
|
104
|
-
maxTurns: 6,
|
|
105
|
-
confidenceFloor: 0.82,
|
|
106
|
-
allowedPaths: ["."],
|
|
107
|
-
networkMode: "restricted",
|
|
108
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
109
|
-
evidenceRequirements: ["control_refs", "evidence_paths"],
|
|
110
|
-
escalationTargets: ["security", "release"],
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
id: "documentation",
|
|
114
|
-
persona: "Samir Okafor",
|
|
115
|
-
role: "specialist",
|
|
116
|
-
domain: "Documentation",
|
|
117
|
-
tools: ["read", "grep", "spec-check"],
|
|
118
|
-
permissionMode: "plan",
|
|
119
|
-
maxTurns: 5,
|
|
120
|
-
confidenceFloor: 0.75,
|
|
121
|
-
allowedPaths: ["."],
|
|
122
|
-
networkMode: "restricted",
|
|
123
|
-
defaultBudget: {
|
|
124
|
-
maxCostUsd: 0.35,
|
|
125
|
-
maxOutputTokens: 2500,
|
|
126
|
-
maxRuntimeMs: 240000,
|
|
127
|
-
maxToolCalls: 30,
|
|
128
|
-
},
|
|
129
|
-
evidenceRequirements: ["doc_paths", "spec_mismatches"],
|
|
130
|
-
escalationTargets: ["architecture", "release"],
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
id: "reliability",
|
|
134
|
-
persona: "Noah Ben-David",
|
|
135
|
-
role: "specialist",
|
|
136
|
-
domain: "Reliability",
|
|
137
|
-
tools: ["read", "grep", "failure-analysis"],
|
|
138
|
-
permissionMode: "plan",
|
|
139
|
-
maxTurns: 6,
|
|
140
|
-
confidenceFloor: 0.8,
|
|
141
|
-
allowedPaths: ["."],
|
|
142
|
-
networkMode: "restricted",
|
|
143
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
144
|
-
evidenceRequirements: ["failure_modes", "rollback_plan"],
|
|
145
|
-
escalationTargets: ["release", "observability"],
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
id: "release",
|
|
149
|
-
persona: "Omar Singh",
|
|
150
|
-
role: "specialist",
|
|
151
|
-
domain: "Release Engineering",
|
|
152
|
-
tools: ["read", "grep", "workflow-review"],
|
|
153
|
-
permissionMode: "plan",
|
|
154
|
-
maxTurns: 6,
|
|
155
|
-
confidenceFloor: 0.8,
|
|
156
|
-
allowedPaths: ["."],
|
|
157
|
-
networkMode: "restricted",
|
|
158
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
159
|
-
evidenceRequirements: ["workflow_refs", "gate_matrix"],
|
|
160
|
-
escalationTargets: ["security", "reliability"],
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
id: "observability",
|
|
164
|
-
persona: "Sofia Alvarez",
|
|
165
|
-
role: "specialist",
|
|
166
|
-
domain: "Observability",
|
|
167
|
-
tools: ["read", "grep", "telemetry-review"],
|
|
168
|
-
permissionMode: "plan",
|
|
169
|
-
maxTurns: 6,
|
|
170
|
-
confidenceFloor: 0.78,
|
|
171
|
-
allowedPaths: ["."],
|
|
172
|
-
networkMode: "restricted",
|
|
173
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
174
|
-
evidenceRequirements: ["signal_inventory", "gaps"],
|
|
175
|
-
escalationTargets: ["reliability", "release"],
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
id: "infrastructure",
|
|
179
|
-
persona: "Kat Hughes",
|
|
180
|
-
role: "specialist",
|
|
181
|
-
domain: "Infrastructure",
|
|
182
|
-
tools: ["read", "grep", "infra-lint"],
|
|
183
|
-
permissionMode: "plan",
|
|
184
|
-
maxTurns: 6,
|
|
185
|
-
confidenceFloor: 0.78,
|
|
186
|
-
allowedPaths: ["."],
|
|
187
|
-
networkMode: "restricted",
|
|
188
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
189
|
-
evidenceRequirements: ["infra_paths", "blast_radius"],
|
|
190
|
-
escalationTargets: ["security", "reliability"],
|
|
191
|
-
},
|
|
192
|
-
{
|
|
193
|
-
id: "supply-chain",
|
|
194
|
-
persona: "Nora Kline",
|
|
195
|
-
role: "specialist",
|
|
196
|
-
domain: "Supply Chain",
|
|
197
|
-
tools: ["read", "grep", "dependency-audit"],
|
|
198
|
-
permissionMode: "plan",
|
|
199
|
-
maxTurns: 6,
|
|
200
|
-
confidenceFloor: 0.82,
|
|
201
|
-
allowedPaths: ["."],
|
|
202
|
-
networkMode: "restricted",
|
|
203
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
204
|
-
evidenceRequirements: ["dependency_refs", "version_risks"],
|
|
205
|
-
escalationTargets: ["security", "release"],
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
id: "frontend",
|
|
209
|
-
persona: "Jules Tanaka",
|
|
210
|
-
role: "specialist",
|
|
211
|
-
domain: "Frontend",
|
|
212
|
-
tools: ["read", "grep", "ui-lint"],
|
|
213
|
-
permissionMode: "plan",
|
|
214
|
-
maxTurns: 6,
|
|
215
|
-
confidenceFloor: 0.76,
|
|
216
|
-
allowedPaths: ["."],
|
|
217
|
-
networkMode: "restricted",
|
|
218
|
-
defaultBudget: { ...DEFAULT_BUDGET },
|
|
219
|
-
evidenceRequirements: ["component_paths", "repro_steps"],
|
|
220
|
-
escalationTargets: ["testing", "architecture"],
|
|
221
|
-
},
|
|
222
|
-
]);
|
|
223
|
-
|
|
224
|
-
function normalizeString(value) {
|
|
225
|
-
return String(value || "").trim();
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function normalizeAgentId(value) {
|
|
229
|
-
return normalizeString(value).toLowerCase();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function normalizeRole(value) {
|
|
233
|
-
const normalized = normalizeString(value).toLowerCase();
|
|
234
|
-
if (normalized === "orchestrator" || normalized === "specialist") {
|
|
235
|
-
return normalized;
|
|
236
|
-
}
|
|
237
|
-
return "specialist";
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function normalizeNetworkMode(value) {
|
|
241
|
-
const normalized = normalizeString(value).toLowerCase();
|
|
242
|
-
if (normalized === "enabled" || normalized === "restricted" || normalized === "disabled") {
|
|
243
|
-
return normalized;
|
|
244
|
-
}
|
|
245
|
-
return "restricted";
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function normalizePositiveNumber(value, fallback, field) {
|
|
249
|
-
const normalized = Number(value);
|
|
250
|
-
if (Number.isFinite(normalized) && normalized > 0) {
|
|
251
|
-
return normalized;
|
|
252
|
-
}
|
|
253
|
-
if (fallback !== undefined) {
|
|
254
|
-
return Number(fallback);
|
|
255
|
-
}
|
|
256
|
-
throw new Error(`${field} must be a positive number.`);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function normalizeBudget(budget = {}, fallback = DEFAULT_BUDGET) {
|
|
260
|
-
if (budget === undefined || budget === null || typeof budget !== "object" || Array.isArray(budget)) {
|
|
261
|
-
throw new Error("defaultBudget must be an object when provided.");
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return {
|
|
265
|
-
maxCostUsd: normalizePositiveNumber(
|
|
266
|
-
budget.maxCostUsd,
|
|
267
|
-
fallback.maxCostUsd,
|
|
268
|
-
"defaultBudget.maxCostUsd"
|
|
269
|
-
),
|
|
270
|
-
maxOutputTokens: Math.floor(
|
|
271
|
-
normalizePositiveNumber(
|
|
272
|
-
budget.maxOutputTokens,
|
|
273
|
-
fallback.maxOutputTokens,
|
|
274
|
-
"defaultBudget.maxOutputTokens"
|
|
275
|
-
)
|
|
276
|
-
),
|
|
277
|
-
maxRuntimeMs: Math.floor(
|
|
278
|
-
normalizePositiveNumber(
|
|
279
|
-
budget.maxRuntimeMs,
|
|
280
|
-
fallback.maxRuntimeMs,
|
|
281
|
-
"defaultBudget.maxRuntimeMs"
|
|
282
|
-
)
|
|
283
|
-
),
|
|
284
|
-
maxToolCalls: Math.floor(
|
|
285
|
-
normalizePositiveNumber(
|
|
286
|
-
budget.maxToolCalls,
|
|
287
|
-
fallback.maxToolCalls,
|
|
288
|
-
"defaultBudget.maxToolCalls"
|
|
289
|
-
)
|
|
290
|
-
),
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function normalizeAgentRecord(record = {}, existing = {}) {
|
|
295
|
-
const id = normalizeAgentId(record.id || existing.id);
|
|
296
|
-
const fallbackBudget = existing.defaultBudget || DEFAULT_BUDGET;
|
|
297
|
-
|
|
298
|
-
return {
|
|
299
|
-
id,
|
|
300
|
-
persona: normalizeString(record.persona || existing.persona),
|
|
301
|
-
role: normalizeRole(record.role || existing.role),
|
|
302
|
-
domain: normalizeString(record.domain || existing.domain),
|
|
303
|
-
tools: Array.isArray(record.tools || existing.tools)
|
|
304
|
-
? (record.tools || existing.tools).map((item) => normalizeString(item)).filter(Boolean)
|
|
305
|
-
: [],
|
|
306
|
-
permissionMode: normalizeString(record.permissionMode || existing.permissionMode || "plan") || "plan",
|
|
307
|
-
maxTurns: Math.max(1, Math.floor(Number(record.maxTurns || existing.maxTurns || 1))),
|
|
308
|
-
confidenceFloor: Math.max(
|
|
309
|
-
0,
|
|
310
|
-
Math.min(1, Number(record.confidenceFloor || existing.confidenceFloor || 0.7))
|
|
311
|
-
),
|
|
312
|
-
allowedPaths: Array.isArray(record.allowedPaths || existing.allowedPaths)
|
|
313
|
-
? (record.allowedPaths || existing.allowedPaths).map((item) => normalizeString(item)).filter(Boolean)
|
|
314
|
-
: ["."],
|
|
315
|
-
networkMode: normalizeNetworkMode(record.networkMode || existing.networkMode),
|
|
316
|
-
defaultBudget: normalizeBudget(record.defaultBudget || existing.defaultBudget || {}, fallbackBudget),
|
|
317
|
-
evidenceRequirements: Array.isArray(record.evidenceRequirements || existing.evidenceRequirements)
|
|
318
|
-
? (record.evidenceRequirements || existing.evidenceRequirements)
|
|
319
|
-
.map((item) => normalizeString(item))
|
|
320
|
-
.filter(Boolean)
|
|
321
|
-
: [],
|
|
322
|
-
escalationTargets: Array.isArray(record.escalationTargets || existing.escalationTargets)
|
|
323
|
-
? (record.escalationTargets || existing.escalationTargets)
|
|
324
|
-
.map((item) => normalizeAgentId(item))
|
|
325
|
-
.filter(Boolean)
|
|
326
|
-
: [],
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function mergeRegistry(builtinAgents = [], overrideAgents = []) {
|
|
331
|
-
const byId = new Map();
|
|
332
|
-
const order = [];
|
|
333
|
-
|
|
334
|
-
for (const builtin of builtinAgents) {
|
|
335
|
-
const normalized = normalizeAgentRecord(builtin);
|
|
336
|
-
byId.set(normalized.id, normalized);
|
|
337
|
-
order.push(normalized.id);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
for (const override of overrideAgents) {
|
|
341
|
-
const id = normalizeAgentId(override.id);
|
|
342
|
-
if (!id) {
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
if (!byId.has(id)) {
|
|
346
|
-
order.push(id);
|
|
347
|
-
}
|
|
348
|
-
const existing = byId.get(id) || { id };
|
|
349
|
-
byId.set(id, normalizeAgentRecord(override, existing));
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return order.map((id) => ({ ...byId.get(id) })).filter(Boolean);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function parseAgentFilter(rawValue) {
|
|
356
|
-
const normalized = normalizeString(rawValue);
|
|
357
|
-
if (!normalized) {
|
|
358
|
-
return [];
|
|
359
|
-
}
|
|
360
|
-
return [...new Set(normalized.split(",").map((item) => normalizeAgentId(item)).filter(Boolean))];
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export function listBuiltinSwarmAgents() {
|
|
364
|
-
return BUILTIN_SWARM_AGENTS.map((agent) => normalizeAgentRecord(agent));
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
export async function loadSwarmRegistry({ registryFile = "" } = {}) {
|
|
368
|
-
const builtin = listBuiltinSwarmAgents();
|
|
369
|
-
const resolvedRegistryFile = normalizeString(registryFile)
|
|
370
|
-
? path.resolve(process.cwd(), registryFile)
|
|
371
|
-
: "";
|
|
372
|
-
if (!resolvedRegistryFile) {
|
|
373
|
-
return {
|
|
374
|
-
registrySource: "builtin",
|
|
375
|
-
registryFile: "",
|
|
376
|
-
agents: builtin,
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
const raw = await fsp.readFile(resolvedRegistryFile, "utf-8");
|
|
381
|
-
const parsed = JSON.parse(raw);
|
|
382
|
-
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.agents)) {
|
|
383
|
-
throw new Error("Invalid swarm registry file: expected { agents: [...] }.");
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return {
|
|
387
|
-
registrySource: "custom",
|
|
388
|
-
registryFile: resolvedRegistryFile,
|
|
389
|
-
agents: mergeRegistry(builtin, parsed.agents),
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
export function selectSwarmAgents(agents = [], requested = "") {
|
|
394
|
-
const requestedIds = parseAgentFilter(requested);
|
|
395
|
-
if (requestedIds.length === 0) {
|
|
396
|
-
return {
|
|
397
|
-
selected: [...agents],
|
|
398
|
-
requestedIds,
|
|
399
|
-
missing: [],
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
const byId = new Map(agents.map((agent) => [agent.id, agent]));
|
|
404
|
-
const selected = [];
|
|
405
|
-
const missing = [];
|
|
406
|
-
for (const id of requestedIds) {
|
|
407
|
-
const agent = byId.get(id);
|
|
408
|
-
if (!agent) {
|
|
409
|
-
missing.push(id);
|
|
410
|
-
continue;
|
|
411
|
-
}
|
|
412
|
-
selected.push(agent);
|
|
413
|
-
}
|
|
414
|
-
return {
|
|
415
|
-
selected,
|
|
416
|
-
requestedIds,
|
|
417
|
-
missing,
|
|
418
|
-
};
|
|
419
|
-
}
|
|
1
|
+
import fsp from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_BUDGET = Object.freeze({
|
|
5
|
+
maxCostUsd: 0.5,
|
|
6
|
+
maxOutputTokens: 3000,
|
|
7
|
+
maxRuntimeMs: 300000,
|
|
8
|
+
maxToolCalls: 40,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const BUILTIN_SWARM_AGENTS = Object.freeze([
|
|
12
|
+
{
|
|
13
|
+
id: "omar",
|
|
14
|
+
persona: "Omar Gate",
|
|
15
|
+
role: "orchestrator",
|
|
16
|
+
domain: "Autonomous Governance",
|
|
17
|
+
tools: ["planner", "budget-governor", "handoff-router"],
|
|
18
|
+
permissionMode: "plan",
|
|
19
|
+
maxTurns: 12,
|
|
20
|
+
confidenceFloor: 0.9,
|
|
21
|
+
allowedPaths: ["."],
|
|
22
|
+
networkMode: "restricted",
|
|
23
|
+
defaultBudget: {
|
|
24
|
+
maxCostUsd: 1.5,
|
|
25
|
+
maxOutputTokens: 10000,
|
|
26
|
+
maxRuntimeMs: 900000,
|
|
27
|
+
maxToolCalls: 120,
|
|
28
|
+
},
|
|
29
|
+
evidenceRequirements: ["scope_constraints", "handoff_manifest", "gate_decision"],
|
|
30
|
+
escalationTargets: ["security", "reliability", "release"],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "security",
|
|
34
|
+
persona: "Nina Patel",
|
|
35
|
+
role: "specialist",
|
|
36
|
+
domain: "Security",
|
|
37
|
+
tools: ["read", "grep", "dependency-audit"],
|
|
38
|
+
permissionMode: "plan",
|
|
39
|
+
maxTurns: 8,
|
|
40
|
+
confidenceFloor: 0.85,
|
|
41
|
+
allowedPaths: ["."],
|
|
42
|
+
networkMode: "restricted",
|
|
43
|
+
defaultBudget: {
|
|
44
|
+
maxCostUsd: 0.8,
|
|
45
|
+
maxOutputTokens: 4000,
|
|
46
|
+
maxRuntimeMs: 480000,
|
|
47
|
+
maxToolCalls: 60,
|
|
48
|
+
},
|
|
49
|
+
evidenceRequirements: ["file_line_reference", "repro_steps"],
|
|
50
|
+
escalationTargets: ["release", "reliability"],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: "architecture",
|
|
54
|
+
persona: "Maya Volkov",
|
|
55
|
+
role: "specialist",
|
|
56
|
+
domain: "Architecture",
|
|
57
|
+
tools: ["read", "grep", "structure-map"],
|
|
58
|
+
permissionMode: "plan",
|
|
59
|
+
maxTurns: 8,
|
|
60
|
+
confidenceFloor: 0.82,
|
|
61
|
+
allowedPaths: ["."],
|
|
62
|
+
networkMode: "restricted",
|
|
63
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
64
|
+
evidenceRequirements: ["component_map", "impact_summary"],
|
|
65
|
+
escalationTargets: ["performance", "testing"],
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: "testing",
|
|
69
|
+
persona: "Priya Raman",
|
|
70
|
+
role: "specialist",
|
|
71
|
+
domain: "Testing",
|
|
72
|
+
tools: ["read", "grep", "test-runner"],
|
|
73
|
+
permissionMode: "plan",
|
|
74
|
+
maxTurns: 6,
|
|
75
|
+
confidenceFloor: 0.8,
|
|
76
|
+
allowedPaths: ["."],
|
|
77
|
+
networkMode: "restricted",
|
|
78
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
79
|
+
evidenceRequirements: ["coverage_gaps", "failing_paths"],
|
|
80
|
+
escalationTargets: ["architecture"],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "performance",
|
|
84
|
+
persona: "Arjun Mehta",
|
|
85
|
+
role: "specialist",
|
|
86
|
+
domain: "Performance",
|
|
87
|
+
tools: ["read", "grep", "profiler-hints"],
|
|
88
|
+
permissionMode: "plan",
|
|
89
|
+
maxTurns: 6,
|
|
90
|
+
confidenceFloor: 0.8,
|
|
91
|
+
allowedPaths: ["."],
|
|
92
|
+
networkMode: "restricted",
|
|
93
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
94
|
+
evidenceRequirements: ["latency_paths", "runtime_assumptions"],
|
|
95
|
+
escalationTargets: ["architecture", "reliability"],
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "compliance",
|
|
99
|
+
persona: "Leila Farouk",
|
|
100
|
+
role: "specialist",
|
|
101
|
+
domain: "Compliance",
|
|
102
|
+
tools: ["read", "grep", "control-map"],
|
|
103
|
+
permissionMode: "plan",
|
|
104
|
+
maxTurns: 6,
|
|
105
|
+
confidenceFloor: 0.82,
|
|
106
|
+
allowedPaths: ["."],
|
|
107
|
+
networkMode: "restricted",
|
|
108
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
109
|
+
evidenceRequirements: ["control_refs", "evidence_paths"],
|
|
110
|
+
escalationTargets: ["security", "release"],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: "documentation",
|
|
114
|
+
persona: "Samir Okafor",
|
|
115
|
+
role: "specialist",
|
|
116
|
+
domain: "Documentation",
|
|
117
|
+
tools: ["read", "grep", "spec-check"],
|
|
118
|
+
permissionMode: "plan",
|
|
119
|
+
maxTurns: 5,
|
|
120
|
+
confidenceFloor: 0.75,
|
|
121
|
+
allowedPaths: ["."],
|
|
122
|
+
networkMode: "restricted",
|
|
123
|
+
defaultBudget: {
|
|
124
|
+
maxCostUsd: 0.35,
|
|
125
|
+
maxOutputTokens: 2500,
|
|
126
|
+
maxRuntimeMs: 240000,
|
|
127
|
+
maxToolCalls: 30,
|
|
128
|
+
},
|
|
129
|
+
evidenceRequirements: ["doc_paths", "spec_mismatches"],
|
|
130
|
+
escalationTargets: ["architecture", "release"],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: "reliability",
|
|
134
|
+
persona: "Noah Ben-David",
|
|
135
|
+
role: "specialist",
|
|
136
|
+
domain: "Reliability",
|
|
137
|
+
tools: ["read", "grep", "failure-analysis"],
|
|
138
|
+
permissionMode: "plan",
|
|
139
|
+
maxTurns: 6,
|
|
140
|
+
confidenceFloor: 0.8,
|
|
141
|
+
allowedPaths: ["."],
|
|
142
|
+
networkMode: "restricted",
|
|
143
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
144
|
+
evidenceRequirements: ["failure_modes", "rollback_plan"],
|
|
145
|
+
escalationTargets: ["release", "observability"],
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: "release",
|
|
149
|
+
persona: "Omar Singh",
|
|
150
|
+
role: "specialist",
|
|
151
|
+
domain: "Release Engineering",
|
|
152
|
+
tools: ["read", "grep", "workflow-review"],
|
|
153
|
+
permissionMode: "plan",
|
|
154
|
+
maxTurns: 6,
|
|
155
|
+
confidenceFloor: 0.8,
|
|
156
|
+
allowedPaths: ["."],
|
|
157
|
+
networkMode: "restricted",
|
|
158
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
159
|
+
evidenceRequirements: ["workflow_refs", "gate_matrix"],
|
|
160
|
+
escalationTargets: ["security", "reliability"],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: "observability",
|
|
164
|
+
persona: "Sofia Alvarez",
|
|
165
|
+
role: "specialist",
|
|
166
|
+
domain: "Observability",
|
|
167
|
+
tools: ["read", "grep", "telemetry-review"],
|
|
168
|
+
permissionMode: "plan",
|
|
169
|
+
maxTurns: 6,
|
|
170
|
+
confidenceFloor: 0.78,
|
|
171
|
+
allowedPaths: ["."],
|
|
172
|
+
networkMode: "restricted",
|
|
173
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
174
|
+
evidenceRequirements: ["signal_inventory", "gaps"],
|
|
175
|
+
escalationTargets: ["reliability", "release"],
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
id: "infrastructure",
|
|
179
|
+
persona: "Kat Hughes",
|
|
180
|
+
role: "specialist",
|
|
181
|
+
domain: "Infrastructure",
|
|
182
|
+
tools: ["read", "grep", "infra-lint"],
|
|
183
|
+
permissionMode: "plan",
|
|
184
|
+
maxTurns: 6,
|
|
185
|
+
confidenceFloor: 0.78,
|
|
186
|
+
allowedPaths: ["."],
|
|
187
|
+
networkMode: "restricted",
|
|
188
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
189
|
+
evidenceRequirements: ["infra_paths", "blast_radius"],
|
|
190
|
+
escalationTargets: ["security", "reliability"],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
id: "supply-chain",
|
|
194
|
+
persona: "Nora Kline",
|
|
195
|
+
role: "specialist",
|
|
196
|
+
domain: "Supply Chain",
|
|
197
|
+
tools: ["read", "grep", "dependency-audit"],
|
|
198
|
+
permissionMode: "plan",
|
|
199
|
+
maxTurns: 6,
|
|
200
|
+
confidenceFloor: 0.82,
|
|
201
|
+
allowedPaths: ["."],
|
|
202
|
+
networkMode: "restricted",
|
|
203
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
204
|
+
evidenceRequirements: ["dependency_refs", "version_risks"],
|
|
205
|
+
escalationTargets: ["security", "release"],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: "frontend",
|
|
209
|
+
persona: "Jules Tanaka",
|
|
210
|
+
role: "specialist",
|
|
211
|
+
domain: "Frontend",
|
|
212
|
+
tools: ["read", "grep", "ui-lint"],
|
|
213
|
+
permissionMode: "plan",
|
|
214
|
+
maxTurns: 6,
|
|
215
|
+
confidenceFloor: 0.76,
|
|
216
|
+
allowedPaths: ["."],
|
|
217
|
+
networkMode: "restricted",
|
|
218
|
+
defaultBudget: { ...DEFAULT_BUDGET },
|
|
219
|
+
evidenceRequirements: ["component_paths", "repro_steps"],
|
|
220
|
+
escalationTargets: ["testing", "architecture"],
|
|
221
|
+
},
|
|
222
|
+
]);
|
|
223
|
+
|
|
224
|
+
function normalizeString(value) {
|
|
225
|
+
return String(value || "").trim();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function normalizeAgentId(value) {
|
|
229
|
+
return normalizeString(value).toLowerCase();
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function normalizeRole(value) {
|
|
233
|
+
const normalized = normalizeString(value).toLowerCase();
|
|
234
|
+
if (normalized === "orchestrator" || normalized === "specialist") {
|
|
235
|
+
return normalized;
|
|
236
|
+
}
|
|
237
|
+
return "specialist";
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function normalizeNetworkMode(value) {
|
|
241
|
+
const normalized = normalizeString(value).toLowerCase();
|
|
242
|
+
if (normalized === "enabled" || normalized === "restricted" || normalized === "disabled") {
|
|
243
|
+
return normalized;
|
|
244
|
+
}
|
|
245
|
+
return "restricted";
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function normalizePositiveNumber(value, fallback, field) {
|
|
249
|
+
const normalized = Number(value);
|
|
250
|
+
if (Number.isFinite(normalized) && normalized > 0) {
|
|
251
|
+
return normalized;
|
|
252
|
+
}
|
|
253
|
+
if (fallback !== undefined) {
|
|
254
|
+
return Number(fallback);
|
|
255
|
+
}
|
|
256
|
+
throw new Error(`${field} must be a positive number.`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function normalizeBudget(budget = {}, fallback = DEFAULT_BUDGET) {
|
|
260
|
+
if (budget === undefined || budget === null || typeof budget !== "object" || Array.isArray(budget)) {
|
|
261
|
+
throw new Error("defaultBudget must be an object when provided.");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
maxCostUsd: normalizePositiveNumber(
|
|
266
|
+
budget.maxCostUsd,
|
|
267
|
+
fallback.maxCostUsd,
|
|
268
|
+
"defaultBudget.maxCostUsd"
|
|
269
|
+
),
|
|
270
|
+
maxOutputTokens: Math.floor(
|
|
271
|
+
normalizePositiveNumber(
|
|
272
|
+
budget.maxOutputTokens,
|
|
273
|
+
fallback.maxOutputTokens,
|
|
274
|
+
"defaultBudget.maxOutputTokens"
|
|
275
|
+
)
|
|
276
|
+
),
|
|
277
|
+
maxRuntimeMs: Math.floor(
|
|
278
|
+
normalizePositiveNumber(
|
|
279
|
+
budget.maxRuntimeMs,
|
|
280
|
+
fallback.maxRuntimeMs,
|
|
281
|
+
"defaultBudget.maxRuntimeMs"
|
|
282
|
+
)
|
|
283
|
+
),
|
|
284
|
+
maxToolCalls: Math.floor(
|
|
285
|
+
normalizePositiveNumber(
|
|
286
|
+
budget.maxToolCalls,
|
|
287
|
+
fallback.maxToolCalls,
|
|
288
|
+
"defaultBudget.maxToolCalls"
|
|
289
|
+
)
|
|
290
|
+
),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function normalizeAgentRecord(record = {}, existing = {}) {
|
|
295
|
+
const id = normalizeAgentId(record.id || existing.id);
|
|
296
|
+
const fallbackBudget = existing.defaultBudget || DEFAULT_BUDGET;
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
id,
|
|
300
|
+
persona: normalizeString(record.persona || existing.persona),
|
|
301
|
+
role: normalizeRole(record.role || existing.role),
|
|
302
|
+
domain: normalizeString(record.domain || existing.domain),
|
|
303
|
+
tools: Array.isArray(record.tools || existing.tools)
|
|
304
|
+
? (record.tools || existing.tools).map((item) => normalizeString(item)).filter(Boolean)
|
|
305
|
+
: [],
|
|
306
|
+
permissionMode: normalizeString(record.permissionMode || existing.permissionMode || "plan") || "plan",
|
|
307
|
+
maxTurns: Math.max(1, Math.floor(Number(record.maxTurns || existing.maxTurns || 1))),
|
|
308
|
+
confidenceFloor: Math.max(
|
|
309
|
+
0,
|
|
310
|
+
Math.min(1, Number(record.confidenceFloor || existing.confidenceFloor || 0.7))
|
|
311
|
+
),
|
|
312
|
+
allowedPaths: Array.isArray(record.allowedPaths || existing.allowedPaths)
|
|
313
|
+
? (record.allowedPaths || existing.allowedPaths).map((item) => normalizeString(item)).filter(Boolean)
|
|
314
|
+
: ["."],
|
|
315
|
+
networkMode: normalizeNetworkMode(record.networkMode || existing.networkMode),
|
|
316
|
+
defaultBudget: normalizeBudget(record.defaultBudget || existing.defaultBudget || {}, fallbackBudget),
|
|
317
|
+
evidenceRequirements: Array.isArray(record.evidenceRequirements || existing.evidenceRequirements)
|
|
318
|
+
? (record.evidenceRequirements || existing.evidenceRequirements)
|
|
319
|
+
.map((item) => normalizeString(item))
|
|
320
|
+
.filter(Boolean)
|
|
321
|
+
: [],
|
|
322
|
+
escalationTargets: Array.isArray(record.escalationTargets || existing.escalationTargets)
|
|
323
|
+
? (record.escalationTargets || existing.escalationTargets)
|
|
324
|
+
.map((item) => normalizeAgentId(item))
|
|
325
|
+
.filter(Boolean)
|
|
326
|
+
: [],
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function mergeRegistry(builtinAgents = [], overrideAgents = []) {
|
|
331
|
+
const byId = new Map();
|
|
332
|
+
const order = [];
|
|
333
|
+
|
|
334
|
+
for (const builtin of builtinAgents) {
|
|
335
|
+
const normalized = normalizeAgentRecord(builtin);
|
|
336
|
+
byId.set(normalized.id, normalized);
|
|
337
|
+
order.push(normalized.id);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
for (const override of overrideAgents) {
|
|
341
|
+
const id = normalizeAgentId(override.id);
|
|
342
|
+
if (!id) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (!byId.has(id)) {
|
|
346
|
+
order.push(id);
|
|
347
|
+
}
|
|
348
|
+
const existing = byId.get(id) || { id };
|
|
349
|
+
byId.set(id, normalizeAgentRecord(override, existing));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return order.map((id) => ({ ...byId.get(id) })).filter(Boolean);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function parseAgentFilter(rawValue) {
|
|
356
|
+
const normalized = normalizeString(rawValue);
|
|
357
|
+
if (!normalized) {
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
return [...new Set(normalized.split(",").map((item) => normalizeAgentId(item)).filter(Boolean))];
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export function listBuiltinSwarmAgents() {
|
|
364
|
+
return BUILTIN_SWARM_AGENTS.map((agent) => normalizeAgentRecord(agent));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export async function loadSwarmRegistry({ registryFile = "" } = {}) {
|
|
368
|
+
const builtin = listBuiltinSwarmAgents();
|
|
369
|
+
const resolvedRegistryFile = normalizeString(registryFile)
|
|
370
|
+
? path.resolve(process.cwd(), registryFile)
|
|
371
|
+
: "";
|
|
372
|
+
if (!resolvedRegistryFile) {
|
|
373
|
+
return {
|
|
374
|
+
registrySource: "builtin",
|
|
375
|
+
registryFile: "",
|
|
376
|
+
agents: builtin,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const raw = await fsp.readFile(resolvedRegistryFile, "utf-8");
|
|
381
|
+
const parsed = JSON.parse(raw);
|
|
382
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.agents)) {
|
|
383
|
+
throw new Error("Invalid swarm registry file: expected { agents: [...] }.");
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return {
|
|
387
|
+
registrySource: "custom",
|
|
388
|
+
registryFile: resolvedRegistryFile,
|
|
389
|
+
agents: mergeRegistry(builtin, parsed.agents),
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export function selectSwarmAgents(agents = [], requested = "") {
|
|
394
|
+
const requestedIds = parseAgentFilter(requested);
|
|
395
|
+
if (requestedIds.length === 0) {
|
|
396
|
+
return {
|
|
397
|
+
selected: [...agents],
|
|
398
|
+
requestedIds,
|
|
399
|
+
missing: [],
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const byId = new Map(agents.map((agent) => [agent.id, agent]));
|
|
404
|
+
const selected = [];
|
|
405
|
+
const missing = [];
|
|
406
|
+
for (const id of requestedIds) {
|
|
407
|
+
const agent = byId.get(id);
|
|
408
|
+
if (!agent) {
|
|
409
|
+
missing.push(id);
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
selected.push(agent);
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
selected,
|
|
416
|
+
requestedIds,
|
|
417
|
+
missing,
|
|
418
|
+
};
|
|
419
|
+
}
|