@arhen/pi-core-subagent 1.0.1 → 1.0.3

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +22 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arhen/pi-core-subagent",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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
@@ -385,8 +385,23 @@ class SubagentManager {
385
385
  private widgetTimer: ReturnType<typeof setTimeout> | undefined;
386
386
  private widgetRun: RunSnapshot | undefined;
387
387
 
388
+ turnActivity = false;
389
+
388
390
  constructor(private readonly pi: ExtensionAPI) {}
389
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
+
390
405
  listRuns(): RunSnapshot[] {
391
406
  return Array.from(this.runs.values()).sort((a, b) => b.createdAt - a.createdAt);
392
407
  }
@@ -812,6 +827,7 @@ class SubagentManager {
812
827
  task.roster = roster;
813
828
  }
814
829
  run.tasks.forEach((t) => (t.runId = run.id));
830
+ this.turnActivity = true;
815
831
  this.runs.set(run.id, run);
816
832
  this.settlers.set(run.id, () => {});
817
833
  this.runControllers.set(run.id, new AbortController());
@@ -859,6 +875,7 @@ class SubagentManager {
859
875
  run.status = aborted ? "aborted" : failed ? "failed" : "completed";
860
876
  run.endedAt = Date.now();
861
877
  this.flushWidget(ctx, onUpdate);
878
+ this.clearWidget(ctx); // run is done — drop the widget immediately
862
879
  this.emit("subagent:run-completed", { runId: run.id, status: run.status, run: cloneRun(run), aggregateUsage: run.aggregateUsage });
863
880
  this.settleRun(run.id, run);
864
881
  this.runControllers.delete(run.id);
@@ -1036,6 +1053,11 @@ export default function (pi: ExtensionAPI) {
1036
1053
  },
1037
1054
  });
1038
1055
 
1056
+ pi.on("agent_start", (_event, ctx) => {
1057
+ if (!manager.turnActivity) manager.clearWidget(ctx);
1058
+ manager.turnActivity = false;
1059
+ });
1060
+
1039
1061
  pi.on("session_start", async (_event, ctx) => {
1040
1062
  await manager.restoreFromSidecar(ctx);
1041
1063
  });