agent-enderun 0.8.7 → 0.9.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/{ENDERUN.md → .enderun/ENDERUN.md} +5 -3
- package/.enderun/PROJECT_MEMORY.md +12 -53
- package/.enderun/STATUS.md +7 -8
- package/.enderun/agents/agent_army_schema.json +28 -6
- package/.enderun/agents/analyst.md +9 -18
- package/.enderun/agents/backend.md +22 -52
- package/.enderun/agents/devops.md +9 -19
- package/.enderun/agents/explorer.md +7 -16
- package/.enderun/agents/frontend.md +82 -84
- package/.enderun/agents/git.md +7 -16
- package/.enderun/agents/manager.md +34 -40
- package/.enderun/agents/mobile.md +7 -16
- package/.enderun/agents/native.md +7 -16
- package/.enderun/agents/orchestrator.md +16 -25
- package/.enderun/agents/qa.md +12 -24
- package/.enderun/agents/schema/agent-lifecycle-schema.json +29 -8
- package/.enderun/agents/security.md +9 -18
- package/.enderun/config.json +1 -1
- package/.enderun/knowledge/SHIM_TEMPLATE.md +25 -0
- package/.enderun/knowledge/eslint-standards.md +63 -0
- package/.enderun/knowledge/hermes_protocol.md +1 -1
- package/.enderun/knowledge/token_economy_and_memory.md +129 -0
- package/.enderun/mcp_config.json +9 -0
- package/.enderun/memory-graph/agent-contexts/analyst.json +1 -1
- package/.enderun/memory-graph/agent-contexts/backend.json +1 -1
- package/.enderun/memory-graph/agent-contexts/devops.json +1 -1
- package/.enderun/memory-graph/agent-contexts/explorer.json +1 -1
- package/.enderun/memory-graph/agent-contexts/frontend.json +1 -1
- package/.enderun/memory-graph/agent-contexts/git.json +1 -1
- package/.enderun/memory-graph/agent-contexts/manager.json +1 -1
- package/.enderun/memory-graph/agent-contexts/mobile.json +1 -1
- package/.enderun/memory-graph/agent-contexts/native.json +1 -1
- package/.enderun/memory-graph/agent-contexts/orchestrator.json +1 -1
- package/.enderun/memory-graph/agent-contexts/qa.json +1 -1
- package/.enderun/memory-graph/agent-contexts/security.json +1 -1
- package/.enderun/memory-graph/graph.json +123 -16
- package/.enderun/memory-graph/shared-facts.json +26 -32
- package/README.md +93 -295
- package/agent.md +25 -0
- package/bin/cli.js +9 -9
- package/bin/update-contract.js +34 -37
- package/bin/validate-agent-army.js +38 -13
- package/claude.md +14 -8
- package/docs/README.md +35 -16
- package/docs/roadmap.md +1 -1
- package/docs/tech-stack.md +30 -0
- package/eslint.config.js +68 -0
- package/framework-mcp/dist/index.js +184 -24
- package/framework-mcp/package.json +6 -33
- package/framework-mcp/tsconfig.json +3 -6
- package/gemini.md +12 -6
- package/grok.md +25 -0
- package/mcp.json +2 -2
- package/package.json +12 -6
- package/panda.config.ts +86 -86
- package/tsconfig.json +9 -0
- package/.enderun/claude.md +0 -19
- package/.enderun/cursor.md +0 -19
- package/.enderun/gemini.md +0 -19
- package/.enderun/logs/analyst.json +0 -1
- package/.enderun/logs/backend.json +0 -1
- package/.enderun/logs/devops.json +0 -1
- package/.enderun/logs/explorer.json +0 -1
- package/.enderun/logs/frontend.json +0 -1
- package/.enderun/logs/git.json +0 -1
- package/.enderun/logs/manager.json +0 -1
- package/.enderun/logs/mobile.json +0 -1
- package/.enderun/logs/native.json +0 -1
- package/.enderun/logs/orchestrator.json +0 -1
- package/.enderun/logs/qa.json +0 -1
- package/.enderun/logs/security.json +0 -1
- package/.env.example +0 -10
- package/cursor.md +0 -19
- package/framework-mcp/README.md +0 -55
- package/framework-mcp/dist/schemas.js +0 -118
- package/framework-mcp/dist/tools/codebase.js +0 -294
- package/framework-mcp/dist/tools/contract.js +0 -197
- package/framework-mcp/dist/tools/framework.js +0 -196
- package/framework-mcp/dist/tools/git.js +0 -51
- package/framework-mcp/dist/tools/governance.js +0 -696
- package/framework-mcp/dist/tools/index.js +0 -47
- package/framework-mcp/dist/tools/knowledge.js +0 -133
- package/framework-mcp/dist/tools/memory.js +0 -200
- package/framework-mcp/dist/tools/messages.js +0 -193
- package/framework-mcp/dist/tools/monitoring.js +0 -294
- package/framework-mcp/dist/tools/orchestration.js +0 -368
- package/framework-mcp/dist/tools/pipeline.js +0 -267
- package/framework-mcp/dist/tools/security.js +0 -137
- package/framework-mcp/dist/utils.js +0 -121
- package/framework-mcp/src/index.ts +0 -49
- package/framework-mcp/src/schemas.ts +0 -106
- package/framework-mcp/src/tools/codebase.ts +0 -284
- package/framework-mcp/src/tools/contract.ts +0 -221
- package/framework-mcp/src/tools/framework.ts +0 -192
- package/framework-mcp/src/tools/git.ts +0 -42
- package/framework-mcp/src/tools/governance.ts +0 -891
- package/framework-mcp/src/tools/index.ts +0 -50
- package/framework-mcp/src/tools/knowledge.ts +0 -141
- package/framework-mcp/src/tools/memory.ts +0 -207
- package/framework-mcp/src/tools/messages.ts +0 -213
- package/framework-mcp/src/tools/monitoring.ts +0 -351
- package/framework-mcp/src/tools/orchestration.ts +0 -440
- package/framework-mcp/src/tools/pipeline.ts +0 -353
- package/framework-mcp/src/tools/security.ts +0 -143
- package/framework-mcp/src/utils.ts +0 -130
- package/src/cli/index.ts +0 -2188
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { getFrameworkDir } from "../utils.js";
|
|
4
|
-
// ─── Tool Definitions ─────────────────────────────────────────────────────────
|
|
5
|
-
export const monitoringTools = [
|
|
6
|
-
{
|
|
7
|
-
name: "get_army_health_dashboard",
|
|
8
|
-
description: "Returns a comprehensive health dashboard for the entire Agent Enderun Army. Includes agent states, active tasks, health scores, queue depth, and recent blockages. Single call for full army situational awareness.",
|
|
9
|
-
inputSchema: {
|
|
10
|
-
type: "object",
|
|
11
|
-
properties: {
|
|
12
|
-
projectRoot: { type: "string", description: "Root directory of the project" },
|
|
13
|
-
},
|
|
14
|
-
required: [],
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: "calculate_agent_performance_score",
|
|
19
|
-
description: "Calculates a dynamic performance score for a specific agent based on their last N actions from the audit log. Returns success rate, average execution time, and blockage frequency.",
|
|
20
|
-
inputSchema: {
|
|
21
|
-
type: "object",
|
|
22
|
-
properties: {
|
|
23
|
-
agentName: { type: "string", description: "Agent identifier (e.g. @backend)" },
|
|
24
|
-
lastN: { type: "number", description: "Number of recent actions to analyze", default: 20 },
|
|
25
|
-
},
|
|
26
|
-
required: ["agentName"],
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: "detect_bottleneck_agents",
|
|
31
|
-
description: "Scans all agent logs and STATUS.md to identify agents that are causing delays — either by being BLOCKED, exceeding execution timeout, or having a high blockage frequency. Returns a prioritized list of bottlenecks.",
|
|
32
|
-
inputSchema: {
|
|
33
|
-
type: "object",
|
|
34
|
-
properties: {
|
|
35
|
-
thresholdMinutes: {
|
|
36
|
-
type: "number",
|
|
37
|
-
description: "Minutes after which an EXECUTING agent is considered a bottleneck",
|
|
38
|
-
default: 30,
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
required: [],
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: "generate_war_room_report",
|
|
46
|
-
description: "Generates a crisis-mode summary report for @manager. Includes: all BLOCKED/ERROR agents, unresolved dependencies, critical path analysis, and recommended immediate actions. Designed for high-urgency situations.",
|
|
47
|
-
inputSchema: {
|
|
48
|
-
type: "object",
|
|
49
|
-
properties: {
|
|
50
|
-
traceId: { type: "string", description: "Active Trace ID for the crisis" },
|
|
51
|
-
crisisDescription: { type: "string", description: "Brief description of the crisis or incident" },
|
|
52
|
-
},
|
|
53
|
-
required: ["traceId", "crisisDescription"],
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
];
|
|
57
|
-
// ─── Handlers ─────────────────────────────────────────────────────────────────
|
|
58
|
-
export const monitoringHandlers = {
|
|
59
|
-
async get_army_health_dashboard(_args, projectRoot) {
|
|
60
|
-
const results = {
|
|
61
|
-
generatedAt: new Date().toISOString(),
|
|
62
|
-
agents: [],
|
|
63
|
-
queueDepth: { pending: 0, processing: 0, completed: 0, failed: 0 },
|
|
64
|
-
recentBlockages: [],
|
|
65
|
-
recentBroadcasts: [],
|
|
66
|
-
overallHealth: "GREEN",
|
|
67
|
-
};
|
|
68
|
-
// Read STATUS.md
|
|
69
|
-
const frameworkDir = getFrameworkDir(projectRoot);
|
|
70
|
-
const statusPath = path.join(projectRoot, frameworkDir, "STATUS.md");
|
|
71
|
-
try {
|
|
72
|
-
const statusContent = await fs.readFile(statusPath, "utf-8");
|
|
73
|
-
const lines = statusContent
|
|
74
|
-
.split("\n")
|
|
75
|
-
.filter((l) => l.includes("|") && !l.includes("---") && !l.includes("Agent"));
|
|
76
|
-
results.agents = lines
|
|
77
|
-
.map((line) => {
|
|
78
|
-
const cells = line.split("|").map((c) => c.trim()).filter(Boolean);
|
|
79
|
-
return cells.length >= 4
|
|
80
|
-
? {
|
|
81
|
-
agent: cells[0],
|
|
82
|
-
state: cells[1],
|
|
83
|
-
currentTask: cells[2],
|
|
84
|
-
blockedBy: cells[3],
|
|
85
|
-
healthScore: cells[4] ?? "—",
|
|
86
|
-
lastAction: cells[5] ?? "—",
|
|
87
|
-
}
|
|
88
|
-
: null;
|
|
89
|
-
})
|
|
90
|
-
.filter(Boolean);
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
results.agents = [{ error: "STATUS.md not found or unreadable" }];
|
|
94
|
-
}
|
|
95
|
-
// Read queue depths
|
|
96
|
-
const queueBase = path.join(projectRoot, ".enderun", "queue");
|
|
97
|
-
for (const subdir of ["pending", "processing", "completed", "failed"]) {
|
|
98
|
-
try {
|
|
99
|
-
const files = await fs.readdir(path.join(queueBase, subdir));
|
|
100
|
-
results.queueDepth[subdir] = files.filter((f) => f.endsWith(".json")).length;
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
results.queueDepth[subdir] = 0;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// Read orchestrator log for recent blockages and broadcasts
|
|
107
|
-
const logPath = path.join(projectRoot, ".enderun", "logs", "orchestrator.json");
|
|
108
|
-
try {
|
|
109
|
-
const logContent = await fs.readFile(logPath, "utf-8");
|
|
110
|
-
const log = JSON.parse(logContent);
|
|
111
|
-
results.recentBlockages = (log.blockages ?? []).slice(-5);
|
|
112
|
-
results.recentBroadcasts = (log.broadcasts ?? []).slice(-3);
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
// No log yet
|
|
116
|
-
}
|
|
117
|
-
// Calculate overall health
|
|
118
|
-
const blockedCount = results.agents.filter((a) => a?.state?.includes("BLOCKED") || a?.state?.includes("ERROR")).length;
|
|
119
|
-
if (blockedCount >= 3)
|
|
120
|
-
results.overallHealth = "RED";
|
|
121
|
-
else if (blockedCount >= 1)
|
|
122
|
-
results.overallHealth = "YELLOW";
|
|
123
|
-
else
|
|
124
|
-
results.overallHealth = "GREEN";
|
|
125
|
-
return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }] };
|
|
126
|
-
},
|
|
127
|
-
async calculate_agent_performance_score(args, projectRoot) {
|
|
128
|
-
const { agentName, lastN } = args;
|
|
129
|
-
const n = lastN ?? 20;
|
|
130
|
-
const logName = agentName.replace("@", "") + ".json";
|
|
131
|
-
const logPath = path.join(projectRoot, ".enderun", "logs", logName);
|
|
132
|
-
try {
|
|
133
|
-
const content = await fs.readFile(logPath, "utf-8");
|
|
134
|
-
const log = JSON.parse(content);
|
|
135
|
-
const actions = (log.actions ?? []).slice(-n);
|
|
136
|
-
const total = actions.length;
|
|
137
|
-
const successful = actions.filter((a) => a.status === "SUCCESS" || a.status === "DONE").length;
|
|
138
|
-
const successRate = total > 0 ? ((successful / total) * 100).toFixed(1) + "%" : "N/A";
|
|
139
|
-
const avgDuration = total > 0
|
|
140
|
-
? (actions.reduce((sum, a) => sum + (a.durationMs ?? 0), 0) / total).toFixed(0) + "ms"
|
|
141
|
-
: "N/A";
|
|
142
|
-
return {
|
|
143
|
-
content: [
|
|
144
|
-
{
|
|
145
|
-
type: "text",
|
|
146
|
-
text: JSON.stringify({
|
|
147
|
-
agent: agentName,
|
|
148
|
-
analyzedActions: total,
|
|
149
|
-
successRate,
|
|
150
|
-
averageExecutionTime: avgDuration,
|
|
151
|
-
generatedAt: new Date().toISOString(),
|
|
152
|
-
}, null, 2),
|
|
153
|
-
},
|
|
154
|
-
],
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
return {
|
|
159
|
-
content: [
|
|
160
|
-
{
|
|
161
|
-
type: "text",
|
|
162
|
-
text: JSON.stringify({
|
|
163
|
-
agent: agentName,
|
|
164
|
-
error: "No log found or log is empty",
|
|
165
|
-
analyzedActions: 0,
|
|
166
|
-
}),
|
|
167
|
-
},
|
|
168
|
-
],
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
async detect_bottleneck_agents(args, projectRoot) {
|
|
173
|
-
const { thresholdMinutes } = args;
|
|
174
|
-
const threshold = thresholdMinutes ?? 30;
|
|
175
|
-
const statusPath = path.join(projectRoot, ".enderun", "STATUS.md");
|
|
176
|
-
const bottlenecks = [];
|
|
177
|
-
try {
|
|
178
|
-
const content = await fs.readFile(statusPath, "utf-8");
|
|
179
|
-
const lines = content
|
|
180
|
-
.split("\n")
|
|
181
|
-
.filter((l) => l.includes("|") && !l.includes("---") && !l.includes("Agent"));
|
|
182
|
-
for (const line of lines) {
|
|
183
|
-
const cells = line.split("|").map((c) => c.trim()).filter(Boolean);
|
|
184
|
-
if (cells.length < 2)
|
|
185
|
-
continue;
|
|
186
|
-
const [agent, state] = cells;
|
|
187
|
-
if (state.includes("BLOCKED")) {
|
|
188
|
-
bottlenecks.push({ agent, state, reason: "Agent is in BLOCKED state", severity: "CRITICAL" });
|
|
189
|
-
}
|
|
190
|
-
else if (state.includes("ERROR")) {
|
|
191
|
-
bottlenecks.push({ agent, state, reason: "Agent is in ERROR state", severity: "CRITICAL" });
|
|
192
|
-
}
|
|
193
|
-
else if (state.includes("EXECUTING")) {
|
|
194
|
-
bottlenecks.push({
|
|
195
|
-
agent,
|
|
196
|
-
state,
|
|
197
|
-
reason: `Agent has been EXECUTING for more than ${threshold} minutes (verify manually)`,
|
|
198
|
-
severity: "HIGH",
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
catch {
|
|
204
|
-
return {
|
|
205
|
-
content: [
|
|
206
|
-
{
|
|
207
|
-
type: "text",
|
|
208
|
-
text: JSON.stringify({ error: "Could not read STATUS.md" }),
|
|
209
|
-
},
|
|
210
|
-
],
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
content: [
|
|
215
|
-
{
|
|
216
|
-
type: "text",
|
|
217
|
-
text: JSON.stringify({
|
|
218
|
-
bottlenecks,
|
|
219
|
-
total: bottlenecks.length,
|
|
220
|
-
analysisThresholdMinutes: threshold,
|
|
221
|
-
generatedAt: new Date().toISOString(),
|
|
222
|
-
}, null, 2),
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
};
|
|
226
|
-
},
|
|
227
|
-
async generate_war_room_report(args, projectRoot) {
|
|
228
|
-
const { traceId, crisisDescription } = args;
|
|
229
|
-
// Gather all data for the war room report
|
|
230
|
-
const report = {
|
|
231
|
-
warRoomReport: true,
|
|
232
|
-
traceId,
|
|
233
|
-
crisisDescription,
|
|
234
|
-
generatedAt: new Date().toISOString(),
|
|
235
|
-
agentStatuses: [],
|
|
236
|
-
queueSnapshot: {},
|
|
237
|
-
recentBlockages: [],
|
|
238
|
-
immediateActions: [],
|
|
239
|
-
};
|
|
240
|
-
// Agent statuses
|
|
241
|
-
const frameworkDir = getFrameworkDir(projectRoot);
|
|
242
|
-
const statusPath = path.join(projectRoot, frameworkDir, "STATUS.md");
|
|
243
|
-
try {
|
|
244
|
-
const content = await fs.readFile(statusPath, "utf-8");
|
|
245
|
-
const lines = content
|
|
246
|
-
.split("\n")
|
|
247
|
-
.filter((l) => l.includes("|") && !l.includes("---") && !l.includes("Agent"));
|
|
248
|
-
report.agentStatuses = lines
|
|
249
|
-
.map((l) => {
|
|
250
|
-
const cells = l.split("|").map((c) => c.trim()).filter(Boolean);
|
|
251
|
-
return cells.length >= 2 ? { agent: cells[0], state: cells[1] } : null;
|
|
252
|
-
})
|
|
253
|
-
.filter(Boolean);
|
|
254
|
-
}
|
|
255
|
-
catch {
|
|
256
|
-
report.agentStatuses = [];
|
|
257
|
-
}
|
|
258
|
-
// Queue snapshot
|
|
259
|
-
const queueBase = path.join(projectRoot, ".enderun", "queue");
|
|
260
|
-
const snapshot = {};
|
|
261
|
-
for (const dir of ["pending", "processing", "completed", "failed"]) {
|
|
262
|
-
try {
|
|
263
|
-
const files = await fs.readdir(path.join(queueBase, dir));
|
|
264
|
-
snapshot[dir] = files.length;
|
|
265
|
-
}
|
|
266
|
-
catch {
|
|
267
|
-
snapshot[dir] = 0;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
report.queueSnapshot = snapshot;
|
|
271
|
-
// Recent blockages
|
|
272
|
-
const logPath = path.join(projectRoot, ".enderun", "logs", "orchestrator.json");
|
|
273
|
-
try {
|
|
274
|
-
const logContent = await fs.readFile(logPath, "utf-8");
|
|
275
|
-
const log = JSON.parse(logContent);
|
|
276
|
-
report.recentBlockages = (log.blockages ?? []).slice(-10);
|
|
277
|
-
}
|
|
278
|
-
catch {
|
|
279
|
-
report.recentBlockages = [];
|
|
280
|
-
}
|
|
281
|
-
// Generate recommended immediate actions
|
|
282
|
-
const blockedAgents = report.agentStatuses.filter((a) => a.state.includes("BLOCKED") || a.state.includes("ERROR"));
|
|
283
|
-
if (blockedAgents.length > 0) {
|
|
284
|
-
report.immediateActions.push(`IMMEDIATE: Resolve ${blockedAgents.map((a) => a.agent).join(", ")} blockages — these are on the critical path`);
|
|
285
|
-
}
|
|
286
|
-
if ((snapshot["pending"] ?? 0) > 5) {
|
|
287
|
-
report.immediateActions.push("HIGH: Queue has excessive pending tasks — consider deploying additional agents");
|
|
288
|
-
}
|
|
289
|
-
if (report.immediateActions.length === 0) {
|
|
290
|
-
report.immediateActions.push("No critical immediate actions required — monitor agent states");
|
|
291
|
-
}
|
|
292
|
-
return { content: [{ type: "text", text: JSON.stringify(report, null, 2) }] };
|
|
293
|
-
},
|
|
294
|
-
};
|
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
// ─── Tool Definitions ─────────────────────────────────────────────────────────
|
|
4
|
-
export const orchestrationTools = [
|
|
5
|
-
{
|
|
6
|
-
name: "create_task_dag",
|
|
7
|
-
description: "Creates a Directed Acyclic Graph (DAG) of tasks with dependencies. Used by @orchestrator to plan parallel execution. Returns both a JSON structure and a Mermaid diagram for visualization.",
|
|
8
|
-
inputSchema: {
|
|
9
|
-
type: "object",
|
|
10
|
-
properties: {
|
|
11
|
-
traceId: {
|
|
12
|
-
type: "string",
|
|
13
|
-
description: "Trace ID inherited from @manager briefing. Required.",
|
|
14
|
-
},
|
|
15
|
-
tasks: {
|
|
16
|
-
type: "array",
|
|
17
|
-
description: "Array of task definitions to build the DAG from.",
|
|
18
|
-
items: {
|
|
19
|
-
type: "object",
|
|
20
|
-
required: ["id", "agent", "briefing"],
|
|
21
|
-
properties: {
|
|
22
|
-
id: { type: "string", description: "Unique task ID (e.g. T001)" },
|
|
23
|
-
agent: { type: "string", description: "Assigned agent (e.g. @backend)" },
|
|
24
|
-
briefing: { type: "string", description: "Task description" },
|
|
25
|
-
dependsOn: {
|
|
26
|
-
type: "array",
|
|
27
|
-
items: { type: "string" },
|
|
28
|
-
description: "Task IDs that must complete before this task starts",
|
|
29
|
-
},
|
|
30
|
-
priority: {
|
|
31
|
-
type: "string",
|
|
32
|
-
enum: ["CRITICAL", "HIGH", "MEDIUM", "LOW"],
|
|
33
|
-
default: "MEDIUM",
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
required: ["traceId", "tasks"],
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: "assign_agent_to_task",
|
|
44
|
-
description: "Assigns the most capable available agent to a task based on domain and capability score. Checks STATUS.md for agent availability before assigning.",
|
|
45
|
-
inputSchema: {
|
|
46
|
-
type: "object",
|
|
47
|
-
properties: {
|
|
48
|
-
traceId: { type: "string", description: "Active Trace ID" },
|
|
49
|
-
taskId: { type: "string", description: "Task ID to assign" },
|
|
50
|
-
domain: {
|
|
51
|
-
type: "string",
|
|
52
|
-
enum: ["backend", "frontend", "security", "qa", "devops", "mobile", "native", "analysis", "git", "exploration"],
|
|
53
|
-
description: "Domain of the task — used to filter eligible agents",
|
|
54
|
-
},
|
|
55
|
-
preferredAgent: {
|
|
56
|
-
type: "string",
|
|
57
|
-
description: "Optional preferred agent. If not available, falls back to capability-based selection.",
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
required: ["traceId", "taskId", "domain"],
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
name: "get_agent_workload",
|
|
65
|
-
description: "Returns the current workload for all agents: active task count, state, current task description, and health score. Used by @orchestrator to make load-aware assignment decisions.",
|
|
66
|
-
inputSchema: {
|
|
67
|
-
type: "object",
|
|
68
|
-
properties: {
|
|
69
|
-
projectRoot: { type: "string", description: "Root directory of the project." },
|
|
70
|
-
},
|
|
71
|
-
required: [],
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
name: "resolve_agent_blockage",
|
|
76
|
-
description: "Handles a BLOCKED agent by documenting the blockage, escalating to @manager, and optionally reassigning the task to another eligible agent.",
|
|
77
|
-
inputSchema: {
|
|
78
|
-
type: "object",
|
|
79
|
-
properties: {
|
|
80
|
-
blockedAgent: { type: "string", description: "The agent identifier that is BLOCKED, e.g. @frontend" },
|
|
81
|
-
traceId: { type: "string", description: "Active Trace ID" },
|
|
82
|
-
blockReason: { type: "string", description: "Mandatory description of why the agent is blocked" },
|
|
83
|
-
reassign: {
|
|
84
|
-
type: "boolean",
|
|
85
|
-
description: "If true, attempt to find and assign an alternative agent",
|
|
86
|
-
default: false,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
required: ["blockedAgent", "traceId", "blockReason"],
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: "broadcast_army_directive",
|
|
94
|
-
description: "Broadcasts a directive message to all agents simultaneously via the Hermes messaging system. Used for war-room mode, policy changes, or global state transitions.",
|
|
95
|
-
inputSchema: {
|
|
96
|
-
type: "object",
|
|
97
|
-
properties: {
|
|
98
|
-
traceId: { type: "string", description: "Active Trace ID" },
|
|
99
|
-
directiveType: {
|
|
100
|
-
type: "string",
|
|
101
|
-
enum: [
|
|
102
|
-
"WAR_ROOM_ACTIVATE",
|
|
103
|
-
"WAR_ROOM_DEACTIVATE",
|
|
104
|
-
"CONTRACT_CHANGED",
|
|
105
|
-
"PHASE_ROLLBACK",
|
|
106
|
-
"POLICY_UPDATE",
|
|
107
|
-
"ARMY_PAUSE",
|
|
108
|
-
"ARMY_RESUME",
|
|
109
|
-
],
|
|
110
|
-
description: "Type of directive being broadcast",
|
|
111
|
-
},
|
|
112
|
-
message: { type: "string", description: "Human-readable directive message" },
|
|
113
|
-
urgency: {
|
|
114
|
-
type: "string",
|
|
115
|
-
enum: ["IMMEDIATE", "HIGH", "NORMAL"],
|
|
116
|
-
default: "NORMAL",
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
required: ["traceId", "directiveType", "message"],
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
];
|
|
123
|
-
// ─── Handlers ─────────────────────────────────────────────────────────────────
|
|
124
|
-
export const orchestrationHandlers = {
|
|
125
|
-
async create_task_dag(args, projectRoot) {
|
|
126
|
-
const { traceId, tasks } = args;
|
|
127
|
-
// Build adjacency structure
|
|
128
|
-
const dagNodes = tasks.map((t) => ({
|
|
129
|
-
id: t.id,
|
|
130
|
-
agent: t.agent,
|
|
131
|
-
briefing: t.briefing,
|
|
132
|
-
status: "PENDING",
|
|
133
|
-
priority: t.priority ?? "MEDIUM",
|
|
134
|
-
dependsOn: t.dependsOn ?? [],
|
|
135
|
-
}));
|
|
136
|
-
// Topological sort to find execution order
|
|
137
|
-
const executionWaves = [];
|
|
138
|
-
const resolved = new Set();
|
|
139
|
-
const remaining = [...dagNodes];
|
|
140
|
-
while (remaining.length > 0) {
|
|
141
|
-
const wave = remaining.filter((n) => n.dependsOn.every((dep) => resolved.has(dep)));
|
|
142
|
-
if (wave.length === 0) {
|
|
143
|
-
return {
|
|
144
|
-
content: [
|
|
145
|
-
{
|
|
146
|
-
type: "text",
|
|
147
|
-
text: JSON.stringify({
|
|
148
|
-
error: "CIRCULAR_DEPENDENCY",
|
|
149
|
-
message: "Circular dependency detected in task DAG. Check dependsOn fields.",
|
|
150
|
-
}),
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
executionWaves.push(wave.map((n) => n.id));
|
|
156
|
-
wave.forEach((n) => {
|
|
157
|
-
resolved.add(n.id);
|
|
158
|
-
remaining.splice(remaining.indexOf(n), 1);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
// Generate Mermaid diagram
|
|
162
|
-
const mermaidLines = ["graph TD"];
|
|
163
|
-
for (const node of dagNodes) {
|
|
164
|
-
const label = `${node.id}["${node.agent}: ${node.briefing.slice(0, 40)}..."]`;
|
|
165
|
-
mermaidLines.push(` ${node.id}${label}`);
|
|
166
|
-
}
|
|
167
|
-
for (const node of dagNodes) {
|
|
168
|
-
for (const dep of node.dependsOn) {
|
|
169
|
-
mermaidLines.push(` ${dep} --> ${node.id}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
const dag = {
|
|
173
|
-
traceId,
|
|
174
|
-
createdAt: new Date().toISOString(),
|
|
175
|
-
nodes: dagNodes,
|
|
176
|
-
executionWaves,
|
|
177
|
-
mermaid: mermaidLines.join("\n"),
|
|
178
|
-
parallelOpportunities: executionWaves.filter((w) => w.length > 1).length,
|
|
179
|
-
};
|
|
180
|
-
// Persist to queue
|
|
181
|
-
const queueDir = path.join(projectRoot, ".enderun", "queue", "pending");
|
|
182
|
-
await fs.mkdir(queueDir, { recursive: true });
|
|
183
|
-
await fs.writeFile(path.join(queueDir, `${traceId}-dag.json`), JSON.stringify(dag, null, 2), "utf-8");
|
|
184
|
-
return { content: [{ type: "text", text: JSON.stringify(dag, null, 2) }] };
|
|
185
|
-
},
|
|
186
|
-
async assign_agent_to_task(args, projectRoot) {
|
|
187
|
-
const { traceId, taskId, domain, preferredAgent } = args;
|
|
188
|
-
// Try to load capability roster from shared-facts.json (dynamic — fixes KRITIK-3)
|
|
189
|
-
let agentCapabilityRoster = [];
|
|
190
|
-
try {
|
|
191
|
-
const sharedFactsPath = path.join(projectRoot, ".enderun", "memory-graph", "shared-facts.json");
|
|
192
|
-
const content = await fs.readFile(sharedFactsPath, "utf-8");
|
|
193
|
-
const facts = JSON.parse(content);
|
|
194
|
-
agentCapabilityRoster = facts.agentCapabilityRoster ?? [];
|
|
195
|
-
}
|
|
196
|
-
catch {
|
|
197
|
-
// Fallback to hardcoded map if shared-facts not available
|
|
198
|
-
}
|
|
199
|
-
// Build domain → agents map from shared-facts roster
|
|
200
|
-
// Exclude @manager — @manager does NOT execute specialist tasks
|
|
201
|
-
const domainMap = {};
|
|
202
|
-
for (const entry of agentCapabilityRoster) {
|
|
203
|
-
if (entry.agent === "@manager" || entry.agent === "@orchestrator")
|
|
204
|
-
continue;
|
|
205
|
-
const d = entry.primaryDomain;
|
|
206
|
-
if (!domainMap[d])
|
|
207
|
-
domainMap[d] = [];
|
|
208
|
-
domainMap[d].push({ agent: entry.agent, capability: entry.capability });
|
|
209
|
-
}
|
|
210
|
-
// Hardcoded fallback (used only if shared-facts unavailable)
|
|
211
|
-
const fallbackDomainMap = {
|
|
212
|
-
backend: [{ agent: "@backend", capability: 9.2 }],
|
|
213
|
-
frontend: [{ agent: "@frontend", capability: 9.0 }],
|
|
214
|
-
security: [{ agent: "@security", capability: 9.3 }],
|
|
215
|
-
qa: [{ agent: "@qa", capability: 9.1 }],
|
|
216
|
-
devops: [{ agent: "@devops", capability: 9.0 }],
|
|
217
|
-
mobile: [{ agent: "@mobile", capability: 8.8 }],
|
|
218
|
-
native: [{ agent: "@native", capability: 8.9 }],
|
|
219
|
-
analysis: [{ agent: "@analyst", capability: 9.6 }],
|
|
220
|
-
git: [{ agent: "@git", capability: 9.1 }],
|
|
221
|
-
exploration: [{ agent: "@explorer", capability: 9.4 }],
|
|
222
|
-
};
|
|
223
|
-
const effectiveMap = Object.keys(domainMap).length > 0 ? domainMap : fallbackDomainMap;
|
|
224
|
-
const candidates = effectiveMap[domain] ?? [];
|
|
225
|
-
let assigned = [...candidates].sort((a, b) => b.capability - a.capability)[0];
|
|
226
|
-
if (preferredAgent && preferredAgent !== "@manager" && preferredAgent !== "@orchestrator") {
|
|
227
|
-
const preferred = candidates.find((c) => c.agent === preferredAgent);
|
|
228
|
-
if (preferred)
|
|
229
|
-
assigned = preferred;
|
|
230
|
-
}
|
|
231
|
-
if (!assigned) {
|
|
232
|
-
return {
|
|
233
|
-
content: [
|
|
234
|
-
{
|
|
235
|
-
type: "text",
|
|
236
|
-
text: JSON.stringify({ error: "NO_ELIGIBLE_AGENT", domain, taskId,
|
|
237
|
-
note: "@manager and @orchestrator are excluded from task assignment" }),
|
|
238
|
-
},
|
|
239
|
-
],
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
const assignment = {
|
|
243
|
-
traceId,
|
|
244
|
-
taskId,
|
|
245
|
-
assignedAgent: assigned.agent,
|
|
246
|
-
capabilityScore: assigned.capability,
|
|
247
|
-
assignedAt: new Date().toISOString(),
|
|
248
|
-
domain,
|
|
249
|
-
sourceMap: Object.keys(domainMap).length > 0 ? "shared-facts" : "fallback",
|
|
250
|
-
};
|
|
251
|
-
// Write assignment log
|
|
252
|
-
const logPath = path.join(projectRoot, ".enderun", "logs", "orchestrator.json");
|
|
253
|
-
let log = { assignments: [] };
|
|
254
|
-
try {
|
|
255
|
-
const existing = await fs.readFile(logPath, "utf-8");
|
|
256
|
-
log = JSON.parse(existing);
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
// File doesn't exist yet — start fresh
|
|
260
|
-
}
|
|
261
|
-
log.assignments.push(assignment);
|
|
262
|
-
await fs.mkdir(path.dirname(logPath), { recursive: true });
|
|
263
|
-
await fs.writeFile(logPath, JSON.stringify(log, null, 2), "utf-8");
|
|
264
|
-
return { content: [{ type: "text", text: JSON.stringify(assignment, null, 2) }] };
|
|
265
|
-
},
|
|
266
|
-
async get_agent_workload(_args, projectRoot) {
|
|
267
|
-
const statusPath = path.join(projectRoot, ".enderun", "STATUS.md");
|
|
268
|
-
let statusContent;
|
|
269
|
-
try {
|
|
270
|
-
statusContent = await fs.readFile(statusPath, "utf-8");
|
|
271
|
-
}
|
|
272
|
-
catch {
|
|
273
|
-
statusContent = "";
|
|
274
|
-
}
|
|
275
|
-
// Parse the markdown table
|
|
276
|
-
const lines = statusContent.length > 0
|
|
277
|
-
? statusContent.split("\n").filter((l) => l.includes("|") && !l.includes("---"))
|
|
278
|
-
: [];
|
|
279
|
-
const agents = lines.length > 1
|
|
280
|
-
? lines
|
|
281
|
-
.slice(1) // skip header
|
|
282
|
-
.map((line) => {
|
|
283
|
-
const cells = line.split("|").map((c) => c.trim()).filter(Boolean);
|
|
284
|
-
return cells.length >= 4
|
|
285
|
-
? { agent: cells[0], state: cells[1], currentTask: cells[2], healthScore: cells[4] }
|
|
286
|
-
: null;
|
|
287
|
-
})
|
|
288
|
-
.filter(Boolean)
|
|
289
|
-
: [];
|
|
290
|
-
return { content: [{ type: "text", text: JSON.stringify({ agents, generatedAt: new Date().toISOString() }, null, 2) }] };
|
|
291
|
-
},
|
|
292
|
-
async resolve_agent_blockage(args, projectRoot) {
|
|
293
|
-
const { blockedAgent, traceId, blockReason, reassign } = args;
|
|
294
|
-
const resolution = {
|
|
295
|
-
traceId,
|
|
296
|
-
blockedAgent,
|
|
297
|
-
blockReason,
|
|
298
|
-
detectedAt: new Date().toISOString(),
|
|
299
|
-
escalatedToManager: true,
|
|
300
|
-
reassignAttempted: reassign ?? false,
|
|
301
|
-
status: "ESCALATED_TO_MANAGER",
|
|
302
|
-
};
|
|
303
|
-
// Log blockage
|
|
304
|
-
const logPath = path.join(projectRoot, ".enderun", "logs", "orchestrator.json");
|
|
305
|
-
let log = { assignments: [], blockages: [] };
|
|
306
|
-
try {
|
|
307
|
-
const existing = await fs.readFile(logPath, "utf-8");
|
|
308
|
-
log = JSON.parse(existing);
|
|
309
|
-
if (!log.blockages)
|
|
310
|
-
log.blockages = [];
|
|
311
|
-
}
|
|
312
|
-
catch {
|
|
313
|
-
// Start fresh
|
|
314
|
-
}
|
|
315
|
-
log.blockages.push(resolution);
|
|
316
|
-
await fs.mkdir(path.dirname(logPath), { recursive: true });
|
|
317
|
-
await fs.writeFile(logPath, JSON.stringify(log, null, 2), "utf-8");
|
|
318
|
-
// Write a message to @manager's inbox via messages folder
|
|
319
|
-
const messagesDir = path.join(projectRoot, ".enderun", "messages");
|
|
320
|
-
await fs.mkdir(messagesDir, { recursive: true });
|
|
321
|
-
const messageFile = path.join(messagesDir, `BLOCKAGE-${traceId}-${Date.now()}.json`);
|
|
322
|
-
await fs.writeFile(messageFile, JSON.stringify({
|
|
323
|
-
from: "@orchestrator",
|
|
324
|
-
to: "@manager",
|
|
325
|
-
type: "AGENT_BLOCKED",
|
|
326
|
-
traceId,
|
|
327
|
-
payload: { blockedAgent, blockReason, resolution },
|
|
328
|
-
timestamp: new Date().toISOString(),
|
|
329
|
-
}), "utf-8");
|
|
330
|
-
return { content: [{ type: "text", text: JSON.stringify(resolution, null, 2) }] };
|
|
331
|
-
},
|
|
332
|
-
async broadcast_army_directive(args, projectRoot) {
|
|
333
|
-
const { traceId, directiveType, message, urgency } = args;
|
|
334
|
-
const broadcast = {
|
|
335
|
-
id: `BROADCAST-${traceId}-${Date.now()}`,
|
|
336
|
-
from: "@orchestrator",
|
|
337
|
-
to: "*",
|
|
338
|
-
traceId,
|
|
339
|
-
directiveType,
|
|
340
|
-
message,
|
|
341
|
-
urgency: urgency ?? "NORMAL",
|
|
342
|
-
timestamp: new Date().toISOString(),
|
|
343
|
-
};
|
|
344
|
-
// Write to messages folder for all agents
|
|
345
|
-
const messagesDir = path.join(projectRoot, ".enderun", "messages");
|
|
346
|
-
await fs.mkdir(messagesDir, { recursive: true });
|
|
347
|
-
await fs.writeFile(path.join(messagesDir, `${broadcast.id}.json`), JSON.stringify(broadcast, null, 2), "utf-8");
|
|
348
|
-
// Log broadcast
|
|
349
|
-
const logPath = path.join(projectRoot, ".enderun", "logs", "orchestrator.json");
|
|
350
|
-
let log = {
|
|
351
|
-
assignments: [],
|
|
352
|
-
blockages: [],
|
|
353
|
-
broadcasts: [],
|
|
354
|
-
};
|
|
355
|
-
try {
|
|
356
|
-
const existing = await fs.readFile(logPath, "utf-8");
|
|
357
|
-
log = JSON.parse(existing);
|
|
358
|
-
if (!log.broadcasts)
|
|
359
|
-
log.broadcasts = [];
|
|
360
|
-
}
|
|
361
|
-
catch {
|
|
362
|
-
// Start fresh
|
|
363
|
-
}
|
|
364
|
-
log.broadcasts.push(broadcast);
|
|
365
|
-
await fs.writeFile(logPath, JSON.stringify(log, null, 2), "utf-8");
|
|
366
|
-
return { content: [{ type: "text", text: JSON.stringify(broadcast, null, 2) }] };
|
|
367
|
-
},
|
|
368
|
-
};
|