@giladbarnea/pi-simple-team 2.0.15 → 2.0.17

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
  }
@@ -117,6 +124,46 @@ function toolResult(payload: JsonRecord, viewDetails: JsonRecord = {}) {
117
124
  };
118
125
  }
119
126
 
127
+ const reminderSlugWords = {
128
+ adjectives: ["amber", "brisk", "calm", "clever", "dusty", "eager", "fuzzy", "gentle", "golden", "hollow", "jolly", "lively", "mellow", "misty", "nimble", "plucky", "quiet", "rapid", "rusty", "silver", "steady", "sunny", "swift", "witty"],
129
+ nouns: ["badger", "beacon", "cedar", "comet", "falcon", "fern", "harbor", "heron", "lantern", "maple", "meadow", "otter", "pebble", "pine", "quail", "raven", "river", "robin", "sparrow", "spruce", "thistle", "tulip", "walrus", "willow"],
130
+ } as const;
131
+
132
+ /** A random two-word label that ties a reminder's wake message to its arming. */
133
+ function reminderSlug(): string {
134
+ const pick = (words: readonly string[]): string => words[crypto.randomInt(words.length)]!;
135
+ return `${pick(reminderSlugWords.adjectives)}-${pick(reminderSlugWords.nouns)}`;
136
+ }
137
+
138
+ /**
139
+ * Formats a moment in the process time zone, with the time zone name the runtime's English locale data provides.
140
+ * @example humanTime(new Date("2026-11-07T08:47:00Z")) // with TZ=Asia/Jerusalem: "Nov 7, 2026, 10:47am GMT+2"
141
+ */
142
+ function humanTime(moment: Date): string {
143
+ const parts = Object.fromEntries(
144
+ new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit", hour12: true, timeZoneName: "short" })
145
+ .formatToParts(moment)
146
+ .map((part) => [part.type, part.value]),
147
+ ) as Record<Intl.DateTimeFormatPartTypes, string>;
148
+ return `${parts.month} ${parts.day}, ${parts.year}, ${parts.hour}:${parts.minute}${parts.dayPeriod.toLowerCase()} ${parts.timeZoneName}`;
149
+ }
150
+
151
+ /**
152
+ * @example humanDuration(3665) // "1h, 1m and 5s"
153
+ * @example humanDuration(2700) // "45m"
154
+ * @example humanDuration(0) // "0s"
155
+ */
156
+ function humanDuration(totalSeconds: number): string {
157
+ const units = [
158
+ [Math.floor(totalSeconds / 3600), "h"],
159
+ [Math.floor((totalSeconds % 3600) / 60), "m"],
160
+ [totalSeconds % 60, "s"],
161
+ ] as const;
162
+ const parts = units.filter(([count]) => count > 0).map(([count, unit]) => `${count}${unit}`);
163
+ if (parts.length === 0) return "0s";
164
+ return parts.length === 1 ? parts[0]! : `${parts.slice(0, -1).join(", ")} and ${parts.at(-1)}`;
165
+ }
166
+
120
167
  /** @example teamIdentity({ name: "review", id: "session-review" }) // { teamName: "review", teamId: "session-review" } */
121
168
  function teamIdentity(team: { name: string; id?: string }): { teamName: string; teamId: string } {
122
169
  return { teamName: team.name, teamId: team.id ?? team.name };
@@ -795,9 +842,30 @@ function applyRuntimeFacts(teammate: TeammateState, facts: JsonRecord): void {
795
842
  teammate.contextPercent = (facts.contextPercent as number | null) ?? undefined;
796
843
  }
797
844
 
845
+ /**
846
+ * 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.
847
+ * A cancelled run is neither: Pi can record an aborted run's last turn as an error, so the final cancellation flag decides.
848
+ */
849
+ function recordRunOutcome(team: TeamState, teammate: TeammateState, event: JsonRecord): void {
850
+ if (event.aborted === true) return;
851
+ const current = team.statuses.get(teammate.name)!;
852
+ if (event.outcome === "error") {
853
+ const errorMessage = String(event.errorMessage);
854
+ const failure = status("error", errorMessage);
855
+ teammate.runFailure = { failure, replaced: current === teammate.runFailure?.failure ? teammate.runFailure.replaced : current };
856
+ team.statuses.set(teammate.name, failure);
857
+ appendTeamLog(team, { team: team.name, teammate: teammate.name, direction: "runtime", kind: "error", summary: preview(`${teammate.name} run failed: ${errorMessage}`), details: { error: errorMessage } });
858
+ return;
859
+ }
860
+ if (event.outcome !== "completed" || !teammate.runFailure) return;
861
+ if (current === teammate.runFailure.failure) team.statuses.set(teammate.name, teammate.runFailure.replaced);
862
+ teammate.runFailure = undefined;
863
+ }
864
+
798
865
  function handleChildEvent(team: TeamState, teammate: TeammateState, event: JsonRecord): void {
799
866
  if (event.type === "agent_start" || event.type === "work_queued") teammate.active = true;
800
867
  if (event.type === "agent_settled" || event.type === "session_shutdown") teammate.active = false;
868
+ if (event.type === "agent_settled") recordRunOutcome(team, teammate, event);
801
869
  if (event.type === "runtime_facts") applyRuntimeFacts(teammate, event);
802
870
  if (event.type === "session_shutdown") {
803
871
  teammate.alive = false;
@@ -1162,17 +1230,23 @@ export default function (pi: ExtensionAPI) {
1162
1230
  }, { additionalProperties: false }),
1163
1231
  async execute(_toolCallId, params) {
1164
1232
  const delayMilliseconds = params.delayMinutes * 60_000;
1165
- const scheduledAt = new Date(Date.now() + delayMilliseconds).toISOString();
1233
+ const delaySeconds = Math.round(delayMilliseconds / 1000);
1234
+ const armedAt = new Date();
1235
+ const wakeAt = new Date(armedAt.getTime() + delayMilliseconds);
1236
+ const slug = reminderSlug();
1166
1237
  const timer = setTimeout(() => {
1167
1238
  reminderTimers.delete(timer);
1168
1239
  pi.sendMessage(
1169
- { customType: "pi-simple-team-reminder", content: params.message, display: false },
1240
+ { customType: "pi-simple-team-reminder", content: `Reminder ${slug} wake up: it's ${humanTime(new Date())} now.\n\n${params.message}`, display: false },
1170
1241
  { deliverAs: "followUp", triggerTurn: true },
1171
1242
  );
1172
1243
  }, delayMilliseconds);
1173
1244
  reminderTimers.add(timer);
1174
1245
  timer.unref();
1175
- return toolResult({ scheduledAt, message: params.message });
1246
+ return {
1247
+ content: [{ type: "text" as const, text: `Armed reminder ${slug}: It's ${humanTime(armedAt)} now. Reminder set in ${delaySeconds} seconds (${humanDuration(delaySeconds)}) for ${humanTime(wakeAt)}.` }],
1248
+ details: { scheduledAt: wakeAt.toISOString(), message: params.message, slug },
1249
+ };
1176
1250
  },
1177
1251
  }),
1178
1252
  );
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.17",
4
4
  "description": "A flat, live team of Pi agents.",
5
5
  "keywords": [
6
6
  "pi-package",