@leitwerk-dev/worker 0.1.9 → 0.2.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/automatic-turn-executor.d.ts +1 -0
- package/dist/automatic-turn-executor.d.ts.map +1 -1
- package/dist/{chunk-O6332GRG.js → chunk-Y7S2MZD3.js} +1349 -932
- package/dist/chunk-Y7S2MZD3.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 +48 -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 +1 -0
- package/dist/entry-runtime.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -5
- package/dist/index.js.map +1 -1
- package/dist/input-consumer.d.ts +6 -11
- package/dist/input-consumer.d.ts.map +1 -1
- package/dist/ipc.d.ts +1 -0
- package/dist/ipc.d.ts.map +1 -1
- package/dist/logical-prompt-runner.d.ts.map +1 -1
- 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 +1 -0
- 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 +11 -0
- 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.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 +2 -0
- package/dist/runtime/adapters.d.ts.map +1 -1
- package/dist/runtime/bootstrap-session.d.ts +8 -5
- package/dist/runtime/bootstrap-session.d.ts.map +1 -1
- package/dist/runtime/bootstrap.d.ts +14 -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.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 +0 -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 +9 -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 +452 -0
- package/src/diagnostics.ts +1 -0
- package/src/docker-registry-credentials.ts +65 -0
- package/src/entry-runtime.ts +5 -4
- package/src/index.ts +11 -0
- package/src/input-consumer.ts +7 -29
- package/src/ipc.ts +37 -2
- package/src/logical-prompt-runner.ts +23 -29
- package/src/managed-pi-bootstrap.ts +3 -3
- package/src/missing-tool-recovery-runner.ts +4 -18
- package/src/pi-adapter.ts +19 -50
- package/src/pi-event-reporter.ts +16 -38
- package/src/pi-resource-bundle.ts +67 -1
- package/src/pre-turn-targeted-inputs.ts +9 -11
- package/src/prompt-guards.ts +44 -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 +2 -0
- package/src/runtime/bootstrap-session.ts +69 -39
- package/src/runtime/bootstrap.ts +160 -103
- package/src/runtime/failure-policy.ts +36 -42
- package/src/runtime/index.ts +43 -14
- 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 +23 -64
- 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 +38 -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 },
|
|
@@ -79,17 +102,7 @@ export interface BootstrapWorkerRuntimeResult {
|
|
|
79
102
|
activation: PreparedStartActivation;
|
|
80
103
|
resolvedPiConfig: ResolvedProcessPiConfig;
|
|
81
104
|
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
|
-
};
|
|
105
|
+
readyPayload: WorkerReadyPayload & { rootEntryId: string | null };
|
|
93
106
|
pendingInputs: InputItem[];
|
|
94
107
|
credentialRefresh?: {
|
|
95
108
|
agentDir: string;
|
|
@@ -99,42 +112,56 @@ export interface BootstrapWorkerRuntimeResult {
|
|
|
99
112
|
};
|
|
100
113
|
}
|
|
101
114
|
|
|
102
|
-
function readNonEmptyString(value: unknown): string | null {
|
|
103
|
-
return typeof value === "string" && value.trim() !== "" ? value : null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
115
|
function withoutCredentialValues(payload: WorkerStartPayload): WorkerStartPayload {
|
|
107
|
-
const
|
|
116
|
+
const withoutCredentials = {
|
|
108
117
|
...payload,
|
|
109
118
|
repositoryCredentials: undefined,
|
|
119
|
+
dockerRegistryCredentials: undefined,
|
|
110
120
|
} as WorkerStartPayload;
|
|
111
|
-
if (!isLlmWorkerStartPayload(
|
|
112
|
-
return
|
|
121
|
+
if (!isLlmWorkerStartPayload(withoutCredentials) || !withoutCredentials.bootstrap.credential) {
|
|
122
|
+
return withoutCredentials;
|
|
113
123
|
}
|
|
114
124
|
return {
|
|
115
|
-
...
|
|
116
|
-
repositoryCredentials: undefined,
|
|
125
|
+
...withoutCredentials,
|
|
117
126
|
bootstrap: {
|
|
118
|
-
...
|
|
119
|
-
credential: { ...
|
|
127
|
+
...withoutCredentials.bootstrap,
|
|
128
|
+
credential: { ...withoutCredentials.bootstrap.credential, values: {} },
|
|
120
129
|
},
|
|
121
130
|
};
|
|
122
131
|
}
|
|
123
132
|
|
|
124
133
|
export function validateRepositoryCredentials(input: {
|
|
125
|
-
credentials: readonly
|
|
134
|
+
credentials: readonly WorkerRepositoryCredential[];
|
|
126
135
|
requirements: readonly RepositoryCredentialRequirement[];
|
|
127
136
|
projectKeys: ReadonlySet<string>;
|
|
137
|
+
projects?: readonly { key: string; repoLocator: string }[];
|
|
128
138
|
}): void {
|
|
129
139
|
const credentialKeys = new Set<string>();
|
|
130
140
|
for (const credential of input.credentials) {
|
|
131
|
-
if (
|
|
141
|
+
if (
|
|
142
|
+
!input.projectKeys.has(credential.projectKey) ||
|
|
143
|
+
!["git_ssh", "git_https"].includes(credential.kind)
|
|
144
|
+
) {
|
|
132
145
|
throw new Error(`Repository credential does not match project '${credential.projectKey}'`);
|
|
133
146
|
}
|
|
134
147
|
if (credentialKeys.has(credential.projectKey)) {
|
|
135
148
|
throw new Error(`Duplicate repository credential for project '${credential.projectKey}'`);
|
|
136
149
|
}
|
|
137
150
|
credentialKeys.add(credential.projectKey);
|
|
151
|
+
if (credential.kind === "git_https") {
|
|
152
|
+
const project = input.projects?.find((project) => project.key === credential.projectKey);
|
|
153
|
+
if (
|
|
154
|
+
!project ||
|
|
155
|
+
repositoryHttpsUrl(credential.repositoryUrl).href !== project.repoLocator ||
|
|
156
|
+
!credential.username ||
|
|
157
|
+
!credential.password ||
|
|
158
|
+
/[\r\n\0]/.test(credential.username + credential.password)
|
|
159
|
+
) {
|
|
160
|
+
throw new Error(
|
|
161
|
+
`Invalid HTTPS credential scope or material for project '${credential.projectKey}'`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
138
165
|
}
|
|
139
166
|
const identities = (items: readonly RepositoryCredentialRequirement[]) =>
|
|
140
167
|
new Set(items.map((item) => `${item.projectKey}:${item.kind}:${item.credentialRef}`));
|
|
@@ -149,27 +176,17 @@ export function shouldPreservePersistedLeafForActiveTurnResume(input: {
|
|
|
149
176
|
processSnapshot: Pick<ProcessInstance, "selectedTurnId" | "currentExecution" | "metadata">;
|
|
150
177
|
payload: Pick<WorkerStartPayload, "resume" | "turnStart">;
|
|
151
178
|
}): 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;
|
|
179
|
+
const { payload, processSnapshot } = input;
|
|
180
|
+
return (
|
|
181
|
+
payload.resume &&
|
|
182
|
+
readNonEmptyString(processSnapshot.selectedTurnId) !== null &&
|
|
183
|
+
processSnapshot.currentExecution?.kind === "worker_start" &&
|
|
184
|
+
processSnapshot.currentExecution.id === payload.turnStart.id &&
|
|
185
|
+
payload.turnStart.state.kind === "accepted" &&
|
|
186
|
+
readNonEmptyString(payload.turnStart.state.turnRecordId) !== null &&
|
|
187
|
+
readNonEmptyString(processSnapshot.metadata?.continueFromPiEntryId) === null &&
|
|
188
|
+
readNonEmptyString(processSnapshot.metadata?.retryForkPiEntryId) === null
|
|
189
|
+
);
|
|
173
190
|
}
|
|
174
191
|
|
|
175
192
|
type ResumeLeafEntryCandidate = {
|
|
@@ -181,39 +198,27 @@ function resolveResumeLeafEntryCandidates(
|
|
|
181
198
|
processSnapshot: ProcessInstance,
|
|
182
199
|
payload: WorkerStartPayload,
|
|
183
200
|
): 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
201
|
const semanticEntryRefs = parseProcessSemanticEntryRefsFromStateJson(processSnapshot.stateJson);
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
202
|
+
const candidates: ResumeLeafEntryCandidate[] = [];
|
|
203
|
+
for (const [source, entryId] of [
|
|
204
|
+
[
|
|
205
|
+
"continue",
|
|
206
|
+
typeof processSnapshot.metadata?.continueFromPiEntryId === "string"
|
|
207
|
+
? processSnapshot.metadata.continueFromPiEntryId
|
|
208
|
+
: null,
|
|
209
|
+
],
|
|
210
|
+
[
|
|
211
|
+
"retry",
|
|
212
|
+
typeof processSnapshot.metadata?.retryForkPiEntryId === "string"
|
|
213
|
+
? processSnapshot.metadata.retryForkPiEntryId
|
|
214
|
+
: null,
|
|
215
|
+
],
|
|
216
|
+
["state", payload.resume ? semanticEntryRefs.currentPrimaryPathLeaf?.entryId : null],
|
|
217
|
+
["payload", payload.resume ? payload.resumeLeafEntryId : null],
|
|
218
|
+
] as const) {
|
|
219
|
+
if (entryId && !candidates.some((candidate) => candidate.entryId === entryId)) {
|
|
220
|
+
candidates.push({ entryId, source });
|
|
221
|
+
}
|
|
217
222
|
}
|
|
218
223
|
|
|
219
224
|
return candidates;
|
|
@@ -393,11 +398,17 @@ export async function bootstrapWorkerRuntime(
|
|
|
393
398
|
const paramsJson = deps.payload.processSnapshot.paramsJson ?? null;
|
|
394
399
|
const stateJson = deps.payload.processSnapshot.stateJson ?? null;
|
|
395
400
|
|
|
396
|
-
// Try the new worker process resolver first
|
|
397
401
|
const resolvedWorkerProcess = deps.resolveWorkerProcess
|
|
398
402
|
? await deps.resolveWorkerProcess(processId, { paramsJson, stateJson })
|
|
399
403
|
: undefined;
|
|
400
404
|
|
|
405
|
+
const dockerCredentials = deps.payload.dockerRegistryCredentials ?? [];
|
|
406
|
+
if (dockerCredentials.length && !deps.configureDockerCredentials)
|
|
407
|
+
throw new Error("Docker credential delivery is unavailable");
|
|
408
|
+
deps.configureDockerCredentials?.(
|
|
409
|
+
dockerCredentials,
|
|
410
|
+
resolvedWorkerProcess?.runtime?.docker === true,
|
|
411
|
+
);
|
|
401
412
|
const projectSnapshots = projectSnapshotsFromPayload(deps.payload.projectSnapshots);
|
|
402
413
|
const repositoryCredentials = deps.payload.repositoryCredentials ?? [];
|
|
403
414
|
const declaredRequirements =
|
|
@@ -409,6 +420,7 @@ export async function bootstrapWorkerRuntime(
|
|
|
409
420
|
credentials: repositoryCredentials,
|
|
410
421
|
requirements: declaredRequirements,
|
|
411
422
|
projectKeys: new Set(projectSnapshots.map((project) => project.key)),
|
|
423
|
+
projects: projectSnapshots,
|
|
412
424
|
});
|
|
413
425
|
deps.gitOps.configureRepositoryCredentials?.(repositoryCredentials);
|
|
414
426
|
const processSnapshot = buildProcessSnapshotSeed(processId, deps.payload.processSnapshot);
|
|
@@ -423,19 +435,11 @@ export async function bootstrapWorkerRuntime(
|
|
|
423
435
|
}));
|
|
424
436
|
const plan = planRunRoot(workspaceRoot, deps.instanceId, runRootProjects);
|
|
425
437
|
|
|
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
|
-
}
|
|
438
|
+
const runRootPreparation = deps.payload.resume
|
|
439
|
+
? validateRunRoot(workspaceRoot, runRootProjects, deps.gitOps).then((validation) =>
|
|
440
|
+
repairRunRoot(workspaceRoot, validation, plan, deps.gitOps),
|
|
441
|
+
)
|
|
442
|
+
: materializeRunRoot(plan, deps.gitOps);
|
|
439
443
|
|
|
440
444
|
const resolvedPiConfig = llmPayload
|
|
441
445
|
? resolveProcessPiConfig({
|
|
@@ -462,6 +466,26 @@ export async function bootstrapWorkerRuntime(
|
|
|
462
466
|
let loadedAgentsFiles: Array<{ path: string; sizeBytes: number }> = [];
|
|
463
467
|
let loadedSkillFiles: Array<{ name: string; path: string }> = [];
|
|
464
468
|
let receipt: WorkerBootstrapReceipt;
|
|
469
|
+
const runRoot = await runRootPreparation;
|
|
470
|
+
let preparedTools: PreparedToolEnvironment | undefined;
|
|
471
|
+
if (resolvedWorkerProcess?.runtime?.developmentTools) {
|
|
472
|
+
if (!deps.payload.developmentTools) {
|
|
473
|
+
throw new Error("Development-tool settings are unavailable for an opted-in process");
|
|
474
|
+
}
|
|
475
|
+
preparedTools = await (deps.developmentTools ?? new MiseDevelopmentToolEnvironment()).prepare({
|
|
476
|
+
config: deps.payload.developmentTools,
|
|
477
|
+
repositories: projectSnapshots.map((project) => ({
|
|
478
|
+
repositoryKey: project.key,
|
|
479
|
+
workingDirectory: path.join(workspaceRoot, project.key),
|
|
480
|
+
})),
|
|
481
|
+
signal: deps.toolPreparationSignal,
|
|
482
|
+
onProgress: deps.onToolPreparationProgress,
|
|
483
|
+
onDiagnosticTrace: deps.onToolDiagnosticTrace,
|
|
484
|
+
});
|
|
485
|
+
for (const [key, value] of Object.entries(preparedTools.commandEnvironment)) {
|
|
486
|
+
if (key === "PATH" || key.startsWith("MISE_")) process.env[key] = value;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
465
489
|
if (llmPayload) {
|
|
466
490
|
const start =
|
|
467
491
|
deps.payload.turnStart.state.kind === "starting" ||
|
|
@@ -497,11 +521,32 @@ export async function bootstrapWorkerRuntime(
|
|
|
497
521
|
instanceId: deps.instanceId,
|
|
498
522
|
startOrLeaseId: deps.payload.workerLeaseId,
|
|
499
523
|
});
|
|
500
|
-
|
|
501
|
-
|
|
524
|
+
const deliveredBundle =
|
|
525
|
+
llmPayload.bootstrap.resourceBundle.archiveBase64 === undefined
|
|
526
|
+
? undefined
|
|
527
|
+
: Buffer.from(llmPayload.bootstrap.resourceBundle.archiveBase64, "base64");
|
|
528
|
+
if (deliveredBundle) {
|
|
529
|
+
verifyCanonicalPiResourceBundle(deliveredBundle, llmPayload.bootstrap.resourceBundle.digest);
|
|
530
|
+
}
|
|
531
|
+
const resourceBundleInput = {
|
|
532
|
+
bundlesDir: deps.payload.treePaths.piResourceBundlesDir,
|
|
533
|
+
startRecordId: deps.payload.turnStart.id,
|
|
502
534
|
digest: llmPayload.bootstrap.resourceBundle.digest,
|
|
503
|
-
|
|
535
|
+
archiveBase64: llmPayload.bootstrap.resourceBundle.archiveBase64,
|
|
536
|
+
};
|
|
537
|
+
const persistedResourceBundle = persistPiResourceBundleForStart({
|
|
538
|
+
...resourceBundleInput,
|
|
539
|
+
...(deliveredBundle ? { deliveredBundle } : {}),
|
|
504
540
|
});
|
|
541
|
+
const bundle = deliveredBundle ?? (await persistedResourceBundle).bundle;
|
|
542
|
+
await Promise.all([
|
|
543
|
+
persistedResourceBundle,
|
|
544
|
+
materializeCanonicalPiResourceBundle({
|
|
545
|
+
bundle,
|
|
546
|
+
digest: llmPayload.bootstrap.resourceBundle.digest,
|
|
547
|
+
targetDir: managedAgentDir,
|
|
548
|
+
}),
|
|
549
|
+
]);
|
|
505
550
|
const manifest = await readAndValidateManagedPiResourceManifest({
|
|
506
551
|
agentDir: managedAgentDir,
|
|
507
552
|
resourceDigest: llmPayload.bootstrap.resourceBundle.digest,
|
|
@@ -608,12 +653,24 @@ export async function bootstrapWorkerRuntime(
|
|
|
608
653
|
resumed: deps.payload.resume,
|
|
609
654
|
primaryTreeFile: deps.payload.treePaths.primaryTreeFile,
|
|
610
655
|
workspaceRoot: deps.payload.treePaths.workspaceRoot,
|
|
611
|
-
aggregatedAgentsSources: aggregatedAgentsMdSources,
|
|
612
|
-
loadedSkills,
|
|
656
|
+
aggregatedAgentsSources: runRoot.aggregatedAgentsMdSources,
|
|
657
|
+
loadedSkills: runRoot.loadedSkills,
|
|
613
658
|
loadedAgentsFiles,
|
|
614
659
|
loadedSkillFiles,
|
|
615
660
|
rootEntryId: null,
|
|
616
661
|
receipt,
|
|
662
|
+
...(preparedTools
|
|
663
|
+
? {
|
|
664
|
+
developmentTools: {
|
|
665
|
+
miseVersion: preparedTools.miseVersion,
|
|
666
|
+
repositories: preparedTools.repositories.map((repository) => ({
|
|
667
|
+
repositoryKey: repository.repositoryKey,
|
|
668
|
+
tools: repository.tools,
|
|
669
|
+
})),
|
|
670
|
+
warnings: preparedTools.warnings,
|
|
671
|
+
},
|
|
672
|
+
}
|
|
673
|
+
: {}),
|
|
617
674
|
},
|
|
618
675
|
pendingInputs,
|
|
619
676
|
...(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
|
? {
|
package/src/runtime/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ServerToWorkerMessage } from "@leitwerk-dev/worker-protocol";
|
|
2
|
+
import { MiseDevelopmentToolEnvironment } from "../development-tool-environment.js";
|
|
2
3
|
import { deliverBatch } from "../input-consumer.js";
|
|
3
4
|
import { WorkerIntegrationToolBridge } from "../integration-tool-bridge.js";
|
|
4
5
|
import type { WorkerIpc } from "../ipc.js";
|
|
@@ -8,6 +9,7 @@ import { resolveRootEntryIdFromHandle } from "../turn-tree-strategy.js";
|
|
|
8
9
|
import { createWorkerIpcReporter } from "../worker-ipc-reporter.js";
|
|
9
10
|
import type { WorkerRuntimeOptions, WorkerRuntimeTimer } from "./adapters.js";
|
|
10
11
|
import { sampleCredentialFiles, WorkerLiveResources } from "./bootstrap-session.js";
|
|
12
|
+
import { extractDockerRegistrySecretValues, redactSecrets } from "./failure-policy.js";
|
|
11
13
|
import {
|
|
12
14
|
createInitialWorkerRuntimeState,
|
|
13
15
|
reduceWorkerRuntime,
|
|
@@ -39,23 +41,39 @@ export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntim
|
|
|
39
41
|
const { config, adapters } = options;
|
|
40
42
|
const sampleCredentials = adapters.sampleCredentials ?? sampleCredentialFiles;
|
|
41
43
|
const ipc: WorkerIpc = adapters.transport;
|
|
44
|
+
const deliveredSecrets = new Set<string>();
|
|
45
|
+
const redact = (text: string) =>
|
|
46
|
+
redactSecrets(
|
|
47
|
+
text,
|
|
48
|
+
[...deliveredSecrets].sort((a, b) => b.length - a.length),
|
|
49
|
+
);
|
|
50
|
+
function redactValue<T>(value: T): T {
|
|
51
|
+
if (deliveredSecrets.size === 0) return value;
|
|
52
|
+
if (typeof value === "string") return redact(value) as T;
|
|
53
|
+
if (Array.isArray(value)) return value.map(redactValue) as T;
|
|
54
|
+
if (value && typeof value === "object")
|
|
55
|
+
return Object.fromEntries(
|
|
56
|
+
Object.entries(value).map(([key, item]) => [key, redactValue(item)]),
|
|
57
|
+
) as T;
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
const emitExtensionEvent = (event: string, payload: unknown) =>
|
|
61
|
+
adapters.extensionEvents?.emit(event, redactValue(payload));
|
|
62
|
+
const writeStderr = (text: string) => adapters.stderr?.write(`${redact(text)}\n`);
|
|
42
63
|
const queue: WorkerRuntimeEvent[] = [];
|
|
43
64
|
const timers = new Map<WorkerTimerName, WorkerRuntimeTimer>();
|
|
44
65
|
let state: WorkerRuntimeStateMachine = createInitialWorkerRuntimeState();
|
|
45
66
|
let draining = false;
|
|
46
67
|
let started = false;
|
|
47
68
|
let invariantQueued = false;
|
|
48
|
-
|
|
49
|
-
const closed = new Promise<void>((resolve) => {
|
|
50
|
-
resolveClosed = resolve;
|
|
51
|
-
});
|
|
69
|
+
const { promise: closed, resolve: resolveClosed } = Promise.withResolvers<void>();
|
|
52
70
|
|
|
53
71
|
const reporter = createWorkerIpcReporter({
|
|
54
72
|
instanceId: config.instanceId,
|
|
55
73
|
workerId: config.workerId,
|
|
56
74
|
now: () => adapters.scheduler.now(),
|
|
57
|
-
send: (message) => ipc.send(message),
|
|
58
|
-
emitExtensionEvent
|
|
75
|
+
send: (message) => ipc.send(redactValue(message)),
|
|
76
|
+
emitExtensionEvent,
|
|
59
77
|
});
|
|
60
78
|
const questionBridge = new WorkerQuestionBridge(reporter);
|
|
61
79
|
const integrationToolBridge = new WorkerIntegrationToolBridge(reporter);
|
|
@@ -63,7 +81,7 @@ export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntim
|
|
|
63
81
|
let dispatch: (event: WorkerRuntimeEvent) => void;
|
|
64
82
|
const piEvents = createPiEventReporter({
|
|
65
83
|
reporter,
|
|
66
|
-
emitExtensionEvent
|
|
84
|
+
emitExtensionEvent,
|
|
67
85
|
getCurrentSelectedTurnId: () => state.session?.selectedTurnId ?? null,
|
|
68
86
|
getSessionTainted: () => state.sessionTainted,
|
|
69
87
|
onLifecycleObservation(kind) {
|
|
@@ -74,12 +92,16 @@ export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntim
|
|
|
74
92
|
instanceId: config.instanceId,
|
|
75
93
|
piFactory: adapters.piFactory,
|
|
76
94
|
gitOps: adapters.gitOps,
|
|
95
|
+
developmentTools: adapters.developmentTools ?? new MiseDevelopmentToolEnvironment(),
|
|
77
96
|
scheduler: adapters.scheduler,
|
|
78
97
|
sessionSnapshots: adapters.sessionSnapshots,
|
|
79
98
|
resolveWorkerProcess: adapters.resolveWorkerProcess,
|
|
80
99
|
progress(payload) {
|
|
81
100
|
reporter.workerTrace(payload, state.session?.selectedTurnId ?? null);
|
|
82
101
|
},
|
|
102
|
+
diagnosticTrace(text) {
|
|
103
|
+
reporter.project({ kind: "protocol", type: "worker.diagnostic_trace", payload: { text } });
|
|
104
|
+
},
|
|
83
105
|
});
|
|
84
106
|
|
|
85
107
|
const invariant = (error: unknown): void => {
|
|
@@ -216,6 +238,12 @@ export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntim
|
|
|
216
238
|
{ turnRecordId: emission.turnRecordId, report: emission.report },
|
|
217
239
|
command.session.selectedTurnId,
|
|
218
240
|
);
|
|
241
|
+
} else if (emission.kind === "prepared") {
|
|
242
|
+
reporter.workerEvent(
|
|
243
|
+
"turn.prepared",
|
|
244
|
+
{ turnRecordId: emission.turnRecordId, data: emission.data },
|
|
245
|
+
command.session.selectedTurnId,
|
|
246
|
+
);
|
|
219
247
|
} else reporter.workerError(emission.payload, command.session.selectedTurnId);
|
|
220
248
|
},
|
|
221
249
|
}),
|
|
@@ -288,19 +316,16 @@ export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntim
|
|
|
288
316
|
...(output.payload as object),
|
|
289
317
|
}
|
|
290
318
|
: output.payload;
|
|
291
|
-
|
|
319
|
+
emitExtensionEvent(output.event, payload);
|
|
292
320
|
return;
|
|
293
321
|
}
|
|
294
322
|
if (output.kind === "diagnostic") {
|
|
295
323
|
reporter.workerTrace(output.payload, state.session?.selectedTurnId ?? null);
|
|
296
|
-
if (output.stderr)
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
if (output.kind === "stderr") {
|
|
300
|
-
adapters.stderr?.write(`${output.message}\n`);
|
|
324
|
+
if (output.stderr) writeStderr(output.stderr);
|
|
301
325
|
return;
|
|
302
326
|
}
|
|
303
|
-
|
|
327
|
+
if (output.kind === "stderr") writeStderr(output.message);
|
|
328
|
+
else launch(output);
|
|
304
329
|
};
|
|
305
330
|
|
|
306
331
|
function drain(): void {
|
|
@@ -340,6 +365,9 @@ export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntim
|
|
|
340
365
|
};
|
|
341
366
|
|
|
342
367
|
const receive = (message: ServerToWorkerMessage): void => {
|
|
368
|
+
if (message.type === "worker.start")
|
|
369
|
+
for (const secret of extractDockerRegistrySecretValues(message.payload))
|
|
370
|
+
deliveredSecrets.add(secret);
|
|
343
371
|
if (message.type === "worker.integration_tool_result") {
|
|
344
372
|
integrationToolBridge.handle(message);
|
|
345
373
|
return;
|
|
@@ -353,6 +381,7 @@ export function createWorkerRuntime(options: WorkerRuntimeOptions): WorkerRuntim
|
|
|
353
381
|
dispatch({ kind: "operator_abort_observed" });
|
|
354
382
|
return;
|
|
355
383
|
}
|
|
384
|
+
if (message.type === "worker.stop") resources.abortToolPreparation();
|
|
356
385
|
dispatch({ kind: "server_message", message });
|
|
357
386
|
};
|
|
358
387
|
|