ai-engineering-loop 1.8.1 → 1.9.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/README.md +3 -1
- package/bin/ai-engineering-loop.js +71 -1
- package/lib/loop-groups.js +144 -0
- package/lib/node-registry.js +8 -0
- package/lib/recipe-graph.js +21 -2
- package/lib/recipe.js +5 -1
- package/lib/run-checkout.js +175 -0
- package/lib/run-history.js +1 -1
- package/lib/run-interactions.js +184 -0
- package/lib/run-state.js +25 -10
- package/lib/studio-runtime.js +9 -1
- package/lib/studio-server.js +97 -1
- package/lib/workflow-runtime.js +315 -5
- package/package.json +1 -1
- package/schemas/compiled-plan.schema.json +5 -0
- package/schemas/loop-group.schema.json +41 -0
- package/schemas/node-definition.schema.json +1 -0
- package/schemas/recipe.schema.json +5 -0
- package/schemas/workflow-event.schema.json +10 -1
- package/schemas/workflow-state.schema.json +16 -0
- package/studio/app.js +351 -30
- package/studio/index.html +46 -16
- package/studio/styles.css +10 -7
package/lib/workflow-runtime.js
CHANGED
|
@@ -88,7 +88,11 @@ function refreshNodes(plan, state, run) {
|
|
|
88
88
|
const dependencies = (node.dependsOn || []).map((id) => state.nodes[id]);
|
|
89
89
|
let nextStatus = current.status;
|
|
90
90
|
let reason = null;
|
|
91
|
-
|
|
91
|
+
const exitGuard = (plan.loopGroups || []).find((group) => group.exitTargetId === node.id);
|
|
92
|
+
if (exitGuard && state.loopGroups?.[exitGuard.id]?.status !== 'EXITED') {
|
|
93
|
+
nextStatus = NODE_STATES.PENDING;
|
|
94
|
+
reason = `waiting for ${exitGuard.id} to exit`;
|
|
95
|
+
} else if (dependencies.some((dependency) => dependency.status === NODE_STATES.FAILED)) {
|
|
92
96
|
nextStatus = NODE_STATES.BLOCKED;
|
|
93
97
|
reason = 'dependency failed';
|
|
94
98
|
} else if (dependencies.every((dependency) => SUCCESS_STATES.has(dependency.status))) {
|
|
@@ -128,18 +132,35 @@ function createWorkflowBundle(plan, runId, { now = new Date(), run } = {}) {
|
|
|
128
132
|
iteration: 1,
|
|
129
133
|
task: ''
|
|
130
134
|
};
|
|
135
|
+
const loopMembership = new Map();
|
|
136
|
+
for (const group of plan.loopGroups || []) {
|
|
137
|
+
for (const nodeId of group.nodeIds) loopMembership.set(nodeId, group.id);
|
|
138
|
+
}
|
|
131
139
|
const state = {
|
|
132
140
|
schemaVersion: 1,
|
|
133
141
|
runId,
|
|
134
142
|
graphHash: plan.graphHash,
|
|
135
143
|
sequence: 0,
|
|
136
144
|
eventHash: null,
|
|
145
|
+
loopGroups: Object.fromEntries((plan.loopGroups || []).map((group) => [
|
|
146
|
+
group.id,
|
|
147
|
+
{
|
|
148
|
+
status: 'PENDING',
|
|
149
|
+
iteration: 1,
|
|
150
|
+
maxIterations: group.maxIterations,
|
|
151
|
+
lastOutcome: null,
|
|
152
|
+
updatedAt: now.toISOString()
|
|
153
|
+
}
|
|
154
|
+
])),
|
|
137
155
|
nodes: Object.fromEntries(plan.nodes.map((node) => [
|
|
138
156
|
node.id,
|
|
139
157
|
{
|
|
140
158
|
status: NODE_STATES.PENDING,
|
|
141
159
|
attempts: 0,
|
|
142
160
|
reason: null,
|
|
161
|
+
...(loopMembership.has(node.id)
|
|
162
|
+
? { loopGroupId: loopMembership.get(node.id), loopIteration: 1 }
|
|
163
|
+
: {}),
|
|
143
164
|
updatedAt: now.toISOString()
|
|
144
165
|
}
|
|
145
166
|
]))
|
|
@@ -153,7 +174,8 @@ function createWorkflowBundle(plan, runId, { now = new Date(), run } = {}) {
|
|
|
153
174
|
type: 'WORKFLOW_CREATED',
|
|
154
175
|
runId,
|
|
155
176
|
graphHash: plan.graphHash,
|
|
156
|
-
initialNodes: state.nodes
|
|
177
|
+
initialNodes: state.nodes,
|
|
178
|
+
initialLoopGroups: state.loopGroups
|
|
157
179
|
});
|
|
158
180
|
state.sequence = event.sequence;
|
|
159
181
|
state.eventHash = event.hash;
|
|
@@ -215,6 +237,7 @@ function verifyPlan(plan, expectedHash) {
|
|
|
215
237
|
mode: plan.mode,
|
|
216
238
|
nodes: plan.nodes
|
|
217
239
|
};
|
|
240
|
+
if (Object.hasOwn(plan, 'loopGroups')) material.loopGroups = plan.loopGroups;
|
|
218
241
|
if (plan.graphHash !== expectedHash || sha256(material) !== plan.graphHash) {
|
|
219
242
|
throw runtimeError('Compiled workflow plan failed integrity validation', 'WORKFLOW_PLAN_TAMPERED');
|
|
220
243
|
}
|
|
@@ -231,10 +254,12 @@ function recoverState(state, events) {
|
|
|
231
254
|
graphHash: state.graphHash,
|
|
232
255
|
sequence: created.sequence,
|
|
233
256
|
eventHash: created.hash,
|
|
234
|
-
nodes: created.initialNodes
|
|
257
|
+
nodes: created.initialNodes,
|
|
258
|
+
loopGroups: created.initialLoopGroups || {}
|
|
235
259
|
};
|
|
236
260
|
for (const event of events.slice(1)) {
|
|
237
261
|
for (const change of event.changes || []) recovered.nodes[change.nodeId] = change.node;
|
|
262
|
+
for (const change of event.loopChanges || []) recovered.loopGroups[change.groupId] = change.loop;
|
|
238
263
|
recovered.sequence = event.sequence;
|
|
239
264
|
recovered.eventHash = event.hash;
|
|
240
265
|
}
|
|
@@ -273,8 +298,17 @@ function appendEvent(filePath, event) {
|
|
|
273
298
|
}
|
|
274
299
|
}
|
|
275
300
|
|
|
276
|
-
function commitChanges(
|
|
277
|
-
|
|
301
|
+
function commitChanges(
|
|
302
|
+
rootDir,
|
|
303
|
+
workflow,
|
|
304
|
+
type,
|
|
305
|
+
changes,
|
|
306
|
+
metadata = {},
|
|
307
|
+
now = new Date(),
|
|
308
|
+
allowEmpty = false,
|
|
309
|
+
loopChanges = []
|
|
310
|
+
) {
|
|
311
|
+
if (changes.length === 0 && loopChanges.length === 0 && !allowEmpty) return workflow;
|
|
278
312
|
const event = eventWithHash({
|
|
279
313
|
schemaVersion: 1,
|
|
280
314
|
sequence: workflow.state.sequence + 1,
|
|
@@ -284,6 +318,7 @@ function commitChanges(rootDir, workflow, type, changes, metadata = {}, now = ne
|
|
|
284
318
|
runId: workflow.run.runId,
|
|
285
319
|
graphHash: workflow.plan.graphHash,
|
|
286
320
|
changes,
|
|
321
|
+
...(loopChanges.length ? { loopChanges } : {}),
|
|
287
322
|
...metadata
|
|
288
323
|
});
|
|
289
324
|
const paths = workflowPaths(rootDir, workflow.run.runId);
|
|
@@ -344,6 +379,63 @@ function nodeChanges(workflow, nodeId, status, metadata = {}, now = new Date())
|
|
|
344
379
|
return [{ nodeId, from: current.status, node: replacement }];
|
|
345
380
|
}
|
|
346
381
|
|
|
382
|
+
function loopChange(workflow, groupId, metadata, now = new Date()) {
|
|
383
|
+
const current = workflow.state.loopGroups[groupId];
|
|
384
|
+
if (!current) throw runtimeError(`Unknown Loop Group: ${groupId}`, 'UNKNOWN_LOOP_GROUP');
|
|
385
|
+
const replacement = { ...current, ...metadata, updatedAt: now.toISOString() };
|
|
386
|
+
workflow.state.loopGroups[groupId] = replacement;
|
|
387
|
+
return { groupId, from: current.status, loop: replacement };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function loopForDecision(plan, nodeId) {
|
|
391
|
+
return (plan.loopGroups || []).find((group) => group.decisionNodeId === nodeId);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function descendantsWithinLoop(plan, group) {
|
|
395
|
+
const members = new Set(group.nodeIds);
|
|
396
|
+
const result = new Set([group.repeatTargetId]);
|
|
397
|
+
let changed = true;
|
|
398
|
+
while (changed) {
|
|
399
|
+
changed = false;
|
|
400
|
+
for (const node of plan.nodes) {
|
|
401
|
+
if (
|
|
402
|
+
members.has(node.id) &&
|
|
403
|
+
!result.has(node.id) &&
|
|
404
|
+
(node.dependsOn || []).some((dependency) => result.has(dependency))
|
|
405
|
+
) {
|
|
406
|
+
result.add(node.id);
|
|
407
|
+
changed = true;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function resetLoopNodes(workflow, group, iteration, now) {
|
|
415
|
+
const changes = [];
|
|
416
|
+
for (const nodeId of descendantsWithinLoop(workflow.plan, group)) {
|
|
417
|
+
const current = workflow.state.nodes[nodeId];
|
|
418
|
+
const replacement = {
|
|
419
|
+
status: NODE_STATES.PENDING,
|
|
420
|
+
attempts: current.attempts,
|
|
421
|
+
reason: 'reset for next Loop iteration',
|
|
422
|
+
activity: null,
|
|
423
|
+
loopGroupId: group.id,
|
|
424
|
+
loopIteration: iteration,
|
|
425
|
+
updatedAt: now.toISOString()
|
|
426
|
+
};
|
|
427
|
+
workflow.state.nodes[nodeId] = replacement;
|
|
428
|
+
changes.push({ nodeId, from: current.status, node: replacement });
|
|
429
|
+
}
|
|
430
|
+
return changes;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function assertDecisionActor(actor) {
|
|
434
|
+
if (!/^[A-Za-z0-9@._-]{1,64}$/.test(String(actor || ''))) {
|
|
435
|
+
throw runtimeError('actor must be a short account identifier', 'INVALID_LOOP_ACTOR');
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
347
439
|
function assertReady(workflow, nodeId) {
|
|
348
440
|
const node = workflow.plan.nodes.find((candidate) => candidate.id === nodeId);
|
|
349
441
|
if (!node) throw runtimeError(`Unknown workflow node: ${nodeId}`, 'UNKNOWN_WORKFLOW_NODE');
|
|
@@ -521,6 +613,9 @@ function completeWorkflowNode(rootDir, nodeId, { runId, artifact, now = new Date
|
|
|
521
613
|
if (node.type === 'command') {
|
|
522
614
|
throw runtimeError('Command nodes are disabled in the controlled runtime', 'COMMAND_EXECUTION_DISABLED');
|
|
523
615
|
}
|
|
616
|
+
if (node.type === 'decision') {
|
|
617
|
+
throw runtimeError(`Node ${nodeId} requires an explicit decision outcome`, 'WRONG_NODE_EXECUTOR');
|
|
618
|
+
}
|
|
524
619
|
if (node.type === 'approval' || LEGACY_NODE_TYPES.has(node.type)) {
|
|
525
620
|
throw runtimeError(`Node ${nodeId} must use its dedicated approval or gate command`, 'WRONG_NODE_EXECUTOR');
|
|
526
621
|
}
|
|
@@ -541,6 +636,219 @@ function completeWorkflowNode(rootDir, nodeId, { runId, artifact, now = new Date
|
|
|
541
636
|
});
|
|
542
637
|
}
|
|
543
638
|
|
|
639
|
+
function resolveWorkflowDecision(
|
|
640
|
+
rootDir,
|
|
641
|
+
nodeId,
|
|
642
|
+
{ runId, outcome, actor = 'agent', now = new Date() } = {}
|
|
643
|
+
) {
|
|
644
|
+
const resolved = resolveRunId(rootDir, runId);
|
|
645
|
+
return withWorkflowLock(rootDir, resolved, () => {
|
|
646
|
+
assertDecisionActor(actor);
|
|
647
|
+
const normalizedOutcome = String(outcome || '').trim();
|
|
648
|
+
if (!normalizedOutcome || normalizedOutcome.length > 80) {
|
|
649
|
+
throw runtimeError('A bounded decision outcome is required', 'INVALID_DECISION_OUTCOME');
|
|
650
|
+
}
|
|
651
|
+
const workflow = loadWorkflow(rootDir, resolved);
|
|
652
|
+
const node = assertReady(workflow, nodeId);
|
|
653
|
+
if (node.type !== 'decision' && node.type !== 'trigger') {
|
|
654
|
+
throw runtimeError(`Node ${nodeId} is not a decision node`, 'WRONG_NODE_EXECUTOR');
|
|
655
|
+
}
|
|
656
|
+
const group = loopForDecision(workflow.plan, nodeId);
|
|
657
|
+
if (group && ![group.repeatOutcome, group.exitOutcome].includes(normalizedOutcome)) {
|
|
658
|
+
throw runtimeError(
|
|
659
|
+
`Outcome must be ${group.repeatOutcome} or ${group.exitOutcome}`,
|
|
660
|
+
'INVALID_LOOP_OUTCOME'
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
const currentLoop = group ? workflow.state.loopGroups[group.id] : null;
|
|
665
|
+
const metadata = {
|
|
666
|
+
nodeId,
|
|
667
|
+
outcome: redactSecrets(normalizedOutcome),
|
|
668
|
+
actor,
|
|
669
|
+
...(group ? { groupId: group.id, iteration: currentLoop.iteration } : {})
|
|
670
|
+
};
|
|
671
|
+
if (!group) {
|
|
672
|
+
let changes = nodeChanges(workflow, nodeId, NODE_STATES.PASSED, {
|
|
673
|
+
attempts: workflow.state.nodes[nodeId].attempts + 1,
|
|
674
|
+
reason: null,
|
|
675
|
+
activity: null,
|
|
676
|
+
outcome: normalizedOutcome
|
|
677
|
+
}, now);
|
|
678
|
+
changes = changes.concat(refreshNodes(workflow.plan, workflow.state, workflow.run));
|
|
679
|
+
return commitChanges(rootDir, workflow, 'DECISION_RESOLVED', changes, metadata, now);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (normalizedOutcome === group.exitOutcome) {
|
|
683
|
+
let changes = nodeChanges(workflow, nodeId, NODE_STATES.PASSED, {
|
|
684
|
+
attempts: workflow.state.nodes[nodeId].attempts + 1,
|
|
685
|
+
reason: null,
|
|
686
|
+
activity: null,
|
|
687
|
+
outcome: normalizedOutcome,
|
|
688
|
+
loopGroupId: group.id,
|
|
689
|
+
loopIteration: currentLoop.iteration
|
|
690
|
+
}, now);
|
|
691
|
+
const loopChanges = [loopChange(workflow, group.id, {
|
|
692
|
+
status: 'EXITED',
|
|
693
|
+
lastOutcome: normalizedOutcome
|
|
694
|
+
}, now)];
|
|
695
|
+
changes = changes.concat(refreshNodes(workflow.plan, workflow.state, workflow.run));
|
|
696
|
+
return commitChanges(rootDir, workflow, 'LOOP_EXITED', changes, metadata, now, false, loopChanges);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if (currentLoop.iteration >= currentLoop.maxIterations) {
|
|
700
|
+
const changes = nodeChanges(workflow, nodeId, NODE_STATES.BLOCKED, {
|
|
701
|
+
attempts: workflow.state.nodes[nodeId].attempts + 1,
|
|
702
|
+
reason: 'Loop iteration limit reached',
|
|
703
|
+
activity: null,
|
|
704
|
+
outcome: normalizedOutcome,
|
|
705
|
+
loopGroupId: group.id,
|
|
706
|
+
loopIteration: currentLoop.iteration
|
|
707
|
+
}, now);
|
|
708
|
+
const loopChanges = [loopChange(workflow, group.id, {
|
|
709
|
+
status: 'BLOCKED',
|
|
710
|
+
lastOutcome: normalizedOutcome
|
|
711
|
+
}, now)];
|
|
712
|
+
return commitChanges(
|
|
713
|
+
rootDir,
|
|
714
|
+
workflow,
|
|
715
|
+
'LOOP_LIMIT_REACHED',
|
|
716
|
+
changes,
|
|
717
|
+
metadata,
|
|
718
|
+
now,
|
|
719
|
+
false,
|
|
720
|
+
loopChanges
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
const nextIteration = currentLoop.iteration + 1;
|
|
725
|
+
let changes = resetLoopNodes(workflow, group, nextIteration, now);
|
|
726
|
+
const loopChanges = [loopChange(workflow, group.id, {
|
|
727
|
+
status: 'RUNNING',
|
|
728
|
+
iteration: nextIteration,
|
|
729
|
+
lastOutcome: normalizedOutcome
|
|
730
|
+
}, now)];
|
|
731
|
+
changes = changes.concat(refreshNodes(workflow.plan, workflow.state, workflow.run));
|
|
732
|
+
return commitChanges(
|
|
733
|
+
rootDir,
|
|
734
|
+
workflow,
|
|
735
|
+
'LOOP_REPEATED',
|
|
736
|
+
changes,
|
|
737
|
+
{ ...metadata, nextIteration },
|
|
738
|
+
now,
|
|
739
|
+
false,
|
|
740
|
+
loopChanges
|
|
741
|
+
);
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
function resolveLoopLimit(
|
|
746
|
+
rootDir,
|
|
747
|
+
groupId,
|
|
748
|
+
{ runId, action, expectedIteration, actor, reason, now = new Date() } = {}
|
|
749
|
+
) {
|
|
750
|
+
const resolved = resolveRunId(rootDir, runId);
|
|
751
|
+
return withWorkflowLock(rootDir, resolved, () => {
|
|
752
|
+
assertDecisionActor(actor);
|
|
753
|
+
const cleanReason = String(reason || '').trim();
|
|
754
|
+
if (!cleanReason || cleanReason.length > 500) {
|
|
755
|
+
throw runtimeError('A reason between 1 and 500 characters is required', 'INVALID_LOOP_REASON');
|
|
756
|
+
}
|
|
757
|
+
if (!['EXTRA_ITERATION', 'EXIT', 'STOP'].includes(action)) {
|
|
758
|
+
throw runtimeError('Loop action must be EXTRA_ITERATION, EXIT, or STOP', 'INVALID_LOOP_ACTION');
|
|
759
|
+
}
|
|
760
|
+
const workflow = loadWorkflow(rootDir, resolved);
|
|
761
|
+
const group = (workflow.plan.loopGroups || []).find((candidate) => candidate.id === groupId);
|
|
762
|
+
if (!group) throw runtimeError(`Unknown Loop Group: ${groupId}`, 'UNKNOWN_LOOP_GROUP');
|
|
763
|
+
const currentLoop = workflow.state.loopGroups[groupId];
|
|
764
|
+
if (currentLoop.status !== 'BLOCKED') {
|
|
765
|
+
throw runtimeError(`Loop Group ${groupId} is not blocked`, 'LOOP_NOT_BLOCKED');
|
|
766
|
+
}
|
|
767
|
+
if (currentLoop.iteration !== expectedIteration) {
|
|
768
|
+
throw runtimeError('Loop Group iteration changed; refresh before approving', 'STALE_LOOP_APPROVAL');
|
|
769
|
+
}
|
|
770
|
+
const metadata = {
|
|
771
|
+
groupId,
|
|
772
|
+
action,
|
|
773
|
+
iteration: currentLoop.iteration,
|
|
774
|
+
actor,
|
|
775
|
+
reason: redactSecrets(cleanReason)
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
if (action === 'EXTRA_ITERATION') {
|
|
779
|
+
const nextIteration = currentLoop.iteration + 1;
|
|
780
|
+
let changes = resetLoopNodes(workflow, group, nextIteration, now);
|
|
781
|
+
const loopChanges = [loopChange(workflow, groupId, {
|
|
782
|
+
status: 'RUNNING',
|
|
783
|
+
iteration: nextIteration
|
|
784
|
+
}, now)];
|
|
785
|
+
changes = changes.concat(refreshNodes(workflow.plan, workflow.state, workflow.run));
|
|
786
|
+
return commitChanges(
|
|
787
|
+
rootDir,
|
|
788
|
+
workflow,
|
|
789
|
+
'LOOP_LIMIT_OVERRIDE',
|
|
790
|
+
changes,
|
|
791
|
+
{ ...metadata, nextIteration },
|
|
792
|
+
now,
|
|
793
|
+
false,
|
|
794
|
+
loopChanges
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if (action === 'EXIT') {
|
|
799
|
+
let changes = nodeChanges(workflow, group.decisionNodeId, NODE_STATES.PASSED, {
|
|
800
|
+
reason: null,
|
|
801
|
+
activity: null,
|
|
802
|
+
approvedBy: actor
|
|
803
|
+
}, now);
|
|
804
|
+
const loopChanges = [loopChange(workflow, groupId, { status: 'EXITED' }, now)];
|
|
805
|
+
changes = changes.concat(refreshNodes(workflow.plan, workflow.state, workflow.run));
|
|
806
|
+
return commitChanges(
|
|
807
|
+
rootDir,
|
|
808
|
+
workflow,
|
|
809
|
+
'LOOP_LIMIT_EXITED',
|
|
810
|
+
changes,
|
|
811
|
+
metadata,
|
|
812
|
+
now,
|
|
813
|
+
false,
|
|
814
|
+
loopChanges
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const changes = [];
|
|
819
|
+
workflow.run = transitionRun(rootDir, resolved, RUN_STATES.CANCELLED, {
|
|
820
|
+
gate: 'loop-limit-stop',
|
|
821
|
+
reason: redactSecrets(cleanReason),
|
|
822
|
+
historyMetadata: {
|
|
823
|
+
actor,
|
|
824
|
+
loopGroupId: groupId,
|
|
825
|
+
loopIteration: currentLoop.iteration
|
|
826
|
+
},
|
|
827
|
+
now
|
|
828
|
+
});
|
|
829
|
+
for (const node of workflow.plan.nodes) {
|
|
830
|
+
const current = workflow.state.nodes[node.id];
|
|
831
|
+
if (!SUCCESS_STATES.has(current.status)) {
|
|
832
|
+
changes.push(...nodeChanges(workflow, node.id, NODE_STATES.BLOCKED, {
|
|
833
|
+
reason: 'Run stopped after Loop limit',
|
|
834
|
+
activity: null
|
|
835
|
+
}, now));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
const loopChanges = [loopChange(workflow, groupId, { status: 'STOPPED' }, now)];
|
|
839
|
+
return commitChanges(
|
|
840
|
+
rootDir,
|
|
841
|
+
workflow,
|
|
842
|
+
'LOOP_RUN_STOPPED',
|
|
843
|
+
changes,
|
|
844
|
+
metadata,
|
|
845
|
+
now,
|
|
846
|
+
false,
|
|
847
|
+
loopChanges
|
|
848
|
+
);
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
|
|
544
852
|
function startWorkflowNode(rootDir, nodeId, { runId, now = new Date() } = {}) {
|
|
545
853
|
const resolved = resolveRunId(rootDir, runId);
|
|
546
854
|
return withWorkflowLock(rootDir, resolved, () => {
|
|
@@ -781,6 +1089,8 @@ module.exports = {
|
|
|
781
1089
|
startWorkflowExecution,
|
|
782
1090
|
startWorkflowNode,
|
|
783
1091
|
completeWorkflowNode,
|
|
1092
|
+
resolveWorkflowDecision,
|
|
1093
|
+
resolveLoopLimit,
|
|
784
1094
|
failWorkflowNode,
|
|
785
1095
|
retryWorkflowNode,
|
|
786
1096
|
recordWorkflowActivity,
|
package/package.json
CHANGED
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
},
|
|
14
14
|
"mode": { "enum": ["REPORT_ONLY", "ASSISTED", "UNATTENDED"] },
|
|
15
15
|
"nodes": { "type": "array", "minItems": 1, "maxItems": 64 },
|
|
16
|
+
"loopGroups": {
|
|
17
|
+
"type": "array",
|
|
18
|
+
"maxItems": 16,
|
|
19
|
+
"items": { "$ref": "./loop-group.schema.json" }
|
|
20
|
+
},
|
|
16
21
|
"graphHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
|
|
17
22
|
},
|
|
18
23
|
"additionalProperties": true
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/egagofur/ai-engineering-loop/schemas/loop-group.schema.json",
|
|
4
|
+
"title": "AI Engineering Loop Loop Group",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": [
|
|
7
|
+
"id",
|
|
8
|
+
"displayName",
|
|
9
|
+
"nodeIds",
|
|
10
|
+
"entryNodeId",
|
|
11
|
+
"decisionNodeId",
|
|
12
|
+
"repeatTargetId",
|
|
13
|
+
"exitTargetId",
|
|
14
|
+
"maxIterations",
|
|
15
|
+
"repeatOutcome",
|
|
16
|
+
"exitOutcome",
|
|
17
|
+
"repeatLabel",
|
|
18
|
+
"exitLabel"
|
|
19
|
+
],
|
|
20
|
+
"properties": {
|
|
21
|
+
"id": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
|
|
22
|
+
"displayName": { "type": "string", "minLength": 1, "maxLength": 80 },
|
|
23
|
+
"nodeIds": {
|
|
24
|
+
"type": "array",
|
|
25
|
+
"minItems": 2,
|
|
26
|
+
"maxItems": 64,
|
|
27
|
+
"uniqueItems": true,
|
|
28
|
+
"items": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" }
|
|
29
|
+
},
|
|
30
|
+
"entryNodeId": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
|
|
31
|
+
"decisionNodeId": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
|
|
32
|
+
"repeatTargetId": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
|
|
33
|
+
"exitTargetId": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$" },
|
|
34
|
+
"maxIterations": { "type": "integer", "minimum": 1, "maximum": 100 },
|
|
35
|
+
"repeatOutcome": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,31}$" },
|
|
36
|
+
"exitOutcome": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,31}$" },
|
|
37
|
+
"repeatLabel": { "type": "string", "minLength": 1, "maxLength": 40 },
|
|
38
|
+
"exitLabel": { "type": "string", "minLength": 1, "maxLength": 40 }
|
|
39
|
+
},
|
|
40
|
+
"additionalProperties": false
|
|
41
|
+
}
|
|
@@ -18,7 +18,16 @@
|
|
|
18
18
|
"NODE_FAILED",
|
|
19
19
|
"NODE_RETRIED",
|
|
20
20
|
"NODE_APPROVED",
|
|
21
|
-
"GATE_PASSED"
|
|
21
|
+
"GATE_PASSED",
|
|
22
|
+
"DECISION_RESOLVED",
|
|
23
|
+
"LOOP_REPEATED",
|
|
24
|
+
"LOOP_EXITED",
|
|
25
|
+
"LOOP_LIMIT_REACHED",
|
|
26
|
+
"LOOP_LIMIT_OVERRIDE",
|
|
27
|
+
"LOOP_LIMIT_EXITED",
|
|
28
|
+
"LOOP_RUN_STOPPED",
|
|
29
|
+
"GOAL_UNFROZEN",
|
|
30
|
+
"WORKFLOW_EXECUTION_STARTED"
|
|
22
31
|
]
|
|
23
32
|
},
|
|
24
33
|
"runId": { "type": "string", "minLength": 1 },
|
|
@@ -10,6 +10,20 @@
|
|
|
10
10
|
"graphHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
11
11
|
"sequence": { "type": "integer", "minimum": 1 },
|
|
12
12
|
"eventHash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
13
|
+
"loopGroups": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"additionalProperties": {
|
|
16
|
+
"type": "object",
|
|
17
|
+
"required": ["status", "iteration", "maxIterations", "updatedAt"],
|
|
18
|
+
"properties": {
|
|
19
|
+
"status": { "enum": ["PENDING", "RUNNING", "BLOCKED", "EXITED", "STOPPED"] },
|
|
20
|
+
"iteration": { "type": "integer", "minimum": 1 },
|
|
21
|
+
"maxIterations": { "type": "integer", "minimum": 1, "maximum": 100 },
|
|
22
|
+
"lastOutcome": { "type": ["string", "null"] },
|
|
23
|
+
"updatedAt": { "type": "string", "format": "date-time" }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
},
|
|
13
27
|
"nodes": {
|
|
14
28
|
"type": "object",
|
|
15
29
|
"additionalProperties": {
|
|
@@ -20,6 +34,8 @@
|
|
|
20
34
|
"enum": ["PENDING", "READY", "RUNNING", "PASSED", "FAILED", "SKIPPED", "BLOCKED"]
|
|
21
35
|
},
|
|
22
36
|
"attempts": { "type": "integer", "minimum": 0 },
|
|
37
|
+
"loopGroupId": { "type": "string" },
|
|
38
|
+
"loopIteration": { "type": "integer", "minimum": 1 },
|
|
23
39
|
"updatedAt": { "type": "string", "format": "date-time" }
|
|
24
40
|
}
|
|
25
41
|
}
|