@xzzpig/pi-subagents 0.24.2 → 0.25.1
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/CHANGELOG.md +37 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/{chunk-RU522D5W.js → chunk-FQPV4O6C.js} +183 -28
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-CYY5UMJU.js → chunk-IXCEOEJT.js} +411 -249
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-224WMDIV.js → chunk-JUYNN63E.js} +350 -123
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-XWWUDWUW.js → chunk-KRNBJPZ2.js} +670 -400
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-JEA2ZKUA.js → chunk-MMJQMPOK.js} +37 -165
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-4UH4WS4G.js → chunk-SNDCIJMK.js} +23 -12
- package/bundle/{chunk-O4D5PBVI.js → chunk-TM2K53NX.js} +3 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-WWDUNXSE.js} +67 -30
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +12 -3
- package/src/extension/schemas.js +7 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +55 -15
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +7 -10
- package/src/runs/background/async-execution.js +66 -29
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/async-steering-action.js +24 -9
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +68 -84
- package/src/runs/foreground/fork-tool-result-handler.d.ts +60 -0
- package/src/runs/foreground/fork-tool-result-handler.js +83 -0
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +6 -5
- package/src/runs/shared/child-session.js +85 -38
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +64 -0
- package/src/shared/fleet-transcript-reader.js +376 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-native-transcript.js +1 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -57
- package/src/tui/fleet-transcript.js +4 -370
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
|
@@ -1,377 +1,11 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
// Fork: the reader (records, validation, event parsing) lives in the shared
|
|
5
|
+
// module; this file only renders a transcript. Keeping the two copies in sync
|
|
6
|
+
// was the fork's largest remaining duplication.
|
|
7
|
+
import { objectValue, safeTranscriptEvent, } from "../shared/fleet-transcript-reader.js";
|
|
10
8
|
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
|
-
/**
|
|
333
|
-
* Shared trusted-root-guarded tail reader that returns raw parsed JSONL
|
|
334
|
-
* records instead of fleet events. Both the legacy rail renderer and the
|
|
335
|
-
* native-component renderer ingest through this single validation path, so
|
|
336
|
-
* symlink refusal and path-escape rejection cannot diverge between them.
|
|
337
|
-
*/
|
|
338
|
-
export function readTranscriptRecords(filePath, options) {
|
|
339
|
-
const validated = validateTranscriptPath(filePath, options.trustedRoots);
|
|
340
|
-
if (!validated.resolvedPath) {
|
|
341
|
-
return { records: [], truncated: false, readFailed: true, ...(validated.warning ? { warning: safeDisplayText(validated.warning) } : {}) };
|
|
342
|
-
}
|
|
343
|
-
const maxRecords = Math.max(1, options.maxRecords ?? DEFAULT_MAX_RECORDS);
|
|
344
|
-
const tail = readTailLines(validated.resolvedPath, Math.max(1024, options.maxBytes ?? DEFAULT_MAX_BYTES));
|
|
345
|
-
const selected = tail.lines.slice(-maxRecords);
|
|
346
|
-
const records = [];
|
|
347
|
-
let malformed = 0;
|
|
348
|
-
for (const line of selected) {
|
|
349
|
-
if (!line.trim())
|
|
350
|
-
continue;
|
|
351
|
-
try {
|
|
352
|
-
const parsed = JSON.parse(line);
|
|
353
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
354
|
-
records.push(parsed);
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
malformed++;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
catch {
|
|
361
|
-
malformed++;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
const warnings = [
|
|
365
|
-
tail.warning,
|
|
366
|
-
malformed > 0 ? `Skipped ${malformed} malformed transcript record${malformed === 1 ? "" : "s"}.` : undefined,
|
|
367
|
-
].filter((value) => Boolean(value));
|
|
368
|
-
return {
|
|
369
|
-
records,
|
|
370
|
-
...(tail.warning ? { readFailed: true } : {}),
|
|
371
|
-
truncated: tail.truncated || tail.lines.length > maxRecords,
|
|
372
|
-
...(warnings.length ? { warning: safeDisplayText(warnings.join(" ")) } : {}),
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
9
|
function statusGlyph(event, theme) {
|
|
376
10
|
if (event.status === "running")
|
|
377
11
|
return theme.fg("warning", "●");
|
package/src/tui/fleet.js
CHANGED
|
@@ -19,9 +19,11 @@ import { stopAsyncRun } from "../runs/foreground/async-stop-action.js";
|
|
|
19
19
|
import { resolveWorkflowForegroundSteeringTarget, steerWorkflowForegroundTarget } from "../runs/foreground/workflow-foreground-steering.js";
|
|
20
20
|
import { contextModeBadge, contextModeLabel } from "../runs/shared/context-mode.js";
|
|
21
21
|
import { foregroundChildStateLabel } from "../runs/foreground/foreground-history.js";
|
|
22
|
-
import { FLEET_STATUS_WIDGET_KEY
|
|
22
|
+
import { FLEET_STATUS_WIDGET_KEY } from "./fleet-status.js";
|
|
23
|
+
import { reportSessionWarning } from "../shared/session-warnings.js";
|
|
23
24
|
import { stepTaskSummary } from "./render.js";
|
|
24
|
-
import {
|
|
25
|
+
import { renderFleetTranscript } from "./fleet-transcript.js";
|
|
26
|
+
import { readFleetTranscript } from "../shared/fleet-transcript-reader.js";
|
|
25
27
|
import { buildNativeFleetTranscript, loadNativeTranscriptSupport } from "./fleet-native-transcript.js";
|
|
26
28
|
import { runningTone } from "./running-tone.js";
|
|
27
29
|
import { childThinkingLevel } from "../shared/model-info.js";
|
|
@@ -228,7 +230,7 @@ export function collectFleetSnapshot(state, options = {}) {
|
|
|
228
230
|
entryLimit: MAX_FLEET_HISTORY_CANDIDATES,
|
|
229
231
|
resultsDir: options.resultsDir ?? DIRS.results,
|
|
230
232
|
reconcile: false,
|
|
231
|
-
onCorruptStatus: (warning) =>
|
|
233
|
+
onCorruptStatus: (warning) => reportSessionWarning(state, warning),
|
|
232
234
|
}).filter((run) => !trackedIds.has(run.id));
|
|
233
235
|
runs = [...trackedRuns, ...history];
|
|
234
236
|
}
|
|
@@ -244,7 +246,7 @@ export function collectFleetSnapshot(state, options = {}) {
|
|
|
244
246
|
}
|
|
245
247
|
if (state.currentSessionId) {
|
|
246
248
|
try {
|
|
247
|
-
for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) =>
|
|
249
|
+
for (const run of snapshotExternalRuns(state.currentSessionId, { ignoreMalformed: true, onMalformedRecord: (message) => reportSessionWarning(state, `Removed ${message}`) })) {
|
|
248
250
|
items.push({
|
|
249
251
|
key: `external:${run.id}`,
|
|
250
252
|
kind: "external",
|
package/src/tui/render.d.ts
CHANGED
|
@@ -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;
|