@floless/app 0.126.3 → 0.126.5
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.
- package/dist/floless-server.cjs +1200 -688
- package/dist/skills/floless-app-new-workflow/SKILL.md +18 -1
- package/dist/skills/floless-app-workflows/SKILL.md +20 -1
- package/dist/web/app.css +184 -6
- package/dist/web/aware.js +474 -4
- package/dist/web/index.html +44 -1
- package/dist/web/steel-3d-view.js +14 -2
- package/dist/web/steel-editor.html +7 -6
- package/dist/web/workspaces.js +24 -1
- package/package.json +1 -1
package/dist/floless-server.cjs
CHANGED
|
@@ -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:
|
|
5492
|
+
var { join: join60 } = 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"] ||
|
|
5543
|
+
const toExecute = bundlerOverrides["thread-stream-worker"] || join60(__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:
|
|
6009
|
+
var { existsSync: existsSync57 } = require("node:fs");
|
|
6010
6010
|
var getCallers = require_caller();
|
|
6011
|
-
var { join:
|
|
6011
|
+
var { join: join60, isAbsolute: isAbsolute5, sep: sep8 } = require("node:path");
|
|
6012
6012
|
var { fileURLToPath: fileURLToPath6 } = require("node:url");
|
|
6013
6013
|
var sleep2 = 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 isAbsolute5(path) && !
|
|
6083
|
+
return isAbsolute5(path) && !existsSync57(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"] ||
|
|
6164
|
+
target = bundlerOverrides["pino-worker"] || join60(__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 (pipeline3) {
|
|
6182
|
-
target = bundlerOverrides["pino-worker"] ||
|
|
6182
|
+
target = bundlerOverrides["pino-worker"] || join60(__dirname, "worker.js");
|
|
6183
6183
|
options.pipelines = [pipeline3.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
|
|
6205
|
+
return join60(__dirname, "..", "file.js");
|
|
6206
6206
|
}
|
|
6207
6207
|
let fixTarget2;
|
|
6208
6208
|
for (const filePath of callers) {
|
|
@@ -7182,7 +7182,7 @@ var require_safe_stable_stringify = __commonJS({
|
|
|
7182
7182
|
return circularValue;
|
|
7183
7183
|
}
|
|
7184
7184
|
let res = "";
|
|
7185
|
-
let
|
|
7185
|
+
let join60 = ",";
|
|
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
|
-
|
|
7199
|
+
join60 = `,
|
|
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 +=
|
|
7207
|
+
res += join60;
|
|
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 += `${
|
|
7213
|
+
res += `${join60}"... ${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
|
-
|
|
7234
|
+
join60 = `,
|
|
7235
7235
|
${indentation}`;
|
|
7236
7236
|
whitespace = " ";
|
|
7237
7237
|
}
|
|
@@ -7245,13 +7245,13 @@ ${indentation}`;
|
|
|
7245
7245
|
const tmp = stringifyFnReplacer(key3, value, stack, replacer, spacer, indentation);
|
|
7246
7246
|
if (tmp !== void 0) {
|
|
7247
7247
|
res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
|
|
7248
|
-
separator =
|
|
7248
|
+
separator = join60;
|
|
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 =
|
|
7254
|
+
separator = join60;
|
|
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
|
|
7295
|
+
let join60 = ",";
|
|
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
|
-
|
|
7308
|
+
join60 = `,
|
|
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 +=
|
|
7316
|
+
res += join60;
|
|
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 += `${
|
|
7322
|
+
res += `${join60}"... ${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
|
-
|
|
7335
|
+
join60 = `,
|
|
7336
7336
|
${indentation}`;
|
|
7337
7337
|
whitespace = " ";
|
|
7338
7338
|
}
|
|
@@ -7341,7 +7341,7 @@ ${indentation}`;
|
|
|
7341
7341
|
const tmp = stringifyArrayReplacer(key3, value[key3], stack, replacer, spacer, indentation);
|
|
7342
7342
|
if (tmp !== void 0) {
|
|
7343
7343
|
res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
|
|
7344
|
-
separator =
|
|
7344
|
+
separator = join60;
|
|
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
|
|
7402
|
+
const join61 = `,
|
|
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 +=
|
|
7409
|
+
res2 += join61;
|
|
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 += `${
|
|
7415
|
+
res2 += `${join61}"... ${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
|
|
7431
|
+
const join60 = `,
|
|
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,
|
|
7437
|
+
res += stringifyTypedArray(value, join60, maximumBreadth);
|
|
7438
7438
|
keys = keys.slice(value.length);
|
|
7439
7439
|
maximumPropertiesToStringify -= value.length;
|
|
7440
|
-
separator =
|
|
7440
|
+
separator = join60;
|
|
7441
7441
|
}
|
|
7442
7442
|
if (deterministic) {
|
|
7443
7443
|
keys = sort(keys, comparator);
|
|
@@ -7448,13 +7448,13 @@ ${indentation}`;
|
|
|
7448
7448
|
const tmp = stringifyIndent(key3, value[key3], stack, spacer, indentation);
|
|
7449
7449
|
if (tmp !== void 0) {
|
|
7450
7450
|
res += `${separator}${strEscape(key3)}: ${tmp}`;
|
|
7451
|
-
separator =
|
|
7451
|
+
separator = join60;
|
|
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 =
|
|
7457
|
+
separator = join60;
|
|
7458
7458
|
}
|
|
7459
7459
|
if (separator !== "") {
|
|
7460
7460
|
res = `
|
|
@@ -41991,7 +41991,7 @@ var require_send = __commonJS({
|
|
|
41991
41991
|
var { parseTokenList } = require_parseTokenList();
|
|
41992
41992
|
var { createHttpError } = require_createHttpError();
|
|
41993
41993
|
var extname4 = path.extname;
|
|
41994
|
-
var
|
|
41994
|
+
var join60 = path.join;
|
|
41995
41995
|
var normalize2 = path.normalize;
|
|
41996
41996
|
var resolve17 = path.resolve;
|
|
41997
41997
|
var sep8 = path.sep;
|
|
@@ -42078,7 +42078,7 @@ var require_send = __commonJS({
|
|
|
42078
42078
|
return { statusCode: 403 };
|
|
42079
42079
|
}
|
|
42080
42080
|
parts = path2.split(sep8);
|
|
42081
|
-
path2 = normalize2(
|
|
42081
|
+
path2 = normalize2(join60(root5, path2));
|
|
42082
42082
|
} else {
|
|
42083
42083
|
if (UP_PATH_REGEXP.test(path2)) {
|
|
42084
42084
|
debug('malicious path "%s"', path2);
|
|
@@ -42187,7 +42187,7 @@ var require_send = __commonJS({
|
|
|
42187
42187
|
});
|
|
42188
42188
|
});
|
|
42189
42189
|
}
|
|
42190
|
-
function
|
|
42190
|
+
function sendError3(statusCode, err2) {
|
|
42191
42191
|
const headers = {};
|
|
42192
42192
|
if (err2 && err2.headers) {
|
|
42193
42193
|
for (const headerName in err2.headers) {
|
|
@@ -42213,9 +42213,9 @@ var require_send = __commonJS({
|
|
|
42213
42213
|
case "ENAMETOOLONG":
|
|
42214
42214
|
case "ENOTDIR":
|
|
42215
42215
|
case "ENOENT":
|
|
42216
|
-
return
|
|
42216
|
+
return sendError3(404, err2);
|
|
42217
42217
|
default:
|
|
42218
|
-
return
|
|
42218
|
+
return sendError3(500, err2);
|
|
42219
42219
|
}
|
|
42220
42220
|
}
|
|
42221
42221
|
function sendNotModified(headers, path2, stat4) {
|
|
@@ -42274,7 +42274,7 @@ var require_send = __commonJS({
|
|
|
42274
42274
|
}
|
|
42275
42275
|
if (isConditionalGET(request)) {
|
|
42276
42276
|
if (isPreconditionFailure(request, headers)) {
|
|
42277
|
-
return
|
|
42277
|
+
return sendError3(412);
|
|
42278
42278
|
}
|
|
42279
42279
|
if (isNotModifiedFailure(request, headers)) {
|
|
42280
42280
|
return sendNotModified(headers, path2, stat4);
|
|
@@ -42293,7 +42293,7 @@ var require_send = __commonJS({
|
|
|
42293
42293
|
if (ranges.length === 0) {
|
|
42294
42294
|
debug("range unsatisfiable");
|
|
42295
42295
|
headers["Content-Range"] = contentRange("bytes", len);
|
|
42296
|
-
return
|
|
42296
|
+
return sendError3(416, {
|
|
42297
42297
|
headers: { "Content-Range": headers["Content-Range"] }
|
|
42298
42298
|
});
|
|
42299
42299
|
} else if (ranges.length === 1) {
|
|
@@ -42338,7 +42338,7 @@ var require_send = __commonJS({
|
|
|
42338
42338
|
}
|
|
42339
42339
|
function sendRedirect(path2, options) {
|
|
42340
42340
|
if (hasTrailingSlash(options.path)) {
|
|
42341
|
-
return
|
|
42341
|
+
return sendError3(403);
|
|
42342
42342
|
}
|
|
42343
42343
|
const loc = encodeURI(collapseLeadingSlashes(options.path + "/"));
|
|
42344
42344
|
const doc = createHtmlDocument("Redirecting", "Redirecting to " + escapeHtml(loc));
|
|
@@ -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 =
|
|
42364
|
+
const p = join60(path2, index);
|
|
42365
42365
|
const { error, stat: stat4 } = await tryStat(p);
|
|
42366
42366
|
if (error) {
|
|
42367
42367
|
err2 = error;
|
|
@@ -42373,7 +42373,7 @@ var require_send = __commonJS({
|
|
|
42373
42373
|
if (err2) {
|
|
42374
42374
|
return sendStatError(err2);
|
|
42375
42375
|
}
|
|
42376
|
-
return
|
|
42376
|
+
return sendError3(404);
|
|
42377
42377
|
}
|
|
42378
42378
|
async function sendFile(request, path2, options) {
|
|
42379
42379
|
const { error, stat: stat4 } = await tryStat(path2);
|
|
@@ -42396,7 +42396,7 @@ var require_send = __commonJS({
|
|
|
42396
42396
|
if (err2) {
|
|
42397
42397
|
return sendStatError(err2);
|
|
42398
42398
|
}
|
|
42399
|
-
return
|
|
42399
|
+
return sendError3(404);
|
|
42400
42400
|
}
|
|
42401
42401
|
if (error) return sendStatError(error);
|
|
42402
42402
|
if (stat4.isDirectory()) return sendRedirect(path2, options);
|
|
@@ -42408,7 +42408,7 @@ var require_send = __commonJS({
|
|
|
42408
42408
|
const parsed = normalizePath3(_path, opts.root);
|
|
42409
42409
|
const { path: path2, parts } = parsed;
|
|
42410
42410
|
if (parsed.statusCode !== void 0) {
|
|
42411
|
-
return
|
|
42411
|
+
return sendError3(parsed.statusCode);
|
|
42412
42412
|
}
|
|
42413
42413
|
if ((debug.enabled || // if debugging is enabled, then check for all cases to log allow case
|
|
42414
42414
|
opts.dotfiles !== 0) && containsDotFile(parts)) {
|
|
@@ -42421,12 +42421,12 @@ var require_send = __commonJS({
|
|
|
42421
42421
|
/* c8 ignore stop */
|
|
42422
42422
|
case 2:
|
|
42423
42423
|
debug('deny dotfile "%s"', path2);
|
|
42424
|
-
return
|
|
42424
|
+
return sendError3(403);
|
|
42425
42425
|
case 1:
|
|
42426
42426
|
// 'ignore'
|
|
42427
42427
|
default:
|
|
42428
42428
|
debug('ignore dotfile "%s"', path2);
|
|
42429
|
-
return
|
|
42429
|
+
return sendError3(404);
|
|
42430
42430
|
}
|
|
42431
42431
|
}
|
|
42432
42432
|
if (opts.index.length && hasTrailingSlash(_path)) {
|
|
@@ -42657,7 +42657,7 @@ var require_content_disposition = __commonJS({
|
|
|
42657
42657
|
"use strict";
|
|
42658
42658
|
module2.exports = contentDisposition;
|
|
42659
42659
|
module2.exports.parse = parse;
|
|
42660
|
-
var
|
|
42660
|
+
var basename15 = require("path").basename;
|
|
42661
42661
|
var Buffer4 = require_safe_buffer().Buffer;
|
|
42662
42662
|
var ENCODE_URL_ATTR_CHAR_REGEXP = /[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g;
|
|
42663
42663
|
var HEX_ESCAPE_REGEXP = /%[0-9A-Fa-f]{2}/;
|
|
@@ -42693,9 +42693,9 @@ var require_content_disposition = __commonJS({
|
|
|
42693
42693
|
if (typeof fallback2 === "string" && NON_LATIN1_REGEXP.test(fallback2)) {
|
|
42694
42694
|
throw new TypeError("fallback must be ISO-8859-1 string");
|
|
42695
42695
|
}
|
|
42696
|
-
var name =
|
|
42696
|
+
var name = basename15(filename);
|
|
42697
42697
|
var isQuotedString = TEXT_REGEXP.test(name);
|
|
42698
|
-
var fallbackName = typeof fallback2 !== "string" ? fallback2 && getlatin1(name) :
|
|
42698
|
+
var fallbackName = typeof fallback2 !== "string" ? fallback2 && getlatin1(name) : basename15(fallback2);
|
|
42699
42699
|
var hasFallback = typeof fallbackName === "string" && fallbackName !== name;
|
|
42700
42700
|
if (hasFallback || !isQuotedString || HEX_ESCAPE_REGEXP.test(name)) {
|
|
42701
42701
|
params["filename*"] = name;
|
|
@@ -43145,8 +43145,8 @@ var require_static = __commonJS({
|
|
|
43145
43145
|
}
|
|
43146
43146
|
}
|
|
43147
43147
|
}
|
|
43148
|
-
for (const [
|
|
43149
|
-
const pathname =
|
|
43148
|
+
for (const [dirname28, rootPath] of indexDirs.entries()) {
|
|
43149
|
+
const pathname = dirname28 + (dirname28.endsWith("/") ? "" : "/");
|
|
43150
43150
|
const file = "/" + pathname.replace(prefix, "");
|
|
43151
43151
|
setUpHeadAndGet(routeOpts, pathname, file, rootPath);
|
|
43152
43152
|
if (opts.redirect === true) {
|
|
@@ -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
|
|
50831
|
-
var
|
|
50832
|
-
var
|
|
50830
|
+
var import_node_path64 = require("node:path");
|
|
50831
|
+
var import_node_os34 = require("node:os");
|
|
50832
|
+
var import_node_fs68 = require("node:fs");
|
|
50833
50833
|
var import_node_child_process15 = require("node:child_process");
|
|
50834
50834
|
var import_node_util6 = require("node:util");
|
|
50835
50835
|
|
|
@@ -51930,6 +51930,9 @@ async function patch(id, fields) {
|
|
|
51930
51930
|
function resolveTemplateId(id) {
|
|
51931
51931
|
return readOrigin(id)?.derivedFrom ?? id;
|
|
51932
51932
|
}
|
|
51933
|
+
function sameAppLineage(a, b) {
|
|
51934
|
+
return a === b || resolveTemplateId(a) === resolveTemplateId(b);
|
|
51935
|
+
}
|
|
51933
51936
|
function resolveContractAuthorityId(id) {
|
|
51934
51937
|
if (!safeSegment(id)) throw new Error(`invalid contract authority app id: ${id}`);
|
|
51935
51938
|
assertNoPendingContractAuthorityOperation(id);
|
|
@@ -53032,12 +53035,47 @@ function newRunTicket() {
|
|
|
53032
53035
|
}
|
|
53033
53036
|
var activeRun = null;
|
|
53034
53037
|
var runChain = Promise.resolve();
|
|
53038
|
+
var TREE_KILL_RETRY_MS = 75;
|
|
53039
|
+
var TREE_KILL_MAX_ATTEMPTS = 20;
|
|
53040
|
+
var treeKillRetries = /* @__PURE__ */ new WeakMap();
|
|
53041
|
+
function retryWindowsTreeKill(child) {
|
|
53042
|
+
if (!child.pid || treeKillRetries.has(child)) return;
|
|
53043
|
+
const state2 = { attempts: 0, timer: null, closed: false };
|
|
53044
|
+
treeKillRetries.set(child, state2);
|
|
53045
|
+
const clear = () => {
|
|
53046
|
+
state2.closed = true;
|
|
53047
|
+
if (state2.timer) clearTimeout(state2.timer);
|
|
53048
|
+
treeKillRetries.delete(child);
|
|
53049
|
+
};
|
|
53050
|
+
child.once("close", clear);
|
|
53051
|
+
const attempt = () => {
|
|
53052
|
+
if (state2.closed || child.exitCode !== null || child.signalCode !== null) {
|
|
53053
|
+
clear();
|
|
53054
|
+
return;
|
|
53055
|
+
}
|
|
53056
|
+
state2.attempts += 1;
|
|
53057
|
+
(0, import_node_child_process2.execFile)("taskkill", ["/pid", String(child.pid), "/T", "/F"], { windowsHide: true, timeout: 1e3 }, (err2) => {
|
|
53058
|
+
if (!err2 || state2.closed) return;
|
|
53059
|
+
if (state2.attempts >= TREE_KILL_MAX_ATTEMPTS) {
|
|
53060
|
+
try {
|
|
53061
|
+
child.kill();
|
|
53062
|
+
} catch {
|
|
53063
|
+
}
|
|
53064
|
+
return;
|
|
53065
|
+
}
|
|
53066
|
+
state2.timer = setTimeout(attempt, TREE_KILL_RETRY_MS);
|
|
53067
|
+
});
|
|
53068
|
+
};
|
|
53069
|
+
attempt();
|
|
53070
|
+
}
|
|
53035
53071
|
function killTree(child) {
|
|
53036
53072
|
if (process.platform === "win32" && child.pid) {
|
|
53037
53073
|
try {
|
|
53038
53074
|
(0, import_node_child_process2.execFileSync)("taskkill", ["/pid", String(child.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 5e3 });
|
|
53039
53075
|
return;
|
|
53040
53076
|
} catch {
|
|
53077
|
+
retryWindowsTreeKill(child);
|
|
53078
|
+
return;
|
|
53041
53079
|
}
|
|
53042
53080
|
}
|
|
53043
53081
|
try {
|
|
@@ -54612,7 +54650,7 @@ function appVersion() {
|
|
|
54612
54650
|
return resolveVersion({
|
|
54613
54651
|
isSea: isSea2(),
|
|
54614
54652
|
sqVersionXml: readSqVersionXml(),
|
|
54615
|
-
define: true ? "0.126.
|
|
54653
|
+
define: true ? "0.126.5" : void 0,
|
|
54616
54654
|
pkgVersion: readPkgVersion()
|
|
54617
54655
|
});
|
|
54618
54656
|
}
|
|
@@ -54628,7 +54666,7 @@ function resolveChannel(s) {
|
|
|
54628
54666
|
function appChannel() {
|
|
54629
54667
|
return resolveChannel({
|
|
54630
54668
|
isSea: isSea2(),
|
|
54631
|
-
define: true ? "0.126.
|
|
54669
|
+
define: true ? "0.126.5" : void 0,
|
|
54632
54670
|
// argv[1] is the entry the runtime actually loaded (…/dist/floless-server.cjs), which is what
|
|
54633
54671
|
// carries the npx cache prefix. Absent under the SEA exe, which never reaches the npx branch.
|
|
54634
54672
|
modulePath: process.argv[1]
|
|
@@ -57552,7 +57590,7 @@ function createProject(input) {
|
|
|
57552
57590
|
writeMeta(meta);
|
|
57553
57591
|
return meta;
|
|
57554
57592
|
}
|
|
57555
|
-
function renameProject(id, name) {
|
|
57593
|
+
async function renameProject(id, name, migrateSidecars) {
|
|
57556
57594
|
const meta = readMeta(safeProjectId(id));
|
|
57557
57595
|
if (!meta) throw new ProjectError(`unknown project: ${id}`);
|
|
57558
57596
|
if (typeof name !== "string" || !name.trim()) throw new ProjectError("project name required");
|
|
@@ -57565,11 +57603,17 @@ function renameProject(id, name) {
|
|
|
57565
57603
|
} catch {
|
|
57566
57604
|
throw new ProjectError("couldn\u2019t rename the project folder \u2014 it may be open or in use. Close the project and try again.");
|
|
57567
57605
|
}
|
|
57606
|
+
let rollbackSidecars = void 0;
|
|
57568
57607
|
try {
|
|
57608
|
+
rollbackSidecars = await migrateSidecars?.(id, newId);
|
|
57569
57609
|
const next = { ...meta, id: newId, name: nextName, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
57570
57610
|
writeMeta(next);
|
|
57571
57611
|
return next;
|
|
57572
57612
|
} catch (e) {
|
|
57613
|
+
try {
|
|
57614
|
+
await rollbackSidecars?.();
|
|
57615
|
+
} catch {
|
|
57616
|
+
}
|
|
57573
57617
|
try {
|
|
57574
57618
|
(0, import_node_fs18.renameSync)(to, from);
|
|
57575
57619
|
} catch {
|
|
@@ -59941,12 +59985,200 @@ function decodeSnapshots(inputs) {
|
|
|
59941
59985
|
});
|
|
59942
59986
|
}
|
|
59943
59987
|
|
|
59988
|
+
// run-relay.ts
|
|
59989
|
+
var import_node_os17 = require("node:os");
|
|
59990
|
+
var import_node_path25 = require("node:path");
|
|
59991
|
+
var RUN_POLICY = {
|
|
59992
|
+
/**
|
|
59993
|
+
* The first slice's one enabled type: small, mechanical, well-scoped.
|
|
59994
|
+
*
|
|
59995
|
+
* Three calls, and nothing else. Note what is NOT here: no `PUT /api/contract`, no `/approve`, no
|
|
59996
|
+
* project route — a `tweak` edits a node in a `.flo` and compiles it, and the approval gate stays
|
|
59997
|
+
* human. `POST /api/compile` is what replaces the skill's `aware app compile` shell-out, which is
|
|
59998
|
+
* the other half of the shell being denied.
|
|
59999
|
+
*/
|
|
60000
|
+
tweak: {
|
|
60001
|
+
runnable: true,
|
|
60002
|
+
calls: (l) => [
|
|
60003
|
+
{ method: "GET", path: "/api/requests", why: "read the authoritative spec for this request" },
|
|
60004
|
+
...isSafeAppId(l.appId) ? [{ method: "POST", path: "/api/compile", body: { id: l.appId }, why: "compile the workflow after editing its .flo" }] : [],
|
|
60005
|
+
{ method: "DELETE", path: `/api/requests/${l.requestId}`, why: "clear this request once applied" }
|
|
60006
|
+
],
|
|
60007
|
+
// The `.flo` lives in the app's own source directory, NOT in the nominated folder — which is
|
|
60008
|
+
// exactly why §D1 insists the nominated folder is an address rather than a sandbox. Without this
|
|
60009
|
+
// grant the agent can read its instruction and edit nothing.
|
|
60010
|
+
//
|
|
60011
|
+
// `.filter(Boolean)`, so an id `appSourceDir` refuses grants NOTHING rather than falling back to
|
|
60012
|
+
// something broader. A run whose app id is unusable should be refused before it starts (the route
|
|
60013
|
+
// does that), and if one ever reaches here it gets no filesystem capability at all.
|
|
60014
|
+
addDirs: (l) => l.appId ? [appSourceDir(l.appId)].filter((d) => d !== null) : []
|
|
60015
|
+
},
|
|
60016
|
+
// ── enabled by E1, but not built in this slice ──────────────────────────────
|
|
60017
|
+
// Each is mechanical and well-scoped enough to run headless; each needs its own call list worked
|
|
60018
|
+
// out from its skill and its own end-to-end proof, and the plan slices the first spawn to ONE type
|
|
60019
|
+
// on purpose. A reason, not a null, so the picker can say why the button is absent.
|
|
60020
|
+
"use-template": { runnable: false, why: "not yet available headless \u2014 run it from your terminal for now" },
|
|
60021
|
+
"ui-customize": { runnable: false, why: "not yet available headless \u2014 run it from your terminal for now" },
|
|
60022
|
+
rebake: { runnable: false, why: "not yet available headless \u2014 run it from your terminal for now" },
|
|
60023
|
+
"tweak-contract": { runnable: false, why: "not yet available headless \u2014 run it from your terminal for now" },
|
|
60024
|
+
// ── E1 says no, and these are the reasons ───────────────────────────────────
|
|
60025
|
+
"revision-read": {
|
|
60026
|
+
runnable: false,
|
|
60027
|
+
// The flagship type, and the judgment-heaviest: every arm of its instruction ends "STOP and tell
|
|
60028
|
+
// me to open Drawings → Steel Filter … do NOT read members until I explicitly come back". It is a
|
|
60029
|
+
// two-phase workflow whose first phase ends in a mandatory human checkpoint, so headless the best
|
|
60030
|
+
// outcome is "prepass runs, agent says go review, exits 0, request still pending" — a row that
|
|
60031
|
+
// lies. It waits until `needs-you` is a first-class, actionable row.
|
|
60032
|
+
why: "reading a drawing set stops at a review checkpoint \u2014 do this one in your terminal"
|
|
60033
|
+
},
|
|
60034
|
+
"knowledge-organize": {
|
|
60035
|
+
runnable: false,
|
|
60036
|
+
// Both take the server organize lock, and the plan's stated mitigation ("mark the request failed
|
|
60037
|
+
// so the lock is released") is a NO-OP: `patchRequest` writes a request file, while the lock is
|
|
60038
|
+
// released by `failOrganize` in the knowledge store. A hard-killed headless organize past
|
|
60039
|
+
// `/start` wedges the Organize button for ten minutes, on a row that renders no ✕.
|
|
60040
|
+
why: "organizing holds a lock a killed run can\u2019t release \u2014 do this one in your terminal"
|
|
60041
|
+
},
|
|
60042
|
+
"knowledge-adjust": { runnable: false, why: "organizing holds a lock a killed run can\u2019t release \u2014 do this one in your terminal" },
|
|
60043
|
+
guide: { runnable: false, why: "this one is a conversation \u2014 headless would talk to nobody" },
|
|
60044
|
+
"new-workflow": { runnable: false, why: "this one is a conversation \u2014 headless would talk to nobody" }
|
|
60045
|
+
};
|
|
60046
|
+
var SAFE_APP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
60047
|
+
var isSafeAppId = (id) => typeof id === "string" && SAFE_APP_ID.test(id);
|
|
60048
|
+
function appSourceDir(appId) {
|
|
60049
|
+
if (!isSafeAppId(appId)) return null;
|
|
60050
|
+
const root5 = process.env.AWARE_HOME || (0, import_node_path25.join)((0, import_node_os17.homedir)(), ".aware");
|
|
60051
|
+
return (0, import_node_path25.join)(root5, "apps", appId);
|
|
60052
|
+
}
|
|
60053
|
+
function policyFor(type) {
|
|
60054
|
+
if (!isRequestType(type)) {
|
|
60055
|
+
return { runnable: false, why: "floless doesn\u2019t recognise this request \u2014 it may have been made by a newer version" };
|
|
60056
|
+
}
|
|
60057
|
+
return RUN_POLICY[type];
|
|
60058
|
+
}
|
|
60059
|
+
var TOOL_NAME = "floless_api";
|
|
60060
|
+
function mcpConfigFor(token2, origin) {
|
|
60061
|
+
return { mcpServers: { floless: { type: "http", url: `${origin}/api/mcp/run/${token2}` } } };
|
|
60062
|
+
}
|
|
60063
|
+
function jsonRpc(id, result) {
|
|
60064
|
+
return { jsonrpc: "2.0", id, result };
|
|
60065
|
+
}
|
|
60066
|
+
function toolRefusal(text3) {
|
|
60067
|
+
return { content: [{ type: "text", text: text3 }], isError: true };
|
|
60068
|
+
}
|
|
60069
|
+
function sameBody(want, got) {
|
|
60070
|
+
if (want === void 0 && got !== null && typeof got === "object" && Object.keys(got).length === 0) return true;
|
|
60071
|
+
return JSON.stringify(sortKeys(want)) === JSON.stringify(sortKeys(got ?? void 0));
|
|
60072
|
+
}
|
|
60073
|
+
function sortKeys(v) {
|
|
60074
|
+
if (Array.isArray(v)) return v.map(sortKeys);
|
|
60075
|
+
if (v && typeof v === "object") {
|
|
60076
|
+
return Object.fromEntries(Object.keys(v).sort().map((k) => [k, sortKeys(v[k])]));
|
|
60077
|
+
}
|
|
60078
|
+
return v;
|
|
60079
|
+
}
|
|
60080
|
+
function normalizePath(raw, origin) {
|
|
60081
|
+
if (typeof raw !== "string" || !raw) return null;
|
|
60082
|
+
let u;
|
|
60083
|
+
try {
|
|
60084
|
+
u = new URL(raw, origin);
|
|
60085
|
+
} catch {
|
|
60086
|
+
return null;
|
|
60087
|
+
}
|
|
60088
|
+
if (new URL(origin).origin !== u.origin) return null;
|
|
60089
|
+
const p = u.pathname.length > 1 && u.pathname.endsWith("/") ? u.pathname.slice(0, -1) : u.pathname;
|
|
60090
|
+
return `${p}${u.search}`;
|
|
60091
|
+
}
|
|
60092
|
+
function registerRunRelay(app, deps, origin) {
|
|
60093
|
+
app.post(
|
|
60094
|
+
"/api/mcp/run/:token",
|
|
60095
|
+
async (req, reply) => {
|
|
60096
|
+
const msg = req.body ?? {};
|
|
60097
|
+
if (msg.id === void 0) return reply.status(202).send();
|
|
60098
|
+
const lease = deps.leaseForToken(req.params.token);
|
|
60099
|
+
if (!lease) {
|
|
60100
|
+
return reply.status(200).send({
|
|
60101
|
+
jsonrpc: "2.0",
|
|
60102
|
+
id: msg.id,
|
|
60103
|
+
error: { code: -32001, message: "this run is no longer active" }
|
|
60104
|
+
});
|
|
60105
|
+
}
|
|
60106
|
+
const policy = policyFor(lease.requestType);
|
|
60107
|
+
const allowed = policy.runnable ? policy.calls(lease) : [];
|
|
60108
|
+
if (msg.method === "initialize") {
|
|
60109
|
+
const requested = msg.params?.protocolVersion;
|
|
60110
|
+
return reply.send(jsonRpc(msg.id, {
|
|
60111
|
+
protocolVersion: requested ?? "2025-06-18",
|
|
60112
|
+
capabilities: { tools: {} },
|
|
60113
|
+
serverInfo: { name: "floless", version: "1" }
|
|
60114
|
+
}));
|
|
60115
|
+
}
|
|
60116
|
+
if (msg.method === "tools/list") {
|
|
60117
|
+
return reply.send(jsonRpc(msg.id, {
|
|
60118
|
+
tools: [{
|
|
60119
|
+
name: TOOL_NAME,
|
|
60120
|
+
description: "Call the floless.app API for THIS request. This is your only channel to floless \u2014 there is no shell in this session. Exactly these calls are permitted:\n" + allowed.map((c) => ` ${c.method} ${c.path}${c.body ? ` body ${JSON.stringify(c.body)}` : ""} \u2014 ${c.why}`).join("\n") + '\nAnything else is refused. If you need something not listed, stop and finish with outcome "needs-you" explaining what you need.',
|
|
60121
|
+
inputSchema: {
|
|
60122
|
+
type: "object",
|
|
60123
|
+
properties: {
|
|
60124
|
+
method: { type: "string", enum: ["GET", "POST", "PUT", "DELETE"] },
|
|
60125
|
+
path: { type: "string" },
|
|
60126
|
+
body: { type: "object" }
|
|
60127
|
+
},
|
|
60128
|
+
required: ["method", "path"]
|
|
60129
|
+
}
|
|
60130
|
+
}]
|
|
60131
|
+
}));
|
|
60132
|
+
}
|
|
60133
|
+
if (msg.method !== "tools/call") {
|
|
60134
|
+
return reply.send({ jsonrpc: "2.0", id: msg.id, error: { code: -32601, message: "method not found" } });
|
|
60135
|
+
}
|
|
60136
|
+
const params = msg.params;
|
|
60137
|
+
if (params?.name !== TOOL_NAME) {
|
|
60138
|
+
return reply.send(jsonRpc(msg.id, toolRefusal(`no such tool: ${String(params?.name)}`)));
|
|
60139
|
+
}
|
|
60140
|
+
if (!policy.runnable) {
|
|
60141
|
+
return reply.send(jsonRpc(msg.id, toolRefusal(`refused: ${policy.why}`)));
|
|
60142
|
+
}
|
|
60143
|
+
const argMethod = String(params.arguments?.["method"] ?? "").toUpperCase();
|
|
60144
|
+
const argPath = normalizePath(params.arguments?.["path"], origin);
|
|
60145
|
+
const argBody = params.arguments?.["body"];
|
|
60146
|
+
const match = argPath === null ? void 0 : allowed.find((c) => c.method === argMethod && c.path === argPath && sameBody(c.body, argBody));
|
|
60147
|
+
if (!match) {
|
|
60148
|
+
return reply.send(jsonRpc(msg.id, toolRefusal(
|
|
60149
|
+
`refused: ${argMethod} ${String(params.arguments?.["path"])} is not permitted for this run.
|
|
60150
|
+
Permitted:
|
|
60151
|
+
${allowed.map((c) => ` ${c.method} ${c.path}${c.body ? ` body ${JSON.stringify(c.body)}` : ""}`).join("\n")}`
|
|
60152
|
+
)));
|
|
60153
|
+
}
|
|
60154
|
+
const res = await deps.dispatch({ method: match.method, path: match.path, ...match.body !== void 0 ? { body: match.body } : {} });
|
|
60155
|
+
if (match.method === "DELETE" && match.path === `/api/requests/${lease.requestId}` && res.status < 300) {
|
|
60156
|
+
deps.markResolved(lease);
|
|
60157
|
+
}
|
|
60158
|
+
const body = match.path === "/api/requests" ? onlyThisRequest(res.body, lease.requestId) : res.body;
|
|
60159
|
+
return reply.send(jsonRpc(msg.id, {
|
|
60160
|
+
content: [{ type: "text", text: JSON.stringify({ status: res.status, body }) }],
|
|
60161
|
+
...res.status >= 400 ? { isError: true } : {}
|
|
60162
|
+
}));
|
|
60163
|
+
}
|
|
60164
|
+
);
|
|
60165
|
+
}
|
|
60166
|
+
function onlyThisRequest(body, requestId) {
|
|
60167
|
+
const b = body;
|
|
60168
|
+
if (!b || !Array.isArray(b.requests)) return body;
|
|
60169
|
+
return { ...b, requests: b.requests.filter((r) => r?.id === requestId) };
|
|
60170
|
+
}
|
|
60171
|
+
|
|
59944
60172
|
// request-instruction.ts
|
|
59945
60173
|
function kbClause(project, appId) {
|
|
59946
60174
|
if (!project) return "";
|
|
59947
60175
|
const guard = appId ? `&app=${appId}` : "";
|
|
59948
60176
|
return `
|
|
59949
|
-
First consult this project's knowledge base per your floless-app-knowledge skill: GET /api/workspace-projects/${project}/knowledge?q=<subject>${guard} returns ranked summaries of the firm's own standards, RFIs and spec notes (<subject> is what you are about to change, url-encoded; the q is required past a small knowledge base \u2014 an unqueried feed deliberately returns no pages); read a decisive one in full with GET /api/projects/${project}/knowledge/page/<slug
|
|
60177
|
+
First consult this project's knowledge base per your floless-app-knowledge skill: GET /api/workspace-projects/${project}/knowledge?q=<subject>${guard} returns ranked summaries of the firm's own standards, RFIs and spec notes (<subject> is what you are about to change, url-encoded; the q is required past a small knowledge base \u2014 an unqueried feed deliberately returns no pages); read a decisive one in full with GET /api/projects/${project}/knowledge/page/<slug>?generation=<generationId>, using the same generation.generationId the feed returned. Let those pages steer the change, and cite the slug you relied on so the user can trace it. If nothing relevant matches, say so rather than inventing a standard.` + pinClause(project, appId);
|
|
60178
|
+
}
|
|
60179
|
+
function pinClause(project, appId) {
|
|
60180
|
+
if (!appId) return "";
|
|
60181
|
+
return ` Once you have applied the change, record what informed it: PUT /api/kb-pin/${appId} with { "projectId": "${project}", "generationId": "<the generation.generationId the feed returned>", "pages": [{ "slug": "\u2026", "title": "\u2026" }] } \u2014 just the pages you actually relied on. Send the generation id you READ, even if the knowledge base has been re-organized since; it is a record of what this work was built from, not a claim about what is current, and the app shows the user when the two have diverged. If you consulted the knowledge base and nothing relevant matched, there is nothing to record \u2014 skip it rather than pinning an empty list.`;
|
|
59950
60182
|
}
|
|
59951
60183
|
function instructionFor(req) {
|
|
59952
60184
|
if (req.type === "use-template" && req.template) {
|
|
@@ -60042,10 +60274,17 @@ var selfOrigin = () => `http://127.0.0.1:${Number(process.env.PORT ?? 4317)}`;
|
|
|
60042
60274
|
function withPrompt(r, base = selfOrigin()) {
|
|
60043
60275
|
try {
|
|
60044
60276
|
const prompt = instructionFor(r);
|
|
60045
|
-
|
|
60277
|
+
const policy = policyFor(r.type);
|
|
60278
|
+
return {
|
|
60279
|
+
...r,
|
|
60280
|
+
prompt,
|
|
60281
|
+
marker: markerFor(r, base, prompt),
|
|
60282
|
+
canRun: policy.runnable,
|
|
60283
|
+
runWhy: policy.runnable ? null : policy.why
|
|
60284
|
+
};
|
|
60046
60285
|
} catch (err2) {
|
|
60047
60286
|
console.error(`[request-instruction] could not compose request ${r.id} (${r.type}):`, err2);
|
|
60048
|
-
return { ...r, prompt: r.instruction ? String(r.instruction).trim() : "", marker: "" };
|
|
60287
|
+
return { ...r, prompt: r.instruction ? String(r.instruction).trim() : "", marker: "", canRun: false, runWhy: null };
|
|
60049
60288
|
}
|
|
60050
60289
|
}
|
|
60051
60290
|
var NO_ENRICHMENTS = { appTemplateId: void 0, contractType: void 0, projectName: void 0 };
|
|
@@ -60061,7 +60300,7 @@ function enrichedView(r, enrich, base = selfOrigin()) {
|
|
|
60061
60300
|
|
|
60062
60301
|
// connection-import.ts
|
|
60063
60302
|
var import_node_fs27 = require("node:fs");
|
|
60064
|
-
var
|
|
60303
|
+
var import_node_path26 = require("node:path");
|
|
60065
60304
|
|
|
60066
60305
|
// ifc-frame.ts
|
|
60067
60306
|
var FILE_Z_UP = "z-up";
|
|
@@ -60094,7 +60333,7 @@ async function ensureConnectionReader() {
|
|
|
60094
60333
|
function writeReaderApp(companionId, command, ifcPath, id) {
|
|
60095
60334
|
const dir = appPath(companionId);
|
|
60096
60335
|
(0, import_node_fs27.mkdirSync)(dir, { recursive: true });
|
|
60097
|
-
const flo = (0,
|
|
60336
|
+
const flo = (0, import_node_path26.join)(dir, `${companionId}.flo`);
|
|
60098
60337
|
const lines = [
|
|
60099
60338
|
`app: ${companionId}`,
|
|
60100
60339
|
"version: 0.1.0",
|
|
@@ -60321,8 +60560,8 @@ async function extractConnection(companionId, ifcPath, id, opts = {}) {
|
|
|
60321
60560
|
|
|
60322
60561
|
// contract-store.ts
|
|
60323
60562
|
var import_node_fs28 = require("node:fs");
|
|
60324
|
-
var
|
|
60325
|
-
var
|
|
60563
|
+
var import_node_path27 = require("node:path");
|
|
60564
|
+
var import_node_os18 = require("node:os");
|
|
60326
60565
|
var ContractError = class extends Error {
|
|
60327
60566
|
/** Carries the acceptance policy's reason forward. "This store must be migrated first" and "your
|
|
60328
60567
|
* contract is corrupt" are different actionable states, and a client that cannot tell them apart
|
|
@@ -60334,8 +60573,8 @@ var ContractError = class extends Error {
|
|
|
60334
60573
|
this.code = code;
|
|
60335
60574
|
}
|
|
60336
60575
|
};
|
|
60337
|
-
var ROOT3 = process.env.FLOLESS_HOME ?? (0,
|
|
60338
|
-
var DIR = (0,
|
|
60576
|
+
var ROOT3 = process.env.FLOLESS_HOME ?? (0, import_node_path27.join)((0, import_node_os18.homedir)(), ".floless");
|
|
60577
|
+
var DIR = (0, import_node_path27.join)(ROOT3, "contracts");
|
|
60339
60578
|
function safeId(appId) {
|
|
60340
60579
|
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(appId)) throw new ContractError(`invalid appId: ${appId}`);
|
|
60341
60580
|
return appId;
|
|
@@ -60345,14 +60584,14 @@ function safeProjectSeg(projectId) {
|
|
|
60345
60584
|
return projectId;
|
|
60346
60585
|
}
|
|
60347
60586
|
function contractPath(appId, projectId) {
|
|
60348
|
-
if (projectId) return (0,
|
|
60349
|
-
return (0,
|
|
60587
|
+
if (projectId) return (0, import_node_path27.join)(ROOT3, "projects", safeProjectSeg(projectId), "contract.json");
|
|
60588
|
+
return (0, import_node_path27.join)(DIR, `${safeId(appId)}.json`);
|
|
60350
60589
|
}
|
|
60351
60590
|
function moveAppContractBytes(fromAppId, toAppId) {
|
|
60352
60591
|
const from = contractPath(fromAppId);
|
|
60353
60592
|
const to = contractPath(toAppId);
|
|
60354
60593
|
if (from === to || !(0, import_node_fs28.existsSync)(from)) return false;
|
|
60355
|
-
(0, import_node_fs28.mkdirSync)((0,
|
|
60594
|
+
(0, import_node_fs28.mkdirSync)((0, import_node_path27.dirname)(to), { recursive: true });
|
|
60356
60595
|
(0, import_node_fs28.renameSync)(from, to);
|
|
60357
60596
|
return true;
|
|
60358
60597
|
}
|
|
@@ -60360,7 +60599,7 @@ function copyAppContractBytes(fromAppId, toAppId) {
|
|
|
60360
60599
|
const from = contractPath(fromAppId);
|
|
60361
60600
|
const to = contractPath(toAppId);
|
|
60362
60601
|
if (from === to || !(0, import_node_fs28.existsSync)(from)) return false;
|
|
60363
|
-
(0, import_node_fs28.mkdirSync)((0,
|
|
60602
|
+
(0, import_node_fs28.mkdirSync)((0, import_node_path27.dirname)(to), { recursive: true });
|
|
60364
60603
|
(0, import_node_fs28.copyFileSync)(from, to);
|
|
60365
60604
|
return true;
|
|
60366
60605
|
}
|
|
@@ -60393,7 +60632,7 @@ function writeContract(appId, doc, projectId, privileged) {
|
|
|
60393
60632
|
throw e;
|
|
60394
60633
|
}
|
|
60395
60634
|
if (projectId) {
|
|
60396
|
-
if (!(0, import_node_fs28.existsSync)((0,
|
|
60635
|
+
if (!(0, import_node_fs28.existsSync)((0, import_node_path27.dirname)(p))) throw new ContractError(`unknown project: ${projectId}`);
|
|
60397
60636
|
} else if (!(0, import_node_fs28.existsSync)(DIR)) {
|
|
60398
60637
|
(0, import_node_fs28.mkdirSync)(DIR, { recursive: true });
|
|
60399
60638
|
}
|
|
@@ -60437,14 +60676,14 @@ function readContractForApp(appId, readAppFn = readApp) {
|
|
|
60437
60676
|
var import_node_crypto15 = require("node:crypto");
|
|
60438
60677
|
var import_node_fs29 = require("node:fs");
|
|
60439
60678
|
var import_promises3 = require("node:fs/promises");
|
|
60440
|
-
var
|
|
60679
|
+
var import_node_path28 = require("node:path");
|
|
60441
60680
|
var BLOB_MIN = 8192;
|
|
60442
60681
|
var BLOB_KEY = "__blobRef__";
|
|
60443
60682
|
var HASH_RE = /^[0-9a-f]{64}$/;
|
|
60444
60683
|
var LOG_CLAIM_TOKEN = (0, import_node_crypto15.randomUUID)();
|
|
60445
|
-
var versionsDir = (id) => (0,
|
|
60446
|
-
var objectsDir = (id) => (0,
|
|
60447
|
-
var logPath = (id) => (0,
|
|
60684
|
+
var versionsDir = (id) => (0, import_node_path28.join)(projectDir(id), "versions");
|
|
60685
|
+
var objectsDir = (id) => (0, import_node_path28.join)(projectDir(id), "objects");
|
|
60686
|
+
var logPath = (id) => (0, import_node_path28.join)(versionsDir(id), "log.json");
|
|
60448
60687
|
function writeAtomic(path, text3) {
|
|
60449
60688
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
60450
60689
|
(0, import_node_fs29.writeFileSync)(tmp, text3);
|
|
@@ -60520,7 +60759,7 @@ function versionBlobHash(node) {
|
|
|
60520
60759
|
function readVersionBlob(id, hash2) {
|
|
60521
60760
|
if (!HASH_RE.test(hash2)) return null;
|
|
60522
60761
|
try {
|
|
60523
|
-
const value = (0, import_node_fs29.readFileSync)((0,
|
|
60762
|
+
const value = (0, import_node_fs29.readFileSync)((0, import_node_path28.join)(objectsDir(id), hash2), "utf8");
|
|
60524
60763
|
return (0, import_node_crypto15.createHash)("sha256").update(value).digest("hex") === hash2 ? value : null;
|
|
60525
60764
|
} catch {
|
|
60526
60765
|
return null;
|
|
@@ -60529,7 +60768,7 @@ function readVersionBlob(id, hash2) {
|
|
|
60529
60768
|
async function readVersionBlobAsync(id, hash2) {
|
|
60530
60769
|
if (!HASH_RE.test(hash2)) return null;
|
|
60531
60770
|
try {
|
|
60532
|
-
const value = await (0, import_promises3.readFile)((0,
|
|
60771
|
+
const value = await (0, import_promises3.readFile)((0, import_node_path28.join)(objectsDir(id), hash2), "utf8");
|
|
60533
60772
|
return (0, import_node_crypto15.createHash)("sha256").update(value).digest("hex") === hash2 ? value : null;
|
|
60534
60773
|
} catch {
|
|
60535
60774
|
return null;
|
|
@@ -60582,26 +60821,26 @@ function claimVersionNumber(id, from) {
|
|
|
60582
60821
|
const dir = versionsDir(id);
|
|
60583
60822
|
const CAP = 1e5;
|
|
60584
60823
|
for (let n = Math.max(1, from); n < from + CAP; n++) {
|
|
60585
|
-
if ((0, import_node_fs29.existsSync)((0,
|
|
60824
|
+
if ((0, import_node_fs29.existsSync)((0, import_node_path28.join)(dir, `${n}.json`))) continue;
|
|
60586
60825
|
try {
|
|
60587
|
-
(0, import_node_fs29.mkdirSync)((0,
|
|
60826
|
+
(0, import_node_fs29.mkdirSync)((0, import_node_path28.join)(dir, `.claim-${n}`));
|
|
60588
60827
|
} catch (e) {
|
|
60589
60828
|
if (e.code === "EEXIST") continue;
|
|
60590
60829
|
throw e;
|
|
60591
60830
|
}
|
|
60592
|
-
if (!(0, import_node_fs29.existsSync)((0,
|
|
60831
|
+
if (!(0, import_node_fs29.existsSync)((0, import_node_path28.join)(dir, `${n}.json`))) return n;
|
|
60593
60832
|
releaseVersionClaim(id, n);
|
|
60594
60833
|
}
|
|
60595
60834
|
throw new Error(`project ${id}: no free version number after ${CAP} attempts from ${from}`);
|
|
60596
60835
|
}
|
|
60597
60836
|
function releaseVersionClaim(id, n) {
|
|
60598
60837
|
try {
|
|
60599
|
-
(0, import_node_fs29.rmSync)((0,
|
|
60838
|
+
(0, import_node_fs29.rmSync)((0, import_node_path28.join)(versionsDir(id), `.claim-${n}`), { recursive: true, force: true });
|
|
60600
60839
|
} catch {
|
|
60601
60840
|
}
|
|
60602
60841
|
}
|
|
60603
60842
|
function withLogClaim(id, fn) {
|
|
60604
|
-
const claim = (0,
|
|
60843
|
+
const claim = (0, import_node_path28.join)(versionsDir(id), ".claim-log");
|
|
60605
60844
|
const me = `${process.pid}:${LOG_CLAIM_TOKEN}`;
|
|
60606
60845
|
const STALE_MS3 = 3e4;
|
|
60607
60846
|
const deadline = Date.now() + 250;
|
|
@@ -60639,7 +60878,7 @@ function createVersion(id, contract, meta) {
|
|
|
60639
60878
|
const blobs = /* @__PURE__ */ new Map();
|
|
60640
60879
|
const skeleton = dehydrate(contract, blobs);
|
|
60641
60880
|
for (const [hash2, text3] of blobs) {
|
|
60642
|
-
const p = (0,
|
|
60881
|
+
const p = (0, import_node_path28.join)(objectsDir(id), hash2);
|
|
60643
60882
|
if (!(0, import_node_fs29.existsSync)(p)) writeAtomic(p, text3);
|
|
60644
60883
|
}
|
|
60645
60884
|
const log2 = loadLog(id);
|
|
@@ -60658,7 +60897,7 @@ function createVersion(id, contract, meta) {
|
|
|
60658
60897
|
...meta.approval ? { approval: meta.approval } : {},
|
|
60659
60898
|
...meta.discard ? { discard: meta.discard } : {}
|
|
60660
60899
|
};
|
|
60661
|
-
const snapshotPath = (0,
|
|
60900
|
+
const snapshotPath = (0, import_node_path28.join)(versionsDir(id), `${n}.json`);
|
|
60662
60901
|
try {
|
|
60663
60902
|
writeAtomic(snapshotPath, JSON.stringify({ meta: row, contract: skeleton }, null, 2));
|
|
60664
60903
|
withLogClaim(id, () => {
|
|
@@ -60685,7 +60924,7 @@ function listVersions(id) {
|
|
|
60685
60924
|
}
|
|
60686
60925
|
function readVersion(id, n) {
|
|
60687
60926
|
try {
|
|
60688
|
-
const snap = JSON.parse((0, import_node_fs29.readFileSync)((0,
|
|
60927
|
+
const snap = JSON.parse((0, import_node_fs29.readFileSync)((0, import_node_path28.join)(versionsDir(id), `${n}.json`), "utf8"));
|
|
60689
60928
|
return rehydrate(snap.contract, id);
|
|
60690
60929
|
} catch {
|
|
60691
60930
|
return null;
|
|
@@ -60693,7 +60932,7 @@ function readVersion(id, n) {
|
|
|
60693
60932
|
}
|
|
60694
60933
|
async function readVersionAsync(id, n) {
|
|
60695
60934
|
try {
|
|
60696
|
-
const snap = JSON.parse(await (0, import_promises3.readFile)((0,
|
|
60935
|
+
const snap = JSON.parse(await (0, import_promises3.readFile)((0, import_node_path28.join)(versionsDir(id), `${n}.json`), "utf8"));
|
|
60697
60936
|
const refs = /* @__PURE__ */ new Set();
|
|
60698
60937
|
collectBlobRefs(snap.contract, refs);
|
|
60699
60938
|
if (refs.size === 0) return snap.contract;
|
|
@@ -60710,7 +60949,7 @@ async function readVersionAsync(id, n) {
|
|
|
60710
60949
|
}
|
|
60711
60950
|
function readVersionSkeleton(id, n) {
|
|
60712
60951
|
try {
|
|
60713
|
-
const snap = JSON.parse((0, import_node_fs29.readFileSync)((0,
|
|
60952
|
+
const snap = JSON.parse((0, import_node_fs29.readFileSync)((0, import_node_path28.join)(versionsDir(id), `${n}.json`), "utf8"));
|
|
60714
60953
|
return snap.contract;
|
|
60715
60954
|
} catch {
|
|
60716
60955
|
return null;
|
|
@@ -60718,7 +60957,7 @@ function readVersionSkeleton(id, n) {
|
|
|
60718
60957
|
}
|
|
60719
60958
|
async function readVersionSkeletonAsync(id, n) {
|
|
60720
60959
|
try {
|
|
60721
|
-
const snap = JSON.parse(await (0, import_promises3.readFile)((0,
|
|
60960
|
+
const snap = JSON.parse(await (0, import_promises3.readFile)((0, import_node_path28.join)(versionsDir(id), `${n}.json`), "utf8"));
|
|
60722
60961
|
return snap.contract;
|
|
60723
60962
|
} catch {
|
|
60724
60963
|
return null;
|
|
@@ -60727,9 +60966,9 @@ async function readVersionSkeletonAsync(id, n) {
|
|
|
60727
60966
|
|
|
60728
60967
|
// activation-store.ts
|
|
60729
60968
|
var import_node_fs30 = require("node:fs");
|
|
60730
|
-
var
|
|
60969
|
+
var import_node_path29 = require("node:path");
|
|
60731
60970
|
var FILENAME = ".floless-activation-record.json";
|
|
60732
|
-
var recordPath = (projectId) => (0,
|
|
60971
|
+
var recordPath = (projectId) => (0, import_node_path29.join)(projectDir(projectId), FILENAME);
|
|
60733
60972
|
function isStoredActivation(v) {
|
|
60734
60973
|
if (!v || typeof v !== "object") return false;
|
|
60735
60974
|
const r = v;
|
|
@@ -60792,7 +61031,7 @@ function incarnationOf(projectId) {
|
|
|
60792
61031
|
// contract-transaction.ts
|
|
60793
61032
|
var import_node_fs31 = require("node:fs");
|
|
60794
61033
|
var import_node_crypto17 = require("node:crypto");
|
|
60795
|
-
var
|
|
61034
|
+
var import_node_path30 = require("node:path");
|
|
60796
61035
|
|
|
60797
61036
|
// project-contract-hash.ts
|
|
60798
61037
|
function contractHash(contract) {
|
|
@@ -62796,8 +63035,8 @@ var RecoveryPendingError = class extends Error {
|
|
|
62796
63035
|
};
|
|
62797
63036
|
var PHASES2 = ["000-begin", "001-before", "002-staged", "003-commit", "004-done"];
|
|
62798
63037
|
var TXN_PREFIX = ".floless-txn-";
|
|
62799
|
-
var txnDir = (projectId, txnId) => (0,
|
|
62800
|
-
var phasePath = (dir, phase) => (0,
|
|
63038
|
+
var txnDir = (projectId, txnId) => (0, import_node_path30.join)(projectDir(projectId), `${TXN_PREFIX}${txnId}`);
|
|
63039
|
+
var phasePath = (dir, phase) => (0, import_node_path30.join)(dir, `${phase}.json`);
|
|
62801
63040
|
function writePhase2(dir, phase, body) {
|
|
62802
63041
|
(0, import_node_fs31.writeFileSync)(phasePath(dir, phase), `${JSON.stringify(body, null, 2)}
|
|
62803
63042
|
`, { flag: "wx" });
|
|
@@ -62821,7 +63060,7 @@ function txnDirs(projectId) {
|
|
|
62821
63060
|
} catch {
|
|
62822
63061
|
return [];
|
|
62823
63062
|
}
|
|
62824
|
-
return entries2.filter((e) => e.startsWith(TXN_PREFIX)).sort().map((e) => (0,
|
|
63063
|
+
return entries2.filter((e) => e.startsWith(TXN_PREFIX)).sort().map((e) => (0, import_node_path30.join)(projectDir(projectId), e));
|
|
62825
63064
|
}
|
|
62826
63065
|
function assertNoPendingRecovery(projectId) {
|
|
62827
63066
|
for (const dir of txnDirs(projectId)) {
|
|
@@ -63193,7 +63432,7 @@ async function runRollbackToV1(opts) {
|
|
|
63193
63432
|
}
|
|
63194
63433
|
function ledgerHead(projectId) {
|
|
63195
63434
|
try {
|
|
63196
|
-
const log2 = JSON.parse((0, import_node_fs31.readFileSync)((0,
|
|
63435
|
+
const log2 = JSON.parse((0, import_node_fs31.readFileSync)((0, import_node_path30.join)(projectDir(projectId), "versions", "log.json"), "utf8"));
|
|
63197
63436
|
return log2.versions.at(-1)?.n ?? 0;
|
|
63198
63437
|
} catch {
|
|
63199
63438
|
return 0;
|
|
@@ -63477,7 +63716,7 @@ function clientCount() {
|
|
|
63477
63716
|
// knowledge-store.ts
|
|
63478
63717
|
var import_node_crypto18 = require("node:crypto");
|
|
63479
63718
|
var import_node_fs33 = require("node:fs");
|
|
63480
|
-
var
|
|
63719
|
+
var import_node_path31 = require("node:path");
|
|
63481
63720
|
var import_yaml6 = __toESM(require_dist6(), 1);
|
|
63482
63721
|
var KnowledgeError = class extends Error {
|
|
63483
63722
|
code;
|
|
@@ -63487,8 +63726,8 @@ var KnowledgeError = class extends Error {
|
|
|
63487
63726
|
}
|
|
63488
63727
|
};
|
|
63489
63728
|
var EMPTY_MANIFEST = { revision: 0, currentGeneration: null, sources: [] };
|
|
63490
|
-
var manifestPath = (id) => (0,
|
|
63491
|
-
var blobsDir = (id) => (0,
|
|
63729
|
+
var manifestPath = (id) => (0, import_node_path31.join)(projectKnowledgeDir(id), "manifest.json");
|
|
63730
|
+
var blobsDir = (id) => (0, import_node_path31.join)(projectKnowledgeDir(id), "blobs");
|
|
63492
63731
|
var BLOB_SHA256_RE = /^[0-9a-f]{64}$/;
|
|
63493
63732
|
function isSourceRow(row) {
|
|
63494
63733
|
if (!row || typeof row !== "object") return false;
|
|
@@ -63525,7 +63764,7 @@ function writeManifest(id, manifest) {
|
|
|
63525
63764
|
const dir = projectKnowledgeDir(id);
|
|
63526
63765
|
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
63527
63766
|
const dest = manifestPath(id);
|
|
63528
|
-
const tmp = (0,
|
|
63767
|
+
const tmp = (0, import_node_path31.join)(dir, `.manifest.json.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`);
|
|
63529
63768
|
(0, import_node_fs33.writeFileSync)(tmp, JSON.stringify(manifest, null, 2));
|
|
63530
63769
|
(0, import_node_fs33.renameSync)(tmp, dest);
|
|
63531
63770
|
}
|
|
@@ -63546,9 +63785,9 @@ function blobPathFor(id, blobSha256) {
|
|
|
63546
63785
|
if (typeof blobSha256 !== "string" || !BLOB_SHA256_RE.test(blobSha256)) {
|
|
63547
63786
|
throw new KnowledgeError(`invalid blob address: ${blobSha256}`);
|
|
63548
63787
|
}
|
|
63549
|
-
const full = (0,
|
|
63550
|
-
const root5 = (0,
|
|
63551
|
-
if (full !== (0,
|
|
63788
|
+
const full = (0, import_node_path31.resolve)((0, import_node_path31.join)(dir, blobSha256));
|
|
63789
|
+
const root5 = (0, import_node_path31.resolve)(dir);
|
|
63790
|
+
if (full !== (0, import_node_path31.join)(root5, blobSha256) || !full.startsWith(root5 + import_node_path31.sep)) {
|
|
63552
63791
|
throw new KnowledgeError(`blob path escapes the blobs directory: ${blobSha256}`);
|
|
63553
63792
|
}
|
|
63554
63793
|
return full;
|
|
@@ -63659,12 +63898,12 @@ function removeSource(id, sourceId) {
|
|
|
63659
63898
|
}
|
|
63660
63899
|
}
|
|
63661
63900
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
63662
|
-
var lockPath = (id) => (0,
|
|
63901
|
+
var lockPath = (id) => (0, import_node_path31.join)(projectKnowledgeDir(id), "lock.json");
|
|
63663
63902
|
function writeLockFile(id, lock) {
|
|
63664
63903
|
const dir = projectKnowledgeDir(id);
|
|
63665
63904
|
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
63666
63905
|
const dest = lockPath(id);
|
|
63667
|
-
const tmp = (0,
|
|
63906
|
+
const tmp = (0, import_node_path31.join)(dir, `.lock.json.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`);
|
|
63668
63907
|
(0, import_node_fs33.writeFileSync)(tmp, JSON.stringify(lock, null, 2));
|
|
63669
63908
|
(0, import_node_fs33.renameSync)(tmp, dest);
|
|
63670
63909
|
}
|
|
@@ -63716,11 +63955,14 @@ function releaseLock(id, requestId) {
|
|
|
63716
63955
|
}
|
|
63717
63956
|
var GENERATION_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
63718
63957
|
var GEN_KEEP = 3;
|
|
63719
|
-
var vaultDir = (id) => (0,
|
|
63720
|
-
var generationsDir = (id) => (0,
|
|
63721
|
-
var currentGenerationPath = (id) => (0,
|
|
63958
|
+
var vaultDir = (id) => (0, import_node_path31.join)(projectKnowledgeDir(id), "vault");
|
|
63959
|
+
var generationsDir = (id) => (0, import_node_path31.join)(vaultDir(id), "generations");
|
|
63960
|
+
var currentGenerationPath = (id) => (0, import_node_path31.join)(vaultDir(id), "current-generation.json");
|
|
63961
|
+
function isGenerationId(value) {
|
|
63962
|
+
return typeof value === "string" && GENERATION_ID_RE.test(value);
|
|
63963
|
+
}
|
|
63722
63964
|
function assertGenerationId(generationId) {
|
|
63723
|
-
if (
|
|
63965
|
+
if (!isGenerationId(generationId)) {
|
|
63724
63966
|
throw new KnowledgeError("invalid generation id");
|
|
63725
63967
|
}
|
|
63726
63968
|
}
|
|
@@ -63729,7 +63971,7 @@ function mintGenerationId() {
|
|
|
63729
63971
|
}
|
|
63730
63972
|
function generationWikiDir(id, generationId) {
|
|
63731
63973
|
assertGenerationId(generationId);
|
|
63732
|
-
return (0,
|
|
63974
|
+
return (0, import_node_path31.join)(generationsDir(id), generationId, "wiki");
|
|
63733
63975
|
}
|
|
63734
63976
|
function publishGeneration(id, generationId) {
|
|
63735
63977
|
assertGenerationId(generationId);
|
|
@@ -63738,7 +63980,7 @@ function publishGeneration(id, generationId) {
|
|
|
63738
63980
|
const dir = vaultDir(id);
|
|
63739
63981
|
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
63740
63982
|
const dest = currentGenerationPath(id);
|
|
63741
|
-
const tmp = (0,
|
|
63983
|
+
const tmp = (0, import_node_path31.join)(dir, `.current-generation.json.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`);
|
|
63742
63984
|
(0, import_node_fs33.writeFileSync)(tmp, JSON.stringify(pointer, null, 2));
|
|
63743
63985
|
(0, import_node_fs33.renameSync)(tmp, dest);
|
|
63744
63986
|
const manifest = readManifest(id);
|
|
@@ -63769,6 +64011,9 @@ function currentGenerationWikiDir(id) {
|
|
|
63769
64011
|
return (0, import_node_fs33.existsSync)(dir) ? dir : null;
|
|
63770
64012
|
}
|
|
63771
64013
|
var WIKI_SLUG_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
64014
|
+
function isWikiSlug(value) {
|
|
64015
|
+
return typeof value === "string" && WIKI_SLUG_RE.test(value);
|
|
64016
|
+
}
|
|
63772
64017
|
var KB_MAX_NODES = 300;
|
|
63773
64018
|
var KB_MAX_TOTAL_BYTES = 8 * 1024 * 1024;
|
|
63774
64019
|
var KB_MAX_VISITS = 5e3;
|
|
@@ -63806,14 +64051,14 @@ function eachPage(wikiDir, io, onPage) {
|
|
|
63806
64051
|
return "stop";
|
|
63807
64052
|
}
|
|
63808
64053
|
if (ent.isDirectory()) {
|
|
63809
|
-
if (walk2((0,
|
|
64054
|
+
if (walk2((0, import_node_path31.join)(dir, ent.name)) === "stop") return "stop";
|
|
63810
64055
|
} else if (ent.isFile() && ent.name.endsWith(".md")) {
|
|
63811
64056
|
const slug = ent.name.slice(0, -3);
|
|
63812
64057
|
if (!WIKI_SLUG_RE.test(slug)) {
|
|
63813
|
-
console.warn(`knowledge-store: skipping non-canonical wiki basename "${slug}" (${(0,
|
|
64058
|
+
console.warn(`knowledge-store: skipping non-canonical wiki basename "${slug}" (${(0, import_node_path31.join)(dir, ent.name)})`);
|
|
63814
64059
|
continue;
|
|
63815
64060
|
}
|
|
63816
|
-
if (onPage(slug, (0,
|
|
64061
|
+
if (onPage(slug, (0, import_node_path31.join)(dir, ent.name))) {
|
|
63817
64062
|
found = true;
|
|
63818
64063
|
return "stop";
|
|
63819
64064
|
}
|
|
@@ -63990,8 +64235,8 @@ function readPage(wikiDir, slug, io = REAL_IO) {
|
|
|
63990
64235
|
if (status === "io-error") throw new KnowledgeError("failed to read the knowledge base", "io-error");
|
|
63991
64236
|
return null;
|
|
63992
64237
|
}
|
|
63993
|
-
const full = (0,
|
|
63994
|
-
if (full !== root5 && !full.startsWith(root5 +
|
|
64238
|
+
const full = (0, import_node_path31.resolve)(found), root5 = (0, import_node_path31.resolve)(wikiDir);
|
|
64239
|
+
if (full !== root5 && !full.startsWith(root5 + import_node_path31.sep)) return null;
|
|
63995
64240
|
const pp = splitPage(full, io);
|
|
63996
64241
|
if (!pp.ok) {
|
|
63997
64242
|
if (pp.reason === "oversize") throw new KnowledgeError("knowledge page too large to serve", "too-large");
|
|
@@ -64073,12 +64318,12 @@ function readKnowledgeSummaries(wikiDir, opts = {}, io = REAL_IO) {
|
|
|
64073
64318
|
truncated
|
|
64074
64319
|
};
|
|
64075
64320
|
}
|
|
64076
|
-
var organizePath = (id) => (0,
|
|
64321
|
+
var organizePath = (id) => (0, import_node_path31.join)(projectKnowledgeDir(id), "organize.json");
|
|
64077
64322
|
function writeOrganizeFile(id, org) {
|
|
64078
64323
|
const dir = projectKnowledgeDir(id);
|
|
64079
64324
|
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
64080
64325
|
const dest = organizePath(id);
|
|
64081
|
-
const tmp = (0,
|
|
64326
|
+
const tmp = (0, import_node_path31.join)(dir, `.organize.json.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`);
|
|
64082
64327
|
(0, import_node_fs33.writeFileSync)(tmp, JSON.stringify(org, null, 2));
|
|
64083
64328
|
(0, import_node_fs33.renameSync)(tmp, dest);
|
|
64084
64329
|
}
|
|
@@ -64187,13 +64432,13 @@ function failOrganize(id, requestId, opts) {
|
|
|
64187
64432
|
function gcOldGenerations(id, currentGenerationId) {
|
|
64188
64433
|
const dir = generationsDir(id);
|
|
64189
64434
|
if (!(0, import_node_fs33.existsSync)(dir)) return;
|
|
64190
|
-
const entries2 = (0, import_node_fs33.readdirSync)(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => ({ name: e.name, mtimeMs: (0, import_node_fs33.statSync)((0,
|
|
64435
|
+
const entries2 = (0, import_node_fs33.readdirSync)(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => ({ name: e.name, mtimeMs: (0, import_node_fs33.statSync)((0, import_node_path31.join)(dir, e.name)).mtimeMs })).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
64191
64436
|
const keep = new Set(entries2.slice(0, GEN_KEEP).map((e) => e.name));
|
|
64192
64437
|
keep.add(currentGenerationId);
|
|
64193
64438
|
for (const e of entries2) {
|
|
64194
64439
|
if (keep.has(e.name)) continue;
|
|
64195
64440
|
try {
|
|
64196
|
-
(0, import_node_fs33.rmSync)((0,
|
|
64441
|
+
(0, import_node_fs33.rmSync)((0, import_node_path31.join)(dir, e.name), { recursive: true, force: true });
|
|
64197
64442
|
} catch (err2) {
|
|
64198
64443
|
console.warn(`knowledge-store: could not GC stale generation dir ${e.name}: ${err2 instanceof Error ? err2.message : err2}`);
|
|
64199
64444
|
}
|
|
@@ -64397,7 +64642,15 @@ function registerKnowledgeRoutes(app) {
|
|
|
64397
64642
|
try {
|
|
64398
64643
|
const project = getProject(req.params.id);
|
|
64399
64644
|
if (!project) return reply.status(404).send({ ok: false, error: `unknown project: ${req.params.id}` });
|
|
64400
|
-
|
|
64645
|
+
let wikiDir;
|
|
64646
|
+
if (req.query.generation === void 0) {
|
|
64647
|
+
wikiDir = currentGenerationWikiDir(project.id);
|
|
64648
|
+
} else if (typeof req.query.generation === "string" && isGenerationId(req.query.generation)) {
|
|
64649
|
+
const requested = generationWikiDir(project.id, req.query.generation);
|
|
64650
|
+
wikiDir = (0, import_node_fs34.existsSync)(requested) ? requested : null;
|
|
64651
|
+
} else {
|
|
64652
|
+
return reply.status(400).send({ ok: false, error: "invalid generation id" });
|
|
64653
|
+
}
|
|
64401
64654
|
const pg = wikiDir ? readPage(wikiDir, req.params.slug) : null;
|
|
64402
64655
|
if (!pg) return reply.status(404).send({ ok: false, error: "page not found" });
|
|
64403
64656
|
return { ok: true, page: pg };
|
|
@@ -65297,8 +65550,8 @@ function viewOf(p, facts) {
|
|
|
65297
65550
|
// project-sources-store.ts
|
|
65298
65551
|
var import_node_crypto19 = require("node:crypto");
|
|
65299
65552
|
var import_node_fs35 = require("node:fs");
|
|
65300
|
-
var
|
|
65301
|
-
var sourcesDir = (id) => (0,
|
|
65553
|
+
var import_node_path32 = require("node:path");
|
|
65554
|
+
var sourcesDir = (id) => (0, import_node_path32.join)(projectDir(id), "sources");
|
|
65302
65555
|
var safeExt = (ext) => typeof ext === "string" && /^[a-z0-9]{1,8}$/i.test(ext) ? ext.toLowerCase() : "bin";
|
|
65303
65556
|
function writeAtomic2(path, buf) {
|
|
65304
65557
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
@@ -65309,7 +65562,7 @@ function saveSource(id, file) {
|
|
|
65309
65562
|
(0, import_node_fs35.mkdirSync)(sourcesDir(id), { recursive: true });
|
|
65310
65563
|
const sha2563 = (0, import_node_crypto19.createHash)("sha256").update(file.buf).digest("hex");
|
|
65311
65564
|
const ext = safeExt(file.ext);
|
|
65312
|
-
const p = (0,
|
|
65565
|
+
const p = (0, import_node_path32.join)(sourcesDir(id), `${sha2563}.${ext}`);
|
|
65313
65566
|
if (!(0, import_node_fs35.existsSync)(p)) writeAtomic2(p, file.buf);
|
|
65314
65567
|
return { name: String(file.name), sha256: sha2563, ext, bytes: file.buf.length };
|
|
65315
65568
|
}
|
|
@@ -67698,10 +67951,15 @@ function lateralHalfExtent(dims, rotDeg, round) {
|
|
|
67698
67951
|
const th = (typeof rotDeg === "number" && isFinite(rotDeg) ? rotDeg : 0) * Math.PI / 180;
|
|
67699
67952
|
return Math.abs(dims.w / 2 * Math.cos(th)) + Math.abs(dims.d / 2 * Math.sin(th));
|
|
67700
67953
|
}
|
|
67954
|
+
function verticalHalfExtent(dims, rotDeg, round) {
|
|
67955
|
+
if (round) return dims.w / 2;
|
|
67956
|
+
const th = (typeof rotDeg === "number" && isFinite(rotDeg) ? rotDeg : 0) * Math.PI / 180;
|
|
67957
|
+
return Math.abs(dims.d / 2 * Math.cos(th)) + Math.abs(dims.w / 2 * Math.sin(th));
|
|
67958
|
+
}
|
|
67701
67959
|
var NO_PLANE_OFFSET = { dx: 0, dy: 0, signed: 0 };
|
|
67702
|
-
function planeOffset(positionH, ax, ay, bx, by, dims, rotDeg
|
|
67960
|
+
function planeOffset(positionH, ax, ay, bx, by, dims, rotDeg) {
|
|
67703
67961
|
const pos2 = planePosition(positionH);
|
|
67704
|
-
if (pos2 === "middle"
|
|
67962
|
+
if (pos2 === "middle") return NO_PLANE_OFFSET;
|
|
67705
67963
|
const planLen = Math.hypot(bx - ax, by - ay);
|
|
67706
67964
|
if (!(planLen >= DEGENERATE_MM)) return NO_PLANE_OFFSET;
|
|
67707
67965
|
const half = lateralHalfExtent(dims, rotDeg, dims.round === true);
|
|
@@ -67909,7 +68167,7 @@ function contractToScene(contractInput) {
|
|
|
67909
68167
|
const ptPerFt = plan.pt_per_ft && plan.pt_per_ft > 0 ? plan.pt_per_ft : 1;
|
|
67910
68168
|
const defaultTosMm = (plan.default_tos ?? 0) * IN_TO_MM2;
|
|
67911
68169
|
for (const m of plan.members ?? []) {
|
|
67912
|
-
const explicit = m.section && typeof m.section.w === "number" && m.section.w > 0 && typeof m.section.d === "number" && m.section.d > 0 ? { w: m.section.w, d: m.section.d, approx: false } : null;
|
|
68170
|
+
const explicit = m.section && typeof m.section.w === "number" && m.section.w > 0 && typeof m.section.d === "number" && m.section.d > 0 ? { w: m.section.w, d: m.section.d, approx: false, round: false } : null;
|
|
67913
68171
|
const stdDims = profileDims(m.profile);
|
|
67914
68172
|
const dims = stdDims ?? explicit;
|
|
67915
68173
|
if (!dims || !Array.isArray(m.wp) || m.wp.length < 2) {
|
|
@@ -67942,9 +68200,10 @@ function contractToScene(contractInput) {
|
|
|
67942
68200
|
const z0 = m.ends?.[0]?.tos != null ? m.ends[0].tos * IN_TO_MM2 : defaultTosMm;
|
|
67943
68201
|
const z1 = m.ends?.[1]?.tos != null ? m.ends[1].tos * IN_TO_MM2 : defaultTosMm;
|
|
67944
68202
|
const pos2 = depthPosition(m.position, Math.abs(z1 - z0), Math.hypot(bx - ax, by - ay), mIsBrace && m.brace?.type === "vertical");
|
|
67945
|
-
const
|
|
68203
|
+
const halfVertical = verticalHalfExtent(dims, m.rot, dims.round === true);
|
|
68204
|
+
const zoff = pos2 === "top" ? -halfVertical : pos2 === "bottom" ? halfVertical : 0;
|
|
67946
68205
|
posOffset = zoff;
|
|
67947
|
-
lat = planeOffset(m.positionH, ax, ay, bx, by, dims, m.rot
|
|
68206
|
+
lat = planeOffset(m.positionH, ax, ay, bx, by, dims, m.rot);
|
|
67948
68207
|
workFrom = [ax + lat.dx, ay + lat.dy, z0];
|
|
67949
68208
|
workTo = [bx + lat.dx, by + lat.dy, z1];
|
|
67950
68209
|
from = [ax + lat.dx, ay + lat.dy, z0 + zoff];
|
|
@@ -68305,7 +68564,7 @@ function sceneFromModel(view) {
|
|
|
68305
68564
|
const beamClears = beamClearances(view.doc.joints);
|
|
68306
68565
|
for (const vm of view.members) {
|
|
68307
68566
|
const m = vm.raw;
|
|
68308
|
-
const explicit = m.section && typeof m.section.w === "number" && m.section.w > 0 && typeof m.section.d === "number" && m.section.d > 0 ? { w: m.section.w, d: m.section.d, approx: false } : null;
|
|
68567
|
+
const explicit = m.section && typeof m.section.w === "number" && m.section.w > 0 && typeof m.section.d === "number" && m.section.d > 0 ? { w: m.section.w, d: m.section.d, approx: false, round: false } : null;
|
|
68309
68568
|
const stdDims = profileDims(m.profile);
|
|
68310
68569
|
const dims = stdDims ?? explicit;
|
|
68311
68570
|
if (!dims) {
|
|
@@ -68338,9 +68597,10 @@ function sceneFromModel(view) {
|
|
|
68338
68597
|
workTo = to;
|
|
68339
68598
|
} else {
|
|
68340
68599
|
const pos2 = depthPosition(m.position, Math.abs(z1 - z0), Math.hypot(bx - ax, by - ay), mIsBrace && braceType === "vertical");
|
|
68341
|
-
const
|
|
68600
|
+
const halfVertical = verticalHalfExtent(dims, m.rot, dims.round === true);
|
|
68601
|
+
const zoff = pos2 === "top" ? -halfVertical : pos2 === "bottom" ? halfVertical : 0;
|
|
68342
68602
|
posOffset = zoff;
|
|
68343
|
-
lat = planeOffset(m.positionH, ax, ay, bx, by, dims, m.rot
|
|
68603
|
+
lat = planeOffset(m.positionH, ax, ay, bx, by, dims, m.rot);
|
|
68344
68604
|
workFrom = [ax + lat.dx, ay + lat.dy, z0];
|
|
68345
68605
|
workTo = [bx + lat.dx, by + lat.dy, z1];
|
|
68346
68606
|
from = [ax + lat.dx, ay + lat.dy, z0 + zoff];
|
|
@@ -69565,7 +69825,7 @@ var import_node_crypto22 = require("node:crypto");
|
|
|
69565
69825
|
|
|
69566
69826
|
// reference-import.ts
|
|
69567
69827
|
var import_node_fs36 = require("node:fs");
|
|
69568
|
-
var
|
|
69828
|
+
var import_node_path33 = require("node:path");
|
|
69569
69829
|
var AGENT2 = "ifc-reference-reader";
|
|
69570
69830
|
var WARN_BYTES = 50 * 1024 * 1024;
|
|
69571
69831
|
var MAX_BYTES5 = 150 * 1024 * 1024;
|
|
@@ -69832,7 +70092,7 @@ var readerChain2 = Promise.resolve();
|
|
|
69832
70092
|
function writeReaderApp2(companionId, command, ifcPath, filter) {
|
|
69833
70093
|
const dir = appPath(companionId);
|
|
69834
70094
|
(0, import_node_fs36.mkdirSync)(dir, { recursive: true });
|
|
69835
|
-
const flo = (0,
|
|
70095
|
+
const flo = (0, import_node_path33.join)(dir, `${companionId}.flo`);
|
|
69836
70096
|
const lines = [
|
|
69837
70097
|
`app: ${companionId}`,
|
|
69838
70098
|
"version: 0.1.0",
|
|
@@ -69942,7 +70202,7 @@ async function readReferenceModel(companionId, ifcPath, opts = {}) {
|
|
|
69942
70202
|
var import_node_crypto21 = require("node:crypto");
|
|
69943
70203
|
var import_node_fs37 = require("node:fs");
|
|
69944
70204
|
var import_promises4 = require("node:stream/promises");
|
|
69945
|
-
var
|
|
70205
|
+
var import_node_path34 = require("node:path");
|
|
69946
70206
|
function insideProject(projectId, relPath) {
|
|
69947
70207
|
const raw = String(relPath ?? "");
|
|
69948
70208
|
const m = raw.match(/^references\/([^/\\]+)$/);
|
|
@@ -69951,24 +70211,24 @@ function insideProject(projectId, relPath) {
|
|
|
69951
70211
|
throw new ReferenceImportError("that reference does not name one of its own files, so it cannot be read or removed");
|
|
69952
70212
|
}
|
|
69953
70213
|
const root5 = realish(projectDir(projectId));
|
|
69954
|
-
const abs = (0,
|
|
69955
|
-
if (realish((0,
|
|
70214
|
+
const abs = (0, import_node_path34.resolve)(root5, REFERENCE_DIR, name);
|
|
70215
|
+
if (realish((0, import_node_path34.join)(root5, REFERENCE_DIR)) !== (0, import_node_path34.resolve)(root5, REFERENCE_DIR)) {
|
|
69956
70216
|
throw new ReferenceImportError("this project\u2019s references folder is a link to somewhere else, so it will not be written to");
|
|
69957
70217
|
}
|
|
69958
|
-
if (!abs.startsWith(root5 +
|
|
70218
|
+
if (!abs.startsWith(root5 + import_node_path34.sep)) {
|
|
69959
70219
|
throw new ReferenceImportError("that reference points outside its project, so it cannot be read or removed");
|
|
69960
70220
|
}
|
|
69961
70221
|
return abs;
|
|
69962
70222
|
}
|
|
69963
70223
|
function realish(p) {
|
|
69964
70224
|
try {
|
|
69965
|
-
return import_node_fs37.realpathSync.native((0,
|
|
70225
|
+
return import_node_fs37.realpathSync.native((0, import_node_path34.resolve)(p));
|
|
69966
70226
|
} catch {
|
|
69967
|
-
return (0,
|
|
70227
|
+
return (0, import_node_path34.resolve)(p);
|
|
69968
70228
|
}
|
|
69969
70229
|
}
|
|
69970
70230
|
var REFERENCE_CACHE_VERSION = 5;
|
|
69971
|
-
var cachePath2 = (projectId, refId2) => (0,
|
|
70231
|
+
var cachePath2 = (projectId, refId2) => (0, import_node_path34.join)(projectDir(projectId), `.floless-refcache-${safeId2(refId2)}.json`);
|
|
69972
70232
|
function safeId2(refId2) {
|
|
69973
70233
|
const s = String(refId2 ?? "").replace(/[^A-Za-z0-9._-]+/g, "_");
|
|
69974
70234
|
if (!s || s === "." || s === "..") throw new ReferenceImportError("that reference has an unusable id");
|
|
@@ -69981,7 +70241,7 @@ async function hashFile(path) {
|
|
|
69981
70241
|
}
|
|
69982
70242
|
function copyOriginal(projectId, relPath, sourceAbs, tag) {
|
|
69983
70243
|
const abs = insideProject(projectId, relPath);
|
|
69984
|
-
(0, import_node_fs37.mkdirSync)((0,
|
|
70244
|
+
(0, import_node_fs37.mkdirSync)((0, import_node_path34.dirname)(abs), { recursive: true });
|
|
69985
70245
|
const tmp = `${abs}.${safeId2(tag)}.part`;
|
|
69986
70246
|
(0, import_node_fs37.copyFileSync)(sourceAbs, tmp);
|
|
69987
70247
|
(0, import_node_fs37.renameSync)(tmp, abs);
|
|
@@ -69989,7 +70249,7 @@ function copyOriginal(projectId, relPath, sourceAbs, tag) {
|
|
|
69989
70249
|
}
|
|
69990
70250
|
function referenceFilesOnDisk(projectId) {
|
|
69991
70251
|
try {
|
|
69992
|
-
return (0, import_node_fs37.readdirSync)((0,
|
|
70252
|
+
return (0, import_node_fs37.readdirSync)((0, import_node_path34.join)(projectDir(projectId), REFERENCE_DIR)).map((f) => `${REFERENCE_DIR}/${f}`);
|
|
69993
70253
|
} catch (e) {
|
|
69994
70254
|
if (e.code === "ENOENT") return [];
|
|
69995
70255
|
throw new ReferenceImportError(
|
|
@@ -70468,8 +70728,8 @@ function registerReferenceRoutes(app, deps) {
|
|
|
70468
70728
|
}
|
|
70469
70729
|
|
|
70470
70730
|
// bom-export.ts
|
|
70471
|
-
var
|
|
70472
|
-
var
|
|
70731
|
+
var import_node_os19 = require("node:os");
|
|
70732
|
+
var import_node_path35 = require("node:path");
|
|
70473
70733
|
|
|
70474
70734
|
// node_modules/write-excel-file/modules/export/writeXlsxFileNode.js
|
|
70475
70735
|
var import_node_fs38 = __toESM(require("node:fs"), 1);
|
|
@@ -73869,8 +74129,8 @@ var BOM_EXPORT_KIND = {
|
|
|
73869
74129
|
html: "bom-html"
|
|
73870
74130
|
};
|
|
73871
74131
|
function bomExportPath(appId, format) {
|
|
73872
|
-
const root5 = process.env.FLOLESS_HOME ?? (0,
|
|
73873
|
-
return (0,
|
|
74132
|
+
const root5 = process.env.FLOLESS_HOME ?? (0, import_node_path35.join)((0, import_node_os19.homedir)(), ".floless");
|
|
74133
|
+
return (0, import_node_path35.join)(root5, "exports", appId, `${appId}-bom.${format}`);
|
|
73874
74134
|
}
|
|
73875
74135
|
function csvField(v) {
|
|
73876
74136
|
let s = String(v);
|
|
@@ -74233,7 +74493,7 @@ function replyLifecycleLockBusyError(error, logger, reply) {
|
|
|
74233
74493
|
|
|
74234
74494
|
// project-export-files.ts
|
|
74235
74495
|
var import_node_fs39 = require("node:fs");
|
|
74236
|
-
var
|
|
74496
|
+
var import_node_path36 = require("node:path");
|
|
74237
74497
|
function projectExportFiles(appId, kindOf2 = appId) {
|
|
74238
74498
|
if (kindOf2 === "vectorize") {
|
|
74239
74499
|
return [{ kind: "svg", filename: `${appId}.svg` }];
|
|
@@ -74262,12 +74522,12 @@ function exportFileBase(projectId, appId, now = /* @__PURE__ */ new Date()) {
|
|
|
74262
74522
|
}
|
|
74263
74523
|
function uniqueProjectExportFilename(projectId, preferred) {
|
|
74264
74524
|
const dir = projectExportsDir(projectId);
|
|
74265
|
-
if (!(0, import_node_fs39.existsSync)((0,
|
|
74266
|
-
const extension = (0,
|
|
74525
|
+
if (!(0, import_node_fs39.existsSync)((0, import_node_path36.join)(dir, preferred))) return preferred;
|
|
74526
|
+
const extension = (0, import_node_path36.extname)(preferred);
|
|
74267
74527
|
const stem = preferred.slice(0, preferred.length - extension.length);
|
|
74268
74528
|
for (let suffix = 2; suffix <= 9999; suffix += 1) {
|
|
74269
74529
|
const candidate = `${stem}-${suffix}${extension}`;
|
|
74270
|
-
if (!(0, import_node_fs39.existsSync)((0,
|
|
74530
|
+
if (!(0, import_node_fs39.existsSync)((0, import_node_path36.join)(dir, candidate))) return candidate;
|
|
74271
74531
|
}
|
|
74272
74532
|
throw new Error("could not allocate a unique project export filename");
|
|
74273
74533
|
}
|
|
@@ -75018,7 +75278,7 @@ function buildApprovalReview(input) {
|
|
|
75018
75278
|
// working-revision-manifest.ts
|
|
75019
75279
|
var import_node_crypto24 = require("node:crypto");
|
|
75020
75280
|
var import_node_fs41 = require("node:fs");
|
|
75021
|
-
var
|
|
75281
|
+
var import_node_path37 = require("node:path");
|
|
75022
75282
|
|
|
75023
75283
|
// write-json-atomic.ts
|
|
75024
75284
|
var import_node_crypto23 = require("node:crypto");
|
|
@@ -75030,7 +75290,7 @@ function writeJsonAtomic(path, value) {
|
|
|
75030
75290
|
}
|
|
75031
75291
|
|
|
75032
75292
|
// working-revision-manifest.ts
|
|
75033
|
-
var pathOf = (projectId) => (0,
|
|
75293
|
+
var pathOf = (projectId) => (0, import_node_path37.join)(projectDir(projectId), ".floless-working-revision-state-v1.json");
|
|
75034
75294
|
var checksumOf = (body) => hashOf(body);
|
|
75035
75295
|
function bodyOf(value) {
|
|
75036
75296
|
const { checksum: _checksum, ...body } = value;
|
|
@@ -75331,13 +75591,13 @@ function projectApprovalCandidateAccepted(appId, projectId, candidate) {
|
|
|
75331
75591
|
// project-checkpoints-store.ts
|
|
75332
75592
|
var import_node_crypto25 = require("node:crypto");
|
|
75333
75593
|
var import_node_fs42 = require("node:fs");
|
|
75334
|
-
var
|
|
75594
|
+
var import_node_path38 = require("node:path");
|
|
75335
75595
|
var HASH_RE2 = /^[0-9a-f]{64}$/;
|
|
75336
75596
|
function root4(projectId) {
|
|
75337
|
-
return (0,
|
|
75597
|
+
return (0, import_node_path38.join)(projectDir(projectId), ".floless-checkpoints-store-v1");
|
|
75338
75598
|
}
|
|
75339
|
-
var objectsDir2 = (projectId) => (0,
|
|
75340
|
-
var eventsPath = (projectId) => (0,
|
|
75599
|
+
var objectsDir2 = (projectId) => (0, import_node_path38.join)(root4(projectId), "objects");
|
|
75600
|
+
var eventsPath = (projectId) => (0, import_node_path38.join)(root4(projectId), "events.json");
|
|
75341
75601
|
function readEvents(projectId) {
|
|
75342
75602
|
try {
|
|
75343
75603
|
const parsed = JSON.parse((0, import_node_fs42.readFileSync)(eventsPath(projectId), "utf8"));
|
|
@@ -75355,7 +75615,7 @@ function validEvent(value) {
|
|
|
75355
75615
|
function readContent(projectId, id) {
|
|
75356
75616
|
if (!HASH_RE2.test(id)) return null;
|
|
75357
75617
|
try {
|
|
75358
|
-
const value = JSON.parse((0, import_node_fs42.readFileSync)((0,
|
|
75618
|
+
const value = JSON.parse((0, import_node_fs42.readFileSync)((0, import_node_path38.join)(objectsDir2(projectId), `${id}.json`), "utf8"));
|
|
75359
75619
|
if (value?.schema !== 1 || value.id !== id || hashCheckpoint(value) !== id) return null;
|
|
75360
75620
|
return value;
|
|
75361
75621
|
} catch {
|
|
@@ -75390,7 +75650,7 @@ function captureProjectCheckpoint(input) {
|
|
|
75390
75650
|
};
|
|
75391
75651
|
const id = hashCheckpoint(withoutId);
|
|
75392
75652
|
(0, import_node_fs42.mkdirSync)(objectsDir2(input.project.id), { recursive: true });
|
|
75393
|
-
const path = (0,
|
|
75653
|
+
const path = (0, import_node_path38.join)(objectsDir2(input.project.id), `${id}.json`);
|
|
75394
75654
|
if (!(0, import_node_fs42.existsSync)(path)) writeJsonAtomic(path, { ...withoutId, id });
|
|
75395
75655
|
const event = appendEvent(input.project.id, {
|
|
75396
75656
|
checkpointId: id,
|
|
@@ -75435,15 +75695,15 @@ function markProjectCheckpoint(project, checkpointId, kind, expectedEventId) {
|
|
|
75435
75695
|
// export-source.ts
|
|
75436
75696
|
var import_node_crypto26 = require("node:crypto");
|
|
75437
75697
|
var import_node_fs43 = require("node:fs");
|
|
75438
|
-
var
|
|
75439
|
-
var
|
|
75698
|
+
var import_node_os20 = require("node:os");
|
|
75699
|
+
var import_node_path39 = require("node:path");
|
|
75440
75700
|
var HANDLE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
75441
75701
|
var MAX_STORED_HANDLES = 512;
|
|
75442
75702
|
function storeRoot() {
|
|
75443
|
-
const root5 = process.env.FLOLESS_HOME ?? (0,
|
|
75444
|
-
return (0,
|
|
75703
|
+
const root5 = process.env.FLOLESS_HOME ?? (0, import_node_path39.join)((0, import_node_os20.homedir)(), ".floless");
|
|
75704
|
+
return (0, import_node_path39.join)(root5, ".floless-export-handles-v1");
|
|
75445
75705
|
}
|
|
75446
|
-
var handlePath = (id) => (0,
|
|
75706
|
+
var handlePath = (id) => (0, import_node_path39.join)(storeRoot(), `${id}.json`);
|
|
75447
75707
|
function withoutChecksum(value) {
|
|
75448
75708
|
const { checksum: _checksum, ...body } = value;
|
|
75449
75709
|
return body;
|
|
@@ -75635,7 +75895,7 @@ function collectExpiredExportHandles(now = Date.now()) {
|
|
|
75635
75895
|
// file-publication.ts
|
|
75636
75896
|
var import_node_crypto27 = require("node:crypto");
|
|
75637
75897
|
var import_node_fs44 = require("node:fs");
|
|
75638
|
-
var
|
|
75898
|
+
var import_node_path40 = require("node:path");
|
|
75639
75899
|
var FilePublicationError = class extends Error {
|
|
75640
75900
|
constructor(message, code, paths = []) {
|
|
75641
75901
|
super(message);
|
|
@@ -75662,9 +75922,9 @@ function fileProofEquals2(a, b) {
|
|
|
75662
75922
|
return a === null || b === null ? a === b : a.bytes === b.bytes && a.sha256 === b.sha256;
|
|
75663
75923
|
}
|
|
75664
75924
|
function durableCanonicalJson(path, value) {
|
|
75665
|
-
const dir = (0,
|
|
75925
|
+
const dir = (0, import_node_path40.dirname)(path);
|
|
75666
75926
|
(0, import_node_fs44.mkdirSync)(dir, { recursive: true });
|
|
75667
|
-
const temp = (0,
|
|
75927
|
+
const temp = (0, import_node_path40.join)(dir, `.${(0, import_node_path40.basename)(path)}.${process.pid}.${(0, import_node_crypto27.randomUUID)()}.tmp`);
|
|
75668
75928
|
try {
|
|
75669
75929
|
(0, import_node_fs44.writeFileSync)(temp, `${canonicalJson(value)}
|
|
75670
75930
|
`, { encoding: "utf8", flag: "wx" });
|
|
@@ -75711,11 +75971,11 @@ function assertSameVolume(a, b) {
|
|
|
75711
75971
|
}
|
|
75712
75972
|
function uniqueArtifact(dir, label2, livePath) {
|
|
75713
75973
|
(0, import_node_fs44.mkdirSync)(dir, { recursive: true });
|
|
75714
|
-
return (0,
|
|
75974
|
+
return (0, import_node_path40.join)(dir, `.floless-${label2}-${(0, import_node_crypto27.randomUUID)()}-${(0, import_node_path40.basename)(livePath)}`);
|
|
75715
75975
|
}
|
|
75716
75976
|
function publishFileExclusive(input) {
|
|
75717
75977
|
const { livePath, stagedPath, expectedLive, artifactDir } = input;
|
|
75718
|
-
assertSameVolume(stagedPath, (0, import_node_fs44.existsSync)(livePath) ? livePath : (0,
|
|
75978
|
+
assertSameVolume(stagedPath, (0, import_node_fs44.existsSync)(livePath) ? livePath : (0, import_node_path40.dirname)(livePath));
|
|
75719
75979
|
const stagedProof = readFileProof2(stagedPath);
|
|
75720
75980
|
if (!stagedProof) throw new FilePublicationError("staged publication file is missing", "io-failure", [stagedPath]);
|
|
75721
75981
|
let beforeImage = null;
|
|
@@ -75744,7 +76004,7 @@ function publishFileExclusive(input) {
|
|
|
75744
76004
|
(0, import_node_fs44.unlinkSync)(stagedPath);
|
|
75745
76005
|
input.onFaultPoint?.("after-staged-unlink", { livePath, stagedPath, beforeImage });
|
|
75746
76006
|
syncFile(livePath);
|
|
75747
|
-
syncDirectoryBestEffort((0,
|
|
76007
|
+
syncDirectoryBestEffort((0, import_node_path40.dirname)(livePath));
|
|
75748
76008
|
} catch (error) {
|
|
75749
76009
|
if (beforeImage && !(0, import_node_fs44.existsSync)(livePath)) {
|
|
75750
76010
|
try {
|
|
@@ -75766,12 +76026,12 @@ function publishFileExclusive(input) {
|
|
|
75766
76026
|
}
|
|
75767
76027
|
|
|
75768
76028
|
// app-publication-guard.ts
|
|
75769
|
-
var
|
|
76029
|
+
var import_node_path42 = require("node:path");
|
|
75770
76030
|
|
|
75771
76031
|
// app-source-lock.ts
|
|
75772
76032
|
var import_node_fs45 = require("node:fs");
|
|
75773
|
-
var
|
|
75774
|
-
var
|
|
76033
|
+
var import_node_os21 = require("node:os");
|
|
76034
|
+
var import_node_path41 = require("node:path");
|
|
75775
76035
|
var AppSourcePublicationBusyError = class extends Error {
|
|
75776
76036
|
status = 409;
|
|
75777
76037
|
constructor() {
|
|
@@ -75780,8 +76040,8 @@ var AppSourcePublicationBusyError = class extends Error {
|
|
|
75780
76040
|
}
|
|
75781
76041
|
};
|
|
75782
76042
|
function activeApprovalTransaction(appId) {
|
|
75783
|
-
const home = process.env.AWARE_HOME || (0,
|
|
75784
|
-
const path = (0,
|
|
76043
|
+
const home = process.env.AWARE_HOME || (0, import_node_path41.join)((0, import_node_os21.homedir)(), ".aware");
|
|
76044
|
+
const path = (0, import_node_path41.join)(home, "apps", appId, ".floless-approval-publication-journal-v1.json");
|
|
75785
76045
|
if (!(0, import_node_fs45.existsSync)(path)) return null;
|
|
75786
76046
|
try {
|
|
75787
76047
|
const stored2 = JSON.parse((0, import_node_fs45.readFileSync)(path, "utf8"));
|
|
@@ -75962,7 +76222,7 @@ var AppPublicationGuardError = class extends Error {
|
|
|
75962
76222
|
function assertTarget(target) {
|
|
75963
76223
|
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(target.appId)) throw new Error(`invalid app publication id: ${target.appId}`);
|
|
75964
76224
|
for (const path of [target.sourcePath, target.lockPath, target.manifestPath]) {
|
|
75965
|
-
if (!(0,
|
|
76225
|
+
if (!(0, import_node_path42.isAbsolute)(path) || !(0, import_node_path42.resolve)(path)) throw new Error("app publication paths must be absolute/resolvable");
|
|
75966
76226
|
}
|
|
75967
76227
|
}
|
|
75968
76228
|
async function underAppLock(input) {
|
|
@@ -76039,17 +76299,17 @@ function withAppPublicationWhileProjectLocked(input) {
|
|
|
76039
76299
|
// approval-app-publication.ts
|
|
76040
76300
|
var import_node_crypto29 = require("node:crypto");
|
|
76041
76301
|
var import_node_fs47 = require("node:fs");
|
|
76042
|
-
var
|
|
76302
|
+
var import_node_path43 = require("node:path");
|
|
76043
76303
|
var JOURNAL = ".floless-approval-publication-journal-v1.json";
|
|
76044
76304
|
var MANIFEST = ".floless-app-publication-state-v1.json";
|
|
76045
|
-
var approvalPublicationJournalPath = (sourcePath) => (0,
|
|
76046
|
-
var approvalPublicationManifestPath = (sourcePath) => (0,
|
|
76305
|
+
var approvalPublicationJournalPath = (sourcePath) => (0, import_node_path43.join)((0, import_node_path43.dirname)(sourcePath), JOURNAL);
|
|
76306
|
+
var approvalPublicationManifestPath = (sourcePath) => (0, import_node_path43.join)((0, import_node_path43.dirname)(sourcePath), MANIFEST);
|
|
76047
76307
|
function stagingRoot2(sourcePath) {
|
|
76048
|
-
return (0,
|
|
76308
|
+
return (0, import_node_path43.join)((0, import_node_path43.dirname)((0, import_node_path43.dirname)((0, import_node_path43.dirname)(sourcePath))), ".floless-approval-publications-v1");
|
|
76049
76309
|
}
|
|
76050
76310
|
function assertContained(root5, path) {
|
|
76051
|
-
const rel = (0,
|
|
76052
|
-
if (!rel || rel.startsWith("..") || (0,
|
|
76311
|
+
const rel = (0, import_node_path43.relative)((0, import_node_path43.resolve)(root5), (0, import_node_path43.resolve)(path));
|
|
76312
|
+
if (!rel || rel.startsWith("..") || (0, import_node_path43.isAbsolute)(rel)) throw new Error("approval publication path escaped its staging root");
|
|
76053
76313
|
}
|
|
76054
76314
|
function validProof2(value) {
|
|
76055
76315
|
if (value === null) return true;
|
|
@@ -76068,8 +76328,8 @@ function readApprovalPublicationJournal(sourcePath) {
|
|
|
76068
76328
|
const stored2 = JSON.parse((0, import_node_fs47.readFileSync)(approvalPublicationJournalPath(sourcePath), "utf8"));
|
|
76069
76329
|
const value = stored2?.journal;
|
|
76070
76330
|
const expectedLiveLock = sourcePath.replace(/\.[^.]+$/, ".lock");
|
|
76071
|
-
const expectedStageDir = (0,
|
|
76072
|
-
if (!value || stored2.checksum !== hashOf(value) || value.schema !== 1 || (0,
|
|
76331
|
+
const expectedStageDir = (0, import_node_path43.join)(stagingRoot2(sourcePath), `${value?.appId ?? ""}-${value?.id ?? ""}`);
|
|
76332
|
+
if (!value || stored2.checksum !== hashOf(value) || value.schema !== 1 || (0, import_node_path43.resolve)(value.liveSourcePath) !== (0, import_node_path43.resolve)(sourcePath) || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(value.appId) || !/^[a-f0-9-]{36}$/i.test(value.id) || !value.projectId || value.phase !== "staged" && value.phase !== "authorized" && value.phase !== "published" || (0, import_node_path43.resolve)(value.liveLockPath) !== (0, import_node_path43.resolve)(expectedLiveLock) || (0, import_node_path43.resolve)(value.stageDir) !== (0, import_node_path43.resolve)(expectedStageDir) || (0, import_node_path43.resolve)(value.stagedSourcePath) !== (0, import_node_path43.resolve)(value.stageDir, "app", (0, import_node_path43.basename)(sourcePath)) || (0, import_node_path43.resolve)(value.stagedLockPath) !== (0, import_node_path43.resolve)(value.stageDir, "app", (0, import_node_path43.basename)(expectedLiveLock)) || (0, import_node_path43.resolve)(value.artifactDir) !== (0, import_node_path43.resolve)(value.stageDir, "artifacts") || !validProof2(value.beforeSource) || !validProof2(value.beforeLock) || !validProof2(value.stagedSource) || value.stagedSource === null || !validProof2(value.stagedLock) || value.stagedLock === null) return null;
|
|
76073
76333
|
assertContained(stagingRoot2(sourcePath), value.stageDir);
|
|
76074
76334
|
assertContained(value.stageDir, value.stagedSourcePath);
|
|
76075
76335
|
assertContained(value.stageDir, value.stagedLockPath);
|
|
@@ -76080,10 +76340,10 @@ function readApprovalPublicationJournal(sourcePath) {
|
|
|
76080
76340
|
}
|
|
76081
76341
|
}
|
|
76082
76342
|
async function stageApprovalPublication(input) {
|
|
76083
|
-
const appRoot = (0,
|
|
76343
|
+
const appRoot = (0, import_node_path43.dirname)(input.sourcePath);
|
|
76084
76344
|
const id = (0, import_node_crypto29.randomUUID)();
|
|
76085
|
-
const stageDir = (0,
|
|
76086
|
-
const stagedAppRoot = (0,
|
|
76345
|
+
const stageDir = (0, import_node_path43.join)(stagingRoot2(input.sourcePath), `${input.appId}-${id}`);
|
|
76346
|
+
const stagedAppRoot = (0, import_node_path43.join)(stageDir, "app");
|
|
76087
76347
|
let stagedSourcePath = "";
|
|
76088
76348
|
let stagedLockPath = "";
|
|
76089
76349
|
let stagedSource = null;
|
|
@@ -76094,9 +76354,9 @@ async function stageApprovalPublication(input) {
|
|
|
76094
76354
|
(0, import_node_fs47.mkdirSync)(stageDir, { recursive: true });
|
|
76095
76355
|
(0, import_node_fs47.cpSync)(appRoot, stagedAppRoot, {
|
|
76096
76356
|
recursive: true,
|
|
76097
|
-
filter: (path) => ![JOURNAL, MANIFEST].includes((0,
|
|
76357
|
+
filter: (path) => ![JOURNAL, MANIFEST].includes((0, import_node_path43.basename)(path))
|
|
76098
76358
|
});
|
|
76099
|
-
stagedSourcePath = (0,
|
|
76359
|
+
stagedSourcePath = (0, import_node_path43.join)(stagedAppRoot, (0, import_node_path43.relative)(appRoot, input.sourcePath));
|
|
76100
76360
|
stagedLockPath = await input.build(stagedSourcePath);
|
|
76101
76361
|
stagedSource = readFileProof2(stagedSourcePath);
|
|
76102
76362
|
stagedLock = readFileProof2(stagedLockPath);
|
|
@@ -76118,7 +76378,7 @@ async function stageApprovalPublication(input) {
|
|
|
76118
76378
|
stagedSourcePath,
|
|
76119
76379
|
stagedLockPath,
|
|
76120
76380
|
stageDir,
|
|
76121
|
-
artifactDir: (0,
|
|
76381
|
+
artifactDir: (0, import_node_path43.join)(stageDir, "artifacts"),
|
|
76122
76382
|
beforeSource,
|
|
76123
76383
|
beforeLock,
|
|
76124
76384
|
stagedSource,
|
|
@@ -76189,9 +76449,6 @@ function values(input) {
|
|
|
76189
76449
|
function optionalString(v) {
|
|
76190
76450
|
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
76191
76451
|
}
|
|
76192
|
-
function sameAppLineage(a, b) {
|
|
76193
|
-
return a === b || resolveTemplateId(a) === resolveTemplateId(b);
|
|
76194
|
-
}
|
|
76195
76452
|
function parseBool(v, fallback2) {
|
|
76196
76453
|
if (v === void 0) return fallback2;
|
|
76197
76454
|
if (Array.isArray(v)) return null;
|
|
@@ -76370,11 +76627,13 @@ function registerWorkspaceDataRoutes(app) {
|
|
|
76370
76627
|
const limit = parseIntParam(req.query.limit);
|
|
76371
76628
|
if (limit === null) return sendError(reply, 400, "invalid limit");
|
|
76372
76629
|
const q = optionalString(req.query.q);
|
|
76373
|
-
const
|
|
76374
|
-
if (!
|
|
76630
|
+
const generation = readCurrentGeneration(project.id);
|
|
76631
|
+
if (!generation) return { ok: true, generation: null, pages: [], total: 0, truncated: false };
|
|
76632
|
+
const wikiDir = generationWikiDir(project.id, generation.generationId);
|
|
76633
|
+
if (!(0, import_node_fs48.existsSync)(wikiDir)) return { ok: true, generation: null, pages: [], total: 0, truncated: false };
|
|
76375
76634
|
try {
|
|
76376
76635
|
const feed = readKnowledgeSummaries(wikiDir, { q, limit: limit ?? void 0 });
|
|
76377
|
-
return { ok: true, generation
|
|
76636
|
+
return { ok: true, generation, ...feed };
|
|
76378
76637
|
} catch (e) {
|
|
76379
76638
|
if (e instanceof KnowledgeError) return sendError(reply, knowledgeErrorStatus(e), e.message);
|
|
76380
76639
|
throw e;
|
|
@@ -76383,6 +76642,53 @@ function registerWorkspaceDataRoutes(app) {
|
|
|
76383
76642
|
);
|
|
76384
76643
|
}
|
|
76385
76644
|
|
|
76645
|
+
// app-id.ts
|
|
76646
|
+
var APP_ID4 = /^[a-z0-9][a-z0-9._-]*$/i;
|
|
76647
|
+
function isSafeAppId2(value) {
|
|
76648
|
+
return typeof value === "string" && APP_ID4.test(value) && safeSegment(value);
|
|
76649
|
+
}
|
|
76650
|
+
|
|
76651
|
+
// contract-request-route.ts
|
|
76652
|
+
function registerContractRequestRoute(app, deps) {
|
|
76653
|
+
app.post(
|
|
76654
|
+
"/api/contract-request",
|
|
76655
|
+
{ bodyLimit: 25 * 1024 * 1024 },
|
|
76656
|
+
async (req, reply) => {
|
|
76657
|
+
const { appId, project, instruction, intent, target, snapshots } = req.body ?? {};
|
|
76658
|
+
if (!isSafeAppId2(appId)) {
|
|
76659
|
+
return reply.status(400).send({ ok: false, error: "invalid appId" });
|
|
76660
|
+
}
|
|
76661
|
+
if (typeof instruction !== "string" || !instruction) {
|
|
76662
|
+
return reply.status(400).send({ ok: false, error: "instruction required" });
|
|
76663
|
+
}
|
|
76664
|
+
let projectId;
|
|
76665
|
+
let requestAppId = appId;
|
|
76666
|
+
if (project !== void 0) {
|
|
76667
|
+
if (!isProjectId(project)) return reply.status(400).send({ ok: false, error: "invalid project id" });
|
|
76668
|
+
const targetProject = getProject(project);
|
|
76669
|
+
if (!targetProject) return reply.status(404).send({ ok: false, error: `unknown project: ${project}` });
|
|
76670
|
+
if (!sameAppLineage(appId, targetProject.app)) {
|
|
76671
|
+
return reply.status(404).send({ ok: false, error: `project "${targetProject.id}" belongs to app "${targetProject.app}", not "${appId}"` });
|
|
76672
|
+
}
|
|
76673
|
+
projectId = targetProject.id;
|
|
76674
|
+
requestAppId = targetProject.app;
|
|
76675
|
+
}
|
|
76676
|
+
let decoded;
|
|
76677
|
+
try {
|
|
76678
|
+
decoded = decodeSnapshots(snapshots);
|
|
76679
|
+
} catch (e) {
|
|
76680
|
+
return reply.status(400).send({ ok: false, error: e instanceof Error ? e.message : "bad snapshot" });
|
|
76681
|
+
}
|
|
76682
|
+
const request = addRequest(
|
|
76683
|
+
{ type: "tweak-contract", appId: requestAppId, ...projectId ? { project: projectId } : {}, instruction, ...intent ? { intent } : {}, ...target ? { target } : {} },
|
|
76684
|
+
decoded
|
|
76685
|
+
);
|
|
76686
|
+
deps.broadcast({ type: "request-added", request });
|
|
76687
|
+
return { ok: true, request: deps.requestView(request) };
|
|
76688
|
+
}
|
|
76689
|
+
);
|
|
76690
|
+
}
|
|
76691
|
+
|
|
76386
76692
|
// project-publication-state.ts
|
|
76387
76693
|
function classifyProjectPublicationState(appId, liveProjects) {
|
|
76388
76694
|
return liveProjects.some((project) => project.app === appId) ? "project-publication" : "project-publication-missing-project";
|
|
@@ -76537,19 +76843,81 @@ function registerMigrationCommitRoute(app, deps) {
|
|
|
76537
76843
|
|
|
76538
76844
|
// workspace-agent-manifest.ts
|
|
76539
76845
|
var import_node_fs49 = require("node:fs");
|
|
76540
|
-
var
|
|
76541
|
-
var
|
|
76846
|
+
var import_node_os22 = require("node:os");
|
|
76847
|
+
var import_node_path44 = require("node:path");
|
|
76848
|
+
var WORKSPACE_MANIFEST_VERSION = "0.2.1";
|
|
76849
|
+
var OWNER_FILE = "floless-workspace.owner.json";
|
|
76542
76850
|
function awareHome() {
|
|
76543
|
-
return process.env.AWARE_HOME || (0,
|
|
76851
|
+
return process.env.AWARE_HOME || (0, import_node_path44.join)((0, import_node_os22.homedir)(), ".aware");
|
|
76544
76852
|
}
|
|
76545
76853
|
function workspaceAgentDir() {
|
|
76546
|
-
return (0,
|
|
76854
|
+
return (0, import_node_path44.join)(awareHome(), "agents", "floless-workspace");
|
|
76855
|
+
}
|
|
76856
|
+
function ownerPath2(dir) {
|
|
76857
|
+
return (0, import_node_path44.join)(dir, OWNER_FILE);
|
|
76858
|
+
}
|
|
76859
|
+
function readOwner2(path) {
|
|
76860
|
+
try {
|
|
76861
|
+
const parsed = JSON.parse((0, import_node_fs49.readFileSync)(path, "utf8"));
|
|
76862
|
+
if (Number.isSafeInteger(parsed.pid) && parsed.pid > 0 && Number.isSafeInteger(parsed.port) && parsed.port > 0 && parsed.port <= 65535 && typeof parsed.manifestVersion === "string" && parsed.manifestVersion.length > 0) return {
|
|
76863
|
+
pid: parsed.pid,
|
|
76864
|
+
port: parsed.port,
|
|
76865
|
+
manifestVersion: parsed.manifestVersion
|
|
76866
|
+
};
|
|
76867
|
+
} catch {
|
|
76868
|
+
}
|
|
76869
|
+
return null;
|
|
76870
|
+
}
|
|
76871
|
+
function processIsAlive(pid) {
|
|
76872
|
+
try {
|
|
76873
|
+
process.kill(pid, 0);
|
|
76874
|
+
return true;
|
|
76875
|
+
} catch (err2) {
|
|
76876
|
+
return err2.code === "EPERM";
|
|
76877
|
+
}
|
|
76547
76878
|
}
|
|
76548
|
-
function syncWorkspaceAgentManifest(port) {
|
|
76879
|
+
function syncWorkspaceAgentManifest(port, deps = {}) {
|
|
76549
76880
|
const dir = workspaceAgentDir();
|
|
76550
76881
|
(0, import_node_fs49.mkdirSync)(dir, { recursive: true });
|
|
76882
|
+
const ownPath = ownerPath2(dir);
|
|
76883
|
+
const pid = deps.pid ?? process.pid;
|
|
76884
|
+
const isAlive = deps.isProcessAlive ?? processIsAlive;
|
|
76885
|
+
const mine = { pid, port, manifestVersion: WORKSPACE_MANIFEST_VERSION };
|
|
76886
|
+
let previousOwner = null;
|
|
76887
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
76888
|
+
const current = readOwner2(ownPath);
|
|
76889
|
+
if (current && isAlive(current.pid)) {
|
|
76890
|
+
if (current.pid !== pid) {
|
|
76891
|
+
return { path: (0, import_node_path44.join)(dir, "manifest.yaml"), owner: current, outcome: "preserved-live-owner", previousOwner: current };
|
|
76892
|
+
}
|
|
76893
|
+
previousOwner = current;
|
|
76894
|
+
break;
|
|
76895
|
+
}
|
|
76896
|
+
previousOwner = current;
|
|
76897
|
+
if ((0, import_node_fs49.existsSync)(ownPath)) {
|
|
76898
|
+
try {
|
|
76899
|
+
(0, import_node_fs49.unlinkSync)(ownPath);
|
|
76900
|
+
} catch {
|
|
76901
|
+
continue;
|
|
76902
|
+
}
|
|
76903
|
+
}
|
|
76904
|
+
try {
|
|
76905
|
+
(0, import_node_fs49.writeFileSync)(ownPath, `${JSON.stringify(mine)}
|
|
76906
|
+
`, { encoding: "utf8", flag: "wx" });
|
|
76907
|
+
break;
|
|
76908
|
+
} catch (err2) {
|
|
76909
|
+
if (err2.code !== "EEXIST") throw err2;
|
|
76910
|
+
}
|
|
76911
|
+
}
|
|
76912
|
+
const claimed2 = readOwner2(ownPath);
|
|
76913
|
+
if (!claimed2 || claimed2.pid !== mine.pid || claimed2.port !== mine.port) {
|
|
76914
|
+
if (claimed2 && isAlive(claimed2.pid)) {
|
|
76915
|
+
return { path: (0, import_node_path44.join)(dir, "manifest.yaml"), owner: claimed2, outcome: "preserved-live-owner", previousOwner: claimed2 };
|
|
76916
|
+
}
|
|
76917
|
+
throw new Error("could not claim floless-workspace manifest ownership");
|
|
76918
|
+
}
|
|
76551
76919
|
const manifest = `agent: floless-workspace
|
|
76552
|
-
version:
|
|
76920
|
+
version: ${WORKSPACE_MANIFEST_VERSION}
|
|
76553
76921
|
sdk-target: 2.4.0
|
|
76554
76922
|
display-name: FloLess Workspace
|
|
76555
76923
|
description: |
|
|
@@ -76691,9 +77059,25 @@ commands:
|
|
|
76691
77059
|
headers: object
|
|
76692
77060
|
body: object
|
|
76693
77061
|
`;
|
|
76694
|
-
const path = (0,
|
|
76695
|
-
|
|
76696
|
-
|
|
77062
|
+
const path = (0, import_node_path44.join)(dir, "manifest.yaml");
|
|
77063
|
+
try {
|
|
77064
|
+
(0, import_node_fs49.writeFileSync)(path, manifest, "utf8");
|
|
77065
|
+
} catch (err2) {
|
|
77066
|
+
const current = readOwner2(ownPath);
|
|
77067
|
+
if (current?.pid === mine.pid && current.port === mine.port) {
|
|
77068
|
+
try {
|
|
77069
|
+
(0, import_node_fs49.unlinkSync)(ownPath);
|
|
77070
|
+
} catch {
|
|
77071
|
+
}
|
|
77072
|
+
}
|
|
77073
|
+
throw err2;
|
|
77074
|
+
}
|
|
77075
|
+
return {
|
|
77076
|
+
path,
|
|
77077
|
+
owner: mine,
|
|
77078
|
+
outcome: previousOwner ? "reclaimed-stale-owner" : "written",
|
|
77079
|
+
previousOwner
|
|
77080
|
+
};
|
|
76697
77081
|
}
|
|
76698
77082
|
|
|
76699
77083
|
// steel-diff.ts
|
|
@@ -78300,10 +78684,18 @@ function awareFailureMessage(e, fallback2) {
|
|
|
78300
78684
|
if (!message || INPUTS_TEMPFILE.test(message)) return fallback2;
|
|
78301
78685
|
return message;
|
|
78302
78686
|
}
|
|
78687
|
+
function agentUpdateFailureMessage(e, id) {
|
|
78688
|
+
const fallback2 = `Could not update \u201C${id}\u201D.`;
|
|
78689
|
+
const message = awareFailureMessage(e, fallback2);
|
|
78690
|
+
if (/^conflict:\s*agent\s+\S+\s+has version\s+.+?\s+installed,\s+which the registry does not publish\b/i.test(message)) {
|
|
78691
|
+
return `\u201C${id}\u201D is a local copy, so it was not replaced by the registry version. This protects any local changes. To replace it deliberately, run \u201Caware agent update ${id} --force\u201D in a terminal.`;
|
|
78692
|
+
}
|
|
78693
|
+
return message;
|
|
78694
|
+
}
|
|
78303
78695
|
|
|
78304
78696
|
// scene-bake.ts
|
|
78305
78697
|
var import_node_fs51 = require("node:fs");
|
|
78306
|
-
var
|
|
78698
|
+
var import_node_path45 = require("node:path");
|
|
78307
78699
|
var import_yaml9 = __toESM(require_dist6(), 1);
|
|
78308
78700
|
function bakeSceneIntoApp(sourcePath, scene, agent = "viewer-3d") {
|
|
78309
78701
|
const doc = (0, import_yaml9.parseDocument)((0, import_node_fs51.readFileSync)(sourcePath, "utf8"));
|
|
@@ -78331,7 +78723,7 @@ function bakeNodeConfigById(sourcePath, nodeId, patch2) {
|
|
|
78331
78723
|
}
|
|
78332
78724
|
function writeViewer3dApp(dir, appId, scene) {
|
|
78333
78725
|
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78334
|
-
const flo = (0,
|
|
78726
|
+
const flo = (0, import_node_path45.join)(dir, `${appId}.flo`);
|
|
78335
78727
|
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78336
78728
|
`app: ${appId}`,
|
|
78337
78729
|
"version: 0.1.0",
|
|
@@ -78362,7 +78754,7 @@ function isCompanionApp(flo) {
|
|
|
78362
78754
|
}
|
|
78363
78755
|
function writeBomReportApp(dir, appId, table) {
|
|
78364
78756
|
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78365
|
-
const flo = (0,
|
|
78757
|
+
const flo = (0, import_node_path45.join)(dir, `${appId}.flo`);
|
|
78366
78758
|
if (!isCompanionApp(flo)) {
|
|
78367
78759
|
throw new Error(`refusing to overwrite "${appId}": an app of that name exists and FloLess did not write it`);
|
|
78368
78760
|
}
|
|
@@ -78394,7 +78786,7 @@ function writeBomReportApp(dir, appId, table) {
|
|
|
78394
78786
|
}
|
|
78395
78787
|
function writeRevitApp(dir, appId, scene, hostPid, revitVersion = "2026") {
|
|
78396
78788
|
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78397
|
-
const flo = (0,
|
|
78789
|
+
const flo = (0, import_node_path45.join)(dir, `${appId}.flo`);
|
|
78398
78790
|
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78399
78791
|
`app: ${appId}`,
|
|
78400
78792
|
"version: 0.1.0",
|
|
@@ -78430,7 +78822,7 @@ function writeRevitApp(dir, appId, scene, hostPid, revitVersion = "2026") {
|
|
|
78430
78822
|
}
|
|
78431
78823
|
function writeSketchupApp(dir, appId, scene) {
|
|
78432
78824
|
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78433
|
-
const flo = (0,
|
|
78825
|
+
const flo = (0, import_node_path45.join)(dir, `${appId}.flo`);
|
|
78434
78826
|
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78435
78827
|
`app: ${appId}`,
|
|
78436
78828
|
"version: 0.1.0",
|
|
@@ -78459,7 +78851,7 @@ function writeSketchupApp(dir, appId, scene) {
|
|
|
78459
78851
|
}
|
|
78460
78852
|
function writeRhinoApp(dir, appId, scene, rhinoId, hostPid) {
|
|
78461
78853
|
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78462
|
-
const flo = (0,
|
|
78854
|
+
const flo = (0, import_node_path45.join)(dir, `${appId}.flo`);
|
|
78463
78855
|
const exactRhinoId = typeof rhinoId === "string" && rhinoId.trim() ? rhinoId.trim() : null;
|
|
78464
78856
|
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78465
78857
|
`app: ${appId}`,
|
|
@@ -78489,7 +78881,7 @@ function writeRhinoApp(dir, appId, scene, rhinoId, hostPid) {
|
|
|
78489
78881
|
}
|
|
78490
78882
|
function writeTeklaApp(dir, appId, scene, teklaVersion = "2026.0") {
|
|
78491
78883
|
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78492
|
-
const flo = (0,
|
|
78884
|
+
const flo = (0, import_node_path45.join)(dir, `${appId}.flo`);
|
|
78493
78885
|
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78494
78886
|
`app: ${appId}`,
|
|
78495
78887
|
"version: 0.1.0",
|
|
@@ -78655,7 +79047,7 @@ async function teklaVersionToBake() {
|
|
|
78655
79047
|
// export-companion.ts
|
|
78656
79048
|
var import_node_crypto30 = require("node:crypto");
|
|
78657
79049
|
var import_node_fs52 = require("node:fs");
|
|
78658
|
-
var
|
|
79050
|
+
var import_node_path46 = require("node:path");
|
|
78659
79051
|
var PREFIX = "floless-export-tmp-";
|
|
78660
79052
|
var LEASE = ".floless-export-lease.json";
|
|
78661
79053
|
var STALE_MS2 = 30 * 6e4;
|
|
@@ -78669,12 +79061,12 @@ function processAlive2(pid) {
|
|
|
78669
79061
|
}
|
|
78670
79062
|
}
|
|
78671
79063
|
function defaultAppsRoot() {
|
|
78672
|
-
return (0,
|
|
79064
|
+
return (0, import_node_path46.dirname)(appPath("placeholder"));
|
|
78673
79065
|
}
|
|
78674
79066
|
function assertScratchPath(path, appsRoot) {
|
|
78675
|
-
const root5 = (0,
|
|
78676
|
-
const target = (0,
|
|
78677
|
-
if ((0,
|
|
79067
|
+
const root5 = (0, import_node_path46.resolve)(appsRoot);
|
|
79068
|
+
const target = (0, import_node_path46.resolve)(path);
|
|
79069
|
+
if ((0, import_node_path46.dirname)(target) !== root5 || !(0, import_node_path46.basename)(target).startsWith(PREFIX)) {
|
|
78678
79070
|
throw new Error(`refusing to remove a non-export companion path: ${target}`);
|
|
78679
79071
|
}
|
|
78680
79072
|
}
|
|
@@ -78686,8 +79078,8 @@ function createExportCompanion(ownerId, sink, appsRoot = defaultAppsRoot()) {
|
|
|
78686
79078
|
const safeOwner = ownerId.replace(/[^a-z0-9._-]/gi, "-").slice(0, 80) || "app";
|
|
78687
79079
|
const token2 = (0, import_node_crypto30.randomUUID)();
|
|
78688
79080
|
const id = `${PREFIX}${safeOwner}-${sink}-${token2}`;
|
|
78689
|
-
const root5 = (0,
|
|
78690
|
-
const path = (0,
|
|
79081
|
+
const root5 = (0, import_node_path46.resolve)(appsRoot);
|
|
79082
|
+
const path = (0, import_node_path46.resolve)(root5, id);
|
|
78691
79083
|
return {
|
|
78692
79084
|
id,
|
|
78693
79085
|
path,
|
|
@@ -78696,7 +79088,7 @@ function createExportCompanion(ownerId, sink, appsRoot = defaultAppsRoot()) {
|
|
|
78696
79088
|
if (!(0, import_node_fs52.existsSync)(path)) return;
|
|
78697
79089
|
let current = null;
|
|
78698
79090
|
try {
|
|
78699
|
-
current = JSON.parse((0, import_node_fs52.readFileSync)((0,
|
|
79091
|
+
current = JSON.parse((0, import_node_fs52.readFileSync)((0, import_node_path46.resolve)(path, LEASE), "utf8"));
|
|
78700
79092
|
} catch {
|
|
78701
79093
|
}
|
|
78702
79094
|
if (current && current.token !== token2) throw new Error(`export companion lease changed for ${id}`);
|
|
@@ -78705,22 +79097,22 @@ function createExportCompanion(ownerId, sink, appsRoot = defaultAppsRoot()) {
|
|
|
78705
79097
|
};
|
|
78706
79098
|
}
|
|
78707
79099
|
function stampExportCompanionLease(companion2) {
|
|
78708
|
-
(0, import_node_fs52.writeFileSync)((0,
|
|
79100
|
+
(0, import_node_fs52.writeFileSync)((0, import_node_path46.resolve)(companion2.path, LEASE), JSON.stringify({
|
|
78709
79101
|
pid: process.pid,
|
|
78710
79102
|
token: companion2.token,
|
|
78711
79103
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
78712
79104
|
}));
|
|
78713
79105
|
}
|
|
78714
79106
|
function sweepStaleExportCompanions(now = Date.now(), appsRoot = defaultAppsRoot()) {
|
|
78715
|
-
const root5 = (0,
|
|
79107
|
+
const root5 = (0, import_node_path46.resolve)(appsRoot);
|
|
78716
79108
|
if (!(0, import_node_fs52.existsSync)(root5)) return [];
|
|
78717
79109
|
const removed = [];
|
|
78718
79110
|
for (const entry2 of (0, import_node_fs52.readdirSync)(root5, { withFileTypes: true })) {
|
|
78719
79111
|
if (!entry2.isDirectory() || !entry2.name.startsWith(PREFIX)) continue;
|
|
78720
|
-
const path = (0,
|
|
79112
|
+
const path = (0, import_node_path46.resolve)(root5, entry2.name);
|
|
78721
79113
|
let lease = null;
|
|
78722
79114
|
try {
|
|
78723
|
-
lease = JSON.parse((0, import_node_fs52.readFileSync)((0,
|
|
79115
|
+
lease = JSON.parse((0, import_node_fs52.readFileSync)((0, import_node_path46.resolve)(path, LEASE), "utf8"));
|
|
78724
79116
|
} catch {
|
|
78725
79117
|
}
|
|
78726
79118
|
let created;
|
|
@@ -79300,8 +79692,8 @@ function looksLikeHostUnavailable(host, ...messages) {
|
|
|
79300
79692
|
|
|
79301
79693
|
// render-readiness.ts
|
|
79302
79694
|
var import_node_fs53 = require("node:fs");
|
|
79303
|
-
var
|
|
79304
|
-
var
|
|
79695
|
+
var import_node_path47 = require("node:path");
|
|
79696
|
+
var import_node_os23 = require("node:os");
|
|
79305
79697
|
var RENDER_AWARE_FLOOR = "0.103.0";
|
|
79306
79698
|
var RENDER_AGENT_ID = "blender";
|
|
79307
79699
|
function isFile(path) {
|
|
@@ -79314,9 +79706,9 @@ function isFile(path) {
|
|
|
79314
79706
|
function lookupOnPath(command, env2) {
|
|
79315
79707
|
const path = env2.PATH ?? env2.Path;
|
|
79316
79708
|
if (!path) return null;
|
|
79317
|
-
for (const dir of path.split(
|
|
79709
|
+
for (const dir of path.split(import_node_path47.delimiter)) {
|
|
79318
79710
|
if (!dir) continue;
|
|
79319
|
-
const candidate = (0,
|
|
79711
|
+
const candidate = (0, import_node_path47.join)(dir, command);
|
|
79320
79712
|
if (isFile(candidate)) return candidate;
|
|
79321
79713
|
}
|
|
79322
79714
|
return null;
|
|
@@ -79333,7 +79725,7 @@ function windowsCandidates(env2) {
|
|
|
79333
79725
|
for (const variable of ["ProgramFiles", "ProgramW6432", "ProgramFiles(x86)"]) {
|
|
79334
79726
|
const value = env2[variable];
|
|
79335
79727
|
if (!value) continue;
|
|
79336
|
-
const root5 = (0,
|
|
79728
|
+
const root5 = (0, import_node_path47.join)(value, "Blender Foundation");
|
|
79337
79729
|
if (!roots.includes(root5)) roots.push(root5);
|
|
79338
79730
|
}
|
|
79339
79731
|
const found = [];
|
|
@@ -79347,7 +79739,7 @@ function windowsCandidates(env2) {
|
|
|
79347
79739
|
for (const name of entries2) {
|
|
79348
79740
|
const match = /^Blender\s+(\d+(?:\.\d+)*)$/i.exec(name);
|
|
79349
79741
|
if (!match) continue;
|
|
79350
|
-
const binary = (0,
|
|
79742
|
+
const binary = (0, import_node_path47.join)(root5, name, "blender.exe");
|
|
79351
79743
|
if (isFile(binary)) {
|
|
79352
79744
|
found.push({ version: match[1].split(".").map(Number), name, binary });
|
|
79353
79745
|
}
|
|
@@ -79361,7 +79753,7 @@ function platformDefaults(env2, isWin3) {
|
|
|
79361
79753
|
if (process.platform === "darwin") {
|
|
79362
79754
|
return [
|
|
79363
79755
|
"/Applications/Blender.app/Contents/MacOS/Blender",
|
|
79364
|
-
(0,
|
|
79756
|
+
(0, import_node_path47.join)((0, import_node_os23.homedir)(), "Applications/Blender.app/Contents/MacOS/Blender")
|
|
79365
79757
|
];
|
|
79366
79758
|
}
|
|
79367
79759
|
return ["/usr/bin/blender", "/usr/local/bin/blender", "/snap/bin/blender"];
|
|
@@ -79519,20 +79911,20 @@ function nothingToApprove(contract) {
|
|
|
79519
79911
|
}
|
|
79520
79912
|
|
|
79521
79913
|
// app-lifecycle.ts
|
|
79522
|
-
var
|
|
79523
|
-
var
|
|
79524
|
-
var
|
|
79914
|
+
var import_node_fs57 = require("node:fs");
|
|
79915
|
+
var import_node_os26 = require("node:os");
|
|
79916
|
+
var import_node_path51 = require("node:path");
|
|
79525
79917
|
|
|
79526
79918
|
// routines.ts
|
|
79527
79919
|
var import_node_fs55 = require("node:fs");
|
|
79528
|
-
var
|
|
79920
|
+
var import_node_path49 = require("node:path");
|
|
79529
79921
|
|
|
79530
79922
|
// trigger-sessions.ts
|
|
79531
79923
|
var import_node_fs54 = require("node:fs");
|
|
79532
|
-
var
|
|
79533
|
-
var
|
|
79924
|
+
var import_node_os24 = require("node:os");
|
|
79925
|
+
var import_node_path48 = require("node:path");
|
|
79534
79926
|
var import_yaml10 = __toESM(require_dist6(), 1);
|
|
79535
|
-
var AGENTS_DIR2 = process.env.AWARE_HOME ? (0,
|
|
79927
|
+
var AGENTS_DIR2 = process.env.AWARE_HOME ? (0, import_node_path48.join)(process.env.AWARE_HOME, "agents") : (0, import_node_path48.join)((0, import_node_os24.homedir)(), ".aware", "agents");
|
|
79536
79928
|
function summarizeFire(data) {
|
|
79537
79929
|
if (!data) return "event";
|
|
79538
79930
|
const type = typeof data.type === "string" ? data.type : "";
|
|
@@ -79549,7 +79941,7 @@ function mapTriggerState(phase) {
|
|
|
79549
79941
|
function isHostBacked(agent, agentsDir = AGENTS_DIR2) {
|
|
79550
79942
|
const safe2 = (n) => !n.includes("/") && !n.includes("\\") && !n.includes("..");
|
|
79551
79943
|
if (!safe2(agent)) return false;
|
|
79552
|
-
const manifestPath2 = (0,
|
|
79944
|
+
const manifestPath2 = (0, import_node_path48.join)(agentsDir, agent, "manifest.yaml");
|
|
79553
79945
|
if (!(0, import_node_fs54.existsSync)(manifestPath2)) return false;
|
|
79554
79946
|
try {
|
|
79555
79947
|
const doc = (0, import_yaml10.parse)((0, import_node_fs54.readFileSync)(manifestPath2, "utf8"));
|
|
@@ -79860,7 +80252,7 @@ var RoutineError = class extends Error {
|
|
|
79860
80252
|
}
|
|
79861
80253
|
status;
|
|
79862
80254
|
};
|
|
79863
|
-
var ROUTINES_FILE = (0,
|
|
80255
|
+
var ROUTINES_FILE = (0, import_node_path49.join)(flolessRoot, "routines.json");
|
|
79864
80256
|
var routines = [];
|
|
79865
80257
|
var loaded = false;
|
|
79866
80258
|
function ensureLoaded() {
|
|
@@ -80327,8 +80719,184 @@ async function stopScheduler() {
|
|
|
80327
80719
|
await stopAllSessions();
|
|
80328
80720
|
}
|
|
80329
80721
|
|
|
80722
|
+
// kb-pin-store.ts
|
|
80723
|
+
var import_node_fs56 = require("node:fs");
|
|
80724
|
+
var import_node_path50 = require("node:path");
|
|
80725
|
+
var import_node_os25 = require("node:os");
|
|
80726
|
+
var KbPinError = class extends Error {
|
|
80727
|
+
code;
|
|
80728
|
+
constructor(message, code) {
|
|
80729
|
+
super(message);
|
|
80730
|
+
this.name = "KbPinError";
|
|
80731
|
+
this.code = code;
|
|
80732
|
+
}
|
|
80733
|
+
};
|
|
80734
|
+
var pinsDir = () => (0, import_node_path50.join)(process.env.FLOLESS_HOME ?? (0, import_node_path50.join)((0, import_node_os25.homedir)(), ".floless"), "kb-pins");
|
|
80735
|
+
var withPinLock = (fn) => withLifecycleLock("internal-export", "kb-pin-store", fn);
|
|
80736
|
+
var KB_PIN_MAX_PAGES = 20;
|
|
80737
|
+
var KB_PIN_MAX_TITLE = 200;
|
|
80738
|
+
var ISO_RE = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;
|
|
80739
|
+
var isIsoTimestamp = (v) => {
|
|
80740
|
+
if (typeof v !== "string") return false;
|
|
80741
|
+
const m = ISO_RE.exec(v);
|
|
80742
|
+
if (!m) return false;
|
|
80743
|
+
const year = Number(m[1]);
|
|
80744
|
+
const month = Number(m[2]);
|
|
80745
|
+
const day2 = Number(m[3]);
|
|
80746
|
+
const hour2 = Number(m[4]);
|
|
80747
|
+
const minute = Number(m[5]);
|
|
80748
|
+
const second = Number(m[6]);
|
|
80749
|
+
const millis = Number((m[7] ?? "").padEnd(3, "0"));
|
|
80750
|
+
const offsetHour = Number(m[9] ?? 0);
|
|
80751
|
+
const offsetMinute = Number(m[10] ?? 0);
|
|
80752
|
+
if (offsetHour > 23 || offsetMinute > 59) return false;
|
|
80753
|
+
const calendar = /* @__PURE__ */ new Date(0);
|
|
80754
|
+
calendar.setUTCFullYear(year, month - 1, day2);
|
|
80755
|
+
calendar.setUTCHours(hour2, minute, second, millis);
|
|
80756
|
+
return calendar.getUTCFullYear() === year && calendar.getUTCMonth() === month - 1 && calendar.getUTCDate() === day2 && calendar.getUTCHours() === hour2 && calendar.getUTCMinutes() === minute && calendar.getUTCSeconds() === second && Number.isFinite(Date.parse(v));
|
|
80757
|
+
};
|
|
80758
|
+
function safeAppId(appId) {
|
|
80759
|
+
if (typeof appId !== "string" || !/^[a-z0-9][a-z0-9._-]*$/i.test(appId)) {
|
|
80760
|
+
throw new KbPinError(`invalid appId: ${String(appId)}`, "invalid-app");
|
|
80761
|
+
}
|
|
80762
|
+
return appId;
|
|
80763
|
+
}
|
|
80764
|
+
var isProjectId2 = (v) => typeof v === "string" && /^[a-z0-9][a-z0-9-]*$/.test(v);
|
|
80765
|
+
var pinPath = (appId) => (0, import_node_path50.join)(pinsDir(), `${safeAppId(appId)}.json`);
|
|
80766
|
+
function assertAppId(appId) {
|
|
80767
|
+
safeAppId(appId);
|
|
80768
|
+
}
|
|
80769
|
+
function normalizePages(pages) {
|
|
80770
|
+
if (!Array.isArray(pages)) throw new KbPinError("pages must be an array", "invalid-pages");
|
|
80771
|
+
if (pages.length > KB_PIN_MAX_PAGES) {
|
|
80772
|
+
throw new KbPinError(`pages must be at most ${KB_PIN_MAX_PAGES} entries`, "invalid-pages");
|
|
80773
|
+
}
|
|
80774
|
+
const seen = /* @__PURE__ */ new Set();
|
|
80775
|
+
const out = [];
|
|
80776
|
+
for (const page of pages) {
|
|
80777
|
+
const p = page;
|
|
80778
|
+
if (!p || typeof p !== "object") throw new KbPinError("each page must be an object", "invalid-pages");
|
|
80779
|
+
if (!isWikiSlug(p.slug)) throw new KbPinError(`invalid page slug: ${String(p.slug)}`, "invalid-pages");
|
|
80780
|
+
if (typeof p.title !== "string" || p.title.length > KB_PIN_MAX_TITLE) {
|
|
80781
|
+
throw new KbPinError(`invalid page title for "${p.slug}"`, "invalid-pages");
|
|
80782
|
+
}
|
|
80783
|
+
if (seen.has(p.slug)) continue;
|
|
80784
|
+
seen.add(p.slug);
|
|
80785
|
+
out.push({ slug: p.slug, title: p.title });
|
|
80786
|
+
}
|
|
80787
|
+
return out;
|
|
80788
|
+
}
|
|
80789
|
+
function readPinUnlocked(appId) {
|
|
80790
|
+
const p = pinPath(appId);
|
|
80791
|
+
if (!(0, import_node_fs56.existsSync)(p)) return null;
|
|
80792
|
+
try {
|
|
80793
|
+
const parsed = JSON.parse((0, import_node_fs56.readFileSync)(p, "utf8"));
|
|
80794
|
+
if (!parsed || typeof parsed !== "object") {
|
|
80795
|
+
console.warn(`kb-pin-store: ignoring schema-invalid pin at ${p} (not an object)`);
|
|
80796
|
+
return null;
|
|
80797
|
+
}
|
|
80798
|
+
if (!isProjectId2(parsed.projectId) || !isGenerationId(parsed.generationId) || !isIsoTimestamp(parsed.pinnedAt)) {
|
|
80799
|
+
console.warn(`kb-pin-store: ignoring schema-invalid pin at ${p} (bad projectId/generationId/pinnedAt)`);
|
|
80800
|
+
return null;
|
|
80801
|
+
}
|
|
80802
|
+
let pages;
|
|
80803
|
+
try {
|
|
80804
|
+
pages = normalizePages(parsed.pages);
|
|
80805
|
+
} catch (e) {
|
|
80806
|
+
console.warn(`kb-pin-store: ignoring schema-invalid pin at ${p}: ${e instanceof Error ? e.message : e}`);
|
|
80807
|
+
return null;
|
|
80808
|
+
}
|
|
80809
|
+
return { projectId: parsed.projectId, generationId: parsed.generationId, pinnedAt: parsed.pinnedAt, pages };
|
|
80810
|
+
} catch (e) {
|
|
80811
|
+
console.warn(`kb-pin-store: ignoring unreadable pin at ${p}: ${e instanceof Error ? e.message : e}`);
|
|
80812
|
+
return null;
|
|
80813
|
+
}
|
|
80814
|
+
}
|
|
80815
|
+
function readPin(appId) {
|
|
80816
|
+
return withPinLock(() => readPinUnlocked(appId));
|
|
80817
|
+
}
|
|
80818
|
+
function writePinUnlocked(appId, pin) {
|
|
80819
|
+
const p = pinPath(appId);
|
|
80820
|
+
if (!isProjectId2(pin.projectId)) {
|
|
80821
|
+
throw new KbPinError(`invalid project id: ${String(pin.projectId)}`, "invalid-project");
|
|
80822
|
+
}
|
|
80823
|
+
if (!isGenerationId(pin.generationId)) {
|
|
80824
|
+
throw new KbPinError(`invalid generation id: ${String(pin.generationId)}`, "invalid-generation");
|
|
80825
|
+
}
|
|
80826
|
+
const doc = {
|
|
80827
|
+
projectId: pin.projectId,
|
|
80828
|
+
generationId: pin.generationId,
|
|
80829
|
+
pinnedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
80830
|
+
pages: normalizePages(pin.pages)
|
|
80831
|
+
};
|
|
80832
|
+
(0, import_node_fs56.mkdirSync)((0, import_node_path50.dirname)(p), { recursive: true });
|
|
80833
|
+
writeJsonAtomic(p, doc);
|
|
80834
|
+
return doc;
|
|
80835
|
+
}
|
|
80836
|
+
function writePin(appId, pin) {
|
|
80837
|
+
return withPinLock(() => writePinUnlocked(appId, pin));
|
|
80838
|
+
}
|
|
80839
|
+
function movePinBytesUnlocked(fromAppId, toAppId) {
|
|
80840
|
+
const from = pinPath(fromAppId);
|
|
80841
|
+
const to = pinPath(toAppId);
|
|
80842
|
+
if (from === to || !(0, import_node_fs56.existsSync)(from)) return false;
|
|
80843
|
+
(0, import_node_fs56.mkdirSync)((0, import_node_path50.dirname)(to), { recursive: true });
|
|
80844
|
+
(0, import_node_fs56.renameSync)(from, to);
|
|
80845
|
+
return true;
|
|
80846
|
+
}
|
|
80847
|
+
function movePinBytes(fromAppId, toAppId) {
|
|
80848
|
+
return withPinLock(() => movePinBytesUnlocked(fromAppId, toAppId));
|
|
80849
|
+
}
|
|
80850
|
+
function dropPinBytesUnlocked(appId) {
|
|
80851
|
+
const p = pinPath(appId);
|
|
80852
|
+
if (!(0, import_node_fs56.existsSync)(p)) return false;
|
|
80853
|
+
(0, import_node_fs56.rmSync)(p, { force: true });
|
|
80854
|
+
return true;
|
|
80855
|
+
}
|
|
80856
|
+
function dropPinBytes(appId) {
|
|
80857
|
+
return withPinLock(() => dropPinBytesUnlocked(appId));
|
|
80858
|
+
}
|
|
80859
|
+
function repointProjectPinsUnlocked(fromProjectId, toProjectId) {
|
|
80860
|
+
if (!isProjectId2(fromProjectId) || !isProjectId2(toProjectId)) {
|
|
80861
|
+
throw new KbPinError("invalid project id for pin repoint", "invalid-project");
|
|
80862
|
+
}
|
|
80863
|
+
if (fromProjectId === toProjectId || !(0, import_node_fs56.existsSync)(pinsDir())) return 0;
|
|
80864
|
+
const targets = [];
|
|
80865
|
+
for (const entry2 of (0, import_node_fs56.readdirSync)(pinsDir(), { withFileTypes: true })) {
|
|
80866
|
+
if (!entry2.isFile() || !entry2.name.endsWith(".json")) continue;
|
|
80867
|
+
const appId = (0, import_node_path50.basename)(entry2.name, ".json");
|
|
80868
|
+
let pin;
|
|
80869
|
+
try {
|
|
80870
|
+
pin = readPinUnlocked(appId);
|
|
80871
|
+
} catch {
|
|
80872
|
+
continue;
|
|
80873
|
+
}
|
|
80874
|
+
if (!pin || pin.projectId !== fromProjectId) continue;
|
|
80875
|
+
targets.push({ path: pinPath(appId), pin });
|
|
80876
|
+
}
|
|
80877
|
+
const written = [];
|
|
80878
|
+
try {
|
|
80879
|
+
for (const target of targets) {
|
|
80880
|
+
writeJsonAtomic(target.path, { ...target.pin, projectId: toProjectId });
|
|
80881
|
+
written.push(target);
|
|
80882
|
+
}
|
|
80883
|
+
} catch (e) {
|
|
80884
|
+
for (const target of written.reverse()) {
|
|
80885
|
+
try {
|
|
80886
|
+
writeJsonAtomic(target.path, target.pin);
|
|
80887
|
+
} catch {
|
|
80888
|
+
}
|
|
80889
|
+
}
|
|
80890
|
+
throw e;
|
|
80891
|
+
}
|
|
80892
|
+
return targets.length;
|
|
80893
|
+
}
|
|
80894
|
+
function repointProjectPins(fromProjectId, toProjectId) {
|
|
80895
|
+
return withPinLock(() => repointProjectPinsUnlocked(fromProjectId, toProjectId));
|
|
80896
|
+
}
|
|
80897
|
+
|
|
80330
80898
|
// app-lifecycle.ts
|
|
80331
|
-
var
|
|
80899
|
+
var APP_ID5 = /^[a-z0-9][a-z0-9._-]*$/i;
|
|
80332
80900
|
var AppLifecycleError = class extends Error {
|
|
80333
80901
|
status;
|
|
80334
80902
|
constructor(message, status) {
|
|
@@ -80338,17 +80906,27 @@ var AppLifecycleError = class extends Error {
|
|
|
80338
80906
|
}
|
|
80339
80907
|
};
|
|
80340
80908
|
function appsDir() {
|
|
80341
|
-
return process.env.AWARE_HOME ? (0,
|
|
80909
|
+
return process.env.AWARE_HOME ? (0, import_node_path51.join)(process.env.AWARE_HOME, "apps") : (0, import_node_path51.join)((0, import_node_os26.homedir)(), ".aware", "apps");
|
|
80342
80910
|
}
|
|
80343
80911
|
function appDirPath(id) {
|
|
80344
|
-
return (0,
|
|
80912
|
+
return (0, import_node_path51.join)(appsDir(), id);
|
|
80345
80913
|
}
|
|
80346
80914
|
function appInstalled(id) {
|
|
80347
|
-
return
|
|
80915
|
+
return APP_ID5.test(id) && (0, import_node_fs57.existsSync)(appDirPath(id));
|
|
80348
80916
|
}
|
|
80349
80917
|
function logCascade(what, e) {
|
|
80350
80918
|
console.error(`[app-lifecycle] cascade step failed (${what}):`, e instanceof Error ? e.message : e);
|
|
80351
80919
|
}
|
|
80920
|
+
async function clearDestinationPin(newId) {
|
|
80921
|
+
try {
|
|
80922
|
+
await dropPinBytes(newId);
|
|
80923
|
+
} catch (e) {
|
|
80924
|
+
throw new AppLifecycleError(
|
|
80925
|
+
`could not clear stale knowledge provenance for "${newId}": ${e instanceof Error ? e.message : String(e)}`,
|
|
80926
|
+
500
|
|
80927
|
+
);
|
|
80928
|
+
}
|
|
80929
|
+
}
|
|
80352
80930
|
function mapAwareError(e) {
|
|
80353
80931
|
const code = e instanceof AwareError ? e.detail?.code : void 0;
|
|
80354
80932
|
if (code === 8) throw new AppLifecycleError("a workflow with that name already exists", 409);
|
|
@@ -80357,7 +80935,7 @@ function mapAwareError(e) {
|
|
|
80357
80935
|
throw e;
|
|
80358
80936
|
}
|
|
80359
80937
|
function assertNewId(newId) {
|
|
80360
|
-
if (!newId || !
|
|
80938
|
+
if (!newId || !APP_ID5.test(newId) || !safeSegment(newId)) {
|
|
80361
80939
|
throw new AppLifecycleError('name must be letters, digits, dot, dash or underscore (no spaces, slashes or "..")', 400);
|
|
80362
80940
|
}
|
|
80363
80941
|
}
|
|
@@ -80371,6 +80949,7 @@ async function renameApp(oldId, newId, deps = defaultDeps2) {
|
|
|
80371
80949
|
assertNewId(newId);
|
|
80372
80950
|
if (newId === oldId) throw new AppLifecycleError("that is already its name", 400);
|
|
80373
80951
|
if (appInstalled(newId)) throw new AppLifecycleError(`a workflow named "${newId}" already exists`, 409);
|
|
80952
|
+
await clearDestinationPin(newId);
|
|
80374
80953
|
const originRenameToken = await beginOriginRename(oldId, newId);
|
|
80375
80954
|
let compiled;
|
|
80376
80955
|
let originCompleted = false;
|
|
@@ -80425,6 +81004,11 @@ async function renameApp(oldId, newId, deps = defaultDeps2) {
|
|
|
80425
81004
|
} catch (e) {
|
|
80426
81005
|
logCascade("move contract", e);
|
|
80427
81006
|
}
|
|
81007
|
+
try {
|
|
81008
|
+
await movePinBytes(oldId, newId);
|
|
81009
|
+
} catch (e) {
|
|
81010
|
+
logCascade("move knowledge pin", e);
|
|
81011
|
+
}
|
|
80428
81012
|
let projectsStale;
|
|
80429
81013
|
try {
|
|
80430
81014
|
projectsStale = repointProjects(oldId, newId).skipped.length;
|
|
@@ -80438,6 +81022,7 @@ async function duplicateApp(srcId, newId, deps = defaultDeps2) {
|
|
|
80438
81022
|
if (!appInstalled(srcId)) throw new AppLifecycleError(`workflow not found: ${srcId}`, 404);
|
|
80439
81023
|
assertNewId(newId);
|
|
80440
81024
|
if (appInstalled(newId)) throw new AppLifecycleError(`a workflow named "${newId}" already exists`, 409);
|
|
81025
|
+
await clearDestinationPin(newId);
|
|
80441
81026
|
const originDuplicateToken = await beginOriginDuplicate(srcId, newId);
|
|
80442
81027
|
let compiled;
|
|
80443
81028
|
let originCompleted = false;
|
|
@@ -80528,6 +81113,80 @@ async function deleteApp(id, deps = defaultDeps2) {
|
|
|
80528
81113
|
} catch (e) {
|
|
80529
81114
|
logCascade("drop contract", e);
|
|
80530
81115
|
}
|
|
81116
|
+
try {
|
|
81117
|
+
await dropPinBytes(id);
|
|
81118
|
+
} catch (e) {
|
|
81119
|
+
logCascade("drop knowledge pin", e);
|
|
81120
|
+
}
|
|
81121
|
+
}
|
|
81122
|
+
|
|
81123
|
+
// kb-pin-routes.ts
|
|
81124
|
+
var import_node_fs58 = require("node:fs");
|
|
81125
|
+
function driftOf(pin) {
|
|
81126
|
+
const cur = readCurrentGeneration(pin.projectId);
|
|
81127
|
+
if (cur === null) return true;
|
|
81128
|
+
if (!(0, import_node_fs58.existsSync)(generationWikiDir(pin.projectId, cur.generationId))) return true;
|
|
81129
|
+
return cur.generationId !== pin.generationId;
|
|
81130
|
+
}
|
|
81131
|
+
function registerKbPinRoutes(app, deps) {
|
|
81132
|
+
app.get("/api/kb-pin/:appId", async (req, reply) => {
|
|
81133
|
+
try {
|
|
81134
|
+
const pin = await readPin(req.params.appId);
|
|
81135
|
+
return { ok: true, pin, drift: pin === null ? false : driftOf(pin) };
|
|
81136
|
+
} catch (e) {
|
|
81137
|
+
return sendError2(reply, e);
|
|
81138
|
+
}
|
|
81139
|
+
});
|
|
81140
|
+
app.put(
|
|
81141
|
+
"/api/kb-pin/:appId",
|
|
81142
|
+
async (req, reply) => {
|
|
81143
|
+
try {
|
|
81144
|
+
const { appId } = req.params;
|
|
81145
|
+
assertAppId(appId);
|
|
81146
|
+
const body = req.body ?? {};
|
|
81147
|
+
if (typeof body.projectId !== "string") {
|
|
81148
|
+
return reply.status(400).send({ ok: false, error: "projectId must be a string", code: "invalid-body" });
|
|
81149
|
+
}
|
|
81150
|
+
if (typeof body.generationId !== "string") {
|
|
81151
|
+
return reply.status(400).send({ ok: false, error: "generationId must be a string", code: "invalid-body" });
|
|
81152
|
+
}
|
|
81153
|
+
const projectId = body.projectId;
|
|
81154
|
+
const generationId = body.generationId;
|
|
81155
|
+
return await withLifecycleLock("app", appId, async () => {
|
|
81156
|
+
if (!appInstalled(appId)) {
|
|
81157
|
+
return reply.status(404).send({ ok: false, error: `unknown workflow: ${appId}`, code: "unknown-app" });
|
|
81158
|
+
}
|
|
81159
|
+
getProject(projectId);
|
|
81160
|
+
return withLifecycleLock("project", projectId, async () => {
|
|
81161
|
+
const project = getProject(projectId);
|
|
81162
|
+
if (!project) {
|
|
81163
|
+
return reply.status(404).send({ ok: false, error: `unknown project: ${projectId}`, code: "unknown-project" });
|
|
81164
|
+
}
|
|
81165
|
+
if (!sameAppLineage(appId, project.app)) {
|
|
81166
|
+
return reply.status(404).send({
|
|
81167
|
+
ok: false,
|
|
81168
|
+
error: `project ${projectId} does not belong to workflow ${appId}`,
|
|
81169
|
+
code: "project-app-mismatch"
|
|
81170
|
+
});
|
|
81171
|
+
}
|
|
81172
|
+
const pin = await writePin(appId, { projectId, generationId, pages: body.pages });
|
|
81173
|
+
deps.broadcast({ type: "kb-pin-changed", id: appId });
|
|
81174
|
+
return { ok: true, pin, drift: driftOf(pin) };
|
|
81175
|
+
});
|
|
81176
|
+
});
|
|
81177
|
+
} catch (e) {
|
|
81178
|
+
return sendError2(reply, e);
|
|
81179
|
+
}
|
|
81180
|
+
}
|
|
81181
|
+
);
|
|
81182
|
+
}
|
|
81183
|
+
function sendError2(reply, e) {
|
|
81184
|
+
if (e instanceof KbPinError) return reply.status(400).send({ ok: false, error: e.message, code: e.code });
|
|
81185
|
+
if (e instanceof ProjectError) return reply.status(400).send({ ok: false, error: e.message, code: "invalid-project" });
|
|
81186
|
+
if (e instanceof KnowledgeError) {
|
|
81187
|
+
return reply.status(knowledgeErrorStatus(e)).send({ ok: false, error: e.message, code: e.code ?? "invalid-generation" });
|
|
81188
|
+
}
|
|
81189
|
+
throw e;
|
|
80531
81190
|
}
|
|
80532
81191
|
|
|
80533
81192
|
// route-gate.ts
|
|
@@ -80582,9 +81241,9 @@ function isGatedAwareRoute(url, method) {
|
|
|
80582
81241
|
|
|
80583
81242
|
// autostart.mjs
|
|
80584
81243
|
var import_node_child_process8 = require("node:child_process");
|
|
80585
|
-
var
|
|
80586
|
-
var
|
|
80587
|
-
var
|
|
81244
|
+
var import_node_fs59 = require("node:fs");
|
|
81245
|
+
var import_node_os27 = require("node:os");
|
|
81246
|
+
var import_node_path52 = require("node:path");
|
|
80588
81247
|
|
|
80589
81248
|
// teardown.mjs
|
|
80590
81249
|
var RUN_KEY = "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
|
@@ -80696,8 +81355,8 @@ function removeLegacyRunKey() {
|
|
|
80696
81355
|
}
|
|
80697
81356
|
function logLine(msg) {
|
|
80698
81357
|
try {
|
|
80699
|
-
(0,
|
|
80700
|
-
(0,
|
|
81358
|
+
(0, import_node_fs59.mkdirSync)(logDir(), { recursive: true });
|
|
81359
|
+
(0, import_node_fs59.appendFileSync)(logFilePath(), `${(/* @__PURE__ */ new Date()).toISOString()} ${msg}
|
|
80701
81360
|
`);
|
|
80702
81361
|
} catch {
|
|
80703
81362
|
}
|
|
@@ -80705,8 +81364,8 @@ function logLine(msg) {
|
|
|
80705
81364
|
function registerAutostart(exePath) {
|
|
80706
81365
|
if (!isWin) return;
|
|
80707
81366
|
const xml = buildAutostartTaskXml(exePath, currentUserId());
|
|
80708
|
-
const tmp = (0,
|
|
80709
|
-
(0,
|
|
81367
|
+
const tmp = (0, import_node_path52.join)((0, import_node_os27.tmpdir)(), `floless-autostart-${process.pid}-${Date.now()}.xml`);
|
|
81368
|
+
(0, import_node_fs59.writeFileSync)(tmp, "\uFEFF" + xml, { encoding: "utf16le" });
|
|
80710
81369
|
try {
|
|
80711
81370
|
(0, import_node_child_process8.execFileSync)("schtasks", ["/Create", "/TN", TASK_NAME, "/XML", tmp, "/F"], {
|
|
80712
81371
|
stdio: ["ignore", "ignore", "ignore"],
|
|
@@ -80717,7 +81376,7 @@ function registerAutostart(exePath) {
|
|
|
80717
81376
|
throw err2;
|
|
80718
81377
|
} finally {
|
|
80719
81378
|
try {
|
|
80720
|
-
(0,
|
|
81379
|
+
(0, import_node_fs59.rmSync)(tmp, { force: true });
|
|
80721
81380
|
} catch {
|
|
80722
81381
|
}
|
|
80723
81382
|
}
|
|
@@ -80752,26 +81411,26 @@ function unregisterAutostart() {
|
|
|
80752
81411
|
// updater.ts
|
|
80753
81412
|
var import_node_child_process9 = require("node:child_process");
|
|
80754
81413
|
var import_node_crypto31 = require("node:crypto");
|
|
80755
|
-
var
|
|
81414
|
+
var import_node_fs61 = require("node:fs");
|
|
80756
81415
|
var import_node_stream3 = require("node:stream");
|
|
80757
81416
|
var import_promises5 = require("node:stream/promises");
|
|
80758
|
-
var
|
|
81417
|
+
var import_node_path54 = require("node:path");
|
|
80759
81418
|
|
|
80760
81419
|
// post-update-marker.mjs
|
|
80761
|
-
var
|
|
80762
|
-
var
|
|
80763
|
-
var
|
|
81420
|
+
var import_node_fs60 = require("node:fs");
|
|
81421
|
+
var import_node_os28 = require("node:os");
|
|
81422
|
+
var import_node_path53 = require("node:path");
|
|
80764
81423
|
var FRESH_MS = 12e4;
|
|
80765
81424
|
function markerPath() {
|
|
80766
81425
|
const override = (process.env.FLOLESS_POST_UPDATE_MARKER ?? "").trim();
|
|
80767
81426
|
if (override) return override;
|
|
80768
|
-
const root5 = process.env.FLOLESS_HOME ?? (0,
|
|
80769
|
-
return (0,
|
|
81427
|
+
const root5 = process.env.FLOLESS_HOME ?? (0, import_node_path53.join)((0, import_node_os28.homedir)(), ".floless");
|
|
81428
|
+
return (0, import_node_path53.join)(root5, ".post-update");
|
|
80770
81429
|
}
|
|
80771
81430
|
function legacyMarkerPath() {
|
|
80772
81431
|
if ((process.env.FLOLESS_POST_UPDATE_MARKER ?? "").trim()) return null;
|
|
80773
81432
|
try {
|
|
80774
|
-
return (0,
|
|
81433
|
+
return (0, import_node_path53.join)((0, import_node_path53.dirname)((0, import_node_path53.dirname)(process.execPath)), ".floless-post-update");
|
|
80775
81434
|
} catch {
|
|
80776
81435
|
return null;
|
|
80777
81436
|
}
|
|
@@ -80781,7 +81440,7 @@ function writePostUpdateMarker() {
|
|
|
80781
81440
|
for (const p of [markerPath(), legacyMarkerPath()]) {
|
|
80782
81441
|
if (!p) continue;
|
|
80783
81442
|
try {
|
|
80784
|
-
(0,
|
|
81443
|
+
(0, import_node_fs60.writeFileSync)(p, (/* @__PURE__ */ new Date()).toISOString());
|
|
80785
81444
|
wrote = true;
|
|
80786
81445
|
} catch {
|
|
80787
81446
|
}
|
|
@@ -80793,9 +81452,9 @@ function consumePostUpdateMarker() {
|
|
|
80793
81452
|
for (const p of [markerPath(), legacyMarkerPath()]) {
|
|
80794
81453
|
if (!p) continue;
|
|
80795
81454
|
try {
|
|
80796
|
-
if (!(0,
|
|
80797
|
-
const ageMs = Date.now() - (0,
|
|
80798
|
-
(0,
|
|
81455
|
+
if (!(0, import_node_fs60.existsSync)(p)) continue;
|
|
81456
|
+
const ageMs = Date.now() - (0, import_node_fs60.statSync)(p).mtimeMs;
|
|
81457
|
+
(0, import_node_fs60.rmSync)(p, { force: true });
|
|
80799
81458
|
if (ageMs < FRESH_MS) fresh = true;
|
|
80800
81459
|
} catch {
|
|
80801
81460
|
}
|
|
@@ -80812,13 +81471,13 @@ function currentVersion() {
|
|
|
80812
81471
|
return appVersion();
|
|
80813
81472
|
}
|
|
80814
81473
|
function installRoot() {
|
|
80815
|
-
return (0,
|
|
81474
|
+
return (0, import_node_path54.dirname)((0, import_node_path54.dirname)(process.execPath));
|
|
80816
81475
|
}
|
|
80817
81476
|
function updateExePath() {
|
|
80818
|
-
return (0,
|
|
81477
|
+
return (0, import_node_path54.join)(installRoot(), "Update.exe");
|
|
80819
81478
|
}
|
|
80820
81479
|
function packagesDir() {
|
|
80821
|
-
return (0,
|
|
81480
|
+
return (0, import_node_path54.join)(installRoot(), "packages");
|
|
80822
81481
|
}
|
|
80823
81482
|
function feedUrl() {
|
|
80824
81483
|
const env2 = (process.env.FLOLESS_UPDATE_URL ?? "").trim().replace(/\/+$/, "");
|
|
@@ -80909,22 +81568,22 @@ async function checkForUpdate() {
|
|
|
80909
81568
|
}
|
|
80910
81569
|
async function sha1OfFile(path) {
|
|
80911
81570
|
const hash2 = (0, import_node_crypto31.createHash)("sha1");
|
|
80912
|
-
await (0, import_promises5.pipeline)((0,
|
|
81571
|
+
await (0, import_promises5.pipeline)((0, import_node_fs61.createReadStream)(path), hash2);
|
|
80913
81572
|
return hash2.digest("hex").toUpperCase();
|
|
80914
81573
|
}
|
|
80915
81574
|
async function downloadPackage(asset) {
|
|
80916
81575
|
if (!NUPKG_NAME.test(asset.FileName)) throw new Error(`refusing suspicious package name: ${asset.FileName}`);
|
|
80917
81576
|
const want = asset.SHA1.toUpperCase();
|
|
80918
81577
|
const dir = packagesDir();
|
|
80919
|
-
(0,
|
|
80920
|
-
const dest = (0,
|
|
80921
|
-
if ((0,
|
|
81578
|
+
(0, import_node_fs61.mkdirSync)(dir, { recursive: true });
|
|
81579
|
+
const dest = (0, import_node_path54.join)(dir, asset.FileName);
|
|
81580
|
+
if ((0, import_node_fs61.existsSync)(dest) && await sha1OfFile(dest) === want) return dest;
|
|
80922
81581
|
const res = await authedFetch(`${feedUrl()}/${encodeURIComponent(asset.FileName)}`, {
|
|
80923
81582
|
redirect: "follow",
|
|
80924
81583
|
signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS)
|
|
80925
81584
|
});
|
|
80926
81585
|
if (!res.ok || !res.body) throw new Error(`download failed: HTTP ${res.status} for ${asset.FileName}`);
|
|
80927
|
-
await (0, import_promises5.pipeline)(import_node_stream3.Readable.fromWeb(res.body), (0,
|
|
81586
|
+
await (0, import_promises5.pipeline)(import_node_stream3.Readable.fromWeb(res.body), (0, import_node_fs61.createWriteStream)(dest));
|
|
80928
81587
|
const got = await sha1OfFile(dest);
|
|
80929
81588
|
if (got !== want) throw new Error(`SHA1 mismatch for ${asset.FileName}: feed=${want} got=${got}`);
|
|
80930
81589
|
return dest;
|
|
@@ -80933,7 +81592,7 @@ async function applyUpdate(check, opts) {
|
|
|
80933
81592
|
if (!check.supported) return { applied: false, message: check.reason ?? "auto-update not supported in this runtime" };
|
|
80934
81593
|
if (!check.updateAvailable || !check.asset) return { applied: false, message: check.reason ?? "no update available" };
|
|
80935
81594
|
const exe2 = updateExePath();
|
|
80936
|
-
if (!(0,
|
|
81595
|
+
if (!(0, import_node_fs61.existsSync)(exe2)) {
|
|
80937
81596
|
return { applied: false, message: `Update.exe not found at ${exe2} \u2014 is this a Velopack install?` };
|
|
80938
81597
|
}
|
|
80939
81598
|
const pkg = await downloadPackage(check.asset);
|
|
@@ -81173,12 +81832,12 @@ function isTraceCorrupt(events) {
|
|
|
81173
81832
|
|
|
81174
81833
|
// launch.mjs
|
|
81175
81834
|
var import_node_child_process10 = require("node:child_process");
|
|
81176
|
-
var
|
|
81835
|
+
var import_node_path55 = require("node:path");
|
|
81177
81836
|
var import_node_url3 = require("node:url");
|
|
81178
|
-
var
|
|
81837
|
+
var import_node_fs62 = require("node:fs");
|
|
81179
81838
|
var import_node_http = __toESM(require("node:http"), 1);
|
|
81180
81839
|
var import_node_readline = require("node:readline");
|
|
81181
|
-
var __dirname2 = (0,
|
|
81840
|
+
var __dirname2 = (0, import_node_path55.dirname)((0, import_node_url3.fileURLToPath)(__import_meta_url));
|
|
81182
81841
|
var PORT = Number(process.env.PORT ?? 4317);
|
|
81183
81842
|
var HEALTH_URL = `http://127.0.0.1:${PORT}/api/health`;
|
|
81184
81843
|
var BROWSER_URL = `http://floless.localhost:${PORT}`;
|
|
@@ -81256,8 +81915,8 @@ async function waitHealthy(timeoutMs = 3e4) {
|
|
|
81256
81915
|
function resolveServerStart() {
|
|
81257
81916
|
const packaged = /flolessapp\.exe$/i.test(process.execPath);
|
|
81258
81917
|
if (packaged) return { cmd: process.execPath, args: ["--serve"], shell: false };
|
|
81259
|
-
const bundle = (0,
|
|
81260
|
-
if ((0,
|
|
81918
|
+
const bundle = (0, import_node_path55.join)(__dirname2, "dist", "floless-server.cjs");
|
|
81919
|
+
if ((0, import_node_fs62.existsSync)(bundle)) return { cmd: process.execPath, args: [bundle, "--serve"], shell: false };
|
|
81261
81920
|
return { cmd: "npm", args: ["run", "start"], shell: isWin2 };
|
|
81262
81921
|
}
|
|
81263
81922
|
function startServerDetached() {
|
|
@@ -81410,8 +82069,8 @@ function taskkillArgs(pid, { tree = true } = {}) {
|
|
|
81410
82069
|
}
|
|
81411
82070
|
function killSupervisor({ tree = true } = {}) {
|
|
81412
82071
|
if (!isWin2) return;
|
|
81413
|
-
const isNpmChannel = /^node(\.exe)?$/i.test((0,
|
|
81414
|
-
const scriptMatch = isNpmChannel ? (0,
|
|
82072
|
+
const isNpmChannel = /^node(\.exe)?$/i.test((0, import_node_path55.basename)(process.execPath));
|
|
82073
|
+
const scriptMatch = isNpmChannel ? (0, import_node_path55.basename)((0, import_node_url3.fileURLToPath)(__import_meta_url)) : void 0;
|
|
81415
82074
|
const realExe = resolveRealInstallExe(process.execPath);
|
|
81416
82075
|
const exeMatch = realExe === process.execPath ? process.execPath : [process.execPath, realExe];
|
|
81417
82076
|
const pids = supervisorPidsToKill(enumerateProcesses(), process.pid, exeMatch, scriptMatch);
|
|
@@ -81582,7 +82241,7 @@ async function runAction(arg, flagArgv = [], selfVersion = null, selfChannel = n
|
|
|
81582
82241
|
}
|
|
81583
82242
|
await action(parseTeardownFlags(flagArgv));
|
|
81584
82243
|
}
|
|
81585
|
-
var entry = (0,
|
|
82244
|
+
var entry = (0, import_node_path55.basename)(process.argv[1] ?? "").toLowerCase();
|
|
81586
82245
|
if (entry === "launch.mjs") {
|
|
81587
82246
|
runAction(process.argv[2], process.argv.slice(3)).catch((e) => {
|
|
81588
82247
|
log(`error: ${e?.message ?? e}`);
|
|
@@ -81593,7 +82252,7 @@ if (entry === "launch.mjs") {
|
|
|
81593
82252
|
// aware-update.ts
|
|
81594
82253
|
var import_promises6 = require("node:fs/promises");
|
|
81595
82254
|
var import_node_crypto32 = require("node:crypto");
|
|
81596
|
-
var
|
|
82255
|
+
var import_node_path56 = require("node:path");
|
|
81597
82256
|
var REGISTRY_LATEST = "https://registry.npmjs.org/@aware-aeco/cli/latest";
|
|
81598
82257
|
var FEED_TIMEOUT_MS2 = 15e3;
|
|
81599
82258
|
var VERSION_TTL_MS = 5e3;
|
|
@@ -81609,8 +82268,8 @@ var nodeBridgeIo = { readdir: import_promises6.readdir, lstat: import_promises6.
|
|
|
81609
82268
|
var nodeBridgeVersionIo = { ...nodeBridgeIo, readFile: import_promises6.readFile };
|
|
81610
82269
|
var BRIDGE_VERSION_MAX_BYTES = 128;
|
|
81611
82270
|
function pathInside(root5, candidate) {
|
|
81612
|
-
const rel = (0,
|
|
81613
|
-
return rel === "" || !rel.startsWith("..") && !(0,
|
|
82271
|
+
const rel = (0, import_node_path56.relative)(root5, candidate);
|
|
82272
|
+
return rel === "" || !rel.startsWith("..") && !(0, import_node_path56.isAbsolute)(rel);
|
|
81614
82273
|
}
|
|
81615
82274
|
async function snapshotPersistentBridges(bridgeDirectory, io = nodeBridgeIo) {
|
|
81616
82275
|
let names;
|
|
@@ -81634,7 +82293,7 @@ async function snapshotPersistentBridges(bridgeDirectory, io = nodeBridgeIo) {
|
|
|
81634
82293
|
for (const host of AWARE_BRIDGE_HOSTS) {
|
|
81635
82294
|
const fileName = `aware-${host}.exe`;
|
|
81636
82295
|
if (!names.includes(fileName)) continue;
|
|
81637
|
-
const candidate = (0,
|
|
82296
|
+
const candidate = (0, import_node_path56.join)(bridgeDirectory, fileName);
|
|
81638
82297
|
try {
|
|
81639
82298
|
const stat4 = await io.lstat(candidate);
|
|
81640
82299
|
const canonical = await io.realpath(candidate);
|
|
@@ -81678,8 +82337,8 @@ async function persistentBridgeVersion(bridgeDirectory, host, io = nodeBridgeVer
|
|
|
81678
82337
|
throw error;
|
|
81679
82338
|
}
|
|
81680
82339
|
};
|
|
81681
|
-
const executable = (0,
|
|
81682
|
-
const marker = (0,
|
|
82340
|
+
const executable = (0, import_node_path56.join)(bridgeDirectory, `aware-${host}.exe`);
|
|
82341
|
+
const marker = (0, import_node_path56.join)(bridgeDirectory, `aware-${host}.version`);
|
|
81683
82342
|
try {
|
|
81684
82343
|
if (!await validateFile(executable) || !await validateFile(marker)) return null;
|
|
81685
82344
|
const bytes = await io.readFile(marker, "utf8");
|
|
@@ -81713,7 +82372,7 @@ function validateMarker(value) {
|
|
|
81713
82372
|
if (v.host != null && !isBridgeHost(v.host)) return null;
|
|
81714
82373
|
if (v.child != null) {
|
|
81715
82374
|
const child = v.child;
|
|
81716
|
-
if (!Number.isSafeInteger(child.pid) || child.pid <= 0 || !PROCESS_IDENTITY.test(child.startIdentity) || !PROCESS_IDENTITY.test(child.executableIdentity) || (0,
|
|
82375
|
+
if (!Number.isSafeInteger(child.pid) || child.pid <= 0 || !PROCESS_IDENTITY.test(child.startIdentity) || !PROCESS_IDENTITY.test(child.executableIdentity) || (0, import_node_path56.basename)(child.executableIdentity) !== child.executableIdentity) return null;
|
|
81717
82376
|
}
|
|
81718
82377
|
return {
|
|
81719
82378
|
// Normalised on read: a decoded schema-1 marker is handed to callers as a schema-2 value with
|
|
@@ -81733,7 +82392,7 @@ function createMaintenanceMarkerStore(markerPath2, options = {}) {
|
|
|
81733
82392
|
const io = options.io ?? nodeMarkerIo;
|
|
81734
82393
|
const maxBytes = Math.min(options.maxBytes ?? MARKER_MAX_BYTES, MARKER_MAX_BYTES);
|
|
81735
82394
|
const randomId = options.randomId ?? import_node_crypto32.randomUUID;
|
|
81736
|
-
const directory = (0,
|
|
82395
|
+
const directory = (0, import_node_path56.dirname)(markerPath2);
|
|
81737
82396
|
return {
|
|
81738
82397
|
async read() {
|
|
81739
82398
|
let bytes;
|
|
@@ -81757,7 +82416,7 @@ function createMaintenanceMarkerStore(markerPath2, options = {}) {
|
|
|
81757
82416
|
const bytes = JSON.stringify(valid);
|
|
81758
82417
|
if (Buffer.byteLength(bytes) > maxBytes) throw new Error("Refused to write an oversized AWARE maintenance marker.");
|
|
81759
82418
|
await io.mkdir(directory, { recursive: true, mode: 448 });
|
|
81760
|
-
const temp = (0,
|
|
82419
|
+
const temp = (0, import_node_path56.join)(directory, `.${(0, import_node_path56.basename)(markerPath2)}.${randomId()}.tmp`);
|
|
81761
82420
|
try {
|
|
81762
82421
|
await io.writeFile(temp, bytes, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
81763
82422
|
await io.rename(temp, markerPath2);
|
|
@@ -81791,7 +82450,7 @@ function validatePending(value) {
|
|
|
81791
82450
|
function createBridgePendingStore(pendingPath, options = {}) {
|
|
81792
82451
|
const io = options.io ?? nodeMarkerIo;
|
|
81793
82452
|
const randomId = options.randomId ?? import_node_crypto32.randomUUID;
|
|
81794
|
-
const directory = (0,
|
|
82453
|
+
const directory = (0, import_node_path56.dirname)(pendingPath);
|
|
81795
82454
|
return {
|
|
81796
82455
|
async read() {
|
|
81797
82456
|
let bytes;
|
|
@@ -81815,7 +82474,7 @@ function createBridgePendingStore(pendingPath, options = {}) {
|
|
|
81815
82474
|
throw new Error("Refused to write an oversized AWARE bridge-repair intent.");
|
|
81816
82475
|
}
|
|
81817
82476
|
await io.mkdir(directory, { recursive: true, mode: 448 });
|
|
81818
|
-
const temp = (0,
|
|
82477
|
+
const temp = (0, import_node_path56.join)(directory, `.${(0, import_node_path56.basename)(pendingPath)}.${randomId()}.tmp`);
|
|
81819
82478
|
try {
|
|
81820
82479
|
await io.writeFile(temp, bytes, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
81821
82480
|
await io.rename(temp, pendingPath);
|
|
@@ -81935,7 +82594,7 @@ async function checkAwareUpdate(bridgeDirectory) {
|
|
|
81935
82594
|
// aware-install-process.ts
|
|
81936
82595
|
var import_node_child_process11 = require("node:child_process");
|
|
81937
82596
|
var import_promises7 = require("node:fs/promises");
|
|
81938
|
-
var
|
|
82597
|
+
var import_node_path57 = require("node:path");
|
|
81939
82598
|
var import_node_util4 = require("node:util");
|
|
81940
82599
|
var execFileAsync2 = (0, import_node_util4.promisify)(import_node_child_process11.execFile);
|
|
81941
82600
|
var DEFAULT_INSTALL_TIMEOUT_MS = 10 * 6e4;
|
|
@@ -81963,7 +82622,7 @@ function killTree2(child) {
|
|
|
81963
82622
|
}
|
|
81964
82623
|
}
|
|
81965
82624
|
function safeExecutableIdentity(value) {
|
|
81966
|
-
const name = (0,
|
|
82625
|
+
const name = (0, import_node_path57.basename)(value.trim()).replace(/[^A-Za-z0-9._-]/g, "").slice(0, 128);
|
|
81967
82626
|
return name || "unknown";
|
|
81968
82627
|
}
|
|
81969
82628
|
async function maintenanceChildIdentity(pid) {
|
|
@@ -82915,10 +83574,10 @@ function registerDebugNodeRoute(app, deps) {
|
|
|
82915
83574
|
// terminal-run.ts
|
|
82916
83575
|
var import_node_child_process13 = require("node:child_process");
|
|
82917
83576
|
var import_node_child_process14 = require("node:child_process");
|
|
82918
|
-
var
|
|
83577
|
+
var import_node_fs65 = require("node:fs");
|
|
82919
83578
|
var import_node_crypto34 = require("node:crypto");
|
|
82920
|
-
var
|
|
82921
|
-
var
|
|
83579
|
+
var import_node_os31 = require("node:os");
|
|
83580
|
+
var import_node_path60 = require("node:path");
|
|
82922
83581
|
|
|
82923
83582
|
// run-contract.ts
|
|
82924
83583
|
var COMPLETION_SCHEMA = {
|
|
@@ -82973,11 +83632,11 @@ function terminalEvent(stdout) {
|
|
|
82973
83632
|
var import_node_child_process12 = require("node:child_process");
|
|
82974
83633
|
var import_node_util5 = require("node:util");
|
|
82975
83634
|
var import_node_crypto33 = require("node:crypto");
|
|
82976
|
-
var
|
|
82977
|
-
var
|
|
82978
|
-
var
|
|
82979
|
-
var ROOT4 = () => process.env.FLOLESS_HOME ?? (0,
|
|
82980
|
-
var LEASE_DIR = () => (0,
|
|
83635
|
+
var import_node_fs63 = require("node:fs");
|
|
83636
|
+
var import_node_os29 = require("node:os");
|
|
83637
|
+
var import_node_path58 = require("node:path");
|
|
83638
|
+
var ROOT4 = () => process.env.FLOLESS_HOME ?? (0, import_node_path58.join)((0, import_node_os29.homedir)(), ".floless");
|
|
83639
|
+
var LEASE_DIR = () => (0, import_node_path58.join)(ROOT4(), "run-leases");
|
|
82981
83640
|
var WIN = process.platform === "win32";
|
|
82982
83641
|
var LeaseHeldError = class extends Error {
|
|
82983
83642
|
constructor(holder) {
|
|
@@ -82988,15 +83647,15 @@ var LeaseHeldError = class extends Error {
|
|
|
82988
83647
|
};
|
|
82989
83648
|
var serverStartedAt = Math.round(Date.now() - process.uptime() * 1e3);
|
|
82990
83649
|
function canonicalDir(p) {
|
|
82991
|
-
const real =
|
|
82992
|
-
if (!(0,
|
|
82993
|
-
return real.length > 1 && real.endsWith(
|
|
83650
|
+
const real = import_node_fs63.realpathSync.native((0, import_node_path58.resolve)(p));
|
|
83651
|
+
if (!(0, import_node_fs63.statSync)(real).isDirectory()) throw new Error(`not a directory: ${p}`);
|
|
83652
|
+
return real.length > 1 && real.endsWith(import_node_path58.sep) ? real.slice(0, -1) : real;
|
|
82994
83653
|
}
|
|
82995
83654
|
function isInside(parent, child) {
|
|
82996
83655
|
const norm = (s) => WIN ? s.toLowerCase() : s;
|
|
82997
83656
|
const p = norm(parent);
|
|
82998
83657
|
const c = norm(child);
|
|
82999
|
-
return c === p || c.startsWith(p.endsWith(
|
|
83658
|
+
return c === p || c.startsWith(p.endsWith(import_node_path58.sep) ? p : p + import_node_path58.sep);
|
|
83000
83659
|
}
|
|
83001
83660
|
function leaseKey(canonicalCwd) {
|
|
83002
83661
|
const k = WIN ? canonicalCwd.toLowerCase() : canonicalCwd;
|
|
@@ -83004,7 +83663,7 @@ function leaseKey(canonicalCwd) {
|
|
|
83004
83663
|
}
|
|
83005
83664
|
function readLeaseFile(file) {
|
|
83006
83665
|
try {
|
|
83007
|
-
const parsed = JSON.parse((0,
|
|
83666
|
+
const parsed = JSON.parse((0, import_node_fs63.readFileSync)(file, "utf8"));
|
|
83008
83667
|
const l = parsed;
|
|
83009
83668
|
if (typeof l?.leaseId !== "string" || typeof l.token !== "string" || typeof l.cwd !== "string") return null;
|
|
83010
83669
|
if (typeof l.requestId !== "string" || typeof l.generation !== "number") return null;
|
|
@@ -83015,8 +83674,8 @@ function readLeaseFile(file) {
|
|
|
83015
83674
|
}
|
|
83016
83675
|
function claimLease(input) {
|
|
83017
83676
|
const cwd = canonicalDir(input.cwd);
|
|
83018
|
-
(0,
|
|
83019
|
-
const file = (0,
|
|
83677
|
+
(0, import_node_fs63.mkdirSync)(LEASE_DIR(), { recursive: true, mode: 448 });
|
|
83678
|
+
const file = (0, import_node_path58.join)(LEASE_DIR(), leaseKey(cwd));
|
|
83020
83679
|
const lease = {
|
|
83021
83680
|
leaseId: (0, import_node_crypto33.randomUUID)(),
|
|
83022
83681
|
// 32 bytes of CSPRNG. This is an authorization token, not a correlation id — it is the only
|
|
@@ -83038,18 +83697,18 @@ function claimLease(input) {
|
|
|
83038
83697
|
resolvedAt: null
|
|
83039
83698
|
};
|
|
83040
83699
|
try {
|
|
83041
|
-
(0,
|
|
83700
|
+
(0, import_node_fs63.writeFileSync)(file, JSON.stringify(lease, null, 2), { flag: "wx", mode: 384 });
|
|
83042
83701
|
return lease;
|
|
83043
83702
|
} catch (err2) {
|
|
83044
83703
|
if (err2?.code !== "EEXIST") throw err2;
|
|
83045
83704
|
const holder = readLeaseFile(file);
|
|
83046
83705
|
if (holder) throw new LeaseHeldError(holder);
|
|
83047
83706
|
try {
|
|
83048
|
-
(0,
|
|
83707
|
+
(0, import_node_fs63.rmSync)(file);
|
|
83049
83708
|
} catch {
|
|
83050
83709
|
}
|
|
83051
83710
|
try {
|
|
83052
|
-
(0,
|
|
83711
|
+
(0, import_node_fs63.writeFileSync)(file, JSON.stringify(lease, null, 2), { flag: "wx", mode: 384 });
|
|
83053
83712
|
return lease;
|
|
83054
83713
|
} catch (retryErr) {
|
|
83055
83714
|
if (retryErr?.code !== "EEXIST") throw retryErr;
|
|
@@ -83061,8 +83720,8 @@ function claimLease(input) {
|
|
|
83061
83720
|
}
|
|
83062
83721
|
function listLeases() {
|
|
83063
83722
|
const dir = LEASE_DIR();
|
|
83064
|
-
if (!(0,
|
|
83065
|
-
return (0,
|
|
83723
|
+
if (!(0, import_node_fs63.existsSync)(dir)) return [];
|
|
83724
|
+
return (0, import_node_fs63.readdirSync)(dir).filter((f) => f.endsWith(".json")).map((f) => readLeaseFile((0, import_node_path58.join)(dir, f))).filter((l) => l !== null);
|
|
83066
83725
|
}
|
|
83067
83726
|
function getLease(leaseId) {
|
|
83068
83727
|
return listLeases().find((l) => l.leaseId === leaseId) ?? null;
|
|
@@ -83078,27 +83737,27 @@ function leaseForToken(token2) {
|
|
|
83078
83737
|
}
|
|
83079
83738
|
function patchLease(leaseId, generation, patch2) {
|
|
83080
83739
|
const dir = LEASE_DIR();
|
|
83081
|
-
if (!(0,
|
|
83082
|
-
for (const f of (0,
|
|
83083
|
-
const file = (0,
|
|
83740
|
+
if (!(0, import_node_fs63.existsSync)(dir)) return null;
|
|
83741
|
+
for (const f of (0, import_node_fs63.readdirSync)(dir).filter((n) => n.endsWith(".json"))) {
|
|
83742
|
+
const file = (0, import_node_path58.join)(dir, f);
|
|
83084
83743
|
const cur = readLeaseFile(file);
|
|
83085
83744
|
if (!cur || cur.leaseId !== leaseId) continue;
|
|
83086
83745
|
if (cur.generation !== generation) return null;
|
|
83087
83746
|
const next = { ...cur, ...patch2, leaseId: cur.leaseId, token: cur.token, generation: cur.generation };
|
|
83088
|
-
(0,
|
|
83747
|
+
(0, import_node_fs63.writeFileSync)(file, JSON.stringify(next, null, 2), { mode: 384 });
|
|
83089
83748
|
return next;
|
|
83090
83749
|
}
|
|
83091
83750
|
return null;
|
|
83092
83751
|
}
|
|
83093
83752
|
function releaseLease(leaseId) {
|
|
83094
83753
|
const dir = LEASE_DIR();
|
|
83095
|
-
if (!(0,
|
|
83096
|
-
for (const f of (0,
|
|
83097
|
-
const file = (0,
|
|
83754
|
+
if (!(0, import_node_fs63.existsSync)(dir)) return false;
|
|
83755
|
+
for (const f of (0, import_node_fs63.readdirSync)(dir).filter((n) => n.endsWith(".json"))) {
|
|
83756
|
+
const file = (0, import_node_path58.join)(dir, f);
|
|
83098
83757
|
const cur = readLeaseFile(file);
|
|
83099
83758
|
if (cur?.leaseId !== leaseId) continue;
|
|
83100
83759
|
try {
|
|
83101
|
-
(0,
|
|
83760
|
+
(0, import_node_fs63.rmSync)(file);
|
|
83102
83761
|
} catch {
|
|
83103
83762
|
}
|
|
83104
83763
|
return true;
|
|
@@ -83169,194 +83828,10 @@ function sameProcess(observed, pid, procStartedAt) {
|
|
|
83169
83828
|
return seen !== void 0 && Math.abs(seen - procStartedAt) < 2e3;
|
|
83170
83829
|
}
|
|
83171
83830
|
|
|
83172
|
-
// run-relay.ts
|
|
83173
|
-
var import_node_os28 = require("node:os");
|
|
83174
|
-
var import_node_path57 = require("node:path");
|
|
83175
|
-
var RUN_POLICY = {
|
|
83176
|
-
/**
|
|
83177
|
-
* The first slice's one enabled type: small, mechanical, well-scoped.
|
|
83178
|
-
*
|
|
83179
|
-
* Three calls, and nothing else. Note what is NOT here: no `PUT /api/contract`, no `/approve`, no
|
|
83180
|
-
* project route — a `tweak` edits a node in a `.flo` and compiles it, and the approval gate stays
|
|
83181
|
-
* human. `POST /api/compile` is what replaces the skill's `aware app compile` shell-out, which is
|
|
83182
|
-
* the other half of the shell being denied.
|
|
83183
|
-
*/
|
|
83184
|
-
tweak: {
|
|
83185
|
-
runnable: true,
|
|
83186
|
-
calls: (l) => [
|
|
83187
|
-
{ method: "GET", path: "/api/requests", why: "read the authoritative spec for this request" },
|
|
83188
|
-
...isSafeAppId(l.appId) ? [{ method: "POST", path: "/api/compile", body: { id: l.appId }, why: "compile the workflow after editing its .flo" }] : [],
|
|
83189
|
-
{ method: "DELETE", path: `/api/requests/${l.requestId}`, why: "clear this request once applied" }
|
|
83190
|
-
],
|
|
83191
|
-
// The `.flo` lives in the app's own source directory, NOT in the nominated folder — which is
|
|
83192
|
-
// exactly why §D1 insists the nominated folder is an address rather than a sandbox. Without this
|
|
83193
|
-
// grant the agent can read its instruction and edit nothing.
|
|
83194
|
-
//
|
|
83195
|
-
// `.filter(Boolean)`, so an id `appSourceDir` refuses grants NOTHING rather than falling back to
|
|
83196
|
-
// something broader. A run whose app id is unusable should be refused before it starts (the route
|
|
83197
|
-
// does that), and if one ever reaches here it gets no filesystem capability at all.
|
|
83198
|
-
addDirs: (l) => l.appId ? [appSourceDir(l.appId)].filter((d) => d !== null) : []
|
|
83199
|
-
},
|
|
83200
|
-
// ── enabled by E1, but not built in this slice ──────────────────────────────
|
|
83201
|
-
// Each is mechanical and well-scoped enough to run headless; each needs its own call list worked
|
|
83202
|
-
// out from its skill and its own end-to-end proof, and the plan slices the first spawn to ONE type
|
|
83203
|
-
// on purpose. A reason, not a null, so the picker can say why the button is absent.
|
|
83204
|
-
"use-template": { runnable: false, why: "not yet available headless \u2014 run it from your terminal for now" },
|
|
83205
|
-
"ui-customize": { runnable: false, why: "not yet available headless \u2014 run it from your terminal for now" },
|
|
83206
|
-
rebake: { runnable: false, why: "not yet available headless \u2014 run it from your terminal for now" },
|
|
83207
|
-
"tweak-contract": { runnable: false, why: "not yet available headless \u2014 run it from your terminal for now" },
|
|
83208
|
-
// ── E1 says no, and these are the reasons ───────────────────────────────────
|
|
83209
|
-
"revision-read": {
|
|
83210
|
-
runnable: false,
|
|
83211
|
-
// The flagship type, and the judgment-heaviest: every arm of its instruction ends "STOP and tell
|
|
83212
|
-
// me to open Drawings → Steel Filter … do NOT read members until I explicitly come back". It is a
|
|
83213
|
-
// two-phase workflow whose first phase ends in a mandatory human checkpoint, so headless the best
|
|
83214
|
-
// outcome is "prepass runs, agent says go review, exits 0, request still pending" — a row that
|
|
83215
|
-
// lies. It waits until `needs-you` is a first-class, actionable row.
|
|
83216
|
-
why: "reading a drawing set stops at a review checkpoint \u2014 do this one in your terminal"
|
|
83217
|
-
},
|
|
83218
|
-
"knowledge-organize": {
|
|
83219
|
-
runnable: false,
|
|
83220
|
-
// Both take the server organize lock, and the plan's stated mitigation ("mark the request failed
|
|
83221
|
-
// so the lock is released") is a NO-OP: `patchRequest` writes a request file, while the lock is
|
|
83222
|
-
// released by `failOrganize` in the knowledge store. A hard-killed headless organize past
|
|
83223
|
-
// `/start` wedges the Organize button for ten minutes, on a row that renders no ✕.
|
|
83224
|
-
why: "organizing holds a lock a killed run can\u2019t release \u2014 do this one in your terminal"
|
|
83225
|
-
},
|
|
83226
|
-
"knowledge-adjust": { runnable: false, why: "organizing holds a lock a killed run can\u2019t release \u2014 do this one in your terminal" },
|
|
83227
|
-
guide: { runnable: false, why: "this one is a conversation \u2014 headless would talk to nobody" },
|
|
83228
|
-
"new-workflow": { runnable: false, why: "this one is a conversation \u2014 headless would talk to nobody" }
|
|
83229
|
-
};
|
|
83230
|
-
var SAFE_APP_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
83231
|
-
var isSafeAppId = (id) => typeof id === "string" && SAFE_APP_ID.test(id);
|
|
83232
|
-
function appSourceDir(appId) {
|
|
83233
|
-
if (!isSafeAppId(appId)) return null;
|
|
83234
|
-
const root5 = process.env.AWARE_HOME || (0, import_node_path57.join)((0, import_node_os28.homedir)(), ".aware");
|
|
83235
|
-
return (0, import_node_path57.join)(root5, "apps", appId);
|
|
83236
|
-
}
|
|
83237
|
-
function policyFor(type) {
|
|
83238
|
-
if (!isRequestType(type)) {
|
|
83239
|
-
return { runnable: false, why: "floless doesn\u2019t recognise this request \u2014 it may have been made by a newer version" };
|
|
83240
|
-
}
|
|
83241
|
-
return RUN_POLICY[type];
|
|
83242
|
-
}
|
|
83243
|
-
var TOOL_NAME = "floless_api";
|
|
83244
|
-
function mcpConfigFor(token2, origin) {
|
|
83245
|
-
return { mcpServers: { floless: { type: "http", url: `${origin}/api/mcp/run/${token2}` } } };
|
|
83246
|
-
}
|
|
83247
|
-
function jsonRpc(id, result) {
|
|
83248
|
-
return { jsonrpc: "2.0", id, result };
|
|
83249
|
-
}
|
|
83250
|
-
function toolRefusal(text3) {
|
|
83251
|
-
return { content: [{ type: "text", text: text3 }], isError: true };
|
|
83252
|
-
}
|
|
83253
|
-
function sameBody(want, got) {
|
|
83254
|
-
if (want === void 0 && got !== null && typeof got === "object" && Object.keys(got).length === 0) return true;
|
|
83255
|
-
return JSON.stringify(sortKeys(want)) === JSON.stringify(sortKeys(got ?? void 0));
|
|
83256
|
-
}
|
|
83257
|
-
function sortKeys(v) {
|
|
83258
|
-
if (Array.isArray(v)) return v.map(sortKeys);
|
|
83259
|
-
if (v && typeof v === "object") {
|
|
83260
|
-
return Object.fromEntries(Object.keys(v).sort().map((k) => [k, sortKeys(v[k])]));
|
|
83261
|
-
}
|
|
83262
|
-
return v;
|
|
83263
|
-
}
|
|
83264
|
-
function normalizePath(raw, origin) {
|
|
83265
|
-
if (typeof raw !== "string" || !raw) return null;
|
|
83266
|
-
let u;
|
|
83267
|
-
try {
|
|
83268
|
-
u = new URL(raw, origin);
|
|
83269
|
-
} catch {
|
|
83270
|
-
return null;
|
|
83271
|
-
}
|
|
83272
|
-
if (new URL(origin).origin !== u.origin) return null;
|
|
83273
|
-
const p = u.pathname.length > 1 && u.pathname.endsWith("/") ? u.pathname.slice(0, -1) : u.pathname;
|
|
83274
|
-
return `${p}${u.search}`;
|
|
83275
|
-
}
|
|
83276
|
-
function registerRunRelay(app, deps, origin) {
|
|
83277
|
-
app.post(
|
|
83278
|
-
"/api/mcp/run/:token",
|
|
83279
|
-
async (req, reply) => {
|
|
83280
|
-
const msg = req.body ?? {};
|
|
83281
|
-
if (msg.id === void 0) return reply.status(202).send();
|
|
83282
|
-
const lease = deps.leaseForToken(req.params.token);
|
|
83283
|
-
if (!lease) {
|
|
83284
|
-
return reply.status(200).send({
|
|
83285
|
-
jsonrpc: "2.0",
|
|
83286
|
-
id: msg.id,
|
|
83287
|
-
error: { code: -32001, message: "this run is no longer active" }
|
|
83288
|
-
});
|
|
83289
|
-
}
|
|
83290
|
-
const policy = policyFor(lease.requestType);
|
|
83291
|
-
const allowed = policy.runnable ? policy.calls(lease) : [];
|
|
83292
|
-
if (msg.method === "initialize") {
|
|
83293
|
-
const requested = msg.params?.protocolVersion;
|
|
83294
|
-
return reply.send(jsonRpc(msg.id, {
|
|
83295
|
-
protocolVersion: requested ?? "2025-06-18",
|
|
83296
|
-
capabilities: { tools: {} },
|
|
83297
|
-
serverInfo: { name: "floless", version: "1" }
|
|
83298
|
-
}));
|
|
83299
|
-
}
|
|
83300
|
-
if (msg.method === "tools/list") {
|
|
83301
|
-
return reply.send(jsonRpc(msg.id, {
|
|
83302
|
-
tools: [{
|
|
83303
|
-
name: TOOL_NAME,
|
|
83304
|
-
description: "Call the floless.app API for THIS request. This is your only channel to floless \u2014 there is no shell in this session. Exactly these calls are permitted:\n" + allowed.map((c) => ` ${c.method} ${c.path}${c.body ? ` body ${JSON.stringify(c.body)}` : ""} \u2014 ${c.why}`).join("\n") + '\nAnything else is refused. If you need something not listed, stop and finish with outcome "needs-you" explaining what you need.',
|
|
83305
|
-
inputSchema: {
|
|
83306
|
-
type: "object",
|
|
83307
|
-
properties: {
|
|
83308
|
-
method: { type: "string", enum: ["GET", "POST", "PUT", "DELETE"] },
|
|
83309
|
-
path: { type: "string" },
|
|
83310
|
-
body: { type: "object" }
|
|
83311
|
-
},
|
|
83312
|
-
required: ["method", "path"]
|
|
83313
|
-
}
|
|
83314
|
-
}]
|
|
83315
|
-
}));
|
|
83316
|
-
}
|
|
83317
|
-
if (msg.method !== "tools/call") {
|
|
83318
|
-
return reply.send({ jsonrpc: "2.0", id: msg.id, error: { code: -32601, message: "method not found" } });
|
|
83319
|
-
}
|
|
83320
|
-
const params = msg.params;
|
|
83321
|
-
if (params?.name !== TOOL_NAME) {
|
|
83322
|
-
return reply.send(jsonRpc(msg.id, toolRefusal(`no such tool: ${String(params?.name)}`)));
|
|
83323
|
-
}
|
|
83324
|
-
if (!policy.runnable) {
|
|
83325
|
-
return reply.send(jsonRpc(msg.id, toolRefusal(`refused: ${policy.why}`)));
|
|
83326
|
-
}
|
|
83327
|
-
const argMethod = String(params.arguments?.["method"] ?? "").toUpperCase();
|
|
83328
|
-
const argPath = normalizePath(params.arguments?.["path"], origin);
|
|
83329
|
-
const argBody = params.arguments?.["body"];
|
|
83330
|
-
const match = argPath === null ? void 0 : allowed.find((c) => c.method === argMethod && c.path === argPath && sameBody(c.body, argBody));
|
|
83331
|
-
if (!match) {
|
|
83332
|
-
return reply.send(jsonRpc(msg.id, toolRefusal(
|
|
83333
|
-
`refused: ${argMethod} ${String(params.arguments?.["path"])} is not permitted for this run.
|
|
83334
|
-
Permitted:
|
|
83335
|
-
${allowed.map((c) => ` ${c.method} ${c.path}${c.body ? ` body ${JSON.stringify(c.body)}` : ""}`).join("\n")}`
|
|
83336
|
-
)));
|
|
83337
|
-
}
|
|
83338
|
-
const res = await deps.dispatch({ method: match.method, path: match.path, ...match.body !== void 0 ? { body: match.body } : {} });
|
|
83339
|
-
if (match.method === "DELETE" && match.path === `/api/requests/${lease.requestId}` && res.status < 300) {
|
|
83340
|
-
deps.markResolved(lease);
|
|
83341
|
-
}
|
|
83342
|
-
const body = match.path === "/api/requests" ? onlyThisRequest(res.body, lease.requestId) : res.body;
|
|
83343
|
-
return reply.send(jsonRpc(msg.id, {
|
|
83344
|
-
content: [{ type: "text", text: JSON.stringify({ status: res.status, body }) }],
|
|
83345
|
-
...res.status >= 400 ? { isError: true } : {}
|
|
83346
|
-
}));
|
|
83347
|
-
}
|
|
83348
|
-
);
|
|
83349
|
-
}
|
|
83350
|
-
function onlyThisRequest(body, requestId) {
|
|
83351
|
-
const b = body;
|
|
83352
|
-
if (!b || !Array.isArray(b.requests)) return body;
|
|
83353
|
-
return { ...b, requests: b.requests.filter((r) => r?.id === requestId) };
|
|
83354
|
-
}
|
|
83355
|
-
|
|
83356
83831
|
// terminal-runtime.ts
|
|
83357
|
-
var
|
|
83358
|
-
var
|
|
83359
|
-
var
|
|
83832
|
+
var import_node_fs64 = require("node:fs");
|
|
83833
|
+
var import_node_os30 = require("node:os");
|
|
83834
|
+
var import_node_path59 = require("node:path");
|
|
83360
83835
|
var WIN2 = process.platform === "win32";
|
|
83361
83836
|
var exe = (name) => WIN2 ? `${name}.exe` : name;
|
|
83362
83837
|
var RUNTIMES = [
|
|
@@ -83367,7 +83842,7 @@ var RUNTIMES = [
|
|
|
83367
83842
|
command: "claude",
|
|
83368
83843
|
// Measured: the native installer puts it in ~/.local/bin, NOT under npm root -g.
|
|
83369
83844
|
// npm package, when that is how it was installed: @anthropic-ai/claude-code.
|
|
83370
|
-
candidates: () => [(0,
|
|
83845
|
+
candidates: () => [(0, import_node_path59.join)((0, import_node_os30.homedir)(), ".local", "bin", exe("claude")), ...npmShims("claude")]
|
|
83371
83846
|
},
|
|
83372
83847
|
{
|
|
83373
83848
|
id: "codex",
|
|
@@ -83376,7 +83851,7 @@ var RUNTIMES = [
|
|
|
83376
83851
|
command: "codex",
|
|
83377
83852
|
// Measured: %LOCALAPPDATA%\Programs\OpenAI\Codex\bin\codex.exe.
|
|
83378
83853
|
candidates: () => [
|
|
83379
|
-
WIN2 && process.env.LOCALAPPDATA ? (0,
|
|
83854
|
+
WIN2 && process.env.LOCALAPPDATA ? (0, import_node_path59.join)(process.env.LOCALAPPDATA, "Programs", "OpenAI", "Codex", "bin", exe("codex")) : (0, import_node_path59.join)((0, import_node_os30.homedir)(), ".codex", "bin", exe("codex")),
|
|
83380
83855
|
...npmShims("codex")
|
|
83381
83856
|
// npm package, when installed that way: @openai/codex
|
|
83382
83857
|
]
|
|
@@ -83389,23 +83864,23 @@ var RUNTIMES = [
|
|
|
83389
83864
|
// NOT MEASURED — no OpenCode on the machine this was written against, so these are the
|
|
83390
83865
|
// documented locations and unproven. The E2E that first enables OpenCode's arm has to confirm
|
|
83391
83866
|
// them on a machine that has it; until then a false `not-found` here is the expected failure.
|
|
83392
|
-
candidates: () => [(0,
|
|
83867
|
+
candidates: () => [(0, import_node_path59.join)((0, import_node_os30.homedir)(), ".opencode", "bin", exe("opencode")), ...npmShims("opencode")]
|
|
83393
83868
|
}
|
|
83394
83869
|
];
|
|
83395
83870
|
function npmShims(bin) {
|
|
83396
|
-
if (WIN2) return process.env.APPDATA ? [(0,
|
|
83871
|
+
if (WIN2) return process.env.APPDATA ? [(0, import_node_path59.join)(process.env.APPDATA, "npm", `${bin}.cmd`)] : [];
|
|
83397
83872
|
return [
|
|
83398
|
-
(0,
|
|
83399
|
-
(0,
|
|
83400
|
-
(0,
|
|
83873
|
+
(0, import_node_path59.join)((0, import_node_os30.homedir)(), ".npm-global", "bin", bin),
|
|
83874
|
+
(0, import_node_path59.join)("/usr", "local", "bin", bin),
|
|
83875
|
+
(0, import_node_path59.join)("/opt", "homebrew", "bin", bin)
|
|
83401
83876
|
// Apple-silicon Homebrew
|
|
83402
83877
|
];
|
|
83403
83878
|
}
|
|
83404
83879
|
function usableBinary(p) {
|
|
83405
83880
|
try {
|
|
83406
|
-
const st = (0,
|
|
83881
|
+
const st = (0, import_node_fs64.statSync)(p);
|
|
83407
83882
|
if (!st.isFile() || st.size === 0) return false;
|
|
83408
|
-
if (!WIN2) (0,
|
|
83883
|
+
if (!WIN2) (0, import_node_fs64.accessSync)(p, import_node_fs64.constants.X_OK);
|
|
83409
83884
|
return true;
|
|
83410
83885
|
} catch {
|
|
83411
83886
|
return false;
|
|
@@ -83427,23 +83902,29 @@ function detectRuntimes(opts) {
|
|
|
83427
83902
|
function refreshRuntimes() {
|
|
83428
83903
|
_cache2 = null;
|
|
83429
83904
|
}
|
|
83430
|
-
var settingsPath = () => (0,
|
|
83905
|
+
var settingsPath = () => (0, import_node_path59.join)(process.env.FLOLESS_HOME ?? (0, import_node_path59.join)((0, import_node_os30.homedir)(), ".floless"), "terminal-runtime.json");
|
|
83431
83906
|
function readSettings() {
|
|
83432
83907
|
try {
|
|
83433
|
-
const raw = JSON.parse((0,
|
|
83908
|
+
const raw = JSON.parse((0, import_node_fs64.readFileSync)(settingsPath(), "utf8"));
|
|
83434
83909
|
return raw && typeof raw === "object" ? raw : {};
|
|
83435
83910
|
} catch {
|
|
83436
83911
|
return {};
|
|
83437
83912
|
}
|
|
83438
83913
|
}
|
|
83439
83914
|
function writeSettings(patch2) {
|
|
83440
|
-
(0,
|
|
83915
|
+
(0, import_node_fs64.mkdirSync)((0, import_node_path59.dirname)(settingsPath()), { recursive: true });
|
|
83441
83916
|
writeJsonAtomic(settingsPath(), { ...readSettings(), ...patch2 });
|
|
83442
83917
|
}
|
|
83443
83918
|
function readProviderSetting() {
|
|
83444
83919
|
const p = readSettings().provider;
|
|
83445
83920
|
return RUNTIMES.some((r) => r.id === p) ? p : null;
|
|
83446
83921
|
}
|
|
83922
|
+
function writeProviderSetting(provider) {
|
|
83923
|
+
if (provider !== null && !RUNTIMES.some((r) => r.id === provider)) {
|
|
83924
|
+
throw new Error(`unknown terminal runtime: ${String(provider)}`);
|
|
83925
|
+
}
|
|
83926
|
+
writeSettings({ provider });
|
|
83927
|
+
}
|
|
83447
83928
|
function resolveProvider() {
|
|
83448
83929
|
const found = detectRuntimes().filter((r) => r.state === "found");
|
|
83449
83930
|
if (!found.length) return null;
|
|
@@ -83463,12 +83944,12 @@ function nominateFolder(projectKey, folder) {
|
|
|
83463
83944
|
throw new FolderError(`That folder doesn\u2019t exist, or isn\u2019t a folder: ${raw}`);
|
|
83464
83945
|
}
|
|
83465
83946
|
try {
|
|
83466
|
-
(0,
|
|
83947
|
+
(0, import_node_fs64.accessSync)(canonical, import_node_fs64.constants.W_OK);
|
|
83467
83948
|
} catch {
|
|
83468
83949
|
throw new FolderError(`floless can\u2019t write in that folder: ${canonical}`);
|
|
83469
83950
|
}
|
|
83470
|
-
const own3 = process.env.FLOLESS_HOME ?? (0,
|
|
83471
|
-
if ((0,
|
|
83951
|
+
const own3 = process.env.FLOLESS_HOME ?? (0, import_node_path59.join)((0, import_node_os30.homedir)(), ".floless");
|
|
83952
|
+
if ((0, import_node_fs64.existsSync)(own3) && isInside(canonicalDir(own3), canonical)) {
|
|
83472
83953
|
throw new FolderError("That\u2019s floless\u2019s own data folder. Pick a folder where your work lives.");
|
|
83473
83954
|
}
|
|
83474
83955
|
if (projectKey) {
|
|
@@ -83499,7 +83980,7 @@ function buildSpawnPlan(input) {
|
|
|
83499
83980
|
}
|
|
83500
83981
|
let file;
|
|
83501
83982
|
try {
|
|
83502
|
-
file =
|
|
83983
|
+
file = import_node_fs64.realpathSync.native(found.path);
|
|
83503
83984
|
if (!usableBinary(file)) throw new Error("not usable");
|
|
83504
83985
|
} catch {
|
|
83505
83986
|
return { ok: false, reason: "Claude Code moved or was uninstalled since floless last looked. Try again." };
|
|
@@ -83637,17 +84118,17 @@ async function finish(deps, lease, patch2) {
|
|
|
83637
84118
|
if (contained) releaseLease(lease.leaseId);
|
|
83638
84119
|
else console.error(`[terminal-run] could not prove the tree for lease ${lease.leaseId} is gone \u2014 lease held`);
|
|
83639
84120
|
}
|
|
83640
|
-
var mcpDir = () => (0,
|
|
83641
|
-
var mcpPath = (leaseId) => (0,
|
|
84121
|
+
var mcpDir = () => (0, import_node_path60.join)(process.env.FLOLESS_HOME ?? (0, import_node_path60.join)((0, import_node_os31.homedir)(), ".floless"), "run-mcp");
|
|
84122
|
+
var mcpPath = (leaseId) => (0, import_node_path60.join)(mcpDir(), `${leaseId}.json`);
|
|
83642
84123
|
function writeMcpConfig(lease) {
|
|
83643
|
-
(0,
|
|
84124
|
+
(0, import_node_fs65.mkdirSync)(mcpDir(), { recursive: true });
|
|
83644
84125
|
const p = mcpPath(lease.leaseId);
|
|
83645
|
-
(0,
|
|
84126
|
+
(0, import_node_fs65.writeFileSync)(p, JSON.stringify(mcpConfigFor(lease.token, selfOrigin()), null, 2), { mode: 384 });
|
|
83646
84127
|
return p;
|
|
83647
84128
|
}
|
|
83648
84129
|
function cleanupMcpConfig(leaseId) {
|
|
83649
84130
|
try {
|
|
83650
|
-
(0,
|
|
84131
|
+
(0, import_node_fs65.rmSync)(mcpPath(leaseId));
|
|
83651
84132
|
} catch {
|
|
83652
84133
|
}
|
|
83653
84134
|
}
|
|
@@ -83685,6 +84166,14 @@ function registerTerminalRunRoutes(app, deps) {
|
|
|
83685
84166
|
provider: resolveProvider(),
|
|
83686
84167
|
folder: resolveRunFolder(req.query?.project ?? null)
|
|
83687
84168
|
}));
|
|
84169
|
+
app.put("/api/terminal-runtimes/provider", async (request, reply) => {
|
|
84170
|
+
const p = request.body?.provider ?? null;
|
|
84171
|
+
if (p !== null && !detectRuntimes().some((r) => r.id === p)) {
|
|
84172
|
+
return reply.status(400).send({ ok: false, error: `floless doesn\u2019t know a terminal AI called \u201C${String(p)}\u201D.` });
|
|
84173
|
+
}
|
|
84174
|
+
writeProviderSetting(p);
|
|
84175
|
+
return { ok: true, provider: resolveProvider() };
|
|
84176
|
+
});
|
|
83688
84177
|
app.put("/api/terminal-runtimes/folder", async (request, reply) => {
|
|
83689
84178
|
try {
|
|
83690
84179
|
const folder = nominateFolder(request.body?.project ?? null, String(request.body?.folder ?? ""));
|
|
@@ -83700,15 +84189,27 @@ function registerTerminalRunRoutes(app, deps) {
|
|
|
83700
84189
|
if (!req) return reply.status(404).send({ ok: false, error: "request not found" });
|
|
83701
84190
|
const policy = policyFor(req.type);
|
|
83702
84191
|
if (!policy.runnable) return reply.status(400).send({ ok: false, error: policy.why, code: "not-runnable" });
|
|
84192
|
+
if (!deps.buildPrompt(req).trim()) {
|
|
84193
|
+
return reply.status(400).send({
|
|
84194
|
+
ok: false,
|
|
84195
|
+
code: "no-prompt",
|
|
84196
|
+
error: "floless can\u2019t compose an instruction for this request, so there is nothing to hand a terminal AI. Clear it and queue it again."
|
|
84197
|
+
});
|
|
84198
|
+
}
|
|
83703
84199
|
if (req.run && (req.run.state === "queued" || req.run.state === "running")) {
|
|
83704
84200
|
return reply.status(409).send({ ok: false, error: "this request is already running", code: "running" });
|
|
83705
84201
|
}
|
|
83706
84202
|
if (req.appId !== void 0 && !isSafeAppId(req.appId)) {
|
|
83707
84203
|
return reply.status(400).send({ ok: false, error: "This request names a workflow floless can\u2019t identify.", code: "bad-app-id" });
|
|
83708
84204
|
}
|
|
83709
|
-
const
|
|
84205
|
+
const asked = request.body?.runtime;
|
|
84206
|
+
const runtime = asked == null ? resolveProvider() : detectRuntimes().find((r) => r.id === asked && r.state === "found")?.id ?? null;
|
|
83710
84207
|
if (!runtime) {
|
|
83711
|
-
return reply.status(400).send({
|
|
84208
|
+
return reply.status(400).send({
|
|
84209
|
+
ok: false,
|
|
84210
|
+
code: "no-runtime",
|
|
84211
|
+
error: asked == null ? "No terminal AI found on this machine." : `floless can\u2019t find ${String(asked)} on this machine.`
|
|
84212
|
+
});
|
|
83712
84213
|
}
|
|
83713
84214
|
const projectKey = req.project ?? req.appId ?? null;
|
|
83714
84215
|
const folder = resolveRunFolder(projectKey);
|
|
@@ -83952,9 +84453,9 @@ async function stopAllRuns(deps) {
|
|
|
83952
84453
|
}
|
|
83953
84454
|
|
|
83954
84455
|
// skill-sync.ts
|
|
83955
|
-
var
|
|
83956
|
-
var
|
|
83957
|
-
var
|
|
84456
|
+
var import_node_fs66 = require("node:fs");
|
|
84457
|
+
var import_node_os32 = require("node:os");
|
|
84458
|
+
var import_node_path61 = require("node:path");
|
|
83958
84459
|
var import_node_url4 = require("node:url");
|
|
83959
84460
|
var import_yaml11 = __toESM(require_dist6(), 1);
|
|
83960
84461
|
|
|
@@ -84001,30 +84502,30 @@ function selectShippedSkillNames(names) {
|
|
|
84001
84502
|
}
|
|
84002
84503
|
|
|
84003
84504
|
// skill-sync.ts
|
|
84004
|
-
var __dirname3 = (0,
|
|
84505
|
+
var __dirname3 = (0, import_node_path61.dirname)((0, import_node_url4.fileURLToPath)(__import_meta_url));
|
|
84005
84506
|
function bundledSkillsRoot() {
|
|
84006
84507
|
const candidates = [
|
|
84007
|
-
(0,
|
|
84008
|
-
(0,
|
|
84009
|
-
(0,
|
|
84508
|
+
(0, import_node_path61.join)(__dirname3, "skills"),
|
|
84509
|
+
(0, import_node_path61.join)((0, import_node_path61.dirname)(process.execPath), "skills"),
|
|
84510
|
+
(0, import_node_path61.join)(__dirname3, "..", ".claude", "skills")
|
|
84010
84511
|
];
|
|
84011
|
-
return candidates.find((p) => (0,
|
|
84512
|
+
return candidates.find((p) => (0, import_node_fs66.existsSync)(p)) ?? null;
|
|
84012
84513
|
}
|
|
84013
84514
|
function targetConfigDirs() {
|
|
84014
84515
|
const override = process.env.FLOLESS_SKILL_TARGETS;
|
|
84015
84516
|
if (override) {
|
|
84016
84517
|
return override.split(";").map((d) => d.trim()).filter(Boolean).map((dir) => ({ runtime: "custom", dir }));
|
|
84017
84518
|
}
|
|
84018
|
-
const home = (0,
|
|
84519
|
+
const home = (0, import_node_os32.homedir)();
|
|
84019
84520
|
return [
|
|
84020
|
-
{ runtime: "claude", dir: (0,
|
|
84021
|
-
{ runtime: "codex", dir: (0,
|
|
84022
|
-
{ runtime: "opencode", dir: (0,
|
|
84521
|
+
{ runtime: "claude", dir: (0, import_node_path61.join)(home, ".claude") },
|
|
84522
|
+
{ runtime: "codex", dir: (0, import_node_path61.join)(home, ".codex") },
|
|
84523
|
+
{ runtime: "opencode", dir: (0, import_node_path61.join)(home, ".opencode") }
|
|
84023
84524
|
];
|
|
84024
84525
|
}
|
|
84025
84526
|
function skillVersion(skillMdPath) {
|
|
84026
84527
|
try {
|
|
84027
|
-
const text3 = (0,
|
|
84528
|
+
const text3 = (0, import_node_fs66.readFileSync)(skillMdPath, "utf8");
|
|
84028
84529
|
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text3);
|
|
84029
84530
|
if (!m || m[1] === void 0) return null;
|
|
84030
84531
|
const fm = (0, import_yaml11.parse)(m[1]);
|
|
@@ -84064,21 +84565,21 @@ function decideAction(installed, bundled) {
|
|
|
84064
84565
|
function bundledSkills(root5) {
|
|
84065
84566
|
let entries2 = [];
|
|
84066
84567
|
try {
|
|
84067
|
-
entries2 = selectShippedSkillNames((0,
|
|
84568
|
+
entries2 = selectShippedSkillNames((0, import_node_fs66.readdirSync)(root5));
|
|
84068
84569
|
} catch {
|
|
84069
84570
|
return [];
|
|
84070
84571
|
}
|
|
84071
84572
|
const out = [];
|
|
84072
84573
|
for (const name of entries2) {
|
|
84073
|
-
const dir = (0,
|
|
84574
|
+
const dir = (0, import_node_path61.join)(root5, name);
|
|
84074
84575
|
let isDir = false;
|
|
84075
84576
|
try {
|
|
84076
|
-
isDir = (0,
|
|
84577
|
+
isDir = (0, import_node_fs66.statSync)(dir).isDirectory();
|
|
84077
84578
|
} catch {
|
|
84078
84579
|
isDir = false;
|
|
84079
84580
|
}
|
|
84080
84581
|
if (!isDir) continue;
|
|
84081
|
-
const v = skillVersion((0,
|
|
84582
|
+
const v = skillVersion((0, import_node_path61.join)(dir, "SKILL.md"));
|
|
84082
84583
|
if (!v) continue;
|
|
84083
84584
|
out.push({ name, dir, version: v });
|
|
84084
84585
|
}
|
|
@@ -84091,17 +84592,17 @@ function syncSkills() {
|
|
|
84091
84592
|
const skills = bundledSkills(root5);
|
|
84092
84593
|
if (!skills.length) return results;
|
|
84093
84594
|
for (const { runtime, dir: cfg } of targetConfigDirs()) {
|
|
84094
|
-
if (!(0,
|
|
84095
|
-
const skillsDir = (0,
|
|
84595
|
+
if (!(0, import_node_fs66.existsSync)(cfg)) continue;
|
|
84596
|
+
const skillsDir = (0, import_node_path61.join)(cfg, "skills");
|
|
84096
84597
|
for (const s of skills) {
|
|
84097
|
-
const dest = (0,
|
|
84098
|
-
const installedMd = (0,
|
|
84099
|
-
const installed = (0,
|
|
84598
|
+
const dest = (0, import_node_path61.join)(skillsDir, s.name);
|
|
84599
|
+
const installedMd = (0, import_node_path61.join)(dest, "SKILL.md");
|
|
84600
|
+
const installed = (0, import_node_fs66.existsSync)(installedMd) ? skillVersion(installedMd) : null;
|
|
84100
84601
|
const action = decideAction(installed, s.version);
|
|
84101
84602
|
if (action === "installed" || action === "updated") {
|
|
84102
84603
|
try {
|
|
84103
|
-
if (action === "updated") (0,
|
|
84104
|
-
(0,
|
|
84604
|
+
if (action === "updated") (0, import_node_fs66.rmSync)(dest, { recursive: true, force: true });
|
|
84605
|
+
(0, import_node_fs66.cpSync)(s.dir, dest, { recursive: true });
|
|
84105
84606
|
results.push({ runtime, skill: s.name, action, from: installed, to: s.version });
|
|
84106
84607
|
} catch {
|
|
84107
84608
|
}
|
|
@@ -84114,9 +84615,9 @@ function syncSkills() {
|
|
|
84114
84615
|
}
|
|
84115
84616
|
|
|
84116
84617
|
// watch.ts
|
|
84117
|
-
var
|
|
84118
|
-
var
|
|
84119
|
-
var
|
|
84618
|
+
var import_node_os33 = require("node:os");
|
|
84619
|
+
var import_node_path63 = require("node:path");
|
|
84620
|
+
var import_node_fs67 = require("node:fs");
|
|
84120
84621
|
|
|
84121
84622
|
// node_modules/chokidar/esm/index.js
|
|
84122
84623
|
var import_fs2 = require("fs");
|
|
@@ -84127,7 +84628,7 @@ var sysPath2 = __toESM(require("path"), 1);
|
|
|
84127
84628
|
// node_modules/readdirp/esm/index.js
|
|
84128
84629
|
var import_promises8 = require("node:fs/promises");
|
|
84129
84630
|
var import_node_stream4 = require("node:stream");
|
|
84130
|
-
var
|
|
84631
|
+
var import_node_path62 = require("node:path");
|
|
84131
84632
|
var EntryTypes = {
|
|
84132
84633
|
FILE_TYPE: "files",
|
|
84133
84634
|
DIR_TYPE: "directories",
|
|
@@ -84202,7 +84703,7 @@ var ReaddirpStream = class extends import_node_stream4.Readable {
|
|
|
84202
84703
|
this._wantsDir = type ? DIR_TYPES.has(type) : false;
|
|
84203
84704
|
this._wantsFile = type ? FILE_TYPES.has(type) : false;
|
|
84204
84705
|
this._wantsEverything = type === EntryTypes.EVERYTHING_TYPE;
|
|
84205
|
-
this._root = (0,
|
|
84706
|
+
this._root = (0, import_node_path62.resolve)(root5);
|
|
84206
84707
|
this._isDirent = !opts.alwaysStat;
|
|
84207
84708
|
this._statsProp = this._isDirent ? "dirent" : "stats";
|
|
84208
84709
|
this._rdOptions = { encoding: "utf8", withFileTypes: this._isDirent };
|
|
@@ -84271,10 +84772,10 @@ var ReaddirpStream = class extends import_node_stream4.Readable {
|
|
|
84271
84772
|
}
|
|
84272
84773
|
async _formatEntry(dirent, path) {
|
|
84273
84774
|
let entry2;
|
|
84274
|
-
const
|
|
84775
|
+
const basename15 = this._isDirent ? dirent.name : dirent;
|
|
84275
84776
|
try {
|
|
84276
|
-
const fullPath = (0,
|
|
84277
|
-
entry2 = { path: (0,
|
|
84777
|
+
const fullPath = (0, import_node_path62.resolve)((0, import_node_path62.join)(path, basename15));
|
|
84778
|
+
entry2 = { path: (0, import_node_path62.relative)(this._root, fullPath), fullPath, basename: basename15 };
|
|
84278
84779
|
entry2[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
|
84279
84780
|
} catch (err2) {
|
|
84280
84781
|
this._onError(err2);
|
|
@@ -84308,7 +84809,7 @@ var ReaddirpStream = class extends import_node_stream4.Readable {
|
|
|
84308
84809
|
}
|
|
84309
84810
|
if (entryRealPathStats.isDirectory()) {
|
|
84310
84811
|
const len = entryRealPath.length;
|
|
84311
|
-
if (full.startsWith(entryRealPath) && full.substr(len, 1) ===
|
|
84812
|
+
if (full.startsWith(entryRealPath) && full.substr(len, 1) === import_node_path62.sep) {
|
|
84312
84813
|
const recursiveError = new Error(`Circular symlink detected: "${full}" points to "${entryRealPath}"`);
|
|
84313
84814
|
recursiveError.code = RECURSIVE_ERROR_CODE;
|
|
84314
84815
|
return this._onError(recursiveError);
|
|
@@ -84813,9 +85314,9 @@ var NodeFsHandler = class {
|
|
|
84813
85314
|
_watchWithNodeFs(path, listener) {
|
|
84814
85315
|
const opts = this.fsw.options;
|
|
84815
85316
|
const directory = sysPath.dirname(path);
|
|
84816
|
-
const
|
|
85317
|
+
const basename15 = sysPath.basename(path);
|
|
84817
85318
|
const parent = this.fsw._getWatchedDir(directory);
|
|
84818
|
-
parent.add(
|
|
85319
|
+
parent.add(basename15);
|
|
84819
85320
|
const absolutePath = sysPath.resolve(path);
|
|
84820
85321
|
const options = {
|
|
84821
85322
|
persistent: opts.persistent
|
|
@@ -84825,7 +85326,7 @@ var NodeFsHandler = class {
|
|
|
84825
85326
|
let closer;
|
|
84826
85327
|
if (opts.usePolling) {
|
|
84827
85328
|
const enableBin = opts.interval !== opts.binaryInterval;
|
|
84828
|
-
options.interval = enableBin && isBinaryPath(
|
|
85329
|
+
options.interval = enableBin && isBinaryPath(basename15) ? opts.binaryInterval : opts.interval;
|
|
84829
85330
|
closer = setFsWatchFileListener(path, absolutePath, options, {
|
|
84830
85331
|
listener,
|
|
84831
85332
|
rawEmitter: this.fsw._emitRaw
|
|
@@ -84847,11 +85348,11 @@ var NodeFsHandler = class {
|
|
|
84847
85348
|
if (this.fsw.closed) {
|
|
84848
85349
|
return;
|
|
84849
85350
|
}
|
|
84850
|
-
const
|
|
84851
|
-
const
|
|
84852
|
-
const parent = this.fsw._getWatchedDir(
|
|
85351
|
+
const dirname28 = sysPath.dirname(file);
|
|
85352
|
+
const basename15 = sysPath.basename(file);
|
|
85353
|
+
const parent = this.fsw._getWatchedDir(dirname28);
|
|
84853
85354
|
let prevStats = stats;
|
|
84854
|
-
if (parent.has(
|
|
85355
|
+
if (parent.has(basename15))
|
|
84855
85356
|
return;
|
|
84856
85357
|
const listener = async (path, newStats) => {
|
|
84857
85358
|
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
|
|
@@ -84876,9 +85377,9 @@ var NodeFsHandler = class {
|
|
|
84876
85377
|
prevStats = newStats2;
|
|
84877
85378
|
}
|
|
84878
85379
|
} catch (error) {
|
|
84879
|
-
this.fsw._remove(
|
|
85380
|
+
this.fsw._remove(dirname28, basename15);
|
|
84880
85381
|
}
|
|
84881
|
-
} else if (parent.has(
|
|
85382
|
+
} else if (parent.has(basename15)) {
|
|
84882
85383
|
const at = newStats.atimeMs;
|
|
84883
85384
|
const mt = newStats.mtimeMs;
|
|
84884
85385
|
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
|
|
@@ -85816,33 +86317,33 @@ function appIdFromLogPath(path) {
|
|
|
85816
86317
|
return i >= 0 && parts[i + 1] ? parts[i + 1] : null;
|
|
85817
86318
|
}
|
|
85818
86319
|
function samePath(a, b) {
|
|
85819
|
-
const ra = (0,
|
|
85820
|
-
const rb = (0,
|
|
86320
|
+
const ra = (0, import_node_path63.resolve)(a);
|
|
86321
|
+
const rb = (0, import_node_path63.resolve)(b);
|
|
85821
86322
|
return process.platform === "win32" ? ra.toLowerCase() === rb.toLowerCase() : ra === rb;
|
|
85822
86323
|
}
|
|
85823
86324
|
function underDir(path, dir) {
|
|
85824
|
-
const rp = (0,
|
|
85825
|
-
const rd = (0,
|
|
86325
|
+
const rp = (0, import_node_path63.resolve)(path);
|
|
86326
|
+
const rd = (0, import_node_path63.resolve)(dir);
|
|
85826
86327
|
const [p, d] = process.platform === "win32" ? [rp.toLowerCase(), rd.toLowerCase()] : [rp, rd];
|
|
85827
|
-
return p === d || p.startsWith(d +
|
|
86328
|
+
return p === d || p.startsWith(d + import_node_path63.sep);
|
|
85828
86329
|
}
|
|
85829
86330
|
function startWatcher() {
|
|
85830
|
-
const awareDir = process.env.AWARE_HOME ?? (0,
|
|
85831
|
-
const credentialsDir = (0,
|
|
85832
|
-
if (!(0,
|
|
86331
|
+
const awareDir = process.env.AWARE_HOME ?? (0, import_node_path63.join)((0, import_node_os33.homedir)(), ".aware");
|
|
86332
|
+
const credentialsDir = (0, import_node_path63.join)(awareDir, "credentials");
|
|
86333
|
+
if (!(0, import_node_fs67.existsSync)(credentialsDir)) {
|
|
85833
86334
|
try {
|
|
85834
|
-
(0,
|
|
86335
|
+
(0, import_node_fs67.mkdirSync)(credentialsDir, { recursive: true });
|
|
85835
86336
|
} catch {
|
|
85836
86337
|
}
|
|
85837
86338
|
}
|
|
85838
|
-
if (!(0,
|
|
86339
|
+
if (!(0, import_node_fs67.existsSync)(uiDir)) {
|
|
85839
86340
|
try {
|
|
85840
|
-
(0,
|
|
86341
|
+
(0, import_node_fs67.mkdirSync)(uiDir, { recursive: true });
|
|
85841
86342
|
} catch {
|
|
85842
86343
|
}
|
|
85843
86344
|
}
|
|
85844
|
-
const targets = ["apps", "logs", "credentials"].map((d) => (0,
|
|
85845
|
-
if ((0,
|
|
86345
|
+
const targets = ["apps", "logs", "credentials"].map((d) => (0, import_node_path63.join)(awareDir, d)).filter((p) => (0, import_node_fs67.existsSync)(p));
|
|
86346
|
+
if ((0, import_node_fs67.existsSync)(uiDir)) targets.push(uiDir);
|
|
85846
86347
|
if (targets.length === 0) {
|
|
85847
86348
|
return null;
|
|
85848
86349
|
}
|
|
@@ -85871,11 +86372,11 @@ function startWatcher() {
|
|
|
85871
86372
|
const isCredential = path.split(/[\\/]/).includes("credentials");
|
|
85872
86373
|
const kind = isCredential ? "credential" : path.endsWith(".jsonl") ? "trace" : path.endsWith(".lock") ? "lock" : path.endsWith(".flo") || path.endsWith(".app") ? "source" : "file";
|
|
85873
86374
|
broadcast({ type: "fs-change", kind, event, path });
|
|
85874
|
-
if (kind === "trace" && event !== "unlink" && (0,
|
|
86375
|
+
if (kind === "trace" && event !== "unlink" && (0, import_node_fs67.existsSync)(path)) {
|
|
85875
86376
|
const id = appIdFromLogPath(path);
|
|
85876
86377
|
if (!id) return;
|
|
85877
86378
|
try {
|
|
85878
|
-
broadcast({ type: "trace-file", id, runId: path.split(
|
|
86379
|
+
broadcast({ type: "trace-file", id, runId: path.split(import_node_path63.sep).pop()?.replace(/\.jsonl$/, "") ?? null, events: parseTrace((0, import_node_fs67.readFileSync)(path, "utf8")) });
|
|
85879
86380
|
} catch {
|
|
85880
86381
|
}
|
|
85881
86382
|
}
|
|
@@ -85884,10 +86385,10 @@ function startWatcher() {
|
|
|
85884
86385
|
}
|
|
85885
86386
|
|
|
85886
86387
|
// index.ts
|
|
85887
|
-
var __dirname4 = (0,
|
|
85888
|
-
var WEB_ROOT = [(0,
|
|
85889
|
-
(p) => (0,
|
|
85890
|
-
) ?? (0,
|
|
86388
|
+
var __dirname4 = (0, import_node_path64.dirname)((0, import_node_url5.fileURLToPath)(__import_meta_url));
|
|
86389
|
+
var WEB_ROOT = [(0, import_node_path64.join)(__dirname4, "web"), (0, import_node_path64.join)((0, import_node_path64.dirname)(process.execPath), "web"), (0, import_node_path64.join)(__dirname4, "..", "web")].find(
|
|
86390
|
+
(p) => (0, import_node_fs68.existsSync)(p)
|
|
86391
|
+
) ?? (0, import_node_path64.join)(__dirname4, "..", "web");
|
|
85891
86392
|
var PORT2 = Number(process.env.PORT ?? 4317);
|
|
85892
86393
|
var HOST = "127.0.0.1";
|
|
85893
86394
|
var crashHandlersInstalled = false;
|
|
@@ -85903,7 +86404,7 @@ function installCrashHandlers() {
|
|
|
85903
86404
|
${stack}
|
|
85904
86405
|
`;
|
|
85905
86406
|
try {
|
|
85906
|
-
(0,
|
|
86407
|
+
(0, import_node_fs68.appendFileSync)(logFilePath(), line);
|
|
85907
86408
|
} catch {
|
|
85908
86409
|
}
|
|
85909
86410
|
if (process.stderr.isTTY) process.stderr.write(line);
|
|
@@ -85998,12 +86499,12 @@ async function startServer() {
|
|
|
85998
86499
|
skip: process.env.AWARE_SKIP_BOOTSTRAP === "1",
|
|
85999
86500
|
logWarn: (msg, fields) => app.log.warn(fields, msg)
|
|
86000
86501
|
};
|
|
86001
|
-
const AWARE_BRIDGE_DIRECTORY = (0,
|
|
86502
|
+
const AWARE_BRIDGE_DIRECTORY = (0, import_node_path64.join)((0, import_node_os34.homedir)(), ".aware", "bridges");
|
|
86002
86503
|
const awareMaintenance = createMaintenanceMarkerStore(
|
|
86003
|
-
(0,
|
|
86504
|
+
(0, import_node_path64.join)((0, import_node_os34.homedir)(), ".floless", "aware-maintenance.json")
|
|
86004
86505
|
);
|
|
86005
86506
|
const awareBridgePending = createBridgePendingStore(
|
|
86006
|
-
(0,
|
|
86507
|
+
(0, import_node_path64.join)((0, import_node_os34.homedir)(), ".floless", "aware-bridge-pending.json")
|
|
86007
86508
|
);
|
|
86008
86509
|
async function staleBridgesForInstalledRuntime() {
|
|
86009
86510
|
const target = aware.npmVersion();
|
|
@@ -86559,16 +87060,17 @@ async function startServer() {
|
|
|
86559
87060
|
const bdir = backupDir(id, fromVersion, Date.now());
|
|
86560
87061
|
let backedUp = false;
|
|
86561
87062
|
try {
|
|
86562
|
-
(0,
|
|
86563
|
-
(0,
|
|
87063
|
+
(0, import_node_fs68.mkdirSync)((0, import_node_path64.dirname)(bdir), { recursive: true });
|
|
87064
|
+
(0, import_node_fs68.cpSync)(appDirPath2, bdir, { recursive: true });
|
|
86564
87065
|
backedUp = true;
|
|
86565
|
-
(0,
|
|
87066
|
+
(0, import_node_fs68.cpSync)(templatePath, srcPath);
|
|
86566
87067
|
if (id !== templateId) stampSourceAppId(srcPath, id);
|
|
86567
87068
|
if (contract != null) {
|
|
86568
87069
|
bakeContractIntoApp(srcPath, contract);
|
|
86569
87070
|
await bakeDownstream(srcPath, id, contract);
|
|
86570
87071
|
}
|
|
86571
87072
|
await aware.compile(srcPath);
|
|
87073
|
+
await dropPinBytes(id);
|
|
86572
87074
|
return { backupPath: bdir };
|
|
86573
87075
|
} catch (e) {
|
|
86574
87076
|
const msg = e instanceof Error ? e.message : String(e);
|
|
@@ -86576,8 +87078,8 @@ async function startServer() {
|
|
|
86576
87078
|
throw new TemplateSwapError(`${verb} failed before any change was made (${msg}) \u2014 the workflow is untouched`, `${verb}-not-started`);
|
|
86577
87079
|
}
|
|
86578
87080
|
try {
|
|
86579
|
-
(0,
|
|
86580
|
-
(0,
|
|
87081
|
+
(0, import_node_fs68.rmSync)(appDirPath2, { recursive: true, force: true });
|
|
87082
|
+
(0, import_node_fs68.cpSync)(bdir, appDirPath2, { recursive: true });
|
|
86581
87083
|
} catch (re) {
|
|
86582
87084
|
const rmsg = re instanceof Error ? re.message : String(re);
|
|
86583
87085
|
throw new TemplateSwapError(`${verb} failed (${msg}) AND rollback failed (${rmsg}) \u2014 restore manually from ${bdir}`, "rollback-failed", bdir);
|
|
@@ -86589,7 +87091,7 @@ async function startServer() {
|
|
|
86589
87091
|
function readSwapContract(id, verb) {
|
|
86590
87092
|
const gerund = verb === "update" ? "updating" : "restoring";
|
|
86591
87093
|
const contract = readAcceptedForRequest(id, void 0);
|
|
86592
|
-
if (contract == null && (0,
|
|
87094
|
+
if (contract == null && (0, import_node_fs68.existsSync)(contractPath(id))) {
|
|
86593
87095
|
return { ok: false, body: { ok: false, error: `"${id}"'s saved data is unreadable \u2014 open it in the editor and re-save before ${gerund}`, code: "contract-corrupt" } };
|
|
86594
87096
|
}
|
|
86595
87097
|
if (contract != null && !validateContract(contract).valid) {
|
|
@@ -86661,7 +87163,14 @@ async function startServer() {
|
|
|
86661
87163
|
const res = await run2();
|
|
86662
87164
|
result = { type: "agent-install-result", action, id, ok: true, installed: res.installed ?? id };
|
|
86663
87165
|
} catch (err2) {
|
|
86664
|
-
|
|
87166
|
+
const fallback2 = `Could not ${action} \u201C${id}\u201D.`;
|
|
87167
|
+
result = {
|
|
87168
|
+
type: "agent-install-result",
|
|
87169
|
+
action,
|
|
87170
|
+
id,
|
|
87171
|
+
ok: false,
|
|
87172
|
+
error: action === "update" ? agentUpdateFailureMessage(err2, id) : awareFailureMessage(err2, fallback2)
|
|
87173
|
+
};
|
|
86665
87174
|
} finally {
|
|
86666
87175
|
agentJobsInFlight.delete(id);
|
|
86667
87176
|
}
|
|
@@ -86758,7 +87267,8 @@ async function startServer() {
|
|
|
86758
87267
|
};
|
|
86759
87268
|
const requestContractType = (r, memo) => {
|
|
86760
87269
|
if (r.type !== "revision-read" || !r.appId || !r.project) return void 0;
|
|
86761
|
-
|
|
87270
|
+
const project = getProject(r.project);
|
|
87271
|
+
if (!project || !sameAppLineage(r.appId, project.app)) return void 0;
|
|
86762
87272
|
return storedContractType(r.appId, r.project, memo);
|
|
86763
87273
|
};
|
|
86764
87274
|
const requestProjectName = (r, memo) => {
|
|
@@ -86822,7 +87332,12 @@ async function startServer() {
|
|
|
86822
87332
|
{ kind: "project", key: req.params.id }
|
|
86823
87333
|
);
|
|
86824
87334
|
const before = getProject(req.params.id);
|
|
86825
|
-
const project = renameProject(req.params.id, req.body?.name)
|
|
87335
|
+
const project = await renameProject(req.params.id, req.body?.name, async (fromId, toId) => {
|
|
87336
|
+
await repointProjectPins(fromId, toId);
|
|
87337
|
+
return async () => {
|
|
87338
|
+
await repointProjectPins(toId, fromId);
|
|
87339
|
+
};
|
|
87340
|
+
});
|
|
86826
87341
|
if (!before) {
|
|
86827
87342
|
req.log.error({ id: req.params.id }, "rename: pre-read missing \u2014 other tabs cannot reconcile this rename");
|
|
86828
87343
|
} else if (before.id !== project.id) {
|
|
@@ -86917,7 +87432,7 @@ async function startServer() {
|
|
|
86917
87432
|
}
|
|
86918
87433
|
let data;
|
|
86919
87434
|
try {
|
|
86920
|
-
data = (0,
|
|
87435
|
+
data = (0, import_node_fs68.readFileSync)(thumb.path);
|
|
86921
87436
|
} catch {
|
|
86922
87437
|
return reply.status(404).send({ ok: false, error: "no thumbnail" });
|
|
86923
87438
|
}
|
|
@@ -87285,7 +87800,7 @@ async function startServer() {
|
|
|
87285
87800
|
const { source, contract } = consumeExportHandle(req.body.sourceHandle, project.id, project.uuid);
|
|
87286
87801
|
const safeLabel = source.filenameLabel.replace(/[^A-Za-z0-9._-]+/g, "-");
|
|
87287
87802
|
const filename = uniqueProjectExportFilename(project.id, `${exportFileBase(project.id, project.app)}-${safeLabel}.flo-contract.json`);
|
|
87288
|
-
const savedTo = (0,
|
|
87803
|
+
const savedTo = (0, import_node_path64.join)(projectExportsDir(project.id), filename);
|
|
87289
87804
|
durableCanonicalJson(savedTo, {
|
|
87290
87805
|
schema: 1,
|
|
87291
87806
|
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -87341,6 +87856,7 @@ async function startServer() {
|
|
|
87341
87856
|
registerRevisionRoutes(app);
|
|
87342
87857
|
registerSteelPrepassRoute(app, { getProject, clearApproval, broadcast });
|
|
87343
87858
|
registerKnowledgeRoutes(app);
|
|
87859
|
+
registerKbPinRoutes(app, { broadcast });
|
|
87344
87860
|
function projectAppMismatch(appId, project) {
|
|
87345
87861
|
const p = getProject(project);
|
|
87346
87862
|
if (!p) return `unknown project: ${project}`;
|
|
@@ -87449,9 +87965,9 @@ async function startServer() {
|
|
|
87449
87965
|
const bad = projectAppMismatch(req.params.appId, project);
|
|
87450
87966
|
if (bad) return reply.status(404).send({ ok: false, error: bad });
|
|
87451
87967
|
const safe2 = req.params.sheet.replace(/[^A-Za-z0-9._-]/g, "");
|
|
87452
|
-
const file = (0,
|
|
87453
|
-
if (!(0,
|
|
87454
|
-
return reply.type("image/svg+xml").send((0,
|
|
87968
|
+
const file = (0, import_node_path64.join)((0, import_node_path64.dirname)(contractPath(req.params.appId, project)), "details", `${safe2}.svg`);
|
|
87969
|
+
if (!(0, import_node_fs68.existsSync)(file)) return reply.status(404).send({ ok: false, error: "no vector for this sheet" });
|
|
87970
|
+
return reply.type("image/svg+xml").send((0, import_node_fs68.readFileSync)(file, "utf8"));
|
|
87455
87971
|
}
|
|
87456
87972
|
);
|
|
87457
87973
|
app.put(
|
|
@@ -87940,7 +88456,7 @@ async function startServer() {
|
|
|
87940
88456
|
}
|
|
87941
88457
|
const statedAt = (filename) => {
|
|
87942
88458
|
try {
|
|
87943
|
-
const st = (0,
|
|
88459
|
+
const st = (0, import_node_fs68.statSync)((0, import_node_path64.join)(dir, filename));
|
|
87944
88460
|
return st.isFile() ? st.mtime.toISOString() : null;
|
|
87945
88461
|
} catch {
|
|
87946
88462
|
return null;
|
|
@@ -87950,14 +88466,14 @@ async function startServer() {
|
|
|
87950
88466
|
const rows2 = (byKind.get(kind) ?? []).map((receipt) => ({
|
|
87951
88467
|
variant: receipt.variant ?? null,
|
|
87952
88468
|
filename: receipt.filename,
|
|
87953
|
-
path: (0,
|
|
88469
|
+
path: (0, import_node_path64.join)(dir, receipt.filename),
|
|
87954
88470
|
exportedAt: statedAt(receipt.filename)
|
|
87955
88471
|
})).sort((a, b) => String(b.exportedAt ?? "").localeCompare(String(a.exportedAt ?? "")));
|
|
87956
88472
|
const headline = rows2[0];
|
|
87957
88473
|
return {
|
|
87958
88474
|
kind,
|
|
87959
88475
|
filename: headline?.filename ?? legacy,
|
|
87960
|
-
path: headline?.path ?? (0,
|
|
88476
|
+
path: headline?.path ?? (0, import_node_path64.join)(dir, legacy),
|
|
87961
88477
|
exportedAt: headline?.exportedAt ?? null,
|
|
87962
88478
|
...rows2.length ? { variants: rows2 } : {}
|
|
87963
88479
|
};
|
|
@@ -88105,7 +88621,7 @@ async function startServer() {
|
|
|
88105
88621
|
}
|
|
88106
88622
|
if (!hasExportableSceneRecords(scene)) return reply.status(422).send({ ok: false, error: emptyError, skipped });
|
|
88107
88623
|
const filename = `${exportFileBase(project, appId)}${explicitExportSourceSuffix(input)}.ifc`;
|
|
88108
|
-
const finalPath = (0,
|
|
88624
|
+
const finalPath = (0, import_node_path64.join)(project ? projectExportsDir(project) : (0, import_node_path64.dirname)(bomExportPath(appId, "csv")), filename);
|
|
88109
88625
|
const priorProjectIfc = project ? listProjectExportReceipts(project).find((row) => row.kind === "ifc") : void 0;
|
|
88110
88626
|
const tempPath = requestIfcTempPath(finalPath);
|
|
88111
88627
|
try {
|
|
@@ -88113,10 +88629,10 @@ async function startServer() {
|
|
|
88113
88629
|
scene,
|
|
88114
88630
|
"output-path": tempPath
|
|
88115
88631
|
});
|
|
88116
|
-
if (!(0,
|
|
88632
|
+
if (!(0, import_node_fs68.existsSync)(tempPath) || (0, import_node_fs68.statSync)(tempPath).size === 0) {
|
|
88117
88633
|
throw new ReceiptReconciliationError("AWARE reported a successful export but wrote no IFC file.");
|
|
88118
88634
|
}
|
|
88119
|
-
const artifactBytes = (0,
|
|
88635
|
+
const artifactBytes = (0, import_node_fs68.readFileSync)(tempPath);
|
|
88120
88636
|
const receipt = reconcileIfcExportReceipt(scene, rawReceipt, producerUnsupported, {
|
|
88121
88637
|
index: parseStepData(artifactBytes),
|
|
88122
88638
|
bytes: artifactBytes
|
|
@@ -88172,7 +88688,7 @@ async function startServer() {
|
|
|
88172
88688
|
ok: false,
|
|
88173
88689
|
error: awareFailureMessage(error, "IFC export failed"),
|
|
88174
88690
|
...reason ? { reason } : {},
|
|
88175
|
-
preservedPrevious: project && priorProjectIfc ? receiptHasFile(project, priorProjectIfc) : (0,
|
|
88691
|
+
preservedPrevious: project && priorProjectIfc ? receiptHasFile(project, priorProjectIfc) : (0, import_node_fs68.existsSync)(finalPath)
|
|
88176
88692
|
});
|
|
88177
88693
|
} finally {
|
|
88178
88694
|
cleanupIfcTemp(tempPath);
|
|
@@ -88219,10 +88735,10 @@ async function startServer() {
|
|
|
88219
88735
|
const receipt = wanted ? stills.find((row) => row.variant === wanted) : [...stills].sort((a, b) => b.exportedAt.localeCompare(a.exportedAt))[0];
|
|
88220
88736
|
if (!receipt) return reply.status(404).send({ ok: false, error: "nothing rendered yet" });
|
|
88221
88737
|
const path = resolveProjectExportReceiptPath(project, receipt);
|
|
88222
|
-
if (!path || !(0,
|
|
88738
|
+
if (!path || !(0, import_node_fs68.existsSync)(path)) {
|
|
88223
88739
|
return reply.status(404).send({ ok: false, error: "the rendered image is no longer on disk" });
|
|
88224
88740
|
}
|
|
88225
|
-
return reply.header("content-type", "image/png").header("cache-control", "private, max-age=31536000, immutable").send((0,
|
|
88741
|
+
return reply.header("content-type", "image/png").header("cache-control", "private, max-age=31536000, immutable").send((0, import_node_fs68.readFileSync)(path));
|
|
88226
88742
|
});
|
|
88227
88743
|
const RENDER_VIEWPOINTS = /* @__PURE__ */ new Set(["hero", "iso", "front", "back", "left", "right", "top"]);
|
|
88228
88744
|
app.post("/api/contract/:appId/render", async (req, reply) => {
|
|
@@ -88283,8 +88799,8 @@ async function startServer() {
|
|
|
88283
88799
|
}
|
|
88284
88800
|
const kind = output === "turntable" ? "render-mp4" : "render-png";
|
|
88285
88801
|
const extension = output === "turntable" ? ".mp4" : ".png";
|
|
88286
|
-
const scratch = (0,
|
|
88287
|
-
const ifcPath = (0,
|
|
88802
|
+
const scratch = (0, import_node_fs68.mkdtempSync)((0, import_node_path64.join)((0, import_node_os34.tmpdir)(), "floless-render-"));
|
|
88803
|
+
const ifcPath = (0, import_node_path64.join)(scratch, "model.ifc");
|
|
88288
88804
|
const rendered = [];
|
|
88289
88805
|
const progress = (stage, extra = {}) => {
|
|
88290
88806
|
try {
|
|
@@ -88295,13 +88811,13 @@ async function startServer() {
|
|
|
88295
88811
|
try {
|
|
88296
88812
|
progress("preparing");
|
|
88297
88813
|
await aware.agentInvoke("ifc", "write", { scene: built.scene, "output-path": ifcPath });
|
|
88298
|
-
if (!(0,
|
|
88814
|
+
if (!(0, import_node_fs68.existsSync)(ifcPath) || (0, import_node_fs68.statSync)(ifcPath).size === 0) {
|
|
88299
88815
|
throw new Error("AWARE reported a successful IFC write but produced no file to render");
|
|
88300
88816
|
}
|
|
88301
88817
|
const renderBudgetMs = output === "turntable" ? 30 * 6e4 : 10 * 6e4;
|
|
88302
88818
|
for (const [i, viewpoint] of viewpoints.entries()) {
|
|
88303
88819
|
progress("rendering", { viewpoint, index: i + 1, output });
|
|
88304
|
-
const artifactPath = (0,
|
|
88820
|
+
const artifactPath = (0, import_node_path64.join)(scratch, `render-${viewpoint}${extension}`);
|
|
88305
88821
|
const receipt = await aware.agentInvoke(RENDER_AGENT_ID, output === "turntable" ? "render.turntable" : "render.still", {
|
|
88306
88822
|
"ifc-path": ifcPath,
|
|
88307
88823
|
"output-path": artifactPath,
|
|
@@ -88313,10 +88829,10 @@ async function startServer() {
|
|
|
88313
88829
|
environment: "studio",
|
|
88314
88830
|
...output === "turntable" ? { "duration-seconds": 12, fps: 24, "width-pixels": 1280, "height-pixels": 720 } : { quality, "width-pixels": 1920, "height-pixels": 1080 }
|
|
88315
88831
|
}, { timeoutMs: renderBudgetMs });
|
|
88316
|
-
if (!(0,
|
|
88832
|
+
if (!(0, import_node_fs68.existsSync)(artifactPath) || (0, import_node_fs68.statSync)(artifactPath).size === 0) {
|
|
88317
88833
|
throw new Error(`the ${viewpoint} render reported success but produced no image`);
|
|
88318
88834
|
}
|
|
88319
|
-
const bytes = (0,
|
|
88835
|
+
const bytes = (0, import_node_fs68.readFileSync)(artifactPath);
|
|
88320
88836
|
const sourceSuffix = "source" in projectSnapshot && projectSnapshot.source ? `-${projectSnapshot.source.filenameLabel.replace(/[^A-Za-z0-9._-]+/g, "-")}` : "";
|
|
88321
88837
|
const preferred = `${exportFileBase(project, appId)}-${viewpoint}${sourceSuffix}${extension}`;
|
|
88322
88838
|
const filename = uniqueProjectExportFilename(project, preferred);
|
|
@@ -88354,7 +88870,7 @@ async function startServer() {
|
|
|
88354
88870
|
// Kept for a single-viewpoint caller so the existing shape still reads naturally.
|
|
88355
88871
|
filename: rendered[0]?.filename,
|
|
88356
88872
|
viewpoint: rendered[0]?.viewpoint,
|
|
88357
|
-
savedTo: rendered[0] ? (0,
|
|
88873
|
+
savedTo: rendered[0] ? (0, import_node_path64.join)(projectExportsDir(project), rendered[0].filename) : void 0
|
|
88358
88874
|
};
|
|
88359
88875
|
} catch (error) {
|
|
88360
88876
|
const reason = awareStderr(error);
|
|
@@ -88372,7 +88888,7 @@ async function startServer() {
|
|
|
88372
88888
|
rendered
|
|
88373
88889
|
});
|
|
88374
88890
|
} finally {
|
|
88375
|
-
(0,
|
|
88891
|
+
(0, import_node_fs68.rmSync)(scratch, { recursive: true, force: true });
|
|
88376
88892
|
}
|
|
88377
88893
|
}, {
|
|
88378
88894
|
// What anyone blocked on this project is told, and for how long to expect it. Erring long
|
|
@@ -88610,10 +89126,10 @@ async function startServer() {
|
|
|
88610
89126
|
}
|
|
88611
89127
|
const preferredFilename = `${exportFileBase(project, appId)}-bom${explicitExportSourceSuffix(input.source)}.${format}`;
|
|
88612
89128
|
const filename = project ? uniqueProjectExportFilename(project, preferredFilename) : preferredFilename;
|
|
88613
|
-
const outPath = project ? (0,
|
|
88614
|
-
const dir = (0,
|
|
89129
|
+
const outPath = project ? (0, import_node_path64.join)(projectExportsDir(project), filename) : bomExportPath(appId, format);
|
|
89130
|
+
const dir = (0, import_node_path64.dirname)(outPath);
|
|
88615
89131
|
try {
|
|
88616
|
-
(0,
|
|
89132
|
+
(0, import_node_fs68.mkdirSync)(dir, { recursive: true });
|
|
88617
89133
|
const kind = BOM_EXPORT_KIND[format];
|
|
88618
89134
|
let text3 = null;
|
|
88619
89135
|
let buf;
|
|
@@ -88641,8 +89157,8 @@ async function startServer() {
|
|
|
88641
89157
|
sourceKind: projectSnapshot.source?.kind ?? "approved",
|
|
88642
89158
|
contractHash: projectSnapshot.contractHash
|
|
88643
89159
|
}, buf);
|
|
88644
|
-
} else if (text3 != null) (0,
|
|
88645
|
-
else (0,
|
|
89160
|
+
} else if (text3 != null) (0, import_node_fs68.writeFileSync)(outPath, text3, "utf8");
|
|
89161
|
+
else (0, import_node_fs68.writeFileSync)(outPath, buf);
|
|
88646
89162
|
return {
|
|
88647
89163
|
ok: true,
|
|
88648
89164
|
payload: text3 != null ? { filename, encoding: "utf8", content: text3, bytes: buf.length, savedTo: outPath } : { filename, encoding: "base64", content: buf.toString("base64"), bytes: buf.length, savedTo: outPath }
|
|
@@ -88680,9 +89196,9 @@ async function startServer() {
|
|
|
88680
89196
|
const svg = contractToSvg(cleaned);
|
|
88681
89197
|
const preferredFilename = `${exportFileBase(project, appId)}${explicitExportSourceSuffix(input)}.svg`;
|
|
88682
89198
|
const filename = project ? uniqueProjectExportFilename(project, preferredFilename) : preferredFilename;
|
|
88683
|
-
const outPath = project ? (0,
|
|
89199
|
+
const outPath = project ? (0, import_node_path64.join)(projectExportsDir(project), filename) : (0, import_node_path64.join)(appPath(appId), filename);
|
|
88684
89200
|
try {
|
|
88685
|
-
(0,
|
|
89201
|
+
(0, import_node_fs68.mkdirSync)((0, import_node_path64.dirname)(outPath), { recursive: true });
|
|
88686
89202
|
if (project && projectSnapshot) {
|
|
88687
89203
|
publishProjectExportArtifact(project, {
|
|
88688
89204
|
kind: "svg",
|
|
@@ -88693,7 +89209,7 @@ async function startServer() {
|
|
|
88693
89209
|
sourceKind: projectSnapshot.source?.kind ?? "approved",
|
|
88694
89210
|
contractHash: projectSnapshot.contractHash
|
|
88695
89211
|
}, Buffer.from(svg, "utf8"));
|
|
88696
|
-
} else (0,
|
|
89212
|
+
} else (0, import_node_fs68.writeFileSync)(outPath, svg, "utf8");
|
|
88697
89213
|
return { ok: true, filename, encoding: "utf8", content: svg, bytes: Buffer.byteLength(svg), savedTo: outPath };
|
|
88698
89214
|
} catch (e) {
|
|
88699
89215
|
app.log.error({ appId, err: e instanceof Error ? e.message : e }, "export-svg: write failed");
|
|
@@ -88839,12 +89355,12 @@ async function startServer() {
|
|
|
88839
89355
|
if (!id && !sourcePath) return reply.status(400).send({ ok: false, error: "id or sourcePath required" });
|
|
88840
89356
|
const explicitInstalledId = (() => {
|
|
88841
89357
|
if (!sourcePath) return null;
|
|
88842
|
-
const awareRoot = process.env.AWARE_HOME || (0,
|
|
88843
|
-
const rel = (0,
|
|
89358
|
+
const awareRoot = process.env.AWARE_HOME || (0, import_node_path64.join)((0, import_node_os34.homedir)(), ".aware");
|
|
89359
|
+
const rel = (0, import_node_path64.relative)((0, import_node_path64.resolve)(awareRoot, "apps"), (0, import_node_path64.resolve)(sourcePath));
|
|
88844
89360
|
const segments = rel.split(/[\\/]/);
|
|
88845
89361
|
if (segments.length !== 2 || !/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(segments[0])) return null;
|
|
88846
89362
|
try {
|
|
88847
|
-
return (0,
|
|
89363
|
+
return (0, import_node_path64.resolve)(readApp(segments[0]).source.path) === (0, import_node_path64.resolve)(sourcePath) ? segments[0] : null;
|
|
88848
89364
|
} catch {
|
|
88849
89365
|
return null;
|
|
88850
89366
|
}
|
|
@@ -88875,11 +89391,22 @@ async function startServer() {
|
|
|
88875
89391
|
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 });
|
|
88876
89392
|
}
|
|
88877
89393
|
await deleteOrigin(id);
|
|
88878
|
-
const stageRoot = (0, import_node_fs66.mkdtempSync)((0, import_node_path63.join)((0, import_node_os33.tmpdir)(), "floless-import-"));
|
|
88879
89394
|
try {
|
|
88880
|
-
|
|
88881
|
-
|
|
88882
|
-
|
|
89395
|
+
await dropPinBytes(id);
|
|
89396
|
+
} catch (e) {
|
|
89397
|
+
app.log.error({ err: e, id }, "could not drop stale knowledge pin before import");
|
|
89398
|
+
return reply.status(500).send({
|
|
89399
|
+
ok: false,
|
|
89400
|
+
error: "Could not clear stale knowledge provenance before import. Close anything using that file and try again.",
|
|
89401
|
+
code: "kb_pin_cleanup_failed",
|
|
89402
|
+
id
|
|
89403
|
+
});
|
|
89404
|
+
}
|
|
89405
|
+
const stageRoot = (0, import_node_fs68.mkdtempSync)((0, import_node_path64.join)((0, import_node_os34.tmpdir)(), "floless-import-"));
|
|
89406
|
+
try {
|
|
89407
|
+
const stageDir = (0, import_node_path64.join)(stageRoot, id);
|
|
89408
|
+
(0, import_node_fs68.mkdirSync)(stageDir);
|
|
89409
|
+
(0, import_node_fs68.writeFileSync)((0, import_node_path64.join)(stageDir, `${id}.flo`), content);
|
|
88883
89410
|
await aware.install(stageDir);
|
|
88884
89411
|
} catch (err2) {
|
|
88885
89412
|
try {
|
|
@@ -88890,7 +89417,7 @@ async function startServer() {
|
|
|
88890
89417
|
const reason = awareStderr(err2);
|
|
88891
89418
|
return reply.status(502).send({ ok: false, error: `import failed: ${msg}`, code: "install-failed", reason, agentsUnavailable: unavailableAgents(reason) });
|
|
88892
89419
|
} finally {
|
|
88893
|
-
(0,
|
|
89420
|
+
(0, import_node_fs68.rmSync)(stageRoot, { recursive: true, force: true });
|
|
88894
89421
|
}
|
|
88895
89422
|
broadcast({ type: "apps-changed", id });
|
|
88896
89423
|
return { ok: true, id };
|
|
@@ -88906,13 +89433,13 @@ async function startServer() {
|
|
|
88906
89433
|
}
|
|
88907
89434
|
const inputs = appData.inputs.map((i) => ({ name: i.name, type: i.type }));
|
|
88908
89435
|
const baked = bakeFloSource(appData.source.text, inputs);
|
|
88909
|
-
const tmpRoot = (0,
|
|
88910
|
-
const backupDir2 = (0,
|
|
88911
|
-
const bakeDir = (0,
|
|
88912
|
-
(0,
|
|
88913
|
-
(0,
|
|
89436
|
+
const tmpRoot = (0, import_node_fs68.mkdtempSync)((0, import_node_path64.join)((0, import_node_os34.tmpdir)(), "floless-bake-"));
|
|
89437
|
+
const backupDir2 = (0, import_node_path64.join)(tmpRoot, `${id}-backup`);
|
|
89438
|
+
const bakeDir = (0, import_node_path64.join)(tmpRoot, id);
|
|
89439
|
+
(0, import_node_fs68.cpSync)(appDir(id), backupDir2, { recursive: true });
|
|
89440
|
+
(0, import_node_fs68.cpSync)(appDir(id), bakeDir, { recursive: true });
|
|
88914
89441
|
const floName = appData.source.path.split(/[\\/]/).pop();
|
|
88915
|
-
(0,
|
|
89442
|
+
(0, import_node_fs68.writeFileSync)((0, import_node_path64.join)(bakeDir, floName), baked);
|
|
88916
89443
|
let appInstalled2 = true;
|
|
88917
89444
|
try {
|
|
88918
89445
|
await aware.uninstall(id);
|
|
@@ -88934,18 +89461,18 @@ async function startServer() {
|
|
|
88934
89461
|
throw installErr;
|
|
88935
89462
|
}
|
|
88936
89463
|
try {
|
|
88937
|
-
await aware.compile((0,
|
|
89464
|
+
await aware.compile((0, import_node_path64.join)(appDir(id), floName));
|
|
88938
89465
|
} catch (compileErr) {
|
|
88939
89466
|
app.log.warn({ id, compileErr: String(compileErr) }, "bake: post-install recompile failed (app baked but may need a manual Compile)");
|
|
88940
89467
|
}
|
|
88941
89468
|
broadcast({ type: "baked", id });
|
|
88942
89469
|
return { ok: true, id, agent: id, inputs };
|
|
88943
89470
|
} finally {
|
|
88944
|
-
if (appInstalled2) (0,
|
|
89471
|
+
if (appInstalled2) (0, import_node_fs68.rmSync)(tmpRoot, { recursive: true, force: true });
|
|
88945
89472
|
}
|
|
88946
89473
|
});
|
|
88947
89474
|
});
|
|
88948
|
-
const graftAgentsDir = () => (0,
|
|
89475
|
+
const graftAgentsDir = () => (0, import_node_path64.join)((0, import_node_os34.homedir)(), ".aware", "agents");
|
|
88949
89476
|
app.post("/api/graft/match", async (req, reply) => {
|
|
88950
89477
|
const { glob } = req.body ?? {};
|
|
88951
89478
|
if (!glob) return reply.status(400).send({ ok: false, error: "glob required" });
|
|
@@ -88962,7 +89489,7 @@ async function startServer() {
|
|
|
88962
89489
|
if (!sourceKind || !sourceRef) {
|
|
88963
89490
|
return reply.status(400).send({ ok: false, error: "sourceKind and sourceRef required" });
|
|
88964
89491
|
}
|
|
88965
|
-
const tempHome = (0,
|
|
89492
|
+
const tempHome = (0, import_node_fs68.mkdtempSync)((0, import_node_path64.join)((0, import_node_os34.tmpdir)(), "floless-graft-"));
|
|
88966
89493
|
let result;
|
|
88967
89494
|
try {
|
|
88968
89495
|
result = await aware.build({
|
|
@@ -88975,19 +89502,19 @@ async function startServer() {
|
|
|
88975
89502
|
awareHome: tempHome
|
|
88976
89503
|
});
|
|
88977
89504
|
} catch (err2) {
|
|
88978
|
-
(0,
|
|
89505
|
+
(0, import_node_fs68.rmSync)(tempHome, { recursive: true, force: true });
|
|
88979
89506
|
const msg = err2 instanceof AwareError ? err2.message : String(err2?.message ?? err2);
|
|
88980
89507
|
return reply.status(422).send({ ok: false, error: msg });
|
|
88981
89508
|
}
|
|
88982
89509
|
const manifest = readStagedManifest(result.agentDir);
|
|
88983
89510
|
if (!manifest) {
|
|
88984
|
-
(0,
|
|
89511
|
+
(0, import_node_fs68.rmSync)(tempHome, { recursive: true, force: true });
|
|
88985
89512
|
return reply.status(502).send({ ok: false, error: `build produced output at ${result.agentDir} but no manifest.yaml` });
|
|
88986
89513
|
}
|
|
88987
89514
|
const token2 = (0, import_node_crypto35.randomUUID)();
|
|
88988
89515
|
registerStage(token2, tempHome, result.agentId);
|
|
88989
89516
|
const preview2 = buildPreview(manifest, sourceKind, sourceRef, token2);
|
|
88990
|
-
if ((0,
|
|
89517
|
+
if ((0, import_node_fs68.existsSync)((0, import_node_path64.join)(graftAgentsDir(), result.agentId))) {
|
|
88991
89518
|
preview2.warnings.unshift(`An agent named "${result.agentId}" is already installed \u2014 creating it will overwrite it.`);
|
|
88992
89519
|
}
|
|
88993
89520
|
return { ok: true, preview: preview2 };
|
|
@@ -89006,7 +89533,7 @@ async function startServer() {
|
|
|
89006
89533
|
registerStage(stagedRef, stage.tempDir, stage.agentId);
|
|
89007
89534
|
return reply.status(409).send({ ok: false, error: err2.message, agentId: stage.agentId, collision: true });
|
|
89008
89535
|
}
|
|
89009
|
-
(0,
|
|
89536
|
+
(0, import_node_fs68.rmSync)(stage.tempDir, { recursive: true, force: true });
|
|
89010
89537
|
throw err2;
|
|
89011
89538
|
}
|
|
89012
89539
|
broadcast({ type: "grafted", id: stage.agentId });
|
|
@@ -89289,18 +89816,18 @@ async function startServer() {
|
|
|
89289
89816
|
app.get("/api/requests/:id/snapshot/:n", async (req, reply) => {
|
|
89290
89817
|
const n = Number.parseInt(req.params.n, 10);
|
|
89291
89818
|
const p = Number.isInteger(n) ? snapshotPathFor(req.params.id, n) : null;
|
|
89292
|
-
if (!p || !(0,
|
|
89819
|
+
if (!p || !(0, import_node_fs68.existsSync)(p)) return reply.status(404).send({ ok: false, error: "snapshot not found" });
|
|
89293
89820
|
const ext = p.split(".").pop().toLowerCase();
|
|
89294
89821
|
reply.header("Content-Type", ext === "png" ? "image/png" : ext === "webp" ? "image/webp" : ext === "pdf" ? "application/pdf" : "image/jpeg");
|
|
89295
89822
|
reply.header("Cache-Control", "no-store");
|
|
89296
|
-
return (0,
|
|
89823
|
+
return (0, import_node_fs68.readFileSync)(p);
|
|
89297
89824
|
});
|
|
89298
89825
|
app.post(
|
|
89299
89826
|
"/api/tweak",
|
|
89300
89827
|
{ bodyLimit: 25 * 1024 * 1024 },
|
|
89301
89828
|
async (req, reply) => {
|
|
89302
89829
|
const { appId, nodeId, instruction, snapshots } = req.body ?? {};
|
|
89303
|
-
if (!appId || !nodeId || !instruction) {
|
|
89830
|
+
if (!isSafeAppId2(appId) || !nodeId || !instruction) {
|
|
89304
89831
|
return reply.status(400).send({ ok: false, error: "appId, nodeId, instruction required" });
|
|
89305
89832
|
}
|
|
89306
89833
|
let decoded;
|
|
@@ -89314,28 +89841,7 @@ async function startServer() {
|
|
|
89314
89841
|
return { ok: true, request: requestView2(request) };
|
|
89315
89842
|
}
|
|
89316
89843
|
);
|
|
89317
|
-
app
|
|
89318
|
-
"/api/contract-request",
|
|
89319
|
-
{ bodyLimit: 25 * 1024 * 1024 },
|
|
89320
|
-
async (req, reply) => {
|
|
89321
|
-
const { appId, project, instruction, intent, target, snapshots } = req.body ?? {};
|
|
89322
|
-
if (!appId || !instruction) {
|
|
89323
|
-
return reply.status(400).send({ ok: false, error: "appId, instruction required" });
|
|
89324
|
-
}
|
|
89325
|
-
let decoded;
|
|
89326
|
-
try {
|
|
89327
|
-
decoded = decodeSnapshots(snapshots);
|
|
89328
|
-
} catch (e) {
|
|
89329
|
-
return reply.status(400).send({ ok: false, error: e instanceof Error ? e.message : "bad snapshot" });
|
|
89330
|
-
}
|
|
89331
|
-
const request = addRequest(
|
|
89332
|
-
{ type: "tweak-contract", appId, ...project ? { project } : {}, instruction, ...intent ? { intent } : {}, ...target ? { target } : {} },
|
|
89333
|
-
decoded
|
|
89334
|
-
);
|
|
89335
|
-
broadcast({ type: "request-added", request });
|
|
89336
|
-
return { ok: true, request: requestView2(request) };
|
|
89337
|
-
}
|
|
89338
|
-
);
|
|
89844
|
+
registerContractRequestRoute(app, { broadcast, requestView: requestView2 });
|
|
89339
89845
|
const REBAKE_INSTRUCTION = "Re-read the attached drawing and re-bake the extracted values into this app's config.yaml (the literals the deterministic run uses), then `aware app compile` the app and tell me to approve the new lock. Do not change node logic \u2014 only the baked config values.";
|
|
89340
89846
|
app.post(
|
|
89341
89847
|
"/api/rebake",
|
|
@@ -89345,7 +89851,7 @@ async function startServer() {
|
|
|
89345
89851
|
async (req, reply) => {
|
|
89346
89852
|
const { appId, inputName, instruction, snapshots } = req.body ?? {};
|
|
89347
89853
|
const sourceName = typeof req.body?.sourceName === "string" ? req.body.sourceName : void 0;
|
|
89348
|
-
if (!appId) return reply.status(400).send({ ok: false, error: "appId required" });
|
|
89854
|
+
if (!isSafeAppId2(appId)) return reply.status(400).send({ ok: false, error: "a valid appId is required" });
|
|
89349
89855
|
let decoded;
|
|
89350
89856
|
try {
|
|
89351
89857
|
decoded = decodeSnapshots(snapshots);
|
|
@@ -89437,7 +89943,7 @@ async function startServer() {
|
|
|
89437
89943
|
);
|
|
89438
89944
|
app.post("/api/use-template", async (req, reply) => {
|
|
89439
89945
|
const { appId, templateId } = req.body ?? {};
|
|
89440
|
-
if (!appId || !templateId) return reply.status(400).send({ ok: false, error: "appId and templateId required" });
|
|
89946
|
+
if (!isSafeAppId2(appId) || !templateId) return reply.status(400).send({ ok: false, error: "a valid appId and templateId are required" });
|
|
89441
89947
|
const template = getTemplate(templateId);
|
|
89442
89948
|
if (!template) return reply.status(404).send({ ok: false, error: "template not found" });
|
|
89443
89949
|
const request = addRequest({ type: "use-template", appId, templateId, template });
|
|
@@ -89446,7 +89952,7 @@ async function startServer() {
|
|
|
89446
89952
|
});
|
|
89447
89953
|
app.post("/api/guide", async (req, reply) => {
|
|
89448
89954
|
const { appId } = req.body ?? {};
|
|
89449
|
-
if (!appId) return reply.status(400).send({ ok: false, error: "appId required" });
|
|
89955
|
+
if (!isSafeAppId2(appId)) return reply.status(400).send({ ok: false, error: "a valid appId is required" });
|
|
89450
89956
|
const request = addRequest({ type: "guide", appId });
|
|
89451
89957
|
broadcast({ type: "request-added", request });
|
|
89452
89958
|
return { ok: true, request: requestView2(request) };
|
|
@@ -89471,7 +89977,8 @@ async function startServer() {
|
|
|
89471
89977
|
patchRequest,
|
|
89472
89978
|
buildPrompt: (r) => {
|
|
89473
89979
|
const v = requestView2(r);
|
|
89474
|
-
return v
|
|
89980
|
+
return v && v.marker && v.prompt ? `${v.marker}
|
|
89981
|
+
${v.prompt}` : "";
|
|
89475
89982
|
},
|
|
89476
89983
|
broadcast,
|
|
89477
89984
|
// The relay executes its approved calls through fastify's own dispatcher rather than over the
|
|
@@ -89552,7 +90059,7 @@ async function startServer() {
|
|
|
89552
90059
|
warn(`last-run-status:${ref} \u2014 trace exists but couldn't be parsed (corrupt/truncated)`);
|
|
89553
90060
|
let finishedAt2 = null;
|
|
89554
90061
|
try {
|
|
89555
|
-
finishedAt2 = (0,
|
|
90062
|
+
finishedAt2 = (0, import_node_fs68.statSync)(latest.path).mtime.toISOString();
|
|
89556
90063
|
} catch {
|
|
89557
90064
|
finishedAt2 = null;
|
|
89558
90065
|
}
|
|
@@ -89562,7 +90069,7 @@ async function startServer() {
|
|
|
89562
90069
|
let finishedAt = typeof runEnd?.ts === "string" ? runEnd.ts : null;
|
|
89563
90070
|
if (!finishedAt) {
|
|
89564
90071
|
try {
|
|
89565
|
-
finishedAt = (0,
|
|
90072
|
+
finishedAt = (0, import_node_fs68.statSync)(latest.path).mtime.toISOString();
|
|
89566
90073
|
} catch {
|
|
89567
90074
|
finishedAt = null;
|
|
89568
90075
|
}
|
|
@@ -89701,8 +90208,13 @@ async function startServer() {
|
|
|
89701
90208
|
await app.listen({ port: PORT2, host: HOST });
|
|
89702
90209
|
app.log.info(`floless.app on http://${HOST}:${PORT2} (aware npm ${getBootstrapState().awareVersion ?? "unresolved"})`);
|
|
89703
90210
|
try {
|
|
89704
|
-
const
|
|
89705
|
-
|
|
90211
|
+
const manifest = syncWorkspaceAgentManifest(PORT2);
|
|
90212
|
+
const logFields = { manifestPath: manifest.path, owner: manifest.owner, previousOwner: manifest.previousOwner };
|
|
90213
|
+
if (manifest.outcome === "preserved-live-owner") {
|
|
90214
|
+
app.log.info(logFields, "preserved floless-workspace AWARE agent manifest owned by a live server");
|
|
90215
|
+
} else {
|
|
90216
|
+
app.log.info({ ...logFields, outcome: manifest.outcome }, "wrote floless-workspace AWARE agent manifest");
|
|
90217
|
+
}
|
|
89706
90218
|
} catch (err2) {
|
|
89707
90219
|
app.log.warn({ err: String(err2) }, "workspace agent manifest sync failed (non-fatal)");
|
|
89708
90220
|
}
|