@centralu/win32-x64 0.1.0-beta.58 → 0.1.0-beta.60
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.
|
@@ -2286,7 +2286,7 @@ var require_websocket = __commonJS({
|
|
|
2286
2286
|
var http = __require("http");
|
|
2287
2287
|
var net2 = __require("net");
|
|
2288
2288
|
var tls = __require("tls");
|
|
2289
|
-
var { randomBytes:
|
|
2289
|
+
var { randomBytes: randomBytes17, createHash: createHash16 } = __require("crypto");
|
|
2290
2290
|
var { Duplex, Readable: Readable2 } = __require("stream");
|
|
2291
2291
|
var { URL: URL2 } = __require("url");
|
|
2292
2292
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
@@ -2824,7 +2824,7 @@ var require_websocket = __commonJS({
|
|
|
2824
2824
|
}
|
|
2825
2825
|
}
|
|
2826
2826
|
const defaultPort = isSecure ? 443 : 80;
|
|
2827
|
-
const key =
|
|
2827
|
+
const key = randomBytes17(16).toString("base64");
|
|
2828
2828
|
const request = isSecure ? https.request : http.request;
|
|
2829
2829
|
const protocolSet = /* @__PURE__ */ new Set();
|
|
2830
2830
|
let perMessageDeflate;
|
|
@@ -2954,7 +2954,7 @@ var require_websocket = __commonJS({
|
|
|
2954
2954
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
2955
2955
|
return;
|
|
2956
2956
|
}
|
|
2957
|
-
const digest =
|
|
2957
|
+
const digest = createHash16("sha1").update(key + GUID).digest("base64");
|
|
2958
2958
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
2959
2959
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
2960
2960
|
return;
|
|
@@ -3323,7 +3323,7 @@ var require_websocket_server = __commonJS({
|
|
|
3323
3323
|
var EventEmitter3 = __require("events");
|
|
3324
3324
|
var http = __require("http");
|
|
3325
3325
|
var { Duplex } = __require("stream");
|
|
3326
|
-
var { createHash:
|
|
3326
|
+
var { createHash: createHash16 } = __require("crypto");
|
|
3327
3327
|
var extension2 = require_extension();
|
|
3328
3328
|
var PerMessageDeflate2 = require_permessage_deflate();
|
|
3329
3329
|
var subprotocol2 = require_subprotocol();
|
|
@@ -3630,7 +3630,7 @@ var require_websocket_server = __commonJS({
|
|
|
3630
3630
|
);
|
|
3631
3631
|
}
|
|
3632
3632
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
3633
|
-
const digest =
|
|
3633
|
+
const digest = createHash16("sha1").update(key + GUID).digest("base64");
|
|
3634
3634
|
const headers = [
|
|
3635
3635
|
"HTTP/1.1 101 Switching Protocols",
|
|
3636
3636
|
"Upgrade: websocket",
|
|
@@ -43040,13 +43040,13 @@ function refuse(message, io2 = realIo) {
|
|
|
43040
43040
|
|
|
43041
43041
|
// packages/agent-host/src/main.ts
|
|
43042
43042
|
import { parseArgs } from "node:util";
|
|
43043
|
-
import { randomBytes as
|
|
43043
|
+
import { randomBytes as randomBytes16 } from "node:crypto";
|
|
43044
43044
|
import { hostname as hostname5 } from "node:os";
|
|
43045
43045
|
import { dirname as dirname27, join as join58 } from "node:path";
|
|
43046
43046
|
import { mkdirSync as mkdirSync21, readFileSync as readFileSync27, writeSync as writeSync4 } from "node:fs";
|
|
43047
43047
|
|
|
43048
43048
|
// packages/protocol/src/version.generated.ts
|
|
43049
|
-
var APP_VERSION = "0.1.0-beta.
|
|
43049
|
+
var APP_VERSION = "0.1.0-beta.60";
|
|
43050
43050
|
|
|
43051
43051
|
// packages/protocol/src/brand.ts
|
|
43052
43052
|
var APP_NAME = "Centralu";
|
|
@@ -63343,12 +63343,13 @@ function errorMessage(e) {
|
|
|
63343
63343
|
}
|
|
63344
63344
|
|
|
63345
63345
|
// packages/protocol/src/theme.ts
|
|
63346
|
-
var defs = (group, kind, list2) => list2.map(([key, label]) => ({
|
|
63346
|
+
var defs = (group, kind, list2) => list2.map(([key, label, follows]) => ({
|
|
63347
63347
|
key,
|
|
63348
63348
|
cssVar: kind === "color" ? `--color-${key}` : `--${key}`,
|
|
63349
63349
|
label,
|
|
63350
63350
|
group,
|
|
63351
|
-
kind
|
|
63351
|
+
kind,
|
|
63352
|
+
...follows ? { follows } : {}
|
|
63352
63353
|
}));
|
|
63353
63354
|
var THEME_TOKENS = [
|
|
63354
63355
|
...defs("Surfaces", "color", [
|
|
@@ -63363,7 +63364,11 @@ var THEME_TOKENS = [
|
|
|
63363
63364
|
]),
|
|
63364
63365
|
...defs("Lines", "color", [
|
|
63365
63366
|
["line", "Line"],
|
|
63366
|
-
["line-
|
|
63367
|
+
["line-chrome", "Window line: sidebar, top bar, panel headers", "line"],
|
|
63368
|
+
["line-strong", "Strong line"],
|
|
63369
|
+
["line-panel", "Resting panel edge", "line-strong"],
|
|
63370
|
+
["line-answering", "Answering panel edge", "ink-muted"],
|
|
63371
|
+
["line-bubble-mine", "Your message bubble edge", "line-strong"]
|
|
63367
63372
|
]),
|
|
63368
63373
|
...defs("Ink", "color", [
|
|
63369
63374
|
["ink-signal", "Signal: waiting for you"],
|
|
@@ -63454,8 +63459,25 @@ var THEME_PRESETS = [
|
|
|
63454
63459
|
{ id: "dark", name: "Dark", base: "dark" },
|
|
63455
63460
|
{ id: "light", name: "Light", base: "light" },
|
|
63456
63461
|
{ id: "hc-dark", name: "High contrast dark", base: "dark" },
|
|
63457
|
-
{ id: "hc-light", name: "High contrast light", base: "light" }
|
|
63462
|
+
{ id: "hc-light", name: "High contrast light", base: "light" },
|
|
63463
|
+
{ id: "graphite", name: "Graphite", base: "dark" }
|
|
63458
63464
|
];
|
|
63465
|
+
function themeSlug(name) {
|
|
63466
|
+
return name.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48) || "theme";
|
|
63467
|
+
}
|
|
63468
|
+
function isPresetThemeId(id3) {
|
|
63469
|
+
return THEME_PRESETS.some((p) => p.id === id3);
|
|
63470
|
+
}
|
|
63471
|
+
function presetIdRefusal(id3) {
|
|
63472
|
+
return `${id3} is a preset's id, and a theme file under it would hide the preset. Leave the id out and the file is filed under another one.`;
|
|
63473
|
+
}
|
|
63474
|
+
function freeThemeId(name, isTaken) {
|
|
63475
|
+
const base2 = themeSlug(name);
|
|
63476
|
+
for (let n = 1; ; n++) {
|
|
63477
|
+
const id3 = n === 1 ? base2 : `${base2}-${n}`;
|
|
63478
|
+
if (!isTaken(id3) && !isPresetThemeId(id3)) return id3;
|
|
63479
|
+
}
|
|
63480
|
+
}
|
|
63459
63481
|
var ThemeFileContent = external_exports.object({
|
|
63460
63482
|
name: external_exports.string().min(1).max(80),
|
|
63461
63483
|
base: external_exports.enum(["dark", "light"]),
|
|
@@ -63474,6 +63496,13 @@ var ThemeFileEntry = external_exports.object({
|
|
|
63474
63496
|
/** True when the file could not be read as a theme at all (not JSON, not an object) */
|
|
63475
63497
|
broken: external_exports.boolean()
|
|
63476
63498
|
});
|
|
63499
|
+
function pickableThemes(files2) {
|
|
63500
|
+
const usable = files2.filter((f) => !f.broken);
|
|
63501
|
+
return [
|
|
63502
|
+
...THEME_PRESETS.filter((p) => !usable.some((f) => f.id === p.id)).map((p) => ({ id: p.id, name: p.name, base: p.base, file: false })),
|
|
63503
|
+
...usable.map((f) => ({ id: f.id, name: f.name, base: f.base, file: true }))
|
|
63504
|
+
];
|
|
63505
|
+
}
|
|
63477
63506
|
var THEME_SCHEMA_FILE = "theme.schema.json";
|
|
63478
63507
|
var THEME_SCHEMA_REF = `./${THEME_SCHEMA_FILE}`;
|
|
63479
63508
|
function parseThemeFile(id3, path2, text3) {
|
|
@@ -63559,7 +63588,7 @@ function themeFileJsonSchema() {
|
|
|
63559
63588
|
properties: Object.fromEntries([
|
|
63560
63589
|
...THEME_TOKENS.map((t) => [
|
|
63561
63590
|
t.key,
|
|
63562
|
-
{ type: "string", maxLength: 400, description: `${t.group}: ${t.label}. ${kindText[t.kind]}` }
|
|
63591
|
+
{ type: "string", maxLength: 400, description: `${t.group}: ${t.label}. ${kindText[t.kind]}${t.follows ? ` Left out, it follows "${t.follows}".` : ""}` }
|
|
63563
63592
|
]),
|
|
63564
63593
|
...RETIRED_THEME_TOKENS.map((key) => [
|
|
63565
63594
|
key,
|
|
@@ -63948,6 +63977,7 @@ function parseClientFrame(raw) {
|
|
|
63948
63977
|
// packages/protocol/src/app-id.ts
|
|
63949
63978
|
var RESERVED_NAME_PREFIX = "centralu";
|
|
63950
63979
|
var APP_SERVER_PREFIX = "app-";
|
|
63980
|
+
var appServerName = (appId) => `${APP_SERVER_PREFIX}${appId}`;
|
|
63951
63981
|
var RESERVED_APP_IDS = ["control"];
|
|
63952
63982
|
var APP_ID_MAX_LENGTH = 32;
|
|
63953
63983
|
var NAME_SHAPE = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
@@ -63963,11 +63993,25 @@ function newAppIdProblem(id3, reservedIds = RESERVED_APP_IDS) {
|
|
|
63963
63993
|
if (reservedIds.includes(id3)) return "builtin";
|
|
63964
63994
|
return null;
|
|
63965
63995
|
}
|
|
63996
|
+
function appIdProblemText(id3, problem3) {
|
|
63997
|
+
if (problem3 === "builtin") return `"${id3}" is reserved. Pick another app id.`;
|
|
63998
|
+
const why2 = {
|
|
63999
|
+
shape: `an app id is lowercase letters, digits and hyphens (up to ${APP_ID_MAX_LENGTH}), starting with a letter or digit, with no underscores ("__" separates names in a session's tool names)`,
|
|
64000
|
+
reserved: `ids starting with "${RESERVED_NAME_PREFIX}" belong to Centralu itself`,
|
|
64001
|
+
"server-prefix": `ids starting with "${APP_SERVER_PREFIX}" are how apps attach to sessions`
|
|
64002
|
+
};
|
|
64003
|
+
return `"${id3}" cannot be an app id: ${why2[problem3]}. Pick another.`;
|
|
64004
|
+
}
|
|
63966
64005
|
|
|
63967
64006
|
// packages/protocol/src/app-key.ts
|
|
63968
64007
|
var USER_APP_SCOPE = "_user";
|
|
63969
|
-
function appKeyOf(
|
|
63970
|
-
|
|
64008
|
+
function appKeyOf(a, appId, machine) {
|
|
64009
|
+
const ref = typeof a === "object" && a !== null ? a : { projectId: a, appId: appId ?? "", machine };
|
|
64010
|
+
return ref.machine && ref.projectId == null ? `${ref.machine}:${USER_APP_SCOPE}/${ref.appId}` : `${ref.projectId ?? USER_APP_SCOPE}/${ref.appId}`;
|
|
64011
|
+
}
|
|
64012
|
+
function sameApp(a, b2) {
|
|
64013
|
+
if (a.appId !== b2.appId || (a.projectId ?? null) !== (b2.projectId ?? null)) return false;
|
|
64014
|
+
return a.projectId != null || (a.machine ?? null) === (b2.machine ?? null);
|
|
63971
64015
|
}
|
|
63972
64016
|
function appLabel(ref) {
|
|
63973
64017
|
return `${ref.projectId === null ? "user" : ref.projectId.slice(0, 8)}/${ref.appId}`;
|
|
@@ -64061,6 +64105,55 @@ function centraluServer(server2) {
|
|
|
64061
64105
|
return null;
|
|
64062
64106
|
}
|
|
64063
64107
|
|
|
64108
|
+
// packages/protocol/src/call-budget.ts
|
|
64109
|
+
var HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
64110
|
+
var DEFAULT_CALL_BUDGET_MS = 3e4;
|
|
64111
|
+
var GIT_WRITE_TIMEOUT_MS = 10 * 6e4;
|
|
64112
|
+
var APP_CAPABILITY_QUESTION_MS = 5 * 6e4;
|
|
64113
|
+
var APP_CALL_TIMEOUT_MS = 10 * 6e4;
|
|
64114
|
+
var LONG_CALL_BUDGET_MS = 18e4;
|
|
64115
|
+
var LONG_CALLS = /* @__PURE__ */ new Set([
|
|
64116
|
+
"agents.resumeSession",
|
|
64117
|
+
// An explicit wake-up
|
|
64118
|
+
"agents.send",
|
|
64119
|
+
// If the session is asleep, revives it first, then sends — pays the same cost
|
|
64120
|
+
"agents.createSession",
|
|
64121
|
+
// When picking up a previous conversation via resumeExternalId
|
|
64122
|
+
"agents.restartSession",
|
|
64123
|
+
// Swaps out the process and revives it again
|
|
64124
|
+
"agents.exportHandoffRecord",
|
|
64125
|
+
// Can scan a rollout hundreds of MB in size (#78)
|
|
64126
|
+
/*
|
|
64127
|
+
* Calls that end in a revival (#164) — while these were missing here, the host would apply and restart on a large
|
|
64128
|
+
* conversation, but the screen showed "RPC timed out" (reading what succeeded as a failure). Add a new RPC that ends
|
|
64129
|
+
* in a revival here too.
|
|
64130
|
+
*/
|
|
64131
|
+
"agents.updateSettings",
|
|
64132
|
+
// Swaps out the process if a resting session's settings change (restartSession)
|
|
64133
|
+
"agents.forkConversation",
|
|
64134
|
+
// Revives as a forked copy
|
|
64135
|
+
"machines.update",
|
|
64136
|
+
// Installs beside and waits for the sessions there to finish (#1399); a wait that outlasts it is the row's to show
|
|
64137
|
+
"agents.resolveMcpProposal",
|
|
64138
|
+
// Restarts the Assistant on approval
|
|
64139
|
+
"agents.resolveSkillProposal",
|
|
64140
|
+
// Same
|
|
64141
|
+
"agents.deleteOrchestratorSkill",
|
|
64142
|
+
// Same
|
|
64143
|
+
"agents.deleteAssistantSkill",
|
|
64144
|
+
// Same
|
|
64145
|
+
// A new project can be a clone (#515), which takes as long as the repository does; past this budget the screen says it is still cloning
|
|
64146
|
+
"projects.create"
|
|
64147
|
+
]);
|
|
64148
|
+
var GIT_WRITE_BUDGET_MS = GIT_WRITE_TIMEOUT_MS + 6e4;
|
|
64149
|
+
var GIT_WRITE_CALLS = /* @__PURE__ */ new Set(["git.stage", "git.commit", "git.checkout", "git.push"]);
|
|
64150
|
+
var APP_CALL_BUDGET_MS = APP_CAPABILITY_QUESTION_MS + APP_CALL_TIMEOUT_MS;
|
|
64151
|
+
function callBudgetMs(method) {
|
|
64152
|
+
if (method === "apps.invoke") return APP_CALL_BUDGET_MS;
|
|
64153
|
+
if (GIT_WRITE_CALLS.has(method)) return GIT_WRITE_BUDGET_MS;
|
|
64154
|
+
return LONG_CALLS.has(method) ? LONG_CALL_BUDGET_MS : DEFAULT_CALL_BUDGET_MS;
|
|
64155
|
+
}
|
|
64156
|
+
|
|
64064
64157
|
// packages/protocol/src/handoff.ts
|
|
64065
64158
|
function handoffPrompt() {
|
|
64066
64159
|
return `You are about to be replaced by a fresh session that starts with no memory of this conversation. Write a handoff note for your successor. Your final message in this turn is the note: the app saves that message to a file and hands the file to your successor. Do not write the note to a file yourself, and do not add a preamble or a closing line around it \u2014 whatever your final message says is the note.
|
|
@@ -65270,15 +65363,15 @@ function tableReader(start3 = startServer) {
|
|
|
65270
65363
|
c.stderr.resume();
|
|
65271
65364
|
c.stdin.on("error", () => {
|
|
65272
65365
|
});
|
|
65273
|
-
const
|
|
65366
|
+
const gone2 = (e) => {
|
|
65274
65367
|
if (child !== c) return;
|
|
65275
65368
|
child = null;
|
|
65276
65369
|
const w = waiting;
|
|
65277
65370
|
waiting = null;
|
|
65278
65371
|
w?.reject(e);
|
|
65279
65372
|
};
|
|
65280
|
-
c.on("error",
|
|
65281
|
-
c.on("exit", (code2) =>
|
|
65373
|
+
c.on("error", gone2);
|
|
65374
|
+
c.on("exit", (code2) => gone2(new Error(`the process table reader ended (${code2})`)));
|
|
65282
65375
|
return c;
|
|
65283
65376
|
}
|
|
65284
65377
|
function readOnce(timeoutMs) {
|
|
@@ -65560,8 +65653,8 @@ function orphansOf(rows3, root3) {
|
|
|
65560
65653
|
return found;
|
|
65561
65654
|
}
|
|
65562
65655
|
var runFile = promisify(execFile);
|
|
65563
|
-
var leftoverOs = (run2, table = () => void 0) =>
|
|
65564
|
-
listProcesses
|
|
65656
|
+
var leftoverOs = (run2, table = () => void 0, alive2 = pidAlive) => {
|
|
65657
|
+
const listProcesses = async (timeoutMs = 6e4) => {
|
|
65565
65658
|
const warm = table();
|
|
65566
65659
|
if (warm) {
|
|
65567
65660
|
try {
|
|
@@ -65572,12 +65665,36 @@ var leftoverOs = (run2, table = () => void 0) => ({
|
|
|
65572
65665
|
}
|
|
65573
65666
|
const { stdout } = await run2(powershell(), [...POWERSHELL_ARGS, READ_ONCE], { timeout: timeoutMs, windowsHide: true });
|
|
65574
65667
|
return parseWinProcs(stdout);
|
|
65575
|
-
}
|
|
65576
|
-
|
|
65577
|
-
|
|
65578
|
-
|
|
65668
|
+
};
|
|
65669
|
+
return {
|
|
65670
|
+
listProcesses,
|
|
65671
|
+
// Asynchronous, so a tree of many processes does not hold the host's thread for each taskkill (about 40 ms each)
|
|
65672
|
+
taskkill: async (pid, alone = false, created) => {
|
|
65673
|
+
if (!alive2(pid)) throw gone(pid);
|
|
65674
|
+
if (created !== void 0 && !(await listProcesses(TASKKILL_MS)).some((r) => r.pid === pid && r.created === created)) throw gone(pid);
|
|
65675
|
+
try {
|
|
65676
|
+
await run2(systemTool2(["taskkill.exe"]), ["/PID", String(pid), ...alone ? [] : ["/T"], "/F"], { timeout: TASKKILL_MS, windowsHide: true });
|
|
65677
|
+
} catch (e) {
|
|
65678
|
+
if (!alive2(pid)) throw gone(pid);
|
|
65679
|
+
throw e;
|
|
65680
|
+
}
|
|
65681
|
+
}
|
|
65682
|
+
};
|
|
65683
|
+
};
|
|
65684
|
+
function pidAlive(pid) {
|
|
65685
|
+
try {
|
|
65686
|
+
process.kill(pid, 0);
|
|
65687
|
+
return true;
|
|
65688
|
+
} catch (e) {
|
|
65689
|
+
return errnoCode(e) === "EPERM";
|
|
65579
65690
|
}
|
|
65580
|
-
}
|
|
65691
|
+
}
|
|
65692
|
+
var ProcessGone = class extends Error {
|
|
65693
|
+
constructor(pid) {
|
|
65694
|
+
super(`process ${pid} is already gone`);
|
|
65695
|
+
}
|
|
65696
|
+
};
|
|
65697
|
+
var gone = (pid) => new ProcessGone(pid);
|
|
65581
65698
|
var warmTable;
|
|
65582
65699
|
var REAL_LEFTOVER_OS = leftoverOs(runFile, () => warmTable);
|
|
65583
65700
|
function warmProcessTable(platform = process.platform) {
|
|
@@ -65660,9 +65777,10 @@ async function endInOrder(found, by, os2) {
|
|
|
65660
65777
|
for (const r of found) {
|
|
65661
65778
|
if (r.pid === process.pid) continue;
|
|
65662
65779
|
try {
|
|
65663
|
-
await os2.taskkill(r.pid, parents.has(r.pid));
|
|
65780
|
+
await os2.taskkill(r.pid, parents.has(r.pid), r.created);
|
|
65664
65781
|
ended2.push(r.pid);
|
|
65665
65782
|
} catch (e) {
|
|
65783
|
+
if (e instanceof ProcessGone) continue;
|
|
65666
65784
|
const status = typeof e === "object" && e !== null ? "status" in e ? e.status : "code" in e ? e.code : void 0 : void 0;
|
|
65667
65785
|
if (status !== 128) console.error(`[agent-host] process ${r.pid}, left running by ${by}, could not be ended (status ${String(status)}: ${e instanceof Error ? e.message.replace(/\s+/g, " ").trim() : "unknown error"})`);
|
|
65668
65786
|
}
|
|
@@ -66131,7 +66249,13 @@ async function copyTreeAsync(f, from, to, o, family2, P5) {
|
|
|
66131
66249
|
|
|
66132
66250
|
// packages/agent-host/src/timing.ts
|
|
66133
66251
|
function durationText(ms3) {
|
|
66134
|
-
|
|
66252
|
+
const unit = (n, one2) => `${n} ${one2}${n === 1 ? "" : "s"}`;
|
|
66253
|
+
if (ms3 === 0) return "0 seconds";
|
|
66254
|
+
if (ms3 < 1e3) return unit(ms3, "millisecond");
|
|
66255
|
+
const s = Math.round(ms3 / 1e3);
|
|
66256
|
+
if (s <= 180 && (s < 60 || s % 60 !== 0)) return unit(s, "second");
|
|
66257
|
+
const min = Math.round(s / 60);
|
|
66258
|
+
return min <= 180 ? unit(min, "minute") : unit(Math.round(min / 60), "hour");
|
|
66135
66259
|
}
|
|
66136
66260
|
function sleepSync(ms3) {
|
|
66137
66261
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms3);
|
|
@@ -66162,7 +66286,7 @@ function withTimeout(p, ms3, label = "A call") {
|
|
|
66162
66286
|
return Promise.race([
|
|
66163
66287
|
p,
|
|
66164
66288
|
new Promise((_, reject) => {
|
|
66165
|
-
timer = unrefTimer(() => reject(new Error(`${label} did not finish within ${durationText(ms3)}`)), ms3);
|
|
66289
|
+
timer = unrefTimer(() => reject(new Error(typeof label === "string" ? `${label} did not finish within ${durationText(ms3)}` : label(ms3))), ms3);
|
|
66166
66290
|
})
|
|
66167
66291
|
]).finally(() => clearTimeout(timer));
|
|
66168
66292
|
}
|
|
@@ -66681,14 +66805,7 @@ var realOsValue = {
|
|
|
66681
66805
|
),
|
|
66682
66806
|
stop,
|
|
66683
66807
|
stopAll,
|
|
66684
|
-
alive:
|
|
66685
|
-
try {
|
|
66686
|
-
process.kill(pid, 0);
|
|
66687
|
-
return true;
|
|
66688
|
-
} catch (e) {
|
|
66689
|
-
return errnoCode(e) === "EPERM";
|
|
66690
|
-
}
|
|
66691
|
-
},
|
|
66808
|
+
alive: pidAlive,
|
|
66692
66809
|
signal: (pid, signal) => {
|
|
66693
66810
|
const refused2 = signalRefusal(signal, HOST_FAMILY);
|
|
66694
66811
|
if (refused2 === "ERR_UNKNOWN_SIGNAL") throw signalError(signal, refused2);
|
|
@@ -68170,14 +68287,14 @@ var HostServer = class _HostServer {
|
|
|
68170
68287
|
for (const timer of this.handshakeTimers.values()) clearTimeout(timer);
|
|
68171
68288
|
this.handshakeTimers.clear();
|
|
68172
68289
|
const sockets = [...this.wss.clients];
|
|
68173
|
-
const
|
|
68290
|
+
const gone2 = sockets.map(
|
|
68174
68291
|
(c) => c.readyState === c.CLOSED ? Promise.resolve() : new Promise((r) => c.once("close", () => r()))
|
|
68175
68292
|
);
|
|
68176
68293
|
for (const c of sockets) c.close(CLOSE_GOING_AWAY, "host shutting down");
|
|
68177
68294
|
const cut3 = setTimeout(() => {
|
|
68178
68295
|
for (const c of sockets) c.terminate();
|
|
68179
68296
|
}, this.limits.closeGraceMs);
|
|
68180
|
-
await Promise.all(
|
|
68297
|
+
await Promise.all(gone2);
|
|
68181
68298
|
clearTimeout(cut3);
|
|
68182
68299
|
this.clients.clear();
|
|
68183
68300
|
const httpClosed = new Promise((r) => this.http.close(() => r()));
|
|
@@ -68473,7 +68590,7 @@ var HostServer = class _HostServer {
|
|
|
68473
68590
|
});
|
|
68474
68591
|
}
|
|
68475
68592
|
});
|
|
68476
|
-
let
|
|
68593
|
+
let gone2 = false;
|
|
68477
68594
|
const forget = () => {
|
|
68478
68595
|
clearTimeout(this.handshakeTimers.get(ws2));
|
|
68479
68596
|
this.handshakeTimers.delete(ws2);
|
|
@@ -68484,8 +68601,8 @@ var HostServer = class _HostServer {
|
|
|
68484
68601
|
leaving.abort();
|
|
68485
68602
|
if (this.byClient.get(client) === ws2) this.byClient.delete(client);
|
|
68486
68603
|
this.failCalls(ws2, "The connection ended before it answered");
|
|
68487
|
-
if (!authed ||
|
|
68488
|
-
|
|
68604
|
+
if (!authed || gone2) return;
|
|
68605
|
+
gone2 = true;
|
|
68489
68606
|
this.opts.onClientGone?.(client);
|
|
68490
68607
|
};
|
|
68491
68608
|
ws2.on("close", forget);
|
|
@@ -68940,9 +69057,6 @@ var REMOTE_DOC_TTL_MS = 15e3;
|
|
|
68940
69057
|
var REMOTE_DOC_CAP = 64;
|
|
68941
69058
|
var SANDBOX_OPAQUE = "allow-scripts allow-forms";
|
|
68942
69059
|
var SANDBOX_APP = "allow-scripts allow-same-origin allow-forms";
|
|
68943
|
-
function sameApp(a, b2) {
|
|
68944
|
-
return a.appId === b2.appId && (a.projectId ?? null) === (b2.projectId ?? null);
|
|
68945
|
-
}
|
|
68946
69060
|
function fail(message) {
|
|
68947
69061
|
throw rpcError(message);
|
|
68948
69062
|
}
|
|
@@ -69436,11 +69550,11 @@ var PendingRequests = class {
|
|
|
69436
69550
|
* The answer to `id`, or a rejection once `timeoutMs` has passed without one: an `Error` with `timeout` as its text, or
|
|
69437
69551
|
* the error `timeout()` makes (one that carries a code or `retryable`)
|
|
69438
69552
|
*/
|
|
69439
|
-
wait(id3, timeoutMs,
|
|
69553
|
+
wait(id3, timeoutMs, timeout) {
|
|
69440
69554
|
const key = String(id3);
|
|
69441
69555
|
return new Promise((resolve21, reject) => {
|
|
69442
69556
|
const timer = setTimeout(() => {
|
|
69443
|
-
if (this.waiting.delete(key)) reject(typeof
|
|
69557
|
+
if (this.waiting.delete(key)) reject(typeof timeout === "string" ? new Error(timeout) : timeout());
|
|
69444
69558
|
}, timeoutMs);
|
|
69445
69559
|
timer.unref?.();
|
|
69446
69560
|
this.waiting.set(key, { resolve: resolve21, reject, timer });
|
|
@@ -69656,9 +69770,9 @@ function runOptions(cwd, env, timeoutMs, signal) {
|
|
|
69656
69770
|
signal,
|
|
69657
69771
|
onChild: (child) => {
|
|
69658
69772
|
live.add(child);
|
|
69659
|
-
const
|
|
69660
|
-
child.once("exit",
|
|
69661
|
-
child.once("error",
|
|
69773
|
+
const gone2 = () => live.delete(child);
|
|
69774
|
+
child.once("exit", gone2);
|
|
69775
|
+
child.once("error", gone2);
|
|
69662
69776
|
}
|
|
69663
69777
|
};
|
|
69664
69778
|
}
|
|
@@ -69672,9 +69786,9 @@ async function stopGitChildren(graceMs = GIT_STOP_GRACE_MS) {
|
|
|
69672
69786
|
async function runGit(cwd, args, opts = {}) {
|
|
69673
69787
|
const argv = await gitArgv(cwd, args, opts.allowRepoPrograms, opts.filters);
|
|
69674
69788
|
if (opts.signal?.aborted) throw gitCancelled();
|
|
69675
|
-
const
|
|
69789
|
+
const timeout = opts.timeout ?? DEFAULTS.timeout;
|
|
69676
69790
|
const r = await realOs().processes.run(programPath("git"), argv, {
|
|
69677
|
-
...runOptions(cwd, opts.env,
|
|
69791
|
+
...runOptions(cwd, opts.env, timeout, opts.signal),
|
|
69678
69792
|
input: opts.input ?? "",
|
|
69679
69793
|
maxBuffer: opts.maxBuffer ?? DEFAULTS.maxBuffer,
|
|
69680
69794
|
stdoutFile: opts.outputFile
|
|
@@ -69685,7 +69799,7 @@ async function runGit(cwd, args, opts = {}) {
|
|
|
69685
69799
|
if ((!ended2 || ended2 === "aborted") && code2 === 0) return out;
|
|
69686
69800
|
if (ended2 === "aborted") throw Object.assign(gitCancelled(), { signal, stdout: out, stderr: err });
|
|
69687
69801
|
if (ended2 === "timeout" || ended2 === "overflow") {
|
|
69688
|
-
const message = ended2 === "timeout" ? `git did not answer within ${
|
|
69802
|
+
const message = ended2 === "timeout" ? `git did not answer within ${timeout} ms` : "Git output exceeded maxBuffer";
|
|
69689
69803
|
throw Object.assign(new Error(message), { code: code2, signal, stdout: "", stderr: "", ...ended2 === "timeout" ? { timedOut: true, killed: true } : {} });
|
|
69690
69804
|
}
|
|
69691
69805
|
throw Object.assign(new Error(err || `Git exited with ${code2 ?? signal}`), { code: code2, signal, stdout: out, stderr: err });
|
|
@@ -82098,11 +82212,11 @@ var Protocol = class {
|
|
|
82098
82212
|
if (notification.params.requestId === void 0) return;
|
|
82099
82213
|
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
82100
82214
|
}
|
|
82101
|
-
_setupTimeout(messageId,
|
|
82215
|
+
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
82102
82216
|
this._timeoutInfo.set(messageId, {
|
|
82103
|
-
timeoutId: setTimeout(onTimeout,
|
|
82217
|
+
timeoutId: setTimeout(onTimeout, timeout),
|
|
82104
82218
|
startTime: Date.now(),
|
|
82105
|
-
timeout
|
|
82219
|
+
timeout,
|
|
82106
82220
|
maxTotalTimeout,
|
|
82107
82221
|
resetTimeoutOnProgress,
|
|
82108
82222
|
onTimeout
|
|
@@ -82544,9 +82658,9 @@ var Protocol = class {
|
|
|
82544
82658
|
});
|
|
82545
82659
|
onAbort = () => cancel(options?.signal?.reason);
|
|
82546
82660
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
82547
|
-
const
|
|
82548
|
-
const timeoutHandler = () => cancel(new SdkError(SdkErrorCode.RequestTimeout, "Request timed out", { timeout
|
|
82549
|
-
this._setupTimeout(messageId,
|
|
82661
|
+
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
82662
|
+
const timeoutHandler = () => cancel(new SdkError(SdkErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
82663
|
+
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
82550
82664
|
this._transport.send(outbound, {
|
|
82551
82665
|
relatedRequestId,
|
|
82552
82666
|
resumptionToken,
|
|
@@ -85148,7 +85262,7 @@ function announcingLedger(inner, announce) {
|
|
|
85148
85262
|
inner.begin(row);
|
|
85149
85263
|
const apps = [{ projectId: row.projectId, appId: row.appId }];
|
|
85150
85264
|
for (const up2 of row.parentRunId ? open6.get(row.parentRunId) ?? [] : []) {
|
|
85151
|
-
if (!apps.some((a) => a
|
|
85265
|
+
if (!apps.some((a) => sameApp(a, up2))) apps.push(up2);
|
|
85152
85266
|
}
|
|
85153
85267
|
open6.set(row.id, apps);
|
|
85154
85268
|
tell(apps);
|
|
@@ -85288,7 +85402,7 @@ function capabilityKey(c) {
|
|
|
85288
85402
|
case "agent":
|
|
85289
85403
|
return `agent:${c.tool}`;
|
|
85290
85404
|
case "app":
|
|
85291
|
-
return `app:${appKeyOf(c.target
|
|
85405
|
+
return `app:${appKeyOf(c.target)}`;
|
|
85292
85406
|
case "host":
|
|
85293
85407
|
return `host:${c.name}`;
|
|
85294
85408
|
}
|
|
@@ -85340,13 +85454,6 @@ var RunAgentArgs = external_exports.object({
|
|
|
85340
85454
|
function deniedText(tool, appName, text3) {
|
|
85341
85455
|
return `${tool} refused: the person did not allow ${appName} to ${text3}. They can change this in the app's Runs panel (Permissions \u2192 Forget), and Centralu asks again when the app's manifest changes what it uses.`;
|
|
85342
85456
|
}
|
|
85343
|
-
var slotOf = (ref) => appKeyOf(ref.projectId, ref.appId);
|
|
85344
|
-
function humanDuration(ms3) {
|
|
85345
|
-
const s = Math.max(1, Math.round(ms3 / 1e3));
|
|
85346
|
-
if (s < 60) return `${s} second${s === 1 ? "" : "s"}`;
|
|
85347
|
-
const m = Math.round(s / 60);
|
|
85348
|
-
return `${m} minute${m === 1 ? "" : "s"}`;
|
|
85349
|
-
}
|
|
85350
85457
|
var NOT_DECLARED = 'this app did not declare "uses": { "agent": \u2026 } in centralu.app.json \u2014 an app may run an agent only if its manifest says so';
|
|
85351
85458
|
var say = (text3) => ({ status: "ok", result: { content: [{ type: "text", text: text3 }] } });
|
|
85352
85459
|
var refuse2 = (text3) => ({ status: "rejected", result: { content: [{ type: "text", text: text3 }], isError: true } });
|
|
@@ -85486,7 +85593,7 @@ var BrokerDesk = class {
|
|
|
85486
85593
|
const body = text3.trim();
|
|
85487
85594
|
if (!body) return refuse8("notify refused: the text is empty");
|
|
85488
85595
|
if (body.length > NOTICE_MAX_CHARS) return refuse8(`notify refused: ${body.length} characters, over ${NOTICE_MAX_CHARS}; say less and point at where the rest is`);
|
|
85489
|
-
const key = appKeyOf(app2.ref
|
|
85596
|
+
const key = appKeyOf(app2.ref);
|
|
85490
85597
|
const now = Date.now();
|
|
85491
85598
|
const recent = (this.noticeTimes.get(key) ?? []).filter((t) => now - t < 6e4);
|
|
85492
85599
|
if (recent.length >= NOTICES_PER_MINUTE) {
|
|
@@ -85565,11 +85672,11 @@ var BrokerDesk = class {
|
|
|
85565
85672
|
}
|
|
85566
85673
|
const denied = await this.permit("run_agent", app2, { kind: "agent", tool: picked.tool }, `run an agent (${host.agentLabel(picked.tool)}) in a new session`, call2);
|
|
85567
85674
|
if (denied) return denied;
|
|
85568
|
-
const key =
|
|
85675
|
+
const key = appKeyOf(app2.ref);
|
|
85569
85676
|
const since = this.agentsRunning.get(key);
|
|
85570
85677
|
if (since !== void 0) {
|
|
85571
85678
|
return refuse2(
|
|
85572
|
-
`run_agent refused: ${app2.name} already has an agent running (started ${
|
|
85679
|
+
`run_agent refused: ${app2.name} already has an agent running (started ${durationText(Date.now() - since)} ago) \u2014 Centralu runs one agent per app at a time. Ask again when it has finished.`
|
|
85573
85680
|
);
|
|
85574
85681
|
}
|
|
85575
85682
|
const windowMs = this.timing().agentRateWindowMs;
|
|
@@ -85577,7 +85684,7 @@ var BrokerDesk = class {
|
|
|
85577
85684
|
const recent = (this.agentStarts.get(key) ?? []).filter((t) => t > now - windowMs);
|
|
85578
85685
|
if (recent.length >= AGENT_RUNS_PER_WINDOW) {
|
|
85579
85686
|
return refuse2(
|
|
85580
|
-
`run_agent refused: ${app2.name} started ${recent.length} agents within ${
|
|
85687
|
+
`run_agent refused: ${app2.name} started ${recent.length} agents within ${durationText(windowMs)}, the most Centralu allows \u2014 ask again in ${durationText(recent[0] + windowMs - now)}, or put more of the work into one prompt`
|
|
85581
85688
|
);
|
|
85582
85689
|
}
|
|
85583
85690
|
this.agentStarts.set(key, [...recent, now]);
|
|
@@ -85644,7 +85751,7 @@ var BrokerDesk = class {
|
|
|
85644
85751
|
}
|
|
85645
85752
|
const path2 = this.apps.chain(call2.parentRunId);
|
|
85646
85753
|
const shown3 = [...path2, { ref: target, tool }].map((p) => `${p.ref.appId}.${p.tool}`).join(" \u2192 ");
|
|
85647
|
-
if (path2.some((p) => p.ref
|
|
85754
|
+
if (path2.some((p) => sameApp(p.ref, target) && p.tool === tool)) {
|
|
85648
85755
|
return refuse2(`call_app refused: ${id3}.${tool} is already running in this chain (${shown3}) \u2014 calling it again would go round in a loop`);
|
|
85649
85756
|
}
|
|
85650
85757
|
if (path2.length >= CHAIN_DEPTH_MAX) {
|
|
@@ -85687,7 +85794,7 @@ var BrokerDesk = class {
|
|
|
85687
85794
|
if (known && known.stamp === stamp2) return known.decision === "allow" ? null : denied();
|
|
85688
85795
|
const host = this.host;
|
|
85689
85796
|
if (!host) return refuse2("the broker is unavailable: there is no one to ask for permission");
|
|
85690
|
-
const slot = `${
|
|
85797
|
+
const slot = `${appKeyOf(app2.ref)} ${key}`;
|
|
85691
85798
|
let q2 = this.asking.get(slot);
|
|
85692
85799
|
if (!q2) {
|
|
85693
85800
|
const withdraw = new AbortController();
|
|
@@ -85738,7 +85845,7 @@ var BrokerDesk = class {
|
|
|
85738
85845
|
if (call2.signal.aborted) throw new Error("cancelled while waiting for the person");
|
|
85739
85846
|
if (answer === null) {
|
|
85740
85847
|
return refuse2(
|
|
85741
|
-
asked.timedOut ? `${tool} refused: the person did not answer within ${
|
|
85848
|
+
asked.timedOut ? `${tool} refused: the person did not answer within ${durationText(this.questionMs())} whether ${app2.name} may ${text3}. Nothing was remembered \u2014 Centralu asks again next time.` : `${tool} refused: the question to the person was withdrawn before an answer`
|
|
85742
85849
|
);
|
|
85743
85850
|
}
|
|
85744
85851
|
this.book.put(app2.ref, { capability: key, text: text3, decision: answer, stamp: stamp2, decidedAt: Date.now() });
|
|
@@ -85833,12 +85940,12 @@ var AppCalls = class {
|
|
|
85833
85940
|
* through `call_app` is held as its caller is. A parent that already ended is `unknown`
|
|
85834
85941
|
*/
|
|
85835
85942
|
agentCallers(ref, seen = /* @__PURE__ */ new Set()) {
|
|
85836
|
-
const key =
|
|
85943
|
+
const key = appKeyOf(ref);
|
|
85837
85944
|
if (seen.has(key)) return [];
|
|
85838
85945
|
seen.add(key);
|
|
85839
85946
|
const out = [];
|
|
85840
85947
|
for (const run2 of this.openRuns.values()) {
|
|
85841
|
-
if (run2.entry.ref
|
|
85948
|
+
if (!sameApp(run2.entry.ref, ref)) continue;
|
|
85842
85949
|
const c = run2.caller;
|
|
85843
85950
|
if (c.kind === "session") out.push({ kind: "session", sessionId: c.sessionId });
|
|
85844
85951
|
else if (c.kind === "view") out.push(c.sessionId ? { kind: "session", sessionId: c.sessionId } : { kind: "person" });
|
|
@@ -85970,50 +86077,6 @@ function resultText(result) {
|
|
|
85970
86077
|
// packages/agent-host/src/apps/external/app-entry.ts
|
|
85971
86078
|
import { existsSync as existsSync5 } from "node:fs";
|
|
85972
86079
|
import { join as join6 } from "node:path";
|
|
85973
|
-
function resetLife(L2) {
|
|
85974
|
-
Object.assign(L2, { failures: 0, retryAt: 0, lastError: null, gaveUp: false, verdict: void 0 });
|
|
85975
|
-
}
|
|
85976
|
-
function keepsVersions(e) {
|
|
85977
|
-
return e.ref.projectId === null || e.found.root === true && !existsSync5(join6(e.dir, ".git"));
|
|
85978
|
-
}
|
|
85979
|
-
var invalidReason = (e) => `This app's manifest is invalid: ${e.error ?? "unknown error"}`;
|
|
85980
|
-
function newEntry(scope, found, reservedIds) {
|
|
85981
|
-
let { manifest, error: error51 } = found;
|
|
85982
|
-
if (manifest && reservedIds.includes(manifest.id)) {
|
|
85983
|
-
error51 = `"${manifest.id}" is a reserved app id \u2014 use another id`;
|
|
85984
|
-
manifest = null;
|
|
85985
|
-
}
|
|
85986
|
-
return {
|
|
85987
|
-
ref: { projectId: scope.projectId, appId: found.folder },
|
|
85988
|
-
scope,
|
|
85989
|
-
found,
|
|
85990
|
-
dir: found.dir,
|
|
85991
|
-
manifest,
|
|
85992
|
-
error: error51,
|
|
85993
|
-
warnings: found.warnings,
|
|
85994
|
-
life: {
|
|
85995
|
-
proc: null,
|
|
85996
|
-
starting: null,
|
|
85997
|
-
spawning: null,
|
|
85998
|
-
failures: 0,
|
|
85999
|
-
retryAt: 0,
|
|
86000
|
-
lastError: null,
|
|
86001
|
-
gaveUp: false,
|
|
86002
|
-
verdict: void 0,
|
|
86003
|
-
epoch: 0,
|
|
86004
|
-
inflight: 0,
|
|
86005
|
-
idleWaiters: [],
|
|
86006
|
-
stamp: null,
|
|
86007
|
-
loaded: null,
|
|
86008
|
-
idle: null,
|
|
86009
|
-
tools: null,
|
|
86010
|
-
toolWarnings: [],
|
|
86011
|
-
known: null,
|
|
86012
|
-
pipeId: 0,
|
|
86013
|
-
busy: null
|
|
86014
|
-
}
|
|
86015
|
-
};
|
|
86016
|
-
}
|
|
86017
86080
|
|
|
86018
86081
|
// packages/agent-host/src/apps/external/manifest.ts
|
|
86019
86082
|
var MANIFEST_FILE = "centralu.app.json";
|
|
@@ -86028,15 +86091,13 @@ var SECRET_NAME = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
|
86028
86091
|
var RESERVED_ENV_PREFIXES = ["CENTRALU_", "CC_"];
|
|
86029
86092
|
var HOST_CAPABILITY = /^[a-z][a-z0-9_.-]{0,63}$/;
|
|
86030
86093
|
var AGENT_TOOL = /^[a-z][a-z0-9-]{0,31}$/;
|
|
86094
|
+
function appIdRefusal(id3, reservedIds, { newName = false } = {}) {
|
|
86095
|
+
const problem3 = newName ? newAppIdProblem(id3, reservedIds) : serverNameProblem(id3) ?? (reservedIds.includes(id3) ? "builtin" : null);
|
|
86096
|
+
return problem3 && appIdProblemText(id3, problem3);
|
|
86097
|
+
}
|
|
86031
86098
|
var appIdField = external_exports.string().superRefine((id3, ctx) => {
|
|
86032
|
-
const
|
|
86033
|
-
if (
|
|
86034
|
-
if (problem3 === "shape") {
|
|
86035
|
-
ctx.addIssue({
|
|
86036
|
-
code: "custom",
|
|
86037
|
-
message: `an app id is lowercase letters, digits and hyphens (up to ${APP_ID_MAX_LENGTH}), starting with a letter or digit \u2014 no underscores: "__" separates names in a session's tool names`
|
|
86038
|
-
});
|
|
86039
|
-
}
|
|
86099
|
+
const refusal2 = appIdRefusal(id3, []);
|
|
86100
|
+
if (refusal2) ctx.addIssue({ code: "custom", message: refusal2 });
|
|
86040
86101
|
});
|
|
86041
86102
|
var toolNameField = external_exports.string().superRefine((name, ctx) => {
|
|
86042
86103
|
const err = toolNameError(name);
|
|
@@ -86190,6 +86251,53 @@ function describeIssue(issue2) {
|
|
|
86190
86251
|
return `${path2}: ${issue2.message}`;
|
|
86191
86252
|
}
|
|
86192
86253
|
|
|
86254
|
+
// packages/agent-host/src/apps/external/app-entry.ts
|
|
86255
|
+
function resetLife(L2) {
|
|
86256
|
+
Object.assign(L2, { failures: 0, retryAt: 0, lastError: null, gaveUp: false, verdict: void 0 });
|
|
86257
|
+
}
|
|
86258
|
+
function keepsVersions(e) {
|
|
86259
|
+
return e.ref.projectId === null || e.found.root === true && !existsSync5(join6(e.dir, ".git"));
|
|
86260
|
+
}
|
|
86261
|
+
var invalidReason = (e) => `This app's manifest is invalid: ${e.error ?? "unknown error"}`;
|
|
86262
|
+
function newEntry(scope, found, reservedIds) {
|
|
86263
|
+
let { manifest, error: error51 } = found;
|
|
86264
|
+
const refusal2 = manifest && appIdRefusal(manifest.id, reservedIds);
|
|
86265
|
+
if (refusal2) {
|
|
86266
|
+
error51 = refusal2;
|
|
86267
|
+
manifest = null;
|
|
86268
|
+
}
|
|
86269
|
+
return {
|
|
86270
|
+
ref: { projectId: scope.projectId, appId: found.folder },
|
|
86271
|
+
scope,
|
|
86272
|
+
found,
|
|
86273
|
+
dir: found.dir,
|
|
86274
|
+
manifest,
|
|
86275
|
+
error: error51,
|
|
86276
|
+
warnings: found.warnings,
|
|
86277
|
+
life: {
|
|
86278
|
+
proc: null,
|
|
86279
|
+
starting: null,
|
|
86280
|
+
spawning: null,
|
|
86281
|
+
failures: 0,
|
|
86282
|
+
retryAt: 0,
|
|
86283
|
+
lastError: null,
|
|
86284
|
+
gaveUp: false,
|
|
86285
|
+
verdict: void 0,
|
|
86286
|
+
epoch: 0,
|
|
86287
|
+
inflight: 0,
|
|
86288
|
+
idleWaiters: [],
|
|
86289
|
+
stamp: null,
|
|
86290
|
+
loaded: null,
|
|
86291
|
+
idle: null,
|
|
86292
|
+
tools: null,
|
|
86293
|
+
toolWarnings: [],
|
|
86294
|
+
known: null,
|
|
86295
|
+
pipeId: 0,
|
|
86296
|
+
busy: null
|
|
86297
|
+
}
|
|
86298
|
+
};
|
|
86299
|
+
}
|
|
86300
|
+
|
|
86193
86301
|
// packages/agent-host/src/apps/external/visibility.ts
|
|
86194
86302
|
var DEFAULT_VISIBILITY = ["model", "app"];
|
|
86195
86303
|
function visibilityOf(tool) {
|
|
@@ -86405,9 +86513,8 @@ async function checkApp(host, ref) {
|
|
|
86405
86513
|
}
|
|
86406
86514
|
const busy = e.life.inflight;
|
|
86407
86515
|
if (!await host.lifecycle.drain(e, host.timing.checkDrainMs)) {
|
|
86408
|
-
const limit = host.timing.checkDrainMs >= 1e3 ? `${Math.round(host.timing.checkDrainMs / 1e3)} s` : `${host.timing.checkDrainMs} ms`;
|
|
86409
86516
|
notes.push(
|
|
86410
|
-
`${busy} call${busy === 1 ? " was" : "s were"} still running after ${
|
|
86517
|
+
`${busy} call${busy === 1 ? " was" : "s were"} still running after ${durationText(host.timing.checkDrainMs)}, so the app was not restarted \u2014 this report is about the process that was already running, which may not have your latest code`
|
|
86411
86518
|
);
|
|
86412
86519
|
break;
|
|
86413
86520
|
}
|
|
@@ -86624,7 +86731,7 @@ function subfoldersOf(root3, appRel) {
|
|
|
86624
86731
|
return [];
|
|
86625
86732
|
}
|
|
86626
86733
|
}
|
|
86627
|
-
function
|
|
86734
|
+
function readManifestFile(root3, manifestRel) {
|
|
86628
86735
|
try {
|
|
86629
86736
|
if (!assertExistingPathSync(root3, manifestRel).isFile()) return { error: `${MANIFEST_FILE} is not a file` };
|
|
86630
86737
|
return { text: readCapped(join9(root3, manifestRel)) };
|
|
@@ -86634,7 +86741,7 @@ function readManifestText(root3, manifestRel) {
|
|
|
86634
86741
|
}
|
|
86635
86742
|
}
|
|
86636
86743
|
function readApp(root3, folderRel, folder, dir) {
|
|
86637
|
-
const read2 =
|
|
86744
|
+
const read2 = readManifestFile(root3, `${folderRel}/${MANIFEST_FILE}`);
|
|
86638
86745
|
if ("missing" in read2) return invalid(folder, dir, `there is no ${MANIFEST_FILE}`);
|
|
86639
86746
|
if ("error" in read2) return invalid(folder, dir, read2.error);
|
|
86640
86747
|
const { text: text3 } = read2;
|
|
@@ -86655,7 +86762,7 @@ function readApp(root3, folderRel, folder, dir) {
|
|
|
86655
86762
|
}
|
|
86656
86763
|
var BROKEN_ROOT_APP_ID = "centralu-root";
|
|
86657
86764
|
function scanRootApp(root3, taken) {
|
|
86658
|
-
const read2 =
|
|
86765
|
+
const read2 = readManifestFile(root3, MANIFEST_FILE);
|
|
86659
86766
|
if ("missing" in read2) return null;
|
|
86660
86767
|
const rootApp = (id4, rest) => ({
|
|
86661
86768
|
folder: id4,
|
|
@@ -86836,16 +86943,10 @@ var AppUnavailableError = class extends Error {
|
|
|
86836
86943
|
};
|
|
86837
86944
|
|
|
86838
86945
|
// packages/agent-host/src/apps/external/app-folders.ts
|
|
86839
|
-
var USER_SCOPE = USER_APP_SCOPE;
|
|
86840
|
-
var APP_ID_PROBLEM = {
|
|
86841
|
-
shape: `an app id is lowercase letters, digits and hyphens (up to ${APP_ID_MAX_LENGTH}), starting with a letter or digit \u2014 no underscores: "__" separates names in a session's tool names`,
|
|
86842
|
-
reserved: `ids starting with "${RESERVED_NAME_PREFIX}" belong to Centralu itself`,
|
|
86843
|
-
"server-prefix": `ids starting with "${APP_SERVER_PREFIX}" are how apps attach to sessions \u2014 pick another`,
|
|
86844
|
-
builtin: "that id is reserved \u2014 pick another"
|
|
86845
|
-
};
|
|
86846
86946
|
function installUserApp(host, spec) {
|
|
86847
86947
|
if (host.disposed()) throw new AppUnavailableError("The app runtime has shut down");
|
|
86848
|
-
|
|
86948
|
+
const refusal2 = appIdRefusal(spec.id, host.deps.reservedIds);
|
|
86949
|
+
if (refusal2) throw new AppUnavailableError(refusal2);
|
|
86849
86950
|
const text3 = JSON.stringify(
|
|
86850
86951
|
{
|
|
86851
86952
|
manifestVersion: MANIFEST_VERSION,
|
|
@@ -86897,7 +86998,7 @@ function createApp(host, spec) {
|
|
|
86897
86998
|
}
|
|
86898
86999
|
root3 = project2.path;
|
|
86899
87000
|
}
|
|
86900
|
-
const key = spec.projectId ??
|
|
87001
|
+
const key = spec.projectId ?? USER_APP_SCOPE;
|
|
86901
87002
|
if (host.hasScope(key)) host.rescan(key);
|
|
86902
87003
|
else host.refresh();
|
|
86903
87004
|
const ref = { projectId: spec.projectId, appId: spec.id };
|
|
@@ -86920,8 +87021,8 @@ function createApp(host, spec) {
|
|
|
86920
87021
|
return host.info(made);
|
|
86921
87022
|
}
|
|
86922
87023
|
function newAppText(host, spec) {
|
|
86923
|
-
const
|
|
86924
|
-
if (
|
|
87024
|
+
const refusal2 = appIdRefusal(spec.id, host.deps.reservedIds, { newName: true });
|
|
87025
|
+
if (refusal2) throw new AppUnavailableError(refusal2);
|
|
86925
87026
|
const name = oneLine(spec.name);
|
|
86926
87027
|
if (!name) throw new AppUnavailableError("The app needs a name");
|
|
86927
87028
|
return { name, description: oneLine(spec.description ?? "") || `${name} (a Centralu app)` };
|
|
@@ -86958,7 +87059,7 @@ async function removeUserApp(host, ref) {
|
|
|
86958
87059
|
}
|
|
86959
87060
|
host.rescanUser();
|
|
86960
87061
|
const e = host.require(ref);
|
|
86961
|
-
const key =
|
|
87062
|
+
const key = appKeyOf(ref);
|
|
86962
87063
|
host.removing.add(key);
|
|
86963
87064
|
try {
|
|
86964
87065
|
await host.lifecycle.halt(e, "app removed", { awaitTree: true });
|
|
@@ -90874,11 +90975,11 @@ var Protocol2 = class {
|
|
|
90874
90975
|
if (notification.params.requestId === void 0) return;
|
|
90875
90976
|
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
90876
90977
|
}
|
|
90877
|
-
_setupTimeout(messageId,
|
|
90978
|
+
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
90878
90979
|
this._timeoutInfo.set(messageId, {
|
|
90879
|
-
timeoutId: setTimeout(onTimeout,
|
|
90980
|
+
timeoutId: setTimeout(onTimeout, timeout),
|
|
90880
90981
|
startTime: Date.now(),
|
|
90881
|
-
timeout
|
|
90982
|
+
timeout,
|
|
90882
90983
|
maxTotalTimeout,
|
|
90883
90984
|
resetTimeoutOnProgress,
|
|
90884
90985
|
onTimeout
|
|
@@ -91320,9 +91421,9 @@ var Protocol2 = class {
|
|
|
91320
91421
|
});
|
|
91321
91422
|
onAbort = () => cancel(options?.signal?.reason);
|
|
91322
91423
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
91323
|
-
const
|
|
91324
|
-
const timeoutHandler = () => cancel(new SdkError2(SdkErrorCode2.RequestTimeout, "Request timed out", { timeout
|
|
91325
|
-
this._setupTimeout(messageId,
|
|
91424
|
+
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC2;
|
|
91425
|
+
const timeoutHandler = () => cancel(new SdkError2(SdkErrorCode2.RequestTimeout, "Request timed out", { timeout }));
|
|
91426
|
+
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
91326
91427
|
this._transport.send(outbound, {
|
|
91327
91428
|
relatedRequestId,
|
|
91328
91429
|
resumptionToken,
|
|
@@ -102048,7 +102149,7 @@ var AppLifecycle = class {
|
|
|
102048
102149
|
return null;
|
|
102049
102150
|
}
|
|
102050
102151
|
viewsOf(e) {
|
|
102051
|
-
return this.viewHolds.get(
|
|
102152
|
+
return this.viewHolds.get(appKeyOf(e.ref)) ?? 0;
|
|
102052
102153
|
}
|
|
102053
102154
|
/** Stops it only after finishing a call in progress — the way an old entry's process is collected when a manifest change replaces the entry */
|
|
102054
102155
|
async haltWhenDrained(e, why2) {
|
|
@@ -102064,7 +102165,7 @@ var AppLifecycle = class {
|
|
|
102064
102165
|
* never treated as an idle app — call the returned function to release the hold (close).
|
|
102065
102166
|
*/
|
|
102066
102167
|
retainView(e, ref) {
|
|
102067
|
-
const key =
|
|
102168
|
+
const key = appKeyOf(e.ref);
|
|
102068
102169
|
this.viewHolds.set(key, (this.viewHolds.get(key) ?? 0) + 1);
|
|
102069
102170
|
this.clearIdle(e);
|
|
102070
102171
|
let released = false;
|
|
@@ -102101,7 +102202,7 @@ var ChangeReflector = class {
|
|
|
102101
102202
|
this.host = host;
|
|
102102
102203
|
}
|
|
102103
102204
|
host;
|
|
102104
|
-
/** Timers for reflecting changes (C-4) — per app name (
|
|
102205
|
+
/** Timers for reflecting changes (C-4) — per app name (`appKeyOf`). Carried over even when the manifest changes and a new entry is created */
|
|
102105
102206
|
turnEndTimers = /* @__PURE__ */ new Map();
|
|
102106
102207
|
quietTimers = /* @__PURE__ */ new Map();
|
|
102107
102208
|
/** Apps whose started entry a scan replaced (new manifest) while their turn-end timer was pending — the timer finds only a never-started entry and must still start it */
|
|
@@ -102121,7 +102222,7 @@ var ChangeReflector = class {
|
|
|
102121
102222
|
* note it would take it for an app nobody ever used and leave it stopped.
|
|
102122
102223
|
*/
|
|
102123
102224
|
manifestReplaced(ref, prev) {
|
|
102124
|
-
const key =
|
|
102225
|
+
const key = appKeyOf(ref);
|
|
102125
102226
|
if (prev.life.stamp !== null && this.turnEndTimers.has(key)) this.replacedBeforeTurnEnd.add(key);
|
|
102126
102227
|
}
|
|
102127
102228
|
/**
|
|
@@ -102139,7 +102240,7 @@ var ChangeReflector = class {
|
|
|
102139
102240
|
*/
|
|
102140
102241
|
builderTurnEnded(ref) {
|
|
102141
102242
|
if (this.host.disposed()) return;
|
|
102142
|
-
const key =
|
|
102243
|
+
const key = appKeyOf(ref);
|
|
102143
102244
|
clearTimeout(this.turnEndTimers.get(key));
|
|
102144
102245
|
const t = setTimeout(() => {
|
|
102145
102246
|
this.turnEndTimers.delete(key);
|
|
@@ -102169,7 +102270,7 @@ var ChangeReflector = class {
|
|
|
102169
102270
|
*/
|
|
102170
102271
|
folderChanged(e) {
|
|
102171
102272
|
if (this.host.builderBusy(e.ref)) return;
|
|
102172
|
-
const key =
|
|
102273
|
+
const key = appKeyOf(e.ref);
|
|
102173
102274
|
clearTimeout(this.quietTimers.get(key));
|
|
102174
102275
|
const ref = e.ref;
|
|
102175
102276
|
const t = setTimeout(() => {
|
|
@@ -102192,7 +102293,7 @@ var ChangeReflector = class {
|
|
|
102192
102293
|
* An open screen also receives "changed".
|
|
102193
102294
|
*/
|
|
102194
102295
|
reloadIfChanged(ref, opts) {
|
|
102195
|
-
const key =
|
|
102296
|
+
const key = appKeyOf(ref);
|
|
102196
102297
|
const running2 = this.reloading.get(key);
|
|
102197
102298
|
if (running2) return running2;
|
|
102198
102299
|
const p = (async () => {
|
|
@@ -102262,7 +102363,7 @@ ${b2.stderr.join("\n")}` : "stderr: (the app printed nothing)");
|
|
|
102262
102363
|
|
|
102263
102364
|
// packages/agent-host/src/apps/external/error-log.ts
|
|
102264
102365
|
var STDERR_SETTLE_MS = 150;
|
|
102265
|
-
var sentKey = (
|
|
102366
|
+
var sentKey = (appKey, b2) => `${appKey}
|
|
102266
102367
|
${b2.kind}
|
|
102267
102368
|
${b2.at}`;
|
|
102268
102369
|
var ErrorLog = class {
|
|
@@ -102270,7 +102371,7 @@ var ErrorLog = class {
|
|
|
102270
102371
|
this.changed = changed;
|
|
102271
102372
|
}
|
|
102272
102373
|
changed;
|
|
102273
|
-
/** Recent error bundles per app
|
|
102374
|
+
/** Recent error bundles per app key (`appKeyOf`), most recent first (C-6) — carried over even when the manifest changes and a new entry is created */
|
|
102274
102375
|
bundles = /* @__PURE__ */ new Map();
|
|
102275
102376
|
/**
|
|
102276
102377
|
* A bundle sent to the building session → the time it was sent (C-6). Kept separately instead of
|
|
@@ -102604,9 +102705,9 @@ var SecretStore = class {
|
|
|
102604
102705
|
*/
|
|
102605
102706
|
forgetScope(scope) {
|
|
102606
102707
|
const doc = this.read();
|
|
102607
|
-
const
|
|
102608
|
-
if (
|
|
102609
|
-
for (const key of
|
|
102708
|
+
const gone2 = Object.keys(doc).filter((key) => key.startsWith(`${scope}/`));
|
|
102709
|
+
if (gone2.length === 0) return;
|
|
102710
|
+
for (const key of gone2) delete doc[key];
|
|
102610
102711
|
this.file.write(doc);
|
|
102611
102712
|
}
|
|
102612
102713
|
/**
|
|
@@ -102748,11 +102849,14 @@ var AppStartEnv = class {
|
|
|
102748
102849
|
dataDirOf(ref) {
|
|
102749
102850
|
return join16(this.deps.dataRoot, "app-data", this.scopeDir(ref), ref.appId);
|
|
102750
102851
|
}
|
|
102751
|
-
/** The
|
|
102852
|
+
/** The ref, once its project id is known to be one path segment. A project id is a UUID — refused rather than written into a path if it does not look like one */
|
|
102853
|
+
pathSafe(ref) {
|
|
102854
|
+
if (ref.projectId !== null && !/^[A-Za-z0-9-]+$/.test(ref.projectId)) throw new AppUnavailableError(`This project id cannot be used in a path: ${ref.projectId}`);
|
|
102855
|
+
return ref;
|
|
102856
|
+
}
|
|
102857
|
+
/** The scope name used as one path segment */
|
|
102752
102858
|
scopeDir(ref) {
|
|
102753
|
-
|
|
102754
|
-
if (!/^[A-Za-z0-9-]+$/.test(ref.projectId)) throw new AppUnavailableError(`This project id cannot be used in a path: ${ref.projectId}`);
|
|
102755
|
-
return ref.projectId;
|
|
102859
|
+
return this.pathSafe(ref).projectId ?? USER_APP_SCOPE;
|
|
102756
102860
|
}
|
|
102757
102861
|
/**
|
|
102758
102862
|
* The function that masks every secret stored for this app (A-3, A-6) — whichever of a run's
|
|
@@ -102763,8 +102867,9 @@ var AppStartEnv = class {
|
|
|
102763
102867
|
masker(ref) {
|
|
102764
102868
|
return redactor(this.secrets.all(this.appKey(ref)));
|
|
102765
102869
|
}
|
|
102870
|
+
/** `appKeyOf`, after the check that its scope can be a path segment: carried app files are moved by this key (`carryAppFiles`) */
|
|
102766
102871
|
appKey(ref) {
|
|
102767
|
-
return
|
|
102872
|
+
return appKeyOf(this.pathSafe(ref));
|
|
102768
102873
|
}
|
|
102769
102874
|
/** Whether a value is set for each declared secret (E, the secrets section) — just the name and whether it is set. No field at all if there is no declaration */
|
|
102770
102875
|
secretSlots(e) {
|
|
@@ -103139,29 +103244,6 @@ import { closeSync as closeSync4, constants as constants5, fstatSync as fstatSyn
|
|
|
103139
103244
|
import { isAbsolute as isAbsolute2, join as join18 } from "node:path";
|
|
103140
103245
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
103141
103246
|
|
|
103142
|
-
// packages/agent-host/src/apps/contract.ts
|
|
103143
|
-
var CENTRALU_MCP_NAME = RESERVED_NAME_PREFIX;
|
|
103144
|
-
var APP_MCP_PREFIX = APP_SERVER_PREFIX;
|
|
103145
|
-
var appMcpServerName = (appId) => `${APP_MCP_PREFIX}${appId}`;
|
|
103146
|
-
function mcpServerNameError(name) {
|
|
103147
|
-
switch (serverNameProblem(name)) {
|
|
103148
|
-
case "reserved":
|
|
103149
|
-
return `A name starting with "${CENTRALU_MCP_NAME}" is the name this app uses \u2014 suggest a different name`;
|
|
103150
|
-
case "shape":
|
|
103151
|
-
return "A name must be lowercase letters, digits, and hyphens, 32 characters or fewer (underscores cannot be used \u2014 they separate parts of a tool name)";
|
|
103152
|
-
case null:
|
|
103153
|
-
return null;
|
|
103154
|
-
}
|
|
103155
|
-
}
|
|
103156
|
-
function proposedMcpServerNameError(name) {
|
|
103157
|
-
const base2 = mcpServerNameError(name);
|
|
103158
|
-
if (base2) return base2;
|
|
103159
|
-
if (newAppIdProblem(name) === "server-prefix") {
|
|
103160
|
-
return `A name starting with "${APP_MCP_PREFIX}" is the name an external app attaches to a session \u2014 suggest a different name`;
|
|
103161
|
-
}
|
|
103162
|
-
return null;
|
|
103163
|
-
}
|
|
103164
|
-
|
|
103165
103247
|
// packages/agent-host/src/zip.ts
|
|
103166
103248
|
import { inflateRawSync } from "node:zlib";
|
|
103167
103249
|
var ZipError = class extends Error {
|
|
@@ -103576,22 +103658,14 @@ function zipParts(name, limits) {
|
|
|
103576
103658
|
return parts;
|
|
103577
103659
|
}
|
|
103578
103660
|
function readStagedManifest(dir, reservedIds) {
|
|
103579
|
-
const
|
|
103580
|
-
|
|
103581
|
-
|
|
103582
|
-
|
|
103583
|
-
if (!st2.isFile()) throw new Error("not a file");
|
|
103584
|
-
size2 = st2.size;
|
|
103585
|
-
} catch {
|
|
103586
|
-
throw new ImportRefused(`There is no ${MANIFEST_FILE} at the top, so this is not a Centralu app`);
|
|
103587
|
-
}
|
|
103588
|
-
if (size2 > MAX_MANIFEST_BYTES) throw new ImportRefused(`${MANIFEST_FILE} is larger than ${MAX_MANIFEST_BYTES} bytes`);
|
|
103589
|
-
const parsed = parseManifest(readFileSync8(path2, "utf8"));
|
|
103661
|
+
const file2 = readManifestFile(dir, MANIFEST_FILE);
|
|
103662
|
+
if ("missing" in file2) throw new ImportRefused(`There is no ${MANIFEST_FILE} at the top, so this is not a Centralu app`);
|
|
103663
|
+
if ("error" in file2) throw new ImportRefused(file2.error);
|
|
103664
|
+
const parsed = parseManifest(file2.text);
|
|
103590
103665
|
if (!parsed.ok) throw new ImportRefused(`${MANIFEST_FILE} is not valid: ${parsed.error}`);
|
|
103591
103666
|
const id3 = parsed.manifest.id;
|
|
103592
|
-
const
|
|
103593
|
-
if (
|
|
103594
|
-
if (reservedIds.includes(id3)) throw new ImportRefused(`"${id3}" is a reserved app id; this app cannot be imported under it`);
|
|
103667
|
+
const refusal2 = appIdRefusal(id3, reservedIds, { newName: true });
|
|
103668
|
+
if (refusal2) throw new ImportRefused(refusal2);
|
|
103595
103669
|
return { manifest: parsed.manifest, warnings: parsed.warnings };
|
|
103596
103670
|
}
|
|
103597
103671
|
function reviewOf(manifest, staged, meta3) {
|
|
@@ -104174,19 +104248,18 @@ var DEFAULT_TIMING = {
|
|
|
104174
104248
|
probeTimeoutMs: 1e4,
|
|
104175
104249
|
connectTimeoutMs: 3e4,
|
|
104176
104250
|
startExitWaitMs: 250,
|
|
104177
|
-
callTimeoutMs:
|
|
104251
|
+
callTimeoutMs: APP_CALL_TIMEOUT_MS,
|
|
104178
104252
|
logMaxBytes: 1024 * 1024,
|
|
104179
104253
|
checkDrainMs: 3e4,
|
|
104180
104254
|
reloadQuietMs: 2e3,
|
|
104181
104255
|
turnEndDebounceMs: 300,
|
|
104182
104256
|
brokerKeepaliveMs: BROKER_KEEPALIVE_MS,
|
|
104183
|
-
capabilityQuestionMs:
|
|
104257
|
+
capabilityQuestionMs: APP_CAPABILITY_QUESTION_MS,
|
|
104184
104258
|
resumeBusyMs: 3e3,
|
|
104185
104259
|
agentRateWindowMs: 6e4
|
|
104186
104260
|
};
|
|
104187
104261
|
|
|
104188
104262
|
// packages/agent-host/src/apps/external/runtime.ts
|
|
104189
|
-
var USER_SCOPE2 = USER_APP_SCOPE;
|
|
104190
104263
|
var ExternalApps = class {
|
|
104191
104264
|
constructor(deps) {
|
|
104192
104265
|
this.deps = deps;
|
|
@@ -104201,26 +104274,24 @@ var ExternalApps = class {
|
|
|
104201
104274
|
blocker: (e) => this.blocker(e),
|
|
104202
104275
|
spawnSpec: (e, pipeId) => this.startEnv.spawnSpec(e, pipeId),
|
|
104203
104276
|
snapshot: (e, stamp2) => {
|
|
104204
|
-
if (keepsVersions(e)) this.handover.snapshot(
|
|
104277
|
+
if (keepsVersions(e)) this.handover.snapshot(appKeyOf(e.ref), e.dir, "started", stamp2);
|
|
104205
104278
|
},
|
|
104206
104279
|
find: (ref) => this.find(ref),
|
|
104207
|
-
holdKey: (ref) => this.holdKey(ref),
|
|
104208
104280
|
label: (ref) => this.label(ref),
|
|
104209
|
-
busyRecorded: (e, reason) => this.busyBook.set(
|
|
104281
|
+
busyRecorded: (e, reason) => this.busyBook.set(appKeyOf(e.ref), reason === null ? null : { projectId: e.ref.projectId, appId: e.ref.appId, reason, at: Date.now() })
|
|
104210
104282
|
});
|
|
104211
104283
|
this.reflector = new ChangeReflector({
|
|
104212
104284
|
timing: this.timing,
|
|
104213
104285
|
disposed: () => this.disposed,
|
|
104214
104286
|
lifecycle: this.lifecycle,
|
|
104215
104287
|
find: (ref) => this.find(ref),
|
|
104216
|
-
holdKey: (ref) => this.holdKey(ref),
|
|
104217
104288
|
label: (ref) => this.label(ref),
|
|
104218
104289
|
blocker: (e, opts) => this.blocker(e, opts),
|
|
104219
104290
|
appsChanged: () => this.appsChanged(),
|
|
104220
104291
|
emitChanged: (ref) => this.deps.emitChanged?.(ref),
|
|
104221
104292
|
builderBusy: (ref) => this.deps.builderBusy?.(ref) ?? false,
|
|
104222
104293
|
rescanNow: (ref) => {
|
|
104223
|
-
const scopeKey = ref.projectId ??
|
|
104294
|
+
const scopeKey = ref.projectId ?? USER_APP_SCOPE;
|
|
104224
104295
|
if (this.scopes.has(scopeKey) && !this.disposed) this.rescan(scopeKey, { now: ref.appId });
|
|
104225
104296
|
}
|
|
104226
104297
|
});
|
|
@@ -104289,9 +104360,9 @@ var ExternalApps = class {
|
|
|
104289
104360
|
/** `onAppsChanged` subscribers, and whether a notification is already scheduled for this tick */
|
|
104290
104361
|
appsListeners = createListeners((err) => console.error("[apps] apps-changed listener failed:", err));
|
|
104291
104362
|
appsNotePending = false;
|
|
104292
|
-
/** Recent error bundles per app
|
|
104363
|
+
/** Recent error bundles per app key (`appKeyOf`) and which were sent (C-6) — `error-log.ts` */
|
|
104293
104364
|
errorLog = new ErrorLog(() => this.appsChanged());
|
|
104294
|
-
/** Apps being removed (`removeUserApp`, by `
|
|
104365
|
+
/** Apps being removed (`removeUserApp`, by `appKeyOf`) — none of them starts again while its folder moves */
|
|
104295
104366
|
removing = /* @__PURE__ */ new Set();
|
|
104296
104367
|
/**
|
|
104297
104368
|
* The broker desk (D) — the one place that resolves what an app requests over fd 3. A call between
|
|
@@ -104321,7 +104392,7 @@ var ExternalApps = class {
|
|
|
104321
104392
|
*/
|
|
104322
104393
|
errors(ref) {
|
|
104323
104394
|
ref = this.resolve(ref);
|
|
104324
|
-
return this.errorLog.errors(
|
|
104395
|
+
return this.errorLog.errors(appKeyOf(ref));
|
|
104325
104396
|
}
|
|
104326
104397
|
/**
|
|
104327
104398
|
* Records that one bundle was sent to the building session (C-6) — **only once.** Returns the
|
|
@@ -104335,15 +104406,15 @@ var ExternalApps = class {
|
|
|
104335
104406
|
*/
|
|
104336
104407
|
markErrorSent(ref, at2) {
|
|
104337
104408
|
ref = this.resolve(ref);
|
|
104338
|
-
return this.errorLog.markSent(
|
|
104409
|
+
return this.errorLog.markSent(appKeyOf(ref), at2);
|
|
104339
104410
|
}
|
|
104340
104411
|
unmarkErrorSent(ref, at2) {
|
|
104341
104412
|
ref = this.resolve(ref);
|
|
104342
|
-
this.errorLog.unmarkSent(
|
|
104413
|
+
this.errorLog.unmarkSent(appKeyOf(ref), at2);
|
|
104343
104414
|
}
|
|
104344
104415
|
/** Records one error bundle for this app (`ErrorLog.record`) */
|
|
104345
104416
|
recordError(e, b2, proc = null) {
|
|
104346
|
-
this.errorLog.record(
|
|
104417
|
+
this.errorLog.record(appKeyOf(e.ref), `${e.manifest?.name ?? e.ref.appId} (${this.label(e.ref)})`, b2, proc);
|
|
104347
104418
|
}
|
|
104348
104419
|
/**
|
|
104349
104420
|
* Receives the part of the broker's body only the host's core can do (an agent session) (D). Called
|
|
@@ -104399,7 +104470,7 @@ var ExternalApps = class {
|
|
|
104399
104470
|
refresh() {
|
|
104400
104471
|
if (this.disposed) return;
|
|
104401
104472
|
const want = /* @__PURE__ */ new Map();
|
|
104402
|
-
want.set(
|
|
104473
|
+
want.set(USER_APP_SCOPE, { key: USER_APP_SCOPE, projectId: null, root: this.deps.dataRoot, trusted: true });
|
|
104403
104474
|
for (const p of this.deps.projects()) {
|
|
104404
104475
|
want.set(p.id, { key: p.id, projectId: p.id, root: p.path, trusted: p.trusted });
|
|
104405
104476
|
}
|
|
@@ -104430,7 +104501,7 @@ var ExternalApps = class {
|
|
|
104430
104501
|
if (this.disposed) return;
|
|
104431
104502
|
for (const rec of this.busyBook.list()) {
|
|
104432
104503
|
const ref = { projectId: rec.projectId, appId: rec.appId };
|
|
104433
|
-
this.busyBook.set(
|
|
104504
|
+
this.busyBook.set(appKeyOf(ref), null);
|
|
104434
104505
|
const e = this.find(ref);
|
|
104435
104506
|
if (!e || this.blocker(e) || !e.manifest?.uses.background) continue;
|
|
104436
104507
|
console.error(`[apps] ${this.label(ref)} was busy (${rec.reason}) when Centralu last stopped \u2014 starting it again`);
|
|
@@ -104566,7 +104637,7 @@ var ExternalApps = class {
|
|
|
104566
104637
|
ref = this.resolve(ref);
|
|
104567
104638
|
const e = this.require(ref);
|
|
104568
104639
|
await this.lifecycle.halt(e, "restart requested");
|
|
104569
|
-
this.busyBook.set(
|
|
104640
|
+
this.busyBook.set(appKeyOf(e.ref), null);
|
|
104570
104641
|
resetLife(e.life);
|
|
104571
104642
|
this.appsChanged();
|
|
104572
104643
|
}
|
|
@@ -104604,7 +104675,7 @@ var ExternalApps = class {
|
|
|
104604
104675
|
timing: this.timing,
|
|
104605
104676
|
lifecycle: this.lifecycle,
|
|
104606
104677
|
rescanNow: (r) => {
|
|
104607
|
-
const key = r.projectId ??
|
|
104678
|
+
const key = r.projectId ?? USER_APP_SCOPE;
|
|
104608
104679
|
if (this.scopes.has(key)) this.rescan(key, { now: r.appId });
|
|
104609
104680
|
else this.refresh();
|
|
104610
104681
|
},
|
|
@@ -104653,7 +104724,6 @@ var ExternalApps = class {
|
|
|
104653
104724
|
require: (ref) => this.require(ref),
|
|
104654
104725
|
info: (e) => this.info(e),
|
|
104655
104726
|
dataDirOf: (ref) => this.startEnv.dataDirOf(ref),
|
|
104656
|
-
holdKey: (ref) => this.holdKey(ref),
|
|
104657
104727
|
removing: this.removing,
|
|
104658
104728
|
lifecycle: this.lifecycle,
|
|
104659
104729
|
forgetImport: (appId) => this.handover.forget(appId)
|
|
@@ -104665,7 +104735,7 @@ var ExternalApps = class {
|
|
|
104665
104735
|
}
|
|
104666
104736
|
/** Rescans the scope an app lives in right now — scans everything if it has never scanned it before */
|
|
104667
104737
|
rescanScopeOf(ref, opts = {}) {
|
|
104668
|
-
const key = ref.projectId ??
|
|
104738
|
+
const key = ref.projectId ?? USER_APP_SCOPE;
|
|
104669
104739
|
if (this.scopes.has(key)) this.rescan(key, opts);
|
|
104670
104740
|
else this.refresh();
|
|
104671
104741
|
}
|
|
@@ -104803,7 +104873,7 @@ var ExternalApps = class {
|
|
|
104803
104873
|
ref = this.resolve(ref);
|
|
104804
104874
|
this.rescanScopeOf(ref);
|
|
104805
104875
|
const e = this.find(ref);
|
|
104806
|
-
if (e && keepsVersions(e)) this.handover.snapshot(
|
|
104876
|
+
if (e && keepsVersions(e)) this.handover.snapshot(appKeyOf(ref), e.dir, "imported");
|
|
104807
104877
|
}
|
|
104808
104878
|
cancelImport(token2) {
|
|
104809
104879
|
this.handover.cancel(token2);
|
|
@@ -104836,7 +104906,7 @@ var ExternalApps = class {
|
|
|
104836
104906
|
ref = this.resolve(ref);
|
|
104837
104907
|
this.rescanScopeOf(ref);
|
|
104838
104908
|
if (!this.keepsVersions(ref)) throw new AppUnavailableError("Project apps are versioned by git");
|
|
104839
|
-
return this.handover.versionsOf(
|
|
104909
|
+
return this.handover.versionsOf(appKeyOf(ref), this.require(ref).dir);
|
|
104840
104910
|
}
|
|
104841
104911
|
/**
|
|
104842
104912
|
* Restores one version — captures the current code as a version before writing it back, clears the
|
|
@@ -104851,7 +104921,7 @@ var ExternalApps = class {
|
|
|
104851
104921
|
this.rescanScopeOf(ref);
|
|
104852
104922
|
if (!this.keepsVersions(ref)) throw new AppUnavailableError("A project app's versions are its git history; restore it with git");
|
|
104853
104923
|
const before = this.require(ref);
|
|
104854
|
-
this.handover.restore(
|
|
104924
|
+
this.handover.restore(appKeyOf(ref), id3, before.dir, { root: before.found.root === true });
|
|
104855
104925
|
this.rescanScopeOf(ref, { now: ref.appId });
|
|
104856
104926
|
const e = this.require(ref);
|
|
104857
104927
|
resetLife(e.life);
|
|
@@ -104880,13 +104950,9 @@ var ExternalApps = class {
|
|
|
104880
104950
|
ref = this.resolve(ref);
|
|
104881
104951
|
this.reflector.builderTurnEnded(ref);
|
|
104882
104952
|
}
|
|
104883
|
-
/** The key for an open screen. Since this is never used in a path, it does not care about a project id's shape (unlike scopeDir) */
|
|
104884
|
-
holdKey(ref) {
|
|
104885
|
-
return appKeyOf(ref.projectId, ref.appId);
|
|
104886
|
-
}
|
|
104887
104953
|
/** An app that is gone takes its error bundles with it (`ErrorLog.forget`) */
|
|
104888
104954
|
forgetErrors(ref) {
|
|
104889
|
-
this.errorLog.forget(
|
|
104955
|
+
this.errorLog.forget(appKeyOf(ref));
|
|
104890
104956
|
}
|
|
104891
104957
|
label(ref) {
|
|
104892
104958
|
return appLabel(ref);
|
|
@@ -104900,7 +104966,7 @@ var ExternalApps = class {
|
|
|
104900
104966
|
* takes a ref resolves it first, so trust and every other rule apply to the app it reaches, as to its new key.
|
|
104901
104967
|
*/
|
|
104902
104968
|
resolve(ref) {
|
|
104903
|
-
if (ref.projectId !== null || this.scopes.get(
|
|
104969
|
+
if (ref.projectId !== null || this.scopes.get(USER_APP_SCOPE)?.apps.has(ref.appId)) return ref;
|
|
104904
104970
|
const projectId = this.deps.adoptedProjectOf?.(ref.appId);
|
|
104905
104971
|
const e = projectId ? this.scopes.get(projectId)?.apps.get(ref.appId) : void 0;
|
|
104906
104972
|
return e?.found.root ? e.ref : ref;
|
|
@@ -104911,11 +104977,11 @@ var ExternalApps = class {
|
|
|
104911
104977
|
return e;
|
|
104912
104978
|
}
|
|
104913
104979
|
find(ref) {
|
|
104914
|
-
return this.scopes.get(ref.projectId ??
|
|
104980
|
+
return this.scopes.get(ref.projectId ?? USER_APP_SCOPE)?.apps.get(ref.appId);
|
|
104915
104981
|
}
|
|
104916
104982
|
info(e) {
|
|
104917
104983
|
const m = e.manifest;
|
|
104918
|
-
const lastErrorAt = this.errorLog.lastAt(
|
|
104984
|
+
const lastErrorAt = this.errorLog.lastAt(appKeyOf(e.ref));
|
|
104919
104985
|
return {
|
|
104920
104986
|
appId: e.ref.appId,
|
|
104921
104987
|
projectId: e.ref.projectId,
|
|
@@ -104980,7 +105046,7 @@ var ExternalApps = class {
|
|
|
104980
105046
|
}
|
|
104981
105047
|
const held3 = this.held(e);
|
|
104982
105048
|
if (held3) return { kind: "unconfirmed", reason: held3 };
|
|
104983
|
-
if (this.removing.has(
|
|
105049
|
+
if (this.removing.has(appKeyOf(e.ref))) return { kind: "removing", reason: "This app is being removed" };
|
|
104984
105050
|
if (e.life.gaveUp && !opts.fresh) {
|
|
104985
105051
|
return {
|
|
104986
105052
|
kind: "failed",
|
|
@@ -105128,9 +105194,9 @@ var InlineViews = class {
|
|
|
105128
105194
|
const v = this.bySession.get(sessionId)?.get(callId);
|
|
105129
105195
|
if (!v || !v.kept) refuse3("This view's result is no longer kept. Open the app instead");
|
|
105130
105196
|
if (!v.instanceId) {
|
|
105131
|
-
const
|
|
105132
|
-
if (
|
|
105133
|
-
if (this.deps.rt.list().find((a) => a
|
|
105197
|
+
const gone2 = this.unavailable(v.ref);
|
|
105198
|
+
if (gone2) refuse3(gone2);
|
|
105199
|
+
if (this.deps.rt.list().find((a) => sameApp(a, v.ref))?.status === "failed") {
|
|
105134
105200
|
refuse3("This app stopped after failing repeatedly. Restart it, then reopen this view");
|
|
105135
105201
|
}
|
|
105136
105202
|
const refusal2 = await this.refusal(v.ref, v.uri);
|
|
@@ -105380,7 +105446,7 @@ var InlineViews = class {
|
|
|
105380
105446
|
* language, since it stands as is in the view.
|
|
105381
105447
|
*/
|
|
105382
105448
|
unavailable(ref) {
|
|
105383
|
-
const info = this.deps.rt.list().find((a) => a
|
|
105449
|
+
const info = this.deps.rt.list().find((a) => sameApp(a, ref));
|
|
105384
105450
|
if (!info) return "This app was removed";
|
|
105385
105451
|
if (info.status === "untrusted") return "This app's project is no longer trusted";
|
|
105386
105452
|
if (info.status === "unconfirmed") return info.error ?? "This imported app is not enabled";
|
|
@@ -106451,6 +106517,7 @@ function hostAccessEnv(access4) {
|
|
|
106451
106517
|
}
|
|
106452
106518
|
|
|
106453
106519
|
// packages/agent-host/src/links/machine-reach.ts
|
|
106520
|
+
var LOOKUP_MS = 4e3;
|
|
106454
106521
|
var TAIL = { tryAgain: "try again once its link is back", readAgain: "read it again once its link is back", none: null };
|
|
106455
106522
|
var notReachable = (m) => m.whyDown ? `${NOT_REACHABLE}; ${oneLineText(m.whyDown, 300)}` : NOT_REACHABLE;
|
|
106456
106523
|
var awaySentence = (m, tail) => m.waitsForPerson ? `${m.name} ${awayPhrase(NOT_CONNECTED)}, then try again` : `${m.name} is ${notReachable(m)}${tail === null ? "" : `; ${tail}`}`;
|
|
@@ -106953,9 +107020,8 @@ async function gitBranches(cwd) {
|
|
|
106953
107020
|
|
|
106954
107021
|
// packages/agent-host/src/dev-services/git-write.ts
|
|
106955
107022
|
function gitWrite(cwd, args, signal) {
|
|
106956
|
-
return runGit(cwd, args, { allowRepoPrograms: true, timeout:
|
|
107023
|
+
return runGit(cwd, args, { allowRepoPrograms: true, timeout: GIT_WRITE_TIMEOUT_MS, signal });
|
|
106957
107024
|
}
|
|
106958
|
-
var WRITE_TIMEOUT_MS = 10 * 6e4;
|
|
106959
107025
|
async function gitCheckout(cwd, branch, opts = {}) {
|
|
106960
107026
|
if (!await isRepo(cwd)) return { ok: false, conflicts: [], message: "Not a git repository" };
|
|
106961
107027
|
if (opts.dryRun) {
|
|
@@ -107061,7 +107127,7 @@ function cloneArgs(url2, into, branch) {
|
|
|
107061
107127
|
function cloneFailure(e, url2, branch) {
|
|
107062
107128
|
const err = execFailure(e);
|
|
107063
107129
|
if (err.code === "ENOENT") return "git is not installed on this machine, so nothing can be cloned.";
|
|
107064
|
-
if (err.timedOut) return `The clone took longer than ${CLONE_TIMEOUT_MS
|
|
107130
|
+
if (err.timedOut) return `The clone took longer than ${durationText(CLONE_TIMEOUT_MS)} and was stopped; nothing was kept.`;
|
|
107065
107131
|
const stderr = err.stderr ?? err.message ?? "";
|
|
107066
107132
|
if (/terminal prompts disabled|could not read (Username|Password)|Authentication failed|Permission denied \(|Host key verification failed|HTTP Basic: Access denied|returned error: 40[13]/i.test(stderr)) {
|
|
107067
107133
|
return `${url2} needs a sign-in this machine does not have saved \u2014 sign in to it on that machine (or use an address it can reach), then try again.`;
|
|
@@ -107356,8 +107422,8 @@ async function prepareWorktreeDependencies(projectCwd, worktreeCwd) {
|
|
|
107356
107422
|
if (err.code === "ENOENT") return [];
|
|
107357
107423
|
throw err;
|
|
107358
107424
|
});
|
|
107359
|
-
for (const
|
|
107360
|
-
console.error(`[worktree] link dropped (points outside the worktree): ${
|
|
107425
|
+
for (const gone2 of removed) {
|
|
107426
|
+
console.error(`[worktree] link dropped (points outside the worktree): ${gone2}`);
|
|
107361
107427
|
}
|
|
107362
107428
|
}
|
|
107363
107429
|
}
|
|
@@ -107885,8 +107951,8 @@ var WorktreeSessions = class {
|
|
|
107885
107951
|
if (err.code === "ENOENT") return [];
|
|
107886
107952
|
throw err;
|
|
107887
107953
|
});
|
|
107888
|
-
for (const
|
|
107889
|
-
problem3(`link dropped (points outside the worktree): ${
|
|
107954
|
+
for (const gone2 of landed) {
|
|
107955
|
+
problem3(`link dropped (points outside the worktree): ${gone2}`);
|
|
107890
107956
|
}
|
|
107891
107957
|
}
|
|
107892
107958
|
await prepareWorktreeDependencies(projectCwd, worktree.path).catch((err) => {
|
|
@@ -107903,7 +107969,7 @@ var WorktreeSessions = class {
|
|
|
107903
107969
|
if (ran.code === 0 && !ran.ended) {
|
|
107904
107970
|
console.error(`[worktree] setup ok (${worktree.branch}): ${setup.command}`);
|
|
107905
107971
|
} else {
|
|
107906
|
-
const why2 = ran.ended ? `it did not finish within ${SETUP_TIMEOUT_MS
|
|
107972
|
+
const why2 = ran.ended ? `it did not finish within ${durationText(SETUP_TIMEOUT_MS)}` : `exit ${String(ran.code ?? ran.signal)}`;
|
|
107907
107973
|
const stderr = ran.stderr.toString("utf8");
|
|
107908
107974
|
console.error(`[worktree] setup failed (${worktree.branch}): ${why2}
|
|
107909
107975
|
${stderr.slice(0, 2e3)}`);
|
|
@@ -108073,7 +108139,7 @@ ${stderr.slice(0, 2e3)}`);
|
|
|
108073
108139
|
*/
|
|
108074
108140
|
async cleanUpGoneWorktree(target, cwd, branch, path2) {
|
|
108075
108141
|
const setAside = { changedFiles: 0, commits: 0 };
|
|
108076
|
-
const
|
|
108142
|
+
const gone2 = `The worktree folder was already gone (${path2})`;
|
|
108077
108143
|
await this.host.trashSession(target.id, false, false, void 0, true);
|
|
108078
108144
|
const key = canonicalKey(path2);
|
|
108079
108145
|
const listedNow = async () => (await gitWorktreeList(cwd)).some((w) => canonicalKey(w.path) === key);
|
|
@@ -108083,9 +108149,9 @@ ${stderr.slice(0, 2e3)}`);
|
|
|
108083
108149
|
await gitWorktreePrune(cwd);
|
|
108084
108150
|
entry = !had ? "git had no entry for it" : await listedNow().catch(() => true) ? "git's entry for it is still listed" : "git's entry was pruned";
|
|
108085
108151
|
} catch (e) {
|
|
108086
|
-
return { ok: true, branch, setAside, note: `${
|
|
108152
|
+
return { ok: true, branch, setAside, note: `${gone2}, but git's entry for it could not be pruned (${e.message}); branch ${branch} was left.` };
|
|
108087
108153
|
}
|
|
108088
|
-
const head = `${
|
|
108154
|
+
const head = `${gone2}; the session is in the session archive and ${entry}.`;
|
|
108089
108155
|
if (await gitRevParse(cwd, `refs/heads/${branch}`) === null) {
|
|
108090
108156
|
return { ok: true, branch, setAside, note: `${head} Branch ${branch} was already gone.` };
|
|
108091
108157
|
}
|
|
@@ -108542,10 +108608,9 @@ function progressOf(reader, sessionId, now = Date.now()) {
|
|
|
108542
108608
|
const last = reader.loadMessages(sessionId, 1).at(-1);
|
|
108543
108609
|
if (!last) return void 0;
|
|
108544
108610
|
const ms3 = Math.max(0, now - last.ts);
|
|
108545
|
-
const quietFor = ms3 < 6e4 ? `${Math.floor(ms3 / 1e3)} s` : ms3 < 36e5 ? `${Math.floor(ms3 / 6e4)} min` : `${Math.floor(ms3 / 36e5)} h`;
|
|
108546
108611
|
const summary = last.payload?.summary;
|
|
108547
108612
|
const lastStep = last.kind === "tool_call" && typeof summary?.title === "string" ? `${typeof summary.tool === "string" ? summary.tool : "tool"}: ${summary.title.split("\n")[0].slice(0, 100)}` : last.kind === "tool_result" ? "a tool call returned" : last.kind === "reasoning" ? "thinking" : last.kind === "text" && last.role === "assistant" ? "writing" : last.kind === "text" && last.role === "user" ? "took in a message" : void 0;
|
|
108548
|
-
return { quietFor, ...lastStep ? { lastStep } : {} };
|
|
108613
|
+
return { quietFor: durationText(ms3), ...lastStep ? { lastStep } : {} };
|
|
108549
108614
|
}
|
|
108550
108615
|
function lastActiveOf(reader, sessionId) {
|
|
108551
108616
|
const rows3 = reader.loadMessages(sessionId, 1);
|
|
@@ -109633,7 +109698,7 @@ var REFUSAL_TEXT = {
|
|
|
109633
109698
|
not_allowed: () => "that is not a party that takes mail",
|
|
109634
109699
|
withheld: (id3) => `${id3} is a request: its words are shown in the turn it starts, and it is marked done there.`,
|
|
109635
109700
|
not_yours: (id3) => `you were not sent ${id3} and did not send it.`,
|
|
109636
|
-
repeat: (name) => `you sent the same text to ${name} less than ${REPEAT_WINDOW_MS
|
|
109701
|
+
repeat: (name) => `you sent the same text to ${name} less than ${durationText(REPEAT_WINDOW_MS)} ago.`,
|
|
109637
109702
|
ask_rate: () => `your project's sessions asked the Assistant ${ASKS_PER_HOUR} times in the last hour; wait, or write to the person.`,
|
|
109638
109703
|
assistant_asks: () => "the Assistant runs on a tool that cannot ask the person for each step of a request yet, so a session cannot ask it: write to the person instead",
|
|
109639
109704
|
untrusted_project: (project2, target) => `your project ${project2} is not trusted, so work you give outside it (to ${target}) waits for the person to trust ${project2}. Nothing was started. Centralu shows the person how, and tells you when ${project2} is trusted; give it again then.`
|
|
@@ -109643,7 +109708,7 @@ var WARNING_TEXT = {
|
|
|
109643
109708
|
host: (turns) => `Mail between sessions started ${turns} turns on this computer in the last hour. It still goes: look at the busy sessions if that is more than you expect.`,
|
|
109644
109709
|
compactCycles: (session2, cycles) => `${session2} asked to compact its conversation and went on to its next step ${cycles} times in the last hour. It keeps working: look at it if that is more than you expect.`,
|
|
109645
109710
|
/** The three guards that refuse rather than warn (#1684, #2035): the person hears of the first refusal of each kind a clock hour */
|
|
109646
|
-
repeat: (sender, to) => `Centralu refused mail from ${sender} to ${to}: the same text again within ${REPEAT_WINDOW_MS
|
|
109711
|
+
repeat: (sender, to) => `Centralu refused mail from ${sender} to ${to}: the same text again within ${durationText(REPEAT_WINDOW_MS)}. ${sender} was told; nothing else was stopped.`,
|
|
109647
109712
|
rate_limited: (sender, limit) => `Centralu refused mail from ${sender}: more than ${limit} messages in a minute. ${sender} was told to wait; nothing else was stopped.`,
|
|
109648
109713
|
ask_rate: (sender) => `Centralu refused a request from ${sender} to the Assistant: its project's sessions asked ${ASKS_PER_HOUR} times in the last hour. ${sender} was told to wait or write to you.`
|
|
109649
109714
|
};
|
|
@@ -110182,6 +110247,25 @@ var MailDelivery = class {
|
|
|
110182
110247
|
// packages/agent-host/src/sessions/delegated-cards.ts
|
|
110183
110248
|
import { createHash as createHash10 } from "node:crypto";
|
|
110184
110249
|
|
|
110250
|
+
// packages/agent-host/src/apps/contract.ts
|
|
110251
|
+
var CENTRALU_MCP_NAME = RESERVED_NAME_PREFIX;
|
|
110252
|
+
function mcpServerNameError(name) {
|
|
110253
|
+
switch (serverNameProblem(name)) {
|
|
110254
|
+
case "reserved":
|
|
110255
|
+
return `A name starting with "${CENTRALU_MCP_NAME}" is the name this app uses \u2014 suggest a different name`;
|
|
110256
|
+
case "shape":
|
|
110257
|
+
return "A name must be lowercase letters, digits, and hyphens, 32 characters or fewer (underscores cannot be used \u2014 they separate parts of a tool name)";
|
|
110258
|
+
case null:
|
|
110259
|
+
return null;
|
|
110260
|
+
}
|
|
110261
|
+
}
|
|
110262
|
+
function proposedMcpServerNameError(name) {
|
|
110263
|
+
const base2 = mcpServerNameError(name);
|
|
110264
|
+
if (base2) return base2;
|
|
110265
|
+
const problem3 = newAppIdProblem(name);
|
|
110266
|
+
return problem3 === "server-prefix" || problem3 === "builtin" ? appIdProblemText(name, problem3) : null;
|
|
110267
|
+
}
|
|
110268
|
+
|
|
110185
110269
|
// packages/agent-host/src/sessions/app-guide.ts
|
|
110186
110270
|
var APP_GUIDE_TOPICS = ["overview", "sessions", "assistant", "apps", "approvals", "settings", "updates"];
|
|
110187
110271
|
var STATIC = {
|
|
@@ -113848,26 +113932,26 @@ Reason: ${why2.slice(0, 600)}`,
|
|
|
113848
113932
|
|
|
113849
113933
|
// packages/agent-host/src/sessions/start-agent-flow.ts
|
|
113850
113934
|
function startAgentLate(progress) {
|
|
113851
|
-
const
|
|
113935
|
+
const seconds = Math.round(START_AGENT_SETUP_MS / 1e3);
|
|
113852
113936
|
const note = progress.unchecked ? ` (${progress.unchecked}.)` : "";
|
|
113853
113937
|
switch (progress.stage) {
|
|
113854
113938
|
case "created":
|
|
113855
113939
|
return {
|
|
113856
113940
|
ok: false,
|
|
113857
|
-
error: `The session [${progress.childId}] was created, but handing it the task took longer than ${
|
|
113941
|
+
error: `The session [${progress.childId}] was created, but handing it the task took longer than ${seconds} seconds. Do not start another: agent_session(sessionId="${progress.childId}", action="status") shows where it stands. ${ASK_THE_PERSON}${note}`
|
|
113858
113942
|
};
|
|
113859
113943
|
case "creating":
|
|
113860
113944
|
return {
|
|
113861
113945
|
ok: false,
|
|
113862
|
-
error: `Starting the session took longer than ${
|
|
113946
|
+
error: `Starting the session took longer than ${seconds} seconds and had not finished, so a session may or may not exist. Do not call start_agent again until read_session (without a sessionId) shows whether a new session is there; if one starts, you will be told when it ends. ${ASK_THE_PERSON}${note}`
|
|
113863
113947
|
};
|
|
113864
113948
|
case "asking":
|
|
113865
113949
|
return {
|
|
113866
113950
|
ok: false,
|
|
113867
|
-
error: `No session was created: the person did not answer the question in this session within ${
|
|
113951
|
+
error: `No session was created: the person did not answer the question in this session within ${seconds} seconds, so it was withdrawn. ${ASK_THE_PERSON}`
|
|
113868
113952
|
};
|
|
113869
113953
|
default:
|
|
113870
|
-
return { ok: false, error: `No session was created: checking the request took longer than ${
|
|
113954
|
+
return { ok: false, error: `No session was created: checking the request took longer than ${seconds} seconds. Try again once; if it repeats, ask the person. ${ASK_THE_PERSON}` };
|
|
113871
113955
|
}
|
|
113872
113956
|
}
|
|
113873
113957
|
var AgentStartFlow = class {
|
|
@@ -114488,10 +114572,10 @@ var DelegationWaits = class {
|
|
|
114488
114572
|
/** Resolves `gone` when a handoff gives this delegation (or start request) to another session (#693); `done` lets go */
|
|
114489
114573
|
untilHandedOver(d2) {
|
|
114490
114574
|
let leave;
|
|
114491
|
-
const
|
|
114575
|
+
const gone2 = new Promise((resolve21) => leave = () => resolve21("handedOver"));
|
|
114492
114576
|
const set3 = d2.leaving ??= /* @__PURE__ */ new Set();
|
|
114493
114577
|
set3.add(leave);
|
|
114494
|
-
return { gone, done: () => set3.delete(leave) };
|
|
114578
|
+
return { gone: gone2, done: () => set3.delete(leave) };
|
|
114495
114579
|
}
|
|
114496
114580
|
/**
|
|
114497
114581
|
* What an original that stays after a handoff hears about work the handoff gave away (#693), or undefined: where it
|
|
@@ -114762,8 +114846,8 @@ var AgentSessionActions = class {
|
|
|
114762
114846
|
if (refused2) return { ok: false, error: refused2 };
|
|
114763
114847
|
return this.flow.remote.agentSession(callerId, remote, opts, signal);
|
|
114764
114848
|
}
|
|
114765
|
-
const
|
|
114766
|
-
if (
|
|
114849
|
+
const gone2 = this.flow.handedOverAnswer(callerId, opts.sessionId);
|
|
114850
|
+
if (gone2) return gone2;
|
|
114767
114851
|
const request = this.host.children.agentStarts.get(opts.sessionId);
|
|
114768
114852
|
if (request && request.req.callerId === callerId) {
|
|
114769
114853
|
const r = await this.agentStartSession(request, opts.action, signal);
|
|
@@ -115257,10 +115341,10 @@ var RemoteAgents = class {
|
|
|
115257
115341
|
const above = !presetWithin(childPreset, this.callerPreset(callerId));
|
|
115258
115342
|
if (above || unasked && childPreset !== "auto") {
|
|
115259
115343
|
const why2 = above ? `this session now runs under ${this.callerPreset(callerId)}, below the ${childPreset} the session made there runs under` : `${machine.name} no longer takes auto from this computer (its "Allow auto from a linked computer" setting was turned off)`;
|
|
115260
|
-
const
|
|
115344
|
+
const gone2 = await reader.deleteSession(made.sessionId);
|
|
115261
115345
|
return {
|
|
115262
115346
|
ok: false,
|
|
115263
|
-
error: `${why2}, so the session made there was given no task and went to ${machine.name}'s session archive${
|
|
115347
|
+
error: `${why2}, so the session made there was given no task and went to ${machine.name}'s session archive${gone2.ok ? "" : `, or would have: it could not be deleted (${bare(gone2.error)}), so "${made.name}" stays there with no task`}. Start it again to ask the person. ${ASK_THE_PERSON}`
|
|
115264
115348
|
};
|
|
115265
115349
|
}
|
|
115266
115350
|
const label = labelOf(this.host.store.messages, caller);
|
|
@@ -116775,9 +116859,6 @@ function isServerOverloaded(errorInfo) {
|
|
|
116775
116859
|
|
|
116776
116860
|
// packages/agent-host/src/sessions/overload-retry.ts
|
|
116777
116861
|
var DELAYS_MS = [3e4, 12e4, 3e5, 6e5];
|
|
116778
|
-
function waitWords(ms3) {
|
|
116779
|
-
return ms3 >= 6e4 ? `${Math.round(ms3 / 6e4)} min` : `${Math.round(ms3 / 1e3)} s`;
|
|
116780
|
-
}
|
|
116781
116862
|
var OverloadRetry = class {
|
|
116782
116863
|
constructor(host) {
|
|
116783
116864
|
this.host = host;
|
|
@@ -116816,7 +116897,7 @@ ${spentWords(tries)}` } };
|
|
|
116816
116897
|
level: "warning",
|
|
116817
116898
|
from: "Centralu",
|
|
116818
116899
|
label: "retry",
|
|
116819
|
-
text: `The model's servers are at capacity, which is not your usage limit. Centralu retries this turn in ${
|
|
116900
|
+
text: `The model's servers are at capacity, which is not your usage limit. Centralu retries this turn in ${durationText(wait)} (retry ${tries + 1} of ${DELAYS_MS.length}). Stop cancels it.`
|
|
116820
116901
|
};
|
|
116821
116902
|
}
|
|
116822
116903
|
/** Every event of a session: the ones that end the turn take a wait away, and start the count over */
|
|
@@ -117177,143 +117258,6 @@ var MergeChecks = class {
|
|
|
117177
117258
|
}
|
|
117178
117259
|
};
|
|
117179
117260
|
|
|
117180
|
-
// packages/agent-host/src/themes.ts
|
|
117181
|
-
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
117182
|
-
import { watch as watch3 } from "node:fs";
|
|
117183
|
-
import { mkdir as mkdir4, readdir as readdir7, readFile as readFile4, stat as stat7 } from "node:fs/promises";
|
|
117184
|
-
import { basename as basename8, join as join30 } from "node:path";
|
|
117185
|
-
var MAX_FILE_BYTES = 256 * 1024;
|
|
117186
|
-
var SETTLE_MS = 100;
|
|
117187
|
-
function themeSlug(name) {
|
|
117188
|
-
return name.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48) || "theme";
|
|
117189
|
-
}
|
|
117190
|
-
var REMOVED_DIR = ".removed";
|
|
117191
|
-
var ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,59}$/;
|
|
117192
|
-
var ThemeFiles = class {
|
|
117193
|
-
constructor(dir, onChange) {
|
|
117194
|
-
this.dir = dir;
|
|
117195
|
-
this.onChange = onChange;
|
|
117196
|
-
}
|
|
117197
|
-
dir;
|
|
117198
|
-
onChange;
|
|
117199
|
-
watcher = null;
|
|
117200
|
-
timer = null;
|
|
117201
|
-
/** Makes the folder, writes the schema next to the themes, and starts watching */
|
|
117202
|
-
async start() {
|
|
117203
|
-
await mkdir4(this.dir, { recursive: true });
|
|
117204
|
-
await this.writeSchema();
|
|
117205
|
-
try {
|
|
117206
|
-
this.watcher = watch3(this.dir, (_event, name) => {
|
|
117207
|
-
if (name && !String(name).endsWith(".json")) return;
|
|
117208
|
-
if (name === THEME_SCHEMA_FILE) return;
|
|
117209
|
-
if (this.timer) clearTimeout(this.timer);
|
|
117210
|
-
this.timer = setTimeout(() => {
|
|
117211
|
-
this.timer = null;
|
|
117212
|
-
this.onChange();
|
|
117213
|
-
}, SETTLE_MS);
|
|
117214
|
-
});
|
|
117215
|
-
this.watcher.on("error", () => this.stopWatching());
|
|
117216
|
-
} catch {
|
|
117217
|
-
}
|
|
117218
|
-
}
|
|
117219
|
-
close() {
|
|
117220
|
-
this.stopWatching();
|
|
117221
|
-
if (this.timer) clearTimeout(this.timer);
|
|
117222
|
-
this.timer = null;
|
|
117223
|
-
}
|
|
117224
|
-
stopWatching() {
|
|
117225
|
-
this.watcher?.close();
|
|
117226
|
-
this.watcher = null;
|
|
117227
|
-
}
|
|
117228
|
-
/**
|
|
117229
|
-
* The schema an editor uses for completion, written only when it differs — a build that adds
|
|
117230
|
-
* a token updates it, and an unchanged one does not touch the folder (or wake the watcher).
|
|
117231
|
-
*/
|
|
117232
|
-
async writeSchema() {
|
|
117233
|
-
const path2 = join30(this.dir, THEME_SCHEMA_FILE);
|
|
117234
|
-
const text3 = `${JSON.stringify(themeFileJsonSchema(), null, 2)}
|
|
117235
|
-
`;
|
|
117236
|
-
const current = await readFile4(path2, "utf8").catch(() => null);
|
|
117237
|
-
if (current !== text3) writeFileWhole(realOs().files, path2, text3);
|
|
117238
|
-
}
|
|
117239
|
-
/** Every `<id>.json` in the folder, read and checked. A file that cannot be read is listed with the reason. */
|
|
117240
|
-
async list() {
|
|
117241
|
-
const names = await readdir7(this.dir).catch(() => []);
|
|
117242
|
-
const entries = [];
|
|
117243
|
-
const ids = names.filter((name) => name.endsWith(".json") && name !== THEME_SCHEMA_FILE).map((name) => name.slice(0, -".json".length)).filter((id3) => ID_PATTERN.test(id3)).sort();
|
|
117244
|
-
for (const id3 of ids) entries.push(await this.read(id3));
|
|
117245
|
-
return entries;
|
|
117246
|
-
}
|
|
117247
|
-
async read(id3) {
|
|
117248
|
-
const path2 = this.pathOf(id3);
|
|
117249
|
-
try {
|
|
117250
|
-
const info = await stat7(path2);
|
|
117251
|
-
if (info.size > MAX_FILE_BYTES) {
|
|
117252
|
-
return { id: id3, path: path2, name: id3, base: "dark", tokens: {}, problems: ["The file is too large to be a theme."], broken: true };
|
|
117253
|
-
}
|
|
117254
|
-
return parseThemeFile(id3, path2, await readFile4(path2, "utf8"));
|
|
117255
|
-
} catch (e) {
|
|
117256
|
-
return { id: id3, path: path2, name: id3, base: "dark", tokens: {}, problems: [`Could not read the file: ${e.message}`], broken: true };
|
|
117257
|
-
}
|
|
117258
|
-
}
|
|
117259
|
-
/** Writes a theme. `id` null makes a new file named after the theme (`My theme` → `my-theme.json`). */
|
|
117260
|
-
async save(id3, content) {
|
|
117261
|
-
const text3 = formatThemeFile(content);
|
|
117262
|
-
if (Buffer.byteLength(text3) > MAX_FILE_BYTES) throw rpcError("The theme is too large to be a theme file.");
|
|
117263
|
-
const target = id3 ?? await this.freeId(content.name);
|
|
117264
|
-
await mkdir4(this.dir, { recursive: true });
|
|
117265
|
-
const names = await readdir7(this.dir).catch(() => []);
|
|
117266
|
-
const clash = names.find((n) => n !== `${target}.json` && n.toLowerCase() === `${target}.json`);
|
|
117267
|
-
if (clash) throw rpcError(`The themes folder has ${clash}, which the list does not show (ids are lowercase); rename or remove it first.`);
|
|
117268
|
-
writeFileWhole(realOs().files, this.pathOf(target), text3);
|
|
117269
|
-
return this.read(target);
|
|
117270
|
-
}
|
|
117271
|
-
/**
|
|
117272
|
-
* Takes a theme file out of the list without destroying it: it moves to `.removed/<id>-<time>-<random>.json`, a place the list
|
|
117273
|
-
* does not look, so a mistaken removal is one move back. The host has no OS trash (Settings' button reaches it through the
|
|
117274
|
-
* shell), so these stay until the person clears the folder. Where it went is returned; null when there was no such file.
|
|
117275
|
-
*/
|
|
117276
|
-
async remove(id3) {
|
|
117277
|
-
const from = this.pathOf(id3);
|
|
117278
|
-
if (!await stat7(from).then(() => true, () => false)) return null;
|
|
117279
|
-
const kept = join30(this.dir, REMOVED_DIR);
|
|
117280
|
-
await mkdir4(kept, { recursive: true });
|
|
117281
|
-
const to = join30(kept, `${id3}-${Date.now()}-${randomBytes7(3).toString("hex")}.json`);
|
|
117282
|
-
await realOs().files.promises.rename(from, to);
|
|
117283
|
-
return to;
|
|
117284
|
-
}
|
|
117285
|
-
/** Copies a file from elsewhere in, under a fresh id if its name is taken. Refuses what does not read as a theme. */
|
|
117286
|
-
async importFrom(source) {
|
|
117287
|
-
const info = await stat7(source);
|
|
117288
|
-
if (!info.isFile()) throw rpcError("That is not a file.");
|
|
117289
|
-
if (info.size > MAX_FILE_BYTES) throw rpcError("The file is too large to be a theme.");
|
|
117290
|
-
const text3 = await readFile4(source, "utf8");
|
|
117291
|
-
const parsed = parseThemeFile("import", source, text3);
|
|
117292
|
-
if (parsed.broken) throw rpcError(parsed.problems[0] ?? "Not a theme file.");
|
|
117293
|
-
const fromName = basename8(source).replace(/\.json$/i, "");
|
|
117294
|
-
const id3 = await this.freeId(parsed.name !== "import" ? parsed.name : fromName);
|
|
117295
|
-
writeFileWhole(realOs().files, this.pathOf(id3), text3);
|
|
117296
|
-
return this.read(id3);
|
|
117297
|
-
}
|
|
117298
|
-
/** The absolute path for an id, for the shell to trash or reveal. Refuses anything that is not an id. */
|
|
117299
|
-
pathOf(id3) {
|
|
117300
|
-
if (!ID_PATTERN.test(id3)) throw rpcError(`Not a theme id: ${id3}`);
|
|
117301
|
-
return join30(this.dir, `${id3}.json`);
|
|
117302
|
-
}
|
|
117303
|
-
async freeId(name) {
|
|
117304
|
-
const base2 = themeSlug(name);
|
|
117305
|
-
for (let n = 1; n < 1e3; n++) {
|
|
117306
|
-
const id3 = n === 1 ? base2 : `${base2}-${n}`;
|
|
117307
|
-
const taken = await stat7(this.pathOf(id3)).then(
|
|
117308
|
-
() => true,
|
|
117309
|
-
() => false
|
|
117310
|
-
);
|
|
117311
|
-
if (!taken) return id3;
|
|
117312
|
-
}
|
|
117313
|
-
return `${base2}-${randomBytes7(4).toString("hex")}`;
|
|
117314
|
-
}
|
|
117315
|
-
};
|
|
117316
|
-
|
|
117317
117261
|
// packages/agent-host/src/sessions/window-rpc.ts
|
|
117318
117262
|
var WINDOW_METHODS = [
|
|
117319
117263
|
"prefs.get",
|
|
@@ -117420,7 +117364,7 @@ var PreferencesFlow = class {
|
|
|
117420
117364
|
]);
|
|
117421
117365
|
if (prefs.status === "rejected") return { ok: false, error: `Could not read the preferences: ${prefs.reason instanceof Error ? prefs.reason.message : String(prefs.reason)}` };
|
|
117422
117366
|
const p = prefs.value;
|
|
117423
|
-
const choices = themes2.status === "fulfilled" ?
|
|
117367
|
+
const choices = pickableThemes(themes2.status === "fulfilled" ? themes2.value : []);
|
|
117424
117368
|
const named3 = (id3) => {
|
|
117425
117369
|
const c = choices.find((x) => x.id === id3);
|
|
117426
117370
|
return c ? `${plainQuoted(c.name)} [${c.id}]` : `[${plainQuoted(id3)}] (no such theme; the stylesheet's own is shown)`;
|
|
@@ -117462,6 +117406,8 @@ var PreferencesFlow = class {
|
|
|
117462
117406
|
if (file2 !== void 0) {
|
|
117463
117407
|
const bad = themeFileRefusal(file2);
|
|
117464
117408
|
if (bad) return { ok: false, error: bad };
|
|
117409
|
+
const named3 = file2.id?.trim();
|
|
117410
|
+
if (named3 && isPresetThemeId(named3) && !(await callWindow(rpc, "themes.list", {})).some((f) => f.id === named3)) return { ok: false, error: `themeFile.id: ${presetIdRefusal(named3)}` };
|
|
117465
117411
|
}
|
|
117466
117412
|
if (changes.theme !== void 0) {
|
|
117467
117413
|
const found = await this.theme(rpc, changes.theme);
|
|
@@ -117498,9 +117444,11 @@ var PreferencesFlow = class {
|
|
|
117498
117444
|
if (sleep4 !== void 0 && sleep4 !== "never" && !(Number.isInteger(sleep4) && sleep4 > 0)) {
|
|
117499
117445
|
return { ok: false, error: `idleSleepMinutes is ${SLEEP_CHOICES}.` };
|
|
117500
117446
|
}
|
|
117447
|
+
let written = null;
|
|
117501
117448
|
if (file2 !== void 0) {
|
|
117502
117449
|
try {
|
|
117503
117450
|
const saved = await callWindow(rpc, "themes.save", { id: file2.id?.trim() || null, content: { name: file2.name.trim(), base: file2.base, tokens: file2.tokens } });
|
|
117451
|
+
written = saved;
|
|
117504
117452
|
done2.push(themeFileWritten(saved));
|
|
117505
117453
|
} catch (e) {
|
|
117506
117454
|
return { ok: false, error: errorMessage(e) };
|
|
@@ -117508,18 +117456,13 @@ var PreferencesFlow = class {
|
|
|
117508
117456
|
}
|
|
117509
117457
|
let toApply = parsed.data;
|
|
117510
117458
|
if (changes.theme !== void 0) {
|
|
117511
|
-
const found = await this.theme(rpc, changes.theme);
|
|
117459
|
+
const found = await this.theme(rpc, written && changes.theme.trim().toLowerCase() === written.name.toLowerCase() ? written.id : changes.theme);
|
|
117512
117460
|
if (typeof found === "string") failed4.push(`Theme: not picked. ${found}`);
|
|
117513
117461
|
else {
|
|
117514
117462
|
theme = found;
|
|
117515
117463
|
patch.themeMode = found.base;
|
|
117516
117464
|
patch[found.base === "dark" ? "themeDark" : "themeLight"] = found.id;
|
|
117517
|
-
|
|
117518
|
-
if (again.success) toApply = again.data;
|
|
117519
|
-
else {
|
|
117520
|
-
theme = null;
|
|
117521
|
-
failed4.push(`Theme: not picked. ${issuesOf(again.error)}.`);
|
|
117522
|
-
}
|
|
117465
|
+
toApply = UiPreferencesPatch.parse(patch);
|
|
117523
117466
|
}
|
|
117524
117467
|
}
|
|
117525
117468
|
const attempt = async (what, run2) => {
|
|
@@ -117702,12 +117645,7 @@ var PreferencesFlow = class {
|
|
|
117702
117645
|
const named3 = file2.id?.trim().toLowerCase();
|
|
117703
117646
|
if (named3) return named3;
|
|
117704
117647
|
const taken = new Set((await callWindow(rpc, "themes.list", {})).map((f) => f.id));
|
|
117705
|
-
|
|
117706
|
-
for (let n = 1; n < 1e3; n++) {
|
|
117707
|
-
const id3 = n === 1 ? base2 : `${base2}-${n}`;
|
|
117708
|
-
if (!taken.has(id3)) return id3;
|
|
117709
|
-
}
|
|
117710
|
-
return base2;
|
|
117648
|
+
return freeThemeId(file2.name.trim(), (id3) => taken.has(id3));
|
|
117711
117649
|
}
|
|
117712
117650
|
/** The session header's action: idle sessions on an older agent CLI restart on the installed one, and the busy ones are named */
|
|
117713
117651
|
async applyVersions(rpc) {
|
|
@@ -117721,7 +117659,7 @@ var PreferencesFlow = class {
|
|
|
117721
117659
|
const wanted = ref.trim();
|
|
117722
117660
|
if (!wanted) return "theme is empty; get_preferences lists the themes to choose from.";
|
|
117723
117661
|
if (HIDDEN2.test(wanted)) return "theme has a control or formatting character in it; give its id or name as plain text.";
|
|
117724
|
-
const choices =
|
|
117662
|
+
const choices = pickableThemes(await callWindow(rpc, "themes.list", {}));
|
|
117725
117663
|
const byId = choices.find((c) => c.id === wanted.toLowerCase());
|
|
117726
117664
|
if (byId) return byId;
|
|
117727
117665
|
const byName = choices.filter((c) => c.name.toLowerCase() === wanted.toLowerCase());
|
|
@@ -117781,12 +117719,6 @@ function agentModelsText(models) {
|
|
|
117781
117719
|
);
|
|
117782
117720
|
return parts.length ? parts.join("; ") : "none chosen (each project keeps its last choice)";
|
|
117783
117721
|
}
|
|
117784
|
-
function themeChoices(files2) {
|
|
117785
|
-
return [
|
|
117786
|
-
...THEME_PRESETS.map((p) => ({ id: p.id, name: p.name, base: p.base, file: false })),
|
|
117787
|
-
...files2.filter((f) => !f.broken).map((f) => ({ id: f.id, name: f.name, base: f.base, file: true }))
|
|
117788
|
-
];
|
|
117789
|
-
}
|
|
117790
117722
|
function appearanceText(now, patch, theme) {
|
|
117791
117723
|
const parts = [];
|
|
117792
117724
|
if (theme) {
|
|
@@ -118026,13 +117958,13 @@ ${lost.map((l) => `- ${l}`).join("\n")}` : local ? "Nothing else is lost: no one
|
|
|
118026
117958
|
if (refused2) return { ok: false, error: refused2 };
|
|
118027
117959
|
const now = await this.read(rpc);
|
|
118028
117960
|
const nowById = new Map(now.sessions.map((s) => [s.id, s]));
|
|
118029
|
-
const
|
|
117961
|
+
const gone2 = [];
|
|
118030
117962
|
const failed4 = [];
|
|
118031
117963
|
let deleted = 0;
|
|
118032
117964
|
for (const s of named3.sessions) {
|
|
118033
117965
|
const current = nowById.get(s.id);
|
|
118034
117966
|
if (!current || !sameRow(s, current)) {
|
|
118035
|
-
|
|
117967
|
+
gone2.push(s.name);
|
|
118036
117968
|
continue;
|
|
118037
117969
|
}
|
|
118038
117970
|
try {
|
|
@@ -118067,7 +117999,7 @@ ${lost.map((l) => `- ${l}`).join("\n")}` : local ? "Nothing else is lost: no one
|
|
|
118067
117999
|
const left = await this.read(rpc).catch(() => null) ?? now;
|
|
118068
118000
|
const arrived = left.sessions.length + left.runs.length + left.steps.length;
|
|
118069
118001
|
const parts = [`Deleted for good: ${plural(deleted, "session")}${runsDeleted ? `, ${plural(runsDeleted, "app run")}` : ""}${stepsDeleted ? `, the subagent steps of ${plural(stepsDeleted, "session")}` : ""}.`];
|
|
118070
|
-
if (
|
|
118002
|
+
if (gone2.length) parts.push(`Not what the card named when it was answered (restored, deleted or deleted again meanwhile), so left alone: ${gone2.map(shown).join(", ")}.`);
|
|
118071
118003
|
if (failed4.length) parts.push(`Stayed in the session archive: ${failed4.join("; ")}`);
|
|
118072
118004
|
if (arrived) parts.push(`The session archive now holds ${plural(left.sessions.length, "session")}, ${plural(left.runs.length, "app run")} and subagent steps of ${plural(left.steps.length, "session")}.`);
|
|
118073
118005
|
return { ok: true, text: parts.join(" ") };
|
|
@@ -118438,7 +118370,7 @@ var TrustFlow = class {
|
|
|
118438
118370
|
].join("\n");
|
|
118439
118371
|
const refused2 = await this.ask(caller, question, signal, "shared");
|
|
118440
118372
|
if (refused2) return { ok: false, error: refused2 };
|
|
118441
|
-
const now = (await callWindow(rpc, "apps.list", {})).find((x) =>
|
|
118373
|
+
const now = (await callWindow(rpc, "apps.list", {})).find((x) => sameApp(x, a));
|
|
118442
118374
|
if (!now) return { ok: false, error: `${label} was removed while the card stood, so nothing was shared.` };
|
|
118443
118375
|
if (now.shared) return { ok: true, text: `${label} was shared while the card stood; nothing more changed.` };
|
|
118444
118376
|
if (appsKey([now]) !== appsKey([a])) return { ok: false, error: `What ${label} may ask for changed while the card stood, so it is not what the card named and nothing was shared. Ask again to show the person what it asks for now.` };
|
|
@@ -118619,7 +118551,7 @@ var AppUpkeepFlow = class {
|
|
|
118619
118551
|
}
|
|
118620
118552
|
async usage(rpc, label, ref) {
|
|
118621
118553
|
const u = await callWindow(rpc, "apps.usage", ref);
|
|
118622
|
-
const line = (name, x) => `${name}: ${plural(x.runs, "agent run")}, ${
|
|
118554
|
+
const line = (name, x) => `${name}: ${plural(x.runs, "agent run")}, ${durationText(x.durationMs)}${x.tokens ? `, ${x.tokens.input} tokens in and ${x.tokens.output} out` : ""}`;
|
|
118623
118555
|
return { ok: true, text: [`The agent use ${label} requested:`, line("Last day", u.day), line("Last 30 days", u.month)].join("\n") };
|
|
118624
118556
|
}
|
|
118625
118557
|
async remove(rpc, caller, app2, label, all, signal) {
|
|
@@ -118633,7 +118565,7 @@ var AppUpkeepFlow = class {
|
|
|
118633
118565
|
const decision = await this.host.hostCards.askHost(caller, { kind: "other", about: ASSISTANT_CHANGE, raw: question }, signal, { alwaysAsk: true });
|
|
118634
118566
|
if (decision === "deny") return { ok: false, error: "The person did not approve it, so the app was not removed. Do not ask again unless they tell you to." };
|
|
118635
118567
|
if (decision === null) return { ok: false, error: "The card was withdrawn before the person answered, so the app was not removed." };
|
|
118636
|
-
const now = (await callWindow(rpc, "apps.list", {})).find((x) => x
|
|
118568
|
+
const now = (await callWindow(rpc, "apps.list", {})).find((x) => sameApp(x, { ...app2, projectId: null }));
|
|
118637
118569
|
if (!now) return { ok: true, text: `${label} was already gone while the card stood; nothing more was done.` };
|
|
118638
118570
|
await callWindow(rpc, "apps.remove", { appId: app2.appId, projectId: null, ...onMachine(app2) });
|
|
118639
118571
|
return { ok: true, text: `Removed ${label}: its folder is in app-trash/ ${where2}, and it is detached from the sessions that had it.` };
|
|
@@ -118764,7 +118696,7 @@ var HousekeepingFlow = class {
|
|
|
118764
118696
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
118765
118697
|
import { existsSync as existsSync15, realpathSync as realpathSync5, statSync as statSync14 } from "node:fs";
|
|
118766
118698
|
import { homedir as homedir7 } from "node:os";
|
|
118767
|
-
import { basename as
|
|
118699
|
+
import { basename as basename8, isAbsolute as isAbsolute5, resolve as resolve11 } from "node:path";
|
|
118768
118700
|
|
|
118769
118701
|
// packages/agent-host/src/dev-services/project-folder.ts
|
|
118770
118702
|
import { lstatSync as lstatSync12, mkdirSync as mkdirSync16, statSync as statSync13 } from "node:fs";
|
|
@@ -118841,7 +118773,7 @@ var ProjectCreation = class {
|
|
|
118841
118773
|
const existing = this.projectAt(spelled2);
|
|
118842
118774
|
const at2 = existing?.path ?? spelled2;
|
|
118843
118775
|
const id3 = existing?.id ?? randomUUID18();
|
|
118844
|
-
this.host.store.projects.addProject({ id: id3, path: at2, name:
|
|
118776
|
+
this.host.store.projects.addProject({ id: id3, path: at2, name: basename8(at2), ...opts.trusted ? { trusted: true } : {} });
|
|
118845
118777
|
return this.host.projectInfo(id3, at2);
|
|
118846
118778
|
}
|
|
118847
118779
|
/**
|
|
@@ -118876,7 +118808,7 @@ var ProjectCreation = class {
|
|
|
118876
118808
|
const git2 = folder ? await isRepo(path2).catch(() => false) : false;
|
|
118877
118809
|
const origin = git2 ? await gitOriginUrl(path2, { trusted: false }) : null;
|
|
118878
118810
|
const kept = folder ? this.projectAt(path2) : void 0;
|
|
118879
|
-
const project2 = kept ? { id: kept.id, name: this.host.store.projects.listProjects().find((p) => p.id === kept.id)?.name ??
|
|
118811
|
+
const project2 = kept ? { id: kept.id, name: this.host.store.projects.listProjects().find((p) => p.id === kept.id)?.name ?? basename8(kept.path) } : null;
|
|
118880
118812
|
return { path: path2, exists: found !== null, folder, git: git2, origin, project: project2 };
|
|
118881
118813
|
}
|
|
118882
118814
|
/**
|
|
@@ -119418,14 +119350,14 @@ var NOTED_KEEP_MS = 6e4;
|
|
|
119418
119350
|
var NOTED_MAX = 64;
|
|
119419
119351
|
var UNUSABLE = /* @__PURE__ */ new Set(["invalid", "untrusted", "unconfirmed", "failed"]);
|
|
119420
119352
|
function givesApp(session2, app2) {
|
|
119421
|
-
return (isAssistantKind(session2.kind) ? app2.projectId === null : session2.projectId !== null && app2.projectId === session2.projectId) || session2.builderOf
|
|
119353
|
+
return (isAssistantKind(session2.kind) ? app2.projectId === null : session2.projectId !== null && app2.projectId === session2.projectId) || session2.builderOf != null && sameApp(session2.builderOf, app2);
|
|
119422
119354
|
}
|
|
119423
119355
|
var APP_NAMES_PREFIX = "session_app_names:";
|
|
119424
119356
|
var nameSlug = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 24).replace(/-+$/, "");
|
|
119425
|
-
var SERVER_NAME_MAX =
|
|
119357
|
+
var SERVER_NAME_MAX = appServerName("x".repeat(APP_ID_MAX_LENGTH)).length;
|
|
119426
119358
|
function freeServerName(appId, taken, qualifier) {
|
|
119427
119359
|
const has = (name) => Array.isArray(taken) ? taken.includes(name) : taken.has(name);
|
|
119428
|
-
const base2 =
|
|
119360
|
+
const base2 = appServerName(appId);
|
|
119429
119361
|
if (!has(base2)) return base2;
|
|
119430
119362
|
const stem = qualifier ? `${base2}-${qualifier}` : base2;
|
|
119431
119363
|
for (let n = qualifier ? 1 : 2; ; n++) {
|
|
@@ -119554,8 +119486,8 @@ var SessionAppsHub = class {
|
|
|
119554
119486
|
const hits = this.named(session2, usable.filter((a) => givesApp(session2, a))).sort((x, y) => x.server.localeCompare(y.server));
|
|
119555
119487
|
const taken = new Set(hits.map((h) => h.server));
|
|
119556
119488
|
for (const x of this.opts.onDemand?.attached(session2.id) ?? []) {
|
|
119557
|
-
const app2 = usable.find((a) => a
|
|
119558
|
-
if (!app2 || taken.has(x.server) || hits.some((h) =>
|
|
119489
|
+
const app2 = usable.find((a) => sameApp(a, x.ref));
|
|
119490
|
+
if (!app2 || taken.has(x.server) || hits.some((h) => sameApp(h.ref, x.ref))) continue;
|
|
119559
119491
|
if (!this.opts.onDemand.allowed(session2, app2)) continue;
|
|
119560
119492
|
hits.push({ ref: x.ref, server: x.server });
|
|
119561
119493
|
taken.add(x.server);
|
|
@@ -119585,7 +119517,7 @@ var SessionAppsHub = class {
|
|
|
119585
119517
|
const key = appKeyOf(a.projectId, a.appId);
|
|
119586
119518
|
let server2 = book[key];
|
|
119587
119519
|
if (!server2) {
|
|
119588
|
-
const base2 =
|
|
119520
|
+
const base2 = appServerName(a.appId);
|
|
119589
119521
|
const slug = a.projectId ? nameSlug(this.opts.projectName?.(a.projectId) ?? "") || a.projectId.slice(0, 8).toLowerCase() : "user";
|
|
119590
119522
|
server2 = !taken.has(base2) ? base2 : freeServerName(a.appId, taken, slug);
|
|
119591
119523
|
book[key] = server2;
|
|
@@ -119614,7 +119546,7 @@ var SessionAppsHub = class {
|
|
|
119614
119546
|
*/
|
|
119615
119547
|
claimAttachName(sessionId, ref, inUse) {
|
|
119616
119548
|
const book = this.bookOf(sessionId);
|
|
119617
|
-
const key = appKeyOf(ref
|
|
119549
|
+
const key = appKeyOf(ref);
|
|
119618
119550
|
const taken = /* @__PURE__ */ new Set([...inUse, ...Object.entries(book).filter(([k2]) => k2 !== key).map(([, server3]) => server3)]);
|
|
119619
119551
|
const had = book[key];
|
|
119620
119552
|
const server2 = had && !taken.has(had) ? had : freeServerName(ref.appId, taken);
|
|
@@ -119635,9 +119567,9 @@ var SessionAppsHub = class {
|
|
|
119635
119567
|
* has not is reachable (#1205): its agent attaches it with `attach_app`, and the person has nothing to do.
|
|
119636
119568
|
*/
|
|
119637
119569
|
reach(session2, ref, live2) {
|
|
119638
|
-
const app2 = this.rt.list().find((a) => a
|
|
119570
|
+
const app2 = this.rt.list().find((a) => sameApp(a, ref));
|
|
119639
119571
|
if (!app2) return { reachable: false, reason: "unavailable" };
|
|
119640
|
-
const own = session2?.id ? this.opts.onDemand?.attached(session2.id).find((x) =>
|
|
119572
|
+
const own = session2?.id ? this.opts.onDemand?.attached(session2.id).find((x) => sameApp(x.ref, ref)) : void 0;
|
|
119641
119573
|
const onDemand = !!session2 && !!own && this.opts.onDemand.allowed(session2, app2);
|
|
119642
119574
|
const selfServed = !!session2 && !own && isAssistantKind(session2.kind) && app2.root === true && !!this.opts.onDemand;
|
|
119643
119575
|
const lostTrust = !!own && app2.status === "untrusted";
|
|
@@ -119646,7 +119578,7 @@ var SessionAppsHub = class {
|
|
|
119646
119578
|
if (UNUSABLE.has(app2.status)) return { reachable: false, reason: "app-unusable", status: app2.status };
|
|
119647
119579
|
if (selfServed && !this.opts.onDemand.allowed(session2, app2)) return { reachable: false, reason: "other-project" };
|
|
119648
119580
|
if (selfServed) return { reachable: true };
|
|
119649
|
-
const server2 = givesApp(session2, app2) ? this.refsFor(session2).find((h) =>
|
|
119581
|
+
const server2 = givesApp(session2, app2) ? this.refsFor(session2).find((h) => sameApp(h.ref, ref))?.server ?? appServerName(app2.appId) : own.server;
|
|
119650
119582
|
const attached = live2?.appAttachment?.(server2) ?? "attached";
|
|
119651
119583
|
if (attached === "restart") return { reachable: false, reason: "restart" };
|
|
119652
119584
|
if (attached === "failed") return { reachable: false, reason: "bridge-failed" };
|
|
@@ -119767,12 +119699,12 @@ var Attachment2 = class {
|
|
|
119767
119699
|
const entry = { sessionId: this.session.id, server: server2, startedAt: Date.now() - opts.waitMs, outcome: null };
|
|
119768
119700
|
this.hub.remember(runId, entry);
|
|
119769
119701
|
void pending.then((o) => entry.outcome = o);
|
|
119770
|
-
const
|
|
119702
|
+
const seconds = Math.round(opts.waitMs / 1e3);
|
|
119771
119703
|
return {
|
|
119772
119704
|
content: [
|
|
119773
119705
|
{
|
|
119774
119706
|
type: "text",
|
|
119775
|
-
text: `This call is still running (past ${
|
|
119707
|
+
text: `This call is still running (past ${seconds} s). Run id: ${runId}
|
|
119776
119708
|
The call has not stopped and carries on. Do not call it again: pass this id as run_id to the ${RUN_STATUS_TOOL} tool of the same server to get its result.`
|
|
119777
119709
|
}
|
|
119778
119710
|
],
|
|
@@ -119795,9 +119727,9 @@ The call has not stopped and carries on. Do not call it again: pass this id as r
|
|
|
119795
119727
|
const d2 = this.hub.detached.get(runId);
|
|
119796
119728
|
if (d2 && d2.sessionId === this.session.id && d2.server === hit.server) {
|
|
119797
119729
|
if (!d2.outcome) {
|
|
119798
|
-
const
|
|
119730
|
+
const seconds = Math.round((Date.now() - d2.startedAt) / 1e3);
|
|
119799
119731
|
return {
|
|
119800
|
-
content: [{ type: "text", text: `Run ${runId} is still running (${
|
|
119732
|
+
content: [{ type: "text", text: `Run ${runId} is still running (${seconds} s so far). Check again a little later.` }],
|
|
119801
119733
|
isError: false,
|
|
119802
119734
|
structuredContent: { runId, status: "running" }
|
|
119803
119735
|
};
|
|
@@ -119805,7 +119737,7 @@ The call has not stopped and carries on. Do not call it again: pass this id as r
|
|
|
119805
119737
|
const o = d2.outcome;
|
|
119806
119738
|
const done2 = toResult(o);
|
|
119807
119739
|
return {
|
|
119808
|
-
content: [{ type: "text", text: `Run ${runId} has finished (${o.status}, ${
|
|
119740
|
+
content: [{ type: "text", text: `Run ${runId} has finished (${o.status}, ${durationText(o.durationMs)}). Its result:` }, ...done2.content],
|
|
119809
119741
|
isError: done2.isError,
|
|
119810
119742
|
structuredContent: { runId, status: o.status, ...done2.structuredContent ? { result: done2.structuredContent } : {} }
|
|
119811
119743
|
};
|
|
@@ -119917,9 +119849,6 @@ The call has not stopped and carries on. Do not call it again: pass this id as r
|
|
|
119917
119849
|
return this.hub.refsFor(this.session).find((h) => h.server === server2) ?? null;
|
|
119918
119850
|
}
|
|
119919
119851
|
};
|
|
119920
|
-
function sameRef(a, b2) {
|
|
119921
|
-
return a.appId === b2.appId && a.projectId === b2.projectId;
|
|
119922
|
-
}
|
|
119923
119852
|
function argsKey(args) {
|
|
119924
119853
|
let v = args;
|
|
119925
119854
|
if (typeof v === "string") {
|
|
@@ -120112,7 +120041,7 @@ var SettingsRecords = class {
|
|
|
120112
120041
|
|
|
120113
120042
|
// packages/agent-host/src/sessions/app-access.ts
|
|
120114
120043
|
var KEY = (sessionId) => `session_apps:${sessionId}`;
|
|
120115
|
-
var SHARED_KEY = (ref) => `app_shared:${appKeyOf(ref
|
|
120044
|
+
var SHARED_KEY = (ref) => `app_shared:${appKeyOf(ref)}`;
|
|
120116
120045
|
var UNUSABLE2 = /* @__PURE__ */ new Set(["invalid", "untrusted", "unconfirmed", "failed"]);
|
|
120117
120046
|
function readShared(store2, ref) {
|
|
120118
120047
|
return ref.projectId !== null && store2.appSetting(SHARED_KEY({ projectId: ref.projectId, appId: ref.appId })) === "1";
|
|
@@ -120141,7 +120070,7 @@ var AppAccess = class {
|
|
|
120141
120070
|
if (app2.projectId === null) return true;
|
|
120142
120071
|
if (app2.root === true && app2.projectId !== from) return app2.status !== "untrusted";
|
|
120143
120072
|
if (app2.projectId === from || app2.shared !== true) return false;
|
|
120144
|
-
const r = this.records(session2.id).find((x) => x
|
|
120073
|
+
const r = this.records(session2.id).find((x) => sameApp(x, app2));
|
|
120145
120074
|
if (!r) return false;
|
|
120146
120075
|
return !!this.deps.boundaryOpen?.(session2.id) || r.consent === "once" || !!this.deps.store.permissions.getProjectConsent(from, app2.projectId, "apps");
|
|
120147
120076
|
}
|
|
@@ -120165,9 +120094,9 @@ var AppAccess = class {
|
|
|
120165
120094
|
if (!named3.ok) return named3;
|
|
120166
120095
|
const app2 = named3.app;
|
|
120167
120096
|
const target = { projectId: app2.projectId, appId: app2.appId };
|
|
120168
|
-
const has = already.find((h) => h.ref
|
|
120097
|
+
const has = already.find((h) => sameApp(h.ref, target));
|
|
120169
120098
|
if (has) return { ok: true, server: has.server, tools: await this.toolNames(target), when: "now", already: true };
|
|
120170
|
-
if (!this.candidates(session2).some((a) => a
|
|
120099
|
+
if (!this.candidates(session2).some((a) => sameApp(a, app2))) {
|
|
120171
120100
|
return { ok: false, error: this.whyNot(session2, app2) };
|
|
120172
120101
|
}
|
|
120173
120102
|
let consent = "none";
|
|
@@ -120182,11 +120111,11 @@ var AppAccess = class {
|
|
|
120182
120111
|
consent = this.deps.boundaryOpen?.(sessionId) ? "auto" : this.deps.store.permissions.getProjectConsent(session2.projectId, app2.projectId, "apps") ? "always" : "once";
|
|
120183
120112
|
const again = this.gate(sessionId);
|
|
120184
120113
|
if (!again.ok) return again;
|
|
120185
|
-
if (!this.candidates(again.session).some((a) => a
|
|
120114
|
+
if (!this.candidates(again.session).some((a) => sameApp(a, app2))) {
|
|
120186
120115
|
return { ok: false, error: this.whyNot(again.session, app2) };
|
|
120187
120116
|
}
|
|
120188
120117
|
}
|
|
120189
|
-
const kept = this.records(sessionId).filter((r) => !(r
|
|
120118
|
+
const kept = this.records(sessionId).filter((r) => !sameApp(r, app2));
|
|
120190
120119
|
const inUse = [...this.deps.hub.refsFor(session2).map((h) => h.server), ...kept.map((r) => r.server)];
|
|
120191
120120
|
const server2 = this.deps.hub.claimAttachName(sessionId, target, inUse);
|
|
120192
120121
|
this.save(sessionId, [...kept, { projectId: app2.projectId, appId: app2.appId, server: server2, consent, at: Date.now() }]);
|
|
@@ -120281,7 +120210,7 @@ var AppAccess = class {
|
|
|
120281
120210
|
candidates(session2) {
|
|
120282
120211
|
const have = this.deps.hub.refsFor(session2);
|
|
120283
120212
|
const assistant = isAssistantKind(session2.kind);
|
|
120284
|
-
return this.deps.hub.rt.list().filter((a) => !UNUSABLE2.has(a.status)).filter((a) => a.projectId === null || (assistant ? a.root === true : a.projectId !== session2.projectId && (a.shared === true || a.root === true))).filter((a) => !have.some((h) => h.ref
|
|
120213
|
+
return this.deps.hub.rt.list().filter((a) => !UNUSABLE2.has(a.status)).filter((a) => a.projectId === null || (assistant ? a.root === true : a.projectId !== session2.projectId && (a.shared === true || a.root === true))).filter((a) => !have.some((h) => sameApp(h.ref, a))).sort((x, y) => this.refOf(x).localeCompare(this.refOf(y)));
|
|
120285
120214
|
}
|
|
120286
120215
|
whyNot(session2, app2) {
|
|
120287
120216
|
if (app2.projectId !== null && app2.projectId === session2.projectId) return `${this.refOf(app2)} is this project's own app; it is attached already when the project is trusted.`;
|
|
@@ -120297,7 +120226,7 @@ var AppAccess = class {
|
|
|
120297
120226
|
const slash = want.lastIndexOf("/");
|
|
120298
120227
|
let app2;
|
|
120299
120228
|
if (slash === -1) {
|
|
120300
|
-
const id3 = want.startsWith(
|
|
120229
|
+
const id3 = want.startsWith(APP_SERVER_PREFIX) && !all.some((a) => a.appId === want) ? want.slice(APP_SERVER_PREFIX.length) : want;
|
|
120301
120230
|
const roots = all.filter((a) => a.root === true && a.appId === id3);
|
|
120302
120231
|
app2 = all.find((a) => a.projectId === null && a.appId === id3) ?? (roots.length === 1 ? roots[0] : void 0);
|
|
120303
120232
|
} else {
|
|
@@ -120365,7 +120294,7 @@ var AppAccess = class {
|
|
|
120365
120294
|
}
|
|
120366
120295
|
};
|
|
120367
120296
|
function isRecord2(x) {
|
|
120368
|
-
return (typeof x.projectId === "string" || x.projectId === null) && typeof x.appId === "string" && typeof x.server === "string" && x.server.startsWith(
|
|
120297
|
+
return (typeof x.projectId === "string" || x.projectId === null) && typeof x.appId === "string" && typeof x.server === "string" && x.server.startsWith(APP_SERVER_PREFIX) && (x.consent === "always" || x.consent === "once" || x.consent === "none" || x.consent === "auto");
|
|
120369
120298
|
}
|
|
120370
120299
|
|
|
120371
120300
|
// packages/agent-host/src/sessions/session-app-wiring.ts
|
|
@@ -120532,7 +120461,7 @@ var SessionAppWiring = class {
|
|
|
120532
120461
|
settings.setAppSetting(key, "1");
|
|
120533
120462
|
const book = parseJson(settings.appSetting(`${APP_NAMES_PREFIX}${sessionId}`));
|
|
120534
120463
|
if (!isObj(book)) return null;
|
|
120535
|
-
const attached = new Set((this.appAccess?.attached(sessionId) ?? []).map((x) => appKeyOf(x.ref
|
|
120464
|
+
const attached = new Set((this.appAccess?.attached(sessionId) ?? []).map((x) => appKeyOf(x.ref)));
|
|
120536
120465
|
const hadRootApp = Object.keys(book).some((k2) => !k2.startsWith(`${USER_APP_SCOPE}/`) && !attached.has(k2));
|
|
120537
120466
|
return hadRootApp ? ROOT_APPS_NOTICE : null;
|
|
120538
120467
|
}
|
|
@@ -120543,7 +120472,7 @@ var SessionAppWiring = class {
|
|
|
120543
120472
|
*/
|
|
120544
120473
|
setAppShared(ref, shared) {
|
|
120545
120474
|
const rt2 = this.requireAppsHub().rt;
|
|
120546
|
-
if (!rt2.list().some((a) => a
|
|
120475
|
+
if (!rt2.list().some((a) => sameApp(a, ref))) {
|
|
120547
120476
|
throw rpcError(`No such app: ${ref.appId}`);
|
|
120548
120477
|
}
|
|
120549
120478
|
writeShared(this.host.store.settings, ref, shared);
|
|
@@ -120694,27 +120623,27 @@ var SessionTools = class {
|
|
|
120694
120623
|
|
|
120695
120624
|
// packages/agent-host/src/dev-services/handoff-notes.ts
|
|
120696
120625
|
import { mkdirSync as mkdirSync17, writeFileSync as writeFileSync8 } from "node:fs";
|
|
120697
|
-
import { mkdir as
|
|
120698
|
-
import { join as
|
|
120699
|
-
var root = () =>
|
|
120626
|
+
import { mkdir as mkdir4, readdir as readdir7, writeFile as writeFile4 } from "node:fs/promises";
|
|
120627
|
+
import { join as join30 } from "node:path";
|
|
120628
|
+
var root = () => join30(dataRoot(), "handoff");
|
|
120700
120629
|
function handoffNoteDir(projectId) {
|
|
120701
120630
|
if (!isProjectId(projectId)) {
|
|
120702
120631
|
throw rpcError(`Not a project id: ${projectId}`);
|
|
120703
120632
|
}
|
|
120704
|
-
return
|
|
120633
|
+
return join30(root(), projectId);
|
|
120705
120634
|
}
|
|
120706
120635
|
function handoffNotePath(projectId, sessionId) {
|
|
120707
120636
|
if (!isSessionId(sessionId)) {
|
|
120708
120637
|
throw rpcError(`Not a session id: ${sessionId}`);
|
|
120709
120638
|
}
|
|
120710
|
-
return
|
|
120639
|
+
return join30(handoffNoteDir(projectId), `${sessionId}.md`);
|
|
120711
120640
|
}
|
|
120712
120641
|
async function handoffNoteBytes(projectId, sessionId) {
|
|
120713
120642
|
return dataBytes(handoffNotePath(projectId, sessionId));
|
|
120714
120643
|
}
|
|
120715
120644
|
async function writeHandoffNote(projectId, sessionId, text3) {
|
|
120716
120645
|
const path2 = handoffNotePath(projectId, sessionId);
|
|
120717
|
-
await
|
|
120646
|
+
await mkdir4(handoffNoteDir(projectId), { recursive: true });
|
|
120718
120647
|
await removeData(path2);
|
|
120719
120648
|
await writeFile4(path2, text3, "utf8");
|
|
120720
120649
|
return path2;
|
|
@@ -120729,7 +120658,7 @@ function writeHandoffNoteSync(projectId, sessionId, text3) {
|
|
|
120729
120658
|
async function sweepHandoffNotes(owned, projectId) {
|
|
120730
120659
|
let dirs;
|
|
120731
120660
|
try {
|
|
120732
|
-
dirs = projectId ? [projectId] : (await
|
|
120661
|
+
dirs = projectId ? [projectId] : (await readdir7(root(), { withFileTypes: true })).filter((d2) => d2.isDirectory()).map((d2) => d2.name);
|
|
120733
120662
|
} catch {
|
|
120734
120663
|
return;
|
|
120735
120664
|
}
|
|
@@ -120740,12 +120669,12 @@ async function sweepHandoffNotes(owned, projectId) {
|
|
|
120740
120669
|
} catch {
|
|
120741
120670
|
continue;
|
|
120742
120671
|
}
|
|
120743
|
-
const entries = await
|
|
120672
|
+
const entries = await readdir7(dir, { withFileTypes: true }).catch(() => []);
|
|
120744
120673
|
for (const e of entries) {
|
|
120745
120674
|
if (!e.isFile() || !e.name.endsWith(".md")) continue;
|
|
120746
120675
|
const owner = e.name.slice(0, -".md".length);
|
|
120747
120676
|
if (owned(owner)) continue;
|
|
120748
|
-
await removeData(
|
|
120677
|
+
await removeData(join30(dir, e.name)).catch(() => {
|
|
120749
120678
|
});
|
|
120750
120679
|
}
|
|
120751
120680
|
}
|
|
@@ -121186,11 +121115,11 @@ ${note}` : note;
|
|
|
121186
121115
|
};
|
|
121187
121116
|
|
|
121188
121117
|
// packages/agent-host/src/mail/ids.ts
|
|
121189
|
-
import { randomBytes as
|
|
121118
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
121190
121119
|
var CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
121191
121120
|
var ID_RE = /^([a-z0-9][a-z0-9-]*)\.(t|m)_([0-9A-HJKMNP-TV-Z]{26})$/;
|
|
121192
121121
|
var UlidMaker = class {
|
|
121193
|
-
constructor(random =
|
|
121122
|
+
constructor(random = randomBytes7) {
|
|
121194
121123
|
this.random = random;
|
|
121195
121124
|
}
|
|
121196
121125
|
random;
|
|
@@ -123025,9 +122954,9 @@ var SessionStarts = class {
|
|
|
123025
122954
|
}
|
|
123026
122955
|
}
|
|
123027
122956
|
const t02 = Date.now();
|
|
123028
|
-
const
|
|
122957
|
+
const gone2 = await this.host.externals.externalGone(m, cwd);
|
|
123029
122958
|
const tCheck = Date.now() - t02;
|
|
123030
|
-
if (
|
|
122959
|
+
if (gone2) {
|
|
123031
122960
|
return { session: m, resumed: false, reason: externalMissingReason(this.host.toolLabel(m.tool), cwd) };
|
|
123032
122961
|
}
|
|
123033
122962
|
const apps = this.host.apps.appsFor(m);
|
|
@@ -123123,8 +123052,8 @@ var SessionStarts = class {
|
|
|
123123
123052
|
return { session: m, resumed: true };
|
|
123124
123053
|
} catch (err) {
|
|
123125
123054
|
this.host.modelWindows.forget(sessionId);
|
|
123126
|
-
const
|
|
123127
|
-
if (
|
|
123055
|
+
const gone3 = err instanceof Error && Reflect.get(err, "code") === "conversation_gone" || await withTimeout(this.host.externals.externalGone(m, cwd), 8e3, "Checking the tool").catch(() => false);
|
|
123056
|
+
if (gone3) {
|
|
123128
123057
|
return { session: m, resumed: false, reason: externalMissingReason(this.host.toolLabel(m.tool), cwd) };
|
|
123129
123058
|
}
|
|
123130
123059
|
const locked = err.code === "conversation_locked";
|
|
@@ -125552,7 +125481,7 @@ var SelfCompaction = class {
|
|
|
125552
125481
|
/** What one kept step asks of the host that finds it (`recover`) */
|
|
125553
125482
|
resume(m, rec) {
|
|
125554
125483
|
const id3 = m.id;
|
|
125555
|
-
if (this.now() - rec.at > THEN_KEEP_MS) return this.tell(id3, rec.then, `it was kept for more than ${THEN_KEEP_MS
|
|
125484
|
+
if (this.now() - rec.at > THEN_KEEP_MS) return this.tell(id3, rec.then, `it was kept for more than ${durationText(THEN_KEEP_MS)} without going on, and what it followed is long past`);
|
|
125556
125485
|
if (rec.stage === "compacted" || rec.stage === "refused") {
|
|
125557
125486
|
if (this.host.ready(id3) && this.queuedNow(id3) !== true) void this.sendThen(id3, rec);
|
|
125558
125487
|
else this.keepHeld(id3, rec);
|
|
@@ -126069,16 +125998,16 @@ async function* readLines(stream) {
|
|
|
126069
125998
|
|
|
126070
125999
|
// packages/agent-host/src/adapters/frames/recorder.ts
|
|
126071
126000
|
import { appendFileSync as appendFileSync2, existsSync as existsSync16, mkdirSync as mkdirSync18 } from "node:fs";
|
|
126072
|
-
import { join as
|
|
126001
|
+
import { join as join31 } from "node:path";
|
|
126073
126002
|
var processes = /* @__PURE__ */ new Map();
|
|
126074
126003
|
function frameRecorder(sessionId, env = process.env) {
|
|
126075
126004
|
const dir = env.CC_RECORD_FRAMES;
|
|
126076
126005
|
if (!dir) return void 0;
|
|
126077
126006
|
mkdirSync18(dir, { recursive: true });
|
|
126078
126007
|
let n = (processes.get(sessionId) ?? 0) + 1;
|
|
126079
|
-
while (existsSync16(
|
|
126008
|
+
while (existsSync16(join31(dir, `${sessionId}.${n}.jsonl`))) n++;
|
|
126080
126009
|
processes.set(sessionId, n);
|
|
126081
|
-
const file2 =
|
|
126010
|
+
const file2 = join31(dir, `${sessionId}.${n}.jsonl`);
|
|
126082
126011
|
const start3 = Date.now();
|
|
126083
126012
|
const write = (entry) => {
|
|
126084
126013
|
try {
|
|
@@ -126166,8 +126095,8 @@ function logToolStderr(proc, label, line) {
|
|
|
126166
126095
|
}
|
|
126167
126096
|
async function stopToolProcess(proc, opts = {}) {
|
|
126168
126097
|
proc.stdin.end();
|
|
126169
|
-
const
|
|
126170
|
-
if (!
|
|
126098
|
+
const gone2 = opts.exited === true || await waitForExit(proc, opts.graceMs ?? STOP_GRACE_MS);
|
|
126099
|
+
if (!gone2) proc.kill("SIGKILL");
|
|
126171
126100
|
}
|
|
126172
126101
|
async function endToolProcess(proc, boundMs) {
|
|
126173
126102
|
proc.kill("SIGKILL");
|
|
@@ -126313,13 +126242,13 @@ var CoreSession = class {
|
|
|
126313
126242
|
watch(proc) {
|
|
126314
126243
|
this.live = proc;
|
|
126315
126244
|
let seen = false;
|
|
126316
|
-
const
|
|
126245
|
+
const gone2 = (code2, err) => {
|
|
126317
126246
|
if (seen) return;
|
|
126318
126247
|
seen = true;
|
|
126319
126248
|
this.exited(proc, code2, err);
|
|
126320
126249
|
};
|
|
126321
|
-
proc.once("exit", (code2) =>
|
|
126322
|
-
proc.on("error", (err) =>
|
|
126250
|
+
proc.once("exit", (code2) => gone2(code2));
|
|
126251
|
+
proc.on("error", (err) => gone2(null, err));
|
|
126323
126252
|
}
|
|
126324
126253
|
send(text3, opts) {
|
|
126325
126254
|
void this.enqueue(text3, opts?.id ?? null, opts?.compact === true);
|
|
@@ -126527,7 +126456,7 @@ var CoreSession = class {
|
|
|
126527
126456
|
};
|
|
126528
126457
|
|
|
126529
126458
|
// packages/agent-host/src/adapters/acp/session.ts
|
|
126530
|
-
import { isAbsolute as isAbsolute6, join as
|
|
126459
|
+
import { isAbsolute as isAbsolute6, join as join32 } from "node:path";
|
|
126531
126460
|
|
|
126532
126461
|
// packages/agent-host/src/adapters/always-allow.ts
|
|
126533
126462
|
var AlwaysAllowRules = class {
|
|
@@ -126669,7 +126598,7 @@ var UnmappedTypes = class {
|
|
|
126669
126598
|
};
|
|
126670
126599
|
|
|
126671
126600
|
// packages/agent-host/src/adapters/acp/connection.ts
|
|
126672
|
-
import { randomBytes as
|
|
126601
|
+
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
126673
126602
|
var RpcError = class extends Error {
|
|
126674
126603
|
constructor(code2, message, data) {
|
|
126675
126604
|
super(message);
|
|
@@ -126714,7 +126643,7 @@ var AcpConnection = class {
|
|
|
126714
126643
|
* String ids with a per-connection prefix: a host that adopts a process the previous host was talking to can
|
|
126715
126644
|
* receive answers to that host's requests (§4.4), and plain counters on both would have collided.
|
|
126716
126645
|
*/
|
|
126717
|
-
idPrefix = `c${
|
|
126646
|
+
idPrefix = `c${randomBytes8(3).toString("hex")}-`;
|
|
126718
126647
|
nextId = 1;
|
|
126719
126648
|
pending = new PendingRequests();
|
|
126720
126649
|
closed = false;
|
|
@@ -126989,7 +126918,7 @@ function centraluMark(server2, tool, args) {
|
|
|
126989
126918
|
function keepAttachedAppMarks(e, attached) {
|
|
126990
126919
|
const stray = (s) => {
|
|
126991
126920
|
if (!s.centralu?.app) return null;
|
|
126992
|
-
const server2 =
|
|
126921
|
+
const server2 = appServerName(s.centralu.app);
|
|
126993
126922
|
for (const a of attached()) if (a === server2) return null;
|
|
126994
126923
|
const { centralu: _gone, ...rest } = s;
|
|
126995
126924
|
return rest;
|
|
@@ -127917,7 +127846,7 @@ var AcpWire = class {
|
|
|
127917
127846
|
ownTool: Boolean(this.deps.centraluToolOf?.(call2)),
|
|
127918
127847
|
auto: this.preset === "auto",
|
|
127919
127848
|
alwaysAllowKey: alwaysAllowKey(detail),
|
|
127920
|
-
edit: edit ? { folder: this.opts.cwd, paths: editPaths(call2).map((p) => isAbsolute6(p) ? p :
|
|
127849
|
+
edit: edit ? { folder: this.opts.cwd, paths: editPaths(call2).map((p) => isAbsolute6(p) ? p : join32(this.opts.cwd, p)) } : null
|
|
127921
127850
|
};
|
|
127922
127851
|
}
|
|
127923
127852
|
respondApproval(requestId, decision, matcher2) {
|
|
@@ -128072,17 +128001,17 @@ var ACP_CAPABILITIES = {
|
|
|
128072
128001
|
// packages/agent-host/src/adapters/antigravity/agent-files.ts
|
|
128073
128002
|
import { spawn as spawnChild } from "node:child_process";
|
|
128074
128003
|
import { createHash as createHash12 } from "node:crypto";
|
|
128075
|
-
import { closeSync as closeSync5, createReadStream as createReadStream3, createWriteStream, existsSync as existsSync18, fstatSync as fstatSync4, openSync as openSync5, readdirSync as readdirSync11, readFileSync as readFileSync12, readSync as readSync4, watch as
|
|
128076
|
-
import { chmod as chmod3, lstat as lstat10, mkdir as
|
|
128004
|
+
import { closeSync as closeSync5, createReadStream as createReadStream3, createWriteStream, existsSync as existsSync18, fstatSync as fstatSync4, openSync as openSync5, readdirSync as readdirSync11, readFileSync as readFileSync12, readSync as readSync4, watch as watch3 } from "node:fs";
|
|
128005
|
+
import { chmod as chmod3, lstat as lstat10, mkdir as mkdir5, mkdtemp as mkdtemp3, readdir as readdir8, readFile as readFile4, realpath as realpath7, stat as stat7, statfs, writeFile as writeFile5 } from "node:fs/promises";
|
|
128077
128006
|
import { homedir as homedir8 } from "node:os";
|
|
128078
|
-
import { dirname as dirname17, join as
|
|
128007
|
+
import { dirname as dirname17, join as join34, resolve as resolve13 } from "node:path";
|
|
128079
128008
|
import { Transform } from "node:stream";
|
|
128080
128009
|
import { pipeline } from "node:stream/promises";
|
|
128081
128010
|
import { createInflateRaw } from "node:zlib";
|
|
128082
128011
|
|
|
128083
128012
|
// packages/agent-host/src/dev-services/instance-lock.ts
|
|
128084
128013
|
import { readFileSync as readFileSync11, unlinkSync as unlinkSync3, writeFileSync as writeFileSync9 } from "node:fs";
|
|
128085
|
-
import { dirname as dirname16, join as
|
|
128014
|
+
import { dirname as dirname16, join as join33 } from "node:path";
|
|
128086
128015
|
import Database2 from "better-sqlite3";
|
|
128087
128016
|
var OWNERSHIP_FILE = "host-ownership.sqlite";
|
|
128088
128017
|
var held2 = /* @__PURE__ */ new Set();
|
|
@@ -128117,7 +128046,7 @@ function parseHolder(raw) {
|
|
|
128117
128046
|
function acquireInstanceLock(dbPath2, startOf = processStartTime, describe4 = {}, now = Date.now) {
|
|
128118
128047
|
if (dbPath2 === ":memory:") return { ok: true, release: () => {
|
|
128119
128048
|
} };
|
|
128120
|
-
const lockPath =
|
|
128049
|
+
const lockPath = join33(dirname16(dbPath2), "host.lock");
|
|
128121
128050
|
const readHolder = () => {
|
|
128122
128051
|
try {
|
|
128123
128052
|
return parseHolder(readFileSync11(lockPath, "utf8"));
|
|
@@ -128125,7 +128054,7 @@ function acquireInstanceLock(dbPath2, startOf = processStartTime, describe4 = {}
|
|
|
128125
128054
|
return null;
|
|
128126
128055
|
}
|
|
128127
128056
|
};
|
|
128128
|
-
const owner = takeOwnership(
|
|
128057
|
+
const owner = takeOwnership(join33(dirname16(dbPath2), OWNERSHIP_FILE));
|
|
128129
128058
|
if (!owner) {
|
|
128130
128059
|
const holder = readHolder();
|
|
128131
128060
|
const pid = holder && Number.isInteger(holder.pid) && holder.pid > 0 ? holder.pid : null;
|
|
@@ -128250,26 +128179,26 @@ function agyPlatformKey(platform = HOST_PLATFORM, arch = process.arch) {
|
|
|
128250
128179
|
return null;
|
|
128251
128180
|
}
|
|
128252
128181
|
function agyHome(dataDir, version2) {
|
|
128253
|
-
const root3 =
|
|
128254
|
-
return { root: root3, versionDir:
|
|
128182
|
+
const root3 = join34(dataDir, "tools", "antigravity");
|
|
128183
|
+
return { root: root3, versionDir: join34(root3, version2), geminiHome: join34(root3, "gemini-home") };
|
|
128255
128184
|
}
|
|
128256
128185
|
function agyProgram(home, archive) {
|
|
128257
|
-
return
|
|
128186
|
+
return join34(home.versionDir, archive.command);
|
|
128258
128187
|
}
|
|
128259
128188
|
var INSTALL_MARKER = "install.json";
|
|
128260
128189
|
function isInstalled(home, archive) {
|
|
128261
128190
|
try {
|
|
128262
|
-
const marker = asObj(JSON.parse(readFileSync12(
|
|
128191
|
+
const marker = asObj(JSON.parse(readFileSync12(join34(home.versionDir, INSTALL_MARKER), "utf8")));
|
|
128263
128192
|
if (marker.sha256 !== archive.sha256) return false;
|
|
128264
|
-
return archive.files.every((f) => existsSync18(
|
|
128193
|
+
return archive.files.every((f) => existsSync18(join34(home.versionDir, f)));
|
|
128265
128194
|
} catch {
|
|
128266
128195
|
return false;
|
|
128267
128196
|
}
|
|
128268
128197
|
}
|
|
128269
128198
|
function hasSignIn(home) {
|
|
128270
|
-
const dir =
|
|
128199
|
+
const dir = join34(home.geminiHome, "antigravity-acp");
|
|
128271
128200
|
try {
|
|
128272
|
-
const settings = asObj(JSON.parse(readFileSync12(
|
|
128201
|
+
const settings = asObj(JSON.parse(readFileSync12(join34(dir, "settings.json"), "utf8")));
|
|
128273
128202
|
const auth = asObj(settings.auth);
|
|
128274
128203
|
return typeof auth.type === "string" && auth.type.length > 0;
|
|
128275
128204
|
} catch {
|
|
@@ -128329,22 +128258,22 @@ async function installAgy(home, archive, version2, opts) {
|
|
|
128329
128258
|
const io2 = opts.io ?? realInstallIo;
|
|
128330
128259
|
const { signal } = opts;
|
|
128331
128260
|
if (isInstalled(home, archive)) return;
|
|
128332
|
-
await
|
|
128261
|
+
await mkdir5(home.root, { recursive: true });
|
|
128333
128262
|
await removeStale(home.root, ".install-");
|
|
128334
128263
|
const free = await io2.freeBytes(home.root);
|
|
128335
128264
|
if (free !== null && free < AGY_INSTALL_SPACE_BYTES) {
|
|
128336
128265
|
throw new InstallFailure("disk_space", `Antigravity needs about ${mb(AGY_INSTALL_SPACE_BYTES)} MB free to install; ${mb(free)} MB are free`);
|
|
128337
128266
|
}
|
|
128338
|
-
const work = await mkdtemp3(
|
|
128267
|
+
const work = await mkdtemp3(join34(home.root, `.install-${ownerTag()}-`));
|
|
128339
128268
|
try {
|
|
128340
|
-
const zip =
|
|
128269
|
+
const zip = join34(work, "archive.zip");
|
|
128341
128270
|
const sha = await download(io2, archive.url, zip, signal, opts.onProgress);
|
|
128342
128271
|
if (sha !== archive.sha256) throw new InstallFailure("checksum", `The downloaded archive does not match the version Centralu pins (sha256 ${sha.slice(0, 12)}\u2026)`);
|
|
128343
128272
|
cancelled(signal);
|
|
128344
|
-
const pkg =
|
|
128273
|
+
const pkg = join34(work, "pkg");
|
|
128345
128274
|
await unpack(zip, archive, pkg, signal, opts.platform ?? HOST_PLATFORM);
|
|
128346
128275
|
await realOs().files.promises.rm(zip, { force: true });
|
|
128347
|
-
await writeFile5(
|
|
128276
|
+
await writeFile5(join34(pkg, INSTALL_MARKER), `${JSON.stringify({ version: version2, sha256: archive.sha256, url: archive.url })}
|
|
128348
128277
|
`);
|
|
128349
128278
|
cancelled(signal);
|
|
128350
128279
|
if (isInstalled(home, archive)) return;
|
|
@@ -128407,12 +128336,12 @@ async function unpack(zip, archive, dir, signal, platform) {
|
|
|
128407
128336
|
if (names.length !== want.length || names.some((n, i) => n !== want[i])) {
|
|
128408
128337
|
throw new InstallFailure("unpack", `The archive holds ${names.join(", ") || "nothing"}, not the files the release names (${want.join(", ")})`);
|
|
128409
128338
|
}
|
|
128410
|
-
await
|
|
128339
|
+
await mkdir5(dir, { recursive: true });
|
|
128411
128340
|
for (const e of entries) {
|
|
128412
128341
|
if (e.kind !== "file" || !/^[\w.-]+$/.test(e.name)) throw new InstallFailure("unpack", `The archive's entry ${e.name} is not a plain file`);
|
|
128413
128342
|
if (e.method !== 0 && e.method !== 8) throw new InstallFailure("unpack", `The archive's entry ${e.name} uses compression method ${e.method}`);
|
|
128414
128343
|
cancelled(signal);
|
|
128415
|
-
const path2 =
|
|
128344
|
+
const path2 = join34(dir, e.name);
|
|
128416
128345
|
await unpackEntry(zip, e, starts.get(e) ?? 0, path2, signal);
|
|
128417
128346
|
if (platform !== "win32") await chmod3(path2, 493);
|
|
128418
128347
|
}
|
|
@@ -128462,9 +128391,9 @@ async function removeLeftovers(home) {
|
|
|
128462
128391
|
await removeStale(home.root, ".sign-in-");
|
|
128463
128392
|
}
|
|
128464
128393
|
async function removeStale(root3, prefix) {
|
|
128465
|
-
const names = await
|
|
128394
|
+
const names = await readdir8(root3).catch(() => []);
|
|
128466
128395
|
const stale = names.filter((n) => n.startsWith(prefix) && ownerGone(n.slice(prefix.length)));
|
|
128467
|
-
await Promise.all(stale.map((n) => realOs().files.promises.rm(
|
|
128396
|
+
await Promise.all(stale.map((n) => realOs().files.promises.rm(join34(root3, n), { recursive: true, force: true }).catch(() => {
|
|
128468
128397
|
})));
|
|
128469
128398
|
}
|
|
128470
128399
|
var ownStart;
|
|
@@ -128495,10 +128424,10 @@ function processAlive(pid) {
|
|
|
128495
128424
|
}
|
|
128496
128425
|
}
|
|
128497
128426
|
async function removeOtherVersions(home) {
|
|
128498
|
-
const names = await
|
|
128427
|
+
const names = await readdir8(home.root).catch(() => []);
|
|
128499
128428
|
for (const n of names) {
|
|
128500
128429
|
if (!/^\d+\.\d+\.\d+/.test(n)) continue;
|
|
128501
|
-
const dir =
|
|
128430
|
+
const dir = join34(home.root, n);
|
|
128502
128431
|
if (dir === home.versionDir) continue;
|
|
128503
128432
|
await realOs().files.promises.rm(dir, { recursive: true, force: true }).catch(() => {
|
|
128504
128433
|
});
|
|
@@ -128521,7 +128450,7 @@ async function folderFacts(spare) {
|
|
|
128521
128450
|
const folder = fact(spare, await lstat10(spare));
|
|
128522
128451
|
const above = [];
|
|
128523
128452
|
for (let p = await realpath7(dirname17(spare)); ; p = dirname17(p)) {
|
|
128524
|
-
above.push(fact(p, await
|
|
128453
|
+
above.push(fact(p, await stat7(p)));
|
|
128525
128454
|
if (dirname17(p) === p) break;
|
|
128526
128455
|
}
|
|
128527
128456
|
return { folder, above };
|
|
@@ -128540,9 +128469,9 @@ async function browserFolder(home, platform = HOST_PLATFORM, places = {}) {
|
|
|
128540
128469
|
const sep13 = platform === "win32" ? ";" : ":";
|
|
128541
128470
|
const nodeBad = platform === "win32" ? unusableIn(node, sep13) : "";
|
|
128542
128471
|
if (nodeBad) return noHelper(`the Node program Centralu runs on is at ${node}, and Antigravity cannot be given a path with ${nodeBad} in it. Install Centralu (or that Node) in a folder whose path has none.`);
|
|
128543
|
-
await
|
|
128472
|
+
await mkdir5(home.root, { recursive: true });
|
|
128544
128473
|
await removeStale(home.root, ".sign-in-");
|
|
128545
|
-
let dir = resolve13(await mkdtemp3(
|
|
128474
|
+
let dir = resolve13(await mkdtemp3(join34(home.root, `.sign-in-${ownerTag()}-`)));
|
|
128546
128475
|
const dataBad = unusableIn(dir, sep13);
|
|
128547
128476
|
if (dataBad) {
|
|
128548
128477
|
await realOs().files.promises.rm(dir, { recursive: true, force: true }).catch(() => {
|
|
@@ -128550,15 +128479,15 @@ async function browserFolder(home, platform = HOST_PLATFORM, places = {}) {
|
|
|
128550
128479
|
const spare = resolve13(places.spare ?? spareFolder(platform));
|
|
128551
128480
|
const data = `Centralu's data folder is at ${home.root}, and Antigravity cannot be given a path with ${dataBad} in it`;
|
|
128552
128481
|
const move = "Move the data folder to a path without them.";
|
|
128553
|
-
const spareBad = unusableIn(
|
|
128482
|
+
const spareBad = unusableIn(join34(spare, ".sign-in-x"), sep13);
|
|
128554
128483
|
if (spareBad) return noHelper(`${data}; nor ${spareBad} in ${spare}, the folder Centralu tries instead. ${move}`);
|
|
128555
128484
|
try {
|
|
128556
|
-
await
|
|
128485
|
+
await mkdir5(spare, { recursive: true, mode: 448 });
|
|
128557
128486
|
const uid = platform === "win32" ? void 0 : process.getuid?.();
|
|
128558
128487
|
const notOwn = uid === void 0 ? "" : notOwnFolder(await folderFacts(spare), uid);
|
|
128559
128488
|
if (notOwn) return noHelper(`${data}, and ${spare}, the folder Centralu tries instead, ${notOwn}. ${move}`);
|
|
128560
128489
|
await removeStale(spare, ".sign-in-");
|
|
128561
|
-
dir = resolve13(await mkdtemp3(
|
|
128490
|
+
dir = resolve13(await mkdtemp3(join34(spare, `.sign-in-${ownerTag()}-`)));
|
|
128562
128491
|
} catch (err) {
|
|
128563
128492
|
const code2 = err instanceof Error ? Reflect.get(err, "code") : void 0;
|
|
128564
128493
|
return noHelper(`${data}, and ${spare}, the folder Centralu tries instead, could not be written to${typeof code2 === "string" ? ` (${code2})` : ""}. ${move}`);
|
|
@@ -128568,14 +128497,14 @@ async function browserFolder(home, platform = HOST_PLATFORM, places = {}) {
|
|
|
128568
128497
|
});
|
|
128569
128498
|
let browser;
|
|
128570
128499
|
if (platform === "win32") {
|
|
128571
|
-
const script =
|
|
128500
|
+
const script = join34(dir, "open-url.mjs");
|
|
128572
128501
|
await writeFile5(script, WINDOWS_HELPER);
|
|
128573
128502
|
browser = windowsBrowserCommand(node, script);
|
|
128574
128503
|
} else {
|
|
128575
|
-
const helper =
|
|
128576
|
-
const part = `${shQuote(
|
|
128504
|
+
const helper = join34(dir, "open-url");
|
|
128505
|
+
const part = `${shQuote(join34(dir, "part-"))}"$$"`;
|
|
128577
128506
|
await writeFile5(helper, `#!/bin/sh
|
|
128578
|
-
printf '%s\\n' "$1" > ${part} && mv ${part} ${shQuote(
|
|
128507
|
+
printf '%s\\n' "$1" > ${part} && mv ${part} ${shQuote(join34(dir, "url-"))}"$$"
|
|
128579
128508
|
exit 0
|
|
128580
128509
|
`, { mode: 448 });
|
|
128581
128510
|
await chmod3(helper, 448);
|
|
@@ -128601,8 +128530,8 @@ exit 0
|
|
|
128601
128530
|
}
|
|
128602
128531
|
for (const name of names) {
|
|
128603
128532
|
taken.add(name);
|
|
128604
|
-
const path2 =
|
|
128605
|
-
void
|
|
128533
|
+
const path2 = join34(dir, name);
|
|
128534
|
+
void readFile4(path2, "utf8").then(
|
|
128606
128535
|
async (text3) => {
|
|
128607
128536
|
await realOs().files.promises.rm(path2, { force: true }).catch(() => {
|
|
128608
128537
|
});
|
|
@@ -128614,7 +128543,7 @@ exit 0
|
|
|
128614
128543
|
}
|
|
128615
128544
|
};
|
|
128616
128545
|
try {
|
|
128617
|
-
watcher =
|
|
128546
|
+
watcher = watch3(dir, () => look());
|
|
128618
128547
|
watcher.on("error", () => {
|
|
128619
128548
|
});
|
|
128620
128549
|
} catch {
|
|
@@ -129145,8 +129074,8 @@ var AntigravityAdapter = class extends AcpAdapter {
|
|
|
129145
129074
|
|
|
129146
129075
|
// packages/agent-host/src/adapters/claude/index.ts
|
|
129147
129076
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
129148
|
-
import { mkdtemp as mkdtemp4, readdir as
|
|
129149
|
-
import { join as
|
|
129077
|
+
import { mkdtemp as mkdtemp4, readdir as readdir11, stat as stat11 } from "node:fs/promises";
|
|
129078
|
+
import { join as join42 } from "node:path";
|
|
129150
129079
|
import { randomUUID as randomUUID22 } from "node:crypto";
|
|
129151
129080
|
|
|
129152
129081
|
// packages/agent-host/src/cli-version.ts
|
|
@@ -129304,14 +129233,16 @@ function parseQuestions(input) {
|
|
|
129304
129233
|
}
|
|
129305
129234
|
return out;
|
|
129306
129235
|
}
|
|
129236
|
+
function ownServerTool(toolName) {
|
|
129237
|
+
const parts = mcpNameParts(toolName);
|
|
129238
|
+
return parts && !parts.tool.includes("__") ? parts : null;
|
|
129239
|
+
}
|
|
129307
129240
|
function isCentraluToolName(toolName) {
|
|
129308
|
-
|
|
129309
|
-
return parts.length === 3 && parts[0] === "mcp" && parts[1] === CENTRALU_MCP_NAME;
|
|
129241
|
+
return ownServerTool(toolName)?.server === CENTRALU_MCP_NAME;
|
|
129310
129242
|
}
|
|
129311
129243
|
function appToolOf(toolName) {
|
|
129312
|
-
const parts = toolName
|
|
129313
|
-
|
|
129314
|
-
return { server: parts[1], tool: parts[2] };
|
|
129244
|
+
const parts = ownServerTool(toolName);
|
|
129245
|
+
return parts?.server.startsWith(APP_SERVER_PREFIX) ? parts : null;
|
|
129315
129246
|
}
|
|
129316
129247
|
var READ_TOOLS2 = /* @__PURE__ */ new Set(["Read", "Glob", "Grep"]);
|
|
129317
129248
|
function readTarget(toolName, input) {
|
|
@@ -129512,10 +129443,10 @@ function claudeQueryOptions({ sessionId, opts, executablePath, servers, permissi
|
|
|
129512
129443
|
}
|
|
129513
129444
|
|
|
129514
129445
|
// packages/agent-host/src/adapters/claude/exe-link.ts
|
|
129515
|
-
import { randomBytes as
|
|
129446
|
+
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
129516
129447
|
import { closeSync as closeSync7, copyFileSync as copyFileSync4, linkSync as linkSync2, mkdirSync as mkdirSync20, openSync as openSync7, readdirSync as readdirSync13, readFileSync as readFileSync15, readSync as readSync6, statSync as statSync16 } from "node:fs";
|
|
129517
129448
|
import { createRequire } from "node:module";
|
|
129518
|
-
import { basename as
|
|
129449
|
+
import { basename as basename11, dirname as dirname21, join as join39 } from "node:path";
|
|
129519
129450
|
var PLACEHOLDER_MAX_BYTES = 1e6;
|
|
129520
129451
|
var INSTALLER_TIMEOUT_MS = 3e4;
|
|
129521
129452
|
var VERSION_TIMEOUT_MS = 1e4;
|
|
@@ -129528,7 +129459,7 @@ async function runNode(file2, args, cwd, timeoutMs) {
|
|
|
129528
129459
|
return { status: 0, output: `${r.stdout}${r.stderr}`.trim() };
|
|
129529
129460
|
} catch (e) {
|
|
129530
129461
|
if (isExecFailure(e)) {
|
|
129531
|
-
if (e.ended === "timeout") return { status: null, output: `it did not finish within ${
|
|
129462
|
+
if (e.ended === "timeout") return { status: null, output: `it did not finish within ${durationText(timeoutMs)}` };
|
|
129532
129463
|
return { status: e.code, output: `${e.stdout}${e.stderr}`.trim() };
|
|
129533
129464
|
}
|
|
129534
129465
|
return { status: null, output: e instanceof Error ? e.message : String(e) };
|
|
@@ -129562,7 +129493,7 @@ var realExeFs = {
|
|
|
129562
129493
|
nativeSize: (installer) => {
|
|
129563
129494
|
try {
|
|
129564
129495
|
const pkg = createRequire(installer).resolve(`@anthropic-ai/claude-code-win32-${process.arch}/package.json`);
|
|
129565
|
-
return statSync16(
|
|
129496
|
+
return statSync16(join39(dirname21(pkg), "claude.exe")).size;
|
|
129566
129497
|
} catch {
|
|
129567
129498
|
return null;
|
|
129568
129499
|
}
|
|
@@ -129570,8 +129501,8 @@ var realExeFs = {
|
|
|
129570
129501
|
runProgram: async (path2, args, timeoutMs) => ({ status: (await runNode(path2, args, void 0, timeoutMs)).status })
|
|
129571
129502
|
};
|
|
129572
129503
|
function installerFor(exe, fs3 = realExeFs) {
|
|
129573
|
-
if (
|
|
129574
|
-
const installer =
|
|
129504
|
+
if (basename11(dirname21(exe)).toLowerCase() !== "bin") return null;
|
|
129505
|
+
const installer = join39(dirname21(dirname21(exe)), "install.cjs");
|
|
129575
129506
|
try {
|
|
129576
129507
|
fs3.stat(installer);
|
|
129577
129508
|
return installer;
|
|
@@ -129604,7 +129535,7 @@ function unprovenProblem(exe, size2, why2, tried, installer) {
|
|
|
129604
129535
|
function claudeKey(exe, stat13, fs3 = realExeFs) {
|
|
129605
129536
|
let version2 = null;
|
|
129606
129537
|
try {
|
|
129607
|
-
const pkg = JSON.parse(fs3.read(
|
|
129538
|
+
const pkg = JSON.parse(fs3.read(join39(dirname21(dirname21(exe)), "package.json")));
|
|
129608
129539
|
if (pkg.name === "@anthropic-ai/claude-code" && typeof pkg.version === "string" && pkg.version) version2 = pkg.version;
|
|
129609
129540
|
} catch {
|
|
129610
129541
|
}
|
|
@@ -129634,7 +129565,7 @@ var ClaudeLinks = class {
|
|
|
129634
129565
|
return windowsStart(this.opts.platform);
|
|
129635
129566
|
}
|
|
129636
129567
|
base() {
|
|
129637
|
-
return
|
|
129568
|
+
return join39(this.opts.root(), "tools", "claude");
|
|
129638
129569
|
}
|
|
129639
129570
|
/**
|
|
129640
129571
|
* `prepare`, after repairing npm's placeholder if that is what `exe` is. Every start path awaits this,
|
|
@@ -129666,8 +129597,8 @@ var ClaudeLinks = class {
|
|
|
129666
129597
|
if (!problem3 && installer && outcome && bad && bad.size === stat13.size && bad.mtimeMs === stat13.mtimeMs) problem3 = unprovenProblem(exe, stat13.size, bad.why, outcome.note, installer);
|
|
129667
129598
|
if (problem3) throw new ClaudePlaceholderError(problem3);
|
|
129668
129599
|
const key = claudeKey(exe, stat13, this.fs);
|
|
129669
|
-
const dir =
|
|
129670
|
-
const target =
|
|
129600
|
+
const dir = join39(this.base(), key);
|
|
129601
|
+
const target = join39(dir, "claude.exe");
|
|
129671
129602
|
const ready = () => {
|
|
129672
129603
|
try {
|
|
129673
129604
|
return this.fs.stat(target).size === stat13.size;
|
|
@@ -129676,7 +129607,7 @@ var ClaudeLinks = class {
|
|
|
129676
129607
|
}
|
|
129677
129608
|
};
|
|
129678
129609
|
if (ready()) return this.use(key, target);
|
|
129679
|
-
const tmp =
|
|
129610
|
+
const tmp = join39(dir, `claude-${randomBytes9(4).toString("hex")}.tmp`);
|
|
129680
129611
|
try {
|
|
129681
129612
|
this.fs.mkdir(dir);
|
|
129682
129613
|
try {
|
|
@@ -129804,7 +129735,7 @@ var ClaudeLinks = class {
|
|
|
129804
129735
|
for (const name of names) {
|
|
129805
129736
|
if (name === this.current || this.uses.has(name)) continue;
|
|
129806
129737
|
try {
|
|
129807
|
-
this.fs.removeDir(
|
|
129738
|
+
this.fs.removeDir(join39(this.base(), name));
|
|
129808
129739
|
} catch {
|
|
129809
129740
|
}
|
|
129810
129741
|
}
|
|
@@ -129945,7 +129876,7 @@ function contentBlocks(m) {
|
|
|
129945
129876
|
}
|
|
129946
129877
|
|
|
129947
129878
|
// packages/agent-host/src/adapters/images.ts
|
|
129948
|
-
import { readFile as
|
|
129879
|
+
import { readFile as readFile6, stat as stat9 } from "node:fs/promises";
|
|
129949
129880
|
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "gif", "webp", "bmp"]);
|
|
129950
129881
|
var startsWith = (buf, bytes2, at2 = 0) => bytes2.every((b2, i) => buf[at2 + i] === b2);
|
|
129951
129882
|
function gifReachesTrailer(buf) {
|
|
@@ -130026,9 +129957,9 @@ async function imageEventFromDisk(sessionId, path2, maxBytes = IMAGE_MAX_BYTES)
|
|
|
130026
129957
|
const file2 = path2.split(/[\\/]/).pop() ?? path2;
|
|
130027
129958
|
const ext2 = file2.includes(".") ? file2.slice(file2.lastIndexOf(".") + 1).toLowerCase() : "";
|
|
130028
129959
|
try {
|
|
130029
|
-
const s = await
|
|
129960
|
+
const s = await stat9(path2);
|
|
130030
129961
|
if (s.size > maxBytes) return fail4(tooLarge(s.size));
|
|
130031
|
-
const buf = await
|
|
129962
|
+
const buf = await readFile6(path2);
|
|
130032
129963
|
const seen = judgeImage(buf);
|
|
130033
129964
|
if (!seen) return fail4(!ext2 ? "the file is not a picture" : IMAGE_EXTENSIONS.has(ext2) ? `the file is not a valid .${ext2} image` : `the .${ext2} format cannot be shown`);
|
|
130034
129965
|
if ("note" in seen) return fail4(seen.note);
|
|
@@ -130591,12 +130522,12 @@ var ClaudeSchedules = class _ClaudeSchedules {
|
|
|
130591
130522
|
}
|
|
130592
130523
|
/** The process went away and its timers with it */
|
|
130593
130524
|
release() {
|
|
130594
|
-
const
|
|
130525
|
+
const gone2 = this.live();
|
|
130595
130526
|
this.calls.clear();
|
|
130596
130527
|
this.wakeups.clear();
|
|
130597
130528
|
this.crons.clear();
|
|
130598
130529
|
this.unnamed.clear();
|
|
130599
|
-
return
|
|
130530
|
+
return gone2;
|
|
130600
130531
|
}
|
|
130601
130532
|
};
|
|
130602
130533
|
|
|
@@ -131476,16 +131407,16 @@ var ClaudeStreamNormalizer = class {
|
|
|
131476
131407
|
|
|
131477
131408
|
// packages/agent-host/src/adapters/claude/lsp-plugins.ts
|
|
131478
131409
|
init_sdk();
|
|
131479
|
-
import { access as access3, readFile as
|
|
131410
|
+
import { access as access3, readFile as readFile7 } from "node:fs/promises";
|
|
131480
131411
|
import { homedir as homedir10 } from "node:os";
|
|
131481
|
-
import { join as
|
|
131412
|
+
import { join as join40 } from "node:path";
|
|
131482
131413
|
var KNOWN_LSP_PLUGINS = ["typescript-lsp@claude-plugins-official"];
|
|
131483
131414
|
function claudeConfigDir(env = process.env, home = homedir10()) {
|
|
131484
|
-
return env.CLAUDE_CONFIG_DIR ||
|
|
131415
|
+
return env.CLAUDE_CONFIG_DIR || join40(home, ".claude");
|
|
131485
131416
|
}
|
|
131486
131417
|
async function readJson2(path2) {
|
|
131487
131418
|
try {
|
|
131488
|
-
return JSON.parse(await
|
|
131419
|
+
return JSON.parse(await readFile7(path2, "utf8"));
|
|
131489
131420
|
} catch {
|
|
131490
131421
|
return void 0;
|
|
131491
131422
|
}
|
|
@@ -131496,22 +131427,22 @@ async function declaresLspServers(id3, configDir) {
|
|
|
131496
131427
|
if (at2 <= 0) return false;
|
|
131497
131428
|
const name = id3.slice(0, at2);
|
|
131498
131429
|
const marketplace = id3.slice(at2 + 1);
|
|
131499
|
-
const installed = await readJson2(
|
|
131430
|
+
const installed = await readJson2(join40(configDir, "plugins", "installed_plugins.json"));
|
|
131500
131431
|
const entries = isObj(installed) && isObj(installed.plugins) ? installed.plugins[id3] : void 0;
|
|
131501
131432
|
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
131502
131433
|
const path2 = isObj(entry) && typeof entry.installPath === "string" ? entry.installPath : null;
|
|
131503
131434
|
if (!path2) continue;
|
|
131504
|
-
if (declares(await readJson2(
|
|
131435
|
+
if (declares(await readJson2(join40(path2, ".claude-plugin", "plugin.json")))) return true;
|
|
131505
131436
|
try {
|
|
131506
|
-
await access3(
|
|
131437
|
+
await access3(join40(path2, ".lsp.json"));
|
|
131507
131438
|
return true;
|
|
131508
131439
|
} catch {
|
|
131509
131440
|
}
|
|
131510
131441
|
}
|
|
131511
|
-
const known = await readJson2(
|
|
131442
|
+
const known = await readJson2(join40(configDir, "plugins", "known_marketplaces.json"));
|
|
131512
131443
|
const place = isObj(known) && isObj(known[marketplace]) ? known[marketplace].installLocation : void 0;
|
|
131513
131444
|
if (typeof place !== "string") return false;
|
|
131514
|
-
const listing = await readJson2(
|
|
131445
|
+
const listing = await readJson2(join40(place, ".claude-plugin", "marketplace.json"));
|
|
131515
131446
|
const plugins = isObj(listing) && Array.isArray(listing.plugins) ? listing.plugins : [];
|
|
131516
131447
|
return plugins.some((p) => isObj(p) && p.name === name && declares(p));
|
|
131517
131448
|
}
|
|
@@ -131876,8 +131807,8 @@ var MidTurnLedger = class {
|
|
|
131876
131807
|
import { resolve as resolve18 } from "node:path";
|
|
131877
131808
|
|
|
131878
131809
|
// packages/agent-host/src/adapters/claude/new-file.ts
|
|
131879
|
-
import { stat as
|
|
131880
|
-
async function newFile(path2, statOf =
|
|
131810
|
+
import { stat as stat10 } from "node:fs/promises";
|
|
131811
|
+
async function newFile(path2, statOf = stat10) {
|
|
131881
131812
|
const found = statOf(path2).then(
|
|
131882
131813
|
() => false,
|
|
131883
131814
|
(err) => err.code === "ENOENT" ? true : void 0
|
|
@@ -132420,7 +132351,7 @@ function tracksInputs(m) {
|
|
|
132420
132351
|
|
|
132421
132352
|
// packages/agent-host/src/adapters/claude/surface.ts
|
|
132422
132353
|
import { readFileSync as readFileSync16 } from "node:fs";
|
|
132423
|
-
import { join as
|
|
132354
|
+
import { join as join41 } from "node:path";
|
|
132424
132355
|
|
|
132425
132356
|
// packages/agent-host/src/adapters/surface-drift.ts
|
|
132426
132357
|
function compareSurface(surface, limitations, baseline) {
|
|
@@ -132913,8 +132844,8 @@ var CLAUDE_SURFACE = {
|
|
|
132913
132844
|
async gather(env) {
|
|
132914
132845
|
const sdk = await env.packageDir(SDK);
|
|
132915
132846
|
return {
|
|
132916
|
-
"package.json": readFileSync16(
|
|
132917
|
-
"sdk.d.ts": readFileSync16(
|
|
132847
|
+
"package.json": readFileSync16(join41(sdk, "package.json"), "utf8"),
|
|
132848
|
+
"sdk.d.ts": readFileSync16(join41(sdk, "sdk.d.ts"), "utf8"),
|
|
132918
132849
|
"claude --version": await env.run("claude", ["--version"]),
|
|
132919
132850
|
"claude --help": await env.run("claude", ["--help"])
|
|
132920
132851
|
};
|
|
@@ -133630,10 +133561,10 @@ async function claudeLoggedIn(bin) {
|
|
|
133630
133561
|
async function sweepProbeDirs(now = Date.now()) {
|
|
133631
133562
|
try {
|
|
133632
133563
|
const root3 = tmpdir4();
|
|
133633
|
-
for (const name of await
|
|
133564
|
+
for (const name of await readdir11(root3)) {
|
|
133634
133565
|
if (!name.startsWith(PROBE_DIR_PREFIX)) continue;
|
|
133635
|
-
const path2 =
|
|
133636
|
-
const old = await
|
|
133566
|
+
const path2 = join42(root3, name);
|
|
133567
|
+
const old = await stat11(path2).then((s) => now - s.mtimeMs > PROBE_DIR_STALE_MS, () => false);
|
|
133637
133568
|
if (old) await realOs().files.promises.rm(path2, { recursive: true, force: true }).catch(() => {
|
|
133638
133569
|
});
|
|
133639
133570
|
}
|
|
@@ -133825,7 +133756,7 @@ var ClaudeAdapter = class _ClaudeAdapter {
|
|
|
133825
133756
|
this.swept = true;
|
|
133826
133757
|
await sweepProbeDirs();
|
|
133827
133758
|
}
|
|
133828
|
-
const dir = await mkdtemp4(
|
|
133759
|
+
const dir = await mkdtemp4(join42(tmpdir4(), PROBE_DIR_PREFIX));
|
|
133829
133760
|
const sessionId = `usage-probe-${randomUUID22()}`;
|
|
133830
133761
|
_ClaudeAdapter.probeIds.add(sessionId);
|
|
133831
133762
|
let probe = null;
|
|
@@ -133910,10 +133841,10 @@ var ClaudeAdapter = class _ClaudeAdapter {
|
|
|
133910
133841
|
|
|
133911
133842
|
// packages/agent-host/src/adapters/codex/index.ts
|
|
133912
133843
|
import { existsSync as existsSync21 } from "node:fs";
|
|
133913
|
-
import { join as
|
|
133844
|
+
import { join as join46 } from "node:path";
|
|
133914
133845
|
|
|
133915
133846
|
// packages/agent-host/src/adapters/codex/client.ts
|
|
133916
|
-
import { randomBytes as
|
|
133847
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
133917
133848
|
|
|
133918
133849
|
// packages/agent-host/src/adapters/codex/native.ts
|
|
133919
133850
|
import { existsSync as existsSync20, readFileSync as readFileSync17, realpathSync as realpathSync8 } from "node:fs";
|
|
@@ -134042,7 +133973,7 @@ var CodexClient = class {
|
|
|
134042
133973
|
* with plain counters both hosts would have sent `1`, `2`, … and an old answer would resolve a new
|
|
134043
133974
|
* request. codex echoes string ids back as given.
|
|
134044
133975
|
*/
|
|
134045
|
-
idPrefix = `${
|
|
133976
|
+
idPrefix = `${randomBytes10(3).toString("hex")}-`;
|
|
134046
133977
|
pending = new PendingRequests();
|
|
134047
133978
|
closed = false;
|
|
134048
133979
|
/** A flag to call onExit only once (both 'error' and 'exit' can fire) */
|
|
@@ -134127,24 +134058,24 @@ async function withCodexClient(opts, fn2) {
|
|
|
134127
134058
|
|
|
134128
134059
|
// packages/agent-host/src/adapters/codex/home.ts
|
|
134129
134060
|
import { homedir as homedir11 } from "node:os";
|
|
134130
|
-
import { join as
|
|
134061
|
+
import { join as join43 } from "node:path";
|
|
134131
134062
|
function codexHome(env = process.env, home = homedir11()) {
|
|
134132
134063
|
const custom2 = env.CODEX_HOME?.trim();
|
|
134133
|
-
return custom2 ? custom2 :
|
|
134064
|
+
return custom2 ? custom2 : join43(home, ".codex");
|
|
134134
134065
|
}
|
|
134135
134066
|
|
|
134136
134067
|
// packages/agent-host/src/adapters/codex/rollout.ts
|
|
134137
134068
|
import { createReadStream as createReadStream5 } from "node:fs";
|
|
134138
|
-
import { readdir as
|
|
134139
|
-
import { join as
|
|
134069
|
+
import { readdir as readdir12 } from "node:fs/promises";
|
|
134070
|
+
import { join as join44 } from "node:path";
|
|
134140
134071
|
var MIN_SUMMARY_CHARS = 200;
|
|
134141
|
-
async function findRolloutPath(threadId, sessionsDir =
|
|
134072
|
+
async function findRolloutPath(threadId, sessionsDir = join44(codexHome(), "sessions")) {
|
|
134142
134073
|
try {
|
|
134143
134074
|
const suffix = `-${threadId}.jsonl`;
|
|
134144
|
-
const names = await
|
|
134075
|
+
const names = await readdir12(sessionsDir, { recursive: true });
|
|
134145
134076
|
const hits = names.filter((n) => String(n).endsWith(suffix)).sort();
|
|
134146
134077
|
const hit = hits[hits.length - 1];
|
|
134147
|
-
return hit ?
|
|
134078
|
+
return hit ? join44(sessionsDir, String(hit)) : null;
|
|
134148
134079
|
} catch {
|
|
134149
134080
|
return null;
|
|
134150
134081
|
}
|
|
@@ -136139,7 +136070,7 @@ function watchBackgroundResume(host) {
|
|
|
136139
136070
|
sessionId: host.sessionId,
|
|
136140
136071
|
error: {
|
|
136141
136072
|
code: "adapter_crashed",
|
|
136142
|
-
message: `Resuming codex did not finish within ${BACKGROUND_RESUME_CAP_MS
|
|
136073
|
+
message: `Resuming codex did not finish within ${durationText(BACKGROUND_RESUME_CAP_MS)}${host.unsentNote()}`,
|
|
136143
136074
|
retryable: true
|
|
136144
136075
|
}
|
|
136145
136076
|
});
|
|
@@ -136640,7 +136571,7 @@ var CodexSession = class {
|
|
|
136640
136571
|
|
|
136641
136572
|
// packages/agent-host/src/adapters/codex/surface.ts
|
|
136642
136573
|
import { readFileSync as readFileSync18 } from "node:fs";
|
|
136643
|
-
import { join as
|
|
136574
|
+
import { join as join45 } from "node:path";
|
|
136644
136575
|
|
|
136645
136576
|
// packages/agent-host/src/adapters/codex/surface-baseline.ts
|
|
136646
136577
|
var SURFACE_BASELINE2 = {
|
|
@@ -136958,7 +136889,7 @@ var CODEX_SURFACE = {
|
|
|
136958
136889
|
"codex --version": await env.run("codex", ["--version"]),
|
|
136959
136890
|
"codex --help": await env.run("codex", ["--help"])
|
|
136960
136891
|
};
|
|
136961
|
-
for (const f of FILES) inputs[f] = readFileSync18(
|
|
136892
|
+
for (const f of FILES) inputs[f] = readFileSync18(join45(out, f), "utf8");
|
|
136962
136893
|
return inputs;
|
|
136963
136894
|
},
|
|
136964
136895
|
read: readCodexSurface,
|
|
@@ -137026,7 +136957,7 @@ var CodexAdapter = class {
|
|
|
137026
136957
|
const launch2 = launchFor2(path2 ?? toolCommand("codex"));
|
|
137027
136958
|
const { stdout } = await execText(launch2.command, [...launch2.args, "--version"], { timeoutMs: 5e3 });
|
|
137028
136959
|
const version2 = `${stdout.trim()} \xB7 ${path2 ?? "PATH"}`;
|
|
137029
|
-
const loggedIn = existsSync21(
|
|
136960
|
+
const loggedIn = existsSync21(join46(codexHome(), "auth.json"));
|
|
137030
136961
|
return {
|
|
137031
136962
|
tool: "codex",
|
|
137032
136963
|
installed: true,
|
|
@@ -137130,7 +137061,7 @@ var CodexAdapter = class {
|
|
|
137130
137061
|
|
|
137131
137062
|
// packages/agent-host/src/adapters/cursor-agent/install.ts
|
|
137132
137063
|
import { existsSync as existsSync22, readdirSync as readdirSync14, realpathSync as realpathSync10 } from "node:fs";
|
|
137133
|
-
import { dirname as dirname23, join as
|
|
137064
|
+
import { dirname as dirname23, join as join47, win32 as win327 } from "node:path";
|
|
137134
137065
|
var realFs = {
|
|
137135
137066
|
exists: existsSync22,
|
|
137136
137067
|
list: (dir) => {
|
|
@@ -137182,14 +137113,14 @@ function findCursor(env = process.env, platform, fs3 = realFs) {
|
|
|
137182
137113
|
const real3 = fs3.real(found);
|
|
137183
137114
|
const dir = dirname23(real3);
|
|
137184
137115
|
const version2 = dir.split(/[\\/]/).pop() ?? "";
|
|
137185
|
-
if (VERSION.test(version2) && fs3.exists(
|
|
137116
|
+
if (VERSION.test(version2) && fs3.exists(join47(dir, "index.js"))) return { version: version2, command: real3, args: [], env: {} };
|
|
137186
137117
|
}
|
|
137187
137118
|
return null;
|
|
137188
137119
|
}
|
|
137189
137120
|
|
|
137190
137121
|
// packages/agent-host/src/adapters/cursor-agent/surface.ts
|
|
137191
137122
|
import { readdirSync as readdirSync15, readFileSync as readFileSync19 } from "node:fs";
|
|
137192
|
-
import { dirname as dirname24, join as
|
|
137123
|
+
import { dirname as dirname24, join as join48 } from "node:path";
|
|
137193
137124
|
|
|
137194
137125
|
// packages/agent-host/src/adapters/cursor-agent/surface-baseline.ts
|
|
137195
137126
|
var SURFACE_BASELINE3 = {
|
|
@@ -137257,7 +137188,7 @@ async function gather2() {
|
|
|
137257
137188
|
const dir = dirname24(install.args[0] ?? install.command);
|
|
137258
137189
|
const names = /* @__PURE__ */ new Set();
|
|
137259
137190
|
for (const f of readdirSync15(dir).filter((n) => n.endsWith(".js"))) {
|
|
137260
|
-
const text3 = readFileSync19(
|
|
137191
|
+
const text3 = readFileSync19(join48(dir, f), "utf8");
|
|
137261
137192
|
if (!text3.includes("session/request_permission") && !text3.includes("cursor_login")) continue;
|
|
137262
137193
|
for (const m of text3.matchAll(/sessionUpdate:"([a-z_]+)"|"(cursor\/[a-z_]+)"/g)) {
|
|
137263
137194
|
const name = m[1] ?? m[2];
|
|
@@ -137368,16 +137299,8 @@ function softRead(o) {
|
|
|
137368
137299
|
const run2 = start3();
|
|
137369
137300
|
const held3 = value && (o.staleOk?.(value.v) ?? true) ? { v: value.v } : null;
|
|
137370
137301
|
if (held3 && !ask.settle) return { value: held3.v, provisional: true };
|
|
137371
|
-
|
|
137372
|
-
|
|
137373
|
-
timer = setTimeout(() => resolve21({ value: held3 ? held3.v : o.fallback(), provisional: true }), ask.settle ? o.settleMs ?? 2e4 : o.softMs);
|
|
137374
|
-
timer.unref?.();
|
|
137375
|
-
});
|
|
137376
|
-
try {
|
|
137377
|
-
return await Promise.race([run2.then((v) => ({ value: v, provisional: false })), soft]);
|
|
137378
|
-
} finally {
|
|
137379
|
-
clearTimeout(timer);
|
|
137380
|
-
}
|
|
137302
|
+
const soft = { value: held3 ? held3.v : o.fallback(), provisional: true };
|
|
137303
|
+
return raceTimeout(run2.then((v) => ({ value: v, provisional: false })), ask.settle ? o.settleMs ?? 2e4 : o.softMs, soft);
|
|
137381
137304
|
};
|
|
137382
137305
|
}
|
|
137383
137306
|
function localUsageReader(o) {
|
|
@@ -137466,10 +137389,10 @@ function cursorRefusalIn(answer) {
|
|
|
137466
137389
|
var STATUS_FOR_MS = 6e4;
|
|
137467
137390
|
function cursorProfile() {
|
|
137468
137391
|
let status = null;
|
|
137469
|
-
const localUsage = cursorUsageReader(async (
|
|
137392
|
+
const localUsage = cursorUsageReader(async (timeout) => {
|
|
137470
137393
|
const install = findCursor();
|
|
137471
137394
|
if (!install) throw new Error("Cursor CLI not found");
|
|
137472
|
-
const r = await execText(install.command, [...install.args, "about", "--format", "json"], { timeoutMs:
|
|
137395
|
+
const r = await execText(install.command, [...install.args, "about", "--format", "json"], { timeoutMs: timeout, env: { ...process.env, ...install.env } });
|
|
137473
137396
|
return r.stdout;
|
|
137474
137397
|
});
|
|
137475
137398
|
return {
|
|
@@ -137512,18 +137435,18 @@ var CursorAgentAdapter = class extends AcpAdapter {
|
|
|
137512
137435
|
// packages/agent-host/src/adapters/opencode/config-files.ts
|
|
137513
137436
|
import { existsSync as existsSync23, readdirSync as readdirSync16, readFileSync as readFileSync20 } from "node:fs";
|
|
137514
137437
|
import { homedir as homedir15 } from "node:os";
|
|
137515
|
-
import { dirname as dirname25, extname as extname3, join as
|
|
137438
|
+
import { dirname as dirname25, extname as extname3, join as join49, relative as relative7 } from "node:path";
|
|
137516
137439
|
function readOpenCodeConfigs(cwd, env, home = homedir15()) {
|
|
137517
|
-
const global2 =
|
|
137440
|
+
const global2 = join49(env.XDG_CONFIG_HOME || join49(home, ".config"), "opencode");
|
|
137518
137441
|
const project2 = !env.OPENCODE_DISABLE_PROJECT_CONFIG;
|
|
137519
137442
|
const upward = project2 ? foldersUp(cwd) : [];
|
|
137520
|
-
const dotFolders = [...upward.map((d2) =>
|
|
137443
|
+
const dotFolders = [...upward.map((d2) => join49(d2, ".opencode")), join49(home, ".opencode"), ...env.OPENCODE_CONFIG_DIR ? [env.OPENCODE_CONFIG_DIR] : []];
|
|
137521
137444
|
const files2 = [
|
|
137522
|
-
...["config.json", "opencode.json", "opencode.jsonc"].map((f) =>
|
|
137445
|
+
...["config.json", "opencode.json", "opencode.jsonc"].map((f) => join49(global2, f)),
|
|
137523
137446
|
...env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : [],
|
|
137524
|
-
...upward.flatMap((d2) => CONFIG_NAMES.map((f) =>
|
|
137525
|
-
...dotFolders.flatMap((d2) => CONFIG_NAMES.map((f) =>
|
|
137526
|
-
...CONFIG_NAMES.map((f) =>
|
|
137447
|
+
...upward.flatMap((d2) => CONFIG_NAMES.map((f) => join49(d2, f))),
|
|
137448
|
+
...dotFolders.flatMap((d2) => CONFIG_NAMES.map((f) => join49(d2, f))),
|
|
137449
|
+
...CONFIG_NAMES.map((f) => join49(managedFolder(env), f))
|
|
137527
137450
|
];
|
|
137528
137451
|
return {
|
|
137529
137452
|
layers: files2.map(readConfig).filter((c) => c !== null),
|
|
@@ -137535,7 +137458,7 @@ function foldersUp(cwd) {
|
|
|
137535
137458
|
const out = [];
|
|
137536
137459
|
for (let d2 = cwd; ; d2 = dirname25(d2)) {
|
|
137537
137460
|
out.push(d2);
|
|
137538
|
-
if (existsSync23(
|
|
137461
|
+
if (existsSync23(join49(d2, ".git")) || dirname25(d2) === d2) return out;
|
|
137539
137462
|
}
|
|
137540
137463
|
}
|
|
137541
137464
|
function managedFolder(env) {
|
|
@@ -137577,13 +137500,13 @@ function stringEnd(text3, start3) {
|
|
|
137577
137500
|
return text3.length;
|
|
137578
137501
|
}
|
|
137579
137502
|
function agentNames(folder) {
|
|
137580
|
-
const named3 = (sub, deep) => markdown(
|
|
137503
|
+
const named3 = (sub, deep) => markdown(join49(folder, sub), deep).map((f) => relative7(join49(folder, sub), f).replaceAll("\\", "/").slice(0, -extname3(f).length));
|
|
137581
137504
|
return [...named3("agent", true), ...named3("agents", true), ...named3("mode", false), ...named3("modes", false)];
|
|
137582
137505
|
}
|
|
137583
137506
|
function markdown(folder, deep) {
|
|
137584
137507
|
try {
|
|
137585
137508
|
return readdirSync16(folder, { withFileTypes: true }).flatMap((e) => {
|
|
137586
|
-
const path2 =
|
|
137509
|
+
const path2 = join49(folder, e.name);
|
|
137587
137510
|
if (e.isDirectory()) return deep ? markdown(path2, deep) : [];
|
|
137588
137511
|
return e.name.endsWith(".md") ? [path2] : [];
|
|
137589
137512
|
});
|
|
@@ -137922,10 +137845,10 @@ var DESCRIPTOR3 = {
|
|
|
137922
137845
|
var VERSION_FOR_MS = 6e4;
|
|
137923
137846
|
function openCodeProfile() {
|
|
137924
137847
|
let known = null;
|
|
137925
|
-
const localUsage = openCodeUsageReader(async (
|
|
137848
|
+
const localUsage = openCodeUsageReader(async (timeout) => {
|
|
137926
137849
|
const l = findOpenCode();
|
|
137927
137850
|
if (!l) throw new Error("OpenCode not found");
|
|
137928
|
-
const r = await execText(l.command, [...l.args, "stats"], { timeoutMs:
|
|
137851
|
+
const r = await execText(l.command, [...l.args, "stats"], { timeoutMs: timeout, maxBuffer: 1024 * 1024 });
|
|
137929
137852
|
return r.stdout;
|
|
137930
137853
|
});
|
|
137931
137854
|
const version2 = async () => {
|
|
@@ -138081,7 +138004,7 @@ var ApprovalRules = class {
|
|
|
138081
138004
|
};
|
|
138082
138005
|
|
|
138083
138006
|
// packages/agent-host/src/sessions/project-registry.ts
|
|
138084
|
-
import { basename as
|
|
138007
|
+
import { basename as basename12 } from "node:path";
|
|
138085
138008
|
var ProjectRegistry = class {
|
|
138086
138009
|
constructor(host) {
|
|
138087
138010
|
this.host = host;
|
|
@@ -138146,7 +138069,7 @@ var ProjectRegistry = class {
|
|
|
138146
138069
|
return {
|
|
138147
138070
|
id: id3,
|
|
138148
138071
|
path: path2,
|
|
138149
|
-
name:
|
|
138072
|
+
name: basename12(path2),
|
|
138150
138073
|
defaultTool: this.host.firstTool(stored),
|
|
138151
138074
|
// Trust (M4, decision 3) — reads the same column as the app runtime. The trust toggle on screen shows
|
|
138152
138075
|
// this value
|
|
@@ -138783,9 +138706,6 @@ var AssistantProposals = class {
|
|
|
138783
138706
|
proposeMcpServer(spec) {
|
|
138784
138707
|
const nameError = proposedMcpServerNameError(spec.name);
|
|
138785
138708
|
if (nameError) return { ok: false, error: nameError };
|
|
138786
|
-
if (RESERVED_APP_IDS.includes(spec.name)) {
|
|
138787
|
-
return { ok: false, error: `"${spec.name}" is a reserved app name \u2014 propose a different name` };
|
|
138788
|
-
}
|
|
138789
138709
|
if (this.userAppExists(spec.name)) return { ok: false, error: `"${spec.name}" is already installed` };
|
|
138790
138710
|
if (this.mcpProposals().some((p) => p.name === spec.name)) return { ok: false, error: PENDING(spec.name) };
|
|
138791
138711
|
const proposals = this.mcpProposals();
|
|
@@ -139752,7 +139672,7 @@ var UsageRecorder = class {
|
|
|
139752
139672
|
|
|
139753
139673
|
// packages/agent-host/src/sessions/manager.ts
|
|
139754
139674
|
import { homedir as homedir17 } from "node:os";
|
|
139755
|
-
import { join as
|
|
139675
|
+
import { join as join52 } from "node:path";
|
|
139756
139676
|
|
|
139757
139677
|
// packages/agent-host/src/dev-services/store.ts
|
|
139758
139678
|
import Database3 from "better-sqlite3";
|
|
@@ -140295,14 +140215,14 @@ var KeptRuns = class {
|
|
|
140295
140215
|
*/
|
|
140296
140216
|
purgeKeptRuns(runIds) {
|
|
140297
140217
|
const tx2 = this.db.transaction(() => {
|
|
140298
|
-
let
|
|
140218
|
+
let gone2 = 0;
|
|
140299
140219
|
for (const id3 of runIds) {
|
|
140300
140220
|
this.db.prepare(`DELETE FROM app_run_messages WHERE run_id = ?`).run(id3);
|
|
140301
140221
|
this.db.prepare(`DELETE FROM app_run_subagent_messages WHERE run_id = ?`).run(id3);
|
|
140302
|
-
|
|
140222
|
+
gone2 += this.db.prepare(`DELETE FROM app_run_records WHERE run_id = ?`).run(id3).changes;
|
|
140303
140223
|
this.db.prepare(`UPDATE app_runs SET request = '', answer = NULL, output = NULL WHERE id = ? AND request IS NOT NULL`).run(id3);
|
|
140304
140224
|
}
|
|
140305
|
-
return
|
|
140225
|
+
return gone2;
|
|
140306
140226
|
});
|
|
140307
140227
|
return tx2();
|
|
140308
140228
|
}
|
|
@@ -140996,10 +140916,10 @@ var UserAppAdoptionRecords = class {
|
|
|
140996
140916
|
for (const { id: id3 } of assistants) {
|
|
140997
140917
|
const book = parseJson(this.settings.appSetting(`session_app_names:${id3}`));
|
|
140998
140918
|
const server2 = isObj(book) ? book[to] : void 0;
|
|
140999
|
-
if (typeof server2 !== "string" || !server2.startsWith(
|
|
140919
|
+
if (typeof server2 !== "string" || !server2.startsWith(APP_SERVER_PREFIX)) continue;
|
|
141000
140920
|
const raw = parseJson(this.settings.appSetting(`${ATTACHED_PREFIX}${id3}`));
|
|
141001
140921
|
const list2 = Array.isArray(raw) ? raw : [];
|
|
141002
|
-
if (list2.some((r) => isObj(r) && r.projectId === projectId && r.appId
|
|
140922
|
+
if (list2.some((r) => isObj(r) && typeof r.appId === "string" && (r.projectId === null || typeof r.projectId === "string") && sameApp({ projectId: r.projectId, appId: r.appId }, { projectId, appId }))) continue;
|
|
141003
140923
|
list2.push({ projectId, appId, server: server2, consent: "none", at: Date.now() });
|
|
141004
140924
|
this.settings.setAppSetting(`${ATTACHED_PREFIX}${id3}`, JSON.stringify(list2));
|
|
141005
140925
|
}
|
|
@@ -144535,8 +144455,8 @@ async function gitBranchPr(projectCwd, branch, signal, timeoutMs = OK2.timeout)
|
|
|
144535
144455
|
}
|
|
144536
144456
|
|
|
144537
144457
|
// packages/agent-host/src/dev-services/file-search.ts
|
|
144538
|
-
import { readdir as
|
|
144539
|
-
import { join as
|
|
144458
|
+
import { readdir as readdir13 } from "node:fs/promises";
|
|
144459
|
+
import { join as join50 } from "node:path";
|
|
144540
144460
|
var MAX_FILES2 = 2e4;
|
|
144541
144461
|
var TTL_MS2 = 15e3;
|
|
144542
144462
|
var WALK_DEPTH = 6;
|
|
@@ -144566,7 +144486,7 @@ async function walk(root3) {
|
|
|
144566
144486
|
const { dir, rel, depth } = next;
|
|
144567
144487
|
let entries;
|
|
144568
144488
|
try {
|
|
144569
|
-
entries = await
|
|
144489
|
+
entries = await readdir13(dir, { withFileTypes: true });
|
|
144570
144490
|
} catch {
|
|
144571
144491
|
continue;
|
|
144572
144492
|
}
|
|
@@ -144574,7 +144494,7 @@ async function walk(root3) {
|
|
|
144574
144494
|
if (e.name.startsWith(".") && e.name !== ".env") continue;
|
|
144575
144495
|
if (e.isDirectory()) {
|
|
144576
144496
|
if (SKIP.has(e.name) || depth >= WALK_DEPTH) continue;
|
|
144577
|
-
queue.push({ dir:
|
|
144497
|
+
queue.push({ dir: join50(dir, e.name), rel: wireJoin(rel, e.name), depth: depth + 1 });
|
|
144578
144498
|
} else {
|
|
144579
144499
|
out.push(wireJoin(rel, e.name).normalize("NFC"));
|
|
144580
144500
|
if (out.length >= MAX_FILES2) break;
|
|
@@ -144920,8 +144840,8 @@ var AskProjectFlow = class {
|
|
|
144920
144840
|
);
|
|
144921
144841
|
if (!opts.task && !outstanding.length) {
|
|
144922
144842
|
const named3 = (id3) => !wantedSession || id3 === wantedSession || this.host.meta.get(id3)?.name.toLowerCase() === wantedSession.toLowerCase();
|
|
144923
|
-
const
|
|
144924
|
-
if (
|
|
144843
|
+
const gone3 = [...this.host.children.handedOver].find(([id3, h]) => h.from === callerId && this.host.meta.get(id3)?.projectId === target.id && named3(id3));
|
|
144844
|
+
if (gone3) return this.host.delegationFlow.handedOverReply(callerId, gone3[0]);
|
|
144925
144845
|
}
|
|
144926
144846
|
if (!opts.task && !wantedSession && outstanding.length === 1) {
|
|
144927
144847
|
const [key2, pending2] = outstanding[0];
|
|
@@ -144940,8 +144860,8 @@ var AskProjectFlow = class {
|
|
|
144940
144860
|
const current2 = this.host.meta.get(chosen.id);
|
|
144941
144861
|
if (!current2 || current2.projectId !== target.id || !isOrdinary(current2)) return "The chosen session is no longer available";
|
|
144942
144862
|
};
|
|
144943
|
-
const
|
|
144944
|
-
if (
|
|
144863
|
+
const gone2 = available();
|
|
144864
|
+
if (gone2) return { ok: false, error: gone2 };
|
|
144945
144865
|
const consent = await this.host.ensureProjectAccess(callerId, target.id, "delegate", {
|
|
144946
144866
|
text: taskLine(opts.task),
|
|
144947
144867
|
session: { id: chosen.id, name: chosen.name }
|
|
@@ -145359,7 +145279,7 @@ var HandoffFlow = class {
|
|
|
145359
145279
|
const name = trustedJsonText(target.name);
|
|
145360
145280
|
try {
|
|
145361
145281
|
const r = await raceBound(turn.done.then(() => null, (e) => e), this.timings.noteMs);
|
|
145362
|
-
if (r === "bound" || r === "aborted") return { ok: false, error: `${name} wrote no note in ${
|
|
145282
|
+
if (r === "bound" || r === "aborted") return { ok: false, error: `${name} wrote no note in ${durationText(this.timings.noteMs)}; nothing was handed off.` };
|
|
145363
145283
|
if (r) return { ok: false, error: `${name} did not write its note: ${r.message}; nothing was handed off. Hand it off from the record (mode "record").` };
|
|
145364
145284
|
const cur = this.host.meta.get(target.id);
|
|
145365
145285
|
if (!cur) return { ok: false, error: `${name} disappeared while writing its note; nothing was handed off.` };
|
|
@@ -145723,14 +145643,14 @@ async function readMessageImage(abs, max = IMAGE_PREVIEW_MAX_BYTES) {
|
|
|
145723
145643
|
}
|
|
145724
145644
|
|
|
145725
145645
|
// packages/agent-host/src/dev-services/attachments.ts
|
|
145726
|
-
import { lstat as lstat12, mkdir as
|
|
145727
|
-
import { extname as extname4, join as
|
|
145728
|
-
var root2 = () =>
|
|
145646
|
+
import { lstat as lstat12, mkdir as mkdir8, readdir as readdir14, writeFile as writeFile6 } from "node:fs/promises";
|
|
145647
|
+
import { extname as extname4, join as join51 } from "node:path";
|
|
145648
|
+
var root2 = () => join51(dataRoot(), "attachments");
|
|
145729
145649
|
function sessionDir(sessionId) {
|
|
145730
145650
|
if (!isSessionId(sessionId)) {
|
|
145731
145651
|
throw rpcError(`Not a session id: ${sessionId}`);
|
|
145732
145652
|
}
|
|
145733
|
-
return
|
|
145653
|
+
return join51(root2(), sessionId);
|
|
145734
145654
|
}
|
|
145735
145655
|
var EXT = {
|
|
145736
145656
|
"image/png": ".png",
|
|
@@ -145740,9 +145660,9 @@ var EXT = {
|
|
|
145740
145660
|
};
|
|
145741
145661
|
async function saveAttachment(sessionId, name, mime, dataBase64) {
|
|
145742
145662
|
const dir = sessionDir(sessionId);
|
|
145743
|
-
await
|
|
145663
|
+
await mkdir8(dir, { recursive: true });
|
|
145744
145664
|
const ext2 = extname4(name) || EXT[mime] || "";
|
|
145745
|
-
const file2 =
|
|
145665
|
+
const file2 = join51(dir, `${Date.now()}-${Math.random().toString(36).slice(2, 8)}${ext2}`);
|
|
145746
145666
|
const buf = Buffer.from(dataBase64, "base64");
|
|
145747
145667
|
await writeFile6(file2, buf);
|
|
145748
145668
|
return { kind: mime.startsWith("image/") ? "image" : "file", path: file2, name, mime, bytes: buf.length };
|
|
@@ -145758,15 +145678,15 @@ async function sweepAttachments(maxBytes = ATTACHMENTS_MAX_BYTES) {
|
|
|
145758
145678
|
const files2 = [];
|
|
145759
145679
|
let dirs;
|
|
145760
145680
|
try {
|
|
145761
|
-
dirs = await
|
|
145681
|
+
dirs = await readdir14(root2());
|
|
145762
145682
|
} catch {
|
|
145763
145683
|
return 0;
|
|
145764
145684
|
}
|
|
145765
145685
|
for (const d2 of dirs) {
|
|
145766
|
-
const dir =
|
|
145767
|
-
const names = await
|
|
145686
|
+
const dir = join51(root2(), d2);
|
|
145687
|
+
const names = await readdir14(dir).catch(() => []);
|
|
145768
145688
|
for (const name of names) {
|
|
145769
|
-
const p =
|
|
145689
|
+
const p = join51(dir, name);
|
|
145770
145690
|
const s = await lstat12(p).catch(() => null);
|
|
145771
145691
|
if (s?.isFile()) files2.push({ path: p, size: s.size, mtime: s.mtimeMs });
|
|
145772
145692
|
}
|
|
@@ -146023,14 +145943,14 @@ var SessionRecord = class {
|
|
|
146023
145943
|
}
|
|
146024
145944
|
async loadMessages(sessionId, limit, beforeSeq) {
|
|
146025
145945
|
const rows3 = this.host.store.messages.loadMessages(sessionId, limit, beforeSeq);
|
|
146026
|
-
const { readFile:
|
|
145946
|
+
const { readFile: readFile11 } = await import("node:fs/promises");
|
|
146027
145947
|
return Promise.all(
|
|
146028
145948
|
rows3.map(async (r) => {
|
|
146029
145949
|
if (r.kind === "image") {
|
|
146030
145950
|
const p = r.payload;
|
|
146031
145951
|
if (!p.path || p.note) return r;
|
|
146032
145952
|
try {
|
|
146033
|
-
const data = (await
|
|
145953
|
+
const data = (await readFile11(p.path)).toString("base64");
|
|
146034
145954
|
return { ...r, payload: { ...p, data } };
|
|
146035
145955
|
} catch {
|
|
146036
145956
|
return { ...r, payload: { ...p, note: "the saved copy was cleared (total-size cap)" } };
|
|
@@ -146043,7 +145963,7 @@ var SessionRecord = class {
|
|
|
146043
145963
|
p.attachments.map(async (a) => {
|
|
146044
145964
|
if (a.kind !== "image") return a;
|
|
146045
145965
|
try {
|
|
146046
|
-
return { ...a, data: (await
|
|
145966
|
+
return { ...a, data: (await readFile11(a.path)).toString("base64") };
|
|
146047
145967
|
} catch {
|
|
146048
145968
|
return a;
|
|
146049
145969
|
}
|
|
@@ -146302,7 +146222,7 @@ Answer in the language the person writes in.`;
|
|
|
146302
146222
|
}
|
|
146303
146223
|
|
|
146304
146224
|
// packages/agent-host/src/sessions/app-sessions.ts
|
|
146305
|
-
var builderKey = (ref) => appKeyOf(ref
|
|
146225
|
+
var builderKey = (ref) => appKeyOf(ref);
|
|
146306
146226
|
var APP_BUILDERS_KEY = "apps.builders";
|
|
146307
146227
|
var AppSessions = class {
|
|
146308
146228
|
constructor(host) {
|
|
@@ -146428,7 +146348,7 @@ var AppSessions = class {
|
|
|
146428
146348
|
async standUpBuilder(ref, tool) {
|
|
146429
146349
|
const rt2 = this.host.appsHub?.rt;
|
|
146430
146350
|
if (!rt2) throw rpcError("External apps are unavailable");
|
|
146431
|
-
const app2 = rt2.list().find((a) => a
|
|
146351
|
+
const app2 = rt2.list().find((a) => sameApp(a, ref));
|
|
146432
146352
|
if (!app2) throw rpcError(noSuchAppText(ref));
|
|
146433
146353
|
if (!app2.trusted) {
|
|
146434
146354
|
throw rpcError("Centralu does not give a builder to an app in a project it does not trust \u2014 trust the project, and the app can start and be tested");
|
|
@@ -146723,7 +146643,7 @@ function appAgentPreset(callers, presetOf) {
|
|
|
146723
146643
|
}
|
|
146724
146644
|
|
|
146725
146645
|
// packages/agent-host/src/sessions/session-trash.ts
|
|
146726
|
-
import { basename as
|
|
146646
|
+
import { basename as basename13 } from "node:path";
|
|
146727
146647
|
import { existsSync as existsSync25, statSync as statSync17 } from "node:fs";
|
|
146728
146648
|
var SessionTrash = class {
|
|
146729
146649
|
constructor(host) {
|
|
@@ -147088,7 +147008,7 @@ var SessionTrash = class {
|
|
|
147088
147008
|
this.host.store.projects.addProject({
|
|
147089
147009
|
id: record2.projectId,
|
|
147090
147010
|
path: record2.projectPath,
|
|
147091
|
-
name: record2.projectName ??
|
|
147011
|
+
name: record2.projectName ?? basename13(record2.projectPath)
|
|
147092
147012
|
});
|
|
147093
147013
|
projectId = record2.projectId;
|
|
147094
147014
|
registered = await this.host.projectInfo(projectId, record2.projectPath);
|
|
@@ -147461,7 +147381,7 @@ function stands(o, proto) {
|
|
|
147461
147381
|
return Object.getPrototypeOf(o) === proto;
|
|
147462
147382
|
}
|
|
147463
147383
|
var SessionManager = class {
|
|
147464
|
-
constructor(store2, adapters2, emit, endpoint, worktreeRoot =
|
|
147384
|
+
constructor(store2, adapters2, emit, endpoint, worktreeRoot = join52(homedir17(), DATA_DIR, "worktrees"), keeperOpts = {}) {
|
|
147465
147385
|
this.store = store2;
|
|
147466
147386
|
this.adapters = adapters2;
|
|
147467
147387
|
this.emit = emit;
|
|
@@ -149104,8 +149024,8 @@ function tellCard(service, giver, card, body, delivered) {
|
|
|
149104
149024
|
}
|
|
149105
149025
|
function withdrawEndedCards(records, session2, stands2) {
|
|
149106
149026
|
records.transaction(() => {
|
|
149107
|
-
const
|
|
149108
|
-
if (
|
|
149027
|
+
const gone2 = records.undeliveredCardNotices(session2).filter(({ message: { facts } }) => facts.card && !stands2(facts.card.session, facts.card.requestId));
|
|
149028
|
+
if (gone2.length) records.deleteRows(gone2.map(({ row }) => ({ messageId: row.messageId, recipient: row.recipient })));
|
|
149109
149029
|
});
|
|
149110
149030
|
}
|
|
149111
149031
|
|
|
@@ -149686,7 +149606,7 @@ var MessageService = class {
|
|
|
149686
149606
|
if (!said) return "the person has typed nothing in this session that it could cite";
|
|
149687
149607
|
const age2 = now - said.ts;
|
|
149688
149608
|
if (age2 < 0) return "the person's last message here is dated later than now";
|
|
149689
|
-
if (age2 > CITE_MS) return `the person's last message here is ${
|
|
149609
|
+
if (age2 > CITE_MS) return `the person's last message here is ${durationText(age2)} old, and a citation may be ${durationText(CITE_MS)} at most`;
|
|
149690
149610
|
if (this.records.hasDedupe(sender, citeKey(said.seq))) return "the person's last message here was cited by an earlier request already";
|
|
149691
149611
|
return { seq: said.seq, at: said.ts };
|
|
149692
149612
|
}
|
|
@@ -151170,7 +151090,7 @@ var MailAcross = class {
|
|
|
151170
151090
|
if (!h.you) return away.push({ name: h.name, why: "it runs an older Centralu; update it there" });
|
|
151171
151091
|
if (!h.reachable) return away.push({ name: h.name, why: "not reachable right now" });
|
|
151172
151092
|
try {
|
|
151173
|
-
const raw = await
|
|
151093
|
+
const raw = await withTimeout(h.call("hub.find", { query, limit: exact ? 50 : FIND_LIMIT, ...exact ? { exact: true } : {} }), ms3, noAnswer);
|
|
151174
151094
|
const r = HubFindResult.safeParse(raw);
|
|
151175
151095
|
if (!r.success) return away.push({ name: h.name, why: "its answer could not be read" });
|
|
151176
151096
|
for (const e of r.data.entries) {
|
|
@@ -151228,12 +151148,7 @@ function stateOf(r) {
|
|
|
151228
151148
|
function pickState(r) {
|
|
151229
151149
|
return stateOf(r);
|
|
151230
151150
|
}
|
|
151231
|
-
|
|
151232
|
-
return new Promise((_, reject) => {
|
|
151233
|
-
const t = setTimeout(() => reject(new Error(`no answer within ${ms3 / 1e3} s`)), ms3);
|
|
151234
|
-
t.unref?.();
|
|
151235
|
-
});
|
|
151236
|
-
}
|
|
151151
|
+
var noAnswer = (ms3) => `no answer within ${durationText(ms3)}`;
|
|
151237
151152
|
|
|
151238
151153
|
// packages/agent-host/src/mail/turns.ts
|
|
151239
151154
|
var STARTED_BY = ["mail", "person", "caller", "cli", "report", "app"];
|
|
@@ -151803,7 +151718,7 @@ function factsOf(s) {
|
|
|
151803
151718
|
}
|
|
151804
151719
|
|
|
151805
151720
|
// packages/agent-host/src/sessions/memory-gate.ts
|
|
151806
|
-
import { readFile as
|
|
151721
|
+
import { readFile as readFile8 } from "node:fs/promises";
|
|
151807
151722
|
import { freemem } from "node:os";
|
|
151808
151723
|
var MEMORY_FLOOR_BYTES = 2 * 1024 ** 3;
|
|
151809
151724
|
var MEMORY_RECHECK_MS = 15e3;
|
|
@@ -151830,7 +151745,7 @@ async function readAvailableMemory(deps = {}) {
|
|
|
151830
151745
|
if (source.kind === "freemem") return free();
|
|
151831
151746
|
const what = source.kind === "command" ? source.file : source.path;
|
|
151832
151747
|
try {
|
|
151833
|
-
const value = source.kind === "command" ? parseVmStat((await (deps.exec ?? ((f, a) => execText(f, a, { timeoutMs: 5e3 })))(source.file, source.args)).stdout) : parseMemInfo(await (deps.readText ?? ((p) =>
|
|
151748
|
+
const value = source.kind === "command" ? parseVmStat((await (deps.exec ?? ((f, a) => execText(f, a, { timeoutMs: 5e3 })))(source.file, source.args)).stdout) : parseMemInfo(await (deps.readText ?? ((p) => readFile8(p, "utf8")))(source.path));
|
|
151834
151749
|
if (value !== null) return value;
|
|
151835
151750
|
console.error(`[memory-gate] could not parse ${what}; letting agent starts through`);
|
|
151836
151751
|
} catch (e) {
|
|
@@ -151924,9 +151839,195 @@ var MemoryGate = class {
|
|
|
151924
151839
|
// packages/agent-host/src/rpc.ts
|
|
151925
151840
|
import { relative as relative9 } from "node:path";
|
|
151926
151841
|
|
|
151842
|
+
// packages/agent-host/src/themes.ts
|
|
151843
|
+
import { randomBytes as randomBytes11 } from "node:crypto";
|
|
151844
|
+
import { watch as watch4 } from "node:fs";
|
|
151845
|
+
import { mkdir as mkdir9, readdir as readdir15, readFile as readFile9, stat as stat12 } from "node:fs/promises";
|
|
151846
|
+
import { basename as basename14, join as join53 } from "node:path";
|
|
151847
|
+
var MAX_FILE_BYTES = 256 * 1024;
|
|
151848
|
+
var SETTLE_MS = 100;
|
|
151849
|
+
var REMOVED_DIR = ".removed";
|
|
151850
|
+
var ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,59}$/;
|
|
151851
|
+
var ThemeFiles = class {
|
|
151852
|
+
constructor(dir, onChange) {
|
|
151853
|
+
this.dir = dir;
|
|
151854
|
+
this.onChange = onChange;
|
|
151855
|
+
}
|
|
151856
|
+
dir;
|
|
151857
|
+
onChange;
|
|
151858
|
+
watcher = null;
|
|
151859
|
+
timer = null;
|
|
151860
|
+
/** Makes the folder, writes the schema next to the themes, and starts watching */
|
|
151861
|
+
async start() {
|
|
151862
|
+
await mkdir9(this.dir, { recursive: true });
|
|
151863
|
+
await this.writeSchema();
|
|
151864
|
+
try {
|
|
151865
|
+
this.watcher = watch4(this.dir, (_event, name) => {
|
|
151866
|
+
if (name && !String(name).endsWith(".json")) return;
|
|
151867
|
+
if (name === THEME_SCHEMA_FILE) return;
|
|
151868
|
+
if (this.timer) clearTimeout(this.timer);
|
|
151869
|
+
this.timer = setTimeout(() => {
|
|
151870
|
+
this.timer = null;
|
|
151871
|
+
this.onChange();
|
|
151872
|
+
}, SETTLE_MS);
|
|
151873
|
+
});
|
|
151874
|
+
this.watcher.on("error", () => this.stopWatching());
|
|
151875
|
+
} catch {
|
|
151876
|
+
}
|
|
151877
|
+
}
|
|
151878
|
+
close() {
|
|
151879
|
+
this.stopWatching();
|
|
151880
|
+
if (this.timer) clearTimeout(this.timer);
|
|
151881
|
+
this.timer = null;
|
|
151882
|
+
}
|
|
151883
|
+
stopWatching() {
|
|
151884
|
+
this.watcher?.close();
|
|
151885
|
+
this.watcher = null;
|
|
151886
|
+
}
|
|
151887
|
+
/**
|
|
151888
|
+
* The schema an editor uses for completion, written only when it differs — a build that adds
|
|
151889
|
+
* a token updates it, and an unchanged one does not touch the folder (or wake the watcher).
|
|
151890
|
+
*/
|
|
151891
|
+
async writeSchema() {
|
|
151892
|
+
const path2 = join53(this.dir, THEME_SCHEMA_FILE);
|
|
151893
|
+
const text3 = `${JSON.stringify(themeFileJsonSchema(), null, 2)}
|
|
151894
|
+
`;
|
|
151895
|
+
const current = await readFile9(path2, "utf8").catch(() => null);
|
|
151896
|
+
if (current !== text3) writeFileWhole(realOs().files, path2, text3);
|
|
151897
|
+
}
|
|
151898
|
+
/** Every `<id>.json` in the folder, read and checked. A file that cannot be read is listed with the reason. */
|
|
151899
|
+
async list() {
|
|
151900
|
+
const names = await readdir15(this.dir).catch(() => []);
|
|
151901
|
+
const entries = [];
|
|
151902
|
+
const ids = names.filter((name) => name.endsWith(".json") && name !== THEME_SCHEMA_FILE).map((name) => name.slice(0, -".json".length)).filter((id3) => ID_PATTERN.test(id3)).sort();
|
|
151903
|
+
for (const id3 of ids) entries.push(await this.read(id3));
|
|
151904
|
+
return entries;
|
|
151905
|
+
}
|
|
151906
|
+
async read(id3) {
|
|
151907
|
+
const path2 = this.pathOf(id3);
|
|
151908
|
+
try {
|
|
151909
|
+
const info = await stat12(path2);
|
|
151910
|
+
if (info.size > MAX_FILE_BYTES) {
|
|
151911
|
+
return { id: id3, path: path2, name: id3, base: "dark", tokens: {}, problems: ["The file is too large to be a theme."], broken: true };
|
|
151912
|
+
}
|
|
151913
|
+
return parseThemeFile(id3, path2, await readFile9(path2, "utf8"));
|
|
151914
|
+
} catch (e) {
|
|
151915
|
+
return { id: id3, path: path2, name: id3, base: "dark", tokens: {}, problems: [`Could not read the file: ${e.message}`], broken: true };
|
|
151916
|
+
}
|
|
151917
|
+
}
|
|
151918
|
+
/** Writes a theme. `id` null makes a new file named after the theme (`My theme` → `my-theme.json`). */
|
|
151919
|
+
async save(id3, content) {
|
|
151920
|
+
const text3 = formatThemeFile(content);
|
|
151921
|
+
if (Buffer.byteLength(text3) > MAX_FILE_BYTES) throw rpcError("The theme is too large to be a theme file.");
|
|
151922
|
+
const target = id3 ?? await this.freeId(content.name);
|
|
151923
|
+
if (id3 !== null && isPresetThemeId(id3) && !await stat12(this.pathOf(id3)).then(() => true, () => false)) throw rpcError(presetIdRefusal(id3));
|
|
151924
|
+
await mkdir9(this.dir, { recursive: true });
|
|
151925
|
+
const names = await readdir15(this.dir).catch(() => []);
|
|
151926
|
+
const clash = names.find((n) => n !== `${target}.json` && n.toLowerCase() === `${target}.json`);
|
|
151927
|
+
if (clash) throw rpcError(`The themes folder has ${clash}, which the list does not show (ids are lowercase); rename or remove it first.`);
|
|
151928
|
+
writeFileWhole(realOs().files, this.pathOf(target), text3);
|
|
151929
|
+
return this.read(target);
|
|
151930
|
+
}
|
|
151931
|
+
/**
|
|
151932
|
+
* Takes a theme file out of the list without destroying it: it moves to `.removed/<id>-<time>-<random>.json`, a place the list
|
|
151933
|
+
* does not look, so a mistaken removal is one move back. The host has no OS trash (Settings' button reaches it through the
|
|
151934
|
+
* shell), so these stay until the person clears the folder. Where it went is returned; null when there was no such file.
|
|
151935
|
+
*/
|
|
151936
|
+
async remove(id3) {
|
|
151937
|
+
const from = this.pathOf(id3);
|
|
151938
|
+
if (!await stat12(from).then(() => true, () => false)) return null;
|
|
151939
|
+
const kept = join53(this.dir, REMOVED_DIR);
|
|
151940
|
+
await mkdir9(kept, { recursive: true });
|
|
151941
|
+
const to = join53(kept, `${id3}-${Date.now()}-${randomBytes11(3).toString("hex")}.json`);
|
|
151942
|
+
await realOs().files.promises.rename(from, to);
|
|
151943
|
+
return to;
|
|
151944
|
+
}
|
|
151945
|
+
/** Copies a file from elsewhere in, under a fresh id if its name is taken. Refuses what does not read as a theme. */
|
|
151946
|
+
async importFrom(source) {
|
|
151947
|
+
const info = await stat12(source);
|
|
151948
|
+
if (!info.isFile()) throw rpcError("That is not a file.");
|
|
151949
|
+
if (info.size > MAX_FILE_BYTES) throw rpcError("The file is too large to be a theme.");
|
|
151950
|
+
const text3 = await readFile9(source, "utf8");
|
|
151951
|
+
const parsed = parseThemeFile("import", source, text3);
|
|
151952
|
+
if (parsed.broken) throw rpcError(parsed.problems[0] ?? "Not a theme file.");
|
|
151953
|
+
const fromName = basename14(source).replace(/\.json$/i, "");
|
|
151954
|
+
const id3 = await this.freeId(parsed.name !== "import" ? parsed.name : fromName);
|
|
151955
|
+
writeFileWhole(realOs().files, this.pathOf(id3), text3);
|
|
151956
|
+
return this.read(id3);
|
|
151957
|
+
}
|
|
151958
|
+
/** The absolute path for an id, for the shell to trash or reveal. Refuses anything that is not an id. */
|
|
151959
|
+
pathOf(id3) {
|
|
151960
|
+
if (!ID_PATTERN.test(id3)) throw rpcError(`Not a theme id: ${id3}`);
|
|
151961
|
+
return join53(this.dir, `${id3}.json`);
|
|
151962
|
+
}
|
|
151963
|
+
/** The id a new file named `name` goes under (`freeThemeId`): not one of the files here, not a preset's */
|
|
151964
|
+
async freeId(name) {
|
|
151965
|
+
const names = new Set((await readdir15(this.dir).catch(() => [])).map((n) => n.toLowerCase()));
|
|
151966
|
+
return freeThemeId(name, (id3) => names.has(`${id3}.json`));
|
|
151967
|
+
}
|
|
151968
|
+
};
|
|
151969
|
+
|
|
151927
151970
|
// packages/agent-host/src/dev-services/strays.ts
|
|
151971
|
+
import { createHash as createHash14, randomBytes as randomBytes12 } from "node:crypto";
|
|
151928
151972
|
import { realpathSync as realpathSync11 } from "node:fs";
|
|
151929
151973
|
import { userInfo as userInfo2 } from "node:os";
|
|
151974
|
+
|
|
151975
|
+
// packages/agent-host/src/os/process-env.ts
|
|
151976
|
+
import { readFile as readFile10, readdir as readdir16 } from "node:fs/promises";
|
|
151977
|
+
async function environmentValues(name, pids, platform = HOST_PLATFORM, run2 = execText) {
|
|
151978
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`not a variable name: ${name}`);
|
|
151979
|
+
if (platform === "linux") return procValues(name, pids);
|
|
151980
|
+
if (platform !== "darwin") return /* @__PURE__ */ new Map();
|
|
151981
|
+
if (pids !== "all" && pids.length === 0) return /* @__PURE__ */ new Map();
|
|
151982
|
+
const which = pids === "all" ? ["-A"] : ["-p", pids.join(",")];
|
|
151983
|
+
try {
|
|
151984
|
+
const { stdout } = await run2("ps", ["-E", "-ww", "-o", "pid=,command=", ...which], { timeoutMs: PS_TIMEOUT_MS, maxBuffer: 64 * 1024 * 1024 });
|
|
151985
|
+
return psEnvironmentValues(stdout, name);
|
|
151986
|
+
} catch (e) {
|
|
151987
|
+
if (isExecFailure(e) && typeof e.code === "number" && !e.ended) return psEnvironmentValues(e.stdout, name);
|
|
151988
|
+
throw new Error(`ps could not list environments: ${isExecFailure(e) ? e.ended ?? `exit ${String(e.code)}` : errorMessage(e)}`);
|
|
151989
|
+
}
|
|
151990
|
+
}
|
|
151991
|
+
var PS_TIMEOUT_MS = 5e3;
|
|
151992
|
+
async function procValues(name, pids) {
|
|
151993
|
+
const all = pids === "all" ? (await readdir16("/proc")).filter((d2) => /^\d+$/.test(d2)).map(Number) : pids;
|
|
151994
|
+
const out = /* @__PURE__ */ new Map();
|
|
151995
|
+
await Promise.all(
|
|
151996
|
+
all.map(async (pid) => {
|
|
151997
|
+
try {
|
|
151998
|
+
const value = environValue(await readFile10(`/proc/${pid}/environ`, "utf8"), name);
|
|
151999
|
+
if (value !== void 0) out.set(pid, value);
|
|
152000
|
+
} catch {
|
|
152001
|
+
}
|
|
152002
|
+
})
|
|
152003
|
+
);
|
|
152004
|
+
return out;
|
|
152005
|
+
}
|
|
152006
|
+
function environValue(environ, name) {
|
|
152007
|
+
const prefix = `${name}=`;
|
|
152008
|
+
for (const entry of environ.split("\0")) if (entry.startsWith(prefix)) return entry.slice(prefix.length);
|
|
152009
|
+
return void 0;
|
|
152010
|
+
}
|
|
152011
|
+
function psEnvironmentValues(out, name) {
|
|
152012
|
+
const values2 = /* @__PURE__ */ new Map();
|
|
152013
|
+
const entry = new RegExp(`(?:^|\\s)${name}=(\\S*)`, "g");
|
|
152014
|
+
for (const line of out.split("\n")) {
|
|
152015
|
+
const m = /^\s*(\d+)\s(.*)$/.exec(line);
|
|
152016
|
+
if (!m) continue;
|
|
152017
|
+
const found = [...(m[2] ?? "").matchAll(entry)].pop();
|
|
152018
|
+
if (found) values2.set(Number(m[1]), found[1] ?? "");
|
|
152019
|
+
}
|
|
152020
|
+
return values2;
|
|
152021
|
+
}
|
|
152022
|
+
|
|
152023
|
+
// packages/agent-host/src/dev-services/strays.ts
|
|
152024
|
+
var OWNER_MARK = "CENTRALU_OWNER";
|
|
152025
|
+
function ownerMarkFor(dbPath2) {
|
|
152026
|
+
return dbPath2 === ":memory:" ? randomBytes12(8).toString("hex") : createHash14("sha256").update(dbPath2).digest("hex").slice(0, 16);
|
|
152027
|
+
}
|
|
152028
|
+
function markOwnChildren(dbPath2, env = process.env) {
|
|
152029
|
+
env[OWNER_MARK] = ownerMarkFor(dbPath2);
|
|
152030
|
+
}
|
|
151930
152031
|
function parsePsRows(out) {
|
|
151931
152032
|
const rows3 = [];
|
|
151932
152033
|
for (const line of out.split("\n")) {
|
|
@@ -151960,7 +152061,7 @@ function insideAny(cwd, roots) {
|
|
|
151960
152061
|
}
|
|
151961
152062
|
return null;
|
|
151962
152063
|
}
|
|
151963
|
-
function
|
|
152064
|
+
function candidatesOf(rows3, cwdOf, roots, selfPid) {
|
|
151964
152065
|
const ours = descendants(rows3, [selfPid]);
|
|
151965
152066
|
const launchers = ancestors(rows3, [selfPid]);
|
|
151966
152067
|
const candidates = /* @__PURE__ */ new Map();
|
|
@@ -151971,23 +152072,28 @@ function pickStrays(rows3, cwdOf, roots, selfPid, adopter = null) {
|
|
|
151971
152072
|
if (!cwd || !insideAny(cwd, roots)) continue;
|
|
151972
152073
|
candidates.set(r.pid, cwd);
|
|
151973
152074
|
}
|
|
152075
|
+
return candidates;
|
|
152076
|
+
}
|
|
152077
|
+
function markAsked(rows3, cwdOf, roots, selfPid) {
|
|
152078
|
+
const candidates = [...candidatesOf(rows3, cwdOf, roots, selfPid).keys()];
|
|
152079
|
+
const listed2 = new Set(rows3.map((r) => r.pid));
|
|
152080
|
+
return [.../* @__PURE__ */ new Set([...candidates, ...ancestors(rows3, candidates)])].filter((pid) => pid > 1 && listed2.has(pid)).sort((a, b2) => a - b2);
|
|
152081
|
+
}
|
|
152082
|
+
function pickStrays(rows3, cwdOf, roots, selfPid, marks, mark) {
|
|
151974
152083
|
const byPid = new Map(rows3.map((r) => [r.pid, r]));
|
|
151975
|
-
const
|
|
152084
|
+
const ourStart = (pid) => {
|
|
151976
152085
|
const seen = /* @__PURE__ */ new Set();
|
|
151977
|
-
let
|
|
151978
|
-
|
|
151979
|
-
|
|
151980
|
-
|
|
151981
|
-
if (!candidates.has(cur.ppid)) return false;
|
|
151982
|
-
cur = byPid.get(cur.ppid);
|
|
152086
|
+
for (let row = byPid.get(pid); row && row.pid > 1 && !seen.has(row.pid); row = byPid.get(row.ppid)) {
|
|
152087
|
+
const found = marks.get(row.pid);
|
|
152088
|
+
if (found !== void 0) return found === mark;
|
|
152089
|
+
seen.add(row.pid);
|
|
151983
152090
|
}
|
|
151984
152091
|
return false;
|
|
151985
152092
|
};
|
|
151986
152093
|
const out = [];
|
|
151987
|
-
for (const [pid, cwd] of
|
|
151988
|
-
if (!unowned(pid)) continue;
|
|
152094
|
+
for (const [pid, cwd] of candidatesOf(rows3, cwdOf, roots, selfPid)) {
|
|
151989
152095
|
const row = byPid.get(pid);
|
|
151990
|
-
if (row) out.push({ pid, command: row.command, cwd });
|
|
152096
|
+
if (row && ourStart(pid)) out.push({ pid, command: row.command, cwd });
|
|
151991
152097
|
}
|
|
151992
152098
|
return out.sort((a, b2) => a.pid - b2.pid);
|
|
151993
152099
|
}
|
|
@@ -152021,29 +152127,20 @@ async function scanProcesses(run2 = exec) {
|
|
|
152021
152127
|
const cwdOf = await cwdsOf(run2, rows3.filter((r) => r.pid > 1 && noTty(r.tty)).map((r) => r.pid));
|
|
152022
152128
|
return { rows: rows3, cwdOf };
|
|
152023
152129
|
}
|
|
152024
|
-
async function
|
|
152025
|
-
let pid = 0;
|
|
152130
|
+
async function ownerMarks(pids) {
|
|
152026
152131
|
try {
|
|
152027
|
-
|
|
152028
|
-
pid = Number((await run2("/bin/sh", ["-c", "sleep 60 </dev/null >/dev/null 2>&1 & echo $!"], opts)).stdout);
|
|
152029
|
-
const ppid = Number((await run2("ps", ["-o", "ppid=", "-p", String(pid)], opts)).stdout);
|
|
152030
|
-
if (!(ppid > 1)) return null;
|
|
152031
|
-
const command = (await run2("ps", ["-o", "command=", "-p", String(ppid)], opts)).stdout.trim();
|
|
152032
|
-
return command === "/init" ? ppid : null;
|
|
152132
|
+
return await environmentValues(OWNER_MARK, pids);
|
|
152033
152133
|
} catch (e) {
|
|
152034
|
-
unread2("
|
|
152035
|
-
return
|
|
152036
|
-
} finally {
|
|
152037
|
-
if (pid > 1) try {
|
|
152038
|
-
end(pid);
|
|
152039
|
-
} catch {
|
|
152040
|
-
}
|
|
152134
|
+
unread2("the processes' owner marks", e);
|
|
152135
|
+
return /* @__PURE__ */ new Map();
|
|
152041
152136
|
}
|
|
152042
152137
|
}
|
|
152043
|
-
async function findStrays(roots, selfPid = process.pid) {
|
|
152044
|
-
if (!hasPs() || roots.length === 0) return [];
|
|
152045
|
-
const
|
|
152046
|
-
|
|
152138
|
+
async function findStrays(roots, selfPid = process.pid, mark = process.env[OWNER_MARK]) {
|
|
152139
|
+
if (!hasPs() || roots.length === 0 || !mark) return [];
|
|
152140
|
+
const { rows: rows3, cwdOf } = await scanProcesses();
|
|
152141
|
+
const resolved = resolveRoots(roots);
|
|
152142
|
+
const marks = await ownerMarks(markAsked(rows3, cwdOf, resolved, selfPid));
|
|
152143
|
+
return pickStrays(rows3, cwdOf, resolved, selfPid, marks, mark);
|
|
152047
152144
|
}
|
|
152048
152145
|
function resolveRoots(roots) {
|
|
152049
152146
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -152148,12 +152245,12 @@ function refuse7(message) {
|
|
|
152148
152245
|
throw rpcError(message);
|
|
152149
152246
|
}
|
|
152150
152247
|
async function askBuilder(deps, req) {
|
|
152151
|
-
const app2 = deps.apps.list().find((a) => a
|
|
152248
|
+
const app2 = deps.apps.list().find((a) => sameApp(a, req.ref));
|
|
152152
152249
|
const builder = deps.builderOf(req.ref);
|
|
152153
152250
|
let view2;
|
|
152154
152251
|
if (req.instanceId) {
|
|
152155
152252
|
const inst = deps.views?.describe(req.instanceId) ?? null;
|
|
152156
|
-
view2 = inst && inst.app
|
|
152253
|
+
view2 = inst && sameApp(inst.app, req.ref) ? inst : null;
|
|
152157
152254
|
}
|
|
152158
152255
|
const built = builderRequestOf({
|
|
152159
152256
|
text: req.text,
|
|
@@ -152169,7 +152266,7 @@ async function askBuilder(deps, req) {
|
|
|
152169
152266
|
return { sessionId: built.builder.id };
|
|
152170
152267
|
}
|
|
152171
152268
|
async function sendErrorToBuilder(deps, ref, at2) {
|
|
152172
|
-
const info = deps.apps.list().find((a) => a
|
|
152269
|
+
const info = deps.apps.list().find((a) => sameApp(a, ref));
|
|
152173
152270
|
if (!info) refuse7("This app no longer exists");
|
|
152174
152271
|
const builder = deps.builderOf(ref);
|
|
152175
152272
|
if (!builder) refuse7("This app has no builder session yet. Start one, then send the error");
|
|
@@ -152529,7 +152626,7 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
152529
152626
|
}
|
|
152530
152627
|
const ref = owner?.ref ?? views2?.describe(instanceId)?.app ?? null;
|
|
152531
152628
|
if (!ref) throw rpcError("This app view is not open");
|
|
152532
|
-
const name = externalApps2?.list().find((a) => a
|
|
152629
|
+
const name = externalApps2?.list().find((a) => sameApp(a, ref))?.name;
|
|
152533
152630
|
await mgr2.inputs.sendFromApp(sessionId, text3, { appId: ref.appId, projectId: ref.projectId, name: name ?? ref.appId }, owner ? "inline" : "pinned");
|
|
152534
152631
|
return { ok: true };
|
|
152535
152632
|
},
|
|
@@ -152586,7 +152683,7 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
152586
152683
|
const apps = requireExternalApps();
|
|
152587
152684
|
if (apps.keepsVersions({ appId, projectId })) return { kind: "snapshots", snapshots: apps.snapshots({ appId, projectId }).map(({ stamp: _stamp, depth: _depth, ...s }) => s) };
|
|
152588
152685
|
const project2 = (await mgr2.projectRegistry.listProjects()).find((x) => x.id === projectId);
|
|
152589
|
-
const app2 = apps.list().find((a) => a
|
|
152686
|
+
const app2 = apps.list().find((a) => sameApp(a, { appId, projectId }));
|
|
152590
152687
|
if (!project2 || !app2) throw rpcError(noSuchAppText({ projectId, appId }));
|
|
152591
152688
|
const { repo, commits } = await gitLogPath(project2.path, relative9(project2.path, app2.dir), 20);
|
|
152592
152689
|
return { kind: "git", repo, commits };
|
|
@@ -152656,7 +152753,7 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
152656
152753
|
} catch {
|
|
152657
152754
|
}
|
|
152658
152755
|
const name = mail?.projectName(projectId);
|
|
152659
|
-
const
|
|
152756
|
+
const gone2 = () => {
|
|
152660
152757
|
try {
|
|
152661
152758
|
mgr2.cwdOfProject(projectId);
|
|
152662
152759
|
return false;
|
|
@@ -152667,7 +152764,7 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
152667
152764
|
try {
|
|
152668
152765
|
await mgr2.deleteProject(projectId);
|
|
152669
152766
|
} finally {
|
|
152670
|
-
if (name !== void 0 &&
|
|
152767
|
+
if (name !== void 0 && gone2()) mail?.projectDeleted(projectId, name);
|
|
152671
152768
|
}
|
|
152672
152769
|
if (cwd !== null) {
|
|
152673
152770
|
terminals2?.closeCwd(cwd);
|
|
@@ -154595,9 +154692,10 @@ async function namedTargets(rpc, params) {
|
|
|
154595
154692
|
machineNamed ||= !!r.machine;
|
|
154596
154693
|
}
|
|
154597
154694
|
if (typeof p.appId === "string") {
|
|
154695
|
+
const appId = p.appId;
|
|
154598
154696
|
const machine = typeof p.machine === "string" ? p.machine : void 0;
|
|
154599
154697
|
const projectId = typeof p.projectId === "string" ? p.projectId : null;
|
|
154600
|
-
const a = (await list2("apps.list", AppRow, machine ? { machine } : {})).find((x) => x
|
|
154698
|
+
const a = (await list2("apps.list", AppRow, machine ? { machine } : {})).find((x) => sameApp(x, { appId, projectId, machine }));
|
|
154601
154699
|
if (!a) return { ok: false, why: "it names an app this computer does not have" };
|
|
154602
154700
|
parts.push(`the app ${quoted3(a.name ?? a.appId)} [${a.appId}]${on2(a.machine)}`);
|
|
154603
154701
|
machineNamed ||= !!a.machine;
|
|
@@ -155703,7 +155801,7 @@ function updateNodeSentence(o) {
|
|
|
155703
155801
|
}
|
|
155704
155802
|
|
|
155705
155803
|
// packages/agent-host/src/links/tunnel.ts
|
|
155706
|
-
import { createHash as
|
|
155804
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
155707
155805
|
import { createConnection as createConnection2, createServer as createServer3 } from "node:net";
|
|
155708
155806
|
import { hostname as hostname3 } from "node:os";
|
|
155709
155807
|
|
|
@@ -155724,9 +155822,6 @@ async function endChild(child, graceMs = RUN_STOP_GRACE_MS) {
|
|
|
155724
155822
|
await realOs().processes.stop(child, graceMs, { sweep: false }).catch(() => {
|
|
155725
155823
|
});
|
|
155726
155824
|
}
|
|
155727
|
-
function seconds(ms3) {
|
|
155728
|
-
return ms3 >= 1e3 ? `${Math.round(ms3 / 1e3)} seconds` : `${ms3} ms`;
|
|
155729
|
-
}
|
|
155730
155825
|
function runSsh(opts) {
|
|
155731
155826
|
const stdoutLimit = opts.stdoutLimit ?? SSH_STDOUT_LIMIT;
|
|
155732
155827
|
return new Promise((resolve21, reject) => {
|
|
@@ -155753,7 +155848,7 @@ function runSsh(opts) {
|
|
|
155753
155848
|
if (kind !== "spawn") void endChild(child);
|
|
155754
155849
|
reject(new SshRunFailure(kind, message, stage));
|
|
155755
155850
|
};
|
|
155756
|
-
const deadline = setTimeout(() => fail4("timeout", `ssh to ${opts.label} did not finish within ${
|
|
155851
|
+
const deadline = setTimeout(() => fail4("timeout", `ssh to ${opts.label} did not finish within ${durationText(opts.timeoutMs)}`), opts.timeoutMs);
|
|
155757
155852
|
const expected = opts.expect ?? [];
|
|
155758
155853
|
let next = 0;
|
|
155759
155854
|
let expectDeadline;
|
|
@@ -155980,7 +156075,7 @@ function notInstalled(where2, spec) {
|
|
|
155980
156075
|
}
|
|
155981
156076
|
var NOT_FOUND2 = "CENTRALU-NOT-FOUND";
|
|
155982
156077
|
var STALE_LAUNCHER = "; if Node was upgraded there, run `centralu serve` once from an interactive shell on that machine";
|
|
155983
|
-
function
|
|
156078
|
+
function noAnswer2(err, r, remote) {
|
|
155984
156079
|
const why2 = lastLine(r.stderr);
|
|
155985
156080
|
if (r.code === 127 && !remote.command?.trim()) return `The Centralu there did not run: ${why2 || "exit 127"}${STALE_LAUNCHER}`;
|
|
155986
156081
|
return `${err.message}${why2 ? `: ${why2}` : r.code ? ` (exit ${r.code})` : ""}`;
|
|
@@ -155989,7 +156084,7 @@ function connectionCommand(spec, pair = null) {
|
|
|
155989
156084
|
return remoteCommand(spec, pair ? `serve --connection --pair ${pair}` : "serve --connection");
|
|
155990
156085
|
}
|
|
155991
156086
|
function hubKeyOf(hubSelfId2) {
|
|
155992
|
-
return /^hub-([0-9a-f]{8})$/.exec(hubSelfId2)?.[1] ??
|
|
156087
|
+
return /^hub-([0-9a-f]{8})$/.exec(hubSelfId2)?.[1] ?? createHash15("sha256").update(hubSelfId2).digest("hex").slice(0, 8);
|
|
155993
156088
|
}
|
|
155994
156089
|
function pairLabel(name, hubKey) {
|
|
155995
156090
|
const key = hubKey && /^[0-9a-f]{1,16}$/.test(hubKey) ? `-${hubKey}` : "";
|
|
@@ -156118,7 +156213,7 @@ var SshTunnel = class {
|
|
|
156118
156213
|
try {
|
|
156119
156214
|
answer = parseDetachLine(r.stdout);
|
|
156120
156215
|
} catch (err) {
|
|
156121
|
-
throw new Error(
|
|
156216
|
+
throw new Error(noAnswer2(err, r, remote));
|
|
156122
156217
|
}
|
|
156123
156218
|
if (answer.ok) {
|
|
156124
156219
|
this.linkBound = false;
|
|
@@ -156146,16 +156241,15 @@ var SshTunnel = class {
|
|
|
156146
156241
|
const markers = typeof command === "string" ? [] : command.expect ?? [];
|
|
156147
156242
|
const readyMs = this.opts.stdinReadyMs ?? SSH_STDIN_READY_MS;
|
|
156148
156243
|
const ackMs = this.opts.stdinAckMs ?? SSH_STDIN_ACK_MS;
|
|
156149
|
-
const sec = (ms3) => `${Math.round(ms3 / 1e3)} seconds`;
|
|
156150
156244
|
const expect = markers.map(
|
|
156151
156245
|
(marker, i) => i === 0 ? {
|
|
156152
156246
|
marker,
|
|
156153
156247
|
withinMs: readyMs,
|
|
156154
|
-
message: `${this.opts.target} did not start this step's PowerShell within ${
|
|
156248
|
+
message: `${this.opts.target} did not start this step's PowerShell within ${durationText(readyMs)} (ssh connecting, login and PowerShell starting)`
|
|
156155
156249
|
} : {
|
|
156156
156250
|
marker,
|
|
156157
156251
|
withinMs: ackMs,
|
|
156158
|
-
message: `PowerShell on ${this.opts.target} did not confirm within ${
|
|
156252
|
+
message: `PowerShell on ${this.opts.target} did not confirm within ${durationText(ackMs)} that it had read this step's input, so the step did not start`,
|
|
156159
156253
|
endedMessage: `PowerShell on ${this.opts.target} ended before it had read this step's input (its own time for that ran out, or the input was cut), so the step did not start`,
|
|
156160
156254
|
// The reader's own exits (cut input, its time); a dropped link (255) or a signal is not, and is not sent again
|
|
156161
156255
|
endedCodes: [STDIN_EXIT_CUT, STDIN_EXIT_LATE]
|
|
@@ -156248,7 +156342,7 @@ var SshTunnel = class {
|
|
|
156248
156342
|
} catch (err) {
|
|
156249
156343
|
const why2 = lastLine(r.stderr);
|
|
156250
156344
|
if (r.code !== 0 && /cannot be read by this user \((EACCES|EPERM)\)/.test(why2)) throw new Error(why2.replace(/^centralu serve: /, ""));
|
|
156251
|
-
throw new Error(
|
|
156345
|
+
throw new Error(noAnswer2(err, r, remote));
|
|
156252
156346
|
}
|
|
156253
156347
|
}
|
|
156254
156348
|
forward(localPort, remotePort, hosting = false) {
|
|
@@ -156956,7 +157050,7 @@ async function listSshHosts(opts = {}) {
|
|
|
156956
157050
|
}
|
|
156957
157051
|
|
|
156958
157052
|
// packages/agent-host/src/links/machine-ids.ts
|
|
156959
|
-
import { randomBytes as
|
|
157053
|
+
import { randomBytes as randomBytes13 } from "node:crypto";
|
|
156960
157054
|
function isMachineId(value) {
|
|
156961
157055
|
return MACHINE_ID_RE.test(value);
|
|
156962
157056
|
}
|
|
@@ -156993,10 +157087,10 @@ function decodeNumber(value) {
|
|
|
156993
157087
|
}
|
|
156994
157088
|
function newMachineId(name, taken) {
|
|
156995
157089
|
const slug = name.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^[^a-z]+/, "").replace(/-+$/, "").slice(0, 24);
|
|
156996
|
-
const base2 = slug && MACHINE_ID_RE.test(slug) ? slug : `m-${
|
|
157090
|
+
const base2 = slug && MACHINE_ID_RE.test(slug) ? slug : `m-${randomBytes13(3).toString("hex")}`;
|
|
156997
157091
|
if (!taken.has(base2)) return base2;
|
|
156998
157092
|
for (let i = 2; i < 1e3; i++) if (!taken.has(`${base2}-${i}`)) return `${base2}-${i}`;
|
|
156999
|
-
return `m-${
|
|
157093
|
+
return `m-${randomBytes13(4).toString("hex")}`;
|
|
157000
157094
|
}
|
|
157001
157095
|
|
|
157002
157096
|
// packages/agent-host/src/links/autostart.ts
|
|
@@ -157055,7 +157149,7 @@ async function askHubAuto(call2, allowed) {
|
|
|
157055
157149
|
}
|
|
157056
157150
|
|
|
157057
157151
|
// packages/agent-host/src/links/linked-machine-connection.ts
|
|
157058
|
-
import { randomBytes as
|
|
157152
|
+
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
157059
157153
|
|
|
157060
157154
|
// packages/agent-host/src/links/qualifier.ts
|
|
157061
157155
|
var CrossMachineError = class extends Error {
|
|
@@ -157354,7 +157448,6 @@ var Qualifier = class {
|
|
|
157354
157448
|
|
|
157355
157449
|
// packages/agent-host/src/links/remote-client.ts
|
|
157356
157450
|
var MAX_INCOMING_CALLS = 16;
|
|
157357
|
-
var DEFAULT_HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
157358
157451
|
var DEFAULT_CALL_TIMEOUT_MS = 2e5;
|
|
157359
157452
|
var linkError = (message, retryable) => rpcError(message, "internal", { retryable });
|
|
157360
157453
|
var RemoteClient = class {
|
|
@@ -157398,7 +157491,7 @@ var RemoteClient = class {
|
|
|
157398
157491
|
this.proving = null;
|
|
157399
157492
|
const ws2 = new this.WS(this.opts.url);
|
|
157400
157493
|
this.ws = ws2;
|
|
157401
|
-
this.handshakeTimer = setTimeout(() => this.lost(ws2, "no answer to hello"), this.opts.handshakeTimeoutMs ??
|
|
157494
|
+
this.handshakeTimer = setTimeout(() => this.lost(ws2, "no answer to hello"), this.opts.handshakeTimeoutMs ?? HANDSHAKE_TIMEOUT_MS);
|
|
157402
157495
|
ws2.on("open", () => {
|
|
157403
157496
|
if (this.ws !== ws2) return;
|
|
157404
157497
|
if (this.opts.proveHost) {
|
|
@@ -157492,14 +157585,14 @@ var RemoteClient = class {
|
|
|
157492
157585
|
get credential() {
|
|
157493
157586
|
return this.opts.credential;
|
|
157494
157587
|
}
|
|
157495
|
-
call(method, params) {
|
|
157588
|
+
call(method, params, timeoutMs) {
|
|
157496
157589
|
if (this.closed) return Promise.reject(linkError("The link is closed", false));
|
|
157497
157590
|
if (!this.ready || !this.ws) return Promise.reject(linkError("The machine is not reachable right now", true));
|
|
157498
157591
|
const ws2 = this.ws;
|
|
157499
157592
|
const id3 = String(this.nextId++);
|
|
157500
157593
|
const answer = this.pending.wait(
|
|
157501
157594
|
id3,
|
|
157502
|
-
this.opts.callTimeoutMs ?? DEFAULT_CALL_TIMEOUT_MS,
|
|
157595
|
+
this.opts.callTimeoutMs ?? timeoutMs ?? DEFAULT_CALL_TIMEOUT_MS,
|
|
157503
157596
|
() => rpcError(`The machine did not answer ${method} in time`, "internal", { retryable: true })
|
|
157504
157597
|
);
|
|
157505
157598
|
try {
|
|
@@ -158263,8 +158356,8 @@ var LinkedMachineConnection = class {
|
|
|
158263
158356
|
const connected = this.status === "connected";
|
|
158264
158357
|
const told = this.reportedUsed.filter((r) => (r.settled || !connected) && !this.revokedHere.has(r.credential.id)).map((r) => r.answered ? r.credential : withoutGone(r.credential));
|
|
158265
158358
|
if (!connected || !line || !all) {
|
|
158266
|
-
const
|
|
158267
|
-
return { otherCredentials:
|
|
158359
|
+
const gone2 = told.slice(0, OTHER_CREDENTIALS_SHOWN).map(({ check: _check2, own: _own, ...c }) => ({ ...c, hubsName: !!line?.pairedAs && c.label === line.pairedAs }));
|
|
158360
|
+
return { otherCredentials: gone2.length ? gone2 : null, otherCredentialsMore: 0, ownCredentialGone: this.ownCredentialTaken, credentialFileUnreadable };
|
|
158268
158361
|
}
|
|
158269
158362
|
const named3 = new Set(all.filter((c) => c.own !== true).map((c) => c.id));
|
|
158270
158363
|
const others = [...all, ...this.notPairedHere(line, all), ...told.filter((c) => !named3.has(c.id))].filter((c) => !this.isCurrent(c, line) && !this.revokedHere.has(c.id));
|
|
@@ -158407,7 +158500,7 @@ var LinkedMachineConnection = class {
|
|
|
158407
158500
|
const startedAt = Date.now();
|
|
158408
158501
|
const told = this.reportSeq;
|
|
158409
158502
|
try {
|
|
158410
|
-
const nonce =
|
|
158503
|
+
const nonce = randomBytes14(16).toString("base64url");
|
|
158411
158504
|
const r = asObj(await client.call("host.credentials", { nonce }));
|
|
158412
158505
|
if (this.client !== client) return;
|
|
158413
158506
|
const listed2 = this.ownOf(credentialsOf(r.credentials), nonce);
|
|
@@ -158512,14 +158605,14 @@ var LinkedMachineConnection = class {
|
|
|
158512
158605
|
return this.mailBack;
|
|
158513
158606
|
}
|
|
158514
158607
|
// ── RoutedMachine ───────────────────────────────────────────────────────────────────────
|
|
158515
|
-
call(method, params) {
|
|
158608
|
+
call(method, params, timeoutMs) {
|
|
158516
158609
|
if (!this.client) return Promise.reject(rpcError(`${this.name} is not reachable right now`, "internal", { retryable: true }));
|
|
158517
158610
|
if (method === "agents.respondApproval" && isObj(params) && params.decision === "always" && this.q.unreadCard(params.sessionId, params.requestId)) {
|
|
158518
158611
|
return Promise.reject(
|
|
158519
158612
|
rpcError(`This question from ${this.name} could not be read in full here, so it cannot be allowed always. Allow it once or deny it.`, "internal", { retryable: false })
|
|
158520
158613
|
);
|
|
158521
158614
|
}
|
|
158522
|
-
return this.client.call(method, params);
|
|
158615
|
+
return this.client.call(method, params, timeoutMs);
|
|
158523
158616
|
}
|
|
158524
158617
|
lastKnown(kind) {
|
|
158525
158618
|
return this.deps.mirror.read(this.id, kind);
|
|
@@ -158779,7 +158872,7 @@ var LinkedMachineConnection = class {
|
|
|
158779
158872
|
this.autoStarts = this.autoStarts.filter((t) => now - t < windowMs);
|
|
158780
158873
|
if (this.autoStarts.length >= max) this.restartsSpent = true;
|
|
158781
158874
|
if (!this.restartsSpent) return null;
|
|
158782
|
-
return `The Centralu hosts this computer started on ${this.name} did not stay up (${max} starts within ${
|
|
158875
|
+
return `The Centralu hosts this computer started on ${this.name} did not stay up (${max} starts within ${durationText(windowMs)}), so it starts no more by itself; serve.log and host.log in its data folder there say why` + (this.lastStartFailure ? ` (the last start: ${this.lastStartFailure})` : "") + ". Start tries again";
|
|
158783
158876
|
}
|
|
158784
158877
|
/** The machine's last switch (plan §10.5a), asked over its shell; null where there is no shell or none ran, undefined with no answer */
|
|
158785
158878
|
async switchThere() {
|
|
@@ -159479,13 +159572,10 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
159479
159572
|
const client = this.client;
|
|
159480
159573
|
if (!client?.connected) return "unreachable";
|
|
159481
159574
|
const ms3 = this.deps.hubAutoReadMs ?? HUB_AUTO_READ_MS;
|
|
159482
|
-
const timedOut2 = /* @__PURE__ */ Symbol("timed out");
|
|
159483
159575
|
try {
|
|
159484
159576
|
return await askHubAuto(async (method, params) => {
|
|
159485
159577
|
if (allowed !== void 0) return client.call(method, params);
|
|
159486
|
-
|
|
159487
|
-
if (answer === timedOut2) throw new Error(`no answer within ${ms3 % 1e3 === 0 ? `${ms3 / 1e3} s` : `${ms3} ms`}`);
|
|
159488
|
-
return answer;
|
|
159578
|
+
return withTimeout(client.call(method, params), ms3, (t) => `no answer within ${durationText(t)}`);
|
|
159489
159579
|
}, allowed);
|
|
159490
159580
|
} catch (err) {
|
|
159491
159581
|
if (!client.connected) return "unreachable";
|
|
@@ -159899,11 +159989,7 @@ function isToolLine(line) {
|
|
|
159899
159989
|
function fencedLine(line) {
|
|
159900
159990
|
return NOT_ONE_LINE.test(line) ? trustedJsonText(line) : line;
|
|
159901
159991
|
}
|
|
159902
|
-
var
|
|
159903
|
-
var TIMED_OUT = /* @__PURE__ */ Symbol("timed out");
|
|
159904
|
-
function notWithin(ms3) {
|
|
159905
|
-
return `did not answer within ${ms3 % 1e3 === 0 ? `${ms3 / 1e3} s` : `${ms3} ms`}`;
|
|
159906
|
-
}
|
|
159992
|
+
var notWithin = (ms3) => `did not answer within ${durationText(ms3)}`;
|
|
159907
159993
|
function cause(err) {
|
|
159908
159994
|
return oneLine4(err instanceof Error ? err.message : String(err), 300);
|
|
159909
159995
|
}
|
|
@@ -159948,11 +160034,7 @@ function linkedSessions(machines, route = notRouted, hubName2, options = {}) {
|
|
|
159948
160034
|
return Array.isArray(list2) ? list2 : [];
|
|
159949
160035
|
};
|
|
159950
160036
|
const rowOf = async (m, id3) => (await listOf(m, "sessions.list")).find((s) => isObj(s) && s.id === id3);
|
|
159951
|
-
const boundedAsk =
|
|
159952
|
-
const answer = await raceTimeout(m.call(method, params), lookupMs, TIMED_OUT);
|
|
159953
|
-
if (answer === TIMED_OUT) throw new Error(notWithin(lookupMs));
|
|
159954
|
-
return answer;
|
|
159955
|
-
};
|
|
160037
|
+
const boundedAsk = (m, method, params) => withTimeout(m.call(method, params), lookupMs, notWithin);
|
|
159956
160038
|
const projectOf = (m, raw) => {
|
|
159957
160039
|
const p = m.q.project(raw);
|
|
159958
160040
|
if (!isObj(p) || typeof p.id !== "string" || typeof p.path !== "string" || !SessionId.safeParse(p.id).success) return null;
|
|
@@ -160735,6 +160817,7 @@ var ROUTES = {
|
|
|
160735
160817
|
};
|
|
160736
160818
|
|
|
160737
160819
|
// packages/agent-host/src/links/router.ts
|
|
160820
|
+
var callOn = (m, method, params, ctx) => m.call(method, params, ctx === void 0 ? void 0 : callBudgetMs(method));
|
|
160738
160821
|
var MachineUnreachableError = class extends Error {
|
|
160739
160822
|
/**
|
|
160740
160823
|
* The sentence `linked-sessions.ts` gives the model (#1341, #1532): a machine the person disconnected says to connect it.
|
|
@@ -160811,7 +160894,7 @@ var Router = class {
|
|
|
160811
160894
|
}
|
|
160812
160895
|
if (!m.reachable && ctx === void 0) await m.reachForCall?.();
|
|
160813
160896
|
if (!m.reachable) throw new MachineUnreachableError(m, ctx?.window === true);
|
|
160814
|
-
return m
|
|
160897
|
+
return callOn(m, method, params, ctx);
|
|
160815
160898
|
}
|
|
160816
160899
|
async byKey(method, params, key, route, ctx) {
|
|
160817
160900
|
if (!isObj(params)) return this.opts.local(method, params, ctx);
|
|
@@ -160883,13 +160966,13 @@ var Router = class {
|
|
|
160883
160966
|
const tool = params.tool;
|
|
160884
160967
|
if (typeof tool !== "string" || params.limits === false) return void 0;
|
|
160885
160968
|
try {
|
|
160886
|
-
const [mine, theirs] = await Promise.all([this.opts.local("agents.account", { tool }), m
|
|
160969
|
+
const [mine, theirs] = await Promise.all([this.opts.local("agents.account", { tool }), callOn(m, "agents.account", { tool }, ctx)]);
|
|
160887
160970
|
const a = isObj(mine) ? mine.fingerprint : null;
|
|
160888
160971
|
const b2 = isObj(theirs) ? theirs.fingerprint : null;
|
|
160889
160972
|
if (typeof a !== "string" || a === "" || a !== b2) return void 0;
|
|
160890
160973
|
const own = await this.opts.local(method, { tool }, ctx);
|
|
160891
160974
|
if (!isObj(own) || own.supported !== true || !own.usage) return void 0;
|
|
160892
|
-
const there = await m
|
|
160975
|
+
const there = await callOn(m, method, { tool, limits: false }, ctx);
|
|
160893
160976
|
const cache2 = isObj(there) ? there.cache : void 0;
|
|
160894
160977
|
return { supported: true, usage: own.usage, sameAccountAsHub: true, ...cache2 ? { cache: cache2 } : {} };
|
|
160895
160978
|
} catch {
|
|
@@ -160907,31 +160990,31 @@ var Router = class {
|
|
|
160907
160990
|
const machines = [...this.opts.machines()];
|
|
160908
160991
|
switch (method) {
|
|
160909
160992
|
case "sessions.list":
|
|
160910
|
-
return this.mergeLists(machines, "sessions", params);
|
|
160993
|
+
return this.mergeLists(machines, "sessions", params, ctx);
|
|
160911
160994
|
case "projects.list":
|
|
160912
|
-
return this.mergeLists(machines, "projects", params);
|
|
160995
|
+
return this.mergeLists(machines, "projects", params, ctx);
|
|
160913
160996
|
case "projects.reorder":
|
|
160914
160997
|
return this.reorderProjects(machines, params, ctx);
|
|
160915
160998
|
case "approvals.deleteRule":
|
|
160916
160999
|
return this.deleteRule(machines, params, ctx);
|
|
160917
161000
|
default:
|
|
160918
|
-
return this.mergeSimple(method, machines, params);
|
|
161001
|
+
return this.mergeSimple(method, machines, params, ctx);
|
|
160919
161002
|
}
|
|
160920
161003
|
}
|
|
160921
|
-
async mergeLists(machines, kind, params) {
|
|
161004
|
+
async mergeLists(machines, kind, params, ctx) {
|
|
160922
161005
|
const method = kind === "sessions" ? "sessions.list" : "projects.list";
|
|
160923
161006
|
const [local, ...remote] = await Promise.all([
|
|
160924
161007
|
this.opts.local(method, params),
|
|
160925
|
-
...machines.map((m) => this.listOf(m, kind))
|
|
161008
|
+
...machines.map((m) => this.listOf(m, kind, ctx))
|
|
160926
161009
|
]);
|
|
160927
161010
|
const all = [...local, ...remote.flat()];
|
|
160928
161011
|
return kind === "projects" && machines.length > 0 ? this.inPersonsOrder(all) : all;
|
|
160929
161012
|
}
|
|
160930
161013
|
/** One machine's list in the hub's terms: asked when it can be, else its mirror, marked `unreachable` */
|
|
160931
|
-
async listOf(m, kind) {
|
|
161014
|
+
async listOf(m, kind, ctx) {
|
|
160932
161015
|
if (m.reachable) {
|
|
160933
161016
|
try {
|
|
160934
|
-
const list2 = await m
|
|
161017
|
+
const list2 = await callOn(m, kind === "sessions" ? "sessions.list" : "projects.list", {}, ctx);
|
|
160935
161018
|
if (Array.isArray(list2)) {
|
|
160936
161019
|
m.observe(kind, list2);
|
|
160937
161020
|
return this.present(m, kind, list2, false);
|
|
@@ -160990,7 +161073,7 @@ var Router = class {
|
|
|
160990
161073
|
this.opts.local("projects.reorder", { ...isObj(params) ? params : {}, orderedIds: local }),
|
|
160991
161074
|
...machines.map(async (m) => {
|
|
160992
161075
|
const ordered = perMachine.get(m);
|
|
160993
|
-
if (!ordered) return this.listOf(m, "projects");
|
|
161076
|
+
if (!ordered) return this.listOf(m, "projects", ctx);
|
|
160994
161077
|
try {
|
|
160995
161078
|
return m.q.projects(await this.forward(m, "projects.reorder", { orderedIds: ordered }, ctx));
|
|
160996
161079
|
} catch {
|
|
@@ -161014,13 +161097,13 @@ var Router = class {
|
|
|
161014
161097
|
return this.forward(m, "approvals.deleteRule", { id: folded.n }, ctx);
|
|
161015
161098
|
}
|
|
161016
161099
|
/** The other merges: every reachable machine, each answer in the hub's terms, combined by kind */
|
|
161017
|
-
async mergeSimple(method, machines, params) {
|
|
161100
|
+
async mergeSimple(method, machines, params, ctx) {
|
|
161018
161101
|
const local = await this.opts.local(method, params);
|
|
161019
161102
|
const missed = machines.filter((m) => !m.reachable);
|
|
161020
161103
|
const answers2 = await Promise.all(
|
|
161021
161104
|
machines.filter((m) => m.reachable).map(async (m) => {
|
|
161022
161105
|
try {
|
|
161023
|
-
return { m, r: await m
|
|
161106
|
+
return { m, r: await callOn(m, method, params, ctx) };
|
|
161024
161107
|
} catch {
|
|
161025
161108
|
missed.push(m);
|
|
161026
161109
|
return null;
|
|
@@ -161128,7 +161211,7 @@ function linkedViews(call2) {
|
|
|
161128
161211
|
}
|
|
161129
161212
|
|
|
161130
161213
|
// packages/agent-host/src/links/stored.ts
|
|
161131
|
-
import { randomBytes as
|
|
161214
|
+
import { randomBytes as randomBytes15 } from "node:crypto";
|
|
161132
161215
|
function storeRegistry(store2) {
|
|
161133
161216
|
return {
|
|
161134
161217
|
list: () => store2.machines.listLinkedMachines(),
|
|
@@ -161145,7 +161228,7 @@ var HUB_SELF_ID = /^hub-[0-9a-f]{8}$/;
|
|
|
161145
161228
|
function hubSelfId(store2) {
|
|
161146
161229
|
const kept = store2.settings.appSetting(HUB_SELF_KEY);
|
|
161147
161230
|
if (kept && HUB_SELF_ID.test(kept)) return kept;
|
|
161148
|
-
const made = `hub-${
|
|
161231
|
+
const made = `hub-${randomBytes15(4).toString("hex")}`;
|
|
161149
161232
|
store2.settings.updateAppSetting(HUB_SELF_KEY, (current) => current !== null && HUB_SELF_ID.test(current) ? current : made);
|
|
161150
161233
|
return store2.settings.appSetting(HUB_SELF_KEY) ?? made;
|
|
161151
161234
|
}
|
|
@@ -161181,7 +161264,6 @@ function storeProjectOrder(store2) {
|
|
|
161181
161264
|
}
|
|
161182
161265
|
|
|
161183
161266
|
// packages/agent-host/src/links/linked-hubs.ts
|
|
161184
|
-
var LOOKUP_MS2 = 4e3;
|
|
161185
161267
|
var MAIL_MS = 3e4;
|
|
161186
161268
|
var older2 = (err) => /Unknown method/i.test(errorMessage(err));
|
|
161187
161269
|
var LinkedHubs = class {
|
|
@@ -161240,7 +161322,7 @@ var LinkedHubs = class {
|
|
|
161240
161322
|
if (h.client === null) why2 = NOT_REACHABLE;
|
|
161241
161323
|
else {
|
|
161242
161324
|
try {
|
|
161243
|
-
const raw = await this.deps.call(h.client, "hub.projects", {}, { timeoutMs: this.deps.lookupMs ??
|
|
161325
|
+
const raw = await this.deps.call(h.client, "hub.projects", {}, { timeoutMs: this.deps.lookupMs ?? LOOKUP_MS });
|
|
161244
161326
|
const parsed = HubMethods["hub.projects"].result.safeParse(raw);
|
|
161245
161327
|
if (parsed.success) h.projects = parsed.data.projects;
|
|
161246
161328
|
else why2 = "its answer could not be read";
|
|
@@ -161645,7 +161727,7 @@ var handedToken = launch.tokenOnStdin ? await readHandedToken(process.stdin).cat
|
|
|
161645
161727
|
console.error(`[agent-host] the launcher did not hand over the token: ${e.message}`);
|
|
161646
161728
|
process.exit(1);
|
|
161647
161729
|
}) : launch.token;
|
|
161648
|
-
var BUILD = true ? "
|
|
161730
|
+
var BUILD = true ? "6299d64" : "dev";
|
|
161649
161731
|
var { values } = parseArgs({
|
|
161650
161732
|
options: {
|
|
161651
161733
|
port: { type: "string", default: "5175" },
|
|
@@ -161666,9 +161748,9 @@ if (values.standby) {
|
|
|
161666
161748
|
process.exit(1);
|
|
161667
161749
|
}
|
|
161668
161750
|
var control = launch.underKeeper || launch.startedBy === "app" ? new ControlChannel(process.stdin) : null;
|
|
161669
|
-
var token = values.token || handedToken ||
|
|
161751
|
+
var token = values.token || handedToken || randomBytes16(16).toString("hex");
|
|
161670
161752
|
var keeperToken = launch.underKeeper && !values.token && handedToken ? token : null;
|
|
161671
|
-
var httpSecret = keeperToken ? deriveHttpSecret(keeperToken) :
|
|
161753
|
+
var httpSecret = keeperToken ? deriveHttpSecret(keeperToken) : randomBytes16(32).toString("base64url");
|
|
161672
161754
|
start2.at("data folder");
|
|
161673
161755
|
var movedNote = null;
|
|
161674
161756
|
function defaultDbPath() {
|
|
@@ -161679,6 +161761,7 @@ function defaultDbPath() {
|
|
|
161679
161761
|
return join58(dir, "store.db");
|
|
161680
161762
|
}
|
|
161681
161763
|
var dbPath = values.memory ? ":memory:" : values.db ?? defaultDbPath();
|
|
161764
|
+
markOwnChildren(dbPath);
|
|
161682
161765
|
var privateFolder = privateDataFolderFor(dbPath);
|
|
161683
161766
|
var madePrivate = privateFolder ? keepDataFolderPrivate(privateFolder) : [];
|
|
161684
161767
|
start2.at("log");
|