@particle-academy/fancy-flow 0.65.2 → 0.66.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.
Files changed (105) hide show
  1. package/README.md +100 -3
  2. package/dist/{FlowViewer-BI_AyyvU.d.ts → FlowViewer-BCc_BvuD.d.ts} +1 -1
  3. package/dist/{FlowViewer-DABx-6A-.d.cts → FlowViewer-CoAJ3o52.d.cts} +1 -1
  4. package/dist/{HumanPrompt-Bpp3JiVH.d.cts → HumanPrompt--pXDOyYC.d.cts} +2 -2
  5. package/dist/{HumanPrompt-BKThiyjB.d.ts → HumanPrompt-DXm_FP9z.d.ts} +2 -2
  6. package/dist/chunk-2QXKDLGT.js +58 -0
  7. package/dist/chunk-2QXKDLGT.js.map +1 -0
  8. package/dist/{chunk-77V4QC6Y.js → chunk-B7HKJJVV.js} +3 -3
  9. package/dist/{chunk-77V4QC6Y.js.map → chunk-B7HKJJVV.js.map} +1 -1
  10. package/dist/{chunk-MBVX4ZRB.js → chunk-FNYLKSFJ.js} +3 -3
  11. package/dist/{chunk-MBVX4ZRB.js.map → chunk-FNYLKSFJ.js.map} +1 -1
  12. package/dist/{chunk-JF6WCRBU.js → chunk-HQGOFGAL.js} +861 -40
  13. package/dist/chunk-HQGOFGAL.js.map +1 -0
  14. package/dist/{chunk-5H54OTKT.js → chunk-IEYCNFXZ.js} +3 -3
  15. package/dist/{chunk-5H54OTKT.js.map → chunk-IEYCNFXZ.js.map} +1 -1
  16. package/dist/{chunk-W5DPKJY4.js → chunk-MTONBM53.js} +4 -4
  17. package/dist/chunk-MTONBM53.js.map +1 -0
  18. package/dist/{chunk-RIAFHQT5.js → chunk-PNHZHEWE.js} +3 -3
  19. package/dist/{chunk-RIAFHQT5.js.map → chunk-PNHZHEWE.js.map} +1 -1
  20. package/dist/{chunk-EO6444T2.js → chunk-UCCTXJXL.js} +4 -4
  21. package/dist/{chunk-EO6444T2.js.map → chunk-UCCTXJXL.js.map} +1 -1
  22. package/dist/connectors.d.cts +2 -2
  23. package/dist/connectors.d.ts +2 -2
  24. package/dist/durable/index.d.cts +2 -2
  25. package/dist/durable/index.d.ts +2 -2
  26. package/dist/durable.cjs +837 -47
  27. package/dist/durable.cjs.map +1 -1
  28. package/dist/durable.js +2 -3
  29. package/dist/durable.js.map +1 -1
  30. package/dist/engine.cjs +843 -132
  31. package/dist/engine.cjs.map +1 -1
  32. package/dist/engine.d.cts +6 -7
  33. package/dist/engine.d.ts +6 -7
  34. package/dist/engine.js +5 -6
  35. package/dist/engine.js.map +1 -1
  36. package/dist/fields/react-fancy.d.cts +3 -3
  37. package/dist/fields/react-fancy.d.ts +3 -3
  38. package/dist/index.cjs +853 -140
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +65 -36
  41. package/dist/index.d.ts +65 -36
  42. package/dist/index.js +19 -18
  43. package/dist/index.js.map +1 -1
  44. package/dist/layout/index.d.cts +1 -1
  45. package/dist/layout/index.d.ts +1 -1
  46. package/dist/llm/prism.cjs.map +1 -1
  47. package/dist/llm/prism.d.cts +1 -2
  48. package/dist/llm/prism.d.ts +1 -2
  49. package/dist/llm/prism.js +1 -1
  50. package/dist/llm/vercel-ai.cjs.map +1 -1
  51. package/dist/llm/vercel-ai.d.cts +1 -2
  52. package/dist/llm/vercel-ai.d.ts +1 -2
  53. package/dist/llm/vercel-ai.js +1 -1
  54. package/dist/registry/index.d.cts +5 -6
  55. package/dist/registry/index.d.ts +5 -6
  56. package/dist/{registry-CntAdUcY.d.cts → registry-BcgllSk2.d.cts} +1 -1
  57. package/dist/{registry-DYoV-MQi.d.ts → registry-h-2QswZ5.d.ts} +1 -1
  58. package/dist/registry.cjs +867 -37
  59. package/dist/registry.cjs.map +1 -1
  60. package/dist/registry.js +3 -3
  61. package/dist/{run-cohort-C1nRh_mi.d.ts → run-cohort-CjUBWg6X.d.ts} +2 -2
  62. package/dist/{run-cohort-CBRAUj-z.d.cts → run-cohort-DL9JzzPU.d.cts} +2 -2
  63. package/dist/{run-flow-2XsHBwpd.d.cts → run-flow-B_8hgO5_.d.cts} +1 -1
  64. package/dist/{run-flow-D7AOCcfE.d.ts → run-flow-CxEGBOxd.d.ts} +1 -1
  65. package/dist/runtime/index.d.cts +5 -5
  66. package/dist/runtime/index.d.ts +5 -5
  67. package/dist/runtime.cjs +837 -36
  68. package/dist/runtime.cjs.map +1 -1
  69. package/dist/runtime.js +4 -4
  70. package/dist/schema/index.d.cts +19 -6
  71. package/dist/schema/index.d.ts +19 -6
  72. package/dist/schema.cjs +837 -36
  73. package/dist/schema.cjs.map +1 -1
  74. package/dist/schema.js +4 -4
  75. package/dist/screens.cjs +837 -36
  76. package/dist/screens.cjs.map +1 -1
  77. package/dist/screens.d.cts +2 -2
  78. package/dist/screens.d.ts +2 -2
  79. package/dist/screens.js +5 -5
  80. package/dist/terminal/fancy-term-host.cjs +99 -0
  81. package/dist/terminal/fancy-term-host.cjs.map +1 -0
  82. package/dist/terminal/fancy-term-host.d.cts +76 -0
  83. package/dist/terminal/fancy-term-host.d.ts +76 -0
  84. package/dist/terminal/fancy-term-host.js +92 -0
  85. package/dist/terminal/fancy-term-host.js.map +1 -0
  86. package/dist/types-B-Syk9-M.d.cts +620 -0
  87. package/dist/types-B-Syk9-M.d.ts +620 -0
  88. package/dist/{types-D71SKA5A.d.cts → types-C2ATTmjN.d.cts} +1 -1
  89. package/dist/{types-Ckhz-YwC.d.ts → types-VunLGqrn.d.ts} +1 -1
  90. package/dist/ux.cjs +837 -36
  91. package/dist/ux.cjs.map +1 -1
  92. package/dist/ux.d.cts +2 -2
  93. package/dist/ux.d.ts +2 -2
  94. package/dist/ux.js +2 -2
  95. package/package.json +11 -1
  96. package/dist/capabilities-BYa5p5jw.d.cts +0 -112
  97. package/dist/capabilities-COOXRiNL.d.ts +0 -112
  98. package/dist/chunk-JF6WCRBU.js.map +0 -1
  99. package/dist/chunk-UM4C46AF.js +0 -103
  100. package/dist/chunk-UM4C46AF.js.map +0 -1
  101. package/dist/chunk-USL4FMFU.js +0 -41
  102. package/dist/chunk-USL4FMFU.js.map +0 -1
  103. package/dist/chunk-W5DPKJY4.js.map +0 -1
  104. package/dist/types-JFYjPJAG.d.cts +0 -333
  105. package/dist/types-JFYjPJAG.d.ts +0 -333
package/dist/runtime.cjs CHANGED
@@ -2166,38 +2166,38 @@ function attrRemoveNS2(fullname) {
2166
2166
  this.removeAttributeNS(fullname.space, fullname.local);
2167
2167
  };
2168
2168
  }
2169
- function attrConstant2(name, interpolate, value1) {
2169
+ function attrConstant2(name, interpolate2, value1) {
2170
2170
  var string00, string1 = value1 + "", interpolate0;
2171
2171
  return function() {
2172
2172
  var string0 = this.getAttribute(name);
2173
- return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate(string00 = string0, value1);
2173
+ return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate2(string00 = string0, value1);
2174
2174
  };
2175
2175
  }
2176
- function attrConstantNS2(fullname, interpolate, value1) {
2176
+ function attrConstantNS2(fullname, interpolate2, value1) {
2177
2177
  var string00, string1 = value1 + "", interpolate0;
2178
2178
  return function() {
2179
2179
  var string0 = this.getAttributeNS(fullname.space, fullname.local);
2180
- return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate(string00 = string0, value1);
2180
+ return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate2(string00 = string0, value1);
2181
2181
  };
2182
2182
  }
2183
- function attrFunction2(name, interpolate, value) {
2183
+ function attrFunction2(name, interpolate2, value) {
2184
2184
  var string00, string10, interpolate0;
2185
2185
  return function() {
2186
2186
  var string0, value1 = value(this), string1;
2187
2187
  if (value1 == null) return void this.removeAttribute(name);
2188
2188
  string0 = this.getAttribute(name);
2189
2189
  string1 = value1 + "";
2190
- return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
2190
+ return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate2(string00 = string0, value1));
2191
2191
  };
2192
2192
  }
2193
- function attrFunctionNS2(fullname, interpolate, value) {
2193
+ function attrFunctionNS2(fullname, interpolate2, value) {
2194
2194
  var string00, string10, interpolate0;
2195
2195
  return function() {
2196
2196
  var string0, value1 = value(this), string1;
2197
2197
  if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
2198
2198
  string0 = this.getAttributeNS(fullname.space, fullname.local);
2199
2199
  string1 = value1 + "";
2200
- return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
2200
+ return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate2(string00 = string0, value1));
2201
2201
  };
2202
2202
  }
2203
2203
  function attr_default2(name, value) {
@@ -2407,11 +2407,11 @@ function selection_default2() {
2407
2407
  }
2408
2408
 
2409
2409
  // node_modules/d3-transition/src/transition/style.js
2410
- function styleNull(name, interpolate) {
2410
+ function styleNull(name, interpolate2) {
2411
2411
  var string00, string10, interpolate0;
2412
2412
  return function() {
2413
2413
  var string0 = styleValue(this, name), string1 = (this.style.removeProperty(name), styleValue(this, name));
2414
- return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : interpolate0 = interpolate(string00 = string0, string10 = string1);
2414
+ return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : interpolate0 = interpolate2(string00 = string0, string10 = string1);
2415
2415
  };
2416
2416
  }
2417
2417
  function styleRemove2(name) {
@@ -2419,19 +2419,19 @@ function styleRemove2(name) {
2419
2419
  this.style.removeProperty(name);
2420
2420
  };
2421
2421
  }
2422
- function styleConstant2(name, interpolate, value1) {
2422
+ function styleConstant2(name, interpolate2, value1) {
2423
2423
  var string00, string1 = value1 + "", interpolate0;
2424
2424
  return function() {
2425
2425
  var string0 = styleValue(this, name);
2426
- return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate(string00 = string0, value1);
2426
+ return string0 === string1 ? null : string0 === string00 ? interpolate0 : interpolate0 = interpolate2(string00 = string0, value1);
2427
2427
  };
2428
2428
  }
2429
- function styleFunction2(name, interpolate, value) {
2429
+ function styleFunction2(name, interpolate2, value) {
2430
2430
  var string00, string10, interpolate0;
2431
2431
  return function() {
2432
2432
  var string0 = styleValue(this, name), value1 = value(this), string1 = value1 + "";
2433
2433
  if (value1 == null) string1 = value1 = (this.style.removeProperty(name), styleValue(this, name));
2434
- return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
2434
+ return string0 === string1 ? null : string0 === string00 && string1 === string10 ? interpolate0 : (string10 = string1, interpolate0 = interpolate2(string00 = string0, value1));
2435
2435
  };
2436
2436
  }
2437
2437
  function styleMaybeRemove(id2, name) {
@@ -2533,9 +2533,9 @@ function transition_default() {
2533
2533
  // node_modules/d3-transition/src/transition/end.js
2534
2534
  function end_default() {
2535
2535
  var on0, on1, that = this, id2 = that._id, size = that.size();
2536
- return new Promise(function(resolve, reject) {
2536
+ return new Promise(function(resolve2, reject) {
2537
2537
  var cancel = { value: reject }, end = { value: function() {
2538
- if (--size === 0) resolve();
2538
+ if (--size === 0) resolve2();
2539
2539
  } };
2540
2540
  that.each(function() {
2541
2541
  var schedule = set2(this, id2), on = schedule.on;
@@ -2547,7 +2547,7 @@ function end_default() {
2547
2547
  }
2548
2548
  schedule.on = on1;
2549
2549
  });
2550
- if (size === 0) resolve();
2550
+ if (size === 0) resolve2();
2551
2551
  });
2552
2552
  }
2553
2553
 
@@ -2749,7 +2749,7 @@ function defaultConstrain(transform2, extent, translateExtent) {
2749
2749
  );
2750
2750
  }
2751
2751
  function zoom_default2() {
2752
- var filter2 = defaultFilter2, extent = defaultExtent, constrain = defaultConstrain, wheelDelta2 = defaultWheelDelta, touchable = defaultTouchable2, scaleExtent = [0, Infinity], translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]], duration = 250, interpolate = zoom_default, listeners2 = dispatch_default("start", "zoom", "end"), touchstarting, touchfirst, touchending, touchDelay = 500, wheelDelay = 150, clickDistance2 = 0, tapDistance = 10;
2752
+ var filter2 = defaultFilter2, extent = defaultExtent, constrain = defaultConstrain, wheelDelta2 = defaultWheelDelta, touchable = defaultTouchable2, scaleExtent = [0, Infinity], translateExtent = [[-Infinity, -Infinity], [Infinity, Infinity]], duration = 250, interpolate2 = zoom_default, listeners2 = dispatch_default("start", "zoom", "end"), touchstarting, touchfirst, touchending, touchDelay = 500, wheelDelay = 150, clickDistance2 = 0, tapDistance = 10;
2753
2753
  function zoom(selection2) {
2754
2754
  selection2.property("__zoom", defaultTransform).on("wheel.zoom", wheeled, { passive: false }).on("mousedown.zoom", mousedowned).on("dblclick.zoom", dblclicked).filter(touchable).on("touchstart.zoom", touchstarted).on("touchmove.zoom", touchmoved).on("touchend.zoom touchcancel.zoom", touchended).style("-webkit-tap-highlight-color", "rgba(0,0,0,0)");
2755
2755
  }
@@ -2810,7 +2810,7 @@ function zoom_default2() {
2810
2810
  }).on("interrupt.zoom end.zoom", function() {
2811
2811
  gesture(this, arguments).event(event).end();
2812
2812
  }).tween("zoom", function() {
2813
- var that = this, args = arguments, g = gesture(that, args).event(event), e = extent.apply(that, args), p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point, w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]), a = that.__zoom, b = typeof transform2 === "function" ? transform2.apply(that, args) : transform2, i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
2813
+ var that = this, args = arguments, g = gesture(that, args).event(event), e = extent.apply(that, args), p = point == null ? centroid(e) : typeof point === "function" ? point.apply(that, args) : point, w = Math.max(e[1][0] - e[0][0], e[1][1] - e[0][1]), a = that.__zoom, b = typeof transform2 === "function" ? transform2.apply(that, args) : transform2, i = interpolate2(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k));
2814
2814
  return function(t) {
2815
2815
  if (t === 1) t = b;
2816
2816
  else {
@@ -3015,7 +3015,7 @@ function zoom_default2() {
3015
3015
  return arguments.length ? (duration = +_, zoom) : duration;
3016
3016
  };
3017
3017
  zoom.interpolate = function(_) {
3018
- return arguments.length ? (interpolate = _, zoom) : interpolate;
3018
+ return arguments.length ? (interpolate2 = _, zoom) : interpolate2;
3019
3019
  };
3020
3020
  zoom.on = function() {
3021
3021
  var value = listeners2.on.apply(listeners2, arguments);
@@ -3508,13 +3508,13 @@ function areSetsEqual(a, b) {
3508
3508
  return true;
3509
3509
  }
3510
3510
  function withResolvers() {
3511
- let resolve;
3511
+ let resolve2;
3512
3512
  let reject;
3513
3513
  const promise = new Promise((res, rej) => {
3514
- resolve = res;
3514
+ resolve2 = res;
3515
3515
  reject = rej;
3516
3516
  });
3517
- return { promise, resolve, reject };
3517
+ return { promise, resolve: resolve2, reject };
3518
3518
  }
3519
3519
  function mergeAriaLabelConfig(partial) {
3520
3520
  return { ...defaultAriaLabelConfig, ...partial || {} };
@@ -5130,8 +5130,8 @@ function XYPanZoom({ domNode, minZoom, maxZoom, translateExtent, viewport, onPan
5130
5130
  d3ZoomInstance.wheelDelta(wheelDelta);
5131
5131
  async function setTransform(transform2, options) {
5132
5132
  if (d3Selection) {
5133
- return new Promise((resolve) => {
5134
- d3ZoomInstance?.interpolate(options?.interpolate === "linear" ? value_default : zoom_default).transform(getD3Transition(d3Selection, options?.duration, options?.ease, () => resolve(true)), transform2);
5133
+ return new Promise((resolve2) => {
5134
+ d3ZoomInstance?.interpolate(options?.interpolate === "linear" ? value_default : zoom_default).transform(getD3Transition(d3Selection, options?.duration, options?.ease, () => resolve2(true)), transform2);
5135
5135
  });
5136
5136
  }
5137
5137
  return false;
@@ -5233,16 +5233,16 @@ function XYPanZoom({ domNode, minZoom, maxZoom, translateExtent, viewport, onPan
5233
5233
  }
5234
5234
  async function scaleTo(zoom, options) {
5235
5235
  if (d3Selection) {
5236
- return new Promise((resolve) => {
5237
- d3ZoomInstance?.interpolate(options?.interpolate === "linear" ? value_default : zoom_default).scaleTo(getD3Transition(d3Selection, options?.duration, options?.ease, () => resolve(true)), zoom);
5236
+ return new Promise((resolve2) => {
5237
+ d3ZoomInstance?.interpolate(options?.interpolate === "linear" ? value_default : zoom_default).scaleTo(getD3Transition(d3Selection, options?.duration, options?.ease, () => resolve2(true)), zoom);
5238
5238
  });
5239
5239
  }
5240
5240
  return false;
5241
5241
  }
5242
5242
  async function scaleBy(factor, options) {
5243
5243
  if (d3Selection) {
5244
- return new Promise((resolve) => {
5245
- d3ZoomInstance?.interpolate(options?.interpolate === "linear" ? value_default : zoom_default).scaleBy(getD3Transition(d3Selection, options?.duration, options?.ease, () => resolve(true)), factor);
5244
+ return new Promise((resolve2) => {
5245
+ d3ZoomInstance?.interpolate(options?.interpolate === "linear" ? value_default : zoom_default).scaleBy(getD3Transition(d3Selection, options?.duration, options?.ease, () => resolve2(true)), factor);
5246
5246
  });
5247
5247
  }
5248
5248
  return false;
@@ -9030,11 +9030,11 @@ function NoteNodeInner(props) {
9030
9030
  const config = data.config ?? {};
9031
9031
  const api = useFlowEditorOptional();
9032
9032
  const hasConfigText = typeof config.text === "string" && config.text.length > 0;
9033
- const text = hasConfigText ? String(config.text) : typeof data.body === "string" ? data.body : typeof data.text === "string" ? data.text : "";
9033
+ const text3 = hasConfigText ? String(config.text) : typeof data.body === "string" ? data.body : typeof data.text === "string" ? data.text : "";
9034
9034
  const title = typeof config.title === "string" && config.title || (!hasConfigText && typeof data.body === "string" && typeof data.label === "string" ? data.label : "");
9035
9035
  const skin = NOTE_COLORS[coerceColor(config.color)];
9036
9036
  const [editing, setEditing] = ReactExports.useState(false);
9037
- const [draft, setDraft] = ReactExports.useState(text);
9037
+ const [draft, setDraft] = ReactExports.useState(text3);
9038
9038
  const areaRef = ReactExports.useRef(null);
9039
9039
  ReactExports.useEffect(() => {
9040
9040
  if (editing && areaRef.current) {
@@ -9045,7 +9045,7 @@ function NoteNodeInner(props) {
9045
9045
  }, [editing]);
9046
9046
  const commit = () => {
9047
9047
  setEditing(false);
9048
- if (!api || draft === text) return;
9048
+ if (!api || draft === text3) return;
9049
9049
  const current = api.nodes.find((n) => n.id === props.id);
9050
9050
  if (!current) return;
9051
9051
  api.updateNode({
@@ -9059,7 +9059,7 @@ function NoteNodeInner(props) {
9059
9059
  className: ["ff-note", props.selected ? "ff-note--selected" : ""].filter(Boolean).join(" "),
9060
9060
  style: { background: skin.bg, borderColor: skin.border },
9061
9061
  onDoubleClick: api ? () => {
9062
- setDraft(text);
9062
+ setDraft(text3);
9063
9063
  setEditing(true);
9064
9064
  } : void 0,
9065
9065
  children: [
@@ -9078,7 +9078,7 @@ function NoteNodeInner(props) {
9078
9078
  if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) commit();
9079
9079
  }
9080
9080
  }
9081
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ff-note__body", children: text || /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ff-note__placeholder", children: api ? "Double-click to write a note\u2026" : "Note" }) })
9081
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ff-note__body", children: text3 || /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ff-note__placeholder", children: api ? "Double-click to write a note\u2026" : "Note" }) })
9082
9082
  ]
9083
9083
  }
9084
9084
  );
@@ -9231,6 +9231,366 @@ var subflowExecutor = async (ctx) => {
9231
9231
  return { __port: "out", value: result.outputs };
9232
9232
  };
9233
9233
 
9234
+ // src/expressions/expr.ts
9235
+ function wholeExpression(trimmed) {
9236
+ if (trimmed.length < 4) return null;
9237
+ if (!trimmed.startsWith("{{") || !trimmed.endsWith("}}")) return null;
9238
+ return trimmed.slice(2, -2);
9239
+ }
9240
+ function interpolate(template, resolve2) {
9241
+ let out = "";
9242
+ let i = 0;
9243
+ for (; ; ) {
9244
+ const open = template.indexOf("{{", i);
9245
+ if (open === -1) return out + template.slice(i);
9246
+ const close = template.indexOf("}}", open + 2);
9247
+ if (close === -1) return out + template.slice(i);
9248
+ out += template.slice(i, open) + resolve2(template.slice(open + 2, close));
9249
+ i = close + 2;
9250
+ }
9251
+ }
9252
+ var FALSY_STRINGS = /* @__PURE__ */ new Set(["", "0", "false", "no", "off", "null"]);
9253
+ var UnresolvedPathError = class extends Error {
9254
+ constructor(path) {
9255
+ super(
9256
+ `Expression path "${path}" did not resolve. Under the "throw" policy an unresolvable path is an error rather than an empty string.`
9257
+ );
9258
+ this.path = path;
9259
+ this.name = "UnresolvedPathError";
9260
+ }
9261
+ };
9262
+ function tryResolvePath(path, context) {
9263
+ const unresolved = { resolved: false, value: null };
9264
+ const trimmed = path.trim();
9265
+ if (trimmed === "") return unresolved;
9266
+ const segments = trimmed.split(".");
9267
+ let cursor;
9268
+ const head = segments[0];
9269
+ if (head === "$json" || head === "$input") {
9270
+ cursor = context !== null && typeof context === "object" && "in" in context ? context.in : context;
9271
+ segments.shift();
9272
+ } else {
9273
+ cursor = context;
9274
+ }
9275
+ for (const segment of segments) {
9276
+ if (cursor === null || cursor === void 0) return unresolved;
9277
+ if (typeof cursor !== "object") return unresolved;
9278
+ const next = cursor[segment];
9279
+ if (next === void 0) return unresolved;
9280
+ cursor = next;
9281
+ }
9282
+ return { resolved: true, value: cursor === void 0 ? null : cursor };
9283
+ }
9284
+ function evaluateExpression(template, context, options = {}) {
9285
+ if (typeof template !== "string") return template;
9286
+ const policy = options.onUnresolved ?? "empty";
9287
+ const whole = wholeExpression(template.trim());
9288
+ if (whole !== null) {
9289
+ const r = tryResolvePath(whole, context);
9290
+ if (r.resolved) return r.value;
9291
+ if (policy === "throw") throw new UnresolvedPathError(whole);
9292
+ return policy === "keep" ? template : null;
9293
+ }
9294
+ return interpolate(template, (path) => {
9295
+ const r = tryResolvePath(path, context);
9296
+ if (r.resolved) return stringify(r.value);
9297
+ if (policy === "throw") throw new UnresolvedPathError(path);
9298
+ return policy === "keep" ? `{{${path}}}` : "";
9299
+ });
9300
+ }
9301
+ function truthy(value) {
9302
+ if (typeof value === "boolean") return value;
9303
+ if (value === null || value === void 0) return false;
9304
+ if (typeof value === "string") return !FALSY_STRINGS.has(value.trim().toLowerCase());
9305
+ if (Array.isArray(value)) return value.length > 0;
9306
+ if (typeof value === "number") return value !== 0;
9307
+ return Boolean(value);
9308
+ }
9309
+ function text(value) {
9310
+ return stringify(value);
9311
+ }
9312
+ function stringify(value) {
9313
+ if (typeof value === "string") return value;
9314
+ if (typeof value === "boolean") return value ? "true" : "false";
9315
+ if (value === null || value === void 0) return "";
9316
+ if (typeof value === "number" || typeof value === "bigint") return String(value);
9317
+ try {
9318
+ return JSON.stringify(value) ?? "";
9319
+ } catch {
9320
+ return "";
9321
+ }
9322
+ }
9323
+
9324
+ // src/registry/logic.ts
9325
+ function configOf(node) {
9326
+ return node?.data?.config ?? {};
9327
+ }
9328
+ function contextOf(inputs) {
9329
+ return inputs;
9330
+ }
9331
+ function resolve(value, inputs) {
9332
+ if (typeof value !== "string") return value;
9333
+ return evaluateExpression(value, contextOf(inputs));
9334
+ }
9335
+ function conditionHolds(row, inputs) {
9336
+ const left = resolve(row.left, inputs);
9337
+ const right = resolve(row.right, inputs);
9338
+ const operator = typeof row.operator === "string" ? row.operator : "eq";
9339
+ const asText = (v) => text(v);
9340
+ const asNumber = (v) => {
9341
+ const n = typeof v === "number" ? v : Number(asText(v));
9342
+ return Number.isFinite(n) ? n : NaN;
9343
+ };
9344
+ const numeric = (fn) => {
9345
+ const a = asNumber(left);
9346
+ const b = asNumber(right);
9347
+ return Number.isFinite(a) && Number.isFinite(b) ? fn(a, b) : false;
9348
+ };
9349
+ const isEmpty = (v) => v === null || v === void 0 || v === "" || Array.isArray(v) && v.length === 0 || typeof v === "object" && !Array.isArray(v) && Object.keys(v).length === 0;
9350
+ switch (operator) {
9351
+ // Compared as TEXT, deliberately. `right` is a text field in the schema, so
9352
+ // `status == "2"` must match the number 2 an upstream node produced —
9353
+ // strict equality there would fail on a difference the author cannot see.
9354
+ case "eq":
9355
+ return asText(left) === asText(right);
9356
+ case "neq":
9357
+ return asText(left) !== asText(right);
9358
+ case "contains":
9359
+ return asText(left).includes(asText(right));
9360
+ case "not_contains":
9361
+ return !asText(left).includes(asText(right));
9362
+ case "gt":
9363
+ return numeric((a, b) => a > b);
9364
+ case "gte":
9365
+ return numeric((a, b) => a >= b);
9366
+ case "lt":
9367
+ return numeric((a, b) => a < b);
9368
+ case "lte":
9369
+ return numeric((a, b) => a <= b);
9370
+ case "truthy":
9371
+ return truthy(left);
9372
+ case "falsy":
9373
+ return !truthy(left);
9374
+ case "empty":
9375
+ return isEmpty(left);
9376
+ case "not_empty":
9377
+ return !isEmpty(left);
9378
+ default:
9379
+ return false;
9380
+ }
9381
+ }
9382
+ var branchExecutor = (ctx) => {
9383
+ const config = configOf(ctx.node);
9384
+ const inputs = ctx.inputs;
9385
+ let taken;
9386
+ const raw = config.condition;
9387
+ if (typeof raw === "string" && raw.trim() !== "") {
9388
+ taken = truthy(resolve(raw, inputs));
9389
+ } else {
9390
+ const rows = Array.isArray(config.conditions) ? config.conditions : [];
9391
+ if (rows.length === 0) {
9392
+ taken = false;
9393
+ } else {
9394
+ const results = rows.map((row) => conditionHolds(row, inputs));
9395
+ taken = config.match === "any" ? results.some(Boolean) : results.every(Boolean);
9396
+ }
9397
+ }
9398
+ return { __port: taken ? "true" : "false", value: ctx.inputs.in ?? ctx.inputs };
9399
+ };
9400
+ var transformExecutor = (ctx) => {
9401
+ const config = configOf(ctx.node);
9402
+ const inputs = ctx.inputs;
9403
+ const passthrough = ctx.inputs.in ?? ctx.inputs;
9404
+ if (config.mode === "expression") {
9405
+ const expression = config.expression;
9406
+ if (typeof expression !== "string" || expression.trim() === "") return passthrough;
9407
+ return resolve(expression, inputs);
9408
+ }
9409
+ const rows = Array.isArray(config.fields) ? config.fields : [];
9410
+ if (rows.length === 0) return passthrough;
9411
+ const out = {};
9412
+ let wrote = false;
9413
+ for (const row of rows) {
9414
+ const key = typeof row.key === "string" ? row.key.trim() : "";
9415
+ if (key === "") continue;
9416
+ out[key] = resolve(row.value, inputs);
9417
+ wrote = true;
9418
+ }
9419
+ return wrote ? out : passthrough;
9420
+ };
9421
+ var mergeExecutor = (ctx) => {
9422
+ const entries = Object.entries(ctx.inputs);
9423
+ if (configOf(ctx.node).mode === "concat") {
9424
+ const out = [];
9425
+ for (const [, value] of entries) {
9426
+ if (value === null || value === void 0) continue;
9427
+ if (Array.isArray(value)) out.push(...value);
9428
+ else out.push(value);
9429
+ }
9430
+ return out;
9431
+ }
9432
+ const merged = {};
9433
+ for (const [port, value] of entries) {
9434
+ if (value === null || value === void 0) continue;
9435
+ if (typeof value === "object" && !Array.isArray(value)) Object.assign(merged, value);
9436
+ else merged[port] = value;
9437
+ }
9438
+ return merged;
9439
+ };
9440
+ var forEachExecutor = (ctx) => {
9441
+ const source = resolve(configOf(ctx.node).source, ctx.inputs);
9442
+ let items;
9443
+ if (Array.isArray(source)) items = source;
9444
+ else if (source === null || source === void 0) items = [];
9445
+ else if (typeof source === "object") items = Object.values(source);
9446
+ else items = [source];
9447
+ return { items, count: items.length };
9448
+ };
9449
+
9450
+ // src/registry/terminal-nodes.ts
9451
+ var DEFAULT_TIMEOUT_MS = 12e4;
9452
+ var ENTER = "\r";
9453
+ function configOf2(node) {
9454
+ return node?.data?.config ?? {};
9455
+ }
9456
+ function text2(config, key) {
9457
+ const value = config[key];
9458
+ return typeof value === "string" ? value : "";
9459
+ }
9460
+ function millis(config, key, fallback) {
9461
+ const value = Number(config[key]);
9462
+ return Number.isFinite(value) && value >= 0 ? value : fallback;
9463
+ }
9464
+ function exitMarker(nonce) {
9465
+ const token = `__fancy_flow_exit_${nonce}__`;
9466
+ return {
9467
+ token,
9468
+ // The expanded status is required to be digits. The shell ECHOES the typed
9469
+ // command back first, and that echo contains the marker with `$?`
9470
+ // unexpanded — so requiring digits is what stops the node matching its own
9471
+ // command line and reporting success before anything has run.
9472
+ pattern: new RegExp(`${token}:(\\d+)`)
9473
+ };
9474
+ }
9475
+ var counter = 0;
9476
+ function newNonce() {
9477
+ counter += 1;
9478
+ return `${Date.now().toString(36)}${counter.toString(36)}${Math.random().toString(36).slice(2, 8)}`;
9479
+ }
9480
+ function withoutMarker(output, token) {
9481
+ return output.split("\n").filter((line) => !line.includes(token)).join("\n").trim();
9482
+ }
9483
+ function fail(ctx, message) {
9484
+ ctx.abort(message);
9485
+ throw new Error(message);
9486
+ }
9487
+ function requireTerminal(ctx) {
9488
+ if (!ctx.terminal) {
9489
+ fail(
9490
+ ctx,
9491
+ `"${String(ctx.node.data?.label ?? ctx.node.id)}" is a terminal node but is not inside a terminal lane. Drag it into one \u2014 a terminal node outside a lane has no session to talk to, and opening a private shell for it would defeat the point of the lane.`
9492
+ );
9493
+ }
9494
+ return ctx.terminal;
9495
+ }
9496
+ function compilePattern(ctx, raw, config) {
9497
+ const flags = typeof config.flags === "string" ? config.flags.replace(/[gy]/g, "") : "";
9498
+ try {
9499
+ return config.mode === "regex" ? new RegExp(raw, flags) : new RegExp(raw.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), flags);
9500
+ } catch (e) {
9501
+ return fail(ctx, `terminal_await has an invalid regex: ${e instanceof Error ? e.message : String(e)}`);
9502
+ }
9503
+ }
9504
+ var terminalRunExecutor = async (ctx) => {
9505
+ const config = configOf2(ctx.node);
9506
+ const command = text2(config, "command").trim();
9507
+ if (!command) fail(ctx, "terminal_run has no command configured");
9508
+ const terminal = requireTerminal(ctx);
9509
+ const session = await terminal.session();
9510
+ const transcript = await terminal.transcript();
9511
+ const { token, pattern } = exitMarker(newNonce());
9512
+ const timeoutMs = millis(config, "timeoutMs", DEFAULT_TIMEOUT_MS);
9513
+ transcript.clear();
9514
+ await session.write(`${command}; printf '${token}:%s\\n' "$?"${ENTER}`);
9515
+ const result = await transcript.waitFor(pattern, { timeoutMs, exited: session.exited });
9516
+ if (result.status === "exited") {
9517
+ fail(
9518
+ ctx,
9519
+ `The terminal exited (code ${result.exitCode}${result.signal ? `, signal ${result.signal}` : ""}) while running "${command}". The lane's session is gone, so every later node in this lane would fail too.`
9520
+ );
9521
+ }
9522
+ if (result.status === "timeout") {
9523
+ fail(
9524
+ ctx,
9525
+ `"${command}" did not finish within ${timeoutMs}ms. Raise the node's timeout if it is genuinely slow \u2014 but a command that waits for input never finishes at all, and needs terminal_send + terminal_await.`
9526
+ );
9527
+ }
9528
+ const exitCode = Number(result.match[1]);
9529
+ const output = withoutMarker(result.text, token);
9530
+ const failOnNonZero = config.failOnNonZero !== false;
9531
+ if (failOnNonZero && exitCode !== 0) {
9532
+ ctx.abort(`"${command}" exited ${exitCode}.
9533
+ ${output}`);
9534
+ }
9535
+ return { output, exitCode, command };
9536
+ };
9537
+ var terminalSendExecutor = async (ctx) => {
9538
+ const config = configOf2(ctx.node);
9539
+ const terminal = requireTerminal(ctx);
9540
+ const session = await terminal.session();
9541
+ const body = text2(config, "text");
9542
+ const submit = config.submit !== false;
9543
+ if (config.clearFirst === true) {
9544
+ (await terminal.transcript()).clear();
9545
+ }
9546
+ await session.write(submit ? `${body}${ENTER}` : body);
9547
+ return { sent: body, submitted: submit };
9548
+ };
9549
+ var terminalAwaitExecutor = async (ctx) => {
9550
+ const config = configOf2(ctx.node);
9551
+ const terminal = requireTerminal(ctx);
9552
+ const session = await terminal.session();
9553
+ const transcript = await terminal.transcript();
9554
+ const raw = text2(config, "pattern").trim();
9555
+ if (!raw) fail(ctx, "terminal_await has no pattern configured \u2014 there is nothing for it to wait for");
9556
+ const pattern = compilePattern(ctx, raw, config);
9557
+ const timeoutMs = millis(config, "timeoutMs", DEFAULT_TIMEOUT_MS);
9558
+ const result = await transcript.waitFor(pattern, {
9559
+ timeoutMs,
9560
+ exited: session.exited
9561
+ });
9562
+ if (result.status === "exited") {
9563
+ fail(
9564
+ ctx,
9565
+ `The terminal exited (code ${result.exitCode}${result.signal ? `, signal ${result.signal}` : ""}) while waiting for ${JSON.stringify(raw)}. It never appeared, and the lane's session is gone.`
9566
+ );
9567
+ }
9568
+ if (result.status === "timeout") {
9569
+ if (config.onTimeout === "continue") {
9570
+ ctx.emit({
9571
+ type: "log",
9572
+ nodeId: ctx.node.id,
9573
+ level: "warn",
9574
+ message: `terminal_await: ${JSON.stringify(raw)} did not appear within ${timeoutMs}ms; continuing as configured.`
9575
+ });
9576
+ return { matched: false, output: result.text, groups: [] };
9577
+ }
9578
+ fail(
9579
+ ctx,
9580
+ `${JSON.stringify(raw)} did not appear within ${timeoutMs}ms. Last output:
9581
+ ${result.text.slice(-2e3)}`
9582
+ );
9583
+ }
9584
+ return {
9585
+ matched: true,
9586
+ output: result.text,
9587
+ matchedText: result.match[0],
9588
+ // Capture groups are the reason to use regex mode at all — a prompt that
9589
+ // reports a session id or a file path is only useful if the value comes out.
9590
+ groups: result.match.slice(1)
9591
+ };
9592
+ };
9593
+
9234
9594
  // src/registry/builtin.ts
9235
9595
  var HUMAN_FIELD_OUTPUT_TYPE = {
9236
9596
  text: "string",
@@ -9520,6 +9880,9 @@ var KINDS = [
9520
9880
  // returns its input on the chosen port
9521
9881
  emits: "input",
9522
9882
  aliases: ["branch", "@fancy/branch"],
9883
+ // Pure logic: no I/O to choose, so a default is safe. A host
9884
+ // executor still wins -- pickExecutor consults the registry first.
9885
+ executor: branchExecutor,
9523
9886
  category: "logic",
9524
9887
  label: "Branch",
9525
9888
  description: "Multi-way branch on a condition or value.",
@@ -9617,6 +9980,9 @@ var KINDS = [
9617
9980
  { path: "count", type: "number" }
9618
9981
  ],
9619
9982
  aliases: ["for_each", "@fancy/for_each"],
9983
+ // Pure logic: no I/O to choose, so a default is safe. A host
9984
+ // executor still wins -- pickExecutor consults the registry first.
9985
+ executor: forEachExecutor,
9620
9986
  category: "logic",
9621
9987
  label: "For Each",
9622
9988
  description: "Iterate over a list, emitting each item on `item`.",
@@ -9637,6 +10003,9 @@ var KINDS = [
9637
10003
  // reference.
9638
10004
  emits: (config) => (config?.mode ?? "merge") === "concat" ? null : "inputs-merged",
9639
10005
  aliases: ["merge", "@fancy/merge"],
10006
+ // Pure logic: no I/O to choose, so a default is safe. A host
10007
+ // executor still wins -- pickExecutor consults the registry first.
10008
+ executor: mergeExecutor,
9640
10009
  category: "logic",
9641
10010
  label: "Merge",
9642
10011
  description: "Combine multiple inputs into one object or array.",
@@ -9682,6 +10051,9 @@ var KINDS = [
9682
10051
  // else the shape that expression names. So the RELATION is config-dependent.
9683
10052
  emits: (config) => (config?.expression ?? "") === "" ? "input" : "expression:expression",
9684
10053
  aliases: ["transform", "@fancy/transform"],
10054
+ // Pure logic: no I/O to choose, so a default is safe. A host
10055
+ // executor still wins -- pickExecutor consults the registry first.
10056
+ executor: transformExecutor,
9685
10057
  category: "logic",
9686
10058
  label: "Transform",
9687
10059
  description: "Reshape data with an expression.",
@@ -10140,6 +10512,179 @@ var KINDS = [
10140
10512
  resizable: { minWidth: 160, minHeight: 72 },
10141
10513
  component: LaneNode
10142
10514
  },
10515
+ {
10516
+ // Terminal lane — a lane that OWNS a terminal for the length of the run.
10517
+ //
10518
+ // Visually a swimlane, and `layout` for the same reason the plain lane is:
10519
+ // a lane is not a step, so it never executes and never appears in topo
10520
+ // order. What is new is that it DECLARES a resource. The runtime opens its
10521
+ // terminal lazily, when the first terminal node inside it runs, and closes
10522
+ // it in the run's `finally` — so a graph that never reaches a terminal node
10523
+ // never spawns a process, and one that does gets exactly one session no
10524
+ // matter how many nodes use it.
10525
+ //
10526
+ // Membership is `parentId`, which already persists into the WorkflowSchema.
10527
+ // That is what lets a headless runtime resolve the same grouping the canvas
10528
+ // shows, without a second association to keep in sync.
10529
+ name: "@particle-academy/terminal_lane",
10530
+ aliases: ["terminal_lane", "@fancy/terminal_lane"],
10531
+ category: "layout",
10532
+ label: "Terminal lane",
10533
+ description: "A lane that owns one terminal. Opens at the first terminal node, closes when the run ends.",
10534
+ icon: "\u25A3",
10535
+ inputs: [],
10536
+ outputs: [],
10537
+ configSchema: [
10538
+ { type: "text", key: "title", label: "Title", default: "Terminal" },
10539
+ {
10540
+ type: "text",
10541
+ key: "command",
10542
+ label: "Command",
10543
+ placeholder: "Leave empty for the default shell"
10544
+ },
10545
+ { type: "text", key: "cwd", label: "Working directory", placeholder: "Host default" },
10546
+ { type: "keyvalue", key: "env", label: "Environment" },
10547
+ {
10548
+ type: "select",
10549
+ key: "orientation",
10550
+ label: "Orientation",
10551
+ default: "horizontal",
10552
+ options: [
10553
+ { value: "horizontal", label: "Row" },
10554
+ { value: "vertical", label: "Column" }
10555
+ ]
10556
+ }
10557
+ ],
10558
+ defaultConfig: { title: "Terminal", orientation: "horizontal" },
10559
+ resizable: { minWidth: 220, minHeight: 120 },
10560
+ component: LaneNode
10561
+ },
10562
+ {
10563
+ // Terminal nodes. All three live inside a terminal lane and talk to the
10564
+ // session that lane owns; outside one they abort by name rather than
10565
+ // opening a shell of their own.
10566
+ name: "@particle-academy/terminal_run",
10567
+ aliases: ["terminal_run", "@fancy/terminal_run"],
10568
+ category: "io",
10569
+ label: "Run in terminal",
10570
+ description: "Run a shell command in the lane's terminal and wait for its exit code.",
10571
+ icon: "$",
10572
+ inputs: [{ id: "in" }],
10573
+ outputs: [{ id: "out", label: "output" }],
10574
+ executor: terminalRunExecutor,
10575
+ configSchema: [
10576
+ {
10577
+ type: "textarea",
10578
+ key: "command",
10579
+ label: "Command",
10580
+ rows: 3,
10581
+ required: true,
10582
+ placeholder: "npm test",
10583
+ description: "Runs in the lane's shell, so `cd` and exported variables persist between nodes. SHELL ONLY \u2014 a TUI never returns to a prompt, so use Send + Await for one."
10584
+ },
10585
+ {
10586
+ type: "number",
10587
+ key: "timeoutMs",
10588
+ label: "Timeout (ms)",
10589
+ default: 12e4,
10590
+ description: "How long to wait for the command to finish before failing the run."
10591
+ },
10592
+ {
10593
+ type: "switch",
10594
+ key: "failOnNonZero",
10595
+ label: "Fail the run on a non-zero exit",
10596
+ default: true,
10597
+ description: "On by default. Turning it off means a failed command lets the run report success \u2014 read the exit code on the output port and branch on it instead."
10598
+ }
10599
+ ],
10600
+ defaultConfig: { command: "", timeoutMs: 12e4, failOnNonZero: true }
10601
+ },
10602
+ {
10603
+ name: "@particle-academy/terminal_send",
10604
+ aliases: ["terminal_send", "@fancy/terminal_send"],
10605
+ category: "io",
10606
+ label: "Send to terminal",
10607
+ description: "Type text at whatever is running in the lane's terminal, without waiting.",
10608
+ icon: "\u2328",
10609
+ inputs: [{ id: "in" }],
10610
+ outputs: [{ id: "out", label: "sent" }],
10611
+ executor: terminalSendExecutor,
10612
+ configSchema: [
10613
+ {
10614
+ type: "textarea",
10615
+ key: "text",
10616
+ label: "Text",
10617
+ rows: 4,
10618
+ placeholder: "Summarise the failing test and propose a fix.",
10619
+ description: "What to type. This is how a graph prompts an agent TUI such as Claude Code or Codex."
10620
+ },
10621
+ {
10622
+ type: "switch",
10623
+ key: "submit",
10624
+ label: "Press Enter",
10625
+ default: true,
10626
+ description: "Off leaves the text on the input line \u2014 useful for building one up across several nodes."
10627
+ },
10628
+ {
10629
+ type: "switch",
10630
+ key: "clearFirst",
10631
+ label: "Forget earlier output first",
10632
+ default: false,
10633
+ description: "Discards anything the terminal said before this send, so a following Await cannot match a prompt left over from the previous exchange."
10634
+ }
10635
+ ],
10636
+ defaultConfig: { text: "", submit: true, clearFirst: false }
10637
+ },
10638
+ {
10639
+ name: "@particle-academy/terminal_await",
10640
+ aliases: ["terminal_await", "@fancy/terminal_await"],
10641
+ category: "io",
10642
+ label: "Await terminal output",
10643
+ description: "Wait until the lane's terminal prints something that matches.",
10644
+ icon: "\u23F1",
10645
+ inputs: [{ id: "in" }],
10646
+ outputs: [{ id: "out", label: "output" }],
10647
+ executor: terminalAwaitExecutor,
10648
+ configSchema: [
10649
+ {
10650
+ type: "text",
10651
+ key: "pattern",
10652
+ label: "Wait for",
10653
+ required: true,
10654
+ placeholder: "esc to interrupt",
10655
+ description: "Matched against the output with colour codes already stripped, so match what you SEE."
10656
+ },
10657
+ {
10658
+ type: "select",
10659
+ key: "mode",
10660
+ label: "Match as",
10661
+ default: "text",
10662
+ options: [
10663
+ { value: "text", label: "Plain text" },
10664
+ { value: "regex", label: "Regular expression" }
10665
+ ],
10666
+ description: "Regex mode also returns capture groups, which is how a value gets out of a prompt."
10667
+ },
10668
+ {
10669
+ type: "number",
10670
+ key: "timeoutMs",
10671
+ label: "Timeout (ms)",
10672
+ default: 12e4
10673
+ },
10674
+ {
10675
+ type: "select",
10676
+ key: "onTimeout",
10677
+ label: "If it never appears",
10678
+ default: "fail",
10679
+ options: [
10680
+ { value: "fail", label: "Fail the run" },
10681
+ { value: "continue", label: "Continue with matched: false" }
10682
+ ],
10683
+ description: "Failing is the default. Continuing lets the next node type at a process that never became ready while the run still reports success, so it has to be asked for."
10684
+ }
10685
+ ],
10686
+ defaultConfig: { pattern: "", mode: "text", timeoutMs: 12e4, onTimeout: "fail" }
10687
+ },
10143
10688
  {
10144
10689
  // Note — a sticky-note annotation. Portless + visual-only: the runtime skips
10145
10690
  // the `annotation` category, so a note's text NEVER reaches a runner — it
@@ -10379,6 +10924,239 @@ var RunIdentity = class _RunIdentity {
10379
10924
  }
10380
10925
  };
10381
10926
 
10927
+ // src/runtime/terminal-transcript.ts
10928
+ var ESC = String.fromCharCode(27);
10929
+ var CSI = String.fromCharCode(155);
10930
+ var BEL = String.fromCharCode(7);
10931
+ var ANSI = new RegExp(
10932
+ `[${ESC}${CSI}](?:\\[[0-?]*[ -/]*[@-~]|\\][^${BEL}${ESC}]*(?:${BEL}|${ESC}\\\\)|[@-Z\\\\-_])`,
10933
+ "g"
10934
+ );
10935
+ var MAX_PENDING_ESCAPE = 1024;
10936
+ var MAX_BUFFER = 1e6;
10937
+ var TerminalTranscript = class {
10938
+ constructor() {
10939
+ /** Stripped, complete text not yet consumed by a wait. */
10940
+ this.text = "";
10941
+ /** Raw bytes held back because they may be the start of an escape sequence. */
10942
+ this.tail = "";
10943
+ this.waiters = /* @__PURE__ */ new Set();
10944
+ }
10945
+ /** Feed raw terminal output in. Safe to call with any chunking. */
10946
+ append(chunk) {
10947
+ this.tail += chunk;
10948
+ const safe = this.safeLength();
10949
+ if (safe > 0) {
10950
+ this.text += this.tail.slice(0, safe).replace(ANSI, "");
10951
+ this.tail = this.tail.slice(safe);
10952
+ }
10953
+ if (this.text.length > MAX_BUFFER) {
10954
+ this.text = this.text.slice(this.text.length - MAX_BUFFER);
10955
+ }
10956
+ for (const wake2 of [...this.waiters]) wake2();
10957
+ }
10958
+ /**
10959
+ * How much of `tail` can be stripped now.
10960
+ *
10961
+ * Everything, unless the final `ESC` has not yet been terminated — in which
10962
+ * case processing stops there and resumes when the rest arrives.
10963
+ */
10964
+ safeLength() {
10965
+ const lastEsc = Math.max(this.tail.lastIndexOf(ESC), this.tail.lastIndexOf(CSI));
10966
+ if (lastEsc === -1) return this.tail.length;
10967
+ ANSI.lastIndex = lastEsc;
10968
+ const match = ANSI.exec(this.tail);
10969
+ ANSI.lastIndex = 0;
10970
+ if (match && match.index === lastEsc) return this.tail.length;
10971
+ if (this.tail.length - lastEsc > MAX_PENDING_ESCAPE) return this.tail.length;
10972
+ return lastEsc;
10973
+ }
10974
+ /** Unconsumed output, escape sequences removed. */
10975
+ peek() {
10976
+ return this.text;
10977
+ }
10978
+ /** Drop everything currently buffered — used before typing a new command. */
10979
+ clear() {
10980
+ this.text = "";
10981
+ this.tail = "";
10982
+ }
10983
+ /**
10984
+ * Wait until `pattern` matches the unconsumed text.
10985
+ *
10986
+ * Checks what has ALREADY arrived before subscribing, because the common case
10987
+ * is that the process answered while the previous node was still finishing.
10988
+ *
10989
+ * `exited` is raced deliberately. Without it, a shell that dies reports as
10990
+ * "timed out waiting for X" — sending whoever reads it to lengthen a timeout
10991
+ * for a process that is not running. Naming the exit is the difference
10992
+ * between a diagnosis and a wrong lead.
10993
+ */
10994
+ waitFor(pattern, options) {
10995
+ return new Promise((resolve2) => {
10996
+ let settled = false;
10997
+ let timer2;
10998
+ const finish = (result) => {
10999
+ if (settled) return;
11000
+ settled = true;
11001
+ this.waiters.delete(check);
11002
+ if (timer2) clearTimeout(timer2);
11003
+ resolve2(result);
11004
+ };
11005
+ const check = () => {
11006
+ pattern.lastIndex = 0;
11007
+ const match = pattern.exec(this.text);
11008
+ if (!match) return;
11009
+ const through = match.index + (match[0].length || 1);
11010
+ const text3 = this.text.slice(0, through);
11011
+ this.text = this.text.slice(through);
11012
+ finish({ status: "matched", text: text3, match });
11013
+ };
11014
+ this.waiters.add(check);
11015
+ check();
11016
+ if (settled) return;
11017
+ if (options.timeoutMs > 0) {
11018
+ timer2 = setTimeout(() => {
11019
+ const text3 = this.text;
11020
+ this.text = "";
11021
+ finish({ status: "timeout", text: text3 });
11022
+ }, options.timeoutMs);
11023
+ timer2.unref?.();
11024
+ }
11025
+ options.exited?.then(
11026
+ (exit) => {
11027
+ if (settled) return;
11028
+ const text3 = this.text;
11029
+ this.text = "";
11030
+ finish({ status: "exited", text: text3, exitCode: exit.exitCode, signal: exit.signal });
11031
+ },
11032
+ () => {
11033
+ }
11034
+ );
11035
+ });
11036
+ }
11037
+ };
11038
+
11039
+ // src/runtime/terminal-sessions.ts
11040
+ var TerminalSessions = class {
11041
+ constructor(graph) {
11042
+ this.graph = graph;
11043
+ this.open = /* @__PURE__ */ new Map();
11044
+ this.laneOf = /* @__PURE__ */ new Map();
11045
+ this.transcripts = /* @__PURE__ */ new Map();
11046
+ this.listening = /* @__PURE__ */ new Map();
11047
+ }
11048
+ /**
11049
+ * The terminal lane a node belongs to, or null.
11050
+ *
11051
+ * Walks up `parentId` rather than checking only the immediate parent, and
11052
+ * caches per node id — a graph is walked once per run, and the answer cannot
11053
+ * change while it runs.
11054
+ */
11055
+ laneFor(nodeId, isTerminalLane) {
11056
+ const cached = this.laneOf.get(nodeId);
11057
+ if (cached !== void 0) return cached;
11058
+ const byId = new Map(this.graph.nodes.map((n) => [n.id, n]));
11059
+ const seen = /* @__PURE__ */ new Set();
11060
+ let current = byId.get(nodeId);
11061
+ let answer = null;
11062
+ while (current) {
11063
+ if (seen.has(current.id)) break;
11064
+ seen.add(current.id);
11065
+ if (current.id !== nodeId && isTerminalLane(current)) {
11066
+ answer = current.id;
11067
+ break;
11068
+ }
11069
+ const parentId = current.parentId;
11070
+ current = parentId ? byId.get(parentId) : void 0;
11071
+ }
11072
+ this.laneOf.set(nodeId, answer);
11073
+ return answer;
11074
+ }
11075
+ /**
11076
+ * The session for a lane, opening it on first use.
11077
+ *
11078
+ * The PROMISE is cached, not the resolved session. Two nodes cannot run
11079
+ * concurrently in the current engine, but a caller that awaits a
11080
+ * half-finished open would otherwise start a second process — and two shells
11081
+ * where a graph says one is the failure this class exists to prevent, arriving
11082
+ * only under concurrency and therefore only sometimes.
11083
+ */
11084
+ session(laneId, spec) {
11085
+ const existing = this.open.get(laneId);
11086
+ if (existing) return existing;
11087
+ {
11088
+ const failed = Promise.reject(
11089
+ new Error(
11090
+ "No terminal host is registered. A terminal lane needs one \u2014 call registerTerminalHost() from the desktop app, or install @particle-academy/fancy-flow/terminal/fancy-term-host."
11091
+ )
11092
+ );
11093
+ this.open.set(laneId, failed);
11094
+ failed.catch(() => {
11095
+ });
11096
+ return failed;
11097
+ }
11098
+ }
11099
+ /**
11100
+ * The accumulated output for a lane.
11101
+ *
11102
+ * Created on demand and kept for the run, so it exists before the session
11103
+ * resolves and survives every node that reads it. Consuming is the reader's
11104
+ * job — see `TerminalTranscript.waitFor`.
11105
+ */
11106
+ transcriptFor(laneId) {
11107
+ const existing = this.transcripts.get(laneId);
11108
+ if (existing) return existing;
11109
+ const created = new TerminalTranscript();
11110
+ this.transcripts.set(laneId, created);
11111
+ return created;
11112
+ }
11113
+ /** True once a lane has a session — used to avoid opening one during teardown. */
11114
+ isOpen(laneId) {
11115
+ return this.open.has(laneId);
11116
+ }
11117
+ /**
11118
+ * Close every session this run opened.
11119
+ *
11120
+ * Every close is attempted even if one throws: a host that fails to close one
11121
+ * PTY must not strand the others, which would leave processes alive after the
11122
+ * run reported that it had finished. Errors are returned rather than thrown,
11123
+ * because teardown runs in a `finally` and throwing there would replace the
11124
+ * run's real error with a cleanup error.
11125
+ */
11126
+ async closeAll() {
11127
+ const errors = [];
11128
+ for (const [laneId, pending] of this.open) {
11129
+ try {
11130
+ this.listening.get(laneId)?.();
11131
+ this.listening.delete(laneId);
11132
+ const session = await pending;
11133
+ await session.close();
11134
+ } catch (e) {
11135
+ errors.push(e instanceof Error ? e : new Error(`${laneId}: ${String(e)}`));
11136
+ }
11137
+ }
11138
+ this.open.clear();
11139
+ this.listening.clear();
11140
+ this.transcripts.clear();
11141
+ return errors;
11142
+ }
11143
+ };
11144
+ function specForLane(lane) {
11145
+ const config = lane.data?.config ?? {};
11146
+ const text3 = (key) => {
11147
+ const value = config[key];
11148
+ return typeof value === "string" && value !== "" ? value : void 0;
11149
+ };
11150
+ const env = config.env;
11151
+ return {
11152
+ command: text3("command"),
11153
+ cwd: text3("cwd"),
11154
+ env: env && typeof env === "object" && !Array.isArray(env) ? Object.fromEntries(
11155
+ Object.entries(env).map(([k, v]) => [k, String(v)])
11156
+ ) : void 0
11157
+ };
11158
+ }
11159
+
10382
11160
  // src/runtime/workflow-props.ts
10383
11161
  function typeOf(value) {
10384
11162
  if (value === null) return "null";
@@ -10457,6 +11235,25 @@ async function runFlow(graph, executors, onEvent = () => {
10457
11235
  const props = propsCheck.props;
10458
11236
  const declaresProps = (graph.inputs?.length ?? 0) > 0;
10459
11237
  const incomingByNode = indexIncoming(graph.edges);
11238
+ const sessions = new TerminalSessions(graph);
11239
+ const isTerminalLane = (candidate) => getNodeKind(candidate.type ?? "")?.name === "@particle-academy/terminal_lane";
11240
+ const terminalAccessorFor = (node) => {
11241
+ const laneId = sessions.laneFor(node.id, isTerminalLane);
11242
+ if (laneId === null) return void 0;
11243
+ const lane = graph.nodes.find((n) => n.id === laneId);
11244
+ if (!lane) return void 0;
11245
+ return {
11246
+ session: () => sessions.session(laneId, specForLane(lane)),
11247
+ // Awaits the session first on purpose. A transcript handed out before
11248
+ // anything is feeding it would look perfectly healthy and match nothing,
11249
+ // and "waited and nothing came" is the hardest failure here to tell apart
11250
+ // from a process that is simply slow.
11251
+ transcript: async () => {
11252
+ await sessions.session(laneId, specForLane(lane));
11253
+ return sessions.transcriptFor(laneId);
11254
+ }
11255
+ };
11256
+ };
10460
11257
  const timer2 = timeoutMs ? setTimeout(() => errors.push(`Run timed out after ${timeoutMs}ms`), timeoutMs) : null;
10461
11258
  onEvent({ type: "run-start" });
10462
11259
  try {
@@ -10522,7 +11319,8 @@ async function runFlow(graph, executors, onEvent = () => {
10522
11319
  emit: onEvent,
10523
11320
  executors,
10524
11321
  depth,
10525
- run
11322
+ run,
11323
+ terminal: terminalAccessorFor(node)
10526
11324
  })
10527
11325
  );
10528
11326
  outputs[node.id] = result;
@@ -10544,6 +11342,9 @@ async function runFlow(graph, executors, onEvent = () => {
10544
11342
  }
10545
11343
  } finally {
10546
11344
  if (timer2) clearTimeout(timer2);
11345
+ for (const error of await sessions.closeAll()) {
11346
+ onEvent({ type: "log", level: "warn", message: `terminal close failed: ${error.message}` });
11347
+ }
10547
11348
  }
10548
11349
  const ok = errors.length === 0;
10549
11350
  onEvent({ type: "run-end", ok });
@@ -10622,7 +11423,7 @@ function pickExecutor(executors, node) {
10622
11423
  for (const id2 of executorLookupIds(node)) {
10623
11424
  if (executors[id2]) return executors[id2];
10624
11425
  }
10625
- return void 0;
11426
+ return getNodeKind(node.type ?? "")?.executor;
10626
11427
  }
10627
11428
  function activatedPorts(node, result) {
10628
11429
  if (result && typeof result === "object") {