usebeeline 0.1.33 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/usebeeline.mjs +885 -610
- package/package.json +1 -1
package/dist/usebeeline.mjs
CHANGED
|
@@ -212,8 +212,8 @@ async function runSquireBrokerLink(options) {
|
|
|
212
212
|
const pending = /* @__PURE__ */ new Map();
|
|
213
213
|
const queued = [];
|
|
214
214
|
let resolveDone;
|
|
215
|
-
const done = new Promise((
|
|
216
|
-
resolveDone =
|
|
215
|
+
const done = new Promise((resolve53) => {
|
|
216
|
+
resolveDone = resolve53;
|
|
217
217
|
});
|
|
218
218
|
const failResponse = (id) => `${JSON.stringify({
|
|
219
219
|
jsonrpc: "2.0",
|
|
@@ -4891,12 +4891,24 @@ async function notify(fields) {
|
|
|
4891
4891
|
async function extendSystemdStartTimeout(ms) {
|
|
4892
4892
|
await notify([`EXTEND_TIMEOUT_USEC=${Math.max(0, Math.round(ms)) * 1e3}`]).catch(() => void 0);
|
|
4893
4893
|
}
|
|
4894
|
-
function startLocalWatchdog(notifier, status, intervalMs = 6e4, env = process.env) {
|
|
4894
|
+
function startLocalWatchdog(notifier, status, workLoopProgress, intervalMs = 6e4, env = process.env) {
|
|
4895
4895
|
if (!env.WATCHDOG_USEC)
|
|
4896
4896
|
return () => void 0;
|
|
4897
|
-
|
|
4897
|
+
let pending = false;
|
|
4898
|
+
let stopped = false;
|
|
4899
|
+
const timer = setInterval(() => {
|
|
4900
|
+
if (pending || stopped)
|
|
4901
|
+
return;
|
|
4902
|
+
pending = true;
|
|
4903
|
+
void workLoopProgress().then((progressed) => stopped || progressed === false ? void 0 : notifier.progress(status(), true)).catch((error) => console.error("[thin-core] watchdog notification failed:", error)).finally(() => {
|
|
4904
|
+
pending = false;
|
|
4905
|
+
});
|
|
4906
|
+
}, intervalMs);
|
|
4898
4907
|
timer.unref?.();
|
|
4899
|
-
return () =>
|
|
4908
|
+
return () => {
|
|
4909
|
+
stopped = true;
|
|
4910
|
+
clearInterval(timer);
|
|
4911
|
+
};
|
|
4900
4912
|
}
|
|
4901
4913
|
var execFileAsync, DELIBERATE_REMOVAL_EXIT_STATUS, DAEMON_DISTRESS_EXIT_STATUS, UNKNOWN_AGENT_EXIT_STATUS, SYSTEMD_UNIT_NAME, SYSTEMD_HELPER_UNIT_NAME, NO_AGENTS_EXIT_STATUS, SYSTEMD_COMMAND_TIMEOUT_MS, SYSTEMD_RESTART_WAIT_MS, AGENT_SERVICE, runSystemctl, SystemdNotifier;
|
|
4902
4914
|
var init_systemd = __esm({
|
|
@@ -4924,8 +4936,8 @@ var init_systemd = __esm({
|
|
|
4924
4936
|
async ready(status) {
|
|
4925
4937
|
await notify(["--ready", `--status=${status}`]);
|
|
4926
4938
|
}
|
|
4927
|
-
async progress(status) {
|
|
4928
|
-
await notify(["WATCHDOG=1", `STATUS=${status}`]);
|
|
4939
|
+
async progress(status, watchdog = false) {
|
|
4940
|
+
await notify([...watchdog ? ["WATCHDOG=1"] : [], `STATUS=${status}`]);
|
|
4929
4941
|
}
|
|
4930
4942
|
async stopping(status) {
|
|
4931
4943
|
await notify(["STOPPING=1", `STATUS=${status}`]);
|
|
@@ -5804,14 +5816,13 @@ var init_self_update = __esm({
|
|
|
5804
5816
|
fetchImpl;
|
|
5805
5817
|
log;
|
|
5806
5818
|
stageOnly;
|
|
5807
|
-
nextCheckAllowedAt = 0;
|
|
5808
5819
|
disposed = false;
|
|
5809
5820
|
applying = false;
|
|
5810
5821
|
deferredBusyNotice = false;
|
|
5811
5822
|
lastVerdictLog = "";
|
|
5812
5823
|
constructor(options) {
|
|
5813
5824
|
const env = options.env ?? process.env;
|
|
5814
|
-
const
|
|
5825
|
+
const numberEnv = (name, fallback) => {
|
|
5815
5826
|
const raw = env[name];
|
|
5816
5827
|
if (!raw)
|
|
5817
5828
|
return fallback;
|
|
@@ -5820,8 +5831,7 @@ var init_self_update = __esm({
|
|
|
5820
5831
|
};
|
|
5821
5832
|
this.options = {
|
|
5822
5833
|
layout: options.layout,
|
|
5823
|
-
|
|
5824
|
-
idleTimeoutMs: options.idleTimeoutMs ?? numberEnv2("BEELINE_UPDATE_IDLE_TIMEOUT_MS", 30 * 6e4),
|
|
5834
|
+
idleTimeoutMs: options.idleTimeoutMs ?? numberEnv("BEELINE_UPDATE_IDLE_TIMEOUT_MS", 30 * 6e4),
|
|
5825
5835
|
idlePollMs: options.idlePollMs ?? 5e3,
|
|
5826
5836
|
env,
|
|
5827
5837
|
now: options.now ?? Date.now
|
|
@@ -5846,7 +5856,7 @@ var init_self_update = __esm({
|
|
|
5846
5856
|
return;
|
|
5847
5857
|
const now2 = this.options.now();
|
|
5848
5858
|
const disabled = this.options.env.BEELINE_UPDATE_DISABLE === "1";
|
|
5849
|
-
if (disabled
|
|
5859
|
+
if (disabled)
|
|
5850
5860
|
return;
|
|
5851
5861
|
this.applying = true;
|
|
5852
5862
|
try {
|
|
@@ -13896,7 +13906,7 @@ function configureNetworkFamilyDefaults(network = net) {
|
|
|
13896
13906
|
configureNetworkFamilyDefaults();
|
|
13897
13907
|
|
|
13898
13908
|
// apps/body/dist/cli.js
|
|
13899
|
-
import { dirname as dirname32, resolve as
|
|
13909
|
+
import { dirname as dirname32, resolve as resolve52 } from "node:path";
|
|
13900
13910
|
import { stdin as stdin4, stdout as stdout5 } from "node:process";
|
|
13901
13911
|
|
|
13902
13912
|
// node_modules/@clack/core/dist/index.mjs
|
|
@@ -15336,7 +15346,7 @@ function parseCursorModelsOutput(output) {
|
|
|
15336
15346
|
};
|
|
15337
15347
|
}
|
|
15338
15348
|
async function enumerateCursorModels(env = process.env) {
|
|
15339
|
-
return new Promise((
|
|
15349
|
+
return new Promise((resolve53) => {
|
|
15340
15350
|
const child = spawn2("cursor-agent", ["models"], {
|
|
15341
15351
|
env,
|
|
15342
15352
|
stdio: ["ignore", "pipe", "ignore"]
|
|
@@ -15350,11 +15360,11 @@ async function enumerateCursorModels(env = process.env) {
|
|
|
15350
15360
|
});
|
|
15351
15361
|
child.on("error", () => {
|
|
15352
15362
|
clearTimeout(timer);
|
|
15353
|
-
|
|
15363
|
+
resolve53(void 0);
|
|
15354
15364
|
});
|
|
15355
15365
|
child.on("close", (code) => {
|
|
15356
15366
|
clearTimeout(timer);
|
|
15357
|
-
|
|
15367
|
+
resolve53(code === 0 ? parseCursorModelsOutput(output) : void 0);
|
|
15358
15368
|
});
|
|
15359
15369
|
});
|
|
15360
15370
|
}
|
|
@@ -15781,13 +15791,13 @@ var CursorAcpServer = class {
|
|
|
15781
15791
|
consumeLine(line);
|
|
15782
15792
|
});
|
|
15783
15793
|
try {
|
|
15784
|
-
const { code, signal } = await new Promise((
|
|
15794
|
+
const { code, signal } = await new Promise((resolve53) => {
|
|
15785
15795
|
let settled = false;
|
|
15786
15796
|
const finish = (exitCode, exitSignal) => {
|
|
15787
15797
|
if (settled)
|
|
15788
15798
|
return;
|
|
15789
15799
|
settled = true;
|
|
15790
|
-
|
|
15800
|
+
resolve53({ code: exitCode, signal: exitSignal });
|
|
15791
15801
|
};
|
|
15792
15802
|
child.once("error", (error) => {
|
|
15793
15803
|
spawnError = error instanceof Error ? error.message : String(error);
|
|
@@ -15932,10 +15942,10 @@ function releaseSquireConnectSession(log2, owner = "") {
|
|
|
15932
15942
|
function squireChromeProfileDir() {
|
|
15933
15943
|
return process.env.TRUSTY_SQUIRE_PROFILE_DIR ?? squireHostPaths(homedir2()).profileDir;
|
|
15934
15944
|
}
|
|
15935
|
-
var defaultShellRunner = (command, args) => new Promise((
|
|
15945
|
+
var defaultShellRunner = (command, args) => new Promise((resolve53) => {
|
|
15936
15946
|
execFile(command, [...args], { timeout: 12e4, maxBuffer: 4 * 1024 * 1024, encoding: "utf8" }, (error, stdout6, stderr) => {
|
|
15937
15947
|
const code = error?.code;
|
|
15938
|
-
|
|
15948
|
+
resolve53({
|
|
15939
15949
|
code: typeof code === "number" ? code : error ? 1 : 0,
|
|
15940
15950
|
stdout: String(stdout6 ?? ""),
|
|
15941
15951
|
stderr: String(stderr ?? "")
|
|
@@ -15960,7 +15970,7 @@ function killConnectTree(child) {
|
|
|
15960
15970
|
}
|
|
15961
15971
|
child.kill();
|
|
15962
15972
|
}
|
|
15963
|
-
var defaultStreamedRunner = (command, args, env, owner = "") => new Promise((
|
|
15973
|
+
var defaultStreamedRunner = (command, args, env, owner = "") => new Promise((resolve53) => {
|
|
15964
15974
|
const child = spawn5(command, args, {
|
|
15965
15975
|
stdio: ["ignore", "pipe", "pipe"],
|
|
15966
15976
|
env: env ?? squireConnectProcessEnv(),
|
|
@@ -15974,7 +15984,7 @@ var defaultStreamedRunner = (command, args, env, owner = "") => new Promise((res
|
|
|
15974
15984
|
const safetyTimer = setTimeout(() => {
|
|
15975
15985
|
if (!resolved) {
|
|
15976
15986
|
resolved = true;
|
|
15977
|
-
|
|
15987
|
+
resolve53({ stdout: stdout6, stderr, pid: child.pid ?? void 0, report, abort: () => {
|
|
15978
15988
|
} });
|
|
15979
15989
|
}
|
|
15980
15990
|
killConnectTree(child);
|
|
@@ -16009,7 +16019,7 @@ var defaultStreamedRunner = (command, args, env, owner = "") => new Promise((res
|
|
|
16009
16019
|
const finish = (result) => {
|
|
16010
16020
|
if (!resolved) {
|
|
16011
16021
|
resolved = true;
|
|
16012
|
-
|
|
16022
|
+
resolve53(result);
|
|
16013
16023
|
}
|
|
16014
16024
|
};
|
|
16015
16025
|
const settle = (result) => {
|
|
@@ -16501,13 +16511,13 @@ var StdioSquireMcpClient = class {
|
|
|
16501
16511
|
const child = this.child;
|
|
16502
16512
|
if (!child)
|
|
16503
16513
|
return Promise.reject(new Error("Squire MCP session is not running"));
|
|
16504
|
-
return new Promise((
|
|
16514
|
+
return new Promise((resolve53, reject) => {
|
|
16505
16515
|
const timeoutMs = method === "initialize" ? INITIALIZE_TIMEOUT_MS : CALL_TIMEOUT_MS;
|
|
16506
16516
|
const timer = setTimeout(() => {
|
|
16507
16517
|
this.pending.delete(id);
|
|
16508
16518
|
reject(new Error(`${toolName2 ?? method} timed out after ${timeoutMs}ms`));
|
|
16509
16519
|
}, timeoutMs);
|
|
16510
|
-
this.pending.set(id, { resolve:
|
|
16520
|
+
this.pending.set(id, { resolve: resolve53, reject, timer });
|
|
16511
16521
|
child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}
|
|
16512
16522
|
`);
|
|
16513
16523
|
});
|
|
@@ -16798,9 +16808,9 @@ var SquireTaskRelay = class {
|
|
|
16798
16808
|
response.writeHead(400, { "content-type": "application/json" }).end(JSON.stringify({ error: error instanceof Error ? error.message : "Squire relay failed" }));
|
|
16799
16809
|
}
|
|
16800
16810
|
});
|
|
16801
|
-
await new Promise((
|
|
16811
|
+
await new Promise((resolve53, reject) => {
|
|
16802
16812
|
server.once("error", reject);
|
|
16803
|
-
server.listen(0, "127.0.0.1",
|
|
16813
|
+
server.listen(0, "127.0.0.1", resolve53);
|
|
16804
16814
|
});
|
|
16805
16815
|
this.server = server;
|
|
16806
16816
|
const address = server.address();
|
|
@@ -17906,11 +17916,11 @@ var RegistryMcpHostBroker = class {
|
|
|
17906
17916
|
})();
|
|
17907
17917
|
});
|
|
17908
17918
|
});
|
|
17909
|
-
await new Promise((
|
|
17919
|
+
await new Promise((resolve53, reject) => {
|
|
17910
17920
|
this.server.once("error", reject);
|
|
17911
17921
|
this.server.listen(this.socketPath, () => {
|
|
17912
17922
|
this.server.off("error", reject);
|
|
17913
|
-
|
|
17923
|
+
resolve53();
|
|
17914
17924
|
});
|
|
17915
17925
|
});
|
|
17916
17926
|
chmodSync(this.socketPath, 384);
|
|
@@ -17919,12 +17929,12 @@ var RegistryMcpHostBroker = class {
|
|
|
17919
17929
|
const server = this.server;
|
|
17920
17930
|
this.server = void 0;
|
|
17921
17931
|
if (server)
|
|
17922
|
-
await new Promise((
|
|
17932
|
+
await new Promise((resolve53) => server.close(() => resolve53()));
|
|
17923
17933
|
rmSync2(this.socketPath, { force: true });
|
|
17924
17934
|
}
|
|
17925
17935
|
};
|
|
17926
17936
|
async function brokerRequest(socketPath, request) {
|
|
17927
|
-
return new Promise((
|
|
17937
|
+
return new Promise((resolve53, reject) => {
|
|
17928
17938
|
const socket = createConnection3(socketPath);
|
|
17929
17939
|
let output = "";
|
|
17930
17940
|
socket.setEncoding("utf8");
|
|
@@ -17941,7 +17951,7 @@ async function brokerRequest(socketPath, request) {
|
|
|
17941
17951
|
throw new Error(parsed.error);
|
|
17942
17952
|
if (!Array.isArray(parsed.messages) || !parsed.messages.every((entry) => typeof entry === "string"))
|
|
17943
17953
|
throw new Error("Registry MCP broker returned an invalid response");
|
|
17944
|
-
|
|
17954
|
+
resolve53(parsed.messages);
|
|
17945
17955
|
} catch (error) {
|
|
17946
17956
|
reject(error);
|
|
17947
17957
|
}
|
|
@@ -18740,6 +18750,7 @@ var AgentChannel = class {
|
|
|
18740
18750
|
#registered = false;
|
|
18741
18751
|
/** A register frame is in flight on the current socket. */
|
|
18742
18752
|
#pending = false;
|
|
18753
|
+
#refused = false;
|
|
18743
18754
|
#registeredAt;
|
|
18744
18755
|
#failures = 0;
|
|
18745
18756
|
#retry;
|
|
@@ -18764,7 +18775,7 @@ var AgentChannel = class {
|
|
|
18764
18775
|
return () => this.#openListeners.delete(listener);
|
|
18765
18776
|
}
|
|
18766
18777
|
start() {
|
|
18767
|
-
if (this.#wanted)
|
|
18778
|
+
if (this.#wanted || this.#refused)
|
|
18768
18779
|
return;
|
|
18769
18780
|
this.#wanted = true;
|
|
18770
18781
|
this.machine.want(this);
|
|
@@ -18797,7 +18808,7 @@ var AgentChannel = class {
|
|
|
18797
18808
|
}
|
|
18798
18809
|
/** The socket opened: ask the server to take this agent. */
|
|
18799
18810
|
register() {
|
|
18800
|
-
if (!this.#wanted || this.#registered || this.#pending)
|
|
18811
|
+
if (!this.#wanted || this.#registered || this.#pending || this.#refused)
|
|
18801
18812
|
return;
|
|
18802
18813
|
clearTimeout(this.#retry);
|
|
18803
18814
|
this.#retry = void 0;
|
|
@@ -18819,6 +18830,7 @@ var AgentChannel = class {
|
|
|
18819
18830
|
this.#registeredAt = Date.now();
|
|
18820
18831
|
this.#registrations += 1;
|
|
18821
18832
|
this.handlers.onOpen();
|
|
18833
|
+
this.machine.registered();
|
|
18822
18834
|
for (const listener of [...this.#openListeners]) {
|
|
18823
18835
|
try {
|
|
18824
18836
|
listener();
|
|
@@ -18829,11 +18841,20 @@ var AgentChannel = class {
|
|
|
18829
18841
|
return;
|
|
18830
18842
|
}
|
|
18831
18843
|
if (event.type === "register-refused") {
|
|
18844
|
+
if (this.#refused)
|
|
18845
|
+
return;
|
|
18832
18846
|
this.#pending = false;
|
|
18833
18847
|
const code = typeof event.code === "string" ? event.code : "refused";
|
|
18834
18848
|
console.warn(`[machine-link] server refused agent ${this.agentId}: ${code}`);
|
|
18849
|
+
this.#refused = ["daemon_token_required", "agent_removed", "too_many_agents"].includes(code);
|
|
18835
18850
|
this.handlers.onRefused?.(code);
|
|
18836
|
-
this.#
|
|
18851
|
+
if (this.#refused) {
|
|
18852
|
+
this.#wanted = false;
|
|
18853
|
+
clearTimeout(this.#retry);
|
|
18854
|
+
this.#retry = void 0;
|
|
18855
|
+
this.machine.unwant(this);
|
|
18856
|
+
} else
|
|
18857
|
+
this.#retryLater();
|
|
18837
18858
|
return;
|
|
18838
18859
|
}
|
|
18839
18860
|
if (event.type === "unregistered") {
|
|
@@ -18890,6 +18911,8 @@ var MachineLink = class {
|
|
|
18890
18911
|
link;
|
|
18891
18912
|
#channels = /* @__PURE__ */ new Map();
|
|
18892
18913
|
#identity = { releaseVersion: "v0.0.0" };
|
|
18914
|
+
#reconciledOnSocket = false;
|
|
18915
|
+
#pendingRelease;
|
|
18893
18916
|
random;
|
|
18894
18917
|
constructor(options) {
|
|
18895
18918
|
this.options = options;
|
|
@@ -18899,11 +18922,15 @@ var MachineLink = class {
|
|
|
18899
18922
|
protocols: () => [MACHINE_SOCKET_PROTOCOL],
|
|
18900
18923
|
factory: options.factory ?? ((url, protocols, socketOptions) => new wrapper_default(url, protocols, socketOptions)),
|
|
18901
18924
|
onOpen: () => {
|
|
18925
|
+
this.#reconciledOnSocket = false;
|
|
18926
|
+
this.#pendingRelease = void 0;
|
|
18902
18927
|
for (const channel of this.#channels.values())
|
|
18903
18928
|
channel.register();
|
|
18904
18929
|
},
|
|
18905
18930
|
onMessage: (data) => this.#message(data),
|
|
18906
18931
|
onClose: () => {
|
|
18932
|
+
this.#reconciledOnSocket = false;
|
|
18933
|
+
this.#pendingRelease = void 0;
|
|
18907
18934
|
for (const channel of this.#channels.values())
|
|
18908
18935
|
channel.socketClosed();
|
|
18909
18936
|
},
|
|
@@ -18921,6 +18948,18 @@ var MachineLink = class {
|
|
|
18921
18948
|
...identity.sourceSha ? { sourceSha: identity.sourceSha } : {}
|
|
18922
18949
|
};
|
|
18923
18950
|
}
|
|
18951
|
+
/** The first accepted registration follows the server's cached release frame. */
|
|
18952
|
+
registered() {
|
|
18953
|
+
if (this.#reconciledOnSocket)
|
|
18954
|
+
return;
|
|
18955
|
+
this.#reconciledOnSocket = true;
|
|
18956
|
+
this.options.onRegistered?.();
|
|
18957
|
+
if (this.#pendingRelease) {
|
|
18958
|
+
const release = this.#pendingRelease;
|
|
18959
|
+
this.#pendingRelease = void 0;
|
|
18960
|
+
this.#broadcast(release);
|
|
18961
|
+
}
|
|
18962
|
+
}
|
|
18924
18963
|
/** A later channel for the same agent (an in-process restart) replaces the earlier one. */
|
|
18925
18964
|
attach(agentId, handlers) {
|
|
18926
18965
|
return new AgentChannel(this, agentId, handlers);
|
|
@@ -18974,13 +19013,19 @@ var MachineLink = class {
|
|
|
18974
19013
|
return;
|
|
18975
19014
|
}
|
|
18976
19015
|
if (event.type === "helper-release") {
|
|
18977
|
-
|
|
18978
|
-
|
|
19016
|
+
if (!this.#reconciledOnSocket)
|
|
19017
|
+
this.#pendingRelease = event;
|
|
19018
|
+
else
|
|
19019
|
+
this.#broadcast(event);
|
|
18979
19020
|
return;
|
|
18980
19021
|
}
|
|
18981
19022
|
if (event.type !== "hello" && event.type !== "force-update")
|
|
18982
19023
|
this.#logUnknown(event.type);
|
|
18983
19024
|
}
|
|
19025
|
+
#broadcast(event) {
|
|
19026
|
+
for (const channel of this.#channels.values())
|
|
19027
|
+
channel.broadcast(event);
|
|
19028
|
+
}
|
|
18984
19029
|
};
|
|
18985
19030
|
|
|
18986
19031
|
// apps/body/dist/agent-sign-in.js
|
|
@@ -19438,7 +19483,7 @@ var AgentSignIn = class {
|
|
|
19438
19483
|
};
|
|
19439
19484
|
for (const name of ISOLATION_VARIABLES)
|
|
19440
19485
|
delete env[name];
|
|
19441
|
-
return new Promise((
|
|
19486
|
+
return new Promise((resolve53, reject) => {
|
|
19442
19487
|
let output = "";
|
|
19443
19488
|
let answered = false;
|
|
19444
19489
|
let child;
|
|
@@ -19479,7 +19524,7 @@ var AgentSignIn = class {
|
|
|
19479
19524
|
return;
|
|
19480
19525
|
answered = true;
|
|
19481
19526
|
clearTimeout(linkTimer);
|
|
19482
|
-
|
|
19527
|
+
resolve53(link2);
|
|
19483
19528
|
};
|
|
19484
19529
|
child.stdout?.on("data", read2);
|
|
19485
19530
|
child.stderr?.on("data", read2);
|
|
@@ -28367,19 +28412,19 @@ function wellKnownExecutableDirs(env = process.env) {
|
|
|
28367
28412
|
return [...versioned, resolve7(home, ".local", "bin"), "/usr/local/bin", "/opt/homebrew/bin"];
|
|
28368
28413
|
}
|
|
28369
28414
|
function augmentedSearchDirectories(env = process.env) {
|
|
28370
|
-
const
|
|
28415
|
+
const directories2 = [];
|
|
28371
28416
|
const pushAll = (paths) => {
|
|
28372
28417
|
for (const directory of paths) {
|
|
28373
|
-
if (directory && !
|
|
28374
|
-
|
|
28418
|
+
if (directory && !directories2.includes(directory))
|
|
28419
|
+
directories2.push(directory);
|
|
28375
28420
|
}
|
|
28376
28421
|
};
|
|
28377
28422
|
pushAll((env.PATH ?? "").split(delimiter));
|
|
28378
28423
|
if (env.BEELINE_HARNESS_PATH_AUGMENT === "0")
|
|
28379
|
-
return
|
|
28424
|
+
return directories2;
|
|
28380
28425
|
pushAll(wellKnownExecutableDirs(env));
|
|
28381
28426
|
pushAll((env.BEELINE_LAUNCHER_PATH ?? "").split(delimiter));
|
|
28382
|
-
return
|
|
28427
|
+
return directories2;
|
|
28383
28428
|
}
|
|
28384
28429
|
function describeExecutableSearch(env = process.env) {
|
|
28385
28430
|
return augmentedSearchDirectories(env).join(", ");
|
|
@@ -29328,13 +29373,13 @@ var RoomSupervisor = class {
|
|
|
29328
29373
|
*/
|
|
29329
29374
|
retryDelay(failures, signal, since = this.#wakes) {
|
|
29330
29375
|
const delay = this.delaysMs[failures - 1];
|
|
29331
|
-
return new Promise((
|
|
29376
|
+
return new Promise((resolve53) => {
|
|
29332
29377
|
let timer;
|
|
29333
29378
|
const done = () => {
|
|
29334
29379
|
clearTimeout(timer);
|
|
29335
29380
|
this.#parked.delete(done);
|
|
29336
29381
|
signal?.removeEventListener("abort", done);
|
|
29337
|
-
|
|
29382
|
+
resolve53();
|
|
29338
29383
|
};
|
|
29339
29384
|
this.#parked.add(done);
|
|
29340
29385
|
signal?.addEventListener("abort", done, { once: true });
|
|
@@ -29519,12 +29564,12 @@ async function retryBeforeReady(work, options) {
|
|
|
29519
29564
|
if (wait2 <= 0)
|
|
29520
29565
|
break;
|
|
29521
29566
|
await options.extendStartTimeout(wait2 + 15e3);
|
|
29522
|
-
await new Promise((
|
|
29567
|
+
await new Promise((resolve53) => {
|
|
29523
29568
|
const timer = setTimeout(done, wait2);
|
|
29524
29569
|
function done() {
|
|
29525
29570
|
clearTimeout(timer);
|
|
29526
29571
|
options.signal?.removeEventListener("abort", done);
|
|
29527
|
-
|
|
29572
|
+
resolve53();
|
|
29528
29573
|
}
|
|
29529
29574
|
wake = done;
|
|
29530
29575
|
options.signal?.addEventListener("abort", done, { once: true });
|
|
@@ -30549,7 +30594,6 @@ import { createHash as createHash8 } from "node:crypto";
|
|
|
30549
30594
|
import { mkdir as mkdir13, rm as rm10, stat as stat8, writeFile as writeFile10 } from "node:fs/promises";
|
|
30550
30595
|
import { dirname as dirname13, resolve as resolve16 } from "node:path";
|
|
30551
30596
|
var UPDATE_CONVERGENCE_SLO_MS = 10 * 6e4;
|
|
30552
|
-
var DEFAULT_UPDATE_INTERVAL_MS = 3e4;
|
|
30553
30597
|
var UPDATE_DRAIN_DEADLINE_MS = 5 * 6e4;
|
|
30554
30598
|
var MAX_HOST_RESTART_STAGGER_MS = 15e3;
|
|
30555
30599
|
function managedRestartStaggerMs(agentId, desiredRelease, drainDeadlineAt, now2 = Date.now()) {
|
|
@@ -30559,7 +30603,6 @@ function managedRestartStaggerMs(agentId, desiredRelease, drainDeadlineAt, now2
|
|
|
30559
30603
|
}
|
|
30560
30604
|
var UPDATE_WORKER_DEADLINE_MS = UPDATE_CONVERGENCE_SLO_MS - 6e4;
|
|
30561
30605
|
var LOCK_STALE_MS = UPDATE_WORKER_DEADLINE_MS + 5 * 6e4;
|
|
30562
|
-
var DEFAULT_UPDATE_INITIAL_DELAY_MS = 0;
|
|
30563
30606
|
async function withInstallLock(layout, work, options = {}) {
|
|
30564
30607
|
const now2 = options.now ?? Date.now;
|
|
30565
30608
|
const lock = resolve16(layout.releasesRoot, ".state", "install.lock");
|
|
@@ -30645,8 +30688,9 @@ var ManagedUpdateHandoff = class _ManagedUpdateHandoff {
|
|
|
30645
30688
|
#now;
|
|
30646
30689
|
#env;
|
|
30647
30690
|
#runUpdateWorker;
|
|
30691
|
+
#onWorkerSettled;
|
|
30648
30692
|
#drainDeadlineMs;
|
|
30649
|
-
#
|
|
30693
|
+
#checkRequested = false;
|
|
30650
30694
|
#updateCycleDeadlineAt;
|
|
30651
30695
|
#worker;
|
|
30652
30696
|
#requested = false;
|
|
@@ -30659,8 +30703,8 @@ var ManagedUpdateHandoff = class _ManagedUpdateHandoff {
|
|
|
30659
30703
|
this.#now = options.now ?? Date.now;
|
|
30660
30704
|
this.#env = options.env ?? process.env;
|
|
30661
30705
|
this.#runUpdateWorker = options.runUpdateWorker ?? runManagedUpdateWorkerProcess;
|
|
30706
|
+
this.#onWorkerSettled = options.onWorkerSettled;
|
|
30662
30707
|
this.#drainDeadlineMs = options.drainDeadlineMs ?? UPDATE_DRAIN_DEADLINE_MS;
|
|
30663
|
-
this.#nextUpdateCheckAt = this.#now() + numberEnv(this.#env, "BEELINE_UPDATE_INITIAL_DELAY_MS", DEFAULT_UPDATE_INITIAL_DELAY_MS);
|
|
30664
30708
|
}
|
|
30665
30709
|
static async create(layout, now2 = Date.now, options = {}) {
|
|
30666
30710
|
const env = options.env ?? process.env;
|
|
@@ -30676,7 +30720,11 @@ var ManagedUpdateHandoff = class _ManagedUpdateHandoff {
|
|
|
30676
30720
|
if (!releaseKey || this.#notifiedReleaseKey === releaseKey)
|
|
30677
30721
|
return;
|
|
30678
30722
|
this.#notifiedReleaseKey = releaseKey;
|
|
30679
|
-
this.#
|
|
30723
|
+
this.#checkRequested = true;
|
|
30724
|
+
}
|
|
30725
|
+
/** A fresh socket covers notices missed while disconnected with one manifest read. */
|
|
30726
|
+
reconcileOnConnect() {
|
|
30727
|
+
this.#checkRequested = true;
|
|
30680
30728
|
}
|
|
30681
30729
|
/**
|
|
30682
30730
|
* Return true once the active release differs from the serving release.
|
|
@@ -30691,50 +30739,49 @@ var ManagedUpdateHandoff = class _ManagedUpdateHandoff {
|
|
|
30691
30739
|
async check() {
|
|
30692
30740
|
if (this.#requested || !this.#loadedRelease)
|
|
30693
30741
|
return this.#requested;
|
|
30694
|
-
if (this.#stagedReleaseId)
|
|
30695
|
-
return false;
|
|
30696
30742
|
const desiredRelease = await activeReleaseId(this.#layout).catch(() => void 0);
|
|
30697
30743
|
if (desiredRelease && desiredRelease !== this.#loadedRelease) {
|
|
30698
30744
|
return this.#armRestart(desiredRelease);
|
|
30699
30745
|
}
|
|
30700
|
-
|
|
30701
|
-
if (state.stagedReleaseId && state.stagedReleaseId !== this.#loadedRelease) {
|
|
30702
|
-
const requestedAt = this.#now();
|
|
30703
|
-
this.#stagedReleaseId = state.stagedReleaseId;
|
|
30704
|
-
this.#restartRequest = {
|
|
30705
|
-
loadedRelease: this.#loadedRelease,
|
|
30706
|
-
desiredRelease: state.stagedReleaseId,
|
|
30707
|
-
drainDeadlineAt: requestedAt + this.#drainDeadlineMs
|
|
30708
|
-
};
|
|
30709
|
-
console.log(`[thin-core] staged update ${state.stagedReleaseId} is waiting for active turns to drain`);
|
|
30746
|
+
if (this.#worker)
|
|
30710
30747
|
return false;
|
|
30711
|
-
|
|
30712
|
-
|
|
30713
|
-
|
|
30714
|
-
|
|
30715
|
-
this.#nextUpdateCheckAt = now2 + numberEnv(this.#env, "BEELINE_UPDATE_INTERVAL_MS", DEFAULT_UPDATE_INTERVAL_MS);
|
|
30716
|
-
if (!this.#worker) {
|
|
30748
|
+
if (this.#env.BEELINE_UPDATE_DISABLE !== "1" && this.#checkRequested) {
|
|
30749
|
+
this.#checkRequested = false;
|
|
30750
|
+
const now2 = this.#now();
|
|
30751
|
+
const notifiedReleaseKey = this.#notifiedReleaseKey;
|
|
30717
30752
|
this.#updateCycleDeadlineAt = now2 + this.#drainDeadlineMs;
|
|
30718
30753
|
this.#worker = withInstallLock(this.#layout, async () => {
|
|
30719
30754
|
const current = await activeReleaseId(this.#layout).catch(() => void 0);
|
|
30720
30755
|
if (current && current !== this.#loadedRelease)
|
|
30721
30756
|
return;
|
|
30722
|
-
const state2 = await readUpdateState(this.#layout);
|
|
30723
|
-
const interval = numberEnv(this.#env, "BEELINE_UPDATE_INTERVAL_MS", DEFAULT_UPDATE_INTERVAL_MS);
|
|
30724
|
-
if (state2.notifiedReleaseKey === this.#notifiedReleaseKey && state2.lastCheckAt !== void 0 && now2 - state2.lastCheckAt < interval)
|
|
30725
|
-
return;
|
|
30726
30757
|
await this.#runUpdateWorker();
|
|
30727
|
-
if (
|
|
30758
|
+
if (notifiedReleaseKey) {
|
|
30728
30759
|
await writeUpdateState(this.#layout, {
|
|
30729
30760
|
...await readUpdateState(this.#layout),
|
|
30730
|
-
notifiedReleaseKey
|
|
30761
|
+
notifiedReleaseKey
|
|
30731
30762
|
});
|
|
30732
30763
|
}
|
|
30733
30764
|
}).catch((error) => {
|
|
30734
30765
|
console.error(`[thin-core] update worker failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
30735
30766
|
}).finally(() => {
|
|
30736
30767
|
this.#worker = void 0;
|
|
30768
|
+
this.#onWorkerSettled?.();
|
|
30737
30769
|
});
|
|
30770
|
+
return false;
|
|
30771
|
+
}
|
|
30772
|
+
if (this.#stagedReleaseId)
|
|
30773
|
+
return false;
|
|
30774
|
+
const state = await readUpdateState(this.#layout);
|
|
30775
|
+
if (state.stagedReleaseId && state.stagedReleaseId !== this.#loadedRelease) {
|
|
30776
|
+
const requestedAt = this.#now();
|
|
30777
|
+
this.#stagedReleaseId = state.stagedReleaseId;
|
|
30778
|
+
this.#restartRequest = {
|
|
30779
|
+
loadedRelease: this.#loadedRelease,
|
|
30780
|
+
desiredRelease: state.stagedReleaseId,
|
|
30781
|
+
drainDeadlineAt: requestedAt + this.#drainDeadlineMs
|
|
30782
|
+
};
|
|
30783
|
+
console.log(`[thin-core] staged update ${state.stagedReleaseId} is waiting for active turns to drain`);
|
|
30784
|
+
return false;
|
|
30738
30785
|
}
|
|
30739
30786
|
return false;
|
|
30740
30787
|
}
|
|
@@ -30823,6 +30870,7 @@ var ManagedUpdateDrain = class {
|
|
|
30823
30870
|
#clearTimer;
|
|
30824
30871
|
#waitLogTimer;
|
|
30825
30872
|
#resolving;
|
|
30873
|
+
#rerunRequested = false;
|
|
30826
30874
|
#restarting = false;
|
|
30827
30875
|
constructor(options) {
|
|
30828
30876
|
this.#options = options;
|
|
@@ -30837,10 +30885,21 @@ var ManagedUpdateDrain = class {
|
|
|
30837
30885
|
#resolve() {
|
|
30838
30886
|
if (this.#restarting)
|
|
30839
30887
|
return Promise.resolve("restarting");
|
|
30840
|
-
if (this.#resolving)
|
|
30888
|
+
if (this.#resolving) {
|
|
30889
|
+
this.#rerunRequested = true;
|
|
30841
30890
|
return this.#resolving;
|
|
30891
|
+
}
|
|
30842
30892
|
this.#resolving = this.#step().finally(() => {
|
|
30843
30893
|
this.#resolving = void 0;
|
|
30894
|
+
if (this.#rerunRequested) {
|
|
30895
|
+
this.#rerunRequested = false;
|
|
30896
|
+
void this.#resolve().catch((error) => {
|
|
30897
|
+
if (this.#options.failed)
|
|
30898
|
+
this.#options.failed(error);
|
|
30899
|
+
else
|
|
30900
|
+
this.#log(`[thin-core] update drain failed: ${String(error)}`);
|
|
30901
|
+
});
|
|
30902
|
+
}
|
|
30844
30903
|
});
|
|
30845
30904
|
return this.#resolving;
|
|
30846
30905
|
}
|
|
@@ -30891,10 +30950,6 @@ function updateWaitMs(options, request) {
|
|
|
30891
30950
|
const remaining = request.drainDeadlineAt - (options.now ?? Date.now)();
|
|
30892
30951
|
return remaining > 0 ? remaining : UPDATE_DRAIN_WAIT_LOG_INTERVAL_MS;
|
|
30893
30952
|
}
|
|
30894
|
-
function numberEnv(env, name, fallback) {
|
|
30895
|
-
const value = Number(env[name]);
|
|
30896
|
-
return Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
30897
|
-
}
|
|
30898
30953
|
async function runManagedUpdateWorker() {
|
|
30899
30954
|
const { beelineInstallLayout: beelineInstallLayout2 } = await Promise.resolve().then(() => (init_self_update(), self_update_exports));
|
|
30900
30955
|
const layout = beelineInstallLayout2(process.env);
|
|
@@ -31014,8 +31069,8 @@ ${import_picocolors.default.dim("Usage:")}
|
|
|
31014
31069
|
beeline update --force Apply even when the comparison is indeterminate
|
|
31015
31070
|
beeline update --manifest-url <u> Override the published manifest URL
|
|
31016
31071
|
|
|
31017
|
-
The supervised
|
|
31018
|
-
|
|
31072
|
+
The supervised helper checks the manifest on connection and on release notices,
|
|
31073
|
+
then waits for a quiet gap to restart. BEELINE_UPDATE_DISABLE=1 turns the
|
|
31019
31074
|
automatic path off. \`beeline update\` always works.
|
|
31020
31075
|
`);
|
|
31021
31076
|
}
|
|
@@ -31238,9 +31293,9 @@ async function runStartCommand(args, interactiveUi, dependencyOverrides = {}) {
|
|
|
31238
31293
|
// apps/body/dist/connect-command.js
|
|
31239
31294
|
import { spawn as spawn13 } from "node:child_process";
|
|
31240
31295
|
import { createHash as createHash9, randomUUID as randomUUID9 } from "node:crypto";
|
|
31241
|
-
import { chmod as chmod6, mkdir as mkdir16, readFile as
|
|
31296
|
+
import { chmod as chmod6, mkdir as mkdir16, readFile as readFile21, unlink as unlink5, writeFile as writeFile13 } from "node:fs/promises";
|
|
31242
31297
|
import { homedir as homedir12, hostname } from "node:os";
|
|
31243
|
-
import { dirname as dirname17, resolve as
|
|
31298
|
+
import { dirname as dirname17, resolve as resolve23 } from "node:path";
|
|
31244
31299
|
import { stdin as stdin3, stdout as stdout4 } from "node:process";
|
|
31245
31300
|
|
|
31246
31301
|
// packages/api-contract/dist/phone-types.js
|
|
@@ -32307,11 +32362,11 @@ var AcpClient = class extends EventEmitter {
|
|
|
32307
32362
|
}, timeoutMs);
|
|
32308
32363
|
} catch (error) {
|
|
32309
32364
|
if (launch && /EPIPE/.test(String(error)) && this.child?.exitCode === null) {
|
|
32310
|
-
await new Promise((
|
|
32311
|
-
const timer = setTimeout(
|
|
32365
|
+
await new Promise((resolve53) => {
|
|
32366
|
+
const timer = setTimeout(resolve53, 250);
|
|
32312
32367
|
this.child?.once("close", () => {
|
|
32313
32368
|
clearTimeout(timer);
|
|
32314
|
-
|
|
32369
|
+
resolve53();
|
|
32315
32370
|
});
|
|
32316
32371
|
});
|
|
32317
32372
|
}
|
|
@@ -32357,8 +32412,8 @@ ${String(error)}`);
|
|
|
32357
32412
|
try {
|
|
32358
32413
|
oomKilled = await Promise.race([
|
|
32359
32414
|
this.oomKills.consume().catch(() => false),
|
|
32360
|
-
new Promise((
|
|
32361
|
-
diagnosticTimer = setTimeout(() =>
|
|
32415
|
+
new Promise((resolve53) => {
|
|
32416
|
+
diagnosticTimer = setTimeout(() => resolve53(false), 100);
|
|
32362
32417
|
})
|
|
32363
32418
|
]);
|
|
32364
32419
|
} finally {
|
|
@@ -32790,7 +32845,7 @@ ${String(error)}`);
|
|
|
32790
32845
|
const current = this.activeRunIds.get(sessionId);
|
|
32791
32846
|
if (current)
|
|
32792
32847
|
return Promise.resolve(current);
|
|
32793
|
-
return new Promise((
|
|
32848
|
+
return new Promise((resolve53, reject) => {
|
|
32794
32849
|
const onUpdate = (update) => {
|
|
32795
32850
|
if (update.sessionId !== sessionId)
|
|
32796
32851
|
return;
|
|
@@ -32798,7 +32853,7 @@ ${String(error)}`);
|
|
|
32798
32853
|
if (!runId)
|
|
32799
32854
|
return;
|
|
32800
32855
|
cleanup();
|
|
32801
|
-
|
|
32856
|
+
resolve53(runId);
|
|
32802
32857
|
};
|
|
32803
32858
|
const timer = setTimeout(() => {
|
|
32804
32859
|
cleanup();
|
|
@@ -32877,14 +32932,14 @@ ${String(error)}`);
|
|
|
32877
32932
|
}
|
|
32878
32933
|
const id = this.nextId++;
|
|
32879
32934
|
const payload = { jsonrpc: "2.0", id, method, params };
|
|
32880
|
-
return new Promise((
|
|
32935
|
+
return new Promise((resolve53, reject) => {
|
|
32881
32936
|
const timer = backstop ? void 0 : setTimeout(() => {
|
|
32882
32937
|
this.pending.delete(id);
|
|
32883
32938
|
reject(new AcpRequestTimeoutError(method, timeoutMs, this.stderrTail, false, detail));
|
|
32884
32939
|
}, timeoutMs);
|
|
32885
32940
|
const sessionId = params?.sessionId;
|
|
32886
32941
|
this.pending.set(id, {
|
|
32887
|
-
resolve:
|
|
32942
|
+
resolve: resolve53,
|
|
32888
32943
|
reject,
|
|
32889
32944
|
timer,
|
|
32890
32945
|
method,
|
|
@@ -33940,18 +33995,145 @@ async function pairDevice(grant, options = {}) {
|
|
|
33940
33995
|
}
|
|
33941
33996
|
|
|
33942
33997
|
// apps/body/dist/openrouter-routing.js
|
|
33943
|
-
import { mkdir as mkdir14, readFile as
|
|
33998
|
+
import { mkdir as mkdir14, readFile as readFile19, writeFile as writeFile11 } from "node:fs/promises";
|
|
33999
|
+
import { resolve as resolve21 } from "node:path";
|
|
34000
|
+
|
|
34001
|
+
// apps/body/dist/openrouter-history.js
|
|
34002
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
34003
|
+
import { lstat as lstat5, readFile as readFile18, readdir as readdir6 } from "node:fs/promises";
|
|
33944
34004
|
import { resolve as resolve20 } from "node:path";
|
|
34005
|
+
import { createInterface as createInterface6 } from "node:readline";
|
|
34006
|
+
var OPENROUTER_HISTORY_WINDOW_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
34007
|
+
var OPENROUTER_GENERATION_URL = "https://openrouter.ai/api/v1/generation";
|
|
34008
|
+
function openRouterTraffic(observations) {
|
|
34009
|
+
const totals = /* @__PURE__ */ new Map();
|
|
34010
|
+
for (const observation2 of observations) {
|
|
34011
|
+
if (observation2.promptTokens <= 0)
|
|
34012
|
+
continue;
|
|
34013
|
+
const total = totals.get(observation2.provider) ?? { calls: 0, promptTokens: 0, cachedTokens: 0 };
|
|
34014
|
+
total.calls++;
|
|
34015
|
+
total.promptTokens += observation2.promptTokens;
|
|
34016
|
+
total.cachedTokens += Math.min(observation2.promptTokens, Math.max(0, observation2.cachedTokens));
|
|
34017
|
+
totals.set(observation2.provider, total);
|
|
34018
|
+
}
|
|
34019
|
+
return [...totals].map(([provider, total]) => ({ ...total, provider, cacheShare: total.cachedTokens / total.promptTokens }));
|
|
34020
|
+
}
|
|
34021
|
+
async function directories(root) {
|
|
34022
|
+
return (await readdir6(root, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory()).map((entry) => resolve20(root, entry.name));
|
|
34023
|
+
}
|
|
34024
|
+
async function openRouterGenerationIds(roomsDir, model, now2) {
|
|
34025
|
+
const ids = /* @__PURE__ */ new Map();
|
|
34026
|
+
for (const room of await directories(roomsDir)) {
|
|
34027
|
+
const ordinary = await Promise.all(["agent-home", "agent-home/pi", "agent-home/pi/sessions"].map(async (path) => {
|
|
34028
|
+
const stat14 = await lstat5(resolve20(room, path)).catch(() => void 0);
|
|
34029
|
+
return stat14?.isDirectory() && !stat14.isSymbolicLink();
|
|
34030
|
+
}));
|
|
34031
|
+
if (!ordinary.every(Boolean))
|
|
34032
|
+
continue;
|
|
34033
|
+
for (const project of await directories(resolve20(room, "agent-home/pi/sessions"))) {
|
|
34034
|
+
const files = await readdir6(project, { withFileTypes: true }).catch(() => []);
|
|
34035
|
+
for (const file of files) {
|
|
34036
|
+
if (!file.isFile() || !file.name.endsWith(".jsonl"))
|
|
34037
|
+
continue;
|
|
34038
|
+
const stream = createReadStream2(resolve20(project, file.name), { encoding: "utf8" });
|
|
34039
|
+
const lines = createInterface6({ input: stream, crlfDelay: Infinity });
|
|
34040
|
+
try {
|
|
34041
|
+
for await (const line of lines) {
|
|
34042
|
+
try {
|
|
34043
|
+
const { message } = JSON.parse(line);
|
|
34044
|
+
if (message?.role !== "assistant" || message.model !== model || typeof message.responseId !== "string")
|
|
34045
|
+
continue;
|
|
34046
|
+
const timestamp = message.timestamp;
|
|
34047
|
+
if (typeof timestamp === "number" && timestamp >= now2 - OPENROUTER_HISTORY_WINDOW_MS && timestamp <= now2) {
|
|
34048
|
+
ids.set(message.responseId, timestamp);
|
|
34049
|
+
}
|
|
34050
|
+
} catch {
|
|
34051
|
+
}
|
|
34052
|
+
}
|
|
34053
|
+
} catch {
|
|
34054
|
+
} finally {
|
|
34055
|
+
lines.close();
|
|
34056
|
+
stream.destroy();
|
|
34057
|
+
}
|
|
34058
|
+
}
|
|
34059
|
+
}
|
|
34060
|
+
}
|
|
34061
|
+
return ids;
|
|
34062
|
+
}
|
|
34063
|
+
function observation(value) {
|
|
34064
|
+
if (!value || typeof value !== "object")
|
|
34065
|
+
return void 0;
|
|
34066
|
+
const row = value;
|
|
34067
|
+
if (typeof row.id !== "string" || typeof row.provider !== "string" || typeof row.timestamp !== "number" || !Number.isFinite(row.timestamp) || typeof row.promptTokens !== "number" || !Number.isFinite(row.promptTokens) || row.promptTokens < 0 || typeof row.cachedTokens !== "number" || !Number.isFinite(row.cachedTokens) || row.cachedTokens < 0)
|
|
34068
|
+
return void 0;
|
|
34069
|
+
return {
|
|
34070
|
+
id: row.id,
|
|
34071
|
+
provider: row.provider,
|
|
34072
|
+
timestamp: row.timestamp,
|
|
34073
|
+
promptTokens: row.promptTokens,
|
|
34074
|
+
cachedTokens: Math.min(row.cachedTokens, row.promptTokens),
|
|
34075
|
+
...typeof row.sessionId === "string" ? { sessionId: row.sessionId } : {}
|
|
34076
|
+
};
|
|
34077
|
+
}
|
|
34078
|
+
async function readOpenRouterTraffic(input) {
|
|
34079
|
+
const path = resolve20(input.cacheDir, `${input.model.replace(/[^A-Za-z0-9._-]+/g, "_")}.generations.json`);
|
|
34080
|
+
let cached = [];
|
|
34081
|
+
try {
|
|
34082
|
+
const value = JSON.parse(await readFile18(path, "utf8"));
|
|
34083
|
+
const record5 = value;
|
|
34084
|
+
if (record5?.model === input.model && Array.isArray(record5.observations)) {
|
|
34085
|
+
cached = record5.observations.map(observation).filter((row) => Boolean(row));
|
|
34086
|
+
}
|
|
34087
|
+
} catch {
|
|
34088
|
+
}
|
|
34089
|
+
const cutoff = input.now - OPENROUTER_HISTORY_WINDOW_MS;
|
|
34090
|
+
const records = new Map(cached.filter((row) => row.timestamp >= cutoff && row.timestamp <= input.now).map((row) => [row.id, row]));
|
|
34091
|
+
const ids = input.roomsDir ? await openRouterGenerationIds(input.roomsDir, input.model, input.now) : /* @__PURE__ */ new Map();
|
|
34092
|
+
const missing = [...ids].filter(([id]) => !records.has(id));
|
|
34093
|
+
let cursor3 = 0;
|
|
34094
|
+
await Promise.all(Array.from({ length: Math.min(6, missing.length) }, async () => {
|
|
34095
|
+
while (cursor3 < missing.length) {
|
|
34096
|
+
const [id, timestamp] = missing[cursor3++];
|
|
34097
|
+
try {
|
|
34098
|
+
const response = await (input.fetchImpl ?? fetch)(`${OPENROUTER_GENERATION_URL}?id=${encodeURIComponent(id)}`, {
|
|
34099
|
+
headers: { authorization: `Bearer ${input.apiKey}` },
|
|
34100
|
+
signal: AbortSignal.timeout(input.timeoutMs ?? 1e4)
|
|
34101
|
+
});
|
|
34102
|
+
if (!response.ok)
|
|
34103
|
+
continue;
|
|
34104
|
+
const { data } = await response.json();
|
|
34105
|
+
if (!data || data.id !== id)
|
|
34106
|
+
continue;
|
|
34107
|
+
const row = observation({
|
|
34108
|
+
id,
|
|
34109
|
+
timestamp,
|
|
34110
|
+
provider: data.provider_name,
|
|
34111
|
+
promptTokens: data.native_tokens_prompt,
|
|
34112
|
+
cachedTokens: data.native_tokens_cached ?? 0,
|
|
34113
|
+
sessionId: data.session_id
|
|
34114
|
+
});
|
|
34115
|
+
if (row)
|
|
34116
|
+
records.set(id, row);
|
|
34117
|
+
} catch {
|
|
34118
|
+
}
|
|
34119
|
+
}
|
|
34120
|
+
}));
|
|
34121
|
+
await writePrivateFileAtomically(path, `${JSON.stringify({ model: input.model, observations: [...records.values()] })}
|
|
34122
|
+
`).catch(() => void 0);
|
|
34123
|
+
return openRouterTraffic([...records.values()]);
|
|
34124
|
+
}
|
|
34125
|
+
|
|
34126
|
+
// apps/body/dist/openrouter-routing.js
|
|
33945
34127
|
var OPENROUTER_ENDPOINTS_BASE_URL = "https://openrouter.ai/api/v1/models";
|
|
33946
34128
|
var OPENROUTER_COMPLETIONS_URL = "https://openrouter.ai/api/v1/chat/completions";
|
|
33947
34129
|
var OPENROUTER_ROUTING_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
33948
34130
|
var OPENROUTER_ROUTING_FETCH_TIMEOUT_MS = 1e4;
|
|
33949
|
-
var OPENROUTER_PROBE_CACHE_TTL_MS = 6 * 60 * 60 * 1e3;
|
|
33950
34131
|
var OPENROUTER_PROBE_MAX_CANDIDATES = 6;
|
|
33951
34132
|
var OPENROUTER_PROBE_TIMEOUT_MS = 2e4;
|
|
33952
34133
|
var OPENROUTER_UPTIME_BAR = 98;
|
|
33953
34134
|
var OPENROUTER_UPTIME_BAR_RELAXED = 95;
|
|
33954
34135
|
var OPENROUTER_MIN_PROVIDERS = 2;
|
|
34136
|
+
var ROUTING_POLICY = "cache-sticky-v1";
|
|
33955
34137
|
var OPENROUTER_MAX_OUTPUT_TOKENS = 32768;
|
|
33956
34138
|
var OPENROUTER_FALLBACK_PROVIDERS = ["deepinfra", "novita"];
|
|
33957
34139
|
function openRouterModelId(model, env = {}) {
|
|
@@ -33983,12 +34165,19 @@ function parseOpenRouterEndpoints(payload) {
|
|
|
33983
34165
|
const contextLength = typeof endpoint2.context_length === "number" ? endpoint2.context_length : 0;
|
|
33984
34166
|
const maxCompletionTokens = typeof endpoint2.max_completion_tokens === "number" ? endpoint2.max_completion_tokens : 0;
|
|
33985
34167
|
const supported = Array.isArray(endpoint2.supported_parameters) ? endpoint2.supported_parameters : [];
|
|
34168
|
+
const pricing = endpoint2.pricing && typeof endpoint2.pricing === "object" ? endpoint2.pricing : {};
|
|
34169
|
+
const promptPrice = tokenPrice(pricing.prompt);
|
|
34170
|
+
const cacheReadPrice = tokenPrice(pricing.input_cache_read);
|
|
33986
34171
|
endpoints.push({
|
|
33987
34172
|
provider,
|
|
33988
34173
|
uptime,
|
|
33989
34174
|
contextLength,
|
|
33990
34175
|
maxCompletionTokens,
|
|
33991
|
-
tools: supported.includes("tools")
|
|
34176
|
+
tools: supported.includes("tools"),
|
|
34177
|
+
...typeof endpoint2.provider_name === "string" ? { providerName: endpoint2.provider_name } : {},
|
|
34178
|
+
...promptPrice === void 0 ? {} : { promptPrice },
|
|
34179
|
+
...cacheReadPrice === void 0 ? {} : { cacheReadPrice },
|
|
34180
|
+
discountedCacheRead: promptPrice !== void 0 && cacheReadPrice !== void 0 && cacheReadPrice < promptPrice
|
|
33992
34181
|
});
|
|
33993
34182
|
}
|
|
33994
34183
|
const architecture = record5.architecture && typeof record5.architecture === "object" ? record5.architecture : {};
|
|
@@ -33999,6 +34188,30 @@ function parseOpenRouterEndpoints(payload) {
|
|
|
33999
34188
|
inputModalities: modalities?.length ? modalities : void 0
|
|
34000
34189
|
};
|
|
34001
34190
|
}
|
|
34191
|
+
function rankOpenRouterProviders(endpoints, contextLength, traffic, answered) {
|
|
34192
|
+
const shares2 = traffic.filter((row) => row.promptTokens > 0).map((row) => row.cacheShare).sort((a2, b) => a2 - b);
|
|
34193
|
+
const middle = Math.floor(shares2.length / 2);
|
|
34194
|
+
const medianShare = shares2.length ? (shares2[middle] + shares2[Math.floor((shares2.length - 1) / 2)]) / 2 : 0;
|
|
34195
|
+
const normalize2 = (name) => name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
34196
|
+
const ranked = /* @__PURE__ */ new Map();
|
|
34197
|
+
for (const endpoint2 of endpoints) {
|
|
34198
|
+
if (!endpoint2.tools || endpoint2.uptime < OPENROUTER_UPTIME_BAR_RELAXED || contextLength !== void 0 && endpoint2.contextLength < contextLength || !answered.includes(endpoint2.provider) || endpoint2.promptPrice === void 0)
|
|
34199
|
+
continue;
|
|
34200
|
+
const measured = traffic.find((row2) => normalize2(row2.provider) === normalize2(endpoint2.providerName ?? endpoint2.provider));
|
|
34201
|
+
const cacheShare = measured?.cacheShare ?? medianShare;
|
|
34202
|
+
const effectiveInputPrice = endpoint2.promptPrice * (1 - cacheShare) + (endpoint2.cacheReadPrice ?? endpoint2.promptPrice) * cacheShare;
|
|
34203
|
+
const row = { provider: endpoint2.provider, cacheShare, measuredCalls: measured?.calls ?? 0, effectiveInputPrice };
|
|
34204
|
+
if (!ranked.has(row.provider) || effectiveInputPrice < ranked.get(row.provider).effectiveInputPrice)
|
|
34205
|
+
ranked.set(row.provider, row);
|
|
34206
|
+
}
|
|
34207
|
+
return [...ranked.values()].sort((a2, b) => a2.effectiveInputPrice - b.effectiveInputPrice || a2.provider.localeCompare(b.provider));
|
|
34208
|
+
}
|
|
34209
|
+
function tokenPrice(value) {
|
|
34210
|
+
if (typeof value !== "number" && (typeof value !== "string" || !value.trim()))
|
|
34211
|
+
return void 0;
|
|
34212
|
+
const price = Number(value);
|
|
34213
|
+
return Number.isFinite(price) && price >= 0 ? price : void 0;
|
|
34214
|
+
}
|
|
34002
34215
|
function piInputModalities(modalities) {
|
|
34003
34216
|
if (!modalities)
|
|
34004
34217
|
return void 0;
|
|
@@ -34028,12 +34241,14 @@ function advertisedContextLength(endpoints) {
|
|
|
34028
34241
|
}
|
|
34029
34242
|
function selectReliableOpenRouterProviders(endpoints, contextLength) {
|
|
34030
34243
|
const eligible = endpoints.filter((endpoint2) => endpoint2.tools && (contextLength === void 0 || endpoint2.contextLength >= contextLength));
|
|
34244
|
+
const caching = eligible.filter((endpoint2) => endpoint2.discountedCacheRead && endpoint2.uptime >= OPENROUTER_UPTIME_BAR_RELAXED);
|
|
34245
|
+
const candidates = caching.length ? caching : eligible;
|
|
34031
34246
|
const atBar = (bar) => {
|
|
34032
34247
|
const seen = /* @__PURE__ */ new Set();
|
|
34033
|
-
return
|
|
34248
|
+
return candidates.filter((endpoint2) => endpoint2.uptime >= bar).sort((left, right) => right.uptime - left.uptime).map((endpoint2) => endpoint2.provider).filter((provider) => seen.has(provider) ? false : (seen.add(provider), true));
|
|
34034
34249
|
};
|
|
34035
34250
|
const strict = atBar(OPENROUTER_UPTIME_BAR);
|
|
34036
|
-
if (strict.length >= OPENROUTER_MIN_PROVIDERS) {
|
|
34251
|
+
if (strict.length >= OPENROUTER_MIN_PROVIDERS && (caching.length === 0 || caching.every((endpoint2) => endpoint2.uptime >= OPENROUTER_UPTIME_BAR))) {
|
|
34037
34252
|
return { providers: strict, bar: OPENROUTER_UPTIME_BAR, contextLength };
|
|
34038
34253
|
}
|
|
34039
34254
|
const relaxed = atBar(OPENROUTER_UPTIME_BAR_RELAXED);
|
|
@@ -34055,20 +34270,24 @@ function openRouterModelLimits(endpoints, providers) {
|
|
|
34055
34270
|
function openRouterRoutingFor(providers, allowFallbacks = true) {
|
|
34056
34271
|
return {
|
|
34057
34272
|
only: [...providers],
|
|
34058
|
-
order
|
|
34273
|
+
// provider.order disables OpenRouter's session stickiness. Pi already
|
|
34274
|
+
// sends its session id; OpenRouter keeps the successful cache provider
|
|
34275
|
+
// and falls back on failure, within `only`, without bouncing to the old
|
|
34276
|
+
// first choice on every request. A recovery override remains explicit.
|
|
34277
|
+
...allowFallbacks ? {} : { order: [...providers] },
|
|
34059
34278
|
allow_fallbacks: allowFallbacks,
|
|
34060
34279
|
require_parameters: false
|
|
34061
34280
|
};
|
|
34062
34281
|
}
|
|
34063
34282
|
function openRouterRoutingCacheDir(runtimeDir) {
|
|
34064
|
-
return
|
|
34283
|
+
return resolve21(runtimeDir, "openrouter-routing");
|
|
34065
34284
|
}
|
|
34066
34285
|
function cachePath(cacheDir, model) {
|
|
34067
|
-
return
|
|
34286
|
+
return resolve21(cacheDir, `${model.replace(/[^A-Za-z0-9._-]+/g, "_")}.json`);
|
|
34068
34287
|
}
|
|
34069
34288
|
async function readCache(cacheDir, model) {
|
|
34070
34289
|
try {
|
|
34071
|
-
const parsed = JSON.parse(await
|
|
34290
|
+
const parsed = JSON.parse(await readFile19(cachePath(cacheDir, model), "utf8"));
|
|
34072
34291
|
if (!parsed || typeof parsed !== "object")
|
|
34073
34292
|
return void 0;
|
|
34074
34293
|
const cached = parsed;
|
|
@@ -34078,6 +34297,7 @@ async function readCache(cacheDir, model) {
|
|
|
34078
34297
|
const input = Array.isArray(cached.input) ? cached.input.filter((value) => value === "text" || value === "image") : cached.input === null ? null : void 0;
|
|
34079
34298
|
const limits = cached.limits === null ? null : cachedLimits(cached.limits);
|
|
34080
34299
|
return {
|
|
34300
|
+
policy: typeof cached.policy === "string" ? cached.policy : void 0,
|
|
34081
34301
|
model,
|
|
34082
34302
|
fetchedAt: cached.fetchedAt,
|
|
34083
34303
|
providers: cached.providers,
|
|
@@ -34106,41 +34326,6 @@ async function writeCache(cacheDir, value) {
|
|
|
34106
34326
|
mode: 384
|
|
34107
34327
|
});
|
|
34108
34328
|
}
|
|
34109
|
-
function probeCachePath(cacheDir, model) {
|
|
34110
|
-
return resolve20(cacheDir, `${model.replace(/[^A-Za-z0-9._-]+/g, "_")}.probe.json`);
|
|
34111
|
-
}
|
|
34112
|
-
async function readProbeCache(cacheDir, model) {
|
|
34113
|
-
try {
|
|
34114
|
-
const parsed = JSON.parse(await readFile18(probeCachePath(cacheDir, model), "utf8"));
|
|
34115
|
-
if (!parsed || typeof parsed !== "object")
|
|
34116
|
-
return void 0;
|
|
34117
|
-
const cached = parsed;
|
|
34118
|
-
if (cached.model !== model || typeof cached.fetchedAt !== "number")
|
|
34119
|
-
return void 0;
|
|
34120
|
-
if (!Array.isArray(cached.answered))
|
|
34121
|
-
return void 0;
|
|
34122
|
-
const answered = [];
|
|
34123
|
-
for (const entry of cached.answered) {
|
|
34124
|
-
if (!entry || typeof entry !== "object")
|
|
34125
|
-
return void 0;
|
|
34126
|
-
const { provider, latencyMs } = entry;
|
|
34127
|
-
if (typeof provider !== "string" || !provider || typeof latencyMs !== "number") {
|
|
34128
|
-
return void 0;
|
|
34129
|
-
}
|
|
34130
|
-
answered.push({ provider, latencyMs });
|
|
34131
|
-
}
|
|
34132
|
-
return { model, fetchedAt: cached.fetchedAt, answered };
|
|
34133
|
-
} catch {
|
|
34134
|
-
return void 0;
|
|
34135
|
-
}
|
|
34136
|
-
}
|
|
34137
|
-
async function writeProbeCache(cacheDir, value) {
|
|
34138
|
-
await mkdir14(cacheDir, { recursive: true, mode: 448 });
|
|
34139
|
-
await writeFile11(probeCachePath(cacheDir, value.model), `${JSON.stringify(value, null, 2)}
|
|
34140
|
-
`, {
|
|
34141
|
-
mode: 384
|
|
34142
|
-
});
|
|
34143
|
-
}
|
|
34144
34329
|
var PROBE_TOOL = {
|
|
34145
34330
|
type: "function",
|
|
34146
34331
|
function: {
|
|
@@ -34226,7 +34411,7 @@ async function probeOpenRouterProviders(input) {
|
|
|
34226
34411
|
function decision(model, providers, bar, source, note, allowFallbacks = true, input, limits) {
|
|
34227
34412
|
const criteria = bar === null ? "fallback pair" : `uptime \u2265${bar}%, tools`;
|
|
34228
34413
|
const suffix = [
|
|
34229
|
-
bar === OPENROUTER_UPTIME_BAR_RELAXED ? "bar lowered:
|
|
34414
|
+
bar === OPENROUTER_UPTIME_BAR_RELAXED && !note?.startsWith("daily") ? "bar lowered: reliability fallback or cache continuity" : "",
|
|
34230
34415
|
source === "cache" ? "cached" : "",
|
|
34231
34416
|
source === "stale-cache" ? "stale cache" : "",
|
|
34232
34417
|
note ?? ""
|
|
@@ -34245,7 +34430,7 @@ function decision(model, providers, bar, source, note, allowFallbacks = true, in
|
|
|
34245
34430
|
async function resolveUptimeRouting(input) {
|
|
34246
34431
|
const now2 = input.now ?? Date.now;
|
|
34247
34432
|
const cached = await readCache(input.cacheDir, input.model);
|
|
34248
|
-
if (cached?.input !== void 0 && cached.limits !== void 0 && now2() - cached.fetchedAt < OPENROUTER_ROUTING_CACHE_TTL_MS) {
|
|
34433
|
+
if (cached?.policy === ROUTING_POLICY && cached?.input !== void 0 && cached.limits !== void 0 && now2() - cached.fetchedAt < OPENROUTER_ROUTING_CACHE_TTL_MS) {
|
|
34249
34434
|
return decision(input.model, cached.providers, cached.bar, "cache", void 0, true, cached.input ?? void 0, cached.limits ?? void 0);
|
|
34250
34435
|
}
|
|
34251
34436
|
let failure;
|
|
@@ -34264,8 +34449,16 @@ async function resolveUptimeRouting(input) {
|
|
|
34264
34449
|
if (selected.providers.length === 0) {
|
|
34265
34450
|
return decision(input.model, OPENROUTER_FALLBACK_PROVIDERS, null, "fallback", "no provider met the bar", true, modelInput);
|
|
34266
34451
|
}
|
|
34452
|
+
if (cached?.policy === ROUTING_POLICY) {
|
|
34453
|
+
const retained = cached.providers.filter((provider) => selected.providers.includes(provider));
|
|
34454
|
+
selected.providers = [
|
|
34455
|
+
...retained,
|
|
34456
|
+
...selected.providers.filter((provider) => !retained.includes(provider))
|
|
34457
|
+
];
|
|
34458
|
+
}
|
|
34267
34459
|
const limits = openRouterModelLimits(endpoints, selected.providers);
|
|
34268
34460
|
await writeCache(input.cacheDir, {
|
|
34461
|
+
policy: ROUTING_POLICY,
|
|
34269
34462
|
model: input.model,
|
|
34270
34463
|
fetchedAt: now2(),
|
|
34271
34464
|
providers: selected.providers,
|
|
@@ -34283,62 +34476,106 @@ async function resolveUptimeRouting(input) {
|
|
|
34283
34476
|
}
|
|
34284
34477
|
return decision(input.model, OPENROUTER_FALLBACK_PROVIDERS, null, "fallback", `api unreachable: ${failure}`);
|
|
34285
34478
|
}
|
|
34286
|
-
|
|
34287
|
-
|
|
34288
|
-
return probe.answered.map((entry) => entry.provider).filter((provider) => candidates.includes(provider));
|
|
34479
|
+
function dailyCachePath(input) {
|
|
34480
|
+
return resolve21(input.cacheDir, `${input.model.replace(/[^A-Za-z0-9._-]+/g, "_")}.daily.json`);
|
|
34289
34481
|
}
|
|
34290
|
-
async function
|
|
34291
|
-
|
|
34292
|
-
|
|
34293
|
-
model
|
|
34294
|
-
|
|
34295
|
-
|
|
34296
|
-
|
|
34297
|
-
|
|
34298
|
-
|
|
34299
|
-
|
|
34300
|
-
|
|
34301
|
-
|
|
34302
|
-
|
|
34303
|
-
|
|
34482
|
+
async function readDailyRouting(input) {
|
|
34483
|
+
try {
|
|
34484
|
+
const row = JSON.parse(await readFile19(dailyCachePath(input), "utf8"));
|
|
34485
|
+
if (row.policy !== "cost-daily-v1" || row.model !== input.model || !Number.isFinite(row.fetchedAt) || !Array.isArray(row.providers) || !row.providers.length || row.providers.length > 3 || !row.providers.every((provider) => typeof provider === "string" && provider.length > 0) || !Array.isArray(row.ranking) || !row.ranking.every((entry) => entry && typeof entry.provider === "string" && Number.isFinite(entry.effectiveInputPrice) && entry.effectiveInputPrice >= 0 && Number.isFinite(entry.cacheShare) && entry.cacheShare >= 0 && entry.cacheShare <= 1) || !row.providers.every((provider) => row.ranking.some((entry) => entry.provider === provider)))
|
|
34486
|
+
return void 0;
|
|
34487
|
+
return {
|
|
34488
|
+
policy: "cost-daily-v1",
|
|
34489
|
+
model: row.model,
|
|
34490
|
+
fetchedAt: row.fetchedAt,
|
|
34491
|
+
providers: row.providers,
|
|
34492
|
+
ranking: row.ranking,
|
|
34493
|
+
...Array.isArray(row.input) ? { input: row.input.filter((value) => value === "text" || value === "image") } : {},
|
|
34494
|
+
...cachedLimits(row.limits) ? { limits: cachedLimits(row.limits) } : {}
|
|
34495
|
+
};
|
|
34496
|
+
} catch {
|
|
34304
34497
|
return void 0;
|
|
34305
34498
|
}
|
|
34306
|
-
|
|
34499
|
+
}
|
|
34500
|
+
function dailyDecision(row, source) {
|
|
34501
|
+
return decision(row.model, row.providers, OPENROUTER_UPTIME_BAR_RELAXED, source, "daily effective input cost; seven-day cache shares; answer-probed", true, row.input, row.limits);
|
|
34502
|
+
}
|
|
34503
|
+
async function buildDailyRouting(input) {
|
|
34504
|
+
const now2 = input.now ?? Date.now;
|
|
34505
|
+
const response = await (input.fetchImpl ?? fetch)(`${OPENROUTER_ENDPOINTS_BASE_URL}/${input.model}/endpoints`, {
|
|
34506
|
+
signal: AbortSignal.timeout(input.timeoutMs ?? OPENROUTER_ROUTING_FETCH_TIMEOUT_MS)
|
|
34507
|
+
});
|
|
34508
|
+
if (!response.ok)
|
|
34509
|
+
throw new Error(`HTTP ${response.status}`);
|
|
34510
|
+
const { endpoints, contextLength, inputModalities } = parseOpenRouterEndpoints(await response.json());
|
|
34511
|
+
const eligible = [...new Set(endpoints.filter((endpoint2) => endpoint2.tools && endpoint2.uptime >= OPENROUTER_UPTIME_BAR_RELAXED && endpoint2.promptPrice !== void 0 && (contextLength === void 0 || endpoint2.contextLength >= contextLength)).map((endpoint2) => endpoint2.provider))];
|
|
34512
|
+
if (!eligible.length)
|
|
34513
|
+
throw new Error("no priced provider met the tools/context/95% gate");
|
|
34514
|
+
const [traffic, probes] = await Promise.all([
|
|
34515
|
+
readOpenRouterTraffic({
|
|
34516
|
+
model: input.model,
|
|
34517
|
+
cacheDir: input.cacheDir,
|
|
34518
|
+
...input.historyRoomsDir ? { roomsDir: input.historyRoomsDir } : {},
|
|
34519
|
+
apiKey: input.apiKey,
|
|
34520
|
+
now: now2(),
|
|
34521
|
+
fetchImpl: input.fetchImpl,
|
|
34522
|
+
timeoutMs: input.timeoutMs
|
|
34523
|
+
}),
|
|
34524
|
+
probeOpenRouterProviders({
|
|
34525
|
+
model: input.model,
|
|
34526
|
+
providers: eligible,
|
|
34527
|
+
apiKey: input.apiKey,
|
|
34528
|
+
fetchImpl: input.fetchImpl,
|
|
34529
|
+
now: input.now,
|
|
34530
|
+
timeoutMs: input.probeTimeoutMs,
|
|
34531
|
+
// Gate every eligible provider once per day, rather than using the old
|
|
34532
|
+
// uptime-first six as a proxy for the cheapest qualified set.
|
|
34533
|
+
maxCandidates: input.probeMaxCandidates ?? eligible.length
|
|
34534
|
+
})
|
|
34535
|
+
]);
|
|
34536
|
+
const ranking = rankOpenRouterProviders(endpoints, contextLength, traffic, probes.filter((probe) => probe.answered).map((probe) => probe.provider));
|
|
34537
|
+
if (!ranking.length)
|
|
34538
|
+
throw new Error("no eligible provider answered the text probe");
|
|
34539
|
+
const providers = ranking.slice(0, 3).map((row2) => row2.provider);
|
|
34540
|
+
const row = {
|
|
34541
|
+
policy: "cost-daily-v1",
|
|
34307
34542
|
model: input.model,
|
|
34308
34543
|
fetchedAt: now2(),
|
|
34309
|
-
|
|
34310
|
-
|
|
34311
|
-
|
|
34312
|
-
|
|
34544
|
+
providers,
|
|
34545
|
+
ranking,
|
|
34546
|
+
input: piInputModalities(inputModalities),
|
|
34547
|
+
limits: openRouterModelLimits(endpoints, providers)
|
|
34548
|
+
};
|
|
34549
|
+
await writePrivateFileAtomically(dailyCachePath(input), `${JSON.stringify(row, null, 2)}
|
|
34550
|
+
`).catch(() => void 0);
|
|
34551
|
+
return row;
|
|
34313
34552
|
}
|
|
34553
|
+
var dailyAttempts = /* @__PURE__ */ new Map();
|
|
34314
34554
|
async function resolveOpenRouterRouting(input) {
|
|
34315
|
-
const
|
|
34555
|
+
const cached = await readDailyRouting(input);
|
|
34316
34556
|
const override = input.providerOverride?.trim();
|
|
34317
34557
|
if (override) {
|
|
34558
|
+
const base = cached ? dailyDecision(cached, "cache") : await resolveUptimeRouting(input);
|
|
34318
34559
|
return decision(input.model, [override], base.bar, base.source, "pinned to one provider after an empty completion", false, base.input, base.limits);
|
|
34319
34560
|
}
|
|
34320
|
-
|
|
34321
|
-
|
|
34322
|
-
return base;
|
|
34561
|
+
if (!input.apiKey?.trim())
|
|
34562
|
+
return resolveUptimeRouting(input);
|
|
34323
34563
|
const now2 = input.now ?? Date.now;
|
|
34324
|
-
|
|
34325
|
-
|
|
34326
|
-
const answered = answeringProviders(probe, base.providers);
|
|
34327
|
-
if (answered.length > 0) {
|
|
34328
|
-
return decision(input.model, answered, base.bar, base.source, "answer-probed, cached", true, base.input, base.limits);
|
|
34329
|
-
}
|
|
34330
|
-
}
|
|
34564
|
+
if (cached && now2() - cached.fetchedAt < OPENROUTER_ROUTING_CACHE_TTL_MS)
|
|
34565
|
+
return dailyDecision(cached, "cache");
|
|
34331
34566
|
const key = `${input.cacheDir}\0${input.model}`;
|
|
34332
|
-
let
|
|
34333
|
-
if (!
|
|
34334
|
-
const
|
|
34335
|
-
|
|
34336
|
-
|
|
34567
|
+
let attempt = dailyAttempts.get(key);
|
|
34568
|
+
if (!attempt || now2() - attempt.startedAt >= OPENROUTER_ROUTING_CACHE_TTL_MS) {
|
|
34569
|
+
const result = buildDailyRouting(input).then((row) => dailyDecision(row, "live")).catch(async (error) => {
|
|
34570
|
+
const base = cached ? dailyDecision(cached, "stale-cache") : await resolveUptimeRouting(input);
|
|
34571
|
+
return { ...base, line: `${base.line}; daily ranking unavailable: ${error instanceof Error ? error.message : String(error)}` };
|
|
34337
34572
|
});
|
|
34338
|
-
|
|
34339
|
-
|
|
34573
|
+
attempt = { startedAt: now2(), result };
|
|
34574
|
+
dailyAttempts.set(key, attempt);
|
|
34340
34575
|
}
|
|
34341
|
-
|
|
34576
|
+
if (cached)
|
|
34577
|
+
return { ...dailyDecision(cached, "stale-cache"), refresh: attempt.result };
|
|
34578
|
+
return attempt.result;
|
|
34342
34579
|
}
|
|
34343
34580
|
function withOpenRouterModelRouting(value, pin) {
|
|
34344
34581
|
const root = value && typeof value === "object" && !Array.isArray(value) ? { ...value } : {};
|
|
@@ -34389,7 +34626,7 @@ function openRouterRoutingInput(config, selection, fetchImpl, extra) {
|
|
|
34389
34626
|
openRouterRouting: {
|
|
34390
34627
|
model,
|
|
34391
34628
|
cacheDir: config.openRouterRoutingCacheDir,
|
|
34392
|
-
...apiKey ? { apiKey } : {},
|
|
34629
|
+
...apiKey ? { apiKey, historyRoomsDir: resolve21(config.openRouterRoutingCacheDir, "../rooms") } : {},
|
|
34393
34630
|
...fetchImpl ? { fetchImpl } : {},
|
|
34394
34631
|
...extra?.providerOverride ? { providerOverride: extra.providerOverride } : {},
|
|
34395
34632
|
...extra?.onDecision ? { onDecision: extra.onDecision } : {}
|
|
@@ -34398,9 +34635,9 @@ function openRouterRoutingInput(config, selection, fetchImpl, extra) {
|
|
|
34398
34635
|
}
|
|
34399
34636
|
|
|
34400
34637
|
// apps/body/dist/provider-key-store.js
|
|
34401
|
-
import { chmod as chmod5, mkdir as mkdir15, readFile as
|
|
34638
|
+
import { chmod as chmod5, mkdir as mkdir15, readFile as readFile20, writeFile as writeFile12 } from "node:fs/promises";
|
|
34402
34639
|
import { homedir as homedir11 } from "node:os";
|
|
34403
|
-
import { dirname as dirname16, resolve as
|
|
34640
|
+
import { dirname as dirname16, resolve as resolve22 } from "node:path";
|
|
34404
34641
|
var PROVIDER_KEY_ENV_VARS = {
|
|
34405
34642
|
openrouter: "OPENROUTER_API_KEY",
|
|
34406
34643
|
openai: "OPENAI_API_KEY",
|
|
@@ -34410,12 +34647,12 @@ var PROVIDER_KEY_ENV_VARS = {
|
|
|
34410
34647
|
};
|
|
34411
34648
|
var GOOGLE_ENV_ALIAS = "GEMINI_API_KEY";
|
|
34412
34649
|
function providerKeyStorePath(env = process.env) {
|
|
34413
|
-
const configRoot = env.XDG_CONFIG_HOME?.trim() ||
|
|
34414
|
-
return
|
|
34650
|
+
const configRoot = env.XDG_CONFIG_HOME?.trim() || resolve22(homedir11(), ".config");
|
|
34651
|
+
return resolve22(configRoot, "beeline", "providers.json");
|
|
34415
34652
|
}
|
|
34416
34653
|
async function readProviderKeyStore(env = process.env) {
|
|
34417
34654
|
const path = providerKeyStorePath(env);
|
|
34418
|
-
const raw = await
|
|
34655
|
+
const raw = await readFile20(path, "utf8").catch(() => void 0);
|
|
34419
34656
|
if (!raw)
|
|
34420
34657
|
return {};
|
|
34421
34658
|
try {
|
|
@@ -34789,12 +35026,12 @@ function parseConnectSubscriptions(value) {
|
|
|
34789
35026
|
];
|
|
34790
35027
|
}
|
|
34791
35028
|
async function readMachineId(env = process.env) {
|
|
34792
|
-
const configDir =
|
|
34793
|
-
const machineIdPath =
|
|
35029
|
+
const configDir = resolve23(env.XDG_CONFIG_HOME ?? resolve23(homedir12(), ".config"), "beeline");
|
|
35030
|
+
const machineIdPath = resolve23(configDir, "machine-id");
|
|
34794
35031
|
let machineId;
|
|
34795
35032
|
let machineName = hostname();
|
|
34796
35033
|
try {
|
|
34797
|
-
const existing = await
|
|
35034
|
+
const existing = await readFile21(machineIdPath, "utf8");
|
|
34798
35035
|
machineId = existing.trim();
|
|
34799
35036
|
if (!/^[0-9a-f-]{32,}$/.test(machineId))
|
|
34800
35037
|
throw new Error("invalid persisted machine id");
|
|
@@ -34863,7 +35100,7 @@ async function installCurrentRelease(fetchImpl) {
|
|
|
34863
35100
|
});
|
|
34864
35101
|
await activateRelease(layout, releaseId);
|
|
34865
35102
|
return {
|
|
34866
|
-
binary:
|
|
35103
|
+
binary: resolve23(layout.binDir, "beeline"),
|
|
34867
35104
|
version: published.version ?? releaseId
|
|
34868
35105
|
};
|
|
34869
35106
|
}
|
|
@@ -34895,7 +35132,7 @@ async function writeProviderEnv(selection, agentPubkey) {
|
|
|
34895
35132
|
const values = providerEnvironment(selection);
|
|
34896
35133
|
if (Object.keys(values).length === 0)
|
|
34897
35134
|
return void 0;
|
|
34898
|
-
const path =
|
|
35135
|
+
const path = resolve23(defaultSupervisorRoot(process.env), "beeline", "connect", `${agentPubkey}.env`);
|
|
34899
35136
|
await mkdir16(dirname17(path), { recursive: true, mode: 448 });
|
|
34900
35137
|
const contents = Object.entries(values).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join("\n");
|
|
34901
35138
|
await writeFile13(path, `${contents}
|
|
@@ -34965,7 +35202,7 @@ async function runConnectWizard(code, fetchImpl, eventSubscriptions, accessPolic
|
|
|
34965
35202
|
await finishConnectedAgentPairing(baseUrl, pairingCode, grant.workspace_joined, eventSubscriptions, fetchImpl);
|
|
34966
35203
|
const installedRelease = await brassSpinner("Installing the Beeline daemon\u2026", () => installCurrentRelease(fetchImpl), (release) => `Installed Beeline helper ${release.version}`);
|
|
34967
35204
|
const llmEnvFile = await writeProviderEnv(selection, grant.agent_pubkey);
|
|
34968
|
-
const grantPath =
|
|
35205
|
+
const grantPath = resolve23(defaultSupervisorRoot(process.env), "beeline", "connect", `grant-${process.pid}-${Date.now()}.json`);
|
|
34969
35206
|
await writePrivateJson(grantPath, {
|
|
34970
35207
|
agentSecretKey: grant.agent_secret_key,
|
|
34971
35208
|
bodySecretKey: grant.body_secret_key,
|
|
@@ -35050,12 +35287,12 @@ async function runConnectFinishCommand(path) {
|
|
|
35050
35287
|
throw new Error("connect-finish may run only from the canonical installed Beeline launcher");
|
|
35051
35288
|
}
|
|
35052
35289
|
try {
|
|
35053
|
-
const grant = JSON.parse(await
|
|
35290
|
+
const grant = JSON.parse(await readFile21(resolve23(path), "utf8"));
|
|
35054
35291
|
if (!isDevicePairingGrant(grant))
|
|
35055
35292
|
throw new Error("device connection grant is invalid");
|
|
35056
35293
|
const connected = await completeDevicePairing(grant);
|
|
35057
|
-
await unlink5(
|
|
35058
|
-
const providerEnv = grant.llmEnvFile ? await
|
|
35294
|
+
await unlink5(resolve23(path));
|
|
35295
|
+
const providerEnv = grant.llmEnvFile ? await readFile21(grant.llmEnvFile, "utf8").catch(() => "") : "";
|
|
35059
35296
|
const apiKey = (/^OPENROUTER_API_KEY=(\S+)/m.exec(providerEnv)?.[1] ?? "").replace(/^["']|["']$/g, "");
|
|
35060
35297
|
const model = openRouterModelId(grant.model, { OPENROUTER_API_KEY: apiKey });
|
|
35061
35298
|
if (model) {
|
|
@@ -35081,11 +35318,11 @@ init_self_update();
|
|
|
35081
35318
|
// apps/body/dist/machine-helper.js
|
|
35082
35319
|
import { mkdir as mkdir30, rename as rename14, stat as stat12, writeFile as writeFile23 } from "node:fs/promises";
|
|
35083
35320
|
import { homedir as homedir19 } from "node:os";
|
|
35084
|
-
import { dirname as dirname31, resolve as
|
|
35321
|
+
import { dirname as dirname31, resolve as resolve50 } from "node:path";
|
|
35085
35322
|
|
|
35086
35323
|
// apps/body/dist/agent-runtime.js
|
|
35087
35324
|
import { homedir as homedir18 } from "node:os";
|
|
35088
|
-
import { dirname as dirname30, join as join22, resolve as
|
|
35325
|
+
import { dirname as dirname30, join as join22, resolve as resolve48 } from "node:path";
|
|
35089
35326
|
|
|
35090
35327
|
// apps/body/dist/model-availability.js
|
|
35091
35328
|
var SECRET_VALUE = /(?:token|key|secret|password)=?[^\s,;]*/gi;
|
|
@@ -35147,8 +35384,8 @@ async function applyRuntimeModelPreflight(config, agent, selection, validate = v
|
|
|
35147
35384
|
|
|
35148
35385
|
// apps/body/dist/model-catalog-sync.js
|
|
35149
35386
|
import { createHash as createHash10 } from "node:crypto";
|
|
35150
|
-
import { readFile as
|
|
35151
|
-
import { resolve as
|
|
35387
|
+
import { readFile as readFile22, writeFile as writeFile14 } from "node:fs/promises";
|
|
35388
|
+
import { resolve as resolve24 } from "node:path";
|
|
35152
35389
|
var MODEL_CATALOG_PROBE_TIMEOUT_MS = 3e4;
|
|
35153
35390
|
var MODEL_CATALOG_HASH_FILE = "model-catalog.sha256";
|
|
35154
35391
|
function modelCatalogHash(options, selection, startupUnavailable) {
|
|
@@ -35173,7 +35410,7 @@ async function withTimeout(work, timeoutMs, what) {
|
|
|
35173
35410
|
async function syncAgentModelCatalog(input) {
|
|
35174
35411
|
const log2 = input.log ?? ((line) => console.log(line));
|
|
35175
35412
|
const fetchCatalog = input.fetchCatalog ?? fetchAgentModelCatalog;
|
|
35176
|
-
const hashPath =
|
|
35413
|
+
const hashPath = resolve24(input.runtimeDir, MODEL_CATALOG_HASH_FILE);
|
|
35177
35414
|
try {
|
|
35178
35415
|
const configuration = await input.api.execute("getAgentConfiguration", {
|
|
35179
35416
|
agentId: input.agentId
|
|
@@ -35185,7 +35422,7 @@ async function syncAgentModelCatalog(input) {
|
|
|
35185
35422
|
const { catalog } = await withTimeout(fetchCatalog(input.agent, input.agentEnv, input.startupUnavailable ? void 0 : selection), input.timeoutMs ?? MODEL_CATALOG_PROBE_TIMEOUT_MS, "model catalog probe");
|
|
35186
35423
|
const effectiveCatalog = input.startupUnavailable ? catalog : withEffectiveCurrentValues(catalog, selection);
|
|
35187
35424
|
const hash = modelCatalogHash(effectiveCatalog, selection, input.startupUnavailable);
|
|
35188
|
-
const previous = await
|
|
35425
|
+
const previous = await readFile22(hashPath, "utf8").catch(() => "");
|
|
35189
35426
|
if (!input.force && previous.trim() === hash)
|
|
35190
35427
|
return "unchanged";
|
|
35191
35428
|
await input.api.execute("postAgentModelCatalog", {
|
|
@@ -35219,10 +35456,10 @@ var LOGIN_URL = /https:\/\/login\.tailscale\.com\/[A-Za-z0-9_/-]+/u;
|
|
|
35219
35456
|
function clipped(value) {
|
|
35220
35457
|
return value.length <= OUTPUT_LIMIT ? value : value.slice(value.length - OUTPUT_LIMIT);
|
|
35221
35458
|
}
|
|
35222
|
-
var runTailscaleCommand = (command, args) => new Promise((
|
|
35459
|
+
var runTailscaleCommand = (command, args) => new Promise((resolve53) => {
|
|
35223
35460
|
execFile9(command, [...args], { timeout: COMMAND_TIMEOUT_MS, maxBuffer: OUTPUT_LIMIT * 2 }, (error, stdout6, stderr) => {
|
|
35224
35461
|
const code = error && "code" in error && typeof error.code === "number" ? error.code : error ? null : 0;
|
|
35225
|
-
|
|
35462
|
+
resolve53({ code, stdout: clipped(stdout6), stderr: clipped(stderr) });
|
|
35226
35463
|
});
|
|
35227
35464
|
});
|
|
35228
35465
|
function loginUrlFrom(status, output) {
|
|
@@ -35994,8 +36231,8 @@ import { dirname as dirname18 } from "node:path";
|
|
|
35994
36231
|
// apps/body/dist/browser-share.js
|
|
35995
36232
|
var shares = /* @__PURE__ */ new Map();
|
|
35996
36233
|
function opened(socket) {
|
|
35997
|
-
return new Promise((
|
|
35998
|
-
socket.once("open",
|
|
36234
|
+
return new Promise((resolve53, reject) => {
|
|
36235
|
+
socket.once("open", resolve53);
|
|
35999
36236
|
socket.once("error", reject);
|
|
36000
36237
|
});
|
|
36001
36238
|
}
|
|
@@ -36171,18 +36408,18 @@ var BrowserShareHost = class {
|
|
|
36171
36408
|
})().catch((error) => socket.end(JSON.stringify({ error: error instanceof Error ? error.message : String(error) })));
|
|
36172
36409
|
});
|
|
36173
36410
|
});
|
|
36174
|
-
await new Promise((
|
|
36411
|
+
await new Promise((resolve53, reject) => {
|
|
36175
36412
|
this.server.once("error", reject);
|
|
36176
36413
|
this.server.listen(this.socketPath, () => {
|
|
36177
36414
|
this.server.off("error", reject);
|
|
36178
|
-
|
|
36415
|
+
resolve53();
|
|
36179
36416
|
});
|
|
36180
36417
|
});
|
|
36181
36418
|
chmodSync2(this.socketPath, 384);
|
|
36182
36419
|
}
|
|
36183
36420
|
async stop() {
|
|
36184
36421
|
if (this.server)
|
|
36185
|
-
await new Promise((
|
|
36422
|
+
await new Promise((resolve53) => this.server.close(() => resolve53()));
|
|
36186
36423
|
this.server = void 0;
|
|
36187
36424
|
rmSync3(this.socketPath, { force: true });
|
|
36188
36425
|
}
|
|
@@ -36192,16 +36429,16 @@ var BrowserShareHost = class {
|
|
|
36192
36429
|
import { execFile as execFile19 } from "node:child_process";
|
|
36193
36430
|
import { createHash as createHash17 } from "node:crypto";
|
|
36194
36431
|
import { existsSync as existsSync10, mkdirSync as mkdirSync4 } from "node:fs";
|
|
36195
|
-
import { lstat as
|
|
36196
|
-
import { dirname as dirname28, relative as relative4, resolve as
|
|
36432
|
+
import { lstat as lstat10, mkdir as mkdir28, readdir as readdir14, realpath as realpath4, rm as rm20 } from "node:fs/promises";
|
|
36433
|
+
import { dirname as dirname28, relative as relative4, resolve as resolve43, sep as sep4 } from "node:path";
|
|
36197
36434
|
import { promisify as promisify13 } from "node:util";
|
|
36198
36435
|
|
|
36199
36436
|
// apps/body/dist/grant-runner.js
|
|
36200
36437
|
import { execFile as execFile11 } from "node:child_process";
|
|
36201
36438
|
import { createHash as createHash11, randomBytes as randomBytes9, randomUUID as randomUUID11 } from "node:crypto";
|
|
36202
|
-
import { chmod as chmod7, mkdir as mkdir17, readFile as
|
|
36439
|
+
import { chmod as chmod7, mkdir as mkdir17, readFile as readFile23, readdir as readdir7, rename as rename9, rm as rm13, rmdir, stat as stat9, writeFile as writeFile15 } from "node:fs/promises";
|
|
36203
36440
|
import { createServer as createServer4 } from "node:http";
|
|
36204
|
-
import { dirname as dirname20, resolve as
|
|
36441
|
+
import { dirname as dirname20, resolve as resolve26 } from "node:path";
|
|
36205
36442
|
|
|
36206
36443
|
// packages/api-contract/dist/surface-capabilities.js
|
|
36207
36444
|
var SURFACE_CAPABILITY_TABLE = {
|
|
@@ -36232,7 +36469,7 @@ function surfaceAllows(surface, capability) {
|
|
|
36232
36469
|
import { execFile as execFile10, spawnSync } from "node:child_process";
|
|
36233
36470
|
import { lstatSync as lstatSync3, readdirSync as readdirSync3, readFileSync as readFileSync8, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
36234
36471
|
import { homedir as homedir13 } from "node:os";
|
|
36235
|
-
import { basename as basename7, dirname as dirname19, isAbsolute as isAbsolute3, relative, resolve as
|
|
36472
|
+
import { basename as basename7, dirname as dirname19, isAbsolute as isAbsolute3, relative, resolve as resolve25, sep } from "node:path";
|
|
36236
36473
|
var DEFAULT_SANDBOX_POLICY = "bwrap";
|
|
36237
36474
|
function isSandboxPolicy(value) {
|
|
36238
36475
|
return value === "bwrap" || value === "off";
|
|
@@ -36277,7 +36514,7 @@ function harnessHomeStateDirs(agentCommand, home = homedir13()) {
|
|
|
36277
36514
|
return [];
|
|
36278
36515
|
for (const { match, dirs } of HARNESS_HOME_STATE_DIRS) {
|
|
36279
36516
|
if (match.test(agentCommand))
|
|
36280
|
-
return dirs.map((dir) =>
|
|
36517
|
+
return dirs.map((dir) => resolve25(home, dir));
|
|
36281
36518
|
}
|
|
36282
36519
|
return [];
|
|
36283
36520
|
}
|
|
@@ -36297,10 +36534,10 @@ function credentialMaskPaths(extraPaths, home = homedir13(), stat14 = (path) =>
|
|
|
36297
36534
|
return void 0;
|
|
36298
36535
|
}
|
|
36299
36536
|
}, requiredPaths = []) {
|
|
36300
|
-
const required = new Set(requiredPaths.map((path) =>
|
|
36537
|
+
const required = new Set(requiredPaths.map((path) => resolve25(path)));
|
|
36301
36538
|
const candidates = [
|
|
36302
|
-
...KNOWN_CREDENTIAL_MASK_PATHS.map((entry) =>
|
|
36303
|
-
...(extraPaths ?? []).map((entry) =>
|
|
36539
|
+
...KNOWN_CREDENTIAL_MASK_PATHS.map((entry) => resolve25(home, entry)),
|
|
36540
|
+
...(extraPaths ?? []).map((entry) => resolve25(entry))
|
|
36304
36541
|
];
|
|
36305
36542
|
const seen = /* @__PURE__ */ new Set();
|
|
36306
36543
|
const masks = [];
|
|
@@ -36325,10 +36562,10 @@ function siblingAgentMaskPaths(ownRuntimeDir, listAgentDirs = (agentsRoot) => {
|
|
|
36325
36562
|
return [];
|
|
36326
36563
|
}
|
|
36327
36564
|
}) {
|
|
36328
|
-
const own =
|
|
36565
|
+
const own = resolve25(ownRuntimeDir);
|
|
36329
36566
|
const agentsRoot = dirname19(own);
|
|
36330
36567
|
const ownName = basename7(own).toLowerCase();
|
|
36331
|
-
return listAgentDirs(agentsRoot).filter((name) => name.toLowerCase() !== ownName).map((name) => ({ path:
|
|
36568
|
+
return listAgentDirs(agentsRoot).filter((name) => name.toLowerCase() !== ownName).map((name) => ({ path: resolve25(agentsRoot, name), kind: "dir" })).sort((a2, b) => a2.path.localeCompare(b.path));
|
|
36332
36569
|
}
|
|
36333
36570
|
var DEFAULT_SANDBOX_DEVICES = ["/dev/kvm"];
|
|
36334
36571
|
function grantedSandboxDevices(result) {
|
|
@@ -36358,7 +36595,7 @@ function sandboxDevicePath(target) {
|
|
|
36358
36595
|
const trimmed = target.trim();
|
|
36359
36596
|
if (!isAbsolute3(trimmed))
|
|
36360
36597
|
return void 0;
|
|
36361
|
-
const path =
|
|
36598
|
+
const path = resolve25(trimmed);
|
|
36362
36599
|
return path.startsWith("/dev/") ? path : void 0;
|
|
36363
36600
|
}
|
|
36364
36601
|
function isUnderTmp(path) {
|
|
@@ -36370,7 +36607,7 @@ function normalize(paths) {
|
|
|
36370
36607
|
for (const path of paths) {
|
|
36371
36608
|
if (!path)
|
|
36372
36609
|
continue;
|
|
36373
|
-
seen.add(
|
|
36610
|
+
seen.add(resolve25(path));
|
|
36374
36611
|
}
|
|
36375
36612
|
return Array.from(seen).sort();
|
|
36376
36613
|
}
|
|
@@ -36407,14 +36644,14 @@ function sandboxMountPlan(spec) {
|
|
|
36407
36644
|
const requiredMounts = [];
|
|
36408
36645
|
const boundaryMasks = [];
|
|
36409
36646
|
if (shared) {
|
|
36410
|
-
const assetRoot =
|
|
36411
|
-
const agentsRoot = dirname19(
|
|
36647
|
+
const assetRoot = resolve25(shared.assetRoot);
|
|
36648
|
+
const agentsRoot = dirname19(resolve25(shared.agentRuntimeDir));
|
|
36412
36649
|
const workspacesRoot = dirname19(dirname19(assetRoot));
|
|
36413
36650
|
boundaryMasks.push({ path: workspacesRoot, kind: "dir" }, { path: agentsRoot, kind: "dir" });
|
|
36414
36651
|
const add = (path, mode, target = path) => {
|
|
36415
|
-
requiredMounts.push({ source:
|
|
36652
|
+
requiredMounts.push({ source: resolve25(path), target: resolve25(target), mode });
|
|
36416
36653
|
};
|
|
36417
|
-
const cwd =
|
|
36654
|
+
const cwd = resolve25(spec.cwd);
|
|
36418
36655
|
const relativeCwd = relative(agentsRoot, cwd);
|
|
36419
36656
|
if (relativeCwd === "" || relativeCwd !== ".." && !relativeCwd.startsWith(`..${sep}`) && !isAbsolute3(relativeCwd))
|
|
36420
36657
|
add(cwd, spec.mode === "edit" ? "bind" : "ro-bind");
|
|
@@ -36423,34 +36660,34 @@ function sandboxMountPlan(spec) {
|
|
|
36423
36660
|
add(shared.privateRoot, "bind");
|
|
36424
36661
|
if (shared.privateAssetRoot && shared.isolatedCategories?.length)
|
|
36425
36662
|
add(shared.privateAssetRoot, "bind");
|
|
36426
|
-
add(
|
|
36663
|
+
add(resolve25(shared.agentRuntimeDir, "runtime.json"), "ro-bind");
|
|
36427
36664
|
for (const path of spec.additionalWritablePaths ?? []) {
|
|
36428
|
-
const rel = relative(cwd,
|
|
36665
|
+
const rel = relative(cwd, resolve25(path));
|
|
36429
36666
|
if (rel && rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute3(rel))
|
|
36430
36667
|
add(path, "bind");
|
|
36431
36668
|
}
|
|
36432
|
-
add(
|
|
36433
|
-
const source = (category, suffix) => shared.privateAssetRoot && shared.isolatedCategories?.includes(category) ?
|
|
36669
|
+
add(resolve25(assetRoot, "cache"), "bind");
|
|
36670
|
+
const source = (category, suffix) => shared.privateAssetRoot && shared.isolatedCategories?.includes(category) ? resolve25(shared.privateAssetRoot, suffix) : resolve25(assetRoot, suffix);
|
|
36434
36671
|
if (shared.privateAssetRoot) {
|
|
36435
36672
|
for (const suffix of shared.isolatedCategories?.includes("package-cache") ? PACKAGE_CACHE_DIRS : [])
|
|
36436
|
-
add(
|
|
36673
|
+
add(resolve25(shared.privateAssetRoot, "cache", suffix), "bind", resolve25(assetRoot, "cache", suffix));
|
|
36437
36674
|
for (const [category, suffix] of [
|
|
36438
36675
|
["codex-download-cache", "cache/codex/download"],
|
|
36439
36676
|
["codex-plugin-cache", "cache/codex/plugins"]
|
|
36440
36677
|
]) {
|
|
36441
36678
|
if (shared.isolatedCategories?.includes(category))
|
|
36442
|
-
add(
|
|
36679
|
+
add(resolve25(shared.privateAssetRoot, suffix), "bind", resolve25(assetRoot, suffix));
|
|
36443
36680
|
}
|
|
36444
36681
|
}
|
|
36445
36682
|
if (shared.codexHome) {
|
|
36446
|
-
add(source("codex-download-cache", "cache/codex/download"), "bind",
|
|
36447
|
-
add(source("codex-plugin-cache", "cache/codex/plugins"), "bind",
|
|
36683
|
+
add(source("codex-download-cache", "cache/codex/download"), "bind", resolve25(shared.codexHome, "cache"));
|
|
36684
|
+
add(source("codex-plugin-cache", "cache/codex/plugins"), "bind", resolve25(shared.codexHome, "plugins/cache"));
|
|
36448
36685
|
}
|
|
36449
36686
|
if (shared.packageHome) {
|
|
36450
|
-
add(source("package-cache", "cache/cargo/registry"), "bind",
|
|
36687
|
+
add(source("package-cache", "cache/cargo/registry"), "bind", resolve25(shared.packageHome, ".cargo/registry"));
|
|
36451
36688
|
}
|
|
36452
36689
|
for (const name of ["tools", "avd-base"])
|
|
36453
|
-
add(
|
|
36690
|
+
add(resolve25(assetRoot, name), "ro-bind");
|
|
36454
36691
|
}
|
|
36455
36692
|
return {
|
|
36456
36693
|
...spec.mode === "edit" ? { rootWritable: true } : {},
|
|
@@ -36458,7 +36695,7 @@ function sandboxMountPlan(spec) {
|
|
|
36458
36695
|
writable,
|
|
36459
36696
|
quotaTmpfs: spec.workbench ? [
|
|
36460
36697
|
{
|
|
36461
|
-
target:
|
|
36698
|
+
target: resolve25(spec.workbench.dir),
|
|
36462
36699
|
maxBytes: spec.workbench.maxBytes,
|
|
36463
36700
|
maxInodes: spec.workbench.maxInodes,
|
|
36464
36701
|
blockGit: true
|
|
@@ -36522,7 +36759,7 @@ function buildBwrapArgv(input) {
|
|
|
36522
36759
|
for (const binding of quotaTmpfs) {
|
|
36523
36760
|
args.push("--dir", binding.target, "--size", String(binding.maxBytes), "--tmpfs", binding.target);
|
|
36524
36761
|
if (binding.blockGit)
|
|
36525
|
-
args.push("--ro-bind", "/dev/null",
|
|
36762
|
+
args.push("--ro-bind", "/dev/null", resolve25(binding.target, ".git"));
|
|
36526
36763
|
}
|
|
36527
36764
|
args.push("--chdir", input.cwd);
|
|
36528
36765
|
args.push("--die-with-parent");
|
|
@@ -36594,7 +36831,7 @@ var INSTALL_RETRY_AFTER_HOURS = 24;
|
|
|
36594
36831
|
var INSTALL_RETRY_AFTER_MS = INSTALL_RETRY_AFTER_HOURS * 60 * 6e4;
|
|
36595
36832
|
var INSTALL_FAILURE_MARKER = "bubblewrap-install-failed";
|
|
36596
36833
|
function installFailureMarker(stateDir) {
|
|
36597
|
-
return
|
|
36834
|
+
return resolve25(stateDir, INSTALL_FAILURE_MARKER);
|
|
36598
36835
|
}
|
|
36599
36836
|
function readInstallFailure(stateDir) {
|
|
36600
36837
|
if (!stateDir)
|
|
@@ -36623,7 +36860,7 @@ function clearInstallFailure(stateDir) {
|
|
|
36623
36860
|
} catch {
|
|
36624
36861
|
}
|
|
36625
36862
|
}
|
|
36626
|
-
var runSandboxInstallCommand = (command, args) => new Promise((
|
|
36863
|
+
var runSandboxInstallCommand = (command, args) => new Promise((resolve53) => {
|
|
36627
36864
|
execFile10(command, [...args], {
|
|
36628
36865
|
timeout: INSTALL_TIMEOUT_MS,
|
|
36629
36866
|
maxBuffer: INSTALL_OUTPUT_LIMIT * 2,
|
|
@@ -36633,7 +36870,7 @@ var runSandboxInstallCommand = (command, args) => new Promise((resolve52) => {
|
|
|
36633
36870
|
}, (error, stdout6, stderr) => {
|
|
36634
36871
|
const code = error && "code" in error && typeof error.code === "number" ? error.code : error ? null : 0;
|
|
36635
36872
|
const output = [stdout6, stderr].join("").trim();
|
|
36636
|
-
|
|
36873
|
+
resolve53({ code, output: output || (error ? error.message : "") });
|
|
36637
36874
|
});
|
|
36638
36875
|
});
|
|
36639
36876
|
function lastLine2(output, fallback) {
|
|
@@ -36742,10 +36979,10 @@ var SANDBOX_STARTED_SCRIPT = ['printf "%s\\n" "$1" >&2', "shift", 'exec "$@"'].j
|
|
|
36742
36979
|
var ROOM_SANDBOX_UNAVAILABLE = "this Room cannot run granted commands: a Room promises a read-only filesystem and that promise is enforced by bubblewrap, which is not usable on this host. Open a corner with open_corner and run it there, where writes belong.";
|
|
36743
36980
|
var ROOM_WRITE_REFUSED_NOTE = "[beeline] the Room filesystem is read-only outside your scratch directory, so this write was refused by the kernel. Open a corner with open_corner to change files.";
|
|
36744
36981
|
function operatorSecretsPath(env = process.env) {
|
|
36745
|
-
return
|
|
36982
|
+
return resolve26(dirname20(providerKeyStorePath(env)), "secrets.json");
|
|
36746
36983
|
}
|
|
36747
36984
|
async function readOperatorSecrets(env = process.env) {
|
|
36748
|
-
const raw = await
|
|
36985
|
+
const raw = await readFile23(operatorSecretsPath(env), "utf8").catch(() => void 0);
|
|
36749
36986
|
if (!raw)
|
|
36750
36987
|
return {};
|
|
36751
36988
|
try {
|
|
@@ -36958,7 +37195,7 @@ ${ROOM_WRITE_REFUSED_NOTE}` : outcome.output, secrets), cap);
|
|
|
36958
37195
|
return;
|
|
36959
37196
|
let bytes;
|
|
36960
37197
|
for (const candidate of candidates) {
|
|
36961
|
-
bytes = await
|
|
37198
|
+
bytes = await readFile23(candidate).catch(() => void 0);
|
|
36962
37199
|
if (bytes)
|
|
36963
37200
|
break;
|
|
36964
37201
|
}
|
|
@@ -36978,8 +37215,8 @@ function scriptCandidates(cwd, scratch, argv) {
|
|
|
36978
37215
|
if (!argument)
|
|
36979
37216
|
return [];
|
|
36980
37217
|
const paths = [
|
|
36981
|
-
|
|
36982
|
-
...scratch ? [
|
|
37218
|
+
resolve26(cwd, argument.path),
|
|
37219
|
+
...scratch ? [resolve26(scratch, argument.path)] : []
|
|
36983
37220
|
];
|
|
36984
37221
|
return [...new Set(paths)];
|
|
36985
37222
|
}
|
|
@@ -37161,13 +37398,13 @@ function captureConnectionUsage(recorder, turn, calls) {
|
|
|
37161
37398
|
}
|
|
37162
37399
|
|
|
37163
37400
|
// apps/body/dist/model-context-window.js
|
|
37164
|
-
import { readFile as
|
|
37401
|
+
import { readFile as readFile24 } from "node:fs/promises";
|
|
37165
37402
|
import { join as join12 } from "node:path";
|
|
37166
37403
|
async function modelContextWindowTokens(model, piHome) {
|
|
37167
37404
|
if (!model || !piHome)
|
|
37168
37405
|
return void 0;
|
|
37169
37406
|
try {
|
|
37170
|
-
const catalog = JSON.parse(await
|
|
37407
|
+
const catalog = JSON.parse(await readFile24(join12(piHome, "models.json"), "utf8"));
|
|
37171
37408
|
const parts = model.split("/");
|
|
37172
37409
|
const preferredProvider = parts.length > 2 ? parts.shift() : void 0;
|
|
37173
37410
|
const modelId = parts.join("/");
|
|
@@ -37183,11 +37420,11 @@ async function modelContextWindowTokens(model, piHome) {
|
|
|
37183
37420
|
}
|
|
37184
37421
|
|
|
37185
37422
|
// apps/body/dist/turn-usage.js
|
|
37186
|
-
import { readFile as
|
|
37423
|
+
import { readFile as readFile26 } from "node:fs/promises";
|
|
37187
37424
|
|
|
37188
37425
|
// apps/body/dist/pi-turn-record.js
|
|
37189
|
-
import { readdir as
|
|
37190
|
-
import { resolve as
|
|
37426
|
+
import { readdir as readdir8, readFile as readFile25 } from "node:fs/promises";
|
|
37427
|
+
import { resolve as resolve27 } from "node:path";
|
|
37191
37428
|
function summarizeProviderError(errorMessage2) {
|
|
37192
37429
|
const trimmed = errorMessage2.trim();
|
|
37193
37430
|
const statusMatch = /^(\d{3}):\s*([\s\S]*)$/.exec(trimmed);
|
|
@@ -37214,7 +37451,7 @@ async function piSessionFilePath(agentEnv, sessionId) {
|
|
|
37214
37451
|
}
|
|
37215
37452
|
async function sessionFileFromMap(home, sessionId) {
|
|
37216
37453
|
try {
|
|
37217
|
-
const raw = await
|
|
37454
|
+
const raw = await readFile25(resolve27(home, ".pi", "pi-acp", "session-map.json"), "utf8");
|
|
37218
37455
|
const map = JSON.parse(raw);
|
|
37219
37456
|
const file = map.sessions?.[sessionId]?.sessionFile;
|
|
37220
37457
|
return typeof file === "string" && file ? file : void 0;
|
|
@@ -37223,25 +37460,25 @@ async function sessionFileFromMap(home, sessionId) {
|
|
|
37223
37460
|
}
|
|
37224
37461
|
}
|
|
37225
37462
|
async function sessionFileFromLayout(piDir, sessionId) {
|
|
37226
|
-
const sessionsRoot =
|
|
37463
|
+
const sessionsRoot = resolve27(piDir, "sessions");
|
|
37227
37464
|
const suffix = `_${sessionId}.jsonl`;
|
|
37228
37465
|
let projects;
|
|
37229
37466
|
try {
|
|
37230
|
-
projects = await
|
|
37467
|
+
projects = await readdir8(sessionsRoot);
|
|
37231
37468
|
} catch {
|
|
37232
37469
|
return void 0;
|
|
37233
37470
|
}
|
|
37234
37471
|
for (const project of projects) {
|
|
37235
|
-
const dir =
|
|
37472
|
+
const dir = resolve27(sessionsRoot, project);
|
|
37236
37473
|
let files;
|
|
37237
37474
|
try {
|
|
37238
|
-
files = await
|
|
37475
|
+
files = await readdir8(dir);
|
|
37239
37476
|
} catch {
|
|
37240
37477
|
continue;
|
|
37241
37478
|
}
|
|
37242
37479
|
const match = files.find((file) => file.endsWith(suffix));
|
|
37243
37480
|
if (match)
|
|
37244
|
-
return
|
|
37481
|
+
return resolve27(dir, match);
|
|
37245
37482
|
}
|
|
37246
37483
|
return void 0;
|
|
37247
37484
|
}
|
|
@@ -37256,7 +37493,7 @@ async function readPiTurnRecord(input) {
|
|
|
37256
37493
|
return void 0;
|
|
37257
37494
|
let raw;
|
|
37258
37495
|
try {
|
|
37259
|
-
raw = await
|
|
37496
|
+
raw = await readFile25(file, "utf8");
|
|
37260
37497
|
} catch {
|
|
37261
37498
|
return void 0;
|
|
37262
37499
|
}
|
|
@@ -37315,7 +37552,7 @@ async function readUsageCalls(input, latestTurn) {
|
|
|
37315
37552
|
const file = await piSessionFilePath(input.agentEnv, input.sessionId);
|
|
37316
37553
|
if (!file)
|
|
37317
37554
|
return latestTurn ? void 0 : [];
|
|
37318
|
-
const raw = await
|
|
37555
|
+
const raw = await readFile26(file, "utf8").catch(() => void 0);
|
|
37319
37556
|
if (raw === void 0)
|
|
37320
37557
|
return void 0;
|
|
37321
37558
|
const calls = [];
|
|
@@ -37543,11 +37780,11 @@ async function runServerCommandIntake(options) {
|
|
|
37543
37780
|
if (attempt === 3)
|
|
37544
37781
|
throw error;
|
|
37545
37782
|
const waitMs = Math.max(250 * 2 ** attempt, error instanceof DaemonApiError ? error.retryAfterMs ?? 0 : 0);
|
|
37546
|
-
await new Promise((
|
|
37783
|
+
await new Promise((resolve53) => {
|
|
37547
37784
|
const done = () => {
|
|
37548
37785
|
clearTimeout(timer);
|
|
37549
37786
|
signal?.removeEventListener("abort", done);
|
|
37550
|
-
|
|
37787
|
+
resolve53();
|
|
37551
37788
|
};
|
|
37552
37789
|
const timer = setTimeout(done, waitMs);
|
|
37553
37790
|
signal?.addEventListener("abort", done, { once: true });
|
|
@@ -37649,11 +37886,11 @@ async function runServerCommandIntake(options) {
|
|
|
37649
37886
|
}
|
|
37650
37887
|
}
|
|
37651
37888
|
options.onPoll?.();
|
|
37652
|
-
const reconcile = await new Promise((
|
|
37889
|
+
const reconcile = await new Promise((resolve53) => {
|
|
37653
37890
|
const done = (needed) => {
|
|
37654
37891
|
signal?.removeEventListener("abort", aborted);
|
|
37655
37892
|
wake = void 0;
|
|
37656
|
-
|
|
37893
|
+
resolve53(needed);
|
|
37657
37894
|
};
|
|
37658
37895
|
const aborted = () => done(false);
|
|
37659
37896
|
wake = done;
|
|
@@ -37696,9 +37933,9 @@ async function runServerCommandIntake(options) {
|
|
|
37696
37933
|
import { execFile as execFile17 } from "node:child_process";
|
|
37697
37934
|
import { createHash as createHash16 } from "node:crypto";
|
|
37698
37935
|
import { existsSync as existsSync9 } from "node:fs";
|
|
37699
|
-
import { mkdir as mkdir27, readFile as
|
|
37936
|
+
import { mkdir as mkdir27, readFile as readFile33, writeFile as writeFile21 } from "node:fs/promises";
|
|
37700
37937
|
import { homedir as homedir17, hostname as hostname4 } from "node:os";
|
|
37701
|
-
import { dirname as dirname26, join as join20, resolve as
|
|
37938
|
+
import { dirname as dirname26, join as join20, resolve as resolve41 } from "node:path";
|
|
37702
37939
|
import { promisify as promisify11 } from "node:util";
|
|
37703
37940
|
|
|
37704
37941
|
// apps/body/dist/machine-host.js
|
|
@@ -37706,16 +37943,16 @@ import { execFile as execFile12 } from "node:child_process";
|
|
|
37706
37943
|
import { hostname as hostname2 } from "node:os";
|
|
37707
37944
|
async function machineHost() {
|
|
37708
37945
|
const local = hostname2();
|
|
37709
|
-
const tailscaleName = await new Promise((
|
|
37946
|
+
const tailscaleName = await new Promise((resolve53) => {
|
|
37710
37947
|
execFile12("tailscale", ["status", "--json"], { timeout: 1500, maxBuffer: 64 * 1024 }, (error, stdout6) => {
|
|
37711
37948
|
if (error)
|
|
37712
|
-
return
|
|
37949
|
+
return resolve53(void 0);
|
|
37713
37950
|
try {
|
|
37714
37951
|
const status = JSON.parse(stdout6);
|
|
37715
37952
|
const name = status.BackendState === "Running" ? status.Self?.DNSName?.replace(/\.$/, "") : void 0;
|
|
37716
|
-
|
|
37953
|
+
resolve53(name || void 0);
|
|
37717
37954
|
} catch {
|
|
37718
|
-
|
|
37955
|
+
resolve53(void 0);
|
|
37719
37956
|
}
|
|
37720
37957
|
});
|
|
37721
37958
|
});
|
|
@@ -38522,9 +38759,9 @@ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false } = {}) {
|
|
|
38522
38759
|
|
|
38523
38760
|
// apps/body/dist/agent-home.js
|
|
38524
38761
|
import { createHash as createHash13, randomUUID as randomUUID13 } from "node:crypto";
|
|
38525
|
-
import { chmod as chmod8, copyFile, lstat as
|
|
38762
|
+
import { chmod as chmod8, copyFile, lstat as lstat6, mkdir as mkdir19, readFile as readFile27, readlink, readdir as readdir9, realpath as realpath2, rename as rename10, rm as rm14, symlink as symlink2, unlink as unlink6, writeFile as writeFile17 } from "node:fs/promises";
|
|
38526
38763
|
import { homedir as homedir14 } from "node:os";
|
|
38527
|
-
import { basename as basename8, dirname as dirname22, join as join15, relative as relative2, resolve as
|
|
38764
|
+
import { basename as basename8, dirname as dirname22, join as join15, relative as relative2, resolve as resolve31, sep as sep2 } from "node:path";
|
|
38528
38765
|
|
|
38529
38766
|
// apps/body/dist/draw-avatar-skill.js
|
|
38530
38767
|
var DRAW_AVATAR_SKILL_NAME = "draw-avatar";
|
|
@@ -38614,7 +38851,7 @@ set_avatar renders bounded geometry to durable image bytes and replaces your cur
|
|
|
38614
38851
|
// apps/body/dist/android-agent-env.js
|
|
38615
38852
|
import { createHash as createHash12 } from "node:crypto";
|
|
38616
38853
|
import { existsSync as existsSync7 } from "node:fs";
|
|
38617
|
-
import { delimiter as delimiter2, resolve as
|
|
38854
|
+
import { delimiter as delimiter2, resolve as resolve28 } from "node:path";
|
|
38618
38855
|
var ANDROID_FIRST_EMULATOR_PORT = 5600;
|
|
38619
38856
|
var ANDROID_PORT_SLOTS = 100;
|
|
38620
38857
|
function androidAgentEnv(input) {
|
|
@@ -38622,25 +38859,25 @@ function androidAgentEnv(input) {
|
|
|
38622
38859
|
const sdk = [
|
|
38623
38860
|
env.ANDROID_HOME,
|
|
38624
38861
|
env.ANDROID_SDK_ROOT,
|
|
38625
|
-
|
|
38626
|
-
|
|
38627
|
-
].find((path) => path && existsSync7(
|
|
38862
|
+
resolve28(input.operatorHome, "android-sdk"),
|
|
38863
|
+
resolve28(input.operatorHome, "Android/Sdk")
|
|
38864
|
+
].find((path) => path && existsSync7(resolve28(path, "platform-tools/adb")));
|
|
38628
38865
|
if (!sdk)
|
|
38629
38866
|
return {};
|
|
38630
|
-
const emulatorHome = env.ANDROID_EMULATOR_HOME ??
|
|
38631
|
-
const slot = createHash12("sha256").update(
|
|
38867
|
+
const emulatorHome = env.ANDROID_EMULATOR_HOME ?? resolve28(input.operatorHome, ".android");
|
|
38868
|
+
const slot = createHash12("sha256").update(resolve28(input.root)).digest().readUInt32BE(0) % ANDROID_PORT_SLOTS;
|
|
38632
38869
|
const emulatorPort = ANDROID_FIRST_EMULATOR_PORT + slot * 4;
|
|
38633
38870
|
return {
|
|
38634
38871
|
ANDROID_HOME: sdk,
|
|
38635
38872
|
ANDROID_SDK_ROOT: sdk,
|
|
38636
38873
|
ANDROID_EMULATOR_HOME: emulatorHome,
|
|
38637
|
-
ANDROID_AVD_HOME: env.ANDROID_AVD_HOME ??
|
|
38874
|
+
ANDROID_AVD_HOME: env.ANDROID_AVD_HOME ?? resolve28(emulatorHome, "avd"),
|
|
38638
38875
|
ANDROID_ADB_SERVER_PORT: String(emulatorPort + 2),
|
|
38639
38876
|
ADB_EMU: "0",
|
|
38640
38877
|
BEELINE_ANDROID_EMULATOR_PORT: String(emulatorPort),
|
|
38641
38878
|
PATH: [
|
|
38642
|
-
|
|
38643
|
-
|
|
38879
|
+
resolve28(sdk, "platform-tools"),
|
|
38880
|
+
resolve28(sdk, "emulator"),
|
|
38644
38881
|
input.inheritedPath ?? env.PATH
|
|
38645
38882
|
].filter(Boolean).join(delimiter2)
|
|
38646
38883
|
};
|
|
@@ -38648,7 +38885,7 @@ function androidAgentEnv(input) {
|
|
|
38648
38885
|
|
|
38649
38886
|
// apps/body/dist/beeline-skill.js
|
|
38650
38887
|
import { readFileSync as readFileSync9 } from "node:fs";
|
|
38651
|
-
import { resolve as
|
|
38888
|
+
import { resolve as resolve29 } from "node:path";
|
|
38652
38889
|
var USING_BEELINE_SKILL_NAME = "using-beeline";
|
|
38653
38890
|
var BEELINE_TRIAGE_SKILL_NAME = "beeline-triage";
|
|
38654
38891
|
var BEELINE_REVIEW_SKILL_NAME = "beeline-review";
|
|
@@ -38667,7 +38904,7 @@ function runningBeelineReleaseId(env = process.env, read2 = (path) => readFileSy
|
|
|
38667
38904
|
const lib = env.BEELINE_LIB_DIR;
|
|
38668
38905
|
if (!lib)
|
|
38669
38906
|
return "source";
|
|
38670
|
-
const manifest = JSON.parse(read2(
|
|
38907
|
+
const manifest = JSON.parse(read2(resolve29(lib, "bundle.json")));
|
|
38671
38908
|
return [manifest.version, manifest.commit].filter(Boolean).join("-") || "source";
|
|
38672
38909
|
} catch {
|
|
38673
38910
|
return "source";
|
|
@@ -39028,7 +39265,7 @@ var SQUIRE_GOVERNED_TOOLS = [
|
|
|
39028
39265
|
var SQUIRE_GOVERNED_TOOL_SET = new Set(SQUIRE_GOVERNED_TOOLS);
|
|
39029
39266
|
|
|
39030
39267
|
// apps/body/dist/host-mcp-route.js
|
|
39031
|
-
import { join as join14, resolve as
|
|
39268
|
+
import { join as join14, resolve as resolve30 } from "node:path";
|
|
39032
39269
|
var import_yaml = __toESM(require_dist(), 1);
|
|
39033
39270
|
init_squire_host();
|
|
39034
39271
|
function grantedMcpServerNames(grants) {
|
|
@@ -39083,7 +39320,7 @@ function grantedSquireHostRouteNames(granted, declarations = {}) {
|
|
|
39083
39320
|
});
|
|
39084
39321
|
}
|
|
39085
39322
|
function hostRouteEnv(hostHome) {
|
|
39086
|
-
return { XDG_CONFIG_HOME: join14(
|
|
39323
|
+
return { XDG_CONFIG_HOME: join14(resolve30(hostHome), ".config") };
|
|
39087
39324
|
}
|
|
39088
39325
|
function rewriteHostMcpDeclaration(name, declaration, hostHome, resourceAuthFile, squireScope) {
|
|
39089
39326
|
const next = { ...declaration };
|
|
@@ -39477,7 +39714,7 @@ async function withSharedClaudeLoginLock(shared, write2) {
|
|
|
39477
39714
|
} catch (error) {
|
|
39478
39715
|
if (error.code !== "EEXIST")
|
|
39479
39716
|
throw error;
|
|
39480
|
-
const held = await
|
|
39717
|
+
const held = await lstat6(lock).catch(() => void 0);
|
|
39481
39718
|
if (held && Date.now() - held.mtimeMs > CLAUDE_LOGIN_LOCK_STALE_MS) {
|
|
39482
39719
|
await rm14(lock, { force: true });
|
|
39483
39720
|
continue;
|
|
@@ -39494,13 +39731,13 @@ async function withSharedClaudeLoginLock(shared, write2) {
|
|
|
39494
39731
|
}
|
|
39495
39732
|
}
|
|
39496
39733
|
async function writeBackDetachedClaudeLogin(target, source) {
|
|
39497
|
-
const detached = await
|
|
39734
|
+
const detached = await readFile27(target, "utf8");
|
|
39498
39735
|
const detachedExpiresAt = claudeLoginExpiresAt(detached);
|
|
39499
39736
|
if (detachedExpiresAt === void 0)
|
|
39500
39737
|
return "not-newer";
|
|
39501
39738
|
const shared = await realpath2(source);
|
|
39502
39739
|
const isNewer = async () => {
|
|
39503
|
-
const sharedExpiresAt = claudeLoginExpiresAt(await
|
|
39740
|
+
const sharedExpiresAt = claudeLoginExpiresAt(await readFile27(shared, "utf8"));
|
|
39504
39741
|
return sharedExpiresAt !== void 0 && detachedExpiresAt > sharedExpiresAt;
|
|
39505
39742
|
};
|
|
39506
39743
|
if (!await isNewer())
|
|
@@ -39523,7 +39760,7 @@ async function writeBackDetachedClaudeLogin(target, source) {
|
|
|
39523
39760
|
return "busy";
|
|
39524
39761
|
if (!written)
|
|
39525
39762
|
return "not-newer";
|
|
39526
|
-
if (await
|
|
39763
|
+
if (await readFile27(target, "utf8") !== detached)
|
|
39527
39764
|
return "busy";
|
|
39528
39765
|
const link2 = `${target}.beeline-link-${randomUUID13()}`;
|
|
39529
39766
|
await symlink2(source, link2);
|
|
@@ -39531,22 +39768,22 @@ async function writeBackDetachedClaudeLogin(target, source) {
|
|
|
39531
39768
|
return "linked";
|
|
39532
39769
|
}
|
|
39533
39770
|
async function repairRoomAgentCredentialLinks(input) {
|
|
39534
|
-
const root =
|
|
39771
|
+
const root = resolve31(input.root);
|
|
39535
39772
|
const operatorHome = input.operatorHome ?? homedir14();
|
|
39536
39773
|
for (const credential of SHARED_CREDENTIALS) {
|
|
39537
|
-
const source =
|
|
39774
|
+
const source = resolve31(operatorHome, credential.source);
|
|
39538
39775
|
if (!existsSync8(source))
|
|
39539
39776
|
continue;
|
|
39540
|
-
const target =
|
|
39777
|
+
const target = resolve31(root, credential.dir, credential.target);
|
|
39541
39778
|
await mkdir19(dirname22(target), { recursive: true, mode: 448 });
|
|
39542
|
-
const stats = await
|
|
39779
|
+
const stats = await lstat6(target).catch((error) => {
|
|
39543
39780
|
if (isMissingPathError(error))
|
|
39544
39781
|
return void 0;
|
|
39545
39782
|
throw error;
|
|
39546
39783
|
});
|
|
39547
39784
|
if (stats?.isSymbolicLink()) {
|
|
39548
39785
|
const linked = await readlink(target);
|
|
39549
|
-
if (
|
|
39786
|
+
if (resolve31(dirname22(target), linked) === source)
|
|
39550
39787
|
continue;
|
|
39551
39788
|
}
|
|
39552
39789
|
if (stats) {
|
|
@@ -39563,20 +39800,20 @@ async function repairRoomAgentCredentialLinks(input) {
|
|
|
39563
39800
|
}
|
|
39564
39801
|
async function writeBackRoomClaudeLogin(input) {
|
|
39565
39802
|
const claude = SHARED_CREDENTIALS.find((credential) => credential.dir === "claude");
|
|
39566
|
-
const source =
|
|
39803
|
+
const source = resolve31(input.operatorHome ?? homedir14(), claude.source);
|
|
39567
39804
|
if (!existsSync8(source))
|
|
39568
39805
|
return;
|
|
39569
|
-
const target =
|
|
39570
|
-
const stats = await
|
|
39806
|
+
const target = resolve31(input.root, claude.dir, claude.target);
|
|
39807
|
+
const stats = await lstat6(target).catch(() => void 0);
|
|
39571
39808
|
if (!stats?.isFile())
|
|
39572
39809
|
return;
|
|
39573
39810
|
await writeBackDetachedClaudeLogin(target, source);
|
|
39574
39811
|
}
|
|
39575
39812
|
function watchRoomClaudeLogin(input) {
|
|
39576
39813
|
const claude = SHARED_CREDENTIALS.find((credential) => credential.dir === "claude");
|
|
39577
|
-
if (!existsSync8(
|
|
39814
|
+
if (!existsSync8(resolve31(input.operatorHome ?? homedir14(), claude.source)))
|
|
39578
39815
|
return void 0;
|
|
39579
|
-
const dir =
|
|
39816
|
+
const dir = resolve31(input.root, claude.dir);
|
|
39580
39817
|
let pass = Promise.resolve();
|
|
39581
39818
|
let watcher;
|
|
39582
39819
|
try {
|
|
@@ -39599,23 +39836,23 @@ function watchRoomClaudeLogin(input) {
|
|
|
39599
39836
|
return watcher;
|
|
39600
39837
|
}
|
|
39601
39838
|
async function prepareRoomAgentHome(input) {
|
|
39602
|
-
const root =
|
|
39839
|
+
const root = resolve31(input.root);
|
|
39603
39840
|
const operatorHome = input.operatorHome ?? homedir14();
|
|
39604
39841
|
let tmpLinkReady = false;
|
|
39605
39842
|
try {
|
|
39606
39843
|
await mkdir19(root, { recursive: true, mode: 448 });
|
|
39607
|
-
const rootStats = await
|
|
39844
|
+
const rootStats = await lstat6(root);
|
|
39608
39845
|
if (!rootStats.isDirectory() || rootStats.isSymbolicLink()) {
|
|
39609
39846
|
throw new AgentHomeSecurityError(`agent home root is not an ordinary directory: ${root}`);
|
|
39610
39847
|
}
|
|
39611
39848
|
for (const subdir of HOME_SUBDIRS) {
|
|
39612
|
-
const path =
|
|
39849
|
+
const path = resolve31(root, subdir);
|
|
39613
39850
|
await mkdir19(path, { recursive: true, mode: 448 });
|
|
39614
39851
|
await assertRealContainedDirectory(path, root);
|
|
39615
39852
|
}
|
|
39616
39853
|
try {
|
|
39617
39854
|
const tmpLink = roomSessionTmpDir(root);
|
|
39618
|
-
const tmpTarget =
|
|
39855
|
+
const tmpTarget = resolve31(root, "tmp");
|
|
39619
39856
|
if (await readlink(tmpLink).catch(() => void 0) !== tmpTarget) {
|
|
39620
39857
|
await rm14(tmpLink, { recursive: true, force: true });
|
|
39621
39858
|
await symlink2(tmpTarget, tmpLink);
|
|
@@ -39650,7 +39887,7 @@ async function prepareRoomAgentHome(input) {
|
|
|
39650
39887
|
if (agentHomeProvisionQueues.get(root) === provision)
|
|
39651
39888
|
agentHomeProvisionQueues.delete(root);
|
|
39652
39889
|
}
|
|
39653
|
-
const env = tmpLinkReady ? roomAgentHomeEnv(root) : { ...roomAgentHomeEnv(root), TMPDIR:
|
|
39890
|
+
const env = tmpLinkReady ? roomAgentHomeEnv(root) : { ...roomAgentHomeEnv(root), TMPDIR: resolve31(root, "tmp") };
|
|
39654
39891
|
return {
|
|
39655
39892
|
...env,
|
|
39656
39893
|
...androidAgentEnv({
|
|
@@ -39669,11 +39906,11 @@ async function provisionAgentSkillsAndMcp(root, operatorHome, skillReleaseId, fa
|
|
|
39669
39906
|
...isReviewer ? [{ name: BEELINE_REVIEW_SKILL_NAME, content: beelineReviewSkillMarkdown(skillReleaseId) }] : []
|
|
39670
39907
|
];
|
|
39671
39908
|
const shared = await resolveSharedSkillSources(operatorHome, sharedSkills);
|
|
39672
|
-
await provisionManagedSkillsDir(
|
|
39909
|
+
await provisionManagedSkillsDir(resolve31(root, skillDir, "skills"), managedSkills, shared, sharedSkills.length === 0);
|
|
39673
39910
|
for (const config of HARNESS_MCP_CONFIGS) {
|
|
39674
39911
|
try {
|
|
39675
|
-
const source =
|
|
39676
|
-
const target =
|
|
39912
|
+
const source = resolve31(operatorHome, config.toml);
|
|
39913
|
+
const target = resolve31(root, config.dir, "config.toml");
|
|
39677
39914
|
const mcpSection = existsSync8(source) ? localHarnessMcpToml(readFileSync10(source, "utf8")) : void 0;
|
|
39678
39915
|
const section = config.dir === "codex" ? [CODEX_ROOM_AGENT_LOCKDOWN_TOML, CODEX_ROOM_WEB_SEARCH_TOML, mcpSection].filter(Boolean).join("\n") : mcpSection;
|
|
39679
39916
|
if (!section) {
|
|
@@ -39688,11 +39925,11 @@ async function provisionAgentSkillsAndMcp(root, operatorHome, skillReleaseId, fa
|
|
|
39688
39925
|
}
|
|
39689
39926
|
}
|
|
39690
39927
|
try {
|
|
39691
|
-
const gooseConfigDir =
|
|
39928
|
+
const gooseConfigDir = resolve31(root, "goose", "config");
|
|
39692
39929
|
await mkdir19(gooseConfigDir, { recursive: true, mode: 448 });
|
|
39693
39930
|
for (const name of GOOSE_SHARED_CONFIG_FILES) {
|
|
39694
|
-
const source =
|
|
39695
|
-
const target =
|
|
39931
|
+
const source = resolve31(operatorHome, ".config", "goose", name);
|
|
39932
|
+
const target = resolve31(gooseConfigDir, name);
|
|
39696
39933
|
if (existsSync8(source)) {
|
|
39697
39934
|
const body = readFileSync10(source, "utf8");
|
|
39698
39935
|
await writeIsolatedHarnessFile(target, name === "config.yaml" ? localGooseConfig(body) : body);
|
|
@@ -39706,8 +39943,8 @@ async function provisionAgentSkillsAndMcp(root, operatorHome, skillReleaseId, fa
|
|
|
39706
39943
|
console.warn("[body] operator Goose configuration passthrough failed:", error);
|
|
39707
39944
|
}
|
|
39708
39945
|
try {
|
|
39709
|
-
const claudeJson =
|
|
39710
|
-
const claudeTarget =
|
|
39946
|
+
const claudeJson = resolve31(operatorHome, ".claude.json");
|
|
39947
|
+
const claudeTarget = resolve31(root, "claude", ".claude.json");
|
|
39711
39948
|
const mcpServers = existsSync8(claudeJson) ? readClaudeUserScopeMcpServers(claudeJson) : void 0;
|
|
39712
39949
|
if (mcpServers && Object.keys(mcpServers).length > 0) {
|
|
39713
39950
|
await writeIsolatedHarnessFile(claudeTarget, `${JSON.stringify({ mcpServers }, null, 2)}
|
|
@@ -39721,8 +39958,8 @@ async function provisionAgentSkillsAndMcp(root, operatorHome, skillReleaseId, fa
|
|
|
39721
39958
|
console.warn("[body] operator MCP passthrough failed for claude:", error);
|
|
39722
39959
|
}
|
|
39723
39960
|
try {
|
|
39724
|
-
const piJson =
|
|
39725
|
-
const piTarget =
|
|
39961
|
+
const piJson = resolve31(operatorHome, PI_MCP_CONFIG.source);
|
|
39962
|
+
const piTarget = resolve31(root, "pi", PI_MCP_CONFIG.target);
|
|
39726
39963
|
const mcpServers = existsSync8(piJson) ? localMcpServers(recordValue2(readJsonObject2(piJson)?.mcpServers) ?? {}) : void 0;
|
|
39727
39964
|
if (mcpServers && Object.keys(mcpServers).length > 0) {
|
|
39728
39965
|
await writeIsolatedHarnessFile(piTarget, `${JSON.stringify({ mcpServers }, null, 2)}
|
|
@@ -39737,7 +39974,7 @@ async function provisionAgentSkillsAndMcp(root, operatorHome, skillReleaseId, fa
|
|
|
39737
39974
|
}
|
|
39738
39975
|
try {
|
|
39739
39976
|
const settings2 = { permissions: { allow: ["WebSearch", "WebFetch"] } };
|
|
39740
|
-
await writeIsolatedHarnessFile(
|
|
39977
|
+
await writeIsolatedHarnessFile(resolve31(root, "claude", "settings.json"), `${JSON.stringify(settings2, null, 2)}
|
|
39741
39978
|
`);
|
|
39742
39979
|
} catch (error) {
|
|
39743
39980
|
if (failClosed)
|
|
@@ -39751,7 +39988,7 @@ async function provisionAgentSkillsAndMcp(root, operatorHome, skillReleaseId, fa
|
|
|
39751
39988
|
httpIdleTimeoutMs: 3e5,
|
|
39752
39989
|
retry: { enabled: true, maxRetries: 3, baseDelayMs: 2e3 }
|
|
39753
39990
|
};
|
|
39754
|
-
await writeIsolatedHarnessFile(
|
|
39991
|
+
await writeIsolatedHarnessFile(resolve31(root, "pi", "settings.json"), `${JSON.stringify(settings2, null, 2)}
|
|
39755
39992
|
`);
|
|
39756
39993
|
}
|
|
39757
39994
|
}
|
|
@@ -39771,7 +40008,7 @@ async function applyGrantedHostRoutes(root, operatorHome, granted, agentKind, fa
|
|
|
39771
40008
|
const routes = routesFor(config.dir);
|
|
39772
40009
|
if (Object.keys(routes).length === 0)
|
|
39773
40010
|
continue;
|
|
39774
|
-
const target =
|
|
40011
|
+
const target = resolve31(root, config.dir, "config.toml");
|
|
39775
40012
|
const existing = existsSync8(target) ? readFileSync10(target, "utf8") : void 0;
|
|
39776
40013
|
const merged = mergeTomlHostRoutes(existing, routes);
|
|
39777
40014
|
if (merged)
|
|
@@ -39780,9 +40017,9 @@ async function applyGrantedHostRoutes(root, operatorHome, granted, agentKind, fa
|
|
|
39780
40017
|
if (appliesToHarness(agentKind, "goose")) {
|
|
39781
40018
|
const routes = routesFor("goose");
|
|
39782
40019
|
if (Object.keys(routes).length > 0) {
|
|
39783
|
-
const gooseConfigDir =
|
|
40020
|
+
const gooseConfigDir = resolve31(root, "goose", "config");
|
|
39784
40021
|
await mkdir19(gooseConfigDir, { recursive: true, mode: 448 });
|
|
39785
|
-
const target =
|
|
40022
|
+
const target = resolve31(gooseConfigDir, "config.yaml");
|
|
39786
40023
|
const existing = existsSync8(target) ? readFileSync10(target, "utf8") : void 0;
|
|
39787
40024
|
const merged = mergeGooseHostRoutes(existing, routes);
|
|
39788
40025
|
if (merged)
|
|
@@ -39792,7 +40029,7 @@ async function applyGrantedHostRoutes(root, operatorHome, granted, agentKind, fa
|
|
|
39792
40029
|
if (appliesToHarness(agentKind, "claude")) {
|
|
39793
40030
|
const routes = routesFor("claude");
|
|
39794
40031
|
if (Object.keys(routes).length > 0) {
|
|
39795
|
-
const target =
|
|
40032
|
+
const target = resolve31(root, "claude", ".claude.json");
|
|
39796
40033
|
const parsed = existsSync8(target) ? readJsonObject2(target) : void 0;
|
|
39797
40034
|
const merged = mergeJsonHostRoutes(recordValue2(parsed?.mcpServers), routes);
|
|
39798
40035
|
if (merged && Object.keys(merged).length > 0) {
|
|
@@ -39804,7 +40041,7 @@ async function applyGrantedHostRoutes(root, operatorHome, granted, agentKind, fa
|
|
|
39804
40041
|
if (appliesToHarness(agentKind, "pi")) {
|
|
39805
40042
|
const routes = routesFor("pi");
|
|
39806
40043
|
if (Object.keys(routes).length > 0) {
|
|
39807
|
-
const target =
|
|
40044
|
+
const target = resolve31(root, "pi", PI_MCP_CONFIG.target);
|
|
39808
40045
|
const parsed = existsSync8(target) ? readJsonObject2(target) : void 0;
|
|
39809
40046
|
const merged = mergeJsonHostRoutes(recordValue2(parsed?.mcpServers), routes);
|
|
39810
40047
|
if (merged && Object.keys(merged).length > 0) {
|
|
@@ -39820,8 +40057,8 @@ async function applyGrantedHostRoutes(root, operatorHome, granted, agentKind, fa
|
|
|
39820
40057
|
}
|
|
39821
40058
|
}
|
|
39822
40059
|
async function provisionPiCustomModelConfig(root, operatorHome, failClosed, openRouterRouting) {
|
|
39823
|
-
const source =
|
|
39824
|
-
const target =
|
|
40060
|
+
const source = resolve31(operatorHome, PI_CUSTOM_MODEL_CONFIG.source);
|
|
40061
|
+
const target = resolve31(root, "pi", PI_CUSTOM_MODEL_CONFIG.target);
|
|
39825
40062
|
let decision2;
|
|
39826
40063
|
if (openRouterRouting) {
|
|
39827
40064
|
decision2 = await resolveOpenRouterRouting(openRouterRouting);
|
|
@@ -39845,7 +40082,7 @@ async function provisionPiCustomModelConfig(root, operatorHome, failClosed, open
|
|
|
39845
40082
|
limits: decision2.limits ?? { maxTokens: OPENROUTER_MAX_OUTPUT_TOKENS }
|
|
39846
40083
|
} : void 0;
|
|
39847
40084
|
try {
|
|
39848
|
-
const sourceStats = await
|
|
40085
|
+
const sourceStats = await lstat6(source).catch(() => void 0);
|
|
39849
40086
|
if (!sourceStats) {
|
|
39850
40087
|
await writeIsolatedHarnessFile(target, `${JSON.stringify(withOpenRouterModelRouting({}, pin), null, 2)}
|
|
39851
40088
|
`);
|
|
@@ -39935,19 +40172,19 @@ function mountedImportedMcpServerNames(input = {}) {
|
|
|
39935
40172
|
const home = env.HOME ?? input.operatorHome ?? homedir14();
|
|
39936
40173
|
const kind = input.agentKind;
|
|
39937
40174
|
if (!kind || kind === "codex") {
|
|
39938
|
-
addTomlMcpNames(names,
|
|
40175
|
+
addTomlMcpNames(names, resolve31(env.CODEX_HOME ?? resolve31(home, ".codex"), "config.toml"));
|
|
39939
40176
|
}
|
|
39940
40177
|
if (!kind || kind === "grok") {
|
|
39941
|
-
addTomlMcpNames(names,
|
|
40178
|
+
addTomlMcpNames(names, resolve31(env.GROK_HOME ?? resolve31(home, ".grok"), "config.toml"));
|
|
39942
40179
|
}
|
|
39943
40180
|
if (!kind || kind === "claude") {
|
|
39944
|
-
addClaudeMcpNames(names,
|
|
40181
|
+
addClaudeMcpNames(names, resolve31(env.CLAUDE_CONFIG_DIR ?? home, ".claude.json"));
|
|
39945
40182
|
}
|
|
39946
40183
|
if (!kind || kind === "goose") {
|
|
39947
|
-
addGooseExtensionNames(names, env.GOOSE_PATH_ROOT ?
|
|
40184
|
+
addGooseExtensionNames(names, env.GOOSE_PATH_ROOT ? resolve31(env.GOOSE_PATH_ROOT, "config/config.yaml") : resolve31(home, ".config/goose/config.yaml"));
|
|
39948
40185
|
}
|
|
39949
40186
|
if (!kind || kind === "pi") {
|
|
39950
|
-
addClaudeMcpNames(names,
|
|
40187
|
+
addClaudeMcpNames(names, resolve31(env.PI_CODING_AGENT_DIR ?? resolve31(home, ".pi/agent"), PI_MCP_CONFIG.target));
|
|
39951
40188
|
}
|
|
39952
40189
|
} else {
|
|
39953
40190
|
collectImportedMcpNames(input.operatorHome ?? homedir14(), names, input.agentKind);
|
|
@@ -39967,17 +40204,17 @@ function hostImportedMcpDeclarations(input = {}) {
|
|
|
39967
40204
|
}
|
|
39968
40205
|
};
|
|
39969
40206
|
if (!kind || kind === "codex")
|
|
39970
|
-
add(readTomlMcpServers(
|
|
40207
|
+
add(readTomlMcpServers(resolve31(operatorHome, ".codex/config.toml")));
|
|
39971
40208
|
if (!kind || kind === "grok")
|
|
39972
|
-
add(readTomlMcpServers(
|
|
40209
|
+
add(readTomlMcpServers(resolve31(operatorHome, ".grok/config.toml")));
|
|
39973
40210
|
if (!kind || kind === "claude") {
|
|
39974
|
-
add(recordValue2(readJsonObject2(
|
|
40211
|
+
add(recordValue2(readJsonObject2(resolve31(operatorHome, ".claude.json"))?.mcpServers));
|
|
39975
40212
|
}
|
|
39976
40213
|
if (!kind || kind === "goose") {
|
|
39977
|
-
add(readGooseExtensions(
|
|
40214
|
+
add(readGooseExtensions(resolve31(operatorHome, ".config/goose/config.yaml")));
|
|
39978
40215
|
}
|
|
39979
40216
|
if (!kind || kind === "pi") {
|
|
39980
|
-
add(recordValue2(readJsonObject2(
|
|
40217
|
+
add(recordValue2(readJsonObject2(resolve31(operatorHome, PI_MCP_CONFIG.source))?.mcpServers));
|
|
39981
40218
|
}
|
|
39982
40219
|
return declarations;
|
|
39983
40220
|
}
|
|
@@ -40009,19 +40246,19 @@ function expectedMountedImportedMcpServerNames(input) {
|
|
|
40009
40246
|
}
|
|
40010
40247
|
function collectImportedMcpNames(operatorHome, names, kind) {
|
|
40011
40248
|
if (!kind || kind === "codex") {
|
|
40012
|
-
addLocalMcpNames(names, readTomlMcpServers(
|
|
40249
|
+
addLocalMcpNames(names, readTomlMcpServers(resolve31(operatorHome, ".codex/config.toml")));
|
|
40013
40250
|
}
|
|
40014
40251
|
if (!kind || kind === "grok") {
|
|
40015
|
-
addLocalMcpNames(names, readTomlMcpServers(
|
|
40252
|
+
addLocalMcpNames(names, readTomlMcpServers(resolve31(operatorHome, ".grok/config.toml")));
|
|
40016
40253
|
}
|
|
40017
40254
|
if (!kind || kind === "claude") {
|
|
40018
|
-
addLocalMcpNames(names, recordValue2(readJsonObject2(
|
|
40255
|
+
addLocalMcpNames(names, recordValue2(readJsonObject2(resolve31(operatorHome, ".claude.json"))?.mcpServers));
|
|
40019
40256
|
}
|
|
40020
40257
|
if (!kind || kind === "goose") {
|
|
40021
|
-
addLocalMcpNames(names, readGooseExtensions(
|
|
40258
|
+
addLocalMcpNames(names, readGooseExtensions(resolve31(operatorHome, ".config/goose/config.yaml")));
|
|
40022
40259
|
}
|
|
40023
40260
|
if (!kind || kind === "pi") {
|
|
40024
|
-
addLocalMcpNames(names, recordValue2(readJsonObject2(
|
|
40261
|
+
addLocalMcpNames(names, recordValue2(readJsonObject2(resolve31(operatorHome, PI_MCP_CONFIG.source))?.mcpServers));
|
|
40025
40262
|
}
|
|
40026
40263
|
}
|
|
40027
40264
|
function addLocalMcpNames(names, servers) {
|
|
@@ -40093,19 +40330,19 @@ async function provisionManagedSkillsDir(target, managedSkills, sharedSkills, op
|
|
|
40093
40330
|
const plan = await planManagedSkills(managedSkills, sharedSkills, optionalShares);
|
|
40094
40331
|
if (await materializedSkillManifest(target) === plan.manifest)
|
|
40095
40332
|
return;
|
|
40096
|
-
const staged =
|
|
40333
|
+
const staged = resolve31(parent, `.skills.${process.pid}.${randomUUID13()}.tmp`);
|
|
40097
40334
|
await mkdir19(staged, { mode: 448 });
|
|
40098
40335
|
try {
|
|
40099
40336
|
for (const entry of plan.entries) {
|
|
40100
40337
|
if (entry.kind === "managed") {
|
|
40101
|
-
const skillDir =
|
|
40338
|
+
const skillDir = resolve31(staged, entry.name);
|
|
40102
40339
|
await mkdir19(skillDir, { recursive: true });
|
|
40103
|
-
await writeIsolatedHarnessFile(
|
|
40340
|
+
await writeIsolatedHarnessFile(resolve31(skillDir, "SKILL.md"), entry.content);
|
|
40104
40341
|
} else {
|
|
40105
|
-
await copySafeSkillTree(entry.source,
|
|
40342
|
+
await copySafeSkillTree(entry.source, resolve31(staged, entry.name), entry.source);
|
|
40106
40343
|
}
|
|
40107
40344
|
}
|
|
40108
|
-
const existing = await
|
|
40345
|
+
const existing = await lstat6(target).catch(() => void 0);
|
|
40109
40346
|
if (existing)
|
|
40110
40347
|
await rm14(target, { recursive: existing.isDirectory(), force: true });
|
|
40111
40348
|
await rename10(staged, target);
|
|
@@ -40130,7 +40367,7 @@ async function planManagedSkills(managedSkills, sharedSkills, optionalShares) {
|
|
|
40130
40367
|
const tree = [];
|
|
40131
40368
|
await walkSafeSkillTree(shared.source, shared.source, {
|
|
40132
40369
|
directory: async (rel) => void tree.push(`d ${join15(shared.name, rel)}`),
|
|
40133
|
-
file: async (rel, realPath) => void tree.push(`f ${join15(shared.name, rel)} ${sha2563(await
|
|
40370
|
+
file: async (rel, realPath) => void tree.push(`f ${join15(shared.name, rel)} ${sha2563(await readFile27(realPath))}`)
|
|
40134
40371
|
});
|
|
40135
40372
|
entries.push({ kind: "shared", name: shared.name, source: shared.source });
|
|
40136
40373
|
lines.push(...tree);
|
|
@@ -40143,15 +40380,15 @@ async function planManagedSkills(managedSkills, sharedSkills, optionalShares) {
|
|
|
40143
40380
|
return { entries, manifest: lines.sort().join("\n") };
|
|
40144
40381
|
}
|
|
40145
40382
|
async function materializedSkillManifest(target) {
|
|
40146
|
-
const stats = await
|
|
40383
|
+
const stats = await lstat6(target).catch(() => void 0);
|
|
40147
40384
|
if (!stats?.isDirectory() || stats.isSymbolicLink())
|
|
40148
40385
|
return void 0;
|
|
40149
40386
|
const lines = [];
|
|
40150
40387
|
const visit = async (directory, prefix) => {
|
|
40151
|
-
for (const entry of await
|
|
40152
|
-
const path =
|
|
40388
|
+
for (const entry of await readdir9(directory)) {
|
|
40389
|
+
const path = resolve31(directory, entry);
|
|
40153
40390
|
const rel = prefix ? join15(prefix, entry) : entry;
|
|
40154
|
-
const entryStats = await
|
|
40391
|
+
const entryStats = await lstat6(path);
|
|
40155
40392
|
if (entryStats.isSymbolicLink())
|
|
40156
40393
|
return false;
|
|
40157
40394
|
if (entryStats.isDirectory()) {
|
|
@@ -40162,7 +40399,7 @@ async function materializedSkillManifest(target) {
|
|
|
40162
40399
|
}
|
|
40163
40400
|
if (!entryStats.isFile() || entryStats.nlink !== 1)
|
|
40164
40401
|
return false;
|
|
40165
|
-
lines.push(`f ${rel} ${sha2563(await
|
|
40402
|
+
lines.push(`f ${rel} ${sha2563(await readFile27(path))}`);
|
|
40166
40403
|
}
|
|
40167
40404
|
return true;
|
|
40168
40405
|
};
|
|
@@ -40184,16 +40421,16 @@ async function resolveSharedSkillSources(operatorHome, names) {
|
|
|
40184
40421
|
const resolved = [];
|
|
40185
40422
|
const skipped = [];
|
|
40186
40423
|
for (const relativeRoot of OPERATOR_SKILL_SOURCE_DIRS) {
|
|
40187
|
-
const sourceRoot =
|
|
40188
|
-
const rootStats = await
|
|
40424
|
+
const sourceRoot = resolve31(operatorHome, relativeRoot);
|
|
40425
|
+
const rootStats = await lstat6(sourceRoot).catch(() => void 0);
|
|
40189
40426
|
if (!rootStats?.isDirectory() || rootStats.isSymbolicLink())
|
|
40190
40427
|
continue;
|
|
40191
|
-
for (const entry of await
|
|
40428
|
+
for (const entry of await readdir9(sourceRoot)) {
|
|
40192
40429
|
if (!isSharedSkillName(entry) || seen.has(entry))
|
|
40193
40430
|
continue;
|
|
40194
|
-
const candidate =
|
|
40431
|
+
const candidate = resolve31(sourceRoot, entry);
|
|
40195
40432
|
try {
|
|
40196
|
-
const candidateStats = await
|
|
40433
|
+
const candidateStats = await lstat6(candidate);
|
|
40197
40434
|
if (candidateStats.isSymbolicLink()) {
|
|
40198
40435
|
const reason = await realpath2(candidate).then(() => "symlinked directory", (error) => isMissingPathError(error) ? "dangling symlink" : "symlinked directory");
|
|
40199
40436
|
skipped.push({
|
|
@@ -40207,8 +40444,8 @@ async function resolveSharedSkillSources(operatorHome, names) {
|
|
|
40207
40444
|
continue;
|
|
40208
40445
|
}
|
|
40209
40446
|
assertContained(sourceRoot, candidate);
|
|
40210
|
-
const skillMd =
|
|
40211
|
-
const skillStats = await
|
|
40447
|
+
const skillMd = resolve31(candidate, "SKILL.md");
|
|
40448
|
+
const skillStats = await lstat6(skillMd).catch((error) => {
|
|
40212
40449
|
if (isMissingPathError(error)) {
|
|
40213
40450
|
skipped.push({ path: candidate, reason: "missing SKILL.md" });
|
|
40214
40451
|
return void 0;
|
|
@@ -40259,10 +40496,10 @@ async function resolveExplicitSkillSources(operatorHome, names) {
|
|
|
40259
40496
|
for (const name of unique) {
|
|
40260
40497
|
const matches = [];
|
|
40261
40498
|
for (const relativeRoot of OPERATOR_SKILL_SOURCE_DIRS) {
|
|
40262
|
-
const sourceRoot =
|
|
40263
|
-
const candidate =
|
|
40264
|
-
const rootStats = await
|
|
40265
|
-
const candidateStats = await
|
|
40499
|
+
const sourceRoot = resolve31(operatorHome, relativeRoot);
|
|
40500
|
+
const candidate = resolve31(sourceRoot, name);
|
|
40501
|
+
const rootStats = await lstat6(sourceRoot).catch(() => void 0);
|
|
40502
|
+
const candidateStats = await lstat6(candidate).catch(() => void 0);
|
|
40266
40503
|
if (!candidateStats)
|
|
40267
40504
|
continue;
|
|
40268
40505
|
if (!rootStats?.isDirectory() || rootStats.isSymbolicLink()) {
|
|
@@ -40277,8 +40514,8 @@ async function resolveExplicitSkillSources(operatorHome, names) {
|
|
|
40277
40514
|
if (matches.length !== 1) {
|
|
40278
40515
|
throw new Error(matches.length === 0 ? `shared skill is unavailable: ${name}` : `shared skill source is ambiguous: ${name}`);
|
|
40279
40516
|
}
|
|
40280
|
-
const skillMd =
|
|
40281
|
-
const skillStats = await
|
|
40517
|
+
const skillMd = resolve31(matches[0], "SKILL.md");
|
|
40518
|
+
const skillStats = await lstat6(skillMd).catch(() => void 0);
|
|
40282
40519
|
if (!skillStats?.isFile() || skillStats.isSymbolicLink() || skillStats.nlink !== 1) {
|
|
40283
40520
|
throw new Error(`shared skill requires an ordinary SKILL.md: ${name}`);
|
|
40284
40521
|
}
|
|
@@ -40288,13 +40525,13 @@ async function resolveExplicitSkillSources(operatorHome, names) {
|
|
|
40288
40525
|
}
|
|
40289
40526
|
function assertContained(root, candidate) {
|
|
40290
40527
|
const rel = relative2(root, candidate);
|
|
40291
|
-
if (rel === ".." || rel.startsWith(`..${sep2}`) ||
|
|
40528
|
+
if (rel === ".." || rel.startsWith(`..${sep2}`) || resolve31(root, rel) !== resolve31(candidate)) {
|
|
40292
40529
|
throw new Error(`path escapes the agent skill boundary: ${candidate}`);
|
|
40293
40530
|
}
|
|
40294
40531
|
}
|
|
40295
40532
|
async function assertRealContainedDirectory(path, root) {
|
|
40296
40533
|
assertContained(root, path);
|
|
40297
|
-
const stats = await
|
|
40534
|
+
const stats = await lstat6(path);
|
|
40298
40535
|
if (!stats.isDirectory() || stats.isSymbolicLink()) {
|
|
40299
40536
|
throw new AgentHomeSecurityError(`agent skill destination is not an ordinary directory: ${path}`);
|
|
40300
40537
|
}
|
|
@@ -40303,11 +40540,11 @@ var BLOCKED_SHARED_FILENAMES = /^(?:\.env(?:\..*)?|auth\.json|\.credentials\.jso
|
|
|
40303
40540
|
async function walkSafeSkillTree(source, sourceRoot, visitor, rel = "") {
|
|
40304
40541
|
assertContained(sourceRoot, source);
|
|
40305
40542
|
const resolvedSource = await realpath2(source);
|
|
40306
|
-
if (resolvedSource !==
|
|
40543
|
+
if (resolvedSource !== resolve31(source)) {
|
|
40307
40544
|
throw new Error(`shared skill path resolves through a link: ${source}`);
|
|
40308
40545
|
}
|
|
40309
40546
|
assertContained(sourceRoot, resolvedSource);
|
|
40310
|
-
const stats = await
|
|
40547
|
+
const stats = await lstat6(resolvedSource);
|
|
40311
40548
|
if (stats.isSymbolicLink())
|
|
40312
40549
|
throw new Error(`shared skill contains a symlink: ${source}`);
|
|
40313
40550
|
if (BLOCKED_SHARED_FILENAMES.test(basename8(source))) {
|
|
@@ -40315,10 +40552,10 @@ async function walkSafeSkillTree(source, sourceRoot, visitor, rel = "") {
|
|
|
40315
40552
|
}
|
|
40316
40553
|
if (stats.isDirectory()) {
|
|
40317
40554
|
await visitor.directory(rel);
|
|
40318
|
-
for (const entry of await
|
|
40555
|
+
for (const entry of await readdir9(resolvedSource)) {
|
|
40319
40556
|
if (entry === "." || entry === "..")
|
|
40320
40557
|
throw new Error("invalid shared skill entry");
|
|
40321
|
-
await walkSafeSkillTree(
|
|
40558
|
+
await walkSafeSkillTree(resolve31(source, entry), sourceRoot, visitor, rel ? join15(rel, entry) : entry);
|
|
40322
40559
|
}
|
|
40323
40560
|
return;
|
|
40324
40561
|
}
|
|
@@ -40330,10 +40567,10 @@ async function walkSafeSkillTree(source, sourceRoot, visitor, rel = "") {
|
|
|
40330
40567
|
async function copySafeSkillTree(source, target, sourceRoot) {
|
|
40331
40568
|
await walkSafeSkillTree(source, sourceRoot, {
|
|
40332
40569
|
directory: async (rel) => {
|
|
40333
|
-
await mkdir19(
|
|
40570
|
+
await mkdir19(resolve31(target, rel), { mode: 448 });
|
|
40334
40571
|
},
|
|
40335
40572
|
file: async (rel, realPath) => {
|
|
40336
|
-
const destination =
|
|
40573
|
+
const destination = resolve31(target, rel);
|
|
40337
40574
|
await copyFile(realPath, destination);
|
|
40338
40575
|
await chmod8(destination, 384);
|
|
40339
40576
|
}
|
|
@@ -40341,11 +40578,11 @@ async function copySafeSkillTree(source, target, sourceRoot) {
|
|
|
40341
40578
|
}
|
|
40342
40579
|
async function writeIsolatedHarnessFile(path, content) {
|
|
40343
40580
|
const parent = dirname22(path);
|
|
40344
|
-
const parentStats = await
|
|
40581
|
+
const parentStats = await lstat6(parent);
|
|
40345
40582
|
if (!parentStats.isDirectory() || parentStats.isSymbolicLink()) {
|
|
40346
40583
|
throw new Error(`isolated harness parent is not a real directory: ${parent}`);
|
|
40347
40584
|
}
|
|
40348
|
-
const temporary =
|
|
40585
|
+
const temporary = resolve31(parent, `.${basename8(path)}.${process.pid}.${randomUUID13()}.tmp`);
|
|
40349
40586
|
try {
|
|
40350
40587
|
await writeFile17(temporary, content, { mode: 384, flag: "wx" });
|
|
40351
40588
|
await chmod8(temporary, 384);
|
|
@@ -40355,24 +40592,24 @@ async function writeIsolatedHarnessFile(path, content) {
|
|
|
40355
40592
|
}
|
|
40356
40593
|
}
|
|
40357
40594
|
function roomSessionTmpDir(root, base = "/tmp") {
|
|
40358
|
-
const hash = createHash13("sha256").update(
|
|
40595
|
+
const hash = createHash13("sha256").update(resolve31(root)).digest("hex").slice(0, 12);
|
|
40359
40596
|
return join15(base, `beeline-${hash}`);
|
|
40360
40597
|
}
|
|
40361
40598
|
function roomAgentHomeEnv(root) {
|
|
40362
|
-
const resolved =
|
|
40599
|
+
const resolved = resolve31(root);
|
|
40363
40600
|
return {
|
|
40364
|
-
HOME:
|
|
40365
|
-
CLAUDE_CONFIG_DIR:
|
|
40366
|
-
CODEX_HOME:
|
|
40367
|
-
GOOSE_PATH_ROOT:
|
|
40368
|
-
GROK_HOME:
|
|
40369
|
-
CURSOR_HOME:
|
|
40370
|
-
OPENCODE_CONFIG_DIR:
|
|
40371
|
-
PI_CODING_AGENT_DIR:
|
|
40372
|
-
XDG_CONFIG_HOME:
|
|
40373
|
-
XDG_DATA_HOME:
|
|
40374
|
-
XDG_STATE_HOME:
|
|
40375
|
-
XDG_CACHE_HOME:
|
|
40601
|
+
HOME: resolve31(resolved, "user"),
|
|
40602
|
+
CLAUDE_CONFIG_DIR: resolve31(resolved, "claude"),
|
|
40603
|
+
CODEX_HOME: resolve31(resolved, "codex"),
|
|
40604
|
+
GOOSE_PATH_ROOT: resolve31(resolved, "goose"),
|
|
40605
|
+
GROK_HOME: resolve31(resolved, "grok"),
|
|
40606
|
+
CURSOR_HOME: resolve31(resolved, "cursor"),
|
|
40607
|
+
OPENCODE_CONFIG_DIR: resolve31(resolved, "opencode"),
|
|
40608
|
+
PI_CODING_AGENT_DIR: resolve31(resolved, "pi"),
|
|
40609
|
+
XDG_CONFIG_HOME: resolve31(resolved, "user/.config"),
|
|
40610
|
+
XDG_DATA_HOME: resolve31(resolved, "user/.local/share"),
|
|
40611
|
+
XDG_STATE_HOME: resolve31(resolved, "state"),
|
|
40612
|
+
XDG_CACHE_HOME: resolve31(resolved, "cache"),
|
|
40376
40613
|
TMPDIR: roomSessionTmpDir(resolved)
|
|
40377
40614
|
};
|
|
40378
40615
|
}
|
|
@@ -40395,10 +40632,10 @@ function harnessStateDirsFromEnv(env) {
|
|
|
40395
40632
|
for (const name of HARNESS_STATE_ENV_VARS) {
|
|
40396
40633
|
const value = env[name];
|
|
40397
40634
|
if (value)
|
|
40398
|
-
stateDirs.push(
|
|
40635
|
+
stateDirs.push(resolve31(value));
|
|
40399
40636
|
}
|
|
40400
40637
|
const tmp = env.TMPDIR;
|
|
40401
|
-
return { stateDirs, ...tmp ? { tmpDir:
|
|
40638
|
+
return { stateDirs, ...tmp ? { tmpDir: resolve31(tmp) } : {} };
|
|
40402
40639
|
}
|
|
40403
40640
|
|
|
40404
40641
|
// apps/body/dist/agent-command-catalog.js
|
|
@@ -41038,12 +41275,12 @@ function mountedMcpSet(servers) {
|
|
|
41038
41275
|
}
|
|
41039
41276
|
|
|
41040
41277
|
// apps/body/dist/corner-prepare-script.js
|
|
41041
|
-
import { readFile as
|
|
41042
|
-
import { resolve as
|
|
41278
|
+
import { readFile as readFile28 } from "node:fs/promises";
|
|
41279
|
+
import { resolve as resolve32 } from "node:path";
|
|
41043
41280
|
var CORNER_PREPARE_SCRIPT = "corner:prepare";
|
|
41044
41281
|
async function hasCornerPrepareScript(worktreePath) {
|
|
41045
41282
|
try {
|
|
41046
|
-
const parsed = JSON.parse(await
|
|
41283
|
+
const parsed = JSON.parse(await readFile28(resolve32(worktreePath, "package.json"), "utf8"));
|
|
41047
41284
|
return typeof parsed.scripts?.[CORNER_PREPARE_SCRIPT] === "string";
|
|
41048
41285
|
} catch {
|
|
41049
41286
|
return false;
|
|
@@ -41052,9 +41289,9 @@ async function hasCornerPrepareScript(worktreePath) {
|
|
|
41052
41289
|
|
|
41053
41290
|
// apps/body/dist/pi-mcp-bridge.js
|
|
41054
41291
|
import { execFile as execFile13 } from "node:child_process";
|
|
41055
|
-
import { mkdtemp as mkdtemp2, mkdir as mkdir21, readFile as
|
|
41292
|
+
import { mkdtemp as mkdtemp2, mkdir as mkdir21, readFile as readFile29, rm as rm15, unlink as unlink7 } from "node:fs/promises";
|
|
41056
41293
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
41057
|
-
import { resolve as
|
|
41294
|
+
import { resolve as resolve33 } from "node:path";
|
|
41058
41295
|
import { promisify as promisify8 } from "node:util";
|
|
41059
41296
|
var PI_MCP_BRIDGE_FILENAME = "beeline-mcp-bridge.js";
|
|
41060
41297
|
var execFileAsync8 = promisify8(execFile13);
|
|
@@ -41065,7 +41302,7 @@ async function piHasNativeMcp(command, env) {
|
|
|
41065
41302
|
let probe = nativeMcpProbes.get(cacheKey);
|
|
41066
41303
|
if (!probe) {
|
|
41067
41304
|
probe = (async () => {
|
|
41068
|
-
const home = await mkdtemp2(
|
|
41305
|
+
const home = await mkdtemp2(resolve33(tmpdir5(), "beeline-pi-mcp-probe-"));
|
|
41069
41306
|
try {
|
|
41070
41307
|
const { stdout: stdout6 } = await execFileAsync8(command, ["mcp", "list", "--json"], {
|
|
41071
41308
|
cwd: home,
|
|
@@ -41086,7 +41323,7 @@ async function piHasNativeMcp(command, env) {
|
|
|
41086
41323
|
}
|
|
41087
41324
|
async function isolatedPiConfig(piHome) {
|
|
41088
41325
|
try {
|
|
41089
|
-
const parsed = JSON.parse(await
|
|
41326
|
+
const parsed = JSON.parse(await readFile29(resolve33(piHome, "mcp.json"), "utf8"));
|
|
41090
41327
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
41091
41328
|
} catch (error) {
|
|
41092
41329
|
if (error.code !== "ENOENT")
|
|
@@ -41140,8 +41377,8 @@ async function installPiMcpBridge(input) {
|
|
|
41140
41377
|
return void 0;
|
|
41141
41378
|
if (!input.piHome)
|
|
41142
41379
|
return void 0;
|
|
41143
|
-
const directory =
|
|
41144
|
-
const path =
|
|
41380
|
+
const directory = resolve33(input.piHome, "extensions");
|
|
41381
|
+
const path = resolve33(directory, PI_MCP_BRIDGE_FILENAME);
|
|
41145
41382
|
try {
|
|
41146
41383
|
const config = await isolatedPiConfig(input.piHome);
|
|
41147
41384
|
const nativeMcp = input.nativeMcp ?? await piHasNativeMcp(input.piCommand ?? "pi", input.agentEnv);
|
|
@@ -41154,13 +41391,13 @@ async function installPiMcpBridge(input) {
|
|
|
41154
41391
|
env: Object.fromEntries((server.env ?? []).map((entry) => [entry.name, entry.value])),
|
|
41155
41392
|
exposure: "direct"
|
|
41156
41393
|
};
|
|
41157
|
-
await writeIsolatedHarnessFile(
|
|
41394
|
+
await writeIsolatedHarnessFile(resolve33(input.piHome, "mcp.json"), `${JSON.stringify({ ...config, mcpServers: mcpServers2 }, null, 2)}
|
|
41158
41395
|
`);
|
|
41159
41396
|
await unlink7(path).catch((error) => {
|
|
41160
41397
|
if (error.code !== "ENOENT")
|
|
41161
41398
|
throw error;
|
|
41162
41399
|
});
|
|
41163
|
-
return
|
|
41400
|
+
return resolve33(input.piHome, "mcp.json");
|
|
41164
41401
|
}
|
|
41165
41402
|
const servers = [...input.servers, ...importedStdioServers(config, input.servers)];
|
|
41166
41403
|
if (!servers.length)
|
|
@@ -41173,7 +41410,7 @@ async function installPiMcpBridge(input) {
|
|
|
41173
41410
|
env: Object.fromEntries((server.env ?? []).map((entry) => [entry.name, entry.value])),
|
|
41174
41411
|
enabled: false
|
|
41175
41412
|
};
|
|
41176
|
-
await writeIsolatedHarnessFile(
|
|
41413
|
+
await writeIsolatedHarnessFile(resolve33(input.piHome, "mcp.json"), `${JSON.stringify({ ...config, mcpServers }, null, 2)}
|
|
41177
41414
|
`);
|
|
41178
41415
|
await mkdir21(directory, { recursive: true, mode: 448 });
|
|
41179
41416
|
await writeIsolatedHarnessFile(path, piMcpBridgeSource(servers));
|
|
@@ -41365,8 +41602,8 @@ export default async function (pi) {
|
|
|
41365
41602
|
|
|
41366
41603
|
// apps/body/dist/corner-branch-sync.js
|
|
41367
41604
|
import { execFile as execFile14 } from "node:child_process";
|
|
41368
|
-
import { access as access2, readFile as
|
|
41369
|
-
import { resolve as
|
|
41605
|
+
import { access as access2, readFile as readFile30 } from "node:fs/promises";
|
|
41606
|
+
import { resolve as resolve34 } from "node:path";
|
|
41370
41607
|
var CORNER_GIT_SYNC_TIMEOUT_MS = 12e4;
|
|
41371
41608
|
var CORNER_GIT_SYNC_KILL_GRACE_MS = 1e3;
|
|
41372
41609
|
var CornerGitSyncInterruptedError = class extends Error {
|
|
@@ -41380,7 +41617,7 @@ async function syncCornerBranch(input) {
|
|
|
41380
41617
|
try {
|
|
41381
41618
|
if (signal.aborted)
|
|
41382
41619
|
throw interrupted();
|
|
41383
|
-
return await new Promise((
|
|
41620
|
+
return await new Promise((resolve53, reject) => {
|
|
41384
41621
|
let killTimer;
|
|
41385
41622
|
let stdout6 = "";
|
|
41386
41623
|
let failure = null;
|
|
@@ -41414,19 +41651,19 @@ async function syncCornerBranch(input) {
|
|
|
41414
41651
|
else if (failure)
|
|
41415
41652
|
reject(failure);
|
|
41416
41653
|
else
|
|
41417
|
-
|
|
41654
|
+
resolve53(stdout6);
|
|
41418
41655
|
});
|
|
41419
41656
|
else
|
|
41420
|
-
input.git(args).then(
|
|
41657
|
+
input.git(args).then(resolve53, reject).finally(cleanup2);
|
|
41421
41658
|
});
|
|
41422
41659
|
} finally {
|
|
41423
41660
|
clearTimeout(timer);
|
|
41424
41661
|
}
|
|
41425
41662
|
};
|
|
41426
|
-
const marker = await
|
|
41427
|
-
const gitDir =
|
|
41663
|
+
const marker = await readFile30(resolve34(input.worktreePath, ".git"), "utf8").catch(() => "");
|
|
41664
|
+
const gitDir = resolve34(input.worktreePath, marker.startsWith("gitdir: ") ? marker.slice(8).trim() : ".git");
|
|
41428
41665
|
for (const directory of ["rebase-merge", "rebase-apply"]) {
|
|
41429
|
-
if (await access2(
|
|
41666
|
+
if (await access2(resolve34(gitDir, directory)).then(() => true, () => false))
|
|
41430
41667
|
await git2(["rebase", "--abort"], true);
|
|
41431
41668
|
}
|
|
41432
41669
|
const remoteRef = `refs/remotes/origin/${input.featureBranch}`;
|
|
@@ -41474,7 +41711,7 @@ async function contains(git2, head, ancestor) {
|
|
|
41474
41711
|
}
|
|
41475
41712
|
|
|
41476
41713
|
// apps/body/dist/room-session.js
|
|
41477
|
-
import { resolve as
|
|
41714
|
+
import { resolve as resolve35 } from "node:path";
|
|
41478
41715
|
import { homedir as homedir15 } from "node:os";
|
|
41479
41716
|
|
|
41480
41717
|
// apps/body/dist/read-only-policy.js
|
|
@@ -41716,22 +41953,22 @@ function readOnlyMcpServer(config, cwd, agentMemoryDir) {
|
|
|
41716
41953
|
command: config.readonlyMcpCommand,
|
|
41717
41954
|
args: [...config.readonlyMcpArgs ?? []],
|
|
41718
41955
|
env: [
|
|
41719
|
-
{ name: "BEELINE_READONLY_ROOT", value:
|
|
41956
|
+
{ name: "BEELINE_READONLY_ROOT", value: resolve35(cwd) },
|
|
41720
41957
|
...config.agentHomeRoot ? [
|
|
41721
41958
|
{
|
|
41722
41959
|
name: "BEELINE_READONLY_AGENT_SKILLS_ROOT",
|
|
41723
|
-
value:
|
|
41960
|
+
value: resolve35(config.agentHomeRoot, skillDir, "skills")
|
|
41724
41961
|
}
|
|
41725
41962
|
] : [],
|
|
41726
|
-
...agentMemoryDir ? [{ name: "BEELINE_READONLY_AGENT_MEMORY_ROOT", value:
|
|
41963
|
+
...agentMemoryDir ? [{ name: "BEELINE_READONLY_AGENT_MEMORY_ROOT", value: resolve35(agentMemoryDir) }] : []
|
|
41727
41964
|
]
|
|
41728
41965
|
};
|
|
41729
41966
|
}
|
|
41730
41967
|
|
|
41731
41968
|
// apps/body/dist/scratch-lifecycle.js
|
|
41732
41969
|
import { execFile as execFile15 } from "node:child_process";
|
|
41733
|
-
import { lstat as
|
|
41734
|
-
import { join as join17, resolve as
|
|
41970
|
+
import { lstat as lstat7, readdir as readdir10, rmdir as rmdir2, rm as rm16, stat as stat10, unlink as unlink8 } from "node:fs/promises";
|
|
41971
|
+
import { join as join17, resolve as resolve36 } from "node:path";
|
|
41735
41972
|
import { promisify as promisify9 } from "node:util";
|
|
41736
41973
|
var execFileAsync9 = promisify9(execFile15);
|
|
41737
41974
|
var CORNER_SCRATCH_BUDGET_BYTES = 5 * 1024 ** 3;
|
|
@@ -41739,7 +41976,7 @@ var CORNER_SCRATCH_TTL_MS = 14 * 24 * 60 * 6e4;
|
|
|
41739
41976
|
var SHARED_MODEL_CACHE_BUDGET_BYTES = 32 * 1024 ** 3;
|
|
41740
41977
|
var MODEL_CACHE_IDLE_MS = 24 * 60 * 6e4;
|
|
41741
41978
|
async function allocatedDirectoryBytes(path) {
|
|
41742
|
-
if (!await
|
|
41979
|
+
if (!await lstat7(path).catch(() => void 0))
|
|
41743
41980
|
return 0;
|
|
41744
41981
|
const output = await execFileAsync9("du", ["-s", "-B1", "--", path], {
|
|
41745
41982
|
maxBuffer: 1024 * 1024
|
|
@@ -41761,11 +41998,11 @@ async function sweepStaleCornerScratch(root, now2 = Date.now(), ttlMs = CORNER_S
|
|
|
41761
41998
|
let files = 0;
|
|
41762
41999
|
let bytes = 0;
|
|
41763
42000
|
const visit = async (dir, top) => {
|
|
41764
|
-
for (const entry of await
|
|
42001
|
+
for (const entry of await readdir10(dir, { withFileTypes: true }).catch(() => [])) {
|
|
41765
42002
|
if (top && (entry.name === "agent-home" || entry.name === "agent-private" || entry.name === ".git"))
|
|
41766
42003
|
continue;
|
|
41767
42004
|
const path = join17(dir, entry.name);
|
|
41768
|
-
const info = await
|
|
42005
|
+
const info = await lstat7(path).catch(() => void 0);
|
|
41769
42006
|
if (!info || info.isSymbolicLink())
|
|
41770
42007
|
continue;
|
|
41771
42008
|
if (info.isDirectory()) {
|
|
@@ -41779,8 +42016,8 @@ async function sweepStaleCornerScratch(root, now2 = Date.now(), ttlMs = CORNER_S
|
|
|
41779
42016
|
}
|
|
41780
42017
|
}
|
|
41781
42018
|
};
|
|
41782
|
-
if ((await
|
|
41783
|
-
await visit(
|
|
42019
|
+
if ((await lstat7(root).catch(() => void 0))?.isDirectory())
|
|
42020
|
+
await visit(resolve36(root), true);
|
|
41784
42021
|
return { files, bytes };
|
|
41785
42022
|
}
|
|
41786
42023
|
async function pruneSharedModelCache(root, now2 = Date.now(), budget = SHARED_MODEL_CACHE_BUDGET_BYTES) {
|
|
@@ -41789,7 +42026,7 @@ async function pruneSharedModelCache(root, now2 = Date.now(), budget = SHARED_MO
|
|
|
41789
42026
|
return [];
|
|
41790
42027
|
const candidates = [];
|
|
41791
42028
|
for (const parent of [join17(root, "hub"), root]) {
|
|
41792
|
-
for (const entry of await
|
|
42029
|
+
for (const entry of await readdir10(parent, { withFileTypes: true }).catch(() => [])) {
|
|
41793
42030
|
const eligible = parent === root ? entry.name === "xet" : /^(?:models|datasets|spaces)--/.test(entry.name);
|
|
41794
42031
|
if (!eligible || !entry.isDirectory())
|
|
41795
42032
|
continue;
|
|
@@ -41861,15 +42098,15 @@ async function awaitInstitutionalContext(fetch2, log2 = console.warn, budgetMs =
|
|
|
41861
42098
|
|
|
41862
42099
|
// apps/body/dist/codegraph.js
|
|
41863
42100
|
import { execFile as execFile16 } from "node:child_process";
|
|
41864
|
-
import { access as access3, appendFile, mkdir as mkdir22, readFile as
|
|
41865
|
-
import { dirname as dirname23, isAbsolute as isAbsolute4, resolve as
|
|
42101
|
+
import { access as access3, appendFile, mkdir as mkdir22, readFile as readFile31 } from "node:fs/promises";
|
|
42102
|
+
import { dirname as dirname23, isAbsolute as isAbsolute4, resolve as resolve37 } from "node:path";
|
|
41866
42103
|
import { promisify as promisify10 } from "node:util";
|
|
41867
42104
|
var execFileAsync10 = promisify10(execFile16);
|
|
41868
42105
|
var CODEGRAPH_MCP_SERVER_NAME = "codegraph";
|
|
41869
42106
|
var CODEGRAPH_INDEX_PATH = ".codegraph/codegraph.db";
|
|
41870
42107
|
var CODEGRAPH_PREPARE_TIMEOUT_MS = 12e4;
|
|
41871
42108
|
function codegraphIndexDirectory(cwd) {
|
|
41872
|
-
return
|
|
42109
|
+
return resolve37(cwd, dirname23(CODEGRAPH_INDEX_PATH));
|
|
41873
42110
|
}
|
|
41874
42111
|
function codegraphMcpServer(config, cwd, options) {
|
|
41875
42112
|
if (!config.codegraphCommand)
|
|
@@ -41877,7 +42114,7 @@ function codegraphMcpServer(config, cwd, options) {
|
|
|
41877
42114
|
return {
|
|
41878
42115
|
name: CODEGRAPH_MCP_SERVER_NAME,
|
|
41879
42116
|
command: config.codegraphCommand,
|
|
41880
|
-
args: ["serve", "--mcp", "--path",
|
|
42117
|
+
args: ["serve", "--mcp", "--path", resolve37(cwd), ...options.readonly ? ["--no-watch"] : []],
|
|
41881
42118
|
env: [
|
|
41882
42119
|
{ name: "CODEGRAPH_TELEMETRY", value: "0" },
|
|
41883
42120
|
// One MCP child per harness session is easier to contain than a daemon
|
|
@@ -41895,7 +42132,7 @@ async function isGitWorktree(cwd) {
|
|
|
41895
42132
|
cwd,
|
|
41896
42133
|
timeout: 1e4
|
|
41897
42134
|
});
|
|
41898
|
-
return
|
|
42135
|
+
return resolve37(stdout6.trim()) === resolve37(cwd);
|
|
41899
42136
|
} catch {
|
|
41900
42137
|
return false;
|
|
41901
42138
|
}
|
|
@@ -41909,9 +42146,9 @@ async function excludeIndexFromGitStatus(cwd) {
|
|
|
41909
42146
|
const gitPath = stdout6.trim();
|
|
41910
42147
|
if (!gitPath)
|
|
41911
42148
|
return;
|
|
41912
|
-
const path = isAbsolute4(gitPath) ? gitPath :
|
|
42149
|
+
const path = isAbsolute4(gitPath) ? gitPath : resolve37(cwd, gitPath);
|
|
41913
42150
|
await mkdir22(dirname23(path), { recursive: true });
|
|
41914
|
-
const existing = await
|
|
42151
|
+
const existing = await readFile31(path, "utf8").catch(() => "");
|
|
41915
42152
|
if (existing.split("\n").includes(".codegraph/"))
|
|
41916
42153
|
return;
|
|
41917
42154
|
await appendFile(path, `${existing && !existing.endsWith("\n") ? "\n" : ""}.codegraph/
|
|
@@ -41924,7 +42161,7 @@ async function prepareCodegraphIndex(config, cwd) {
|
|
|
41924
42161
|
if (!command || !await isGitWorktree(cwd))
|
|
41925
42162
|
return false;
|
|
41926
42163
|
await excludeIndexFromGitStatus(cwd);
|
|
41927
|
-
const indexPath =
|
|
42164
|
+
const indexPath = resolve37(cwd, CODEGRAPH_INDEX_PATH);
|
|
41928
42165
|
const indexed = await access3(indexPath).then(() => true, () => false);
|
|
41929
42166
|
const args = indexed ? ["sync", "--quiet", cwd] : ["init", "--yes", cwd];
|
|
41930
42167
|
try {
|
|
@@ -42744,8 +42981,8 @@ function assembleTurnPrompt(context) {
|
|
|
42744
42981
|
}
|
|
42745
42982
|
|
|
42746
42983
|
// apps/body/dist/turn-trace.js
|
|
42747
|
-
import { appendFile as appendFile2, mkdir as mkdir23, readdir as
|
|
42748
|
-
import { resolve as
|
|
42984
|
+
import { appendFile as appendFile2, mkdir as mkdir23, readdir as readdir11, rm as rm17 } from "node:fs/promises";
|
|
42985
|
+
import { resolve as resolve38 } from "node:path";
|
|
42749
42986
|
import { performance as performance3 } from "node:perf_hooks";
|
|
42750
42987
|
var TURN_PHASES = [
|
|
42751
42988
|
/** Enqueued on `SessionScheduler` until this turn holds a slot. A capacity wait lives here. */
|
|
@@ -43034,7 +43271,7 @@ function formatTurnTraceLine(record5) {
|
|
|
43034
43271
|
return [head, ...record5.attempts.map((attempt) => formatTurnAttempt(attempt))].join("\n ");
|
|
43035
43272
|
}
|
|
43036
43273
|
function turnTraceDirectory(runtimeDir) {
|
|
43037
|
-
return
|
|
43274
|
+
return resolve38(runtimeDir, "turn-traces");
|
|
43038
43275
|
}
|
|
43039
43276
|
var TURN_TRACE_RETENTION_DAYS = 7;
|
|
43040
43277
|
function traceFileName(date) {
|
|
@@ -43051,7 +43288,7 @@ var TurnTraceFile = class {
|
|
|
43051
43288
|
this.options = options;
|
|
43052
43289
|
}
|
|
43053
43290
|
path(now2 = (this.options.clock ?? (() => /* @__PURE__ */ new Date()))()) {
|
|
43054
|
-
return
|
|
43291
|
+
return resolve38(this.directory, traceFileName(now2));
|
|
43055
43292
|
}
|
|
43056
43293
|
write(record5) {
|
|
43057
43294
|
this.tail = this.tail.catch(() => void 0).then(async () => {
|
|
@@ -43074,8 +43311,8 @@ var TurnTraceFile = class {
|
|
|
43074
43311
|
return;
|
|
43075
43312
|
this.prunedDay = day;
|
|
43076
43313
|
const cutoff = traceFileName(new Date(now2.getTime() - TURN_TRACE_RETENTION_DAYS * 864e5));
|
|
43077
|
-
const names = await
|
|
43078
|
-
await Promise.all(names.filter((name) => /^turns-\d{4}-\d{2}-\d{2}\.jsonl$/.test(name) && name < cutoff).map((name) => rm17(
|
|
43314
|
+
const names = await readdir11(this.directory).catch(() => []);
|
|
43315
|
+
await Promise.all(names.filter((name) => /^turns-\d{4}-\d{2}-\d{2}\.jsonl$/.test(name) && name < cutoff).map((name) => rm17(resolve38(this.directory, name), { force: true })));
|
|
43079
43316
|
}
|
|
43080
43317
|
};
|
|
43081
43318
|
|
|
@@ -44099,8 +44336,8 @@ var MonolithRoomTurnLoop = class {
|
|
|
44099
44336
|
let timer;
|
|
44100
44337
|
const stats = statsPromise && remaining > 0 ? await Promise.race([
|
|
44101
44338
|
statsPromise,
|
|
44102
|
-
new Promise((
|
|
44103
|
-
timer = setTimeout(() =>
|
|
44339
|
+
new Promise((resolve53) => {
|
|
44340
|
+
timer = setTimeout(() => resolve53(void 0), remaining);
|
|
44104
44341
|
})
|
|
44105
44342
|
]).finally(() => {
|
|
44106
44343
|
if (timer)
|
|
@@ -44517,9 +44754,9 @@ function roomMessagePrompt(author, body, attachments, delivered, harnessAcceptsI
|
|
|
44517
44754
|
|
|
44518
44755
|
// apps/body/dist/corner-github-auth.js
|
|
44519
44756
|
import { chmod as chmod9, mkdir as mkdir25, writeFile as writeFile20 } from "node:fs/promises";
|
|
44520
|
-
import { delimiter as delimiter3, resolve as
|
|
44757
|
+
import { delimiter as delimiter3, resolve as resolve39 } from "node:path";
|
|
44521
44758
|
async function installCornerGitHubWrappers(input) {
|
|
44522
|
-
const bin =
|
|
44759
|
+
const bin = resolve39(input.root, "beeline-github-bin");
|
|
44523
44760
|
await mkdir25(bin, { recursive: true, mode: 448 });
|
|
44524
44761
|
const common = {
|
|
44525
44762
|
node: process.execPath,
|
|
@@ -44531,13 +44768,13 @@ async function installCornerGitHubWrappers(input) {
|
|
|
44531
44768
|
gitCommand: input.gitBinary,
|
|
44532
44769
|
originUrl: input.originUrl ?? ""
|
|
44533
44770
|
};
|
|
44534
|
-
await writeLauncher(
|
|
44771
|
+
await writeLauncher(resolve39(bin, "git"), {
|
|
44535
44772
|
...common,
|
|
44536
44773
|
command: input.gitBinary,
|
|
44537
44774
|
launcher: "git",
|
|
44538
44775
|
restFallback: false
|
|
44539
44776
|
});
|
|
44540
|
-
await writeLauncher(
|
|
44777
|
+
await writeLauncher(resolve39(bin, "gh"), {
|
|
44541
44778
|
...common,
|
|
44542
44779
|
command: input.ghBinary ?? "",
|
|
44543
44780
|
launcher: "gh",
|
|
@@ -44991,32 +45228,32 @@ function agentGitIdentityEnv(agent) {
|
|
|
44991
45228
|
// apps/body/dist/warm-node-modules.js
|
|
44992
45229
|
import { createHash as createHash15, randomUUID as randomUUID14 } from "node:crypto";
|
|
44993
45230
|
import { constants as fsConstants3 } from "node:fs";
|
|
44994
|
-
import { chmod as chmod10, copyFile as copyFile2, link, lstat as
|
|
44995
|
-
import { dirname as dirname25, join as join19, resolve as
|
|
45231
|
+
import { chmod as chmod10, copyFile as copyFile2, link, lstat as lstat8, mkdir as mkdir26, readdir as readdir12, readFile as readFile32, readlink as readlink2, rename as rename11, rm as rm18, stat as stat11, symlink as symlink3, utimes } from "node:fs/promises";
|
|
45232
|
+
import { dirname as dirname25, join as join19, resolve as resolve40 } from "node:path";
|
|
44996
45233
|
var STORE_FORMAT = "v1";
|
|
44997
45234
|
var STAGING_PREFIX = ".beeline-warm-";
|
|
44998
45235
|
var STAGING_SWEEP_MS = 24 * 60 * 60 * 1e3;
|
|
44999
45236
|
var WARM_STORE_MAX_ENTRIES = 3;
|
|
45000
45237
|
function sharedNpmCacheDir(supervisorRoot2) {
|
|
45001
|
-
return
|
|
45238
|
+
return resolve40(supervisorRoot2, "beeline", "npm-cache");
|
|
45002
45239
|
}
|
|
45003
45240
|
function sharedPnpmStoreDir(supervisorRoot2) {
|
|
45004
|
-
return
|
|
45241
|
+
return resolve40(supervisorRoot2, "beeline", "pnpm-store");
|
|
45005
45242
|
}
|
|
45006
45243
|
function sharedTurboCacheDir(supervisorRoot2) {
|
|
45007
|
-
return
|
|
45244
|
+
return resolve40(supervisorRoot2, "beeline", "turbo-cache");
|
|
45008
45245
|
}
|
|
45009
45246
|
function warmNodeModulesStoreDir(supervisorRoot2) {
|
|
45010
|
-
return
|
|
45247
|
+
return resolve40(supervisorRoot2, "beeline", "node-modules");
|
|
45011
45248
|
}
|
|
45012
45249
|
function mobileNodeModulesStoreDir(supervisorRoot2) {
|
|
45013
|
-
return
|
|
45250
|
+
return resolve40(supervisorRoot2, "beeline", "node-modules-mobile");
|
|
45014
45251
|
}
|
|
45015
45252
|
function isPlanRefusal(value) {
|
|
45016
45253
|
return "failure" in value;
|
|
45017
45254
|
}
|
|
45018
45255
|
async function readWarmPlan(worktreePath) {
|
|
45019
|
-
const lockfile = await
|
|
45256
|
+
const lockfile = await readFile32(resolve40(worktreePath, "package-lock.json")).catch(() => void 0);
|
|
45020
45257
|
if (!lockfile)
|
|
45021
45258
|
return { failure: "no-lockfile" };
|
|
45022
45259
|
const packages = parseLockfilePackages(lockfile);
|
|
@@ -45055,11 +45292,11 @@ async function seedWarmNodeModules(input) {
|
|
|
45055
45292
|
return { reason: plan.failure, ...plan.detail ? { detail: plan.detail } : {} };
|
|
45056
45293
|
}
|
|
45057
45294
|
for (const tree of plan.trees) {
|
|
45058
|
-
if (await pathExists(
|
|
45295
|
+
if (await pathExists(resolve40(input.worktreePath, tree))) {
|
|
45059
45296
|
return { reason: "present", key: plan.key };
|
|
45060
45297
|
}
|
|
45061
45298
|
}
|
|
45062
|
-
const entry =
|
|
45299
|
+
const entry = resolve40(input.storeRoot, plan.key);
|
|
45063
45300
|
if (!await isDirectory(entry))
|
|
45064
45301
|
return { reason: "cold", key: plan.key };
|
|
45065
45302
|
const [storeDevice, checkoutDevice] = await Promise.all([
|
|
@@ -45069,19 +45306,19 @@ async function seedWarmNodeModules(input) {
|
|
|
45069
45306
|
if (storeDevice === void 0 || storeDevice !== checkoutDevice) {
|
|
45070
45307
|
return { reason: "cross-device", key: plan.key };
|
|
45071
45308
|
}
|
|
45072
|
-
const staging =
|
|
45309
|
+
const staging = resolve40(input.storeRoot, `${STAGING_PREFIX}${process.pid}.${randomUUID14()}`);
|
|
45073
45310
|
const placed = [];
|
|
45074
45311
|
const now2 = (input.now ?? Date.now)();
|
|
45075
45312
|
try {
|
|
45076
45313
|
await sweepStaleStaging(input.storeRoot, now2);
|
|
45077
45314
|
await utimes(entry, now2 / 1e3, now2 / 1e3).catch(() => void 0);
|
|
45078
45315
|
for (const tree of plan.trees) {
|
|
45079
|
-
await cloneTree(
|
|
45316
|
+
await cloneTree(resolve40(entry, tree), resolve40(staging, tree), seedFile);
|
|
45080
45317
|
}
|
|
45081
45318
|
for (const tree of plan.trees) {
|
|
45082
|
-
const target =
|
|
45319
|
+
const target = resolve40(input.worktreePath, tree);
|
|
45083
45320
|
await mkdir26(dirname25(target), { recursive: true });
|
|
45084
|
-
await rename11(
|
|
45321
|
+
await rename11(resolve40(staging, tree), target);
|
|
45085
45322
|
placed.push(target);
|
|
45086
45323
|
}
|
|
45087
45324
|
return { reason: "seeded", key: plan.key };
|
|
@@ -45099,11 +45336,11 @@ async function harvestWarmNodeModules(input) {
|
|
|
45099
45336
|
if (isPlanRefusal(plan)) {
|
|
45100
45337
|
return { reason: plan.failure, ...plan.detail ? { detail: plan.detail } : {} };
|
|
45101
45338
|
}
|
|
45102
|
-
const entry =
|
|
45339
|
+
const entry = resolve40(input.storeRoot, plan.key);
|
|
45103
45340
|
if (await pathExists(entry))
|
|
45104
45341
|
return { reason: "already-warm", key: plan.key };
|
|
45105
45342
|
for (const tree of plan.trees) {
|
|
45106
|
-
if (!await isDirectory(
|
|
45343
|
+
if (!await isDirectory(resolve40(input.worktreePath, tree))) {
|
|
45107
45344
|
return { reason: "no-node-modules", key: plan.key, detail: tree };
|
|
45108
45345
|
}
|
|
45109
45346
|
}
|
|
@@ -45115,12 +45352,12 @@ async function harvestWarmNodeModules(input) {
|
|
|
45115
45352
|
detail: `${missing.length} absent, e.g. ${missing.slice(0, 3).join(", ")}`
|
|
45116
45353
|
};
|
|
45117
45354
|
}
|
|
45118
|
-
const staging =
|
|
45355
|
+
const staging = resolve40(input.storeRoot, `${STAGING_PREFIX}${process.pid}.${randomUUID14()}`);
|
|
45119
45356
|
try {
|
|
45120
45357
|
await mkdir26(input.storeRoot, { recursive: true, mode: 493 });
|
|
45121
45358
|
await sweepStaleStaging(input.storeRoot, (input.now ?? Date.now)());
|
|
45122
45359
|
for (const tree of plan.trees) {
|
|
45123
|
-
await cloneTree(
|
|
45360
|
+
await cloneTree(resolve40(input.worktreePath, tree), resolve40(staging, tree), harvestFile);
|
|
45124
45361
|
}
|
|
45125
45362
|
await input.onCopied?.();
|
|
45126
45363
|
if (!await stagedTreeIsPublishable(input.worktreePath, staging, plan.key)) {
|
|
@@ -45143,16 +45380,16 @@ async function stagedTreeIsPublishable(worktreePath, staging, key) {
|
|
|
45143
45380
|
return false;
|
|
45144
45381
|
const hidden = join19("node_modules", ".package-lock.json");
|
|
45145
45382
|
const [copied, current] = await Promise.all([
|
|
45146
|
-
|
|
45147
|
-
|
|
45383
|
+
readFile32(resolve40(staging, hidden)).catch(() => void 0),
|
|
45384
|
+
readFile32(resolve40(worktreePath, hidden)).catch(() => void 0)
|
|
45148
45385
|
]);
|
|
45149
45386
|
if (!copied || !current || !copied.equals(current))
|
|
45150
45387
|
return false;
|
|
45151
45388
|
return (await missingInstalledPackages(worktreePath, staging)).length === 0;
|
|
45152
45389
|
}
|
|
45153
45390
|
async function missingInstalledPackages(worktreePath, treeRoot = worktreePath) {
|
|
45154
|
-
const wanted = parseLockfilePackages(await
|
|
45155
|
-
const installed = parseLockfilePackages(await
|
|
45391
|
+
const wanted = parseLockfilePackages(await readFile32(resolve40(worktreePath, "package-lock.json")).catch(() => void 0));
|
|
45392
|
+
const installed = parseLockfilePackages(await readFile32(resolve40(treeRoot, "node_modules", ".package-lock.json")).catch(() => void 0));
|
|
45156
45393
|
if (!wanted)
|
|
45157
45394
|
return ["package-lock.json is unreadable"];
|
|
45158
45395
|
if (!installed)
|
|
@@ -45172,7 +45409,7 @@ async function missingInstalledPackages(worktreePath, treeRoot = worktreePath) {
|
|
|
45172
45409
|
required.push(path);
|
|
45173
45410
|
}
|
|
45174
45411
|
await mapWithLimit(required, INTEGRITY_READ_CONCURRENCY, async (path) => {
|
|
45175
|
-
if (!(path in installed) || !await isInstalledPackage(
|
|
45412
|
+
if (!(path in installed) || !await isInstalledPackage(resolve40(treeRoot, path))) {
|
|
45176
45413
|
missing.push(path);
|
|
45177
45414
|
}
|
|
45178
45415
|
});
|
|
@@ -45212,7 +45449,7 @@ function isContainedTreePath(value) {
|
|
|
45212
45449
|
}
|
|
45213
45450
|
async function cloneTree(source, target, file, topLevel = true) {
|
|
45214
45451
|
await mkdir26(target, { recursive: true, mode: 493 });
|
|
45215
|
-
for (const entry of await
|
|
45452
|
+
for (const entry of await readdir12(source, { withFileTypes: true })) {
|
|
45216
45453
|
const from = join19(source, entry.name);
|
|
45217
45454
|
const to = join19(target, entry.name);
|
|
45218
45455
|
if (entry.isSymbolicLink()) {
|
|
@@ -45241,10 +45478,10 @@ var seedFile = async (source, target, topLevel) => {
|
|
|
45241
45478
|
await chmod10(target, 420);
|
|
45242
45479
|
};
|
|
45243
45480
|
async function pruneWarmStore(storeRoot, keep) {
|
|
45244
|
-
const names = (await
|
|
45481
|
+
const names = (await readdir12(storeRoot).catch(() => [])).filter((name) => !name.startsWith(STAGING_PREFIX));
|
|
45245
45482
|
const entries = [];
|
|
45246
45483
|
for (const name of names) {
|
|
45247
|
-
const info = await
|
|
45484
|
+
const info = await lstat8(join19(storeRoot, name)).catch(() => void 0);
|
|
45248
45485
|
if (info?.isDirectory())
|
|
45249
45486
|
entries.push({ name, usedAt: info.mtimeMs });
|
|
45250
45487
|
}
|
|
@@ -45255,19 +45492,19 @@ async function pruneWarmStore(storeRoot, keep) {
|
|
|
45255
45492
|
return dropped.map((entry) => entry.name);
|
|
45256
45493
|
}
|
|
45257
45494
|
async function sweepStaleStaging(storeRoot, now2) {
|
|
45258
|
-
const entries = await
|
|
45495
|
+
const entries = await readdir12(storeRoot).catch(() => []);
|
|
45259
45496
|
for (const name of entries) {
|
|
45260
45497
|
if (!name.startsWith(STAGING_PREFIX))
|
|
45261
45498
|
continue;
|
|
45262
45499
|
const path = join19(storeRoot, name);
|
|
45263
|
-
const info = await
|
|
45500
|
+
const info = await lstat8(path).catch(() => void 0);
|
|
45264
45501
|
if (!info || now2 - info.mtimeMs < STAGING_SWEEP_MS)
|
|
45265
45502
|
continue;
|
|
45266
45503
|
await rm18(path, { recursive: true, force: true }).catch(() => void 0);
|
|
45267
45504
|
}
|
|
45268
45505
|
}
|
|
45269
45506
|
async function pathExists(path) {
|
|
45270
|
-
return
|
|
45507
|
+
return lstat8(path).then(() => true, () => false);
|
|
45271
45508
|
}
|
|
45272
45509
|
async function deviceOf(path) {
|
|
45273
45510
|
return stat11(path).then((info) => info.dev, () => void 0);
|
|
@@ -45830,7 +46067,7 @@ var MonolithCornerTurnLoop = class {
|
|
|
45830
46067
|
this.options.api.execute("getCornerRestoreState", { cornerId: this.options.cornerId })
|
|
45831
46068
|
]);
|
|
45832
46069
|
const { hostRoutes: grantedHostRoutes, devices: grantedDevices, isolatedCategories } = grants;
|
|
45833
|
-
const privateAssetRoot =
|
|
46070
|
+
const privateAssetRoot = resolve41(runtimeDirectory(this.options.runtime.supervisorRoot, this.options.runtime.agent.publicKey), "private-assets");
|
|
45834
46071
|
const self = roster.members.find((member) => member.identityId === this.agent.publicKey);
|
|
45835
46072
|
const opener = this.options.openedBy ? roster.members.find((member) => member.identityId === this.options.openedBy) : void 0;
|
|
45836
46073
|
const reviewer = Boolean(this.options.repository) && configuration.isReviewer === true;
|
|
@@ -45954,12 +46191,12 @@ var MonolithCornerTurnLoop = class {
|
|
|
45954
46191
|
await prepareCodexCacheTargets(homeOverlay.CODEX_HOME);
|
|
45955
46192
|
if (assets && homeOverlay.HOME)
|
|
45956
46193
|
await preparePackageCacheTargets(homeOverlay.HOME);
|
|
45957
|
-
const cargoTargetDir =
|
|
46194
|
+
const cargoTargetDir = resolve41(this.options.worktreePath, ".beeline-cargo-target");
|
|
45958
46195
|
const npmCacheDir = cacheEnv.npm_config_cache ?? sharedNpmCacheDir(this.options.runtime.supervisorRoot);
|
|
45959
46196
|
const pnpmStoreDir = cacheEnv.PNPM_CONFIG_STORE_DIR ?? sharedPnpmStoreDir(this.options.runtime.supervisorRoot);
|
|
45960
46197
|
const turboCacheDir = cacheEnv.TURBO_CACHE_DIR ?? sharedTurboCacheDir(this.options.runtime.supervisorRoot);
|
|
45961
|
-
const modelCacheDir = cacheEnv.HF_HUB_CACHE ??
|
|
45962
|
-
const hfHomeDir = assets && this.options.config.agentHomeRoot ?
|
|
46198
|
+
const modelCacheDir = cacheEnv.HF_HUB_CACHE ?? resolve41(this.options.runtime.supervisorRoot, "beeline", "model-cache");
|
|
46199
|
+
const hfHomeDir = assets && this.options.config.agentHomeRoot ? resolve41(this.options.config.agentHomeRoot, "cache/huggingface-private") : modelCacheDir;
|
|
45963
46200
|
await Promise.all([npmCacheDir, pnpmStoreDir, cargoTargetDir, turboCacheDir, modelCacheDir].map((path) => mkdir27(path, { recursive: true, mode: 448 })));
|
|
45964
46201
|
const agentEnv = {
|
|
45965
46202
|
...this.options.config.agentEnv,
|
|
@@ -45971,7 +46208,7 @@ var MonolithCornerTurnLoop = class {
|
|
|
45971
46208
|
...cacheEnv,
|
|
45972
46209
|
...androidAssets && this.options.config.agentHomeRoot ? {
|
|
45973
46210
|
ANDROID_AVD_HOME: androidAssets.avdBase,
|
|
45974
|
-
ANDROID_EMULATOR_HOME:
|
|
46211
|
+
ANDROID_EMULATOR_HOME: resolve41(this.options.config.agentHomeRoot, "android-emulator")
|
|
45975
46212
|
} : {},
|
|
45976
46213
|
npm_config_cache: npmCacheDir,
|
|
45977
46214
|
// pnpm reads its settings from PNPM_CONFIG_* environment variables and
|
|
@@ -45982,14 +46219,14 @@ var MonolithCornerTurnLoop = class {
|
|
|
45982
46219
|
HF_HOME: hfHomeDir,
|
|
45983
46220
|
HUGGINGFACE_HUB_CACHE: assets || isolatedCategories.includes("package-cache") ? modelCacheDir : join20(modelCacheDir, "hub"),
|
|
45984
46221
|
...assets && androidAssets && this.options.config.agentHomeRoot ? {
|
|
45985
|
-
BEELINE_ANDROID_LEASE_ROOT:
|
|
45986
|
-
BEELINE_ANDROID_INSTANCE_ROOT:
|
|
46222
|
+
BEELINE_ANDROID_LEASE_ROOT: resolve41(assets.cache, "android-leases"),
|
|
46223
|
+
BEELINE_ANDROID_INSTANCE_ROOT: resolve41(this.options.config.agentHomeRoot, "android-instances"),
|
|
45987
46224
|
BEELINE_ANDROID_BASE_AVD_HOME: androidAssets.avdBase,
|
|
45988
|
-
BEELINE_ANDROID_EMULATOR_BINARY:
|
|
46225
|
+
BEELINE_ANDROID_EMULATOR_BINARY: resolve41(homeOverlay.ANDROID_HOME, "emulator/emulator")
|
|
45989
46226
|
} : {}
|
|
45990
46227
|
};
|
|
45991
46228
|
if (toolchain && assets) {
|
|
45992
|
-
agentEnv.PATH = `${
|
|
46229
|
+
agentEnv.PATH = `${resolve41(toolchain.binDir, "../../bin")}:${toolchain.binDir}:${agentEnv.PATH ?? ""}`;
|
|
45993
46230
|
if (this.options.config.agentKind === "pi")
|
|
45994
46231
|
agentEnv.PI_ACP_PI_COMMAND = toolchain.cliCommand;
|
|
45995
46232
|
}
|
|
@@ -46253,7 +46490,7 @@ var MonolithCornerTurnLoop = class {
|
|
|
46253
46490
|
briefRevision: restore.brief?.revision
|
|
46254
46491
|
}),
|
|
46255
46492
|
...this.options.config.agentHomeRoot && this.options.config.agentKind && !AGENT_SKILL_DIRS.includes(this.options.config.agentKind) ? [
|
|
46256
|
-
`This harness has no verified native skill discovery. Read the release-managed review procedure at ${
|
|
46493
|
+
`This harness has no verified native skill discovery. Read the release-managed review procedure at ${resolve41(this.options.config.agentHomeRoot, "codex", "skills", "beeline-review", "SKILL.md")} before the verdict.`
|
|
46257
46494
|
] : []
|
|
46258
46495
|
].join("\n");
|
|
46259
46496
|
} catch {
|
|
@@ -46371,8 +46608,8 @@ var MonolithCornerTurnLoop = class {
|
|
|
46371
46608
|
let timer;
|
|
46372
46609
|
const stats = statsPromise && remaining > 0 ? await Promise.race([
|
|
46373
46610
|
statsPromise,
|
|
46374
|
-
new Promise((
|
|
46375
|
-
timer = setTimeout(() =>
|
|
46611
|
+
new Promise((resolve53) => {
|
|
46612
|
+
timer = setTimeout(() => resolve53(void 0), remaining);
|
|
46376
46613
|
})
|
|
46377
46614
|
]).finally(() => {
|
|
46378
46615
|
if (timer)
|
|
@@ -46437,7 +46674,7 @@ var MonolithCornerTurnLoop = class {
|
|
|
46437
46674
|
const briefDelivered = this.attachmentDir && briefAttachments.length ? await deliverAttachments(briefAttachments, join20(this.attachmentDir, requestId.replace(/[^\w-]/g, "_"), "brief", String(assignedBrief.revision)), this.options.fetchImpl) : [];
|
|
46438
46675
|
briefFileLines = await Promise.all((assignedBrief?.attachments ?? []).map(async (file, index) => {
|
|
46439
46676
|
const entry = briefDelivered.find((item) => item.attachment === briefAttachments[index]);
|
|
46440
|
-
const verified = entry?.path && createHash16("sha256").update(await
|
|
46677
|
+
const verified = entry?.path && createHash16("sha256").update(await readFile33(entry.path)).digest("hex") === file.sha256;
|
|
46441
46678
|
return `- ${file.title} (${file.purpose}; ${file.required ? "required" : "optional"}; sha256 ${file.sha256}): ${verified ? entry.path : "UNAVAILABLE OR CONTENT MISMATCH"}`;
|
|
46442
46679
|
}));
|
|
46443
46680
|
missingRequiredBriefFile = (assignedBrief?.attachments ?? []).some((file, index) => file.required && briefFileLines[index]?.includes("UNAVAILABLE OR CONTENT MISMATCH"));
|
|
@@ -46875,13 +47112,13 @@ ${continuation}` : assembled;
|
|
|
46875
47112
|
if (this.harvest || !this.options.repository || this.options.config.agentSharedAssetRoot)
|
|
46876
47113
|
return;
|
|
46877
47114
|
const { cornerId, worktreePath, runtime } = this.options;
|
|
46878
|
-
const mobilePath =
|
|
47115
|
+
const mobilePath = resolve41(worktreePath, "apps/mobile");
|
|
46879
47116
|
const jobs = [
|
|
46880
47117
|
harvestWarmNodeModules({
|
|
46881
47118
|
worktreePath,
|
|
46882
47119
|
storeRoot: warmNodeModulesStoreDir(runtime.supervisorRoot)
|
|
46883
47120
|
}),
|
|
46884
|
-
...existsSync9(
|
|
47121
|
+
...existsSync9(resolve41(mobilePath, "package-lock.json")) ? [
|
|
46885
47122
|
harvestWarmNodeModules({
|
|
46886
47123
|
worktreePath: mobilePath,
|
|
46887
47124
|
storeRoot: mobileNodeModulesStoreDir(runtime.supervisorRoot)
|
|
@@ -46929,7 +47166,7 @@ ${continuation}` : assembled;
|
|
|
46929
47166
|
const delay = outage ? Math.min(2e3 * 2 ** attempt, 3e4) : 250 * (attempt + 1);
|
|
46930
47167
|
if ((outage ? Date.now() + delay > outageDeadline : attempt === 2) || this.forcedStop || this.currentTurn && this.stoppedTurns.has(this.currentTurn.requestId))
|
|
46931
47168
|
throw error;
|
|
46932
|
-
await new Promise((
|
|
47169
|
+
await new Promise((resolve53) => setTimeout(resolve53, delay));
|
|
46933
47170
|
}
|
|
46934
47171
|
}
|
|
46935
47172
|
if (!token)
|
|
@@ -47029,8 +47266,8 @@ ${continuation}` : assembled;
|
|
|
47029
47266
|
|
|
47030
47267
|
// apps/body/dist/corner-disk-recovery.js
|
|
47031
47268
|
import { execFile as execFile18 } from "node:child_process";
|
|
47032
|
-
import { lstat as
|
|
47033
|
-
import { basename as basename10, dirname as dirname27, join as join21, relative as relative3, resolve as
|
|
47269
|
+
import { lstat as lstat9, readdir as readdir13, realpath as realpath3, rm as rm19 } from "node:fs/promises";
|
|
47270
|
+
import { basename as basename10, dirname as dirname27, join as join21, relative as relative3, resolve as resolve42, sep as sep3 } from "node:path";
|
|
47034
47271
|
import { promisify as promisify12 } from "node:util";
|
|
47035
47272
|
var execFileAsync12 = promisify12(execFile18);
|
|
47036
47273
|
var GENERATED_DIRS = /* @__PURE__ */ new Set([
|
|
@@ -47045,11 +47282,11 @@ var GENERATED_DIRS = /* @__PURE__ */ new Set([
|
|
|
47045
47282
|
var MAX_DIRECTORY_DEPTH = 4;
|
|
47046
47283
|
var MAX_VISITED_DIRECTORIES = 5e3;
|
|
47047
47284
|
function cornerRecoveryPointerPath(worktree) {
|
|
47048
|
-
const checkout =
|
|
47285
|
+
const checkout = resolve42(worktree.path);
|
|
47049
47286
|
if (basename10(checkout) !== worktree.cornerId || basename10(dirname27(checkout)) !== "corners" || basename10(dirname27(dirname27(checkout))) !== "beeline" || !/^[a-zA-Z0-9-]{1,80}$/.test(worktree.cornerId)) {
|
|
47050
47287
|
throw new Error("refusing recovery pointer outside a Beeline corner checkout");
|
|
47051
47288
|
}
|
|
47052
|
-
return
|
|
47289
|
+
return resolve42(dirname27(dirname27(checkout)), "recovery", "corners", `${worktree.cornerId}.json`);
|
|
47053
47290
|
}
|
|
47054
47291
|
async function git(checkout, args) {
|
|
47055
47292
|
const result = await execFileAsync12("git", ["-C", checkout, ...args], {
|
|
@@ -47067,9 +47304,9 @@ async function ignoredAndUntracked(checkout, path) {
|
|
|
47067
47304
|
return !(await git(checkout, ["ls-files", "--", rel])).trim();
|
|
47068
47305
|
}
|
|
47069
47306
|
async function preserveUnpublishedCornerWorktree(worktree, reason) {
|
|
47070
|
-
const checkout =
|
|
47307
|
+
const checkout = resolve42(worktree.path);
|
|
47071
47308
|
const pointer = cornerRecoveryPointerPath(worktree);
|
|
47072
|
-
const info = await
|
|
47309
|
+
const info = await lstat9(checkout);
|
|
47073
47310
|
if (!info.isDirectory() || await realpath3(checkout) !== checkout) {
|
|
47074
47311
|
throw new Error("refusing to prune a non-canonical corner checkout");
|
|
47075
47312
|
}
|
|
@@ -47093,7 +47330,7 @@ async function preserveUnpublishedCornerWorktree(worktree, reason) {
|
|
|
47093
47330
|
break;
|
|
47094
47331
|
if (current.depth >= MAX_DIRECTORY_DEPTH)
|
|
47095
47332
|
continue;
|
|
47096
|
-
for (const entry of await
|
|
47333
|
+
for (const entry of await readdir13(current.path, { withFileTypes: true })) {
|
|
47097
47334
|
if (!entry.isDirectory() || entry.name === ".git")
|
|
47098
47335
|
continue;
|
|
47099
47336
|
const path = join21(current.path, entry.name);
|
|
@@ -47629,7 +47866,7 @@ function cornerStartConfigKey(repository, objective) {
|
|
|
47629
47866
|
function cornerRepositoryCacheDir(supervisorRoot2, remote) {
|
|
47630
47867
|
const normalizedRemote = roomCheckoutRemote(remote);
|
|
47631
47868
|
const repositoryHash = createHash17("sha256").update(normalizedRemote).digest("hex").slice(0, 24);
|
|
47632
|
-
return
|
|
47869
|
+
return resolve43(supervisorRoot2, "beeline", "repositories", `${repositoryHash}.git`);
|
|
47633
47870
|
}
|
|
47634
47871
|
function isStandingCornerStartFault(error) {
|
|
47635
47872
|
const text2 = error instanceof Error ? error.message : String(error);
|
|
@@ -47638,11 +47875,11 @@ function isStandingCornerStartFault(error) {
|
|
|
47638
47875
|
async function materializeCornerWorktree(input) {
|
|
47639
47876
|
const remote = roomCheckoutRemote(input.remote);
|
|
47640
47877
|
const gitCommonDir = cornerRepositoryCacheDir(input.supervisorRoot, remote);
|
|
47641
|
-
const path =
|
|
47878
|
+
const path = resolve43(input.supervisorRoot, "beeline", "corners", input.cornerId);
|
|
47642
47879
|
await mkdir28(dirname28(gitCommonDir), { recursive: true, mode: 448 });
|
|
47643
47880
|
await mkdir28(dirname28(path), { recursive: true, mode: 448 });
|
|
47644
47881
|
const authEnv = githubGitEnv(input.token);
|
|
47645
|
-
if (!existsSync10(
|
|
47882
|
+
if (!existsSync10(resolve43(gitCommonDir, "HEAD"))) {
|
|
47646
47883
|
await execFileAsync13("git", ["clone", "--bare", remote, gitCommonDir], {
|
|
47647
47884
|
env: authEnv,
|
|
47648
47885
|
maxBuffer: 4 * 1024 * 1024
|
|
@@ -47665,7 +47902,7 @@ async function materializeCornerWorktree(input) {
|
|
|
47665
47902
|
return false;
|
|
47666
47903
|
throw error;
|
|
47667
47904
|
});
|
|
47668
|
-
if (!existsSync10(
|
|
47905
|
+
if (!existsSync10(resolve43(path, ".git"))) {
|
|
47669
47906
|
await rm20(path, { recursive: true, force: true });
|
|
47670
47907
|
await execFileAsync13("git", [
|
|
47671
47908
|
`--git-dir=${gitCommonDir}`,
|
|
@@ -47683,8 +47920,8 @@ async function materializeCornerWorktree(input) {
|
|
|
47683
47920
|
if (seed.reason !== "no-lockfile") {
|
|
47684
47921
|
console.log(`[thin-core] corner ${input.cornerId} warm node_modules: ${seed.reason}${seed.detail ? ` (${seed.detail})` : ""}`);
|
|
47685
47922
|
}
|
|
47686
|
-
const mobilePath =
|
|
47687
|
-
if (existsSync10(
|
|
47923
|
+
const mobilePath = resolve43(path, "apps/mobile");
|
|
47924
|
+
if (existsSync10(resolve43(mobilePath, "package-lock.json"))) {
|
|
47688
47925
|
const mobileSeed = input.workspaceId ? { reason: "no-lockfile" } : await seedWarmNodeModules({
|
|
47689
47926
|
worktreePath: mobilePath,
|
|
47690
47927
|
storeRoot: mobileNodeModulesStoreDir(input.supervisorRoot)
|
|
@@ -47742,9 +47979,9 @@ async function mapWithConcurrency(values, limit, visit) {
|
|
|
47742
47979
|
}));
|
|
47743
47980
|
}
|
|
47744
47981
|
async function discoverCornerWorktree(supervisorRoot2, cornerId) {
|
|
47745
|
-
const cornersRoot =
|
|
47746
|
-
const path =
|
|
47747
|
-
if (dirname28(path) !== cornersRoot || !existsSync10(
|
|
47982
|
+
const cornersRoot = resolve43(supervisorRoot2, "beeline", "corners");
|
|
47983
|
+
const path = resolve43(cornersRoot, cornerId);
|
|
47984
|
+
if (dirname28(path) !== cornersRoot || !existsSync10(resolve43(path, ".git")))
|
|
47748
47985
|
return void 0;
|
|
47749
47986
|
const [canonicalRoot, canonicalPath] = await Promise.all([
|
|
47750
47987
|
realpath4(cornersRoot),
|
|
@@ -47756,8 +47993,8 @@ async function discoverCornerWorktree(supervisorRoot2, cornerId) {
|
|
|
47756
47993
|
const common = await execFileAsync13("git", ["-C", path, "rev-parse", "--git-common-dir"]).catch(() => void 0);
|
|
47757
47994
|
if (!common)
|
|
47758
47995
|
return void 0;
|
|
47759
|
-
const gitCommonDir =
|
|
47760
|
-
const repositoriesRoot =
|
|
47996
|
+
const gitCommonDir = resolve43(path, common.stdout.trim());
|
|
47997
|
+
const repositoriesRoot = resolve43(supervisorRoot2, "beeline", "repositories");
|
|
47761
47998
|
const commonRelative = relative4(repositoriesRoot, gitCommonDir);
|
|
47762
47999
|
if (!commonRelative || commonRelative === ".." || commonRelative.startsWith(`..${sep4}`) || commonRelative.startsWith(sep4)) {
|
|
47763
48000
|
throw new Error(`refusing corner ${cornerId} with git directory outside repository cache`);
|
|
@@ -47765,8 +48002,8 @@ async function discoverCornerWorktree(supervisorRoot2, cornerId) {
|
|
|
47765
48002
|
return { path, gitCommonDir };
|
|
47766
48003
|
}
|
|
47767
48004
|
async function localCornerWorktreeIds(supervisorRoot2) {
|
|
47768
|
-
const root =
|
|
47769
|
-
const entries = await
|
|
48005
|
+
const root = resolve43(supervisorRoot2, "beeline", "corners");
|
|
48006
|
+
const entries = await readdir14(root, { withFileTypes: true }).catch((error) => {
|
|
47770
48007
|
if (error.code === "ENOENT")
|
|
47771
48008
|
return [];
|
|
47772
48009
|
throw error;
|
|
@@ -47871,14 +48108,14 @@ async function originContains(gitCommonDir, head) {
|
|
|
47871
48108
|
}
|
|
47872
48109
|
var execFileAsync13 = promisify13(execFile19);
|
|
47873
48110
|
async function removeCornerScratchWorkspace(input) {
|
|
47874
|
-
const expected =
|
|
47875
|
-
if (
|
|
48111
|
+
const expected = resolve43(input.roomRoot, "scratch");
|
|
48112
|
+
if (resolve43(input.scratchPath) !== expected) {
|
|
47876
48113
|
throw new Error(`refusing to remove scratch outside corner ${input.cornerId}`);
|
|
47877
48114
|
}
|
|
47878
|
-
for (const entry of await
|
|
48115
|
+
for (const entry of await readdir14(expected, { withFileTypes: true }).catch(() => [])) {
|
|
47879
48116
|
if (entry.name === "agent-home" || entry.name === "agent-private")
|
|
47880
48117
|
continue;
|
|
47881
|
-
await rm20(
|
|
48118
|
+
await rm20(resolve43(expected, entry.name), { recursive: true, force: true });
|
|
47882
48119
|
}
|
|
47883
48120
|
}
|
|
47884
48121
|
var RoomRuntimeCoordinator = class {
|
|
@@ -47897,8 +48134,8 @@ var RoomRuntimeCoordinator = class {
|
|
|
47897
48134
|
localWorktreeIds;
|
|
47898
48135
|
/** Event-driven cleanup retries stay scoped to the failed local corner. */
|
|
47899
48136
|
archiveCleanupFaults = /* @__PURE__ */ new Map();
|
|
47900
|
-
/** A
|
|
47901
|
-
|
|
48137
|
+
/** A non-retryable refusal parks this local checkout for the rest of this core's lifetime. */
|
|
48138
|
+
archiveCleanupRefused = /* @__PURE__ */ new Set();
|
|
47902
48139
|
/**
|
|
47903
48140
|
* A corner whose branch cleanup found commits no origin ref contains. That
|
|
47904
48141
|
* is never transient - nothing pushes them later - so retrying it every
|
|
@@ -48354,13 +48591,13 @@ var RoomRuntimeCoordinator = class {
|
|
|
48354
48591
|
return this.runtime.rooms.find((room) => room.channelId === roomId);
|
|
48355
48592
|
}
|
|
48356
48593
|
roomRoot(roomId) {
|
|
48357
|
-
return this.roomRecord(roomId)?.root ??
|
|
48594
|
+
return this.roomRecord(roomId)?.root ?? resolve43(dirname28(this.configPath), "rooms", roomId);
|
|
48358
48595
|
}
|
|
48359
48596
|
roomAgentHomeRoot(workspaceRoot, required = false) {
|
|
48360
48597
|
const flag = process.env.BUZZY_BODY_ROOM_HOME;
|
|
48361
48598
|
if (!required && flag === "0")
|
|
48362
48599
|
return void 0;
|
|
48363
|
-
const home =
|
|
48600
|
+
const home = resolve43(workspaceRoot, "agent-home");
|
|
48364
48601
|
if (!required && flag !== "1" && !existsSync10(home) && existsSync10(workspaceRoot))
|
|
48365
48602
|
return void 0;
|
|
48366
48603
|
try {
|
|
@@ -48377,8 +48614,8 @@ var RoomRuntimeCoordinator = class {
|
|
|
48377
48614
|
...this.baseConfig,
|
|
48378
48615
|
workspaceRoot,
|
|
48379
48616
|
...process.env.BEELINE_SHARED_ASSETS_ENABLED === "0" ? { agentSharedAssetRoot: void 0 } : { agentSharedAssetRoot: workspaceAssetRoot(this.runtime.supervisorRoot, this.runtime.communityId) },
|
|
48380
|
-
agentPrivateRoot:
|
|
48381
|
-
agentMemoryRoot:
|
|
48617
|
+
agentPrivateRoot: resolve43(workspaceRoot, "agent-private"),
|
|
48618
|
+
agentMemoryRoot: resolve43(dirname28(this.configPath), "memory"),
|
|
48382
48619
|
openRouterRoutingCacheDir: openRouterRoutingCacheDir(dirname28(this.configPath)),
|
|
48383
48620
|
turnTraceDir: turnTraceDirectory(dirname28(this.configPath)),
|
|
48384
48621
|
...agentHomeRoot ? { agentHomeRoot } : {}
|
|
@@ -48461,11 +48698,11 @@ var RoomRuntimeCoordinator = class {
|
|
|
48461
48698
|
const remote = roomCheckoutRemote(repository.remote);
|
|
48462
48699
|
const targetBranch = repository.targetBranch || "main";
|
|
48463
48700
|
const checkoutId = createHash17("sha256").update(`${roomId}\0${remote}\0${targetBranch}`).digest("hex").slice(0, 24);
|
|
48464
|
-
const path =
|
|
48701
|
+
const path = resolve43(this.runtime.supervisorRoot, "beeline", "room-checkouts", checkoutId);
|
|
48465
48702
|
await mkdir28(dirname28(path), { recursive: true, mode: 448 });
|
|
48466
48703
|
const token = remote.startsWith("https://github.com/") ? await this.parentRepositoryToken(roomId) : void 0;
|
|
48467
48704
|
const env = token ? githubGitEnv(token.token) : process.env;
|
|
48468
|
-
if (!existsSync10(
|
|
48705
|
+
if (!existsSync10(resolve43(path, ".git"))) {
|
|
48469
48706
|
await execFileAsync13("git", ["clone", "--no-checkout", remote, path], {
|
|
48470
48707
|
env,
|
|
48471
48708
|
maxBuffer: 4 * 1024 * 1024
|
|
@@ -48552,10 +48789,10 @@ var RoomRuntimeCoordinator = class {
|
|
|
48552
48789
|
featureBranch,
|
|
48553
48790
|
token: granted.token
|
|
48554
48791
|
}) : void 0;
|
|
48555
|
-
const workspacePath = worktree?.path ??
|
|
48792
|
+
const workspacePath = worktree?.path ?? resolve43(this.roomRoot(corner.cornerId), "scratch");
|
|
48556
48793
|
if (!worktree)
|
|
48557
48794
|
await mkdir28(workspacePath, { recursive: true, mode: 448 });
|
|
48558
|
-
await writePrivateFileAtomically(
|
|
48795
|
+
await writePrivateFileAtomically(resolve43(this.roomRoot(corner.cornerId), ".beeline-corner.json"), `${JSON.stringify({ cornerId: corner.cornerId, parentRoomId: corner.parentRoomId })}
|
|
48559
48796
|
`);
|
|
48560
48797
|
if (worktree && shouldPostInitialCornerWorkingState(restore)) {
|
|
48561
48798
|
await this.options.daemonApi.execute("postCornerRemoteState", {
|
|
@@ -48880,7 +49117,7 @@ var RoomRuntimeCoordinator = class {
|
|
|
48880
49117
|
this.archiveCleanupAbandoned.delete(cornerId);
|
|
48881
49118
|
continue;
|
|
48882
49119
|
}
|
|
48883
|
-
if (this.archiveCleanupAbandoned.has(cornerId))
|
|
49120
|
+
if (this.archiveCleanupAbandoned.has(cornerId) || this.archiveCleanupRefused.has(cornerId))
|
|
48884
49121
|
continue;
|
|
48885
49122
|
if (!this.archiveCleanupDue(cornerId))
|
|
48886
49123
|
continue;
|
|
@@ -48898,7 +49135,10 @@ var RoomRuntimeCoordinator = class {
|
|
|
48898
49135
|
console.error(`[thin-core] corner ${cornerId} branch cleanup abandoned; unpublished work kept:`, error);
|
|
48899
49136
|
continue;
|
|
48900
49137
|
}
|
|
48901
|
-
|
|
49138
|
+
if (error instanceof DaemonApiError && error.status >= 400 && error.status < 500 && !error.retryable)
|
|
49139
|
+
this.archiveCleanupRefused.add(cornerId);
|
|
49140
|
+
else
|
|
49141
|
+
this.deferArchiveCleanup(cornerId);
|
|
48902
49142
|
console.error(`[thin-core] corner ${cornerId} branch cleanup retry failed:`, error);
|
|
48903
49143
|
}
|
|
48904
49144
|
}
|
|
@@ -48917,9 +49157,8 @@ var RoomRuntimeCoordinator = class {
|
|
|
48917
49157
|
continue;
|
|
48918
49158
|
if (this.archiveCleanupAbandoned.has(cornerId))
|
|
48919
49159
|
continue;
|
|
48920
|
-
if (this.
|
|
49160
|
+
if (this.archiveCleanupRefused.has(cornerId))
|
|
48921
49161
|
continue;
|
|
48922
|
-
this.archiveCleanupAccessDenied.delete(cornerId);
|
|
48923
49162
|
let corner = corners.get(cornerId);
|
|
48924
49163
|
let discovered;
|
|
48925
49164
|
let candidate;
|
|
@@ -48948,7 +49187,7 @@ var RoomRuntimeCoordinator = class {
|
|
|
48948
49187
|
throw new Error(`archived corner ${corner.cornerId} has no authoritative repository`);
|
|
48949
49188
|
}
|
|
48950
49189
|
const expectedCommonDir = cornerRepositoryCacheDir(this.runtime.supervisorRoot, repository.remote);
|
|
48951
|
-
if (
|
|
49190
|
+
if (resolve43(discovered.gitCommonDir) !== expectedCommonDir) {
|
|
48952
49191
|
throw new Error(`archived corner ${corner.cornerId} repository cache does not match`);
|
|
48953
49192
|
}
|
|
48954
49193
|
if (!restore.featureBranch) {
|
|
@@ -48975,8 +49214,8 @@ var RoomRuntimeCoordinator = class {
|
|
|
48975
49214
|
}
|
|
48976
49215
|
continue;
|
|
48977
49216
|
}
|
|
48978
|
-
if (error instanceof DaemonApiError && error.status
|
|
48979
|
-
this.
|
|
49217
|
+
if (error instanceof DaemonApiError && error.status >= 400 && error.status < 500 && !error.retryable)
|
|
49218
|
+
this.archiveCleanupRefused.add(cornerId);
|
|
48980
49219
|
else
|
|
48981
49220
|
this.deferArchiveCleanup(cornerId);
|
|
48982
49221
|
console.error(`[thin-core] archived corner ${cornerId} cleanup deferred:`, error);
|
|
@@ -49036,10 +49275,10 @@ var RoomRuntimeCoordinator = class {
|
|
|
49036
49275
|
async cleanupArchivedCornerLocalState(cornerId, knownArchive) {
|
|
49037
49276
|
if (this.running.has(cornerId) || this.startingCorners.has(cornerId))
|
|
49038
49277
|
return false;
|
|
49039
|
-
const root =
|
|
49278
|
+
const root = resolve43(dirname28(this.configPath), "rooms", cornerId);
|
|
49040
49279
|
if (this.roomRoot(cornerId) !== root || !/^[a-zA-Z0-9-]{1,80}$/.test(cornerId))
|
|
49041
49280
|
return false;
|
|
49042
|
-
const info = await
|
|
49281
|
+
const info = await lstat10(root).catch(() => void 0);
|
|
49043
49282
|
if (!info?.isDirectory() || await realpath4(root) !== root)
|
|
49044
49283
|
return false;
|
|
49045
49284
|
let archived = knownArchive?.has(cornerId) ?? false;
|
|
@@ -49057,9 +49296,9 @@ var RoomRuntimeCoordinator = class {
|
|
|
49057
49296
|
await removeCornerScratchWorkspace({
|
|
49058
49297
|
cornerId,
|
|
49059
49298
|
roomRoot: root,
|
|
49060
|
-
scratchPath:
|
|
49299
|
+
scratchPath: resolve43(root, "scratch")
|
|
49061
49300
|
});
|
|
49062
|
-
await rm20(
|
|
49301
|
+
await rm20(resolve43(root, ".beeline-corner.json"), { force: true });
|
|
49063
49302
|
return true;
|
|
49064
49303
|
}
|
|
49065
49304
|
/** Recover chat-only scratch and per-member homes after missed close events
|
|
@@ -49067,18 +49306,18 @@ var RoomRuntimeCoordinator = class {
|
|
|
49067
49306
|
* checkout has already gone; a scratch directory identifies legacy chat
|
|
49068
49307
|
* corners. Active scratch gets a 14-day file TTL, never a wholesale reap. */
|
|
49069
49308
|
async sweepCornerLocalState(archived, desired) {
|
|
49070
|
-
const root =
|
|
49309
|
+
const root = resolve43(dirname28(this.configPath), "rooms");
|
|
49071
49310
|
const due = this.now() - this.lastCornerScratchSweepAt >= 6 * 60 * 6e4;
|
|
49072
49311
|
if (due)
|
|
49073
49312
|
this.lastCornerScratchSweepAt = this.now();
|
|
49074
|
-
for (const entry of await
|
|
49313
|
+
for (const entry of await readdir14(root, { withFileTypes: true }).catch(() => [])) {
|
|
49075
49314
|
if (!entry.isDirectory() || !/^[a-zA-Z0-9-]{1,80}$/.test(entry.name))
|
|
49076
49315
|
continue;
|
|
49077
|
-
const roomRoot =
|
|
49078
|
-
const scratch =
|
|
49079
|
-
const marker =
|
|
49080
|
-
const hasScratch = (await
|
|
49081
|
-
const hasMarker = (await
|
|
49316
|
+
const roomRoot = resolve43(root, entry.name);
|
|
49317
|
+
const scratch = resolve43(roomRoot, "scratch");
|
|
49318
|
+
const marker = resolve43(roomRoot, ".beeline-corner.json");
|
|
49319
|
+
const hasScratch = (await lstat10(scratch).catch(() => void 0))?.isDirectory() ?? false;
|
|
49320
|
+
const hasMarker = (await lstat10(marker).catch(() => void 0))?.isFile() ?? false;
|
|
49082
49321
|
if (!hasScratch && !hasMarker)
|
|
49083
49322
|
continue;
|
|
49084
49323
|
if (desired.has(entry.name)) {
|
|
@@ -49249,6 +49488,7 @@ var ThinDaemonCore = class {
|
|
|
49249
49488
|
pendingDiscovery = false;
|
|
49250
49489
|
discoveryWaiter;
|
|
49251
49490
|
discoveryStatus = "starting";
|
|
49491
|
+
progressWaiters = /* @__PURE__ */ new Set();
|
|
49252
49492
|
constructor(runtime, configPath, baseConfig, options) {
|
|
49253
49493
|
if (!runtime.transport)
|
|
49254
49494
|
throw new Error("thin daemon requires monolith transport");
|
|
@@ -49259,7 +49499,7 @@ var ThinDaemonCore = class {
|
|
|
49259
49499
|
});
|
|
49260
49500
|
}
|
|
49261
49501
|
async waitForDiscovery(signal) {
|
|
49262
|
-
if (this.pendingDiscovery || signal?.aborted)
|
|
49502
|
+
if (this.pendingDiscovery || this.progressWaiters.size || signal?.aborted)
|
|
49263
49503
|
return;
|
|
49264
49504
|
await new Promise((resolveWait) => {
|
|
49265
49505
|
const done = () => {
|
|
@@ -49269,10 +49509,17 @@ var ThinDaemonCore = class {
|
|
|
49269
49509
|
};
|
|
49270
49510
|
this.discoveryWaiter = done;
|
|
49271
49511
|
signal?.addEventListener("abort", done, { once: true });
|
|
49272
|
-
if (this.pendingDiscovery)
|
|
49512
|
+
if (this.pendingDiscovery || this.progressWaiters.size)
|
|
49273
49513
|
done();
|
|
49274
49514
|
});
|
|
49275
49515
|
}
|
|
49516
|
+
/** The existing machine watchdog tick wakes this loop without discovering Rooms. */
|
|
49517
|
+
requestWorkLoopProgress() {
|
|
49518
|
+
return new Promise((resolveProgress) => {
|
|
49519
|
+
this.progressWaiters.add(resolveProgress);
|
|
49520
|
+
this.discoveryWaiter?.();
|
|
49521
|
+
});
|
|
49522
|
+
}
|
|
49276
49523
|
activeRoomIds() {
|
|
49277
49524
|
return this.roomRuntime.activeRoomIds();
|
|
49278
49525
|
}
|
|
@@ -49336,19 +49583,25 @@ var ThinDaemonCore = class {
|
|
|
49336
49583
|
await opts.onEstablished?.();
|
|
49337
49584
|
const supervisor2 = this.roomRuntime.supervisor;
|
|
49338
49585
|
let failures = 0;
|
|
49586
|
+
let discover = true;
|
|
49339
49587
|
while (!opts.signal?.aborted) {
|
|
49340
|
-
|
|
49588
|
+
const acknowledge = [...this.progressWaiters];
|
|
49589
|
+
const shouldDiscover = discover || this.pendingDiscovery;
|
|
49590
|
+
if (shouldDiscover)
|
|
49591
|
+
this.pendingDiscovery = false;
|
|
49341
49592
|
const wakesBefore = supervisor2.wakes;
|
|
49342
49593
|
try {
|
|
49343
|
-
|
|
49344
|
-
|
|
49345
|
-
|
|
49346
|
-
|
|
49347
|
-
|
|
49594
|
+
if (shouldDiscover) {
|
|
49595
|
+
const membership = await this.roomRuntime.reconcile();
|
|
49596
|
+
if (membership === "not-member")
|
|
49597
|
+
return "agent-removed";
|
|
49598
|
+
this.discoveryStatus = membership === "unknown" ? "monolith membership degraded" : "";
|
|
49599
|
+
failures = 0;
|
|
49600
|
+
}
|
|
49348
49601
|
} catch (error) {
|
|
49349
49602
|
if (isAgentRemovedError(error))
|
|
49350
49603
|
return "agent-removed";
|
|
49351
|
-
failures
|
|
49604
|
+
failures = error instanceof DaemonApiError && !error.retryable ? supervisor2.retries + 1 : failures + 1;
|
|
49352
49605
|
console.error(failures > supervisor2.retries ? "[thin-core] discovery failed; waiting for the next live open or discovery wake:" : `[thin-core] discovery failed; retry ${failures} of ${supervisor2.retries}:`, error);
|
|
49353
49606
|
this.discoveryStatus = `monolith discovery degraded: ${error instanceof Error ? error.message : String(error)}`;
|
|
49354
49607
|
this.roomRuntime.suspectLink(error);
|
|
@@ -49356,16 +49609,24 @@ var ThinDaemonCore = class {
|
|
|
49356
49609
|
if (opts.signal?.aborted)
|
|
49357
49610
|
break;
|
|
49358
49611
|
await opts.onProgress?.(this.healthStatus());
|
|
49359
|
-
|
|
49612
|
+
for (const done of acknowledge) {
|
|
49613
|
+
this.progressWaiters.delete(done);
|
|
49614
|
+
done();
|
|
49615
|
+
}
|
|
49616
|
+
if (failures > 0 && failures <= supervisor2.retries) {
|
|
49360
49617
|
await supervisor2.retryDelay(failures, opts.signal, wakesBefore);
|
|
49361
|
-
|
|
49362
|
-
|
|
49363
|
-
|
|
49618
|
+
discover = true;
|
|
49619
|
+
} else {
|
|
49620
|
+
failures = 0;
|
|
49364
49621
|
await this.waitForDiscovery(opts.signal);
|
|
49622
|
+
discover = this.pendingDiscovery;
|
|
49365
49623
|
}
|
|
49366
49624
|
}
|
|
49367
49625
|
return "aborted";
|
|
49368
49626
|
} finally {
|
|
49627
|
+
for (const done of this.progressWaiters)
|
|
49628
|
+
done();
|
|
49629
|
+
this.progressWaiters.clear();
|
|
49369
49630
|
opts.signal?.removeEventListener("abort", stop);
|
|
49370
49631
|
await this.roomRuntime.shutdown();
|
|
49371
49632
|
}
|
|
@@ -49374,10 +49635,10 @@ var ThinDaemonCore = class {
|
|
|
49374
49635
|
|
|
49375
49636
|
// apps/body/dist/force-update-journal.js
|
|
49376
49637
|
import { mkdirSync as mkdirSync5, readFileSync as readFileSync11, renameSync as renameSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
49377
|
-
import { resolve as
|
|
49638
|
+
import { resolve as resolve44 } from "node:path";
|
|
49378
49639
|
var NAME = "force-update-interruptions.json";
|
|
49379
49640
|
function pathFor(runtimeDir) {
|
|
49380
|
-
return
|
|
49641
|
+
return resolve44(runtimeDir, NAME);
|
|
49381
49642
|
}
|
|
49382
49643
|
function read(runtimeDir) {
|
|
49383
49644
|
try {
|
|
@@ -49455,17 +49716,17 @@ function staleGeneration(error) {
|
|
|
49455
49716
|
init_launchd();
|
|
49456
49717
|
init_systemd();
|
|
49457
49718
|
import { mkdir as mkdir29, rename as rename12 } from "node:fs/promises";
|
|
49458
|
-
import { dirname as dirname29, resolve as
|
|
49719
|
+
import { dirname as dirname29, resolve as resolve45 } from "node:path";
|
|
49459
49720
|
async function retireRemovedAgent(runtime, options = {}) {
|
|
49460
|
-
const deletedRoot =
|
|
49461
|
-
const target =
|
|
49721
|
+
const deletedRoot = resolve45(runtime.supervisorRoot, "beeline", "deleted-runtimes");
|
|
49722
|
+
const target = resolve45(deletedRoot, `${runtime.agent.publicKey}-${Date.now()}`);
|
|
49462
49723
|
return relocateAgentRuntime(runtime, target, {
|
|
49463
49724
|
...options.run ? { run: options.run } : {}
|
|
49464
49725
|
});
|
|
49465
49726
|
}
|
|
49466
49727
|
async function relocateAgentRuntime(runtime, target, options = {}) {
|
|
49467
49728
|
const source = runtimeDirectory(runtime.supervisorRoot, runtime.agent.publicKey);
|
|
49468
|
-
const destination =
|
|
49729
|
+
const destination = resolve45(target);
|
|
49469
49730
|
if (destination === source || destination.startsWith(`${source}/`)) {
|
|
49470
49731
|
throw new Error("agent runtime destination must be outside the live runtime");
|
|
49471
49732
|
}
|
|
@@ -49487,8 +49748,8 @@ async function relocateAgentRuntime(runtime, target, options = {}) {
|
|
|
49487
49748
|
init_systemd();
|
|
49488
49749
|
|
|
49489
49750
|
// apps/body/dist/release-status.js
|
|
49490
|
-
import { readFile as
|
|
49491
|
-
import { resolve as
|
|
49751
|
+
import { readFile as readFile34, readdir as readdir15, rename as rename13, writeFile as writeFile22 } from "node:fs/promises";
|
|
49752
|
+
import { resolve as resolve46 } from "node:path";
|
|
49492
49753
|
var DAEMON_RELEASE_STATUS_FILE = "release-status.json";
|
|
49493
49754
|
var RELEASE_VERSION = /^v\d+\.\d+\.\d+$/;
|
|
49494
49755
|
var SOURCE_SHA = /^[0-9a-f]{7,64}$/;
|
|
@@ -49505,7 +49766,7 @@ async function writeDaemonReleaseStatus(runtimeDir, agentPubkey, identity, optio
|
|
|
49505
49766
|
pid: options.pid ?? process.pid,
|
|
49506
49767
|
readyAt: (options.now?.() ?? /* @__PURE__ */ new Date()).toISOString()
|
|
49507
49768
|
};
|
|
49508
|
-
const target =
|
|
49769
|
+
const target = resolve46(runtimeDir, DAEMON_RELEASE_STATUS_FILE);
|
|
49509
49770
|
const temporary = `${target}.${status.pid}.tmp`;
|
|
49510
49771
|
await writeFile22(temporary, `${JSON.stringify(status, null, 2)}
|
|
49511
49772
|
`, { mode: 384 });
|
|
@@ -49514,8 +49775,8 @@ async function writeDaemonReleaseStatus(runtimeDir, agentPubkey, identity, optio
|
|
|
49514
49775
|
}
|
|
49515
49776
|
|
|
49516
49777
|
// apps/body/dist/scratch-sweep.js
|
|
49517
|
-
import { lstat as
|
|
49518
|
-
import { resolve as
|
|
49778
|
+
import { lstat as lstat11, readdir as readdir16, rmdir as rmdir3, unlink as unlink9 } from "node:fs/promises";
|
|
49779
|
+
import { resolve as resolve47 } from "node:path";
|
|
49519
49780
|
var DEFAULT_SCRATCH_TTL_HOURS = 72;
|
|
49520
49781
|
var NEVER_SWEEP_SUBDIR_NAMES = new Set(HOME_SUBDIRS.filter((name) => name !== "tmp"));
|
|
49521
49782
|
function scratchTtlMs(env = process.env) {
|
|
@@ -49524,10 +49785,10 @@ function scratchTtlMs(env = process.env) {
|
|
|
49524
49785
|
return (Number.isFinite(hours) && hours > 0 ? hours : DEFAULT_SCRATCH_TTL_HOURS) * 60 * 60 * 1e3;
|
|
49525
49786
|
}
|
|
49526
49787
|
async function discoverAttachScratchRoots(runtimeDir) {
|
|
49527
|
-
const roomsDir =
|
|
49788
|
+
const roomsDir = resolve47(runtimeDir, "rooms");
|
|
49528
49789
|
let entries;
|
|
49529
49790
|
try {
|
|
49530
|
-
entries = await
|
|
49791
|
+
entries = await readdir16(roomsDir, { withFileTypes: true });
|
|
49531
49792
|
} catch {
|
|
49532
49793
|
return [];
|
|
49533
49794
|
}
|
|
@@ -49535,8 +49796,8 @@ async function discoverAttachScratchRoots(runtimeDir) {
|
|
|
49535
49796
|
for (const entry of entries) {
|
|
49536
49797
|
if (!entry.isDirectory())
|
|
49537
49798
|
continue;
|
|
49538
|
-
const home =
|
|
49539
|
-
const stats = await
|
|
49799
|
+
const home = resolve47(roomsDir, entry.name, "agent-home");
|
|
49800
|
+
const stats = await lstat11(home).catch(() => void 0);
|
|
49540
49801
|
if (stats?.isDirectory())
|
|
49541
49802
|
roots.push(home);
|
|
49542
49803
|
}
|
|
@@ -49545,7 +49806,7 @@ async function discoverAttachScratchRoots(runtimeDir) {
|
|
|
49545
49806
|
async function removeStaleFiles(dir, cutoffMs, protectNamesHere) {
|
|
49546
49807
|
let entries;
|
|
49547
49808
|
try {
|
|
49548
|
-
entries = await
|
|
49809
|
+
entries = await readdir16(dir, { withFileTypes: true });
|
|
49549
49810
|
} catch {
|
|
49550
49811
|
return { removedFiles: 0, removedBytes: 0 };
|
|
49551
49812
|
}
|
|
@@ -49554,15 +49815,15 @@ async function removeStaleFiles(dir, cutoffMs, protectNamesHere) {
|
|
|
49554
49815
|
for (const entry of entries) {
|
|
49555
49816
|
if (protectNamesHere && NEVER_SWEEP_SUBDIR_NAMES.has(entry.name))
|
|
49556
49817
|
continue;
|
|
49557
|
-
const path =
|
|
49558
|
-
const stats = await
|
|
49818
|
+
const path = resolve47(dir, entry.name);
|
|
49819
|
+
const stats = await lstat11(path).catch(() => void 0);
|
|
49559
49820
|
if (!stats || stats.isSymbolicLink())
|
|
49560
49821
|
continue;
|
|
49561
49822
|
if (stats.isDirectory()) {
|
|
49562
49823
|
const nested = await removeStaleFiles(path, cutoffMs, false);
|
|
49563
49824
|
removedFiles += nested.removedFiles;
|
|
49564
49825
|
removedBytes += nested.removedBytes;
|
|
49565
|
-
const remaining = await
|
|
49826
|
+
const remaining = await readdir16(path).catch(() => void 0);
|
|
49566
49827
|
if (remaining && remaining.length === 0)
|
|
49567
49828
|
await rmdir3(path).catch(() => void 0);
|
|
49568
49829
|
continue;
|
|
@@ -49580,7 +49841,7 @@ async function sweepAttachScratchRoots(roots, ttlMs, now2 = Date.now()) {
|
|
|
49580
49841
|
let removedFiles = 0;
|
|
49581
49842
|
let removedBytes = 0;
|
|
49582
49843
|
for (const root of roots) {
|
|
49583
|
-
const stats = await
|
|
49844
|
+
const stats = await lstat11(root).catch(() => void 0);
|
|
49584
49845
|
if (!stats?.isDirectory())
|
|
49585
49846
|
continue;
|
|
49586
49847
|
const result = await removeStaleFiles(root, cutoffMs, true);
|
|
@@ -49624,7 +49885,7 @@ async function runAgentRuntime(configPath, host, signal) {
|
|
|
49624
49885
|
BUZZ_DEV_MCP_BIN: runtime.mcpBinary
|
|
49625
49886
|
};
|
|
49626
49887
|
const config = loadBodyConfig({
|
|
49627
|
-
workspaceRoot:
|
|
49888
|
+
workspaceRoot: resolve48(runtimeDir, "workspace"),
|
|
49628
49889
|
llmEnvFile: runtime.llmEnvFile,
|
|
49629
49890
|
env,
|
|
49630
49891
|
agent
|
|
@@ -49759,7 +50020,6 @@ async function runAgentRuntime(configPath, host, signal) {
|
|
|
49759
50020
|
host.notifyReleaseAvailable(`${version}:${sha}`);
|
|
49760
50021
|
void host.tickUpdate();
|
|
49761
50022
|
});
|
|
49762
|
-
daemonApi.onLiveOpen(() => void host.tickUpdate());
|
|
49763
50023
|
core.setInteractiveIdleListener(() => {
|
|
49764
50024
|
void host.tickUpdate();
|
|
49765
50025
|
});
|
|
@@ -49891,26 +50151,26 @@ init_squire_host();
|
|
|
49891
50151
|
|
|
49892
50152
|
// apps/body/dist/host-disk-retention.js
|
|
49893
50153
|
import { execFile as execFile20 } from "node:child_process";
|
|
49894
|
-
import { lstat as
|
|
49895
|
-
import { join as join23, resolve as
|
|
50154
|
+
import { lstat as lstat12, readdir as readdir17, rm as rm21 } from "node:fs/promises";
|
|
50155
|
+
import { join as join23, resolve as resolve49 } from "node:path";
|
|
49896
50156
|
import { promisify as promisify14 } from "node:util";
|
|
49897
50157
|
var execFileAsync14 = promisify14(execFile20);
|
|
49898
50158
|
var DELETED_RUNTIME_TTL_MS = 30 * 24 * 60 * 6e4;
|
|
49899
50159
|
var REPOSITORY_CACHE_TTL_MS = 30 * 24 * 60 * 6e4;
|
|
49900
50160
|
async function pruneDeletedRuntimes(supervisorRoot2, now2 = Date.now()) {
|
|
49901
|
-
const root =
|
|
50161
|
+
const root = resolve49(supervisorRoot2, "beeline", "deleted-runtimes");
|
|
49902
50162
|
const removed = [];
|
|
49903
|
-
for (const entry of await
|
|
50163
|
+
for (const entry of await readdir17(root, { withFileTypes: true }).catch(() => [])) {
|
|
49904
50164
|
const match = /^([a-f0-9]{64})-(\d{13})$/.exec(entry.name);
|
|
49905
50165
|
if (!entry.isDirectory() || !match || now2 - Number(match[2]) < DELETED_RUNTIME_TTL_MS)
|
|
49906
50166
|
continue;
|
|
49907
50167
|
const path = join23(root, entry.name);
|
|
49908
|
-
if (!(await
|
|
50168
|
+
if (!(await lstat12(path)).isDirectory())
|
|
49909
50169
|
continue;
|
|
49910
|
-
const rooms =
|
|
50170
|
+
const rooms = resolve49(path, "rooms");
|
|
49911
50171
|
let retainsHome = false;
|
|
49912
|
-
for (const room of await
|
|
49913
|
-
const home = await
|
|
50172
|
+
for (const room of await readdir17(rooms).catch(() => [])) {
|
|
50173
|
+
const home = await lstat12(resolve49(rooms, room, "agent-home")).catch(() => void 0);
|
|
49914
50174
|
if (home) {
|
|
49915
50175
|
retainsHome = true;
|
|
49916
50176
|
break;
|
|
@@ -49924,19 +50184,19 @@ async function pruneDeletedRuntimes(supervisorRoot2, now2 = Date.now()) {
|
|
|
49924
50184
|
return removed;
|
|
49925
50185
|
}
|
|
49926
50186
|
async function pruneRepositoryCaches(supervisorRoot2, now2 = Date.now()) {
|
|
49927
|
-
const root =
|
|
50187
|
+
const root = resolve49(supervisorRoot2, "beeline", "repositories");
|
|
49928
50188
|
const removed = [];
|
|
49929
|
-
for (const entry of await
|
|
50189
|
+
for (const entry of await readdir17(root, { withFileTypes: true }).catch(() => [])) {
|
|
49930
50190
|
if (!entry.isDirectory() || !/^[a-f0-9]{24}\.git$/.test(entry.name))
|
|
49931
50191
|
continue;
|
|
49932
50192
|
const path = join23(root, entry.name);
|
|
49933
|
-
const info = await
|
|
50193
|
+
const info = await lstat12(path);
|
|
49934
50194
|
if (!info.isDirectory() || now2 - info.mtimeMs < REPOSITORY_CACHE_TTL_MS)
|
|
49935
50195
|
continue;
|
|
49936
50196
|
const listing = await execFileAsync14("git", [`--git-dir=${path}`, "worktree", "list", "--porcelain"]).then((result) => result.stdout, () => void 0);
|
|
49937
50197
|
if (listing === void 0)
|
|
49938
50198
|
continue;
|
|
49939
|
-
const attached = listing.split("\n").some((line) => line.startsWith("worktree ") &&
|
|
50199
|
+
const attached = listing.split("\n").some((line) => line.startsWith("worktree ") && resolve49(line.slice("worktree ".length)) !== path);
|
|
49940
50200
|
if (attached)
|
|
49941
50201
|
continue;
|
|
49942
50202
|
const refs = await execFileAsync14("git", [
|
|
@@ -50002,7 +50262,7 @@ async function runMachineHelper(options = {}) {
|
|
|
50002
50262
|
diskSweepRunning = true;
|
|
50003
50263
|
try {
|
|
50004
50264
|
const modelDue = now2 - lastModelSweepAt >= 60 * 6e4;
|
|
50005
|
-
const removed = modelDue ? await pruneSharedModelCache(
|
|
50265
|
+
const removed = modelDue ? await pruneSharedModelCache(resolve50(supervisorRoot2, "beeline", "model-cache")) : [];
|
|
50006
50266
|
if (modelDue)
|
|
50007
50267
|
lastModelSweepAt = now2;
|
|
50008
50268
|
if (now2 - lastRetentionSweepAt >= 24 * 60 * 6e4) {
|
|
@@ -50145,7 +50405,11 @@ async function runMachineHelper(options = {}) {
|
|
|
50145
50405
|
const machineKey = () => [...slots.values()].map((slot) => slot.agentId).sort()[0] ?? "helper";
|
|
50146
50406
|
if (layout) {
|
|
50147
50407
|
update = await ManagedUpdateHandoff.create(layout, Date.now, {
|
|
50148
|
-
env
|
|
50408
|
+
env,
|
|
50409
|
+
...options.runUpdateWorker ? { runUpdateWorker: options.runUpdateWorker } : {},
|
|
50410
|
+
onWorkerSettled: () => {
|
|
50411
|
+
void tickUpdate();
|
|
50412
|
+
}
|
|
50149
50413
|
});
|
|
50150
50414
|
}
|
|
50151
50415
|
const recoverManagedRestart = (error) => {
|
|
@@ -50191,7 +50455,13 @@ async function runMachineHelper(options = {}) {
|
|
|
50191
50455
|
machineLink: (baseUrl) => {
|
|
50192
50456
|
let link2 = links.get(baseUrl);
|
|
50193
50457
|
if (!link2) {
|
|
50194
|
-
link2 = new MachineLink({
|
|
50458
|
+
link2 = new MachineLink({
|
|
50459
|
+
baseUrl,
|
|
50460
|
+
onRegistered: () => {
|
|
50461
|
+
update?.reconcileOnConnect();
|
|
50462
|
+
void tickUpdate();
|
|
50463
|
+
}
|
|
50464
|
+
});
|
|
50195
50465
|
link2.setHelperIdentity({
|
|
50196
50466
|
releaseVersion: loadedReleaseIdentity?.version,
|
|
50197
50467
|
sourceSha: loadedReleaseIdentity?.commit
|
|
@@ -50318,7 +50588,12 @@ async function runMachineHelper(options = {}) {
|
|
|
50318
50588
|
void rescan().catch((error) => console.error("[helper] rescan failed:", error));
|
|
50319
50589
|
};
|
|
50320
50590
|
signals.on("SIGHUP", onHangup);
|
|
50321
|
-
const stopWatchdog = startLocalWatchdog(notifier, statusLine)
|
|
50591
|
+
const stopWatchdog = startLocalWatchdog(notifier, statusLine, async () => {
|
|
50592
|
+
if ([...slots.values()].some((slot) => slot.running && !slot.controller.signal.aborted && !hosted.has(slot.agentId)))
|
|
50593
|
+
return false;
|
|
50594
|
+
await Promise.all([...hosted.values()].map((agent) => agent.core.requestWorkLoopProgress()));
|
|
50595
|
+
return true;
|
|
50596
|
+
}, void 0, env);
|
|
50322
50597
|
try {
|
|
50323
50598
|
console.log(`[helper] hosting ${initial.length} agent(s) on one machine socket per server`);
|
|
50324
50599
|
for (const configPath of initial)
|
|
@@ -50404,10 +50679,10 @@ function sleep3(ms, signal) {
|
|
|
50404
50679
|
// apps/body/dist/android-emulator-lease.js
|
|
50405
50680
|
import { execFileSync, spawn as spawn14 } from "node:child_process";
|
|
50406
50681
|
import { randomUUID as randomUUID15 } from "node:crypto";
|
|
50407
|
-
import { cp as cp2, mkdir as mkdir31, open as open6, readFile as
|
|
50682
|
+
import { cp as cp2, mkdir as mkdir31, open as open6, readFile as readFile35, rm as rm22, stat as stat13, writeFile as writeFile24 } from "node:fs/promises";
|
|
50408
50683
|
import { createServer as createServer5 } from "node:net";
|
|
50409
50684
|
import { existsSync as existsSync11 } from "node:fs";
|
|
50410
|
-
import { resolve as
|
|
50685
|
+
import { resolve as resolve51 } from "node:path";
|
|
50411
50686
|
var FIRST_PORT = 5554;
|
|
50412
50687
|
var LAST_PORT = 5584;
|
|
50413
50688
|
var PORT_STEP = 4;
|
|
@@ -50420,7 +50695,7 @@ function processAlive(pid) {
|
|
|
50420
50695
|
}
|
|
50421
50696
|
}
|
|
50422
50697
|
async function processStart(pid) {
|
|
50423
|
-
const raw = await
|
|
50698
|
+
const raw = await readFile35(`/proc/${pid}/stat`, "utf8").catch(() => void 0);
|
|
50424
50699
|
if (raw)
|
|
50425
50700
|
return raw.slice(raw.lastIndexOf(")") + 2).split(" ")[19];
|
|
50426
50701
|
try {
|
|
@@ -50437,13 +50712,13 @@ async function portFree(port) {
|
|
|
50437
50712
|
});
|
|
50438
50713
|
}
|
|
50439
50714
|
async function leaseEmulator(root, privateRoot) {
|
|
50440
|
-
const absolute =
|
|
50715
|
+
const absolute = resolve51(root);
|
|
50441
50716
|
await Promise.all([
|
|
50442
50717
|
mkdir31(absolute, { recursive: true, mode: 448 }),
|
|
50443
50718
|
mkdir31(privateRoot, { recursive: true, mode: 448 })
|
|
50444
50719
|
]);
|
|
50445
50720
|
for (let port = FIRST_PORT; port <= LAST_PORT; port += PORT_STEP) {
|
|
50446
|
-
const marker =
|
|
50721
|
+
const marker = resolve51(absolute, `port-${port}.lease`);
|
|
50447
50722
|
let handle2;
|
|
50448
50723
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
50449
50724
|
try {
|
|
@@ -50452,7 +50727,7 @@ async function leaseEmulator(root, privateRoot) {
|
|
|
50452
50727
|
} catch (error) {
|
|
50453
50728
|
if (error.code !== "EEXIST")
|
|
50454
50729
|
throw error;
|
|
50455
|
-
const old = await
|
|
50730
|
+
const old = await readFile35(marker, "utf8").catch(() => "");
|
|
50456
50731
|
const [pidText, start] = old.split(":");
|
|
50457
50732
|
const pid = Number(pidText);
|
|
50458
50733
|
if (Number.isSafeInteger(pid) && pid > 0 && processAlive(pid)) {
|
|
@@ -50466,20 +50741,20 @@ async function leaseEmulator(root, privateRoot) {
|
|
|
50466
50741
|
if (!before || !await portFree(port) || !await portFree(port + 1) || !await portFree(port + 2))
|
|
50467
50742
|
break;
|
|
50468
50743
|
const after = await stat13(marker).catch(() => void 0);
|
|
50469
|
-
if (after && before.ino === after.ino && await
|
|
50744
|
+
if (after && before.ino === after.ino && await readFile35(marker, "utf8").catch(() => "") === old)
|
|
50470
50745
|
await rm22(marker, { force: true });
|
|
50471
50746
|
}
|
|
50472
50747
|
}
|
|
50473
50748
|
if (!handle2)
|
|
50474
50749
|
continue;
|
|
50475
|
-
const instance =
|
|
50750
|
+
const instance = resolve51(privateRoot, `instance-${randomUUID15()}`);
|
|
50476
50751
|
const ownership = `${process.pid}:${await processStart(process.pid)}:${randomUUID15()}:${instance}`;
|
|
50477
50752
|
try {
|
|
50478
50753
|
await handle2.writeFile(ownership);
|
|
50479
50754
|
await handle2.sync();
|
|
50480
50755
|
if (!await portFree(port) || !await portFree(port + 1) || !await portFree(port + 2)) {
|
|
50481
50756
|
await handle2.close();
|
|
50482
|
-
if (await
|
|
50757
|
+
if (await readFile35(marker, "utf8").catch(() => "") === ownership)
|
|
50483
50758
|
await rm22(marker, { force: true });
|
|
50484
50759
|
continue;
|
|
50485
50760
|
}
|
|
@@ -50490,14 +50765,14 @@ async function leaseEmulator(root, privateRoot) {
|
|
|
50490
50765
|
serial: `emulator-${port}`,
|
|
50491
50766
|
root: instance,
|
|
50492
50767
|
release: async () => {
|
|
50493
|
-
if (await
|
|
50768
|
+
if (await readFile35(marker, "utf8").catch(() => "") === ownership)
|
|
50494
50769
|
await rm22(marker, { force: true });
|
|
50495
50770
|
await rm22(instance, { recursive: true, force: true });
|
|
50496
50771
|
}
|
|
50497
50772
|
};
|
|
50498
50773
|
} catch (error) {
|
|
50499
50774
|
await handle2.close().catch(() => void 0);
|
|
50500
|
-
if (await
|
|
50775
|
+
if (await readFile35(marker, "utf8").catch(() => "") === ownership)
|
|
50501
50776
|
await rm22(marker, { force: true });
|
|
50502
50777
|
throw error;
|
|
50503
50778
|
}
|
|
@@ -50522,19 +50797,19 @@ async function runLeasedEmulator(args, env = process.env) {
|
|
|
50522
50797
|
if (env.ANDROID_EMULATOR_HOME)
|
|
50523
50798
|
await mkdir31(env.ANDROID_EMULATOR_HOME, { recursive: true, mode: 448 });
|
|
50524
50799
|
if (env.ANDROID_HOME) {
|
|
50525
|
-
const adb =
|
|
50800
|
+
const adb = resolve51(env.ANDROID_HOME, "platform-tools/adb");
|
|
50526
50801
|
if (existsSync11(adb))
|
|
50527
50802
|
execFileSync(adb, ["start-server"], { env, timeout: 15e3 });
|
|
50528
50803
|
}
|
|
50529
|
-
const original =
|
|
50530
|
-
const localAvdHome =
|
|
50531
|
-
const local =
|
|
50532
|
-
const data =
|
|
50804
|
+
const original = resolve51(baseAvdHome, `${avdName}.avd`);
|
|
50805
|
+
const localAvdHome = resolve51(lease.root, "avd");
|
|
50806
|
+
const local = resolve51(localAvdHome, `${avdName}.avd`);
|
|
50807
|
+
const data = resolve51(lease.root, "data");
|
|
50533
50808
|
await mkdir31(local, { recursive: true, mode: 448 });
|
|
50534
50809
|
await mkdir31(data, { recursive: true, mode: 448 });
|
|
50535
|
-
await cp2(
|
|
50536
|
-
const metadata = await
|
|
50537
|
-
await writeFile24(
|
|
50810
|
+
await cp2(resolve51(original, "config.ini"), resolve51(local, "config.ini"));
|
|
50811
|
+
const metadata = await readFile35(resolve51(baseAvdHome, `${avdName}.ini`), "utf8");
|
|
50812
|
+
await writeFile24(resolve51(localAvdHome, `${avdName}.ini`), metadata.replace(/^path\s*=.*$/m, `path=${local}`).replace(/^path\.rel\s*=.*\n?/m, ""), { mode: 384 });
|
|
50538
50813
|
const status = await new Promise((done, reject) => {
|
|
50539
50814
|
const child = spawn14(emulator, [...args.filter((arg) => arg !== "-read-only"), "-port", String(lease.port), "-datadir", data], {
|
|
50540
50815
|
env: { ...env, ANDROID_AVD_HOME: localAvdHome, ADB_EMU: "0" },
|
|
@@ -50651,7 +50926,7 @@ async function main() {
|
|
|
50651
50926
|
const roomId = roomFlag >= 0 ? args[roomFlag + 1] : void 0;
|
|
50652
50927
|
if (!configPath || !roomId)
|
|
50653
50928
|
throw new Error("corner-read-token requires --config and --room");
|
|
50654
|
-
const activated = await activateDaemonTransport(
|
|
50929
|
+
const activated = await activateDaemonTransport(resolve52(configPath));
|
|
50655
50930
|
if (!activated)
|
|
50656
50931
|
throw new Error("corner-read-token requires monolith transport");
|
|
50657
50932
|
const credential = await activated.client.execute("getRoomGitHubToken", { roomId });
|
|
@@ -50706,7 +50981,7 @@ async function main() {
|
|
|
50706
50981
|
}
|
|
50707
50982
|
if (!configPath && !args.includes("--machine"))
|
|
50708
50983
|
throw new Error("daemon requires --machine, or --config <runtime.json> for one agent");
|
|
50709
|
-
const { reason, lifecycle } = await runMachineHelper(configPath ? { configPaths: [
|
|
50984
|
+
const { reason, lifecycle } = await runMachineHelper(configPath ? { configPaths: [resolve52(configPath)] } : {});
|
|
50710
50985
|
daemonLifecycle = lifecycle;
|
|
50711
50986
|
lifecycle.exit(reason);
|
|
50712
50987
|
return;
|