@leitwerk-dev/worker 0.3.0 → 0.4.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/{chunk-4WNVRNE5.js → chunk-KJCBXN5F.js} +1856 -1394
- package/dist/chunk-KJCBXN5F.js.map +1 -0
- package/dist/container-entry-main.js +160 -3
- package/dist/container-entry-main.js.map +1 -1
- package/dist/container-entry.d.ts +1 -0
- package/dist/container-entry.d.ts.map +1 -1
- package/dist/development-tool-environment.d.ts.map +1 -1
- package/dist/diagnostics.d.ts +5 -1
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/docker-registry-credentials.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/ipc.d.ts.map +1 -1
- package/dist/logical-prompt-runner.d.ts.map +1 -1
- package/dist/missing-tool-recovery-runner.d.ts.map +1 -1
- package/dist/pi-adapter.d.ts +5 -0
- package/dist/pi-adapter.d.ts.map +1 -1
- package/dist/pi-event-reporter.d.ts +2 -0
- package/dist/pi-event-reporter.d.ts.map +1 -1
- package/dist/pi-inspection.d.ts +5 -0
- package/dist/pi-inspection.d.ts.map +1 -0
- package/dist/pi-resource-bundle.d.ts +8 -1
- package/dist/pi-resource-bundle.d.ts.map +1 -1
- package/dist/runtime/bootstrap-session.d.ts +5 -1
- package/dist/runtime/bootstrap-session.d.ts.map +1 -1
- package/dist/runtime/bootstrap.d.ts.map +1 -1
- package/dist/runtime/failure-policy.d.ts.map +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/llm-turn-execution.d.ts +2 -0
- package/dist/runtime/llm-turn-execution.d.ts.map +1 -1
- package/dist/runtime/turn-execution.d.ts.map +1 -1
- package/dist/session-snapshot-exchange.d.ts.map +1 -1
- package/dist/strict-outcome-schema.d.ts +11 -0
- package/dist/strict-outcome-schema.d.ts.map +1 -0
- package/dist/test-helpers/llm-turn.d.ts +4 -0
- package/dist/test-helpers/llm-turn.d.ts.map +1 -0
- package/dist/test-helpers/pi-provider.d.ts +13 -0
- package/dist/test-helpers/pi-provider.d.ts.map +1 -0
- package/dist/transport-error.d.ts +16 -0
- package/dist/transport-error.d.ts.map +1 -0
- package/dist/turn-outcome-tool-session.d.ts +6 -1
- package/dist/turn-outcome-tool-session.d.ts.map +1 -1
- package/dist/turn-result-markdown.d.ts +5 -0
- package/dist/turn-result-markdown.d.ts.map +1 -1
- package/dist/virtual-machine-docker.d.ts +10 -0
- package/dist/virtual-machine-docker.d.ts.map +1 -0
- package/dist/worker-entry.js +1 -1
- package/dist/workspace/checkout-tool.d.ts +6 -0
- package/dist/workspace/checkout-tool.d.ts.map +1 -0
- package/dist/workspace/manifest.d.ts +2 -0
- package/dist/workspace/manifest.d.ts.map +1 -1
- package/dist/workspace/node-run-root-git-ops.d.ts +1 -0
- package/dist/workspace/node-run-root-git-ops.d.ts.map +1 -1
- package/dist/workspace/run-root.d.ts +5 -3
- package/dist/workspace/run-root.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/container-entry.ts +22 -0
- package/src/development-tool-environment.ts +2 -0
- package/src/diagnostics.ts +6 -1
- package/src/docker-registry-credentials.ts +8 -0
- package/src/index.ts +1 -0
- package/src/ipc.ts +4 -24
- package/src/logical-prompt-runner.ts +45 -41
- package/src/missing-tool-recovery-runner.ts +26 -18
- package/src/pi-adapter.ts +222 -337
- package/src/pi-event-reporter.ts +8 -0
- package/src/pi-inspection.ts +126 -0
- package/src/pi-resource-bundle.ts +12 -2
- package/src/runtime/bootstrap-session.ts +14 -1
- package/src/runtime/bootstrap.ts +16 -5
- package/src/runtime/failure-policy.ts +20 -2
- package/src/runtime/index.ts +65 -10
- package/src/runtime/llm-turn-execution.ts +28 -1
- package/src/runtime/turn-execution.ts +71 -2
- package/src/session-snapshot-exchange.ts +2 -0
- package/src/strict-outcome-schema.ts +84 -0
- package/src/test-helpers/llm-turn.ts +22 -0
- package/src/test-helpers/pi-provider.ts +126 -0
- package/src/transport-error.ts +92 -0
- package/src/turn-outcome-tool-session.ts +123 -26
- package/src/turn-result-markdown.ts +23 -6
- package/src/virtual-machine-docker.ts +191 -0
- package/src/workspace/checkout-tool.ts +68 -0
- package/src/workspace/manifest.ts +3 -0
- package/src/workspace/node-run-root-git-ops.ts +19 -0
- package/src/workspace/run-root.ts +62 -26
- package/dist/chunk-4WNVRNE5.js.map +0 -1
|
@@ -118,6 +118,20 @@ export async function executeLogicalPromptPlan<TOutcome extends string>(input: {
|
|
|
118
118
|
const taint = (reason: string) => input.emit?.({ kind: "session_tainted", reason });
|
|
119
119
|
let currentPlan = input.plan;
|
|
120
120
|
let compactionContinueAttempts = 0;
|
|
121
|
+
const requestCompactionContinuation = (resultPiEntryId: string | null, afterError = false) => {
|
|
122
|
+
compactionContinueAttempts += 1;
|
|
123
|
+
trace({
|
|
124
|
+
level: "info",
|
|
125
|
+
code: afterError
|
|
126
|
+
? "turn.compaction_error_continue_requested"
|
|
127
|
+
: "turn.compaction_continue_requested",
|
|
128
|
+
message: `Turn '${input.turnId}' requested an explicit continue after ${afterError ? "context-window compaction" : "compaction"}`,
|
|
129
|
+
turnRecordId: input.turnRecordId,
|
|
130
|
+
turnId: input.turnId,
|
|
131
|
+
details: { attempt: compactionContinueAttempts, resultPiEntryId },
|
|
132
|
+
});
|
|
133
|
+
currentPlan = DEFAULT_CONTINUATION_PLAN;
|
|
134
|
+
};
|
|
121
135
|
const reportFailure = (
|
|
122
136
|
error: unknown,
|
|
123
137
|
args: {
|
|
@@ -158,21 +172,24 @@ export async function executeLogicalPromptPlan<TOutcome extends string>(input: {
|
|
|
158
172
|
for (;;) {
|
|
159
173
|
const plan = currentPlan;
|
|
160
174
|
const guardSuspension = new PromptGuardSuspension();
|
|
161
|
-
const promptOptions =
|
|
162
|
-
input.toolSession.tools
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
:
|
|
175
|
+
const promptOptions = {
|
|
176
|
+
tools: input.toolSession.tools,
|
|
177
|
+
activeTools: input.toolSession.activeTools,
|
|
178
|
+
shouldBlockToolCall: (toolName: string) => input.toolSession.shouldBlockToolCall(toolName),
|
|
179
|
+
shouldStopAfterTurn: (toolResults: readonly unknown[]) => {
|
|
180
|
+
let rejected = false;
|
|
181
|
+
for (const message of toolResults) {
|
|
182
|
+
rejected = input.toolSession.recordToolResult(message) || rejected;
|
|
183
|
+
}
|
|
184
|
+
return rejected || Boolean(input.toolSession.getCompletionState().abortReason);
|
|
185
|
+
},
|
|
186
|
+
suspendPromptGuards: () => guardSuspension.suspend(),
|
|
187
|
+
terminalAcknowledgement: {
|
|
188
|
+
...input.toolSession.terminalAcknowledgement,
|
|
189
|
+
timeoutMs: TERMINAL_ACKNOWLEDGEMENT_TIMEOUT_MS,
|
|
190
|
+
isOperatorAbortRequested: () => input.operatorAbortSignal?.aborted === true,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
176
193
|
|
|
177
194
|
let runPrompt = () =>
|
|
178
195
|
plan.kind === "continue"
|
|
@@ -236,7 +253,11 @@ export async function executeLogicalPromptPlan<TOutcome extends string>(input: {
|
|
|
236
253
|
"Terminal acknowledgement did not complete and was ignored",
|
|
237
254
|
);
|
|
238
255
|
}
|
|
256
|
+
for (const entryId of attempt.result.createdEntryIds) {
|
|
257
|
+
input.toolSession.recordToolResult(input.piHandle.getEntry(entryId)?.message);
|
|
258
|
+
}
|
|
239
259
|
const completionState = input.toolSession.getCompletionState();
|
|
260
|
+
if (completionState.abortReason) throw new Error(completionState.abortReason);
|
|
240
261
|
const acknowledgementFailure = input.toolSession.terminalAcknowledgement.failureReason();
|
|
241
262
|
if (acknowledgementFailure) {
|
|
242
263
|
trace({
|
|
@@ -255,19 +276,7 @@ export async function executeLogicalPromptPlan<TOutcome extends string>(input: {
|
|
|
255
276
|
compactionContinueAttempts,
|
|
256
277
|
})
|
|
257
278
|
) {
|
|
258
|
-
|
|
259
|
-
trace({
|
|
260
|
-
level: "info",
|
|
261
|
-
code: "turn.compaction_continue_requested",
|
|
262
|
-
message: `Turn '${input.turnId}' requested an explicit continue after compaction`,
|
|
263
|
-
turnRecordId: input.turnRecordId,
|
|
264
|
-
turnId: input.turnId,
|
|
265
|
-
details: {
|
|
266
|
-
attempt: compactionContinueAttempts,
|
|
267
|
-
resultPiEntryId: attempt.result.resultEntryId,
|
|
268
|
-
},
|
|
269
|
-
});
|
|
270
|
-
currentPlan = DEFAULT_CONTINUATION_PLAN;
|
|
279
|
+
requestCompactionContinuation(attempt.result.resultEntryId);
|
|
271
280
|
continue;
|
|
272
281
|
}
|
|
273
282
|
return {
|
|
@@ -276,6 +285,13 @@ export async function executeLogicalPromptPlan<TOutcome extends string>(input: {
|
|
|
276
285
|
resolvedOutcome,
|
|
277
286
|
};
|
|
278
287
|
} catch (error: unknown) {
|
|
288
|
+
const { abortReason } = input.toolSession.getCompletionState();
|
|
289
|
+
if (abortReason)
|
|
290
|
+
return input.reportFailedTurn(
|
|
291
|
+
"llm_error",
|
|
292
|
+
`Turn aborted by LLM: ${abortReason}`,
|
|
293
|
+
input.piHandle.getLeafId(),
|
|
294
|
+
);
|
|
279
295
|
if (
|
|
280
296
|
shouldAutoContinueAfterCompactionError({
|
|
281
297
|
error,
|
|
@@ -283,19 +299,7 @@ export async function executeLogicalPromptPlan<TOutcome extends string>(input: {
|
|
|
283
299
|
compactionContinueAttempts,
|
|
284
300
|
})
|
|
285
301
|
) {
|
|
286
|
-
|
|
287
|
-
trace({
|
|
288
|
-
level: "info",
|
|
289
|
-
code: "turn.compaction_error_continue_requested",
|
|
290
|
-
message: `Turn '${input.turnId}' requested an explicit continue after context-window compaction`,
|
|
291
|
-
turnRecordId: input.turnRecordId,
|
|
292
|
-
turnId: input.turnId,
|
|
293
|
-
details: {
|
|
294
|
-
attempt: compactionContinueAttempts,
|
|
295
|
-
resultPiEntryId: input.piHandle.getLeafId(),
|
|
296
|
-
},
|
|
297
|
-
});
|
|
298
|
-
currentPlan = DEFAULT_CONTINUATION_PLAN;
|
|
302
|
+
requestCompactionContinuation(input.piHandle.getLeafId(), true);
|
|
299
303
|
continue;
|
|
300
304
|
}
|
|
301
305
|
return reportFailure(error, {
|
|
@@ -27,29 +27,28 @@ export async function runMissingToolRecovery<TOutcome extends string>(input: {
|
|
|
27
27
|
const trace = (payload: WorkerDiagnosticPayload) => input.emit?.({ kind: "trace", payload });
|
|
28
28
|
const reportError = (payload: WorkerDiagnosticPayload) =>
|
|
29
29
|
input.emit?.({ kind: "error", payload });
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
);
|
|
33
|
-
if (!baseMissingToolRecovery) {
|
|
30
|
+
let recovery = input.toolSession.resolveMissingToolRecovery(input.initialAttempt.completionState);
|
|
31
|
+
if (!recovery) {
|
|
34
32
|
return { finalAttempt: input.initialAttempt };
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
let recoveryContext = input.toolSession.buildRecoveryContext(recovery);
|
|
36
|
+
let description = input.toolSession.describeRecovery(recovery);
|
|
39
37
|
reportError({
|
|
40
38
|
level: "warn",
|
|
41
|
-
code: "turn.required_tool_call_missing",
|
|
42
|
-
message: `Turn '${input.turnId}'
|
|
39
|
+
code: recovery.rejectedOutcome ? "turn.outcome_rejected" : "turn.required_tool_call_missing",
|
|
40
|
+
message: `Turn '${input.turnId}' did not complete: ${description}`,
|
|
43
41
|
turnRecordId: input.turnRecordId,
|
|
44
42
|
turnId: input.turnId,
|
|
45
43
|
errorClass: "protocol_error",
|
|
46
44
|
details: {
|
|
47
45
|
attemptBudget: MAX_MISSING_TOOL_CALL_RECOVERY_ATTEMPTS,
|
|
48
|
-
missingToolNames:
|
|
46
|
+
missingToolNames: recovery.missingToolNames,
|
|
49
47
|
},
|
|
50
48
|
});
|
|
51
49
|
|
|
52
50
|
let finalAttempt = input.initialAttempt;
|
|
51
|
+
let unchangedRejections = 0;
|
|
53
52
|
for (
|
|
54
53
|
let recoveryAttempt = 1;
|
|
55
54
|
recoveryAttempt <= MAX_MISSING_TOOL_CALL_RECOVERY_ATTEMPTS;
|
|
@@ -58,37 +57,46 @@ export async function runMissingToolRecovery<TOutcome extends string>(input: {
|
|
|
58
57
|
trace({
|
|
59
58
|
level: "info",
|
|
60
59
|
code: "turn.required_tool_call_retry_requested",
|
|
61
|
-
message: `Turn '${input.turnId}' is retrying
|
|
60
|
+
message: `Turn '${input.turnId}' is retrying: ${description}`,
|
|
62
61
|
turnRecordId: input.turnRecordId,
|
|
63
62
|
turnId: input.turnId,
|
|
64
63
|
details: {
|
|
65
64
|
recoveryAttempt,
|
|
66
|
-
missingToolNames:
|
|
65
|
+
missingToolNames: recovery.missingToolNames,
|
|
67
66
|
},
|
|
68
67
|
});
|
|
68
|
+
const previousAttempt = finalAttempt;
|
|
69
69
|
finalAttempt = await input.executeLogicalPromptPlan(
|
|
70
70
|
{
|
|
71
71
|
kind: "continue",
|
|
72
72
|
continueUserPrompt: recoveryContext.suggestedContinuePrompt,
|
|
73
73
|
prepareForContinuation: async () =>
|
|
74
|
-
await input.piHandle.branch(
|
|
74
|
+
await input.piHandle.branch(previousAttempt.promptResult.resultEntryId),
|
|
75
75
|
},
|
|
76
|
-
{ baseState:
|
|
76
|
+
{ baseState: previousAttempt.completionState },
|
|
77
77
|
);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const nextRecovery = input.toolSession.resolveMissingToolRecovery(finalAttempt.completionState);
|
|
79
|
+
if (!nextRecovery) return { finalAttempt };
|
|
80
|
+
unchangedRejections =
|
|
81
|
+
recovery.rejectedOutcome &&
|
|
82
|
+
JSON.stringify(recovery.rejectedOutcome) === JSON.stringify(nextRecovery.rejectedOutcome)
|
|
83
|
+
? unchangedRejections + 1
|
|
84
|
+
: 0;
|
|
85
|
+
recovery = nextRecovery;
|
|
86
|
+
recoveryContext = input.toolSession.buildRecoveryContext(recovery);
|
|
87
|
+
description = input.toolSession.describeRecovery(recovery);
|
|
88
|
+
if (unchangedRejections >= 2) break;
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
reportError({
|
|
84
92
|
level: "error",
|
|
85
93
|
code: "turn.required_tool_call_retry_exhausted",
|
|
86
|
-
message: `Turn '${input.turnId}'
|
|
94
|
+
message: `Turn '${input.turnId}' stopped automatic recovery: ${description}`,
|
|
87
95
|
turnRecordId: input.turnRecordId,
|
|
88
96
|
turnId: input.turnId,
|
|
89
97
|
errorClass: "protocol_error",
|
|
90
98
|
details: {
|
|
91
|
-
missingToolNames:
|
|
99
|
+
missingToolNames: recovery.missingToolNames,
|
|
92
100
|
},
|
|
93
101
|
});
|
|
94
102
|
return {
|