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.ts";
|
|
|
21
21
|
import { assertWaitToolDependencies, createToolDescriptor } from "./operation-bridge-types.ts";
|
|
22
22
|
import { requestResumeAdmission } from "./worker-waits.ts";
|
|
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 type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
26
27
|
import * as PiCodingAgent from "@earendil-works/pi-coding-agent";
|
|
@@ -82,7 +83,10 @@ import { readAppendedLines, type LogCursor } from "./log-cursor.ts";
|
|
|
82
83
|
import { DELEGATION_MODES, DELEGATION_MODE_REQUEST, isDelegationMode, normalizeDelegationMode, type DelegationMode } from "./delegation.ts";
|
|
83
84
|
import { resolveExtensions, extensionArgs } from "./extensions.ts";
|
|
84
85
|
import { prepareTaskRuntime, applyDirectApplicationLoadout, DEFAULT_TASK_PERMISSIONS, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.ts";
|
|
85
|
-
import {
|
|
86
|
+
import { worktreePolicyNotice } from "./worktree-feedback.ts";
|
|
87
|
+
import type { IsolatedWorkspace } from "./isolated-workspace.ts";
|
|
88
|
+
import type { SubagentWorkspace, SubagentWorkspaceOptions } from "./git-workspace.ts";
|
|
89
|
+
import { canonicalizePath, compileWritePolicy, describeSandboxSupport, takeRecoverySnapshot } from "./shared-sandbox-core.ts";
|
|
86
90
|
import { TASK_BUILTINS } from "./shared-task-sandbox.ts";
|
|
87
91
|
import { describeTaskTools, planTaskTools, selectEffectiveTaskTools } from "./subagent-tools.ts";
|
|
88
92
|
import {
|
|
@@ -137,6 +141,7 @@ import {
|
|
|
137
141
|
batchLaunchResult,
|
|
138
142
|
mergeJobOptions,
|
|
139
143
|
nextBatchId,
|
|
144
|
+
normalizeSessionSelector,
|
|
140
145
|
planBatchLaunches,
|
|
141
146
|
validateBatchPlan,
|
|
142
147
|
} from "./batch.mjs";
|
|
@@ -535,25 +540,28 @@ function markCompletionCallbackSuppressed(id: string, reason: string, now: numbe
|
|
|
535
540
|
// pending marker the replacing session recovers (#625), so leave it.
|
|
536
541
|
if (sessionTornDown && reason === NO_ACTIVE_SESSION_REASON) return;
|
|
537
542
|
const meta = readMeta(id);
|
|
538
|
-
if (!meta
|
|
543
|
+
if (!meta) return;
|
|
539
544
|
// An explicitly interrupted run owes its completion to the conversation that
|
|
540
545
|
// launched it (#625, DEV-226 criterion 5). An unrelated session merely being
|
|
541
546
|
// active — B opening before the original A returns — drops this delivery
|
|
542
547
|
// attempt but must keep the obligation: the pending marker stays, and A
|
|
543
548
|
// recovers it when it comes back. Records that never lost supervision keep
|
|
544
549
|
// today's durable suppression, so legacy/foreign notifications stay dead.
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
+
writeMeta(meta, { patch: current => {
|
|
551
|
+
if (current.completionCallbackSentAt !== undefined || current.completionCallbackSuppressedAt !== undefined) return;
|
|
552
|
+
if ((current.supervisionInterruptedAt !== undefined || current.operations?.resumeLaunchToken)
|
|
553
|
+
&& isConversationIdentityReason(reason)) return;
|
|
554
|
+
return { completionCallbackSuppressedAt: now, completionCallbackSuppressedReason: reason };
|
|
555
|
+
} });
|
|
550
556
|
}
|
|
551
557
|
|
|
552
558
|
function markCompletionCallbackSent(id: string, now: number): void {
|
|
553
559
|
const meta = readMeta(id);
|
|
554
|
-
if (!meta
|
|
555
|
-
meta
|
|
556
|
-
|
|
560
|
+
if (!meta) return;
|
|
561
|
+
writeMeta(meta, { patch: current =>
|
|
562
|
+
current.completionCallbackSentAt === undefined && current.completionCallbackSuppressedAt === undefined
|
|
563
|
+
? { completionCallbackSentAt: now } : undefined,
|
|
564
|
+
});
|
|
557
565
|
}
|
|
558
566
|
|
|
559
567
|
/** Queue one durable ordinary terminal event on the host-shared batch. */
|
|
@@ -966,6 +974,7 @@ let healthTicker: ReturnType<typeof setInterval> | undefined;
|
|
|
966
974
|
let managedHealthClose: (() => void) | undefined;
|
|
967
975
|
/** ExtensionAPI retained so health transitions can deliver coordinator follow-ups (#65). */
|
|
968
976
|
let healthPi: ExtensionAPI | undefined;
|
|
977
|
+
let recoverWorkerWaitsAfterExit: (() => Promise<void>) | undefined;
|
|
969
978
|
|
|
970
979
|
/**
|
|
971
980
|
* Deliver a durable, deduped coordinator follow-up for orphaned/lost (#65).
|
|
@@ -1214,10 +1223,12 @@ function stopForTiming(pi: ExtensionAPI | undefined, id: string, reason: TimingS
|
|
|
1214
1223
|
return outcome.action === "finalized";
|
|
1215
1224
|
}
|
|
1216
1225
|
const current = readMeta(id);
|
|
1217
|
-
if (current
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1226
|
+
if (current) {
|
|
1227
|
+
writeMeta(current, { patch: latest =>
|
|
1228
|
+
latest.callback !== false && latest.completionCallbackPendingAt === undefined
|
|
1229
|
+
&& latest.completionCallbackSentAt === undefined && latest.completionCallbackSuppressedAt === undefined
|
|
1230
|
+
? { completionCallbackPendingAt: now } : undefined,
|
|
1231
|
+
});
|
|
1221
1232
|
}
|
|
1222
1233
|
progressCache.delete(id);
|
|
1223
1234
|
if (current && !callbackSuppressionReason(current)) {
|
|
@@ -1374,7 +1385,11 @@ function reconcileHealth(ids?: readonly string[]): void {
|
|
|
1374
1385
|
notify: (message, level) => { try { ctx?.ui.notify(message, level); } catch { /* unavailable UI */ } },
|
|
1375
1386
|
sendMessage: () => enqueueCompletionCallback(pi, meta.id),
|
|
1376
1387
|
});
|
|
1377
|
-
if (observed.finalization?.applied) {
|
|
1388
|
+
if (observed.finalization?.applied) {
|
|
1389
|
+
void recoverWorkerWaitsAfterExit?.().catch(() => undefined);
|
|
1390
|
+
syncHealthTicker();
|
|
1391
|
+
continue;
|
|
1392
|
+
}
|
|
1378
1393
|
interruptedReconciliation = observed.reconciliation;
|
|
1379
1394
|
}
|
|
1380
1395
|
} catch { /* best-effort; the ordinary reconciliation below still runs */ }
|
|
@@ -2056,24 +2071,44 @@ function resolvePiBinary(): string {
|
|
|
2056
2071
|
return cachedPi;
|
|
2057
2072
|
}
|
|
2058
2073
|
|
|
2074
|
+
function prepareLaunchWorkspace(options: SubagentWorkspaceOptions, isolated?: IsolatedWorkspace): Promise<SubagentWorkspace> {
|
|
2075
|
+
const built = import.meta.url.endsWith(".domain.mjs");
|
|
2076
|
+
const entry = new URL("./workspace-prepare-worker.mjs", import.meta.url);
|
|
2077
|
+
return new Promise((resolve, reject) => {
|
|
2078
|
+
const worker = new Worker(entry, {
|
|
2079
|
+
workerData: { options, isolated },
|
|
2080
|
+
execArgv: built ? [] : ["--import", import.meta.resolve("tsx")],
|
|
2081
|
+
});
|
|
2082
|
+
worker.once("message", resolve);
|
|
2083
|
+
worker.once("error", reject);
|
|
2084
|
+
worker.once("exit", code => reject(new Error(`Git workspace preparation exited before reporting a result (code ${code}).`)));
|
|
2085
|
+
});
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2059
2088
|
/**
|
|
2060
2089
|
* Finalize a run once its child exits. Host-facing wrapper around the
|
|
2061
2090
|
* first-party finalizer (finalization.ts) so tests can exercise the durable
|
|
2062
2091
|
* path without importing the pi package.
|
|
2063
2092
|
*/
|
|
2064
|
-
function finalizeRun(pi: ExtensionAPI, ctx: ExtensionContext | undefined, id: string, code: number | null): void {
|
|
2093
|
+
function finalizeRun(pi: ExtensionAPI, ctx: ExtensionContext | undefined, id: string, code: number | null, recoveredWriterExit = false): void {
|
|
2065
2094
|
progressCache.delete(id);
|
|
2066
2095
|
directlySupervisedRunIds.delete(id);
|
|
2067
2096
|
// Host-facing wrapper around first-party finalizer (finalization.ts).
|
|
2068
2097
|
// Coherent child-exit evidence may supersede provisional orphaned/lost
|
|
2069
2098
|
// reconciliation; finalization.ts enforces canExitFinalize + lifecycle authority.
|
|
2070
|
-
finalizeRunCore(id, code, {
|
|
2099
|
+
const result = finalizeRunCore(id, code, {
|
|
2100
|
+
recoveredWriterExit,
|
|
2071
2101
|
renderWidget,
|
|
2072
2102
|
notify: (message, level) => {
|
|
2073
2103
|
try { ctx?.ui.notify(message, level); } catch { /* ignore */ }
|
|
2074
2104
|
},
|
|
2075
2105
|
sendMessage: () => enqueueCompletionCallback(pi, id),
|
|
2076
2106
|
});
|
|
2107
|
+
if (recoveredWriterExit && result.applied) {
|
|
2108
|
+
// The old exit callback is gone. Finish its durable wait handoff after
|
|
2109
|
+
// recovery, including the independent writer and lease proof checks.
|
|
2110
|
+
void recoverWorkerWaitsAfterExit?.().catch(() => undefined);
|
|
2111
|
+
}
|
|
2077
2112
|
syncHealthTicker();
|
|
2078
2113
|
}
|
|
2079
2114
|
|
|
@@ -2105,7 +2140,7 @@ function finalizeInterruptedRunFromLog(
|
|
|
2105
2140
|
if (!run.sawEnd || run.unmatchedToolCalls.length > 0) return false;
|
|
2106
2141
|
// Exit code is unknown after the observer is gone; the lifecycle authority
|
|
2107
2142
|
// classifies from the coherent stream instead of inventing one.
|
|
2108
|
-
finalizeRun(pi, uiCtx, meta.id, null);
|
|
2143
|
+
finalizeRun(pi, uiCtx, meta.id, null, true);
|
|
2109
2144
|
return true;
|
|
2110
2145
|
}
|
|
2111
2146
|
|
|
@@ -2329,14 +2364,16 @@ function latestConversationAttempt(sessionId: string, metas: readonly RunMeta[])
|
|
|
2329
2364
|
* missing session is the only error added here. Nothing is ever recreated.
|
|
2330
2365
|
*/
|
|
2331
2366
|
function requestedSessionId(job: { session_id?: string; session_name?: string }, cwd: string): string | undefined {
|
|
2332
|
-
|
|
2367
|
+
const sessionId = normalizeSessionSelector(job.session_id);
|
|
2368
|
+
const sessionName = normalizeSessionSelector(job.session_name);
|
|
2369
|
+
if (sessionId !== undefined && sessionName !== undefined) {
|
|
2333
2370
|
throw new Error("Pass either session_id or session_name, not both.");
|
|
2334
2371
|
}
|
|
2335
|
-
if (
|
|
2336
|
-
if (typeof
|
|
2337
|
-
return selectSessionByName(listMetas(),
|
|
2372
|
+
if (sessionName !== undefined) {
|
|
2373
|
+
if (typeof sessionName !== "string") throw new Error("session_name must be a non-empty name.");
|
|
2374
|
+
return selectSessionByName(listMetas(), sessionName, (workspace) => isWithinWorkspace(workspace, cwd));
|
|
2338
2375
|
}
|
|
2339
|
-
return
|
|
2376
|
+
return sessionId;
|
|
2340
2377
|
}
|
|
2341
2378
|
|
|
2342
2379
|
function continuationPlanFor(sessionId: string, origin: RunCallbackOrigin | undefined): ContinuationPlan {
|
|
@@ -2409,6 +2446,12 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2409
2446
|
let catalogModelRegistry: ExtensionContext["modelRegistry"] | undefined;
|
|
2410
2447
|
let delegationOverride: DelegationMode | undefined;
|
|
2411
2448
|
let capOverride: number | undefined;
|
|
2449
|
+
let workspaceOverride: "clone" | "worktree" | undefined;
|
|
2450
|
+
const activeWorkspace = () => workspaceOverride ?? (loadConfig().gitWorkspace === "worktree" ? "worktree" : "clone");
|
|
2451
|
+
const changeWorkspace = (mode: "clone" | "worktree") => {
|
|
2452
|
+
workspaceOverride = mode;
|
|
2453
|
+
pi.appendEntry("pi-better-subagents-workspace", { version: 1, mode });
|
|
2454
|
+
};
|
|
2412
2455
|
let timingOverride: { maxMinutes?: number; toolWaitMinutes?: number; stuckMinutes?: number } = {};
|
|
2413
2456
|
interface SkillSelection { mode: SkillExposureMode; paths: string[] }
|
|
2414
2457
|
let skillsOverride: SkillSelection | undefined;
|
|
@@ -2536,7 +2579,9 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2536
2579
|
capOverride = undefined;
|
|
2537
2580
|
delegationOverride = undefined;
|
|
2538
2581
|
timingOverride = {};
|
|
2582
|
+
workspaceOverride = undefined;
|
|
2539
2583
|
skillsOverride = undefined;
|
|
2584
|
+
pi.appendEntry("pi-better-subagents-workspace", { version: 1, mode: null });
|
|
2540
2585
|
pi.appendEntry("pi-better-subagents-cap", { version: 1, maxConcurrent: null });
|
|
2541
2586
|
pi.appendEntry("pi-better-subagents-delegation", { version: 1, mode: null });
|
|
2542
2587
|
pi.appendEntry("pi-better-subagents-timing", { version: 1, maxMinutes: null, toolWaitMinutes: null, stuckMinutes: null });
|
|
@@ -2629,6 +2674,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2629
2674
|
savedTiming.stuckMinutes = cfg.stuckMinutes;
|
|
2630
2675
|
}
|
|
2631
2676
|
writeSubagentSettings({
|
|
2677
|
+
...(workspaceOverride ? { gitWorkspace: workspaceOverride } : {}),
|
|
2632
2678
|
delegationMode: activeDelegationMode(),
|
|
2633
2679
|
maxConcurrent: activeConcurrencyCap(),
|
|
2634
2680
|
...savedTiming,
|
|
@@ -2669,6 +2715,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2669
2715
|
delegationOverride = undefined;
|
|
2670
2716
|
capOverride = undefined;
|
|
2671
2717
|
timingOverride = {};
|
|
2718
|
+
workspaceOverride = undefined;
|
|
2672
2719
|
skillsOverride = undefined;
|
|
2673
2720
|
const branch = ctx.sessionManager?.getBranch?.();
|
|
2674
2721
|
if (!Array.isArray(branch)) return;
|
|
@@ -2703,6 +2750,12 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2703
2750
|
}
|
|
2704
2751
|
continue;
|
|
2705
2752
|
}
|
|
2753
|
+
if (entry.type === "custom" && entry.customType === "pi-better-subagents-workspace") {
|
|
2754
|
+
const data = entry.data as { version?: number; mode?: unknown } | null;
|
|
2755
|
+
if (data?.version === 1 && (data.mode === "worktree" || data.mode === "clone" || data.mode === null)) {
|
|
2756
|
+
workspaceOverride = data.mode ?? undefined;
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2706
2759
|
if (entry.type === "custom" && entry.customType === "pi-better-subagents-timing") {
|
|
2707
2760
|
const data = entry.data as {
|
|
2708
2761
|
version?: unknown; maxMinutes?: unknown; toolWaitMinutes?: unknown; stuckMinutes?: unknown;
|
|
@@ -2728,6 +2781,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2728
2781
|
// Capture for the health ticker (module-level); needed for orphaned/lost
|
|
2729
2782
|
// coordinator follow-ups that fire outside a tool-call stack (#65).
|
|
2730
2783
|
healthPi = pi;
|
|
2784
|
+
recoverWorkerWaitsAfterExit = reconcileWorkerWaits;
|
|
2731
2785
|
ensureSubagentProvider();
|
|
2732
2786
|
registerSubagentsGoalProvider(pi);
|
|
2733
2787
|
observeSandboxPermissions(pi);
|
|
@@ -2741,12 +2795,12 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2741
2795
|
restoreDelegationMode(ctx);
|
|
2742
2796
|
await workerOperations.start();
|
|
2743
2797
|
return definition.execute(key, params, signal, onUpdate, ctx);
|
|
2744
|
-
} } : { ...definition, async execute(key, params,
|
|
2798
|
+
} } : { ...definition, async execute(key, params, signal, _onUpdate, ctx) {
|
|
2745
2799
|
ctx = captureLaunchContext(ctx);
|
|
2746
2800
|
catalogHostFrom(ctx);
|
|
2747
2801
|
const { submitManagedLaunch } = await import("./managed-launch-client.ts");
|
|
2748
2802
|
void activateWorkObservation();
|
|
2749
|
-
return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, params)) as never;
|
|
2803
|
+
return await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, params, signal)) as never;
|
|
2750
2804
|
} });
|
|
2751
2805
|
};
|
|
2752
2806
|
announceExecutionAdapter(pi, {
|
|
@@ -2836,7 +2890,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2836
2890
|
/** Skill exposure for this launch; omit to inherit catalog/config/discovery. */
|
|
2837
2891
|
skills?: readonly string[];
|
|
2838
2892
|
sandbox_dir?: string; callback?: boolean; cwd?: string;
|
|
2839
|
-
git_clone_workspace?: boolean; approve?: boolean; allow_nested?: boolean;
|
|
2893
|
+
git_clone_workspace?: boolean; isolation?: boolean; recover_in_clone?: boolean; approve?: boolean; allow_nested?: boolean;
|
|
2840
2894
|
agent?: string; role?: string | readonly string[]; alias?: string;
|
|
2841
2895
|
catalog?: CatalogRunRecord; catalogResolved?: boolean;
|
|
2842
2896
|
/**
|
|
@@ -2901,7 +2955,8 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2901
2955
|
modelNote?: string;
|
|
2902
2956
|
}> {
|
|
2903
2957
|
const { resolveChildClosure, resolveChildLaunch, configSnapshot } = await import("./child-dependencies.mjs");
|
|
2904
|
-
const { resolveSubagentWorkspace } = await import("./git-workspace.ts");
|
|
2958
|
+
const { resolveSubagentWorkspace, linkedWorktreeGitDir } = await import("./git-workspace.ts");
|
|
2959
|
+
const { workspaceChoice, restoreWorkspace, discardWorkspace, markWorkspaceWriter } = await import("./isolated-workspace.ts");
|
|
2905
2960
|
const { PREFLIGHT_ENV } = await import("./child-preflight.mjs");
|
|
2906
2961
|
assertThinkingLevel(p.thinking);
|
|
2907
2962
|
// Skill exposure is a caller choice, not a launch: validate its shape
|
|
@@ -2923,6 +2978,16 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2923
2978
|
// moving a live conversation into a different sandbox.
|
|
2924
2979
|
const permissionPlan = resolveSubagentPermissions(pi, p.sandbox,
|
|
2925
2980
|
resume && { runId: resume.prior.id, sandbox: resume.recipe.sandbox });
|
|
2981
|
+
if (permissionPlan.sandboxEnabled) {
|
|
2982
|
+
const support = describeSandboxSupport();
|
|
2983
|
+
if (!support.supported) {
|
|
2984
|
+
const remedy = permissionPlan.permissions
|
|
2985
|
+
? "Turn off the Subagents sandbox in /sandbox settings to run without confinement."
|
|
2986
|
+
: resume ? "Launch a new subagent with sandbox:false to run without confinement."
|
|
2987
|
+
: "Pass sandbox:false to run without confinement.";
|
|
2988
|
+
throw new Error(`Task sandbox unavailable: ${support.reason} ${remedy}`);
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2926
2991
|
const processPolicy = describeSubagentProcessPolicy(permissionPlan, process.platform);
|
|
2927
2992
|
const processAccess = effectiveWorkerProcessAccess(permissionPlan);
|
|
2928
2993
|
const taskPermissions = permissionPlan.inactiveProfile
|
|
@@ -2993,7 +3058,38 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2993
3058
|
// The disposable clone this launch owns (removed if the spawn fails); a caller's sandbox_dir is not ours.
|
|
2994
3059
|
// A continuation never prepares another clone: the recipe's workspace already
|
|
2995
3060
|
// holds the prior attempt's uncommitted work.
|
|
2996
|
-
|
|
3061
|
+
if (p.isolation === false && p.git_clone_workspace) throw new Error("Choose either live checkout or git_clone_workspace.");
|
|
3062
|
+
if (p.recover_in_clone && (!resume || resume.recipe.workspace?.mode !== "worktree" || internal?.resumeWait)) {
|
|
3063
|
+
throw new Error("Clone handoff requires an explicit continuation of a linked worktree.");
|
|
3064
|
+
}
|
|
3065
|
+
if (resume && p.isolation !== undefined && Boolean(resume.recipe.workspace || resume.recipe.gitCloneWorkspace) !== p.isolation) {
|
|
3066
|
+
throw new ContinuationError("Changing isolation would replace the saved workspace.");
|
|
3067
|
+
}
|
|
3068
|
+
const handoffAuthority = p.recover_in_clone ? resume?.recipe.workspaceAuthority : undefined;
|
|
3069
|
+
if (p.recover_in_clone && resume) {
|
|
3070
|
+
const previous = handoffAuthority?.sandbox;
|
|
3071
|
+
const permissions = taskPermissions ?? DEFAULT_TASK_PERMISSIONS;
|
|
3072
|
+
assertAssignmentPermissionScope(handoffAuthority, {
|
|
3073
|
+
mandatoryPermissions: permissionPlan.enforced,
|
|
3074
|
+
sandbox: sandboxEnabled ? {
|
|
3075
|
+
root: resume.recipe.sandboxDir,
|
|
3076
|
+
denyWrite: previous?.denyWrite ?? [],
|
|
3077
|
+
permissions: {
|
|
3078
|
+
...DEFAULT_TASK_PERMISSIONS, ...permissions, ...resolveCommandSettings(permissions),
|
|
3079
|
+
processAccess: permissions.processAccess ?? "off",
|
|
3080
|
+
},
|
|
3081
|
+
} : null,
|
|
3082
|
+
});
|
|
3083
|
+
}
|
|
3084
|
+
const selected = normalizeTools(p.tools ?? cfg.defaultTools ?? (p.clean ? SAFE_CLEAN_TOOLS : SAFE_DEFAULT_TOOLS));
|
|
3085
|
+
let isolated = resume?.recipe.workspace;
|
|
3086
|
+
if (!resume && !p.sandbox_dir && p.isolation !== false) {
|
|
3087
|
+
isolated = workspaceChoice(
|
|
3088
|
+
p.cwd ?? ctx.cwd, id, p.git_clone_workspace ? "clone" : activeWorkspace(),
|
|
3089
|
+
p.git_clone_workspace ? "write" : selected, p.git_clone_workspace ? "" : p.exclude_tools ?? "",
|
|
3090
|
+
);
|
|
3091
|
+
}
|
|
3092
|
+
const ownedCloneWorkspace = !resume && !p.sandbox_dir && (isolated || p.git_clone_workspace) ? taskWorkspaceDir(id) : undefined;
|
|
2997
3093
|
// A launch attempt only becomes a run when `writeMeta` commits. Until
|
|
2998
3094
|
// then everything it creates (prompt, control/, provenance, its own
|
|
2999
3095
|
// session dir, clone workspace, task scratch) belongs to the attempt and
|
|
@@ -3003,6 +3099,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3003
3099
|
let spawned: ReturnType<typeof spawnDetached> | undefined;
|
|
3004
3100
|
let launchScratch: string | undefined;
|
|
3005
3101
|
let committed = false;
|
|
3102
|
+
let createdWorkspace = false;
|
|
3006
3103
|
try {
|
|
3007
3104
|
if (!resume) mkdirSync(childSessionDir, { recursive: true });
|
|
3008
3105
|
mkdirSync(runDir(id), { recursive: true });
|
|
@@ -3012,17 +3109,31 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3012
3109
|
// (#623 R1). The outer catch drops the whole directory on failure.
|
|
3013
3110
|
recordLaunchAttempt(id);
|
|
3014
3111
|
|
|
3112
|
+
// Cleanup, restoration and the actual writer share the conversation lease.
|
|
3113
|
+
if (resume || managed) lease = acquireConversationLease({ sessionId, attemptId: id });
|
|
3114
|
+
if (resume) {
|
|
3115
|
+
revalidateContinuationUnderLease(resume, callbackOrigin);
|
|
3116
|
+
if (isolated) isolated = restoreWorkspace(isolated, p.recover_in_clone, resume.prior.id);
|
|
3117
|
+
}
|
|
3118
|
+
if (!resume && isolated) {
|
|
3119
|
+
const root = taskWorkspaceDir(id);
|
|
3120
|
+
mkdirSync(dirname(root), { recursive: true });
|
|
3121
|
+
mkdirSync(root, { mode: 0o700 });
|
|
3122
|
+
createdWorkspace = true;
|
|
3123
|
+
}
|
|
3124
|
+
const workspaceOptions = {
|
|
3125
|
+
ctxCwd: ctx.cwd, cwd: p.cwd, sandboxDir: p.sandbox_dir ?? ownedCloneWorkspace,
|
|
3126
|
+
gitCloneWorkspace: p.git_clone_workspace, runId: id, runDirPath: runDir(id), sandboxEnabled,
|
|
3127
|
+
};
|
|
3015
3128
|
const workspace = resume
|
|
3016
3129
|
? { cwd: resume.recipe.cwd, requestedSandboxDir: resume.recipe.sandboxDir }
|
|
3017
|
-
:
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
sandboxEnabled,
|
|
3025
|
-
});
|
|
3130
|
+
: isolated || p.git_clone_workspace
|
|
3131
|
+
? await prepareLaunchWorkspace(workspaceOptions, p.git_clone_workspace ? undefined : isolated)
|
|
3132
|
+
: resolveSubagentWorkspace(workspaceOptions);
|
|
3133
|
+
// Legacy explicit clones launch at the repository root, even when the source is a subdirectory.
|
|
3134
|
+
if (!resume && isolated && p.git_clone_workspace) isolated = { ...isolated, subdir: "" };
|
|
3135
|
+
let workspaceNote = isolated ? `Git workspace: ${isolated.mode} at ${workspace.cwd}. Base ${isolated.base}.`
|
|
3136
|
+
+ (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." : "") : "";
|
|
3026
3137
|
const cwd = workspace.cwd;
|
|
3027
3138
|
const requestedSandboxDir = workspace.requestedSandboxDir;
|
|
3028
3139
|
|
|
@@ -3049,7 +3160,8 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3049
3160
|
});
|
|
3050
3161
|
|
|
3051
3162
|
if (requestedSandboxDir) mkdirSync(requestedSandboxDir, { recursive: true });
|
|
3052
|
-
|
|
3163
|
+
const workerPrompt = workspaceNote ? workspaceNote + "\n\n" + p.prompt : p.prompt;
|
|
3164
|
+
writeFileSync(promptPathFor(id), workerPrompt);
|
|
3053
3165
|
|
|
3054
3166
|
// A continuation keeps the recipe's launch intent; only current
|
|
3055
3167
|
// permission-driven adjustments are re-derived from it.
|
|
@@ -3058,7 +3170,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3058
3170
|
const clean = resume ? resume.recipe.clean : p.clean === true;
|
|
3059
3171
|
const allowNested = resume ? resume.recipe.allowNested : p.allow_nested === true;
|
|
3060
3172
|
const approve = resume ? resume.recipe.approve : p.approve === true;
|
|
3061
|
-
const gitCloneWorkspace = resume ? resume.recipe.gitCloneWorkspace : p.git_clone_workspace === true;
|
|
3173
|
+
const gitCloneWorkspace = isolated ? isolated.mode === "clone" : resume ? resume.recipe.gitCloneWorkspace : p.git_clone_workspace === true;
|
|
3062
3174
|
const callbackEnabled = resume ? p.callback ?? resume.recipe.callback : p.callback !== false;
|
|
3063
3175
|
const launchName = resume ? resume.recipe.name : p.name;
|
|
3064
3176
|
// The frozen launch snapshot is the same shape a fresh spawn freezes.
|
|
@@ -3294,7 +3406,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3294
3406
|
...(allow && !sandboxEnabled ? ["--tools", allow] : []),
|
|
3295
3407
|
...(excludes.size ? ["--exclude-tools", [...excludes].join(",")] : []),
|
|
3296
3408
|
...(sandboxEnabled ? ["--no-builtin-tools", "--no-approve"] : approve ? ["--approve"] : []),
|
|
3297
|
-
|
|
3409
|
+
workerPrompt,
|
|
3298
3410
|
];
|
|
3299
3411
|
|
|
3300
3412
|
const selectedTools = allow.split(",").filter((name) => name && !excludes.has(name));
|
|
@@ -3302,7 +3414,9 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3302
3414
|
const optionalTrustedTools = taskTools?.trusted.filter(({ name }) => selectedTools.includes(name)
|
|
3303
3415
|
&& (inheritedTrusted ? inheritedTrusted.has(name) : requestedTools === undefined)).map(({ name }) => name) ?? [];
|
|
3304
3416
|
const dropped = toolSelection?.dropped ?? [];
|
|
3417
|
+
const sharedGitDir = sandboxEnabled && isolated?.mode !== "clone" ? linkedWorktreeGitDir(cwd) : undefined;
|
|
3305
3418
|
const taskRuntime = sandboxEnabled && requestedSandboxDir ? prepareTaskRuntime({
|
|
3419
|
+
worktreeGitDir: isolated?.mode === "worktree" ? sharedGitDir : undefined,
|
|
3306
3420
|
root: requestedSandboxDir, controlDir: join(runDir(id), "control"),
|
|
3307
3421
|
tools: selectedTools,
|
|
3308
3422
|
permissions: taskPermissions && { ...taskPermissions, ...commandSettings },
|
|
@@ -3319,8 +3433,21 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3319
3433
|
runtimeRoots: [baseDir()],
|
|
3320
3434
|
capturedDenyWrite: internal?.resumeWait
|
|
3321
3435
|
? (resume?.prior.operations?.policy.sandbox as WorkerSandboxAuthority | null)?.denyWrite
|
|
3322
|
-
:
|
|
3436
|
+
: handoffAuthority?.sandbox?.denyWrite,
|
|
3323
3437
|
}) : undefined;
|
|
3438
|
+
if (taskRuntime && sharedGitDir) {
|
|
3439
|
+
const policy = taskRuntime.policy;
|
|
3440
|
+
const notice = worktreePolicyNotice(sharedGitDir, compileWritePolicy({
|
|
3441
|
+
writableRoot: policy.root, home: policy.home, permissions: policy.permissions,
|
|
3442
|
+
denyWrite: policy.denyWrite, runtimeCompatibility: true, runtimeWrite: [policy.scratch],
|
|
3443
|
+
}));
|
|
3444
|
+
if (notice) {
|
|
3445
|
+
workspaceNote = isolated?.mode === "worktree" ? `${workspaceNote} ${notice}`
|
|
3446
|
+
: `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.`;
|
|
3447
|
+
args[args.length - 1] = workspaceNote + "\n\n" + p.prompt;
|
|
3448
|
+
writeFileSync(promptPathFor(id), args[args.length - 1]!);
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3324
3451
|
launchScratch = taskRuntime?.policy.scratch;
|
|
3325
3452
|
if (sandboxEnabled && !taskRuntime) throw new Error("Task sandbox has no workspace; refusing an unconfined child.");
|
|
3326
3453
|
// Parent-authored trust record, written before the child can run (#325).
|
|
@@ -3349,18 +3476,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3349
3476
|
if (countRunning() >= maxConcurrent) {
|
|
3350
3477
|
throw new Error(`Max concurrent subagents (${maxConcurrent}) reached. Stop or let some finish first.`);
|
|
3351
3478
|
}
|
|
3352
|
-
//
|
|
3353
|
-
// and finalization. A live duplicate continuation is refused instead of
|
|
3354
|
-
// letting two processes rewrite one session file. A fresh launch has a
|
|
3355
|
-
// brand-new native session id, so it cannot contend with anyone and
|
|
3356
|
-
// needs no lease; every continuation does.
|
|
3357
|
-
if (resume || managed) {
|
|
3358
|
-
lease = acquireConversationLease({ sessionId, attemptId: id });
|
|
3359
|
-
}
|
|
3360
|
-
// The lease is the first moment no other process can retire this
|
|
3361
|
-
// conversation: re-prove the history identity the cached plan was
|
|
3362
|
-
// built from, so `--session` can never reopen a file another sweep
|
|
3363
|
-
// removed as an empty replacement.
|
|
3479
|
+
// Recheck the saved conversation after asynchronous launch preparation.
|
|
3364
3480
|
if (resume) revalidateContinuationUnderLease(resume, callbackOrigin);
|
|
3365
3481
|
const preflightPath = join(runDir(id), "child-preflight.json");
|
|
3366
3482
|
writeFileSync(preflightPath, JSON.stringify({ ...fullResolution, model, tools: selectedTools,
|
|
@@ -3434,18 +3550,21 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3434
3550
|
// cannot hide inside a final asynchronous window.
|
|
3435
3551
|
if (internal?.resumeWait && !resume?.prior.assignment) throw new PreSpawnResumeError("This legacy park has no verified assignment outcome recipient; refusing continuation on an unsupported binding.");
|
|
3436
3552
|
if (!assignment && bridgeEnabled) throw new Error("Durable assignment outcomes require a recorded parent session and transcript capability.");
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3553
|
+
const workspaceAuthority = {
|
|
3554
|
+
mandatoryPermissions: permissionPlan.enforced,
|
|
3555
|
+
sandbox: taskRuntime ? {
|
|
3440
3556
|
root: taskRuntime.policy.root,
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
} : null
|
|
3444
|
-
|
|
3557
|
+
permissions: taskRuntime.policy.permissions,
|
|
3558
|
+
denyWrite: [...taskRuntime.policy.denyWrite],
|
|
3559
|
+
} : null,
|
|
3560
|
+
};
|
|
3561
|
+
if (internal?.resumeWait) {
|
|
3562
|
+
assertAssignmentPermissionScope(resume?.prior.operations?.policy, workspaceAuthority, Boolean(managed));
|
|
3445
3563
|
}
|
|
3446
3564
|
// Freeze the ordinary recipe before the durable external-launch intent.
|
|
3447
3565
|
const recipe = buildLaunchRecipe({
|
|
3448
3566
|
...(!legacyToolLoading ? { toolLoadingVersion: 1 as const } : {}),
|
|
3567
|
+
...(isolated ? { workspace: isolated, workspaceAuthority } : {}),
|
|
3449
3568
|
attemptId: id, sessionId, sessionDir: childSessionDir, cwd, model, effort: thinking,
|
|
3450
3569
|
tools: callerLaunchTools(allow), excludeTools: requestedExcludes.size ? [...requestedExcludes].join(",") : undefined,
|
|
3451
3570
|
...(optionalTrustedTools.length ? { optionalTrustedTools } : {}),
|
|
@@ -3509,6 +3628,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3509
3628
|
timing: resolveRunTiming({ params: launchTimingParams(p), settings: timingSettingsFor(cfg), env: process.env, startedAt }),
|
|
3510
3629
|
};
|
|
3511
3630
|
const dispatchGuard = await internal?.beforeSpawn?.({ runId: id, permissionPlan });
|
|
3631
|
+
if (isolated) markWorkspaceWriter(isolated,id);
|
|
3512
3632
|
const managedEnv = managed?.beforeSpawn({ id, sessionId, lease: lease!.token, leasePath: lease!.path,
|
|
3513
3633
|
preflightPath, policyPath: taskRuntime?.policyPath, permissions: permissionPlan, recipe, recoveryMeta: meta });
|
|
3514
3634
|
spawned = releaseChild(dispatchGuard, () => spawnDetached({ file: cmd.file, fileArgs: cmd.fileArgs, cwd, logPath: logPathFor(id),
|
|
@@ -3580,7 +3700,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3580
3700
|
: resolution.specs.length
|
|
3581
3701
|
? `Runtime: isolated · extensions ${resolution.specs.join(", ")}\n`
|
|
3582
3702
|
: `Runtime: isolated · built-in tools only\n`;
|
|
3583
|
-
const warn = (dropped.length ? `Task sandbox: ${dropped.map((tool) => `${tool.name} disabled (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join("; ")}.\n` : "") +
|
|
3703
|
+
const warn = (workspaceNote ? workspaceNote + "\n" : "") + (dropped.length ? `Task sandbox: ${dropped.map((tool) => `${tool.name} disabled (${withheldBridgeReasons.get(tool.name) ?? tool.reason})`).join("; ")}.\n` : "") +
|
|
3584
3704
|
(!sandboxEnabled && resolution.unmapped.length
|
|
3585
3705
|
? `NOTE: no extension mapped for ${resolution.unmapped.join(", ")} — ` +
|
|
3586
3706
|
`${resolution.unmapped.length > 1 ? "these tools" : "this tool"} will NOT exist in the child. ` +
|
|
@@ -3605,8 +3725,9 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3605
3725
|
const { abortUncommittedLaunch } = await import("./launch-abort.ts");
|
|
3606
3726
|
await abortUncommittedLaunch(id, {
|
|
3607
3727
|
child: spawned, lease,
|
|
3608
|
-
artifacts: { sessionDir: childSessionDir, workspaceDir: ownedCloneWorkspace, scratch: launchScratch },
|
|
3728
|
+
artifacts: { sessionDir: childSessionDir, workspaceDir: isolated ? undefined : ownedCloneWorkspace, scratch: launchScratch },
|
|
3609
3729
|
});
|
|
3730
|
+
if (createdWorkspace && isolated) discardWorkspace(isolated);
|
|
3610
3731
|
}
|
|
3611
3732
|
throw error;
|
|
3612
3733
|
}
|
|
@@ -3827,11 +3948,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3827
3948
|
service.registerContinuationAdapter(orchestration.adapter);
|
|
3828
3949
|
} catch { /* a host that refuses the adapter leaves parking unavailable */ }
|
|
3829
3950
|
try {
|
|
3830
|
-
const reconciliation =
|
|
3831
|
-
resume: (park) => orchestration.resume(park),
|
|
3832
|
-
notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
|
|
3833
|
-
notify: notifyOwnedWait,
|
|
3834
|
-
});
|
|
3951
|
+
const reconciliation = reconcileWorkerWaits();
|
|
3835
3952
|
if (managed) {
|
|
3836
3953
|
void reconciliation.catch(() => undefined);
|
|
3837
3954
|
return;
|
|
@@ -3844,6 +3961,17 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3844
3961
|
} catch { /* reconciliation retries on the next session start */ }
|
|
3845
3962
|
}
|
|
3846
3963
|
|
|
3964
|
+
async function reconcileWorkerWaits(): Promise<void> {
|
|
3965
|
+
const service = workerOperations.service;
|
|
3966
|
+
if (!service) return;
|
|
3967
|
+
const orchestration = ensureResumeOrchestration();
|
|
3968
|
+
await reconcileParkedWaits(service, {
|
|
3969
|
+
resume: (park) => orchestration.resume(park),
|
|
3970
|
+
notifyWhen: (meta) => Boolean(activeCallbackOrigin && belongsToOrigin(meta, activeCallbackOrigin)),
|
|
3971
|
+
notify: notifyOwnedWait,
|
|
3972
|
+
});
|
|
3973
|
+
}
|
|
3974
|
+
|
|
3847
3975
|
// ---- subagent_spawn -------------------------------------------------
|
|
3848
3976
|
//
|
|
3849
3977
|
// One tool launches both fresh work and a continuation of saved work. A
|
|
@@ -3871,7 +3999,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3871
3999
|
...CATALOG_GUIDELINES,
|
|
3872
4000
|
"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.",
|
|
3873
4001
|
"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.",
|
|
3874
|
-
"
|
|
4002
|
+
"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.",
|
|
3875
4003
|
"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.",
|
|
3876
4004
|
"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.",
|
|
3877
4005
|
"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.",
|
|
@@ -3894,6 +4022,8 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3894
4022
|
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." })),
|
|
3895
4023
|
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." })),
|
|
3896
4024
|
cwd: Type.Optional(Type.String({ description: "Working directory (default: current)." })),
|
|
4025
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
4026
|
+
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." })),
|
|
3897
4027
|
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." })),
|
|
3898
4028
|
approve: Type.Optional(Type.Boolean({ description: "Trust project-local files in the child (default: false; headless runs cannot prompt for trust)." })),
|
|
3899
4029
|
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." })),
|
|
@@ -3937,6 +4067,8 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3937
4067
|
model: p.model,
|
|
3938
4068
|
thinking: p.thinking,
|
|
3939
4069
|
callback: p.callback,
|
|
4070
|
+
isolation: p.isolation,
|
|
4071
|
+
recover_in_clone: p.recover_in_clone,
|
|
3940
4072
|
deadline_minutes: p.deadline_minutes,
|
|
3941
4073
|
grace_minutes: p.grace_minutes,
|
|
3942
4074
|
max_minutes: p.max_minutes,
|
|
@@ -4064,6 +4196,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4064
4196
|
callback: Type.Optional(Type.Boolean({ description: "Default TRUE: post result back on completion." })),
|
|
4065
4197
|
clean: Type.Optional(Type.Boolean({ description: "Hermetic builtins-only child; no extensions load." })),
|
|
4066
4198
|
cwd: Type.Optional(Type.String({ description: "Working directory (default: current)." })),
|
|
4199
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
4067
4200
|
git_clone_workspace: Type.Optional(Type.Boolean({ description: "Prepare a disposable Git clone workspace for each job (same semantics as subagent_spawn)." })),
|
|
4068
4201
|
approve: Type.Optional(Type.Boolean({ description: "Trust project-local files in children." })),
|
|
4069
4202
|
allow_nested: Type.Optional(Type.Boolean({ description: "Allow children to spawn their own subagents." })),
|
|
@@ -4087,6 +4220,8 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4087
4220
|
callback: Type.Optional(Type.Boolean()),
|
|
4088
4221
|
clean: Type.Optional(Type.Boolean()),
|
|
4089
4222
|
cwd: Type.Optional(Type.String()),
|
|
4223
|
+
isolation: Type.Optional(Type.Boolean({ description: "Use false to work in the live checkout. By default each Git writer gets its own workspace." })),
|
|
4224
|
+
recover_in_clone: Type.Optional(Type.Boolean({ description: "Continue this job in a verified Clone." })),
|
|
4090
4225
|
git_clone_workspace: Type.Optional(Type.Boolean()),
|
|
4091
4226
|
approve: Type.Optional(Type.Boolean()),
|
|
4092
4227
|
allow_nested: Type.Optional(Type.Boolean()),
|
|
@@ -4129,8 +4264,10 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4129
4264
|
|
|
4130
4265
|
let catalogSnapshot: CatalogSnapshot | undefined;
|
|
4131
4266
|
let catalogHost: CatalogHost | undefined;
|
|
4132
|
-
const needsCatalog = p.jobs.some((job) =>
|
|
4133
|
-
|
|
4267
|
+
const needsCatalog = p.jobs.some((job) => {
|
|
4268
|
+
const merged = mergeJobOptions(p.shared, job);
|
|
4269
|
+
return merged.session_id === undefined && merged.session_name === undefined && hasCatalogSelector(merged);
|
|
4270
|
+
});
|
|
4134
4271
|
if (needsCatalog) {
|
|
4135
4272
|
catalogHost = catalogHostFrom(ctx);
|
|
4136
4273
|
noteCatalogHost(catalogHost);
|
|
@@ -4192,7 +4329,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4192
4329
|
const job = p.jobs[i];
|
|
4193
4330
|
let name = names[i];
|
|
4194
4331
|
const merged = mergeJobOptions(p.shared, job);
|
|
4195
|
-
const isContinuation =
|
|
4332
|
+
const isContinuation = merged.session_id !== undefined || merged.session_name !== undefined;
|
|
4196
4333
|
// A continuation keeps its own frozen model and effort. shared.model
|
|
4197
4334
|
// is a default for NEW conversations, so only a per-job value is an
|
|
4198
4335
|
// explicit escalation of the saved recipe.
|
|
@@ -4210,7 +4347,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4210
4347
|
}
|
|
4211
4348
|
|
|
4212
4349
|
try {
|
|
4213
|
-
const sessionId = requestedSessionId(
|
|
4350
|
+
const sessionId = requestedSessionId(merged, ctx.cwd);
|
|
4214
4351
|
// A saved conversation is never re-resolved against the catalog.
|
|
4215
4352
|
if (sessionId === undefined && catalogSnapshot && catalogHost && hasCatalogSelector(merged)) {
|
|
4216
4353
|
const explicitName = typeof job.name === "string" && job.name.trim() !== "" ? job.name : undefined;
|
|
@@ -4387,6 +4524,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4387
4524
|
const timing = timingState();
|
|
4388
4525
|
return {
|
|
4389
4526
|
mode: settings.delegationMode, maxConcurrent: settings.maxConcurrent,
|
|
4527
|
+
gitWorkspace: activeWorkspace(),
|
|
4390
4528
|
maxMinutes: timing.maxMinutes,
|
|
4391
4529
|
modeSource: settings.sources.delegationMode,
|
|
4392
4530
|
capSource: settings.sources.maxConcurrent,
|
|
@@ -4402,7 +4540,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4402
4540
|
skillsError: skills.error,
|
|
4403
4541
|
};
|
|
4404
4542
|
},
|
|
4405
|
-
changeMode, changeCap, changeTiming, changeSkills, save: saveSettings, reset: resetSettings,
|
|
4543
|
+
changeMode, changeWorkspace, changeCap, changeTiming, changeSkills, save: saveSettings, reset: resetSettings,
|
|
4406
4544
|
discoverSkills: () => discoveredSkillsFromContext(ctx),
|
|
4407
4545
|
// Close this page first; the catalog opens after ui.custom resolves.
|
|
4408
4546
|
openAgents: () => done("agents"),
|
|
@@ -4414,7 +4552,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4414
4552
|
: skills.mode === "none" ? "no skills" : `${skills.paths.length} selected skills`;
|
|
4415
4553
|
const timing = timingState();
|
|
4416
4554
|
ctx.ui.notify(`Delegation mode: ${activeDelegationMode()}. Concurrent subagents: ${activeConcurrencyCap()}. ` +
|
|
4417
|
-
`
|
|
4555
|
+
`Run timeout: ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "No limit"}. Tool-wait alert: ${timing.toolWaitMinutes} min. ` +
|
|
4418
4556
|
`No-progress alert: ${timing.stuckMinutes} min. Skills: ${skillChoice}. ` +
|
|
4419
4557
|
`Use /subagents mode <mode>, cap <number>, tool-wait <minutes>, stuck <minutes>, or settings; /subagents save persists them.`, "info");
|
|
4420
4558
|
}
|
|
@@ -4500,7 +4638,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4500
4638
|
const timing = timingState();
|
|
4501
4639
|
if (ctx.hasUI && !(await ctx.ui.confirm("Save subagent defaults?",
|
|
4502
4640
|
`Future sessions will start in ${activeDelegationMode()} with a cap of ${activeConcurrencyCap()}, ` +
|
|
4503
|
-
`timeout ${timing.maxMinutes
|
|
4641
|
+
`run timeout ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "No limit"}, tool-wait alert ${timing.toolWaitMinutes} min, ` +
|
|
4504
4642
|
`no-progress alert ${timing.stuckMinutes} min, and ${skillChoice}.`))) {
|
|
4505
4643
|
ctx.ui.notify("Subagent defaults unchanged.", "info");
|
|
4506
4644
|
return;
|