@giladbarnea/pi-simple-team 2.0.15 → 2.0.16

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/README.md CHANGED
@@ -148,6 +148,7 @@ Your main uses `team_log` when it needs to understand the chain of events in hig
148
148
 
149
149
  Provides main a timestamped, filterable, append-only record of the team’s messages, tool calls, and lifecycle events.
150
150
  Attempts can end before retries finish. A separate run row reports final settlement as ended or cancelled. Ended does not imply success.
151
+ A run that ends on a provider error adds an error row with the provider's message and sets the teammate's status to `error` with that message, until a later run completes.
151
152
 
152
153
  ### 🌅 Herdr Support
153
154
 
package/child-tools.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as http from "node:http";
2
- import { defineTool, getMarkdownTheme, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { defineTool, getMarkdownTheme, type AgentActivityOutcome, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
3
3
  import { Type } from "typebox";
4
4
  import { formatContextWindowReport, requireKnownContextUsage } from "./context-window.ts";
5
5
  import { formatModelReference } from "./model-preflight.ts";
@@ -146,6 +146,7 @@ function startChildRuntime(pi: ExtensionAPI, config: ChildRuntimeConfig): void {
146
146
  let idleWaiters: Array<() => void> = [];
147
147
  let lifecycleQueue: Promise<void> = Promise.resolve();
148
148
  let lifecycleError: Error | undefined;
149
+ let lastTurnOutcome: { outcome: AgentActivityOutcome; errorMessage?: string } = { outcome: "completed" };
149
150
 
150
151
  const notifyParent = (event: JsonRecord): Promise<void> => {
151
152
  lifecycleQueue = lifecycleQueue.then(async () => {
@@ -189,17 +190,22 @@ function startChildRuntime(pi: ExtensionAPI, config: ChildRuntimeConfig): void {
189
190
  pi.on("agent_start", (event, context) => {
190
191
  idle = false;
191
192
  activeContext = context;
193
+ lastTurnOutcome = { outcome: "completed" };
192
194
  notifyParent({ type: "agent_start" });
193
195
  });
194
196
  pi.on("agent_end", (event) => {
195
197
  notifyParent({ type: "agent_end", messages: event.messages });
196
198
  });
199
+ /** Pi settles a run on its last turn's outcome, so a retried attempt that then succeeds settles as completed. */
197
200
  pi.on("agent_settled", (event) => {
198
- notifyParent({ type: "agent_settled", aborted: event.aborted });
201
+ notifyParent({ type: "agent_settled", aborted: event.aborted, ...lastTurnOutcome });
199
202
  markIdle();
200
203
  });
201
204
  const reportRuntimeFacts = (context: ExtensionContext): Promise<void> => notifyParent({ type: "runtime_facts", ...runtimeFacts(context) });
202
- pi.on("turn_end", (_event, context) => { void reportRuntimeFacts(context); });
205
+ pi.on("turn_end", (event, context) => {
206
+ lastTurnOutcome = { outcome: event.outcome, errorMessage: event.message.role === "assistant" ? event.message.errorMessage : undefined };
207
+ void reportRuntimeFacts(context);
208
+ });
203
209
  pi.on("session_compact", (_event, context) => { void reportRuntimeFacts(context); });
204
210
  pi.on("model_select", (_event, context) => { void reportRuntimeFacts(context); });
205
211
  pi.on("thinking_level_select", (_event, context) => { void reportRuntimeFacts(context); });
package/index.ts CHANGED
@@ -42,6 +42,12 @@ interface TeamStatus {
42
42
 
43
43
  type TeammateTransport = "rpc" | "herdr";
44
44
 
45
+ /** The error status a failed run set, and the status it replaced. */
46
+ interface RunFailure {
47
+ failure: TeamStatus;
48
+ replaced: TeamStatus;
49
+ }
50
+
45
51
  interface TeammateState {
46
52
  name: string;
47
53
  prompt: string;
@@ -64,6 +70,7 @@ interface TeammateState {
64
70
  alive: boolean;
65
71
  active: boolean;
66
72
  contextPercent?: number;
73
+ runFailure?: RunFailure;
67
74
  pendingTurnDeliveries: number;
68
75
  deliveryQueue: Promise<void>;
69
76
  }
@@ -795,9 +802,30 @@ function applyRuntimeFacts(teammate: TeammateState, facts: JsonRecord): void {
795
802
  teammate.contextPercent = (facts.contextPercent as number | null) ?? undefined;
796
803
  }
797
804
 
805
+ /**
806
+ * A failed run shows through the same error status and log row as a failed delivery. A later completed run restores the status the failure replaced, unless the teammate has set its own since.
807
+ * A cancelled run is neither: Pi can record an aborted run's last turn as an error, so the final cancellation flag decides.
808
+ */
809
+ function recordRunOutcome(team: TeamState, teammate: TeammateState, event: JsonRecord): void {
810
+ if (event.aborted === true) return;
811
+ const current = team.statuses.get(teammate.name)!;
812
+ if (event.outcome === "error") {
813
+ const errorMessage = String(event.errorMessage);
814
+ const failure = status("error", errorMessage);
815
+ teammate.runFailure = { failure, replaced: current === teammate.runFailure?.failure ? teammate.runFailure.replaced : current };
816
+ team.statuses.set(teammate.name, failure);
817
+ appendTeamLog(team, { team: team.name, teammate: teammate.name, direction: "runtime", kind: "error", summary: preview(`${teammate.name} run failed: ${errorMessage}`), details: { error: errorMessage } });
818
+ return;
819
+ }
820
+ if (event.outcome !== "completed" || !teammate.runFailure) return;
821
+ if (current === teammate.runFailure.failure) team.statuses.set(teammate.name, teammate.runFailure.replaced);
822
+ teammate.runFailure = undefined;
823
+ }
824
+
798
825
  function handleChildEvent(team: TeamState, teammate: TeammateState, event: JsonRecord): void {
799
826
  if (event.type === "agent_start" || event.type === "work_queued") teammate.active = true;
800
827
  if (event.type === "agent_settled" || event.type === "session_shutdown") teammate.active = false;
828
+ if (event.type === "agent_settled") recordRunOutcome(team, teammate, event);
801
829
  if (event.type === "runtime_facts") applyRuntimeFacts(teammate, event);
802
830
  if (event.type === "session_shutdown") {
803
831
  teammate.alive = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-simple-team",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "description": "A flat, live team of Pi agents.",
5
5
  "keywords": [
6
6
  "pi-package",