pi-better-server 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/package.json +4 -3
  2. package/scripts/measure-full-runtime/frontend.ts +10 -2
  3. package/scripts/measure-full-runtime.mjs +2 -0
  4. package/src/runtime/background-tools.ts +54 -8
  5. package/src/runtime/background.ts +16 -4
  6. package/src/runtime/domain/background/process.mjs +49 -11
  7. package/src/runtime/domain/background/supervisor/store.mjs +3 -3
  8. package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -3
  9. package/src/runtime/domain/background-service/index.domain.mjs +19 -0
  10. package/src/runtime/domain/background-service/index.ts +19 -0
  11. package/src/runtime/domain/background-service/managed-frontend.domain.mjs +87 -5
  12. package/src/runtime/domain/background-service/managed-frontend.ts +76 -5
  13. package/src/runtime/domain/background-service/navigator-provider.domain.mjs +5 -0
  14. package/src/runtime/domain/background-service/navigator-provider.ts +4 -0
  15. package/src/runtime/domain/background-service/observed-waits.domain.mjs +203 -31
  16. package/src/runtime/domain/background-service/observed-waits.ts +168 -24
  17. package/src/runtime/domain/background-service/process.domain.mjs +49 -11
  18. package/src/runtime/domain/background-service/process.ts +45 -11
  19. package/src/runtime/domain/background-service/review-settings.domain.mjs +16 -0
  20. package/src/runtime/domain/background-service/review-settings.ts +18 -0
  21. package/src/runtime/domain/background-service/runtime.domain.mjs +8 -70
  22. package/src/runtime/domain/background-service/runtime.ts +8 -73
  23. package/src/runtime/domain/background-service/shared-navigator.domain.mjs +55 -28
  24. package/src/runtime/domain/background-service/shared-navigator.ts +47 -26
  25. package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
  26. package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
  27. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +5 -1
  28. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +6 -0
  29. package/src/runtime/domain/background-service/stall.domain.mjs +5 -3
  30. package/src/runtime/domain/background-service/stall.ts +7 -4
  31. package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
  32. package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
  33. package/src/runtime/domain/background-service/supervisor/README.md +1 -4
  34. package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
  35. package/src/runtime/domain/background-service/supervisor/generated/process.mjs +49 -11
  36. package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
  37. package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
  38. package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
  39. package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
  40. package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
  41. package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
  42. package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
  43. package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
  44. package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -3
  45. package/src/runtime/domain/background-service/tools.domain.mjs +22 -16
  46. package/src/runtime/domain/background-service/tools.ts +26 -16
  47. package/src/runtime/domain/background-service/types.ts +4 -2
  48. package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
  49. package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
  50. package/src/runtime/domain/coordinator/src/outbox.mjs +7 -0
  51. package/src/runtime/domain/coordinator/src/store.mjs +5 -1
  52. package/src/runtime/domain/log-paths.mjs +8 -1
  53. package/src/runtime/domain/parse.mjs +9 -5
  54. package/src/runtime/domain/sandbox-policy/README.md +3 -3
  55. package/src/runtime/domain/sandbox-policy/package.json +1 -1
  56. package/src/runtime/domain/session-store.mjs +7 -0
  57. package/src/runtime/domain/subagents/README.md +12 -10
  58. package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +2 -5
  59. package/src/runtime/domain/subagents/assignment-outcomes.ts +2 -5
  60. package/src/runtime/domain/subagents/assignment-report.domain.mjs +22 -0
  61. package/src/runtime/domain/subagents/assignment-report.ts +20 -0
  62. package/src/runtime/domain/subagents/batch.mjs +13 -5
  63. package/src/runtime/domain/subagents/cleanup.domain.mjs +11 -2
  64. package/src/runtime/domain/subagents/cleanup.ts +10 -2
  65. package/src/runtime/domain/subagents/config.domain.mjs +5 -0
  66. package/src/runtime/domain/subagents/config.ts +7 -1
  67. package/src/runtime/domain/subagents/continuation.domain.mjs +4 -2
  68. package/src/runtime/domain/subagents/continuation.ts +4 -2
  69. package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
  70. package/src/runtime/domain/subagents/failures.ts +10 -2
  71. package/src/runtime/domain/subagents/finalization.domain.mjs +5 -2
  72. package/src/runtime/domain/subagents/finalization.ts +7 -2
  73. package/src/runtime/domain/subagents/index.domain.mjs +163 -61
  74. package/src/runtime/domain/subagents/index.ts +163 -60
  75. package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +515 -0
  76. package/src/runtime/domain/subagents/isolated-workspace.ts +557 -0
  77. package/src/runtime/domain/subagents/list.mjs +2 -2
  78. package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +22 -5
  79. package/src/runtime/domain/subagents/managed-launch-client.ts +23 -6
  80. package/src/runtime/domain/subagents/output-payload.domain.mjs +24 -9
  81. package/src/runtime/domain/subagents/output-payload.ts +26 -12
  82. package/src/runtime/domain/subagents/package.json +4 -2
  83. package/src/runtime/domain/subagents/parse.domain.mjs +9 -5
  84. package/src/runtime/domain/subagents/parse.ts +10 -5
  85. package/src/runtime/domain/subagents/registry.domain.mjs +24 -18
  86. package/src/runtime/domain/subagents/registry.ts +23 -5
  87. package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
  88. package/src/runtime/domain/subagents/retained-result.ts +65 -0
  89. package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
  90. package/src/runtime/domain/subagents/session-selection.ts +2 -1
  91. package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
  92. package/src/runtime/domain/subagents/session-store.ts +9 -0
  93. package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
  94. package/src/runtime/domain/subagents/settings-page.ts +147 -108
  95. package/src/runtime/domain/subagents/shared-catalog.domain.mjs +23 -7
  96. package/src/runtime/domain/subagents/shared-catalog.ts +23 -7
  97. package/src/runtime/domain/subagents/shared-navigator.domain.mjs +55 -28
  98. package/src/runtime/domain/subagents/shared-navigator.ts +47 -26
  99. package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
  100. package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
  101. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +5 -1
  102. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +6 -0
  103. package/src/runtime/domain/subagents/task-guard.domain.mjs +14 -1
  104. package/src/runtime/domain/subagents/task-guard.ts +13 -1
  105. package/src/runtime/domain/subagents/task-policy.domain.mjs +2 -1
  106. package/src/runtime/domain/subagents/task-policy.ts +5 -1
  107. package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
  108. package/src/runtime/domain/subagents/tools.ts +4 -7
  109. package/src/runtime/domain/subagents/work-observation.domain.mjs +25 -1
  110. package/src/runtime/domain/subagents/work-observation.ts +20 -1
  111. package/src/runtime/domain/subagents/workspace-files.domain.mjs +103 -0
  112. package/src/runtime/domain/subagents/workspace-files.ts +114 -0
  113. package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
  114. package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
  115. package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
  116. package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
  117. package/src/runtime/domain/subagents/worktree-feedback.ts +77 -0
  118. package/src/runtime/read-model.ts +4 -2
  119. package/src/runtime/root.ts +5 -2
  120. package/src/version.ts +1 -1
@@ -48,14 +48,15 @@ import { readAppendedLines } from "./log-cursor.domain.mjs";
48
48
  import { DELEGATION_MODES, DELEGATION_MODE_REQUEST, isDelegationMode, normalizeDelegationMode } from "./delegation.domain.mjs";
49
49
  import { resolveExtensions, extensionArgs } from "./extensions.domain.mjs";
50
50
  import { prepareTaskRuntime, applyDirectApplicationLoadout, DEFAULT_TASK_PERMISSIONS, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.domain.mjs";
51
- import { canonicalizePath, takeRecoverySnapshot } from "./shared-sandbox-core.domain.mjs";
51
+ import { worktreePolicyNotice } from "./worktree-feedback.domain.mjs";
52
+ import { canonicalizePath, compileWritePolicy, takeRecoverySnapshot } from "./shared-sandbox-core.domain.mjs";
52
53
  import { TASK_BUILTINS } from "./shared-task-sandbox.domain.mjs";
53
54
  import { describeTaskTools, planTaskTools, selectEffectiveTaskTools } from "./subagent-tools.domain.mjs";
54
55
  import { announceExecutionAdapter, describeSubagentProcessPolicy, effectiveWorkerProcessAccess, observeSandboxPermissions, resolveCommandSettings, resolveSubagentPermissions, } from "./permission-policy.domain.mjs";
55
56
  import { dirname, isAbsolute, join } from "node:path";
56
57
  import { baseDir, taskWorkspaceDir, sessionsDir, runDir, recordTaskRuntimeProvenance, recordLaunchAttempt, clearLaunchAttempt, logPathFor, promptPathFor, nextRunId, writeMeta, readMeta, listMetas, listActiveMetasForParent, listMetasForOrigin, listMetasForParent, onMetaChanged, effectiveStatus, ownedByThisParent as ownedByFrontend, navigatorVisibleRuns, dismissRun, } from "./registry.domain.mjs";
57
58
  import { captureProcessIdentity, extractChildEventFactsFromLog, loadHealthThresholdsFromConfig, isAbandonedByParent, needsMonitoring, observeRunHealth, realProcessProbe, reconcileRun, resetChildEventLogCursor, } from "./health.domain.mjs";
58
- import { assignBatchJobNames, batchLaunchOutputSchema, batchLaunchResult, mergeJobOptions, nextBatchId, planBatchLaunches, validateBatchPlan, } from "./batch.mjs";
59
+ import { assignBatchJobNames, batchLaunchOutputSchema, batchLaunchResult, mergeJobOptions, nextBatchId, normalizeSessionSelector, planBatchLaunches, validateBatchPlan, } from "./batch.mjs";
59
60
  import { formatCapacityRejectMessage, getSharedCapacityGate, } from "./capacity.mjs";
60
61
  import { buildHealthCallbackDelivery } from "./completion.domain.mjs";
61
62
  import { cancelCallbackBatch, getCallbackBatcher, packCallbackBatch, setCallbackBatchContext } from "./shared-callback-batcher.domain.mjs";
@@ -838,6 +839,7 @@ let healthTicker;
838
839
  let managedHealthClose;
839
840
  /** ExtensionAPI retained so health transitions can deliver coordinator follow-ups (#65). */
840
841
  let healthPi;
842
+ let recoverWorkerWaitsAfterExit;
841
843
  /**
842
844
  * Deliver a durable, deduped coordinator follow-up for orphaned/lost (#65).
843
845
  *
@@ -1305,6 +1307,7 @@ function reconcileHealth(ids) {
1305
1307
  sendMessage: () => enqueueCompletionCallback(pi, meta.id),
1306
1308
  });
1307
1309
  if (observed.finalization?.applied) {
1310
+ void recoverWorkerWaitsAfterExit?.().catch(() => undefined);
1308
1311
  syncHealthTicker();
1309
1312
  continue;
1310
1313
  }
@@ -2035,13 +2038,14 @@ function resolvePiBinary() {
2035
2038
  * first-party finalizer (finalization.ts) so tests can exercise the durable
2036
2039
  * path without importing the pi package.
2037
2040
  */
2038
- function finalizeRun(pi, ctx, id, code) {
2041
+ function finalizeRun(pi, ctx, id, code, recoveredWriterExit = false) {
2039
2042
  progressCache.delete(id);
2040
2043
  directlySupervisedRunIds.delete(id);
2041
2044
  // Host-facing wrapper around first-party finalizer (finalization.ts).
2042
2045
  // Coherent child-exit evidence may supersede provisional orphaned/lost
2043
2046
  // reconciliation; finalization.ts enforces canExitFinalize + lifecycle authority.
2044
- finalizeRunCore(id, code, {
2047
+ const result = finalizeRunCore(id, code, {
2048
+ recoveredWriterExit,
2045
2049
  renderWidget,
2046
2050
  notify: (message, level) => {
2047
2051
  try {
@@ -2051,6 +2055,11 @@ function finalizeRun(pi, ctx, id, code) {
2051
2055
  },
2052
2056
  sendMessage: () => enqueueCompletionCallback(pi, id),
2053
2057
  });
2058
+ if (recoveredWriterExit && result.applied) {
2059
+ // The old exit callback is gone. Finish its durable wait handoff after
2060
+ // recovery, including the independent writer and lease proof checks.
2061
+ void recoverWorkerWaitsAfterExit?.().catch(() => undefined);
2062
+ }
2054
2063
  syncHealthTicker();
2055
2064
  }
2056
2065
  /**
@@ -2087,7 +2096,7 @@ function finalizeInterruptedRunFromLog(pi, meta, now) {
2087
2096
  return false;
2088
2097
  // Exit code is unknown after the observer is gone; the lifecycle authority
2089
2098
  // classifies from the coherent stream instead of inventing one.
2090
- finalizeRun(pi, uiCtx, meta.id, null);
2099
+ finalizeRun(pi, uiCtx, meta.id, null, true);
2091
2100
  return true;
2092
2101
  }
2093
2102
  /**
@@ -2304,15 +2313,17 @@ function latestConversationAttempt(sessionId, metas) {
2304
2313
  * missing session is the only error added here. Nothing is ever recreated.
2305
2314
  */
2306
2315
  function requestedSessionId(job, cwd) {
2307
- if (job.session_id !== undefined && job.session_name !== undefined) {
2316
+ const sessionId = normalizeSessionSelector(job.session_id);
2317
+ const sessionName = normalizeSessionSelector(job.session_name);
2318
+ if (sessionId !== undefined && sessionName !== undefined) {
2308
2319
  throw new Error("Pass either session_id or session_name, not both.");
2309
2320
  }
2310
- if (job.session_name !== undefined) {
2311
- if (typeof job.session_name !== "string")
2321
+ if (sessionName !== undefined) {
2322
+ if (typeof sessionName !== "string")
2312
2323
  throw new Error("session_name must be a non-empty name.");
2313
- return selectSessionByName(listMetas(), job.session_name, (workspace) => isWithinWorkspace(workspace, cwd));
2324
+ return selectSessionByName(listMetas(), sessionName, (workspace) => isWithinWorkspace(workspace, cwd));
2314
2325
  }
2315
- return job.session_id;
2326
+ return sessionId;
2316
2327
  }
2317
2328
  function continuationPlanFor(sessionId, origin) {
2318
2329
  const others = listMetas();
@@ -2379,6 +2390,12 @@ export default function (pi, managed) {
2379
2390
  let catalogModelRegistry;
2380
2391
  let delegationOverride;
2381
2392
  let capOverride;
2393
+ let workspaceOverride;
2394
+ const activeWorkspace = () => workspaceOverride ?? (loadConfig().gitWorkspace === "worktree" ? "worktree" : "clone");
2395
+ const changeWorkspace = (mode) => {
2396
+ workspaceOverride = mode;
2397
+ pi.appendEntry("pi-better-subagents-workspace", { version: 1, mode });
2398
+ };
2382
2399
  let timingOverride = {};
2383
2400
  let skillsOverride;
2384
2401
  const savedSkills = () => {
@@ -2498,7 +2515,9 @@ export default function (pi, managed) {
2498
2515
  capOverride = undefined;
2499
2516
  delegationOverride = undefined;
2500
2517
  timingOverride = {};
2518
+ workspaceOverride = undefined;
2501
2519
  skillsOverride = undefined;
2520
+ pi.appendEntry("pi-better-subagents-workspace", { version: 1, mode: null });
2502
2521
  pi.appendEntry("pi-better-subagents-cap", { version: 1, maxConcurrent: null });
2503
2522
  pi.appendEntry("pi-better-subagents-delegation", { version: 1, mode: null });
2504
2523
  pi.appendEntry("pi-better-subagents-timing", { version: 1, maxMinutes: null, toolWaitMinutes: null, stuckMinutes: null });
@@ -2602,6 +2621,7 @@ export default function (pi, managed) {
2602
2621
  savedTiming.stuckMinutes = cfg.stuckMinutes;
2603
2622
  }
2604
2623
  writeSubagentSettings({
2624
+ ...(workspaceOverride ? { gitWorkspace: workspaceOverride } : {}),
2605
2625
  delegationMode: activeDelegationMode(),
2606
2626
  maxConcurrent: activeConcurrencyCap(),
2607
2627
  ...savedTiming,
@@ -2645,6 +2665,7 @@ export default function (pi, managed) {
2645
2665
  delegationOverride = undefined;
2646
2666
  capOverride = undefined;
2647
2667
  timingOverride = {};
2668
+ workspaceOverride = undefined;
2648
2669
  skillsOverride = undefined;
2649
2670
  const branch = ctx.sessionManager?.getBranch?.();
2650
2671
  if (!Array.isArray(branch))
@@ -2687,6 +2708,12 @@ export default function (pi, managed) {
2687
2708
  }
2688
2709
  continue;
2689
2710
  }
2711
+ if (entry.type === "custom" && entry.customType === "pi-better-subagents-workspace") {
2712
+ const data = entry.data;
2713
+ if (data?.version === 1 && (data.mode === "worktree" || data.mode === "clone" || data.mode === null)) {
2714
+ workspaceOverride = data.mode ?? undefined;
2715
+ }
2716
+ }
2690
2717
  if (entry.type === "custom" && entry.customType === "pi-better-subagents-timing") {
2691
2718
  const data = entry.data;
2692
2719
  if (data?.version !== 1)
@@ -2719,6 +2746,7 @@ export default function (pi, managed) {
2719
2746
  // Capture for the health ticker (module-level); needed for orphaned/lost
2720
2747
  // coordinator follow-ups that fire outside a tool-call stack (#65).
2721
2748
  healthPi = pi;
2749
+ recoverWorkerWaitsAfterExit = reconcileWorkerWaits;
2722
2750
  ensureSubagentProvider();
2723
2751
  registerSubagentsGoalProvider(pi);
2724
2752
  observeSandboxPermissions(pi);
@@ -2732,12 +2760,12 @@ export default function (pi, managed) {
2732
2760
  restoreDelegationMode(ctx);
2733
2761
  await workerOperations.start();
2734
2762
  return definition.execute(key, params, signal, onUpdate, ctx);
2735
- } } : { ...definition, async execute(key, params, _signal, _onUpdate, ctx) {
2763
+ } } : { ...definition, async execute(key, params, signal, _onUpdate, ctx) {
2736
2764
  ctx = captureLaunchContext(ctx);
2737
2765
  catalogHostFrom(ctx);
2738
2766
  const { submitManagedLaunch } = await import("./managed-launch-client.domain.mjs");
2739
2767
  void activateWorkObservation();
2740
- return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, params));
2768
+ return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, params, signal));
2741
2769
  } });
2742
2770
  };
2743
2771
  announceExecutionAdapter(pi, {
@@ -2834,7 +2862,8 @@ export default function (pi, managed) {
2834
2862
  */
2835
2863
  internal) {
2836
2864
  const { resolveChildClosure, resolveChildLaunch, configSnapshot } = await import("./child-dependencies.mjs");
2837
- const { resolveSubagentWorkspace } = await import("./git-workspace.domain.mjs");
2865
+ const { resolveSubagentWorkspace, inspectGitWorkspace } = await import("./git-workspace.domain.mjs");
2866
+ const { workspaceChoice, createIsolatedWorkspace, restoreWorkspace, discardWorkspace, markWorkspaceWriter } = await import("./isolated-workspace.domain.mjs");
2838
2867
  const { PREFLIGHT_ENV } = await import("./child-preflight.mjs");
2839
2868
  assertThinkingLevel(p.thinking);
2840
2869
  // Skill exposure is a caller choice, not a launch: validate its shape
@@ -2928,7 +2957,36 @@ export default function (pi, managed) {
2928
2957
  // The disposable clone this launch owns (removed if the spawn fails); a caller's sandbox_dir is not ours.
2929
2958
  // A continuation never prepares another clone: the recipe's workspace already
2930
2959
  // holds the prior attempt's uncommitted work.
2931
- const ownedCloneWorkspace = !resume && !p.sandbox_dir && sandboxEnabled && p.git_clone_workspace ? taskWorkspaceDir(id) : undefined;
2960
+ if (p.isolation === false && p.git_clone_workspace)
2961
+ throw new Error("Choose either live checkout or git_clone_workspace.");
2962
+ if (p.recover_in_clone && (!resume || resume.recipe.workspace?.mode !== "worktree" || internal?.resumeWait)) {
2963
+ throw new Error("Clone handoff requires an explicit continuation of a linked worktree.");
2964
+ }
2965
+ if (resume && p.isolation !== undefined && Boolean(resume.recipe.workspace || resume.recipe.gitCloneWorkspace) !== p.isolation) {
2966
+ throw new ContinuationError("Changing isolation would replace the saved workspace.");
2967
+ }
2968
+ const handoffAuthority = p.recover_in_clone ? resume?.recipe.workspaceAuthority : undefined;
2969
+ if (p.recover_in_clone && resume) {
2970
+ const previous = handoffAuthority?.sandbox;
2971
+ const permissions = taskPermissions ?? DEFAULT_TASK_PERMISSIONS;
2972
+ assertAssignmentPermissionScope(handoffAuthority, {
2973
+ mandatoryPermissions: permissionPlan.enforced,
2974
+ sandbox: sandboxEnabled ? {
2975
+ root: resume.recipe.sandboxDir,
2976
+ denyWrite: previous?.denyWrite ?? [],
2977
+ permissions: {
2978
+ ...DEFAULT_TASK_PERMISSIONS, ...permissions, ...resolveCommandSettings(permissions),
2979
+ processAccess: permissions.processAccess ?? "off",
2980
+ },
2981
+ } : null,
2982
+ });
2983
+ }
2984
+ const selected = normalizeTools(p.tools ?? cfg.defaultTools ?? (p.clean ? SAFE_CLEAN_TOOLS : SAFE_DEFAULT_TOOLS));
2985
+ let isolated = resume?.recipe.workspace;
2986
+ if (!resume && !p.sandbox_dir && p.isolation !== false) {
2987
+ isolated = workspaceChoice(p.cwd ?? ctx.cwd, id, p.git_clone_workspace ? "clone" : activeWorkspace(), p.git_clone_workspace ? "write" : selected, p.git_clone_workspace ? "" : p.exclude_tools ?? "");
2988
+ }
2989
+ const ownedCloneWorkspace = !resume && !p.sandbox_dir && (isolated || p.git_clone_workspace) ? taskWorkspaceDir(id) : undefined;
2932
2990
  // A launch attempt only becomes a run when `writeMeta` commits. Until
2933
2991
  // then everything it creates (prompt, control/, provenance, its own
2934
2992
  // session dir, clone workspace, task scratch) belongs to the attempt and
@@ -2938,6 +2996,7 @@ export default function (pi, managed) {
2938
2996
  let spawned;
2939
2997
  let launchScratch;
2940
2998
  let committed = false;
2999
+ let createdWorkspace = false;
2941
3000
  try {
2942
3001
  if (!resume)
2943
3002
  mkdirSync(childSessionDir, { recursive: true });
@@ -2947,17 +3006,33 @@ export default function (pi, managed) {
2947
3006
  // concurrent purge can tell this live attempt from dead launch debris
2948
3007
  // (#623 R1). The outer catch drops the whole directory on failure.
2949
3008
  recordLaunchAttempt(id);
3009
+ // Cleanup, restoration and the actual writer share the conversation lease.
3010
+ if (resume || managed)
3011
+ lease = acquireConversationLease({ sessionId, attemptId: id });
3012
+ if (resume) {
3013
+ revalidateContinuationUnderLease(resume, callbackOrigin);
3014
+ if (isolated)
3015
+ isolated = restoreWorkspace(isolated, p.recover_in_clone, resume.prior.id);
3016
+ }
3017
+ if (!resume && isolated) {
3018
+ const root = taskWorkspaceDir(id);
3019
+ mkdirSync(dirname(root), { recursive: true });
3020
+ mkdirSync(root, { mode: 0o700 });
3021
+ createdWorkspace = true;
3022
+ }
3023
+ const isolatedCwd = isolated && !resume && !p.git_clone_workspace ? createIsolatedWorkspace(isolated, true) : undefined;
2950
3024
  const workspace = resume
2951
3025
  ? { cwd: resume.recipe.cwd, requestedSandboxDir: resume.recipe.sandboxDir }
2952
- : resolveSubagentWorkspace({
2953
- ctxCwd: ctx.cwd,
2954
- cwd: p.cwd,
2955
- sandboxDir: p.sandbox_dir ?? ownedCloneWorkspace,
2956
- gitCloneWorkspace: p.git_clone_workspace,
2957
- runId: id,
2958
- runDirPath: runDir(id),
2959
- sandboxEnabled,
2960
- });
3026
+ : isolatedCwd ? { cwd: isolatedCwd, requestedSandboxDir: sandboxEnabled ? isolatedCwd : undefined }
3027
+ : resolveSubagentWorkspace({
3028
+ ctxCwd: ctx.cwd, cwd: p.cwd, sandboxDir: p.sandbox_dir ?? ownedCloneWorkspace,
3029
+ gitCloneWorkspace: p.git_clone_workspace, runId: id, runDirPath: runDir(id), sandboxEnabled,
3030
+ });
3031
+ // Legacy explicit clones launch at the repository root, even when the source is a subdirectory.
3032
+ if (!resume && isolated && p.git_clone_workspace)
3033
+ isolated = { ...isolated, subdir: "" };
3034
+ let workspaceNote = isolated ? `Git workspace: ${isolated.mode} at ${workspace.cwd}. Base ${isolated.base}.`
3035
+ + (isolated.mode === "worktree" && sandboxEnabled ? " Git metadata is shared outside this checkout. If the sandbox denies a Git operation, report the operation and current changes. The parent can review them here or continue this session with recover_in_clone:true." : "") : "";
2961
3036
  const cwd = workspace.cwd;
2962
3037
  const requestedSandboxDir = workspace.requestedSandboxDir;
2963
3038
  // Skill exposure is decided once per attempt. A continuation replays the
@@ -2983,7 +3058,8 @@ export default function (pi, managed) {
2983
3058
  });
2984
3059
  if (requestedSandboxDir)
2985
3060
  mkdirSync(requestedSandboxDir, { recursive: true });
2986
- writeFileSync(promptPathFor(id), p.prompt);
3061
+ const workerPrompt = workspaceNote ? workspaceNote + "\n\n" + p.prompt : p.prompt;
3062
+ writeFileSync(promptPathFor(id), workerPrompt);
2987
3063
  // A continuation keeps the recipe's launch intent; only current
2988
3064
  // permission-driven adjustments are re-derived from it.
2989
3065
  const requestedTools = resume ? callerLaunchTools(resume.recipe.tools) : p.tools;
@@ -2991,7 +3067,7 @@ export default function (pi, managed) {
2991
3067
  const clean = resume ? resume.recipe.clean : p.clean === true;
2992
3068
  const allowNested = resume ? resume.recipe.allowNested : p.allow_nested === true;
2993
3069
  const approve = resume ? resume.recipe.approve : p.approve === true;
2994
- const gitCloneWorkspace = resume ? resume.recipe.gitCloneWorkspace : p.git_clone_workspace === true;
3070
+ const gitCloneWorkspace = isolated ? isolated.mode === "clone" : resume ? resume.recipe.gitCloneWorkspace : p.git_clone_workspace === true;
2995
3071
  const callbackEnabled = resume ? p.callback ?? resume.recipe.callback : p.callback !== false;
2996
3072
  const launchName = resume ? resume.recipe.name : p.name;
2997
3073
  // The frozen launch snapshot is the same shape a fresh spawn freezes.
@@ -3221,7 +3297,7 @@ export default function (pi, managed) {
3221
3297
  ...(allow && !sandboxEnabled ? ["--tools", allow] : []),
3222
3298
  ...(excludes.size ? ["--exclude-tools", [...excludes].join(",")] : []),
3223
3299
  ...(sandboxEnabled ? ["--no-builtin-tools", "--no-approve"] : approve ? ["--approve"] : []),
3224
- p.prompt,
3300
+ workerPrompt,
3225
3301
  ];
3226
3302
  const selectedTools = allow.split(",").filter((name) => name && !excludes.has(name));
3227
3303
  const inheritedTrusted = resume ? new Set(resume.recipe.optionalTrustedTools ?? []) : undefined;
@@ -3229,6 +3305,7 @@ export default function (pi, managed) {
3229
3305
  && (inheritedTrusted ? inheritedTrusted.has(name) : requestedTools === undefined)).map(({ name }) => name) ?? [];
3230
3306
  const dropped = toolSelection?.dropped ?? [];
3231
3307
  const taskRuntime = sandboxEnabled && requestedSandboxDir ? prepareTaskRuntime({
3308
+ worktreeGitDir: isolated?.mode === "worktree" ? inspectGitWorkspace(cwd).gitDir : undefined,
3232
3309
  root: requestedSandboxDir, controlDir: join(runDir(id), "control"),
3233
3310
  tools: selectedTools,
3234
3311
  permissions: taskPermissions && { ...taskPermissions, ...commandSettings },
@@ -3245,8 +3322,20 @@ export default function (pi, managed) {
3245
3322
  runtimeRoots: [baseDir()],
3246
3323
  capturedDenyWrite: internal?.resumeWait
3247
3324
  ? resume?.prior.operations?.policy.sandbox?.denyWrite
3248
- : undefined,
3325
+ : handoffAuthority?.sandbox?.denyWrite,
3249
3326
  }) : undefined;
3327
+ if (taskRuntime?.policy.worktreeGitDir) {
3328
+ const policy = taskRuntime.policy;
3329
+ const notice = worktreePolicyNotice(policy.worktreeGitDir, compileWritePolicy({
3330
+ writableRoot: policy.root, home: policy.home, permissions: policy.permissions,
3331
+ denyWrite: policy.denyWrite, runtimeCompatibility: true, runtimeWrite: [policy.scratch],
3332
+ }));
3333
+ if (notice) {
3334
+ workspaceNote += " " + notice;
3335
+ args[args.length - 1] = workspaceNote + "\n\n" + p.prompt;
3336
+ writeFileSync(promptPathFor(id), args[args.length - 1]);
3337
+ }
3338
+ }
3250
3339
  launchScratch = taskRuntime?.policy.scratch;
3251
3340
  if (sandboxEnabled && !taskRuntime)
3252
3341
  throw new Error("Task sandbox has no workspace; refusing an unconfined child.");
@@ -3280,18 +3369,7 @@ export default function (pi, managed) {
3280
3369
  if (countRunning() >= maxConcurrent) {
3281
3370
  throw new Error(`Max concurrent subagents (${maxConcurrent}) reached. Stop or let some finish first.`);
3282
3371
  }
3283
- // One writer per conversation, held across admission, child lifetime,
3284
- // and finalization. A live duplicate continuation is refused instead of
3285
- // letting two processes rewrite one session file. A fresh launch has a
3286
- // brand-new native session id, so it cannot contend with anyone and
3287
- // needs no lease; every continuation does.
3288
- if (resume || managed) {
3289
- lease = acquireConversationLease({ sessionId, attemptId: id });
3290
- }
3291
- // The lease is the first moment no other process can retire this
3292
- // conversation: re-prove the history identity the cached plan was
3293
- // built from, so `--session` can never reopen a file another sweep
3294
- // removed as an empty replacement.
3372
+ // Recheck the saved conversation after asynchronous launch preparation.
3295
3373
  if (resume)
3296
3374
  revalidateContinuationUnderLease(resume, callbackOrigin);
3297
3375
  const preflightPath = join(runDir(id), "child-preflight.json");
@@ -3370,18 +3448,21 @@ export default function (pi, managed) {
3370
3448
  throw new PreSpawnResumeError("This legacy park has no verified assignment outcome recipient; refusing continuation on an unsupported binding.");
3371
3449
  if (!assignment && bridgeEnabled)
3372
3450
  throw new Error("Durable assignment outcomes require a recorded parent session and transcript capability.");
3373
- if (internal?.resumeWait) {
3374
- const captured = resume?.prior.operations?.policy;
3375
- const currentSandbox = taskRuntime ? {
3451
+ const workspaceAuthority = {
3452
+ mandatoryPermissions: permissionPlan.enforced,
3453
+ sandbox: taskRuntime ? {
3376
3454
  root: taskRuntime.policy.root,
3377
- ...(taskRuntime.policy.permissions ? { permissions: taskRuntime.policy.permissions } : {}),
3378
- ...(taskRuntime.policy.denyWrite ? { denyWrite: [...taskRuntime.policy.denyWrite] } : {}),
3379
- } : null;
3380
- assertAssignmentPermissionScope(captured, { sandbox: currentSandbox, mandatoryPermissions: permissionPlan.enforced }, Boolean(managed));
3455
+ permissions: taskRuntime.policy.permissions,
3456
+ denyWrite: [...taskRuntime.policy.denyWrite],
3457
+ } : null,
3458
+ };
3459
+ if (internal?.resumeWait) {
3460
+ assertAssignmentPermissionScope(resume?.prior.operations?.policy, workspaceAuthority, Boolean(managed));
3381
3461
  }
3382
3462
  // Freeze the ordinary recipe before the durable external-launch intent.
3383
3463
  const recipe = buildLaunchRecipe({
3384
3464
  ...(!legacyToolLoading ? { toolLoadingVersion: 1 } : {}),
3465
+ ...(isolated ? { workspace: isolated, workspaceAuthority } : {}),
3385
3466
  attemptId: id, sessionId, sessionDir: childSessionDir, cwd, model, effort: thinking,
3386
3467
  tools: callerLaunchTools(allow), excludeTools: requestedExcludes.size ? [...requestedExcludes].join(",") : undefined,
3387
3468
  ...(optionalTrustedTools.length ? { optionalTrustedTools } : {}),
@@ -3445,6 +3526,8 @@ export default function (pi, managed) {
3445
3526
  timing: resolveRunTiming({ params: launchTimingParams(p), settings: timingSettingsFor(cfg), env: process.env, startedAt }),
3446
3527
  };
3447
3528
  const dispatchGuard = await internal?.beforeSpawn?.({ runId: id, permissionPlan });
3529
+ if (isolated)
3530
+ markWorkspaceWriter(isolated, id);
3448
3531
  const managedEnv = managed?.beforeSpawn({ id, sessionId, lease: lease.token, leasePath: lease.path,
3449
3532
  preflightPath, policyPath: taskRuntime?.policyPath, permissions: permissionPlan, recipe, recoveryMeta: meta });
3450
3533
  spawned = releaseChild(dispatchGuard, () => spawnDetached({ file: cmd.file, fileArgs: cmd.fileArgs, cwd, logPath: logPathFor(id),
@@ -3517,7 +3600,7 @@ export default function (pi, managed) {
3517
3600
  : resolution.specs.length
3518
3601
  ? `Runtime: isolated · extensions ${resolution.specs.join(", ")}\n`
3519
3602
  : `Runtime: isolated · built-in tools only\n`;
3520
- const warn = (dropped.length ? `Task sandbox: ${dropped.map((tool) => `${tool.name} disabled (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join("; ")}.\n` : "") +
3603
+ const warn = (workspaceNote ? workspaceNote + "\n" : "") + (dropped.length ? `Task sandbox: ${dropped.map((tool) => `${tool.name} disabled (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join("; ")}.\n` : "") +
3521
3604
  (!sandboxEnabled && resolution.unmapped.length
3522
3605
  ? `NOTE: no extension mapped for ${resolution.unmapped.join(", ")} — ` +
3523
3606
  `${resolution.unmapped.length > 1 ? "these tools" : "this tool"} will NOT exist in the child. ` +
@@ -3543,8 +3626,10 @@ export default function (pi, managed) {
3543
3626
  const { abortUncommittedLaunch } = await import("./launch-abort.domain.mjs");
3544
3627
  await abortUncommittedLaunch(id, {
3545
3628
  child: spawned, lease,
3546
- artifacts: { sessionDir: childSessionDir, workspaceDir: ownedCloneWorkspace, scratch: launchScratch },
3629
+ artifacts: { sessionDir: childSessionDir, workspaceDir: isolated ? undefined : ownedCloneWorkspace, scratch: launchScratch },
3547
3630
  });
3631
+ if (createdWorkspace && isolated)
3632
+ discardWorkspace(isolated);
3548
3633
  }
3549
3634
  throw error;
3550
3635
  }
@@ -3760,11 +3845,7 @@ export default function (pi, managed) {
3760
3845
  }
3761
3846
  catch { /* a host that refuses the adapter leaves parking unavailable */ }
3762
3847
  try {
3763
- const reconciliation = reconcileParkedWaits(service, {
3764
- resume: (park) => orchestration.resume(park),
3765
- notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
3766
- notify: notifyOwnedWait,
3767
- });
3848
+ const reconciliation = reconcileWorkerWaits();
3768
3849
  if (managed) {
3769
3850
  void reconciliation.catch(() => undefined);
3770
3851
  return;
@@ -3777,6 +3858,17 @@ export default function (pi, managed) {
3777
3858
  }
3778
3859
  catch { /* reconciliation retries on the next session start */ }
3779
3860
  }
3861
+ async function reconcileWorkerWaits() {
3862
+ const service = workerOperations.service;
3863
+ if (!service)
3864
+ return;
3865
+ const orchestration = ensureResumeOrchestration();
3866
+ await reconcileParkedWaits(service, {
3867
+ resume: (park) => orchestration.resume(park),
3868
+ notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
3869
+ notify: notifyOwnedWait,
3870
+ });
3871
+ }
3780
3872
  // ---- subagent_spawn -------------------------------------------------
3781
3873
  //
3782
3874
  // One tool launches both fresh work and a continuation of saved work. A
@@ -3803,7 +3895,7 @@ export default function (pi, managed) {
3803
3895
  ...CATALOG_GUIDELINES,
3804
3896
  "Subagent sandboxing defaults to off. Human settings in /sandbox control file, credential-file, command, and network permissions; sandbox:false cannot override an enabled human profile. Set sandbox:true to request kernel confinement, including without published settings. Set callback:false to finish quietly — then read the result on demand via subagent_result.",
3805
3897
  "Every launch automatically joins one shared harness-owned watcher, including batch launches; it stops when the last active run ends. Do not start a separate heartbeat or background watcher for subagents. A tool call still open for tool_wait_minutes (default 5) or no progress for stuck_minutes (default 10) sends one factual alert; these alerts never stop, cancel, or restart the run. Hard timeouts default to 60 minutes; max_minutes overrides that default (0 disables). Soft deadlines remain opt-in for work with a real wall-clock bound: deadline_minutes steers the child to wrap up and later stops it after grace_minutes, while max_minutes stops it without grace. Do not set elapsed-time limits merely because a task may take a while; use them only when the work needs a real wall-clock bound.",
3806
- "Use git_clone_workspace:true when the subagent will mutate Git in a sandbox. The parent prepares a disposable, self-contained clone with a real .git/ directory inside the sandbox root, so linked-worktree metadata outside the sandbox cannot stall the child.",
3898
+ "Git writers receive separate checkouts by default. /subagents settings selects Clone or Worktree. isolation:false selects the live checkout. A sandboxed Worktree can return its files or explicitly continue in a verified Clone with recover_in_clone:true.",
3807
3899
  "Saved conversations persist automatically. To continue a completed or stopped worker in its own history, call subagent_spawn with session_id (the native session id reported for the saved conversation) and the new feedback as prompt. Omit session_id for a brand-new conversation.",
3808
3900
  "On a continuation, pass prompt, session_id, and only optional model, thinking, callback, or timing overrides. Launch-only options (name, agent, role, alias, tools, exclude_tools, skills, clean, sandbox, sandbox_dir, cwd, git_clone_workspace, approve, allow_nested) keep the saved recipe; repeat them only with the same value, otherwise the launch is refused.",
3809
3901
  "Do not restate the original task or role when continuing: they already live in the saved conversation. A running or orphaned latest attempt blocks continuation until it stops, and missing saved history is refused rather than recreated.",
@@ -3826,6 +3918,8 @@ export default function (pi, managed) {
3826
3918
  sandbox_dir: Type.Optional(Type.String({ description: "Confine writes to (and run the child in) this directory instead of the working dir. Created if missing." })),
3827
3919
  callback: Type.Optional(Type.Boolean({ description: "Default TRUE: on completion, trigger a turn that calls subagent_result and presents the result. Set false to finish quietly — the result is then read on demand via subagent_result." })),
3828
3920
  cwd: Type.Optional(Type.String({ description: "Working directory (default: current)." })),
3921
+ isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
3922
+ recover_in_clone: Type.Optional(Type.Boolean({ description: "Continue a stopped or completed linked-worktree conversation in a verified clone with the same history and permissions." })),
3829
3923
  git_clone_workspace: Type.Optional(Type.Boolean({ description: "Prepare a disposable Git clone workspace for sandboxed Git-mutating subagents. The clone has a real .git/ directory inside the sandbox writable root and is self-contained after setup." })),
3830
3924
  approve: Type.Optional(Type.Boolean({ description: "Trust project-local files in the child (default: false; headless runs cannot prompt for trust)." })),
3831
3925
  allow_nested: Type.Optional(Type.Boolean({ description: "Allow the child to spawn its own subagents (default: false). Loads this extension in the child and allowlists its tools." })),
@@ -3865,6 +3959,8 @@ export default function (pi, managed) {
3865
3959
  model: p.model,
3866
3960
  thinking: p.thinking,
3867
3961
  callback: p.callback,
3962
+ isolation: p.isolation,
3963
+ recover_in_clone: p.recover_in_clone,
3868
3964
  deadline_minutes: p.deadline_minutes,
3869
3965
  grace_minutes: p.grace_minutes,
3870
3966
  max_minutes: p.max_minutes,
@@ -3989,6 +4085,7 @@ export default function (pi, managed) {
3989
4085
  callback: Type.Optional(Type.Boolean({ description: "Default TRUE: post result back on completion." })),
3990
4086
  clean: Type.Optional(Type.Boolean({ description: "Hermetic builtins-only child; no extensions load." })),
3991
4087
  cwd: Type.Optional(Type.String({ description: "Working directory (default: current)." })),
4088
+ isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
3992
4089
  git_clone_workspace: Type.Optional(Type.Boolean({ description: "Prepare a disposable Git clone workspace for each job (same semantics as subagent_spawn)." })),
3993
4090
  approve: Type.Optional(Type.Boolean({ description: "Trust project-local files in children." })),
3994
4091
  allow_nested: Type.Optional(Type.Boolean({ description: "Allow children to spawn their own subagents." })),
@@ -4012,6 +4109,8 @@ export default function (pi, managed) {
4012
4109
  callback: Type.Optional(Type.Boolean()),
4013
4110
  clean: Type.Optional(Type.Boolean()),
4014
4111
  cwd: Type.Optional(Type.String()),
4112
+ isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
4113
+ recover_in_clone: Type.Optional(Type.Boolean({ description: "Continue this job in a verified Clone." })),
4015
4114
  git_clone_workspace: Type.Optional(Type.Boolean()),
4016
4115
  approve: Type.Optional(Type.Boolean()),
4017
4116
  allow_nested: Type.Optional(Type.Boolean()),
@@ -4046,8 +4145,10 @@ export default function (pi, managed) {
4046
4145
  throw new Error(blankSelector);
4047
4146
  let catalogSnapshot;
4048
4147
  let catalogHost;
4049
- const needsCatalog = p.jobs.some((job) => job.session_id === undefined && job.session_name === undefined
4050
- && hasCatalogSelector(mergeJobOptions(p.shared, job)));
4148
+ const needsCatalog = p.jobs.some((job) => {
4149
+ const merged = mergeJobOptions(p.shared, job);
4150
+ return merged.session_id === undefined && merged.session_name === undefined && hasCatalogSelector(merged);
4151
+ });
4051
4152
  if (needsCatalog) {
4052
4153
  catalogHost = catalogHostFrom(ctx);
4053
4154
  noteCatalogHost(catalogHost);
@@ -4104,7 +4205,7 @@ export default function (pi, managed) {
4104
4205
  const job = p.jobs[i];
4105
4206
  let name = names[i];
4106
4207
  const merged = mergeJobOptions(p.shared, job);
4107
- const isContinuation = job.session_id !== undefined || job.session_name !== undefined;
4208
+ const isContinuation = merged.session_id !== undefined || merged.session_name !== undefined;
4108
4209
  // A continuation keeps its own frozen model and effort. shared.model
4109
4210
  // is a default for NEW conversations, so only a per-job value is an
4110
4211
  // explicit escalation of the saved recipe.
@@ -4120,7 +4221,7 @@ export default function (pi, managed) {
4120
4221
  }
4121
4222
  }
4122
4223
  try {
4123
- const sessionId = requestedSessionId(job, ctx.cwd);
4224
+ const sessionId = requestedSessionId(merged, ctx.cwd);
4124
4225
  // A saved conversation is never re-resolved against the catalog.
4125
4226
  if (sessionId === undefined && catalogSnapshot && catalogHost && hasCatalogSelector(merged)) {
4126
4227
  const explicitName = typeof job.name === "string" && job.name.trim() !== "" ? job.name : undefined;
@@ -4299,6 +4400,7 @@ export default function (pi, managed) {
4299
4400
  const timing = timingState();
4300
4401
  return {
4301
4402
  mode: settings.delegationMode, maxConcurrent: settings.maxConcurrent,
4403
+ gitWorkspace: activeWorkspace(),
4302
4404
  maxMinutes: timing.maxMinutes,
4303
4405
  modeSource: settings.sources.delegationMode,
4304
4406
  capSource: settings.sources.maxConcurrent,
@@ -4314,7 +4416,7 @@ export default function (pi, managed) {
4314
4416
  skillsError: skills.error,
4315
4417
  };
4316
4418
  },
4317
- changeMode, changeCap, changeTiming, changeSkills, save: saveSettings, reset: resetSettings,
4419
+ changeMode, changeWorkspace, changeCap, changeTiming, changeSkills, save: saveSettings, reset: resetSettings,
4318
4420
  discoverSkills: () => discoveredSkillsFromContext(ctx),
4319
4421
  // Close this page first; the catalog opens after ui.custom resolves.
4320
4422
  openAgents: () => done("agents"),
@@ -4328,7 +4430,7 @@ export default function (pi, managed) {
4328
4430
  : skills.mode === "none" ? "no skills" : `${skills.paths.length} selected skills`;
4329
4431
  const timing = timingState();
4330
4432
  ctx.ui.notify(`Delegation mode: ${activeDelegationMode()}. Concurrent subagents: ${activeConcurrencyCap()}. ` +
4331
- `Timeout: ${timing.maxMinutes} minutes (0 disables). Tool-wait alert: ${timing.toolWaitMinutes} min. ` +
4433
+ `Run timeout: ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "No limit"}. Tool-wait alert: ${timing.toolWaitMinutes} min. ` +
4332
4434
  `No-progress alert: ${timing.stuckMinutes} min. Skills: ${skillChoice}. ` +
4333
4435
  `Use /subagents mode <mode>, cap <number>, tool-wait <minutes>, stuck <minutes>, or settings; /subagents save persists them.`, "info");
4334
4436
  }
@@ -4420,7 +4522,7 @@ export default function (pi, managed) {
4420
4522
  : skills.mode === "none" ? "no skills" : `${skills.paths.length} selected skills`;
4421
4523
  const timing = timingState();
4422
4524
  if (ctx.hasUI && !(await ctx.ui.confirm("Save subagent defaults?", `Future sessions will start in ${activeDelegationMode()} with a cap of ${activeConcurrencyCap()}, ` +
4423
- `timeout ${timing.maxMinutes} minutes (0 disables), tool-wait alert ${timing.toolWaitMinutes} min, ` +
4525
+ `run timeout ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "No limit"}, tool-wait alert ${timing.toolWaitMinutes} min, ` +
4424
4526
  `no-progress alert ${timing.stuckMinutes} min, and ${skillChoice}.`))) {
4425
4527
  ctx.ui.notify("Subagent defaults unchanged.", "info");
4426
4528
  return;