@leitwerk-dev/worker 0.1.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/dist/LICENSE +13 -0
- package/dist/automatic-turn-executor.d.ts +28 -0
- package/dist/automatic-turn-executor.d.ts.map +1 -0
- package/dist/automatic-turn-executor.js +58 -0
- package/dist/automatic-turn-executor.js.map +1 -0
- package/dist/chunk-N5HLJDWA.js +8124 -0
- package/dist/chunk-N5HLJDWA.js.map +1 -0
- package/dist/diagnostics.d.ts +23 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +51 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/entry-runtime.d.ts +24 -0
- package/dist/entry-runtime.d.ts.map +1 -0
- package/dist/entry-runtime.js +160 -0
- package/dist/entry-runtime.js.map +1 -0
- package/dist/event-translator.d.ts +8 -0
- package/dist/event-translator.d.ts.map +1 -0
- package/dist/event-translator.js +12 -0
- package/dist/event-translator.js.map +1 -0
- package/dist/extension-entry-roots.d.ts +7 -0
- package/dist/extension-entry-roots.d.ts.map +1 -0
- package/dist/extension-entry-roots.js +41 -0
- package/dist/extension-entry-roots.js.map +1 -0
- package/dist/identified-pi-entry.d.ts +56 -0
- package/dist/identified-pi-entry.d.ts.map +1 -0
- package/dist/identified-pi-entry.js +125 -0
- package/dist/identified-pi-entry.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/input-consumer.d.ts +24 -0
- package/dist/input-consumer.d.ts.map +1 -0
- package/dist/input-consumer.js +34 -0
- package/dist/input-consumer.js.map +1 -0
- package/dist/ipc.d.ts +22 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +192 -0
- package/dist/ipc.js.map +1 -0
- package/dist/logical-prompt-runner.d.ts +49 -0
- package/dist/logical-prompt-runner.d.ts.map +1 -0
- package/dist/logical-prompt-runner.js +225 -0
- package/dist/logical-prompt-runner.js.map +1 -0
- package/dist/managed-pi-agent-dir.d.ts +13 -0
- package/dist/managed-pi-agent-dir.d.ts.map +1 -0
- package/dist/managed-pi-agent-dir.js +66 -0
- package/dist/managed-pi-agent-dir.js.map +1 -0
- package/dist/managed-pi-bootstrap.d.ts +24 -0
- package/dist/managed-pi-bootstrap.d.ts.map +1 -0
- package/dist/managed-pi-bootstrap.js +135 -0
- package/dist/managed-pi-bootstrap.js.map +1 -0
- package/dist/missing-tool-recovery-runner.d.ts +23 -0
- package/dist/missing-tool-recovery-runner.d.ts.map +1 -0
- package/dist/missing-tool-recovery-runner.js +73 -0
- package/dist/missing-tool-recovery-runner.js.map +1 -0
- package/dist/pi-adapter.d.ts +134 -0
- package/dist/pi-adapter.d.ts.map +1 -0
- package/dist/pi-adapter.js +1648 -0
- package/dist/pi-adapter.js.map +1 -0
- package/dist/pi-branch-guard.d.ts +39 -0
- package/dist/pi-branch-guard.d.ts.map +1 -0
- package/dist/pi-branch-guard.js +75 -0
- package/dist/pi-branch-guard.js.map +1 -0
- package/dist/pi-event-reporter.d.ts +15 -0
- package/dist/pi-event-reporter.d.ts.map +1 -0
- package/dist/pi-event-reporter.js +136 -0
- package/dist/pi-event-reporter.js.map +1 -0
- package/dist/pi-resource-bundle.d.ts +12 -0
- package/dist/pi-resource-bundle.d.ts.map +1 -0
- package/dist/pi-resource-bundle.js +58 -0
- package/dist/pi-resource-bundle.js.map +1 -0
- package/dist/pre-turn-targeted-inputs.d.ts +44 -0
- package/dist/pre-turn-targeted-inputs.d.ts.map +1 -0
- package/dist/pre-turn-targeted-inputs.js +101 -0
- package/dist/pre-turn-targeted-inputs.js.map +1 -0
- package/dist/prompt-guards.d.ts +52 -0
- package/dist/prompt-guards.d.ts.map +1 -0
- package/dist/prompt-guards.js +318 -0
- package/dist/prompt-guards.js.map +1 -0
- package/dist/question-bridge.d.ts +16 -0
- package/dist/question-bridge.d.ts.map +1 -0
- package/dist/question-bridge.js +55 -0
- package/dist/question-bridge.js.map +1 -0
- package/dist/question-tool.d.ts +14 -0
- package/dist/question-tool.d.ts.map +1 -0
- package/dist/question-tool.js +54 -0
- package/dist/question-tool.js.map +1 -0
- package/dist/resource-loader-factory.d.ts +11 -0
- package/dist/resource-loader-factory.d.ts.map +1 -0
- package/dist/resource-loader-factory.js +87 -0
- package/dist/resource-loader-factory.js.map +1 -0
- package/dist/result-image-upload.d.ts +14 -0
- package/dist/result-image-upload.d.ts.map +1 -0
- package/dist/result-image-upload.js +183 -0
- package/dist/result-image-upload.js.map +1 -0
- package/dist/runtime/adapters.d.ts +48 -0
- package/dist/runtime/adapters.d.ts.map +1 -0
- package/dist/runtime/adapters.js +15 -0
- package/dist/runtime/adapters.js.map +1 -0
- package/dist/runtime/bootstrap-session.d.ts +95 -0
- package/dist/runtime/bootstrap-session.d.ts.map +1 -0
- package/dist/runtime/bootstrap-session.js +198 -0
- package/dist/runtime/bootstrap-session.js.map +1 -0
- package/dist/runtime/bootstrap.d.ts +81 -0
- package/dist/runtime/bootstrap.d.ts.map +1 -0
- package/dist/runtime/bootstrap.js +440 -0
- package/dist/runtime/bootstrap.js.map +1 -0
- package/dist/runtime/failure-policy.d.ts +79 -0
- package/dist/runtime/failure-policy.d.ts.map +1 -0
- package/dist/runtime/failure-policy.js +182 -0
- package/dist/runtime/failure-policy.js.map +1 -0
- package/dist/runtime/index.d.ts +9 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +326 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/lifecycle-reducer.d.ts +328 -0
- package/dist/runtime/lifecycle-reducer.d.ts.map +1 -0
- package/dist/runtime/lifecycle-reducer.js +1100 -0
- package/dist/runtime/lifecycle-reducer.js.map +1 -0
- package/dist/runtime/llm-turn-execution.d.ts +42 -0
- package/dist/runtime/llm-turn-execution.d.ts.map +1 -0
- package/dist/runtime/llm-turn-execution.js +472 -0
- package/dist/runtime/llm-turn-execution.js.map +1 -0
- package/dist/runtime/settings.d.ts +11 -0
- package/dist/runtime/settings.d.ts.map +1 -0
- package/dist/runtime/settings.js +23 -0
- package/dist/runtime/settings.js.map +1 -0
- package/dist/runtime/snapshot-policy.d.ts +11 -0
- package/dist/runtime/snapshot-policy.d.ts.map +1 -0
- package/dist/runtime/snapshot-policy.js +16 -0
- package/dist/runtime/snapshot-policy.js.map +1 -0
- package/dist/runtime/turn-execution.d.ts +49 -0
- package/dist/runtime/turn-execution.d.ts.map +1 -0
- package/dist/runtime/turn-execution.js +120 -0
- package/dist/runtime/turn-execution.js.map +1 -0
- package/dist/session-snapshot-exchange.d.ts +39 -0
- package/dist/session-snapshot-exchange.d.ts.map +1 -0
- package/dist/session-snapshot-exchange.js +102 -0
- package/dist/session-snapshot-exchange.js.map +1 -0
- package/dist/test-helpers/fake-websocket.d.ts +16 -0
- package/dist/test-helpers/fake-websocket.d.ts.map +1 -0
- package/dist/test-helpers/fake-websocket.js +40 -0
- package/dist/test-helpers/fake-websocket.js.map +1 -0
- package/dist/test-helpers/ipc-harness.d.ts +11 -0
- package/dist/test-helpers/ipc-harness.d.ts.map +1 -0
- package/dist/test-helpers/ipc-harness.js +17 -0
- package/dist/test-helpers/ipc-harness.js.map +1 -0
- package/dist/test-helpers/worker-message-builders.d.ts +21 -0
- package/dist/test-helpers/worker-message-builders.d.ts.map +1 -0
- package/dist/test-helpers/worker-message-builders.js +62 -0
- package/dist/test-helpers/worker-message-builders.js.map +1 -0
- package/dist/turn-continuation.d.ts +28 -0
- package/dist/turn-continuation.d.ts.map +1 -0
- package/dist/turn-continuation.js +80 -0
- package/dist/turn-continuation.js.map +1 -0
- package/dist/turn-execution-error.d.ts +39 -0
- package/dist/turn-execution-error.d.ts.map +1 -0
- package/dist/turn-execution-error.js +64 -0
- package/dist/turn-execution-error.js.map +1 -0
- package/dist/turn-execution-result.d.ts +35 -0
- package/dist/turn-execution-result.d.ts.map +1 -0
- package/dist/turn-execution-result.js +21 -0
- package/dist/turn-execution-result.js.map +1 -0
- package/dist/turn-outcome-tool-session.d.ts +50 -0
- package/dist/turn-outcome-tool-session.d.ts.map +1 -0
- package/dist/turn-outcome-tool-session.js +209 -0
- package/dist/turn-outcome-tool-session.js.map +1 -0
- package/dist/turn-record-id.d.ts +3 -0
- package/dist/turn-record-id.d.ts.map +1 -0
- package/dist/turn-record-id.js +10 -0
- package/dist/turn-record-id.js.map +1 -0
- package/dist/turn-result-markdown.d.ts +74 -0
- package/dist/turn-result-markdown.d.ts.map +1 -0
- package/dist/turn-result-markdown.js +263 -0
- package/dist/turn-result-markdown.js.map +1 -0
- package/dist/turn-tree-strategy.d.ts +29 -0
- package/dist/turn-tree-strategy.d.ts.map +1 -0
- package/dist/turn-tree-strategy.js +80 -0
- package/dist/turn-tree-strategy.js.map +1 -0
- package/dist/worker-entry.d.ts +2 -0
- package/dist/worker-entry.d.ts.map +1 -0
- package/dist/worker-entry.js +7 -0
- package/dist/worker-entry.js.map +1 -0
- package/dist/worker-http.d.ts +2 -0
- package/dist/worker-http.d.ts.map +1 -0
- package/dist/worker-http.js +9 -0
- package/dist/worker-http.js.map +1 -0
- package/dist/worker-ipc-reporter.d.ts +29 -0
- package/dist/worker-ipc-reporter.d.ts.map +1 -0
- package/dist/worker-ipc-reporter.js +58 -0
- package/dist/worker-ipc-reporter.js.map +1 -0
- package/dist/worker-payloads.d.ts +10 -0
- package/dist/worker-payloads.d.ts.map +1 -0
- package/dist/worker-payloads.js +66 -0
- package/dist/worker-payloads.js.map +1 -0
- package/dist/worker-start-payload.d.ts +7 -0
- package/dist/worker-start-payload.d.ts.map +1 -0
- package/dist/worker-start-payload.js +5 -0
- package/dist/worker-start-payload.js.map +1 -0
- package/dist/workspace/manifest.d.ts +35 -0
- package/dist/workspace/manifest.d.ts.map +1 -0
- package/dist/workspace/manifest.js +79 -0
- package/dist/workspace/manifest.js.map +1 -0
- package/dist/workspace/node-run-root-git-ops.d.ts +17 -0
- package/dist/workspace/node-run-root-git-ops.d.ts.map +1 -0
- package/dist/workspace/node-run-root-git-ops.js +96 -0
- package/dist/workspace/node-run-root-git-ops.js.map +1 -0
- package/dist/workspace/resource-aggregator.d.ts +15 -0
- package/dist/workspace/resource-aggregator.d.ts.map +1 -0
- package/dist/workspace/resource-aggregator.js +39 -0
- package/dist/workspace/resource-aggregator.js.map +1 -0
- package/dist/workspace/run-root.d.ts +52 -0
- package/dist/workspace/run-root.d.ts.map +1 -0
- package/dist/workspace/run-root.js +209 -0
- package/dist/workspace/run-root.js.map +1 -0
- package/package.json +55 -0
- package/src/automatic-turn-executor.ts +106 -0
- package/src/diagnostics.ts +82 -0
- package/src/entry-runtime.ts +235 -0
- package/src/event-translator.ts +22 -0
- package/src/extension-entry-roots.ts +43 -0
- package/src/identified-pi-entry.ts +188 -0
- package/src/index.ts +54 -0
- package/src/input-consumer.ts +71 -0
- package/src/ipc.ts +250 -0
- package/src/logical-prompt-runner.ts +320 -0
- package/src/managed-pi-agent-dir.ts +86 -0
- package/src/managed-pi-bootstrap.ts +208 -0
- package/src/missing-tool-recovery-runner.ts +112 -0
- package/src/pi-adapter.ts +2197 -0
- package/src/pi-branch-guard.ts +104 -0
- package/src/pi-event-reporter.ts +164 -0
- package/src/pi-resource-bundle.ts +90 -0
- package/src/pre-turn-targeted-inputs.ts +167 -0
- package/src/prompt-guards.ts +385 -0
- package/src/question-bridge.ts +69 -0
- package/src/question-tool.ts +65 -0
- package/src/resource-loader-factory.ts +115 -0
- package/src/result-image-upload.ts +256 -0
- package/src/runtime/adapters.ts +67 -0
- package/src/runtime/bootstrap-session.ts +294 -0
- package/src/runtime/bootstrap.ts +621 -0
- package/src/runtime/failure-policy.ts +274 -0
- package/src/runtime/index.ts +362 -0
- package/src/runtime/lifecycle-reducer.ts +1537 -0
- package/src/runtime/llm-turn-execution.ts +696 -0
- package/src/runtime/settings.ts +41 -0
- package/src/runtime/snapshot-policy.ts +28 -0
- package/src/runtime/turn-execution.ts +203 -0
- package/src/session-snapshot-exchange.ts +155 -0
- package/src/test-helpers/fake-websocket.ts +46 -0
- package/src/test-helpers/ipc-harness.ts +19 -0
- package/src/test-helpers/worker-message-builders.ts +92 -0
- package/src/turn-continuation.ts +147 -0
- package/src/turn-execution-error.ts +102 -0
- package/src/turn-execution-result.ts +48 -0
- package/src/turn-outcome-tool-session.ts +311 -0
- package/src/turn-record-id.ts +17 -0
- package/src/turn-result-markdown.ts +355 -0
- package/src/turn-tree-strategy.ts +141 -0
- package/src/worker-entry.ts +8 -0
- package/src/worker-http.ts +6 -0
- package/src/worker-ipc-reporter.ts +100 -0
- package/src/worker-payloads.ts +94 -0
- package/src/worker-start-payload.ts +10 -0
- package/src/workspace/manifest.ts +126 -0
- package/src/workspace/node-run-root-git-ops.ts +137 -0
- package/src/workspace/resource-aggregator.ts +43 -0
- package/src/workspace/run-root.ts +361 -0
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type {
|
|
3
|
+
PreparedTurnStart,
|
|
4
|
+
ProcessInstance,
|
|
5
|
+
ProcessProject,
|
|
6
|
+
WorkerBootstrapReceipt,
|
|
7
|
+
} from "@leitwerk-dev/domain";
|
|
8
|
+
import type { ResolvedWorkerProcess } from "@leitwerk-dev/extension-runtime";
|
|
9
|
+
import type {
|
|
10
|
+
RepositoryCredentialRequirement,
|
|
11
|
+
ResolvedProcessPiConfig,
|
|
12
|
+
} from "@leitwerk-dev/process-sdk";
|
|
13
|
+
import { createTemplateContext, resolveProcessPiConfig } from "@leitwerk-dev/process-sdk/pi-config";
|
|
14
|
+
import type { WorkerGitSshCredential, WorkerStartPayload } from "@leitwerk-dev/worker-protocol";
|
|
15
|
+
import type { InputItem } from "../input-consumer.js";
|
|
16
|
+
import {
|
|
17
|
+
resolveManagedPiAgentDir,
|
|
18
|
+
writeManagedPiCredentialFiles,
|
|
19
|
+
} from "../managed-pi-agent-dir.js";
|
|
20
|
+
import {
|
|
21
|
+
assertManagedPiCredentialFiles,
|
|
22
|
+
buildManagedPiCredentialFiles,
|
|
23
|
+
readAndValidateManagedPiResourceManifest,
|
|
24
|
+
} from "../managed-pi-bootstrap.js";
|
|
25
|
+
import type { PiTreeHandle, PiTreeHandleFactory, PiTreePlanningSnapshot } from "../pi-adapter.js";
|
|
26
|
+
import { materializeCanonicalPiResourceBundle } from "../pi-resource-bundle.js";
|
|
27
|
+
import { resolvePreTurnTargetStartSelection } from "../pre-turn-targeted-inputs.js";
|
|
28
|
+
import { planTurnTreeExecution } from "../turn-tree-strategy.js";
|
|
29
|
+
import {
|
|
30
|
+
buildProcessSnapshotSeed,
|
|
31
|
+
inputDeliveryToItem,
|
|
32
|
+
parseProcessSemanticEntryRefsFromStateJson,
|
|
33
|
+
projectSnapshotsFromPayload,
|
|
34
|
+
readProcessProductRefs,
|
|
35
|
+
readProcessSemanticEntryRefs,
|
|
36
|
+
} from "../worker-payloads.js";
|
|
37
|
+
import { isLlmWorkerStartPayload } from "../worker-start-payload.js";
|
|
38
|
+
import {
|
|
39
|
+
materializeRunRoot,
|
|
40
|
+
planRunRoot,
|
|
41
|
+
type RunRootGitOps,
|
|
42
|
+
repairRunRoot,
|
|
43
|
+
validateRunRoot,
|
|
44
|
+
} from "../workspace/run-root.js";
|
|
45
|
+
import type { WorkerRuntimeScheduler } from "./adapters.js";
|
|
46
|
+
|
|
47
|
+
export interface BootstrapWorkerRuntimeDeps {
|
|
48
|
+
instanceId: string;
|
|
49
|
+
payload: WorkerStartPayload;
|
|
50
|
+
piFactory: PiTreeHandleFactory;
|
|
51
|
+
gitOps: RunRootGitOps;
|
|
52
|
+
scheduler: WorkerRuntimeScheduler;
|
|
53
|
+
resolveWorkerProcess?: (
|
|
54
|
+
processId: string,
|
|
55
|
+
opts?: { paramsJson?: string | null; stateJson?: string | null },
|
|
56
|
+
) => ResolvedWorkerProcess | Promise<ResolvedWorkerProcess | undefined> | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface AcceptedStartActivationResult {
|
|
60
|
+
piHandle: PiTreeHandle | null;
|
|
61
|
+
diagnostics: string[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface PreparedStartActivation {
|
|
65
|
+
startPayload: WorkerStartPayload;
|
|
66
|
+
managedAgentDir: string | null;
|
|
67
|
+
managedModelProfileId: string | null;
|
|
68
|
+
workspaceRoot: string;
|
|
69
|
+
sessionCwd: string;
|
|
70
|
+
processSnapshot: ProcessInstance;
|
|
71
|
+
resolvedPiConfig: ResolvedProcessPiConfig;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface BootstrapWorkerRuntimeResult {
|
|
75
|
+
startPayload: WorkerStartPayload;
|
|
76
|
+
resolvedWorkerProcess?: ResolvedWorkerProcess;
|
|
77
|
+
projectSnapshots: ProcessProject[];
|
|
78
|
+
processSnapshot: ProcessInstance;
|
|
79
|
+
activation: PreparedStartActivation;
|
|
80
|
+
resolvedPiConfig: ResolvedProcessPiConfig;
|
|
81
|
+
diagnostics: string[];
|
|
82
|
+
readyPayload: {
|
|
83
|
+
resumed: boolean;
|
|
84
|
+
primaryTreeFile: string;
|
|
85
|
+
workspaceRoot: string;
|
|
86
|
+
aggregatedAgentsSources: string[];
|
|
87
|
+
loadedSkills: string[];
|
|
88
|
+
loadedAgentsFiles: Array<{ path: string; sizeBytes: number }>;
|
|
89
|
+
loadedSkillFiles: Array<{ name: string; path: string }>;
|
|
90
|
+
rootEntryId: string | null;
|
|
91
|
+
receipt: WorkerBootstrapReceipt;
|
|
92
|
+
};
|
|
93
|
+
pendingInputs: InputItem[];
|
|
94
|
+
credentialRefresh?: {
|
|
95
|
+
agentDir: string;
|
|
96
|
+
declaredCredentialPaths: readonly string[];
|
|
97
|
+
providerId: string;
|
|
98
|
+
revision: number;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function readNonEmptyString(value: unknown): string | null {
|
|
103
|
+
return typeof value === "string" && value.trim() !== "" ? value : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function withoutCredentialValues(payload: WorkerStartPayload): WorkerStartPayload {
|
|
107
|
+
const withoutRepositoryCredentials = {
|
|
108
|
+
...payload,
|
|
109
|
+
repositoryCredentials: undefined,
|
|
110
|
+
} as WorkerStartPayload;
|
|
111
|
+
if (!isLlmWorkerStartPayload(payload) || !payload.bootstrap.credential) {
|
|
112
|
+
return withoutRepositoryCredentials;
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
...payload,
|
|
116
|
+
repositoryCredentials: undefined,
|
|
117
|
+
bootstrap: {
|
|
118
|
+
...payload.bootstrap,
|
|
119
|
+
credential: { ...payload.bootstrap.credential, values: {} },
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function validateRepositoryCredentials(input: {
|
|
125
|
+
credentials: readonly WorkerGitSshCredential[];
|
|
126
|
+
requirements: readonly RepositoryCredentialRequirement[];
|
|
127
|
+
projectKeys: ReadonlySet<string>;
|
|
128
|
+
}): void {
|
|
129
|
+
const credentialKeys = new Set<string>();
|
|
130
|
+
for (const credential of input.credentials) {
|
|
131
|
+
if (!input.projectKeys.has(credential.projectKey) || credential.kind !== "git_ssh") {
|
|
132
|
+
throw new Error(`Repository credential does not match project '${credential.projectKey}'`);
|
|
133
|
+
}
|
|
134
|
+
if (credentialKeys.has(credential.projectKey)) {
|
|
135
|
+
throw new Error(`Duplicate repository credential for project '${credential.projectKey}'`);
|
|
136
|
+
}
|
|
137
|
+
credentialKeys.add(credential.projectKey);
|
|
138
|
+
}
|
|
139
|
+
const identities = (items: readonly RepositoryCredentialRequirement[]) =>
|
|
140
|
+
new Set(items.map((item) => `${item.projectKey}:${item.kind}:${item.credentialRef}`));
|
|
141
|
+
const delivered = identities(input.credentials);
|
|
142
|
+
const declared = identities(input.requirements);
|
|
143
|
+
if (delivered.size !== declared.size || [...declared].some((item) => !delivered.has(item))) {
|
|
144
|
+
throw new Error("Delivered repository credentials do not exactly satisfy process requirements");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function shouldPreservePersistedLeafForActiveTurnResume(input: {
|
|
149
|
+
processSnapshot: Pick<ProcessInstance, "selectedTurnId" | "currentExecution" | "metadata">;
|
|
150
|
+
payload: Pick<WorkerStartPayload, "resume" | "turnStart">;
|
|
151
|
+
}): boolean {
|
|
152
|
+
if (!input.payload.resume) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (!readNonEmptyString(input.processSnapshot.selectedTurnId)) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
if (
|
|
159
|
+
input.processSnapshot.currentExecution?.kind !== "worker_start" ||
|
|
160
|
+
input.processSnapshot.currentExecution.id !== input.payload.turnStart.id ||
|
|
161
|
+
input.payload.turnStart.state.kind !== "accepted" ||
|
|
162
|
+
!readNonEmptyString(input.payload.turnStart.state.turnRecordId)
|
|
163
|
+
) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
if (readNonEmptyString(input.processSnapshot.metadata?.continueFromPiEntryId)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
if (readNonEmptyString(input.processSnapshot.metadata?.retryForkPiEntryId)) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
type ResumeLeafEntryCandidate = {
|
|
176
|
+
entryId: string;
|
|
177
|
+
source: "continue" | "retry" | "state" | "payload";
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
function resolveResumeLeafEntryCandidates(
|
|
181
|
+
processSnapshot: ProcessInstance,
|
|
182
|
+
payload: WorkerStartPayload,
|
|
183
|
+
): ResumeLeafEntryCandidate[] {
|
|
184
|
+
const candidates: ResumeLeafEntryCandidate[] = [];
|
|
185
|
+
const continueFromPiEntryId =
|
|
186
|
+
typeof processSnapshot.metadata?.continueFromPiEntryId === "string"
|
|
187
|
+
? processSnapshot.metadata.continueFromPiEntryId
|
|
188
|
+
: null;
|
|
189
|
+
if (continueFromPiEntryId) {
|
|
190
|
+
candidates.push({ entryId: continueFromPiEntryId, source: "continue" });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const retryForkPiEntryId =
|
|
194
|
+
typeof processSnapshot.metadata?.retryForkPiEntryId === "string"
|
|
195
|
+
? processSnapshot.metadata.retryForkPiEntryId
|
|
196
|
+
: null;
|
|
197
|
+
if (retryForkPiEntryId && retryForkPiEntryId !== continueFromPiEntryId) {
|
|
198
|
+
candidates.push({ entryId: retryForkPiEntryId, source: "retry" });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const semanticEntryRefs = parseProcessSemanticEntryRefsFromStateJson(processSnapshot.stateJson);
|
|
202
|
+
const stateLeafId = payload.resume
|
|
203
|
+
? (semanticEntryRefs.currentPrimaryPathLeaf?.entryId ?? null)
|
|
204
|
+
: null;
|
|
205
|
+
if (stateLeafId && stateLeafId !== continueFromPiEntryId && stateLeafId !== retryForkPiEntryId) {
|
|
206
|
+
candidates.push({ entryId: stateLeafId, source: "state" });
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const payloadLeafId = payload.resume ? (payload.resumeLeafEntryId ?? null) : null;
|
|
210
|
+
if (
|
|
211
|
+
payloadLeafId &&
|
|
212
|
+
payloadLeafId !== continueFromPiEntryId &&
|
|
213
|
+
payloadLeafId !== retryForkPiEntryId &&
|
|
214
|
+
payloadLeafId !== stateLeafId
|
|
215
|
+
) {
|
|
216
|
+
candidates.push({ entryId: payloadLeafId, source: "payload" });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return candidates;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function requireResumeLeafEntry(
|
|
223
|
+
candidate: ResumeLeafEntryCandidate,
|
|
224
|
+
entryExists: boolean,
|
|
225
|
+
): boolean {
|
|
226
|
+
if (entryExists) return true;
|
|
227
|
+
const subject =
|
|
228
|
+
candidate.source === "continue"
|
|
229
|
+
? "Continuation Pi entry"
|
|
230
|
+
: candidate.source === "retry"
|
|
231
|
+
? "Retry fork Pi entry"
|
|
232
|
+
: null;
|
|
233
|
+
if (subject) {
|
|
234
|
+
throw new Error(
|
|
235
|
+
`${subject} '${candidate.entryId}' was requested but does not exist in the persisted instance tree`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function resolvePlanningRootEntryId(
|
|
242
|
+
snapshot: PiTreePlanningSnapshot,
|
|
243
|
+
leafId: string | null,
|
|
244
|
+
): string | null {
|
|
245
|
+
const entriesById = new Map(snapshot.entries.map((entry) => [entry.id, entry]));
|
|
246
|
+
let current = leafId ? entriesById.get(leafId) : undefined;
|
|
247
|
+
const visited = new Set<string>();
|
|
248
|
+
while (current && !visited.has(current.id)) {
|
|
249
|
+
visited.add(current.id);
|
|
250
|
+
if (!current.parentId) return current.id;
|
|
251
|
+
current = entriesById.get(current.parentId);
|
|
252
|
+
}
|
|
253
|
+
return snapshot.entries.find((entry) => entry.parentId === null)?.id ?? null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function resolvePlanningLeaf(input: {
|
|
257
|
+
snapshot: PiTreePlanningSnapshot;
|
|
258
|
+
processSnapshot: ProcessInstance;
|
|
259
|
+
payload: WorkerStartPayload;
|
|
260
|
+
}): string | null {
|
|
261
|
+
const entryIds = new Set(input.snapshot.entries.map((entry) => entry.id));
|
|
262
|
+
for (const candidate of resolveResumeLeafEntryCandidates(input.processSnapshot, input.payload)) {
|
|
263
|
+
if (requireResumeLeafEntry(candidate, entryIds.has(candidate.entryId)))
|
|
264
|
+
return candidate.entryId;
|
|
265
|
+
}
|
|
266
|
+
return input.snapshot.currentLeafId;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function leadingTargetedInputsAfterOrdinaryInputs(inputs: readonly InputItem[]) {
|
|
270
|
+
const firstTargetedIndex = inputs.findIndex((input) => input.target !== null);
|
|
271
|
+
if (firstTargetedIndex < 0) return [];
|
|
272
|
+
const targeted = [];
|
|
273
|
+
for (const input of inputs.slice(firstTargetedIndex)) {
|
|
274
|
+
if (!input.target) break;
|
|
275
|
+
targeted.push({ ...input, target: input.target });
|
|
276
|
+
}
|
|
277
|
+
return targeted;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function prepareFreshLlmTurnStart(input: {
|
|
281
|
+
payload: WorkerStartPayload;
|
|
282
|
+
processSnapshot: ProcessInstance;
|
|
283
|
+
resolvedWorkerProcess: ResolvedWorkerProcess | undefined;
|
|
284
|
+
piFactory: PiTreeHandleFactory;
|
|
285
|
+
sessionCwd: string;
|
|
286
|
+
pendingInputs: readonly InputItem[];
|
|
287
|
+
}): Promise<PreparedTurnStart> {
|
|
288
|
+
const turnId = input.payload.turnStart.turnId;
|
|
289
|
+
const definition = input.resolvedWorkerProcess?.turns.get(turnId)?.definition;
|
|
290
|
+
if (!definition || definition.kind !== "llm") {
|
|
291
|
+
throw new Error(`Selected LLM turn '${turnId}' is unavailable during worker bootstrap`);
|
|
292
|
+
}
|
|
293
|
+
const snapshot = await input.piFactory.inspectPrimaryTree({
|
|
294
|
+
treeFile: input.payload.treePaths.primaryTreeFile,
|
|
295
|
+
sessionCwd: input.sessionCwd,
|
|
296
|
+
});
|
|
297
|
+
const entryIds = new Set(snapshot.entries.map((entry) => entry.id));
|
|
298
|
+
const continuation = input.payload.turnStart.continuation;
|
|
299
|
+
if (continuation) {
|
|
300
|
+
requireResumeLeafEntry(
|
|
301
|
+
{ entryId: continuation.continueFromPiEntryId, source: "continue" },
|
|
302
|
+
entryIds.has(continuation.continueFromPiEntryId),
|
|
303
|
+
);
|
|
304
|
+
return {
|
|
305
|
+
pathType: definition.branchType,
|
|
306
|
+
contextMode: definition.context,
|
|
307
|
+
startTarget: { kind: "entry", entryId: continuation.continueFromPiEntryId },
|
|
308
|
+
forkPiEntryId: continuation.continueFromPiEntryId,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const currentLeafId = resolvePlanningLeaf({
|
|
313
|
+
snapshot,
|
|
314
|
+
processSnapshot: input.processSnapshot,
|
|
315
|
+
payload: input.payload,
|
|
316
|
+
});
|
|
317
|
+
const targetedInputs = leadingTargetedInputsAfterOrdinaryInputs(input.pendingInputs);
|
|
318
|
+
const plan = planTurnTreeExecution({
|
|
319
|
+
turnDef: definition,
|
|
320
|
+
currentLeafId,
|
|
321
|
+
rootEntryId: resolvePlanningRootEntryId(snapshot, currentLeafId),
|
|
322
|
+
semanticEntryRefs:
|
|
323
|
+
readProcessSemanticEntryRefs(input.resolvedWorkerProcess?.state) ??
|
|
324
|
+
parseProcessSemanticEntryRefsFromStateJson(input.processSnapshot.stateJson),
|
|
325
|
+
productRefs: readProcessProductRefs(input.resolvedWorkerProcess?.state),
|
|
326
|
+
entryExists: (entryId) => entryIds.has(entryId),
|
|
327
|
+
preTurnStartSelection: resolvePreTurnTargetStartSelection(targetedInputs),
|
|
328
|
+
hasPreTurnTargetedInputs: targetedInputs.length > 0,
|
|
329
|
+
});
|
|
330
|
+
return {
|
|
331
|
+
pathType: plan.pathType,
|
|
332
|
+
contextMode: definition.context,
|
|
333
|
+
startTarget: plan.startTarget,
|
|
334
|
+
forkPiEntryId: plan.forkPiEntryId,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
async function restorePrimaryPathLeaf(
|
|
339
|
+
piHandle: PiTreeHandle,
|
|
340
|
+
processSnapshot: ProcessInstance,
|
|
341
|
+
payload: WorkerStartPayload,
|
|
342
|
+
): Promise<string[]> {
|
|
343
|
+
if (shouldPreservePersistedLeafForActiveTurnResume({ processSnapshot, payload })) {
|
|
344
|
+
return [];
|
|
345
|
+
}
|
|
346
|
+
const candidates = resolveResumeLeafEntryCandidates(processSnapshot, payload);
|
|
347
|
+
for (const candidate of candidates) {
|
|
348
|
+
if (!requireResumeLeafEntry(candidate, Boolean(piHandle.getEntry(candidate.entryId)))) continue;
|
|
349
|
+
await piHandle.branch(candidate.entryId);
|
|
350
|
+
return [];
|
|
351
|
+
}
|
|
352
|
+
return candidates.length > 0
|
|
353
|
+
? [
|
|
354
|
+
`Worker bootstrap could not restore any requested primary-path leaf candidates (${candidates.map((candidate) => `${candidate.source}:${candidate.entryId}`).join(", ")}). Continuing with the persisted instance-tree leaf.`,
|
|
355
|
+
]
|
|
356
|
+
: [];
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export async function activatePreparedStart(input: {
|
|
360
|
+
instanceId: string;
|
|
361
|
+
piFactory: PiTreeHandleFactory;
|
|
362
|
+
activation: PreparedStartActivation;
|
|
363
|
+
}): Promise<AcceptedStartActivationResult> {
|
|
364
|
+
const prepared = input.activation;
|
|
365
|
+
if (!isLlmWorkerStartPayload(prepared.startPayload)) {
|
|
366
|
+
return { piHandle: null, diagnostics: [] };
|
|
367
|
+
}
|
|
368
|
+
if (!prepared.managedAgentDir) throw new Error("Managed Pi agent directory is unavailable");
|
|
369
|
+
const piHandle = await input.piFactory.createPrimaryTreeHandle({
|
|
370
|
+
instanceId: input.instanceId,
|
|
371
|
+
treeFile: prepared.startPayload.treePaths.primaryTreeFile,
|
|
372
|
+
workspaceRoot: prepared.workspaceRoot,
|
|
373
|
+
sessionCwd: prepared.sessionCwd,
|
|
374
|
+
resume: prepared.startPayload.resume,
|
|
375
|
+
agentDir: prepared.managedAgentDir,
|
|
376
|
+
configSnapshot: prepared.startPayload.configSnapshot,
|
|
377
|
+
modelProfileId: prepared.managedModelProfileId,
|
|
378
|
+
piConfig: prepared.resolvedPiConfig,
|
|
379
|
+
});
|
|
380
|
+
const diagnostics = await restorePrimaryPathLeaf(
|
|
381
|
+
piHandle,
|
|
382
|
+
prepared.processSnapshot,
|
|
383
|
+
prepared.startPayload,
|
|
384
|
+
);
|
|
385
|
+
return { piHandle, diagnostics };
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export async function bootstrapWorkerRuntime(
|
|
389
|
+
deps: BootstrapWorkerRuntimeDeps,
|
|
390
|
+
): Promise<BootstrapWorkerRuntimeResult> {
|
|
391
|
+
const llmPayload = isLlmWorkerStartPayload(deps.payload) ? deps.payload : null;
|
|
392
|
+
const processId = deps.payload.processSnapshot.processId ?? "";
|
|
393
|
+
const paramsJson = deps.payload.processSnapshot.paramsJson ?? null;
|
|
394
|
+
const stateJson = deps.payload.processSnapshot.stateJson ?? null;
|
|
395
|
+
|
|
396
|
+
// Try the new worker process resolver first
|
|
397
|
+
const resolvedWorkerProcess = deps.resolveWorkerProcess
|
|
398
|
+
? await deps.resolveWorkerProcess(processId, { paramsJson, stateJson })
|
|
399
|
+
: undefined;
|
|
400
|
+
|
|
401
|
+
const projectSnapshots = projectSnapshotsFromPayload(deps.payload.projectSnapshots);
|
|
402
|
+
const repositoryCredentials = deps.payload.repositoryCredentials ?? [];
|
|
403
|
+
const declaredRequirements =
|
|
404
|
+
resolvedWorkerProcess?.repositoryCredentials?.({
|
|
405
|
+
params: resolvedWorkerProcess.params,
|
|
406
|
+
projects: projectSnapshots,
|
|
407
|
+
}) ?? [];
|
|
408
|
+
validateRepositoryCredentials({
|
|
409
|
+
credentials: repositoryCredentials,
|
|
410
|
+
requirements: declaredRequirements,
|
|
411
|
+
projectKeys: new Set(projectSnapshots.map((project) => project.key)),
|
|
412
|
+
});
|
|
413
|
+
deps.gitOps.configureRepositoryCredentials?.(repositoryCredentials);
|
|
414
|
+
const processSnapshot = buildProcessSnapshotSeed(processId, deps.payload.processSnapshot);
|
|
415
|
+
|
|
416
|
+
const workspaceRoot = deps.payload.treePaths.workspaceRoot;
|
|
417
|
+
const runRootProjects = projectSnapshots.map((project) => ({
|
|
418
|
+
key: project.key,
|
|
419
|
+
repoLocator: project.repoLocator,
|
|
420
|
+
repoLocatorKind: project.repoLocatorKind,
|
|
421
|
+
baseBranch: project.baseBranch,
|
|
422
|
+
workBranch: project.workBranch ?? "",
|
|
423
|
+
}));
|
|
424
|
+
const plan = planRunRoot(workspaceRoot, deps.instanceId, runRootProjects);
|
|
425
|
+
|
|
426
|
+
let aggregatedAgentsMdSources: string[] = [];
|
|
427
|
+
let loadedSkills: string[] = [];
|
|
428
|
+
|
|
429
|
+
if (!deps.payload.resume) {
|
|
430
|
+
const materialized = await materializeRunRoot(plan, deps.gitOps);
|
|
431
|
+
aggregatedAgentsMdSources = materialized.aggregatedAgentsMdSources;
|
|
432
|
+
loadedSkills = materialized.loadedSkills;
|
|
433
|
+
} else {
|
|
434
|
+
const validation = await validateRunRoot(workspaceRoot, runRootProjects, deps.gitOps);
|
|
435
|
+
const repaired = await repairRunRoot(workspaceRoot, validation, plan, deps.gitOps);
|
|
436
|
+
aggregatedAgentsMdSources = repaired.aggregatedAgentsMdSources;
|
|
437
|
+
loadedSkills = repaired.loadedSkills;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const resolvedPiConfig = llmPayload
|
|
441
|
+
? resolveProcessPiConfig({
|
|
442
|
+
processId,
|
|
443
|
+
processPiConfig: resolvedWorkerProcess?.piConfig,
|
|
444
|
+
turns: resolvedWorkerProcess?.turns?.values(),
|
|
445
|
+
configSnapshot: llmPayload.configSnapshot,
|
|
446
|
+
templateContext: createTemplateContext({
|
|
447
|
+
params: resolvedWorkerProcess?.params,
|
|
448
|
+
process: processSnapshot,
|
|
449
|
+
projects: projectSnapshots,
|
|
450
|
+
}),
|
|
451
|
+
})
|
|
452
|
+
: { systemPrompt: "", availableToolNames: [] };
|
|
453
|
+
|
|
454
|
+
const sessionCwd = resolvedPiConfig.sessionCwd
|
|
455
|
+
? path.resolve(workspaceRoot, resolvedPiConfig.sessionCwd)
|
|
456
|
+
: workspaceRoot;
|
|
457
|
+
const pendingInputs = (deps.payload.pendingInputs ?? []).map(inputDeliveryToItem);
|
|
458
|
+
const diagnostics: string[] = [];
|
|
459
|
+
let managedAgentDir: string | null = null;
|
|
460
|
+
let credentialRefresh: BootstrapWorkerRuntimeResult["credentialRefresh"];
|
|
461
|
+
let managedModelProfileId: string | null = null;
|
|
462
|
+
let loadedAgentsFiles: Array<{ path: string; sizeBytes: number }> = [];
|
|
463
|
+
let loadedSkillFiles: Array<{ name: string; path: string }> = [];
|
|
464
|
+
let receipt: WorkerBootstrapReceipt;
|
|
465
|
+
if (llmPayload) {
|
|
466
|
+
const start =
|
|
467
|
+
deps.payload.turnStart.state.kind === "starting" ||
|
|
468
|
+
deps.payload.turnStart.state.kind === "accepted"
|
|
469
|
+
? deps.payload.turnStart.state.start
|
|
470
|
+
: null;
|
|
471
|
+
if (!start || start.kind !== "llm")
|
|
472
|
+
throw new Error("LLM worker start lacks resolved LLM inputs");
|
|
473
|
+
const configuredProfile = llmPayload.configSnapshot.pi.model_profiles.find(
|
|
474
|
+
(profile) => profile.id === start.model.profileId,
|
|
475
|
+
);
|
|
476
|
+
if (
|
|
477
|
+
!configuredProfile ||
|
|
478
|
+
configuredProfile.provider !== start.model.providerId ||
|
|
479
|
+
configuredProfile.model_id !== start.model.modelId
|
|
480
|
+
) {
|
|
481
|
+
throw new Error("Resolved LLM start model does not match the worker model catalog");
|
|
482
|
+
}
|
|
483
|
+
managedModelProfileId = start.model.profileId;
|
|
484
|
+
if (start.piResourceSnapshotDigest !== llmPayload.bootstrap.resourceBundle.digest) {
|
|
485
|
+
throw new Error("LLM worker start resource digest does not match the delivered bundle");
|
|
486
|
+
}
|
|
487
|
+
if (
|
|
488
|
+
deps.payload.processSnapshot.selectedTurnModelProfileId !== undefined &&
|
|
489
|
+
deps.payload.processSnapshot.selectedTurnModelProfileId !== null &&
|
|
490
|
+
deps.payload.processSnapshot.selectedTurnModelProfileId !== start.model.profileId
|
|
491
|
+
) {
|
|
492
|
+
throw new Error("Selected model profile does not match the resolved LLM start");
|
|
493
|
+
}
|
|
494
|
+
const root = llmPayload.configSnapshot.pi.agent_dir;
|
|
495
|
+
managedAgentDir = resolveManagedPiAgentDir({
|
|
496
|
+
agentDirRoot: root,
|
|
497
|
+
instanceId: deps.instanceId,
|
|
498
|
+
startOrLeaseId: deps.payload.workerLeaseId,
|
|
499
|
+
});
|
|
500
|
+
await materializeCanonicalPiResourceBundle({
|
|
501
|
+
bundle: Buffer.from(llmPayload.bootstrap.resourceBundle.archiveBase64, "base64"),
|
|
502
|
+
digest: llmPayload.bootstrap.resourceBundle.digest,
|
|
503
|
+
targetDir: managedAgentDir,
|
|
504
|
+
});
|
|
505
|
+
const manifest = await readAndValidateManagedPiResourceManifest({
|
|
506
|
+
agentDir: managedAgentDir,
|
|
507
|
+
resourceDigest: llmPayload.bootstrap.resourceBundle.digest,
|
|
508
|
+
start,
|
|
509
|
+
});
|
|
510
|
+
const deliveredCredential = llmPayload.bootstrap.credential;
|
|
511
|
+
await writeManagedPiCredentialFiles(
|
|
512
|
+
managedAgentDir,
|
|
513
|
+
buildManagedPiCredentialFiles({
|
|
514
|
+
manifest,
|
|
515
|
+
credential: deliveredCredential,
|
|
516
|
+
providerId: start.model.providerId,
|
|
517
|
+
}),
|
|
518
|
+
);
|
|
519
|
+
await assertManagedPiCredentialFiles({
|
|
520
|
+
agentDir: managedAgentDir,
|
|
521
|
+
manifest,
|
|
522
|
+
credential: deliveredCredential,
|
|
523
|
+
});
|
|
524
|
+
const prepared = await deps.piFactory.prepareManagedBootstrap({
|
|
525
|
+
agentDir: managedAgentDir,
|
|
526
|
+
workspaceRoot,
|
|
527
|
+
sessionCwd,
|
|
528
|
+
configSnapshot: llmPayload.configSnapshot,
|
|
529
|
+
piConfig: resolvedPiConfig,
|
|
530
|
+
manifest,
|
|
531
|
+
expectedModel: { providerId: start.model.providerId, modelId: start.model.modelId },
|
|
532
|
+
});
|
|
533
|
+
if (
|
|
534
|
+
prepared.resolvedModel.providerId !== start.model.providerId ||
|
|
535
|
+
prepared.resolvedModel.modelId !== start.model.modelId
|
|
536
|
+
) {
|
|
537
|
+
throw new Error("Prepared Pi model does not match the resolved LLM start");
|
|
538
|
+
}
|
|
539
|
+
diagnostics.push(...prepared.diagnostics);
|
|
540
|
+
loadedAgentsFiles = prepared.loadedAgentsFiles;
|
|
541
|
+
loadedSkillFiles = prepared.loadedSkillFiles;
|
|
542
|
+
const credentialRevision = deliveredCredential?.revision ?? null;
|
|
543
|
+
if (deliveredCredential && credentialRevision !== null) {
|
|
544
|
+
credentialRefresh = {
|
|
545
|
+
agentDir: managedAgentDir,
|
|
546
|
+
declaredCredentialPaths: manifest.declaredCredentialPaths,
|
|
547
|
+
providerId: deliveredCredential.providerId,
|
|
548
|
+
revision: credentialRevision,
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
const preparedStart =
|
|
552
|
+
deps.payload.turnStart.state.kind === "accepted"
|
|
553
|
+
? deps.payload.acceptedPreparedStart
|
|
554
|
+
: await prepareFreshLlmTurnStart({
|
|
555
|
+
payload: deps.payload,
|
|
556
|
+
processSnapshot,
|
|
557
|
+
resolvedWorkerProcess,
|
|
558
|
+
piFactory: deps.piFactory,
|
|
559
|
+
sessionCwd,
|
|
560
|
+
pendingInputs,
|
|
561
|
+
});
|
|
562
|
+
if (!preparedStart) {
|
|
563
|
+
throw new Error("Accepted LLM worker start lacks its original prepared tree start");
|
|
564
|
+
}
|
|
565
|
+
receipt = {
|
|
566
|
+
kind: "llm",
|
|
567
|
+
startRecordId: deps.payload.turnStart.id,
|
|
568
|
+
workerLeaseId: deps.payload.workerLeaseId,
|
|
569
|
+
receiptEpoch: deps.payload.workerLeaseId,
|
|
570
|
+
verifiedResourceSnapshotDigest: llmPayload.bootstrap.resourceBundle.digest,
|
|
571
|
+
credentialRevision,
|
|
572
|
+
loadedResourceIds: prepared.loadedResourceIds,
|
|
573
|
+
resolvedModel: { providerId: start.model.providerId, modelId: start.model.modelId },
|
|
574
|
+
preparedStart,
|
|
575
|
+
readyAt: deps.scheduler.now().toISOString(),
|
|
576
|
+
};
|
|
577
|
+
} else {
|
|
578
|
+
receipt = {
|
|
579
|
+
kind: "automatic",
|
|
580
|
+
startRecordId: deps.payload.turnStart.id,
|
|
581
|
+
workerLeaseId: deps.payload.workerLeaseId,
|
|
582
|
+
receiptEpoch: deps.payload.workerLeaseId,
|
|
583
|
+
readyAt: deps.scheduler.now().toISOString(),
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
// Pi credentials are file-backed after bootstrap. The complete result and
|
|
587
|
+
// deferred activation must not retain or mutate the IPC credential values.
|
|
588
|
+
const startPayload = withoutCredentialValues(deps.payload);
|
|
589
|
+
const activation: PreparedStartActivation = {
|
|
590
|
+
startPayload,
|
|
591
|
+
managedAgentDir,
|
|
592
|
+
managedModelProfileId,
|
|
593
|
+
workspaceRoot,
|
|
594
|
+
sessionCwd,
|
|
595
|
+
processSnapshot,
|
|
596
|
+
resolvedPiConfig,
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
return {
|
|
600
|
+
startPayload,
|
|
601
|
+
resolvedWorkerProcess,
|
|
602
|
+
projectSnapshots,
|
|
603
|
+
processSnapshot,
|
|
604
|
+
activation,
|
|
605
|
+
resolvedPiConfig,
|
|
606
|
+
diagnostics,
|
|
607
|
+
readyPayload: {
|
|
608
|
+
resumed: deps.payload.resume,
|
|
609
|
+
primaryTreeFile: deps.payload.treePaths.primaryTreeFile,
|
|
610
|
+
workspaceRoot: deps.payload.treePaths.workspaceRoot,
|
|
611
|
+
aggregatedAgentsSources: aggregatedAgentsMdSources,
|
|
612
|
+
loadedSkills,
|
|
613
|
+
loadedAgentsFiles,
|
|
614
|
+
loadedSkillFiles,
|
|
615
|
+
rootEntryId: null,
|
|
616
|
+
receipt,
|
|
617
|
+
},
|
|
618
|
+
pendingInputs,
|
|
619
|
+
...(credentialRefresh ? { credentialRefresh } : {}),
|
|
620
|
+
};
|
|
621
|
+
}
|