@floless/app 0.126.0 → 0.126.1
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 +904 -885
- package/dist/templates/dummy-report.flo +6 -0
- package/dist/templates/floless-workspace-knowledge.flo +6 -0
- package/dist/templates/floless-workspace-read.flo +6 -0
- package/dist/templates/tekla-bom-by-phase.flo +6 -0
- package/dist/templates/tekla-pdf-takeoff.flo +6 -0
- package/dist/templates/tekla-selection-now.flo +10 -0
- package/dist/templates/tekla-selection-report.flo +10 -0
- package/dist/web/aware-update-client.js +0 -2
- package/dist/web/aware.js +0 -5
- package/dist/web/steel-3d-core.js +77 -0
- package/dist/web/steel-3d-view.js +4 -7
- package/dist/web/steel-editor.html +21 -9
- package/dist/web/steel-model-v2-commands.js +23 -3
- package/package.json +4 -1
package/dist/floless-server.cjs
CHANGED
|
@@ -50829,7 +50829,7 @@ var import_node_readline2 = require("node:readline");
|
|
|
50829
50829
|
var import_node_url5 = require("node:url");
|
|
50830
50830
|
var import_node_path59 = require("node:path");
|
|
50831
50831
|
var import_node_os29 = require("node:os");
|
|
50832
|
-
var
|
|
50832
|
+
var import_node_fs63 = require("node:fs");
|
|
50833
50833
|
var import_node_child_process12 = require("node:child_process");
|
|
50834
50834
|
var import_node_util5 = require("node:util");
|
|
50835
50835
|
|
|
@@ -50876,7 +50876,7 @@ var import_static = __toESM(require_static(), 1);
|
|
|
50876
50876
|
|
|
50877
50877
|
// aware-adapter.ts
|
|
50878
50878
|
var import_node_child_process2 = require("node:child_process");
|
|
50879
|
-
var
|
|
50879
|
+
var import_node_fs9 = require("node:fs");
|
|
50880
50880
|
var import_node_path7 = require("node:path");
|
|
50881
50881
|
var import_node_os7 = require("node:os");
|
|
50882
50882
|
var import_node_crypto5 = require("node:crypto");
|
|
@@ -50884,21 +50884,43 @@ var import_node_module = require("node:module");
|
|
|
50884
50884
|
|
|
50885
50885
|
// app-reader.ts
|
|
50886
50886
|
var import_node_crypto4 = require("node:crypto");
|
|
50887
|
-
var
|
|
50887
|
+
var import_node_fs8 = require("node:fs");
|
|
50888
50888
|
var import_node_os6 = require("node:os");
|
|
50889
50889
|
var import_node_path6 = require("node:path");
|
|
50890
50890
|
var import_yaml = __toESM(require_dist6(), 1);
|
|
50891
50891
|
|
|
50892
50892
|
// app-origin-store.ts
|
|
50893
|
-
var
|
|
50893
|
+
var import_node_fs7 = require("node:fs");
|
|
50894
50894
|
var import_node_os5 = require("node:os");
|
|
50895
50895
|
var import_node_path5 = require("node:path");
|
|
50896
50896
|
var import_node_crypto3 = require("node:crypto");
|
|
50897
50897
|
var import_node_util = require("node:util");
|
|
50898
50898
|
|
|
50899
|
+
// fsync.ts
|
|
50900
|
+
var import_node_fs3 = require("node:fs");
|
|
50901
|
+
function syncFile(path) {
|
|
50902
|
+
const fd2 = (0, import_node_fs3.openSync)(path, "r+");
|
|
50903
|
+
try {
|
|
50904
|
+
(0, import_node_fs3.fsyncSync)(fd2);
|
|
50905
|
+
} finally {
|
|
50906
|
+
(0, import_node_fs3.closeSync)(fd2);
|
|
50907
|
+
}
|
|
50908
|
+
}
|
|
50909
|
+
function syncDirectoryBestEffort(path) {
|
|
50910
|
+
try {
|
|
50911
|
+
const fd2 = (0, import_node_fs3.openSync)(path, "r");
|
|
50912
|
+
try {
|
|
50913
|
+
(0, import_node_fs3.fsyncSync)(fd2);
|
|
50914
|
+
} finally {
|
|
50915
|
+
(0, import_node_fs3.closeSync)(fd2);
|
|
50916
|
+
}
|
|
50917
|
+
} catch {
|
|
50918
|
+
}
|
|
50919
|
+
}
|
|
50920
|
+
|
|
50899
50921
|
// visual-input-store.ts
|
|
50900
50922
|
var import_node_crypto = require("node:crypto");
|
|
50901
|
-
var
|
|
50923
|
+
var import_node_fs4 = require("node:fs");
|
|
50902
50924
|
var import_node_os2 = require("node:os");
|
|
50903
50925
|
var import_node_path2 = require("node:path");
|
|
50904
50926
|
var MAX_BYTES2 = 100 * 1024 * 1024;
|
|
@@ -50943,13 +50965,13 @@ function storeVisualInput(appId, dataUrl) {
|
|
|
50943
50965
|
if (target !== root5 && !target.startsWith(root5 + import_node_path2.sep)) {
|
|
50944
50966
|
throw new VisualInputError("refusing to write outside the inputs root");
|
|
50945
50967
|
}
|
|
50946
|
-
(0,
|
|
50947
|
-
if (!(0,
|
|
50968
|
+
(0, import_node_fs4.mkdirSync)(dir, { recursive: true });
|
|
50969
|
+
if (!(0, import_node_fs4.existsSync)(path)) {
|
|
50948
50970
|
const tmp = `${path}.tmp`;
|
|
50949
|
-
(0,
|
|
50950
|
-
(0,
|
|
50971
|
+
(0, import_node_fs4.writeFileSync)(tmp, buf);
|
|
50972
|
+
(0, import_node_fs4.renameSync)(tmp, path);
|
|
50951
50973
|
}
|
|
50952
|
-
return { path, ext, bytes: (0,
|
|
50974
|
+
return { path, ext, bytes: (0, import_node_fs4.statSync)(path).size, sha256: sha2563 };
|
|
50953
50975
|
}
|
|
50954
50976
|
var MAX_IFC_BYTES = 64 * 1024 * 1024;
|
|
50955
50977
|
var mb = (bytes) => `${Math.round(bytes / (1024 * 1024))} MB`;
|
|
@@ -50977,47 +50999,47 @@ function storeIfcInput(appId, dataUrl, maxBytes = MAX_IFC_BYTES) {
|
|
|
50977
50999
|
if (target !== root5 && !target.startsWith(root5 + import_node_path2.sep)) {
|
|
50978
51000
|
throw new VisualInputError("refusing to write outside the inputs root");
|
|
50979
51001
|
}
|
|
50980
|
-
(0,
|
|
50981
|
-
if (!(0,
|
|
51002
|
+
(0, import_node_fs4.mkdirSync)(dir, { recursive: true });
|
|
51003
|
+
if (!(0, import_node_fs4.existsSync)(path)) {
|
|
50982
51004
|
const tmp = `${path}.tmp`;
|
|
50983
|
-
(0,
|
|
50984
|
-
(0,
|
|
51005
|
+
(0, import_node_fs4.writeFileSync)(tmp, buf);
|
|
51006
|
+
(0, import_node_fs4.renameSync)(tmp, path);
|
|
50985
51007
|
}
|
|
50986
|
-
return { path, sha256: sha2563, bytes: (0,
|
|
51008
|
+
return { path, sha256: sha2563, bytes: (0, import_node_fs4.statSync)(path).size };
|
|
50987
51009
|
}
|
|
50988
51010
|
function ifcInputPath(appId, sha2563) {
|
|
50989
51011
|
if (!safeSegment(appId) || !safeSegment(sha2563) || !/^[a-f0-9]{64}$/i.test(sha2563)) return null;
|
|
50990
51012
|
const root5 = (0, import_node_path2.resolve)(inputsDir());
|
|
50991
51013
|
for (const ext of ["ifc", "ifczip"]) {
|
|
50992
51014
|
const path = (0, import_node_path2.resolve)((0, import_node_path2.join)(inputsDir(), appId, `${sha2563}.${ext}`));
|
|
50993
|
-
if ((path === root5 || path.startsWith(root5 + import_node_path2.sep)) && (0,
|
|
51015
|
+
if ((path === root5 || path.startsWith(root5 + import_node_path2.sep)) && (0, import_node_fs4.existsSync)(path)) return path;
|
|
50994
51016
|
}
|
|
50995
51017
|
return null;
|
|
50996
51018
|
}
|
|
50997
51019
|
function renameVisualInputs(oldId, newId) {
|
|
50998
51020
|
if (!safeSegment(oldId) || !safeSegment(newId)) throw new VisualInputError("invalid app id");
|
|
50999
51021
|
const from = (0, import_node_path2.join)(inputsDir(), oldId);
|
|
51000
|
-
if (!(0,
|
|
51022
|
+
if (!(0, import_node_fs4.existsSync)(from)) return;
|
|
51001
51023
|
const to = (0, import_node_path2.join)(inputsDir(), newId);
|
|
51002
|
-
if ((0,
|
|
51003
|
-
(0,
|
|
51004
|
-
(0,
|
|
51024
|
+
if ((0, import_node_fs4.existsSync)(to)) (0, import_node_fs4.rmSync)(to, { recursive: true, force: true });
|
|
51025
|
+
(0, import_node_fs4.mkdirSync)(inputsDir(), { recursive: true });
|
|
51026
|
+
(0, import_node_fs4.renameSync)(from, to);
|
|
51005
51027
|
}
|
|
51006
51028
|
function copyVisualInputs(srcId, newId) {
|
|
51007
51029
|
if (!safeSegment(srcId) || !safeSegment(newId)) throw new VisualInputError("invalid app id");
|
|
51008
51030
|
const from = (0, import_node_path2.join)(inputsDir(), srcId);
|
|
51009
|
-
if (!(0,
|
|
51010
|
-
(0,
|
|
51031
|
+
if (!(0, import_node_fs4.existsSync)(from)) return;
|
|
51032
|
+
(0, import_node_fs4.cpSync)(from, (0, import_node_path2.join)(inputsDir(), newId), { recursive: true });
|
|
51011
51033
|
}
|
|
51012
51034
|
function deleteVisualInputs(id) {
|
|
51013
51035
|
if (!safeSegment(id)) throw new VisualInputError("invalid app id");
|
|
51014
51036
|
const dir = (0, import_node_path2.join)(inputsDir(), id);
|
|
51015
|
-
if ((0,
|
|
51037
|
+
if ((0, import_node_fs4.existsSync)(dir)) (0, import_node_fs4.rmSync)(dir, { recursive: true, force: true });
|
|
51016
51038
|
}
|
|
51017
51039
|
|
|
51018
51040
|
// lifecycle-lock.ts
|
|
51019
51041
|
var import_node_async_hooks = require("node:async_hooks");
|
|
51020
|
-
var
|
|
51042
|
+
var import_node_fs5 = require("node:fs");
|
|
51021
51043
|
var import_node_child_process = require("node:child_process");
|
|
51022
51044
|
var import_node_os3 = require("node:os");
|
|
51023
51045
|
var import_node_path3 = require("node:path");
|
|
@@ -51179,9 +51201,9 @@ function processStartIdentity(pid, fresh = false) {
|
|
|
51179
51201
|
let value = null;
|
|
51180
51202
|
try {
|
|
51181
51203
|
if (process.platform === "linux") {
|
|
51182
|
-
const stat4 = (0,
|
|
51204
|
+
const stat4 = (0, import_node_fs5.readFileSync)(`/proc/${pid}/stat`, "utf8");
|
|
51183
51205
|
const fields = stat4.slice(stat4.lastIndexOf(")") + 2).trim().split(/\s+/);
|
|
51184
|
-
const bootId = (0,
|
|
51206
|
+
const bootId = (0, import_node_fs5.readFileSync)("/proc/sys/kernel/random/boot_id", "utf8").trim();
|
|
51185
51207
|
value = fields[19] && bootId ? `${bootId}:${fields[19]}` : null;
|
|
51186
51208
|
} else if (process.platform === "win32") {
|
|
51187
51209
|
const millis = (0, import_node_child_process.execFileSync)("powershell.exe", [
|
|
@@ -51222,7 +51244,7 @@ function processAlive(owner2) {
|
|
|
51222
51244
|
}
|
|
51223
51245
|
if (process.platform === "linux") {
|
|
51224
51246
|
try {
|
|
51225
|
-
const stat4 = (0,
|
|
51247
|
+
const stat4 = (0, import_node_fs5.readFileSync)(`/proc/${pid}/stat`, "utf8");
|
|
51226
51248
|
const fields = stat4.slice(stat4.lastIndexOf(")") + 2).trim().split(/\s+/);
|
|
51227
51249
|
if (fields[0] === "Z") return false;
|
|
51228
51250
|
} catch {
|
|
@@ -51236,7 +51258,7 @@ function processAlive(owner2) {
|
|
|
51236
51258
|
}
|
|
51237
51259
|
function readOwnerFile(file) {
|
|
51238
51260
|
try {
|
|
51239
|
-
const parsed = JSON.parse((0,
|
|
51261
|
+
const parsed = JSON.parse((0, import_node_fs5.readFileSync)(file, "utf8"));
|
|
51240
51262
|
return Number.isInteger(parsed.pid) && typeof parsed.token === "string" && typeof parsed.acquiredAt === "string" && (parsed.started == null || typeof parsed.started === "string") ? parsed : null;
|
|
51241
51263
|
} catch {
|
|
51242
51264
|
return null;
|
|
@@ -51248,9 +51270,9 @@ function readOwner(path) {
|
|
|
51248
51270
|
function publishExclusive(file, bytes) {
|
|
51249
51271
|
const temp = (0, import_node_path3.join)(root(), `.publish-${process.pid}-${(0, import_node_crypto2.randomUUID)()}.tmp`);
|
|
51250
51272
|
try {
|
|
51251
|
-
(0,
|
|
51273
|
+
(0, import_node_fs5.writeFileSync)(temp, bytes, { flag: "wx" });
|
|
51252
51274
|
try {
|
|
51253
|
-
(0,
|
|
51275
|
+
(0, import_node_fs5.linkSync)(temp, file);
|
|
51254
51276
|
return true;
|
|
51255
51277
|
} catch (error) {
|
|
51256
51278
|
const code = error.code;
|
|
@@ -51259,7 +51281,7 @@ function publishExclusive(file, bytes) {
|
|
|
51259
51281
|
}
|
|
51260
51282
|
} finally {
|
|
51261
51283
|
try {
|
|
51262
|
-
(0,
|
|
51284
|
+
(0, import_node_fs5.rmSync)(temp, { force: true });
|
|
51263
51285
|
} catch {
|
|
51264
51286
|
}
|
|
51265
51287
|
}
|
|
@@ -51272,7 +51294,7 @@ function staleGeneration(path, now = Date.now()) {
|
|
|
51272
51294
|
return (0, import_node_crypto2.createHash)("sha256").update(JSON.stringify(owner2)).digest("hex").slice(0, 24);
|
|
51273
51295
|
}
|
|
51274
51296
|
try {
|
|
51275
|
-
const stat4 = (0,
|
|
51297
|
+
const stat4 = (0, import_node_fs5.statSync)(path);
|
|
51276
51298
|
if (now - stat4.mtimeMs <= STALE_MS) return null;
|
|
51277
51299
|
return (0, import_node_crypto2.createHash)("sha256").update(`${stat4.dev}:${stat4.ino}:${stat4.birthtimeMs}:${stat4.mtimeMs}`).digest("hex").slice(0, 24);
|
|
51278
51300
|
} catch {
|
|
@@ -51304,14 +51326,14 @@ function retireStaleLock(path, generation) {
|
|
|
51304
51326
|
if (claim && processAlive(claim)) return false;
|
|
51305
51327
|
if (!claim) {
|
|
51306
51328
|
try {
|
|
51307
|
-
if (Date.now() - (0,
|
|
51329
|
+
if (Date.now() - (0, import_node_fs5.statSync)(claimPath).mtimeMs <= STALE_MS) return false;
|
|
51308
51330
|
} catch {
|
|
51309
51331
|
continue;
|
|
51310
51332
|
}
|
|
51311
51333
|
}
|
|
51312
51334
|
round += 1;
|
|
51313
51335
|
}
|
|
51314
|
-
if ((0,
|
|
51336
|
+
if ((0, import_node_fs5.existsSync)(payload)) return false;
|
|
51315
51337
|
const observedOwner = readOwner(path);
|
|
51316
51338
|
if (staleGeneration(path) !== generation) return false;
|
|
51317
51339
|
if (!observedOwner) {
|
|
@@ -51328,7 +51350,7 @@ function retireStaleLock(path, generation) {
|
|
|
51328
51350
|
}
|
|
51329
51351
|
}
|
|
51330
51352
|
try {
|
|
51331
|
-
(0,
|
|
51353
|
+
(0, import_node_fs5.renameSync)(path, payload);
|
|
51332
51354
|
} catch (error) {
|
|
51333
51355
|
const code = error.code;
|
|
51334
51356
|
if (code === "ENOENT" || code === "EEXIST" || code === "ENOTEMPTY" || code === "EACCES" || code === "EPERM") return false;
|
|
@@ -51337,12 +51359,12 @@ function retireStaleLock(path, generation) {
|
|
|
51337
51359
|
return true;
|
|
51338
51360
|
}
|
|
51339
51361
|
async function acquire(path, kind, key, options) {
|
|
51340
|
-
(0,
|
|
51362
|
+
(0, import_node_fs5.mkdirSync)(root(), { recursive: true });
|
|
51341
51363
|
const budget = options.timeoutMsForTest ?? TIMEOUT_MS;
|
|
51342
51364
|
const deadline = Date.now() + budget;
|
|
51343
51365
|
while (true) {
|
|
51344
51366
|
try {
|
|
51345
|
-
(0,
|
|
51367
|
+
(0, import_node_fs5.mkdirSync)(path);
|
|
51346
51368
|
const owner2 = {
|
|
51347
51369
|
pid: process.pid,
|
|
51348
51370
|
token: PROCESS_TOKEN,
|
|
@@ -51409,11 +51431,11 @@ async function withLifecycleLock(kind, key, fn, options = {}) {
|
|
|
51409
51431
|
next.add(token2);
|
|
51410
51432
|
return await held.run(next, fn);
|
|
51411
51433
|
} finally {
|
|
51412
|
-
if ((0,
|
|
51434
|
+
if ((0, import_node_fs5.existsSync)(path)) {
|
|
51413
51435
|
const owner2 = readOwner(path);
|
|
51414
51436
|
if (owner2?.pid === process.pid && owner2.token === PROCESS_TOKEN) {
|
|
51415
51437
|
try {
|
|
51416
|
-
(0,
|
|
51438
|
+
(0, import_node_fs5.rmSync)(path, { recursive: true, force: true });
|
|
51417
51439
|
} catch (e) {
|
|
51418
51440
|
notifyReleaseFailure(kind, key, path, e);
|
|
51419
51441
|
}
|
|
@@ -51426,7 +51448,7 @@ async function withLifecycleLock(kind, key, fn, options = {}) {
|
|
|
51426
51448
|
}
|
|
51427
51449
|
|
|
51428
51450
|
// aware-app-store-adapter.ts
|
|
51429
|
-
var
|
|
51451
|
+
var import_node_fs6 = require("node:fs");
|
|
51430
51452
|
var import_node_os4 = require("node:os");
|
|
51431
51453
|
var import_node_path4 = require("node:path");
|
|
51432
51454
|
var APP_ID = /^[a-z0-9][a-z0-9._-]*$/i;
|
|
@@ -51438,32 +51460,21 @@ function duplicateProofPath(appId, token2) {
|
|
|
51438
51460
|
const awareRoot = process.env.AWARE_HOME ?? (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".aware");
|
|
51439
51461
|
return (0, import_node_path4.join)(awareRoot, "apps", appId, `.floless-origin-duplicate-${token2}`);
|
|
51440
51462
|
}
|
|
51441
|
-
function syncDirectoryBestEffort(path) {
|
|
51442
|
-
try {
|
|
51443
|
-
const fd2 = (0, import_node_fs5.openSync)(path, "r");
|
|
51444
|
-
try {
|
|
51445
|
-
(0, import_node_fs5.fsyncSync)(fd2);
|
|
51446
|
-
} finally {
|
|
51447
|
-
(0, import_node_fs5.closeSync)(fd2);
|
|
51448
|
-
}
|
|
51449
|
-
} catch {
|
|
51450
|
-
}
|
|
51451
|
-
}
|
|
51452
51463
|
function prepareAwareDuplicateProof(appId, token2) {
|
|
51453
51464
|
const path = duplicateProofPath(appId, token2);
|
|
51454
|
-
const fd2 = (0,
|
|
51465
|
+
const fd2 = (0, import_node_fs6.openSync)(path, "wx");
|
|
51455
51466
|
try {
|
|
51456
|
-
(0,
|
|
51457
|
-
(0,
|
|
51467
|
+
(0, import_node_fs6.writeFileSync)(fd2, token2);
|
|
51468
|
+
(0, import_node_fs6.fsyncSync)(fd2);
|
|
51458
51469
|
} finally {
|
|
51459
|
-
(0,
|
|
51470
|
+
(0, import_node_fs6.closeSync)(fd2);
|
|
51460
51471
|
}
|
|
51461
51472
|
syncDirectoryBestEffort((0, import_node_path4.dirname)(path));
|
|
51462
51473
|
}
|
|
51463
51474
|
function awareDuplicateProofExists(appId, token2) {
|
|
51464
51475
|
const path = duplicateProofPath(appId, token2);
|
|
51465
51476
|
try {
|
|
51466
|
-
return (0,
|
|
51477
|
+
return (0, import_node_fs6.existsSync)(path) && (0, import_node_fs6.statSync)(path).size <= 128 && (0, import_node_fs6.readFileSync)(path, "utf8").trim() === token2;
|
|
51467
51478
|
} catch {
|
|
51468
51479
|
return false;
|
|
51469
51480
|
}
|
|
@@ -51471,7 +51482,7 @@ function awareDuplicateProofExists(appId, token2) {
|
|
|
51471
51482
|
function clearAwareDuplicateProof(appId, token2) {
|
|
51472
51483
|
const path = duplicateProofPath(appId, token2);
|
|
51473
51484
|
if (!awareDuplicateProofExists(appId, token2)) return;
|
|
51474
|
-
(0,
|
|
51485
|
+
(0, import_node_fs6.rmSync)(path, { force: true });
|
|
51475
51486
|
syncDirectoryBestEffort((0, import_node_path4.dirname)(path));
|
|
51476
51487
|
}
|
|
51477
51488
|
|
|
@@ -51488,41 +51499,25 @@ function duplicateJournalDir() {
|
|
|
51488
51499
|
const root5 = process.env.FLOLESS_HOME ?? (0, import_node_path5.join)((0, import_node_os5.homedir)(), ".floless");
|
|
51489
51500
|
return (0, import_node_path5.join)(root5, "app-origin-duplicates");
|
|
51490
51501
|
}
|
|
51491
|
-
function syncDirectoryBestEffort2(dir) {
|
|
51492
|
-
try {
|
|
51493
|
-
const dirFd = (0, import_node_fs6.openSync)(dir, "r");
|
|
51494
|
-
try {
|
|
51495
|
-
(0, import_node_fs6.fsyncSync)(dirFd);
|
|
51496
|
-
} finally {
|
|
51497
|
-
(0, import_node_fs6.closeSync)(dirFd);
|
|
51498
|
-
}
|
|
51499
|
-
} catch {
|
|
51500
|
-
}
|
|
51501
|
-
}
|
|
51502
51502
|
function durableWrite(file, bytes) {
|
|
51503
51503
|
const dir = (0, import_node_path5.dirname)(file);
|
|
51504
|
-
if (!(0,
|
|
51504
|
+
if (!(0, import_node_fs7.existsSync)(dir)) (0, import_node_fs7.mkdirSync)(dir, { recursive: true });
|
|
51505
51505
|
const tmp = `${file}.${process.pid}.${(0, import_node_crypto3.randomUUID)()}.tmp`;
|
|
51506
51506
|
try {
|
|
51507
|
-
(0,
|
|
51508
|
-
|
|
51509
|
-
|
|
51510
|
-
|
|
51511
|
-
} finally {
|
|
51512
|
-
(0, import_node_fs6.closeSync)(tempFd);
|
|
51513
|
-
}
|
|
51514
|
-
(0, import_node_fs6.renameSync)(tmp, file);
|
|
51515
|
-
syncDirectoryBestEffort2(dir);
|
|
51507
|
+
(0, import_node_fs7.writeFileSync)(tmp, bytes, { flag: "wx" });
|
|
51508
|
+
syncFile(tmp);
|
|
51509
|
+
(0, import_node_fs7.renameSync)(tmp, file);
|
|
51510
|
+
syncDirectoryBestEffort(dir);
|
|
51516
51511
|
} finally {
|
|
51517
51512
|
try {
|
|
51518
|
-
(0,
|
|
51513
|
+
(0, import_node_fs7.rmSync)(tmp, { force: true });
|
|
51519
51514
|
} catch {
|
|
51520
51515
|
}
|
|
51521
51516
|
}
|
|
51522
51517
|
}
|
|
51523
51518
|
function loadAll() {
|
|
51524
51519
|
try {
|
|
51525
|
-
const parsed = JSON.parse((0,
|
|
51520
|
+
const parsed = JSON.parse((0, import_node_fs7.readFileSync)(storeFile(), "utf8"));
|
|
51526
51521
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
51527
51522
|
} catch {
|
|
51528
51523
|
return {};
|
|
@@ -51530,10 +51525,10 @@ function loadAll() {
|
|
|
51530
51525
|
}
|
|
51531
51526
|
function loadAllStrict() {
|
|
51532
51527
|
const file = storeFile();
|
|
51533
|
-
if (!(0,
|
|
51528
|
+
if (!(0, import_node_fs7.existsSync)(file)) return {};
|
|
51534
51529
|
let parsed;
|
|
51535
51530
|
try {
|
|
51536
|
-
parsed = JSON.parse((0,
|
|
51531
|
+
parsed = JSON.parse((0, import_node_fs7.readFileSync)(file, "utf8"));
|
|
51537
51532
|
} catch (e) {
|
|
51538
51533
|
throw new Error(`app-origin store is unreadable: ${e instanceof Error ? e.message : String(e)}`);
|
|
51539
51534
|
}
|
|
@@ -51575,12 +51570,12 @@ function duplicateJournalPath(token2) {
|
|
|
51575
51570
|
}
|
|
51576
51571
|
function readRenameJournal(token2) {
|
|
51577
51572
|
const path = journalPath(token2);
|
|
51578
|
-
if (!(0,
|
|
51573
|
+
if (!(0, import_node_fs7.existsSync)(path) || (0, import_node_fs7.statSync)(path).size > 64 * 1024) {
|
|
51579
51574
|
throw new Error("app-origin rename journal is missing or oversized");
|
|
51580
51575
|
}
|
|
51581
51576
|
let parsed;
|
|
51582
51577
|
try {
|
|
51583
|
-
parsed = JSON.parse((0,
|
|
51578
|
+
parsed = JSON.parse((0, import_node_fs7.readFileSync)(path, "utf8"));
|
|
51584
51579
|
} catch (error) {
|
|
51585
51580
|
throw new Error(`app-origin rename journal is unreadable: ${error instanceof Error ? error.message : String(error)}`);
|
|
51586
51581
|
}
|
|
@@ -51613,12 +51608,12 @@ function terminalAuthorityRootIn(all, id) {
|
|
|
51613
51608
|
}
|
|
51614
51609
|
function readDuplicateJournal(token2) {
|
|
51615
51610
|
const path = duplicateJournalPath(token2);
|
|
51616
|
-
if (!(0,
|
|
51611
|
+
if (!(0, import_node_fs7.existsSync)(path) || (0, import_node_fs7.statSync)(path).size > 64 * 1024) {
|
|
51617
51612
|
throw new Error("app-origin duplicate journal is missing or oversized");
|
|
51618
51613
|
}
|
|
51619
51614
|
let parsed;
|
|
51620
51615
|
try {
|
|
51621
|
-
parsed = JSON.parse((0,
|
|
51616
|
+
parsed = JSON.parse((0, import_node_fs7.readFileSync)(path, "utf8"));
|
|
51622
51617
|
} catch (error) {
|
|
51623
51618
|
throw new Error(`app-origin duplicate journal is unreadable: ${error instanceof Error ? error.message : String(error)}`);
|
|
51624
51619
|
}
|
|
@@ -51627,12 +51622,12 @@ function readDuplicateJournal(token2) {
|
|
|
51627
51622
|
return journal;
|
|
51628
51623
|
}
|
|
51629
51624
|
function removeRenameJournal(token2) {
|
|
51630
|
-
(0,
|
|
51631
|
-
|
|
51625
|
+
(0, import_node_fs7.rmSync)(journalPath(token2), { force: true });
|
|
51626
|
+
syncDirectoryBestEffort(renameJournalDir());
|
|
51632
51627
|
}
|
|
51633
51628
|
function removeDuplicateJournal(token2) {
|
|
51634
|
-
(0,
|
|
51635
|
-
|
|
51629
|
+
(0, import_node_fs7.rmSync)(duplicateJournalPath(token2), { force: true });
|
|
51630
|
+
syncDirectoryBestEffort(duplicateJournalDir());
|
|
51636
51631
|
}
|
|
51637
51632
|
function recordAt(all, id) {
|
|
51638
51633
|
return all[id] ?? null;
|
|
@@ -51671,15 +51666,15 @@ function cancelJournalState(journal, all) {
|
|
|
51671
51666
|
}
|
|
51672
51667
|
function pendingRenameJournals() {
|
|
51673
51668
|
const dir = renameJournalDir();
|
|
51674
|
-
if (!(0,
|
|
51675
|
-
const names = (0,
|
|
51669
|
+
if (!(0, import_node_fs7.existsSync)(dir)) return [];
|
|
51670
|
+
const names = (0, import_node_fs7.readdirSync)(dir).filter((name) => name.endsWith(".json"));
|
|
51676
51671
|
if (names.length > 256) throw new Error(`app-origin rename recovery refused ${names.length} journals`);
|
|
51677
51672
|
return names.map((name) => readRenameJournal(name.slice(0, -".json".length)));
|
|
51678
51673
|
}
|
|
51679
51674
|
function pendingDuplicateJournals() {
|
|
51680
51675
|
const dir = duplicateJournalDir();
|
|
51681
|
-
if (!(0,
|
|
51682
|
-
const names = (0,
|
|
51676
|
+
if (!(0, import_node_fs7.existsSync)(dir)) return [];
|
|
51677
|
+
const names = (0, import_node_fs7.readdirSync)(dir).filter((name) => name.endsWith(".json"));
|
|
51683
51678
|
if (names.length > 256) throw new Error(`app-origin duplicate recovery refused ${names.length} journals`);
|
|
51684
51679
|
return names.map((name) => readDuplicateJournal(name.slice(0, -".json".length)));
|
|
51685
51680
|
}
|
|
@@ -51746,8 +51741,8 @@ async function cancelOriginRename(token2) {
|
|
|
51746
51741
|
function reconcileOriginRenameUnlocked(token2) {
|
|
51747
51742
|
const journal = readRenameJournal(token2);
|
|
51748
51743
|
const awareRoot = process.env.AWARE_HOME ?? (0, import_node_path5.join)((0, import_node_os5.homedir)(), ".aware");
|
|
51749
|
-
const oldExists = (0,
|
|
51750
|
-
const newExists = (0,
|
|
51744
|
+
const oldExists = (0, import_node_fs7.existsSync)((0, import_node_path5.join)(awareRoot, "apps", journal.oldId));
|
|
51745
|
+
const newExists = (0, import_node_fs7.existsSync)((0, import_node_path5.join)(awareRoot, "apps", journal.newId));
|
|
51751
51746
|
const all = loadAllStrict();
|
|
51752
51747
|
if (oldExists && newExists && journalState(journal, all) === "before") {
|
|
51753
51748
|
removeRenameJournal(token2);
|
|
@@ -51770,7 +51765,7 @@ async function reconcileOriginRename(token2) {
|
|
|
51770
51765
|
async function recoverPendingOriginRenames() {
|
|
51771
51766
|
return withStoreLock(() => {
|
|
51772
51767
|
const dir = renameJournalDir();
|
|
51773
|
-
if (!(0,
|
|
51768
|
+
if (!(0, import_node_fs7.existsSync)(dir)) return [];
|
|
51774
51769
|
const journals = pendingRenameJournals();
|
|
51775
51770
|
const recovered = [];
|
|
51776
51771
|
for (const journal of journals) {
|
|
@@ -51897,7 +51892,7 @@ async function reconcileOriginDuplicate(token2) {
|
|
|
51897
51892
|
async function recoverPendingOriginDuplicates() {
|
|
51898
51893
|
return withStoreLock(() => {
|
|
51899
51894
|
const dir = duplicateJournalDir();
|
|
51900
|
-
if (!(0,
|
|
51895
|
+
if (!(0, import_node_fs7.existsSync)(dir)) return [];
|
|
51901
51896
|
const recovered = [];
|
|
51902
51897
|
for (const journal of pendingDuplicateJournals()) {
|
|
51903
51898
|
reconcileOriginDuplicateUnlocked(journal.token);
|
|
@@ -52015,7 +52010,7 @@ var AppNotFoundError = class extends Error {
|
|
|
52015
52010
|
function appDir(id) {
|
|
52016
52011
|
if (id.includes("/") || id.includes("\\") || id.includes("..")) throw new AppNotFoundError(id);
|
|
52017
52012
|
const dir = (0, import_node_path6.join)(APPS_DIR, id);
|
|
52018
|
-
if (!(0,
|
|
52013
|
+
if (!(0, import_node_fs8.existsSync)(dir)) throw new AppNotFoundError(id);
|
|
52019
52014
|
return dir;
|
|
52020
52015
|
}
|
|
52021
52016
|
function appPath(id) {
|
|
@@ -52024,7 +52019,7 @@ function appPath(id) {
|
|
|
52024
52019
|
}
|
|
52025
52020
|
function appExists(id) {
|
|
52026
52021
|
if (id.includes("/") || id.includes("\\") || id.includes("..")) return false;
|
|
52027
|
-
return (0,
|
|
52022
|
+
return (0, import_node_fs8.existsSync)((0, import_node_path6.join)(APPS_DIR, id));
|
|
52028
52023
|
}
|
|
52029
52024
|
function appHasSource(id) {
|
|
52030
52025
|
if (!appExists(id)) return false;
|
|
@@ -52036,7 +52031,7 @@ function appHasSource(id) {
|
|
|
52036
52031
|
}
|
|
52037
52032
|
}
|
|
52038
52033
|
function firstWithExt(dir, ext) {
|
|
52039
|
-
const hit = (0,
|
|
52034
|
+
const hit = (0, import_node_fs8.readdirSync)(dir).find((f) => f.toLowerCase().endsWith(ext));
|
|
52040
52035
|
return hit ? (0, import_node_path6.join)(dir, hit) : null;
|
|
52041
52036
|
}
|
|
52042
52037
|
function sha256(text3) {
|
|
@@ -52053,12 +52048,12 @@ function appMeta(id, bypassCache = false) {
|
|
|
52053
52048
|
const dir = appDir(id);
|
|
52054
52049
|
const sourcePath = firstWithExt(dir, ".app") ?? firstWithExt(dir, ".flo");
|
|
52055
52050
|
if (!sourcePath) return META_DEFAULT;
|
|
52056
|
-
const st = (0,
|
|
52051
|
+
const st = (0, import_node_fs8.statSync)(sourcePath);
|
|
52057
52052
|
const hit = bypassCache ? void 0 : metaCache.get(sourcePath);
|
|
52058
52053
|
if (hit && hit.mtimeMs === st.mtimeMs && hit.size === st.size && hit.ino === st.ino) return hit.meta;
|
|
52059
52054
|
sourceParses++;
|
|
52060
|
-
const text3 = (0,
|
|
52061
|
-
const after = (0,
|
|
52055
|
+
const text3 = (0, import_node_fs8.readFileSync)(sourcePath, "utf8");
|
|
52056
|
+
const after = (0, import_node_fs8.statSync)(sourcePath);
|
|
52062
52057
|
const settled = after.mtimeMs === st.mtimeMs && after.size === st.size && after.ino === st.ino;
|
|
52063
52058
|
const remember = (meta2) => {
|
|
52064
52059
|
if (settled && !bypassCache) metaCache.set(sourcePath, { mtimeMs: st.mtimeMs, size: st.size, ino: st.ino, meta: meta2 });
|
|
@@ -52120,12 +52115,12 @@ function readApp(id) {
|
|
|
52120
52115
|
const dir = appDir(id);
|
|
52121
52116
|
const sourcePath = firstWithExt(dir, ".app") ?? firstWithExt(dir, ".flo");
|
|
52122
52117
|
if (!sourcePath) throw new AppNotFoundError(id);
|
|
52123
|
-
const sourceText = (0,
|
|
52118
|
+
const sourceText = (0, import_node_fs8.readFileSync)(sourcePath, "utf8");
|
|
52124
52119
|
const sourceHash = sha256(sourceText);
|
|
52125
52120
|
const src = asRecord((0, import_yaml.parse)(sourceText));
|
|
52126
52121
|
const origin = appOrigin(id);
|
|
52127
52122
|
const lockPath2 = firstWithExt(dir, ".lock");
|
|
52128
|
-
const lockText = lockPath2 ? (0,
|
|
52123
|
+
const lockText = lockPath2 ? (0, import_node_fs8.readFileSync)(lockPath2, "utf8") : null;
|
|
52129
52124
|
const lockDoc = lockText ? asRecord((0, import_yaml.parse)(lockText)) : {};
|
|
52130
52125
|
const lockNodes = Array.isArray(lockDoc.nodes) ? lockDoc.nodes : [];
|
|
52131
52126
|
const lockById = new Map(lockNodes.map((n) => [String(n.id), n]));
|
|
@@ -52233,10 +52228,10 @@ function readCommandSpec(agent, command, agentsDir = AGENTS_DIR) {
|
|
|
52233
52228
|
const safe2 = (n) => !/[/\\\0]/.test(n) && !n.includes("..");
|
|
52234
52229
|
if (!safe2(agent) || !safe2(command)) return null;
|
|
52235
52230
|
const manifestPath2 = (0, import_node_path6.join)(agentsDir, agent, "manifest.yaml");
|
|
52236
|
-
if (!(0,
|
|
52231
|
+
if (!(0, import_node_fs8.existsSync)(manifestPath2)) return null;
|
|
52237
52232
|
let doc;
|
|
52238
52233
|
try {
|
|
52239
|
-
doc = asRecord((0, import_yaml.parse)((0,
|
|
52234
|
+
doc = asRecord((0, import_yaml.parse)((0, import_node_fs8.readFileSync)(manifestPath2, "utf8")));
|
|
52240
52235
|
} catch {
|
|
52241
52236
|
return null;
|
|
52242
52237
|
}
|
|
@@ -52278,10 +52273,10 @@ function readNodeSkill(agent, command, agentsDir = AGENTS_DIR) {
|
|
|
52278
52273
|
const safe2 = (n) => !/[/\\\0]/.test(n) && !n.includes("..");
|
|
52279
52274
|
if (!safe2(agent) || !safe2(command)) return null;
|
|
52280
52275
|
const manifestPath2 = (0, import_node_path6.join)(agentsDir, agent, "manifest.yaml");
|
|
52281
|
-
if (!(0,
|
|
52276
|
+
if (!(0, import_node_fs8.existsSync)(manifestPath2)) return null;
|
|
52282
52277
|
let doc;
|
|
52283
52278
|
try {
|
|
52284
|
-
doc = asRecord((0, import_yaml.parse)((0,
|
|
52279
|
+
doc = asRecord((0, import_yaml.parse)((0, import_node_fs8.readFileSync)(manifestPath2, "utf8")));
|
|
52285
52280
|
} catch {
|
|
52286
52281
|
return null;
|
|
52287
52282
|
}
|
|
@@ -52319,9 +52314,9 @@ var AGENTS_DIR = process.env.AWARE_HOME ? (0, import_node_path6.join)(process.en
|
|
|
52319
52314
|
var CREDENTIALS_DIR = process.env.AWARE_HOME ? (0, import_node_path6.join)(process.env.AWARE_HOME, "credentials") : (0, import_node_path6.join)((0, import_node_os6.homedir)(), ".aware", "credentials");
|
|
52320
52315
|
function credentialStatus(secret) {
|
|
52321
52316
|
const file = (0, import_node_path6.join)(CREDENTIALS_DIR, `${secret}.json`);
|
|
52322
|
-
if (!(0,
|
|
52317
|
+
if (!(0, import_node_fs8.existsSync)(file)) return { status: "disconnected", expiresAt: null };
|
|
52323
52318
|
try {
|
|
52324
|
-
const doc = JSON.parse((0,
|
|
52319
|
+
const doc = JSON.parse((0, import_node_fs8.readFileSync)(file, "utf8"));
|
|
52325
52320
|
const raw = doc["expires_at"] ?? doc["expiresAt"] ?? doc["expiry"];
|
|
52326
52321
|
if (raw != null) {
|
|
52327
52322
|
const ms = typeof raw === "number" ? raw * (raw < 1e12 ? 1e3 : 1) : Date.parse(String(raw));
|
|
@@ -52334,15 +52329,15 @@ function credentialStatus(secret) {
|
|
|
52334
52329
|
return { status: "connected", expiresAt: null };
|
|
52335
52330
|
}
|
|
52336
52331
|
function listIntegrations() {
|
|
52337
|
-
if (!(0,
|
|
52332
|
+
if (!(0, import_node_fs8.existsSync)(AGENTS_DIR)) return [];
|
|
52338
52333
|
const out = [];
|
|
52339
52334
|
const seen = /* @__PURE__ */ new Set();
|
|
52340
52335
|
const safe2 = (n) => !/[/\\\0]/.test(n) && !n.includes("..");
|
|
52341
|
-
for (const agentId of (0,
|
|
52336
|
+
for (const agentId of (0, import_node_fs8.readdirSync)(AGENTS_DIR)) {
|
|
52342
52337
|
if (!safe2(agentId)) continue;
|
|
52343
52338
|
const manifestPath2 = (0, import_node_path6.join)(AGENTS_DIR, agentId, "manifest.yaml");
|
|
52344
|
-
if (!(0,
|
|
52345
|
-
const manifestText = (0,
|
|
52339
|
+
if (!(0, import_node_fs8.existsSync)(manifestPath2)) continue;
|
|
52340
|
+
const manifestText = (0, import_node_fs8.readFileSync)(manifestPath2, "utf8");
|
|
52346
52341
|
if (!manifestText.includes("secrets:")) continue;
|
|
52347
52342
|
let doc;
|
|
52348
52343
|
try {
|
|
@@ -52396,6 +52391,12 @@ function parseTrace(text3) {
|
|
|
52396
52391
|
}
|
|
52397
52392
|
});
|
|
52398
52393
|
}
|
|
52394
|
+
function nodeOutput(traceText, node) {
|
|
52395
|
+
const events = traceText ? parseTrace(traceText) : [];
|
|
52396
|
+
const ev = [...events].reverse().find((e) => e.kind === "node-output" && e.node === node);
|
|
52397
|
+
const data = ev ? ev.data : null;
|
|
52398
|
+
return data && typeof data === "object" ? data : null;
|
|
52399
|
+
}
|
|
52399
52400
|
|
|
52400
52401
|
// aware-lifecycle-gate.ts
|
|
52401
52402
|
var import_node_async_hooks2 = require("node:async_hooks");
|
|
@@ -52697,14 +52698,14 @@ var AwareUnsupportedError = class extends AwareError {
|
|
|
52697
52698
|
};
|
|
52698
52699
|
function resolveInvoker() {
|
|
52699
52700
|
const envDir = process.env.AWARE_CLI_DIR;
|
|
52700
|
-
if (envDir && (0,
|
|
52701
|
+
if (envDir && (0, import_node_fs9.existsSync)((0, import_node_path7.join)(envDir, "scripts/bin/aware.js"))) {
|
|
52701
52702
|
return { head: [nodeExe(), (0, import_node_path7.join)(envDir, "scripts/bin/aware.js")], shell: false, pkgDir: envDir };
|
|
52702
52703
|
}
|
|
52703
52704
|
try {
|
|
52704
52705
|
const root5 = (0, import_node_child_process2.execFileSync)("npm", ["root", "-g"], { encoding: "utf8", shell: process.platform === "win32", windowsHide: true, timeout: 1e4 }).trim();
|
|
52705
52706
|
const pkgDir = (0, import_node_path7.join)(root5, "@aware-aeco", "cli");
|
|
52706
52707
|
const bin = (0, import_node_path7.join)(pkgDir, "scripts/bin/aware.js");
|
|
52707
|
-
if ((0,
|
|
52708
|
+
if ((0, import_node_fs9.existsSync)(bin)) return { head: [nodeExe(), bin], shell: false, pkgDir };
|
|
52708
52709
|
} catch {
|
|
52709
52710
|
}
|
|
52710
52711
|
return { head: ["aware"], shell: process.platform === "win32", pkgDir: null };
|
|
@@ -52721,7 +52722,7 @@ function awareNpmVersion() {
|
|
|
52721
52722
|
const invoker = currentInvoker();
|
|
52722
52723
|
if (!invoker.pkgDir) return null;
|
|
52723
52724
|
try {
|
|
52724
|
-
const pkg = JSON.parse((0,
|
|
52725
|
+
const pkg = JSON.parse((0, import_node_fs9.readFileSync)((0, import_node_path7.join)(invoker.pkgDir, "package.json"), "utf8"));
|
|
52725
52726
|
return typeof pkg.version === "string" ? pkg.version : null;
|
|
52726
52727
|
} catch {
|
|
52727
52728
|
return null;
|
|
@@ -52852,7 +52853,7 @@ function resolveTeklaBridge() {
|
|
|
52852
52853
|
(0, import_node_path7.join)((0, import_node_os7.homedir)(), ".aware", "bridges", "aware-tekla.exe"),
|
|
52853
52854
|
invoker.pkgDir ? (0, import_node_path7.join)(invoker.pkgDir, "binaries", "aware-tekla.exe") : null
|
|
52854
52855
|
].filter((p) => !!p);
|
|
52855
|
-
return candidates.find((p) => (0,
|
|
52856
|
+
return candidates.find((p) => (0, import_node_fs9.existsSync)(p)) ?? null;
|
|
52856
52857
|
}
|
|
52857
52858
|
function teklaBridgeStatus() {
|
|
52858
52859
|
const path = resolveTeklaBridge();
|
|
@@ -52860,7 +52861,7 @@ function teklaBridgeStatus() {
|
|
|
52860
52861
|
const marker = (0, import_node_path7.join)((0, import_node_path7.dirname)(path), "aware-tekla.version");
|
|
52861
52862
|
let version = null;
|
|
52862
52863
|
try {
|
|
52863
|
-
const value = (0,
|
|
52864
|
+
const value = (0, import_node_fs9.readFileSync)(marker, "utf8").trim();
|
|
52864
52865
|
version = value || null;
|
|
52865
52866
|
} catch {
|
|
52866
52867
|
}
|
|
@@ -52873,14 +52874,14 @@ function resolveHostBridge(host) {
|
|
|
52873
52874
|
(0, import_node_path7.join)((0, import_node_os7.homedir)(), ".aware", "bridges", exe),
|
|
52874
52875
|
invoker.pkgDir ? (0, import_node_path7.join)(invoker.pkgDir, "binaries", exe) : null
|
|
52875
52876
|
].filter((p) => !!p);
|
|
52876
|
-
return candidates.find((p) => (0,
|
|
52877
|
+
return candidates.find((p) => (0, import_node_fs9.existsSync)(p)) ?? null;
|
|
52877
52878
|
}
|
|
52878
52879
|
function hostBridgeStatus(host) {
|
|
52879
52880
|
const path = resolveHostBridge(host);
|
|
52880
52881
|
if (!path) return { path: null, version: null };
|
|
52881
52882
|
let version = null;
|
|
52882
52883
|
try {
|
|
52883
|
-
version = (0,
|
|
52884
|
+
version = (0, import_node_fs9.readFileSync)((0, import_node_path7.join)((0, import_node_path7.dirname)(path), `aware-${host}.version`), "utf8").trim() || null;
|
|
52884
52885
|
} catch {
|
|
52885
52886
|
}
|
|
52886
52887
|
return { path, version };
|
|
@@ -52961,7 +52962,7 @@ function sketchupDiscoveryEnv() {
|
|
|
52961
52962
|
}
|
|
52962
52963
|
function resolveConnectionReaderBridge() {
|
|
52963
52964
|
const p = (0, import_node_path7.join)((0, import_node_os7.homedir)(), ".aware", "bridges", "aware-connection-reader.exe");
|
|
52964
|
-
return (0,
|
|
52965
|
+
return (0, import_node_fs9.existsSync)(p) ? p : null;
|
|
52965
52966
|
}
|
|
52966
52967
|
function injectDebugger(code) {
|
|
52967
52968
|
const lines = code.split(/\r?\n/);
|
|
@@ -53068,11 +53069,11 @@ function traceLogPath(id, instance, runId, logsRoot = LOGS_DIR) {
|
|
|
53068
53069
|
}
|
|
53069
53070
|
function latestTracePath(id, logsRoot = LOGS_DIR) {
|
|
53070
53071
|
const appDir2 = (0, import_node_path7.join)(logsRoot, id);
|
|
53071
|
-
if (!(0,
|
|
53072
|
+
if (!(0, import_node_fs9.existsSync)(appDir2)) return null;
|
|
53072
53073
|
let best = null;
|
|
53073
53074
|
let instances;
|
|
53074
53075
|
try {
|
|
53075
|
-
instances = (0,
|
|
53076
|
+
instances = (0, import_node_fs9.readdirSync)(appDir2);
|
|
53076
53077
|
} catch {
|
|
53077
53078
|
return null;
|
|
53078
53079
|
}
|
|
@@ -53080,8 +53081,8 @@ function latestTracePath(id, logsRoot = LOGS_DIR) {
|
|
|
53080
53081
|
const instDir = (0, import_node_path7.join)(appDir2, instance);
|
|
53081
53082
|
let entries2;
|
|
53082
53083
|
try {
|
|
53083
|
-
if (!(0,
|
|
53084
|
-
entries2 = (0,
|
|
53084
|
+
if (!(0, import_node_fs9.statSync)(instDir).isDirectory()) continue;
|
|
53085
|
+
entries2 = (0, import_node_fs9.readdirSync)(instDir);
|
|
53085
53086
|
} catch {
|
|
53086
53087
|
continue;
|
|
53087
53088
|
}
|
|
@@ -53089,7 +53090,7 @@ function latestTracePath(id, logsRoot = LOGS_DIR) {
|
|
|
53089
53090
|
if (!f.endsWith(".jsonl")) continue;
|
|
53090
53091
|
const p = (0, import_node_path7.join)(instDir, f);
|
|
53091
53092
|
try {
|
|
53092
|
-
const m = (0,
|
|
53093
|
+
const m = (0, import_node_fs9.statSync)(p).mtimeMs;
|
|
53093
53094
|
if (!best || m > best.mtimeMs) best = { path: p, mtimeMs: m };
|
|
53094
53095
|
} catch {
|
|
53095
53096
|
}
|
|
@@ -53098,17 +53099,17 @@ function latestTracePath(id, logsRoot = LOGS_DIR) {
|
|
|
53098
53099
|
return best ? best.path : null;
|
|
53099
53100
|
}
|
|
53100
53101
|
function readTail(path, maxBytes) {
|
|
53101
|
-
const size = (0,
|
|
53102
|
-
if (size <= maxBytes) return { text: (0,
|
|
53103
|
-
const fd2 = (0,
|
|
53102
|
+
const size = (0, import_node_fs9.statSync)(path).size;
|
|
53103
|
+
if (size <= maxBytes) return { text: (0, import_node_fs9.readFileSync)(path, "utf8"), truncated: false };
|
|
53104
|
+
const fd2 = (0, import_node_fs9.openSync)(path, "r");
|
|
53104
53105
|
try {
|
|
53105
53106
|
const buf = Buffer.alloc(maxBytes);
|
|
53106
|
-
const read = (0,
|
|
53107
|
+
const read = (0, import_node_fs9.readSync)(fd2, buf, 0, maxBytes, size - maxBytes);
|
|
53107
53108
|
const nl = buf.indexOf(10, 0);
|
|
53108
53109
|
const start = nl >= 0 && nl + 1 <= read ? nl + 1 : 0;
|
|
53109
53110
|
return { text: buf.subarray(start, read).toString("utf8"), truncated: true };
|
|
53110
53111
|
} finally {
|
|
53111
|
-
(0,
|
|
53112
|
+
(0, import_node_fs9.closeSync)(fd2);
|
|
53112
53113
|
}
|
|
53113
53114
|
}
|
|
53114
53115
|
function readLatestTrace(id, logsRoot = LOGS_DIR, maxBytes) {
|
|
@@ -53116,7 +53117,7 @@ function readLatestTrace(id, logsRoot = LOGS_DIR, maxBytes) {
|
|
|
53116
53117
|
if (!p) return null;
|
|
53117
53118
|
let read;
|
|
53118
53119
|
try {
|
|
53119
|
-
read = maxBytes && maxBytes > 0 ? readTail(p, maxBytes) : { text: (0,
|
|
53120
|
+
read = maxBytes && maxBytes > 0 ? readTail(p, maxBytes) : { text: (0, import_node_fs9.readFileSync)(p, "utf8"), truncated: false };
|
|
53120
53121
|
} catch {
|
|
53121
53122
|
return null;
|
|
53122
53123
|
}
|
|
@@ -53171,7 +53172,7 @@ function startTriggerWithLease(id, args, lease) {
|
|
|
53171
53172
|
const readAndEmit = () => {
|
|
53172
53173
|
if (!tracePath || !traceCb) return;
|
|
53173
53174
|
try {
|
|
53174
|
-
const txt = (0,
|
|
53175
|
+
const txt = (0, import_node_fs9.readFileSync)(tracePath, "utf8");
|
|
53175
53176
|
if (txt.length !== lastLen) {
|
|
53176
53177
|
lastLen = txt.length;
|
|
53177
53178
|
traceCb(parseTrace(txt));
|
|
@@ -53241,13 +53242,13 @@ function assertNodeId(id) {
|
|
|
53241
53242
|
var SOURCE_EXT = /\.(flo|app|flow|aware)$/i;
|
|
53242
53243
|
function assertSourcePath(p) {
|
|
53243
53244
|
if (!SOURCE_EXT.test(p)) throw new AwareError(`source must be a .flo/.app file: ${JSON.stringify(p)}`);
|
|
53244
|
-
if (!(0,
|
|
53245
|
-
return (0,
|
|
53245
|
+
if (!(0, import_node_fs9.existsSync)(p)) throw new AwareError(`source path not found: ${JSON.stringify(p)}`);
|
|
53246
|
+
return (0, import_node_fs9.realpathSync)(p);
|
|
53246
53247
|
}
|
|
53247
53248
|
function assertAppDir(p) {
|
|
53248
|
-
if (!(0,
|
|
53249
|
-
const real = (0,
|
|
53250
|
-
if (!(0,
|
|
53249
|
+
if (!(0, import_node_fs9.existsSync)(p)) throw new AwareError(`app dir not found: ${JSON.stringify(p)}`);
|
|
53250
|
+
const real = (0, import_node_fs9.realpathSync)(p);
|
|
53251
|
+
if (!(0, import_node_fs9.statSync)(real).isDirectory()) throw new AwareError(`app dir is not a directory: ${JSON.stringify(p)}`);
|
|
53251
53252
|
return real;
|
|
53252
53253
|
}
|
|
53253
53254
|
var GRAFT_PKG_AT_VER_RE = /^[A-Za-z0-9][\w.@/-]{0,127}$/;
|
|
@@ -53268,8 +53269,8 @@ function assertSourceRef(kind, ref) {
|
|
|
53268
53269
|
case "openapi":
|
|
53269
53270
|
case "yard":
|
|
53270
53271
|
if (GRAFT_URL_RE.test(r)) return r;
|
|
53271
|
-
if (!(0,
|
|
53272
|
-
return (0,
|
|
53272
|
+
if (!(0, import_node_fs9.existsSync)(r)) throw new AwareError(`${kind}: file/dir not found: ${r}`);
|
|
53273
|
+
return (0, import_node_fs9.realpathSync)(r);
|
|
53273
53274
|
case "nuget":
|
|
53274
53275
|
case "npm":
|
|
53275
53276
|
case "ruby":
|
|
@@ -53534,7 +53535,7 @@ var awareImpl = {
|
|
|
53534
53535
|
let ref;
|
|
53535
53536
|
if (inputs !== void 0) {
|
|
53536
53537
|
inputsFile = (0, import_node_path7.join)((0, import_node_os7.tmpdir)(), `floless-agent-inputs-${(0, import_node_crypto5.randomUUID)()}.json`);
|
|
53537
|
-
(0,
|
|
53538
|
+
(0, import_node_fs9.writeFileSync)(inputsFile, JSON.stringify(inputs));
|
|
53538
53539
|
ref = `@${inputsFile}`;
|
|
53539
53540
|
}
|
|
53540
53541
|
const { data } = await runJson(agentInvokeArgv(agent, command, ref), opts.timeoutMs);
|
|
@@ -53550,7 +53551,7 @@ var awareImpl = {
|
|
|
53550
53551
|
} finally {
|
|
53551
53552
|
if (inputsFile) {
|
|
53552
53553
|
try {
|
|
53553
|
-
(0,
|
|
53554
|
+
(0, import_node_fs9.rmSync)(inputsFile);
|
|
53554
53555
|
} catch {
|
|
53555
53556
|
}
|
|
53556
53557
|
}
|
|
@@ -53585,7 +53586,7 @@ var awareImpl = {
|
|
|
53585
53586
|
if (code !== 0) throw new AwareError(`aware app compile failed (exit ${code})`, { stdout, stderr });
|
|
53586
53587
|
const m = stdout.match(/→\s*(.+\.lock)\s*$/m);
|
|
53587
53588
|
const lockPath2 = m?.[1]?.trim() ?? null;
|
|
53588
|
-
const lockText = lockPath2 && (0,
|
|
53589
|
+
const lockText = lockPath2 && (0, import_node_fs9.existsSync)(lockPath2) ? (0, import_node_fs9.readFileSync)(lockPath2, "utf8") : null;
|
|
53589
53590
|
return { lockPath: lockPath2, lockText, output: stdout.trim() };
|
|
53590
53591
|
},
|
|
53591
53592
|
/**
|
|
@@ -53781,7 +53782,7 @@ var awareImpl = {
|
|
|
53781
53782
|
if (code !== 0) throw new AwareError(`aware app run failed (exit ${code})`, { stdout, stderr });
|
|
53782
53783
|
const runId = stdout.match(/run-id\s+([0-9a-f-]{36})/i)?.[1] ?? null;
|
|
53783
53784
|
const tracePath = stdout.match(/trace at\s+(.+\.jsonl)\s*$/m)?.[1]?.trim() ?? null;
|
|
53784
|
-
const traceText = tracePath && (0,
|
|
53785
|
+
const traceText = tracePath && (0, import_node_fs9.existsSync)(tracePath) ? (0, import_node_fs9.readFileSync)(tracePath, "utf8") : null;
|
|
53785
53786
|
return { runId, tracePath, traceText, output: stdout.trim() };
|
|
53786
53787
|
} finally {
|
|
53787
53788
|
if (activeRun === ticket) activeRun = null;
|
|
@@ -53828,7 +53829,7 @@ var aware = new Proxy(awareImpl, {
|
|
|
53828
53829
|
});
|
|
53829
53830
|
|
|
53830
53831
|
// extensions-store.ts
|
|
53831
|
-
var
|
|
53832
|
+
var import_node_fs10 = require("node:fs");
|
|
53832
53833
|
var import_node_os8 = require("node:os");
|
|
53833
53834
|
var import_node_path8 = require("node:path");
|
|
53834
53835
|
var ROOT = process.env.FLOLESS_HOME ?? (0, import_node_path8.join)((0, import_node_os8.homedir)(), ".floless");
|
|
@@ -53837,11 +53838,11 @@ var extensionsFile = (0, import_node_path8.join)(uiDir, "extensions.json");
|
|
|
53837
53838
|
var TIMELINE_FILE = (0, import_node_path8.join)(uiDir, "timeline.json");
|
|
53838
53839
|
var HISTORY_KEEP = 20;
|
|
53839
53840
|
function ensureUiDir() {
|
|
53840
|
-
if (!(0,
|
|
53841
|
+
if (!(0, import_node_fs10.existsSync)(uiDir)) (0, import_node_fs10.mkdirSync)(uiDir, { recursive: true });
|
|
53841
53842
|
}
|
|
53842
53843
|
function readExtensionsText() {
|
|
53843
53844
|
try {
|
|
53844
|
-
return (0,
|
|
53845
|
+
return (0, import_node_fs10.readFileSync)(extensionsFile, "utf8");
|
|
53845
53846
|
} catch {
|
|
53846
53847
|
return null;
|
|
53847
53848
|
}
|
|
@@ -53872,7 +53873,7 @@ function panelsCountOf(text3) {
|
|
|
53872
53873
|
function loadTimeline() {
|
|
53873
53874
|
let text3;
|
|
53874
53875
|
try {
|
|
53875
|
-
text3 = (0,
|
|
53876
|
+
text3 = (0, import_node_fs10.readFileSync)(TIMELINE_FILE, "utf8");
|
|
53876
53877
|
} catch {
|
|
53877
53878
|
return { cursor: -1, entries: [] };
|
|
53878
53879
|
}
|
|
@@ -53896,19 +53897,19 @@ function loadTimeline() {
|
|
|
53896
53897
|
function saveTimeline(t) {
|
|
53897
53898
|
ensureUiDir();
|
|
53898
53899
|
const tmp = `${TIMELINE_FILE}.${process.pid}.tmp`;
|
|
53899
|
-
(0,
|
|
53900
|
-
(0,
|
|
53900
|
+
(0, import_node_fs10.writeFileSync)(tmp, JSON.stringify(t, null, 2));
|
|
53901
|
+
(0, import_node_fs10.renameSync)(tmp, TIMELINE_FILE);
|
|
53901
53902
|
}
|
|
53902
53903
|
function writeExtensionsText(text3) {
|
|
53903
53904
|
ensureUiDir();
|
|
53904
53905
|
const tmp = `${extensionsFile}.${process.pid}.tmp`;
|
|
53905
|
-
(0,
|
|
53906
|
-
(0,
|
|
53906
|
+
(0, import_node_fs10.writeFileSync)(tmp, text3);
|
|
53907
|
+
(0, import_node_fs10.renameSync)(tmp, extensionsFile);
|
|
53907
53908
|
}
|
|
53908
53909
|
function applyState(entry2) {
|
|
53909
53910
|
if (entry2.content === null) {
|
|
53910
53911
|
try {
|
|
53911
|
-
(0,
|
|
53912
|
+
(0, import_node_fs10.rmSync)(extensionsFile);
|
|
53912
53913
|
} catch {
|
|
53913
53914
|
}
|
|
53914
53915
|
} else {
|
|
@@ -54159,7 +54160,7 @@ function runBootstrap(deps) {
|
|
|
54159
54160
|
}
|
|
54160
54161
|
|
|
54161
54162
|
// licensing.ts
|
|
54162
|
-
var
|
|
54163
|
+
var import_node_fs11 = require("node:fs");
|
|
54163
54164
|
var import_node_path9 = require("node:path");
|
|
54164
54165
|
var import_node_os9 = require("node:os");
|
|
54165
54166
|
var import_node_child_process3 = require("node:child_process");
|
|
@@ -54237,13 +54238,13 @@ var STORE_FILES = ["floless-license.json", "floless-license-cache.json", "floles
|
|
|
54237
54238
|
function adoptStore(oldDir, newDir) {
|
|
54238
54239
|
try {
|
|
54239
54240
|
if (oldDir === newDir) return false;
|
|
54240
|
-
if (!(0,
|
|
54241
|
-
if ((0,
|
|
54242
|
-
(0,
|
|
54241
|
+
if (!(0, import_node_fs11.existsSync)((0, import_node_path9.join)(oldDir, "floless-license.json"))) return false;
|
|
54242
|
+
if ((0, import_node_fs11.existsSync)((0, import_node_path9.join)(newDir, "floless-license.json"))) return false;
|
|
54243
|
+
(0, import_node_fs11.mkdirSync)(newDir, { recursive: true });
|
|
54243
54244
|
for (const f of STORE_FILES) {
|
|
54244
54245
|
const oldP = (0, import_node_path9.join)(oldDir, f);
|
|
54245
54246
|
const newP = (0, import_node_path9.join)(newDir, f);
|
|
54246
|
-
if ((0,
|
|
54247
|
+
if ((0, import_node_fs11.existsSync)(oldP) && !(0, import_node_fs11.existsSync)(newP)) (0, import_node_fs11.copyFileSync)(oldP, newP);
|
|
54247
54248
|
}
|
|
54248
54249
|
return true;
|
|
54249
54250
|
} catch {
|
|
@@ -54260,16 +54261,16 @@ function migrateLegacyStore() {
|
|
|
54260
54261
|
}
|
|
54261
54262
|
function readJson(path) {
|
|
54262
54263
|
try {
|
|
54263
|
-
return (0,
|
|
54264
|
+
return (0, import_node_fs11.existsSync)(path) ? JSON.parse((0, import_node_fs11.readFileSync)(path, "utf8")) : null;
|
|
54264
54265
|
} catch {
|
|
54265
54266
|
return null;
|
|
54266
54267
|
}
|
|
54267
54268
|
}
|
|
54268
54269
|
function writeJson(path, value) {
|
|
54269
|
-
(0,
|
|
54270
|
-
(0,
|
|
54270
|
+
(0, import_node_fs11.mkdirSync)(storeDir(), { recursive: true });
|
|
54271
|
+
(0, import_node_fs11.writeFileSync)(path, JSON.stringify(value, null, 2), "utf8");
|
|
54271
54272
|
try {
|
|
54272
|
-
(0,
|
|
54273
|
+
(0, import_node_fs11.chmodSync)(path, 384);
|
|
54273
54274
|
} catch {
|
|
54274
54275
|
}
|
|
54275
54276
|
}
|
|
@@ -54502,7 +54503,7 @@ function logout() {
|
|
|
54502
54503
|
resetSeat();
|
|
54503
54504
|
for (const p of [tokenPath(), cachePath()]) {
|
|
54504
54505
|
try {
|
|
54505
|
-
(0,
|
|
54506
|
+
(0, import_node_fs11.rmSync)(p, { force: true });
|
|
54506
54507
|
} catch {
|
|
54507
54508
|
}
|
|
54508
54509
|
}
|
|
@@ -54575,7 +54576,7 @@ function installId() {
|
|
|
54575
54576
|
// version.ts
|
|
54576
54577
|
var import_node_module3 = require("node:module");
|
|
54577
54578
|
var import_node_path10 = require("node:path");
|
|
54578
|
-
var
|
|
54579
|
+
var import_node_fs12 = require("node:fs");
|
|
54579
54580
|
function resolveVersion(s) {
|
|
54580
54581
|
if (s.isSea) {
|
|
54581
54582
|
const m = s.sqVersionXml?.match(/<version>([^<]+)<\/version>/);
|
|
@@ -54595,7 +54596,7 @@ function isSea2() {
|
|
|
54595
54596
|
function readSqVersionXml() {
|
|
54596
54597
|
try {
|
|
54597
54598
|
const sq = (0, import_node_path10.join)((0, import_node_path10.dirname)(process.execPath), "sq.version");
|
|
54598
|
-
return (0,
|
|
54599
|
+
return (0, import_node_fs12.existsSync)(sq) ? (0, import_node_fs12.readFileSync)(sq, "utf8") : null;
|
|
54599
54600
|
} catch {
|
|
54600
54601
|
return null;
|
|
54601
54602
|
}
|
|
@@ -54611,7 +54612,7 @@ function appVersion() {
|
|
|
54611
54612
|
return resolveVersion({
|
|
54612
54613
|
isSea: isSea2(),
|
|
54613
54614
|
sqVersionXml: readSqVersionXml(),
|
|
54614
|
-
define: true ? "0.126.
|
|
54615
|
+
define: true ? "0.126.1" : void 0,
|
|
54615
54616
|
pkgVersion: readPkgVersion()
|
|
54616
54617
|
});
|
|
54617
54618
|
}
|
|
@@ -54627,7 +54628,7 @@ function resolveChannel(s) {
|
|
|
54627
54628
|
function appChannel() {
|
|
54628
54629
|
return resolveChannel({
|
|
54629
54630
|
isSea: isSea2(),
|
|
54630
|
-
define: true ? "0.126.
|
|
54631
|
+
define: true ? "0.126.1" : void 0,
|
|
54631
54632
|
// argv[1] is the entry the runtime actually loaded (…/dist/floless-server.cjs), which is what
|
|
54632
54633
|
// carries the npx cache prefix. Absent under the SEA exe, which never reaches the npx branch.
|
|
54633
54634
|
modulePath: process.argv[1]
|
|
@@ -54635,24 +54636,31 @@ function appChannel() {
|
|
|
54635
54636
|
}
|
|
54636
54637
|
|
|
54637
54638
|
// workflow-update.ts
|
|
54638
|
-
var
|
|
54639
|
+
var import_node_fs13 = require("node:fs");
|
|
54639
54640
|
var import_node_os11 = require("node:os");
|
|
54640
54641
|
var import_node_path11 = require("node:path");
|
|
54641
54642
|
var import_node_url = require("node:url");
|
|
54642
54643
|
var import_yaml2 = __toESM(require_dist6(), 1);
|
|
54643
|
-
|
|
54644
|
-
|
|
54644
|
+
|
|
54645
|
+
// dotted-version.ts
|
|
54646
|
+
function compareDotted(a, b) {
|
|
54645
54647
|
const pa = String(a).split(".");
|
|
54646
54648
|
const pb = String(b).split(".");
|
|
54647
54649
|
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
54648
|
-
const na =
|
|
54649
|
-
const nb =
|
|
54650
|
+
const na = parseInt(pa[i] ?? "0", 10) || 0;
|
|
54651
|
+
const nb = parseInt(pb[i] ?? "0", 10) || 0;
|
|
54650
54652
|
if (na !== nb) return na > nb ? 1 : -1;
|
|
54651
54653
|
}
|
|
54652
54654
|
return 0;
|
|
54653
54655
|
}
|
|
54656
|
+
function versionGt(a, b) {
|
|
54657
|
+
return compareDotted(a, b) > 0;
|
|
54658
|
+
}
|
|
54659
|
+
|
|
54660
|
+
// workflow-update.ts
|
|
54661
|
+
var here = (0, import_node_path11.dirname)((0, import_node_url.fileURLToPath)(__import_meta_url));
|
|
54654
54662
|
function changelogSince(changelog, installed) {
|
|
54655
|
-
return (changelog ?? []).filter((e) => e &&
|
|
54663
|
+
return (changelog ?? []).filter((e) => e && compareDotted(String(e.version), installed) > 0);
|
|
54656
54664
|
}
|
|
54657
54665
|
function detectUpdates(installed, templates) {
|
|
54658
54666
|
const byId = new Map(templates.filter((t) => t.publisher === "floless").map((t) => [t.id, t]));
|
|
@@ -54662,7 +54670,7 @@ function detectUpdates(installed, templates) {
|
|
|
54662
54670
|
if (app.publisher != null && app.publisher !== "floless") continue;
|
|
54663
54671
|
const t = byId.get(app.templateId);
|
|
54664
54672
|
if (!t) continue;
|
|
54665
|
-
if (
|
|
54673
|
+
if (compareDotted(t.version, app.version) <= 0) continue;
|
|
54666
54674
|
out.push({
|
|
54667
54675
|
id: app.id,
|
|
54668
54676
|
templateId: t.id,
|
|
@@ -54675,15 +54683,15 @@ function detectUpdates(installed, templates) {
|
|
|
54675
54683
|
return out;
|
|
54676
54684
|
}
|
|
54677
54685
|
function stampSourceAppId(sourcePath, id) {
|
|
54678
|
-
const doc = (0, import_yaml2.parseDocument)((0,
|
|
54686
|
+
const doc = (0, import_yaml2.parseDocument)((0, import_node_fs13.readFileSync)(sourcePath, "utf8"));
|
|
54679
54687
|
if (doc.errors.length > 0) {
|
|
54680
54688
|
throw new Error(`stamp app id: source is not valid YAML: ${doc.errors[0]?.message ?? "parse error"}`);
|
|
54681
54689
|
}
|
|
54682
54690
|
doc.set("app", id);
|
|
54683
|
-
(0,
|
|
54691
|
+
(0, import_node_fs13.writeFileSync)(sourcePath, doc.toString());
|
|
54684
54692
|
}
|
|
54685
54693
|
function readTemplateMeta(path) {
|
|
54686
|
-
const doc = (0, import_yaml2.parse)((0,
|
|
54694
|
+
const doc = (0, import_yaml2.parse)((0, import_node_fs13.readFileSync)(path, "utf8")) ?? {};
|
|
54687
54695
|
return {
|
|
54688
54696
|
id: String(doc.app ?? ""),
|
|
54689
54697
|
version: doc.version != null ? String(doc.version) : "0.0.0",
|
|
@@ -54705,16 +54713,16 @@ function templatePaths(roots) {
|
|
|
54705
54713
|
// SEA exe
|
|
54706
54714
|
];
|
|
54707
54715
|
for (const d of flatDirs) {
|
|
54708
|
-
if (!(0,
|
|
54709
|
-
const flos = (0,
|
|
54716
|
+
if (!(0, import_node_fs13.existsSync)(d)) continue;
|
|
54717
|
+
const flos = (0, import_node_fs13.readdirSync)(d).filter((f) => f.endsWith(".flo"));
|
|
54710
54718
|
if (flos.length) return flos.map((f) => (0, import_node_path11.join)(d, f));
|
|
54711
54719
|
}
|
|
54712
54720
|
for (const demos of [(0, import_node_path11.join)(here, "..", "demos"), (0, import_node_path11.join)(here, "..", "..", "demos")]) {
|
|
54713
|
-
if (!(0,
|
|
54721
|
+
if (!(0, import_node_fs13.existsSync)(demos)) continue;
|
|
54714
54722
|
const out = [];
|
|
54715
|
-
for (const dir of (0,
|
|
54723
|
+
for (const dir of (0, import_node_fs13.readdirSync)(demos)) {
|
|
54716
54724
|
try {
|
|
54717
|
-
for (const f of (0,
|
|
54725
|
+
for (const f of (0, import_node_fs13.readdirSync)((0, import_node_path11.join)(demos, dir))) if (f.endsWith(".flo")) out.push((0, import_node_path11.join)(demos, dir, f));
|
|
54718
54726
|
} catch {
|
|
54719
54727
|
}
|
|
54720
54728
|
}
|
|
@@ -54746,7 +54754,7 @@ function backupDir(id, version, ts) {
|
|
|
54746
54754
|
var import_node_os12 = require("node:os");
|
|
54747
54755
|
var import_node_path12 = require("node:path");
|
|
54748
54756
|
var import_node_net = __toESM(require("node:net"), 1);
|
|
54749
|
-
var
|
|
54757
|
+
var import_node_fs14 = require("node:fs");
|
|
54750
54758
|
var MANAGED_HEADER = "# managed by floless.app - do not edit";
|
|
54751
54759
|
var OAUTH_PRESETS = {
|
|
54752
54760
|
"trimble-connect": {
|
|
@@ -54791,14 +54799,14 @@ function ensureManagedProfile(id) {
|
|
|
54791
54799
|
if (!preset) return "not-managed";
|
|
54792
54800
|
const dir = oauthDir();
|
|
54793
54801
|
const file = (0, import_node_path12.join)(dir, `${id}.yaml`);
|
|
54794
|
-
const existing = (0,
|
|
54802
|
+
const existing = (0, import_node_fs14.existsSync)(file) ? (0, import_node_fs14.readFileSync)(file, "utf8") : null;
|
|
54795
54803
|
if (existing !== null && !existing.startsWith(MANAGED_HEADER) && !isUpgradableLegacyProfile(existing, preset)) {
|
|
54796
54804
|
return "skipped";
|
|
54797
54805
|
}
|
|
54798
54806
|
const desired = managedProfileYaml(preset);
|
|
54799
54807
|
if (existing === desired) return "unchanged";
|
|
54800
|
-
(0,
|
|
54801
|
-
(0,
|
|
54808
|
+
(0, import_node_fs14.mkdirSync)(dir, { recursive: true });
|
|
54809
|
+
(0, import_node_fs14.writeFileSync)(file, desired, "utf8");
|
|
54802
54810
|
return "written";
|
|
54803
54811
|
}
|
|
54804
54812
|
function isPortBindable(port, host = "127.0.0.1") {
|
|
@@ -54840,7 +54848,7 @@ function bakeFloSource(source, inputs) {
|
|
|
54840
54848
|
var import_yaml4 = __toESM(require_dist6(), 1);
|
|
54841
54849
|
|
|
54842
54850
|
// contract-schema.ts
|
|
54843
|
-
var
|
|
54851
|
+
var import_node_fs15 = require("node:fs");
|
|
54844
54852
|
var import_node_path13 = require("node:path");
|
|
54845
54853
|
var import_node_url2 = require("node:url");
|
|
54846
54854
|
function validate(doc, schema) {
|
|
@@ -54982,7 +54990,7 @@ function loadContractSchema(file) {
|
|
|
54982
54990
|
];
|
|
54983
54991
|
for (const p of candidates) {
|
|
54984
54992
|
try {
|
|
54985
|
-
const parsed = JSON.parse((0,
|
|
54993
|
+
const parsed = JSON.parse((0, import_node_fs15.readFileSync)(p, "utf8"));
|
|
54986
54994
|
_cache.set(file, parsed);
|
|
54987
54995
|
return parsed;
|
|
54988
54996
|
} catch (err2) {
|
|
@@ -55893,7 +55901,7 @@ function extractReportHtml(events) {
|
|
|
55893
55901
|
|
|
55894
55902
|
// open-file.ts
|
|
55895
55903
|
var import_node_child_process4 = require("node:child_process");
|
|
55896
|
-
var
|
|
55904
|
+
var import_node_fs16 = require("node:fs");
|
|
55897
55905
|
var import_node_path14 = require("node:path");
|
|
55898
55906
|
var OPEN_EXTS = /* @__PURE__ */ new Set([".xls", ".xlsx", ".html", ".htm", ".csv", ".svg", ".png", ".mp4"]);
|
|
55899
55907
|
var REVEAL_EXTS = /* @__PURE__ */ new Set([...OPEN_EXTS, ".ifc", ".nc1", ".dstv"]);
|
|
@@ -55907,7 +55915,7 @@ function validateOpenable(path, mode = "open") {
|
|
|
55907
55915
|
if (!allowed) return { ok: false, error: "unsupported file type" };
|
|
55908
55916
|
let isFile2 = false;
|
|
55909
55917
|
try {
|
|
55910
|
-
isFile2 = (0,
|
|
55918
|
+
isFile2 = (0, import_node_fs16.existsSync)(path) && (0, import_node_fs16.statSync)(path).isFile();
|
|
55911
55919
|
} catch {
|
|
55912
55920
|
isFile2 = false;
|
|
55913
55921
|
}
|
|
@@ -55950,7 +55958,7 @@ function validateOpenableFolder(dir) {
|
|
|
55950
55958
|
if (dir.includes("%")) return { ok: false, error: "unsupported folder path" };
|
|
55951
55959
|
let isDir = false;
|
|
55952
55960
|
try {
|
|
55953
|
-
isDir = (0,
|
|
55961
|
+
isDir = (0, import_node_fs16.existsSync)(dir) && (0, import_node_fs16.statSync)(dir).isDirectory();
|
|
55954
55962
|
} catch {
|
|
55955
55963
|
isDir = false;
|
|
55956
55964
|
}
|
|
@@ -55982,10 +55990,10 @@ function extractSavedPath(events) {
|
|
|
55982
55990
|
}
|
|
55983
55991
|
|
|
55984
55992
|
// exports-folder-route.ts
|
|
55985
|
-
var
|
|
55993
|
+
var import_node_fs19 = require("node:fs");
|
|
55986
55994
|
|
|
55987
55995
|
// projects-store.ts
|
|
55988
|
-
var
|
|
55996
|
+
var import_node_fs18 = require("node:fs");
|
|
55989
55997
|
var import_promises = require("node:fs/promises");
|
|
55990
55998
|
var import_node_path16 = require("node:path");
|
|
55991
55999
|
var import_node_os14 = require("node:os");
|
|
@@ -57334,7 +57342,7 @@ function unzipSync(data, opts) {
|
|
|
57334
57342
|
}
|
|
57335
57343
|
|
|
57336
57344
|
// revision-staging-store.ts
|
|
57337
|
-
var
|
|
57345
|
+
var import_node_fs17 = require("node:fs");
|
|
57338
57346
|
var import_node_crypto8 = require("node:crypto");
|
|
57339
57347
|
var import_node_os13 = require("node:os");
|
|
57340
57348
|
var import_node_path15 = require("node:path");
|
|
@@ -57372,25 +57380,25 @@ var metaPath = (stagingKey) => (0, import_node_path15.join)(stagingDir(stagingKe
|
|
|
57372
57380
|
var docPath = (stagingKey) => (0, import_node_path15.join)(stagingDir(stagingKey), "candidate.json");
|
|
57373
57381
|
function stageCandidate(stagingKey, candidate, meta) {
|
|
57374
57382
|
const dir = stagingDir(stagingKey);
|
|
57375
|
-
(0,
|
|
57383
|
+
(0, import_node_fs17.mkdirSync)(dir, { recursive: true });
|
|
57376
57384
|
const bytes = JSON.stringify(candidate ?? null);
|
|
57377
57385
|
const record3 = { stageId: (0, import_node_crypto8.randomUUID)(), ...meta, candidateHash: hashOf(candidate ?? null) };
|
|
57378
|
-
(0,
|
|
57379
|
-
(0,
|
|
57386
|
+
(0, import_node_fs17.writeFileSync)(docPath(stagingKey), bytes);
|
|
57387
|
+
(0, import_node_fs17.writeFileSync)(metaPath(stagingKey), JSON.stringify(record3, null, 2));
|
|
57380
57388
|
return record3;
|
|
57381
57389
|
}
|
|
57382
57390
|
function readStaged(stagingKey) {
|
|
57383
57391
|
const record3 = readStagedRecord(stagingKey);
|
|
57384
57392
|
if (!record3) return null;
|
|
57385
|
-
if (!(0,
|
|
57393
|
+
if (!(0, import_node_fs17.existsSync)(docPath(stagingKey))) return null;
|
|
57386
57394
|
const candidate = readStagedCandidate(stagingKey);
|
|
57387
57395
|
if (hashOf(candidate ?? null) !== record3.candidateHash) return null;
|
|
57388
57396
|
return { record: record3, candidate };
|
|
57389
57397
|
}
|
|
57390
57398
|
function readStagedRecord(stagingKey) {
|
|
57391
57399
|
try {
|
|
57392
|
-
if (!(0,
|
|
57393
|
-
const r = JSON.parse((0,
|
|
57400
|
+
if (!(0, import_node_fs17.existsSync)(metaPath(stagingKey))) return null;
|
|
57401
|
+
const r = JSON.parse((0, import_node_fs17.readFileSync)(metaPath(stagingKey), "utf8"));
|
|
57394
57402
|
return typeof r?.stageId === "string" && typeof r?.requestId === "string" ? r : null;
|
|
57395
57403
|
} catch {
|
|
57396
57404
|
return null;
|
|
@@ -57398,22 +57406,22 @@ function readStagedRecord(stagingKey) {
|
|
|
57398
57406
|
}
|
|
57399
57407
|
function readStagedCandidate(stagingKey) {
|
|
57400
57408
|
try {
|
|
57401
|
-
if (!(0,
|
|
57402
|
-
return JSON.parse((0,
|
|
57409
|
+
if (!(0, import_node_fs17.existsSync)(docPath(stagingKey))) return null;
|
|
57410
|
+
return JSON.parse((0, import_node_fs17.readFileSync)(docPath(stagingKey), "utf8"));
|
|
57403
57411
|
} catch {
|
|
57404
57412
|
return null;
|
|
57405
57413
|
}
|
|
57406
57414
|
}
|
|
57407
57415
|
function dropStagingFor(stagingKey) {
|
|
57408
57416
|
try {
|
|
57409
|
-
(0,
|
|
57417
|
+
(0, import_node_fs17.rmSync)(stagingDir(stagingKey), { recursive: true, force: true });
|
|
57410
57418
|
} catch {
|
|
57411
57419
|
}
|
|
57412
57420
|
}
|
|
57413
57421
|
function listStagedKeys() {
|
|
57414
57422
|
try {
|
|
57415
|
-
if (!(0,
|
|
57416
|
-
return (0,
|
|
57423
|
+
if (!(0, import_node_fs17.existsSync)(stagingRoot())) return [];
|
|
57424
|
+
return (0, import_node_fs17.readdirSync)(stagingRoot()).filter((d) => STAGING_KEY.test(d));
|
|
57417
57425
|
} catch {
|
|
57418
57426
|
return [];
|
|
57419
57427
|
}
|
|
@@ -57457,7 +57465,7 @@ function archiveDir(id) {
|
|
|
57457
57465
|
}
|
|
57458
57466
|
function mintProjectId(name, draw = () => (0, import_node_crypto9.randomBytes)(3).toString("hex")) {
|
|
57459
57467
|
let id = `${slugify(name)}-${draw()}`;
|
|
57460
|
-
while ((0,
|
|
57468
|
+
while ((0, import_node_fs18.existsSync)(projectDir(id)) || (0, import_node_fs18.existsSync)(archiveDir(id))) id = `${slugify(name)}-${draw()}`;
|
|
57461
57469
|
return id;
|
|
57462
57470
|
}
|
|
57463
57471
|
function projectExportsDir(id) {
|
|
@@ -57468,9 +57476,9 @@ function projectKnowledgeDir(id) {
|
|
|
57468
57476
|
}
|
|
57469
57477
|
var metaPath2 = (id) => (0, import_node_path16.join)(projectDir(id), "project.json");
|
|
57470
57478
|
function readMetaFile(jsonPath, id) {
|
|
57471
|
-
if (!(0,
|
|
57479
|
+
if (!(0, import_node_fs18.existsSync)(jsonPath)) return null;
|
|
57472
57480
|
try {
|
|
57473
|
-
const meta = JSON.parse((0,
|
|
57481
|
+
const meta = JSON.parse((0, import_node_fs18.readFileSync)(jsonPath, "utf8"));
|
|
57474
57482
|
if (meta && meta.id === id) return meta;
|
|
57475
57483
|
console.warn(`projects-store: ignoring ${jsonPath} \u2014 its id "${String(meta?.id)}" does not match the folder "${id}"`);
|
|
57476
57484
|
return null;
|
|
@@ -57485,14 +57493,14 @@ function readMeta(id) {
|
|
|
57485
57493
|
function writeMetaTo(dir, meta) {
|
|
57486
57494
|
const path = (0, import_node_path16.join)(dir, "project.json");
|
|
57487
57495
|
const tmp = `${path}.${process.pid}.${(0, import_node_crypto9.randomUUID)()}.tmp`;
|
|
57488
|
-
(0,
|
|
57489
|
-
(0,
|
|
57496
|
+
(0, import_node_fs18.writeFileSync)(tmp, JSON.stringify(meta, null, 2));
|
|
57497
|
+
(0, import_node_fs18.renameSync)(tmp, path);
|
|
57490
57498
|
}
|
|
57491
57499
|
var writeMeta = (meta) => writeMetaTo(projectDir(meta.id), meta);
|
|
57492
57500
|
function listProjects() {
|
|
57493
|
-
if (!(0,
|
|
57501
|
+
if (!(0, import_node_fs18.existsSync)(projectsRoot())) return [];
|
|
57494
57502
|
const out = [];
|
|
57495
|
-
for (const entry2 of (0,
|
|
57503
|
+
for (const entry2 of (0, import_node_fs18.readdirSync)(projectsRoot(), { withFileTypes: true })) {
|
|
57496
57504
|
if (!isProjectDir(entry2)) continue;
|
|
57497
57505
|
const meta = readMeta(entry2.name);
|
|
57498
57506
|
if (meta) out.push(meta);
|
|
@@ -57538,7 +57546,7 @@ function createProject(input) {
|
|
|
57538
57546
|
if (!name) throw new ProjectError("project name required");
|
|
57539
57547
|
if (!/^[a-z0-9][a-z0-9._-]*$/i.test(app)) throw new ProjectError(`invalid app id: ${app || "(empty)"}`);
|
|
57540
57548
|
const id = mintProjectId(name);
|
|
57541
|
-
(0,
|
|
57549
|
+
(0, import_node_fs18.mkdirSync)(projectDir(id), { recursive: true });
|
|
57542
57550
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
57543
57551
|
const meta = { id, uuid: (0, import_node_crypto9.randomUUID)(), name, app, createdAt: now, updatedAt: now };
|
|
57544
57552
|
writeMeta(meta);
|
|
@@ -57553,7 +57561,7 @@ function renameProject(id, name) {
|
|
|
57553
57561
|
const newId = mintProjectId(nextName);
|
|
57554
57562
|
const from = projectDir(id), to = projectDir(newId);
|
|
57555
57563
|
try {
|
|
57556
|
-
(0,
|
|
57564
|
+
(0, import_node_fs18.renameSync)(from, to);
|
|
57557
57565
|
} catch {
|
|
57558
57566
|
throw new ProjectError("couldn\u2019t rename the project folder \u2014 it may be open or in use. Close the project and try again.");
|
|
57559
57567
|
}
|
|
@@ -57563,7 +57571,7 @@ function renameProject(id, name) {
|
|
|
57563
57571
|
return next;
|
|
57564
57572
|
} catch (e) {
|
|
57565
57573
|
try {
|
|
57566
|
-
(0,
|
|
57574
|
+
(0, import_node_fs18.renameSync)(to, from);
|
|
57567
57575
|
} catch {
|
|
57568
57576
|
}
|
|
57569
57577
|
throw e;
|
|
@@ -57591,7 +57599,7 @@ function duplicateProject(id, name, onCreated) {
|
|
|
57591
57599
|
app: src.app
|
|
57592
57600
|
});
|
|
57593
57601
|
onCreated?.(copy);
|
|
57594
|
-
(0,
|
|
57602
|
+
(0, import_node_fs18.cpSync)(projectDir(src.id), projectDir(copy.id), {
|
|
57595
57603
|
recursive: true,
|
|
57596
57604
|
filter: (p) => !p.endsWith("project.json") && !isReservedProjectInternalPath(p)
|
|
57597
57605
|
});
|
|
@@ -57610,15 +57618,15 @@ function repointProjects(oldId, newId) {
|
|
|
57610
57618
|
console.warn(`repointProjects: leaving project ${meta.id} on "${oldId}" \u2014 ${e instanceof Error ? e.message : e}`);
|
|
57611
57619
|
}
|
|
57612
57620
|
};
|
|
57613
|
-
if ((0,
|
|
57614
|
-
for (const entry2 of (0,
|
|
57621
|
+
if ((0, import_node_fs18.existsSync)(projectsRoot())) {
|
|
57622
|
+
for (const entry2 of (0, import_node_fs18.readdirSync)(projectsRoot(), { withFileTypes: true })) {
|
|
57615
57623
|
if (!isProjectDir(entry2)) continue;
|
|
57616
57624
|
const meta = readMeta(entry2.name);
|
|
57617
57625
|
if (meta && meta.app === oldId) repoint(meta, () => projectDir(meta.id));
|
|
57618
57626
|
}
|
|
57619
57627
|
}
|
|
57620
|
-
if ((0,
|
|
57621
|
-
for (const entry2 of (0,
|
|
57628
|
+
if ((0, import_node_fs18.existsSync)(archiveRoot())) {
|
|
57629
|
+
for (const entry2 of (0, import_node_fs18.readdirSync)(archiveRoot(), { withFileTypes: true })) {
|
|
57622
57630
|
if (!isProjectDir(entry2)) continue;
|
|
57623
57631
|
const meta = readMetaFile((0, import_node_path16.join)(archiveRoot(), entry2.name, "project.json"), entry2.name);
|
|
57624
57632
|
if (meta && meta.app === oldId) repoint(meta, () => (0, import_node_path16.join)(archiveRoot(), safeProjectId(meta.id)));
|
|
@@ -57628,18 +57636,18 @@ function repointProjects(oldId, newId) {
|
|
|
57628
57636
|
}
|
|
57629
57637
|
function archiveProject(id) {
|
|
57630
57638
|
const dir = projectDir(id);
|
|
57631
|
-
if (!(0,
|
|
57632
|
-
(0,
|
|
57639
|
+
if (!(0, import_node_fs18.existsSync)(dir)) throw new ProjectError(`unknown project: ${id}`);
|
|
57640
|
+
(0, import_node_fs18.mkdirSync)(archiveRoot(), { recursive: true });
|
|
57633
57641
|
const dest = (0, import_node_path16.join)(archiveRoot(), id);
|
|
57634
|
-
if ((0,
|
|
57642
|
+
if ((0, import_node_fs18.existsSync)(dest)) throw new ProjectError(`already archived: ${id}`);
|
|
57635
57643
|
const meta = readMeta(id);
|
|
57636
57644
|
if (meta) writeMeta({ ...meta, updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
57637
|
-
(0,
|
|
57645
|
+
(0, import_node_fs18.renameSync)(dir, dest);
|
|
57638
57646
|
}
|
|
57639
57647
|
function listArchivedProjects() {
|
|
57640
|
-
if (!(0,
|
|
57648
|
+
if (!(0, import_node_fs18.existsSync)(archiveRoot())) return [];
|
|
57641
57649
|
const out = [];
|
|
57642
|
-
for (const entry2 of (0,
|
|
57650
|
+
for (const entry2 of (0, import_node_fs18.readdirSync)(archiveRoot(), { withFileTypes: true })) {
|
|
57643
57651
|
if (!isProjectDir(entry2)) continue;
|
|
57644
57652
|
const meta = readMetaFile((0, import_node_path16.join)(archiveRoot(), entry2.name, "project.json"), entry2.name);
|
|
57645
57653
|
if (meta) out.push(meta);
|
|
@@ -57648,19 +57656,19 @@ function listArchivedProjects() {
|
|
|
57648
57656
|
}
|
|
57649
57657
|
function unarchiveProject(id) {
|
|
57650
57658
|
const src = archiveDir(id);
|
|
57651
|
-
if (!(0,
|
|
57659
|
+
if (!(0, import_node_fs18.existsSync)(src)) throw new ProjectError(`not archived: ${id}`);
|
|
57652
57660
|
const meta = readMetaFile((0, import_node_path16.join)(src, "project.json"), id);
|
|
57653
57661
|
if (!meta) throw new ProjectError(`archived project has missing or unreadable metadata: ${id}`);
|
|
57654
57662
|
const dest = projectDir(id);
|
|
57655
|
-
if ((0,
|
|
57656
|
-
(0,
|
|
57663
|
+
if ((0, import_node_fs18.existsSync)(dest)) throw new ProjectError(`a live project with that id already exists: ${id}`);
|
|
57664
|
+
(0, import_node_fs18.renameSync)(src, dest);
|
|
57657
57665
|
return meta;
|
|
57658
57666
|
}
|
|
57659
57667
|
function deleteArchivedProject(id) {
|
|
57660
57668
|
const dir = archiveDir(id);
|
|
57661
|
-
if (!(0,
|
|
57669
|
+
if (!(0, import_node_fs18.existsSync)(dir)) throw new ProjectError(`not archived: ${id}`);
|
|
57662
57670
|
const stagingId = readMetaFile((0, import_node_path16.join)(dir, "project.json"), id)?.stagingId;
|
|
57663
|
-
(0,
|
|
57671
|
+
(0, import_node_fs18.rmSync)(dir, { recursive: true, force: true });
|
|
57664
57672
|
if (stagingId) dropStagingFor(stagingId);
|
|
57665
57673
|
}
|
|
57666
57674
|
var THUMBNAIL_EXTS = ["webp", "png", "jpg"];
|
|
@@ -57682,7 +57690,7 @@ function thumbnailIn(dir) {
|
|
|
57682
57690
|
for (const ext of THUMBNAIL_EXTS) {
|
|
57683
57691
|
const path = (0, import_node_path16.join)(dir, `thumbnail.${ext}`);
|
|
57684
57692
|
try {
|
|
57685
|
-
const st = (0,
|
|
57693
|
+
const st = (0, import_node_fs18.statSync)(path);
|
|
57686
57694
|
if (!st.isFile() || st.mtimeMs <= bestMs) continue;
|
|
57687
57695
|
bestMs = st.mtimeMs;
|
|
57688
57696
|
best = { ext, path, bytes: st.size, updatedAt: st.mtime.toISOString(), stamp: `${st.mtimeMs}-${st.size}` };
|
|
@@ -57709,13 +57717,13 @@ function setProjectThumbnail(id, data) {
|
|
|
57709
57717
|
const dir = projectDir(id);
|
|
57710
57718
|
const path = (0, import_node_path16.join)(dir, `thumbnail.${ext}`);
|
|
57711
57719
|
const tmp = `${path}.${process.pid}.${(0, import_node_crypto9.randomUUID)()}.tmp`;
|
|
57712
|
-
(0,
|
|
57713
|
-
(0,
|
|
57720
|
+
(0, import_node_fs18.writeFileSync)(tmp, data);
|
|
57721
|
+
(0, import_node_fs18.renameSync)(tmp, path);
|
|
57714
57722
|
for (const other of THUMBNAIL_EXTS) {
|
|
57715
|
-
if (other !== ext) (0,
|
|
57723
|
+
if (other !== ext) (0, import_node_fs18.rmSync)((0, import_node_path16.join)(dir, `thumbnail.${other}`), { force: true });
|
|
57716
57724
|
}
|
|
57717
57725
|
writeMeta({ ...meta, updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
57718
|
-
const st = (0,
|
|
57726
|
+
const st = (0, import_node_fs18.statSync)(path);
|
|
57719
57727
|
return { ext, path, bytes: st.size, updatedAt: st.mtime.toISOString(), stamp: `${st.mtimeMs}-${st.size}` };
|
|
57720
57728
|
}
|
|
57721
57729
|
function clearProjectThumbnail(id) {
|
|
@@ -57725,8 +57733,8 @@ function clearProjectThumbnail(id) {
|
|
|
57725
57733
|
let removed = false;
|
|
57726
57734
|
for (const ext of THUMBNAIL_EXTS) {
|
|
57727
57735
|
const path = (0, import_node_path16.join)(dir, `thumbnail.${ext}`);
|
|
57728
|
-
if ((0,
|
|
57729
|
-
(0,
|
|
57736
|
+
if ((0, import_node_fs18.existsSync)(path)) {
|
|
57737
|
+
(0, import_node_fs18.rmSync)(path, { force: true });
|
|
57730
57738
|
removed = true;
|
|
57731
57739
|
}
|
|
57732
57740
|
}
|
|
@@ -57851,7 +57859,7 @@ function importProjectZip(data) {
|
|
|
57851
57859
|
}
|
|
57852
57860
|
const dest = projectDir(id);
|
|
57853
57861
|
const destResolved = (0, import_node_path16.resolve)(dest);
|
|
57854
|
-
(0,
|
|
57862
|
+
(0, import_node_fs18.mkdirSync)(dest, { recursive: true });
|
|
57855
57863
|
try {
|
|
57856
57864
|
for (const [entryPath, bytes] of Object.entries(entries2)) {
|
|
57857
57865
|
if (entryPath === metaEntry) continue;
|
|
@@ -57861,8 +57869,8 @@ function importProjectZip(data) {
|
|
|
57861
57869
|
if (target !== destResolved && !target.startsWith(destResolved + import_node_path16.sep)) {
|
|
57862
57870
|
throw new ProjectError(`archive entry escapes the project dir: ${entryPath}`);
|
|
57863
57871
|
}
|
|
57864
|
-
(0,
|
|
57865
|
-
(0,
|
|
57872
|
+
(0, import_node_fs18.mkdirSync)((0, import_node_path16.dirname)(target), { recursive: true });
|
|
57873
|
+
(0, import_node_fs18.writeFileSync)(target, bytes);
|
|
57866
57874
|
}
|
|
57867
57875
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
57868
57876
|
const meta = {
|
|
@@ -57877,7 +57885,7 @@ function importProjectZip(data) {
|
|
|
57877
57885
|
writeMeta(meta);
|
|
57878
57886
|
return meta;
|
|
57879
57887
|
} catch (e) {
|
|
57880
|
-
(0,
|
|
57888
|
+
(0, import_node_fs18.rmSync)(dest, { recursive: true, force: true });
|
|
57881
57889
|
throw e;
|
|
57882
57890
|
}
|
|
57883
57891
|
}
|
|
@@ -57891,7 +57899,7 @@ function registerExportsFolderRoute(app) {
|
|
|
57891
57899
|
}
|
|
57892
57900
|
const dir = projectExportsDir(project);
|
|
57893
57901
|
try {
|
|
57894
|
-
(0,
|
|
57902
|
+
(0, import_node_fs19.mkdirSync)(dir, { recursive: true });
|
|
57895
57903
|
} catch (error) {
|
|
57896
57904
|
req.log.warn(
|
|
57897
57905
|
{ project, error: error instanceof Error ? error.message : error },
|
|
@@ -57908,7 +57916,7 @@ function registerExportsFolderRoute(app) {
|
|
|
57908
57916
|
|
|
57909
57917
|
// project-export-save-route.ts
|
|
57910
57918
|
var import_node_crypto12 = require("node:crypto");
|
|
57911
|
-
var
|
|
57919
|
+
var import_node_fs22 = require("node:fs");
|
|
57912
57920
|
var import_promises2 = require("node:fs/promises");
|
|
57913
57921
|
var import_node_path21 = require("node:path");
|
|
57914
57922
|
|
|
@@ -57983,13 +57991,13 @@ async function chooseProjectExportPath(options, platform = process.platform, run
|
|
|
57983
57991
|
|
|
57984
57992
|
// ifc-publication.ts
|
|
57985
57993
|
var import_node_crypto11 = require("node:crypto");
|
|
57986
|
-
var
|
|
57994
|
+
var import_node_fs21 = require("node:fs");
|
|
57987
57995
|
var import_node_os15 = require("node:os");
|
|
57988
57996
|
var import_node_path20 = require("node:path");
|
|
57989
57997
|
|
|
57990
57998
|
// project-export-receipts.ts
|
|
57991
57999
|
var import_node_crypto10 = require("node:crypto");
|
|
57992
|
-
var
|
|
58000
|
+
var import_node_fs20 = require("node:fs");
|
|
57993
58001
|
var import_node_path19 = require("node:path");
|
|
57994
58002
|
|
|
57995
58003
|
// safe-filename.ts
|
|
@@ -58024,7 +58032,7 @@ function proof(bytes) {
|
|
|
58024
58032
|
return bytes ? { exists: true, bytes: bytes.length, sha256: hash(bytes) } : { exists: false, bytes: 0, sha256: null };
|
|
58025
58033
|
}
|
|
58026
58034
|
function readFileProof(path) {
|
|
58027
|
-
return (0,
|
|
58035
|
+
return (0, import_node_fs20.existsSync)(path) ? proof((0, import_node_fs20.readFileSync)(path)) : proof(null);
|
|
58028
58036
|
}
|
|
58029
58037
|
function fileProofEquals(a, b) {
|
|
58030
58038
|
return a.exists === b.exists && a.bytes === b.bytes && a.sha256 === b.sha256;
|
|
@@ -58122,46 +58130,27 @@ function indexBytes(body) {
|
|
|
58122
58130
|
return Buffer.from(`${JSON.stringify({ exports: exports2 }, null, 2)}
|
|
58123
58131
|
`, "utf8");
|
|
58124
58132
|
}
|
|
58125
|
-
function syncFile(path) {
|
|
58126
|
-
const fd2 = (0, import_node_fs19.openSync)(path, "r+");
|
|
58127
|
-
try {
|
|
58128
|
-
(0, import_node_fs19.fsyncSync)(fd2);
|
|
58129
|
-
} finally {
|
|
58130
|
-
(0, import_node_fs19.closeSync)(fd2);
|
|
58131
|
-
}
|
|
58132
|
-
}
|
|
58133
|
-
function syncDirectory(path) {
|
|
58134
|
-
try {
|
|
58135
|
-
const fd2 = (0, import_node_fs19.openSync)(path, "r");
|
|
58136
|
-
try {
|
|
58137
|
-
(0, import_node_fs19.fsyncSync)(fd2);
|
|
58138
|
-
} finally {
|
|
58139
|
-
(0, import_node_fs19.closeSync)(fd2);
|
|
58140
|
-
}
|
|
58141
|
-
} catch {
|
|
58142
|
-
}
|
|
58143
|
-
}
|
|
58144
58133
|
function durableReplace(path, bytes) {
|
|
58145
58134
|
const dir = (0, import_node_path19.dirname)(path);
|
|
58146
|
-
(0,
|
|
58135
|
+
(0, import_node_fs20.mkdirSync)(dir, { recursive: true });
|
|
58147
58136
|
const tmp = (0, import_node_path19.join)(dir, `.floless-tmp-receipt-${(0, import_node_crypto10.randomUUID)()}`);
|
|
58148
58137
|
try {
|
|
58149
|
-
(0,
|
|
58138
|
+
(0, import_node_fs20.writeFileSync)(tmp, bytes, { flag: "wx" });
|
|
58150
58139
|
syncFile(tmp);
|
|
58151
|
-
(0,
|
|
58140
|
+
(0, import_node_fs20.renameSync)(tmp, path);
|
|
58152
58141
|
syncFile(path);
|
|
58153
|
-
|
|
58142
|
+
syncDirectoryBestEffort(dir);
|
|
58154
58143
|
} finally {
|
|
58155
58144
|
try {
|
|
58156
|
-
(0,
|
|
58145
|
+
(0, import_node_fs20.rmSync)(tmp, { force: true });
|
|
58157
58146
|
} catch {
|
|
58158
58147
|
}
|
|
58159
58148
|
}
|
|
58160
58149
|
}
|
|
58161
58150
|
function strictCurrent(projectId) {
|
|
58162
58151
|
const path = projectExportIndexPath(projectId);
|
|
58163
|
-
if (!(0,
|
|
58164
|
-
const bytes = (0,
|
|
58152
|
+
if (!(0, import_node_fs20.existsSync)(path)) return { bytes: null, body: { exports: [], opaque: [] } };
|
|
58153
|
+
const bytes = (0, import_node_fs20.readFileSync)(path);
|
|
58165
58154
|
return { bytes, body: parseIndexBytes(bytes) };
|
|
58166
58155
|
}
|
|
58167
58156
|
function listProjectExportReceipts(projectId) {
|
|
@@ -58182,7 +58171,7 @@ function prepareProjectExport(projectId, receipt) {
|
|
|
58182
58171
|
const version = receipt.version;
|
|
58183
58172
|
validateInput(receipt);
|
|
58184
58173
|
const dir = projectExportsDir(projectId);
|
|
58185
|
-
(0,
|
|
58174
|
+
(0, import_node_fs20.mkdirSync)(dir, { recursive: true });
|
|
58186
58175
|
const current = strictCurrent(projectId);
|
|
58187
58176
|
const key = receiptKey(receipt.kind, receipt.variant);
|
|
58188
58177
|
const prior = current.body.exports.find((row) => receiptKey(row.kind, row.variant) === key) ?? null;
|
|
@@ -58252,8 +58241,8 @@ function restoreProjectExportTransition(transition) {
|
|
|
58252
58241
|
}
|
|
58253
58242
|
durableReplace(transition.indexPath, Buffer.from(transition.beforeBytesBase64, "base64"));
|
|
58254
58243
|
} else {
|
|
58255
|
-
(0,
|
|
58256
|
-
|
|
58244
|
+
(0, import_node_fs20.rmSync)(transition.indexPath, { force: true });
|
|
58245
|
+
syncDirectoryBestEffort((0, import_node_path19.dirname)(transition.indexPath));
|
|
58257
58246
|
}
|
|
58258
58247
|
if (!currentMatches(transition.indexPath, transition.before)) {
|
|
58259
58248
|
throw new ProjectExportReceiptError("project export index did not match the restored proof.");
|
|
@@ -58275,8 +58264,8 @@ function cleanupSupersededProjectExport(transition) {
|
|
|
58275
58264
|
const path = resolveProjectExportReceiptPath(transition.projectId, superseded);
|
|
58276
58265
|
if (!path) return;
|
|
58277
58266
|
try {
|
|
58278
|
-
(0,
|
|
58279
|
-
|
|
58267
|
+
(0, import_node_fs20.rmSync)(path, { force: true });
|
|
58268
|
+
syncDirectoryBestEffort((0, import_node_path19.dirname)(path));
|
|
58280
58269
|
} catch {
|
|
58281
58270
|
}
|
|
58282
58271
|
}
|
|
@@ -58290,10 +58279,10 @@ function publishProjectExportArtifact(projectId, receipt, bytes) {
|
|
|
58290
58279
|
}
|
|
58291
58280
|
const path2 = resolveProjectExportReceiptPath(projectId, receipt);
|
|
58292
58281
|
if (!path2) throw new ProjectExportReceiptError("project export artifact path is unsafe.");
|
|
58293
|
-
(0,
|
|
58294
|
-
(0,
|
|
58282
|
+
(0, import_node_fs20.mkdirSync)((0, import_node_path19.dirname)(path2), { recursive: true });
|
|
58283
|
+
(0, import_node_fs20.writeFileSync)(path2, bytes, { flag: "wx" });
|
|
58295
58284
|
syncFile(path2);
|
|
58296
|
-
|
|
58285
|
+
syncDirectoryBestEffort((0, import_node_path19.dirname)(path2));
|
|
58297
58286
|
return null;
|
|
58298
58287
|
}
|
|
58299
58288
|
const transition = prepareProjectExport(projectId, receipt);
|
|
@@ -58301,7 +58290,7 @@ function publishProjectExportArtifact(projectId, receipt, bytes) {
|
|
|
58301
58290
|
if (!path) throw new ProjectExportReceiptError("project export artifact path is unsafe.");
|
|
58302
58291
|
let wroteArtifact = false;
|
|
58303
58292
|
try {
|
|
58304
|
-
(0,
|
|
58293
|
+
(0, import_node_fs20.writeFileSync)(path, bytes, { flag: "wx" });
|
|
58305
58294
|
wroteArtifact = true;
|
|
58306
58295
|
syncFile(path);
|
|
58307
58296
|
commitProjectExportTransition(transition);
|
|
@@ -58316,8 +58305,8 @@ function publishProjectExportArtifact(projectId, receipt, bytes) {
|
|
|
58316
58305
|
}
|
|
58317
58306
|
if (!restoreError && wroteArtifact) {
|
|
58318
58307
|
try {
|
|
58319
|
-
(0,
|
|
58320
|
-
|
|
58308
|
+
(0, import_node_fs20.rmSync)(path, { force: true });
|
|
58309
|
+
syncDirectoryBestEffort((0, import_node_path19.dirname)(path));
|
|
58321
58310
|
} catch {
|
|
58322
58311
|
}
|
|
58323
58312
|
}
|
|
@@ -58331,7 +58320,7 @@ function publishProjectExportArtifact(projectId, receipt, bytes) {
|
|
|
58331
58320
|
}
|
|
58332
58321
|
function receiptHasFile(projectId, receipt) {
|
|
58333
58322
|
const path = resolveProjectExportReceiptPath(projectId, receipt);
|
|
58334
|
-
return path !== null && (0,
|
|
58323
|
+
return path !== null && (0, import_node_fs20.existsSync)(path);
|
|
58335
58324
|
}
|
|
58336
58325
|
function matchingProjectExportReceipts(projectId, version, contractHash2, kinds) {
|
|
58337
58326
|
const wanted = kinds ? new Set(kinds) : null;
|
|
@@ -58371,38 +58360,19 @@ function proof2(bytes) {
|
|
|
58371
58360
|
function sameProof(path, expected) {
|
|
58372
58361
|
return fileProofEquals(readFileProof(path), expected);
|
|
58373
58362
|
}
|
|
58374
|
-
function syncFile2(path) {
|
|
58375
|
-
const fd2 = (0, import_node_fs20.openSync)(path, "r+");
|
|
58376
|
-
try {
|
|
58377
|
-
(0, import_node_fs20.fsyncSync)(fd2);
|
|
58378
|
-
} finally {
|
|
58379
|
-
(0, import_node_fs20.closeSync)(fd2);
|
|
58380
|
-
}
|
|
58381
|
-
}
|
|
58382
|
-
function syncDirectory2(path) {
|
|
58383
|
-
try {
|
|
58384
|
-
const fd2 = (0, import_node_fs20.openSync)(path, "r");
|
|
58385
|
-
try {
|
|
58386
|
-
(0, import_node_fs20.fsyncSync)(fd2);
|
|
58387
|
-
} finally {
|
|
58388
|
-
(0, import_node_fs20.closeSync)(fd2);
|
|
58389
|
-
}
|
|
58390
|
-
} catch {
|
|
58391
|
-
}
|
|
58392
|
-
}
|
|
58393
58363
|
function durableReplace2(path, bytes) {
|
|
58394
58364
|
const dir = (0, import_node_path20.dirname)(path);
|
|
58395
|
-
(0,
|
|
58365
|
+
(0, import_node_fs21.mkdirSync)(dir, { recursive: true });
|
|
58396
58366
|
const tmp = (0, import_node_path20.join)(dir, `.floless-tmp-recovery-${(0, import_node_crypto11.randomUUID)()}`);
|
|
58397
58367
|
try {
|
|
58398
|
-
(0,
|
|
58399
|
-
|
|
58400
|
-
(0,
|
|
58401
|
-
|
|
58402
|
-
|
|
58368
|
+
(0, import_node_fs21.writeFileSync)(tmp, bytes, { flag: "wx" });
|
|
58369
|
+
syncFile(tmp);
|
|
58370
|
+
(0, import_node_fs21.renameSync)(tmp, path);
|
|
58371
|
+
syncFile(path);
|
|
58372
|
+
syncDirectoryBestEffort(dir);
|
|
58403
58373
|
} finally {
|
|
58404
58374
|
try {
|
|
58405
|
-
(0,
|
|
58375
|
+
(0, import_node_fs21.rmSync)(tmp, { force: true });
|
|
58406
58376
|
} catch {
|
|
58407
58377
|
}
|
|
58408
58378
|
}
|
|
@@ -58428,12 +58398,12 @@ function validateRequestPaths(tempPath, finalPath) {
|
|
|
58428
58398
|
function requestIfcTempPath(finalPath) {
|
|
58429
58399
|
const final = canonicalPath(finalPath);
|
|
58430
58400
|
if (!plainIfcFilename((0, import_node_path20.basename)(final))) throw new IfcPublicationError("IFC final filename is unsafe.");
|
|
58431
|
-
(0,
|
|
58401
|
+
(0, import_node_fs21.mkdirSync)((0, import_node_path20.dirname)(final), { recursive: true });
|
|
58432
58402
|
return (0, import_node_path20.join)((0, import_node_path20.dirname)(final), `.floless-tmp-ifc-${(0, import_node_crypto11.randomUUID)()}.ifc`);
|
|
58433
58403
|
}
|
|
58434
58404
|
function validateIfc(path) {
|
|
58435
|
-
if (!(0,
|
|
58436
|
-
const bytes = (0,
|
|
58405
|
+
if (!(0, import_node_fs21.existsSync)(path) || (0, import_node_fs21.statSync)(path).size === 0) throw new IfcPublicationError("the IFC export produced no file");
|
|
58406
|
+
const bytes = (0, import_node_fs21.readFileSync)(path);
|
|
58437
58407
|
const prefix = bytes.subarray(0, Math.min(bytes.length, 128)).toString("utf8");
|
|
58438
58408
|
if (!prefix.includes("ISO-10303-21")) throw new IfcPublicationError("the IFC export did not produce a valid STEP envelope");
|
|
58439
58409
|
return { bytes, proof: proof2(bytes) };
|
|
@@ -58447,20 +58417,20 @@ function writePhase(txnDir2, journal) {
|
|
|
58447
58417
|
const index = PHASES.indexOf(journal.phase);
|
|
58448
58418
|
if (index < 0) throw new IfcPublicationError(`unknown IFC publication phase "${journal.phase}".`);
|
|
58449
58419
|
const destination = (0, import_node_path20.join)(txnDir2, `${String(index).padStart(3, "0")}-${journal.phase}.json`);
|
|
58450
|
-
if ((0,
|
|
58420
|
+
if ((0, import_node_fs21.existsSync)(destination)) throw new IfcPublicationError(`IFC publication phase "${journal.phase}" already exists.`);
|
|
58451
58421
|
const temp = (0, import_node_path20.join)(txnDir2, `.phase-${(0, import_node_crypto11.randomUUID)()}.tmp`);
|
|
58452
58422
|
const bytes = Buffer.from(`${JSON.stringify(journal, null, 2)}
|
|
58453
58423
|
`, "utf8");
|
|
58454
58424
|
try {
|
|
58455
|
-
(0,
|
|
58456
|
-
|
|
58457
|
-
(0,
|
|
58458
|
-
|
|
58459
|
-
|
|
58460
|
-
|
|
58425
|
+
(0, import_node_fs21.writeFileSync)(temp, bytes, { flag: "wx" });
|
|
58426
|
+
syncFile(temp);
|
|
58427
|
+
(0, import_node_fs21.renameSync)(temp, destination);
|
|
58428
|
+
syncFile(destination);
|
|
58429
|
+
syncDirectoryBestEffort(txnDir2);
|
|
58430
|
+
syncDirectoryBestEffort((0, import_node_path20.dirname)(txnDir2));
|
|
58461
58431
|
} finally {
|
|
58462
58432
|
try {
|
|
58463
|
-
(0,
|
|
58433
|
+
(0, import_node_fs21.rmSync)(temp, { force: true });
|
|
58464
58434
|
} catch {
|
|
58465
58435
|
}
|
|
58466
58436
|
}
|
|
@@ -58526,7 +58496,7 @@ function loadJournal(txnDir2) {
|
|
|
58526
58496
|
const match = (0, import_node_path20.basename)(txnDir2).match(ACTIVE_RE);
|
|
58527
58497
|
if (!match) throw new IfcPublicationError(`unsafe IFC transaction directory "${(0, import_node_path20.basename)(txnDir2)}".`);
|
|
58528
58498
|
const txnId = match[1];
|
|
58529
|
-
const entries2 = (0,
|
|
58499
|
+
const entries2 = (0, import_node_fs21.readdirSync)(txnDir2, { withFileTypes: true });
|
|
58530
58500
|
if (!entries2.length) return null;
|
|
58531
58501
|
const phaseFiles = entries2.filter((entry2) => entry2.isFile() && PHASE_RE.test(entry2.name)).sort((a, b) => a.name.localeCompare(b.name));
|
|
58532
58502
|
const unknown = entries2.filter((entry2) => !(entry2.isFile() && (PHASE_RE.test(entry2.name) || /^\.phase-[a-f0-9-]+\.tmp$/i.test(entry2.name))));
|
|
@@ -58541,10 +58511,10 @@ function loadJournal(txnDir2) {
|
|
|
58541
58511
|
const declaredPhase = phaseMatch[2];
|
|
58542
58512
|
if (declaredIndex !== index || PHASES[index] !== declaredPhase) break;
|
|
58543
58513
|
const path = (0, import_node_path20.join)(txnDir2, entry2.name);
|
|
58544
|
-
if ((0,
|
|
58514
|
+
if ((0, import_node_fs21.statSync)(path).size > MAX_PHASE_BYTES) break;
|
|
58545
58515
|
let parsed;
|
|
58546
58516
|
try {
|
|
58547
|
-
parsed = JSON.parse((0,
|
|
58517
|
+
parsed = JSON.parse((0, import_node_fs21.readFileSync)(path, "utf8"));
|
|
58548
58518
|
} catch {
|
|
58549
58519
|
break;
|
|
58550
58520
|
}
|
|
@@ -58571,8 +58541,8 @@ function restoreIndex(journal) {
|
|
|
58571
58541
|
if (journal.priorIndex.exists) {
|
|
58572
58542
|
durableReplace2(indexPath, Buffer.from(journal.priorIndexBase64, "base64"));
|
|
58573
58543
|
} else {
|
|
58574
|
-
(0,
|
|
58575
|
-
|
|
58544
|
+
(0, import_node_fs21.rmSync)(indexPath, { force: true });
|
|
58545
|
+
syncDirectoryBestEffort((0, import_node_path20.dirname)(indexPath));
|
|
58576
58546
|
}
|
|
58577
58547
|
if (!sameProof(indexPath, journal.priorIndex)) {
|
|
58578
58548
|
throw new IfcPublicationError("receipt index restore did not match its recorded proof.");
|
|
@@ -58587,15 +58557,15 @@ function restoreArtifact(journal) {
|
|
|
58587
58557
|
if (!fileProofEquals(backup, journal.priorArtifact)) {
|
|
58588
58558
|
throw new IfcPublicationError("IFC backup does not match the recorded prior artifact.");
|
|
58589
58559
|
}
|
|
58590
|
-
(0,
|
|
58560
|
+
(0, import_node_fs21.rmSync)(journal.backupPath, { force: true });
|
|
58591
58561
|
}
|
|
58592
58562
|
} else if (!final.exists || fileProofEquals(final, journal.newArtifact)) {
|
|
58593
58563
|
if (!fileProofEquals(backup, journal.priorArtifact)) {
|
|
58594
58564
|
throw new IfcPublicationError("IFC prior artifact cannot be proven for rollback.");
|
|
58595
58565
|
}
|
|
58596
|
-
if (final.exists) (0,
|
|
58597
|
-
(0,
|
|
58598
|
-
|
|
58566
|
+
if (final.exists) (0, import_node_fs21.rmSync)(journal.finalPath, { force: true });
|
|
58567
|
+
(0, import_node_fs21.renameSync)(journal.backupPath, journal.finalPath);
|
|
58568
|
+
syncFile(journal.finalPath);
|
|
58599
58569
|
} else {
|
|
58600
58570
|
throw new IfcPublicationError("IFC final artifact is in an unknown state; recovery retained evidence.");
|
|
58601
58571
|
}
|
|
@@ -58607,25 +58577,25 @@ function restoreArtifact(journal) {
|
|
|
58607
58577
|
if (!fileProofEquals(final, journal.newArtifact)) {
|
|
58608
58578
|
throw new IfcPublicationError("IFC final artifact is in an unknown state; recovery retained evidence.");
|
|
58609
58579
|
}
|
|
58610
|
-
(0,
|
|
58580
|
+
(0, import_node_fs21.rmSync)(journal.finalPath, { force: true });
|
|
58611
58581
|
}
|
|
58612
58582
|
if (backup.exists) throw new IfcPublicationError("unexpected IFC backup exists for a no-prior transaction.");
|
|
58613
58583
|
}
|
|
58614
|
-
if ((0,
|
|
58584
|
+
if ((0, import_node_fs21.existsSync)(journal.tempPath)) {
|
|
58615
58585
|
if (!sameProof(journal.tempPath, journal.newArtifact)) {
|
|
58616
58586
|
throw new IfcPublicationError("IFC temp artifact does not match its recorded proof.");
|
|
58617
58587
|
}
|
|
58618
|
-
(0,
|
|
58588
|
+
(0, import_node_fs21.rmSync)(journal.tempPath, { force: true });
|
|
58619
58589
|
}
|
|
58620
|
-
|
|
58590
|
+
syncDirectoryBestEffort(journal.exportDir);
|
|
58621
58591
|
}
|
|
58622
58592
|
function retireTransaction(txnDir2) {
|
|
58623
58593
|
const match = (0, import_node_path20.basename)(txnDir2).match(ACTIVE_RE);
|
|
58624
58594
|
if (!match) throw new IfcPublicationError("cannot retire an unsafe IFC transaction directory.");
|
|
58625
58595
|
const cleanupDir = (0, import_node_path20.join)((0, import_node_path20.dirname)(txnDir2), `.floless-cleanup-ifc-${match[1]}`);
|
|
58626
|
-
if ((0,
|
|
58627
|
-
(0,
|
|
58628
|
-
|
|
58596
|
+
if ((0, import_node_fs21.existsSync)(cleanupDir)) throw new IfcPublicationError("IFC cleanup directory already exists.");
|
|
58597
|
+
(0, import_node_fs21.renameSync)(txnDir2, cleanupDir);
|
|
58598
|
+
syncDirectoryBestEffort((0, import_node_path20.dirname)(txnDir2));
|
|
58629
58599
|
return cleanupDir;
|
|
58630
58600
|
}
|
|
58631
58601
|
function finishCommitted(txnDir2, journal, allowMissingBackup) {
|
|
@@ -58641,8 +58611,8 @@ function finishCommitted(txnDir2, journal, allowMissingBackup) {
|
|
|
58641
58611
|
if (!fileProofEquals(backup, journal.priorArtifact)) {
|
|
58642
58612
|
throw new IfcPublicationError("committed IFC backup does not match the recorded prior artifact.");
|
|
58643
58613
|
}
|
|
58644
|
-
(0,
|
|
58645
|
-
|
|
58614
|
+
(0, import_node_fs21.rmSync)(journal.backupPath, { force: true });
|
|
58615
|
+
syncDirectoryBestEffort(journal.exportDir);
|
|
58646
58616
|
} else if (!allowMissingBackup) {
|
|
58647
58617
|
throw new IfcPublicationError("committed IFC backup disappeared before verified cleanup.");
|
|
58648
58618
|
}
|
|
@@ -58650,18 +58620,18 @@ function finishCommitted(txnDir2, journal, allowMissingBackup) {
|
|
|
58650
58620
|
throw new IfcPublicationError("unexpected committed IFC backup exists for a no-prior transaction.");
|
|
58651
58621
|
}
|
|
58652
58622
|
const cleanupDir = retireTransaction(txnDir2);
|
|
58653
|
-
(0,
|
|
58654
|
-
|
|
58623
|
+
(0, import_node_fs21.rmSync)(cleanupDir, { recursive: true, force: true });
|
|
58624
|
+
syncDirectoryBestEffort(journal.exportDir);
|
|
58655
58625
|
}
|
|
58656
58626
|
function rollbackTransaction(txnDir2, journal) {
|
|
58657
58627
|
restoreArtifact(journal);
|
|
58658
58628
|
restoreIndex(journal);
|
|
58659
58629
|
const cleanupDir = retireTransaction(txnDir2);
|
|
58660
|
-
(0,
|
|
58661
|
-
|
|
58630
|
+
(0, import_node_fs21.rmSync)(cleanupDir, { recursive: true, force: true });
|
|
58631
|
+
syncDirectoryBestEffort(journal.exportDir);
|
|
58662
58632
|
}
|
|
58663
58633
|
function safeTransactionDirectory(path) {
|
|
58664
|
-
const st = (0,
|
|
58634
|
+
const st = (0, import_node_fs21.lstatSync)(path);
|
|
58665
58635
|
if (!st.isDirectory() || st.isSymbolicLink()) {
|
|
58666
58636
|
throw new IfcPublicationError(`IFC transaction path is not a plain directory: ${path}`);
|
|
58667
58637
|
}
|
|
@@ -58671,7 +58641,7 @@ async function recoverActive(txnDir2, expected) {
|
|
|
58671
58641
|
const journal = loadJournal(txnDir2);
|
|
58672
58642
|
if (!journal) {
|
|
58673
58643
|
const cleanupDir = retireTransaction(txnDir2);
|
|
58674
|
-
(0,
|
|
58644
|
+
(0, import_node_fs21.rmSync)(cleanupDir, { recursive: true, force: true });
|
|
58675
58645
|
return;
|
|
58676
58646
|
}
|
|
58677
58647
|
if (expected && (journal.resource.kind !== expected.kind || journal.resource.key !== expected.key)) {
|
|
@@ -58684,9 +58654,9 @@ async function recoverActive(txnDir2, expected) {
|
|
|
58684
58654
|
}
|
|
58685
58655
|
async function recoverIfcPublicationsInDirectory(exportDir, expected) {
|
|
58686
58656
|
const dir = canonicalPath(exportDir);
|
|
58687
|
-
if (!(0,
|
|
58657
|
+
if (!(0, import_node_fs21.existsSync)(dir)) return [];
|
|
58688
58658
|
safeTransactionDirectory(dir);
|
|
58689
|
-
const entries2 = (0,
|
|
58659
|
+
const entries2 = (0, import_node_fs21.readdirSync)(dir, { withFileTypes: true }).filter((entry2) => ACTIVE_RE.test(entry2.name) || CLEANUP_RE.test(entry2.name));
|
|
58690
58660
|
if (entries2.length > MAX_TRANSACTIONS) {
|
|
58691
58661
|
throw new IfcPublicationError(`IFC recovery refused ${entries2.length} transaction directories (limit ${MAX_TRANSACTIONS}).`);
|
|
58692
58662
|
}
|
|
@@ -58695,8 +58665,8 @@ async function recoverIfcPublicationsInDirectory(exportDir, expected) {
|
|
|
58695
58665
|
const path = (0, import_node_path20.join)(dir, entry2.name);
|
|
58696
58666
|
safeTransactionDirectory(path);
|
|
58697
58667
|
if (CLEANUP_RE.test(entry2.name)) {
|
|
58698
|
-
(0,
|
|
58699
|
-
|
|
58668
|
+
(0, import_node_fs21.rmSync)(path, { recursive: true, force: true });
|
|
58669
|
+
syncDirectoryBestEffort(dir);
|
|
58700
58670
|
recovered.push(entry2.name);
|
|
58701
58671
|
continue;
|
|
58702
58672
|
}
|
|
@@ -58709,9 +58679,9 @@ async function recoverAllIfcPublications() {
|
|
|
58709
58679
|
const recovered = [];
|
|
58710
58680
|
const rootHome = process.env.FLOLESS_HOME ?? (0, import_node_path20.join)((0, import_node_os15.homedir)(), ".floless");
|
|
58711
58681
|
const projectsRoot2 = (0, import_node_path20.join)(rootHome, "projects");
|
|
58712
|
-
if ((0,
|
|
58682
|
+
if ((0, import_node_fs21.existsSync)(projectsRoot2)) {
|
|
58713
58683
|
safeTransactionDirectory(projectsRoot2);
|
|
58714
|
-
for (const entry2 of (0,
|
|
58684
|
+
for (const entry2 of (0, import_node_fs21.readdirSync)(projectsRoot2, { withFileTypes: true })) {
|
|
58715
58685
|
if (entry2.name.startsWith(".")) continue;
|
|
58716
58686
|
if (entry2.isSymbolicLink()) throw new IfcPublicationError(`project recovery root is a link: ${entry2.name}`);
|
|
58717
58687
|
if (!entry2.isDirectory() || !/^[a-z0-9][a-z0-9-]*$/.test(entry2.name)) continue;
|
|
@@ -58723,9 +58693,9 @@ async function recoverAllIfcPublications() {
|
|
|
58723
58693
|
}
|
|
58724
58694
|
}
|
|
58725
58695
|
const root5 = (0, import_node_path20.join)(rootHome, "exports");
|
|
58726
|
-
if ((0,
|
|
58696
|
+
if ((0, import_node_fs21.existsSync)(root5)) {
|
|
58727
58697
|
safeTransactionDirectory(root5);
|
|
58728
|
-
for (const entry2 of (0,
|
|
58698
|
+
for (const entry2 of (0, import_node_fs21.readdirSync)(root5, { withFileTypes: true })) {
|
|
58729
58699
|
if (entry2.name.startsWith(".")) continue;
|
|
58730
58700
|
if (entry2.isSymbolicLink()) throw new IfcPublicationError(`workflow recovery root is a link: ${entry2.name}`);
|
|
58731
58701
|
if (!entry2.isDirectory()) continue;
|
|
@@ -58756,13 +58726,13 @@ function promiseLike(value) {
|
|
|
58756
58726
|
async function publishIfcAtomically(tempPath, finalPath, options) {
|
|
58757
58727
|
if (!options || !validResource(options.resource)) throw new IfcPublicationError("IFC publication resource is invalid.");
|
|
58758
58728
|
const paths = validateRequestPaths(tempPath, finalPath);
|
|
58759
|
-
const tempStat = (0,
|
|
58729
|
+
const tempStat = (0, import_node_fs21.lstatSync)(paths.temp);
|
|
58760
58730
|
if (!tempStat.isFile()) throw new IfcPublicationError("the IFC to publish is not a regular file.");
|
|
58761
58731
|
const validated = validateIfc(paths.temp);
|
|
58762
58732
|
if (options.expectedContentSha256 !== void 0 && validated.proof.sha256 !== options.expectedContentSha256) {
|
|
58763
58733
|
throw new IfcPublicationError("the IFC changed between reconciliation and publication.");
|
|
58764
58734
|
}
|
|
58765
|
-
|
|
58735
|
+
syncFile(paths.temp);
|
|
58766
58736
|
if (options.receipt) {
|
|
58767
58737
|
assertReceiptOptions(options.receipt, options.resource, paths.dir, paths.final, validated.proof);
|
|
58768
58738
|
}
|
|
@@ -58794,8 +58764,8 @@ async function publishIfcAtomically(tempPath, finalPath, options) {
|
|
|
58794
58764
|
};
|
|
58795
58765
|
let journal = { ...base, phase: "prepared" };
|
|
58796
58766
|
let committed = false;
|
|
58797
|
-
(0,
|
|
58798
|
-
|
|
58767
|
+
(0, import_node_fs21.mkdirSync)(txnDir2);
|
|
58768
|
+
syncDirectoryBestEffort(paths.dir);
|
|
58799
58769
|
const hit = (point) => {
|
|
58800
58770
|
options.fault?.(point);
|
|
58801
58771
|
if (options.crashAt === point) throw new SimulatedPublicationCrash(point);
|
|
@@ -58810,13 +58780,13 @@ async function publishIfcAtomically(tempPath, finalPath, options) {
|
|
|
58810
58780
|
phase("prepared");
|
|
58811
58781
|
phase("backing-up");
|
|
58812
58782
|
if (priorArtifact.exists) {
|
|
58813
|
-
(0,
|
|
58814
|
-
|
|
58783
|
+
(0, import_node_fs21.renameSync)(paths.final, backupPath);
|
|
58784
|
+
syncDirectoryBestEffort(paths.dir);
|
|
58815
58785
|
}
|
|
58816
58786
|
phase("promoting");
|
|
58817
|
-
(0,
|
|
58818
|
-
|
|
58819
|
-
|
|
58787
|
+
(0, import_node_fs21.renameSync)(paths.temp, paths.final);
|
|
58788
|
+
syncFile(paths.final);
|
|
58789
|
+
syncDirectoryBestEffort(paths.dir);
|
|
58820
58790
|
if (!sameProof(paths.final, validated.proof)) {
|
|
58821
58791
|
throw new IfcPublicationError("promoted IFC did not match the request artifact proof.");
|
|
58822
58792
|
}
|
|
@@ -58843,8 +58813,8 @@ async function publishIfcAtomically(tempPath, finalPath, options) {
|
|
|
58843
58813
|
if (!fileProofEquals(backup, priorArtifact)) {
|
|
58844
58814
|
throw new IfcPublicationError("IFC backup did not match the recorded prior artifact before cleanup.");
|
|
58845
58815
|
}
|
|
58846
|
-
(0,
|
|
58847
|
-
|
|
58816
|
+
(0, import_node_fs21.rmSync)(backupPath, { force: true });
|
|
58817
|
+
syncDirectoryBestEffort(paths.dir);
|
|
58848
58818
|
} else if (backup.exists) {
|
|
58849
58819
|
throw new IfcPublicationError("unexpected IFC backup exists for a no-prior transaction.");
|
|
58850
58820
|
}
|
|
@@ -58853,8 +58823,8 @@ async function publishIfcAtomically(tempPath, finalPath, options) {
|
|
|
58853
58823
|
const cleanupDir = retireTransaction(txnDir2);
|
|
58854
58824
|
hit("after-retire");
|
|
58855
58825
|
hit("before-cleanup-remove");
|
|
58856
|
-
(0,
|
|
58857
|
-
|
|
58826
|
+
(0, import_node_fs21.rmSync)(cleanupDir, { recursive: true, force: true });
|
|
58827
|
+
syncDirectoryBestEffort(paths.dir);
|
|
58858
58828
|
return { bytes: validated.bytes, cleanupPending: false };
|
|
58859
58829
|
} catch (error) {
|
|
58860
58830
|
if (error instanceof SimulatedPublicationCrash) throw error;
|
|
@@ -58899,8 +58869,8 @@ function cleanupIfcTemp(path) {
|
|
|
58899
58869
|
if (!TEMP_RE.test((0, import_node_path20.basename)(path))) return;
|
|
58900
58870
|
const canonical = canonicalPath(path);
|
|
58901
58871
|
const dir = (0, import_node_path20.dirname)(canonical);
|
|
58902
|
-
if ((0,
|
|
58903
|
-
for (const entry2 of (0,
|
|
58872
|
+
if ((0, import_node_fs21.existsSync)(dir)) {
|
|
58873
|
+
for (const entry2 of (0, import_node_fs21.readdirSync)(dir, { withFileTypes: true })) {
|
|
58904
58874
|
if (!entry2.isDirectory() || !ACTIVE_RE.test(entry2.name)) continue;
|
|
58905
58875
|
try {
|
|
58906
58876
|
const journal = loadJournal((0, import_node_path20.join)(dir, entry2.name));
|
|
@@ -58911,7 +58881,7 @@ function cleanupIfcTemp(path) {
|
|
|
58911
58881
|
}
|
|
58912
58882
|
}
|
|
58913
58883
|
try {
|
|
58914
|
-
(0,
|
|
58884
|
+
(0, import_node_fs21.rmSync)(path, { force: true });
|
|
58915
58885
|
} catch {
|
|
58916
58886
|
}
|
|
58917
58887
|
}
|
|
@@ -58964,7 +58934,7 @@ function registerProjectExportSaveRoute(app, deps = {}) {
|
|
|
58964
58934
|
const current = getProject(req.params.id);
|
|
58965
58935
|
if (!current) throw new ProjectError(`unknown project: ${req.params.id}`);
|
|
58966
58936
|
const directory = projectExportsDir(current.id);
|
|
58967
|
-
(0,
|
|
58937
|
+
(0, import_node_fs22.mkdirSync)(directory, { recursive: true });
|
|
58968
58938
|
return { project: current, initialDirectory: directory };
|
|
58969
58939
|
});
|
|
58970
58940
|
project = prepared.project;
|
|
@@ -59006,7 +58976,7 @@ function registerProjectExportSaveRoute(app, deps = {}) {
|
|
|
59006
58976
|
{ kind: "project", key: project.id }
|
|
59007
58977
|
);
|
|
59008
58978
|
const { data } = await exportProjectZip(project.id, { excludeAbsolutePaths: [selectedPath] });
|
|
59009
|
-
if (!(0,
|
|
58979
|
+
if (!(0, import_node_fs22.existsSync)((0, import_node_path21.dirname)(selectedPath))) throw new Error("the selected folder no longer exists");
|
|
59010
58980
|
await writeArchive(selectedPath, data);
|
|
59011
58981
|
return { ok: true, cancelled: false, filename: (0, import_node_path21.basename)(selectedPath) };
|
|
59012
58982
|
});
|
|
@@ -59572,16 +59542,16 @@ function buildPreview(m, sourceKind, sourceRef, stagedRef) {
|
|
|
59572
59542
|
}
|
|
59573
59543
|
|
|
59574
59544
|
// graft-manifest-reader.ts
|
|
59575
|
-
var
|
|
59545
|
+
var import_node_fs23 = require("node:fs");
|
|
59576
59546
|
var import_node_path22 = require("node:path");
|
|
59577
59547
|
var import_yaml5 = __toESM(require_dist6(), 1);
|
|
59578
59548
|
var asRecord2 = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
|
|
59579
59549
|
function readStagedManifest(agentDir) {
|
|
59580
59550
|
const manifestPath2 = (0, import_node_path22.join)(agentDir, "manifest.yaml");
|
|
59581
|
-
if (!(0,
|
|
59551
|
+
if (!(0, import_node_fs23.existsSync)(manifestPath2)) return null;
|
|
59582
59552
|
let doc;
|
|
59583
59553
|
try {
|
|
59584
|
-
doc = asRecord2((0, import_yaml5.parse)((0,
|
|
59554
|
+
doc = asRecord2((0, import_yaml5.parse)((0, import_node_fs23.readFileSync)(manifestPath2, "utf8")));
|
|
59585
59555
|
} catch {
|
|
59586
59556
|
return null;
|
|
59587
59557
|
}
|
|
@@ -59612,9 +59582,9 @@ function readStagedManifest(agentDir) {
|
|
|
59612
59582
|
let skillCount = Array.isArray(doc.skills) ? doc.skills.length : 0;
|
|
59613
59583
|
if (!skillCount) {
|
|
59614
59584
|
const skillsDir = (0, import_node_path22.join)(agentDir, "skills");
|
|
59615
|
-
if ((0,
|
|
59585
|
+
if ((0, import_node_fs23.existsSync)(skillsDir)) {
|
|
59616
59586
|
try {
|
|
59617
|
-
skillCount = (0,
|
|
59587
|
+
skillCount = (0, import_node_fs23.readdirSync)(skillsDir).filter((f) => f.endsWith(".md")).length;
|
|
59618
59588
|
} catch {
|
|
59619
59589
|
}
|
|
59620
59590
|
}
|
|
@@ -59628,7 +59598,7 @@ function readStagedManifest(agentDir) {
|
|
|
59628
59598
|
}
|
|
59629
59599
|
|
|
59630
59600
|
// graft-stage-registry.ts
|
|
59631
|
-
var
|
|
59601
|
+
var import_node_fs24 = require("node:fs");
|
|
59632
59602
|
var TTL_MS = 30 * 60 * 1e3;
|
|
59633
59603
|
var registry = /* @__PURE__ */ new Map();
|
|
59634
59604
|
function registerStage(token2, tempDir, agentId) {
|
|
@@ -59650,7 +59620,7 @@ function evict(token2) {
|
|
|
59650
59620
|
clearTimeout(e.timer);
|
|
59651
59621
|
registry.delete(token2);
|
|
59652
59622
|
try {
|
|
59653
|
-
(0,
|
|
59623
|
+
(0, import_node_fs24.rmSync)(e.tempDir, { recursive: true, force: true });
|
|
59654
59624
|
} catch {
|
|
59655
59625
|
}
|
|
59656
59626
|
}
|
|
@@ -59659,7 +59629,7 @@ function clearAllStages() {
|
|
|
59659
59629
|
}
|
|
59660
59630
|
|
|
59661
59631
|
// graft-commit.ts
|
|
59662
|
-
var
|
|
59632
|
+
var import_node_fs25 = require("node:fs");
|
|
59663
59633
|
var import_node_path23 = require("node:path");
|
|
59664
59634
|
var GraftCommitError = class extends Error {
|
|
59665
59635
|
constructor(message, code) {
|
|
@@ -59672,32 +59642,32 @@ var GraftCommitError = class extends Error {
|
|
|
59672
59642
|
function commitStaged(tempDir, agentId, targetAgentsDir, force) {
|
|
59673
59643
|
const staged = (0, import_node_path23.join)(tempDir, "agents", agentId);
|
|
59674
59644
|
const target = (0, import_node_path23.join)(targetAgentsDir, agentId);
|
|
59675
|
-
if ((0,
|
|
59645
|
+
if ((0, import_node_fs25.existsSync)(target)) {
|
|
59676
59646
|
if (!force) throw new GraftCommitError(`an agent named "${agentId}" is already installed`, "collision");
|
|
59677
|
-
(0,
|
|
59647
|
+
(0, import_node_fs25.rmSync)(target, { recursive: true, force: true });
|
|
59678
59648
|
}
|
|
59679
|
-
(0,
|
|
59649
|
+
(0, import_node_fs25.mkdirSync)(targetAgentsDir, { recursive: true });
|
|
59680
59650
|
try {
|
|
59681
|
-
(0,
|
|
59651
|
+
(0, import_node_fs25.renameSync)(staged, target);
|
|
59682
59652
|
} catch {
|
|
59683
|
-
(0,
|
|
59653
|
+
(0, import_node_fs25.cpSync)(staged, target, { recursive: true });
|
|
59684
59654
|
}
|
|
59685
|
-
(0,
|
|
59655
|
+
(0, import_node_fs25.rmSync)(tempDir, { recursive: true, force: true });
|
|
59686
59656
|
return { agentId };
|
|
59687
59657
|
}
|
|
59688
59658
|
function matchAssemblies(globOrDir) {
|
|
59689
59659
|
let dir;
|
|
59690
59660
|
let pattern;
|
|
59691
|
-
if ((0,
|
|
59661
|
+
if ((0, import_node_fs25.existsSync)(globOrDir) && (0, import_node_fs25.statSync)(globOrDir).isDirectory()) {
|
|
59692
59662
|
dir = globOrDir;
|
|
59693
59663
|
pattern = "*.dll";
|
|
59694
59664
|
} else {
|
|
59695
59665
|
dir = (0, import_node_path23.dirname)(globOrDir);
|
|
59696
59666
|
pattern = (0, import_node_path23.basename)(globOrDir);
|
|
59697
59667
|
}
|
|
59698
|
-
if (!dir || !(0,
|
|
59668
|
+
if (!dir || !(0, import_node_fs25.existsSync)(dir) || !(0, import_node_fs25.statSync)(dir).isDirectory()) return [];
|
|
59699
59669
|
const re = globToRegExp(pattern);
|
|
59700
|
-
return (0,
|
|
59670
|
+
return (0, import_node_fs25.readdirSync)(dir).filter((f) => re.test(f)).sort();
|
|
59701
59671
|
}
|
|
59702
59672
|
function globToRegExp(p) {
|
|
59703
59673
|
const esc = p.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
@@ -59706,7 +59676,7 @@ function globToRegExp(p) {
|
|
|
59706
59676
|
|
|
59707
59677
|
// floless-store.ts
|
|
59708
59678
|
var import_node_crypto14 = require("node:crypto");
|
|
59709
|
-
var
|
|
59679
|
+
var import_node_fs26 = require("node:fs");
|
|
59710
59680
|
var import_node_os16 = require("node:os");
|
|
59711
59681
|
var import_node_path24 = require("node:path");
|
|
59712
59682
|
var ROOT2 = process.env.FLOLESS_HOME ?? (0, import_node_path24.join)((0, import_node_os16.homedir)(), ".floless");
|
|
@@ -59714,7 +59684,7 @@ var TEMPLATES_FILE = (0, import_node_path24.join)(ROOT2, "templates.json");
|
|
|
59714
59684
|
var REQUESTS_DIR = (0, import_node_path24.join)(ROOT2, "requests");
|
|
59715
59685
|
var STEEL_FAVS_FILE = (0, import_node_path24.join)(ROOT2, "steel-connections.json");
|
|
59716
59686
|
function ensureRoot() {
|
|
59717
|
-
if (!(0,
|
|
59687
|
+
if (!(0, import_node_fs26.existsSync)(ROOT2)) (0, import_node_fs26.mkdirSync)(ROOT2, { recursive: true });
|
|
59718
59688
|
}
|
|
59719
59689
|
function withinRequestsDir(p) {
|
|
59720
59690
|
const base = (0, import_node_path24.resolve)(REQUESTS_DIR);
|
|
@@ -59722,9 +59692,9 @@ function withinRequestsDir(p) {
|
|
|
59722
59692
|
return full === base || full.startsWith(base + import_node_path24.sep);
|
|
59723
59693
|
}
|
|
59724
59694
|
function listTemplates() {
|
|
59725
|
-
if (!(0,
|
|
59695
|
+
if (!(0, import_node_fs26.existsSync)(TEMPLATES_FILE)) return [];
|
|
59726
59696
|
try {
|
|
59727
|
-
const parsed = JSON.parse((0,
|
|
59697
|
+
const parsed = JSON.parse((0, import_node_fs26.readFileSync)(TEMPLATES_FILE, "utf8"));
|
|
59728
59698
|
return Array.isArray(parsed) ? parsed : [];
|
|
59729
59699
|
} catch {
|
|
59730
59700
|
return [];
|
|
@@ -59733,8 +59703,8 @@ function listTemplates() {
|
|
|
59733
59703
|
function writeTemplates(list) {
|
|
59734
59704
|
ensureRoot();
|
|
59735
59705
|
const tmp = `${TEMPLATES_FILE}.${process.pid}.tmp`;
|
|
59736
|
-
(0,
|
|
59737
|
-
(0,
|
|
59706
|
+
(0, import_node_fs26.writeFileSync)(tmp, JSON.stringify(list, null, 2));
|
|
59707
|
+
(0, import_node_fs26.renameSync)(tmp, TEMPLATES_FILE);
|
|
59738
59708
|
}
|
|
59739
59709
|
function addTemplate(input) {
|
|
59740
59710
|
const list = listTemplates();
|
|
@@ -59778,9 +59748,9 @@ function updateTemplate(id, patch2) {
|
|
|
59778
59748
|
return cur;
|
|
59779
59749
|
}
|
|
59780
59750
|
function listSteelFavourites() {
|
|
59781
|
-
if (!(0,
|
|
59751
|
+
if (!(0, import_node_fs26.existsSync)(STEEL_FAVS_FILE)) return [];
|
|
59782
59752
|
try {
|
|
59783
|
-
const parsed = JSON.parse((0,
|
|
59753
|
+
const parsed = JSON.parse((0, import_node_fs26.readFileSync)(STEEL_FAVS_FILE, "utf8"));
|
|
59784
59754
|
return Array.isArray(parsed) ? parsed : [];
|
|
59785
59755
|
} catch {
|
|
59786
59756
|
return [];
|
|
@@ -59789,8 +59759,8 @@ function listSteelFavourites() {
|
|
|
59789
59759
|
function writeSteelFavourites(list) {
|
|
59790
59760
|
ensureRoot();
|
|
59791
59761
|
const tmp = `${STEEL_FAVS_FILE}.${process.pid}.tmp`;
|
|
59792
|
-
(0,
|
|
59793
|
-
(0,
|
|
59762
|
+
(0, import_node_fs26.writeFileSync)(tmp, JSON.stringify(list, null, 2));
|
|
59763
|
+
(0, import_node_fs26.renameSync)(tmp, STEEL_FAVS_FILE);
|
|
59794
59764
|
}
|
|
59795
59765
|
function addSteelFavourite(input) {
|
|
59796
59766
|
const list = listSteelFavourites();
|
|
@@ -59829,13 +59799,13 @@ function updateSteelFavourite(id, patch2) {
|
|
|
59829
59799
|
}
|
|
59830
59800
|
function addRequest(req, decoded = []) {
|
|
59831
59801
|
ensureRoot();
|
|
59832
|
-
if (!(0,
|
|
59802
|
+
if (!(0, import_node_fs26.existsSync)(REQUESTS_DIR)) (0, import_node_fs26.mkdirSync)(REQUESTS_DIR, { recursive: true });
|
|
59833
59803
|
const id = (0, import_node_crypto14.randomUUID)();
|
|
59834
59804
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
59835
59805
|
const base = `${createdAt.replace(/[:.]/g, "-")}__${id}`;
|
|
59836
59806
|
const snapshots = decoded.map((d, i) => {
|
|
59837
59807
|
const p = (0, import_node_path24.join)(REQUESTS_DIR, `${base}__snap${i + 1}.${d.ext}`);
|
|
59838
|
-
(0,
|
|
59808
|
+
(0, import_node_fs26.writeFileSync)(p, d.buf);
|
|
59839
59809
|
return p;
|
|
59840
59810
|
});
|
|
59841
59811
|
const full = {
|
|
@@ -59845,82 +59815,82 @@ function addRequest(req, decoded = []) {
|
|
|
59845
59815
|
...req,
|
|
59846
59816
|
...snapshots.length ? { snapshots } : {}
|
|
59847
59817
|
};
|
|
59848
|
-
(0,
|
|
59818
|
+
(0, import_node_fs26.writeFileSync)((0, import_node_path24.join)(REQUESTS_DIR, `${base}.json`), JSON.stringify(full, null, 2));
|
|
59849
59819
|
return full;
|
|
59850
59820
|
}
|
|
59851
59821
|
function listRequests() {
|
|
59852
|
-
if (!(0,
|
|
59853
|
-
return (0,
|
|
59822
|
+
if (!(0, import_node_fs26.existsSync)(REQUESTS_DIR)) return [];
|
|
59823
|
+
return (0, import_node_fs26.readdirSync)(REQUESTS_DIR).filter((f) => f.endsWith(".json")).sort().map((f) => {
|
|
59854
59824
|
try {
|
|
59855
|
-
return JSON.parse((0,
|
|
59825
|
+
return JSON.parse((0, import_node_fs26.readFileSync)((0, import_node_path24.join)(REQUESTS_DIR, f), "utf8"));
|
|
59856
59826
|
} catch {
|
|
59857
59827
|
return null;
|
|
59858
59828
|
}
|
|
59859
59829
|
}).filter((r) => r !== null);
|
|
59860
59830
|
}
|
|
59861
59831
|
function deleteRequest(id) {
|
|
59862
|
-
if (!(0,
|
|
59863
|
-
const file = (0,
|
|
59832
|
+
if (!(0, import_node_fs26.existsSync)(REQUESTS_DIR)) return false;
|
|
59833
|
+
const file = (0, import_node_fs26.readdirSync)(REQUESTS_DIR).find((f) => f.endsWith(`__${id}.json`));
|
|
59864
59834
|
if (!file) return false;
|
|
59865
59835
|
try {
|
|
59866
|
-
const parsed = JSON.parse((0,
|
|
59836
|
+
const parsed = JSON.parse((0, import_node_fs26.readFileSync)((0, import_node_path24.join)(REQUESTS_DIR, file), "utf8"));
|
|
59867
59837
|
for (const p of parsed.snapshots ?? []) {
|
|
59868
59838
|
if (!withinRequestsDir(p)) continue;
|
|
59869
59839
|
try {
|
|
59870
|
-
(0,
|
|
59840
|
+
(0, import_node_fs26.rmSync)(p);
|
|
59871
59841
|
} catch {
|
|
59872
59842
|
}
|
|
59873
59843
|
}
|
|
59874
59844
|
} catch {
|
|
59875
59845
|
}
|
|
59876
|
-
(0,
|
|
59846
|
+
(0, import_node_fs26.rmSync)((0, import_node_path24.join)(REQUESTS_DIR, file));
|
|
59877
59847
|
return true;
|
|
59878
59848
|
}
|
|
59879
59849
|
function hasRequestFile(id) {
|
|
59880
|
-
if (!(0,
|
|
59881
|
-
return (0,
|
|
59850
|
+
if (!(0, import_node_fs26.existsSync)(REQUESTS_DIR)) return false;
|
|
59851
|
+
return (0, import_node_fs26.readdirSync)(REQUESTS_DIR).some((f) => f.endsWith(`__${id}.json`));
|
|
59882
59852
|
}
|
|
59883
59853
|
function getRequest(id) {
|
|
59884
|
-
if (!(0,
|
|
59885
|
-
const file = (0,
|
|
59854
|
+
if (!(0, import_node_fs26.existsSync)(REQUESTS_DIR)) return null;
|
|
59855
|
+
const file = (0, import_node_fs26.readdirSync)(REQUESTS_DIR).find((f) => f.endsWith(`__${id}.json`));
|
|
59886
59856
|
if (!file) return null;
|
|
59887
59857
|
try {
|
|
59888
|
-
return JSON.parse((0,
|
|
59858
|
+
return JSON.parse((0, import_node_fs26.readFileSync)((0, import_node_path24.join)(REQUESTS_DIR, file), "utf8"));
|
|
59889
59859
|
} catch {
|
|
59890
59860
|
return null;
|
|
59891
59861
|
}
|
|
59892
59862
|
}
|
|
59893
59863
|
function patchRequest(id, patch2) {
|
|
59894
|
-
if (!(0,
|
|
59895
|
-
const file = (0,
|
|
59864
|
+
if (!(0, import_node_fs26.existsSync)(REQUESTS_DIR)) return null;
|
|
59865
|
+
const file = (0, import_node_fs26.readdirSync)(REQUESTS_DIR).find((f) => f.endsWith(`__${id}.json`));
|
|
59896
59866
|
if (!file) return null;
|
|
59897
59867
|
try {
|
|
59898
|
-
const cur = JSON.parse((0,
|
|
59868
|
+
const cur = JSON.parse((0, import_node_fs26.readFileSync)((0, import_node_path24.join)(REQUESTS_DIR, file), "utf8"));
|
|
59899
59869
|
const next = { ...cur, ...patch2, id: cur.id, createdAt: cur.createdAt };
|
|
59900
|
-
(0,
|
|
59870
|
+
(0, import_node_fs26.writeFileSync)((0, import_node_path24.join)(REQUESTS_DIR, file), JSON.stringify(next, null, 2));
|
|
59901
59871
|
return next;
|
|
59902
59872
|
} catch {
|
|
59903
59873
|
return null;
|
|
59904
59874
|
}
|
|
59905
59875
|
}
|
|
59906
59876
|
function clearRequests() {
|
|
59907
|
-
if (!(0,
|
|
59908
|
-
const allFiles = (0,
|
|
59877
|
+
if (!(0, import_node_fs26.existsSync)(REQUESTS_DIR)) return 0;
|
|
59878
|
+
const allFiles = (0, import_node_fs26.readdirSync)(REQUESTS_DIR);
|
|
59909
59879
|
const jsonFiles = allFiles.filter((f) => f.endsWith(".json"));
|
|
59910
59880
|
for (const f of allFiles) {
|
|
59911
59881
|
try {
|
|
59912
|
-
(0,
|
|
59882
|
+
(0, import_node_fs26.rmSync)((0, import_node_path24.join)(REQUESTS_DIR, f));
|
|
59913
59883
|
} catch {
|
|
59914
59884
|
}
|
|
59915
59885
|
}
|
|
59916
59886
|
return jsonFiles.length;
|
|
59917
59887
|
}
|
|
59918
59888
|
function snapshotPathFor(id, n) {
|
|
59919
|
-
if (!(0,
|
|
59920
|
-
const file = (0,
|
|
59889
|
+
if (!(0, import_node_fs26.existsSync)(REQUESTS_DIR)) return null;
|
|
59890
|
+
const file = (0, import_node_fs26.readdirSync)(REQUESTS_DIR).find((f) => f.endsWith(`__${id}.json`));
|
|
59921
59891
|
if (!file) return null;
|
|
59922
59892
|
try {
|
|
59923
|
-
const parsed = JSON.parse((0,
|
|
59893
|
+
const parsed = JSON.parse((0, import_node_fs26.readFileSync)((0, import_node_path24.join)(REQUESTS_DIR, file), "utf8"));
|
|
59924
59894
|
const cand = parsed.snapshots?.[n] ?? null;
|
|
59925
59895
|
return cand && withinRequestsDir(cand) ? cand : null;
|
|
59926
59896
|
} catch {
|
|
@@ -59956,7 +59926,7 @@ function decodeSnapshots(inputs) {
|
|
|
59956
59926
|
}
|
|
59957
59927
|
|
|
59958
59928
|
// connection-import.ts
|
|
59959
|
-
var
|
|
59929
|
+
var import_node_fs27 = require("node:fs");
|
|
59960
59930
|
var import_node_path25 = require("node:path");
|
|
59961
59931
|
|
|
59962
59932
|
// ifc-frame.ts
|
|
@@ -59989,7 +59959,7 @@ async function ensureConnectionReader() {
|
|
|
59989
59959
|
}
|
|
59990
59960
|
function writeReaderApp(companionId, command, ifcPath, id) {
|
|
59991
59961
|
const dir = appPath(companionId);
|
|
59992
|
-
(0,
|
|
59962
|
+
(0, import_node_fs27.mkdirSync)(dir, { recursive: true });
|
|
59993
59963
|
const flo = (0, import_node_path25.join)(dir, `${companionId}.flo`);
|
|
59994
59964
|
const lines = [
|
|
59995
59965
|
`app: ${companionId}`,
|
|
@@ -60023,15 +59993,9 @@ function writeReaderApp(companionId, command, ifcPath, id) {
|
|
|
60023
59993
|
];
|
|
60024
59994
|
if (command === "extract") lines.push(` id: ${JSON.stringify(id ?? "")}`);
|
|
60025
59995
|
lines.push("");
|
|
60026
|
-
(0,
|
|
59996
|
+
(0, import_node_fs27.writeFileSync)(flo, lines.join("\n"));
|
|
60027
59997
|
return flo;
|
|
60028
59998
|
}
|
|
60029
|
-
function nodeOutput(traceText, node) {
|
|
60030
|
-
const events = traceText ? parseTrace(traceText) : [];
|
|
60031
|
-
const ev = [...events].reverse().find((e) => e.kind === "node-output" && e.node === node);
|
|
60032
|
-
const data = ev ? ev.data : null;
|
|
60033
|
-
return data && typeof data === "object" ? data : null;
|
|
60034
|
-
}
|
|
60035
59999
|
async function runReader(companionId, command, ifcPath, id, opts = {}) {
|
|
60036
60000
|
const prev = readerChain;
|
|
60037
60001
|
let release;
|
|
@@ -60222,7 +60186,7 @@ async function extractConnection(companionId, ifcPath, id, opts = {}) {
|
|
|
60222
60186
|
}
|
|
60223
60187
|
|
|
60224
60188
|
// contract-store.ts
|
|
60225
|
-
var
|
|
60189
|
+
var import_node_fs28 = require("node:fs");
|
|
60226
60190
|
var import_node_path26 = require("node:path");
|
|
60227
60191
|
var import_node_os17 = require("node:os");
|
|
60228
60192
|
var ContractError = class extends Error {
|
|
@@ -60253,30 +60217,30 @@ function contractPath(appId, projectId) {
|
|
|
60253
60217
|
function moveAppContractBytes(fromAppId, toAppId) {
|
|
60254
60218
|
const from = contractPath(fromAppId);
|
|
60255
60219
|
const to = contractPath(toAppId);
|
|
60256
|
-
if (from === to || !(0,
|
|
60257
|
-
(0,
|
|
60258
|
-
(0,
|
|
60220
|
+
if (from === to || !(0, import_node_fs28.existsSync)(from)) return false;
|
|
60221
|
+
(0, import_node_fs28.mkdirSync)((0, import_node_path26.dirname)(to), { recursive: true });
|
|
60222
|
+
(0, import_node_fs28.renameSync)(from, to);
|
|
60259
60223
|
return true;
|
|
60260
60224
|
}
|
|
60261
60225
|
function copyAppContractBytes(fromAppId, toAppId) {
|
|
60262
60226
|
const from = contractPath(fromAppId);
|
|
60263
60227
|
const to = contractPath(toAppId);
|
|
60264
|
-
if (from === to || !(0,
|
|
60265
|
-
(0,
|
|
60266
|
-
(0,
|
|
60228
|
+
if (from === to || !(0, import_node_fs28.existsSync)(from)) return false;
|
|
60229
|
+
(0, import_node_fs28.mkdirSync)((0, import_node_path26.dirname)(to), { recursive: true });
|
|
60230
|
+
(0, import_node_fs28.copyFileSync)(from, to);
|
|
60267
60231
|
return true;
|
|
60268
60232
|
}
|
|
60269
60233
|
function dropAppContractBytes(appId) {
|
|
60270
60234
|
const p = contractPath(appId);
|
|
60271
|
-
if (!(0,
|
|
60272
|
-
(0,
|
|
60235
|
+
if (!(0, import_node_fs28.existsSync)(p)) return false;
|
|
60236
|
+
(0, import_node_fs28.rmSync)(p, { force: true });
|
|
60273
60237
|
return true;
|
|
60274
60238
|
}
|
|
60275
60239
|
function readContract(appId, projectId) {
|
|
60276
60240
|
const p = contractPath(appId, projectId);
|
|
60277
|
-
if (!(0,
|
|
60241
|
+
if (!(0, import_node_fs28.existsSync)(p)) return null;
|
|
60278
60242
|
try {
|
|
60279
|
-
return JSON.parse((0,
|
|
60243
|
+
return JSON.parse((0, import_node_fs28.readFileSync)(p, "utf8"));
|
|
60280
60244
|
} catch (e) {
|
|
60281
60245
|
console.warn(`readContract: ignoring unreadable contract at ${p}: ${e instanceof Error ? e.message : e}`);
|
|
60282
60246
|
return null;
|
|
@@ -60295,17 +60259,17 @@ function writeContract(appId, doc, projectId, privileged) {
|
|
|
60295
60259
|
throw e;
|
|
60296
60260
|
}
|
|
60297
60261
|
if (projectId) {
|
|
60298
|
-
if (!(0,
|
|
60299
|
-
} else if (!(0,
|
|
60300
|
-
(0,
|
|
60262
|
+
if (!(0, import_node_fs28.existsSync)((0, import_node_path26.dirname)(p))) throw new ContractError(`unknown project: ${projectId}`);
|
|
60263
|
+
} else if (!(0, import_node_fs28.existsSync)(DIR)) {
|
|
60264
|
+
(0, import_node_fs28.mkdirSync)(DIR, { recursive: true });
|
|
60301
60265
|
}
|
|
60302
60266
|
const tmp = `${p}.${process.pid}.tmp`;
|
|
60303
|
-
(0,
|
|
60304
|
-
(0,
|
|
60267
|
+
(0, import_node_fs28.writeFileSync)(tmp, JSON.stringify(doc));
|
|
60268
|
+
(0, import_node_fs28.renameSync)(tmp, p);
|
|
60305
60269
|
}
|
|
60306
60270
|
|
|
60307
60271
|
// contract-gateway.ts
|
|
60308
|
-
var
|
|
60272
|
+
var import_node_fs32 = require("node:fs");
|
|
60309
60273
|
|
|
60310
60274
|
// contract-resolve.ts
|
|
60311
60275
|
function bakedContractNode(app) {
|
|
@@ -60337,7 +60301,7 @@ function readContractForApp(appId, readAppFn = readApp) {
|
|
|
60337
60301
|
|
|
60338
60302
|
// project-versions-store.ts
|
|
60339
60303
|
var import_node_crypto15 = require("node:crypto");
|
|
60340
|
-
var
|
|
60304
|
+
var import_node_fs29 = require("node:fs");
|
|
60341
60305
|
var import_promises3 = require("node:fs/promises");
|
|
60342
60306
|
var import_node_path27 = require("node:path");
|
|
60343
60307
|
var BLOB_MIN = 8192;
|
|
@@ -60349,8 +60313,8 @@ var objectsDir = (id) => (0, import_node_path27.join)(projectDir(id), "objects")
|
|
|
60349
60313
|
var logPath = (id) => (0, import_node_path27.join)(versionsDir(id), "log.json");
|
|
60350
60314
|
function writeAtomic(path, text3) {
|
|
60351
60315
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
60352
|
-
(0,
|
|
60353
|
-
(0,
|
|
60316
|
+
(0, import_node_fs29.writeFileSync)(tmp, text3);
|
|
60317
|
+
(0, import_node_fs29.renameSync)(tmp, path);
|
|
60354
60318
|
}
|
|
60355
60319
|
function isVersionMeta(v) {
|
|
60356
60320
|
if (!v || typeof v !== "object") return false;
|
|
@@ -60385,7 +60349,7 @@ function isValidSource(s) {
|
|
|
60385
60349
|
}
|
|
60386
60350
|
function loadLog(id) {
|
|
60387
60351
|
try {
|
|
60388
|
-
const parsed = JSON.parse((0,
|
|
60352
|
+
const parsed = JSON.parse((0, import_node_fs29.readFileSync)(logPath(id), "utf8"));
|
|
60389
60353
|
const raw = parsed && typeof parsed === "object" && Array.isArray(parsed.versions) ? parsed.versions : [];
|
|
60390
60354
|
return { versions: raw.filter(isVersionMeta) };
|
|
60391
60355
|
} catch {
|
|
@@ -60422,7 +60386,7 @@ function versionBlobHash(node) {
|
|
|
60422
60386
|
function readVersionBlob(id, hash2) {
|
|
60423
60387
|
if (!HASH_RE.test(hash2)) return null;
|
|
60424
60388
|
try {
|
|
60425
|
-
const value = (0,
|
|
60389
|
+
const value = (0, import_node_fs29.readFileSync)((0, import_node_path27.join)(objectsDir(id), hash2), "utf8");
|
|
60426
60390
|
return (0, import_node_crypto15.createHash)("sha256").update(value).digest("hex") === hash2 ? value : null;
|
|
60427
60391
|
} catch {
|
|
60428
60392
|
return null;
|
|
@@ -60484,21 +60448,21 @@ function claimVersionNumber(id, from) {
|
|
|
60484
60448
|
const dir = versionsDir(id);
|
|
60485
60449
|
const CAP = 1e5;
|
|
60486
60450
|
for (let n = Math.max(1, from); n < from + CAP; n++) {
|
|
60487
|
-
if ((0,
|
|
60451
|
+
if ((0, import_node_fs29.existsSync)((0, import_node_path27.join)(dir, `${n}.json`))) continue;
|
|
60488
60452
|
try {
|
|
60489
|
-
(0,
|
|
60453
|
+
(0, import_node_fs29.mkdirSync)((0, import_node_path27.join)(dir, `.claim-${n}`));
|
|
60490
60454
|
} catch (e) {
|
|
60491
60455
|
if (e.code === "EEXIST") continue;
|
|
60492
60456
|
throw e;
|
|
60493
60457
|
}
|
|
60494
|
-
if (!(0,
|
|
60458
|
+
if (!(0, import_node_fs29.existsSync)((0, import_node_path27.join)(dir, `${n}.json`))) return n;
|
|
60495
60459
|
releaseVersionClaim(id, n);
|
|
60496
60460
|
}
|
|
60497
60461
|
throw new Error(`project ${id}: no free version number after ${CAP} attempts from ${from}`);
|
|
60498
60462
|
}
|
|
60499
60463
|
function releaseVersionClaim(id, n) {
|
|
60500
60464
|
try {
|
|
60501
|
-
(0,
|
|
60465
|
+
(0, import_node_fs29.rmSync)((0, import_node_path27.join)(versionsDir(id), `.claim-${n}`), { recursive: true, force: true });
|
|
60502
60466
|
} catch {
|
|
60503
60467
|
}
|
|
60504
60468
|
}
|
|
@@ -60509,13 +60473,13 @@ function withLogClaim(id, fn) {
|
|
|
60509
60473
|
const deadline = Date.now() + 250;
|
|
60510
60474
|
for (; ; ) {
|
|
60511
60475
|
try {
|
|
60512
|
-
(0,
|
|
60476
|
+
(0, import_node_fs29.writeFileSync)(claim, me, { flag: "wx" });
|
|
60513
60477
|
break;
|
|
60514
60478
|
} catch (e) {
|
|
60515
60479
|
if (e.code !== "EEXIST") throw e;
|
|
60516
60480
|
try {
|
|
60517
|
-
if (Date.now() - (0,
|
|
60518
|
-
(0,
|
|
60481
|
+
if (Date.now() - (0, import_node_fs29.statSync)(claim).mtimeMs > STALE_MS3) {
|
|
60482
|
+
(0, import_node_fs29.rmSync)(claim, { force: true });
|
|
60519
60483
|
continue;
|
|
60520
60484
|
}
|
|
60521
60485
|
} catch {
|
|
@@ -60530,19 +60494,19 @@ function withLogClaim(id, fn) {
|
|
|
60530
60494
|
return fn();
|
|
60531
60495
|
} finally {
|
|
60532
60496
|
try {
|
|
60533
|
-
if ((0,
|
|
60497
|
+
if ((0, import_node_fs29.readFileSync)(claim, "utf8") === me) (0, import_node_fs29.rmSync)(claim, { force: true });
|
|
60534
60498
|
} catch {
|
|
60535
60499
|
}
|
|
60536
60500
|
}
|
|
60537
60501
|
}
|
|
60538
60502
|
function createVersion(id, contract, meta) {
|
|
60539
|
-
(0,
|
|
60540
|
-
(0,
|
|
60503
|
+
(0, import_node_fs29.mkdirSync)(versionsDir(id), { recursive: true });
|
|
60504
|
+
(0, import_node_fs29.mkdirSync)(objectsDir(id), { recursive: true });
|
|
60541
60505
|
const blobs = /* @__PURE__ */ new Map();
|
|
60542
60506
|
const skeleton = dehydrate(contract, blobs);
|
|
60543
60507
|
for (const [hash2, text3] of blobs) {
|
|
60544
60508
|
const p = (0, import_node_path27.join)(objectsDir(id), hash2);
|
|
60545
|
-
if (!(0,
|
|
60509
|
+
if (!(0, import_node_fs29.existsSync)(p)) writeAtomic(p, text3);
|
|
60546
60510
|
}
|
|
60547
60511
|
const log2 = loadLog(id);
|
|
60548
60512
|
const n = claimVersionNumber(id, (log2.versions.at(-1)?.n ?? 0) + 1);
|
|
@@ -60571,7 +60535,7 @@ function createVersion(id, contract, meta) {
|
|
|
60571
60535
|
});
|
|
60572
60536
|
} catch (e) {
|
|
60573
60537
|
try {
|
|
60574
|
-
(0,
|
|
60538
|
+
(0, import_node_fs29.rmSync)(snapshotPath, { force: true });
|
|
60575
60539
|
} catch {
|
|
60576
60540
|
}
|
|
60577
60541
|
throw e;
|
|
@@ -60587,7 +60551,7 @@ function listVersions(id) {
|
|
|
60587
60551
|
}
|
|
60588
60552
|
function readVersion(id, n) {
|
|
60589
60553
|
try {
|
|
60590
|
-
const snap = JSON.parse((0,
|
|
60554
|
+
const snap = JSON.parse((0, import_node_fs29.readFileSync)((0, import_node_path27.join)(versionsDir(id), `${n}.json`), "utf8"));
|
|
60591
60555
|
return rehydrate(snap.contract, id);
|
|
60592
60556
|
} catch {
|
|
60593
60557
|
return null;
|
|
@@ -60612,7 +60576,7 @@ async function readVersionAsync(id, n) {
|
|
|
60612
60576
|
}
|
|
60613
60577
|
function readVersionSkeleton(id, n) {
|
|
60614
60578
|
try {
|
|
60615
|
-
const snap = JSON.parse((0,
|
|
60579
|
+
const snap = JSON.parse((0, import_node_fs29.readFileSync)((0, import_node_path27.join)(versionsDir(id), `${n}.json`), "utf8"));
|
|
60616
60580
|
return snap.contract;
|
|
60617
60581
|
} catch {
|
|
60618
60582
|
return null;
|
|
@@ -60628,7 +60592,7 @@ async function readVersionSkeletonAsync(id, n) {
|
|
|
60628
60592
|
}
|
|
60629
60593
|
|
|
60630
60594
|
// activation-store.ts
|
|
60631
|
-
var
|
|
60595
|
+
var import_node_fs30 = require("node:fs");
|
|
60632
60596
|
var import_node_path28 = require("node:path");
|
|
60633
60597
|
var FILENAME = ".floless-activation-record.json";
|
|
60634
60598
|
var recordPath = (projectId) => (0, import_node_path28.join)(projectDir(projectId), FILENAME);
|
|
@@ -60639,7 +60603,7 @@ function isStoredActivation(v) {
|
|
|
60639
60603
|
}
|
|
60640
60604
|
function readActivation(projectId) {
|
|
60641
60605
|
try {
|
|
60642
|
-
const raw = JSON.parse((0,
|
|
60606
|
+
const raw = JSON.parse((0, import_node_fs30.readFileSync)(recordPath(projectId), "utf8"));
|
|
60643
60607
|
return isStoredActivation(raw) ? raw : null;
|
|
60644
60608
|
} catch {
|
|
60645
60609
|
return null;
|
|
@@ -60647,15 +60611,15 @@ function readActivation(projectId) {
|
|
|
60647
60611
|
}
|
|
60648
60612
|
function writeActivation(projectId, rec) {
|
|
60649
60613
|
const path = recordPath(projectId);
|
|
60650
|
-
(0,
|
|
60614
|
+
(0, import_node_fs30.mkdirSync)(projectDir(projectId), { recursive: true });
|
|
60651
60615
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
60652
|
-
(0,
|
|
60616
|
+
(0, import_node_fs30.writeFileSync)(tmp, `${JSON.stringify(rec, null, 2)}
|
|
60653
60617
|
`);
|
|
60654
|
-
(0,
|
|
60618
|
+
(0, import_node_fs30.renameSync)(tmp, path);
|
|
60655
60619
|
}
|
|
60656
60620
|
function dropActivation(projectId) {
|
|
60657
60621
|
try {
|
|
60658
|
-
(0,
|
|
60622
|
+
(0, import_node_fs30.rmSync)(recordPath(projectId), { force: true });
|
|
60659
60623
|
} catch {
|
|
60660
60624
|
}
|
|
60661
60625
|
}
|
|
@@ -60692,7 +60656,7 @@ function incarnationOf(projectId) {
|
|
|
60692
60656
|
}
|
|
60693
60657
|
|
|
60694
60658
|
// contract-transaction.ts
|
|
60695
|
-
var
|
|
60659
|
+
var import_node_fs31 = require("node:fs");
|
|
60696
60660
|
var import_node_crypto17 = require("node:crypto");
|
|
60697
60661
|
var import_node_path29 = require("node:path");
|
|
60698
60662
|
|
|
@@ -60705,6 +60669,47 @@ function contractHash(contract) {
|
|
|
60705
60669
|
var import_node_crypto16 = require("node:crypto");
|
|
60706
60670
|
|
|
60707
60671
|
// ../web/steel-3d-core.js
|
|
60672
|
+
var SECTION_FAMILIES = [
|
|
60673
|
+
["W", "I"],
|
|
60674
|
+
["M", "I"],
|
|
60675
|
+
["S", "I"],
|
|
60676
|
+
["HP", "I"],
|
|
60677
|
+
// US I-family
|
|
60678
|
+
["UC", "I"],
|
|
60679
|
+
["UB", "I"],
|
|
60680
|
+
["UKC", "I"],
|
|
60681
|
+
["UKB", "I"],
|
|
60682
|
+
["IPE", "I"],
|
|
60683
|
+
["HE", "I"],
|
|
60684
|
+
// UK/EU I-family
|
|
60685
|
+
["C", "C"],
|
|
60686
|
+
["MC", "C"],
|
|
60687
|
+
["PFC", "C"],
|
|
60688
|
+
// channels
|
|
60689
|
+
["L", "L"],
|
|
60690
|
+
// angles
|
|
60691
|
+
["HSS", "TUBE"],
|
|
60692
|
+
["PIPE", "TUBE"],
|
|
60693
|
+
["TS", "TUBE"],
|
|
60694
|
+
["TUBE", "TUBE"],
|
|
60695
|
+
["HSQ", "TUBE"],
|
|
60696
|
+
["SHS", "TUBE"],
|
|
60697
|
+
["RHS", "TUBE"],
|
|
60698
|
+
["CHS", "TUBE"]
|
|
60699
|
+
// hollow sections
|
|
60700
|
+
];
|
|
60701
|
+
function sectionKindOf(profile) {
|
|
60702
|
+
const p = String(profile == null ? "" : profile).toUpperCase().trim();
|
|
60703
|
+
let kind = "BOX";
|
|
60704
|
+
let best = 0;
|
|
60705
|
+
for (const [prefix, familyKind] of SECTION_FAMILIES) {
|
|
60706
|
+
if (prefix.length > best && p.startsWith(prefix)) {
|
|
60707
|
+
best = prefix.length;
|
|
60708
|
+
kind = familyKind;
|
|
60709
|
+
}
|
|
60710
|
+
}
|
|
60711
|
+
return kind;
|
|
60712
|
+
}
|
|
60708
60713
|
var nz = (n) => n + 0;
|
|
60709
60714
|
function dispToMm(pt, ptPerFt) {
|
|
60710
60715
|
const k = mmPerPx(ptPerFt);
|
|
@@ -62654,25 +62659,25 @@ var TXN_PREFIX = ".floless-txn-";
|
|
|
62654
62659
|
var txnDir = (projectId, txnId) => (0, import_node_path29.join)(projectDir(projectId), `${TXN_PREFIX}${txnId}`);
|
|
62655
62660
|
var phasePath = (dir, phase) => (0, import_node_path29.join)(dir, `${phase}.json`);
|
|
62656
62661
|
function writePhase2(dir, phase, body) {
|
|
62657
|
-
(0,
|
|
62662
|
+
(0, import_node_fs31.writeFileSync)(phasePath(dir, phase), `${JSON.stringify(body, null, 2)}
|
|
62658
62663
|
`, { flag: "wx" });
|
|
62659
62664
|
}
|
|
62660
62665
|
function readPhase(dir, phase) {
|
|
62661
62666
|
try {
|
|
62662
|
-
return JSON.parse((0,
|
|
62667
|
+
return JSON.parse((0, import_node_fs31.readFileSync)(phasePath(dir, phase), "utf8"));
|
|
62663
62668
|
} catch {
|
|
62664
62669
|
return null;
|
|
62665
62670
|
}
|
|
62666
62671
|
}
|
|
62667
62672
|
function highestPhase(dir) {
|
|
62668
62673
|
let found = null;
|
|
62669
|
-
for (const p of PHASES2) if ((0,
|
|
62674
|
+
for (const p of PHASES2) if ((0, import_node_fs31.existsSync)(phasePath(dir, p))) found = p;
|
|
62670
62675
|
return found;
|
|
62671
62676
|
}
|
|
62672
62677
|
function txnDirs(projectId) {
|
|
62673
62678
|
let entries2;
|
|
62674
62679
|
try {
|
|
62675
|
-
entries2 = (0,
|
|
62680
|
+
entries2 = (0, import_node_fs31.readdirSync)(projectDir(projectId));
|
|
62676
62681
|
} catch {
|
|
62677
62682
|
return [];
|
|
62678
62683
|
}
|
|
@@ -62729,13 +62734,13 @@ function sameActivation(a, b) {
|
|
|
62729
62734
|
}
|
|
62730
62735
|
function supersede(dir) {
|
|
62731
62736
|
try {
|
|
62732
|
-
(0,
|
|
62737
|
+
(0, import_node_fs31.renameSync)(dir, dir.replace(TXN_PREFIX, `.floless-cleanup-${(0, import_node_crypto17.randomUUID)().slice(0, 8)}-`));
|
|
62733
62738
|
} catch {
|
|
62734
62739
|
}
|
|
62735
62740
|
}
|
|
62736
62741
|
function retire(dir) {
|
|
62737
62742
|
try {
|
|
62738
|
-
(0,
|
|
62743
|
+
(0, import_node_fs31.rmSync)(dir, { recursive: true, force: true });
|
|
62739
62744
|
} catch {
|
|
62740
62745
|
}
|
|
62741
62746
|
}
|
|
@@ -62831,7 +62836,7 @@ async function runMigration(opts) {
|
|
|
62831
62836
|
const authorityAppId = contractAuthorityFor(appId);
|
|
62832
62837
|
const txnId = `${Date.now().toString(36)}-${process.pid.toString(36)}-${(0, import_node_crypto17.randomUUID)().slice(0, 8)}`;
|
|
62833
62838
|
const dir = txnDir(projectId, txnId);
|
|
62834
|
-
(0,
|
|
62839
|
+
(0, import_node_fs31.mkdirSync)(dir, { recursive: true });
|
|
62835
62840
|
const begin = {
|
|
62836
62841
|
txnId,
|
|
62837
62842
|
projectId,
|
|
@@ -62876,7 +62881,7 @@ async function runInitialReadToV2(opts) {
|
|
|
62876
62881
|
return withLifecycleLock("project", projectId, () => {
|
|
62877
62882
|
assertNoPendingRecovery(projectId);
|
|
62878
62883
|
const current = readContract(appId, projectId);
|
|
62879
|
-
if (current == null && (0,
|
|
62884
|
+
if (current == null && (0, import_node_fs31.existsSync)(contractPath(appId, projectId))) {
|
|
62880
62885
|
throw new ContractTransactionError("the project contract exists but is unreadable", "contract-corrupt");
|
|
62881
62886
|
}
|
|
62882
62887
|
const currentType = current == null ? null : declaredTypeOf(current);
|
|
@@ -62947,7 +62952,7 @@ ${items.map((item) => ` \u2022 ${item}`).join("\n")}`,
|
|
|
62947
62952
|
assertTypeOwnedByApp(STEEL_V2, { appId, projectId, storeKey, operation: "migrate" });
|
|
62948
62953
|
const txnId = `${Date.now().toString(36)}-${process.pid.toString(36)}-${(0, import_node_crypto17.randomUUID)().slice(0, 8)}`;
|
|
62949
62954
|
const dir = txnDir(projectId, txnId);
|
|
62950
|
-
(0,
|
|
62955
|
+
(0, import_node_fs31.mkdirSync)(dir, { recursive: true });
|
|
62951
62956
|
const begin = {
|
|
62952
62957
|
txnId,
|
|
62953
62958
|
projectId,
|
|
@@ -63011,7 +63016,7 @@ async function runRollbackToV1(opts) {
|
|
|
63011
63016
|
const authorityAppId = contractAuthorityFor(appId);
|
|
63012
63017
|
const txnId = `${Date.now().toString(36)}-${process.pid.toString(36)}-${(0, import_node_crypto17.randomUUID)().slice(0, 8)}-rb`;
|
|
63013
63018
|
const dir = txnDir(projectId, txnId);
|
|
63014
|
-
(0,
|
|
63019
|
+
(0, import_node_fs31.mkdirSync)(dir, { recursive: true });
|
|
63015
63020
|
const begin = {
|
|
63016
63021
|
txnId,
|
|
63017
63022
|
projectId,
|
|
@@ -63048,7 +63053,7 @@ async function runRollbackToV1(opts) {
|
|
|
63048
63053
|
}
|
|
63049
63054
|
function ledgerHead(projectId) {
|
|
63050
63055
|
try {
|
|
63051
|
-
const log2 = JSON.parse((0,
|
|
63056
|
+
const log2 = JSON.parse((0, import_node_fs31.readFileSync)((0, import_node_path29.join)(projectDir(projectId), "versions", "log.json"), "utf8"));
|
|
63052
63057
|
return log2.versions.at(-1)?.n ?? 0;
|
|
63053
63058
|
} catch {
|
|
63054
63059
|
return 0;
|
|
@@ -63161,7 +63166,7 @@ function storeEtag(appId, projectId) {
|
|
|
63161
63166
|
return etagOf(readContract(appId, projectId));
|
|
63162
63167
|
}
|
|
63163
63168
|
function storedContractBytesExist(appId, projectId) {
|
|
63164
|
-
return (0,
|
|
63169
|
+
return (0, import_node_fs32.existsSync)(contractPath(appId, projectId));
|
|
63165
63170
|
}
|
|
63166
63171
|
var PreconditionFailedError = class extends Error {
|
|
63167
63172
|
code = "precondition-failed";
|
|
@@ -63293,7 +63298,7 @@ function acceptSteelForRoute(doc, ctx, from, reads) {
|
|
|
63293
63298
|
}
|
|
63294
63299
|
|
|
63295
63300
|
// knowledge-routes.ts
|
|
63296
|
-
var
|
|
63301
|
+
var import_node_fs34 = require("node:fs");
|
|
63297
63302
|
|
|
63298
63303
|
// sse.ts
|
|
63299
63304
|
var clients = /* @__PURE__ */ new Set();
|
|
@@ -63331,7 +63336,7 @@ function clientCount() {
|
|
|
63331
63336
|
|
|
63332
63337
|
// knowledge-store.ts
|
|
63333
63338
|
var import_node_crypto18 = require("node:crypto");
|
|
63334
|
-
var
|
|
63339
|
+
var import_node_fs33 = require("node:fs");
|
|
63335
63340
|
var import_node_path30 = require("node:path");
|
|
63336
63341
|
var import_yaml6 = __toESM(require_dist6(), 1);
|
|
63337
63342
|
var KnowledgeError = class extends Error {
|
|
@@ -63352,9 +63357,9 @@ function isSourceRow(row) {
|
|
|
63352
63357
|
}
|
|
63353
63358
|
function readManifest(id) {
|
|
63354
63359
|
const p = manifestPath(id);
|
|
63355
|
-
if (!(0,
|
|
63360
|
+
if (!(0, import_node_fs33.existsSync)(p)) return { ...EMPTY_MANIFEST, sources: [] };
|
|
63356
63361
|
try {
|
|
63357
|
-
const parsed = JSON.parse((0,
|
|
63362
|
+
const parsed = JSON.parse((0, import_node_fs33.readFileSync)(p, "utf8"));
|
|
63358
63363
|
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.sources)) {
|
|
63359
63364
|
console.warn(`knowledge-store: ignoring schema-invalid manifest.json at ${p} (missing/invalid sources array)`);
|
|
63360
63365
|
return { ...EMPTY_MANIFEST, sources: [] };
|
|
@@ -63378,11 +63383,11 @@ function readManifest(id) {
|
|
|
63378
63383
|
}
|
|
63379
63384
|
function writeManifest(id, manifest) {
|
|
63380
63385
|
const dir = projectKnowledgeDir(id);
|
|
63381
|
-
(0,
|
|
63386
|
+
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
63382
63387
|
const dest = manifestPath(id);
|
|
63383
63388
|
const tmp = (0, import_node_path30.join)(dir, `.manifest.json.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`);
|
|
63384
|
-
(0,
|
|
63385
|
-
(0,
|
|
63389
|
+
(0, import_node_fs33.writeFileSync)(tmp, JSON.stringify(manifest, null, 2));
|
|
63390
|
+
(0, import_node_fs33.renameSync)(tmp, dest);
|
|
63386
63391
|
}
|
|
63387
63392
|
var MAX_FILES = 50;
|
|
63388
63393
|
var MAX_FILE_BYTES = 100 * 1024 * 1024;
|
|
@@ -63459,12 +63464,12 @@ function addSource(id, input) {
|
|
|
63459
63464
|
const { buf, mime, filename } = input;
|
|
63460
63465
|
const sha2563 = (0, import_node_crypto18.createHash)("sha256").update(buf).digest("hex");
|
|
63461
63466
|
const dir = blobsDir(id);
|
|
63462
|
-
(0,
|
|
63467
|
+
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
63463
63468
|
const blobPath = blobPathFor(id, sha2563);
|
|
63464
|
-
if (!(0,
|
|
63469
|
+
if (!(0, import_node_fs33.existsSync)(blobPath)) {
|
|
63465
63470
|
const tmp = `${blobPath}.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`;
|
|
63466
|
-
(0,
|
|
63467
|
-
(0,
|
|
63471
|
+
(0, import_node_fs33.writeFileSync)(tmp, buf);
|
|
63472
|
+
(0, import_node_fs33.renameSync)(tmp, blobPath);
|
|
63468
63473
|
}
|
|
63469
63474
|
const manifest = readManifest(id);
|
|
63470
63475
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -63507,7 +63512,7 @@ function removeSource(id, sourceId) {
|
|
|
63507
63512
|
if (!stillReferenced) {
|
|
63508
63513
|
const blobPath = blobPathFor(id, removed.blobSha256);
|
|
63509
63514
|
try {
|
|
63510
|
-
if ((0,
|
|
63515
|
+
if ((0, import_node_fs33.existsSync)(blobPath)) (0, import_node_fs33.unlinkSync)(blobPath);
|
|
63511
63516
|
} catch (e) {
|
|
63512
63517
|
console.warn(`knowledge-store: could not GC blob ${removed.blobSha256} for ${id}: ${e instanceof Error ? e.message : e}`);
|
|
63513
63518
|
}
|
|
@@ -63517,17 +63522,17 @@ var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
|
63517
63522
|
var lockPath = (id) => (0, import_node_path30.join)(projectKnowledgeDir(id), "lock.json");
|
|
63518
63523
|
function writeLockFile(id, lock) {
|
|
63519
63524
|
const dir = projectKnowledgeDir(id);
|
|
63520
|
-
(0,
|
|
63525
|
+
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
63521
63526
|
const dest = lockPath(id);
|
|
63522
63527
|
const tmp = (0, import_node_path30.join)(dir, `.lock.json.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`);
|
|
63523
|
-
(0,
|
|
63524
|
-
(0,
|
|
63528
|
+
(0, import_node_fs33.writeFileSync)(tmp, JSON.stringify(lock, null, 2));
|
|
63529
|
+
(0, import_node_fs33.renameSync)(tmp, dest);
|
|
63525
63530
|
}
|
|
63526
63531
|
function readLock(id) {
|
|
63527
63532
|
const p = lockPath(id);
|
|
63528
|
-
if (!(0,
|
|
63533
|
+
if (!(0, import_node_fs33.existsSync)(p)) return null;
|
|
63529
63534
|
try {
|
|
63530
|
-
const parsed = JSON.parse((0,
|
|
63535
|
+
const parsed = JSON.parse((0, import_node_fs33.readFileSync)(p, "utf8"));
|
|
63531
63536
|
if (!parsed || typeof parsed !== "object" || typeof parsed.requestId !== "string" || typeof parsed.createdAt !== "number" || !Number.isFinite(parsed.createdAt)) {
|
|
63532
63537
|
console.warn(`knowledge-store: ignoring schema-invalid lock.json at ${p}`);
|
|
63533
63538
|
return null;
|
|
@@ -63563,7 +63568,7 @@ function releaseLock(id, requestId) {
|
|
|
63563
63568
|
if (existing.requestId !== requestId) return false;
|
|
63564
63569
|
const p = lockPath(id);
|
|
63565
63570
|
try {
|
|
63566
|
-
if ((0,
|
|
63571
|
+
if ((0, import_node_fs33.existsSync)(p)) (0, import_node_fs33.unlinkSync)(p);
|
|
63567
63572
|
} catch (e) {
|
|
63568
63573
|
console.warn(`knowledge-store: could not release lock.json at ${p}: ${e instanceof Error ? e.message : e}`);
|
|
63569
63574
|
}
|
|
@@ -63588,14 +63593,14 @@ function generationWikiDir(id, generationId) {
|
|
|
63588
63593
|
}
|
|
63589
63594
|
function publishGeneration(id, generationId) {
|
|
63590
63595
|
assertGenerationId(generationId);
|
|
63591
|
-
if (!(0,
|
|
63596
|
+
if (!(0, import_node_fs33.existsSync)(generationWikiDir(id, generationId))) throw new KnowledgeError("generation not found");
|
|
63592
63597
|
const pointer = { generationId, publishedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
63593
63598
|
const dir = vaultDir(id);
|
|
63594
|
-
(0,
|
|
63599
|
+
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
63595
63600
|
const dest = currentGenerationPath(id);
|
|
63596
63601
|
const tmp = (0, import_node_path30.join)(dir, `.current-generation.json.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`);
|
|
63597
|
-
(0,
|
|
63598
|
-
(0,
|
|
63602
|
+
(0, import_node_fs33.writeFileSync)(tmp, JSON.stringify(pointer, null, 2));
|
|
63603
|
+
(0, import_node_fs33.renameSync)(tmp, dest);
|
|
63599
63604
|
const manifest = readManifest(id);
|
|
63600
63605
|
manifest.currentGeneration = generationId;
|
|
63601
63606
|
writeManifest(id, manifest);
|
|
@@ -63604,9 +63609,9 @@ function publishGeneration(id, generationId) {
|
|
|
63604
63609
|
}
|
|
63605
63610
|
function readCurrentGeneration(id) {
|
|
63606
63611
|
const p = currentGenerationPath(id);
|
|
63607
|
-
if (!(0,
|
|
63612
|
+
if (!(0, import_node_fs33.existsSync)(p)) return null;
|
|
63608
63613
|
try {
|
|
63609
|
-
const parsed = JSON.parse((0,
|
|
63614
|
+
const parsed = JSON.parse((0, import_node_fs33.readFileSync)(p, "utf8"));
|
|
63610
63615
|
if (typeof parsed?.generationId !== "string" || !GENERATION_ID_RE.test(parsed.generationId) || typeof parsed.publishedAt !== "string") {
|
|
63611
63616
|
console.warn(`knowledge-store: ignoring schema-invalid current-generation.json at ${p}`);
|
|
63612
63617
|
return null;
|
|
@@ -63621,7 +63626,7 @@ function currentGenerationWikiDir(id) {
|
|
|
63621
63626
|
const current = readCurrentGeneration(id);
|
|
63622
63627
|
if (!current) return null;
|
|
63623
63628
|
const dir = generationWikiDir(id, current.generationId);
|
|
63624
|
-
return (0,
|
|
63629
|
+
return (0, import_node_fs33.existsSync)(dir) ? dir : null;
|
|
63625
63630
|
}
|
|
63626
63631
|
var WIKI_SLUG_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
63627
63632
|
var KB_MAX_NODES = 300;
|
|
@@ -63629,9 +63634,9 @@ var KB_MAX_TOTAL_BYTES = 8 * 1024 * 1024;
|
|
|
63629
63634
|
var KB_MAX_VISITS = 5e3;
|
|
63630
63635
|
var KB_MAX_PAGE_BYTES = 512 * 1024;
|
|
63631
63636
|
var REAL_IO = {
|
|
63632
|
-
readdir: (dir) => (0,
|
|
63633
|
-
readFile: (path) => (0,
|
|
63634
|
-
statSize: (path) => (0,
|
|
63637
|
+
readdir: (dir) => (0, import_node_fs33.readdirSync)(dir, { withFileTypes: true }),
|
|
63638
|
+
readFile: (path) => (0, import_node_fs33.readFileSync)(path, "utf8"),
|
|
63639
|
+
statSize: (path) => (0, import_node_fs33.statSync)(path).size
|
|
63635
63640
|
};
|
|
63636
63641
|
var VAULT_START = "<!-- vault:generated:start -->";
|
|
63637
63642
|
var VAULT_END = "<!-- vault:generated:end -->";
|
|
@@ -63931,17 +63936,17 @@ function readKnowledgeSummaries(wikiDir, opts = {}, io = REAL_IO) {
|
|
|
63931
63936
|
var organizePath = (id) => (0, import_node_path30.join)(projectKnowledgeDir(id), "organize.json");
|
|
63932
63937
|
function writeOrganizeFile(id, org) {
|
|
63933
63938
|
const dir = projectKnowledgeDir(id);
|
|
63934
|
-
(0,
|
|
63939
|
+
(0, import_node_fs33.mkdirSync)(dir, { recursive: true });
|
|
63935
63940
|
const dest = organizePath(id);
|
|
63936
63941
|
const tmp = (0, import_node_path30.join)(dir, `.organize.json.${process.pid}.${(0, import_node_crypto18.randomUUID)()}.tmp`);
|
|
63937
|
-
(0,
|
|
63938
|
-
(0,
|
|
63942
|
+
(0, import_node_fs33.writeFileSync)(tmp, JSON.stringify(org, null, 2));
|
|
63943
|
+
(0, import_node_fs33.renameSync)(tmp, dest);
|
|
63939
63944
|
}
|
|
63940
63945
|
function readOrganize(id) {
|
|
63941
63946
|
const p = organizePath(id);
|
|
63942
|
-
if (!(0,
|
|
63947
|
+
if (!(0, import_node_fs33.existsSync)(p)) return null;
|
|
63943
63948
|
try {
|
|
63944
|
-
const parsed = JSON.parse((0,
|
|
63949
|
+
const parsed = JSON.parse((0, import_node_fs33.readFileSync)(p, "utf8"));
|
|
63945
63950
|
if (!parsed || typeof parsed !== "object" || typeof parsed.requestId !== "string" || typeof parsed.generationId !== "string" || !GENERATION_ID_RE.test(parsed.generationId) || typeof parsed.baseRevision !== "number" || !Number.isFinite(parsed.baseRevision)) {
|
|
63946
63951
|
console.warn(`knowledge-store: ignoring schema-invalid organize.json at ${p}`);
|
|
63947
63952
|
return null;
|
|
@@ -63960,7 +63965,7 @@ function readOrganize(id) {
|
|
|
63960
63965
|
function deleteOrganizeFile(id) {
|
|
63961
63966
|
const p = organizePath(id);
|
|
63962
63967
|
try {
|
|
63963
|
-
if ((0,
|
|
63968
|
+
if ((0, import_node_fs33.existsSync)(p)) (0, import_node_fs33.unlinkSync)(p);
|
|
63964
63969
|
} catch (e) {
|
|
63965
63970
|
console.warn(`knowledge-store: could not delete organize.json at ${p}: ${e instanceof Error ? e.message : e}`);
|
|
63966
63971
|
}
|
|
@@ -63978,7 +63983,7 @@ function startOrganize(id, requestId) {
|
|
|
63978
63983
|
const generationId = mintGenerationId();
|
|
63979
63984
|
const manifest = readManifest(id);
|
|
63980
63985
|
const baseRevision = manifest.revision;
|
|
63981
|
-
(0,
|
|
63986
|
+
(0, import_node_fs33.mkdirSync)(generationWikiDir(id, generationId), { recursive: true });
|
|
63982
63987
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
63983
63988
|
for (const row of manifest.sources) {
|
|
63984
63989
|
if (row.useAsKb) {
|
|
@@ -63999,8 +64004,8 @@ function finishOrganize(id, requestId, opts) {
|
|
|
63999
64004
|
throw new KnowledgeError("generation id mismatch");
|
|
64000
64005
|
}
|
|
64001
64006
|
const wikiDir = generationWikiDir(id, org.generationId);
|
|
64002
|
-
if (!(0,
|
|
64003
|
-
if ((0,
|
|
64007
|
+
if (!(0, import_node_fs33.existsSync)(wikiDir)) throw new KnowledgeError("generation not found");
|
|
64008
|
+
if ((0, import_node_fs33.readdirSync)(wikiDir).length === 0) {
|
|
64004
64009
|
throw new KnowledgeError("nothing to publish \u2014 generation is empty");
|
|
64005
64010
|
}
|
|
64006
64011
|
publishGeneration(id, org.generationId);
|
|
@@ -64041,14 +64046,14 @@ function failOrganize(id, requestId, opts) {
|
|
|
64041
64046
|
}
|
|
64042
64047
|
function gcOldGenerations(id, currentGenerationId) {
|
|
64043
64048
|
const dir = generationsDir(id);
|
|
64044
|
-
if (!(0,
|
|
64045
|
-
const entries2 = (0,
|
|
64049
|
+
if (!(0, import_node_fs33.existsSync)(dir)) return;
|
|
64050
|
+
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_path30.join)(dir, e.name)).mtimeMs })).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
64046
64051
|
const keep = new Set(entries2.slice(0, GEN_KEEP).map((e) => e.name));
|
|
64047
64052
|
keep.add(currentGenerationId);
|
|
64048
64053
|
for (const e of entries2) {
|
|
64049
64054
|
if (keep.has(e.name)) continue;
|
|
64050
64055
|
try {
|
|
64051
|
-
(0,
|
|
64056
|
+
(0, import_node_fs33.rmSync)((0, import_node_path30.join)(dir, e.name), { recursive: true, force: true });
|
|
64052
64057
|
} catch (err2) {
|
|
64053
64058
|
console.warn(`knowledge-store: could not GC stale generation dir ${e.name}: ${err2 instanceof Error ? err2.message : err2}`);
|
|
64054
64059
|
}
|
|
@@ -64164,7 +64169,7 @@ function registerKnowledgeRoutes(app) {
|
|
|
64164
64169
|
const blobPath = blobPathFor(project.id, row.blobSha256);
|
|
64165
64170
|
let fd2;
|
|
64166
64171
|
try {
|
|
64167
|
-
fd2 = (0,
|
|
64172
|
+
fd2 = (0, import_node_fs34.openSync)(blobPath, "r");
|
|
64168
64173
|
} catch (e) {
|
|
64169
64174
|
const code = e.code;
|
|
64170
64175
|
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
@@ -64174,17 +64179,17 @@ function registerKnowledgeRoutes(app) {
|
|
|
64174
64179
|
}
|
|
64175
64180
|
let streamOwnsFd = false;
|
|
64176
64181
|
try {
|
|
64177
|
-
const st = (0,
|
|
64182
|
+
const st = (0, import_node_fs34.fstatSync)(fd2);
|
|
64178
64183
|
if (!st.isFile()) {
|
|
64179
64184
|
return reply.status(404).send({ ok: false, error: "source bytes are missing" });
|
|
64180
64185
|
}
|
|
64181
64186
|
reply.header("Content-Type", row.mime).header("Content-Length", String(st.size)).header("X-Content-Type-Options", "nosniff").header("Content-Disposition", "inline").header("Cache-Control", "private, no-store").header("Content-Security-Policy", "default-src 'none'; sandbox; frame-ancestors 'self'").header("Cross-Origin-Resource-Policy", "same-origin");
|
|
64182
64187
|
if (req.method === "HEAD") return reply.send();
|
|
64183
|
-
const stream = (0,
|
|
64188
|
+
const stream = (0, import_node_fs34.createReadStream)(blobPath, { fd: fd2, autoClose: true });
|
|
64184
64189
|
streamOwnsFd = true;
|
|
64185
64190
|
return reply.send(stream);
|
|
64186
64191
|
} finally {
|
|
64187
|
-
if (!streamOwnsFd) (0,
|
|
64192
|
+
if (!streamOwnsFd) (0, import_node_fs34.closeSync)(fd2);
|
|
64188
64193
|
}
|
|
64189
64194
|
} catch (e) {
|
|
64190
64195
|
if (e instanceof ProjectError) return reply.status(400).send({ ok: false, error: e.message });
|
|
@@ -65151,21 +65156,21 @@ function viewOf(p, facts) {
|
|
|
65151
65156
|
|
|
65152
65157
|
// project-sources-store.ts
|
|
65153
65158
|
var import_node_crypto19 = require("node:crypto");
|
|
65154
|
-
var
|
|
65159
|
+
var import_node_fs35 = require("node:fs");
|
|
65155
65160
|
var import_node_path31 = require("node:path");
|
|
65156
65161
|
var sourcesDir = (id) => (0, import_node_path31.join)(projectDir(id), "sources");
|
|
65157
65162
|
var safeExt = (ext) => typeof ext === "string" && /^[a-z0-9]{1,8}$/i.test(ext) ? ext.toLowerCase() : "bin";
|
|
65158
65163
|
function writeAtomic2(path, buf) {
|
|
65159
65164
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
65160
|
-
(0,
|
|
65161
|
-
(0,
|
|
65165
|
+
(0, import_node_fs35.writeFileSync)(tmp, buf);
|
|
65166
|
+
(0, import_node_fs35.renameSync)(tmp, path);
|
|
65162
65167
|
}
|
|
65163
65168
|
function saveSource(id, file) {
|
|
65164
|
-
(0,
|
|
65169
|
+
(0, import_node_fs35.mkdirSync)(sourcesDir(id), { recursive: true });
|
|
65165
65170
|
const sha2563 = (0, import_node_crypto19.createHash)("sha256").update(file.buf).digest("hex");
|
|
65166
65171
|
const ext = safeExt(file.ext);
|
|
65167
65172
|
const p = (0, import_node_path31.join)(sourcesDir(id), `${sha2563}.${ext}`);
|
|
65168
|
-
if (!(0,
|
|
65173
|
+
if (!(0, import_node_fs35.existsSync)(p)) writeAtomic2(p, file.buf);
|
|
65169
65174
|
return { name: String(file.name), sha256: sha2563, ext, bytes: file.buf.length };
|
|
65170
65175
|
}
|
|
65171
65176
|
|
|
@@ -65291,14 +65296,7 @@ function spread(n, half) {
|
|
|
65291
65296
|
if (n <= 1) return [0];
|
|
65292
65297
|
return Array.from({ length: n }, (_, i) => -half + 2 * half * i / (n - 1));
|
|
65293
65298
|
}
|
|
65294
|
-
|
|
65295
|
-
const p = (profile || "").toUpperCase().trim();
|
|
65296
|
-
if (/^(W|M|S|HP|UC|UB|UKC|UKB|IPE|HE)/.test(p)) return "I";
|
|
65297
|
-
if (/^(C|MC|PFC)/.test(p)) return "C";
|
|
65298
|
-
if (/^L/.test(p)) return "L";
|
|
65299
|
-
if (/^(HSS|PIPE|TS|SHS|RHS|CHS|TUBE|HSQ)/.test(p)) return "TUBE";
|
|
65300
|
-
return "BOX";
|
|
65301
|
-
}
|
|
65299
|
+
var profileKind = (profile) => sectionKindOf(profile);
|
|
65302
65300
|
function profileOutline(profile, w, d) {
|
|
65303
65301
|
const hw = w / 2, hd = d / 2;
|
|
65304
65302
|
switch (profileKind(profile)) {
|
|
@@ -65448,6 +65446,10 @@ function expandBasePlate(joint, col) {
|
|
|
65448
65446
|
function webHalfThk(profile, w) {
|
|
65449
65447
|
return profileKind(profile) === "I" ? Math.min(w * 0.5, Math.max(w * 0.1, 5)) / 2 : 0;
|
|
65450
65448
|
}
|
|
65449
|
+
function supportsEstimatedIWeb(profile) {
|
|
65450
|
+
const p = String(profile ?? "").trim().toUpperCase().replace(/[×✕✖]/g, "X");
|
|
65451
|
+
return /^(W|S|HP|M(?!C))/.test(p);
|
|
65452
|
+
}
|
|
65451
65453
|
function sectionAxesOnNormal(rot, atEnd1) {
|
|
65452
65454
|
const th = (rot ?? 0) * Math.PI / 180;
|
|
65453
65455
|
const round = (n) => Math.abs(n) < 1e-9 ? 0 : Math.abs(Math.abs(n) - 1) < 1e-9 ? Math.sign(n) : n;
|
|
@@ -65466,14 +65468,14 @@ function realWebThk(profile, w) {
|
|
|
65466
65468
|
case "chs":
|
|
65467
65469
|
return x.t;
|
|
65468
65470
|
case "rect":
|
|
65469
|
-
return webHalfThk(profile, w) * 2;
|
|
65471
|
+
return supportsEstimatedIWeb(profile) ? webHalfThk(profile, w) * 2 : null;
|
|
65470
65472
|
}
|
|
65471
65473
|
}
|
|
65472
65474
|
function lapFaces(member, requestedSide, atEnd1) {
|
|
65473
65475
|
const { uOnN, vOnN } = sectionAxesOnNormal(member.rot, atEnd1);
|
|
65474
65476
|
const faces = bearingFaces(xsectionFor(member.profile, member.dims), uOnN, vOnN, requestedSide);
|
|
65475
65477
|
if (faces) return faces;
|
|
65476
|
-
if (profileKind(member.profile) === "I" && Math.abs(Math.abs(uOnN) - 1) < 1e-9) {
|
|
65478
|
+
if (profileKind(member.profile) === "I" && supportsEstimatedIWeb(member.profile) && Math.abs(Math.abs(uOnN) - 1) < 1e-9) {
|
|
65477
65479
|
const h = webHalfThk(member.profile, member.dims.w);
|
|
65478
65480
|
return { lapN: requestedSide * h, sideDir: requestedSide, plyFarN: -requestedSide * h, ply: 2 * h, derived: false };
|
|
65479
65481
|
}
|
|
@@ -65533,7 +65535,7 @@ function supportWorkZAt(support, pt) {
|
|
|
65533
65535
|
function beamCopes(beam, support, at, params) {
|
|
65534
65536
|
if (!support || !finite3(support.from) || !finite3(support.to) || !support.dims || !(support.dims.d > 0) || !(support.dims.w > 0)) return {};
|
|
65535
65537
|
if (!finite3(beam.from) || !finite3(beam.to) || !beam.dims || !(beam.dims.d > 0) || !(beam.dims.w > 0)) return {};
|
|
65536
|
-
if (profileKind(support.profile) !== "I") return {};
|
|
65538
|
+
if (profileKind(support.profile) !== "I") return { reason: "support-section-unsupported" };
|
|
65537
65539
|
const endPt = at === "end1" ? beam.to : beam.from;
|
|
65538
65540
|
const gap = Math.max(0, num2(params, "clearance", 12.7));
|
|
65539
65541
|
const beamMidZ = endPt[2] + (typeof beam.posOffset === "number" && isFinite(beam.posOffset) ? beam.posOffset : 0);
|
|
@@ -65607,7 +65609,11 @@ function expandShearPlate(joint, beam, support, nativeSupport) {
|
|
|
65607
65609
|
);
|
|
65608
65610
|
}
|
|
65609
65611
|
const pOff = lap.lapN + lap.sideDir * (thickness / 2);
|
|
65610
|
-
const
|
|
65612
|
+
const supportWeb = support && profileKind(support.profile) === "I" ? realWebThk(support.profile, support.dims.w) : null;
|
|
65613
|
+
if (support && profileKind(support.profile) === "I" && supportWeb == null) {
|
|
65614
|
+
return refusal("bearing-face-unresolved", { supportId: support.id });
|
|
65615
|
+
}
|
|
65616
|
+
const u0 = supportWeb == null ? 0 : supportWeb / 2;
|
|
65611
65617
|
const edgeV = Math.min(edge, height * 0.4);
|
|
65612
65618
|
const pV = rows2 > 1 ? Math.min(pitch, Math.max(0, height - 2 * edgeV) / (rows2 - 1)) : 0;
|
|
65613
65619
|
const vOffs = Array.from({ length: rows2 }, (_, i) => (i - (rows2 - 1) / 2) * pV);
|
|
@@ -65618,6 +65624,16 @@ function expandShearPlate(joint, beam, support, nativeSupport) {
|
|
|
65618
65624
|
const pU = cols > 1 ? Math.min(colPitch, (regHi - regLo) / (cols - 1)) : 0;
|
|
65619
65625
|
const uOffs = Array.from({ length: cols }, (_, j) => cU + (j - (cols - 1) / 2) * pU);
|
|
65620
65626
|
const diagnostics = [];
|
|
65627
|
+
if (support && profileKind(support.profile) !== "I") {
|
|
65628
|
+
diagnostics.push({
|
|
65629
|
+
jointId: joint.id,
|
|
65630
|
+
kind: joint.kind,
|
|
65631
|
+
severity: "warning",
|
|
65632
|
+
code: "support-section-unsupported",
|
|
65633
|
+
supportId: support.id,
|
|
65634
|
+
profile: support.profile
|
|
65635
|
+
});
|
|
65636
|
+
}
|
|
65621
65637
|
if (cols > 1 && pU < colPitch - 1e-6) {
|
|
65622
65638
|
diagnostics.push({
|
|
65623
65639
|
jointId: joint.id,
|
|
@@ -65713,6 +65729,7 @@ function expandShearPlate(joint, beam, support, nativeSupport) {
|
|
|
65713
65729
|
if (support && support.role === "beam" && !support.isBrace && finite3(support.from) && finite3(support.to) && support.dims && support.dims.d > 0 && support.dims.w > 0) {
|
|
65714
65730
|
const supPosOff = typeof support.posOffset === "number" && isFinite(support.posOffset) ? support.posOffset : 0;
|
|
65715
65731
|
const twGirder = realWebThk(support.profile, support.dims.w);
|
|
65732
|
+
if (twGirder == null) return refusal("bearing-face-unresolved", { supportId: support.id });
|
|
65716
65733
|
const stiffH = support.dims.d * 0.9;
|
|
65717
65734
|
const stiffW = Math.max(support.dims.w / 2 - twGirder / 2, thickness * 2);
|
|
65718
65735
|
const girderCentZ = endPt[2] + supPosOff;
|
|
@@ -69408,7 +69425,7 @@ function registerSteelPrepassRoute(app, deps) {
|
|
|
69408
69425
|
var import_node_crypto22 = require("node:crypto");
|
|
69409
69426
|
|
|
69410
69427
|
// reference-import.ts
|
|
69411
|
-
var
|
|
69428
|
+
var import_node_fs36 = require("node:fs");
|
|
69412
69429
|
var import_node_path32 = require("node:path");
|
|
69413
69430
|
var AGENT2 = "ifc-reference-reader";
|
|
69414
69431
|
var WARN_BYTES = 50 * 1024 * 1024;
|
|
@@ -69675,7 +69692,7 @@ function projectRelativeReferencePath(fileName, taken = /* @__PURE__ */ new Set(
|
|
|
69675
69692
|
var readerChain2 = Promise.resolve();
|
|
69676
69693
|
function writeReaderApp2(companionId, command, ifcPath, filter) {
|
|
69677
69694
|
const dir = appPath(companionId);
|
|
69678
|
-
(0,
|
|
69695
|
+
(0, import_node_fs36.mkdirSync)(dir, { recursive: true });
|
|
69679
69696
|
const flo = (0, import_node_path32.join)(dir, `${companionId}.flo`);
|
|
69680
69697
|
const lines = [
|
|
69681
69698
|
`app: ${companionId}`,
|
|
@@ -69716,15 +69733,9 @@ function writeReaderApp2(companionId, command, ifcPath, filter) {
|
|
|
69716
69733
|
if (emit?.ifcTypes) lines.push(` ifc-types: ${JSON.stringify(emit.ifcTypes)}`);
|
|
69717
69734
|
}
|
|
69718
69735
|
lines.push("");
|
|
69719
|
-
(0,
|
|
69736
|
+
(0, import_node_fs36.writeFileSync)(flo, lines.join("\n"));
|
|
69720
69737
|
return flo;
|
|
69721
69738
|
}
|
|
69722
|
-
function nodeOutput2(traceText, node) {
|
|
69723
|
-
const events = traceText ? parseTrace(traceText) : [];
|
|
69724
|
-
const ev = [...events].reverse().find((e) => e.kind === "node-output" && e.node === node);
|
|
69725
|
-
const data = ev ? ev.data : null;
|
|
69726
|
-
return data && typeof data === "object" ? data : null;
|
|
69727
|
-
}
|
|
69728
69739
|
async function ensureReferenceReader() {
|
|
69729
69740
|
try {
|
|
69730
69741
|
await aware.ensureAgentInstalled(AGENT2);
|
|
@@ -69755,7 +69766,7 @@ async function runReader2(companionId, command, ifcPath, opts = {}) {
|
|
|
69755
69766
|
const reason = e instanceof AwareError ? String(e.detail?.stderr ?? "").trim() : "";
|
|
69756
69767
|
throw new ReferenceImportError(reason || (e instanceof Error ? e.message : "the reference reader failed"));
|
|
69757
69768
|
}
|
|
69758
|
-
const out =
|
|
69769
|
+
const out = nodeOutput(traceText, command);
|
|
69759
69770
|
if (!out) throw new ReferenceImportError("the reference reader returned no result");
|
|
69760
69771
|
return out;
|
|
69761
69772
|
} finally {
|
|
@@ -69790,7 +69801,7 @@ async function readReferenceModel(companionId, ifcPath, opts = {}) {
|
|
|
69790
69801
|
|
|
69791
69802
|
// reference-store.ts
|
|
69792
69803
|
var import_node_crypto21 = require("node:crypto");
|
|
69793
|
-
var
|
|
69804
|
+
var import_node_fs37 = require("node:fs");
|
|
69794
69805
|
var import_promises4 = require("node:stream/promises");
|
|
69795
69806
|
var import_node_path33 = require("node:path");
|
|
69796
69807
|
function insideProject(projectId, relPath) {
|
|
@@ -69812,7 +69823,7 @@ function insideProject(projectId, relPath) {
|
|
|
69812
69823
|
}
|
|
69813
69824
|
function realish(p) {
|
|
69814
69825
|
try {
|
|
69815
|
-
return
|
|
69826
|
+
return import_node_fs37.realpathSync.native((0, import_node_path33.resolve)(p));
|
|
69816
69827
|
} catch {
|
|
69817
69828
|
return (0, import_node_path33.resolve)(p);
|
|
69818
69829
|
}
|
|
@@ -69826,20 +69837,20 @@ function safeId2(refId2) {
|
|
|
69826
69837
|
}
|
|
69827
69838
|
async function hashFile(path) {
|
|
69828
69839
|
const h = (0, import_node_crypto21.createHash)("sha256");
|
|
69829
|
-
await (0, import_promises4.pipeline)((0,
|
|
69840
|
+
await (0, import_promises4.pipeline)((0, import_node_fs37.createReadStream)(path), h);
|
|
69830
69841
|
return h.digest("hex");
|
|
69831
69842
|
}
|
|
69832
69843
|
function copyOriginal(projectId, relPath, sourceAbs, tag) {
|
|
69833
69844
|
const abs = insideProject(projectId, relPath);
|
|
69834
|
-
(0,
|
|
69845
|
+
(0, import_node_fs37.mkdirSync)((0, import_node_path33.dirname)(abs), { recursive: true });
|
|
69835
69846
|
const tmp = `${abs}.${safeId2(tag)}.part`;
|
|
69836
|
-
(0,
|
|
69837
|
-
(0,
|
|
69847
|
+
(0, import_node_fs37.copyFileSync)(sourceAbs, tmp);
|
|
69848
|
+
(0, import_node_fs37.renameSync)(tmp, abs);
|
|
69838
69849
|
return abs;
|
|
69839
69850
|
}
|
|
69840
69851
|
function referenceFilesOnDisk(projectId) {
|
|
69841
69852
|
try {
|
|
69842
|
-
return (0,
|
|
69853
|
+
return (0, import_node_fs37.readdirSync)((0, import_node_path33.join)(projectDir(projectId), REFERENCE_DIR)).map((f) => `${REFERENCE_DIR}/${f}`);
|
|
69843
69854
|
} catch (e) {
|
|
69844
69855
|
if (e.code === "ENOENT") return [];
|
|
69845
69856
|
throw new ReferenceImportError(
|
|
@@ -69849,13 +69860,13 @@ function referenceFilesOnDisk(projectId) {
|
|
|
69849
69860
|
}
|
|
69850
69861
|
function originalPath(projectId, relPath) {
|
|
69851
69862
|
const abs = insideProject(projectId, relPath);
|
|
69852
|
-
return (0,
|
|
69863
|
+
return (0, import_node_fs37.existsSync)(abs) ? abs : null;
|
|
69853
69864
|
}
|
|
69854
69865
|
function writeCache2(projectId, refId2, cache2) {
|
|
69855
69866
|
const p = cachePath2(projectId, refId2);
|
|
69856
69867
|
const tmp = `${p}.part`;
|
|
69857
|
-
(0,
|
|
69858
|
-
(0,
|
|
69868
|
+
(0, import_node_fs37.writeFileSync)(tmp, JSON.stringify(cache2));
|
|
69869
|
+
(0, import_node_fs37.renameSync)(tmp, p);
|
|
69859
69870
|
}
|
|
69860
69871
|
function filterKey(filter) {
|
|
69861
69872
|
const part = (v) => v?.length ? [...v].sort() : [];
|
|
@@ -69865,9 +69876,9 @@ function filterKey(filter) {
|
|
|
69865
69876
|
}
|
|
69866
69877
|
function cachedGeometry(projectId, refId2, expectHash, expectFilter) {
|
|
69867
69878
|
const p = cachePath2(projectId, refId2);
|
|
69868
|
-
if (!(0,
|
|
69879
|
+
if (!(0, import_node_fs37.existsSync)(p)) return null;
|
|
69869
69880
|
try {
|
|
69870
|
-
const parsed = JSON.parse((0,
|
|
69881
|
+
const parsed = JSON.parse((0, import_node_fs37.readFileSync)(p, "utf8"));
|
|
69871
69882
|
if (!parsed || parsed.v !== REFERENCE_CACHE_VERSION || !Array.isArray(parsed.objects)) return null;
|
|
69872
69883
|
if (parsed.sourceHash !== expectHash) return null;
|
|
69873
69884
|
if (filterKey(parsed.filter) !== filterKey(expectFilter)) return null;
|
|
@@ -69877,11 +69888,11 @@ function cachedGeometry(projectId, refId2, expectHash, expectFilter) {
|
|
|
69877
69888
|
}
|
|
69878
69889
|
}
|
|
69879
69890
|
function dropCache(projectId, refId2) {
|
|
69880
|
-
(0,
|
|
69891
|
+
(0, import_node_fs37.rmSync)(cachePath2(projectId, refId2), { force: true });
|
|
69881
69892
|
}
|
|
69882
69893
|
function removeReference(projectId, refId2, relPath) {
|
|
69883
69894
|
dropCache(projectId, refId2);
|
|
69884
|
-
if (relPath) (0,
|
|
69895
|
+
if (relPath) (0, import_node_fs37.rmSync)(insideProject(projectId, relPath), { force: true });
|
|
69885
69896
|
}
|
|
69886
69897
|
function takenReferencePaths(refs) {
|
|
69887
69898
|
return new Set((refs ?? []).map((r) => r.file).filter((f) => typeof f === "string"));
|
|
@@ -70322,7 +70333,7 @@ var import_node_os18 = require("node:os");
|
|
|
70322
70333
|
var import_node_path34 = require("node:path");
|
|
70323
70334
|
|
|
70324
70335
|
// node_modules/write-excel-file/modules/export/writeXlsxFileNode.js
|
|
70325
|
-
var
|
|
70336
|
+
var import_node_fs38 = __toESM(require("node:fs"), 1);
|
|
70326
70337
|
|
|
70327
70338
|
// node_modules/write-excel-file/modules/xlsx/helpers/features/getAdditionalContent.js
|
|
70328
70339
|
function _createForOfIteratorHelperLoose(r, e) {
|
|
@@ -73422,7 +73433,7 @@ function writeXlsxFile(arg1, arg2, arg3) {
|
|
|
73422
73433
|
},
|
|
73423
73434
|
toFile: function toFile(filePath) {
|
|
73424
73435
|
return createReadableStream().then(function(readableStream) {
|
|
73425
|
-
return pipe(readableStream,
|
|
73436
|
+
return pipe(readableStream, import_node_fs38.default.createWriteStream(filePath));
|
|
73426
73437
|
});
|
|
73427
73438
|
}
|
|
73428
73439
|
};
|
|
@@ -74050,6 +74061,10 @@ function registerContractAccessRoutes(app, deps) {
|
|
|
74050
74061
|
}
|
|
74051
74062
|
|
|
74052
74063
|
// contract-access-errors.ts
|
|
74064
|
+
function replyRecoveryPendingError(error, request, reply) {
|
|
74065
|
+
request.log.warn({ code: error.code, err: error }, "contract recovery pending \u2014 request refused");
|
|
74066
|
+
return reply.status(409).send({ ok: false, error: error.message, code: error.code });
|
|
74067
|
+
}
|
|
74053
74068
|
function replyContractPolicyError(error, request, reply) {
|
|
74054
74069
|
const stateShaped = error.code === "contract-not-activated" || error.code === "contract-type-unknown" || error.code === "contract-type-wrong-app" || error.code === "contract-authority-unresolved";
|
|
74055
74070
|
if (stateShaped) {
|
|
@@ -74078,7 +74093,7 @@ function replyLifecycleLockBusyError(error, logger, reply) {
|
|
|
74078
74093
|
}
|
|
74079
74094
|
|
|
74080
74095
|
// project-export-files.ts
|
|
74081
|
-
var
|
|
74096
|
+
var import_node_fs39 = require("node:fs");
|
|
74082
74097
|
var import_node_path35 = require("node:path");
|
|
74083
74098
|
function projectExportFiles(appId, kindOf2 = appId) {
|
|
74084
74099
|
if (kindOf2 === "vectorize") {
|
|
@@ -74108,12 +74123,12 @@ function exportFileBase(projectId, appId, now = /* @__PURE__ */ new Date()) {
|
|
|
74108
74123
|
}
|
|
74109
74124
|
function uniqueProjectExportFilename(projectId, preferred) {
|
|
74110
74125
|
const dir = projectExportsDir(projectId);
|
|
74111
|
-
if (!(0,
|
|
74126
|
+
if (!(0, import_node_fs39.existsSync)((0, import_node_path35.join)(dir, preferred))) return preferred;
|
|
74112
74127
|
const extension = (0, import_node_path35.extname)(preferred);
|
|
74113
74128
|
const stem = preferred.slice(0, preferred.length - extension.length);
|
|
74114
74129
|
for (let suffix = 2; suffix <= 9999; suffix += 1) {
|
|
74115
74130
|
const candidate = `${stem}-${suffix}${extension}`;
|
|
74116
|
-
if (!(0,
|
|
74131
|
+
if (!(0, import_node_fs39.existsSync)((0, import_node_path35.join)(dir, candidate))) return candidate;
|
|
74117
74132
|
}
|
|
74118
74133
|
throw new Error("could not allocate a unique project export filename");
|
|
74119
74134
|
}
|
|
@@ -74128,11 +74143,24 @@ var WorkspaceSnapshotError = class extends Error {
|
|
|
74128
74143
|
status;
|
|
74129
74144
|
notReviewable;
|
|
74130
74145
|
};
|
|
74146
|
+
var NoApprovedVersionError = class extends WorkspaceSnapshotError {
|
|
74147
|
+
constructor() {
|
|
74148
|
+
super(409, "project has no approved version");
|
|
74149
|
+
this.name = "NoApprovedVersionError";
|
|
74150
|
+
}
|
|
74151
|
+
};
|
|
74131
74152
|
function approvedRows(projectId) {
|
|
74132
74153
|
const project = getProject(projectId);
|
|
74133
74154
|
if (!project) return [];
|
|
74155
|
+
const allRows = listVersions(projectId);
|
|
74156
|
+
if (project.uuid) {
|
|
74157
|
+
const tainted = allRows.find((v) => v.gate === "model" && v.kind === "approve" && !v.approval);
|
|
74158
|
+
if (tainted) {
|
|
74159
|
+
throw new WorkspaceSnapshotError(409, `project has no approved version: approved version ${tainted.n} has no approval proof`);
|
|
74160
|
+
}
|
|
74161
|
+
}
|
|
74134
74162
|
const projectTime = Date.parse(project.createdAt);
|
|
74135
|
-
return
|
|
74163
|
+
return allRows.filter((v) => v.gate === "model" && v.kind === "approve").filter((v) => v.approval ? !!project.uuid && v.approval.projectUuid === project.uuid : Number.isFinite(projectTime) && Date.parse(v.ts) >= projectTime).map(({ current: _current, ...meta }) => meta);
|
|
74136
74164
|
}
|
|
74137
74165
|
function latestApprovedVersion(projectId) {
|
|
74138
74166
|
return approvedRows(projectId)[0] ?? null;
|
|
@@ -74146,10 +74174,8 @@ function currentApprovedSnapshot(projectId, version) {
|
|
|
74146
74174
|
const rows2 = approvedRows(projectId);
|
|
74147
74175
|
const row = version === void 0 ? rows2[0] : rows2.find((v) => v.n === version);
|
|
74148
74176
|
if (!row) {
|
|
74149
|
-
throw new
|
|
74150
|
-
|
|
74151
|
-
version === void 0 ? "project has no approved version" : `approved version not found: ${version}`
|
|
74152
|
-
);
|
|
74177
|
+
if (version === void 0) throw new NoApprovedVersionError();
|
|
74178
|
+
throw new WorkspaceSnapshotError(404, `approved version not found: ${version}`);
|
|
74153
74179
|
}
|
|
74154
74180
|
const latest = rows2[0];
|
|
74155
74181
|
const assertOwned = (candidate, hash2) => {
|
|
@@ -74189,6 +74215,22 @@ function currentApprovedSnapshot(projectId, version) {
|
|
|
74189
74215
|
headDiverged: row.n !== latest.n
|
|
74190
74216
|
};
|
|
74191
74217
|
}
|
|
74218
|
+
function approvedSnapshotForMetadata(projectId, surface) {
|
|
74219
|
+
try {
|
|
74220
|
+
return currentApprovedSnapshot(projectId);
|
|
74221
|
+
} catch (error) {
|
|
74222
|
+
if (error instanceof NoApprovedVersionError) return null;
|
|
74223
|
+
if (error instanceof WorkspaceSnapshotError && error.status === 404) throw error;
|
|
74224
|
+
if (error instanceof WorkspaceSnapshotError || error instanceof ContractPolicyError) {
|
|
74225
|
+
const status = error instanceof WorkspaceSnapshotError ? error.status : error.code;
|
|
74226
|
+
console.error(
|
|
74227
|
+
`${surface}: project ${projectId} has an approved version the gate refused to serve (${status}) \u2014 reporting no approved head. ${error.message}`
|
|
74228
|
+
);
|
|
74229
|
+
return null;
|
|
74230
|
+
}
|
|
74231
|
+
throw error;
|
|
74232
|
+
}
|
|
74233
|
+
}
|
|
74192
74234
|
|
|
74193
74235
|
// approval-partition.ts
|
|
74194
74236
|
var unchangedNode = (value) => ({ materialize: () => value });
|
|
@@ -74833,16 +74875,16 @@ function buildApprovalReview(input) {
|
|
|
74833
74875
|
|
|
74834
74876
|
// working-revision-manifest.ts
|
|
74835
74877
|
var import_node_crypto24 = require("node:crypto");
|
|
74836
|
-
var
|
|
74878
|
+
var import_node_fs41 = require("node:fs");
|
|
74837
74879
|
var import_node_path36 = require("node:path");
|
|
74838
74880
|
|
|
74839
74881
|
// write-json-atomic.ts
|
|
74840
74882
|
var import_node_crypto23 = require("node:crypto");
|
|
74841
|
-
var
|
|
74883
|
+
var import_node_fs40 = require("node:fs");
|
|
74842
74884
|
function writeJsonAtomic(path, value) {
|
|
74843
74885
|
const tmp = `${path}.${process.pid}.${(0, import_node_crypto23.randomUUID)()}.tmp`;
|
|
74844
|
-
(0,
|
|
74845
|
-
(0,
|
|
74886
|
+
(0, import_node_fs40.writeFileSync)(tmp, canonicalJson(value));
|
|
74887
|
+
(0, import_node_fs40.renameSync)(tmp, path);
|
|
74846
74888
|
}
|
|
74847
74889
|
|
|
74848
74890
|
// working-revision-manifest.ts
|
|
@@ -74859,7 +74901,7 @@ function assertProject(project) {
|
|
|
74859
74901
|
function readWorkingRevisionManifest(project) {
|
|
74860
74902
|
const uuid = assertProject(project);
|
|
74861
74903
|
try {
|
|
74862
|
-
const value = JSON.parse((0,
|
|
74904
|
+
const value = JSON.parse((0, import_node_fs41.readFileSync)(pathOf(project.id), "utf8"));
|
|
74863
74905
|
if (value?.schema !== 1 || value.projectUuid !== uuid || !Number.isInteger(value.epoch) || value.epoch < 0) return null;
|
|
74864
74906
|
return checksumOf(bodyOf(value)) === value.checksum ? value : null;
|
|
74865
74907
|
} catch {
|
|
@@ -74881,8 +74923,8 @@ function ensureWorkingRevisionManifest(input) {
|
|
|
74881
74923
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
74882
74924
|
};
|
|
74883
74925
|
const value = { ...body, checksum: checksumOf(body) };
|
|
74884
|
-
(0,
|
|
74885
|
-
if (!(0,
|
|
74926
|
+
(0, import_node_fs41.mkdirSync)(projectDir(input.project.id), { recursive: true });
|
|
74927
|
+
if (!(0, import_node_fs41.existsSync)(pathOf(input.project.id))) writeJsonAtomic(pathOf(input.project.id), value);
|
|
74886
74928
|
return readWorkingRevisionManifest(input.project) ?? value;
|
|
74887
74929
|
}
|
|
74888
74930
|
function advanceWorkingRevisionManifest(input) {
|
|
@@ -75146,7 +75188,7 @@ function projectApprovalCandidateAccepted(appId, projectId, candidate) {
|
|
|
75146
75188
|
|
|
75147
75189
|
// project-checkpoints-store.ts
|
|
75148
75190
|
var import_node_crypto25 = require("node:crypto");
|
|
75149
|
-
var
|
|
75191
|
+
var import_node_fs42 = require("node:fs");
|
|
75150
75192
|
var import_node_path37 = require("node:path");
|
|
75151
75193
|
var HASH_RE2 = /^[0-9a-f]{64}$/;
|
|
75152
75194
|
function root4(projectId) {
|
|
@@ -75156,7 +75198,7 @@ var objectsDir2 = (projectId) => (0, import_node_path37.join)(root4(projectId),
|
|
|
75156
75198
|
var eventsPath = (projectId) => (0, import_node_path37.join)(root4(projectId), "events.json");
|
|
75157
75199
|
function readEvents(projectId) {
|
|
75158
75200
|
try {
|
|
75159
|
-
const parsed = JSON.parse((0,
|
|
75201
|
+
const parsed = JSON.parse((0, import_node_fs42.readFileSync)(eventsPath(projectId), "utf8"));
|
|
75160
75202
|
if (parsed?.schema !== 1 || !Array.isArray(parsed.events)) return { schema: 1, events: [] };
|
|
75161
75203
|
return { schema: 1, events: parsed.events.filter(validEvent) };
|
|
75162
75204
|
} catch {
|
|
@@ -75171,7 +75213,7 @@ function validEvent(value) {
|
|
|
75171
75213
|
function readContent(projectId, id) {
|
|
75172
75214
|
if (!HASH_RE2.test(id)) return null;
|
|
75173
75215
|
try {
|
|
75174
|
-
const value = JSON.parse((0,
|
|
75216
|
+
const value = JSON.parse((0, import_node_fs42.readFileSync)((0, import_node_path37.join)(objectsDir2(projectId), `${id}.json`), "utf8"));
|
|
75175
75217
|
if (value?.schema !== 1 || value.id !== id || hashCheckpoint(value) !== id) return null;
|
|
75176
75218
|
return value;
|
|
75177
75219
|
} catch {
|
|
@@ -75187,7 +75229,7 @@ function requireIdentity(project) {
|
|
|
75187
75229
|
return project.uuid;
|
|
75188
75230
|
}
|
|
75189
75231
|
function appendEvent(projectId, event) {
|
|
75190
|
-
(0,
|
|
75232
|
+
(0, import_node_fs42.mkdirSync)(root4(projectId), { recursive: true });
|
|
75191
75233
|
const log2 = readEvents(projectId);
|
|
75192
75234
|
const row = { ...event, eventId: (0, import_node_crypto25.randomUUID)(), at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
75193
75235
|
log2.events.push(row);
|
|
@@ -75205,9 +75247,9 @@ function captureProjectCheckpoint(input) {
|
|
|
75205
75247
|
contract: input.contract
|
|
75206
75248
|
};
|
|
75207
75249
|
const id = hashCheckpoint(withoutId);
|
|
75208
|
-
(0,
|
|
75250
|
+
(0, import_node_fs42.mkdirSync)(objectsDir2(input.project.id), { recursive: true });
|
|
75209
75251
|
const path = (0, import_node_path37.join)(objectsDir2(input.project.id), `${id}.json`);
|
|
75210
|
-
if (!(0,
|
|
75252
|
+
if (!(0, import_node_fs42.existsSync)(path)) writeJsonAtomic(path, { ...withoutId, id });
|
|
75211
75253
|
const event = appendEvent(input.project.id, {
|
|
75212
75254
|
checkpointId: id,
|
|
75213
75255
|
kind: "captured",
|
|
@@ -75250,7 +75292,7 @@ function markProjectCheckpoint(project, checkpointId, kind, expectedEventId) {
|
|
|
75250
75292
|
|
|
75251
75293
|
// export-source.ts
|
|
75252
75294
|
var import_node_crypto26 = require("node:crypto");
|
|
75253
|
-
var
|
|
75295
|
+
var import_node_fs43 = require("node:fs");
|
|
75254
75296
|
var import_node_os19 = require("node:os");
|
|
75255
75297
|
var import_node_path38 = require("node:path");
|
|
75256
75298
|
var HANDLE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -75273,7 +75315,7 @@ function validId(id) {
|
|
|
75273
75315
|
function readExportHandle(handleId) {
|
|
75274
75316
|
if (!validId(handleId)) return null;
|
|
75275
75317
|
try {
|
|
75276
|
-
const value = JSON.parse((0,
|
|
75318
|
+
const value = JSON.parse((0, import_node_fs43.readFileSync)(handlePath(handleId), "utf8"));
|
|
75277
75319
|
if (value?.schema !== 1 || value.handleId !== handleId || value.checksum !== hashOf(withoutChecksum(value))) return null;
|
|
75278
75320
|
return value;
|
|
75279
75321
|
} catch {
|
|
@@ -75282,7 +75324,7 @@ function readExportHandle(handleId) {
|
|
|
75282
75324
|
}
|
|
75283
75325
|
function captureExportSource(projectId, selector = { kind: "latest-approved" }, isDerivedEligible) {
|
|
75284
75326
|
collectExpiredExportHandles();
|
|
75285
|
-
if ((0,
|
|
75327
|
+
if ((0, import_node_fs43.existsSync)(storeRoot()) && (0, import_node_fs43.readdirSync)(storeRoot()).filter((name) => name.endsWith(".json")).length >= MAX_STORED_HANDLES) {
|
|
75286
75328
|
throw new Error("too many frozen export sources are waiting; finish or retry older exports first");
|
|
75287
75329
|
}
|
|
75288
75330
|
const project = getProject(projectId);
|
|
@@ -75321,11 +75363,7 @@ function captureExportSource(projectId, selector = { kind: "latest-approved" },
|
|
|
75321
75363
|
draft = true;
|
|
75322
75364
|
derived = isDerivedEligible ? isDerivedEligible(contract) : true;
|
|
75323
75365
|
baseApprovedVersion = manifest?.workingBase?.version ?? null;
|
|
75324
|
-
|
|
75325
|
-
latestApprovedVersion2 = currentApprovedSnapshot(projectId).version.n;
|
|
75326
|
-
} catch {
|
|
75327
|
-
latestApprovedVersion2 = null;
|
|
75328
|
-
}
|
|
75366
|
+
latestApprovedVersion2 = approvedSnapshotForMetadata(projectId, "capturing a working export source")?.version.n ?? null;
|
|
75329
75367
|
} else {
|
|
75330
75368
|
const checkpoint = readProjectCheckpoint(project, selector.checkpointId);
|
|
75331
75369
|
if (!checkpoint) throw new Error(`checkpoint not found: ${selector.checkpointId}`);
|
|
@@ -75335,11 +75373,7 @@ function captureExportSource(projectId, selector = { kind: "latest-approved" },
|
|
|
75335
75373
|
sourceRef = checkpoint.id;
|
|
75336
75374
|
draft = true;
|
|
75337
75375
|
baseApprovedVersion = checkpoint.base?.version ?? null;
|
|
75338
|
-
|
|
75339
|
-
latestApprovedVersion2 = currentApprovedSnapshot(projectId).version.n;
|
|
75340
|
-
} catch {
|
|
75341
|
-
latestApprovedVersion2 = null;
|
|
75342
|
-
}
|
|
75376
|
+
latestApprovedVersion2 = approvedSnapshotForMetadata(projectId, "capturing a checkpoint export source")?.version.n ?? null;
|
|
75343
75377
|
derived = isDerivedEligible ? isDerivedEligible(contract) : false;
|
|
75344
75378
|
}
|
|
75345
75379
|
const contentHash = hashOf(contract);
|
|
@@ -75368,7 +75402,7 @@ function captureExportSource(projectId, selector = { kind: "latest-approved" },
|
|
|
75368
75402
|
expiresAt: new Date(Date.now() + HANDLE_TTL_MS).toISOString(),
|
|
75369
75403
|
resultRefs: []
|
|
75370
75404
|
};
|
|
75371
|
-
(0,
|
|
75405
|
+
(0, import_node_fs43.mkdirSync)(storeRoot(), { recursive: true });
|
|
75372
75406
|
writeJsonAtomic(handlePath(handleId), stored(body));
|
|
75373
75407
|
const { contract: _contract, lease: _lease, expiresAt: _expiresAt, resultRefs: _refs, checksum: _checksum, ...resolved } = readExportHandle(handleId);
|
|
75374
75408
|
return resolved;
|
|
@@ -75380,7 +75414,7 @@ function cloneExportHandle(handleId, copies) {
|
|
|
75380
75414
|
if (!original || original.lease !== "active" || Date.parse(original.expiresAt) <= Date.now()) {
|
|
75381
75415
|
throw new Error("export source handle is unavailable");
|
|
75382
75416
|
}
|
|
75383
|
-
const storedCount = (0,
|
|
75417
|
+
const storedCount = (0, import_node_fs43.existsSync)(storeRoot()) ? (0, import_node_fs43.readdirSync)(storeRoot()).filter((name) => name.endsWith(".json")).length : 0;
|
|
75384
75418
|
if (storedCount + copies - 1 > MAX_STORED_HANDLES) throw new Error("too many frozen export sources are waiting");
|
|
75385
75419
|
const results = [];
|
|
75386
75420
|
const created = [];
|
|
@@ -75395,7 +75429,7 @@ function cloneExportHandle(handleId, copies) {
|
|
|
75395
75429
|
results.push(resolved);
|
|
75396
75430
|
}
|
|
75397
75431
|
} catch (error) {
|
|
75398
|
-
for (const id of created) (0,
|
|
75432
|
+
for (const id of created) (0, import_node_fs43.rmSync)(handlePath(id), { force: true });
|
|
75399
75433
|
throw error;
|
|
75400
75434
|
}
|
|
75401
75435
|
return results;
|
|
@@ -75435,21 +75469,21 @@ function releaseUnusedExportHandle(handleId, projectId, projectUuid) {
|
|
|
75435
75469
|
}
|
|
75436
75470
|
function projectIdHasActiveExportLeases(projectId) {
|
|
75437
75471
|
collectExpiredExportHandles();
|
|
75438
|
-
if (!(0,
|
|
75439
|
-
return (0,
|
|
75472
|
+
if (!(0, import_node_fs43.existsSync)(storeRoot())) return false;
|
|
75473
|
+
return (0, import_node_fs43.readdirSync)(storeRoot()).some((name) => {
|
|
75440
75474
|
const handle = name.endsWith(".json") ? readExportHandle(name.slice(0, -5)) : null;
|
|
75441
75475
|
return handle?.projectId === projectId && handle.lease === "active" && Date.parse(handle.expiresAt) > Date.now();
|
|
75442
75476
|
});
|
|
75443
75477
|
}
|
|
75444
75478
|
function collectExpiredExportHandles(now = Date.now()) {
|
|
75445
|
-
if (!(0,
|
|
75479
|
+
if (!(0, import_node_fs43.existsSync)(storeRoot())) return 0;
|
|
75446
75480
|
let removed = 0;
|
|
75447
|
-
for (const name of (0,
|
|
75481
|
+
for (const name of (0, import_node_fs43.readdirSync)(storeRoot())) {
|
|
75448
75482
|
if (!name.endsWith(".json")) continue;
|
|
75449
75483
|
const id = name.slice(0, -5);
|
|
75450
75484
|
const handle = readExportHandle(id);
|
|
75451
75485
|
if (!handle || Date.parse(handle.expiresAt) <= now && handle.resultRefs.length === 0) {
|
|
75452
|
-
(0,
|
|
75486
|
+
(0, import_node_fs43.rmSync)(handlePath(id), { force: true });
|
|
75453
75487
|
removed++;
|
|
75454
75488
|
}
|
|
75455
75489
|
}
|
|
@@ -75458,7 +75492,7 @@ function collectExpiredExportHandles(now = Date.now()) {
|
|
|
75458
75492
|
|
|
75459
75493
|
// file-publication.ts
|
|
75460
75494
|
var import_node_crypto27 = require("node:crypto");
|
|
75461
|
-
var
|
|
75495
|
+
var import_node_fs44 = require("node:fs");
|
|
75462
75496
|
var import_node_path39 = require("node:path");
|
|
75463
75497
|
var FilePublicationError = class extends Error {
|
|
75464
75498
|
constructor(message, code, paths = []) {
|
|
@@ -75476,7 +75510,7 @@ var proofOfBytes = (bytes) => ({
|
|
|
75476
75510
|
});
|
|
75477
75511
|
function readFileProof2(path) {
|
|
75478
75512
|
try {
|
|
75479
|
-
return proofOfBytes((0,
|
|
75513
|
+
return proofOfBytes((0, import_node_fs44.readFileSync)(path));
|
|
75480
75514
|
} catch (error) {
|
|
75481
75515
|
if (error.code === "ENOENT") return null;
|
|
75482
75516
|
throw error;
|
|
@@ -75485,39 +75519,20 @@ function readFileProof2(path) {
|
|
|
75485
75519
|
function fileProofEquals2(a, b) {
|
|
75486
75520
|
return a === null || b === null ? a === b : a.bytes === b.bytes && a.sha256 === b.sha256;
|
|
75487
75521
|
}
|
|
75488
|
-
function syncFile3(path) {
|
|
75489
|
-
const fd2 = (0, import_node_fs43.openSync)(path, "r+");
|
|
75490
|
-
try {
|
|
75491
|
-
(0, import_node_fs43.fsyncSync)(fd2);
|
|
75492
|
-
} finally {
|
|
75493
|
-
(0, import_node_fs43.closeSync)(fd2);
|
|
75494
|
-
}
|
|
75495
|
-
}
|
|
75496
|
-
function syncDirectoryBestEffort3(path) {
|
|
75497
|
-
try {
|
|
75498
|
-
const fd2 = (0, import_node_fs43.openSync)(path, "r");
|
|
75499
|
-
try {
|
|
75500
|
-
(0, import_node_fs43.fsyncSync)(fd2);
|
|
75501
|
-
} finally {
|
|
75502
|
-
(0, import_node_fs43.closeSync)(fd2);
|
|
75503
|
-
}
|
|
75504
|
-
} catch {
|
|
75505
|
-
}
|
|
75506
|
-
}
|
|
75507
75522
|
function durableCanonicalJson(path, value) {
|
|
75508
75523
|
const dir = (0, import_node_path39.dirname)(path);
|
|
75509
|
-
(0,
|
|
75524
|
+
(0, import_node_fs44.mkdirSync)(dir, { recursive: true });
|
|
75510
75525
|
const temp = (0, import_node_path39.join)(dir, `.${(0, import_node_path39.basename)(path)}.${process.pid}.${(0, import_node_crypto27.randomUUID)()}.tmp`);
|
|
75511
75526
|
try {
|
|
75512
|
-
(0,
|
|
75527
|
+
(0, import_node_fs44.writeFileSync)(temp, `${canonicalJson(value)}
|
|
75513
75528
|
`, { encoding: "utf8", flag: "wx" });
|
|
75514
|
-
|
|
75515
|
-
(0,
|
|
75516
|
-
|
|
75517
|
-
|
|
75529
|
+
syncFile(temp);
|
|
75530
|
+
(0, import_node_fs44.renameSync)(temp, path);
|
|
75531
|
+
syncFile(path);
|
|
75532
|
+
syncDirectoryBestEffort(dir);
|
|
75518
75533
|
} finally {
|
|
75519
75534
|
try {
|
|
75520
|
-
(0,
|
|
75535
|
+
(0, import_node_fs44.rmSync)(temp, { force: true });
|
|
75521
75536
|
} catch {
|
|
75522
75537
|
}
|
|
75523
75538
|
}
|
|
@@ -75536,7 +75551,7 @@ function mappedError(error, paths) {
|
|
|
75536
75551
|
}
|
|
75537
75552
|
function linkExclusive(source, destination) {
|
|
75538
75553
|
try {
|
|
75539
|
-
(0,
|
|
75554
|
+
(0, import_node_fs44.linkSync)(source, destination);
|
|
75540
75555
|
} catch (error) {
|
|
75541
75556
|
throw mappedError(error, [source, destination]);
|
|
75542
75557
|
}
|
|
@@ -75545,27 +75560,27 @@ function assertSameVolume(a, b) {
|
|
|
75545
75560
|
let aDev;
|
|
75546
75561
|
let bDev;
|
|
75547
75562
|
try {
|
|
75548
|
-
aDev = (0,
|
|
75549
|
-
bDev = (0,
|
|
75563
|
+
aDev = (0, import_node_fs44.statSync)(a, { bigint: true }).dev;
|
|
75564
|
+
bDev = (0, import_node_fs44.statSync)(b, { bigint: true }).dev;
|
|
75550
75565
|
} catch (error) {
|
|
75551
75566
|
throw mappedError(error, [a, b]);
|
|
75552
75567
|
}
|
|
75553
75568
|
if (aDev !== bDev) throw new FilePublicationError("publication paths are not on the same volume", "different-volume", [a, b]);
|
|
75554
75569
|
}
|
|
75555
75570
|
function uniqueArtifact(dir, label2, livePath) {
|
|
75556
|
-
(0,
|
|
75571
|
+
(0, import_node_fs44.mkdirSync)(dir, { recursive: true });
|
|
75557
75572
|
return (0, import_node_path39.join)(dir, `.floless-${label2}-${(0, import_node_crypto27.randomUUID)()}-${(0, import_node_path39.basename)(livePath)}`);
|
|
75558
75573
|
}
|
|
75559
75574
|
function publishFileExclusive(input) {
|
|
75560
75575
|
const { livePath, stagedPath, expectedLive, artifactDir } = input;
|
|
75561
|
-
assertSameVolume(stagedPath, (0,
|
|
75576
|
+
assertSameVolume(stagedPath, (0, import_node_fs44.existsSync)(livePath) ? livePath : (0, import_node_path39.dirname)(livePath));
|
|
75562
75577
|
const stagedProof = readFileProof2(stagedPath);
|
|
75563
75578
|
if (!stagedProof) throw new FilePublicationError("staged publication file is missing", "io-failure", [stagedPath]);
|
|
75564
75579
|
let beforeImage = null;
|
|
75565
75580
|
if (expectedLive) {
|
|
75566
75581
|
beforeImage = uniqueArtifact(artifactDir, "before", livePath);
|
|
75567
75582
|
try {
|
|
75568
|
-
(0,
|
|
75583
|
+
(0, import_node_fs44.renameSync)(livePath, beforeImage);
|
|
75569
75584
|
} catch (error) {
|
|
75570
75585
|
throw mappedError(error, [livePath, beforeImage]);
|
|
75571
75586
|
}
|
|
@@ -75577,19 +75592,19 @@ function publishFileExclusive(input) {
|
|
|
75577
75592
|
}
|
|
75578
75593
|
throw new FilePublicationError("the live file changed before publication", "live-changed", [livePath, beforeImage]);
|
|
75579
75594
|
}
|
|
75580
|
-
} else if ((0,
|
|
75595
|
+
} else if ((0, import_node_fs44.existsSync)(livePath)) {
|
|
75581
75596
|
throw new FilePublicationError("the live destination appeared before publication", "destination-exists", [livePath]);
|
|
75582
75597
|
}
|
|
75583
75598
|
try {
|
|
75584
75599
|
input.onFaultPoint?.("after-live-move", { livePath, stagedPath, beforeImage });
|
|
75585
75600
|
linkExclusive(stagedPath, livePath);
|
|
75586
75601
|
input.onFaultPoint?.("after-live-link", { livePath, stagedPath, beforeImage });
|
|
75587
|
-
(0,
|
|
75602
|
+
(0, import_node_fs44.unlinkSync)(stagedPath);
|
|
75588
75603
|
input.onFaultPoint?.("after-staged-unlink", { livePath, stagedPath, beforeImage });
|
|
75589
|
-
|
|
75590
|
-
|
|
75604
|
+
syncFile(livePath);
|
|
75605
|
+
syncDirectoryBestEffort((0, import_node_path39.dirname)(livePath));
|
|
75591
75606
|
} catch (error) {
|
|
75592
|
-
if (beforeImage && !(0,
|
|
75607
|
+
if (beforeImage && !(0, import_node_fs44.existsSync)(livePath)) {
|
|
75593
75608
|
try {
|
|
75594
75609
|
linkExclusive(beforeImage, livePath);
|
|
75595
75610
|
} catch {
|
|
@@ -75612,7 +75627,7 @@ function publishFileExclusive(input) {
|
|
|
75612
75627
|
var import_node_path41 = require("node:path");
|
|
75613
75628
|
|
|
75614
75629
|
// app-source-lock.ts
|
|
75615
|
-
var
|
|
75630
|
+
var import_node_fs45 = require("node:fs");
|
|
75616
75631
|
var import_node_os20 = require("node:os");
|
|
75617
75632
|
var import_node_path40 = require("node:path");
|
|
75618
75633
|
var AppSourcePublicationBusyError = class extends Error {
|
|
@@ -75625,9 +75640,9 @@ var AppSourcePublicationBusyError = class extends Error {
|
|
|
75625
75640
|
function activeApprovalTransaction(appId) {
|
|
75626
75641
|
const home = process.env.AWARE_HOME || (0, import_node_path40.join)((0, import_node_os20.homedir)(), ".aware");
|
|
75627
75642
|
const path = (0, import_node_path40.join)(home, "apps", appId, ".floless-approval-publication-journal-v1.json");
|
|
75628
|
-
if (!(0,
|
|
75643
|
+
if (!(0, import_node_fs45.existsSync)(path)) return null;
|
|
75629
75644
|
try {
|
|
75630
|
-
const stored2 = JSON.parse((0,
|
|
75645
|
+
const stored2 = JSON.parse((0, import_node_fs45.readFileSync)(path, "utf8"));
|
|
75631
75646
|
return typeof stored2?.journal?.id === "string" && stored2.journal.id ? stored2.journal.id : "__invalid__";
|
|
75632
75647
|
} catch {
|
|
75633
75648
|
return "__invalid__";
|
|
@@ -75643,7 +75658,7 @@ function withAppSourceLock(appId, label2, fn, options = {}) {
|
|
|
75643
75658
|
|
|
75644
75659
|
// app-publication-manifest.ts
|
|
75645
75660
|
var import_node_crypto28 = require("node:crypto");
|
|
75646
|
-
var
|
|
75661
|
+
var import_node_fs46 = require("node:fs");
|
|
75647
75662
|
var import_yaml7 = __toESM(require_dist6(), 1);
|
|
75648
75663
|
var APP_PUBLICATION_MANIFEST_SCHEMA = 1;
|
|
75649
75664
|
var AppPublicationManifestError = class extends Error {
|
|
@@ -75660,7 +75675,7 @@ function observeAppPublication(sourcePath, lockPath2) {
|
|
|
75660
75675
|
let lockSourceHash = null;
|
|
75661
75676
|
if (lock) {
|
|
75662
75677
|
try {
|
|
75663
|
-
const parsed = (0, import_yaml7.parse)((0,
|
|
75678
|
+
const parsed = (0, import_yaml7.parse)((0, import_node_fs46.readFileSync)(lockPath2, "utf8"));
|
|
75664
75679
|
lockSourceHash = typeof parsed?.["source-hash"] === "string" ? parsed["source-hash"] : null;
|
|
75665
75680
|
} catch {
|
|
75666
75681
|
}
|
|
@@ -75685,10 +75700,10 @@ function validManifest(value) {
|
|
|
75685
75700
|
return m.schema === APP_PUBLICATION_MANIFEST_SCHEMA && typeof m.publicationId === "string" && !!m.publicationId && typeof m.appId === "string" && !!m.appId && Number.isSafeInteger(m.generation) && (m.generation ?? -1) >= 0 && (m.state === "ready-clean" || m.state === "ready-dirty" || m.state === "recovering") && validProof(m.source) && validProof(m.lock) && (m.lockSourceHash === null || typeof m.lockSourceHash === "string") && validTxn && typeof m.updatedAt === "string" && (m.state === "recovering" ? m.transaction !== null : m.transaction === null);
|
|
75686
75701
|
}
|
|
75687
75702
|
function readAppPublicationManifest(path) {
|
|
75688
|
-
if (!(0,
|
|
75703
|
+
if (!(0, import_node_fs46.existsSync)(path)) return null;
|
|
75689
75704
|
let stored2;
|
|
75690
75705
|
try {
|
|
75691
|
-
stored2 = JSON.parse((0,
|
|
75706
|
+
stored2 = JSON.parse((0, import_node_fs46.readFileSync)(path, "utf8"));
|
|
75692
75707
|
} catch {
|
|
75693
75708
|
throw new AppPublicationManifestError(`app publication manifest is unreadable: ${path}`, "corrupt");
|
|
75694
75709
|
}
|
|
@@ -75881,7 +75896,7 @@ function withAppPublicationWhileProjectLocked(input) {
|
|
|
75881
75896
|
|
|
75882
75897
|
// approval-app-publication.ts
|
|
75883
75898
|
var import_node_crypto29 = require("node:crypto");
|
|
75884
|
-
var
|
|
75899
|
+
var import_node_fs47 = require("node:fs");
|
|
75885
75900
|
var import_node_path42 = require("node:path");
|
|
75886
75901
|
var JOURNAL = ".floless-approval-publication-journal-v1.json";
|
|
75887
75902
|
var MANIFEST = ".floless-app-publication-state-v1.json";
|
|
@@ -75908,7 +75923,7 @@ function storeJournal(journal) {
|
|
|
75908
75923
|
}
|
|
75909
75924
|
function readApprovalPublicationJournal(sourcePath) {
|
|
75910
75925
|
try {
|
|
75911
|
-
const stored2 = JSON.parse((0,
|
|
75926
|
+
const stored2 = JSON.parse((0, import_node_fs47.readFileSync)(approvalPublicationJournalPath(sourcePath), "utf8"));
|
|
75912
75927
|
const value = stored2?.journal;
|
|
75913
75928
|
const expectedLiveLock = sourcePath.replace(/\.[^.]+$/, ".lock");
|
|
75914
75929
|
const expectedStageDir = (0, import_node_path42.join)(stagingRoot2(sourcePath), `${value?.appId ?? ""}-${value?.id ?? ""}`);
|
|
@@ -75934,8 +75949,8 @@ async function stageApprovalPublication(input) {
|
|
|
75934
75949
|
const beforeSource = readFileProof2(input.sourcePath);
|
|
75935
75950
|
const beforeLock = readFileProof2(input.liveLockPath);
|
|
75936
75951
|
try {
|
|
75937
|
-
(0,
|
|
75938
|
-
(0,
|
|
75952
|
+
(0, import_node_fs47.mkdirSync)(stageDir, { recursive: true });
|
|
75953
|
+
(0, import_node_fs47.cpSync)(appRoot, stagedAppRoot, {
|
|
75939
75954
|
recursive: true,
|
|
75940
75955
|
filter: (path) => ![JOURNAL, MANIFEST].includes((0, import_node_path42.basename)(path))
|
|
75941
75956
|
});
|
|
@@ -75948,7 +75963,7 @@ async function stageApprovalPublication(input) {
|
|
|
75948
75963
|
throw new Error("live workflow changed while the approval was being staged");
|
|
75949
75964
|
}
|
|
75950
75965
|
} catch (error) {
|
|
75951
|
-
(0,
|
|
75966
|
+
(0, import_node_fs47.rmSync)(stageDir, { recursive: true, force: true });
|
|
75952
75967
|
throw error;
|
|
75953
75968
|
}
|
|
75954
75969
|
const journal = {
|
|
@@ -75981,12 +75996,12 @@ function publishOne(livePath, stagedPath, before, staged, artifactDir) {
|
|
|
75981
75996
|
const live = readFileProof2(livePath);
|
|
75982
75997
|
if (fileProofEquals2(live, staged)) return;
|
|
75983
75998
|
if (!fileProofEquals2(live, before)) throw new Error(`live publication changed outside the approval transaction: ${livePath}`);
|
|
75984
|
-
if (!(0,
|
|
75999
|
+
if (!(0, import_node_fs47.existsSync)(stagedPath)) throw new Error(`staged publication bytes are unavailable: ${stagedPath}`);
|
|
75985
76000
|
publishFileExclusive({ livePath, stagedPath, expectedLive: before, artifactDir });
|
|
75986
76001
|
}
|
|
75987
76002
|
function completeApprovalPublication(journal) {
|
|
75988
76003
|
if (journal.phase !== "authorized" && journal.phase !== "published") throw new Error("approval publication is not authorized");
|
|
75989
|
-
(0,
|
|
76004
|
+
(0, import_node_fs47.mkdirSync)(journal.artifactDir, { recursive: true });
|
|
75990
76005
|
publishOne(journal.liveSourcePath, journal.stagedSourcePath, journal.beforeSource, journal.stagedSource, journal.artifactDir);
|
|
75991
76006
|
publishOne(journal.liveLockPath, journal.stagedLockPath, journal.beforeLock, journal.stagedLock, journal.artifactDir);
|
|
75992
76007
|
if (!fileProofEquals2(readFileProof2(journal.liveSourcePath), journal.stagedSource) || !fileProofEquals2(readFileProof2(journal.liveLockPath), journal.stagedLock)) {
|
|
@@ -75999,17 +76014,17 @@ function finalizeApprovalPublication(journal) {
|
|
|
75999
76014
|
if (!current || current.id !== journal.id || current.phase !== "published") {
|
|
76000
76015
|
throw new Error("published approval recovery authority is unavailable");
|
|
76001
76016
|
}
|
|
76002
|
-
(0,
|
|
76003
|
-
(0,
|
|
76017
|
+
(0, import_node_fs47.rmSync)(journal.stageDir, { recursive: true, force: true });
|
|
76018
|
+
(0, import_node_fs47.rmSync)(approvalPublicationJournalPath(journal.liveSourcePath), { force: true });
|
|
76004
76019
|
}
|
|
76005
76020
|
function abandonApprovalPublication(journal) {
|
|
76006
76021
|
if (journal.phase !== "staged") throw new Error("an authorized approval publication must be completed, not abandoned");
|
|
76007
|
-
(0,
|
|
76008
|
-
(0,
|
|
76022
|
+
(0, import_node_fs47.rmSync)(approvalPublicationJournalPath(journal.liveSourcePath), { force: true });
|
|
76023
|
+
(0, import_node_fs47.rmSync)(journal.stageDir, { recursive: true, force: true });
|
|
76009
76024
|
}
|
|
76010
76025
|
|
|
76011
76026
|
// workspace-data.ts
|
|
76012
|
-
var
|
|
76027
|
+
var import_node_fs48 = require("node:fs");
|
|
76013
76028
|
var VALID_INCLUDES = /* @__PURE__ */ new Set(["contract", "exports"]);
|
|
76014
76029
|
var VALID_EXPORT_KINDS = /* @__PURE__ */ new Set([
|
|
76015
76030
|
"bom-csv",
|
|
@@ -76070,15 +76085,15 @@ function exportBody(projectId, receipt, opts) {
|
|
|
76070
76085
|
};
|
|
76071
76086
|
if (opts.includePaths) body.path = path;
|
|
76072
76087
|
if (opts.exportContents) {
|
|
76073
|
-
const st = (0,
|
|
76088
|
+
const st = (0, import_node_fs48.statSync)(path);
|
|
76074
76089
|
if (st.size > opts.maxBytes) {
|
|
76075
76090
|
body.contentOmitted = true;
|
|
76076
76091
|
body.omittedReason = `export is ${st.size} bytes, over max-bytes ${opts.maxBytes}`;
|
|
76077
76092
|
} else if (receipt.encoding === "base64") {
|
|
76078
|
-
body.content = (0,
|
|
76093
|
+
body.content = (0, import_node_fs48.readFileSync)(path).toString("base64");
|
|
76079
76094
|
} else {
|
|
76080
76095
|
body.encoding = receipt.encoding ?? "utf8";
|
|
76081
|
-
body.content = (0,
|
|
76096
|
+
body.content = (0, import_node_fs48.readFileSync)(path, "utf8");
|
|
76082
76097
|
}
|
|
76083
76098
|
}
|
|
76084
76099
|
return body;
|
|
@@ -76090,7 +76105,16 @@ function registerWorkspaceDataRoutes(app) {
|
|
|
76090
76105
|
const resolveRoot = templateIdResolver();
|
|
76091
76106
|
const filterRoot = appFilter ? resolveRoot(appFilter) : void 0;
|
|
76092
76107
|
const projects = listProjects().filter((p) => !appFilter || p.app === appFilter || resolveRoot(p.app) === filterRoot).flatMap((p) => {
|
|
76093
|
-
|
|
76108
|
+
let latest;
|
|
76109
|
+
try {
|
|
76110
|
+
latest = latestApprovedVersion(p.id);
|
|
76111
|
+
} catch (error) {
|
|
76112
|
+
if (error instanceof WorkspaceSnapshotError) {
|
|
76113
|
+
req.log.warn({ projectId: p.id, error: error.message }, "approved project omitted because its snapshot gate refused it");
|
|
76114
|
+
return [];
|
|
76115
|
+
}
|
|
76116
|
+
throw error;
|
|
76117
|
+
}
|
|
76094
76118
|
if (!latest) return [];
|
|
76095
76119
|
return [{
|
|
76096
76120
|
id: p.id,
|
|
@@ -76345,7 +76369,7 @@ function registerMigrationCommitRoute(app, deps) {
|
|
|
76345
76369
|
return reply.send(res);
|
|
76346
76370
|
} catch (e) {
|
|
76347
76371
|
if (e instanceof RecoveryPendingError) {
|
|
76348
|
-
return
|
|
76372
|
+
return replyRecoveryPendingError(e, req, reply);
|
|
76349
76373
|
}
|
|
76350
76374
|
if (e instanceof ContractTransactionError) {
|
|
76351
76375
|
return reply.status(statusFor(e.code)).send({ ok: false, error: e.message, code: e.code });
|
|
@@ -76357,7 +76381,7 @@ function registerMigrationCommitRoute(app, deps) {
|
|
|
76357
76381
|
}
|
|
76358
76382
|
|
|
76359
76383
|
// workspace-agent-manifest.ts
|
|
76360
|
-
var
|
|
76384
|
+
var import_node_fs49 = require("node:fs");
|
|
76361
76385
|
var import_node_os21 = require("node:os");
|
|
76362
76386
|
var import_node_path43 = require("node:path");
|
|
76363
76387
|
function awareHome() {
|
|
@@ -76368,7 +76392,7 @@ function workspaceAgentDir() {
|
|
|
76368
76392
|
}
|
|
76369
76393
|
function syncWorkspaceAgentManifest(port) {
|
|
76370
76394
|
const dir = workspaceAgentDir();
|
|
76371
|
-
(0,
|
|
76395
|
+
(0, import_node_fs49.mkdirSync)(dir, { recursive: true });
|
|
76372
76396
|
const manifest = `agent: floless-workspace
|
|
76373
76397
|
version: 0.2.0
|
|
76374
76398
|
sdk-target: 2.4.0
|
|
@@ -76499,7 +76523,7 @@ commands:
|
|
|
76499
76523
|
body: object
|
|
76500
76524
|
`;
|
|
76501
76525
|
const path = (0, import_node_path43.join)(dir, "manifest.yaml");
|
|
76502
|
-
if (!(0,
|
|
76526
|
+
if (!(0, import_node_fs49.existsSync)(path) || manifest !== "") (0, import_node_fs49.writeFileSync)(path, manifest, "utf8");
|
|
76503
76527
|
return path;
|
|
76504
76528
|
}
|
|
76505
76529
|
|
|
@@ -77594,7 +77618,7 @@ function computeVersionDiff(id, n, base) {
|
|
|
77594
77618
|
}
|
|
77595
77619
|
|
|
77596
77620
|
// contract-bake.ts
|
|
77597
|
-
var
|
|
77621
|
+
var import_node_fs50 = require("node:fs");
|
|
77598
77622
|
var import_yaml8 = __toESM(require_dist6(), 1);
|
|
77599
77623
|
function isSteelType(t) {
|
|
77600
77624
|
return t === STEEL_V1 || t === STEEL_V2;
|
|
@@ -77618,7 +77642,7 @@ function bakedV2(contract) {
|
|
|
77618
77642
|
return stripConfidentialImages(baked);
|
|
77619
77643
|
}
|
|
77620
77644
|
function bakeContractIntoApp(sourcePath, contract) {
|
|
77621
|
-
const doc = (0, import_yaml8.parseDocument)((0,
|
|
77645
|
+
const doc = (0, import_yaml8.parseDocument)((0, import_node_fs50.readFileSync)(sourcePath, "utf8"));
|
|
77622
77646
|
if (doc.errors.length > 0) {
|
|
77623
77647
|
throw new Error(`contract bake: source is not valid YAML: ${doc.errors[0]?.message ?? "parse error"}`);
|
|
77624
77648
|
}
|
|
@@ -77642,7 +77666,7 @@ function bakeContractIntoApp(sourcePath, contract) {
|
|
|
77642
77666
|
throw new InvalidModelV2Error(`refusing to bake: contract declares steel.model/v2 but is not valid v2: ${issues[0] ?? "unknown"}`, issues);
|
|
77643
77667
|
}
|
|
77644
77668
|
doc.setIn(["nodes", idx, "config", "takeoff"], bakedV2(contract));
|
|
77645
|
-
(0,
|
|
77669
|
+
(0, import_node_fs50.writeFileSync)(sourcePath, doc.toString());
|
|
77646
77670
|
return;
|
|
77647
77671
|
}
|
|
77648
77672
|
const baked = { ...contract };
|
|
@@ -77687,7 +77711,7 @@ function bakeContractIntoApp(sourcePath, contract) {
|
|
|
77687
77711
|
);
|
|
77688
77712
|
}
|
|
77689
77713
|
doc.setIn(["nodes", idx, "config", "takeoff"], baked);
|
|
77690
|
-
(0,
|
|
77714
|
+
(0, import_node_fs50.writeFileSync)(sourcePath, doc.toString());
|
|
77691
77715
|
}
|
|
77692
77716
|
|
|
77693
77717
|
// vectorize.ts
|
|
@@ -78109,11 +78133,11 @@ function awareFailureMessage(e, fallback2) {
|
|
|
78109
78133
|
}
|
|
78110
78134
|
|
|
78111
78135
|
// scene-bake.ts
|
|
78112
|
-
var
|
|
78136
|
+
var import_node_fs51 = require("node:fs");
|
|
78113
78137
|
var import_node_path44 = require("node:path");
|
|
78114
78138
|
var import_yaml9 = __toESM(require_dist6(), 1);
|
|
78115
78139
|
function bakeSceneIntoApp(sourcePath, scene, agent = "viewer-3d") {
|
|
78116
|
-
const doc = (0, import_yaml9.parseDocument)((0,
|
|
78140
|
+
const doc = (0, import_yaml9.parseDocument)((0, import_node_fs51.readFileSync)(sourcePath, "utf8"));
|
|
78117
78141
|
if (doc.errors.length > 0) {
|
|
78118
78142
|
throw new Error(`scene bake: source is not valid YAML: ${doc.errors[0]?.message ?? "parse error"}`);
|
|
78119
78143
|
}
|
|
@@ -78122,10 +78146,10 @@ function bakeSceneIntoApp(sourcePath, scene, agent = "viewer-3d") {
|
|
|
78122
78146
|
const idx = items.findIndex((it) => ((0, import_yaml9.isMap)(it) ? it.toJSON() : null)?.agent === agent);
|
|
78123
78147
|
if (idx < 0) throw new Error(`no ${agent} render node to bake the scene into`);
|
|
78124
78148
|
doc.setIn(["nodes", idx, "config", "scene"], scene);
|
|
78125
|
-
(0,
|
|
78149
|
+
(0, import_node_fs51.writeFileSync)(sourcePath, doc.toString());
|
|
78126
78150
|
}
|
|
78127
78151
|
function bakeNodeConfigById(sourcePath, nodeId, patch2) {
|
|
78128
|
-
const doc = (0, import_yaml9.parseDocument)((0,
|
|
78152
|
+
const doc = (0, import_yaml9.parseDocument)((0, import_node_fs51.readFileSync)(sourcePath, "utf8"));
|
|
78129
78153
|
if (doc.errors.length > 0) {
|
|
78130
78154
|
throw new Error(`node bake: source is not valid YAML: ${doc.errors[0]?.message ?? "parse error"}`);
|
|
78131
78155
|
}
|
|
@@ -78134,12 +78158,12 @@ function bakeNodeConfigById(sourcePath, nodeId, patch2) {
|
|
|
78134
78158
|
const idx = items.findIndex((it) => ((0, import_yaml9.isMap)(it) ? it.toJSON() : null)?.id === nodeId);
|
|
78135
78159
|
if (idx < 0) throw new Error(`no node with id "${nodeId}"`);
|
|
78136
78160
|
for (const [key, value] of Object.entries(patch2)) doc.setIn(["nodes", idx, "config", key], value);
|
|
78137
|
-
(0,
|
|
78161
|
+
(0, import_node_fs51.writeFileSync)(sourcePath, doc.toString());
|
|
78138
78162
|
}
|
|
78139
78163
|
function writeViewer3dApp(dir, appId, scene) {
|
|
78140
|
-
(0,
|
|
78164
|
+
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78141
78165
|
const flo = (0, import_node_path44.join)(dir, `${appId}.flo`);
|
|
78142
|
-
(0,
|
|
78166
|
+
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78143
78167
|
`app: ${appId}`,
|
|
78144
78168
|
"version: 0.1.0",
|
|
78145
78169
|
"display-name: Steel 3D",
|
|
@@ -78162,18 +78186,18 @@ function writeViewer3dApp(dir, appId, scene) {
|
|
|
78162
78186
|
var COMPANION_MARKER = "# floless-companion: generated by FloLess \u2014 overwritten on every export";
|
|
78163
78187
|
function isCompanionApp(flo) {
|
|
78164
78188
|
try {
|
|
78165
|
-
return (0,
|
|
78189
|
+
return (0, import_node_fs51.readFileSync)(flo, "utf8").split(/\r?\n/, 1)[0]?.trim() === COMPANION_MARKER;
|
|
78166
78190
|
} catch (e) {
|
|
78167
78191
|
return e?.code === "ENOENT";
|
|
78168
78192
|
}
|
|
78169
78193
|
}
|
|
78170
78194
|
function writeBomReportApp(dir, appId, table) {
|
|
78171
|
-
(0,
|
|
78195
|
+
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78172
78196
|
const flo = (0, import_node_path44.join)(dir, `${appId}.flo`);
|
|
78173
78197
|
if (!isCompanionApp(flo)) {
|
|
78174
78198
|
throw new Error(`refusing to overwrite "${appId}": an app of that name exists and FloLess did not write it`);
|
|
78175
78199
|
}
|
|
78176
|
-
(0,
|
|
78200
|
+
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78177
78201
|
COMPANION_MARKER,
|
|
78178
78202
|
`app: ${appId}`,
|
|
78179
78203
|
"version: 0.1.0",
|
|
@@ -78200,9 +78224,9 @@ function writeBomReportApp(dir, appId, table) {
|
|
|
78200
78224
|
return flo;
|
|
78201
78225
|
}
|
|
78202
78226
|
function writeRevitApp(dir, appId, scene, hostPid, revitVersion = "2026") {
|
|
78203
|
-
(0,
|
|
78227
|
+
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78204
78228
|
const flo = (0, import_node_path44.join)(dir, `${appId}.flo`);
|
|
78205
|
-
(0,
|
|
78229
|
+
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78206
78230
|
`app: ${appId}`,
|
|
78207
78231
|
"version: 0.1.0",
|
|
78208
78232
|
"display-name: Steel to Revit",
|
|
@@ -78236,9 +78260,9 @@ function writeRevitApp(dir, appId, scene, hostPid, revitVersion = "2026") {
|
|
|
78236
78260
|
return flo;
|
|
78237
78261
|
}
|
|
78238
78262
|
function writeSketchupApp(dir, appId, scene) {
|
|
78239
|
-
(0,
|
|
78263
|
+
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78240
78264
|
const flo = (0, import_node_path44.join)(dir, `${appId}.flo`);
|
|
78241
|
-
(0,
|
|
78265
|
+
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78242
78266
|
`app: ${appId}`,
|
|
78243
78267
|
"version: 0.1.0",
|
|
78244
78268
|
"display-name: Steel to SketchUp",
|
|
@@ -78265,10 +78289,10 @@ function writeSketchupApp(dir, appId, scene) {
|
|
|
78265
78289
|
return flo;
|
|
78266
78290
|
}
|
|
78267
78291
|
function writeRhinoApp(dir, appId, scene, rhinoId, hostPid) {
|
|
78268
|
-
(0,
|
|
78292
|
+
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78269
78293
|
const flo = (0, import_node_path44.join)(dir, `${appId}.flo`);
|
|
78270
78294
|
const exactRhinoId = typeof rhinoId === "string" && rhinoId.trim() ? rhinoId.trim() : null;
|
|
78271
|
-
(0,
|
|
78295
|
+
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78272
78296
|
`app: ${appId}`,
|
|
78273
78297
|
"version: 0.1.0",
|
|
78274
78298
|
"display-name: Steel to Rhino",
|
|
@@ -78295,9 +78319,9 @@ function writeRhinoApp(dir, appId, scene, rhinoId, hostPid) {
|
|
|
78295
78319
|
return flo;
|
|
78296
78320
|
}
|
|
78297
78321
|
function writeTeklaApp(dir, appId, scene, teklaVersion = "2026.0") {
|
|
78298
|
-
(0,
|
|
78322
|
+
(0, import_node_fs51.mkdirSync)(dir, { recursive: true });
|
|
78299
78323
|
const flo = (0, import_node_path44.join)(dir, `${appId}.flo`);
|
|
78300
|
-
(0,
|
|
78324
|
+
(0, import_node_fs51.writeFileSync)(flo, [
|
|
78301
78325
|
`app: ${appId}`,
|
|
78302
78326
|
"version: 0.1.0",
|
|
78303
78327
|
"display-name: Steel to Tekla",
|
|
@@ -78461,7 +78485,7 @@ async function teklaVersionToBake() {
|
|
|
78461
78485
|
|
|
78462
78486
|
// export-companion.ts
|
|
78463
78487
|
var import_node_crypto30 = require("node:crypto");
|
|
78464
|
-
var
|
|
78488
|
+
var import_node_fs52 = require("node:fs");
|
|
78465
78489
|
var import_node_path45 = require("node:path");
|
|
78466
78490
|
var PREFIX = "floless-export-tmp-";
|
|
78467
78491
|
var LEASE = ".floless-export-lease.json";
|
|
@@ -78487,7 +78511,7 @@ function assertScratchPath(path, appsRoot) {
|
|
|
78487
78511
|
}
|
|
78488
78512
|
function removeScratch(path, appsRoot) {
|
|
78489
78513
|
assertScratchPath(path, appsRoot);
|
|
78490
|
-
(0,
|
|
78514
|
+
(0, import_node_fs52.rmSync)(path, { recursive: true, force: true });
|
|
78491
78515
|
}
|
|
78492
78516
|
function createExportCompanion(ownerId, sink, appsRoot = defaultAppsRoot()) {
|
|
78493
78517
|
const safeOwner = ownerId.replace(/[^a-z0-9._-]/gi, "-").slice(0, 80) || "app";
|
|
@@ -78500,10 +78524,10 @@ function createExportCompanion(ownerId, sink, appsRoot = defaultAppsRoot()) {
|
|
|
78500
78524
|
path,
|
|
78501
78525
|
token: token2,
|
|
78502
78526
|
cleanup: () => {
|
|
78503
|
-
if (!(0,
|
|
78527
|
+
if (!(0, import_node_fs52.existsSync)(path)) return;
|
|
78504
78528
|
let current = null;
|
|
78505
78529
|
try {
|
|
78506
|
-
current = JSON.parse((0,
|
|
78530
|
+
current = JSON.parse((0, import_node_fs52.readFileSync)((0, import_node_path45.resolve)(path, LEASE), "utf8"));
|
|
78507
78531
|
} catch {
|
|
78508
78532
|
}
|
|
78509
78533
|
if (current && current.token !== token2) throw new Error(`export companion lease changed for ${id}`);
|
|
@@ -78512,7 +78536,7 @@ function createExportCompanion(ownerId, sink, appsRoot = defaultAppsRoot()) {
|
|
|
78512
78536
|
};
|
|
78513
78537
|
}
|
|
78514
78538
|
function stampExportCompanionLease(companion2) {
|
|
78515
|
-
(0,
|
|
78539
|
+
(0, import_node_fs52.writeFileSync)((0, import_node_path45.resolve)(companion2.path, LEASE), JSON.stringify({
|
|
78516
78540
|
pid: process.pid,
|
|
78517
78541
|
token: companion2.token,
|
|
78518
78542
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -78520,19 +78544,19 @@ function stampExportCompanionLease(companion2) {
|
|
|
78520
78544
|
}
|
|
78521
78545
|
function sweepStaleExportCompanions(now = Date.now(), appsRoot = defaultAppsRoot()) {
|
|
78522
78546
|
const root5 = (0, import_node_path45.resolve)(appsRoot);
|
|
78523
|
-
if (!(0,
|
|
78547
|
+
if (!(0, import_node_fs52.existsSync)(root5)) return [];
|
|
78524
78548
|
const removed = [];
|
|
78525
|
-
for (const entry2 of (0,
|
|
78549
|
+
for (const entry2 of (0, import_node_fs52.readdirSync)(root5, { withFileTypes: true })) {
|
|
78526
78550
|
if (!entry2.isDirectory() || !entry2.name.startsWith(PREFIX)) continue;
|
|
78527
78551
|
const path = (0, import_node_path45.resolve)(root5, entry2.name);
|
|
78528
78552
|
let lease = null;
|
|
78529
78553
|
try {
|
|
78530
|
-
lease = JSON.parse((0,
|
|
78554
|
+
lease = JSON.parse((0, import_node_fs52.readFileSync)((0, import_node_path45.resolve)(path, LEASE), "utf8"));
|
|
78531
78555
|
} catch {
|
|
78532
78556
|
}
|
|
78533
78557
|
let created;
|
|
78534
78558
|
try {
|
|
78535
|
-
created = lease ? Date.parse(lease.createdAt) : (0,
|
|
78559
|
+
created = lease ? Date.parse(lease.createdAt) : (0, import_node_fs52.statSync)(path).mtimeMs;
|
|
78536
78560
|
} catch {
|
|
78537
78561
|
continue;
|
|
78538
78562
|
}
|
|
@@ -78560,7 +78584,7 @@ async function teklaReadiness(deps = DEFAULT_DEPS) {
|
|
|
78560
78584
|
}
|
|
78561
78585
|
async function teklaReadinessUnlocked(deps) {
|
|
78562
78586
|
const awareVersion = deps.npmVersion();
|
|
78563
|
-
const awareCurrent = !!awareVersion &&
|
|
78587
|
+
const awareCurrent = !!awareVersion && compareDotted(awareVersion, TEKLA_AWARE_FLOOR) >= 0;
|
|
78564
78588
|
const bridge = deps.bridgeStatus();
|
|
78565
78589
|
const bridgeCurrent = !!bridge.path && bridge.version === awareVersion;
|
|
78566
78590
|
const base = {
|
|
@@ -78880,7 +78904,7 @@ async function hostReadinessUnlocked(host, deps, targetPid) {
|
|
|
78880
78904
|
const label2 = HOST_LABELS[host];
|
|
78881
78905
|
const floor = HOST_BAKE_AWARE_FLOORS[host];
|
|
78882
78906
|
const awareVersion = deps.npmVersion();
|
|
78883
|
-
const awareCurrent = !!awareVersion &&
|
|
78907
|
+
const awareCurrent = !!awareVersion && compareDotted(awareVersion, floor) >= 0;
|
|
78884
78908
|
const bridge = deps.bridgeStatus(host);
|
|
78885
78909
|
const bridgeCurrent = !!bridge.path && bridge.version === awareVersion;
|
|
78886
78910
|
const base = {
|
|
@@ -79106,14 +79130,14 @@ function looksLikeHostUnavailable(host, ...messages) {
|
|
|
79106
79130
|
}
|
|
79107
79131
|
|
|
79108
79132
|
// render-readiness.ts
|
|
79109
|
-
var
|
|
79133
|
+
var import_node_fs53 = require("node:fs");
|
|
79110
79134
|
var import_node_path46 = require("node:path");
|
|
79111
79135
|
var import_node_os22 = require("node:os");
|
|
79112
79136
|
var RENDER_AWARE_FLOOR = "0.103.0";
|
|
79113
79137
|
var RENDER_AGENT_ID = "blender";
|
|
79114
79138
|
function isFile(path) {
|
|
79115
79139
|
try {
|
|
79116
|
-
return (0,
|
|
79140
|
+
return (0, import_node_fs53.existsSync)(path) && (0, import_node_fs53.statSync)(path).isFile();
|
|
79117
79141
|
} catch {
|
|
79118
79142
|
return false;
|
|
79119
79143
|
}
|
|
@@ -79147,7 +79171,7 @@ function windowsCandidates(env2) {
|
|
|
79147
79171
|
for (const root5 of roots) {
|
|
79148
79172
|
let entries2;
|
|
79149
79173
|
try {
|
|
79150
|
-
entries2 = (0,
|
|
79174
|
+
entries2 = (0, import_node_fs53.readdirSync)(root5);
|
|
79151
79175
|
} catch {
|
|
79152
79176
|
continue;
|
|
79153
79177
|
}
|
|
@@ -79197,7 +79221,7 @@ async function renderReadiness(deps = DEFAULT_DEPS4) {
|
|
|
79197
79221
|
async function renderReadinessUnlocked(deps) {
|
|
79198
79222
|
try {
|
|
79199
79223
|
const version = deps.npmVersion();
|
|
79200
|
-
const current = !!version &&
|
|
79224
|
+
const current = !!version && compareDotted(version, RENDER_AWARE_FLOOR) >= 0;
|
|
79201
79225
|
const base = {
|
|
79202
79226
|
aware: { version, floor: RENDER_AWARE_FLOOR, current },
|
|
79203
79227
|
agent: { installed: false },
|
|
@@ -79326,16 +79350,16 @@ function nothingToApprove(contract) {
|
|
|
79326
79350
|
}
|
|
79327
79351
|
|
|
79328
79352
|
// app-lifecycle.ts
|
|
79329
|
-
var
|
|
79353
|
+
var import_node_fs56 = require("node:fs");
|
|
79330
79354
|
var import_node_os24 = require("node:os");
|
|
79331
79355
|
var import_node_path49 = require("node:path");
|
|
79332
79356
|
|
|
79333
79357
|
// routines.ts
|
|
79334
|
-
var
|
|
79358
|
+
var import_node_fs55 = require("node:fs");
|
|
79335
79359
|
var import_node_path48 = require("node:path");
|
|
79336
79360
|
|
|
79337
79361
|
// trigger-sessions.ts
|
|
79338
|
-
var
|
|
79362
|
+
var import_node_fs54 = require("node:fs");
|
|
79339
79363
|
var import_node_os23 = require("node:os");
|
|
79340
79364
|
var import_node_path47 = require("node:path");
|
|
79341
79365
|
var import_yaml10 = __toESM(require_dist6(), 1);
|
|
@@ -79357,9 +79381,9 @@ function isHostBacked(agent, agentsDir = AGENTS_DIR2) {
|
|
|
79357
79381
|
const safe2 = (n) => !n.includes("/") && !n.includes("\\") && !n.includes("..");
|
|
79358
79382
|
if (!safe2(agent)) return false;
|
|
79359
79383
|
const manifestPath2 = (0, import_node_path47.join)(agentsDir, agent, "manifest.yaml");
|
|
79360
|
-
if (!(0,
|
|
79384
|
+
if (!(0, import_node_fs54.existsSync)(manifestPath2)) return false;
|
|
79361
79385
|
try {
|
|
79362
|
-
const doc = (0, import_yaml10.parse)((0,
|
|
79386
|
+
const doc = (0, import_yaml10.parse)((0, import_node_fs54.readFileSync)(manifestPath2, "utf8"));
|
|
79363
79387
|
const transport = doc?.transport;
|
|
79364
79388
|
return !!(transport && typeof transport === "object" && "cli" in transport);
|
|
79365
79389
|
} catch {
|
|
@@ -79703,10 +79727,10 @@ function sanitizeRoutine(raw) {
|
|
|
79703
79727
|
};
|
|
79704
79728
|
}
|
|
79705
79729
|
function loadFromDisk() {
|
|
79706
|
-
if (!(0,
|
|
79730
|
+
if (!(0, import_node_fs55.existsSync)(ROUTINES_FILE)) return [];
|
|
79707
79731
|
let text3;
|
|
79708
79732
|
try {
|
|
79709
|
-
text3 = (0,
|
|
79733
|
+
text3 = (0, import_node_fs55.readFileSync)(ROUTINES_FILE, "utf8");
|
|
79710
79734
|
} catch {
|
|
79711
79735
|
return [];
|
|
79712
79736
|
}
|
|
@@ -79715,17 +79739,17 @@ function loadFromDisk() {
|
|
|
79715
79739
|
return Array.isArray(parsed) ? parsed.map(sanitizeRoutine).filter((r) => r !== null) : [];
|
|
79716
79740
|
} catch {
|
|
79717
79741
|
try {
|
|
79718
|
-
(0,
|
|
79742
|
+
(0, import_node_fs55.renameSync)(ROUTINES_FILE, `${ROUTINES_FILE}.corrupt-${Date.now()}`);
|
|
79719
79743
|
} catch {
|
|
79720
79744
|
}
|
|
79721
79745
|
return [];
|
|
79722
79746
|
}
|
|
79723
79747
|
}
|
|
79724
79748
|
function saveRoutines() {
|
|
79725
|
-
if (!(0,
|
|
79749
|
+
if (!(0, import_node_fs55.existsSync)(flolessRoot)) (0, import_node_fs55.mkdirSync)(flolessRoot, { recursive: true });
|
|
79726
79750
|
const tmp = `${ROUTINES_FILE}.${process.pid}.tmp`;
|
|
79727
|
-
(0,
|
|
79728
|
-
(0,
|
|
79751
|
+
(0, import_node_fs55.writeFileSync)(tmp, JSON.stringify(routines, null, 2));
|
|
79752
|
+
(0, import_node_fs55.renameSync)(tmp, ROUTINES_FILE);
|
|
79729
79753
|
}
|
|
79730
79754
|
function listRoutines() {
|
|
79731
79755
|
ensureLoaded();
|
|
@@ -80151,7 +80175,7 @@ function appDirPath(id) {
|
|
|
80151
80175
|
return (0, import_node_path49.join)(appsDir(), id);
|
|
80152
80176
|
}
|
|
80153
80177
|
function appInstalled(id) {
|
|
80154
|
-
return APP_ID4.test(id) && (0,
|
|
80178
|
+
return APP_ID4.test(id) && (0, import_node_fs56.existsSync)(appDirPath(id));
|
|
80155
80179
|
}
|
|
80156
80180
|
function logCascade(what, e) {
|
|
80157
80181
|
console.error(`[app-lifecycle] cascade step failed (${what}):`, e instanceof Error ? e.message : e);
|
|
@@ -80389,7 +80413,7 @@ function isGatedAwareRoute(url, method) {
|
|
|
80389
80413
|
|
|
80390
80414
|
// autostart.mjs
|
|
80391
80415
|
var import_node_child_process8 = require("node:child_process");
|
|
80392
|
-
var
|
|
80416
|
+
var import_node_fs57 = require("node:fs");
|
|
80393
80417
|
var import_node_os25 = require("node:os");
|
|
80394
80418
|
var import_node_path50 = require("node:path");
|
|
80395
80419
|
|
|
@@ -80503,8 +80527,8 @@ function removeLegacyRunKey() {
|
|
|
80503
80527
|
}
|
|
80504
80528
|
function logLine(msg) {
|
|
80505
80529
|
try {
|
|
80506
|
-
(0,
|
|
80507
|
-
(0,
|
|
80530
|
+
(0, import_node_fs57.mkdirSync)(logDir(), { recursive: true });
|
|
80531
|
+
(0, import_node_fs57.appendFileSync)(logFilePath(), `${(/* @__PURE__ */ new Date()).toISOString()} ${msg}
|
|
80508
80532
|
`);
|
|
80509
80533
|
} catch {
|
|
80510
80534
|
}
|
|
@@ -80513,7 +80537,7 @@ function registerAutostart(exePath) {
|
|
|
80513
80537
|
if (!isWin) return;
|
|
80514
80538
|
const xml = buildAutostartTaskXml(exePath, currentUserId());
|
|
80515
80539
|
const tmp = (0, import_node_path50.join)((0, import_node_os25.tmpdir)(), `floless-autostart-${process.pid}-${Date.now()}.xml`);
|
|
80516
|
-
(0,
|
|
80540
|
+
(0, import_node_fs57.writeFileSync)(tmp, "\uFEFF" + xml, { encoding: "utf16le" });
|
|
80517
80541
|
try {
|
|
80518
80542
|
(0, import_node_child_process8.execFileSync)("schtasks", ["/Create", "/TN", TASK_NAME, "/XML", tmp, "/F"], {
|
|
80519
80543
|
stdio: ["ignore", "ignore", "ignore"],
|
|
@@ -80524,7 +80548,7 @@ function registerAutostart(exePath) {
|
|
|
80524
80548
|
throw err2;
|
|
80525
80549
|
} finally {
|
|
80526
80550
|
try {
|
|
80527
|
-
(0,
|
|
80551
|
+
(0, import_node_fs57.rmSync)(tmp, { force: true });
|
|
80528
80552
|
} catch {
|
|
80529
80553
|
}
|
|
80530
80554
|
}
|
|
@@ -80559,13 +80583,13 @@ function unregisterAutostart() {
|
|
|
80559
80583
|
// updater.ts
|
|
80560
80584
|
var import_node_child_process9 = require("node:child_process");
|
|
80561
80585
|
var import_node_crypto31 = require("node:crypto");
|
|
80562
|
-
var
|
|
80586
|
+
var import_node_fs59 = require("node:fs");
|
|
80563
80587
|
var import_node_stream3 = require("node:stream");
|
|
80564
80588
|
var import_promises5 = require("node:stream/promises");
|
|
80565
80589
|
var import_node_path52 = require("node:path");
|
|
80566
80590
|
|
|
80567
80591
|
// post-update-marker.mjs
|
|
80568
|
-
var
|
|
80592
|
+
var import_node_fs58 = require("node:fs");
|
|
80569
80593
|
var import_node_os26 = require("node:os");
|
|
80570
80594
|
var import_node_path51 = require("node:path");
|
|
80571
80595
|
var FRESH_MS = 12e4;
|
|
@@ -80588,7 +80612,7 @@ function writePostUpdateMarker() {
|
|
|
80588
80612
|
for (const p of [markerPath(), legacyMarkerPath()]) {
|
|
80589
80613
|
if (!p) continue;
|
|
80590
80614
|
try {
|
|
80591
|
-
(0,
|
|
80615
|
+
(0, import_node_fs58.writeFileSync)(p, (/* @__PURE__ */ new Date()).toISOString());
|
|
80592
80616
|
wrote = true;
|
|
80593
80617
|
} catch {
|
|
80594
80618
|
}
|
|
@@ -80600,9 +80624,9 @@ function consumePostUpdateMarker() {
|
|
|
80600
80624
|
for (const p of [markerPath(), legacyMarkerPath()]) {
|
|
80601
80625
|
if (!p) continue;
|
|
80602
80626
|
try {
|
|
80603
|
-
if (!(0,
|
|
80604
|
-
const ageMs = Date.now() - (0,
|
|
80605
|
-
(0,
|
|
80627
|
+
if (!(0, import_node_fs58.existsSync)(p)) continue;
|
|
80628
|
+
const ageMs = Date.now() - (0, import_node_fs58.statSync)(p).mtimeMs;
|
|
80629
|
+
(0, import_node_fs58.rmSync)(p, { force: true });
|
|
80606
80630
|
if (ageMs < FRESH_MS) fresh = true;
|
|
80607
80631
|
} catch {
|
|
80608
80632
|
}
|
|
@@ -80610,17 +80634,6 @@ function consumePostUpdateMarker() {
|
|
|
80610
80634
|
return fresh;
|
|
80611
80635
|
}
|
|
80612
80636
|
|
|
80613
|
-
// dotted-version.ts
|
|
80614
|
-
function versionGt(a, b) {
|
|
80615
|
-
const pa = a.split(".").map((n) => parseInt(n, 10) || 0);
|
|
80616
|
-
const pb = b.split(".").map((n) => parseInt(n, 10) || 0);
|
|
80617
|
-
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
80618
|
-
const d = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
80619
|
-
if (d !== 0) return d > 0;
|
|
80620
|
-
}
|
|
80621
|
-
return false;
|
|
80622
|
-
}
|
|
80623
|
-
|
|
80624
80637
|
// updater.ts
|
|
80625
80638
|
var CHANNEL = "win";
|
|
80626
80639
|
var FEED_TIMEOUT_MS = 15e3;
|
|
@@ -80727,22 +80740,22 @@ async function checkForUpdate() {
|
|
|
80727
80740
|
}
|
|
80728
80741
|
async function sha1OfFile(path) {
|
|
80729
80742
|
const hash2 = (0, import_node_crypto31.createHash)("sha1");
|
|
80730
|
-
await (0, import_promises5.pipeline)((0,
|
|
80743
|
+
await (0, import_promises5.pipeline)((0, import_node_fs59.createReadStream)(path), hash2);
|
|
80731
80744
|
return hash2.digest("hex").toUpperCase();
|
|
80732
80745
|
}
|
|
80733
80746
|
async function downloadPackage(asset) {
|
|
80734
80747
|
if (!NUPKG_NAME.test(asset.FileName)) throw new Error(`refusing suspicious package name: ${asset.FileName}`);
|
|
80735
80748
|
const want = asset.SHA1.toUpperCase();
|
|
80736
80749
|
const dir = packagesDir();
|
|
80737
|
-
(0,
|
|
80750
|
+
(0, import_node_fs59.mkdirSync)(dir, { recursive: true });
|
|
80738
80751
|
const dest = (0, import_node_path52.join)(dir, asset.FileName);
|
|
80739
|
-
if ((0,
|
|
80752
|
+
if ((0, import_node_fs59.existsSync)(dest) && await sha1OfFile(dest) === want) return dest;
|
|
80740
80753
|
const res = await authedFetch(`${feedUrl()}/${encodeURIComponent(asset.FileName)}`, {
|
|
80741
80754
|
redirect: "follow",
|
|
80742
80755
|
signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS)
|
|
80743
80756
|
});
|
|
80744
80757
|
if (!res.ok || !res.body) throw new Error(`download failed: HTTP ${res.status} for ${asset.FileName}`);
|
|
80745
|
-
await (0, import_promises5.pipeline)(import_node_stream3.Readable.fromWeb(res.body), (0,
|
|
80758
|
+
await (0, import_promises5.pipeline)(import_node_stream3.Readable.fromWeb(res.body), (0, import_node_fs59.createWriteStream)(dest));
|
|
80746
80759
|
const got = await sha1OfFile(dest);
|
|
80747
80760
|
if (got !== want) throw new Error(`SHA1 mismatch for ${asset.FileName}: feed=${want} got=${got}`);
|
|
80748
80761
|
return dest;
|
|
@@ -80751,7 +80764,7 @@ async function applyUpdate(check, opts) {
|
|
|
80751
80764
|
if (!check.supported) return { applied: false, message: check.reason ?? "auto-update not supported in this runtime" };
|
|
80752
80765
|
if (!check.updateAvailable || !check.asset) return { applied: false, message: check.reason ?? "no update available" };
|
|
80753
80766
|
const exe = updateExePath();
|
|
80754
|
-
if (!(0,
|
|
80767
|
+
if (!(0, import_node_fs59.existsSync)(exe)) {
|
|
80755
80768
|
return { applied: false, message: `Update.exe not found at ${exe} \u2014 is this a Velopack install?` };
|
|
80756
80769
|
}
|
|
80757
80770
|
const pkg = await downloadPackage(check.asset);
|
|
@@ -80993,7 +81006,7 @@ function isTraceCorrupt(events) {
|
|
|
80993
81006
|
var import_node_child_process10 = require("node:child_process");
|
|
80994
81007
|
var import_node_path53 = require("node:path");
|
|
80995
81008
|
var import_node_url3 = require("node:url");
|
|
80996
|
-
var
|
|
81009
|
+
var import_node_fs60 = require("node:fs");
|
|
80997
81010
|
var import_node_http = __toESM(require("node:http"), 1);
|
|
80998
81011
|
var import_node_readline = require("node:readline");
|
|
80999
81012
|
var __dirname2 = (0, import_node_path53.dirname)((0, import_node_url3.fileURLToPath)(__import_meta_url));
|
|
@@ -81075,7 +81088,7 @@ function resolveServerStart() {
|
|
|
81075
81088
|
const packaged = /flolessapp\.exe$/i.test(process.execPath);
|
|
81076
81089
|
if (packaged) return { cmd: process.execPath, args: ["--serve"], shell: false };
|
|
81077
81090
|
const bundle = (0, import_node_path53.join)(__dirname2, "dist", "floless-server.cjs");
|
|
81078
|
-
if ((0,
|
|
81091
|
+
if ((0, import_node_fs60.existsSync)(bundle)) return { cmd: process.execPath, args: [bundle, "--serve"], shell: false };
|
|
81079
81092
|
return { cmd: "npm", args: ["run", "start"], shell: isWin2 };
|
|
81080
81093
|
}
|
|
81081
81094
|
function startServerDetached() {
|
|
@@ -82686,8 +82699,52 @@ function registerAwareUpdateRoutes(app, manager) {
|
|
|
82686
82699
|
);
|
|
82687
82700
|
}
|
|
82688
82701
|
|
|
82702
|
+
// debug-node-route.ts
|
|
82703
|
+
function resolveArgs(configArgs, inputs) {
|
|
82704
|
+
const out = {};
|
|
82705
|
+
for (const [k, v] of Object.entries(configArgs)) {
|
|
82706
|
+
if (typeof v === "string") {
|
|
82707
|
+
const m = v.match(/^\{\{\s*inputs\.([A-Za-z0-9._-]+)\s*\}\}$/);
|
|
82708
|
+
out[k] = m && m[1] != null && m[1] in inputs ? inputs[m[1]] : v;
|
|
82709
|
+
} else {
|
|
82710
|
+
out[k] = v;
|
|
82711
|
+
}
|
|
82712
|
+
}
|
|
82713
|
+
return out;
|
|
82714
|
+
}
|
|
82715
|
+
function registerDebugNodeRoute(app, deps) {
|
|
82716
|
+
app.post(
|
|
82717
|
+
"/api/debug-node",
|
|
82718
|
+
async (req, reply) => {
|
|
82719
|
+
const { id, nodeId, inputs } = req.body ?? {};
|
|
82720
|
+
if (!id || !nodeId) return reply.status(400).send({ ok: false, error: "id and nodeId required" });
|
|
82721
|
+
const appData = deps.readApp(id);
|
|
82722
|
+
if (!appData.runnable) return reply.status(409).send({ ok: false, error: "app not runnable \u2014 compile the lock first" });
|
|
82723
|
+
const node = appData.nodes.find((n) => n.id === nodeId);
|
|
82724
|
+
if (!node) return reply.status(404).send({ ok: false, error: `node not found: ${nodeId}` });
|
|
82725
|
+
const code = node.config?.code;
|
|
82726
|
+
if (typeof code !== "string") return reply.status(400).send({ ok: false, error: `node ${nodeId} has no exec code` });
|
|
82727
|
+
const version = typeof node.config?.version === "string" ? node.config.version : void 0;
|
|
82728
|
+
const configArgs = node.config?.args ?? {};
|
|
82729
|
+
const effectiveInputs = {};
|
|
82730
|
+
for (const inp of appData.inputs) {
|
|
82731
|
+
const d = inp.default;
|
|
82732
|
+
if (typeof d === "string" || typeof d === "number" || typeof d === "boolean") effectiveInputs[inp.name] = d;
|
|
82733
|
+
}
|
|
82734
|
+
Object.assign(effectiveInputs, inputs ?? {});
|
|
82735
|
+
const args = resolveArgs(configArgs, effectiveInputs);
|
|
82736
|
+
deps.broadcast({ type: "debug-started", id, nodeId });
|
|
82737
|
+
const result = await deps.execTekla(code, { version, args, debug: true });
|
|
82738
|
+
deps.broadcast({ type: "debug-ended", id, nodeId });
|
|
82739
|
+
const r = result.result ?? {};
|
|
82740
|
+
const html = typeof r.html === "string" ? r.html : null;
|
|
82741
|
+
return { ok: true, result, report: withBadge(html ? { nodeId, html } : null) };
|
|
82742
|
+
}
|
|
82743
|
+
);
|
|
82744
|
+
}
|
|
82745
|
+
|
|
82689
82746
|
// skill-sync.ts
|
|
82690
|
-
var
|
|
82747
|
+
var import_node_fs61 = require("node:fs");
|
|
82691
82748
|
var import_node_os27 = require("node:os");
|
|
82692
82749
|
var import_node_path56 = require("node:path");
|
|
82693
82750
|
var import_node_url4 = require("node:url");
|
|
@@ -82743,7 +82800,7 @@ function bundledSkillsRoot() {
|
|
|
82743
82800
|
(0, import_node_path56.join)((0, import_node_path56.dirname)(process.execPath), "skills"),
|
|
82744
82801
|
(0, import_node_path56.join)(__dirname3, "..", ".claude", "skills")
|
|
82745
82802
|
];
|
|
82746
|
-
return candidates.find((p) => (0,
|
|
82803
|
+
return candidates.find((p) => (0, import_node_fs61.existsSync)(p)) ?? null;
|
|
82747
82804
|
}
|
|
82748
82805
|
function targetConfigDirs() {
|
|
82749
82806
|
const override = process.env.FLOLESS_SKILL_TARGETS;
|
|
@@ -82759,7 +82816,7 @@ function targetConfigDirs() {
|
|
|
82759
82816
|
}
|
|
82760
82817
|
function skillVersion(skillMdPath) {
|
|
82761
82818
|
try {
|
|
82762
|
-
const text3 = (0,
|
|
82819
|
+
const text3 = (0, import_node_fs61.readFileSync)(skillMdPath, "utf8");
|
|
82763
82820
|
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text3);
|
|
82764
82821
|
if (!m || m[1] === void 0) return null;
|
|
82765
82822
|
const fm = (0, import_yaml11.parse)(m[1]);
|
|
@@ -82799,7 +82856,7 @@ function decideAction(installed, bundled) {
|
|
|
82799
82856
|
function bundledSkills(root5) {
|
|
82800
82857
|
let entries2 = [];
|
|
82801
82858
|
try {
|
|
82802
|
-
entries2 = selectShippedSkillNames((0,
|
|
82859
|
+
entries2 = selectShippedSkillNames((0, import_node_fs61.readdirSync)(root5));
|
|
82803
82860
|
} catch {
|
|
82804
82861
|
return [];
|
|
82805
82862
|
}
|
|
@@ -82808,7 +82865,7 @@ function bundledSkills(root5) {
|
|
|
82808
82865
|
const dir = (0, import_node_path56.join)(root5, name);
|
|
82809
82866
|
let isDir = false;
|
|
82810
82867
|
try {
|
|
82811
|
-
isDir = (0,
|
|
82868
|
+
isDir = (0, import_node_fs61.statSync)(dir).isDirectory();
|
|
82812
82869
|
} catch {
|
|
82813
82870
|
isDir = false;
|
|
82814
82871
|
}
|
|
@@ -82826,17 +82883,17 @@ function syncSkills() {
|
|
|
82826
82883
|
const skills = bundledSkills(root5);
|
|
82827
82884
|
if (!skills.length) return results;
|
|
82828
82885
|
for (const { runtime, dir: cfg } of targetConfigDirs()) {
|
|
82829
|
-
if (!(0,
|
|
82886
|
+
if (!(0, import_node_fs61.existsSync)(cfg)) continue;
|
|
82830
82887
|
const skillsDir = (0, import_node_path56.join)(cfg, "skills");
|
|
82831
82888
|
for (const s of skills) {
|
|
82832
82889
|
const dest = (0, import_node_path56.join)(skillsDir, s.name);
|
|
82833
82890
|
const installedMd = (0, import_node_path56.join)(dest, "SKILL.md");
|
|
82834
|
-
const installed = (0,
|
|
82891
|
+
const installed = (0, import_node_fs61.existsSync)(installedMd) ? skillVersion(installedMd) : null;
|
|
82835
82892
|
const action = decideAction(installed, s.version);
|
|
82836
82893
|
if (action === "installed" || action === "updated") {
|
|
82837
82894
|
try {
|
|
82838
|
-
if (action === "updated") (0,
|
|
82839
|
-
(0,
|
|
82895
|
+
if (action === "updated") (0, import_node_fs61.rmSync)(dest, { recursive: true, force: true });
|
|
82896
|
+
(0, import_node_fs61.cpSync)(s.dir, dest, { recursive: true });
|
|
82840
82897
|
results.push({ runtime, skill: s.name, action, from: installed, to: s.version });
|
|
82841
82898
|
} catch {
|
|
82842
82899
|
}
|
|
@@ -82851,7 +82908,7 @@ function syncSkills() {
|
|
|
82851
82908
|
// watch.ts
|
|
82852
82909
|
var import_node_os28 = require("node:os");
|
|
82853
82910
|
var import_node_path58 = require("node:path");
|
|
82854
|
-
var
|
|
82911
|
+
var import_node_fs62 = require("node:fs");
|
|
82855
82912
|
|
|
82856
82913
|
// node_modules/chokidar/esm/index.js
|
|
82857
82914
|
var import_fs2 = require("fs");
|
|
@@ -84564,20 +84621,20 @@ function underDir(path, dir) {
|
|
|
84564
84621
|
function startWatcher() {
|
|
84565
84622
|
const awareDir = process.env.AWARE_HOME ?? (0, import_node_path58.join)((0, import_node_os28.homedir)(), ".aware");
|
|
84566
84623
|
const credentialsDir = (0, import_node_path58.join)(awareDir, "credentials");
|
|
84567
|
-
if (!(0,
|
|
84624
|
+
if (!(0, import_node_fs62.existsSync)(credentialsDir)) {
|
|
84568
84625
|
try {
|
|
84569
|
-
(0,
|
|
84626
|
+
(0, import_node_fs62.mkdirSync)(credentialsDir, { recursive: true });
|
|
84570
84627
|
} catch {
|
|
84571
84628
|
}
|
|
84572
84629
|
}
|
|
84573
|
-
if (!(0,
|
|
84630
|
+
if (!(0, import_node_fs62.existsSync)(uiDir)) {
|
|
84574
84631
|
try {
|
|
84575
|
-
(0,
|
|
84632
|
+
(0, import_node_fs62.mkdirSync)(uiDir, { recursive: true });
|
|
84576
84633
|
} catch {
|
|
84577
84634
|
}
|
|
84578
84635
|
}
|
|
84579
|
-
const targets = ["apps", "logs", "credentials"].map((d) => (0, import_node_path58.join)(awareDir, d)).filter((p) => (0,
|
|
84580
|
-
if ((0,
|
|
84636
|
+
const targets = ["apps", "logs", "credentials"].map((d) => (0, import_node_path58.join)(awareDir, d)).filter((p) => (0, import_node_fs62.existsSync)(p));
|
|
84637
|
+
if ((0, import_node_fs62.existsSync)(uiDir)) targets.push(uiDir);
|
|
84581
84638
|
if (targets.length === 0) {
|
|
84582
84639
|
return null;
|
|
84583
84640
|
}
|
|
@@ -84606,11 +84663,11 @@ function startWatcher() {
|
|
|
84606
84663
|
const isCredential = path.split(/[\\/]/).includes("credentials");
|
|
84607
84664
|
const kind = isCredential ? "credential" : path.endsWith(".jsonl") ? "trace" : path.endsWith(".lock") ? "lock" : path.endsWith(".flo") || path.endsWith(".app") ? "source" : "file";
|
|
84608
84665
|
broadcast({ type: "fs-change", kind, event, path });
|
|
84609
|
-
if (kind === "trace" && event !== "unlink" && (0,
|
|
84666
|
+
if (kind === "trace" && event !== "unlink" && (0, import_node_fs62.existsSync)(path)) {
|
|
84610
84667
|
const id = appIdFromLogPath(path);
|
|
84611
84668
|
if (!id) return;
|
|
84612
84669
|
try {
|
|
84613
|
-
broadcast({ type: "trace-file", id, runId: path.split(import_node_path58.sep).pop()?.replace(/\.jsonl$/, "") ?? null, events: parseTrace((0,
|
|
84670
|
+
broadcast({ type: "trace-file", id, runId: path.split(import_node_path58.sep).pop()?.replace(/\.jsonl$/, "") ?? null, events: parseTrace((0, import_node_fs62.readFileSync)(path, "utf8")) });
|
|
84614
84671
|
} catch {
|
|
84615
84672
|
}
|
|
84616
84673
|
}
|
|
@@ -84621,7 +84678,7 @@ function startWatcher() {
|
|
|
84621
84678
|
// index.ts
|
|
84622
84679
|
var __dirname4 = (0, import_node_path59.dirname)((0, import_node_url5.fileURLToPath)(__import_meta_url));
|
|
84623
84680
|
var WEB_ROOT = [(0, import_node_path59.join)(__dirname4, "web"), (0, import_node_path59.join)((0, import_node_path59.dirname)(process.execPath), "web"), (0, import_node_path59.join)(__dirname4, "..", "web")].find(
|
|
84624
|
-
(p) => (0,
|
|
84681
|
+
(p) => (0, import_node_fs63.existsSync)(p)
|
|
84625
84682
|
) ?? (0, import_node_path59.join)(__dirname4, "..", "web");
|
|
84626
84683
|
var PORT2 = Number(process.env.PORT ?? 4317);
|
|
84627
84684
|
var HOST = "127.0.0.1";
|
|
@@ -84638,7 +84695,7 @@ function installCrashHandlers() {
|
|
|
84638
84695
|
${stack}
|
|
84639
84696
|
`;
|
|
84640
84697
|
try {
|
|
84641
|
-
(0,
|
|
84698
|
+
(0, import_node_fs63.appendFileSync)(logFilePath(), line);
|
|
84642
84699
|
} catch {
|
|
84643
84700
|
}
|
|
84644
84701
|
if (process.stderr.isTTY) process.stderr.write(line);
|
|
@@ -84992,6 +85049,12 @@ async function startServer() {
|
|
|
84992
85049
|
if (err2 instanceof AppNotFoundError) {
|
|
84993
85050
|
return reply.status(404).send({ ok: false, error: err2.message });
|
|
84994
85051
|
}
|
|
85052
|
+
if (err2 instanceof RecoveryPendingError) {
|
|
85053
|
+
return replyRecoveryPendingError(err2, req, reply);
|
|
85054
|
+
}
|
|
85055
|
+
if (err2 instanceof WorkspaceSnapshotError) {
|
|
85056
|
+
return reply.status(err2.status).send({ ok: false, error: err2.message });
|
|
85057
|
+
}
|
|
84995
85058
|
if (err2 instanceof ContractPolicyError) {
|
|
84996
85059
|
return replyContractPolicyError(err2, req, reply);
|
|
84997
85060
|
}
|
|
@@ -85140,7 +85203,7 @@ async function startServer() {
|
|
|
85140
85203
|
if (!html) return reply.status(400).send({ ok: false, error: "html is required" });
|
|
85141
85204
|
if (b.kind === "model-3d") {
|
|
85142
85205
|
const installed = aware.npmVersion();
|
|
85143
|
-
if (!installed ||
|
|
85206
|
+
if (!installed || compareDotted(installed, SHARE_3D_AWARE_FLOOR) < 0) {
|
|
85144
85207
|
return reply.status(409).send({
|
|
85145
85208
|
ok: false,
|
|
85146
85209
|
error: "aware_too_old",
|
|
@@ -85288,10 +85351,10 @@ async function startServer() {
|
|
|
85288
85351
|
const bdir = backupDir(id, fromVersion, Date.now());
|
|
85289
85352
|
let backedUp = false;
|
|
85290
85353
|
try {
|
|
85291
|
-
(0,
|
|
85292
|
-
(0,
|
|
85354
|
+
(0, import_node_fs63.mkdirSync)((0, import_node_path59.dirname)(bdir), { recursive: true });
|
|
85355
|
+
(0, import_node_fs63.cpSync)(appDirPath2, bdir, { recursive: true });
|
|
85293
85356
|
backedUp = true;
|
|
85294
|
-
(0,
|
|
85357
|
+
(0, import_node_fs63.cpSync)(templatePath, srcPath);
|
|
85295
85358
|
if (id !== templateId) stampSourceAppId(srcPath, id);
|
|
85296
85359
|
if (contract != null) {
|
|
85297
85360
|
bakeContractIntoApp(srcPath, contract);
|
|
@@ -85305,8 +85368,8 @@ async function startServer() {
|
|
|
85305
85368
|
throw new TemplateSwapError(`${verb} failed before any change was made (${msg}) \u2014 the workflow is untouched`, `${verb}-not-started`);
|
|
85306
85369
|
}
|
|
85307
85370
|
try {
|
|
85308
|
-
(0,
|
|
85309
|
-
(0,
|
|
85371
|
+
(0, import_node_fs63.rmSync)(appDirPath2, { recursive: true, force: true });
|
|
85372
|
+
(0, import_node_fs63.cpSync)(bdir, appDirPath2, { recursive: true });
|
|
85310
85373
|
} catch (re) {
|
|
85311
85374
|
const rmsg = re instanceof Error ? re.message : String(re);
|
|
85312
85375
|
throw new TemplateSwapError(`${verb} failed (${msg}) AND rollback failed (${rmsg}) \u2014 restore manually from ${bdir}`, "rollback-failed", bdir);
|
|
@@ -85318,7 +85381,7 @@ async function startServer() {
|
|
|
85318
85381
|
function readSwapContract(id, verb) {
|
|
85319
85382
|
const gerund = verb === "update" ? "updating" : "restoring";
|
|
85320
85383
|
const contract = readAcceptedForRequest(id, void 0);
|
|
85321
|
-
if (contract == null && (0,
|
|
85384
|
+
if (contract == null && (0, import_node_fs63.existsSync)(contractPath(id))) {
|
|
85322
85385
|
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" } };
|
|
85323
85386
|
}
|
|
85324
85387
|
if (contract != null && !validateContract(contract).valid) {
|
|
@@ -85346,7 +85409,7 @@ async function startServer() {
|
|
|
85346
85409
|
} catch {
|
|
85347
85410
|
return reply.status(404).send({ ok: false, error: `"${id}" is not installed`, code: "not-installed" });
|
|
85348
85411
|
}
|
|
85349
|
-
if (
|
|
85412
|
+
if (compareDotted(t.version, fromVersion) <= 0) {
|
|
85350
85413
|
return reply.status(409).send({ ok: false, error: `"${id}" is already at ${fromVersion}`, code: "up-to-date" });
|
|
85351
85414
|
}
|
|
85352
85415
|
const preflight = readSwapContract(id, "update");
|
|
@@ -85643,7 +85706,7 @@ async function startServer() {
|
|
|
85643
85706
|
}
|
|
85644
85707
|
let data;
|
|
85645
85708
|
try {
|
|
85646
|
-
data = (0,
|
|
85709
|
+
data = (0, import_node_fs63.readFileSync)(thumb.path);
|
|
85647
85710
|
} catch {
|
|
85648
85711
|
return reply.status(404).send({ ok: false, error: "no thumbnail" });
|
|
85649
85712
|
}
|
|
@@ -85900,13 +85963,7 @@ async function startServer() {
|
|
|
85900
85963
|
const publicationIdentity = saved.publicationIdentity;
|
|
85901
85964
|
let manifest = ensureWorkingRevisionManifest({ project, publicationIdentity, contract: current, workingBase: saved.base });
|
|
85902
85965
|
if (manifest.draftHash !== contractHash(current)) manifest = refreshWorkingDraftHash({ project, expectedEpoch: manifest.epoch, expectedDraftHash: manifest.draftHash, contract: current });
|
|
85903
|
-
const latest = (
|
|
85904
|
-
try {
|
|
85905
|
-
return currentApprovedSnapshot(project.id);
|
|
85906
|
-
} catch {
|
|
85907
|
-
return null;
|
|
85908
|
-
}
|
|
85909
|
-
})();
|
|
85966
|
+
const latest = approvedSnapshotForMetadata(project.id, "resuming saved work");
|
|
85910
85967
|
if (!latest || contractHash(current) !== latest.contractHash) captureProjectCheckpoint({ project, publicationIdentity, base: manifest.workingBase, contract: current, revisionEpoch: manifest.epoch });
|
|
85911
85968
|
try {
|
|
85912
85969
|
await writeContractChecked(project.app, saved.contract, project.id, { origin: "internal", why: "resume an explicitly selected saved-work checkpoint" });
|
|
@@ -85932,11 +85989,7 @@ async function startServer() {
|
|
|
85932
85989
|
const project = getProject(req.params.id);
|
|
85933
85990
|
if (!project) return reply.status(404).send({ ok: false, error: `unknown project: ${req.params.id}` });
|
|
85934
85991
|
return withLifecycleLock("project", project.id, () => {
|
|
85935
|
-
|
|
85936
|
-
try {
|
|
85937
|
-
latest = currentApprovedSnapshot(project.id);
|
|
85938
|
-
} catch {
|
|
85939
|
-
}
|
|
85992
|
+
const latest = approvedSnapshotForMetadata(project.id, "listing export sources");
|
|
85940
85993
|
return {
|
|
85941
85994
|
ok: true,
|
|
85942
85995
|
default: latest ? { kind: "latest-approved", version: latest.version.n, hash: latest.contractHash } : null,
|
|
@@ -85971,6 +86024,7 @@ async function startServer() {
|
|
|
85971
86024
|
} catch {
|
|
85972
86025
|
}
|
|
85973
86026
|
}
|
|
86027
|
+
if (error instanceof RecoveryPendingError || error instanceof LifecycleLockBusyError) throw error;
|
|
85974
86028
|
return reply.status(409).send({ ok: false, error: error instanceof Error ? error.message : "could not capture export source" });
|
|
85975
86029
|
}
|
|
85976
86030
|
});
|
|
@@ -86032,7 +86086,6 @@ async function startServer() {
|
|
|
86032
86086
|
broadcast(contractChangedWithReason(project.app, project.id, "rollback"));
|
|
86033
86087
|
return { ok: true, version: listVersions(project.id).find((v) => v.n === res.versionN) ?? null };
|
|
86034
86088
|
} catch (e) {
|
|
86035
|
-
if (e instanceof RecoveryPendingError) return reply.status(409).send({ ok: false, error: e.message, code: e.code });
|
|
86036
86089
|
if (e instanceof ContractTransactionError) return reply.status(409).send({ ok: false, error: e.message, code: e.code });
|
|
86037
86090
|
throw e;
|
|
86038
86091
|
}
|
|
@@ -86163,8 +86216,8 @@ async function startServer() {
|
|
|
86163
86216
|
if (bad) return reply.status(404).send({ ok: false, error: bad });
|
|
86164
86217
|
const safe2 = req.params.sheet.replace(/[^A-Za-z0-9._-]/g, "");
|
|
86165
86218
|
const file = (0, import_node_path59.join)((0, import_node_path59.dirname)(contractPath(req.params.appId, project)), "details", `${safe2}.svg`);
|
|
86166
|
-
if (!(0,
|
|
86167
|
-
return reply.type("image/svg+xml").send((0,
|
|
86219
|
+
if (!(0, import_node_fs63.existsSync)(file)) return reply.status(404).send({ ok: false, error: "no vector for this sheet" });
|
|
86220
|
+
return reply.type("image/svg+xml").send((0, import_node_fs63.readFileSync)(file, "utf8"));
|
|
86168
86221
|
}
|
|
86169
86222
|
);
|
|
86170
86223
|
app.put(
|
|
@@ -86653,7 +86706,7 @@ async function startServer() {
|
|
|
86653
86706
|
}
|
|
86654
86707
|
const statedAt = (filename) => {
|
|
86655
86708
|
try {
|
|
86656
|
-
const st = (0,
|
|
86709
|
+
const st = (0, import_node_fs63.statSync)((0, import_node_path59.join)(dir, filename));
|
|
86657
86710
|
return st.isFile() ? st.mtime.toISOString() : null;
|
|
86658
86711
|
} catch {
|
|
86659
86712
|
return null;
|
|
@@ -86682,7 +86735,7 @@ async function startServer() {
|
|
|
86682
86735
|
const project = req.query.project || void 0;
|
|
86683
86736
|
if (req.query.for === "share") {
|
|
86684
86737
|
const installed = aware.npmVersion();
|
|
86685
|
-
if (!installed ||
|
|
86738
|
+
if (!installed || compareDotted(installed, SHARE_3D_AWARE_FLOOR) < 0) {
|
|
86686
86739
|
return reply.status(409).send({
|
|
86687
86740
|
ok: false,
|
|
86688
86741
|
error: "aware_too_old",
|
|
@@ -86706,6 +86759,7 @@ async function startServer() {
|
|
|
86706
86759
|
}
|
|
86707
86760
|
} catch (error) {
|
|
86708
86761
|
if (error instanceof WorkspaceSnapshotError) return reply.status(error.status).send({ ok: false, error: error.message });
|
|
86762
|
+
if (error instanceof RecoveryPendingError) throw error;
|
|
86709
86763
|
return reply.status(409).send({ ok: false, error: error instanceof Error ? error.message : "the selected export source is unavailable" });
|
|
86710
86764
|
}
|
|
86711
86765
|
}
|
|
@@ -86825,10 +86879,10 @@ async function startServer() {
|
|
|
86825
86879
|
scene,
|
|
86826
86880
|
"output-path": tempPath
|
|
86827
86881
|
});
|
|
86828
|
-
if (!(0,
|
|
86882
|
+
if (!(0, import_node_fs63.existsSync)(tempPath) || (0, import_node_fs63.statSync)(tempPath).size === 0) {
|
|
86829
86883
|
throw new ReceiptReconciliationError("AWARE reported a successful export but wrote no IFC file.");
|
|
86830
86884
|
}
|
|
86831
|
-
const artifactBytes = (0,
|
|
86885
|
+
const artifactBytes = (0, import_node_fs63.readFileSync)(tempPath);
|
|
86832
86886
|
const receipt = reconcileIfcExportReceipt(scene, rawReceipt, producerUnsupported, {
|
|
86833
86887
|
index: parseStepData(artifactBytes),
|
|
86834
86888
|
bytes: artifactBytes
|
|
@@ -86884,7 +86938,7 @@ async function startServer() {
|
|
|
86884
86938
|
ok: false,
|
|
86885
86939
|
error: awareFailureMessage(error, "IFC export failed"),
|
|
86886
86940
|
...reason ? { reason } : {},
|
|
86887
|
-
preservedPrevious: project && priorProjectIfc ? receiptHasFile(project, priorProjectIfc) : (0,
|
|
86941
|
+
preservedPrevious: project && priorProjectIfc ? receiptHasFile(project, priorProjectIfc) : (0, import_node_fs63.existsSync)(finalPath)
|
|
86888
86942
|
});
|
|
86889
86943
|
} finally {
|
|
86890
86944
|
cleanupIfcTemp(tempPath);
|
|
@@ -86913,9 +86967,12 @@ async function startServer() {
|
|
|
86913
86967
|
try {
|
|
86914
86968
|
snapshot = currentApprovedSnapshot(project);
|
|
86915
86969
|
} catch (error) {
|
|
86916
|
-
if (error instanceof
|
|
86970
|
+
if (error instanceof NoApprovedVersionError) {
|
|
86917
86971
|
return reply.status(404).send({ ok: false, error: "nothing rendered for the approved version" });
|
|
86918
86972
|
}
|
|
86973
|
+
if (error instanceof WorkspaceSnapshotError) {
|
|
86974
|
+
return reply.status(error.status).send({ ok: false, error: error.message });
|
|
86975
|
+
}
|
|
86919
86976
|
throw error;
|
|
86920
86977
|
}
|
|
86921
86978
|
const stills = matchingProjectExportReceipts(
|
|
@@ -86928,10 +86985,10 @@ async function startServer() {
|
|
|
86928
86985
|
const receipt = wanted ? stills.find((row) => row.variant === wanted) : [...stills].sort((a, b) => b.exportedAt.localeCompare(a.exportedAt))[0];
|
|
86929
86986
|
if (!receipt) return reply.status(404).send({ ok: false, error: "nothing rendered yet" });
|
|
86930
86987
|
const path = resolveProjectExportReceiptPath(project, receipt);
|
|
86931
|
-
if (!path || !(0,
|
|
86988
|
+
if (!path || !(0, import_node_fs63.existsSync)(path)) {
|
|
86932
86989
|
return reply.status(404).send({ ok: false, error: "the rendered image is no longer on disk" });
|
|
86933
86990
|
}
|
|
86934
|
-
return reply.header("content-type", "image/png").header("cache-control", "private, max-age=31536000, immutable").send((0,
|
|
86991
|
+
return reply.header("content-type", "image/png").header("cache-control", "private, max-age=31536000, immutable").send((0, import_node_fs63.readFileSync)(path));
|
|
86935
86992
|
});
|
|
86936
86993
|
const RENDER_VIEWPOINTS = /* @__PURE__ */ new Set(["hero", "iso", "front", "back", "left", "right", "top"]);
|
|
86937
86994
|
app.post("/api/contract/:appId/render", async (req, reply) => {
|
|
@@ -86975,6 +87032,7 @@ async function startServer() {
|
|
|
86975
87032
|
if (error instanceof WorkspaceSnapshotError) {
|
|
86976
87033
|
return reply.status(error.status).send({ ok: false, error: error.message });
|
|
86977
87034
|
}
|
|
87035
|
+
if (error instanceof RecoveryPendingError) throw error;
|
|
86978
87036
|
return reply.status(409).send({ ok: false, error: error instanceof Error ? error.message : "the selected export source is unavailable" });
|
|
86979
87037
|
}
|
|
86980
87038
|
const steel = acceptSteelForRoute(projectSnapshot.contract, { appId, projectId: project }, "stored", "v1-or-v2");
|
|
@@ -86991,7 +87049,7 @@ async function startServer() {
|
|
|
86991
87049
|
}
|
|
86992
87050
|
const kind = output === "turntable" ? "render-mp4" : "render-png";
|
|
86993
87051
|
const extension = output === "turntable" ? ".mp4" : ".png";
|
|
86994
|
-
const scratch = (0,
|
|
87052
|
+
const scratch = (0, import_node_fs63.mkdtempSync)((0, import_node_path59.join)((0, import_node_os29.tmpdir)(), "floless-render-"));
|
|
86995
87053
|
const ifcPath = (0, import_node_path59.join)(scratch, "model.ifc");
|
|
86996
87054
|
const rendered = [];
|
|
86997
87055
|
const progress = (stage, extra = {}) => {
|
|
@@ -87003,7 +87061,7 @@ async function startServer() {
|
|
|
87003
87061
|
try {
|
|
87004
87062
|
progress("preparing");
|
|
87005
87063
|
await aware.agentInvoke("ifc", "write", { scene: built.scene, "output-path": ifcPath });
|
|
87006
|
-
if (!(0,
|
|
87064
|
+
if (!(0, import_node_fs63.existsSync)(ifcPath) || (0, import_node_fs63.statSync)(ifcPath).size === 0) {
|
|
87007
87065
|
throw new Error("AWARE reported a successful IFC write but produced no file to render");
|
|
87008
87066
|
}
|
|
87009
87067
|
const renderBudgetMs = output === "turntable" ? 30 * 6e4 : 10 * 6e4;
|
|
@@ -87021,10 +87079,10 @@ async function startServer() {
|
|
|
87021
87079
|
environment: "studio",
|
|
87022
87080
|
...output === "turntable" ? { "duration-seconds": 12, fps: 24, "width-pixels": 1280, "height-pixels": 720 } : { quality, "width-pixels": 1920, "height-pixels": 1080 }
|
|
87023
87081
|
}, { timeoutMs: renderBudgetMs });
|
|
87024
|
-
if (!(0,
|
|
87082
|
+
if (!(0, import_node_fs63.existsSync)(artifactPath) || (0, import_node_fs63.statSync)(artifactPath).size === 0) {
|
|
87025
87083
|
throw new Error(`the ${viewpoint} render reported success but produced no image`);
|
|
87026
87084
|
}
|
|
87027
|
-
const bytes = (0,
|
|
87085
|
+
const bytes = (0, import_node_fs63.readFileSync)(artifactPath);
|
|
87028
87086
|
const sourceSuffix = "source" in projectSnapshot && projectSnapshot.source ? `-${projectSnapshot.source.filenameLabel.replace(/[^A-Za-z0-9._-]+/g, "-")}` : "";
|
|
87029
87087
|
const preferred = `${exportFileBase(project, appId)}-${viewpoint}${sourceSuffix}${extension}`;
|
|
87030
87088
|
const filename = uniqueProjectExportFilename(project, preferred);
|
|
@@ -87080,7 +87138,7 @@ async function startServer() {
|
|
|
87080
87138
|
rendered
|
|
87081
87139
|
});
|
|
87082
87140
|
} finally {
|
|
87083
|
-
(0,
|
|
87141
|
+
(0, import_node_fs63.rmSync)(scratch, { recursive: true, force: true });
|
|
87084
87142
|
}
|
|
87085
87143
|
}, {
|
|
87086
87144
|
// What anyone blocked on this project is told, and for how long to expect it. Erring long
|
|
@@ -87321,7 +87379,7 @@ async function startServer() {
|
|
|
87321
87379
|
const outPath = project ? (0, import_node_path59.join)(projectExportsDir(project), filename) : bomExportPath(appId, format);
|
|
87322
87380
|
const dir = (0, import_node_path59.dirname)(outPath);
|
|
87323
87381
|
try {
|
|
87324
|
-
(0,
|
|
87382
|
+
(0, import_node_fs63.mkdirSync)(dir, { recursive: true });
|
|
87325
87383
|
const kind = BOM_EXPORT_KIND[format];
|
|
87326
87384
|
let text3 = null;
|
|
87327
87385
|
let buf;
|
|
@@ -87349,8 +87407,8 @@ async function startServer() {
|
|
|
87349
87407
|
sourceKind: projectSnapshot.source?.kind ?? "approved",
|
|
87350
87408
|
contractHash: projectSnapshot.contractHash
|
|
87351
87409
|
}, buf);
|
|
87352
|
-
} else if (text3 != null) (0,
|
|
87353
|
-
else (0,
|
|
87410
|
+
} else if (text3 != null) (0, import_node_fs63.writeFileSync)(outPath, text3, "utf8");
|
|
87411
|
+
else (0, import_node_fs63.writeFileSync)(outPath, buf);
|
|
87354
87412
|
return {
|
|
87355
87413
|
ok: true,
|
|
87356
87414
|
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 }
|
|
@@ -87390,7 +87448,7 @@ async function startServer() {
|
|
|
87390
87448
|
const filename = project ? uniqueProjectExportFilename(project, preferredFilename) : preferredFilename;
|
|
87391
87449
|
const outPath = project ? (0, import_node_path59.join)(projectExportsDir(project), filename) : (0, import_node_path59.join)(appPath(appId), filename);
|
|
87392
87450
|
try {
|
|
87393
|
-
(0,
|
|
87451
|
+
(0, import_node_fs63.mkdirSync)((0, import_node_path59.dirname)(outPath), { recursive: true });
|
|
87394
87452
|
if (project && projectSnapshot) {
|
|
87395
87453
|
publishProjectExportArtifact(project, {
|
|
87396
87454
|
kind: "svg",
|
|
@@ -87401,7 +87459,7 @@ async function startServer() {
|
|
|
87401
87459
|
sourceKind: projectSnapshot.source?.kind ?? "approved",
|
|
87402
87460
|
contractHash: projectSnapshot.contractHash
|
|
87403
87461
|
}, Buffer.from(svg, "utf8"));
|
|
87404
|
-
} else (0,
|
|
87462
|
+
} else (0, import_node_fs63.writeFileSync)(outPath, svg, "utf8");
|
|
87405
87463
|
return { ok: true, filename, encoding: "utf8", content: svg, bytes: Buffer.byteLength(svg), savedTo: outPath };
|
|
87406
87464
|
} catch (e) {
|
|
87407
87465
|
app.log.error({ appId, err: e instanceof Error ? e.message : e }, "export-svg: write failed");
|
|
@@ -87583,11 +87641,11 @@ async function startServer() {
|
|
|
87583
87641
|
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 });
|
|
87584
87642
|
}
|
|
87585
87643
|
await deleteOrigin(id);
|
|
87586
|
-
const stageRoot = (0,
|
|
87644
|
+
const stageRoot = (0, import_node_fs63.mkdtempSync)((0, import_node_path59.join)((0, import_node_os29.tmpdir)(), "floless-import-"));
|
|
87587
87645
|
try {
|
|
87588
87646
|
const stageDir = (0, import_node_path59.join)(stageRoot, id);
|
|
87589
|
-
(0,
|
|
87590
|
-
(0,
|
|
87647
|
+
(0, import_node_fs63.mkdirSync)(stageDir);
|
|
87648
|
+
(0, import_node_fs63.writeFileSync)((0, import_node_path59.join)(stageDir, `${id}.flo`), content);
|
|
87591
87649
|
await aware.install(stageDir);
|
|
87592
87650
|
} catch (err2) {
|
|
87593
87651
|
try {
|
|
@@ -87598,7 +87656,7 @@ async function startServer() {
|
|
|
87598
87656
|
const reason = awareStderr(err2);
|
|
87599
87657
|
return reply.status(502).send({ ok: false, error: `import failed: ${msg}`, code: "install-failed", reason, agentsUnavailable: unavailableAgents(reason) });
|
|
87600
87658
|
} finally {
|
|
87601
|
-
(0,
|
|
87659
|
+
(0, import_node_fs63.rmSync)(stageRoot, { recursive: true, force: true });
|
|
87602
87660
|
}
|
|
87603
87661
|
broadcast({ type: "apps-changed", id });
|
|
87604
87662
|
return { ok: true, id };
|
|
@@ -87614,13 +87672,13 @@ async function startServer() {
|
|
|
87614
87672
|
}
|
|
87615
87673
|
const inputs = appData.inputs.map((i) => ({ name: i.name, type: i.type }));
|
|
87616
87674
|
const baked = bakeFloSource(appData.source.text, inputs);
|
|
87617
|
-
const tmpRoot = (0,
|
|
87675
|
+
const tmpRoot = (0, import_node_fs63.mkdtempSync)((0, import_node_path59.join)((0, import_node_os29.tmpdir)(), "floless-bake-"));
|
|
87618
87676
|
const backupDir2 = (0, import_node_path59.join)(tmpRoot, `${id}-backup`);
|
|
87619
87677
|
const bakeDir = (0, import_node_path59.join)(tmpRoot, id);
|
|
87620
|
-
(0,
|
|
87621
|
-
(0,
|
|
87678
|
+
(0, import_node_fs63.cpSync)(appDir(id), backupDir2, { recursive: true });
|
|
87679
|
+
(0, import_node_fs63.cpSync)(appDir(id), bakeDir, { recursive: true });
|
|
87622
87680
|
const floName = appData.source.path.split(/[\\/]/).pop();
|
|
87623
|
-
(0,
|
|
87681
|
+
(0, import_node_fs63.writeFileSync)((0, import_node_path59.join)(bakeDir, floName), baked);
|
|
87624
87682
|
let appInstalled2 = true;
|
|
87625
87683
|
try {
|
|
87626
87684
|
await aware.uninstall(id);
|
|
@@ -87649,7 +87707,7 @@ async function startServer() {
|
|
|
87649
87707
|
broadcast({ type: "baked", id });
|
|
87650
87708
|
return { ok: true, id, agent: id, inputs };
|
|
87651
87709
|
} finally {
|
|
87652
|
-
if (appInstalled2) (0,
|
|
87710
|
+
if (appInstalled2) (0, import_node_fs63.rmSync)(tmpRoot, { recursive: true, force: true });
|
|
87653
87711
|
}
|
|
87654
87712
|
});
|
|
87655
87713
|
});
|
|
@@ -87670,7 +87728,7 @@ async function startServer() {
|
|
|
87670
87728
|
if (!sourceKind || !sourceRef) {
|
|
87671
87729
|
return reply.status(400).send({ ok: false, error: "sourceKind and sourceRef required" });
|
|
87672
87730
|
}
|
|
87673
|
-
const tempHome = (0,
|
|
87731
|
+
const tempHome = (0, import_node_fs63.mkdtempSync)((0, import_node_path59.join)((0, import_node_os29.tmpdir)(), "floless-graft-"));
|
|
87674
87732
|
let result;
|
|
87675
87733
|
try {
|
|
87676
87734
|
result = await aware.build({
|
|
@@ -87683,19 +87741,19 @@ async function startServer() {
|
|
|
87683
87741
|
awareHome: tempHome
|
|
87684
87742
|
});
|
|
87685
87743
|
} catch (err2) {
|
|
87686
|
-
(0,
|
|
87744
|
+
(0, import_node_fs63.rmSync)(tempHome, { recursive: true, force: true });
|
|
87687
87745
|
const msg = err2 instanceof AwareError ? err2.message : String(err2?.message ?? err2);
|
|
87688
87746
|
return reply.status(422).send({ ok: false, error: msg });
|
|
87689
87747
|
}
|
|
87690
87748
|
const manifest = readStagedManifest(result.agentDir);
|
|
87691
87749
|
if (!manifest) {
|
|
87692
|
-
(0,
|
|
87750
|
+
(0, import_node_fs63.rmSync)(tempHome, { recursive: true, force: true });
|
|
87693
87751
|
return reply.status(502).send({ ok: false, error: `build produced output at ${result.agentDir} but no manifest.yaml` });
|
|
87694
87752
|
}
|
|
87695
87753
|
const token2 = (0, import_node_crypto33.randomUUID)();
|
|
87696
87754
|
registerStage(token2, tempHome, result.agentId);
|
|
87697
87755
|
const preview2 = buildPreview(manifest, sourceKind, sourceRef, token2);
|
|
87698
|
-
if ((0,
|
|
87756
|
+
if ((0, import_node_fs63.existsSync)((0, import_node_path59.join)(graftAgentsDir(), result.agentId))) {
|
|
87699
87757
|
preview2.warnings.unshift(`An agent named "${result.agentId}" is already installed \u2014 creating it will overwrite it.`);
|
|
87700
87758
|
}
|
|
87701
87759
|
return { ok: true, preview: preview2 };
|
|
@@ -87714,7 +87772,7 @@ async function startServer() {
|
|
|
87714
87772
|
registerStage(stagedRef, stage.tempDir, stage.agentId);
|
|
87715
87773
|
return reply.status(409).send({ ok: false, error: err2.message, agentId: stage.agentId, collision: true });
|
|
87716
87774
|
}
|
|
87717
|
-
(0,
|
|
87775
|
+
(0, import_node_fs63.rmSync)(stage.tempDir, { recursive: true, force: true });
|
|
87718
87776
|
throw err2;
|
|
87719
87777
|
}
|
|
87720
87778
|
broadcast({ type: "grafted", id: stage.agentId });
|
|
@@ -87883,46 +87941,7 @@ async function startServer() {
|
|
|
87883
87941
|
const events = parseTrace(latest.text);
|
|
87884
87942
|
return { ok: true, id, runId: latest.runId, ...summarizeRun(events), events };
|
|
87885
87943
|
});
|
|
87886
|
-
|
|
87887
|
-
const out = {};
|
|
87888
|
-
for (const [k, v] of Object.entries(configArgs)) {
|
|
87889
|
-
if (typeof v === "string") {
|
|
87890
|
-
const m = v.match(/^\{\{\s*inputs\.([A-Za-z0-9._-]+)\s*\}\}$/);
|
|
87891
|
-
out[k] = m && m[1] != null && m[1] in inputs ? inputs[m[1]] : v;
|
|
87892
|
-
} else {
|
|
87893
|
-
out[k] = v;
|
|
87894
|
-
}
|
|
87895
|
-
}
|
|
87896
|
-
return out;
|
|
87897
|
-
}
|
|
87898
|
-
app.post(
|
|
87899
|
-
"/api/debug-node",
|
|
87900
|
-
async (req, reply) => {
|
|
87901
|
-
const { id, nodeId, inputs } = req.body ?? {};
|
|
87902
|
-
if (!id || !nodeId) return reply.status(400).send({ ok: false, error: "id and nodeId required" });
|
|
87903
|
-
const appData = readApp(id);
|
|
87904
|
-
if (!appData.runnable) return reply.status(409).send({ ok: false, error: "app not runnable \u2014 compile the lock first" });
|
|
87905
|
-
const node = appData.nodes.find((n) => n.id === nodeId);
|
|
87906
|
-
if (!node) return reply.status(404).send({ ok: false, error: `node not found: ${nodeId}` });
|
|
87907
|
-
const code = node.config?.code;
|
|
87908
|
-
if (typeof code !== "string") return reply.status(400).send({ ok: false, error: `node ${nodeId} has no exec code` });
|
|
87909
|
-
const version = typeof node.config?.version === "string" ? node.config.version : void 0;
|
|
87910
|
-
const configArgs = node.config?.args ?? {};
|
|
87911
|
-
const effectiveInputs = {};
|
|
87912
|
-
for (const inp of appData.inputs) {
|
|
87913
|
-
const d = inp.default;
|
|
87914
|
-
if (typeof d === "string" || typeof d === "number" || typeof d === "boolean") effectiveInputs[inp.name] = d;
|
|
87915
|
-
}
|
|
87916
|
-
Object.assign(effectiveInputs, inputs ?? {});
|
|
87917
|
-
const args = resolveArgs(configArgs, effectiveInputs);
|
|
87918
|
-
broadcast({ type: "debug-started", id, nodeId });
|
|
87919
|
-
const result = await aware.execTekla(code, { version, args, debug: true });
|
|
87920
|
-
broadcast({ type: "debug-ended", id, nodeId });
|
|
87921
|
-
const r = result.result ?? {};
|
|
87922
|
-
const html = typeof r.html === "string" ? r.html : null;
|
|
87923
|
-
return { ok: true, result, report: withBadge(html ? { nodeId, html } : null) };
|
|
87924
|
-
}
|
|
87925
|
-
);
|
|
87944
|
+
registerDebugNodeRoute(app, { readApp, execTekla: (code, opts) => aware.execTekla(code, opts), broadcast });
|
|
87926
87945
|
app.get("/api/routines", async () => ({
|
|
87927
87946
|
// Annotate each with live state so the UI reconciles from the server (a dropped
|
|
87928
87947
|
// SSE event can't wedge an indicator): schedule routines carry queued/active
|
|
@@ -88036,11 +88055,11 @@ async function startServer() {
|
|
|
88036
88055
|
app.get("/api/requests/:id/snapshot/:n", async (req, reply) => {
|
|
88037
88056
|
const n = Number.parseInt(req.params.n, 10);
|
|
88038
88057
|
const p = Number.isInteger(n) ? snapshotPathFor(req.params.id, n) : null;
|
|
88039
|
-
if (!p || !(0,
|
|
88058
|
+
if (!p || !(0, import_node_fs63.existsSync)(p)) return reply.status(404).send({ ok: false, error: "snapshot not found" });
|
|
88040
88059
|
const ext = p.split(".").pop().toLowerCase();
|
|
88041
88060
|
reply.header("Content-Type", ext === "png" ? "image/png" : ext === "webp" ? "image/webp" : ext === "pdf" ? "application/pdf" : "image/jpeg");
|
|
88042
88061
|
reply.header("Cache-Control", "no-store");
|
|
88043
|
-
return (0,
|
|
88062
|
+
return (0, import_node_fs63.readFileSync)(p);
|
|
88044
88063
|
});
|
|
88045
88064
|
app.post(
|
|
88046
88065
|
"/api/tweak",
|
|
@@ -88269,7 +88288,7 @@ async function startServer() {
|
|
|
88269
88288
|
warn(`last-run-status:${ref} \u2014 trace exists but couldn't be parsed (corrupt/truncated)`);
|
|
88270
88289
|
let finishedAt2 = null;
|
|
88271
88290
|
try {
|
|
88272
|
-
finishedAt2 = (0,
|
|
88291
|
+
finishedAt2 = (0, import_node_fs63.statSync)(latest.path).mtime.toISOString();
|
|
88273
88292
|
} catch {
|
|
88274
88293
|
finishedAt2 = null;
|
|
88275
88294
|
}
|
|
@@ -88279,7 +88298,7 @@ async function startServer() {
|
|
|
88279
88298
|
let finishedAt = typeof runEnd?.ts === "string" ? runEnd.ts : null;
|
|
88280
88299
|
if (!finishedAt) {
|
|
88281
88300
|
try {
|
|
88282
|
-
finishedAt = (0,
|
|
88301
|
+
finishedAt = (0, import_node_fs63.statSync)(latest.path).mtime.toISOString();
|
|
88283
88302
|
} catch {
|
|
88284
88303
|
finishedAt = null;
|
|
88285
88304
|
}
|