@clearideas/agent-runtime-step-loop 0.9.0 → 1.0.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/NOTICE +2 -2
- package/dist/index.js +105 -6
- package/package.json +4 -4
package/NOTICE
CHANGED
|
@@ -3,6 +3,6 @@ Copyright 2026 Clear Ideas Incorporated
|
|
|
3
3
|
|
|
4
4
|
Clear Ideas is a trademark of Clear Ideas Incorporated.
|
|
5
5
|
|
|
6
|
-
The documentation site includes @clearideas/analytics 1.
|
|
6
|
+
The documentation site includes @clearideas/consent-analytics 0.1.0-rc.1, distributed
|
|
7
7
|
under the MIT License. Its license text is available at
|
|
8
|
-
docs/public/assets/analytics/LICENSE.clearideas-analytics.txt.
|
|
8
|
+
docs/public/assets/analytics/LICENSE.clearideas-consent-analytics.txt.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyStatePatch, setVariableAtPath, withoutMessagesView, } from "@clearideas/agent-runtime-core";
|
|
1
|
+
import { applyStatePatch, childExecutionKey, createLimitSuspension, setVariableAtPath, withoutMessagesView, } from "@clearideas/agent-runtime-core";
|
|
2
2
|
const clone = (value) => structuredClone(value);
|
|
3
3
|
const asObject = (value) => value != null && typeof value === "object" && !Array.isArray(value)
|
|
4
4
|
? value
|
|
@@ -56,11 +56,26 @@ const parseItems = (source, delimiter, variables, maxIterations) => {
|
|
|
56
56
|
return { items: [], structured: false };
|
|
57
57
|
};
|
|
58
58
|
const serializeOutput = (value) => typeof value === "string" ? value : JSON.stringify(value);
|
|
59
|
+
const isCount = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
60
|
+
const isChildFrame = (value) => {
|
|
61
|
+
const frame = asObject(value);
|
|
62
|
+
return (frame !== undefined &&
|
|
63
|
+
asObject(frame.state) !== undefined &&
|
|
64
|
+
(frame.continuation === null ||
|
|
65
|
+
asObject(frame.continuation) !== undefined) &&
|
|
66
|
+
isCount(frame.transcriptCount) &&
|
|
67
|
+
isCount(frame.artifactCount));
|
|
68
|
+
};
|
|
59
69
|
const isLoopContinuation = (value, stepId) => value?.type === "loop" &&
|
|
60
70
|
value.stepId === stepId &&
|
|
61
71
|
typeof value.iterationIndex === "number" &&
|
|
62
72
|
typeof value.childIndex === "number" &&
|
|
63
|
-
Array.isArray(value.outputs)
|
|
73
|
+
Array.isArray(value.outputs) &&
|
|
74
|
+
(value.child === undefined || isChildFrame(value.child));
|
|
75
|
+
/** Split a restored list into the loop's own items and its child's tail. */
|
|
76
|
+
const splitTail = (items, count) => count > 0 && count <= items.length
|
|
77
|
+
? [items.slice(0, items.length - count), items.slice(items.length - count)]
|
|
78
|
+
: [items, []];
|
|
64
79
|
/** An iteration's variables for `loop.previous`, without runtime-provided views. */
|
|
65
80
|
const snapshotIterationVariables = (manifest, state) => {
|
|
66
81
|
const result = withoutMessagesView(manifest, clone(state));
|
|
@@ -113,6 +128,14 @@ export class LoopStepExecutor {
|
|
|
113
128
|
const restored = isLoopContinuation(context.resume?.continuation, context.step.id)
|
|
114
129
|
? context.resume.continuation
|
|
115
130
|
: undefined;
|
|
131
|
+
if (context.resume?.continuation && !restored) {
|
|
132
|
+
// Checkpoints written before loops framed their children hold a child's
|
|
133
|
+
// continuation in place of the loop's; the loop cannot tell where it was.
|
|
134
|
+
await context.emit("diagnostic", {
|
|
135
|
+
code: "LOOP_RESUME_STATE_UNRECOGNIZED",
|
|
136
|
+
message: "The loop's saved position was not recognized; it restarts from its first iteration.",
|
|
137
|
+
});
|
|
138
|
+
}
|
|
116
139
|
let state = clone(context.variables);
|
|
117
140
|
const outputs = clone(restored?.outputs ?? []);
|
|
118
141
|
let previous = clone(restored?.previous ?? null);
|
|
@@ -121,13 +144,30 @@ export class LoopStepExecutor {
|
|
|
121
144
|
let startChild = restored?.childIndex ?? 0;
|
|
122
145
|
let goalMet = restored?.goalMet ?? false;
|
|
123
146
|
let goalMetAtIteration = restored?.goalMetAtIteration ?? null;
|
|
124
|
-
|
|
125
|
-
|
|
147
|
+
// A mid-step child's transcript and artifacts are the tail of what the
|
|
148
|
+
// loop restored; they go back to the child, not into the loop's lists.
|
|
149
|
+
const [transcript, childTranscript] = splitTail(clone(restored ? (context.resume?.transcript ?? []) : []), restored?.child?.transcriptCount ?? 0);
|
|
150
|
+
const [artifacts, childArtifacts] = splitTail(clone(restored ? (context.resume?.artifacts ?? []) : []), restored?.child?.artifactCount ?? 0);
|
|
151
|
+
let resumingChild = restored?.child
|
|
152
|
+
? clone(restored.child)
|
|
153
|
+
: undefined;
|
|
126
154
|
/** A child asked to end the run (for example a rejected approval with onReject: complete). */
|
|
127
155
|
let endRun = false;
|
|
128
156
|
if (!restored?.finished) {
|
|
129
157
|
for (let iteration = startIteration; iteration < iterationLimit; iteration += 1) {
|
|
130
|
-
|
|
158
|
+
// A runaway guard: the checkpoint after the previous iteration is the
|
|
159
|
+
// position a raised limit resumes from.
|
|
160
|
+
const iterationCeiling = context.limits?.maxLoopIterations;
|
|
161
|
+
if (iterationCeiling !== undefined && iteration >= iterationCeiling) {
|
|
162
|
+
throw createLimitSuspension({
|
|
163
|
+
limit: "maxLoopIterations",
|
|
164
|
+
used: iteration,
|
|
165
|
+
value: iterationCeiling,
|
|
166
|
+
stepId: context.step.id,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const resumingIteration = iteration === startIteration &&
|
|
170
|
+
(startChild > 0 || resumingChild !== undefined);
|
|
131
171
|
let local = resumingIteration ? clone(state) : clone(state);
|
|
132
172
|
if (!resumingIteration) {
|
|
133
173
|
const itemVariable = config.itemVariable ?? "item";
|
|
@@ -182,7 +222,61 @@ export class LoopStepExecutor {
|
|
|
182
222
|
if (!child)
|
|
183
223
|
continue;
|
|
184
224
|
const childPath = `${stepPath}/${child.id}`;
|
|
185
|
-
const
|
|
225
|
+
const resumed = resumingIteration && childIndex === childStart
|
|
226
|
+
? resumingChild
|
|
227
|
+
: undefined;
|
|
228
|
+
resumingChild = undefined;
|
|
229
|
+
const childStartState = clone(local);
|
|
230
|
+
const frame = {
|
|
231
|
+
key: String(iteration),
|
|
232
|
+
checkpoint: (nested) => ({
|
|
233
|
+
// The loop resumes from the variables it had when the child began.
|
|
234
|
+
state: childStartState,
|
|
235
|
+
cursor: {
|
|
236
|
+
stepId: child.id,
|
|
237
|
+
stepPath: childPath,
|
|
238
|
+
loopIteration: iteration + 1,
|
|
239
|
+
childIndex,
|
|
240
|
+
...(nested.cursor ?? {}),
|
|
241
|
+
},
|
|
242
|
+
continuation: {
|
|
243
|
+
...continuation({
|
|
244
|
+
stepId: context.step.id,
|
|
245
|
+
iterationIndex: iteration,
|
|
246
|
+
childIndex,
|
|
247
|
+
outputs,
|
|
248
|
+
previous,
|
|
249
|
+
lastOutput,
|
|
250
|
+
finished: false,
|
|
251
|
+
goalMet,
|
|
252
|
+
goalMetAtIteration,
|
|
253
|
+
}),
|
|
254
|
+
child: {
|
|
255
|
+
state: clone(nested.state),
|
|
256
|
+
continuation: nested.continuation
|
|
257
|
+
? clone(nested.continuation)
|
|
258
|
+
: null,
|
|
259
|
+
transcriptCount: nested.transcript?.length ?? 0,
|
|
260
|
+
artifactCount: nested.artifacts?.length ?? 0,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
transcript: [...transcript, ...(nested.transcript ?? [])],
|
|
264
|
+
artifacts: [...artifacts, ...(nested.artifacts ?? [])],
|
|
265
|
+
...(nested.boundary ? { boundary: nested.boundary } : {}),
|
|
266
|
+
}),
|
|
267
|
+
...(resumed
|
|
268
|
+
? {
|
|
269
|
+
resume: {
|
|
270
|
+
...(resumed.continuation
|
|
271
|
+
? { continuation: resumed.continuation }
|
|
272
|
+
: {}),
|
|
273
|
+
transcript: childTranscript,
|
|
274
|
+
artifacts: childArtifacts,
|
|
275
|
+
},
|
|
276
|
+
}
|
|
277
|
+
: {}),
|
|
278
|
+
};
|
|
279
|
+
const result = await executeChild(child, resumed ? clone(resumed.state) : local, childPath, frame);
|
|
186
280
|
local = applyStatePatch(local, result.statePatch);
|
|
187
281
|
transcript.push(...(result.transcript ?? []));
|
|
188
282
|
artifacts.push(...(result.artifacts ?? []));
|
|
@@ -195,6 +289,11 @@ export class LoopStepExecutor {
|
|
|
195
289
|
const nextChildIndex = childIndex + 1;
|
|
196
290
|
const nextChild = context.step.steps[nextChildIndex];
|
|
197
291
|
await checkpoint({
|
|
292
|
+
// The child completed: a step commit point and a restart point.
|
|
293
|
+
boundary: {
|
|
294
|
+
stepPath: childPath,
|
|
295
|
+
executionKey: childExecutionKey(context.executionKey ?? stepPath, child.id, { key: String(iteration) }),
|
|
296
|
+
},
|
|
198
297
|
state: local,
|
|
199
298
|
cursor: {
|
|
200
299
|
stepId: nextChild?.id ?? context.step.id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clearideas/agent-runtime-step-loop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Sequential condition and goal loop executor for Clear Ideas Agent Runtime.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Clear Ideas Incorporated",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"postpack": "node ../../scripts/cleanup-package-license.mjs"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@clearideas/agent-runtime-contracts": "0.
|
|
40
|
-
"@clearideas/agent-runtime-core": "0.
|
|
39
|
+
"@clearideas/agent-runtime-contracts": "1.0.0",
|
|
40
|
+
"@clearideas/agent-runtime-core": "1.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@clearideas/agent-runtime-condition-jexl": "0.
|
|
43
|
+
"@clearideas/agent-runtime-condition-jexl": "1.0.0",
|
|
44
44
|
"typescript": "^7.0.2",
|
|
45
45
|
"vitest": "^5.1.0"
|
|
46
46
|
},
|