@synergenius/flow-weaver 0.23.3 → 0.23.4

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.4";
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,7 +11471,7 @@ function generateControlFlowWithExecutionContext(workflow, nodeTypes, isAsync2,
11459
11471
  isAsync2,
11460
11472
  "ctx",
11461
11473
  bundleMode,
11462
- /* @__PURE__ */ new Set(),
11474
+ promotedPreDeclared,
11463
11475
  branchingNodesNeedingSuccessFlag.has(instanceId),
11464
11476
  production
11465
11477
  );
@@ -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
11891
  if (!isLast || forceTrackSuccessNodes.has(chain[i])) {
11880
11892
  const safeId = toValidIdentifier(chain[i]);
11881
- lines.push(`${indent}let ${safeId}_success = false;`);
11893
+ if (!alreadyDeclaredFlags.has(safeId)) {
11894
+ lines.push(`${indent}let ${safeId}_success = false;`);
11895
+ }
11882
11896
  preDeclaredFlags.add(safeId);
11883
11897
  }
11884
11898
  }
@@ -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,7 +12268,7 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12247
12268
  isAsync2,
12248
12269
  ctxVar,
12249
12270
  bundleMode,
12250
- /* @__PURE__ */ new Set(),
12271
+ nestedPreDeclared,
12251
12272
  false,
12252
12273
  production
12253
12274
  );
@@ -12308,6 +12329,13 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12308
12329
  if (!nodeType) return;
12309
12330
  if (branchingNodes.has(instanceId2)) {
12310
12331
  const nestedRegion = branchRegions.get(instanceId2);
12332
+ const nestedSafeId = toValidIdentifier(instanceId2);
12333
+ const nestedHasDownstream = nestedRegion.successNodes.size > 0 || nestedRegion.failureNodes.size > 0;
12334
+ const nestedPreDeclared = new Set(preDeclaredSuccessFlags);
12335
+ if (nestedHasDownstream && !nestedPreDeclared.has(nestedSafeId)) {
12336
+ lines.push(`${indent} let ${nestedSafeId}_success = false;`);
12337
+ nestedPreDeclared.add(nestedSafeId);
12338
+ }
12311
12339
  generateBranchingNodeCode(
12312
12340
  inst,
12313
12341
  nodeType,
@@ -12324,7 +12352,7 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12324
12352
  isAsync2,
12325
12353
  ctxVar,
12326
12354
  bundleMode,
12327
- /* @__PURE__ */ new Set(),
12355
+ nestedPreDeclared,
12328
12356
  false,
12329
12357
  production
12330
12358
  );
@@ -95923,7 +95951,7 @@ var {
95923
95951
  // src/cli/index.ts
95924
95952
  init_logger();
95925
95953
  init_error_utils();
95926
- var version2 = true ? "0.23.3" : "0.0.0-dev";
95954
+ var version2 = true ? "0.23.4" : "0.0.0-dev";
95927
95955
  var program2 = new Command();
95928
95956
  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
95957
  logger.banner(version2);
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.23.3";
1
+ export declare const VERSION = "0.23.4";
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.4';
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), 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
888
  if (!isLast || forceTrackSuccessNodes.has(chain[i])) {
871
889
  const safeId = toValidIdentifier(chain[i]);
872
- lines.push(`${indent}let ${safeId}_success = false;`);
890
+ if (!alreadyDeclaredFlags.has(safeId)) {
891
+ lines.push(`${indent}let ${safeId}_success = false;`);
892
+ }
873
893
  preDeclaredFlags.add(safeId);
874
894
  }
875
895
  }
@@ -1194,7 +1214,18 @@ 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, false, production);
1198
1229
  successExecutedNodes.push(instanceId);
1199
1230
  nestedRegion.successNodes.forEach((n) => successExecutedNodes.push(n));
1200
1231
  nestedRegion.failureNodes.forEach((n) => successExecutedNodes.push(n));
@@ -1235,7 +1266,16 @@ bundleMode = false, preDeclaredSuccessFlags = new Set(), forceTrackSuccess = fal
1235
1266
  return;
1236
1267
  if (branchingNodes.has(instanceId)) {
1237
1268
  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);
1269
+ // Pre-declare nested branching node's _success flag at the current
1270
+ // scope (same fix as success branch above).
1271
+ const nestedSafeId = toValidIdentifier(instanceId);
1272
+ const nestedHasDownstream = nestedRegion.successNodes.size > 0 || nestedRegion.failureNodes.size > 0;
1273
+ const nestedPreDeclared = new Set(preDeclaredSuccessFlags);
1274
+ if (nestedHasDownstream && !nestedPreDeclared.has(nestedSafeId)) {
1275
+ lines.push(`${indent} let ${nestedSafeId}_success = false;`);
1276
+ nestedPreDeclared.add(nestedSafeId);
1277
+ }
1278
+ generateBranchingNodeCode(inst, nodeType, workflow, allNodeTypes, nestedRegion, failureVars, generatedNodes, lines, `${indent} `, false, branchingNodes, branchRegions, isAsync, ctxVar, bundleMode, nestedPreDeclared, false, production);
1239
1279
  failureExecutedNodes.push(instanceId);
1240
1280
  nestedRegion.successNodes.forEach((n) => failureExecutedNodes.push(n));
1241
1281
  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.4",
4
4
  "description": "Deterministic workflow compiler for AI agents. Compiles to standalone TypeScript, no runtime dependencies.",
5
5
  "private": false,
6
6
  "type": "module",