@securecoms/agent-bridge 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -3
- package/dist/attachments.d.ts +13 -0
- package/dist/bin.js +386 -249
- package/dist/bridge-agent.d.ts +16 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.js +325 -188
- package/dist/outbox.d.ts +42 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -7416,37 +7416,37 @@ __export(layout_exports, {
|
|
|
7416
7416
|
presentWithSize: () => presentWithSize,
|
|
7417
7417
|
wrongTypeAt: () => wrongTypeAt
|
|
7418
7418
|
});
|
|
7419
|
-
import { chmodSync, lstatSync as
|
|
7419
|
+
import { chmodSync as chmodSync2, lstatSync as lstatSync3, mkdirSync as mkdirSync2, renameSync, rmSync } from "node:fs";
|
|
7420
7420
|
import { homedir as homedir2 } from "node:os";
|
|
7421
|
-
import { basename as
|
|
7421
|
+
import { basename as basename3, dirname as dirname5, join as join10 } from "node:path";
|
|
7422
7422
|
function kind(p) {
|
|
7423
7423
|
try {
|
|
7424
|
-
return
|
|
7424
|
+
return lstatSync3(p).isDirectory() ? "dir" : "other";
|
|
7425
7425
|
} catch (e) {
|
|
7426
7426
|
if (e.code === "ENOENT") return "absent";
|
|
7427
7427
|
throw e;
|
|
7428
7428
|
}
|
|
7429
7429
|
}
|
|
7430
7430
|
function plainDirChain(root3, parts, opts) {
|
|
7431
|
-
const modelsDir =
|
|
7431
|
+
const modelsDir = dirname5(root3);
|
|
7432
7432
|
for (const part of parts) if (!part || part === "." || part === ".." || part.includes("/") || part.includes("\\")) throw new LayoutRefused();
|
|
7433
7433
|
const k = kind(modelsDir);
|
|
7434
7434
|
if (k === "other") throw new LayoutRefused();
|
|
7435
7435
|
if (k === "absent") {
|
|
7436
7436
|
if (!opts.create) return null;
|
|
7437
|
-
|
|
7437
|
+
mkdirSync2(modelsDir, { recursive: true, mode: 448 });
|
|
7438
7438
|
if (kind(modelsDir) !== "dir") throw new LayoutRefused();
|
|
7439
7439
|
}
|
|
7440
|
-
const chain = opts.fromModelsDir ? parts : [
|
|
7440
|
+
const chain = opts.fromModelsDir ? parts : [basename3(root3), ...parts];
|
|
7441
7441
|
let p = modelsDir;
|
|
7442
7442
|
for (let i = 0; i < chain.length; i++) {
|
|
7443
|
-
p =
|
|
7443
|
+
p = join10(p, chain[i]);
|
|
7444
7444
|
const c = kind(p);
|
|
7445
7445
|
if (c === "other") throw new LayoutRefused();
|
|
7446
7446
|
if (c === "absent") {
|
|
7447
7447
|
if (!opts.create) return null;
|
|
7448
7448
|
try {
|
|
7449
|
-
|
|
7449
|
+
mkdirSync2(p, { mode: i === chain.length - 1 && opts.mode !== void 0 ? opts.mode : 493 });
|
|
7450
7450
|
} catch (e) {
|
|
7451
7451
|
if (e.code !== "EEXIST") throw e;
|
|
7452
7452
|
}
|
|
@@ -7457,7 +7457,7 @@ function plainDirChain(root3, parts, opts) {
|
|
|
7457
7457
|
}
|
|
7458
7458
|
function presentWithSize(p, size) {
|
|
7459
7459
|
try {
|
|
7460
|
-
const s =
|
|
7460
|
+
const s = lstatSync3(p);
|
|
7461
7461
|
return s.isFile() && s.size === size;
|
|
7462
7462
|
} catch {
|
|
7463
7463
|
return false;
|
|
@@ -7465,7 +7465,7 @@ function presentWithSize(p, size) {
|
|
|
7465
7465
|
}
|
|
7466
7466
|
function wrongTypeAt(p) {
|
|
7467
7467
|
try {
|
|
7468
|
-
const s =
|
|
7468
|
+
const s = lstatSync3(p);
|
|
7469
7469
|
return !s.isFile() && !s.isSymbolicLink();
|
|
7470
7470
|
} catch {
|
|
7471
7471
|
return false;
|
|
@@ -7478,16 +7478,16 @@ function installVerified(root3, modelId, f, partial, opts) {
|
|
|
7478
7478
|
dir = plainDirChain(root3, [modelId, f.sha256], { create: true });
|
|
7479
7479
|
if (!dir) throw new LayoutRefused();
|
|
7480
7480
|
if (!opts.replace && presentWithSize(dest, f.size)) return;
|
|
7481
|
-
|
|
7481
|
+
chmodSync2(dir, 493);
|
|
7482
7482
|
try {
|
|
7483
7483
|
renameSync(partial, dest);
|
|
7484
7484
|
} catch (e) {
|
|
7485
7485
|
if (!presentWithSize(dest, f.size)) throw e;
|
|
7486
7486
|
return;
|
|
7487
7487
|
}
|
|
7488
|
-
|
|
7488
|
+
chmodSync2(dest, 292);
|
|
7489
7489
|
} finally {
|
|
7490
|
-
if (dir)
|
|
7490
|
+
if (dir) chmodSync2(dir, 365);
|
|
7491
7491
|
rmSync(partial, { force: true });
|
|
7492
7492
|
}
|
|
7493
7493
|
}
|
|
@@ -7495,9 +7495,9 @@ var defaultModelsRoot, partialDir, filePath, LayoutRefused;
|
|
|
7495
7495
|
var init_layout = __esm({
|
|
7496
7496
|
"src/memory/embedder/layout.ts"() {
|
|
7497
7497
|
"use strict";
|
|
7498
|
-
defaultModelsRoot = (home = homedir2()) =>
|
|
7499
|
-
partialDir = (root3) =>
|
|
7500
|
-
filePath = (root3, modelId, f) =>
|
|
7498
|
+
defaultModelsRoot = (home = homedir2()) => join10(home, ".securecoms", "models", "embeddings");
|
|
7499
|
+
partialDir = (root3) => join10(dirname5(root3), ".partial");
|
|
7500
|
+
filePath = (root3, modelId, f) => join10(root3, modelId, f.sha256, f.name);
|
|
7501
7501
|
LayoutRefused = class extends Error {
|
|
7502
7502
|
constructor() {
|
|
7503
7503
|
super("the model directory is not a plain directory");
|
|
@@ -7557,11 +7557,11 @@ __export(import_bundle_exports, {
|
|
|
7557
7557
|
});
|
|
7558
7558
|
import { createHash as createHash6, randomBytes as randomBytes12 } from "node:crypto";
|
|
7559
7559
|
import { readFileSync as readFileSync16, statSync as statSync7, writeFileSync as writeFileSync4 } from "node:fs";
|
|
7560
|
-
import { join as
|
|
7560
|
+
import { join as join25 } from "node:path";
|
|
7561
7561
|
async function importModelBundle(srcDir, root3, m) {
|
|
7562
7562
|
const verified = [];
|
|
7563
7563
|
for (const f of m.files) {
|
|
7564
|
-
const src =
|
|
7564
|
+
const src = join25(srcDir, f.name);
|
|
7565
7565
|
let size;
|
|
7566
7566
|
try {
|
|
7567
7567
|
const s = statSync7(src);
|
|
@@ -7585,7 +7585,7 @@ async function importModelBundle(srcDir, root3, m) {
|
|
|
7585
7585
|
for (const { f, bytes } of verified) {
|
|
7586
7586
|
try {
|
|
7587
7587
|
const pdir = plainDirChain(root3, [".partial"], { create: true, fromModelsDir: true, mode: 448 });
|
|
7588
|
-
const partial =
|
|
7588
|
+
const partial = join25(pdir, randomBytes12(12).toString("hex"));
|
|
7589
7589
|
writeFileSync4(partial, bytes, { mode: 384, flag: "wx" });
|
|
7590
7590
|
installVerified(root3, m.modelId, f, partial, { replace: true });
|
|
7591
7591
|
} catch (e) {
|
|
@@ -25474,8 +25474,8 @@ function openDeliveryPings(o) {
|
|
|
25474
25474
|
return Promise.resolve({ value: void 0, done: true });
|
|
25475
25475
|
if (queue.length)
|
|
25476
25476
|
return Promise.resolve({ value: queue.shift(), done: false });
|
|
25477
|
-
return new Promise((
|
|
25478
|
-
waiter =
|
|
25477
|
+
return new Promise((resolve5) => {
|
|
25478
|
+
waiter = resolve5;
|
|
25479
25479
|
});
|
|
25480
25480
|
}
|
|
25481
25481
|
};
|
|
@@ -25795,8 +25795,8 @@ var PingSubscriber = class {
|
|
|
25795
25795
|
return Promise.resolve({ value: void 0, done: true });
|
|
25796
25796
|
if (this.queue.length)
|
|
25797
25797
|
return Promise.resolve({ value: this.queue.shift(), done: false });
|
|
25798
|
-
return new Promise((
|
|
25799
|
-
this.waiter =
|
|
25798
|
+
return new Promise((resolve5) => {
|
|
25799
|
+
this.waiter = resolve5;
|
|
25800
25800
|
});
|
|
25801
25801
|
}
|
|
25802
25802
|
};
|
|
@@ -30493,8 +30493,96 @@ function loadPackageMeta(importMetaUrl) {
|
|
|
30493
30493
|
}
|
|
30494
30494
|
|
|
30495
30495
|
// src/bridge-agent.ts
|
|
30496
|
-
import { existsSync as existsSync5, promises as
|
|
30497
|
-
|
|
30496
|
+
import { existsSync as existsSync5, promises as fsp2, readFileSync as readFileSync11, statSync as statSync5 } from "node:fs";
|
|
30497
|
+
|
|
30498
|
+
// src/outbox.ts
|
|
30499
|
+
import { constants, mkdirSync, lstatSync as lstatSync2, chmodSync, realpathSync, promises as fsp } from "node:fs";
|
|
30500
|
+
import { basename, dirname as dirname4, join as join4, resolve } from "node:path";
|
|
30501
|
+
var VAULT_OUTBOX_DIRNAME = "vault-outbox";
|
|
30502
|
+
var PathOutsideOutboxError = class extends Error {
|
|
30503
|
+
constructor() {
|
|
30504
|
+
super("path_outside_outbox");
|
|
30505
|
+
this.name = "PathOutsideOutboxError";
|
|
30506
|
+
}
|
|
30507
|
+
};
|
|
30508
|
+
var POSIX = process.platform !== "win32";
|
|
30509
|
+
function ownedPrivateDir(st) {
|
|
30510
|
+
if (st.isSymbolicLink() || !st.isDirectory()) return false;
|
|
30511
|
+
if (!POSIX) return true;
|
|
30512
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
30513
|
+
if (uid !== void 0 && st.uid !== uid) return false;
|
|
30514
|
+
return (st.mode & 511) === 448;
|
|
30515
|
+
}
|
|
30516
|
+
function ensureOutbox(dir) {
|
|
30517
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
30518
|
+
let st = lstatSync2(dir);
|
|
30519
|
+
if (st.isSymbolicLink() || !st.isDirectory()) throw new PathOutsideOutboxError();
|
|
30520
|
+
const uid = POSIX && typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
30521
|
+
if (uid !== void 0 && st.uid !== uid) throw new PathOutsideOutboxError();
|
|
30522
|
+
if (POSIX && (st.mode & 511) !== 448) {
|
|
30523
|
+
chmodSync(dir, 448);
|
|
30524
|
+
st = lstatSync2(dir);
|
|
30525
|
+
}
|
|
30526
|
+
if (!ownedPrivateDir(st)) throw new PathOutsideOutboxError();
|
|
30527
|
+
return { dir, real: realpathSync(dir), dev: st.dev, ino: st.ino };
|
|
30528
|
+
}
|
|
30529
|
+
var NOFOLLOW = constants.O_NOFOLLOW ?? 0;
|
|
30530
|
+
var NONBLOCK = constants.O_NONBLOCK ?? 0;
|
|
30531
|
+
async function readOutboxFile(pin, callerPath) {
|
|
30532
|
+
if (!pin) throw new PathOutsideOutboxError();
|
|
30533
|
+
try {
|
|
30534
|
+
const st = await fsp.lstat(pin.dir);
|
|
30535
|
+
if (!ownedPrivateDir(st) || st.dev !== pin.dev || st.ino !== pin.ino) throw new PathOutsideOutboxError();
|
|
30536
|
+
} catch {
|
|
30537
|
+
throw new PathOutsideOutboxError();
|
|
30538
|
+
}
|
|
30539
|
+
const requested = resolve(pin.dir, callerPath);
|
|
30540
|
+
const name = basename(requested);
|
|
30541
|
+
let realParent;
|
|
30542
|
+
try {
|
|
30543
|
+
realParent = await fsp.realpath(dirname4(requested));
|
|
30544
|
+
} catch {
|
|
30545
|
+
throw new PathOutsideOutboxError();
|
|
30546
|
+
}
|
|
30547
|
+
if (realParent !== pin.real) throw new PathOutsideOutboxError();
|
|
30548
|
+
const target = join4(pin.real, name);
|
|
30549
|
+
const pre = await fsp.lstat(target);
|
|
30550
|
+
if (pre.isSymbolicLink() || !pre.isFile()) throw new PathOutsideOutboxError();
|
|
30551
|
+
let handle;
|
|
30552
|
+
try {
|
|
30553
|
+
handle = await fsp.open(target, constants.O_RDONLY | NOFOLLOW | NONBLOCK);
|
|
30554
|
+
} catch (e) {
|
|
30555
|
+
if (e.code === "ENOENT") throw e;
|
|
30556
|
+
throw new PathOutsideOutboxError();
|
|
30557
|
+
}
|
|
30558
|
+
try {
|
|
30559
|
+
const st = await handle.stat();
|
|
30560
|
+
if (!st.isFile() || st.dev !== pre.dev || st.ino !== pre.ino || st.nlink !== 1) {
|
|
30561
|
+
throw new PathOutsideOutboxError();
|
|
30562
|
+
}
|
|
30563
|
+
return { bytes: new Uint8Array(await handle.readFile()), path: target, dev: st.dev, ino: st.ino };
|
|
30564
|
+
} finally {
|
|
30565
|
+
await handle.close().catch(() => {
|
|
30566
|
+
});
|
|
30567
|
+
}
|
|
30568
|
+
}
|
|
30569
|
+
async function consumeOutboxFile(pin, read) {
|
|
30570
|
+
try {
|
|
30571
|
+
const dir = await fsp.lstat(pin.dir);
|
|
30572
|
+
if (!ownedPrivateDir(dir) || dir.dev !== pin.dev || dir.ino !== pin.ino) return false;
|
|
30573
|
+
if (await fsp.realpath(pin.dir) !== pin.real) return false;
|
|
30574
|
+
const target = join4(pin.real, basename(read.path));
|
|
30575
|
+
const st = await fsp.lstat(target);
|
|
30576
|
+
if (st.isSymbolicLink() || st.dev !== read.dev || st.ino !== read.ino) return false;
|
|
30577
|
+
await fsp.unlink(target);
|
|
30578
|
+
return true;
|
|
30579
|
+
} catch {
|
|
30580
|
+
return false;
|
|
30581
|
+
}
|
|
30582
|
+
}
|
|
30583
|
+
|
|
30584
|
+
// src/bridge-agent.ts
|
|
30585
|
+
import { join as join20, dirname as dirname8 } from "node:path";
|
|
30498
30586
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
30499
30587
|
|
|
30500
30588
|
// src/latency.ts
|
|
@@ -30942,11 +31030,21 @@ function pinCoverage(pinStripped, ownerMessage, coverTexts) {
|
|
|
30942
31030
|
}
|
|
30943
31031
|
|
|
30944
31032
|
// src/attachments.ts
|
|
30945
|
-
import { basename } from "node:path";
|
|
31033
|
+
import { basename as basename2 } from "node:path";
|
|
30946
31034
|
var VAULT_REF_MAX_SIZE_HINT = 100 * 1024 * 1024 - 16;
|
|
30947
31035
|
var VAULT_REF_MAX_NAME = 255;
|
|
30948
31036
|
var VAULT_REF_MAX_MIME = 127;
|
|
30949
31037
|
var CANONICAL_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
31038
|
+
var InvalidBlobIdError = class extends Error {
|
|
31039
|
+
constructor() {
|
|
31040
|
+
super("invalid_blob_id");
|
|
31041
|
+
this.name = "InvalidBlobIdError";
|
|
31042
|
+
}
|
|
31043
|
+
};
|
|
31044
|
+
function assertBlobId(blobId) {
|
|
31045
|
+
if (typeof blobId !== "string" || !CANONICAL_UUID.test(blobId)) throw new InvalidBlobIdError();
|
|
31046
|
+
return blobId;
|
|
31047
|
+
}
|
|
30950
31048
|
var VAULT_PIN = /^blake2b:[0-9a-f]{64}$/;
|
|
30951
31049
|
var HINT_FORBIDDEN = /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/;
|
|
30952
31050
|
var MIME_TYPE = /^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*$/;
|
|
@@ -30985,7 +31083,7 @@ function toVaultRefEntry(body) {
|
|
|
30985
31083
|
return entry;
|
|
30986
31084
|
}
|
|
30987
31085
|
function sanitizeFilename(name, fallback) {
|
|
30988
|
-
const base =
|
|
31086
|
+
const base = basename2(name ?? "");
|
|
30989
31087
|
const cleaned = base.replace(/[/\\]/g, "").replace(/^\.+$/, "");
|
|
30990
31088
|
return cleaned.length > 0 ? cleaned : fallback;
|
|
30991
31089
|
}
|
|
@@ -31015,7 +31113,7 @@ function mimeForName(name) {
|
|
|
31015
31113
|
async function prepareAttachment(filePath2, caption, channelId, deps) {
|
|
31016
31114
|
await deps.ready();
|
|
31017
31115
|
const bytes = await deps.readFile(filePath2);
|
|
31018
|
-
const name =
|
|
31116
|
+
const name = basename2(filePath2);
|
|
31019
31117
|
const { encryptedData, fileKey, fileNonce, digest } = await deps.encryptFile(bytes);
|
|
31020
31118
|
const blobId = await deps.uploadBlob(encryptedData, channelId);
|
|
31021
31119
|
const body = {
|
|
@@ -31033,8 +31131,9 @@ async function prepareAttachment(filePath2, caption, channelId, deps) {
|
|
|
31033
31131
|
return body;
|
|
31034
31132
|
}
|
|
31035
31133
|
async function materializeAttachment(body, ctx, deps) {
|
|
31134
|
+
const blobId = assertBlobId(body.blobId);
|
|
31036
31135
|
await deps.ready();
|
|
31037
|
-
const ciphertext = await deps.downloadBlob(
|
|
31136
|
+
const ciphertext = await deps.downloadBlob(blobId);
|
|
31038
31137
|
const sha25612 = await deps.computeFileDigest(ciphertext);
|
|
31039
31138
|
if (sha25612 !== body.digest) {
|
|
31040
31139
|
throw new Error(`attachment digest mismatch for blob ${body.blobId}`);
|
|
@@ -31060,13 +31159,13 @@ function ensureSodiumReady2() {
|
|
|
31060
31159
|
// src/memory/hermes-session-map.ts
|
|
31061
31160
|
import { readFileSync as readFileSync3 } from "node:fs";
|
|
31062
31161
|
import { homedir } from "node:os";
|
|
31063
|
-
import { join as
|
|
31162
|
+
import { join as join5 } from "node:path";
|
|
31064
31163
|
function expandHome(p) {
|
|
31065
|
-
return p === "~" || p.startsWith("~/") ?
|
|
31164
|
+
return p === "~" || p.startsWith("~/") ? join5(homedir(), p.slice(1)) : p;
|
|
31066
31165
|
}
|
|
31067
31166
|
function resolveHermesSession(baseDir, conversationId) {
|
|
31068
31167
|
try {
|
|
31069
|
-
const path =
|
|
31168
|
+
const path = join5(expandHome(baseDir), "sessions", "sessions.json");
|
|
31070
31169
|
const map = JSON.parse(readFileSync3(path, "utf8"));
|
|
31071
31170
|
const entry = map[`agent:main:securecoms:dm:${conversationId}`];
|
|
31072
31171
|
const sid = entry?.session_id;
|
|
@@ -31078,11 +31177,11 @@ function resolveHermesSession(baseDir, conversationId) {
|
|
|
31078
31177
|
|
|
31079
31178
|
// src/memory/hermes-store.ts
|
|
31080
31179
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
31081
|
-
import { join as
|
|
31180
|
+
import { join as join6 } from "node:path";
|
|
31082
31181
|
var HermesStore = class {
|
|
31083
31182
|
dbPath;
|
|
31084
31183
|
constructor(baseDir) {
|
|
31085
|
-
this.dbPath =
|
|
31184
|
+
this.dbPath = join6(expandHome(baseDir), "state.db");
|
|
31086
31185
|
}
|
|
31087
31186
|
/** Recent-K conversational turns for a session, chronological. Fail-safe → []. */
|
|
31088
31187
|
readRecent(sessionId, limit) {
|
|
@@ -31224,10 +31323,10 @@ var HermesMemoryProvider = class {
|
|
|
31224
31323
|
|
|
31225
31324
|
// src/memory/openclaw-session-map.ts
|
|
31226
31325
|
import { readFileSync as readFileSync4 } from "node:fs";
|
|
31227
|
-
import { join as
|
|
31326
|
+
import { join as join7 } from "node:path";
|
|
31228
31327
|
function resolveOwnerDmSession(baseDir, agent) {
|
|
31229
31328
|
try {
|
|
31230
|
-
const path =
|
|
31329
|
+
const path = join7(expandHome(baseDir), "agents", agent, "sessions", "sessions.json");
|
|
31231
31330
|
const map = JSON.parse(readFileSync4(path, "utf8"));
|
|
31232
31331
|
let best = null;
|
|
31233
31332
|
for (const [key, entry] of Object.entries(map)) {
|
|
@@ -31245,11 +31344,11 @@ function resolveOwnerDmSession(baseDir, agent) {
|
|
|
31245
31344
|
|
|
31246
31345
|
// src/memory/openclaw-session-log.ts
|
|
31247
31346
|
import { readFileSync as readFileSync5 } from "node:fs";
|
|
31248
|
-
import { join as
|
|
31347
|
+
import { join as join8 } from "node:path";
|
|
31249
31348
|
function readRecentTurns(baseDir, agent, sessionId, k) {
|
|
31250
31349
|
let raw;
|
|
31251
31350
|
try {
|
|
31252
|
-
raw = readFileSync5(
|
|
31351
|
+
raw = readFileSync5(join8(expandHome(baseDir), "agents", agent, "sessions", `${sessionId}.jsonl`), "utf8");
|
|
31253
31352
|
} catch {
|
|
31254
31353
|
return [];
|
|
31255
31354
|
}
|
|
@@ -31280,7 +31379,7 @@ function readRecentTurns(baseDir, agent, sessionId, k) {
|
|
|
31280
31379
|
|
|
31281
31380
|
// src/memory/openclaw-workspace-facts.ts
|
|
31282
31381
|
import { readdirSync, readFileSync as readFileSync6, statSync as statSync2 } from "node:fs";
|
|
31283
|
-
import { join as
|
|
31382
|
+
import { join as join9 } from "node:path";
|
|
31284
31383
|
var DEFAULT_FACTS_BUDGET = 8e3;
|
|
31285
31384
|
var MEMORY_MD_CAP = 6e3;
|
|
31286
31385
|
var MIN_FRAGMENT = 200;
|
|
@@ -31291,7 +31390,7 @@ function resolveWorkspaceDir(baseDir, agent, override) {
|
|
|
31291
31390
|
const base = expandHome(baseDir);
|
|
31292
31391
|
const isMain2 = agent === "" || agent === "main";
|
|
31293
31392
|
try {
|
|
31294
|
-
const cfg = JSON.parse(readFileSync6(
|
|
31393
|
+
const cfg = JSON.parse(readFileSync6(join9(base, "openclaw.json"), "utf8"));
|
|
31295
31394
|
const agents = cfg?.agents;
|
|
31296
31395
|
if (agents && typeof agents === "object") {
|
|
31297
31396
|
const list = Array.isArray(agents.list) ? agents.list : [];
|
|
@@ -31304,7 +31403,7 @@ function resolveWorkspaceDir(baseDir, agent, override) {
|
|
|
31304
31403
|
}
|
|
31305
31404
|
} catch {
|
|
31306
31405
|
}
|
|
31307
|
-
return isMain2 ?
|
|
31406
|
+
return isMain2 ? join9(base, "workspace") : join9(base, `workspace-${agent}`);
|
|
31308
31407
|
}
|
|
31309
31408
|
var TRUNC = "\u2026[truncated]";
|
|
31310
31409
|
function headSlice(s, n) {
|
|
@@ -31334,7 +31433,7 @@ function readWorkspaceFacts(baseDir, agent, opts) {
|
|
|
31334
31433
|
let truncated = false;
|
|
31335
31434
|
let remaining = budget;
|
|
31336
31435
|
try {
|
|
31337
|
-
const r = readBounded(
|
|
31436
|
+
const r = readBounded(join9(dir, "MEMORY.md"));
|
|
31338
31437
|
if (r.oversize) truncated = true;
|
|
31339
31438
|
else if (r.text && r.text.trim()) {
|
|
31340
31439
|
const { text, clipped } = headSlice(r.text, Math.min(MEMORY_MD_CAP, budget));
|
|
@@ -31347,7 +31446,7 @@ ${TRUNC}` : ""}`);
|
|
|
31347
31446
|
} catch {
|
|
31348
31447
|
}
|
|
31349
31448
|
try {
|
|
31350
|
-
const dailies = readdirSync(
|
|
31449
|
+
const dailies = readdirSync(join9(dir, "memory")).filter((f) => DAILY_RE.test(f)).sort().reverse().slice(0, 2);
|
|
31351
31450
|
for (const f of dailies) {
|
|
31352
31451
|
if (remaining < MIN_FRAGMENT) {
|
|
31353
31452
|
truncated = true;
|
|
@@ -31355,7 +31454,7 @@ ${TRUNC}` : ""}`);
|
|
|
31355
31454
|
}
|
|
31356
31455
|
let r;
|
|
31357
31456
|
try {
|
|
31358
|
-
r = readBounded(
|
|
31457
|
+
r = readBounded(join9(dir, "memory", f));
|
|
31359
31458
|
} catch {
|
|
31360
31459
|
continue;
|
|
31361
31460
|
}
|
|
@@ -32094,14 +32193,14 @@ function parsePayloadMemory(raw) {
|
|
|
32094
32193
|
|
|
32095
32194
|
// src/memory/embedder/client.ts
|
|
32096
32195
|
import { connect } from "node:net";
|
|
32097
|
-
import { existsSync as existsSync3, mkdirSync as
|
|
32196
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync5, readFileSync as readFileSync9, rmSync as rmSync6, statSync as statSync3 } from "node:fs";
|
|
32098
32197
|
import { fileURLToPath } from "node:url";
|
|
32099
32198
|
|
|
32100
32199
|
// src/memory/embedder/download.ts
|
|
32101
32200
|
import { createHash as createHash2, randomBytes as randomBytes6 } from "node:crypto";
|
|
32102
|
-
import { chmodSync as
|
|
32201
|
+
import { chmodSync as chmodSync3, rmSync as rmSync2 } from "node:fs";
|
|
32103
32202
|
import { open } from "node:fs/promises";
|
|
32104
|
-
import { join as
|
|
32203
|
+
import { join as join11 } from "node:path";
|
|
32105
32204
|
init_layout();
|
|
32106
32205
|
var WRONG_TYPE_STRIKES = 3;
|
|
32107
32206
|
var wrongTypeStrikes = /* @__PURE__ */ new Map();
|
|
@@ -32117,8 +32216,8 @@ function removeModelFiles(root3, m) {
|
|
|
32117
32216
|
for (const f of m.files) {
|
|
32118
32217
|
const dir = plainDirChain(root3, [m.modelId, f.sha256], { create: false });
|
|
32119
32218
|
if (!dir) continue;
|
|
32120
|
-
|
|
32121
|
-
rmSync2(
|
|
32219
|
+
chmodSync3(dir, 493);
|
|
32220
|
+
rmSync2(join11(dir, f.name), { force: true });
|
|
32122
32221
|
}
|
|
32123
32222
|
}
|
|
32124
32223
|
var VerifyFailed = class extends Error {
|
|
@@ -32165,7 +32264,7 @@ async function fetchSameOrigin(url, origin, fetchImpl, signal, stallMs, abort) {
|
|
|
32165
32264
|
async function downloadOne(f, o) {
|
|
32166
32265
|
if (wrongTypeAt(filePath(o.root, o.modelId, f))) throw new WrongType("wrong type at model path");
|
|
32167
32266
|
const pdir = plainDirChain(o.root, [".partial"], { create: true, fromModelsDir: true, mode: 448 });
|
|
32168
|
-
const partial =
|
|
32267
|
+
const partial = join11(pdir, randomBytes6(12).toString("hex"));
|
|
32169
32268
|
const fh = await open(partial, "wx", 384);
|
|
32170
32269
|
const ac = new AbortController();
|
|
32171
32270
|
const abort = () => ac.abort();
|
|
@@ -32242,17 +32341,17 @@ async function ensureModelFiles(o) {
|
|
|
32242
32341
|
|
|
32243
32342
|
// src/memory/embedder/gc.ts
|
|
32244
32343
|
init_layout();
|
|
32245
|
-
import { chmodSync as
|
|
32246
|
-
import { join as
|
|
32344
|
+
import { chmodSync as chmodSync4, closeSync, constants as constants2, fstatSync, futimesSync, lstatSync as lstatSync4, openSync, readdirSync as readdirSync2, rmSync as rmSync3 } from "node:fs";
|
|
32345
|
+
import { join as join12 } from "node:path";
|
|
32247
32346
|
var THIRTY_DAYS = 30 * 864e5;
|
|
32248
32347
|
var SAFE_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
32249
32348
|
function touchUserMarker(root3, modelId, identityId) {
|
|
32250
32349
|
if (!SAFE_ID.test(identityId)) throw new Error("invalid identity id for the model marker");
|
|
32251
32350
|
const dir = plainDirChain(root3, [modelId, ".users"], { create: true });
|
|
32252
|
-
const p =
|
|
32351
|
+
const p = join12(dir, identityId);
|
|
32253
32352
|
let fd;
|
|
32254
32353
|
try {
|
|
32255
|
-
fd = openSync(p,
|
|
32354
|
+
fd = openSync(p, constants2.O_WRONLY | constants2.O_CREAT | constants2.O_NOFOLLOW | constants2.O_NONBLOCK, 420);
|
|
32256
32355
|
} catch {
|
|
32257
32356
|
throw new Error("the model marker is not a regular file");
|
|
32258
32357
|
}
|
|
@@ -32266,22 +32365,22 @@ function touchUserMarker(root3, modelId, identityId) {
|
|
|
32266
32365
|
}
|
|
32267
32366
|
function isRealDir(p) {
|
|
32268
32367
|
try {
|
|
32269
|
-
return
|
|
32368
|
+
return lstatSync4(p).isDirectory();
|
|
32270
32369
|
} catch {
|
|
32271
32370
|
return false;
|
|
32272
32371
|
}
|
|
32273
32372
|
}
|
|
32274
32373
|
function makeWritable(p) {
|
|
32275
32374
|
if (!isRealDir(p)) return;
|
|
32276
|
-
|
|
32277
|
-
for (const e of readdirSync2(p)) makeWritable(
|
|
32375
|
+
chmodSync4(p, 493);
|
|
32376
|
+
for (const e of readdirSync2(p)) makeWritable(join12(p, e));
|
|
32278
32377
|
}
|
|
32279
32378
|
function newestMarkerMs(users) {
|
|
32280
32379
|
if (!isRealDir(users)) return void 0;
|
|
32281
32380
|
let newest;
|
|
32282
32381
|
for (const u of readdirSync2(users)) {
|
|
32283
32382
|
try {
|
|
32284
|
-
const s =
|
|
32383
|
+
const s = lstatSync4(join12(users, u));
|
|
32285
32384
|
if (!s.isFile()) continue;
|
|
32286
32385
|
newest = newest === void 0 ? s.mtimeMs : Math.max(newest, s.mtimeMs);
|
|
32287
32386
|
} catch {
|
|
@@ -32294,9 +32393,9 @@ function gcModels(root3, keepModelIds, now, maxAgeMs = THIRTY_DAYS) {
|
|
|
32294
32393
|
const removed = [];
|
|
32295
32394
|
for (const modelId of readdirSync2(root3).sort()) {
|
|
32296
32395
|
if (modelId.startsWith(".") || keepModelIds.includes(modelId)) continue;
|
|
32297
|
-
const tree =
|
|
32396
|
+
const tree = join12(root3, modelId);
|
|
32298
32397
|
if (!isRealDir(tree)) continue;
|
|
32299
|
-
const lastUse = newestMarkerMs(
|
|
32398
|
+
const lastUse = newestMarkerMs(join12(tree, ".users")) ?? lstatSync4(tree).mtimeMs;
|
|
32300
32399
|
if (now - lastUse <= maxAgeMs) continue;
|
|
32301
32400
|
makeWritable(tree);
|
|
32302
32401
|
rmSync3(tree, { recursive: true, force: true });
|
|
@@ -32402,44 +32501,44 @@ var SealedChannel = class {
|
|
|
32402
32501
|
// src/memory/embedder/embedder-paths.ts
|
|
32403
32502
|
import { createHash as createHash3 } from "node:crypto";
|
|
32404
32503
|
import { homedir as homedir3 } from "node:os";
|
|
32405
|
-
import { join as
|
|
32504
|
+
import { join as join13 } from "node:path";
|
|
32406
32505
|
function embedderKey(m) {
|
|
32407
32506
|
const model = m.files.find((f) => f.name === "model.onnx");
|
|
32408
32507
|
return createHash3("sha256").update(`${EMBEDDER_PROTOCOL}\0${m.modelId}\0${model.sha256}\0${m.wasmSha256}`).digest("hex").slice(0, 16);
|
|
32409
32508
|
}
|
|
32410
|
-
var embedderRunDir = (home = homedir3()) =>
|
|
32509
|
+
var embedderRunDir = (home = homedir3()) => join13(home, ".securecoms", "run", "embedder");
|
|
32411
32510
|
var embedderPaths = (dir, key) => ({
|
|
32412
|
-
sock:
|
|
32413
|
-
token:
|
|
32414
|
-
lock:
|
|
32415
|
-
status:
|
|
32416
|
-
pid:
|
|
32511
|
+
sock: join13(dir, `${key}.sock`),
|
|
32512
|
+
token: join13(dir, `${key}.token`),
|
|
32513
|
+
lock: join13(dir, `${key}.spawn.lock`),
|
|
32514
|
+
status: join13(dir, `${key}.status`),
|
|
32515
|
+
pid: join13(dir, `${key}.pid`)
|
|
32417
32516
|
// E1 delta H1: the instance's lifetime lock
|
|
32418
32517
|
});
|
|
32419
32518
|
var SOCKET_PATH_MAX = 103;
|
|
32420
32519
|
var windowsRunDir = (env = process.env) => {
|
|
32421
32520
|
if (!env.LOCALAPPDATA) throw new Error("LOCALAPPDATA unset");
|
|
32422
|
-
return
|
|
32521
|
+
return join13(env.LOCALAPPDATA, "SecureComs", "run", "embedder");
|
|
32423
32522
|
};
|
|
32424
32523
|
|
|
32425
32524
|
// src/memory/embedder/spawn.ts
|
|
32426
32525
|
import { spawn } from "node:child_process";
|
|
32427
|
-
import { existsSync as existsSync2, mkdirSync as
|
|
32526
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync4, realpathSync as realpathSync2 } from "node:fs";
|
|
32428
32527
|
|
|
32429
32528
|
// src/memory/embedder/run-dir.ts
|
|
32430
|
-
import { existsSync, lstatSync as
|
|
32431
|
-
import { dirname as
|
|
32529
|
+
import { existsSync, lstatSync as lstatSync5, mkdirSync as mkdirSync3 } from "node:fs";
|
|
32530
|
+
import { dirname as dirname6 } from "node:path";
|
|
32432
32531
|
var RunDirRefused = class extends Error {
|
|
32433
32532
|
};
|
|
32434
|
-
function ensureRunDir(dir, uid = process.getuid?.() ?? -1, lstat =
|
|
32435
|
-
const parent3 =
|
|
32436
|
-
if (!existsSync(parent3))
|
|
32533
|
+
function ensureRunDir(dir, uid = process.getuid?.() ?? -1, lstat = lstatSync5) {
|
|
32534
|
+
const parent3 = dirname6(dir);
|
|
32535
|
+
if (!existsSync(parent3)) mkdirSync3(parent3, { recursive: true, mode: 448 });
|
|
32437
32536
|
const ps = lstat(parent3);
|
|
32438
32537
|
if (ps.isSymbolicLink() || !ps.isDirectory()) throw new RunDirRefused("run directory parent is not a real directory");
|
|
32439
32538
|
if (ps.uid !== uid) throw new RunDirRefused("run directory parent is not owned by this user");
|
|
32440
32539
|
if ((ps.mode & 18) !== 0) throw new RunDirRefused("run directory parent is group or world writable");
|
|
32441
32540
|
try {
|
|
32442
|
-
|
|
32541
|
+
mkdirSync3(dir, { mode: 448 });
|
|
32443
32542
|
} catch (e) {
|
|
32444
32543
|
if (e.code !== "EEXIST") throw e;
|
|
32445
32544
|
}
|
|
@@ -32450,11 +32549,11 @@ function ensureRunDir(dir, uid = process.getuid?.() ?? -1, lstat = lstatSync4) {
|
|
|
32450
32549
|
}
|
|
32451
32550
|
|
|
32452
32551
|
// src/memory/embedder/spawn.ts
|
|
32453
|
-
import { basename as
|
|
32552
|
+
import { basename as basename4, dirname as dirname7, join as join14 } from "node:path";
|
|
32454
32553
|
init_layout();
|
|
32455
32554
|
|
|
32456
32555
|
// src/memory/embedder/locks.ts
|
|
32457
|
-
import { closeSync as closeSync2, constants as
|
|
32556
|
+
import { closeSync as closeSync2, constants as constants3, fstatSync as fstatSync2, linkSync, openSync as openSync2, readFileSync as readFileSync7, renameSync as renameSync2, rmSync as rmSync4, writeSync } from "node:fs";
|
|
32458
32557
|
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
32459
32558
|
import { uptime } from "node:os";
|
|
32460
32559
|
var LOCK_STALE_MS = 1e4;
|
|
@@ -32476,7 +32575,7 @@ var PROCESS_LOCK_ENV = {
|
|
|
32476
32575
|
function inspect(path) {
|
|
32477
32576
|
let fd;
|
|
32478
32577
|
try {
|
|
32479
|
-
fd = openSync2(path,
|
|
32578
|
+
fd = openSync2(path, constants3.O_RDONLY | constants3.O_NOFOLLOW);
|
|
32480
32579
|
} catch {
|
|
32481
32580
|
return null;
|
|
32482
32581
|
}
|
|
@@ -32500,7 +32599,7 @@ function takeLock(path, now = Date.now, env = PROCESS_LOCK_ENV) {
|
|
|
32500
32599
|
const id = `${env.pid} ${env.bootTime()} ${env.startTime()} ${randomBytes9(8).toString("hex")}`;
|
|
32501
32600
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
32502
32601
|
try {
|
|
32503
|
-
const fd = openSync2(path,
|
|
32602
|
+
const fd = openSync2(path, constants3.O_CREAT | constants3.O_EXCL | constants3.O_WRONLY, 384);
|
|
32504
32603
|
try {
|
|
32505
32604
|
writeSync(fd, id);
|
|
32506
32605
|
} finally {
|
|
@@ -32561,7 +32660,7 @@ function embedderEnv(env = process.env, platform = process.platform) {
|
|
|
32561
32660
|
}
|
|
32562
32661
|
var withReal = (p) => {
|
|
32563
32662
|
try {
|
|
32564
|
-
const r =
|
|
32663
|
+
const r = realpathSync2(p);
|
|
32565
32664
|
return r === p ? [p] : [p, r];
|
|
32566
32665
|
} catch {
|
|
32567
32666
|
return [p];
|
|
@@ -32569,10 +32668,10 @@ var withReal = (p) => {
|
|
|
32569
32668
|
};
|
|
32570
32669
|
var realish = (p) => {
|
|
32571
32670
|
try {
|
|
32572
|
-
return
|
|
32671
|
+
return realpathSync2(p);
|
|
32573
32672
|
} catch {
|
|
32574
|
-
const up =
|
|
32575
|
-
return up === p ? p :
|
|
32673
|
+
const up = dirname7(p);
|
|
32674
|
+
return up === p ? p : join14(realish(up), basename4(p));
|
|
32576
32675
|
}
|
|
32577
32676
|
};
|
|
32578
32677
|
var both = (p) => {
|
|
@@ -32584,7 +32683,7 @@ function spawnEmbedder(o) {
|
|
|
32584
32683
|
const run = o.runDir ?? embedderRunDir(o.home);
|
|
32585
32684
|
const win = (o.platform ?? process.platform) === "win32";
|
|
32586
32685
|
if (o.createRunDir !== false) {
|
|
32587
|
-
if (win)
|
|
32686
|
+
if (win) mkdirSync4(run, { recursive: true, mode: 448 });
|
|
32588
32687
|
else ensureRunDir(run);
|
|
32589
32688
|
}
|
|
32590
32689
|
const perm = permissionFlags();
|
|
@@ -32593,13 +32692,13 @@ function spawnEmbedder(o) {
|
|
|
32593
32692
|
o.onNoPermissionModel?.();
|
|
32594
32693
|
}
|
|
32595
32694
|
const reads = perm.length === 0 ? [] : [
|
|
32596
|
-
...withReal(
|
|
32695
|
+
...withReal(dirname7(o.distDir)),
|
|
32597
32696
|
...existsSync2(defaultModelsRoot(o.home)) ? withReal(defaultModelsRoot(o.home)) : [defaultModelsRoot(o.home)],
|
|
32598
|
-
...both(
|
|
32599
|
-
...win ? both(
|
|
32697
|
+
...both(dirname7(run)),
|
|
32698
|
+
...win ? both(join14(o.home, ".securecoms", "run")) : []
|
|
32600
32699
|
// the voice-call heartbeats (the run dir lives elsewhere)
|
|
32601
32700
|
];
|
|
32602
|
-
const script = withReal(
|
|
32701
|
+
const script = withReal(join14(o.distDir, "embedder.js")).at(-1);
|
|
32603
32702
|
const net = (o.nodeFlags ?? process.allowedNodeEnvironmentFlags).has("--allow-net") ? ["--allow-net"] : [];
|
|
32604
32703
|
const flags = perm.length === 0 ? [] : [...perm, ...reads.map((r) => `--allow-fs-read=${r}`), ...both(run).map((w) => `--allow-fs-write=${w}`), "--allow-worker", ...net];
|
|
32605
32704
|
const child = (o.spawnFn ?? spawn)(
|
|
@@ -32608,7 +32707,7 @@ function spawnEmbedder(o) {
|
|
|
32608
32707
|
// 11c review LOW 3, fixed by the Task 12 Mini gate: cwd is the run directory's PARENT, which the bridge created (0700)
|
|
32609
32708
|
// before spawning; the run directory itself is created by the embedder, so on a first start it does not exist yet and
|
|
32610
32709
|
// a cwd there fails the spawn with ENOENT. Never the bridge's working directory.
|
|
32611
|
-
{ detached: true, stdio: "ignore", windowsHide: true, cwd:
|
|
32710
|
+
{ detached: true, stdio: "ignore", windowsHide: true, cwd: dirname7(run), env: win ? { ...embedderEnv(process.env, "win32"), USERPROFILE: o.home, LOCALAPPDATA: dirname7(dirname7(dirname7(run))) } : { ...embedderEnv(), HOME: o.home } }
|
|
32612
32711
|
);
|
|
32613
32712
|
child.unref();
|
|
32614
32713
|
child.on("error", () => {
|
|
@@ -32620,8 +32719,8 @@ function spawnEmbedder(o) {
|
|
|
32620
32719
|
import { execFile } from "node:child_process";
|
|
32621
32720
|
import { promisify } from "node:util";
|
|
32622
32721
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
32623
|
-
import { lstatSync as
|
|
32624
|
-
import { join as
|
|
32722
|
+
import { lstatSync as lstatSync6, readFileSync as readFileSync8, rmSync as rmSync5 } from "node:fs";
|
|
32723
|
+
import { join as join15, win32 } from "node:path";
|
|
32625
32724
|
var WINDOWS_SEMANTIC_ENABLED = false;
|
|
32626
32725
|
var windowsSemanticOn = (platform, enabled = WINDOWS_SEMANTIC_ENABLED) => platform !== "win32" || enabled;
|
|
32627
32726
|
function parseSaveSddl(saveFile) {
|
|
@@ -32649,7 +32748,7 @@ function aclAllows(sddl, ownerSid) {
|
|
|
32649
32748
|
if (aces.length === 0 || rest !== "" && !rest.startsWith("S:")) return false;
|
|
32650
32749
|
return aces.every((a) => a[0] === "A" && allowed.has(a[5] ?? "") || a[0] === "D");
|
|
32651
32750
|
}
|
|
32652
|
-
function hasReparsePoint(path, lstat =
|
|
32751
|
+
function hasReparsePoint(path, lstat = lstatSync6) {
|
|
32653
32752
|
const root3 = win32.parse(path).root;
|
|
32654
32753
|
let cur = root3;
|
|
32655
32754
|
for (const part of path.slice(root3.length).split(/[\\/]/).filter(Boolean)) {
|
|
@@ -32668,7 +32767,7 @@ async function currentUserSid(run = defaultRunner) {
|
|
|
32668
32767
|
}
|
|
32669
32768
|
async function verifyRunDirAcl(path, deps = {}, sid) {
|
|
32670
32769
|
const run = deps.run ?? defaultRunner;
|
|
32671
|
-
const out =
|
|
32770
|
+
const out = join15(deps.tmp ?? process.env.TEMP ?? process.env.TMP ?? ".", `sc-acl-${randomBytes10(8).toString("hex")}.txt`);
|
|
32672
32771
|
try {
|
|
32673
32772
|
if (hasReparsePoint(path, deps.lstat)) return false;
|
|
32674
32773
|
const user = await (sid ? sid() : currentUserSid(run));
|
|
@@ -32749,12 +32848,12 @@ var EmbedderClient = class {
|
|
|
32749
32848
|
ready(ms) {
|
|
32750
32849
|
if (this.st.state === "ready") return Promise.resolve(true);
|
|
32751
32850
|
if (this.st.state !== "preparing" || !(ms > 0)) return Promise.resolve(false);
|
|
32752
|
-
return new Promise((
|
|
32851
|
+
return new Promise((resolve5) => {
|
|
32753
32852
|
let t;
|
|
32754
32853
|
const w = (ok) => {
|
|
32755
32854
|
clearTimeout(t);
|
|
32756
32855
|
this.readyWaiters.delete(w);
|
|
32757
|
-
|
|
32856
|
+
resolve5(ok);
|
|
32758
32857
|
};
|
|
32759
32858
|
this.readyWaiters.add(w);
|
|
32760
32859
|
t = setTimeout(() => w(false), ms);
|
|
@@ -32863,7 +32962,7 @@ var EmbedderClient = class {
|
|
|
32863
32962
|
const p = this.paths();
|
|
32864
32963
|
if (!this.tcp() && Buffer.byteLength(`${p.sock}.00000000`) > SOCKET_PATH_MAX) return this.fail("run_dir_refused");
|
|
32865
32964
|
if (this.tcp()) {
|
|
32866
|
-
|
|
32965
|
+
mkdirSync5(this.runDir(), { recursive: true, mode: 448 });
|
|
32867
32966
|
if (!await this.aclOk(true)) return this.fail("acl_unverified");
|
|
32868
32967
|
}
|
|
32869
32968
|
if (!this.tcp()) {
|
|
@@ -32999,7 +33098,7 @@ var EmbedderClient = class {
|
|
|
32999
33098
|
}
|
|
33000
33099
|
if (this.closed) return false;
|
|
33001
33100
|
}
|
|
33002
|
-
return new Promise((
|
|
33101
|
+
return new Promise((resolve5) => {
|
|
33003
33102
|
const s = this.tcp() ? connect({ host: "127.0.0.1", port: pub.port }) : connect(p.sock);
|
|
33004
33103
|
const nc = nonce();
|
|
33005
33104
|
let ns = "";
|
|
@@ -33012,7 +33111,7 @@ var EmbedderClient = class {
|
|
|
33012
33111
|
if (!settled) {
|
|
33013
33112
|
settled = true;
|
|
33014
33113
|
clearTimeout(t);
|
|
33015
|
-
|
|
33114
|
+
resolve5(ok);
|
|
33016
33115
|
}
|
|
33017
33116
|
}
|
|
33018
33117
|
const refuse3 = (reason) => {
|
|
@@ -33581,12 +33680,12 @@ var ReembedQueue = class {
|
|
|
33581
33680
|
};
|
|
33582
33681
|
|
|
33583
33682
|
// src/memory/recall/call-heartbeat.ts
|
|
33584
|
-
import { closeSync as closeSync3, constants as
|
|
33585
|
-
import { join as
|
|
33683
|
+
import { closeSync as closeSync3, constants as constants4, fstatSync as fstatSync3, futimesSync as futimesSync2, openSync as openSync3, rmSync as rmSync7 } from "node:fs";
|
|
33684
|
+
import { join as join17 } from "node:path";
|
|
33586
33685
|
|
|
33587
33686
|
// src/memory/embedder/heartbeats.ts
|
|
33588
|
-
import { lstatSync as
|
|
33589
|
-
import { join as
|
|
33687
|
+
import { lstatSync as lstatSync7, readdirSync as readdirSync3 } from "node:fs";
|
|
33688
|
+
import { join as join16 } from "node:path";
|
|
33590
33689
|
var HEARTBEAT_FUTURE_SKEW_MS = 6e4;
|
|
33591
33690
|
var HEARTBEAT_STALE_MS = 3e4;
|
|
33592
33691
|
function heartbeatAgeFresh(ageMs, staleMs = HEARTBEAT_STALE_MS) {
|
|
@@ -33601,7 +33700,7 @@ function anyHeartbeatFresh(dir, now, staleMs = HEARTBEAT_STALE_MS) {
|
|
|
33601
33700
|
}
|
|
33602
33701
|
return names.some((n) => {
|
|
33603
33702
|
try {
|
|
33604
|
-
const st =
|
|
33703
|
+
const st = lstatSync7(join16(dir, n));
|
|
33605
33704
|
return st.isFile() && heartbeatAgeFresh(now - st.mtimeMs, staleMs);
|
|
33606
33705
|
} catch {
|
|
33607
33706
|
return false;
|
|
@@ -33667,7 +33766,7 @@ var CallHeartbeat = class {
|
|
|
33667
33766
|
if (dir === null) return;
|
|
33668
33767
|
let fd;
|
|
33669
33768
|
try {
|
|
33670
|
-
fd = openSync3(
|
|
33769
|
+
fd = openSync3(join17(dir, this.identityId), constants4.O_WRONLY | constants4.O_CREAT | constants4.O_NOFOLLOW | constants4.O_NONBLOCK, 384);
|
|
33671
33770
|
if (!fstatSync3(fd).isFile()) return;
|
|
33672
33771
|
const t = new Date(this.now());
|
|
33673
33772
|
futimesSync2(fd, t, t);
|
|
@@ -33682,7 +33781,7 @@ var CallHeartbeat = class {
|
|
|
33682
33781
|
const dir = SAFE_ID2.test(this.identityId) ? this.dirOk() : null;
|
|
33683
33782
|
if (dir === null) return;
|
|
33684
33783
|
try {
|
|
33685
|
-
rmSync7(
|
|
33784
|
+
rmSync7(join17(dir, this.identityId), { force: true });
|
|
33686
33785
|
this.wrote = false;
|
|
33687
33786
|
} catch (e) {
|
|
33688
33787
|
this.log("warn", "memory.call_heartbeat_failed", {}, e);
|
|
@@ -33745,9 +33844,9 @@ function queryTokenMacs(key, text, max = QUERY_MACS_MAX) {
|
|
|
33745
33844
|
|
|
33746
33845
|
// src/memory/unified/ranking-client.ts
|
|
33747
33846
|
import { Worker } from "node:worker_threads";
|
|
33748
|
-
import { join as
|
|
33847
|
+
import { join as join18 } from "node:path";
|
|
33749
33848
|
function workerTransport(init, distDir) {
|
|
33750
|
-
const w = new Worker(
|
|
33849
|
+
const w = new Worker(join18(distDir, "memory-worker.js"), { workerData: init });
|
|
33751
33850
|
return {
|
|
33752
33851
|
post: (m) => w.postMessage(m),
|
|
33753
33852
|
onMessage: (cb) => {
|
|
@@ -33807,15 +33906,15 @@ var RankingClient = class {
|
|
|
33807
33906
|
ask(build, deadlineAt) {
|
|
33808
33907
|
const id = ++this.seq;
|
|
33809
33908
|
if (this.closed) return Promise.resolve("failed");
|
|
33810
|
-
return new Promise((
|
|
33909
|
+
return new Promise((resolve5) => {
|
|
33811
33910
|
const timer = setTimeout(() => {
|
|
33812
33911
|
this.waiting.delete(id);
|
|
33813
33912
|
this.misses++;
|
|
33814
|
-
|
|
33913
|
+
resolve5("late");
|
|
33815
33914
|
}, Math.max(0, deadlineAt - Date.now()));
|
|
33816
33915
|
this.waiting.set(id, { resolve: (m) => {
|
|
33817
33916
|
clearTimeout(timer);
|
|
33818
|
-
|
|
33917
|
+
resolve5(m);
|
|
33819
33918
|
} });
|
|
33820
33919
|
try {
|
|
33821
33920
|
this.transport().post(build(id));
|
|
@@ -33824,7 +33923,7 @@ var RankingClient = class {
|
|
|
33824
33923
|
this.waiting.delete(id);
|
|
33825
33924
|
this.misses++;
|
|
33826
33925
|
(this.d.log ?? writeServiceLog)("warn", "memory.ranking_worker_spawn_failed", void 0, e);
|
|
33827
|
-
|
|
33926
|
+
resolve5("failed");
|
|
33828
33927
|
}
|
|
33829
33928
|
});
|
|
33830
33929
|
}
|
|
@@ -35152,17 +35251,17 @@ async function runSummarize(opts) {
|
|
|
35152
35251
|
// src/service/runtime-config-dir.ts
|
|
35153
35252
|
import { createHash as createHash5, randomUUID } from "node:crypto";
|
|
35154
35253
|
import {
|
|
35155
|
-
chmodSync as
|
|
35254
|
+
chmodSync as chmodSync5,
|
|
35156
35255
|
existsSync as existsSync4,
|
|
35157
|
-
lstatSync as
|
|
35158
|
-
mkdirSync as
|
|
35256
|
+
lstatSync as lstatSync8,
|
|
35257
|
+
mkdirSync as mkdirSync6,
|
|
35159
35258
|
readFileSync as readFileSync10,
|
|
35160
35259
|
renameSync as renameSync3,
|
|
35161
35260
|
statSync as statSync4,
|
|
35162
35261
|
unlinkSync,
|
|
35163
35262
|
writeFileSync
|
|
35164
35263
|
} from "node:fs";
|
|
35165
|
-
import { basename as
|
|
35264
|
+
import { basename as basename5, isAbsolute, join as join19 } from "node:path";
|
|
35166
35265
|
|
|
35167
35266
|
// src/grants/search-providers.ts
|
|
35168
35267
|
var SEARCH_PROVIDERS = /* @__PURE__ */ new Set(["brave", "tavily", "parallel", "exa", "firecrawl"]);
|
|
@@ -35174,18 +35273,18 @@ function isSearchProvider(value) {
|
|
|
35174
35273
|
// src/service/runtime-config-dir.ts
|
|
35175
35274
|
var MEMORY_FILE = "MEMORY.md";
|
|
35176
35275
|
var REAL_FS = {
|
|
35177
|
-
mkdir: (p, mode) =>
|
|
35178
|
-
chmod: (p, mode) =>
|
|
35276
|
+
mkdir: (p, mode) => mkdirSync6(p, { recursive: true, mode }),
|
|
35277
|
+
chmod: (p, mode) => chmodSync5(p, mode),
|
|
35179
35278
|
writeFile: (p, data, mode) => writeFileSync(p, data, { mode }),
|
|
35180
35279
|
rename: (a, b) => renameSync3(a, b),
|
|
35181
35280
|
readFile: (p) => readFileSync10(p, "utf8"),
|
|
35182
35281
|
unlink: (p) => unlinkSync(p)
|
|
35183
35282
|
};
|
|
35184
35283
|
function runtimeConfigDir(home, identityId) {
|
|
35185
|
-
return
|
|
35284
|
+
return join19(home, ".securecoms", "runtime-config", identityId);
|
|
35186
35285
|
}
|
|
35187
35286
|
function assertManagedName(name) {
|
|
35188
|
-
if (!name || name.includes("/") || name.includes("\\") || name === "." || name === ".." || name !==
|
|
35287
|
+
if (!name || name.includes("/") || name.includes("\\") || name === "." || name === ".." || name !== basename5(name)) {
|
|
35189
35288
|
throw new Error(`refusing managed config file name ${JSON.stringify(name)}: not a plain filename`);
|
|
35190
35289
|
}
|
|
35191
35290
|
if (isLocalOnlyName(name)) {
|
|
@@ -35199,19 +35298,19 @@ function isLocalOnlyName(name) {
|
|
|
35199
35298
|
var MANIFEST_POLICY_FILE = "manifest-policy.json";
|
|
35200
35299
|
function removeManagedLlmSource(home, identityId, deps = REAL_FS) {
|
|
35201
35300
|
try {
|
|
35202
|
-
deps.unlink(
|
|
35301
|
+
deps.unlink(join19(runtimeConfigDir(home, identityId), "llm-source.json"));
|
|
35203
35302
|
} catch (e) {
|
|
35204
35303
|
if (e?.code !== "ENOENT") throw e;
|
|
35205
35304
|
}
|
|
35206
35305
|
}
|
|
35207
35306
|
function writeManifestPolicy(home, identityId, policy, deps = REAL_FS) {
|
|
35208
|
-
const parent3 =
|
|
35307
|
+
const parent3 = join19(home, ".securecoms", "runtime-config");
|
|
35209
35308
|
const dir = runtimeConfigDir(home, identityId);
|
|
35210
|
-
for (const d of [
|
|
35309
|
+
for (const d of [join19(home, ".securecoms"), parent3, dir]) {
|
|
35211
35310
|
deps.mkdir(d, 448);
|
|
35212
35311
|
deps.chmod(d, 448);
|
|
35213
35312
|
}
|
|
35214
|
-
atomicWrite(
|
|
35313
|
+
atomicWrite(join19(dir, MANIFEST_POLICY_FILE), JSON.stringify(policy) + "\n", deps);
|
|
35215
35314
|
}
|
|
35216
35315
|
function atomicWrite(path, body, deps) {
|
|
35217
35316
|
const tmp = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
@@ -35230,13 +35329,13 @@ function atomicWrite(path, body, deps) {
|
|
|
35230
35329
|
function writeManagedFiles(home, identityId, files, deps = REAL_FS) {
|
|
35231
35330
|
const entries = Object.entries(files);
|
|
35232
35331
|
for (const [name] of entries) assertManagedName(name);
|
|
35233
|
-
const parent3 =
|
|
35332
|
+
const parent3 = join19(home, ".securecoms", "runtime-config");
|
|
35234
35333
|
const dir = runtimeConfigDir(home, identityId);
|
|
35235
|
-
for (const d of [
|
|
35334
|
+
for (const d of [join19(home, ".securecoms"), parent3, dir]) {
|
|
35236
35335
|
deps.mkdir(d, 448);
|
|
35237
35336
|
deps.chmod(d, 448);
|
|
35238
35337
|
}
|
|
35239
|
-
for (const [name, body] of entries) atomicWrite(
|
|
35338
|
+
for (const [name, body] of entries) atomicWrite(join19(dir, name), body, deps);
|
|
35240
35339
|
}
|
|
35241
35340
|
function checkConfiguredPaths(skillsJson, statFn = (p) => {
|
|
35242
35341
|
const s = statSync4(p);
|
|
@@ -35315,7 +35414,7 @@ function localLegacySources(doc) {
|
|
|
35315
35414
|
const channelId = source.channelId;
|
|
35316
35415
|
if (kind2 !== "global-memory" && kind2 !== "conversation-history" && kind2 !== "captured-memory" || typeof path !== "string" || !isAbsolute(path) || channelId !== void 0 && typeof channelId !== "string") continue;
|
|
35317
35416
|
try {
|
|
35318
|
-
const st =
|
|
35417
|
+
const st = lstatSync8(path);
|
|
35319
35418
|
if (!st.isFile() || st.isSymbolicLink()) continue;
|
|
35320
35419
|
if (st.size <= LEGACY_MEMORY_SOURCE_MAX_BYTES && st.size > contentBudget) continue;
|
|
35321
35420
|
const oversize = st.size > LEGACY_MEMORY_SOURCE_MAX_BYTES;
|
|
@@ -35343,7 +35442,7 @@ function localLegacySources(doc) {
|
|
|
35343
35442
|
return out;
|
|
35344
35443
|
}
|
|
35345
35444
|
function readLocalReport(home, identityId) {
|
|
35346
|
-
const p =
|
|
35445
|
+
const p = join19(runtimeConfigDir(home, identityId), LOCAL_REPORT_FILE);
|
|
35347
35446
|
if (!existsSync4(p)) return null;
|
|
35348
35447
|
let doc;
|
|
35349
35448
|
try {
|
|
@@ -35378,7 +35477,7 @@ function readLocalReport(home, identityId) {
|
|
|
35378
35477
|
}
|
|
35379
35478
|
function deleteLegacyMemorySources(home, identityId, ids) {
|
|
35380
35479
|
if (ids.length === 0) return 0;
|
|
35381
|
-
const p =
|
|
35480
|
+
const p = join19(runtimeConfigDir(home, identityId), LOCAL_REPORT_FILE);
|
|
35382
35481
|
if (!existsSync4(p)) return 0;
|
|
35383
35482
|
let doc;
|
|
35384
35483
|
try {
|
|
@@ -35421,7 +35520,7 @@ async function applyLegacyMemoryFactDecisions(home, identityId, rawDecisions, re
|
|
|
35421
35520
|
group.set(decision.fact_hash, decision);
|
|
35422
35521
|
bySource.set(decision.source_id, group);
|
|
35423
35522
|
}
|
|
35424
|
-
const reportPath =
|
|
35523
|
+
const reportPath = join19(runtimeConfigDir(home, identityId), LOCAL_REPORT_FILE);
|
|
35425
35524
|
if (!existsSync4(reportPath)) return { sourcesDeleted: 0, factsAssigned: 0 };
|
|
35426
35525
|
let doc;
|
|
35427
35526
|
try {
|
|
@@ -35459,7 +35558,7 @@ async function applyLegacyMemoryFactDecisions(home, identityId, rawDecisions, re
|
|
|
35459
35558
|
}
|
|
35460
35559
|
function pruneManagedMemory(home, identityId, hashes, deps = REAL_FS) {
|
|
35461
35560
|
const dir = runtimeConfigDir(home, identityId);
|
|
35462
|
-
const path =
|
|
35561
|
+
const path = join19(dir, MEMORY_FILE);
|
|
35463
35562
|
if (!existsSync4(path)) return 0;
|
|
35464
35563
|
const drop = new Set(hashes);
|
|
35465
35564
|
const before = deps.readFile(path).split("\n");
|
|
@@ -36501,8 +36600,8 @@ function voiceWindowEligible(t) {
|
|
|
36501
36600
|
}
|
|
36502
36601
|
function waitMs(ms) {
|
|
36503
36602
|
if (ms <= 0) return Promise.resolve();
|
|
36504
|
-
return new Promise((
|
|
36505
|
-
const t = setTimeout(
|
|
36603
|
+
return new Promise((resolve5) => {
|
|
36604
|
+
const t = setTimeout(resolve5, ms);
|
|
36506
36605
|
t.unref?.();
|
|
36507
36606
|
});
|
|
36508
36607
|
}
|
|
@@ -36639,7 +36738,7 @@ var FileOwnerAuthorityStore = class {
|
|
|
36639
36738
|
}
|
|
36640
36739
|
async readAll() {
|
|
36641
36740
|
try {
|
|
36642
|
-
return JSON.parse(await
|
|
36741
|
+
return JSON.parse(await fsp2.readFile(this.path, "utf8"));
|
|
36643
36742
|
} catch (e) {
|
|
36644
36743
|
if (e.code === "ENOENT") return {};
|
|
36645
36744
|
throw e;
|
|
@@ -36652,8 +36751,8 @@ var FileOwnerAuthorityStore = class {
|
|
|
36652
36751
|
async save(enclaveId, pin) {
|
|
36653
36752
|
const all = await this.readAll();
|
|
36654
36753
|
all[enclaveId] = pin;
|
|
36655
|
-
await
|
|
36656
|
-
await
|
|
36754
|
+
await fsp2.mkdir(dirname8(this.path), { recursive: true });
|
|
36755
|
+
await fsp2.writeFile(this.path, JSON.stringify(all), "utf8");
|
|
36657
36756
|
}
|
|
36658
36757
|
};
|
|
36659
36758
|
var AgentPausedSendError = class extends Error {
|
|
@@ -36860,7 +36959,7 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
36860
36959
|
threshold: EMBEDDING_MANIFEST.similarityThreshold,
|
|
36861
36960
|
warm: windowsSemanticOn(this.platform)
|
|
36862
36961
|
};
|
|
36863
|
-
return deps.rankingTransport ? deps.rankingTransport(init) : workerTransport(init,
|
|
36962
|
+
return deps.rankingTransport ? deps.rankingTransport(init) : workerTransport(init, dirname8(fileURLToPath2(import.meta.url)));
|
|
36864
36963
|
}
|
|
36865
36964
|
});
|
|
36866
36965
|
this.embedder = deps.embedder ?? (deps.hostMachine === true && deps.home === void 0 ? new EmbedderClient({ identityId: cfg.identityId, home: homedir4(), source: cfg.modelSource, fetchImpl: this.fetchImpl, platform: this.platform }) : INERT_EMBEDDER);
|
|
@@ -36871,7 +36970,7 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
36871
36970
|
modelId: EMBEDDING_MANIFEST.modelId,
|
|
36872
36971
|
threshold: EMBEDDING_MANIFEST.similarityThreshold
|
|
36873
36972
|
});
|
|
36874
|
-
this.heartbeat = new CallHeartbeat(this.machinePaths ?
|
|
36973
|
+
this.heartbeat = new CallHeartbeat(this.machinePaths ? join20(this.home, ".securecoms", "run", "voice-call") : null, cfg.identityId, VOICE_LIVE_WINDOW_MS);
|
|
36875
36974
|
this.reembed = new ReembedQueue({
|
|
36876
36975
|
store: this.store,
|
|
36877
36976
|
embedder: this.embedder,
|
|
@@ -36930,15 +37029,15 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
36930
37029
|
this.bootDrainWaitMs = deps.bootDrainWaitMs ?? BOOT_DRAIN_WAIT_MS_DEFAULT;
|
|
36931
37030
|
this.searchCapabilityRefetchDebounceMs = deps.searchCapabilityRefetchDebounceMs ?? SEARCH_CAPABILITY_REFETCH_DEBOUNCE_MS;
|
|
36932
37031
|
this.searchCapabilityRefetchMaxWaitMs = deps.searchCapabilityRefetchMaxWaitMs ?? SEARCH_CAPABILITY_REFETCH_MAX_WAIT_MS;
|
|
36933
|
-
this.replySleep = deps.replySleep ?? ((ms) => new Promise((
|
|
36934
|
-
const t = setTimeout(
|
|
37032
|
+
this.replySleep = deps.replySleep ?? ((ms) => new Promise((resolve5) => {
|
|
37033
|
+
const t = setTimeout(resolve5, ms);
|
|
36935
37034
|
t.unref?.();
|
|
36936
37035
|
}));
|
|
36937
37036
|
this.actionRateFloor = new TokenBucketFloor({ capacity: 1, refillPerMinute: 30, now: this.actionClock });
|
|
36938
37037
|
this.globalActionRateFloor = new TokenBucketFloor({ capacity: 1, refillPerMinute: 30, now: this.actionClock });
|
|
36939
37038
|
const self = this;
|
|
36940
37039
|
this.downloadBlobImpl = deps.downloadBlob ?? async function(blobId) {
|
|
36941
|
-
const url = `${cfg.apiBase}/api/v1/attachments/${encodeURIComponent(blobId)}?caller_identity_id=${encodeURIComponent(cfg.identityId)}`;
|
|
37040
|
+
const url = `${cfg.apiBase}/api/v1/attachments/${encodeURIComponent(assertBlobId(blobId))}?caller_identity_id=${encodeURIComponent(cfg.identityId)}`;
|
|
36942
37041
|
const res = await fetchWithDeadline(self.fetchImpl, url, { headers: { authorization: `Bearer ${cfg.apiKey}` } }, {
|
|
36943
37042
|
op: "attachment_download",
|
|
36944
37043
|
timeoutMs: FETCH_DEADLINE_MS.blobBase,
|
|
@@ -36958,8 +37057,9 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
36958
37057
|
const j = await res.json();
|
|
36959
37058
|
return String(j.attachment_id);
|
|
36960
37059
|
};
|
|
36961
|
-
this.attachmentsDirImpl = deps.attachmentsDir ??
|
|
36962
|
-
this.
|
|
37060
|
+
this.attachmentsDirImpl = deps.attachmentsDir ?? join20(dirname8(cfg.storePath), "attachments");
|
|
37061
|
+
this.vaultOutboxDirImpl = deps.vaultOutboxDir !== void 0 ? deps.vaultOutboxDir : cfg.storePath === ":memory:" ? null : join20(dirname8(cfg.storePath), VAULT_OUTBOX_DIRNAME);
|
|
37062
|
+
this.vaultOwnerStoreImpl = deps.vaultOwnerStore ?? new FileOwnerAuthorityStore(join20(dirname8(cfg.storePath), "vault-owner-pins.json"));
|
|
36963
37063
|
this.action = {
|
|
36964
37064
|
begin: (channelId) => this.actionBegin(channelId),
|
|
36965
37065
|
start: (opts) => this.actionStart(opts),
|
|
@@ -37690,6 +37790,9 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
37690
37790
|
uploadBlobImpl;
|
|
37691
37791
|
/** Track 5: directory where received attachments are saved. */
|
|
37692
37792
|
attachmentsDirImpl;
|
|
37793
|
+
vaultOutboxDirImpl;
|
|
37794
|
+
/** Audit 2026-10-30 HIGH 2: the outbox pinned at start(); null = every upload refused. */
|
|
37795
|
+
outboxPin = null;
|
|
37693
37796
|
/** B7: persistence for the vault kekset's owner-pin TOFU state. */
|
|
37694
37797
|
vaultOwnerStoreImpl;
|
|
37695
37798
|
/** B7: last-seen kekset generation per enclave, enforced monotonic across
|
|
@@ -37966,7 +38069,7 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
37966
38069
|
}
|
|
37967
38070
|
/** No manifest in force: a manifest-policy.json left by an earlier one is replaced by an empty tool list. */
|
|
37968
38071
|
overwriteStalePolicy() {
|
|
37969
|
-
if (!existsSync5(
|
|
38072
|
+
if (!existsSync5(join20(runtimeConfigDir(this.home, this.cfg.identityId), "manifest-policy.json"))) return;
|
|
37970
38073
|
this.grantWriters.writeManifestPolicy(this.home, this.cfg.identityId, { v: 1, manifest_tools: [], secret_path_mode: "enforce" });
|
|
37971
38074
|
}
|
|
37972
38075
|
/** The report half of refetchRuntimeConfigOnce (split out for the plan 4 Task 11 bind_failed path). */
|
|
@@ -38133,6 +38236,13 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
38133
38236
|
}
|
|
38134
38237
|
async startBody() {
|
|
38135
38238
|
this.startedAt = Date.now();
|
|
38239
|
+
if (this.vaultOutboxDirImpl) {
|
|
38240
|
+
try {
|
|
38241
|
+
this.outboxPin = ensureOutbox(this.vaultOutboxDirImpl);
|
|
38242
|
+
} catch (e) {
|
|
38243
|
+
writeServiceLog("warn", "vault_outbox.unavailable", {}, e);
|
|
38244
|
+
}
|
|
38245
|
+
}
|
|
38136
38246
|
await this.restoreRuntimeInbox();
|
|
38137
38247
|
await this.loadToolGrantState();
|
|
38138
38248
|
this.recomputeManifestPolicy(NO_FEATURES);
|
|
@@ -38158,8 +38268,8 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
38158
38268
|
const drain = this.ingestOnce().then(() => true, () => true);
|
|
38159
38269
|
const drainedInTime = await Promise.race([
|
|
38160
38270
|
drain,
|
|
38161
|
-
new Promise((
|
|
38162
|
-
const t = setTimeout(() =>
|
|
38271
|
+
new Promise((resolve5) => {
|
|
38272
|
+
const t = setTimeout(() => resolve5(false), this.bootDrainWaitMs);
|
|
38163
38273
|
t.unref?.();
|
|
38164
38274
|
void drain.then(() => clearTimeout(t));
|
|
38165
38275
|
})
|
|
@@ -38169,7 +38279,7 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
38169
38279
|
await this.bootReconcileKeyPackage();
|
|
38170
38280
|
} else {
|
|
38171
38281
|
writeServiceLog("warn", "boot.drain_slow", { wait_ms: this.bootDrainWaitMs });
|
|
38172
|
-
const settled = new Promise((
|
|
38282
|
+
const settled = new Promise((resolve5) => this.ingestSettledWaiters.push(resolve5));
|
|
38173
38283
|
this.deferredBootPublish = settled.then(async () => {
|
|
38174
38284
|
this.bootDrainPending = false;
|
|
38175
38285
|
if (this.closingDown) return;
|
|
@@ -39676,7 +39786,8 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
39676
39786
|
uploadBlob: (ciphertext, channelId) => this.uploadBlobImpl(ciphertext, channelId),
|
|
39677
39787
|
encryptFile,
|
|
39678
39788
|
bytesToBase64: bytesToBase642,
|
|
39679
|
-
|
|
39789
|
+
// Security fix 2026-10-30: attachments upload only from the outbox.
|
|
39790
|
+
readFile: (p) => readOutboxFile(this.outboxPin, p).then((r) => r.bytes)
|
|
39680
39791
|
};
|
|
39681
39792
|
}
|
|
39682
39793
|
receiveDeps() {
|
|
@@ -39686,8 +39797,8 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
39686
39797
|
decryptFile,
|
|
39687
39798
|
computeFileDigest,
|
|
39688
39799
|
base64ToBytes: base64ToBytes2,
|
|
39689
|
-
mkdirp: (d) =>
|
|
39690
|
-
writeFile: (p, data) =>
|
|
39800
|
+
mkdirp: (d) => fsp2.mkdir(d, { recursive: true }).then(() => void 0),
|
|
39801
|
+
writeFile: (p, data) => fsp2.writeFile(p, data)
|
|
39691
39802
|
};
|
|
39692
39803
|
}
|
|
39693
39804
|
async sendAttachment(channelId, filePath2, caption) {
|
|
@@ -39695,8 +39806,11 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
39695
39806
|
const joined = await this.reconcileJoin(channelId);
|
|
39696
39807
|
if (!joined) throw new ChannelPendingError(channelId);
|
|
39697
39808
|
let body;
|
|
39809
|
+
let read;
|
|
39698
39810
|
try {
|
|
39699
|
-
|
|
39811
|
+
read = await readOutboxFile(this.outboxPin, filePath2);
|
|
39812
|
+
const bytes = read.bytes;
|
|
39813
|
+
body = await prepareAttachment(filePath2, caption, channelId, { ...this.sendDeps(), readFile: async () => bytes });
|
|
39700
39814
|
} catch (e) {
|
|
39701
39815
|
if (e.code === "ENOENT" || e.code === "EACCES" || e.code === "ENOTDIR" || e.code === "EISDIR") {
|
|
39702
39816
|
throw new InvalidPathError(filePath2, e);
|
|
@@ -39737,6 +39851,7 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
39737
39851
|
);
|
|
39738
39852
|
this.latency.record("send.total", performance.now() - sendStart);
|
|
39739
39853
|
this.agentHops.noteOwnSend(channelId);
|
|
39854
|
+
await this.consumeUploaded(read);
|
|
39740
39855
|
return { message_id: id, status: "sent" };
|
|
39741
39856
|
}
|
|
39742
39857
|
// ── B7: FileSafe vault commands (loopback boundary) ──────────────────────
|
|
@@ -40262,25 +40377,26 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
40262
40377
|
}
|
|
40263
40378
|
};
|
|
40264
40379
|
}
|
|
40265
|
-
/** Read `path`
|
|
40380
|
+
/** Read `path` from the vault outbox (security fix 2026-10-30; see
|
|
40381
|
+
* ./outbox.ts), encrypt + wrap its DEK under the vault's
|
|
40266
40382
|
* current KEK generation, and create+upload+commit it as a new vault
|
|
40267
40383
|
* file node named `name` (which may differ from `path`'s basename). */
|
|
40268
40384
|
async vaultWrite(enclaveId, vaultChannelId, path, name) {
|
|
40269
|
-
|
|
40270
|
-
let bytes;
|
|
40385
|
+
let read;
|
|
40271
40386
|
try {
|
|
40272
|
-
|
|
40387
|
+
read = await readOutboxFile(this.outboxPin, path);
|
|
40273
40388
|
} catch (e) {
|
|
40274
40389
|
const code = e.code;
|
|
40275
40390
|
if (code === "ENOENT" || code === "EACCES" || code === "ENOTDIR" || code === "EISDIR") throw new InvalidPathError(path, e);
|
|
40276
40391
|
throw e;
|
|
40277
40392
|
}
|
|
40393
|
+
const session = await this.getVaultSession(enclaveId, await this.resolveVaultChannelId(enclaveId, vaultChannelId));
|
|
40278
40394
|
const nodeId = crypto.randomUUID();
|
|
40279
|
-
|
|
40395
|
+
const written = await vaultWriteImpl({
|
|
40280
40396
|
enclaveId,
|
|
40281
40397
|
nodeId,
|
|
40282
40398
|
name,
|
|
40283
|
-
bytes,
|
|
40399
|
+
bytes: read.bytes,
|
|
40284
40400
|
deps: {
|
|
40285
40401
|
exporterKekForGeneration: session.kekForGeneration,
|
|
40286
40402
|
currentGeneration: session.currentGeneration,
|
|
@@ -40289,6 +40405,16 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
40289
40405
|
commitNode: (committedNodeId) => this.vaultCommitNode(enclaveId, committedNodeId)
|
|
40290
40406
|
}
|
|
40291
40407
|
});
|
|
40408
|
+
await this.consumeUploaded(read);
|
|
40409
|
+
return written;
|
|
40410
|
+
}
|
|
40411
|
+
/** Audit 2026-10-30 MED 5: an uploaded file leaves the outbox (no plaintext lingers). Content-free log. */
|
|
40412
|
+
async consumeUploaded(read) {
|
|
40413
|
+
if (!this.outboxPin || !await consumeOutboxFile(this.outboxPin, read)) writeServiceLog("warn", "vault_outbox.consume_failed");
|
|
40414
|
+
}
|
|
40415
|
+
/** Audit 2026-10-30 MED 3: the pinned outbox path, served only on the authenticated GET /v1/vault-outbox. */
|
|
40416
|
+
vaultOutboxPath() {
|
|
40417
|
+
return this.outboxPin?.dir ?? null;
|
|
40292
40418
|
}
|
|
40293
40419
|
/** Download + verify + decrypt a vault file node. Returns the plaintext
|
|
40294
40420
|
* base64-encoded (the loopback boundary is JSON-only, mirroring how
|
|
@@ -42721,13 +42847,13 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
42721
42847
|
throw new Error("summarize_no_runtime");
|
|
42722
42848
|
}
|
|
42723
42849
|
const messages = [{ role: "user", content: prompt }];
|
|
42724
|
-
return new Promise((
|
|
42850
|
+
return new Promise((resolve5, reject) => {
|
|
42725
42851
|
const onAbort = () => reject(new Error("aborted"));
|
|
42726
42852
|
signal.addEventListener("abort", onAbort);
|
|
42727
42853
|
this.fastLlm.complete(messages).then(
|
|
42728
42854
|
(text) => {
|
|
42729
42855
|
signal.removeEventListener("abort", onAbort);
|
|
42730
|
-
|
|
42856
|
+
resolve5(text);
|
|
42731
42857
|
},
|
|
42732
42858
|
(err) => {
|
|
42733
42859
|
signal.removeEventListener("abort", onAbort);
|
|
@@ -43675,7 +43801,7 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
43675
43801
|
return got;
|
|
43676
43802
|
}
|
|
43677
43803
|
const cap = Math.min(waitSeconds, 50) * 1e3;
|
|
43678
|
-
await new Promise((
|
|
43804
|
+
await new Promise((resolve5) => {
|
|
43679
43805
|
let fired = false;
|
|
43680
43806
|
let timer;
|
|
43681
43807
|
const wake = () => {
|
|
@@ -43684,7 +43810,7 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
43684
43810
|
clearTimeout(timer);
|
|
43685
43811
|
const i = this.waiters.indexOf(wake);
|
|
43686
43812
|
if (i >= 0) this.waiters.splice(i, 1);
|
|
43687
|
-
|
|
43813
|
+
resolve5();
|
|
43688
43814
|
};
|
|
43689
43815
|
timer = setTimeout(wake, cap);
|
|
43690
43816
|
this.waiters.push(wake);
|
|
@@ -43727,13 +43853,13 @@ var BridgeAgent = class _BridgeAgent {
|
|
|
43727
43853
|
const bound = b !== null && b.state === "bound" && b.counter === this.toolGrantCounter;
|
|
43728
43854
|
const switchOn = audience === "owner_dm" ? this.ownerDmManifestGrants : audience === "team_room" ? this.roomManifestGrants : false;
|
|
43729
43855
|
const signedNow = new Set(audience && manifest ? manifest.grants[audience] ?? [] : []);
|
|
43730
|
-
const
|
|
43856
|
+
const constants5 = new Set(audience === "owner_dm" ? OWNER_DM_DEFAULT_READ_GRANTS.map((g) => g.tool) : audience === "team_room" ? ROOM_DEFAULT_READ_GRANTS.map((g) => g.tool) : []);
|
|
43731
43857
|
let changed = false;
|
|
43732
43858
|
const out = a.tool_grants.flatMap((g) => {
|
|
43733
43859
|
if (!(g.mode === "read" && g.source === "manifest")) return [g];
|
|
43734
43860
|
if (switchOn && bound && signedNow.has(g.tool)) return [g];
|
|
43735
43861
|
changed = true;
|
|
43736
|
-
return
|
|
43862
|
+
return constants5.has(g.tool) && signedNow.has(g.tool) ? [Object.freeze({ tool: g.tool, mode: "read" })] : [];
|
|
43737
43863
|
});
|
|
43738
43864
|
if (!changed) return m;
|
|
43739
43865
|
return { ...m, authorization: Object.freeze({ ...a, tool_grants: Object.freeze(out) }) };
|
|
@@ -44550,7 +44676,7 @@ ${channelId}`;
|
|
|
44550
44676
|
}
|
|
44551
44677
|
const withheld = new Set(Object.keys(TOOL_FEATURE).filter((t) => !toolAllowedByFeatures(t, features)));
|
|
44552
44678
|
if (withheld.size === 0) return;
|
|
44553
|
-
const path =
|
|
44679
|
+
const path = join20(runtimeConfigDir(this.home, this.cfg.identityId), MANIFEST_POLICY_FILE);
|
|
44554
44680
|
if (!existsSync5(path)) return;
|
|
44555
44681
|
let doc;
|
|
44556
44682
|
try {
|
|
@@ -44775,8 +44901,8 @@ ${channelId}`;
|
|
|
44775
44901
|
let timer;
|
|
44776
44902
|
await Promise.race([
|
|
44777
44903
|
ingest.released,
|
|
44778
|
-
new Promise((
|
|
44779
|
-
timer = setTimeout(
|
|
44904
|
+
new Promise((resolve5) => {
|
|
44905
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44780
44906
|
})
|
|
44781
44907
|
]);
|
|
44782
44908
|
if (timer) clearTimeout(timer);
|
|
@@ -44786,8 +44912,8 @@ ${channelId}`;
|
|
|
44786
44912
|
let timer;
|
|
44787
44913
|
await Promise.race([
|
|
44788
44914
|
starting,
|
|
44789
|
-
new Promise((
|
|
44790
|
-
timer = setTimeout(
|
|
44915
|
+
new Promise((resolve5) => {
|
|
44916
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44791
44917
|
})
|
|
44792
44918
|
]);
|
|
44793
44919
|
if (timer) clearTimeout(timer);
|
|
@@ -44796,8 +44922,8 @@ ${channelId}`;
|
|
|
44796
44922
|
let timer;
|
|
44797
44923
|
await Promise.race([
|
|
44798
44924
|
this.membershipSweepWork,
|
|
44799
|
-
new Promise((
|
|
44800
|
-
timer = setTimeout(
|
|
44925
|
+
new Promise((resolve5) => {
|
|
44926
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44801
44927
|
})
|
|
44802
44928
|
]);
|
|
44803
44929
|
if (timer) clearTimeout(timer);
|
|
@@ -44807,8 +44933,8 @@ ${channelId}`;
|
|
|
44807
44933
|
let timer;
|
|
44808
44934
|
await Promise.race([
|
|
44809
44935
|
this.recallPruneWork,
|
|
44810
|
-
new Promise((
|
|
44811
|
-
timer = setTimeout(
|
|
44936
|
+
new Promise((resolve5) => {
|
|
44937
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44812
44938
|
})
|
|
44813
44939
|
]);
|
|
44814
44940
|
if (timer) clearTimeout(timer);
|
|
@@ -44818,8 +44944,8 @@ ${channelId}`;
|
|
|
44818
44944
|
let timer;
|
|
44819
44945
|
await Promise.race([
|
|
44820
44946
|
this.recallMaintenanceWork,
|
|
44821
|
-
new Promise((
|
|
44822
|
-
timer = setTimeout(
|
|
44947
|
+
new Promise((resolve5) => {
|
|
44948
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44823
44949
|
})
|
|
44824
44950
|
]);
|
|
44825
44951
|
if (timer) clearTimeout(timer);
|
|
@@ -44831,8 +44957,8 @@ ${channelId}`;
|
|
|
44831
44957
|
let timer;
|
|
44832
44958
|
await Promise.race([
|
|
44833
44959
|
Promise.allSettled([...this.recallTapWork]),
|
|
44834
|
-
new Promise((
|
|
44835
|
-
timer = setTimeout(
|
|
44960
|
+
new Promise((resolve5) => {
|
|
44961
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44836
44962
|
})
|
|
44837
44963
|
]);
|
|
44838
44964
|
if (timer) clearTimeout(timer);
|
|
@@ -44841,8 +44967,8 @@ ${channelId}`;
|
|
|
44841
44967
|
let timer;
|
|
44842
44968
|
await Promise.race([
|
|
44843
44969
|
Promise.allSettled([...this.unifiedWork]),
|
|
44844
|
-
new Promise((
|
|
44845
|
-
timer = setTimeout(
|
|
44970
|
+
new Promise((resolve5) => {
|
|
44971
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44846
44972
|
})
|
|
44847
44973
|
]);
|
|
44848
44974
|
if (timer) clearTimeout(timer);
|
|
@@ -44851,8 +44977,8 @@ ${channelId}`;
|
|
|
44851
44977
|
let timer;
|
|
44852
44978
|
await Promise.race([
|
|
44853
44979
|
this.recallPrewarmWork,
|
|
44854
|
-
new Promise((
|
|
44855
|
-
timer = setTimeout(
|
|
44980
|
+
new Promise((resolve5) => {
|
|
44981
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44856
44982
|
})
|
|
44857
44983
|
]);
|
|
44858
44984
|
if (timer) clearTimeout(timer);
|
|
@@ -44862,8 +44988,8 @@ ${channelId}`;
|
|
|
44862
44988
|
let timer;
|
|
44863
44989
|
await Promise.race([
|
|
44864
44990
|
Promise.allSettled([...this.replyWork]),
|
|
44865
|
-
new Promise((
|
|
44866
|
-
timer = setTimeout(
|
|
44991
|
+
new Promise((resolve5) => {
|
|
44992
|
+
timer = setTimeout(resolve5, _BridgeAgent.GRACEFUL_DRAIN_MS);
|
|
44867
44993
|
})
|
|
44868
44994
|
]);
|
|
44869
44995
|
if (timer) clearTimeout(timer);
|
|
@@ -44956,6 +45082,10 @@ var BRIDGE_ERRORS = {
|
|
|
44956
45082
|
// Weather/currency Task 17 (OQ-P1): a send frame's credit is not the closed value, or rides an a2a frame. TERMINAL:
|
|
44957
45083
|
// the inbound is retired, so the model (and the weather call) never runs again for it.
|
|
44958
45084
|
reply_credit_unknown: { http: 400, message: "reply credit not recognised; not sent" },
|
|
45085
|
+
// Security fix 2026-10-30: an upload route was given a path that is not a
|
|
45086
|
+
// regular file directly inside the bridge's vault outbox (`vault_outbox` on
|
|
45087
|
+
// /healthz). Fixed and content-free: the path is never echoed or logged.
|
|
45088
|
+
path_outside_outbox: { http: 400, message: "uploads must come from the bridge vault outbox; copy the file there first" },
|
|
44959
45089
|
internal: { http: 500, message: "internal error" }
|
|
44960
45090
|
};
|
|
44961
45091
|
function errorBody(code, detail) {
|
|
@@ -44995,10 +45125,10 @@ function withManifestCapability(m, manifestConsumer) {
|
|
|
44995
45125
|
if (manifestConsumer) return m;
|
|
44996
45126
|
const a = m.authorization;
|
|
44997
45127
|
if (!a || !a.tool_grants.some(isManifestGrant)) return m;
|
|
44998
|
-
const
|
|
45128
|
+
const constants5 = new Set(a.audience === "owner_dm" || a.audience === "team_room" ? CONSTANT_TOOL_NAMES[a.audience] : []);
|
|
44999
45129
|
const narrowed = a.tool_grants.flatMap((g) => {
|
|
45000
45130
|
if (!isManifestGrant(g)) return [g];
|
|
45001
|
-
return
|
|
45131
|
+
return constants5.has(g.tool) ? [Object.freeze({ tool: g.tool, mode: "read" })] : [];
|
|
45002
45132
|
});
|
|
45003
45133
|
return { ...m, authorization: Object.freeze({ ...a, tool_grants: Object.freeze(narrowed) }) };
|
|
45004
45134
|
}
|
|
@@ -45156,7 +45286,7 @@ function jsonError(res, code, detail) {
|
|
|
45156
45286
|
json(res, httpStatus(code), errorBody(code, detail));
|
|
45157
45287
|
}
|
|
45158
45288
|
function readBody(req, cap) {
|
|
45159
|
-
return new Promise((
|
|
45289
|
+
return new Promise((resolve5, reject) => {
|
|
45160
45290
|
let size = 0;
|
|
45161
45291
|
let done = false;
|
|
45162
45292
|
const chunks = [];
|
|
@@ -45176,7 +45306,7 @@ function readBody(req, cap) {
|
|
|
45176
45306
|
req.on("end", () => {
|
|
45177
45307
|
if (!done) {
|
|
45178
45308
|
done = true;
|
|
45179
|
-
|
|
45309
|
+
resolve5(Buffer.concat(chunks).toString("utf8"));
|
|
45180
45310
|
}
|
|
45181
45311
|
});
|
|
45182
45312
|
req.on("error", (e) => {
|
|
@@ -45254,6 +45384,9 @@ function createHttpServer(agent, opts) {
|
|
|
45254
45384
|
}
|
|
45255
45385
|
return json(res, 200, r);
|
|
45256
45386
|
}
|
|
45387
|
+
if (method === "GET" && path === "/v1/vault-outbox") {
|
|
45388
|
+
return json(res, 200, { path: agent.vaultOutboxPath() });
|
|
45389
|
+
}
|
|
45257
45390
|
if (method === "POST" && path === "/v1/send-attachment") {
|
|
45258
45391
|
const parsed = sendAttachmentSchema.safeParse(JSON.parse(await readBody(req, OTHER_CAP)));
|
|
45259
45392
|
if (!parsed.success) return jsonError(res, "invalid_request", parsed.error.issues);
|
|
@@ -45365,6 +45498,10 @@ function createHttpServer(agent, opts) {
|
|
|
45365
45498
|
if (e instanceof SendForbiddenError) return jsonError(res, "send_forbidden");
|
|
45366
45499
|
if (e instanceof GroupSupersededSendError) return jsonError(res, "group_superseded");
|
|
45367
45500
|
if (e instanceof IdempotencyConflictError) return jsonError(res, "invalid_request", e.message);
|
|
45501
|
+
if (e instanceof PathOutsideOutboxError) {
|
|
45502
|
+
writeServiceLog("warn", "vault_outbox.refused");
|
|
45503
|
+
return jsonError(res, "path_outside_outbox");
|
|
45504
|
+
}
|
|
45368
45505
|
if (e instanceof InvalidPathError) return jsonError(res, "invalid_request", e.message);
|
|
45369
45506
|
if (e instanceof VaultPinMismatchError) return jsonError(res, "vault_ref_changed", { pin: e.pin });
|
|
45370
45507
|
if (e instanceof VaultIntegrityError) return jsonError(res, "vault_integrity_failed", e.message);
|
|
@@ -45966,18 +46103,18 @@ async function handleInbound(sock, agent, data, inflight, flush, session) {
|
|
|
45966
46103
|
var LOWER_UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
45967
46104
|
|
|
45968
46105
|
// src/bin.ts
|
|
45969
|
-
import { readFileSync as readFileSync17, mkdirSync as
|
|
45970
|
-
import { join as
|
|
46106
|
+
import { readFileSync as readFileSync17, mkdirSync as mkdirSync9, writeFileSync as writeFileSync5, rmSync as rmSync8, existsSync as existsSync7, realpathSync as realpathSync4, readdirSync as readdirSync4, statSync as statSync8, chmodSync as chmodSync7 } from "node:fs";
|
|
46107
|
+
import { join as join26, dirname as dirname14, isAbsolute as isAbsolute3, resolve as resolve4 } from "node:path";
|
|
45971
46108
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
45972
46109
|
import { homedir as homedir5, userInfo } from "node:os";
|
|
45973
46110
|
import { spawnSync } from "node:child_process";
|
|
45974
46111
|
import { createServer as netCreateServer } from "node:net";
|
|
45975
46112
|
|
|
45976
46113
|
// src/service/install.ts
|
|
45977
|
-
import { dirname as
|
|
46114
|
+
import { dirname as dirname9 } from "node:path";
|
|
45978
46115
|
|
|
45979
46116
|
// src/service/config.ts
|
|
45980
|
-
import { basename as
|
|
46117
|
+
import { basename as basename6, extname, isAbsolute as isAbsolute2, resolve as resolve2 } from "node:path";
|
|
45981
46118
|
|
|
45982
46119
|
// src/service/resolve-node.ts
|
|
45983
46120
|
var REQUIRED_NODE_MAJOR = 24;
|
|
@@ -46055,11 +46192,11 @@ function deriveServiceConfig(input) {
|
|
|
46055
46192
|
`The Node at ${input.execPath} moves when it is upgraded, so the background service can't use it. Install Node ${REQUIRED_NODE_MAJOR} from https://nodejs.org, then run the install command again.`
|
|
46056
46193
|
);
|
|
46057
46194
|
}
|
|
46058
|
-
const stem = input.label ??
|
|
46195
|
+
const stem = input.label ?? basename6(input.credentialPath, extname(input.credentialPath));
|
|
46059
46196
|
const slug = slugify(stem);
|
|
46060
|
-
const cred = isAbsolute2(input.credentialPath) ? input.credentialPath :
|
|
46197
|
+
const cred = isAbsolute2(input.credentialPath) ? input.credentialPath : resolve2(input.credentialPath);
|
|
46061
46198
|
const args2 = ["--credential", cred];
|
|
46062
|
-
if (input.storePath) args2.push("--store", isAbsolute2(input.storePath) ? input.storePath :
|
|
46199
|
+
if (input.storePath) args2.push("--store", isAbsolute2(input.storePath) ? input.storePath : resolve2(input.storePath));
|
|
46063
46200
|
if (input.port != null) args2.push("--port", String(input.port));
|
|
46064
46201
|
return {
|
|
46065
46202
|
slug,
|
|
@@ -46154,7 +46291,7 @@ function waitForPreviousExit(deps, pid) {
|
|
|
46154
46291
|
}
|
|
46155
46292
|
}
|
|
46156
46293
|
function tokenHint(input) {
|
|
46157
|
-
return `${
|
|
46294
|
+
return `${dirname9(input.credentialPath)}/bridge-token`;
|
|
46158
46295
|
}
|
|
46159
46296
|
function requireOk(r, what) {
|
|
46160
46297
|
if (r.status !== 0) throw new Error(`${what} failed (exit ${r.status})${r.stderr ? `: ${r.stderr.trim()}` : ""}`);
|
|
@@ -46162,8 +46299,8 @@ function requireOk(r, what) {
|
|
|
46162
46299
|
function installService(input, deps) {
|
|
46163
46300
|
const cfg = deriveServiceConfig(input);
|
|
46164
46301
|
if (deps.platform === "darwin") {
|
|
46165
|
-
deps.mkdirp(
|
|
46166
|
-
deps.mkdirp(
|
|
46302
|
+
deps.mkdirp(dirname9(cfg.plistPath));
|
|
46303
|
+
deps.mkdirp(dirname9(cfg.logPath));
|
|
46167
46304
|
deps.writeFile(cfg.plistPath, renderLaunchdPlist(cfg));
|
|
46168
46305
|
const target = `gui/${cfg.uid}/${cfg.label}`;
|
|
46169
46306
|
const previousPid = launchdPid(deps, target);
|
|
@@ -46175,7 +46312,7 @@ function installService(input, deps) {
|
|
|
46175
46312
|
return { label: cfg.label, filePath: cfg.plistPath, logHint: cfg.logPath, tokenHint: tokenHint(input) };
|
|
46176
46313
|
}
|
|
46177
46314
|
if (deps.platform === "linux") {
|
|
46178
|
-
deps.mkdirp(
|
|
46315
|
+
deps.mkdirp(dirname9(cfg.unitPath));
|
|
46179
46316
|
deps.writeFile(cfg.unitPath, renderSystemdUnit(cfg));
|
|
46180
46317
|
deps.run("systemctl", ["--user", "daemon-reload"]);
|
|
46181
46318
|
deps.run("loginctl", ["enable-linger", deps.user]);
|
|
@@ -46204,10 +46341,10 @@ function uninstallService(input, deps) {
|
|
|
46204
46341
|
}
|
|
46205
46342
|
|
|
46206
46343
|
// src/service/install-prep.ts
|
|
46207
|
-
import { join as
|
|
46344
|
+
import { join as join22 } from "node:path";
|
|
46208
46345
|
|
|
46209
46346
|
// src/service/wire.ts
|
|
46210
|
-
import { join as
|
|
46347
|
+
import { join as join21, dirname as dirname10 } from "node:path";
|
|
46211
46348
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
46212
46349
|
|
|
46213
46350
|
// src/service/hermes-config.ts
|
|
@@ -46382,8 +46519,8 @@ function checkBindingConflict(prev, next, allowRebind) {
|
|
|
46382
46519
|
};
|
|
46383
46520
|
}
|
|
46384
46521
|
function connectorsSrcDir(importMetaUrl, harness) {
|
|
46385
|
-
const pkgRoot =
|
|
46386
|
-
return
|
|
46522
|
+
const pkgRoot = dirname10(dirname10(fileURLToPath3(importMetaUrl)));
|
|
46523
|
+
return join21(pkgRoot, "connectors", harness);
|
|
46387
46524
|
}
|
|
46388
46525
|
function hermesConfigPath(home) {
|
|
46389
46526
|
return `${home}/.hermes/config.yaml`;
|
|
@@ -46645,10 +46782,10 @@ function assertReadableCredential(absPath, deps) {
|
|
|
46645
46782
|
return { deviceId: json2.device_id, identityId: json2.identity_id, issuedAt };
|
|
46646
46783
|
}
|
|
46647
46784
|
function durableDir(home, slug) {
|
|
46648
|
-
return
|
|
46785
|
+
return join22(home, `securecoms-agent-${slug}`);
|
|
46649
46786
|
}
|
|
46650
46787
|
function durableCredentialPath(home, slug) {
|
|
46651
|
-
return
|
|
46788
|
+
return join22(durableDir(home, slug), `${slug}.json`);
|
|
46652
46789
|
}
|
|
46653
46790
|
var DURABLE_PREFIX = "securecoms-agent-";
|
|
46654
46791
|
var InstallRefusedError = class extends Error {
|
|
@@ -46669,8 +46806,8 @@ function refuseExistingIdentity(args2, deps) {
|
|
|
46669
46806
|
const others = names.filter((n) => n.startsWith(DURABLE_PREFIX) && n !== destName).sort();
|
|
46670
46807
|
for (const name of [destName, ...others]) {
|
|
46671
46808
|
const slug = name.slice(DURABLE_PREFIX.length);
|
|
46672
|
-
const dir =
|
|
46673
|
-
const credPath =
|
|
46809
|
+
const dir = join22(args2.home, name);
|
|
46810
|
+
const credPath = join22(dir, `${slug}.json`);
|
|
46674
46811
|
if (!deps.fileExists(credPath)) continue;
|
|
46675
46812
|
let existing = null;
|
|
46676
46813
|
try {
|
|
@@ -46679,7 +46816,7 @@ function refuseExistingIdentity(args2, deps) {
|
|
|
46679
46816
|
} catch {
|
|
46680
46817
|
}
|
|
46681
46818
|
if (!existing || typeof existing.identity_id !== "string" || !existing.identity_id) {
|
|
46682
|
-
if (deps.fileExists(
|
|
46819
|
+
if (deps.fileExists(join22(dir, "bridge-state.db"))) throw existingIdentityError(dir, slug);
|
|
46683
46820
|
continue;
|
|
46684
46821
|
}
|
|
46685
46822
|
if (existing.identity_id !== args2.parsed.identityId) continue;
|
|
@@ -46734,7 +46871,7 @@ function readSiblingDefs(dir, prefix, deps) {
|
|
|
46734
46871
|
for (const n of names) {
|
|
46735
46872
|
if (!n.startsWith(prefix)) continue;
|
|
46736
46873
|
try {
|
|
46737
|
-
out.push(deps.readFile(
|
|
46874
|
+
out.push(deps.readFile(join22(dir, n)));
|
|
46738
46875
|
} catch {
|
|
46739
46876
|
}
|
|
46740
46877
|
}
|
|
@@ -46815,7 +46952,7 @@ async function orchestrateInstall(ctx) {
|
|
|
46815
46952
|
}
|
|
46816
46953
|
|
|
46817
46954
|
// src/service/fleet.ts
|
|
46818
|
-
import { dirname as
|
|
46955
|
+
import { dirname as dirname11 } from "node:path";
|
|
46819
46956
|
function parseArgFromDef(def, flag) {
|
|
46820
46957
|
const esc = flag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46821
46958
|
const re = new RegExp(`${esc}(?:<\\/string>\\s*<string>|\\s+)([^<\\s]+)`);
|
|
@@ -46859,7 +46996,7 @@ function readFleet(deps) {
|
|
|
46859
46996
|
let identityId = `unknown:${slug}`, deviceId = "", label = slug, env = "unknown";
|
|
46860
46997
|
let credDir = null;
|
|
46861
46998
|
if (credPath) {
|
|
46862
|
-
credDir =
|
|
46999
|
+
credDir = dirname11(credPath);
|
|
46863
47000
|
try {
|
|
46864
47001
|
const c = JSON.parse(deps.readFile(credPath));
|
|
46865
47002
|
if (c.identity_id) identityId = c.identity_id;
|
|
@@ -46927,31 +47064,31 @@ function renderStatusTable(rows) {
|
|
|
46927
47064
|
|
|
46928
47065
|
// src/service/connection-file.ts
|
|
46929
47066
|
import {
|
|
46930
|
-
chmodSync as
|
|
46931
|
-
mkdirSync as
|
|
47067
|
+
chmodSync as chmodSync6,
|
|
47068
|
+
mkdirSync as mkdirSync7,
|
|
46932
47069
|
readFileSync as readFileSync13,
|
|
46933
47070
|
renameSync as renameSync4,
|
|
46934
47071
|
unlinkSync as unlinkSync2,
|
|
46935
47072
|
writeFileSync as writeFileSync3
|
|
46936
47073
|
} from "node:fs";
|
|
46937
47074
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
46938
|
-
import { join as
|
|
47075
|
+
import { join as join23 } from "node:path";
|
|
46939
47076
|
var REAL_FS2 = {
|
|
46940
|
-
mkdir: (p, mode) =>
|
|
46941
|
-
chmod: (p, mode) =>
|
|
47077
|
+
mkdir: (p, mode) => mkdirSync7(p, { recursive: true, mode }),
|
|
47078
|
+
chmod: (p, mode) => chmodSync6(p, mode),
|
|
46942
47079
|
writeFile: (p, data, mode) => writeFileSync3(p, data, { mode }),
|
|
46943
47080
|
rename: (a, b) => renameSync4(a, b),
|
|
46944
47081
|
readFile: (p) => readFileSync13(p, "utf8"),
|
|
46945
47082
|
unlink: (p) => unlinkSync2(p)
|
|
46946
47083
|
};
|
|
46947
47084
|
function securecomsDir(home) {
|
|
46948
|
-
return
|
|
47085
|
+
return join23(home, ".securecoms");
|
|
46949
47086
|
}
|
|
46950
47087
|
function connectionsDir(home) {
|
|
46951
|
-
return
|
|
47088
|
+
return join23(securecomsDir(home), "connections");
|
|
46952
47089
|
}
|
|
46953
47090
|
function connectionFilePath(home, identityId) {
|
|
46954
|
-
return
|
|
47091
|
+
return join23(connectionsDir(home), `${identityId}.json`);
|
|
46955
47092
|
}
|
|
46956
47093
|
function newInstanceId() {
|
|
46957
47094
|
return randomUUID2();
|
|
@@ -46990,9 +47127,9 @@ function removeConnectionFileIfOwned(home, identityId, instanceId, deps = REAL_F
|
|
|
46990
47127
|
|
|
46991
47128
|
// src/service/instance-lock.ts
|
|
46992
47129
|
import { execFileSync } from "node:child_process";
|
|
46993
|
-
import { closeSync as closeSync4, fsyncSync, mkdirSync as
|
|
47130
|
+
import { closeSync as closeSync4, fsyncSync, mkdirSync as mkdirSync8, openSync as openSync4, readFileSync as readFileSync14, statSync as statSync6, unlinkSync as unlinkSync3, utimesSync, writeSync as writeSync2 } from "node:fs";
|
|
46994
47131
|
import { hostname, uptime as uptime2 } from "node:os";
|
|
46995
|
-
import { dirname as
|
|
47132
|
+
import { dirname as dirname12 } from "node:path";
|
|
46996
47133
|
var LOCK_PARTIAL_WRITE_GRACE_MS = 1e4;
|
|
46997
47134
|
var LOCK_TAKEOVER_GUARD_STALE_MS = 3e4;
|
|
46998
47135
|
var BOOT_TOLERANCE_SEC = 120;
|
|
@@ -47221,7 +47358,7 @@ var InstanceLock = class {
|
|
|
47221
47358
|
create() {
|
|
47222
47359
|
let fd;
|
|
47223
47360
|
try {
|
|
47224
|
-
|
|
47361
|
+
mkdirSync8(dirname12(this.path), { recursive: true, mode: 448 });
|
|
47225
47362
|
fd = openSync4(this.path, "wx", 384);
|
|
47226
47363
|
} catch (error) {
|
|
47227
47364
|
if (errno(error) === "EEXIST") return "exists";
|
|
@@ -47312,15 +47449,15 @@ import {
|
|
|
47312
47449
|
closeSync as closeSync5,
|
|
47313
47450
|
fchmodSync,
|
|
47314
47451
|
fsyncSync as fsyncSync2,
|
|
47315
|
-
lstatSync as
|
|
47452
|
+
lstatSync as lstatSync9,
|
|
47316
47453
|
openSync as openSync5,
|
|
47317
47454
|
readFileSync as readFileSync15,
|
|
47318
|
-
realpathSync as
|
|
47455
|
+
realpathSync as realpathSync3,
|
|
47319
47456
|
renameSync as renameSync5,
|
|
47320
47457
|
unlinkSync as unlinkSync4,
|
|
47321
47458
|
writeSync as writeSync3
|
|
47322
47459
|
} from "node:fs";
|
|
47323
|
-
import { dirname as
|
|
47460
|
+
import { dirname as dirname13, join as join24, resolve as resolve3 } from "node:path";
|
|
47324
47461
|
var PIN_COPY = Object.freeze({
|
|
47325
47462
|
saved: "pin saved. Restart the Connector to use it.",
|
|
47326
47463
|
// [COPY, approved by Eric 2026-10-12]
|
|
@@ -47344,7 +47481,7 @@ var PIN_COPY = Object.freeze({
|
|
|
47344
47481
|
var refuse2 = (reason) => ({ ok: false, reason });
|
|
47345
47482
|
function isSymlink(path) {
|
|
47346
47483
|
try {
|
|
47347
|
-
return
|
|
47484
|
+
return lstatSync9(path).isSymbolicLink();
|
|
47348
47485
|
} catch (e) {
|
|
47349
47486
|
if (e?.code === "ENOENT") return null;
|
|
47350
47487
|
throw e;
|
|
@@ -47368,10 +47505,10 @@ function writeTemp(path, bytes) {
|
|
|
47368
47505
|
}
|
|
47369
47506
|
}
|
|
47370
47507
|
function runPinCommand(opts) {
|
|
47371
|
-
const credDir =
|
|
47372
|
-
const target =
|
|
47508
|
+
const credDir = dirname13(resolve3(opts.credentialPath));
|
|
47509
|
+
const target = join24(credDir, PIN_FILE_NAME);
|
|
47373
47510
|
try {
|
|
47374
|
-
if (
|
|
47511
|
+
if (realpathSync3(dirname13(resolve3(opts.pinSourcePath))) !== realpathSync3(credDir)) return refuse2("directory_mismatch");
|
|
47375
47512
|
} catch {
|
|
47376
47513
|
return refuse2("io_error");
|
|
47377
47514
|
}
|
|
@@ -47413,7 +47550,7 @@ function runPinCommand(opts) {
|
|
|
47413
47550
|
const pinBytes = JSON.stringify(pinObject, null, 2) + "\n";
|
|
47414
47551
|
const credBytes = JSON.stringify({ ...cred, owner_signing_key: pinObject }, null, 2) + "\n";
|
|
47415
47552
|
const pinTmp = `${target}.tmp-${process.pid}`;
|
|
47416
|
-
const credTmp = `${
|
|
47553
|
+
const credTmp = `${resolve3(opts.credentialPath)}.tmp-${process.pid}`;
|
|
47417
47554
|
const created = [];
|
|
47418
47555
|
const fail = () => {
|
|
47419
47556
|
for (const p of created) {
|
|
@@ -47447,7 +47584,7 @@ function runPinCommand(opts) {
|
|
|
47447
47584
|
created.splice(created.indexOf(pinTmp), 1);
|
|
47448
47585
|
step("pin_renamed");
|
|
47449
47586
|
try {
|
|
47450
|
-
renameSync5(credTmp,
|
|
47587
|
+
renameSync5(credTmp, resolve3(opts.credentialPath));
|
|
47451
47588
|
} catch {
|
|
47452
47589
|
return fail();
|
|
47453
47590
|
}
|
|
@@ -47528,7 +47665,7 @@ function parseVerb(argv) {
|
|
|
47528
47665
|
return v === "install" || v === "uninstall" || v === "status" || v === "wire" || v === "unwire" || v === "models" || v === "pin" ? v : null;
|
|
47529
47666
|
}
|
|
47530
47667
|
function slugFromCredentialPath(credentialPath) {
|
|
47531
|
-
const dir =
|
|
47668
|
+
const dir = dirname14(credentialPath);
|
|
47532
47669
|
const base = dir.split(/[\\/]/).pop() ?? "";
|
|
47533
47670
|
const m = base.match(/^securecoms-agent-(.+)$/);
|
|
47534
47671
|
if (m) return m[1];
|
|
@@ -47544,7 +47681,7 @@ function realServiceDeps() {
|
|
|
47544
47681
|
},
|
|
47545
47682
|
writeFile: (p, data) => writeFileSync5(p, data, { mode: 420 }),
|
|
47546
47683
|
removeFile: (p) => rmSync8(p, { force: true }),
|
|
47547
|
-
mkdirp: (p) =>
|
|
47684
|
+
mkdirp: (p) => mkdirSync9(p, { recursive: true }),
|
|
47548
47685
|
fileExists: (p) => existsSync7(p),
|
|
47549
47686
|
user: userInfo().username,
|
|
47550
47687
|
pidAlive: pidAliveByKill,
|
|
@@ -47574,7 +47711,7 @@ function realResolveNodeDeps() {
|
|
|
47574
47711
|
return m ? Number(m[1]) : null;
|
|
47575
47712
|
};
|
|
47576
47713
|
return {
|
|
47577
|
-
realpath: (p) =>
|
|
47714
|
+
realpath: (p) => realpathSync4(p),
|
|
47578
47715
|
fileExists: (p) => existsSync7(p),
|
|
47579
47716
|
nodeMajorOf: majorOf,
|
|
47580
47717
|
arch: () => process.arch,
|
|
@@ -47598,10 +47735,10 @@ function realPrepDeps() {
|
|
|
47598
47735
|
readFile: (p) => readFileSync17(p, "utf8"),
|
|
47599
47736
|
writeFileMode: (p, data, mode) => writeFileSync5(p, data, { mode }),
|
|
47600
47737
|
mkdirp: (p, mode) => {
|
|
47601
|
-
|
|
47738
|
+
mkdirSync9(p, { recursive: true, mode: mode ?? 493 });
|
|
47602
47739
|
},
|
|
47603
47740
|
fileExists: (p) => existsSync7(p),
|
|
47604
|
-
realpath: (p) =>
|
|
47741
|
+
realpath: (p) => realpathSync4(p),
|
|
47605
47742
|
listDir: (p) => {
|
|
47606
47743
|
try {
|
|
47607
47744
|
return readdirSync4(p);
|
|
@@ -47663,33 +47800,33 @@ function runStatus() {
|
|
|
47663
47800
|
}
|
|
47664
47801
|
function realCopyConnector(srcDir, dstDir, harness) {
|
|
47665
47802
|
const allowedExt = CONNECTOR_FILE_EXTENSIONS[harness];
|
|
47666
|
-
|
|
47803
|
+
mkdirSync9(dstDir, { recursive: true });
|
|
47667
47804
|
for (const name of readdirSync4(srcDir)) {
|
|
47668
|
-
const srcPath =
|
|
47805
|
+
const srcPath = join26(srcDir, name);
|
|
47669
47806
|
if (statSync8(srcPath).isDirectory()) {
|
|
47670
47807
|
if (CONNECTOR_SKIP_DIRS.has(name)) continue;
|
|
47671
|
-
realCopyConnector(srcPath,
|
|
47808
|
+
realCopyConnector(srcPath, join26(dstDir, name), harness);
|
|
47672
47809
|
continue;
|
|
47673
47810
|
}
|
|
47674
47811
|
if (name.includes(".test.")) continue;
|
|
47675
47812
|
if (!allowedExt.some((ext) => name.endsWith(ext))) continue;
|
|
47676
|
-
writeFileSync5(
|
|
47813
|
+
writeFileSync5(join26(dstDir, name), readFileSync17(srcPath));
|
|
47677
47814
|
}
|
|
47678
47815
|
}
|
|
47679
47816
|
function realWriteBinding(dstDir, identityId) {
|
|
47680
|
-
|
|
47681
|
-
writeFileSync5(
|
|
47817
|
+
mkdirSync9(dstDir, { recursive: true });
|
|
47818
|
+
writeFileSync5(join26(dstDir, "securecoms.binding.json"), JSON.stringify({ identity_id: identityId }) + "\n", { mode: 384 });
|
|
47682
47819
|
}
|
|
47683
47820
|
function realReadBinding(dstDir) {
|
|
47684
47821
|
try {
|
|
47685
|
-
const parsed = JSON.parse(readFileSync17(
|
|
47822
|
+
const parsed = JSON.parse(readFileSync17(join26(dstDir, "securecoms.binding.json"), "utf8"));
|
|
47686
47823
|
return parsed.identity_id ?? null;
|
|
47687
47824
|
} catch {
|
|
47688
47825
|
return null;
|
|
47689
47826
|
}
|
|
47690
47827
|
}
|
|
47691
47828
|
function realRemoveBinding(dstDir) {
|
|
47692
|
-
rmSync8(
|
|
47829
|
+
rmSync8(join26(dstDir, "securecoms.binding.json"), { force: true });
|
|
47693
47830
|
}
|
|
47694
47831
|
function realStatDir(p) {
|
|
47695
47832
|
try {
|
|
@@ -47765,7 +47902,7 @@ async function runServiceVerb(verb) {
|
|
|
47765
47902
|
}
|
|
47766
47903
|
try {
|
|
47767
47904
|
if (verb === "install") {
|
|
47768
|
-
const credAbs = isAbsolute3(credentialPath) ? credentialPath :
|
|
47905
|
+
const credAbs = isAbsolute3(credentialPath) ? credentialPath : resolve4(credentialPath);
|
|
47769
47906
|
const installExecPath = chooseInstallExecPath(
|
|
47770
47907
|
process.execPath,
|
|
47771
47908
|
argOrEnv("--exec-path", "SECURECOMS_EXEC_PATH"),
|
|
@@ -47976,11 +48113,11 @@ async function runMode(deps) {
|
|
|
47976
48113
|
refuse3("identity_id_invalid", { field: "identity_id" });
|
|
47977
48114
|
return deps.exit(1);
|
|
47978
48115
|
}
|
|
47979
|
-
const lockDir =
|
|
47980
|
-
const lockPath =
|
|
48116
|
+
const lockDir = join26(deps.home, ".securecoms", "locks");
|
|
48117
|
+
const lockPath = join26(lockDir, `${cfg.identityId.toLowerCase()}.lock`);
|
|
47981
48118
|
try {
|
|
47982
|
-
|
|
47983
|
-
|
|
48119
|
+
mkdirSync9(lockDir, { recursive: true, mode: 448 });
|
|
48120
|
+
chmodSync7(lockDir, 448);
|
|
47984
48121
|
} catch (e) {
|
|
47985
48122
|
log("error", "startup.instance_lock_failed", {}, e);
|
|
47986
48123
|
return deps.exit(1);
|
|
@@ -48027,7 +48164,7 @@ async function runMode(deps) {
|
|
|
48027
48164
|
return deps.exit(1);
|
|
48028
48165
|
}
|
|
48029
48166
|
deps.onExit(() => lock.release());
|
|
48030
|
-
const tokenFile = daemon.tokenFile ??
|
|
48167
|
+
const tokenFile = daemon.tokenFile ?? join26(dirname14(credentialPath), "bridge-token");
|
|
48031
48168
|
const token = resolveToken({ tokenFile, token: daemon.token });
|
|
48032
48169
|
const preBound = deps.net.createServer((sock) => sock.destroy());
|
|
48033
48170
|
const bindError = await new Promise((resolveBind) => {
|
|
@@ -48176,7 +48313,7 @@ async function main() {
|
|
|
48176
48313
|
await runMode(realRunModeDeps(credentialPath, storePath));
|
|
48177
48314
|
}
|
|
48178
48315
|
var here = fileURLToPath4(import.meta.url);
|
|
48179
|
-
var isMain = !!process.argv[1] && refersToSameFile(here, process.argv[1],
|
|
48316
|
+
var isMain = !!process.argv[1] && refersToSameFile(here, process.argv[1], realpathSync4);
|
|
48180
48317
|
if (isMain) {
|
|
48181
48318
|
main().catch((e) => {
|
|
48182
48319
|
writeServiceLog("error", "startup.fatal", {}, e);
|