@xzzpig/pi-subagents 0.25.0 → 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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.25.1] - 2026-11-15 (fork)
4
+
5
+ ### Changed
6
+
7
+ - **Conflict-surface refactor, no behavior change.** Fleet transcript reading now
8
+ lives in one shared reader (`shared/fleet-transcript-reader.ts`); the TUI fleet
9
+ pane only keeps its renderer, so both the run-status and transcript views parse
10
+ child sessions through the same code.
11
+ - The fork's tool-result handler moved out of the upstream run closure into
12
+ fork-only `src/runs/foreground/fork-tool-result-handler.ts` (budget blocking,
13
+ mutating-failure escalation, supervisor progress publication, bounded
14
+ call-id de-duplication unchanged); `execution.ts` keeps one factory call.
15
+ - Packaging identity (repository URL, files allowlist, lockfile policy) is
16
+ enforced by `scripts/check-fork-identity.mjs` instead of per-package replay prose.
17
+
3
18
  ## [0.25.0] - 2026-11-13 (fork)
4
19
 
5
20
  ### Changed
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  getLivePromptAudit,
3
3
  handleInspectorAction,
4
+ objectValue,
4
5
  readFleetTranscript,
6
+ readTranscriptRecords,
5
7
  resolveWorkflowForegroundSteeringTarget,
8
+ safeTranscriptEvent,
6
9
  steerAsyncRun,
7
10
  steerWorkflowForegroundTarget
8
- } from "./chunk-IUDEI6FJ.js";
11
+ } from "./chunk-MMJQMPOK.js";
9
12
  import {
10
13
  FLEET_STATUS_WIDGET_KEY,
11
14
  emitUiSpanSilent,
@@ -15,7 +18,6 @@ import {
15
18
  import {
16
19
  foregroundChildStateLabel,
17
20
  formatAsyncRunTranscript,
18
- isTrustedRecordedSessionFile,
19
21
  stopAsyncRun
20
22
  } from "./chunk-ULGMXABL.js";
21
23
  import "./chunk-7J4ZXMY7.js";
@@ -59,8 +61,8 @@ import {
59
61
  } from "./chunk-YFCK7H2S.js";
60
62
 
61
63
  // src/tui/fleet.ts
62
- import * as fs2 from "node:fs";
63
- import * as path2 from "node:path";
64
+ import * as fs from "node:fs";
65
+ import * as path from "node:path";
64
66
  import {
65
67
  getMarkdownTheme
66
68
  } from "@earendil-works/pi-coding-agent";
@@ -147,175 +149,9 @@ function parseMouseWheelEvent(data) {
147
149
  }
148
150
 
149
151
  // src/tui/fleet-transcript.ts
150
- import * as fs from "node:fs";
151
- import * as path from "node:path";
152
152
  import { getLanguageFromPath, highlightCode } from "@earendil-works/pi-coding-agent";
153
153
  import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
154
- var DEFAULT_MAX_RECORDS = 240;
155
- var DEFAULT_MAX_BYTES = 2 * 1024 * 1024;
156
- var MAX_MESSAGE_CHARS = 64 * 1024;
157
154
  var TOOL_PREVIEW_LINES = 7;
158
- function sanitizeJsonDisplayValue(value) {
159
- if (typeof value === "string") {
160
- const safe = safeTerminalText(value);
161
- return { value: safe, changed: safe !== value };
162
- }
163
- if (Array.isArray(value)) {
164
- const sanitized = value.map(sanitizeJsonDisplayValue);
165
- return {
166
- value: sanitized.map((entry) => entry.value),
167
- changed: sanitized.some((entry) => entry.changed)
168
- };
169
- }
170
- if (value && typeof value === "object") {
171
- let changed = false;
172
- const sanitized = /* @__PURE__ */ Object.create(null);
173
- for (const [key, nested] of Object.entries(value)) {
174
- const safeKey = safeTerminalText(key);
175
- const safeValue = sanitizeJsonDisplayValue(nested);
176
- sanitized[safeKey] = safeValue.value;
177
- changed ||= safeKey !== key || safeValue.changed;
178
- }
179
- return { value: changed ? sanitized : value, changed };
180
- }
181
- return { value, changed: false };
182
- }
183
- function safeToolArgsPayload(payload) {
184
- try {
185
- const sanitized = sanitizeJsonDisplayValue(JSON.parse(payload));
186
- return sanitized.changed ? JSON.stringify(sanitized.value) : safeTerminalText(payload);
187
- } catch {
188
- return safeTerminalText(payload);
189
- }
190
- }
191
- function objectValue(value) {
192
- return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
193
- }
194
- function pathWithin(base, candidate) {
195
- const resolvedBase = path.resolve(base);
196
- const resolvedCandidate = path.resolve(candidate);
197
- return resolvedCandidate === resolvedBase || resolvedCandidate.startsWith(`${resolvedBase}${path.sep}`);
198
- }
199
- function errorMessage(error) {
200
- return error instanceof Error ? error.message : String(error);
201
- }
202
- function isNotFoundError(error) {
203
- return Boolean(objectValue(error)?.code === "ENOENT");
204
- }
205
- function validateTranscriptPath(filePath, trustedRoots, trustedFiles = [], trustedFileRoot) {
206
- if (trustedRoots.length === 0 && (!trustedFileRoot || trustedFiles.length === 0)) return { warning: `Transcript preview has no trusted root: ${filePath}` };
207
- const resolvedPath = path.resolve(filePath);
208
- const recordedCandidate = trustedFileRoot && pathWithin(trustedFileRoot, resolvedPath) && trustedFiles.some((file) => path.resolve(file) === resolvedPath);
209
- if (!trustedRoots.some((root) => pathWithin(root, resolvedPath)) && !recordedCandidate) {
210
- return { warning: `Transcript is outside trusted roots: ${filePath}` };
211
- }
212
- let stat;
213
- try {
214
- stat = fs.lstatSync(resolvedPath);
215
- } catch (error) {
216
- if (isNotFoundError(error)) return {};
217
- return { warning: `Transcript could not be inspected: ${errorMessage(error)}` };
218
- }
219
- if (stat.isSymbolicLink()) return { warning: `Transcript preview refused a symlink: ${filePath}` };
220
- if (!stat.isFile()) return { warning: `Transcript path is not a file: ${filePath}` };
221
- try {
222
- const realPath = fs.realpathSync(resolvedPath);
223
- const realRoots = trustedRoots.filter((root) => fs.existsSync(root)).map((root) => fs.realpathSync(root));
224
- if (!realRoots.some((root) => pathWithin(root, realPath)) && !isTrustedRecordedSessionFile(realPath, trustedFiles, trustedFileRoot)) {
225
- return { warning: `Transcript resolves outside trusted roots: ${filePath}` };
226
- }
227
- return { resolvedPath: realPath };
228
- } catch (error) {
229
- return { warning: `Transcript path could not be resolved: ${errorMessage(error)}` };
230
- }
231
- }
232
- function isCompleteRecord(line) {
233
- if (!line?.trim()) return false;
234
- try {
235
- return objectValue(JSON.parse(line)) !== void 0;
236
- } catch {
237
- return false;
238
- }
239
- }
240
- function readTailLines(filePath, maxBytes) {
241
- let fd;
242
- try {
243
- const noFollow = typeof fs.constants.O_NOFOLLOW === "number" ? fs.constants.O_NOFOLLOW : 0;
244
- fd = fs.openSync(filePath, fs.constants.O_RDONLY | noFollow);
245
- const stat = fs.fstatSync(fd);
246
- if (!stat.isFile()) return { lines: [], truncated: false, warning: `Transcript path is not a file: ${filePath}` };
247
- if (stat.size === 0) return { lines: [], truncated: false };
248
- const bytesToRead = Math.min(stat.size, maxBytes);
249
- const start = stat.size - bytesToRead;
250
- const buffer = Buffer.alloc(bytesToRead);
251
- const bytesRead = fs.readSync(fd, buffer, 0, bytesToRead, start);
252
- const content = buffer.subarray(0, bytesRead).toString("utf-8");
253
- const endsWithNewline = content.endsWith("\n");
254
- let lines = content.split(/\r?\n/);
255
- if (start > 0 && lines.length > 0) lines = lines.slice(1);
256
- if (lines.at(-1) === "") lines = lines.slice(0, -1);
257
- else if (!endsWithNewline && !isCompleteRecord(lines.at(-1))) lines = lines.slice(0, -1);
258
- return { lines, truncated: start > 0 };
259
- } catch (error) {
260
- return { lines: [], truncated: false, warning: `Transcript could not be read: ${errorMessage(error)}` };
261
- } finally {
262
- if (fd !== void 0) fs.closeSync(fd);
263
- }
264
- }
265
- function safeTranscriptEvent(event) {
266
- if (event.kind === "assistant") {
267
- return {
268
- ...event,
269
- text: safeTerminalText(event.text),
270
- ...event.model ? { model: safeTerminalText(event.model) } : {}
271
- };
272
- }
273
- if (event.kind === "user" || event.kind === "notice") {
274
- return { ...event, text: safeTerminalText(event.text) };
275
- }
276
- return {
277
- ...event,
278
- name: safeTerminalText(event.name),
279
- ...event.args !== void 0 ? { args: safeTerminalText(event.args) } : {},
280
- ...event.argsPayload !== void 0 ? { argsPayload: safeToolArgsPayload(event.argsPayload) } : {},
281
- ...event.output !== void 0 ? { output: safeTerminalText(event.output) } : {},
282
- ...event.error !== void 0 ? { error: safeTerminalText(event.error) } : {}
283
- };
284
- }
285
- function readTranscriptRecords(filePath, options) {
286
- const validated = validateTranscriptPath(filePath, options.trustedRoots);
287
- if (!validated.resolvedPath) {
288
- return { records: [], truncated: false, readFailed: true, ...validated.warning ? { warning: safeTerminalText(validated.warning) } : {} };
289
- }
290
- const maxRecords = Math.max(1, options.maxRecords ?? DEFAULT_MAX_RECORDS);
291
- const tail = readTailLines(validated.resolvedPath, Math.max(1024, options.maxBytes ?? DEFAULT_MAX_BYTES));
292
- const selected = tail.lines.slice(-maxRecords);
293
- const records = [];
294
- let malformed = 0;
295
- for (const line of selected) {
296
- if (!line.trim()) continue;
297
- try {
298
- const parsed = JSON.parse(line);
299
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
300
- records.push(parsed);
301
- } else {
302
- malformed++;
303
- }
304
- } catch {
305
- malformed++;
306
- }
307
- }
308
- const warnings = [
309
- tail.warning,
310
- malformed > 0 ? `Skipped ${malformed} malformed transcript record${malformed === 1 ? "" : "s"}.` : void 0
311
- ].filter((value) => Boolean(value));
312
- return {
313
- records,
314
- ...tail.warning ? { readFailed: true } : {},
315
- truncated: tail.truncated || tail.lines.length > maxRecords,
316
- ...warnings.length ? { warning: safeTerminalText(warnings.join(" ")) } : {}
317
- };
318
- }
319
155
  function statusGlyph(event, theme) {
320
156
  if (event.status === "running") return theme.fg("warning", "\u25CF");
321
157
  if (event.status === "error") return theme.fg("error", "\u2717");
@@ -1072,17 +908,17 @@ function foregroundActiveDetail(item, state) {
1072
908
  ];
1073
909
  return lines.filter((line) => line !== void 0);
1074
910
  }
1075
- function pathWithin2(base, candidate) {
1076
- const resolvedBase = path2.resolve(base);
1077
- const resolvedCandidate = path2.resolve(candidate);
1078
- return resolvedCandidate === resolvedBase || resolvedCandidate.startsWith(`${resolvedBase}${path2.sep}`);
911
+ function pathWithin(base, candidate) {
912
+ const resolvedBase = path.resolve(base);
913
+ const resolvedCandidate = path.resolve(candidate);
914
+ return resolvedCandidate === resolvedBase || resolvedCandidate.startsWith(`${resolvedBase}${path.sep}`);
1079
915
  }
1080
916
  function trustedFileTail(filePath, trustedRoots) {
1081
- const resolvedPath = path2.resolve(filePath);
1082
- if (trustedRoots.length === 0 || !trustedRoots.some((root) => pathWithin2(root, resolvedPath))) return { warning: `output artifact is outside trusted roots: ${filePath}` };
917
+ const resolvedPath = path.resolve(filePath);
918
+ if (trustedRoots.length === 0 || !trustedRoots.some((root) => pathWithin(root, resolvedPath))) return { warning: `output artifact is outside trusted roots: ${filePath}` };
1083
919
  let stat;
1084
920
  try {
1085
- stat = fs2.lstatSync(resolvedPath);
921
+ stat = fs.lstatSync(resolvedPath);
1086
922
  } catch (error) {
1087
923
  if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return { unavailable: `output artifact unavailable: ${filePath}` };
1088
924
  return { warning: `output artifact could not be inspected: ${error instanceof Error ? error.message : String(error)}` };
@@ -1090,17 +926,17 @@ function trustedFileTail(filePath, trustedRoots) {
1090
926
  if (stat.isSymbolicLink()) return { warning: `output artifact refused a symlink: ${filePath}` };
1091
927
  if (!stat.isFile()) return { warning: `output artifact is not a file: ${filePath}` };
1092
928
  try {
1093
- const realPath = fs2.realpathSync(resolvedPath);
1094
- const realRoots = trustedRoots.filter((root) => fs2.existsSync(root)).map((root) => fs2.realpathSync(root));
1095
- if (!realRoots.some((root) => pathWithin2(root, realPath))) return { warning: `output artifact resolves outside trusted roots: ${filePath}` };
1096
- const fd = fs2.openSync(realPath, "r");
929
+ const realPath = fs.realpathSync(resolvedPath);
930
+ const realRoots = trustedRoots.filter((root) => fs.existsSync(root)).map((root) => fs.realpathSync(root));
931
+ if (!realRoots.some((root) => pathWithin(root, realPath))) return { warning: `output artifact resolves outside trusted roots: ${filePath}` };
932
+ const fd = fs.openSync(realPath, "r");
1097
933
  try {
1098
934
  const bytes = Math.min(stat.size, OUTPUT_TAIL_BYTES);
1099
935
  const buffer = Buffer.alloc(bytes);
1100
- fs2.readSync(fd, buffer, 0, bytes, stat.size - bytes);
936
+ fs.readSync(fd, buffer, 0, bytes, stat.size - bytes);
1101
937
  return { text: decodeUtf8Tail(buffer) };
1102
938
  } finally {
1103
- fs2.closeSync(fd);
939
+ fs.closeSync(fd);
1104
940
  }
1105
941
  } catch (error) {
1106
942
  return { warning: `output artifact could not be read: ${error instanceof Error ? error.message : String(error)}` };
@@ -1108,7 +944,7 @@ function trustedFileTail(filePath, trustedRoots) {
1108
944
  }
1109
945
  function foregroundRecentOutputLines(item, state) {
1110
946
  const outputPath = item.child.artifactPaths?.outputPath ?? item.child.savedOutputPath;
1111
- const output = item.child.finalOutput ? { text: item.child.finalOutput } : outputPath ? trustedFileTail(path2.isAbsolute(outputPath) ? outputPath : path2.resolve(item.run.cwd, outputPath), uniquePaths([
947
+ const output = item.child.finalOutput ? { text: item.child.finalOutput } : outputPath ? trustedFileTail(path.isAbsolute(outputPath) ? outputPath : path.resolve(item.run.cwd, outputPath), uniquePaths([
1112
948
  fleetArtifactsRoot(state, item.run.cwd),
1113
949
  fleetArtifactsRoot(state, state.baseCwd)
1114
950
  ])) : void 0;
@@ -1206,7 +1042,7 @@ function asyncDetail(item, state) {
1206
1042
  }
1207
1043
  return lines;
1208
1044
  }
1209
- const outputPath = item.index !== void 0 ? path2.join(item.run.asyncDir, `output-${item.index}.log`) : void 0;
1045
+ const outputPath = item.index !== void 0 ? path.join(item.run.asyncDir, `output-${item.index}.log`) : void 0;
1210
1046
  return [
1211
1047
  `Run: ${item.runId}`,
1212
1048
  "Source: async",
@@ -1255,7 +1091,7 @@ function firstToolResultText(result, fallback) {
1255
1091
  return { text, ...result.isError ? { isError: true } : {} };
1256
1092
  }
1257
1093
  function uniquePaths(values) {
1258
- return [...new Set(values.filter((value) => Boolean(value)).map((value) => path2.resolve(value)))];
1094
+ return [...new Set(values.filter((value) => Boolean(value)).map((value) => path.resolve(value)))];
1259
1095
  }
1260
1096
  function fleetArtifactsRoot(state, cwd) {
1261
1097
  return getArtifactsDir(
@@ -1275,7 +1111,7 @@ function transcriptTarget(item, state) {
1275
1111
  }
1276
1112
  if (item.kind === "foreground-recent") {
1277
1113
  if (!item.child.transcriptPath) return void 0;
1278
- const transcriptPath2 = path2.isAbsolute(item.child.transcriptPath) ? item.child.transcriptPath : path2.resolve(item.run.cwd, item.child.transcriptPath);
1114
+ const transcriptPath2 = path.isAbsolute(item.child.transcriptPath) ? item.child.transcriptPath : path.resolve(item.run.cwd, item.child.transcriptPath);
1279
1115
  return {
1280
1116
  path: transcriptPath2,
1281
1117
  trustedRoots: uniquePaths([
@@ -1289,7 +1125,7 @@ function transcriptTarget(item, state) {
1289
1125
  const recordedSessionFile = step?.sessionFile ?? item.run.sessionFile;
1290
1126
  const recordedPath = step?.transcriptPath ?? recordedSessionFile;
1291
1127
  if (!recordedPath) return void 0;
1292
- const transcriptPath = path2.isAbsolute(recordedPath) ? recordedPath : path2.resolve(item.run.asyncDir, recordedPath);
1128
+ const transcriptPath = path.isAbsolute(recordedPath) ? recordedPath : path.resolve(item.run.asyncDir, recordedPath);
1293
1129
  const trackedJob = state.fleetJobs?.get(item.runId) ?? state.asyncJobs.get(item.runId);
1294
1130
  return {
1295
1131
  path: transcriptPath,
@@ -1376,7 +1212,7 @@ function rightAligned(left, right, width) {
1376
1212
  }
1377
1213
  function transcriptFingerprint(filePath) {
1378
1214
  try {
1379
- const stat = fs2.statSync(filePath, { bigint: true });
1215
+ const stat = fs.statSync(filePath, { bigint: true });
1380
1216
  return `${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`;
1381
1217
  } catch {
1382
1218
  return "missing";
@@ -6468,7 +6468,7 @@ function childSessionFactory() {
6468
6468
  }
6469
6469
  function createLazyPlacementFactory(local) {
6470
6470
  let placed;
6471
- const factory = async () => placed ??= (await import("./chunk-OSVXFWPG.js")).createPlacementAwareChildSessionFactory(local);
6471
+ const factory = async () => placed ??= (await import("./chunk-WWDUNXSE.js")).createPlacementAwareChildSessionFactory(local);
6472
6472
  return {
6473
6473
  async create(launch) {
6474
6474
  return launch.machine ? (await factory()).create(launch) : local.create(launch);
@@ -14,7 +14,7 @@ import {
14
14
  } from "./chunk-LZ3HBDTR.js";
15
15
  import {
16
16
  package_default
17
- } from "./chunk-YWXILP5N.js";
17
+ } from "./chunk-TM2K53NX.js";
18
18
  import {
19
19
  EXTERNAL_JOB_BRIDGE_REQUEST_DIR,
20
20
  REVIVAL_ORIGIN_FILE,
@@ -65,7 +65,7 @@ import {
65
65
  snapshotProviderDiagnostics,
66
66
  workflowResumeClaimState,
67
67
  workflowResumeRefusal
68
- } from "./chunk-IJWITCC6.js";
68
+ } from "./chunk-IXCEOEJT.js";
69
69
  import {
70
70
  listHerdrProjectPaneRoots,
71
71
  restoreHerdrProjectPaneSnapshots
@@ -5744,7 +5744,7 @@ function registerSlashCommands(pi, state, options = {}) {
5744
5744
  }
5745
5745
  fleetOpen = true;
5746
5746
  try {
5747
- const { openSubagentFleet } = await import("./chunk-IKFKH5EL.js");
5747
+ const { openSubagentFleet } = await import("./chunk-FQPV4O6C.js");
5748
5748
  await openSubagentFleet(ctx, state, { asyncDirRoot: DIRS.async, inspectorPlugins: () => getInspectorPlugins(pi), resultsDir: DIRS.results, fleetKeybindings: options.fleetKeybindings, events: pi.events });
5749
5749
  } finally {
5750
5750
  fleetOpen = false;
@@ -9213,7 +9213,7 @@ function registerSubagentExtension(pi) {
9213
9213
  const ctx = withLastUiContext((current) => current);
9214
9214
  if (!ctx) return;
9215
9215
  try {
9216
- const { openSubagentFleet } = await import("./chunk-IKFKH5EL.js");
9216
+ const { openSubagentFleet } = await import("./chunk-FQPV4O6C.js");
9217
9217
  await openSubagentFleet(ctx, state, { initialKey: itemKey, asyncDirRoot: DIRS.async, resultsDir: DIRS.results, fleetKeybindings: config.fleetKeybindings, inspectorPlugins: () => getInspectorPlugins(pi), events: pi.events });
9218
9218
  } catch (error) {
9219
9219
  if (isStaleExtensionContextError(error)) {
@@ -9424,7 +9424,7 @@ function registerSubagentExtension(pi) {
9424
9424
  let executor;
9425
9425
  let executorPromise;
9426
9426
  let executorModulePromise;
9427
- const loadExecutorModule = () => executorModulePromise ??= import("./chunk-5YEOWNSD.js");
9427
+ const loadExecutorModule = () => executorModulePromise ??= import("./chunk-KRNBJPZ2.js");
9428
9428
  const getExecutor = () => {
9429
9429
  executorPromise ??= loadExecutorModule().then(({ createSubagentExecutor }) => {
9430
9430
  executor = createSubagentExecutor(executorDeps);
@@ -9438,7 +9438,7 @@ function registerSubagentExtension(pi) {
9438
9438
  modulePreloadTimer = setTimeout(() => {
9439
9439
  loadExecutorModule().catch(() => {
9440
9440
  });
9441
- if (fleetViewEnabled) import("./chunk-IKFKH5EL.js").catch(() => {
9441
+ if (fleetViewEnabled) import("./chunk-FQPV4O6C.js").catch(() => {
9442
9442
  });
9443
9443
  }, MODULE_PRELOAD_DELAY_MS);
9444
9444
  modulePreloadTimer.unref?.();