pi-subagents 0.86.0 → 0.88.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-PYOAIN3V.js → chunk-2DIEL4WG.js} +2 -2
- package/bundle/{chunk-GJGTMLPE.js → chunk-3DT5X2QC.js} +483 -477
- package/bundle/{chunk-374MZFF4.js → chunk-3MFYKBKI.js} +23 -13
- package/bundle/{chunk-ZJJCPV3L.js → chunk-47GJDBIK.js} +10 -6
- package/bundle/{chunk-77ASNIEM.js → chunk-47ZN7NKR.js} +1 -1
- package/bundle/{chunk-QGO6HXHG.js → chunk-4MVDMA5C.js} +88 -64
- package/bundle/{chunk-O3YH7XIY.js → chunk-4PM6RDE5.js} +46 -32
- package/bundle/{chunk-BWC2LVII.js → chunk-4UGWHREQ.js} +200 -64
- package/bundle/{chunk-3RKFH2UZ.js → chunk-6EUQPQY7.js} +31 -14
- package/bundle/{chunk-A637IMAO.js → chunk-6OWNDN7R.js} +2 -2
- package/bundle/{chunk-6VD7BGIC.js → chunk-6PR44R7E.js} +7 -2
- package/bundle/{chunk-7ZUFN6ME.js → chunk-CKLZ5FGU.js} +2 -2
- package/bundle/{chunk-ZPY5QZCS.js → chunk-CYKNHFXB.js} +1 -1
- package/bundle/{chunk-YK3QYNLE.js → chunk-GDR2ILWY.js} +1 -1
- package/bundle/{chunk-7QA7ZA46.js → chunk-IZEKQEY4.js} +9 -9
- package/bundle/{chunk-NAFLUJ26.js → chunk-KXW62VBU.js} +1 -1
- package/bundle/{chunk-S2Q75LP3.js → chunk-L4YY2TOE.js} +1 -1
- package/bundle/{chunk-QM3JGE4W.js → chunk-MTPICU4A.js} +12 -12
- package/bundle/{chunk-BU6PFPVX.js → chunk-PJSOS2Q4.js} +12 -7
- package/bundle/{chunk-UR7OW5S7.js → chunk-RHYVKQQL.js} +11 -5
- package/bundle/{chunk-BGXEAYUM.js → chunk-SVIXQDIV.js} +20 -5
- package/bundle/{chunk-7ADDXUGF.js → chunk-UVDLJXL6.js} +14 -5
- package/bundle/{chunk-NF7IEKBH.js → chunk-W2BZS6UC.js} +27 -13
- package/bundle/{chunk-5H4BICQZ.js → chunk-W6HIYD2Z.js} +1 -1
- package/bundle/{chunk-2IYBCYFU.js → chunk-XAOHLFJO.js} +174 -56
- package/bundle/{chunk-LGINOOY5.js → chunk-XIA5GSEU.js} +2 -2
- package/bundle/chunk-YDZ7BZD5.js +523 -0
- package/bundle/{chunk-WN2E5XHN.js → chunk-YZPVALSQ.js} +30 -5
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +4 -4
- package/docs/configuration.md +17 -5
- package/docs/extension-api.md +2 -0
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +5 -1
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +22 -10
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +1 -0
- package/src/agents/agents.js +39 -14
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +6 -0
- package/src/extension/index.js +8 -5
- package/src/extension/schemas.d.ts +4 -0
- package/src/extension/schemas.js +2 -0
- package/src/extension/tool-activation.js +20 -3
- package/src/runs/background/async-execution.d.ts +2 -1
- package/src/runs/background/async-execution.js +4 -2
- package/src/runs/background/async-resume.js +2 -1
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +11 -5
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- package/src/runs/background/run-child-session.d.ts +2 -2
- package/src/runs/background/run-child-session.js +4 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +0 -2
- package/src/runs/background/subagent-runner.js +73 -58
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/foreground/async-steering-action.js +24 -9
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.js +33 -15
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +2 -8
- package/src/runs/foreground/subagent-executor.js +57 -23
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- package/src/runs/shared/child-session.d.ts +5 -4
- package/src/runs/shared/child-session.js +64 -36
- package/src/runs/shared/herdr-placed-run.js +3 -2
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- package/src/runs/shared/model-resolution.d.ts +19 -4
- package/src/runs/shared/model-resolution.js +50 -51
- package/src/runs/shared/subagent-prompt-runtime.js +14 -2
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- package/src/shared/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- package/src/shared/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +23 -0
- package/src/shared/utils.d.ts +3 -1
- package/src/shared/utils.js +4 -0
- package/src/tui/render.js +33 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +103 -39
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +1 -1
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +3 -1
- package/src/workflows/workflow-script-worker.js +3 -1
- package/bundle/chunk-GRJHIXYF.js +0 -235
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
startWatchdogDiffBaselineCapture,
|
|
12
12
|
writeUserWatchdogEnabled,
|
|
13
13
|
writeWatchdogModelSettings
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-47GJDBIK.js";
|
|
15
15
|
import {
|
|
16
16
|
resolveGitRepositoryIdentity
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-RHYVKQQL.js";
|
|
18
18
|
import {
|
|
19
19
|
listAsyncRuns,
|
|
20
20
|
parallelHandoffPath,
|
|
@@ -22,14 +22,14 @@ import {
|
|
|
22
22
|
readAsyncRecoveryDescriptor,
|
|
23
23
|
readWorkflowLaunchRecord,
|
|
24
24
|
resolveRetainedWorktreeCwd
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-SVIXQDIV.js";
|
|
26
26
|
import {
|
|
27
27
|
ownsRun
|
|
28
28
|
} from "./chunk-HXRB42AF.js";
|
|
29
29
|
import {
|
|
30
30
|
deepFreezeWorkflowArgs,
|
|
31
31
|
normalizeWorkflowArgs
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-W2BZS6UC.js";
|
|
33
33
|
import {
|
|
34
34
|
HOST_STEP_MAX_COUNT,
|
|
35
35
|
REQUIRE_LAUNCHER_SHAPE_ERROR,
|
|
@@ -54,21 +54,21 @@ import {
|
|
|
54
54
|
resolveMissionStoreLocation,
|
|
55
55
|
validateMissionId,
|
|
56
56
|
workflowRunParamsFingerprint
|
|
57
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-3DT5X2QC.js";
|
|
58
58
|
import {
|
|
59
59
|
requestAsyncCommand,
|
|
60
60
|
watchAsyncControlInbox
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-W6HIYD2Z.js";
|
|
62
62
|
import {
|
|
63
63
|
supervisorChannelDir
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-3MFYKBKI.js";
|
|
65
65
|
import {
|
|
66
66
|
createHerdrClient,
|
|
67
67
|
detectHerdr
|
|
68
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-2DIEL4WG.js";
|
|
69
69
|
import {
|
|
70
70
|
getProjectSubagentsDir
|
|
71
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-YDZ7BZD5.js";
|
|
72
72
|
import {
|
|
73
73
|
ExternalJobProviderError,
|
|
74
74
|
getExternalJobProvider,
|
|
@@ -78,10 +78,11 @@ import {
|
|
|
78
78
|
} from "./chunk-YYREO77V.js";
|
|
79
79
|
import {
|
|
80
80
|
mergeRuntimeAgents
|
|
81
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-KXW62VBU.js";
|
|
82
82
|
import {
|
|
83
83
|
CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL,
|
|
84
84
|
EXTERNAL_CLI_ADAPTER_SAFETY,
|
|
85
|
+
MAX_LISTED_AGENTS,
|
|
85
86
|
PI_CODING_AGENT_PACKAGE,
|
|
86
87
|
PI_CODING_AGENT_PACKAGE_ROOT_ENV,
|
|
87
88
|
PROMPT_REDACTED,
|
|
@@ -106,10 +107,12 @@ import {
|
|
|
106
107
|
getSupportedThinkingLevels,
|
|
107
108
|
isCodeOwnedExternalCliAdapterId,
|
|
108
109
|
isUnavailableSubagentModel,
|
|
110
|
+
knownModelProviders,
|
|
109
111
|
mergeAgentsForScope,
|
|
110
112
|
mergeBuiltinAgentOverride,
|
|
111
113
|
normalizeModelSegment,
|
|
112
114
|
normalizeWorkflowLaneMetadata,
|
|
115
|
+
parseAcceptanceReport,
|
|
113
116
|
parseFrontmatter,
|
|
114
117
|
parsePackageName,
|
|
115
118
|
parseUnquotedList,
|
|
@@ -136,7 +139,7 @@ import {
|
|
|
136
139
|
withFileLease,
|
|
137
140
|
writeAtomicJson,
|
|
138
141
|
writePrivateAtomicJson
|
|
139
|
-
} from "./chunk-
|
|
142
|
+
} from "./chunk-4MVDMA5C.js";
|
|
140
143
|
import {
|
|
141
144
|
DIRS,
|
|
142
145
|
INTERCOM_DETACH_REQUEST_EVENT,
|
|
@@ -3108,6 +3111,7 @@ function editableAgentConfig(agent) {
|
|
|
3108
3111
|
const next = { ...config };
|
|
3109
3112
|
if (!hasDeclaredField("model")) delete next.model;
|
|
3110
3113
|
if (!hasDeclaredField("thinking")) delete next.thinking;
|
|
3114
|
+
if (!hasDeclaredField("inheritGlobalContext")) next.inheritGlobalContext = false;
|
|
3111
3115
|
return next;
|
|
3112
3116
|
};
|
|
3113
3117
|
const {
|
|
@@ -3156,7 +3160,7 @@ function editableAgentConfig(agent) {
|
|
|
3156
3160
|
...base.thinking !== void 0 && hasDeclaredField("thinking") ? { thinking: base.thinking } : {},
|
|
3157
3161
|
systemPromptMode: base.systemPromptMode,
|
|
3158
3162
|
inheritProjectContext: base.inheritProjectContext,
|
|
3159
|
-
inheritGlobalContext: base.inheritGlobalContext,
|
|
3163
|
+
inheritGlobalContext: hasDeclaredField("inheritGlobalContext") && base.inheritGlobalContext,
|
|
3160
3164
|
inheritSkills: base.inheritSkills,
|
|
3161
3165
|
...base.defaultContext !== void 0 ? { defaultContext: base.defaultContext } : {},
|
|
3162
3166
|
...base.acceptanceRole !== void 0 ? { acceptanceRole: base.acceptanceRole } : {},
|
|
@@ -3765,7 +3769,8 @@ function handleList(params, ctx) {
|
|
|
3765
3769
|
let scopedAgents = effectiveAgentsForScope(scope, d, ctx.runtimeAgentOwner, ctx.model?.provider);
|
|
3766
3770
|
scopedAgents = scopedAgents.sort((a, b) => a.name.localeCompare(b.name));
|
|
3767
3771
|
const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.piSessionId);
|
|
3768
|
-
const
|
|
3772
|
+
const search = typeof params.search === "string" ? params.search.trim().toLowerCase() : "";
|
|
3773
|
+
const visibleAgents = scopedAgents.filter((a) => !a.disabled && (!search || [a.name, a.description, ...a.aliases ?? []].some((text2) => text2.toLowerCase().includes(search))));
|
|
3769
3774
|
const agents = visibleAgents.filter((a) => isAgentAllowedByCapabilityCeiling(a.name, capabilityCeiling));
|
|
3770
3775
|
const restrictedAgents = visibleAgents.filter((a) => !isAgentAllowedByCapabilityCeiling(a.name, capabilityCeiling));
|
|
3771
3776
|
const restrictedSources = capabilityCeilingAgentRestrictionSources(capabilityCeiling);
|
|
@@ -3779,13 +3784,18 @@ function handleList(params, ctx) {
|
|
|
3779
3784
|
const capabilityMode = params.capabilities === true;
|
|
3780
3785
|
const externalCliAvailability = capabilityMode ? externalCliAvailabilityForAgents([...agents, ...restrictedAgents]) : void 0;
|
|
3781
3786
|
const availableModels = capabilityMode ? ctx.modelRegistry.getAvailable().map(toModelInfo) : [];
|
|
3782
|
-
const
|
|
3787
|
+
const knownProviders = knownModelProviders(ctx.modelRegistry);
|
|
3788
|
+
const unavailableModels = new Set([...agents, ...restrictedAgents].filter((agent) => (agent.runner?.type ?? "pi") === "pi" && isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? ctx.model?.provider, knownProviders)));
|
|
3783
3789
|
const formatLine = capabilityMode ? (agent, names) => formatAgentCapabilitiesLine(agent, names, externalCliAvailability, unavailableModels) : formatAgentListLine;
|
|
3790
|
+
const shownAgents = agents.slice(0, MAX_LISTED_AGENTS);
|
|
3791
|
+
const shownRestrictedAgents = restrictedAgents.slice(0, MAX_LISTED_AGENTS - shownAgents.length);
|
|
3792
|
+
const omittedCount = Math.max(0, agents.length + restrictedAgents.length - MAX_LISTED_AGENTS);
|
|
3784
3793
|
const lines = [
|
|
3785
3794
|
capabilityMode ? "Executable agents (capabilities):" : "Executable agents:",
|
|
3786
|
-
...formatAgentListSections(
|
|
3795
|
+
...formatAgentListSections(shownAgents, providerNameSet, formatLine)
|
|
3787
3796
|
];
|
|
3788
|
-
appendRestrictedAgentLines({ lines, agents:
|
|
3797
|
+
appendRestrictedAgentLines({ lines, agents: shownRestrictedAgents, sources: restrictedSources, providerNames: providerNameSet, formatLine });
|
|
3798
|
+
if (omittedCount > 0) lines.push("", `+${omittedCount} more; narrow with {action:"list", options:{search:"<term>"}}`);
|
|
3789
3799
|
appendExternalJobRegistryLine(lines, [...agents, ...restrictedAgents], providerStatus);
|
|
3790
3800
|
appendAgentDiagnosticLines(lines, d.agentDiagnostics);
|
|
3791
3801
|
if (proactiveSuggestions.length) lines.push("", ...proactiveSuggestions);
|
|
@@ -3822,6 +3832,7 @@ function handleModels(params, ctx) {
|
|
|
3822
3832
|
const discovered = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
|
|
3823
3833
|
const effectiveAgents = effectiveAgentsForScope(scope, discovered, ctx.runtimeAgentOwner, ctx.model?.provider).sort((a, b) => a.name.localeCompare(b.name));
|
|
3824
3834
|
const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
3835
|
+
const knownProviders = knownModelProviders(ctx.modelRegistry);
|
|
3825
3836
|
const currentModel = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : void 0;
|
|
3826
3837
|
const preferredProvider = ctx.model?.provider;
|
|
3827
3838
|
const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.piSessionId);
|
|
@@ -3850,8 +3861,8 @@ function handleModels(params, ctx) {
|
|
|
3850
3861
|
];
|
|
3851
3862
|
const modelEntries = selectedAgents.flatMap((agent) => requestedAgent ? [{ agent, name: requestedAgent }] : [{ agent, name: agent.name }, ...(agent.aliases ?? []).map((name) => ({ agent, name }))]);
|
|
3852
3863
|
for (const { agent, name } of modelEntries) {
|
|
3853
|
-
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider);
|
|
3854
|
-
const shownModel = resolvedModel === void 0 ? "(unresolved)" : (agent.runner?.type ?? "pi") === "pi" && isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? preferredProvider) ? `${resolvedModel} ${UNAVAILABLE_MODEL_MARKER}` : resolvedModel;
|
|
3864
|
+
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider, { knownProviders });
|
|
3865
|
+
const shownModel = resolvedModel === void 0 ? "(unresolved)" : (agent.runner?.type ?? "pi") === "pi" && isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? preferredProvider, knownProviders) ? `${resolvedModel} ${UNAVAILABLE_MODEL_MARKER}` : resolvedModel;
|
|
3855
3866
|
const effectiveThinking = resolveEffectiveThinking(resolvedModel, agent.thinking) ?? (agent.thinking === false ? "off" : void 0);
|
|
3856
3867
|
const source = `${formatModelSource(agent, currentModel)}${agent.disabled ? "; disabled" : ""}${isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling) ? "" : "; restricted"}`;
|
|
3857
3868
|
if (requestedAgent) {
|
|
@@ -3966,7 +3977,7 @@ function handleCreate(params, ctx) {
|
|
|
3966
3977
|
if (mw) warnings.push(mw);
|
|
3967
3978
|
const sw = skillsWarning(ctx.cwd, agent);
|
|
3968
3979
|
if (sw) warnings.push(sw);
|
|
3969
|
-
fs7.writeFileSync(targetPath, serializeAgent(agent), "utf-8");
|
|
3980
|
+
fs7.writeFileSync(targetPath, serializeAgent(agent, { explicitInheritGlobalContext: hasKey(cfg, "inheritGlobalContext") }), "utf-8");
|
|
3970
3981
|
ctx.onAgentsChanged?.();
|
|
3971
3982
|
return result4([`Created agent '${runtimeName}' at ${targetPath}.`, ...warnings].join("\n"));
|
|
3972
3983
|
}
|
|
@@ -4356,7 +4367,7 @@ function resolveWatchdogModelInput(ctx, rawModel) {
|
|
|
4356
4367
|
if (!trimmed) throw new Error("Watchdog model must be a non-empty provider/model value.");
|
|
4357
4368
|
const availableModels = modelRegistryEntries(ctx);
|
|
4358
4369
|
const preferredProvider = typeof ctx.model?.provider === "string" ? ctx.model.provider : void 0;
|
|
4359
|
-
const resolved = resolveModelCandidate(trimmed, availableModels, preferredProvider) ?? trimmed;
|
|
4370
|
+
const resolved = resolveModelCandidate(trimmed, availableModels, preferredProvider, knownModelProviders(ctx.modelRegistry)) ?? trimmed;
|
|
4360
4371
|
const { baseModel, thinkingSuffix } = splitKnownThinkingSuffix(resolved);
|
|
4361
4372
|
const named = splitProviderModel(baseModel);
|
|
4362
4373
|
if (!named) throw new Error(`Watchdog model '${rawModel}' did not resolve to provider/model. Use a provider-qualified model such as openai-codex/gpt-5.5:high or anthropic/claude-opus-4-8:high.`);
|
|
@@ -6569,7 +6580,7 @@ function registerPiWebSessionLiveness(registration) {
|
|
|
6569
6580
|
// src/runs/background/wait-subscriptions.ts
|
|
6570
6581
|
import * as fs10 from "node:fs";
|
|
6571
6582
|
import * as path9 from "node:path";
|
|
6572
|
-
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
6583
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "node:crypto";
|
|
6573
6584
|
var SUBSCRIPTION_VERSION = 1;
|
|
6574
6585
|
var STATUS_OUTCOMES = /* @__PURE__ */ new Set(["timed out", "could not be reconciled", "needs attention", "reconciliation failed"]);
|
|
6575
6586
|
var RECONCILE_INTERVAL_MS = 1e3;
|
|
@@ -6581,7 +6592,7 @@ function isNotFound(error2) {
|
|
|
6581
6592
|
function parseRecord(value) {
|
|
6582
6593
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
6583
6594
|
const record = value;
|
|
6584
|
-
if (record.version !== SUBSCRIPTION_VERSION || typeof record.token !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(record.token) || typeof record.sessionId !== "string" || record.targetKind !== "async" && record.targetKind !== "foreground" || typeof record.runId !== "string" || typeof record.requestedId !== "string" || typeof record.createdAt !== "number" || typeof record.expiresAt !== "number") return void 0;
|
|
6595
|
+
if (record.version !== SUBSCRIPTION_VERSION || typeof record.token !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(record.token) || typeof record.sessionId !== "string" || record.completionOwnerId !== void 0 && typeof record.completionOwnerId !== "string" || record.completionOwnerProcess !== void 0 && !isRecordedPid(record.completionOwnerProcess) || record.targetKind !== "async" && record.targetKind !== "foreground" || typeof record.runId !== "string" || typeof record.requestedId !== "string" || typeof record.createdAt !== "number" || typeof record.expiresAt !== "number") return void 0;
|
|
6585
6596
|
return record;
|
|
6586
6597
|
}
|
|
6587
6598
|
function needsAttention(run) {
|
|
@@ -6590,6 +6601,26 @@ function needsAttention(run) {
|
|
|
6590
6601
|
function subscriptionFile(dir, token) {
|
|
6591
6602
|
return path9.join(dir, `${token}.json`);
|
|
6592
6603
|
}
|
|
6604
|
+
function claimPrefix(token, replacedOwnerId) {
|
|
6605
|
+
return `${token}.claim-${createHash3("sha256").update(replacedOwnerId).digest("hex").slice(0, 16)}.`;
|
|
6606
|
+
}
|
|
6607
|
+
function latestClaimGeneration(files, prefix) {
|
|
6608
|
+
let latest = 0;
|
|
6609
|
+
for (const file of files) {
|
|
6610
|
+
const generation = file.startsWith(prefix) ? file.slice(prefix.length) : "";
|
|
6611
|
+
if (/^[1-9][0-9]*$/.test(generation)) latest = Math.max(latest, Number(generation));
|
|
6612
|
+
}
|
|
6613
|
+
return latest;
|
|
6614
|
+
}
|
|
6615
|
+
function removeClaimFiles(dir, token) {
|
|
6616
|
+
try {
|
|
6617
|
+
for (const file of fs10.readdirSync(dir)) {
|
|
6618
|
+
if (file.startsWith(`${token}.claim-`)) fs10.rmSync(path9.join(dir, file), { force: true });
|
|
6619
|
+
}
|
|
6620
|
+
} catch (error2) {
|
|
6621
|
+
if (!isNotFound(error2)) console.error(`Failed to remove claims of wait subscription '${token}':`, error2);
|
|
6622
|
+
}
|
|
6623
|
+
}
|
|
6593
6624
|
function formatWaitSubscriptions(state, now = Date.now()) {
|
|
6594
6625
|
const subscriptions = [...state.waitSubscriptions?.values() ?? []].sort((left, right) => left.createdAt - right.createdAt);
|
|
6595
6626
|
if (subscriptions.length === 0) return void 0;
|
|
@@ -6610,6 +6641,51 @@ function createWaitSubscriptionManager(pi, state, options = {}) {
|
|
|
6610
6641
|
let disposed = false;
|
|
6611
6642
|
let interval;
|
|
6612
6643
|
let lastForeignSweepAt = 0;
|
|
6644
|
+
const readRecordFile = (filePath) => {
|
|
6645
|
+
try {
|
|
6646
|
+
return parseRecord(JSON.parse(fs10.readFileSync(filePath, "utf-8")));
|
|
6647
|
+
} catch (error2) {
|
|
6648
|
+
if (isNotFound(error2)) return void 0;
|
|
6649
|
+
throw error2;
|
|
6650
|
+
}
|
|
6651
|
+
};
|
|
6652
|
+
const isDead = (recorded) => recorded !== void 0 && checkRecordedPidLiveness(recorded, {
|
|
6653
|
+
observedScope: currentPidNamespaceScope(),
|
|
6654
|
+
observedBootId: currentBootId(),
|
|
6655
|
+
kill: options.kill
|
|
6656
|
+
}) === "dead";
|
|
6657
|
+
const latestClaimantHolds = (claimPath) => {
|
|
6658
|
+
let body;
|
|
6659
|
+
try {
|
|
6660
|
+
body = JSON.parse(fs10.readFileSync(claimPath, "utf-8"));
|
|
6661
|
+
} catch (error2) {
|
|
6662
|
+
return !(error2 instanceof SyntaxError);
|
|
6663
|
+
}
|
|
6664
|
+
const claimant = body?.process;
|
|
6665
|
+
return isRecordedPid(claimant) && !isDead(claimant);
|
|
6666
|
+
};
|
|
6667
|
+
const claimRecord = (filePath, record) => {
|
|
6668
|
+
if (!record.completionOwnerId || record.completionOwnerId === state.completionOwnerId) return record;
|
|
6669
|
+
if (!isDead(record.completionOwnerProcess)) return void 0;
|
|
6670
|
+
if (!state.completionOwnerId) return record;
|
|
6671
|
+
const prefix = claimPrefix(record.token, record.completionOwnerId);
|
|
6672
|
+
const latest = latestClaimGeneration(fs10.readdirSync(subscriptionsDir), prefix);
|
|
6673
|
+
if (latest > 0 && latestClaimantHolds(path9.join(subscriptionsDir, `${prefix}${latest}`))) return void 0;
|
|
6674
|
+
const claimPath = path9.join(subscriptionsDir, `${prefix}${latest + 1}`);
|
|
6675
|
+
if (!createClaimFile(claimPath, { ownerId: state.completionOwnerId, process: currentRecordedPid() })) return void 0;
|
|
6676
|
+
try {
|
|
6677
|
+
if (readRecordFile(filePath)?.completionOwnerId !== record.completionOwnerId) {
|
|
6678
|
+
fs10.rmSync(claimPath, { force: true });
|
|
6679
|
+
return void 0;
|
|
6680
|
+
}
|
|
6681
|
+
const claimed = { ...record, completionOwnerId: state.completionOwnerId, completionOwnerProcess: currentRecordedPid() };
|
|
6682
|
+
writeAtomicJson(filePath, claimed);
|
|
6683
|
+
return claimed;
|
|
6684
|
+
} catch (error2) {
|
|
6685
|
+
fs10.rmSync(claimPath, { force: true });
|
|
6686
|
+
throw error2;
|
|
6687
|
+
}
|
|
6688
|
+
};
|
|
6613
6689
|
const sweepExpiredForeignSubscriptions = (force = false) => {
|
|
6614
6690
|
const sweptAt = now();
|
|
6615
6691
|
if (!force && sweptAt - lastForeignSweepAt < FOREIGN_SWEEP_INTERVAL_MS) return;
|
|
@@ -6625,7 +6701,7 @@ function createWaitSubscriptionManager(pi, state, options = {}) {
|
|
|
6625
6701
|
const filePath = path9.join(subscriptionsDir, file);
|
|
6626
6702
|
let record;
|
|
6627
6703
|
try {
|
|
6628
|
-
record =
|
|
6704
|
+
record = readRecordFile(filePath);
|
|
6629
6705
|
} catch (error2) {
|
|
6630
6706
|
console.error(`Ignoring invalid wait subscription '${filePath}':`, error2);
|
|
6631
6707
|
continue;
|
|
@@ -6636,23 +6712,31 @@ function createWaitSubscriptionManager(pi, state, options = {}) {
|
|
|
6636
6712
|
try {
|
|
6637
6713
|
fs10.unlinkSync(filePath);
|
|
6638
6714
|
} catch (error2) {
|
|
6639
|
-
if (!isNotFound(error2))
|
|
6715
|
+
if (!isNotFound(error2)) {
|
|
6716
|
+
console.error(`Failed to remove expired wait subscription '${filePath}':`, error2);
|
|
6717
|
+
continue;
|
|
6718
|
+
}
|
|
6640
6719
|
}
|
|
6720
|
+
removeClaimFiles(subscriptionsDir, record.token);
|
|
6641
6721
|
}
|
|
6642
6722
|
};
|
|
6643
6723
|
const remove = (record) => {
|
|
6724
|
+
let removed = true;
|
|
6644
6725
|
try {
|
|
6645
6726
|
fs10.unlinkSync(subscriptionFile(subscriptionsDir, record.token));
|
|
6646
6727
|
} catch (error2) {
|
|
6647
6728
|
if (!isNotFound(error2)) throw error2;
|
|
6729
|
+
removed = false;
|
|
6648
6730
|
}
|
|
6649
6731
|
subscriptions.delete(record.token);
|
|
6650
6732
|
unresolvedRestoredForegroundTokens.delete(record.token);
|
|
6733
|
+
removeClaimFiles(subscriptionsDir, record.token);
|
|
6734
|
+
return removed;
|
|
6651
6735
|
};
|
|
6652
6736
|
const settle = (record, outcome, detail, completion) => {
|
|
6653
6737
|
if (disposed || state.currentSessionId !== record.sessionId) return;
|
|
6654
6738
|
try {
|
|
6655
|
-
remove(record);
|
|
6739
|
+
if (!remove(record)) return;
|
|
6656
6740
|
} catch (error2) {
|
|
6657
6741
|
console.error(`Failed to clear wait subscription '${record.token}'; it remains armed:`, error2);
|
|
6658
6742
|
return;
|
|
@@ -6765,6 +6849,7 @@ Parent action: ${STATUS_OUTCOMES.has(outcome) ? STATUS_ACTION : COMPLETION_ACTIO
|
|
|
6765
6849
|
version: SUBSCRIPTION_VERSION,
|
|
6766
6850
|
token: randomUUID4(),
|
|
6767
6851
|
sessionId,
|
|
6852
|
+
...state.completionOwnerId ? { completionOwnerId: state.completionOwnerId, completionOwnerProcess: currentRecordedPid() } : {},
|
|
6768
6853
|
targetKind: input.targetKind,
|
|
6769
6854
|
runId: input.runId,
|
|
6770
6855
|
requestedId: input.requestedId,
|
|
@@ -6789,16 +6874,19 @@ Parent action: ${STATUS_OUTCOMES.has(outcome) ? STATUS_ACTION : COMPLETION_ACTIO
|
|
|
6789
6874
|
throw error2;
|
|
6790
6875
|
}
|
|
6791
6876
|
for (const file of files) {
|
|
6877
|
+
const filePath = path9.join(subscriptionsDir, file);
|
|
6878
|
+
let record;
|
|
6792
6879
|
try {
|
|
6793
|
-
const
|
|
6794
|
-
if (!
|
|
6795
|
-
|
|
6796
|
-
subscriptions.set(record.token, record);
|
|
6797
|
-
if (record.targetKind === "foreground" && !state.foregroundRuns?.has(record.runId)) unresolvedRestoredForegroundTokens.add(record.token);
|
|
6798
|
-
}
|
|
6880
|
+
const found = readRecordFile(filePath);
|
|
6881
|
+
if (!found || file !== `${found.token}.json` || found.sessionId !== state.currentSessionId) continue;
|
|
6882
|
+
record = claimRecord(filePath, found);
|
|
6799
6883
|
} catch (error2) {
|
|
6800
|
-
console.error(`
|
|
6884
|
+
console.error(`Failed to restore wait subscription '${filePath}':`, error2);
|
|
6885
|
+
continue;
|
|
6801
6886
|
}
|
|
6887
|
+
if (!record) continue;
|
|
6888
|
+
subscriptions.set(record.token, record);
|
|
6889
|
+
if (record.targetKind === "foreground" && !state.foregroundRuns?.has(record.runId)) unresolvedRestoredForegroundTokens.add(record.token);
|
|
6802
6890
|
}
|
|
6803
6891
|
reconcile();
|
|
6804
6892
|
},
|
|
@@ -7101,6 +7189,7 @@ var CHORD_PEER_ALIASES = [
|
|
|
7101
7189
|
{ specifier: "@earendil-works/chord", pkg: "@earendil-works/chord", subpath: "." },
|
|
7102
7190
|
{ specifier: "@earendil-works/chord/context", pkg: "@earendil-works/chord", subpath: "./context" }
|
|
7103
7191
|
];
|
|
7192
|
+
var SCHEMA_PACKAGE = "@earendil-works/pi-schema";
|
|
7104
7193
|
function readManifest(packageDir) {
|
|
7105
7194
|
try {
|
|
7106
7195
|
return JSON.parse(fs12.readFileSync(path11.join(packageDir, "package.json"), "utf-8"));
|
|
@@ -7191,6 +7280,15 @@ function resolveHostPeerAliases(piPackageRoot) {
|
|
|
7191
7280
|
if (target && fs12.existsSync(target)) aliases[specifier] = fs12.realpathSync(target);
|
|
7192
7281
|
else if (pkg !== CHORD_PACKAGE || chordRequired) missing.push(specifier);
|
|
7193
7282
|
}
|
|
7283
|
+
const piAiDir = findPeerPackageDir(piPackageRoot, "@earendil-works/pi-ai", hostManifest?.name);
|
|
7284
|
+
const piAiManifest = piAiDir ? readManifest(piAiDir) : void 0;
|
|
7285
|
+
if (piAiDir && piAiManifest && declaresDependency(piAiManifest, SCHEMA_PACKAGE)) {
|
|
7286
|
+
const schemaDir = findPeerPackageDir(fs12.realpathSync(piAiDir), SCHEMA_PACKAGE, void 0);
|
|
7287
|
+
for (const subpath of [".", "./formats"]) {
|
|
7288
|
+
const target = schemaDir ? resolvePackageSubpath(schemaDir, subpath) : void 0;
|
|
7289
|
+
if (!target || !fs12.existsSync(target)) missing.push(subpath === "." ? SCHEMA_PACKAGE : `${SCHEMA_PACKAGE}/formats`);
|
|
7290
|
+
}
|
|
7291
|
+
}
|
|
7194
7292
|
return { aliases, missing };
|
|
7195
7293
|
}
|
|
7196
7294
|
|
|
@@ -7462,10 +7560,12 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7462
7560
|
const loadPiCodingAgent = options.loadPiCodingAgent ?? loadHostPiCodingAgent;
|
|
7463
7561
|
const shutdownTimeoutMs = options.shutdownTimeoutMs ?? 5e3;
|
|
7464
7562
|
let runtime;
|
|
7465
|
-
const live = /* @__PURE__ */ new
|
|
7563
|
+
const live = /* @__PURE__ */ new Map();
|
|
7466
7564
|
const shutdowns = /* @__PURE__ */ new Set();
|
|
7467
7565
|
const mcpWaits = /* @__PURE__ */ new Map();
|
|
7468
|
-
let
|
|
7566
|
+
let globalDisposals = 0;
|
|
7567
|
+
const parentDisposals = /* @__PURE__ */ new Map();
|
|
7568
|
+
const parentDisposalEpoch = (parent) => parentDisposals.get(parent) ?? 0;
|
|
7469
7569
|
const sharedRuntime = async (pi) => {
|
|
7470
7570
|
runtime ??= pi.ModelRuntime.create().catch((error2) => {
|
|
7471
7571
|
runtime = void 0;
|
|
@@ -7473,9 +7573,28 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7473
7573
|
});
|
|
7474
7574
|
return runtime;
|
|
7475
7575
|
};
|
|
7576
|
+
const disposeMatching = async (matches) => {
|
|
7577
|
+
for (const [cancel, wait] of mcpWaits) if (matches(wait.parent)) cancel.abort();
|
|
7578
|
+
const children = [...live.keys()].filter((child) => !child.detached && matches(live.get(child)));
|
|
7579
|
+
for (const child of children) child.shutDown = true;
|
|
7580
|
+
await Promise.allSettled(children.map((child) => child.abort()));
|
|
7581
|
+
for (const child of children) {
|
|
7582
|
+
try {
|
|
7583
|
+
void child.dispose();
|
|
7584
|
+
} catch {
|
|
7585
|
+
}
|
|
7586
|
+
}
|
|
7587
|
+
await Promise.allSettled([
|
|
7588
|
+
...shutdowns,
|
|
7589
|
+
...[...mcpWaits.values()].filter((wait) => matches(wait.parent)).map((wait) => wait.ready)
|
|
7590
|
+
]);
|
|
7591
|
+
if (live.size === 0) runtime = void 0;
|
|
7592
|
+
};
|
|
7476
7593
|
return {
|
|
7477
7594
|
async create(launch) {
|
|
7478
|
-
const
|
|
7595
|
+
const globalDisposalsAtStart = globalDisposals;
|
|
7596
|
+
const parentEpochAtStart = parentDisposalEpoch(launch.parentSessionFile);
|
|
7597
|
+
const disposedSinceStart = () => globalDisposals !== globalDisposalsAtStart || parentDisposalEpoch(launch.parentSessionFile) !== parentEpochAtStart;
|
|
7479
7598
|
const pi = await loadPiCodingAgent();
|
|
7480
7599
|
const builtinMcpTools = launch.builtinMcpTools ?? [];
|
|
7481
7600
|
let readinessTool;
|
|
@@ -7624,11 +7743,11 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7624
7743
|
if (builtinMcp) {
|
|
7625
7744
|
const cancel = new AbortController();
|
|
7626
7745
|
const signal = launch.signal ? AbortSignal.any([cancel.signal, launch.signal]) : cancel.signal;
|
|
7627
|
-
if (
|
|
7746
|
+
if (disposedSinceStart()) cancel.abort();
|
|
7628
7747
|
const ready = (async () => {
|
|
7629
7748
|
try {
|
|
7630
7749
|
await builtinMcp.waitForTools(signal, () => loader.getExtensions().errors.find(({ path: path17 }) => path17 === "builtin:mcp")?.error);
|
|
7631
|
-
if (
|
|
7750
|
+
if (disposedSinceStart()) throw new Error("The child session factory was disposed while the child waited for its MCP tools.");
|
|
7632
7751
|
if (signal.aborted) throw new Error("The child launch was cancelled while waiting for its MCP tools.");
|
|
7633
7752
|
const missing = missingBuiltinMcpTools(session, builtinMcpTools.map(({ name }) => name));
|
|
7634
7753
|
if (missing.length) throw new Error(`Selected built-in MCP tools did not register in the child session: ${missing.join(", ")}. The MCP server may have failed to connect, or the name belongs to a different tool than the selector names; check it with /mcp.`);
|
|
@@ -7637,21 +7756,44 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7637
7756
|
throw error2;
|
|
7638
7757
|
}
|
|
7639
7758
|
})();
|
|
7640
|
-
mcpWaits.set(cancel, ready);
|
|
7759
|
+
mcpWaits.set(cancel, { ready, parent: launch.parentSessionFile });
|
|
7641
7760
|
try {
|
|
7642
7761
|
await ready;
|
|
7643
7762
|
} finally {
|
|
7644
7763
|
mcpWaits.delete(cancel);
|
|
7645
7764
|
}
|
|
7646
7765
|
}
|
|
7766
|
+
let reportCompleted = false;
|
|
7767
|
+
const guidanceClosed = "Child completed its acceptance report; resume it for further guidance.";
|
|
7768
|
+
const assertAcceptsGuidance = () => {
|
|
7769
|
+
if (reportCompleted) throw new Error(guidanceClosed);
|
|
7770
|
+
};
|
|
7771
|
+
const rejectQueuedGuidance = () => {
|
|
7772
|
+
session.clearQueue();
|
|
7773
|
+
throw new Error(guidanceClosed);
|
|
7774
|
+
};
|
|
7647
7775
|
const child = {
|
|
7648
|
-
subscribe: (listener) => session.subscribe((event) =>
|
|
7776
|
+
subscribe: (listener) => session.subscribe((event) => {
|
|
7777
|
+
if (event.type === "message_end" && event.message.role === "assistant" && event.message.stopReason === "stop") {
|
|
7778
|
+
const text2 = event.message.content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
7779
|
+
const report = parseAcceptanceReport(text2);
|
|
7780
|
+
if (report.report || report.malformed) {
|
|
7781
|
+
reportCompleted = true;
|
|
7782
|
+
session.clearQueue();
|
|
7783
|
+
session.agent.steer = rejectQueuedGuidance;
|
|
7784
|
+
session.agent.followUp = rejectQueuedGuidance;
|
|
7785
|
+
}
|
|
7786
|
+
}
|
|
7787
|
+
listener(event);
|
|
7788
|
+
}),
|
|
7649
7789
|
prompt: (text2) => session.prompt(text2),
|
|
7650
7790
|
...commands ? { finishCommands: () => commands.finish() } : {},
|
|
7651
7791
|
steer: async (text2) => {
|
|
7792
|
+
assertAcceptsGuidance();
|
|
7652
7793
|
await session.steer(text2);
|
|
7653
7794
|
},
|
|
7654
7795
|
followUp: async (text2) => {
|
|
7796
|
+
assertAcceptsGuidance();
|
|
7655
7797
|
await session.followUp(text2);
|
|
7656
7798
|
},
|
|
7657
7799
|
abort: () => session.abort(),
|
|
@@ -7691,23 +7833,16 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7691
7833
|
return session.model?.contextWindow;
|
|
7692
7834
|
}
|
|
7693
7835
|
};
|
|
7694
|
-
live.
|
|
7836
|
+
live.set(child, launch.parentSessionFile);
|
|
7695
7837
|
return child;
|
|
7696
7838
|
},
|
|
7697
7839
|
async dispose() {
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
try {
|
|
7705
|
-
void child.dispose();
|
|
7706
|
-
} catch {
|
|
7707
|
-
}
|
|
7708
|
-
}
|
|
7709
|
-
await Promise.allSettled([...shutdowns, ...mcpWaits.values()]);
|
|
7710
|
-
if (live.size === 0) runtime = void 0;
|
|
7840
|
+
globalDisposals += 1;
|
|
7841
|
+
await disposeMatching(() => true);
|
|
7842
|
+
},
|
|
7843
|
+
async disposeForParent(parentSessionFile) {
|
|
7844
|
+
parentDisposals.set(parentSessionFile, parentDisposalEpoch(parentSessionFile) + 1);
|
|
7845
|
+
await disposeMatching((parent) => parent === parentSessionFile);
|
|
7711
7846
|
}
|
|
7712
7847
|
};
|
|
7713
7848
|
}
|
|
@@ -7719,28 +7854,28 @@ function childSessionFactory() {
|
|
|
7719
7854
|
}
|
|
7720
7855
|
function createLazyPlacementFactory(local) {
|
|
7721
7856
|
let placed;
|
|
7722
|
-
const factory = async () => placed ??= (await import("./chunk-
|
|
7857
|
+
const factory = async () => placed ??= (await import("./chunk-PJSOS2Q4.js")).createPlacementAwareChildSessionFactory(local);
|
|
7723
7858
|
return {
|
|
7724
7859
|
async create(launch) {
|
|
7725
7860
|
return launch.machine ? (await factory()).create(launch) : local.create(launch);
|
|
7726
7861
|
},
|
|
7727
7862
|
async dispose() {
|
|
7728
|
-
|
|
7729
|
-
|
|
7863
|
+
await (placed ?? local).dispose();
|
|
7864
|
+
},
|
|
7865
|
+
async disposeForParent(parentSessionFile) {
|
|
7866
|
+
await (placed ?? local).disposeForParent(parentSessionFile);
|
|
7730
7867
|
}
|
|
7731
7868
|
};
|
|
7732
7869
|
}
|
|
7733
7870
|
function childSessionFactoryModule() {
|
|
7734
7871
|
return activeFactoryModule;
|
|
7735
7872
|
}
|
|
7736
|
-
async function
|
|
7737
|
-
|
|
7738
|
-
if (!factory) return;
|
|
7739
|
-
await factory.dispose();
|
|
7873
|
+
async function disposeChildSessionsForParent(parentSessionFile) {
|
|
7874
|
+
await activeFactory?.disposeForParent(parentSessionFile);
|
|
7740
7875
|
}
|
|
7741
7876
|
|
|
7742
7877
|
// src/workflows/workflow-reuse.ts
|
|
7743
|
-
import { createHash as
|
|
7878
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
7744
7879
|
import * as fs14 from "node:fs";
|
|
7745
7880
|
import * as path13 from "node:path";
|
|
7746
7881
|
var WORKFLOW_CHILD_JOURNAL_FILE = "workflow-children.jsonl";
|
|
@@ -7752,7 +7887,7 @@ function workflowStopCause(reason) {
|
|
|
7752
7887
|
return reason instanceof Error && "workflowStopCause" in reason && reason.workflowStopCause === WORKFLOW_STOP_CAUSE_RUNTIME_REPLACED ? WORKFLOW_STOP_CAUSE_RUNTIME_REPLACED : void 0;
|
|
7753
7888
|
}
|
|
7754
7889
|
function sha256(text2) {
|
|
7755
|
-
return
|
|
7890
|
+
return createHash4("sha256").update(text2).digest("hex");
|
|
7756
7891
|
}
|
|
7757
7892
|
function workflowScriptDigest(script) {
|
|
7758
7893
|
return sha256(script);
|
|
@@ -7877,7 +8012,7 @@ import { randomUUID as randomUUID6 } from "node:crypto";
|
|
|
7877
8012
|
import * as path14 from "node:path";
|
|
7878
8013
|
var MAX_WORKFLOW_RESUME_ATTEMPTS = 3;
|
|
7879
8014
|
function workflowResumeRefusal(code, reason, runId) {
|
|
7880
|
-
const byHand = code === "launch-missing" || code === "launch-invalid" || code === "structured" || code === "internal" || code === "digest" || code === "authority" ? relaunchByHandText(runId) : code === "capacity" || code === "attempts" || code === "launch-failed" ? resumeByHandText(runId) : "";
|
|
8015
|
+
const byHand = code === "launch-missing" || code === "launch-invalid" || code === "structured" || code === "internal" || code === "digest" || code === "authority" || code === "drained" ? relaunchByHandText(runId) : code === "capacity" || code === "attempts" || code === "launch-failed" ? resumeByHandText(runId) : "";
|
|
7881
8016
|
return { code, reason, byHand };
|
|
7882
8017
|
}
|
|
7883
8018
|
function manualWorkflowResumeRefusalText(runId, refusal) {
|
|
@@ -7907,6 +8042,7 @@ function prepareWorkflowResume(input) {
|
|
|
7907
8042
|
if (trigger === "manual") reconcileAsyncRun(sourceAsyncDir);
|
|
7908
8043
|
const status = readStatus(sourceAsyncDir);
|
|
7909
8044
|
if (!status || status.mode !== "workflow" || !isReusableWorkflowStopCause(status.workflow?.stopCause)) return refuse("not-interrupted", "not interrupted; pass message to revive one of its children");
|
|
8045
|
+
if (status.workflow?.drainRequestedAt !== void 0) return refuse("drained", "it was being drained when it was interrupted");
|
|
7910
8046
|
const attempt = (status.workflow?.resumeOrigin?.attempt ?? 0) + (status.workflow?.stopCause === WORKFLOW_STOP_CAUSE_OWNER_EXITED ? 1 : 0);
|
|
7911
8047
|
if (trigger === "auto" && attempt > MAX_WORKFLOW_RESUME_ATTEMPTS) return refuse("attempts", `${MAX_WORKFLOW_RESUME_ATTEMPTS} resumes already followed Pi exits`);
|
|
7912
8048
|
if (record.source === "structured") return refuse("structured", "launched from tasks/chain");
|
|
@@ -8652,7 +8788,7 @@ export {
|
|
|
8652
8788
|
childSessionHasQueuedMessages,
|
|
8653
8789
|
childSessionFactory,
|
|
8654
8790
|
childSessionFactoryModule,
|
|
8655
|
-
|
|
8791
|
+
disposeChildSessionsForParent,
|
|
8656
8792
|
WORKFLOW_RUNTIME_REPLACED_STOP_NOTICE,
|
|
8657
8793
|
runtimeReplacedAbortReason,
|
|
8658
8794
|
workflowStopCause,
|