@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/schema.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
  );
@@ -9279,6 +9279,239 @@ var RunIdentity = class _RunIdentity {
9279
9279
  }
9280
9280
  };
9281
9281
 
9282
+ // src/runtime/terminal-transcript.ts
9283
+ var ESC = String.fromCharCode(27);
9284
+ var CSI = String.fromCharCode(155);
9285
+ var BEL = String.fromCharCode(7);
9286
+ var ANSI = new RegExp(
9287
+ `[${ESC}${CSI}](?:\\[[0-?]*[ -/]*[@-~]|\\][^${BEL}${ESC}]*(?:${BEL}|${ESC}\\\\)|[@-Z\\\\-_])`,
9288
+ "g"
9289
+ );
9290
+ var MAX_PENDING_ESCAPE = 1024;
9291
+ var MAX_BUFFER = 1e6;
9292
+ var TerminalTranscript = class {
9293
+ constructor() {
9294
+ /** Stripped, complete text not yet consumed by a wait. */
9295
+ this.text = "";
9296
+ /** Raw bytes held back because they may be the start of an escape sequence. */
9297
+ this.tail = "";
9298
+ this.waiters = /* @__PURE__ */ new Set();
9299
+ }
9300
+ /** Feed raw terminal output in. Safe to call with any chunking. */
9301
+ append(chunk) {
9302
+ this.tail += chunk;
9303
+ const safe = this.safeLength();
9304
+ if (safe > 0) {
9305
+ this.text += this.tail.slice(0, safe).replace(ANSI, "");
9306
+ this.tail = this.tail.slice(safe);
9307
+ }
9308
+ if (this.text.length > MAX_BUFFER) {
9309
+ this.text = this.text.slice(this.text.length - MAX_BUFFER);
9310
+ }
9311
+ for (const wake2 of [...this.waiters]) wake2();
9312
+ }
9313
+ /**
9314
+ * How much of `tail` can be stripped now.
9315
+ *
9316
+ * Everything, unless the final `ESC` has not yet been terminated — in which
9317
+ * case processing stops there and resumes when the rest arrives.
9318
+ */
9319
+ safeLength() {
9320
+ const lastEsc = Math.max(this.tail.lastIndexOf(ESC), this.tail.lastIndexOf(CSI));
9321
+ if (lastEsc === -1) return this.tail.length;
9322
+ ANSI.lastIndex = lastEsc;
9323
+ const match = ANSI.exec(this.tail);
9324
+ ANSI.lastIndex = 0;
9325
+ if (match && match.index === lastEsc) return this.tail.length;
9326
+ if (this.tail.length - lastEsc > MAX_PENDING_ESCAPE) return this.tail.length;
9327
+ return lastEsc;
9328
+ }
9329
+ /** Unconsumed output, escape sequences removed. */
9330
+ peek() {
9331
+ return this.text;
9332
+ }
9333
+ /** Drop everything currently buffered — used before typing a new command. */
9334
+ clear() {
9335
+ this.text = "";
9336
+ this.tail = "";
9337
+ }
9338
+ /**
9339
+ * Wait until `pattern` matches the unconsumed text.
9340
+ *
9341
+ * Checks what has ALREADY arrived before subscribing, because the common case
9342
+ * is that the process answered while the previous node was still finishing.
9343
+ *
9344
+ * `exited` is raced deliberately. Without it, a shell that dies reports as
9345
+ * "timed out waiting for X" — sending whoever reads it to lengthen a timeout
9346
+ * for a process that is not running. Naming the exit is the difference
9347
+ * between a diagnosis and a wrong lead.
9348
+ */
9349
+ waitFor(pattern, options) {
9350
+ return new Promise((resolve2) => {
9351
+ let settled = false;
9352
+ let timer2;
9353
+ const finish = (result) => {
9354
+ if (settled) return;
9355
+ settled = true;
9356
+ this.waiters.delete(check);
9357
+ if (timer2) clearTimeout(timer2);
9358
+ resolve2(result);
9359
+ };
9360
+ const check = () => {
9361
+ pattern.lastIndex = 0;
9362
+ const match = pattern.exec(this.text);
9363
+ if (!match) return;
9364
+ const through = match.index + (match[0].length || 1);
9365
+ const text3 = this.text.slice(0, through);
9366
+ this.text = this.text.slice(through);
9367
+ finish({ status: "matched", text: text3, match });
9368
+ };
9369
+ this.waiters.add(check);
9370
+ check();
9371
+ if (settled) return;
9372
+ if (options.timeoutMs > 0) {
9373
+ timer2 = setTimeout(() => {
9374
+ const text3 = this.text;
9375
+ this.text = "";
9376
+ finish({ status: "timeout", text: text3 });
9377
+ }, options.timeoutMs);
9378
+ timer2.unref?.();
9379
+ }
9380
+ options.exited?.then(
9381
+ (exit) => {
9382
+ if (settled) return;
9383
+ const text3 = this.text;
9384
+ this.text = "";
9385
+ finish({ status: "exited", text: text3, exitCode: exit.exitCode, signal: exit.signal });
9386
+ },
9387
+ () => {
9388
+ }
9389
+ );
9390
+ });
9391
+ }
9392
+ };
9393
+
9394
+ // src/runtime/terminal-sessions.ts
9395
+ var TerminalSessions = class {
9396
+ constructor(graph) {
9397
+ this.graph = graph;
9398
+ this.open = /* @__PURE__ */ new Map();
9399
+ this.laneOf = /* @__PURE__ */ new Map();
9400
+ this.transcripts = /* @__PURE__ */ new Map();
9401
+ this.listening = /* @__PURE__ */ new Map();
9402
+ }
9403
+ /**
9404
+ * The terminal lane a node belongs to, or null.
9405
+ *
9406
+ * Walks up `parentId` rather than checking only the immediate parent, and
9407
+ * caches per node id — a graph is walked once per run, and the answer cannot
9408
+ * change while it runs.
9409
+ */
9410
+ laneFor(nodeId, isTerminalLane) {
9411
+ const cached = this.laneOf.get(nodeId);
9412
+ if (cached !== void 0) return cached;
9413
+ const byId = new Map(this.graph.nodes.map((n) => [n.id, n]));
9414
+ const seen = /* @__PURE__ */ new Set();
9415
+ let current = byId.get(nodeId);
9416
+ let answer = null;
9417
+ while (current) {
9418
+ if (seen.has(current.id)) break;
9419
+ seen.add(current.id);
9420
+ if (current.id !== nodeId && isTerminalLane(current)) {
9421
+ answer = current.id;
9422
+ break;
9423
+ }
9424
+ const parentId = current.parentId;
9425
+ current = parentId ? byId.get(parentId) : void 0;
9426
+ }
9427
+ this.laneOf.set(nodeId, answer);
9428
+ return answer;
9429
+ }
9430
+ /**
9431
+ * The session for a lane, opening it on first use.
9432
+ *
9433
+ * The PROMISE is cached, not the resolved session. Two nodes cannot run
9434
+ * concurrently in the current engine, but a caller that awaits a
9435
+ * half-finished open would otherwise start a second process — and two shells
9436
+ * where a graph says one is the failure this class exists to prevent, arriving
9437
+ * only under concurrency and therefore only sometimes.
9438
+ */
9439
+ session(laneId, spec) {
9440
+ const existing = this.open.get(laneId);
9441
+ if (existing) return existing;
9442
+ {
9443
+ const failed = Promise.reject(
9444
+ new Error(
9445
+ "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."
9446
+ )
9447
+ );
9448
+ this.open.set(laneId, failed);
9449
+ failed.catch(() => {
9450
+ });
9451
+ return failed;
9452
+ }
9453
+ }
9454
+ /**
9455
+ * The accumulated output for a lane.
9456
+ *
9457
+ * Created on demand and kept for the run, so it exists before the session
9458
+ * resolves and survives every node that reads it. Consuming is the reader's
9459
+ * job — see `TerminalTranscript.waitFor`.
9460
+ */
9461
+ transcriptFor(laneId) {
9462
+ const existing = this.transcripts.get(laneId);
9463
+ if (existing) return existing;
9464
+ const created = new TerminalTranscript();
9465
+ this.transcripts.set(laneId, created);
9466
+ return created;
9467
+ }
9468
+ /** True once a lane has a session — used to avoid opening one during teardown. */
9469
+ isOpen(laneId) {
9470
+ return this.open.has(laneId);
9471
+ }
9472
+ /**
9473
+ * Close every session this run opened.
9474
+ *
9475
+ * Every close is attempted even if one throws: a host that fails to close one
9476
+ * PTY must not strand the others, which would leave processes alive after the
9477
+ * run reported that it had finished. Errors are returned rather than thrown,
9478
+ * because teardown runs in a `finally` and throwing there would replace the
9479
+ * run's real error with a cleanup error.
9480
+ */
9481
+ async closeAll() {
9482
+ const errors = [];
9483
+ for (const [laneId, pending] of this.open) {
9484
+ try {
9485
+ this.listening.get(laneId)?.();
9486
+ this.listening.delete(laneId);
9487
+ const session = await pending;
9488
+ await session.close();
9489
+ } catch (e) {
9490
+ errors.push(e instanceof Error ? e : new Error(`${laneId}: ${String(e)}`));
9491
+ }
9492
+ }
9493
+ this.open.clear();
9494
+ this.listening.clear();
9495
+ this.transcripts.clear();
9496
+ return errors;
9497
+ }
9498
+ };
9499
+ function specForLane(lane) {
9500
+ const config = lane.data?.config ?? {};
9501
+ const text3 = (key) => {
9502
+ const value = config[key];
9503
+ return typeof value === "string" && value !== "" ? value : void 0;
9504
+ };
9505
+ const env = config.env;
9506
+ return {
9507
+ command: text3("command"),
9508
+ cwd: text3("cwd"),
9509
+ env: env && typeof env === "object" && !Array.isArray(env) ? Object.fromEntries(
9510
+ Object.entries(env).map(([k, v]) => [k, String(v)])
9511
+ ) : void 0
9512
+ };
9513
+ }
9514
+
9282
9515
  // src/runtime/workflow-props.ts
9283
9516
  function typeOf(value) {
9284
9517
  if (value === null) return "null";
@@ -9357,6 +9590,25 @@ async function runFlow(graph, executors, onEvent = () => {
9357
9590
  const props = propsCheck.props;
9358
9591
  const declaresProps = (graph.inputs?.length ?? 0) > 0;
9359
9592
  const incomingByNode = indexIncoming(graph.edges);
9593
+ const sessions = new TerminalSessions(graph);
9594
+ const isTerminalLane = (candidate) => getNodeKind(candidate.type ?? "")?.name === "@particle-academy/terminal_lane";
9595
+ const terminalAccessorFor = (node) => {
9596
+ const laneId = sessions.laneFor(node.id, isTerminalLane);
9597
+ if (laneId === null) return void 0;
9598
+ const lane = graph.nodes.find((n) => n.id === laneId);
9599
+ if (!lane) return void 0;
9600
+ return {
9601
+ session: () => sessions.session(laneId, specForLane(lane)),
9602
+ // Awaits the session first on purpose. A transcript handed out before
9603
+ // anything is feeding it would look perfectly healthy and match nothing,
9604
+ // and "waited and nothing came" is the hardest failure here to tell apart
9605
+ // from a process that is simply slow.
9606
+ transcript: async () => {
9607
+ await sessions.session(laneId, specForLane(lane));
9608
+ return sessions.transcriptFor(laneId);
9609
+ }
9610
+ };
9611
+ };
9360
9612
  const timer2 = timeoutMs ? setTimeout(() => errors.push(`Run timed out after ${timeoutMs}ms`), timeoutMs) : null;
9361
9613
  onEvent({ type: "run-start" });
9362
9614
  try {
@@ -9422,7 +9674,8 @@ async function runFlow(graph, executors, onEvent = () => {
9422
9674
  emit: onEvent,
9423
9675
  executors,
9424
9676
  depth,
9425
- run
9677
+ run,
9678
+ terminal: terminalAccessorFor(node)
9426
9679
  })
9427
9680
  );
9428
9681
  outputs[node.id] = result;
@@ -9444,6 +9697,9 @@ async function runFlow(graph, executors, onEvent = () => {
9444
9697
  }
9445
9698
  } finally {
9446
9699
  if (timer2) clearTimeout(timer2);
9700
+ for (const error of await sessions.closeAll()) {
9701
+ onEvent({ type: "log", level: "warn", message: `terminal close failed: ${error.message}` });
9702
+ }
9447
9703
  }
9448
9704
  const ok = errors.length === 0;
9449
9705
  onEvent({ type: "run-end", ok });
@@ -9522,7 +9778,7 @@ function pickExecutor(executors, node) {
9522
9778
  for (const id2 of executorLookupIds(node)) {
9523
9779
  if (executors[id2]) return executors[id2];
9524
9780
  }
9525
- return void 0;
9781
+ return getNodeKind(node.type ?? "")?.executor;
9526
9782
  }
9527
9783
  function activatedPorts(node, result) {
9528
9784
  if (result && typeof result === "object") {
@@ -9632,6 +9888,366 @@ var subflowExecutor = async (ctx) => {
9632
9888
  return { __port: "out", value: result.outputs };
9633
9889
  };
9634
9890
 
9891
+ // src/expressions/expr.ts
9892
+ function wholeExpression(trimmed) {
9893
+ if (trimmed.length < 4) return null;
9894
+ if (!trimmed.startsWith("{{") || !trimmed.endsWith("}}")) return null;
9895
+ return trimmed.slice(2, -2);
9896
+ }
9897
+ function interpolate(template, resolve2) {
9898
+ let out = "";
9899
+ let i = 0;
9900
+ for (; ; ) {
9901
+ const open = template.indexOf("{{", i);
9902
+ if (open === -1) return out + template.slice(i);
9903
+ const close = template.indexOf("}}", open + 2);
9904
+ if (close === -1) return out + template.slice(i);
9905
+ out += template.slice(i, open) + resolve2(template.slice(open + 2, close));
9906
+ i = close + 2;
9907
+ }
9908
+ }
9909
+ var FALSY_STRINGS = /* @__PURE__ */ new Set(["", "0", "false", "no", "off", "null"]);
9910
+ var UnresolvedPathError = class extends Error {
9911
+ constructor(path) {
9912
+ super(
9913
+ `Expression path "${path}" did not resolve. Under the "throw" policy an unresolvable path is an error rather than an empty string.`
9914
+ );
9915
+ this.path = path;
9916
+ this.name = "UnresolvedPathError";
9917
+ }
9918
+ };
9919
+ function tryResolvePath(path, context) {
9920
+ const unresolved = { resolved: false, value: null };
9921
+ const trimmed = path.trim();
9922
+ if (trimmed === "") return unresolved;
9923
+ const segments = trimmed.split(".");
9924
+ let cursor;
9925
+ const head = segments[0];
9926
+ if (head === "$json" || head === "$input") {
9927
+ cursor = context !== null && typeof context === "object" && "in" in context ? context.in : context;
9928
+ segments.shift();
9929
+ } else {
9930
+ cursor = context;
9931
+ }
9932
+ for (const segment of segments) {
9933
+ if (cursor === null || cursor === void 0) return unresolved;
9934
+ if (typeof cursor !== "object") return unresolved;
9935
+ const next = cursor[segment];
9936
+ if (next === void 0) return unresolved;
9937
+ cursor = next;
9938
+ }
9939
+ return { resolved: true, value: cursor === void 0 ? null : cursor };
9940
+ }
9941
+ function evaluateExpression(template, context, options = {}) {
9942
+ if (typeof template !== "string") return template;
9943
+ const policy = options.onUnresolved ?? "empty";
9944
+ const whole = wholeExpression(template.trim());
9945
+ if (whole !== null) {
9946
+ const r = tryResolvePath(whole, context);
9947
+ if (r.resolved) return r.value;
9948
+ if (policy === "throw") throw new UnresolvedPathError(whole);
9949
+ return policy === "keep" ? template : null;
9950
+ }
9951
+ return interpolate(template, (path) => {
9952
+ const r = tryResolvePath(path, context);
9953
+ if (r.resolved) return stringify(r.value);
9954
+ if (policy === "throw") throw new UnresolvedPathError(path);
9955
+ return policy === "keep" ? `{{${path}}}` : "";
9956
+ });
9957
+ }
9958
+ function truthy(value) {
9959
+ if (typeof value === "boolean") return value;
9960
+ if (value === null || value === void 0) return false;
9961
+ if (typeof value === "string") return !FALSY_STRINGS.has(value.trim().toLowerCase());
9962
+ if (Array.isArray(value)) return value.length > 0;
9963
+ if (typeof value === "number") return value !== 0;
9964
+ return Boolean(value);
9965
+ }
9966
+ function text(value) {
9967
+ return stringify(value);
9968
+ }
9969
+ function stringify(value) {
9970
+ if (typeof value === "string") return value;
9971
+ if (typeof value === "boolean") return value ? "true" : "false";
9972
+ if (value === null || value === void 0) return "";
9973
+ if (typeof value === "number" || typeof value === "bigint") return String(value);
9974
+ try {
9975
+ return JSON.stringify(value) ?? "";
9976
+ } catch {
9977
+ return "";
9978
+ }
9979
+ }
9980
+
9981
+ // src/registry/logic.ts
9982
+ function configOf(node) {
9983
+ return node?.data?.config ?? {};
9984
+ }
9985
+ function contextOf(inputs) {
9986
+ return inputs;
9987
+ }
9988
+ function resolve(value, inputs) {
9989
+ if (typeof value !== "string") return value;
9990
+ return evaluateExpression(value, contextOf(inputs));
9991
+ }
9992
+ function conditionHolds(row, inputs) {
9993
+ const left = resolve(row.left, inputs);
9994
+ const right = resolve(row.right, inputs);
9995
+ const operator = typeof row.operator === "string" ? row.operator : "eq";
9996
+ const asText = (v) => text(v);
9997
+ const asNumber = (v) => {
9998
+ const n = typeof v === "number" ? v : Number(asText(v));
9999
+ return Number.isFinite(n) ? n : NaN;
10000
+ };
10001
+ const numeric = (fn) => {
10002
+ const a = asNumber(left);
10003
+ const b = asNumber(right);
10004
+ return Number.isFinite(a) && Number.isFinite(b) ? fn(a, b) : false;
10005
+ };
10006
+ 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;
10007
+ switch (operator) {
10008
+ // Compared as TEXT, deliberately. `right` is a text field in the schema, so
10009
+ // `status == "2"` must match the number 2 an upstream node produced —
10010
+ // strict equality there would fail on a difference the author cannot see.
10011
+ case "eq":
10012
+ return asText(left) === asText(right);
10013
+ case "neq":
10014
+ return asText(left) !== asText(right);
10015
+ case "contains":
10016
+ return asText(left).includes(asText(right));
10017
+ case "not_contains":
10018
+ return !asText(left).includes(asText(right));
10019
+ case "gt":
10020
+ return numeric((a, b) => a > b);
10021
+ case "gte":
10022
+ return numeric((a, b) => a >= b);
10023
+ case "lt":
10024
+ return numeric((a, b) => a < b);
10025
+ case "lte":
10026
+ return numeric((a, b) => a <= b);
10027
+ case "truthy":
10028
+ return truthy(left);
10029
+ case "falsy":
10030
+ return !truthy(left);
10031
+ case "empty":
10032
+ return isEmpty(left);
10033
+ case "not_empty":
10034
+ return !isEmpty(left);
10035
+ default:
10036
+ return false;
10037
+ }
10038
+ }
10039
+ var branchExecutor = (ctx) => {
10040
+ const config = configOf(ctx.node);
10041
+ const inputs = ctx.inputs;
10042
+ let taken;
10043
+ const raw = config.condition;
10044
+ if (typeof raw === "string" && raw.trim() !== "") {
10045
+ taken = truthy(resolve(raw, inputs));
10046
+ } else {
10047
+ const rows = Array.isArray(config.conditions) ? config.conditions : [];
10048
+ if (rows.length === 0) {
10049
+ taken = false;
10050
+ } else {
10051
+ const results = rows.map((row) => conditionHolds(row, inputs));
10052
+ taken = config.match === "any" ? results.some(Boolean) : results.every(Boolean);
10053
+ }
10054
+ }
10055
+ return { __port: taken ? "true" : "false", value: ctx.inputs.in ?? ctx.inputs };
10056
+ };
10057
+ var transformExecutor = (ctx) => {
10058
+ const config = configOf(ctx.node);
10059
+ const inputs = ctx.inputs;
10060
+ const passthrough = ctx.inputs.in ?? ctx.inputs;
10061
+ if (config.mode === "expression") {
10062
+ const expression = config.expression;
10063
+ if (typeof expression !== "string" || expression.trim() === "") return passthrough;
10064
+ return resolve(expression, inputs);
10065
+ }
10066
+ const rows = Array.isArray(config.fields) ? config.fields : [];
10067
+ if (rows.length === 0) return passthrough;
10068
+ const out = {};
10069
+ let wrote = false;
10070
+ for (const row of rows) {
10071
+ const key = typeof row.key === "string" ? row.key.trim() : "";
10072
+ if (key === "") continue;
10073
+ out[key] = resolve(row.value, inputs);
10074
+ wrote = true;
10075
+ }
10076
+ return wrote ? out : passthrough;
10077
+ };
10078
+ var mergeExecutor = (ctx) => {
10079
+ const entries = Object.entries(ctx.inputs);
10080
+ if (configOf(ctx.node).mode === "concat") {
10081
+ const out = [];
10082
+ for (const [, value] of entries) {
10083
+ if (value === null || value === void 0) continue;
10084
+ if (Array.isArray(value)) out.push(...value);
10085
+ else out.push(value);
10086
+ }
10087
+ return out;
10088
+ }
10089
+ const merged = {};
10090
+ for (const [port, value] of entries) {
10091
+ if (value === null || value === void 0) continue;
10092
+ if (typeof value === "object" && !Array.isArray(value)) Object.assign(merged, value);
10093
+ else merged[port] = value;
10094
+ }
10095
+ return merged;
10096
+ };
10097
+ var forEachExecutor = (ctx) => {
10098
+ const source = resolve(configOf(ctx.node).source, ctx.inputs);
10099
+ let items;
10100
+ if (Array.isArray(source)) items = source;
10101
+ else if (source === null || source === void 0) items = [];
10102
+ else if (typeof source === "object") items = Object.values(source);
10103
+ else items = [source];
10104
+ return { items, count: items.length };
10105
+ };
10106
+
10107
+ // src/registry/terminal-nodes.ts
10108
+ var DEFAULT_TIMEOUT_MS = 12e4;
10109
+ var ENTER = "\r";
10110
+ function configOf2(node) {
10111
+ return node?.data?.config ?? {};
10112
+ }
10113
+ function text2(config, key) {
10114
+ const value = config[key];
10115
+ return typeof value === "string" ? value : "";
10116
+ }
10117
+ function millis(config, key, fallback) {
10118
+ const value = Number(config[key]);
10119
+ return Number.isFinite(value) && value >= 0 ? value : fallback;
10120
+ }
10121
+ function exitMarker(nonce) {
10122
+ const token = `__fancy_flow_exit_${nonce}__`;
10123
+ return {
10124
+ token,
10125
+ // The expanded status is required to be digits. The shell ECHOES the typed
10126
+ // command back first, and that echo contains the marker with `$?`
10127
+ // unexpanded — so requiring digits is what stops the node matching its own
10128
+ // command line and reporting success before anything has run.
10129
+ pattern: new RegExp(`${token}:(\\d+)`)
10130
+ };
10131
+ }
10132
+ var counter = 0;
10133
+ function newNonce() {
10134
+ counter += 1;
10135
+ return `${Date.now().toString(36)}${counter.toString(36)}${Math.random().toString(36).slice(2, 8)}`;
10136
+ }
10137
+ function withoutMarker(output, token) {
10138
+ return output.split("\n").filter((line) => !line.includes(token)).join("\n").trim();
10139
+ }
10140
+ function fail(ctx, message) {
10141
+ ctx.abort(message);
10142
+ throw new Error(message);
10143
+ }
10144
+ function requireTerminal(ctx) {
10145
+ if (!ctx.terminal) {
10146
+ fail(
10147
+ ctx,
10148
+ `"${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.`
10149
+ );
10150
+ }
10151
+ return ctx.terminal;
10152
+ }
10153
+ function compilePattern(ctx, raw, config) {
10154
+ const flags = typeof config.flags === "string" ? config.flags.replace(/[gy]/g, "") : "";
10155
+ try {
10156
+ return config.mode === "regex" ? new RegExp(raw, flags) : new RegExp(raw.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), flags);
10157
+ } catch (e) {
10158
+ return fail(ctx, `terminal_await has an invalid regex: ${e instanceof Error ? e.message : String(e)}`);
10159
+ }
10160
+ }
10161
+ var terminalRunExecutor = async (ctx) => {
10162
+ const config = configOf2(ctx.node);
10163
+ const command = text2(config, "command").trim();
10164
+ if (!command) fail(ctx, "terminal_run has no command configured");
10165
+ const terminal = requireTerminal(ctx);
10166
+ const session = await terminal.session();
10167
+ const transcript = await terminal.transcript();
10168
+ const { token, pattern } = exitMarker(newNonce());
10169
+ const timeoutMs = millis(config, "timeoutMs", DEFAULT_TIMEOUT_MS);
10170
+ transcript.clear();
10171
+ await session.write(`${command}; printf '${token}:%s\\n' "$?"${ENTER}`);
10172
+ const result = await transcript.waitFor(pattern, { timeoutMs, exited: session.exited });
10173
+ if (result.status === "exited") {
10174
+ fail(
10175
+ ctx,
10176
+ `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.`
10177
+ );
10178
+ }
10179
+ if (result.status === "timeout") {
10180
+ fail(
10181
+ ctx,
10182
+ `"${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.`
10183
+ );
10184
+ }
10185
+ const exitCode = Number(result.match[1]);
10186
+ const output = withoutMarker(result.text, token);
10187
+ const failOnNonZero = config.failOnNonZero !== false;
10188
+ if (failOnNonZero && exitCode !== 0) {
10189
+ ctx.abort(`"${command}" exited ${exitCode}.
10190
+ ${output}`);
10191
+ }
10192
+ return { output, exitCode, command };
10193
+ };
10194
+ var terminalSendExecutor = async (ctx) => {
10195
+ const config = configOf2(ctx.node);
10196
+ const terminal = requireTerminal(ctx);
10197
+ const session = await terminal.session();
10198
+ const body = text2(config, "text");
10199
+ const submit = config.submit !== false;
10200
+ if (config.clearFirst === true) {
10201
+ (await terminal.transcript()).clear();
10202
+ }
10203
+ await session.write(submit ? `${body}${ENTER}` : body);
10204
+ return { sent: body, submitted: submit };
10205
+ };
10206
+ var terminalAwaitExecutor = async (ctx) => {
10207
+ const config = configOf2(ctx.node);
10208
+ const terminal = requireTerminal(ctx);
10209
+ const session = await terminal.session();
10210
+ const transcript = await terminal.transcript();
10211
+ const raw = text2(config, "pattern").trim();
10212
+ if (!raw) fail(ctx, "terminal_await has no pattern configured \u2014 there is nothing for it to wait for");
10213
+ const pattern = compilePattern(ctx, raw, config);
10214
+ const timeoutMs = millis(config, "timeoutMs", DEFAULT_TIMEOUT_MS);
10215
+ const result = await transcript.waitFor(pattern, {
10216
+ timeoutMs,
10217
+ exited: session.exited
10218
+ });
10219
+ if (result.status === "exited") {
10220
+ fail(
10221
+ ctx,
10222
+ `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.`
10223
+ );
10224
+ }
10225
+ if (result.status === "timeout") {
10226
+ if (config.onTimeout === "continue") {
10227
+ ctx.emit({
10228
+ type: "log",
10229
+ nodeId: ctx.node.id,
10230
+ level: "warn",
10231
+ message: `terminal_await: ${JSON.stringify(raw)} did not appear within ${timeoutMs}ms; continuing as configured.`
10232
+ });
10233
+ return { matched: false, output: result.text, groups: [] };
10234
+ }
10235
+ fail(
10236
+ ctx,
10237
+ `${JSON.stringify(raw)} did not appear within ${timeoutMs}ms. Last output:
10238
+ ${result.text.slice(-2e3)}`
10239
+ );
10240
+ }
10241
+ return {
10242
+ matched: true,
10243
+ output: result.text,
10244
+ matchedText: result.match[0],
10245
+ // Capture groups are the reason to use regex mode at all — a prompt that
10246
+ // reports a session id or a file path is only useful if the value comes out.
10247
+ groups: result.match.slice(1)
10248
+ };
10249
+ };
10250
+
9635
10251
  // src/registry/builtin.ts
9636
10252
  var HUMAN_FIELD_OUTPUT_TYPE = {
9637
10253
  text: "string",
@@ -9921,6 +10537,9 @@ var KINDS = [
9921
10537
  // returns its input on the chosen port
9922
10538
  emits: "input",
9923
10539
  aliases: ["branch", "@fancy/branch"],
10540
+ // Pure logic: no I/O to choose, so a default is safe. A host
10541
+ // executor still wins -- pickExecutor consults the registry first.
10542
+ executor: branchExecutor,
9924
10543
  category: "logic",
9925
10544
  label: "Branch",
9926
10545
  description: "Multi-way branch on a condition or value.",
@@ -10018,6 +10637,9 @@ var KINDS = [
10018
10637
  { path: "count", type: "number" }
10019
10638
  ],
10020
10639
  aliases: ["for_each", "@fancy/for_each"],
10640
+ // Pure logic: no I/O to choose, so a default is safe. A host
10641
+ // executor still wins -- pickExecutor consults the registry first.
10642
+ executor: forEachExecutor,
10021
10643
  category: "logic",
10022
10644
  label: "For Each",
10023
10645
  description: "Iterate over a list, emitting each item on `item`.",
@@ -10038,6 +10660,9 @@ var KINDS = [
10038
10660
  // reference.
10039
10661
  emits: (config) => (config?.mode ?? "merge") === "concat" ? null : "inputs-merged",
10040
10662
  aliases: ["merge", "@fancy/merge"],
10663
+ // Pure logic: no I/O to choose, so a default is safe. A host
10664
+ // executor still wins -- pickExecutor consults the registry first.
10665
+ executor: mergeExecutor,
10041
10666
  category: "logic",
10042
10667
  label: "Merge",
10043
10668
  description: "Combine multiple inputs into one object or array.",
@@ -10083,6 +10708,9 @@ var KINDS = [
10083
10708
  // else the shape that expression names. So the RELATION is config-dependent.
10084
10709
  emits: (config) => (config?.expression ?? "") === "" ? "input" : "expression:expression",
10085
10710
  aliases: ["transform", "@fancy/transform"],
10711
+ // Pure logic: no I/O to choose, so a default is safe. A host
10712
+ // executor still wins -- pickExecutor consults the registry first.
10713
+ executor: transformExecutor,
10086
10714
  category: "logic",
10087
10715
  label: "Transform",
10088
10716
  description: "Reshape data with an expression.",
@@ -10541,6 +11169,179 @@ var KINDS = [
10541
11169
  resizable: { minWidth: 160, minHeight: 72 },
10542
11170
  component: LaneNode
10543
11171
  },
11172
+ {
11173
+ // Terminal lane — a lane that OWNS a terminal for the length of the run.
11174
+ //
11175
+ // Visually a swimlane, and `layout` for the same reason the plain lane is:
11176
+ // a lane is not a step, so it never executes and never appears in topo
11177
+ // order. What is new is that it DECLARES a resource. The runtime opens its
11178
+ // terminal lazily, when the first terminal node inside it runs, and closes
11179
+ // it in the run's `finally` — so a graph that never reaches a terminal node
11180
+ // never spawns a process, and one that does gets exactly one session no
11181
+ // matter how many nodes use it.
11182
+ //
11183
+ // Membership is `parentId`, which already persists into the WorkflowSchema.
11184
+ // That is what lets a headless runtime resolve the same grouping the canvas
11185
+ // shows, without a second association to keep in sync.
11186
+ name: "@particle-academy/terminal_lane",
11187
+ aliases: ["terminal_lane", "@fancy/terminal_lane"],
11188
+ category: "layout",
11189
+ label: "Terminal lane",
11190
+ description: "A lane that owns one terminal. Opens at the first terminal node, closes when the run ends.",
11191
+ icon: "\u25A3",
11192
+ inputs: [],
11193
+ outputs: [],
11194
+ configSchema: [
11195
+ { type: "text", key: "title", label: "Title", default: "Terminal" },
11196
+ {
11197
+ type: "text",
11198
+ key: "command",
11199
+ label: "Command",
11200
+ placeholder: "Leave empty for the default shell"
11201
+ },
11202
+ { type: "text", key: "cwd", label: "Working directory", placeholder: "Host default" },
11203
+ { type: "keyvalue", key: "env", label: "Environment" },
11204
+ {
11205
+ type: "select",
11206
+ key: "orientation",
11207
+ label: "Orientation",
11208
+ default: "horizontal",
11209
+ options: [
11210
+ { value: "horizontal", label: "Row" },
11211
+ { value: "vertical", label: "Column" }
11212
+ ]
11213
+ }
11214
+ ],
11215
+ defaultConfig: { title: "Terminal", orientation: "horizontal" },
11216
+ resizable: { minWidth: 220, minHeight: 120 },
11217
+ component: LaneNode
11218
+ },
11219
+ {
11220
+ // Terminal nodes. All three live inside a terminal lane and talk to the
11221
+ // session that lane owns; outside one they abort by name rather than
11222
+ // opening a shell of their own.
11223
+ name: "@particle-academy/terminal_run",
11224
+ aliases: ["terminal_run", "@fancy/terminal_run"],
11225
+ category: "io",
11226
+ label: "Run in terminal",
11227
+ description: "Run a shell command in the lane's terminal and wait for its exit code.",
11228
+ icon: "$",
11229
+ inputs: [{ id: "in" }],
11230
+ outputs: [{ id: "out", label: "output" }],
11231
+ executor: terminalRunExecutor,
11232
+ configSchema: [
11233
+ {
11234
+ type: "textarea",
11235
+ key: "command",
11236
+ label: "Command",
11237
+ rows: 3,
11238
+ required: true,
11239
+ placeholder: "npm test",
11240
+ 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."
11241
+ },
11242
+ {
11243
+ type: "number",
11244
+ key: "timeoutMs",
11245
+ label: "Timeout (ms)",
11246
+ default: 12e4,
11247
+ description: "How long to wait for the command to finish before failing the run."
11248
+ },
11249
+ {
11250
+ type: "switch",
11251
+ key: "failOnNonZero",
11252
+ label: "Fail the run on a non-zero exit",
11253
+ default: true,
11254
+ 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."
11255
+ }
11256
+ ],
11257
+ defaultConfig: { command: "", timeoutMs: 12e4, failOnNonZero: true }
11258
+ },
11259
+ {
11260
+ name: "@particle-academy/terminal_send",
11261
+ aliases: ["terminal_send", "@fancy/terminal_send"],
11262
+ category: "io",
11263
+ label: "Send to terminal",
11264
+ description: "Type text at whatever is running in the lane's terminal, without waiting.",
11265
+ icon: "\u2328",
11266
+ inputs: [{ id: "in" }],
11267
+ outputs: [{ id: "out", label: "sent" }],
11268
+ executor: terminalSendExecutor,
11269
+ configSchema: [
11270
+ {
11271
+ type: "textarea",
11272
+ key: "text",
11273
+ label: "Text",
11274
+ rows: 4,
11275
+ placeholder: "Summarise the failing test and propose a fix.",
11276
+ description: "What to type. This is how a graph prompts an agent TUI such as Claude Code or Codex."
11277
+ },
11278
+ {
11279
+ type: "switch",
11280
+ key: "submit",
11281
+ label: "Press Enter",
11282
+ default: true,
11283
+ description: "Off leaves the text on the input line \u2014 useful for building one up across several nodes."
11284
+ },
11285
+ {
11286
+ type: "switch",
11287
+ key: "clearFirst",
11288
+ label: "Forget earlier output first",
11289
+ default: false,
11290
+ description: "Discards anything the terminal said before this send, so a following Await cannot match a prompt left over from the previous exchange."
11291
+ }
11292
+ ],
11293
+ defaultConfig: { text: "", submit: true, clearFirst: false }
11294
+ },
11295
+ {
11296
+ name: "@particle-academy/terminal_await",
11297
+ aliases: ["terminal_await", "@fancy/terminal_await"],
11298
+ category: "io",
11299
+ label: "Await terminal output",
11300
+ description: "Wait until the lane's terminal prints something that matches.",
11301
+ icon: "\u23F1",
11302
+ inputs: [{ id: "in" }],
11303
+ outputs: [{ id: "out", label: "output" }],
11304
+ executor: terminalAwaitExecutor,
11305
+ configSchema: [
11306
+ {
11307
+ type: "text",
11308
+ key: "pattern",
11309
+ label: "Wait for",
11310
+ required: true,
11311
+ placeholder: "esc to interrupt",
11312
+ description: "Matched against the output with colour codes already stripped, so match what you SEE."
11313
+ },
11314
+ {
11315
+ type: "select",
11316
+ key: "mode",
11317
+ label: "Match as",
11318
+ default: "text",
11319
+ options: [
11320
+ { value: "text", label: "Plain text" },
11321
+ { value: "regex", label: "Regular expression" }
11322
+ ],
11323
+ description: "Regex mode also returns capture groups, which is how a value gets out of a prompt."
11324
+ },
11325
+ {
11326
+ type: "number",
11327
+ key: "timeoutMs",
11328
+ label: "Timeout (ms)",
11329
+ default: 12e4
11330
+ },
11331
+ {
11332
+ type: "select",
11333
+ key: "onTimeout",
11334
+ label: "If it never appears",
11335
+ default: "fail",
11336
+ options: [
11337
+ { value: "fail", label: "Fail the run" },
11338
+ { value: "continue", label: "Continue with matched: false" }
11339
+ ],
11340
+ 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."
11341
+ }
11342
+ ],
11343
+ defaultConfig: { pattern: "", mode: "text", timeoutMs: 12e4, onTimeout: "fail" }
11344
+ },
10544
11345
  {
10545
11346
  // Note — a sticky-note annotation. Portless + visual-only: the runtime skips
10546
11347
  // the `annotation` category, so a note's text NEVER reaches a runner — it