@synergenius/flow-weaver 0.23.4 → 0.24.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 (38) hide show
  1. package/dist/api/generate-in-place.d.ts +0 -9
  2. package/dist/api/generate-in-place.js +6 -54
  3. package/dist/api/generate.d.ts +4 -5
  4. package/dist/api/generate.js +6 -26
  5. package/dist/cli/commands/compile.d.ts +0 -5
  6. package/dist/cli/commands/compile.js +36 -8
  7. package/dist/cli/commands/context.js +4 -6
  8. package/dist/cli/commands/create.js +6 -14
  9. package/dist/cli/commands/describe.js +6 -10
  10. package/dist/cli/commands/diagram.js +18 -25
  11. package/dist/cli/commands/diff.js +7 -14
  12. package/dist/cli/commands/docs.js +3 -6
  13. package/dist/cli/commands/doctor.js +1 -1
  14. package/dist/cli/commands/export.js +1 -1
  15. package/dist/cli/commands/grammar.js +3 -4
  16. package/dist/cli/commands/implement.js +8 -13
  17. package/dist/cli/commands/market.js +4 -8
  18. package/dist/cli/commands/migrate.js +2 -1
  19. package/dist/cli/commands/modify.js +2 -1
  20. package/dist/cli/commands/openapi.js +2 -1
  21. package/dist/cli/commands/pattern.js +3 -2
  22. package/dist/cli/commands/strip.js +3 -6
  23. package/dist/cli/commands/validate.js +6 -1
  24. package/dist/cli/flow-weaver.mjs +789 -797
  25. package/dist/cli/index.js +10 -12
  26. package/dist/cli/postinstall.d.ts +16 -0
  27. package/dist/cli/postinstall.js +119 -0
  28. package/dist/cli/utils/parse-int-strict.d.ts +7 -0
  29. package/dist/cli/utils/parse-int-strict.js +17 -0
  30. package/dist/cli/utils/safe-write.d.ts +18 -0
  31. package/dist/cli/utils/safe-write.js +54 -0
  32. package/dist/generated-version.d.ts +1 -1
  33. package/dist/generated-version.js +1 -1
  34. package/dist/generator/unified.js +8 -6
  35. package/docs/reference/cli-reference.md +0 -1
  36. package/docs/reference/compilation.md +2 -10
  37. package/package.json +4 -2
  38. package/scripts/postinstall.cjs +86 -0
@@ -935,8 +935,8 @@ var require_command = __commonJS({
935
935
  "node_modules/commander/lib/command.js"(exports2) {
936
936
  var EventEmitter2 = __require("events").EventEmitter;
937
937
  var childProcess = __require("child_process");
938
- var path54 = __require("path");
939
- var fs50 = __require("fs");
938
+ var path55 = __require("path");
939
+ var fs48 = __require("fs");
940
940
  var process6 = __require("process");
941
941
  var { Argument: Argument2, humanReadableArgName } = require_argument();
942
942
  var { CommanderError: CommanderError2 } = require_error();
@@ -1759,10 +1759,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
1759
1759
  let launchWithNode = false;
1760
1760
  const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
1761
1761
  function findFile(baseDir, baseName) {
1762
- const localBin = path54.resolve(baseDir, baseName);
1763
- if (fs50.existsSync(localBin)) return localBin;
1764
- if (sourceExt.includes(path54.extname(baseName))) return void 0;
1765
- const foundExt = sourceExt.find((ext2) => fs50.existsSync(`${localBin}${ext2}`));
1762
+ const localBin = path55.resolve(baseDir, baseName);
1763
+ if (fs48.existsSync(localBin)) return localBin;
1764
+ if (sourceExt.includes(path55.extname(baseName))) return void 0;
1765
+ const foundExt = sourceExt.find((ext2) => fs48.existsSync(`${localBin}${ext2}`));
1766
1766
  if (foundExt) return `${localBin}${foundExt}`;
1767
1767
  return void 0;
1768
1768
  }
@@ -1773,23 +1773,23 @@ Expecting one of '${allowedValues.join("', '")}'`);
1773
1773
  if (this._scriptPath) {
1774
1774
  let resolvedScriptPath;
1775
1775
  try {
1776
- resolvedScriptPath = fs50.realpathSync(this._scriptPath);
1776
+ resolvedScriptPath = fs48.realpathSync(this._scriptPath);
1777
1777
  } catch (err) {
1778
1778
  resolvedScriptPath = this._scriptPath;
1779
1779
  }
1780
- executableDir = path54.resolve(path54.dirname(resolvedScriptPath), executableDir);
1780
+ executableDir = path55.resolve(path55.dirname(resolvedScriptPath), executableDir);
1781
1781
  }
1782
1782
  if (executableDir) {
1783
1783
  let localFile = findFile(executableDir, executableFile);
1784
1784
  if (!localFile && !subcommand._executableFile && this._scriptPath) {
1785
- const legacyName = path54.basename(this._scriptPath, path54.extname(this._scriptPath));
1785
+ const legacyName = path55.basename(this._scriptPath, path55.extname(this._scriptPath));
1786
1786
  if (legacyName !== this._name) {
1787
1787
  localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
1788
1788
  }
1789
1789
  }
1790
1790
  executableFile = localFile || executableFile;
1791
1791
  }
1792
- launchWithNode = sourceExt.includes(path54.extname(executableFile));
1792
+ launchWithNode = sourceExt.includes(path55.extname(executableFile));
1793
1793
  let proc2;
1794
1794
  if (process6.platform !== "win32") {
1795
1795
  if (launchWithNode) {
@@ -2572,7 +2572,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
2572
2572
  * @return {Command}
2573
2573
  */
2574
2574
  nameFromFilename(filename) {
2575
- this._name = path54.basename(filename, path54.extname(filename));
2575
+ this._name = path55.basename(filename, path55.extname(filename));
2576
2576
  return this;
2577
2577
  }
2578
2578
  /**
@@ -2586,9 +2586,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
2586
2586
  * @param {string} [path]
2587
2587
  * @return {string|null|Command}
2588
2588
  */
2589
- executableDir(path55) {
2590
- if (path55 === void 0) return this._executableDir;
2591
- this._executableDir = path55;
2589
+ executableDir(path56) {
2590
+ if (path56 === void 0) return this._executableDir;
2591
+ this._executableDir = path56;
2592
2592
  return this;
2593
2593
  }
2594
2594
  /**
@@ -7303,12 +7303,12 @@ var init_esm4 = __esm({
7303
7303
  /**
7304
7304
  * Get the Path object referenced by the string path, resolved from this Path
7305
7305
  */
7306
- resolve(path54) {
7307
- if (!path54) {
7306
+ resolve(path55) {
7307
+ if (!path55) {
7308
7308
  return this;
7309
7309
  }
7310
- const rootPath = this.getRootString(path54);
7311
- const dir = path54.substring(rootPath.length);
7310
+ const rootPath = this.getRootString(path55);
7311
+ const dir = path55.substring(rootPath.length);
7312
7312
  const dirParts = dir.split(this.splitSep);
7313
7313
  const result = rootPath ? this.getRoot(rootPath).#resolveParts(dirParts) : this.#resolveParts(dirParts);
7314
7314
  return result;
@@ -8060,8 +8060,8 @@ var init_esm4 = __esm({
8060
8060
  /**
8061
8061
  * @internal
8062
8062
  */
8063
- getRootString(path54) {
8064
- return win32.parse(path54).root;
8063
+ getRootString(path55) {
8064
+ return win32.parse(path55).root;
8065
8065
  }
8066
8066
  /**
8067
8067
  * @internal
@@ -8107,8 +8107,8 @@ var init_esm4 = __esm({
8107
8107
  /**
8108
8108
  * @internal
8109
8109
  */
8110
- getRootString(path54) {
8111
- return path54.startsWith("/") ? "/" : "";
8110
+ getRootString(path55) {
8111
+ return path55.startsWith("/") ? "/" : "";
8112
8112
  }
8113
8113
  /**
8114
8114
  * @internal
@@ -8157,8 +8157,8 @@ var init_esm4 = __esm({
8157
8157
  *
8158
8158
  * @internal
8159
8159
  */
8160
- constructor(cwd = process.cwd(), pathImpl, sep3, { nocase, childrenCacheSize = 16 * 1024, fs: fs50 = defaultFS } = {}) {
8161
- this.#fs = fsFromOption(fs50);
8160
+ constructor(cwd = process.cwd(), pathImpl, sep4, { nocase, childrenCacheSize = 16 * 1024, fs: fs48 = defaultFS } = {}) {
8161
+ this.#fs = fsFromOption(fs48);
8162
8162
  if (cwd instanceof URL || cwd.startsWith("file://")) {
8163
8163
  cwd = fileURLToPath(cwd);
8164
8164
  }
@@ -8168,7 +8168,7 @@ var init_esm4 = __esm({
8168
8168
  this.#resolveCache = new ResolveCache();
8169
8169
  this.#resolvePosixCache = new ResolveCache();
8170
8170
  this.#children = new ChildrenCache(childrenCacheSize);
8171
- const split = cwdPath.substring(this.rootPath.length).split(sep3);
8171
+ const split = cwdPath.substring(this.rootPath.length).split(sep4);
8172
8172
  if (split.length === 1 && !split[0]) {
8173
8173
  split.pop();
8174
8174
  }
@@ -8197,11 +8197,11 @@ var init_esm4 = __esm({
8197
8197
  /**
8198
8198
  * Get the depth of a provided path, string, or the cwd
8199
8199
  */
8200
- depth(path54 = this.cwd) {
8201
- if (typeof path54 === "string") {
8202
- path54 = this.cwd.resolve(path54);
8200
+ depth(path55 = this.cwd) {
8201
+ if (typeof path55 === "string") {
8202
+ path55 = this.cwd.resolve(path55);
8203
8203
  }
8204
- return path54.depth();
8204
+ return path55.depth();
8205
8205
  }
8206
8206
  /**
8207
8207
  * Return the cache of child entries. Exposed so subclasses can create
@@ -8688,9 +8688,9 @@ var init_esm4 = __esm({
8688
8688
  process6();
8689
8689
  return results;
8690
8690
  }
8691
- chdir(path54 = this.cwd) {
8691
+ chdir(path55 = this.cwd) {
8692
8692
  const oldCwd = this.cwd;
8693
- this.cwd = typeof path54 === "string" ? this.cwd.resolve(path54) : path54;
8693
+ this.cwd = typeof path55 === "string" ? this.cwd.resolve(path55) : path55;
8694
8694
  this.cwd[setAsCwd](oldCwd);
8695
8695
  }
8696
8696
  };
@@ -8716,8 +8716,8 @@ var init_esm4 = __esm({
8716
8716
  /**
8717
8717
  * @internal
8718
8718
  */
8719
- newRoot(fs50) {
8720
- return new PathWin32(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs50 });
8719
+ newRoot(fs48) {
8720
+ return new PathWin32(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs48 });
8721
8721
  }
8722
8722
  /**
8723
8723
  * Return true if the provided path string is an absolute path
@@ -8745,8 +8745,8 @@ var init_esm4 = __esm({
8745
8745
  /**
8746
8746
  * @internal
8747
8747
  */
8748
- newRoot(fs50) {
8749
- return new PathPosix(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs50 });
8748
+ newRoot(fs48) {
8749
+ return new PathPosix(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs48 });
8750
8750
  }
8751
8751
  /**
8752
8752
  * Return true if the provided path string is an absolute path
@@ -9065,8 +9065,8 @@ var init_processor = __esm({
9065
9065
  }
9066
9066
  // match, absolute, ifdir
9067
9067
  entries() {
9068
- return [...this.store.entries()].map(([path54, n]) => [
9069
- path54,
9068
+ return [...this.store.entries()].map(([path55, n]) => [
9069
+ path55,
9070
9070
  !!(n & 2),
9071
9071
  !!(n & 1)
9072
9072
  ]);
@@ -9279,9 +9279,9 @@ var init_walker = __esm({
9279
9279
  signal;
9280
9280
  maxDepth;
9281
9281
  includeChildMatches;
9282
- constructor(patterns, path54, opts) {
9282
+ constructor(patterns, path55, opts) {
9283
9283
  this.patterns = patterns;
9284
- this.path = path54;
9284
+ this.path = path55;
9285
9285
  this.opts = opts;
9286
9286
  this.#sep = !opts.posix && opts.platform === "win32" ? "\\" : "/";
9287
9287
  this.includeChildMatches = opts.includeChildMatches !== false;
@@ -9300,11 +9300,11 @@ var init_walker = __esm({
9300
9300
  });
9301
9301
  }
9302
9302
  }
9303
- #ignored(path54) {
9304
- return this.seen.has(path54) || !!this.#ignore?.ignored?.(path54);
9303
+ #ignored(path55) {
9304
+ return this.seen.has(path55) || !!this.#ignore?.ignored?.(path55);
9305
9305
  }
9306
- #childrenIgnored(path54) {
9307
- return !!this.#ignore?.childrenIgnored?.(path54);
9306
+ #childrenIgnored(path55) {
9307
+ return !!this.#ignore?.childrenIgnored?.(path55);
9308
9308
  }
9309
9309
  // backpressure mechanism
9310
9310
  pause() {
@@ -9519,8 +9519,8 @@ var init_walker = __esm({
9519
9519
  };
9520
9520
  GlobWalker = class extends GlobUtil {
9521
9521
  matches = /* @__PURE__ */ new Set();
9522
- constructor(patterns, path54, opts) {
9523
- super(patterns, path54, opts);
9522
+ constructor(patterns, path55, opts) {
9523
+ super(patterns, path55, opts);
9524
9524
  }
9525
9525
  matchEmit(e) {
9526
9526
  this.matches.add(e);
@@ -9557,8 +9557,8 @@ var init_walker = __esm({
9557
9557
  };
9558
9558
  GlobStream = class extends GlobUtil {
9559
9559
  results;
9560
- constructor(patterns, path54, opts) {
9561
- super(patterns, path54, opts);
9560
+ constructor(patterns, path55, opts) {
9561
+ super(patterns, path55, opts);
9562
9562
  this.results = new Minipass({
9563
9563
  signal: this.signal,
9564
9564
  objectMode: true
@@ -9886,7 +9886,7 @@ var VERSION;
9886
9886
  var init_generated_version = __esm({
9887
9887
  "src/generated-version.ts"() {
9888
9888
  "use strict";
9889
- VERSION = "0.23.4";
9889
+ VERSION = "0.24.0";
9890
9890
  }
9891
9891
  });
9892
9892
 
@@ -11472,7 +11472,7 @@ function generateControlFlowWithExecutionContext(workflow, nodeTypes, isAsync2,
11472
11472
  "ctx",
11473
11473
  bundleMode,
11474
11474
  promotedPreDeclared,
11475
- branchingNodesNeedingSuccessFlag.has(instanceId),
11475
+ branchingNodesNeedingSuccessFlag.has(instanceId) || topLevelSuccessFlags.has(toValidIdentifier(instanceId)),
11476
11476
  production
11477
11477
  );
11478
11478
  if (branchNeedsClose) {
@@ -11888,8 +11888,8 @@ function generateBranchingChainCode(chain, workflow, nodeTypes, branchingNodes,
11888
11888
  const preDeclaredFlags = new Set(alreadyDeclaredFlags);
11889
11889
  for (let i = 0; i < chain.length; i++) {
11890
11890
  const isLast = i === chain.length - 1;
11891
- if (!isLast || forceTrackSuccessNodes.has(chain[i])) {
11892
- const safeId = toValidIdentifier(chain[i]);
11891
+ const safeId = toValidIdentifier(chain[i]);
11892
+ if (!isLast || forceTrackSuccessNodes.has(chain[i]) || alreadyDeclaredFlags.has(safeId)) {
11893
11893
  if (!alreadyDeclaredFlags.has(safeId)) {
11894
11894
  lines.push(`${indent}let ${safeId}_success = false;`);
11895
11895
  }
@@ -11942,8 +11942,8 @@ function generateBranchingChainCode(chain, workflow, nodeTypes, branchingNodes,
11942
11942
  ctxVar,
11943
11943
  bundleMode,
11944
11944
  preDeclaredFlags,
11945
- !isLast || forceTrackSuccessNodes.has(chain[i]),
11946
- // forceTrackSuccess for non-last chain nodes or nodes with promoted dependents
11945
+ !isLast || forceTrackSuccessNodes.has(chain[i]) || alreadyDeclaredFlags.has(safeId),
11946
+ // forceTrackSuccess for non-last chain nodes, nodes with promoted dependents, or nodes with pre-declared flags
11947
11947
  production
11948
11948
  );
11949
11949
  generateScopedChildrenExecution(
@@ -12269,7 +12269,8 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12269
12269
  ctxVar,
12270
12270
  bundleMode,
12271
12271
  nestedPreDeclared,
12272
- false,
12272
+ nestedPreDeclared.has(nestedSafeId),
12273
+ // force tracking if flag was pre-declared at higher scope
12273
12274
  production
12274
12275
  );
12275
12276
  successExecutedNodes.push(instanceId2);
@@ -12353,7 +12354,8 @@ function generateBranchingNodeCode(instance, branchNode, workflow, allNodeTypes,
12353
12354
  ctxVar,
12354
12355
  bundleMode,
12355
12356
  nestedPreDeclared,
12356
- false,
12357
+ nestedPreDeclared.has(nestedSafeId),
12358
+ // force tracking if flag was pre-declared at higher scope
12357
12359
  production
12358
12360
  );
12359
12361
  failureExecutedNodes.push(instanceId2);
@@ -13110,7 +13112,7 @@ var require_util = __commonJS({
13110
13112
  var normalize2 = createSafeHandler((url) => {
13111
13113
  });
13112
13114
  exports2.normalize = normalize2;
13113
- function join29(aRoot, aPath) {
13115
+ function join28(aRoot, aPath) {
13114
13116
  const pathType = getURLType(aPath);
13115
13117
  const rootType = getURLType(aRoot);
13116
13118
  aRoot = ensureDirectory(aRoot);
@@ -13140,7 +13142,7 @@ var require_util = __commonJS({
13140
13142
  const newPath = withBase(aPath, withBase(aRoot, base));
13141
13143
  return computeRelativeURL(base, newPath);
13142
13144
  }
13143
- exports2.join = join29;
13145
+ exports2.join = join28;
13144
13146
  function relative10(rootURL, targetURL) {
13145
13147
  const result = relativeIfPossible(rootURL, targetURL);
13146
13148
  return typeof result === "string" ? result : normalize2(targetURL);
@@ -13169,8 +13171,8 @@ var require_util = __commonJS({
13169
13171
  sourceURL = sourceURL.replace(/^\//, "");
13170
13172
  }
13171
13173
  let url = normalize2(sourceURL || "");
13172
- if (sourceRoot) url = join29(sourceRoot, url);
13173
- if (sourceMapURL) url = join29(trimFilename(sourceMapURL), url);
13174
+ if (sourceRoot) url = join28(sourceRoot, url);
13175
+ if (sourceMapURL) url = join28(trimFilename(sourceMapURL), url);
13174
13176
  return url;
13175
13177
  }
13176
13178
  exports2.computeSourceURL = computeSourceURL;
@@ -13721,12 +13723,12 @@ var require_binary_search = __commonJS({
13721
13723
  var require_read_wasm = __commonJS({
13722
13724
  "node_modules/source-map/lib/read-wasm.js"(exports2, module2) {
13723
13725
  "use strict";
13724
- var fs50 = __require("fs");
13725
- var path54 = __require("path");
13726
+ var fs48 = __require("fs");
13727
+ var path55 = __require("path");
13726
13728
  module2.exports = function readWasm() {
13727
13729
  return new Promise((resolve38, reject2) => {
13728
- const wasmPath = path54.join(__dirname, "mappings.wasm");
13729
- fs50.readFile(wasmPath, null, (error2, data) => {
13730
+ const wasmPath = path55.join(__dirname, "mappings.wasm");
13731
+ fs48.readFile(wasmPath, null, (error2, data) => {
13730
13732
  if (error2) {
13731
13733
  reject2(error2);
13732
13734
  return;
@@ -16598,9 +16600,9 @@ ${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
16598
16600
  if (regexp.flags) result = `(?${regexp.flags})${result}`;
16599
16601
  return result;
16600
16602
  }
16601
- var fs50 = __require("fs");
16603
+ var fs48 = __require("fs");
16602
16604
  var os5 = __require("os");
16603
- var path54 = __require("path");
16605
+ var path55 = __require("path");
16604
16606
  var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
16605
16607
  var isValidBinaryPath = (x) => !!x && x !== "/usr/bin/esbuild";
16606
16608
  var packageDarwin_arm64 = "@esbuild/darwin-arm64";
@@ -16659,19 +16661,19 @@ ${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
16659
16661
  }
16660
16662
  function pkgForSomeOtherPlatform() {
16661
16663
  const libMainJS = __require.resolve("esbuild");
16662
- const nodeModulesDirectory = path54.dirname(path54.dirname(path54.dirname(libMainJS)));
16663
- if (path54.basename(nodeModulesDirectory) === "node_modules") {
16664
+ const nodeModulesDirectory = path55.dirname(path55.dirname(path55.dirname(libMainJS)));
16665
+ if (path55.basename(nodeModulesDirectory) === "node_modules") {
16664
16666
  for (const unixKey in knownUnixlikePackages) {
16665
16667
  try {
16666
16668
  const pkg = knownUnixlikePackages[unixKey];
16667
- if (fs50.existsSync(path54.join(nodeModulesDirectory, pkg))) return pkg;
16669
+ if (fs48.existsSync(path55.join(nodeModulesDirectory, pkg))) return pkg;
16668
16670
  } catch {
16669
16671
  }
16670
16672
  }
16671
16673
  for (const windowsKey in knownWindowsPackages) {
16672
16674
  try {
16673
16675
  const pkg = knownWindowsPackages[windowsKey];
16674
- if (fs50.existsSync(path54.join(nodeModulesDirectory, pkg))) return pkg;
16676
+ if (fs48.existsSync(path55.join(nodeModulesDirectory, pkg))) return pkg;
16675
16677
  } catch {
16676
16678
  }
16677
16679
  }
@@ -16679,12 +16681,12 @@ ${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
16679
16681
  return null;
16680
16682
  }
16681
16683
  function downloadedBinPath(pkg, subpath) {
16682
- const esbuildLibDir = path54.dirname(__require.resolve("esbuild"));
16683
- return path54.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path54.basename(subpath)}`);
16684
+ const esbuildLibDir = path55.dirname(__require.resolve("esbuild"));
16685
+ return path55.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path55.basename(subpath)}`);
16684
16686
  }
16685
16687
  function generateBinPath() {
16686
16688
  if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
16687
- if (!fs50.existsSync(ESBUILD_BINARY_PATH)) {
16689
+ if (!fs48.existsSync(ESBUILD_BINARY_PATH)) {
16688
16690
  console.warn(`[esbuild] Ignoring bad configuration: ESBUILD_BINARY_PATH=${ESBUILD_BINARY_PATH}`);
16689
16691
  } else {
16690
16692
  return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
@@ -16696,7 +16698,7 @@ ${file}:${line}:${column}: ERROR: ${pluginText}${e.text}`;
16696
16698
  binPath = __require.resolve(`${pkg}/${subpath}`);
16697
16699
  } catch (e) {
16698
16700
  binPath = downloadedBinPath(pkg, subpath);
16699
- if (!fs50.existsSync(binPath)) {
16701
+ if (!fs48.existsSync(binPath)) {
16700
16702
  try {
16701
16703
  __require.resolve(pkg);
16702
16704
  } catch {
@@ -16770,17 +16772,17 @@ for your current platform.`);
16770
16772
  }
16771
16773
  if (pnpapi) {
16772
16774
  const root2 = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
16773
- const binTargetPath = path54.join(
16775
+ const binTargetPath = path55.join(
16774
16776
  root2,
16775
16777
  "node_modules",
16776
16778
  ".cache",
16777
16779
  "esbuild",
16778
- `pnpapi-${pkg.replace("/", "-")}-${"0.27.3"}-${path54.basename(subpath)}`
16780
+ `pnpapi-${pkg.replace("/", "-")}-${"0.27.3"}-${path55.basename(subpath)}`
16779
16781
  );
16780
- if (!fs50.existsSync(binTargetPath)) {
16781
- fs50.mkdirSync(path54.dirname(binTargetPath), { recursive: true });
16782
- fs50.copyFileSync(binPath, binTargetPath);
16783
- fs50.chmodSync(binTargetPath, 493);
16782
+ if (!fs48.existsSync(binTargetPath)) {
16783
+ fs48.mkdirSync(path55.dirname(binTargetPath), { recursive: true });
16784
+ fs48.copyFileSync(binPath, binTargetPath);
16785
+ fs48.chmodSync(binTargetPath, 493);
16784
16786
  }
16785
16787
  return { binPath: binTargetPath, isWASM };
16786
16788
  }
@@ -17830,7 +17832,7 @@ function generateCode(ast, options) {
17830
17832
  sourceMap = false,
17831
17833
  allWorkflows = [],
17832
17834
  moduleFormat = "esm",
17833
- externalRuntimePath,
17835
+ bundleMode = false,
17834
17836
  constants = [],
17835
17837
  externalNodeTypes = {},
17836
17838
  generateStubs = false,
@@ -17872,7 +17874,6 @@ function generateCode(ast, options) {
17872
17874
  });
17873
17875
  }
17874
17876
  };
17875
- const bundleMode = !!externalRuntimePath;
17876
17877
  const functionBody = bodyGenerator.generateWithExecutionContext(
17877
17878
  ast,
17878
17879
  ast.nodeTypes,
@@ -17885,26 +17886,7 @@ function generateCode(ast, options) {
17885
17886
  addLine();
17886
17887
  lines.push("");
17887
17888
  addLine();
17888
- if (externalRuntimePath) {
17889
- lines.push(`// Runtime imported from shared module`);
17890
- addLine();
17891
- lines.push(
17892
- generateImportStatement(
17893
- ["GeneratedExecutionContext", "CancellationError"],
17894
- externalRuntimePath,
17895
- moduleFormat
17896
- )
17897
- );
17898
- addLine();
17899
- if (!production) {
17900
- lines.push(
17901
- moduleFormat === "cjs" ? `const { TDebugger } = require('${externalRuntimePath}');` : `import type { TDebugger } from '${externalRuntimePath}';`
17902
- );
17903
- addLine();
17904
- }
17905
- lines.push("");
17906
- addLine();
17907
- } else {
17889
+ {
17908
17890
  const inlineRuntime = generateInlineRuntime(production);
17909
17891
  const runtimeLines = inlineRuntime.split("\n");
17910
17892
  runtimeLines.forEach((line) => {
@@ -17966,7 +17948,7 @@ function generateCode(ast, options) {
17966
17948
  lines.push("");
17967
17949
  addLine();
17968
17950
  functionImportsByFile.forEach((nodes, sourceFile) => {
17969
- if (externalRuntimePath) {
17951
+ if (bundleMode) {
17970
17952
  nodes.forEach((node) => {
17971
17953
  const lowerName = node.functionName.toLowerCase();
17972
17954
  const relativePath = `../node-types/${lowerName}.js`;
@@ -17984,7 +17966,7 @@ function generateCode(ast, options) {
17984
17966
  }
17985
17967
  });
17986
17968
  workflowImportsByFile.forEach((names, sourceFile) => {
17987
- if (externalRuntimePath) {
17969
+ if (bundleMode) {
17988
17970
  names.forEach((name) => {
17989
17971
  const relativePath = `./${name}.js`;
17990
17972
  lines.push(generateImportStatement([name], relativePath, moduleFormat));
@@ -18280,9 +18262,9 @@ var init_port_tag_utils = __esm({
18280
18262
  });
18281
18263
 
18282
18264
  // src/sugar-optimizer.ts
18283
- function validatePathMacro(path54, connections, instances, nodeTypes, startPorts, exitPorts) {
18265
+ function validatePathMacro(path55, connections, instances, nodeTypes, startPorts, exitPorts) {
18284
18266
  const instanceIds = new Set(instances.map((inst) => inst.id));
18285
- for (const step of path54.steps) {
18267
+ for (const step of path55.steps) {
18286
18268
  if (step.node === "Start" || step.node === "Exit") continue;
18287
18269
  if (!instanceIds.has(step.node)) return false;
18288
18270
  }
@@ -18292,9 +18274,9 @@ function validatePathMacro(path54, connections, instances, nodeTypes, startPorts
18292
18274
  connKeys.add(`${conn.from.node}.${conn.from.port}->${conn.to.node}.${conn.to.port}`);
18293
18275
  }
18294
18276
  }
18295
- for (let i = 0; i < path54.steps.length - 1; i++) {
18296
- const current2 = path54.steps[i];
18297
- const next = path54.steps[i + 1];
18277
+ for (let i = 0; i < path55.steps.length - 1; i++) {
18278
+ const current2 = path55.steps[i];
18279
+ const next = path55.steps[i + 1];
18298
18280
  const route = current2.route || "ok";
18299
18281
  let expectedKey;
18300
18282
  if (current2.node === "Start") {
@@ -18340,7 +18322,7 @@ function validatePathMacro(path54, connections, instances, nodeTypes, startPorts
18340
18322
  const nt = getNodeType2(nodeId);
18341
18323
  return nt?.inputs || {};
18342
18324
  };
18343
- const { steps } = path54;
18325
+ const { steps } = path55;
18344
18326
  for (let i = 0; i < steps.length - 1; i++) {
18345
18327
  const nextId = steps[i + 1].node;
18346
18328
  if (nextId === "Exit") continue;
@@ -18462,12 +18444,12 @@ function detectSugarPatterns(connections, instances, existingMacros, nodeTypes,
18462
18444
  }
18463
18445
  const candidateRoutes = [];
18464
18446
  const MAX_ROUTES = 20;
18465
- function dfs(node, path54, visited) {
18447
+ function dfs(node, path55, visited) {
18466
18448
  if (candidateRoutes.length >= MAX_ROUTES) return;
18467
18449
  if (node === "Exit") {
18468
- path54.push({ node: "Exit" });
18469
- candidateRoutes.push([...path54]);
18470
- path54.pop();
18450
+ path55.push({ node: "Exit" });
18451
+ candidateRoutes.push([...path55]);
18452
+ path55.pop();
18471
18453
  return;
18472
18454
  }
18473
18455
  if (visited.has(node)) return;
@@ -18479,15 +18461,15 @@ function detectSugarPatterns(connections, instances, existingMacros, nodeTypes,
18479
18461
  }
18480
18462
  if (edges.ok && !coveredByExistingMacro.has(edges.ok === "Exit" ? "" : edges.ok)) {
18481
18463
  const step = node === "Start" ? { node: "Start" } : { node };
18482
- path54.push(step);
18483
- dfs(edges.ok, path54, visited);
18484
- path54.pop();
18464
+ path55.push(step);
18465
+ dfs(edges.ok, path55, visited);
18466
+ path55.pop();
18485
18467
  }
18486
18468
  if (edges.fail && !coveredByExistingMacro.has(edges.fail === "Exit" ? "" : edges.fail)) {
18487
18469
  const step = { node, route: "fail" };
18488
- path54.push(step);
18489
- dfs(edges.fail, path54, visited);
18490
- path54.pop();
18470
+ path55.push(step);
18471
+ dfs(edges.fail, path55, visited);
18472
+ path55.pop();
18491
18473
  }
18492
18474
  visited.delete(node);
18493
18475
  }
@@ -19164,26 +19146,8 @@ var init_annotation_generator = __esm({
19164
19146
  // src/api/generate-in-place.ts
19165
19147
  import * as ts2 from "typescript";
19166
19148
  import * as path3 from "path";
19167
- import * as fs3 from "fs";
19168
- function isFlowWeaverPackageInstalled(startDir) {
19169
- let dir = startDir;
19170
- const root2 = path3.parse(dir).root;
19171
- while (dir !== root2) {
19172
- const candidate = path3.join(dir, "node_modules", "@synergenius", "flow-weaver");
19173
- try {
19174
- if (fs3.existsSync(candidate)) {
19175
- return true;
19176
- }
19177
- } catch {
19178
- }
19179
- const parent = path3.dirname(dir);
19180
- if (parent === dir) break;
19181
- dir = parent;
19182
- }
19183
- return false;
19184
- }
19185
19149
  function generateInPlace(sourceCode, ast, options = {}) {
19186
- const { production = false, allWorkflows, moduleFormat = "esm", inlineRuntime = false, sourceFile, skipParamReturns = false } = options;
19150
+ const { production = false, allWorkflows, moduleFormat = "esm", sourceFile, skipParamReturns = false } = options;
19187
19151
  let result = sourceCode;
19188
19152
  let hasChanges = false;
19189
19153
  for (const nodeType of ast.nodeTypes) {
@@ -19209,13 +19173,7 @@ function generateInPlace(sourceCode, ast, options = {}) {
19209
19173
  result = jsdocResult.code;
19210
19174
  hasChanges = true;
19211
19175
  }
19212
- let useExternalRuntime = false;
19213
- if (!inlineRuntime) {
19214
- const lookupDir = sourceFile ? path3.dirname(sourceFile) : ast.sourceFile ? path3.dirname(ast.sourceFile) : process.cwd();
19215
- useExternalRuntime = isFlowWeaverPackageInstalled(lookupDir);
19216
- }
19217
- const externalRuntimePath = useExternalRuntime ? "@synergenius/flow-weaver/runtime" : void 0;
19218
- const runtimeCode = generateRuntimeSection(ast.functionName, production, moduleFormat, externalRuntimePath);
19176
+ const runtimeCode = generateRuntimeSection(ast.functionName, production, moduleFormat);
19219
19177
  const runtimeResult = replaceOrInsertSection(
19220
19178
  result,
19221
19179
  MARKERS.RUNTIME_START,
@@ -19257,23 +19215,13 @@ function generateInPlace(sourceCode, ast, options = {}) {
19257
19215
  }
19258
19216
  return { code: result, hasChanges };
19259
19217
  }
19260
- function generateRuntimeSection(functionName, production, moduleFormat = "esm", externalRuntimePath) {
19218
+ function generateRuntimeSection(functionName, production, moduleFormat = "esm") {
19261
19219
  const lines = [];
19262
19220
  lines.push("// ============================================================================");
19263
19221
  lines.push("// DO NOT EDIT - This section is auto-generated by Flow Weaver");
19264
19222
  lines.push("// ============================================================================");
19265
19223
  lines.push("");
19266
- if (externalRuntimePath) {
19267
- lines.push(`import { GeneratedExecutionContext, CancellationError } from '${externalRuntimePath}';`);
19268
- if (!production) {
19269
- lines.push(`import type { TDebugger, TDebugController } from '${externalRuntimePath}';`);
19270
- lines.push("declare const __flowWeaverDebugger__: TDebugger | undefined;");
19271
- } else {
19272
- lines.push(`import type { TDebugController } from '${externalRuntimePath}';`);
19273
- }
19274
- } else {
19275
- lines.push(generateInlineRuntime(production));
19276
- }
19224
+ lines.push(generateInlineRuntime(production));
19277
19225
  return lines.join("\n");
19278
19226
  }
19279
19227
  function detectFunctionIsAsync(source, functionName) {
@@ -22106,11 +22054,11 @@ var init_toKey = __esm({
22106
22054
  });
22107
22055
 
22108
22056
  // node_modules/lodash-es/_baseGet.js
22109
- function baseGet(object3, path54) {
22110
- path54 = castPath_default(path54, object3);
22111
- var index = 0, length = path54.length;
22057
+ function baseGet(object3, path55) {
22058
+ path55 = castPath_default(path55, object3);
22059
+ var index = 0, length = path55.length;
22112
22060
  while (object3 != null && index < length) {
22113
- object3 = object3[toKey_default(path54[index++])];
22061
+ object3 = object3[toKey_default(path55[index++])];
22114
22062
  }
22115
22063
  return index && index == length ? object3 : void 0;
22116
22064
  }
@@ -22124,8 +22072,8 @@ var init_baseGet = __esm({
22124
22072
  });
22125
22073
 
22126
22074
  // node_modules/lodash-es/get.js
22127
- function get(object3, path54, defaultValue) {
22128
- var result = object3 == null ? void 0 : baseGet_default(object3, path54);
22075
+ function get(object3, path55, defaultValue) {
22076
+ var result = object3 == null ? void 0 : baseGet_default(object3, path55);
22129
22077
  return result === void 0 ? defaultValue : result;
22130
22078
  }
22131
22079
  var get_default;
@@ -23488,11 +23436,11 @@ var init_baseHasIn = __esm({
23488
23436
  });
23489
23437
 
23490
23438
  // node_modules/lodash-es/_hasPath.js
23491
- function hasPath(object3, path54, hasFunc) {
23492
- path54 = castPath_default(path54, object3);
23493
- var index = -1, length = path54.length, result = false;
23439
+ function hasPath(object3, path55, hasFunc) {
23440
+ path55 = castPath_default(path55, object3);
23441
+ var index = -1, length = path55.length, result = false;
23494
23442
  while (++index < length) {
23495
- var key = toKey_default(path54[index]);
23443
+ var key = toKey_default(path55[index]);
23496
23444
  if (!(result = object3 != null && hasFunc(object3, key))) {
23497
23445
  break;
23498
23446
  }
@@ -23518,8 +23466,8 @@ var init_hasPath = __esm({
23518
23466
  });
23519
23467
 
23520
23468
  // node_modules/lodash-es/hasIn.js
23521
- function hasIn(object3, path54) {
23522
- return object3 != null && hasPath_default(object3, path54, baseHasIn_default);
23469
+ function hasIn(object3, path55) {
23470
+ return object3 != null && hasPath_default(object3, path55, baseHasIn_default);
23523
23471
  }
23524
23472
  var hasIn_default;
23525
23473
  var init_hasIn = __esm({
@@ -23531,13 +23479,13 @@ var init_hasIn = __esm({
23531
23479
  });
23532
23480
 
23533
23481
  // node_modules/lodash-es/_baseMatchesProperty.js
23534
- function baseMatchesProperty(path54, srcValue) {
23535
- if (isKey_default(path54) && isStrictComparable_default(srcValue)) {
23536
- return matchesStrictComparable_default(toKey_default(path54), srcValue);
23482
+ function baseMatchesProperty(path55, srcValue) {
23483
+ if (isKey_default(path55) && isStrictComparable_default(srcValue)) {
23484
+ return matchesStrictComparable_default(toKey_default(path55), srcValue);
23537
23485
  }
23538
23486
  return function(object3) {
23539
- var objValue = get_default(object3, path54);
23540
- return objValue === void 0 && objValue === srcValue ? hasIn_default(object3, path54) : baseIsEqual_default(srcValue, objValue, COMPARE_PARTIAL_FLAG6 | COMPARE_UNORDERED_FLAG4);
23487
+ var objValue = get_default(object3, path55);
23488
+ return objValue === void 0 && objValue === srcValue ? hasIn_default(object3, path55) : baseIsEqual_default(srcValue, objValue, COMPARE_PARTIAL_FLAG6 | COMPARE_UNORDERED_FLAG4);
23541
23489
  };
23542
23490
  }
23543
23491
  var COMPARE_PARTIAL_FLAG6, COMPARE_UNORDERED_FLAG4, baseMatchesProperty_default;
@@ -23570,9 +23518,9 @@ var init_baseProperty = __esm({
23570
23518
  });
23571
23519
 
23572
23520
  // node_modules/lodash-es/_basePropertyDeep.js
23573
- function basePropertyDeep(path54) {
23521
+ function basePropertyDeep(path55) {
23574
23522
  return function(object3) {
23575
- return baseGet_default(object3, path54);
23523
+ return baseGet_default(object3, path55);
23576
23524
  };
23577
23525
  }
23578
23526
  var basePropertyDeep_default;
@@ -23584,8 +23532,8 @@ var init_basePropertyDeep = __esm({
23584
23532
  });
23585
23533
 
23586
23534
  // node_modules/lodash-es/property.js
23587
- function property(path54) {
23588
- return isKey_default(path54) ? baseProperty_default(toKey_default(path54)) : basePropertyDeep_default(path54);
23535
+ function property(path55) {
23536
+ return isKey_default(path55) ? baseProperty_default(toKey_default(path55)) : basePropertyDeep_default(path55);
23589
23537
  }
23590
23538
  var property_default;
23591
23539
  var init_property = __esm({
@@ -24204,8 +24152,8 @@ var init_baseHas = __esm({
24204
24152
  });
24205
24153
 
24206
24154
  // node_modules/lodash-es/has.js
24207
- function has(object3, path54) {
24208
- return object3 != null && hasPath_default(object3, path54, baseHas_default);
24155
+ function has(object3, path55) {
24156
+ return object3 != null && hasPath_default(object3, path55, baseHas_default);
24209
24157
  }
24210
24158
  var has_default;
24211
24159
  var init_has = __esm({
@@ -24411,14 +24359,14 @@ var init_negate = __esm({
24411
24359
  });
24412
24360
 
24413
24361
  // node_modules/lodash-es/_baseSet.js
24414
- function baseSet(object3, path54, value, customizer) {
24362
+ function baseSet(object3, path55, value, customizer) {
24415
24363
  if (!isObject_default(object3)) {
24416
24364
  return object3;
24417
24365
  }
24418
- path54 = castPath_default(path54, object3);
24419
- var index = -1, length = path54.length, lastIndex = length - 1, nested = object3;
24366
+ path55 = castPath_default(path55, object3);
24367
+ var index = -1, length = path55.length, lastIndex = length - 1, nested = object3;
24420
24368
  while (nested != null && ++index < length) {
24421
- var key = toKey_default(path54[index]), newValue = value;
24369
+ var key = toKey_default(path55[index]), newValue = value;
24422
24370
  if (key === "__proto__" || key === "constructor" || key === "prototype") {
24423
24371
  return object3;
24424
24372
  }
@@ -24426,7 +24374,7 @@ function baseSet(object3, path54, value, customizer) {
24426
24374
  var objValue = nested[key];
24427
24375
  newValue = customizer ? customizer(objValue, key, nested) : void 0;
24428
24376
  if (newValue === void 0) {
24429
- newValue = isObject_default(objValue) ? objValue : isIndex_default(path54[index + 1]) ? [] : {};
24377
+ newValue = isObject_default(objValue) ? objValue : isIndex_default(path55[index + 1]) ? [] : {};
24430
24378
  }
24431
24379
  }
24432
24380
  assignValue_default(nested, key, newValue);
@@ -24450,9 +24398,9 @@ var init_baseSet = __esm({
24450
24398
  function basePickBy(object3, paths, predicate) {
24451
24399
  var index = -1, length = paths.length, result = {};
24452
24400
  while (++index < length) {
24453
- var path54 = paths[index], value = baseGet_default(object3, path54);
24454
- if (predicate(value, path54)) {
24455
- baseSet_default(result, castPath_default(path54, object3), value);
24401
+ var path55 = paths[index], value = baseGet_default(object3, path55);
24402
+ if (predicate(value, path55)) {
24403
+ baseSet_default(result, castPath_default(path55, object3), value);
24456
24404
  }
24457
24405
  }
24458
24406
  return result;
@@ -24476,8 +24424,8 @@ function pickBy(object3, predicate) {
24476
24424
  return [prop];
24477
24425
  });
24478
24426
  predicate = baseIteratee_default(predicate);
24479
- return basePickBy_default(object3, props, function(value, path54) {
24480
- return predicate(value, path54[0]);
24427
+ return basePickBy_default(object3, props, function(value, path55) {
24428
+ return predicate(value, path55[0]);
24481
24429
  });
24482
24430
  }
24483
24431
  var pickBy_default;
@@ -27224,12 +27172,12 @@ function assignCategoriesMapProp(tokenTypes) {
27224
27172
  singleAssignCategoriesToksMap([], currTokType);
27225
27173
  });
27226
27174
  }
27227
- function singleAssignCategoriesToksMap(path54, nextNode) {
27228
- forEach_default(path54, (pathNode) => {
27175
+ function singleAssignCategoriesToksMap(path55, nextNode) {
27176
+ forEach_default(path55, (pathNode) => {
27229
27177
  nextNode.categoryMatchesMap[pathNode.tokenTypeIdx] = true;
27230
27178
  });
27231
27179
  forEach_default(nextNode.CATEGORIES, (nextCategory) => {
27232
- const newPath = path54.concat(nextNode);
27180
+ const newPath = path55.concat(nextNode);
27233
27181
  if (!includes_default(newPath, nextCategory)) {
27234
27182
  singleAssignCategoriesToksMap(newPath, nextCategory);
27235
27183
  }
@@ -28399,10 +28347,10 @@ var init_interpreter = __esm({
28399
28347
  init_rest();
28400
28348
  init_api2();
28401
28349
  AbstractNextPossibleTokensWalker = class extends RestWalker {
28402
- constructor(topProd, path54) {
28350
+ constructor(topProd, path55) {
28403
28351
  super();
28404
28352
  this.topProd = topProd;
28405
- this.path = path54;
28353
+ this.path = path55;
28406
28354
  this.possibleTokTypes = [];
28407
28355
  this.nextProductionName = "";
28408
28356
  this.nextProductionOccurrence = 0;
@@ -28446,9 +28394,9 @@ var init_interpreter = __esm({
28446
28394
  }
28447
28395
  };
28448
28396
  NextAfterTokenWalker = class extends AbstractNextPossibleTokensWalker {
28449
- constructor(topProd, path54) {
28450
- super(topProd, path54);
28451
- this.path = path54;
28397
+ constructor(topProd, path55) {
28398
+ super(topProd, path55);
28399
+ this.path = path55;
28452
28400
  this.nextTerminalName = "";
28453
28401
  this.nextTerminalOccurrence = 0;
28454
28402
  this.nextTerminalName = this.path.lastTok.name;
@@ -28689,10 +28637,10 @@ function initializeArrayOfArrays(size) {
28689
28637
  }
28690
28638
  return result;
28691
28639
  }
28692
- function pathToHashKeys(path54) {
28640
+ function pathToHashKeys(path55) {
28693
28641
  let keys2 = [""];
28694
- for (let i = 0; i < path54.length; i++) {
28695
- const tokType = path54[i];
28642
+ for (let i = 0; i < path55.length; i++) {
28643
+ const tokType = path55[i];
28696
28644
  const longerKeys = [];
28697
28645
  for (let j = 0; j < keys2.length; j++) {
28698
28646
  const currShorterKey = keys2[j];
@@ -28995,7 +28943,7 @@ function validateRuleIsOverridden(ruleName, definedRulesNames, className) {
28995
28943
  }
28996
28944
  return errors2;
28997
28945
  }
28998
- function validateNoLeftRecursion(topRule, currRule, errMsgProvider, path54 = []) {
28946
+ function validateNoLeftRecursion(topRule, currRule, errMsgProvider, path55 = []) {
28999
28947
  const errors2 = [];
29000
28948
  const nextNonTerminals = getFirstNoneTerminal(currRule.definition);
29001
28949
  if (isEmpty_default(nextNonTerminals)) {
@@ -29007,15 +28955,15 @@ function validateNoLeftRecursion(topRule, currRule, errMsgProvider, path54 = [])
29007
28955
  errors2.push({
29008
28956
  message: errMsgProvider.buildLeftRecursionError({
29009
28957
  topLevelRule: topRule,
29010
- leftRecursionPath: path54
28958
+ leftRecursionPath: path55
29011
28959
  }),
29012
28960
  type: ParserDefinitionErrorType.LEFT_RECURSION,
29013
28961
  ruleName
29014
28962
  });
29015
28963
  }
29016
- const validNextSteps = difference_default(nextNonTerminals, path54.concat([topRule]));
28964
+ const validNextSteps = difference_default(nextNonTerminals, path55.concat([topRule]));
29017
28965
  const errorsFromNextSteps = flatMap_default(validNextSteps, (currRefRule) => {
29018
- const newPath = clone_default(path54);
28966
+ const newPath = clone_default(path55);
29019
28967
  newPath.push(currRefRule);
29020
28968
  return validateNoLeftRecursion(topRule, currRefRule, errMsgProvider, newPath);
29021
28969
  });
@@ -34006,8 +33954,8 @@ function itemToEBNF(item) {
34006
33954
  const sepName = item.separator?.name || ",";
34007
33955
  return `${definitionToEBNF(item.definition || [])} { "${sepName === "Comma" ? "," : sepName}" ${definitionToEBNF(item.definition || [])} }`;
34008
33956
  case "RepetitionWithSeparator":
34009
- const sep3 = item.separator?.name || ",";
34010
- return `[ ${definitionToEBNF(item.definition || [])} { "${sep3 === "Comma" ? "," : sep3}" ${definitionToEBNF(item.definition || [])} } ]`;
33957
+ const sep4 = item.separator?.name || ",";
33958
+ return `[ ${definitionToEBNF(item.definition || [])} { "${sep4 === "Comma" ? "," : sep4}" ${definitionToEBNF(item.definition || [])} } ]`;
34011
33959
  default:
34012
33960
  return `/* ${item.type} */`;
34013
33961
  }
@@ -35277,7 +35225,7 @@ var init_port_ordering = __esm({
35277
35225
 
35278
35226
  // src/resolve-package-types.ts
35279
35227
  import * as path4 from "node:path";
35280
- import * as fs4 from "node:fs";
35228
+ import * as fs3 from "node:fs";
35281
35229
  function resolvePackageTypesPath(packageSpecifier, fromDir, nodeModulesOverride) {
35282
35230
  const nodeModulesDirs = nodeModulesOverride ? [nodeModulesOverride] : findNodeModulesDirs(fromDir);
35283
35231
  for (const nmDir of nodeModulesDirs) {
@@ -35292,7 +35240,7 @@ function findNodeModulesDirs(fromDir) {
35292
35240
  const root2 = path4.parse(current2).root;
35293
35241
  while (current2 !== root2) {
35294
35242
  const candidate = path4.join(current2, "node_modules");
35295
- if (fs4.existsSync(candidate) && fs4.statSync(candidate).isDirectory()) {
35243
+ if (fs3.existsSync(candidate) && fs3.statSync(candidate).isDirectory()) {
35296
35244
  dirs.push(candidate);
35297
35245
  }
35298
35246
  const parent = path4.dirname(current2);
@@ -35309,14 +35257,14 @@ function resolveExportsTypes(exports2, pkgDir) {
35309
35257
  const rootObj = root2;
35310
35258
  if (typeof rootObj.types === "string") {
35311
35259
  const typesPath = path4.resolve(pkgDir, rootObj.types);
35312
- if (fs4.existsSync(typesPath)) {
35260
+ if (fs3.existsSync(typesPath)) {
35313
35261
  return typesPath;
35314
35262
  }
35315
35263
  }
35316
35264
  }
35317
35265
  if (typeof exportsObj.types === "string") {
35318
35266
  const typesPath = path4.resolve(pkgDir, exportsObj.types);
35319
- if (fs4.existsSync(typesPath)) {
35267
+ if (fs3.existsSync(typesPath)) {
35320
35268
  return typesPath;
35321
35269
  }
35322
35270
  }
@@ -35325,13 +35273,13 @@ function resolveExportsTypes(exports2, pkgDir) {
35325
35273
  function resolveInNodeModules(packageSpecifier, nmDir) {
35326
35274
  const pkgDir = path4.join(nmDir, packageSpecifier);
35327
35275
  const pkgJsonPath = path4.join(pkgDir, "package.json");
35328
- if (fs4.existsSync(pkgJsonPath)) {
35276
+ if (fs3.existsSync(pkgJsonPath)) {
35329
35277
  try {
35330
- const pkgJson = JSON.parse(fs4.readFileSync(pkgJsonPath, "utf-8"));
35278
+ const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
35331
35279
  const typesField = pkgJson.types || pkgJson.typings;
35332
35280
  if (typesField) {
35333
35281
  const typesPath = path4.resolve(pkgDir, typesField);
35334
- if (fs4.existsSync(typesPath)) {
35282
+ if (fs3.existsSync(typesPath)) {
35335
35283
  return typesPath;
35336
35284
  }
35337
35285
  }
@@ -35346,11 +35294,11 @@ function resolveInNodeModules(packageSpecifier, nmDir) {
35346
35294
  }
35347
35295
  const atTypesName = packageSpecifier.startsWith("@") ? packageSpecifier.replace("@", "").replace("/", "__") : packageSpecifier;
35348
35296
  const atTypesPath = path4.join(nmDir, "@types", atTypesName, "index.d.ts");
35349
- if (fs4.existsSync(atTypesPath)) {
35297
+ if (fs3.existsSync(atTypesPath)) {
35350
35298
  return atTypesPath;
35351
35299
  }
35352
35300
  const indexDtsPath = path4.join(pkgDir, "index.d.ts");
35353
- if (fs4.existsSync(indexDtsPath)) {
35301
+ if (fs3.existsSync(indexDtsPath)) {
35354
35302
  return indexDtsPath;
35355
35303
  }
35356
35304
  return null;
@@ -35554,7 +35502,7 @@ __export(registry_exports, {
35554
35502
  listInstalledPackages: () => listInstalledPackages,
35555
35503
  searchPackages: () => searchPackages
35556
35504
  });
35557
- import * as fs5 from "fs";
35505
+ import * as fs4 from "fs";
35558
35506
  import * as path5 from "path";
35559
35507
  async function searchPackages(options = {}) {
35560
35508
  const { query, limit = 20, registryUrl } = options;
@@ -35581,7 +35529,7 @@ async function searchPackages(options = {}) {
35581
35529
  }
35582
35530
  async function listInstalledPackages(projectDir) {
35583
35531
  const nodeModules = path5.join(projectDir, "node_modules");
35584
- if (!fs5.existsSync(nodeModules)) return [];
35532
+ if (!fs4.existsSync(nodeModules)) return [];
35585
35533
  const patterns = [
35586
35534
  path5.join(nodeModules, "flow-weaver-pack-*", "flowweaver.manifest.json"),
35587
35535
  path5.join(nodeModules, "@*", "flow-weaver-pack-*", "flowweaver.manifest.json")
@@ -35593,12 +35541,12 @@ async function listInstalledPackages(projectDir) {
35593
35541
  try {
35594
35542
  const pkgDir = path5.dirname(manifestPath);
35595
35543
  const manifest = JSON.parse(
35596
- fs5.readFileSync(manifestPath, "utf-8")
35544
+ fs4.readFileSync(manifestPath, "utf-8")
35597
35545
  );
35598
35546
  const pkgJsonPath = path5.join(pkgDir, "package.json");
35599
35547
  let version3 = manifest.version;
35600
- if (fs5.existsSync(pkgJsonPath)) {
35601
- const pkg = JSON.parse(fs5.readFileSync(pkgJsonPath, "utf-8"));
35548
+ if (fs4.existsSync(pkgJsonPath)) {
35549
+ const pkg = JSON.parse(fs4.readFileSync(pkgJsonPath, "utf-8"));
35602
35550
  version3 = pkg.version ?? manifest.version;
35603
35551
  }
35604
35552
  results.push({
@@ -35616,9 +35564,9 @@ async function listInstalledPackages(projectDir) {
35616
35564
  function getInstalledPackageManifest(projectDir, packageName) {
35617
35565
  const packageDir = path5.join(projectDir, "node_modules", packageName);
35618
35566
  const manifestPath = path5.join(packageDir, "flowweaver.manifest.json");
35619
- if (!fs5.existsSync(manifestPath)) return null;
35567
+ if (!fs4.existsSync(manifestPath)) return null;
35620
35568
  try {
35621
- return JSON.parse(fs5.readFileSync(manifestPath, "utf-8"));
35569
+ return JSON.parse(fs4.readFileSync(manifestPath, "utf-8"));
35622
35570
  } catch {
35623
35571
  return null;
35624
35572
  }
@@ -35757,7 +35705,7 @@ var init_validation_registry = __esm({
35757
35705
 
35758
35706
  // src/parser.ts
35759
35707
  import * as path6 from "node:path";
35760
- import * as fs6 from "node:fs";
35708
+ import * as fs5 from "node:fs";
35761
35709
  import { createHash } from "node:crypto";
35762
35710
  function externalToAST(ext2) {
35763
35711
  const inputs = {};
@@ -35910,7 +35858,7 @@ var init_parser2 = __esm({
35910
35858
  warnings: [...cached2.result.warnings, ...warnings]
35911
35859
  };
35912
35860
  this.parseCache.set(filePath, {
35913
- mtime: fs6.statSync(filePath).mtimeMs,
35861
+ mtime: fs5.statSync(filePath).mtimeMs,
35914
35862
  contentHash: this.computeHash(newContent),
35915
35863
  result
35916
35864
  });
@@ -35920,14 +35868,14 @@ var init_parser2 = __esm({
35920
35868
  }
35921
35869
  }
35922
35870
  parse(filePath, externalNodeTypes) {
35923
- const stats = fs6.statSync(filePath);
35871
+ const stats = fs5.statSync(filePath);
35924
35872
  const hasExternalTypes = externalNodeTypes && externalNodeTypes.length > 0;
35925
35873
  if (!hasExternalTypes) {
35926
35874
  const cached2 = this.parseCache.get(filePath);
35927
35875
  if (cached2 && cached2.mtime === stats.mtimeMs) {
35928
35876
  return cached2.result;
35929
35877
  }
35930
- const rawContent2 = fs6.readFileSync(filePath, "utf-8");
35878
+ const rawContent2 = fs5.readFileSync(filePath, "utf-8");
35931
35879
  const content2 = hasInPlaceMarkers(rawContent2) ? stripGeneratedSections(rawContent2) : rawContent2;
35932
35880
  const hash2 = this.computeHash(content2);
35933
35881
  if (cached2 && cached2.contentHash === hash2) {
@@ -35936,7 +35884,7 @@ var init_parser2 = __esm({
35936
35884
  }
35937
35885
  return this.fullParse(filePath, content2, hash2, stats.mtimeMs);
35938
35886
  }
35939
- const rawContent = fs6.readFileSync(filePath, "utf-8");
35887
+ const rawContent = fs5.readFileSync(filePath, "utf-8");
35940
35888
  const content = hasInPlaceMarkers(rawContent) ? stripGeneratedSections(rawContent) : rawContent;
35941
35889
  const hash = this.computeHash(content);
35942
35890
  return this.fullParse(filePath, content, hash, stats.mtimeMs, externalNodeTypes);
@@ -36029,33 +35977,33 @@ var init_parser2 = __esm({
36029
35977
  const hasExtension = extensions.some((ext2) => moduleSpecifier.endsWith(ext2));
36030
35978
  if (hasExtension) {
36031
35979
  const fullPath = path6.resolve(currentDir, moduleSpecifier);
36032
- if (fs6.existsSync(fullPath)) return fullPath;
35980
+ if (fs5.existsSync(fullPath)) return fullPath;
36033
35981
  if (moduleSpecifier.endsWith(".js")) {
36034
35982
  const tsPath = fullPath.replace(/\.js$/, ".ts");
36035
- if (fs6.existsSync(tsPath)) return tsPath;
35983
+ if (fs5.existsSync(tsPath)) return tsPath;
36036
35984
  const tsxPath = fullPath.replace(/\.js$/, ".tsx");
36037
- if (fs6.existsSync(tsxPath)) return tsxPath;
35985
+ if (fs5.existsSync(tsxPath)) return tsxPath;
36038
35986
  } else if (moduleSpecifier.endsWith(".jsx")) {
36039
35987
  const tsxPath = fullPath.replace(/\.jsx$/, ".tsx");
36040
- if (fs6.existsSync(tsxPath)) return tsxPath;
35988
+ if (fs5.existsSync(tsxPath)) return tsxPath;
36041
35989
  }
36042
35990
  return null;
36043
35991
  }
36044
35992
  for (const ext2 of extensions) {
36045
35993
  const fullPath = path6.resolve(currentDir, moduleSpecifier + ext2);
36046
- if (fs6.existsSync(fullPath)) {
35994
+ if (fs5.existsSync(fullPath)) {
36047
35995
  return fullPath;
36048
35996
  }
36049
35997
  }
36050
35998
  const dirPath = path6.resolve(currentDir, moduleSpecifier);
36051
- if (fs6.existsSync(dirPath) && fs6.statSync(dirPath).isDirectory()) {
35999
+ if (fs5.existsSync(dirPath) && fs5.statSync(dirPath).isDirectory()) {
36052
36000
  const pkgPath = path6.join(dirPath, "package.json");
36053
- if (fs6.existsSync(pkgPath)) {
36001
+ if (fs5.existsSync(pkgPath)) {
36054
36002
  try {
36055
- const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
36003
+ const pkg = JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
36056
36004
  if (pkg.main) {
36057
36005
  const mainPath = path6.resolve(dirPath, pkg.main);
36058
- if (fs6.existsSync(mainPath)) {
36006
+ if (fs5.existsSync(mainPath)) {
36059
36007
  return mainPath;
36060
36008
  }
36061
36009
  }
@@ -36065,7 +36013,7 @@ var init_parser2 = __esm({
36065
36013
  }
36066
36014
  for (const ext2 of extensions) {
36067
36015
  const indexPath = path6.join(dirPath, `index${ext2}`);
36068
- if (fs6.existsSync(indexPath)) {
36016
+ if (fs5.existsSync(indexPath)) {
36069
36017
  return indexPath;
36070
36018
  }
36071
36019
  }
@@ -36110,7 +36058,7 @@ var init_parser2 = __esm({
36110
36058
  } else {
36111
36059
  this.importStack.add(importedFilePath);
36112
36060
  try {
36113
- const importedRaw = fs6.readFileSync(importedFilePath, "utf-8");
36061
+ const importedRaw = fs5.readFileSync(importedFilePath, "utf-8");
36114
36062
  const importedContent = hasInPlaceMarkers(importedRaw) ? stripGeneratedSections(importedRaw) : importedRaw;
36115
36063
  const importedFile = this.project.createSourceFile(importedFilePath, importedContent, {
36116
36064
  overwrite: true
@@ -36178,7 +36126,7 @@ var init_parser2 = __esm({
36178
36126
  const dtsPath = resolvePackageTypesPath(moduleSpecifier, currentDir);
36179
36127
  if (!dtsPath) return [];
36180
36128
  try {
36181
- const dtsContent = fs6.readFileSync(dtsPath, "utf-8");
36129
+ const dtsContent = fs5.readFileSync(dtsPath, "utf-8");
36182
36130
  const dtsFile = this.project.createSourceFile(
36183
36131
  `__npm_dts__/${moduleSpecifier}.d.ts`,
36184
36132
  dtsContent,
@@ -36239,7 +36187,7 @@ var init_parser2 = __esm({
36239
36187
  }
36240
36188
  this.importStack.add(importedFilePath);
36241
36189
  try {
36242
- const importedContent = fs6.readFileSync(importedFilePath, "utf-8");
36190
+ const importedContent = fs5.readFileSync(importedFilePath, "utf-8");
36243
36191
  const importedFile = this.project.createSourceFile(importedFilePath, importedContent, {
36244
36192
  overwrite: true
36245
36193
  });
@@ -36277,7 +36225,7 @@ var init_parser2 = __esm({
36277
36225
  return this.createImportStub(imp);
36278
36226
  }
36279
36227
  try {
36280
- const dtsContent = fs6.readFileSync(dtsPath, "utf-8");
36228
+ const dtsContent = fs5.readFileSync(dtsPath, "utf-8");
36281
36229
  const dtsFile = this.project.createSourceFile(
36282
36230
  `__npm_dts__/${imp.importSource}.d.ts`,
36283
36231
  dtsContent,
@@ -39259,13 +39207,13 @@ Add '@param ${fromPort}' to the workflow JSDoc and include it in the params obje
39259
39207
  connections.filter((c) => c.from.node === c.to.node).map((c) => c.from.node)
39260
39208
  );
39261
39209
  const nonSelfLoopConnections = connections.filter((c) => c.from.node !== c.to.node);
39262
- const dfs = (nodeName, path54) => {
39210
+ const dfs = (nodeName, path55) => {
39263
39211
  if (recursionStack.has(nodeName)) {
39264
39212
  if (selfLoopNodes.has(nodeName)) {
39265
39213
  return false;
39266
39214
  }
39267
- const cycleStart = path54.indexOf(nodeName);
39268
- const cyclePath = [...path54.slice(cycleStart), nodeName];
39215
+ const cycleStart = path55.indexOf(nodeName);
39216
+ const cyclePath = [...path55.slice(cycleStart), nodeName];
39269
39217
  const cycleNodes = cyclePath.slice(0, -1);
39270
39218
  const sortedCycle = [...cycleNodes].sort();
39271
39219
  const cycleKey = sortedCycle.join(",");
@@ -39287,7 +39235,7 @@ Add '@param ${fromPort}' to the workflow JSDoc and include it in the params obje
39287
39235
  return false;
39288
39236
  }
39289
39237
  recursionStack.add(nodeName);
39290
- const newPath = [...path54, nodeName];
39238
+ const newPath = [...path55, nodeName];
39291
39239
  const instance = instances.find((n) => n.id === nodeName);
39292
39240
  if (!instance) {
39293
39241
  recursionStack.delete(nodeName);
@@ -40523,14 +40471,14 @@ __export(serialization_node_exports, {
40523
40471
  saveAST: () => saveAST,
40524
40472
  saveASTAlongside: () => saveASTAlongside
40525
40473
  });
40526
- import * as fs7 from "node:fs/promises";
40474
+ import * as fs6 from "node:fs/promises";
40527
40475
  import * as path7 from "node:path";
40528
40476
  async function saveAST(ast, filePath) {
40529
40477
  const json2 = serializeAST(ast, true);
40530
- await fs7.writeFile(filePath, json2, "utf-8");
40478
+ await fs6.writeFile(filePath, json2, "utf-8");
40531
40479
  }
40532
40480
  async function loadAST(filePath) {
40533
- const json2 = await fs7.readFile(filePath, "utf-8");
40481
+ const json2 = await fs6.readFile(filePath, "utf-8");
40534
40482
  return deserializeAST(json2);
40535
40483
  }
40536
40484
  async function saveASTAlongside(ast) {
@@ -40555,7 +40503,7 @@ var init_serialization_node = __esm({
40555
40503
  });
40556
40504
 
40557
40505
  // src/api/compile.ts
40558
- import * as fs8 from "node:fs/promises";
40506
+ import * as fs7 from "node:fs/promises";
40559
40507
  import * as path8 from "node:path";
40560
40508
  async function compileWorkflow(filePath, options = {}) {
40561
40509
  const startTime = Date.now();
@@ -40577,7 +40525,7 @@ ${errorMessages.join("\n")}`);
40577
40525
  let code;
40578
40526
  let outputFile;
40579
40527
  if (inPlace) {
40580
- const sourceCode = await fs8.readFile(filePath, "utf-8");
40528
+ const sourceCode = await fs7.readFile(filePath, "utf-8");
40581
40529
  const result2 = generateInPlace(sourceCode, parseResult.ast, {
40582
40530
  ...options.generate,
40583
40531
  allWorkflows: parseResult.allWorkflows,
@@ -40586,13 +40534,13 @@ ${errorMessages.join("\n")}`);
40586
40534
  code = result2.code;
40587
40535
  outputFile = filePath;
40588
40536
  if (options.write !== false) {
40589
- await fs8.writeFile(filePath, code, "utf-8");
40537
+ await fs7.writeFile(filePath, code, "utf-8");
40590
40538
  }
40591
40539
  } else {
40592
40540
  code = generateCode(parseResult.ast, options.generate);
40593
40541
  outputFile = options.outputFile || getDefaultOutputFile(filePath);
40594
40542
  if (options.write !== false) {
40595
- await fs8.writeFile(outputFile, code, "utf-8");
40543
+ await fs7.writeFile(outputFile, code, "utf-8");
40596
40544
  }
40597
40545
  }
40598
40546
  if (options.saveAST) {
@@ -40872,7 +40820,7 @@ function processResult(result, scope) {
40872
40820
  }
40873
40821
  return result !== NOTHING ? result : void 0;
40874
40822
  }
40875
- function finalize(rootScope, value, path54) {
40823
+ function finalize(rootScope, value, path55) {
40876
40824
  if (isFrozen(value))
40877
40825
  return value;
40878
40826
  const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
@@ -40880,7 +40828,7 @@ function finalize(rootScope, value, path54) {
40880
40828
  if (!state) {
40881
40829
  each(
40882
40830
  value,
40883
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path54),
40831
+ (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path55),
40884
40832
  useStrictIteration
40885
40833
  );
40886
40834
  return value;
@@ -40910,16 +40858,16 @@ function finalize(rootScope, value, path54) {
40910
40858
  result,
40911
40859
  key,
40912
40860
  childValue,
40913
- path54,
40861
+ path55,
40914
40862
  isSet22
40915
40863
  ),
40916
40864
  useStrictIteration
40917
40865
  );
40918
40866
  maybeFreeze(rootScope, result, false);
40919
- if (path54 && rootScope.patches_) {
40867
+ if (path55 && rootScope.patches_) {
40920
40868
  getPlugin("Patches").generatePatches_(
40921
40869
  state,
40922
- path54,
40870
+ path55,
40923
40871
  rootScope.patches_,
40924
40872
  rootScope.inversePatches_
40925
40873
  );
@@ -40941,9 +40889,9 @@ function finalizeProperty(rootScope, parentState, targetObject, prop, childValue
40941
40889
  if (process.env.NODE_ENV !== "production" && childValue === targetObject)
40942
40890
  die(5);
40943
40891
  if (isDraft(childValue)) {
40944
- const path54 = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
40892
+ const path55 = rootPath && parentState && parentState.type_ !== 3 && // Set objects are atomic since they have no keys.
40945
40893
  !has2(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0;
40946
- const res = finalize(rootScope, childValue, path54);
40894
+ const res = finalize(rootScope, childValue, path55);
40947
40895
  set(targetObject, prop, res);
40948
40896
  if (isDraft(res)) {
40949
40897
  rootScope.canAutoFreeze_ = false;
@@ -42333,8 +42281,8 @@ var init_parseUtil = __esm({
42333
42281
  init_errors();
42334
42282
  init_en();
42335
42283
  makeIssue = (params) => {
42336
- const { data, path: path54, errorMaps, issueData } = params;
42337
- const fullPath = [...path54, ...issueData.path || []];
42284
+ const { data, path: path55, errorMaps, issueData } = params;
42285
+ const fullPath = [...path55, ...issueData.path || []];
42338
42286
  const fullIssue = {
42339
42287
  ...issueData,
42340
42288
  path: fullPath
@@ -42642,11 +42590,11 @@ var init_types = __esm({
42642
42590
  init_parseUtil();
42643
42591
  init_util();
42644
42592
  ParseInputLazyPath = class {
42645
- constructor(parent, value, path54, key) {
42593
+ constructor(parent, value, path55, key) {
42646
42594
  this._cachedPath = [];
42647
42595
  this.parent = parent;
42648
42596
  this.data = value;
42649
- this._path = path54;
42597
+ this._path = path55;
42650
42598
  this._key = key;
42651
42599
  }
42652
42600
  get path() {
@@ -54570,7 +54518,7 @@ __export(doctor_exports, {
54570
54518
  runDoctorChecks: () => runDoctorChecks,
54571
54519
  stripJsonComments: () => stripJsonComments
54572
54520
  });
54573
- import * as fs9 from "fs";
54521
+ import * as fs8 from "fs";
54574
54522
  import * as path9 from "path";
54575
54523
  import { execSync } from "child_process";
54576
54524
  function stripJsonComments(text) {
@@ -54605,9 +54553,9 @@ function stripJsonComments(text) {
54605
54553
  }
54606
54554
  function detectProjectModuleFormat(cwd) {
54607
54555
  const pkgPath = path9.join(cwd, "package.json");
54608
- if (fs9.existsSync(pkgPath)) {
54556
+ if (fs8.existsSync(pkgPath)) {
54609
54557
  try {
54610
- const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
54558
+ const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf8"));
54611
54559
  if (pkg.type === "module") {
54612
54560
  return { format: "esm", source: "package.json", details: '"type": "module"' };
54613
54561
  }
@@ -54622,9 +54570,9 @@ function detectProjectModuleFormat(cwd) {
54622
54570
  }
54623
54571
  }
54624
54572
  const tsconfigPath = path9.join(cwd, "tsconfig.json");
54625
- if (fs9.existsSync(tsconfigPath)) {
54573
+ if (fs8.existsSync(tsconfigPath)) {
54626
54574
  try {
54627
- const raw = fs9.readFileSync(tsconfigPath, "utf8");
54575
+ const raw = fs8.readFileSync(tsconfigPath, "utf8");
54628
54576
  const parsed = JSON.parse(stripJsonComments(raw));
54629
54577
  const compilerOptions = parsed.compilerOptions ?? {};
54630
54578
  const mod = typeof compilerOptions.module === "string" ? compilerOptions.module.toLowerCase() : void 0;
@@ -54661,7 +54609,7 @@ function checkNodeVersion() {
54661
54609
  }
54662
54610
  function checkTypeScriptVersion(cwd) {
54663
54611
  const tsPath = path9.join(cwd, "node_modules", "typescript", "package.json");
54664
- if (!fs9.existsSync(tsPath)) {
54612
+ if (!fs8.existsSync(tsPath)) {
54665
54613
  return {
54666
54614
  name: "TypeScript version",
54667
54615
  status: "fail",
@@ -54670,7 +54618,7 @@ function checkTypeScriptVersion(cwd) {
54670
54618
  };
54671
54619
  }
54672
54620
  try {
54673
- const tsPkg = JSON.parse(fs9.readFileSync(tsPath, "utf8"));
54621
+ const tsPkg = JSON.parse(fs8.readFileSync(tsPath, "utf8"));
54674
54622
  const major = parseInt(tsPkg.version.split(".")[0], 10);
54675
54623
  if (major >= 5) {
54676
54624
  return {
@@ -54696,7 +54644,7 @@ function checkTypeScriptVersion(cwd) {
54696
54644
  }
54697
54645
  function checkPackageJsonType(cwd) {
54698
54646
  const pkgPath = path9.join(cwd, "package.json");
54699
- if (!fs9.existsSync(pkgPath)) {
54647
+ if (!fs8.existsSync(pkgPath)) {
54700
54648
  return {
54701
54649
  name: 'package.json "type"',
54702
54650
  status: "fail",
@@ -54705,7 +54653,7 @@ function checkPackageJsonType(cwd) {
54705
54653
  };
54706
54654
  }
54707
54655
  try {
54708
- const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
54656
+ const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf8"));
54709
54657
  if (pkg.type === "module") {
54710
54658
  return {
54711
54659
  name: 'package.json "type"',
@@ -54737,11 +54685,11 @@ function checkPackageJsonType(cwd) {
54737
54685
  }
54738
54686
  function readTsconfig(cwd) {
54739
54687
  const tsconfigPath = path9.join(cwd, "tsconfig.json");
54740
- if (!fs9.existsSync(tsconfigPath)) {
54688
+ if (!fs8.existsSync(tsconfigPath)) {
54741
54689
  return { parsed: null, error: "No tsconfig.json found" };
54742
54690
  }
54743
54691
  try {
54744
- const raw = fs9.readFileSync(tsconfigPath, "utf8");
54692
+ const raw = fs8.readFileSync(tsconfigPath, "utf8");
54745
54693
  const parsed = JSON.parse(stripJsonComments(raw));
54746
54694
  return { parsed };
54747
54695
  } catch {
@@ -54842,9 +54790,9 @@ function checkTsconfigModuleResolution(cwd) {
54842
54790
  }
54843
54791
  function checkFlowWeaverInstalled(cwd) {
54844
54792
  const pkgPath = path9.join(cwd, "node_modules", "@synergenius", "flow-weaver", "package.json");
54845
- if (fs9.existsSync(pkgPath)) {
54793
+ if (fs8.existsSync(pkgPath)) {
54846
54794
  try {
54847
- const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
54795
+ const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf8"));
54848
54796
  return {
54849
54797
  name: "@synergenius/flow-weaver installed",
54850
54798
  status: "pass",
@@ -54868,7 +54816,7 @@ function checkFlowWeaverInstalled(cwd) {
54868
54816
  function checkFlowWeaverVersion(cwd) {
54869
54817
  const libraryPath = path9.join(cwd, "node_modules", "@synergenius", "flow-weaver");
54870
54818
  const pkgPath = path9.join(libraryPath, "package.json");
54871
- if (!fs9.existsSync(pkgPath)) {
54819
+ if (!fs8.existsSync(pkgPath)) {
54872
54820
  return {
54873
54821
  name: "Library version",
54874
54822
  status: "pass",
@@ -54877,8 +54825,8 @@ function checkFlowWeaverVersion(cwd) {
54877
54825
  }
54878
54826
  try {
54879
54827
  const projectPkgPath = path9.join(cwd, "package.json");
54880
- if (fs9.existsSync(projectPkgPath)) {
54881
- const projectPkg = JSON.parse(fs9.readFileSync(projectPkgPath, "utf8"));
54828
+ if (fs8.existsSync(projectPkgPath)) {
54829
+ const projectPkg = JSON.parse(fs8.readFileSync(projectPkgPath, "utf8"));
54882
54830
  const depSpec = projectPkg.dependencies?.["@synergenius/flow-weaver"] ?? projectPkg.devDependencies?.["@synergenius/flow-weaver"];
54883
54831
  if (typeof depSpec === "string" && (depSpec.startsWith("file:") || depSpec.startsWith("link:") || depSpec.startsWith("workspace:"))) {
54884
54832
  return {
@@ -54888,7 +54836,7 @@ function checkFlowWeaverVersion(cwd) {
54888
54836
  };
54889
54837
  }
54890
54838
  }
54891
- if (fs9.lstatSync(libraryPath).isSymbolicLink()) {
54839
+ if (fs8.lstatSync(libraryPath).isSymbolicLink()) {
54892
54840
  return {
54893
54841
  name: "Library version",
54894
54842
  status: "pass",
@@ -54898,7 +54846,7 @@ function checkFlowWeaverVersion(cwd) {
54898
54846
  } catch {
54899
54847
  }
54900
54848
  try {
54901
- const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
54849
+ const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf8"));
54902
54850
  const currentVersion = pkg.version;
54903
54851
  const latestVersion = execSync("npm view @synergenius/flow-weaver version", {
54904
54852
  timeout: 5e3,
@@ -54927,7 +54875,7 @@ function checkFlowWeaverVersion(cwd) {
54927
54875
  }
54928
54876
  function checkTypesNodeInstalled(cwd) {
54929
54877
  const pkgPath = path9.join(cwd, "node_modules", "@types", "node", "package.json");
54930
- if (fs9.existsSync(pkgPath)) {
54878
+ if (fs8.existsSync(pkgPath)) {
54931
54879
  return {
54932
54880
  name: "@types/node installed",
54933
54881
  status: "pass",
@@ -54943,7 +54891,7 @@ function checkTypesNodeInstalled(cwd) {
54943
54891
  }
54944
54892
  function checkTsxAvailable(cwd) {
54945
54893
  const localBin = path9.join(cwd, "node_modules", ".bin", "tsx");
54946
- if (fs9.existsSync(localBin)) {
54894
+ if (fs8.existsSync(localBin)) {
54947
54895
  return {
54948
54896
  name: "tsx available",
54949
54897
  status: "pass",
@@ -54968,7 +54916,7 @@ function checkTsxAvailable(cwd) {
54968
54916
  }
54969
54917
  function readYaml(filePath) {
54970
54918
  try {
54971
- const content = fs9.readFileSync(filePath, "utf8");
54919
+ const content = fs8.readFileSync(filePath, "utf8");
54972
54920
  return { data: load(content) };
54973
54921
  } catch (e) {
54974
54922
  return { data: null, error: e instanceof Error ? e.message : String(e) };
@@ -54976,7 +54924,7 @@ function readYaml(filePath) {
54976
54924
  }
54977
54925
  function checkProjectConfig(cwd) {
54978
54926
  const configPath = path9.join(cwd, ".flowweaver", "config.yaml");
54979
- if (!fs9.existsSync(configPath)) {
54927
+ if (!fs8.existsSync(configPath)) {
54980
54928
  return {
54981
54929
  name: "Project config",
54982
54930
  status: "warn",
@@ -55019,7 +54967,7 @@ function checkProjectConfig(cwd) {
55019
54967
  }
55020
54968
  function checkDeploymentManifest(cwd) {
55021
54969
  const deployDir = path9.join(cwd, ".flowweaver", "deployment");
55022
- if (!fs9.existsSync(deployDir)) {
54970
+ if (!fs8.existsSync(deployDir)) {
55023
54971
  return {
55024
54972
  name: "Deployment manifest",
55025
54973
  status: "pass",
@@ -55027,7 +54975,7 @@ function checkDeploymentManifest(cwd) {
55027
54975
  };
55028
54976
  }
55029
54977
  const manifestPath = path9.join(deployDir, "manifest.yaml");
55030
- if (!fs9.existsSync(manifestPath)) {
54978
+ if (!fs8.existsSync(manifestPath)) {
55031
54979
  return {
55032
54980
  name: "Deployment manifest",
55033
54981
  status: "fail",
@@ -55077,7 +55025,7 @@ function checkDeploymentManifest(cwd) {
55077
55025
  }
55078
55026
  function checkDeploymentProfiles(cwd) {
55079
55027
  const deployDir = path9.join(cwd, ".flowweaver", "deployment");
55080
- if (!fs9.existsSync(deployDir)) {
55028
+ if (!fs8.existsSync(deployDir)) {
55081
55029
  return {
55082
55030
  name: "Deployment profiles",
55083
55031
  status: "pass",
@@ -55085,7 +55033,7 @@ function checkDeploymentProfiles(cwd) {
55085
55033
  };
55086
55034
  }
55087
55035
  const manifestPath = path9.join(deployDir, "manifest.yaml");
55088
- if (!fs9.existsSync(manifestPath)) {
55036
+ if (!fs8.existsSync(manifestPath)) {
55089
55037
  return {
55090
55038
  name: "Deployment profiles",
55091
55039
  status: "pass",
@@ -55105,7 +55053,7 @@ function checkDeploymentProfiles(cwd) {
55105
55053
  const invalid = [];
55106
55054
  for (const profile of profiles) {
55107
55055
  const profilePath = path9.join(deployDir, `${profile}.yaml`);
55108
- if (!fs9.existsSync(profilePath)) {
55056
+ if (!fs8.existsSync(profilePath)) {
55109
55057
  missing.push(profile);
55110
55058
  continue;
55111
55059
  }
@@ -55205,7 +55153,7 @@ async function doctorCommand(options = {}) {
55205
55153
  }
55206
55154
  }
55207
55155
  if (!report.ok) {
55208
- process.exit(1);
55156
+ throw new Error("Doctor found issues that need to be fixed");
55209
55157
  }
55210
55158
  }
55211
55159
  var VALID_FILE_TYPES;
@@ -55218,6 +55166,49 @@ var init_doctor = __esm({
55218
55166
  }
55219
55167
  });
55220
55168
 
55169
+ // src/cli/utils/safe-write.ts
55170
+ import * as fs9 from "fs";
55171
+ import * as path10 from "path";
55172
+ function ensureDir(dirPath) {
55173
+ if (!fs9.existsSync(dirPath)) {
55174
+ fs9.mkdirSync(dirPath, { recursive: true });
55175
+ }
55176
+ }
55177
+ function wrapIOError(filePath, error2) {
55178
+ if (error2 instanceof Error) {
55179
+ const code = error2.code;
55180
+ if (code === "EACCES" || code === "EPERM") {
55181
+ throw new Error(`Permission denied: cannot write to ${filePath}. Check file/directory permissions.`);
55182
+ }
55183
+ if (code === "EROFS") {
55184
+ throw new Error(`Read-only file system: cannot write to ${filePath}.`);
55185
+ }
55186
+ throw error2;
55187
+ }
55188
+ throw error2;
55189
+ }
55190
+ function safeWriteFile(filePath, content, encoding = "utf8") {
55191
+ try {
55192
+ ensureDir(path10.dirname(filePath));
55193
+ fs9.writeFileSync(filePath, content, encoding);
55194
+ } catch (error2) {
55195
+ wrapIOError(filePath, error2);
55196
+ }
55197
+ }
55198
+ function safeAppendFile(filePath, content, encoding = "utf8") {
55199
+ try {
55200
+ ensureDir(path10.dirname(filePath));
55201
+ fs9.appendFileSync(filePath, content, encoding);
55202
+ } catch (error2) {
55203
+ wrapIOError(filePath, error2);
55204
+ }
55205
+ }
55206
+ var init_safe_write = __esm({
55207
+ "src/cli/utils/safe-write.ts"() {
55208
+ "use strict";
55209
+ }
55210
+ });
55211
+
55221
55212
  // src/cli/commands/compile.ts
55222
55213
  var compile_exports = {};
55223
55214
  __export(compile_exports, {
@@ -55225,9 +55216,9 @@ __export(compile_exports, {
55225
55216
  compileCustomTarget: () => compileCustomTarget
55226
55217
  });
55227
55218
  import * as fs10 from "fs";
55228
- import * as path10 from "path";
55219
+ import * as path11 from "path";
55229
55220
  function displayPath(filePath) {
55230
- const rel = path10.relative(process.cwd(), filePath);
55221
+ const rel = path11.relative(process.cwd(), filePath);
55231
55222
  if (rel && !rel.startsWith("..") && rel.length < filePath.length) {
55232
55223
  return rel;
55233
55224
  }
@@ -55241,7 +55232,7 @@ function resolveModuleFormat(format, cwd) {
55241
55232
  return detection.format;
55242
55233
  }
55243
55234
  async function compileCommand(input, options = {}) {
55244
- const { production = false, sourceMap = false, strict = false, verbose = false, workflowName, dryRun = false, format, inlineRuntime = false, clean = false, target } = options;
55235
+ const { production = false, sourceMap = false, strict = false, verbose = false, workflowName, dryRun = false, format, clean = false, target, output } = options;
55245
55236
  if (target && target !== "typescript") {
55246
55237
  return compileCustomTarget(target, input, { production, verbose, workflowName, dryRun, cron: options.cron, serve: options.serve, framework: options.framework, typedEvents: options.typedEvents, retries: options.retries, timeout: options.timeout });
55247
55238
  }
@@ -55250,7 +55241,7 @@ async function compileCommand(input, options = {}) {
55250
55241
  let pattern = input;
55251
55242
  try {
55252
55243
  if (fs10.existsSync(input) && fs10.statSync(input).isDirectory()) {
55253
- pattern = path10.join(input, "**/*.ts");
55244
+ pattern = path11.join(input, "**/*.ts");
55254
55245
  }
55255
55246
  } catch {
55256
55247
  }
@@ -55265,6 +55256,23 @@ async function compileCommand(input, options = {}) {
55265
55256
  if (files.length === 0) {
55266
55257
  throw new Error(`No files found matching pattern: ${input}`);
55267
55258
  }
55259
+ let outputDir;
55260
+ let outputFile;
55261
+ if (output) {
55262
+ const isOutputDir = output.endsWith("/") || output.endsWith(path11.sep) || fs10.existsSync(output) && fs10.statSync(output).isDirectory();
55263
+ if (isOutputDir) {
55264
+ outputDir = output.endsWith("/") || output.endsWith(path11.sep) ? output.slice(0, -1) : output;
55265
+ if (!fs10.existsSync(outputDir)) {
55266
+ fs10.mkdirSync(outputDir, { recursive: true });
55267
+ }
55268
+ } else if (files.length > 1) {
55269
+ throw new Error(
55270
+ `Cannot use --output with a file path when compiling multiple files. Use a directory path instead (e.g. --output ${output}/)`
55271
+ );
55272
+ } else {
55273
+ outputFile = path11.resolve(output);
55274
+ }
55275
+ }
55268
55276
  const totalTimer = logger.timer();
55269
55277
  logger.section("Compiling Workflows");
55270
55278
  if (verbose) {
@@ -55280,7 +55288,7 @@ async function compileCommand(input, options = {}) {
55280
55288
  let errorCount = 0;
55281
55289
  for (let i = 0; i < files.length; i++) {
55282
55290
  const file = files[i];
55283
- const fileName = path10.basename(file);
55291
+ const fileName = path11.basename(file);
55284
55292
  const fileTimer = logger.timer();
55285
55293
  try {
55286
55294
  const rawSource = fs10.readFileSync(file, "utf8");
@@ -55349,9 +55357,10 @@ async function compileCommand(input, options = {}) {
55349
55357
  }
55350
55358
  }
55351
55359
  const sourceCode = fs10.readFileSync(file, "utf8");
55352
- const result = generateInPlace(sourceCode, parseResult.ast, { production, moduleFormat, inlineRuntime, sourceFile: file, skipParamReturns: clean });
55360
+ const result = generateInPlace(sourceCode, parseResult.ast, { production, moduleFormat, sourceFile: file, skipParamReturns: clean });
55361
+ const writePath = outputFile ? outputFile : outputDir ? path11.join(outputDir, path11.basename(file)) : file;
55353
55362
  if (!dryRun) {
55354
- fs10.writeFileSync(file, result.code, "utf8");
55363
+ safeWriteFile(writePath, result.code);
55355
55364
  if (sourceMap) {
55356
55365
  const mapResult = generateCode(parseResult.ast, {
55357
55366
  production,
@@ -55359,13 +55368,13 @@ async function compileCommand(input, options = {}) {
55359
55368
  moduleFormat
55360
55369
  });
55361
55370
  if (mapResult.sourceMap) {
55362
- const mapPath = file + ".map";
55363
- fs10.writeFileSync(mapPath, mapResult.sourceMap, "utf8");
55371
+ const mapPath = writePath + ".map";
55372
+ safeWriteFile(mapPath, mapResult.sourceMap);
55364
55373
  const sourceMappingComment = `
55365
- //# sourceMappingURL=${path10.basename(mapPath)}
55374
+ //# sourceMappingURL=${path11.basename(mapPath)}
55366
55375
  `;
55367
55376
  if (!result.code.includes("//# sourceMappingURL=")) {
55368
- fs10.appendFileSync(file, sourceMappingComment, "utf8");
55377
+ safeAppendFile(writePath, sourceMappingComment);
55369
55378
  }
55370
55379
  if (verbose) {
55371
55380
  logger.info(` source map: ${displayPath(mapPath)}`);
@@ -55410,7 +55419,7 @@ async function compileCustomTarget(target, input, options) {
55410
55419
  const hint = available.length > 0 ? ` Available targets: typescript, ${available.join(", ")}` : " No custom targets registered.";
55411
55420
  throw new Error(`Unknown compile target: ${target}.${hint}`);
55412
55421
  }
55413
- const filePath = path10.resolve(input);
55422
+ const filePath = path11.resolve(input);
55414
55423
  if (!fs10.existsSync(filePath)) {
55415
55424
  throw new Error(`File not found: ${displayPath(filePath)}`);
55416
55425
  }
@@ -55465,7 +55474,7 @@ ${msgs}`);
55465
55474
  logger.info(`... (${lines.length - 50} more lines)`);
55466
55475
  }
55467
55476
  } else {
55468
- fs10.writeFileSync(outputPath, code, "utf8");
55477
+ safeWriteFile(outputPath, code);
55469
55478
  logger.success(`Compiled: ${displayPath(outputPath)}`);
55470
55479
  }
55471
55480
  logger.newline();
@@ -55486,6 +55495,7 @@ var init_compile2 = __esm({
55486
55495
  init_doctor();
55487
55496
  init_compile_target_registry();
55488
55497
  init_parser2();
55498
+ init_safe_write();
55489
55499
  }
55490
55500
  });
55491
55501
 
@@ -55495,13 +55505,13 @@ __export(strip_exports, {
55495
55505
  stripCommand: () => stripCommand
55496
55506
  });
55497
55507
  import * as fs11 from "fs";
55498
- import * as path11 from "path";
55508
+ import * as path12 from "path";
55499
55509
  async function stripCommand(input, options = {}) {
55500
55510
  const { output, dryRun = false, verbose = false } = options;
55501
55511
  let pattern = input;
55502
55512
  try {
55503
55513
  if (fs11.existsSync(input) && fs11.statSync(input).isDirectory()) {
55504
- pattern = path11.join(input, "**/*.ts");
55514
+ pattern = path12.join(input, "**/*.ts");
55505
55515
  }
55506
55516
  } catch {
55507
55517
  }
@@ -55514,8 +55524,7 @@ async function stripCommand(input, options = {}) {
55514
55524
  }
55515
55525
  });
55516
55526
  if (files.length === 0) {
55517
- logger.error(`No files found matching pattern: ${input}`);
55518
- process.exit(1);
55527
+ throw new Error(`No files found matching pattern: ${input}`);
55519
55528
  }
55520
55529
  const t = logger.timer();
55521
55530
  let stripped = 0;
@@ -55525,24 +55534,21 @@ async function stripCommand(input, options = {}) {
55525
55534
  if (!hasInPlaceMarkers(content)) {
55526
55535
  skipped++;
55527
55536
  if (verbose) {
55528
- logger.info(`Skipped (no markers): ${path11.relative(process.cwd(), filePath)}`);
55537
+ logger.info(`Skipped (no markers): ${path12.relative(process.cwd(), filePath)}`);
55529
55538
  }
55530
55539
  continue;
55531
55540
  }
55532
55541
  const result = stripGeneratedSections(content);
55533
55542
  if (dryRun) {
55534
- logger.info(`Would strip: ${path11.relative(process.cwd(), filePath)}`);
55543
+ logger.info(`Would strip: ${path12.relative(process.cwd(), filePath)}`);
55535
55544
  stripped++;
55536
55545
  continue;
55537
55546
  }
55538
- const outPath = output ? path11.join(path11.resolve(output), path11.basename(filePath)) : filePath;
55539
- if (output) {
55540
- fs11.mkdirSync(path11.dirname(outPath), { recursive: true });
55541
- }
55542
- fs11.writeFileSync(outPath, result);
55547
+ const outPath = output ? path12.join(path12.resolve(output), path12.basename(filePath)) : filePath;
55548
+ safeWriteFile(outPath, result);
55543
55549
  stripped++;
55544
55550
  if (verbose) {
55545
- logger.success(`Stripped: ${path11.relative(process.cwd(), outPath)}`);
55551
+ logger.success(`Stripped: ${path12.relative(process.cwd(), outPath)}`);
55546
55552
  }
55547
55553
  }
55548
55554
  const verb = dryRun ? "would be stripped" : "stripped";
@@ -55554,6 +55560,7 @@ var init_strip = __esm({
55554
55560
  init_esm5();
55555
55561
  init_generate_in_place();
55556
55562
  init_logger();
55563
+ init_safe_write();
55557
55564
  }
55558
55565
  });
55559
55566
 
@@ -55859,14 +55866,14 @@ function waypointsToSvgPath(waypoints, cornerRadius) {
55859
55866
  radii[i + 1] *= scale;
55860
55867
  }
55861
55868
  }
55862
- let path54 = `M ${waypoints[0][0]},${waypoints[0][1]}`;
55869
+ let path55 = `M ${waypoints[0][0]},${waypoints[0][1]}`;
55863
55870
  for (let i = 1; i < waypoints.length - 1; i++) {
55864
55871
  const prev = waypoints[i - 1];
55865
55872
  const curr = waypoints[i];
55866
55873
  const next = waypoints[i + 1];
55867
55874
  const r = radii[i];
55868
55875
  if (r < 2) {
55869
- path54 += ` L ${curr[0]},${curr[1]}`;
55876
+ path55 += ` L ${curr[0]},${curr[1]}`;
55870
55877
  continue;
55871
55878
  }
55872
55879
  const dPrev = [prev[0] - curr[0], prev[1] - curr[1]];
@@ -55879,12 +55886,12 @@ function waypointsToSvgPath(waypoints, cornerRadius) {
55879
55886
  const arcEnd = [curr[0] + uNext[0] * r, curr[1] + uNext[1] * r];
55880
55887
  const cross = dPrev[0] * dNext[1] - dPrev[1] * dNext[0];
55881
55888
  const sweep = cross > 0 ? 0 : 1;
55882
- path54 += ` L ${arcStart[0]},${arcStart[1]}`;
55883
- path54 += ` A ${r} ${r} 0 0 ${sweep} ${arcEnd[0]},${arcEnd[1]}`;
55889
+ path55 += ` L ${arcStart[0]},${arcStart[1]}`;
55890
+ path55 += ` A ${r} ${r} 0 0 ${sweep} ${arcEnd[0]},${arcEnd[1]}`;
55884
55891
  }
55885
55892
  const last2 = waypoints[waypoints.length - 1];
55886
- path54 += ` L ${last2[0]},${last2[1]}`;
55887
- return path54;
55893
+ path55 += ` L ${last2[0]},${last2[1]}`;
55894
+ return path55;
55888
55895
  }
55889
55896
  function computeWaypoints(from, to, nodeBoxes, sourceNodeId, targetNodeId, padding, exitStub, entryStub, allocator) {
55890
55897
  const isSelfConnection = sourceNodeId === targetNodeId;
@@ -56031,7 +56038,7 @@ function calculateOrthogonalPath(from, to, nodeBoxes, sourceNodeId, targetNodeId
56031
56038
  }
56032
56039
  function calculateOrthogonalPathSafe(from, to, nodeBoxes, sourceNodeId, targetNodeId, options, allocator) {
56033
56040
  try {
56034
- const path54 = calculateOrthogonalPath(
56041
+ const path55 = calculateOrthogonalPath(
56035
56042
  from,
56036
56043
  to,
56037
56044
  nodeBoxes,
@@ -56040,8 +56047,8 @@ function calculateOrthogonalPathSafe(from, to, nodeBoxes, sourceNodeId, targetNo
56040
56047
  options,
56041
56048
  allocator
56042
56049
  );
56043
- if (!path54 || path54.length < 5) return null;
56044
- return path54;
56050
+ if (!path55 || path55.length < 5) return null;
56051
+ return path55;
56045
56052
  } catch {
56046
56053
  return null;
56047
56054
  }
@@ -56265,13 +56272,13 @@ function computeConnectionPath(sx, sy, tx, ty) {
56265
56272
  const deUy = deY / deLen;
56266
56273
  const [cx, cy] = quadCurveControl(bx, by, dx, dy, -deUx, -deUy);
56267
56274
  const [fx, fy] = quadCurveControl(gx, gy, ex, ey, deUx, deUy);
56268
- let path54 = `M ${cx},${cy} M ${ax},${ay}`;
56269
- path54 += ` L ${bx},${by}`;
56270
- path54 += ` Q ${cx},${cy} ${dx},${dy}`;
56271
- path54 += ` L ${ex},${ey}`;
56272
- path54 += ` Q ${fx},${fy} ${gx},${gy}`;
56273
- path54 += ` L ${hx},${hy}`;
56274
- return path54;
56275
+ let path55 = `M ${cx},${cy} M ${ax},${ay}`;
56276
+ path55 += ` L ${bx},${by}`;
56277
+ path55 += ` Q ${cx},${cy} ${dx},${dy}`;
56278
+ path55 += ` L ${ex},${ey}`;
56279
+ path55 += ` Q ${fx},${fy} ${gx},${gy}`;
56280
+ path55 += ` L ${hx},${hy}`;
56281
+ return path55;
56275
56282
  }
56276
56283
  function orderedPorts(ports, direction) {
56277
56284
  const cloned = {};
@@ -56561,7 +56568,7 @@ function finalizeScopePositions(parentNode, ast, theme = "dark") {
56561
56568
  function buildConnection(fromNode, fromPort, toNode, toPort, sourcePort, targetPort, theme = "dark") {
56562
56569
  const sourceColor = getPortColor(sourcePort.dataType, sourcePort.isFailure, theme);
56563
56570
  const targetColor = getPortColor(targetPort.dataType, targetPort.isFailure, theme);
56564
- const path54 = computeConnectionPath(sourcePort.cx, sourcePort.cy, targetPort.cx, targetPort.cy);
56571
+ const path55 = computeConnectionPath(sourcePort.cx, sourcePort.cy, targetPort.cx, targetPort.cy);
56565
56572
  return {
56566
56573
  fromNode,
56567
56574
  fromPort,
@@ -56570,7 +56577,7 @@ function buildConnection(fromNode, fromPort, toNode, toPort, sourcePort, targetP
56570
56577
  sourceColor,
56571
56578
  targetColor,
56572
56579
  isStepConnection: sourcePort.dataType === "STEP",
56573
- path: path54
56580
+ path: path55
56574
56581
  };
56575
56582
  }
56576
56583
  function portsColumnHeight(count) {
@@ -57031,9 +57038,9 @@ function buildDiagramGraph(ast, options = {}) {
57031
57038
  color: targetColor,
57032
57039
  dashed
57033
57040
  };
57034
- let path54;
57041
+ let path55;
57035
57042
  if (xDistance > STUB_DISTANCE_THRESHOLD) {
57036
- path54 = "";
57043
+ path55 = "";
57037
57044
  } else if (!useCurve && distance > ORTHOGONAL_DISTANCE_THRESHOLD) {
57038
57045
  const orthoPath = calculateOrthogonalPathSafe(
57039
57046
  [sx, sy],
@@ -57044,9 +57051,9 @@ function buildDiagramGraph(ast, options = {}) {
57044
57051
  { fromPortIndex: pc3.fromPortIndex, toPortIndex: pc3.toPortIndex },
57045
57052
  allocator
57046
57053
  );
57047
- path54 = orthoPath ?? computeConnectionPath(sx, sy, tx, ty);
57054
+ path55 = orthoPath ?? computeConnectionPath(sx, sy, tx, ty);
57048
57055
  } else {
57049
- path54 = computeConnectionPath(sx, sy, tx, ty);
57056
+ path55 = computeConnectionPath(sx, sy, tx, ty);
57050
57057
  }
57051
57058
  connections.push({
57052
57059
  fromNode: pc3.fromNodeId,
@@ -57056,7 +57063,7 @@ function buildDiagramGraph(ast, options = {}) {
57056
57063
  sourceColor,
57057
57064
  targetColor,
57058
57065
  isStepConnection: pc3.sourcePort.dataType === "STEP",
57059
- path: path54,
57066
+ path: path55,
57060
57067
  sourceStub,
57061
57068
  targetStub
57062
57069
  });
@@ -57216,12 +57223,12 @@ function resolveDefaultIcon(nt) {
57216
57223
  if (nt.variant === "WORKFLOW" || nt.variant === "IMPORTED_WORKFLOW") return "flow";
57217
57224
  return "code";
57218
57225
  }
57219
- function pathExtent(path54) {
57226
+ function pathExtent(path55) {
57220
57227
  let minX = Infinity, minY = Infinity;
57221
57228
  let maxX = -Infinity, maxY = -Infinity;
57222
57229
  const pattern = /(-?[\d.]+),(-?[\d.]+)/g;
57223
57230
  let m;
57224
- while ((m = pattern.exec(path54)) !== null) {
57231
+ while ((m = pattern.exec(path55)) !== null) {
57225
57232
  const x = parseFloat(m[1]);
57226
57233
  const y = parseFloat(m[2]);
57227
57234
  minX = Math.min(minX, x);
@@ -57827,7 +57834,7 @@ __export(describe_exports, {
57827
57834
  generateMermaid: () => generateMermaid
57828
57835
  });
57829
57836
  import * as fs12 from "fs";
57830
- import * as path12 from "path";
57837
+ import * as path13 from "path";
57831
57838
  function buildNodeInfo(instance, nodeType) {
57832
57839
  return {
57833
57840
  id: instance.id,
@@ -57860,17 +57867,17 @@ function buildAdjacency(ast) {
57860
57867
  function enumeratePaths(ast) {
57861
57868
  const { fromStart, toExit, edges } = buildAdjacency(ast);
57862
57869
  const paths = [];
57863
- function dfs(current2, path54, visited) {
57870
+ function dfs(current2, path55, visited) {
57864
57871
  if (toExit.has(current2)) {
57865
- paths.push([...path54, "Exit"]);
57872
+ paths.push([...path55, "Exit"]);
57866
57873
  }
57867
57874
  const targets = edges.get(current2) || [];
57868
57875
  for (const next of targets) {
57869
57876
  if (!visited.has(next)) {
57870
57877
  visited.add(next);
57871
- path54.push(next);
57872
- dfs(next, path54, visited);
57873
- path54.pop();
57878
+ path55.push(next);
57879
+ dfs(next, path55, visited);
57880
+ path55.pop();
57874
57881
  visited.delete(next);
57875
57882
  }
57876
57883
  }
@@ -57884,22 +57891,22 @@ function enumeratePaths(ast) {
57884
57891
  function buildGraph(ast) {
57885
57892
  const { fromStart, toExit, edges } = buildAdjacency(ast);
57886
57893
  const lines = [];
57887
- function dfs(current2, path54, visited) {
57894
+ function dfs(current2, path55, visited) {
57888
57895
  if (toExit.has(current2)) {
57889
- lines.push([...path54, "Exit"].join(" -> "));
57896
+ lines.push([...path55, "Exit"].join(" -> "));
57890
57897
  }
57891
57898
  const targets = edges.get(current2) || [];
57892
57899
  for (const next of targets) {
57893
57900
  if (!visited.has(next)) {
57894
57901
  visited.add(next);
57895
- path54.push(next);
57896
- dfs(next, path54, visited);
57897
- path54.pop();
57902
+ path55.push(next);
57903
+ dfs(next, path55, visited);
57904
+ path55.pop();
57898
57905
  visited.delete(next);
57899
57906
  }
57900
57907
  }
57901
57908
  if (targets.length === 0 && !toExit.has(current2)) {
57902
- lines.push(path54.join(" -> "));
57909
+ lines.push(path55.join(" -> "));
57903
57910
  }
57904
57911
  }
57905
57912
  fromStart.forEach((startNode) => {
@@ -58121,36 +58128,32 @@ function formatDescribeOutput(ast, output, format) {
58121
58128
  }
58122
58129
  async function describeCommand(input, options = {}) {
58123
58130
  const { format = "json", node: focusNodeId, workflowName, compile = false } = options;
58124
- const filePath = path12.resolve(input);
58131
+ const filePath = path13.resolve(input);
58125
58132
  if (!fs12.existsSync(filePath)) {
58126
- logger.error(`File not found: ${filePath}`);
58127
- process.exit(1);
58133
+ throw new Error(`File not found: ${filePath}`);
58128
58134
  }
58129
58135
  try {
58130
58136
  const parseResult = await parseWorkflow(filePath, { workflowName });
58131
58137
  if (parseResult.errors.length > 0) {
58132
- logger.error(`Parse errors:`);
58133
- parseResult.errors.forEach((err) => logger.error(` ${err}`));
58134
- process.exit(1);
58138
+ throw new Error(`Parse errors:
58139
+ ${parseResult.errors.map((err) => ` ${err}`).join("\n")}`);
58135
58140
  }
58136
58141
  const ast = parseResult.ast;
58137
58142
  if (compile) {
58138
58143
  const sourceCode = fs12.readFileSync(filePath, "utf8");
58139
58144
  const generated = generateInPlace(sourceCode, ast, { production: false });
58140
58145
  if (generated.hasChanges) {
58141
- fs12.writeFileSync(filePath, generated.code, "utf8");
58142
- logger.info(`Updated runtime markers in ${path12.basename(filePath)}`);
58146
+ safeWriteFile(filePath, generated.code);
58147
+ logger.info(`Updated runtime markers in ${path13.basename(filePath)}`);
58143
58148
  }
58144
58149
  }
58145
58150
  const output = describeWorkflow(ast, { node: focusNodeId });
58146
58151
  console.log(formatDescribeOutput(ast, output, format));
58147
58152
  } catch (error2) {
58148
58153
  if (error2 instanceof Error && error2.message.startsWith("Node not found:")) {
58149
- logger.error(error2.message);
58150
- process.exit(1);
58154
+ throw error2;
58151
58155
  }
58152
- logger.error(`Failed to describe workflow: ${getErrorMessage(error2)}`);
58153
- process.exit(1);
58156
+ throw new Error(`Failed to describe workflow: ${getErrorMessage(error2)}`);
58154
58157
  }
58155
58158
  }
58156
58159
  var init_describe = __esm({
@@ -58161,6 +58164,7 @@ var init_describe = __esm({
58161
58164
  init_query();
58162
58165
  init_logger();
58163
58166
  init_error_utils();
58167
+ init_safe_write();
58164
58168
  init_geometry();
58165
58169
  init_ascii_renderer();
58166
58170
  }
@@ -60209,33 +60213,27 @@ __export(diagram_exports, {
60209
60213
  diagramCommand: () => diagramCommand
60210
60214
  });
60211
60215
  import * as fs13 from "fs";
60212
- import * as path13 from "path";
60216
+ import * as path14 from "path";
60213
60217
  async function diagramCommand(input, options = {}) {
60214
60218
  const { output, format = "svg", ...diagramOptions } = options;
60215
- const filePath = path13.resolve(input);
60219
+ const filePath = path14.resolve(input);
60216
60220
  if (!fs13.existsSync(filePath)) {
60217
- logger.error(`File not found: ${filePath}`);
60218
- process.exit(1);
60221
+ throw new Error(`File not found: ${filePath}`);
60219
60222
  }
60220
- try {
60221
- let result;
60222
- if (ASCII_FORMATS.has(format)) {
60223
- result = fileToASCII(filePath, { ...diagramOptions, format });
60224
- } else if (format === "html") {
60225
- result = fileToHTML(filePath, diagramOptions);
60226
- } else {
60227
- result = fileToSVG(filePath, diagramOptions);
60228
- }
60229
- if (output) {
60230
- const outputPath = path13.resolve(output);
60231
- fs13.writeFileSync(outputPath, result, "utf-8");
60232
- logger.success(`Diagram written to ${outputPath}`);
60233
- } else {
60234
- process.stdout.write(result);
60235
- }
60236
- } catch (error2) {
60237
- logger.error(`Failed to generate diagram: ${getErrorMessage(error2)}`);
60238
- process.exit(1);
60223
+ let result;
60224
+ if (ASCII_FORMATS.has(format)) {
60225
+ result = fileToASCII(filePath, { ...diagramOptions, format });
60226
+ } else if (format === "html") {
60227
+ result = fileToHTML(filePath, diagramOptions);
60228
+ } else {
60229
+ result = fileToSVG(filePath, diagramOptions);
60230
+ }
60231
+ if (output) {
60232
+ const outputPath = path14.resolve(output);
60233
+ safeWriteFile(outputPath, result);
60234
+ logger.success(`Diagram written to ${outputPath}`);
60235
+ } else {
60236
+ process.stdout.write(result);
60239
60237
  }
60240
60238
  }
60241
60239
  var ASCII_FORMATS;
@@ -60244,7 +60242,7 @@ var init_diagram2 = __esm({
60244
60242
  "use strict";
60245
60243
  init_diagram();
60246
60244
  init_logger();
60247
- init_error_utils();
60245
+ init_safe_write();
60248
60246
  ASCII_FORMATS = /* @__PURE__ */ new Set(["ascii", "ascii-compact", "text"]);
60249
60247
  }
60250
60248
  });
@@ -60273,18 +60271,16 @@ __export(diff_exports, {
60273
60271
  diffCommand: () => diffCommand
60274
60272
  });
60275
60273
  import * as fs14 from "fs";
60276
- import * as path14 from "path";
60274
+ import * as path15 from "path";
60277
60275
  async function diffCommand(file1, file2, options = {}) {
60278
60276
  const { format = "text", workflowName, exitZero = false } = options;
60279
- const filePath1 = path14.resolve(file1);
60280
- const filePath2 = path14.resolve(file2);
60277
+ const filePath1 = path15.resolve(file1);
60278
+ const filePath2 = path15.resolve(file2);
60281
60279
  if (!fs14.existsSync(filePath1)) {
60282
- logger.error(`File not found: ${filePath1}`);
60283
- process.exit(1);
60280
+ throw new Error(`File not found: ${filePath1}`);
60284
60281
  }
60285
60282
  if (!fs14.existsSync(filePath2)) {
60286
- logger.error(`File not found: ${filePath2}`);
60287
- process.exit(1);
60283
+ throw new Error(`File not found: ${filePath2}`);
60288
60284
  }
60289
60285
  try {
60290
60286
  const [result1, result2] = await Promise.all([
@@ -60292,14 +60288,12 @@ async function diffCommand(file1, file2, options = {}) {
60292
60288
  parseWorkflow(filePath2, { workflowName })
60293
60289
  ]);
60294
60290
  if (result1.errors.length > 0) {
60295
- logger.error(`Parse errors in ${file1}:`);
60296
- result1.errors.forEach((err) => logger.error(` ${err}`));
60297
- process.exit(1);
60291
+ throw new Error(`Parse errors in ${file1}:
60292
+ ${result1.errors.map((err) => ` ${err}`).join("\n")}`);
60298
60293
  }
60299
60294
  if (result2.errors.length > 0) {
60300
- logger.error(`Parse errors in ${file2}:`);
60301
- result2.errors.forEach((err) => logger.error(` ${err}`));
60302
- process.exit(1);
60295
+ throw new Error(`Parse errors in ${file2}:
60296
+ ${result2.errors.map((err) => ` ${err}`).join("\n")}`);
60303
60297
  }
60304
60298
  const diff = WorkflowDiffer.compare(result1.ast, result2.ast);
60305
60299
  if (diff.identical) {
@@ -60311,12 +60305,11 @@ async function diffCommand(file1, file2, options = {}) {
60311
60305
  } else {
60312
60306
  console.log(formatDiff(diff, format));
60313
60307
  if (!exitZero) {
60314
- process.exit(1);
60308
+ throw new Error("Workflows have differences");
60315
60309
  }
60316
60310
  }
60317
60311
  } catch (error2) {
60318
- logger.error(`Failed to diff workflows: ${getErrorMessage(error2)}`);
60319
- process.exit(1);
60312
+ throw new Error(`Failed to diff workflows: ${getErrorMessage(error2)}`);
60320
60313
  }
60321
60314
  }
60322
60315
  var init_diff2 = __esm({
@@ -60335,14 +60328,14 @@ __export(validate_exports2, {
60335
60328
  validateCommand: () => validateCommand
60336
60329
  });
60337
60330
  import * as fs15 from "fs";
60338
- import * as path15 from "path";
60331
+ import * as path16 from "path";
60339
60332
  async function validateCommand(input, options = {}) {
60340
60333
  const { verbose = false, quiet = false, workflowName, json: json2 = false, strict = false } = options;
60341
60334
  try {
60342
60335
  let pattern = input;
60343
60336
  try {
60344
60337
  if (fs15.existsSync(input) && fs15.statSync(input).isDirectory()) {
60345
- pattern = path15.join(input, "**/*.ts");
60338
+ pattern = path16.join(input, "**/*.ts");
60346
60339
  }
60347
60340
  } catch {
60348
60341
  }
@@ -60376,7 +60369,7 @@ async function validateCommand(input, options = {}) {
60376
60369
  const jsonResults = [];
60377
60370
  for (let i = 0; i < files.length; i++) {
60378
60371
  const file = files[i];
60379
- const fileName = path15.basename(file);
60372
+ const fileName = path16.basename(file);
60380
60373
  if (!json2 && verbose) {
60381
60374
  logger.progress(i + 1, files.length, fileName);
60382
60375
  }
@@ -60561,7 +60554,11 @@ async function validateCommand(input, options = {}) {
60561
60554
  }
60562
60555
  }
60563
60556
  if (totalErrors > 0) {
60564
- process.exit(1);
60557
+ if (json2) {
60558
+ process.exitCode = 1;
60559
+ return;
60560
+ }
60561
+ throw new Error(`Validation failed with ${totalErrors} error${totalErrors !== 1 ? "s" : ""}`);
60565
60562
  }
60566
60563
  } catch (error2) {
60567
60564
  if (json2) {
@@ -65480,15 +65477,15 @@ var require_route = __commonJS({
65480
65477
  };
65481
65478
  }
65482
65479
  function wrapConversion(toModel, graph) {
65483
- const path54 = [graph[toModel].parent, toModel];
65480
+ const path55 = [graph[toModel].parent, toModel];
65484
65481
  let fn = conversions[graph[toModel].parent][toModel];
65485
65482
  let cur = graph[toModel].parent;
65486
65483
  while (graph[cur].parent) {
65487
- path54.unshift(graph[cur].parent);
65484
+ path55.unshift(graph[cur].parent);
65488
65485
  fn = link(conversions[graph[cur].parent][cur], fn);
65489
65486
  cur = graph[cur].parent;
65490
65487
  }
65491
- fn.conversion = path54;
65488
+ fn.conversion = path55;
65492
65489
  return fn;
65493
65490
  }
65494
65491
  module2.exports = function(fromModel) {
@@ -66050,12 +66047,12 @@ var init_esm8 = __esm({
66050
66047
 
66051
66048
  // src/docs/index.ts
66052
66049
  import * as fs16 from "fs";
66053
- import * as path16 from "path";
66050
+ import * as path17 from "path";
66054
66051
  import { fileURLToPath as fileURLToPath3 } from "url";
66055
66052
  function getDocsDir() {
66056
66053
  const thisFile = fileURLToPath3(import.meta.url);
66057
- const packageRoot = path16.resolve(path16.dirname(thisFile), "..", "..");
66058
- return path16.join(packageRoot, "docs", "reference");
66054
+ const packageRoot = path17.resolve(path17.dirname(thisFile), "..", "..");
66055
+ return path17.join(packageRoot, "docs", "reference");
66059
66056
  }
66060
66057
  function parseFrontmatter(raw) {
66061
66058
  const fmMatch = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
@@ -66132,7 +66129,7 @@ function listTopics() {
66132
66129
  if (fs16.existsSync(docsDir)) {
66133
66130
  const files = fs16.readdirSync(docsDir).filter((f) => f.endsWith(".md")).sort();
66134
66131
  for (const file of files) {
66135
- const raw = fs16.readFileSync(path16.join(docsDir, file), "utf-8");
66132
+ const raw = fs16.readFileSync(path17.join(docsDir, file), "utf-8");
66136
66133
  const { frontmatter } = parseFrontmatter(raw);
66137
66134
  coreTopics.push({
66138
66135
  slug: file.replace(/\.md$/, ""),
@@ -66157,7 +66154,7 @@ function listTopics() {
66157
66154
  }
66158
66155
  function readTopic(slug, compact2) {
66159
66156
  const docsDir = getDocsDir();
66160
- const coreFilePath = path16.join(docsDir, `${slug}.md`);
66157
+ const coreFilePath = path17.join(docsDir, `${slug}.md`);
66161
66158
  if (fs16.existsSync(coreFilePath)) {
66162
66159
  const raw = fs16.readFileSync(coreFilePath, "utf-8");
66163
66160
  const { frontmatter, body } = parseFrontmatter(raw);
@@ -66190,7 +66187,7 @@ function readTopic(slug, compact2) {
66190
66187
  }
66191
66188
  function readTopicStructured(slug) {
66192
66189
  const docsDir = getDocsDir();
66193
- const filePath = path16.join(docsDir, `${slug}.md`);
66190
+ const filePath = path17.join(docsDir, `${slug}.md`);
66194
66191
  if (!fs16.existsSync(filePath)) return null;
66195
66192
  const raw = fs16.readFileSync(filePath, "utf-8");
66196
66193
  const { frontmatter, body } = parseFrontmatter(raw);
@@ -66214,7 +66211,7 @@ function searchDocs(query) {
66214
66211
  (kw) => queryTerms.some((term) => kw.toLowerCase().includes(term))
66215
66212
  );
66216
66213
  const packTopic = packDocTopics.find((p) => p.slug === topic.slug);
66217
- const filePath = packTopic ? packTopic.filePath : path16.join(docsDir, `${topic.slug}.md`);
66214
+ const filePath = packTopic ? packTopic.filePath : path17.join(docsDir, `${topic.slug}.md`);
66218
66215
  if (!fs16.existsSync(filePath)) continue;
66219
66216
  const raw = fs16.readFileSync(filePath, "utf-8");
66220
66217
  const { body } = parseFrontmatter(raw);
@@ -67084,7 +67081,7 @@ __export(mcp_setup_exports, {
67084
67081
  });
67085
67082
  import { execSync as execSync3 } from "child_process";
67086
67083
  import * as fs17 from "fs";
67087
- import * as path17 from "path";
67084
+ import * as path18 from "path";
67088
67085
  import * as os from "os";
67089
67086
  function defaultDeps() {
67090
67087
  return {
@@ -67132,7 +67129,7 @@ async function binaryExists(binary2, deps) {
67132
67129
  async function mergeJsonConfig(deps, filePath, rootKey) {
67133
67130
  const existing = await deps.readFile(filePath);
67134
67131
  if (existing === null) {
67135
- const dir = path17.dirname(filePath);
67132
+ const dir = path18.dirname(filePath);
67136
67133
  await deps.mkdir(dir);
67137
67134
  const config3 = { [rootKey]: { "flow-weaver": MCP_ENTRY } };
67138
67135
  await deps.writeFile(filePath, JSON.stringify(config3, null, 2) + "\n");
@@ -67341,12 +67338,12 @@ var init_mcp_setup = __esm({
67341
67338
  id: "cursor",
67342
67339
  displayName: "Cursor",
67343
67340
  detect: async (deps) => {
67344
- const dirExists = await deps.fileExists(path17.join(deps.cwd(), ".cursor"));
67341
+ const dirExists = await deps.fileExists(path18.join(deps.cwd(), ".cursor"));
67345
67342
  if (dirExists) return true;
67346
67343
  return binaryExists("cursor", deps);
67347
67344
  },
67348
67345
  isConfigured: async (deps) => {
67349
- const filePath = path17.join(deps.cwd(), ".cursor", "mcp.json");
67346
+ const filePath = path18.join(deps.cwd(), ".cursor", "mcp.json");
67350
67347
  const content = await deps.readFile(filePath);
67351
67348
  if (!content) return false;
67352
67349
  try {
@@ -67357,7 +67354,7 @@ var init_mcp_setup = __esm({
67357
67354
  }
67358
67355
  },
67359
67356
  configure: async (deps) => {
67360
- const filePath = path17.join(deps.cwd(), ".cursor", "mcp.json");
67357
+ const filePath = path18.join(deps.cwd(), ".cursor", "mcp.json");
67361
67358
  const result = await mergeJsonConfig(deps, filePath, "mcpServers");
67362
67359
  return result.detail;
67363
67360
  }
@@ -67368,7 +67365,7 @@ var init_mcp_setup = __esm({
67368
67365
  displayName: "VS Code Copilot",
67369
67366
  detect: (deps) => binaryExists("code", deps),
67370
67367
  isConfigured: async (deps) => {
67371
- const filePath = path17.join(deps.cwd(), ".vscode", "mcp.json");
67368
+ const filePath = path18.join(deps.cwd(), ".vscode", "mcp.json");
67372
67369
  const content = await deps.readFile(filePath);
67373
67370
  if (!content) return false;
67374
67371
  try {
@@ -67379,7 +67376,7 @@ var init_mcp_setup = __esm({
67379
67376
  }
67380
67377
  },
67381
67378
  configure: async (deps) => {
67382
- const filePath = path17.join(deps.cwd(), ".vscode", "mcp.json");
67379
+ const filePath = path18.join(deps.cwd(), ".vscode", "mcp.json");
67383
67380
  const result = await mergeJsonConfig(deps, filePath, "servers");
67384
67381
  return result.detail;
67385
67382
  }
@@ -67389,13 +67386,13 @@ var init_mcp_setup = __esm({
67389
67386
  id: "windsurf",
67390
67387
  displayName: "Windsurf",
67391
67388
  detect: async (deps) => {
67392
- const configDir = path17.join(deps.homedir(), ".codeium", "windsurf");
67389
+ const configDir = path18.join(deps.homedir(), ".codeium", "windsurf");
67393
67390
  const dirExists = await deps.fileExists(configDir);
67394
67391
  if (dirExists) return true;
67395
67392
  return binaryExists("windsurf", deps);
67396
67393
  },
67397
67394
  isConfigured: async (deps) => {
67398
- const filePath = path17.join(deps.homedir(), ".codeium", "windsurf", "mcp_config.json");
67395
+ const filePath = path18.join(deps.homedir(), ".codeium", "windsurf", "mcp_config.json");
67399
67396
  const content = await deps.readFile(filePath);
67400
67397
  if (!content) return false;
67401
67398
  try {
@@ -67406,7 +67403,7 @@ var init_mcp_setup = __esm({
67406
67403
  }
67407
67404
  },
67408
67405
  configure: async (deps) => {
67409
- const filePath = path17.join(deps.homedir(), ".codeium", "windsurf", "mcp_config.json");
67406
+ const filePath = path18.join(deps.homedir(), ".codeium", "windsurf", "mcp_config.json");
67410
67407
  const result = await mergeJsonConfig(deps, filePath, "mcpServers");
67411
67408
  return result.detail;
67412
67409
  }
@@ -67434,10 +67431,10 @@ var init_mcp_setup = __esm({
67434
67431
  id: "openclaw",
67435
67432
  displayName: "OpenClaw",
67436
67433
  detect: async (deps) => {
67437
- return deps.fileExists(path17.join(deps.cwd(), "openclaw.json"));
67434
+ return deps.fileExists(path18.join(deps.cwd(), "openclaw.json"));
67438
67435
  },
67439
67436
  isConfigured: async (deps) => {
67440
- const filePath = path17.join(deps.cwd(), "openclaw.json");
67437
+ const filePath = path18.join(deps.cwd(), "openclaw.json");
67441
67438
  const content = await deps.readFile(filePath);
67442
67439
  if (!content) return false;
67443
67440
  try {
@@ -67448,7 +67445,7 @@ var init_mcp_setup = __esm({
67448
67445
  }
67449
67446
  },
67450
67447
  configure: async (deps) => {
67451
- const filePath = path17.join(deps.cwd(), "openclaw.json");
67448
+ const filePath = path18.join(deps.cwd(), "openclaw.json");
67452
67449
  const result = await mergeJsonConfig(deps, filePath, "mcpServers");
67453
67450
  return result.detail;
67454
67451
  }
@@ -67472,7 +67469,7 @@ __export(init_exports, {
67472
67469
  validateProjectName: () => validateProjectName
67473
67470
  });
67474
67471
  import * as fs18 from "fs";
67475
- import * as path18 from "path";
67472
+ import * as path19 from "path";
67476
67473
  import { execSync as execSync4, spawn } from "child_process";
67477
67474
  function validateProjectName(name) {
67478
67475
  if (!name) return "Project name cannot be empty";
@@ -67503,7 +67500,7 @@ async function resolveInitConfig(dirArg, options) {
67503
67500
  if (options.name) {
67504
67501
  projectName = options.name;
67505
67502
  } else if (dirArg) {
67506
- projectName = path18.basename(dirArg);
67503
+ projectName = path19.basename(dirArg);
67507
67504
  } else if (skipPrompts) {
67508
67505
  projectName = "my-project";
67509
67506
  } else {
@@ -67517,7 +67514,7 @@ async function resolveInitConfig(dirArg, options) {
67517
67514
  if (valid !== true) {
67518
67515
  throw new Error(valid);
67519
67516
  }
67520
- const targetDir = path18.resolve(dirArg ?? projectName);
67517
+ const targetDir = path19.resolve(dirArg ?? projectName);
67521
67518
  let persona;
67522
67519
  if (options.preset) {
67523
67520
  if (!VALID_PERSONAS.includes(options.preset)) {
@@ -67823,8 +67820,8 @@ function scaffoldProject(targetDir, files, options) {
67823
67820
  const filesCreated = [];
67824
67821
  const filesSkipped = [];
67825
67822
  for (const [relativePath, content] of Object.entries(files)) {
67826
- const absPath = path18.join(targetDir, relativePath);
67827
- const dir = path18.dirname(absPath);
67823
+ const absPath = path19.join(targetDir, relativePath);
67824
+ const dir = path19.dirname(absPath);
67828
67825
  fs18.mkdirSync(dir, { recursive: true });
67829
67826
  if (fs18.existsSync(absPath) && !options.force) {
67830
67827
  filesSkipped.push(relativePath);
@@ -67898,9 +67895,9 @@ async function handleAgentHandoff(opts) {
67898
67895
  }
67899
67896
  if (promptAction === "file" || promptAction === "both") {
67900
67897
  const setupContent = generateSetupPromptFile(projectName, persona, template, filesCreated, useCaseDescription);
67901
- const setupPath = path18.join(targetDir, "PROJECT_SETUP.md");
67898
+ const setupPath = path19.join(targetDir, "PROJECT_SETUP.md");
67902
67899
  fs18.writeFileSync(setupPath, setupContent, "utf8");
67903
- const gitignorePath = path18.join(targetDir, ".gitignore");
67900
+ const gitignorePath = path19.join(targetDir, ".gitignore");
67904
67901
  if (fs18.existsSync(gitignorePath)) {
67905
67902
  const existing = fs18.readFileSync(gitignorePath, "utf8");
67906
67903
  if (!existing.includes("PROJECT_SETUP.md")) {
@@ -67917,7 +67914,7 @@ async function initCommand(dirArg, options) {
67917
67914
  try {
67918
67915
  await loadPackTemplates(process.cwd());
67919
67916
  const config2 = await resolveInitConfig(dirArg, options);
67920
- const pkgPath = path18.join(config2.targetDir, "package.json");
67917
+ const pkgPath = path19.join(config2.targetDir, "package.json");
67921
67918
  if (fs18.existsSync(pkgPath) && !config2.force) {
67922
67919
  throw new Error(
67923
67920
  `${config2.targetDir} already contains a package.json. Use --force to overwrite.`
@@ -67941,7 +67938,7 @@ async function initCommand(dirArg, options) {
67941
67938
  gitResult = runGitInit(config2.targetDir);
67942
67939
  }
67943
67940
  const workflowFile = `${config2.projectName}-workflow.ts`;
67944
- const workflowPath = path18.join(config2.targetDir, "src", workflowFile);
67941
+ const workflowPath = path19.join(config2.targetDir, "src", workflowFile);
67945
67942
  let compileResult;
67946
67943
  if (!options.json && fs18.existsSync(workflowPath)) {
67947
67944
  try {
@@ -68042,7 +68039,7 @@ async function initCommand(dirArg, options) {
68042
68039
  logger.newline();
68043
68040
  }
68044
68041
  const workflowCode = files[`src/${workflowFile}`] ?? null;
68045
- const relDir = path18.relative(process.cwd(), config2.targetDir);
68042
+ const relDir = path19.relative(process.cwd(), config2.targetDir);
68046
68043
  const displayDir = !relDir || relDir === "." ? null : relDir.startsWith("../../") ? config2.targetDir : relDir;
68047
68044
  const skipAgent = options.agent === false || options.yes || isNonInteractive();
68048
68045
  if (!skipAgent) {
@@ -68176,7 +68173,7 @@ var watch_exports = {};
68176
68173
  __export(watch_exports, {
68177
68174
  watchCommand: () => watchCommand
68178
68175
  });
68179
- import * as path19 from "path";
68176
+ import * as path20 from "path";
68180
68177
  function timestamp2() {
68181
68178
  const now = /* @__PURE__ */ new Date();
68182
68179
  const h = String(now.getHours()).padStart(2, "0");
@@ -68201,7 +68198,7 @@ async function watchCommand(input, options = {}) {
68201
68198
  });
68202
68199
  watcher.on("change", async (file) => {
68203
68200
  logger.newline();
68204
- logger.info(`${timestamp2()} File changed: ${path19.basename(file)}`);
68201
+ logger.info(`${timestamp2()} File changed: ${path20.basename(file)}`);
68205
68202
  logger.info(`${timestamp2()} Recompiling...`);
68206
68203
  logger.newline();
68207
68204
  try {
@@ -68242,15 +68239,15 @@ var init_watch = __esm({
68242
68239
  });
68243
68240
 
68244
68241
  // src/mcp/workflow-executor.ts
68245
- import * as path20 from "path";
68242
+ import * as path21 from "path";
68246
68243
  import * as fs19 from "fs";
68247
68244
  import { pathToFileURL } from "url";
68248
68245
  import ts4 from "typescript";
68249
68246
  async function executeWorkflowFromFile(filePath, params, options) {
68250
- const resolvedPath = path20.resolve(filePath);
68247
+ const resolvedPath = path21.resolve(filePath);
68251
68248
  const includeTrace = options?.includeTrace !== false;
68252
68249
  const tmpId = `fw-exec-${Date.now()}-${Math.random().toString(36).slice(2)}`;
68253
- const tmpBase = path20.join(path20.dirname(resolvedPath), tmpId);
68250
+ const tmpBase = path21.join(path21.dirname(resolvedPath), tmpId);
68254
68251
  const tmpTsFile = `${tmpBase}.ts`;
68255
68252
  const tmpFile = `${tmpBase}.mjs`;
68256
68253
  try {
@@ -68279,20 +68276,20 @@ async function executeWorkflowFromFile(filePath, params, options) {
68279
68276
  }
68280
68277
  });
68281
68278
  let transpiledOutput = jsOutput.outputText;
68282
- const srcDir = path20.dirname(tmpTsFile);
68283
- if (srcDir.includes(`${path20.sep}src${path20.sep}`)) {
68284
- const distDir = srcDir.replace(`${path20.sep}src${path20.sep}`, `${path20.sep}dist${path20.sep}`);
68279
+ const srcDir = path21.dirname(tmpTsFile);
68280
+ if (srcDir.includes(`${path21.sep}src${path21.sep}`)) {
68281
+ const distDir = srcDir.replace(`${path21.sep}src${path21.sep}`, `${path21.sep}dist${path21.sep}`);
68285
68282
  transpiledOutput = transpiledOutput.replace(
68286
68283
  /from\s+['"](\.[^'"]+)['"]/g,
68287
68284
  (_match, specifier) => {
68288
- const resolvedSrc = path20.resolve(srcDir, specifier);
68285
+ const resolvedSrc = path21.resolve(srcDir, specifier);
68289
68286
  if (!fs19.existsSync(resolvedSrc)) {
68290
68287
  const distEquivalent = resolvedSrc.replace(
68291
- `${path20.sep}src${path20.sep}`,
68292
- `${path20.sep}dist${path20.sep}`
68288
+ `${path21.sep}src${path21.sep}`,
68289
+ `${path21.sep}dist${path21.sep}`
68293
68290
  );
68294
68291
  if (fs19.existsSync(distEquivalent)) {
68295
- const relative10 = path20.relative(srcDir, distEquivalent);
68292
+ const relative10 = path21.relative(srcDir, distEquivalent);
68296
68293
  const posixRelative = relative10.replace(/\\/g, "/");
68297
68294
  const normalized = posixRelative.startsWith(".") ? posixRelative : `./${posixRelative}`;
68298
68295
  return `from '${normalized}'`;
@@ -68433,7 +68430,7 @@ var dev_exports = {};
68433
68430
  __export(dev_exports, {
68434
68431
  devCommand: () => devCommand
68435
68432
  });
68436
- import * as path21 from "path";
68433
+ import * as path22 from "path";
68437
68434
  import * as fs20 from "fs";
68438
68435
  function timestamp3() {
68439
68436
  const now = /* @__PURE__ */ new Date();
@@ -68448,7 +68445,7 @@ function cycleSeparator(file) {
68448
68445
  logger.log(`
68449
68446
  ${logger.dim(`\u2500\u2500\u2500 ${ts5} ${pad2}`)}`);
68450
68447
  if (file) {
68451
- logger.log(` ${logger.dim("File changed:")} ${path21.basename(file)}`);
68448
+ logger.log(` ${logger.dim("File changed:")} ${path22.basename(file)}`);
68452
68449
  }
68453
68450
  }
68454
68451
  function parseParams(options) {
@@ -68460,7 +68457,7 @@ function parseParams(options) {
68460
68457
  }
68461
68458
  }
68462
68459
  if (options.paramsFile) {
68463
- const paramsFilePath = path21.resolve(options.paramsFile);
68460
+ const paramsFilePath = path22.resolve(options.paramsFile);
68464
68461
  if (!fs20.existsSync(paramsFilePath)) {
68465
68462
  throw new Error(`Params file not found: ${paramsFilePath}`);
68466
68463
  }
@@ -68540,7 +68537,7 @@ async function compileAndRun(filePath, params, options) {
68540
68537
  }
68541
68538
  }
68542
68539
  async function devCommand(input, options = {}) {
68543
- const filePath = path21.resolve(input);
68540
+ const filePath = path22.resolve(input);
68544
68541
  if (!fs20.existsSync(filePath)) {
68545
68542
  throw new Error(`File not found: ${filePath}`);
68546
68543
  }
@@ -68557,7 +68554,7 @@ async function devCommand(input, options = {}) {
68557
68554
  const params = parseParams(options);
68558
68555
  if (!options.json) {
68559
68556
  logger.section("Dev Mode");
68560
- logger.info(`File: ${path21.basename(filePath)}`);
68557
+ logger.info(`File: ${path22.basename(filePath)}`);
68561
68558
  if (Object.keys(params).length > 0) {
68562
68559
  logger.info(`Params: ${JSON.stringify(params)}`);
68563
68560
  }
@@ -68816,10 +68813,10 @@ function assignProp(target, prop, value) {
68816
68813
  configurable: true
68817
68814
  });
68818
68815
  }
68819
- function getElementAtPath(obj, path54) {
68820
- if (!path54)
68816
+ function getElementAtPath(obj, path55) {
68817
+ if (!path55)
68821
68818
  return obj;
68822
- return path54.reduce((acc, key) => acc?.[key], obj);
68819
+ return path55.reduce((acc, key) => acc?.[key], obj);
68823
68820
  }
68824
68821
  function promiseAllObject(promisesObj) {
68825
68822
  const keys2 = Object.keys(promisesObj);
@@ -69068,11 +69065,11 @@ function aborted(x, startIndex = 0) {
69068
69065
  }
69069
69066
  return false;
69070
69067
  }
69071
- function prefixIssues(path54, issues) {
69068
+ function prefixIssues(path55, issues) {
69072
69069
  return issues.map((iss) => {
69073
69070
  var _a2;
69074
69071
  (_a2 = iss).path ?? (_a2.path = []);
69075
- iss.path.unshift(path54);
69072
+ iss.path.unshift(path55);
69076
69073
  return iss;
69077
69074
  });
69078
69075
  }
@@ -69289,7 +69286,7 @@ var init_errors6 = __esm({
69289
69286
  });
69290
69287
 
69291
69288
  // node_modules/zod/v4/core/parse.js
69292
- var _parse, parse3, _parseAsync, parseAsync, _safeParse, safeParse, _safeParseAsync, safeParseAsync;
69289
+ var _parse, parse2, _parseAsync, parseAsync, _safeParse, safeParse, _safeParseAsync, safeParseAsync;
69293
69290
  var init_parse2 = __esm({
69294
69291
  "node_modules/zod/v4/core/parse.js"() {
69295
69292
  init_core();
@@ -69308,7 +69305,7 @@ var init_parse2 = __esm({
69308
69305
  }
69309
69306
  return result.value;
69310
69307
  };
69311
- parse3 = /* @__PURE__ */ _parse($ZodRealError);
69308
+ parse2 = /* @__PURE__ */ _parse($ZodRealError);
69312
69309
  _parseAsync = (_Err) => async (schema2, value, _ctx, params) => {
69313
69310
  const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
69314
69311
  let result = schema2._zod.run({ value, issues: [] }, ctx);
@@ -72573,7 +72570,7 @@ var init_schemas2 = __esm({
72573
72570
  throw new Error("Uninitialized schema in ZodMiniType.");
72574
72571
  $ZodType.init(inst, def);
72575
72572
  inst.def = def;
72576
- inst.parse = (data, params) => parse3(inst, data, params, { callee: inst.parse });
72573
+ inst.parse = (data, params) => parse2(inst, data, params, { callee: inst.parse });
72577
72574
  inst.safeParse = (data, params) => safeParse(inst, data, params);
72578
72575
  inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
72579
72576
  inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
@@ -72897,12 +72894,12 @@ var init_errors7 = __esm({
72897
72894
  });
72898
72895
 
72899
72896
  // node_modules/zod/v4/classic/parse.js
72900
- var parse4, parseAsync2, safeParse3, safeParseAsync3;
72897
+ var parse3, parseAsync2, safeParse3, safeParseAsync3;
72901
72898
  var init_parse4 = __esm({
72902
72899
  "node_modules/zod/v4/classic/parse.js"() {
72903
72900
  init_core2();
72904
72901
  init_errors7();
72905
- parse4 = /* @__PURE__ */ _parse(ZodRealError);
72902
+ parse3 = /* @__PURE__ */ _parse(ZodRealError);
72906
72903
  parseAsync2 = /* @__PURE__ */ _parseAsync(ZodRealError);
72907
72904
  safeParse3 = /* @__PURE__ */ _safeParse(ZodRealError);
72908
72905
  safeParseAsync3 = /* @__PURE__ */ _safeParseAsync(ZodRealError);
@@ -73132,7 +73129,7 @@ var init_schemas3 = __esm({
73132
73129
  reg.add(inst, meta);
73133
73130
  return inst;
73134
73131
  });
73135
- inst.parse = (data, params) => parse4(inst, data, params, { callee: inst.parse });
73132
+ inst.parse = (data, params) => parse3(inst, data, params, { callee: inst.parse });
73136
73133
  inst.safeParse = (data, params) => safeParse3(inst, data, params);
73137
73134
  inst.parseAsync = async (data, params) => parseAsync2(inst, data, params, { callee: inst.parseAsync });
73138
73135
  inst.safeParseAsync = async (data, params) => safeParseAsync3(inst, data, params);
@@ -80878,8 +80875,8 @@ var require_utils = __commonJS({
80878
80875
  }
80879
80876
  return ind;
80880
80877
  }
80881
- function removeDotSegments(path54) {
80882
- let input = path54;
80878
+ function removeDotSegments(path55) {
80879
+ let input = path55;
80883
80880
  const output = [];
80884
80881
  let nextSlash = -1;
80885
80882
  let len = 0;
@@ -81078,8 +81075,8 @@ var require_schemes = __commonJS({
81078
81075
  wsComponent.secure = void 0;
81079
81076
  }
81080
81077
  if (wsComponent.resourceName) {
81081
- const [path54, query] = wsComponent.resourceName.split("?");
81082
- wsComponent.path = path54 && path54 !== "/" ? path54 : void 0;
81078
+ const [path55, query] = wsComponent.resourceName.split("?");
81079
+ wsComponent.path = path55 && path55 !== "/" ? path55 : void 0;
81083
81080
  wsComponent.query = query;
81084
81081
  wsComponent.resourceName = void 0;
81085
81082
  }
@@ -81231,24 +81228,24 @@ var require_fast_uri = __commonJS({
81231
81228
  function normalize2(uri, options) {
81232
81229
  if (typeof uri === "string") {
81233
81230
  uri = /** @type {T} */
81234
- serialize(parse5(uri, options), options);
81231
+ serialize(parse4(uri, options), options);
81235
81232
  } else if (typeof uri === "object") {
81236
81233
  uri = /** @type {T} */
81237
- parse5(serialize(uri, options), options);
81234
+ parse4(serialize(uri, options), options);
81238
81235
  }
81239
81236
  return uri;
81240
81237
  }
81241
81238
  function resolve38(baseURI, relativeURI, options) {
81242
81239
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
81243
- const resolved = resolveComponent(parse5(baseURI, schemelessOptions), parse5(relativeURI, schemelessOptions), schemelessOptions, true);
81240
+ const resolved = resolveComponent(parse4(baseURI, schemelessOptions), parse4(relativeURI, schemelessOptions), schemelessOptions, true);
81244
81241
  schemelessOptions.skipEscape = true;
81245
81242
  return serialize(resolved, schemelessOptions);
81246
81243
  }
81247
81244
  function resolveComponent(base, relative10, options, skipNormalization) {
81248
81245
  const target = {};
81249
81246
  if (!skipNormalization) {
81250
- base = parse5(serialize(base, options), options);
81251
- relative10 = parse5(serialize(relative10, options), options);
81247
+ base = parse4(serialize(base, options), options);
81248
+ relative10 = parse4(serialize(relative10, options), options);
81252
81249
  }
81253
81250
  options = options || {};
81254
81251
  if (!options.tolerant && relative10.scheme) {
@@ -81300,13 +81297,13 @@ var require_fast_uri = __commonJS({
81300
81297
  function equal(uriA, uriB, options) {
81301
81298
  if (typeof uriA === "string") {
81302
81299
  uriA = unescape(uriA);
81303
- uriA = serialize(normalizeComponentEncoding(parse5(uriA, options), true), { ...options, skipEscape: true });
81300
+ uriA = serialize(normalizeComponentEncoding(parse4(uriA, options), true), { ...options, skipEscape: true });
81304
81301
  } else if (typeof uriA === "object") {
81305
81302
  uriA = serialize(normalizeComponentEncoding(uriA, true), { ...options, skipEscape: true });
81306
81303
  }
81307
81304
  if (typeof uriB === "string") {
81308
81305
  uriB = unescape(uriB);
81309
- uriB = serialize(normalizeComponentEncoding(parse5(uriB, options), true), { ...options, skipEscape: true });
81306
+ uriB = serialize(normalizeComponentEncoding(parse4(uriB, options), true), { ...options, skipEscape: true });
81310
81307
  } else if (typeof uriB === "object") {
81311
81308
  uriB = serialize(normalizeComponentEncoding(uriB, true), { ...options, skipEscape: true });
81312
81309
  }
@@ -81375,7 +81372,7 @@ var require_fast_uri = __commonJS({
81375
81372
  return uriTokens.join("");
81376
81373
  }
81377
81374
  var URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
81378
- function parse5(uri, opts) {
81375
+ function parse4(uri, opts) {
81379
81376
  const options = Object.assign({}, opts);
81380
81377
  const parsed = {
81381
81378
  scheme: void 0,
@@ -81469,7 +81466,7 @@ var require_fast_uri = __commonJS({
81469
81466
  resolveComponent,
81470
81467
  equal,
81471
81468
  serialize,
81472
- parse: parse5
81469
+ parse: parse4
81473
81470
  };
81474
81471
  module2.exports = fastUri;
81475
81472
  module2.exports.default = fastUri;
@@ -84441,12 +84438,12 @@ var require_dist = __commonJS({
84441
84438
  throw new Error(`Unknown format "${name}"`);
84442
84439
  return f;
84443
84440
  };
84444
- function addFormats(ajv, list, fs50, exportName) {
84441
+ function addFormats(ajv, list, fs48, exportName) {
84445
84442
  var _a2;
84446
84443
  var _b;
84447
84444
  (_a2 = (_b = ajv.opts.code).formats) !== null && _a2 !== void 0 ? _a2 : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
84448
84445
  for (const f of list)
84449
- ajv.addFormat(f, fs50[f]);
84446
+ ajv.addFormat(f, fs48[f]);
84450
84447
  }
84451
84448
  module2.exports = exports2 = formatsPlugin;
84452
84449
  Object.defineProperty(exports2, "__esModule", { value: true });
@@ -86123,7 +86120,7 @@ var init_response_utils = __esm({
86123
86120
  });
86124
86121
 
86125
86122
  // src/mcp/tools-query.ts
86126
- import * as path22 from "path";
86123
+ import * as path23 from "path";
86127
86124
  function parseErrorCode(errors2) {
86128
86125
  if (errors2.some((e) => e.includes("[MULTIPLE_WORKFLOWS_FOUND]"))) {
86129
86126
  return "MULTIPLE_WORKFLOWS_FOUND";
@@ -86142,11 +86139,11 @@ function registerQueryTools(mcp) {
86142
86139
  },
86143
86140
  async (args) => {
86144
86141
  try {
86145
- const filePath = path22.resolve(args.filePath);
86146
- const parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName, projectDir: path22.dirname(filePath) });
86142
+ const filePath = path23.resolve(args.filePath);
86143
+ const parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName, projectDir: path23.dirname(filePath) });
86147
86144
  if (parseResult.errors.length > 0 && parseResult.errors.some((e) => typeof e === "string" && e.includes("No workflows found"))) {
86148
86145
  try {
86149
- const ntResult = await parseWorkflow(filePath, { nodeTypesOnly: true, projectDir: path22.dirname(filePath) });
86146
+ const ntResult = await parseWorkflow(filePath, { nodeTypesOnly: true, projectDir: path23.dirname(filePath) });
86150
86147
  if (ntResult.errors.length === 0 && ntResult.ast.nodeTypes?.length > 0) {
86151
86148
  return makeToolResult({
86152
86149
  nodeTypesOnly: true,
@@ -86191,11 +86188,11 @@ ${parseResult.errors.join("\n")}`
86191
86188
  },
86192
86189
  async (args) => {
86193
86190
  try {
86194
- const filePath = path22.resolve(args.filePath);
86195
- const parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName, projectDir: path22.dirname(filePath) });
86191
+ const filePath = path23.resolve(args.filePath);
86192
+ const parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName, projectDir: path23.dirname(filePath) });
86196
86193
  if (parseResult.errors.length > 0 && parseResult.errors.some((e) => typeof e === "string" && e.includes("No workflows found"))) {
86197
86194
  try {
86198
- const ntResult = await parseWorkflow(filePath, { nodeTypesOnly: true, projectDir: path22.dirname(filePath) });
86195
+ const ntResult = await parseWorkflow(filePath, { nodeTypesOnly: true, projectDir: path23.dirname(filePath) });
86199
86196
  if (ntResult.errors.length === 0 && ntResult.ast.nodeTypes?.length > 0) {
86200
86197
  const count = ntResult.ast.nodeTypes.length;
86201
86198
  return makeToolResult({
@@ -86271,7 +86268,7 @@ ${parseResult.errors.join("\n")}`
86271
86268
  },
86272
86269
  async (args) => {
86273
86270
  try {
86274
- const filePath = path22.resolve(args.filePath);
86271
+ const filePath = path23.resolve(args.filePath);
86275
86272
  const customTarget = args.target && args.target !== "typescript" ? compileTargetRegistry.get(args.target) : void 0;
86276
86273
  if (args.target && args.target !== "typescript") {
86277
86274
  if (!customTarget) {
@@ -86313,8 +86310,8 @@ ${parseResult.errors.join("\n")}`);
86313
86310
  });
86314
86311
  const outputFile = filePath.replace(/\.ts$/, `.${args.target}.ts`);
86315
86312
  if (args.write !== false) {
86316
- const fs50 = await import("fs");
86317
- fs50.writeFileSync(outputFile, code, "utf8");
86313
+ const fs48 = await import("fs");
86314
+ fs48.writeFileSync(outputFile, code, "utf8");
86318
86315
  }
86319
86316
  return makeToolResult({
86320
86317
  target: args.target,
@@ -86351,11 +86348,11 @@ ${parseResult.errors.join("\n")}`);
86351
86348
  },
86352
86349
  async (args) => {
86353
86350
  try {
86354
- const file1 = path22.resolve(args.file1);
86355
- const file2 = path22.resolve(args.file2);
86351
+ const file1 = path23.resolve(args.file1);
86352
+ const file2 = path23.resolve(args.file2);
86356
86353
  const [result1, result2] = await Promise.all([
86357
- parseWorkflow(file1, { workflowName: args.workflowName, projectDir: path22.dirname(file1) }),
86358
- parseWorkflow(file2, { workflowName: args.workflowName, projectDir: path22.dirname(file2) })
86354
+ parseWorkflow(file1, { workflowName: args.workflowName, projectDir: path23.dirname(file1) }),
86355
+ parseWorkflow(file2, { workflowName: args.workflowName, projectDir: path23.dirname(file2) })
86359
86356
  ]);
86360
86357
  if (result1.errors.length > 0) {
86361
86358
  return makeErrorResult(
@@ -86417,11 +86414,11 @@ Query types:
86417
86414
  },
86418
86415
  async (args) => {
86419
86416
  try {
86420
- const filePath = path22.resolve(args.filePath);
86421
- let parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName, projectDir: path22.dirname(filePath) });
86417
+ const filePath = path23.resolve(args.filePath);
86418
+ let parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName, projectDir: path23.dirname(filePath) });
86422
86419
  if (parseResult.errors.length > 0 && args.query === "node-types" && parseResult.errors.some((e) => typeof e === "string" && e.includes("No workflows found"))) {
86423
86420
  try {
86424
- const ntResult = await parseWorkflow(filePath, { nodeTypesOnly: true, projectDir: path22.dirname(filePath) });
86421
+ const ntResult = await parseWorkflow(filePath, { nodeTypesOnly: true, projectDir: path23.dirname(filePath) });
86425
86422
  if (ntResult.errors.length === 0) {
86426
86423
  parseResult = ntResult;
86427
86424
  }
@@ -86516,7 +86513,7 @@ ${parseResult.errors.join("\n")}`
86516
86513
  },
86517
86514
  async (args) => {
86518
86515
  try {
86519
- const dir = path22.resolve(args.directory ?? process.cwd());
86516
+ const dir = path23.resolve(args.directory ?? process.cwd());
86520
86517
  const report = runDoctorChecks(dir);
86521
86518
  return makeToolResult(report);
86522
86519
  } catch (err) {
@@ -86546,7 +86543,7 @@ var init_tools_query = __esm({
86546
86543
  });
86547
86544
 
86548
86545
  // src/mcp/tools-template.ts
86549
- import * as path23 from "path";
86546
+ import * as path24 from "path";
86550
86547
  import * as fs21 from "fs";
86551
86548
  function registerTemplateTools(mcp) {
86552
86549
  mcp.tool(
@@ -86589,7 +86586,7 @@ function registerTemplateTools(mcp) {
86589
86586
  },
86590
86587
  async (args) => {
86591
86588
  try {
86592
- const outPath = path23.resolve(args.filePath);
86589
+ const outPath = path24.resolve(args.filePath);
86593
86590
  const wt = getWorkflowTemplate2(args.template);
86594
86591
  if (wt) {
86595
86592
  const code = generateWorkflowFromTemplate(args.template, {
@@ -86679,7 +86676,7 @@ var init_registry2 = __esm({
86679
86676
  });
86680
86677
 
86681
86678
  // src/mcp/tools-pattern.ts
86682
- import * as path24 from "path";
86679
+ import * as path25 from "path";
86683
86680
  import * as fs22 from "fs";
86684
86681
  function registerPatternTools(mcp) {
86685
86682
  mcp.tool(
@@ -86690,7 +86687,7 @@ function registerPatternTools(mcp) {
86690
86687
  },
86691
86688
  async (args) => {
86692
86689
  try {
86693
- const filePath = path24.resolve(args.filePath);
86690
+ const filePath = path25.resolve(args.filePath);
86694
86691
  const patterns = listPatterns(filePath);
86695
86692
  return makeToolResult(patterns);
86696
86693
  } catch (err) {
@@ -86713,8 +86710,8 @@ function registerPatternTools(mcp) {
86713
86710
  },
86714
86711
  async (args) => {
86715
86712
  try {
86716
- const patternFilePath = path24.resolve(args.patternFile);
86717
- const targetFilePath = path24.resolve(args.targetFile);
86713
+ const patternFilePath = path25.resolve(args.patternFile);
86714
+ const targetFilePath = path25.resolve(args.targetFile);
86718
86715
  const annotationParser = new AnnotationParser();
86719
86716
  const patternResult = annotationParser.parse(patternFilePath);
86720
86717
  if (patternResult.patterns.length === 0) {
@@ -86779,7 +86776,7 @@ function registerPatternTools(mcp) {
86779
86776
  },
86780
86777
  async (args) => {
86781
86778
  try {
86782
- const dir = path24.resolve(args.directory);
86779
+ const dir = path25.resolve(args.directory);
86783
86780
  const results = await findWorkflows(dir, args.pattern);
86784
86781
  return makeToolResult(results);
86785
86782
  } catch (err) {
@@ -86816,7 +86813,7 @@ function registerPatternTools(mcp) {
86816
86813
  if (!paramValidation.success) {
86817
86814
  return makeErrorResult("INVALID_PARAMS", paramValidation.error);
86818
86815
  }
86819
- const filePath = path24.resolve(args.filePath);
86816
+ const filePath = path25.resolve(args.filePath);
86820
86817
  const sourceCode = fs22.readFileSync(filePath, "utf8");
86821
86818
  const parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName });
86822
86819
  if (parseResult.errors.length > 0) {
@@ -87109,7 +87106,7 @@ ${parseResult.errors.join("\n")}`);
87109
87106
  );
87110
87107
  }
87111
87108
  }
87112
- const filePath = path24.resolve(args.filePath);
87109
+ const filePath = path25.resolve(args.filePath);
87113
87110
  const sourceCode = fs22.readFileSync(filePath, "utf8");
87114
87111
  const parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName });
87115
87112
  if (parseResult.errors.length > 0) {
@@ -87220,7 +87217,7 @@ ${parseResult.errors.join("\n")}`);
87220
87217
  },
87221
87218
  async (args) => {
87222
87219
  try {
87223
- const filePath = path24.resolve(args.sourceFile);
87220
+ const filePath = path25.resolve(args.sourceFile);
87224
87221
  const parseResult = await parseWorkflow(filePath);
87225
87222
  if (parseResult.errors.length > 0) {
87226
87223
  return makeErrorResult("PARSE_ERROR", `Parse errors:
@@ -87236,7 +87233,7 @@ ${parseResult.errors.join("\n")}`);
87236
87233
  name: args.name
87237
87234
  });
87238
87235
  if (args.outputFile) {
87239
- const outPath = path24.resolve(args.outputFile);
87236
+ const outPath = path25.resolve(args.outputFile);
87240
87237
  fs22.writeFileSync(outPath, result.patternCode, "utf8");
87241
87238
  return makeToolResult({
87242
87239
  success: true,
@@ -87281,7 +87278,7 @@ ${parseResult.errors.join("\n")}`);
87281
87278
  }
87282
87279
  const results = [];
87283
87280
  for (const file of files) {
87284
- const filePath = path24.resolve(file);
87281
+ const filePath = path25.resolve(file);
87285
87282
  try {
87286
87283
  const sourceCode = fs22.readFileSync(filePath, "utf8");
87287
87284
  const parseResult = await parseWorkflow(filePath);
@@ -87582,7 +87579,7 @@ var init_executor = __esm({
87582
87579
 
87583
87580
  // src/deployment/core/adapters.ts
87584
87581
  import * as fs23 from "fs";
87585
- import * as path25 from "path";
87582
+ import * as path26 from "path";
87586
87583
  import { randomUUID as randomUUID2 } from "crypto";
87587
87584
  function createAdapter(source) {
87588
87585
  switch (source) {
@@ -87669,7 +87666,7 @@ var init_adapters = __esm({
87669
87666
  throw new Error(`Invalid JSON in params: ${input.params}`);
87670
87667
  }
87671
87668
  } else if (input.paramsFile) {
87672
- const paramsFilePath = path25.resolve(input.paramsFile);
87669
+ const paramsFilePath = path26.resolve(input.paramsFile);
87673
87670
  if (!fs23.existsSync(paramsFilePath)) {
87674
87671
  throw new Error(`Params file not found: ${paramsFilePath}`);
87675
87672
  }
@@ -87695,7 +87692,7 @@ var init_adapters = __esm({
87695
87692
  * Extract workflow ID from file path (uses filename without extension)
87696
87693
  */
87697
87694
  extractWorkflowId(filePath) {
87698
- const basename21 = path25.basename(filePath, path25.extname(filePath));
87695
+ const basename21 = path26.basename(filePath, path26.extname(filePath));
87699
87696
  return basename21;
87700
87697
  }
87701
87698
  };
@@ -87926,7 +87923,7 @@ var init_defaults2 = __esm({
87926
87923
 
87927
87924
  // src/deployment/config/loader.ts
87928
87925
  import * as fs24 from "fs";
87929
- import * as path26 from "path";
87926
+ import * as path27 from "path";
87930
87927
  import { pathToFileURL as pathToFileURL2 } from "url";
87931
87928
  async function loadConfig(cliOverrides, configPath) {
87932
87929
  const environment = detectEnvironment(cliOverrides);
@@ -87964,7 +87961,7 @@ async function loadConfigFile(configPath) {
87964
87961
  }
87965
87962
  const cwd = process.cwd();
87966
87963
  for (const fileName of CONFIG_FILE_NAMES) {
87967
- const configFilePath = path26.join(cwd, fileName);
87964
+ const configFilePath = path27.join(cwd, fileName);
87968
87965
  if (fs24.existsSync(configFilePath)) {
87969
87966
  return loadConfigFromPath(configFilePath);
87970
87967
  }
@@ -87972,11 +87969,11 @@ async function loadConfigFile(configPath) {
87972
87969
  return null;
87973
87970
  }
87974
87971
  async function loadConfigFromPath(filePath) {
87975
- const absolutePath = path26.resolve(filePath);
87972
+ const absolutePath = path27.resolve(filePath);
87976
87973
  if (!fs24.existsSync(absolutePath)) {
87977
87974
  return null;
87978
87975
  }
87979
- const ext2 = path26.extname(absolutePath);
87976
+ const ext2 = path27.extname(absolutePath);
87980
87977
  if (ext2 === ".yaml" || ext2 === ".yml") {
87981
87978
  try {
87982
87979
  const content = fs24.readFileSync(absolutePath, "utf8");
@@ -88367,8 +88364,8 @@ var init_generator = __esm({
88367
88364
  doc.paths["/health"] = this.generateHealthEndpoint();
88368
88365
  doc.paths["/workflows"] = this.generateListEndpoint();
88369
88366
  for (const endpoint of endpoints) {
88370
- const path54 = options.basePath ? `${options.basePath}${endpoint.path}` : endpoint.path;
88371
- doc.paths[path54] = this.generateWorkflowEndpoint(endpoint);
88367
+ const path55 = options.basePath ? `${options.basePath}${endpoint.path}` : endpoint.path;
88368
+ doc.paths[path55] = this.generateWorkflowEndpoint(endpoint);
88372
88369
  }
88373
88370
  return doc;
88374
88371
  }
@@ -88602,7 +88599,7 @@ var init_generator = __esm({
88602
88599
  });
88603
88600
 
88604
88601
  // src/deployment/targets/base.ts
88605
- import * as path27 from "path";
88602
+ import * as path28 from "path";
88606
88603
  var BaseExportTarget, ExportTargetRegistry;
88607
88604
  var init_base = __esm({
88608
88605
  "src/deployment/targets/base.ts"() {
@@ -88653,7 +88650,7 @@ var init_base = __esm({
88653
88650
  createFile(outputDir, relativePath, content, type2) {
88654
88651
  return {
88655
88652
  relativePath,
88656
- absolutePath: path27.join(outputDir, relativePath),
88653
+ absolutePath: path28.join(outputDir, relativePath),
88657
88654
  content,
88658
88655
  type: type2
88659
88656
  };
@@ -88706,7 +88703,7 @@ var init_base = __esm({
88706
88703
  * Get relative import path for the workflow
88707
88704
  */
88708
88705
  getWorkflowImport(workflowFile) {
88709
- const basename21 = path27.basename(workflowFile, path27.extname(workflowFile));
88706
+ const basename21 = path28.basename(workflowFile, path28.extname(workflowFile));
88710
88707
  return `./${basename21}.js`;
88711
88708
  }
88712
88709
  /**
@@ -89473,7 +89470,7 @@ __export(deployment_exports, {
89473
89470
  loadConfigSync: () => loadConfigSync,
89474
89471
  schemaConverter: () => schemaConverter
89475
89472
  });
89476
- import * as path28 from "path";
89473
+ import * as path29 from "path";
89477
89474
  import { pathToFileURL as pathToFileURL3 } from "url";
89478
89475
  async function createTargetRegistry(projectDir) {
89479
89476
  const registry2 = new ExportTargetRegistry();
@@ -89482,7 +89479,7 @@ async function createTargetRegistry(projectDir) {
89482
89479
  const packages = await listInstalledPackages2(projectDir);
89483
89480
  for (const pkg of packages) {
89484
89481
  for (const def of pkg.manifest.exportTargets ?? []) {
89485
- const filePath = path28.join(pkg.path, def.file);
89482
+ const filePath = path29.join(pkg.path, def.file);
89486
89483
  const mod = await import(pathToFileURL3(filePath).href);
89487
89484
  const TargetClass = def.exportName ? mod[def.exportName] : mod.default;
89488
89485
  registry2.register(def.name, () => new TargetClass());
@@ -89508,7 +89505,7 @@ var init_deployment = __esm({
89508
89505
  });
89509
89506
 
89510
89507
  // src/mcp/tools-export.ts
89511
- import * as path29 from "path";
89508
+ import * as path30 from "path";
89512
89509
  import * as fs25 from "fs";
89513
89510
  function registerExportTools(mcp) {
89514
89511
  mcp.tool(
@@ -89527,8 +89524,8 @@ function registerExportTools(mcp) {
89527
89524
  },
89528
89525
  async (args) => {
89529
89526
  try {
89530
- const filePath = path29.resolve(args.filePath);
89531
- const outputDir = path29.resolve(args.outputDir);
89527
+ const filePath = path30.resolve(args.filePath);
89528
+ const outputDir = path30.resolve(args.outputDir);
89532
89529
  const preview = args.preview ?? false;
89533
89530
  const includeDocs = args.includeDocs ?? true;
89534
89531
  try {
@@ -89547,7 +89544,7 @@ function registerExportTools(mcp) {
89547
89544
  }
89548
89545
  let parseResult;
89549
89546
  try {
89550
- parseResult = await parseWorkflow(filePath, { nodeTypesOnly: false, projectDir: path29.dirname(filePath) });
89547
+ parseResult = await parseWorkflow(filePath, { nodeTypesOnly: false, projectDir: path30.dirname(filePath) });
89551
89548
  } catch (err) {
89552
89549
  return makeErrorResult(
89553
89550
  "PARSE_ERROR",
@@ -89556,7 +89553,7 @@ function registerExportTools(mcp) {
89556
89553
  }
89557
89554
  if (parseResult.errors.length > 0) {
89558
89555
  try {
89559
- const ntResult = await parseWorkflow(filePath, { nodeTypesOnly: true, projectDir: path29.dirname(filePath) });
89556
+ const ntResult = await parseWorkflow(filePath, { nodeTypesOnly: true, projectDir: path30.dirname(filePath) });
89560
89557
  if (ntResult.errors.length === 0) {
89561
89558
  parseResult = ntResult;
89562
89559
  }
@@ -89570,7 +89567,7 @@ function registerExportTools(mcp) {
89570
89567
  }
89571
89568
  }
89572
89569
  if (!exportTarget.generateBundle) {
89573
- const serviceName2 = args.serviceName || path29.basename(filePath, ".ts").replace(/[^a-zA-Z0-9-]/g, "-");
89570
+ const serviceName2 = args.serviceName || path30.basename(filePath, ".ts").replace(/[^a-zA-Z0-9-]/g, "-");
89574
89571
  const artifacts2 = await exportTarget.generate({
89575
89572
  sourceFile: filePath,
89576
89573
  workflowName: args.workflows?.[0] || serviceName2,
@@ -89581,8 +89578,8 @@ function registerExportTools(mcp) {
89581
89578
  if (!preview) {
89582
89579
  await fs25.promises.mkdir(outputDir, { recursive: true });
89583
89580
  for (const file of artifacts2.files) {
89584
- const fullPath = path29.join(outputDir, file.relativePath);
89585
- await fs25.promises.mkdir(path29.dirname(fullPath), { recursive: true });
89581
+ const fullPath = path30.join(outputDir, file.relativePath);
89582
+ await fs25.promises.mkdir(path30.dirname(fullPath), { recursive: true });
89586
89583
  await fs25.promises.writeFile(fullPath, file.content, "utf-8");
89587
89584
  }
89588
89585
  }
@@ -89610,7 +89607,7 @@ function registerExportTools(mcp) {
89610
89607
  const uniqueNodeTypes = [
89611
89608
  ...new Map(allNodeTypes.map((nt) => [nt.name, nt])).values()
89612
89609
  ];
89613
- const serviceName = args.serviceName || path29.basename(filePath, ".ts").replace(/[^a-zA-Z0-9-]/g, "-");
89610
+ const serviceName = args.serviceName || path30.basename(filePath, ".ts").replace(/[^a-zA-Z0-9-]/g, "-");
89614
89611
  const bundleWorkflows = allWorkflows.filter((w) => args.workflows ? args.workflows.includes(w.name) : true).map((w) => ({
89615
89612
  name: w.name,
89616
89613
  functionName: w.functionName,
@@ -89661,8 +89658,8 @@ function registerExportTools(mcp) {
89661
89658
  if (!preview) {
89662
89659
  await fs25.promises.mkdir(outputDir, { recursive: true });
89663
89660
  for (const file of artifacts.files) {
89664
- const fullPath = path29.join(outputDir, file.relativePath);
89665
- await fs25.promises.mkdir(path29.dirname(fullPath), { recursive: true });
89661
+ const fullPath = path30.join(outputDir, file.relativePath);
89662
+ await fs25.promises.mkdir(path30.dirname(fullPath), { recursive: true });
89666
89663
  await fs25.promises.writeFile(fullPath, file.content, "utf-8");
89667
89664
  }
89668
89665
  }
@@ -89712,7 +89709,7 @@ var init_tools_export = __esm({
89712
89709
 
89713
89710
  // src/marketplace/manifest.ts
89714
89711
  import * as fs26 from "fs";
89715
- import * as path30 from "path";
89712
+ import * as path31 from "path";
89716
89713
  function toManifestPort(port) {
89717
89714
  return {
89718
89715
  dataType: port.dataType,
@@ -89783,7 +89780,7 @@ function patternToManifest(pat, relativeFile) {
89783
89780
  }
89784
89781
  async function generateManifest(options) {
89785
89782
  const { directory, srcDir = "src", distDir = "dist" } = options;
89786
- const pkgPath = path30.join(directory, "package.json");
89783
+ const pkgPath = path31.join(directory, "package.json");
89787
89784
  if (!fs26.existsSync(pkgPath)) {
89788
89785
  return {
89789
89786
  manifest: emptyManifest("unknown", "0.0.0"),
@@ -89792,8 +89789,8 @@ async function generateManifest(options) {
89792
89789
  };
89793
89790
  }
89794
89791
  const pkg = JSON.parse(fs26.readFileSync(pkgPath, "utf-8"));
89795
- const srcRoot = path30.join(directory, srcDir);
89796
- const pattern = path30.join(srcRoot, "**/*.ts").replace(/\\/g, "/");
89792
+ const srcRoot = path31.join(directory, srcDir);
89793
+ const pattern = path31.join(srcRoot, "**/*.ts").replace(/\\/g, "/");
89797
89794
  const files = await glob(pattern, { absolute: true });
89798
89795
  const tsFiles = files.filter((f) => !f.endsWith(".d.ts") && !f.includes("node_modules"));
89799
89796
  const parser3 = new AnnotationParser();
@@ -89806,8 +89803,8 @@ async function generateManifest(options) {
89806
89803
  try {
89807
89804
  const result = parser3.parse(file);
89808
89805
  parsedFiles.push(file);
89809
- const relFromSrc = path30.relative(srcRoot, file);
89810
- const distRelative = path30.join(distDir, relFromSrc.replace(/\.ts$/, ".js"));
89806
+ const relFromSrc = path31.relative(srcRoot, file);
89807
+ const distRelative = path31.join(distDir, relFromSrc.replace(/\.ts$/, ".js"));
89811
89808
  for (const nt of result.nodeTypes) {
89812
89809
  allNodeTypes.push(nodeTypeToManifest(nt, distRelative));
89813
89810
  }
@@ -89853,12 +89850,12 @@ async function generateManifest(options) {
89853
89850
  return { manifest, parsedFiles, errors: errors2 };
89854
89851
  }
89855
89852
  function writeManifest(directory, manifest) {
89856
- const outPath = path30.join(directory, "flowweaver.manifest.json");
89853
+ const outPath = path31.join(directory, "flowweaver.manifest.json");
89857
89854
  fs26.writeFileSync(outPath, JSON.stringify(manifest, null, 2) + "\n", "utf-8");
89858
89855
  return outPath;
89859
89856
  }
89860
89857
  function readManifest(directory) {
89861
- const manifestPath = path30.join(directory, "flowweaver.manifest.json");
89858
+ const manifestPath = path31.join(directory, "flowweaver.manifest.json");
89862
89859
  if (!fs26.existsSync(manifestPath)) return null;
89863
89860
  return JSON.parse(fs26.readFileSync(manifestPath, "utf-8"));
89864
89861
  }
@@ -89882,7 +89879,7 @@ var init_manifest = __esm({
89882
89879
 
89883
89880
  // src/marketplace/validator.ts
89884
89881
  import * as fs27 from "fs";
89885
- import * as path31 from "path";
89882
+ import * as path32 from "path";
89886
89883
  function issue2(code, severity, message) {
89887
89884
  return { code, severity, message };
89888
89885
  }
@@ -89927,7 +89924,7 @@ function validatePackageJson(pkg, directory) {
89927
89924
  if (pkg.private === true) {
89928
89925
  issues.push(issue2("PKG-004", "error", 'Package must not be "private: true"'));
89929
89926
  }
89930
- if (!fs27.existsSync(path31.join(directory, "README.md"))) {
89927
+ if (!fs27.existsSync(path32.join(directory, "README.md"))) {
89931
89928
  issues.push(issue2("PKG-007", "warning", "README.md should exist"));
89932
89929
  }
89933
89930
  return issues;
@@ -90002,7 +89999,7 @@ function validateManifestContents(manifest) {
90002
89999
  async function validateWorkflows(manifest, directory) {
90003
90000
  const issues = [];
90004
90001
  for (const wf of manifest.workflows) {
90005
- const srcFile = path31.join(
90002
+ const srcFile = path32.join(
90006
90003
  directory,
90007
90004
  wf.file.replace(/^dist\//, "src/").replace(/\.js$/, ".ts")
90008
90005
  );
@@ -90026,7 +90023,7 @@ async function validateWorkflows(manifest, directory) {
90026
90023
  return issues;
90027
90024
  }
90028
90025
  async function validatePackage(directory, manifest) {
90029
- const pkgPath = path31.join(directory, "package.json");
90026
+ const pkgPath = path32.join(directory, "package.json");
90030
90027
  if (!fs27.existsSync(pkgPath)) {
90031
90028
  return {
90032
90029
  valid: false,
@@ -90201,7 +90198,7 @@ var init_tools_marketplace = __esm({
90201
90198
 
90202
90199
  // src/mcp/tools-diagram.ts
90203
90200
  import * as fs28 from "fs";
90204
- import * as path32 from "path";
90201
+ import * as path33 from "path";
90205
90202
  function registerDiagramTools(mcp) {
90206
90203
  mcp.tool(
90207
90204
  "fw_diagram",
@@ -90237,7 +90234,7 @@ function registerDiagramTools(mcp) {
90237
90234
  result = sourceToSVG(args.source, diagramOptions);
90238
90235
  }
90239
90236
  } else {
90240
- const resolvedPath = path32.resolve(args.filePath);
90237
+ const resolvedPath = path33.resolve(args.filePath);
90241
90238
  if (!fs28.existsSync(resolvedPath)) {
90242
90239
  return makeErrorResult("FILE_NOT_FOUND", `File not found: ${resolvedPath}`);
90243
90240
  }
@@ -90250,7 +90247,7 @@ function registerDiagramTools(mcp) {
90250
90247
  }
90251
90248
  }
90252
90249
  if (args.outputPath) {
90253
- const outputResolved = path32.resolve(args.outputPath);
90250
+ const outputResolved = path33.resolve(args.outputPath);
90254
90251
  fs28.writeFileSync(outputResolved, result, "utf-8");
90255
90252
  return makeToolResult({ written: outputResolved, size: result.length });
90256
90253
  }
@@ -90355,7 +90352,7 @@ var init_tools_docs = __esm({
90355
90352
 
90356
90353
  // src/mcp/tools-model.ts
90357
90354
  import * as fs29 from "fs";
90358
- import * as path33 from "path";
90355
+ import * as path34 from "path";
90359
90356
  function findDeclareFunction(source, functionName) {
90360
90357
  const lines = source.split("\n");
90361
90358
  const startPattern = new RegExp(`^(\\s*)declare\\s+function\\s+${escapeRegex2(functionName)}\\s*\\(`);
@@ -90386,7 +90383,7 @@ function registerModelTools(mcp) {
90386
90383
  },
90387
90384
  async (args) => {
90388
90385
  try {
90389
- const outputPath = path33.resolve(args.filePath);
90386
+ const outputPath = path34.resolve(args.filePath);
90390
90387
  const lines = [];
90391
90388
  for (const step of args.steps) {
90392
90389
  lines.push("/** @flowWeaver node */");
@@ -90414,7 +90411,7 @@ function registerModelTools(mcp) {
90414
90411
  lines.push(...jsdocLines);
90415
90412
  lines.push("");
90416
90413
  const content = lines.join("\n");
90417
- const dir = path33.dirname(outputPath);
90414
+ const dir = path34.dirname(outputPath);
90418
90415
  if (!fs29.existsSync(dir)) {
90419
90416
  fs29.mkdirSync(dir, { recursive: true });
90420
90417
  }
@@ -90442,7 +90439,7 @@ function registerModelTools(mcp) {
90442
90439
  },
90443
90440
  async (args) => {
90444
90441
  try {
90445
- const filePath = path33.resolve(args.filePath);
90442
+ const filePath = path34.resolve(args.filePath);
90446
90443
  const parseResult = await parseWorkflow(filePath, { workflowName: args.workflowName });
90447
90444
  if (parseResult.errors.length > 0) {
90448
90445
  return makeErrorResult("PARSE_ERROR", `Parse errors:
@@ -90511,7 +90508,7 @@ ${parseResult.errors.join("\n")}`);
90511
90508
  },
90512
90509
  async (args) => {
90513
90510
  try {
90514
- const filePath = path33.resolve(args.filePath);
90511
+ const filePath = path34.resolve(args.filePath);
90515
90512
  if (!fs29.existsSync(filePath)) {
90516
90513
  return makeErrorResult("FILE_NOT_FOUND", `File not found: ${args.filePath}`);
90517
90514
  }
@@ -90838,7 +90835,7 @@ var init_debug_controller = __esm({
90838
90835
 
90839
90836
  // src/runtime/checkpoint.ts
90840
90837
  import * as fs30 from "fs";
90841
- import * as path34 from "path";
90838
+ import * as path35 from "path";
90842
90839
  import * as crypto from "crypto";
90843
90840
  function isUnserializableMarker(value) {
90844
90841
  return typeof value === "object" && value !== null && value.__fw_unserializable__ === true;
@@ -90894,7 +90891,7 @@ function loadCheckpoint(checkpointPath, workflowFilePath) {
90894
90891
  }
90895
90892
  let stale = false;
90896
90893
  if (workflowFilePath) {
90897
- const currentHash = hashFile(path34.resolve(workflowFilePath));
90894
+ const currentHash = hashFile(path35.resolve(workflowFilePath));
90898
90895
  stale = currentHash !== data.workflowHash;
90899
90896
  }
90900
90897
  const unsafeSet = new Set(data.unsafeNodes);
@@ -90920,12 +90917,12 @@ function loadCheckpoint(checkpointPath, workflowFilePath) {
90920
90917
  return { data, stale, rerunNodes, skipNodes };
90921
90918
  }
90922
90919
  function findLatestCheckpoint(workflowFilePath, workflowName) {
90923
- const dir = path34.join(path34.dirname(path34.resolve(workflowFilePath)), ".fw-checkpoints");
90920
+ const dir = path35.join(path35.dirname(path35.resolve(workflowFilePath)), ".fw-checkpoints");
90924
90921
  if (!fs30.existsSync(dir)) return null;
90925
90922
  const files = fs30.readdirSync(dir).filter((f) => f.endsWith(".json")).filter((f) => !workflowName || f.startsWith(`${workflowName}-`));
90926
90923
  if (files.length === 0) return null;
90927
- const sorted = files.map((f) => ({ name: f, mtime: fs30.statSync(path34.join(dir, f)).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
90928
- return path34.join(dir, sorted[0].name);
90924
+ const sorted = files.map((f) => ({ name: f, mtime: fs30.statSync(path35.join(dir, f)).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
90925
+ return path35.join(dir, sorted[0].name);
90929
90926
  }
90930
90927
  var CheckpointWriter;
90931
90928
  var init_checkpoint = __esm({
@@ -90941,12 +90938,12 @@ var init_checkpoint = __esm({
90941
90938
  checkpointPath;
90942
90939
  writeLock = Promise.resolve();
90943
90940
  constructor(workflowFilePath, workflowName, runId, params = {}) {
90944
- this.filePath = path34.resolve(workflowFilePath);
90941
+ this.filePath = path35.resolve(workflowFilePath);
90945
90942
  this.workflowName = workflowName;
90946
90943
  this.runId = runId;
90947
90944
  this.params = params;
90948
- this.dir = path34.join(path34.dirname(this.filePath), ".fw-checkpoints");
90949
- this.checkpointPath = path34.join(this.dir, `${workflowName}-${runId}.json`);
90945
+ this.dir = path35.join(path35.dirname(this.filePath), ".fw-checkpoints");
90946
+ this.checkpointPath = path35.join(this.dir, `${workflowName}-${runId}.json`);
90950
90947
  this.workflowHash = hashFile(this.filePath);
90951
90948
  }
90952
90949
  /**
@@ -91095,10 +91092,10 @@ var init_debug_session = __esm({
91095
91092
  });
91096
91093
 
91097
91094
  // src/mcp/tools-debug.ts
91098
- import * as path35 from "path";
91095
+ import * as path36 from "path";
91099
91096
  import * as fs31 from "fs";
91100
91097
  async function getExecutionOrder(filePath, workflowName) {
91101
- const source = fs31.readFileSync(path35.resolve(filePath), "utf8");
91098
+ const source = fs31.readFileSync(path36.resolve(filePath), "utf8");
91102
91099
  const parsed = await parseWorkflow(source, { workflowName });
91103
91100
  if (parsed.errors.length > 0) {
91104
91101
  throw new Error(`Failed to parse workflow: ${parsed.errors.join(", ")}`);
@@ -91685,7 +91682,7 @@ Only reveal TypeScript when the user explicitly asks: "show me the code", "let m
91685
91682
  });
91686
91683
 
91687
91684
  // src/mcp/pack-tools.ts
91688
- import * as path36 from "path";
91685
+ import * as path37 from "path";
91689
91686
  function compareVersions(a, b) {
91690
91687
  const pa = a.split(".").map(Number);
91691
91688
  const pb = b.split(".").map(Number);
@@ -91723,7 +91720,7 @@ async function registerPackMcpTools(mcp) {
91723
91720
  const manifest = pkg.manifest;
91724
91721
  if (!manifest.mcpEntrypoint || !manifest.mcpTools?.length) continue;
91725
91722
  checkPackEngineVersion(pkg);
91726
- const entrypointPath = path36.join(pkg.path, manifest.mcpEntrypoint);
91723
+ const entrypointPath = path37.join(pkg.path, manifest.mcpEntrypoint);
91727
91724
  try {
91728
91725
  const mod = await import(entrypointPath);
91729
91726
  if (typeof mod.registerMcpTools === "function") {
@@ -91812,10 +91809,10 @@ __export(create_exports, {
91812
91809
  createWorkflowCommand: () => createWorkflowCommand
91813
91810
  });
91814
91811
  import * as fs32 from "fs";
91815
- import * as path37 from "path";
91812
+ import * as path38 from "path";
91816
91813
  function insertIntoFile(filePath, content, line) {
91817
91814
  if (!fs32.existsSync(filePath)) {
91818
- const dir = path37.dirname(filePath);
91815
+ const dir = path38.dirname(filePath);
91819
91816
  if (!fs32.existsSync(dir)) {
91820
91817
  fs32.mkdirSync(dir, { recursive: true });
91821
91818
  }
@@ -91843,12 +91840,10 @@ async function createWorkflowCommand(template, file, options = {}) {
91843
91840
  } = options;
91844
91841
  const templateDef = getWorkflowTemplate(template);
91845
91842
  if (!templateDef) {
91846
- logger.error(`Unknown workflow template: ${template}`);
91847
- logger.info("Run 'fw templates' to see available templates");
91848
- process.exit(1);
91843
+ throw new Error(`Unknown workflow template: ${template}. Run 'fw templates' to see available templates`);
91849
91844
  }
91850
- const filePath = path37.resolve(file);
91851
- const baseName = path37.basename(filePath, path37.extname(filePath));
91845
+ const filePath = path38.resolve(file);
91846
+ const baseName = path38.basename(filePath, path38.extname(filePath));
91852
91847
  const workflowName = options.name || toCamelCase(baseName);
91853
91848
  const config2 = {};
91854
91849
  if (provider) config2.provider = provider;
@@ -91860,8 +91855,7 @@ async function createWorkflowCommand(template, file, options = {}) {
91860
91855
  try {
91861
91856
  Object.assign(config2, JSON.parse(configJson));
91862
91857
  } catch {
91863
- logger.error("Invalid --config JSON");
91864
- process.exit(1);
91858
+ throw new Error("Invalid --config JSON");
91865
91859
  }
91866
91860
  }
91867
91861
  const code = templateDef.generate({
@@ -91881,27 +91875,23 @@ async function createWorkflowCommand(template, file, options = {}) {
91881
91875
  }
91882
91876
  logger.info(` Workflow function: ${workflowName}`);
91883
91877
  } catch (error2) {
91884
- logger.error(`Failed to create workflow: ${getErrorMessage(error2)}`);
91885
- process.exit(1);
91878
+ throw new Error(`Failed to create workflow: ${getErrorMessage(error2)}`);
91886
91879
  }
91887
91880
  }
91888
91881
  async function createNodeCommand(name, file, options = {}) {
91889
91882
  const { line, template = "processor", preview = false, strategy, config: configJson } = options;
91890
91883
  const templateDef = getNodeTemplate(template);
91891
91884
  if (!templateDef) {
91892
- logger.error(`Unknown node template: ${template}`);
91893
- logger.info("Run 'fw templates' to see available templates");
91894
- process.exit(1);
91885
+ throw new Error(`Unknown node template: ${template}. Run 'fw templates' to see available templates`);
91895
91886
  }
91896
- const filePath = path37.resolve(file);
91887
+ const filePath = path38.resolve(file);
91897
91888
  const config2 = {};
91898
91889
  if (strategy) config2.strategy = strategy;
91899
91890
  if (configJson) {
91900
91891
  try {
91901
91892
  Object.assign(config2, JSON.parse(configJson));
91902
91893
  } catch {
91903
- logger.error("Invalid --config JSON");
91904
- process.exit(1);
91894
+ throw new Error("Invalid --config JSON");
91905
91895
  }
91906
91896
  }
91907
91897
  const nodeName = toCamelCase(name);
@@ -91919,8 +91909,7 @@ async function createNodeCommand(name, file, options = {}) {
91919
91909
  }
91920
91910
  logger.info(` Node function: ${nodeName}`);
91921
91911
  } catch (error2) {
91922
- logger.error(`Failed to create node: ${getErrorMessage(error2)}`);
91923
- process.exit(1);
91912
+ throw new Error(`Failed to create node: ${getErrorMessage(error2)}`);
91924
91913
  }
91925
91914
  }
91926
91915
  var init_create = __esm({
@@ -91944,13 +91933,13 @@ __export(modify_exports, {
91944
91933
  modifySetPositionCommand: () => modifySetPositionCommand
91945
91934
  });
91946
91935
  import * as fs33 from "fs";
91947
- import * as path38 from "path";
91936
+ import * as path39 from "path";
91948
91937
  async function readParseModifyWrite(file, operation, params) {
91949
91938
  const validation = validateModifyParams(operation, params);
91950
91939
  if (!validation.success) {
91951
91940
  throw new Error(validation.error);
91952
91941
  }
91953
- const filePath = path38.resolve(file);
91942
+ const filePath = path39.resolve(file);
91954
91943
  const source = fs33.readFileSync(filePath, "utf-8");
91955
91944
  const parseResult = await parseWorkflow(filePath);
91956
91945
  if (parseResult.errors.length > 0) {
@@ -91959,7 +91948,7 @@ ${parseResult.errors.join("\n")}`);
91959
91948
  }
91960
91949
  const { ast: modifiedAST, warnings } = applyModifyOperation(parseResult.ast, operation, params);
91961
91950
  const result = generateInPlace(source, modifiedAST);
91962
- fs33.writeFileSync(filePath, result.code, "utf-8");
91951
+ safeWriteFile(filePath, result.code);
91963
91952
  for (const w of warnings) {
91964
91953
  logger.warn(w);
91965
91954
  }
@@ -92003,6 +91992,7 @@ var init_modify = __esm({
92003
91992
  init_generate_in_place();
92004
91993
  init_modify_operation();
92005
91994
  init_logger();
91995
+ init_safe_write();
92006
91996
  }
92007
91997
  });
92008
91998
 
@@ -92079,7 +92069,6 @@ var grammar_exports = {};
92079
92069
  __export(grammar_exports, {
92080
92070
  grammarCommand: () => grammarCommand
92081
92071
  });
92082
- import * as fs34 from "fs";
92083
92072
  async function grammarCommand(options = {}) {
92084
92073
  const defaultFormat = options.output ? "html" : process.stdout.isTTY ? "ebnf" : "html";
92085
92074
  const { format = defaultFormat, output } = options;
@@ -92099,14 +92088,13 @@ async function grammarCommand(options = {}) {
92099
92088
  content = generateGrammarDiagrams();
92100
92089
  }
92101
92090
  if (output) {
92102
- fs34.writeFileSync(output, content, "utf-8");
92091
+ safeWriteFile(output, content);
92103
92092
  logger.success(`Grammar written to ${output}`);
92104
92093
  } else {
92105
92094
  process.stdout.write(content);
92106
92095
  }
92107
92096
  } catch (error2) {
92108
- logger.error(`Grammar generation failed: ${getErrorMessage(error2)}`);
92109
- process.exit(1);
92097
+ throw new Error(`Grammar generation failed: ${getErrorMessage(error2)}`);
92110
92098
  }
92111
92099
  }
92112
92100
  var init_grammar = __esm({
@@ -92115,6 +92103,7 @@ var init_grammar = __esm({
92115
92103
  init_grammar_diagrams();
92116
92104
  init_logger();
92117
92105
  init_error_utils();
92106
+ init_safe_write();
92118
92107
  }
92119
92108
  });
92120
92109
 
@@ -92125,13 +92114,13 @@ __export(pattern_exports, {
92125
92114
  patternExtractCommand: () => patternExtractCommand,
92126
92115
  patternListCommand: () => patternListCommand
92127
92116
  });
92128
- import * as fs35 from "fs";
92129
- import * as path39 from "path";
92117
+ import * as fs34 from "fs";
92118
+ import * as path40 from "path";
92130
92119
  async function patternListCommand(inputPath, options) {
92131
- if (!fs35.existsSync(inputPath)) {
92120
+ if (!fs34.existsSync(inputPath)) {
92132
92121
  throw new Error(`Path not found: ${inputPath}`);
92133
92122
  }
92134
- const stat = fs35.statSync(inputPath);
92123
+ const stat = fs34.statSync(inputPath);
92135
92124
  let files;
92136
92125
  if (stat.isDirectory()) {
92137
92126
  files = await glob("**/*.ts", { cwd: inputPath, absolute: true });
@@ -92166,7 +92155,7 @@ async function patternListCommand(inputPath, options) {
92166
92155
  if (description) {
92167
92156
  logger.info(description);
92168
92157
  }
92169
- logger.info(`File: ${path39.relative(process.cwd(), file)}`);
92158
+ logger.info(`File: ${path40.relative(process.cwd(), file)}`);
92170
92159
  if (inputPorts.length > 0) {
92171
92160
  logger.info("Input ports:");
92172
92161
  for (const port of inputPorts) {
@@ -92200,7 +92189,7 @@ async function patternApplyCommand(patternFile, targetFile, options) {
92200
92189
  } else {
92201
92190
  pattern = patternResult.patterns[0];
92202
92191
  }
92203
- const targetContent = fs35.readFileSync(targetFile, "utf8");
92192
+ const targetContent = fs34.readFileSync(targetFile, "utf8");
92204
92193
  const targetResult = parser2.parse(targetFile);
92205
92194
  const existingNodeTypes = new Set(targetResult.nodeTypes.map((nt) => nt.name));
92206
92195
  const result = applyPattern({
@@ -92232,7 +92221,7 @@ async function patternApplyCommand(patternFile, targetFile, options) {
92232
92221
  }
92233
92222
  return;
92234
92223
  }
92235
- fs35.writeFileSync(targetFile, result.modifiedContent);
92224
+ safeWriteFile(targetFile, result.modifiedContent);
92236
92225
  logger.success(`Applied pattern "${pattern.name}" to ${targetFile}`);
92237
92226
  if (result.nodeTypesAdded.length > 0) {
92238
92227
  logger.info(`Added node types: ${result.nodeTypesAdded.join(", ")}`);
@@ -92270,7 +92259,7 @@ async function patternExtractCommand(sourceFile, options) {
92270
92259
  console.log(result.patternCode);
92271
92260
  return;
92272
92261
  }
92273
- fs35.writeFileSync(options.output, result.patternCode);
92262
+ safeWriteFile(options.output, result.patternCode);
92274
92263
  logger.success(`Extracted pattern "${result.patternName}" to ${options.output}`);
92275
92264
  logger.info(`Included nodes: ${result.nodes.join(", ")}`);
92276
92265
  logger.info(`Input ports: ${result.inputPorts.join(", ") || "none"}`);
@@ -92283,6 +92272,7 @@ var init_pattern2 = __esm({
92283
92272
  init_esm5();
92284
92273
  init_parser2();
92285
92274
  init_logger();
92275
+ init_safe_write();
92286
92276
  init_patterns();
92287
92277
  parser2 = new AnnotationParser();
92288
92278
  }
@@ -92294,11 +92284,11 @@ __export(run_exports, {
92294
92284
  runCommand: () => runCommand2,
92295
92285
  validateMockConfig: () => validateMockConfig
92296
92286
  });
92297
- import * as path40 from "path";
92298
- import * as fs36 from "fs";
92287
+ import * as path41 from "path";
92288
+ import * as fs35 from "fs";
92299
92289
  import * as readline8 from "readline";
92300
92290
  function displayPath2(filePath) {
92301
- const rel = path40.relative(process.cwd(), filePath);
92291
+ const rel = path41.relative(process.cwd(), filePath);
92302
92292
  if (rel && !rel.startsWith("..") && rel.length < filePath.length) {
92303
92293
  return rel;
92304
92294
  }
@@ -92317,8 +92307,8 @@ async function runCommand2(input, options) {
92317
92307
  await runCommandInner(input, options);
92318
92308
  }
92319
92309
  async function runCommandInner(input, options) {
92320
- const filePath = path40.resolve(input);
92321
- if (!fs36.existsSync(filePath)) {
92310
+ const filePath = path41.resolve(input);
92311
+ if (!fs35.existsSync(filePath)) {
92322
92312
  throw new Error(`File not found: ${displayPath2(filePath)}`);
92323
92313
  }
92324
92314
  let params = {};
@@ -92329,12 +92319,12 @@ async function runCommandInner(input, options) {
92329
92319
  throw new Error(`Invalid JSON in --params: ${options.params}`);
92330
92320
  }
92331
92321
  } else if (options.paramsFile) {
92332
- const paramsFilePath = path40.resolve(options.paramsFile);
92333
- if (!fs36.existsSync(paramsFilePath)) {
92322
+ const paramsFilePath = path41.resolve(options.paramsFile);
92323
+ if (!fs35.existsSync(paramsFilePath)) {
92334
92324
  throw new Error(`Params file not found: ${paramsFilePath}`);
92335
92325
  }
92336
92326
  try {
92337
- const content = fs36.readFileSync(paramsFilePath, "utf8");
92327
+ const content = fs35.readFileSync(paramsFilePath, "utf8");
92338
92328
  params = JSON.parse(content);
92339
92329
  } catch {
92340
92330
  throw new Error(`Failed to parse params file: ${options.paramsFile}`);
@@ -92348,12 +92338,12 @@ async function runCommandInner(input, options) {
92348
92338
  throw new Error(`Invalid JSON in --mocks: ${options.mocks}`);
92349
92339
  }
92350
92340
  } else if (options.mocksFile) {
92351
- const mocksFilePath = path40.resolve(options.mocksFile);
92352
- if (!fs36.existsSync(mocksFilePath)) {
92341
+ const mocksFilePath = path41.resolve(options.mocksFile);
92342
+ if (!fs35.existsSync(mocksFilePath)) {
92353
92343
  throw new Error(`Mocks file not found: ${mocksFilePath}`);
92354
92344
  }
92355
92345
  try {
92356
- const content = fs36.readFileSync(mocksFilePath, "utf8");
92346
+ const content = fs35.readFileSync(mocksFilePath, "utf8");
92357
92347
  mocks = JSON.parse(content);
92358
92348
  } catch {
92359
92349
  throw new Error(`Failed to parse mocks file: ${options.mocksFile}`);
@@ -92423,7 +92413,7 @@ async function runCommandInner(input, options) {
92423
92413
  if (useDebug) {
92424
92414
  let executionOrder = resumeExecutionOrder;
92425
92415
  if (!executionOrder) {
92426
- const source = fs36.readFileSync(filePath, "utf8");
92416
+ const source = fs35.readFileSync(filePath, "utf8");
92427
92417
  const parsed = await parseWorkflow(source, { workflowName: options.workflow });
92428
92418
  if (parsed.errors.length === 0) {
92429
92419
  executionOrder = getTopologicalOrder(parsed.ast);
@@ -92945,7 +92935,7 @@ var init_run = __esm({
92945
92935
  });
92946
92936
 
92947
92937
  // src/server/workflow-registry.ts
92948
- import * as fs37 from "fs";
92938
+ import * as fs36 from "fs";
92949
92939
  var WorkflowRegistry;
92950
92940
  var init_workflow_registry = __esm({
92951
92941
  "src/server/workflow-registry.ts"() {
@@ -92986,7 +92976,7 @@ var init_workflow_registry = __esm({
92986
92976
  this.endpoints.clear();
92987
92977
  for (const file of files) {
92988
92978
  try {
92989
- const content = fs37.readFileSync(file, "utf8");
92979
+ const content = fs36.readFileSync(file, "utf8");
92990
92980
  if (!content.includes("@flowWeaver")) {
92991
92981
  continue;
92992
92982
  }
@@ -93391,14 +93381,14 @@ var serve_exports = {};
93391
93381
  __export(serve_exports, {
93392
93382
  serveCommand: () => serveCommand
93393
93383
  });
93394
- import * as path41 from "path";
93395
- import * as fs38 from "fs";
93384
+ import * as path42 from "path";
93385
+ import * as fs37 from "fs";
93396
93386
  async function serveCommand(dir, options) {
93397
- const workflowDir = path41.resolve(dir || ".");
93398
- if (!fs38.existsSync(workflowDir)) {
93387
+ const workflowDir = path42.resolve(dir || ".");
93388
+ if (!fs37.existsSync(workflowDir)) {
93399
93389
  throw new Error(`Directory not found: ${workflowDir}`);
93400
93390
  }
93401
- if (!fs38.statSync(workflowDir).isDirectory()) {
93391
+ if (!fs37.statSync(workflowDir).isDirectory()) {
93402
93392
  throw new Error(`Not a directory: ${workflowDir}`);
93403
93393
  }
93404
93394
  const port = options.port ?? 3e3;
@@ -93448,8 +93438,8 @@ var init_serve = __esm({
93448
93438
  });
93449
93439
 
93450
93440
  // src/export/index.ts
93451
- import * as path42 from "path";
93452
- import * as fs39 from "fs";
93441
+ import * as path43 from "path";
93442
+ import * as fs38 from "fs";
93453
93443
  import * as os2 from "os";
93454
93444
  async function exportWorkflow(options) {
93455
93445
  const { createTargetRegistry: createTargetRegistry2 } = await Promise.resolve().then(() => (init_deployment(), deployment_exports));
@@ -93461,8 +93451,8 @@ async function exportWorkflow(options) {
93461
93451
  available.length === 0 ? `No export targets installed. Install a target pack (e.g. npm install flow-weaver-pack-${options.target})` : `Unknown target "${options.target}". Installed: ${available.join(", ")}`
93462
93452
  );
93463
93453
  }
93464
- const inputPath = path42.resolve(options.input);
93465
- const outputDir = path42.resolve(options.output);
93454
+ const inputPath = path43.resolve(options.input);
93455
+ const outputDir = path43.resolve(options.output);
93466
93456
  const isDryRun = options.dryRun ?? false;
93467
93457
  if (options.multi) {
93468
93458
  return exportMultiWorkflowViaRegistry(
@@ -93482,11 +93472,11 @@ async function exportWorkflow(options) {
93482
93472
  );
93483
93473
  }
93484
93474
  async function exportSingleWorkflowViaRegistry(target, inputPath, outputDir, isDryRun, options) {
93485
- if (!fs39.existsSync(inputPath)) {
93475
+ if (!fs38.existsSync(inputPath)) {
93486
93476
  throw new Error(`Input file not found: ${inputPath}`);
93487
93477
  }
93488
93478
  const parser3 = new AnnotationParser();
93489
- const projectDir = path42.dirname(inputPath);
93479
+ const projectDir = path43.dirname(inputPath);
93490
93480
  await parser3.loadPackHandlers(projectDir);
93491
93481
  const parseResult = parser3.parse(inputPath);
93492
93482
  if (parseResult.workflows.length === 0) {
@@ -93516,8 +93506,8 @@ async function exportSingleWorkflowViaRegistry(target, inputPath, outputDir, isD
93516
93506
  );
93517
93507
  let compiledContent;
93518
93508
  if (needsCompiledWorkflow) {
93519
- const workDir = isDryRun ? path42.join(os2.tmpdir(), `fw-export-dryrun-${Date.now()}`) : outputDir;
93520
- fs39.mkdirSync(workDir, { recursive: true });
93509
+ const workDir = isDryRun ? path43.join(os2.tmpdir(), `fw-export-dryrun-${Date.now()}`) : outputDir;
93510
+ fs38.mkdirSync(workDir, { recursive: true });
93521
93511
  try {
93522
93512
  const compiledPath = await compileToOutput(
93523
93513
  inputPath,
@@ -93525,29 +93515,29 @@ async function exportSingleWorkflowViaRegistry(target, inputPath, outputDir, isD
93525
93515
  workDir,
93526
93516
  options.production
93527
93517
  );
93528
- compiledContent = fs39.readFileSync(compiledPath, "utf8");
93518
+ compiledContent = fs38.readFileSync(compiledPath, "utf8");
93529
93519
  } finally {
93530
93520
  if (isDryRun) {
93531
93521
  try {
93532
- fs39.rmSync(workDir, { recursive: true, force: true });
93522
+ fs38.rmSync(workDir, { recursive: true, force: true });
93533
93523
  } catch {
93534
93524
  }
93535
93525
  }
93536
93526
  }
93537
93527
  }
93538
93528
  const files = artifacts.files.map((f) => ({
93539
- path: path42.join(outputDir, f.relativePath),
93529
+ path: path43.join(outputDir, f.relativePath),
93540
93530
  content: f.content
93541
93531
  }));
93542
93532
  if (compiledContent) {
93543
- const workflowOutputPath = path42.join(outputDir, "workflow.ts");
93533
+ const workflowOutputPath = path43.join(outputDir, "workflow.ts");
93544
93534
  files.push({ path: workflowOutputPath, content: compiledContent });
93545
93535
  }
93546
93536
  if (!isDryRun) {
93547
93537
  for (const file of files) {
93548
- const dirPath = path42.dirname(file.path);
93549
- fs39.mkdirSync(dirPath, { recursive: true });
93550
- fs39.writeFileSync(file.path, file.content, "utf-8");
93538
+ const dirPath = path43.dirname(file.path);
93539
+ fs38.mkdirSync(dirPath, { recursive: true });
93540
+ fs38.writeFileSync(file.path, file.content, "utf-8");
93551
93541
  }
93552
93542
  }
93553
93543
  return {
@@ -93559,11 +93549,11 @@ async function exportSingleWorkflowViaRegistry(target, inputPath, outputDir, isD
93559
93549
  };
93560
93550
  }
93561
93551
  async function exportMultiWorkflowViaRegistry(target, inputPath, outputDir, isDryRun, options) {
93562
- if (!fs39.existsSync(inputPath)) {
93552
+ if (!fs38.existsSync(inputPath)) {
93563
93553
  throw new Error(`Input file not found: ${inputPath}`);
93564
93554
  }
93565
93555
  const parser3 = new AnnotationParser();
93566
- const projectDir = path42.dirname(inputPath);
93556
+ const projectDir = path43.dirname(inputPath);
93567
93557
  await parser3.loadPackHandlers(projectDir);
93568
93558
  const parseResult = parser3.parse(inputPath);
93569
93559
  if (parseResult.workflows.length === 0) {
@@ -93579,7 +93569,7 @@ async function exportMultiWorkflowViaRegistry(target, inputPath, outputDir, isDr
93579
93569
  throw new Error(`None of the requested workflows found. Available: ${available}`);
93580
93570
  }
93581
93571
  }
93582
- const serviceName = path42.basename(options.input, path42.extname(options.input)) + "-service";
93572
+ const serviceName = path43.basename(options.input, path43.extname(options.input)) + "-service";
93583
93573
  const bundleWorkflows = selectedWorkflows.map((w) => ({
93584
93574
  name: w.name,
93585
93575
  functionName: w.functionName,
@@ -93604,15 +93594,15 @@ async function exportMultiWorkflowViaRegistry(target, inputPath, outputDir, isDr
93604
93594
  });
93605
93595
  const files = artifacts.files.map(
93606
93596
  (f) => ({
93607
- path: path42.join(outputDir, f.relativePath),
93597
+ path: path43.join(outputDir, f.relativePath),
93608
93598
  content: f.content
93609
93599
  })
93610
93600
  );
93611
93601
  if (!isDryRun) {
93612
93602
  for (const file of files) {
93613
- const dirPath = path42.dirname(file.path);
93614
- fs39.mkdirSync(dirPath, { recursive: true });
93615
- fs39.writeFileSync(file.path, file.content, "utf-8");
93603
+ const dirPath = path43.dirname(file.path);
93604
+ fs38.mkdirSync(dirPath, { recursive: true });
93605
+ fs38.writeFileSync(file.path, file.content, "utf-8");
93616
93606
  }
93617
93607
  }
93618
93608
  return {
@@ -93624,8 +93614,8 @@ async function exportMultiWorkflowViaRegistry(target, inputPath, outputDir, isDr
93624
93614
  };
93625
93615
  }
93626
93616
  async function compileToOutput(inputPath, functionName, outputDir, production) {
93627
- const outputPath = path42.join(outputDir, "workflow.ts");
93628
- fs39.copyFileSync(inputPath, outputPath);
93617
+ const outputPath = path43.join(outputDir, "workflow.ts");
93618
+ fs38.copyFileSync(inputPath, outputPath);
93629
93619
  await compileWorkflow(outputPath, {
93630
93620
  write: true,
93631
93621
  inPlace: true,
@@ -93684,7 +93674,7 @@ async function exportCommand(input, options) {
93684
93674
  input,
93685
93675
  output: options.output,
93686
93676
  workflow: options.workflow,
93687
- production: options.production ?? true,
93677
+ production: options.production ?? false,
93688
93678
  bundle: options.bundle,
93689
93679
  dryRun: isDryRun,
93690
93680
  multi: isMulti,
@@ -93774,14 +93764,14 @@ var openapi_exports = {};
93774
93764
  __export(openapi_exports, {
93775
93765
  openapiCommand: () => openapiCommand
93776
93766
  });
93777
- import * as path43 from "path";
93778
- import * as fs40 from "fs";
93767
+ import * as path44 from "path";
93768
+ import * as fs39 from "fs";
93779
93769
  async function openapiCommand(dir, options) {
93780
- const workflowDir = path43.resolve(dir);
93781
- if (!fs40.existsSync(workflowDir)) {
93770
+ const workflowDir = path44.resolve(dir);
93771
+ if (!fs39.existsSync(workflowDir)) {
93782
93772
  throw new Error(`Directory not found: ${workflowDir}`);
93783
93773
  }
93784
- if (!fs40.statSync(workflowDir).isDirectory()) {
93774
+ if (!fs39.statSync(workflowDir).isDirectory()) {
93785
93775
  throw new Error(`Not a directory: ${workflowDir}`);
93786
93776
  }
93787
93777
  const registry2 = new WorkflowRegistry(workflowDir);
@@ -93802,8 +93792,8 @@ async function openapiCommand(dir, options) {
93802
93792
  const format = options.format || "json";
93803
93793
  const spec = format === "yaml" ? generateOpenAPIYaml(endpoints, generatorOptions) : generateOpenAPIJson(endpoints, generatorOptions);
93804
93794
  if (options.output) {
93805
- const outputPath = path43.resolve(options.output);
93806
- fs40.writeFileSync(outputPath, spec);
93795
+ const outputPath = path44.resolve(options.output);
93796
+ safeWriteFile(outputPath, spec);
93807
93797
  logger.success(`OpenAPI specification written to ${outputPath}`);
93808
93798
  } else {
93809
93799
  process.stdout.write(spec + "\n");
@@ -93815,6 +93805,7 @@ var init_openapi = __esm({
93815
93805
  init_workflow_registry();
93816
93806
  init_generator();
93817
93807
  init_logger();
93808
+ init_safe_write();
93818
93809
  }
93819
93810
  });
93820
93811
 
@@ -93825,8 +93816,8 @@ __export(plugin_exports, {
93825
93816
  pluginInitCommand: () => pluginInitCommand,
93826
93817
  validatePluginName: () => validatePluginName
93827
93818
  });
93828
- import * as fs41 from "fs";
93829
- import * as path44 from "path";
93819
+ import * as fs40 from "fs";
93820
+ import * as path45 from "path";
93830
93821
  function validatePluginName(name) {
93831
93822
  if (!name) return "Plugin name cannot be empty";
93832
93823
  if (name.length > 100) return "Plugin name must be at most 100 characters";
@@ -93951,18 +93942,18 @@ async function pluginInitCommand(name, options) {
93951
93942
  }
93952
93943
  return;
93953
93944
  }
93954
- const targetDir = path44.resolve("plugins", name);
93945
+ const targetDir = path45.resolve("plugins", name);
93955
93946
  const filesCreated = [];
93956
93947
  const filesSkipped = [];
93957
93948
  for (const [relativePath, content] of Object.entries(files)) {
93958
- const absPath = path44.join(targetDir, relativePath);
93959
- const dir = path44.dirname(absPath);
93960
- fs41.mkdirSync(dir, { recursive: true });
93961
- if (fs41.existsSync(absPath) && !force) {
93949
+ const absPath = path45.join(targetDir, relativePath);
93950
+ const dir = path45.dirname(absPath);
93951
+ fs40.mkdirSync(dir, { recursive: true });
93952
+ if (fs40.existsSync(absPath) && !force) {
93962
93953
  filesSkipped.push(relativePath);
93963
93954
  continue;
93964
93955
  }
93965
- fs41.writeFileSync(absPath, content, "utf8");
93956
+ fs40.writeFileSync(absPath, content, "utf8");
93966
93957
  filesCreated.push(relativePath);
93967
93958
  }
93968
93959
  logger.section("Plugin scaffolded");
@@ -93993,8 +93984,8 @@ var migrate_exports = {};
93993
93984
  __export(migrate_exports, {
93994
93985
  migrateCommand: () => migrateCommand
93995
93986
  });
93996
- import * as fs42 from "fs";
93997
- import * as path45 from "path";
93987
+ import * as fs41 from "fs";
93988
+ import * as path46 from "path";
93998
93989
  async function migrateCommand(globPattern, options = {}) {
93999
93990
  const { dryRun = false, diff = false } = options;
94000
93991
  const files = globSync(globPattern, { ignore: ["**/node_modules/**", "**/*.generated.ts"] });
@@ -94011,9 +94002,9 @@ async function migrateCommand(globPattern, options = {}) {
94011
94002
  let skippedCount = 0;
94012
94003
  let errorCount = 0;
94013
94004
  for (const file of files) {
94014
- const filePath = path45.resolve(file);
94005
+ const filePath = path46.resolve(file);
94015
94006
  try {
94016
- const sourceCode = fs42.readFileSync(filePath, "utf8");
94007
+ const sourceCode = fs41.readFileSync(filePath, "utf8");
94017
94008
  const parseResult = await parseWorkflow(filePath);
94018
94009
  if (parseResult.errors.length > 0) {
94019
94010
  logger.error(` ${file}: parse errors \u2014 skipping`);
@@ -94046,7 +94037,7 @@ ${file}:`);
94046
94037
  migratedCount++;
94047
94038
  continue;
94048
94039
  }
94049
- fs42.writeFileSync(filePath, genResult.code, "utf8");
94040
+ safeWriteFile(filePath, genResult.code);
94050
94041
  logger.success(` ${file}: migrated`);
94051
94042
  migratedCount++;
94052
94043
  } catch (error2) {
@@ -94070,6 +94061,7 @@ var init_migrate = __esm({
94070
94061
  init_diff();
94071
94062
  init_registry2();
94072
94063
  init_logger();
94064
+ init_safe_write();
94073
94065
  init_error_utils();
94074
94066
  }
94075
94067
  });
@@ -94079,16 +94071,16 @@ var status_exports = {};
94079
94071
  __export(status_exports, {
94080
94072
  statusCommand: () => statusCommand
94081
94073
  });
94082
- import * as fs43 from "fs";
94083
- import * as path46 from "path";
94074
+ import * as fs42 from "fs";
94075
+ import * as path47 from "path";
94084
94076
  function formatPortList(ports) {
94085
94077
  return Object.entries(ports).filter(([name]) => name !== "execute" && name !== "onSuccess" && name !== "onFailure").map(([name, port]) => `${name}(${port.dataType.toLowerCase()})`);
94086
94078
  }
94087
94079
  async function statusCommand(input, options = {}) {
94088
94080
  const { workflowName, json: json2 = false } = options;
94089
94081
  try {
94090
- const filePath = path46.resolve(input);
94091
- if (!fs43.existsSync(filePath)) {
94082
+ const filePath = path47.resolve(input);
94083
+ if (!fs42.existsSync(filePath)) {
94092
94084
  if (json2) {
94093
94085
  console.log(JSON.stringify({ error: `File not found: ${input}` }));
94094
94086
  } else {
@@ -94193,8 +94185,8 @@ var implement_exports = {};
94193
94185
  __export(implement_exports, {
94194
94186
  implementCommand: () => implementCommand
94195
94187
  });
94196
- import * as fs44 from "fs";
94197
- import * as path47 from "path";
94188
+ import * as fs43 from "fs";
94189
+ import * as path48 from "path";
94198
94190
  function findDeclareFunction2(source, functionName) {
94199
94191
  const lines = source.split("\n");
94200
94192
  const escaped = functionName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -94216,16 +94208,14 @@ function findDeclareFunction2(source, functionName) {
94216
94208
  async function implementCommand(input, nodeName, options = {}) {
94217
94209
  const { workflowName, preview = false } = options;
94218
94210
  try {
94219
- const filePath = path47.resolve(input);
94220
- if (!fs44.existsSync(filePath)) {
94221
- logger.error(`File not found: ${input}`);
94222
- process.exit(1);
94211
+ const filePath = path48.resolve(input);
94212
+ if (!fs43.existsSync(filePath)) {
94213
+ throw new Error(`File not found: ${input}`);
94223
94214
  }
94224
94215
  const parseResult = await parseWorkflow(filePath, { workflowName });
94225
94216
  if (parseResult.errors.length > 0) {
94226
- logger.error("Parse errors:");
94227
- parseResult.errors.forEach((e) => logger.error(` ${e}`));
94228
- process.exit(1);
94217
+ throw new Error(`Parse errors:
94218
+ ${parseResult.errors.map((e) => ` ${e}`).join("\n")}`);
94229
94219
  }
94230
94220
  const ast = parseResult.ast;
94231
94221
  const stubNodeType = ast.nodeTypes.find(
@@ -94241,17 +94231,15 @@ async function implementCommand(input, nodeName, options = {}) {
94241
94231
  }
94242
94232
  const available = ast.nodeTypes.filter((nt) => nt.variant === "STUB").map((nt) => nt.functionName);
94243
94233
  if (available.length === 0) {
94244
- logger.error("No stub nodes found in this workflow.");
94234
+ throw new Error("No stub nodes found in this workflow.");
94245
94235
  } else {
94246
- logger.error(`Stub node "${nodeName}" not found. Available stubs: ${available.join(", ")}`);
94236
+ throw new Error(`Stub node "${nodeName}" not found. Available stubs: ${available.join(", ")}`);
94247
94237
  }
94248
- process.exit(1);
94249
94238
  }
94250
- const source = fs44.readFileSync(filePath, "utf8");
94239
+ const source = fs43.readFileSync(filePath, "utf8");
94251
94240
  const found = findDeclareFunction2(source, stubNodeType.functionName);
94252
94241
  if (!found) {
94253
- logger.error(`Could not find "declare function ${stubNodeType.functionName}" in source file.`);
94254
- process.exit(1);
94242
+ throw new Error(`Could not find "declare function ${stubNodeType.functionName}" in source file.`);
94255
94243
  }
94256
94244
  const implementedType = { ...stubNodeType, variant: "FUNCTION" };
94257
94245
  const signatureLines = generateFunctionSignature(implementedType);
@@ -94262,12 +94250,11 @@ async function implementCommand(input, nodeName, options = {}) {
94262
94250
  console.log(replacement);
94263
94251
  } else {
94264
94252
  const updated = source.replace(found.match, replacement);
94265
- fs44.writeFileSync(filePath, updated, "utf8");
94266
- logger.success(`Implemented ${stubNodeType.functionName} in ${path47.basename(filePath)}`);
94253
+ safeWriteFile(filePath, updated);
94254
+ logger.success(`Implemented ${stubNodeType.functionName} in ${path48.basename(filePath)}`);
94267
94255
  }
94268
94256
  } catch (error2) {
94269
- logger.error(`Implement failed: ${getErrorMessage(error2)}`);
94270
- process.exit(1);
94257
+ throw new Error(`Implement failed: ${getErrorMessage(error2)}`);
94271
94258
  }
94272
94259
  }
94273
94260
  var init_implement = __esm({
@@ -94277,6 +94264,7 @@ var init_implement = __esm({
94277
94264
  init_annotation_generator();
94278
94265
  init_logger();
94279
94266
  init_error_utils();
94267
+ init_safe_write();
94280
94268
  }
94281
94269
  });
94282
94270
 
@@ -94415,8 +94403,7 @@ __export(docs_exports, {
94415
94403
  async function docsListCommand(options) {
94416
94404
  const topics = listTopics();
94417
94405
  if (topics.length === 0) {
94418
- logger.error("No documentation topics found.");
94419
- process.exit(1);
94406
+ throw new Error("No documentation topics found.");
94420
94407
  }
94421
94408
  if (options.json) {
94422
94409
  process.stdout.write(JSON.stringify({ topics }, null, 2) + "\n");
@@ -94437,16 +94424,14 @@ async function docsReadCommand(topic, options) {
94437
94424
  if (options.json) {
94438
94425
  const structured = readTopicStructured(topic);
94439
94426
  if (!structured) {
94440
- logger.error(`Unknown topic: "${topic}". Run "fw docs" to see available topics.`);
94441
- process.exit(1);
94427
+ throw new Error(`Unknown topic: "${topic}". Run "fw docs" to see available topics.`);
94442
94428
  }
94443
94429
  process.stdout.write(JSON.stringify(structured, null, 2) + "\n");
94444
94430
  return;
94445
94431
  }
94446
94432
  const doc = readTopic(topic, options.compact);
94447
94433
  if (!doc) {
94448
- logger.error(`Unknown topic: "${topic}". Run "fw docs" to see available topics.`);
94449
- process.exit(1);
94434
+ throw new Error(`Unknown topic: "${topic}". Run "fw docs" to see available topics.`);
94450
94435
  }
94451
94436
  process.stdout.write(doc.content + "\n");
94452
94437
  }
@@ -94496,7 +94481,6 @@ var context_exports = {};
94496
94481
  __export(context_exports, {
94497
94482
  contextCommand: () => contextCommand
94498
94483
  });
94499
- import * as fs45 from "fs";
94500
94484
  async function contextCommand(preset, options) {
94501
94485
  if (options.list) {
94502
94486
  logger.section("Context Presets");
@@ -94513,15 +94497,13 @@ async function contextCommand(preset, options) {
94513
94497
  }
94514
94498
  const presetName = preset ?? "core";
94515
94499
  if (!PRESET_NAMES.includes(presetName) && !options.topics) {
94516
- logger.error(
94500
+ throw new Error(
94517
94501
  `Unknown preset "${preset}". Available: ${PRESET_NAMES.join(", ")}. Or use --topics to specify topics directly.`
94518
94502
  );
94519
- process.exit(1);
94520
94503
  }
94521
94504
  const profile = options.profile ?? "standalone";
94522
94505
  if (profile !== "standalone" && profile !== "assistant") {
94523
- logger.error(`Unknown profile "${profile}". Use "standalone" or "assistant".`);
94524
- process.exit(1);
94506
+ throw new Error(`Unknown profile "${profile}". Use "standalone" or "assistant".`);
94525
94507
  }
94526
94508
  const result = buildContext({
94527
94509
  preset: PRESET_NAMES.includes(presetName) ? presetName : "core",
@@ -94531,7 +94513,7 @@ async function contextCommand(preset, options) {
94531
94513
  includeGrammar: options.grammar !== false
94532
94514
  });
94533
94515
  if (options.output) {
94534
- fs45.writeFileSync(options.output, result.content, "utf-8");
94516
+ safeWriteFile(options.output, result.content);
94535
94517
  logger.success(`Context written to ${options.output}`);
94536
94518
  } else {
94537
94519
  process.stdout.write(result.content);
@@ -94545,6 +94527,7 @@ var init_context2 = __esm({
94545
94527
  "use strict";
94546
94528
  init_context();
94547
94529
  init_logger();
94530
+ init_safe_write();
94548
94531
  }
94549
94532
  });
94550
94533
 
@@ -94558,8 +94541,8 @@ __export(market_exports, {
94558
94541
  marketPublishCommand: () => marketPublishCommand,
94559
94542
  marketSearchCommand: () => marketSearchCommand
94560
94543
  });
94561
- import * as fs46 from "fs";
94562
- import * as path48 from "path";
94544
+ import * as fs44 from "fs";
94545
+ import * as path49 from "path";
94563
94546
  import { execSync as execSync7 } from "child_process";
94564
94547
  async function marketInitCommand(name, options = {}) {
94565
94548
  if (!name.startsWith("flow-weaver-pack-")) {
@@ -94567,18 +94550,16 @@ async function marketInitCommand(name, options = {}) {
94567
94550
  logger.warn(`Name should follow "flow-weaver-pack-*" convention, using "${suggested}"`);
94568
94551
  name = suggested;
94569
94552
  }
94570
- const targetDir = path48.resolve(name);
94571
- if (fs46.existsSync(targetDir)) {
94572
- const stat = fs46.statSync(targetDir);
94553
+ const targetDir = path49.resolve(name);
94554
+ if (fs44.existsSync(targetDir)) {
94555
+ const stat = fs44.statSync(targetDir);
94573
94556
  if (stat.isDirectory()) {
94574
- const contents = fs46.readdirSync(targetDir);
94557
+ const contents = fs44.readdirSync(targetDir);
94575
94558
  if (contents.length > 0) {
94576
- logger.error(`Directory "${name}" already exists and is not empty`);
94577
- process.exit(1);
94559
+ throw new Error(`Directory "${name}" already exists and is not empty`);
94578
94560
  }
94579
94561
  } else {
94580
- logger.error(`"${name}" already exists and is not a directory`);
94581
- process.exit(1);
94562
+ throw new Error(`"${name}" already exists and is not a directory`);
94582
94563
  }
94583
94564
  }
94584
94565
  logger.section("Creating Marketplace Package");
@@ -94586,13 +94567,13 @@ async function marketInitCommand(name, options = {}) {
94586
94567
  logger.newline();
94587
94568
  const dirs = [
94588
94569
  targetDir,
94589
- path48.join(targetDir, "src"),
94590
- path48.join(targetDir, "src", "node-types"),
94591
- path48.join(targetDir, "src", "workflows"),
94592
- path48.join(targetDir, "src", "patterns")
94570
+ path49.join(targetDir, "src"),
94571
+ path49.join(targetDir, "src", "node-types"),
94572
+ path49.join(targetDir, "src", "workflows"),
94573
+ path49.join(targetDir, "src", "patterns")
94593
94574
  ];
94594
94575
  for (const dir of dirs) {
94595
- fs46.mkdirSync(dir, { recursive: true });
94576
+ fs44.mkdirSync(dir, { recursive: true });
94596
94577
  }
94597
94578
  const shortName = name.replace(/^flow-weaver-pack-/, "");
94598
94579
  const pkg = {
@@ -94623,8 +94604,8 @@ async function marketInitCommand(name, options = {}) {
94623
94604
  },
94624
94605
  files: ["dist", "flowweaver.manifest.json", "README.md", "LICENSE"]
94625
94606
  };
94626
- fs46.writeFileSync(
94627
- path48.join(targetDir, "package.json"),
94607
+ fs44.writeFileSync(
94608
+ path49.join(targetDir, "package.json"),
94628
94609
  JSON.stringify(pkg, null, 2) + "\n"
94629
94610
  );
94630
94611
  const tsconfig = {
@@ -94642,8 +94623,8 @@ async function marketInitCommand(name, options = {}) {
94642
94623
  include: ["src"],
94643
94624
  exclude: ["node_modules", "dist"]
94644
94625
  };
94645
- fs46.writeFileSync(
94646
- path48.join(targetDir, "tsconfig.json"),
94626
+ fs44.writeFileSync(
94627
+ path49.join(targetDir, "tsconfig.json"),
94647
94628
  JSON.stringify(tsconfig, null, 2) + "\n"
94648
94629
  );
94649
94630
  const sampleNodeType = `/**
@@ -94661,21 +94642,21 @@ export function sample(execute: () => void, data: string): { result: string } {
94661
94642
  return { result: data.toUpperCase() };
94662
94643
  }
94663
94644
  `;
94664
- fs46.writeFileSync(path48.join(targetDir, "src", "node-types", "sample.ts"), sampleNodeType);
94665
- fs46.writeFileSync(
94666
- path48.join(targetDir, "src", "node-types", "index.ts"),
94645
+ fs44.writeFileSync(path49.join(targetDir, "src", "node-types", "sample.ts"), sampleNodeType);
94646
+ fs44.writeFileSync(
94647
+ path49.join(targetDir, "src", "node-types", "index.ts"),
94667
94648
  "export { sample } from './sample.js';\n"
94668
94649
  );
94669
- fs46.writeFileSync(
94670
- path48.join(targetDir, "src", "workflows", "index.ts"),
94650
+ fs44.writeFileSync(
94651
+ path49.join(targetDir, "src", "workflows", "index.ts"),
94671
94652
  "// Export workflows here\n"
94672
94653
  );
94673
- fs46.writeFileSync(
94674
- path48.join(targetDir, "src", "patterns", "index.ts"),
94654
+ fs44.writeFileSync(
94655
+ path49.join(targetDir, "src", "patterns", "index.ts"),
94675
94656
  "// Export patterns here\n"
94676
94657
  );
94677
- fs46.writeFileSync(
94678
- path48.join(targetDir, "src", "index.ts"),
94658
+ fs44.writeFileSync(
94659
+ path49.join(targetDir, "src", "index.ts"),
94679
94660
  [
94680
94661
  "export * from './node-types/index.js';",
94681
94662
  "export * from './workflows/index.js';",
@@ -94708,9 +94689,9 @@ npm run pack # Generate flowweaver.manifest.json
94708
94689
  npm publish # Publish to npm
94709
94690
  \`\`\`
94710
94691
  `;
94711
- fs46.writeFileSync(path48.join(targetDir, "README.md"), readme);
94712
- fs46.writeFileSync(
94713
- path48.join(targetDir, ".gitignore"),
94692
+ fs44.writeFileSync(path49.join(targetDir, "README.md"), readme);
94693
+ fs44.writeFileSync(
94694
+ path49.join(targetDir, ".gitignore"),
94714
94695
  ["node_modules", "dist", "*.tgz", ""].join("\n")
94715
94696
  );
94716
94697
  logger.success("Created package.json");
@@ -94730,7 +94711,7 @@ npm publish # Publish to npm
94730
94711
  logger.newline();
94731
94712
  }
94732
94713
  async function marketPackCommand(directory, options = {}) {
94733
- const dir = path48.resolve(directory ?? ".");
94714
+ const dir = path49.resolve(directory ?? ".");
94734
94715
  const { json: json2 = false, verbose = false } = options;
94735
94716
  if (!json2) {
94736
94717
  logger.section("Packing Marketplace Package");
@@ -94766,26 +94747,25 @@ async function marketPackCommand(directory, options = {}) {
94766
94747
  }
94767
94748
  if (!validation.valid) {
94768
94749
  logger.newline();
94769
- logger.error("Package validation failed. Fix errors above before publishing.");
94770
- process.exit(1);
94750
+ throw new Error("Package validation failed. Fix errors above before publishing.");
94771
94751
  }
94772
94752
  const outPath = writeManifest(dir, manifest);
94773
94753
  logger.newline();
94774
- logger.success(`Manifest written to ${path48.relative(dir, outPath)}`);
94754
+ logger.success(`Manifest written to ${path49.relative(dir, outPath)}`);
94775
94755
  if (warnings.length > 0) {
94776
94756
  logger.warn(`${warnings.length} warning(s) \u2014 consider fixing before publishing`);
94777
94757
  }
94778
94758
  logger.newline();
94779
94759
  }
94780
94760
  async function marketPublishCommand(directory, options = {}) {
94781
- const dir = path48.resolve(directory ?? ".");
94761
+ const dir = path49.resolve(directory ?? ".");
94782
94762
  const { dryRun = false, tag } = options;
94783
94763
  logger.section("Publishing Marketplace Package");
94784
94764
  await marketPackCommand(dir, { json: false });
94785
- if (!fs46.existsSync(path48.join(dir, "LICENSE"))) {
94765
+ if (!fs44.existsSync(path49.join(dir, "LICENSE"))) {
94786
94766
  logger.warn("LICENSE file not found \u2014 consider adding one");
94787
94767
  }
94788
- const pkg = JSON.parse(fs46.readFileSync(path48.join(dir, "package.json"), "utf-8"));
94768
+ const pkg = JSON.parse(fs44.readFileSync(path49.join(dir, "package.json"), "utf-8"));
94789
94769
  logger.info(`Publishing ${pkg.name}@${pkg.version}`);
94790
94770
  const npmArgs = ["publish"];
94791
94771
  if (dryRun) npmArgs.push("--dry-run");
@@ -94798,8 +94778,7 @@ async function marketPublishCommand(directory, options = {}) {
94798
94778
  logger.success(`Published ${pkg.name}@${pkg.version} to npm`);
94799
94779
  }
94800
94780
  } catch (err) {
94801
- logger.error(`npm publish failed: ${getErrorMessage(err)}`);
94802
- process.exit(1);
94781
+ throw new Error(`npm publish failed: ${getErrorMessage(err)}`);
94803
94782
  }
94804
94783
  }
94805
94784
  async function marketInstallCommand(packageSpec, options = {}) {
@@ -94821,7 +94800,7 @@ async function marketInstallCommand(packageSpec, options = {}) {
94821
94800
  return;
94822
94801
  }
94823
94802
  const packageName = resolvePackageName2(packageSpec);
94824
- const manifest = readManifest(path48.join(process.cwd(), "node_modules", packageName));
94803
+ const manifest = readManifest(path49.join(process.cwd(), "node_modules", packageName));
94825
94804
  if (json2) {
94826
94805
  console.log(JSON.stringify({
94827
94806
  success: true,
@@ -94912,7 +94891,7 @@ async function marketListCommand(options = {}) {
94912
94891
  }
94913
94892
  function resolvePackageName2(spec) {
94914
94893
  if (spec.endsWith(".tgz") || spec.endsWith(".tar.gz")) {
94915
- const base = path48.basename(spec, spec.endsWith(".tar.gz") ? ".tar.gz" : ".tgz");
94894
+ const base = path49.basename(spec, spec.endsWith(".tar.gz") ? ".tar.gz" : ".tgz");
94916
94895
  const match2 = base.match(/^(.+)-\d+\.\d+\.\d+/);
94917
94896
  return match2 ? match2[1] : base;
94918
94897
  }
@@ -94973,7 +94952,7 @@ var pack_commands_exports = {};
94973
94952
  __export(pack_commands_exports, {
94974
94953
  registerPackCommands: () => registerPackCommands
94975
94954
  });
94976
- import * as path49 from "path";
94955
+ import * as path50 from "path";
94977
94956
  import { pathToFileURL as pathToFileURL4 } from "node:url";
94978
94957
  function compareVersions2(a, b) {
94979
94958
  const pa = a.split(".").map(Number);
@@ -95015,7 +94994,7 @@ async function registerPackCommands(program3) {
95015
94994
  if (!manifest.cliEntrypoint || !manifest.cliCommands?.length) continue;
95016
94995
  checkPackEngineVersion2(pkg);
95017
94996
  const namespace = deriveNamespace(pkg.name);
95018
- const entrypointPath = path49.join(pkg.path, manifest.cliEntrypoint);
94997
+ const entrypointPath = path50.join(pkg.path, manifest.cliEntrypoint);
95019
94998
  const group = program3.command(namespace).description(`Commands from ${pkg.name}`);
95020
94999
  const showPackHelp = async () => {
95021
95000
  try {
@@ -95076,13 +95055,13 @@ var init_pack_commands = __esm({
95076
95055
  });
95077
95056
 
95078
95057
  // src/cli/config/credentials.ts
95079
- import * as fs47 from "node:fs";
95080
- import * as path50 from "node:path";
95058
+ import * as fs45 from "node:fs";
95059
+ import * as path51 from "node:path";
95081
95060
  import * as os3 from "node:os";
95082
95061
  function loadCredentials() {
95083
- if (!fs47.existsSync(CREDENTIALS_FILE)) return null;
95062
+ if (!fs45.existsSync(CREDENTIALS_FILE)) return null;
95084
95063
  try {
95085
- const data = JSON.parse(fs47.readFileSync(CREDENTIALS_FILE, "utf-8"));
95064
+ const data = JSON.parse(fs45.readFileSync(CREDENTIALS_FILE, "utf-8"));
95086
95065
  if (isTokenExpired(data)) return null;
95087
95066
  return data;
95088
95067
  } catch {
@@ -95090,16 +95069,16 @@ function loadCredentials() {
95090
95069
  }
95091
95070
  }
95092
95071
  function saveCredentials(creds) {
95093
- fs47.mkdirSync(FW_CONFIG_DIR, { recursive: true });
95094
- fs47.writeFileSync(CREDENTIALS_FILE, JSON.stringify(creds, null, 2), "utf-8");
95072
+ fs45.mkdirSync(FW_CONFIG_DIR, { recursive: true });
95073
+ fs45.writeFileSync(CREDENTIALS_FILE, JSON.stringify(creds, null, 2), "utf-8");
95095
95074
  try {
95096
- fs47.chmodSync(CREDENTIALS_FILE, 384);
95075
+ fs45.chmodSync(CREDENTIALS_FILE, 384);
95097
95076
  } catch {
95098
95077
  }
95099
95078
  }
95100
95079
  function clearCredentials() {
95101
95080
  try {
95102
- fs47.unlinkSync(CREDENTIALS_FILE);
95081
+ fs45.unlinkSync(CREDENTIALS_FILE);
95103
95082
  } catch {
95104
95083
  }
95105
95084
  }
@@ -95114,8 +95093,8 @@ var FW_CONFIG_DIR, CREDENTIALS_FILE;
95114
95093
  var init_credentials = __esm({
95115
95094
  "src/cli/config/credentials.ts"() {
95116
95095
  "use strict";
95117
- FW_CONFIG_DIR = path50.join(os3.homedir(), ".fw");
95118
- CREDENTIALS_FILE = path50.join(FW_CONFIG_DIR, "credentials.json");
95096
+ FW_CONFIG_DIR = path51.join(os3.homedir(), ".fw");
95097
+ CREDENTIALS_FILE = path51.join(FW_CONFIG_DIR, "credentials.json");
95119
95098
  }
95120
95099
  });
95121
95100
 
@@ -95131,14 +95110,14 @@ var init_platform_client = __esm({
95131
95110
  this.baseUrl = creds.platformUrl.replace(/\/+$/, "");
95132
95111
  this.token = creds.token;
95133
95112
  }
95134
- async fetch(path54, opts = {}) {
95113
+ async fetch(path55, opts = {}) {
95135
95114
  const isApiKey = this.token.startsWith("fw_");
95136
95115
  const headers = {
95137
95116
  "Content-Type": "application/json",
95138
95117
  ...isApiKey ? { "X-API-Key": this.token } : { Authorization: `Bearer ${this.token}` },
95139
95118
  ...opts.headers ?? {}
95140
95119
  };
95141
- return fetch(`${this.baseUrl}${path54}`, { ...opts, headers });
95120
+ return fetch(`${this.baseUrl}${path55}`, { ...opts, headers });
95142
95121
  }
95143
95122
  // Auth
95144
95123
  async getUser() {
@@ -95495,8 +95474,8 @@ __export(deploy_exports, {
95495
95474
  deployCommand: () => deployCommand,
95496
95475
  undeployCommand: () => undeployCommand
95497
95476
  });
95498
- import * as fs48 from "node:fs";
95499
- import * as path51 from "node:path";
95477
+ import * as fs46 from "node:fs";
95478
+ import * as path52 from "node:path";
95500
95479
  async function deployCommand(filePath, options = {}) {
95501
95480
  const creds = loadCredentials();
95502
95481
  if (!creds) {
@@ -95504,14 +95483,14 @@ async function deployCommand(filePath, options = {}) {
95504
95483
  process.exit(1);
95505
95484
  return;
95506
95485
  }
95507
- const absPath = path51.resolve(filePath);
95508
- if (!fs48.existsSync(absPath)) {
95486
+ const absPath = path52.resolve(filePath);
95487
+ if (!fs46.existsSync(absPath)) {
95509
95488
  console.error(` \x1B[31m\u2717\x1B[0m File not found: ${filePath}`);
95510
95489
  process.exit(1);
95511
95490
  return;
95512
95491
  }
95513
- const source = fs48.readFileSync(absPath, "utf-8");
95514
- const name = options.name ?? path51.basename(filePath, path51.extname(filePath));
95492
+ const source = fs46.readFileSync(absPath, "utf-8");
95493
+ const name = options.name ?? path52.basename(filePath, path52.extname(filePath));
95515
95494
  const client = new PlatformClient(creds);
95516
95495
  console.log("");
95517
95496
  console.log(` \x1B[2mPushing ${name}...\x1B[0m`);
@@ -95767,8 +95746,8 @@ __export(connect_exports, {
95767
95746
  handleConnect: () => handleConnect,
95768
95747
  loadPackDeviceHandlers: () => loadPackDeviceHandlers
95769
95748
  });
95770
- import * as fs49 from "node:fs";
95771
- import * as path52 from "node:path";
95749
+ import * as fs47 from "node:fs";
95750
+ import * as path53 from "node:path";
95772
95751
  import * as os4 from "node:os";
95773
95752
  import * as readline10 from "node:readline";
95774
95753
  function promptYesNo(message) {
@@ -95804,12 +95783,12 @@ async function loadPackDeviceHandlers(conn, projectDir) {
95804
95783
  return loadedPacks;
95805
95784
  }
95806
95785
  async function handleConnect(projectDir) {
95807
- const credPath = path52.join(os4.homedir(), ".fw", "credentials.json");
95808
- if (!fs49.existsSync(credPath)) {
95786
+ const credPath = path53.join(os4.homedir(), ".fw", "credentials.json");
95787
+ if (!fs47.existsSync(credPath)) {
95809
95788
  console.error("\n Not logged in. Run: fw login\n");
95810
95789
  process.exit(1);
95811
95790
  }
95812
- const creds = JSON.parse(fs49.readFileSync(credPath, "utf-8"));
95791
+ const creds = JSON.parse(fs47.readFileSync(credPath, "utf-8"));
95813
95792
  if (!creds.token || !creds.platformUrl || creds.expiresAt < Date.now()) {
95814
95793
  console.error("\n Credentials expired. Run: fw login\n");
95815
95794
  process.exit(1);
@@ -95818,27 +95797,27 @@ async function handleConnect(projectDir) {
95818
95797
  platformUrl: creds.platformUrl,
95819
95798
  token: creds.token,
95820
95799
  projectDir,
95821
- deviceName: path52.basename(projectDir),
95800
+ deviceName: path53.basename(projectDir),
95822
95801
  logger: (msg) => process.stderr.write(` \x1B[2m${msg}\x1B[0m
95823
95802
  `)
95824
95803
  });
95825
95804
  conn.addCapability("file_read");
95826
95805
  conn.addCapability("file_list");
95827
95806
  conn.onRequest("file:read", async (_method, params) => {
95828
- const filePath = path52.resolve(projectDir, String(params.path ?? ""));
95807
+ const filePath = path53.resolve(projectDir, String(params.path ?? ""));
95829
95808
  if (!filePath.startsWith(projectDir)) throw new Error("Path outside project directory");
95830
- if (!fs49.existsSync(filePath)) throw new Error("File not found");
95831
- const stat = fs49.statSync(filePath);
95832
- if (stat.isDirectory()) return { type: "directory", entries: fs49.readdirSync(filePath) };
95809
+ if (!fs47.existsSync(filePath)) throw new Error("File not found");
95810
+ const stat = fs47.statSync(filePath);
95811
+ if (stat.isDirectory()) return { type: "directory", entries: fs47.readdirSync(filePath) };
95833
95812
  if (stat.size > 1048576) throw new Error("File too large (>1MB)");
95834
- return { type: "file", content: fs49.readFileSync(filePath, "utf-8") };
95813
+ return { type: "file", content: fs47.readFileSync(filePath, "utf-8") };
95835
95814
  });
95836
95815
  conn.onRequest("file:list", async (_method, params) => {
95837
- const dirPath = path52.resolve(projectDir, String(params.path ?? "."));
95816
+ const dirPath = path53.resolve(projectDir, String(params.path ?? "."));
95838
95817
  if (!dirPath.startsWith(projectDir)) throw new Error("Path outside project directory");
95839
- if (!fs49.existsSync(dirPath)) throw new Error("Directory not found");
95840
- const entries = fs49.readdirSync(dirPath, { withFileTypes: true });
95841
- return entries.filter((e) => !e.name.startsWith(".") && e.name !== "node_modules" && e.name !== "dist").map((e) => ({ name: e.name, type: e.isDirectory() ? "directory" : "file", path: path52.relative(projectDir, path52.join(dirPath, e.name)), hasUnfetchedChildren: e.isDirectory() }));
95818
+ if (!fs47.existsSync(dirPath)) throw new Error("Directory not found");
95819
+ const entries = fs47.readdirSync(dirPath, { withFileTypes: true });
95820
+ return entries.filter((e) => !e.name.startsWith(".") && e.name !== "node_modules" && e.name !== "dist").map((e) => ({ name: e.name, type: e.isDirectory() ? "directory" : "file", path: path53.relative(projectDir, path53.join(dirPath, e.name)), hasUnfetchedChildren: e.isDirectory() }));
95842
95821
  });
95843
95822
  const loadedPacks = await loadPackDeviceHandlers(conn, projectDir);
95844
95823
  if (loadedPacks.length > 0) {
@@ -95846,7 +95825,7 @@ async function handleConnect(projectDir) {
95846
95825
  }
95847
95826
  console.log("");
95848
95827
  console.log(" \x1B[1mflow-weaver connect\x1B[0m");
95849
- console.log(` \x1B[2mProject: ${path52.basename(projectDir)}\x1B[0m`);
95828
+ console.log(` \x1B[2mProject: ${path53.basename(projectDir)}\x1B[0m`);
95850
95829
  console.log(` \x1B[2mPlatform: ${creds.platformUrl}\x1B[0m`);
95851
95830
  console.log("");
95852
95831
  if (loadedPacks.length > 0) {
@@ -95929,7 +95908,7 @@ if (process.env.FORCE_COLOR === "0") {
95929
95908
  }
95930
95909
 
95931
95910
  // src/cli/index.ts
95932
- import * as path53 from "node:path";
95911
+ import * as path54 from "node:path";
95933
95912
 
95934
95913
  // node_modules/commander/esm.mjs
95935
95914
  var import_index = __toESM(require_commander(), 1);
@@ -95948,10 +95927,23 @@ var {
95948
95927
  Help
95949
95928
  } = import_index.default;
95950
95929
 
95930
+ // src/cli/utils/parse-int-strict.ts
95931
+ function parseIntStrict(value) {
95932
+ const trimmed = value.trim();
95933
+ if (trimmed === "") {
95934
+ throw new Error(`"${value}" is not a valid number`);
95935
+ }
95936
+ const n = Number(trimmed);
95937
+ if (!Number.isFinite(n) || !Number.isInteger(n)) {
95938
+ throw new Error(`"${value}" is not a valid number`);
95939
+ }
95940
+ return n;
95941
+ }
95942
+
95951
95943
  // src/cli/index.ts
95952
95944
  init_logger();
95953
95945
  init_error_utils();
95954
- var version2 = true ? "0.23.4" : "0.0.0-dev";
95946
+ var version2 = true ? "0.24.0" : "0.0.0-dev";
95955
95947
  var program2 = new Command();
95956
95948
  program2.name("fw").description("Flow Weaver Annotations - Compile and validate workflow files").option("-v, --version", "Output the current version").option("--no-color", "Disable colors").option("--color", "Force colors").on("option:version", () => {
95957
95949
  logger.banner(version2);
@@ -95982,7 +95974,7 @@ function wrapAction(fn) {
95982
95974
  }
95983
95975
  };
95984
95976
  }
95985
- program2.command("compile <input>").description("Compile workflow files to TypeScript").option("-o, --output <path>", "Output file or directory").option("-p, --production", "Generate production code (no debug events)", false).option("-s, --source-map", "Generate source maps", false).option("--verbose", "Verbose output", false).option("--dry-run", "Preview compilation without writing files", false).option("-w, --workflow <name>", "Specific workflow name to compile").addOption(new Option("-f, --format <format>", "Module format").choices(["esm", "cjs", "auto"]).default("auto")).option("--strict", "Treat type coercion warnings as errors", false).option("--inline-runtime", "Force inline runtime even when @synergenius/flow-weaver package is installed", false).option("--clean", "Omit redundant @param/@returns annotations from compiled output", false).option("--target <target>", "Compilation target: typescript (default) or a registered extension target").option("--cron <schedule>", "Set cron trigger schedule").option("--serve", "Generate serve() handler for HTTP event reception").option("--framework <name>", "Framework adapter for serve handler (next, express, hono, fastify, remix)").option("--typed-events", "Generate Zod event schemas from workflow @param annotations").option("--retries <n>", "Number of retries per function", parseInt).option("--timeout <duration>", 'Function timeout (e.g. "30m", "1h")').action(wrapAction(async (input, options) => {
95977
+ program2.command("compile <input>").description("Compile workflow files to TypeScript").option("-o, --output <path>", "Output file or directory").option("-p, --production", "Generate production code (no debug events)", false).option("-s, --source-map", "Generate source maps", false).option("--verbose", "Verbose output", false).option("--dry-run", "Preview compilation without writing files", false).option("-w, --workflow <name>", "Specific workflow name to compile").addOption(new Option("-f, --format <format>", "Module format").choices(["esm", "cjs", "auto"]).default("auto")).option("--strict", "Treat type coercion warnings as errors", false).option("--clean", "Omit redundant @param/@returns annotations from compiled output", false).option("--target <target>", "Compilation target: typescript (default) or a registered extension target").option("--cron <schedule>", "Set cron trigger schedule").option("--serve", "Generate serve() handler for HTTP event reception").option("--framework <name>", "Framework adapter for serve handler (next, express, hono, fastify, remix)").option("--typed-events", "Generate Zod event schemas from workflow @param annotations").option("--retries <n>", "Number of retries per function", parseIntStrict).option("--timeout <duration>", 'Function timeout (e.g. "30m", "1h")').action(wrapAction(async (input, options) => {
95986
95978
  const { compileCommand: compileCommand2 } = await Promise.resolve().then(() => (init_compile2(), compile_exports));
95987
95979
  if (options.workflow) options.workflowName = options.workflow;
95988
95980
  await compileCommand2(input, options);
@@ -95996,7 +95988,7 @@ program2.command("describe <input>").description("Output workflow structure in L
95996
95988
  if (options.workflow) options.workflowName = options.workflow;
95997
95989
  await describeCommand2(input, options);
95998
95990
  }));
95999
- program2.command("diagram <input>").description("Generate SVG or interactive HTML diagram of a workflow").option("-t, --theme <theme>", "Color theme: dark, light", "dark").option("--width <pixels>", "SVG width in pixels").option("-p, --padding <pixels>", "Canvas padding in pixels").option("--no-port-labels", "Hide data type labels on ports").option("-w, --workflow <name>", "Specific workflow to render").addOption(new Option("-f, --format <format>", "Output format").choices(["svg", "html", "ascii", "ascii-compact", "text"]).default("svg")).option("-o, --output <file>", "Write output to file instead of stdout").action(wrapAction(async (input, options) => {
95991
+ program2.command("diagram <input>").description("Generate SVG or interactive HTML diagram of a workflow").addOption(new Option("-t, --theme <theme>", "Color theme").choices(["dark", "light"]).default("dark")).option("--width <pixels>", "SVG width in pixels").option("-p, --padding <pixels>", "Canvas padding in pixels").option("--no-port-labels", "Hide data type labels on ports").option("-w, --workflow <name>", "Specific workflow to render").addOption(new Option("-f, --format <format>", "Output format").choices(["svg", "html", "ascii", "ascii-compact", "text"]).default("svg")).option("-o, --output <file>", "Write output to file instead of stdout").action(wrapAction(async (input, options) => {
96000
95992
  if (options.width) options.width = Number(options.width);
96001
95993
  if (options.padding) options.padding = Number(options.padding);
96002
95994
  options.showPortLabels = options.portLabels;
@@ -96018,7 +96010,7 @@ program2.command("doctor").description("Check project environment and configurat
96018
96010
  const { doctorCommand: doctorCommand2 } = await Promise.resolve().then(() => (init_doctor(), doctor_exports));
96019
96011
  await doctorCommand2(options);
96020
96012
  }));
96021
- program2.command("init [directory]").description("Create a new flow-weaver project").option("-n, --name <name>", "Project name (defaults to directory name)").option("-t, --template <template>", "Workflow template (default: sequential)").option("-f, --format <format>", "Module format: esm or cjs (default: esm)").option("-y, --yes", "Skip prompts and use defaults", false).option("--preset <persona>", "User preset: nocode, vibecoder, lowcode, expert").option("--use-case <category>", "Use case: data, ai, api, automation, cicd, minimal").option("--mcp", "Auto-configure MCP for AI editors after scaffolding").option("--no-mcp", "Skip MCP setup prompt").option("--no-agent", "Skip post-init agent launch prompt").option("--install", "Run npm install after scaffolding").option("--no-install", "Skip npm install").option("--git", "Initialize a git repository").option("--no-git", "Skip git init").option("--with-weaver", "Install Weaver AI assistant").option("--no-weaver", "Skip Weaver installation").option("--force", "Overwrite existing files", false).option("--json", "Output results as JSON", false).action(wrapAction(async (directory, options) => {
96013
+ program2.command("init [directory]").description("Create a new flow-weaver project").option("-n, --name <name>", "Project name (defaults to directory name)").option("-t, --template <template>", "Workflow template (default: sequential)").option("-f, --format <format>", "Module format: esm or cjs (default: esm)").option("-y, --yes", "Skip prompts and use defaults", false).option("--preset <persona>", "User preset: nocode, vibecoder, lowcode, expert").option("--use-case <category>", "Use case: data, ai, api, automation, cicd, minimal").option("--mcp", "Auto-configure MCP for AI editors after scaffolding").option("--no-mcp", "Skip MCP setup prompt").option("--no-agent", "Skip post-init agent launch prompt").option("--install", "Run npm install after scaffolding").option("--no-install", "Skip npm install").option("--git", "Initialize a git repository").option("--no-git", "Skip git init").option("--with-weaver", "Install Weaver AI assistant").option("--no-weaver", "Skip Weaver installation").option("--force", "Overwrite existing files", false).action(wrapAction(async (directory, options) => {
96022
96014
  const { initCommand: initCommand2 } = await Promise.resolve().then(() => (init_init(), init_exports));
96023
96015
  await initCommand2(directory, options);
96024
96016
  }));
@@ -96027,7 +96019,7 @@ program2.command("watch <input>").description("Watch workflow files and recompil
96027
96019
  if (options.workflow) options.workflowName = options.workflow;
96028
96020
  await watchCommand2(input, options);
96029
96021
  }));
96030
- program2.command("dev <input>").description("Watch, compile, and run workflow on changes").option("--params <json>", "Input parameters as JSON string").option("--params-file <path>", "Path to JSON file with input parameters").option("-w, --workflow <name>", "Specific workflow name to run").option("-p, --production", "Run in production mode (no trace events)", false).option("-f, --format <format>", "Module format: esm, cjs, or auto", "auto").option("--clean", "Omit redundant @param/@returns annotations", false).option("--once", "Run once then exit", false).option("--json", "Output result as JSON", false).option("--target <target>", "Compilation target (default: typescript)").option("--framework <framework>", "Framework for serve handler", "express").option("--port <port>", "Port for dev server", (v) => parseInt(v, 10), 3e3).action(wrapAction(async (input, options) => {
96022
+ program2.command("dev <input>").description("Watch, compile, and run workflow on changes").option("--params <json>", "Input parameters as JSON string").option("--params-file <path>", "Path to JSON file with input parameters").option("-w, --workflow <name>", "Specific workflow name to run").option("-p, --production", "Run in production mode (no trace events)", false).option("-f, --format <format>", "Module format: esm, cjs, or auto", "auto").option("--clean", "Omit redundant @param/@returns annotations", false).option("--once", "Run once then exit", false).option("--json", "Output result as JSON", false).option("--target <target>", "Compilation target (default: typescript)").action(wrapAction(async (input, options) => {
96031
96023
  const { devCommand: devCommand2 } = await Promise.resolve().then(() => (init_dev(), dev_exports));
96032
96024
  await devCommand2(input, options);
96033
96025
  }));
@@ -96040,11 +96032,11 @@ program2.command("mcp-setup").description("Configure MCP server for AI coding to
96040
96032
  await mcpSetupCommand2(options);
96041
96033
  }));
96042
96034
  var createCmd = program2.command("create").description("Create workflows or nodes from templates");
96043
- createCmd.command("workflow <template> <file>").description("Create a workflow from a template").option("-l, --line <number>", "Insert at specific line number", parseInt).option("-a, --async", "Generate an async workflow", false).option("-p, --preview", "Preview generated code without writing", false).option("--provider <provider>", "LLM provider (openai, anthropic, ollama, mock)").option("--model <model>", "Model identifier (e.g., gpt-4o, claude-3-5-sonnet-20241022)").option("--config <json>", "Configuration as JSON string").option("--name <name>", "Override the derived workflow function name").option("--nodes <names>", 'Comma-separated node function names (e.g., "fetch,parse,store")').option("--input <name>", 'Custom input port name (default: "data")').option("--output <name>", 'Custom output port name (default: "result")').action(wrapAction(async (template, file, options) => {
96035
+ createCmd.command("workflow <template> <file>").description("Create a workflow from a template").option("-l, --line <number>", "Insert at specific line number", parseIntStrict).option("-a, --async", "Generate an async workflow", false).option("-p, --preview", "Preview generated code without writing", false).option("--provider <provider>", "LLM provider (openai, anthropic, ollama, mock)").option("--model <model>", "Model identifier (e.g., gpt-4o, claude-3-5-sonnet-20241022)").option("--config <json>", "Configuration as JSON string").option("--name <name>", "Override the derived workflow function name").option("--nodes <names>", 'Comma-separated node function names (e.g., "fetch,parse,store")').option("--input <name>", 'Custom input port name (default: "data")').option("--output <name>", 'Custom output port name (default: "result")').action(wrapAction(async (template, file, options) => {
96044
96036
  const { createWorkflowCommand: createWorkflowCommand2 } = await Promise.resolve().then(() => (init_create(), create_exports));
96045
96037
  await createWorkflowCommand2(template, file, options);
96046
96038
  }));
96047
- createCmd.command("node <name> <file>").description("Create a node type from a template").option("-l, --line <number>", "Insert at specific line number", parseInt).option("-t, --template <template>", "Node template to use", "transformer").option("-p, --preview", "Preview generated code without writing", false).option("--strategy <strategy>", "Template strategy (e.g. mock, callback, webhook)").option("--config <json>", "Additional configuration (JSON)").action(wrapAction(async (name, file, options) => {
96039
+ createCmd.command("node <name> <file>").description("Create a node type from a template").option("-l, --line <number>", "Insert at specific line number", parseIntStrict).option("-t, --template <template>", "Node template to use", "transformer").option("-p, --preview", "Preview generated code without writing", false).option("--strategy <strategy>", "Template strategy (e.g. mock, callback, webhook)").option("--config <json>", "Additional configuration (JSON)").action(wrapAction(async (name, file, options) => {
96048
96040
  const { createNodeCommand: createNodeCommand2 } = await Promise.resolve().then(() => (init_create(), create_exports));
96049
96041
  await createNodeCommand2(name, file, options);
96050
96042
  }));
@@ -96100,14 +96092,14 @@ patternCmd.command("extract <source-file>").description("Extract a pattern from
96100
96092
  const { patternExtractCommand: patternExtractCommand2 } = await Promise.resolve().then(() => (init_pattern2(), pattern_exports));
96101
96093
  await patternExtractCommand2(sourceFile, options);
96102
96094
  }));
96103
- program2.command("run <input>").description("Execute a workflow file directly").option("-w, --workflow <name>", "Specific workflow name to run").option("--params <json>", "Input parameters as JSON string").option("--params-file <path>", "Path to JSON file with input parameters").option("-p, --production", "Production mode (no trace events)", false).option("-t, --trace", "Include execution trace events").option("-s, --stream", "Stream trace events in real-time").option("--json", "Output result as JSON", false).option("--timeout <ms>", "Execution timeout in milliseconds", parseInt).option("--mocks <json>", "Mock config for built-in nodes (events, invocations, agents, fast) as JSON").option("--mocks-file <path>", "Path to JSON file with mock config for built-in nodes").option("-d, --debug", "Start in step-through debug mode").option("--checkpoint", "Enable checkpointing to disk after each node").option("--resume [file]", "Resume from a checkpoint file (auto-detects latest if no file)").option("-b, --breakpoint <nodeIds...>", "Set initial breakpoints (repeatable)").action(wrapAction(async (input, options) => {
96095
+ program2.command("run <input>").description("Execute a workflow file directly").option("-w, --workflow <name>", "Specific workflow name to run").option("--params <json>", "Input parameters as JSON string").option("--params-file <path>", "Path to JSON file with input parameters").option("-p, --production", "Production mode (no trace events)", false).option("-t, --trace", "Include execution trace events").option("-s, --stream", "Stream trace events in real-time").option("--json", "Output result as JSON", false).option("--timeout <ms>", "Execution timeout in milliseconds", parseIntStrict).option("--mocks <json>", "Mock config for built-in nodes (events, invocations, agents, fast) as JSON").option("--mocks-file <path>", "Path to JSON file with mock config for built-in nodes").option("-d, --debug", "Start in step-through debug mode").option("--checkpoint", "Enable checkpointing to disk after each node").option("--resume [file]", "Resume from a checkpoint file (auto-detects latest if no file)").option("-b, --breakpoint <nodeIds...>", "Set initial breakpoints (repeatable)").action(wrapAction(async (input, options) => {
96104
96096
  const { runCommand: runCommand3 } = await Promise.resolve().then(() => (init_run(), run_exports));
96105
96097
  await runCommand3(input, options);
96106
96098
  }));
96107
96099
  program2.command("serve [directory]").description("Start HTTP server exposing workflows as endpoints").option("-p, --port <port>", "Server port", "3000").option("-H, --host <host>", "Server host", "0.0.0.0").option("--no-watch", "Disable file watching for hot reload").option("--production", "Production mode (no trace events)", false).option("--precompile", "Precompile all workflows on startup", false).option("--cors <origin>", "CORS origin", "*").option("--swagger", "Enable Swagger UI at /docs", false).action(wrapAction(async (directory, options) => {
96108
96100
  const { serveCommand: serveCommand2 } = await Promise.resolve().then(() => (init_serve(), serve_exports));
96109
96101
  await serveCommand2(directory, {
96110
- port: parseInt(options.port, 10),
96102
+ port: parseIntStrict(options.port),
96111
96103
  host: options.host,
96112
96104
  watch: options.watch,
96113
96105
  production: options.production,
@@ -96116,7 +96108,7 @@ program2.command("serve [directory]").description("Start HTTP server exposing wo
96116
96108
  swagger: options.swagger
96117
96109
  });
96118
96110
  }));
96119
- program2.command("export <input>").description("Export workflow as serverless function").requiredOption("-t, --target <target>", "Target platform (install target packs via marketplace)").requiredOption("-o, --output <path>", "Output directory").option("-w, --workflow <name>", "Specific workflow name to export").option("-p, --production", "Production mode", true).option("--dry-run", "Preview without writing files", false).option("--multi", "Export all workflows in file as a single multi-workflow service", false).option("--workflows <names>", "Comma-separated list of workflows to export (used with --multi)").option("--docs", "Include API documentation routes (/docs and /openapi.json)", false).option("--durable-steps", "Use deep generator with per-node durable steps", false).action(wrapAction(async (input, options) => {
96111
+ program2.command("export <input>").description("Export workflow as serverless function").requiredOption("-t, --target <target>", "Target platform (install target packs via marketplace)").requiredOption("-o, --output <path>", "Output directory").option("-w, --workflow <name>", "Specific workflow name to export").option("-p, --production", "Production mode (no debug events)", false).option("--bundle", "Bundle node types into the output", false).option("--dry-run", "Preview without writing files", false).option("--multi", "Export all workflows in file as a single multi-workflow service", false).option("--workflows <names>", "Comma-separated list of workflows to export (used with --multi)").option("--docs", "Include API documentation routes (/docs and /openapi.json)", false).option("--durable-steps", "Use deep generator with per-node durable steps", false).action(wrapAction(async (input, options) => {
96120
96112
  const { exportCommand: exportCommand2 } = await Promise.resolve().then(() => (init_export2(), export_exports));
96121
96113
  await exportCommand2(input, options);
96122
96114
  }));
@@ -96189,7 +96181,7 @@ marketCmd.command("install <package>").description("Install a marketplace packag
96189
96181
  }));
96190
96182
  marketCmd.command("search [query]").description("Search npm for marketplace packages").option("-l, --limit <number>", "Max results", "20").option("-r, --registry <url>", "Custom registry search URL (e.g., private npm registry)").option("--json", "Output as JSON", false).action(wrapAction(async (query, options) => {
96191
96183
  const { marketSearchCommand: marketSearchCommand2 } = await Promise.resolve().then(() => (init_market(), market_exports));
96192
- await marketSearchCommand2(query, { ...options, limit: parseInt(options.limit, 10) });
96184
+ await marketSearchCommand2(query, { ...options, limit: parseIntStrict(options.limit) });
96193
96185
  }));
96194
96186
  marketCmd.command("list").description("List installed marketplace packages").option("--json", "Output as JSON", false).action(wrapAction(async (options) => {
96195
96187
  const { marketListCommand: marketListCommand2 } = await Promise.resolve().then(() => (init_market(), market_exports));
@@ -96252,7 +96244,7 @@ if (!process.env["VITEST"]) {
96252
96244
  });
96253
96245
  program2.command("connect [dir]").description("Connect this device to the Flow Weaver platform").action(async (dir) => {
96254
96246
  const { handleConnect: handleConnect2 } = await Promise.resolve().then(() => (init_connect(), connect_exports));
96255
- await handleConnect2(path53.resolve(dir ?? "."));
96247
+ await handleConnect2(path54.resolve(dir ?? "."));
96256
96248
  });
96257
96249
  if (!program2.commands.some((c) => c.name() === "weaver")) {
96258
96250
  program2.command("weaver").description("AI assistant for Flow Weaver workflows").allowUnknownOption(true).action(async () => {