@vicary/pi-subagents 0.88.1 → 0.89.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 (88) hide show
  1. package/CHANGELOG.md +36 -1
  2. package/bundle/agents.js +3 -3
  3. package/bundle/child-tool-plan.js +2 -2
  4. package/bundle/{chunk-7OX6O7DQ.js → chunk-443LPCRI.js} +5 -5
  5. package/bundle/{chunk-4QFZZV3O.js → chunk-4AL6LDBY.js} +3 -1
  6. package/bundle/{chunk-6CG2VAG4.js → chunk-4ALRHKGE.js} +1 -1
  7. package/bundle/{chunk-4ZQBZDF3.js → chunk-6JD4XCA4.js} +76 -18
  8. package/bundle/{chunk-CGWNA6EJ.js → chunk-7JLNWAMO.js} +21 -21
  9. package/bundle/{chunk-LV3CPYXJ.js → chunk-7W2IQFP4.js} +4 -4
  10. package/bundle/{chunk-W6HIYD2Z.js → chunk-A3INCQ6Z.js} +1 -1
  11. package/bundle/{chunk-IYT7X46U.js → chunk-CFIYO2IV.js} +5 -5
  12. package/bundle/{chunk-CYKNHFXB.js → chunk-EPMRDKQT.js} +1 -1
  13. package/bundle/{chunk-RMZAAXIR.js → chunk-ETDE2VYK.js} +2 -2
  14. package/bundle/{chunk-4MVDMA5C.js → chunk-GHJ6BH5U.js} +13 -7
  15. package/bundle/{chunk-PYKBTBY6.js → chunk-HSHLPYCQ.js} +9 -9
  16. package/bundle/{chunk-D32H53HM.js → chunk-HZDLR73C.js} +1 -1
  17. package/bundle/{chunk-2DIEL4WG.js → chunk-JFACGAJT.js} +2 -2
  18. package/bundle/{chunk-L4YY2TOE.js → chunk-JRO2CU4D.js} +1 -1
  19. package/bundle/{chunk-KXW62VBU.js → chunk-KOLLMZ2X.js} +1 -1
  20. package/bundle/{chunk-AZPP3G4N.js → chunk-LEPIY76E.js} +34 -5
  21. package/bundle/{chunk-BKISQ5CJ.js → chunk-MJHQIUU7.js} +56 -34
  22. package/bundle/{chunk-47ZN7NKR.js → chunk-NONHDYXE.js} +1 -1
  23. package/bundle/{chunk-DSHQWGHO.js → chunk-NQ26PJSQ.js} +96 -96
  24. package/bundle/{chunk-2HKPEANZ.js → chunk-OVBUEVOT.js} +26 -15
  25. package/bundle/{chunk-JQTHG2ID.js → chunk-PFZZMVD5.js} +74 -31
  26. package/bundle/{chunk-YDZ7BZD5.js → chunk-S77ZKDLS.js} +1 -1
  27. package/bundle/{chunk-CPSUJHZE.js → chunk-SLLZJ5EC.js} +39 -10
  28. package/bundle/{chunk-V7SZMS6W.js → chunk-SWL2EITY.js} +2 -2
  29. package/bundle/{chunk-XIA5GSEU.js → chunk-UQT2EQ4U.js} +2 -2
  30. package/bundle/{chunk-5EMPFFO4.js → chunk-WW6GQBBS.js} +4 -4
  31. package/bundle/{chunk-GDR2ILWY.js → chunk-ZSCIHMUI.js} +50 -22
  32. package/bundle/control-channel.js +2 -2
  33. package/bundle/index.js +2 -2
  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 +10 -4
  38. package/docs/configuration.md +2 -0
  39. package/docs/extension-api.md +1 -1
  40. package/docs/tool-reference.md +1 -1
  41. package/docs/workflows.md +5 -3
  42. package/package.json +2 -2
  43. package/src/extension/herdr-pi-bridge.js +78 -22
  44. package/src/extension/schemas.js +1 -1
  45. package/src/extension/subagent-options.js +5 -0
  46. package/src/intercom/result-intercom.js +3 -2
  47. package/src/runs/background/notify.d.ts +3 -0
  48. package/src/runs/background/notify.js +7 -2
  49. package/src/runs/background/run-status.js +3 -2
  50. package/src/runs/background/runner-child-launch.js +1 -0
  51. package/src/runs/background/subagent-runner.js +11 -8
  52. package/src/runs/foreground/execution.js +8 -7
  53. package/src/runs/foreground/subagent-executor.js +31 -5
  54. package/src/runs/shared/child-launch.d.ts +2 -0
  55. package/src/runs/shared/child-launch.js +1 -1
  56. package/src/runs/shared/child-session.d.ts +2 -1
  57. package/src/runs/shared/herdr-connection.d.ts +6 -0
  58. package/src/runs/shared/herdr-connection.js +11 -1
  59. package/src/runs/shared/herdr-machine.d.ts +2 -2
  60. package/src/runs/shared/herdr-machine.js +47 -22
  61. package/src/runs/shared/herdr-pane-host.d.ts +7 -19
  62. package/src/runs/shared/herdr-pane-host.js +48 -33
  63. package/src/runs/shared/herdr-pi-protocol.d.ts +1 -0
  64. package/src/runs/shared/herdr-pi-protocol.js +3 -2
  65. package/src/runs/shared/herdr-placed-run.d.ts +2 -12
  66. package/src/runs/shared/herdr-placed-run.js +10 -8
  67. package/src/runs/shared/kept-branch-text.d.ts +8 -0
  68. package/src/runs/shared/kept-branch-text.js +24 -0
  69. package/src/runs/shared/local-machine-access.d.ts +4 -1
  70. package/src/runs/shared/local-machine-access.js +6 -3
  71. package/src/runs/shared/mutation-evidence.d.ts +7 -1
  72. package/src/runs/shared/mutation-evidence.js +18 -2
  73. package/src/runs/shared/parallel-handoff.js +19 -7
  74. package/src/runs/shared/placed-run-owner.d.ts +4 -2
  75. package/src/runs/shared/placed-run-owner.js +15 -7
  76. package/src/runs/shared/rex-machine.d.ts +7 -3
  77. package/src/runs/shared/rex-machine.js +12 -9
  78. package/src/runs/shared/rex-pane-host.js +7 -27
  79. package/src/runs/shared/single-output.js +2 -2
  80. package/src/runs/shared/subagent-prompt-runtime.js +33 -0
  81. package/src/runs/shared/tool-availability.d.ts +4 -0
  82. package/src/runs/shared/tool-availability.js +7 -0
  83. package/src/runs/shared/worktree-cleanup-plan.js +2 -2
  84. package/src/runs/shared/worktree.d.ts +4 -14
  85. package/src/runs/shared/worktree.js +38 -8
  86. package/src/shared/types.d.ts +26 -2
  87. package/src/workflows/workflow-child-summary.d.ts +2 -1
  88. package/src/workflows/workflow-child-summary.js +14 -6
@@ -8,7 +8,7 @@ import {
8
8
  projectTimeoutRecovery,
9
9
  readAsyncRecoveryDescriptor,
10
10
  utf8Tail
11
- } from "./chunk-4ZQBZDF3.js";
11
+ } from "./chunk-6JD4XCA4.js";
12
12
  import {
13
13
  MAX_ARGS_BYTES,
14
14
  MAX_ARGS_DEPTH,
@@ -21,10 +21,10 @@ import {
21
21
  resultFilePath,
22
22
  resultPayloadMatchesSessionRun,
23
23
  resultPayloadPathForSessionRun
24
- } from "./chunk-CPSUJHZE.js";
24
+ } from "./chunk-SLLZJ5EC.js";
25
25
  import {
26
26
  PROJECT_SUBAGENTS_RELATIVE_DIR
27
- } from "./chunk-YDZ7BZD5.js";
27
+ } from "./chunk-S77ZKDLS.js";
28
28
  import {
29
29
  listBackgroundWorkWakeChannels,
30
30
  snapshotBackgroundWork
@@ -50,7 +50,7 @@ import {
50
50
  waitToolName,
51
51
  withSettingsFileLease,
52
52
  writePrivateAtomicJson
53
- } from "./chunk-4MVDMA5C.js";
53
+ } from "./chunk-GHJ6BH5U.js";
54
54
  import {
55
55
  DIRS,
56
56
  INTERCOM_DETACH_REQUEST_EVENT,
@@ -906,7 +906,7 @@ var SubagentParamProperties = {
906
906
  usageBudget: Type2.Optional(UsageBudgetOverride),
907
907
  agentScope: Type2.Optional(Type2.String({ description: "user/project/both (default); project wins collisions." })),
908
908
  cwd: Type2.Optional(Type2.String({ description: "Execution/project-pane directory." })),
909
- machine: Type2.Optional(Type2.String({ minLength: 1, maxLength: 128, description: 'Herdr saved machine id or label (runs an external CLI agent), a Rex host named in settings (runs a Pi child), or "local" (a Pi child in a Rex pane here). On another machine, cwd is a directory there.' })),
909
+ machine: Type2.Optional(Type2.String({ minLength: 1, maxLength: 128, description: 'Herdr saved machine id or label (runs an external CLI agent), a Rex host named in settings (runs a Pi child), or "local" (a Pi child in a new tab of the Herdr or Rex session this Pi runs in). On another machine, cwd is a directory there.' })),
910
910
  requireLauncher: Type2.Optional(Type2.Object({
911
911
  name: Type2.String({ pattern: RUNNER_LAUNCHER_NAME_PATTERN.source }),
912
912
  definitionDigest: Type2.String({ pattern: "^[0-9a-f]{64}$" })
@@ -11,7 +11,7 @@ import {
11
11
  readStatus,
12
12
  writeAtomicJson,
13
13
  writePrivateAtomicJson
14
- } from "./chunk-4MVDMA5C.js";
14
+ } from "./chunk-GHJ6BH5U.js";
15
15
  import {
16
16
  ASYNC_DIR,
17
17
  INTERCOM_DETACH_REQUEST_EVENT,
@@ -11,13 +11,13 @@ import {
11
11
  validateAuthorityPolicy,
12
12
  validateMissionStoreConfig,
13
13
  validateModelResponseAliases
14
- } from "./chunk-CPSUJHZE.js";
14
+ } from "./chunk-SLLZJ5EC.js";
15
15
  import {
16
16
  getAgentDir,
17
17
  readStatus,
18
18
  validatePermissionConfig,
19
19
  writePrivateAtomicJson
20
- } from "./chunk-4MVDMA5C.js";
20
+ } from "./chunk-GHJ6BH5U.js";
21
21
  import {
22
22
  FLEET_KEYBINDING_ACTIONS,
23
23
  RUNNER_LAUNCHER_NAME_PATTERN,
@@ -6561,6 +6561,9 @@ var REX_EXIT_UNREACHABLE = 4;
6561
6561
  function isRexLocalMachine(machine) {
6562
6562
  return machine?.provider === "rex" && !("target" in machine);
6563
6563
  }
6564
+ function editsLocalDisk(machine) {
6565
+ return machine !== void 0 && !("target" in machine);
6566
+ }
6564
6567
  var REX_BUNDLE_BIN = "Library/Application Support/com.superlogical.rex/RexServer/Versions/Current/Rex Server.app/Contents/MacOS/rex";
6565
6568
  var REX_CALL_TIMEOUT_MS = 15e3;
6566
6569
  var REX_MAX_OUTPUT = 1024 * 1024;
@@ -6604,9 +6607,12 @@ function resolveRexLocalPlacement(input) {
6604
6607
  if (result.status === REX_EXIT_UNREACHABLE) throw new Error("Machine 'local' needs the Rex server, but it is unreachable.");
6605
6608
  if (result.status !== 0) throw new Error(`rex session inspect exited with code ${result.status}: ${(result.stderr || result.stdout).trim().slice(0, 512)}`);
6606
6609
  if (!sessionConfirmed(result.stdout, session)) throw new Error(`The Rex server did not confirm session ${session}.`);
6607
- const stepCwd = input.stepCwd?.trim();
6608
- const home = stepCwd === "~" || stepCwd?.startsWith("~/") ? path12.join(os4.homedir(), stepCwd.slice(1)) : void 0;
6609
- const requested = home ?? (stepCwd ? path12.resolve(input.cwd, stepCwd) : input.cwd);
6610
+ return { provider: "rex", id: REX_LOCAL_MACHINE, session, cwd: resolveLocalLaunchCwd(input.cwd, input.stepCwd), ...server ? { server } : {} };
6611
+ }
6612
+ function resolveLocalLaunchCwd(parentCwd, stepCwd) {
6613
+ const step = stepCwd?.trim();
6614
+ const home = step === "~" || step?.startsWith("~/") ? path12.join(os4.homedir(), step.slice(1)) : void 0;
6615
+ const requested = home ?? (step ? path12.resolve(parentCwd, step) : parentCwd);
6610
6616
  let cwd;
6611
6617
  try {
6612
6618
  cwd = fs12.realpathSync(requested);
@@ -6614,9 +6620,7 @@ function resolveRexLocalPlacement(input) {
6614
6620
  throw new Error(`Machine 'local' cwd does not exist: ${requested}.`, { cause: error });
6615
6621
  }
6616
6622
  if (!fs12.statSync(cwd).isDirectory()) throw new Error(`Machine 'local' cwd is not a directory: ${requested}.`);
6617
- const machine = { provider: "rex", id: REX_LOCAL_MACHINE, session, cwd };
6618
- if (server) machine.server = server;
6619
- return machine;
6623
+ return cwd;
6620
6624
  }
6621
6625
 
6622
6626
  // src/runs/shared/single-output.ts
@@ -6701,7 +6705,7 @@ function outputPathMappingFromTask(task, savedPath) {
6701
6705
  }
6702
6706
  function injectSingleOutputInstruction(task, outputPath, capabilities, machine) {
6703
6707
  if (!outputPath) return task;
6704
- const remote = machine !== void 0 && !isRexLocalMachine(machine);
6708
+ const remote = machine !== void 0 && !editsLocalDisk(machine);
6705
6709
  const delivery = !remote && (!capabilities || hasOutputWriteCapability(capabilities.tools, capabilities.mcpDirectTools)) ? `Write your findings to exactly this path: ${outputPath}` : [
6706
6710
  "Return the complete artifact in your final response.",
6707
6711
  `The runtime will persist it to exactly this path: ${outputPath}`,
@@ -8629,6 +8633,7 @@ export {
8629
8633
  REX_EXIT_GONE,
8630
8634
  REX_EXIT_UNREACHABLE,
8631
8635
  isRexLocalMachine,
8636
+ editsLocalDisk,
8632
8637
  REX_BUNDLE_BIN,
8633
8638
  REX_CALL_TIMEOUT_MS,
8634
8639
  REX_MAX_OUTPUT,
@@ -8636,6 +8641,7 @@ export {
8636
8641
  resolveRexBinary,
8637
8642
  rexCommandEnv,
8638
8643
  resolveRexLocalPlacement,
8644
+ resolveLocalLaunchCwd,
8639
8645
  extractChildWrittenOutput,
8640
8646
  normalizeSingleOutputOverride,
8641
8647
  resolveSingleOutputPath,
@@ -7,37 +7,37 @@ import {
7
7
  safeTranscriptEvent,
8
8
  steerAsyncRun,
9
9
  steerWorkflowForegroundTarget
10
- } from "./chunk-7OX6O7DQ.js";
10
+ } from "./chunk-443LPCRI.js";
11
11
  import {
12
12
  FLEET_STATUS_WIDGET_KEY,
13
13
  runningTone,
14
14
  stepTaskSummary
15
- } from "./chunk-5EMPFFO4.js";
15
+ } from "./chunk-WW6GQBBS.js";
16
16
  import {
17
17
  foregroundChildStateLabel,
18
18
  formatAsyncRunTranscript,
19
19
  stopAsyncRun
20
- } from "./chunk-LV3CPYXJ.js";
20
+ } from "./chunk-7W2IQFP4.js";
21
21
  import {
22
22
  contextModeBadge,
23
23
  contextModeLabel,
24
24
  decodeUtf8Tail,
25
25
  listAsyncRuns
26
- } from "./chunk-4ZQBZDF3.js";
26
+ } from "./chunk-6JD4XCA4.js";
27
27
  import {
28
28
  reportSessionWarning
29
29
  } from "./chunk-HXRB42AF.js";
30
- import "./chunk-CPSUJHZE.js";
31
- import "./chunk-W6HIYD2Z.js";
30
+ import "./chunk-SLLZJ5EC.js";
31
+ import "./chunk-A3INCQ6Z.js";
32
32
  import "./chunk-NIXWDZZV.js";
33
- import "./chunk-47ZN7NKR.js";
33
+ import "./chunk-NONHDYXE.js";
34
34
  import "./chunk-7F6RKT6W.js";
35
35
  import "./chunk-YARY7JWU.js";
36
36
  import "./chunk-7J4ZXMY7.js";
37
37
  import {
38
38
  getArtifactPaths,
39
39
  getArtifactsDir
40
- } from "./chunk-YDZ7BZD5.js";
40
+ } from "./chunk-S77ZKDLS.js";
41
41
  import {
42
42
  snapshotExternalRuns
43
43
  } from "./chunk-UKG4V45O.js";
@@ -49,7 +49,7 @@ import {
49
49
  formatTokens,
50
50
  readStatus,
51
51
  shortenPath
52
- } from "./chunk-4MVDMA5C.js";
52
+ } from "./chunk-GHJ6BH5U.js";
53
53
  import {
54
54
  DIRS
55
55
  } from "./chunk-JEZOSEWG.js";
@@ -7,7 +7,7 @@ import {
7
7
  getAgentDir,
8
8
  getConfigDirName,
9
9
  getProjectConfigDir
10
- } from "./chunk-4MVDMA5C.js";
10
+ } from "./chunk-GHJ6BH5U.js";
11
11
  import {
12
12
  TEMP_ROOT_DIR
13
13
  } from "./chunk-JEZOSEWG.js";
@@ -3,11 +3,11 @@ import {
3
3
  } from "./chunk-7J4ZXMY7.js";
4
4
  import {
5
5
  getProjectSubagentsDir
6
- } from "./chunk-YDZ7BZD5.js";
6
+ } from "./chunk-S77ZKDLS.js";
7
7
  import {
8
8
  getPiSpawnCommand,
9
9
  writeAtomicJson
10
- } from "./chunk-4MVDMA5C.js";
10
+ } from "./chunk-GHJ6BH5U.js";
11
11
 
12
12
  // src/inspectors/herdr/project-panes.ts
13
13
  import * as fs from "node:fs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  registerRuntimeAgent
3
- } from "./chunk-KXW62VBU.js";
3
+ } from "./chunk-KOLLMZ2X.js";
4
4
 
5
5
  // src/agents/runtime-agent-events.ts
6
6
  var RUNTIME_AGENT_REGISTER_EVENT = "pi-subagents:runtime-agent-register:v1";
@@ -8,7 +8,7 @@ import {
8
8
  validateCodeOwnedProfileRunner,
9
9
  validatePermissionRules,
10
10
  validateToolBudgetConfig
11
- } from "./chunk-4MVDMA5C.js";
11
+ } from "./chunk-GHJ6BH5U.js";
12
12
 
13
13
  // src/agents/runtime-agent-registry.ts
14
14
  var RUNTIME_AGENT_REGISTRY_KEY = "pi-subagents.runtime-agents.v1";
@@ -14,20 +14,20 @@ import {
14
14
  resolveCurrentSessionId,
15
15
  resolveWatchdogReviewModel,
16
16
  startWatchdogDiffBaselineCapture
17
- } from "./chunk-IYT7X46U.js";
17
+ } from "./chunk-CFIYO2IV.js";
18
18
  import {
19
19
  agentStreamOptions,
20
20
  opencodeSessionHeaders
21
- } from "./chunk-4ZQBZDF3.js";
21
+ } from "./chunk-6JD4XCA4.js";
22
22
  import {
23
23
  registerNativeSupervisorClient
24
- } from "./chunk-CYKNHFXB.js";
24
+ } from "./chunk-EPMRDKQT.js";
25
25
  import {
26
26
  MODEL_ONLY_TOOL
27
27
  } from "./chunk-HXRB42AF.js";
28
28
  import {
29
29
  inheritedNestedRouteOf
30
- } from "./chunk-CPSUJHZE.js";
30
+ } from "./chunk-SLLZJ5EC.js";
31
31
  import {
32
32
  CHILD_WATCHDOG_STATUS_EVENT,
33
33
  DEFAULT_WAIT_TOOL_NAME,
@@ -46,7 +46,7 @@ import {
46
46
  toolBudgetSoftNudge,
47
47
  validateAcceptanceReport,
48
48
  validateStructuredOutputValue
49
- } from "./chunk-4MVDMA5C.js";
49
+ } from "./chunk-GHJ6BH5U.js";
50
50
  import {
51
51
  INTERCOM_SESSION_IDENTITY_EVENT
52
52
  } from "./chunk-JEZOSEWG.js";
@@ -84,6 +84,13 @@ function projectRuntimeAcknowledgedExtensions(ids) {
84
84
  // src/runs/shared/tool-availability.ts
85
85
  function formatChildToolDiagnostic(diagnostic, options = {}) {
86
86
  const subject = diagnostic.agent ? `Agent '${diagnostic.agent}'` : "Subagent";
87
+ if (diagnostic.undeclared?.length) {
88
+ const uncallable = diagnostic.uncallable?.length ? ` and added ${diagnostic.uncallable.join(", ")}, which this child cannot call` : "";
89
+ return [
90
+ `${subject} declares tools: ${diagnostic.required.join(", ")}, but an extension loaded in this child replaced the tools sent to the model: it left out ${diagnostic.undeclared.join(", ")}${uncallable}.`,
91
+ "The `tools` field is a strict allowlist. Set `extensions: []` or list only the extensions this child needs, or omit `tools` to use that extension's tool surface."
92
+ ].join("\n");
93
+ }
87
94
  if (options.host === "parent") {
88
95
  return [
89
96
  `${subject} ran as a foreground child, which never loads the parent's ambient extensions, and these child tools were unavailable: ${diagnostic.missing.join(", ")}.`,
@@ -533,7 +540,29 @@ function filterChildPromptOptions(options, inherited) {
533
540
  function rewritesChildPrompt(config) {
534
541
  return config.inheritProjectContext !== void 0 || config.inheritGlobalContext !== void 0 || config.inheritSkills !== void 0 || Boolean(config.fanoutChild);
535
542
  }
543
+ function registerDeclaredToolCheck(pi, config, required) {
544
+ pi.on("context_with_system", (event, ctx) => {
545
+ const declared = new Set(getCurrentTools(event.messages).map((tool) => tool.name));
546
+ if (required.every((name) => declared.has(name))) return void 0;
547
+ const registered = new Set(pi.getAllTools().map((tool) => tool.name));
548
+ const undeclared = required.filter((name) => registered.has(name) && !declared.has(name));
549
+ if (undeclared.length === 0) return void 0;
550
+ const active = new Set(pi.getActiveTools());
551
+ const uncallable = config.forkCacheKey ? [] : [...declared].filter((name) => !active.has(name));
552
+ config.toolDiagnostic?.({
553
+ ...config.agent ? { agent: config.agent } : {},
554
+ required: [...required],
555
+ available: [...registered],
556
+ missing: [],
557
+ undeclared,
558
+ ...uncallable.length > 0 ? { uncallable } : {}
559
+ });
560
+ ctx.abort();
561
+ return void 0;
562
+ });
563
+ }
536
564
  function registerSubagentPromptBoundary(pi, config) {
565
+ if (config.requiredTools) registerDeclaredToolCheck(pi, config, config.requiredTools);
537
566
  if (!rewritesChildPrompt(config)) return;
538
567
  if (config.forkCacheKey) return;
539
568
  pi.on("before_agent_start", (event) => {
@@ -3,7 +3,7 @@ import {
3
3
  projectRuntimeAcknowledgedExtensions,
4
4
  registerSubagentPromptBoundary,
5
5
  registerSubagentPromptRuntime
6
- } from "./chunk-AZPP3G4N.js";
6
+ } from "./chunk-LEPIY76E.js";
7
7
  import {
8
8
  INSPECTOR_ACTIONS,
9
9
  canQueueRetainedAsyncFollowUp,
@@ -25,12 +25,12 @@ import {
25
25
  updateSteeringTarget,
26
26
  waitForSteeringAction,
27
27
  workflowAsyncChildSteeringGuidance
28
- } from "./chunk-7OX6O7DQ.js";
28
+ } from "./chunk-443LPCRI.js";
29
29
  import {
30
30
  PLACED_RESTORE_UNSUPPORTED,
31
31
  formatHerdrMachineRunnerUnsupported,
32
32
  resolveMachinePlacement
33
- } from "./chunk-GDR2ILWY.js";
33
+ } from "./chunk-ZSCIHMUI.js";
34
34
  import {
35
35
  COMPLETION_ACTION,
36
36
  DEFAULT_CONTROL_CONFIG,
@@ -119,7 +119,7 @@ import {
119
119
  workflowScriptDigest,
120
120
  workflowStopCause,
121
121
  writeWorkflowReceipt
122
- } from "./chunk-2HKPEANZ.js";
122
+ } from "./chunk-OVBUEVOT.js";
123
123
  import {
124
124
  SUBAGENT_PARENT_SESSION_ENV,
125
125
  applyWatchdogLaunchRules,
@@ -132,7 +132,7 @@ import {
132
132
  resolveWatchdogConfig,
133
133
  sendRuleViolationWarning,
134
134
  writeWatchdogModelSettings
135
- } from "./chunk-IYT7X46U.js";
135
+ } from "./chunk-CFIYO2IV.js";
136
136
  import {
137
137
  MAX_REMEMBERED_FOREGROUND_RUNS,
138
138
  discardRunningForegroundRun,
@@ -145,7 +145,7 @@ import {
145
145
  resolveSubagentRunId,
146
146
  resolveWorkflowChatProgress,
147
147
  stopAsyncRun
148
- } from "./chunk-LV3CPYXJ.js";
148
+ } from "./chunk-7W2IQFP4.js";
149
149
  import {
150
150
  RunFanoutLimitError,
151
151
  annotateWorkflowPreflightTrace,
@@ -165,6 +165,7 @@ import {
165
165
  formatAsyncRunProgressLabel,
166
166
  formatNestedRunStatusLines,
167
167
  formatParallelHandoffError,
168
+ formatParallelHandoffLines,
168
169
  formatParallelHandoffReference,
169
170
  formatRunFanoutBudget,
170
171
  formatStoredParallelHandoffCleanup,
@@ -191,6 +192,8 @@ import {
191
192
  recordParallelHandoffMerge,
192
193
  recordParallelHandoffSupersession,
193
194
  recoveryDescriptorPath,
195
+ remoteMutationEvidence,
196
+ remoteMutationSnapshot,
194
197
  resolveAsyncResumeTarget,
195
198
  resolveAsyncRunLocation,
196
199
  resolveAsyncStatusChild,
@@ -206,12 +209,12 @@ import {
206
209
  writeRunFanoutBudgetDescriptor,
207
210
  writeWorkflowLaunchRecord,
208
211
  writeWorktreeSetupHandoff
209
- } from "./chunk-4ZQBZDF3.js";
212
+ } from "./chunk-6JD4XCA4.js";
210
213
  import {
211
214
  NATIVE_SUPERVISOR_TOOL_NAME,
212
215
  createNativeSupervisorChannel,
213
216
  resolveSupervisorChannelDir
214
- } from "./chunk-CYKNHFXB.js";
217
+ } from "./chunk-EPMRDKQT.js";
215
218
  import {
216
219
  MODEL_ONLY_TOOL,
217
220
  inheritedSessionIds,
@@ -234,10 +237,10 @@ import {
234
237
  canPreferFork,
235
238
  createForkContextResolver,
236
239
  resolveSubagentLaunchContext
237
- } from "./chunk-V7SZMS6W.js";
240
+ } from "./chunk-SWL2EITY.js";
238
241
  import {
239
242
  handleRefinementAction
240
- } from "./chunk-XIA5GSEU.js";
243
+ } from "./chunk-UQT2EQ4U.js";
241
244
  import {
242
245
  ActiveAsyncCapacityError,
243
246
  acquireActiveAsyncCapacity,
@@ -253,7 +256,7 @@ import {
253
256
  resolveDisabledFeatureSurface,
254
257
  resolveMaxActiveAsyncRunsPerSession,
255
258
  transferActiveAsyncCapacity
256
- } from "./chunk-RMZAAXIR.js";
259
+ } from "./chunk-ETDE2VYK.js";
257
260
  import {
258
261
  DEFAULT_STALE_TERMINAL_ACTIVE_MARKER_MS,
259
262
  MACHINE_DIFF_OPTIONS,
@@ -290,6 +293,7 @@ import {
290
293
  inheritedNestedParentAddressOf,
291
294
  inheritedNestedRouteOf,
292
295
  initializeProcessTerminal,
296
+ isWorktreeCleanupTaskDone,
293
297
  lookupRunnerLauncher,
294
298
  missionAcceptanceStatus,
295
299
  nestedResultsPath,
@@ -339,7 +343,7 @@ import {
339
343
  writeNestedControlRequest,
340
344
  writeNestedControlResult,
341
345
  writeNestedEvent
342
- } from "./chunk-CPSUJHZE.js";
346
+ } from "./chunk-SLLZJ5EC.js";
343
347
  import {
344
348
  closeSteerInbox,
345
349
  consumeSteerRequests,
@@ -347,7 +351,7 @@ import {
347
351
  readRevivalBriefs,
348
352
  requestAsyncSteer,
349
353
  watchAsyncControlInbox
350
- } from "./chunk-W6HIYD2Z.js";
354
+ } from "./chunk-A3INCQ6Z.js";
351
355
  import "./chunk-NIXWDZZV.js";
352
356
  import {
353
357
  INTERCOM_BRIDGE_MARKER,
@@ -356,7 +360,7 @@ import {
356
360
  resolveIntercomBridge,
357
361
  resolveIntercomSessionTarget,
358
362
  resolveSubagentIntercomTarget
359
- } from "./chunk-47ZN7NKR.js";
363
+ } from "./chunk-NONHDYXE.js";
360
364
  import {
361
365
  agentDefinitionDigest,
362
366
  resolveLaunchBinding,
@@ -371,7 +375,7 @@ import {
371
375
  resolvePiLaunchToolPlan,
372
376
  resolveRuntimeModulePath,
373
377
  supervisorChannelDir
374
- } from "./chunk-D32H53HM.js";
378
+ } from "./chunk-HZDLR73C.js";
375
379
  import {
376
380
  assertRequiredChildExtensionsAdmitted,
377
381
  createRequiredChildExtensionIdentity,
@@ -383,7 +387,7 @@ import {
383
387
  import {
384
388
  HERDR_PROJECT_PANE_ACTIONS,
385
389
  handleHerdrProjectPaneAction
386
- } from "./chunk-2DIEL4WG.js";
390
+ } from "./chunk-JFACGAJT.js";
387
391
  import "./chunk-7J4ZXMY7.js";
388
392
  import {
389
393
  PROJECT_SUBAGENTS_RELATIVE_DIR,
@@ -397,12 +401,12 @@ import {
397
401
  missingForkCopyNote,
398
402
  writeArtifact,
399
403
  writeMetadata
400
- } from "./chunk-YDZ7BZD5.js";
404
+ } from "./chunk-S77ZKDLS.js";
401
405
  import "./chunk-XA3DY6UG.js";
402
406
  import {
403
407
  getExternalJobProvider
404
408
  } from "./chunk-YYREO77V.js";
405
- import "./chunk-KXW62VBU.js";
409
+ import "./chunk-KOLLMZ2X.js";
406
410
  import {
407
411
  ChainOutputValidationError,
408
412
  DEFAULT_WAIT_TOOL_NAME,
@@ -449,6 +453,7 @@ import {
449
453
  discoverAgentsAll,
450
454
  discoverAvailableSkills,
451
455
  editDistance,
456
+ editsLocalDisk,
452
457
  encodeExtensionBindings,
453
458
  evaluateAcceptance,
454
459
  externalCliReceiptMetadata,
@@ -486,7 +491,6 @@ import {
486
491
  isDynamicRunnerGroup,
487
492
  isParallelGroup,
488
493
  isParallelStep,
489
- isRexLocalMachine,
490
494
  isSettlementFatalOutputError,
491
495
  isStorageCapacityError,
492
496
  isToolBudgetBlockedMessage,
@@ -556,7 +560,7 @@ import {
556
560
  writeAtomicJson,
557
561
  writeInitialProgressFile,
558
562
  writePrivateAtomicJson
559
- } from "./chunk-4MVDMA5C.js";
563
+ } from "./chunk-GHJ6BH5U.js";
560
564
  import {
561
565
  CHAIN_RUNS_DIR,
562
566
  DEFAULT_ARTIFACT_CONFIG,
@@ -1370,7 +1374,7 @@ ${input.systemPrompt}` : void 0;
1370
1374
  cwd: input.cwd,
1371
1375
  ...input.machine ? { machine: input.machine } : {},
1372
1376
  ...input.projectTrusted !== void 0 ? { projectTrusted: input.projectTrusted } : {},
1373
- ...input.machine ? { remoteResources: { agent: input.childAgentName, ...input.remoteSkillNames ? { skills: input.remoteSkillNames } : {}, ...input.remoteReads !== void 0 ? { reads: input.remoteReads } : {}, ...toolPlan.explicitToolAllowlist ? { toolCeiling: [...toolPlan.effectiveToolAllowlist] } : toolPlan.capabilityCeiling?.allowedTools ? { toolCeiling: [...toolPlan.capabilityCeiling.allowedTools] } : {} } } : {},
1377
+ ...input.machine ? { remoteResources: { agent: input.childAgentName, ...input.remoteSkillNames ? { skills: input.remoteSkillNames } : {}, ...input.remoteReads !== void 0 ? { reads: input.remoteReads } : {}, ...toolPlan.explicitToolAllowlist ? { toolCeiling: [...toolPlan.effectiveToolAllowlist] } : toolPlan.capabilityCeiling?.allowedTools ? { toolCeiling: [...toolPlan.capabilityCeiling.allowedTools] } : {}, ...input.acceptancePrompt ? { acceptancePrompt: input.acceptancePrompt } : {} } } : {},
1374
1378
  storage: childStorage(input),
1375
1379
  ...input.parentSessionFile ? { parentSessionFile: input.parentSessionFile } : {},
1376
1380
  ...input.model ? { model: input.model } : {},
@@ -5392,6 +5396,7 @@ async function runSingleAttempt(runtimeCwd, agent, task, model, options, shared)
5392
5396
  machine: options.machine,
5393
5397
  remoteSkillNames: options.skills ?? agent.skills,
5394
5398
  remoteReads: options.remoteReads,
5399
+ acceptancePrompt: shared.acceptancePrompt,
5395
5400
  extensionBindings: options.extensionBindings,
5396
5401
  requiredExtensions: options.requiredExtensions,
5397
5402
  sessionEnabled: shared.sessionEnabled,
@@ -5510,6 +5515,7 @@ ${shared.acceptancePrompt}` : shared.systemPrompt,
5510
5515
  index: options.index ?? 0,
5511
5516
  agent: agent.name,
5512
5517
  ...childSessionName ? { sessionName: childSessionName } : {},
5518
+ ...options.sessionFile ? { sessionFile: options.sessionFile } : {},
5513
5519
  status: "running",
5514
5520
  task,
5515
5521
  skills: shared.resolvedSkillNames,
@@ -5549,8 +5555,8 @@ ${shared.acceptancePrompt}` : shared.systemPrompt,
5549
5555
  };
5550
5556
  return result2;
5551
5557
  }
5552
- const mutationCwd = isRexLocalMachine(options.machine) ? options.machine.cwd : options.cwd ?? runtimeCwd;
5553
- const mutationSnapshot = options.machine && !isRexLocalMachine(options.machine) ? { source: "tracked-files", trackedOnly: true, cwd: mutationCwd, dirtyFiles: [], fingerprints: {}, unavailable: "Local Git evidence is not authoritative for a pane-native remote run." } : snapshotTrackedMutations(mutationCwd);
5558
+ const mutationCwd = editsLocalDisk(options.machine) ? options.machine.cwd : options.cwd ?? runtimeCwd;
5559
+ const mutationSnapshot = options.machine && !editsLocalDisk(options.machine) ? remoteMutationSnapshot(mutationCwd) : snapshotTrackedMutations(mutationCwd);
5554
5560
  let structuredOutputToolInvoked = false;
5555
5561
  let structuredOutputMessageStartIndex;
5556
5562
  let toolAvailabilityError;
@@ -6498,8 +6504,7 @@ ${formatInheritedProviderDiagnostic({ agent: agent.name, model: launch.session.m
6498
6504
  tokens: progress.tokens,
6499
6505
  durationMs: progress.durationMs
6500
6506
  };
6501
- const remoteGitChanged = result2.nativeMachine?.initialGit && result2.nativeMachine.finalGit ? result2.nativeMachine.initialGit.head !== result2.nativeMachine.finalGit.head || result2.nativeMachine.initialGit.dirty !== result2.nativeMachine.finalGit.dirty : void 0;
6502
- const mutationEvidence = result2.nativeMachine && !isRexLocalMachine(options.machine) ? { source: "tracked-files", trackedOnly: true, changedFiles: [], attemptedMutation: remoteGitChanged === true, ...remoteGitChanged === void 0 ? { unavailable: "Remote Git before/after evidence was incomplete." } : {} } : await collectTrackedMutationEvidence(mutationSnapshot, mutationCwd);
6507
+ const mutationEvidence = result2.nativeMachine && !editsLocalDisk(options.machine) ? remoteMutationEvidence(result2.nativeMachine) : await collectTrackedMutationEvidence(mutationSnapshot, mutationCwd);
6503
6508
  const acceptanceOutput = getFinalOutput(result2.messages ?? []);
6504
6509
  const structuredText = result2.structuredOutput === void 0 ? void 0 : JSON.stringify(result2.structuredOutput, null, 2);
6505
6510
  let fullOutput = stripAcceptanceReport(acceptanceOutput);
@@ -6591,7 +6596,7 @@ function writeStructuredOutputArtifacts(runtime, value, acceptanceReport) {
6591
6596
  }
6592
6597
  async function runSyncCompletionInner(runtimeCwd, agents, agentName, task, options) {
6593
6598
  const effectiveCwd = options.cwd ?? runtimeCwd;
6594
- const cwdError = options.machine && !isRexLocalMachine(options.machine) ? void 0 : preflightLaunchCwd(options.requestedCwd ?? effectiveCwd, effectiveCwd);
6599
+ const cwdError = options.machine && !editsLocalDisk(options.machine) ? void 0 : preflightLaunchCwd(options.requestedCwd ?? effectiveCwd, effectiveCwd);
6595
6600
  if (cwdError) {
6596
6601
  return redactResultPrompt(withRunContext({
6597
6602
  index: options.index ?? 0,
@@ -8925,7 +8930,7 @@ Extensions denied: ${status.capabilityCeiling.denyExtensions ? "yes" : "no"} (so
8925
8930
  status.turnBudget ? `Turn budget: ${status.turnBudget.turnCount}/${status.turnBudget.maxTurns}+${status.turnBudget.graceTurns} (${status.turnBudget.outcome})` : void 0,
8926
8931
  `Dir: ${asyncDir}`,
8927
8932
  outputPath ? `Output: ${outputPath}` : void 0,
8928
- status.parallelHandoff ? `Parallel handoff: ${status.parallelHandoff.path}` : void 0,
8933
+ ...status.parallelHandoff ? formatParallelHandoffLines(status.parallelHandoff.path, status.parallelHandoff.keptBranches) : [],
8929
8934
  reconciliation.message ? `Diagnosis: ${reconciliation.message}` : void 0,
8930
8935
  reconciliation.resultPath && fs17.existsSync(reconciliation.resultPath) ? `Result: ${reconciliation.resultPath}` : void 0
8931
8936
  ].filter((line) => Boolean(line));
@@ -9061,7 +9066,7 @@ Extensions denied: ${status.capabilityCeiling.denyExtensions ? "yes" : "no"} (so
9061
9066
  const status = data.state === "stopped" || data.stopped === true || childStatuses.includes("stopped") ? "stopped" : data.success ? "complete" : data.state === "paused" || data.exitCode === 0 ? "paused" : "failed";
9062
9067
  const runId = data.runId ?? data.id ?? resolvedId;
9063
9068
  const lines = [`Run: ${runId}`, data.toolCallId ? `Tool call: ${data.toolCallId}` : void 0, `State: ${status}`, `Result: ${resultPath}`].filter((line) => Boolean(line));
9064
- if (data.parallelHandoff?.path) lines.push(`Parallel handoff: ${data.parallelHandoff.path}`);
9069
+ if (data.parallelHandoff?.path) lines.push(...formatParallelHandoffLines(data.parallelHandoff.path, data.parallelHandoff.keptBranches));
9065
9070
  const receipt = data.workflowReceipt;
9066
9071
  const receiptPath = receipt && typeof receipt === "object" && !Array.isArray(receipt) ? receipt.path : void 0;
9067
9072
  const workflowReceiptPath2 = typeof receiptPath === "string" && receiptPath ? receiptPath : void 0;
@@ -9649,7 +9654,7 @@ function buildUnknownGitEntry(input) {
9649
9654
  return blockedEntry(entry, "unknown", "unknown", "no matching extension-owned handoff metadata was found");
9650
9655
  }
9651
9656
  function buildMissingMetadataEntry(input) {
9652
- if (input.record.task.worktreeRemoved && input.record.task.branchRemoved) return void 0;
9657
+ if (isWorktreeCleanupTaskDone(input.record.task)) return void 0;
9653
9658
  const pathValue = metadataRecordPath(input.record);
9654
9659
  const entry = buildEntryBase({ path: pathValue, branch: input.record.task.branch, source: "metadata", metadata: input.record, targetHead: input.targetHead });
9655
9660
  return blockedEntry(entry, "stale", "unknown", "handoff metadata records a worktree that is not present in Git worktree state");
@@ -12803,6 +12808,16 @@ function writeWorkflowAggregateOutput(outputPath, text, producedChildOutputPaths
12803
12808
  ${error instanceof Error ? error.message : String(error)}`;
12804
12809
  }
12805
12810
  }
12811
+ function removeEarlierWorkflowOutput(outputPath) {
12812
+ if (!outputPath) return void 0;
12813
+ try {
12814
+ fs20.rmSync(outputPath, { force: true });
12815
+ return void 0;
12816
+ } catch (error) {
12817
+ return `Output file error: ${outputPath}
12818
+ ${error instanceof Error ? error.message : String(error)}`;
12819
+ }
12820
+ }
12806
12821
  function appendWorkflowOutputWarning(text, warning) {
12807
12822
  return warning ? `${text}
12808
12823
 
@@ -14904,6 +14919,7 @@ Parent action: ${STATUS_ACTION}`,
14904
14919
  step.async = runId2 !== void 0 && path18.basename(runId2) === runId2 && fs20.existsSync(path18.join(path18.dirname(asyncDir), runId2));
14905
14920
  persist({ tolerateStatusWriteFailure: true });
14906
14921
  };
14922
+ const earlierOutputWarning2 = workflowReuseSource ? void 0 : removeEarlierWorkflowOutput(workflowAggregateOutputPath2);
14907
14923
  try {
14908
14924
  const workflow = await runWorkflowScript({
14909
14925
  script: workflowScript,
@@ -15212,7 +15228,7 @@ Parent action: ${COMPLETION_ACTION}` : content,
15212
15228
  }
15213
15229
  const errorPreview = status.error && status.error.length > 1e3 ? `${status.error.slice(0, 1e3)}\u2026 (truncated; full error: ${statusPath} (error))` : status.error;
15214
15230
  const terminalSummary = `${status.state === "complete" ? "Workflow completed after detached child finished." : errorPreview ?? (pauseForDetached ? "Workflow paused." : "Workflow failed.")}${stopCause ? ` ${WORKFLOW_RUNTIME_REPLACED_STOP_NOTICE}` : ""}${workflowOutputPathMappingSummary2(partial.children)}${finalPreflightWarnings.length ? ` ${finalPreflightWarnings.join(" ")}` : ""}`;
15215
- const outputWarning = writeWorkflowAggregateOutput(workflowAggregateOutputPath2, terminalSummary, producedChildOutputPaths2);
15231
+ const outputWarning = status.state === "complete" ? writeWorkflowAggregateOutput(workflowAggregateOutputPath2, terminalSummary, producedChildOutputPaths2) : earlierOutputWarning2;
15216
15232
  const resultSummary = appendWorkflowOutputWarning(terminalSummary, outputWarning);
15217
15233
  const receiptState = status.state === "complete" ? "complete" : status.state === "paused" ? "paused" : status.state === "stopped" ? "stopped" : "failed";
15218
15234
  const terminalOutcome = workflowFailureTerminalOutcome(error, partial.children, usageBudgetState(workflowUsageBudget.budget, sumResultsCost(workflowResults2)));
@@ -15288,6 +15304,7 @@ Parent action: ${COMPLETION_ACTION}` : content,
15288
15304
  const liveWorkflowChildren = workflowChildSummary({ parentToolCallId: _id, workflowRunId: foregroundWorkflowRunId, workflowState: "running", inventoryComplete: false, trace: liveWorkflow.trace, progress: childProgress, launches: childLaunches });
15289
15305
  onUpdate?.(workflowProgressUpdate(foregroundWorkflowRunId, chatProgress, liveWorkflow, liveWorkflowChildren, workflowPreflight));
15290
15306
  };
15307
+ const earlierOutputWarning = removeEarlierWorkflowOutput(workflowAggregateOutputPath);
15291
15308
  try {
15292
15309
  const workflow = await runWorkflowScript({
15293
15310
  script: requestParams.workflowScript,
@@ -15369,7 +15386,11 @@ Parent action: ${COMPLETION_ACTION}` : content,
15369
15386
  (deps2.state.blockingWorkflowChildren ??= /* @__PURE__ */ new Set()).add(launch.runId);
15370
15387
  blockingWorkflowChildren.add(launch.runId);
15371
15388
  }
15372
- childLaunches.set(key, { agent: launch.agent, ...launch.runId ? { runId: launch.runId } : {} });
15389
+ childLaunches.set(key, {
15390
+ agent: launch.agent,
15391
+ ...launch.runId ? { runId: launch.runId } : {},
15392
+ ...launch.sessionFile ? { sessionFile: launch.sessionFile } : {}
15393
+ });
15373
15394
  try {
15374
15395
  sendWorkflowProgress();
15375
15396
  } catch (error) {
@@ -15462,7 +15483,7 @@ ${workflow.console.map((entry) => `[${entry.level}] ${entry.text}`).join("\n")}`
15462
15483
  const finalPreflightTrace = annotateWorkflowPreflightTrace(partial.trace, workflowPreflight);
15463
15484
  const trace = finalPreflightTrace.map((entry) => ({ line: `- ${entry.operation} ${entry.key}: ${entry.state}${entry.runId ? ` (${entry.runId})` : ""}${entry.warning ? ` \u2014 ${entry.warning}` : ""}`, error: entry.error }));
15464
15485
  const outputMappings = workflowOutputPathMappingSummary2(partial.children).trim();
15465
- const displayText = formatWorkflowResultText({
15486
+ const displayText = appendWorkflowOutputWarning(formatWorkflowResultText({
15466
15487
  head: workflowPreflight ? [formatWorkflowPreflight(workflowPreflight)] : [],
15467
15488
  script: [
15468
15489
  `Workflow failed: ${text}`,
@@ -15477,10 +15498,11 @@ ${partial.console.map((entry) => `[${entry.level}] ${entry.text}`).join("\n")}`]
15477
15498
  ...outputMappings ? [outputMappings] : []
15478
15499
  ],
15479
15500
  maxOutput: requestParams.maxOutput,
15480
- aggregateOutputPath: workflowAggregateOutputPath,
15501
+ // A failed workflow's text never goes to the declared output file; truncated text goes to the full-result file.
15502
+ aggregateOutputPath: void 0,
15481
15503
  fullResultPath: workflowFullResultPath,
15482
15504
  producedChildOutputPaths
15483
- });
15505
+ }), earlierOutputWarning);
15484
15506
  const workflowChildren = workflowChildSummary({ parentToolCallId: _id, workflowRunId: foregroundWorkflowRunId, workflowState: "failed", inventoryComplete: true, trace: partial.trace, children: partial.children });
15485
15507
  const terminalOutcome = workflowFailureTerminalOutcome(error, partial.children, usageBudgetState(workflowUsageBudget.budget, sumResultsCost(workflowResults)));
15486
15508
  const receipt = terminalWorkflowReceipt(foregroundWorkflowRunId, "failed", partial.children, workflowChildren, terminalOutcome, [...workflowHostSteps.values()], workflowResource?.provenance, workflowArgsDigest);
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-7F6RKT6W.js";
4
4
  import {
5
5
  getAgentDir
6
- } from "./chunk-4MVDMA5C.js";
6
+ } from "./chunk-GHJ6BH5U.js";
7
7
 
8
8
  // src/intercom/intercom-bridge.ts
9
9
  import * as fs from "node:fs";