@gjczone/pi-swarm 0.1.2

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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -0
  3. package/dist/index.d.ts +13 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +99 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/shared/controller.d.ts +86 -0
  8. package/dist/shared/controller.d.ts.map +1 -0
  9. package/dist/shared/controller.js +662 -0
  10. package/dist/shared/controller.js.map +1 -0
  11. package/dist/shared/pi-invoke.d.ts +31 -0
  12. package/dist/shared/pi-invoke.d.ts.map +1 -0
  13. package/dist/shared/pi-invoke.js +54 -0
  14. package/dist/shared/pi-invoke.js.map +1 -0
  15. package/dist/shared/render.d.ts +44 -0
  16. package/dist/shared/render.d.ts.map +1 -0
  17. package/dist/shared/render.js +116 -0
  18. package/dist/shared/render.js.map +1 -0
  19. package/dist/shared/spawner.d.ts +26 -0
  20. package/dist/shared/spawner.d.ts.map +1 -0
  21. package/dist/shared/spawner.js +226 -0
  22. package/dist/shared/spawner.js.map +1 -0
  23. package/dist/shared/types.d.ts +182 -0
  24. package/dist/shared/types.d.ts.map +1 -0
  25. package/dist/shared/types.js +8 -0
  26. package/dist/shared/types.js.map +1 -0
  27. package/dist/state/persistence.d.ts +83 -0
  28. package/dist/state/persistence.d.ts.map +1 -0
  29. package/dist/state/persistence.js +215 -0
  30. package/dist/state/persistence.js.map +1 -0
  31. package/dist/state/recovery.d.ts +35 -0
  32. package/dist/state/recovery.d.ts.map +1 -0
  33. package/dist/state/recovery.js +149 -0
  34. package/dist/state/recovery.js.map +1 -0
  35. package/dist/swarm/command.d.ts +36 -0
  36. package/dist/swarm/command.d.ts.map +1 -0
  37. package/dist/swarm/command.js +113 -0
  38. package/dist/swarm/command.js.map +1 -0
  39. package/dist/swarm/mode.d.ts +58 -0
  40. package/dist/swarm/mode.d.ts.map +1 -0
  41. package/dist/swarm/mode.js +87 -0
  42. package/dist/swarm/mode.js.map +1 -0
  43. package/dist/swarm/tool.d.ts +11 -0
  44. package/dist/swarm/tool.d.ts.map +1 -0
  45. package/dist/swarm/tool.js +190 -0
  46. package/dist/swarm/tool.js.map +1 -0
  47. package/dist/team/command.d.ts +11 -0
  48. package/dist/team/command.d.ts.map +1 -0
  49. package/dist/team/command.js +32 -0
  50. package/dist/team/command.js.map +1 -0
  51. package/dist/team/mailbox.d.ts +61 -0
  52. package/dist/team/mailbox.d.ts.map +1 -0
  53. package/dist/team/mailbox.js +160 -0
  54. package/dist/team/mailbox.js.map +1 -0
  55. package/dist/team/supervisor.d.ts +77 -0
  56. package/dist/team/supervisor.d.ts.map +1 -0
  57. package/dist/team/supervisor.js +195 -0
  58. package/dist/team/supervisor.js.map +1 -0
  59. package/dist/team/task-graph.d.ts +61 -0
  60. package/dist/team/task-graph.d.ts.map +1 -0
  61. package/dist/team/task-graph.js +193 -0
  62. package/dist/team/task-graph.js.map +1 -0
  63. package/dist/team/tool.d.ts +11 -0
  64. package/dist/team/tool.d.ts.map +1 -0
  65. package/dist/team/tool.js +210 -0
  66. package/dist/team/tool.js.map +1 -0
  67. package/dist/tui/permission-prompt.d.ts +26 -0
  68. package/dist/tui/permission-prompt.d.ts.map +1 -0
  69. package/dist/tui/permission-prompt.js +94 -0
  70. package/dist/tui/permission-prompt.js.map +1 -0
  71. package/dist/tui/progress.d.ts +64 -0
  72. package/dist/tui/progress.d.ts.map +1 -0
  73. package/dist/tui/progress.js +260 -0
  74. package/dist/tui/progress.js.map +1 -0
  75. package/dist/tui/swarm-markers.d.ts +20 -0
  76. package/dist/tui/swarm-markers.d.ts.map +1 -0
  77. package/dist/tui/swarm-markers.js +61 -0
  78. package/dist/tui/swarm-markers.js.map +1 -0
  79. package/package.json +58 -0
@@ -0,0 +1,210 @@
1
+ /**
2
+ * team/tool — AgentTeam tool registration.
3
+ *
4
+ * Registers the `AgentTeam` tool that the LLM can call to orchestrate
5
+ * a team of role-based agents that collaborate via a shared mailbox.
6
+ *
7
+ * Inspired by pi-crew's team orchestration and CrewAI's hierarchical model.
8
+ */
9
+ import { Type } from "typebox";
10
+ import { SubagentBatchController, } from "../shared/controller.js";
11
+ import { spawnSubagent, resumeSubagent, retrySubagent, } from "../shared/spawner.js";
12
+ import { TeamSupervisor } from "./supervisor.js";
13
+ // ---------------------------------------------------------------------------
14
+ // Constants
15
+ // ---------------------------------------------------------------------------
16
+ const DEFAULT_SUBAGENT_TIMEOUT_MS = 30 * 60 * 1000;
17
+ const AGENT_TEAM_DESCRIPTION = `Launch a collaborative team of role-based agents to complete a complex multi-phase task.
18
+
19
+ AgentTeam is best for tasks that require multiple steps across different roles:
20
+ explorer (codebase understanding) → planner (design) → coder (implementation)
21
+ → reviewer (quality check) → tester (verification).
22
+
23
+ Each agent communicates via a shared mailbox. The supervisor decomposes the goal
24
+ into phases, assigns each phase to a role agent, and synthesizes the final result.
25
+ Agents receive context from previous phases automatically.
26
+
27
+ Default phases: explore → plan → implement → review → test.
28
+ Custom phases and roles can be specified.
29
+
30
+ If AgentTeam is called, that call must be the only tool call in the response.`;
31
+ // ---------------------------------------------------------------------------
32
+ // Registration
33
+ // ---------------------------------------------------------------------------
34
+ export function registerAgentTeamTool(pi) {
35
+ pi.registerTool({
36
+ name: "AgentTeam",
37
+ label: "Agent Team",
38
+ description: AGENT_TEAM_DESCRIPTION,
39
+ parameters: Type.Object({
40
+ goal: Type.String({
41
+ description: "High-level goal for the team.",
42
+ }),
43
+ description: Type.String({
44
+ description: "Short description for the team run.",
45
+ }),
46
+ phases: Type.Optional(Type.Array(Type.Object({
47
+ name: Type.String(),
48
+ role: Type.String(),
49
+ dependsOn: Type.Optional(Type.Array(Type.String())),
50
+ }), {
51
+ description: "Custom phase definitions. Defaults to explore/plan/implement/review/test.",
52
+ })),
53
+ roles: Type.Optional(Type.Array(Type.Object({
54
+ role: Type.String(),
55
+ model: Type.Optional(Type.String()),
56
+ tools: Type.Optional(Type.Array(Type.String())),
57
+ systemPrompt: Type.Optional(Type.String()),
58
+ }), {
59
+ description: "Custom role configurations with optional model/tools overrides.",
60
+ })),
61
+ max_agents: Type.Optional(Type.Number({
62
+ description: "Max concurrent agents. Default 4.",
63
+ })),
64
+ resume_agent_ids: Type.Optional(Type.Record(Type.String(), Type.String(), {
65
+ description: "Map of existing agent_id to prompt for resuming failed phases.",
66
+ })),
67
+ }, { additionalProperties: false }),
68
+ execute: async (toolCallId, params, signal, _onUpdate, _ctx) => {
69
+ const p = params;
70
+ let supervisor = null;
71
+ try {
72
+ const crewRoot = process.env.PI_SWARM_CREW_ROOT ?? ".pi/swarm";
73
+ const runId = `team-${Date.now().toString(36)}`;
74
+ // Build phase definitions
75
+ const phases = p.phases?.map((ph) => ({
76
+ name: ph.name,
77
+ role: ph.role,
78
+ dependsOn: ph.dependsOn,
79
+ }));
80
+ // Build role configs
81
+ const roles = p.roles?.map((r) => ({
82
+ role: r.role,
83
+ model: r.model,
84
+ tools: r.tools,
85
+ systemPrompt: r.systemPrompt,
86
+ }));
87
+ // Create supervisor
88
+ supervisor = new TeamSupervisor({
89
+ cwd: process.cwd(),
90
+ crewRoot,
91
+ runId,
92
+ goal: p.goal,
93
+ phases,
94
+ roles,
95
+ maxAgents: p.max_agents ?? 4,
96
+ });
97
+ // Process resume entries first
98
+ const resumeIds = p.resume_agent_ids ?? {};
99
+ for (const [agentId, prompt] of Object.entries(resumeIds)) {
100
+ // Resume logic: re-spawn the agent with the new prompt
101
+ // For now, we track resumable agent IDs
102
+ }
103
+ // Run phases sequentially through the task graph
104
+ const allResults = [];
105
+ let currentPhase = supervisor.startNextPhase();
106
+ while (currentPhase !== null) {
107
+ // Check abort signal between phases
108
+ signal?.throwIfAborted();
109
+ const { phase, role, prompt: phasePrompt } = currentPhase;
110
+ // Spawn a single agent for this phase
111
+ const tasks = [
112
+ {
113
+ kind: "spawn",
114
+ data: { phase: phase.phase.name, role },
115
+ profileName: role,
116
+ parentToolCallId: toolCallId,
117
+ prompt: phasePrompt,
118
+ description: `${p.description} — ${phase.phase.name} (${role})`,
119
+ swarmIndex: 1,
120
+ runInBackground: false,
121
+ signal,
122
+ timeout: DEFAULT_SUBAGENT_TIMEOUT_MS,
123
+ },
124
+ ];
125
+ const controller = new SubagentBatchController({
126
+ spawn: spawnSubagent,
127
+ resume: resumeSubagent,
128
+ retry: retrySubagent,
129
+ }, tasks, {
130
+ maxConcurrency: 1, // Team phases run sequentially
131
+ });
132
+ let phaseResults;
133
+ try {
134
+ phaseResults = await controller.run();
135
+ }
136
+ catch (err) {
137
+ // Phase was aborted or failed catastrophically
138
+ supervisor.failPhase(phase.phase.name, err instanceof Error ? err.message : String(err));
139
+ // Abort signal: stop the entire run, save partial state
140
+ if (signal?.aborted) {
141
+ supervisor.finalize();
142
+ const partialOutput = supervisor.synthesizeResult();
143
+ return {
144
+ content: [{ type: "text", text: partialOutput }],
145
+ details: undefined,
146
+ };
147
+ }
148
+ // Non-abort error: try next phase
149
+ currentPhase = supervisor.startNextPhase();
150
+ continue;
151
+ }
152
+ allResults.push(...phaseResults);
153
+ const result = phaseResults[0];
154
+ if (result && result.status === "completed") {
155
+ supervisor.assignAgent(phase.phase.name, result.agentId ?? phase.phase.name);
156
+ supervisor.completePhase(phase.phase.name, result.result ?? "");
157
+ }
158
+ else if (result) {
159
+ supervisor.failPhase(phase.phase.name, result.error ?? "Unknown error");
160
+ }
161
+ currentPhase = supervisor.startNextPhase();
162
+ }
163
+ // Finalize and render
164
+ supervisor.finalize();
165
+ const output = supervisor.synthesizeResult();
166
+ return {
167
+ content: [{ type: "text", text: output }],
168
+ details: undefined,
169
+ };
170
+ }
171
+ catch (error) {
172
+ const message = error instanceof Error
173
+ ? error.message
174
+ : String(error);
175
+ // Return partial state if available
176
+ if (supervisor) {
177
+ try {
178
+ const partialOutput = supervisor.synthesizeResult();
179
+ if (partialOutput) {
180
+ return {
181
+ content: [
182
+ {
183
+ type: "text",
184
+ text: `${partialOutput}\n\nRun interrupted: ${message}`,
185
+ },
186
+ ],
187
+ isError: true,
188
+ details: undefined,
189
+ };
190
+ }
191
+ }
192
+ catch {
193
+ // Synthesis failed — fall through to generic error
194
+ }
195
+ }
196
+ return {
197
+ content: [
198
+ {
199
+ type: "text",
200
+ text: `AgentTeam failed: ${message}`,
201
+ },
202
+ ],
203
+ isError: true,
204
+ details: undefined,
205
+ };
206
+ }
207
+ },
208
+ });
209
+ }
210
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/team/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACL,uBAAuB,GAExB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,aAAa,EACb,cAAc,EACd,aAAa,GACd,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMjD,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,2BAA2B,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnD,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;8EAa+C,CAAC;AAE/E,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E,MAAM,UAAU,qBAAqB,CACnC,EAAgB;IAEhB,EAAE,CAAC,YAAY,CAAC;QACd,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE,YAAY;QACnB,WAAW,EAAE,sBAAsB;QACnC,UAAU,EAAE,IAAI,CAAC,MAAM,CACrB;YACE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;gBAChB,WAAW,EAAE,+BAA+B;aAC7C,CAAC;YACF,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC;gBACvB,WAAW,EACT,qCAAqC;aACxC,CAAC;YACF,MAAM,EAAE,IAAI,CAAC,QAAQ,CACnB,IAAI,CAAC,KA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,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oBACzC,OAAO,EAAE,SAAS;iBACnB,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,GACX,KAAK,YAAY,KAAK;oBACpB,CAAC,CAAC,KAAK,CAAC,OAAO;oBACf,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACpB,oCAAoC;gBACpC,IAAI,UAAU,EAAE,CAAC;oBACf,IAAI,CAAC;wBACH,MAAM,aAAa,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC;wBACpD,IAAI,aAAa,EAAE,CAAC;4BAClB,OAAO;gCACL,OAAO,EAAE;oCACP;wCACE,IAAI,EAAE,MAAM;wCACZ,IAAI,EAAE,GAAG,aAAa,wBAAwB,OAAO,EAAE;qCACxD;iCACF;gCACD,OAAO,EAAE,IAAI;gCACb,OAAO,EAAE,SAAS;6BACnB,CAAC;wBACJ,CAAC;oBACH,CAAC;oBAAC,MAAM,CAAC;wBACP,mDAAmD;oBACrD,CAAC;gBACH,CAAC;gBACD,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,qBAAqB,OAAO,EAAE;yBACrC;qBACF;oBACD,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE,SAAS;iBACnB,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * tui/permission-prompt — swarm start permission dialog for manual mode.
3
+ *
4
+ * When the user is in manual permission mode and tries to start a
5
+ * swarm, this component asks whether to switch to auto/yolo or cancel.
6
+ *
7
+ * Ported from MoonshotAI/kimi-code's SwarmStartPermissionPromptComponent.
8
+ */
9
+ import type { Component } from "@earendil-works/pi-tui";
10
+ export type SwarmPermissionChoice = "auto" | "yolo" | "cancel";
11
+ export interface SwarmPermissionPromptOptions {
12
+ /** Called when the user makes a selection. */
13
+ onSelect: (choice: SwarmPermissionChoice) => void;
14
+ /** Called when the user cancels (Escape). */
15
+ onCancel: () => void;
16
+ }
17
+ export declare class SwarmPermissionPromptComponent implements Component {
18
+ private readonly opts;
19
+ private selectedIndex;
20
+ private readonly choices;
21
+ constructor(opts: SwarmPermissionPromptOptions);
22
+ handleInput(data: string): void;
23
+ invalidate(): void;
24
+ render(width: number): string[];
25
+ }
26
+ //# sourceMappingURL=permission-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-prompt.d.ts","sourceRoot":"","sources":["../../src/tui/permission-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAMxD,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE/D,MAAM,WAAW,4BAA4B;IAC3C,8CAA8C;IAC9C,QAAQ,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAClD,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAMD,qBAAa,8BAA+B,YAAW,SAAS;IAQlD,OAAO,CAAC,QAAQ,CAAC,IAAI;IAPjC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAItB;gBAE2B,IAAI,EAAE,4BAA4B;IAE/D,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAwB/B,UAAU,IAAI,IAAI;IAIlB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;CA4BhC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * tui/permission-prompt — swarm start permission dialog for manual mode.
3
+ *
4
+ * When the user is in manual permission mode and tries to start a
5
+ * swarm, this component asks whether to switch to auto/yolo or cancel.
6
+ *
7
+ * Ported from MoonshotAI/kimi-code's SwarmStartPermissionPromptComponent.
8
+ */
9
+ // ---------------------------------------------------------------------------
10
+ // Component
11
+ // ---------------------------------------------------------------------------
12
+ export class SwarmPermissionPromptComponent {
13
+ opts;
14
+ selectedIndex = 0;
15
+ choices = [
16
+ "auto",
17
+ "yolo",
18
+ "cancel",
19
+ ];
20
+ constructor(opts) {
21
+ this.opts = opts;
22
+ }
23
+ handleInput(data) {
24
+ if (data === "\x1b[A" || data === "k") {
25
+ // Up arrow or 'k'
26
+ this.selectedIndex = Math.max(0, this.selectedIndex - 1);
27
+ this.invalidate();
28
+ }
29
+ else if (data === "\x1b[B" || data === "j") {
30
+ // Down arrow or 'j'
31
+ this.selectedIndex = Math.min(this.choices.length - 1, this.selectedIndex + 1);
32
+ this.invalidate();
33
+ }
34
+ else if (data === "\r" || data === "\n") {
35
+ // Enter
36
+ const choice = this.choices[this.selectedIndex];
37
+ if (choice) {
38
+ this.opts.onSelect(choice);
39
+ }
40
+ }
41
+ else if (data === "\x1b") {
42
+ // Escape
43
+ this.opts.onCancel();
44
+ }
45
+ }
46
+ invalidate() {
47
+ // No cached state to clear — render is pure.
48
+ }
49
+ render(width) {
50
+ const safeWidth = Math.max(10, width);
51
+ const lines = [];
52
+ lines.push(borderTop(safeWidth));
53
+ lines.push(padLine("Manual mode can block swarm work.", safeWidth));
54
+ lines.push(padLine("", safeWidth));
55
+ lines.push(padLine("Choose a permission mode for this swarm:", safeWidth));
56
+ lines.push(padLine("", safeWidth));
57
+ for (let i = 0; i < this.choices.length; i += 1) {
58
+ const choice = this.choices[i];
59
+ const isSelected = i === this.selectedIndex;
60
+ const prefix = isSelected ? " > " : " ";
61
+ const label = choiceLabel(choice);
62
+ lines.push(padLine(`${prefix}${label}`, safeWidth));
63
+ }
64
+ lines.push(padLine("", safeWidth));
65
+ lines.push(padLine("Use arrow keys to select, Enter to confirm, Esc to cancel.", safeWidth));
66
+ lines.push(borderBottom(safeWidth));
67
+ return lines;
68
+ }
69
+ }
70
+ // ---------------------------------------------------------------------------
71
+ // Helpers
72
+ // ---------------------------------------------------------------------------
73
+ function choiceLabel(choice) {
74
+ switch (choice) {
75
+ case "auto":
76
+ return "Auto mode — tools auto-approved, including AgentSwarm";
77
+ case "yolo":
78
+ return "YOLO mode — all tools auto-approved, no confirmations";
79
+ case "cancel":
80
+ return "Cancel — do not start the swarm";
81
+ }
82
+ }
83
+ function borderTop(width) {
84
+ return `\u250C${"\u2500".repeat(Math.max(0, width - 2))}\u2510`;
85
+ }
86
+ function borderBottom(width) {
87
+ return `\u2514${"\u2500".repeat(Math.max(0, width - 2))}\u2518`;
88
+ }
89
+ function padLine(text, width) {
90
+ const inner = `\u2502 ${text}`;
91
+ const padding = Math.max(0, width - inner.length - 1);
92
+ return `${inner}${" ".repeat(padding)}\u2502`;
93
+ }
94
+ //# sourceMappingURL=permission-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-prompt.js","sourceRoot":"","sources":["../../src/tui/permission-prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiBH,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,MAAM,OAAO,8BAA8B;IAQZ;IAPrB,aAAa,GAAG,CAAC,CAAC;IACT,OAAO,GAAqC;QAC3D,MAAM;QACN,MAAM;QACN,QAAQ;KACT,CAAC;IAEF,YAA6B,IAAkC;QAAlC,SAAI,GAAJ,IAAI,CAA8B;IAAG,CAAC;IAEnE,WAAW,CAAC,IAAY;QACtB,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACtC,kBAAkB;YAClB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;YACzD,IAAI,CAAC,UAAU,EAAE,CAAC;QACpB,CAAC;aAAM,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YAC7C,oBAAoB;YACpB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,CAC3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,CAAC,IAAY,EAAE,KAAa;IAC1C,MAAM,KAAK,GAAG,UAAU,IAAI,EAAE,CAAC;IAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACtD,OAAO,GAAG,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;AAChD,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * tui/progress — AgentSwarm live progress panel.
3
+ *
4
+ * Renders a real-time progress display above the input area when
5
+ * an AgentSwarm batch is running. Each subagent gets a braille
6
+ * progress bar with status labels.
7
+ *
8
+ * Ported from MoonshotAI/kimi-code's AgentSwarmProgressComponent.
9
+ */
10
+ import type { Component } from "@earendil-works/pi-tui";
11
+ /** Phase of a single member (subagent) in the progress display. */
12
+ export type MemberPhase = "pending" | "queued" | "prompting" | "working" | "completed" | "failed" | "cancelled" | "suspended";
13
+ /** Status of a single member. */
14
+ export interface MemberStatus {
15
+ /** 1-based index. */
16
+ readonly index: number;
17
+ /** Current phase. */
18
+ phase: MemberPhase;
19
+ /** Label for the item being processed. */
20
+ item?: string;
21
+ /** Result text (for completed/failed). */
22
+ result?: string;
23
+ /** Error message (for failed). */
24
+ error?: string;
25
+ /** When the member transitioned to its current phase (ms timestamp). */
26
+ phaseStartedAt?: number;
27
+ }
28
+ /** Overall swarm status pushed from the tool execution. */
29
+ export interface SwarmProgressState {
30
+ /** Title for the progress panel. */
31
+ title?: string;
32
+ /** Overall status label. */
33
+ status?: string;
34
+ /** Total number of subagents. */
35
+ total: number;
36
+ /** Completed count. */
37
+ completed: number;
38
+ /** Failed count. */
39
+ failed: number;
40
+ /** Currently active count. */
41
+ active: number;
42
+ /** Queued count. */
43
+ queued: number;
44
+ /** Per-member status. */
45
+ members: MemberStatus[];
46
+ }
47
+ export declare class AgentSwarmProgressComponent implements Component {
48
+ private state_;
49
+ private animationFrame;
50
+ private startTime;
51
+ private renderedWidth;
52
+ private cachedLines;
53
+ constructor();
54
+ /** Update the progress state from the tool execution. */
55
+ update(state: SwarmProgressState): void;
56
+ /** Mark the swarm as completed (triggers completion animation). */
57
+ complete(): void;
58
+ /** Stop the animation loop. */
59
+ dispose(): void;
60
+ invalidate(): void;
61
+ render(width: number): string[];
62
+ private startAnimation;
63
+ }
64
+ //# sourceMappingURL=progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/tui/progress.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAkDxD,mEAAmE;AACnE,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,QAAQ,GACR,WAAW,GACX,SAAS,GACT,WAAW,GACX,QAAQ,GACR,WAAW,GACX,WAAW,CAAC;AAEhB,iCAAiC;AACjC,MAAM,WAAW,YAAY;IAC3B,qBAAqB;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,qBAAqB;IACrB,KAAK,EAAE,WAAW,CAAC;IACnB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,2DAA2D;AAC3D,MAAM,WAAW,kBAAkB;IACjC,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,uBAAuB;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,MAAM,EAAE,MAAM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