pi-better-server 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -3
- package/scripts/measure-full-runtime/frontend.ts +10 -2
- package/scripts/measure-full-runtime.mjs +2 -0
- package/src/codex/return.ts +3 -2
- package/src/detach/extension.ts +20 -3
- package/src/event-log.ts +40 -12
- package/src/hosted-session.ts +11 -5
- package/src/remote-client/packages.ts +1 -4
- package/src/runtime/background-tools.ts +54 -8
- package/src/runtime/background.ts +16 -4
- package/src/runtime/domain/background/process.mjs +49 -11
- package/src/runtime/domain/background/supervisor/store.mjs +3 -3
- package/src/runtime/domain/background/supervisor/supervisor.mjs +9 -3
- package/src/runtime/domain/background-service/index.domain.mjs +19 -0
- package/src/runtime/domain/background-service/index.ts +19 -0
- package/src/runtime/domain/background-service/managed-frontend.domain.mjs +87 -5
- package/src/runtime/domain/background-service/managed-frontend.ts +76 -5
- package/src/runtime/domain/background-service/navigator-provider.domain.mjs +5 -0
- package/src/runtime/domain/background-service/navigator-provider.ts +4 -0
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +203 -31
- package/src/runtime/domain/background-service/observed-waits.ts +168 -24
- package/src/runtime/domain/background-service/process.domain.mjs +49 -11
- package/src/runtime/domain/background-service/process.ts +45 -11
- package/src/runtime/domain/background-service/review-settings.domain.mjs +16 -0
- package/src/runtime/domain/background-service/review-settings.ts +18 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +8 -70
- package/src/runtime/domain/background-service/runtime.ts +8 -73
- package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +2 -3
- package/src/runtime/domain/background-service/shared-harness-settings.ts +2 -5
- package/src/runtime/domain/background-service/shared-navigator.domain.mjs +55 -28
- package/src/runtime/domain/background-service/shared-navigator.ts +47 -26
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +5 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +6 -0
- package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +1 -1
- package/src/runtime/domain/background-service/shared-ssh-core/index.ts +1 -1
- package/src/runtime/domain/background-service/stall.domain.mjs +5 -3
- package/src/runtime/domain/background-service/stall.ts +7 -4
- package/src/runtime/domain/background-service/supervised-progress.domain.mjs +42 -0
- package/src/runtime/domain/background-service/supervised-progress.ts +43 -0
- package/src/runtime/domain/background-service/supervisor/README.md +1 -4
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/process.mjs +49 -11
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/generated/store.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +47 -4
- package/src/runtime/domain/background-service/supervisor/runner.ts +38 -3
- package/src/runtime/domain/background-service/supervisor/store.domain.mjs +3 -3
- package/src/runtime/domain/background-service/supervisor/store.ts +3 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.domain.mjs +9 -3
- package/src/runtime/domain/background-service/supervisor/supervisor.ts +6 -3
- package/src/runtime/domain/background-service/tools.domain.mjs +22 -16
- package/src/runtime/domain/background-service/tools.ts +26 -16
- package/src/runtime/domain/background-service/types.ts +4 -2
- package/src/runtime/domain/background-service/watch-fingerprint.domain.mjs +67 -0
- package/src/runtime/domain/background-service/watch-fingerprint.ts +70 -0
- package/src/runtime/domain/catalog/catalog-preferences.mjs +1 -3
- package/src/runtime/domain/coordinator/src/outbox.mjs +7 -0
- package/src/runtime/domain/coordinator/src/store.mjs +5 -1
- package/src/runtime/domain/log-paths.mjs +8 -1
- package/src/runtime/domain/parse.mjs +9 -5
- package/src/runtime/domain/sandbox-policy/README.md +3 -3
- package/src/runtime/domain/sandbox-policy/package.json +1 -1
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +2 -3
- package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +2 -5
- package/src/runtime/domain/session-store.mjs +7 -0
- package/src/runtime/domain/shared-harness-settings.mjs +2 -3
- package/src/runtime/domain/subagents/README.md +12 -10
- package/src/runtime/domain/subagents/assignment-outcomes.domain.mjs +2 -5
- package/src/runtime/domain/subagents/assignment-outcomes.ts +2 -5
- package/src/runtime/domain/subagents/assignment-report.domain.mjs +22 -0
- package/src/runtime/domain/subagents/assignment-report.ts +20 -0
- package/src/runtime/domain/subagents/batch.mjs +13 -5
- package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +1 -3
- package/src/runtime/domain/subagents/catalog-preferences.ts +1 -5
- package/src/runtime/domain/subagents/cleanup.domain.mjs +11 -2
- package/src/runtime/domain/subagents/cleanup.ts +10 -2
- package/src/runtime/domain/subagents/config.domain.mjs +5 -0
- package/src/runtime/domain/subagents/config.ts +8 -2
- package/src/runtime/domain/subagents/continuation.domain.mjs +4 -2
- package/src/runtime/domain/subagents/continuation.ts +4 -2
- package/src/runtime/domain/subagents/extensions.mjs +1 -0
- package/src/runtime/domain/subagents/failures.domain.mjs +11 -2
- package/src/runtime/domain/subagents/failures.ts +10 -2
- package/src/runtime/domain/subagents/finalization.domain.mjs +39 -32
- package/src/runtime/domain/subagents/finalization.ts +37 -30
- package/src/runtime/domain/subagents/git-workspace.domain.mjs +51 -6
- package/src/runtime/domain/subagents/git-workspace.ts +48 -6
- package/src/runtime/domain/subagents/index.domain.mjs +208 -75
- package/src/runtime/domain/subagents/index.ts +213 -75
- package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +508 -0
- package/src/runtime/domain/subagents/isolated-workspace.ts +551 -0
- package/src/runtime/domain/subagents/list.mjs +2 -2
- package/src/runtime/domain/subagents/managed-launch-client.domain.mjs +22 -5
- package/src/runtime/domain/subagents/managed-launch-client.ts +23 -6
- package/src/runtime/domain/subagents/output-payload.domain.mjs +24 -9
- package/src/runtime/domain/subagents/output-payload.ts +26 -12
- package/src/runtime/domain/subagents/package.json +4 -2
- package/src/runtime/domain/subagents/parse.domain.mjs +9 -5
- package/src/runtime/domain/subagents/parse.ts +10 -5
- package/src/runtime/domain/subagents/registry.domain.mjs +31 -25
- package/src/runtime/domain/subagents/registry.ts +31 -13
- package/src/runtime/domain/subagents/retained-result.domain.mjs +56 -0
- package/src/runtime/domain/subagents/retained-result.ts +65 -0
- package/src/runtime/domain/subagents/session-selection.domain.mjs +3 -1
- package/src/runtime/domain/subagents/session-selection.ts +2 -1
- package/src/runtime/domain/subagents/session-store.domain.mjs +7 -0
- package/src/runtime/domain/subagents/session-store.ts +9 -0
- package/src/runtime/domain/subagents/settings-page.domain.mjs +151 -107
- package/src/runtime/domain/subagents/settings-page.ts +147 -108
- package/src/runtime/domain/subagents/shared-catalog.domain.mjs +23 -7
- package/src/runtime/domain/subagents/shared-catalog.ts +23 -7
- package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +2 -3
- package/src/runtime/domain/subagents/shared-harness-settings.ts +2 -5
- package/src/runtime/domain/subagents/shared-navigator.domain.mjs +55 -28
- package/src/runtime/domain/subagents/shared-navigator.ts +47 -26
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/outbox.ts +9 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +5 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +6 -0
- package/src/runtime/domain/subagents/task-guard.domain.mjs +14 -1
- package/src/runtime/domain/subagents/task-guard.ts +13 -1
- package/src/runtime/domain/subagents/task-policy.domain.mjs +2 -1
- package/src/runtime/domain/subagents/task-policy.ts +5 -1
- package/src/runtime/domain/subagents/tools.domain.mjs +4 -8
- package/src/runtime/domain/subagents/tools.ts +4 -7
- package/src/runtime/domain/subagents/work-observation.domain.mjs +25 -1
- package/src/runtime/domain/subagents/work-observation.ts +20 -1
- package/src/runtime/domain/subagents/workspace-files.domain.mjs +103 -0
- package/src/runtime/domain/subagents/workspace-files.ts +114 -0
- package/src/runtime/domain/subagents/workspace-prepare-worker.mjs +12 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.d.mts +38 -0
- package/src/runtime/domain/subagents/workspace-scope.domain.mjs +5 -0
- package/src/runtime/domain/subagents/workspace-scope.ts +6 -0
- package/src/runtime/domain/subagents/worktree-feedback.domain.mjs +55 -0
- package/src/runtime/domain/subagents/worktree-feedback.ts +77 -0
- package/src/runtime/read-model.ts +4 -2
- package/src/runtime/root.ts +5 -2
- package/src/shared-ssh-core/index.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -21,6 +21,7 @@ import { currentSandboxPermissions } from "./permission-policy.domain.mjs";
|
|
|
21
21
|
import { assertWaitToolDependencies, createToolDescriptor } from "./operation-bridge-types.domain.mjs";
|
|
22
22
|
import { requestResumeAdmission } from "./worker-waits.domain.mjs";
|
|
23
23
|
import { execSync } from "node:child_process";
|
|
24
|
+
import { Worker } from "node:worker_threads";
|
|
24
25
|
import { writeFileSync, mkdirSync, renameSync, statSync } from "node:fs";
|
|
25
26
|
import * as PiCodingAgent from "@earendil-works/pi-coding-agent";
|
|
26
27
|
import * as PiTui from "@earendil-works/pi-tui";
|
|
@@ -48,14 +49,15 @@ import { readAppendedLines } from "./log-cursor.domain.mjs";
|
|
|
48
49
|
import { DELEGATION_MODES, DELEGATION_MODE_REQUEST, isDelegationMode, normalizeDelegationMode } from "./delegation.domain.mjs";
|
|
49
50
|
import { resolveExtensions, extensionArgs } from "./extensions.domain.mjs";
|
|
50
51
|
import { prepareTaskRuntime, applyDirectApplicationLoadout, DEFAULT_TASK_PERMISSIONS, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.domain.mjs";
|
|
51
|
-
import {
|
|
52
|
+
import { worktreePolicyNotice } from "./worktree-feedback.domain.mjs";
|
|
53
|
+
import { canonicalizePath, compileWritePolicy, describeSandboxSupport, takeRecoverySnapshot } from "./shared-sandbox-core.domain.mjs";
|
|
52
54
|
import { TASK_BUILTINS } from "./shared-task-sandbox.domain.mjs";
|
|
53
55
|
import { describeTaskTools, planTaskTools, selectEffectiveTaskTools } from "./subagent-tools.domain.mjs";
|
|
54
56
|
import { announceExecutionAdapter, describeSubagentProcessPolicy, effectiveWorkerProcessAccess, observeSandboxPermissions, resolveCommandSettings, resolveSubagentPermissions, } from "./permission-policy.domain.mjs";
|
|
55
57
|
import { dirname, isAbsolute, join } from "node:path";
|
|
56
58
|
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
59
|
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";
|
|
60
|
+
import { assignBatchJobNames, batchLaunchOutputSchema, batchLaunchResult, mergeJobOptions, nextBatchId, normalizeSessionSelector, planBatchLaunches, validateBatchPlan, } from "./batch.mjs";
|
|
59
61
|
import { formatCapacityRejectMessage, getSharedCapacityGate, } from "./capacity.mjs";
|
|
60
62
|
import { buildHealthCallbackDelivery } from "./completion.domain.mjs";
|
|
61
63
|
import { cancelCallbackBatch, getCallbackBatcher, packCallbackBatch, setCallbackBatchContext } from "./shared-callback-batcher.domain.mjs";
|
|
@@ -353,7 +355,7 @@ function markCompletionCallbackSuppressed(id, reason, now = Date.now()) {
|
|
|
353
355
|
if (sessionTornDown && reason === NO_ACTIVE_SESSION_REASON)
|
|
354
356
|
return;
|
|
355
357
|
const meta = readMeta(id);
|
|
356
|
-
if (!meta
|
|
358
|
+
if (!meta)
|
|
357
359
|
return;
|
|
358
360
|
// An explicitly interrupted run owes its completion to the conversation that
|
|
359
361
|
// launched it (#625, DEV-226 criterion 5). An unrelated session merely being
|
|
@@ -361,19 +363,22 @@ function markCompletionCallbackSuppressed(id, reason, now = Date.now()) {
|
|
|
361
363
|
// attempt but must keep the obligation: the pending marker stays, and A
|
|
362
364
|
// recovers it when it comes back. Records that never lost supervision keep
|
|
363
365
|
// today's durable suppression, so legacy/foreign notifications stay dead.
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
366
|
+
writeMeta(meta, { patch: current => {
|
|
367
|
+
if (current.completionCallbackSentAt !== undefined || current.completionCallbackSuppressedAt !== undefined)
|
|
368
|
+
return;
|
|
369
|
+
if ((current.supervisionInterruptedAt !== undefined || current.operations?.resumeLaunchToken)
|
|
370
|
+
&& isConversationIdentityReason(reason))
|
|
371
|
+
return;
|
|
372
|
+
return { completionCallbackSuppressedAt: now, completionCallbackSuppressedReason: reason };
|
|
373
|
+
} });
|
|
370
374
|
}
|
|
371
375
|
function markCompletionCallbackSent(id, now) {
|
|
372
376
|
const meta = readMeta(id);
|
|
373
|
-
if (!meta
|
|
377
|
+
if (!meta)
|
|
374
378
|
return;
|
|
375
|
-
meta.completionCallbackSentAt
|
|
376
|
-
|
|
379
|
+
writeMeta(meta, { patch: current => current.completionCallbackSentAt === undefined && current.completionCallbackSuppressedAt === undefined
|
|
380
|
+
? { completionCallbackSentAt: now } : undefined,
|
|
381
|
+
});
|
|
377
382
|
}
|
|
378
383
|
/** Queue one durable ordinary terminal event on the host-shared batch. */
|
|
379
384
|
function enqueueCompletionCallback(pi, id) {
|
|
@@ -838,6 +843,7 @@ let healthTicker;
|
|
|
838
843
|
let managedHealthClose;
|
|
839
844
|
/** ExtensionAPI retained so health transitions can deliver coordinator follow-ups (#65). */
|
|
840
845
|
let healthPi;
|
|
846
|
+
let recoverWorkerWaitsAfterExit;
|
|
841
847
|
/**
|
|
842
848
|
* Deliver a durable, deduped coordinator follow-up for orphaned/lost (#65).
|
|
843
849
|
*
|
|
@@ -1125,10 +1131,11 @@ function stopForTiming(pi, id, reason, now) {
|
|
|
1125
1131
|
return outcome.action === "finalized";
|
|
1126
1132
|
}
|
|
1127
1133
|
const current = readMeta(id);
|
|
1128
|
-
if (current
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1134
|
+
if (current) {
|
|
1135
|
+
writeMeta(current, { patch: latest => latest.callback !== false && latest.completionCallbackPendingAt === undefined
|
|
1136
|
+
&& latest.completionCallbackSentAt === undefined && latest.completionCallbackSuppressedAt === undefined
|
|
1137
|
+
? { completionCallbackPendingAt: now } : undefined,
|
|
1138
|
+
});
|
|
1132
1139
|
}
|
|
1133
1140
|
progressCache.delete(id);
|
|
1134
1141
|
if (current && !callbackSuppressionReason(current)) {
|
|
@@ -1305,6 +1312,7 @@ function reconcileHealth(ids) {
|
|
|
1305
1312
|
sendMessage: () => enqueueCompletionCallback(pi, meta.id),
|
|
1306
1313
|
});
|
|
1307
1314
|
if (observed.finalization?.applied) {
|
|
1315
|
+
void recoverWorkerWaitsAfterExit?.().catch(() => undefined);
|
|
1308
1316
|
syncHealthTicker();
|
|
1309
1317
|
continue;
|
|
1310
1318
|
}
|
|
@@ -2030,18 +2038,32 @@ function resolvePiBinary() {
|
|
|
2030
2038
|
}
|
|
2031
2039
|
return cachedPi;
|
|
2032
2040
|
}
|
|
2041
|
+
function prepareLaunchWorkspace(options, isolated) {
|
|
2042
|
+
const built = import.meta.url.endsWith(".domain.mjs");
|
|
2043
|
+
const entry = new URL("./workspace-prepare-worker.mjs", import.meta.url);
|
|
2044
|
+
return new Promise((resolve, reject) => {
|
|
2045
|
+
const worker = new Worker(entry, {
|
|
2046
|
+
workerData: { options, isolated },
|
|
2047
|
+
execArgv: built ? [] : ["--import", import.meta.resolve("tsx")],
|
|
2048
|
+
});
|
|
2049
|
+
worker.once("message", resolve);
|
|
2050
|
+
worker.once("error", reject);
|
|
2051
|
+
worker.once("exit", code => reject(new Error(`Git workspace preparation exited before reporting a result (code ${code}).`)));
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2033
2054
|
/**
|
|
2034
2055
|
* Finalize a run once its child exits. Host-facing wrapper around the
|
|
2035
2056
|
* first-party finalizer (finalization.ts) so tests can exercise the durable
|
|
2036
2057
|
* path without importing the pi package.
|
|
2037
2058
|
*/
|
|
2038
|
-
function finalizeRun(pi, ctx, id, code) {
|
|
2059
|
+
function finalizeRun(pi, ctx, id, code, recoveredWriterExit = false) {
|
|
2039
2060
|
progressCache.delete(id);
|
|
2040
2061
|
directlySupervisedRunIds.delete(id);
|
|
2041
2062
|
// Host-facing wrapper around first-party finalizer (finalization.ts).
|
|
2042
2063
|
// Coherent child-exit evidence may supersede provisional orphaned/lost
|
|
2043
2064
|
// reconciliation; finalization.ts enforces canExitFinalize + lifecycle authority.
|
|
2044
|
-
finalizeRunCore(id, code, {
|
|
2065
|
+
const result = finalizeRunCore(id, code, {
|
|
2066
|
+
recoveredWriterExit,
|
|
2045
2067
|
renderWidget,
|
|
2046
2068
|
notify: (message, level) => {
|
|
2047
2069
|
try {
|
|
@@ -2051,6 +2073,11 @@ function finalizeRun(pi, ctx, id, code) {
|
|
|
2051
2073
|
},
|
|
2052
2074
|
sendMessage: () => enqueueCompletionCallback(pi, id),
|
|
2053
2075
|
});
|
|
2076
|
+
if (recoveredWriterExit && result.applied) {
|
|
2077
|
+
// The old exit callback is gone. Finish its durable wait handoff after
|
|
2078
|
+
// recovery, including the independent writer and lease proof checks.
|
|
2079
|
+
void recoverWorkerWaitsAfterExit?.().catch(() => undefined);
|
|
2080
|
+
}
|
|
2054
2081
|
syncHealthTicker();
|
|
2055
2082
|
}
|
|
2056
2083
|
/**
|
|
@@ -2087,7 +2114,7 @@ function finalizeInterruptedRunFromLog(pi, meta, now) {
|
|
|
2087
2114
|
return false;
|
|
2088
2115
|
// Exit code is unknown after the observer is gone; the lifecycle authority
|
|
2089
2116
|
// classifies from the coherent stream instead of inventing one.
|
|
2090
|
-
finalizeRun(pi, uiCtx, meta.id, null);
|
|
2117
|
+
finalizeRun(pi, uiCtx, meta.id, null, true);
|
|
2091
2118
|
return true;
|
|
2092
2119
|
}
|
|
2093
2120
|
/**
|
|
@@ -2304,15 +2331,17 @@ function latestConversationAttempt(sessionId, metas) {
|
|
|
2304
2331
|
* missing session is the only error added here. Nothing is ever recreated.
|
|
2305
2332
|
*/
|
|
2306
2333
|
function requestedSessionId(job, cwd) {
|
|
2307
|
-
|
|
2334
|
+
const sessionId = normalizeSessionSelector(job.session_id);
|
|
2335
|
+
const sessionName = normalizeSessionSelector(job.session_name);
|
|
2336
|
+
if (sessionId !== undefined && sessionName !== undefined) {
|
|
2308
2337
|
throw new Error("Pass either session_id or session_name, not both.");
|
|
2309
2338
|
}
|
|
2310
|
-
if (
|
|
2311
|
-
if (typeof
|
|
2339
|
+
if (sessionName !== undefined) {
|
|
2340
|
+
if (typeof sessionName !== "string")
|
|
2312
2341
|
throw new Error("session_name must be a non-empty name.");
|
|
2313
|
-
return selectSessionByName(listMetas(),
|
|
2342
|
+
return selectSessionByName(listMetas(), sessionName, (workspace) => isWithinWorkspace(workspace, cwd));
|
|
2314
2343
|
}
|
|
2315
|
-
return
|
|
2344
|
+
return sessionId;
|
|
2316
2345
|
}
|
|
2317
2346
|
function continuationPlanFor(sessionId, origin) {
|
|
2318
2347
|
const others = listMetas();
|
|
@@ -2379,6 +2408,12 @@ export default function (pi, managed) {
|
|
|
2379
2408
|
let catalogModelRegistry;
|
|
2380
2409
|
let delegationOverride;
|
|
2381
2410
|
let capOverride;
|
|
2411
|
+
let workspaceOverride;
|
|
2412
|
+
const activeWorkspace = () => workspaceOverride ?? (loadConfig().gitWorkspace === "worktree" ? "worktree" : "clone");
|
|
2413
|
+
const changeWorkspace = (mode) => {
|
|
2414
|
+
workspaceOverride = mode;
|
|
2415
|
+
pi.appendEntry("pi-better-subagents-workspace", { version: 1, mode });
|
|
2416
|
+
};
|
|
2382
2417
|
let timingOverride = {};
|
|
2383
2418
|
let skillsOverride;
|
|
2384
2419
|
const savedSkills = () => {
|
|
@@ -2498,7 +2533,9 @@ export default function (pi, managed) {
|
|
|
2498
2533
|
capOverride = undefined;
|
|
2499
2534
|
delegationOverride = undefined;
|
|
2500
2535
|
timingOverride = {};
|
|
2536
|
+
workspaceOverride = undefined;
|
|
2501
2537
|
skillsOverride = undefined;
|
|
2538
|
+
pi.appendEntry("pi-better-subagents-workspace", { version: 1, mode: null });
|
|
2502
2539
|
pi.appendEntry("pi-better-subagents-cap", { version: 1, maxConcurrent: null });
|
|
2503
2540
|
pi.appendEntry("pi-better-subagents-delegation", { version: 1, mode: null });
|
|
2504
2541
|
pi.appendEntry("pi-better-subagents-timing", { version: 1, maxMinutes: null, toolWaitMinutes: null, stuckMinutes: null });
|
|
@@ -2602,6 +2639,7 @@ export default function (pi, managed) {
|
|
|
2602
2639
|
savedTiming.stuckMinutes = cfg.stuckMinutes;
|
|
2603
2640
|
}
|
|
2604
2641
|
writeSubagentSettings({
|
|
2642
|
+
...(workspaceOverride ? { gitWorkspace: workspaceOverride } : {}),
|
|
2605
2643
|
delegationMode: activeDelegationMode(),
|
|
2606
2644
|
maxConcurrent: activeConcurrencyCap(),
|
|
2607
2645
|
...savedTiming,
|
|
@@ -2645,6 +2683,7 @@ export default function (pi, managed) {
|
|
|
2645
2683
|
delegationOverride = undefined;
|
|
2646
2684
|
capOverride = undefined;
|
|
2647
2685
|
timingOverride = {};
|
|
2686
|
+
workspaceOverride = undefined;
|
|
2648
2687
|
skillsOverride = undefined;
|
|
2649
2688
|
const branch = ctx.sessionManager?.getBranch?.();
|
|
2650
2689
|
if (!Array.isArray(branch))
|
|
@@ -2687,6 +2726,12 @@ export default function (pi, managed) {
|
|
|
2687
2726
|
}
|
|
2688
2727
|
continue;
|
|
2689
2728
|
}
|
|
2729
|
+
if (entry.type === "custom" && entry.customType === "pi-better-subagents-workspace") {
|
|
2730
|
+
const data = entry.data;
|
|
2731
|
+
if (data?.version === 1 && (data.mode === "worktree" || data.mode === "clone" || data.mode === null)) {
|
|
2732
|
+
workspaceOverride = data.mode ?? undefined;
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2690
2735
|
if (entry.type === "custom" && entry.customType === "pi-better-subagents-timing") {
|
|
2691
2736
|
const data = entry.data;
|
|
2692
2737
|
if (data?.version !== 1)
|
|
@@ -2719,6 +2764,7 @@ export default function (pi, managed) {
|
|
|
2719
2764
|
// Capture for the health ticker (module-level); needed for orphaned/lost
|
|
2720
2765
|
// coordinator follow-ups that fire outside a tool-call stack (#65).
|
|
2721
2766
|
healthPi = pi;
|
|
2767
|
+
recoverWorkerWaitsAfterExit = reconcileWorkerWaits;
|
|
2722
2768
|
ensureSubagentProvider();
|
|
2723
2769
|
registerSubagentsGoalProvider(pi);
|
|
2724
2770
|
observeSandboxPermissions(pi);
|
|
@@ -2732,12 +2778,12 @@ export default function (pi, managed) {
|
|
|
2732
2778
|
restoreDelegationMode(ctx);
|
|
2733
2779
|
await workerOperations.start();
|
|
2734
2780
|
return definition.execute(key, params, signal, onUpdate, ctx);
|
|
2735
|
-
} } : { ...definition, async execute(key, params,
|
|
2781
|
+
} } : { ...definition, async execute(key, params, signal, _onUpdate, ctx) {
|
|
2736
2782
|
ctx = captureLaunchContext(ctx);
|
|
2737
2783
|
catalogHostFrom(ctx);
|
|
2738
2784
|
const { submitManagedLaunch } = await import("./managed-launch-client.domain.mjs");
|
|
2739
2785
|
void activateWorkObservation();
|
|
2740
|
-
return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, params));
|
|
2786
|
+
return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, params, signal));
|
|
2741
2787
|
} });
|
|
2742
2788
|
};
|
|
2743
2789
|
announceExecutionAdapter(pi, {
|
|
@@ -2834,7 +2880,8 @@ export default function (pi, managed) {
|
|
|
2834
2880
|
*/
|
|
2835
2881
|
internal) {
|
|
2836
2882
|
const { resolveChildClosure, resolveChildLaunch, configSnapshot } = await import("./child-dependencies.mjs");
|
|
2837
|
-
const { resolveSubagentWorkspace } = await import("./git-workspace.domain.mjs");
|
|
2883
|
+
const { resolveSubagentWorkspace, linkedWorktreeGitDir } = await import("./git-workspace.domain.mjs");
|
|
2884
|
+
const { workspaceChoice, restoreWorkspace, discardWorkspace, markWorkspaceWriter } = await import("./isolated-workspace.domain.mjs");
|
|
2838
2885
|
const { PREFLIGHT_ENV } = await import("./child-preflight.mjs");
|
|
2839
2886
|
assertThinkingLevel(p.thinking);
|
|
2840
2887
|
// Skill exposure is a caller choice, not a launch: validate its shape
|
|
@@ -2856,6 +2903,16 @@ export default function (pi, managed) {
|
|
|
2856
2903
|
// and a profile that would change confinement refuses instead of silently
|
|
2857
2904
|
// moving a live conversation into a different sandbox.
|
|
2858
2905
|
const permissionPlan = resolveSubagentPermissions(pi, p.sandbox, resume && { runId: resume.prior.id, sandbox: resume.recipe.sandbox });
|
|
2906
|
+
if (permissionPlan.sandboxEnabled) {
|
|
2907
|
+
const support = describeSandboxSupport();
|
|
2908
|
+
if (!support.supported) {
|
|
2909
|
+
const remedy = permissionPlan.permissions
|
|
2910
|
+
? "Turn off the Subagents sandbox in /sandbox settings to run without confinement."
|
|
2911
|
+
: resume ? "Launch a new subagent with sandbox:false to run without confinement."
|
|
2912
|
+
: "Pass sandbox:false to run without confinement.";
|
|
2913
|
+
throw new Error(`Task sandbox unavailable: ${support.reason} ${remedy}`);
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2859
2916
|
const processPolicy = describeSubagentProcessPolicy(permissionPlan, process.platform);
|
|
2860
2917
|
const processAccess = effectiveWorkerProcessAccess(permissionPlan);
|
|
2861
2918
|
const taskPermissions = permissionPlan.inactiveProfile
|
|
@@ -2928,7 +2985,36 @@ export default function (pi, managed) {
|
|
|
2928
2985
|
// The disposable clone this launch owns (removed if the spawn fails); a caller's sandbox_dir is not ours.
|
|
2929
2986
|
// A continuation never prepares another clone: the recipe's workspace already
|
|
2930
2987
|
// holds the prior attempt's uncommitted work.
|
|
2931
|
-
|
|
2988
|
+
if (p.isolation === false && p.git_clone_workspace)
|
|
2989
|
+
throw new Error("Choose either live checkout or git_clone_workspace.");
|
|
2990
|
+
if (p.recover_in_clone && (!resume || resume.recipe.workspace?.mode !== "worktree" || internal?.resumeWait)) {
|
|
2991
|
+
throw new Error("Clone handoff requires an explicit continuation of a linked worktree.");
|
|
2992
|
+
}
|
|
2993
|
+
if (resume && p.isolation !== undefined && Boolean(resume.recipe.workspace || resume.recipe.gitCloneWorkspace) !== p.isolation) {
|
|
2994
|
+
throw new ContinuationError("Changing isolation would replace the saved workspace.");
|
|
2995
|
+
}
|
|
2996
|
+
const handoffAuthority = p.recover_in_clone ? resume?.recipe.workspaceAuthority : undefined;
|
|
2997
|
+
if (p.recover_in_clone && resume) {
|
|
2998
|
+
const previous = handoffAuthority?.sandbox;
|
|
2999
|
+
const permissions = taskPermissions ?? DEFAULT_TASK_PERMISSIONS;
|
|
3000
|
+
assertAssignmentPermissionScope(handoffAuthority, {
|
|
3001
|
+
mandatoryPermissions: permissionPlan.enforced,
|
|
3002
|
+
sandbox: sandboxEnabled ? {
|
|
3003
|
+
root: resume.recipe.sandboxDir,
|
|
3004
|
+
denyWrite: previous?.denyWrite ?? [],
|
|
3005
|
+
permissions: {
|
|
3006
|
+
...DEFAULT_TASK_PERMISSIONS, ...permissions, ...resolveCommandSettings(permissions),
|
|
3007
|
+
processAccess: permissions.processAccess ?? "off",
|
|
3008
|
+
},
|
|
3009
|
+
} : null,
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
const selected = normalizeTools(p.tools ?? cfg.defaultTools ?? (p.clean ? SAFE_CLEAN_TOOLS : SAFE_DEFAULT_TOOLS));
|
|
3013
|
+
let isolated = resume?.recipe.workspace;
|
|
3014
|
+
if (!resume && !p.sandbox_dir && p.isolation !== false) {
|
|
3015
|
+
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 ?? "");
|
|
3016
|
+
}
|
|
3017
|
+
const ownedCloneWorkspace = !resume && !p.sandbox_dir && (isolated || p.git_clone_workspace) ? taskWorkspaceDir(id) : undefined;
|
|
2932
3018
|
// A launch attempt only becomes a run when `writeMeta` commits. Until
|
|
2933
3019
|
// then everything it creates (prompt, control/, provenance, its own
|
|
2934
3020
|
// session dir, clone workspace, task scratch) belongs to the attempt and
|
|
@@ -2938,6 +3024,7 @@ export default function (pi, managed) {
|
|
|
2938
3024
|
let spawned;
|
|
2939
3025
|
let launchScratch;
|
|
2940
3026
|
let committed = false;
|
|
3027
|
+
let createdWorkspace = false;
|
|
2941
3028
|
try {
|
|
2942
3029
|
if (!resume)
|
|
2943
3030
|
mkdirSync(childSessionDir, { recursive: true });
|
|
@@ -2947,17 +3034,34 @@ export default function (pi, managed) {
|
|
|
2947
3034
|
// concurrent purge can tell this live attempt from dead launch debris
|
|
2948
3035
|
// (#623 R1). The outer catch drops the whole directory on failure.
|
|
2949
3036
|
recordLaunchAttempt(id);
|
|
3037
|
+
// Cleanup, restoration and the actual writer share the conversation lease.
|
|
3038
|
+
if (resume || managed)
|
|
3039
|
+
lease = acquireConversationLease({ sessionId, attemptId: id });
|
|
3040
|
+
if (resume) {
|
|
3041
|
+
revalidateContinuationUnderLease(resume, callbackOrigin);
|
|
3042
|
+
if (isolated)
|
|
3043
|
+
isolated = restoreWorkspace(isolated, p.recover_in_clone, resume.prior.id);
|
|
3044
|
+
}
|
|
3045
|
+
if (!resume && isolated) {
|
|
3046
|
+
const root = taskWorkspaceDir(id);
|
|
3047
|
+
mkdirSync(dirname(root), { recursive: true });
|
|
3048
|
+
mkdirSync(root, { mode: 0o700 });
|
|
3049
|
+
createdWorkspace = true;
|
|
3050
|
+
}
|
|
3051
|
+
const workspaceOptions = {
|
|
3052
|
+
ctxCwd: ctx.cwd, cwd: p.cwd, sandboxDir: p.sandbox_dir ?? ownedCloneWorkspace,
|
|
3053
|
+
gitCloneWorkspace: p.git_clone_workspace, runId: id, runDirPath: runDir(id), sandboxEnabled,
|
|
3054
|
+
};
|
|
2950
3055
|
const workspace = resume
|
|
2951
3056
|
? { cwd: resume.recipe.cwd, requestedSandboxDir: resume.recipe.sandboxDir }
|
|
2952
|
-
:
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
});
|
|
3057
|
+
: isolated || p.git_clone_workspace
|
|
3058
|
+
? await prepareLaunchWorkspace(workspaceOptions, p.git_clone_workspace ? undefined : isolated)
|
|
3059
|
+
: resolveSubagentWorkspace(workspaceOptions);
|
|
3060
|
+
// Legacy explicit clones launch at the repository root, even when the source is a subdirectory.
|
|
3061
|
+
if (!resume && isolated && p.git_clone_workspace)
|
|
3062
|
+
isolated = { ...isolated, subdir: "" };
|
|
3063
|
+
let workspaceNote = isolated ? `Git workspace: ${isolated.mode} at ${workspace.cwd}. Base ${isolated.base}.`
|
|
3064
|
+
+ (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
3065
|
const cwd = workspace.cwd;
|
|
2962
3066
|
const requestedSandboxDir = workspace.requestedSandboxDir;
|
|
2963
3067
|
// Skill exposure is decided once per attempt. A continuation replays the
|
|
@@ -2983,7 +3087,8 @@ export default function (pi, managed) {
|
|
|
2983
3087
|
});
|
|
2984
3088
|
if (requestedSandboxDir)
|
|
2985
3089
|
mkdirSync(requestedSandboxDir, { recursive: true });
|
|
2986
|
-
|
|
3090
|
+
const workerPrompt = workspaceNote ? workspaceNote + "\n\n" + p.prompt : p.prompt;
|
|
3091
|
+
writeFileSync(promptPathFor(id), workerPrompt);
|
|
2987
3092
|
// A continuation keeps the recipe's launch intent; only current
|
|
2988
3093
|
// permission-driven adjustments are re-derived from it.
|
|
2989
3094
|
const requestedTools = resume ? callerLaunchTools(resume.recipe.tools) : p.tools;
|
|
@@ -2991,7 +3096,7 @@ export default function (pi, managed) {
|
|
|
2991
3096
|
const clean = resume ? resume.recipe.clean : p.clean === true;
|
|
2992
3097
|
const allowNested = resume ? resume.recipe.allowNested : p.allow_nested === true;
|
|
2993
3098
|
const approve = resume ? resume.recipe.approve : p.approve === true;
|
|
2994
|
-
const gitCloneWorkspace = resume ? resume.recipe.gitCloneWorkspace : p.git_clone_workspace === true;
|
|
3099
|
+
const gitCloneWorkspace = isolated ? isolated.mode === "clone" : resume ? resume.recipe.gitCloneWorkspace : p.git_clone_workspace === true;
|
|
2995
3100
|
const callbackEnabled = resume ? p.callback ?? resume.recipe.callback : p.callback !== false;
|
|
2996
3101
|
const launchName = resume ? resume.recipe.name : p.name;
|
|
2997
3102
|
// The frozen launch snapshot is the same shape a fresh spawn freezes.
|
|
@@ -3221,14 +3326,16 @@ export default function (pi, managed) {
|
|
|
3221
3326
|
...(allow && !sandboxEnabled ? ["--tools", allow] : []),
|
|
3222
3327
|
...(excludes.size ? ["--exclude-tools", [...excludes].join(",")] : []),
|
|
3223
3328
|
...(sandboxEnabled ? ["--no-builtin-tools", "--no-approve"] : approve ? ["--approve"] : []),
|
|
3224
|
-
|
|
3329
|
+
workerPrompt,
|
|
3225
3330
|
];
|
|
3226
3331
|
const selectedTools = allow.split(",").filter((name) => name && !excludes.has(name));
|
|
3227
3332
|
const inheritedTrusted = resume ? new Set(resume.recipe.optionalTrustedTools ?? []) : undefined;
|
|
3228
3333
|
const optionalTrustedTools = taskTools?.trusted.filter(({ name }) => selectedTools.includes(name)
|
|
3229
3334
|
&& (inheritedTrusted ? inheritedTrusted.has(name) : requestedTools === undefined)).map(({ name }) => name) ?? [];
|
|
3230
3335
|
const dropped = toolSelection?.dropped ?? [];
|
|
3336
|
+
const sharedGitDir = sandboxEnabled && isolated?.mode !== "clone" ? linkedWorktreeGitDir(cwd) : undefined;
|
|
3231
3337
|
const taskRuntime = sandboxEnabled && requestedSandboxDir ? prepareTaskRuntime({
|
|
3338
|
+
worktreeGitDir: isolated?.mode === "worktree" ? sharedGitDir : undefined,
|
|
3232
3339
|
root: requestedSandboxDir, controlDir: join(runDir(id), "control"),
|
|
3233
3340
|
tools: selectedTools,
|
|
3234
3341
|
permissions: taskPermissions && { ...taskPermissions, ...commandSettings },
|
|
@@ -3245,8 +3352,21 @@ export default function (pi, managed) {
|
|
|
3245
3352
|
runtimeRoots: [baseDir()],
|
|
3246
3353
|
capturedDenyWrite: internal?.resumeWait
|
|
3247
3354
|
? resume?.prior.operations?.policy.sandbox?.denyWrite
|
|
3248
|
-
:
|
|
3355
|
+
: handoffAuthority?.sandbox?.denyWrite,
|
|
3249
3356
|
}) : undefined;
|
|
3357
|
+
if (taskRuntime && sharedGitDir) {
|
|
3358
|
+
const policy = taskRuntime.policy;
|
|
3359
|
+
const notice = worktreePolicyNotice(sharedGitDir, compileWritePolicy({
|
|
3360
|
+
writableRoot: policy.root, home: policy.home, permissions: policy.permissions,
|
|
3361
|
+
denyWrite: policy.denyWrite, runtimeCompatibility: true, runtimeWrite: [policy.scratch],
|
|
3362
|
+
}));
|
|
3363
|
+
if (notice) {
|
|
3364
|
+
workspaceNote = isolated?.mode === "worktree" ? `${workspaceNote} ${notice}`
|
|
3365
|
+
: `Git workspace: existing linked worktree at ${cwd}. ${notice} Use git_clone_workspace:true for a new worker that needs to commit, or return the changes for the parent to commit.`;
|
|
3366
|
+
args[args.length - 1] = workspaceNote + "\n\n" + p.prompt;
|
|
3367
|
+
writeFileSync(promptPathFor(id), args[args.length - 1]);
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3250
3370
|
launchScratch = taskRuntime?.policy.scratch;
|
|
3251
3371
|
if (sandboxEnabled && !taskRuntime)
|
|
3252
3372
|
throw new Error("Task sandbox has no workspace; refusing an unconfined child.");
|
|
@@ -3280,18 +3400,7 @@ export default function (pi, managed) {
|
|
|
3280
3400
|
if (countRunning() >= maxConcurrent) {
|
|
3281
3401
|
throw new Error(`Max concurrent subagents (${maxConcurrent}) reached. Stop or let some finish first.`);
|
|
3282
3402
|
}
|
|
3283
|
-
//
|
|
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.
|
|
3403
|
+
// Recheck the saved conversation after asynchronous launch preparation.
|
|
3295
3404
|
if (resume)
|
|
3296
3405
|
revalidateContinuationUnderLease(resume, callbackOrigin);
|
|
3297
3406
|
const preflightPath = join(runDir(id), "child-preflight.json");
|
|
@@ -3370,18 +3479,21 @@ export default function (pi, managed) {
|
|
|
3370
3479
|
throw new PreSpawnResumeError("This legacy park has no verified assignment outcome recipient; refusing continuation on an unsupported binding.");
|
|
3371
3480
|
if (!assignment && bridgeEnabled)
|
|
3372
3481
|
throw new Error("Durable assignment outcomes require a recorded parent session and transcript capability.");
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3482
|
+
const workspaceAuthority = {
|
|
3483
|
+
mandatoryPermissions: permissionPlan.enforced,
|
|
3484
|
+
sandbox: taskRuntime ? {
|
|
3376
3485
|
root: taskRuntime.policy.root,
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
} : null
|
|
3380
|
-
|
|
3486
|
+
permissions: taskRuntime.policy.permissions,
|
|
3487
|
+
denyWrite: [...taskRuntime.policy.denyWrite],
|
|
3488
|
+
} : null,
|
|
3489
|
+
};
|
|
3490
|
+
if (internal?.resumeWait) {
|
|
3491
|
+
assertAssignmentPermissionScope(resume?.prior.operations?.policy, workspaceAuthority, Boolean(managed));
|
|
3381
3492
|
}
|
|
3382
3493
|
// Freeze the ordinary recipe before the durable external-launch intent.
|
|
3383
3494
|
const recipe = buildLaunchRecipe({
|
|
3384
3495
|
...(!legacyToolLoading ? { toolLoadingVersion: 1 } : {}),
|
|
3496
|
+
...(isolated ? { workspace: isolated, workspaceAuthority } : {}),
|
|
3385
3497
|
attemptId: id, sessionId, sessionDir: childSessionDir, cwd, model, effort: thinking,
|
|
3386
3498
|
tools: callerLaunchTools(allow), excludeTools: requestedExcludes.size ? [...requestedExcludes].join(",") : undefined,
|
|
3387
3499
|
...(optionalTrustedTools.length ? { optionalTrustedTools } : {}),
|
|
@@ -3445,6 +3557,8 @@ export default function (pi, managed) {
|
|
|
3445
3557
|
timing: resolveRunTiming({ params: launchTimingParams(p), settings: timingSettingsFor(cfg), env: process.env, startedAt }),
|
|
3446
3558
|
};
|
|
3447
3559
|
const dispatchGuard = await internal?.beforeSpawn?.({ runId: id, permissionPlan });
|
|
3560
|
+
if (isolated)
|
|
3561
|
+
markWorkspaceWriter(isolated, id);
|
|
3448
3562
|
const managedEnv = managed?.beforeSpawn({ id, sessionId, lease: lease.token, leasePath: lease.path,
|
|
3449
3563
|
preflightPath, policyPath: taskRuntime?.policyPath, permissions: permissionPlan, recipe, recoveryMeta: meta });
|
|
3450
3564
|
spawned = releaseChild(dispatchGuard, () => spawnDetached({ file: cmd.file, fileArgs: cmd.fileArgs, cwd, logPath: logPathFor(id),
|
|
@@ -3517,7 +3631,7 @@ export default function (pi, managed) {
|
|
|
3517
3631
|
: resolution.specs.length
|
|
3518
3632
|
? `Runtime: isolated · extensions ${resolution.specs.join(", ")}\n`
|
|
3519
3633
|
: `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` : "") +
|
|
3634
|
+
const warn = (workspaceNote ? workspaceNote + "\n" : "") + (dropped.length ? `Task sandbox: ${dropped.map((tool) => `${tool.name} disabled (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join("; ")}.\n` : "") +
|
|
3521
3635
|
(!sandboxEnabled && resolution.unmapped.length
|
|
3522
3636
|
? `NOTE: no extension mapped for ${resolution.unmapped.join(", ")} — ` +
|
|
3523
3637
|
`${resolution.unmapped.length > 1 ? "these tools" : "this tool"} will NOT exist in the child. ` +
|
|
@@ -3543,8 +3657,10 @@ export default function (pi, managed) {
|
|
|
3543
3657
|
const { abortUncommittedLaunch } = await import("./launch-abort.domain.mjs");
|
|
3544
3658
|
await abortUncommittedLaunch(id, {
|
|
3545
3659
|
child: spawned, lease,
|
|
3546
|
-
artifacts: { sessionDir: childSessionDir, workspaceDir: ownedCloneWorkspace, scratch: launchScratch },
|
|
3660
|
+
artifacts: { sessionDir: childSessionDir, workspaceDir: isolated ? undefined : ownedCloneWorkspace, scratch: launchScratch },
|
|
3547
3661
|
});
|
|
3662
|
+
if (createdWorkspace && isolated)
|
|
3663
|
+
discardWorkspace(isolated);
|
|
3548
3664
|
}
|
|
3549
3665
|
throw error;
|
|
3550
3666
|
}
|
|
@@ -3760,11 +3876,7 @@ export default function (pi, managed) {
|
|
|
3760
3876
|
}
|
|
3761
3877
|
catch { /* a host that refuses the adapter leaves parking unavailable */ }
|
|
3762
3878
|
try {
|
|
3763
|
-
const reconciliation =
|
|
3764
|
-
resume: (park) => orchestration.resume(park),
|
|
3765
|
-
notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
|
|
3766
|
-
notify: notifyOwnedWait,
|
|
3767
|
-
});
|
|
3879
|
+
const reconciliation = reconcileWorkerWaits();
|
|
3768
3880
|
if (managed) {
|
|
3769
3881
|
void reconciliation.catch(() => undefined);
|
|
3770
3882
|
return;
|
|
@@ -3777,6 +3889,17 @@ export default function (pi, managed) {
|
|
|
3777
3889
|
}
|
|
3778
3890
|
catch { /* reconciliation retries on the next session start */ }
|
|
3779
3891
|
}
|
|
3892
|
+
async function reconcileWorkerWaits() {
|
|
3893
|
+
const service = workerOperations.service;
|
|
3894
|
+
if (!service)
|
|
3895
|
+
return;
|
|
3896
|
+
const orchestration = ensureResumeOrchestration();
|
|
3897
|
+
await reconcileParkedWaits(service, {
|
|
3898
|
+
resume: (park) => orchestration.resume(park),
|
|
3899
|
+
notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
|
|
3900
|
+
notify: notifyOwnedWait,
|
|
3901
|
+
});
|
|
3902
|
+
}
|
|
3780
3903
|
// ---- subagent_spawn -------------------------------------------------
|
|
3781
3904
|
//
|
|
3782
3905
|
// One tool launches both fresh work and a continuation of saved work. A
|
|
@@ -3803,7 +3926,7 @@ export default function (pi, managed) {
|
|
|
3803
3926
|
...CATALOG_GUIDELINES,
|
|
3804
3927
|
"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
3928
|
"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
|
-
"
|
|
3929
|
+
"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
3930
|
"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
3931
|
"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
3932
|
"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 +3949,8 @@ export default function (pi, managed) {
|
|
|
3826
3949
|
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
3950
|
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
3951
|
cwd: Type.Optional(Type.String({ description: "Working directory (default: current)." })),
|
|
3952
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
3953
|
+
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
3954
|
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
3955
|
approve: Type.Optional(Type.Boolean({ description: "Trust project-local files in the child (default: false; headless runs cannot prompt for trust)." })),
|
|
3831
3956
|
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 +3990,8 @@ export default function (pi, managed) {
|
|
|
3865
3990
|
model: p.model,
|
|
3866
3991
|
thinking: p.thinking,
|
|
3867
3992
|
callback: p.callback,
|
|
3993
|
+
isolation: p.isolation,
|
|
3994
|
+
recover_in_clone: p.recover_in_clone,
|
|
3868
3995
|
deadline_minutes: p.deadline_minutes,
|
|
3869
3996
|
grace_minutes: p.grace_minutes,
|
|
3870
3997
|
max_minutes: p.max_minutes,
|
|
@@ -3989,6 +4116,7 @@ export default function (pi, managed) {
|
|
|
3989
4116
|
callback: Type.Optional(Type.Boolean({ description: "Default TRUE: post result back on completion." })),
|
|
3990
4117
|
clean: Type.Optional(Type.Boolean({ description: "Hermetic builtins-only child; no extensions load." })),
|
|
3991
4118
|
cwd: Type.Optional(Type.String({ description: "Working directory (default: current)." })),
|
|
4119
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
3992
4120
|
git_clone_workspace: Type.Optional(Type.Boolean({ description: "Prepare a disposable Git clone workspace for each job (same semantics as subagent_spawn)." })),
|
|
3993
4121
|
approve: Type.Optional(Type.Boolean({ description: "Trust project-local files in children." })),
|
|
3994
4122
|
allow_nested: Type.Optional(Type.Boolean({ description: "Allow children to spawn their own subagents." })),
|
|
@@ -4012,6 +4140,8 @@ export default function (pi, managed) {
|
|
|
4012
4140
|
callback: Type.Optional(Type.Boolean()),
|
|
4013
4141
|
clean: Type.Optional(Type.Boolean()),
|
|
4014
4142
|
cwd: Type.Optional(Type.String()),
|
|
4143
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
4144
|
+
recover_in_clone: Type.Optional(Type.Boolean({ description: "Continue this job in a verified Clone." })),
|
|
4015
4145
|
git_clone_workspace: Type.Optional(Type.Boolean()),
|
|
4016
4146
|
approve: Type.Optional(Type.Boolean()),
|
|
4017
4147
|
allow_nested: Type.Optional(Type.Boolean()),
|
|
@@ -4046,8 +4176,10 @@ export default function (pi, managed) {
|
|
|
4046
4176
|
throw new Error(blankSelector);
|
|
4047
4177
|
let catalogSnapshot;
|
|
4048
4178
|
let catalogHost;
|
|
4049
|
-
const needsCatalog = p.jobs.some((job) =>
|
|
4050
|
-
|
|
4179
|
+
const needsCatalog = p.jobs.some((job) => {
|
|
4180
|
+
const merged = mergeJobOptions(p.shared, job);
|
|
4181
|
+
return merged.session_id === undefined && merged.session_name === undefined && hasCatalogSelector(merged);
|
|
4182
|
+
});
|
|
4051
4183
|
if (needsCatalog) {
|
|
4052
4184
|
catalogHost = catalogHostFrom(ctx);
|
|
4053
4185
|
noteCatalogHost(catalogHost);
|
|
@@ -4104,7 +4236,7 @@ export default function (pi, managed) {
|
|
|
4104
4236
|
const job = p.jobs[i];
|
|
4105
4237
|
let name = names[i];
|
|
4106
4238
|
const merged = mergeJobOptions(p.shared, job);
|
|
4107
|
-
const isContinuation =
|
|
4239
|
+
const isContinuation = merged.session_id !== undefined || merged.session_name !== undefined;
|
|
4108
4240
|
// A continuation keeps its own frozen model and effort. shared.model
|
|
4109
4241
|
// is a default for NEW conversations, so only a per-job value is an
|
|
4110
4242
|
// explicit escalation of the saved recipe.
|
|
@@ -4120,7 +4252,7 @@ export default function (pi, managed) {
|
|
|
4120
4252
|
}
|
|
4121
4253
|
}
|
|
4122
4254
|
try {
|
|
4123
|
-
const sessionId = requestedSessionId(
|
|
4255
|
+
const sessionId = requestedSessionId(merged, ctx.cwd);
|
|
4124
4256
|
// A saved conversation is never re-resolved against the catalog.
|
|
4125
4257
|
if (sessionId === undefined && catalogSnapshot && catalogHost && hasCatalogSelector(merged)) {
|
|
4126
4258
|
const explicitName = typeof job.name === "string" && job.name.trim() !== "" ? job.name : undefined;
|
|
@@ -4299,6 +4431,7 @@ export default function (pi, managed) {
|
|
|
4299
4431
|
const timing = timingState();
|
|
4300
4432
|
return {
|
|
4301
4433
|
mode: settings.delegationMode, maxConcurrent: settings.maxConcurrent,
|
|
4434
|
+
gitWorkspace: activeWorkspace(),
|
|
4302
4435
|
maxMinutes: timing.maxMinutes,
|
|
4303
4436
|
modeSource: settings.sources.delegationMode,
|
|
4304
4437
|
capSource: settings.sources.maxConcurrent,
|
|
@@ -4314,7 +4447,7 @@ export default function (pi, managed) {
|
|
|
4314
4447
|
skillsError: skills.error,
|
|
4315
4448
|
};
|
|
4316
4449
|
},
|
|
4317
|
-
changeMode, changeCap, changeTiming, changeSkills, save: saveSettings, reset: resetSettings,
|
|
4450
|
+
changeMode, changeWorkspace, changeCap, changeTiming, changeSkills, save: saveSettings, reset: resetSettings,
|
|
4318
4451
|
discoverSkills: () => discoveredSkillsFromContext(ctx),
|
|
4319
4452
|
// Close this page first; the catalog opens after ui.custom resolves.
|
|
4320
4453
|
openAgents: () => done("agents"),
|
|
@@ -4328,7 +4461,7 @@ export default function (pi, managed) {
|
|
|
4328
4461
|
: skills.mode === "none" ? "no skills" : `${skills.paths.length} selected skills`;
|
|
4329
4462
|
const timing = timingState();
|
|
4330
4463
|
ctx.ui.notify(`Delegation mode: ${activeDelegationMode()}. Concurrent subagents: ${activeConcurrencyCap()}. ` +
|
|
4331
|
-
`
|
|
4464
|
+
`Run timeout: ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "No limit"}. Tool-wait alert: ${timing.toolWaitMinutes} min. ` +
|
|
4332
4465
|
`No-progress alert: ${timing.stuckMinutes} min. Skills: ${skillChoice}. ` +
|
|
4333
4466
|
`Use /subagents mode <mode>, cap <number>, tool-wait <minutes>, stuck <minutes>, or settings; /subagents save persists them.`, "info");
|
|
4334
4467
|
}
|
|
@@ -4420,7 +4553,7 @@ export default function (pi, managed) {
|
|
|
4420
4553
|
: skills.mode === "none" ? "no skills" : `${skills.paths.length} selected skills`;
|
|
4421
4554
|
const timing = timingState();
|
|
4422
4555
|
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
|
|
4556
|
+
`run timeout ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "No limit"}, tool-wait alert ${timing.toolWaitMinutes} min, ` +
|
|
4424
4557
|
`no-progress alert ${timing.stuckMinutes} min, and ${skillChoice}.`))) {
|
|
4425
4558
|
ctx.ui.notify("Subagent defaults unchanged.", "info");
|
|
4426
4559
|
return;
|