@centralu/host-win32-x64 0.1.0-beta.59 → 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.
- package/host/bundle-info.json +2 -2
- package/host/centralu-package.json +5 -5
- package/host/main.mjs +755 -691
- package/package.json +1 -1
package/host/main.mjs
CHANGED
|
@@ -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"],
|
|
@@ -63457,6 +63462,22 @@ var THEME_PRESETS = [
|
|
|
63457
63462
|
{ id: "hc-light", name: "High contrast light", base: "light" },
|
|
63458
63463
|
{ id: "graphite", name: "Graphite", base: "dark" }
|
|
63459
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
|
+
}
|
|
63460
63481
|
var ThemeFileContent = external_exports.object({
|
|
63461
63482
|
name: external_exports.string().min(1).max(80),
|
|
63462
63483
|
base: external_exports.enum(["dark", "light"]),
|
|
@@ -63475,6 +63496,13 @@ var ThemeFileEntry = external_exports.object({
|
|
|
63475
63496
|
/** True when the file could not be read as a theme at all (not JSON, not an object) */
|
|
63476
63497
|
broken: external_exports.boolean()
|
|
63477
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
|
+
}
|
|
63478
63506
|
var THEME_SCHEMA_FILE = "theme.schema.json";
|
|
63479
63507
|
var THEME_SCHEMA_REF = `./${THEME_SCHEMA_FILE}`;
|
|
63480
63508
|
function parseThemeFile(id3, path2, text3) {
|
|
@@ -63560,7 +63588,7 @@ function themeFileJsonSchema() {
|
|
|
63560
63588
|
properties: Object.fromEntries([
|
|
63561
63589
|
...THEME_TOKENS.map((t) => [
|
|
63562
63590
|
t.key,
|
|
63563
|
-
{ 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}".` : ""}` }
|
|
63564
63592
|
]),
|
|
63565
63593
|
...RETIRED_THEME_TOKENS.map((key) => [
|
|
63566
63594
|
key,
|
|
@@ -63949,6 +63977,7 @@ function parseClientFrame(raw) {
|
|
|
63949
63977
|
// packages/protocol/src/app-id.ts
|
|
63950
63978
|
var RESERVED_NAME_PREFIX = "centralu";
|
|
63951
63979
|
var APP_SERVER_PREFIX = "app-";
|
|
63980
|
+
var appServerName = (appId) => `${APP_SERVER_PREFIX}${appId}`;
|
|
63952
63981
|
var RESERVED_APP_IDS = ["control"];
|
|
63953
63982
|
var APP_ID_MAX_LENGTH = 32;
|
|
63954
63983
|
var NAME_SHAPE = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
@@ -63964,11 +63993,25 @@ function newAppIdProblem(id3, reservedIds = RESERVED_APP_IDS) {
|
|
|
63964
63993
|
if (reservedIds.includes(id3)) return "builtin";
|
|
63965
63994
|
return null;
|
|
63966
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
|
+
}
|
|
63967
64005
|
|
|
63968
64006
|
// packages/protocol/src/app-key.ts
|
|
63969
64007
|
var USER_APP_SCOPE = "_user";
|
|
63970
|
-
function appKeyOf(
|
|
63971
|
-
|
|
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);
|
|
63972
64015
|
}
|
|
63973
64016
|
function appLabel(ref) {
|
|
63974
64017
|
return `${ref.projectId === null ? "user" : ref.projectId.slice(0, 8)}/${ref.appId}`;
|
|
@@ -64062,6 +64105,55 @@ function centraluServer(server2) {
|
|
|
64062
64105
|
return null;
|
|
64063
64106
|
}
|
|
64064
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
|
+
|
|
64065
64157
|
// packages/protocol/src/handoff.ts
|
|
64066
64158
|
function handoffPrompt() {
|
|
64067
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.
|
|
@@ -66157,7 +66249,13 @@ async function copyTreeAsync(f, from, to, o, family2, P5) {
|
|
|
66157
66249
|
|
|
66158
66250
|
// packages/agent-host/src/timing.ts
|
|
66159
66251
|
function durationText(ms3) {
|
|
66160
|
-
|
|
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");
|
|
66161
66259
|
}
|
|
66162
66260
|
function sleepSync(ms3) {
|
|
66163
66261
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms3);
|
|
@@ -66188,7 +66286,7 @@ function withTimeout(p, ms3, label = "A call") {
|
|
|
66188
66286
|
return Promise.race([
|
|
66189
66287
|
p,
|
|
66190
66288
|
new Promise((_, reject) => {
|
|
66191
|
-
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);
|
|
66192
66290
|
})
|
|
66193
66291
|
]).finally(() => clearTimeout(timer));
|
|
66194
66292
|
}
|
|
@@ -68959,9 +69057,6 @@ var REMOTE_DOC_TTL_MS = 15e3;
|
|
|
68959
69057
|
var REMOTE_DOC_CAP = 64;
|
|
68960
69058
|
var SANDBOX_OPAQUE = "allow-scripts allow-forms";
|
|
68961
69059
|
var SANDBOX_APP = "allow-scripts allow-same-origin allow-forms";
|
|
68962
|
-
function sameApp(a, b2) {
|
|
68963
|
-
return a.appId === b2.appId && (a.projectId ?? null) === (b2.projectId ?? null);
|
|
68964
|
-
}
|
|
68965
69060
|
function fail(message) {
|
|
68966
69061
|
throw rpcError(message);
|
|
68967
69062
|
}
|
|
@@ -69455,11 +69550,11 @@ var PendingRequests = class {
|
|
|
69455
69550
|
* The answer to `id`, or a rejection once `timeoutMs` has passed without one: an `Error` with `timeout` as its text, or
|
|
69456
69551
|
* the error `timeout()` makes (one that carries a code or `retryable`)
|
|
69457
69552
|
*/
|
|
69458
|
-
wait(id3, timeoutMs,
|
|
69553
|
+
wait(id3, timeoutMs, timeout) {
|
|
69459
69554
|
const key = String(id3);
|
|
69460
69555
|
return new Promise((resolve21, reject) => {
|
|
69461
69556
|
const timer = setTimeout(() => {
|
|
69462
|
-
if (this.waiting.delete(key)) reject(typeof
|
|
69557
|
+
if (this.waiting.delete(key)) reject(typeof timeout === "string" ? new Error(timeout) : timeout());
|
|
69463
69558
|
}, timeoutMs);
|
|
69464
69559
|
timer.unref?.();
|
|
69465
69560
|
this.waiting.set(key, { resolve: resolve21, reject, timer });
|
|
@@ -69691,9 +69786,9 @@ async function stopGitChildren(graceMs = GIT_STOP_GRACE_MS) {
|
|
|
69691
69786
|
async function runGit(cwd, args, opts = {}) {
|
|
69692
69787
|
const argv = await gitArgv(cwd, args, opts.allowRepoPrograms, opts.filters);
|
|
69693
69788
|
if (opts.signal?.aborted) throw gitCancelled();
|
|
69694
|
-
const
|
|
69789
|
+
const timeout = opts.timeout ?? DEFAULTS.timeout;
|
|
69695
69790
|
const r = await realOs().processes.run(programPath("git"), argv, {
|
|
69696
|
-
...runOptions(cwd, opts.env,
|
|
69791
|
+
...runOptions(cwd, opts.env, timeout, opts.signal),
|
|
69697
69792
|
input: opts.input ?? "",
|
|
69698
69793
|
maxBuffer: opts.maxBuffer ?? DEFAULTS.maxBuffer,
|
|
69699
69794
|
stdoutFile: opts.outputFile
|
|
@@ -69704,7 +69799,7 @@ async function runGit(cwd, args, opts = {}) {
|
|
|
69704
69799
|
if ((!ended2 || ended2 === "aborted") && code2 === 0) return out;
|
|
69705
69800
|
if (ended2 === "aborted") throw Object.assign(gitCancelled(), { signal, stdout: out, stderr: err });
|
|
69706
69801
|
if (ended2 === "timeout" || ended2 === "overflow") {
|
|
69707
|
-
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";
|
|
69708
69803
|
throw Object.assign(new Error(message), { code: code2, signal, stdout: "", stderr: "", ...ended2 === "timeout" ? { timedOut: true, killed: true } : {} });
|
|
69709
69804
|
}
|
|
69710
69805
|
throw Object.assign(new Error(err || `Git exited with ${code2 ?? signal}`), { code: code2, signal, stdout: out, stderr: err });
|
|
@@ -82117,11 +82212,11 @@ var Protocol = class {
|
|
|
82117
82212
|
if (notification.params.requestId === void 0) return;
|
|
82118
82213
|
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
82119
82214
|
}
|
|
82120
|
-
_setupTimeout(messageId,
|
|
82215
|
+
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
82121
82216
|
this._timeoutInfo.set(messageId, {
|
|
82122
|
-
timeoutId: setTimeout(onTimeout,
|
|
82217
|
+
timeoutId: setTimeout(onTimeout, timeout),
|
|
82123
82218
|
startTime: Date.now(),
|
|
82124
|
-
timeout
|
|
82219
|
+
timeout,
|
|
82125
82220
|
maxTotalTimeout,
|
|
82126
82221
|
resetTimeoutOnProgress,
|
|
82127
82222
|
onTimeout
|
|
@@ -82563,9 +82658,9 @@ var Protocol = class {
|
|
|
82563
82658
|
});
|
|
82564
82659
|
onAbort = () => cancel(options?.signal?.reason);
|
|
82565
82660
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
82566
|
-
const
|
|
82567
|
-
const timeoutHandler = () => cancel(new SdkError(SdkErrorCode.RequestTimeout, "Request timed out", { timeout
|
|
82568
|
-
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);
|
|
82569
82664
|
this._transport.send(outbound, {
|
|
82570
82665
|
relatedRequestId,
|
|
82571
82666
|
resumptionToken,
|
|
@@ -85167,7 +85262,7 @@ function announcingLedger(inner, announce) {
|
|
|
85167
85262
|
inner.begin(row);
|
|
85168
85263
|
const apps = [{ projectId: row.projectId, appId: row.appId }];
|
|
85169
85264
|
for (const up2 of row.parentRunId ? open6.get(row.parentRunId) ?? [] : []) {
|
|
85170
|
-
if (!apps.some((a) => a
|
|
85265
|
+
if (!apps.some((a) => sameApp(a, up2))) apps.push(up2);
|
|
85171
85266
|
}
|
|
85172
85267
|
open6.set(row.id, apps);
|
|
85173
85268
|
tell(apps);
|
|
@@ -85307,7 +85402,7 @@ function capabilityKey(c) {
|
|
|
85307
85402
|
case "agent":
|
|
85308
85403
|
return `agent:${c.tool}`;
|
|
85309
85404
|
case "app":
|
|
85310
|
-
return `app:${appKeyOf(c.target
|
|
85405
|
+
return `app:${appKeyOf(c.target)}`;
|
|
85311
85406
|
case "host":
|
|
85312
85407
|
return `host:${c.name}`;
|
|
85313
85408
|
}
|
|
@@ -85359,13 +85454,6 @@ var RunAgentArgs = external_exports.object({
|
|
|
85359
85454
|
function deniedText(tool, appName, text3) {
|
|
85360
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.`;
|
|
85361
85456
|
}
|
|
85362
|
-
var slotOf = (ref) => appKeyOf(ref.projectId, ref.appId);
|
|
85363
|
-
function humanDuration(ms3) {
|
|
85364
|
-
const s = Math.max(1, Math.round(ms3 / 1e3));
|
|
85365
|
-
if (s < 60) return `${s} second${s === 1 ? "" : "s"}`;
|
|
85366
|
-
const m = Math.round(s / 60);
|
|
85367
|
-
return `${m} minute${m === 1 ? "" : "s"}`;
|
|
85368
|
-
}
|
|
85369
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';
|
|
85370
85458
|
var say = (text3) => ({ status: "ok", result: { content: [{ type: "text", text: text3 }] } });
|
|
85371
85459
|
var refuse2 = (text3) => ({ status: "rejected", result: { content: [{ type: "text", text: text3 }], isError: true } });
|
|
@@ -85505,7 +85593,7 @@ var BrokerDesk = class {
|
|
|
85505
85593
|
const body = text3.trim();
|
|
85506
85594
|
if (!body) return refuse8("notify refused: the text is empty");
|
|
85507
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`);
|
|
85508
|
-
const key = appKeyOf(app2.ref
|
|
85596
|
+
const key = appKeyOf(app2.ref);
|
|
85509
85597
|
const now = Date.now();
|
|
85510
85598
|
const recent = (this.noticeTimes.get(key) ?? []).filter((t) => now - t < 6e4);
|
|
85511
85599
|
if (recent.length >= NOTICES_PER_MINUTE) {
|
|
@@ -85584,11 +85672,11 @@ var BrokerDesk = class {
|
|
|
85584
85672
|
}
|
|
85585
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);
|
|
85586
85674
|
if (denied) return denied;
|
|
85587
|
-
const key =
|
|
85675
|
+
const key = appKeyOf(app2.ref);
|
|
85588
85676
|
const since = this.agentsRunning.get(key);
|
|
85589
85677
|
if (since !== void 0) {
|
|
85590
85678
|
return refuse2(
|
|
85591
|
-
`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.`
|
|
85592
85680
|
);
|
|
85593
85681
|
}
|
|
85594
85682
|
const windowMs = this.timing().agentRateWindowMs;
|
|
@@ -85596,7 +85684,7 @@ var BrokerDesk = class {
|
|
|
85596
85684
|
const recent = (this.agentStarts.get(key) ?? []).filter((t) => t > now - windowMs);
|
|
85597
85685
|
if (recent.length >= AGENT_RUNS_PER_WINDOW) {
|
|
85598
85686
|
return refuse2(
|
|
85599
|
-
`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`
|
|
85600
85688
|
);
|
|
85601
85689
|
}
|
|
85602
85690
|
this.agentStarts.set(key, [...recent, now]);
|
|
@@ -85663,7 +85751,7 @@ var BrokerDesk = class {
|
|
|
85663
85751
|
}
|
|
85664
85752
|
const path2 = this.apps.chain(call2.parentRunId);
|
|
85665
85753
|
const shown3 = [...path2, { ref: target, tool }].map((p) => `${p.ref.appId}.${p.tool}`).join(" \u2192 ");
|
|
85666
|
-
if (path2.some((p) => p.ref
|
|
85754
|
+
if (path2.some((p) => sameApp(p.ref, target) && p.tool === tool)) {
|
|
85667
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`);
|
|
85668
85756
|
}
|
|
85669
85757
|
if (path2.length >= CHAIN_DEPTH_MAX) {
|
|
@@ -85706,7 +85794,7 @@ var BrokerDesk = class {
|
|
|
85706
85794
|
if (known && known.stamp === stamp2) return known.decision === "allow" ? null : denied();
|
|
85707
85795
|
const host = this.host;
|
|
85708
85796
|
if (!host) return refuse2("the broker is unavailable: there is no one to ask for permission");
|
|
85709
|
-
const slot = `${
|
|
85797
|
+
const slot = `${appKeyOf(app2.ref)} ${key}`;
|
|
85710
85798
|
let q2 = this.asking.get(slot);
|
|
85711
85799
|
if (!q2) {
|
|
85712
85800
|
const withdraw = new AbortController();
|
|
@@ -85757,7 +85845,7 @@ var BrokerDesk = class {
|
|
|
85757
85845
|
if (call2.signal.aborted) throw new Error("cancelled while waiting for the person");
|
|
85758
85846
|
if (answer === null) {
|
|
85759
85847
|
return refuse2(
|
|
85760
|
-
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`
|
|
85761
85849
|
);
|
|
85762
85850
|
}
|
|
85763
85851
|
this.book.put(app2.ref, { capability: key, text: text3, decision: answer, stamp: stamp2, decidedAt: Date.now() });
|
|
@@ -85852,12 +85940,12 @@ var AppCalls = class {
|
|
|
85852
85940
|
* through `call_app` is held as its caller is. A parent that already ended is `unknown`
|
|
85853
85941
|
*/
|
|
85854
85942
|
agentCallers(ref, seen = /* @__PURE__ */ new Set()) {
|
|
85855
|
-
const key =
|
|
85943
|
+
const key = appKeyOf(ref);
|
|
85856
85944
|
if (seen.has(key)) return [];
|
|
85857
85945
|
seen.add(key);
|
|
85858
85946
|
const out = [];
|
|
85859
85947
|
for (const run2 of this.openRuns.values()) {
|
|
85860
|
-
if (run2.entry.ref
|
|
85948
|
+
if (!sameApp(run2.entry.ref, ref)) continue;
|
|
85861
85949
|
const c = run2.caller;
|
|
85862
85950
|
if (c.kind === "session") out.push({ kind: "session", sessionId: c.sessionId });
|
|
85863
85951
|
else if (c.kind === "view") out.push(c.sessionId ? { kind: "session", sessionId: c.sessionId } : { kind: "person" });
|
|
@@ -85989,50 +86077,6 @@ function resultText(result) {
|
|
|
85989
86077
|
// packages/agent-host/src/apps/external/app-entry.ts
|
|
85990
86078
|
import { existsSync as existsSync5 } from "node:fs";
|
|
85991
86079
|
import { join as join6 } from "node:path";
|
|
85992
|
-
function resetLife(L2) {
|
|
85993
|
-
Object.assign(L2, { failures: 0, retryAt: 0, lastError: null, gaveUp: false, verdict: void 0 });
|
|
85994
|
-
}
|
|
85995
|
-
function keepsVersions(e) {
|
|
85996
|
-
return e.ref.projectId === null || e.found.root === true && !existsSync5(join6(e.dir, ".git"));
|
|
85997
|
-
}
|
|
85998
|
-
var invalidReason = (e) => `This app's manifest is invalid: ${e.error ?? "unknown error"}`;
|
|
85999
|
-
function newEntry(scope, found, reservedIds) {
|
|
86000
|
-
let { manifest, error: error51 } = found;
|
|
86001
|
-
if (manifest && reservedIds.includes(manifest.id)) {
|
|
86002
|
-
error51 = `"${manifest.id}" is a reserved app id \u2014 use another id`;
|
|
86003
|
-
manifest = null;
|
|
86004
|
-
}
|
|
86005
|
-
return {
|
|
86006
|
-
ref: { projectId: scope.projectId, appId: found.folder },
|
|
86007
|
-
scope,
|
|
86008
|
-
found,
|
|
86009
|
-
dir: found.dir,
|
|
86010
|
-
manifest,
|
|
86011
|
-
error: error51,
|
|
86012
|
-
warnings: found.warnings,
|
|
86013
|
-
life: {
|
|
86014
|
-
proc: null,
|
|
86015
|
-
starting: null,
|
|
86016
|
-
spawning: null,
|
|
86017
|
-
failures: 0,
|
|
86018
|
-
retryAt: 0,
|
|
86019
|
-
lastError: null,
|
|
86020
|
-
gaveUp: false,
|
|
86021
|
-
verdict: void 0,
|
|
86022
|
-
epoch: 0,
|
|
86023
|
-
inflight: 0,
|
|
86024
|
-
idleWaiters: [],
|
|
86025
|
-
stamp: null,
|
|
86026
|
-
loaded: null,
|
|
86027
|
-
idle: null,
|
|
86028
|
-
tools: null,
|
|
86029
|
-
toolWarnings: [],
|
|
86030
|
-
known: null,
|
|
86031
|
-
pipeId: 0,
|
|
86032
|
-
busy: null
|
|
86033
|
-
}
|
|
86034
|
-
};
|
|
86035
|
-
}
|
|
86036
86080
|
|
|
86037
86081
|
// packages/agent-host/src/apps/external/manifest.ts
|
|
86038
86082
|
var MANIFEST_FILE = "centralu.app.json";
|
|
@@ -86047,15 +86091,13 @@ var SECRET_NAME = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
|
86047
86091
|
var RESERVED_ENV_PREFIXES = ["CENTRALU_", "CC_"];
|
|
86048
86092
|
var HOST_CAPABILITY = /^[a-z][a-z0-9_.-]{0,63}$/;
|
|
86049
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
|
+
}
|
|
86050
86098
|
var appIdField = external_exports.string().superRefine((id3, ctx) => {
|
|
86051
|
-
const
|
|
86052
|
-
if (
|
|
86053
|
-
if (problem3 === "shape") {
|
|
86054
|
-
ctx.addIssue({
|
|
86055
|
-
code: "custom",
|
|
86056
|
-
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`
|
|
86057
|
-
});
|
|
86058
|
-
}
|
|
86099
|
+
const refusal2 = appIdRefusal(id3, []);
|
|
86100
|
+
if (refusal2) ctx.addIssue({ code: "custom", message: refusal2 });
|
|
86059
86101
|
});
|
|
86060
86102
|
var toolNameField = external_exports.string().superRefine((name, ctx) => {
|
|
86061
86103
|
const err = toolNameError(name);
|
|
@@ -86209,6 +86251,53 @@ function describeIssue(issue2) {
|
|
|
86209
86251
|
return `${path2}: ${issue2.message}`;
|
|
86210
86252
|
}
|
|
86211
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
|
+
|
|
86212
86301
|
// packages/agent-host/src/apps/external/visibility.ts
|
|
86213
86302
|
var DEFAULT_VISIBILITY = ["model", "app"];
|
|
86214
86303
|
function visibilityOf(tool) {
|
|
@@ -86424,9 +86513,8 @@ async function checkApp(host, ref) {
|
|
|
86424
86513
|
}
|
|
86425
86514
|
const busy = e.life.inflight;
|
|
86426
86515
|
if (!await host.lifecycle.drain(e, host.timing.checkDrainMs)) {
|
|
86427
|
-
const limit = host.timing.checkDrainMs >= 1e3 ? `${Math.round(host.timing.checkDrainMs / 1e3)} s` : `${host.timing.checkDrainMs} ms`;
|
|
86428
86516
|
notes.push(
|
|
86429
|
-
`${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`
|
|
86430
86518
|
);
|
|
86431
86519
|
break;
|
|
86432
86520
|
}
|
|
@@ -86643,7 +86731,7 @@ function subfoldersOf(root3, appRel) {
|
|
|
86643
86731
|
return [];
|
|
86644
86732
|
}
|
|
86645
86733
|
}
|
|
86646
|
-
function
|
|
86734
|
+
function readManifestFile(root3, manifestRel) {
|
|
86647
86735
|
try {
|
|
86648
86736
|
if (!assertExistingPathSync(root3, manifestRel).isFile()) return { error: `${MANIFEST_FILE} is not a file` };
|
|
86649
86737
|
return { text: readCapped(join9(root3, manifestRel)) };
|
|
@@ -86653,7 +86741,7 @@ function readManifestText(root3, manifestRel) {
|
|
|
86653
86741
|
}
|
|
86654
86742
|
}
|
|
86655
86743
|
function readApp(root3, folderRel, folder, dir) {
|
|
86656
|
-
const read2 =
|
|
86744
|
+
const read2 = readManifestFile(root3, `${folderRel}/${MANIFEST_FILE}`);
|
|
86657
86745
|
if ("missing" in read2) return invalid(folder, dir, `there is no ${MANIFEST_FILE}`);
|
|
86658
86746
|
if ("error" in read2) return invalid(folder, dir, read2.error);
|
|
86659
86747
|
const { text: text3 } = read2;
|
|
@@ -86674,7 +86762,7 @@ function readApp(root3, folderRel, folder, dir) {
|
|
|
86674
86762
|
}
|
|
86675
86763
|
var BROKEN_ROOT_APP_ID = "centralu-root";
|
|
86676
86764
|
function scanRootApp(root3, taken) {
|
|
86677
|
-
const read2 =
|
|
86765
|
+
const read2 = readManifestFile(root3, MANIFEST_FILE);
|
|
86678
86766
|
if ("missing" in read2) return null;
|
|
86679
86767
|
const rootApp = (id4, rest) => ({
|
|
86680
86768
|
folder: id4,
|
|
@@ -86855,16 +86943,10 @@ var AppUnavailableError = class extends Error {
|
|
|
86855
86943
|
};
|
|
86856
86944
|
|
|
86857
86945
|
// packages/agent-host/src/apps/external/app-folders.ts
|
|
86858
|
-
var USER_SCOPE = USER_APP_SCOPE;
|
|
86859
|
-
var APP_ID_PROBLEM = {
|
|
86860
|
-
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`,
|
|
86861
|
-
reserved: `ids starting with "${RESERVED_NAME_PREFIX}" belong to Centralu itself`,
|
|
86862
|
-
"server-prefix": `ids starting with "${APP_SERVER_PREFIX}" are how apps attach to sessions \u2014 pick another`,
|
|
86863
|
-
builtin: "that id is reserved \u2014 pick another"
|
|
86864
|
-
};
|
|
86865
86946
|
function installUserApp(host, spec) {
|
|
86866
86947
|
if (host.disposed()) throw new AppUnavailableError("The app runtime has shut down");
|
|
86867
|
-
|
|
86948
|
+
const refusal2 = appIdRefusal(spec.id, host.deps.reservedIds);
|
|
86949
|
+
if (refusal2) throw new AppUnavailableError(refusal2);
|
|
86868
86950
|
const text3 = JSON.stringify(
|
|
86869
86951
|
{
|
|
86870
86952
|
manifestVersion: MANIFEST_VERSION,
|
|
@@ -86916,7 +86998,7 @@ function createApp(host, spec) {
|
|
|
86916
86998
|
}
|
|
86917
86999
|
root3 = project2.path;
|
|
86918
87000
|
}
|
|
86919
|
-
const key = spec.projectId ??
|
|
87001
|
+
const key = spec.projectId ?? USER_APP_SCOPE;
|
|
86920
87002
|
if (host.hasScope(key)) host.rescan(key);
|
|
86921
87003
|
else host.refresh();
|
|
86922
87004
|
const ref = { projectId: spec.projectId, appId: spec.id };
|
|
@@ -86939,8 +87021,8 @@ function createApp(host, spec) {
|
|
|
86939
87021
|
return host.info(made);
|
|
86940
87022
|
}
|
|
86941
87023
|
function newAppText(host, spec) {
|
|
86942
|
-
const
|
|
86943
|
-
if (
|
|
87024
|
+
const refusal2 = appIdRefusal(spec.id, host.deps.reservedIds, { newName: true });
|
|
87025
|
+
if (refusal2) throw new AppUnavailableError(refusal2);
|
|
86944
87026
|
const name = oneLine(spec.name);
|
|
86945
87027
|
if (!name) throw new AppUnavailableError("The app needs a name");
|
|
86946
87028
|
return { name, description: oneLine(spec.description ?? "") || `${name} (a Centralu app)` };
|
|
@@ -86977,7 +87059,7 @@ async function removeUserApp(host, ref) {
|
|
|
86977
87059
|
}
|
|
86978
87060
|
host.rescanUser();
|
|
86979
87061
|
const e = host.require(ref);
|
|
86980
|
-
const key =
|
|
87062
|
+
const key = appKeyOf(ref);
|
|
86981
87063
|
host.removing.add(key);
|
|
86982
87064
|
try {
|
|
86983
87065
|
await host.lifecycle.halt(e, "app removed", { awaitTree: true });
|
|
@@ -90893,11 +90975,11 @@ var Protocol2 = class {
|
|
|
90893
90975
|
if (notification.params.requestId === void 0) return;
|
|
90894
90976
|
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
90895
90977
|
}
|
|
90896
|
-
_setupTimeout(messageId,
|
|
90978
|
+
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
90897
90979
|
this._timeoutInfo.set(messageId, {
|
|
90898
|
-
timeoutId: setTimeout(onTimeout,
|
|
90980
|
+
timeoutId: setTimeout(onTimeout, timeout),
|
|
90899
90981
|
startTime: Date.now(),
|
|
90900
|
-
timeout
|
|
90982
|
+
timeout,
|
|
90901
90983
|
maxTotalTimeout,
|
|
90902
90984
|
resetTimeoutOnProgress,
|
|
90903
90985
|
onTimeout
|
|
@@ -91339,9 +91421,9 @@ var Protocol2 = class {
|
|
|
91339
91421
|
});
|
|
91340
91422
|
onAbort = () => cancel(options?.signal?.reason);
|
|
91341
91423
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
91342
|
-
const
|
|
91343
|
-
const timeoutHandler = () => cancel(new SdkError2(SdkErrorCode2.RequestTimeout, "Request timed out", { timeout
|
|
91344
|
-
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);
|
|
91345
91427
|
this._transport.send(outbound, {
|
|
91346
91428
|
relatedRequestId,
|
|
91347
91429
|
resumptionToken,
|
|
@@ -102067,7 +102149,7 @@ var AppLifecycle = class {
|
|
|
102067
102149
|
return null;
|
|
102068
102150
|
}
|
|
102069
102151
|
viewsOf(e) {
|
|
102070
|
-
return this.viewHolds.get(
|
|
102152
|
+
return this.viewHolds.get(appKeyOf(e.ref)) ?? 0;
|
|
102071
102153
|
}
|
|
102072
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 */
|
|
102073
102155
|
async haltWhenDrained(e, why2) {
|
|
@@ -102083,7 +102165,7 @@ var AppLifecycle = class {
|
|
|
102083
102165
|
* never treated as an idle app — call the returned function to release the hold (close).
|
|
102084
102166
|
*/
|
|
102085
102167
|
retainView(e, ref) {
|
|
102086
|
-
const key =
|
|
102168
|
+
const key = appKeyOf(e.ref);
|
|
102087
102169
|
this.viewHolds.set(key, (this.viewHolds.get(key) ?? 0) + 1);
|
|
102088
102170
|
this.clearIdle(e);
|
|
102089
102171
|
let released = false;
|
|
@@ -102120,7 +102202,7 @@ var ChangeReflector = class {
|
|
|
102120
102202
|
this.host = host;
|
|
102121
102203
|
}
|
|
102122
102204
|
host;
|
|
102123
|
-
/** 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 */
|
|
102124
102206
|
turnEndTimers = /* @__PURE__ */ new Map();
|
|
102125
102207
|
quietTimers = /* @__PURE__ */ new Map();
|
|
102126
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 */
|
|
@@ -102140,7 +102222,7 @@ var ChangeReflector = class {
|
|
|
102140
102222
|
* note it would take it for an app nobody ever used and leave it stopped.
|
|
102141
102223
|
*/
|
|
102142
102224
|
manifestReplaced(ref, prev) {
|
|
102143
|
-
const key =
|
|
102225
|
+
const key = appKeyOf(ref);
|
|
102144
102226
|
if (prev.life.stamp !== null && this.turnEndTimers.has(key)) this.replacedBeforeTurnEnd.add(key);
|
|
102145
102227
|
}
|
|
102146
102228
|
/**
|
|
@@ -102158,7 +102240,7 @@ var ChangeReflector = class {
|
|
|
102158
102240
|
*/
|
|
102159
102241
|
builderTurnEnded(ref) {
|
|
102160
102242
|
if (this.host.disposed()) return;
|
|
102161
|
-
const key =
|
|
102243
|
+
const key = appKeyOf(ref);
|
|
102162
102244
|
clearTimeout(this.turnEndTimers.get(key));
|
|
102163
102245
|
const t = setTimeout(() => {
|
|
102164
102246
|
this.turnEndTimers.delete(key);
|
|
@@ -102188,7 +102270,7 @@ var ChangeReflector = class {
|
|
|
102188
102270
|
*/
|
|
102189
102271
|
folderChanged(e) {
|
|
102190
102272
|
if (this.host.builderBusy(e.ref)) return;
|
|
102191
|
-
const key =
|
|
102273
|
+
const key = appKeyOf(e.ref);
|
|
102192
102274
|
clearTimeout(this.quietTimers.get(key));
|
|
102193
102275
|
const ref = e.ref;
|
|
102194
102276
|
const t = setTimeout(() => {
|
|
@@ -102211,7 +102293,7 @@ var ChangeReflector = class {
|
|
|
102211
102293
|
* An open screen also receives "changed".
|
|
102212
102294
|
*/
|
|
102213
102295
|
reloadIfChanged(ref, opts) {
|
|
102214
|
-
const key =
|
|
102296
|
+
const key = appKeyOf(ref);
|
|
102215
102297
|
const running2 = this.reloading.get(key);
|
|
102216
102298
|
if (running2) return running2;
|
|
102217
102299
|
const p = (async () => {
|
|
@@ -102281,7 +102363,7 @@ ${b2.stderr.join("\n")}` : "stderr: (the app printed nothing)");
|
|
|
102281
102363
|
|
|
102282
102364
|
// packages/agent-host/src/apps/external/error-log.ts
|
|
102283
102365
|
var STDERR_SETTLE_MS = 150;
|
|
102284
|
-
var sentKey = (
|
|
102366
|
+
var sentKey = (appKey, b2) => `${appKey}
|
|
102285
102367
|
${b2.kind}
|
|
102286
102368
|
${b2.at}`;
|
|
102287
102369
|
var ErrorLog = class {
|
|
@@ -102289,7 +102371,7 @@ var ErrorLog = class {
|
|
|
102289
102371
|
this.changed = changed;
|
|
102290
102372
|
}
|
|
102291
102373
|
changed;
|
|
102292
|
-
/** 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 */
|
|
102293
102375
|
bundles = /* @__PURE__ */ new Map();
|
|
102294
102376
|
/**
|
|
102295
102377
|
* A bundle sent to the building session → the time it was sent (C-6). Kept separately instead of
|
|
@@ -102767,11 +102849,14 @@ var AppStartEnv = class {
|
|
|
102767
102849
|
dataDirOf(ref) {
|
|
102768
102850
|
return join16(this.deps.dataRoot, "app-data", this.scopeDir(ref), ref.appId);
|
|
102769
102851
|
}
|
|
102770
|
-
/** 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 */
|
|
102771
102858
|
scopeDir(ref) {
|
|
102772
|
-
|
|
102773
|
-
if (!/^[A-Za-z0-9-]+$/.test(ref.projectId)) throw new AppUnavailableError(`This project id cannot be used in a path: ${ref.projectId}`);
|
|
102774
|
-
return ref.projectId;
|
|
102859
|
+
return this.pathSafe(ref).projectId ?? USER_APP_SCOPE;
|
|
102775
102860
|
}
|
|
102776
102861
|
/**
|
|
102777
102862
|
* The function that masks every secret stored for this app (A-3, A-6) — whichever of a run's
|
|
@@ -102782,8 +102867,9 @@ var AppStartEnv = class {
|
|
|
102782
102867
|
masker(ref) {
|
|
102783
102868
|
return redactor(this.secrets.all(this.appKey(ref)));
|
|
102784
102869
|
}
|
|
102870
|
+
/** `appKeyOf`, after the check that its scope can be a path segment: carried app files are moved by this key (`carryAppFiles`) */
|
|
102785
102871
|
appKey(ref) {
|
|
102786
|
-
return
|
|
102872
|
+
return appKeyOf(this.pathSafe(ref));
|
|
102787
102873
|
}
|
|
102788
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 */
|
|
102789
102875
|
secretSlots(e) {
|
|
@@ -103158,29 +103244,6 @@ import { closeSync as closeSync4, constants as constants5, fstatSync as fstatSyn
|
|
|
103158
103244
|
import { isAbsolute as isAbsolute2, join as join18 } from "node:path";
|
|
103159
103245
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
103160
103246
|
|
|
103161
|
-
// packages/agent-host/src/apps/contract.ts
|
|
103162
|
-
var CENTRALU_MCP_NAME = RESERVED_NAME_PREFIX;
|
|
103163
|
-
var APP_MCP_PREFIX = APP_SERVER_PREFIX;
|
|
103164
|
-
var appMcpServerName = (appId) => `${APP_MCP_PREFIX}${appId}`;
|
|
103165
|
-
function mcpServerNameError(name) {
|
|
103166
|
-
switch (serverNameProblem(name)) {
|
|
103167
|
-
case "reserved":
|
|
103168
|
-
return `A name starting with "${CENTRALU_MCP_NAME}" is the name this app uses \u2014 suggest a different name`;
|
|
103169
|
-
case "shape":
|
|
103170
|
-
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)";
|
|
103171
|
-
case null:
|
|
103172
|
-
return null;
|
|
103173
|
-
}
|
|
103174
|
-
}
|
|
103175
|
-
function proposedMcpServerNameError(name) {
|
|
103176
|
-
const base2 = mcpServerNameError(name);
|
|
103177
|
-
if (base2) return base2;
|
|
103178
|
-
if (newAppIdProblem(name) === "server-prefix") {
|
|
103179
|
-
return `A name starting with "${APP_MCP_PREFIX}" is the name an external app attaches to a session \u2014 suggest a different name`;
|
|
103180
|
-
}
|
|
103181
|
-
return null;
|
|
103182
|
-
}
|
|
103183
|
-
|
|
103184
103247
|
// packages/agent-host/src/zip.ts
|
|
103185
103248
|
import { inflateRawSync } from "node:zlib";
|
|
103186
103249
|
var ZipError = class extends Error {
|
|
@@ -103595,22 +103658,14 @@ function zipParts(name, limits) {
|
|
|
103595
103658
|
return parts;
|
|
103596
103659
|
}
|
|
103597
103660
|
function readStagedManifest(dir, reservedIds) {
|
|
103598
|
-
const
|
|
103599
|
-
|
|
103600
|
-
|
|
103601
|
-
|
|
103602
|
-
if (!st2.isFile()) throw new Error("not a file");
|
|
103603
|
-
size2 = st2.size;
|
|
103604
|
-
} catch {
|
|
103605
|
-
throw new ImportRefused(`There is no ${MANIFEST_FILE} at the top, so this is not a Centralu app`);
|
|
103606
|
-
}
|
|
103607
|
-
if (size2 > MAX_MANIFEST_BYTES) throw new ImportRefused(`${MANIFEST_FILE} is larger than ${MAX_MANIFEST_BYTES} bytes`);
|
|
103608
|
-
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);
|
|
103609
103665
|
if (!parsed.ok) throw new ImportRefused(`${MANIFEST_FILE} is not valid: ${parsed.error}`);
|
|
103610
103666
|
const id3 = parsed.manifest.id;
|
|
103611
|
-
const
|
|
103612
|
-
if (
|
|
103613
|
-
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);
|
|
103614
103669
|
return { manifest: parsed.manifest, warnings: parsed.warnings };
|
|
103615
103670
|
}
|
|
103616
103671
|
function reviewOf(manifest, staged, meta3) {
|
|
@@ -104193,19 +104248,18 @@ var DEFAULT_TIMING = {
|
|
|
104193
104248
|
probeTimeoutMs: 1e4,
|
|
104194
104249
|
connectTimeoutMs: 3e4,
|
|
104195
104250
|
startExitWaitMs: 250,
|
|
104196
|
-
callTimeoutMs:
|
|
104251
|
+
callTimeoutMs: APP_CALL_TIMEOUT_MS,
|
|
104197
104252
|
logMaxBytes: 1024 * 1024,
|
|
104198
104253
|
checkDrainMs: 3e4,
|
|
104199
104254
|
reloadQuietMs: 2e3,
|
|
104200
104255
|
turnEndDebounceMs: 300,
|
|
104201
104256
|
brokerKeepaliveMs: BROKER_KEEPALIVE_MS,
|
|
104202
|
-
capabilityQuestionMs:
|
|
104257
|
+
capabilityQuestionMs: APP_CAPABILITY_QUESTION_MS,
|
|
104203
104258
|
resumeBusyMs: 3e3,
|
|
104204
104259
|
agentRateWindowMs: 6e4
|
|
104205
104260
|
};
|
|
104206
104261
|
|
|
104207
104262
|
// packages/agent-host/src/apps/external/runtime.ts
|
|
104208
|
-
var USER_SCOPE2 = USER_APP_SCOPE;
|
|
104209
104263
|
var ExternalApps = class {
|
|
104210
104264
|
constructor(deps) {
|
|
104211
104265
|
this.deps = deps;
|
|
@@ -104220,26 +104274,24 @@ var ExternalApps = class {
|
|
|
104220
104274
|
blocker: (e) => this.blocker(e),
|
|
104221
104275
|
spawnSpec: (e, pipeId) => this.startEnv.spawnSpec(e, pipeId),
|
|
104222
104276
|
snapshot: (e, stamp2) => {
|
|
104223
|
-
if (keepsVersions(e)) this.handover.snapshot(
|
|
104277
|
+
if (keepsVersions(e)) this.handover.snapshot(appKeyOf(e.ref), e.dir, "started", stamp2);
|
|
104224
104278
|
},
|
|
104225
104279
|
find: (ref) => this.find(ref),
|
|
104226
|
-
holdKey: (ref) => this.holdKey(ref),
|
|
104227
104280
|
label: (ref) => this.label(ref),
|
|
104228
|
-
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() })
|
|
104229
104282
|
});
|
|
104230
104283
|
this.reflector = new ChangeReflector({
|
|
104231
104284
|
timing: this.timing,
|
|
104232
104285
|
disposed: () => this.disposed,
|
|
104233
104286
|
lifecycle: this.lifecycle,
|
|
104234
104287
|
find: (ref) => this.find(ref),
|
|
104235
|
-
holdKey: (ref) => this.holdKey(ref),
|
|
104236
104288
|
label: (ref) => this.label(ref),
|
|
104237
104289
|
blocker: (e, opts) => this.blocker(e, opts),
|
|
104238
104290
|
appsChanged: () => this.appsChanged(),
|
|
104239
104291
|
emitChanged: (ref) => this.deps.emitChanged?.(ref),
|
|
104240
104292
|
builderBusy: (ref) => this.deps.builderBusy?.(ref) ?? false,
|
|
104241
104293
|
rescanNow: (ref) => {
|
|
104242
|
-
const scopeKey = ref.projectId ??
|
|
104294
|
+
const scopeKey = ref.projectId ?? USER_APP_SCOPE;
|
|
104243
104295
|
if (this.scopes.has(scopeKey) && !this.disposed) this.rescan(scopeKey, { now: ref.appId });
|
|
104244
104296
|
}
|
|
104245
104297
|
});
|
|
@@ -104308,9 +104360,9 @@ var ExternalApps = class {
|
|
|
104308
104360
|
/** `onAppsChanged` subscribers, and whether a notification is already scheduled for this tick */
|
|
104309
104361
|
appsListeners = createListeners((err) => console.error("[apps] apps-changed listener failed:", err));
|
|
104310
104362
|
appsNotePending = false;
|
|
104311
|
-
/** Recent error bundles per app
|
|
104363
|
+
/** Recent error bundles per app key (`appKeyOf`) and which were sent (C-6) — `error-log.ts` */
|
|
104312
104364
|
errorLog = new ErrorLog(() => this.appsChanged());
|
|
104313
|
-
/** Apps being removed (`removeUserApp`, by `
|
|
104365
|
+
/** Apps being removed (`removeUserApp`, by `appKeyOf`) — none of them starts again while its folder moves */
|
|
104314
104366
|
removing = /* @__PURE__ */ new Set();
|
|
104315
104367
|
/**
|
|
104316
104368
|
* The broker desk (D) — the one place that resolves what an app requests over fd 3. A call between
|
|
@@ -104340,7 +104392,7 @@ var ExternalApps = class {
|
|
|
104340
104392
|
*/
|
|
104341
104393
|
errors(ref) {
|
|
104342
104394
|
ref = this.resolve(ref);
|
|
104343
|
-
return this.errorLog.errors(
|
|
104395
|
+
return this.errorLog.errors(appKeyOf(ref));
|
|
104344
104396
|
}
|
|
104345
104397
|
/**
|
|
104346
104398
|
* Records that one bundle was sent to the building session (C-6) — **only once.** Returns the
|
|
@@ -104354,15 +104406,15 @@ var ExternalApps = class {
|
|
|
104354
104406
|
*/
|
|
104355
104407
|
markErrorSent(ref, at2) {
|
|
104356
104408
|
ref = this.resolve(ref);
|
|
104357
|
-
return this.errorLog.markSent(
|
|
104409
|
+
return this.errorLog.markSent(appKeyOf(ref), at2);
|
|
104358
104410
|
}
|
|
104359
104411
|
unmarkErrorSent(ref, at2) {
|
|
104360
104412
|
ref = this.resolve(ref);
|
|
104361
|
-
this.errorLog.unmarkSent(
|
|
104413
|
+
this.errorLog.unmarkSent(appKeyOf(ref), at2);
|
|
104362
104414
|
}
|
|
104363
104415
|
/** Records one error bundle for this app (`ErrorLog.record`) */
|
|
104364
104416
|
recordError(e, b2, proc = null) {
|
|
104365
|
-
this.errorLog.record(
|
|
104417
|
+
this.errorLog.record(appKeyOf(e.ref), `${e.manifest?.name ?? e.ref.appId} (${this.label(e.ref)})`, b2, proc);
|
|
104366
104418
|
}
|
|
104367
104419
|
/**
|
|
104368
104420
|
* Receives the part of the broker's body only the host's core can do (an agent session) (D). Called
|
|
@@ -104418,7 +104470,7 @@ var ExternalApps = class {
|
|
|
104418
104470
|
refresh() {
|
|
104419
104471
|
if (this.disposed) return;
|
|
104420
104472
|
const want = /* @__PURE__ */ new Map();
|
|
104421
|
-
want.set(
|
|
104473
|
+
want.set(USER_APP_SCOPE, { key: USER_APP_SCOPE, projectId: null, root: this.deps.dataRoot, trusted: true });
|
|
104422
104474
|
for (const p of this.deps.projects()) {
|
|
104423
104475
|
want.set(p.id, { key: p.id, projectId: p.id, root: p.path, trusted: p.trusted });
|
|
104424
104476
|
}
|
|
@@ -104449,7 +104501,7 @@ var ExternalApps = class {
|
|
|
104449
104501
|
if (this.disposed) return;
|
|
104450
104502
|
for (const rec of this.busyBook.list()) {
|
|
104451
104503
|
const ref = { projectId: rec.projectId, appId: rec.appId };
|
|
104452
|
-
this.busyBook.set(
|
|
104504
|
+
this.busyBook.set(appKeyOf(ref), null);
|
|
104453
104505
|
const e = this.find(ref);
|
|
104454
104506
|
if (!e || this.blocker(e) || !e.manifest?.uses.background) continue;
|
|
104455
104507
|
console.error(`[apps] ${this.label(ref)} was busy (${rec.reason}) when Centralu last stopped \u2014 starting it again`);
|
|
@@ -104585,7 +104637,7 @@ var ExternalApps = class {
|
|
|
104585
104637
|
ref = this.resolve(ref);
|
|
104586
104638
|
const e = this.require(ref);
|
|
104587
104639
|
await this.lifecycle.halt(e, "restart requested");
|
|
104588
|
-
this.busyBook.set(
|
|
104640
|
+
this.busyBook.set(appKeyOf(e.ref), null);
|
|
104589
104641
|
resetLife(e.life);
|
|
104590
104642
|
this.appsChanged();
|
|
104591
104643
|
}
|
|
@@ -104623,7 +104675,7 @@ var ExternalApps = class {
|
|
|
104623
104675
|
timing: this.timing,
|
|
104624
104676
|
lifecycle: this.lifecycle,
|
|
104625
104677
|
rescanNow: (r) => {
|
|
104626
|
-
const key = r.projectId ??
|
|
104678
|
+
const key = r.projectId ?? USER_APP_SCOPE;
|
|
104627
104679
|
if (this.scopes.has(key)) this.rescan(key, { now: r.appId });
|
|
104628
104680
|
else this.refresh();
|
|
104629
104681
|
},
|
|
@@ -104672,7 +104724,6 @@ var ExternalApps = class {
|
|
|
104672
104724
|
require: (ref) => this.require(ref),
|
|
104673
104725
|
info: (e) => this.info(e),
|
|
104674
104726
|
dataDirOf: (ref) => this.startEnv.dataDirOf(ref),
|
|
104675
|
-
holdKey: (ref) => this.holdKey(ref),
|
|
104676
104727
|
removing: this.removing,
|
|
104677
104728
|
lifecycle: this.lifecycle,
|
|
104678
104729
|
forgetImport: (appId) => this.handover.forget(appId)
|
|
@@ -104684,7 +104735,7 @@ var ExternalApps = class {
|
|
|
104684
104735
|
}
|
|
104685
104736
|
/** Rescans the scope an app lives in right now — scans everything if it has never scanned it before */
|
|
104686
104737
|
rescanScopeOf(ref, opts = {}) {
|
|
104687
|
-
const key = ref.projectId ??
|
|
104738
|
+
const key = ref.projectId ?? USER_APP_SCOPE;
|
|
104688
104739
|
if (this.scopes.has(key)) this.rescan(key, opts);
|
|
104689
104740
|
else this.refresh();
|
|
104690
104741
|
}
|
|
@@ -104822,7 +104873,7 @@ var ExternalApps = class {
|
|
|
104822
104873
|
ref = this.resolve(ref);
|
|
104823
104874
|
this.rescanScopeOf(ref);
|
|
104824
104875
|
const e = this.find(ref);
|
|
104825
|
-
if (e && keepsVersions(e)) this.handover.snapshot(
|
|
104876
|
+
if (e && keepsVersions(e)) this.handover.snapshot(appKeyOf(ref), e.dir, "imported");
|
|
104826
104877
|
}
|
|
104827
104878
|
cancelImport(token2) {
|
|
104828
104879
|
this.handover.cancel(token2);
|
|
@@ -104855,7 +104906,7 @@ var ExternalApps = class {
|
|
|
104855
104906
|
ref = this.resolve(ref);
|
|
104856
104907
|
this.rescanScopeOf(ref);
|
|
104857
104908
|
if (!this.keepsVersions(ref)) throw new AppUnavailableError("Project apps are versioned by git");
|
|
104858
|
-
return this.handover.versionsOf(
|
|
104909
|
+
return this.handover.versionsOf(appKeyOf(ref), this.require(ref).dir);
|
|
104859
104910
|
}
|
|
104860
104911
|
/**
|
|
104861
104912
|
* Restores one version — captures the current code as a version before writing it back, clears the
|
|
@@ -104870,7 +104921,7 @@ var ExternalApps = class {
|
|
|
104870
104921
|
this.rescanScopeOf(ref);
|
|
104871
104922
|
if (!this.keepsVersions(ref)) throw new AppUnavailableError("A project app's versions are its git history; restore it with git");
|
|
104872
104923
|
const before = this.require(ref);
|
|
104873
|
-
this.handover.restore(
|
|
104924
|
+
this.handover.restore(appKeyOf(ref), id3, before.dir, { root: before.found.root === true });
|
|
104874
104925
|
this.rescanScopeOf(ref, { now: ref.appId });
|
|
104875
104926
|
const e = this.require(ref);
|
|
104876
104927
|
resetLife(e.life);
|
|
@@ -104899,13 +104950,9 @@ var ExternalApps = class {
|
|
|
104899
104950
|
ref = this.resolve(ref);
|
|
104900
104951
|
this.reflector.builderTurnEnded(ref);
|
|
104901
104952
|
}
|
|
104902
|
-
/** 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) */
|
|
104903
|
-
holdKey(ref) {
|
|
104904
|
-
return appKeyOf(ref.projectId, ref.appId);
|
|
104905
|
-
}
|
|
104906
104953
|
/** An app that is gone takes its error bundles with it (`ErrorLog.forget`) */
|
|
104907
104954
|
forgetErrors(ref) {
|
|
104908
|
-
this.errorLog.forget(
|
|
104955
|
+
this.errorLog.forget(appKeyOf(ref));
|
|
104909
104956
|
}
|
|
104910
104957
|
label(ref) {
|
|
104911
104958
|
return appLabel(ref);
|
|
@@ -104919,7 +104966,7 @@ var ExternalApps = class {
|
|
|
104919
104966
|
* takes a ref resolves it first, so trust and every other rule apply to the app it reaches, as to its new key.
|
|
104920
104967
|
*/
|
|
104921
104968
|
resolve(ref) {
|
|
104922
|
-
if (ref.projectId !== null || this.scopes.get(
|
|
104969
|
+
if (ref.projectId !== null || this.scopes.get(USER_APP_SCOPE)?.apps.has(ref.appId)) return ref;
|
|
104923
104970
|
const projectId = this.deps.adoptedProjectOf?.(ref.appId);
|
|
104924
104971
|
const e = projectId ? this.scopes.get(projectId)?.apps.get(ref.appId) : void 0;
|
|
104925
104972
|
return e?.found.root ? e.ref : ref;
|
|
@@ -104930,11 +104977,11 @@ var ExternalApps = class {
|
|
|
104930
104977
|
return e;
|
|
104931
104978
|
}
|
|
104932
104979
|
find(ref) {
|
|
104933
|
-
return this.scopes.get(ref.projectId ??
|
|
104980
|
+
return this.scopes.get(ref.projectId ?? USER_APP_SCOPE)?.apps.get(ref.appId);
|
|
104934
104981
|
}
|
|
104935
104982
|
info(e) {
|
|
104936
104983
|
const m = e.manifest;
|
|
104937
|
-
const lastErrorAt = this.errorLog.lastAt(
|
|
104984
|
+
const lastErrorAt = this.errorLog.lastAt(appKeyOf(e.ref));
|
|
104938
104985
|
return {
|
|
104939
104986
|
appId: e.ref.appId,
|
|
104940
104987
|
projectId: e.ref.projectId,
|
|
@@ -104999,7 +105046,7 @@ var ExternalApps = class {
|
|
|
104999
105046
|
}
|
|
105000
105047
|
const held3 = this.held(e);
|
|
105001
105048
|
if (held3) return { kind: "unconfirmed", reason: held3 };
|
|
105002
|
-
if (this.removing.has(
|
|
105049
|
+
if (this.removing.has(appKeyOf(e.ref))) return { kind: "removing", reason: "This app is being removed" };
|
|
105003
105050
|
if (e.life.gaveUp && !opts.fresh) {
|
|
105004
105051
|
return {
|
|
105005
105052
|
kind: "failed",
|
|
@@ -105149,7 +105196,7 @@ var InlineViews = class {
|
|
|
105149
105196
|
if (!v.instanceId) {
|
|
105150
105197
|
const gone2 = this.unavailable(v.ref);
|
|
105151
105198
|
if (gone2) refuse3(gone2);
|
|
105152
|
-
if (this.deps.rt.list().find((a) => a
|
|
105199
|
+
if (this.deps.rt.list().find((a) => sameApp(a, v.ref))?.status === "failed") {
|
|
105153
105200
|
refuse3("This app stopped after failing repeatedly. Restart it, then reopen this view");
|
|
105154
105201
|
}
|
|
105155
105202
|
const refusal2 = await this.refusal(v.ref, v.uri);
|
|
@@ -105399,7 +105446,7 @@ var InlineViews = class {
|
|
|
105399
105446
|
* language, since it stands as is in the view.
|
|
105400
105447
|
*/
|
|
105401
105448
|
unavailable(ref) {
|
|
105402
|
-
const info = this.deps.rt.list().find((a) => a
|
|
105449
|
+
const info = this.deps.rt.list().find((a) => sameApp(a, ref));
|
|
105403
105450
|
if (!info) return "This app was removed";
|
|
105404
105451
|
if (info.status === "untrusted") return "This app's project is no longer trusted";
|
|
105405
105452
|
if (info.status === "unconfirmed") return info.error ?? "This imported app is not enabled";
|
|
@@ -106470,6 +106517,7 @@ function hostAccessEnv(access4) {
|
|
|
106470
106517
|
}
|
|
106471
106518
|
|
|
106472
106519
|
// packages/agent-host/src/links/machine-reach.ts
|
|
106520
|
+
var LOOKUP_MS = 4e3;
|
|
106473
106521
|
var TAIL = { tryAgain: "try again once its link is back", readAgain: "read it again once its link is back", none: null };
|
|
106474
106522
|
var notReachable = (m) => m.whyDown ? `${NOT_REACHABLE}; ${oneLineText(m.whyDown, 300)}` : NOT_REACHABLE;
|
|
106475
106523
|
var awaySentence = (m, tail) => m.waitsForPerson ? `${m.name} ${awayPhrase(NOT_CONNECTED)}, then try again` : `${m.name} is ${notReachable(m)}${tail === null ? "" : `; ${tail}`}`;
|
|
@@ -106972,9 +107020,8 @@ async function gitBranches(cwd) {
|
|
|
106972
107020
|
|
|
106973
107021
|
// packages/agent-host/src/dev-services/git-write.ts
|
|
106974
107022
|
function gitWrite(cwd, args, signal) {
|
|
106975
|
-
return runGit(cwd, args, { allowRepoPrograms: true, timeout:
|
|
107023
|
+
return runGit(cwd, args, { allowRepoPrograms: true, timeout: GIT_WRITE_TIMEOUT_MS, signal });
|
|
106976
107024
|
}
|
|
106977
|
-
var WRITE_TIMEOUT_MS = 10 * 6e4;
|
|
106978
107025
|
async function gitCheckout(cwd, branch, opts = {}) {
|
|
106979
107026
|
if (!await isRepo(cwd)) return { ok: false, conflicts: [], message: "Not a git repository" };
|
|
106980
107027
|
if (opts.dryRun) {
|
|
@@ -107080,7 +107127,7 @@ function cloneArgs(url2, into, branch) {
|
|
|
107080
107127
|
function cloneFailure(e, url2, branch) {
|
|
107081
107128
|
const err = execFailure(e);
|
|
107082
107129
|
if (err.code === "ENOENT") return "git is not installed on this machine, so nothing can be cloned.";
|
|
107083
|
-
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.`;
|
|
107084
107131
|
const stderr = err.stderr ?? err.message ?? "";
|
|
107085
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)) {
|
|
107086
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.`;
|
|
@@ -107922,7 +107969,7 @@ var WorktreeSessions = class {
|
|
|
107922
107969
|
if (ran.code === 0 && !ran.ended) {
|
|
107923
107970
|
console.error(`[worktree] setup ok (${worktree.branch}): ${setup.command}`);
|
|
107924
107971
|
} else {
|
|
107925
|
-
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)}`;
|
|
107926
107973
|
const stderr = ran.stderr.toString("utf8");
|
|
107927
107974
|
console.error(`[worktree] setup failed (${worktree.branch}): ${why2}
|
|
107928
107975
|
${stderr.slice(0, 2e3)}`);
|
|
@@ -108561,10 +108608,9 @@ function progressOf(reader, sessionId, now = Date.now()) {
|
|
|
108561
108608
|
const last = reader.loadMessages(sessionId, 1).at(-1);
|
|
108562
108609
|
if (!last) return void 0;
|
|
108563
108610
|
const ms3 = Math.max(0, now - last.ts);
|
|
108564
|
-
const quietFor = ms3 < 6e4 ? `${Math.floor(ms3 / 1e3)} s` : ms3 < 36e5 ? `${Math.floor(ms3 / 6e4)} min` : `${Math.floor(ms3 / 36e5)} h`;
|
|
108565
108611
|
const summary = last.payload?.summary;
|
|
108566
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;
|
|
108567
|
-
return { quietFor, ...lastStep ? { lastStep } : {} };
|
|
108613
|
+
return { quietFor: durationText(ms3), ...lastStep ? { lastStep } : {} };
|
|
108568
108614
|
}
|
|
108569
108615
|
function lastActiveOf(reader, sessionId) {
|
|
108570
108616
|
const rows3 = reader.loadMessages(sessionId, 1);
|
|
@@ -109652,7 +109698,7 @@ var REFUSAL_TEXT = {
|
|
|
109652
109698
|
not_allowed: () => "that is not a party that takes mail",
|
|
109653
109699
|
withheld: (id3) => `${id3} is a request: its words are shown in the turn it starts, and it is marked done there.`,
|
|
109654
109700
|
not_yours: (id3) => `you were not sent ${id3} and did not send it.`,
|
|
109655
|
-
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.`,
|
|
109656
109702
|
ask_rate: () => `your project's sessions asked the Assistant ${ASKS_PER_HOUR} times in the last hour; wait, or write to the person.`,
|
|
109657
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",
|
|
109658
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.`
|
|
@@ -109662,7 +109708,7 @@ var WARNING_TEXT = {
|
|
|
109662
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.`,
|
|
109663
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.`,
|
|
109664
109710
|
/** The three guards that refuse rather than warn (#1684, #2035): the person hears of the first refusal of each kind a clock hour */
|
|
109665
|
-
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.`,
|
|
109666
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.`,
|
|
109667
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.`
|
|
109668
109714
|
};
|
|
@@ -110201,6 +110247,25 @@ var MailDelivery = class {
|
|
|
110201
110247
|
// packages/agent-host/src/sessions/delegated-cards.ts
|
|
110202
110248
|
import { createHash as createHash10 } from "node:crypto";
|
|
110203
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
|
+
|
|
110204
110269
|
// packages/agent-host/src/sessions/app-guide.ts
|
|
110205
110270
|
var APP_GUIDE_TOPICS = ["overview", "sessions", "assistant", "apps", "approvals", "settings", "updates"];
|
|
110206
110271
|
var STATIC = {
|
|
@@ -113867,26 +113932,26 @@ Reason: ${why2.slice(0, 600)}`,
|
|
|
113867
113932
|
|
|
113868
113933
|
// packages/agent-host/src/sessions/start-agent-flow.ts
|
|
113869
113934
|
function startAgentLate(progress) {
|
|
113870
|
-
const
|
|
113935
|
+
const seconds = Math.round(START_AGENT_SETUP_MS / 1e3);
|
|
113871
113936
|
const note = progress.unchecked ? ` (${progress.unchecked}.)` : "";
|
|
113872
113937
|
switch (progress.stage) {
|
|
113873
113938
|
case "created":
|
|
113874
113939
|
return {
|
|
113875
113940
|
ok: false,
|
|
113876
|
-
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}`
|
|
113877
113942
|
};
|
|
113878
113943
|
case "creating":
|
|
113879
113944
|
return {
|
|
113880
113945
|
ok: false,
|
|
113881
|
-
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}`
|
|
113882
113947
|
};
|
|
113883
113948
|
case "asking":
|
|
113884
113949
|
return {
|
|
113885
113950
|
ok: false,
|
|
113886
|
-
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}`
|
|
113887
113952
|
};
|
|
113888
113953
|
default:
|
|
113889
|
-
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}` };
|
|
113890
113955
|
}
|
|
113891
113956
|
}
|
|
113892
113957
|
var AgentStartFlow = class {
|
|
@@ -116794,9 +116859,6 @@ function isServerOverloaded(errorInfo) {
|
|
|
116794
116859
|
|
|
116795
116860
|
// packages/agent-host/src/sessions/overload-retry.ts
|
|
116796
116861
|
var DELAYS_MS = [3e4, 12e4, 3e5, 6e5];
|
|
116797
|
-
function waitWords(ms3) {
|
|
116798
|
-
return ms3 >= 6e4 ? `${Math.round(ms3 / 6e4)} min` : `${Math.round(ms3 / 1e3)} s`;
|
|
116799
|
-
}
|
|
116800
116862
|
var OverloadRetry = class {
|
|
116801
116863
|
constructor(host) {
|
|
116802
116864
|
this.host = host;
|
|
@@ -116835,7 +116897,7 @@ ${spentWords(tries)}` } };
|
|
|
116835
116897
|
level: "warning",
|
|
116836
116898
|
from: "Centralu",
|
|
116837
116899
|
label: "retry",
|
|
116838
|
-
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.`
|
|
116839
116901
|
};
|
|
116840
116902
|
}
|
|
116841
116903
|
/** Every event of a session: the ones that end the turn take a wait away, and start the count over */
|
|
@@ -117196,143 +117258,6 @@ var MergeChecks = class {
|
|
|
117196
117258
|
}
|
|
117197
117259
|
};
|
|
117198
117260
|
|
|
117199
|
-
// packages/agent-host/src/themes.ts
|
|
117200
|
-
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
117201
|
-
import { watch as watch3 } from "node:fs";
|
|
117202
|
-
import { mkdir as mkdir4, readdir as readdir7, readFile as readFile4, stat as stat7 } from "node:fs/promises";
|
|
117203
|
-
import { basename as basename8, join as join30 } from "node:path";
|
|
117204
|
-
var MAX_FILE_BYTES = 256 * 1024;
|
|
117205
|
-
var SETTLE_MS = 100;
|
|
117206
|
-
function themeSlug(name) {
|
|
117207
|
-
return name.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48) || "theme";
|
|
117208
|
-
}
|
|
117209
|
-
var REMOVED_DIR = ".removed";
|
|
117210
|
-
var ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,59}$/;
|
|
117211
|
-
var ThemeFiles = class {
|
|
117212
|
-
constructor(dir, onChange) {
|
|
117213
|
-
this.dir = dir;
|
|
117214
|
-
this.onChange = onChange;
|
|
117215
|
-
}
|
|
117216
|
-
dir;
|
|
117217
|
-
onChange;
|
|
117218
|
-
watcher = null;
|
|
117219
|
-
timer = null;
|
|
117220
|
-
/** Makes the folder, writes the schema next to the themes, and starts watching */
|
|
117221
|
-
async start() {
|
|
117222
|
-
await mkdir4(this.dir, { recursive: true });
|
|
117223
|
-
await this.writeSchema();
|
|
117224
|
-
try {
|
|
117225
|
-
this.watcher = watch3(this.dir, (_event, name) => {
|
|
117226
|
-
if (name && !String(name).endsWith(".json")) return;
|
|
117227
|
-
if (name === THEME_SCHEMA_FILE) return;
|
|
117228
|
-
if (this.timer) clearTimeout(this.timer);
|
|
117229
|
-
this.timer = setTimeout(() => {
|
|
117230
|
-
this.timer = null;
|
|
117231
|
-
this.onChange();
|
|
117232
|
-
}, SETTLE_MS);
|
|
117233
|
-
});
|
|
117234
|
-
this.watcher.on("error", () => this.stopWatching());
|
|
117235
|
-
} catch {
|
|
117236
|
-
}
|
|
117237
|
-
}
|
|
117238
|
-
close() {
|
|
117239
|
-
this.stopWatching();
|
|
117240
|
-
if (this.timer) clearTimeout(this.timer);
|
|
117241
|
-
this.timer = null;
|
|
117242
|
-
}
|
|
117243
|
-
stopWatching() {
|
|
117244
|
-
this.watcher?.close();
|
|
117245
|
-
this.watcher = null;
|
|
117246
|
-
}
|
|
117247
|
-
/**
|
|
117248
|
-
* The schema an editor uses for completion, written only when it differs — a build that adds
|
|
117249
|
-
* a token updates it, and an unchanged one does not touch the folder (or wake the watcher).
|
|
117250
|
-
*/
|
|
117251
|
-
async writeSchema() {
|
|
117252
|
-
const path2 = join30(this.dir, THEME_SCHEMA_FILE);
|
|
117253
|
-
const text3 = `${JSON.stringify(themeFileJsonSchema(), null, 2)}
|
|
117254
|
-
`;
|
|
117255
|
-
const current = await readFile4(path2, "utf8").catch(() => null);
|
|
117256
|
-
if (current !== text3) writeFileWhole(realOs().files, path2, text3);
|
|
117257
|
-
}
|
|
117258
|
-
/** Every `<id>.json` in the folder, read and checked. A file that cannot be read is listed with the reason. */
|
|
117259
|
-
async list() {
|
|
117260
|
-
const names = await readdir7(this.dir).catch(() => []);
|
|
117261
|
-
const entries = [];
|
|
117262
|
-
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();
|
|
117263
|
-
for (const id3 of ids) entries.push(await this.read(id3));
|
|
117264
|
-
return entries;
|
|
117265
|
-
}
|
|
117266
|
-
async read(id3) {
|
|
117267
|
-
const path2 = this.pathOf(id3);
|
|
117268
|
-
try {
|
|
117269
|
-
const info = await stat7(path2);
|
|
117270
|
-
if (info.size > MAX_FILE_BYTES) {
|
|
117271
|
-
return { id: id3, path: path2, name: id3, base: "dark", tokens: {}, problems: ["The file is too large to be a theme."], broken: true };
|
|
117272
|
-
}
|
|
117273
|
-
return parseThemeFile(id3, path2, await readFile4(path2, "utf8"));
|
|
117274
|
-
} catch (e) {
|
|
117275
|
-
return { id: id3, path: path2, name: id3, base: "dark", tokens: {}, problems: [`Could not read the file: ${e.message}`], broken: true };
|
|
117276
|
-
}
|
|
117277
|
-
}
|
|
117278
|
-
/** Writes a theme. `id` null makes a new file named after the theme (`My theme` → `my-theme.json`). */
|
|
117279
|
-
async save(id3, content) {
|
|
117280
|
-
const text3 = formatThemeFile(content);
|
|
117281
|
-
if (Buffer.byteLength(text3) > MAX_FILE_BYTES) throw rpcError("The theme is too large to be a theme file.");
|
|
117282
|
-
const target = id3 ?? await this.freeId(content.name);
|
|
117283
|
-
await mkdir4(this.dir, { recursive: true });
|
|
117284
|
-
const names = await readdir7(this.dir).catch(() => []);
|
|
117285
|
-
const clash = names.find((n) => n !== `${target}.json` && n.toLowerCase() === `${target}.json`);
|
|
117286
|
-
if (clash) throw rpcError(`The themes folder has ${clash}, which the list does not show (ids are lowercase); rename or remove it first.`);
|
|
117287
|
-
writeFileWhole(realOs().files, this.pathOf(target), text3);
|
|
117288
|
-
return this.read(target);
|
|
117289
|
-
}
|
|
117290
|
-
/**
|
|
117291
|
-
* Takes a theme file out of the list without destroying it: it moves to `.removed/<id>-<time>-<random>.json`, a place the list
|
|
117292
|
-
* does not look, so a mistaken removal is one move back. The host has no OS trash (Settings' button reaches it through the
|
|
117293
|
-
* shell), so these stay until the person clears the folder. Where it went is returned; null when there was no such file.
|
|
117294
|
-
*/
|
|
117295
|
-
async remove(id3) {
|
|
117296
|
-
const from = this.pathOf(id3);
|
|
117297
|
-
if (!await stat7(from).then(() => true, () => false)) return null;
|
|
117298
|
-
const kept = join30(this.dir, REMOVED_DIR);
|
|
117299
|
-
await mkdir4(kept, { recursive: true });
|
|
117300
|
-
const to = join30(kept, `${id3}-${Date.now()}-${randomBytes7(3).toString("hex")}.json`);
|
|
117301
|
-
await realOs().files.promises.rename(from, to);
|
|
117302
|
-
return to;
|
|
117303
|
-
}
|
|
117304
|
-
/** Copies a file from elsewhere in, under a fresh id if its name is taken. Refuses what does not read as a theme. */
|
|
117305
|
-
async importFrom(source) {
|
|
117306
|
-
const info = await stat7(source);
|
|
117307
|
-
if (!info.isFile()) throw rpcError("That is not a file.");
|
|
117308
|
-
if (info.size > MAX_FILE_BYTES) throw rpcError("The file is too large to be a theme.");
|
|
117309
|
-
const text3 = await readFile4(source, "utf8");
|
|
117310
|
-
const parsed = parseThemeFile("import", source, text3);
|
|
117311
|
-
if (parsed.broken) throw rpcError(parsed.problems[0] ?? "Not a theme file.");
|
|
117312
|
-
const fromName = basename8(source).replace(/\.json$/i, "");
|
|
117313
|
-
const id3 = await this.freeId(parsed.name !== "import" ? parsed.name : fromName);
|
|
117314
|
-
writeFileWhole(realOs().files, this.pathOf(id3), text3);
|
|
117315
|
-
return this.read(id3);
|
|
117316
|
-
}
|
|
117317
|
-
/** The absolute path for an id, for the shell to trash or reveal. Refuses anything that is not an id. */
|
|
117318
|
-
pathOf(id3) {
|
|
117319
|
-
if (!ID_PATTERN.test(id3)) throw rpcError(`Not a theme id: ${id3}`);
|
|
117320
|
-
return join30(this.dir, `${id3}.json`);
|
|
117321
|
-
}
|
|
117322
|
-
async freeId(name) {
|
|
117323
|
-
const base2 = themeSlug(name);
|
|
117324
|
-
for (let n = 1; n < 1e3; n++) {
|
|
117325
|
-
const id3 = n === 1 ? base2 : `${base2}-${n}`;
|
|
117326
|
-
const taken = await stat7(this.pathOf(id3)).then(
|
|
117327
|
-
() => true,
|
|
117328
|
-
() => false
|
|
117329
|
-
);
|
|
117330
|
-
if (!taken) return id3;
|
|
117331
|
-
}
|
|
117332
|
-
return `${base2}-${randomBytes7(4).toString("hex")}`;
|
|
117333
|
-
}
|
|
117334
|
-
};
|
|
117335
|
-
|
|
117336
117261
|
// packages/agent-host/src/sessions/window-rpc.ts
|
|
117337
117262
|
var WINDOW_METHODS = [
|
|
117338
117263
|
"prefs.get",
|
|
@@ -117439,7 +117364,7 @@ var PreferencesFlow = class {
|
|
|
117439
117364
|
]);
|
|
117440
117365
|
if (prefs.status === "rejected") return { ok: false, error: `Could not read the preferences: ${prefs.reason instanceof Error ? prefs.reason.message : String(prefs.reason)}` };
|
|
117441
117366
|
const p = prefs.value;
|
|
117442
|
-
const choices = themes2.status === "fulfilled" ?
|
|
117367
|
+
const choices = pickableThemes(themes2.status === "fulfilled" ? themes2.value : []);
|
|
117443
117368
|
const named3 = (id3) => {
|
|
117444
117369
|
const c = choices.find((x) => x.id === id3);
|
|
117445
117370
|
return c ? `${plainQuoted(c.name)} [${c.id}]` : `[${plainQuoted(id3)}] (no such theme; the stylesheet's own is shown)`;
|
|
@@ -117481,6 +117406,8 @@ var PreferencesFlow = class {
|
|
|
117481
117406
|
if (file2 !== void 0) {
|
|
117482
117407
|
const bad = themeFileRefusal(file2);
|
|
117483
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)}` };
|
|
117484
117411
|
}
|
|
117485
117412
|
if (changes.theme !== void 0) {
|
|
117486
117413
|
const found = await this.theme(rpc, changes.theme);
|
|
@@ -117517,9 +117444,11 @@ var PreferencesFlow = class {
|
|
|
117517
117444
|
if (sleep4 !== void 0 && sleep4 !== "never" && !(Number.isInteger(sleep4) && sleep4 > 0)) {
|
|
117518
117445
|
return { ok: false, error: `idleSleepMinutes is ${SLEEP_CHOICES}.` };
|
|
117519
117446
|
}
|
|
117447
|
+
let written = null;
|
|
117520
117448
|
if (file2 !== void 0) {
|
|
117521
117449
|
try {
|
|
117522
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;
|
|
117523
117452
|
done2.push(themeFileWritten(saved));
|
|
117524
117453
|
} catch (e) {
|
|
117525
117454
|
return { ok: false, error: errorMessage(e) };
|
|
@@ -117527,18 +117456,13 @@ var PreferencesFlow = class {
|
|
|
117527
117456
|
}
|
|
117528
117457
|
let toApply = parsed.data;
|
|
117529
117458
|
if (changes.theme !== void 0) {
|
|
117530
|
-
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);
|
|
117531
117460
|
if (typeof found === "string") failed4.push(`Theme: not picked. ${found}`);
|
|
117532
117461
|
else {
|
|
117533
117462
|
theme = found;
|
|
117534
117463
|
patch.themeMode = found.base;
|
|
117535
117464
|
patch[found.base === "dark" ? "themeDark" : "themeLight"] = found.id;
|
|
117536
|
-
|
|
117537
|
-
if (again.success) toApply = again.data;
|
|
117538
|
-
else {
|
|
117539
|
-
theme = null;
|
|
117540
|
-
failed4.push(`Theme: not picked. ${issuesOf(again.error)}.`);
|
|
117541
|
-
}
|
|
117465
|
+
toApply = UiPreferencesPatch.parse(patch);
|
|
117542
117466
|
}
|
|
117543
117467
|
}
|
|
117544
117468
|
const attempt = async (what, run2) => {
|
|
@@ -117721,12 +117645,7 @@ var PreferencesFlow = class {
|
|
|
117721
117645
|
const named3 = file2.id?.trim().toLowerCase();
|
|
117722
117646
|
if (named3) return named3;
|
|
117723
117647
|
const taken = new Set((await callWindow(rpc, "themes.list", {})).map((f) => f.id));
|
|
117724
|
-
|
|
117725
|
-
for (let n = 1; n < 1e3; n++) {
|
|
117726
|
-
const id3 = n === 1 ? base2 : `${base2}-${n}`;
|
|
117727
|
-
if (!taken.has(id3)) return id3;
|
|
117728
|
-
}
|
|
117729
|
-
return base2;
|
|
117648
|
+
return freeThemeId(file2.name.trim(), (id3) => taken.has(id3));
|
|
117730
117649
|
}
|
|
117731
117650
|
/** The session header's action: idle sessions on an older agent CLI restart on the installed one, and the busy ones are named */
|
|
117732
117651
|
async applyVersions(rpc) {
|
|
@@ -117740,7 +117659,7 @@ var PreferencesFlow = class {
|
|
|
117740
117659
|
const wanted = ref.trim();
|
|
117741
117660
|
if (!wanted) return "theme is empty; get_preferences lists the themes to choose from.";
|
|
117742
117661
|
if (HIDDEN2.test(wanted)) return "theme has a control or formatting character in it; give its id or name as plain text.";
|
|
117743
|
-
const choices =
|
|
117662
|
+
const choices = pickableThemes(await callWindow(rpc, "themes.list", {}));
|
|
117744
117663
|
const byId = choices.find((c) => c.id === wanted.toLowerCase());
|
|
117745
117664
|
if (byId) return byId;
|
|
117746
117665
|
const byName = choices.filter((c) => c.name.toLowerCase() === wanted.toLowerCase());
|
|
@@ -117800,12 +117719,6 @@ function agentModelsText(models) {
|
|
|
117800
117719
|
);
|
|
117801
117720
|
return parts.length ? parts.join("; ") : "none chosen (each project keeps its last choice)";
|
|
117802
117721
|
}
|
|
117803
|
-
function themeChoices(files2) {
|
|
117804
|
-
return [
|
|
117805
|
-
...THEME_PRESETS.map((p) => ({ id: p.id, name: p.name, base: p.base, file: false })),
|
|
117806
|
-
...files2.filter((f) => !f.broken).map((f) => ({ id: f.id, name: f.name, base: f.base, file: true }))
|
|
117807
|
-
];
|
|
117808
|
-
}
|
|
117809
117722
|
function appearanceText(now, patch, theme) {
|
|
117810
117723
|
const parts = [];
|
|
117811
117724
|
if (theme) {
|
|
@@ -118457,7 +118370,7 @@ var TrustFlow = class {
|
|
|
118457
118370
|
].join("\n");
|
|
118458
118371
|
const refused2 = await this.ask(caller, question, signal, "shared");
|
|
118459
118372
|
if (refused2) return { ok: false, error: refused2 };
|
|
118460
|
-
const now = (await callWindow(rpc, "apps.list", {})).find((x) =>
|
|
118373
|
+
const now = (await callWindow(rpc, "apps.list", {})).find((x) => sameApp(x, a));
|
|
118461
118374
|
if (!now) return { ok: false, error: `${label} was removed while the card stood, so nothing was shared.` };
|
|
118462
118375
|
if (now.shared) return { ok: true, text: `${label} was shared while the card stood; nothing more changed.` };
|
|
118463
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.` };
|
|
@@ -118638,7 +118551,7 @@ var AppUpkeepFlow = class {
|
|
|
118638
118551
|
}
|
|
118639
118552
|
async usage(rpc, label, ref) {
|
|
118640
118553
|
const u = await callWindow(rpc, "apps.usage", ref);
|
|
118641
|
-
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` : ""}`;
|
|
118642
118555
|
return { ok: true, text: [`The agent use ${label} requested:`, line("Last day", u.day), line("Last 30 days", u.month)].join("\n") };
|
|
118643
118556
|
}
|
|
118644
118557
|
async remove(rpc, caller, app2, label, all, signal) {
|
|
@@ -118652,7 +118565,7 @@ var AppUpkeepFlow = class {
|
|
|
118652
118565
|
const decision = await this.host.hostCards.askHost(caller, { kind: "other", about: ASSISTANT_CHANGE, raw: question }, signal, { alwaysAsk: true });
|
|
118653
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." };
|
|
118654
118567
|
if (decision === null) return { ok: false, error: "The card was withdrawn before the person answered, so the app was not removed." };
|
|
118655
|
-
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 }));
|
|
118656
118569
|
if (!now) return { ok: true, text: `${label} was already gone while the card stood; nothing more was done.` };
|
|
118657
118570
|
await callWindow(rpc, "apps.remove", { appId: app2.appId, projectId: null, ...onMachine(app2) });
|
|
118658
118571
|
return { ok: true, text: `Removed ${label}: its folder is in app-trash/ ${where2}, and it is detached from the sessions that had it.` };
|
|
@@ -118783,7 +118696,7 @@ var HousekeepingFlow = class {
|
|
|
118783
118696
|
import { randomUUID as randomUUID18 } from "node:crypto";
|
|
118784
118697
|
import { existsSync as existsSync15, realpathSync as realpathSync5, statSync as statSync14 } from "node:fs";
|
|
118785
118698
|
import { homedir as homedir7 } from "node:os";
|
|
118786
|
-
import { basename as
|
|
118699
|
+
import { basename as basename8, isAbsolute as isAbsolute5, resolve as resolve11 } from "node:path";
|
|
118787
118700
|
|
|
118788
118701
|
// packages/agent-host/src/dev-services/project-folder.ts
|
|
118789
118702
|
import { lstatSync as lstatSync12, mkdirSync as mkdirSync16, statSync as statSync13 } from "node:fs";
|
|
@@ -118860,7 +118773,7 @@ var ProjectCreation = class {
|
|
|
118860
118773
|
const existing = this.projectAt(spelled2);
|
|
118861
118774
|
const at2 = existing?.path ?? spelled2;
|
|
118862
118775
|
const id3 = existing?.id ?? randomUUID18();
|
|
118863
|
-
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 } : {} });
|
|
118864
118777
|
return this.host.projectInfo(id3, at2);
|
|
118865
118778
|
}
|
|
118866
118779
|
/**
|
|
@@ -118895,7 +118808,7 @@ var ProjectCreation = class {
|
|
|
118895
118808
|
const git2 = folder ? await isRepo(path2).catch(() => false) : false;
|
|
118896
118809
|
const origin = git2 ? await gitOriginUrl(path2, { trusted: false }) : null;
|
|
118897
118810
|
const kept = folder ? this.projectAt(path2) : void 0;
|
|
118898
|
-
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;
|
|
118899
118812
|
return { path: path2, exists: found !== null, folder, git: git2, origin, project: project2 };
|
|
118900
118813
|
}
|
|
118901
118814
|
/**
|
|
@@ -119437,14 +119350,14 @@ var NOTED_KEEP_MS = 6e4;
|
|
|
119437
119350
|
var NOTED_MAX = 64;
|
|
119438
119351
|
var UNUSABLE = /* @__PURE__ */ new Set(["invalid", "untrusted", "unconfirmed", "failed"]);
|
|
119439
119352
|
function givesApp(session2, app2) {
|
|
119440
|
-
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);
|
|
119441
119354
|
}
|
|
119442
119355
|
var APP_NAMES_PREFIX = "session_app_names:";
|
|
119443
119356
|
var nameSlug = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 24).replace(/-+$/, "");
|
|
119444
|
-
var SERVER_NAME_MAX =
|
|
119357
|
+
var SERVER_NAME_MAX = appServerName("x".repeat(APP_ID_MAX_LENGTH)).length;
|
|
119445
119358
|
function freeServerName(appId, taken, qualifier) {
|
|
119446
119359
|
const has = (name) => Array.isArray(taken) ? taken.includes(name) : taken.has(name);
|
|
119447
|
-
const base2 =
|
|
119360
|
+
const base2 = appServerName(appId);
|
|
119448
119361
|
if (!has(base2)) return base2;
|
|
119449
119362
|
const stem = qualifier ? `${base2}-${qualifier}` : base2;
|
|
119450
119363
|
for (let n = qualifier ? 1 : 2; ; n++) {
|
|
@@ -119573,8 +119486,8 @@ var SessionAppsHub = class {
|
|
|
119573
119486
|
const hits = this.named(session2, usable.filter((a) => givesApp(session2, a))).sort((x, y) => x.server.localeCompare(y.server));
|
|
119574
119487
|
const taken = new Set(hits.map((h) => h.server));
|
|
119575
119488
|
for (const x of this.opts.onDemand?.attached(session2.id) ?? []) {
|
|
119576
|
-
const app2 = usable.find((a) => a
|
|
119577
|
-
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;
|
|
119578
119491
|
if (!this.opts.onDemand.allowed(session2, app2)) continue;
|
|
119579
119492
|
hits.push({ ref: x.ref, server: x.server });
|
|
119580
119493
|
taken.add(x.server);
|
|
@@ -119604,7 +119517,7 @@ var SessionAppsHub = class {
|
|
|
119604
119517
|
const key = appKeyOf(a.projectId, a.appId);
|
|
119605
119518
|
let server2 = book[key];
|
|
119606
119519
|
if (!server2) {
|
|
119607
|
-
const base2 =
|
|
119520
|
+
const base2 = appServerName(a.appId);
|
|
119608
119521
|
const slug = a.projectId ? nameSlug(this.opts.projectName?.(a.projectId) ?? "") || a.projectId.slice(0, 8).toLowerCase() : "user";
|
|
119609
119522
|
server2 = !taken.has(base2) ? base2 : freeServerName(a.appId, taken, slug);
|
|
119610
119523
|
book[key] = server2;
|
|
@@ -119633,7 +119546,7 @@ var SessionAppsHub = class {
|
|
|
119633
119546
|
*/
|
|
119634
119547
|
claimAttachName(sessionId, ref, inUse) {
|
|
119635
119548
|
const book = this.bookOf(sessionId);
|
|
119636
|
-
const key = appKeyOf(ref
|
|
119549
|
+
const key = appKeyOf(ref);
|
|
119637
119550
|
const taken = /* @__PURE__ */ new Set([...inUse, ...Object.entries(book).filter(([k2]) => k2 !== key).map(([, server3]) => server3)]);
|
|
119638
119551
|
const had = book[key];
|
|
119639
119552
|
const server2 = had && !taken.has(had) ? had : freeServerName(ref.appId, taken);
|
|
@@ -119654,9 +119567,9 @@ var SessionAppsHub = class {
|
|
|
119654
119567
|
* has not is reachable (#1205): its agent attaches it with `attach_app`, and the person has nothing to do.
|
|
119655
119568
|
*/
|
|
119656
119569
|
reach(session2, ref, live2) {
|
|
119657
|
-
const app2 = this.rt.list().find((a) => a
|
|
119570
|
+
const app2 = this.rt.list().find((a) => sameApp(a, ref));
|
|
119658
119571
|
if (!app2) return { reachable: false, reason: "unavailable" };
|
|
119659
|
-
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;
|
|
119660
119573
|
const onDemand = !!session2 && !!own && this.opts.onDemand.allowed(session2, app2);
|
|
119661
119574
|
const selfServed = !!session2 && !own && isAssistantKind(session2.kind) && app2.root === true && !!this.opts.onDemand;
|
|
119662
119575
|
const lostTrust = !!own && app2.status === "untrusted";
|
|
@@ -119665,7 +119578,7 @@ var SessionAppsHub = class {
|
|
|
119665
119578
|
if (UNUSABLE.has(app2.status)) return { reachable: false, reason: "app-unusable", status: app2.status };
|
|
119666
119579
|
if (selfServed && !this.opts.onDemand.allowed(session2, app2)) return { reachable: false, reason: "other-project" };
|
|
119667
119580
|
if (selfServed) return { reachable: true };
|
|
119668
|
-
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;
|
|
119669
119582
|
const attached = live2?.appAttachment?.(server2) ?? "attached";
|
|
119670
119583
|
if (attached === "restart") return { reachable: false, reason: "restart" };
|
|
119671
119584
|
if (attached === "failed") return { reachable: false, reason: "bridge-failed" };
|
|
@@ -119786,12 +119699,12 @@ var Attachment2 = class {
|
|
|
119786
119699
|
const entry = { sessionId: this.session.id, server: server2, startedAt: Date.now() - opts.waitMs, outcome: null };
|
|
119787
119700
|
this.hub.remember(runId, entry);
|
|
119788
119701
|
void pending.then((o) => entry.outcome = o);
|
|
119789
|
-
const
|
|
119702
|
+
const seconds = Math.round(opts.waitMs / 1e3);
|
|
119790
119703
|
return {
|
|
119791
119704
|
content: [
|
|
119792
119705
|
{
|
|
119793
119706
|
type: "text",
|
|
119794
|
-
text: `This call is still running (past ${
|
|
119707
|
+
text: `This call is still running (past ${seconds} s). Run id: ${runId}
|
|
119795
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.`
|
|
119796
119709
|
}
|
|
119797
119710
|
],
|
|
@@ -119814,9 +119727,9 @@ The call has not stopped and carries on. Do not call it again: pass this id as r
|
|
|
119814
119727
|
const d2 = this.hub.detached.get(runId);
|
|
119815
119728
|
if (d2 && d2.sessionId === this.session.id && d2.server === hit.server) {
|
|
119816
119729
|
if (!d2.outcome) {
|
|
119817
|
-
const
|
|
119730
|
+
const seconds = Math.round((Date.now() - d2.startedAt) / 1e3);
|
|
119818
119731
|
return {
|
|
119819
|
-
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.` }],
|
|
119820
119733
|
isError: false,
|
|
119821
119734
|
structuredContent: { runId, status: "running" }
|
|
119822
119735
|
};
|
|
@@ -119824,7 +119737,7 @@ The call has not stopped and carries on. Do not call it again: pass this id as r
|
|
|
119824
119737
|
const o = d2.outcome;
|
|
119825
119738
|
const done2 = toResult(o);
|
|
119826
119739
|
return {
|
|
119827
|
-
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],
|
|
119828
119741
|
isError: done2.isError,
|
|
119829
119742
|
structuredContent: { runId, status: o.status, ...done2.structuredContent ? { result: done2.structuredContent } : {} }
|
|
119830
119743
|
};
|
|
@@ -119936,9 +119849,6 @@ The call has not stopped and carries on. Do not call it again: pass this id as r
|
|
|
119936
119849
|
return this.hub.refsFor(this.session).find((h) => h.server === server2) ?? null;
|
|
119937
119850
|
}
|
|
119938
119851
|
};
|
|
119939
|
-
function sameRef(a, b2) {
|
|
119940
|
-
return a.appId === b2.appId && a.projectId === b2.projectId;
|
|
119941
|
-
}
|
|
119942
119852
|
function argsKey(args) {
|
|
119943
119853
|
let v = args;
|
|
119944
119854
|
if (typeof v === "string") {
|
|
@@ -120131,7 +120041,7 @@ var SettingsRecords = class {
|
|
|
120131
120041
|
|
|
120132
120042
|
// packages/agent-host/src/sessions/app-access.ts
|
|
120133
120043
|
var KEY = (sessionId) => `session_apps:${sessionId}`;
|
|
120134
|
-
var SHARED_KEY = (ref) => `app_shared:${appKeyOf(ref
|
|
120044
|
+
var SHARED_KEY = (ref) => `app_shared:${appKeyOf(ref)}`;
|
|
120135
120045
|
var UNUSABLE2 = /* @__PURE__ */ new Set(["invalid", "untrusted", "unconfirmed", "failed"]);
|
|
120136
120046
|
function readShared(store2, ref) {
|
|
120137
120047
|
return ref.projectId !== null && store2.appSetting(SHARED_KEY({ projectId: ref.projectId, appId: ref.appId })) === "1";
|
|
@@ -120160,7 +120070,7 @@ var AppAccess = class {
|
|
|
120160
120070
|
if (app2.projectId === null) return true;
|
|
120161
120071
|
if (app2.root === true && app2.projectId !== from) return app2.status !== "untrusted";
|
|
120162
120072
|
if (app2.projectId === from || app2.shared !== true) return false;
|
|
120163
|
-
const r = this.records(session2.id).find((x) => x
|
|
120073
|
+
const r = this.records(session2.id).find((x) => sameApp(x, app2));
|
|
120164
120074
|
if (!r) return false;
|
|
120165
120075
|
return !!this.deps.boundaryOpen?.(session2.id) || r.consent === "once" || !!this.deps.store.permissions.getProjectConsent(from, app2.projectId, "apps");
|
|
120166
120076
|
}
|
|
@@ -120184,9 +120094,9 @@ var AppAccess = class {
|
|
|
120184
120094
|
if (!named3.ok) return named3;
|
|
120185
120095
|
const app2 = named3.app;
|
|
120186
120096
|
const target = { projectId: app2.projectId, appId: app2.appId };
|
|
120187
|
-
const has = already.find((h) => h.ref
|
|
120097
|
+
const has = already.find((h) => sameApp(h.ref, target));
|
|
120188
120098
|
if (has) return { ok: true, server: has.server, tools: await this.toolNames(target), when: "now", already: true };
|
|
120189
|
-
if (!this.candidates(session2).some((a) => a
|
|
120099
|
+
if (!this.candidates(session2).some((a) => sameApp(a, app2))) {
|
|
120190
120100
|
return { ok: false, error: this.whyNot(session2, app2) };
|
|
120191
120101
|
}
|
|
120192
120102
|
let consent = "none";
|
|
@@ -120201,11 +120111,11 @@ var AppAccess = class {
|
|
|
120201
120111
|
consent = this.deps.boundaryOpen?.(sessionId) ? "auto" : this.deps.store.permissions.getProjectConsent(session2.projectId, app2.projectId, "apps") ? "always" : "once";
|
|
120202
120112
|
const again = this.gate(sessionId);
|
|
120203
120113
|
if (!again.ok) return again;
|
|
120204
|
-
if (!this.candidates(again.session).some((a) => a
|
|
120114
|
+
if (!this.candidates(again.session).some((a) => sameApp(a, app2))) {
|
|
120205
120115
|
return { ok: false, error: this.whyNot(again.session, app2) };
|
|
120206
120116
|
}
|
|
120207
120117
|
}
|
|
120208
|
-
const kept = this.records(sessionId).filter((r) => !(r
|
|
120118
|
+
const kept = this.records(sessionId).filter((r) => !sameApp(r, app2));
|
|
120209
120119
|
const inUse = [...this.deps.hub.refsFor(session2).map((h) => h.server), ...kept.map((r) => r.server)];
|
|
120210
120120
|
const server2 = this.deps.hub.claimAttachName(sessionId, target, inUse);
|
|
120211
120121
|
this.save(sessionId, [...kept, { projectId: app2.projectId, appId: app2.appId, server: server2, consent, at: Date.now() }]);
|
|
@@ -120300,7 +120210,7 @@ var AppAccess = class {
|
|
|
120300
120210
|
candidates(session2) {
|
|
120301
120211
|
const have = this.deps.hub.refsFor(session2);
|
|
120302
120212
|
const assistant = isAssistantKind(session2.kind);
|
|
120303
|
-
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)));
|
|
120304
120214
|
}
|
|
120305
120215
|
whyNot(session2, app2) {
|
|
120306
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.`;
|
|
@@ -120316,7 +120226,7 @@ var AppAccess = class {
|
|
|
120316
120226
|
const slash = want.lastIndexOf("/");
|
|
120317
120227
|
let app2;
|
|
120318
120228
|
if (slash === -1) {
|
|
120319
|
-
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;
|
|
120320
120230
|
const roots = all.filter((a) => a.root === true && a.appId === id3);
|
|
120321
120231
|
app2 = all.find((a) => a.projectId === null && a.appId === id3) ?? (roots.length === 1 ? roots[0] : void 0);
|
|
120322
120232
|
} else {
|
|
@@ -120384,7 +120294,7 @@ var AppAccess = class {
|
|
|
120384
120294
|
}
|
|
120385
120295
|
};
|
|
120386
120296
|
function isRecord2(x) {
|
|
120387
|
-
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");
|
|
120388
120298
|
}
|
|
120389
120299
|
|
|
120390
120300
|
// packages/agent-host/src/sessions/session-app-wiring.ts
|
|
@@ -120551,7 +120461,7 @@ var SessionAppWiring = class {
|
|
|
120551
120461
|
settings.setAppSetting(key, "1");
|
|
120552
120462
|
const book = parseJson(settings.appSetting(`${APP_NAMES_PREFIX}${sessionId}`));
|
|
120553
120463
|
if (!isObj(book)) return null;
|
|
120554
|
-
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)));
|
|
120555
120465
|
const hadRootApp = Object.keys(book).some((k2) => !k2.startsWith(`${USER_APP_SCOPE}/`) && !attached.has(k2));
|
|
120556
120466
|
return hadRootApp ? ROOT_APPS_NOTICE : null;
|
|
120557
120467
|
}
|
|
@@ -120562,7 +120472,7 @@ var SessionAppWiring = class {
|
|
|
120562
120472
|
*/
|
|
120563
120473
|
setAppShared(ref, shared) {
|
|
120564
120474
|
const rt2 = this.requireAppsHub().rt;
|
|
120565
|
-
if (!rt2.list().some((a) => a
|
|
120475
|
+
if (!rt2.list().some((a) => sameApp(a, ref))) {
|
|
120566
120476
|
throw rpcError(`No such app: ${ref.appId}`);
|
|
120567
120477
|
}
|
|
120568
120478
|
writeShared(this.host.store.settings, ref, shared);
|
|
@@ -120713,27 +120623,27 @@ var SessionTools = class {
|
|
|
120713
120623
|
|
|
120714
120624
|
// packages/agent-host/src/dev-services/handoff-notes.ts
|
|
120715
120625
|
import { mkdirSync as mkdirSync17, writeFileSync as writeFileSync8 } from "node:fs";
|
|
120716
|
-
import { mkdir as
|
|
120717
|
-
import { join as
|
|
120718
|
-
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");
|
|
120719
120629
|
function handoffNoteDir(projectId) {
|
|
120720
120630
|
if (!isProjectId(projectId)) {
|
|
120721
120631
|
throw rpcError(`Not a project id: ${projectId}`);
|
|
120722
120632
|
}
|
|
120723
|
-
return
|
|
120633
|
+
return join30(root(), projectId);
|
|
120724
120634
|
}
|
|
120725
120635
|
function handoffNotePath(projectId, sessionId) {
|
|
120726
120636
|
if (!isSessionId(sessionId)) {
|
|
120727
120637
|
throw rpcError(`Not a session id: ${sessionId}`);
|
|
120728
120638
|
}
|
|
120729
|
-
return
|
|
120639
|
+
return join30(handoffNoteDir(projectId), `${sessionId}.md`);
|
|
120730
120640
|
}
|
|
120731
120641
|
async function handoffNoteBytes(projectId, sessionId) {
|
|
120732
120642
|
return dataBytes(handoffNotePath(projectId, sessionId));
|
|
120733
120643
|
}
|
|
120734
120644
|
async function writeHandoffNote(projectId, sessionId, text3) {
|
|
120735
120645
|
const path2 = handoffNotePath(projectId, sessionId);
|
|
120736
|
-
await
|
|
120646
|
+
await mkdir4(handoffNoteDir(projectId), { recursive: true });
|
|
120737
120647
|
await removeData(path2);
|
|
120738
120648
|
await writeFile4(path2, text3, "utf8");
|
|
120739
120649
|
return path2;
|
|
@@ -120748,7 +120658,7 @@ function writeHandoffNoteSync(projectId, sessionId, text3) {
|
|
|
120748
120658
|
async function sweepHandoffNotes(owned, projectId) {
|
|
120749
120659
|
let dirs;
|
|
120750
120660
|
try {
|
|
120751
|
-
dirs = projectId ? [projectId] : (await
|
|
120661
|
+
dirs = projectId ? [projectId] : (await readdir7(root(), { withFileTypes: true })).filter((d2) => d2.isDirectory()).map((d2) => d2.name);
|
|
120752
120662
|
} catch {
|
|
120753
120663
|
return;
|
|
120754
120664
|
}
|
|
@@ -120759,12 +120669,12 @@ async function sweepHandoffNotes(owned, projectId) {
|
|
|
120759
120669
|
} catch {
|
|
120760
120670
|
continue;
|
|
120761
120671
|
}
|
|
120762
|
-
const entries = await
|
|
120672
|
+
const entries = await readdir7(dir, { withFileTypes: true }).catch(() => []);
|
|
120763
120673
|
for (const e of entries) {
|
|
120764
120674
|
if (!e.isFile() || !e.name.endsWith(".md")) continue;
|
|
120765
120675
|
const owner = e.name.slice(0, -".md".length);
|
|
120766
120676
|
if (owned(owner)) continue;
|
|
120767
|
-
await removeData(
|
|
120677
|
+
await removeData(join30(dir, e.name)).catch(() => {
|
|
120768
120678
|
});
|
|
120769
120679
|
}
|
|
120770
120680
|
}
|
|
@@ -121205,11 +121115,11 @@ ${note}` : note;
|
|
|
121205
121115
|
};
|
|
121206
121116
|
|
|
121207
121117
|
// packages/agent-host/src/mail/ids.ts
|
|
121208
|
-
import { randomBytes as
|
|
121118
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
121209
121119
|
var CROCKFORD = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
121210
121120
|
var ID_RE = /^([a-z0-9][a-z0-9-]*)\.(t|m)_([0-9A-HJKMNP-TV-Z]{26})$/;
|
|
121211
121121
|
var UlidMaker = class {
|
|
121212
|
-
constructor(random =
|
|
121122
|
+
constructor(random = randomBytes7) {
|
|
121213
121123
|
this.random = random;
|
|
121214
121124
|
}
|
|
121215
121125
|
random;
|
|
@@ -125571,7 +125481,7 @@ var SelfCompaction = class {
|
|
|
125571
125481
|
/** What one kept step asks of the host that finds it (`recover`) */
|
|
125572
125482
|
resume(m, rec) {
|
|
125573
125483
|
const id3 = m.id;
|
|
125574
|
-
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`);
|
|
125575
125485
|
if (rec.stage === "compacted" || rec.stage === "refused") {
|
|
125576
125486
|
if (this.host.ready(id3) && this.queuedNow(id3) !== true) void this.sendThen(id3, rec);
|
|
125577
125487
|
else this.keepHeld(id3, rec);
|
|
@@ -126088,16 +125998,16 @@ async function* readLines(stream) {
|
|
|
126088
125998
|
|
|
126089
125999
|
// packages/agent-host/src/adapters/frames/recorder.ts
|
|
126090
126000
|
import { appendFileSync as appendFileSync2, existsSync as existsSync16, mkdirSync as mkdirSync18 } from "node:fs";
|
|
126091
|
-
import { join as
|
|
126001
|
+
import { join as join31 } from "node:path";
|
|
126092
126002
|
var processes = /* @__PURE__ */ new Map();
|
|
126093
126003
|
function frameRecorder(sessionId, env = process.env) {
|
|
126094
126004
|
const dir = env.CC_RECORD_FRAMES;
|
|
126095
126005
|
if (!dir) return void 0;
|
|
126096
126006
|
mkdirSync18(dir, { recursive: true });
|
|
126097
126007
|
let n = (processes.get(sessionId) ?? 0) + 1;
|
|
126098
|
-
while (existsSync16(
|
|
126008
|
+
while (existsSync16(join31(dir, `${sessionId}.${n}.jsonl`))) n++;
|
|
126099
126009
|
processes.set(sessionId, n);
|
|
126100
|
-
const file2 =
|
|
126010
|
+
const file2 = join31(dir, `${sessionId}.${n}.jsonl`);
|
|
126101
126011
|
const start3 = Date.now();
|
|
126102
126012
|
const write = (entry) => {
|
|
126103
126013
|
try {
|
|
@@ -126546,7 +126456,7 @@ var CoreSession = class {
|
|
|
126546
126456
|
};
|
|
126547
126457
|
|
|
126548
126458
|
// packages/agent-host/src/adapters/acp/session.ts
|
|
126549
|
-
import { isAbsolute as isAbsolute6, join as
|
|
126459
|
+
import { isAbsolute as isAbsolute6, join as join32 } from "node:path";
|
|
126550
126460
|
|
|
126551
126461
|
// packages/agent-host/src/adapters/always-allow.ts
|
|
126552
126462
|
var AlwaysAllowRules = class {
|
|
@@ -126688,7 +126598,7 @@ var UnmappedTypes = class {
|
|
|
126688
126598
|
};
|
|
126689
126599
|
|
|
126690
126600
|
// packages/agent-host/src/adapters/acp/connection.ts
|
|
126691
|
-
import { randomBytes as
|
|
126601
|
+
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
126692
126602
|
var RpcError = class extends Error {
|
|
126693
126603
|
constructor(code2, message, data) {
|
|
126694
126604
|
super(message);
|
|
@@ -126733,7 +126643,7 @@ var AcpConnection = class {
|
|
|
126733
126643
|
* String ids with a per-connection prefix: a host that adopts a process the previous host was talking to can
|
|
126734
126644
|
* receive answers to that host's requests (§4.4), and plain counters on both would have collided.
|
|
126735
126645
|
*/
|
|
126736
|
-
idPrefix = `c${
|
|
126646
|
+
idPrefix = `c${randomBytes8(3).toString("hex")}-`;
|
|
126737
126647
|
nextId = 1;
|
|
126738
126648
|
pending = new PendingRequests();
|
|
126739
126649
|
closed = false;
|
|
@@ -127008,7 +126918,7 @@ function centraluMark(server2, tool, args) {
|
|
|
127008
126918
|
function keepAttachedAppMarks(e, attached) {
|
|
127009
126919
|
const stray = (s) => {
|
|
127010
126920
|
if (!s.centralu?.app) return null;
|
|
127011
|
-
const server2 =
|
|
126921
|
+
const server2 = appServerName(s.centralu.app);
|
|
127012
126922
|
for (const a of attached()) if (a === server2) return null;
|
|
127013
126923
|
const { centralu: _gone, ...rest } = s;
|
|
127014
126924
|
return rest;
|
|
@@ -127936,7 +127846,7 @@ var AcpWire = class {
|
|
|
127936
127846
|
ownTool: Boolean(this.deps.centraluToolOf?.(call2)),
|
|
127937
127847
|
auto: this.preset === "auto",
|
|
127938
127848
|
alwaysAllowKey: alwaysAllowKey(detail),
|
|
127939
|
-
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
|
|
127940
127850
|
};
|
|
127941
127851
|
}
|
|
127942
127852
|
respondApproval(requestId, decision, matcher2) {
|
|
@@ -128091,17 +128001,17 @@ var ACP_CAPABILITIES = {
|
|
|
128091
128001
|
// packages/agent-host/src/adapters/antigravity/agent-files.ts
|
|
128092
128002
|
import { spawn as spawnChild } from "node:child_process";
|
|
128093
128003
|
import { createHash as createHash12 } from "node:crypto";
|
|
128094
|
-
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
|
|
128095
|
-
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";
|
|
128096
128006
|
import { homedir as homedir8 } from "node:os";
|
|
128097
|
-
import { dirname as dirname17, join as
|
|
128007
|
+
import { dirname as dirname17, join as join34, resolve as resolve13 } from "node:path";
|
|
128098
128008
|
import { Transform } from "node:stream";
|
|
128099
128009
|
import { pipeline } from "node:stream/promises";
|
|
128100
128010
|
import { createInflateRaw } from "node:zlib";
|
|
128101
128011
|
|
|
128102
128012
|
// packages/agent-host/src/dev-services/instance-lock.ts
|
|
128103
128013
|
import { readFileSync as readFileSync11, unlinkSync as unlinkSync3, writeFileSync as writeFileSync9 } from "node:fs";
|
|
128104
|
-
import { dirname as dirname16, join as
|
|
128014
|
+
import { dirname as dirname16, join as join33 } from "node:path";
|
|
128105
128015
|
import Database2 from "better-sqlite3";
|
|
128106
128016
|
var OWNERSHIP_FILE = "host-ownership.sqlite";
|
|
128107
128017
|
var held2 = /* @__PURE__ */ new Set();
|
|
@@ -128136,7 +128046,7 @@ function parseHolder(raw) {
|
|
|
128136
128046
|
function acquireInstanceLock(dbPath2, startOf = processStartTime, describe4 = {}, now = Date.now) {
|
|
128137
128047
|
if (dbPath2 === ":memory:") return { ok: true, release: () => {
|
|
128138
128048
|
} };
|
|
128139
|
-
const lockPath =
|
|
128049
|
+
const lockPath = join33(dirname16(dbPath2), "host.lock");
|
|
128140
128050
|
const readHolder = () => {
|
|
128141
128051
|
try {
|
|
128142
128052
|
return parseHolder(readFileSync11(lockPath, "utf8"));
|
|
@@ -128144,7 +128054,7 @@ function acquireInstanceLock(dbPath2, startOf = processStartTime, describe4 = {}
|
|
|
128144
128054
|
return null;
|
|
128145
128055
|
}
|
|
128146
128056
|
};
|
|
128147
|
-
const owner = takeOwnership(
|
|
128057
|
+
const owner = takeOwnership(join33(dirname16(dbPath2), OWNERSHIP_FILE));
|
|
128148
128058
|
if (!owner) {
|
|
128149
128059
|
const holder = readHolder();
|
|
128150
128060
|
const pid = holder && Number.isInteger(holder.pid) && holder.pid > 0 ? holder.pid : null;
|
|
@@ -128269,26 +128179,26 @@ function agyPlatformKey(platform = HOST_PLATFORM, arch = process.arch) {
|
|
|
128269
128179
|
return null;
|
|
128270
128180
|
}
|
|
128271
128181
|
function agyHome(dataDir, version2) {
|
|
128272
|
-
const root3 =
|
|
128273
|
-
return { root: root3, versionDir:
|
|
128182
|
+
const root3 = join34(dataDir, "tools", "antigravity");
|
|
128183
|
+
return { root: root3, versionDir: join34(root3, version2), geminiHome: join34(root3, "gemini-home") };
|
|
128274
128184
|
}
|
|
128275
128185
|
function agyProgram(home, archive) {
|
|
128276
|
-
return
|
|
128186
|
+
return join34(home.versionDir, archive.command);
|
|
128277
128187
|
}
|
|
128278
128188
|
var INSTALL_MARKER = "install.json";
|
|
128279
128189
|
function isInstalled(home, archive) {
|
|
128280
128190
|
try {
|
|
128281
|
-
const marker = asObj(JSON.parse(readFileSync12(
|
|
128191
|
+
const marker = asObj(JSON.parse(readFileSync12(join34(home.versionDir, INSTALL_MARKER), "utf8")));
|
|
128282
128192
|
if (marker.sha256 !== archive.sha256) return false;
|
|
128283
|
-
return archive.files.every((f) => existsSync18(
|
|
128193
|
+
return archive.files.every((f) => existsSync18(join34(home.versionDir, f)));
|
|
128284
128194
|
} catch {
|
|
128285
128195
|
return false;
|
|
128286
128196
|
}
|
|
128287
128197
|
}
|
|
128288
128198
|
function hasSignIn(home) {
|
|
128289
|
-
const dir =
|
|
128199
|
+
const dir = join34(home.geminiHome, "antigravity-acp");
|
|
128290
128200
|
try {
|
|
128291
|
-
const settings = asObj(JSON.parse(readFileSync12(
|
|
128201
|
+
const settings = asObj(JSON.parse(readFileSync12(join34(dir, "settings.json"), "utf8")));
|
|
128292
128202
|
const auth = asObj(settings.auth);
|
|
128293
128203
|
return typeof auth.type === "string" && auth.type.length > 0;
|
|
128294
128204
|
} catch {
|
|
@@ -128348,22 +128258,22 @@ async function installAgy(home, archive, version2, opts) {
|
|
|
128348
128258
|
const io2 = opts.io ?? realInstallIo;
|
|
128349
128259
|
const { signal } = opts;
|
|
128350
128260
|
if (isInstalled(home, archive)) return;
|
|
128351
|
-
await
|
|
128261
|
+
await mkdir5(home.root, { recursive: true });
|
|
128352
128262
|
await removeStale(home.root, ".install-");
|
|
128353
128263
|
const free = await io2.freeBytes(home.root);
|
|
128354
128264
|
if (free !== null && free < AGY_INSTALL_SPACE_BYTES) {
|
|
128355
128265
|
throw new InstallFailure("disk_space", `Antigravity needs about ${mb(AGY_INSTALL_SPACE_BYTES)} MB free to install; ${mb(free)} MB are free`);
|
|
128356
128266
|
}
|
|
128357
|
-
const work = await mkdtemp3(
|
|
128267
|
+
const work = await mkdtemp3(join34(home.root, `.install-${ownerTag()}-`));
|
|
128358
128268
|
try {
|
|
128359
|
-
const zip =
|
|
128269
|
+
const zip = join34(work, "archive.zip");
|
|
128360
128270
|
const sha = await download(io2, archive.url, zip, signal, opts.onProgress);
|
|
128361
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)`);
|
|
128362
128272
|
cancelled(signal);
|
|
128363
|
-
const pkg =
|
|
128273
|
+
const pkg = join34(work, "pkg");
|
|
128364
128274
|
await unpack(zip, archive, pkg, signal, opts.platform ?? HOST_PLATFORM);
|
|
128365
128275
|
await realOs().files.promises.rm(zip, { force: true });
|
|
128366
|
-
await writeFile5(
|
|
128276
|
+
await writeFile5(join34(pkg, INSTALL_MARKER), `${JSON.stringify({ version: version2, sha256: archive.sha256, url: archive.url })}
|
|
128367
128277
|
`);
|
|
128368
128278
|
cancelled(signal);
|
|
128369
128279
|
if (isInstalled(home, archive)) return;
|
|
@@ -128426,12 +128336,12 @@ async function unpack(zip, archive, dir, signal, platform) {
|
|
|
128426
128336
|
if (names.length !== want.length || names.some((n, i) => n !== want[i])) {
|
|
128427
128337
|
throw new InstallFailure("unpack", `The archive holds ${names.join(", ") || "nothing"}, not the files the release names (${want.join(", ")})`);
|
|
128428
128338
|
}
|
|
128429
|
-
await
|
|
128339
|
+
await mkdir5(dir, { recursive: true });
|
|
128430
128340
|
for (const e of entries) {
|
|
128431
128341
|
if (e.kind !== "file" || !/^[\w.-]+$/.test(e.name)) throw new InstallFailure("unpack", `The archive's entry ${e.name} is not a plain file`);
|
|
128432
128342
|
if (e.method !== 0 && e.method !== 8) throw new InstallFailure("unpack", `The archive's entry ${e.name} uses compression method ${e.method}`);
|
|
128433
128343
|
cancelled(signal);
|
|
128434
|
-
const path2 =
|
|
128344
|
+
const path2 = join34(dir, e.name);
|
|
128435
128345
|
await unpackEntry(zip, e, starts.get(e) ?? 0, path2, signal);
|
|
128436
128346
|
if (platform !== "win32") await chmod3(path2, 493);
|
|
128437
128347
|
}
|
|
@@ -128481,9 +128391,9 @@ async function removeLeftovers(home) {
|
|
|
128481
128391
|
await removeStale(home.root, ".sign-in-");
|
|
128482
128392
|
}
|
|
128483
128393
|
async function removeStale(root3, prefix) {
|
|
128484
|
-
const names = await
|
|
128394
|
+
const names = await readdir8(root3).catch(() => []);
|
|
128485
128395
|
const stale = names.filter((n) => n.startsWith(prefix) && ownerGone(n.slice(prefix.length)));
|
|
128486
|
-
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(() => {
|
|
128487
128397
|
})));
|
|
128488
128398
|
}
|
|
128489
128399
|
var ownStart;
|
|
@@ -128514,10 +128424,10 @@ function processAlive(pid) {
|
|
|
128514
128424
|
}
|
|
128515
128425
|
}
|
|
128516
128426
|
async function removeOtherVersions(home) {
|
|
128517
|
-
const names = await
|
|
128427
|
+
const names = await readdir8(home.root).catch(() => []);
|
|
128518
128428
|
for (const n of names) {
|
|
128519
128429
|
if (!/^\d+\.\d+\.\d+/.test(n)) continue;
|
|
128520
|
-
const dir =
|
|
128430
|
+
const dir = join34(home.root, n);
|
|
128521
128431
|
if (dir === home.versionDir) continue;
|
|
128522
128432
|
await realOs().files.promises.rm(dir, { recursive: true, force: true }).catch(() => {
|
|
128523
128433
|
});
|
|
@@ -128540,7 +128450,7 @@ async function folderFacts(spare) {
|
|
|
128540
128450
|
const folder = fact(spare, await lstat10(spare));
|
|
128541
128451
|
const above = [];
|
|
128542
128452
|
for (let p = await realpath7(dirname17(spare)); ; p = dirname17(p)) {
|
|
128543
|
-
above.push(fact(p, await
|
|
128453
|
+
above.push(fact(p, await stat7(p)));
|
|
128544
128454
|
if (dirname17(p) === p) break;
|
|
128545
128455
|
}
|
|
128546
128456
|
return { folder, above };
|
|
@@ -128559,9 +128469,9 @@ async function browserFolder(home, platform = HOST_PLATFORM, places = {}) {
|
|
|
128559
128469
|
const sep13 = platform === "win32" ? ";" : ":";
|
|
128560
128470
|
const nodeBad = platform === "win32" ? unusableIn(node, sep13) : "";
|
|
128561
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.`);
|
|
128562
|
-
await
|
|
128472
|
+
await mkdir5(home.root, { recursive: true });
|
|
128563
128473
|
await removeStale(home.root, ".sign-in-");
|
|
128564
|
-
let dir = resolve13(await mkdtemp3(
|
|
128474
|
+
let dir = resolve13(await mkdtemp3(join34(home.root, `.sign-in-${ownerTag()}-`)));
|
|
128565
128475
|
const dataBad = unusableIn(dir, sep13);
|
|
128566
128476
|
if (dataBad) {
|
|
128567
128477
|
await realOs().files.promises.rm(dir, { recursive: true, force: true }).catch(() => {
|
|
@@ -128569,15 +128479,15 @@ async function browserFolder(home, platform = HOST_PLATFORM, places = {}) {
|
|
|
128569
128479
|
const spare = resolve13(places.spare ?? spareFolder(platform));
|
|
128570
128480
|
const data = `Centralu's data folder is at ${home.root}, and Antigravity cannot be given a path with ${dataBad} in it`;
|
|
128571
128481
|
const move = "Move the data folder to a path without them.";
|
|
128572
|
-
const spareBad = unusableIn(
|
|
128482
|
+
const spareBad = unusableIn(join34(spare, ".sign-in-x"), sep13);
|
|
128573
128483
|
if (spareBad) return noHelper(`${data}; nor ${spareBad} in ${spare}, the folder Centralu tries instead. ${move}`);
|
|
128574
128484
|
try {
|
|
128575
|
-
await
|
|
128485
|
+
await mkdir5(spare, { recursive: true, mode: 448 });
|
|
128576
128486
|
const uid = platform === "win32" ? void 0 : process.getuid?.();
|
|
128577
128487
|
const notOwn = uid === void 0 ? "" : notOwnFolder(await folderFacts(spare), uid);
|
|
128578
128488
|
if (notOwn) return noHelper(`${data}, and ${spare}, the folder Centralu tries instead, ${notOwn}. ${move}`);
|
|
128579
128489
|
await removeStale(spare, ".sign-in-");
|
|
128580
|
-
dir = resolve13(await mkdtemp3(
|
|
128490
|
+
dir = resolve13(await mkdtemp3(join34(spare, `.sign-in-${ownerTag()}-`)));
|
|
128581
128491
|
} catch (err) {
|
|
128582
128492
|
const code2 = err instanceof Error ? Reflect.get(err, "code") : void 0;
|
|
128583
128493
|
return noHelper(`${data}, and ${spare}, the folder Centralu tries instead, could not be written to${typeof code2 === "string" ? ` (${code2})` : ""}. ${move}`);
|
|
@@ -128587,14 +128497,14 @@ async function browserFolder(home, platform = HOST_PLATFORM, places = {}) {
|
|
|
128587
128497
|
});
|
|
128588
128498
|
let browser;
|
|
128589
128499
|
if (platform === "win32") {
|
|
128590
|
-
const script =
|
|
128500
|
+
const script = join34(dir, "open-url.mjs");
|
|
128591
128501
|
await writeFile5(script, WINDOWS_HELPER);
|
|
128592
128502
|
browser = windowsBrowserCommand(node, script);
|
|
128593
128503
|
} else {
|
|
128594
|
-
const helper =
|
|
128595
|
-
const part = `${shQuote(
|
|
128504
|
+
const helper = join34(dir, "open-url");
|
|
128505
|
+
const part = `${shQuote(join34(dir, "part-"))}"$$"`;
|
|
128596
128506
|
await writeFile5(helper, `#!/bin/sh
|
|
128597
|
-
printf '%s\\n' "$1" > ${part} && mv ${part} ${shQuote(
|
|
128507
|
+
printf '%s\\n' "$1" > ${part} && mv ${part} ${shQuote(join34(dir, "url-"))}"$$"
|
|
128598
128508
|
exit 0
|
|
128599
128509
|
`, { mode: 448 });
|
|
128600
128510
|
await chmod3(helper, 448);
|
|
@@ -128620,8 +128530,8 @@ exit 0
|
|
|
128620
128530
|
}
|
|
128621
128531
|
for (const name of names) {
|
|
128622
128532
|
taken.add(name);
|
|
128623
|
-
const path2 =
|
|
128624
|
-
void
|
|
128533
|
+
const path2 = join34(dir, name);
|
|
128534
|
+
void readFile4(path2, "utf8").then(
|
|
128625
128535
|
async (text3) => {
|
|
128626
128536
|
await realOs().files.promises.rm(path2, { force: true }).catch(() => {
|
|
128627
128537
|
});
|
|
@@ -128633,7 +128543,7 @@ exit 0
|
|
|
128633
128543
|
}
|
|
128634
128544
|
};
|
|
128635
128545
|
try {
|
|
128636
|
-
watcher =
|
|
128546
|
+
watcher = watch3(dir, () => look());
|
|
128637
128547
|
watcher.on("error", () => {
|
|
128638
128548
|
});
|
|
128639
128549
|
} catch {
|
|
@@ -129164,8 +129074,8 @@ var AntigravityAdapter = class extends AcpAdapter {
|
|
|
129164
129074
|
|
|
129165
129075
|
// packages/agent-host/src/adapters/claude/index.ts
|
|
129166
129076
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
129167
|
-
import { mkdtemp as mkdtemp4, readdir as
|
|
129168
|
-
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";
|
|
129169
129079
|
import { randomUUID as randomUUID22 } from "node:crypto";
|
|
129170
129080
|
|
|
129171
129081
|
// packages/agent-host/src/cli-version.ts
|
|
@@ -129323,14 +129233,16 @@ function parseQuestions(input) {
|
|
|
129323
129233
|
}
|
|
129324
129234
|
return out;
|
|
129325
129235
|
}
|
|
129236
|
+
function ownServerTool(toolName) {
|
|
129237
|
+
const parts = mcpNameParts(toolName);
|
|
129238
|
+
return parts && !parts.tool.includes("__") ? parts : null;
|
|
129239
|
+
}
|
|
129326
129240
|
function isCentraluToolName(toolName) {
|
|
129327
|
-
|
|
129328
|
-
return parts.length === 3 && parts[0] === "mcp" && parts[1] === CENTRALU_MCP_NAME;
|
|
129241
|
+
return ownServerTool(toolName)?.server === CENTRALU_MCP_NAME;
|
|
129329
129242
|
}
|
|
129330
129243
|
function appToolOf(toolName) {
|
|
129331
|
-
const parts = toolName
|
|
129332
|
-
|
|
129333
|
-
return { server: parts[1], tool: parts[2] };
|
|
129244
|
+
const parts = ownServerTool(toolName);
|
|
129245
|
+
return parts?.server.startsWith(APP_SERVER_PREFIX) ? parts : null;
|
|
129334
129246
|
}
|
|
129335
129247
|
var READ_TOOLS2 = /* @__PURE__ */ new Set(["Read", "Glob", "Grep"]);
|
|
129336
129248
|
function readTarget(toolName, input) {
|
|
@@ -129531,10 +129443,10 @@ function claudeQueryOptions({ sessionId, opts, executablePath, servers, permissi
|
|
|
129531
129443
|
}
|
|
129532
129444
|
|
|
129533
129445
|
// packages/agent-host/src/adapters/claude/exe-link.ts
|
|
129534
|
-
import { randomBytes as
|
|
129446
|
+
import { randomBytes as randomBytes9 } from "node:crypto";
|
|
129535
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";
|
|
129536
129448
|
import { createRequire } from "node:module";
|
|
129537
|
-
import { basename as
|
|
129449
|
+
import { basename as basename11, dirname as dirname21, join as join39 } from "node:path";
|
|
129538
129450
|
var PLACEHOLDER_MAX_BYTES = 1e6;
|
|
129539
129451
|
var INSTALLER_TIMEOUT_MS = 3e4;
|
|
129540
129452
|
var VERSION_TIMEOUT_MS = 1e4;
|
|
@@ -129547,7 +129459,7 @@ async function runNode(file2, args, cwd, timeoutMs) {
|
|
|
129547
129459
|
return { status: 0, output: `${r.stdout}${r.stderr}`.trim() };
|
|
129548
129460
|
} catch (e) {
|
|
129549
129461
|
if (isExecFailure(e)) {
|
|
129550
|
-
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)}` };
|
|
129551
129463
|
return { status: e.code, output: `${e.stdout}${e.stderr}`.trim() };
|
|
129552
129464
|
}
|
|
129553
129465
|
return { status: null, output: e instanceof Error ? e.message : String(e) };
|
|
@@ -129581,7 +129493,7 @@ var realExeFs = {
|
|
|
129581
129493
|
nativeSize: (installer) => {
|
|
129582
129494
|
try {
|
|
129583
129495
|
const pkg = createRequire(installer).resolve(`@anthropic-ai/claude-code-win32-${process.arch}/package.json`);
|
|
129584
|
-
return statSync16(
|
|
129496
|
+
return statSync16(join39(dirname21(pkg), "claude.exe")).size;
|
|
129585
129497
|
} catch {
|
|
129586
129498
|
return null;
|
|
129587
129499
|
}
|
|
@@ -129589,8 +129501,8 @@ var realExeFs = {
|
|
|
129589
129501
|
runProgram: async (path2, args, timeoutMs) => ({ status: (await runNode(path2, args, void 0, timeoutMs)).status })
|
|
129590
129502
|
};
|
|
129591
129503
|
function installerFor(exe, fs3 = realExeFs) {
|
|
129592
|
-
if (
|
|
129593
|
-
const installer =
|
|
129504
|
+
if (basename11(dirname21(exe)).toLowerCase() !== "bin") return null;
|
|
129505
|
+
const installer = join39(dirname21(dirname21(exe)), "install.cjs");
|
|
129594
129506
|
try {
|
|
129595
129507
|
fs3.stat(installer);
|
|
129596
129508
|
return installer;
|
|
@@ -129623,7 +129535,7 @@ function unprovenProblem(exe, size2, why2, tried, installer) {
|
|
|
129623
129535
|
function claudeKey(exe, stat13, fs3 = realExeFs) {
|
|
129624
129536
|
let version2 = null;
|
|
129625
129537
|
try {
|
|
129626
|
-
const pkg = JSON.parse(fs3.read(
|
|
129538
|
+
const pkg = JSON.parse(fs3.read(join39(dirname21(dirname21(exe)), "package.json")));
|
|
129627
129539
|
if (pkg.name === "@anthropic-ai/claude-code" && typeof pkg.version === "string" && pkg.version) version2 = pkg.version;
|
|
129628
129540
|
} catch {
|
|
129629
129541
|
}
|
|
@@ -129653,7 +129565,7 @@ var ClaudeLinks = class {
|
|
|
129653
129565
|
return windowsStart(this.opts.platform);
|
|
129654
129566
|
}
|
|
129655
129567
|
base() {
|
|
129656
|
-
return
|
|
129568
|
+
return join39(this.opts.root(), "tools", "claude");
|
|
129657
129569
|
}
|
|
129658
129570
|
/**
|
|
129659
129571
|
* `prepare`, after repairing npm's placeholder if that is what `exe` is. Every start path awaits this,
|
|
@@ -129685,8 +129597,8 @@ var ClaudeLinks = class {
|
|
|
129685
129597
|
if (!problem3 && installer && outcome && bad && bad.size === stat13.size && bad.mtimeMs === stat13.mtimeMs) problem3 = unprovenProblem(exe, stat13.size, bad.why, outcome.note, installer);
|
|
129686
129598
|
if (problem3) throw new ClaudePlaceholderError(problem3);
|
|
129687
129599
|
const key = claudeKey(exe, stat13, this.fs);
|
|
129688
|
-
const dir =
|
|
129689
|
-
const target =
|
|
129600
|
+
const dir = join39(this.base(), key);
|
|
129601
|
+
const target = join39(dir, "claude.exe");
|
|
129690
129602
|
const ready = () => {
|
|
129691
129603
|
try {
|
|
129692
129604
|
return this.fs.stat(target).size === stat13.size;
|
|
@@ -129695,7 +129607,7 @@ var ClaudeLinks = class {
|
|
|
129695
129607
|
}
|
|
129696
129608
|
};
|
|
129697
129609
|
if (ready()) return this.use(key, target);
|
|
129698
|
-
const tmp =
|
|
129610
|
+
const tmp = join39(dir, `claude-${randomBytes9(4).toString("hex")}.tmp`);
|
|
129699
129611
|
try {
|
|
129700
129612
|
this.fs.mkdir(dir);
|
|
129701
129613
|
try {
|
|
@@ -129823,7 +129735,7 @@ var ClaudeLinks = class {
|
|
|
129823
129735
|
for (const name of names) {
|
|
129824
129736
|
if (name === this.current || this.uses.has(name)) continue;
|
|
129825
129737
|
try {
|
|
129826
|
-
this.fs.removeDir(
|
|
129738
|
+
this.fs.removeDir(join39(this.base(), name));
|
|
129827
129739
|
} catch {
|
|
129828
129740
|
}
|
|
129829
129741
|
}
|
|
@@ -129964,7 +129876,7 @@ function contentBlocks(m) {
|
|
|
129964
129876
|
}
|
|
129965
129877
|
|
|
129966
129878
|
// packages/agent-host/src/adapters/images.ts
|
|
129967
|
-
import { readFile as
|
|
129879
|
+
import { readFile as readFile6, stat as stat9 } from "node:fs/promises";
|
|
129968
129880
|
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set(["png", "jpg", "jpeg", "gif", "webp", "bmp"]);
|
|
129969
129881
|
var startsWith = (buf, bytes2, at2 = 0) => bytes2.every((b2, i) => buf[at2 + i] === b2);
|
|
129970
129882
|
function gifReachesTrailer(buf) {
|
|
@@ -130045,9 +129957,9 @@ async function imageEventFromDisk(sessionId, path2, maxBytes = IMAGE_MAX_BYTES)
|
|
|
130045
129957
|
const file2 = path2.split(/[\\/]/).pop() ?? path2;
|
|
130046
129958
|
const ext2 = file2.includes(".") ? file2.slice(file2.lastIndexOf(".") + 1).toLowerCase() : "";
|
|
130047
129959
|
try {
|
|
130048
|
-
const s = await
|
|
129960
|
+
const s = await stat9(path2);
|
|
130049
129961
|
if (s.size > maxBytes) return fail4(tooLarge(s.size));
|
|
130050
|
-
const buf = await
|
|
129962
|
+
const buf = await readFile6(path2);
|
|
130051
129963
|
const seen = judgeImage(buf);
|
|
130052
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`);
|
|
130053
129965
|
if ("note" in seen) return fail4(seen.note);
|
|
@@ -131495,16 +131407,16 @@ var ClaudeStreamNormalizer = class {
|
|
|
131495
131407
|
|
|
131496
131408
|
// packages/agent-host/src/adapters/claude/lsp-plugins.ts
|
|
131497
131409
|
init_sdk();
|
|
131498
|
-
import { access as access3, readFile as
|
|
131410
|
+
import { access as access3, readFile as readFile7 } from "node:fs/promises";
|
|
131499
131411
|
import { homedir as homedir10 } from "node:os";
|
|
131500
|
-
import { join as
|
|
131412
|
+
import { join as join40 } from "node:path";
|
|
131501
131413
|
var KNOWN_LSP_PLUGINS = ["typescript-lsp@claude-plugins-official"];
|
|
131502
131414
|
function claudeConfigDir(env = process.env, home = homedir10()) {
|
|
131503
|
-
return env.CLAUDE_CONFIG_DIR ||
|
|
131415
|
+
return env.CLAUDE_CONFIG_DIR || join40(home, ".claude");
|
|
131504
131416
|
}
|
|
131505
131417
|
async function readJson2(path2) {
|
|
131506
131418
|
try {
|
|
131507
|
-
return JSON.parse(await
|
|
131419
|
+
return JSON.parse(await readFile7(path2, "utf8"));
|
|
131508
131420
|
} catch {
|
|
131509
131421
|
return void 0;
|
|
131510
131422
|
}
|
|
@@ -131515,22 +131427,22 @@ async function declaresLspServers(id3, configDir) {
|
|
|
131515
131427
|
if (at2 <= 0) return false;
|
|
131516
131428
|
const name = id3.slice(0, at2);
|
|
131517
131429
|
const marketplace = id3.slice(at2 + 1);
|
|
131518
|
-
const installed = await readJson2(
|
|
131430
|
+
const installed = await readJson2(join40(configDir, "plugins", "installed_plugins.json"));
|
|
131519
131431
|
const entries = isObj(installed) && isObj(installed.plugins) ? installed.plugins[id3] : void 0;
|
|
131520
131432
|
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
131521
131433
|
const path2 = isObj(entry) && typeof entry.installPath === "string" ? entry.installPath : null;
|
|
131522
131434
|
if (!path2) continue;
|
|
131523
|
-
if (declares(await readJson2(
|
|
131435
|
+
if (declares(await readJson2(join40(path2, ".claude-plugin", "plugin.json")))) return true;
|
|
131524
131436
|
try {
|
|
131525
|
-
await access3(
|
|
131437
|
+
await access3(join40(path2, ".lsp.json"));
|
|
131526
131438
|
return true;
|
|
131527
131439
|
} catch {
|
|
131528
131440
|
}
|
|
131529
131441
|
}
|
|
131530
|
-
const known = await readJson2(
|
|
131442
|
+
const known = await readJson2(join40(configDir, "plugins", "known_marketplaces.json"));
|
|
131531
131443
|
const place = isObj(known) && isObj(known[marketplace]) ? known[marketplace].installLocation : void 0;
|
|
131532
131444
|
if (typeof place !== "string") return false;
|
|
131533
|
-
const listing = await readJson2(
|
|
131445
|
+
const listing = await readJson2(join40(place, ".claude-plugin", "marketplace.json"));
|
|
131534
131446
|
const plugins = isObj(listing) && Array.isArray(listing.plugins) ? listing.plugins : [];
|
|
131535
131447
|
return plugins.some((p) => isObj(p) && p.name === name && declares(p));
|
|
131536
131448
|
}
|
|
@@ -131895,8 +131807,8 @@ var MidTurnLedger = class {
|
|
|
131895
131807
|
import { resolve as resolve18 } from "node:path";
|
|
131896
131808
|
|
|
131897
131809
|
// packages/agent-host/src/adapters/claude/new-file.ts
|
|
131898
|
-
import { stat as
|
|
131899
|
-
async function newFile(path2, statOf =
|
|
131810
|
+
import { stat as stat10 } from "node:fs/promises";
|
|
131811
|
+
async function newFile(path2, statOf = stat10) {
|
|
131900
131812
|
const found = statOf(path2).then(
|
|
131901
131813
|
() => false,
|
|
131902
131814
|
(err) => err.code === "ENOENT" ? true : void 0
|
|
@@ -132439,7 +132351,7 @@ function tracksInputs(m) {
|
|
|
132439
132351
|
|
|
132440
132352
|
// packages/agent-host/src/adapters/claude/surface.ts
|
|
132441
132353
|
import { readFileSync as readFileSync16 } from "node:fs";
|
|
132442
|
-
import { join as
|
|
132354
|
+
import { join as join41 } from "node:path";
|
|
132443
132355
|
|
|
132444
132356
|
// packages/agent-host/src/adapters/surface-drift.ts
|
|
132445
132357
|
function compareSurface(surface, limitations, baseline) {
|
|
@@ -132932,8 +132844,8 @@ var CLAUDE_SURFACE = {
|
|
|
132932
132844
|
async gather(env) {
|
|
132933
132845
|
const sdk = await env.packageDir(SDK);
|
|
132934
132846
|
return {
|
|
132935
|
-
"package.json": readFileSync16(
|
|
132936
|
-
"sdk.d.ts": readFileSync16(
|
|
132847
|
+
"package.json": readFileSync16(join41(sdk, "package.json"), "utf8"),
|
|
132848
|
+
"sdk.d.ts": readFileSync16(join41(sdk, "sdk.d.ts"), "utf8"),
|
|
132937
132849
|
"claude --version": await env.run("claude", ["--version"]),
|
|
132938
132850
|
"claude --help": await env.run("claude", ["--help"])
|
|
132939
132851
|
};
|
|
@@ -133649,10 +133561,10 @@ async function claudeLoggedIn(bin) {
|
|
|
133649
133561
|
async function sweepProbeDirs(now = Date.now()) {
|
|
133650
133562
|
try {
|
|
133651
133563
|
const root3 = tmpdir4();
|
|
133652
|
-
for (const name of await
|
|
133564
|
+
for (const name of await readdir11(root3)) {
|
|
133653
133565
|
if (!name.startsWith(PROBE_DIR_PREFIX)) continue;
|
|
133654
|
-
const path2 =
|
|
133655
|
-
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);
|
|
133656
133568
|
if (old) await realOs().files.promises.rm(path2, { recursive: true, force: true }).catch(() => {
|
|
133657
133569
|
});
|
|
133658
133570
|
}
|
|
@@ -133844,7 +133756,7 @@ var ClaudeAdapter = class _ClaudeAdapter {
|
|
|
133844
133756
|
this.swept = true;
|
|
133845
133757
|
await sweepProbeDirs();
|
|
133846
133758
|
}
|
|
133847
|
-
const dir = await mkdtemp4(
|
|
133759
|
+
const dir = await mkdtemp4(join42(tmpdir4(), PROBE_DIR_PREFIX));
|
|
133848
133760
|
const sessionId = `usage-probe-${randomUUID22()}`;
|
|
133849
133761
|
_ClaudeAdapter.probeIds.add(sessionId);
|
|
133850
133762
|
let probe = null;
|
|
@@ -133929,10 +133841,10 @@ var ClaudeAdapter = class _ClaudeAdapter {
|
|
|
133929
133841
|
|
|
133930
133842
|
// packages/agent-host/src/adapters/codex/index.ts
|
|
133931
133843
|
import { existsSync as existsSync21 } from "node:fs";
|
|
133932
|
-
import { join as
|
|
133844
|
+
import { join as join46 } from "node:path";
|
|
133933
133845
|
|
|
133934
133846
|
// packages/agent-host/src/adapters/codex/client.ts
|
|
133935
|
-
import { randomBytes as
|
|
133847
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
133936
133848
|
|
|
133937
133849
|
// packages/agent-host/src/adapters/codex/native.ts
|
|
133938
133850
|
import { existsSync as existsSync20, readFileSync as readFileSync17, realpathSync as realpathSync8 } from "node:fs";
|
|
@@ -134061,7 +133973,7 @@ var CodexClient = class {
|
|
|
134061
133973
|
* with plain counters both hosts would have sent `1`, `2`, … and an old answer would resolve a new
|
|
134062
133974
|
* request. codex echoes string ids back as given.
|
|
134063
133975
|
*/
|
|
134064
|
-
idPrefix = `${
|
|
133976
|
+
idPrefix = `${randomBytes10(3).toString("hex")}-`;
|
|
134065
133977
|
pending = new PendingRequests();
|
|
134066
133978
|
closed = false;
|
|
134067
133979
|
/** A flag to call onExit only once (both 'error' and 'exit' can fire) */
|
|
@@ -134146,24 +134058,24 @@ async function withCodexClient(opts, fn2) {
|
|
|
134146
134058
|
|
|
134147
134059
|
// packages/agent-host/src/adapters/codex/home.ts
|
|
134148
134060
|
import { homedir as homedir11 } from "node:os";
|
|
134149
|
-
import { join as
|
|
134061
|
+
import { join as join43 } from "node:path";
|
|
134150
134062
|
function codexHome(env = process.env, home = homedir11()) {
|
|
134151
134063
|
const custom2 = env.CODEX_HOME?.trim();
|
|
134152
|
-
return custom2 ? custom2 :
|
|
134064
|
+
return custom2 ? custom2 : join43(home, ".codex");
|
|
134153
134065
|
}
|
|
134154
134066
|
|
|
134155
134067
|
// packages/agent-host/src/adapters/codex/rollout.ts
|
|
134156
134068
|
import { createReadStream as createReadStream5 } from "node:fs";
|
|
134157
|
-
import { readdir as
|
|
134158
|
-
import { join as
|
|
134069
|
+
import { readdir as readdir12 } from "node:fs/promises";
|
|
134070
|
+
import { join as join44 } from "node:path";
|
|
134159
134071
|
var MIN_SUMMARY_CHARS = 200;
|
|
134160
|
-
async function findRolloutPath(threadId, sessionsDir =
|
|
134072
|
+
async function findRolloutPath(threadId, sessionsDir = join44(codexHome(), "sessions")) {
|
|
134161
134073
|
try {
|
|
134162
134074
|
const suffix = `-${threadId}.jsonl`;
|
|
134163
|
-
const names = await
|
|
134075
|
+
const names = await readdir12(sessionsDir, { recursive: true });
|
|
134164
134076
|
const hits = names.filter((n) => String(n).endsWith(suffix)).sort();
|
|
134165
134077
|
const hit = hits[hits.length - 1];
|
|
134166
|
-
return hit ?
|
|
134078
|
+
return hit ? join44(sessionsDir, String(hit)) : null;
|
|
134167
134079
|
} catch {
|
|
134168
134080
|
return null;
|
|
134169
134081
|
}
|
|
@@ -136158,7 +136070,7 @@ function watchBackgroundResume(host) {
|
|
|
136158
136070
|
sessionId: host.sessionId,
|
|
136159
136071
|
error: {
|
|
136160
136072
|
code: "adapter_crashed",
|
|
136161
|
-
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()}`,
|
|
136162
136074
|
retryable: true
|
|
136163
136075
|
}
|
|
136164
136076
|
});
|
|
@@ -136659,7 +136571,7 @@ var CodexSession = class {
|
|
|
136659
136571
|
|
|
136660
136572
|
// packages/agent-host/src/adapters/codex/surface.ts
|
|
136661
136573
|
import { readFileSync as readFileSync18 } from "node:fs";
|
|
136662
|
-
import { join as
|
|
136574
|
+
import { join as join45 } from "node:path";
|
|
136663
136575
|
|
|
136664
136576
|
// packages/agent-host/src/adapters/codex/surface-baseline.ts
|
|
136665
136577
|
var SURFACE_BASELINE2 = {
|
|
@@ -136977,7 +136889,7 @@ var CODEX_SURFACE = {
|
|
|
136977
136889
|
"codex --version": await env.run("codex", ["--version"]),
|
|
136978
136890
|
"codex --help": await env.run("codex", ["--help"])
|
|
136979
136891
|
};
|
|
136980
|
-
for (const f of FILES) inputs[f] = readFileSync18(
|
|
136892
|
+
for (const f of FILES) inputs[f] = readFileSync18(join45(out, f), "utf8");
|
|
136981
136893
|
return inputs;
|
|
136982
136894
|
},
|
|
136983
136895
|
read: readCodexSurface,
|
|
@@ -137045,7 +136957,7 @@ var CodexAdapter = class {
|
|
|
137045
136957
|
const launch2 = launchFor2(path2 ?? toolCommand("codex"));
|
|
137046
136958
|
const { stdout } = await execText(launch2.command, [...launch2.args, "--version"], { timeoutMs: 5e3 });
|
|
137047
136959
|
const version2 = `${stdout.trim()} \xB7 ${path2 ?? "PATH"}`;
|
|
137048
|
-
const loggedIn = existsSync21(
|
|
136960
|
+
const loggedIn = existsSync21(join46(codexHome(), "auth.json"));
|
|
137049
136961
|
return {
|
|
137050
136962
|
tool: "codex",
|
|
137051
136963
|
installed: true,
|
|
@@ -137149,7 +137061,7 @@ var CodexAdapter = class {
|
|
|
137149
137061
|
|
|
137150
137062
|
// packages/agent-host/src/adapters/cursor-agent/install.ts
|
|
137151
137063
|
import { existsSync as existsSync22, readdirSync as readdirSync14, realpathSync as realpathSync10 } from "node:fs";
|
|
137152
|
-
import { dirname as dirname23, join as
|
|
137064
|
+
import { dirname as dirname23, join as join47, win32 as win327 } from "node:path";
|
|
137153
137065
|
var realFs = {
|
|
137154
137066
|
exists: existsSync22,
|
|
137155
137067
|
list: (dir) => {
|
|
@@ -137201,14 +137113,14 @@ function findCursor(env = process.env, platform, fs3 = realFs) {
|
|
|
137201
137113
|
const real3 = fs3.real(found);
|
|
137202
137114
|
const dir = dirname23(real3);
|
|
137203
137115
|
const version2 = dir.split(/[\\/]/).pop() ?? "";
|
|
137204
|
-
if (VERSION.test(version2) && fs3.exists(
|
|
137116
|
+
if (VERSION.test(version2) && fs3.exists(join47(dir, "index.js"))) return { version: version2, command: real3, args: [], env: {} };
|
|
137205
137117
|
}
|
|
137206
137118
|
return null;
|
|
137207
137119
|
}
|
|
137208
137120
|
|
|
137209
137121
|
// packages/agent-host/src/adapters/cursor-agent/surface.ts
|
|
137210
137122
|
import { readdirSync as readdirSync15, readFileSync as readFileSync19 } from "node:fs";
|
|
137211
|
-
import { dirname as dirname24, join as
|
|
137123
|
+
import { dirname as dirname24, join as join48 } from "node:path";
|
|
137212
137124
|
|
|
137213
137125
|
// packages/agent-host/src/adapters/cursor-agent/surface-baseline.ts
|
|
137214
137126
|
var SURFACE_BASELINE3 = {
|
|
@@ -137276,7 +137188,7 @@ async function gather2() {
|
|
|
137276
137188
|
const dir = dirname24(install.args[0] ?? install.command);
|
|
137277
137189
|
const names = /* @__PURE__ */ new Set();
|
|
137278
137190
|
for (const f of readdirSync15(dir).filter((n) => n.endsWith(".js"))) {
|
|
137279
|
-
const text3 = readFileSync19(
|
|
137191
|
+
const text3 = readFileSync19(join48(dir, f), "utf8");
|
|
137280
137192
|
if (!text3.includes("session/request_permission") && !text3.includes("cursor_login")) continue;
|
|
137281
137193
|
for (const m of text3.matchAll(/sessionUpdate:"([a-z_]+)"|"(cursor\/[a-z_]+)"/g)) {
|
|
137282
137194
|
const name = m[1] ?? m[2];
|
|
@@ -137387,16 +137299,8 @@ function softRead(o) {
|
|
|
137387
137299
|
const run2 = start3();
|
|
137388
137300
|
const held3 = value && (o.staleOk?.(value.v) ?? true) ? { v: value.v } : null;
|
|
137389
137301
|
if (held3 && !ask.settle) return { value: held3.v, provisional: true };
|
|
137390
|
-
|
|
137391
|
-
|
|
137392
|
-
timer = setTimeout(() => resolve21({ value: held3 ? held3.v : o.fallback(), provisional: true }), ask.settle ? o.settleMs ?? 2e4 : o.softMs);
|
|
137393
|
-
timer.unref?.();
|
|
137394
|
-
});
|
|
137395
|
-
try {
|
|
137396
|
-
return await Promise.race([run2.then((v) => ({ value: v, provisional: false })), soft]);
|
|
137397
|
-
} finally {
|
|
137398
|
-
clearTimeout(timer);
|
|
137399
|
-
}
|
|
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);
|
|
137400
137304
|
};
|
|
137401
137305
|
}
|
|
137402
137306
|
function localUsageReader(o) {
|
|
@@ -137485,10 +137389,10 @@ function cursorRefusalIn(answer) {
|
|
|
137485
137389
|
var STATUS_FOR_MS = 6e4;
|
|
137486
137390
|
function cursorProfile() {
|
|
137487
137391
|
let status = null;
|
|
137488
|
-
const localUsage = cursorUsageReader(async (
|
|
137392
|
+
const localUsage = cursorUsageReader(async (timeout) => {
|
|
137489
137393
|
const install = findCursor();
|
|
137490
137394
|
if (!install) throw new Error("Cursor CLI not found");
|
|
137491
|
-
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 } });
|
|
137492
137396
|
return r.stdout;
|
|
137493
137397
|
});
|
|
137494
137398
|
return {
|
|
@@ -137531,18 +137435,18 @@ var CursorAgentAdapter = class extends AcpAdapter {
|
|
|
137531
137435
|
// packages/agent-host/src/adapters/opencode/config-files.ts
|
|
137532
137436
|
import { existsSync as existsSync23, readdirSync as readdirSync16, readFileSync as readFileSync20 } from "node:fs";
|
|
137533
137437
|
import { homedir as homedir15 } from "node:os";
|
|
137534
|
-
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";
|
|
137535
137439
|
function readOpenCodeConfigs(cwd, env, home = homedir15()) {
|
|
137536
|
-
const global2 =
|
|
137440
|
+
const global2 = join49(env.XDG_CONFIG_HOME || join49(home, ".config"), "opencode");
|
|
137537
137441
|
const project2 = !env.OPENCODE_DISABLE_PROJECT_CONFIG;
|
|
137538
137442
|
const upward = project2 ? foldersUp(cwd) : [];
|
|
137539
|
-
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] : []];
|
|
137540
137444
|
const files2 = [
|
|
137541
|
-
...["config.json", "opencode.json", "opencode.jsonc"].map((f) =>
|
|
137445
|
+
...["config.json", "opencode.json", "opencode.jsonc"].map((f) => join49(global2, f)),
|
|
137542
137446
|
...env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : [],
|
|
137543
|
-
...upward.flatMap((d2) => CONFIG_NAMES.map((f) =>
|
|
137544
|
-
...dotFolders.flatMap((d2) => CONFIG_NAMES.map((f) =>
|
|
137545
|
-
...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))
|
|
137546
137450
|
];
|
|
137547
137451
|
return {
|
|
137548
137452
|
layers: files2.map(readConfig).filter((c) => c !== null),
|
|
@@ -137554,7 +137458,7 @@ function foldersUp(cwd) {
|
|
|
137554
137458
|
const out = [];
|
|
137555
137459
|
for (let d2 = cwd; ; d2 = dirname25(d2)) {
|
|
137556
137460
|
out.push(d2);
|
|
137557
|
-
if (existsSync23(
|
|
137461
|
+
if (existsSync23(join49(d2, ".git")) || dirname25(d2) === d2) return out;
|
|
137558
137462
|
}
|
|
137559
137463
|
}
|
|
137560
137464
|
function managedFolder(env) {
|
|
@@ -137596,13 +137500,13 @@ function stringEnd(text3, start3) {
|
|
|
137596
137500
|
return text3.length;
|
|
137597
137501
|
}
|
|
137598
137502
|
function agentNames(folder) {
|
|
137599
|
-
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));
|
|
137600
137504
|
return [...named3("agent", true), ...named3("agents", true), ...named3("mode", false), ...named3("modes", false)];
|
|
137601
137505
|
}
|
|
137602
137506
|
function markdown(folder, deep) {
|
|
137603
137507
|
try {
|
|
137604
137508
|
return readdirSync16(folder, { withFileTypes: true }).flatMap((e) => {
|
|
137605
|
-
const path2 =
|
|
137509
|
+
const path2 = join49(folder, e.name);
|
|
137606
137510
|
if (e.isDirectory()) return deep ? markdown(path2, deep) : [];
|
|
137607
137511
|
return e.name.endsWith(".md") ? [path2] : [];
|
|
137608
137512
|
});
|
|
@@ -137941,10 +137845,10 @@ var DESCRIPTOR3 = {
|
|
|
137941
137845
|
var VERSION_FOR_MS = 6e4;
|
|
137942
137846
|
function openCodeProfile() {
|
|
137943
137847
|
let known = null;
|
|
137944
|
-
const localUsage = openCodeUsageReader(async (
|
|
137848
|
+
const localUsage = openCodeUsageReader(async (timeout) => {
|
|
137945
137849
|
const l = findOpenCode();
|
|
137946
137850
|
if (!l) throw new Error("OpenCode not found");
|
|
137947
|
-
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 });
|
|
137948
137852
|
return r.stdout;
|
|
137949
137853
|
});
|
|
137950
137854
|
const version2 = async () => {
|
|
@@ -138100,7 +138004,7 @@ var ApprovalRules = class {
|
|
|
138100
138004
|
};
|
|
138101
138005
|
|
|
138102
138006
|
// packages/agent-host/src/sessions/project-registry.ts
|
|
138103
|
-
import { basename as
|
|
138007
|
+
import { basename as basename12 } from "node:path";
|
|
138104
138008
|
var ProjectRegistry = class {
|
|
138105
138009
|
constructor(host) {
|
|
138106
138010
|
this.host = host;
|
|
@@ -138165,7 +138069,7 @@ var ProjectRegistry = class {
|
|
|
138165
138069
|
return {
|
|
138166
138070
|
id: id3,
|
|
138167
138071
|
path: path2,
|
|
138168
|
-
name:
|
|
138072
|
+
name: basename12(path2),
|
|
138169
138073
|
defaultTool: this.host.firstTool(stored),
|
|
138170
138074
|
// Trust (M4, decision 3) — reads the same column as the app runtime. The trust toggle on screen shows
|
|
138171
138075
|
// this value
|
|
@@ -138802,9 +138706,6 @@ var AssistantProposals = class {
|
|
|
138802
138706
|
proposeMcpServer(spec) {
|
|
138803
138707
|
const nameError = proposedMcpServerNameError(spec.name);
|
|
138804
138708
|
if (nameError) return { ok: false, error: nameError };
|
|
138805
|
-
if (RESERVED_APP_IDS.includes(spec.name)) {
|
|
138806
|
-
return { ok: false, error: `"${spec.name}" is a reserved app name \u2014 propose a different name` };
|
|
138807
|
-
}
|
|
138808
138709
|
if (this.userAppExists(spec.name)) return { ok: false, error: `"${spec.name}" is already installed` };
|
|
138809
138710
|
if (this.mcpProposals().some((p) => p.name === spec.name)) return { ok: false, error: PENDING(spec.name) };
|
|
138810
138711
|
const proposals = this.mcpProposals();
|
|
@@ -139771,7 +139672,7 @@ var UsageRecorder = class {
|
|
|
139771
139672
|
|
|
139772
139673
|
// packages/agent-host/src/sessions/manager.ts
|
|
139773
139674
|
import { homedir as homedir17 } from "node:os";
|
|
139774
|
-
import { join as
|
|
139675
|
+
import { join as join52 } from "node:path";
|
|
139775
139676
|
|
|
139776
139677
|
// packages/agent-host/src/dev-services/store.ts
|
|
139777
139678
|
import Database3 from "better-sqlite3";
|
|
@@ -141015,10 +140916,10 @@ var UserAppAdoptionRecords = class {
|
|
|
141015
140916
|
for (const { id: id3 } of assistants) {
|
|
141016
140917
|
const book = parseJson(this.settings.appSetting(`session_app_names:${id3}`));
|
|
141017
140918
|
const server2 = isObj(book) ? book[to] : void 0;
|
|
141018
|
-
if (typeof server2 !== "string" || !server2.startsWith(
|
|
140919
|
+
if (typeof server2 !== "string" || !server2.startsWith(APP_SERVER_PREFIX)) continue;
|
|
141019
140920
|
const raw = parseJson(this.settings.appSetting(`${ATTACHED_PREFIX}${id3}`));
|
|
141020
140921
|
const list2 = Array.isArray(raw) ? raw : [];
|
|
141021
|
-
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;
|
|
141022
140923
|
list2.push({ projectId, appId, server: server2, consent: "none", at: Date.now() });
|
|
141023
140924
|
this.settings.setAppSetting(`${ATTACHED_PREFIX}${id3}`, JSON.stringify(list2));
|
|
141024
140925
|
}
|
|
@@ -144554,8 +144455,8 @@ async function gitBranchPr(projectCwd, branch, signal, timeoutMs = OK2.timeout)
|
|
|
144554
144455
|
}
|
|
144555
144456
|
|
|
144556
144457
|
// packages/agent-host/src/dev-services/file-search.ts
|
|
144557
|
-
import { readdir as
|
|
144558
|
-
import { join as
|
|
144458
|
+
import { readdir as readdir13 } from "node:fs/promises";
|
|
144459
|
+
import { join as join50 } from "node:path";
|
|
144559
144460
|
var MAX_FILES2 = 2e4;
|
|
144560
144461
|
var TTL_MS2 = 15e3;
|
|
144561
144462
|
var WALK_DEPTH = 6;
|
|
@@ -144585,7 +144486,7 @@ async function walk(root3) {
|
|
|
144585
144486
|
const { dir, rel, depth } = next;
|
|
144586
144487
|
let entries;
|
|
144587
144488
|
try {
|
|
144588
|
-
entries = await
|
|
144489
|
+
entries = await readdir13(dir, { withFileTypes: true });
|
|
144589
144490
|
} catch {
|
|
144590
144491
|
continue;
|
|
144591
144492
|
}
|
|
@@ -144593,7 +144494,7 @@ async function walk(root3) {
|
|
|
144593
144494
|
if (e.name.startsWith(".") && e.name !== ".env") continue;
|
|
144594
144495
|
if (e.isDirectory()) {
|
|
144595
144496
|
if (SKIP.has(e.name) || depth >= WALK_DEPTH) continue;
|
|
144596
|
-
queue.push({ dir:
|
|
144497
|
+
queue.push({ dir: join50(dir, e.name), rel: wireJoin(rel, e.name), depth: depth + 1 });
|
|
144597
144498
|
} else {
|
|
144598
144499
|
out.push(wireJoin(rel, e.name).normalize("NFC"));
|
|
144599
144500
|
if (out.length >= MAX_FILES2) break;
|
|
@@ -145378,7 +145279,7 @@ var HandoffFlow = class {
|
|
|
145378
145279
|
const name = trustedJsonText(target.name);
|
|
145379
145280
|
try {
|
|
145380
145281
|
const r = await raceBound(turn.done.then(() => null, (e) => e), this.timings.noteMs);
|
|
145381
|
-
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.` };
|
|
145382
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").` };
|
|
145383
145284
|
const cur = this.host.meta.get(target.id);
|
|
145384
145285
|
if (!cur) return { ok: false, error: `${name} disappeared while writing its note; nothing was handed off.` };
|
|
@@ -145742,14 +145643,14 @@ async function readMessageImage(abs, max = IMAGE_PREVIEW_MAX_BYTES) {
|
|
|
145742
145643
|
}
|
|
145743
145644
|
|
|
145744
145645
|
// packages/agent-host/src/dev-services/attachments.ts
|
|
145745
|
-
import { lstat as lstat12, mkdir as
|
|
145746
|
-
import { extname as extname4, join as
|
|
145747
|
-
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");
|
|
145748
145649
|
function sessionDir(sessionId) {
|
|
145749
145650
|
if (!isSessionId(sessionId)) {
|
|
145750
145651
|
throw rpcError(`Not a session id: ${sessionId}`);
|
|
145751
145652
|
}
|
|
145752
|
-
return
|
|
145653
|
+
return join51(root2(), sessionId);
|
|
145753
145654
|
}
|
|
145754
145655
|
var EXT = {
|
|
145755
145656
|
"image/png": ".png",
|
|
@@ -145759,9 +145660,9 @@ var EXT = {
|
|
|
145759
145660
|
};
|
|
145760
145661
|
async function saveAttachment(sessionId, name, mime, dataBase64) {
|
|
145761
145662
|
const dir = sessionDir(sessionId);
|
|
145762
|
-
await
|
|
145663
|
+
await mkdir8(dir, { recursive: true });
|
|
145763
145664
|
const ext2 = extname4(name) || EXT[mime] || "";
|
|
145764
|
-
const file2 =
|
|
145665
|
+
const file2 = join51(dir, `${Date.now()}-${Math.random().toString(36).slice(2, 8)}${ext2}`);
|
|
145765
145666
|
const buf = Buffer.from(dataBase64, "base64");
|
|
145766
145667
|
await writeFile6(file2, buf);
|
|
145767
145668
|
return { kind: mime.startsWith("image/") ? "image" : "file", path: file2, name, mime, bytes: buf.length };
|
|
@@ -145777,15 +145678,15 @@ async function sweepAttachments(maxBytes = ATTACHMENTS_MAX_BYTES) {
|
|
|
145777
145678
|
const files2 = [];
|
|
145778
145679
|
let dirs;
|
|
145779
145680
|
try {
|
|
145780
|
-
dirs = await
|
|
145681
|
+
dirs = await readdir14(root2());
|
|
145781
145682
|
} catch {
|
|
145782
145683
|
return 0;
|
|
145783
145684
|
}
|
|
145784
145685
|
for (const d2 of dirs) {
|
|
145785
|
-
const dir =
|
|
145786
|
-
const names = await
|
|
145686
|
+
const dir = join51(root2(), d2);
|
|
145687
|
+
const names = await readdir14(dir).catch(() => []);
|
|
145787
145688
|
for (const name of names) {
|
|
145788
|
-
const p =
|
|
145689
|
+
const p = join51(dir, name);
|
|
145789
145690
|
const s = await lstat12(p).catch(() => null);
|
|
145790
145691
|
if (s?.isFile()) files2.push({ path: p, size: s.size, mtime: s.mtimeMs });
|
|
145791
145692
|
}
|
|
@@ -146042,14 +145943,14 @@ var SessionRecord = class {
|
|
|
146042
145943
|
}
|
|
146043
145944
|
async loadMessages(sessionId, limit, beforeSeq) {
|
|
146044
145945
|
const rows3 = this.host.store.messages.loadMessages(sessionId, limit, beforeSeq);
|
|
146045
|
-
const { readFile:
|
|
145946
|
+
const { readFile: readFile11 } = await import("node:fs/promises");
|
|
146046
145947
|
return Promise.all(
|
|
146047
145948
|
rows3.map(async (r) => {
|
|
146048
145949
|
if (r.kind === "image") {
|
|
146049
145950
|
const p = r.payload;
|
|
146050
145951
|
if (!p.path || p.note) return r;
|
|
146051
145952
|
try {
|
|
146052
|
-
const data = (await
|
|
145953
|
+
const data = (await readFile11(p.path)).toString("base64");
|
|
146053
145954
|
return { ...r, payload: { ...p, data } };
|
|
146054
145955
|
} catch {
|
|
146055
145956
|
return { ...r, payload: { ...p, note: "the saved copy was cleared (total-size cap)" } };
|
|
@@ -146062,7 +145963,7 @@ var SessionRecord = class {
|
|
|
146062
145963
|
p.attachments.map(async (a) => {
|
|
146063
145964
|
if (a.kind !== "image") return a;
|
|
146064
145965
|
try {
|
|
146065
|
-
return { ...a, data: (await
|
|
145966
|
+
return { ...a, data: (await readFile11(a.path)).toString("base64") };
|
|
146066
145967
|
} catch {
|
|
146067
145968
|
return a;
|
|
146068
145969
|
}
|
|
@@ -146321,7 +146222,7 @@ Answer in the language the person writes in.`;
|
|
|
146321
146222
|
}
|
|
146322
146223
|
|
|
146323
146224
|
// packages/agent-host/src/sessions/app-sessions.ts
|
|
146324
|
-
var builderKey = (ref) => appKeyOf(ref
|
|
146225
|
+
var builderKey = (ref) => appKeyOf(ref);
|
|
146325
146226
|
var APP_BUILDERS_KEY = "apps.builders";
|
|
146326
146227
|
var AppSessions = class {
|
|
146327
146228
|
constructor(host) {
|
|
@@ -146447,7 +146348,7 @@ var AppSessions = class {
|
|
|
146447
146348
|
async standUpBuilder(ref, tool) {
|
|
146448
146349
|
const rt2 = this.host.appsHub?.rt;
|
|
146449
146350
|
if (!rt2) throw rpcError("External apps are unavailable");
|
|
146450
|
-
const app2 = rt2.list().find((a) => a
|
|
146351
|
+
const app2 = rt2.list().find((a) => sameApp(a, ref));
|
|
146451
146352
|
if (!app2) throw rpcError(noSuchAppText(ref));
|
|
146452
146353
|
if (!app2.trusted) {
|
|
146453
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");
|
|
@@ -146742,7 +146643,7 @@ function appAgentPreset(callers, presetOf) {
|
|
|
146742
146643
|
}
|
|
146743
146644
|
|
|
146744
146645
|
// packages/agent-host/src/sessions/session-trash.ts
|
|
146745
|
-
import { basename as
|
|
146646
|
+
import { basename as basename13 } from "node:path";
|
|
146746
146647
|
import { existsSync as existsSync25, statSync as statSync17 } from "node:fs";
|
|
146747
146648
|
var SessionTrash = class {
|
|
146748
146649
|
constructor(host) {
|
|
@@ -147107,7 +147008,7 @@ var SessionTrash = class {
|
|
|
147107
147008
|
this.host.store.projects.addProject({
|
|
147108
147009
|
id: record2.projectId,
|
|
147109
147010
|
path: record2.projectPath,
|
|
147110
|
-
name: record2.projectName ??
|
|
147011
|
+
name: record2.projectName ?? basename13(record2.projectPath)
|
|
147111
147012
|
});
|
|
147112
147013
|
projectId = record2.projectId;
|
|
147113
147014
|
registered = await this.host.projectInfo(projectId, record2.projectPath);
|
|
@@ -147480,7 +147381,7 @@ function stands(o, proto) {
|
|
|
147480
147381
|
return Object.getPrototypeOf(o) === proto;
|
|
147481
147382
|
}
|
|
147482
147383
|
var SessionManager = class {
|
|
147483
|
-
constructor(store2, adapters2, emit, endpoint, worktreeRoot =
|
|
147384
|
+
constructor(store2, adapters2, emit, endpoint, worktreeRoot = join52(homedir17(), DATA_DIR, "worktrees"), keeperOpts = {}) {
|
|
147484
147385
|
this.store = store2;
|
|
147485
147386
|
this.adapters = adapters2;
|
|
147486
147387
|
this.emit = emit;
|
|
@@ -149705,7 +149606,7 @@ var MessageService = class {
|
|
|
149705
149606
|
if (!said) return "the person has typed nothing in this session that it could cite";
|
|
149706
149607
|
const age2 = now - said.ts;
|
|
149707
149608
|
if (age2 < 0) return "the person's last message here is dated later than now";
|
|
149708
|
-
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`;
|
|
149709
149610
|
if (this.records.hasDedupe(sender, citeKey(said.seq))) return "the person's last message here was cited by an earlier request already";
|
|
149710
149611
|
return { seq: said.seq, at: said.ts };
|
|
149711
149612
|
}
|
|
@@ -151189,7 +151090,7 @@ var MailAcross = class {
|
|
|
151189
151090
|
if (!h.you) return away.push({ name: h.name, why: "it runs an older Centralu; update it there" });
|
|
151190
151091
|
if (!h.reachable) return away.push({ name: h.name, why: "not reachable right now" });
|
|
151191
151092
|
try {
|
|
151192
|
-
const raw = await
|
|
151093
|
+
const raw = await withTimeout(h.call("hub.find", { query, limit: exact ? 50 : FIND_LIMIT, ...exact ? { exact: true } : {} }), ms3, noAnswer);
|
|
151193
151094
|
const r = HubFindResult.safeParse(raw);
|
|
151194
151095
|
if (!r.success) return away.push({ name: h.name, why: "its answer could not be read" });
|
|
151195
151096
|
for (const e of r.data.entries) {
|
|
@@ -151247,12 +151148,7 @@ function stateOf(r) {
|
|
|
151247
151148
|
function pickState(r) {
|
|
151248
151149
|
return stateOf(r);
|
|
151249
151150
|
}
|
|
151250
|
-
|
|
151251
|
-
return new Promise((_, reject) => {
|
|
151252
|
-
const t = setTimeout(() => reject(new Error(`no answer within ${ms3 / 1e3} s`)), ms3);
|
|
151253
|
-
t.unref?.();
|
|
151254
|
-
});
|
|
151255
|
-
}
|
|
151151
|
+
var noAnswer = (ms3) => `no answer within ${durationText(ms3)}`;
|
|
151256
151152
|
|
|
151257
151153
|
// packages/agent-host/src/mail/turns.ts
|
|
151258
151154
|
var STARTED_BY = ["mail", "person", "caller", "cli", "report", "app"];
|
|
@@ -151822,7 +151718,7 @@ function factsOf(s) {
|
|
|
151822
151718
|
}
|
|
151823
151719
|
|
|
151824
151720
|
// packages/agent-host/src/sessions/memory-gate.ts
|
|
151825
|
-
import { readFile as
|
|
151721
|
+
import { readFile as readFile8 } from "node:fs/promises";
|
|
151826
151722
|
import { freemem } from "node:os";
|
|
151827
151723
|
var MEMORY_FLOOR_BYTES = 2 * 1024 ** 3;
|
|
151828
151724
|
var MEMORY_RECHECK_MS = 15e3;
|
|
@@ -151849,7 +151745,7 @@ async function readAvailableMemory(deps = {}) {
|
|
|
151849
151745
|
if (source.kind === "freemem") return free();
|
|
151850
151746
|
const what = source.kind === "command" ? source.file : source.path;
|
|
151851
151747
|
try {
|
|
151852
|
-
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));
|
|
151853
151749
|
if (value !== null) return value;
|
|
151854
151750
|
console.error(`[memory-gate] could not parse ${what}; letting agent starts through`);
|
|
151855
151751
|
} catch (e) {
|
|
@@ -151943,9 +151839,195 @@ var MemoryGate = class {
|
|
|
151943
151839
|
// packages/agent-host/src/rpc.ts
|
|
151944
151840
|
import { relative as relative9 } from "node:path";
|
|
151945
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
|
+
|
|
151946
151970
|
// packages/agent-host/src/dev-services/strays.ts
|
|
151971
|
+
import { createHash as createHash14, randomBytes as randomBytes12 } from "node:crypto";
|
|
151947
151972
|
import { realpathSync as realpathSync11 } from "node:fs";
|
|
151948
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
|
+
}
|
|
151949
152031
|
function parsePsRows(out) {
|
|
151950
152032
|
const rows3 = [];
|
|
151951
152033
|
for (const line of out.split("\n")) {
|
|
@@ -151979,7 +152061,7 @@ function insideAny(cwd, roots) {
|
|
|
151979
152061
|
}
|
|
151980
152062
|
return null;
|
|
151981
152063
|
}
|
|
151982
|
-
function
|
|
152064
|
+
function candidatesOf(rows3, cwdOf, roots, selfPid) {
|
|
151983
152065
|
const ours = descendants(rows3, [selfPid]);
|
|
151984
152066
|
const launchers = ancestors(rows3, [selfPid]);
|
|
151985
152067
|
const candidates = /* @__PURE__ */ new Map();
|
|
@@ -151990,23 +152072,28 @@ function pickStrays(rows3, cwdOf, roots, selfPid, adopter = null) {
|
|
|
151990
152072
|
if (!cwd || !insideAny(cwd, roots)) continue;
|
|
151991
152073
|
candidates.set(r.pid, cwd);
|
|
151992
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) {
|
|
151993
152083
|
const byPid = new Map(rows3.map((r) => [r.pid, r]));
|
|
151994
|
-
const
|
|
152084
|
+
const ourStart = (pid) => {
|
|
151995
152085
|
const seen = /* @__PURE__ */ new Set();
|
|
151996
|
-
let
|
|
151997
|
-
|
|
151998
|
-
|
|
151999
|
-
|
|
152000
|
-
if (!candidates.has(cur.ppid)) return false;
|
|
152001
|
-
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);
|
|
152002
152090
|
}
|
|
152003
152091
|
return false;
|
|
152004
152092
|
};
|
|
152005
152093
|
const out = [];
|
|
152006
|
-
for (const [pid, cwd] of
|
|
152007
|
-
if (!unowned(pid)) continue;
|
|
152094
|
+
for (const [pid, cwd] of candidatesOf(rows3, cwdOf, roots, selfPid)) {
|
|
152008
152095
|
const row = byPid.get(pid);
|
|
152009
|
-
if (row) out.push({ pid, command: row.command, cwd });
|
|
152096
|
+
if (row && ourStart(pid)) out.push({ pid, command: row.command, cwd });
|
|
152010
152097
|
}
|
|
152011
152098
|
return out.sort((a, b2) => a.pid - b2.pid);
|
|
152012
152099
|
}
|
|
@@ -152040,29 +152127,20 @@ async function scanProcesses(run2 = exec) {
|
|
|
152040
152127
|
const cwdOf = await cwdsOf(run2, rows3.filter((r) => r.pid > 1 && noTty(r.tty)).map((r) => r.pid));
|
|
152041
152128
|
return { rows: rows3, cwdOf };
|
|
152042
152129
|
}
|
|
152043
|
-
async function
|
|
152044
|
-
let pid = 0;
|
|
152130
|
+
async function ownerMarks(pids) {
|
|
152045
152131
|
try {
|
|
152046
|
-
|
|
152047
|
-
pid = Number((await run2("/bin/sh", ["-c", "sleep 60 </dev/null >/dev/null 2>&1 & echo $!"], opts)).stdout);
|
|
152048
|
-
const ppid = Number((await run2("ps", ["-o", "ppid=", "-p", String(pid)], opts)).stdout);
|
|
152049
|
-
if (!(ppid > 1)) return null;
|
|
152050
|
-
const command = (await run2("ps", ["-o", "command=", "-p", String(ppid)], opts)).stdout.trim();
|
|
152051
|
-
return command === "/init" ? ppid : null;
|
|
152132
|
+
return await environmentValues(OWNER_MARK, pids);
|
|
152052
152133
|
} catch (e) {
|
|
152053
|
-
unread2("
|
|
152054
|
-
return
|
|
152055
|
-
} finally {
|
|
152056
|
-
if (pid > 1) try {
|
|
152057
|
-
end(pid);
|
|
152058
|
-
} catch {
|
|
152059
|
-
}
|
|
152134
|
+
unread2("the processes' owner marks", e);
|
|
152135
|
+
return /* @__PURE__ */ new Map();
|
|
152060
152136
|
}
|
|
152061
152137
|
}
|
|
152062
|
-
async function findStrays(roots, selfPid = process.pid) {
|
|
152063
|
-
if (!hasPs() || roots.length === 0) return [];
|
|
152064
|
-
const
|
|
152065
|
-
|
|
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);
|
|
152066
152144
|
}
|
|
152067
152145
|
function resolveRoots(roots) {
|
|
152068
152146
|
const out = /* @__PURE__ */ new Set();
|
|
@@ -152167,12 +152245,12 @@ function refuse7(message) {
|
|
|
152167
152245
|
throw rpcError(message);
|
|
152168
152246
|
}
|
|
152169
152247
|
async function askBuilder(deps, req) {
|
|
152170
|
-
const app2 = deps.apps.list().find((a) => a
|
|
152248
|
+
const app2 = deps.apps.list().find((a) => sameApp(a, req.ref));
|
|
152171
152249
|
const builder = deps.builderOf(req.ref);
|
|
152172
152250
|
let view2;
|
|
152173
152251
|
if (req.instanceId) {
|
|
152174
152252
|
const inst = deps.views?.describe(req.instanceId) ?? null;
|
|
152175
|
-
view2 = inst && inst.app
|
|
152253
|
+
view2 = inst && sameApp(inst.app, req.ref) ? inst : null;
|
|
152176
152254
|
}
|
|
152177
152255
|
const built = builderRequestOf({
|
|
152178
152256
|
text: req.text,
|
|
@@ -152188,7 +152266,7 @@ async function askBuilder(deps, req) {
|
|
|
152188
152266
|
return { sessionId: built.builder.id };
|
|
152189
152267
|
}
|
|
152190
152268
|
async function sendErrorToBuilder(deps, ref, at2) {
|
|
152191
|
-
const info = deps.apps.list().find((a) => a
|
|
152269
|
+
const info = deps.apps.list().find((a) => sameApp(a, ref));
|
|
152192
152270
|
if (!info) refuse7("This app no longer exists");
|
|
152193
152271
|
const builder = deps.builderOf(ref);
|
|
152194
152272
|
if (!builder) refuse7("This app has no builder session yet. Start one, then send the error");
|
|
@@ -152548,7 +152626,7 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
152548
152626
|
}
|
|
152549
152627
|
const ref = owner?.ref ?? views2?.describe(instanceId)?.app ?? null;
|
|
152550
152628
|
if (!ref) throw rpcError("This app view is not open");
|
|
152551
|
-
const name = externalApps2?.list().find((a) => a
|
|
152629
|
+
const name = externalApps2?.list().find((a) => sameApp(a, ref))?.name;
|
|
152552
152630
|
await mgr2.inputs.sendFromApp(sessionId, text3, { appId: ref.appId, projectId: ref.projectId, name: name ?? ref.appId }, owner ? "inline" : "pinned");
|
|
152553
152631
|
return { ok: true };
|
|
152554
152632
|
},
|
|
@@ -152605,7 +152683,7 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
152605
152683
|
const apps = requireExternalApps();
|
|
152606
152684
|
if (apps.keepsVersions({ appId, projectId })) return { kind: "snapshots", snapshots: apps.snapshots({ appId, projectId }).map(({ stamp: _stamp, depth: _depth, ...s }) => s) };
|
|
152607
152685
|
const project2 = (await mgr2.projectRegistry.listProjects()).find((x) => x.id === projectId);
|
|
152608
|
-
const app2 = apps.list().find((a) => a
|
|
152686
|
+
const app2 = apps.list().find((a) => sameApp(a, { appId, projectId }));
|
|
152609
152687
|
if (!project2 || !app2) throw rpcError(noSuchAppText({ projectId, appId }));
|
|
152610
152688
|
const { repo, commits } = await gitLogPath(project2.path, relative9(project2.path, app2.dir), 20);
|
|
152611
152689
|
return { kind: "git", repo, commits };
|
|
@@ -154614,9 +154692,10 @@ async function namedTargets(rpc, params) {
|
|
|
154614
154692
|
machineNamed ||= !!r.machine;
|
|
154615
154693
|
}
|
|
154616
154694
|
if (typeof p.appId === "string") {
|
|
154695
|
+
const appId = p.appId;
|
|
154617
154696
|
const machine = typeof p.machine === "string" ? p.machine : void 0;
|
|
154618
154697
|
const projectId = typeof p.projectId === "string" ? p.projectId : null;
|
|
154619
|
-
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 }));
|
|
154620
154699
|
if (!a) return { ok: false, why: "it names an app this computer does not have" };
|
|
154621
154700
|
parts.push(`the app ${quoted3(a.name ?? a.appId)} [${a.appId}]${on2(a.machine)}`);
|
|
154622
154701
|
machineNamed ||= !!a.machine;
|
|
@@ -155722,7 +155801,7 @@ function updateNodeSentence(o) {
|
|
|
155722
155801
|
}
|
|
155723
155802
|
|
|
155724
155803
|
// packages/agent-host/src/links/tunnel.ts
|
|
155725
|
-
import { createHash as
|
|
155804
|
+
import { createHash as createHash15 } from "node:crypto";
|
|
155726
155805
|
import { createConnection as createConnection2, createServer as createServer3 } from "node:net";
|
|
155727
155806
|
import { hostname as hostname3 } from "node:os";
|
|
155728
155807
|
|
|
@@ -155743,9 +155822,6 @@ async function endChild(child, graceMs = RUN_STOP_GRACE_MS) {
|
|
|
155743
155822
|
await realOs().processes.stop(child, graceMs, { sweep: false }).catch(() => {
|
|
155744
155823
|
});
|
|
155745
155824
|
}
|
|
155746
|
-
function seconds(ms3) {
|
|
155747
|
-
return ms3 >= 1e3 ? `${Math.round(ms3 / 1e3)} seconds` : `${ms3} ms`;
|
|
155748
|
-
}
|
|
155749
155825
|
function runSsh(opts) {
|
|
155750
155826
|
const stdoutLimit = opts.stdoutLimit ?? SSH_STDOUT_LIMIT;
|
|
155751
155827
|
return new Promise((resolve21, reject) => {
|
|
@@ -155772,7 +155848,7 @@ function runSsh(opts) {
|
|
|
155772
155848
|
if (kind !== "spawn") void endChild(child);
|
|
155773
155849
|
reject(new SshRunFailure(kind, message, stage));
|
|
155774
155850
|
};
|
|
155775
|
-
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);
|
|
155776
155852
|
const expected = opts.expect ?? [];
|
|
155777
155853
|
let next = 0;
|
|
155778
155854
|
let expectDeadline;
|
|
@@ -155999,7 +156075,7 @@ function notInstalled(where2, spec) {
|
|
|
155999
156075
|
}
|
|
156000
156076
|
var NOT_FOUND2 = "CENTRALU-NOT-FOUND";
|
|
156001
156077
|
var STALE_LAUNCHER = "; if Node was upgraded there, run `centralu serve` once from an interactive shell on that machine";
|
|
156002
|
-
function
|
|
156078
|
+
function noAnswer2(err, r, remote) {
|
|
156003
156079
|
const why2 = lastLine(r.stderr);
|
|
156004
156080
|
if (r.code === 127 && !remote.command?.trim()) return `The Centralu there did not run: ${why2 || "exit 127"}${STALE_LAUNCHER}`;
|
|
156005
156081
|
return `${err.message}${why2 ? `: ${why2}` : r.code ? ` (exit ${r.code})` : ""}`;
|
|
@@ -156008,7 +156084,7 @@ function connectionCommand(spec, pair = null) {
|
|
|
156008
156084
|
return remoteCommand(spec, pair ? `serve --connection --pair ${pair}` : "serve --connection");
|
|
156009
156085
|
}
|
|
156010
156086
|
function hubKeyOf(hubSelfId2) {
|
|
156011
|
-
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);
|
|
156012
156088
|
}
|
|
156013
156089
|
function pairLabel(name, hubKey) {
|
|
156014
156090
|
const key = hubKey && /^[0-9a-f]{1,16}$/.test(hubKey) ? `-${hubKey}` : "";
|
|
@@ -156137,7 +156213,7 @@ var SshTunnel = class {
|
|
|
156137
156213
|
try {
|
|
156138
156214
|
answer = parseDetachLine(r.stdout);
|
|
156139
156215
|
} catch (err) {
|
|
156140
|
-
throw new Error(
|
|
156216
|
+
throw new Error(noAnswer2(err, r, remote));
|
|
156141
156217
|
}
|
|
156142
156218
|
if (answer.ok) {
|
|
156143
156219
|
this.linkBound = false;
|
|
@@ -156165,16 +156241,15 @@ var SshTunnel = class {
|
|
|
156165
156241
|
const markers = typeof command === "string" ? [] : command.expect ?? [];
|
|
156166
156242
|
const readyMs = this.opts.stdinReadyMs ?? SSH_STDIN_READY_MS;
|
|
156167
156243
|
const ackMs = this.opts.stdinAckMs ?? SSH_STDIN_ACK_MS;
|
|
156168
|
-
const sec = (ms3) => `${Math.round(ms3 / 1e3)} seconds`;
|
|
156169
156244
|
const expect = markers.map(
|
|
156170
156245
|
(marker, i) => i === 0 ? {
|
|
156171
156246
|
marker,
|
|
156172
156247
|
withinMs: readyMs,
|
|
156173
|
-
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)`
|
|
156174
156249
|
} : {
|
|
156175
156250
|
marker,
|
|
156176
156251
|
withinMs: ackMs,
|
|
156177
|
-
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`,
|
|
156178
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`,
|
|
156179
156254
|
// The reader's own exits (cut input, its time); a dropped link (255) or a signal is not, and is not sent again
|
|
156180
156255
|
endedCodes: [STDIN_EXIT_CUT, STDIN_EXIT_LATE]
|
|
@@ -156267,7 +156342,7 @@ var SshTunnel = class {
|
|
|
156267
156342
|
} catch (err) {
|
|
156268
156343
|
const why2 = lastLine(r.stderr);
|
|
156269
156344
|
if (r.code !== 0 && /cannot be read by this user \((EACCES|EPERM)\)/.test(why2)) throw new Error(why2.replace(/^centralu serve: /, ""));
|
|
156270
|
-
throw new Error(
|
|
156345
|
+
throw new Error(noAnswer2(err, r, remote));
|
|
156271
156346
|
}
|
|
156272
156347
|
}
|
|
156273
156348
|
forward(localPort, remotePort, hosting = false) {
|
|
@@ -156975,7 +157050,7 @@ async function listSshHosts(opts = {}) {
|
|
|
156975
157050
|
}
|
|
156976
157051
|
|
|
156977
157052
|
// packages/agent-host/src/links/machine-ids.ts
|
|
156978
|
-
import { randomBytes as
|
|
157053
|
+
import { randomBytes as randomBytes13 } from "node:crypto";
|
|
156979
157054
|
function isMachineId(value) {
|
|
156980
157055
|
return MACHINE_ID_RE.test(value);
|
|
156981
157056
|
}
|
|
@@ -157012,10 +157087,10 @@ function decodeNumber(value) {
|
|
|
157012
157087
|
}
|
|
157013
157088
|
function newMachineId(name, taken) {
|
|
157014
157089
|
const slug = name.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^[^a-z]+/, "").replace(/-+$/, "").slice(0, 24);
|
|
157015
|
-
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")}`;
|
|
157016
157091
|
if (!taken.has(base2)) return base2;
|
|
157017
157092
|
for (let i = 2; i < 1e3; i++) if (!taken.has(`${base2}-${i}`)) return `${base2}-${i}`;
|
|
157018
|
-
return `m-${
|
|
157093
|
+
return `m-${randomBytes13(4).toString("hex")}`;
|
|
157019
157094
|
}
|
|
157020
157095
|
|
|
157021
157096
|
// packages/agent-host/src/links/autostart.ts
|
|
@@ -157074,7 +157149,7 @@ async function askHubAuto(call2, allowed) {
|
|
|
157074
157149
|
}
|
|
157075
157150
|
|
|
157076
157151
|
// packages/agent-host/src/links/linked-machine-connection.ts
|
|
157077
|
-
import { randomBytes as
|
|
157152
|
+
import { randomBytes as randomBytes14 } from "node:crypto";
|
|
157078
157153
|
|
|
157079
157154
|
// packages/agent-host/src/links/qualifier.ts
|
|
157080
157155
|
var CrossMachineError = class extends Error {
|
|
@@ -157373,7 +157448,6 @@ var Qualifier = class {
|
|
|
157373
157448
|
|
|
157374
157449
|
// packages/agent-host/src/links/remote-client.ts
|
|
157375
157450
|
var MAX_INCOMING_CALLS = 16;
|
|
157376
|
-
var DEFAULT_HANDSHAKE_TIMEOUT_MS = 1e4;
|
|
157377
157451
|
var DEFAULT_CALL_TIMEOUT_MS = 2e5;
|
|
157378
157452
|
var linkError = (message, retryable) => rpcError(message, "internal", { retryable });
|
|
157379
157453
|
var RemoteClient = class {
|
|
@@ -157417,7 +157491,7 @@ var RemoteClient = class {
|
|
|
157417
157491
|
this.proving = null;
|
|
157418
157492
|
const ws2 = new this.WS(this.opts.url);
|
|
157419
157493
|
this.ws = ws2;
|
|
157420
|
-
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);
|
|
157421
157495
|
ws2.on("open", () => {
|
|
157422
157496
|
if (this.ws !== ws2) return;
|
|
157423
157497
|
if (this.opts.proveHost) {
|
|
@@ -157511,14 +157585,14 @@ var RemoteClient = class {
|
|
|
157511
157585
|
get credential() {
|
|
157512
157586
|
return this.opts.credential;
|
|
157513
157587
|
}
|
|
157514
|
-
call(method, params) {
|
|
157588
|
+
call(method, params, timeoutMs) {
|
|
157515
157589
|
if (this.closed) return Promise.reject(linkError("The link is closed", false));
|
|
157516
157590
|
if (!this.ready || !this.ws) return Promise.reject(linkError("The machine is not reachable right now", true));
|
|
157517
157591
|
const ws2 = this.ws;
|
|
157518
157592
|
const id3 = String(this.nextId++);
|
|
157519
157593
|
const answer = this.pending.wait(
|
|
157520
157594
|
id3,
|
|
157521
|
-
this.opts.callTimeoutMs ?? DEFAULT_CALL_TIMEOUT_MS,
|
|
157595
|
+
this.opts.callTimeoutMs ?? timeoutMs ?? DEFAULT_CALL_TIMEOUT_MS,
|
|
157522
157596
|
() => rpcError(`The machine did not answer ${method} in time`, "internal", { retryable: true })
|
|
157523
157597
|
);
|
|
157524
157598
|
try {
|
|
@@ -158426,7 +158500,7 @@ var LinkedMachineConnection = class {
|
|
|
158426
158500
|
const startedAt = Date.now();
|
|
158427
158501
|
const told = this.reportSeq;
|
|
158428
158502
|
try {
|
|
158429
|
-
const nonce =
|
|
158503
|
+
const nonce = randomBytes14(16).toString("base64url");
|
|
158430
158504
|
const r = asObj(await client.call("host.credentials", { nonce }));
|
|
158431
158505
|
if (this.client !== client) return;
|
|
158432
158506
|
const listed2 = this.ownOf(credentialsOf(r.credentials), nonce);
|
|
@@ -158531,14 +158605,14 @@ var LinkedMachineConnection = class {
|
|
|
158531
158605
|
return this.mailBack;
|
|
158532
158606
|
}
|
|
158533
158607
|
// ── RoutedMachine ───────────────────────────────────────────────────────────────────────
|
|
158534
|
-
call(method, params) {
|
|
158608
|
+
call(method, params, timeoutMs) {
|
|
158535
158609
|
if (!this.client) return Promise.reject(rpcError(`${this.name} is not reachable right now`, "internal", { retryable: true }));
|
|
158536
158610
|
if (method === "agents.respondApproval" && isObj(params) && params.decision === "always" && this.q.unreadCard(params.sessionId, params.requestId)) {
|
|
158537
158611
|
return Promise.reject(
|
|
158538
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 })
|
|
158539
158613
|
);
|
|
158540
158614
|
}
|
|
158541
|
-
return this.client.call(method, params);
|
|
158615
|
+
return this.client.call(method, params, timeoutMs);
|
|
158542
158616
|
}
|
|
158543
158617
|
lastKnown(kind) {
|
|
158544
158618
|
return this.deps.mirror.read(this.id, kind);
|
|
@@ -158798,7 +158872,7 @@ var LinkedMachineConnection = class {
|
|
|
158798
158872
|
this.autoStarts = this.autoStarts.filter((t) => now - t < windowMs);
|
|
158799
158873
|
if (this.autoStarts.length >= max) this.restartsSpent = true;
|
|
158800
158874
|
if (!this.restartsSpent) return null;
|
|
158801
|
-
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";
|
|
158802
158876
|
}
|
|
158803
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 */
|
|
158804
158878
|
async switchThere() {
|
|
@@ -159498,13 +159572,10 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
159498
159572
|
const client = this.client;
|
|
159499
159573
|
if (!client?.connected) return "unreachable";
|
|
159500
159574
|
const ms3 = this.deps.hubAutoReadMs ?? HUB_AUTO_READ_MS;
|
|
159501
|
-
const timedOut2 = /* @__PURE__ */ Symbol("timed out");
|
|
159502
159575
|
try {
|
|
159503
159576
|
return await askHubAuto(async (method, params) => {
|
|
159504
159577
|
if (allowed !== void 0) return client.call(method, params);
|
|
159505
|
-
|
|
159506
|
-
if (answer === timedOut2) throw new Error(`no answer within ${ms3 % 1e3 === 0 ? `${ms3 / 1e3} s` : `${ms3} ms`}`);
|
|
159507
|
-
return answer;
|
|
159578
|
+
return withTimeout(client.call(method, params), ms3, (t) => `no answer within ${durationText(t)}`);
|
|
159508
159579
|
}, allowed);
|
|
159509
159580
|
} catch (err) {
|
|
159510
159581
|
if (!client.connected) return "unreachable";
|
|
@@ -159918,11 +159989,7 @@ function isToolLine(line) {
|
|
|
159918
159989
|
function fencedLine(line) {
|
|
159919
159990
|
return NOT_ONE_LINE.test(line) ? trustedJsonText(line) : line;
|
|
159920
159991
|
}
|
|
159921
|
-
var
|
|
159922
|
-
var TIMED_OUT = /* @__PURE__ */ Symbol("timed out");
|
|
159923
|
-
function notWithin(ms3) {
|
|
159924
|
-
return `did not answer within ${ms3 % 1e3 === 0 ? `${ms3 / 1e3} s` : `${ms3} ms`}`;
|
|
159925
|
-
}
|
|
159992
|
+
var notWithin = (ms3) => `did not answer within ${durationText(ms3)}`;
|
|
159926
159993
|
function cause(err) {
|
|
159927
159994
|
return oneLine4(err instanceof Error ? err.message : String(err), 300);
|
|
159928
159995
|
}
|
|
@@ -159967,11 +160034,7 @@ function linkedSessions(machines, route = notRouted, hubName2, options = {}) {
|
|
|
159967
160034
|
return Array.isArray(list2) ? list2 : [];
|
|
159968
160035
|
};
|
|
159969
160036
|
const rowOf = async (m, id3) => (await listOf(m, "sessions.list")).find((s) => isObj(s) && s.id === id3);
|
|
159970
|
-
const boundedAsk =
|
|
159971
|
-
const answer = await raceTimeout(m.call(method, params), lookupMs, TIMED_OUT);
|
|
159972
|
-
if (answer === TIMED_OUT) throw new Error(notWithin(lookupMs));
|
|
159973
|
-
return answer;
|
|
159974
|
-
};
|
|
160037
|
+
const boundedAsk = (m, method, params) => withTimeout(m.call(method, params), lookupMs, notWithin);
|
|
159975
160038
|
const projectOf = (m, raw) => {
|
|
159976
160039
|
const p = m.q.project(raw);
|
|
159977
160040
|
if (!isObj(p) || typeof p.id !== "string" || typeof p.path !== "string" || !SessionId.safeParse(p.id).success) return null;
|
|
@@ -160754,6 +160817,7 @@ var ROUTES = {
|
|
|
160754
160817
|
};
|
|
160755
160818
|
|
|
160756
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));
|
|
160757
160821
|
var MachineUnreachableError = class extends Error {
|
|
160758
160822
|
/**
|
|
160759
160823
|
* The sentence `linked-sessions.ts` gives the model (#1341, #1532): a machine the person disconnected says to connect it.
|
|
@@ -160830,7 +160894,7 @@ var Router = class {
|
|
|
160830
160894
|
}
|
|
160831
160895
|
if (!m.reachable && ctx === void 0) await m.reachForCall?.();
|
|
160832
160896
|
if (!m.reachable) throw new MachineUnreachableError(m, ctx?.window === true);
|
|
160833
|
-
return m
|
|
160897
|
+
return callOn(m, method, params, ctx);
|
|
160834
160898
|
}
|
|
160835
160899
|
async byKey(method, params, key, route, ctx) {
|
|
160836
160900
|
if (!isObj(params)) return this.opts.local(method, params, ctx);
|
|
@@ -160902,13 +160966,13 @@ var Router = class {
|
|
|
160902
160966
|
const tool = params.tool;
|
|
160903
160967
|
if (typeof tool !== "string" || params.limits === false) return void 0;
|
|
160904
160968
|
try {
|
|
160905
|
-
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)]);
|
|
160906
160970
|
const a = isObj(mine) ? mine.fingerprint : null;
|
|
160907
160971
|
const b2 = isObj(theirs) ? theirs.fingerprint : null;
|
|
160908
160972
|
if (typeof a !== "string" || a === "" || a !== b2) return void 0;
|
|
160909
160973
|
const own = await this.opts.local(method, { tool }, ctx);
|
|
160910
160974
|
if (!isObj(own) || own.supported !== true || !own.usage) return void 0;
|
|
160911
|
-
const there = await m
|
|
160975
|
+
const there = await callOn(m, method, { tool, limits: false }, ctx);
|
|
160912
160976
|
const cache2 = isObj(there) ? there.cache : void 0;
|
|
160913
160977
|
return { supported: true, usage: own.usage, sameAccountAsHub: true, ...cache2 ? { cache: cache2 } : {} };
|
|
160914
160978
|
} catch {
|
|
@@ -160926,31 +160990,31 @@ var Router = class {
|
|
|
160926
160990
|
const machines = [...this.opts.machines()];
|
|
160927
160991
|
switch (method) {
|
|
160928
160992
|
case "sessions.list":
|
|
160929
|
-
return this.mergeLists(machines, "sessions", params);
|
|
160993
|
+
return this.mergeLists(machines, "sessions", params, ctx);
|
|
160930
160994
|
case "projects.list":
|
|
160931
|
-
return this.mergeLists(machines, "projects", params);
|
|
160995
|
+
return this.mergeLists(machines, "projects", params, ctx);
|
|
160932
160996
|
case "projects.reorder":
|
|
160933
160997
|
return this.reorderProjects(machines, params, ctx);
|
|
160934
160998
|
case "approvals.deleteRule":
|
|
160935
160999
|
return this.deleteRule(machines, params, ctx);
|
|
160936
161000
|
default:
|
|
160937
|
-
return this.mergeSimple(method, machines, params);
|
|
161001
|
+
return this.mergeSimple(method, machines, params, ctx);
|
|
160938
161002
|
}
|
|
160939
161003
|
}
|
|
160940
|
-
async mergeLists(machines, kind, params) {
|
|
161004
|
+
async mergeLists(machines, kind, params, ctx) {
|
|
160941
161005
|
const method = kind === "sessions" ? "sessions.list" : "projects.list";
|
|
160942
161006
|
const [local, ...remote] = await Promise.all([
|
|
160943
161007
|
this.opts.local(method, params),
|
|
160944
|
-
...machines.map((m) => this.listOf(m, kind))
|
|
161008
|
+
...machines.map((m) => this.listOf(m, kind, ctx))
|
|
160945
161009
|
]);
|
|
160946
161010
|
const all = [...local, ...remote.flat()];
|
|
160947
161011
|
return kind === "projects" && machines.length > 0 ? this.inPersonsOrder(all) : all;
|
|
160948
161012
|
}
|
|
160949
161013
|
/** One machine's list in the hub's terms: asked when it can be, else its mirror, marked `unreachable` */
|
|
160950
|
-
async listOf(m, kind) {
|
|
161014
|
+
async listOf(m, kind, ctx) {
|
|
160951
161015
|
if (m.reachable) {
|
|
160952
161016
|
try {
|
|
160953
|
-
const list2 = await m
|
|
161017
|
+
const list2 = await callOn(m, kind === "sessions" ? "sessions.list" : "projects.list", {}, ctx);
|
|
160954
161018
|
if (Array.isArray(list2)) {
|
|
160955
161019
|
m.observe(kind, list2);
|
|
160956
161020
|
return this.present(m, kind, list2, false);
|
|
@@ -161009,7 +161073,7 @@ var Router = class {
|
|
|
161009
161073
|
this.opts.local("projects.reorder", { ...isObj(params) ? params : {}, orderedIds: local }),
|
|
161010
161074
|
...machines.map(async (m) => {
|
|
161011
161075
|
const ordered = perMachine.get(m);
|
|
161012
|
-
if (!ordered) return this.listOf(m, "projects");
|
|
161076
|
+
if (!ordered) return this.listOf(m, "projects", ctx);
|
|
161013
161077
|
try {
|
|
161014
161078
|
return m.q.projects(await this.forward(m, "projects.reorder", { orderedIds: ordered }, ctx));
|
|
161015
161079
|
} catch {
|
|
@@ -161033,13 +161097,13 @@ var Router = class {
|
|
|
161033
161097
|
return this.forward(m, "approvals.deleteRule", { id: folded.n }, ctx);
|
|
161034
161098
|
}
|
|
161035
161099
|
/** The other merges: every reachable machine, each answer in the hub's terms, combined by kind */
|
|
161036
|
-
async mergeSimple(method, machines, params) {
|
|
161100
|
+
async mergeSimple(method, machines, params, ctx) {
|
|
161037
161101
|
const local = await this.opts.local(method, params);
|
|
161038
161102
|
const missed = machines.filter((m) => !m.reachable);
|
|
161039
161103
|
const answers2 = await Promise.all(
|
|
161040
161104
|
machines.filter((m) => m.reachable).map(async (m) => {
|
|
161041
161105
|
try {
|
|
161042
|
-
return { m, r: await m
|
|
161106
|
+
return { m, r: await callOn(m, method, params, ctx) };
|
|
161043
161107
|
} catch {
|
|
161044
161108
|
missed.push(m);
|
|
161045
161109
|
return null;
|
|
@@ -161147,7 +161211,7 @@ function linkedViews(call2) {
|
|
|
161147
161211
|
}
|
|
161148
161212
|
|
|
161149
161213
|
// packages/agent-host/src/links/stored.ts
|
|
161150
|
-
import { randomBytes as
|
|
161214
|
+
import { randomBytes as randomBytes15 } from "node:crypto";
|
|
161151
161215
|
function storeRegistry(store2) {
|
|
161152
161216
|
return {
|
|
161153
161217
|
list: () => store2.machines.listLinkedMachines(),
|
|
@@ -161164,7 +161228,7 @@ var HUB_SELF_ID = /^hub-[0-9a-f]{8}$/;
|
|
|
161164
161228
|
function hubSelfId(store2) {
|
|
161165
161229
|
const kept = store2.settings.appSetting(HUB_SELF_KEY);
|
|
161166
161230
|
if (kept && HUB_SELF_ID.test(kept)) return kept;
|
|
161167
|
-
const made = `hub-${
|
|
161231
|
+
const made = `hub-${randomBytes15(4).toString("hex")}`;
|
|
161168
161232
|
store2.settings.updateAppSetting(HUB_SELF_KEY, (current) => current !== null && HUB_SELF_ID.test(current) ? current : made);
|
|
161169
161233
|
return store2.settings.appSetting(HUB_SELF_KEY) ?? made;
|
|
161170
161234
|
}
|
|
@@ -161200,7 +161264,6 @@ function storeProjectOrder(store2) {
|
|
|
161200
161264
|
}
|
|
161201
161265
|
|
|
161202
161266
|
// packages/agent-host/src/links/linked-hubs.ts
|
|
161203
|
-
var LOOKUP_MS2 = 4e3;
|
|
161204
161267
|
var MAIL_MS = 3e4;
|
|
161205
161268
|
var older2 = (err) => /Unknown method/i.test(errorMessage(err));
|
|
161206
161269
|
var LinkedHubs = class {
|
|
@@ -161259,7 +161322,7 @@ var LinkedHubs = class {
|
|
|
161259
161322
|
if (h.client === null) why2 = NOT_REACHABLE;
|
|
161260
161323
|
else {
|
|
161261
161324
|
try {
|
|
161262
|
-
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 });
|
|
161263
161326
|
const parsed = HubMethods["hub.projects"].result.safeParse(raw);
|
|
161264
161327
|
if (parsed.success) h.projects = parsed.data.projects;
|
|
161265
161328
|
else why2 = "its answer could not be read";
|
|
@@ -161664,7 +161727,7 @@ var handedToken = launch.tokenOnStdin ? await readHandedToken(process.stdin).cat
|
|
|
161664
161727
|
console.error(`[agent-host] the launcher did not hand over the token: ${e.message}`);
|
|
161665
161728
|
process.exit(1);
|
|
161666
161729
|
}) : launch.token;
|
|
161667
|
-
var BUILD = true ? "
|
|
161730
|
+
var BUILD = true ? "6299d64" : "dev";
|
|
161668
161731
|
var { values } = parseArgs({
|
|
161669
161732
|
options: {
|
|
161670
161733
|
port: { type: "string", default: "5175" },
|
|
@@ -161685,9 +161748,9 @@ if (values.standby) {
|
|
|
161685
161748
|
process.exit(1);
|
|
161686
161749
|
}
|
|
161687
161750
|
var control = launch.underKeeper || launch.startedBy === "app" ? new ControlChannel(process.stdin) : null;
|
|
161688
|
-
var token = values.token || handedToken ||
|
|
161751
|
+
var token = values.token || handedToken || randomBytes16(16).toString("hex");
|
|
161689
161752
|
var keeperToken = launch.underKeeper && !values.token && handedToken ? token : null;
|
|
161690
|
-
var httpSecret = keeperToken ? deriveHttpSecret(keeperToken) :
|
|
161753
|
+
var httpSecret = keeperToken ? deriveHttpSecret(keeperToken) : randomBytes16(32).toString("base64url");
|
|
161691
161754
|
start2.at("data folder");
|
|
161692
161755
|
var movedNote = null;
|
|
161693
161756
|
function defaultDbPath() {
|
|
@@ -161698,6 +161761,7 @@ function defaultDbPath() {
|
|
|
161698
161761
|
return join58(dir, "store.db");
|
|
161699
161762
|
}
|
|
161700
161763
|
var dbPath = values.memory ? ":memory:" : values.db ?? defaultDbPath();
|
|
161764
|
+
markOwnChildren(dbPath);
|
|
161701
161765
|
var privateFolder = privateDataFolderFor(dbPath);
|
|
161702
161766
|
var madePrivate = privateFolder ? keepDataFolderPrivate(privateFolder) : [];
|
|
161703
161767
|
start2.at("log");
|