@synergenius/flow-weaver 0.23.3 → 0.23.5

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.
@@ -9886,7 +9886,7 @@ var VERSION;
9886
9886
  var init_generated_version = __esm({
9887
9887
  "src/generated-version.ts"() {
9888
9888
  "use strict";
9889
- VERSION = "0.23.3";
9889
+ VERSION = "0.23.5";
9890
9890
  }
9891
9891
  });
9892
9892
 
@@ -11198,6 +11198,15 @@ function generateControlFlowWithExecutionContext(workflow, nodeTypes, isAsync2,
11198
11198
  }
11199
11199
  }
11200
11200
  });
11201
+ const topLevelSuccessFlags = /* @__PURE__ */ new Set();
11202
+ branchRegions.forEach((region, nodeId) => {
11203
+ if (region.successNodes.size > 0 || region.failureNodes.size > 0) {
11204
+ const safeId = toValidIdentifier(nodeId);
11205
+ lines.push(` let ${safeId}_success = false;`);
11206
+ topLevelSuccessFlags.add(safeId);
11207
+ hasLetDeclarations = true;
11208
+ }
11209
+ });
11201
11210
  if (hasLetDeclarations) {
11202
11211
  lines.push("");
11203
11212
  }
@@ -11417,7 +11426,8 @@ function generateControlFlowWithExecutionContext(workflow, nodeTypes, isAsync2,
11417
11426
  "ctx",
11418
11427
  bundleMode,
11419
11428
  branchingNodesNeedingSuccessFlag,
11420
- production
11429
+ production,
11430
+ topLevelSuccessFlags
11421
11431
  );
11422
11432
  if (chainNeedsClose) {
11423
11433
  lines.push(` }`);
@@ -11426,6 +11436,8 @@ function generateControlFlowWithExecutionContext(workflow, nodeTypes, isAsync2,
11426
11436
  }
11427
11437
  let branchIndent = " ";
11428
11438
  let branchNeedsClose = false;
11439
+ const nodeRegion = branchRegions.get(instanceId);
11440
+ const promotedPreDeclared = new Set(topLevelSuccessFlags);
11429
11441
  if (nodesPromotedFromBranches.has(instanceId)) {
11430
11442
  const stepSourceConditions = [];
11431
11443
  workflow.connections.forEach((conn) => {
@@ -11448,7 +11460,7 @@ function generateControlFlowWithExecutionContext(workflow, nodeTypes, isAsync2,
11448
11460
  nodeType,
11449
11461
  workflow,
11450
11462
  nodeTypes,
11451
- branchRegions.get(instanceId),
11463
+ nodeRegion,
11452
11464
  availableVars,
11453
11465
  generatedNodes,
11454
11466
  lines,
@@ -11459,8 +11471,8 @@ function generateControlFlowWithExecutionContext(workflow, nodeTypes, isAsync2,
11459
11471
  isAsync2,
11460
11472
  "ctx",
11461
11473
  bundleMode,
11462
- /* @__PURE__ */ new Set(),
11463
- branchingNodesNeedingSuccessFlag.has(instanceId),
11474
+ promotedPreDeclared,
11475
+ branchingNodesNeedingSuccessFlag.has(instanceId) || topLevelSuccessFlags.has(toValidIdentifier(instanceId)),
11464
11476
  production
11465
11477
  );
11466
11478
  if (branchNeedsClose) {
@@ -11872,13 +11884,15 @@ function buildStepSourceCondition(sourceNode, sourcePort, branchingNodes) {
11872
11884
  }
11873
11885
  return `${safeNode}Idx !== undefined`;
11874
11886
  }
11875
- function generateBranchingChainCode(chain, workflow, nodeTypes, branchingNodes, branchRegions, availableVars, generatedNodes, lines, indent, isAsync2, ctxVar, bundleMode, forceTrackSuccessNodes = /* @__PURE__ */ new Set(), production = false) {
11876
- const preDeclaredFlags = /* @__PURE__ */ new Set();
11887
+ function generateBranchingChainCode(chain, workflow, nodeTypes, branchingNodes, branchRegions, availableVars, generatedNodes, lines, indent, isAsync2, ctxVar, bundleMode, forceTrackSuccessNodes = /* @__PURE__ */ new Set(), production = false, alreadyDeclaredFlags = /* @__PURE__ */ new Set()) {
11888
+ const preDeclaredFlags = new Set(alreadyDeclaredFlags);
11877
11889
  for (let i = 0; i < chain.length; i++) {
11878
11890
  const isLast = i === chain.length - 1;
11879
- if (!isLast || forceTrackSuccessNodes.has(chain[i])) {
11880
- const safeId = toValidIdentifier(chain[i]);
11881
- lines.push(`${indent}let ${safeId}_success = false;`);
11891
+ const safeId = toValidIdentifier(chain[i]);
11892
+ if (!isLast || forceTrackSuccessNodes.has(chain[i]) || alreadyDeclaredFlags.has(safeId)) {
11893
+ if (!alreadyDeclaredFlags.has(safeId)) {
11894
+ lines.push(`${indent}let ${safeId}_success = false;`);
11895
+ }
11882
11896
  preDeclaredFlags.add(safeId);
11883
11897
  }
11884
11898
  }
@@ -11928,8 +11942,8 @@ function generateBranchingChainCode(chain, workflow, nodeTypes, branchingNodes,
11928
11942
  ctxVar,
11929
11943
  bundleMode,
11930
11944
  preDeclaredFlags,
11931
- !isLast || forceTrackSuccessNodes.has(chain[i]),
11932
- // forceTrackSuccess for non-last chain nodes or nodes with promoted dependents
11945
+ !isLast || forceTrackSuccessNodes.has(chain[i]) || alreadyDeclaredFlags.has(safeId),
11946
+ // forceTrackSuccess for non-last chain nodes, nodes with promoted dependents, or nodes with pre-declared flags
11933
11947
  production
11934
11948
  );
11935
11949
  generateScopedChildrenExecution(
@@ -12231,6 +12245,13 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12231
12245
  if (!nodeType) return;
12232
12246
  if (branchingNodes.has(instanceId2)) {
12233
12247
  const nestedRegion = branchRegions.get(instanceId2);
12248
+ const nestedSafeId = toValidIdentifier(instanceId2);
12249
+ const nestedHasDownstream = nestedRegion.successNodes.size > 0 || nestedRegion.failureNodes.size > 0;
12250
+ const nestedPreDeclared = new Set(preDeclaredSuccessFlags);
12251
+ if (nestedHasDownstream && !nestedPreDeclared.has(nestedSafeId)) {
12252
+ lines.push(`${indent} let ${nestedSafeId}_success = false;`);
12253
+ nestedPreDeclared.add(nestedSafeId);
12254
+ }
12234
12255
  generateBranchingNodeCode(
12235
12256
  inst,
12236
12257
  nodeType,
@@ -12247,8 +12268,9 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12247
12268
  isAsync2,
12248
12269
  ctxVar,
12249
12270
  bundleMode,
12250
- /* @__PURE__ */ new Set(),
12251
- false,
12271
+ nestedPreDeclared,
12272
+ nestedPreDeclared.has(nestedSafeId),
12273
+ // force tracking if flag was pre-declared at higher scope
12252
12274
  production
12253
12275
  );
12254
12276
  successExecutedNodes.push(instanceId2);
@@ -12308,6 +12330,13 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12308
12330
  if (!nodeType) return;
12309
12331
  if (branchingNodes.has(instanceId2)) {
12310
12332
  const nestedRegion = branchRegions.get(instanceId2);
12333
+ const nestedSafeId = toValidIdentifier(instanceId2);
12334
+ const nestedHasDownstream = nestedRegion.successNodes.size > 0 || nestedRegion.failureNodes.size > 0;
12335
+ const nestedPreDeclared = new Set(preDeclaredSuccessFlags);
12336
+ if (nestedHasDownstream && !nestedPreDeclared.has(nestedSafeId)) {
12337
+ lines.push(`${indent} let ${nestedSafeId}_success = false;`);
12338
+ nestedPreDeclared.add(nestedSafeId);
12339
+ }
12311
12340
  generateBranchingNodeCode(
12312
12341
  inst,
12313
12342
  nodeType,
@@ -12324,8 +12353,9 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12324
12353
  isAsync2,
12325
12354
  ctxVar,
12326
12355
  bundleMode,
12327
- /* @__PURE__ */ new Set(),
12328
- false,
12356
+ nestedPreDeclared,
12357
+ nestedPreDeclared.has(nestedSafeId),
12358
+ // force tracking if flag was pre-declared at higher scope
12329
12359
  production
12330
12360
  );
12331
12361
  failureExecutedNodes.push(instanceId2);
@@ -95923,7 +95953,7 @@ var {
95923
95953
  // src/cli/index.ts
95924
95954
  init_logger();
95925
95955
  init_error_utils();
95926
- var version2 = true ? "0.23.3" : "0.0.0-dev";
95956
+ var version2 = true ? "0.23.5" : "0.0.0-dev";
95927
95957
  var program2 = new Command();
95928
95958
  program2.name("fw").description("Flow Weaver Annotations - Compile and validate workflow files").option("-v, --version", "Output the current version").option("--no-color", "Disable colors").option("--color", "Force colors").on("option:version", () => {
95929
95959
  logger.banner(version2);
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.23.3";
1
+ export declare const VERSION = "0.23.5";
2
2
  //# sourceMappingURL=generated-version.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Auto-generated by scripts/generate-version.ts — do not edit manually
2
- export const VERSION = '0.23.3';
2
+ export const VERSION = '0.23.5';
3
3
  //# sourceMappingURL=generated-version.js.map
@@ -187,6 +187,19 @@ export function generateControlFlowWithExecutionContext(workflow, nodeTypes, isA
187
187
  }
188
188
  }
189
189
  });
190
+ // Pre-declare _success flags for branching nodes that have downstream nodes.
191
+ // These flags must be at the function's top level because downstream guards
192
+ // (promoted nodes, chain guards) may reference them outside the branch block
193
+ // where the branching node is generated.
194
+ const topLevelSuccessFlags = new Set();
195
+ branchRegions.forEach((region, nodeId) => {
196
+ if (region.successNodes.size > 0 || region.failureNodes.size > 0) {
197
+ const safeId = toValidIdentifier(nodeId);
198
+ lines.push(` let ${safeId}_success = false;`);
199
+ topLevelSuccessFlags.add(safeId);
200
+ hasLetDeclarations = true;
201
+ }
202
+ });
190
203
  if (hasLetDeclarations) {
191
204
  lines.push('');
192
205
  }
@@ -410,7 +423,7 @@ export function generateControlFlowWithExecutionContext(workflow, nodeTypes, isA
410
423
  chainNeedsClose = true;
411
424
  }
412
425
  }
413
- generateBranchingChainCode(branchingChains.get(instanceId), workflow, nodeTypes, branchingNodes, branchRegions, availableVars, generatedNodes, lines, chainIndent, isAsync, 'ctx', bundleMode, branchingNodesNeedingSuccessFlag, production);
426
+ generateBranchingChainCode(branchingChains.get(instanceId), workflow, nodeTypes, branchingNodes, branchRegions, availableVars, generatedNodes, lines, chainIndent, isAsync, 'ctx', bundleMode, branchingNodesNeedingSuccessFlag, production, topLevelSuccessFlags);
414
427
  if (chainNeedsClose) {
415
428
  lines.push(` }`);
416
429
  }
@@ -420,6 +433,10 @@ export function generateControlFlowWithExecutionContext(workflow, nodeTypes, isA
420
433
  // For promoted branching nodes, wrap in STEP guard from execute port source
421
434
  let branchIndent = ' ';
422
435
  let branchNeedsClose = false;
436
+ // Pre-declare _success flag at the outer scope so downstream guards
437
+ // (which may run after the promoted guard block) can access it.
438
+ const nodeRegion = branchRegions.get(instanceId);
439
+ const promotedPreDeclared = new Set(topLevelSuccessFlags);
423
440
  if (nodesPromotedFromBranches.has(instanceId)) {
424
441
  const stepSourceConditions = [];
425
442
  workflow.connections.forEach((conn) => {
@@ -439,7 +456,7 @@ export function generateControlFlowWithExecutionContext(workflow, nodeTypes, isA
439
456
  branchNeedsClose = true;
440
457
  }
441
458
  }
442
- generateBranchingNodeCode(instance, nodeType, workflow, nodeTypes, branchRegions.get(instanceId), availableVars, generatedNodes, lines, branchIndent, false, branchingNodes, branchRegions, isAsync, 'ctx', bundleMode, new Set(), branchingNodesNeedingSuccessFlag.has(instanceId), production);
459
+ generateBranchingNodeCode(instance, nodeType, workflow, nodeTypes, nodeRegion, availableVars, generatedNodes, lines, branchIndent, false, branchingNodes, branchRegions, isAsync, 'ctx', bundleMode, promotedPreDeclared, branchingNodesNeedingSuccessFlag.has(instanceId) || topLevelSuccessFlags.has(toValidIdentifier(instanceId)), production);
443
460
  if (branchNeedsClose) {
444
461
  lines.push(` }`);
445
462
  }
@@ -860,16 +877,19 @@ function buildStepSourceCondition(sourceNode, sourcePort, branchingNodes) {
860
877
  * if (A_success) { B code } else { CANCELLED for B,C and regions }
861
878
  * if (A_success && B_success) { C code } else { CANCELLED for C and regions }
862
879
  */
863
- function generateBranchingChainCode(chain, workflow, nodeTypes, branchingNodes, branchRegions, availableVars, generatedNodes, lines, indent, isAsync, ctxVar, bundleMode, forceTrackSuccessNodes = new Set(), production = false) {
880
+ function generateBranchingChainCode(chain, workflow, nodeTypes, branchingNodes, branchRegions, availableVars, generatedNodes, lines, indent, isAsync, ctxVar, bundleMode, forceTrackSuccessNodes = new Set(), production = false, alreadyDeclaredFlags = new Set()) {
864
881
  // Pre-declare success flags for all non-last chain nodes so they're
865
882
  // accessible across guard blocks (avoiding let-in-block scoping issues).
866
883
  // Also pre-declare for the last node if promoted nodes depend on its _success flag.
867
- const preDeclaredFlags = new Set();
884
+ // Skip flags already declared at a higher scope (e.g. function top-level).
885
+ const preDeclaredFlags = new Set(alreadyDeclaredFlags);
868
886
  for (let i = 0; i < chain.length; i++) {
869
887
  const isLast = i === chain.length - 1;
870
- if (!isLast || forceTrackSuccessNodes.has(chain[i])) {
871
- const safeId = toValidIdentifier(chain[i]);
872
- lines.push(`${indent}let ${safeId}_success = false;`);
888
+ const safeId = toValidIdentifier(chain[i]);
889
+ if (!isLast || forceTrackSuccessNodes.has(chain[i]) || alreadyDeclaredFlags.has(safeId)) {
890
+ if (!alreadyDeclaredFlags.has(safeId)) {
891
+ lines.push(`${indent}let ${safeId}_success = false;`);
892
+ }
873
893
  preDeclaredFlags.add(safeId);
874
894
  }
875
895
  }
@@ -904,7 +924,7 @@ function generateBranchingChainCode(chain, workflow, nodeTypes, branchingNodes,
904
924
  lines.push(`${indent}if (${guardCondition}) {`);
905
925
  }
906
926
  const nodeIndent = hasGuard ? indent + ' ' : indent;
907
- generateBranchingNodeCode(instance, nodeType, workflow, nodeTypes, effectiveRegion, availableVars, generatedNodes, lines, nodeIndent, false, branchingNodes, branchRegions, isAsync, ctxVar, bundleMode, preDeclaredFlags, !isLast || forceTrackSuccessNodes.has(chain[i]), // forceTrackSuccess for non-last chain nodes or nodes with promoted dependents
927
+ generateBranchingNodeCode(instance, nodeType, workflow, nodeTypes, effectiveRegion, availableVars, generatedNodes, lines, nodeIndent, false, branchingNodes, branchRegions, isAsync, ctxVar, bundleMode, preDeclaredFlags, !isLast || forceTrackSuccessNodes.has(chain[i]) || alreadyDeclaredFlags.has(safeId), // forceTrackSuccess for non-last chain nodes, nodes with promoted dependents, or nodes with pre-declared flags
908
928
  production);
909
929
  // Generate scoped children for this chain node
910
930
  generateScopedChildrenExecution(instance, nodeType, workflow, nodeTypes, generatedNodes, availableVars, lines, nodeIndent, branchingNodes, branchRegions, isAsync, bundleMode, production);
@@ -1194,7 +1214,19 @@ bundleMode = false, preDeclaredSuccessFlags = new Set(), forceTrackSuccess = fal
1194
1214
  return;
1195
1215
  if (branchingNodes.has(instanceId)) {
1196
1216
  const nestedRegion = branchRegions.get(instanceId);
1197
- generateBranchingNodeCode(inst, nodeType, workflow, allNodeTypes, nestedRegion, successVars, generatedNodes, lines, `${indent} `, false, branchingNodes, branchRegions, isAsync, ctxVar, bundleMode, new Set(), false, production);
1217
+ // Pre-declare nested branching node's _success flag at the current
1218
+ // scope so it remains accessible to downstream guards that may run
1219
+ // outside this branch block. (Fixes scoping bug where the flag was
1220
+ // declared inside a nested conditional but referenced at a higher scope.)
1221
+ const nestedSafeId = toValidIdentifier(instanceId);
1222
+ const nestedHasDownstream = nestedRegion.successNodes.size > 0 || nestedRegion.failureNodes.size > 0;
1223
+ const nestedPreDeclared = new Set(preDeclaredSuccessFlags);
1224
+ if (nestedHasDownstream && !nestedPreDeclared.has(nestedSafeId)) {
1225
+ lines.push(`${indent} let ${nestedSafeId}_success = false;`);
1226
+ nestedPreDeclared.add(nestedSafeId);
1227
+ }
1228
+ generateBranchingNodeCode(inst, nodeType, workflow, allNodeTypes, nestedRegion, successVars, generatedNodes, lines, `${indent} `, false, branchingNodes, branchRegions, isAsync, ctxVar, bundleMode, nestedPreDeclared, nestedPreDeclared.has(nestedSafeId), // force tracking if flag was pre-declared at higher scope
1229
+ production);
1198
1230
  successExecutedNodes.push(instanceId);
1199
1231
  nestedRegion.successNodes.forEach((n) => successExecutedNodes.push(n));
1200
1232
  nestedRegion.failureNodes.forEach((n) => successExecutedNodes.push(n));
@@ -1235,7 +1267,17 @@ bundleMode = false, preDeclaredSuccessFlags = new Set(), forceTrackSuccess = fal
1235
1267
  return;
1236
1268
  if (branchingNodes.has(instanceId)) {
1237
1269
  const nestedRegion = branchRegions.get(instanceId);
1238
- generateBranchingNodeCode(inst, nodeType, workflow, allNodeTypes, nestedRegion, failureVars, generatedNodes, lines, `${indent} `, false, branchingNodes, branchRegions, isAsync, ctxVar, bundleMode, new Set(), false, production);
1270
+ // Pre-declare nested branching node's _success flag at the current
1271
+ // scope (same fix as success branch above).
1272
+ const nestedSafeId = toValidIdentifier(instanceId);
1273
+ const nestedHasDownstream = nestedRegion.successNodes.size > 0 || nestedRegion.failureNodes.size > 0;
1274
+ const nestedPreDeclared = new Set(preDeclaredSuccessFlags);
1275
+ if (nestedHasDownstream && !nestedPreDeclared.has(nestedSafeId)) {
1276
+ lines.push(`${indent} let ${nestedSafeId}_success = false;`);
1277
+ nestedPreDeclared.add(nestedSafeId);
1278
+ }
1279
+ generateBranchingNodeCode(inst, nodeType, workflow, allNodeTypes, nestedRegion, failureVars, generatedNodes, lines, `${indent} `, false, branchingNodes, branchRegions, isAsync, ctxVar, bundleMode, nestedPreDeclared, nestedPreDeclared.has(nestedSafeId), // force tracking if flag was pre-declared at higher scope
1280
+ production);
1239
1281
  failureExecutedNodes.push(instanceId);
1240
1282
  nestedRegion.successNodes.forEach((n) => failureExecutedNodes.push(n));
1241
1283
  nestedRegion.failureNodes.forEach((n) => failureExecutedNodes.push(n));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synergenius/flow-weaver",
3
- "version": "0.23.3",
3
+ "version": "0.23.5",
4
4
  "description": "Deterministic workflow compiler for AI agents. Compiles to standalone TypeScript, no runtime dependencies.",
5
5
  "private": false,
6
6
  "type": "module",