coremind-runtime 0.2.0-beta.2 → 0.2.0-rc.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/README.md +10 -2
- package/dist/checkpoint.d.ts +5 -0
- package/dist/checkpoint.d.ts.map +1 -1
- package/dist/checkpoint.js +73 -1
- package/dist/checkpoint.js.map +1 -1
- package/dist/context.d.ts +6 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +48 -9
- package/dist/context.js.map +1 -1
- package/dist/evaluation-graders.d.ts +89 -0
- package/dist/evaluation-graders.d.ts.map +1 -0
- package/dist/evaluation-graders.js +481 -0
- package/dist/evaluation-graders.js.map +1 -0
- package/dist/evaluation.d.ts +13 -2
- package/dist/evaluation.d.ts.map +1 -1
- package/dist/evaluation.js +118 -37
- package/dist/evaluation.js.map +1 -1
- package/dist/events.d.ts +22 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/loop-controller.d.ts +79 -0
- package/dist/loop-controller.d.ts.map +1 -0
- package/dist/loop-controller.js +372 -0
- package/dist/loop-controller.js.map +1 -0
- package/dist/loop-runner.d.ts +52 -0
- package/dist/loop-runner.d.ts.map +1 -0
- package/dist/loop-runner.js +213 -0
- package/dist/loop-runner.js.map +1 -0
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +3 -2
- package/dist/orchestrator.js.map +1 -1
- package/dist/public-tool.d.ts +2 -0
- package/dist/public-tool.d.ts.map +1 -1
- package/dist/public-tool.js +12 -0
- package/dist/public-tool.js.map +1 -1
- package/dist/result.d.ts +1 -1
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js.map +1 -1
- package/dist/retry-policy.d.ts +16 -0
- package/dist/retry-policy.d.ts.map +1 -0
- package/dist/retry-policy.js +112 -0
- package/dist/retry-policy.js.map +1 -0
- package/dist/run-state.d.ts +12 -1
- package/dist/run-state.d.ts.map +1 -1
- package/dist/run-state.js +72 -3
- package/dist/run-state.js.map +1 -1
- package/dist/run-terminalizer.d.ts +11 -0
- package/dist/run-terminalizer.d.ts.map +1 -0
- package/dist/run-terminalizer.js +38 -0
- package/dist/run-terminalizer.js.map +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +230 -55
- package/dist/runtime.js.map +1 -1
- package/dist/tool-policy.d.ts +11 -2
- package/dist/tool-policy.d.ts.map +1 -1
- package/dist/tool-policy.js +112 -15
- package/dist/tool-policy.js.map +1 -1
- package/dist/trace.d.ts +2 -0
- package/dist/trace.d.ts.map +1 -1
- package/dist/trace.js +77 -1
- package/dist/trace.js.map +1 -1
- package/package.json +13 -6
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { assign, createActor, setup } from "xstate";
|
|
2
|
+
import { CoreMindError } from "./errors.js";
|
|
3
|
+
const LOOP_MACHINE_VERSION = "1";
|
|
4
|
+
const LOOP_PHASES = new Set([
|
|
5
|
+
"idle",
|
|
6
|
+
"planning",
|
|
7
|
+
"executing",
|
|
8
|
+
"verifying",
|
|
9
|
+
"repairing",
|
|
10
|
+
"paused",
|
|
11
|
+
"succeeded",
|
|
12
|
+
"failed",
|
|
13
|
+
"aborted",
|
|
14
|
+
"timeout",
|
|
15
|
+
"budget_exceeded",
|
|
16
|
+
]);
|
|
17
|
+
const TERMINAL_PHASES = new Set([
|
|
18
|
+
"succeeded",
|
|
19
|
+
"failed",
|
|
20
|
+
"aborted",
|
|
21
|
+
"timeout",
|
|
22
|
+
"budget_exceeded",
|
|
23
|
+
]);
|
|
24
|
+
function createLoopMachine(config) {
|
|
25
|
+
return setup({
|
|
26
|
+
types: {
|
|
27
|
+
context: {},
|
|
28
|
+
events: {},
|
|
29
|
+
},
|
|
30
|
+
guards: {
|
|
31
|
+
hasPlanning: () => config.hasPlanning,
|
|
32
|
+
verificationPassed: ({ event }) => event.type === "VERIFIED" && event.passed,
|
|
33
|
+
repairLimitExhausted: ({ context }) => context.iteration >= config.maxIterations || context.repairCount >= config.maxRepairs,
|
|
34
|
+
failOnVerification: () => config.onFailure === "fail",
|
|
35
|
+
pauseOnVerification: () => config.onFailure === "pause",
|
|
36
|
+
repeatedActionExhausted: ({ context, event }) => hasFingerprint(event) &&
|
|
37
|
+
nextRepeatedCount(context, event.fingerprint) >= config.maxRepeatedAction,
|
|
38
|
+
pauseForRepeatedAction: ({ context, event }) => hasFingerprint(event) &&
|
|
39
|
+
nextRepeatedCount(context, event.fingerprint) >= config.maxRepeatedAction &&
|
|
40
|
+
config.onExhausted === "pause",
|
|
41
|
+
resumePlanning: ({ context }) => context.resumePhase === "planning",
|
|
42
|
+
resumeExecuting: ({ context }) => context.resumePhase === "executing",
|
|
43
|
+
resumeVerifying: ({ context }) => context.resumePhase === "verifying",
|
|
44
|
+
resumeRepairing: ({ context }) => context.resumePhase === "repairing",
|
|
45
|
+
},
|
|
46
|
+
actions: {
|
|
47
|
+
recordExecution: assign(({ context, event }) => {
|
|
48
|
+
const execution = event;
|
|
49
|
+
return {
|
|
50
|
+
...recordFingerprint(context, execution.fingerprint),
|
|
51
|
+
iteration: context.iteration + 1,
|
|
52
|
+
};
|
|
53
|
+
}),
|
|
54
|
+
recordRepair: assign(({ context, event }) => {
|
|
55
|
+
const repair = event;
|
|
56
|
+
return {
|
|
57
|
+
...recordFingerprint(context, repair.fingerprint),
|
|
58
|
+
iteration: context.iteration + 1,
|
|
59
|
+
};
|
|
60
|
+
}),
|
|
61
|
+
countRepair: assign(({ context }) => ({ repairCount: context.repairCount + 1 })),
|
|
62
|
+
pauseFromPlanning: assign(({ event }) => pauseContext(event, "planning")),
|
|
63
|
+
pauseFromExecuting: assign(({ event }) => pauseContext(event, "executing")),
|
|
64
|
+
pauseFromVerifying: assign(({ event }) => pauseContext(event, "verifying")),
|
|
65
|
+
pauseFromRepairing: assign(({ event }) => pauseContext(event, "repairing")),
|
|
66
|
+
pauseForVerification: assign(({ context }) => ({
|
|
67
|
+
pauseReason: "verification_failed",
|
|
68
|
+
resumePhase: "repairing",
|
|
69
|
+
repairCount: context.repairCount + 1,
|
|
70
|
+
})),
|
|
71
|
+
pauseForExhaustion: assign({
|
|
72
|
+
pauseReason: "loop_exhausted",
|
|
73
|
+
resumePhase: undefined,
|
|
74
|
+
failureCode: "loop_exhausted",
|
|
75
|
+
failureMessage: "Loop 已达到迭代或修复上限",
|
|
76
|
+
}),
|
|
77
|
+
pauseForNoProgress: assign(({ context, event }) => {
|
|
78
|
+
const action = event;
|
|
79
|
+
return {
|
|
80
|
+
...recordFingerprint(context, action.fingerprint),
|
|
81
|
+
pauseReason: "loop_no_progress",
|
|
82
|
+
resumePhase: undefined,
|
|
83
|
+
failureCode: "loop_no_progress",
|
|
84
|
+
failureMessage: "Loop 重复相同动作,未检测到进展",
|
|
85
|
+
};
|
|
86
|
+
}),
|
|
87
|
+
failForExhaustion: assign({
|
|
88
|
+
failureCode: "loop_exhausted",
|
|
89
|
+
failureMessage: "Loop 已达到迭代或修复上限",
|
|
90
|
+
}),
|
|
91
|
+
failForNoProgress: assign(({ context, event }) => {
|
|
92
|
+
const action = event;
|
|
93
|
+
return {
|
|
94
|
+
...recordFingerprint(context, action.fingerprint),
|
|
95
|
+
failureCode: "loop_no_progress",
|
|
96
|
+
failureMessage: "Loop 重复相同动作,未检测到进展",
|
|
97
|
+
};
|
|
98
|
+
}),
|
|
99
|
+
failForVerification: assign({
|
|
100
|
+
failureCode: "verification_failed",
|
|
101
|
+
failureMessage: "验证未通过,配置要求立即失败",
|
|
102
|
+
}),
|
|
103
|
+
markAborted: assign({
|
|
104
|
+
failureCode: "aborted",
|
|
105
|
+
failureMessage: "执行已中止",
|
|
106
|
+
}),
|
|
107
|
+
markTimeout: assign({
|
|
108
|
+
failureCode: "run_timeout",
|
|
109
|
+
failureMessage: "Loop 执行超时",
|
|
110
|
+
}),
|
|
111
|
+
markBudgetExceeded: assign({
|
|
112
|
+
failureCode: "budget_exceeded",
|
|
113
|
+
failureMessage: "Loop 已耗尽运行预算",
|
|
114
|
+
}),
|
|
115
|
+
markFailure: assign(({ event }) => {
|
|
116
|
+
const failure = event;
|
|
117
|
+
return { failureCode: failure.code, failureMessage: failure.message };
|
|
118
|
+
}),
|
|
119
|
+
clearPause: assign({ pauseReason: undefined, resumePhase: undefined }),
|
|
120
|
+
},
|
|
121
|
+
}).createMachine({
|
|
122
|
+
id: "coremind-loop",
|
|
123
|
+
initial: "idle",
|
|
124
|
+
context: {
|
|
125
|
+
iteration: 0,
|
|
126
|
+
repairCount: 0,
|
|
127
|
+
repeatedActionCount: 0,
|
|
128
|
+
},
|
|
129
|
+
on: {
|
|
130
|
+
ABORT: { target: ".aborted", actions: "markAborted" },
|
|
131
|
+
TIMEOUT: { target: ".timeout", actions: "markTimeout" },
|
|
132
|
+
BUDGET_EXCEEDED: { target: ".budget_exceeded", actions: "markBudgetExceeded" },
|
|
133
|
+
FAIL: { target: ".failed", actions: "markFailure" },
|
|
134
|
+
},
|
|
135
|
+
states: {
|
|
136
|
+
idle: {
|
|
137
|
+
on: {
|
|
138
|
+
START: [{ guard: "hasPlanning", target: "planning" }, { target: "executing" }],
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
planning: {
|
|
142
|
+
on: {
|
|
143
|
+
PLANNED: "executing",
|
|
144
|
+
PAUSE: { target: "paused", actions: "pauseFromPlanning" },
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
executing: {
|
|
148
|
+
on: {
|
|
149
|
+
EXECUTED: [
|
|
150
|
+
{
|
|
151
|
+
guard: "pauseForRepeatedAction",
|
|
152
|
+
target: "paused",
|
|
153
|
+
actions: "pauseForNoProgress",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
guard: ({ context, event }) => event.type === "EXECUTED" &&
|
|
157
|
+
nextRepeatedCount(context, event.fingerprint) >= config.maxRepeatedAction &&
|
|
158
|
+
config.onExhausted === "fail",
|
|
159
|
+
target: "failed",
|
|
160
|
+
actions: "failForNoProgress",
|
|
161
|
+
},
|
|
162
|
+
{ target: "verifying", actions: "recordExecution" },
|
|
163
|
+
],
|
|
164
|
+
PAUSE: { target: "paused", actions: "pauseFromExecuting" },
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
verifying: {
|
|
168
|
+
on: {
|
|
169
|
+
VERIFIED: [
|
|
170
|
+
{ guard: "verificationPassed", target: "succeeded" },
|
|
171
|
+
{
|
|
172
|
+
guard: ({ context }) => (context.iteration >= config.maxIterations ||
|
|
173
|
+
context.repairCount >= config.maxRepairs) &&
|
|
174
|
+
config.onExhausted === "pause",
|
|
175
|
+
target: "paused",
|
|
176
|
+
actions: "pauseForExhaustion",
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
guard: "repairLimitExhausted",
|
|
180
|
+
target: "failed",
|
|
181
|
+
actions: "failForExhaustion",
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
guard: "failOnVerification",
|
|
185
|
+
target: "failed",
|
|
186
|
+
actions: "failForVerification",
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
guard: "pauseOnVerification",
|
|
190
|
+
target: "paused",
|
|
191
|
+
actions: "pauseForVerification",
|
|
192
|
+
},
|
|
193
|
+
{ target: "repairing", actions: "countRepair" },
|
|
194
|
+
],
|
|
195
|
+
PAUSE: { target: "paused", actions: "pauseFromVerifying" },
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
repairing: {
|
|
199
|
+
on: {
|
|
200
|
+
REPAIRED: [
|
|
201
|
+
{
|
|
202
|
+
guard: ({ context, event }) => event.type === "REPAIRED" &&
|
|
203
|
+
nextRepeatedCount(context, event.fingerprint) >= config.maxRepeatedAction &&
|
|
204
|
+
config.onExhausted === "pause",
|
|
205
|
+
target: "paused",
|
|
206
|
+
actions: "pauseForNoProgress",
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
guard: "repeatedActionExhausted",
|
|
210
|
+
target: "failed",
|
|
211
|
+
actions: "failForNoProgress",
|
|
212
|
+
},
|
|
213
|
+
{ target: "verifying", actions: "recordRepair" },
|
|
214
|
+
],
|
|
215
|
+
PAUSE: { target: "paused", actions: "pauseFromRepairing" },
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
paused: {
|
|
219
|
+
on: {
|
|
220
|
+
RESUME: [
|
|
221
|
+
{ guard: "resumePlanning", target: "planning", actions: "clearPause" },
|
|
222
|
+
{ guard: "resumeExecuting", target: "executing", actions: "clearPause" },
|
|
223
|
+
{ guard: "resumeVerifying", target: "verifying", actions: "clearPause" },
|
|
224
|
+
{ guard: "resumeRepairing", target: "repairing", actions: "clearPause" },
|
|
225
|
+
],
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
succeeded: { type: "final" },
|
|
229
|
+
failed: { type: "final" },
|
|
230
|
+
aborted: { type: "final" },
|
|
231
|
+
timeout: { type: "final" },
|
|
232
|
+
budget_exceeded: { type: "final" },
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/** XState 只存在于此适配器内部;调用方只读写 CoreMind 的领域事件和版本化快照。 */
|
|
237
|
+
export class LoopController {
|
|
238
|
+
config;
|
|
239
|
+
actor;
|
|
240
|
+
transitionSequence;
|
|
241
|
+
listeners = new Set();
|
|
242
|
+
constructor(config, snapshot) {
|
|
243
|
+
validateConfig(config);
|
|
244
|
+
this.config = { ...config };
|
|
245
|
+
const machine = createLoopMachine(config);
|
|
246
|
+
this.transitionSequence = snapshot?.transitionSequence ?? 0;
|
|
247
|
+
this.actor = snapshot
|
|
248
|
+
? createActor(machine, {
|
|
249
|
+
snapshot: machine.resolveState({
|
|
250
|
+
value: snapshot.phase,
|
|
251
|
+
context: contextFromSnapshot(snapshot),
|
|
252
|
+
status: TERMINAL_PHASES.has(snapshot.phase) ? "done" : "active",
|
|
253
|
+
}),
|
|
254
|
+
})
|
|
255
|
+
: createActor(machine);
|
|
256
|
+
this.actor.start();
|
|
257
|
+
}
|
|
258
|
+
static restore(config, snapshot) {
|
|
259
|
+
validateSnapshot(config, snapshot);
|
|
260
|
+
return new LoopController(config, snapshot);
|
|
261
|
+
}
|
|
262
|
+
get phase() {
|
|
263
|
+
return this.actor.getSnapshot().value;
|
|
264
|
+
}
|
|
265
|
+
send(event) {
|
|
266
|
+
const from = this.phase;
|
|
267
|
+
this.actor.send(event);
|
|
268
|
+
const to = this.phase;
|
|
269
|
+
if (from === to)
|
|
270
|
+
return;
|
|
271
|
+
this.transitionSequence += 1;
|
|
272
|
+
const transition = {
|
|
273
|
+
sequence: this.transitionSequence,
|
|
274
|
+
event: event.type,
|
|
275
|
+
from,
|
|
276
|
+
to,
|
|
277
|
+
snapshot: this.getSnapshot(),
|
|
278
|
+
};
|
|
279
|
+
for (const listener of this.listeners)
|
|
280
|
+
listener(transition);
|
|
281
|
+
}
|
|
282
|
+
subscribe(listener) {
|
|
283
|
+
this.listeners.add(listener);
|
|
284
|
+
return () => this.listeners.delete(listener);
|
|
285
|
+
}
|
|
286
|
+
getSnapshot() {
|
|
287
|
+
const context = this.actor.getSnapshot().context;
|
|
288
|
+
return {
|
|
289
|
+
schemaVersion: 1,
|
|
290
|
+
machineVersion: LOOP_MACHINE_VERSION,
|
|
291
|
+
runId: this.config.runId,
|
|
292
|
+
configFingerprint: this.config.configFingerprint,
|
|
293
|
+
phase: this.phase,
|
|
294
|
+
iteration: context.iteration,
|
|
295
|
+
repairCount: context.repairCount,
|
|
296
|
+
repeatedActionCount: context.repeatedActionCount,
|
|
297
|
+
transitionSequence: this.transitionSequence,
|
|
298
|
+
...(context.lastActionFingerprint !== undefined
|
|
299
|
+
? { lastActionFingerprint: context.lastActionFingerprint }
|
|
300
|
+
: {}),
|
|
301
|
+
...(context.pauseReason !== undefined ? { pauseReason: context.pauseReason } : {}),
|
|
302
|
+
...(context.resumePhase !== undefined ? { resumePhase: context.resumePhase } : {}),
|
|
303
|
+
...(context.failureCode !== undefined ? { failureCode: context.failureCode } : {}),
|
|
304
|
+
...(context.failureMessage !== undefined ? { failureMessage: context.failureMessage } : {}),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function hasFingerprint(event) {
|
|
309
|
+
return event.type === "EXECUTED" || event.type === "REPAIRED";
|
|
310
|
+
}
|
|
311
|
+
function nextRepeatedCount(context, fingerprint) {
|
|
312
|
+
return context.lastActionFingerprint === fingerprint ? context.repeatedActionCount + 1 : 1;
|
|
313
|
+
}
|
|
314
|
+
function recordFingerprint(context, fingerprint) {
|
|
315
|
+
return {
|
|
316
|
+
lastActionFingerprint: fingerprint,
|
|
317
|
+
repeatedActionCount: nextRepeatedCount(context, fingerprint),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function pauseContext(event, resumePhase) {
|
|
321
|
+
const pause = event;
|
|
322
|
+
return { pauseReason: pause.reason, resumePhase };
|
|
323
|
+
}
|
|
324
|
+
function contextFromSnapshot(snapshot) {
|
|
325
|
+
return {
|
|
326
|
+
iteration: snapshot.iteration,
|
|
327
|
+
repairCount: snapshot.repairCount,
|
|
328
|
+
repeatedActionCount: snapshot.repeatedActionCount,
|
|
329
|
+
...(snapshot.lastActionFingerprint !== undefined
|
|
330
|
+
? { lastActionFingerprint: snapshot.lastActionFingerprint }
|
|
331
|
+
: {}),
|
|
332
|
+
...(snapshot.pauseReason !== undefined ? { pauseReason: snapshot.pauseReason } : {}),
|
|
333
|
+
...(snapshot.resumePhase !== undefined ? { resumePhase: snapshot.resumePhase } : {}),
|
|
334
|
+
...(snapshot.failureCode !== undefined ? { failureCode: snapshot.failureCode } : {}),
|
|
335
|
+
...(snapshot.failureMessage !== undefined ? { failureMessage: snapshot.failureMessage } : {}),
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function validateConfig(config) {
|
|
339
|
+
if (!config.runId || !config.configFingerprint) {
|
|
340
|
+
throw new CoreMindError("loop_config_invalid", "LoopController 缺少 runId 或配置指纹");
|
|
341
|
+
}
|
|
342
|
+
if (!Number.isInteger(config.maxIterations) ||
|
|
343
|
+
config.maxIterations < 1 ||
|
|
344
|
+
!Number.isInteger(config.maxRepairs) ||
|
|
345
|
+
config.maxRepairs < 0 ||
|
|
346
|
+
!Number.isInteger(config.maxRepeatedAction) ||
|
|
347
|
+
config.maxRepeatedAction < 1) {
|
|
348
|
+
throw new CoreMindError("loop_config_invalid", "LoopController 的迭代和修复上限无效");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
function validateSnapshot(config, snapshot) {
|
|
352
|
+
if (snapshot.schemaVersion !== 1 || snapshot.machineVersion !== LOOP_MACHINE_VERSION) {
|
|
353
|
+
throw new CoreMindError("loop_snapshot_invalid", "Loop 快照版本不受支持");
|
|
354
|
+
}
|
|
355
|
+
if (snapshot.runId !== config.runId) {
|
|
356
|
+
throw new CoreMindError("loop_snapshot_mismatch", "Loop 快照 runId 与当前运行不匹配");
|
|
357
|
+
}
|
|
358
|
+
if (snapshot.configFingerprint !== config.configFingerprint) {
|
|
359
|
+
throw new CoreMindError("loop_snapshot_mismatch", "Loop 快照配置指纹与当前配置不匹配");
|
|
360
|
+
}
|
|
361
|
+
if (!LOOP_PHASES.has(snapshot.phase) ||
|
|
362
|
+
!nonNegativeInteger(snapshot.iteration) ||
|
|
363
|
+
!nonNegativeInteger(snapshot.repairCount) ||
|
|
364
|
+
!nonNegativeInteger(snapshot.repeatedActionCount) ||
|
|
365
|
+
!nonNegativeInteger(snapshot.transitionSequence)) {
|
|
366
|
+
throw new CoreMindError("loop_snapshot_invalid", "Loop 快照内容无效");
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function nonNegativeInteger(value) {
|
|
370
|
+
return Number.isInteger(value) && value >= 0;
|
|
371
|
+
}
|
|
372
|
+
//# sourceMappingURL=loop-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-controller.js","sourceRoot":"","sources":["../src/loop-controller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H,CAAC;AAED,SAAS,gBAAgB,CAAC,MAA4B,EAAE,QAAgC;IACtF,IAAI,QAAQ,CAAC,aAAa,KAAK,CAAC,IAAI,QAAQ,CAAC,cAAc,KAAK,oBAAoB,EAAE,CAAC;QACrF,MAAM,IAAI,aAAa,CAAC,uBAAuB,EAAE,eAAe,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,QAAQ,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,IAAI,aAAa,CAAC,wBAAwB,EAAE,wBAAwB,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,QAAQ,CAAC,iBAAiB,KAAK,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAC5D,MAAM,IAAI,aAAa,CAAC,wBAAwB,EAAE,qBAAqB,CAAC,CAAC;IAC3E,CAAC;IACD,IACE,CAAC,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC;QAChC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,SAAS,CAAC;QACvC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,WAAW,CAAC;QACzC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QACjD,CAAC,kBAAkB,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAChD,CAAC;QACD,MAAM,IAAI,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC;IAClE,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;IACvC,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { LoopConfig } from "coremind-config";
|
|
2
|
+
import type { CoreMindEvent } from "./events.js";
|
|
3
|
+
import { type LoopControllerSnapshot } from "./loop-controller.js";
|
|
4
|
+
import { type CompletedWorkflowStep, type StepOutput } from "./orchestrator.js";
|
|
5
|
+
export type LoopStepKind = "planning" | "execute" | "verify" | "repair";
|
|
6
|
+
export interface LoopStepRequest {
|
|
7
|
+
kind: LoopStepKind;
|
|
8
|
+
stepId: string;
|
|
9
|
+
agent: string;
|
|
10
|
+
input: string;
|
|
11
|
+
}
|
|
12
|
+
export interface LoopRunnerOptions {
|
|
13
|
+
runId: string;
|
|
14
|
+
configFingerprint: string;
|
|
15
|
+
initialPrompt?: string;
|
|
16
|
+
loop: LoopConfig;
|
|
17
|
+
executeStep: (request: LoopStepRequest) => Promise<string>;
|
|
18
|
+
emit: (event: CoreMindEvent) => void;
|
|
19
|
+
persistSnapshot: (snapshot: LoopControllerSnapshot) => Promise<void>;
|
|
20
|
+
restoredSnapshot?: LoopControllerSnapshot;
|
|
21
|
+
completedSteps?: ReadonlyMap<string, CompletedWorkflowStep>;
|
|
22
|
+
}
|
|
23
|
+
export interface LoopRunResult {
|
|
24
|
+
outputs: Map<string, StepOutput>;
|
|
25
|
+
transcript: string;
|
|
26
|
+
snapshot: LoopControllerSnapshot;
|
|
27
|
+
error?: unknown;
|
|
28
|
+
}
|
|
29
|
+
/** 执行显式、有限、可恢复的规划—执行—验证—修复循环。 */
|
|
30
|
+
export declare class LoopRunner {
|
|
31
|
+
private readonly options;
|
|
32
|
+
readonly outputs: Map<string, StepOutput>;
|
|
33
|
+
private readonly variables;
|
|
34
|
+
private readonly controller;
|
|
35
|
+
private readonly completedSteps;
|
|
36
|
+
constructor(options: LoopRunnerOptions);
|
|
37
|
+
getSnapshot(): LoopControllerSnapshot;
|
|
38
|
+
/** 由 Runtime 的总超时或外部取消入口推进到同一确定性终态。 */
|
|
39
|
+
interrupt(error: unknown): Promise<void>;
|
|
40
|
+
run(): Promise<LoopRunResult>;
|
|
41
|
+
private runPlanning;
|
|
42
|
+
private runExecution;
|
|
43
|
+
private runVerification;
|
|
44
|
+
private runRepair;
|
|
45
|
+
private runStep;
|
|
46
|
+
private saveOutput;
|
|
47
|
+
private interpolate;
|
|
48
|
+
private sendAndPersist;
|
|
49
|
+
private recordExecutionError;
|
|
50
|
+
private result;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=loop-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop-runner.d.ts","sourceRoot":"","sources":["../src/loop-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,qBAAqB,EAAiB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/F,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAExE,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3D,IAAI,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACrC,eAAe,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,gBAAgB,CAAC,EAAE,sBAAsB,CAAC;IAC1C,cAAc,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAID,iCAAiC;AACjC,qBAAa,UAAU;IAMT,OAAO,CAAC,QAAQ,CAAC,OAAO;IALpC,QAAQ,CAAC,OAAO,0BAAiC;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA6B;IACvD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAC5C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA6C;gBAE/C,OAAO,EAAE,iBAAiB;IAiCvD,WAAW,IAAI,sBAAsB;IAIrC,uCAAuC;IACjC,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC,GAAG,IAAI,OAAO,CAAC,aAAa,CAAC;YAmCrB,WAAW;YAeX,YAAY;YAaZ,eAAe;YAgBf,SAAS;YAeT,OAAO;IA2BrB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,WAAW;YAOL,cAAc;YAQd,oBAAoB;IAoBlC,OAAO,CAAC,MAAM;CASf"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { CoreMindError } from "./errors.js";
|
|
3
|
+
import { LoopController, } from "./loop-controller.js";
|
|
4
|
+
import { evalCondition } from "./orchestrator.js";
|
|
5
|
+
import { classifyRetry } from "./retry-policy.js";
|
|
6
|
+
const INTERPOLATE_RE = /\{\{\s*([\w.-]+)\s*\}\}/g;
|
|
7
|
+
/** 执行显式、有限、可恢复的规划—执行—验证—修复循环。 */
|
|
8
|
+
export class LoopRunner {
|
|
9
|
+
options;
|
|
10
|
+
outputs = new Map();
|
|
11
|
+
variables = new Map();
|
|
12
|
+
controller;
|
|
13
|
+
completedSteps;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.options = options;
|
|
16
|
+
const loop = options.loop;
|
|
17
|
+
const config = {
|
|
18
|
+
runId: options.runId,
|
|
19
|
+
configFingerprint: options.configFingerprint,
|
|
20
|
+
hasPlanning: loop.planning !== undefined,
|
|
21
|
+
maxIterations: loop.maxIterations ?? 3,
|
|
22
|
+
maxRepairs: loop.maxRepairs ?? 2,
|
|
23
|
+
maxRepeatedAction: loop.maxRepeatedAction ?? 2,
|
|
24
|
+
onFailure: loop.onFailure ?? "repair",
|
|
25
|
+
onExhausted: loop.onExhausted ?? "fail",
|
|
26
|
+
};
|
|
27
|
+
this.controller = options.restoredSnapshot
|
|
28
|
+
? LoopController.restore(config, options.restoredSnapshot)
|
|
29
|
+
: new LoopController(config);
|
|
30
|
+
this.completedSteps = options.completedSteps ?? new Map();
|
|
31
|
+
if (options.initialPrompt !== undefined)
|
|
32
|
+
this.variables.set("prompt", options.initialPrompt);
|
|
33
|
+
for (const completed of this.completedSteps.values()) {
|
|
34
|
+
if (completed.saveAs)
|
|
35
|
+
this.saveOutput(completed.saveAs, completed.output);
|
|
36
|
+
}
|
|
37
|
+
this.controller.subscribe((transition) => {
|
|
38
|
+
this.options.emit({
|
|
39
|
+
type: "loop_state",
|
|
40
|
+
from: transition.from,
|
|
41
|
+
to: transition.to,
|
|
42
|
+
trigger: transition.event,
|
|
43
|
+
iteration: transition.snapshot.iteration,
|
|
44
|
+
repairs: transition.snapshot.repairCount,
|
|
45
|
+
...(transition.snapshot.pauseReason ? { reason: transition.snapshot.pauseReason } : {}),
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
getSnapshot() {
|
|
50
|
+
return this.controller.getSnapshot();
|
|
51
|
+
}
|
|
52
|
+
/** 由 Runtime 的总超时或外部取消入口推进到同一确定性终态。 */
|
|
53
|
+
async interrupt(error) {
|
|
54
|
+
await this.recordExecutionError(error);
|
|
55
|
+
}
|
|
56
|
+
async run() {
|
|
57
|
+
try {
|
|
58
|
+
if (this.controller.phase === "paused")
|
|
59
|
+
await this.sendAndPersist({ type: "RESUME" });
|
|
60
|
+
if (this.controller.phase === "idle")
|
|
61
|
+
await this.sendAndPersist({ type: "START" });
|
|
62
|
+
while (!isTerminal(this.controller.phase)) {
|
|
63
|
+
switch (this.controller.phase) {
|
|
64
|
+
case "planning":
|
|
65
|
+
await this.runPlanning();
|
|
66
|
+
break;
|
|
67
|
+
case "executing":
|
|
68
|
+
await this.runExecution();
|
|
69
|
+
break;
|
|
70
|
+
case "verifying":
|
|
71
|
+
await this.runVerification();
|
|
72
|
+
break;
|
|
73
|
+
case "repairing":
|
|
74
|
+
await this.runRepair();
|
|
75
|
+
break;
|
|
76
|
+
case "paused":
|
|
77
|
+
return this.result(terminalError(this.controller.getSnapshot()));
|
|
78
|
+
default:
|
|
79
|
+
throw new CoreMindError("loop_state_invalid", `Loop 进入无法执行的状态:${this.controller.phase}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return this.result(terminalError(this.controller.getSnapshot()));
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
await this.recordExecutionError(error);
|
|
86
|
+
return this.result(errorForCaller(error, this.controller.getSnapshot()));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async runPlanning() {
|
|
90
|
+
const planning = this.options.loop.planning;
|
|
91
|
+
if (!planning)
|
|
92
|
+
throw new CoreMindError("loop_config_invalid", "Loop 规划阶段缺少 planning 配置");
|
|
93
|
+
const output = await this.runStep("planning", "loop-plan", planning.agent, this.interpolate(planning.input), "plan");
|
|
94
|
+
this.saveOutput("plan", output);
|
|
95
|
+
await this.sendAndPersist({ type: "PLANNED" });
|
|
96
|
+
}
|
|
97
|
+
async runExecution() {
|
|
98
|
+
const action = this.options.loop.execute;
|
|
99
|
+
const output = await this.runStep("execute", "loop-execute", action.agent, this.interpolate(action.input), "candidate");
|
|
100
|
+
this.saveOutput("candidate", output);
|
|
101
|
+
await this.sendAndPersist({ type: "EXECUTED", fingerprint: progressFingerprint(output.text) });
|
|
102
|
+
}
|
|
103
|
+
async runVerification() {
|
|
104
|
+
const verification = this.options.loop.verify;
|
|
105
|
+
const iteration = this.controller.getSnapshot().iteration;
|
|
106
|
+
this.variables.set("iteration", String(iteration));
|
|
107
|
+
const output = await this.runStep("verify", `loop-verify-${iteration}`, verification.agent, this.interpolate(verification.input), "verification");
|
|
108
|
+
this.saveOutput("verification", output);
|
|
109
|
+
const condition = this.interpolate(verification.passIf, output.text);
|
|
110
|
+
await this.sendAndPersist({ type: "VERIFIED", passed: evalCondition(condition) });
|
|
111
|
+
}
|
|
112
|
+
async runRepair() {
|
|
113
|
+
const repair = this.options.loop.repair;
|
|
114
|
+
const repairCount = this.controller.getSnapshot().repairCount;
|
|
115
|
+
this.variables.set("repairs", String(repairCount));
|
|
116
|
+
const output = await this.runStep("repair", `loop-repair-${repairCount}`, repair.agent, this.interpolate(repair.input), "candidate");
|
|
117
|
+
this.saveOutput("candidate", output);
|
|
118
|
+
await this.sendAndPersist({ type: "REPAIRED", fingerprint: progressFingerprint(output.text) });
|
|
119
|
+
}
|
|
120
|
+
async runStep(kind, stepId, agent, input, saveAs) {
|
|
121
|
+
const completed = this.completedSteps.get(stepId);
|
|
122
|
+
if (completed) {
|
|
123
|
+
this.options.emit({ type: "step_resumed", stepId });
|
|
124
|
+
if (completed.saveAs)
|
|
125
|
+
this.saveOutput(completed.saveAs, completed.output);
|
|
126
|
+
return completed.output;
|
|
127
|
+
}
|
|
128
|
+
this.options.emit({ type: "step_start", stepId, kind: `loop_${kind}` });
|
|
129
|
+
try {
|
|
130
|
+
const text = await this.options.executeStep({ kind, stepId, agent, input });
|
|
131
|
+
const output = { text, metadata: { agent, stepId } };
|
|
132
|
+
this.options.emit({ type: "step_output", stepId, agent, text, saveAs });
|
|
133
|
+
this.options.emit({ type: "step_end", stepId, ok: true });
|
|
134
|
+
return output;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
this.options.emit({ type: "step_end", stepId, ok: false });
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
saveOutput(name, output) {
|
|
142
|
+
this.outputs.set(name, output);
|
|
143
|
+
this.variables.set(name, output.text);
|
|
144
|
+
this.variables.set(`${name}.text`, output.text);
|
|
145
|
+
}
|
|
146
|
+
interpolate(template, verificationText) {
|
|
147
|
+
return template.replace(INTERPOLATE_RE, (match, name) => {
|
|
148
|
+
if (name === "text" && verificationText !== undefined)
|
|
149
|
+
return verificationText;
|
|
150
|
+
return this.variables.get(name) ?? match;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async sendAndPersist(event) {
|
|
154
|
+
const before = this.controller.phase;
|
|
155
|
+
this.controller.send(event);
|
|
156
|
+
if (this.controller.phase !== before) {
|
|
157
|
+
await this.options.persistSnapshot(this.controller.getSnapshot());
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async recordExecutionError(error) {
|
|
161
|
+
if (isTerminal(this.controller.phase))
|
|
162
|
+
return;
|
|
163
|
+
const code = error instanceof CoreMindError ? error.code : "loop_failed";
|
|
164
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
165
|
+
const category = classifyRetry(error).category;
|
|
166
|
+
if (category === "human") {
|
|
167
|
+
await this.sendAndPersist({ type: "PAUSE", reason: code });
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (code === "aborted") {
|
|
171
|
+
await this.sendAndPersist({ type: "ABORT" });
|
|
172
|
+
}
|
|
173
|
+
else if (code === "run_timeout" || code === "step_timeout") {
|
|
174
|
+
await this.sendAndPersist({ type: "TIMEOUT" });
|
|
175
|
+
}
|
|
176
|
+
else if (code === "budget_exceeded" || code === "retry_limit" || code === "step_limit") {
|
|
177
|
+
await this.sendAndPersist({ type: "BUDGET_EXCEEDED" });
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
await this.sendAndPersist({ type: "FAIL", code, message });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
result(error) {
|
|
184
|
+
const transcript = this.outputs.get("candidate")?.text ?? "";
|
|
185
|
+
return {
|
|
186
|
+
outputs: new Map(this.outputs),
|
|
187
|
+
transcript,
|
|
188
|
+
snapshot: this.controller.getSnapshot(),
|
|
189
|
+
...(error !== undefined ? { error } : {}),
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function isTerminal(phase) {
|
|
194
|
+
return ["succeeded", "failed", "aborted", "timeout", "budget_exceeded"].includes(phase);
|
|
195
|
+
}
|
|
196
|
+
function terminalError(snapshot) {
|
|
197
|
+
if (snapshot.phase === "succeeded")
|
|
198
|
+
return undefined;
|
|
199
|
+
if (snapshot.phase === "paused") {
|
|
200
|
+
return new CoreMindError("loop_paused", snapshot.pauseReason ?? "Loop 已暂停");
|
|
201
|
+
}
|
|
202
|
+
return new CoreMindError(snapshot.failureCode ?? "loop_failed", snapshot.failureMessage ?? `Loop 以 ${snapshot.phase} 结束`);
|
|
203
|
+
}
|
|
204
|
+
function errorForCaller(error, snapshot) {
|
|
205
|
+
if (snapshot.phase === "paused")
|
|
206
|
+
return terminalError(snapshot);
|
|
207
|
+
return error;
|
|
208
|
+
}
|
|
209
|
+
function progressFingerprint(text) {
|
|
210
|
+
const normalized = text.replace(/\r\n/g, "\n").trim();
|
|
211
|
+
return createHash("sha256").update(normalized).digest("hex");
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=loop-runner.js.map
|