@gjczone/pi-swarm 0.1.6 → 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/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -5
- package/dist/index.js.map +1 -1
- package/dist/shared/controller.d.ts +5 -2
- package/dist/shared/controller.d.ts.map +1 -1
- package/dist/shared/controller.js +109 -43
- package/dist/shared/controller.js.map +1 -1
- package/dist/shared/render.d.ts +4 -4
- package/dist/shared/render.d.ts.map +1 -1
- package/dist/shared/render.js +7 -9
- package/dist/shared/render.js.map +1 -1
- package/dist/shared/spawner.d.ts +1 -1
- package/dist/shared/spawner.d.ts.map +1 -1
- package/dist/shared/spawner.js +232 -132
- package/dist/shared/spawner.js.map +1 -1
- package/dist/shared/types.d.ts +44 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/state/persistence.d.ts +21 -14
- package/dist/state/persistence.d.ts.map +1 -1
- package/dist/state/persistence.js +79 -28
- package/dist/state/persistence.js.map +1 -1
- package/dist/state/recovery.d.ts +2 -2
- package/dist/state/recovery.d.ts.map +1 -1
- package/dist/state/recovery.js +37 -22
- package/dist/state/recovery.js.map +1 -1
- package/dist/swarm/command.d.ts.map +1 -1
- package/dist/swarm/command.js.map +1 -1
- package/dist/swarm/mode.d.ts.map +1 -1
- package/dist/swarm/mode.js +9 -4
- package/dist/swarm/mode.js.map +1 -1
- package/dist/swarm/tool.d.ts.map +1 -1
- package/dist/swarm/tool.js +77 -5
- package/dist/swarm/tool.js.map +1 -1
- package/dist/team/command.d.ts +3 -2
- package/dist/team/command.d.ts.map +1 -1
- package/dist/team/command.js +24 -7
- package/dist/team/command.js.map +1 -1
- package/dist/team/mailbox.d.ts +3 -3
- package/dist/team/mailbox.d.ts.map +1 -1
- package/dist/team/mailbox.js +38 -17
- package/dist/team/mailbox.js.map +1 -1
- package/dist/team/supervisor.d.ts +31 -5
- package/dist/team/supervisor.d.ts.map +1 -1
- package/dist/team/supervisor.js +187 -16
- package/dist/team/supervisor.js.map +1 -1
- package/dist/team/task-graph.d.ts.map +1 -1
- package/dist/team/task-graph.js +4 -7
- package/dist/team/task-graph.js.map +1 -1
- package/dist/team/tool.d.ts +3 -3
- package/dist/team/tool.d.ts.map +1 -1
- package/dist/team/tool.js +81 -24
- package/dist/team/tool.js.map +1 -1
- package/dist/tui/permission-prompt.d.ts.map +1 -1
- package/dist/tui/permission-prompt.js.map +1 -1
- package/dist/tui/progress.d.ts +10 -0
- package/dist/tui/progress.d.ts.map +1 -1
- package/dist/tui/progress.js +50 -1
- package/dist/tui/progress.js.map +1 -1
- package/dist/tui/team-dashboard.d.ts +54 -0
- package/dist/tui/team-dashboard.d.ts.map +1 -0
- package/dist/tui/team-dashboard.js +240 -0
- package/dist/tui/team-dashboard.js.map +1 -0
- package/package.json +1 -1
package/dist/swarm/tool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/swarm/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/swarm/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAC;AAO9B,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAE5B,+DAA+D;AAC/D,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AAEhD,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,qBAAqB,GAAG,OAAO,CAAC;AAC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4B;QAC5B,SAAS,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO;QACL,SAAS;QACT,OAAO;YACL,SAAS,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,mBAAmB,CAAC,GAAqB;IAChD,IAAI,GAAG,CAAC,IAAI,KAAK,KAAK;QAAE,OAAO;IAC/B,MAAM,SAAS,GAAG,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC;IACpC,IAAI,OAAO,SAAS,KAAK,UAAU;QAAE,OAAO;IAC5C,IAAI,CAAC;QACH,SAAS,CAAC,mBAAmB,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;IAC1E,CAAC;IAAC,MAAM,CAAC;QACP,qDAAqD;IACvD,CAAC;AACH,CAAC"}
|
package/dist/team/command.d.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* Supports:
|
|
5
5
|
* /swarm-team <goal> — launch a team run for the given goal
|
|
6
6
|
*
|
|
7
|
-
* The command delegates to the
|
|
7
|
+
* The command delegates to the SwarmTeam tool internally.
|
|
8
8
|
*/
|
|
9
9
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
10
|
-
|
|
10
|
+
import type { SwarmCommandHost } from "../swarm/command.js";
|
|
11
|
+
export declare function registerTeamCommand(pi: ExtensionAPI, host: SwarmCommandHost): void;
|
|
11
12
|
//# sourceMappingURL=command.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/team/command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/team/command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAM5D,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,YAAY,EAChB,IAAI,EAAE,gBAAgB,GACrB,IAAI,CA+CN"}
|
package/dist/team/command.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* Supports:
|
|
5
5
|
* /swarm-team <goal> — launch a team run for the given goal
|
|
6
6
|
*
|
|
7
|
-
* The command delegates to the
|
|
7
|
+
* The command delegates to the SwarmTeam tool internally.
|
|
8
8
|
*/
|
|
9
9
|
// ---------------------------------------------------------------------------
|
|
10
10
|
// Registration
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
|
-
export function registerTeamCommand(pi) {
|
|
12
|
+
export function registerTeamCommand(pi, host) {
|
|
13
13
|
pi.registerCommand("swarm-team", {
|
|
14
14
|
description: "Launch a collaborative team of role-based agents to complete a complex task. " +
|
|
15
15
|
"Usage: /swarm-team <goal>",
|
|
@@ -19,13 +19,30 @@ export function registerTeamCommand(pi) {
|
|
|
19
19
|
ctx.ui?.notify?.("Usage: /swarm-team <goal>", "warning");
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
if (!host.hasModel()) {
|
|
23
|
+
host.showError("No model configured. Please set a model first.");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// Activate swarm mode if not already active
|
|
27
|
+
if (!host.swarmActive) {
|
|
28
|
+
if (host.getPermissionMode() === "manual") {
|
|
29
|
+
const confirmed = await ctx.ui?.confirm("Swarm Team", "Starting a swarm team task. Switch to auto permission mode?");
|
|
30
|
+
if (!confirmed) {
|
|
31
|
+
host.showStatus("Swarm team task cancelled.");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await host.setPermissionMode("auto");
|
|
35
|
+
}
|
|
36
|
+
host.setSwarmActive(true, "task");
|
|
37
|
+
}
|
|
38
|
+
// TUI marker
|
|
39
|
+
host.pi.sendMessage?.({
|
|
40
|
+
customType: "swarm:marker",
|
|
41
|
+
content: "active",
|
|
27
42
|
display: true,
|
|
28
43
|
});
|
|
44
|
+
// Send the goal as a user prompt — the LLM will call SwarmTeam
|
|
45
|
+
host.sendNormalUserInput(`Use the SwarmTeam tool to accomplish this goal: ${prompt}`);
|
|
29
46
|
},
|
|
30
47
|
});
|
|
31
48
|
}
|
package/dist/team/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/team/command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/team/command.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,MAAM,UAAU,mBAAmB,CACjC,EAAgB,EAChB,IAAsB;IAEtB,EAAE,CAAC,eAAe,CAAC,YAAY,EAAE;QAC/B,WAAW,EACT,+EAA+E;YAC/E,2BAA2B;QAC7B,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,GAA4B;YACtD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;YAE3B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACxB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,2BAA2B,EAAE,SAAS,CAAC,CAAC;gBACzD,OAAO;YACT,CAAC;YAED,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACrB,IAAI,CAAC,SAAS,CAAC,gDAAgD,CAAC,CAAC;gBACjE,OAAO;YACT,CAAC;YAED,4CAA4C;YAC5C,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;gBACtB,IAAI,IAAI,CAAC,iBAAiB,EAAE,KAAK,QAAQ,EAAE,CAAC;oBAC1C,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,EAAE,EAAE,OAAO,CACrC,YAAY,EACZ,6DAA6D,CAC9D,CAAC;oBACF,IAAI,CAAC,SAAS,EAAE,CAAC;wBACf,IAAI,CAAC,UAAU,CAAC,4BAA4B,CAAC,CAAC;wBAC9C,OAAO;oBACT,CAAC;oBACD,MAAM,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;gBACvC,CAAC;gBACD,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACpC,CAAC;YAED,aAAa;YACb,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC;gBACpB,UAAU,EAAE,cAAc;gBAC1B,OAAO,EAAE,QAAQ;gBACjB,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,+DAA+D;YAC/D,IAAI,CAAC,mBAAmB,CACtB,mDAAmD,MAAM,EAAE,CAC5D,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/team/mailbox.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { MailboxMessage } from "../shared/types.js";
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolve mailbox paths for a team run.
|
|
12
12
|
*
|
|
13
|
-
* {
|
|
13
|
+
* {swarmRoot}/state/runs/{runId}/mailbox/
|
|
14
14
|
* inbox.jsonl — team-level inbox
|
|
15
15
|
* outbox.jsonl — team-level outbox
|
|
16
16
|
* delivery.json — delivery state
|
|
@@ -25,8 +25,8 @@ export interface MailboxPaths {
|
|
|
25
25
|
readonly delivery: string;
|
|
26
26
|
readonly taskDir: string;
|
|
27
27
|
}
|
|
28
|
-
export declare function resolveMailboxPaths(
|
|
29
|
-
export declare function resolveTaskMailboxPaths(
|
|
28
|
+
export declare function resolveMailboxPaths(swarmRoot: string, runId: string): MailboxPaths;
|
|
29
|
+
export declare function resolveTaskMailboxPaths(paths: MailboxPaths, taskId: string): {
|
|
30
30
|
inbox: string;
|
|
31
31
|
outbox: string;
|
|
32
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mailbox.d.ts","sourceRoot":"","sources":["../../src/team/mailbox.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"mailbox.d.ts","sourceRoot":"","sources":["../../src/team/mailbox.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAyCzD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GACZ,YAAY,CASd;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAQnC;AAMD;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CASvD;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,cAAc,GACtB,IAAI,CAaN;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,cAAc,EAAE,CAE/D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,MAAM,GACb,cAAc,EAAE,CAGlB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,IAAI,CAK3E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQ5E;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,IAAI,CAIN"}
|
package/dist/team/mailbox.js
CHANGED
|
@@ -8,8 +8,32 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import * as fs from "node:fs";
|
|
10
10
|
import * as path from "node:path";
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import { validateId } from "../state/persistence.js";
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Security helpers
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
const SAFE_RECIPIENT_PATTERN = /^[a-zA-Z0-9_-]+$/;
|
|
16
|
+
function validateRecipient(recipient, field) {
|
|
17
|
+
if (recipient === "broadcast")
|
|
18
|
+
return;
|
|
19
|
+
if (typeof recipient !== "string" ||
|
|
20
|
+
recipient.length === 0 ||
|
|
21
|
+
recipient.length > 128) {
|
|
22
|
+
throw new Error(`Invalid ${field}: must be a non-empty string up to 128 characters`);
|
|
23
|
+
}
|
|
24
|
+
if (!SAFE_RECIPIENT_PATTERN.test(recipient)) {
|
|
25
|
+
throw new Error(`Invalid ${field}: "${recipient}" contains unsafe characters`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function ensureWithinMailbox(resolvedPath, mailboxRoot) {
|
|
29
|
+
const normalizedRoot = path.resolve(mailboxRoot) + path.sep;
|
|
30
|
+
const normalizedPath = path.resolve(resolvedPath);
|
|
31
|
+
if (!normalizedPath.startsWith(normalizedRoot)) {
|
|
32
|
+
throw new Error(`Path traversal detected: ${resolvedPath} escapes mailbox root`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function resolveMailboxPaths(swarmRoot, runId) {
|
|
36
|
+
const root = path.join(swarmRoot, "state", "runs", runId, "mailbox");
|
|
13
37
|
return {
|
|
14
38
|
root,
|
|
15
39
|
inbox: path.join(root, "inbox.jsonl"),
|
|
@@ -18,8 +42,10 @@ export function resolveMailboxPaths(crewRoot, runId) {
|
|
|
18
42
|
taskDir: path.join(root, "tasks"),
|
|
19
43
|
};
|
|
20
44
|
}
|
|
21
|
-
export function resolveTaskMailboxPaths(
|
|
22
|
-
|
|
45
|
+
export function resolveTaskMailboxPaths(paths, taskId) {
|
|
46
|
+
validateId(taskId, "taskId");
|
|
47
|
+
const base = path.join(paths.taskDir, taskId);
|
|
48
|
+
ensureWithinMailbox(base, paths.root);
|
|
23
49
|
return {
|
|
24
50
|
inbox: path.join(base, "inbox.jsonl"),
|
|
25
51
|
outbox: path.join(base, "outbox.jsonl"),
|
|
@@ -46,17 +72,14 @@ export function ensureMailbox(paths) {
|
|
|
46
72
|
*/
|
|
47
73
|
export function sendMessage(paths, message) {
|
|
48
74
|
ensureMailbox(paths);
|
|
75
|
+
validateRecipient(message.to, "message.to");
|
|
49
76
|
// Append to team outbox
|
|
50
77
|
appendJsonLine(paths.outbox, message);
|
|
51
78
|
// If addressed to a specific agent, also put in their task inbox
|
|
52
79
|
if (message.to && message.to !== "broadcast") {
|
|
53
|
-
const taskPaths = resolveTaskMailboxPaths(paths.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// The task inbox is under the taskDir.
|
|
57
|
-
const taskInbox = path.join(paths.taskDir, message.to, "inbox.jsonl");
|
|
58
|
-
fs.mkdirSync(path.dirname(taskInbox), { recursive: true });
|
|
59
|
-
appendJsonLine(taskInbox, message);
|
|
80
|
+
const taskPaths = resolveTaskMailboxPaths(paths, message.to);
|
|
81
|
+
fs.mkdirSync(path.dirname(taskPaths.inbox), { recursive: true });
|
|
82
|
+
appendJsonLine(taskPaths.inbox, message);
|
|
60
83
|
}
|
|
61
84
|
}
|
|
62
85
|
/**
|
|
@@ -69,7 +92,7 @@ export function readInbox(paths) {
|
|
|
69
92
|
* Read messages from a task-specific inbox.
|
|
70
93
|
*/
|
|
71
94
|
export function readTaskInbox(paths, taskId) {
|
|
72
|
-
const taskPaths = resolveTaskMailboxPaths(
|
|
95
|
+
const taskPaths = resolveTaskMailboxPaths(paths, taskId);
|
|
73
96
|
return readJsonLines(taskPaths.inbox);
|
|
74
97
|
}
|
|
75
98
|
/**
|
|
@@ -134,9 +157,7 @@ function readJsonLines(filePath) {
|
|
|
134
157
|
}
|
|
135
158
|
}
|
|
136
159
|
function writeJsonLines(filePath, messages) {
|
|
137
|
-
const content = messages
|
|
138
|
-
.map((m) => JSON.stringify(m))
|
|
139
|
-
.join("\n");
|
|
160
|
+
const content = messages.map((m) => JSON.stringify(m)).join("\n");
|
|
140
161
|
fs.writeFileSync(filePath, content + (content ? "\n" : ""), "utf-8");
|
|
141
162
|
}
|
|
142
163
|
function extractRunId(mailboxRoot) {
|
|
@@ -148,8 +169,8 @@ function extractRunId(mailboxRoot) {
|
|
|
148
169
|
}
|
|
149
170
|
return "unknown";
|
|
150
171
|
}
|
|
151
|
-
function
|
|
152
|
-
// mailboxRoot = {
|
|
172
|
+
function extractSwarmRoot(mailboxRoot) {
|
|
173
|
+
// mailboxRoot = {swarmRoot}/state/runs/{runId}/mailbox
|
|
153
174
|
const parts = mailboxRoot.split(path.sep);
|
|
154
175
|
const stateIdx = parts.lastIndexOf("state");
|
|
155
176
|
if (stateIdx >= 0) {
|
package/dist/team/mailbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mailbox.js","sourceRoot":"","sources":["../../src/team/mailbox.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;
|
|
1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AU,IAAI,CAAC,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC,UAAU,GAAG,CAAC,CAAE,CAAC;IAChC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,gBAAgB,CAAC,WAAmB;IAC3C,uDAAuD;IACvD,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
* each phase to a role agent, monitors progress via the mailbox,
|
|
6
6
|
* and synthesizes the final result.
|
|
7
7
|
*/
|
|
8
|
-
import type { AgentRole, TeamPhase, AgentRoleConfig } from "../shared/types.js";
|
|
8
|
+
import type { AgentRole, TeamPhase, AgentRoleConfig, TeamProgressCallback } from "../shared/types.js";
|
|
9
9
|
import { TaskGraph, type PhaseState } from "./task-graph.js";
|
|
10
10
|
import { type MailboxPaths } from "./mailbox.js";
|
|
11
11
|
export interface TeamSupervisorConfig {
|
|
12
12
|
/** Working directory for the team run. */
|
|
13
13
|
readonly cwd: string;
|
|
14
|
-
/**
|
|
15
|
-
readonly
|
|
14
|
+
/** Swarm root for state persistence. */
|
|
15
|
+
readonly swarmRoot: string;
|
|
16
16
|
/** Unique run identifier. */
|
|
17
17
|
readonly runId: string;
|
|
18
18
|
/** High-level goal. */
|
|
@@ -23,6 +23,8 @@ export interface TeamSupervisorConfig {
|
|
|
23
23
|
readonly roles?: readonly AgentRoleConfig[];
|
|
24
24
|
/** Max concurrent agents. */
|
|
25
25
|
readonly maxAgents?: number;
|
|
26
|
+
/** Progress callback for TUI dashboard updates. */
|
|
27
|
+
readonly onProgress?: TeamProgressCallback;
|
|
26
28
|
}
|
|
27
29
|
export interface TeamRunState {
|
|
28
30
|
readonly runId: string;
|
|
@@ -37,6 +39,7 @@ export declare class TeamSupervisor {
|
|
|
37
39
|
readonly config: TeamSupervisorConfig;
|
|
38
40
|
readonly state: TeamRunState;
|
|
39
41
|
readonly mailboxPaths: MailboxPaths;
|
|
42
|
+
private readonly onProgress?;
|
|
40
43
|
constructor(config: TeamSupervisorConfig);
|
|
41
44
|
/**
|
|
42
45
|
* Get the next phase that is ready to execute (dependencies satisfied,
|
|
@@ -52,9 +55,24 @@ export declare class TeamSupervisor {
|
|
|
52
55
|
prompt: string;
|
|
53
56
|
} | null;
|
|
54
57
|
/**
|
|
55
|
-
*
|
|
58
|
+
* Parse agent output for mailbox_message blocks and separate them from the result.
|
|
56
59
|
*/
|
|
57
|
-
|
|
60
|
+
parseAgentMessages(output: string): {
|
|
61
|
+
result: string;
|
|
62
|
+
messages: Array<{
|
|
63
|
+
to: string;
|
|
64
|
+
content: string;
|
|
65
|
+
}>;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Mark a phase as completed with its raw output.
|
|
69
|
+
* Parses messages from output, delivers them, and sends task_result broadcast.
|
|
70
|
+
*/
|
|
71
|
+
completePhase(name: string, rawOutput: string): {
|
|
72
|
+
result: string;
|
|
73
|
+
deliveredMessages: number;
|
|
74
|
+
};
|
|
75
|
+
private generateMessageId;
|
|
58
76
|
/**
|
|
59
77
|
* Mark a phase as failed.
|
|
60
78
|
*/
|
|
@@ -63,6 +81,14 @@ export declare class TeamSupervisor {
|
|
|
63
81
|
* Assign an agent to a phase.
|
|
64
82
|
*/
|
|
65
83
|
assignAgent(phaseName: string, agentId: string): void;
|
|
84
|
+
/**
|
|
85
|
+
* Build and emit a TeamProgressSnapshot for the TUI dashboard.
|
|
86
|
+
*
|
|
87
|
+
* Reads current phase statuses from the task graph, counts mailbox
|
|
88
|
+
* messages, and calls the optional onProgress callback with the
|
|
89
|
+
* snapshot.
|
|
90
|
+
*/
|
|
91
|
+
private emitProgress;
|
|
66
92
|
/** Check if the entire run is complete. */
|
|
67
93
|
isComplete(): boolean;
|
|
68
94
|
/** Finalize the run with an overall status. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../src/team/supervisor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,eAAe,
|
|
1
|
+
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../src/team/supervisor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,SAAS,EACT,SAAS,EACT,eAAe,EAEf,oBAAoB,EAErB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,SAAS,EAET,KAAK,UAAU,EAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAML,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AAMtB,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,6BAA6B;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uBAAuB;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACvC,2BAA2B;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IAC5C,6BAA6B;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,mDAAmD;IACnD,QAAQ,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AAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAwB5C;;OAEG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAarD;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IA8CpB,2CAA2C;IAC3C,UAAU,IAAI,OAAO;IAIrB,+CAA+C;IAC/C,QAAQ,IAAI,IAAI;IAMhB;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAkC1B,OAAO,CAAC,gBAAgB;IAmExB,OAAO,CAAC,YAAY;CAYrB"}
|
package/dist/team/supervisor.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* and synthesizes the final result.
|
|
7
7
|
*/
|
|
8
8
|
import { TaskGraph, DEFAULT_TEAM_PHASES, } from "./task-graph.js";
|
|
9
|
-
import { resolveMailboxPaths, ensureMailbox, } from "./mailbox.js";
|
|
9
|
+
import { resolveMailboxPaths, ensureMailbox, sendMessage, readTaskInbox, updateDeliveryState, } from "./mailbox.js";
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
11
|
// Supervisor
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
@@ -14,9 +14,11 @@ export class TeamSupervisor {
|
|
|
14
14
|
config;
|
|
15
15
|
state;
|
|
16
16
|
mailboxPaths;
|
|
17
|
+
onProgress;
|
|
17
18
|
constructor(config) {
|
|
18
19
|
this.config = config;
|
|
19
|
-
this.
|
|
20
|
+
this.onProgress = config.onProgress;
|
|
21
|
+
this.mailboxPaths = resolveMailboxPaths(config.swarmRoot, config.runId);
|
|
20
22
|
const phases = config.phases ?? DEFAULT_TEAM_PHASES;
|
|
21
23
|
this.state = {
|
|
22
24
|
runId: config.runId,
|
|
@@ -27,6 +29,8 @@ export class TeamSupervisor {
|
|
|
27
29
|
startedAt: Date.now(),
|
|
28
30
|
};
|
|
29
31
|
ensureMailbox(this.mailboxPaths);
|
|
32
|
+
// Emit initial state (all queued)
|
|
33
|
+
this.emitProgress();
|
|
30
34
|
}
|
|
31
35
|
// -------------------------------------------------------------------
|
|
32
36
|
// Phase management
|
|
@@ -62,7 +66,24 @@ export class TeamSupervisor {
|
|
|
62
66
|
const result = this.state.taskGraph.startPhase(phase.phase.name);
|
|
63
67
|
if (!result.ok)
|
|
64
68
|
return null;
|
|
69
|
+
// Send task assignment message to the role's mailbox
|
|
70
|
+
const assignmentMessage = {
|
|
71
|
+
messageId: this.generateMessageId(),
|
|
72
|
+
runId: this.state.runId,
|
|
73
|
+
timestamp: new Date().toISOString(),
|
|
74
|
+
from: "supervisor",
|
|
75
|
+
to: phase.phase.role,
|
|
76
|
+
type: "task_assignment",
|
|
77
|
+
payload: {
|
|
78
|
+
phase: phase.phase.name,
|
|
79
|
+
goal: this.config.goal,
|
|
80
|
+
dependsOn: phase.phase.dependsOn ?? [],
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
sendMessage(this.mailboxPaths, assignmentMessage);
|
|
84
|
+
updateDeliveryState(this.mailboxPaths, assignmentMessage.messageId, "delivered");
|
|
65
85
|
const prompt = this.buildPhasePrompt(phase);
|
|
86
|
+
this.emitProgress();
|
|
66
87
|
return {
|
|
67
88
|
phase,
|
|
68
89
|
role: phase.phase.role,
|
|
@@ -70,28 +91,96 @@ export class TeamSupervisor {
|
|
|
70
91
|
};
|
|
71
92
|
}
|
|
72
93
|
/**
|
|
73
|
-
*
|
|
94
|
+
* Parse agent output for mailbox_message blocks and separate them from the result.
|
|
95
|
+
*/
|
|
96
|
+
parseAgentMessages(output) {
|
|
97
|
+
const messages = [];
|
|
98
|
+
const messageRegex = /<mailbox_message\s+to="([^"]+)">([\s\S]*?)<\/mailbox_message>/g;
|
|
99
|
+
let match;
|
|
100
|
+
while ((match = messageRegex.exec(output)) !== null) {
|
|
101
|
+
messages.push({
|
|
102
|
+
to: match[1].trim(),
|
|
103
|
+
content: match[2].trim(),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const result = output.replace(messageRegex, "").trim();
|
|
107
|
+
return { result, messages };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Mark a phase as completed with its raw output.
|
|
111
|
+
* Parses messages from output, delivers them, and sends task_result broadcast.
|
|
74
112
|
*/
|
|
75
|
-
completePhase(name,
|
|
113
|
+
completePhase(name, rawOutput) {
|
|
114
|
+
const phase = this.state.taskGraph.getPhase(name);
|
|
115
|
+
if (!phase) {
|
|
116
|
+
return { result: rawOutput, deliveredMessages: 0 };
|
|
117
|
+
}
|
|
118
|
+
const { result, messages } = this.parseAgentMessages(rawOutput);
|
|
76
119
|
this.state.taskGraph.completePhase(name, result);
|
|
77
|
-
//
|
|
78
|
-
|
|
120
|
+
// Deliver parsed handoff messages
|
|
121
|
+
let deliveredCount = 0;
|
|
122
|
+
for (const msg of messages) {
|
|
123
|
+
try {
|
|
124
|
+
const handoffMessage = {
|
|
125
|
+
messageId: this.generateMessageId(),
|
|
126
|
+
runId: this.state.runId,
|
|
127
|
+
timestamp: new Date().toISOString(),
|
|
128
|
+
from: name,
|
|
129
|
+
to: msg.to,
|
|
130
|
+
type: "handoff",
|
|
131
|
+
payload: { content: msg.content },
|
|
132
|
+
};
|
|
133
|
+
sendMessage(this.mailboxPaths, handoffMessage);
|
|
134
|
+
updateDeliveryState(this.mailboxPaths, handoffMessage.messageId, "delivered");
|
|
135
|
+
deliveredCount++;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// Skip invalid messages
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Broadcast task result
|
|
142
|
+
const resultMessage = {
|
|
143
|
+
messageId: this.generateMessageId(),
|
|
144
|
+
runId: this.state.runId,
|
|
145
|
+
timestamp: new Date().toISOString(),
|
|
146
|
+
from: name,
|
|
147
|
+
to: "broadcast",
|
|
148
|
+
type: "task_result",
|
|
149
|
+
payload: { phase: name, result },
|
|
150
|
+
};
|
|
151
|
+
sendMessage(this.mailboxPaths, resultMessage);
|
|
152
|
+
updateDeliveryState(this.mailboxPaths, resultMessage.messageId, "broadcast");
|
|
153
|
+
this.emitProgress();
|
|
154
|
+
return { result, deliveredMessages: deliveredCount };
|
|
155
|
+
}
|
|
156
|
+
generateMessageId() {
|
|
157
|
+
return `msg-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
79
158
|
}
|
|
80
159
|
/**
|
|
81
160
|
* Mark a phase as failed.
|
|
82
161
|
*/
|
|
83
162
|
failPhase(name, error) {
|
|
84
163
|
this.state.taskGraph.failPhase(name, error);
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
164
|
+
// BFS: skip all phases that depend (directly or transitively) on a failed/skipped phase
|
|
165
|
+
const queue = [name];
|
|
166
|
+
const visited = new Set();
|
|
167
|
+
while (queue.length > 0) {
|
|
168
|
+
const current = queue.shift();
|
|
169
|
+
if (visited.has(current))
|
|
89
170
|
continue;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.state.taskGraph.
|
|
171
|
+
visited.add(current);
|
|
172
|
+
for (const otherName of this.state.taskGraph.getPhaseNames()) {
|
|
173
|
+
const other = this.state.taskGraph.getPhase(otherName);
|
|
174
|
+
if (!other || other.status !== "queued")
|
|
175
|
+
continue;
|
|
176
|
+
const deps = other.phase.dependsOn ?? [];
|
|
177
|
+
if (deps.includes(current)) {
|
|
178
|
+
this.state.taskGraph.skipPhase(otherName);
|
|
179
|
+
queue.push(otherName);
|
|
180
|
+
}
|
|
93
181
|
}
|
|
94
182
|
}
|
|
183
|
+
this.emitProgress();
|
|
95
184
|
}
|
|
96
185
|
/**
|
|
97
186
|
* Assign an agent to a phase.
|
|
@@ -103,6 +192,59 @@ export class TeamSupervisor {
|
|
|
103
192
|
// -------------------------------------------------------------------
|
|
104
193
|
// Completion
|
|
105
194
|
// -------------------------------------------------------------------
|
|
195
|
+
// -------------------------------------------------------------------
|
|
196
|
+
// Progress emission
|
|
197
|
+
// -------------------------------------------------------------------
|
|
198
|
+
/**
|
|
199
|
+
* Build and emit a TeamProgressSnapshot for the TUI dashboard.
|
|
200
|
+
*
|
|
201
|
+
* Reads current phase statuses from the task graph, counts mailbox
|
|
202
|
+
* messages, and calls the optional onProgress callback with the
|
|
203
|
+
* snapshot.
|
|
204
|
+
*/
|
|
205
|
+
emitProgress() {
|
|
206
|
+
if (!this.onProgress)
|
|
207
|
+
return;
|
|
208
|
+
try {
|
|
209
|
+
const allPhases = this.state.taskGraph.getAllPhases();
|
|
210
|
+
const phases = allPhases.map((p) => ({
|
|
211
|
+
name: p.phase.name,
|
|
212
|
+
role: p.phase.role,
|
|
213
|
+
status: p.status,
|
|
214
|
+
error: p.error,
|
|
215
|
+
}));
|
|
216
|
+
const completed = phases.filter((p) => p.status === "completed").length;
|
|
217
|
+
const failed = phases.filter((p) => p.status === "failed").length;
|
|
218
|
+
// Find current running phase
|
|
219
|
+
const runningPhase = phases.find((p) => p.status === "running");
|
|
220
|
+
// Best-effort mailbox count
|
|
221
|
+
let mailboxCount = 0;
|
|
222
|
+
try {
|
|
223
|
+
const inbox = readTaskInbox(this.mailboxPaths, "supervisor");
|
|
224
|
+
mailboxCount = inbox.length;
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
// Ignore mailbox read errors
|
|
228
|
+
}
|
|
229
|
+
const snapshot = {
|
|
230
|
+
title: this.config.goal,
|
|
231
|
+
goal: this.config.goal,
|
|
232
|
+
status: this.state.status,
|
|
233
|
+
totalPhases: phases.length,
|
|
234
|
+
completedPhases: completed,
|
|
235
|
+
failedPhases: failed,
|
|
236
|
+
currentPhase: runningPhase?.name,
|
|
237
|
+
currentRole: runningPhase?.role,
|
|
238
|
+
phases,
|
|
239
|
+
mailboxCount,
|
|
240
|
+
startedAt: this.state.startedAt,
|
|
241
|
+
};
|
|
242
|
+
this.onProgress(snapshot);
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
// Best effort — dashboard failure must not break the run
|
|
246
|
+
}
|
|
247
|
+
}
|
|
106
248
|
/** Check if the entire run is complete. */
|
|
107
249
|
isComplete() {
|
|
108
250
|
return this.state.taskGraph.isComplete();
|
|
@@ -111,13 +253,14 @@ export class TeamSupervisor {
|
|
|
111
253
|
finalize() {
|
|
112
254
|
this.state.status = this.state.taskGraph.overallStatus();
|
|
113
255
|
this.state.completedAt = Date.now();
|
|
256
|
+
this.emitProgress();
|
|
114
257
|
}
|
|
115
258
|
/**
|
|
116
259
|
* Synthesize the final team result from all completed phases.
|
|
117
260
|
*/
|
|
118
261
|
synthesizeResult() {
|
|
119
262
|
const lines = [
|
|
120
|
-
"<
|
|
263
|
+
"<swarm_team_result>",
|
|
121
264
|
`<summary>${this.buildSummary()}</summary>`,
|
|
122
265
|
];
|
|
123
266
|
for (const phase of this.state.taskGraph.getAllPhases()) {
|
|
@@ -135,7 +278,7 @@ export class TeamSupervisor {
|
|
|
135
278
|
}
|
|
136
279
|
lines.push(`</phase>`);
|
|
137
280
|
}
|
|
138
|
-
lines.push("</
|
|
281
|
+
lines.push("</swarm_team_result>");
|
|
139
282
|
return lines.join("\n");
|
|
140
283
|
}
|
|
141
284
|
// -------------------------------------------------------------------
|
|
@@ -162,12 +305,40 @@ export class TeamSupervisor {
|
|
|
162
305
|
contextBlock = `\n\nContext from previous phases:\n${depResults}`;
|
|
163
306
|
}
|
|
164
307
|
}
|
|
308
|
+
// Read messages addressed to this role
|
|
309
|
+
let messagesBlock = "";
|
|
310
|
+
try {
|
|
311
|
+
const roleMessages = readTaskInbox(this.mailboxPaths, role);
|
|
312
|
+
const handoffMessages = roleMessages.filter((m) => m.type === "handoff" || m.type === "task_assignment");
|
|
313
|
+
if (handoffMessages.length > 0) {
|
|
314
|
+
const messageText = handoffMessages
|
|
315
|
+
.map((m) => `Message from ${m.from}:\n${String(m.payload.content ?? m.payload.phase ?? "")}`)
|
|
316
|
+
.join("\n\n");
|
|
317
|
+
messagesBlock = `\n\nMessages for you:\n${messageText}`;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
// Ignore mailbox read errors
|
|
322
|
+
}
|
|
165
323
|
return [
|
|
166
324
|
`You are the ${role} agent in a team working on: ${goal}`,
|
|
167
325
|
`Your current phase is: ${name}`,
|
|
168
326
|
contextBlock,
|
|
327
|
+
messagesBlock,
|
|
328
|
+
``,
|
|
329
|
+
`## Communication Protocol`,
|
|
330
|
+
``,
|
|
331
|
+
`You can send messages to other team members by including them in your output using this format:`,
|
|
332
|
+
``,
|
|
333
|
+
`<mailbox_message to="role_name">`,
|
|
334
|
+
`Your message content here.`,
|
|
335
|
+
`</mailbox_message>`,
|
|
336
|
+
``,
|
|
337
|
+
`You can address messages to: explorer, planner, coder, reviewer, tester, fixer, or broadcast.`,
|
|
338
|
+
`Messages are delivered after your phase completes.`,
|
|
339
|
+
``,
|
|
340
|
+
`Your final output (outside of mailbox_message tags) is your phase result.`,
|
|
169
341
|
`Complete the ${name} phase and write your result.`,
|
|
170
|
-
`Output only the result — no conversation.`,
|
|
171
342
|
]
|
|
172
343
|
.filter(Boolean)
|
|
173
344
|
.join("\n");
|