@arhen/pi-core-subagent 1.0.0 → 1.0.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.
- package/package.json +1 -1
- package/src/index.ts +26 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arhen/pi-core-subagent",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "pi extension: fast in-process subagents with single/parallel/chain, background runs, intercom and agent-to-agent mailbox. Leader defines agents inline.",
|
|
6
6
|
"license": "MIT",
|
package/src/index.ts
CHANGED
|
@@ -268,6 +268,7 @@ class SubagentsWidget implements Component {
|
|
|
268
268
|
const active = !TERMINAL.includes(run.status);
|
|
269
269
|
const head = active ? "accent" : "dim";
|
|
270
270
|
const lines = [truncateToWidth(`${this.theme.fg(head, active ? "●" : "○")} ${this.theme.fg(head, `Subagents (${done}/${run.tasks.length})`)}`, width, "…")];
|
|
271
|
+
const allDone = TERMINAL.includes(run.status);
|
|
271
272
|
const visible = run.tasks.slice(0, MAX_TASKS);
|
|
272
273
|
visible.forEach((task, i) => {
|
|
273
274
|
const last = i === visible.length - 1 && run.tasks.length <= MAX_TASKS;
|
|
@@ -276,7 +277,10 @@ class SubagentsWidget implements Component {
|
|
|
276
277
|
!TERMINAL.includes(task.status) && task.lastActivity
|
|
277
278
|
? `${this.theme.fg("dim", `→ ${task.lastActivity}`)} · `
|
|
278
279
|
: "";
|
|
279
|
-
|
|
280
|
+
// Completed run: dim everything except the agent name.
|
|
281
|
+
const line = allDone
|
|
282
|
+
? `${this.theme.fg("dim", `${statusIcon(task.status)} `)}${task.agent} ${this.theme.fg("dim", `· ${taskStatsWithUsage(task)} · ${taskTimer(task)}`)}`
|
|
283
|
+
: `${statusIcon(task.status)} ${task.agent} · ${activity}${taskStatsWithUsage(task)} · ${taskTimer(task)}`;
|
|
280
284
|
lines.push(truncateToWidth(`${conn} ${line}`, width, "…"));
|
|
281
285
|
});
|
|
282
286
|
if (run.tasks.length > MAX_TASKS) lines.push(`${this.theme.fg("dim", "└─")} ${this.theme.fg("dim", `+${run.tasks.length - MAX_TASKS} more`)}`);
|
|
@@ -381,8 +385,23 @@ class SubagentManager {
|
|
|
381
385
|
private widgetTimer: ReturnType<typeof setTimeout> | undefined;
|
|
382
386
|
private widgetRun: RunSnapshot | undefined;
|
|
383
387
|
|
|
388
|
+
turnActivity = false;
|
|
389
|
+
|
|
384
390
|
constructor(private readonly pi: ExtensionAPI) {}
|
|
385
391
|
|
|
392
|
+
/** Hide the widget. Call on agent_start when the turn made no subagent calls. */
|
|
393
|
+
clearWidget(ctx: ExtensionContext): void {
|
|
394
|
+
this.widgetRun = undefined;
|
|
395
|
+
this.widgetTui = null;
|
|
396
|
+
if (ctx.hasUI) {
|
|
397
|
+
try {
|
|
398
|
+
ctx.ui.setWidget("subagents", undefined);
|
|
399
|
+
} catch {
|
|
400
|
+
/* ignore */
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
386
405
|
listRuns(): RunSnapshot[] {
|
|
387
406
|
return Array.from(this.runs.values()).sort((a, b) => b.createdAt - a.createdAt);
|
|
388
407
|
}
|
|
@@ -808,6 +827,7 @@ class SubagentManager {
|
|
|
808
827
|
task.roster = roster;
|
|
809
828
|
}
|
|
810
829
|
run.tasks.forEach((t) => (t.runId = run.id));
|
|
830
|
+
this.turnActivity = true;
|
|
811
831
|
this.runs.set(run.id, run);
|
|
812
832
|
this.settlers.set(run.id, () => {});
|
|
813
833
|
this.runControllers.set(run.id, new AbortController());
|
|
@@ -1032,6 +1052,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
1032
1052
|
},
|
|
1033
1053
|
});
|
|
1034
1054
|
|
|
1055
|
+
pi.on("agent_start", (_event, ctx) => {
|
|
1056
|
+
if (!manager.turnActivity) manager.clearWidget(ctx);
|
|
1057
|
+
manager.turnActivity = false;
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1035
1060
|
pi.on("session_start", async (_event, ctx) => {
|
|
1036
1061
|
await manager.restoreFromSidecar(ctx);
|
|
1037
1062
|
});
|