@floless/app 0.55.0 → 0.57.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.
@@ -5489,7 +5489,7 @@ var require_thread_stream = __commonJS({
5489
5489
  var { version } = require_package();
5490
5490
  var { EventEmitter: EventEmitter2 } = require("events");
5491
5491
  var { Worker: Worker2 } = require("worker_threads");
5492
- var { join: join29 } = require("path");
5492
+ var { join: join30 } = require("path");
5493
5493
  var { pathToFileURL } = require("url");
5494
5494
  var { wait } = require_wait();
5495
5495
  var {
@@ -5540,7 +5540,7 @@ var require_thread_stream = __commonJS({
5540
5540
  function createWorker(stream, opts) {
5541
5541
  const { filename, workerData } = opts;
5542
5542
  const bundlerOverrides = "__bundlerPathsOverrides" in globalThis ? globalThis.__bundlerPathsOverrides : {};
5543
- const toExecute = bundlerOverrides["thread-stream-worker"] || join29(__dirname, "lib", "worker.js");
5543
+ const toExecute = bundlerOverrides["thread-stream-worker"] || join30(__dirname, "lib", "worker.js");
5544
5544
  const worker = new Worker2(toExecute, {
5545
5545
  ...opts.workerOpts,
5546
5546
  name: opts.workerOpts?.name || "thread-stream",
@@ -6006,9 +6006,9 @@ var require_transport = __commonJS({
6006
6006
  "node_modules/pino/lib/transport.js"(exports2, module2) {
6007
6007
  "use strict";
6008
6008
  var { createRequire: createRequire5 } = require("module");
6009
- var { existsSync: existsSync24 } = require("node:fs");
6009
+ var { existsSync: existsSync25 } = require("node:fs");
6010
6010
  var getCallers = require_caller();
6011
- var { join: join29, isAbsolute: isAbsolute2, sep: sep4 } = require("node:path");
6011
+ var { join: join30, isAbsolute: isAbsolute2, sep: sep4 } = require("node:path");
6012
6012
  var { fileURLToPath: fileURLToPath6 } = require("node:url");
6013
6013
  var sleep = require_atomic_sleep();
6014
6014
  var onExit = require_on_exit_leak_free();
@@ -6080,7 +6080,7 @@ var require_transport = __commonJS({
6080
6080
  return false;
6081
6081
  }
6082
6082
  }
6083
- return isAbsolute2(path) && !existsSync24(path);
6083
+ return isAbsolute2(path) && !existsSync25(path);
6084
6084
  }
6085
6085
  function stripQuotes(value) {
6086
6086
  const first = value[0];
@@ -6161,7 +6161,7 @@ var require_transport = __commonJS({
6161
6161
  throw new Error("only one of target or targets can be specified");
6162
6162
  }
6163
6163
  if (targets) {
6164
- target = bundlerOverrides["pino-worker"] || join29(__dirname, "worker.js");
6164
+ target = bundlerOverrides["pino-worker"] || join30(__dirname, "worker.js");
6165
6165
  options.targets = targets.filter((dest) => dest.target).map((dest) => {
6166
6166
  return {
6167
6167
  ...dest,
@@ -6179,7 +6179,7 @@ var require_transport = __commonJS({
6179
6179
  });
6180
6180
  });
6181
6181
  } else if (pipeline2) {
6182
- target = bundlerOverrides["pino-worker"] || join29(__dirname, "worker.js");
6182
+ target = bundlerOverrides["pino-worker"] || join30(__dirname, "worker.js");
6183
6183
  options.pipelines = [pipeline2.map((dest) => {
6184
6184
  return {
6185
6185
  ...dest,
@@ -6202,7 +6202,7 @@ var require_transport = __commonJS({
6202
6202
  return origin;
6203
6203
  }
6204
6204
  if (origin === "pino/file") {
6205
- return join29(__dirname, "..", "file.js");
6205
+ return join30(__dirname, "..", "file.js");
6206
6206
  }
6207
6207
  let fixTarget2;
6208
6208
  for (const filePath of callers) {
@@ -6317,14 +6317,14 @@ var require_tools = __commonJS({
6317
6317
  }
6318
6318
  return point < 32 ? JSON.stringify(str) : '"' + result + '"';
6319
6319
  }
6320
- function asJson(obj, msg, num, time) {
6320
+ function asJson(obj, msg, num2, time) {
6321
6321
  if (asJsonChan.hasSubscribers === false) {
6322
- return _asJson.call(this, obj, msg, num, time);
6322
+ return _asJson.call(this, obj, msg, num2, time);
6323
6323
  }
6324
6324
  const store = { instance: this, arguments };
6325
- return asJsonChan.traceSync(_asJson, store, this, obj, msg, num, time);
6325
+ return asJsonChan.traceSync(_asJson, store, this, obj, msg, num2, time);
6326
6326
  }
6327
- function _asJson(obj, msg, num, time) {
6327
+ function _asJson(obj, msg, num2, time) {
6328
6328
  const stringify2 = this[stringifySym];
6329
6329
  const stringifySafe = this[stringifySafeSym];
6330
6330
  const stringifiers = this[stringifiersSym];
@@ -6334,7 +6334,7 @@ var require_tools = __commonJS({
6334
6334
  const formatters = this[formattersSym];
6335
6335
  const messageKey = this[messageKeySym];
6336
6336
  const errorKey = this[errorKeySym];
6337
- let data = this[lsCacheSym][num] + time;
6337
+ let data = this[lsCacheSym][num2] + time;
6338
6338
  data = data + chindings;
6339
6339
  let value;
6340
6340
  if (formatters.log) {
@@ -6959,7 +6959,7 @@ var require_proto = __commonJS({
6959
6959
  function defaultMixinMergeStrategy(mergeObject, mixinObject) {
6960
6960
  return Object.assign(mixinObject, mergeObject);
6961
6961
  }
6962
- function write(_obj, msg, num) {
6962
+ function write(_obj, msg, num2) {
6963
6963
  const t = this[timeSym]();
6964
6964
  const mixin = this[mixinSym];
6965
6965
  const errorKey = this[errorKeySym];
@@ -6981,12 +6981,12 @@ var require_proto = __commonJS({
6981
6981
  }
6982
6982
  }
6983
6983
  if (mixin) {
6984
- obj = mixinMergeStrategy(obj, mixin(obj, num, this));
6984
+ obj = mixinMergeStrategy(obj, mixin(obj, num2, this));
6985
6985
  }
6986
- const s = this[asJsonSym](obj, msg, num, t);
6986
+ const s = this[asJsonSym](obj, msg, num2, t);
6987
6987
  const stream = this[streamSym];
6988
6988
  if (stream[needsMetadataGsym] === true) {
6989
- stream.lastLevel = num;
6989
+ stream.lastLevel = num2;
6990
6990
  stream.lastObj = obj;
6991
6991
  stream.lastMsg = msg;
6992
6992
  stream.lastTime = t.slice(this[timeSliceIndexSym]);
@@ -7182,7 +7182,7 @@ var require_safe_stable_stringify = __commonJS({
7182
7182
  return circularValue;
7183
7183
  }
7184
7184
  let res = "";
7185
- let join29 = ",";
7185
+ let join30 = ",";
7186
7186
  const originalIndentation = indentation;
7187
7187
  if (Array.isArray(value)) {
7188
7188
  if (value.length === 0) {
@@ -7196,7 +7196,7 @@ var require_safe_stable_stringify = __commonJS({
7196
7196
  indentation += spacer;
7197
7197
  res += `
7198
7198
  ${indentation}`;
7199
- join29 = `,
7199
+ join30 = `,
7200
7200
  ${indentation}`;
7201
7201
  }
7202
7202
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -7204,13 +7204,13 @@ ${indentation}`;
7204
7204
  for (; i < maximumValuesToStringify - 1; i++) {
7205
7205
  const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
7206
7206
  res += tmp2 !== void 0 ? tmp2 : "null";
7207
- res += join29;
7207
+ res += join30;
7208
7208
  }
7209
7209
  const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
7210
7210
  res += tmp !== void 0 ? tmp : "null";
7211
7211
  if (value.length - 1 > maximumBreadth) {
7212
7212
  const removedKeys = value.length - maximumBreadth - 1;
7213
- res += `${join29}"... ${getItemCount(removedKeys)} not stringified"`;
7213
+ res += `${join30}"... ${getItemCount(removedKeys)} not stringified"`;
7214
7214
  }
7215
7215
  if (spacer !== "") {
7216
7216
  res += `
@@ -7231,7 +7231,7 @@ ${originalIndentation}`;
7231
7231
  let separator = "";
7232
7232
  if (spacer !== "") {
7233
7233
  indentation += spacer;
7234
- join29 = `,
7234
+ join30 = `,
7235
7235
  ${indentation}`;
7236
7236
  whitespace = " ";
7237
7237
  }
@@ -7245,13 +7245,13 @@ ${indentation}`;
7245
7245
  const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
7246
7246
  if (tmp !== void 0) {
7247
7247
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
7248
- separator = join29;
7248
+ separator = join30;
7249
7249
  }
7250
7250
  }
7251
7251
  if (keyLength > maximumBreadth) {
7252
7252
  const removedKeys = keyLength - maximumBreadth;
7253
7253
  res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
7254
- separator = join29;
7254
+ separator = join30;
7255
7255
  }
7256
7256
  if (spacer !== "" && separator.length > 1) {
7257
7257
  res = `
@@ -7292,7 +7292,7 @@ ${originalIndentation}`;
7292
7292
  }
7293
7293
  const originalIndentation = indentation;
7294
7294
  let res = "";
7295
- let join29 = ",";
7295
+ let join30 = ",";
7296
7296
  if (Array.isArray(value)) {
7297
7297
  if (value.length === 0) {
7298
7298
  return "[]";
@@ -7305,7 +7305,7 @@ ${originalIndentation}`;
7305
7305
  indentation += spacer;
7306
7306
  res += `
7307
7307
  ${indentation}`;
7308
- join29 = `,
7308
+ join30 = `,
7309
7309
  ${indentation}`;
7310
7310
  }
7311
7311
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -7313,13 +7313,13 @@ ${indentation}`;
7313
7313
  for (; i < maximumValuesToStringify - 1; i++) {
7314
7314
  const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
7315
7315
  res += tmp2 !== void 0 ? tmp2 : "null";
7316
- res += join29;
7316
+ res += join30;
7317
7317
  }
7318
7318
  const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
7319
7319
  res += tmp !== void 0 ? tmp : "null";
7320
7320
  if (value.length - 1 > maximumBreadth) {
7321
7321
  const removedKeys = value.length - maximumBreadth - 1;
7322
- res += `${join29}"... ${getItemCount(removedKeys)} not stringified"`;
7322
+ res += `${join30}"... ${getItemCount(removedKeys)} not stringified"`;
7323
7323
  }
7324
7324
  if (spacer !== "") {
7325
7325
  res += `
@@ -7332,7 +7332,7 @@ ${originalIndentation}`;
7332
7332
  let whitespace = "";
7333
7333
  if (spacer !== "") {
7334
7334
  indentation += spacer;
7335
- join29 = `,
7335
+ join30 = `,
7336
7336
  ${indentation}`;
7337
7337
  whitespace = " ";
7338
7338
  }
@@ -7341,7 +7341,7 @@ ${indentation}`;
7341
7341
  const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
7342
7342
  if (tmp !== void 0) {
7343
7343
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
7344
- separator = join29;
7344
+ separator = join30;
7345
7345
  }
7346
7346
  }
7347
7347
  if (spacer !== "" && separator.length > 1) {
@@ -7399,20 +7399,20 @@ ${originalIndentation}`;
7399
7399
  indentation += spacer;
7400
7400
  let res2 = `
7401
7401
  ${indentation}`;
7402
- const join30 = `,
7402
+ const join31 = `,
7403
7403
  ${indentation}`;
7404
7404
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
7405
7405
  let i = 0;
7406
7406
  for (; i < maximumValuesToStringify - 1; i++) {
7407
7407
  const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
7408
7408
  res2 += tmp2 !== void 0 ? tmp2 : "null";
7409
- res2 += join30;
7409
+ res2 += join31;
7410
7410
  }
7411
7411
  const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
7412
7412
  res2 += tmp !== void 0 ? tmp : "null";
7413
7413
  if (value.length - 1 > maximumBreadth) {
7414
7414
  const removedKeys = value.length - maximumBreadth - 1;
7415
- res2 += `${join30}"... ${getItemCount(removedKeys)} not stringified"`;
7415
+ res2 += `${join31}"... ${getItemCount(removedKeys)} not stringified"`;
7416
7416
  }
7417
7417
  res2 += `
7418
7418
  ${originalIndentation}`;
@@ -7428,16 +7428,16 @@ ${originalIndentation}`;
7428
7428
  return '"[Object]"';
7429
7429
  }
7430
7430
  indentation += spacer;
7431
- const join29 = `,
7431
+ const join30 = `,
7432
7432
  ${indentation}`;
7433
7433
  let res = "";
7434
7434
  let separator = "";
7435
7435
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
7436
7436
  if (isTypedArrayWithEntries(value)) {
7437
- res += stringifyTypedArray(value, join29, maximumBreadth);
7437
+ res += stringifyTypedArray(value, join30, maximumBreadth);
7438
7438
  keys = keys.slice(value.length);
7439
7439
  maximumPropertiesToStringify -= value.length;
7440
- separator = join29;
7440
+ separator = join30;
7441
7441
  }
7442
7442
  if (deterministic) {
7443
7443
  keys = sort(keys, comparator);
@@ -7448,13 +7448,13 @@ ${indentation}`;
7448
7448
  const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
7449
7449
  if (tmp !== void 0) {
7450
7450
  res += `${separator}${strEscape(key2)}: ${tmp}`;
7451
- separator = join29;
7451
+ separator = join30;
7452
7452
  }
7453
7453
  }
7454
7454
  if (keyLength > maximumBreadth) {
7455
7455
  const removedKeys = keyLength - maximumBreadth;
7456
7456
  res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
7457
- separator = join29;
7457
+ separator = join30;
7458
7458
  }
7459
7459
  if (separator !== "") {
7460
7460
  res = `
@@ -8513,13 +8513,13 @@ var require_serializer = __commonJS({
8513
8513
  return "" + integer;
8514
8514
  }
8515
8515
  asNumber(i) {
8516
- const num = Number(i);
8517
- if (num !== num) {
8516
+ const num2 = Number(i);
8517
+ if (num2 !== num2) {
8518
8518
  throw new Error(`The value "${i}" cannot be converted to a number.`);
8519
- } else if (num === Infinity || num === -Infinity) {
8519
+ } else if (num2 === Infinity || num2 === -Infinity) {
8520
8520
  return "null";
8521
8521
  } else {
8522
- return "" + num;
8522
+ return "" + num2;
8523
8523
  }
8524
8524
  }
8525
8525
  asBoolean(bool) {
@@ -10711,17 +10711,17 @@ var require_proxy_addr = __commonJS({
10711
10711
  return len2 === 0 ? trustNone : len2 === 1 ? trustSingle(rangeSubnets[0]) : trustMulti(rangeSubnets);
10712
10712
  }
10713
10713
  function parseipNotation(note) {
10714
- const pos = note.lastIndexOf("/");
10715
- const str = pos !== -1 ? note.substring(0, pos) : note;
10714
+ const pos2 = note.lastIndexOf("/");
10715
+ const str = pos2 !== -1 ? note.substring(0, pos2) : note;
10716
10716
  if (!isip(str)) {
10717
10717
  throw new TypeError("invalid IP address: " + str);
10718
10718
  }
10719
10719
  let ip = parseip(str);
10720
- if (pos === -1 && ip.kind() === "ipv6" && ip.isIPv4MappedAddress()) {
10720
+ if (pos2 === -1 && ip.kind() === "ipv6" && ip.isIPv4MappedAddress()) {
10721
10721
  ip = ip.toIPv4Address();
10722
10722
  }
10723
10723
  const max = ip.kind() === "ipv6" ? 128 : 32;
10724
- let range = pos !== -1 ? note.substring(pos + 1, note.length) : null;
10724
+ let range = pos2 !== -1 ? note.substring(pos2 + 1, note.length) : null;
10725
10725
  if (range === null) {
10726
10726
  range = max;
10727
10727
  } else if (DIGIT_REGEXP.test(range)) {
@@ -17085,15 +17085,15 @@ var require_ucs2length = __commonJS({
17085
17085
  function ucs2length(str) {
17086
17086
  const len2 = str.length;
17087
17087
  let length = 0;
17088
- let pos = 0;
17088
+ let pos2 = 0;
17089
17089
  let value;
17090
- while (pos < len2) {
17090
+ while (pos2 < len2) {
17091
17091
  length++;
17092
- value = str.charCodeAt(pos++);
17093
- if (value >= 55296 && value <= 56319 && pos < len2) {
17094
- value = str.charCodeAt(pos);
17092
+ value = str.charCodeAt(pos2++);
17093
+ if (value >= 55296 && value <= 56319 && pos2 < len2) {
17094
+ value = str.charCodeAt(pos2);
17095
17095
  if ((value & 64512) === 56320)
17096
- pos++;
17096
+ pos2++;
17097
17097
  }
17098
17098
  }
17099
17099
  return length;
@@ -19981,14 +19981,14 @@ var require_parseJson = __commonJS({
19981
19981
  Object.defineProperty(exports2, "__esModule", { value: true });
19982
19982
  exports2.parseJsonString = exports2.parseJsonNumber = exports2.parseJson = void 0;
19983
19983
  var rxParseJson = /position\s(\d+)(?: \(line \d+ column \d+\))?$/;
19984
- function parseJson(s, pos) {
19984
+ function parseJson(s, pos2) {
19985
19985
  let endPos;
19986
19986
  parseJson.message = void 0;
19987
19987
  let matches;
19988
- if (pos)
19989
- s = s.slice(pos);
19988
+ if (pos2)
19989
+ s = s.slice(pos2);
19990
19990
  try {
19991
- parseJson.position = pos + s.length;
19991
+ parseJson.position = pos2 + s.length;
19992
19992
  return JSON.parse(s);
19993
19993
  } catch (e) {
19994
19994
  matches = rxParseJson.exec(e.message);
@@ -19999,7 +19999,7 @@ var require_parseJson = __commonJS({
19999
19999
  endPos = +matches[1];
20000
20000
  const c = s[endPos];
20001
20001
  s = s.slice(0, endPos);
20002
- parseJson.position = pos + endPos;
20002
+ parseJson.position = pos2 + endPos;
20003
20003
  try {
20004
20004
  return JSON.parse(s);
20005
20005
  } catch (e1) {
@@ -20012,17 +20012,17 @@ var require_parseJson = __commonJS({
20012
20012
  parseJson.message = void 0;
20013
20013
  parseJson.position = 0;
20014
20014
  parseJson.code = 'require("ajv/dist/runtime/parseJson").parseJson';
20015
- function parseJsonNumber(s, pos, maxDigits) {
20015
+ function parseJsonNumber(s, pos2, maxDigits) {
20016
20016
  let numStr = "";
20017
20017
  let c;
20018
20018
  parseJsonNumber.message = void 0;
20019
- if (s[pos] === "-") {
20019
+ if (s[pos2] === "-") {
20020
20020
  numStr += "-";
20021
- pos++;
20021
+ pos2++;
20022
20022
  }
20023
- if (s[pos] === "0") {
20023
+ if (s[pos2] === "0") {
20024
20024
  numStr += "0";
20025
- pos++;
20025
+ pos2++;
20026
20026
  } else {
20027
20027
  if (!parseDigits(maxDigits)) {
20028
20028
  errorMessage();
@@ -20030,43 +20030,43 @@ var require_parseJson = __commonJS({
20030
20030
  }
20031
20031
  }
20032
20032
  if (maxDigits) {
20033
- parseJsonNumber.position = pos;
20033
+ parseJsonNumber.position = pos2;
20034
20034
  return +numStr;
20035
20035
  }
20036
- if (s[pos] === ".") {
20036
+ if (s[pos2] === ".") {
20037
20037
  numStr += ".";
20038
- pos++;
20038
+ pos2++;
20039
20039
  if (!parseDigits()) {
20040
20040
  errorMessage();
20041
20041
  return void 0;
20042
20042
  }
20043
20043
  }
20044
- if (c = s[pos], c === "e" || c === "E") {
20044
+ if (c = s[pos2], c === "e" || c === "E") {
20045
20045
  numStr += "e";
20046
- pos++;
20047
- if (c = s[pos], c === "+" || c === "-") {
20046
+ pos2++;
20047
+ if (c = s[pos2], c === "+" || c === "-") {
20048
20048
  numStr += c;
20049
- pos++;
20049
+ pos2++;
20050
20050
  }
20051
20051
  if (!parseDigits()) {
20052
20052
  errorMessage();
20053
20053
  return void 0;
20054
20054
  }
20055
20055
  }
20056
- parseJsonNumber.position = pos;
20056
+ parseJsonNumber.position = pos2;
20057
20057
  return +numStr;
20058
20058
  function parseDigits(maxLen) {
20059
20059
  let digit = false;
20060
- while (c = s[pos], c >= "0" && c <= "9" && (maxLen === void 0 || maxLen-- > 0)) {
20060
+ while (c = s[pos2], c >= "0" && c <= "9" && (maxLen === void 0 || maxLen-- > 0)) {
20061
20061
  digit = true;
20062
20062
  numStr += c;
20063
- pos++;
20063
+ pos2++;
20064
20064
  }
20065
20065
  return digit;
20066
20066
  }
20067
20067
  function errorMessage() {
20068
- parseJsonNumber.position = pos;
20069
- parseJsonNumber.message = pos < s.length ? `unexpected token ${s[pos]}` : "unexpected end";
20068
+ parseJsonNumber.position = pos2;
20069
+ parseJsonNumber.message = pos2 < s.length ? `unexpected token ${s[pos2]}` : "unexpected end";
20070
20070
  }
20071
20071
  }
20072
20072
  exports2.parseJsonNumber = parseJsonNumber;
@@ -20085,26 +20085,26 @@ var require_parseJson = __commonJS({
20085
20085
  };
20086
20086
  var CODE_A = "a".charCodeAt(0);
20087
20087
  var CODE_0 = "0".charCodeAt(0);
20088
- function parseJsonString(s, pos) {
20088
+ function parseJsonString(s, pos2) {
20089
20089
  let str = "";
20090
20090
  let c;
20091
20091
  parseJsonString.message = void 0;
20092
20092
  while (true) {
20093
- c = s[pos++];
20093
+ c = s[pos2++];
20094
20094
  if (c === '"')
20095
20095
  break;
20096
20096
  if (c === "\\") {
20097
- c = s[pos];
20097
+ c = s[pos2];
20098
20098
  if (c in escapedChars) {
20099
20099
  str += escapedChars[c];
20100
- pos++;
20100
+ pos2++;
20101
20101
  } else if (c === "u") {
20102
- pos++;
20102
+ pos2++;
20103
20103
  let count = 4;
20104
20104
  let code = 0;
20105
20105
  while (count--) {
20106
20106
  code <<= 4;
20107
- c = s[pos];
20107
+ c = s[pos2];
20108
20108
  if (c === void 0) {
20109
20109
  errorMessage("unexpected end");
20110
20110
  return void 0;
@@ -20118,7 +20118,7 @@ var require_parseJson = __commonJS({
20118
20118
  errorMessage(`unexpected token ${c}`);
20119
20119
  return void 0;
20120
20120
  }
20121
- pos++;
20121
+ pos2++;
20122
20122
  }
20123
20123
  str += String.fromCharCode(code);
20124
20124
  } else {
@@ -20137,10 +20137,10 @@ var require_parseJson = __commonJS({
20137
20137
  }
20138
20138
  }
20139
20139
  }
20140
- parseJsonString.position = pos;
20140
+ parseJsonString.position = pos2;
20141
20141
  return str;
20142
20142
  function errorMessage(msg) {
20143
- parseJsonString.position = pos;
20143
+ parseJsonString.position = pos2;
20144
20144
  parseJsonString.message = msg;
20145
20145
  }
20146
20146
  }
@@ -24673,9 +24673,9 @@ var require_semver = __commonJS({
24673
24673
  } else {
24674
24674
  this.prerelease = m[4].split(".").map((id) => {
24675
24675
  if (/^[0-9]+$/.test(id)) {
24676
- const num = +id;
24677
- if (num >= 0 && num < MAX_SAFE_INTEGER) {
24678
- return num;
24676
+ const num2 = +id;
24677
+ if (num2 >= 0 && num2 < MAX_SAFE_INTEGER) {
24678
+ return num2;
24679
24679
  }
24680
24680
  }
24681
24681
  return id;
@@ -25041,8 +25041,8 @@ var require_patch = __commonJS({
25041
25041
  "node_modules/semver/functions/patch.js"(exports2, module2) {
25042
25042
  "use strict";
25043
25043
  var SemVer = require_semver();
25044
- var patch = (a, loose) => new SemVer(a, loose).patch;
25045
- module2.exports = patch;
25044
+ var patch2 = (a, loose) => new SemVer(a, loose).patch;
25045
+ module2.exports = patch2;
25046
25046
  }
25047
25047
  });
25048
25048
 
@@ -25270,10 +25270,10 @@ var require_coerce = __commonJS({
25270
25270
  }
25271
25271
  const major = match[2];
25272
25272
  const minor = match[3] || "0";
25273
- const patch = match[4] || "0";
25273
+ const patch2 = match[4] || "0";
25274
25274
  const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "";
25275
25275
  const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
25276
- return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options);
25276
+ return parse(`${major}.${minor}.${patch2}${prerelease}${build}`, options);
25277
25277
  };
25278
25278
  module2.exports = coerce;
25279
25279
  }
@@ -26338,7 +26338,7 @@ var require_semver2 = __commonJS({
26338
26338
  var diff = require_diff();
26339
26339
  var major = require_major();
26340
26340
  var minor = require_minor();
26341
- var patch = require_patch();
26341
+ var patch2 = require_patch();
26342
26342
  var prerelease = require_prerelease();
26343
26343
  var compare = require_compare();
26344
26344
  var rcompare = require_rcompare();
@@ -26377,7 +26377,7 @@ var require_semver2 = __commonJS({
26377
26377
  diff,
26378
26378
  major,
26379
26379
  minor,
26380
- patch,
26380
+ patch: patch2,
26381
26381
  prerelease,
26382
26382
  compare,
26383
26383
  rcompare,
@@ -28698,13 +28698,13 @@ var require_accept_version = __commonJS({
28698
28698
  if (typeof version !== "string") {
28699
28699
  throw new TypeError("Version should be a string");
28700
28700
  }
28701
- let [major, minor, patch] = version.split(".", 3);
28701
+ let [major, minor, patch2] = version.split(".", 3);
28702
28702
  if (isNaN(major)) {
28703
28703
  throw new TypeError("Major version must be a numeric value");
28704
28704
  }
28705
28705
  major = Number(major);
28706
28706
  minor = Number(minor) || 0;
28707
- patch = Number(patch) || 0;
28707
+ patch2 = Number(patch2) || 0;
28708
28708
  if (major >= this.maxMajor) {
28709
28709
  this.maxMajor = major;
28710
28710
  this.store.set("x", store);
@@ -28717,11 +28717,11 @@ var require_accept_version = __commonJS({
28717
28717
  this.store.set(`${major}.x`, store);
28718
28718
  this.store.set(`${major}.x.x`, store);
28719
28719
  }
28720
- if (patch >= (this.maxPatches[`${major}.${minor}`] || 0)) {
28721
- this.maxPatches[`${major}.${minor}`] = patch;
28720
+ if (patch2 >= (this.maxPatches[`${major}.${minor}`] || 0)) {
28721
+ this.maxPatches[`${major}.${minor}`] = patch2;
28722
28722
  this.store.set(`${major}.${minor}.x`, store);
28723
28723
  }
28724
- this.store.set(`${major}.${minor}.${patch}`, store);
28724
+ this.store.set(`${major}.${minor}.${patch2}`, store);
28725
28725
  return this;
28726
28726
  };
28727
28727
  SemVerStore.prototype.get = function(version) {
@@ -32432,48 +32432,48 @@ var require_set_cookie = __commonJS({
32432
32432
  return [];
32433
32433
  }
32434
32434
  var cookiesStrings = [];
32435
- var pos = 0;
32435
+ var pos2 = 0;
32436
32436
  var start;
32437
32437
  var ch2;
32438
32438
  var lastComma;
32439
32439
  var nextStart;
32440
32440
  var cookiesSeparatorFound;
32441
32441
  function skipWhitespace() {
32442
- while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
32443
- pos += 1;
32442
+ while (pos2 < cookiesString.length && /\s/.test(cookiesString.charAt(pos2))) {
32443
+ pos2 += 1;
32444
32444
  }
32445
- return pos < cookiesString.length;
32445
+ return pos2 < cookiesString.length;
32446
32446
  }
32447
32447
  function notSpecialChar() {
32448
- ch2 = cookiesString.charAt(pos);
32448
+ ch2 = cookiesString.charAt(pos2);
32449
32449
  return ch2 !== "=" && ch2 !== ";" && ch2 !== ",";
32450
32450
  }
32451
- while (pos < cookiesString.length) {
32452
- start = pos;
32451
+ while (pos2 < cookiesString.length) {
32452
+ start = pos2;
32453
32453
  cookiesSeparatorFound = false;
32454
32454
  while (skipWhitespace()) {
32455
- ch2 = cookiesString.charAt(pos);
32455
+ ch2 = cookiesString.charAt(pos2);
32456
32456
  if (ch2 === ",") {
32457
- lastComma = pos;
32458
- pos += 1;
32457
+ lastComma = pos2;
32458
+ pos2 += 1;
32459
32459
  skipWhitespace();
32460
- nextStart = pos;
32461
- while (pos < cookiesString.length && notSpecialChar()) {
32462
- pos += 1;
32460
+ nextStart = pos2;
32461
+ while (pos2 < cookiesString.length && notSpecialChar()) {
32462
+ pos2 += 1;
32463
32463
  }
32464
- if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
32464
+ if (pos2 < cookiesString.length && cookiesString.charAt(pos2) === "=") {
32465
32465
  cookiesSeparatorFound = true;
32466
- pos = nextStart;
32466
+ pos2 = nextStart;
32467
32467
  cookiesStrings.push(cookiesString.substring(start, lastComma));
32468
- start = pos;
32468
+ start = pos2;
32469
32469
  } else {
32470
- pos = lastComma + 1;
32470
+ pos2 = lastComma + 1;
32471
32471
  }
32472
32472
  } else {
32473
- pos += 1;
32473
+ pos2 += 1;
32474
32474
  }
32475
32475
  }
32476
- if (!cookiesSeparatorFound || pos >= cookiesString.length) {
32476
+ if (!cookiesSeparatorFound || pos2 >= cookiesString.length) {
32477
32477
  cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
32478
32478
  }
32479
32479
  }
@@ -34746,22 +34746,22 @@ var require_brace_expressions = __commonJS({
34746
34746
  var regexpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
34747
34747
  var rangesToString = (ranges) => ranges.join("");
34748
34748
  var parseClass = (glob, position) => {
34749
- const pos = position;
34750
- if (glob.charAt(pos) !== "[") {
34749
+ const pos2 = position;
34750
+ if (glob.charAt(pos2) !== "[") {
34751
34751
  throw new Error("not in a brace expression");
34752
34752
  }
34753
34753
  const ranges = [];
34754
34754
  const negs = [];
34755
- let i = pos + 1;
34755
+ let i = pos2 + 1;
34756
34756
  let sawStart = false;
34757
34757
  let uflag = false;
34758
34758
  let escaping = false;
34759
34759
  let negate = false;
34760
- let endPos = pos;
34760
+ let endPos = pos2;
34761
34761
  let rangeStart = "";
34762
34762
  WHILE: while (i < glob.length) {
34763
34763
  const c = glob.charAt(i);
34764
- if ((c === "!" || c === "^") && i === pos + 1) {
34764
+ if ((c === "!" || c === "^") && i === pos2 + 1) {
34765
34765
  negate = true;
34766
34766
  i++;
34767
34767
  continue;
@@ -34782,7 +34782,7 @@ var require_brace_expressions = __commonJS({
34782
34782
  for (const [cls, [unip, u, neg]] of Object.entries(posixClasses)) {
34783
34783
  if (glob.startsWith(cls, i)) {
34784
34784
  if (rangeStart) {
34785
- return ["$.", false, glob.length - pos, true];
34785
+ return ["$.", false, glob.length - pos2, true];
34786
34786
  }
34787
34787
  i += cls.length;
34788
34788
  if (neg)
@@ -34822,16 +34822,16 @@ var require_brace_expressions = __commonJS({
34822
34822
  return ["", false, 0, false];
34823
34823
  }
34824
34824
  if (!ranges.length && !negs.length) {
34825
- return ["$.", false, glob.length - pos, true];
34825
+ return ["$.", false, glob.length - pos2, true];
34826
34826
  }
34827
34827
  if (negs.length === 0 && ranges.length === 1 && /^\\?.$/.test(ranges[0]) && !negate) {
34828
34828
  const r = ranges[0].length === 2 ? ranges[0].slice(-1) : ranges[0];
34829
- return [regexpEscape(r), false, endPos - pos, false];
34829
+ return [regexpEscape(r), false, endPos - pos2, false];
34830
34830
  }
34831
34831
  const sranges = "[" + (negate ? "^" : "") + rangesToString(ranges) + "]";
34832
34832
  const snegs = "[" + (negate ? "" : "^") + rangesToString(negs) + "]";
34833
34833
  const comb = ranges.length && negs.length ? "(" + sranges + "|" + snegs + ")" : ranges.length ? sranges : snegs;
34834
- return [comb, uflag, endPos - pos, true];
34834
+ return [comb, uflag, endPos - pos2, true];
34835
34835
  };
34836
34836
  exports2.parseClass = parseClass;
34837
34837
  }
@@ -35067,14 +35067,14 @@ var require_ast = __commonJS({
35067
35067
  }
35068
35068
  return c;
35069
35069
  }
35070
- static #parseAST(str, ast, pos, opt, extDepth) {
35070
+ static #parseAST(str, ast, pos2, opt, extDepth) {
35071
35071
  const maxDepth = opt.maxExtglobRecursion ?? 2;
35072
35072
  let escaping = false;
35073
35073
  let inBrace = false;
35074
35074
  let braceStart = -1;
35075
35075
  let braceNeg = false;
35076
35076
  if (ast.type === null) {
35077
- let i2 = pos;
35077
+ let i2 = pos2;
35078
35078
  let acc2 = "";
35079
35079
  while (i2 < str.length) {
35080
35080
  const c = str.charAt(i2++);
@@ -35114,7 +35114,7 @@ var require_ast = __commonJS({
35114
35114
  ast.push(acc2);
35115
35115
  return i2;
35116
35116
  }
35117
- let i = pos + 1;
35117
+ let i = pos2 + 1;
35118
35118
  let part = new _a2(null, ast);
35119
35119
  const parts = [];
35120
35120
  let acc = "";
@@ -35173,7 +35173,7 @@ var require_ast = __commonJS({
35173
35173
  }
35174
35174
  ast.type = null;
35175
35175
  ast.#hasMagic = void 0;
35176
- ast.#parts = [str.substring(pos - 1)];
35176
+ ast.#parts = [str.substring(pos2 - 1)];
35177
35177
  return i;
35178
35178
  }
35179
35179
  #canAdoptWithSpace(child) {
@@ -41036,24 +41036,24 @@ var require_dist5 = __commonJS({
41036
41036
  var DAY = HOUR * 24;
41037
41037
  var YEAR = DAY * 365.25;
41038
41038
  function parse(val) {
41039
- var num, arr = val.toLowerCase().match(RGX);
41040
- if (arr != null && (num = parseFloat(arr[1]))) {
41041
- if (arr[3] != null) return num * SEC;
41042
- if (arr[4] != null) return num * MIN;
41043
- if (arr[5] != null) return num * HOUR;
41044
- if (arr[6] != null) return num * DAY;
41045
- if (arr[7] != null) return num * DAY * 7;
41046
- if (arr[8] != null) return num * YEAR;
41047
- return num;
41039
+ var num2, arr = val.toLowerCase().match(RGX);
41040
+ if (arr != null && (num2 = parseFloat(arr[1]))) {
41041
+ if (arr[3] != null) return num2 * SEC;
41042
+ if (arr[4] != null) return num2 * MIN;
41043
+ if (arr[5] != null) return num2 * HOUR;
41044
+ if (arr[6] != null) return num2 * DAY;
41045
+ if (arr[7] != null) return num2 * DAY * 7;
41046
+ if (arr[8] != null) return num2 * YEAR;
41047
+ return num2;
41048
41048
  }
41049
41049
  }
41050
41050
  function fmt(val, pfx, str, long) {
41051
- var num = (val | 0) === val ? val : ~~(val + 0.5);
41052
- return pfx + num + (long ? " " + str + (num != 1 ? "s" : "") : str[0]);
41051
+ var num2 = (val | 0) === val ? val : ~~(val + 0.5);
41052
+ return pfx + num2 + (long ? " " + str + (num2 != 1 ? "s" : "") : str[0]);
41053
41053
  }
41054
- function format(num, long) {
41055
- var pfx = num < 0 ? "-" : "", abs = num < 0 ? -num : num;
41056
- if (abs < SEC) return num + (long ? " ms" : "ms");
41054
+ function format(num2, long) {
41055
+ var pfx = num2 < 0 ? "-" : "", abs = num2 < 0 ? -num2 : num2;
41056
+ if (abs < SEC) return num2 + (long ? " ms" : "ms");
41057
41057
  if (abs < MIN) return fmt(abs / SEC, pfx, "second", long);
41058
41058
  if (abs < HOUR) return fmt(abs / MIN, pfx, "minute", long);
41059
41059
  if (abs < DAY) return fmt(abs / HOUR, pfx, "hour", long);
@@ -41991,7 +41991,7 @@ var require_send = __commonJS({
41991
41991
  var { parseTokenList } = require_parseTokenList();
41992
41992
  var { createHttpError } = require_createHttpError();
41993
41993
  var extname2 = path.extname;
41994
- var join29 = path.join;
41994
+ var join30 = path.join;
41995
41995
  var normalize2 = path.normalize;
41996
41996
  var resolve6 = path.resolve;
41997
41997
  var sep4 = path.sep;
@@ -42078,7 +42078,7 @@ var require_send = __commonJS({
42078
42078
  return { statusCode: 403 };
42079
42079
  }
42080
42080
  parts = path2.split(sep4);
42081
- path2 = normalize2(join29(root, path2));
42081
+ path2 = normalize2(join30(root, path2));
42082
42082
  } else {
42083
42083
  if (UP_PATH_REGEXP.test(path2)) {
42084
42084
  debug('malicious path "%s"', path2);
@@ -42361,7 +42361,7 @@ var require_send = __commonJS({
42361
42361
  let err2;
42362
42362
  for (let i = 0; i < options.index.length; i++) {
42363
42363
  const index = options.index[i];
42364
- const p = join29(path2, index);
42364
+ const p = join30(path2, index);
42365
42365
  const { error, stat: stat4 } = await tryStat(p);
42366
42366
  if (error) {
42367
42367
  err2 = error;
@@ -43145,8 +43145,8 @@ var require_static = __commonJS({
43145
43145
  }
43146
43146
  }
43147
43147
  }
43148
- for (const [dirname12, rootPath] of indexDirs.entries()) {
43149
- const pathname = dirname12 + (dirname12.endsWith("/") ? "" : "/");
43148
+ for (const [dirname13, rootPath] of indexDirs.entries()) {
43149
+ const pathname = dirname13 + (dirname13.endsWith("/") ? "" : "/");
43150
43150
  const file = "/" + pathname.replace(prefix, "");
43151
43151
  setUpHeadAndGet(routeOpts, pathname, file, rootPath);
43152
43152
  if (opts.redirect === true) {
@@ -45784,9 +45784,9 @@ var require_stringifyNumber = __commonJS({
45784
45784
  function stringifyNumber({ format, minFractionDigits, tag, value }) {
45785
45785
  if (typeof value === "bigint")
45786
45786
  return String(value);
45787
- const num = typeof value === "number" ? value : Number(value);
45788
- if (!isFinite(num))
45789
- return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
45787
+ const num2 = typeof value === "number" ? value : Number(value);
45788
+ if (!isFinite(num2))
45789
+ return isNaN(num2) ? ".nan" : num2 < 0 ? "-.inf" : ".inf";
45790
45790
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
45791
45791
  if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
45792
45792
  let i = n.indexOf(".");
@@ -45826,8 +45826,8 @@ var require_float = __commonJS({
45826
45826
  test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
45827
45827
  resolve: (str) => parseFloat(str),
45828
45828
  stringify(node) {
45829
- const num = Number(node.value);
45830
- return isFinite(num) ? num.toExponential() : stringifyNumber.stringifyNumber(node);
45829
+ const num2 = Number(node.value);
45830
+ return isFinite(num2) ? num2.toExponential() : stringifyNumber.stringifyNumber(node);
45831
45831
  }
45832
45832
  };
45833
45833
  var float = {
@@ -46266,8 +46266,8 @@ var require_float2 = __commonJS({
46266
46266
  test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
46267
46267
  resolve: (str) => parseFloat(str.replace(/_/g, "")),
46268
46268
  stringify(node) {
46269
- const num = Number(node.value);
46270
- return isFinite(num) ? num.toExponential() : stringifyNumber.stringifyNumber(node);
46269
+ const num2 = Number(node.value);
46270
+ return isFinite(num2) ? num2.toExponential() : stringifyNumber.stringifyNumber(node);
46271
46271
  }
46272
46272
  };
46273
46273
  var float = {
@@ -46469,23 +46469,23 @@ var require_timestamp2 = __commonJS({
46469
46469
  function parseSexagesimal(str, asBigInt) {
46470
46470
  const sign = str[0];
46471
46471
  const parts = sign === "-" || sign === "+" ? str.substring(1) : str;
46472
- const num = (n) => asBigInt ? BigInt(n) : Number(n);
46473
- const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 * num(60) + num(p), num(0));
46474
- return sign === "-" ? num(-1) * res : res;
46472
+ const num2 = (n) => asBigInt ? BigInt(n) : Number(n);
46473
+ const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 * num2(60) + num2(p), num2(0));
46474
+ return sign === "-" ? num2(-1) * res : res;
46475
46475
  }
46476
46476
  function stringifySexagesimal(node) {
46477
46477
  let { value } = node;
46478
- let num = (n) => n;
46478
+ let num2 = (n) => n;
46479
46479
  if (typeof value === "bigint")
46480
- num = (n) => BigInt(n);
46480
+ num2 = (n) => BigInt(n);
46481
46481
  else if (isNaN(value) || !isFinite(value))
46482
46482
  return stringifyNumber.stringifyNumber(node);
46483
46483
  let sign = "";
46484
46484
  if (value < 0) {
46485
46485
  sign = "-";
46486
- value *= num(-1);
46486
+ value *= num2(-1);
46487
46487
  }
46488
- const _60 = num(60);
46488
+ const _60 = num2(60);
46489
46489
  const parts = [value % _60];
46490
46490
  if (value < 60) {
46491
46491
  parts.unshift(0);
@@ -47113,28 +47113,28 @@ var require_errors5 = __commonJS({
47113
47113
  "node_modules/yaml/dist/errors.js"(exports2) {
47114
47114
  "use strict";
47115
47115
  var YAMLError = class extends Error {
47116
- constructor(name, pos, code, message) {
47116
+ constructor(name, pos2, code, message) {
47117
47117
  super();
47118
47118
  this.name = name;
47119
47119
  this.code = code;
47120
47120
  this.message = message;
47121
- this.pos = pos;
47121
+ this.pos = pos2;
47122
47122
  }
47123
47123
  };
47124
47124
  var YAMLParseError = class extends YAMLError {
47125
- constructor(pos, code, message) {
47126
- super("YAMLParseError", pos, code, message);
47125
+ constructor(pos2, code, message) {
47126
+ super("YAMLParseError", pos2, code, message);
47127
47127
  }
47128
47128
  };
47129
47129
  var YAMLWarning = class extends YAMLError {
47130
- constructor(pos, code, message) {
47131
- super("YAMLWarning", pos, code, message);
47130
+ constructor(pos2, code, message) {
47131
+ super("YAMLWarning", pos2, code, message);
47132
47132
  }
47133
47133
  };
47134
47134
  var prettifyError = (src, lc2) => (error) => {
47135
47135
  if (error.pos[0] === -1)
47136
47136
  return;
47137
- error.linePos = error.pos.map((pos) => lc2.linePos(pos));
47137
+ error.linePos = error.pos.map((pos2) => lc2.linePos(pos2));
47138
47138
  const { line, col } = error.linePos[0];
47139
47139
  error.message += ` at line ${line}, column ${col}`;
47140
47140
  let ci = col - 1;
@@ -48117,8 +48117,8 @@ var require_resolve_flow_scalar = __commonJS({
48117
48117
  return source;
48118
48118
  let res = match[1];
48119
48119
  let sep4 = " ";
48120
- let pos = first.lastIndex;
48121
- line.lastIndex = pos;
48120
+ let pos2 = first.lastIndex;
48121
+ line.lastIndex = pos2;
48122
48122
  while (match = line.exec(source)) {
48123
48123
  if (match[1] === "") {
48124
48124
  if (sep4 === "\n")
@@ -48129,10 +48129,10 @@ var require_resolve_flow_scalar = __commonJS({
48129
48129
  res += sep4 + match[1];
48130
48130
  sep4 = " ";
48131
48131
  }
48132
- pos = line.lastIndex;
48132
+ pos2 = line.lastIndex;
48133
48133
  }
48134
48134
  const last = /[ \t]*(.*)/sy;
48135
- last.lastIndex = pos;
48135
+ last.lastIndex = pos2;
48136
48136
  match = last.exec(source);
48137
48137
  return res + sep4 + (match?.[1] ?? "");
48138
48138
  }
@@ -48332,10 +48332,10 @@ var require_compose_scalar = __commonJS({
48332
48332
  var require_util_empty_scalar_position = __commonJS({
48333
48333
  "node_modules/yaml/dist/compose/util-empty-scalar-position.js"(exports2) {
48334
48334
  "use strict";
48335
- function emptyScalarPosition(offset, before, pos) {
48335
+ function emptyScalarPosition(offset, before, pos2) {
48336
48336
  if (before) {
48337
- pos ?? (pos = before.length);
48338
- for (let i = pos - 1; i >= 0; --i) {
48337
+ pos2 ?? (pos2 = before.length);
48338
+ for (let i = pos2 - 1; i >= 0; --i) {
48339
48339
  let st = before[i];
48340
48340
  switch (st.type) {
48341
48341
  case "space":
@@ -48425,10 +48425,10 @@ var require_compose_node = __commonJS({
48425
48425
  node.srcToken = token;
48426
48426
  return node;
48427
48427
  }
48428
- function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag, end }, onError) {
48428
+ function composeEmptyNode(ctx, offset, before, pos2, { spaceBefore, comment, anchor, tag, end }, onError) {
48429
48429
  const token = {
48430
48430
  type: "scalar",
48431
- offset: utilEmptyScalarPosition.emptyScalarPosition(offset, before, pos),
48431
+ offset: utilEmptyScalarPosition.emptyScalarPosition(offset, before, pos2),
48432
48432
  indent: -1,
48433
48433
  source: ""
48434
48434
  };
@@ -48559,11 +48559,11 @@ var require_composer = __commonJS({
48559
48559
  this.errors = [];
48560
48560
  this.warnings = [];
48561
48561
  this.onError = (source, code, message, warning) => {
48562
- const pos = getErrorPos(source);
48562
+ const pos2 = getErrorPos(source);
48563
48563
  if (warning)
48564
- this.warnings.push(new errors.YAMLWarning(pos, code, message));
48564
+ this.warnings.push(new errors.YAMLWarning(pos2, code, message));
48565
48565
  else
48566
- this.errors.push(new errors.YAMLParseError(pos, code, message));
48566
+ this.errors.push(new errors.YAMLParseError(pos2, code, message));
48567
48567
  };
48568
48568
  this.directives = new directives.Directives({ version: options.version || "1.2" });
48569
48569
  this.options = options;
@@ -48634,9 +48634,9 @@ ${cb}` : comment;
48634
48634
  switch (token.type) {
48635
48635
  case "directive":
48636
48636
  this.directives.add(token.source, (offset, message, warning) => {
48637
- const pos = getErrorPos(token);
48638
- pos[0] += offset;
48639
- this.onError(pos, "BAD_DIRECTIVE", message, warning);
48637
+ const pos2 = getErrorPos(token);
48638
+ pos2[0] += offset;
48639
+ this.onError(pos2, "BAD_DIRECTIVE", message, warning);
48640
48640
  });
48641
48641
  this.prelude.push(token.source);
48642
48642
  this.atDirectives = true;
@@ -48725,8 +48725,8 @@ var require_cst_scalar = __commonJS({
48725
48725
  var stringifyString = require_stringifyString();
48726
48726
  function resolveAsScalar(token, strict = true, onError) {
48727
48727
  if (token) {
48728
- const _onError = (pos, code, message) => {
48729
- const offset = typeof pos === "number" ? pos : Array.isArray(pos) ? pos[0] : pos.offset;
48728
+ const _onError = (pos2, code, message) => {
48729
+ const offset = typeof pos2 === "number" ? pos2 : Array.isArray(pos2) ? pos2[0] : pos2.offset;
48730
48730
  if (onError)
48731
48731
  onError(offset, code, message);
48732
48732
  else
@@ -50649,7 +50649,7 @@ var require_public_api = __commonJS({
50649
50649
  return docs;
50650
50650
  return Object.assign([], { empty: true }, composer$1.streamInfo());
50651
50651
  }
50652
- function parseDocument4(source, options = {}) {
50652
+ function parseDocument5(source, options = {}) {
50653
50653
  const { lineCounter: lineCounter2, prettyErrors } = parseOptions(options);
50654
50654
  const parser$1 = new parser.Parser(lineCounter2?.addNewLine);
50655
50655
  const composer$1 = new composer.Composer(options);
@@ -50675,7 +50675,7 @@ var require_public_api = __commonJS({
50675
50675
  } else if (options === void 0 && reviver && typeof reviver === "object") {
50676
50676
  options = reviver;
50677
50677
  }
50678
- const doc = parseDocument4(src, options);
50678
+ const doc = parseDocument5(src, options);
50679
50679
  if (!doc)
50680
50680
  return null;
50681
50681
  doc.warnings.forEach((warning) => log2.warn(doc.options.logLevel, warning));
@@ -50711,7 +50711,7 @@ var require_public_api = __commonJS({
50711
50711
  }
50712
50712
  exports2.parse = parse;
50713
50713
  exports2.parseAllDocuments = parseAllDocuments;
50714
- exports2.parseDocument = parseDocument4;
50714
+ exports2.parseDocument = parseDocument5;
50715
50715
  exports2.stringify = stringify;
50716
50716
  }
50717
50717
  });
@@ -50827,9 +50827,9 @@ var import_node_readline2 = require("node:readline");
50827
50827
 
50828
50828
  // index.ts
50829
50829
  var import_node_url5 = require("node:url");
50830
- var import_node_path27 = require("node:path");
50831
- var import_node_os19 = require("node:os");
50832
- var import_node_fs29 = require("node:fs");
50830
+ var import_node_path28 = require("node:path");
50831
+ var import_node_os20 = require("node:os");
50832
+ var import_node_fs30 = require("node:fs");
50833
50833
  var import_node_child_process7 = require("node:child_process");
50834
50834
 
50835
50835
  // log.mjs
@@ -50875,19 +50875,180 @@ var import_static = __toESM(require_static(), 1);
50875
50875
 
50876
50876
  // aware-adapter.ts
50877
50877
  var import_node_child_process = require("node:child_process");
50878
- var import_node_fs4 = require("node:fs");
50879
- var import_node_path3 = require("node:path");
50880
- var import_node_os3 = require("node:os");
50881
- var import_node_crypto2 = require("node:crypto");
50878
+ var import_node_fs6 = require("node:fs");
50879
+ var import_node_path5 = require("node:path");
50880
+ var import_node_os5 = require("node:os");
50881
+ var import_node_crypto3 = require("node:crypto");
50882
50882
  var import_node_module = require("node:module");
50883
50883
 
50884
50884
  // app-reader.ts
50885
+ var import_node_crypto2 = require("node:crypto");
50886
+ var import_node_fs5 = require("node:fs");
50887
+ var import_node_os4 = require("node:os");
50888
+ var import_node_path4 = require("node:path");
50889
+ var import_yaml = __toESM(require_dist6(), 1);
50890
+
50891
+ // app-origin-store.ts
50892
+ var import_node_fs4 = require("node:fs");
50893
+ var import_node_os3 = require("node:os");
50894
+ var import_node_path3 = require("node:path");
50895
+
50896
+ // visual-input-store.ts
50885
50897
  var import_node_crypto = require("node:crypto");
50886
50898
  var import_node_fs3 = require("node:fs");
50887
50899
  var import_node_os2 = require("node:os");
50888
50900
  var import_node_path2 = require("node:path");
50889
- var import_yaml = __toESM(require_dist6(), 1);
50890
- var APPS_DIR = process.env.AWARE_HOME ? (0, import_node_path2.join)(process.env.AWARE_HOME, "apps") : (0, import_node_path2.join)((0, import_node_os2.homedir)(), ".aware", "apps");
50901
+ var MAX_BYTES2 = 25 * 1024 * 1024;
50902
+ var VisualInputError = class extends Error {
50903
+ };
50904
+ function inputsDir() {
50905
+ const root = process.env.FLOLESS_HOME ?? (0, import_node_path2.join)((0, import_node_os2.homedir)(), ".floless");
50906
+ return (0, import_node_path2.join)(root, "inputs");
50907
+ }
50908
+ function sniffExt(buf) {
50909
+ if (buf.length >= 8 && buf[0] === 137 && buf[1] === 80 && buf[2] === 78 && buf[3] === 71) return "png";
50910
+ if (buf.length >= 3 && buf[0] === 255 && buf[1] === 216 && buf[2] === 255) return "jpg";
50911
+ if (buf.length >= 12 && buf.toString("ascii", 0, 4) === "RIFF" && buf.toString("ascii", 8, 12) === "WEBP") return "webp";
50912
+ if (buf.length >= 5 && buf.toString("ascii", 0, 5) === "%PDF-") return "pdf";
50913
+ return null;
50914
+ }
50915
+ var RESERVED = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;
50916
+ function safeSegment(s) {
50917
+ if (!s || s === "." || s.includes("..")) return false;
50918
+ if (s.includes("/") || s.includes("\\") || s.includes(import_node_path2.sep)) return false;
50919
+ for (let i = 0; i < s.length; i++) {
50920
+ const c = s.charCodeAt(i);
50921
+ if (c < 32 || c === 58) return false;
50922
+ }
50923
+ if (/[. ]$/.test(s)) return false;
50924
+ return !RESERVED.test(s);
50925
+ }
50926
+ function storeVisualInput(appId, dataUrl) {
50927
+ if (!safeSegment(appId)) throw new VisualInputError("invalid app id");
50928
+ const m = /^data:([\w/+.-]+);base64,(.*)$/s.exec(dataUrl || "");
50929
+ if (!m) throw new VisualInputError("visual input must be a base64 data URL");
50930
+ const buf = Buffer.from(m[2] ?? "", "base64");
50931
+ if (buf.length === 0) throw new VisualInputError("empty visual input");
50932
+ if (buf.length > MAX_BYTES2) throw new VisualInputError("visual input too large (max 25 MB)");
50933
+ const ext = sniffExt(buf);
50934
+ if (!ext) throw new VisualInputError("visual input must be PNG, JPEG, WebP, or PDF");
50935
+ const sha2562 = (0, import_node_crypto.createHash)("sha256").update(buf).digest("hex");
50936
+ const dir = (0, import_node_path2.join)(inputsDir(), appId);
50937
+ const path = (0, import_node_path2.join)(dir, `${sha2562}.${ext}`);
50938
+ const root = (0, import_node_path2.resolve)(inputsDir());
50939
+ const target = (0, import_node_path2.resolve)(path);
50940
+ if (target !== root && !target.startsWith(root + import_node_path2.sep)) {
50941
+ throw new VisualInputError("refusing to write outside the inputs root");
50942
+ }
50943
+ (0, import_node_fs3.mkdirSync)(dir, { recursive: true });
50944
+ if (!(0, import_node_fs3.existsSync)(path)) {
50945
+ const tmp = `${path}.tmp`;
50946
+ (0, import_node_fs3.writeFileSync)(tmp, buf);
50947
+ (0, import_node_fs3.renameSync)(tmp, path);
50948
+ }
50949
+ return { path, ext, bytes: (0, import_node_fs3.statSync)(path).size, sha256: sha2562 };
50950
+ }
50951
+ function renameVisualInputs(oldId, newId) {
50952
+ if (!safeSegment(oldId) || !safeSegment(newId)) throw new VisualInputError("invalid app id");
50953
+ const from = (0, import_node_path2.join)(inputsDir(), oldId);
50954
+ if (!(0, import_node_fs3.existsSync)(from)) return;
50955
+ const to = (0, import_node_path2.join)(inputsDir(), newId);
50956
+ if ((0, import_node_fs3.existsSync)(to)) (0, import_node_fs3.rmSync)(to, { recursive: true, force: true });
50957
+ (0, import_node_fs3.mkdirSync)(inputsDir(), { recursive: true });
50958
+ (0, import_node_fs3.renameSync)(from, to);
50959
+ }
50960
+ function copyVisualInputs(srcId, newId) {
50961
+ if (!safeSegment(srcId) || !safeSegment(newId)) throw new VisualInputError("invalid app id");
50962
+ const from = (0, import_node_path2.join)(inputsDir(), srcId);
50963
+ if (!(0, import_node_fs3.existsSync)(from)) return;
50964
+ (0, import_node_fs3.cpSync)(from, (0, import_node_path2.join)(inputsDir(), newId), { recursive: true });
50965
+ }
50966
+ function deleteVisualInputs(id) {
50967
+ if (!safeSegment(id)) throw new VisualInputError("invalid app id");
50968
+ const dir = (0, import_node_path2.join)(inputsDir(), id);
50969
+ if ((0, import_node_fs3.existsSync)(dir)) (0, import_node_fs3.rmSync)(dir, { recursive: true, force: true });
50970
+ }
50971
+
50972
+ // app-origin-store.ts
50973
+ function storeFile() {
50974
+ const root = process.env.FLOLESS_HOME ?? (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".floless");
50975
+ return (0, import_node_path3.join)(root, "app-origin.json");
50976
+ }
50977
+ function loadAll() {
50978
+ try {
50979
+ const parsed = JSON.parse((0, import_node_fs4.readFileSync)(storeFile(), "utf8"));
50980
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
50981
+ } catch {
50982
+ return {};
50983
+ }
50984
+ }
50985
+ function saveAll(map) {
50986
+ const file = storeFile();
50987
+ const dir = (0, import_node_path3.dirname)(file);
50988
+ if (!(0, import_node_fs4.existsSync)(dir)) (0, import_node_fs4.mkdirSync)(dir, { recursive: true });
50989
+ const tmp = `${file}.${process.pid}.tmp`;
50990
+ (0, import_node_fs4.writeFileSync)(tmp, JSON.stringify(map, null, 2));
50991
+ (0, import_node_fs4.renameSync)(tmp, file);
50992
+ }
50993
+ function readOrigin(id) {
50994
+ if (!safeSegment(id)) return null;
50995
+ return loadAll()[id] ?? null;
50996
+ }
50997
+ function patch(id, fields) {
50998
+ if (!safeSegment(id)) return;
50999
+ const all = loadAll();
51000
+ all[id] = { ...all[id] ?? {}, ...fields };
51001
+ saveAll(all);
51002
+ }
51003
+ function setDerivedFrom(id, derivedFrom) {
51004
+ patch(id, { derivedFrom });
51005
+ }
51006
+ function resolveTemplateId(id) {
51007
+ return readOrigin(id)?.derivedFrom ?? id;
51008
+ }
51009
+ function markForked(id, who, ts) {
51010
+ patch(id, { forkedAt: ts, forkedFromVersion: who.version, liabilityAcceptedAt: ts, liabilityAcceptedBy: who.acceptedBy });
51011
+ }
51012
+ function clearFork(id) {
51013
+ if (!safeSegment(id)) return;
51014
+ const all = loadAll();
51015
+ const prev = all[id];
51016
+ if (!prev) return;
51017
+ const next = {};
51018
+ if (prev.derivedFrom) next.derivedFrom = prev.derivedFrom;
51019
+ all[id] = next;
51020
+ saveAll(all);
51021
+ }
51022
+ function renameOrigin(oldId, newId) {
51023
+ if (!safeSegment(oldId) || !safeSegment(newId)) return;
51024
+ const all = loadAll();
51025
+ const prev = all[oldId] ?? { derivedFrom: oldId };
51026
+ delete all[oldId];
51027
+ all[newId] = prev;
51028
+ saveAll(all);
51029
+ }
51030
+ function copyOrigin(srcId, newId) {
51031
+ setDerivedFrom(newId, resolveTemplateId(srcId));
51032
+ }
51033
+ function deleteOrigin(id) {
51034
+ if (!safeSegment(id)) return;
51035
+ const all = loadAll();
51036
+ if (id in all) {
51037
+ delete all[id];
51038
+ saveAll(all);
51039
+ }
51040
+ }
51041
+ function appOrigin(id) {
51042
+ try {
51043
+ const rec = readOrigin(id);
51044
+ return { templateId: rec?.derivedFrom ?? id, forked: !!rec?.forkedAt, derivedFrom: rec?.derivedFrom ?? null };
51045
+ } catch {
51046
+ return { templateId: id, forked: false, derivedFrom: null };
51047
+ }
51048
+ }
51049
+
51050
+ // app-reader.ts
51051
+ var APPS_DIR = process.env.AWARE_HOME ? (0, import_node_path4.join)(process.env.AWARE_HOME, "apps") : (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".aware", "apps");
50891
51052
  function normalizeNote(n) {
50892
51053
  if (n && typeof n === "object") {
50893
51054
  const o = n;
@@ -50916,24 +51077,24 @@ var AppNotFoundError = class extends Error {
50916
51077
  };
50917
51078
  function appDir(id) {
50918
51079
  if (id.includes("/") || id.includes("\\") || id.includes("..")) throw new AppNotFoundError(id);
50919
- const dir = (0, import_node_path2.join)(APPS_DIR, id);
50920
- if (!(0, import_node_fs3.existsSync)(dir)) throw new AppNotFoundError(id);
51080
+ const dir = (0, import_node_path4.join)(APPS_DIR, id);
51081
+ if (!(0, import_node_fs5.existsSync)(dir)) throw new AppNotFoundError(id);
50921
51082
  return dir;
50922
51083
  }
50923
51084
  function appPath(id) {
50924
51085
  if (id.includes("/") || id.includes("\\") || id.includes("..")) throw new AppNotFoundError(id);
50925
- return (0, import_node_path2.join)(APPS_DIR, id);
51086
+ return (0, import_node_path4.join)(APPS_DIR, id);
50926
51087
  }
50927
51088
  function appExists(id) {
50928
51089
  if (id.includes("/") || id.includes("\\") || id.includes("..")) return false;
50929
- return (0, import_node_fs3.existsSync)((0, import_node_path2.join)(APPS_DIR, id));
51090
+ return (0, import_node_fs5.existsSync)((0, import_node_path4.join)(APPS_DIR, id));
50930
51091
  }
50931
51092
  function firstWithExt(dir, ext) {
50932
- const hit = (0, import_node_fs3.readdirSync)(dir).find((f) => f.toLowerCase().endsWith(ext));
50933
- return hit ? (0, import_node_path2.join)(dir, hit) : null;
51093
+ const hit = (0, import_node_fs5.readdirSync)(dir).find((f) => f.toLowerCase().endsWith(ext));
51094
+ return hit ? (0, import_node_path4.join)(dir, hit) : null;
50934
51095
  }
50935
51096
  function sha256(text) {
50936
- return (0, import_node_crypto.createHash)("sha256").update(text).digest("hex");
51097
+ return (0, import_node_crypto2.createHash)("sha256").update(text).digest("hex");
50937
51098
  }
50938
51099
  function asRecord(v) {
50939
51100
  return v && typeof v === "object" && !Array.isArray(v) ? v : {};
@@ -50943,7 +51104,7 @@ function appProvider(id) {
50943
51104
  const dir = appDir(id);
50944
51105
  const sourcePath = firstWithExt(dir, ".app") ?? firstWithExt(dir, ".flo");
50945
51106
  if (!sourcePath) return "other";
50946
- const src = asRecord((0, import_yaml.parse)((0, import_node_fs3.readFileSync)(sourcePath, "utf8")));
51107
+ const src = asRecord((0, import_yaml.parse)((0, import_node_fs5.readFileSync)(sourcePath, "utf8")));
50947
51108
  const srcNodes = Array.isArray(src.nodes) ? src.nodes : [];
50948
51109
  const counts = /* @__PURE__ */ new Map();
50949
51110
  for (const n of srcNodes) {
@@ -50967,7 +51128,7 @@ function appBaked(id) {
50967
51128
  const dir = appDir(id);
50968
51129
  const sourcePath = firstWithExt(dir, ".app") ?? firstWithExt(dir, ".flo");
50969
51130
  if (!sourcePath) return false;
50970
- const src = asRecord((0, import_yaml.parse)((0, import_node_fs3.readFileSync)(sourcePath, "utf8")));
51131
+ const src = asRecord((0, import_yaml.parse)((0, import_node_fs5.readFileSync)(sourcePath, "utf8")));
50971
51132
  return src["exposes-as-agent"] === true;
50972
51133
  } catch {
50973
51134
  return false;
@@ -50977,11 +51138,12 @@ function readApp(id) {
50977
51138
  const dir = appDir(id);
50978
51139
  const sourcePath = firstWithExt(dir, ".app") ?? firstWithExt(dir, ".flo");
50979
51140
  if (!sourcePath) throw new AppNotFoundError(id);
50980
- const sourceText = (0, import_node_fs3.readFileSync)(sourcePath, "utf8");
51141
+ const sourceText = (0, import_node_fs5.readFileSync)(sourcePath, "utf8");
50981
51142
  const sourceHash = sha256(sourceText);
50982
51143
  const src = asRecord((0, import_yaml.parse)(sourceText));
51144
+ const origin = appOrigin(id);
50983
51145
  const lockPath = firstWithExt(dir, ".lock");
50984
- const lockText = lockPath ? (0, import_node_fs3.readFileSync)(lockPath, "utf8") : null;
51146
+ const lockText = lockPath ? (0, import_node_fs5.readFileSync)(lockPath, "utf8") : null;
50985
51147
  const lockDoc = lockText ? asRecord((0, import_yaml.parse)(lockText)) : {};
50986
51148
  const lockNodes = Array.isArray(lockDoc.nodes) ? lockDoc.nodes : [];
50987
51149
  const lockById = new Map(lockNodes.map((n) => [String(n.id), n]));
@@ -51059,6 +51221,10 @@ function readApp(id) {
51059
51221
  displayName: typeof src["display-name"] === "string" ? src["display-name"] : id,
51060
51222
  description: typeof src.description === "string" ? src.description : "",
51061
51223
  version: src.version != null ? String(src.version) : "0.0.0",
51224
+ publisher: typeof src.publisher === "string" ? src.publisher : null,
51225
+ derivedFrom: origin.derivedFrom,
51226
+ templateId: origin.templateId,
51227
+ forked: origin.forked,
51062
51228
  layout,
51063
51229
  requires: Array.isArray(src.requires) ? src.requires.map(String) : [],
51064
51230
  inputs,
@@ -51082,11 +51248,11 @@ function sourceNodeId(nodes, connections) {
51082
51248
  function readCommandSpec(agent, command, agentsDir = AGENTS_DIR) {
51083
51249
  const safe = (n) => !/[/\\\0]/.test(n) && !n.includes("..");
51084
51250
  if (!safe(agent) || !safe(command)) return null;
51085
- const manifestPath = (0, import_node_path2.join)(agentsDir, agent, "manifest.yaml");
51086
- if (!(0, import_node_fs3.existsSync)(manifestPath)) return null;
51251
+ const manifestPath = (0, import_node_path4.join)(agentsDir, agent, "manifest.yaml");
51252
+ if (!(0, import_node_fs5.existsSync)(manifestPath)) return null;
51087
51253
  let doc;
51088
51254
  try {
51089
- doc = asRecord((0, import_yaml.parse)((0, import_node_fs3.readFileSync)(manifestPath, "utf8")));
51255
+ doc = asRecord((0, import_yaml.parse)((0, import_node_fs5.readFileSync)(manifestPath, "utf8")));
51090
51256
  } catch {
51091
51257
  return null;
51092
51258
  }
@@ -51127,11 +51293,11 @@ function parseManifestInputs(raw) {
51127
51293
  function readNodeSkill(agent, command, agentsDir = AGENTS_DIR) {
51128
51294
  const safe = (n) => !/[/\\\0]/.test(n) && !n.includes("..");
51129
51295
  if (!safe(agent) || !safe(command)) return null;
51130
- const manifestPath = (0, import_node_path2.join)(agentsDir, agent, "manifest.yaml");
51131
- if (!(0, import_node_fs3.existsSync)(manifestPath)) return null;
51296
+ const manifestPath = (0, import_node_path4.join)(agentsDir, agent, "manifest.yaml");
51297
+ if (!(0, import_node_fs5.existsSync)(manifestPath)) return null;
51132
51298
  let doc;
51133
51299
  try {
51134
- doc = asRecord((0, import_yaml.parse)((0, import_node_fs3.readFileSync)(manifestPath, "utf8")));
51300
+ doc = asRecord((0, import_yaml.parse)((0, import_node_fs5.readFileSync)(manifestPath, "utf8")));
51135
51301
  } catch {
51136
51302
  return null;
51137
51303
  }
@@ -51165,13 +51331,13 @@ function detectTriggerSource(nodes, connections, lookup) {
51165
51331
  if (!spec || spec.lifecycle !== "start" || !spec.streaming) return null;
51166
51332
  return { nodeId: src.id, agent: src.agent, command: src.command, inputs: spec.inputs };
51167
51333
  }
51168
- var AGENTS_DIR = process.env.AWARE_HOME ? (0, import_node_path2.join)(process.env.AWARE_HOME, "agents") : (0, import_node_path2.join)((0, import_node_os2.homedir)(), ".aware", "agents");
51169
- var CREDENTIALS_DIR = process.env.AWARE_HOME ? (0, import_node_path2.join)(process.env.AWARE_HOME, "credentials") : (0, import_node_path2.join)((0, import_node_os2.homedir)(), ".aware", "credentials");
51334
+ var AGENTS_DIR = process.env.AWARE_HOME ? (0, import_node_path4.join)(process.env.AWARE_HOME, "agents") : (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".aware", "agents");
51335
+ var CREDENTIALS_DIR = process.env.AWARE_HOME ? (0, import_node_path4.join)(process.env.AWARE_HOME, "credentials") : (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".aware", "credentials");
51170
51336
  function credentialStatus(secret) {
51171
- const file = (0, import_node_path2.join)(CREDENTIALS_DIR, `${secret}.json`);
51172
- if (!(0, import_node_fs3.existsSync)(file)) return { status: "disconnected", expiresAt: null };
51337
+ const file = (0, import_node_path4.join)(CREDENTIALS_DIR, `${secret}.json`);
51338
+ if (!(0, import_node_fs5.existsSync)(file)) return { status: "disconnected", expiresAt: null };
51173
51339
  try {
51174
- const doc = JSON.parse((0, import_node_fs3.readFileSync)(file, "utf8"));
51340
+ const doc = JSON.parse((0, import_node_fs5.readFileSync)(file, "utf8"));
51175
51341
  const raw = doc["expires_at"] ?? doc["expiresAt"] ?? doc["expiry"];
51176
51342
  if (raw != null) {
51177
51343
  const ms = typeof raw === "number" ? raw * (raw < 1e12 ? 1e3 : 1) : Date.parse(String(raw));
@@ -51184,15 +51350,15 @@ function credentialStatus(secret) {
51184
51350
  return { status: "connected", expiresAt: null };
51185
51351
  }
51186
51352
  function listIntegrations() {
51187
- if (!(0, import_node_fs3.existsSync)(AGENTS_DIR)) return [];
51353
+ if (!(0, import_node_fs5.existsSync)(AGENTS_DIR)) return [];
51188
51354
  const out = [];
51189
51355
  const seen = /* @__PURE__ */ new Set();
51190
51356
  const safe = (n) => !/[/\\\0]/.test(n) && !n.includes("..");
51191
- for (const agentId of (0, import_node_fs3.readdirSync)(AGENTS_DIR)) {
51357
+ for (const agentId of (0, import_node_fs5.readdirSync)(AGENTS_DIR)) {
51192
51358
  if (!safe(agentId)) continue;
51193
- const manifestPath = (0, import_node_path2.join)(AGENTS_DIR, agentId, "manifest.yaml");
51194
- if (!(0, import_node_fs3.existsSync)(manifestPath)) continue;
51195
- const manifestText = (0, import_node_fs3.readFileSync)(manifestPath, "utf8");
51359
+ const manifestPath = (0, import_node_path4.join)(AGENTS_DIR, agentId, "manifest.yaml");
51360
+ if (!(0, import_node_fs5.existsSync)(manifestPath)) continue;
51361
+ const manifestText = (0, import_node_fs5.readFileSync)(manifestPath, "utf8");
51196
51362
  if (!manifestText.includes("secrets:")) continue;
51197
51363
  let doc;
51198
51364
  try {
@@ -51283,14 +51449,14 @@ var AwareUnsupportedError = class extends AwareError {
51283
51449
  };
51284
51450
  function resolveInvoker() {
51285
51451
  const envDir = process.env.AWARE_CLI_DIR;
51286
- if (envDir && (0, import_node_fs4.existsSync)((0, import_node_path3.join)(envDir, "scripts/bin/aware.js"))) {
51287
- return { head: [nodeExe(), (0, import_node_path3.join)(envDir, "scripts/bin/aware.js")], shell: false, pkgDir: envDir };
51452
+ if (envDir && (0, import_node_fs6.existsSync)((0, import_node_path5.join)(envDir, "scripts/bin/aware.js"))) {
51453
+ return { head: [nodeExe(), (0, import_node_path5.join)(envDir, "scripts/bin/aware.js")], shell: false, pkgDir: envDir };
51288
51454
  }
51289
51455
  try {
51290
51456
  const root = (0, import_node_child_process.execFileSync)("npm", ["root", "-g"], { encoding: "utf8", shell: process.platform === "win32", windowsHide: true, timeout: 1e4 }).trim();
51291
- const pkgDir = (0, import_node_path3.join)(root, "@aware-aeco", "cli");
51292
- const bin = (0, import_node_path3.join)(pkgDir, "scripts/bin/aware.js");
51293
- if ((0, import_node_fs4.existsSync)(bin)) return { head: [nodeExe(), bin], shell: false, pkgDir };
51457
+ const pkgDir = (0, import_node_path5.join)(root, "@aware-aeco", "cli");
51458
+ const bin = (0, import_node_path5.join)(pkgDir, "scripts/bin/aware.js");
51459
+ if ((0, import_node_fs6.existsSync)(bin)) return { head: [nodeExe(), bin], shell: false, pkgDir };
51294
51460
  } catch {
51295
51461
  }
51296
51462
  return { head: ["aware"], shell: process.platform === "win32", pkgDir: null };
@@ -51307,7 +51473,7 @@ function awareNpmVersion() {
51307
51473
  const invoker = currentInvoker();
51308
51474
  if (!invoker.pkgDir) return null;
51309
51475
  try {
51310
- const pkg = JSON.parse((0, import_node_fs4.readFileSync)((0, import_node_path3.join)(invoker.pkgDir, "package.json"), "utf8"));
51476
+ const pkg = JSON.parse((0, import_node_fs6.readFileSync)((0, import_node_path5.join)(invoker.pkgDir, "package.json"), "utf8"));
51311
51477
  return typeof pkg.version === "string" ? pkg.version : null;
51312
51478
  } catch {
51313
51479
  return null;
@@ -51396,10 +51562,10 @@ async function runJson(args) {
51396
51562
  function resolveTeklaBridge() {
51397
51563
  const invoker = currentInvoker();
51398
51564
  const candidates = [
51399
- (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".aware", "bridges", "aware-tekla.exe"),
51400
- invoker.pkgDir ? (0, import_node_path3.join)(invoker.pkgDir, "binaries", "aware-tekla.exe") : null
51565
+ (0, import_node_path5.join)((0, import_node_os5.homedir)(), ".aware", "bridges", "aware-tekla.exe"),
51566
+ invoker.pkgDir ? (0, import_node_path5.join)(invoker.pkgDir, "binaries", "aware-tekla.exe") : null
51401
51567
  ].filter((p) => !!p);
51402
- return candidates.find((p) => (0, import_node_fs4.existsSync)(p)) ?? null;
51568
+ return candidates.find((p) => (0, import_node_fs6.existsSync)(p)) ?? null;
51403
51569
  }
51404
51570
  function injectDebugger(code) {
51405
51571
  const lines = code.split(/\r?\n/);
@@ -51481,39 +51647,39 @@ function cancelActiveRun() {
51481
51647
  function isRunActive() {
51482
51648
  return activeRun !== null;
51483
51649
  }
51484
- var LOGS_DIR = process.env.AWARE_HOME ? (0, import_node_path3.join)(process.env.AWARE_HOME, "logs") : (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".aware", "logs");
51650
+ var LOGS_DIR = process.env.AWARE_HOME ? (0, import_node_path5.join)(process.env.AWARE_HOME, "logs") : (0, import_node_path5.join)((0, import_node_os5.homedir)(), ".aware", "logs");
51485
51651
  var TRIGGER_POLL_MS = 250;
51486
51652
  function parseRunHandle(stdout) {
51487
51653
  const m = stdout.match(/instance\s+([^,\s]+),\s*run-id\s+([0-9a-f-]{36})/i);
51488
51654
  return m ? { instance: m[1], runId: m[2] } : null;
51489
51655
  }
51490
51656
  function traceLogPath(id, instance, runId, logsRoot = LOGS_DIR) {
51491
- return (0, import_node_path3.join)(logsRoot, id, instance, `${runId}.jsonl`);
51657
+ return (0, import_node_path5.join)(logsRoot, id, instance, `${runId}.jsonl`);
51492
51658
  }
51493
51659
  function latestTracePath(id, logsRoot = LOGS_DIR) {
51494
- const appDir2 = (0, import_node_path3.join)(logsRoot, id);
51495
- if (!(0, import_node_fs4.existsSync)(appDir2)) return null;
51660
+ const appDir2 = (0, import_node_path5.join)(logsRoot, id);
51661
+ if (!(0, import_node_fs6.existsSync)(appDir2)) return null;
51496
51662
  let best = null;
51497
51663
  let instances;
51498
51664
  try {
51499
- instances = (0, import_node_fs4.readdirSync)(appDir2);
51665
+ instances = (0, import_node_fs6.readdirSync)(appDir2);
51500
51666
  } catch {
51501
51667
  return null;
51502
51668
  }
51503
51669
  for (const instance of instances) {
51504
- const instDir = (0, import_node_path3.join)(appDir2, instance);
51670
+ const instDir = (0, import_node_path5.join)(appDir2, instance);
51505
51671
  let entries;
51506
51672
  try {
51507
- if (!(0, import_node_fs4.statSync)(instDir).isDirectory()) continue;
51508
- entries = (0, import_node_fs4.readdirSync)(instDir);
51673
+ if (!(0, import_node_fs6.statSync)(instDir).isDirectory()) continue;
51674
+ entries = (0, import_node_fs6.readdirSync)(instDir);
51509
51675
  } catch {
51510
51676
  continue;
51511
51677
  }
51512
51678
  for (const f of entries) {
51513
51679
  if (!f.endsWith(".jsonl")) continue;
51514
- const p = (0, import_node_path3.join)(instDir, f);
51680
+ const p = (0, import_node_path5.join)(instDir, f);
51515
51681
  try {
51516
- const m = (0, import_node_fs4.statSync)(p).mtimeMs;
51682
+ const m = (0, import_node_fs6.statSync)(p).mtimeMs;
51517
51683
  if (!best || m > best.mtimeMs) best = { path: p, mtimeMs: m };
51518
51684
  } catch {
51519
51685
  }
@@ -51522,17 +51688,17 @@ function latestTracePath(id, logsRoot = LOGS_DIR) {
51522
51688
  return best ? best.path : null;
51523
51689
  }
51524
51690
  function readTail(path, maxBytes) {
51525
- const size = (0, import_node_fs4.statSync)(path).size;
51526
- if (size <= maxBytes) return { text: (0, import_node_fs4.readFileSync)(path, "utf8"), truncated: false };
51527
- const fd2 = (0, import_node_fs4.openSync)(path, "r");
51691
+ const size = (0, import_node_fs6.statSync)(path).size;
51692
+ if (size <= maxBytes) return { text: (0, import_node_fs6.readFileSync)(path, "utf8"), truncated: false };
51693
+ const fd2 = (0, import_node_fs6.openSync)(path, "r");
51528
51694
  try {
51529
51695
  const buf = Buffer.alloc(maxBytes);
51530
- const read = (0, import_node_fs4.readSync)(fd2, buf, 0, maxBytes, size - maxBytes);
51696
+ const read = (0, import_node_fs6.readSync)(fd2, buf, 0, maxBytes, size - maxBytes);
51531
51697
  const nl = buf.indexOf(10, 0);
51532
51698
  const start = nl >= 0 && nl + 1 <= read ? nl + 1 : 0;
51533
51699
  return { text: buf.subarray(start, read).toString("utf8"), truncated: true };
51534
51700
  } finally {
51535
- (0, import_node_fs4.closeSync)(fd2);
51701
+ (0, import_node_fs6.closeSync)(fd2);
51536
51702
  }
51537
51703
  }
51538
51704
  function readLatestTrace(id, logsRoot = LOGS_DIR, maxBytes) {
@@ -51540,7 +51706,7 @@ function readLatestTrace(id, logsRoot = LOGS_DIR, maxBytes) {
51540
51706
  if (!p) return null;
51541
51707
  let read;
51542
51708
  try {
51543
- read = maxBytes && maxBytes > 0 ? readTail(p, maxBytes) : { text: (0, import_node_fs4.readFileSync)(p, "utf8"), truncated: false };
51709
+ read = maxBytes && maxBytes > 0 ? readTail(p, maxBytes) : { text: (0, import_node_fs6.readFileSync)(p, "utf8"), truncated: false };
51544
51710
  } catch {
51545
51711
  return null;
51546
51712
  }
@@ -51575,7 +51741,7 @@ function startTrigger(id, opts = {}) {
51575
51741
  const readAndEmit = () => {
51576
51742
  if (!tracePath || !traceCb) return;
51577
51743
  try {
51578
- const txt = (0, import_node_fs4.readFileSync)(tracePath, "utf8");
51744
+ const txt = (0, import_node_fs6.readFileSync)(tracePath, "utf8");
51579
51745
  if (txt.length !== lastLen) {
51580
51746
  lastLen = txt.length;
51581
51747
  traceCb(parseTrace(txt));
@@ -51636,13 +51802,13 @@ function assertNodeId(id) {
51636
51802
  var SOURCE_EXT = /\.(flo|app|flow|aware)$/i;
51637
51803
  function assertSourcePath(p) {
51638
51804
  if (!SOURCE_EXT.test(p)) throw new AwareError(`source must be a .flo/.app file: ${JSON.stringify(p)}`);
51639
- if (!(0, import_node_fs4.existsSync)(p)) throw new AwareError(`source path not found: ${JSON.stringify(p)}`);
51640
- return (0, import_node_fs4.realpathSync)(p);
51805
+ if (!(0, import_node_fs6.existsSync)(p)) throw new AwareError(`source path not found: ${JSON.stringify(p)}`);
51806
+ return (0, import_node_fs6.realpathSync)(p);
51641
51807
  }
51642
51808
  function assertAppDir(p) {
51643
- if (!(0, import_node_fs4.existsSync)(p)) throw new AwareError(`app dir not found: ${JSON.stringify(p)}`);
51644
- const real = (0, import_node_fs4.realpathSync)(p);
51645
- if (!(0, import_node_fs4.statSync)(real).isDirectory()) throw new AwareError(`app dir is not a directory: ${JSON.stringify(p)}`);
51809
+ if (!(0, import_node_fs6.existsSync)(p)) throw new AwareError(`app dir not found: ${JSON.stringify(p)}`);
51810
+ const real = (0, import_node_fs6.realpathSync)(p);
51811
+ if (!(0, import_node_fs6.statSync)(real).isDirectory()) throw new AwareError(`app dir is not a directory: ${JSON.stringify(p)}`);
51646
51812
  return real;
51647
51813
  }
51648
51814
  var GRAFT_PKG_AT_VER_RE = /^[A-Za-z0-9][\w.@/-]{0,127}$/;
@@ -51663,8 +51829,8 @@ function assertSourceRef(kind, ref) {
51663
51829
  case "openapi":
51664
51830
  case "yard":
51665
51831
  if (GRAFT_URL_RE.test(r)) return r;
51666
- if (!(0, import_node_fs4.existsSync)(r)) throw new AwareError(`${kind}: file/dir not found: ${r}`);
51667
- return (0, import_node_fs4.realpathSync)(r);
51832
+ if (!(0, import_node_fs6.existsSync)(r)) throw new AwareError(`${kind}: file/dir not found: ${r}`);
51833
+ return (0, import_node_fs6.realpathSync)(r);
51668
51834
  case "nuget":
51669
51835
  case "npm":
51670
51836
  case "ruby":
@@ -51901,8 +52067,8 @@ var aware = {
51901
52067
  try {
51902
52068
  let ref;
51903
52069
  if (inputs !== void 0) {
51904
- inputsFile = (0, import_node_path3.join)((0, import_node_os3.tmpdir)(), `floless-agent-inputs-${(0, import_node_crypto2.randomUUID)()}.json`);
51905
- (0, import_node_fs4.writeFileSync)(inputsFile, JSON.stringify(inputs));
52070
+ inputsFile = (0, import_node_path5.join)((0, import_node_os5.tmpdir)(), `floless-agent-inputs-${(0, import_node_crypto3.randomUUID)()}.json`);
52071
+ (0, import_node_fs6.writeFileSync)(inputsFile, JSON.stringify(inputs));
51906
52072
  ref = `@${inputsFile}`;
51907
52073
  }
51908
52074
  const { data } = await runJson(agentInvokeArgv(agent, command, ref));
@@ -51918,7 +52084,7 @@ var aware = {
51918
52084
  } finally {
51919
52085
  if (inputsFile) {
51920
52086
  try {
51921
- (0, import_node_fs4.rmSync)(inputsFile);
52087
+ (0, import_node_fs6.rmSync)(inputsFile);
51922
52088
  } catch {
51923
52089
  }
51924
52090
  }
@@ -51953,7 +52119,7 @@ var aware = {
51953
52119
  if (code !== 0) throw new AwareError(`aware app compile failed (exit ${code})`, { stdout, stderr });
51954
52120
  const m = stdout.match(/→\s*(.+\.lock)\s*$/m);
51955
52121
  const lockPath = m?.[1]?.trim() ?? null;
51956
- const lockText = lockPath && (0, import_node_fs4.existsSync)(lockPath) ? (0, import_node_fs4.readFileSync)(lockPath, "utf8") : null;
52122
+ const lockText = lockPath && (0, import_node_fs6.existsSync)(lockPath) ? (0, import_node_fs6.readFileSync)(lockPath, "utf8") : null;
51957
52123
  return { lockPath, lockText, output: stdout.trim() };
51958
52124
  },
51959
52125
  /**
@@ -52114,7 +52280,7 @@ var aware = {
52114
52280
  if (code !== 0) throw new AwareError(`aware app run failed (exit ${code})`, { stdout, stderr });
52115
52281
  const runId = stdout.match(/run-id\s+([0-9a-f-]{36})/i)?.[1] ?? null;
52116
52282
  const tracePath = stdout.match(/trace at\s+(.+\.jsonl)\s*$/m)?.[1]?.trim() ?? null;
52117
- const traceText = tracePath && (0, import_node_fs4.existsSync)(tracePath) ? (0, import_node_fs4.readFileSync)(tracePath, "utf8") : null;
52283
+ const traceText = tracePath && (0, import_node_fs6.existsSync)(tracePath) ? (0, import_node_fs6.readFileSync)(tracePath, "utf8") : null;
52118
52284
  return { runId, tracePath, traceText, output: stdout.trim() };
52119
52285
  } finally {
52120
52286
  if (activeRun === reg2) activeRun = null;
@@ -52147,20 +52313,20 @@ var aware = {
52147
52313
  };
52148
52314
 
52149
52315
  // extensions-store.ts
52150
- var import_node_fs5 = require("node:fs");
52151
- var import_node_os4 = require("node:os");
52152
- var import_node_path4 = require("node:path");
52153
- var ROOT = process.env.FLOLESS_HOME ?? (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".floless");
52154
- var uiDir = (0, import_node_path4.join)(ROOT, "ui");
52155
- var extensionsFile = (0, import_node_path4.join)(uiDir, "extensions.json");
52156
- var TIMELINE_FILE = (0, import_node_path4.join)(uiDir, "timeline.json");
52316
+ var import_node_fs7 = require("node:fs");
52317
+ var import_node_os6 = require("node:os");
52318
+ var import_node_path6 = require("node:path");
52319
+ var ROOT = process.env.FLOLESS_HOME ?? (0, import_node_path6.join)((0, import_node_os6.homedir)(), ".floless");
52320
+ var uiDir = (0, import_node_path6.join)(ROOT, "ui");
52321
+ var extensionsFile = (0, import_node_path6.join)(uiDir, "extensions.json");
52322
+ var TIMELINE_FILE = (0, import_node_path6.join)(uiDir, "timeline.json");
52157
52323
  var HISTORY_KEEP = 20;
52158
52324
  function ensureUiDir() {
52159
- if (!(0, import_node_fs5.existsSync)(uiDir)) (0, import_node_fs5.mkdirSync)(uiDir, { recursive: true });
52325
+ if (!(0, import_node_fs7.existsSync)(uiDir)) (0, import_node_fs7.mkdirSync)(uiDir, { recursive: true });
52160
52326
  }
52161
52327
  function readExtensionsText() {
52162
52328
  try {
52163
- return (0, import_node_fs5.readFileSync)(extensionsFile, "utf8");
52329
+ return (0, import_node_fs7.readFileSync)(extensionsFile, "utf8");
52164
52330
  } catch {
52165
52331
  return null;
52166
52332
  }
@@ -52191,7 +52357,7 @@ function panelsCountOf(text) {
52191
52357
  function loadTimeline() {
52192
52358
  let text;
52193
52359
  try {
52194
- text = (0, import_node_fs5.readFileSync)(TIMELINE_FILE, "utf8");
52360
+ text = (0, import_node_fs7.readFileSync)(TIMELINE_FILE, "utf8");
52195
52361
  } catch {
52196
52362
  return { cursor: -1, entries: [] };
52197
52363
  }
@@ -52215,19 +52381,19 @@ function loadTimeline() {
52215
52381
  function saveTimeline(t) {
52216
52382
  ensureUiDir();
52217
52383
  const tmp = `${TIMELINE_FILE}.${process.pid}.tmp`;
52218
- (0, import_node_fs5.writeFileSync)(tmp, JSON.stringify(t, null, 2));
52219
- (0, import_node_fs5.renameSync)(tmp, TIMELINE_FILE);
52384
+ (0, import_node_fs7.writeFileSync)(tmp, JSON.stringify(t, null, 2));
52385
+ (0, import_node_fs7.renameSync)(tmp, TIMELINE_FILE);
52220
52386
  }
52221
52387
  function writeExtensionsText(text) {
52222
52388
  ensureUiDir();
52223
52389
  const tmp = `${extensionsFile}.${process.pid}.tmp`;
52224
- (0, import_node_fs5.writeFileSync)(tmp, text);
52225
- (0, import_node_fs5.renameSync)(tmp, extensionsFile);
52390
+ (0, import_node_fs7.writeFileSync)(tmp, text);
52391
+ (0, import_node_fs7.renameSync)(tmp, extensionsFile);
52226
52392
  }
52227
52393
  function applyState(entry2) {
52228
52394
  if (entry2.content === null) {
52229
52395
  try {
52230
- (0, import_node_fs5.rmSync)(extensionsFile);
52396
+ (0, import_node_fs7.rmSync)(extensionsFile);
52231
52397
  } catch {
52232
52398
  }
52233
52399
  } else {
@@ -52421,13 +52587,13 @@ function runBootstrap(deps) {
52421
52587
  }
52422
52588
 
52423
52589
  // licensing.ts
52424
- var import_node_fs6 = require("node:fs");
52425
- var import_node_path5 = require("node:path");
52426
- var import_node_os5 = require("node:os");
52590
+ var import_node_fs8 = require("node:fs");
52591
+ var import_node_path7 = require("node:path");
52592
+ var import_node_os7 = require("node:os");
52427
52593
  var import_node_child_process2 = require("node:child_process");
52428
- var import_node_crypto3 = require("node:crypto");
52594
+ var import_node_crypto4 = require("node:crypto");
52429
52595
  var import_node_module2 = require("node:module");
52430
- var import_node_os6 = require("node:os");
52596
+ var import_node_os8 = require("node:os");
52431
52597
  var ENVS = {
52432
52598
  production: { apiBase: "https://api.floless.io/api", webBase: "https://floless.io" },
52433
52599
  staging: { apiBase: "https://api.stage.floless.io/api", webBase: "https://stage.floless.io" }
@@ -52481,26 +52647,26 @@ function isSea() {
52481
52647
  }
52482
52648
  function storeDir() {
52483
52649
  if (process.env.FLOLESS_LICENSE_DIR) return process.env.FLOLESS_LICENSE_DIR;
52484
- if (isSea() && process.env.LOCALAPPDATA) return (0, import_node_path5.join)(process.env.LOCALAPPDATA, "FlolessApp-data");
52485
- return (0, import_node_path5.join)((0, import_node_os5.homedir)(), ".aware");
52650
+ if (isSea() && process.env.LOCALAPPDATA) return (0, import_node_path7.join)(process.env.LOCALAPPDATA, "FlolessApp-data");
52651
+ return (0, import_node_path7.join)((0, import_node_os7.homedir)(), ".aware");
52486
52652
  }
52487
- var tokenPath = () => (0, import_node_path5.join)(storeDir(), "floless-license.json");
52488
- var cachePath = () => (0, import_node_path5.join)(storeDir(), "floless-license-cache.json");
52653
+ var tokenPath = () => (0, import_node_path7.join)(storeDir(), "floless-license.json");
52654
+ var cachePath = () => (0, import_node_path7.join)(storeDir(), "floless-license-cache.json");
52489
52655
  var _migrated = false;
52490
52656
  function migrateLegacyStore() {
52491
52657
  if (_migrated) return;
52492
52658
  _migrated = true;
52493
52659
  if (process.env.FLOLESS_LICENSE_DIR || !(isSea() && process.env.LOCALAPPDATA)) return;
52494
- const oldDir = (0, import_node_path5.join)(process.env.LOCALAPPDATA, "FlolessApp");
52660
+ const oldDir = (0, import_node_path7.join)(process.env.LOCALAPPDATA, "FlolessApp");
52495
52661
  const newDir = storeDir();
52496
52662
  if (oldDir === newDir) return;
52497
52663
  for (const f of ["floless-license.json", "floless-license-cache.json", "floless-install-id"]) {
52498
52664
  try {
52499
- const oldP = (0, import_node_path5.join)(oldDir, f);
52500
- const newP = (0, import_node_path5.join)(newDir, f);
52501
- if ((0, import_node_fs6.existsSync)(oldP) && !(0, import_node_fs6.existsSync)(newP)) {
52502
- (0, import_node_fs6.mkdirSync)(newDir, { recursive: true });
52503
- (0, import_node_fs6.copyFileSync)(oldP, newP);
52665
+ const oldP = (0, import_node_path7.join)(oldDir, f);
52666
+ const newP = (0, import_node_path7.join)(newDir, f);
52667
+ if ((0, import_node_fs8.existsSync)(oldP) && !(0, import_node_fs8.existsSync)(newP)) {
52668
+ (0, import_node_fs8.mkdirSync)(newDir, { recursive: true });
52669
+ (0, import_node_fs8.copyFileSync)(oldP, newP);
52504
52670
  }
52505
52671
  } catch {
52506
52672
  }
@@ -52508,16 +52674,16 @@ function migrateLegacyStore() {
52508
52674
  }
52509
52675
  function readJson(path) {
52510
52676
  try {
52511
- return (0, import_node_fs6.existsSync)(path) ? JSON.parse((0, import_node_fs6.readFileSync)(path, "utf8")) : null;
52677
+ return (0, import_node_fs8.existsSync)(path) ? JSON.parse((0, import_node_fs8.readFileSync)(path, "utf8")) : null;
52512
52678
  } catch {
52513
52679
  return null;
52514
52680
  }
52515
52681
  }
52516
52682
  function writeJson(path, value) {
52517
- (0, import_node_fs6.mkdirSync)(storeDir(), { recursive: true });
52518
- (0, import_node_fs6.writeFileSync)(path, JSON.stringify(value, null, 2), "utf8");
52683
+ (0, import_node_fs8.mkdirSync)(storeDir(), { recursive: true });
52684
+ (0, import_node_fs8.writeFileSync)(path, JSON.stringify(value, null, 2), "utf8");
52519
52685
  try {
52520
- (0, import_node_fs6.chmodSync)(path, 384);
52686
+ (0, import_node_fs8.chmodSync)(path, 384);
52521
52687
  } catch {
52522
52688
  }
52523
52689
  }
@@ -52657,7 +52823,7 @@ async function ensureSeat(token) {
52657
52823
  const res = await fetch(`${env().apiBase}/seats/claim`, {
52658
52824
  method: "POST",
52659
52825
  headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
52660
- body: JSON.stringify({ device_fingerprint: installId(), device_name: (0, import_node_os6.hostname)(), os_version: `${process.platform} ${process.arch}` })
52826
+ body: JSON.stringify({ device_fingerprint: installId(), device_name: (0, import_node_os8.hostname)(), os_version: `${process.platform} ${process.arch}` })
52661
52827
  });
52662
52828
  if (!res.ok) return;
52663
52829
  const b = await res.json();
@@ -52678,7 +52844,7 @@ async function seatHeartbeat() {
52678
52844
  try {
52679
52845
  const token = await ensureFreshToken().catch(() => null);
52680
52846
  if (!token) return;
52681
- const hmac = (0, import_node_crypto3.createHmac)("sha256", seat.hmacSecret).update(seat.nonce).digest("hex");
52847
+ const hmac = (0, import_node_crypto4.createHmac)("sha256", seat.hmacSecret).update(seat.nonce).digest("hex");
52682
52848
  let res;
52683
52849
  try {
52684
52850
  res = await fetch(`${env().apiBase}/seats/heartbeat`, {
@@ -52750,7 +52916,7 @@ function logout() {
52750
52916
  resetSeat();
52751
52917
  for (const p of [tokenPath(), cachePath()]) {
52752
52918
  try {
52753
- (0, import_node_fs6.rmSync)(p, { force: true });
52919
+ (0, import_node_fs8.rmSync)(p, { force: true });
52754
52920
  } catch {
52755
52921
  }
52756
52922
  }
@@ -52774,7 +52940,7 @@ function openBrowser(url) {
52774
52940
  (0, import_node_child_process2.spawn)(cmd, args, opts).unref();
52775
52941
  }
52776
52942
  async function startLogin() {
52777
- const sessionId = (0, import_node_crypto3.randomUUID)();
52943
+ const sessionId = (0, import_node_crypto4.randomUUID)();
52778
52944
  const loginUrl = `${env().webBase}/login?desktop=true&session=${sessionId}&app=floless`;
52779
52945
  openBrowser(loginUrl);
52780
52946
  void pollDesktopStatus(sessionId).catch(() => {
@@ -52807,20 +52973,20 @@ async function pollDesktopStatus(sessionId, timeoutMs = 18e4) {
52807
52973
  return false;
52808
52974
  }
52809
52975
  function installId() {
52810
- const p = (0, import_node_path5.join)(storeDir(), "floless-install-id");
52976
+ const p = (0, import_node_path7.join)(storeDir(), "floless-install-id");
52811
52977
  const existing = readJson(p);
52812
52978
  if (typeof existing === "string" && existing.length >= 80 && existing.length <= 100) {
52813
52979
  return existing;
52814
52980
  }
52815
- const id = (0, import_node_crypto3.createHash)("sha512").update((0, import_node_crypto3.randomUUID)()).digest("base64");
52981
+ const id = (0, import_node_crypto4.createHash)("sha512").update((0, import_node_crypto4.randomUUID)()).digest("base64");
52816
52982
  writeJson(p, id);
52817
52983
  return id;
52818
52984
  }
52819
52985
 
52820
52986
  // version.ts
52821
52987
  var import_node_module3 = require("node:module");
52822
- var import_node_path6 = require("node:path");
52823
- var import_node_fs7 = require("node:fs");
52988
+ var import_node_path8 = require("node:path");
52989
+ var import_node_fs9 = require("node:fs");
52824
52990
  function resolveVersion(s) {
52825
52991
  if (s.isSea) {
52826
52992
  const m = s.sqVersionXml?.match(/<version>([^<]+)<\/version>/);
@@ -52839,8 +53005,8 @@ function isSea2() {
52839
53005
  }
52840
53006
  function readSqVersionXml() {
52841
53007
  try {
52842
- const sq = (0, import_node_path6.join)((0, import_node_path6.dirname)(process.execPath), "sq.version");
52843
- return (0, import_node_fs7.existsSync)(sq) ? (0, import_node_fs7.readFileSync)(sq, "utf8") : null;
53008
+ const sq = (0, import_node_path8.join)((0, import_node_path8.dirname)(process.execPath), "sq.version");
53009
+ return (0, import_node_fs9.existsSync)(sq) ? (0, import_node_fs9.readFileSync)(sq, "utf8") : null;
52844
53010
  } catch {
52845
53011
  return null;
52846
53012
  }
@@ -52856,7 +53022,7 @@ function appVersion() {
52856
53022
  return resolveVersion({
52857
53023
  isSea: isSea2(),
52858
53024
  sqVersionXml: readSqVersionXml(),
52859
- define: true ? "0.55.0" : void 0,
53025
+ define: true ? "0.57.0" : void 0,
52860
53026
  pkgVersion: readPkgVersion()
52861
53027
  });
52862
53028
  }
@@ -52866,16 +53032,16 @@ function resolveChannel(s) {
52866
53032
  return "dev";
52867
53033
  }
52868
53034
  function appChannel() {
52869
- return resolveChannel({ isSea: isSea2(), define: true ? "0.55.0" : void 0 });
53035
+ return resolveChannel({ isSea: isSea2(), define: true ? "0.57.0" : void 0 });
52870
53036
  }
52871
53037
 
52872
53038
  // workflow-update.ts
52873
- var import_node_fs8 = require("node:fs");
52874
- var import_node_os7 = require("node:os");
52875
- var import_node_path7 = require("node:path");
53039
+ var import_node_fs10 = require("node:fs");
53040
+ var import_node_os9 = require("node:os");
53041
+ var import_node_path9 = require("node:path");
52876
53042
  var import_node_url = require("node:url");
52877
53043
  var import_yaml2 = __toESM(require_dist6(), 1);
52878
- var here = (0, import_node_path7.dirname)((0, import_node_url.fileURLToPath)(__import_meta_url));
53044
+ var here = (0, import_node_path9.dirname)((0, import_node_url.fileURLToPath)(__import_meta_url));
52879
53045
  function compareSemver(a, b) {
52880
53046
  const pa = String(a).split(".");
52881
53047
  const pb = String(b).split(".");
@@ -52890,24 +53056,35 @@ function changelogSince(changelog, installed) {
52890
53056
  return (changelog ?? []).filter((e) => e && compareSemver(String(e.version), installed) > 0);
52891
53057
  }
52892
53058
  function detectUpdates(installed, templates) {
53059
+ const byId = new Map(templates.filter((t) => t.publisher === "floless").map((t) => [t.id, t]));
52893
53060
  const out = [];
52894
- for (const t of templates) {
52895
- if (t.publisher !== "floless") continue;
52896
- const iv = installed[t.id];
52897
- if (iv == null) continue;
52898
- if (compareSemver(t.version, iv) <= 0) continue;
53061
+ for (const app of installed) {
53062
+ if (app.forked) continue;
53063
+ if (app.publisher != null && app.publisher !== "floless") continue;
53064
+ const t = byId.get(app.templateId);
53065
+ if (!t) continue;
53066
+ if (compareSemver(t.version, app.version) <= 0) continue;
52899
53067
  out.push({
52900
- id: t.id,
52901
- installed: iv,
53068
+ id: app.id,
53069
+ templateId: t.id,
53070
+ installed: app.version,
52902
53071
  available: t.version,
52903
53072
  module: t.module,
52904
- changelog: changelogSince(t.changelog, iv)
53073
+ changelog: changelogSince(t.changelog, app.version)
52905
53074
  });
52906
53075
  }
52907
53076
  return out;
52908
53077
  }
53078
+ function stampSourceAppId(sourcePath, id) {
53079
+ const doc = (0, import_yaml2.parseDocument)((0, import_node_fs10.readFileSync)(sourcePath, "utf8"));
53080
+ if (doc.errors.length > 0) {
53081
+ throw new Error(`stamp app id: source is not valid YAML: ${doc.errors[0]?.message ?? "parse error"}`);
53082
+ }
53083
+ doc.set("app", id);
53084
+ (0, import_node_fs10.writeFileSync)(sourcePath, doc.toString());
53085
+ }
52909
53086
  function readTemplateMeta(path) {
52910
- const doc = (0, import_yaml2.parse)((0, import_node_fs8.readFileSync)(path, "utf8")) ?? {};
53087
+ const doc = (0, import_yaml2.parse)((0, import_node_fs10.readFileSync)(path, "utf8")) ?? {};
52911
53088
  return {
52912
53089
  id: String(doc.app ?? ""),
52913
53090
  version: doc.version != null ? String(doc.version) : "0.0.0",
@@ -52921,24 +53098,24 @@ function templatePaths(roots) {
52921
53098
  const envDir = process.env.FLOLESS_TEMPLATES_DIR;
52922
53099
  const flatDirs = roots ?? [
52923
53100
  ...envDir ? [envDir] : [],
52924
- (0, import_node_path7.join)(here, "templates"),
53101
+ (0, import_node_path9.join)(here, "templates"),
52925
53102
  // bundled: dist/templates beside the cjs
52926
- (0, import_node_path7.join)(here, "dist", "templates"),
53103
+ (0, import_node_path9.join)(here, "dist", "templates"),
52927
53104
  // dev: the built bundle at server/dist
52928
- (0, import_node_path7.join)((0, import_node_path7.dirname)(process.execPath), "templates")
53105
+ (0, import_node_path9.join)((0, import_node_path9.dirname)(process.execPath), "templates")
52929
53106
  // SEA exe
52930
53107
  ];
52931
53108
  for (const d of flatDirs) {
52932
- if (!(0, import_node_fs8.existsSync)(d)) continue;
52933
- const flos = (0, import_node_fs8.readdirSync)(d).filter((f) => f.endsWith(".flo"));
52934
- if (flos.length) return flos.map((f) => (0, import_node_path7.join)(d, f));
53109
+ if (!(0, import_node_fs10.existsSync)(d)) continue;
53110
+ const flos = (0, import_node_fs10.readdirSync)(d).filter((f) => f.endsWith(".flo"));
53111
+ if (flos.length) return flos.map((f) => (0, import_node_path9.join)(d, f));
52935
53112
  }
52936
- for (const demos of [(0, import_node_path7.join)(here, "..", "demos"), (0, import_node_path7.join)(here, "..", "..", "demos")]) {
52937
- if (!(0, import_node_fs8.existsSync)(demos)) continue;
53113
+ for (const demos of [(0, import_node_path9.join)(here, "..", "demos"), (0, import_node_path9.join)(here, "..", "..", "demos")]) {
53114
+ if (!(0, import_node_fs10.existsSync)(demos)) continue;
52938
53115
  const out = [];
52939
- for (const dir of (0, import_node_fs8.readdirSync)(demos)) {
53116
+ for (const dir of (0, import_node_fs10.readdirSync)(demos)) {
52940
53117
  try {
52941
- for (const f of (0, import_node_fs8.readdirSync)((0, import_node_path7.join)(demos, dir))) if (f.endsWith(".flo")) out.push((0, import_node_path7.join)(demos, dir, f));
53118
+ for (const f of (0, import_node_fs10.readdirSync)((0, import_node_path9.join)(demos, dir))) if (f.endsWith(".flo")) out.push((0, import_node_path9.join)(demos, dir, f));
52942
53119
  } catch {
52943
53120
  }
52944
53121
  }
@@ -52958,19 +53135,19 @@ function loadTemplates(roots) {
52958
53135
  return out;
52959
53136
  }
52960
53137
  function backupDir(id, version, ts) {
52961
- const root = process.env.FLOLESS_HOME ?? (0, import_node_path7.join)((0, import_node_os7.homedir)(), ".floless");
53138
+ const root = process.env.FLOLESS_HOME ?? (0, import_node_path9.join)((0, import_node_os9.homedir)(), ".floless");
52962
53139
  const safe = (s) => {
52963
53140
  const c = String(s).replace(/[^0-9A-Za-z._-]/g, "_");
52964
53141
  return /^\.+$/.test(c) ? "_" : c || "_";
52965
53142
  };
52966
- return (0, import_node_path7.join)(root, "app-backups", safe(id), `${safe(version)}-${ts}`);
53143
+ return (0, import_node_path9.join)(root, "app-backups", safe(id), `${safe(version)}-${ts}`);
52967
53144
  }
52968
53145
 
52969
53146
  // oauth-presets.ts
52970
- var import_node_os8 = require("node:os");
52971
- var import_node_path8 = require("node:path");
53147
+ var import_node_os10 = require("node:os");
53148
+ var import_node_path10 = require("node:path");
52972
53149
  var import_node_net = __toESM(require("node:net"), 1);
52973
- var import_node_fs9 = require("node:fs");
53150
+ var import_node_fs11 = require("node:fs");
52974
53151
  var MANAGED_HEADER = "# managed by floless.app - do not edit";
52975
53152
  var OAUTH_PRESETS = {
52976
53153
  "trimble-connect": {
@@ -53000,7 +53177,7 @@ function managedProfileYaml(preset) {
53000
53177
  ].join("\n");
53001
53178
  }
53002
53179
  function oauthDir() {
53003
- return process.env.AWARE_HOME ? (0, import_node_path8.join)(process.env.AWARE_HOME, "oauth") : (0, import_node_path8.join)((0, import_node_os8.homedir)(), ".aware", "oauth");
53180
+ return process.env.AWARE_HOME ? (0, import_node_path10.join)(process.env.AWARE_HOME, "oauth") : (0, import_node_path10.join)((0, import_node_os10.homedir)(), ".aware", "oauth");
53004
53181
  }
53005
53182
  function isUpgradableLegacyProfile(existing, preset) {
53006
53183
  if (existing.startsWith(MANAGED_HEADER)) return false;
@@ -53014,15 +53191,15 @@ function ensureManagedProfile(id) {
53014
53191
  const preset = OAUTH_PRESETS[id];
53015
53192
  if (!preset) return "not-managed";
53016
53193
  const dir = oauthDir();
53017
- const file = (0, import_node_path8.join)(dir, `${id}.yaml`);
53018
- const existing = (0, import_node_fs9.existsSync)(file) ? (0, import_node_fs9.readFileSync)(file, "utf8") : null;
53194
+ const file = (0, import_node_path10.join)(dir, `${id}.yaml`);
53195
+ const existing = (0, import_node_fs11.existsSync)(file) ? (0, import_node_fs11.readFileSync)(file, "utf8") : null;
53019
53196
  if (existing !== null && !existing.startsWith(MANAGED_HEADER) && !isUpgradableLegacyProfile(existing, preset)) {
53020
53197
  return "skipped";
53021
53198
  }
53022
53199
  const desired = managedProfileYaml(preset);
53023
53200
  if (existing === desired) return "unchanged";
53024
- (0, import_node_fs9.mkdirSync)(dir, { recursive: true });
53025
- (0, import_node_fs9.writeFileSync)(file, desired, "utf8");
53201
+ (0, import_node_fs11.mkdirSync)(dir, { recursive: true });
53202
+ (0, import_node_fs11.writeFileSync)(file, desired, "utf8");
53026
53203
  return "written";
53027
53204
  }
53028
53205
  function isPortBindable(port, host = "127.0.0.1") {
@@ -53193,16 +53370,16 @@ function buildPreview(m, sourceKind, sourceRef, stagedRef) {
53193
53370
  }
53194
53371
 
53195
53372
  // graft-manifest-reader.ts
53196
- var import_node_fs10 = require("node:fs");
53197
- var import_node_path9 = require("node:path");
53373
+ var import_node_fs12 = require("node:fs");
53374
+ var import_node_path11 = require("node:path");
53198
53375
  var import_yaml4 = __toESM(require_dist6(), 1);
53199
53376
  var asRecord2 = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
53200
53377
  function readStagedManifest(agentDir) {
53201
- const manifestPath = (0, import_node_path9.join)(agentDir, "manifest.yaml");
53202
- if (!(0, import_node_fs10.existsSync)(manifestPath)) return null;
53378
+ const manifestPath = (0, import_node_path11.join)(agentDir, "manifest.yaml");
53379
+ if (!(0, import_node_fs12.existsSync)(manifestPath)) return null;
53203
53380
  let doc;
53204
53381
  try {
53205
- doc = asRecord2((0, import_yaml4.parse)((0, import_node_fs10.readFileSync)(manifestPath, "utf8")));
53382
+ doc = asRecord2((0, import_yaml4.parse)((0, import_node_fs12.readFileSync)(manifestPath, "utf8")));
53206
53383
  } catch {
53207
53384
  return null;
53208
53385
  }
@@ -53232,10 +53409,10 @@ function readStagedManifest(agentDir) {
53232
53409
  }
53233
53410
  let skillCount = Array.isArray(doc.skills) ? doc.skills.length : 0;
53234
53411
  if (!skillCount) {
53235
- const skillsDir = (0, import_node_path9.join)(agentDir, "skills");
53236
- if ((0, import_node_fs10.existsSync)(skillsDir)) {
53412
+ const skillsDir = (0, import_node_path11.join)(agentDir, "skills");
53413
+ if ((0, import_node_fs12.existsSync)(skillsDir)) {
53237
53414
  try {
53238
- skillCount = (0, import_node_fs10.readdirSync)(skillsDir).filter((f) => f.endsWith(".md")).length;
53415
+ skillCount = (0, import_node_fs12.readdirSync)(skillsDir).filter((f) => f.endsWith(".md")).length;
53239
53416
  } catch {
53240
53417
  }
53241
53418
  }
@@ -53249,7 +53426,7 @@ function readStagedManifest(agentDir) {
53249
53426
  }
53250
53427
 
53251
53428
  // graft-stage-registry.ts
53252
- var import_node_fs11 = require("node:fs");
53429
+ var import_node_fs13 = require("node:fs");
53253
53430
  var TTL_MS = 30 * 60 * 1e3;
53254
53431
  var registry = /* @__PURE__ */ new Map();
53255
53432
  function registerStage(token, tempDir, agentId) {
@@ -53271,7 +53448,7 @@ function evict(token) {
53271
53448
  clearTimeout(e.timer);
53272
53449
  registry.delete(token);
53273
53450
  try {
53274
- (0, import_node_fs11.rmSync)(e.tempDir, { recursive: true, force: true });
53451
+ (0, import_node_fs13.rmSync)(e.tempDir, { recursive: true, force: true });
53275
53452
  } catch {
53276
53453
  }
53277
53454
  }
@@ -53280,8 +53457,8 @@ function clearAllStages() {
53280
53457
  }
53281
53458
 
53282
53459
  // graft-commit.ts
53283
- var import_node_fs12 = require("node:fs");
53284
- var import_node_path10 = require("node:path");
53460
+ var import_node_fs14 = require("node:fs");
53461
+ var import_node_path12 = require("node:path");
53285
53462
  var GraftCommitError = class extends Error {
53286
53463
  constructor(message, code) {
53287
53464
  super(message);
@@ -53291,34 +53468,34 @@ var GraftCommitError = class extends Error {
53291
53468
  code;
53292
53469
  };
53293
53470
  function commitStaged(tempDir, agentId, targetAgentsDir, force) {
53294
- const staged = (0, import_node_path10.join)(tempDir, "agents", agentId);
53295
- const target = (0, import_node_path10.join)(targetAgentsDir, agentId);
53296
- if ((0, import_node_fs12.existsSync)(target)) {
53471
+ const staged = (0, import_node_path12.join)(tempDir, "agents", agentId);
53472
+ const target = (0, import_node_path12.join)(targetAgentsDir, agentId);
53473
+ if ((0, import_node_fs14.existsSync)(target)) {
53297
53474
  if (!force) throw new GraftCommitError(`an agent named "${agentId}" is already installed`, "collision");
53298
- (0, import_node_fs12.rmSync)(target, { recursive: true, force: true });
53475
+ (0, import_node_fs14.rmSync)(target, { recursive: true, force: true });
53299
53476
  }
53300
- (0, import_node_fs12.mkdirSync)(targetAgentsDir, { recursive: true });
53477
+ (0, import_node_fs14.mkdirSync)(targetAgentsDir, { recursive: true });
53301
53478
  try {
53302
- (0, import_node_fs12.renameSync)(staged, target);
53479
+ (0, import_node_fs14.renameSync)(staged, target);
53303
53480
  } catch {
53304
- (0, import_node_fs12.cpSync)(staged, target, { recursive: true });
53481
+ (0, import_node_fs14.cpSync)(staged, target, { recursive: true });
53305
53482
  }
53306
- (0, import_node_fs12.rmSync)(tempDir, { recursive: true, force: true });
53483
+ (0, import_node_fs14.rmSync)(tempDir, { recursive: true, force: true });
53307
53484
  return { agentId };
53308
53485
  }
53309
53486
  function matchAssemblies(globOrDir) {
53310
53487
  let dir;
53311
53488
  let pattern;
53312
- if ((0, import_node_fs12.existsSync)(globOrDir) && (0, import_node_fs12.statSync)(globOrDir).isDirectory()) {
53489
+ if ((0, import_node_fs14.existsSync)(globOrDir) && (0, import_node_fs14.statSync)(globOrDir).isDirectory()) {
53313
53490
  dir = globOrDir;
53314
53491
  pattern = "*.dll";
53315
53492
  } else {
53316
- dir = (0, import_node_path10.dirname)(globOrDir);
53317
- pattern = (0, import_node_path10.basename)(globOrDir);
53493
+ dir = (0, import_node_path12.dirname)(globOrDir);
53494
+ pattern = (0, import_node_path12.basename)(globOrDir);
53318
53495
  }
53319
- if (!dir || !(0, import_node_fs12.existsSync)(dir) || !(0, import_node_fs12.statSync)(dir).isDirectory()) return [];
53496
+ if (!dir || !(0, import_node_fs14.existsSync)(dir) || !(0, import_node_fs14.statSync)(dir).isDirectory()) return [];
53320
53497
  const re = globToRegExp(pattern);
53321
- return (0, import_node_fs12.readdirSync)(dir).filter((f) => re.test(f)).sort();
53498
+ return (0, import_node_fs14.readdirSync)(dir).filter((f) => re.test(f)).sort();
53322
53499
  }
53323
53500
  function globToRegExp(p) {
53324
53501
  const esc = p.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
@@ -53326,25 +53503,25 @@ function globToRegExp(p) {
53326
53503
  }
53327
53504
 
53328
53505
  // floless-store.ts
53329
- var import_node_crypto4 = require("node:crypto");
53330
- var import_node_fs13 = require("node:fs");
53331
- var import_node_os9 = require("node:os");
53332
- var import_node_path11 = require("node:path");
53333
- var ROOT2 = process.env.FLOLESS_HOME ?? (0, import_node_path11.join)((0, import_node_os9.homedir)(), ".floless");
53334
- var TEMPLATES_FILE = (0, import_node_path11.join)(ROOT2, "templates.json");
53335
- var REQUESTS_DIR = (0, import_node_path11.join)(ROOT2, "requests");
53506
+ var import_node_crypto5 = require("node:crypto");
53507
+ var import_node_fs15 = require("node:fs");
53508
+ var import_node_os11 = require("node:os");
53509
+ var import_node_path13 = require("node:path");
53510
+ var ROOT2 = process.env.FLOLESS_HOME ?? (0, import_node_path13.join)((0, import_node_os11.homedir)(), ".floless");
53511
+ var TEMPLATES_FILE = (0, import_node_path13.join)(ROOT2, "templates.json");
53512
+ var REQUESTS_DIR = (0, import_node_path13.join)(ROOT2, "requests");
53336
53513
  function ensureRoot() {
53337
- if (!(0, import_node_fs13.existsSync)(ROOT2)) (0, import_node_fs13.mkdirSync)(ROOT2, { recursive: true });
53514
+ if (!(0, import_node_fs15.existsSync)(ROOT2)) (0, import_node_fs15.mkdirSync)(ROOT2, { recursive: true });
53338
53515
  }
53339
53516
  function withinRequestsDir(p) {
53340
- const base = (0, import_node_path11.resolve)(REQUESTS_DIR);
53341
- const full = (0, import_node_path11.resolve)(p);
53342
- return full === base || full.startsWith(base + import_node_path11.sep);
53517
+ const base = (0, import_node_path13.resolve)(REQUESTS_DIR);
53518
+ const full = (0, import_node_path13.resolve)(p);
53519
+ return full === base || full.startsWith(base + import_node_path13.sep);
53343
53520
  }
53344
53521
  function listTemplates() {
53345
- if (!(0, import_node_fs13.existsSync)(TEMPLATES_FILE)) return [];
53522
+ if (!(0, import_node_fs15.existsSync)(TEMPLATES_FILE)) return [];
53346
53523
  try {
53347
- const parsed = JSON.parse((0, import_node_fs13.readFileSync)(TEMPLATES_FILE, "utf8"));
53524
+ const parsed = JSON.parse((0, import_node_fs15.readFileSync)(TEMPLATES_FILE, "utf8"));
53348
53525
  return Array.isArray(parsed) ? parsed : [];
53349
53526
  } catch {
53350
53527
  return [];
@@ -53353,8 +53530,8 @@ function listTemplates() {
53353
53530
  function writeTemplates(list) {
53354
53531
  ensureRoot();
53355
53532
  const tmp = `${TEMPLATES_FILE}.${process.pid}.tmp`;
53356
- (0, import_node_fs13.writeFileSync)(tmp, JSON.stringify(list, null, 2));
53357
- (0, import_node_fs13.renameSync)(tmp, TEMPLATES_FILE);
53533
+ (0, import_node_fs15.writeFileSync)(tmp, JSON.stringify(list, null, 2));
53534
+ (0, import_node_fs15.renameSync)(tmp, TEMPLATES_FILE);
53358
53535
  }
53359
53536
  function addTemplate(input) {
53360
53537
  const list = listTemplates();
@@ -53365,7 +53542,7 @@ function addTemplate(input) {
53365
53542
  if (dup) return dup;
53366
53543
  }
53367
53544
  const tpl = {
53368
- id: (0, import_node_crypto4.randomUUID)(),
53545
+ id: (0, import_node_crypto5.randomUUID)(),
53369
53546
  name: input.name.trim(),
53370
53547
  category: (input.category || "Uncategorized").trim(),
53371
53548
  node: input.node,
@@ -53386,12 +53563,12 @@ function deleteTemplate(id) {
53386
53563
  function getTemplate(id) {
53387
53564
  return listTemplates().find((t) => t.id === id) ?? null;
53388
53565
  }
53389
- function updateTemplate(id, patch) {
53566
+ function updateTemplate(id, patch2) {
53390
53567
  const list = listTemplates();
53391
53568
  const cur = list.find((t) => t.id === id);
53392
53569
  if (!cur) return null;
53393
- const name = patch.name?.trim();
53394
- const category = patch.category?.trim();
53570
+ const name = patch2.name?.trim();
53571
+ const category = patch2.category?.trim();
53395
53572
  cur.name = name || cur.name;
53396
53573
  cur.category = category || cur.category;
53397
53574
  writeTemplates(list);
@@ -53399,13 +53576,13 @@ function updateTemplate(id, patch) {
53399
53576
  }
53400
53577
  function addRequest(req, decoded = []) {
53401
53578
  ensureRoot();
53402
- if (!(0, import_node_fs13.existsSync)(REQUESTS_DIR)) (0, import_node_fs13.mkdirSync)(REQUESTS_DIR, { recursive: true });
53403
- const id = (0, import_node_crypto4.randomUUID)();
53579
+ if (!(0, import_node_fs15.existsSync)(REQUESTS_DIR)) (0, import_node_fs15.mkdirSync)(REQUESTS_DIR, { recursive: true });
53580
+ const id = (0, import_node_crypto5.randomUUID)();
53404
53581
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
53405
53582
  const base = `${createdAt.replace(/[:.]/g, "-")}__${id}`;
53406
53583
  const snapshots = decoded.map((d, i) => {
53407
- const p = (0, import_node_path11.join)(REQUESTS_DIR, `${base}__snap${i + 1}.${d.ext}`);
53408
- (0, import_node_fs13.writeFileSync)(p, d.buf);
53584
+ const p = (0, import_node_path13.join)(REQUESTS_DIR, `${base}__snap${i + 1}.${d.ext}`);
53585
+ (0, import_node_fs15.writeFileSync)(p, d.buf);
53409
53586
  return p;
53410
53587
  });
53411
53588
  const full = {
@@ -53415,55 +53592,55 @@ function addRequest(req, decoded = []) {
53415
53592
  ...req,
53416
53593
  ...snapshots.length ? { snapshots } : {}
53417
53594
  };
53418
- (0, import_node_fs13.writeFileSync)((0, import_node_path11.join)(REQUESTS_DIR, `${base}.json`), JSON.stringify(full, null, 2));
53595
+ (0, import_node_fs15.writeFileSync)((0, import_node_path13.join)(REQUESTS_DIR, `${base}.json`), JSON.stringify(full, null, 2));
53419
53596
  return full;
53420
53597
  }
53421
53598
  function listRequests() {
53422
- if (!(0, import_node_fs13.existsSync)(REQUESTS_DIR)) return [];
53423
- return (0, import_node_fs13.readdirSync)(REQUESTS_DIR).filter((f) => f.endsWith(".json")).sort().map((f) => {
53599
+ if (!(0, import_node_fs15.existsSync)(REQUESTS_DIR)) return [];
53600
+ return (0, import_node_fs15.readdirSync)(REQUESTS_DIR).filter((f) => f.endsWith(".json")).sort().map((f) => {
53424
53601
  try {
53425
- return JSON.parse((0, import_node_fs13.readFileSync)((0, import_node_path11.join)(REQUESTS_DIR, f), "utf8"));
53602
+ return JSON.parse((0, import_node_fs15.readFileSync)((0, import_node_path13.join)(REQUESTS_DIR, f), "utf8"));
53426
53603
  } catch {
53427
53604
  return null;
53428
53605
  }
53429
53606
  }).filter((r) => r !== null);
53430
53607
  }
53431
53608
  function deleteRequest(id) {
53432
- if (!(0, import_node_fs13.existsSync)(REQUESTS_DIR)) return false;
53433
- const file = (0, import_node_fs13.readdirSync)(REQUESTS_DIR).find((f) => f.endsWith(`__${id}.json`));
53609
+ if (!(0, import_node_fs15.existsSync)(REQUESTS_DIR)) return false;
53610
+ const file = (0, import_node_fs15.readdirSync)(REQUESTS_DIR).find((f) => f.endsWith(`__${id}.json`));
53434
53611
  if (!file) return false;
53435
53612
  try {
53436
- const parsed = JSON.parse((0, import_node_fs13.readFileSync)((0, import_node_path11.join)(REQUESTS_DIR, file), "utf8"));
53613
+ const parsed = JSON.parse((0, import_node_fs15.readFileSync)((0, import_node_path13.join)(REQUESTS_DIR, file), "utf8"));
53437
53614
  for (const p of parsed.snapshots ?? []) {
53438
53615
  if (!withinRequestsDir(p)) continue;
53439
53616
  try {
53440
- (0, import_node_fs13.rmSync)(p);
53617
+ (0, import_node_fs15.rmSync)(p);
53441
53618
  } catch {
53442
53619
  }
53443
53620
  }
53444
53621
  } catch {
53445
53622
  }
53446
- (0, import_node_fs13.rmSync)((0, import_node_path11.join)(REQUESTS_DIR, file));
53623
+ (0, import_node_fs15.rmSync)((0, import_node_path13.join)(REQUESTS_DIR, file));
53447
53624
  return true;
53448
53625
  }
53449
53626
  function clearRequests() {
53450
- if (!(0, import_node_fs13.existsSync)(REQUESTS_DIR)) return 0;
53451
- const allFiles = (0, import_node_fs13.readdirSync)(REQUESTS_DIR);
53627
+ if (!(0, import_node_fs15.existsSync)(REQUESTS_DIR)) return 0;
53628
+ const allFiles = (0, import_node_fs15.readdirSync)(REQUESTS_DIR);
53452
53629
  const jsonFiles = allFiles.filter((f) => f.endsWith(".json"));
53453
53630
  for (const f of allFiles) {
53454
53631
  try {
53455
- (0, import_node_fs13.rmSync)((0, import_node_path11.join)(REQUESTS_DIR, f));
53632
+ (0, import_node_fs15.rmSync)((0, import_node_path13.join)(REQUESTS_DIR, f));
53456
53633
  } catch {
53457
53634
  }
53458
53635
  }
53459
53636
  return jsonFiles.length;
53460
53637
  }
53461
53638
  function snapshotPathFor(id, n) {
53462
- if (!(0, import_node_fs13.existsSync)(REQUESTS_DIR)) return null;
53463
- const file = (0, import_node_fs13.readdirSync)(REQUESTS_DIR).find((f) => f.endsWith(`__${id}.json`));
53639
+ if (!(0, import_node_fs15.existsSync)(REQUESTS_DIR)) return null;
53640
+ const file = (0, import_node_fs15.readdirSync)(REQUESTS_DIR).find((f) => f.endsWith(`__${id}.json`));
53464
53641
  if (!file) return null;
53465
53642
  try {
53466
- const parsed = JSON.parse((0, import_node_fs13.readFileSync)((0, import_node_path11.join)(REQUESTS_DIR, file), "utf8"));
53643
+ const parsed = JSON.parse((0, import_node_fs15.readFileSync)((0, import_node_path13.join)(REQUESTS_DIR, file), "utf8"));
53467
53644
  const cand = parsed.snapshots?.[n] ?? null;
53468
53645
  return cand && withinRequestsDir(cand) ? cand : null;
53469
53646
  } catch {
@@ -53474,8 +53651,8 @@ var flolessRoot = ROOT2;
53474
53651
  var SnapshotError = class extends Error {
53475
53652
  };
53476
53653
  var MAX_SNAPSHOTS = 8;
53477
- var MAX_BYTES2 = 25 * 1024 * 1024;
53478
- function sniffExt(buf) {
53654
+ var MAX_BYTES3 = 25 * 1024 * 1024;
53655
+ function sniffExt2(buf) {
53479
53656
  if (buf.length >= 8 && buf[0] === 137 && buf[1] === 80 && buf[2] === 78 && buf[3] === 71) return "png";
53480
53657
  if (buf.length >= 3 && buf[0] === 255 && buf[1] === 216 && buf[2] === 255) return "jpg";
53481
53658
  if (buf.length >= 12 && buf.toString("ascii", 0, 4) === "RIFF" && buf.toString("ascii", 8, 12) === "WEBP") return "webp";
@@ -53488,100 +53665,24 @@ function decodeSnapshots(inputs) {
53488
53665
  return inputs.map((s) => {
53489
53666
  const m = /^data:([\w/+.-]+);base64,(.*)$/s.exec(s.dataUrl || "");
53490
53667
  if (!m) throw new SnapshotError("snapshot must be a base64 data URL");
53491
- if ((m[2]?.length ?? 0) * 0.75 > MAX_BYTES2) throw new SnapshotError("snapshot too large (max 25 MB)");
53668
+ if ((m[2]?.length ?? 0) * 0.75 > MAX_BYTES3) throw new SnapshotError("snapshot too large (max 25 MB)");
53492
53669
  const buf = Buffer.from(m[2] ?? "", "base64");
53493
53670
  if (buf.length === 0) throw new SnapshotError("empty snapshot");
53494
- if (buf.length > MAX_BYTES2) throw new SnapshotError("snapshot too large (max 25 MB)");
53495
- const ext = sniffExt(buf);
53671
+ if (buf.length > MAX_BYTES3) throw new SnapshotError("snapshot too large (max 25 MB)");
53672
+ const ext = sniffExt2(buf);
53496
53673
  if (!ext) throw new SnapshotError("snapshot must be PNG, JPEG, WebP, or PDF");
53497
53674
  return { buf, ext };
53498
53675
  });
53499
53676
  }
53500
53677
 
53501
- // visual-input-store.ts
53502
- var import_node_crypto5 = require("node:crypto");
53503
- var import_node_fs14 = require("node:fs");
53504
- var import_node_os10 = require("node:os");
53505
- var import_node_path12 = require("node:path");
53506
- var MAX_BYTES3 = 25 * 1024 * 1024;
53507
- var VisualInputError = class extends Error {
53508
- };
53509
- function inputsDir() {
53510
- const root = process.env.FLOLESS_HOME ?? (0, import_node_path12.join)((0, import_node_os10.homedir)(), ".floless");
53511
- return (0, import_node_path12.join)(root, "inputs");
53512
- }
53513
- function sniffExt2(buf) {
53514
- if (buf.length >= 8 && buf[0] === 137 && buf[1] === 80 && buf[2] === 78 && buf[3] === 71) return "png";
53515
- if (buf.length >= 3 && buf[0] === 255 && buf[1] === 216 && buf[2] === 255) return "jpg";
53516
- if (buf.length >= 12 && buf.toString("ascii", 0, 4) === "RIFF" && buf.toString("ascii", 8, 12) === "WEBP") return "webp";
53517
- if (buf.length >= 5 && buf.toString("ascii", 0, 5) === "%PDF-") return "pdf";
53518
- return null;
53519
- }
53520
- var RESERVED = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..*)?$/i;
53521
- function safeSegment(s) {
53522
- if (!s || s === "." || s.includes("..")) return false;
53523
- if (s.includes("/") || s.includes("\\") || s.includes(import_node_path12.sep)) return false;
53524
- for (let i = 0; i < s.length; i++) {
53525
- const c = s.charCodeAt(i);
53526
- if (c < 32 || c === 58) return false;
53527
- }
53528
- if (/[. ]$/.test(s)) return false;
53529
- return !RESERVED.test(s);
53530
- }
53531
- function storeVisualInput(appId, dataUrl) {
53532
- if (!safeSegment(appId)) throw new VisualInputError("invalid app id");
53533
- const m = /^data:([\w/+.-]+);base64,(.*)$/s.exec(dataUrl || "");
53534
- if (!m) throw new VisualInputError("visual input must be a base64 data URL");
53535
- const buf = Buffer.from(m[2] ?? "", "base64");
53536
- if (buf.length === 0) throw new VisualInputError("empty visual input");
53537
- if (buf.length > MAX_BYTES3) throw new VisualInputError("visual input too large (max 25 MB)");
53538
- const ext = sniffExt2(buf);
53539
- if (!ext) throw new VisualInputError("visual input must be PNG, JPEG, WebP, or PDF");
53540
- const sha2562 = (0, import_node_crypto5.createHash)("sha256").update(buf).digest("hex");
53541
- const dir = (0, import_node_path12.join)(inputsDir(), appId);
53542
- const path = (0, import_node_path12.join)(dir, `${sha2562}.${ext}`);
53543
- const root = (0, import_node_path12.resolve)(inputsDir());
53544
- const target = (0, import_node_path12.resolve)(path);
53545
- if (target !== root && !target.startsWith(root + import_node_path12.sep)) {
53546
- throw new VisualInputError("refusing to write outside the inputs root");
53547
- }
53548
- (0, import_node_fs14.mkdirSync)(dir, { recursive: true });
53549
- if (!(0, import_node_fs14.existsSync)(path)) {
53550
- const tmp = `${path}.tmp`;
53551
- (0, import_node_fs14.writeFileSync)(tmp, buf);
53552
- (0, import_node_fs14.renameSync)(tmp, path);
53553
- }
53554
- return { path, ext, bytes: (0, import_node_fs14.statSync)(path).size, sha256: sha2562 };
53555
- }
53556
- function renameVisualInputs(oldId, newId) {
53557
- if (!safeSegment(oldId) || !safeSegment(newId)) throw new VisualInputError("invalid app id");
53558
- const from = (0, import_node_path12.join)(inputsDir(), oldId);
53559
- if (!(0, import_node_fs14.existsSync)(from)) return;
53560
- const to = (0, import_node_path12.join)(inputsDir(), newId);
53561
- if ((0, import_node_fs14.existsSync)(to)) (0, import_node_fs14.rmSync)(to, { recursive: true, force: true });
53562
- (0, import_node_fs14.mkdirSync)(inputsDir(), { recursive: true });
53563
- (0, import_node_fs14.renameSync)(from, to);
53564
- }
53565
- function copyVisualInputs(srcId, newId) {
53566
- if (!safeSegment(srcId) || !safeSegment(newId)) throw new VisualInputError("invalid app id");
53567
- const from = (0, import_node_path12.join)(inputsDir(), srcId);
53568
- if (!(0, import_node_fs14.existsSync)(from)) return;
53569
- (0, import_node_fs14.cpSync)(from, (0, import_node_path12.join)(inputsDir(), newId), { recursive: true });
53570
- }
53571
- function deleteVisualInputs(id) {
53572
- if (!safeSegment(id)) throw new VisualInputError("invalid app id");
53573
- const dir = (0, import_node_path12.join)(inputsDir(), id);
53574
- if ((0, import_node_fs14.existsSync)(dir)) (0, import_node_fs14.rmSync)(dir, { recursive: true, force: true });
53575
- }
53576
-
53577
53678
  // contract-store.ts
53578
- var import_node_fs16 = require("node:fs");
53579
- var import_node_path14 = require("node:path");
53580
- var import_node_os11 = require("node:os");
53679
+ var import_node_fs17 = require("node:fs");
53680
+ var import_node_path15 = require("node:path");
53681
+ var import_node_os12 = require("node:os");
53581
53682
 
53582
53683
  // contract-schema.ts
53583
- var import_node_fs15 = require("node:fs");
53584
- var import_node_path13 = require("node:path");
53684
+ var import_node_fs16 = require("node:fs");
53685
+ var import_node_path14 = require("node:path");
53585
53686
  var import_node_url2 = require("node:url");
53586
53687
  function validate(doc, schema) {
53587
53688
  const errors = [];
@@ -53682,16 +53783,16 @@ function walk(value, node, root, path, errors) {
53682
53783
  var _cached = null;
53683
53784
  function loadSteelTakeoffSchema() {
53684
53785
  if (_cached) return _cached;
53685
- const here2 = (0, import_node_path13.dirname)((0, import_node_url2.fileURLToPath)(__import_meta_url));
53786
+ const here2 = (0, import_node_path14.dirname)((0, import_node_url2.fileURLToPath)(__import_meta_url));
53686
53787
  const candidates = [
53687
- (0, import_node_path13.join)(here2, "..", "schemas", "steel.takeoff.v1.schema.json"),
53788
+ (0, import_node_path14.join)(here2, "..", "schemas", "steel.takeoff.v1.schema.json"),
53688
53789
  // dev: server/ next to schemas/
53689
- (0, import_node_path13.join)(here2, "schemas", "steel.takeoff.v1.schema.json")
53790
+ (0, import_node_path14.join)(here2, "schemas", "steel.takeoff.v1.schema.json")
53690
53791
  // bundled: dist/ holds ./schemas
53691
53792
  ];
53692
53793
  for (const p of candidates) {
53693
53794
  try {
53694
- const text = (0, import_node_fs15.readFileSync)(p, "utf8");
53795
+ const text = (0, import_node_fs16.readFileSync)(p, "utf8");
53695
53796
  _cached = JSON.parse(text);
53696
53797
  return _cached;
53697
53798
  } catch (err2) {
@@ -53707,20 +53808,20 @@ function validateSteelTakeoff(doc) {
53707
53808
  // contract-store.ts
53708
53809
  var ContractError = class extends Error {
53709
53810
  };
53710
- var ROOT3 = process.env.FLOLESS_HOME ?? (0, import_node_path14.join)((0, import_node_os11.homedir)(), ".floless");
53711
- var DIR = (0, import_node_path14.join)(ROOT3, "contracts");
53811
+ var ROOT3 = process.env.FLOLESS_HOME ?? (0, import_node_path15.join)((0, import_node_os12.homedir)(), ".floless");
53812
+ var DIR = (0, import_node_path15.join)(ROOT3, "contracts");
53712
53813
  function safeId(appId) {
53713
53814
  if (!/^[a-z0-9][a-z0-9._-]*$/i.test(appId)) throw new ContractError(`invalid appId: ${appId}`);
53714
53815
  return appId;
53715
53816
  }
53716
53817
  function contractPath(appId) {
53717
- return (0, import_node_path14.join)(DIR, `${safeId(appId)}.json`);
53818
+ return (0, import_node_path15.join)(DIR, `${safeId(appId)}.json`);
53718
53819
  }
53719
53820
  function readContract(appId) {
53720
53821
  const p = contractPath(appId);
53721
- if (!(0, import_node_fs16.existsSync)(p)) return null;
53822
+ if (!(0, import_node_fs17.existsSync)(p)) return null;
53722
53823
  try {
53723
- return JSON.parse((0, import_node_fs16.readFileSync)(p, "utf8"));
53824
+ return JSON.parse((0, import_node_fs17.readFileSync)(p, "utf8"));
53724
53825
  } catch (e) {
53725
53826
  console.warn(`readContract: ignoring unreadable contract at ${p}: ${e instanceof Error ? e.message : e}`);
53726
53827
  return null;
@@ -53733,8 +53834,8 @@ function writeContract(appId, doc) {
53733
53834
  const first = res.errors.slice(0, 5).map((e) => `${e.path}: ${e.message}`).join("; ");
53734
53835
  throw new ContractError(`contract failed schema validation \u2014 ${first}`);
53735
53836
  }
53736
- if (!(0, import_node_fs16.existsSync)(DIR)) (0, import_node_fs16.mkdirSync)(DIR, { recursive: true });
53737
- (0, import_node_fs16.writeFileSync)(p, JSON.stringify(doc));
53837
+ if (!(0, import_node_fs17.existsSync)(DIR)) (0, import_node_fs17.mkdirSync)(DIR, { recursive: true });
53838
+ (0, import_node_fs17.writeFileSync)(p, JSON.stringify(doc));
53738
53839
  }
53739
53840
 
53740
53841
  // contract-resolve.ts
@@ -53756,10 +53857,10 @@ function readContractForApp(appId, readAppFn = readApp) {
53756
53857
  }
53757
53858
 
53758
53859
  // contract-bake.ts
53759
- var import_node_fs17 = require("node:fs");
53860
+ var import_node_fs18 = require("node:fs");
53760
53861
  var import_yaml5 = __toESM(require_dist6(), 1);
53761
53862
  function bakeContractIntoApp(sourcePath, contract) {
53762
- const doc = (0, import_yaml5.parseDocument)((0, import_node_fs17.readFileSync)(sourcePath, "utf8"));
53863
+ const doc = (0, import_yaml5.parseDocument)((0, import_node_fs18.readFileSync)(sourcePath, "utf8"));
53763
53864
  if (doc.errors.length > 0) {
53764
53865
  throw new Error(`contract bake: source is not valid YAML: ${doc.errors[0]?.message ?? "parse error"}`);
53765
53866
  }
@@ -53802,7 +53903,389 @@ function bakeContractIntoApp(sourcePath, contract) {
53802
53903
  baked.filter = next;
53803
53904
  }
53804
53905
  doc.setIn(["nodes", idx, "config", "takeoff"], baked);
53805
- (0, import_node_fs17.writeFileSync)(sourcePath, doc.toString());
53906
+ (0, import_node_fs18.writeFileSync)(sourcePath, doc.toString());
53907
+ }
53908
+
53909
+ // steel-joints.ts
53910
+ var GROUPS = {
53911
+ "base-plate": { key: "base-plate", label: "Base plates", color: "#6b7a8d" },
53912
+ // darkest plate grey
53913
+ "washer-plate": { key: "washer-plate", label: "Washer plates", color: "#9aafc3" },
53914
+ anchor: { key: "anchor", label: "Anchor rods", color: "#b0c4d8" },
53915
+ // cool zinc-grey
53916
+ nut: { key: "nut", label: "Nuts", color: "#7a8a9e" },
53917
+ washer: { key: "washer", label: "Washers", color: "#dde4ed" },
53918
+ // lightest zinc
53919
+ weld: { key: "weld", label: "Welds", color: "#f97316" },
53920
+ // weld orange (heat) — off the UI error-red
53921
+ // Shear-plate kit — same muted steel band; the fin plate a touch lighter than the base plate so the
53922
+ // two connection types are tellable apart in a mixed model, bolts on the zinc fastener grey.
53923
+ "shear-plate": { key: "shear-plate", label: "Shear plates", color: "#7d8ba0" },
53924
+ bolt: { key: "bolt", label: "Bolts", color: "#b0c4d8" },
53925
+ // cool zinc-grey (matches the anchor fasteners)
53926
+ stiffener: { key: "stiffener", label: "Stiffeners", color: "#9aafc3" },
53927
+ cope: { key: "cope", label: "Copes", color: "#c2703a" }
53928
+ // a muted cut/burn amber — the removed corner (subtractive; rendered as the notch, not a swatch mesh)
53929
+ };
53930
+ var EMBED = 1;
53931
+ function num(params, key, def) {
53932
+ const v = params?.[key];
53933
+ return typeof v === "number" && isFinite(v) ? v : def;
53934
+ }
53935
+ function pos(params, key, def) {
53936
+ const v = num(params, key, def);
53937
+ return v > 0 ? v : def;
53938
+ }
53939
+ function intMin1(params, key, def) {
53940
+ return Math.max(1, Math.round(num(params, key, def)));
53941
+ }
53942
+ function finite3(a) {
53943
+ return Array.isArray(a) && a.length >= 3 && a.every((n) => typeof n === "number" && isFinite(n));
53944
+ }
53945
+ function spread(n, half) {
53946
+ if (n <= 1) return [0];
53947
+ return Array.from({ length: n }, (_, i) => -half + 2 * half * i / (n - 1));
53948
+ }
53949
+ function profileKind(profile) {
53950
+ const p = (profile || "").toUpperCase().trim();
53951
+ if (/^(W|M|S|HP|UC|UB|UKC|UKB|IPE|HE)/.test(p)) return "I";
53952
+ if (/^(C|MC|PFC)/.test(p)) return "C";
53953
+ if (/^L/.test(p)) return "L";
53954
+ if (/^(HSS|PIPE|TS|SHS|RHS|CHS|TUBE|HSQ)/.test(p)) return "TUBE";
53955
+ return "BOX";
53956
+ }
53957
+ function profileOutline(profile, w, d) {
53958
+ const hw = w / 2, hd = d / 2;
53959
+ switch (profileKind(profile)) {
53960
+ case "I": {
53961
+ const tf = Math.min(d * 0.5, Math.max(d * 0.1, 6)), tw = Math.min(w * 0.5, Math.max(w * 0.1, 5));
53962
+ return [
53963
+ [-hw, -hd],
53964
+ [hw, -hd],
53965
+ [hw, -hd + tf],
53966
+ [tw / 2, -hd + tf],
53967
+ [tw / 2, hd - tf],
53968
+ [hw, hd - tf],
53969
+ [hw, hd],
53970
+ [-hw, hd],
53971
+ [-hw, hd - tf],
53972
+ [-tw / 2, hd - tf],
53973
+ [-tw / 2, -hd + tf],
53974
+ [-hw, -hd + tf]
53975
+ ];
53976
+ }
53977
+ case "C": {
53978
+ const tf = Math.max(d * 0.1, 5), tw = Math.max(w * 0.12, 5);
53979
+ return [[-hw, -hd], [hw, -hd], [hw, -hd + tf], [-hw + tw, -hd + tf], [-hw + tw, hd - tf], [hw, hd - tf], [hw, hd], [-hw, hd]];
53980
+ }
53981
+ case "L": {
53982
+ const t = Math.max(Math.min(w, d) * 0.18, 5);
53983
+ return [[-hw, -hd], [hw, -hd], [hw, -hd + t], [-hw + t, -hd + t], [-hw + t, hd], [-hw, hd]];
53984
+ }
53985
+ default:
53986
+ return [[-hw, -hd], [hw, -hd], [hw, hd], [-hw, hd]];
53987
+ }
53988
+ }
53989
+ function expandBasePlate(joint, col) {
53990
+ const p = joint.params;
53991
+ const base = col.from[2] <= col.to[2] ? col.from : col.to;
53992
+ const [bx, by, bz] = base;
53993
+ const { w, d } = col.dims;
53994
+ const thickness = pos(p, "thickness", 25);
53995
+ const margin = Math.max(0, num(p, "margin", 75));
53996
+ const width = pos(p, "plateWidth", Math.max(w, d) + 2 * margin);
53997
+ const depth = pos(p, "plateDepth", Math.max(w, d) + 2 * margin);
53998
+ const boltDia = pos(p, "boltDia", 24);
53999
+ const clearance = num(p, "holeClearance", 6);
54000
+ const edge = num(p, "edgeDist", Math.max(1.5 * boltDia, 40));
54001
+ const cols = intMin1(p, "boltCols", 2);
54002
+ const rows = intMin1(p, "boltRows", 2);
54003
+ const weldLeg = num(p, "weldLeg", 8);
54004
+ const projBelow = num(p, "projBelow", 75);
54005
+ const nutH = pos(p, "nutHeight", 0.8 * boltDia);
54006
+ const nutAF = pos(p, "nutAcrossFlats", 1.6 * boltDia);
54007
+ const wpSide = pos(p, "washerPlateSide", 2.5 * boltDia);
54008
+ const wpThick = pos(p, "washerPlateThickness", Math.max(0.35 * boltDia, 8));
54009
+ const washerOD = pos(p, "washerOuter", 2 * boltDia);
54010
+ const washerID = boltDia + 3;
54011
+ const washerH = pos(p, "washerThickness", Math.max(0.25 * boltDia, 4));
54012
+ const levelingNut = p?.["levelingNut"] !== false;
54013
+ const SEAT = 0.5;
54014
+ const plateTop = bz + EMBED, plateBottom = plateTop - thickness;
54015
+ const us = spread(cols, Math.max(0, width / 2 - edge));
54016
+ const vs = spread(rows, Math.max(0, depth / 2 - edge));
54017
+ const holes = [];
54018
+ const kit = [];
54019
+ let k = 0;
54020
+ for (const v of vs) {
54021
+ for (const u of us) {
54022
+ const ax = bx + u, ay = by + v, jid = joint.id;
54023
+ holes.push({ u, v, d: boltDia + clearance });
54024
+ const wpBot = plateTop + SEAT, wpTop = wpBot + wpThick, washerTop = wpTop + washerH, fnTop = washerTop + nutH;
54025
+ kit.push(
54026
+ { id: `${jid}:rod${k}`, group: "anchor", kind: "rod", from: [ax, ay, plateBottom - projBelow], to: [ax, ay, fnTop + 0.4 * boltDia], d: boltDia, meta: { label: `Anchor rod \u2300${boltDia}` } },
54027
+ { id: `${jid}:wp${k}`, group: "washer-plate", kind: "plate", center: [ax, ay, wpBot + wpThick / 2], uDir: [1, 0, 0], vDir: [0, 1, 0], width: wpSide, depth: wpSide, thickness: wpThick, holes: [{ u: 0, v: 0, d: boltDia + 2 }], meta: { label: `Washer plate ${Math.round(wpSide)}\xD7${Math.round(wpSide)}\xD7${Math.round(wpThick)}` } },
54028
+ { id: `${jid}:wsh${k}`, group: "washer", kind: "washer", from: [ax, ay, wpTop], to: [ax, ay, washerTop], dOuter: washerOD, dInner: washerID, meta: { label: `Washer \u2300${Math.round(washerOD)}` } },
54029
+ { id: `${jid}:fn${k}`, group: "nut", kind: "nut", from: [ax, ay, washerTop], to: [ax, ay, fnTop], acrossFlats: nutAF, meta: { label: `Nut M${boltDia}` } }
54030
+ );
54031
+ if (levelingNut) kit.push({ id: `${jid}:ln${k}`, group: "nut", kind: "nut", from: [ax, ay, plateBottom - SEAT - nutH], to: [ax, ay, plateBottom - SEAT], acrossFlats: nutAF, meta: { label: `Leveling nut M${boltDia}` } });
54032
+ k++;
54033
+ }
54034
+ }
54035
+ const plate = {
54036
+ id: `${joint.id}:plate`,
54037
+ group: "base-plate",
54038
+ kind: "plate",
54039
+ center: [bx, by, plateBottom + thickness / 2],
54040
+ // plate top seats the column (= bz + EMBED); body hangs below
54041
+ uDir: [1, 0, 0],
54042
+ vDir: [0, 1, 0],
54043
+ width,
54044
+ depth,
54045
+ thickness,
54046
+ holes,
54047
+ meta: { label: `Base plate ${Math.round(width)}\xD7${Math.round(depth)}\xD7${Math.round(thickness)}` }
54048
+ };
54049
+ const weld = {
54050
+ id: `${joint.id}:weld`,
54051
+ group: "weld",
54052
+ kind: "weld",
54053
+ path: profileOutline(col.profile, w, d).map(([u, vv]) => [bx + u, by + vv, bz]),
54054
+ leg: weldLeg,
54055
+ meta: { label: `Fillet ${weldLeg}` }
54056
+ };
54057
+ return [plate, ...kit, weld];
54058
+ }
54059
+ function webHalfThk(profile, w) {
54060
+ return profileKind(profile) === "I" ? Math.min(w * 0.5, Math.max(w * 0.1, 5)) / 2 : 0;
54061
+ }
54062
+ function flangeThk(profile, d) {
54063
+ return profileKind(profile) === "I" ? Math.min(d * 0.5, Math.max(d * 0.1, 6)) : d / 2;
54064
+ }
54065
+ var clamp = (x, lo, hi) => Math.max(lo, Math.min(hi, x));
54066
+ function supportWorkZAt(support, pt) {
54067
+ const a = support.from, b = support.to;
54068
+ const dx = b[0] - a[0], dy = b[1] - a[1];
54069
+ const len2 = dx * dx + dy * dy;
54070
+ if (!(len2 > 1e-9)) return a[2];
54071
+ const t = clamp(((pt[0] - a[0]) * dx + (pt[1] - a[1]) * dy) / len2, 0, 1);
54072
+ return a[2] + (b[2] - a[2]) * t;
54073
+ }
54074
+ function beamCopes(beam, support, at, params) {
54075
+ if (!support || !finite3(support.from) || !finite3(support.to) || !support.dims || !(support.dims.d > 0) || !(support.dims.w > 0)) return {};
54076
+ if (!finite3(beam.from) || !finite3(beam.to) || !beam.dims || !(beam.dims.d > 0) || !(beam.dims.w > 0)) return {};
54077
+ if (profileKind(support.profile) !== "I") return {};
54078
+ const endPt = at === "end1" ? beam.to : beam.from;
54079
+ const gap = Math.max(0, num(params, "clearance", 12.7));
54080
+ const beamMidZ = endPt[2] + (typeof beam.posOffset === "number" && isFinite(beam.posOffset) ? beam.posOffset : 0);
54081
+ const beamTopZ = beamMidZ + beam.dims.d / 2, beamBotZ = beamMidZ - beam.dims.d / 2;
54082
+ const supMidZ = supportWorkZAt(support, endPt) + (typeof support.posOffset === "number" && isFinite(support.posOffset) ? support.posOffset : 0);
54083
+ const supTopZ = supMidZ + support.dims.d / 2, supBotZ = supMidZ - support.dims.d / 2;
54084
+ const tfS = flangeThk(support.profile, support.dims.d);
54085
+ const kClear = Math.max(0, num(params, "copeKClear", 12.7));
54086
+ const minLen = Math.max(0, num(params, "copeMinLength", 31.75));
54087
+ const kBand = tfS + kClear;
54088
+ const webLo = supBotZ + kBand, webHi = supTopZ - kBand;
54089
+ if (!(webLo < webHi && beamTopZ > webLo && beamBotZ < webHi)) return {};
54090
+ const length = Math.max(support.dims.w / 2 + gap, minLen);
54091
+ const out = {};
54092
+ if (beamTopZ > webHi) out.top = { depth: clamp(beamTopZ - (webHi - gap), 0, beam.dims.d), length };
54093
+ if (beamBotZ < webLo) out.bottom = { depth: clamp(webLo + gap - beamBotZ, 0, beam.dims.d), length };
54094
+ return out;
54095
+ }
54096
+ var IN = 25.4;
54097
+ function aiscBoltLength(gripMm, diaMm) {
54098
+ const Q = IN / 4;
54099
+ const raw = gripMm + diaMm + Q;
54100
+ const step = raw > 5 * IN ? 2 * Q : Q;
54101
+ return Math.ceil((raw - 1e-6) / step) * step;
54102
+ }
54103
+ function expandShearPlate(joint, beam, support) {
54104
+ const p = joint.params;
54105
+ const atEnd1 = joint.at === "end1";
54106
+ const endPt = atEnd1 ? beam.to : beam.from;
54107
+ const farPt = atEnd1 ? beam.from : beam.to;
54108
+ let ux = farPt[0] - endPt[0], uy = farPt[1] - endPt[1];
54109
+ const hLen = Math.hypot(ux, uy);
54110
+ if (!(hLen > 1e-6)) return [];
54111
+ ux /= hLen;
54112
+ uy /= hLen;
54113
+ const uDir = [ux, uy, 0];
54114
+ const vDir = [0, 0, 1];
54115
+ const nDir = [uy, -ux, 0];
54116
+ const posOff = typeof beam.posOffset === "number" && isFinite(beam.posOffset) ? beam.posOffset : 0;
54117
+ const webZ = endPt[2] + posOff;
54118
+ const P = (u, v, n) => [
54119
+ endPt[0] + uDir[0] * u + nDir[0] * n,
54120
+ endPt[1] + uDir[1] * u + nDir[1] * n,
54121
+ webZ + v
54122
+ ];
54123
+ const thickness = pos(p, "plateThickness", 10);
54124
+ const width = pos(p, "plateWidth", 120);
54125
+ const boltDia = pos(p, "boltDia", 20);
54126
+ const cols = intMin1(p, "boltCols", 1);
54127
+ const rows = intMin1(p, "boltRows", 3);
54128
+ const pitch = pos(p, "boltPitch", 70);
54129
+ const holeClr = num(p, "holeClearance", 2);
54130
+ const edge = Math.max(0, num(p, "edgeDist", Math.max(1.5 * boltDia, 30)));
54131
+ const weldLeg = num(p, "weldLeg", 6);
54132
+ const clearance = Math.max(0, num(p, "clearance", 12.7));
54133
+ const stiffener = p?.["stiffener"] === true;
54134
+ const height = pos(p, "plateHeight", (rows - 1) * pitch + 2 * edge);
54135
+ const twHalf = webHalfThk(beam.profile, beam.dims.w);
54136
+ const webSide = num(p, "webSide", 1) >= 0 ? 1 : -1;
54137
+ const pOff = webSide * (twHalf + thickness / 2);
54138
+ const edgeV = Math.min(edge, height * 0.4);
54139
+ const pV = rows > 1 ? Math.min(pitch, Math.max(0, height - 2 * edgeV) / (rows - 1)) : 0;
54140
+ const vOffs = Array.from({ length: rows }, (_, i) => (i - (rows - 1) / 2) * pV);
54141
+ const edgeU = Math.min(edge, width * 0.4);
54142
+ const regHi = Math.max(edgeU, width - edgeU);
54143
+ const regLo = Math.min(clearance + edgeU, regHi);
54144
+ const cU = (regLo + regHi) / 2;
54145
+ const pU = cols > 1 ? Math.min(pitch, (regHi - regLo) / (cols - 1)) : 0;
54146
+ const uOffs = Array.from({ length: cols }, (_, j) => cU + (j - (cols - 1) / 2) * pU);
54147
+ const nutH = 0.8 * boltDia, nutAF = 1.6 * boltDia;
54148
+ const plateOuterN = webSide * (twHalf + thickness);
54149
+ const webFarN = -webSide * twHalf;
54150
+ const headTipN = plateOuterN + webSide * nutH;
54151
+ const nutTipN = webFarN - webSide * nutH;
54152
+ const grade = p?.["boltGrade"] === "A490" ? "A490" : "A325";
54153
+ const grip = thickness + 2 * twHalf;
54154
+ const boltLen = aiscBoltLength(grip, boltDia);
54155
+ const callout = `\u2300${Math.round(boltDia)} ${grade} \xD7 ${Math.round(boltLen)}`;
54156
+ const holes = [];
54157
+ const bolts = [];
54158
+ let k = 0;
54159
+ for (const v of vOffs) {
54160
+ for (const u of uOffs) {
54161
+ const jid = joint.id;
54162
+ holes.push({ u: u - width / 2, v, d: boltDia + holeClr });
54163
+ bolts.push(
54164
+ // the shank = the AISC bolt LENGTH, from under the head (plate outer face) into the connection
54165
+ { id: `${jid}:bolt${k}`, group: "bolt", kind: "rod", from: P(u, v, plateOuterN), to: P(u, v, plateOuterN - webSide * boltLen), d: boltDia, meta: { label: `Bolt ${callout}` } },
54166
+ { id: `${jid}:head${k}`, group: "nut", kind: "nut", from: P(u, v, plateOuterN), to: P(u, v, headTipN), acrossFlats: nutAF, meta: { label: `Bolt head ${callout}` } },
54167
+ { id: `${jid}:nut${k}`, group: "nut", kind: "nut", from: P(u, v, webFarN), to: P(u, v, nutTipN), acrossFlats: nutAF, meta: { label: `Bolt nut ${callout}` } }
54168
+ );
54169
+ k++;
54170
+ }
54171
+ }
54172
+ const plate = {
54173
+ id: `${joint.id}:plate`,
54174
+ group: "shear-plate",
54175
+ kind: "plate",
54176
+ center: P(width / 2, 0, pOff),
54177
+ uDir,
54178
+ vDir,
54179
+ // welded edge at u=0 (the support); lapped on the webSide face; cantilevered +uDir toward the beam
54180
+ width,
54181
+ depth: height,
54182
+ thickness,
54183
+ holes,
54184
+ meta: { label: `Shear plate ${Math.round(width)}\xD7${Math.round(height)}\xD7${Math.round(thickness)}` }
54185
+ };
54186
+ const weld = {
54187
+ id: `${joint.id}:weld`,
54188
+ group: "weld",
54189
+ kind: "weld",
54190
+ closed: false,
54191
+ path: [P(0, -height / 2, pOff), P(0, height / 2, pOff)],
54192
+ leg: weldLeg,
54193
+ meta: { label: `Fillet ${weldLeg}` }
54194
+ };
54195
+ const parts = [plate, ...bolts, weld];
54196
+ if (stiffener) {
54197
+ if (support && support.role === "beam" && finite3(support.from) && finite3(support.to) && support.dims && support.dims.d > 0 && support.dims.w > 0) {
54198
+ const supPosOff = typeof support.posOffset === "number" && isFinite(support.posOffset) ? support.posOffset : 0;
54199
+ const twGirder = webHalfThk(support.profile, support.dims.w) * 2;
54200
+ const stiffH = support.dims.d * 0.9;
54201
+ const stiffW = Math.max(support.dims.w / 2 - twGirder / 2, thickness * 2);
54202
+ const girderCentZ = endPt[2] + supPosOff;
54203
+ const cu = -(twGirder / 2 + stiffW / 2);
54204
+ const center = [endPt[0] + uDir[0] * cu, endPt[1] + uDir[1] * cu, girderCentZ];
54205
+ parts.push({ id: `${joint.id}:stiff`, group: "stiffener", kind: "plate", center, uDir, vDir, width: stiffW, depth: stiffH, thickness, holes: [], meta: { label: `Stiffener ${Math.round(stiffW)}\xD7${Math.round(stiffH)}\xD7${Math.round(thickness)}` } });
54206
+ const wfx = endPt[0] - uDir[0] * (twGirder / 2), wfy = endPt[1] - uDir[1] * (twGirder / 2);
54207
+ parts.push({ id: `${joint.id}:stiffweld`, group: "weld", kind: "weld", closed: false, path: [[wfx, wfy, girderCentZ - stiffH / 2], [wfx, wfy, girderCentZ + stiffH / 2]], leg: weldLeg, meta: { label: `Fillet ${weldLeg}` } });
54208
+ } else {
54209
+ const oppOff = -webSide * (twHalf + thickness / 2);
54210
+ parts.push({ id: `${joint.id}:stiff`, group: "stiffener", kind: "plate", center: P(width / 2, 0, oppOff), uDir, vDir, width, depth: height, thickness, holes: [], meta: { label: `Stiffener ${Math.round(width)}\xD7${Math.round(height)}\xD7${Math.round(thickness)}` } });
54211
+ parts.push({ id: `${joint.id}:stiffweld`, group: "weld", kind: "weld", closed: false, path: [P(0, -height / 2, oppOff), P(0, height / 2, oppOff)], leg: weldLeg, meta: { label: `Fillet ${weldLeg}` } });
54212
+ }
54213
+ }
54214
+ const cope = beamCopes(beam, support, joint.at ?? "end0", p);
54215
+ const copeRadius = pos(p, "copeRadius", 12.7);
54216
+ const MIN_COPE = 1;
54217
+ const pushCope = (side, dec) => {
54218
+ if (!(dec.depth > MIN_COPE)) return;
54219
+ const lenU = dec.length + clearance;
54220
+ const vC = side === "top" ? beam.dims.d / 2 - dec.depth / 2 : -beam.dims.d / 2 + dec.depth / 2;
54221
+ parts.push({
54222
+ id: `${joint.id}:cope-${side}`,
54223
+ group: "cope",
54224
+ kind: "cut",
54225
+ member: beam.id,
54226
+ center: P(lenU / 2, vC, 0),
54227
+ uDir,
54228
+ vDir,
54229
+ width: lenU,
54230
+ depth: dec.depth,
54231
+ thickness: beam.dims.w + 2,
54232
+ radius: copeRadius,
54233
+ meta: { label: `${side === "top" ? "Top" : "Bottom"} cope ${Math.round(dec.length)}\xD7${Math.round(dec.depth)}` }
54234
+ });
54235
+ };
54236
+ if (cope.top) pushCope("top", cope.top);
54237
+ if (cope.bottom) pushCope("bottom", cope.bottom);
54238
+ return parts;
54239
+ }
54240
+ function expandJoints(joints, memberGeo) {
54241
+ const elements = [];
54242
+ const skipped = [];
54243
+ const usedGroups = /* @__PURE__ */ new Set();
54244
+ (joints ?? []).forEach((j, i) => {
54245
+ if (!j || !j.id || !j.main) {
54246
+ skipped.push(j?.id || `joint#${i}`);
54247
+ return;
54248
+ }
54249
+ if (j.kind === "base-plate") {
54250
+ const col = memberGeo.get(j.main);
54251
+ if (!col || col.role !== "column") {
54252
+ skipped.push(j.id);
54253
+ return;
54254
+ }
54255
+ if (!finite3(col.from) || !finite3(col.to) || !col.dims || !(col.dims.w > 0) || !(col.dims.d > 0)) {
54256
+ skipped.push(j.id);
54257
+ return;
54258
+ }
54259
+ for (const part of expandBasePlate(j, col)) {
54260
+ elements.push(part);
54261
+ usedGroups.add(part.group);
54262
+ }
54263
+ } else if (j.kind === "shear-plate") {
54264
+ const beam = memberGeo.get(j.main);
54265
+ if (!beam || beam.role !== "beam") {
54266
+ skipped.push(j.id);
54267
+ return;
54268
+ }
54269
+ if (!finite3(beam.from) || !finite3(beam.to) || !beam.dims || !(beam.dims.w > 0) || !(beam.dims.d > 0)) {
54270
+ skipped.push(j.id);
54271
+ return;
54272
+ }
54273
+ const support = j.secondaries && j.secondaries[0] ? memberGeo.get(j.secondaries[0]) : void 0;
54274
+ const parts = expandShearPlate(j, beam, support);
54275
+ if (!parts.length) {
54276
+ skipped.push(j.id);
54277
+ return;
54278
+ }
54279
+ for (const part of parts) {
54280
+ elements.push(part);
54281
+ if (part.kind !== "cut") usedGroups.add(part.group);
54282
+ }
54283
+ } else {
54284
+ skipped.push(j.id);
54285
+ }
54286
+ });
54287
+ const groups = [...usedGroups].map((k) => GROUPS[k]);
54288
+ return { elements, groups, skipped };
53806
54289
  }
53807
54290
 
53808
54291
  // contract-to-scene.ts
@@ -53850,9 +54333,20 @@ function dispToMm(pt, ptPerFt) {
53850
54333
  function contractToScene(contractInput) {
53851
54334
  const contract = contractInput ?? {};
53852
54335
  const elements = [];
54336
+ const memberGeo = /* @__PURE__ */ new Map();
53853
54337
  const skipped = [];
53854
54338
  const profileOrder = [];
53855
54339
  const seenProfile = /* @__PURE__ */ new Set();
54340
+ const beamClear = /* @__PURE__ */ new Map();
54341
+ for (const j of contract.joints ?? []) {
54342
+ if (!j || j.kind !== "shear-plate" || !j.main || j.at !== "end0" && j.at !== "end1") continue;
54343
+ const pc = j.params?.["clearance"];
54344
+ const cl = typeof pc === "number" && isFinite(pc) ? Math.max(0, pc) : 12.7;
54345
+ const cur = beamClear.get(j.main) ?? { e0: 0, e1: 0 };
54346
+ if (j.at === "end0") cur.e0 = Math.max(cur.e0, cl);
54347
+ else cur.e1 = Math.max(cur.e1, cl);
54348
+ beamClear.set(j.main, cur);
54349
+ }
53856
54350
  for (const plan of contract.plans ?? []) {
53857
54351
  const ptPerFt = plan.pt_per_ft && plan.pt_per_ft > 0 ? plan.pt_per_ft : 1;
53858
54352
  const defaultTosMm = (plan.default_tos ?? 0) * IN_TO_MM;
@@ -53871,19 +54365,37 @@ function contractToScene(contractInput) {
53871
54365
  const [bx, by] = dispToMm(m.wp[1], ptPerFt);
53872
54366
  let from;
53873
54367
  let to;
54368
+ let workFrom;
54369
+ let workTo;
54370
+ let posOffset = 0;
53874
54371
  if (m.role === "column") {
53875
54372
  const bos = m.col?.bos != null ? m.col.bos * IN_TO_MM : 0;
53876
54373
  const tos = m.col?.tos != null ? m.col.tos * IN_TO_MM : defaultTosMm;
53877
54374
  from = [ax, ay, bos];
53878
54375
  to = [ax, ay, tos];
54376
+ workFrom = from;
54377
+ workTo = to;
53879
54378
  } else {
53880
54379
  const z0 = m.ends?.[0]?.tos != null ? m.ends[0].tos * IN_TO_MM : defaultTosMm;
53881
54380
  const z1 = m.ends?.[1]?.tos != null ? m.ends[1].tos * IN_TO_MM : defaultTosMm;
53882
- const pos = depthPosition(m.position, Math.abs(z1 - z0), Math.hypot(bx - ax, by - ay));
53883
- const zoff = pos === "top" ? -dims.d / 2 : pos === "bottom" ? dims.d / 2 : 0;
54381
+ workFrom = [ax, ay, z0];
54382
+ workTo = [bx, by, z1];
54383
+ const pos2 = depthPosition(m.position, Math.abs(z1 - z0), Math.hypot(bx - ax, by - ay));
54384
+ const zoff = pos2 === "top" ? -dims.d / 2 : pos2 === "bottom" ? dims.d / 2 : 0;
54385
+ posOffset = zoff;
53884
54386
  from = [ax, ay, z0 + zoff];
53885
54387
  to = [bx, by, z1 + zoff];
53886
54388
  }
54389
+ memberGeo.set(m.id, { id: m.id, role: m.role === "column" ? "column" : "beam", from: workFrom, to: workTo, dims: { w: dims.w, d: dims.d }, profile, posOffset });
54390
+ const clr = beamClear.get(m.id);
54391
+ if (clr && m.role !== "column") {
54392
+ const dx = to[0] - from[0], dy = to[1] - from[1], dz = to[2] - from[2];
54393
+ const L = Math.hypot(dx, dy, dz) || 1;
54394
+ const ex = dx / L, ey = dy / L, ez = dz / L;
54395
+ const e0 = Math.min(Math.max(0, clr.e0), L * 0.4), e1 = Math.min(Math.max(0, clr.e1), L * 0.4);
54396
+ if (e0 > 0) from = [from[0] + ex * e0, from[1] + ey * e0, from[2] + ez * e0];
54397
+ if (e1 > 0) to = [to[0] - ex * e1, to[1] - ey * e1, to[2] - ez * e1];
54398
+ }
53887
54399
  elements.push({ id: m.id, group: profile, kind: "box", from, to, section: { w: dims.w, d: dims.d }, meta: { profile } });
53888
54400
  }
53889
54401
  }
@@ -53892,6 +54404,10 @@ function contractToScene(contractInput) {
53892
54404
  label: profile,
53893
54405
  color: pickColor(profile, i, contract)
53894
54406
  }));
54407
+ const joints = expandJoints(contract.joints, memberGeo);
54408
+ for (const part of joints.elements) elements.push(part);
54409
+ for (const g of joints.groups) groups.push(g);
54410
+ for (const id of joints.skipped) skipped.push(`joint:${id}`);
53895
54411
  return {
53896
54412
  scene: { meta: { name: contract.title || "Steel Model", units: "mm", up: "z" }, groups, elements },
53897
54413
  skipped
@@ -53959,11 +54475,11 @@ function contractToBom(contractInput) {
53959
54475
  }
53960
54476
 
53961
54477
  // bom-export.ts
53962
- var import_node_os12 = require("node:os");
53963
- var import_node_path15 = require("node:path");
54478
+ var import_node_os13 = require("node:os");
54479
+ var import_node_path16 = require("node:path");
53964
54480
 
53965
54481
  // node_modules/write-excel-file/modules/export/writeXlsxFileNode.js
53966
- var import_node_fs18 = __toESM(require("node:fs"), 1);
54482
+ var import_node_fs19 = __toESM(require("node:fs"), 1);
53967
54483
 
53968
54484
  // node_modules/write-excel-file/modules/xlsx/helpers/features/getAdditionalContent.js
53969
54485
  function _createForOfIteratorHelperLoose(r, e) {
@@ -57292,9 +57808,9 @@ var clen = function(cf, cl) {
57292
57808
  l += cf[i] * cl[i];
57293
57809
  return l;
57294
57810
  };
57295
- var wfblk = function(out, pos, dat) {
57811
+ var wfblk = function(out, pos2, dat) {
57296
57812
  var s = dat.length;
57297
- var o = shft(pos + 2);
57813
+ var o = shft(pos2 + 2);
57298
57814
  out[o] = s & 255;
57299
57815
  out[o + 1] = s >> 8;
57300
57816
  out[o + 2] = out[o] ^ 255;
@@ -57374,9 +57890,9 @@ var dflt = function(dat, lvl, plvl, pre, post, st) {
57374
57890
  var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7e3)) + post);
57375
57891
  var w = o.subarray(pre, o.length - post);
57376
57892
  var lst = st.l;
57377
- var pos = (st.r || 0) & 7;
57893
+ var pos2 = (st.r || 0) & 7;
57378
57894
  if (lvl) {
57379
- if (pos)
57895
+ if (pos2)
57380
57896
  w[0] = st.r >> 3;
57381
57897
  var opt = deo[lvl - 1];
57382
57898
  var n = opt >> 13, c = opt & 8191;
@@ -57397,7 +57913,7 @@ var dflt = function(dat, lvl, plvl, pre, post, st) {
57397
57913
  if (wi <= i) {
57398
57914
  var rem = s - i;
57399
57915
  if ((lc_1 > 7e3 || li > 24576) && (rem > 423 || !lst)) {
57400
- pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);
57916
+ pos2 = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos2);
57401
57917
  li = lc_1 = eb = 0, bs = i;
57402
57918
  for (var j = 0; j < 286; ++j)
57403
57919
  lf[j] = 0;
@@ -57451,24 +57967,24 @@ var dflt = function(dat, lvl, plvl, pre, post, st) {
57451
57967
  syms[li++] = dat[i];
57452
57968
  ++lf[dat[i]];
57453
57969
  }
57454
- pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);
57970
+ pos2 = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos2);
57455
57971
  if (!lst) {
57456
- st.r = pos & 7 | w[pos / 8 | 0] << 3;
57457
- pos -= 7;
57972
+ st.r = pos2 & 7 | w[pos2 / 8 | 0] << 3;
57973
+ pos2 -= 7;
57458
57974
  st.h = head, st.p = prev, st.i = i, st.w = wi;
57459
57975
  }
57460
57976
  } else {
57461
57977
  for (var i = st.w || 0; i < s + lst; i += 65535) {
57462
57978
  var e = i + 65535;
57463
57979
  if (e >= s) {
57464
- w[pos / 8 | 0] = lst;
57980
+ w[pos2 / 8 | 0] = lst;
57465
57981
  e = s;
57466
57982
  }
57467
- pos = wfblk(w, pos + 1, dat.subarray(i, e));
57983
+ pos2 = wfblk(w, pos2 + 1, dat.subarray(i, e));
57468
57984
  }
57469
57985
  st.i = s;
57470
57986
  }
57471
- return slc(o, 0, pre + shft(pos) + post);
57987
+ return slc(o, 0, pre + shft(pos2) + post);
57472
57988
  };
57473
57989
  var crct = /* @__PURE__ */ (function() {
57474
57990
  var t = new Int32Array(256);
@@ -58135,7 +58651,7 @@ function writeXlsxFile(arg1, arg2, arg3) {
58135
58651
  },
58136
58652
  toFile: function toFile(filePath) {
58137
58653
  return createReadableStream().then(function(readableStream) {
58138
- return pipe(readableStream, import_node_fs18.default.createWriteStream(filePath));
58654
+ return pipe(readableStream, import_node_fs19.default.createWriteStream(filePath));
58139
58655
  });
58140
58656
  }
58141
58657
  };
@@ -58160,8 +58676,8 @@ function pipe(readableStream, writableStream) {
58160
58676
 
58161
58677
  // bom-export.ts
58162
58678
  function bomExportPath(appId, format) {
58163
- const root = process.env.FLOLESS_HOME ?? (0, import_node_path15.join)((0, import_node_os12.homedir)(), ".floless");
58164
- return (0, import_node_path15.join)(root, "exports", appId, `${appId}-bom.${format}`);
58679
+ const root = process.env.FLOLESS_HOME ?? (0, import_node_path16.join)((0, import_node_os13.homedir)(), ".floless");
58680
+ return (0, import_node_path16.join)(root, "exports", appId, `${appId}-bom.${format}`);
58165
58681
  }
58166
58682
  function csvField(v) {
58167
58683
  let s = String(v);
@@ -58189,11 +58705,11 @@ async function bomToXlsx(bom) {
58189
58705
  }
58190
58706
 
58191
58707
  // scene-bake.ts
58192
- var import_node_fs19 = require("node:fs");
58193
- var import_node_path16 = require("node:path");
58708
+ var import_node_fs20 = require("node:fs");
58709
+ var import_node_path17 = require("node:path");
58194
58710
  var import_yaml6 = __toESM(require_dist6(), 1);
58195
58711
  function bakeSceneIntoApp(sourcePath, scene, agent = "viewer-3d") {
58196
- const doc = (0, import_yaml6.parseDocument)((0, import_node_fs19.readFileSync)(sourcePath, "utf8"));
58712
+ const doc = (0, import_yaml6.parseDocument)((0, import_node_fs20.readFileSync)(sourcePath, "utf8"));
58197
58713
  if (doc.errors.length > 0) {
58198
58714
  throw new Error(`scene bake: source is not valid YAML: ${doc.errors[0]?.message ?? "parse error"}`);
58199
58715
  }
@@ -58202,10 +58718,10 @@ function bakeSceneIntoApp(sourcePath, scene, agent = "viewer-3d") {
58202
58718
  const idx = items.findIndex((it) => ((0, import_yaml6.isMap)(it) ? it.toJSON() : null)?.agent === agent);
58203
58719
  if (idx < 0) throw new Error(`no ${agent} render node to bake the scene into`);
58204
58720
  doc.setIn(["nodes", idx, "config", "scene"], scene);
58205
- (0, import_node_fs19.writeFileSync)(sourcePath, doc.toString());
58721
+ (0, import_node_fs20.writeFileSync)(sourcePath, doc.toString());
58206
58722
  }
58207
- function bakeNodeConfigById(sourcePath, nodeId, patch) {
58208
- const doc = (0, import_yaml6.parseDocument)((0, import_node_fs19.readFileSync)(sourcePath, "utf8"));
58723
+ function bakeNodeConfigById(sourcePath, nodeId, patch2) {
58724
+ const doc = (0, import_yaml6.parseDocument)((0, import_node_fs20.readFileSync)(sourcePath, "utf8"));
58209
58725
  if (doc.errors.length > 0) {
58210
58726
  throw new Error(`node bake: source is not valid YAML: ${doc.errors[0]?.message ?? "parse error"}`);
58211
58727
  }
@@ -58213,13 +58729,13 @@ function bakeNodeConfigById(sourcePath, nodeId, patch) {
58213
58729
  const items = (0, import_yaml6.isSeq)(seq) ? seq.items : [];
58214
58730
  const idx = items.findIndex((it) => ((0, import_yaml6.isMap)(it) ? it.toJSON() : null)?.id === nodeId);
58215
58731
  if (idx < 0) throw new Error(`no node with id "${nodeId}"`);
58216
- for (const [key, value] of Object.entries(patch)) doc.setIn(["nodes", idx, "config", key], value);
58217
- (0, import_node_fs19.writeFileSync)(sourcePath, doc.toString());
58732
+ for (const [key, value] of Object.entries(patch2)) doc.setIn(["nodes", idx, "config", key], value);
58733
+ (0, import_node_fs20.writeFileSync)(sourcePath, doc.toString());
58218
58734
  }
58219
58735
  function writeViewer3dApp(dir, appId, scene) {
58220
- (0, import_node_fs19.mkdirSync)(dir, { recursive: true });
58221
- const flo = (0, import_node_path16.join)(dir, `${appId}.flo`);
58222
- (0, import_node_fs19.writeFileSync)(flo, [
58736
+ (0, import_node_fs20.mkdirSync)(dir, { recursive: true });
58737
+ const flo = (0, import_node_path17.join)(dir, `${appId}.flo`);
58738
+ (0, import_node_fs20.writeFileSync)(flo, [
58223
58739
  `app: ${appId}`,
58224
58740
  "version: 0.1.0",
58225
58741
  "display-name: Steel 3D",
@@ -58240,9 +58756,9 @@ function writeViewer3dApp(dir, appId, scene) {
58240
58756
  return flo;
58241
58757
  }
58242
58758
  function writeIfcApp(dir, appId, scene, outputPath) {
58243
- (0, import_node_fs19.mkdirSync)(dir, { recursive: true });
58244
- const flo = (0, import_node_path16.join)(dir, `${appId}.flo`);
58245
- (0, import_node_fs19.writeFileSync)(flo, [
58759
+ (0, import_node_fs20.mkdirSync)(dir, { recursive: true });
58760
+ const flo = (0, import_node_path17.join)(dir, `${appId}.flo`);
58761
+ (0, import_node_fs20.writeFileSync)(flo, [
58246
58762
  `app: ${appId}`,
58247
58763
  "version: 0.1.0",
58248
58764
  "display-name: Steel IFC",
@@ -58265,9 +58781,9 @@ function writeIfcApp(dir, appId, scene, outputPath) {
58265
58781
  return flo;
58266
58782
  }
58267
58783
  function writeTeklaApp(dir, appId, scene, teklaVersion = "2026.0") {
58268
- (0, import_node_fs19.mkdirSync)(dir, { recursive: true });
58269
- const flo = (0, import_node_path16.join)(dir, `${appId}.flo`);
58270
- (0, import_node_fs19.writeFileSync)(flo, [
58784
+ (0, import_node_fs20.mkdirSync)(dir, { recursive: true });
58785
+ const flo = (0, import_node_path17.join)(dir, `${appId}.flo`);
58786
+ (0, import_node_fs20.writeFileSync)(flo, [
58271
58787
  `app: ${appId}`,
58272
58788
  "version: 0.1.0",
58273
58789
  "display-name: Steel to Tekla",
@@ -58306,11 +58822,11 @@ async function bakeBomExportNodes(sourcePath, appId, contract) {
58306
58822
  xlsx: bom ? (await bomToXlsx(bom)).toString("base64") : null
58307
58823
  };
58308
58824
  for (const { id, format } of EXPORT_NODES) {
58309
- const patch = { path: bomExportPath(appId, format) };
58825
+ const patch2 = { path: bomExportPath(appId, format) };
58310
58826
  const bytes = bytesFor[format];
58311
- if (bytes != null) patch.bytes = bytes;
58827
+ if (bytes != null) patch2.bytes = bytes;
58312
58828
  try {
58313
- bakeNodeConfigById(sourcePath, id, patch);
58829
+ bakeNodeConfigById(sourcePath, id, patch2);
58314
58830
  baked.push(id);
58315
58831
  } catch (e) {
58316
58832
  if (!(e instanceof Error && /no node with id/.test(e.message))) throw e;
@@ -58485,16 +59001,16 @@ function memberTons(contract, m) {
58485
59001
  }
58486
59002
  function rollup(members, countWeighted = false) {
58487
59003
  const counts = emptyCounts();
58488
- let num = 0, den = 0, tons = 0;
59004
+ let num2 = 0, den = 0, tons = 0;
58489
59005
  for (const m of members) {
58490
59006
  counts[m.band]++;
58491
59007
  if (m.band === "rfi") continue;
58492
59008
  const w = countWeighted ? 1 : m.tons;
58493
- num += w * BAND_WEIGHT[m.band];
59009
+ num2 += w * BAND_WEIGHT[m.band];
58494
59010
  den += w;
58495
59011
  tons += m.tons;
58496
59012
  }
58497
- return { score: den > 0 ? Math.round(num / den * 100) : null, tons, counts };
59013
+ return { score: den > 0 ? Math.round(num2 / den * 100) : null, tons, counts };
58498
59014
  }
58499
59015
  function bandEnd(end, rows) {
58500
59016
  const row = end.conn ? rows.get(end.conn) : void 0;
@@ -58530,14 +59046,14 @@ function scoreConnections(contractInput) {
58530
59046
  }
58531
59047
  });
58532
59048
  const counts = emptyCounts();
58533
- let num = 0, den = 0;
59049
+ let num2 = 0, den = 0;
58534
59050
  for (const e of byEnd) {
58535
59051
  counts[e.band]++;
58536
59052
  if (e.band === "rfi") continue;
58537
- num += BAND_WEIGHT[e.band];
59053
+ num2 += BAND_WEIGHT[e.band];
58538
59054
  den += 1;
58539
59055
  }
58540
- const category = { score: den > 0 ? Math.round(num / den * 100) : null, tons: 0, counts };
59056
+ const category = { score: den > 0 ? Math.round(num2 / den * 100) : null, tons: 0, counts };
58541
59057
  return { byEnd, category };
58542
59058
  }
58543
59059
  function scoreContract(contractInput) {
@@ -58584,7 +59100,7 @@ function scoreContract(contractInput) {
58584
59100
  const columns = rollup(byMember.filter((m) => m.role === "column"));
58585
59101
  const details = rollupDetails(byDetail);
58586
59102
  const scored = byMember.filter((m) => m.band !== "rfi");
58587
- const num = scored.reduce((s, m) => s + m.tons * BAND_WEIGHT[m.band], 0);
59103
+ const num2 = scored.reduce((s, m) => s + m.tons * BAND_WEIGHT[m.band], 0);
58588
59104
  const den = scored.reduce((s, m) => s + m.tons, 0);
58589
59105
  return {
58590
59106
  byMember,
@@ -58602,7 +59118,7 @@ function scoreContract(contractInput) {
58602
59118
  note: "Approximate in v1 \u2014 precise per-segment binding is Slice 2."
58603
59119
  },
58604
59120
  overall: {
58605
- score: den > 0 ? Math.round(num / den * 100) : null,
59121
+ score: den > 0 ? Math.round(num2 / den * 100) : null,
58606
59122
  tons: den,
58607
59123
  rfiCount: byMember.filter((m) => m.band === "rfi").length
58608
59124
  }
@@ -58614,13 +59130,13 @@ function detailSheet(text) {
58614
59130
  }
58615
59131
  function rollupDetails(details) {
58616
59132
  const counts = emptyCounts();
58617
- let num = 0, den = 0;
59133
+ let num2 = 0, den = 0;
58618
59134
  for (const d of details) {
58619
59135
  counts[d.band]++;
58620
- num += BAND_WEIGHT[d.band];
59136
+ num2 += BAND_WEIGHT[d.band];
58621
59137
  den += 1;
58622
59138
  }
58623
- return { score: den > 0 ? Math.round(num / den * 100) : null, tons: 0, counts };
59139
+ return { score: den > 0 ? Math.round(num2 / den * 100) : null, tons: 0, counts };
58624
59140
  }
58625
59141
 
58626
59142
  // contract-score.ts
@@ -58666,13 +59182,13 @@ function scoreContract2(contractInput) {
58666
59182
  }
58667
59183
 
58668
59184
  // app-lifecycle.ts
58669
- var import_node_fs22 = require("node:fs");
58670
- var import_node_os14 = require("node:os");
58671
- var import_node_path19 = require("node:path");
59185
+ var import_node_fs23 = require("node:fs");
59186
+ var import_node_os15 = require("node:os");
59187
+ var import_node_path20 = require("node:path");
58672
59188
 
58673
59189
  // routines.ts
58674
- var import_node_fs21 = require("node:fs");
58675
- var import_node_path18 = require("node:path");
59190
+ var import_node_fs22 = require("node:fs");
59191
+ var import_node_path19 = require("node:path");
58676
59192
 
58677
59193
  // sse.ts
58678
59194
  var clients = /* @__PURE__ */ new Set();
@@ -58709,11 +59225,11 @@ function clientCount() {
58709
59225
  }
58710
59226
 
58711
59227
  // trigger-sessions.ts
58712
- var import_node_fs20 = require("node:fs");
58713
- var import_node_os13 = require("node:os");
58714
- var import_node_path17 = require("node:path");
59228
+ var import_node_fs21 = require("node:fs");
59229
+ var import_node_os14 = require("node:os");
59230
+ var import_node_path18 = require("node:path");
58715
59231
  var import_yaml7 = __toESM(require_dist6(), 1);
58716
- var AGENTS_DIR2 = process.env.AWARE_HOME ? (0, import_node_path17.join)(process.env.AWARE_HOME, "agents") : (0, import_node_path17.join)((0, import_node_os13.homedir)(), ".aware", "agents");
59232
+ var AGENTS_DIR2 = process.env.AWARE_HOME ? (0, import_node_path18.join)(process.env.AWARE_HOME, "agents") : (0, import_node_path18.join)((0, import_node_os14.homedir)(), ".aware", "agents");
58717
59233
  function summarizeFire(data) {
58718
59234
  if (!data) return "event";
58719
59235
  const type = typeof data.type === "string" ? data.type : "";
@@ -58730,10 +59246,10 @@ function mapTriggerState(phase) {
58730
59246
  function isHostBacked(agent, agentsDir = AGENTS_DIR2) {
58731
59247
  const safe = (n) => !n.includes("/") && !n.includes("\\") && !n.includes("..");
58732
59248
  if (!safe(agent)) return false;
58733
- const manifestPath = (0, import_node_path17.join)(agentsDir, agent, "manifest.yaml");
58734
- if (!(0, import_node_fs20.existsSync)(manifestPath)) return false;
59249
+ const manifestPath = (0, import_node_path18.join)(agentsDir, agent, "manifest.yaml");
59250
+ if (!(0, import_node_fs21.existsSync)(manifestPath)) return false;
58735
59251
  try {
58736
- const doc = (0, import_yaml7.parse)((0, import_node_fs20.readFileSync)(manifestPath, "utf8"));
59252
+ const doc = (0, import_yaml7.parse)((0, import_node_fs21.readFileSync)(manifestPath, "utf8"));
58737
59253
  const transport = doc?.transport;
58738
59254
  return !!(transport && typeof transport === "object" && "cli" in transport);
58739
59255
  } catch {
@@ -59018,7 +59534,7 @@ var RoutineError = class extends Error {
59018
59534
  }
59019
59535
  status;
59020
59536
  };
59021
- var ROUTINES_FILE = (0, import_node_path18.join)(flolessRoot, "routines.json");
59537
+ var ROUTINES_FILE = (0, import_node_path19.join)(flolessRoot, "routines.json");
59022
59538
  var routines = [];
59023
59539
  var loaded = false;
59024
59540
  function ensureLoaded() {
@@ -59054,10 +59570,10 @@ function sanitizeRoutine(raw) {
59054
59570
  };
59055
59571
  }
59056
59572
  function loadFromDisk() {
59057
- if (!(0, import_node_fs21.existsSync)(ROUTINES_FILE)) return [];
59573
+ if (!(0, import_node_fs22.existsSync)(ROUTINES_FILE)) return [];
59058
59574
  let text;
59059
59575
  try {
59060
- text = (0, import_node_fs21.readFileSync)(ROUTINES_FILE, "utf8");
59576
+ text = (0, import_node_fs22.readFileSync)(ROUTINES_FILE, "utf8");
59061
59577
  } catch {
59062
59578
  return [];
59063
59579
  }
@@ -59066,17 +59582,17 @@ function loadFromDisk() {
59066
59582
  return Array.isArray(parsed) ? parsed.map(sanitizeRoutine).filter((r) => r !== null) : [];
59067
59583
  } catch {
59068
59584
  try {
59069
- (0, import_node_fs21.renameSync)(ROUTINES_FILE, `${ROUTINES_FILE}.corrupt-${Date.now()}`);
59585
+ (0, import_node_fs22.renameSync)(ROUTINES_FILE, `${ROUTINES_FILE}.corrupt-${Date.now()}`);
59070
59586
  } catch {
59071
59587
  }
59072
59588
  return [];
59073
59589
  }
59074
59590
  }
59075
59591
  function saveRoutines() {
59076
- if (!(0, import_node_fs21.existsSync)(flolessRoot)) (0, import_node_fs21.mkdirSync)(flolessRoot, { recursive: true });
59592
+ if (!(0, import_node_fs22.existsSync)(flolessRoot)) (0, import_node_fs22.mkdirSync)(flolessRoot, { recursive: true });
59077
59593
  const tmp = `${ROUTINES_FILE}.${process.pid}.tmp`;
59078
- (0, import_node_fs21.writeFileSync)(tmp, JSON.stringify(routines, null, 2));
59079
- (0, import_node_fs21.renameSync)(tmp, ROUTINES_FILE);
59594
+ (0, import_node_fs22.writeFileSync)(tmp, JSON.stringify(routines, null, 2));
59595
+ (0, import_node_fs22.renameSync)(tmp, ROUTINES_FILE);
59080
59596
  }
59081
59597
  function listRoutines() {
59082
59598
  ensureLoaded();
@@ -59233,30 +59749,30 @@ function createRoutine(input) {
59233
59749
  broadcast({ type: "routine-changed", id: r.id });
59234
59750
  return r;
59235
59751
  }
59236
- function updateRoutine(id, patch) {
59752
+ function updateRoutine(id, patch2) {
59237
59753
  ensureLoaded();
59238
59754
  const r = getRoutine(id);
59239
59755
  if (!r) return null;
59240
- if (patch.name !== void 0) {
59241
- const name = String(patch.name).trim();
59756
+ if (patch2.name !== void 0) {
59757
+ const name = String(patch2.name).trim();
59242
59758
  if (!name) throw new RoutineError("name cannot be empty");
59243
59759
  r.name = name;
59244
59760
  }
59245
- if (patch.schedule !== void 0) {
59761
+ if (patch2.schedule !== void 0) {
59246
59762
  if (r.kind !== "schedule") throw new RoutineError("cannot set a schedule on a trigger routine");
59247
- const err2 = validateSchedule(patch.schedule);
59763
+ const err2 = validateSchedule(patch2.schedule);
59248
59764
  if (err2) throw new RoutineError(err2);
59249
- r.schedule = patch.schedule;
59765
+ r.schedule = patch2.schedule;
59250
59766
  }
59251
- if (patch.inputs !== void 0) {
59767
+ if (patch2.inputs !== void 0) {
59252
59768
  const app = requireApp(r.workflow);
59253
- r.inputs = coerceInputs(app, patch.inputs);
59769
+ r.inputs = coerceInputs(app, patch2.inputs);
59254
59770
  }
59255
- if (patch.enabled !== void 0) r.enabled = !!patch.enabled;
59771
+ if (patch2.enabled !== void 0) r.enabled = !!patch2.enabled;
59256
59772
  r.updated = (/* @__PURE__ */ new Date()).toISOString();
59257
59773
  r.nextFireAt = computeNextFire(r);
59258
59774
  saveRoutines();
59259
- if (r.kind === "trigger" && (patch.enabled !== void 0 || patch.inputs !== void 0)) {
59775
+ if (r.kind === "trigger" && (patch2.enabled !== void 0 || patch2.inputs !== void 0)) {
59260
59776
  syncTriggerSession(r);
59261
59777
  }
59262
59778
  broadcast({ type: "routine-changed", id: r.id });
@@ -59484,13 +60000,13 @@ var AppLifecycleError = class extends Error {
59484
60000
  }
59485
60001
  };
59486
60002
  function appsDir() {
59487
- return process.env.AWARE_HOME ? (0, import_node_path19.join)(process.env.AWARE_HOME, "apps") : (0, import_node_path19.join)((0, import_node_os14.homedir)(), ".aware", "apps");
60003
+ return process.env.AWARE_HOME ? (0, import_node_path20.join)(process.env.AWARE_HOME, "apps") : (0, import_node_path20.join)((0, import_node_os15.homedir)(), ".aware", "apps");
59488
60004
  }
59489
60005
  function appDirPath(id) {
59490
- return (0, import_node_path19.join)(appsDir(), id);
60006
+ return (0, import_node_path20.join)(appsDir(), id);
59491
60007
  }
59492
60008
  function appInstalled(id) {
59493
- return APP_ID3.test(id) && (0, import_node_fs22.existsSync)(appDirPath(id));
60009
+ return APP_ID3.test(id) && (0, import_node_fs23.existsSync)(appDirPath(id));
59494
60010
  }
59495
60011
  function logCascade(what, e) {
59496
60012
  console.error(`[app-lifecycle] cascade step failed (${what}):`, e instanceof Error ? e.message : e);
@@ -59528,6 +60044,11 @@ async function renameApp(oldId, newId, deps = defaultDeps2) {
59528
60044
  } catch (e) {
59529
60045
  logCascade("re-point routines", e);
59530
60046
  }
60047
+ try {
60048
+ renameOrigin(oldId, newId);
60049
+ } catch (e) {
60050
+ logCascade("carry lineage", e);
60051
+ }
59531
60052
  return { id: newId, compiled };
59532
60053
  }
59533
60054
  async function duplicateApp(srcId, newId, deps = defaultDeps2) {
@@ -59540,6 +60061,11 @@ async function duplicateApp(srcId, newId, deps = defaultDeps2) {
59540
60061
  } catch (e) {
59541
60062
  logCascade("copy visual inputs", e);
59542
60063
  }
60064
+ try {
60065
+ copyOrigin(srcId, newId);
60066
+ } catch (e) {
60067
+ logCascade("copy lineage", e);
60068
+ }
59543
60069
  return { id: newId, compiled };
59544
60070
  }
59545
60071
  async function deleteApp(id, deps = defaultDeps2) {
@@ -59555,6 +60081,11 @@ async function deleteApp(id, deps = defaultDeps2) {
59555
60081
  } catch (e) {
59556
60082
  logCascade("remove routines", e);
59557
60083
  }
60084
+ try {
60085
+ deleteOrigin(id);
60086
+ } catch (e) {
60087
+ logCascade("drop lineage", e);
60088
+ }
59558
60089
  }
59559
60090
 
59560
60091
  // route-gate.ts
@@ -59591,9 +60122,9 @@ function isGatedAwareRoute(url, method) {
59591
60122
 
59592
60123
  // autostart.mjs
59593
60124
  var import_node_child_process4 = require("node:child_process");
59594
- var import_node_fs23 = require("node:fs");
59595
- var import_node_os15 = require("node:os");
59596
- var import_node_path20 = require("node:path");
60125
+ var import_node_fs24 = require("node:fs");
60126
+ var import_node_os16 = require("node:os");
60127
+ var import_node_path21 = require("node:path");
59597
60128
 
59598
60129
  // teardown.mjs
59599
60130
  var RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
@@ -59705,8 +60236,8 @@ function removeLegacyRunKey() {
59705
60236
  }
59706
60237
  function logLine(msg) {
59707
60238
  try {
59708
- (0, import_node_fs23.mkdirSync)(logDir(), { recursive: true });
59709
- (0, import_node_fs23.appendFileSync)(logFilePath(), `${(/* @__PURE__ */ new Date()).toISOString()} ${msg}
60239
+ (0, import_node_fs24.mkdirSync)(logDir(), { recursive: true });
60240
+ (0, import_node_fs24.appendFileSync)(logFilePath(), `${(/* @__PURE__ */ new Date()).toISOString()} ${msg}
59710
60241
  `);
59711
60242
  } catch {
59712
60243
  }
@@ -59714,8 +60245,8 @@ function logLine(msg) {
59714
60245
  function registerAutostart(exePath) {
59715
60246
  if (!isWin) return;
59716
60247
  const xml = buildAutostartTaskXml(exePath, currentUserId());
59717
- const tmp = (0, import_node_path20.join)((0, import_node_os15.tmpdir)(), `floless-autostart-${process.pid}-${Date.now()}.xml`);
59718
- (0, import_node_fs23.writeFileSync)(tmp, "\uFEFF" + xml, { encoding: "utf16le" });
60248
+ const tmp = (0, import_node_path21.join)((0, import_node_os16.tmpdir)(), `floless-autostart-${process.pid}-${Date.now()}.xml`);
60249
+ (0, import_node_fs24.writeFileSync)(tmp, "\uFEFF" + xml, { encoding: "utf16le" });
59719
60250
  try {
59720
60251
  (0, import_node_child_process4.execFileSync)("schtasks", ["/Create", "/TN", TASK_NAME, "/XML", tmp, "/F"], {
59721
60252
  stdio: ["ignore", "ignore", "ignore"],
@@ -59726,7 +60257,7 @@ function registerAutostart(exePath) {
59726
60257
  throw err2;
59727
60258
  } finally {
59728
60259
  try {
59729
- (0, import_node_fs23.rmSync)(tmp, { force: true });
60260
+ (0, import_node_fs24.rmSync)(tmp, { force: true });
59730
60261
  } catch {
59731
60262
  }
59732
60263
  }
@@ -59761,26 +60292,26 @@ function unregisterAutostart() {
59761
60292
  // updater.ts
59762
60293
  var import_node_child_process5 = require("node:child_process");
59763
60294
  var import_node_crypto6 = require("node:crypto");
59764
- var import_node_fs25 = require("node:fs");
60295
+ var import_node_fs26 = require("node:fs");
59765
60296
  var import_node_stream3 = require("node:stream");
59766
60297
  var import_promises = require("node:stream/promises");
59767
- var import_node_path22 = require("node:path");
60298
+ var import_node_path23 = require("node:path");
59768
60299
 
59769
60300
  // post-update-marker.mjs
59770
- var import_node_fs24 = require("node:fs");
59771
- var import_node_os16 = require("node:os");
59772
- var import_node_path21 = require("node:path");
60301
+ var import_node_fs25 = require("node:fs");
60302
+ var import_node_os17 = require("node:os");
60303
+ var import_node_path22 = require("node:path");
59773
60304
  var FRESH_MS = 12e4;
59774
60305
  function markerPath() {
59775
60306
  const override = (process.env.FLOLESS_POST_UPDATE_MARKER ?? "").trim();
59776
60307
  if (override) return override;
59777
- const root = process.env.FLOLESS_HOME ?? (0, import_node_path21.join)((0, import_node_os16.homedir)(), ".floless");
59778
- return (0, import_node_path21.join)(root, ".post-update");
60308
+ const root = process.env.FLOLESS_HOME ?? (0, import_node_path22.join)((0, import_node_os17.homedir)(), ".floless");
60309
+ return (0, import_node_path22.join)(root, ".post-update");
59779
60310
  }
59780
60311
  function legacyMarkerPath() {
59781
60312
  if ((process.env.FLOLESS_POST_UPDATE_MARKER ?? "").trim()) return null;
59782
60313
  try {
59783
- return (0, import_node_path21.join)((0, import_node_path21.dirname)((0, import_node_path21.dirname)(process.execPath)), ".floless-post-update");
60314
+ return (0, import_node_path22.join)((0, import_node_path22.dirname)((0, import_node_path22.dirname)(process.execPath)), ".floless-post-update");
59784
60315
  } catch {
59785
60316
  return null;
59786
60317
  }
@@ -59790,7 +60321,7 @@ function writePostUpdateMarker() {
59790
60321
  for (const p of [markerPath(), legacyMarkerPath()]) {
59791
60322
  if (!p) continue;
59792
60323
  try {
59793
- (0, import_node_fs24.writeFileSync)(p, (/* @__PURE__ */ new Date()).toISOString());
60324
+ (0, import_node_fs25.writeFileSync)(p, (/* @__PURE__ */ new Date()).toISOString());
59794
60325
  wrote = true;
59795
60326
  } catch {
59796
60327
  }
@@ -59802,9 +60333,9 @@ function consumePostUpdateMarker() {
59802
60333
  for (const p of [markerPath(), legacyMarkerPath()]) {
59803
60334
  if (!p) continue;
59804
60335
  try {
59805
- if (!(0, import_node_fs24.existsSync)(p)) continue;
59806
- const ageMs = Date.now() - (0, import_node_fs24.statSync)(p).mtimeMs;
59807
- (0, import_node_fs24.rmSync)(p, { force: true });
60336
+ if (!(0, import_node_fs25.existsSync)(p)) continue;
60337
+ const ageMs = Date.now() - (0, import_node_fs25.statSync)(p).mtimeMs;
60338
+ (0, import_node_fs25.rmSync)(p, { force: true });
59808
60339
  if (ageMs < FRESH_MS) fresh = true;
59809
60340
  } catch {
59810
60341
  }
@@ -59821,13 +60352,13 @@ function currentVersion() {
59821
60352
  return appVersion();
59822
60353
  }
59823
60354
  function installRoot() {
59824
- return (0, import_node_path22.dirname)((0, import_node_path22.dirname)(process.execPath));
60355
+ return (0, import_node_path23.dirname)((0, import_node_path23.dirname)(process.execPath));
59825
60356
  }
59826
60357
  function updateExePath() {
59827
- return (0, import_node_path22.join)(installRoot(), "Update.exe");
60358
+ return (0, import_node_path23.join)(installRoot(), "Update.exe");
59828
60359
  }
59829
60360
  function packagesDir() {
59830
- return (0, import_node_path22.join)(installRoot(), "packages");
60361
+ return (0, import_node_path23.join)(installRoot(), "packages");
59831
60362
  }
59832
60363
  function feedUrl() {
59833
60364
  const env2 = (process.env.FLOLESS_UPDATE_URL ?? "").trim().replace(/\/+$/, "");
@@ -59920,22 +60451,22 @@ async function checkForUpdate() {
59920
60451
  }
59921
60452
  async function sha1OfFile(path) {
59922
60453
  const hash = (0, import_node_crypto6.createHash)("sha1");
59923
- await (0, import_promises.pipeline)((0, import_node_fs25.createReadStream)(path), hash);
60454
+ await (0, import_promises.pipeline)((0, import_node_fs26.createReadStream)(path), hash);
59924
60455
  return hash.digest("hex").toUpperCase();
59925
60456
  }
59926
60457
  async function downloadPackage(asset) {
59927
60458
  if (!NUPKG_NAME.test(asset.FileName)) throw new Error(`refusing suspicious package name: ${asset.FileName}`);
59928
60459
  const want = asset.SHA1.toUpperCase();
59929
60460
  const dir = packagesDir();
59930
- (0, import_node_fs25.mkdirSync)(dir, { recursive: true });
59931
- const dest = (0, import_node_path22.join)(dir, asset.FileName);
59932
- if ((0, import_node_fs25.existsSync)(dest) && await sha1OfFile(dest) === want) return dest;
60461
+ (0, import_node_fs26.mkdirSync)(dir, { recursive: true });
60462
+ const dest = (0, import_node_path23.join)(dir, asset.FileName);
60463
+ if ((0, import_node_fs26.existsSync)(dest) && await sha1OfFile(dest) === want) return dest;
59933
60464
  const res = await authedFetch(`${feedUrl()}/${encodeURIComponent(asset.FileName)}`, {
59934
60465
  redirect: "follow",
59935
60466
  signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS)
59936
60467
  });
59937
60468
  if (!res.ok || !res.body) throw new Error(`download failed: HTTP ${res.status} for ${asset.FileName}`);
59938
- await (0, import_promises.pipeline)(import_node_stream3.Readable.fromWeb(res.body), (0, import_node_fs25.createWriteStream)(dest));
60469
+ await (0, import_promises.pipeline)(import_node_stream3.Readable.fromWeb(res.body), (0, import_node_fs26.createWriteStream)(dest));
59939
60470
  const got = await sha1OfFile(dest);
59940
60471
  if (got !== want) throw new Error(`SHA1 mismatch for ${asset.FileName}: feed=${want} got=${got}`);
59941
60472
  return dest;
@@ -59944,7 +60475,7 @@ async function applyUpdate(check, opts) {
59944
60475
  if (!check.supported) return { applied: false, message: check.reason ?? "auto-update not supported in this runtime" };
59945
60476
  if (!check.updateAvailable || !check.asset) return { applied: false, message: check.reason ?? "no update available" };
59946
60477
  const exe = updateExePath();
59947
- if (!(0, import_node_fs25.existsSync)(exe)) {
60478
+ if (!(0, import_node_fs26.existsSync)(exe)) {
59948
60479
  return { applied: false, message: `Update.exe not found at ${exe} \u2014 is this a Velopack install?` };
59949
60480
  }
59950
60481
  const pkg = await downloadPackage(check.asset);
@@ -60184,12 +60715,12 @@ function isTraceCorrupt(events) {
60184
60715
 
60185
60716
  // launch.mjs
60186
60717
  var import_node_child_process6 = require("node:child_process");
60187
- var import_node_path23 = require("node:path");
60718
+ var import_node_path24 = require("node:path");
60188
60719
  var import_node_url3 = require("node:url");
60189
- var import_node_fs26 = require("node:fs");
60720
+ var import_node_fs27 = require("node:fs");
60190
60721
  var import_node_http = __toESM(require("node:http"), 1);
60191
60722
  var import_node_readline = require("node:readline");
60192
- var __dirname2 = (0, import_node_path23.dirname)((0, import_node_url3.fileURLToPath)(__import_meta_url));
60723
+ var __dirname2 = (0, import_node_path24.dirname)((0, import_node_url3.fileURLToPath)(__import_meta_url));
60193
60724
  var PORT = Number(process.env.PORT ?? 4317);
60194
60725
  var HEALTH_URL = `http://127.0.0.1:${PORT}/api/health`;
60195
60726
  var BROWSER_URL = `http://floless.localhost:${PORT}`;
@@ -60261,8 +60792,8 @@ async function waitHealthy(timeoutMs = 3e4) {
60261
60792
  function resolveServerStart() {
60262
60793
  const packaged = /flolessapp\.exe$/i.test(process.execPath);
60263
60794
  if (packaged) return { cmd: process.execPath, args: ["--serve"], shell: false };
60264
- const bundle = (0, import_node_path23.join)(__dirname2, "dist", "floless-server.cjs");
60265
- if ((0, import_node_fs26.existsSync)(bundle)) return { cmd: process.execPath, args: [bundle, "--serve"], shell: false };
60795
+ const bundle = (0, import_node_path24.join)(__dirname2, "dist", "floless-server.cjs");
60796
+ if ((0, import_node_fs27.existsSync)(bundle)) return { cmd: process.execPath, args: [bundle, "--serve"], shell: false };
60266
60797
  return { cmd: "npm", args: ["run", "start"], shell: isWin2 };
60267
60798
  }
60268
60799
  function startServerDetached() {
@@ -60415,8 +60946,8 @@ function taskkillArgs(pid, { tree = true } = {}) {
60415
60946
  }
60416
60947
  function killSupervisor({ tree = true } = {}) {
60417
60948
  if (!isWin2) return;
60418
- const isNpmChannel = /^node(\.exe)?$/i.test((0, import_node_path23.basename)(process.execPath));
60419
- const scriptMatch = isNpmChannel ? (0, import_node_path23.basename)((0, import_node_url3.fileURLToPath)(__import_meta_url)) : void 0;
60949
+ const isNpmChannel = /^node(\.exe)?$/i.test((0, import_node_path24.basename)(process.execPath));
60950
+ const scriptMatch = isNpmChannel ? (0, import_node_path24.basename)((0, import_node_url3.fileURLToPath)(__import_meta_url)) : void 0;
60420
60951
  const realExe = resolveRealInstallExe(process.execPath);
60421
60952
  const exeMatch = realExe === process.execPath ? process.execPath : [process.execPath, realExe];
60422
60953
  const pids = supervisorPidsToKill(enumerateProcesses(), process.pid, exeMatch, scriptMatch);
@@ -60581,7 +61112,7 @@ async function runAction(arg, flagArgv = [], selfVersion = null) {
60581
61112
  }
60582
61113
  await action(parseTeardownFlags(flagArgv));
60583
61114
  }
60584
- var entry = (0, import_node_path23.basename)(process.argv[1] ?? "").toLowerCase();
61115
+ var entry = (0, import_node_path24.basename)(process.argv[1] ?? "").toLowerCase();
60585
61116
  if (entry === "launch.mjs") {
60586
61117
  runAction(process.argv[2], process.argv.slice(3)).catch((e) => {
60587
61118
  log(`error: ${e?.message ?? e}`);
@@ -60655,9 +61186,9 @@ function awareUpgradeBlockReason(s) {
60655
61186
  }
60656
61187
 
60657
61188
  // skill-sync.ts
60658
- var import_node_fs27 = require("node:fs");
60659
- var import_node_os17 = require("node:os");
60660
- var import_node_path24 = require("node:path");
61189
+ var import_node_fs28 = require("node:fs");
61190
+ var import_node_os18 = require("node:os");
61191
+ var import_node_path25 = require("node:path");
60661
61192
  var import_node_url4 = require("node:url");
60662
61193
  var import_yaml8 = __toESM(require_dist6(), 1);
60663
61194
 
@@ -60665,6 +61196,8 @@ var import_yaml8 = __toESM(require_dist6(), 1);
60665
61196
  var PRODUCT_SKILLS = [
60666
61197
  "floless-app-bridge",
60667
61198
  // drive the floless.app CLI / desktop bridge from the user's AI
61199
+ "floless-app-new-workflow",
61200
+ // build a brand-new .flo from scratch, step by step, verifying each step (the create-sibling of onboarding's tour)
60668
61201
  "floless-app-onboarding",
60669
61202
  // guided, re-runnable tour of AWARE + floless.app for new users
60670
61203
  "floless-app-queue",
@@ -60696,30 +61229,30 @@ function selectShippedSkillNames(names) {
60696
61229
  }
60697
61230
 
60698
61231
  // skill-sync.ts
60699
- var __dirname3 = (0, import_node_path24.dirname)((0, import_node_url4.fileURLToPath)(__import_meta_url));
61232
+ var __dirname3 = (0, import_node_path25.dirname)((0, import_node_url4.fileURLToPath)(__import_meta_url));
60700
61233
  function bundledSkillsRoot() {
60701
61234
  const candidates = [
60702
- (0, import_node_path24.join)(__dirname3, "skills"),
60703
- (0, import_node_path24.join)((0, import_node_path24.dirname)(process.execPath), "skills"),
60704
- (0, import_node_path24.join)(__dirname3, "..", ".claude", "skills")
61235
+ (0, import_node_path25.join)(__dirname3, "skills"),
61236
+ (0, import_node_path25.join)((0, import_node_path25.dirname)(process.execPath), "skills"),
61237
+ (0, import_node_path25.join)(__dirname3, "..", ".claude", "skills")
60705
61238
  ];
60706
- return candidates.find((p) => (0, import_node_fs27.existsSync)(p)) ?? null;
61239
+ return candidates.find((p) => (0, import_node_fs28.existsSync)(p)) ?? null;
60707
61240
  }
60708
61241
  function targetConfigDirs() {
60709
61242
  const override = process.env.FLOLESS_SKILL_TARGETS;
60710
61243
  if (override) {
60711
61244
  return override.split(";").map((d) => d.trim()).filter(Boolean).map((dir) => ({ runtime: "custom", dir }));
60712
61245
  }
60713
- const home = (0, import_node_os17.homedir)();
61246
+ const home = (0, import_node_os18.homedir)();
60714
61247
  return [
60715
- { runtime: "claude", dir: (0, import_node_path24.join)(home, ".claude") },
60716
- { runtime: "codex", dir: (0, import_node_path24.join)(home, ".codex") },
60717
- { runtime: "opencode", dir: (0, import_node_path24.join)(home, ".opencode") }
61248
+ { runtime: "claude", dir: (0, import_node_path25.join)(home, ".claude") },
61249
+ { runtime: "codex", dir: (0, import_node_path25.join)(home, ".codex") },
61250
+ { runtime: "opencode", dir: (0, import_node_path25.join)(home, ".opencode") }
60718
61251
  ];
60719
61252
  }
60720
61253
  function skillVersion(skillMdPath) {
60721
61254
  try {
60722
- const text = (0, import_node_fs27.readFileSync)(skillMdPath, "utf8");
61255
+ const text = (0, import_node_fs28.readFileSync)(skillMdPath, "utf8");
60723
61256
  const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
60724
61257
  if (!m || m[1] === void 0) return null;
60725
61258
  const fm = (0, import_yaml8.parse)(m[1]);
@@ -60759,21 +61292,21 @@ function decideAction(installed, bundled) {
60759
61292
  function bundledSkills(root) {
60760
61293
  let entries = [];
60761
61294
  try {
60762
- entries = selectShippedSkillNames((0, import_node_fs27.readdirSync)(root));
61295
+ entries = selectShippedSkillNames((0, import_node_fs28.readdirSync)(root));
60763
61296
  } catch {
60764
61297
  return [];
60765
61298
  }
60766
61299
  const out = [];
60767
61300
  for (const name of entries) {
60768
- const dir = (0, import_node_path24.join)(root, name);
61301
+ const dir = (0, import_node_path25.join)(root, name);
60769
61302
  let isDir = false;
60770
61303
  try {
60771
- isDir = (0, import_node_fs27.statSync)(dir).isDirectory();
61304
+ isDir = (0, import_node_fs28.statSync)(dir).isDirectory();
60772
61305
  } catch {
60773
61306
  isDir = false;
60774
61307
  }
60775
61308
  if (!isDir) continue;
60776
- const v = skillVersion((0, import_node_path24.join)(dir, "SKILL.md"));
61309
+ const v = skillVersion((0, import_node_path25.join)(dir, "SKILL.md"));
60777
61310
  if (!v) continue;
60778
61311
  out.push({ name, dir, version: v });
60779
61312
  }
@@ -60786,17 +61319,17 @@ function syncSkills() {
60786
61319
  const skills = bundledSkills(root);
60787
61320
  if (!skills.length) return results;
60788
61321
  for (const { runtime, dir: cfg } of targetConfigDirs()) {
60789
- if (!(0, import_node_fs27.existsSync)(cfg)) continue;
60790
- const skillsDir = (0, import_node_path24.join)(cfg, "skills");
61322
+ if (!(0, import_node_fs28.existsSync)(cfg)) continue;
61323
+ const skillsDir = (0, import_node_path25.join)(cfg, "skills");
60791
61324
  for (const s of skills) {
60792
- const dest = (0, import_node_path24.join)(skillsDir, s.name);
60793
- const installedMd = (0, import_node_path24.join)(dest, "SKILL.md");
60794
- const installed = (0, import_node_fs27.existsSync)(installedMd) ? skillVersion(installedMd) : null;
61325
+ const dest = (0, import_node_path25.join)(skillsDir, s.name);
61326
+ const installedMd = (0, import_node_path25.join)(dest, "SKILL.md");
61327
+ const installed = (0, import_node_fs28.existsSync)(installedMd) ? skillVersion(installedMd) : null;
60795
61328
  const action = decideAction(installed, s.version);
60796
61329
  if (action === "installed" || action === "updated") {
60797
61330
  try {
60798
- if (action === "updated") (0, import_node_fs27.rmSync)(dest, { recursive: true, force: true });
60799
- (0, import_node_fs27.cpSync)(s.dir, dest, { recursive: true });
61331
+ if (action === "updated") (0, import_node_fs28.rmSync)(dest, { recursive: true, force: true });
61332
+ (0, import_node_fs28.cpSync)(s.dir, dest, { recursive: true });
60800
61333
  results.push({ runtime, skill: s.name, action, from: installed, to: s.version });
60801
61334
  } catch {
60802
61335
  }
@@ -60809,9 +61342,9 @@ function syncSkills() {
60809
61342
  }
60810
61343
 
60811
61344
  // watch.ts
60812
- var import_node_os18 = require("node:os");
60813
- var import_node_path26 = require("node:path");
60814
- var import_node_fs28 = require("node:fs");
61345
+ var import_node_os19 = require("node:os");
61346
+ var import_node_path27 = require("node:path");
61347
+ var import_node_fs29 = require("node:fs");
60815
61348
 
60816
61349
  // node_modules/chokidar/esm/index.js
60817
61350
  var import_fs2 = require("fs");
@@ -60822,7 +61355,7 @@ var sysPath2 = __toESM(require("path"), 1);
60822
61355
  // node_modules/readdirp/esm/index.js
60823
61356
  var import_promises2 = require("node:fs/promises");
60824
61357
  var import_node_stream4 = require("node:stream");
60825
- var import_node_path25 = require("node:path");
61358
+ var import_node_path26 = require("node:path");
60826
61359
  var EntryTypes = {
60827
61360
  FILE_TYPE: "files",
60828
61361
  DIR_TYPE: "directories",
@@ -60897,7 +61430,7 @@ var ReaddirpStream = class extends import_node_stream4.Readable {
60897
61430
  this._wantsDir = type ? DIR_TYPES.has(type) : false;
60898
61431
  this._wantsFile = type ? FILE_TYPES.has(type) : false;
60899
61432
  this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
60900
- this._root = (0, import_node_path25.resolve)(root);
61433
+ this._root = (0, import_node_path26.resolve)(root);
60901
61434
  this._isDirent = !opts.alwaysStat;
60902
61435
  this._statsProp = this._isDirent ? "dirent" : "stats";
60903
61436
  this._rdOptions = { encoding: "utf8", withFileTypes: this._isDirent };
@@ -60968,8 +61501,8 @@ var ReaddirpStream = class extends import_node_stream4.Readable {
60968
61501
  let entry2;
60969
61502
  const basename5 = this._isDirent ? dirent.name : dirent;
60970
61503
  try {
60971
- const fullPath = (0, import_node_path25.resolve)((0, import_node_path25.join)(path, basename5));
60972
- entry2 = { path: (0, import_node_path25.relative)(this._root, fullPath), fullPath, basename: basename5 };
61504
+ const fullPath = (0, import_node_path26.resolve)((0, import_node_path26.join)(path, basename5));
61505
+ entry2 = { path: (0, import_node_path26.relative)(this._root, fullPath), fullPath, basename: basename5 };
60973
61506
  entry2[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
60974
61507
  } catch (err2) {
60975
61508
  this._onError(err2);
@@ -61003,7 +61536,7 @@ var ReaddirpStream = class extends import_node_stream4.Readable {
61003
61536
  }
61004
61537
  if (entryRealPathStats.isDirectory()) {
61005
61538
  const len2 = entryRealPath.length;
61006
- if (full.startsWith(entryRealPath) && full.substr(len2, 1) === import_node_path25.sep) {
61539
+ if (full.startsWith(entryRealPath) && full.substr(len2, 1) === import_node_path26.sep) {
61007
61540
  const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
61008
61541
  recursiveError.code = RECURSIVE_ERROR_CODE;
61009
61542
  return this._onError(recursiveError);
@@ -61542,9 +62075,9 @@ var NodeFsHandler = class {
61542
62075
  if (this.fsw.closed) {
61543
62076
  return;
61544
62077
  }
61545
- const dirname12 = sysPath.dirname(file);
62078
+ const dirname13 = sysPath.dirname(file);
61546
62079
  const basename5 = sysPath.basename(file);
61547
- const parent = this.fsw._getWatchedDir(dirname12);
62080
+ const parent = this.fsw._getWatchedDir(dirname13);
61548
62081
  let prevStats = stats;
61549
62082
  if (parent.has(basename5))
61550
62083
  return;
@@ -61571,7 +62104,7 @@ var NodeFsHandler = class {
61571
62104
  prevStats = newStats2;
61572
62105
  }
61573
62106
  } catch (error) {
61574
- this.fsw._remove(dirname12, basename5);
62107
+ this.fsw._remove(dirname13, basename5);
61575
62108
  }
61576
62109
  } else if (parent.has(basename5)) {
61577
62110
  const at = newStats.atimeMs;
@@ -62511,33 +63044,33 @@ function appIdFromLogPath(path) {
62511
63044
  return i >= 0 && parts[i + 1] ? parts[i + 1] : null;
62512
63045
  }
62513
63046
  function samePath(a, b) {
62514
- const ra = (0, import_node_path26.resolve)(a);
62515
- const rb = (0, import_node_path26.resolve)(b);
63047
+ const ra = (0, import_node_path27.resolve)(a);
63048
+ const rb = (0, import_node_path27.resolve)(b);
62516
63049
  return process.platform === "win32" ? ra.toLowerCase() === rb.toLowerCase() : ra === rb;
62517
63050
  }
62518
63051
  function underDir(path, dir) {
62519
- const rp = (0, import_node_path26.resolve)(path);
62520
- const rd = (0, import_node_path26.resolve)(dir);
63052
+ const rp = (0, import_node_path27.resolve)(path);
63053
+ const rd = (0, import_node_path27.resolve)(dir);
62521
63054
  const [p, d] = process.platform === "win32" ? [rp.toLowerCase(), rd.toLowerCase()] : [rp, rd];
62522
- return p === d || p.startsWith(d + import_node_path26.sep);
63055
+ return p === d || p.startsWith(d + import_node_path27.sep);
62523
63056
  }
62524
63057
  function startWatcher() {
62525
- const awareDir = process.env.AWARE_HOME ?? (0, import_node_path26.join)((0, import_node_os18.homedir)(), ".aware");
62526
- const credentialsDir = (0, import_node_path26.join)(awareDir, "credentials");
62527
- if (!(0, import_node_fs28.existsSync)(credentialsDir)) {
63058
+ const awareDir = process.env.AWARE_HOME ?? (0, import_node_path27.join)((0, import_node_os19.homedir)(), ".aware");
63059
+ const credentialsDir = (0, import_node_path27.join)(awareDir, "credentials");
63060
+ if (!(0, import_node_fs29.existsSync)(credentialsDir)) {
62528
63061
  try {
62529
- (0, import_node_fs28.mkdirSync)(credentialsDir, { recursive: true });
63062
+ (0, import_node_fs29.mkdirSync)(credentialsDir, { recursive: true });
62530
63063
  } catch {
62531
63064
  }
62532
63065
  }
62533
- if (!(0, import_node_fs28.existsSync)(uiDir)) {
63066
+ if (!(0, import_node_fs29.existsSync)(uiDir)) {
62534
63067
  try {
62535
- (0, import_node_fs28.mkdirSync)(uiDir, { recursive: true });
63068
+ (0, import_node_fs29.mkdirSync)(uiDir, { recursive: true });
62536
63069
  } catch {
62537
63070
  }
62538
63071
  }
62539
- const targets = ["apps", "logs", "credentials"].map((d) => (0, import_node_path26.join)(awareDir, d)).filter((p) => (0, import_node_fs28.existsSync)(p));
62540
- if ((0, import_node_fs28.existsSync)(uiDir)) targets.push(uiDir);
63072
+ const targets = ["apps", "logs", "credentials"].map((d) => (0, import_node_path27.join)(awareDir, d)).filter((p) => (0, import_node_fs29.existsSync)(p));
63073
+ if ((0, import_node_fs29.existsSync)(uiDir)) targets.push(uiDir);
62541
63074
  if (targets.length === 0) {
62542
63075
  return null;
62543
63076
  }
@@ -62566,11 +63099,11 @@ function startWatcher() {
62566
63099
  const isCredential = path.split(/[\\/]/).includes("credentials");
62567
63100
  const kind = isCredential ? "credential" : path.endsWith(".jsonl") ? "trace" : path.endsWith(".lock") ? "lock" : path.endsWith(".flo") || path.endsWith(".app") ? "source" : "file";
62568
63101
  broadcast({ type: "fs-change", kind, event, path });
62569
- if (kind === "trace" && event !== "unlink" && (0, import_node_fs28.existsSync)(path)) {
63102
+ if (kind === "trace" && event !== "unlink" && (0, import_node_fs29.existsSync)(path)) {
62570
63103
  const id = appIdFromLogPath(path);
62571
63104
  if (!id) return;
62572
63105
  try {
62573
- broadcast({ type: "trace-file", id, runId: path.split(import_node_path26.sep).pop()?.replace(/\.jsonl$/, "") ?? null, events: parseTrace((0, import_node_fs28.readFileSync)(path, "utf8")) });
63106
+ broadcast({ type: "trace-file", id, runId: path.split(import_node_path27.sep).pop()?.replace(/\.jsonl$/, "") ?? null, events: parseTrace((0, import_node_fs29.readFileSync)(path, "utf8")) });
62574
63107
  } catch {
62575
63108
  }
62576
63109
  }
@@ -62579,10 +63112,10 @@ function startWatcher() {
62579
63112
  }
62580
63113
 
62581
63114
  // index.ts
62582
- var __dirname4 = (0, import_node_path27.dirname)((0, import_node_url5.fileURLToPath)(__import_meta_url));
62583
- var WEB_ROOT = [(0, import_node_path27.join)(__dirname4, "web"), (0, import_node_path27.join)((0, import_node_path27.dirname)(process.execPath), "web"), (0, import_node_path27.join)(__dirname4, "..", "web")].find(
62584
- (p) => (0, import_node_fs29.existsSync)(p)
62585
- ) ?? (0, import_node_path27.join)(__dirname4, "..", "web");
63115
+ var __dirname4 = (0, import_node_path28.dirname)((0, import_node_url5.fileURLToPath)(__import_meta_url));
63116
+ var WEB_ROOT = [(0, import_node_path28.join)(__dirname4, "web"), (0, import_node_path28.join)((0, import_node_path28.dirname)(process.execPath), "web"), (0, import_node_path28.join)(__dirname4, "..", "web")].find(
63117
+ (p) => (0, import_node_fs30.existsSync)(p)
63118
+ ) ?? (0, import_node_path28.join)(__dirname4, "..", "web");
62586
63119
  var PORT2 = Number(process.env.PORT ?? 4317);
62587
63120
  var HOST = "127.0.0.1";
62588
63121
  var crashHandlersInstalled = false;
@@ -62598,7 +63131,7 @@ function installCrashHandlers() {
62598
63131
  ${stack}
62599
63132
  `;
62600
63133
  try {
62601
- (0, import_node_fs29.appendFileSync)(logFilePath(), line);
63134
+ (0, import_node_fs30.appendFileSync)(logFilePath(), line);
62602
63135
  } catch {
62603
63136
  }
62604
63137
  if (process.stderr.isTTY) process.stderr.write(line);
@@ -62766,9 +63299,9 @@ async function startServer() {
62766
63299
  if (!title || !body) {
62767
63300
  return reply.status(400).send({ ok: false, error: "title and body are required" });
62768
63301
  }
62769
- const clamp = (s, n) => s.length > n ? s.slice(0, n) : s;
63302
+ const clamp2 = (s, n) => s.length > n ? s.slice(0, n) : s;
62770
63303
  const context = b.context && typeof b.context === "object" && !Array.isArray(b.context) && JSON.stringify(b.context).length <= 16e3 ? b.context : void 0;
62771
- const result = await reportIssue({ category, title: clamp(title, 200), body: clamp(body, 12e3), context });
63304
+ const result = await reportIssue({ category, title: clamp2(title, 200), body: clamp2(body, 12e3), context });
62772
63305
  if (result.ok) return { ok: true, ref: result.ref };
62773
63306
  const status = result.error === "signed_out" ? 401 : result.error === "rate_limited" ? 429 : 503;
62774
63307
  return reply.status(status).send({ ok: false, error: result.error });
@@ -62861,24 +63394,64 @@ async function startServer() {
62861
63394
  });
62862
63395
  app.get("/api/apps", async () => {
62863
63396
  const apps = await aware.list();
62864
- return { ok: true, apps: apps.map((a) => ({ ...a, provider: appProvider(a.id), baked: appBaked(a.id) })) };
63397
+ return { ok: true, apps: apps.map((a) => ({ ...a, provider: appProvider(a.id), baked: appBaked(a.id), ...appOrigin(a.id) })) };
62865
63398
  });
62866
63399
  app.get("/api/workflows/updates", async () => {
62867
63400
  const apps = await aware.list();
62868
- const installed = {};
63401
+ const installed = [];
62869
63402
  for (const a of apps) {
62870
63403
  try {
62871
- installed[a.id] = readApp(a.id).version;
63404
+ const { templateId, forked } = appOrigin(a.id);
63405
+ const app2 = readApp(a.id);
63406
+ installed.push({ id: a.id, version: app2.version, templateId, forked, publisher: app2.publisher });
62872
63407
  } catch {
62873
63408
  }
62874
63409
  }
62875
63410
  return { ok: true, updates: detectUpdates(installed, loadTemplates()) };
62876
63411
  });
62877
63412
  const _wfUpdating = /* @__PURE__ */ new Set();
63413
+ class TemplateSwapError extends Error {
63414
+ code;
63415
+ backupPath;
63416
+ constructor(message, code, backupPath) {
63417
+ super(message);
63418
+ this.name = "TemplateSwapError";
63419
+ this.code = code;
63420
+ this.backupPath = backupPath;
63421
+ }
63422
+ }
63423
+ async function swapTemplateIntoApp(opts) {
63424
+ const { id, templateId, templatePath, srcPath, appDirPath: appDirPath2, fromVersion, contract, verb } = opts;
63425
+ const bdir = backupDir(id, fromVersion, Date.now());
63426
+ try {
63427
+ (0, import_node_fs30.mkdirSync)((0, import_node_path28.dirname)(bdir), { recursive: true });
63428
+ (0, import_node_fs30.cpSync)(appDirPath2, bdir, { recursive: true });
63429
+ (0, import_node_fs30.cpSync)(templatePath, srcPath);
63430
+ if (id !== templateId) stampSourceAppId(srcPath, id);
63431
+ if (contract != null) {
63432
+ bakeContractIntoApp(srcPath, contract);
63433
+ await bakeDownstream(srcPath, id, contract);
63434
+ }
63435
+ await aware.compile(srcPath);
63436
+ return { backupPath: bdir };
63437
+ } catch (e) {
63438
+ const msg = e instanceof Error ? e.message : String(e);
63439
+ try {
63440
+ (0, import_node_fs30.rmSync)(appDirPath2, { recursive: true, force: true });
63441
+ (0, import_node_fs30.cpSync)(bdir, appDirPath2, { recursive: true });
63442
+ } catch (re) {
63443
+ const rmsg = re instanceof Error ? re.message : String(re);
63444
+ throw new TemplateSwapError(`${verb} failed (${msg}) AND rollback failed (${rmsg}) \u2014 restore manually from ${bdir}`, "rollback-failed", bdir);
63445
+ }
63446
+ throw new TemplateSwapError(`${verb} failed (rolled back to ${fromVersion}): ${msg}`, `${verb}-failed`);
63447
+ }
63448
+ }
62878
63449
  app.post("/api/workflows/:id/update", async (req, reply) => {
62879
63450
  const id = req.params.id;
62880
- const t = loadTemplates().find((x) => x.id === id);
62881
- if (!t) return reply.status(404).send({ ok: false, error: `no bundled template for "${id}"`, code: "no-template" });
63451
+ const { templateId, forked } = appOrigin(id);
63452
+ if (forked) return reply.status(409).send({ ok: false, error: `"${id}" is a fork (off the update channel) \u2014 restore it to the official version first to rejoin`, code: "forked" });
63453
+ const t = loadTemplates().find((x) => x.id === templateId);
63454
+ if (!t) return reply.status(404).send({ ok: false, error: `no bundled template in the lineage of "${id}"`, code: "no-template" });
62882
63455
  if (t.publisher !== "floless") return reply.status(400).send({ ok: false, error: `"${id}" is not a FloLess-published workflow`, code: "not-published" });
62883
63456
  if (_wfUpdating.has(id)) return reply.status(409).send({ ok: false, error: `an update for "${id}" is already in progress`, code: "in-progress" });
62884
63457
  let fromVersion;
@@ -62896,7 +63469,7 @@ async function startServer() {
62896
63469
  return reply.status(409).send({ ok: false, error: `"${id}" is already at ${fromVersion}`, code: "up-to-date" });
62897
63470
  }
62898
63471
  const contract = readContract(id);
62899
- if (contract == null && (0, import_node_fs29.existsSync)(contractPath(id))) {
63472
+ if (contract == null && (0, import_node_fs30.existsSync)(contractPath(id))) {
62900
63473
  return reply.status(409).send({ ok: false, error: `"${id}"'s saved data is unreadable \u2014 open it in the editor and re-save before updating`, code: "contract-corrupt" });
62901
63474
  }
62902
63475
  if (contract != null) {
@@ -62904,28 +63477,13 @@ async function startServer() {
62904
63477
  if (!v.valid) return reply.status(409).send({ ok: false, error: `"${id}"'s saved data is invalid \u2014 re-save it in the editor before updating`, code: "contract-invalid" });
62905
63478
  }
62906
63479
  _wfUpdating.add(id);
62907
- const bdir = backupDir(id, fromVersion, Date.now());
62908
63480
  try {
62909
- (0, import_node_fs29.mkdirSync)((0, import_node_path27.dirname)(bdir), { recursive: true });
62910
- (0, import_node_fs29.cpSync)(appDirPath2, bdir, { recursive: true });
62911
- (0, import_node_fs29.cpSync)(t.path, srcPath);
62912
- if (contract != null) {
62913
- bakeContractIntoApp(srcPath, contract);
62914
- await bakeDownstream(srcPath, id, contract);
62915
- }
62916
- await aware.compile(srcPath);
63481
+ const { backupPath } = await swapTemplateIntoApp({ id, templateId, templatePath: t.path, srcPath, appDirPath: appDirPath2, fromVersion, contract, verb: "update" });
62917
63482
  broadcast({ type: "apps-changed", id });
62918
- return { ok: true, id, fromVersion, toVersion: t.version, backupPath: bdir };
63483
+ return { ok: true, id, fromVersion, toVersion: t.version, backupPath };
62919
63484
  } catch (e) {
62920
- const msg = e instanceof Error ? e.message : String(e);
62921
- try {
62922
- (0, import_node_fs29.rmSync)(appDirPath2, { recursive: true, force: true });
62923
- (0, import_node_fs29.cpSync)(bdir, appDirPath2, { recursive: true });
62924
- } catch (re) {
62925
- const rmsg = re instanceof Error ? re.message : String(re);
62926
- return reply.status(500).send({ ok: false, error: `update failed (${msg}) AND rollback failed (${rmsg}) \u2014 restore manually from ${bdir}`, code: "rollback-failed", backupPath: bdir });
62927
- }
62928
- return reply.status(500).send({ ok: false, error: `update failed (rolled back to ${fromVersion}): ${msg}`, code: "update-failed" });
63485
+ if (e instanceof TemplateSwapError) return reply.status(500).send({ ok: false, error: e.message, code: e.code, ...e.backupPath ? { backupPath: e.backupPath } : {} });
63486
+ throw e;
62929
63487
  } finally {
62930
63488
  _wfUpdating.delete(id);
62931
63489
  }
@@ -63192,7 +63750,7 @@ async function startServer() {
63192
63750
  }
63193
63751
  const companionId = `${req.params.appId}-ifc`;
63194
63752
  const filename = `${req.params.appId}.ifc`;
63195
- const outPath = (0, import_node_path27.join)(appPath(companionId), filename);
63753
+ const outPath = (0, import_node_path28.join)(appPath(companionId), filename);
63196
63754
  let flo;
63197
63755
  try {
63198
63756
  flo = writeIfcApp(appPath(companionId), companionId, scene, outPath);
@@ -63215,8 +63773,8 @@ async function startServer() {
63215
63773
  }
63216
63774
  throw e;
63217
63775
  }
63218
- if (!(0, import_node_fs29.existsSync)(outPath)) return reply.send({ ok: false, error: "the IFC export produced no file" });
63219
- const content = (0, import_node_fs29.readFileSync)(outPath, "utf8");
63776
+ if (!(0, import_node_fs30.existsSync)(outPath)) return reply.send({ ok: false, error: "the IFC export produced no file" });
63777
+ const content = (0, import_node_fs30.readFileSync)(outPath, "utf8");
63220
63778
  broadcast({ type: "apps-changed" });
63221
63779
  return { ok: true, filename, content, bytes: Buffer.byteLength(content), skipped };
63222
63780
  });
@@ -63295,17 +63853,17 @@ async function startServer() {
63295
63853
  return reply.status(422).send({ ok: false, error: "no priced members to export \u2014 every member is an RFI (no AISC size / weight yet)" });
63296
63854
  }
63297
63855
  const outPath = bomExportPath(appId, format);
63298
- const dir = (0, import_node_path27.dirname)(outPath);
63856
+ const dir = (0, import_node_path28.dirname)(outPath);
63299
63857
  const filename = `${appId}-bom.${format}`;
63300
63858
  try {
63301
- (0, import_node_fs29.mkdirSync)(dir, { recursive: true });
63859
+ (0, import_node_fs30.mkdirSync)(dir, { recursive: true });
63302
63860
  if (format === "csv") {
63303
63861
  const text = bomToCsv(bom);
63304
- (0, import_node_fs29.writeFileSync)(outPath, text, "utf8");
63862
+ (0, import_node_fs30.writeFileSync)(outPath, text, "utf8");
63305
63863
  return { ok: true, filename, encoding: "utf8", content: text, bytes: Buffer.byteLength(text), savedTo: outPath };
63306
63864
  }
63307
63865
  const buf = await bomToXlsx(bom);
63308
- (0, import_node_fs29.writeFileSync)(outPath, buf);
63866
+ (0, import_node_fs30.writeFileSync)(outPath, buf);
63309
63867
  return { ok: true, filename, encoding: "base64", content: buf.toString("base64"), bytes: buf.length, savedTo: outPath };
63310
63868
  } catch (e) {
63311
63869
  app.log.error({ appId, format, err: e instanceof Error ? e.message : e }, "export-bom: generation failed");
@@ -63341,6 +63899,60 @@ async function startServer() {
63341
63899
  broadcast({ type: "apps-changed", id: req.params.id });
63342
63900
  return { ok: true };
63343
63901
  });
63902
+ app.post("/api/app/:id/fork", async (req, reply) => {
63903
+ const id = req.params.id;
63904
+ if (!appExists(id)) return reply.status(404).send({ ok: false, error: `"${id}" is not installed`, code: "not-installed" });
63905
+ if (req.body?.accept !== true) return reply.status(400).send({ ok: false, error: "liability terms not accepted", code: "terms-required" });
63906
+ let version;
63907
+ try {
63908
+ version = readApp(id).version;
63909
+ } catch {
63910
+ return reply.status(404).send({ ok: false, error: `"${id}" is not installed`, code: "not-installed" });
63911
+ }
63912
+ const acceptedBy = typeof req.body?.acceptedBy === "string" ? req.body.acceptedBy : void 0;
63913
+ markForked(id, { version, acceptedBy }, (/* @__PURE__ */ new Date()).toISOString());
63914
+ broadcast({ type: "apps-changed", id });
63915
+ return { ok: true, id, forked: true };
63916
+ });
63917
+ app.post("/api/app/:id/restore", async (req, reply) => {
63918
+ const id = req.params.id;
63919
+ const { templateId } = appOrigin(id);
63920
+ const t = loadTemplates().find((x) => x.id === templateId);
63921
+ if (!t) return reply.status(404).send({ ok: false, error: `no bundled template to restore "${id}" from`, code: "no-template" });
63922
+ if (t.publisher !== "floless") return reply.status(400).send({ ok: false, error: `"${id}" has no FloLess-published template to restore from`, code: "not-published" });
63923
+ if (_wfUpdating.has(id)) return reply.status(409).send({ ok: false, error: `an operation for "${id}" is already in progress`, code: "in-progress" });
63924
+ let fromVersion;
63925
+ let srcPath;
63926
+ let appDirPath2;
63927
+ try {
63928
+ const a = readApp(id);
63929
+ fromVersion = a.version;
63930
+ srcPath = a.source.path;
63931
+ appDirPath2 = appDir(id);
63932
+ } catch {
63933
+ return reply.status(404).send({ ok: false, error: `"${id}" is not installed`, code: "not-installed" });
63934
+ }
63935
+ const contract = readContract(id);
63936
+ if (contract == null && (0, import_node_fs30.existsSync)(contractPath(id))) {
63937
+ return reply.status(409).send({ ok: false, error: `"${id}"'s saved data is unreadable \u2014 open it in the editor and re-save before restoring`, code: "contract-corrupt" });
63938
+ }
63939
+ if (contract != null) {
63940
+ const v = validateSteelTakeoff(contract);
63941
+ if (!v.valid) return reply.status(409).send({ ok: false, error: `"${id}"'s saved data is invalid \u2014 re-save it in the editor before restoring`, code: "contract-invalid" });
63942
+ }
63943
+ _wfUpdating.add(id);
63944
+ try {
63945
+ const { backupPath } = await swapTemplateIntoApp({ id, templateId, templatePath: t.path, srcPath, appDirPath: appDirPath2, fromVersion, contract, verb: "restore" });
63946
+ clearFork(id);
63947
+ broadcast({ type: "apps-changed", id });
63948
+ return { ok: true, id, restored: true, version: t.version, backupPath };
63949
+ } catch (e) {
63950
+ if (e instanceof TemplateSwapError) return reply.status(500).send({ ok: false, error: e.message, code: e.code, ...e.backupPath ? { backupPath: e.backupPath } : {} });
63951
+ throw e;
63952
+ } finally {
63953
+ _wfUpdating.delete(id);
63954
+ }
63955
+ });
63344
63956
  app.post("/api/app/:id/freeze", async (req, reply) => {
63345
63957
  const nodeId = typeof req.body?.nodeId === "string" ? req.body.nodeId.trim() : "";
63346
63958
  if (!nodeId) return reply.status(400).send({ ok: false, error: "nodeId required" });
@@ -63399,11 +64011,11 @@ async function startServer() {
63399
64011
  if (appExists(id)) {
63400
64012
  return reply.status(409).send({ ok: false, error: `a workflow named "${id}" is already installed \u2014 remove it first, or rename the file's app: id`, code: "exists", id });
63401
64013
  }
63402
- const stageRoot = (0, import_node_fs29.mkdtempSync)((0, import_node_path27.join)((0, import_node_os19.tmpdir)(), "floless-import-"));
64014
+ const stageRoot = (0, import_node_fs30.mkdtempSync)((0, import_node_path28.join)((0, import_node_os20.tmpdir)(), "floless-import-"));
63403
64015
  try {
63404
- const stageDir = (0, import_node_path27.join)(stageRoot, id);
63405
- (0, import_node_fs29.mkdirSync)(stageDir);
63406
- (0, import_node_fs29.writeFileSync)((0, import_node_path27.join)(stageDir, `${id}.flo`), content);
64016
+ const stageDir = (0, import_node_path28.join)(stageRoot, id);
64017
+ (0, import_node_fs30.mkdirSync)(stageDir);
64018
+ (0, import_node_fs30.writeFileSync)((0, import_node_path28.join)(stageDir, `${id}.flo`), content);
63407
64019
  await aware.install(stageDir);
63408
64020
  } catch (err2) {
63409
64021
  try {
@@ -63413,7 +64025,7 @@ async function startServer() {
63413
64025
  const msg = err2 instanceof AwareError ? err2.message : String(err2?.message ?? err2);
63414
64026
  return reply.status(502).send({ ok: false, error: `import failed: ${msg}` });
63415
64027
  } finally {
63416
- (0, import_node_fs29.rmSync)(stageRoot, { recursive: true, force: true });
64028
+ (0, import_node_fs30.rmSync)(stageRoot, { recursive: true, force: true });
63417
64029
  }
63418
64030
  broadcast({ type: "apps-changed", id });
63419
64031
  return { ok: true, id };
@@ -63427,13 +64039,13 @@ async function startServer() {
63427
64039
  }
63428
64040
  const inputs = appData.inputs.map((i) => ({ name: i.name, type: i.type }));
63429
64041
  const baked = bakeFloSource(appData.source.text, inputs);
63430
- const tmpRoot = (0, import_node_fs29.mkdtempSync)((0, import_node_path27.join)((0, import_node_os19.tmpdir)(), "floless-bake-"));
63431
- const backupDir2 = (0, import_node_path27.join)(tmpRoot, `${id}-backup`);
63432
- const bakeDir = (0, import_node_path27.join)(tmpRoot, id);
63433
- (0, import_node_fs29.cpSync)(appDir(id), backupDir2, { recursive: true });
63434
- (0, import_node_fs29.cpSync)(appDir(id), bakeDir, { recursive: true });
64042
+ const tmpRoot = (0, import_node_fs30.mkdtempSync)((0, import_node_path28.join)((0, import_node_os20.tmpdir)(), "floless-bake-"));
64043
+ const backupDir2 = (0, import_node_path28.join)(tmpRoot, `${id}-backup`);
64044
+ const bakeDir = (0, import_node_path28.join)(tmpRoot, id);
64045
+ (0, import_node_fs30.cpSync)(appDir(id), backupDir2, { recursive: true });
64046
+ (0, import_node_fs30.cpSync)(appDir(id), bakeDir, { recursive: true });
63435
64047
  const floName = appData.source.path.split(/[\\/]/).pop();
63436
- (0, import_node_fs29.writeFileSync)((0, import_node_path27.join)(bakeDir, floName), baked);
64048
+ (0, import_node_fs30.writeFileSync)((0, import_node_path28.join)(bakeDir, floName), baked);
63437
64049
  let appInstalled2 = true;
63438
64050
  try {
63439
64051
  await aware.uninstall(id);
@@ -63455,17 +64067,17 @@ async function startServer() {
63455
64067
  throw installErr;
63456
64068
  }
63457
64069
  try {
63458
- await aware.compile((0, import_node_path27.join)(appDir(id), floName));
64070
+ await aware.compile((0, import_node_path28.join)(appDir(id), floName));
63459
64071
  } catch (compileErr) {
63460
64072
  app.log.warn({ id, compileErr: String(compileErr) }, "bake: post-install recompile failed (app baked but may need a manual Compile)");
63461
64073
  }
63462
64074
  broadcast({ type: "baked", id });
63463
64075
  return { ok: true, id, agent: id, inputs };
63464
64076
  } finally {
63465
- if (appInstalled2) (0, import_node_fs29.rmSync)(tmpRoot, { recursive: true, force: true });
64077
+ if (appInstalled2) (0, import_node_fs30.rmSync)(tmpRoot, { recursive: true, force: true });
63466
64078
  }
63467
64079
  });
63468
- const graftAgentsDir = () => (0, import_node_path27.join)((0, import_node_os19.homedir)(), ".aware", "agents");
64080
+ const graftAgentsDir = () => (0, import_node_path28.join)((0, import_node_os20.homedir)(), ".aware", "agents");
63469
64081
  app.post("/api/graft/match", async (req, reply) => {
63470
64082
  const { glob } = req.body ?? {};
63471
64083
  if (!glob) return reply.status(400).send({ ok: false, error: "glob required" });
@@ -63482,7 +64094,7 @@ async function startServer() {
63482
64094
  if (!sourceKind || !sourceRef) {
63483
64095
  return reply.status(400).send({ ok: false, error: "sourceKind and sourceRef required" });
63484
64096
  }
63485
- const tempHome = (0, import_node_fs29.mkdtempSync)((0, import_node_path27.join)((0, import_node_os19.tmpdir)(), "floless-graft-"));
64097
+ const tempHome = (0, import_node_fs30.mkdtempSync)((0, import_node_path28.join)((0, import_node_os20.tmpdir)(), "floless-graft-"));
63486
64098
  let result;
63487
64099
  try {
63488
64100
  result = await aware.build({
@@ -63495,19 +64107,19 @@ async function startServer() {
63495
64107
  awareHome: tempHome
63496
64108
  });
63497
64109
  } catch (err2) {
63498
- (0, import_node_fs29.rmSync)(tempHome, { recursive: true, force: true });
64110
+ (0, import_node_fs30.rmSync)(tempHome, { recursive: true, force: true });
63499
64111
  const msg = err2 instanceof AwareError ? err2.message : String(err2?.message ?? err2);
63500
64112
  return reply.status(422).send({ ok: false, error: msg });
63501
64113
  }
63502
64114
  const manifest = readStagedManifest(result.agentDir);
63503
64115
  if (!manifest) {
63504
- (0, import_node_fs29.rmSync)(tempHome, { recursive: true, force: true });
64116
+ (0, import_node_fs30.rmSync)(tempHome, { recursive: true, force: true });
63505
64117
  return reply.status(502).send({ ok: false, error: `build produced output at ${result.agentDir} but no manifest.yaml` });
63506
64118
  }
63507
64119
  const token = (0, import_node_crypto7.randomUUID)();
63508
64120
  registerStage(token, tempHome, result.agentId);
63509
64121
  const preview = buildPreview(manifest, sourceKind, sourceRef, token);
63510
- if ((0, import_node_fs29.existsSync)((0, import_node_path27.join)(graftAgentsDir(), result.agentId))) {
64122
+ if ((0, import_node_fs30.existsSync)((0, import_node_path28.join)(graftAgentsDir(), result.agentId))) {
63511
64123
  preview.warnings.unshift(`An agent named "${result.agentId}" is already installed \u2014 creating it will overwrite it.`);
63512
64124
  }
63513
64125
  return { ok: true, preview };
@@ -63526,7 +64138,7 @@ async function startServer() {
63526
64138
  registerStage(stagedRef, stage.tempDir, stage.agentId);
63527
64139
  return reply.status(409).send({ ok: false, error: err2.message, agentId: stage.agentId, collision: true });
63528
64140
  }
63529
- (0, import_node_fs29.rmSync)(stage.tempDir, { recursive: true, force: true });
64141
+ (0, import_node_fs30.rmSync)(stage.tempDir, { recursive: true, force: true });
63530
64142
  throw err2;
63531
64143
  }
63532
64144
  broadcast({ type: "grafted", id: stage.agentId });
@@ -63786,11 +64398,11 @@ async function startServer() {
63786
64398
  app.get("/api/requests/:id/snapshot/:n", async (req, reply) => {
63787
64399
  const n = Number.parseInt(req.params.n, 10);
63788
64400
  const p = Number.isInteger(n) ? snapshotPathFor(req.params.id, n) : null;
63789
- if (!p || !(0, import_node_fs29.existsSync)(p)) return reply.status(404).send({ ok: false, error: "snapshot not found" });
64401
+ if (!p || !(0, import_node_fs30.existsSync)(p)) return reply.status(404).send({ ok: false, error: "snapshot not found" });
63790
64402
  const ext = p.split(".").pop().toLowerCase();
63791
64403
  reply.header("Content-Type", ext === "png" ? "image/png" : ext === "webp" ? "image/webp" : ext === "pdf" ? "application/pdf" : "image/jpeg");
63792
64404
  reply.header("Cache-Control", "no-store");
63793
- return (0, import_node_fs29.readFileSync)(p);
64405
+ return (0, import_node_fs30.readFileSync)(p);
63794
64406
  });
63795
64407
  app.post(
63796
64408
  "/api/tweak",
@@ -63883,6 +64495,11 @@ async function startServer() {
63883
64495
  broadcast({ type: "request-added", request });
63884
64496
  return { ok: true, request };
63885
64497
  });
64498
+ app.post("/api/guide-new", async (_req, _reply) => {
64499
+ const request = addRequest({ type: "new-workflow" });
64500
+ broadcast({ type: "request-added", request });
64501
+ return { ok: true, request };
64502
+ });
63886
64503
  app.delete("/api/requests/:id", async (req, reply) => {
63887
64504
  if (!deleteRequest(req.params.id)) return reply.status(404).send({ ok: false, error: "request not found" });
63888
64505
  broadcast({ type: "requests-changed" });
@@ -63947,7 +64564,7 @@ async function startServer() {
63947
64564
  warn(`last-run-status:${ref} \u2014 trace exists but couldn't be parsed (corrupt/truncated)`);
63948
64565
  let finishedAt2 = null;
63949
64566
  try {
63950
- finishedAt2 = (0, import_node_fs29.statSync)(latest.path).mtime.toISOString();
64567
+ finishedAt2 = (0, import_node_fs30.statSync)(latest.path).mtime.toISOString();
63951
64568
  } catch {
63952
64569
  finishedAt2 = null;
63953
64570
  }
@@ -63957,7 +64574,7 @@ async function startServer() {
63957
64574
  let finishedAt = typeof runEnd?.ts === "string" ? runEnd.ts : null;
63958
64575
  if (!finishedAt) {
63959
64576
  try {
63960
- finishedAt = (0, import_node_fs29.statSync)(latest.path).mtime.toISOString();
64577
+ finishedAt = (0, import_node_fs30.statSync)(latest.path).mtime.toISOString();
63961
64578
  } catch {
63962
64579
  finishedAt = null;
63963
64580
  }