pi-subagents 0.84.0 → 0.86.0

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 (210) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +2 -2
  4. package/bundle/{chunk-JG4QKI5M.js → chunk-2IYBCYFU.js} +214 -97
  5. package/bundle/{chunk-V2BZYLEP.js → chunk-374MZFF4.js} +7 -2
  6. package/bundle/{chunk-4E7BKDTX.js → chunk-3RKFH2UZ.js} +11 -156
  7. package/bundle/{chunk-F4ASL6OV.js → chunk-5H4BICQZ.js} +1 -1
  8. package/bundle/{chunk-PALJGGYC.js → chunk-6VD7BGIC.js} +6 -3
  9. package/bundle/{chunk-C5P5CHYK.js → chunk-77ASNIEM.js} +1 -1
  10. package/bundle/{chunk-XDQORLZ5.js → chunk-7ADDXUGF.js} +15 -6
  11. package/bundle/{chunk-PV63UFUR.js → chunk-7QA7ZA46.js} +183 -28
  12. package/bundle/{chunk-NKQ6JNAS.js → chunk-7ZUFN6ME.js} +2 -1
  13. package/bundle/{chunk-SSG7IEP5.js → chunk-A637IMAO.js} +2 -2
  14. package/bundle/{chunk-L3WFKBEI.js → chunk-BGXEAYUM.js} +247 -153
  15. package/bundle/{chunk-J5YL7LYR.js → chunk-BU6PFPVX.js} +59 -27
  16. package/bundle/{chunk-DZDETGRJ.js → chunk-BWC2LVII.js} +259 -216
  17. package/bundle/{chunk-CGN2TVE7.js → chunk-GJGTMLPE.js} +322 -18
  18. package/bundle/{chunk-D3JAFGMO.js → chunk-GRJHIXYF.js} +1 -1
  19. package/bundle/chunk-HXRB42AF.js +108 -0
  20. package/bundle/{chunk-LFDBD4PW.js → chunk-LGINOOY5.js} +2 -2
  21. package/bundle/{chunk-G2Z6ZH26.js → chunk-NAFLUJ26.js} +1 -1
  22. package/bundle/{chunk-235AWJUQ.js → chunk-O3YH7XIY.js} +324 -111
  23. package/bundle/{chunk-2DHZTCOL.js → chunk-PYOAIN3V.js} +2 -2
  24. package/bundle/{chunk-LNRJCP2Y.js → chunk-QGO6HXHG.js} +417 -242
  25. package/bundle/{chunk-VQVVHSY6.js → chunk-QM3JGE4W.js} +22 -11
  26. package/bundle/{chunk-2S4K53MV.js → chunk-S2Q75LP3.js} +1 -1
  27. package/bundle/{chunk-NENDSQUY.js → chunk-UR7OW5S7.js} +9 -6
  28. package/bundle/{chunk-AKOIVLA5.js → chunk-WN2E5XHN.js} +135 -77
  29. package/bundle/{chunk-2D52JFLF.js → chunk-YK3QYNLE.js} +41 -117
  30. package/bundle/{chunk-7BWGNDNK.js → chunk-ZJJCPV3L.js} +190 -1177
  31. package/bundle/chunk-ZPY5QZCS.js +1067 -0
  32. package/bundle/control-channel.js +2 -2
  33. package/bundle/index.js +1 -1
  34. package/bundle/intercom-bridge.js +2 -2
  35. package/bundle/preflight.js +8 -8
  36. package/bundle/project-panes.js +3 -3
  37. package/docs/agents.md +23 -2
  38. package/docs/configuration.md +4 -4
  39. package/docs/extension-api.md +16 -1
  40. package/docs/tool-reference.md +2 -0
  41. package/docs/workflows.md +30 -2
  42. package/package.json +1 -1
  43. package/src/agents/agent-management.js +27 -11
  44. package/src/agents/agent-memory.d.ts +1 -4
  45. package/src/agents/agent-memory.js +1 -4
  46. package/src/agents/agents.d.ts +1 -3
  47. package/src/agents/agents.js +7 -6
  48. package/src/agents/frontmatter.js +1 -8
  49. package/src/agents/global-npm-root.d.ts +1 -0
  50. package/src/agents/global-npm-root.js +11 -3
  51. package/src/agents/skills.d.ts +0 -3
  52. package/src/agents/skills.js +0 -3
  53. package/src/extension/config.js +7 -1
  54. package/src/extension/herdr-pi-bridge.js +10 -2
  55. package/src/extension/index.d.ts +0 -13
  56. package/src/extension/index.js +43 -32
  57. package/src/extension/public-execution.d.ts +1 -0
  58. package/src/extension/public-execution.js +4 -0
  59. package/src/extension/reply-workflow-script.js +24 -4
  60. package/src/extension/schemas.d.ts +8 -3
  61. package/src/extension/schemas.js +5 -3
  62. package/src/extension/session-switch.d.ts +25 -0
  63. package/src/extension/session-switch.js +138 -0
  64. package/src/extension/subagent-guide.d.ts +1 -1
  65. package/src/extension/subagent-guide.js +1 -1
  66. package/src/extension/subagent-launch-tool.d.ts +25 -0
  67. package/src/extension/subagent-launch-tool.js +48 -0
  68. package/src/extension/tool-activation.js +35 -12
  69. package/src/extension/tool-description.d.ts +1 -1
  70. package/src/extension/tool-description.js +14 -8
  71. package/src/inspectors/herdr/actions.d.ts +0 -1
  72. package/src/inspectors/herdr/actions.js +0 -1
  73. package/src/inspectors/session-roots-codec.d.ts +0 -1
  74. package/src/inspectors/session-roots-codec.js +0 -1
  75. package/src/inspectors/tmux/actions.d.ts +0 -1
  76. package/src/inspectors/tmux/actions.js +0 -1
  77. package/src/integrations/herdr-status.js +3 -8
  78. package/src/intercom/native-supervisor-channel.js +65 -9
  79. package/src/runs/background/async-execution.d.ts +5 -9
  80. package/src/runs/background/async-execution.js +62 -27
  81. package/src/runs/background/async-job-tracker.js +12 -0
  82. package/src/runs/background/async-resume.d.ts +2 -1
  83. package/src/runs/background/async-resume.js +112 -39
  84. package/src/runs/background/async-retention.js +6 -1
  85. package/src/runs/background/auto-drain.js +2 -1
  86. package/src/runs/background/boot-id.d.ts +1 -3
  87. package/src/runs/background/boot-id.js +1 -3
  88. package/src/runs/background/completion-batcher.d.ts +3 -4
  89. package/src/runs/background/completion-batcher.js +2 -3
  90. package/src/runs/background/control-channel.d.ts +0 -6
  91. package/src/runs/background/control-channel.js +0 -6
  92. package/src/runs/background/fleet-view.js +2 -3
  93. package/src/runs/background/notify.d.ts +0 -2
  94. package/src/runs/background/notify.js +0 -2
  95. package/src/runs/background/result-watcher.d.ts +1 -0
  96. package/src/runs/background/result-watcher.js +59 -29
  97. package/src/runs/background/resume-guidance.js +4 -2
  98. package/src/runs/background/retained-children.js +2 -1
  99. package/src/runs/background/run-child-session.d.ts +0 -1
  100. package/src/runs/background/run-child-session.js +1 -1
  101. package/src/runs/background/run-status.js +9 -7
  102. package/src/runs/background/scheduled-runs.d.ts +3 -1
  103. package/src/runs/background/scheduled-runs.js +13 -16
  104. package/src/runs/background/subagent-runner.d.ts +2 -4
  105. package/src/runs/background/subagent-runner.js +15 -12
  106. package/src/runs/background/subagent-wait.js +12 -15
  107. package/src/runs/background/wait-config.d.ts +2 -0
  108. package/src/runs/background/wait-config.js +17 -3
  109. package/src/runs/background/wait-tool.js +4 -2
  110. package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
  111. package/src/runs/background/workflow-terminal-proof.js +0 -1
  112. package/src/runs/foreground/execution.d.ts +0 -3
  113. package/src/runs/foreground/execution.js +17 -9
  114. package/src/runs/foreground/subagent-executor.d.ts +3 -2
  115. package/src/runs/foreground/subagent-executor.js +107 -26
  116. package/src/runs/shared/acceptance.js +69 -26
  117. package/src/runs/shared/child-commands.js +15 -2
  118. package/src/runs/shared/child-hooks.d.ts +1 -7
  119. package/src/runs/shared/child-hooks.js +13 -5
  120. package/src/runs/shared/child-launch.js +6 -2
  121. package/src/runs/shared/child-runtime-config.d.ts +0 -1
  122. package/src/runs/shared/child-session.d.ts +1 -1
  123. package/src/runs/shared/child-session.js +21 -2
  124. package/src/runs/shared/child-tool-plan.d.ts +0 -1
  125. package/src/runs/shared/child-tool-plan.js +0 -1
  126. package/src/runs/shared/claude-code-adapter.js +11 -0
  127. package/src/runs/shared/external-cli-contract.d.ts +49 -0
  128. package/src/runs/shared/external-cli-contract.js +18 -13
  129. package/src/runs/shared/external-cli-runner.js +26 -6
  130. package/src/runs/shared/herdr-connection.js +2 -1
  131. package/src/runs/shared/herdr-pane-host.d.ts +2 -2
  132. package/src/runs/shared/herdr-pane-host.js +17 -1
  133. package/src/runs/shared/herdr-placed-run.js +48 -22
  134. package/src/runs/shared/lane-metadata.d.ts +0 -1
  135. package/src/runs/shared/lane-metadata.js +0 -1
  136. package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
  137. package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
  138. package/src/runs/shared/model-resolution.d.ts +2 -2
  139. package/src/runs/shared/model-resolution.js +7 -1
  140. package/src/runs/shared/model-scope.d.ts +1 -5
  141. package/src/runs/shared/model-scope.js +1 -5
  142. package/src/runs/shared/mutation-evidence.d.ts +1 -1
  143. package/src/runs/shared/mutation-evidence.js +52 -7
  144. package/src/runs/shared/nested-events.d.ts +1 -0
  145. package/src/runs/shared/nested-events.js +1 -1
  146. package/src/runs/shared/parallel-utils.d.ts +0 -1
  147. package/src/runs/shared/permissions.js +5 -3
  148. package/src/runs/shared/placement-host.d.ts +5 -1
  149. package/src/runs/shared/rex-pane-host.d.ts +0 -1
  150. package/src/runs/shared/rex-pane-host.js +0 -2
  151. package/src/runs/shared/run-launch-folder.d.ts +12 -0
  152. package/src/runs/shared/run-launch-folder.js +21 -0
  153. package/src/runs/shared/runner-launcher.d.ts +12 -1
  154. package/src/runs/shared/runner-launcher.js +16 -0
  155. package/src/runs/shared/single-output.d.ts +3 -3
  156. package/src/runs/shared/single-output.js +5 -3
  157. package/src/runs/shared/structured-output.d.ts +8 -0
  158. package/src/runs/shared/structured-output.js +40 -5
  159. package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
  160. package/src/runs/shared/subagent-prompt-runtime.js +4 -2
  161. package/src/runs/shared/tool-timeout.js +2 -1
  162. package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
  163. package/src/runs/shared/worktree-cleanup-plan.js +0 -1
  164. package/src/runs/shared/worktree.d.ts +3 -0
  165. package/src/runs/shared/worktree.js +20 -0
  166. package/src/shared/capacity-resilient-json.d.ts +1 -1
  167. package/src/shared/child-cache-retention.d.ts +1 -2
  168. package/src/shared/child-cache-retention.js +1 -2
  169. package/src/shared/fleet-transcript-reader.d.ts +51 -0
  170. package/src/shared/fleet-transcript-reader.js +333 -0
  171. package/src/shared/formatters.d.ts +0 -18
  172. package/src/shared/formatters.js +0 -18
  173. package/src/shared/session-succession.d.ts +16 -1
  174. package/src/shared/session-succession.js +41 -2
  175. package/src/shared/session-warnings.d.ts +7 -0
  176. package/src/shared/session-warnings.js +26 -0
  177. package/src/shared/settings.d.ts +0 -23
  178. package/src/shared/settings.js +3 -35
  179. package/src/shared/types.d.ts +85 -59
  180. package/src/shared/types.js +0 -12
  181. package/src/shared/utils.d.ts +0 -14
  182. package/src/shared/utils.js +0 -22
  183. package/src/shared/wait-tool-name.d.ts +8 -0
  184. package/src/shared/wait-tool-name.js +13 -0
  185. package/src/slash/slash-commands.js +2 -1
  186. package/src/slash/subagent-cost.d.ts +3 -2
  187. package/src/slash/subagent-cost.js +22 -3
  188. package/src/slash/subagents-admin.js +0 -1
  189. package/src/tui/fleet-status.d.ts +0 -5
  190. package/src/tui/fleet-status.js +4 -24
  191. package/src/tui/fleet-transcript.d.ts +1 -44
  192. package/src/tui/fleet-transcript.js +1 -327
  193. package/src/tui/fleet.js +6 -4
  194. package/src/tui/render.d.ts +0 -9
  195. package/src/tui/render.js +161 -66
  196. package/src/tui/subagent-messages.js +3 -2
  197. package/src/watchdog/register-child.d.ts +2 -3
  198. package/src/watchdog/register-child.js +2 -3
  199. package/src/watchdog/turn-delta.js +2 -1
  200. package/src/workflows/scripted-workflow.js +241 -20
  201. package/src/workflows/workflow-launch-record.d.ts +15 -6
  202. package/src/workflows/workflow-launch-record.js +30 -12
  203. package/src/workflows/workflow-receipt.js +36 -53
  204. package/src/workflows/workflow-resume-claim.js +2 -2
  205. package/src/workflows/workflow-resume.d.ts +1 -1
  206. package/src/workflows/workflow-resume.js +11 -8
  207. package/src/workflows/workflow-script-worker.d.ts +13 -0
  208. package/src/workflows/workflow-script-worker.js +79 -0
  209. package/workflow-script-process.cjs +36 -0
  210. package/workflow-script-worker.cjs +4 -1
@@ -34,11 +34,6 @@ export interface FleetStatusOptions {
34
34
  export declare function resolveFleetViewPlacement(value: unknown): FleetViewPlacement;
35
35
  export declare function formatFleetElapsed(ms: number): string;
36
36
  export declare function formatFleetTokens(count: number, window?: number, windowCount?: number): string;
37
- /**
38
- * Reports a Fleet problem once per process. Fleet refreshes on a timer, and console output while the TUI owns
39
- * the terminal is drawn over the editor, so an interactive session gets one TUI warning instead.
40
- */
41
- export declare function reportFleetWarning(state: SubagentState, message: string): void;
42
37
  export declare function collectFleetStatusEntries(state: SubagentState): FleetStatusEntry[];
43
38
  export declare class SubagentFleetStatus {
44
39
  private ctx;
@@ -5,7 +5,8 @@ import { projectAsyncWorkflowRows } from "../runs/shared/async-status-projection
5
5
  import { contextModeLabel } from "../runs/shared/context-mode.js";
6
6
  import { formatWorkflowJsonPreview } from "../workflows/scripted-workflow.js";
7
7
  import { hostStepReportName, hostStepVerdictLabel } from "../runs/shared/host-step-status.js";
8
- import { isStaleExtensionContextError, withCachedUiContext } from "../shared/extension-context.js";
8
+ import { isStaleExtensionContextError } from "../shared/extension-context.js";
9
+ import { reportSessionWarning } from "../shared/session-warnings.js";
9
10
  import { inlineWorkflowRenderKey } from "./render.js";
10
11
  import { runningTone } from "./running-tone.js";
11
12
  import { childThinkingLevel } from "../shared/model-info.js";
@@ -318,27 +319,6 @@ function projectPaneEntries(state) {
318
319
  projectPane: pane,
319
320
  }));
320
321
  }
321
- const reportedFleetWarnings = new Set();
322
- /**
323
- * Reports a Fleet problem once per process. Fleet refreshes on a timer, and console output while the TUI owns
324
- * the terminal is drawn over the editor, so an interactive session gets one TUI warning instead.
325
- */
326
- export function reportFleetWarning(state, message) {
327
- if (reportedFleetWarnings.has(message))
328
- return;
329
- reportedFleetWarnings.add(message);
330
- const text = `[pi-subagents] ${message}`;
331
- const cached = state.lastUiContext;
332
- const notified = withCachedUiContext(cached, () => {
333
- if (state.lastUiContext === cached)
334
- state.lastUiContext = null;
335
- }, (ctx) => {
336
- ctx.ui.notify(text, "warning");
337
- return true;
338
- });
339
- if (!notified)
340
- console.warn(text);
341
- }
342
322
  export function collectFleetStatusEntries(state) {
343
323
  const now = Date.now();
344
324
  const entries = [];
@@ -486,7 +466,7 @@ export function collectFleetStatusEntries(state) {
486
466
  }
487
467
  if (state.currentSessionId) {
488
468
  try {
489
- for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportFleetWarning(state, `Removed ${message}`) })) {
469
+ for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportSessionWarning(state, `Removed ${message}`) })) {
490
470
  if (!isActiveState(run.state))
491
471
  continue;
492
472
  entries.push({
@@ -501,7 +481,7 @@ export function collectFleetStatusEntries(state) {
501
481
  }
502
482
  }
503
483
  catch (cause) {
504
- reportFleetWarning(state, `Failed to inspect external jobs: ${cause instanceof Error ? cause.message : String(cause)}`);
484
+ reportSessionWarning(state, `Failed to inspect external jobs: ${cause instanceof Error ? cause.message : String(cause)}`);
505
485
  }
506
486
  }
507
487
  entries.push(...projectPaneEntries(state));
@@ -1,50 +1,7 @@
1
1
  import { type ExtensionContext } from "@earendil-works/pi-coding-agent";
2
2
  import { type MarkdownTheme } from "@earendil-works/pi-tui";
3
+ import { type FleetTranscript } from "../shared/fleet-transcript-reader.ts";
3
4
  type Theme = ExtensionContext["ui"]["theme"];
4
- export type FleetTranscriptEvent = {
5
- kind: "assistant";
6
- text: string;
7
- model?: string;
8
- timestamp?: number;
9
- } | {
10
- kind: "user";
11
- text: string;
12
- timestamp?: number;
13
- } | {
14
- kind: "tool";
15
- toolCallId?: string;
16
- name: string;
17
- args?: string;
18
- argsPayload?: string;
19
- output?: string;
20
- outputTruncated?: boolean;
21
- status: "running" | "complete" | "error";
22
- error?: string;
23
- startedAt?: number;
24
- endedAt?: number;
25
- timestamp?: number;
26
- } | {
27
- kind: "notice";
28
- text: string;
29
- tone: "muted" | "warning" | "error";
30
- timestamp?: number;
31
- };
32
- export interface FleetTranscript {
33
- path: string;
34
- events: FleetTranscriptEvent[];
35
- truncated: boolean;
36
- warning?: string;
37
- /** The path was refused or the file could not be read, as opposed to a read that only skipped records. */
38
- readFailed?: true;
39
- }
40
- interface FleetTranscriptReadOptions {
41
- trustedRoots: string[];
42
- trustedFiles?: string[];
43
- trustedFileRoot?: string;
44
- maxRecords?: number;
45
- maxBytes?: number;
46
- }
47
- export declare function readFleetTranscript(filePath: string, options: FleetTranscriptReadOptions): FleetTranscript;
48
5
  export declare function renderFleetTranscript(transcript: FleetTranscript, width: number, theme: Theme, markdownTheme: MarkdownTheme, options?: {
49
6
  expandedTools?: boolean;
50
7
  }): string[];
@@ -1,334 +1,8 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
1
  import { getLanguageFromPath, highlightCode } from "@earendil-works/pi-coding-agent";
4
2
  import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
5
3
  import { safeTerminalText as safeDisplayText } from "../shared/display-text.js";
6
- import { isTrustedRecordedSessionFile } from "../shared/session-file-trust.js";
7
- const DEFAULT_MAX_RECORDS = 240;
8
- const DEFAULT_MAX_BYTES = 2 * 1024 * 1024;
9
- const MAX_MESSAGE_CHARS = 64 * 1024;
4
+ import { objectValue, safeTranscriptEvent } from "../shared/fleet-transcript-reader.js";
10
5
  const TOOL_PREVIEW_LINES = 7;
11
- function sanitizeJsonDisplayValue(value) {
12
- if (typeof value === "string") {
13
- const safe = safeDisplayText(value);
14
- return { value: safe, changed: safe !== value };
15
- }
16
- if (Array.isArray(value)) {
17
- const sanitized = value.map(sanitizeJsonDisplayValue);
18
- return {
19
- value: sanitized.map((entry) => entry.value),
20
- changed: sanitized.some((entry) => entry.changed),
21
- };
22
- }
23
- if (value && typeof value === "object") {
24
- let changed = false;
25
- const sanitized = Object.create(null);
26
- for (const [key, nested] of Object.entries(value)) {
27
- const safeKey = safeDisplayText(key);
28
- const safeValue = sanitizeJsonDisplayValue(nested);
29
- sanitized[safeKey] = safeValue.value;
30
- changed ||= safeKey !== key || safeValue.changed;
31
- }
32
- return { value: changed ? sanitized : value, changed };
33
- }
34
- return { value, changed: false };
35
- }
36
- function safeToolArgsPayload(payload) {
37
- try {
38
- const sanitized = sanitizeJsonDisplayValue(JSON.parse(payload));
39
- return sanitized.changed ? JSON.stringify(sanitized.value) : safeDisplayText(payload);
40
- }
41
- catch {
42
- return safeDisplayText(payload);
43
- }
44
- }
45
- function objectValue(value) {
46
- return value && typeof value === "object" && !Array.isArray(value)
47
- ? value
48
- : undefined;
49
- }
50
- function stringValue(value) {
51
- return typeof value === "string" && value.trim() ? value : undefined;
52
- }
53
- function numberValue(value) {
54
- return typeof value === "number" && Number.isFinite(value) ? value : undefined;
55
- }
56
- function pathWithin(base, candidate) {
57
- const resolvedBase = path.resolve(base);
58
- const resolvedCandidate = path.resolve(candidate);
59
- return resolvedCandidate === resolvedBase || resolvedCandidate.startsWith(`${resolvedBase}${path.sep}`);
60
- }
61
- function errorMessage(error) {
62
- return error instanceof Error ? error.message : String(error);
63
- }
64
- function isNotFoundError(error) {
65
- return Boolean(objectValue(error)?.code === "ENOENT");
66
- }
67
- function validateTranscriptPath(filePath, trustedRoots, trustedFiles = [], trustedFileRoot) {
68
- if (trustedRoots.length === 0 && (!trustedFileRoot || trustedFiles.length === 0))
69
- return { warning: `Transcript preview has no trusted root: ${filePath}` };
70
- const resolvedPath = path.resolve(filePath);
71
- const recordedCandidate = trustedFileRoot
72
- && pathWithin(trustedFileRoot, resolvedPath)
73
- && trustedFiles.some((file) => path.resolve(file) === resolvedPath);
74
- if (!trustedRoots.some((root) => pathWithin(root, resolvedPath)) && !recordedCandidate) {
75
- return { warning: `Transcript is outside trusted roots: ${filePath}` };
76
- }
77
- let stat;
78
- try {
79
- stat = fs.lstatSync(resolvedPath);
80
- }
81
- catch (error) {
82
- if (isNotFoundError(error))
83
- return {};
84
- return { warning: `Transcript could not be inspected: ${errorMessage(error)}` };
85
- }
86
- if (stat.isSymbolicLink())
87
- return { warning: `Transcript preview refused a symlink: ${filePath}` };
88
- if (!stat.isFile())
89
- return { warning: `Transcript path is not a file: ${filePath}` };
90
- try {
91
- const realPath = fs.realpathSync(resolvedPath);
92
- const realRoots = trustedRoots
93
- .filter((root) => fs.existsSync(root))
94
- .map((root) => fs.realpathSync(root));
95
- if (!realRoots.some((root) => pathWithin(root, realPath)) && !isTrustedRecordedSessionFile(realPath, trustedFiles, trustedFileRoot)) {
96
- return { warning: `Transcript resolves outside trusted roots: ${filePath}` };
97
- }
98
- return { resolvedPath: realPath };
99
- }
100
- catch (error) {
101
- return { warning: `Transcript path could not be resolved: ${errorMessage(error)}` };
102
- }
103
- }
104
- function isCompleteRecord(line) {
105
- if (!line?.trim())
106
- return false;
107
- try {
108
- return objectValue(JSON.parse(line)) !== undefined;
109
- }
110
- catch {
111
- return false;
112
- }
113
- }
114
- function readTailLines(filePath, maxBytes) {
115
- let fd;
116
- try {
117
- const noFollow = typeof fs.constants.O_NOFOLLOW === "number" ? fs.constants.O_NOFOLLOW : 0;
118
- fd = fs.openSync(filePath, fs.constants.O_RDONLY | noFollow);
119
- const stat = fs.fstatSync(fd);
120
- if (!stat.isFile())
121
- return { lines: [], truncated: false, warning: `Transcript path is not a file: ${filePath}` };
122
- if (stat.size === 0)
123
- return { lines: [], truncated: false };
124
- const bytesToRead = Math.min(stat.size, maxBytes);
125
- const start = stat.size - bytesToRead;
126
- const buffer = Buffer.alloc(bytesToRead);
127
- const bytesRead = fs.readSync(fd, buffer, 0, bytesToRead, start);
128
- const content = buffer.subarray(0, bytesRead).toString("utf-8");
129
- const endsWithNewline = content.endsWith("\n");
130
- let lines = content.split(/\r?\n/);
131
- if (start > 0 && lines.length > 0)
132
- lines = lines.slice(1);
133
- if (lines.at(-1) === "")
134
- lines = lines.slice(0, -1);
135
- else if (!endsWithNewline && !isCompleteRecord(lines.at(-1)))
136
- lines = lines.slice(0, -1);
137
- return { lines, truncated: start > 0 };
138
- }
139
- catch (error) {
140
- return { lines: [], truncated: false, warning: `Transcript could not be read: ${errorMessage(error)}` };
141
- }
142
- finally {
143
- if (fd !== undefined)
144
- fs.closeSync(fd);
145
- }
146
- }
147
- function clipMessage(text) {
148
- if (text.length <= MAX_MESSAGE_CHARS)
149
- return text;
150
- return `${text.slice(0, MAX_MESSAGE_CHARS)}\n\n… message truncated`;
151
- }
152
- function safeTranscriptEvent(event) {
153
- if (event.kind === "assistant") {
154
- return {
155
- ...event,
156
- text: safeDisplayText(event.text),
157
- ...(event.model ? { model: safeDisplayText(event.model) } : {}),
158
- };
159
- }
160
- if (event.kind === "user" || event.kind === "notice") {
161
- return { ...event, text: safeDisplayText(event.text) };
162
- }
163
- return {
164
- ...event,
165
- name: safeDisplayText(event.name),
166
- ...(event.args !== undefined ? { args: safeDisplayText(event.args) } : {}),
167
- ...(event.argsPayload !== undefined ? { argsPayload: safeToolArgsPayload(event.argsPayload) } : {}),
168
- ...(event.output !== undefined ? { output: safeDisplayText(event.output) } : {}),
169
- ...(event.error !== undefined ? { error: safeDisplayText(event.error) } : {}),
170
- };
171
- }
172
- function findTool(events, toolCallId, name) {
173
- if (toolCallId) {
174
- for (let index = events.length - 1; index >= 0; index--) {
175
- const event = events[index];
176
- if (event?.kind === "tool" && event.toolCallId === toolCallId)
177
- return event;
178
- }
179
- return undefined;
180
- }
181
- for (let index = events.length - 1; index >= 0; index--) {
182
- const event = events[index];
183
- if (event?.kind !== "tool")
184
- continue;
185
- const tool = event;
186
- if ((!name || tool.name === name) && !tool.resultSeen)
187
- return tool;
188
- }
189
- return undefined;
190
- }
191
- function appendTextEvent(events, kind, text, metadata) {
192
- const clipped = clipMessage(text.trim());
193
- if (!clipped)
194
- return;
195
- const previous = events.at(-1);
196
- if (previous?.kind === kind && previous.text === clipped)
197
- return;
198
- events.push({ kind, text: clipped, ...metadata });
199
- }
200
- function parseTranscriptLines(lines, conversationStarted = false) {
201
- const events = [];
202
- let malformed = 0;
203
- let explicitTruncation = false;
204
- let assistantSeen = conversationStarted;
205
- for (const line of lines) {
206
- if (!line.trim())
207
- continue;
208
- let record;
209
- try {
210
- record = objectValue(JSON.parse(line));
211
- }
212
- catch {
213
- malformed++;
214
- continue;
215
- }
216
- if (!record) {
217
- malformed++;
218
- continue;
219
- }
220
- const recordType = stringValue(record.recordType);
221
- const timestamp = numberValue(record.ts);
222
- if (recordType === "truncated") {
223
- explicitTruncation = true;
224
- continue;
225
- }
226
- if (recordType === "tool_start") {
227
- const name = stringValue(record.toolName) ?? "tool";
228
- events.push({
229
- kind: "tool",
230
- ...(stringValue(record.toolCallId) ? { toolCallId: stringValue(record.toolCallId) } : {}),
231
- name,
232
- ...(stringValue(record.argsPreview) ? { args: stringValue(record.argsPreview) } : {}),
233
- ...(stringValue(record.argsPayload) ? { argsPayload: stringValue(record.argsPayload) } : {}),
234
- status: "running",
235
- ...(timestamp !== undefined ? { timestamp, startedAt: timestamp } : {}),
236
- });
237
- continue;
238
- }
239
- if (recordType === "tool_end") {
240
- const tool = findTool(events, stringValue(record.toolCallId), stringValue(record.toolName));
241
- if (tool && !tool.resultSeen)
242
- tool.status = record.isError === true ? "error" : "complete";
243
- if (tool && timestamp !== undefined && tool.endedAt === undefined)
244
- tool.endedAt = timestamp;
245
- continue;
246
- }
247
- if (recordType === "stderr") {
248
- const text = stringValue(record.text);
249
- if (text)
250
- events.push({ kind: "notice", text: clipMessage(text), tone: "error", ...(timestamp !== undefined ? { timestamp } : {}) });
251
- continue;
252
- }
253
- if (recordType !== "message")
254
- continue;
255
- const message = objectValue(record.message);
256
- const role = stringValue(record.role) ?? stringValue(message?.role);
257
- const text = stringValue(record.text) ?? stringValue(message?.text) ?? stringValue(message?.content);
258
- if (role === "toolResult" || role === "tool_result") {
259
- const toolCallId = stringValue(record.toolCallId) ?? stringValue(message?.toolCallId);
260
- const name = stringValue(record.toolName) ?? stringValue(message?.toolName) ?? "tool";
261
- const failed = record.isError === true || message?.isError === true;
262
- let tool = findTool(events, toolCallId, name);
263
- if (!tool) {
264
- tool = {
265
- kind: "tool",
266
- ...(toolCallId ? { toolCallId } : {}),
267
- name,
268
- status: failed ? "error" : "complete",
269
- ...(timestamp !== undefined ? { timestamp } : {}),
270
- };
271
- events.push(tool);
272
- }
273
- if (!tool.resultSeen) {
274
- tool.resultSeen = true;
275
- tool.status = failed ? "error" : "complete";
276
- if (timestamp !== undefined && tool.endedAt === undefined)
277
- tool.endedAt = timestamp;
278
- if (text && (!failed || tool.output === undefined)) {
279
- tool.output = clipMessage(text);
280
- tool.outputTruncated = record.outputTruncated === true || text.includes("… payload truncated") || text.includes("[Showing lines");
281
- }
282
- if (failed && text)
283
- tool.error = clipMessage(text.split(/\r?\n/).find((candidate) => candidate.trim()) ?? text);
284
- }
285
- continue;
286
- }
287
- if (role === "assistant") {
288
- assistantSeen = true;
289
- // The transcript writer records the assistant message's provider-local id, which can itself contain a slash.
290
- const rawModel = stringValue(record.model) ?? stringValue(message?.model);
291
- const provider = stringValue(message?.provider);
292
- const model = rawModel && provider ? `${provider}/${rawModel}` : rawModel;
293
- if (text)
294
- appendTextEvent(events, "assistant", text, {
295
- ...(model ? { model } : {}),
296
- ...(timestamp !== undefined ? { timestamp } : {}),
297
- });
298
- continue;
299
- }
300
- if (role === "user" && assistantSeen && text) {
301
- appendTextEvent(events, "user", text, timestamp !== undefined ? { timestamp } : {});
302
- }
303
- }
304
- for (const event of events) {
305
- if (event.kind === "tool")
306
- delete event.resultSeen;
307
- }
308
- return { events: events.map(safeTranscriptEvent), malformed, explicitTruncation };
309
- }
310
- export function readFleetTranscript(filePath, options) {
311
- const validated = validateTranscriptPath(filePath, options.trustedRoots, options.trustedFiles, options.trustedFileRoot);
312
- if (!validated.resolvedPath) {
313
- return { path: filePath, events: [], truncated: false, readFailed: true, ...(validated.warning ? { warning: safeDisplayText(validated.warning) } : {}) };
314
- }
315
- const maxRecords = Math.max(1, options.maxRecords ?? DEFAULT_MAX_RECORDS);
316
- const tail = readTailLines(validated.resolvedPath, Math.max(1024, options.maxBytes ?? DEFAULT_MAX_BYTES));
317
- const recordsOmitted = tail.truncated || tail.lines.length > maxRecords;
318
- const selectedLines = tail.lines.slice(-maxRecords);
319
- const parsed = parseTranscriptLines(selectedLines, recordsOmitted);
320
- const warnings = [
321
- tail.warning,
322
- parsed.malformed > 0 ? `Skipped ${parsed.malformed} malformed transcript record${parsed.malformed === 1 ? "" : "s"}.` : undefined,
323
- ].filter((value) => Boolean(value));
324
- return {
325
- path: filePath,
326
- events: parsed.events,
327
- truncated: tail.truncated || tail.lines.length > maxRecords || parsed.explicitTruncation,
328
- ...(tail.warning ? { readFailed: true } : {}),
329
- ...(warnings.length ? { warning: safeDisplayText(warnings.join(" ")) } : {}),
330
- };
331
- }
332
6
  function statusGlyph(event, theme) {
333
7
  if (event.status === "running")
334
8
  return theme.fg("warning", "●");
package/src/tui/fleet.js CHANGED
@@ -17,9 +17,11 @@ import { stopAsyncRun } from "../runs/foreground/async-stop-action.js";
17
17
  import { resolveWorkflowForegroundSteeringTarget, steerWorkflowForegroundTarget } from "../runs/foreground/workflow-foreground-steering.js";
18
18
  import { contextModeBadge, contextModeLabel } from "../runs/shared/context-mode.js";
19
19
  import { foregroundChildStateLabel } from "../runs/foreground/foreground-history.js";
20
- import { FLEET_STATUS_WIDGET_KEY, reportFleetWarning } from "./fleet-status.js";
20
+ import { FLEET_STATUS_WIDGET_KEY } from "./fleet-status.js";
21
+ import { reportSessionWarning } from "../shared/session-warnings.js";
21
22
  import { stepTaskSummary } from "./render.js";
22
- import { readFleetTranscript, renderFleetTranscript } from "./fleet-transcript.js";
23
+ import { renderFleetTranscript } from "./fleet-transcript.js";
24
+ import { readFleetTranscript } from "../shared/fleet-transcript-reader.js";
23
25
  import { runningTone } from "./running-tone.js";
24
26
  import { childThinkingLevel } from "../shared/model-info.js";
25
27
  import { handleInspectorAction } from "../inspectors/actions.js";
@@ -222,7 +224,7 @@ export function collectFleetSnapshot(state, options = {}) {
222
224
  entryLimit: MAX_FLEET_HISTORY_CANDIDATES,
223
225
  resultsDir: options.resultsDir ?? DIRS.results,
224
226
  reconcile: false,
225
- onCorruptStatus: (warning) => reportFleetWarning(state, warning),
227
+ onCorruptStatus: (warning) => reportSessionWarning(state, warning),
226
228
  }).filter((run) => !trackedIds.has(run.id));
227
229
  runs = [...trackedRuns, ...history];
228
230
  }
@@ -238,7 +240,7 @@ export function collectFleetSnapshot(state, options = {}) {
238
240
  }
239
241
  if (state.currentSessionId) {
240
242
  try {
241
- for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportFleetWarning(state, `Removed ${message}`) })) {
243
+ for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportSessionWarning(state, `Removed ${message}`) })) {
242
244
  items.push({
243
245
  key: `external:${run.id}`,
244
246
  kind: "external",
@@ -1,6 +1,3 @@
1
- /**
2
- * Rendering functions for subagent results
3
- */
4
1
  import type { AgentToolResult } from "@earendil-works/pi-agent-core";
5
2
  import { type ExtensionContext } from "@earendil-works/pi-coding-agent";
6
3
  import { type Component } from "@earendil-works/pi-tui";
@@ -50,16 +47,10 @@ export declare function inlineWorkflowRenderKey(job: AsyncJobState, children: As
50
47
  /** Presentation-only coverage from the mounted inline Fleet roster, never configuration. */
51
48
  export declare function setInlineWorkflowCoverage(ui: ExtensionContext["ui"], coverage: ReadonlyMap<string, string>): void;
52
49
  export declare function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width?: number, expanded?: boolean, frame?: number): string[];
53
- /**
54
- * Render the async jobs widget
55
- */
56
50
  export declare function renderWidget(ctx: ExtensionContext, jobs: AsyncJobState[], initiallyCollapsed?: boolean, layout?: AsyncWidgetLayout): void;
57
51
  export declare function renderSubagentSummary(result: AgentToolResult<Details>, options: {
58
52
  isPartial?: boolean;
59
53
  }, theme: Theme): Component;
60
- /**
61
- * Render a subagent result
62
- */
63
54
  export declare function renderSubagentResult(result: AgentToolResult<Details>, options: {
64
55
  expanded: boolean;
65
56
  }, theme: Theme, frame?: number, rendererConfig?: MainWindowRendererConfig, foregroundDetachShortcut?: string): Component;