pi-crew 0.1.12 → 0.1.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-crew",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Pi extension for coordinated AI teams, workflows, worktrees, and async task orchestration",
5
5
  "author": "baphuongna",
6
6
  "license": "MIT",
@@ -100,15 +100,38 @@ function setNestedConfig(config: Record<string, unknown>, key: string, value: un
100
100
  }
101
101
 
102
102
  export function registerPiTeams(pi: ExtensionAPI): void {
103
+ const globalStore = globalThis as Record<string, unknown>;
104
+ const runtimeCleanupStoreKey = "__piCrewRuntimeCleanup";
105
+ const previousRuntimeCleanup = globalStore[runtimeCleanupStoreKey];
106
+ if (typeof previousRuntimeCleanup === "function") {
107
+ try { previousRuntimeCleanup(); } catch {}
108
+ }
103
109
  const notifierState: AsyncNotifierState = { seenFinishedRunIds: new Set() };
104
110
  let currentCtx: ExtensionContext | undefined;
105
111
  let rpcHandle: PiCrewRpcHandle | undefined;
112
+ let cleanedUp = false;
106
113
  const widgetState: CrewWidgetState = { frame: 0 };
107
114
  const foregroundControllers = new Set<AbortController>();
108
115
  registerAutonomousPolicy(pi);
109
116
  rpcHandle = registerPiCrewRpc((pi as unknown as { events?: Parameters<typeof registerPiCrewRpc>[0] }).events, () => currentCtx);
117
+ const cleanupRuntime = (): void => {
118
+ if (cleanedUp) return;
119
+ cleanedUp = true;
120
+ for (const controller of foregroundControllers) controller.abort();
121
+ foregroundControllers.clear();
122
+ terminateActiveChildPiProcesses();
123
+ stopAsyncRunNotifier(notifierState);
124
+ stopCrewWidget(currentCtx, widgetState, currentCtx ? loadConfig(currentCtx.cwd).config.ui : undefined);
125
+ clearPiCrewPowerbar(pi.events);
126
+ rpcHandle?.unsubscribe();
127
+ rpcHandle = undefined;
128
+ currentCtx = undefined;
129
+ if (globalStore[runtimeCleanupStoreKey] === cleanupRuntime) delete globalStore[runtimeCleanupStoreKey];
130
+ };
131
+ globalStore[runtimeCleanupStoreKey] = cleanupRuntime;
110
132
 
111
133
  pi.on("session_start", (_event, ctx) => {
134
+ cleanedUp = false;
112
135
  currentCtx = ctx;
113
136
  notifyActiveRuns(ctx);
114
137
  const loadedConfig = loadConfig(ctx.cwd);
@@ -125,14 +148,7 @@ export function registerPiTeams(pi: ExtensionAPI): void {
125
148
  widgetState.interval.unref?.();
126
149
  });
127
150
  pi.on("session_shutdown", () => {
128
- for (const controller of foregroundControllers) controller.abort();
129
- terminateActiveChildPiProcesses();
130
- stopAsyncRunNotifier(notifierState);
131
- stopCrewWidget(currentCtx, widgetState, currentCtx ? loadConfig(currentCtx.cwd).config.ui : undefined);
132
- clearPiCrewPowerbar(pi.events);
133
- currentCtx = undefined;
134
- rpcHandle?.unsubscribe();
135
- rpcHandle = undefined;
151
+ cleanupRuntime();
136
152
  });
137
153
 
138
154
  const tool: ToolDefinition = {
@@ -160,6 +160,7 @@ export async function executeTeamRun(input: ExecuteTeamRunInput): Promise<{ mani
160
160
  if (failed) {
161
161
  tasks = markBlocked(tasks, `Blocked by failed task '${failed.id}'.`);
162
162
  saveRunTasks(manifest, tasks);
163
+ saveCrewAgents(manifest, tasks.map((task) => recordFromTask(manifest, task, runtimeKind)));
163
164
  manifest = updateRunStatus(manifest, "failed", `Failed at task '${failed.id}'.`);
164
165
  return { manifest, tasks };
165
166
  }
@@ -169,6 +170,7 @@ export async function executeTeamRun(input: ExecuteTeamRunInput): Promise<{ mani
169
170
  if (readyBatch.length === 0) {
170
171
  tasks = markBlocked(tasks, "No ready queued task; dependency graph may be invalid.");
171
172
  saveRunTasks(manifest, tasks);
173
+ saveCrewAgents(manifest, tasks.map((task) => recordFromTask(manifest, task, runtimeKind)));
172
174
  manifest = updateRunStatus(manifest, "blocked", "No ready queued task.");
173
175
  return { manifest, tasks };
174
176
  }
@@ -108,9 +108,18 @@ function activeWidgetRuns(cwd: string): WidgetRun[] {
108
108
  }
109
109
 
110
110
  function statusSummary(runs: WidgetRun[]): string {
111
- const runningAgents = runs.flatMap((item) => item.agents).filter((agent) => agent.status === "running").length;
112
- const queuedAgents = runs.flatMap((item) => item.agents).filter((agent) => agent.status === "queued").length;
113
- return `● pi-crew · runs=${runs.length} agents=${runningAgents} running${queuedAgents ? ` · ${queuedAgents} queued` : ""} · /team-dashboard`;
111
+ const agents = runs.flatMap((item) => item.agents);
112
+ const runningAgents = agents.filter((agent) => agent.status === "running").length;
113
+ const queuedAgents = agents.filter((agent) => agent.status === "queued").length;
114
+ const completedAgents = agents.filter((agent) => agent.status === "completed").length;
115
+ const parts = [`${runningAgents} running`];
116
+ if (queuedAgents) parts.push(`${queuedAgents} queued`);
117
+ if (completedAgents) parts.push(`${completedAgents}/${agents.length} done`);
118
+ return `⚙ pi-crew · ${parts.join(" · ")} · /team-dashboard`;
119
+ }
120
+
121
+ function shortRunLabel(run: TeamRunManifest): string {
122
+ return `${run.team}/${run.workflow ?? "none"}`;
114
123
  }
115
124
 
116
125
  export function buildCrewWidgetLines(cwd: string, frame = 0, maxLines = 8): string[] {
@@ -119,15 +128,12 @@ export function buildCrewWidgetLines(cwd: string, frame = 0, maxLines = 8): stri
119
128
  const runningGlyph = SPINNER[frame % SPINNER.length] ?? "⠋";
120
129
  const lines: string[] = [statusSummary(runs)];
121
130
  for (const { run, agents } of runs) {
122
- const running = agents.find((agent) => agent.status === "running");
123
- const queued = agents.find((agent) => agent.status === "queued");
124
- const step = running?.taskId ?? queued?.taskId ?? run.status;
125
- const completed = agents.filter((agent) => agent.status === "completed").length;
126
- lines.push(`${glyph(run.status, runningGlyph)} ${run.runId.slice(-8)} ${run.team}/${run.workflow ?? "none"} · ${step} · ${completed}/${agents.length} done`);
127
131
  const activeAgents = agents.filter((item) => item.status === "running" || item.status === "queued");
132
+ const completed = agents.filter((agent) => agent.status === "completed").length;
133
+ lines.push(`${glyph(run.status, runningGlyph)} ${shortRunLabel(run)} · ${completed}/${agents.length} done · ${run.runId.slice(-8)}`);
128
134
  for (const agent of activeAgents.slice(0, 3)) {
129
135
  const stats = agentStats(agent);
130
- lines.push(` ${glyph(agent.status, runningGlyph)} ${agent.taskId} ${agent.role}→${agent.agent} · ${agentActivity(agent)}${stats ? ` · ${stats}` : ""}`);
136
+ lines.push(` ${glyph(agent.status, runningGlyph)} ${agent.agent} (${agent.role}) · ${agentActivity(agent)}${stats ? ` · ${stats}` : ""}`);
131
137
  }
132
138
  if (activeAgents.length > 3) lines.push(` … +${activeAgents.length - 3} more agents`);
133
139
  if (lines.length >= maxLines) break;
@@ -153,7 +159,7 @@ class CrewWidgetComponent implements WidgetComponent {
153
159
  const bold = this.theme.bold?.bind(this.theme) ?? ((text: string) => text);
154
160
  return buildCrewWidgetLines(this.cwd, this.frame, this.maxLines).map((line, index) => {
155
161
  const colored = index === 0
156
- ? line.replace(" pi-crew", `${fg("accent", "")} ${bold("pi-crew")}`)
162
+ ? line.replace(" pi-crew", `${fg("accent", "")} ${bold("pi-crew")}`)
157
163
  : line.replace(/^\s*([⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏▶◦✓✗■·])/, (match, icon: string) => match.replace(icon, fg(icon === "✓" ? "success" : icon === "✗" ? "error" : icon === "◦" ? "dim" : "accent", icon)));
158
164
  return truncate(colored, width);
159
165
  });