@leitwerk-dev/worker 0.1.9 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/automatic-turn-executor.d.ts +1 -0
- package/dist/automatic-turn-executor.d.ts.map +1 -1
- package/dist/{chunk-O6332GRG.js → chunk-2LLFMCR6.js} +1511 -1071
- package/dist/chunk-2LLFMCR6.js.map +1 -0
- package/dist/connection-diagnostics.d.ts +5 -0
- package/dist/connection-diagnostics.d.ts.map +1 -0
- package/dist/container-entry-main.d.ts +2 -0
- package/dist/container-entry-main.d.ts.map +1 -0
- package/dist/container-entry-main.js +232 -0
- package/dist/container-entry-main.js.map +1 -0
- package/dist/container-entry.d.ts +14 -0
- package/dist/container-entry.d.ts.map +1 -0
- package/dist/development-tool-environment.d.ts +84 -0
- package/dist/development-tool-environment.d.ts.map +1 -0
- package/dist/diagnostics.d.ts +4 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/docker-registry-credentials.d.ts +8 -0
- package/dist/docker-registry-credentials.d.ts.map +1 -0
- package/dist/entry-runtime.d.ts +19 -0
- package/dist/entry-runtime.d.ts.map +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/input-consumer.d.ts +7 -11
- package/dist/input-consumer.d.ts.map +1 -1
- package/dist/ipc.d.ts +10 -0
- package/dist/ipc.d.ts.map +1 -1
- package/dist/logical-prompt-runner.d.ts.map +1 -1
- package/dist/managed-pi-agent-dir.d.ts +8 -1
- package/dist/managed-pi-agent-dir.d.ts.map +1 -1
- package/dist/managed-pi-bootstrap.d.ts +1 -0
- package/dist/managed-pi-bootstrap.d.ts.map +1 -1
- package/dist/missing-tool-recovery-runner.d.ts +4 -3
- package/dist/missing-tool-recovery-runner.d.ts.map +1 -1
- package/dist/pi-adapter.d.ts +88 -1
- package/dist/pi-adapter.d.ts.map +1 -1
- package/dist/pi-event-reporter.d.ts.map +1 -1
- package/dist/pi-resource-bundle.d.ts +17 -1
- package/dist/pi-resource-bundle.d.ts.map +1 -1
- package/dist/pre-turn-targeted-inputs.d.ts +8 -7
- package/dist/pre-turn-targeted-inputs.d.ts.map +1 -1
- package/dist/prompt-guards.d.ts +6 -0
- package/dist/prompt-guards.d.ts.map +1 -1
- package/dist/repository-bash-tool.d.ts +4 -0
- package/dist/repository-bash-tool.d.ts.map +1 -0
- package/dist/resource-loader-factory.d.ts +1 -2
- package/dist/resource-loader-factory.d.ts.map +1 -1
- package/dist/result-image-upload.d.ts.map +1 -1
- package/dist/runtime/adapters.d.ts +38 -0
- package/dist/runtime/adapters.d.ts.map +1 -1
- package/dist/runtime/bootstrap-session.d.ts +9 -5
- package/dist/runtime/bootstrap-session.d.ts.map +1 -1
- package/dist/runtime/bootstrap.d.ts +38 -18
- package/dist/runtime/bootstrap.d.ts.map +1 -1
- package/dist/runtime/failure-policy.d.ts +1 -0
- package/dist/runtime/failure-policy.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +4 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/lifecycle-reducer.d.ts.map +1 -1
- package/dist/runtime/llm-turn-execution.d.ts +3 -8
- package/dist/runtime/llm-turn-execution.d.ts.map +1 -1
- package/dist/runtime/turn-execution.d.ts +2 -9
- package/dist/runtime/turn-execution.d.ts.map +1 -1
- package/dist/session-snapshot-exchange.d.ts +10 -4
- package/dist/session-snapshot-exchange.d.ts.map +1 -1
- package/dist/turn-continuation.d.ts.map +1 -1
- package/dist/turn-execution-error.d.ts +1 -1
- package/dist/turn-execution-error.d.ts.map +1 -1
- package/dist/turn-execution-result.d.ts +1 -0
- package/dist/turn-execution-result.d.ts.map +1 -1
- package/dist/turn-outcome-tool-session.d.ts +0 -2
- package/dist/turn-outcome-tool-session.d.ts.map +1 -1
- package/dist/turn-result-markdown.d.ts +2 -1
- package/dist/turn-result-markdown.d.ts.map +1 -1
- package/dist/turn-tree-strategy.d.ts +0 -1
- package/dist/turn-tree-strategy.d.ts.map +1 -1
- package/dist/worker-entry.js +16 -4
- package/dist/worker-entry.js.map +1 -1
- package/dist/worker-ipc-reporter.d.ts.map +1 -1
- package/dist/workspace/manifest.d.ts +4 -7
- package/dist/workspace/manifest.d.ts.map +1 -1
- package/dist/workspace/node-run-root-git-ops.d.ts +2 -2
- package/dist/workspace/node-run-root-git-ops.d.ts.map +1 -1
- package/dist/workspace/resource-aggregator.d.ts.map +1 -1
- package/dist/workspace/run-root.d.ts +21 -20
- package/dist/workspace/run-root.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/automatic-turn-executor.ts +2 -0
- package/src/connection-diagnostics.ts +27 -0
- package/src/container-entry-main.ts +24 -0
- package/src/container-entry.ts +246 -0
- package/src/development-tool-environment.ts +490 -0
- package/src/diagnostics.ts +1 -0
- package/src/docker-registry-credentials.ts +65 -0
- package/src/entry-runtime.ts +29 -5
- package/src/index.ts +1 -39
- package/src/input-consumer.ts +8 -29
- package/src/ipc.ts +50 -2
- package/src/logical-prompt-runner.ts +23 -29
- package/src/managed-pi-agent-dir.ts +8 -1
- package/src/managed-pi-bootstrap.ts +4 -3
- package/src/missing-tool-recovery-runner.ts +4 -18
- package/src/pi-adapter.ts +125 -56
- package/src/pi-event-reporter.ts +16 -38
- package/src/pi-resource-bundle.ts +77 -3
- package/src/pre-turn-targeted-inputs.ts +9 -11
- package/src/prompt-guards.ts +50 -75
- package/src/repository-bash-tool.ts +15 -0
- package/src/resource-loader-factory.ts +1 -18
- package/src/result-image-upload.ts +16 -27
- package/src/runtime/adapters.ts +46 -4
- package/src/runtime/bootstrap-session.ts +70 -39
- package/src/runtime/bootstrap.ts +184 -101
- package/src/runtime/failure-policy.ts +36 -42
- package/src/runtime/index.ts +47 -15
- package/src/runtime/lifecycle-reducer.ts +71 -173
- package/src/runtime/llm-turn-execution.ts +13 -30
- package/src/runtime/turn-execution.ts +78 -31
- package/src/session-snapshot-exchange.ts +46 -68
- package/src/turn-continuation.ts +9 -17
- package/src/turn-execution-error.ts +3 -11
- package/src/turn-execution-result.ts +1 -0
- package/src/turn-outcome-tool-session.ts +25 -21
- package/src/turn-result-markdown.ts +31 -34
- package/src/turn-tree-strategy.ts +6 -19
- package/src/worker-entry.ts +8 -0
- package/src/worker-ipc-reporter.ts +8 -16
- package/src/workspace/manifest.ts +5 -7
- package/src/workspace/node-run-root-git-ops.ts +65 -25
- package/src/workspace/resource-aggregator.ts +5 -16
- package/src/workspace/run-root.ts +50 -89
- package/dist/automatic-turn-executor.js +0 -58
- package/dist/automatic-turn-executor.js.map +0 -1
- package/dist/chunk-O6332GRG.js.map +0 -1
- package/dist/diagnostics.js +0 -51
- package/dist/diagnostics.js.map +0 -1
- package/dist/entry-runtime.js +0 -160
- package/dist/entry-runtime.js.map +0 -1
- package/dist/event-translator.js +0 -12
- package/dist/event-translator.js.map +0 -1
- package/dist/extension-entry-roots.js +0 -41
- package/dist/extension-entry-roots.js.map +0 -1
- package/dist/identified-pi-entry.js +0 -125
- package/dist/identified-pi-entry.js.map +0 -1
- package/dist/input-consumer.js +0 -34
- package/dist/input-consumer.js.map +0 -1
- package/dist/integration-tool-bridge.js +0 -53
- package/dist/integration-tool-bridge.js.map +0 -1
- package/dist/ipc.js +0 -192
- package/dist/ipc.js.map +0 -1
- package/dist/logical-prompt-runner.js +0 -225
- package/dist/logical-prompt-runner.js.map +0 -1
- package/dist/managed-pi-agent-dir.js +0 -66
- package/dist/managed-pi-agent-dir.js.map +0 -1
- package/dist/managed-pi-bootstrap.js +0 -135
- package/dist/managed-pi-bootstrap.js.map +0 -1
- package/dist/missing-tool-recovery-runner.js +0 -73
- package/dist/missing-tool-recovery-runner.js.map +0 -1
- package/dist/pi-adapter.js +0 -1648
- package/dist/pi-adapter.js.map +0 -1
- package/dist/pi-branch-guard.js +0 -75
- package/dist/pi-branch-guard.js.map +0 -1
- package/dist/pi-event-reporter.js +0 -136
- package/dist/pi-event-reporter.js.map +0 -1
- package/dist/pi-resource-bundle.js +0 -58
- package/dist/pi-resource-bundle.js.map +0 -1
- package/dist/pre-turn-targeted-inputs.js +0 -101
- package/dist/pre-turn-targeted-inputs.js.map +0 -1
- package/dist/prompt-guards.js +0 -318
- package/dist/prompt-guards.js.map +0 -1
- package/dist/question-bridge.js +0 -24
- package/dist/question-bridge.js.map +0 -1
- package/dist/question-tool.js +0 -54
- package/dist/question-tool.js.map +0 -1
- package/dist/replaying-request-bridge.js +0 -71
- package/dist/replaying-request-bridge.js.map +0 -1
- package/dist/resource-loader-factory.js +0 -87
- package/dist/resource-loader-factory.js.map +0 -1
- package/dist/result-image-upload.js +0 -183
- package/dist/result-image-upload.js.map +0 -1
- package/dist/runtime/adapters.js +0 -15
- package/dist/runtime/adapters.js.map +0 -1
- package/dist/runtime/bootstrap-session.js +0 -199
- package/dist/runtime/bootstrap-session.js.map +0 -1
- package/dist/runtime/bootstrap.js +0 -440
- package/dist/runtime/bootstrap.js.map +0 -1
- package/dist/runtime/failure-policy.js +0 -182
- package/dist/runtime/failure-policy.js.map +0 -1
- package/dist/runtime/index.js +0 -339
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/lifecycle-reducer.js +0 -1142
- package/dist/runtime/lifecycle-reducer.js.map +0 -1
- package/dist/runtime/llm-turn-execution.js +0 -494
- package/dist/runtime/llm-turn-execution.js.map +0 -1
- package/dist/runtime/settings.js +0 -24
- package/dist/runtime/settings.js.map +0 -1
- package/dist/runtime/snapshot-policy.js +0 -16
- package/dist/runtime/snapshot-policy.js.map +0 -1
- package/dist/runtime/turn-execution.js +0 -151
- package/dist/runtime/turn-execution.js.map +0 -1
- package/dist/session-snapshot-exchange.js +0 -102
- package/dist/session-snapshot-exchange.js.map +0 -1
- package/dist/test-helpers/fake-websocket.js +0 -40
- package/dist/test-helpers/fake-websocket.js.map +0 -1
- package/dist/test-helpers/ipc-harness.d.ts +0 -11
- package/dist/test-helpers/ipc-harness.d.ts.map +0 -1
- package/dist/test-helpers/ipc-harness.js +0 -17
- package/dist/test-helpers/ipc-harness.js.map +0 -1
- package/dist/turn-continuation.js +0 -80
- package/dist/turn-continuation.js.map +0 -1
- package/dist/turn-execution-error.js +0 -64
- package/dist/turn-execution-error.js.map +0 -1
- package/dist/turn-execution-result.js +0 -21
- package/dist/turn-execution-result.js.map +0 -1
- package/dist/turn-outcome-tool-session.js +0 -210
- package/dist/turn-outcome-tool-session.js.map +0 -1
- package/dist/turn-record-id.js +0 -10
- package/dist/turn-record-id.js.map +0 -1
- package/dist/turn-result-markdown.js +0 -263
- package/dist/turn-result-markdown.js.map +0 -1
- package/dist/turn-tree-strategy.js +0 -80
- package/dist/turn-tree-strategy.js.map +0 -1
- package/dist/worker-http.js +0 -9
- package/dist/worker-http.js.map +0 -1
- package/dist/worker-ipc-reporter.js +0 -58
- package/dist/worker-ipc-reporter.js.map +0 -1
- package/dist/worker-payloads.js +0 -66
- package/dist/worker-payloads.js.map +0 -1
- package/dist/worker-start-payload.js +0 -5
- package/dist/worker-start-payload.js.map +0 -1
- package/dist/workspace/manifest.js +0 -79
- package/dist/workspace/manifest.js.map +0 -1
- package/dist/workspace/node-run-root-git-ops.js +0 -96
- package/dist/workspace/node-run-root-git-ops.js.map +0 -1
- package/dist/workspace/resource-aggregator.js +0 -39
- package/dist/workspace/resource-aggregator.js.map +0 -1
- package/dist/workspace/run-root.js +0 -209
- package/dist/workspace/run-root.js.map +0 -1
- package/src/test-helpers/ipc-harness.ts +0 -19
package/src/runtime/bootstrap.ts
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import
|
|
3
|
-
PreparedTurnStart,
|
|
4
|
-
ProcessInstance,
|
|
5
|
-
ProcessProject,
|
|
6
|
-
|
|
2
|
+
import {
|
|
3
|
+
type PreparedTurnStart,
|
|
4
|
+
type ProcessInstance,
|
|
5
|
+
type ProcessProject,
|
|
6
|
+
readNonBlankString as readNonEmptyString,
|
|
7
|
+
type WorkerBootstrapReceipt,
|
|
7
8
|
} from "@leitwerk-dev/domain";
|
|
8
9
|
import type { ResolvedWorkerProcess } from "@leitwerk-dev/extension-runtime";
|
|
9
10
|
import type {
|
|
10
11
|
RepositoryCredentialRequirement,
|
|
11
12
|
ResolvedProcessPiConfig,
|
|
12
13
|
} from "@leitwerk-dev/process-sdk";
|
|
14
|
+
import { repositoryHttpsUrl } from "@leitwerk-dev/process-sdk";
|
|
13
15
|
import { createTemplateContext, resolveProcessPiConfig } from "@leitwerk-dev/process-sdk/pi-config";
|
|
14
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
WorkerReadyPayload,
|
|
18
|
+
WorkerRepositoryCredential,
|
|
19
|
+
WorkerStartPayload,
|
|
20
|
+
} from "@leitwerk-dev/worker-protocol";
|
|
21
|
+
import {
|
|
22
|
+
type DevelopmentToolEnvironment,
|
|
23
|
+
MiseDevelopmentToolEnvironment,
|
|
24
|
+
type PreparedToolEnvironment,
|
|
25
|
+
} from "../development-tool-environment.js";
|
|
15
26
|
import type { InputItem } from "../input-consumer.js";
|
|
16
27
|
import {
|
|
17
28
|
resolveManagedPiAgentDir,
|
|
@@ -23,7 +34,11 @@ import {
|
|
|
23
34
|
readAndValidateManagedPiResourceManifest,
|
|
24
35
|
} from "../managed-pi-bootstrap.js";
|
|
25
36
|
import type { PiTreeHandle, PiTreeHandleFactory, PiTreePlanningSnapshot } from "../pi-adapter.js";
|
|
26
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
materializeCanonicalPiResourceBundle,
|
|
39
|
+
persistPiResourceBundleForStart,
|
|
40
|
+
verifyCanonicalPiResourceBundle,
|
|
41
|
+
} from "../pi-resource-bundle.js";
|
|
27
42
|
import { resolvePreTurnTargetStartSelection } from "../pre-turn-targeted-inputs.js";
|
|
28
43
|
import { planTurnTreeExecution } from "../turn-tree-strategy.js";
|
|
29
44
|
import {
|
|
@@ -50,6 +65,14 @@ export interface BootstrapWorkerRuntimeDeps {
|
|
|
50
65
|
piFactory: PiTreeHandleFactory;
|
|
51
66
|
gitOps: RunRootGitOps;
|
|
52
67
|
scheduler: WorkerRuntimeScheduler;
|
|
68
|
+
developmentTools?: DevelopmentToolEnvironment;
|
|
69
|
+
configureDockerCredentials?(
|
|
70
|
+
credentials: NonNullable<WorkerStartPayload["dockerRegistryCredentials"]>,
|
|
71
|
+
enabled: boolean,
|
|
72
|
+
): void;
|
|
73
|
+
toolPreparationSignal?: AbortSignal;
|
|
74
|
+
onToolPreparationProgress?(repositoryKey: string, phase: "installing" | "verifying"): void;
|
|
75
|
+
onToolDiagnosticTrace?(text: string): void;
|
|
53
76
|
resolveWorkerProcess?: (
|
|
54
77
|
processId: string,
|
|
55
78
|
opts?: { paramsJson?: string | null; stateJson?: string | null },
|
|
@@ -61,80 +84,110 @@ export interface AcceptedStartActivationResult {
|
|
|
61
84
|
diagnostics: string[];
|
|
62
85
|
}
|
|
63
86
|
|
|
87
|
+
/** @internal */
|
|
64
88
|
export interface PreparedStartActivation {
|
|
89
|
+
/** @internal */
|
|
65
90
|
startPayload: WorkerStartPayload;
|
|
91
|
+
/** @internal */
|
|
66
92
|
managedAgentDir: string | null;
|
|
93
|
+
/** @internal */
|
|
67
94
|
managedModelProfileId: string | null;
|
|
95
|
+
/** @internal */
|
|
68
96
|
workspaceRoot: string;
|
|
97
|
+
/** @internal */
|
|
69
98
|
sessionCwd: string;
|
|
99
|
+
/** @internal */
|
|
70
100
|
processSnapshot: ProcessInstance;
|
|
101
|
+
/** @internal */
|
|
71
102
|
resolvedPiConfig: ResolvedProcessPiConfig;
|
|
72
103
|
}
|
|
73
104
|
|
|
105
|
+
/** @internal */
|
|
74
106
|
export interface BootstrapWorkerRuntimeResult {
|
|
107
|
+
/** @internal */
|
|
75
108
|
startPayload: WorkerStartPayload;
|
|
109
|
+
/** @internal */
|
|
76
110
|
resolvedWorkerProcess?: ResolvedWorkerProcess;
|
|
111
|
+
/** @internal */
|
|
77
112
|
projectSnapshots: ProcessProject[];
|
|
113
|
+
/** @internal */
|
|
78
114
|
processSnapshot: ProcessInstance;
|
|
115
|
+
/** @internal */
|
|
79
116
|
activation: PreparedStartActivation;
|
|
117
|
+
/** @internal */
|
|
80
118
|
resolvedPiConfig: ResolvedProcessPiConfig;
|
|
119
|
+
/** @internal */
|
|
81
120
|
diagnostics: string[];
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
workspaceRoot: string;
|
|
86
|
-
aggregatedAgentsSources: string[];
|
|
87
|
-
loadedSkills: string[];
|
|
88
|
-
loadedAgentsFiles: Array<{ path: string; sizeBytes: number }>;
|
|
89
|
-
loadedSkillFiles: Array<{ name: string; path: string }>;
|
|
121
|
+
/** @internal */
|
|
122
|
+
readyPayload: WorkerReadyPayload & {
|
|
123
|
+
/** @internal */
|
|
90
124
|
rootEntryId: string | null;
|
|
91
|
-
receipt: WorkerBootstrapReceipt;
|
|
92
125
|
};
|
|
126
|
+
/** @internal */
|
|
93
127
|
pendingInputs: InputItem[];
|
|
128
|
+
/** @internal */
|
|
94
129
|
credentialRefresh?: {
|
|
130
|
+
/** @internal */
|
|
95
131
|
agentDir: string;
|
|
132
|
+
/** @internal */
|
|
96
133
|
declaredCredentialPaths: readonly string[];
|
|
134
|
+
/** @internal */
|
|
97
135
|
providerId: string;
|
|
136
|
+
/** @internal */
|
|
98
137
|
revision: number;
|
|
99
138
|
};
|
|
100
139
|
}
|
|
101
140
|
|
|
102
|
-
function readNonEmptyString(value: unknown): string | null {
|
|
103
|
-
return typeof value === "string" && value.trim() !== "" ? value : null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
141
|
function withoutCredentialValues(payload: WorkerStartPayload): WorkerStartPayload {
|
|
107
|
-
const
|
|
142
|
+
const withoutCredentials = {
|
|
108
143
|
...payload,
|
|
109
144
|
repositoryCredentials: undefined,
|
|
145
|
+
dockerRegistryCredentials: undefined,
|
|
110
146
|
} as WorkerStartPayload;
|
|
111
|
-
if (!isLlmWorkerStartPayload(
|
|
112
|
-
return
|
|
147
|
+
if (!isLlmWorkerStartPayload(withoutCredentials) || !withoutCredentials.bootstrap.credential) {
|
|
148
|
+
return withoutCredentials;
|
|
113
149
|
}
|
|
114
150
|
return {
|
|
115
|
-
...
|
|
116
|
-
repositoryCredentials: undefined,
|
|
151
|
+
...withoutCredentials,
|
|
117
152
|
bootstrap: {
|
|
118
|
-
...
|
|
119
|
-
credential: { ...
|
|
153
|
+
...withoutCredentials.bootstrap,
|
|
154
|
+
credential: { ...withoutCredentials.bootstrap.credential, values: {} },
|
|
120
155
|
},
|
|
121
156
|
};
|
|
122
157
|
}
|
|
123
158
|
|
|
124
159
|
export function validateRepositoryCredentials(input: {
|
|
125
|
-
credentials: readonly
|
|
160
|
+
credentials: readonly WorkerRepositoryCredential[];
|
|
126
161
|
requirements: readonly RepositoryCredentialRequirement[];
|
|
127
162
|
projectKeys: ReadonlySet<string>;
|
|
163
|
+
projects?: readonly { key: string; repoLocator: string }[];
|
|
128
164
|
}): void {
|
|
129
165
|
const credentialKeys = new Set<string>();
|
|
130
166
|
for (const credential of input.credentials) {
|
|
131
|
-
if (
|
|
167
|
+
if (
|
|
168
|
+
!input.projectKeys.has(credential.projectKey) ||
|
|
169
|
+
!["git_ssh", "git_https"].includes(credential.kind)
|
|
170
|
+
) {
|
|
132
171
|
throw new Error(`Repository credential does not match project '${credential.projectKey}'`);
|
|
133
172
|
}
|
|
134
173
|
if (credentialKeys.has(credential.projectKey)) {
|
|
135
174
|
throw new Error(`Duplicate repository credential for project '${credential.projectKey}'`);
|
|
136
175
|
}
|
|
137
176
|
credentialKeys.add(credential.projectKey);
|
|
177
|
+
if (credential.kind === "git_https") {
|
|
178
|
+
const project = input.projects?.find((project) => project.key === credential.projectKey);
|
|
179
|
+
if (
|
|
180
|
+
!project ||
|
|
181
|
+
repositoryHttpsUrl(credential.repositoryUrl).href !== project.repoLocator ||
|
|
182
|
+
!credential.username ||
|
|
183
|
+
!credential.password ||
|
|
184
|
+
/[\r\n\0]/.test(credential.username + credential.password)
|
|
185
|
+
) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`Invalid HTTPS credential scope or material for project '${credential.projectKey}'`,
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
138
191
|
}
|
|
139
192
|
const identities = (items: readonly RepositoryCredentialRequirement[]) =>
|
|
140
193
|
new Set(items.map((item) => `${item.projectKey}:${item.kind}:${item.credentialRef}`));
|
|
@@ -149,27 +202,17 @@ export function shouldPreservePersistedLeafForActiveTurnResume(input: {
|
|
|
149
202
|
processSnapshot: Pick<ProcessInstance, "selectedTurnId" | "currentExecution" | "metadata">;
|
|
150
203
|
payload: Pick<WorkerStartPayload, "resume" | "turnStart">;
|
|
151
204
|
}): boolean {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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;
|
|
205
|
+
const { payload, processSnapshot } = input;
|
|
206
|
+
return (
|
|
207
|
+
payload.resume &&
|
|
208
|
+
readNonEmptyString(processSnapshot.selectedTurnId) !== null &&
|
|
209
|
+
processSnapshot.currentExecution?.kind === "worker_start" &&
|
|
210
|
+
processSnapshot.currentExecution.id === payload.turnStart.id &&
|
|
211
|
+
payload.turnStart.state.kind === "accepted" &&
|
|
212
|
+
readNonEmptyString(payload.turnStart.state.turnRecordId) !== null &&
|
|
213
|
+
readNonEmptyString(processSnapshot.metadata?.continueFromPiEntryId) === null &&
|
|
214
|
+
readNonEmptyString(processSnapshot.metadata?.retryForkPiEntryId) === null
|
|
215
|
+
);
|
|
173
216
|
}
|
|
174
217
|
|
|
175
218
|
type ResumeLeafEntryCandidate = {
|
|
@@ -181,39 +224,27 @@ function resolveResumeLeafEntryCandidates(
|
|
|
181
224
|
processSnapshot: ProcessInstance,
|
|
182
225
|
payload: WorkerStartPayload,
|
|
183
226
|
): 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
227
|
const semanticEntryRefs = parseProcessSemanticEntryRefsFromStateJson(processSnapshot.stateJson);
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
228
|
+
const candidates: ResumeLeafEntryCandidate[] = [];
|
|
229
|
+
for (const [source, entryId] of [
|
|
230
|
+
[
|
|
231
|
+
"continue",
|
|
232
|
+
typeof processSnapshot.metadata?.continueFromPiEntryId === "string"
|
|
233
|
+
? processSnapshot.metadata.continueFromPiEntryId
|
|
234
|
+
: null,
|
|
235
|
+
],
|
|
236
|
+
[
|
|
237
|
+
"retry",
|
|
238
|
+
typeof processSnapshot.metadata?.retryForkPiEntryId === "string"
|
|
239
|
+
? processSnapshot.metadata.retryForkPiEntryId
|
|
240
|
+
: null,
|
|
241
|
+
],
|
|
242
|
+
["state", payload.resume ? semanticEntryRefs.currentPrimaryPathLeaf?.entryId : null],
|
|
243
|
+
["payload", payload.resume ? payload.resumeLeafEntryId : null],
|
|
244
|
+
] as const) {
|
|
245
|
+
if (entryId && !candidates.some((candidate) => candidate.entryId === entryId)) {
|
|
246
|
+
candidates.push({ entryId, source });
|
|
247
|
+
}
|
|
217
248
|
}
|
|
218
249
|
|
|
219
250
|
return candidates;
|
|
@@ -393,11 +424,17 @@ export async function bootstrapWorkerRuntime(
|
|
|
393
424
|
const paramsJson = deps.payload.processSnapshot.paramsJson ?? null;
|
|
394
425
|
const stateJson = deps.payload.processSnapshot.stateJson ?? null;
|
|
395
426
|
|
|
396
|
-
// Try the new worker process resolver first
|
|
397
427
|
const resolvedWorkerProcess = deps.resolveWorkerProcess
|
|
398
428
|
? await deps.resolveWorkerProcess(processId, { paramsJson, stateJson })
|
|
399
429
|
: undefined;
|
|
400
430
|
|
|
431
|
+
const dockerCredentials = deps.payload.dockerRegistryCredentials ?? [];
|
|
432
|
+
if (dockerCredentials.length && !deps.configureDockerCredentials)
|
|
433
|
+
throw new Error("Docker credential delivery is unavailable");
|
|
434
|
+
deps.configureDockerCredentials?.(
|
|
435
|
+
dockerCredentials,
|
|
436
|
+
resolvedWorkerProcess?.runtime?.docker === true,
|
|
437
|
+
);
|
|
401
438
|
const projectSnapshots = projectSnapshotsFromPayload(deps.payload.projectSnapshots);
|
|
402
439
|
const repositoryCredentials = deps.payload.repositoryCredentials ?? [];
|
|
403
440
|
const declaredRequirements =
|
|
@@ -409,6 +446,7 @@ export async function bootstrapWorkerRuntime(
|
|
|
409
446
|
credentials: repositoryCredentials,
|
|
410
447
|
requirements: declaredRequirements,
|
|
411
448
|
projectKeys: new Set(projectSnapshots.map((project) => project.key)),
|
|
449
|
+
projects: projectSnapshots,
|
|
412
450
|
});
|
|
413
451
|
deps.gitOps.configureRepositoryCredentials?.(repositoryCredentials);
|
|
414
452
|
const processSnapshot = buildProcessSnapshotSeed(processId, deps.payload.processSnapshot);
|
|
@@ -423,19 +461,11 @@ export async function bootstrapWorkerRuntime(
|
|
|
423
461
|
}));
|
|
424
462
|
const plan = planRunRoot(workspaceRoot, deps.instanceId, runRootProjects);
|
|
425
463
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
-
}
|
|
464
|
+
const runRootPreparation = deps.payload.resume
|
|
465
|
+
? validateRunRoot(workspaceRoot, runRootProjects, deps.gitOps).then((validation) =>
|
|
466
|
+
repairRunRoot(workspaceRoot, validation, plan, deps.gitOps),
|
|
467
|
+
)
|
|
468
|
+
: materializeRunRoot(plan, deps.gitOps);
|
|
439
469
|
|
|
440
470
|
const resolvedPiConfig = llmPayload
|
|
441
471
|
? resolveProcessPiConfig({
|
|
@@ -462,6 +492,26 @@ export async function bootstrapWorkerRuntime(
|
|
|
462
492
|
let loadedAgentsFiles: Array<{ path: string; sizeBytes: number }> = [];
|
|
463
493
|
let loadedSkillFiles: Array<{ name: string; path: string }> = [];
|
|
464
494
|
let receipt: WorkerBootstrapReceipt;
|
|
495
|
+
const runRoot = await runRootPreparation;
|
|
496
|
+
let preparedTools: PreparedToolEnvironment | undefined;
|
|
497
|
+
if (resolvedWorkerProcess?.runtime?.developmentTools) {
|
|
498
|
+
if (!deps.payload.developmentTools) {
|
|
499
|
+
throw new Error("Development-tool settings are unavailable for an opted-in process");
|
|
500
|
+
}
|
|
501
|
+
preparedTools = await (deps.developmentTools ?? new MiseDevelopmentToolEnvironment()).prepare({
|
|
502
|
+
config: deps.payload.developmentTools,
|
|
503
|
+
repositories: projectSnapshots.map((project) => ({
|
|
504
|
+
repositoryKey: project.key,
|
|
505
|
+
workingDirectory: path.join(workspaceRoot, project.key),
|
|
506
|
+
})),
|
|
507
|
+
signal: deps.toolPreparationSignal,
|
|
508
|
+
onProgress: deps.onToolPreparationProgress,
|
|
509
|
+
onDiagnosticTrace: deps.onToolDiagnosticTrace,
|
|
510
|
+
});
|
|
511
|
+
for (const [key, value] of Object.entries(preparedTools.commandEnvironment)) {
|
|
512
|
+
if (key === "PATH" || key.startsWith("MISE_")) process.env[key] = value;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
465
515
|
if (llmPayload) {
|
|
466
516
|
const start =
|
|
467
517
|
deps.payload.turnStart.state.kind === "starting" ||
|
|
@@ -497,11 +547,32 @@ export async function bootstrapWorkerRuntime(
|
|
|
497
547
|
instanceId: deps.instanceId,
|
|
498
548
|
startOrLeaseId: deps.payload.workerLeaseId,
|
|
499
549
|
});
|
|
500
|
-
|
|
501
|
-
|
|
550
|
+
const deliveredBundle =
|
|
551
|
+
llmPayload.bootstrap.resourceBundle.archiveBase64 === undefined
|
|
552
|
+
? undefined
|
|
553
|
+
: Buffer.from(llmPayload.bootstrap.resourceBundle.archiveBase64, "base64");
|
|
554
|
+
if (deliveredBundle) {
|
|
555
|
+
verifyCanonicalPiResourceBundle(deliveredBundle, llmPayload.bootstrap.resourceBundle.digest);
|
|
556
|
+
}
|
|
557
|
+
const resourceBundleInput = {
|
|
558
|
+
bundlesDir: deps.payload.treePaths.piResourceBundlesDir,
|
|
559
|
+
startRecordId: deps.payload.turnStart.id,
|
|
502
560
|
digest: llmPayload.bootstrap.resourceBundle.digest,
|
|
503
|
-
|
|
561
|
+
archiveBase64: llmPayload.bootstrap.resourceBundle.archiveBase64,
|
|
562
|
+
};
|
|
563
|
+
const persistedResourceBundle = persistPiResourceBundleForStart({
|
|
564
|
+
...resourceBundleInput,
|
|
565
|
+
...(deliveredBundle ? { deliveredBundle } : {}),
|
|
504
566
|
});
|
|
567
|
+
const bundle = deliveredBundle ?? (await persistedResourceBundle).bundle;
|
|
568
|
+
await Promise.all([
|
|
569
|
+
persistedResourceBundle,
|
|
570
|
+
materializeCanonicalPiResourceBundle({
|
|
571
|
+
bundle,
|
|
572
|
+
digest: llmPayload.bootstrap.resourceBundle.digest,
|
|
573
|
+
targetDir: managedAgentDir,
|
|
574
|
+
}),
|
|
575
|
+
]);
|
|
505
576
|
const manifest = await readAndValidateManagedPiResourceManifest({
|
|
506
577
|
agentDir: managedAgentDir,
|
|
507
578
|
resourceDigest: llmPayload.bootstrap.resourceBundle.digest,
|
|
@@ -608,12 +679,24 @@ export async function bootstrapWorkerRuntime(
|
|
|
608
679
|
resumed: deps.payload.resume,
|
|
609
680
|
primaryTreeFile: deps.payload.treePaths.primaryTreeFile,
|
|
610
681
|
workspaceRoot: deps.payload.treePaths.workspaceRoot,
|
|
611
|
-
aggregatedAgentsSources: aggregatedAgentsMdSources,
|
|
612
|
-
loadedSkills,
|
|
682
|
+
aggregatedAgentsSources: runRoot.aggregatedAgentsMdSources,
|
|
683
|
+
loadedSkills: runRoot.loadedSkills,
|
|
613
684
|
loadedAgentsFiles,
|
|
614
685
|
loadedSkillFiles,
|
|
615
686
|
rootEntryId: null,
|
|
616
687
|
receipt,
|
|
688
|
+
...(preparedTools
|
|
689
|
+
? {
|
|
690
|
+
developmentTools: {
|
|
691
|
+
miseVersion: preparedTools.miseVersion,
|
|
692
|
+
repositories: preparedTools.repositories.map((repository) => ({
|
|
693
|
+
repositoryKey: repository.repositoryKey,
|
|
694
|
+
tools: repository.tools,
|
|
695
|
+
})),
|
|
696
|
+
warnings: preparedTools.warnings,
|
|
697
|
+
},
|
|
698
|
+
}
|
|
699
|
+
: {}),
|
|
617
700
|
},
|
|
618
701
|
pendingInputs,
|
|
619
702
|
...(credentialRefresh ? { credentialRefresh } : {}),
|
|
@@ -85,9 +85,23 @@ export function extractSecretValuesFromPayload(
|
|
|
85
85
|
if (typeof value === "string" && value.trim() !== "") secrets.add(value.trim());
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
+
for (const value of extractDockerRegistrySecretValues(payload)) secrets.add(value);
|
|
88
89
|
return Array.from(secrets);
|
|
89
90
|
}
|
|
90
91
|
|
|
92
|
+
export function extractDockerRegistrySecretValues(payload: WorkerStartPayload): string[] {
|
|
93
|
+
const secrets = new Set<string>();
|
|
94
|
+
for (const credential of payload.dockerRegistryCredentials ?? []) {
|
|
95
|
+
secrets.add(credential.password);
|
|
96
|
+
secrets.add(Buffer.from(`${credential.username}:${credential.password}`).toString("base64"));
|
|
97
|
+
secrets.add(Buffer.from(credential.password).toString("base64"));
|
|
98
|
+
secrets.add(encodeURIComponent(credential.password));
|
|
99
|
+
}
|
|
100
|
+
return Array.from(secrets)
|
|
101
|
+
.filter(Boolean)
|
|
102
|
+
.sort((a, b) => b.length - a.length);
|
|
103
|
+
}
|
|
104
|
+
|
|
91
105
|
export function redactSecrets(message: string, secrets: readonly string[]): string {
|
|
92
106
|
let result = message;
|
|
93
107
|
for (const secret of secrets) {
|
|
@@ -105,32 +119,8 @@ function errorCode(error: unknown, fallback: string): string {
|
|
|
105
119
|
return typeof code === "string" && code.trim() !== "" ? code.trim() : fallback;
|
|
106
120
|
}
|
|
107
121
|
|
|
108
|
-
function sessionContext(payload: WorkerStartPayload): WorkerFailureSessionContext {
|
|
109
|
-
return {
|
|
110
|
-
selectedTurnId: payload.processSnapshot.selectedTurnId ?? null,
|
|
111
|
-
lifecycleStatus: payload.processSnapshot.lifecycleStatus ?? "running",
|
|
112
|
-
snapshotSource: failureSnapshotSource(payload),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function failureSnapshotSource(payload: WorkerStartPayload) {
|
|
117
|
-
return {
|
|
118
|
-
kind: payload.bootstrap.kind,
|
|
119
|
-
treeFile: payload.treePaths.primaryTreeFile,
|
|
120
|
-
} as const;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
122
|
/** Pure normalization boundary for every failure owned by the worker runtime. */
|
|
124
123
|
export function normalizeWorkerFailure(failure: WorkerFailure): WorkerFailureDisposition {
|
|
125
|
-
const session =
|
|
126
|
-
failure.kind === "bootstrap"
|
|
127
|
-
? sessionContext(failure.payload)
|
|
128
|
-
: failure.kind === "dispatch" ||
|
|
129
|
-
failure.kind === "cleanup" ||
|
|
130
|
-
failure.kind === "turn" ||
|
|
131
|
-
failure.kind === "mandatory_snapshot"
|
|
132
|
-
? (failure.session ?? null)
|
|
133
|
-
: null;
|
|
134
124
|
const secrets = extractSecretValuesFromPayload(
|
|
135
125
|
failure.kind === "bootstrap" ? failure.payload : null,
|
|
136
126
|
);
|
|
@@ -152,11 +142,8 @@ export function normalizeWorkerFailure(failure: WorkerFailure): WorkerFailureDis
|
|
|
152
142
|
const summary =
|
|
153
143
|
failure.kind === "mandatory_snapshot"
|
|
154
144
|
? `Mandatory session snapshot upload failed before ${failure.point}: ${message}`
|
|
155
|
-
:
|
|
156
|
-
const errorClass =
|
|
157
|
-
failure.kind === "turn"
|
|
158
|
-
? (turnError?.errorClass ?? classified.errorClass)
|
|
159
|
-
: classified.errorClass;
|
|
145
|
+
: (turnError?.message ?? message);
|
|
146
|
+
const errorClass = turnError?.errorClass ?? classified.errorClass;
|
|
160
147
|
const payload: WorkerTurnFailedPayload = {
|
|
161
148
|
turnRecordId: correlation.turnRecordId,
|
|
162
149
|
turnId: correlation.turnId,
|
|
@@ -192,7 +179,7 @@ export function normalizeWorkerFailure(failure: WorkerFailure): WorkerFailureDis
|
|
|
192
179
|
kind: "turn_failed",
|
|
193
180
|
payload,
|
|
194
181
|
park: {
|
|
195
|
-
selectedTurnId: session?.selectedTurnId ?? correlation.turnId,
|
|
182
|
+
selectedTurnId: failure.session?.selectedTurnId ?? correlation.turnId,
|
|
196
183
|
reason: summary,
|
|
197
184
|
errorClass,
|
|
198
185
|
},
|
|
@@ -210,7 +197,13 @@ export function normalizeWorkerFailure(failure: WorkerFailure): WorkerFailureDis
|
|
|
210
197
|
errorClass: "infrastructure",
|
|
211
198
|
},
|
|
212
199
|
stderrMessage: summary,
|
|
213
|
-
snapshot: {
|
|
200
|
+
snapshot: {
|
|
201
|
+
point: "before_worker_failed",
|
|
202
|
+
source: {
|
|
203
|
+
kind: failure.payload.bootstrap.kind,
|
|
204
|
+
treeFile: failure.payload.treePaths.primaryTreeFile,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
214
207
|
terminal: {
|
|
215
208
|
kind: "worker_failed",
|
|
216
209
|
payload: {
|
|
@@ -218,21 +211,25 @@ export function normalizeWorkerFailure(failure: WorkerFailure): WorkerFailureDis
|
|
|
218
211
|
errorCode: errorCode(failure.error, "bootstrap_failed"),
|
|
219
212
|
message: bounded(summary),
|
|
220
213
|
errorClass: "infrastructure",
|
|
221
|
-
selectedTurnId:
|
|
214
|
+
selectedTurnId: failure.payload.processSnapshot.selectedTurnId ?? null,
|
|
222
215
|
},
|
|
223
216
|
},
|
|
224
217
|
exitCode: 1,
|
|
225
218
|
};
|
|
226
219
|
}
|
|
227
220
|
|
|
221
|
+
const { session } = failure;
|
|
222
|
+
const isCleanup = failure.kind === "cleanup";
|
|
223
|
+
const summary = `${isCleanup ? "Worker cleanup failed" : "Worker dispatch failed"}: ${message}`;
|
|
224
|
+
const diagnostic: WorkerDiagnosticPayload = {
|
|
225
|
+
level: "error",
|
|
226
|
+
code: isCleanup ? "cleanup.failed" : "runtime.dispatch_failed",
|
|
227
|
+
message: summary,
|
|
228
|
+
errorClass: classified.errorClass,
|
|
229
|
+
};
|
|
228
230
|
if (failure.kind === "dispatch" && session && session.lifecycleStatus !== "error") {
|
|
229
231
|
return {
|
|
230
|
-
diagnostic
|
|
231
|
-
level: "error",
|
|
232
|
-
code: "runtime.dispatch_failed",
|
|
233
|
-
message: `Worker dispatch failed: ${message}`,
|
|
234
|
-
errorClass: classified.errorClass,
|
|
235
|
-
},
|
|
232
|
+
diagnostic,
|
|
236
233
|
stderrMessage: message,
|
|
237
234
|
terminal: {
|
|
238
235
|
kind: "park",
|
|
@@ -245,11 +242,8 @@ export function normalizeWorkerFailure(failure: WorkerFailure): WorkerFailureDis
|
|
|
245
242
|
};
|
|
246
243
|
}
|
|
247
244
|
|
|
248
|
-
const isCleanup = failure.kind === "cleanup";
|
|
249
|
-
const code = isCleanup ? "cleanup.failed" : "runtime.dispatch_failed";
|
|
250
|
-
const summary = `${isCleanup ? "Worker cleanup failed" : "Worker dispatch failed"}: ${message}`;
|
|
251
245
|
return {
|
|
252
|
-
diagnostic
|
|
246
|
+
diagnostic,
|
|
253
247
|
stderrMessage: summary,
|
|
254
248
|
...(session
|
|
255
249
|
? {
|