poe-code 3.0.203 → 3.0.205

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 (110) hide show
  1. package/dist/cli/commands/braintrust.d.ts +3 -0
  2. package/dist/cli/commands/braintrust.js +77 -0
  3. package/dist/cli/commands/braintrust.js.map +1 -0
  4. package/dist/cli/commands/configure.d.ts +1 -0
  5. package/dist/cli/commands/configure.js +197 -0
  6. package/dist/cli/commands/configure.js.map +1 -1
  7. package/dist/cli/commands/experiment.js +42 -5
  8. package/dist/cli/commands/experiment.js.map +1 -1
  9. package/dist/cli/commands/harness.d.ts +3 -0
  10. package/dist/cli/commands/harness.js +260 -0
  11. package/dist/cli/commands/harness.js.map +1 -0
  12. package/dist/cli/commands/pipeline.js +58 -24
  13. package/dist/cli/commands/pipeline.js.map +1 -1
  14. package/dist/cli/commands/ralph.js +8 -3
  15. package/dist/cli/commands/ralph.js.map +1 -1
  16. package/dist/cli/commands/runtime/build.d.ts +7 -0
  17. package/dist/cli/commands/runtime/build.js +128 -0
  18. package/dist/cli/commands/runtime/build.js.map +1 -0
  19. package/dist/cli/commands/runtime/index.d.ts +3 -0
  20. package/dist/cli/commands/runtime/index.js +14 -0
  21. package/dist/cli/commands/runtime/index.js.map +1 -0
  22. package/dist/cli/commands/runtime/init.d.ts +7 -0
  23. package/dist/cli/commands/runtime/init.js +39 -0
  24. package/dist/cli/commands/runtime/init.js.map +1 -0
  25. package/dist/cli/commands/runtime/jobs/attach.d.ts +3 -0
  26. package/dist/cli/commands/runtime/jobs/attach.js +35 -0
  27. package/dist/cli/commands/runtime/jobs/attach.js.map +1 -0
  28. package/dist/cli/commands/runtime/jobs/index.d.ts +3 -0
  29. package/dist/cli/commands/runtime/jobs/index.js +16 -0
  30. package/dist/cli/commands/runtime/jobs/index.js.map +1 -0
  31. package/dist/cli/commands/runtime/jobs/logs.d.ts +3 -0
  32. package/dist/cli/commands/runtime/jobs/logs.js +27 -0
  33. package/dist/cli/commands/runtime/jobs/logs.js.map +1 -0
  34. package/dist/cli/commands/runtime/jobs/ls.d.ts +3 -0
  35. package/dist/cli/commands/runtime/jobs/ls.js +60 -0
  36. package/dist/cli/commands/runtime/jobs/ls.js.map +1 -0
  37. package/dist/cli/commands/runtime/jobs/sandbox.d.ts +3 -0
  38. package/dist/cli/commands/runtime/jobs/sandbox.js +15 -0
  39. package/dist/cli/commands/runtime/jobs/sandbox.js.map +1 -0
  40. package/dist/cli/commands/runtime/jobs/shared.d.ts +22 -0
  41. package/dist/cli/commands/runtime/jobs/shared.js +124 -0
  42. package/dist/cli/commands/runtime/jobs/shared.js.map +1 -0
  43. package/dist/cli/commands/runtime/jobs/stop.d.ts +3 -0
  44. package/dist/cli/commands/runtime/jobs/stop.js +31 -0
  45. package/dist/cli/commands/runtime/jobs/stop.js.map +1 -0
  46. package/dist/cli/commands/runtime/jobs/sync.d.ts +3 -0
  47. package/dist/cli/commands/runtime/jobs/sync.js +25 -0
  48. package/dist/cli/commands/runtime/jobs/sync.js.map +1 -0
  49. package/dist/cli/commands/runtime/shared.d.ts +20 -0
  50. package/dist/cli/commands/runtime/shared.js +69 -0
  51. package/dist/cli/commands/runtime/shared.js.map +1 -0
  52. package/dist/cli/commands/runtime/templates/clear.d.ts +3 -0
  53. package/dist/cli/commands/runtime/templates/clear.js +53 -0
  54. package/dist/cli/commands/runtime/templates/clear.js.map +1 -0
  55. package/dist/cli/commands/runtime/templates/index.d.ts +3 -0
  56. package/dist/cli/commands/runtime/templates/index.js +10 -0
  57. package/dist/cli/commands/runtime/templates/index.js.map +1 -0
  58. package/dist/cli/commands/runtime/templates/ls.d.ts +3 -0
  59. package/dist/cli/commands/runtime/templates/ls.js +52 -0
  60. package/dist/cli/commands/runtime/templates/ls.js.map +1 -0
  61. package/dist/cli/commands/runtime-options.d.ts +1 -0
  62. package/dist/cli/commands/runtime-options.js +5 -2
  63. package/dist/cli/commands/runtime-options.js.map +1 -1
  64. package/dist/cli/commands/spawn.js +27 -4
  65. package/dist/cli/commands/spawn.js.map +1 -1
  66. package/dist/cli/program.js +17 -1
  67. package/dist/cli/program.js.map +1 -1
  68. package/dist/index.js +24192 -2429
  69. package/dist/index.js.map +4 -4
  70. package/dist/providers/claude-code.js +1692 -93
  71. package/dist/providers/claude-code.js.map +4 -4
  72. package/dist/providers/codex.js +1692 -93
  73. package/dist/providers/codex.js.map +4 -4
  74. package/dist/providers/goose.js +1687 -88
  75. package/dist/providers/goose.js.map +4 -4
  76. package/dist/providers/kimi.js +1692 -93
  77. package/dist/providers/kimi.js.map +4 -4
  78. package/dist/providers/opencode.js +1692 -93
  79. package/dist/providers/opencode.js.map +4 -4
  80. package/dist/providers/poe-agent.js +1580 -308
  81. package/dist/providers/poe-agent.js.map +4 -4
  82. package/dist/providers/spawn-options.d.ts +4 -1
  83. package/dist/sdk/experiment.js +1 -0
  84. package/dist/sdk/experiment.js.map +1 -1
  85. package/dist/sdk/ralph.js +108 -16
  86. package/dist/sdk/ralph.js.map +1 -1
  87. package/dist/sdk/spawn.js +11 -4
  88. package/dist/sdk/spawn.js.map +1 -1
  89. package/dist/sdk/types.d.ts +12 -1
  90. package/dist/utils/command-checks.js +2 -29
  91. package/dist/utils/command-checks.js.map +1 -1
  92. package/package.json +12 -7
  93. package/packages/design-system/dist/components/help-formatter-plain.d.ts +4 -0
  94. package/packages/design-system/dist/components/help-formatter-plain.js +132 -0
  95. package/packages/design-system/dist/components/help-formatter.d.ts +13 -0
  96. package/packages/design-system/dist/components/help-formatter.js +116 -7
  97. package/packages/design-system/dist/components/index.d.ts +2 -2
  98. package/packages/design-system/dist/components/index.js +1 -1
  99. package/packages/design-system/dist/components/text.d.ts +1 -0
  100. package/packages/design-system/dist/components/text.js +8 -0
  101. package/packages/design-system/dist/index.d.ts +3 -2
  102. package/packages/design-system/dist/index.js +2 -1
  103. package/packages/memory/dist/index.js +1201 -115
  104. package/packages/memory/dist/index.js.map +4 -4
  105. package/packages/superintendent/dist/commands/run.d.ts +10 -0
  106. package/packages/superintendent/dist/commands/run.js +96 -49
  107. package/packages/superintendent/dist/commands/superintendent-group.d.ts +6 -0
  108. package/packages/superintendent/dist/runtime/agent-runner.d.ts +1 -0
  109. package/packages/superintendent/dist/runtime/agent-runner.js +4 -2
  110. package/packages/superintendent/dist/runtime/loop.d.ts +1 -0
@@ -609,8 +609,8 @@ function resourceNotFound(resource) {
609
609
  `Resource not found: ${resource}`
610
610
  );
611
611
  }
612
- function assertAbsolutePath(path37) {
613
- if (!isAbsolute(path37)) {
612
+ function assertAbsolutePath(path41) {
613
+ if (!isAbsolute(path41)) {
614
614
  throw invalidParams('"path" must be an absolute path');
615
615
  }
616
616
  }
@@ -1383,6 +1383,7 @@ function parseRunner(raw) {
1383
1383
  detach: parseOptionalBoolean(record.detach, "runner.detach") ?? false,
1384
1384
  upload_max_file_mb: uploadMaxFileMb,
1385
1385
  download_conflict: parseDownloadConflict(record.download_conflict),
1386
+ sync: parseRunnerSync(record.sync),
1386
1387
  workspace: parseRunnerWorkspace(record.workspace)
1387
1388
  });
1388
1389
  }
@@ -1421,13 +1422,14 @@ function parseRuntime(raw) {
1421
1422
  ...shared,
1422
1423
  type,
1423
1424
  template_id: parseOptionalString(record.template_id),
1425
+ from_template: parseOptionalString(record.from_template),
1424
1426
  dockerfile: parseOptionalString(record.dockerfile),
1425
1427
  build_context: parseOptionalString(record.build_context),
1428
+ workspace_dir: parseWorkspaceDir(record.workspace_dir),
1426
1429
  cpu: parseOptionalNumber(record.cpu),
1427
1430
  memory_mb: parseOptionalNumber(record.memory_mb),
1428
1431
  timeout_minutes: parseOptionalNumber(record.timeout_minutes),
1429
- preserve_after_exit_hours: preserveAfterExitHours,
1430
- api_key_env: parseOptionalString(record.api_key_env) ?? "E2B_API_KEY"
1432
+ preserve_after_exit_hours: preserveAfterExitHours
1431
1433
  });
1432
1434
  }
1433
1435
  return {
@@ -1464,11 +1466,23 @@ function parseRuntimeType(value) {
1464
1466
  }
1465
1467
  throw new Error('type: expected "host", "docker", or "e2b".');
1466
1468
  }
1469
+ function parseWorkspaceDir(value) {
1470
+ const workspaceDir = parseOptionalString(value) ?? "/workspace";
1471
+ if (!path.posix.isAbsolute(workspaceDir)) {
1472
+ throw new Error("workspace_dir: expected an absolute sandbox path.");
1473
+ }
1474
+ let normalized = path.posix.normalize(workspaceDir);
1475
+ while (normalized.length > 1 && normalized.endsWith("/")) {
1476
+ normalized = normalized.slice(0, -1);
1477
+ }
1478
+ return normalized;
1479
+ }
1467
1480
  function createDefaultRunnerScope() {
1468
1481
  return {
1469
1482
  detach: false,
1470
1483
  upload_max_file_mb: 100,
1471
1484
  download_conflict: "refuse",
1485
+ sync: "both",
1472
1486
  workspace: {
1473
1487
  exclude: [...defaultWorkspaceExclude]
1474
1488
  }
@@ -1499,6 +1513,15 @@ function parseDownloadConflict(value) {
1499
1513
  }
1500
1514
  throw new Error('runner.download_conflict: expected "refuse" or "overwrite".');
1501
1515
  }
1516
+ function parseRunnerSync(value) {
1517
+ if (value === void 0) {
1518
+ return "both";
1519
+ }
1520
+ if (value === "both" || value === "upload" || value === "none") {
1521
+ return value;
1522
+ }
1523
+ throw new Error('runner.sync: expected "both", "upload", or "none".');
1524
+ }
1502
1525
  function parseBuildArgs(value) {
1503
1526
  if (value === void 0) {
1504
1527
  return {};
@@ -1661,6 +1684,11 @@ var init_runtime = __esm({
1661
1684
  default: "",
1662
1685
  doc: "Path to the Docker build context"
1663
1686
  },
1687
+ workspace_dir: {
1688
+ type: "string",
1689
+ default: "/workspace",
1690
+ doc: "Sandbox-local workspace directory for E2B runtime upload, execution, and download"
1691
+ },
1664
1692
  engine: {
1665
1693
  type: "string",
1666
1694
  default: "",
@@ -1682,6 +1710,11 @@ var init_runtime = __esm({
1682
1710
  default: "",
1683
1711
  doc: "Prebuilt E2B template id"
1684
1712
  },
1713
+ from_template: {
1714
+ type: "string",
1715
+ default: "",
1716
+ doc: "Existing E2B template alias to extend instead of using the Dockerfile FROM image"
1717
+ },
1685
1718
  cpu: {
1686
1719
  type: "json",
1687
1720
  default: void 0,
@@ -1705,11 +1738,6 @@ var init_runtime = __esm({
1705
1738
  default: void 0,
1706
1739
  parse: parseOptionalNumber,
1707
1740
  doc: "Hours to keep an E2B sandbox alive after job exit"
1708
- },
1709
- api_key_env: {
1710
- type: "string",
1711
- default: "",
1712
- doc: "Environment variable name containing the E2B API key"
1713
1741
  }
1714
1742
  }
1715
1743
  };
@@ -1775,10 +1803,48 @@ function defineScope(scope, schema) {
1775
1803
  schema
1776
1804
  };
1777
1805
  }
1806
+ function parseBraintrustIntegrationConfig(value) {
1807
+ if (!isRecord(value)) {
1808
+ throw new Error("expected an object");
1809
+ }
1810
+ const enabled = value.enabled === void 0 ? false : value.enabled;
1811
+ if (typeof enabled !== "boolean") {
1812
+ throw new Error("enabled must be a boolean");
1813
+ }
1814
+ return {
1815
+ enabled,
1816
+ ...optionalStringEntry("apiKey", value.apiKey),
1817
+ ...optionalStringEntry("apiUrl", value.apiUrl),
1818
+ ...optionalStringEntry("project", value.project)
1819
+ };
1820
+ }
1821
+ function optionalStringEntry(key2, value) {
1822
+ if (value === void 0) {
1823
+ return {};
1824
+ }
1825
+ if (typeof value !== "string") {
1826
+ throw new Error(`${key2} must be a string`);
1827
+ }
1828
+ return { [key2]: value };
1829
+ }
1830
+ function isRecord(value) {
1831
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1832
+ }
1833
+ var integrationsConfigScope;
1778
1834
  var init_schema = __esm({
1779
1835
  "packages/poe-code-config/src/schema.ts"() {
1780
1836
  "use strict";
1781
1837
  init_runtime();
1838
+ integrationsConfigScope = defineScope("integrations", {
1839
+ braintrust: {
1840
+ type: "json",
1841
+ default: {
1842
+ enabled: false
1843
+ },
1844
+ parse: parseBraintrustIntegrationConfig,
1845
+ doc: "Braintrust integration configuration"
1846
+ }
1847
+ });
1782
1848
  }
1783
1849
  });
1784
1850
 
@@ -1899,11 +1965,11 @@ var init_parse = __esm({
1899
1965
  function mergeLayers(layers) {
1900
1966
  return mergeObjectLayers(layers, []);
1901
1967
  }
1902
- function mergeObjectLayers(layers, path37) {
1968
+ function mergeObjectLayers(layers, path41) {
1903
1969
  const data = {};
1904
1970
  const sources = {};
1905
1971
  for (const key2 of collectKeys(layers)) {
1906
- const resolved = resolveKey(layers, key2, path37);
1972
+ const resolved = resolveKey(layers, key2, path41);
1907
1973
  if (resolved === void 0) {
1908
1974
  continue;
1909
1975
  }
@@ -1921,7 +1987,7 @@ function collectKeys(layers) {
1921
1987
  }
1922
1988
  return [...keys];
1923
1989
  }
1924
- function resolveKey(layers, key2, path37) {
1990
+ function resolveKey(layers, key2, path41) {
1925
1991
  let winningSource;
1926
1992
  let winningValue;
1927
1993
  const objectLayers = [];
@@ -1951,9 +2017,9 @@ function resolveKey(layers, key2, path37) {
1951
2017
  if (winningSource === void 0) {
1952
2018
  return void 0;
1953
2019
  }
1954
- const fullPath = buildPath(path37, key2);
2020
+ const fullPath = buildPath(path41, key2);
1955
2021
  if (isPlainObject(winningValue)) {
1956
- const merged = mergeObjectLayers(objectLayers, [...path37, key2]);
2022
+ const merged = mergeObjectLayers(objectLayers, [...path41, key2]);
1957
2023
  return {
1958
2024
  value: merged.data,
1959
2025
  sources: {
@@ -1978,8 +2044,8 @@ function isWinningCandidate(key2, value) {
1978
2044
  }
1979
2045
  return true;
1980
2046
  }
1981
- function buildPath(path37, key2) {
1982
- return [...path37, key2].join(".");
2047
+ function buildPath(path41, key2) {
2048
+ return [...path41, key2].join(".");
1983
2049
  }
1984
2050
  function isPlainObject(value) {
1985
2051
  if (value === null || Array.isArray(value) || typeof value !== "object") {
@@ -2625,16 +2691,16 @@ function getConfigFormat(pathOrFormat) {
2625
2691
  }
2626
2692
  return formatRegistry[formatName];
2627
2693
  }
2628
- function detectFormat2(path37) {
2629
- const ext = getExtension(path37);
2694
+ function detectFormat2(path41) {
2695
+ const ext = getExtension(path41);
2630
2696
  return extensionMap[ext];
2631
2697
  }
2632
- function getExtension(path37) {
2633
- const lastDot = path37.lastIndexOf(".");
2698
+ function getExtension(path41) {
2699
+ const lastDot = path41.lastIndexOf(".");
2634
2700
  if (lastDot === -1) {
2635
2701
  return "";
2636
2702
  }
2637
- return path37.slice(lastDot).toLowerCase();
2703
+ return path41.slice(lastDot).toLowerCase();
2638
2704
  }
2639
2705
  var formatRegistry, extensionMap;
2640
2706
  var init_formats = __esm({
@@ -3432,7 +3498,7 @@ async function parseStoredDocument(fs4, filePath, raw) {
3432
3498
  }
3433
3499
  }
3434
3500
  function normalizeDocument(value) {
3435
- if (!isRecord(value)) {
3501
+ if (!isRecord2(value)) {
3436
3502
  return {};
3437
3503
  }
3438
3504
  const document = {};
@@ -3445,7 +3511,7 @@ function normalizeDocument(value) {
3445
3511
  return document;
3446
3512
  }
3447
3513
  function normalizeScopeValues(value) {
3448
- if (!isRecord(value)) {
3514
+ if (!isRecord2(value)) {
3449
3515
  return {};
3450
3516
  }
3451
3517
  const normalized = {};
@@ -3484,7 +3550,7 @@ function createInvalidBackupPath(filePath) {
3484
3550
  const baseName = path6.basename(filePath);
3485
3551
  return path6.join(directory, `${baseName}.invalid-${createTimestamp()}.json`);
3486
3552
  }
3487
- function isRecord(value) {
3553
+ function isRecord2(value) {
3488
3554
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
3489
3555
  }
3490
3556
  function resolveConfigPath(homeDir) {
@@ -3651,7 +3717,7 @@ function mergeScope(scope, baseScope, overrideScope) {
3651
3717
  ...Object.fromEntries(scopeEntries)
3652
3718
  };
3653
3719
  }
3654
- function mergeRuntimeScope(baseScope, overrideScope, path37 = []) {
3720
+ function mergeRuntimeScope(baseScope, overrideScope, path41 = []) {
3655
3721
  const merged = {};
3656
3722
  const keys = /* @__PURE__ */ new Set([...Object.keys(baseScope), ...Object.keys(overrideScope)]);
3657
3723
  for (const key2 of keys) {
@@ -3663,22 +3729,22 @@ function mergeRuntimeScope(baseScope, overrideScope, path37 = []) {
3663
3729
  }
3664
3730
  continue;
3665
3731
  }
3666
- if (isRuntimeConcatenativeArray([...path37, key2]) && Array.isArray(baseValue) && Array.isArray(overrideValue)) {
3732
+ if (isRuntimeConcatenativeArray([...path41, key2]) && Array.isArray(baseValue) && Array.isArray(overrideValue)) {
3667
3733
  merged[key2] = [...baseValue, ...overrideValue];
3668
3734
  continue;
3669
3735
  }
3670
- if (isRecord2(baseValue) && isRecord2(overrideValue)) {
3671
- merged[key2] = mergeRuntimeScope(baseValue, overrideValue, [...path37, key2]);
3736
+ if (isRecord3(baseValue) && isRecord3(overrideValue)) {
3737
+ merged[key2] = mergeRuntimeScope(baseValue, overrideValue, [...path41, key2]);
3672
3738
  continue;
3673
3739
  }
3674
3740
  merged[key2] = overrideValue;
3675
3741
  }
3676
3742
  return merged;
3677
3743
  }
3678
- function isRuntimeConcatenativeArray(path37) {
3679
- return path37.join(".") === "mounts" || path37.join(".") === "runner.workspace.exclude";
3744
+ function isRuntimeConcatenativeArray(path41) {
3745
+ return path41.join(".") === "mounts" || path41.join(".") === "runner.workspace.exclude";
3680
3746
  }
3681
- function isRecord2(value) {
3747
+ function isRecord3(value) {
3682
3748
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
3683
3749
  }
3684
3750
  var init_merge2 = __esm({
@@ -3687,6 +3753,59 @@ var init_merge2 = __esm({
3687
3753
  }
3688
3754
  });
3689
3755
 
3756
+ // packages/poe-code-config/src/merge-callbacks.ts
3757
+ function mergeLoopCallbacks(user, added) {
3758
+ return mergeCallbacks(user, added);
3759
+ }
3760
+ function mergeCallbacks(user, added) {
3761
+ if (!user) {
3762
+ return added;
3763
+ }
3764
+ if (!added) {
3765
+ return user;
3766
+ }
3767
+ const userCallbacks = user;
3768
+ const addedCallbacks = added;
3769
+ const result = {};
3770
+ const keys = /* @__PURE__ */ new Set([...Object.keys(user), ...Object.keys(added)]);
3771
+ for (const key2 of keys) {
3772
+ const userCallback = userCallbacks[key2];
3773
+ const addedCallback = addedCallbacks[key2];
3774
+ if (userCallback && addedCallback) {
3775
+ result[key2] = function mergedCallback(...args) {
3776
+ const userResult = userCallback.apply(this, args);
3777
+ try {
3778
+ addedCallback.apply(this, args);
3779
+ } catch (error2) {
3780
+ console.warn(`Added callback ${key2} failed`, error2);
3781
+ }
3782
+ return userResult;
3783
+ };
3784
+ continue;
3785
+ }
3786
+ result[key2] = userCallback ?? addedCallback;
3787
+ }
3788
+ return result;
3789
+ }
3790
+ var init_merge_callbacks = __esm({
3791
+ "packages/poe-code-config/src/merge-callbacks.ts"() {
3792
+ "use strict";
3793
+ }
3794
+ });
3795
+
3796
+ // packages/poe-code-config/src/integrations-loader.ts
3797
+ async function loadIntegrations(config) {
3798
+ if (!config.integrations?.braintrust?.enabled) return null;
3799
+ const packageName = "@poe-code/braintrust";
3800
+ const mod = await import(packageName);
3801
+ return mod.bootstrap(config);
3802
+ }
3803
+ var init_integrations_loader = __esm({
3804
+ "packages/poe-code-config/src/integrations-loader.ts"() {
3805
+ "use strict";
3806
+ }
3807
+ });
3808
+
3690
3809
  // packages/poe-code-config/src/models.ts
3691
3810
  var init_models = __esm({
3692
3811
  "packages/poe-code-config/src/models.ts"() {
@@ -3768,8 +3887,8 @@ function isPidRunning(pid) {
3768
3887
  }
3769
3888
  function createDefaultFs() {
3770
3889
  return {
3771
- open: (path37, flags) => fsPromises2.open(path37, flags),
3772
- readFile: (path37, encoding) => fsPromises2.readFile(path37, encoding),
3890
+ open: (path41, flags) => fsPromises2.open(path41, flags),
3891
+ readFile: (path41, encoding) => fsPromises2.readFile(path41, encoding),
3773
3892
  stat: fsPromises2.stat,
3774
3893
  unlink: fsPromises2.unlink
3775
3894
  };
@@ -4089,12 +4208,12 @@ function parseJobEntry(content) {
4089
4208
  return parsed;
4090
4209
  }
4091
4210
  function isJobEntry(value) {
4092
- return isRecord3(value) && typeof value.id === "string" && typeof value.env_id === "string" && typeof value.env_kind === "string" && typeof value.tool === "string" && Array.isArray(value.argv) && value.argv.every((arg) => typeof arg === "string") && typeof value.cwd === "string" && typeof value.started_at === "string" && isJobStatus(value.status) && (value.exit_code === void 0 || typeof value.exit_code === "number") && (value.exited_at === void 0 || typeof value.exited_at === "string") && (value.log_file === void 0 || typeof value.log_file === "string");
4211
+ return isRecord4(value) && typeof value.id === "string" && typeof value.env_id === "string" && typeof value.env_kind === "string" && typeof value.tool === "string" && Array.isArray(value.argv) && value.argv.every((arg) => typeof arg === "string") && typeof value.cwd === "string" && typeof value.started_at === "string" && isJobStatus(value.status) && (value.exit_code === void 0 || typeof value.exit_code === "number") && (value.exited_at === void 0 || typeof value.exited_at === "string") && (value.log_file === void 0 || typeof value.log_file === "string");
4093
4212
  }
4094
4213
  function isJobStatus(value) {
4095
4214
  return value === "pending" || value === "running" || value === "exited" || value === "killed" || value === "lost";
4096
4215
  }
4097
- function isRecord3(value) {
4216
+ function isRecord4(value) {
4098
4217
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
4099
4218
  }
4100
4219
  var init_jobs = __esm({
@@ -4170,7 +4289,7 @@ function createEmptyState() {
4170
4289
  };
4171
4290
  }
4172
4291
  function normalizeTemplateState(value) {
4173
- if (!isRecord4(value)) {
4292
+ if (!isRecord5(value)) {
4174
4293
  return createEmptyState();
4175
4294
  }
4176
4295
  return {
@@ -4179,7 +4298,7 @@ function normalizeTemplateState(value) {
4179
4298
  };
4180
4299
  }
4181
4300
  function normalizeTemplateEntries(value) {
4182
- if (!isRecord4(value)) {
4301
+ if (!isRecord5(value)) {
4183
4302
  return {};
4184
4303
  }
4185
4304
  const entries = {};
@@ -4191,9 +4310,9 @@ function normalizeTemplateEntries(value) {
4191
4310
  return entries;
4192
4311
  }
4193
4312
  function isTemplateEntry(value) {
4194
- return isRecord4(value) && typeof value.hash === "string" && typeof value.runtime_type === "string" && typeof value.dockerfile_path === "string" && typeof value.built_at === "string" && (value.template_id === void 0 || typeof value.template_id === "string") && (value.image === void 0 || typeof value.image === "string");
4313
+ return isRecord5(value) && typeof value.hash === "string" && typeof value.runtime_type === "string" && typeof value.dockerfile_path === "string" && typeof value.built_at === "string" && (value.template_id === void 0 || typeof value.template_id === "string") && (value.image === void 0 || typeof value.image === "string");
4195
4314
  }
4196
- function isRecord4(value) {
4315
+ function isRecord5(value) {
4197
4316
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
4198
4317
  }
4199
4318
  var init_templates = __esm({
@@ -4231,6 +4350,8 @@ var init_src5 = __esm({
4231
4350
  init_plan_scope();
4232
4351
  init_config();
4233
4352
  init_merge2();
4353
+ init_merge_callbacks();
4354
+ init_integrations_loader();
4234
4355
  init_models();
4235
4356
  init_memory();
4236
4357
  init_resolve2();
@@ -6414,7 +6535,7 @@ async function deriveEncryptionKey(getMachineIdentity, salt) {
6414
6535
  function parseEncryptedDocument(raw) {
6415
6536
  try {
6416
6537
  const parsed = JSON.parse(raw);
6417
- if (!isRecord5(parsed)) {
6538
+ if (!isRecord6(parsed)) {
6418
6539
  return null;
6419
6540
  }
6420
6541
  if (parsed.version !== ENCRYPTION_VERSION) {
@@ -6433,7 +6554,7 @@ function parseEncryptedDocument(raw) {
6433
6554
  return null;
6434
6555
  }
6435
6556
  }
6436
- function isRecord5(value) {
6557
+ function isRecord6(value) {
6437
6558
  return Boolean(value && typeof value === "object" && !Array.isArray(value));
6438
6559
  }
6439
6560
  function isNotFoundError2(error2) {
@@ -12518,6 +12639,38 @@ function wrapForLogTee(argv, jobId) {
12518
12639
  ].join(" && ");
12519
12640
  return ["sh", "-c", script];
12520
12641
  }
12642
+ async function* streamLogFile(env, jobId, opts) {
12643
+ const fs4 = env.fs ?? nodeFs2;
12644
+ const file = jobLogPath(jobId);
12645
+ let byteOffset = opts.sinceByte ?? 0;
12646
+ while (true) {
12647
+ if (opts.since !== void 0 && !await wasModifiedSince(fs4, file, opts.since)) {
12648
+ await waitForLogChange(fs4, file);
12649
+ continue;
12650
+ }
12651
+ const result = await readLogChunk(fs4, file, byteOffset);
12652
+ if (result !== null) {
12653
+ byteOffset = result.nextByteOffset;
12654
+ yield result.chunk;
12655
+ continue;
12656
+ }
12657
+ await waitForLogChange(fs4, file);
12658
+ }
12659
+ }
12660
+ async function wasModifiedSince(fs4, file, since) {
12661
+ if (fs4.promises.stat === void 0) {
12662
+ return true;
12663
+ }
12664
+ try {
12665
+ const stat7 = await fs4.promises.stat(file);
12666
+ return stat7.mtimeMs >= since.getTime();
12667
+ } catch (error2) {
12668
+ if (isNodeError(error2) && error2.code === "ENOENT") {
12669
+ return false;
12670
+ }
12671
+ throw error2;
12672
+ }
12673
+ }
12521
12674
  async function waitForExit(env, jobId, opts = {}) {
12522
12675
  const fs4 = env.fs ?? nodeFs2;
12523
12676
  const file = jobExitPath(jobId);
@@ -12541,6 +12694,19 @@ function jobLogPath(jobId) {
12541
12694
  function jobExitPath(jobId) {
12542
12695
  return `${JOB_DIR}/${jobId}.exit`;
12543
12696
  }
12697
+ async function readLogChunk(fs4, file, byteOffset) {
12698
+ const contents = await readFileIfExists2(fs4, file);
12699
+ if (contents === null || byteOffset >= contents.byteLength) {
12700
+ return null;
12701
+ }
12702
+ return {
12703
+ chunk: {
12704
+ byteOffset,
12705
+ data: contents.subarray(byteOffset).toString("utf8")
12706
+ },
12707
+ nextByteOffset: contents.byteLength
12708
+ };
12709
+ }
12544
12710
  async function readTextFileIfExists(fs4, file) {
12545
12711
  const contents = await readFileIfExists2(fs4, file);
12546
12712
  return contents?.toString("utf8") ?? null;
@@ -12556,6 +12722,27 @@ async function readFileIfExists2(fs4, file) {
12556
12722
  throw error2;
12557
12723
  }
12558
12724
  }
12725
+ async function waitForLogChange(fs4, file) {
12726
+ const watch = fs4.watch;
12727
+ if (typeof watch !== "function") {
12728
+ await sleep2(POLL_INTERVAL_MS);
12729
+ return;
12730
+ }
12731
+ await new Promise((resolve2) => {
12732
+ let watcher = null;
12733
+ const timer = setTimeout(done, POLL_INTERVAL_MS);
12734
+ function done() {
12735
+ clearTimeout(timer);
12736
+ watcher?.close();
12737
+ resolve2();
12738
+ }
12739
+ try {
12740
+ watcher = watch(file, done);
12741
+ } catch {
12742
+ done();
12743
+ }
12744
+ });
12745
+ }
12559
12746
  function sleep2(ms, signal) {
12560
12747
  return new Promise((resolve2, reject) => {
12561
12748
  let timer = null;
@@ -12596,6 +12783,38 @@ var init_log_stream = __esm({
12596
12783
  }
12597
12784
  });
12598
12785
 
12786
+ // packages/agent-harness-tools/src/binary-exists.ts
12787
+ function createBinaryExistsDetectors(binaryName) {
12788
+ const commonPaths = [
12789
+ `/usr/local/bin/${binaryName}`,
12790
+ `/usr/bin/${binaryName}`,
12791
+ `$HOME/.local/bin/${binaryName}`,
12792
+ `$HOME/.claude/local/bin/${binaryName}`
12793
+ ];
12794
+ return [
12795
+ {
12796
+ command: "which",
12797
+ args: [binaryName],
12798
+ validate: (result) => result.exitCode === 0
12799
+ },
12800
+ {
12801
+ command: "where",
12802
+ args: [binaryName],
12803
+ validate: (result) => result.exitCode === 0 && result.stdout.trim().length > 0
12804
+ },
12805
+ {
12806
+ command: "sh",
12807
+ args: ["-c", commonPaths.map((p) => `test -f "${p}"`).join(" || ")],
12808
+ validate: (result) => result.exitCode === 0
12809
+ }
12810
+ ];
12811
+ }
12812
+ var init_binary_exists = __esm({
12813
+ "packages/agent-harness-tools/src/binary-exists.ts"() {
12814
+ "use strict";
12815
+ }
12816
+ });
12817
+
12599
12818
  // packages/agent-harness-tools/src/run-poe-command.ts
12600
12819
  import { randomBytes as randomBytes2 } from "node:crypto";
12601
12820
  async function runPoeCommand(opts) {
@@ -12617,12 +12836,18 @@ async function runPoeCommand(opts) {
12617
12836
  let shouldClose = true;
12618
12837
  try {
12619
12838
  const upload = env.uploadWorkspace();
12839
+ await Promise.all([pendingJob, upload]);
12840
+ await configureE2bSpawnAgentIfAvailable({
12841
+ env,
12842
+ openSpec: opts.openSpec,
12843
+ factoryType: opts.factory.type
12844
+ });
12620
12845
  const argv = wrapCommand ? wrapForLogTee(opts.openSpec.jobLabel.argv, jobId) : opts.openSpec.jobLabel.argv;
12621
12846
  const handle = execution?.tty ? env.shell() : env.exec({
12622
12847
  command: argv[0],
12623
12848
  args: argv.slice(1),
12624
12849
  cwd: opts.openSpec.cwd,
12625
- env: execution && "env" in execution ? execution.env : opts.openSpec.env,
12850
+ env: resolveExecutionEnv(opts.openSpec),
12626
12851
  stdin: execution?.stdin ?? "inherit",
12627
12852
  stdout: execution?.stdout ?? "pipe",
12628
12853
  stderr: execution?.stderr ?? "pipe",
@@ -12632,15 +12857,19 @@ async function runPoeCommand(opts) {
12632
12857
  handle.stdin?.setDefaultEncoding("utf8");
12633
12858
  handle.stdin?.end(execution.input);
12634
12859
  }
12635
- const runningJob = Promise.all([pendingJob, upload]).then(
12636
- () => opts.state.jobs.update(jobId, {
12637
- status: "running",
12638
- env_id: env.id,
12639
- started_at: (/* @__PURE__ */ new Date()).toISOString()
12640
- })
12641
- );
12860
+ const runningJob = opts.state.jobs.update(jobId, {
12861
+ status: "running",
12862
+ env_id: env.id,
12863
+ started_at: (/* @__PURE__ */ new Date()).toISOString()
12864
+ });
12642
12865
  if (opts.detach) {
12643
12866
  await runningJob;
12867
+ setDetachedJobContext(env, {
12868
+ id: jobId,
12869
+ tool: opts.openSpec.jobLabel.tool,
12870
+ argv: opts.openSpec.jobLabel.argv
12871
+ });
12872
+ await env.detach();
12644
12873
  shouldClose = false;
12645
12874
  return { kind: "detached", jobId, envId: env.id };
12646
12875
  }
@@ -12672,6 +12901,97 @@ async function runPoeCommand(opts) {
12672
12901
  }
12673
12902
  }
12674
12903
  }
12904
+ async function configureE2bSpawnAgentIfAvailable(opts) {
12905
+ if (opts.factoryType !== "e2b") {
12906
+ return;
12907
+ }
12908
+ const agentId = resolveAgentId(opts.openSpec.jobLabel.tool);
12909
+ const agent2 = allAgents.find((candidate) => candidate.id === agentId);
12910
+ const binaryName = agent2?.binaryName;
12911
+ if (!agentId || !binaryName) {
12912
+ return;
12913
+ }
12914
+ const commandEnv = resolveExecutionEnv(opts.openSpec);
12915
+ const exists = await binaryExists(opts.env, {
12916
+ binaryName,
12917
+ cwd: opts.openSpec.cwd,
12918
+ env: commandEnv
12919
+ });
12920
+ if (!exists) {
12921
+ return;
12922
+ }
12923
+ const result = await runProbeCommand(opts.env, {
12924
+ command: "poe-code",
12925
+ args: ["configure", "--yes", "--provider", "poe", agentId],
12926
+ cwd: opts.openSpec.cwd,
12927
+ env: commandEnv
12928
+ });
12929
+ if (result.exitCode !== 0) {
12930
+ throw new Error(
12931
+ `Failed to configure ${agentId} for Poe inside E2B sandbox.
12932
+ ${formatProbeResult(result)}`
12933
+ );
12934
+ }
12935
+ }
12936
+ async function binaryExists(env, opts) {
12937
+ for (const detector of createBinaryExistsDetectors(opts.binaryName)) {
12938
+ const result = await runProbeCommand(env, {
12939
+ ...detector,
12940
+ cwd: opts.cwd,
12941
+ env: opts.env
12942
+ });
12943
+ if (detector.validate(result)) {
12944
+ return true;
12945
+ }
12946
+ }
12947
+ return false;
12948
+ }
12949
+ function resolveExecutionEnv(openSpec) {
12950
+ const execution = openSpec.execution;
12951
+ return execution?.env ?? openSpec.env;
12952
+ }
12953
+ async function runProbeCommand(env, spec10) {
12954
+ const handle = env.exec({
12955
+ command: spec10.command,
12956
+ args: spec10.args,
12957
+ cwd: spec10.cwd,
12958
+ env: spec10.env,
12959
+ stdin: "ignore",
12960
+ stdout: "pipe",
12961
+ stderr: "pipe"
12962
+ });
12963
+ const stdout = readStream(handle.stdout);
12964
+ const stderr = readStream(handle.stderr);
12965
+ const result = await handle.result;
12966
+ return {
12967
+ exitCode: result.exitCode,
12968
+ stdout: await stdout,
12969
+ stderr: await stderr
12970
+ };
12971
+ }
12972
+ function readStream(stream) {
12973
+ if (!stream) {
12974
+ return Promise.resolve("");
12975
+ }
12976
+ return new Promise((resolve2, reject) => {
12977
+ let output = "";
12978
+ stream.setEncoding("utf8");
12979
+ stream.on("data", (chunk) => {
12980
+ output += chunk.toString();
12981
+ });
12982
+ stream.on("error", reject);
12983
+ stream.on("end", () => resolve2(output));
12984
+ });
12985
+ }
12986
+ function formatProbeResult(result) {
12987
+ return [
12988
+ `Exit code: ${result.exitCode}`,
12989
+ result.stdout.trim() ? `stdout:
12990
+ ${result.stdout.trim()}` : "",
12991
+ result.stderr.trim() ? `stderr:
12992
+ ${result.stderr.trim()}` : ""
12993
+ ].filter(Boolean).join("\n");
12994
+ }
12675
12995
  async function runSync(opts) {
12676
12996
  const execution = opts.openSpec.execution;
12677
12997
  const capture = execution?.captureOutput === true;
@@ -12683,7 +13003,9 @@ async function runSync(opts) {
12683
13003
  const download = await opts.env.downloadWorkspace({
12684
13004
  conflictPolicy: opts.openSpec.runner?.download_conflict ?? "refuse"
12685
13005
  });
12686
- await opts.env.close();
13006
+ if (opts.closeAfterDownload !== false) {
13007
+ await opts.env.close();
13008
+ }
12687
13009
  return {
12688
13010
  exitCode,
12689
13011
  download,
@@ -12839,6 +13161,10 @@ function toLogStreamEnv(env) {
12839
13161
  const candidate = env;
12840
13162
  return candidate.fs === void 0 ? {} : { fs: candidate.fs };
12841
13163
  }
13164
+ function setDetachedJobContext(env, context) {
13165
+ const candidate = env;
13166
+ candidate.setDetachedJobContext?.(context);
13167
+ }
12842
13168
  function isPromiseLike(value) {
12843
13169
  return typeof value.then === "function";
12844
13170
  }
@@ -12874,6 +13200,8 @@ var ULID_ALPHABET;
12874
13200
  var init_run_poe_command = __esm({
12875
13201
  "packages/agent-harness-tools/src/run-poe-command.ts"() {
12876
13202
  "use strict";
13203
+ init_src8();
13204
+ init_binary_exists();
12877
13205
  init_log_stream();
12878
13206
  ULID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
12879
13207
  }
@@ -12884,10 +13212,13 @@ function registerExecutionEnvFactory(factory) {
12884
13212
  executionEnvFactories.set(factory.type, factory);
12885
13213
  }
12886
13214
  function selectExecutionEnv(runtime) {
12887
- const factory = executionEnvFactories.get(runtime.type);
13215
+ return selectExecutionEnvFactory(runtime.type);
13216
+ }
13217
+ function selectExecutionEnvFactory(type) {
13218
+ const factory = executionEnvFactories.get(type);
12888
13219
  if (factory === void 0) {
12889
13220
  throw new Error(
12890
- `No execution environment factory registered for runtime type "${runtime.type}".`
13221
+ `No execution environment factory registered for runtime type "${type}".`
12891
13222
  );
12892
13223
  }
12893
13224
  return factory;
@@ -12905,8 +13236,10 @@ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:f
12905
13236
  import os4 from "node:os";
12906
13237
  function resolvePoeCommandExecution(input) {
12907
13238
  const homeDir = input.context?.homeDir ?? os4.homedir();
12908
- const config = applyRuntimeOverrides(loadRuntimeConfig(input.cwd, homeDir), input.runtime, input.cwd);
12909
- const resolved = resolveRuntime({ cwd: input.cwd, config });
13239
+ const runtimeConfigCwd = input.runtimeConfigCwd ?? input.cwd;
13240
+ const loaded = loadRuntimeConfig(runtimeConfigCwd, homeDir);
13241
+ const config = applyRuntimeOverrides(loaded, input.runtime, runtimeConfigCwd);
13242
+ const resolved = resolveRuntime({ cwd: runtimeConfigCwd, config });
12910
13243
  const factory = selectExecutionEnv(resolved.runtime);
12911
13244
  const state = input.context?.state ?? loadState(homeDir);
12912
13245
  return {
@@ -12915,6 +13248,7 @@ function resolvePoeCommandExecution(input) {
12915
13248
  state,
12916
13249
  openSpec: {
12917
13250
  cwd: input.cwd,
13251
+ runtimeCwd: runtimeConfigCwd,
12918
13252
  runtime: resolved.runtime,
12919
13253
  runner: config.runner,
12920
13254
  state,
@@ -12930,10 +13264,11 @@ function resolvePoeCommandExecution(input) {
12930
13264
  }
12931
13265
  function applyRuntimeOverrides(config, overrides, cwd = process.cwd()) {
12932
13266
  if (!overrides) {
12933
- return config;
13267
+ return { runtime: config.runtime, runner: config.runner };
12934
13268
  }
13269
+ const base = "rawScope" in config && config.rawScope ? { ...config.rawScope } : { ...config.runtime };
12935
13270
  const runtime = parseRuntime({
12936
- ...config.runtime,
13271
+ ...base,
12937
13272
  ...overrides.runtime !== void 0 ? { type: overrides.runtime } : {},
12938
13273
  ...overrides.runtimeImage !== void 0 ? { image: overrides.runtimeImage } : {},
12939
13274
  ...overrides.runtimeTemplate !== void 0 ? { template_id: overrides.runtimeTemplate } : {},
@@ -12943,7 +13278,8 @@ function applyRuntimeOverrides(config, overrides, cwd = process.cwd()) {
12943
13278
  runtime,
12944
13279
  runner: {
12945
13280
  ...config.runner,
12946
- ...overrides.detach === true ? { detach: true } : {}
13281
+ ...overrides.detach === true ? { detach: true } : {},
13282
+ ...overrides.runnerSync !== void 0 ? { sync: overrides.runnerSync } : {}
12947
13283
  }
12948
13284
  };
12949
13285
  }
@@ -12961,6 +13297,7 @@ function loadRuntimeConfig(cwd, homeDir) {
12961
13297
  );
12962
13298
  const runtimeScope = resolveScope(runtimeConfigScope.schema, document.runtime, process.env);
12963
13299
  return {
13300
+ rawScope: { ...runtimeScope },
12964
13301
  runtime: parseRuntime(runtimeScope),
12965
13302
  runner: runtimeScope.runner
12966
13303
  };
@@ -13070,6 +13407,7 @@ var init_src9 = __esm({
13070
13407
  init_run_logs();
13071
13408
  init_log_stream();
13072
13409
  init_run_poe_command();
13410
+ init_binary_exists();
13073
13411
  init_poe_command_execution();
13074
13412
  init_skill_config();
13075
13413
  init_execution_env();
@@ -13290,7 +13628,7 @@ function createDockerEnv(input) {
13290
13628
  const containerRef = input.id;
13291
13629
  return {
13292
13630
  id: containerRef,
13293
- job: null,
13631
+ job: input.attachedJobId === void 0 ? null : createContainerJob(containerRef, input.runner, input.engine, input.context, input.attachedJobId),
13294
13632
  async uploadWorkspace() {
13295
13633
  const tempDir = mkdtempSync(path21.join(tmpdir(), "poe-docker-upload-"));
13296
13634
  const archivePath = path21.join(tempDir, "workspace.tar");
@@ -13425,35 +13763,57 @@ async function resolveImage(input) {
13425
13763
  if (input.runtime.image !== void 0) {
13426
13764
  return input.runtime.image;
13427
13765
  }
13766
+ const result = await buildDockerRuntimeTemplate({
13767
+ cwd: input.spec.cwd,
13768
+ runtime: input.runtime,
13769
+ state: input.spec.state,
13770
+ runner: input.runner
13771
+ });
13772
+ return result.image;
13773
+ }
13774
+ async function buildDockerRuntimeTemplate(input) {
13775
+ const runner = input.runner ?? createHostRunner();
13776
+ const engine = input.runtime.engine ?? detectEngine();
13777
+ const context = detectContext();
13428
13778
  const dockerfilePath = path21.resolve(
13429
- input.spec.cwd,
13779
+ input.cwd,
13430
13780
  input.runtime.dockerfile ?? path21.join(".poe-code", "Dockerfile")
13431
13781
  );
13432
- const buildContext = path21.resolve(input.spec.cwd, input.runtime.build_context ?? ".");
13782
+ const buildContext = path21.resolve(input.cwd, input.runtime.build_context ?? ".");
13433
13783
  const dockerfileBytes = await readFile3(dockerfilePath);
13434
13784
  const hash = hashDockerTemplate(dockerfileBytes, input.runtime.build_args ?? {});
13435
- const cached2 = await input.spec.state?.templates.get("docker", hash);
13785
+ const cached2 = input.force ? null : await input.state?.templates.get("docker", hash);
13436
13786
  if (cached2?.image !== void 0) {
13437
- return cached2.image;
13787
+ return {
13788
+ backend: "docker",
13789
+ hash,
13790
+ image: cached2.image,
13791
+ cached: true
13792
+ };
13438
13793
  }
13439
13794
  const image = `poe-code/local:${hash}`;
13440
13795
  await buildImage({
13441
- runner: input.runner,
13442
- engine: input.engine,
13443
- context: input.context,
13796
+ runner,
13797
+ engine,
13798
+ context,
13444
13799
  image,
13445
13800
  dockerfilePath,
13446
13801
  buildContext,
13447
13802
  buildArgs: input.runtime.build_args ?? {}
13448
13803
  });
13449
- await input.spec.state?.templates.put("docker", {
13804
+ await input.state?.templates.put("docker", {
13450
13805
  hash,
13451
13806
  image,
13452
13807
  runtime_type: "docker",
13453
13808
  dockerfile_path: dockerfilePath,
13454
13809
  built_at: (/* @__PURE__ */ new Date()).toISOString()
13455
13810
  });
13456
- return image;
13811
+ return {
13812
+ backend: "docker",
13813
+ hash,
13814
+ image,
13815
+ cached: false
13816
+ };
13457
13817
  }
13458
13818
  function hashDockerTemplate(dockerfileBytes, buildArgs) {
13459
13819
  const hash = createHash2("sha256");
@@ -13499,8 +13859,8 @@ function parseDockerRuntime(runtime) {
13499
13859
  }
13500
13860
  async function runAndRead(runner, spec10) {
13501
13861
  const handle = runner.exec(spec10);
13502
- const stdout = readStream(handle.stdout);
13503
- const stderr = readStream(handle.stderr);
13862
+ const stdout = readStream2(handle.stdout);
13863
+ const stderr = readStream2(handle.stderr);
13504
13864
  const result = await handle.result;
13505
13865
  const output = await stdout;
13506
13866
  if (result.exitCode !== 0) {
@@ -13515,7 +13875,7 @@ ${errorOutput}` : ""}`
13515
13875
  async function runOrThrow(runner, spec10) {
13516
13876
  await runAndRead(runner, spec10);
13517
13877
  }
13518
- async function readStream(stream) {
13878
+ async function readStream2(stream) {
13519
13879
  if (stream === null) {
13520
13880
  return "";
13521
13881
  }
@@ -13538,9 +13898,9 @@ function buildEnvArgs(env) {
13538
13898
  function createContainerName() {
13539
13899
  return `poe-env-${randomBytes4(6).toString("hex")}`;
13540
13900
  }
13541
- async function createContainerJob(containerId, runner, engine, context) {
13901
+ function createContainerJob(containerId, runner, engine, context, jobId = containerId) {
13542
13902
  return {
13543
- id: containerId,
13903
+ id: jobId,
13544
13904
  envId: containerId,
13545
13905
  tool: "docker",
13546
13906
  argv: ["attach", containerId],
@@ -13557,14 +13917,32 @@ async function createContainerJob(containerId, runner, engine, context) {
13557
13917
  stdout: "pipe",
13558
13918
  stderr: "pipe"
13559
13919
  });
13560
- const stdout = await readStream(handle.stdout);
13920
+ const stdout = await readStream2(handle.stdout);
13561
13921
  const result = await handle.result;
13562
13922
  if (result.exitCode !== 0) {
13563
13923
  return "lost";
13564
13924
  }
13565
13925
  return stdout.trim() === "running" ? "running" : "exited";
13566
13926
  },
13567
- async *stream() {
13927
+ async *stream(opts) {
13928
+ const handle = runner.exec({
13929
+ command: engine,
13930
+ args: [
13931
+ ...buildContextArgs(engine, context),
13932
+ "exec",
13933
+ containerId,
13934
+ "sh",
13935
+ "-c",
13936
+ `test -f ${shellQuote2(`/tmp/poe-jobs/${jobId}.log`)} && tail -c +${(opts?.sinceByte ?? 0) + 1} ${shellQuote2(`/tmp/poe-jobs/${jobId}.log`)} || true`
13937
+ ],
13938
+ stdout: "pipe",
13939
+ stderr: "pipe"
13940
+ });
13941
+ const stdout = await readStream2(handle.stdout);
13942
+ await handle.result;
13943
+ if (stdout.length > 0) {
13944
+ yield { byteOffset: opts?.sinceByte ?? 0, data: stdout };
13945
+ }
13568
13946
  },
13569
13947
  async wait() {
13570
13948
  const handle = runner.exec({
@@ -13573,7 +13951,7 @@ async function createContainerJob(containerId, runner, engine, context) {
13573
13951
  stdout: "pipe",
13574
13952
  stderr: "pipe"
13575
13953
  });
13576
- const stdout = await readStream(handle.stdout);
13954
+ const stdout = await readStream2(handle.stdout);
13577
13955
  const result = await handle.result;
13578
13956
  return { exitCode: Number.parseInt(stdout.trim(), 10) || result.exitCode };
13579
13957
  },
@@ -13588,9 +13966,9 @@ async function createContainerJob(containerId, runner, engine, context) {
13588
13966
  }
13589
13967
  };
13590
13968
  }
13591
- function createAttachedSpec() {
13969
+ function createAttachedSpec(cwd = "/workspace") {
13592
13970
  return {
13593
- cwd: "/workspace",
13971
+ cwd,
13594
13972
  runtime: {
13595
13973
  type: "docker",
13596
13974
  image: "attached",
@@ -13661,109 +14039,925 @@ var init_docker_execution_env = __esm({
13661
14039
  context
13662
14040
  });
13663
14041
  },
13664
- async attach(envId) {
14042
+ async attach(envId, context) {
13665
14043
  const engine = detectEngine();
13666
14044
  return createDockerEnv({
13667
14045
  id: envId,
13668
- spec: createAttachedSpec(),
14046
+ spec: createAttachedSpec(context?.cwd),
13669
14047
  runner: createHostRunner(),
13670
14048
  engine,
13671
- context: detectContext()
14049
+ context: detectContext(),
14050
+ attachedJobId: context?.jobId
13672
14051
  });
13673
14052
  }
13674
- };
14053
+ };
14054
+ }
14055
+ });
14056
+
14057
+ // packages/process-runner/src/host/host-execution-env.ts
14058
+ var hostExecutionEnvFactory;
14059
+ var init_host_execution_env = __esm({
14060
+ "packages/process-runner/src/host/host-execution-env.ts"() {
14061
+ "use strict";
14062
+ init_host_runner();
14063
+ hostExecutionEnvFactory = {
14064
+ type: "host",
14065
+ supportsDetach: false,
14066
+ async open(openSpec) {
14067
+ return {
14068
+ id: "host",
14069
+ job: null,
14070
+ async uploadWorkspace() {
14071
+ return {
14072
+ files: 0,
14073
+ bytes: 0,
14074
+ skipped: []
14075
+ };
14076
+ },
14077
+ async downloadWorkspace() {
14078
+ return {
14079
+ files: 0,
14080
+ bytes: 0,
14081
+ conflicts: []
14082
+ };
14083
+ },
14084
+ exec(spec10) {
14085
+ return createHostRunner().exec(spec10);
14086
+ },
14087
+ async detach() {
14088
+ throw new Error("host runtime does not support detach because host has no addressable env");
14089
+ },
14090
+ shell() {
14091
+ const shellSpec = openSpec.shellSpec;
14092
+ return createHostRunner().exec({
14093
+ command: shellSpec?.command ?? openSpec.env.SHELL ?? process.env.SHELL ?? "sh",
14094
+ ...shellSpec?.args ? { args: shellSpec.args } : {},
14095
+ cwd: openSpec.cwd,
14096
+ env: shellSpec && "env" in shellSpec ? shellSpec.env : openSpec.env,
14097
+ stdin: "inherit",
14098
+ stdout: "inherit",
14099
+ stderr: "inherit",
14100
+ tty: true
14101
+ });
14102
+ },
14103
+ async close() {
14104
+ }
14105
+ };
14106
+ },
14107
+ async attach() {
14108
+ throw new Error("host runtime does not support reattach");
14109
+ }
14110
+ };
14111
+ }
14112
+ });
14113
+
14114
+ // packages/process-runner/src/testing/mock-runner.ts
14115
+ import { Readable, Writable } from "node:stream";
14116
+ var init_mock_runner = __esm({
14117
+ "packages/process-runner/src/testing/mock-runner.ts"() {
14118
+ "use strict";
14119
+ }
14120
+ });
14121
+
14122
+ // packages/process-runner/src/testing/index.ts
14123
+ var init_testing = __esm({
14124
+ "packages/process-runner/src/testing/index.ts"() {
14125
+ "use strict";
14126
+ init_mock_runner();
14127
+ }
14128
+ });
14129
+
14130
+ // packages/process-runner/src/index.ts
14131
+ var init_src10 = __esm({
14132
+ "packages/process-runner/src/index.ts"() {
14133
+ "use strict";
14134
+ init_context();
14135
+ init_engine();
14136
+ init_docker_runner();
14137
+ init_docker_execution_env();
14138
+ init_host_execution_env();
14139
+ init_host_runner();
14140
+ init_testing();
14141
+ }
14142
+ });
14143
+
14144
+ // packages/runner-e2b/src/sdk.ts
14145
+ import { Template, Sandbox } from "e2b";
14146
+ async function createSandbox(opts) {
14147
+ return Sandbox.create(opts.templateId, {
14148
+ apiKey: opts.apiKey,
14149
+ envs: opts.env,
14150
+ ...opts.timeoutMinutes === void 0 ? {} : { timeoutMs: opts.timeoutMinutes * 6e4 }
14151
+ });
14152
+ }
14153
+ async function connectSandbox(id, apiKey) {
14154
+ return Sandbox.connect(id, apiKey === void 0 ? void 0 : { apiKey });
14155
+ }
14156
+ async function buildTemplate(opts) {
14157
+ const template = Template({ fileContextPath: opts.buildContext }).fromDockerfile(
14158
+ opts.dockerfilePath
14159
+ );
14160
+ if (opts.fromTemplate !== void 0 && opts.fromTemplate.length > 0) {
14161
+ template.fromTemplate(opts.fromTemplate);
14162
+ }
14163
+ const result = await Template.build(template, opts.name, {
14164
+ apiKey: opts.apiKey,
14165
+ ...opts.cpu === void 0 ? {} : { cpuCount: opts.cpu },
14166
+ ...opts.memoryMb === void 0 ? {} : { memoryMB: opts.memoryMb },
14167
+ ...opts.onLog ? { onBuildLogs: opts.onLog } : {}
14168
+ });
14169
+ return { templateId: result.templateId };
14170
+ }
14171
+ function toArrayBuffer(buffer) {
14172
+ const output = new ArrayBuffer(buffer.byteLength);
14173
+ new Uint8Array(output).set(buffer);
14174
+ return output;
14175
+ }
14176
+ async function readableToString(stream) {
14177
+ if (stream === null) {
14178
+ return "";
14179
+ }
14180
+ stream.setEncoding("utf8");
14181
+ const chunks = [];
14182
+ for await (const chunk of stream) {
14183
+ chunks.push(String(chunk));
14184
+ }
14185
+ return chunks.join("");
14186
+ }
14187
+ var init_sdk = __esm({
14188
+ "packages/runner-e2b/src/sdk.ts"() {
14189
+ "use strict";
14190
+ }
14191
+ });
14192
+
14193
+ // packages/runner-e2b/src/template-build.ts
14194
+ import { createHash as createHash3 } from "node:crypto";
14195
+ import { readdir, readFile as readFile4 } from "node:fs/promises";
14196
+ import path22 from "node:path";
14197
+ async function buildE2bRuntimeTemplate(input) {
14198
+ const dockerfileBytes = await readFile4(input.dockerfilePath);
14199
+ const buildContextFiles = await readBuildContextFiles(input.buildContext);
14200
+ const hash = hashTemplate(dockerfileBytes, buildContextFiles, input.runtime.build_args);
14201
+ const cached2 = input.force === true ? null : await input.state?.templates.get("e2b", hash);
14202
+ if (cached2?.template_id !== void 0) {
14203
+ return { backend: "e2b", hash, templateId: cached2.template_id, cached: true };
14204
+ }
14205
+ const tail = [];
14206
+ const onLog = (entry) => {
14207
+ tail.push(entry.message);
14208
+ if (tail.length > BUILD_LOG_TAIL_SIZE) {
14209
+ tail.shift();
14210
+ }
14211
+ input.onLog?.(entry);
14212
+ };
14213
+ let built;
14214
+ try {
14215
+ built = await buildTemplate({
14216
+ apiKey: input.apiKey,
14217
+ name: `poe-code-${hash.slice(0, 32)}`,
14218
+ dockerfilePath: input.dockerfilePath,
14219
+ buildContext: input.buildContext,
14220
+ cpu: input.runtime.cpu,
14221
+ memoryMb: input.runtime.memory_mb,
14222
+ fromTemplate: input.runtime.from_template,
14223
+ onLog
14224
+ });
14225
+ } catch (error2) {
14226
+ throw decorateBuildError(error2, tail);
14227
+ }
14228
+ await input.state?.templates.put("e2b", {
14229
+ hash,
14230
+ template_id: built.templateId,
14231
+ runtime_type: "e2b",
14232
+ dockerfile_path: input.dockerfilePath,
14233
+ built_at: (/* @__PURE__ */ new Date()).toISOString()
14234
+ });
14235
+ return { backend: "e2b", hash, templateId: built.templateId, cached: false };
14236
+ }
14237
+ function decorateBuildError(error2, tail) {
14238
+ const original = error2 instanceof Error ? error2 : new Error(String(error2));
14239
+ if (tail.length === 0) {
14240
+ return original;
14241
+ }
14242
+ const decorated = new Error(`${original.message}
14243
+
14244
+ Last build output:
14245
+ ${tail.join("\n")}`);
14246
+ decorated.stack = original.stack;
14247
+ decorated.cause = original;
14248
+ return decorated;
14249
+ }
14250
+ function hashTemplate(dockerfileBytes, buildContextFiles, buildArgs) {
14251
+ const hash = createHash3("sha256");
14252
+ hash.update(dockerfileBytes);
14253
+ hash.update("\0");
14254
+ for (const file of buildContextFiles) {
14255
+ hash.update(file.relativePath);
14256
+ hash.update("\0");
14257
+ hash.update(file.bytes);
14258
+ hash.update("\0");
14259
+ }
14260
+ for (const [key2, value] of Object.entries(buildArgs).sort(
14261
+ ([left], [right]) => left.localeCompare(right)
14262
+ )) {
14263
+ hash.update(key2);
14264
+ hash.update("=");
14265
+ hash.update(value);
14266
+ hash.update("\0");
14267
+ }
14268
+ return hash.digest("hex");
14269
+ }
14270
+ async function readBuildContextFiles(buildContext) {
14271
+ const files = [];
14272
+ await collectBuildContextFiles(buildContext, "", files);
14273
+ return files.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
14274
+ }
14275
+ async function collectBuildContextFiles(buildContext, relativeDir, files) {
14276
+ const absoluteDir = path22.join(buildContext, relativeDir);
14277
+ const entries = await readdir(absoluteDir, { withFileTypes: true });
14278
+ for (const entry of entries) {
14279
+ const relativePath = path22.join(relativeDir, entry.name);
14280
+ if (entry.isDirectory()) {
14281
+ await collectBuildContextFiles(buildContext, relativePath, files);
14282
+ continue;
14283
+ }
14284
+ if (!entry.isFile()) {
14285
+ continue;
14286
+ }
14287
+ files.push({
14288
+ relativePath: relativePath.split(path22.sep).join("/"),
14289
+ bytes: await readFile4(path22.join(buildContext, relativePath))
14290
+ });
14291
+ }
14292
+ }
14293
+ var BUILD_LOG_TAIL_SIZE;
14294
+ var init_template_build = __esm({
14295
+ "packages/runner-e2b/src/template-build.ts"() {
14296
+ "use strict";
14297
+ init_sdk();
14298
+ BUILD_LOG_TAIL_SIZE = 30;
14299
+ }
14300
+ });
14301
+
14302
+ // packages/runner-e2b/src/job-handle.ts
14303
+ import path23 from "node:path";
14304
+ function createE2bJobHandle(input) {
14305
+ const fs4 = createE2bLogStreamFs(input.sandbox);
14306
+ return {
14307
+ id: input.jobId,
14308
+ envId: input.envId,
14309
+ tool: input.tool,
14310
+ argv: input.argv,
14311
+ async status() {
14312
+ const exit = await readExitCode(input.sandbox, input.jobId);
14313
+ if (exit !== null) {
14314
+ return "exited";
14315
+ }
14316
+ const processes = await input.sandbox.commands.list();
14317
+ const isRunning = input.pid === void 0 ? processes.some((process2) => processMentionsJob(process2, input.jobId)) : processes.some((process2) => process2.pid === input.pid);
14318
+ return isRunning ? "running" : "lost";
14319
+ },
14320
+ stream(opts = {}) {
14321
+ return streamLogFile({ fs: fs4 }, input.jobId, opts);
14322
+ },
14323
+ async wait() {
14324
+ const result = await waitForExit({ fs: fs4 }, input.jobId);
14325
+ const preserveMs = input.preserveAfterExitHours * 60 * 60 * 1e3;
14326
+ if (preserveMs > 0) {
14327
+ await input.sandbox.setTimeout(preserveMs);
14328
+ }
14329
+ return result;
14330
+ },
14331
+ async kill() {
14332
+ const pids = input.pid === void 0 ? (await input.sandbox.commands.list()).filter((process2) => processMentionsJob(process2, input.jobId)).map((process2) => process2.pid) : [input.pid];
14333
+ await Promise.all(pids.map((pid) => input.sandbox.commands.kill(pid)));
14334
+ }
14335
+ };
14336
+ }
14337
+ function createE2bLogStreamFs(sandbox) {
14338
+ return {
14339
+ promises: {
14340
+ async readFile(filePath) {
14341
+ return Buffer.from(await sandbox.files.read(filePath, { format: "bytes" }));
14342
+ },
14343
+ async stat(filePath) {
14344
+ const result = await sandbox.commands.run(
14345
+ `stat -c %Y ${shellQuote3(filePath)} 2>/dev/null || stat -f %m ${shellQuote3(filePath)}`
14346
+ );
14347
+ if (!("stdout" in result)) {
14348
+ throw new Error(`Unable to stat ${filePath}`);
14349
+ }
14350
+ const seconds = Number(result.stdout?.trim());
14351
+ if (!Number.isFinite(seconds)) {
14352
+ throw new Error(`Unable to stat ${filePath}`);
14353
+ }
14354
+ return { mtimeMs: seconds * 1e3 };
14355
+ }
14356
+ },
14357
+ watch(filePath, listener) {
14358
+ let closed = false;
14359
+ let stop = null;
14360
+ void sandbox.files.watchDir(path23.dirname(filePath), listener, { recursive: false }).then((handle) => {
14361
+ if (closed) {
14362
+ void handle.stop();
14363
+ return;
14364
+ }
14365
+ stop = () => {
14366
+ void handle.stop();
14367
+ };
14368
+ });
14369
+ return {
14370
+ close() {
14371
+ closed = true;
14372
+ stop?.();
14373
+ }
14374
+ };
14375
+ }
14376
+ };
14377
+ }
14378
+ function processMentionsJob(process2, jobId) {
14379
+ const needle = `/tmp/poe-jobs/${jobId}`;
14380
+ return process2.cmd.includes(needle) || process2.args.some((arg) => arg.includes(needle));
14381
+ }
14382
+ function shellQuote3(value) {
14383
+ return `'${value.replaceAll("'", "'\\''")}'`;
14384
+ }
14385
+ async function readExitCode(sandbox, jobId) {
14386
+ try {
14387
+ const contents = await sandbox.files.read(`${JOB_DIR2}/${jobId}.exit`);
14388
+ const exitCode = Number(contents.trim());
14389
+ return Number.isInteger(exitCode) ? exitCode : null;
14390
+ } catch {
14391
+ return null;
14392
+ }
14393
+ }
14394
+ var JOB_DIR2;
14395
+ var init_job_handle = __esm({
14396
+ "packages/runner-e2b/src/job-handle.ts"() {
14397
+ "use strict";
14398
+ init_src9();
14399
+ JOB_DIR2 = "/tmp/poe-jobs";
14400
+ }
14401
+ });
14402
+
14403
+ // packages/runner-e2b/src/opened-env.ts
14404
+ import { mkdtempSync as mkdtempSync2, rmSync as rmSync2 } from "node:fs";
14405
+ import { readFile as readFile5, writeFile } from "node:fs/promises";
14406
+ import { tmpdir as tmpdir2 } from "node:os";
14407
+ import path24 from "node:path";
14408
+ import { PassThrough as PassThrough2, Writable as Writable2 } from "node:stream";
14409
+ function createOpenedE2bEnv(input) {
14410
+ const hostRunner = input.spec.hostRunner ?? createHostRunner();
14411
+ const hostWorkspaceDir = path24.resolve(input.spec.cwd);
14412
+ const sandboxWorkspaceDir = normalizeSandboxWorkspaceDir(input.runtime.workspace_dir);
14413
+ let lastProcess = null;
14414
+ let detachedJobContext = null;
14415
+ const mapWorkspaceCwd = (cwd) => {
14416
+ if (cwd === void 0) {
14417
+ return void 0;
14418
+ }
14419
+ if (path24.isAbsolute(cwd) && path24.resolve(cwd) === hostWorkspaceDir) {
14420
+ return sandboxWorkspaceDir;
14421
+ }
14422
+ return cwd;
14423
+ };
14424
+ const attachedJobId = input.spec.detachedJobId;
14425
+ const env = {
14426
+ id: input.sandbox.sandboxId,
14427
+ job: attachedJobId ? createE2bJobHandle({
14428
+ sandbox: input.sandbox,
14429
+ envId: input.sandbox.sandboxId,
14430
+ jobId: attachedJobId,
14431
+ tool: input.spec.jobLabel.tool,
14432
+ argv: input.spec.jobLabel.argv,
14433
+ preserveAfterExitHours: input.runtime.preserve_after_exit_hours ?? 24
14434
+ }) : null,
14435
+ fs: createE2bLogStreamFs(input.sandbox),
14436
+ setDetachedJobContext(context) {
14437
+ detachedJobContext = context;
14438
+ },
14439
+ async uploadWorkspace() {
14440
+ if (input.spec.runner?.sync === "none") {
14441
+ return { files: 0, bytes: 0, skipped: [] };
14442
+ }
14443
+ const tempDir = mkdtempSync2(path24.join(tmpdir2(), "poe-e2b-upload-"));
14444
+ const archivePath = path24.join(tempDir, "workspace.tar");
14445
+ try {
14446
+ await runOrThrow2(hostRunner, {
14447
+ command: "tar",
14448
+ args: [
14449
+ ...input.spec.uploadIgnoreFiles.flatMap((ignored) => ["--exclude", ignored]),
14450
+ "-cf",
14451
+ archivePath,
14452
+ "-C",
14453
+ input.spec.cwd,
14454
+ "."
14455
+ ],
14456
+ stdout: "pipe",
14457
+ stderr: "pipe"
14458
+ });
14459
+ await input.sandbox.files.write(
14460
+ "/tmp/poe-workspace-upload.tar",
14461
+ toArrayBuffer(await readFile5(archivePath))
14462
+ );
14463
+ await runRemoteOrThrow(
14464
+ input.sandbox,
14465
+ createUploadWorkspaceCommand(sandboxWorkspaceDir)
14466
+ );
14467
+ return { files: 0, bytes: 0, skipped: [] };
14468
+ } finally {
14469
+ rmSync2(tempDir, { recursive: true, force: true });
14470
+ }
14471
+ },
14472
+ async downloadWorkspace(opts) {
14473
+ if (input.spec.runner?.sync === "upload" || input.spec.runner?.sync === "none") {
14474
+ return { files: 0, bytes: 0, conflicts: [] };
14475
+ }
14476
+ const tempDir = mkdtempSync2(path24.join(tmpdir2(), "poe-e2b-download-"));
14477
+ const archivePath = path24.join(tempDir, "workspace.tar");
14478
+ try {
14479
+ await runRemoteOrThrow(
14480
+ input.sandbox,
14481
+ `tar -cf /tmp/poe-workspace-download.tar -C ${shellQuote4(sandboxWorkspaceDir)} .`
14482
+ );
14483
+ const archive = await input.sandbox.files.read("/tmp/poe-workspace-download.tar", {
14484
+ format: "bytes"
14485
+ });
14486
+ await writeFile(archivePath, Buffer.from(archive));
14487
+ await runOrThrow2(hostRunner, {
14488
+ command: "tar",
14489
+ args: [
14490
+ opts.conflictPolicy === "refuse" ? "-xkf" : "-xf",
14491
+ archivePath,
14492
+ "-C",
14493
+ input.spec.cwd
14494
+ ],
14495
+ stdout: "pipe",
14496
+ stderr: "pipe"
14497
+ });
14498
+ return { files: 0, bytes: archive.byteLength, conflicts: [] };
14499
+ } finally {
14500
+ rmSync2(tempDir, { recursive: true, force: true });
14501
+ }
14502
+ },
14503
+ exec(spec10) {
14504
+ const handle = runE2bCommand(input.sandbox, {
14505
+ ...spec10,
14506
+ cwd: mapWorkspaceCwd(spec10.cwd),
14507
+ env: resolveSandboxCommandEnv(spec10.env)
14508
+ });
14509
+ lastProcess = { started: handle.started };
14510
+ return handle;
14511
+ },
14512
+ async detach() {
14513
+ if (detachedJobContext === null) {
14514
+ throw new Error("Cannot detach E2B environment before a job context is registered.");
14515
+ }
14516
+ if (lastProcess === null) {
14517
+ throw new Error("Cannot detach E2B environment before a command is running.");
14518
+ }
14519
+ const command = await lastProcess.started;
14520
+ const preserveAfterExitHours = input.runtime.preserve_after_exit_hours ?? 24;
14521
+ const preserveMs = preserveAfterExitHours * 60 * 60 * 1e3;
14522
+ if (preserveMs > 0) {
14523
+ await input.sandbox.setTimeout(preserveMs);
14524
+ }
14525
+ return createE2bJobHandle({
14526
+ sandbox: input.sandbox,
14527
+ envId: input.sandbox.sandboxId,
14528
+ jobId: detachedJobContext.id,
14529
+ tool: detachedJobContext.tool,
14530
+ argv: detachedJobContext.argv,
14531
+ pid: command.pid,
14532
+ preserveAfterExitHours
14533
+ });
14534
+ },
14535
+ shell() {
14536
+ const shellSpec = input.spec.shellSpec;
14537
+ const command = shellSpec?.command ?? input.spec.env.SHELL ?? "sh";
14538
+ return runE2bPty(input.sandbox, {
14539
+ command,
14540
+ ...shellSpec?.args ? { args: shellSpec.args } : {},
14541
+ cwd: mapWorkspaceCwd(shellSpec?.cwd ?? input.spec.cwd),
14542
+ env: resolveSandboxCommandEnv(
14543
+ shellSpec && "env" in shellSpec ? shellSpec.env : input.spec.env
14544
+ ),
14545
+ stdin: "inherit",
14546
+ stdout: "inherit",
14547
+ stderr: "inherit",
14548
+ tty: true
14549
+ });
14550
+ },
14551
+ async close() {
14552
+ await input.sandbox.kill();
14553
+ }
14554
+ };
14555
+ return env;
14556
+ }
14557
+ function runE2bCommand(sandbox, spec10) {
14558
+ const stdout = spec10.stdout === "inherit" ? null : new PassThrough2();
14559
+ const stderr = spec10.stderr === "inherit" ? null : new PassThrough2();
14560
+ let e2bHandle = null;
14561
+ const command = shellCommand([spec10.command, ...spec10.args ?? []]);
14562
+ const started = sandbox.commands.run(command, {
14563
+ background: true,
14564
+ cwd: spec10.cwd,
14565
+ envs: spec10.env,
14566
+ stdin: spec10.stdin === "pipe",
14567
+ onStdout(data) {
14568
+ stdout?.write(data);
14569
+ if (spec10.stdout === "inherit") {
14570
+ process.stdout.write(data);
14571
+ }
14572
+ },
14573
+ onStderr(data) {
14574
+ stderr?.write(data);
14575
+ if (spec10.stderr === "inherit") {
14576
+ process.stderr.write(data);
14577
+ }
14578
+ }
14579
+ });
14580
+ const stdin = spec10.stdin === "pipe" ? new Writable2({
14581
+ write(chunk, _encoding, callback) {
14582
+ started.then(
14583
+ (handle) => sandbox.commands.sendStdin(
14584
+ handle.pid,
14585
+ Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))
14586
+ )
14587
+ ).then(() => callback(), callback);
14588
+ },
14589
+ final(callback) {
14590
+ if (sandbox.commands.closeStdin === void 0) {
14591
+ callback();
14592
+ return;
14593
+ }
14594
+ started.then((handle) => sandbox.commands.closeStdin(handle.pid)).then(() => callback(), callback);
14595
+ }
14596
+ }) : null;
14597
+ const result = started.then((handle) => {
14598
+ e2bHandle = handle;
14599
+ return handle.wait();
14600
+ }).then(
14601
+ (result2) => {
14602
+ stdout?.end();
14603
+ stderr?.end();
14604
+ return { exitCode: result2.exitCode ?? 0 };
14605
+ },
14606
+ (error2) => {
14607
+ stdout?.end();
14608
+ stderr?.end();
14609
+ if (isExitError(error2)) {
14610
+ return { exitCode: error2.exitCode };
14611
+ }
14612
+ return { exitCode: 1 };
14613
+ }
14614
+ );
14615
+ return {
14616
+ get pid() {
14617
+ return e2bHandle?.pid ?? null;
14618
+ },
14619
+ stdin,
14620
+ stdout,
14621
+ stderr,
14622
+ result,
14623
+ kill() {
14624
+ void e2bHandle?.kill();
14625
+ },
14626
+ get e2bHandle() {
14627
+ return e2bHandle;
14628
+ },
14629
+ started
14630
+ };
14631
+ }
14632
+ function runE2bPty(sandbox, spec10) {
14633
+ const stdout = new PassThrough2();
14634
+ let handleRef = null;
14635
+ const stdin = new Writable2({
14636
+ write(chunk, _encoding, callback) {
14637
+ if (handleRef === null) {
14638
+ callback(new Error("E2B PTY stdin is not ready."));
14639
+ return;
14640
+ }
14641
+ sandbox.pty.sendInput(handleRef.pid, Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk))).then(() => callback(), callback);
14642
+ }
14643
+ });
14644
+ const started = sandbox.pty.create({
14645
+ cols: process.stdout.columns || 80,
14646
+ rows: process.stdout.rows || 24,
14647
+ cwd: spec10.cwd,
14648
+ envs: spec10.env,
14649
+ onData(data) {
14650
+ stdout.write(Buffer.from(data));
14651
+ if (spec10.stdout === "inherit") {
14652
+ process.stdout.write(Buffer.from(data));
14653
+ }
14654
+ }
14655
+ });
14656
+ const result = started.then((handle) => {
14657
+ handleRef = handle;
14658
+ return handle.wait();
14659
+ }).then(
14660
+ (result2) => {
14661
+ stdout.end();
14662
+ return { exitCode: result2.exitCode ?? 0 };
14663
+ },
14664
+ () => {
14665
+ stdout.end();
14666
+ return { exitCode: 1 };
14667
+ }
14668
+ );
14669
+ return {
14670
+ get pid() {
14671
+ return handleRef?.pid ?? null;
14672
+ },
14673
+ stdin: spec10.stdin === "inherit" ? process.stdin : stdin,
14674
+ stdout: spec10.stdout === "inherit" ? null : stdout,
14675
+ stderr: null,
14676
+ result,
14677
+ kill() {
14678
+ void (handleRef === null ? void 0 : sandbox.pty.kill(handleRef.pid));
14679
+ }
14680
+ };
14681
+ }
14682
+ async function runRemoteOrThrow(sandbox, command) {
14683
+ const stdoutTail = createLineTail(REMOTE_COMMAND_STDERR_TAIL_SIZE);
14684
+ const stderrTail = createLineTail(REMOTE_COMMAND_STDERR_TAIL_SIZE);
14685
+ let result;
14686
+ try {
14687
+ result = await sandbox.commands.run(command, {
14688
+ onStdout(data) {
14689
+ stdoutTail.push(data);
14690
+ },
14691
+ onStderr(data) {
14692
+ stderrTail.push(data);
14693
+ }
14694
+ });
14695
+ } catch (error2) {
14696
+ appendRemoteCommandOutput(error2, stdoutTail, stderrTail);
14697
+ if (isCommandExitError(error2)) {
14698
+ throw decorateRemoteCommandError(error2, command, stderrTail.values());
14699
+ }
14700
+ throw error2;
14701
+ }
14702
+ appendRemoteCommandOutput(result, stdoutTail, stderrTail);
14703
+ if ("exitCode" in result && result.exitCode !== 0) {
14704
+ throw decorateRemoteCommandError(
14705
+ new Error(`E2B command failed with exit code ${result.exitCode}`),
14706
+ command,
14707
+ stderrTail.values()
14708
+ );
14709
+ }
14710
+ }
14711
+ function appendRemoteCommandOutput(source, stdoutTail, stderrTail) {
14712
+ if (!source || typeof source !== "object") {
14713
+ return;
14714
+ }
14715
+ const output = source;
14716
+ if (typeof output.stdout === "string") {
14717
+ stdoutTail.push(output.stdout);
14718
+ }
14719
+ if (typeof output.stderr === "string") {
14720
+ stderrTail.push(output.stderr);
14721
+ }
14722
+ }
14723
+ function decorateRemoteCommandError(error2, command, stderrTail) {
14724
+ const original = error2 instanceof Error ? error2 : new Error(String(error2));
14725
+ const tail = stderrTail.length === 0 ? "" : `
14726
+
14727
+ Last stderr output:
14728
+ ${stderrTail.join("\n")}`;
14729
+ const decorated = new Error(`E2B command failed: ${command}
14730
+ ${original.message}${tail}`);
14731
+ decorated.stack = original.stack;
14732
+ decorated.cause = original;
14733
+ return decorated;
14734
+ }
14735
+ function createLineTail(maxLines) {
14736
+ const lines = [];
14737
+ let pending = "";
14738
+ const appendLine = (line) => {
14739
+ lines.push(trimTrailingCarriageReturn(line));
14740
+ while (lines.length > maxLines) {
14741
+ lines.shift();
14742
+ }
14743
+ };
14744
+ return {
14745
+ push(chunk) {
14746
+ pending += chunk;
14747
+ const parts = pending.split("\n");
14748
+ pending = parts.pop() ?? "";
14749
+ for (const line of parts) {
14750
+ appendLine(line);
14751
+ }
14752
+ },
14753
+ values() {
14754
+ const output = [...lines];
14755
+ if (pending.length > 0) {
14756
+ output.push(trimTrailingCarriageReturn(pending));
14757
+ }
14758
+ return output.slice(-maxLines);
14759
+ }
14760
+ };
14761
+ }
14762
+ function trimTrailingCarriageReturn(value) {
14763
+ return value.endsWith("\r") ? value.slice(0, -1) : value;
14764
+ }
14765
+ async function runOrThrow2(runner, spec10) {
14766
+ const handle = runner.exec(spec10);
14767
+ const stderr = readableToString(handle.stderr);
14768
+ const result = await handle.result;
14769
+ if (result.exitCode !== 0) {
14770
+ throw new Error(
14771
+ `Command failed with exit code ${result.exitCode}: ${spec10.command} ${(spec10.args ?? []).join(" ")}
14772
+ ${await stderr}`
14773
+ );
13675
14774
  }
13676
- });
13677
-
13678
- // packages/process-runner/src/host/host-execution-env.ts
13679
- var hostExecutionEnvFactory;
13680
- var init_host_execution_env = __esm({
13681
- "packages/process-runner/src/host/host-execution-env.ts"() {
14775
+ }
14776
+ function shellCommand(argv) {
14777
+ return argv.map(shellQuote4).join(" ");
14778
+ }
14779
+ function shellQuote4(value) {
14780
+ return `'${value.replaceAll("'", "'\\''")}'`;
14781
+ }
14782
+ function createUploadWorkspaceCommand(sandboxWorkspaceDir) {
14783
+ const quotedWorkspaceDir = shellQuote4(sandboxWorkspaceDir);
14784
+ return [
14785
+ `mkdir -p ${quotedWorkspaceDir} || { command -v sudo >/dev/null 2>&1 && sudo mkdir -p ${quotedWorkspaceDir} && sudo chown "$(id -u):$(id -g)" ${quotedWorkspaceDir}; }`,
14786
+ `test -w ${quotedWorkspaceDir} && tar -xf /tmp/poe-workspace-upload.tar -C ${quotedWorkspaceDir}`
14787
+ ].join("\n");
14788
+ }
14789
+ function resolveSandboxCommandEnv(env) {
14790
+ if (env === void 0) {
14791
+ return void 0;
14792
+ }
14793
+ return {
14794
+ ...env,
14795
+ HOME: "/home/user"
14796
+ };
14797
+ }
14798
+ function normalizeSandboxWorkspaceDir(workspaceDir) {
14799
+ const resolvedWorkspaceDir = workspaceDir ?? "/workspace";
14800
+ if (!path24.posix.isAbsolute(resolvedWorkspaceDir)) {
14801
+ throw new Error("E2B runtime workspace_dir must be an absolute sandbox path.");
14802
+ }
14803
+ let normalized = path24.posix.normalize(resolvedWorkspaceDir);
14804
+ while (normalized.length > 1 && normalized.endsWith("/")) {
14805
+ normalized = normalized.slice(0, -1);
14806
+ }
14807
+ return normalized;
14808
+ }
14809
+ function isExitError(error2) {
14810
+ return Boolean(
14811
+ error2 && typeof error2 === "object" && typeof error2.exitCode === "number"
14812
+ );
14813
+ }
14814
+ function isCommandExitError(error2) {
14815
+ return isExitError(error2) || Boolean(
14816
+ error2 && typeof error2 === "object" && error2.name === "CommandExitError"
14817
+ );
14818
+ }
14819
+ var REMOTE_COMMAND_STDERR_TAIL_SIZE;
14820
+ var init_opened_env = __esm({
14821
+ "packages/runner-e2b/src/opened-env.ts"() {
13682
14822
  "use strict";
13683
- init_host_runner();
13684
- hostExecutionEnvFactory = {
13685
- type: "host",
13686
- supportsDetach: false,
13687
- async open(openSpec) {
13688
- return {
13689
- id: "host",
13690
- job: null,
13691
- async uploadWorkspace() {
13692
- return {
13693
- files: 0,
13694
- bytes: 0,
13695
- skipped: []
13696
- };
13697
- },
13698
- async downloadWorkspace() {
13699
- return {
13700
- files: 0,
13701
- bytes: 0,
13702
- conflicts: []
13703
- };
13704
- },
13705
- exec(spec10) {
13706
- return createHostRunner().exec(spec10);
13707
- },
13708
- async detach() {
13709
- throw new Error("host runtime does not support detach because host has no addressable env");
13710
- },
13711
- shell() {
13712
- const shellSpec = openSpec.shellSpec;
13713
- return createHostRunner().exec({
13714
- command: shellSpec?.command ?? openSpec.env.SHELL ?? process.env.SHELL ?? "sh",
13715
- ...shellSpec?.args ? { args: shellSpec.args } : {},
13716
- cwd: openSpec.cwd,
13717
- env: shellSpec && "env" in shellSpec ? shellSpec.env : openSpec.env,
13718
- stdin: "inherit",
13719
- stdout: "inherit",
13720
- stderr: "inherit",
13721
- tty: true
13722
- });
13723
- },
13724
- async close() {
13725
- }
13726
- };
13727
- },
13728
- async attach() {
13729
- throw new Error("host runtime does not support reattach");
13730
- }
13731
- };
14823
+ init_src10();
14824
+ init_job_handle();
14825
+ init_sdk();
14826
+ REMOTE_COMMAND_STDERR_TAIL_SIZE = 30;
13732
14827
  }
13733
14828
  });
13734
14829
 
13735
- // packages/process-runner/src/testing/mock-runner.ts
13736
- import { Readable, Writable } from "node:stream";
13737
- var init_mock_runner = __esm({
13738
- "packages/process-runner/src/testing/mock-runner.ts"() {
14830
+ // packages/runner-e2b/src/auth-scope.ts
14831
+ import os5 from "node:os";
14832
+ import { promises as nodeFs4 } from "node:fs";
14833
+ async function resolveE2bApiKey(input) {
14834
+ const homeDir = input.homeDir ?? os5.homedir();
14835
+ const fs4 = input.fs ?? nodeFs4;
14836
+ const env = input.env ?? process.env;
14837
+ const document = await readMergedDocument(
14838
+ fs4,
14839
+ resolveConfigPath(homeDir),
14840
+ resolveProjectConfigPath(input.cwd)
14841
+ );
14842
+ const resolved = resolveScope(e2bAuthScope.schema, document.e2b, env);
14843
+ if (resolved.api_key.length === 0) {
14844
+ throw new Error(
14845
+ "No E2B API key. Set E2B_API_KEY or e2b.api_key in ~/.poe-code/config.json."
14846
+ );
14847
+ }
14848
+ return resolved.api_key;
14849
+ }
14850
+ var e2bAuthScope;
14851
+ var init_auth_scope = __esm({
14852
+ "packages/runner-e2b/src/auth-scope.ts"() {
13739
14853
  "use strict";
14854
+ init_src5();
14855
+ e2bAuthScope = defineScope("e2b", {
14856
+ api_key: {
14857
+ type: "string",
14858
+ default: "",
14859
+ doc: "E2B API key",
14860
+ env: "E2B_API_KEY"
14861
+ }
14862
+ });
13740
14863
  }
13741
14864
  });
13742
14865
 
13743
- // packages/process-runner/src/testing/index.ts
13744
- var init_testing = __esm({
13745
- "packages/process-runner/src/testing/index.ts"() {
14866
+ // packages/runner-e2b/src/factory.ts
14867
+ import path25 from "node:path";
14868
+ function parseE2bRuntime(runtime) {
14869
+ if (!runtime || typeof runtime !== "object" || Array.isArray(runtime)) {
14870
+ throw new Error("e2b runtime must be an object");
14871
+ }
14872
+ const record = runtime;
14873
+ if (record.type !== "e2b") {
14874
+ throw new Error('e2b runtime type must be "e2b"');
14875
+ }
14876
+ return record;
14877
+ }
14878
+ var e2bExecutionEnvFactory;
14879
+ var init_factory = __esm({
14880
+ "packages/runner-e2b/src/factory.ts"() {
13746
14881
  "use strict";
13747
- init_mock_runner();
14882
+ init_sdk();
14883
+ init_template_build();
14884
+ init_opened_env();
14885
+ init_auth_scope();
14886
+ e2bExecutionEnvFactory = {
14887
+ type: "e2b",
14888
+ supportsDetach: true,
14889
+ async open(spec10) {
14890
+ const runtime = parseE2bRuntime(spec10.runtime);
14891
+ const runtimeCwd = spec10.runtimeCwd ?? spec10.cwd;
14892
+ const apiKey = await resolveE2bApiKey({ cwd: runtimeCwd });
14893
+ const templateId = runtime.template_id ?? (await buildE2bRuntimeTemplate({
14894
+ runtime,
14895
+ dockerfilePath: path25.resolve(
14896
+ runtimeCwd,
14897
+ runtime.dockerfile ?? path25.join(".poe-code", "Dockerfile")
14898
+ ),
14899
+ buildContext: path25.resolve(runtimeCwd, runtime.build_context ?? "."),
14900
+ state: spec10.state,
14901
+ apiKey
14902
+ })).templateId;
14903
+ const sandbox = await createSandbox({
14904
+ apiKey,
14905
+ templateId,
14906
+ env: spec10.env,
14907
+ timeoutMinutes: runtime.timeout_minutes
14908
+ });
14909
+ return createOpenedE2bEnv({ sandbox, spec: spec10, runtime });
14910
+ },
14911
+ async attach(envId, context) {
14912
+ const cwd = context?.cwd ?? process.cwd();
14913
+ const apiKey = await resolveE2bApiKey({ cwd });
14914
+ const sandbox = await connectSandbox(envId, apiKey);
14915
+ return createOpenedE2bEnv({
14916
+ sandbox,
14917
+ spec: {
14918
+ cwd: context?.cwd ?? "/workspace",
14919
+ runtime: {
14920
+ type: "e2b",
14921
+ build_args: {},
14922
+ mounts: [],
14923
+ workspace_dir: "/workspace",
14924
+ preserve_after_exit_hours: 24
14925
+ },
14926
+ env: {},
14927
+ uploadIgnoreFiles: [],
14928
+ jobLabel: { tool: context?.tool ?? "e2b", argv: context?.argv ?? [] },
14929
+ ...context?.jobId ? { detachedJobId: context.jobId } : {}
14930
+ },
14931
+ runtime: {
14932
+ type: "e2b",
14933
+ build_args: {},
14934
+ mounts: [],
14935
+ workspace_dir: "/workspace",
14936
+ preserve_after_exit_hours: 24
14937
+ }
14938
+ });
14939
+ }
14940
+ };
13748
14941
  }
13749
14942
  });
13750
14943
 
13751
- // packages/process-runner/src/index.ts
13752
- var init_src10 = __esm({
13753
- "packages/process-runner/src/index.ts"() {
14944
+ // packages/runner-e2b/src/index.ts
14945
+ var e2bExecutionEnvFactory2;
14946
+ var init_src11 = __esm({
14947
+ "packages/runner-e2b/src/index.ts"() {
13754
14948
  "use strict";
13755
- init_context();
13756
- init_engine();
13757
- init_docker_runner();
13758
- init_docker_execution_env();
13759
- init_host_execution_env();
13760
- init_host_runner();
13761
- init_testing();
14949
+ init_factory();
14950
+ init_auth_scope();
14951
+ init_template_build();
14952
+ e2bExecutionEnvFactory2 = e2bExecutionEnvFactory;
13762
14953
  }
13763
14954
  });
13764
14955
 
13765
14956
  // packages/agent-spawn/src/register-factories.ts
13766
14957
  import { spawn as spawnChildProcess3 } from "node:child_process";
14958
+ function isVitest() {
14959
+ return process.env.VITEST !== void 0 || process.env.VITEST_POOL_ID !== void 0;
14960
+ }
13767
14961
  function createTestHostExecutionEnvFactory() {
13768
14962
  return {
13769
14963
  type: "host",
@@ -13847,9 +15041,11 @@ var init_register_factories = __esm({
13847
15041
  "use strict";
13848
15042
  init_src9();
13849
15043
  init_src10();
15044
+ init_src11();
13850
15045
  registerExecutionEnvFactory(hostExecutionEnvFactory);
13851
15046
  registerExecutionEnvFactory(dockerExecutionEnvFactory);
13852
- if (process.env.VITEST === "true") {
15047
+ registerExecutionEnvFactory(e2bExecutionEnvFactory2);
15048
+ if (isVitest()) {
13853
15049
  registerExecutionEnvFactory(createTestHostExecutionEnvFactory());
13854
15050
  }
13855
15051
  }
@@ -14322,7 +15518,7 @@ var init_runtime2 = __esm({
14322
15518
 
14323
15519
  // packages/agent-spawn/src/spawn.ts
14324
15520
  import { mkdirSync, openSync, writeSync, closeSync } from "node:fs";
14325
- import path22 from "node:path";
15521
+ import path26 from "node:path";
14326
15522
  function createAbortError3() {
14327
15523
  const error2 = new Error("Agent spawn aborted");
14328
15524
  error2.name = "AbortError";
@@ -14419,6 +15615,7 @@ async function spawn6(agentId, options, context) {
14419
15615
  const argv = [binaryName, ...spawnArgs];
14420
15616
  const execution = resolvePoeCommandExecution({
14421
15617
  cwd: options.cwd ?? process.cwd(),
15618
+ runtimeConfigCwd: options.runtimeConfigCwd,
14422
15619
  env: processEnv ?? process.env,
14423
15620
  argv,
14424
15621
  tool: resolvedId,
@@ -14427,7 +15624,8 @@ async function spawn6(agentId, options, context) {
14427
15624
  runtimeImage: options.runtimeImage,
14428
15625
  runtimeTemplate: options.runtimeTemplate,
14429
15626
  detach: options.detach,
14430
- mountPoeCode: options.mountPoeCode
15627
+ mountPoeCode: options.mountPoeCode,
15628
+ runnerSync: options.runnerSync
14431
15629
  },
14432
15630
  context,
14433
15631
  openSpec: {
@@ -14464,6 +15662,7 @@ async function spawn6(agentId, options, context) {
14464
15662
  stdout: "",
14465
15663
  stderr: "",
14466
15664
  exitCode: 0,
15665
+ detached: { jobId: result.jobId, envId: result.envId },
14467
15666
  ...logFilePath ? { logFile: logFilePath } : {}
14468
15667
  };
14469
15668
  }
@@ -14485,11 +15684,11 @@ function resolveSpawnLogPath(options) {
14485
15684
  if (!options.logDir || !options.logFileName) {
14486
15685
  return void 0;
14487
15686
  }
14488
- return path22.join(options.logDir, options.logFileName);
15687
+ return path26.join(options.logDir, options.logFileName);
14489
15688
  }
14490
15689
  function openSpawnLog(filePath) {
14491
15690
  try {
14492
- mkdirSync(path22.dirname(filePath), { recursive: true });
15691
+ mkdirSync(path26.dirname(filePath), { recursive: true });
14493
15692
  return openSync(filePath, "a");
14494
15693
  } catch {
14495
15694
  return void 0;
@@ -14735,6 +15934,12 @@ var init_text = __esm({
14735
15934
  if (format === "markdown") return `**${content}**`;
14736
15935
  return typography.bold(content);
14737
15936
  },
15937
+ sectionHeader(content) {
15938
+ const format = resolveOutputFormat();
15939
+ if (format === "json") return content;
15940
+ if (format === "markdown") return `## ${content}`;
15941
+ return typography.bold(content.toUpperCase());
15942
+ },
14738
15943
  command(content) {
14739
15944
  const format = resolveOutputFormat();
14740
15945
  if (format === "json") return content;
@@ -15079,7 +16284,13 @@ var init_help_formatter = __esm({
15079
16284
  "packages/design-system/src/components/help-formatter.ts"() {
15080
16285
  "use strict";
15081
16286
  init_text();
15082
- init_widths();
16287
+ }
16288
+ });
16289
+
16290
+ // packages/design-system/src/components/help-formatter-plain.ts
16291
+ var init_help_formatter_plain = __esm({
16292
+ "packages/design-system/src/components/help-formatter-plain.ts"() {
16293
+ "use strict";
15083
16294
  }
15084
16295
  });
15085
16296
 
@@ -20412,7 +21623,7 @@ var init_store2 = __esm({
20412
21623
 
20413
21624
  // packages/design-system/src/dashboard/terminal.ts
20414
21625
  import readline from "node:readline";
20415
- import { PassThrough as PassThrough2 } from "node:stream";
21626
+ import { PassThrough as PassThrough3 } from "node:stream";
20416
21627
  function createTerminalDriver(opts) {
20417
21628
  const stdin = opts?.stdin ?? process.stdin;
20418
21629
  const stdout = opts?.stdout ?? process.stdout;
@@ -20967,7 +22178,7 @@ var init_static = __esm({
20967
22178
  });
20968
22179
 
20969
22180
  // packages/design-system/src/index.ts
20970
- var init_src11 = __esm({
22181
+ var init_src12 = __esm({
20971
22182
  "packages/design-system/src/index.ts"() {
20972
22183
  "use strict";
20973
22184
  init_tokens();
@@ -20979,6 +22190,7 @@ var init_src11 = __esm({
20979
22190
  init_symbols();
20980
22191
  init_logger();
20981
22192
  init_help_formatter();
22193
+ init_help_formatter_plain();
20982
22194
  init_command_errors();
20983
22195
  init_command_errors();
20984
22196
  init_table();
@@ -21091,7 +22303,7 @@ async function renderAcpStream(events) {
21091
22303
  var init_renderer2 = __esm({
21092
22304
  "packages/agent-spawn/src/acp/renderer.ts"() {
21093
22305
  "use strict";
21094
- init_src11();
22306
+ init_src12();
21095
22307
  init_session_update_converter();
21096
22308
  }
21097
22309
  });
@@ -21108,9 +22320,9 @@ var init_autonomous = __esm({
21108
22320
  });
21109
22321
 
21110
22322
  // packages/agent-spawn/src/acp/replay.ts
21111
- import path23 from "node:path";
22323
+ import path27 from "node:path";
21112
22324
  import { homedir as homedir3 } from "node:os";
21113
- import { open as open2, readdir } from "node:fs/promises";
22325
+ import { open as open2, readdir as readdir2 } from "node:fs/promises";
21114
22326
  import { createInterface } from "node:readline";
21115
22327
  var init_replay = __esm({
21116
22328
  "packages/agent-spawn/src/acp/replay.ts"() {
@@ -21228,21 +22440,21 @@ async function* adaptClaude(lines) {
21228
22440
  if (blockType !== "tool_result") continue;
21229
22441
  const kind = toolKindsById.get(item.tool_use_id);
21230
22442
  toolKindsById.delete(item.tool_use_id);
21231
- let path37;
22443
+ let path41;
21232
22444
  if (typeof item.content === "string") {
21233
- path37 = item.content;
22445
+ path41 = item.content;
21234
22446
  } else {
21235
22447
  try {
21236
- path37 = JSON.stringify(item.content);
22448
+ path41 = JSON.stringify(item.content);
21237
22449
  } catch {
21238
- path37 = String(item.content);
22450
+ path41 = String(item.content);
21239
22451
  }
21240
22452
  }
21241
22453
  yield {
21242
22454
  event: "tool_complete",
21243
22455
  id: item.tool_use_id,
21244
22456
  kind,
21245
- path: path37
22457
+ path: path41
21246
22458
  };
21247
22459
  }
21248
22460
  }
@@ -21365,10 +22577,10 @@ async function* adaptCodex(lines) {
21365
22577
  const kindFromStart = toolKindById.get(item.id);
21366
22578
  const kind = kindFromStart ?? (itemType === "command_execution" ? "exec" : itemType === "file_edit" ? "edit" : "other");
21367
22579
  const titleFromEvent = isNonEmptyString(item.path) ? item.path : itemType === "mcp_tool_call" ? `${isNonEmptyString(item.server) ? item.server : "unknown"}.${isNonEmptyString(item.tool) ? item.tool : "unknown"}` : void 0;
21368
- const path37 = titleFromEvent ?? toolTitleById.get(item.id) ?? "";
22580
+ const path41 = titleFromEvent ?? toolTitleById.get(item.id) ?? "";
21369
22581
  toolTitleById.delete(item.id);
21370
22582
  toolKindById.delete(item.id);
21371
- yield { event: "tool_complete", id: item.id, kind, path: path37 };
22583
+ yield { event: "tool_complete", id: item.id, kind, path: path41 };
21372
22584
  }
21373
22585
  }
21374
22586
  }
@@ -21751,6 +22963,7 @@ function spawnStreaming(options) {
21751
22963
  const argv = [binaryName, ...args];
21752
22964
  const execution = resolvePoeCommandExecution({
21753
22965
  cwd: options.cwd ?? process.cwd(),
22966
+ runtimeConfigCwd: options.runtimeConfigCwd,
21754
22967
  env: processEnv ?? process.env,
21755
22968
  argv,
21756
22969
  tool: agentId,
@@ -21759,7 +22972,8 @@ function spawnStreaming(options) {
21759
22972
  runtimeImage: options.runtimeImage,
21760
22973
  runtimeTemplate: options.runtimeTemplate,
21761
22974
  detach: options.detach,
21762
- mountPoeCode: options.mountPoeCode
22975
+ mountPoeCode: options.mountPoeCode,
22976
+ runnerSync: options.runnerSync
21763
22977
  },
21764
22978
  openSpec: {
21765
22979
  execution: {
@@ -21798,7 +23012,12 @@ function spawnStreaming(options) {
21798
23012
  signal: options.signal
21799
23013
  });
21800
23014
  if (runResult.kind === "detached") {
21801
- return { stdout: "", stderr: "", exitCode: 0 };
23015
+ return {
23016
+ stdout: "",
23017
+ stderr: "",
23018
+ exitCode: 0,
23019
+ detached: { jobId: runResult.jobId, envId: runResult.envId }
23020
+ };
21802
23021
  }
21803
23022
  result.stderr = runResult.stderr ?? "";
21804
23023
  result.exitCode = runResult.exitCode;
@@ -21923,7 +23142,7 @@ function updateSessionFromEvent(ctx, event, toolCallsById) {
21923
23142
  }
21924
23143
  const id = readString(event.id);
21925
23144
  const kind = readString(event.kind);
21926
- const path37 = readString(event.path);
23145
+ const path41 = readString(event.path);
21927
23146
  let toolCall = id ? toolCallsById.get(id) : void 0;
21928
23147
  if (!toolCall) {
21929
23148
  toolCall = {};
@@ -21938,8 +23157,8 @@ function updateSessionFromEvent(ctx, event, toolCallsById) {
21938
23157
  if (kind) {
21939
23158
  toolCall.kind = kind;
21940
23159
  }
21941
- if (path37) {
21942
- toolCall.path = path37;
23160
+ if (path41) {
23161
+ toolCall.path = path41;
21943
23162
  }
21944
23163
  }
21945
23164
  var sessionCapture;
@@ -22025,7 +23244,7 @@ var init_usage_capture = __esm({
22025
23244
  });
22026
23245
 
22027
23246
  // packages/agent-spawn/src/acp/middlewares/spawn-log.ts
22028
- import path24 from "node:path";
23247
+ import path28 from "node:path";
22029
23248
  import { homedir as homedir4 } from "node:os";
22030
23249
  import { mkdir as mkdir2, open as open3 } from "node:fs/promises";
22031
23250
  function pad2(value, width) {
@@ -22062,14 +23281,14 @@ function resolveLogFilePath(ctx) {
22062
23281
  if (ctx.logPath) {
22063
23282
  return ctx.logPath;
22064
23283
  }
22065
- const baseDir = ctx.logDir ?? path24.join(homedir4(), ".poe-code", "spawn-logs");
23284
+ const baseDir = ctx.logDir ?? path28.join(homedir4(), ".poe-code", "spawn-logs");
22066
23285
  if (ctx.logFileName) {
22067
- return path24.join(baseDir, ctx.logFileName);
23286
+ return path28.join(baseDir, ctx.logFileName);
22068
23287
  }
22069
23288
  const startedAt = resolveStartedAt(ctx.startedAt);
22070
23289
  const { day, time, milliseconds } = formatTimestamp(startedAt);
22071
23290
  const fileName = `${day}-${time}-${milliseconds}-${normalizeAgent(ctx.agent)}.jsonl`;
22072
- return path24.join(baseDir, fileName);
23291
+ return path28.join(baseDir, fileName);
22073
23292
  }
22074
23293
  async function writePreloadedEvents(writer, events) {
22075
23294
  for (const event of events) {
@@ -22087,7 +23306,7 @@ var init_spawn_log = __esm({
22087
23306
  logDirPath;
22088
23307
  constructor(ctx) {
22089
23308
  this.filePath = resolveLogFilePath(ctx);
22090
- this.logDirPath = path24.dirname(this.filePath);
23309
+ this.logDirPath = path28.dirname(this.filePath);
22091
23310
  }
22092
23311
  async writeEvent(event) {
22093
23312
  if (this.isDisabled) {
@@ -22155,7 +23374,7 @@ var init_spawn_log = __esm({
22155
23374
  });
22156
23375
 
22157
23376
  // packages/agent-spawn/src/index.ts
22158
- var init_src12 = __esm({
23377
+ var init_src13 = __esm({
22159
23378
  "packages/agent-spawn/src/index.ts"() {
22160
23379
  "use strict";
22161
23380
  init_register_factories();
@@ -22185,7 +23404,7 @@ var gitContext, poe_agent_plugin_git_context_default;
22185
23404
  var init_poe_agent_plugin_git_context = __esm({
22186
23405
  "packages/poe-agent/src/plugins/poe-agent-plugin-git-context.ts"() {
22187
23406
  "use strict";
22188
- init_src12();
23407
+ init_src13();
22189
23408
  gitContext = (cwd) => ({
22190
23409
  name: "git-context",
22191
23410
  async prompt(ctx) {
@@ -22424,7 +23643,7 @@ __export(src_exports, {
22424
23643
  systemPromptPlugin: () => poe_agent_plugin_system_prompt_default,
22425
23644
  webPlugin: () => poe_agent_plugin_web_default
22426
23645
  });
22427
- var init_src13 = __esm({
23646
+ var init_src14 = __esm({
22428
23647
  "packages/poe-agent/src/index.ts"() {
22429
23648
  "use strict";
22430
23649
  init_agent();
@@ -22456,7 +23675,7 @@ var init_src13 = __esm({
22456
23675
 
22457
23676
  // src/providers/poe-agent.ts
22458
23677
  import fsPromises8 from "node:fs/promises";
22459
- import os6 from "node:os";
23678
+ import os7 from "node:os";
22460
23679
 
22461
23680
  // src/cli/constants.ts
22462
23681
  var DEFAULT_FRONTIER_MODEL = "anthropic/claude-opus-4.7";
@@ -22650,16 +23869,16 @@ function createInstallRunner(definition) {
22650
23869
  // src/services/config.ts
22651
23870
  init_src3();
22652
23871
  init_src5();
22653
- init_src13();
22654
- import path36 from "node:path";
23872
+ init_src14();
23873
+ import path40 from "node:path";
22655
23874
 
22656
23875
  // packages/superintendent/src/document/parse.ts
22657
- import path25 from "node:path";
23876
+ import path29 from "node:path";
22658
23877
  import { parseDocument as parseDocument2 } from "yaml";
22659
23878
  var superintendentDocumentSchemaId = "https://poe-platform.github.io/poe-code/schemas/plans/superintendent.schema.json";
22660
23879
  var validStatusStates = /* @__PURE__ */ new Set(["in_progress", "review", "completed"]);
22661
23880
  function parseSuperintendentDoc(filePath, content) {
22662
- const resolvedFilePath = path25.resolve(filePath);
23881
+ const resolvedFilePath = path29.resolve(filePath);
22663
23882
  const { frontmatterText, body } = splitFrontmatter(resolvedFilePath, content);
22664
23883
  const parsedFrontmatter = parseYamlFrontmatter(resolvedFilePath, frontmatterText);
22665
23884
  return {
@@ -22669,7 +23888,7 @@ function parseSuperintendentDoc(filePath, content) {
22669
23888
  };
22670
23889
  }
22671
23890
  function readExplicitBuilderAgent(filePath, content) {
22672
- const resolvedFilePath = path25.resolve(filePath);
23891
+ const resolvedFilePath = path29.resolve(filePath);
22673
23892
  const { frontmatterText } = splitFrontmatter(resolvedFilePath, content);
22674
23893
  const parsedFrontmatter = parseYamlFrontmatter(resolvedFilePath, frontmatterText);
22675
23894
  const frontmatter = expectRecord(parsedFrontmatter, "frontmatter", resolvedFilePath);
@@ -22826,7 +24045,7 @@ function parseStatusBlock(value, filePath) {
22826
24045
  };
22827
24046
  }
22828
24047
  function expectRecord(value, fieldName, filePath) {
22829
- if (!isRecord6(value)) {
24048
+ if (!isRecord7(value)) {
22830
24049
  throw new Error(`${filePath}: ${fieldName} must be a mapping`);
22831
24050
  }
22832
24051
  return value;
@@ -22855,12 +24074,12 @@ function expectStringArray(value, fieldName, filePath) {
22855
24074
  }
22856
24075
  return value;
22857
24076
  }
22858
- function isRecord6(value) {
24077
+ function isRecord7(value) {
22859
24078
  return typeof value === "object" && value !== null && !Array.isArray(value);
22860
24079
  }
22861
24080
 
22862
24081
  // packages/superintendent/src/document/write.ts
22863
- import path26 from "node:path";
24082
+ import path30 from "node:path";
22864
24083
  import { isMap, parseDocument as parseDocument3 } from "yaml";
22865
24084
  function updateStatus(filePath, content, status) {
22866
24085
  return updateFrontmatter(filePath, content, (frontmatterDocument) => {
@@ -22881,7 +24100,7 @@ function setStatusReason(filePath, content, reason) {
22881
24100
  });
22882
24101
  }
22883
24102
  function updateFrontmatter(filePath, content, mutate) {
22884
- const resolvedFilePath = path26.resolve(filePath);
24103
+ const resolvedFilePath = path30.resolve(filePath);
22885
24104
  const parts = splitDocument(resolvedFilePath, content);
22886
24105
  const frontmatterDocument = parseDocument3(parts.frontmatterText);
22887
24106
  if (frontmatterDocument.errors.length > 0) {
@@ -23005,7 +24224,7 @@ function formatFrontmatter(serialized, lineBreak) {
23005
24224
  }
23006
24225
 
23007
24226
  // packages/superintendent/src/document/tasks.ts
23008
- init_src11();
24227
+ init_src12();
23009
24228
  function parseTaskBoard(body) {
23010
24229
  const sectionNodes = readTaskBoardSection(body);
23011
24230
  const tasks = [];
@@ -23107,7 +24326,7 @@ function extractText(node) {
23107
24326
 
23108
24327
  // packages/superintendent/src/runtime/loop.ts
23109
24328
  init_src9();
23110
- import path29 from "node:path";
24329
+ import path33 from "node:path";
23111
24330
  import * as fsPromises6 from "node:fs/promises";
23112
24331
 
23113
24332
  // packages/superintendent/src/state/machine.ts
@@ -23126,9 +24345,9 @@ function createLoopState(doc) {
23126
24345
  // packages/superintendent/src/runtime/agent-runner.ts
23127
24346
  init_register_factories();
23128
24347
  init_src9();
23129
- init_src12();
24348
+ init_src13();
23130
24349
  import { mkdirSync as mkdirSync2, openSync as openSync2, writeSync as writeSync2, closeSync as closeSync2 } from "node:fs";
23131
- import path27 from "node:path";
24350
+ import path31 from "node:path";
23132
24351
  var injectedRunner;
23133
24352
  async function withAutonomousAgentRunner(runner, operation) {
23134
24353
  const previous = injectedRunner;
@@ -23151,7 +24370,8 @@ async function runAutonomousAgent(input) {
23151
24370
  ...input.runtimeImage ? { runtimeImage: input.runtimeImage } : {},
23152
24371
  ...input.runtimeTemplate ? { runtimeTemplate: input.runtimeTemplate } : {},
23153
24372
  ...input.detach ? { detach: input.detach } : {},
23154
- ...input.mountPoeCode ? { mountPoeCode: input.mountPoeCode } : {}
24373
+ ...input.mountPoeCode ? { mountPoeCode: input.mountPoeCode } : {},
24374
+ ...input.runnerSync ? { runnerSync: input.runnerSync } : {}
23155
24375
  });
23156
24376
  }
23157
24377
  const spawnArgs = buildSpawnArgs(input.agent, {
@@ -23172,7 +24392,8 @@ async function runAutonomousAgent(input) {
23172
24392
  runtimeImage: input.runtimeImage,
23173
24393
  runtimeTemplate: input.runtimeTemplate,
23174
24394
  detach: input.detach,
23175
- mountPoeCode: input.mountPoeCode
24395
+ mountPoeCode: input.mountPoeCode,
24396
+ runnerSync: input.runnerSync
23176
24397
  },
23177
24398
  openSpec: {
23178
24399
  execution: {
@@ -23214,7 +24435,7 @@ async function runAutonomousAgent(input) {
23214
24435
  }
23215
24436
  function openSpawnLog2(filePath) {
23216
24437
  try {
23217
- mkdirSync2(path27.dirname(filePath), { recursive: true });
24438
+ mkdirSync2(path31.dirname(filePath), { recursive: true });
23218
24439
  return openSync2(filePath, "a");
23219
24440
  } catch {
23220
24441
  return void 0;
@@ -23239,15 +24460,15 @@ function closeSpawnLog2(fd) {
23239
24460
  init_register_factories();
23240
24461
 
23241
24462
  // packages/superintendent/src/runtime/resolve-cwd.ts
23242
- import path28 from "node:path";
24463
+ import path32 from "node:path";
23243
24464
  function resolveRoleCwd(role, docPath, defaultCwd) {
23244
24465
  if (role.cwd === void 0) {
23245
24466
  return defaultCwd;
23246
24467
  }
23247
- if (path28.isAbsolute(role.cwd)) {
24468
+ if (path32.isAbsolute(role.cwd)) {
23248
24469
  return role.cwd;
23249
24470
  }
23250
- return path28.resolve(path28.dirname(docPath), role.cwd);
24471
+ return path32.resolve(path32.dirname(docPath), role.cwd);
23251
24472
  }
23252
24473
 
23253
24474
  // packages/superintendent/src/runtime/templates.ts
@@ -23267,9 +24488,9 @@ function collectReferencedInspectors(template) {
23267
24488
  return names;
23268
24489
  }
23269
24490
  function readTemplateValue(context, variablePath) {
23270
- return variablePath.split(".").reduce((value, segment) => isRecord7(value) ? value[segment] : void 0, context);
24491
+ return variablePath.split(".").reduce((value, segment) => isRecord8(value) ? value[segment] : void 0, context);
23271
24492
  }
23272
- function isRecord7(value) {
24493
+ function isRecord8(value) {
23273
24494
  return typeof value === "object" && value !== null;
23274
24495
  }
23275
24496
 
@@ -23528,7 +24749,7 @@ function createWorkflowTool(role, state) {
23528
24749
  };
23529
24750
  }
23530
24751
  function parseWorkflowCall(input) {
23531
- if (!isRecord8(input)) {
24752
+ if (!isRecord9(input)) {
23532
24753
  throw invalidActionError();
23533
24754
  }
23534
24755
  const { action } = input;
@@ -23600,7 +24821,7 @@ function invalidActionError() {
23600
24821
  'workflow_transition action must be one of "request_review", "approve_completion", or "request_changes"'
23601
24822
  );
23602
24823
  }
23603
- function isRecord8(value) {
24824
+ function isRecord9(value) {
23604
24825
  return typeof value === "object" && value !== null && !Array.isArray(value);
23605
24826
  }
23606
24827
 
@@ -23690,7 +24911,7 @@ function collectToolNames(result) {
23690
24911
  }
23691
24912
  const names = [];
23692
24913
  collectToolNamesFrom(result.toolCalls, names);
23693
- if (isRecord9(result.sessionResult)) {
24914
+ if (isRecord10(result.sessionResult)) {
23694
24915
  collectToolNamesFrom(result.sessionResult.toolCalls, names);
23695
24916
  }
23696
24917
  return names;
@@ -23735,13 +24956,13 @@ function readTransitionFromToolCalls(value) {
23735
24956
  return void 0;
23736
24957
  }
23737
24958
  function readTransitionFromSessionResult(value) {
23738
- if (!isRecord9(value)) {
24959
+ if (!isRecord10(value)) {
23739
24960
  return void 0;
23740
24961
  }
23741
24962
  return readTransitionFromToolCalls(value.toolCalls);
23742
24963
  }
23743
24964
  function readToolCall(value) {
23744
- return isRecord9(value) ? value : void 0;
24965
+ return isRecord10(value) ? value : void 0;
23745
24966
  }
23746
24967
  function readToolCallName(toolCall) {
23747
24968
  return readString4(toolCall.name) ?? readString4(toolCall.tool) ?? readString4(toolCall.title) ?? readString4(toolCall.path);
@@ -23778,7 +24999,7 @@ function encodeJson(value) {
23778
24999
  function readString4(value) {
23779
25000
  return typeof value === "string" ? value : void 0;
23780
25001
  }
23781
- function isRecord9(value) {
25002
+ function isRecord10(value) {
23782
25003
  return typeof value === "object" && value !== null && !Array.isArray(value);
23783
25004
  }
23784
25005
 
@@ -23887,7 +25108,7 @@ function readTransitionFromToolCalls2(value) {
23887
25108
  return void 0;
23888
25109
  }
23889
25110
  function readTransitionFromSessionResult2(value) {
23890
- if (!isRecord10(value)) {
25111
+ if (!isRecord11(value)) {
23891
25112
  return void 0;
23892
25113
  }
23893
25114
  return readTransitionFromToolCalls2(value.toolCalls);
@@ -23912,7 +25133,7 @@ function extractOutputText(result) {
23912
25133
  return readString5(result.output) ?? readString5(result.stdout) ?? readString5(result.text) ?? "";
23913
25134
  }
23914
25135
  function readToolCall2(value) {
23915
- return isRecord10(value) ? value : void 0;
25136
+ return isRecord11(value) ? value : void 0;
23916
25137
  }
23917
25138
  function readToolCallName2(toolCall) {
23918
25139
  return readString5(toolCall.name) ?? readString5(toolCall.tool) ?? readString5(toolCall.title) ?? readString5(toolCall.path);
@@ -23952,7 +25173,7 @@ function splitLines(value) {
23952
25173
  function readString5(value) {
23953
25174
  return typeof value === "string" ? value : void 0;
23954
25175
  }
23955
- function isRecord10(value) {
25176
+ function isRecord11(value) {
23956
25177
  return typeof value === "object" && value !== null && !Array.isArray(value);
23957
25178
  }
23958
25179
 
@@ -24302,7 +25523,7 @@ async function executeSuperintendent(options, context) {
24302
25523
  function buildRoleOptions(options, role) {
24303
25524
  return {
24304
25525
  defaultCwd: options.cwd,
24305
- ...options.logDir ? { logPath: path29.join(options.logDir, makeRunLogFileName(role)) } : {}
25526
+ ...options.logDir ? { logPath: path33.join(options.logDir, makeRunLogFileName(role)) } : {}
24306
25527
  };
24307
25528
  }
24308
25529
  function shouldContinueReview(doc) {
@@ -24549,7 +25770,7 @@ var S = {
24549
25770
 
24550
25771
  // packages/toolcraft/src/package-metadata.ts
24551
25772
  import { existsSync as existsSync3, readFileSync as readFileSync3, statSync } from "node:fs";
24552
- import path30 from "node:path";
25773
+ import path34 from "node:path";
24553
25774
  import { fileURLToPath as fileURLToPath2 } from "node:url";
24554
25775
 
24555
25776
  // packages/toolcraft/src/index.ts
@@ -24895,7 +26116,7 @@ function defineGroup(config) {
24895
26116
  }
24896
26117
 
24897
26118
  // packages/superintendent/src/commands/builder-group.ts
24898
- init_src11();
26119
+ init_src12();
24899
26120
  var builderRunParams = S.Object({
24900
26121
  path: S.String({ description: "Path to the superintendent markdown document" })
24901
26122
  });
@@ -24966,15 +26187,15 @@ function hasCode2(error2, code) {
24966
26187
  }
24967
26188
 
24968
26189
  // packages/superintendent/src/commands/install.ts
24969
- import path33 from "node:path";
24970
- import { readFile as readFile6, stat as stat4, mkdir as mkdir4, writeFile as writeFile2, unlink as unlink3, readdir as readdir3, chmod as chmod2 } from "node:fs/promises";
26190
+ import path37 from "node:path";
26191
+ import { readFile as readFile8, stat as stat4, mkdir as mkdir4, writeFile as writeFile3, unlink as unlink3, readdir as readdir4, chmod as chmod2 } from "node:fs/promises";
24971
26192
  import { fileURLToPath as fileURLToPath5 } from "node:url";
24972
26193
  init_src5();
24973
26194
 
24974
26195
  // packages/agent-skill-config/src/configs.ts
24975
26196
  init_src8();
24976
- import os5 from "node:os";
24977
- import path31 from "node:path";
26197
+ import os6 from "node:os";
26198
+ import path35 from "node:path";
24978
26199
  var agentSkillConfigs = {
24979
26200
  "claude-code": {
24980
26201
  globalSkillDir: "~/.claude/skills",
@@ -25010,8 +26231,8 @@ function resolveAgentSupport(input, registry = agentSkillConfigs) {
25010
26231
  init_src3();
25011
26232
 
25012
26233
  // packages/agent-skill-config/src/templates.ts
25013
- import { readFile as readFile5, stat as stat3 } from "node:fs/promises";
25014
- import path32 from "node:path";
26234
+ import { readFile as readFile7, stat as stat3 } from "node:fs/promises";
26235
+ import path36 from "node:path";
25015
26236
  import { fileURLToPath as fileURLToPath4 } from "node:url";
25016
26237
 
25017
26238
  // packages/agent-skill-config/src/apply.ts
@@ -25071,12 +26292,12 @@ async function installSkill(agentId, skill, options) {
25071
26292
  // packages/superintendent/src/commands/install.ts
25072
26293
  init_src9();
25073
26294
  var fs2 = {
25074
- readFile: (p, encoding) => readFile6(p, encoding),
25075
- writeFile: (p, content) => writeFile2(p, content),
26295
+ readFile: (p, encoding) => readFile8(p, encoding),
26296
+ writeFile: (p, content) => writeFile3(p, content),
25076
26297
  mkdir: (p, options) => mkdir4(p, options).then(() => void 0),
25077
26298
  unlink: (p) => unlink3(p),
25078
26299
  stat: (p) => stat4(p).then((s) => ({ mode: s.mode })),
25079
- readdir: (p) => readdir3(p),
26300
+ readdir: (p) => readdir4(p),
25080
26301
  chmod: (p, mode) => chmod2(p, mode)
25081
26302
  };
25082
26303
  var installParams = S.Object({
@@ -25166,9 +26387,9 @@ async function resolvePlanDirectory(cwd, homeDir, env) {
25166
26387
  }
25167
26388
  function resolveAbsoluteDirectory(dir, cwd, homeDir) {
25168
26389
  if (dir.startsWith("~/")) {
25169
- return path33.join(homeDir, dir.slice(2));
26390
+ return path37.join(homeDir, dir.slice(2));
25170
26391
  }
25171
- return path33.isAbsolute(dir) ? dir : path33.resolve(cwd, dir);
26392
+ return path37.isAbsolute(dir) ? dir : path37.resolve(cwd, dir);
25172
26393
  }
25173
26394
  async function pathExists2(targetPath) {
25174
26395
  try {
@@ -25188,15 +26409,15 @@ async function loadSkillTemplate() {
25188
26409
  }
25189
26410
  const packageRoot = await findPackageRoot(fileURLToPath5(import.meta.url));
25190
26411
  const templateRoots = [
25191
- path33.join(packageRoot, "src", "templates"),
25192
- path33.join(packageRoot, "dist", "templates")
26412
+ path37.join(packageRoot, "src", "templates"),
26413
+ path37.join(packageRoot, "dist", "templates")
25193
26414
  ];
25194
26415
  for (const templateRoot of templateRoots) {
25195
26416
  if (!await pathExists2(templateRoot)) {
25196
26417
  continue;
25197
26418
  }
25198
- skillTemplateCache = await readFile6(
25199
- path33.join(templateRoot, "SKILL_superintendent.md"),
26419
+ skillTemplateCache = await readFile8(
26420
+ path37.join(templateRoot, "SKILL_superintendent.md"),
25200
26421
  "utf8"
25201
26422
  );
25202
26423
  return skillTemplateCache;
@@ -25204,12 +26425,12 @@ async function loadSkillTemplate() {
25204
26425
  throw new Error("Unable to locate Superintendent skill template.");
25205
26426
  }
25206
26427
  async function findPackageRoot(entryFilePath) {
25207
- let currentPath = path33.dirname(entryFilePath);
26428
+ let currentPath = path37.dirname(entryFilePath);
25208
26429
  while (true) {
25209
- if (await pathExists2(path33.join(currentPath, "package.json"))) {
26430
+ if (await pathExists2(path37.join(currentPath, "package.json"))) {
25210
26431
  return currentPath;
25211
26432
  }
25212
- const parentPath = path33.dirname(currentPath);
26433
+ const parentPath = path37.dirname(currentPath);
25213
26434
  if (parentPath === currentPath) {
25214
26435
  throw new Error("Unable to locate package root for Superintendent templates.");
25215
26436
  }
@@ -25351,7 +26572,7 @@ function hasCode3(error2, code) {
25351
26572
  }
25352
26573
 
25353
26574
  // packages/superintendent/src/commands/superintendent-group.ts
25354
- init_src11();
26575
+ init_src12();
25355
26576
 
25356
26577
  // packages/superintendent/src/commands/complete.ts
25357
26578
  var completeParams = S.Object({
@@ -25407,16 +26628,16 @@ function hasCode4(error2, code) {
25407
26628
  }
25408
26629
 
25409
26630
  // packages/superintendent/src/commands/plan-path.ts
25410
- import path34 from "node:path";
25411
- import { readFile as readFile7, writeFile as writeFile3, mkdir as mkdir5, unlink as unlink4, stat as stat5, readdir as readdir4 } from "node:fs/promises";
26631
+ import path38 from "node:path";
26632
+ import { readFile as readFile9, writeFile as writeFile4, mkdir as mkdir5, unlink as unlink4, stat as stat5, readdir as readdir5 } from "node:fs/promises";
25412
26633
  init_src5();
25413
26634
  var fs3 = {
25414
- readFile: (p, encoding) => readFile7(p, encoding),
25415
- writeFile: (p, content) => writeFile3(p, content),
26635
+ readFile: (p, encoding) => readFile9(p, encoding),
26636
+ writeFile: (p, content) => writeFile4(p, content),
25416
26637
  mkdir: (p, options) => mkdir5(p, options).then(() => void 0),
25417
26638
  unlink: (p) => unlink4(p),
25418
26639
  stat: (p) => stat5(p).then((s) => ({ mode: s.mode })),
25419
- readdir: (p) => readdir4(p)
26640
+ readdir: (p) => readdir5(p)
25420
26641
  };
25421
26642
  var planPathCommand = defineCommand({
25422
26643
  name: "plan-path",
@@ -25443,22 +26664,22 @@ var planPathCommand = defineCommand({
25443
26664
  });
25444
26665
  function resolveAbsoluteDirectory2(dir, cwd, homeDir) {
25445
26666
  if (dir.startsWith("~/")) {
25446
- return path34.join(homeDir, dir.slice(2));
26667
+ return path38.join(homeDir, dir.slice(2));
25447
26668
  }
25448
- return path34.isAbsolute(dir) ? dir : path34.resolve(cwd, dir);
26669
+ return path38.isAbsolute(dir) ? dir : path38.resolve(cwd, dir);
25449
26670
  }
25450
26671
 
25451
26672
  // packages/superintendent/src/commands/run.ts
25452
26673
  init_src9();
25453
- init_src12();
26674
+ init_src13();
25454
26675
  init_src8();
25455
- import path35 from "node:path";
26676
+ import path39 from "node:path";
25456
26677
  import * as fsPromises7 from "node:fs/promises";
25457
26678
  import { spawn as nodeSpawn, spawnSync as nodeSpawnSync } from "node:child_process";
25458
26679
 
25459
26680
  // packages/superintendent/src/commands/poe-agent-runner.ts
25460
26681
  init_src8();
25461
- init_src13();
26682
+ init_src14();
25462
26683
  async function executePoeAgent(agentSpec, input, createAgent = agent) {
25463
26684
  const { model } = parseAgentSpecifier(agentSpec);
25464
26685
  if (!model) {
@@ -25475,7 +26696,7 @@ async function executePoeAgent(agentSpec, input, createAgent = agent) {
25475
26696
  }
25476
26697
 
25477
26698
  // packages/superintendent/src/commands/run.ts
25478
- init_src11();
26699
+ init_src12();
25479
26700
  init_src5();
25480
26701
 
25481
26702
  // packages/superintendent/src/config-scope.ts
@@ -25512,6 +26733,9 @@ var runParams = S.Object({
25512
26733
  mountPoeCode: S.Optional(S.Boolean({
25513
26734
  description: "Mount the local poe-code checkout into the runtime"
25514
26735
  })),
26736
+ runnerSync: S.Optional(S.Enum(["both", "upload", "none"], {
26737
+ description: "Override runner workspace sync: both, upload, or none"
26738
+ })),
25515
26739
  tui: S.Optional(S.Boolean({ description: "Show a live dashboard while Superintendent is running" }))
25516
26740
  });
25517
26741
  var runCommand2 = defineCommand({
@@ -25524,24 +26748,36 @@ var runCommand2 = defineCommand({
25524
26748
  const cwd = process.cwd();
25525
26749
  const homeDir = process.env.HOME ?? process.env.USERPROFILE ?? cwd;
25526
26750
  const commandConfig = await resolveSuperintendentCommandConfig(cwd, homeDir, process.env);
26751
+ const integrations = await loadIntegrations(commandConfig.configDoc);
25527
26752
  const tuiEnabled = params.tui ?? commandConfig.tui;
25528
- return runSuperintendentCommand({
25529
- cwd,
25530
- homeDir,
25531
- docPath: params.doc,
25532
- ...params.agent ? { builderAgent: params.agent } : {},
25533
- ...params.runtime ? { runtime: params.runtime } : {},
25534
- ...params.runtimeImage ? { runtimeImage: params.runtimeImage } : {},
25535
- ...params.runtimeTemplate ? { runtimeTemplate: params.runtimeTemplate } : {},
25536
- ...params.detach ? { detach: params.detach } : {},
25537
- ...params.mountPoeCode ? { mountPoeCode: params.mountPoeCode } : {},
25538
- configuredDefaultAgent: commandConfig.configuredDefaultAgent,
25539
- assumeYes: process.argv.includes("--yes"),
25540
- interactive: Boolean(process.stdin.isTTY),
25541
- useDashboard: shouldUseInteractiveDashboard(tuiEnabled) && resolveOutputFormat() === "terminal",
25542
- env: process.env,
25543
- ...commandConfig.planDirectory ? { planDirectory: commandConfig.planDirectory } : {}
25544
- });
26753
+ try {
26754
+ const runOptions = {
26755
+ cwd,
26756
+ homeDir,
26757
+ docPath: params.doc,
26758
+ ...params.agent ? { builderAgent: params.agent } : {},
26759
+ ...params.runtime ? { runtime: params.runtime } : {},
26760
+ ...params.runtimeImage ? { runtimeImage: params.runtimeImage } : {},
26761
+ ...params.runtimeTemplate ? { runtimeTemplate: params.runtimeTemplate } : {},
26762
+ ...params.detach ? { detach: params.detach } : {},
26763
+ ...params.mountPoeCode ? { mountPoeCode: params.mountPoeCode } : {},
26764
+ ...params.runnerSync ? { runnerSync: params.runnerSync } : {},
26765
+ configuredDefaultAgent: commandConfig.configuredDefaultAgent,
26766
+ assumeYes: process.argv.includes("--yes"),
26767
+ interactive: Boolean(process.stdin.isTTY),
26768
+ useDashboard: shouldUseInteractiveDashboard(tuiEnabled) && resolveOutputFormat() === "terminal",
26769
+ env: process.env,
26770
+ integrations,
26771
+ ...commandConfig.planDirectory ? { planDirectory: commandConfig.planDirectory } : {}
26772
+ };
26773
+ return integrations ? await integrations.traceRun(
26774
+ "superintendent",
26775
+ params.doc ?? "run",
26776
+ () => runSuperintendentCommand(runOptions)
26777
+ ) : await runSuperintendentCommand(runOptions);
26778
+ } finally {
26779
+ await integrations?.shutdown();
26780
+ }
25545
26781
  },
25546
26782
  render: {
25547
26783
  rich: (result, { logger: logger2 }) => {
@@ -25582,24 +26818,35 @@ function createRunMcpCommand(runners) {
25582
26818
  const cwd = process.cwd();
25583
26819
  const homeDir = process.env.HOME ?? process.env.USERPROFILE ?? cwd;
25584
26820
  const commandConfig = await resolveSuperintendentCommandConfig(cwd, homeDir, process.env);
25585
- return runSuperintendentCommand({
25586
- cwd,
25587
- homeDir,
25588
- docPath: params.doc,
25589
- ...params.agent ? { builderAgent: params.agent } : {},
25590
- ...params.runtime ? { runtime: params.runtime } : {},
25591
- ...params.runtimeImage ? { runtimeImage: params.runtimeImage } : {},
25592
- ...params.runtimeTemplate ? { runtimeTemplate: params.runtimeTemplate } : {},
25593
- ...params.detach ? { detach: params.detach } : {},
25594
- ...params.mountPoeCode ? { mountPoeCode: params.mountPoeCode } : {},
25595
- configuredDefaultAgent: commandConfig.configuredDefaultAgent,
25596
- assumeYes: true,
25597
- interactive: false,
25598
- useDashboard: false,
25599
- env: process.env,
25600
- ...commandConfig.planDirectory ? { planDirectory: commandConfig.planDirectory } : {},
25601
- ...runners?.runLoop ? { runLoop: runners.runLoop } : {}
25602
- });
26821
+ const integrations = await loadIntegrations(commandConfig.configDoc);
26822
+ try {
26823
+ const runOptions = {
26824
+ cwd,
26825
+ homeDir,
26826
+ docPath: params.doc,
26827
+ ...params.agent ? { builderAgent: params.agent } : {},
26828
+ ...params.runtime ? { runtime: params.runtime } : {},
26829
+ ...params.runtimeImage ? { runtimeImage: params.runtimeImage } : {},
26830
+ ...params.runtimeTemplate ? { runtimeTemplate: params.runtimeTemplate } : {},
26831
+ ...params.detach ? { detach: params.detach } : {},
26832
+ ...params.mountPoeCode ? { mountPoeCode: params.mountPoeCode } : {},
26833
+ configuredDefaultAgent: commandConfig.configuredDefaultAgent,
26834
+ assumeYes: true,
26835
+ interactive: false,
26836
+ useDashboard: false,
26837
+ env: process.env,
26838
+ integrations,
26839
+ ...commandConfig.planDirectory ? { planDirectory: commandConfig.planDirectory } : {},
26840
+ ...runners?.runLoop ? { runLoop: runners.runLoop } : {}
26841
+ };
26842
+ return integrations ? await integrations.traceRun(
26843
+ "superintendent",
26844
+ params.doc ?? "run",
26845
+ () => runSuperintendentCommand(runOptions)
26846
+ ) : await runSuperintendentCommand(runOptions);
26847
+ } finally {
26848
+ await integrations?.shutdown();
26849
+ }
25603
26850
  },
25604
26851
  render: runCommand2.render
25605
26852
  });
@@ -25622,12 +26869,13 @@ async function resolveSuperintendentCommandConfig(cwd, homeDir, env, fs4) {
25622
26869
  );
25623
26870
  const coreResolved = resolveScope(coreDefaultAgentConfigSchema, document.core, env);
25624
26871
  return {
26872
+ configDoc: document,
25625
26873
  configuredDefaultAgent: normalizeAgentSelection(coreResolved.defaultAgent) ?? null,
25626
26874
  ...planDirectory ? { planDirectory } : {},
25627
26875
  tui: superintendentResolved.tui === true
25628
26876
  };
25629
26877
  } catch {
25630
- return { configuredDefaultAgent: null, tui: false };
26878
+ return { configDoc: {}, configuredDefaultAgent: null, tui: false };
25631
26879
  }
25632
26880
  }
25633
26881
  async function resolveSuperintendentPlanDirectory(cwd, homeDir, env, fs4) {
@@ -25684,6 +26932,16 @@ async function runSuperintendentCommand(options) {
25684
26932
  const useDashboard = options.useDashboard ?? resolveOutputFormat() === "terminal";
25685
26933
  const stderr = options.stderr ?? process.stderr;
25686
26934
  const exitProcess = options.exit ?? ((code) => process.exit(code));
26935
+ const integrations = options.integrations ?? null;
26936
+ const shutdownAndExit = (code) => {
26937
+ if (!integrations) {
26938
+ exitProcess(code);
26939
+ return;
26940
+ }
26941
+ void integrations.shutdown().finally(() => {
26942
+ exitProcess(code);
26943
+ });
26944
+ };
25687
26945
  const selectedDocPath = await resolveDocPath({
25688
26946
  cwd: options.cwd,
25689
26947
  homeDir: options.homeDir,
@@ -25724,7 +26982,7 @@ async function runSuperintendentCommand(options) {
25724
26982
  const headlessAbort = new AbortController();
25725
26983
  const headlessSigint = () => {
25726
26984
  headlessAbort.abort();
25727
- exitProcess(130);
26985
+ shutdownAndExit(130);
25728
26986
  };
25729
26987
  process.on("SIGINT", headlessSigint);
25730
26988
  try {
@@ -25735,7 +26993,7 @@ async function runSuperintendentCommand(options) {
25735
26993
  ...options.fs ? { fs: fs4 } : {},
25736
26994
  signal: headlessAbort.signal,
25737
26995
  logDir: runLogDir,
25738
- callbacks: {
26996
+ callbacks: mergeLoopCallbacks({
25739
26997
  onBuilderStart: () => {
25740
26998
  activeStage = "builder";
25741
26999
  },
@@ -25766,17 +27024,19 @@ async function runSuperintendentCommand(options) {
25766
27024
  onOwnerComplete: () => {
25767
27025
  activeStage = void 0;
25768
27026
  }
25769
- },
27027
+ }, integrations?.superintendentCallbacks),
25770
27028
  runAgent: createAgentRunner({
25771
27029
  session: void 0,
25772
27030
  executeAgent: options.executeAgent,
25773
27031
  selectedBuilderAgent,
27032
+ integrations,
25774
27033
  runtime: {
25775
27034
  runtime: options.runtime,
25776
27035
  runtimeImage: options.runtimeImage,
25777
27036
  runtimeTemplate: options.runtimeTemplate,
25778
27037
  detach: options.detach,
25779
- mountPoeCode: options.mountPoeCode
27038
+ mountPoeCode: options.mountPoeCode,
27039
+ runnerSync: options.runnerSync
25780
27040
  },
25781
27041
  activeStage: () => activeStage,
25782
27042
  now,
@@ -25937,7 +27197,7 @@ async function runSuperintendentCommand(options) {
25937
27197
  abortController.abort();
25938
27198
  session.dashboard.stop();
25939
27199
  session.dashboard.destroy();
25940
- exitProcess(130);
27200
+ shutdownAndExit(130);
25941
27201
  };
25942
27202
  const handleDashboardCommand = (command) => {
25943
27203
  if (command === "forceQuit") {
@@ -25989,7 +27249,7 @@ async function runSuperintendentCommand(options) {
25989
27249
  session.pauseRequested = true;
25990
27250
  }
25991
27251
  editPlan(session.dashboard, session.latestLogFile, env, options.openInEditor);
25992
- appendEvent("info", `Log opened: ${path35.basename(session.latestLogFile)}`);
27252
+ appendEvent("info", `Log opened: ${path39.basename(session.latestLogFile)}`);
25993
27253
  syncStats();
25994
27254
  }
25995
27255
  };
@@ -26010,19 +27270,21 @@ async function runSuperintendentCommand(options) {
26010
27270
  cwd: options.cwd,
26011
27271
  homeDir: options.homeDir,
26012
27272
  ...options.fs ? { fs: fs4 } : {},
26013
- callbacks,
27273
+ callbacks: mergeLoopCallbacks(callbacks, integrations?.superintendentCallbacks),
26014
27274
  signal: abortController.signal,
26015
27275
  logDir: runLogDir,
26016
27276
  runAgent: createAgentRunner({
26017
27277
  session,
26018
27278
  executeAgent: options.executeAgent,
26019
27279
  selectedBuilderAgent,
27280
+ integrations,
26020
27281
  runtime: {
26021
27282
  runtime: options.runtime,
26022
27283
  runtimeImage: options.runtimeImage,
26023
27284
  runtimeTemplate: options.runtimeTemplate,
26024
27285
  detach: options.detach,
26025
- mountPoeCode: options.mountPoeCode
27286
+ mountPoeCode: options.mountPoeCode,
27287
+ runnerSync: options.runnerSync
26026
27288
  },
26027
27289
  activeStage: () => session.activeStage,
26028
27290
  now,
@@ -26145,13 +27407,13 @@ async function listPlanDirectoryDocs(fs4, planDirectory, cwd, homeDir) {
26145
27407
  }
26146
27408
  throw error2;
26147
27409
  }
26148
- return entries.filter((entry) => entry.toLowerCase().endsWith(".md")).map((entry) => path35.join(absoluteDir, entry)).sort((left, right) => left.localeCompare(right));
27410
+ return entries.filter((entry) => entry.toLowerCase().endsWith(".md")).map((entry) => path39.join(absoluteDir, entry)).sort((left, right) => left.localeCompare(right));
26149
27411
  }
26150
27412
  function resolveAbsolutePlanDirectory(dir, cwd, homeDir) {
26151
27413
  if (dir.startsWith("~/")) {
26152
- return path35.join(homeDir, dir.slice(2));
27414
+ return path39.join(homeDir, dir.slice(2));
26153
27415
  }
26154
- return path35.isAbsolute(dir) ? dir : path35.resolve(cwd, dir);
27416
+ return path39.isAbsolute(dir) ? dir : path39.resolve(cwd, dir);
26155
27417
  }
26156
27418
  function normalizeAgentSelection(value) {
26157
27419
  if (typeof value !== "string") {
@@ -26171,7 +27433,7 @@ function createAgentRunner(options) {
26171
27433
  return async (input) => {
26172
27434
  const activeStage = options.activeStage();
26173
27435
  const agent2 = activeStage === "builder" ? options.selectedBuilderAgent : input.agent;
26174
- const executeAgent = options.executeAgent ?? executeSpawnAgent;
27436
+ const executeAgent = options.executeAgent ?? ((nextAgent, nextInput) => executeSpawnAgent(nextAgent, nextInput, options.integrations));
26175
27437
  const stageLabel = formatStageLabel(activeStage);
26176
27438
  const emitLine = (kind, line) => {
26177
27439
  if (line.length === 0) {
@@ -26242,12 +27504,12 @@ function formatStageLabel(stage) {
26242
27504
  }
26243
27505
  return `inspector:${stage.inspector}`;
26244
27506
  }
26245
- async function executeSpawnAgent(agent2, input) {
27507
+ async function executeSpawnAgent(agent2, input, integrations) {
26246
27508
  if (parseAgentSpecifier(agent2).agent === "poe-agent") {
26247
27509
  return executePoeAgent(agent2, input);
26248
27510
  }
26249
27511
  if ((input.onStdout || input.onStderr) && supportsStreaming(agent2)) {
26250
- return executeSpawnAgentStreaming(agent2, input);
27512
+ return executeSpawnAgentStreaming(agent2, input, integrations);
26251
27513
  }
26252
27514
  const tee = input.onStdout || input.onStderr ? {
26253
27515
  ...input.onStdout ? { stdout: { write: input.onStdout } } : {},
@@ -26266,6 +27528,7 @@ async function executeSpawnAgent(agent2, input) {
26266
27528
  ...input.runtimeTemplate ? { runtimeTemplate: input.runtimeTemplate } : {},
26267
27529
  ...input.detach ? { detach: input.detach } : {},
26268
27530
  ...input.mountPoeCode ? { mountPoeCode: input.mountPoeCode } : {},
27531
+ ...input.runnerSync ? { runnerSync: input.runnerSync } : {},
26269
27532
  ...tee ? { tee } : {}
26270
27533
  });
26271
27534
  return {
@@ -26280,7 +27543,7 @@ function supportsStreaming(agent2) {
26280
27543
  const config = getSpawnConfig(agent2);
26281
27544
  return config?.kind === "cli";
26282
27545
  }
26283
- async function executeSpawnAgentStreaming(agent2, input) {
27546
+ async function executeSpawnAgentStreaming(agent2, input, integrations) {
26284
27547
  const writer = (line) => {
26285
27548
  input.onStdout?.(`${line}
26286
27549
  `);
@@ -26298,6 +27561,7 @@ async function executeSpawnAgentStreaming(agent2, input) {
26298
27561
  ...input.runtimeTemplate ? { runtimeTemplate: input.runtimeTemplate } : {},
26299
27562
  ...input.detach ? { detach: input.detach } : {},
26300
27563
  ...input.mountPoeCode ? { mountPoeCode: input.mountPoeCode } : {},
27564
+ ...input.runnerSync ? { runnerSync: input.runnerSync } : {},
26301
27565
  ...input.onStderr ? { tee: { stderr: { write: input.onStderr } } } : {}
26302
27566
  });
26303
27567
  const middlewareContext = {
@@ -26312,7 +27576,15 @@ async function executeSpawnAgentStreaming(agent2, input) {
26312
27576
  ...input.logPath ? { logPath: input.logPath } : {},
26313
27577
  ...input.mode ? { mode: input.mode } : {}
26314
27578
  };
26315
- await applyMiddlewares([spawnLog, usageCapture, sessionCapture], middlewareContext);
27579
+ await applyMiddlewares(
27580
+ [
27581
+ spawnLog,
27582
+ usageCapture,
27583
+ sessionCapture,
27584
+ ...integrations?.spawnMiddleware ? [integrations.spawnMiddleware] : []
27585
+ ],
27586
+ middlewareContext
27587
+ );
26316
27588
  await acp_exports.withAcpWriter(writer, () => renderAcpStream(middlewareContext.eventStream ?? rawEvents));
26317
27589
  const final = await done;
26318
27590
  const logFile = middlewareContext.logFile ?? final.logFile;
@@ -26403,7 +27675,7 @@ function resolveEditor(env) {
26403
27675
  const parts = raw.split(/\s+/);
26404
27676
  const command = parts[0] ?? "vi";
26405
27677
  const args = parts.slice(1);
26406
- const binary = path35.basename(command);
27678
+ const binary = path39.basename(command);
26407
27679
  const mode = GUI_EDITOR_BINARIES.has(binary) ? "gui" : "tty";
26408
27680
  return { command, args, mode };
26409
27681
  }
@@ -26430,11 +27702,11 @@ function stripStopReason(result) {
26430
27702
  };
26431
27703
  }
26432
27704
  function displayPath(filePath, cwd, homeDir) {
26433
- if (filePath.startsWith(`${cwd}${path35.sep}`)) {
26434
- return path35.relative(cwd, filePath);
27705
+ if (filePath.startsWith(`${cwd}${path39.sep}`)) {
27706
+ return path39.relative(cwd, filePath);
26435
27707
  }
26436
- if (filePath.startsWith(`${homeDir}${path35.sep}`)) {
26437
- return `~/${path35.relative(homeDir, filePath)}`;
27708
+ if (filePath.startsWith(`${homeDir}${path39.sep}`)) {
27709
+ return `~/${path39.relative(homeDir, filePath)}`;
26438
27710
  }
26439
27711
  return filePath;
26440
27712
  }
@@ -27057,7 +28329,7 @@ function emitEvent(callback, event) {
27057
28329
  }
27058
28330
  async function loadConfiguredPlugins(options) {
27059
28331
  const fs4 = createConfigFileSystem(options.fs);
27060
- const homeDir = options.homeDir ?? os6.homedir();
28332
+ const homeDir = options.homeDir ?? os7.homedir();
27061
28333
  const store = createConfigStore({
27062
28334
  fs: fs4,
27063
28335
  filePath: options.configPath ?? resolveConfigPath(homeDir),
@@ -27128,7 +28400,7 @@ function createInMemoryAcpTransport2(options) {
27128
28400
  }
27129
28401
  if (method === "session/new") {
27130
28402
  const request = params;
27131
- const { createAgentSession: createAgentSession2 } = await Promise.resolve().then(() => (init_src13(), src_exports));
28403
+ const { createAgentSession: createAgentSession2 } = await Promise.resolve().then(() => (init_src14(), src_exports));
27132
28404
  const session = await createAgentSession2({
27133
28405
  model: options.model,
27134
28406
  cwd: request.cwd || options.cwd,