pi-subagents 0.89.1 → 0.89.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/bundle/child-tool-plan.js +1 -1
  3. package/bundle/{chunk-TDXVQPZW.js → chunk-2UCFLUE4.js} +62 -10
  4. package/bundle/{chunk-C22YEYFZ.js → chunk-464OJSDP.js} +2 -2
  5. package/bundle/{chunk-YLU5JFW2.js → chunk-4KQW5R6U.js} +1 -1
  6. package/bundle/{chunk-7J4ZXMY7.js → chunk-72334PEI.js} +6 -4
  7. package/bundle/{chunk-6D54VW3E.js → chunk-76WVWEFE.js} +24 -15
  8. package/bundle/{chunk-R3NH5XAL.js → chunk-AHGJSJYY.js} +3 -2
  9. package/bundle/{chunk-TRN65L4F.js → chunk-DGLXVN3F.js} +1 -1
  10. package/bundle/{chunk-KCDPTXHT.js → chunk-DHY5TY2Y.js} +235 -197
  11. package/bundle/{chunk-CASL47ST.js → chunk-DYBRIEIF.js} +3 -3
  12. package/bundle/{chunk-MIX3MCIF.js → chunk-FF5K5HQU.js} +8 -3
  13. package/bundle/{chunk-URKQZHVH.js → chunk-FO2GIU5F.js} +23 -14
  14. package/bundle/{chunk-OUM6SEVD.js → chunk-JEYG7CNC.js} +6 -2
  15. package/bundle/{chunk-LUNVS6KP.js → chunk-KA4MKMYT.js} +7 -7
  16. package/bundle/{chunk-IGZTXGPG.js → chunk-ME4IS3Y3.js} +15 -15
  17. package/bundle/{chunk-BERAWSQQ.js → chunk-RHKIP45B.js} +4 -4
  18. package/bundle/{chunk-4FFKVLBG.js → chunk-SRCMJY4F.js} +3 -3
  19. package/bundle/{chunk-SG3NCWZW.js → chunk-U753SUBC.js} +1 -1
  20. package/bundle/{chunk-F6PTAPQ3.js → chunk-UBPAMRVL.js} +6 -6
  21. package/bundle/index.js +1 -1
  22. package/bundle/preflight.js +7 -5
  23. package/bundle/project-panes.js +2 -2
  24. package/docs/observability.md +3 -1
  25. package/docs/watchdog.md +3 -2
  26. package/package.json +1 -1
  27. package/src/api/preflight.d.ts +1 -0
  28. package/src/api/preflight.js +2 -1
  29. package/src/inspectors/herdr/project-panes.d.ts +2 -0
  30. package/src/inspectors/herdr/project-panes.js +7 -1
  31. package/src/inspectors/shell-command.d.ts +2 -1
  32. package/src/inspectors/shell-command.js +7 -5
  33. package/src/runs/background/active-async-capacity.js +2 -1
  34. package/src/runs/background/active-run-index.d.ts +1 -0
  35. package/src/runs/background/active-run-index.js +3 -0
  36. package/src/runs/background/async-execution.d.ts +2 -0
  37. package/src/runs/background/async-execution.js +3 -2
  38. package/src/runs/background/process-terminal.d.ts +6 -0
  39. package/src/runs/background/process-terminal.js +34 -2
  40. package/src/runs/background/run-status.js +2 -1
  41. package/src/runs/background/stale-run-reconciler.d.ts +8 -0
  42. package/src/runs/background/stale-run-reconciler.js +38 -8
  43. package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
  44. package/src/runs/background/workflow-terminal-proof.js +4 -4
  45. package/src/runs/foreground/execution.js +2 -2
  46. package/src/runs/foreground/subagent-executor.d.ts +2 -0
  47. package/src/runs/foreground/subagent-executor.js +10 -1
  48. package/src/runs/shared/herdr-pane-host.js +10 -2
  49. package/src/runs/shared/mcp-config-sources.d.ts +1 -0
  50. package/src/runs/shared/mcp-config-sources.js +1 -1
  51. package/src/runs/shared/mcp-direct-tool-allowlist.js +1 -0
  52. package/src/shared/types.d.ts +2 -0
  53. package/src/tui/fleet-transcript.js +21 -9
  54. package/src/watchdog/runtime.d.ts +4 -0
  55. package/src/watchdog/runtime.js +50 -12
  56. package/src/watchdog/turn-delta.d.ts +2 -0
  57. package/src/watchdog/turn-delta.js +21 -0
@@ -5,13 +5,15 @@ import { collectWatchdogLspDiagnostics, formatWatchdogLspDiagnosticsBlock, Watch
5
5
  import { ruleViolationWarning } from "./rules.js";
6
6
  import { WatchdogScopeArtifact } from "./scope.js";
7
7
  import { resolveWatchdogConfig } from "./settings.js";
8
- import { formatWatchdogOrchestrationActivity, formatWatchdogTurnDelta } from "./turn-delta.js";
8
+ import { formatWatchdogOrchestrationActivity, formatWatchdogSupervisorReplies, formatWatchdogTurnDelta } from "./turn-delta.js";
9
9
  import { WATCHDOG_WARNING_IMPORTANCES, } from "./types.js";
10
10
  import { normalizeWatchdogWarningDetails } from "./warning-format.js";
11
11
  const DEFAULT_REVIEW = () => ({ warnings: [] });
12
12
  const MAX_REVIEW_INPUT_CHARS = 24_000;
13
13
  const REVIEW_INPUT_HEAD_CHARS = 6_000;
14
14
  const REVIEW_DELTA_SEPARATOR = "\n\n---\n\n";
15
+ const MAX_SUPERVISOR_REPLY_CHARS = 3_000;
16
+ const MAX_SUPERVISOR_REPLIES_CHARS = 6_000;
15
17
  export function boundWatchdogReviewText(text, cap = MAX_REVIEW_INPUT_CHARS) {
16
18
  if (text.length <= cap)
17
19
  return text;
@@ -19,6 +21,13 @@ export function boundWatchdogReviewText(text, cap = MAX_REVIEW_INPUT_CHARS) {
19
21
  const marker = `\n\n[... about ${text.length - cap} characters omitted ...]\n\n`;
20
22
  return `${text.slice(0, head)}${marker}${text.slice(text.length - (cap - head - marker.length))}`;
21
23
  }
24
+ // The reviewer must not read missing text as proof that an instruction or authorization never happened.
25
+ function omittedDeltaNote(chars) {
26
+ return `[Parts of this run's turn delta omitted: about ${chars} characters are not shown, to fit the review input limit. Do not report an instruction, authorization, or action as absent unless the supplied evidence shows it; it may be in an omitted part.]`;
27
+ }
28
+ const OMITTED_NOTE_RESERVE = omittedDeltaNote(Number.MAX_SAFE_INTEGER).length + 2;
29
+ // Retained delta leaves room for the note, so a note never forces a second cut of the delta.
30
+ const MAX_RETAINED_DELTA_CHARS = MAX_REVIEW_INPUT_CHARS - OMITTED_NOTE_RESERVE;
22
31
  function errorMessage(error) {
23
32
  return error instanceof Error ? error.message : String(error);
24
33
  }
@@ -52,6 +61,7 @@ export class MainWatchdogRuntime {
52
61
  status = "idle";
53
62
  pendingDeltas = [];
54
63
  pendingDeltaChars = 0;
64
+ omittedDeltaChars = 0;
55
65
  guard = new WatchdogEmissionGuard();
56
66
  guardMaxWarnings = null;
57
67
  epoch = 0;
@@ -90,6 +100,7 @@ export class MainWatchdogRuntime {
90
100
  activityTail = "";
91
101
  activityPending = false;
92
102
  activityReviewUsed = false;
103
+ supervisorReplies = [];
93
104
  constructor(options = {}) {
94
105
  this.cwd = options.cwd ?? process.cwd();
95
106
  this.resolveConfig = options.resolveConfig ?? resolveWatchdogConfig;
@@ -201,8 +212,10 @@ export class MainWatchdogRuntime {
201
212
  this.lspLedger.reset();
202
213
  this.lastLspSnapshot = undefined;
203
214
  }
204
- if (options.clearScope)
215
+ if (options.clearScope) {
205
216
  this.scope.reset();
217
+ this.supervisorReplies = [];
218
+ }
206
219
  if (options.clearScope || options.clearActivity)
207
220
  this.clearActivity();
208
221
  if (options.clearReviewInputSignature)
@@ -229,6 +242,7 @@ export class MainWatchdogRuntime {
229
242
  this.lastLspSnapshot = undefined;
230
243
  this.lspLedger.reset();
231
244
  this.scope.reset();
245
+ this.supervisorReplies = [];
232
246
  this.observedRepoEditThisTurn = false;
233
247
  this.toolResultsThisRun = 0;
234
248
  this.midRunReviewing = false;
@@ -267,6 +281,7 @@ export class MainWatchdogRuntime {
267
281
  this.activityPending = true;
268
282
  }
269
283
  }
284
+ this.retainSupervisorReplies(event);
270
285
  this.observedRepoEditThisTurn ||= eventIndicatesRepoEdit(event);
271
286
  const delta = formatWatchdogTurnDelta({
272
287
  includeUserPrompt: this.includeUserPromptInNextDelta,
@@ -779,16 +794,28 @@ export class MainWatchdogRuntime {
779
794
  let entry = delta.trim();
780
795
  if (!entry)
781
796
  return;
782
- if (entry.length > MAX_REVIEW_INPUT_CHARS)
783
- entry = boundWatchdogReviewText(entry);
797
+ if (entry.length > MAX_RETAINED_DELTA_CHARS) {
798
+ this.omittedDeltaChars += entry.length - MAX_RETAINED_DELTA_CHARS;
799
+ entry = boundWatchdogReviewText(entry, MAX_RETAINED_DELTA_CHARS);
800
+ }
784
801
  this.pendingDeltas.push(entry);
785
802
  this.pendingDeltaChars += entry.length;
786
- while (this.pendingDeltas.length > 1 && this.pendingDeltaChars + (this.pendingDeltas.length - 1) * REVIEW_DELTA_SEPARATOR.length > MAX_REVIEW_INPUT_CHARS) {
803
+ while (this.pendingDeltas.length > 1 && this.pendingDeltaChars + (this.pendingDeltas.length - 1) * REVIEW_DELTA_SEPARATOR.length > MAX_RETAINED_DELTA_CHARS) {
787
804
  const removed = this.pendingDeltas.shift();
788
- if (removed)
805
+ if (removed) {
789
806
  this.pendingDeltaChars -= removed.length;
807
+ this.omittedDeltaChars += removed.length;
808
+ }
790
809
  }
791
810
  }
811
+ // Kept outside the rolling delta so a long run cannot push the supervisor's instruction out of the review input.
812
+ retainSupervisorReplies(event) {
813
+ for (const reply of formatWatchdogSupervisorReplies(event))
814
+ this.supervisorReplies.push(boundWatchdogReviewText(reply, MAX_SUPERVISOR_REPLY_CHARS));
815
+ let total = this.supervisorReplies.reduce((sum, reply) => sum + reply.length, 0);
816
+ while (this.supervisorReplies.length > 1 && total > MAX_SUPERVISOR_REPLIES_CHARS)
817
+ total -= this.supervisorReplies.shift().length;
818
+ }
792
819
  buildReviewInput(changeSignature, lspBlock = "") {
793
820
  const input = this.pendingDeltas.join(REVIEW_DELTA_SEPARATOR);
794
821
  const scopeBlock = this.scopeBlock();
@@ -796,25 +823,36 @@ export class MainWatchdogRuntime {
796
823
  ? ["Changed repo paths: every dirty path in the working tree. Authorship is not verified; a path may predate this session or come from another session.", ...changeSignature.changedPaths.slice(0, 200).map((file) => `- ${file}`)].join("\n")
797
824
  : "";
798
825
  const activity = this.activityTail ? `Recent delivered orchestration activity (oldest first; bounded observations, not a task board; waits/holds are not evidence of neglect):\n${this.activityTail}` : "";
826
+ const supervisor = this.configResult.config.scope.enabled && this.supervisorReplies.length
827
+ ? `Supervisor replies this agent received through contact_supervisor (oldest first; the orchestrator's answers to this agent's questions, which can authorize or redirect its work):\n${this.supervisorReplies.join(REVIEW_DELTA_SEPARATOR)}`
828
+ : "";
799
829
  const contextPieces = [scopeBlock, changes, lspBlock, activity].filter(Boolean);
800
- if (!contextPieces.length)
801
- return boundWatchdogReviewText(input);
830
+ if (!contextPieces.length && !supervisor)
831
+ return this.boundDeltaInput(input, MAX_REVIEW_INPUT_CHARS);
802
832
  const maxContextLength = Math.floor(MAX_REVIEW_INPUT_CHARS / 2);
803
833
  const maxPieceLength = Math.max(1_000, Math.floor(maxContextLength / contextPieces.length));
804
- const boundedContext = contextPieces.map((piece) => piece.length > maxPieceLength
805
- ? piece === activity ? boundWatchdogReviewText(piece, maxPieceLength) : `${piece.slice(0, maxPieceLength - 6)}\n- ...`
806
- : piece).join(REVIEW_DELTA_SEPARATOR);
834
+ // Supervisor replies are already bounded to whole entries at retention; a second head+tail cut would drop whole replies.
835
+ const boundedContext = [...contextPieces.map((piece) => piece.length > maxPieceLength
836
+ ? piece === activity ? boundWatchdogReviewText(piece, maxPieceLength) : `${piece.slice(0, maxPieceLength - 6)}\n- ...`
837
+ : piece), supervisor].filter(Boolean).join(REVIEW_DELTA_SEPARATOR);
807
838
  const separatorLength = input ? REVIEW_DELTA_SEPARATOR.length : 0;
808
839
  const inputBudget = MAX_REVIEW_INPUT_CHARS - boundedContext.length - separatorLength;
809
- const boundedInput = inputBudget <= 0 ? "" : boundWatchdogReviewText(input, inputBudget);
840
+ const boundedInput = inputBudget <= 0 ? "" : this.boundDeltaInput(input, inputBudget);
810
841
  return [boundedContext, boundedInput].filter(Boolean).join(REVIEW_DELTA_SEPARATOR);
811
842
  }
843
+ boundDeltaInput(input, cap) {
844
+ if (!input || (this.omittedDeltaChars === 0 && input.length <= cap))
845
+ return input;
846
+ const bodyCap = cap - OMITTED_NOTE_RESERVE;
847
+ return `${omittedDeltaNote(this.omittedDeltaChars + Math.max(0, input.length - bodyCap))}\n\n${boundWatchdogReviewText(input, bodyCap)}`;
848
+ }
812
849
  scopeBlock() {
813
850
  return this.configResult.config.scope.enabled ? this.scope.render() : "";
814
851
  }
815
852
  clearPendingDeltas() {
816
853
  this.pendingDeltas = [];
817
854
  this.pendingDeltaChars = 0;
855
+ this.omittedDeltaChars = 0;
818
856
  }
819
857
  clearActivity() {
820
858
  if (!this.activityTail)
@@ -13,3 +13,5 @@ export declare function formatWatchdogReviewMessage(message: unknown, options?:
13
13
  export declare function formatWatchdogTurnDelta(input: WatchdogTurnDeltaInput): string;
14
14
  /** Only completed, exactly paired native orchestration calls are activity evidence. */
15
15
  export declare function formatWatchdogOrchestrationActivity(event: unknown): string;
16
+ /** A supervisor reply arrives as a tool result, never as a user prompt, so scope alone never records it. */
17
+ export declare function formatWatchdogSupervisorReplies(event: unknown): string[];
@@ -187,3 +187,24 @@ export function formatWatchdogOrchestrationActivity(event) {
187
187
  }
188
188
  return sections.join("\n\n");
189
189
  }
190
+ /** A supervisor reply arrives as a tool result, never as a user prompt, so scope alone never records it. */
191
+ export function formatWatchdogSupervisorReplies(event) {
192
+ const turn = event;
193
+ if (turn?.type !== "turn_end" || !Array.isArray(turn.message?.content) || !Array.isArray(turn.toolResults))
194
+ return [];
195
+ const entries = [];
196
+ for (const call of turn.message.content) {
197
+ if (call?.type !== "toolCall" || call.name !== "contact_supervisor" || typeof call.id !== "string")
198
+ continue;
199
+ const args = call.arguments;
200
+ if (!args || typeof args !== "object" || !["need_decision", "interview_request"].includes(args.reason))
201
+ continue;
202
+ const result = turn.toolResults.find((value) => {
203
+ const result = value;
204
+ return result?.role === "toolResult" && result.toolCallId === call.id && result.toolName === call.name && result.isError !== true && !result.error;
205
+ });
206
+ if (result)
207
+ entries.push([formatToolCall(call.name, args), formatWatchdogReviewMessage(result) ?? ""].join("\n\n"));
208
+ }
209
+ return entries;
210
+ }