pi-better-server 0.7.1 → 0.7.3
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 +1 -1
- package/src/runtime/background-tools.ts +2 -1
- package/src/runtime/domain/background/registry.mjs +3 -0
- package/src/runtime/domain/background/shared-operation-coordinator/src/task-lifetime.mjs +6 -0
- package/src/runtime/domain/background/terminal-publication.mjs +5 -2
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +13 -0
- package/src/runtime/domain/background-service/managed-authority.ts +16 -0
- package/src/runtime/domain/background-service/managed-client.domain.mjs +2 -2
- package/src/runtime/domain/background-service/managed-client.ts +2 -2
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +8 -4
- package/src/runtime/domain/background-service/observed-waits.ts +8 -4
- package/src/runtime/domain/background-service/registry.domain.mjs +3 -0
- package/src/runtime/domain/background-service/registry.ts +2 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +3 -2
- package/src/runtime/domain/background-service/runtime.ts +3 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/expiry.domain.mjs +44 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/expiry.ts +44 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +8 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +3 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +5 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-lifetime.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-lifetime.ts +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +22 -13
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +40 -32
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +12 -19
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +12 -16
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +12 -7
- package/src/runtime/domain/background-service/supervisor/generated/task-lifetime.mjs +9 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +12 -7
- package/src/runtime/domain/background-service/supervisor/runner.ts +12 -7
- package/src/runtime/domain/background-service/supervisor/types.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +3 -2
- package/src/runtime/domain/background-service/tools.ts +3 -2
- package/src/runtime/domain/coordinator/src/expiry.mjs +43 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +8 -1
- package/src/runtime/domain/coordinator/src/store.mjs +3 -0
- package/src/runtime/domain/coordinator/src/task-lifetime.mjs +6 -0
- package/src/runtime/domain/coordinator/src/waits.mjs +22 -13
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +12 -19
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +12 -16
- package/src/runtime/domain/subagents/README.md +2 -2
- package/src/runtime/domain/subagents/cleanup.domain.mjs +5 -2
- package/src/runtime/domain/subagents/cleanup.ts +4 -1
- package/src/runtime/domain/subagents/index.domain.mjs +47 -29
- package/src/runtime/domain/subagents/index.ts +46 -27
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +28 -2
- package/src/runtime/domain/subagents/managed-launch-host.ts +26 -2
- package/src/runtime/domain/subagents/managed-launch-port.ts +2 -0
- package/src/runtime/domain/subagents/output-payload.domain.mjs +3 -1
- package/src/runtime/domain/subagents/output-payload.ts +2 -0
- package/src/runtime/domain/subagents/package.json +1 -1
- package/src/runtime/domain/subagents/registry-cleanup-worker.mjs +24 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +33 -7
- package/src/runtime/domain/subagents/registry.ts +18 -4
- package/src/runtime/domain/subagents/settings-page.domain.mjs +10 -10
- package/src/runtime/domain/subagents/settings-page.ts +10 -10
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/expiry.domain.mjs +44 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/expiry.ts +44 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +8 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +3 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +5 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-lifetime.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-lifetime.ts +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +22 -13
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +40 -32
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +12 -19
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +12 -16
- package/src/runtime/domain/subagents/stop.domain.mjs +7 -5
- package/src/runtime/domain/subagents/stop.ts +7 -5
- package/src/runtime/domain/subagents/timing.domain.mjs +7 -3
- package/src/runtime/domain/subagents/timing.ts +11 -4
- package/src/runtime/domain/subagents/tools.domain.mjs +3 -2
- package/src/runtime/domain/subagents/tools.ts +3 -2
- package/src/runtime/domain/subagents/workflow-assignment.domain.mjs +25 -0
- package/src/runtime/domain/subagents/workflow-assignment.ts +35 -0
- package/src/runtime/domain/subagents/workspace-files.domain.mjs +6 -6
- package/src/runtime/domain/subagents/workspace-files.ts +6 -6
- package/src/runtime/query-executor.ts +11 -2
- package/src/runtime/task-expiry.ts +52 -0
- package/src/server.ts +4 -0
- package/src/version.ts +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.ts";
|
|
1
2
|
import { shouldRestoreWorkObservation } from "./shared-work-client.mjs";
|
|
2
3
|
import { appendTimingWake, removeTimingReceipt, receiptTimingWake, timingWakeReceipt } from "./timing-notifications.ts";
|
|
3
4
|
import { captureLaunchContext } from "./launch-context.ts";
|
|
@@ -58,6 +59,7 @@ import { deliverSubagentPrompt, effectiveSubagentSettings, formatSubagentSetting
|
|
|
58
59
|
import { STEER_FILE_ENV, readSteerReceipt } from "./child-steer.ts";
|
|
59
60
|
import {
|
|
60
61
|
continuationTimingParams,
|
|
62
|
+
configuredMaxMinutes,
|
|
61
63
|
decideTiming,
|
|
62
64
|
describeTiming,
|
|
63
65
|
DEFAULT_TIMING_MINUTES,
|
|
@@ -80,6 +82,7 @@ import {
|
|
|
80
82
|
type TimingStopReason,
|
|
81
83
|
} from "./timing.ts";
|
|
82
84
|
import { readAppendedLines, type LogCursor } from "./log-cursor.ts";
|
|
85
|
+
import { launchWorkflowAssignment } from "./workflow-assignment.ts";
|
|
83
86
|
import { DELEGATION_MODES, DELEGATION_MODE_REQUEST, isDelegationMode, normalizeDelegationMode, type DelegationMode } from "./delegation.ts";
|
|
84
87
|
import { resolveExtensions, extensionArgs } from "./extensions.ts";
|
|
85
88
|
import { prepareTaskRuntime, applyDirectApplicationLoadout, DEFAULT_TASK_PERMISSIONS, RUN_APPLICATION, SDK_BUILTIN_TOOLS } from "./task-policy.ts";
|
|
@@ -1246,7 +1249,11 @@ function stopForTiming(pi: ExtensionAPI | undefined, id: string, reason: TimingS
|
|
|
1246
1249
|
*/
|
|
1247
1250
|
function enforceTiming(pi: ExtensionAPI | undefined, meta: RunMeta, now: number): boolean {
|
|
1248
1251
|
const timing = meta.timing;
|
|
1249
|
-
if (!timing
|
|
1252
|
+
if (!timing) return false;
|
|
1253
|
+
if ((meta.status === "running" || meta.status === "orphaned") && now >= (timing.lifetimeAt ?? taskDeadline(meta.startedAt))) {
|
|
1254
|
+
return stopForTiming(pi, meta.id, "ceiling", now);
|
|
1255
|
+
}
|
|
1256
|
+
if (timing.stopReason) return false;
|
|
1250
1257
|
// The ceiling also bounds an orphaned run (child gone, its process group still alive).
|
|
1251
1258
|
if (meta.status === "orphaned") {
|
|
1252
1259
|
return timing.ceilingAt !== undefined && now >= timing.ceilingAt ? stopForTiming(pi, meta.id, "ceiling", now) : false;
|
|
@@ -1711,10 +1718,7 @@ function navigatorCloseRun(id: string) {
|
|
|
1711
1718
|
});
|
|
1712
1719
|
if (outcome.action === "dismissed" || outcome.action === "stopped-and-dismissed") pendingNavigatorDismissals.add(id);
|
|
1713
1720
|
// A closed row is off the hot path: release its caches and retained events.
|
|
1714
|
-
|
|
1715
|
-
healthLogCache.delete(id);
|
|
1716
|
-
resetChildEventLogCursor(id);
|
|
1717
|
-
resetParseRunCursor(id);
|
|
1721
|
+
forgetRunCaches(id);
|
|
1718
1722
|
syncHealthTicker();
|
|
1719
1723
|
// Close stops (or log-finalizes) the run, which is a terminal transition:
|
|
1720
1724
|
// queue its one completion callback so no terminal state is silent (#624).
|
|
@@ -2071,6 +2075,13 @@ function resolvePiBinary(): string {
|
|
|
2071
2075
|
return cachedPi;
|
|
2072
2076
|
}
|
|
2073
2077
|
|
|
2078
|
+
function forgetRunCaches(id: string): void {
|
|
2079
|
+
spendCache.delete(id);
|
|
2080
|
+
healthLogCache.delete(id);
|
|
2081
|
+
resetChildEventLogCursor(id);
|
|
2082
|
+
resetParseRunCursor(id);
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2074
2085
|
function prepareLaunchWorkspace(options: SubagentWorkspaceOptions, isolated?: IsolatedWorkspace): Promise<SubagentWorkspace> {
|
|
2075
2086
|
const built = import.meta.url.endsWith(".domain.mjs");
|
|
2076
2087
|
const entry = new URL("./workspace-prepare-worker.mjs", import.meta.url);
|
|
@@ -2536,13 +2547,13 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2536
2547
|
const defaults = resolveRunTiming({ settings: cfg, env: process.env, startedAt: 0 });
|
|
2537
2548
|
const minutes = (ms: number | undefined): number => ms === undefined ? 0 : ms / 60_000;
|
|
2538
2549
|
return {
|
|
2539
|
-
maxMinutes:
|
|
2550
|
+
maxMinutes: configuredMaxMinutes(sessionTimeout, timingSettingsFor(cfg), process.env),
|
|
2540
2551
|
toolWaitMinutes: minutes(effective.toolWaitMs),
|
|
2541
2552
|
stuckMinutes: minutes(effective.stuckMs),
|
|
2542
2553
|
timeoutSource: timeoutSource(),
|
|
2543
2554
|
toolWaitSource: sourceFor("toolWaitMinutes"),
|
|
2544
2555
|
stuckSource: sourceFor("stuckMinutes"),
|
|
2545
|
-
defaultMaxMinutes:
|
|
2556
|
+
defaultMaxMinutes: configuredMaxMinutes({}, cfg, process.env),
|
|
2546
2557
|
defaultToolWaitMinutes: minutes(defaults.toolWaitMs),
|
|
2547
2558
|
defaultStuckMinutes: minutes(defaults.stuckMs),
|
|
2548
2559
|
};
|
|
@@ -2794,13 +2805,14 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
2794
2805
|
ctx = captureLaunchContext(ctx);
|
|
2795
2806
|
restoreDelegationMode(ctx);
|
|
2796
2807
|
await workerOperations.start();
|
|
2797
|
-
return definition.execute(key,
|
|
2808
|
+
return launchWorkflowAssignment(pi, ctx, key, params, args => definition.execute(key, args, signal, onUpdate, ctx));
|
|
2798
2809
|
} } : { ...definition, async execute(key, params, signal, _onUpdate, ctx) {
|
|
2799
2810
|
ctx = captureLaunchContext(ctx);
|
|
2800
2811
|
catalogHostFrom(ctx);
|
|
2801
2812
|
const { submitManagedLaunch } = await import("./managed-launch-client.ts");
|
|
2802
2813
|
void activateWorkObservation();
|
|
2803
|
-
return
|
|
2814
|
+
return launchWorkflowAssignment(pi, ctx, key, params, async args =>
|
|
2815
|
+
await observeNavigatorLaunch(ctx, "subagents", key, "Subagent launch", () => submitManagedLaunch(pi, ctx, key, definition.name, args, signal)) as never);
|
|
2804
2816
|
} });
|
|
2805
2817
|
};
|
|
2806
2818
|
announceExecutionAdapter(pi, {
|
|
@@ -3021,19 +3033,15 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3021
3033
|
model = parsed.model;
|
|
3022
3034
|
thinking = parsed.thinking;
|
|
3023
3035
|
}
|
|
3024
|
-
//
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
spendCache.delete(id);
|
|
3034
|
-
healthLogCache.delete(id);
|
|
3035
|
-
resetChildEventLogCursor(id);
|
|
3036
|
-
resetParseRunCursor(id);
|
|
3036
|
+
// Continuations revalidate and lease their saved history. Only fresh launches request maintenance.
|
|
3037
|
+
if (!resume) {
|
|
3038
|
+
if (managed) {
|
|
3039
|
+
const { cleanupTerminalRunRetentionMs, cleanupSessionRetentionMs, maxRegistryBytes } = cfg;
|
|
3040
|
+
managed.scheduleRegistryCleanup({ cleanupTerminalRunRetentionMs, cleanupSessionRetentionMs, maxRegistryBytes }, forgetRunCaches);
|
|
3041
|
+
} else {
|
|
3042
|
+
runDailyCleanupOnce({ config: cfg });
|
|
3043
|
+
for (const removed of enforceRegistrySizeCapOnce({ config: cfg }).removed) forgetRunCaches(removed);
|
|
3044
|
+
}
|
|
3037
3045
|
}
|
|
3038
3046
|
const callbackOrigin = internal?.parkOwner
|
|
3039
3047
|
? { cwd: internal.parkOwner.workspace, sessionId: internal.parkOwner.sessionId }
|
|
@@ -3576,6 +3584,11 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3576
3584
|
trustedExtensions: resume?.recipe.trustedExtensions ?? taskTools?.trusted.map(({ name, package: owner, loadPath }) => ({ name, package: owner, loadPath })),
|
|
3577
3585
|
});
|
|
3578
3586
|
const startedAt = Date.now();
|
|
3587
|
+
const timing = resolveRunTiming({ params: launchTimingParams(p), settings: timingSettingsFor(cfg), env: process.env, startedAt });
|
|
3588
|
+
if (internal?.resumeWait && resume) {
|
|
3589
|
+
timing.lifetimeAt = resume.prior.timing?.lifetimeAt ?? taskDeadline(resume.prior.startedAt);
|
|
3590
|
+
timing.ceilingAt = Math.min(timing.lifetimeAt, resume.prior.timing?.ceilingAt ?? Infinity, timing.ceilingAt!);
|
|
3591
|
+
}
|
|
3579
3592
|
const meta: RunMeta = {
|
|
3580
3593
|
assignment,
|
|
3581
3594
|
outcomeSupport: { version: 1, available: Boolean(assignment), ...(!assignment ? { reason: "Legacy host has no verified parent session/transcript; durable assignment delivery is unavailable." } : {}) },
|
|
@@ -3625,9 +3638,12 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3625
3638
|
tools: bridgePlan.tools,
|
|
3626
3639
|
},
|
|
3627
3640
|
} : {}),
|
|
3628
|
-
timing
|
|
3641
|
+
timing,
|
|
3629
3642
|
};
|
|
3630
3643
|
const dispatchGuard = await internal?.beforeSpawn?.({ runId: id, permissionPlan });
|
|
3644
|
+
if (internal?.resumeWait && Date.now() >= timing.ceilingAt!) {
|
|
3645
|
+
throw new PreSpawnResumeError("The parked task reached its execution time limit before dispatch.");
|
|
3646
|
+
}
|
|
3631
3647
|
if (isolated) markWorkspaceWriter(isolated,id);
|
|
3632
3648
|
const managedEnv = managed?.beforeSpawn({ id, sessionId, lease: lease!.token, leasePath: lease!.path,
|
|
3633
3649
|
preflightPath, policyPath: taskRuntime?.policyPath, permissions: permissionPlan, recipe, recoveryMeta: meta });
|
|
@@ -3784,7 +3800,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3784
3800
|
const prior = readMeta(input.park.runId);
|
|
3785
3801
|
if (!prior) throw new PreSpawnResumeError(`Cannot resume ${input.park.runId}: its run record is gone.`);
|
|
3786
3802
|
const now = Date.now();
|
|
3787
|
-
if (prior.timing?.deadlineAt !== undefined && now >= prior.timing.deadlineAt) {
|
|
3803
|
+
if (now >= taskDeadline(prior.startedAt, prior.timing?.ceilingAt) || (prior.timing?.deadlineAt !== undefined && now >= prior.timing.deadlineAt)) {
|
|
3788
3804
|
throw new PreSpawnResumeError(
|
|
3789
3805
|
`Cannot resume ${input.park.runId}: its assignment deadline passed while it was parked. The wait is held for the owner.`,
|
|
3790
3806
|
);
|
|
@@ -3998,7 +4014,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
3998
4014
|
"The tools param is both the tool allowlist AND what determines which extensions load in the child (e.g. tools='read,bash,web_fetch' loads only the web-tools package). Ask for the tools the task needs and nothing more; clean:true gives a built-ins-only child. When the task already names its SKILL.md by path, pass skills with those absolute paths (or [] for none) so the child does not advertise the whole skills catalog. Without an agent or role, pick a model with the model param (e.g. 'xai/grok-4.5@high'); providerless model patterns are resolved by Pi, while provider/model is deterministic and loads mapped provider extensions.",
|
|
3999
4015
|
...CATALOG_GUIDELINES,
|
|
4000
4016
|
"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.",
|
|
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
|
|
4017
|
+
"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 up to 24 hours (0 selects the maximum). 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.",
|
|
4002
4018
|
"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.",
|
|
4003
4019
|
"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.",
|
|
4004
4020
|
"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.",
|
|
@@ -4006,6 +4022,9 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4006
4022
|
],
|
|
4007
4023
|
parameters: Type.Object({
|
|
4008
4024
|
prompt: Type.String({ description: "The task for the subagent. This is the only context it gets — be self-contained. On a continuation this is the next user turn; the original task and role stay in saved history." }),
|
|
4025
|
+
workflow: Type.Optional(Type.Object({
|
|
4026
|
+
runId: Type.String(), step: Type.String(),
|
|
4027
|
+
}, { description: "Bind this launch to a ready dynamic workflow item. Supply its selected role or agent and inherit catalog skills." })),
|
|
4009
4028
|
session_name: Type.Optional(Type.String({ description: "Exact name of one saved conversation in the current folder and descendants. Alternative to session_id. Duplicate names report matching session ids instead of choosing a conversation." })),
|
|
4010
4029
|
session_id: Type.Optional(Type.String({ description: "Native session id of a saved conversation to continue (reported for every launch and attempt). Omit to start a new conversation. A continuation gets a new run id but keeps this session id, history, workspace, and frozen launch recipe." })),
|
|
4011
4030
|
name: Type.Optional(Type.String({ description: "Short label for the run (e.g. 'reviewer'). Ignored when agent or role is set, except as the direct-role alias when alias is omitted." })),
|
|
@@ -4552,7 +4571,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4552
4571
|
: skills.mode === "none" ? "no skills" : `${skills.paths.length} selected skills`;
|
|
4553
4572
|
const timing = timingState();
|
|
4554
4573
|
ctx.ui.notify(`Delegation mode: ${activeDelegationMode()}. Concurrent subagents: ${activeConcurrencyCap()}. ` +
|
|
4555
|
-
`Run timeout: ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "
|
|
4574
|
+
`Run timeout: ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "24 hours"}. Tool-wait alert: ${timing.toolWaitMinutes} min. ` +
|
|
4556
4575
|
`No-progress alert: ${timing.stuckMinutes} min. Skills: ${skillChoice}. ` +
|
|
4557
4576
|
`Use /subagents mode <mode>, cap <number>, tool-wait <minutes>, stuck <minutes>, or settings; /subagents save persists them.`, "info");
|
|
4558
4577
|
}
|
|
@@ -4638,7 +4657,7 @@ export default function (pi: ExtensionAPI, managed?: import("./managed-launch-po
|
|
|
4638
4657
|
const timing = timingState();
|
|
4639
4658
|
if (ctx.hasUI && !(await ctx.ui.confirm("Save subagent defaults?",
|
|
4640
4659
|
`Future sessions will start in ${activeDelegationMode()} with a cap of ${activeConcurrencyCap()}, ` +
|
|
4641
|
-
`run timeout ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "
|
|
4660
|
+
`run timeout ${timing.maxMinutes ? timing.maxMinutes + " minutes" : "24 hours"}, tool-wait alert ${timing.toolWaitMinutes} min, ` +
|
|
4642
4661
|
`no-progress alert ${timing.stuckMinutes} min, and ${skillChoice}.`))) {
|
|
4643
4662
|
ctx.ui.notify("Subagent defaults unchanged.", "info");
|
|
4644
4663
|
return;
|
|
@@ -10,7 +10,7 @@ import extension from "./index.domain.mjs";
|
|
|
10
10
|
import { bindRuntimeOutcomeStore } from "./assignment-outcomes.domain.mjs";
|
|
11
11
|
import { catalogSnapshotFromWire } from "./catalog-store.domain.mjs";
|
|
12
12
|
import { openLaunchJournal, launchDigest } from "./managed-launch-journal.mjs";
|
|
13
|
-
import { baseDir, nextRunId, processStartToken, listMetas, writeMeta, listActiveMetasForParent, effectiveStatus, readMeta, readParkRecord, updateParkRecord } from "./registry.domain.mjs";
|
|
13
|
+
import { baseDir, nextRunId, processStartToken, listMetas, notifyRunRemoved, writeMeta, listActiveMetasForParent, effectiveStatus, readMeta, readParkRecord, updateParkRecord } from "./registry.domain.mjs";
|
|
14
14
|
import { recoverLaunchMetadata } from "./managed-launch-recovery.domain.mjs";
|
|
15
15
|
import { assertSubagentHandoff } from "./managed-launch-ownership.domain.mjs";
|
|
16
16
|
import { createOwnerCapacityGates } from "./capacity.mjs";
|
|
@@ -42,6 +42,7 @@ export class ManagedSubagentHost {
|
|
|
42
42
|
closeJournal;
|
|
43
43
|
epoch;
|
|
44
44
|
pending = 0;
|
|
45
|
+
registryCleanup;
|
|
45
46
|
requestSequence = 0;
|
|
46
47
|
requestRecords = new Map();
|
|
47
48
|
foldRecord;
|
|
@@ -196,7 +197,8 @@ export class ManagedSubagentHost {
|
|
|
196
197
|
}
|
|
197
198
|
capacityFor = createOwnerCapacityGates(({ pid, start }) => listActiveMetasForParent(pid).filter(meta => meta.spawnPidStartTime === start && effectiveStatus(meta) === "running").length
|
|
198
199
|
+ this.journal.unresolvedAttempts().filter((attempt) => attempt.capacityOwner?.pid === pid && attempt.capacityOwner?.start === start && !readMeta(attempt.id)).length);
|
|
199
|
-
get
|
|
200
|
+
get cleaningRegistry() { return this.registryCleanup !== undefined; }
|
|
201
|
+
get busy() { return this.pending > 0 || Boolean(this.failureResponse) || this.cleaningRegistry; }
|
|
200
202
|
status() {
|
|
201
203
|
return { owner: "server", instanceId: this.instance, runtimeEpoch: this.epoch,
|
|
202
204
|
lifecycle: { ...this.lifecycleMetrics, activeDeadlines: this.healthDue.size },
|
|
@@ -339,10 +341,33 @@ export class ManagedSubagentHost {
|
|
|
339
341
|
process.kill(record.pid, 0);
|
|
340
342
|
return record;
|
|
341
343
|
}
|
|
344
|
+
scheduleRegistryCleanup = (config, onRemoved) => {
|
|
345
|
+
if (this.registryCleanup)
|
|
346
|
+
return;
|
|
347
|
+
this.registryCleanup = new Promise((resolve, reject) => {
|
|
348
|
+
const worker = new Worker(new URL("./registry-cleanup-worker.mjs", import.meta.url), {
|
|
349
|
+
workerData: { root: this.root, config },
|
|
350
|
+
execArgv: import.meta.url.endsWith(".domain.mjs") ? [] : ["--import", import.meta.resolve("tsx")],
|
|
351
|
+
});
|
|
352
|
+
worker.on("message", (id) => {
|
|
353
|
+
notifyRunRemoved(id);
|
|
354
|
+
onRemoved(id);
|
|
355
|
+
});
|
|
356
|
+
worker.once("error", reject);
|
|
357
|
+
worker.once("exit", code => {
|
|
358
|
+
if (code === 0)
|
|
359
|
+
resolve();
|
|
360
|
+
else
|
|
361
|
+
reject(new Error(`Registry cleanup worker exited with code ${code}`));
|
|
362
|
+
});
|
|
363
|
+
}).catch(error => console.error("[pi-better-subagents] Registry cleanup failed:", error))
|
|
364
|
+
.finally(() => { this.registryCleanup = undefined; });
|
|
365
|
+
};
|
|
342
366
|
initialize() {
|
|
343
367
|
return this.initializing ??= (async () => {
|
|
344
368
|
const host = this;
|
|
345
369
|
const port = {
|
|
370
|
+
scheduleRegistryCleanup: this.scheduleRegistryCleanup,
|
|
346
371
|
observeHealth: reconcile => host.observeHealth(reconcile),
|
|
347
372
|
activeProviders: () => host.current.activeProviders ?? {},
|
|
348
373
|
backgroundTools: () => host.current.background?.available === true ? host.current.background.tools : [],
|
|
@@ -598,6 +623,7 @@ export class ManagedSubagentHost {
|
|
|
598
623
|
this.healthClose?.();
|
|
599
624
|
Atomics.store(this.foldRevocation, 0, 1);
|
|
600
625
|
await this.tail.catch(() => undefined);
|
|
626
|
+
await this.registryCleanup;
|
|
601
627
|
await this.failureWorker?.terminate();
|
|
602
628
|
this.failureWorker = undefined;
|
|
603
629
|
if (failureFoldRevocations.get(this.root) === this.foldRevocation)
|
|
@@ -9,7 +9,7 @@ import extension from "./index.ts";
|
|
|
9
9
|
import { bindRuntimeOutcomeStore } from "./assignment-outcomes.ts";
|
|
10
10
|
import { catalogSnapshotFromWire } from "./catalog-store.ts";
|
|
11
11
|
import { openLaunchJournal, launchDigest } from "./managed-launch-journal.mjs";
|
|
12
|
-
import { baseDir, nextRunId, processStartToken, listMetas, writeMeta, listActiveMetasForParent, effectiveStatus, readMeta, readParkRecord, updateParkRecord } from "./registry.ts";
|
|
12
|
+
import { baseDir, nextRunId, processStartToken, listMetas, notifyRunRemoved, writeMeta, listActiveMetasForParent, effectiveStatus, readMeta, readParkRecord, updateParkRecord } from "./registry.ts";
|
|
13
13
|
import { recoverLaunchMetadata } from "./managed-launch-recovery.ts";
|
|
14
14
|
import { assertSubagentHandoff } from "./managed-launch-ownership.ts";
|
|
15
15
|
import { createOwnerCapacityGates } from "./capacity.mjs";
|
|
@@ -37,6 +37,7 @@ export class ManagedSubagentHost {
|
|
|
37
37
|
private closeJournal: () => void;
|
|
38
38
|
private epoch: number;
|
|
39
39
|
private pending = 0;
|
|
40
|
+
private registryCleanup?: Promise<void>;
|
|
40
41
|
private requestSequence = 0;
|
|
41
42
|
private requestRecords = new Map<number, any>();
|
|
42
43
|
private foldRecord?: { kind: string; ids: readonly string[]; lastProgressAt: number; nextDeadline: number; recovery: string };
|
|
@@ -151,7 +152,8 @@ export class ManagedSubagentHost {
|
|
|
151
152
|
private capacityFor = createOwnerCapacityGates(({ pid, start }: { pid: number; start: string }) =>
|
|
152
153
|
listActiveMetasForParent(pid).filter(meta => meta.spawnPidStartTime === start && effectiveStatus(meta) === "running").length
|
|
153
154
|
+ this.journal.unresolvedAttempts().filter((attempt: any) => attempt.capacityOwner?.pid === pid && attempt.capacityOwner?.start === start && !readMeta(attempt.id)).length);
|
|
154
|
-
get
|
|
155
|
+
get cleaningRegistry() { return this.registryCleanup !== undefined; }
|
|
156
|
+
get busy() { return this.pending > 0 || Boolean(this.failureResponse) || this.cleaningRegistry; }
|
|
155
157
|
status() {
|
|
156
158
|
return { owner: "server", instanceId: this.instance, runtimeEpoch: this.epoch,
|
|
157
159
|
lifecycle: { ...this.lifecycleMetrics, activeDeadlines: this.healthDue.size },
|
|
@@ -260,10 +262,31 @@ export class ManagedSubagentHost {
|
|
|
260
262
|
process.kill(record.pid, 0);
|
|
261
263
|
return record;
|
|
262
264
|
}
|
|
265
|
+
private scheduleRegistryCleanup: ManagedLaunchPort["scheduleRegistryCleanup"] = (config, onRemoved) => {
|
|
266
|
+
if (this.registryCleanup) return;
|
|
267
|
+
this.registryCleanup = new Promise<void>((resolve, reject) => {
|
|
268
|
+
const worker = new Worker(new URL("./registry-cleanup-worker.mjs", import.meta.url), {
|
|
269
|
+
workerData: { root: this.root, config },
|
|
270
|
+
execArgv: import.meta.url.endsWith(".domain.mjs") ? [] : ["--import", import.meta.resolve("tsx")],
|
|
271
|
+
});
|
|
272
|
+
worker.on("message", (id: string) => {
|
|
273
|
+
notifyRunRemoved(id);
|
|
274
|
+
onRemoved(id);
|
|
275
|
+
});
|
|
276
|
+
worker.once("error", reject);
|
|
277
|
+
worker.once("exit", code => {
|
|
278
|
+
if (code === 0) resolve();
|
|
279
|
+
else reject(new Error(`Registry cleanup worker exited with code ${code}`));
|
|
280
|
+
});
|
|
281
|
+
}).catch(error => console.error("[pi-better-subagents] Registry cleanup failed:", error))
|
|
282
|
+
.finally(() => { this.registryCleanup = undefined; });
|
|
283
|
+
};
|
|
284
|
+
|
|
263
285
|
private initialize() {
|
|
264
286
|
return this.initializing ??= (async () => {
|
|
265
287
|
const host = this;
|
|
266
288
|
const port: ManagedLaunchPort = {
|
|
289
|
+
scheduleRegistryCleanup: this.scheduleRegistryCleanup,
|
|
267
290
|
observeHealth: reconcile => host.observeHealth(reconcile),
|
|
268
291
|
activeProviders: () => host.current.activeProviders ?? {},
|
|
269
292
|
backgroundTools: () => host.current.background?.available === true ? host.current.background.tools : [],
|
|
@@ -487,6 +510,7 @@ export class ManagedSubagentHost {
|
|
|
487
510
|
this.healthClose?.();
|
|
488
511
|
Atomics.store(this.foldRevocation, 0, 1);
|
|
489
512
|
await this.tail.catch(() => undefined);
|
|
513
|
+
await this.registryCleanup;
|
|
490
514
|
await this.failureWorker?.terminate(); this.failureWorker = undefined;
|
|
491
515
|
if (failureFoldRevocations.get(this.root) === this.foldRevocation) failureFoldRevocations.delete(this.root);
|
|
492
516
|
const session = this.session;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SubagentConfig } from "./config.ts";
|
|
1
2
|
import type { CatalogHost } from "./catalog-runtime.ts";
|
|
2
3
|
import type { CatalogSnapshot } from "./catalog-store.ts";
|
|
3
4
|
import type { RunMeta } from "./registry.ts";
|
|
@@ -6,6 +7,7 @@ import type { RunMeta } from "./registry.ts";
|
|
|
6
7
|
export interface ManagedLaunchPort {
|
|
7
8
|
observeHealth?(reconcile: (ids: readonly string[]) => void): () => void;
|
|
8
9
|
activeProviders?(): Record<string, string>;
|
|
10
|
+
scheduleRegistryCleanup(config: Pick<SubagentConfig, "cleanupTerminalRunRetentionMs" | "cleanupSessionRetentionMs" | "maxRegistryBytes">, onRemoved: (id: string) => void): void;
|
|
9
11
|
backgroundTools(): readonly string[];
|
|
10
12
|
readonly owner: { pid: number; start?: string };
|
|
11
13
|
readonly identity: { root: string; instance: string; epoch: number };
|
|
@@ -521,7 +521,7 @@ export function assembleOrphanedResult(id, meta, healthLine, request = {}, scope
|
|
|
521
521
|
statusCursor: ctx.statusCursor,
|
|
522
522
|
});
|
|
523
523
|
}
|
|
524
|
-
export function assembleSubagentResult(id, meta, request = {}, healthLine = "", scopeKey = defaultScope()) {
|
|
524
|
+
export function assembleSubagentResult(id, meta, request = {}, healthLine = "", scopeKey = defaultScope(), observed) {
|
|
525
525
|
healthLine = [healthLine, projectionDiagnostic(meta)].filter(Boolean).join("\n");
|
|
526
526
|
const st = effectiveStatus(meta);
|
|
527
527
|
if (isRawMode(request.mode) || cursorKind(request.cursor) === "f")
|
|
@@ -601,6 +601,8 @@ export function assembleSubagentResult(id, meta, request = {}, healthLine = "",
|
|
|
601
601
|
}
|
|
602
602
|
const exceptional = isRoutineComplete(lifecycle) ? undefined : formatLifecycleDiagnostics(lifecycle);
|
|
603
603
|
const answer = run.finalText || "";
|
|
604
|
+
if (observed)
|
|
605
|
+
observed.hasFinalAnswer = Boolean(answer.trim());
|
|
604
606
|
const fallback = !answer
|
|
605
607
|
? (run.lastActivity
|
|
606
608
|
? `(no final answer parsed; latest activity)\n${run.lastActivity}`
|
|
@@ -702,6 +702,7 @@ export function assembleSubagentResult(
|
|
|
702
702
|
request: PayloadRequest = {},
|
|
703
703
|
healthLine = "",
|
|
704
704
|
scopeKey = defaultScope(),
|
|
705
|
+
observed?: { hasFinalAnswer?: boolean },
|
|
705
706
|
): string {
|
|
706
707
|
healthLine = [healthLine, projectionDiagnostic(meta)].filter(Boolean).join("\n");
|
|
707
708
|
const st = effectiveStatus(meta);
|
|
@@ -782,6 +783,7 @@ export function assembleSubagentResult(
|
|
|
782
783
|
|
|
783
784
|
const exceptional = isRoutineComplete(lifecycle) ? undefined : formatLifecycleDiagnostics(lifecycle);
|
|
784
785
|
const answer = run.finalText || "";
|
|
786
|
+
if (observed) observed.hasFinalAnswer = Boolean(answer.trim());
|
|
785
787
|
const fallback = !answer
|
|
786
788
|
? (run.lastActivity
|
|
787
789
|
? `(no final answer parsed; latest activity)\n${run.lastActivity}`
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated fixed launch domain from packages/pi-better-subagents/registry-cleanup-worker.mjs. Do not edit directly.
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
4
|
+
import { bindRuntimeOutcomeStore } from "./assignment-outcomes.domain.mjs";
|
|
5
|
+
import { enforceRegistrySizeCapOnce, runDailyCleanupOnce } from "./cleanup.domain.mjs";
|
|
6
|
+
import { onMetaChanged } from "./registry.domain.mjs";
|
|
7
|
+
import { openStore } from "./shared-operation-coordinator/index.domain.mjs";
|
|
8
|
+
const { root, config } = workerData;
|
|
9
|
+
process.env.PI_CODING_AGENT_DIR = root;
|
|
10
|
+
// Reuse one coordinator connection for all assignment and retention checks in this sweep.
|
|
11
|
+
const store = openStore({ path: join(root, "operation-coordinator.sqlite") });
|
|
12
|
+
const unbind = bindRuntimeOutcomeStore(root, store);
|
|
13
|
+
// Cleanup emits a metadata change after each committed removal, including during the daily sweep.
|
|
14
|
+
const off = onMetaChanged(meta => { if (meta)
|
|
15
|
+
parentPort.postMessage(meta.id); });
|
|
16
|
+
try {
|
|
17
|
+
runDailyCleanupOnce({ config });
|
|
18
|
+
enforceRegistrySizeCapOnce({ config });
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
off();
|
|
22
|
+
unbind();
|
|
23
|
+
store.close();
|
|
24
|
+
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
// Generated fixed launch domain from packages/pi-better-subagents/registry.ts. Do not edit directly.
|
|
2
2
|
import { reclaimWorkspace } from "./isolated-workspace.domain.mjs";
|
|
3
3
|
import { retainResult } from "./retained-result.domain.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Run registry — durable metadata for each spawned subagent.
|
|
6
|
+
*
|
|
7
|
+
* The authoritative record for every run is a `meta.json` sidecar on disk, so
|
|
8
|
+
* `list` / `output` / `result` keep working across foreground turns, `/reload`,
|
|
9
|
+
* and even a full pi restart. In-memory state holds only the live exit handlers
|
|
10
|
+
* for runs this process spawned.
|
|
11
|
+
*
|
|
12
|
+
* Catalog launches may attach an optional immutable `catalog` snapshot to that
|
|
13
|
+
* same record. Display-label reservations live under `{baseDir()}/labels`
|
|
14
|
+
* (see catalog-identity.ts). They are not a second registry, and removing a
|
|
15
|
+
* run directory does not delete them.
|
|
16
|
+
*/
|
|
17
|
+
import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.domain.mjs";
|
|
4
18
|
import { assignmentRetainsEvidence } from "./assignment-outcomes.domain.mjs";
|
|
5
19
|
import { processStartToken } from "./process-identity.mjs";
|
|
6
20
|
export { processStartToken } from "./process-identity.mjs";
|
|
@@ -1022,10 +1036,27 @@ export function onMetaChanged(listener) {
|
|
|
1022
1036
|
metaChangedListeners.add(listener);
|
|
1023
1037
|
return () => metaChangedListeners.delete(listener);
|
|
1024
1038
|
}
|
|
1039
|
+
/** Drop volatile state in the process observing a committed cleanup. */
|
|
1040
|
+
export function notifyRunRemoved(id, meta = metaCache.get(id)) {
|
|
1041
|
+
metaCache.delete(id);
|
|
1042
|
+
for (const listener of metaChangedListeners) {
|
|
1043
|
+
try {
|
|
1044
|
+
listener(meta);
|
|
1045
|
+
}
|
|
1046
|
+
catch { /* best effort */ }
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
function restoreTaskDeadline(meta) {
|
|
1050
|
+
if (meta.status !== "running" && meta.status !== "orphaned")
|
|
1051
|
+
return;
|
|
1052
|
+
meta.timing ??= { graceMs: 0 };
|
|
1053
|
+
meta.timing.ceilingAt = taskDeadline(meta.startedAt, meta.timing.ceilingAt);
|
|
1054
|
+
}
|
|
1025
1055
|
export function readMeta(id) {
|
|
1026
1056
|
try {
|
|
1027
1057
|
registryIo.metadataFileReads += 1;
|
|
1028
1058
|
const meta = JSON.parse(readFileSync(metaPathFor(id), "utf-8"));
|
|
1059
|
+
restoreTaskDeadline(meta);
|
|
1029
1060
|
metaCache.set(id, meta);
|
|
1030
1061
|
return meta;
|
|
1031
1062
|
}
|
|
@@ -1069,16 +1100,10 @@ export function removeMetaArtifacts(meta, options = {}) {
|
|
|
1069
1100
|
if (scratch) {
|
|
1070
1101
|
rmSync(scratch, { recursive: true, force: true });
|
|
1071
1102
|
}
|
|
1072
|
-
metaCache.delete(meta.id);
|
|
1073
1103
|
removeIndexEntry(join(baseDir(), "by-parent", String(meta.spawnPid)), meta.id);
|
|
1074
1104
|
removeIndexEntry(join(baseDir(), "by-parent-active", String(meta.spawnPid)), meta.id);
|
|
1075
1105
|
removeIndexEntry(join(baseDir(), "by-origin", originKey(originOf(meta))), meta.id);
|
|
1076
|
-
|
|
1077
|
-
try {
|
|
1078
|
-
listener(meta);
|
|
1079
|
-
}
|
|
1080
|
-
catch { /* best effort */ }
|
|
1081
|
-
}
|
|
1106
|
+
notifyRunRemoved(meta.id, meta);
|
|
1082
1107
|
return true;
|
|
1083
1108
|
}
|
|
1084
1109
|
catch (error) {
|
|
@@ -1329,6 +1354,7 @@ export function inspectRunMeta(id) {
|
|
|
1329
1354
|
metaCache.delete(id);
|
|
1330
1355
|
return { kind: "unreadable", detail: `invalid metadata: ${invalid}` };
|
|
1331
1356
|
}
|
|
1357
|
+
restoreTaskDeadline(meta);
|
|
1332
1358
|
metaCache.set(id, meta);
|
|
1333
1359
|
return { kind: "ok", meta };
|
|
1334
1360
|
}
|
|
@@ -14,6 +14,7 @@ import { retainResult } from "./retained-result.ts";
|
|
|
14
14
|
* run directory does not delete them.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.ts";
|
|
17
18
|
import type { RunTiming } from "./timing.ts";
|
|
18
19
|
import { assignmentRetainsEvidence } from "./assignment-outcomes.ts";
|
|
19
20
|
import type { SkillExposureSource } from "./skills.ts";
|
|
@@ -1316,10 +1317,25 @@ export function onMetaChanged(listener: (meta?: RunMeta) => void): () => void {
|
|
|
1316
1317
|
return () => metaChangedListeners.delete(listener);
|
|
1317
1318
|
}
|
|
1318
1319
|
|
|
1320
|
+
/** Drop volatile state in the process observing a committed cleanup. */
|
|
1321
|
+
export function notifyRunRemoved(id: string, meta = metaCache.get(id)): void {
|
|
1322
|
+
metaCache.delete(id);
|
|
1323
|
+
for (const listener of metaChangedListeners) {
|
|
1324
|
+
try { listener(meta); } catch { /* best effort */ }
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
function restoreTaskDeadline(meta: RunMeta): void {
|
|
1329
|
+
if (meta.status !== "running" && meta.status !== "orphaned") return;
|
|
1330
|
+
meta.timing ??= { graceMs: 0 };
|
|
1331
|
+
meta.timing.ceilingAt = taskDeadline(meta.startedAt, meta.timing.ceilingAt);
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1319
1334
|
export function readMeta(id: string): RunMeta | undefined {
|
|
1320
1335
|
try {
|
|
1321
1336
|
registryIo.metadataFileReads += 1;
|
|
1322
1337
|
const meta = JSON.parse(readFileSync(metaPathFor(id), "utf-8")) as RunMeta;
|
|
1338
|
+
restoreTaskDeadline(meta);
|
|
1323
1339
|
metaCache.set(id, meta);
|
|
1324
1340
|
return meta;
|
|
1325
1341
|
} catch (error) {
|
|
@@ -1376,13 +1392,10 @@ export function removeMetaArtifacts(meta: RunMeta, options: RemoveMetaArtifactsO
|
|
|
1376
1392
|
if (scratch) {
|
|
1377
1393
|
rmSync(scratch, { recursive: true, force: true });
|
|
1378
1394
|
}
|
|
1379
|
-
metaCache.delete(meta.id);
|
|
1380
1395
|
removeIndexEntry(join(baseDir(), "by-parent", String(meta.spawnPid)), meta.id);
|
|
1381
1396
|
removeIndexEntry(join(baseDir(), "by-parent-active", String(meta.spawnPid)), meta.id);
|
|
1382
1397
|
removeIndexEntry(join(baseDir(), "by-origin", originKey(originOf(meta))), meta.id);
|
|
1383
|
-
|
|
1384
|
-
try { listener(meta); } catch { /* best effort */ }
|
|
1385
|
-
}
|
|
1398
|
+
notifyRunRemoved(meta.id, meta);
|
|
1386
1399
|
return true;
|
|
1387
1400
|
} catch (error) {
|
|
1388
1401
|
options.errors?.push(meta.cwd + ": " + String(error));
|
|
@@ -1659,6 +1672,7 @@ export function inspectRunMeta(id: string): { kind: "ok"; meta: RunMeta } | { ki
|
|
|
1659
1672
|
metaCache.delete(id);
|
|
1660
1673
|
return { kind: "unreadable", detail: `invalid metadata: ${invalid}` };
|
|
1661
1674
|
}
|
|
1675
|
+
restoreTaskDeadline(meta);
|
|
1662
1676
|
metaCache.set(id, meta);
|
|
1663
1677
|
return { kind: "ok", meta };
|
|
1664
1678
|
}
|
|
@@ -3,7 +3,7 @@ import * as Tui from "@earendil-works/pi-tui";
|
|
|
3
3
|
import { isConcurrencyCap } from "./config.domain.mjs";
|
|
4
4
|
import { DELEGATION_MODES } from "./delegation.domain.mjs";
|
|
5
5
|
import { createSkillPicker } from "./skill-picker.domain.mjs";
|
|
6
|
-
import { isTimingMinutes,
|
|
6
|
+
import { isTimingMinutes, validatedTimingMinutes } from "./timing.domain.mjs";
|
|
7
7
|
const rows = [
|
|
8
8
|
{ kind: "mode", label: "Delegation mode" },
|
|
9
9
|
{ kind: "cap", label: "Concurrent subagents" },
|
|
@@ -22,14 +22,14 @@ const SKILL_MODES = [
|
|
|
22
22
|
{ mode: "none", label: "No skill catalog" },
|
|
23
23
|
{ mode: "explicit", label: "Selected skills" },
|
|
24
24
|
];
|
|
25
|
-
const
|
|
25
|
+
const MAX_TIMEOUT = "24 hours";
|
|
26
26
|
function parseRunTimeout(input) {
|
|
27
27
|
const text = input.trim();
|
|
28
|
-
if (
|
|
28
|
+
if (["no limit", MAX_TIMEOUT].includes(text.toLowerCase()))
|
|
29
29
|
return 0;
|
|
30
30
|
const minutes = Number(text);
|
|
31
|
-
if (!text || !isTimingMinutes(minutes)) {
|
|
32
|
-
throw new Error(
|
|
31
|
+
if (!text || !isTimingMinutes(minutes) || minutes > 1440) {
|
|
32
|
+
throw new Error("Enter 24 hours or a duration up to 1440 minutes.");
|
|
33
33
|
}
|
|
34
34
|
return minutes;
|
|
35
35
|
}
|
|
@@ -51,7 +51,7 @@ function settingValue(kind, s) {
|
|
|
51
51
|
case "mode": return s.mode;
|
|
52
52
|
case "cap": return String(s.maxConcurrent);
|
|
53
53
|
case "workspace": return s.gitWorkspace === "worktree" ? "Worktree" : "Clone";
|
|
54
|
-
case "timeout": return s.maxMinutes === 0 ?
|
|
54
|
+
case "timeout": return s.maxMinutes === 0 || s.maxMinutes >= 1440 ? MAX_TIMEOUT : `${s.maxMinutes} min`;
|
|
55
55
|
case "toolWait": return s.toolWaitMinutes === 0 ? "Off" : `${s.toolWaitMinutes} min`;
|
|
56
56
|
case "stuck": return s.stuckMinutes === 0 ? "Off" : `${s.stuckMinutes} min`;
|
|
57
57
|
case "skills": return skillLabel(s.skillsMode);
|
|
@@ -71,7 +71,7 @@ function description(kind, s) {
|
|
|
71
71
|
case "workspace": return s.gitWorkspace === "worktree"
|
|
72
72
|
? "Create a linked worktree that shares the repository’s Git metadata."
|
|
73
73
|
: "Create a separate local clone for each isolated Git workspace.";
|
|
74
|
-
case "timeout": return "Stop a subagent when its run reaches this limit.
|
|
74
|
+
case "timeout": return "Stop a subagent when its run reaches this limit. The maximum is 24 hours.";
|
|
75
75
|
case "toolWait": return "Notify the parent when a tool call stays open this long. Enter 0 to turn this alert off.";
|
|
76
76
|
case "stuck": return "Notify the parent after this long without progress. Time spent waiting for a tool is excluded. Enter 0 to turn this alert off.";
|
|
77
77
|
case "skills": return "Choose how new subagents discover skills.\n" + skillSource(s);
|
|
@@ -94,7 +94,7 @@ function shortcuts(kind, editing) {
|
|
|
94
94
|
const change = confirm ? `${confirm}/Space` : "Space";
|
|
95
95
|
const verb = kind === "agents" || kind === "choose" ? "open" : kind === "reset" ? "restore" : "change";
|
|
96
96
|
const actions = editing ? [confirm && `${confirm} to apply`]
|
|
97
|
-
: kind === "timeout" ? ["Space for
|
|
97
|
+
: kind === "timeout" ? ["Space for 24 hours", confirm && `${confirm} to edit minutes`]
|
|
98
98
|
: [`${change} to ${verb}`];
|
|
99
99
|
if (!editing)
|
|
100
100
|
actions.push("Ctrl+S to save defaults");
|
|
@@ -187,10 +187,10 @@ export function createSubagentSettingsPage(theme, handlers, requestRender, close
|
|
|
187
187
|
else if (selected.kind === "timeout") {
|
|
188
188
|
if (key === " ") {
|
|
189
189
|
handlers.changeTiming("maxMinutes", 0);
|
|
190
|
-
report("Run timeout set to
|
|
190
|
+
report("Run timeout set to 24 hours.");
|
|
191
191
|
}
|
|
192
192
|
else {
|
|
193
|
-
startEditing(selected, settings.maxMinutes === 0 ?
|
|
193
|
+
startEditing(selected, settings.maxMinutes === 0 || settings.maxMinutes >= 1440 ? MAX_TIMEOUT : String(settings.maxMinutes));
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
else if (selected.kind === "skills") {
|