@centralu/host-win32-x64 0.1.0-beta.54 → 0.1.0-beta.55
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 +1709 -469
- package/package.json +1 -1
package/host/main.mjs
CHANGED
|
@@ -43046,7 +43046,7 @@ import { dirname as dirname27, join as join59 } 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.55";
|
|
43050
43050
|
|
|
43051
43051
|
// packages/protocol/src/brand.ts
|
|
43052
43052
|
var APP_NAME = "Centralu";
|
|
@@ -57804,6 +57804,9 @@ function applyBackgroundTasks(prev, e) {
|
|
|
57804
57804
|
function liveBackgroundTasks(tasks) {
|
|
57805
57805
|
return tasks.filter((t) => t.status === "running" && !t.ambient);
|
|
57806
57806
|
}
|
|
57807
|
+
function workTasks(tasks) {
|
|
57808
|
+
return liveBackgroundTasks(tasks).filter((t) => !t.timer);
|
|
57809
|
+
}
|
|
57807
57810
|
var QuestionOption = external_exports.object({
|
|
57808
57811
|
label: external_exports.string(),
|
|
57809
57812
|
description: external_exports.string().default("")
|
|
@@ -58696,8 +58699,8 @@ var ModelOption = external_exports.object({
|
|
|
58696
58699
|
});
|
|
58697
58700
|
function listedModel(models, model) {
|
|
58698
58701
|
if (!model) return void 0;
|
|
58699
|
-
const
|
|
58700
|
-
if (
|
|
58702
|
+
const named3 = models.find((m) => m.id === model);
|
|
58703
|
+
if (named3) return named3;
|
|
58701
58704
|
const aliases = models.filter((m) => m.resolved === model && m.id !== "default");
|
|
58702
58705
|
return aliases.length === 1 ? aliases[0] : void 0;
|
|
58703
58706
|
}
|
|
@@ -58922,12 +58925,12 @@ function unknownApprovalCard(raw) {
|
|
|
58922
58925
|
lines.push(
|
|
58923
58926
|
`It reaches from project ${from ? quoted(from, 80) : "(unnamed)"} to project ${to ? quoted(to, 80) : "(unnamed)"}.`
|
|
58924
58927
|
);
|
|
58925
|
-
const
|
|
58928
|
+
const named3 = [
|
|
58926
58929
|
nameOf(card.project) && `project ${quoted(nameOf(card.project), 80)}`,
|
|
58927
58930
|
nameOf(card.app) && `app ${quoted(nameOf(card.app), 80)}`,
|
|
58928
58931
|
trimmed2(card.machine) && `machine ${quoted(trimmed2(card.machine), 80)}`
|
|
58929
58932
|
].filter(Boolean);
|
|
58930
|
-
if (
|
|
58933
|
+
if (named3.length) lines.push(`It names ${named3.join(", ")}.`);
|
|
58931
58934
|
for (const [key, label] of [
|
|
58932
58935
|
["text", "Its text"],
|
|
58933
58936
|
["raw", "Its text"],
|
|
@@ -61474,7 +61477,9 @@ var appMethods = methodsOf(appsParams, appsResults);
|
|
|
61474
61477
|
// packages/protocol/src/machines-hub.ts
|
|
61475
61478
|
var HubOffer = external_exports.object({
|
|
61476
61479
|
hub: external_exports.object({ id: MachineId, name: external_exports.string().min(1).max(200) }),
|
|
61477
|
-
on: external_exports.boolean()
|
|
61480
|
+
on: external_exports.boolean(),
|
|
61481
|
+
mail: external_exports.boolean().optional(),
|
|
61482
|
+
you: MachineId.optional()
|
|
61478
61483
|
});
|
|
61479
61484
|
var HubProject = external_exports.object({ id: external_exports.string().min(1).max(200), name: external_exports.string().max(500) });
|
|
61480
61485
|
var HubAskParams = external_exports.object({
|
|
@@ -61501,11 +61506,90 @@ var HubAskResult = external_exports.union([
|
|
|
61501
61506
|
notice: external_exports.string().optional()
|
|
61502
61507
|
})
|
|
61503
61508
|
]);
|
|
61509
|
+
var HubMailParams = external_exports.object({
|
|
61510
|
+
sessionId: external_exports.string().min(1).max(200),
|
|
61511
|
+
// The hub checks the length as for its own sessions, and refuses it in its words
|
|
61512
|
+
text: external_exports.string().min(1).max(2e5),
|
|
61513
|
+
needsReply: external_exports.boolean().optional(),
|
|
61514
|
+
urgent: external_exports.boolean().optional(),
|
|
61515
|
+
/** The recipient, as the hub names it (`session:<hub id>/<id>`); none: the session that started the sender (item 2, additive) */
|
|
61516
|
+
to: external_exports.string().min(1).max(300).optional(),
|
|
61517
|
+
/** The message this answers, by its id, which both sides keep (item 2) */
|
|
61518
|
+
replyTo: external_exports.string().min(1).max(200).optional(),
|
|
61519
|
+
/** The sender's name, as the recipient reads it */
|
|
61520
|
+
name: external_exports.string().max(500).optional(),
|
|
61521
|
+
/**
|
|
61522
|
+
* A notice to `to` rather than the session's message (the "no longer watched" notice, item 2). The hub writes it as the
|
|
61523
|
+
* machine's, never as its own Centralu's, and only to a session that sent mail to one of that machine's sessions
|
|
61524
|
+
*/
|
|
61525
|
+
notice: external_exports.boolean().optional(),
|
|
61526
|
+
/**
|
|
61527
|
+
* The message's id, picked by the sending host (#2067 review, additive): the recipient's host writes it under that id and
|
|
61528
|
+
* takes a second send of it as the one it has, so a send whose answer was lost can be sent again, or its copy kept later
|
|
61529
|
+
*/
|
|
61530
|
+
id: external_exports.string().min(1).max(200).optional()
|
|
61531
|
+
});
|
|
61532
|
+
var HubMailResult = external_exports.union([
|
|
61533
|
+
// `address`: the recipient as the hub names it, which the sender's copy is kept under (#2067 item 2, additive)
|
|
61534
|
+
external_exports.object({ ok: external_exports.literal(true), messageId: external_exports.string().min(1).max(200), to: external_exports.string().max(500), address: external_exports.string().max(300).optional() }),
|
|
61535
|
+
external_exports.object({ ok: external_exports.literal(false), why: external_exports.string().min(1).max(100), text: external_exports.string().max(4e3) })
|
|
61536
|
+
]);
|
|
61537
|
+
var HostMailParams = external_exports.object({
|
|
61538
|
+
from: external_exports.string().min(1).max(300),
|
|
61539
|
+
name: external_exports.string().max(500).optional(),
|
|
61540
|
+
to: external_exports.string().min(1).max(200),
|
|
61541
|
+
text: external_exports.string().min(1).max(2e5),
|
|
61542
|
+
needsReply: external_exports.boolean().optional(),
|
|
61543
|
+
urgent: external_exports.boolean().optional(),
|
|
61544
|
+
replyTo: external_exports.string().min(1).max(200).optional(),
|
|
61545
|
+
notice: external_exports.boolean().optional(),
|
|
61546
|
+
/** As `HubMailParams.id` */
|
|
61547
|
+
id: external_exports.string().min(1).max(200).optional()
|
|
61548
|
+
});
|
|
61549
|
+
var MailRowState = external_exports.object({
|
|
61550
|
+
messageId: external_exports.string().min(1).max(200),
|
|
61551
|
+
recipient: external_exports.string().min(1).max(300),
|
|
61552
|
+
deliveredAt: external_exports.number().nullable(),
|
|
61553
|
+
readAt: external_exports.number().nullable(),
|
|
61554
|
+
settled: external_exports.string().max(40).nullable(),
|
|
61555
|
+
settledAt: external_exports.number().nullable(),
|
|
61556
|
+
answerId: external_exports.string().max(200).nullable(),
|
|
61557
|
+
releasedAt: external_exports.number().nullable(),
|
|
61558
|
+
releasedWhy: external_exports.string().max(40).nullable(),
|
|
61559
|
+
/** The message's sender, as the hub names it: a hub passes a row of mail between two machines on by it */
|
|
61560
|
+
sender: external_exports.string().max(300).optional()
|
|
61561
|
+
});
|
|
61562
|
+
var MailRowsParams = external_exports.object({ rows: external_exports.array(MailRowState).max(500) });
|
|
61563
|
+
var DirectoryEntry = external_exports.object({
|
|
61564
|
+
address: external_exports.string().min(1).max(300),
|
|
61565
|
+
name: external_exports.string().max(500),
|
|
61566
|
+
project: external_exports.string().max(500).nullable(),
|
|
61567
|
+
machine: external_exports.string().max(200).nullable(),
|
|
61568
|
+
role: external_exports.string().max(40),
|
|
61569
|
+
state: external_exports.string().max(40),
|
|
61570
|
+
/** Working now */
|
|
61571
|
+
busy: external_exports.boolean(),
|
|
61572
|
+
/** When it last waited or started, ms */
|
|
61573
|
+
at: external_exports.number()
|
|
61574
|
+
});
|
|
61575
|
+
var HubFindParams = external_exports.object({ query: external_exports.string().max(500), limit: external_exports.number().int().min(1).max(50), exact: external_exports.boolean().optional() });
|
|
61576
|
+
var HubFindResult = external_exports.object({
|
|
61577
|
+
entries: external_exports.array(DirectoryEntry).max(50),
|
|
61578
|
+
matched: external_exports.number().int().min(0),
|
|
61579
|
+
total: external_exports.number().int().min(0),
|
|
61580
|
+
away: external_exports.array(external_exports.object({ name: external_exports.string().max(200), why: external_exports.string().max(300) })).max(50)
|
|
61581
|
+
});
|
|
61504
61582
|
var HubMethods = {
|
|
61505
61583
|
/** The hub's projects a machine's session may ask */
|
|
61506
61584
|
"hub.projects": { params: external_exports.object({}), result: external_exports.object({ projects: external_exports.array(HubProject) }) },
|
|
61507
61585
|
/** An ask_project into one of them, behind the hub's card for the pair */
|
|
61508
|
-
"hub.askProject": { params: HubAskParams, result: HubAskResult }
|
|
61586
|
+
"hub.askProject": { params: HubAskParams, result: HubAskResult },
|
|
61587
|
+
/** A message of a session the hub started on the machine to the session that started it (#2067). Additive */
|
|
61588
|
+
"hub.mail": { params: HubMailParams, result: HubMailResult },
|
|
61589
|
+
/** The rows of messages that crossed, as the machine knows them (#2067 item 2). Additive */
|
|
61590
|
+
"hub.mailRows": { params: MailRowsParams, result: external_exports.object({ ok: external_exports.literal(true) }) },
|
|
61591
|
+
/** A search of the hub's directory of sessions, its machines' included (#2067 item 3). Additive */
|
|
61592
|
+
"hub.find": { params: HubFindParams, result: HubFindResult }
|
|
61509
61593
|
};
|
|
61510
61594
|
|
|
61511
61595
|
// packages/protocol/src/commands/methods/host.params.ts
|
|
@@ -61849,7 +61933,14 @@ var hostParams = {
|
|
|
61849
61933
|
* only, and shows it to its sessions by its name, "not reachable" once that connection is gone. Asked by the hub
|
|
61850
61934
|
* directly, never routed. Additive
|
|
61851
61935
|
*/
|
|
61852
|
-
"host.hubOffer": HubOffer
|
|
61936
|
+
"host.hubOffer": HubOffer,
|
|
61937
|
+
/**
|
|
61938
|
+
* A message from the hub's side to a session here (#2067 item 2, docs/plans/linked-mail.md §6): taken only on a
|
|
61939
|
+
* connection a hub offered on, from that hub's addresses. Asked by the hub directly, never routed. Additive
|
|
61940
|
+
*/
|
|
61941
|
+
"host.mail": HostMailParams,
|
|
61942
|
+
/** The rows of messages that crossed, as the hub knows them (#2067 item 2). Additive */
|
|
61943
|
+
"host.mailRows": MailRowsParams
|
|
61853
61944
|
};
|
|
61854
61945
|
|
|
61855
61946
|
// packages/protocol/src/commands/methods/host.results.ts
|
|
@@ -61914,7 +62005,14 @@ var hostResults = {
|
|
|
61914
62005
|
]),
|
|
61915
62006
|
"host.handover": external_exports.object({ ok: external_exports.literal(true) }),
|
|
61916
62007
|
"host.systemEnding": external_exports.object({ ok: external_exports.literal(true) }),
|
|
61917
|
-
|
|
62008
|
+
// `mail`: this host takes mail from the hub's side (`host.mail`, #2067 item 2), so the hub's task for a child here says to mail
|
|
62009
|
+
"host.hubOffer": external_exports.object({ ok: external_exports.literal(true), mail: external_exports.boolean().optional() }),
|
|
62010
|
+
// As `hub.mail` answers (machines-hub.ts `HubMailResult`, which the window's bundle leaves out, #1648)
|
|
62011
|
+
"host.mail": external_exports.union([
|
|
62012
|
+
external_exports.object({ ok: external_exports.literal(true), messageId: external_exports.string().min(1).max(200), to: external_exports.string().max(500), address: external_exports.string().max(300).optional() }),
|
|
62013
|
+
external_exports.object({ ok: external_exports.literal(false), why: external_exports.string().min(1).max(100), text: external_exports.string().max(4e3) })
|
|
62014
|
+
]),
|
|
62015
|
+
"host.mailRows": external_exports.object({ ok: external_exports.literal(true) })
|
|
61918
62016
|
};
|
|
61919
62017
|
|
|
61920
62018
|
// packages/protocol/src/commands/methods/host.ts
|
|
@@ -64011,8 +64109,14 @@ function isWaiting(state) {
|
|
|
64011
64109
|
function isInTurn(state) {
|
|
64012
64110
|
return state === "working" || state === "waiting_approval";
|
|
64013
64111
|
}
|
|
64112
|
+
function pausedOnBackground(s) {
|
|
64113
|
+
return (s.state === "waiting_input" || s.state === "idle") && !s.interruption && workTasks(s.backgroundTasks ?? []).length > 0;
|
|
64114
|
+
}
|
|
64014
64115
|
function unheard(row) {
|
|
64015
|
-
|
|
64116
|
+
const working = row.state === "working";
|
|
64117
|
+
const tasks = Array.isArray(row.backgroundTasks) && row.backgroundTasks.length > 0;
|
|
64118
|
+
if (!working && !tasks) return row;
|
|
64119
|
+
return { ...row, ...working ? { state: "idle" } : {}, ...tasks ? { backgroundTasks: [] } : {} };
|
|
64016
64120
|
}
|
|
64017
64121
|
var ALLOWED = {
|
|
64018
64122
|
idle: ["working", "error"],
|
|
@@ -65193,6 +65297,14 @@ import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
|
65193
65297
|
function rpcError(message, code2 = "internal", more) {
|
|
65194
65298
|
return Object.assign(new Error(message), { code: code2, ...more });
|
|
65195
65299
|
}
|
|
65300
|
+
var answeredByPeer = /* @__PURE__ */ new WeakSet();
|
|
65301
|
+
function peerAnswer(err) {
|
|
65302
|
+
answeredByPeer.add(err);
|
|
65303
|
+
return err;
|
|
65304
|
+
}
|
|
65305
|
+
function isPeerAnswer(err) {
|
|
65306
|
+
return typeof err === "object" && err !== null && answeredByPeer.has(err);
|
|
65307
|
+
}
|
|
65196
65308
|
function sessionNotFound(sessionId) {
|
|
65197
65309
|
return rpcError(`Session not found: ${sessionId}`, "session_not_found");
|
|
65198
65310
|
}
|
|
@@ -65597,6 +65709,9 @@ var METHOD_RIGHTS = {
|
|
|
65597
65709
|
/** The window telling the serve host the system is ending (#1970): said with the window's full credential. An everyday one could plant a false end that relabels a real crash as the system's (#1397) */
|
|
65598
65710
|
"host.systemEnding": "window",
|
|
65599
65711
|
"host.hubOffer": "link",
|
|
65712
|
+
// From a hub that offered on the same connection only (rpc.ts), as `host.hubOffer` (#2067 item 2)
|
|
65713
|
+
"host.mail": "link",
|
|
65714
|
+
"host.mailRows": "link",
|
|
65600
65715
|
// The window's own state, preferences, themes and approval rules
|
|
65601
65716
|
"workspace.save": "window",
|
|
65602
65717
|
"approvals.deleteRule": "everyday",
|
|
@@ -65926,13 +66041,13 @@ function verifierOf(credential) {
|
|
|
65926
66041
|
function credentialCheck(verifier, nonce) {
|
|
65927
66042
|
return createHmac7("sha256", verifier).update(`centralu credential check v1\0${nonce}`).digest("base64url");
|
|
65928
66043
|
}
|
|
65929
|
-
function readCredentialFile(path2,
|
|
66044
|
+
function readCredentialFile(path2, read2, pause = sleepSync, now = Date.now) {
|
|
65930
66045
|
let code2 = "";
|
|
65931
66046
|
for (let i = 0; i < 5; i++) {
|
|
65932
66047
|
if (i > 0) pause(10 * i);
|
|
65933
66048
|
let parsed;
|
|
65934
66049
|
try {
|
|
65935
|
-
parsed = JSON.parse(
|
|
66050
|
+
parsed = JSON.parse(read2(path2));
|
|
65936
66051
|
} catch (e) {
|
|
65937
66052
|
code2 = errnoCode(e) ?? "EUNREADABLE";
|
|
65938
66053
|
continue;
|
|
@@ -66136,18 +66251,18 @@ function usedEvent(r, nonce = randomBytes2(16).toString("base64url")) {
|
|
|
66136
66251
|
};
|
|
66137
66252
|
return { type: "host_credential_used", credential };
|
|
66138
66253
|
}
|
|
66139
|
-
function credentialsReport(path2,
|
|
66140
|
-
let listed2 = readListing(path2,
|
|
66141
|
-
const unreadable = listed2 ? null : readCredentialFile(path2,
|
|
66142
|
-
if (!listed2 && unreadable === null) listed2 = readListing(path2,
|
|
66254
|
+
function credentialsReport(path2, read2, used, nonce, onListed) {
|
|
66255
|
+
let listed2 = readListing(path2, read2);
|
|
66256
|
+
const unreadable = listed2 ? null : readCredentialFile(path2, read2).unreadable?.code ?? null;
|
|
66257
|
+
if (!listed2 && unreadable === null) listed2 = readListing(path2, read2);
|
|
66143
66258
|
if (listed2) onListed?.(listed2);
|
|
66144
66259
|
const shown3 = listed2?.map(({ verifier, publicKey, ...c }) => ({ ...c, ...secretFields({ verifier, publicKey }, nonce) }));
|
|
66145
66260
|
return { credentials: listed2 && shown3 ? [...shown3, ...used.gone(listed2, nonce)] : null, unreadable, usedUnderHubLabels: used.underHubLabels(nonce), usedIds: used.ids() };
|
|
66146
66261
|
}
|
|
66147
|
-
function readListing(path2,
|
|
66262
|
+
function readListing(path2, read2) {
|
|
66148
66263
|
let parsed;
|
|
66149
66264
|
try {
|
|
66150
|
-
parsed = JSON.parse(
|
|
66265
|
+
parsed = JSON.parse(read2(path2));
|
|
66151
66266
|
} catch {
|
|
66152
66267
|
return null;
|
|
66153
66268
|
}
|
|
@@ -66379,8 +66494,8 @@ var HostServer = class _HostServer {
|
|
|
66379
66494
|
};
|
|
66380
66495
|
if (opts.fullCredentials) {
|
|
66381
66496
|
this.sweepTimer = setInterval(() => {
|
|
66382
|
-
const
|
|
66383
|
-
if (this.fullBy.size > 0 &&
|
|
66497
|
+
const read2 = this.credentialRead();
|
|
66498
|
+
if (this.fullBy.size > 0 && read2) this.sweepWithdrawn(read2);
|
|
66384
66499
|
}, opts.credentialSweepMs ?? 1e3);
|
|
66385
66500
|
this.sweepTimer.unref?.();
|
|
66386
66501
|
}
|
|
@@ -66628,13 +66743,13 @@ var HostServer = class _HostServer {
|
|
|
66628
66743
|
* Before, such a socket kept full rights for as long as it stayed open, while no listing showed the credential. The
|
|
66629
66744
|
* peer sees 4001 "credential withdrawn": a hub reads its connection line again and pairs anew
|
|
66630
66745
|
*/
|
|
66631
|
-
sweepWithdrawn(
|
|
66746
|
+
sweepWithdrawn(read2) {
|
|
66632
66747
|
for (const [ws2, held2] of this.fullBy) {
|
|
66633
|
-
const still = held2.publicKey === void 0 ?
|
|
66748
|
+
const still = held2.publicKey === void 0 ? read2.open.some((c) => c.id === held2.id) : (read2.openKeys ?? []).some((k2) => k2.id === held2.id && k2.publicKey === held2.publicKey);
|
|
66634
66749
|
if (still) continue;
|
|
66635
66750
|
this.fullBy.delete(ws2);
|
|
66636
66751
|
this.hubLinks.delete(ws2);
|
|
66637
|
-
this.refuse(ws2, CLOSE_AUTH,
|
|
66752
|
+
this.refuse(ws2, CLOSE_AUTH, read2.unreadable ? CREDENTIAL_FILE_UNREADABLE : "credential withdrawn");
|
|
66638
66753
|
}
|
|
66639
66754
|
}
|
|
66640
66755
|
/** The full credentials as `fullCredentials` reads them now, whole; null on a host without them */
|
|
@@ -66692,13 +66807,13 @@ var HostServer = class _HostServer {
|
|
|
66692
66807
|
if (proved) return this.refuse(ws2, CLOSE_AUTH, "not a hello");
|
|
66693
66808
|
proved = true;
|
|
66694
66809
|
const ask = frame.data;
|
|
66695
|
-
const
|
|
66696
|
-
if (ask.key !== void 0 &&
|
|
66810
|
+
const read2 = this.credentialRead();
|
|
66811
|
+
if (ask.key !== void 0 && read2) {
|
|
66697
66812
|
const answer = answerKeyProve({
|
|
66698
66813
|
signing: this.signing,
|
|
66699
66814
|
nonce: ask.nonce,
|
|
66700
66815
|
keyId: ask.key,
|
|
66701
|
-
entry: (
|
|
66816
|
+
entry: (read2.openKeys ?? []).find((k2) => k2.id === ask.key),
|
|
66702
66817
|
address: linkAddressOf(this.opts.frontDoor, req.socket.localAddress, req.socket.localPort)
|
|
66703
66818
|
});
|
|
66704
66819
|
if ("refused" in answer) return this.refuse(ws2, CLOSE_AUTH, answer.refused === "withdrawn" ? "credential withdrawn" : "not a hello");
|
|
@@ -66706,8 +66821,8 @@ var HostServer = class _HostServer {
|
|
|
66706
66821
|
this.sendTo(ws2, JSON.stringify({ kind: "proof", nonce: ask.nonce, mac: hostProof(this.opts.token, ask.nonce), ...answer.fields }));
|
|
66707
66822
|
return;
|
|
66708
66823
|
}
|
|
66709
|
-
const
|
|
66710
|
-
const mac5 =
|
|
66824
|
+
const named3 = ask.credential ? read2?.open.find((c) => c.id === ask.credential) : void 0;
|
|
66825
|
+
const mac5 = named3 ? credentialProof(named3.verifier, ask.nonce) : hostProof(this.opts.token, ask.nonce);
|
|
66711
66826
|
this.sendTo(ws2, JSON.stringify({ kind: "proof", nonce: ask.nonce, mac: mac5 }));
|
|
66712
66827
|
return;
|
|
66713
66828
|
}
|
|
@@ -66911,7 +67026,7 @@ var HostServer = class _HostServer {
|
|
|
66911
67026
|
if (!call2) return;
|
|
66912
67027
|
if (a.ok) return call2.resolve(a.result);
|
|
66913
67028
|
const e = a.error;
|
|
66914
|
-
call2.reject(rpcError(e?.message ?? "The other side refused the call", e?.code ?? "internal", { retryable: e?.retryable === true, ...e?.data !== void 0 ? { data: e.data } : {} }));
|
|
67029
|
+
call2.reject(peerAnswer(rpcError(e?.message ?? "The other side refused the call", e?.code ?? "internal", { retryable: e?.retryable === true, ...e?.data !== void 0 ? { data: e.data } : {} })));
|
|
66915
67030
|
}
|
|
66916
67031
|
/** Every call still waiting on a socket that is gone gets its answer: its outcome there is unknown */
|
|
66917
67032
|
failCalls(ws2, why2) {
|
|
@@ -67799,11 +67914,11 @@ var PendingRequests = class {
|
|
|
67799
67914
|
* The answer to `id`, or a rejection once `timeoutMs` has passed without one: an `Error` with `timeout` as its text, or
|
|
67800
67915
|
* the error `timeout()` makes (one that carries a code or `retryable`)
|
|
67801
67916
|
*/
|
|
67802
|
-
wait(id3, timeoutMs,
|
|
67917
|
+
wait(id3, timeoutMs, timeout2) {
|
|
67803
67918
|
const key = String(id3);
|
|
67804
67919
|
return new Promise((resolve21, reject) => {
|
|
67805
67920
|
const timer = setTimeout(() => {
|
|
67806
|
-
if (this.waiting.delete(key)) reject(typeof
|
|
67921
|
+
if (this.waiting.delete(key)) reject(typeof timeout2 === "string" ? new Error(timeout2) : timeout2());
|
|
67807
67922
|
}, timeoutMs);
|
|
67808
67923
|
timer.unref?.();
|
|
67809
67924
|
this.waiting.set(key, { resolve: resolve21, reject, timer });
|
|
@@ -68105,9 +68220,9 @@ function hasProcessGroups(platform = process.platform) {
|
|
|
68105
68220
|
}
|
|
68106
68221
|
var REAL_OS = {
|
|
68107
68222
|
platform: process.platform,
|
|
68108
|
-
taskkill: (pid) => {
|
|
68223
|
+
taskkill: (pid, alone = false) => {
|
|
68109
68224
|
const exe = systemTool2(["taskkill.exe"]);
|
|
68110
|
-
execFileSync2(exe, ["/PID", String(pid), "/T", "/F"], { stdio: ["ignore", "ignore", "pipe"], timeout: 5e3, windowsHide: true });
|
|
68225
|
+
execFileSync2(exe, ["/PID", String(pid), ...alone ? [] : ["/T"], "/F"], { stdio: ["ignore", "ignore", "pipe"], timeout: 5e3, windowsHide: true });
|
|
68111
68226
|
}
|
|
68112
68227
|
};
|
|
68113
68228
|
function shootWindows(handle2, os2) {
|
|
@@ -68211,38 +68326,93 @@ function orphansOf(rows3, root3) {
|
|
|
68211
68326
|
var runFile = promisify(execFile);
|
|
68212
68327
|
var LIST_PROCESSES = "Get-CimInstance Win32_Process | ForEach-Object { if ($_.CreationDate) { '{0} {1} {2}' -f $_.ProcessId, $_.ParentProcessId, ([DateTimeOffset]$_.CreationDate).ToUnixTimeMilliseconds() } }";
|
|
68213
68328
|
var leftoverOs = (run4) => ({
|
|
68214
|
-
listProcesses: async () => {
|
|
68329
|
+
listProcesses: async (timeoutMs = 6e4) => {
|
|
68215
68330
|
const exe = systemTool2(["WindowsPowerShell", "v1.0", "powershell.exe"]);
|
|
68216
|
-
const { stdout } = await run4(exe, ["-NoProfile", "-NonInteractive", "-Command", LIST_PROCESSES], { timeout:
|
|
68331
|
+
const { stdout } = await run4(exe, ["-NoProfile", "-NonInteractive", "-Command", LIST_PROCESSES], { timeout: timeoutMs, windowsHide: true });
|
|
68217
68332
|
return parseWinProcs(stdout);
|
|
68218
68333
|
},
|
|
68219
|
-
taskkill
|
|
68334
|
+
// Asynchronous, so a tree of many processes does not hold the host's thread for each taskkill (about 40 ms each)
|
|
68335
|
+
taskkill: async (pid, alone = false) => {
|
|
68336
|
+
await run4(systemTool2(["taskkill.exe"]), ["/PID", String(pid), ...alone ? [] : ["/T"], "/F"], { timeout: 5e3, windowsHide: true });
|
|
68337
|
+
}
|
|
68220
68338
|
});
|
|
68221
68339
|
var REAL_LEFTOVER_OS = leftoverOs(runFile);
|
|
68222
68340
|
async function collectOrphansWindows(root3, os2 = REAL_LEFTOVER_OS) {
|
|
68341
|
+
return collectAllOrphansWindows([root3], os2);
|
|
68342
|
+
}
|
|
68343
|
+
async function collectAllOrphansWindows(roots, os2 = REAL_LEFTOVER_OS) {
|
|
68344
|
+
if (roots.length === 0) return [];
|
|
68223
68345
|
let rows3;
|
|
68224
68346
|
try {
|
|
68225
68347
|
rows3 = await os2.listProcesses();
|
|
68226
68348
|
} catch (e) {
|
|
68227
|
-
const
|
|
68228
|
-
console.error(`[agent-host] the process table could not be read (${
|
|
68349
|
+
const pids = roots.map((r) => r.pid).join(", ");
|
|
68350
|
+
console.error(`[agent-host] the process table could not be read (${unread(e)}); what process ${pids} left running may still run`);
|
|
68229
68351
|
return [];
|
|
68230
68352
|
}
|
|
68231
|
-
const
|
|
68232
|
-
|
|
68233
|
-
|
|
68234
|
-
const
|
|
68235
|
-
|
|
68353
|
+
const ended2 = [];
|
|
68354
|
+
for (const root3 of roots) {
|
|
68355
|
+
const found = orphansOf(rows3, root3);
|
|
68356
|
+
const turnedAway = rows3.filter((r) => r.ppid === root3.pid && r.pid !== root3.pid && !found.includes(r));
|
|
68357
|
+
if (turnedAway.length > 0) {
|
|
68358
|
+
const list2 = turnedAway.map((r) => `${r.pid} (created ${r.created})`).join(", ");
|
|
68359
|
+
console.error(`[agent-host] process ${root3.pid} ran from ${root3.spawnedAt} to ${root3.exitedAt}; its children created outside that were left alone: ${list2}`);
|
|
68360
|
+
}
|
|
68361
|
+
ended2.push(...await endInOrder(found, root3.pid, os2));
|
|
68362
|
+
}
|
|
68363
|
+
return ended2;
|
|
68364
|
+
}
|
|
68365
|
+
var STOP_LIST_MS = 1500;
|
|
68366
|
+
async function stopTreeWindows(root3, endRoot, os2 = REAL_LEFTOVER_OS) {
|
|
68367
|
+
return stopTreesWindows([{ ...root3, endRoot }], os2);
|
|
68368
|
+
}
|
|
68369
|
+
async function stopTreesWindows(roots, os2 = REAL_LEFTOVER_OS) {
|
|
68370
|
+
if (roots.length === 0) return [];
|
|
68371
|
+
let rows3;
|
|
68372
|
+
try {
|
|
68373
|
+
rows3 = await within(os2.listProcesses(STOP_LIST_MS), STOP_LIST_MS);
|
|
68374
|
+
} catch (e) {
|
|
68375
|
+
const pids = roots.map((r) => r.pid).join(", ");
|
|
68376
|
+
console.error(`[agent-host] the process table could not be read (${unread(e)}); process ${pids} and what it started are ended with taskkill /T, in no order`);
|
|
68377
|
+
for (const root3 of roots) {
|
|
68378
|
+
try {
|
|
68379
|
+
await os2.taskkill(root3.pid);
|
|
68380
|
+
} catch {
|
|
68381
|
+
root3.endRoot();
|
|
68382
|
+
}
|
|
68383
|
+
}
|
|
68384
|
+
return [];
|
|
68236
68385
|
}
|
|
68386
|
+
const now = Date.now();
|
|
68387
|
+
const trees = roots.map((root3) => ({ root: root3, tree: orphansOf(rows3, { pid: root3.pid, spawnedAt: root3.spawnedAt, exitedAt: now }) }));
|
|
68388
|
+
for (const { root: root3 } of trees) root3.endRoot();
|
|
68237
68389
|
const ended2 = [];
|
|
68390
|
+
for (const { root: root3, tree } of trees) ended2.push(...await endInOrder(tree, root3.pid, os2));
|
|
68391
|
+
return ended2;
|
|
68392
|
+
}
|
|
68393
|
+
function within(p, ms3) {
|
|
68394
|
+
return new Promise((resolve21, reject) => {
|
|
68395
|
+
const timer = setTimeout(() => reject(Object.assign(new Error("timed out"), { killed: true })), ms3);
|
|
68396
|
+
p.then(
|
|
68397
|
+
(v) => (clearTimeout(timer), resolve21(v)),
|
|
68398
|
+
(e) => (clearTimeout(timer), reject(e instanceof Error ? e : new Error(String(e))))
|
|
68399
|
+
);
|
|
68400
|
+
});
|
|
68401
|
+
}
|
|
68402
|
+
function unread(e) {
|
|
68403
|
+
return typeof e === "object" && e !== null && "killed" in e && e.killed ? "timed out" : e instanceof Error ? e.message : "unknown error";
|
|
68404
|
+
}
|
|
68405
|
+
async function endInOrder(found, by, os2) {
|
|
68406
|
+
const ended2 = [];
|
|
68407
|
+
const parents = new Set(found.map((r) => r.ppid));
|
|
68238
68408
|
for (const r of found) {
|
|
68239
68409
|
if (r.pid === process.pid) continue;
|
|
68240
68410
|
try {
|
|
68241
|
-
os2.taskkill(r.pid);
|
|
68411
|
+
await os2.taskkill(r.pid, parents.has(r.pid));
|
|
68242
68412
|
ended2.push(r.pid);
|
|
68243
68413
|
} catch (e) {
|
|
68244
|
-
const status = typeof e === "object" && e !== null
|
|
68245
|
-
if (status !== 128) console.error(`[agent-host] process ${r.pid}, left running by ${
|
|
68414
|
+
const status = typeof e === "object" && e !== null ? "status" in e ? e.status : "code" in e ? e.code : void 0 : void 0;
|
|
68415
|
+
if (status !== 128) console.error(`[agent-host] process ${r.pid}, left running by ${by}, could not be ended (status ${String(status)}: ${e instanceof Error ? e.message.replace(/\s+/g, " ").trim() : "unknown error"})`);
|
|
68246
68416
|
}
|
|
68247
68417
|
}
|
|
68248
68418
|
return ended2;
|
|
@@ -68818,7 +68988,7 @@ var files = {
|
|
|
68818
68988
|
promises
|
|
68819
68989
|
};
|
|
68820
68990
|
var RealChild = class extends EventEmitter {
|
|
68821
|
-
constructor(started, spawnedAt,
|
|
68991
|
+
constructor(started, spawnedAt, failed4) {
|
|
68822
68992
|
super();
|
|
68823
68993
|
this.started = started;
|
|
68824
68994
|
this.node = started?.child ?? null;
|
|
@@ -68829,7 +68999,7 @@ var RealChild = class extends EventEmitter {
|
|
|
68829
68999
|
this.exited = new Promise((resolve21) => {
|
|
68830
69000
|
if (!node) {
|
|
68831
69001
|
process.nextTick(() => {
|
|
68832
|
-
const error51 =
|
|
69002
|
+
const error51 = failed4 ?? asOsError(new Error("not started"));
|
|
68833
69003
|
this.emit("error", error51);
|
|
68834
69004
|
resolve21({ code: null, signal: null, error: error51 });
|
|
68835
69005
|
});
|
|
@@ -68925,11 +69095,39 @@ async function stop(child, graceMs, o = {}) {
|
|
|
68925
69095
|
throw new TypeError("realOs().processes.stop: a child the real OS started");
|
|
68926
69096
|
const node = child.node;
|
|
68927
69097
|
const running2 = () => node !== null && node.exitCode === null && node.signalCode === null;
|
|
68928
|
-
|
|
69098
|
+
const groups = traits.hasProcessGroups;
|
|
69099
|
+
if (node?.pid !== void 0 && running2()) {
|
|
69100
|
+
if (groups) stopTree(killHandle(node), graceMs, running2);
|
|
69101
|
+
else await stopTreeWindows({ pid: node.pid, spawnedAt: child.started?.spawnedAt ?? child.spawnedAt }, () => void (running2() && node.kill()));
|
|
69102
|
+
}
|
|
68929
69103
|
const exit = await child.exited;
|
|
68930
69104
|
if (child.started && o.sweep !== false) await sweepLeftovers(child.started);
|
|
68931
69105
|
return { code: exit.code, signal: exit.signal };
|
|
68932
69106
|
}
|
|
69107
|
+
async function stopAll(children, graceMs) {
|
|
69108
|
+
if (traits.hasProcessGroups) {
|
|
69109
|
+
await Promise.all(children.map((c) => stop(c, graceMs).catch(() => {
|
|
69110
|
+
})));
|
|
69111
|
+
return;
|
|
69112
|
+
}
|
|
69113
|
+
const real3 = children.map((c) => {
|
|
69114
|
+
if (!(c instanceof RealChild)) throw new TypeError("realOs().processes.stopAll: children the real OS started");
|
|
69115
|
+
return c;
|
|
69116
|
+
});
|
|
69117
|
+
const alive2 = (node) => node.exitCode === null && node.signalCode === null;
|
|
69118
|
+
const roots = real3.flatMap((c) => {
|
|
69119
|
+
const node = c.node;
|
|
69120
|
+
if (node?.pid === void 0 || !alive2(node)) return [];
|
|
69121
|
+
return [{ pid: node.pid, spawnedAt: c.started?.spawnedAt ?? c.spawnedAt, endRoot: () => void (alive2(node) && node.kill()) }];
|
|
69122
|
+
});
|
|
69123
|
+
await stopTreesWindows(roots);
|
|
69124
|
+
await Promise.all(real3.map((c) => c.exited));
|
|
69125
|
+
const ended2 = real3.flatMap((c) => {
|
|
69126
|
+
const pid = c.started?.child.pid;
|
|
69127
|
+
return c.started && pid !== void 0 ? [{ pid, spawnedAt: c.started.spawnedAt, exitedAt: c.started.exitedAt() ?? Date.now() }] : [];
|
|
69128
|
+
});
|
|
69129
|
+
await collectAllOrphansWindows(ended2);
|
|
69130
|
+
}
|
|
68933
69131
|
function runSync(command, args, o = {}) {
|
|
68934
69132
|
const r = spawnSync2(command, [...args], {
|
|
68935
69133
|
cwd: o.cwd,
|
|
@@ -68989,6 +69187,7 @@ var realOsValue = {
|
|
|
68989
69187
|
o
|
|
68990
69188
|
),
|
|
68991
69189
|
stop,
|
|
69190
|
+
stopAll,
|
|
68992
69191
|
alive: (pid) => {
|
|
68993
69192
|
try {
|
|
68994
69193
|
process.kill(pid, 0);
|
|
@@ -69123,11 +69322,13 @@ function gitEnv(own) {
|
|
|
69123
69322
|
return { ...process.env, ...own, LC_ALL: "C.UTF-8", LANGUAGE: "C" };
|
|
69124
69323
|
}
|
|
69125
69324
|
var live = /* @__PURE__ */ new Set();
|
|
69126
|
-
|
|
69325
|
+
var running = (child) => child.exitCode === null && child.signalCode === null;
|
|
69326
|
+
function runOptions(cwd, env, timeoutMs, signal) {
|
|
69127
69327
|
return {
|
|
69128
69328
|
cwd,
|
|
69129
69329
|
env: gitEnv(env),
|
|
69130
69330
|
timeoutMs,
|
|
69331
|
+
signal,
|
|
69131
69332
|
onChild: (child) => {
|
|
69132
69333
|
live.add(child);
|
|
69133
69334
|
const gone = () => live.delete(child);
|
|
@@ -69137,24 +69338,20 @@ function runOptions(cwd, env, timeoutMs) {
|
|
|
69137
69338
|
};
|
|
69138
69339
|
}
|
|
69139
69340
|
var GIT_STOP_GRACE_MS = 2e3;
|
|
69140
|
-
var running = (child) => child.exitCode === null && child.signalCode === null;
|
|
69141
69341
|
async function stopGitChildren(graceMs = GIT_STOP_GRACE_MS) {
|
|
69142
69342
|
const children = [...live].filter(running);
|
|
69143
69343
|
if (children.length === 0) return;
|
|
69144
|
-
|
|
69145
|
-
|
|
69146
|
-
});
|
|
69147
|
-
await raceTimeout(exited, graceMs + 1e3, void 0);
|
|
69344
|
+
await raceTimeout(realOs().processes.stopAll(children, graceMs).catch(() => {
|
|
69345
|
+
}), graceMs + 1e3, void 0);
|
|
69148
69346
|
}
|
|
69149
69347
|
async function runGit(cwd, args, opts = {}) {
|
|
69150
69348
|
const argv = await gitArgv(cwd, args, opts.allowRepoPrograms, opts.filters);
|
|
69151
69349
|
if (opts.signal?.aborted) throw gitCancelled();
|
|
69152
|
-
const
|
|
69350
|
+
const timeout2 = opts.timeout ?? DEFAULTS.timeout;
|
|
69153
69351
|
const r = await realOs().processes.run(programPath("git"), argv, {
|
|
69154
|
-
...runOptions(cwd, opts.env,
|
|
69352
|
+
...runOptions(cwd, opts.env, timeout2, opts.signal),
|
|
69155
69353
|
input: opts.input ?? "",
|
|
69156
69354
|
maxBuffer: opts.maxBuffer ?? DEFAULTS.maxBuffer,
|
|
69157
|
-
signal: opts.signal,
|
|
69158
69355
|
stdoutFile: opts.outputFile
|
|
69159
69356
|
});
|
|
69160
69357
|
const out = r.stdout.toString("utf8");
|
|
@@ -69163,7 +69360,7 @@ async function runGit(cwd, args, opts = {}) {
|
|
|
69163
69360
|
if ((!ended2 || ended2 === "aborted") && code2 === 0) return out;
|
|
69164
69361
|
if (ended2 === "aborted") throw Object.assign(gitCancelled(), { signal, stdout: out, stderr: err });
|
|
69165
69362
|
if (ended2 === "timeout" || ended2 === "overflow") {
|
|
69166
|
-
const message = ended2 === "timeout" ? `git did not answer within ${
|
|
69363
|
+
const message = ended2 === "timeout" ? `git did not answer within ${timeout2} ms` : "Git output exceeded maxBuffer";
|
|
69167
69364
|
throw Object.assign(new Error(message), { code: code2, signal, stdout: "", stderr: "", ...ended2 === "timeout" ? { timedOut: true, killed: true } : {} });
|
|
69168
69365
|
}
|
|
69169
69366
|
throw Object.assign(new Error(err || `Git exited with ${code2 ?? signal}`), { code: code2, signal, stdout: out, stderr: err });
|
|
@@ -81576,11 +81773,11 @@ var Protocol = class {
|
|
|
81576
81773
|
if (notification.params.requestId === void 0) return;
|
|
81577
81774
|
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
81578
81775
|
}
|
|
81579
|
-
_setupTimeout(messageId,
|
|
81776
|
+
_setupTimeout(messageId, timeout2, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
81580
81777
|
this._timeoutInfo.set(messageId, {
|
|
81581
|
-
timeoutId: setTimeout(onTimeout,
|
|
81778
|
+
timeoutId: setTimeout(onTimeout, timeout2),
|
|
81582
81779
|
startTime: Date.now(),
|
|
81583
|
-
timeout,
|
|
81780
|
+
timeout: timeout2,
|
|
81584
81781
|
maxTotalTimeout,
|
|
81585
81782
|
resetTimeoutOnProgress,
|
|
81586
81783
|
onTimeout
|
|
@@ -82022,9 +82219,9 @@ var Protocol = class {
|
|
|
82022
82219
|
});
|
|
82023
82220
|
onAbort = () => cancel(options?.signal?.reason);
|
|
82024
82221
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
82025
|
-
const
|
|
82026
|
-
const timeoutHandler = () => cancel(new SdkError(SdkErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
82027
|
-
this._setupTimeout(messageId,
|
|
82222
|
+
const timeout2 = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
82223
|
+
const timeoutHandler = () => cancel(new SdkError(SdkErrorCode.RequestTimeout, "Request timed out", { timeout: timeout2 }));
|
|
82224
|
+
this._setupTimeout(messageId, timeout2, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
82028
82225
|
this._transport.send(outbound, {
|
|
82029
82226
|
relatedRequestId,
|
|
82030
82227
|
resumptionToken,
|
|
@@ -85705,14 +85902,14 @@ function declaredRisk(tool) {
|
|
|
85705
85902
|
function namedArguments(tool, key) {
|
|
85706
85903
|
const v = tool._meta?.[key];
|
|
85707
85904
|
if (typeof v !== "object" || v === null || Array.isArray(v)) return null;
|
|
85708
|
-
const
|
|
85709
|
-
if (Object.keys(
|
|
85710
|
-
return Object.values(
|
|
85905
|
+
const named3 = Object.fromEntries(Object.entries(v));
|
|
85906
|
+
if (Object.keys(named3).length === 0) return null;
|
|
85907
|
+
return Object.values(named3).every((x) => typeof x === "boolean" || typeof x === "string" || typeof x === "number") ? named3 : null;
|
|
85711
85908
|
}
|
|
85712
85909
|
var askWhen = (tool) => namedArguments(tool, ASK_WHEN_META_KEY);
|
|
85713
85910
|
var askUnless = (tool) => namedArguments(tool, ASK_UNLESS_META_KEY);
|
|
85714
85911
|
var ANY_VALUE = "*";
|
|
85715
|
-
var matches = (given,
|
|
85912
|
+
var matches = (given, named3) => named3 === ANY_VALUE ? given !== void 0 && given !== null && given !== "" : given === named3;
|
|
85716
85913
|
function runsUnasked(tool, scope) {
|
|
85717
85914
|
const risk = declaredRisk(tool);
|
|
85718
85915
|
if (risk === "local") return true;
|
|
@@ -85765,11 +85962,11 @@ function checkTools(manifest, tools) {
|
|
|
85765
85962
|
)
|
|
85766
85963
|
);
|
|
85767
85964
|
}
|
|
85768
|
-
for (const [key,
|
|
85965
|
+
for (const [key, read2] of [[ASK_WHEN_META_KEY, askWhen], [ASK_UNLESS_META_KEY, askUnless]]) {
|
|
85769
85966
|
if (t._meta?.[key] === void 0) continue;
|
|
85770
85967
|
if (declaredRisk(t) !== "routine")
|
|
85771
85968
|
findings.push(warning(where2, `_meta["${key}"] does nothing here \u2014 only a tool that declares "${RISK_META_KEY}": "routine" reads it, and any other write asks`));
|
|
85772
|
-
else if (!
|
|
85969
|
+
else if (!read2(t))
|
|
85773
85970
|
findings.push(
|
|
85774
85971
|
warning(where2, `_meta["${key}"] must be an object of argument names and plain values (true, false, a string, a number or "*"), such as { "push": true }; the host cannot read it, so the tool always asks`)
|
|
85775
85972
|
);
|
|
@@ -85797,10 +85994,10 @@ function checkTools(manifest, tools) {
|
|
|
85797
85994
|
}
|
|
85798
85995
|
return { findings, tools: summaries, screens: [...screens2] };
|
|
85799
85996
|
}
|
|
85800
|
-
function checkScreen(uri,
|
|
85997
|
+
function checkScreen(uri, read2) {
|
|
85801
85998
|
const where2 = `screen ${uri}`;
|
|
85802
|
-
if (
|
|
85803
|
-
const content =
|
|
85999
|
+
if (read2 instanceof Error) return { findings: [problem(where2, `could not be read: ${read2.message.split("\n")[0]}`)], chars: 0 };
|
|
86000
|
+
const content = read2.contents.find((c) => c.uri === uri) ?? read2.contents[0];
|
|
85804
86001
|
if (!content) return { findings: [problem(where2, "it was read but came back empty (no contents)")], chars: 0 };
|
|
85805
86002
|
const findings = [];
|
|
85806
86003
|
if (!isViewMimeType(content.mimeType)) {
|
|
@@ -85903,13 +86100,13 @@ async function checkApp(host, ref) {
|
|
|
85903
86100
|
findings.push(...t.findings.map(maskFinding));
|
|
85904
86101
|
tools = t.tools.map((x) => ({ ...x, name: mask(x.name), screen: x.screen === null ? null : mask(x.screen) }));
|
|
85905
86102
|
for (const uri of t.screens) {
|
|
85906
|
-
let
|
|
86103
|
+
let read2;
|
|
85907
86104
|
try {
|
|
85908
|
-
|
|
86105
|
+
read2 = await proc.client.readResource({ uri }, { timeout: host.timing.connectTimeoutMs });
|
|
85909
86106
|
} catch (err) {
|
|
85910
|
-
|
|
86107
|
+
read2 = err;
|
|
85911
86108
|
}
|
|
85912
|
-
const s = checkScreen(uri,
|
|
86109
|
+
const s = checkScreen(uri, read2);
|
|
85913
86110
|
findings.push(...s.findings.map(maskFinding));
|
|
85914
86111
|
screens2.push({ uri: mask(uri), chars: s.chars });
|
|
85915
86112
|
}
|
|
@@ -86123,10 +86320,10 @@ function readManifestText(root3, manifestRel) {
|
|
|
86123
86320
|
}
|
|
86124
86321
|
}
|
|
86125
86322
|
function readApp(root3, folderRel, folder, dir) {
|
|
86126
|
-
const
|
|
86127
|
-
if ("missing" in
|
|
86128
|
-
if ("error" in
|
|
86129
|
-
const { text: text3 } =
|
|
86323
|
+
const read2 = readManifestText(root3, `${folderRel}/${MANIFEST_FILE}`);
|
|
86324
|
+
if ("missing" in read2) return invalid(folder, dir, `there is no ${MANIFEST_FILE}`);
|
|
86325
|
+
if ("error" in read2) return invalid(folder, dir, read2.error);
|
|
86326
|
+
const { text: text3 } = read2;
|
|
86130
86327
|
const hash2 = createHash6("sha256").update(text3).digest("hex");
|
|
86131
86328
|
const parsed = parseManifest(text3);
|
|
86132
86329
|
if (!parsed.ok) return { folder, dir, hash: hash2, manifest: null, error: parsed.error, warnings: parsed.warnings };
|
|
@@ -86144,19 +86341,19 @@ function readApp(root3, folderRel, folder, dir) {
|
|
|
86144
86341
|
}
|
|
86145
86342
|
var BROKEN_ROOT_APP_ID = "centralu-root";
|
|
86146
86343
|
function scanRootApp(root3, taken) {
|
|
86147
|
-
const
|
|
86148
|
-
if ("missing" in
|
|
86344
|
+
const read2 = readManifestText(root3, MANIFEST_FILE);
|
|
86345
|
+
if ("missing" in read2) return null;
|
|
86149
86346
|
const rootApp = (id4, rest) => ({
|
|
86150
86347
|
folder: id4,
|
|
86151
86348
|
dir: root3,
|
|
86152
86349
|
root: true,
|
|
86153
86350
|
...rest
|
|
86154
86351
|
});
|
|
86155
|
-
if ("error" in
|
|
86156
|
-
const hash2 = createHash6("sha256").update(
|
|
86157
|
-
const parsed = parseManifest(
|
|
86352
|
+
if ("error" in read2) return rootApp(BROKEN_ROOT_APP_ID, { hash: null, manifest: null, error: read2.error, warnings: [] });
|
|
86353
|
+
const hash2 = createHash6("sha256").update(read2.text).digest("hex");
|
|
86354
|
+
const parsed = parseManifest(read2.text);
|
|
86158
86355
|
if (!parsed.ok) {
|
|
86159
|
-
const id4 = rawId(
|
|
86356
|
+
const id4 = rawId(read2.text);
|
|
86160
86357
|
return rootApp(id4 !== null && !taken.includes(id4) ? id4 : BROKEN_ROOT_APP_ID, { hash: hash2, manifest: null, error: parsed.error, warnings: parsed.warnings });
|
|
86161
86358
|
}
|
|
86162
86359
|
const { id: id3 } = parsed.manifest;
|
|
@@ -90363,11 +90560,11 @@ var Protocol2 = class {
|
|
|
90363
90560
|
if (notification.params.requestId === void 0) return;
|
|
90364
90561
|
this._requestHandlerAbortControllers.get(notification.params.requestId)?.abort(notification.params.reason);
|
|
90365
90562
|
}
|
|
90366
|
-
_setupTimeout(messageId,
|
|
90563
|
+
_setupTimeout(messageId, timeout2, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
90367
90564
|
this._timeoutInfo.set(messageId, {
|
|
90368
|
-
timeoutId: setTimeout(onTimeout,
|
|
90565
|
+
timeoutId: setTimeout(onTimeout, timeout2),
|
|
90369
90566
|
startTime: Date.now(),
|
|
90370
|
-
timeout,
|
|
90567
|
+
timeout: timeout2,
|
|
90371
90568
|
maxTotalTimeout,
|
|
90372
90569
|
resetTimeoutOnProgress,
|
|
90373
90570
|
onTimeout
|
|
@@ -90809,9 +91006,9 @@ var Protocol2 = class {
|
|
|
90809
91006
|
});
|
|
90810
91007
|
onAbort = () => cancel(options?.signal?.reason);
|
|
90811
91008
|
options?.signal?.addEventListener("abort", onAbort, { once: true });
|
|
90812
|
-
const
|
|
90813
|
-
const timeoutHandler = () => cancel(new SdkError2(SdkErrorCode2.RequestTimeout, "Request timed out", { timeout }));
|
|
90814
|
-
this._setupTimeout(messageId,
|
|
91009
|
+
const timeout2 = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC2;
|
|
91010
|
+
const timeoutHandler = () => cancel(new SdkError2(SdkErrorCode2.RequestTimeout, "Request timed out", { timeout: timeout2 }));
|
|
91011
|
+
this._setupTimeout(messageId, timeout2, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
90815
91012
|
this._transport.send(outbound, {
|
|
90816
91013
|
relatedRequestId,
|
|
90817
91014
|
resumptionToken,
|
|
@@ -102670,9 +102867,9 @@ var EOCD_SEARCH = 22 + 65535;
|
|
|
102670
102867
|
function readZipEntries(buf, maxEntries) {
|
|
102671
102868
|
return readZipEntriesFrom(buf.length, (pos, len) => buf.subarray(pos, pos + len), maxEntries);
|
|
102672
102869
|
}
|
|
102673
|
-
function readZipEntriesFrom(size2,
|
|
102870
|
+
function readZipEntriesFrom(size2, read2, maxEntries) {
|
|
102674
102871
|
const tailStart = Math.max(0, size2 - EOCD_SEARCH);
|
|
102675
|
-
const tail =
|
|
102872
|
+
const tail = read2(tailStart, size2 - tailStart);
|
|
102676
102873
|
let at2 = -1;
|
|
102677
102874
|
for (let i = tail.length - 22; i >= 0; i--) {
|
|
102678
102875
|
if (tail.readUInt32LE(i) === EOCD) {
|
|
@@ -102691,7 +102888,7 @@ function readZipEntriesFrom(size2, read, maxEntries) {
|
|
|
102691
102888
|
if (total === 65535 || cdSize === 4294967295 || cdOffset === 4294967295) throw new ZipError("ZIP64 archives are not supported");
|
|
102692
102889
|
if (total > maxEntries) throw new ZipError(`The archive has ${total} entries; at most ${maxEntries} are accepted`);
|
|
102693
102890
|
if (cdOffset + cdSize > end) throw new ZipError("The zip file is damaged (central directory out of range)");
|
|
102694
|
-
const cd2 =
|
|
102891
|
+
const cd2 = read2(cdOffset, end - cdOffset);
|
|
102695
102892
|
const limit = cd2.length;
|
|
102696
102893
|
const out = [];
|
|
102697
102894
|
let p = 0;
|
|
@@ -102750,8 +102947,8 @@ function zipEntryBytes(buf, e) {
|
|
|
102750
102947
|
const start3 = zipEntryStart(buf.length, (pos, len) => buf.subarray(pos, pos + len), e);
|
|
102751
102948
|
return buf.subarray(start3, start3 + e.compressedSize);
|
|
102752
102949
|
}
|
|
102753
|
-
function zipEntryStart(size2,
|
|
102754
|
-
const head = e.offset + 30 <= size2 ?
|
|
102950
|
+
function zipEntryStart(size2, read2, e) {
|
|
102951
|
+
const head = e.offset + 30 <= size2 ? read2(e.offset, 30) : null;
|
|
102755
102952
|
if (!head || head.length < 30 || head.readUInt32LE(0) !== LOC) throw new ZipError(`The zip file is damaged (bad local header): ${e.name}`);
|
|
102756
102953
|
const start3 = e.offset + 30 + head.readUInt16LE(26) + head.readUInt16LE(28);
|
|
102757
102954
|
if (start3 + e.compressedSize > size2) throw new ZipError(`The zip file is damaged (data out of range): ${e.name}`);
|
|
@@ -102827,8 +103024,8 @@ function httpsProblem(url2) {
|
|
|
102827
103024
|
if (url2.protocol !== "https:") return `Only https links can be downloaded: ${url2.href}`;
|
|
102828
103025
|
if (url2.username || url2.password) return "Links with a user name or password in them are not accepted";
|
|
102829
103026
|
if (isThisMachineHost(url2.hostname)) {
|
|
102830
|
-
const
|
|
102831
|
-
return
|
|
103027
|
+
const named3 = url2.hostname === "localhost" || url2.hostname.endsWith(".localhost");
|
|
103028
|
+
return named3 ? `A link to this machine cannot be downloaded: ${url2.href}` : `A link to this machine or a link-local address cannot be downloaded: ${url2.href}`;
|
|
102832
103029
|
}
|
|
102833
103030
|
return null;
|
|
102834
103031
|
}
|
|
@@ -102982,14 +103179,14 @@ function stageZip(buf, dest, limits) {
|
|
|
102982
103179
|
} catch (e) {
|
|
102983
103180
|
throw new ImportRefused(e.message);
|
|
102984
103181
|
}
|
|
102985
|
-
const
|
|
102986
|
-
const visible =
|
|
103182
|
+
const named3 = entries.map((e) => ({ e, parts: zipParts(e.name, limits) })).filter((x) => x.parts.length > 0);
|
|
103183
|
+
const visible = named3.filter((x) => !hiddenPart(x.parts[0]));
|
|
102987
103184
|
const top = new Set(visible.map((x) => x.parts[0]));
|
|
102988
103185
|
const strip = !visible.some((x) => x.parts.length === 1 && x.parts[0] === MANIFEST_FILE) && top.size === 1 && visible.every((x) => x.parts.length > 1 || x.e.kind === "dir");
|
|
102989
103186
|
const t = new Tally(limits);
|
|
102990
103187
|
const plan = [];
|
|
102991
103188
|
const seen = /* @__PURE__ */ new Map();
|
|
102992
|
-
for (const { e, parts: all } of
|
|
103189
|
+
for (const { e, parts: all } of named3) {
|
|
102993
103190
|
if (hiddenPart(all[0])) {
|
|
102994
103191
|
const at2 = all.length > 1 || e.kind === "dir" ? `${all[0]}/` : all[0];
|
|
102995
103192
|
if (!t.out.skipped.some((s) => s.path === at2)) t.skip(at2, "hidden");
|
|
@@ -104952,16 +105149,16 @@ function readBook(raw) {
|
|
|
104952
105149
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { assigned: {}, retired: [] };
|
|
104953
105150
|
const { assigned, retired, ...rest } = raw;
|
|
104954
105151
|
const book = { ...rest, assigned: {}, retired: [] };
|
|
104955
|
-
const
|
|
105152
|
+
const unread3 = [];
|
|
104956
105153
|
if (assigned && typeof assigned === "object") {
|
|
104957
105154
|
for (const [k2, v] of Object.entries(assigned)) {
|
|
104958
105155
|
if (validPort(v)) book.assigned[k2] = v;
|
|
104959
|
-
else portsIn(v,
|
|
105156
|
+
else portsIn(v, unread3);
|
|
104960
105157
|
}
|
|
104961
105158
|
}
|
|
104962
|
-
if (Array.isArray(retired)) for (const p of retired) (validPort(p) ? book.retired :
|
|
105159
|
+
if (Array.isArray(retired)) for (const p of retired) (validPort(p) ? book.retired : unread3).push(...portsIn(p));
|
|
104963
105160
|
const used = /* @__PURE__ */ new Set([...Object.values(book.assigned), ...book.retired]);
|
|
104964
|
-
for (const p of
|
|
105161
|
+
for (const p of unread3) {
|
|
104965
105162
|
if (used.has(p)) continue;
|
|
104966
105163
|
used.add(p);
|
|
104967
105164
|
book.retired.push(p);
|
|
@@ -105136,12 +105333,12 @@ function folderMatcher(dir) {
|
|
|
105136
105333
|
const real3 = realFolder(dir);
|
|
105137
105334
|
if (real3 === null) return null;
|
|
105138
105335
|
const near = [fold(resolve5(dir)), fold(real3)];
|
|
105139
|
-
const
|
|
105336
|
+
const within2 = (path2) => near.some((n) => path2 === n || path2.startsWith(n.endsWith(sep3) ? n : n + sep3));
|
|
105140
105337
|
return (kept) => {
|
|
105141
105338
|
const k2 = resolve5(kept);
|
|
105142
|
-
if (
|
|
105339
|
+
if (within2(fold(k2)) || k2.startsWith("\\\\")) return true;
|
|
105143
105340
|
const r = realFolder(k2);
|
|
105144
|
-
return r === null ||
|
|
105341
|
+
return r === null || within2(fold(r));
|
|
105145
105342
|
};
|
|
105146
105343
|
}
|
|
105147
105344
|
function realFolder(path2) {
|
|
@@ -106127,8 +106324,8 @@ function awayFor(wanted, away, known) {
|
|
|
106127
106324
|
return away.filter((a) => a.machineId === prefix || a.machine.toLowerCase() === prefix || wanted.startsWith(`${a.machineId}.`));
|
|
106128
106325
|
}
|
|
106129
106326
|
function pickAskedSession(sessions, wanted, label, lastActive = (s) => s.lastActive) {
|
|
106130
|
-
const
|
|
106131
|
-
const chosen = sessions.find((s) => s.id === wanted) ?? (
|
|
106327
|
+
const named3 = wanted ? sessions.filter((s) => s.name.toLowerCase() === wanted.toLowerCase()) : sessions;
|
|
106328
|
+
const chosen = sessions.find((s) => s.id === wanted) ?? (named3.length === 1 ? named3[0] : void 0);
|
|
106132
106329
|
if (chosen) return { chosen };
|
|
106133
106330
|
const list2 = sessions.map((s) => JSON.stringify({ id: s.id, name: oneLineText(s.name, 200), state: s.state, lastActive: lastActive(s) ?? null })).join("\n");
|
|
106134
106331
|
return {
|
|
@@ -106710,8 +106907,8 @@ async function fetchBranch(repoCwd, remote, branch, timeoutMs) {
|
|
|
106710
106907
|
const tracking = `refs/remotes/${remote}/${branch}`;
|
|
106711
106908
|
const key = `${pathKey2(repoCwd)}
|
|
106712
106909
|
${remote}`;
|
|
106713
|
-
const
|
|
106714
|
-
if (
|
|
106910
|
+
const failed4 = failedFetches.get(key);
|
|
106911
|
+
if (failed4 && Date.now() - failed4.at < FETCH_RETRY_AFTER_MS) return { why: failed4.why };
|
|
106715
106912
|
try {
|
|
106716
106913
|
const own = await configValue(repoCwd, "core.sshCommand") !== "";
|
|
106717
106914
|
await runGit(repoCwd, ["fetch", "--no-tags", "--no-recurse-submodules", "--quiet", "--", remote, `+refs/heads/${branch}:${tracking}`], {
|
|
@@ -107686,9 +107883,12 @@ function agentChoice(asked, remembered, byDifficulty) {
|
|
|
107686
107883
|
const effort = asked.effort ?? (!asked.model || asked.model === remembered?.model ? remembered?.effort ?? void 0 : void 0);
|
|
107687
107884
|
return { ...model ? { model } : {}, ...effort ? { effort } : {} };
|
|
107688
107885
|
}
|
|
107689
|
-
function remoteAgentFrame(parentName, task, instructions = "") {
|
|
107886
|
+
function remoteAgentFrame(parentName, task, instructions = "", mail = false) {
|
|
107690
107887
|
return [
|
|
107691
|
-
`[A session working on this repository on another computer, "${frameField(parentName)}", gives you this task through Centralu's start_agent. Your final message goes back to it as the answer: keep it short. It cannot read this computer's files, so put what it needs in the answer itself, and commit and push what it should get.
|
|
107888
|
+
`[A session working on this repository on another computer, "${frameField(parentName)}", gives you this task through Centralu's start_agent. Your final message goes back to it as the answer: keep it short. It cannot read this computer's files, so put what it needs in the answer itself, and commit and push what it should get. ` + (mail ? 'To write to it before you answer (a question, a checkpoint), call mail with `to: "parent"`. ' : (
|
|
107889
|
+
// #1987: this machine's Centralu takes no mail from that computer, so the answer is the only way it hears from the child
|
|
107890
|
+
"Mail does not reach it from here yet: the answer is how it hears from you. "
|
|
107891
|
+
)) + "Wait for your own background work that ends (a test run, a build) inside your turn before you answer.]",
|
|
107692
107892
|
"",
|
|
107693
107893
|
task,
|
|
107694
107894
|
// The machine's own copy of the project's instructions: its paths and its shell, not the parent's (#1161 item 2)
|
|
@@ -107910,7 +108110,7 @@ function agentListText(r) {
|
|
|
107910
108110
|
if (rows3.length === 0) return { text: "No session start_agent started from here is left." };
|
|
107911
108111
|
const finished = rows3.filter((r5) => r5.state === "finished").length;
|
|
107912
108112
|
const lines = rows3.map(
|
|
107913
|
-
(r5) => `- ${frameField(r5.name)} [${r5.sessionId}] \xB7 ${r5.tool} \xB7 ${r5.state}${r5.asleep ? " (asleep)" : ""}` + (r5.machine ? ` \xB7 on ${frameField(r5.machine)}` : "") + (r5.worktree ? ` \xB7 worktree branch ${frameField(r5.worktree.branch)}${r5.worktree.unmerged ? ", not merged: a delete keeps its work in the session archive" : ", merged"}` : "") + (r5.lastActive ? ` \xB7 last ${r5.lastActive}` : "")
|
|
108113
|
+
(r5) => `- ${frameField(r5.name)} [${r5.sessionId}] \xB7 ${r5.tool} \xB7 ${r5.state === "paused" ? "paused (background work)" : r5.state}${r5.asleep ? " (asleep)" : ""}` + (r5.machine ? ` \xB7 on ${frameField(r5.machine)}` : "") + (r5.worktree ? ` \xB7 worktree branch ${frameField(r5.worktree.branch)}${r5.worktree.unmerged ? ", not merged: a delete keeps its work in the session archive" : ", merged"}` : "") + (r5.lastActive ? ` \xB7 last ${r5.lastActive}` : "")
|
|
107914
108114
|
);
|
|
107915
108115
|
return {
|
|
107916
108116
|
text: `Sessions you started (${rows3.length}, ${finished} finished):
|
|
@@ -107994,15 +108194,15 @@ function staleSessionHint(host, id3, visible, seesAll = false, doing = "act") {
|
|
|
107994
108194
|
});
|
|
107995
108195
|
const heir = heirId ? host.meta.get(heirId) : void 0;
|
|
107996
108196
|
if (!trashed && !heir) return "";
|
|
107997
|
-
const
|
|
108197
|
+
const named3 = trashed ? live2.filter((s) => s.name === trashed.session.name && s.projectId === trashed.record.projectId && s !== heir) : [];
|
|
107998
108198
|
const label = (s) => `${plainQuoted(s.name, 80)} (id ${s.id})`;
|
|
107999
108199
|
const parts = [];
|
|
108000
108200
|
if (trashed) parts.push(`That id was the session ${plainQuoted(trashed.session.name, 80)}, deleted since (it is in the archive).`);
|
|
108001
108201
|
else parts.push("That id was a session that has been replaced by a handoff.");
|
|
108002
108202
|
if (heir) parts.push(`The live session that took over from it: ${label(heir)}.`);
|
|
108003
|
-
if (
|
|
108203
|
+
if (named3.length) parts.push(`Live in the same project with the same name: ${named3.map(label).join(", ")}.`);
|
|
108004
108204
|
const then2 = doing === "send" ? "Nothing was sent; send to the one you meant, by its id." : doing === "read" ? "Nothing was read; read the one you meant, by its id." : "Nothing was done; retry the same call with the id of the live session you meant.";
|
|
108005
|
-
parts.push(heir ||
|
|
108205
|
+
parts.push(heir || named3.length ? then2 : "No live session carries its name; list the sessions to find the one you meant.");
|
|
108006
108206
|
return " " + parts.join(" ");
|
|
108007
108207
|
}
|
|
108008
108208
|
|
|
@@ -108196,16 +108396,16 @@ var lineCutOf = (maxChars) => Math.min(LINE_WINDOW_CHARS, Math.max(LINE_MAX_CHAR
|
|
|
108196
108396
|
function pick2(texts, start3, sides, budget) {
|
|
108197
108397
|
const w = { lo: start3, hi: start3 };
|
|
108198
108398
|
let size2 = (texts[start3]?.length ?? 0) + 1;
|
|
108199
|
-
const take = (
|
|
108200
|
-
const at2 =
|
|
108399
|
+
const take = (older3) => {
|
|
108400
|
+
const at2 = older3 ? w.lo - 1 : w.hi + 1;
|
|
108201
108401
|
const text3 = texts[at2];
|
|
108202
108402
|
if (text3 === void 0 || size2 + text3.length + 1 > budget) return false;
|
|
108203
108403
|
size2 += text3.length + 1;
|
|
108204
|
-
if (
|
|
108404
|
+
if (older3) w.lo = at2;
|
|
108205
108405
|
else w.hi = at2;
|
|
108206
108406
|
return true;
|
|
108207
108407
|
};
|
|
108208
|
-
for (let
|
|
108408
|
+
for (let older3 = sides !== "newer"; take(older3) || sides === "both" && take(!older3); ) if (sides === "both") older3 = !older3;
|
|
108209
108409
|
return w;
|
|
108210
108410
|
}
|
|
108211
108411
|
function fitWith(texts, start3, sides, maxChars, notes) {
|
|
@@ -108261,9 +108461,9 @@ function asPredecessor(lines, sessionId) {
|
|
|
108261
108461
|
}
|
|
108262
108462
|
|
|
108263
108463
|
// packages/agent-host/src/sessions/assistant-seat.ts
|
|
108264
|
-
function createdPreset(seat, project2,
|
|
108464
|
+
function createdPreset(seat, project2, named3, asker) {
|
|
108265
108465
|
const cap = project2.trusted ? seat : lowestPreset("normal", seat);
|
|
108266
|
-
if (
|
|
108466
|
+
if (named3 !== void 0) return presetWithin(named3, cap) ? named3 : null;
|
|
108267
108467
|
return lowestPreset(defaultPresetFor(project2), cap, ...asker ? [asker] : []);
|
|
108268
108468
|
}
|
|
108269
108469
|
var OFFSET_READ_ROWS = 200;
|
|
@@ -108419,11 +108619,11 @@ function centraluToolsFor(host, assistantId, scopeIds, ownProject, hubView) {
|
|
|
108419
108619
|
return { ok: false, error: `No such project: ${wanted}. Not asked, and its projects may be missing: ${missing.map((a) => `${a.machine} (${a.why})`).join(", ")}.` };
|
|
108420
108620
|
}
|
|
108421
108621
|
if (local.length + remote.length > 1) {
|
|
108422
|
-
const
|
|
108622
|
+
const named3 = [
|
|
108423
108623
|
...local.map((p) => `${p.name} [${p.id}] on this computer`),
|
|
108424
108624
|
...remote.map((p) => `${p.name} [${p.id}] on ${p.machine}${p.away ? ` (which ${awayPhrase(p.away)})` : ""}`)
|
|
108425
108625
|
];
|
|
108426
|
-
return { ok: false, error: `More than one project is called that; give its id: ${
|
|
108626
|
+
return { ok: false, error: `More than one project is called that; give its id: ${named3.join("; ")}` };
|
|
108427
108627
|
}
|
|
108428
108628
|
const away = remote[0]?.away;
|
|
108429
108629
|
if (away) return { ok: false, error: `${remote[0].name} [${remote[0].id}] is on ${remote[0].machine}, which ${awayPhrase(away)}. ${tryAgainAfter(away)}` };
|
|
@@ -108593,11 +108793,11 @@ function centraluToolsFor(host, assistantId, scopeIds, ownProject, hubView) {
|
|
|
108593
108793
|
}
|
|
108594
108794
|
const before = opts?.before;
|
|
108595
108795
|
const fromSeq = opts?.from;
|
|
108596
|
-
const
|
|
108796
|
+
const read2 = before != null ? host.store.messages.loadMessages(sessionId, limit * 2, before) : fromSeq != null ? host.store.messages.loadMessagesFrom(sessionId, fromSeq - 1, limit * 2) : around ? [
|
|
108597
108797
|
...host.store.messages.loadMessages(sessionId, limit, around + 1),
|
|
108598
108798
|
...host.store.messages.loadMessagesFrom(sessionId, around, limit)
|
|
108599
108799
|
] : host.store.messages.loadMessages(sessionId, limit * 2);
|
|
108600
|
-
const rows3 = cut3 === null ?
|
|
108800
|
+
const rows3 = cut3 === null ? read2 : read2.filter((r) => r.seq < cut3);
|
|
108601
108801
|
const lines = mark(sessionLines(rows3, opts));
|
|
108602
108802
|
const at2 = around != null ? rows3.find((r) => r.seq >= around)?.seq : void 0;
|
|
108603
108803
|
const anchor = at2 === void 0 ? -1 : lines.findLastIndex((l) => l.seq <= at2);
|
|
@@ -109040,8 +109240,8 @@ var AskedGate = class {
|
|
|
109040
109240
|
if (step === null) return run4();
|
|
109041
109241
|
const recorded = async () => {
|
|
109042
109242
|
const done2 = await run4();
|
|
109043
|
-
const
|
|
109044
|
-
if (!
|
|
109243
|
+
const failed4 = typeof done2 === "object" && done2 !== null && ("isError" in done2 && done2.isError === true || "allowed" in done2 && done2.allowed === false);
|
|
109244
|
+
if (!failed4) this.record(asker, "act" in step ? step.act : `run ${call2.name}`);
|
|
109045
109245
|
return done2;
|
|
109046
109246
|
};
|
|
109047
109247
|
const kind = stepKind(call2.name, call2.args);
|
|
@@ -109117,6 +109317,9 @@ function refusalReason(err) {
|
|
|
109117
109317
|
function bodyLimit(sender) {
|
|
109118
109318
|
return sender === "app" ? 4e3 : 16e3;
|
|
109119
109319
|
}
|
|
109320
|
+
function tooLongText(sender) {
|
|
109321
|
+
return `a body from ${sender === "app" ? "an app" : "this sender"} is at most ${bodyLimit(sender)} characters`;
|
|
109322
|
+
}
|
|
109120
109323
|
function postsPerMinute(sender) {
|
|
109121
109324
|
return sender === "session" ? 30 : sender === "app" ? 10 : Infinity;
|
|
109122
109325
|
}
|
|
@@ -109167,7 +109370,8 @@ var REMINDER = {
|
|
|
109167
109370
|
var REFUSAL_TEXT = {
|
|
109168
109371
|
gone: (address) => `${address} is gone: it is in the session archive or deleted.`,
|
|
109169
109372
|
no_mailbox: () => "that session cannot read mail: only an ordinary session in a project, or the Assistant, has the mail tool",
|
|
109170
|
-
|
|
109373
|
+
// The mailbox here never writes to another computer's session: a session's mail tool sends it there (#2067 item 2), and this is what any other way of sending reads
|
|
109374
|
+
elsewhere: (address) => `${address} is on another computer, and only a session's mail tool sends mail there: nothing was written.`,
|
|
109171
109375
|
unknown_message: (id3) => `there is no message ${id3} you can read; check the id with mail(action="inbox").`,
|
|
109172
109376
|
own_message: (id3) => `${id3} is your own message; say who it is for with to="\u2026".`,
|
|
109173
109377
|
recipients: () => `at most ${MAX_RECIPIENTS} recipients.`,
|
|
@@ -109251,7 +109455,8 @@ var MailDelivery = class {
|
|
|
109251
109455
|
});
|
|
109252
109456
|
this.heartbeat = opts.heartbeat;
|
|
109253
109457
|
this.turns = opts.turns;
|
|
109254
|
-
this.o = { ...DEFAULTS2, ...Object.fromEntries(Object.entries(opts).filter(([k2]) => k2 !== "now" && k2 !== "schedule" && k2 !== "heartbeat" && k2 !== "turns")) };
|
|
109458
|
+
this.o = { ...DEFAULTS2, ...Object.fromEntries(Object.entries(opts).filter(([k2]) => k2 !== "now" && k2 !== "schedule" && k2 !== "heartbeat" && k2 !== "turns" && k2 !== "across")) };
|
|
109459
|
+
this.across = opts.across;
|
|
109255
109460
|
}
|
|
109256
109461
|
service;
|
|
109257
109462
|
records;
|
|
@@ -109259,6 +109464,7 @@ var MailDelivery = class {
|
|
|
109259
109464
|
now;
|
|
109260
109465
|
schedule;
|
|
109261
109466
|
o;
|
|
109467
|
+
across;
|
|
109262
109468
|
heartbeat;
|
|
109263
109469
|
turns;
|
|
109264
109470
|
/** One delivery in flight per mailbox; a change that comes meanwhile is looked at when it ends */
|
|
@@ -109354,7 +109560,8 @@ var MailDelivery = class {
|
|
|
109354
109560
|
}
|
|
109355
109561
|
this.lastSweepAt = now;
|
|
109356
109562
|
this.moveOnWorkOfGoneSessions();
|
|
109357
|
-
const
|
|
109563
|
+
const across = this.across;
|
|
109564
|
+
const recipients = across ? this.records.dueRecipients().filter((r) => !across(r)) : this.records.dueRecipients();
|
|
109358
109565
|
if (this.catchUpPending) {
|
|
109359
109566
|
this.catchUpPending = false;
|
|
109360
109567
|
await this.catchUp(recipients);
|
|
@@ -110706,9 +110913,9 @@ var MAIL_TOOLS = [
|
|
|
110706
110913
|
name: "mail",
|
|
110707
110914
|
description: `Centralu's mailbox: work and messages with other sessions, apps and the person; send to "assistant" to ask it, with cite=true only when the person's last message here asked for it.`,
|
|
110708
110915
|
schema: external_exports.object({
|
|
110709
|
-
action: external_exports.enum(["inbox", "read", "handled", "send", "reply", "update", "close"]),
|
|
110916
|
+
action: external_exports.enum(["inbox", "read", "handled", "send", "reply", "update", "close", "find"]),
|
|
110710
110917
|
thread: external_exports.string().optional(),
|
|
110711
|
-
to: external_exports.string().optional().describe('"parent": the session that started you, for a question or checkpoint; "assistant": the Centralu Assistant, for what only it can decide; "person": the human; or a session by name or id (a shared name is refused, listing them)'),
|
|
110918
|
+
to: external_exports.string().optional().describe('"parent": the session that started you, for a question or checkpoint; "assistant": the Centralu Assistant, for what only it can decide; "person": the human; or a session by name or id (a shared name is refused, listing them). For find: words (name, project, machine, role) to search every computer'),
|
|
110712
110919
|
kind: external_exports.string().optional(),
|
|
110713
110920
|
subject: external_exports.string().optional(),
|
|
110714
110921
|
text: external_exports.string().optional(),
|
|
@@ -110724,7 +110931,7 @@ var MAIL_TOOLS = [
|
|
|
110724
110931
|
deferred: true
|
|
110725
110932
|
}
|
|
110726
110933
|
];
|
|
110727
|
-
var MAIL_BUDGET_CHARS =
|
|
110934
|
+
var MAIL_BUDGET_CHARS = 1240;
|
|
110728
110935
|
var COMPACT_TOOLS = [
|
|
110729
110936
|
{
|
|
110730
110937
|
name: "compact_self",
|
|
@@ -110968,10 +111175,10 @@ function namedCall(profile, tool, args, tier = rareTier) {
|
|
|
110968
111175
|
function commandsSentence(profile, tools, tier = rareTier) {
|
|
110969
111176
|
if (profile === null) return "";
|
|
110970
111177
|
const commands = commandsFor(profile, tier);
|
|
110971
|
-
const
|
|
110972
|
-
if (!
|
|
110973
|
-
const list2 =
|
|
110974
|
-
return `${list2} ${
|
|
111178
|
+
const named3 = tools.filter((t) => commands.includes(t));
|
|
111179
|
+
if (!named3.length) return "";
|
|
111180
|
+
const list2 = named3.join(" and ");
|
|
111181
|
+
return `${list2} ${named3.length === 1 ? "is one" : "are"} of this session's commands: centralu_run(command="${named3[0]}", args={\u2026}) runs ${named3.length === 1 ? "it" : "each"}.`;
|
|
110975
111182
|
}
|
|
110976
111183
|
function notAToolText(profile, name, tier = rareTier) {
|
|
110977
111184
|
const refused2 = `Not a tool of this session: ${name}`;
|
|
@@ -111079,10 +111286,10 @@ function decisionFrom(text3) {
|
|
|
111079
111286
|
}
|
|
111080
111287
|
function cardCall(profile, sessionId) {
|
|
111081
111288
|
if (profile === "reader") return { call: `agent_session(sessionId="${sessionId}", action="status") shows it; action="answer" answers it`, canAnswer: true };
|
|
111082
|
-
const
|
|
111289
|
+
const read2 = `read_session(sessionId="${sessionId}") shows it`;
|
|
111083
111290
|
const answer = callForm(profile, "answer_question", { sessionId, text: FILL });
|
|
111084
|
-
if (!answer) return { call:
|
|
111085
|
-
return { call: `${
|
|
111291
|
+
if (!answer) return { call: read2, canAnswer: false };
|
|
111292
|
+
return { call: `${read2}; ${answer} answers it`, canAnswer: true };
|
|
111086
111293
|
}
|
|
111087
111294
|
function cardNotice(kind, sessionId, how, answerable) {
|
|
111088
111295
|
const head = kind === "question" ? "[Centralu] The session you gave work to is asking a question in that turn." : "[Centralu] The session you gave work to is waiting on an approval in that turn.";
|
|
@@ -111320,7 +111527,7 @@ var HandoffChildren = class {
|
|
|
111320
111527
|
if (!removed && heir.permissionPreset !== "auto") this.host.queue.dropOpenedByAuto(from);
|
|
111321
111528
|
const queuedBy = removed ? /* @__PURE__ */ new Set() : new Set([...this.host.children.queued.values()].flat().filter((r) => r.callerSessionId === from).map((r) => r.sessionId));
|
|
111322
111529
|
const delegated = [...this.host.children.delegations.values()].filter((d2) => d2.callerId === from);
|
|
111323
|
-
const
|
|
111530
|
+
const stateOf2 = (s) => {
|
|
111324
111531
|
if (s.pendingApproval) return "waiting for an approval";
|
|
111325
111532
|
if (s.pendingQuestions.length) return "waiting on a question";
|
|
111326
111533
|
if (s.state === "waiting_approval") return "waiting for an approval";
|
|
@@ -111360,7 +111567,7 @@ var HandoffChildren = class {
|
|
|
111360
111567
|
for (const id3 of linked) {
|
|
111361
111568
|
const s = this.host.meta.get(id3);
|
|
111362
111569
|
if (!s || id3 === to) continue;
|
|
111363
|
-
const state =
|
|
111570
|
+
const state = stateOf2(s);
|
|
111364
111571
|
sessions.push(id3);
|
|
111365
111572
|
const project2 = s.projectId !== original.projectId ? projects.get(s.projectId ?? "") ?? s.projectId ?? "" : void 0;
|
|
111366
111573
|
const told = this.host.children.awaitingReport.get(id3) === from || armReports.includes(id3) || queuedBy.has(id3);
|
|
@@ -111533,7 +111740,7 @@ function answerRecorder(mail, records, turns, waitingOn = () => 0) {
|
|
|
111533
111740
|
records.markRead(owner, reports, now);
|
|
111534
111741
|
const task = records.newestTask(owner, child);
|
|
111535
111742
|
if (!how || !task) return;
|
|
111536
|
-
const
|
|
111743
|
+
const read2 = `read_session(sessionId="${childId}")`;
|
|
111537
111744
|
const waiting = how.ok ? waitingOn(callerId, childId) : 0;
|
|
111538
111745
|
const startedAt = turns?.latest(childId)?.startedAt;
|
|
111539
111746
|
const written = mail.report(task.id, {
|
|
@@ -111542,10 +111749,10 @@ function answerRecorder(mail, records, turns, waitingOn = () => 0) {
|
|
|
111542
111749
|
body: how.ok ? `${TURN_ENDED}
|
|
111543
111750
|
id: ${childId}
|
|
111544
111751
|
|
|
111545
|
-
Its last response is that session's own words, so it is not repeated here: ${
|
|
111752
|
+
Its last response is that session's own words, so it is not repeated here: ${read2} reads it.` : `[Centralu] The assigned work did not finish.
|
|
111546
111753
|
id: ${childId}
|
|
111547
111754
|
|
|
111548
|
-
Its tool's error, by kind: ${how.error}. Its words are its tool's, not Centralu's, so they are not repeated here: ${
|
|
111755
|
+
Its tool's error, by kind: ${how.error}. Its words are its tool's, not Centralu's, so they are not repeated here: ${read2} shows them.`,
|
|
111549
111756
|
...how.ok ? { answer: how.text.length > ANSWER_KEPT ? `${how.text.slice(0, ANSWER_KEPT)}\u2026` : how.text } : { error: how.error }
|
|
111550
111757
|
});
|
|
111551
111758
|
if ("message" in written) {
|
|
@@ -113098,7 +113305,7 @@ function nameOf2(key, by, names) {
|
|
|
113098
113305
|
var tokensOf = (r) => r.inputTokens + r.cacheReadTokens + r.cacheCreationTokens + r.outputTokens;
|
|
113099
113306
|
function historyRows(buckets, p, names) {
|
|
113100
113307
|
const rows3 = /* @__PURE__ */ new Map();
|
|
113101
|
-
const
|
|
113308
|
+
const named3 = /* @__PURE__ */ new Map();
|
|
113102
113309
|
for (const b2 of buckets) {
|
|
113103
113310
|
const period = p.groupBy === "day" ? dayStart(b2.hour) : b2.hour;
|
|
113104
113311
|
const key = keyOf3(b2, p.by);
|
|
@@ -113106,8 +113313,8 @@ function historyRows(buckets, p, names) {
|
|
|
113106
113313
|
${key}`;
|
|
113107
113314
|
let r = rows3.get(id3);
|
|
113108
113315
|
if (!r) {
|
|
113109
|
-
let name =
|
|
113110
|
-
if (name === void 0)
|
|
113316
|
+
let name = named3.get(key);
|
|
113317
|
+
if (name === void 0) named3.set(key, name = nameOf2(key, p.by, names));
|
|
113111
113318
|
rows3.set(id3, r = emptyRow(period, key, name));
|
|
113112
113319
|
}
|
|
113113
113320
|
add(r, b2);
|
|
@@ -114663,7 +114870,7 @@ function ownAgents(host, callerId) {
|
|
|
114663
114870
|
}
|
|
114664
114871
|
function agentState(host, s) {
|
|
114665
114872
|
const running2 = [...host.children.delegations.values()].some((d2) => d2.sessionId === s.id && !d2.settled);
|
|
114666
|
-
return s.pendingApproval || s.pendingQuestions.length ? "waiting" : inTurn(s.state) || running2 ? "working" : s.state === "error" || s.state === "limited" || s.interruption ? "stopped" : "finished";
|
|
114873
|
+
return s.pendingApproval || s.pendingQuestions.length ? "waiting" : inTurn(s.state) || running2 ? "working" : pausedOnBackground(s) ? "paused" : s.state === "error" || s.state === "limited" || s.interruption ? "stopped" : "finished";
|
|
114667
114874
|
}
|
|
114668
114875
|
function cleanUpDue(child, callerId, notice) {
|
|
114669
114876
|
return child.askedBy === callerId && !notice && !child.interruption && child.state !== "error" && child.state !== "limited";
|
|
@@ -115444,6 +115651,8 @@ var RemoteAgents = class {
|
|
|
115444
115651
|
}
|
|
115445
115652
|
host;
|
|
115446
115653
|
places;
|
|
115654
|
+
/** Whether a machine takes mail from this hub (`LinkedMachineConnection.takesMail`, #2067 item 2): its children's task then says to mail. Set by main.ts */
|
|
115655
|
+
machineMail = null;
|
|
115447
115656
|
loaded = null;
|
|
115448
115657
|
waits = /* @__PURE__ */ new Map();
|
|
115449
115658
|
/** Children whose parent was told their link dropped, until it is back */
|
|
@@ -115526,7 +115735,7 @@ var RemoteAgents = class {
|
|
|
115526
115735
|
continue;
|
|
115527
115736
|
}
|
|
115528
115737
|
const there = listed2?.find((s) => s.sessionId === r.sessionId);
|
|
115529
|
-
const state = there?.state === "waiting_approval" || there?.state === "waiting_question" ? "waiting" : there ? inTurn(there.state) ? "working" : "finished" : this.waits.has(r.sessionId) || this.reportArmed(r) ? "working" : "finished";
|
|
115738
|
+
const state = there?.state === "waiting_approval" || there?.state === "waiting_question" ? "waiting" : there ? inTurn(there.state) ? "working" : pausedOnBackground({ state: there.state, backgroundTasks: this.host.linkedReports.tasksOf(r.sessionId), interruption: there.interruption }) ? "paused" : there.state === "error" || there.state === "limited" || there.interruption ? "stopped" : "finished" : this.waits.has(r.sessionId) || this.reportArmed(r) ? "working" : "finished";
|
|
115530
115739
|
out.push({ sessionId: r.sessionId, name: r.name, tool: r.tool, state, asleep: false, machine: r.machine });
|
|
115531
115740
|
}
|
|
115532
115741
|
return out;
|
|
@@ -115706,7 +115915,7 @@ var RemoteAgents = class {
|
|
|
115706
115915
|
};
|
|
115707
115916
|
}
|
|
115708
115917
|
const label = labelOf(this.host.store.messages, caller);
|
|
115709
|
-
const task = remoteAgentFrame(label, opts.task, await this.instructionsOn(reader, target));
|
|
115918
|
+
const task = remoteAgentFrame(label, opts.task, await this.instructionsOn(reader, target), this.machineMail?.(machine.id) === true);
|
|
115710
115919
|
const rec = {
|
|
115711
115920
|
sessionId: made.sessionId,
|
|
115712
115921
|
callerId,
|
|
@@ -115768,7 +115977,7 @@ var RemoteAgents = class {
|
|
|
115768
115977
|
const reader = this.host.linkedReader;
|
|
115769
115978
|
if (!reader) return { ok: false, error: `${rec.sessionId} is on ${rec.machine}, and no machine is linked to this computer now.` };
|
|
115770
115979
|
const label = labelOf(this.host.store.messages, this.host.meta.get(callerId));
|
|
115771
|
-
const
|
|
115980
|
+
const stateOf2 = async () => {
|
|
115772
115981
|
const r = await reader.read(rec.sessionId, 1);
|
|
115773
115982
|
if (!r.ok) return { ok: false, error: `${rec.machine} cannot be asked about "${rec.name}" now: ${r.error ?? "no answer"}` };
|
|
115774
115983
|
const state = r.state ?? "idle";
|
|
@@ -115778,7 +115987,7 @@ var RemoteAgents = class {
|
|
|
115778
115987
|
case "answer":
|
|
115779
115988
|
return this.answer(rec, opts.card, opts.text ?? "", reader);
|
|
115780
115989
|
case "status": {
|
|
115781
|
-
const now = await
|
|
115990
|
+
const now = await stateOf2();
|
|
115782
115991
|
if (!now.ok) return now;
|
|
115783
115992
|
const g5 = await this.gate(rec, reader);
|
|
115784
115993
|
const running2 = now.running || this.waits.has(rec.sessionId);
|
|
@@ -115790,12 +115999,12 @@ var RemoteAgents = class {
|
|
|
115790
115999
|
case "wait": {
|
|
115791
116000
|
const g5 = await this.gate(rec, reader);
|
|
115792
116001
|
if (!g5.owned) {
|
|
115793
|
-
const now2 = await
|
|
116002
|
+
const now2 = await stateOf2();
|
|
115794
116003
|
if (!now2.ok) return now2;
|
|
115795
116004
|
return this.notYours(rec, g5, now2.running, now2.state);
|
|
115796
116005
|
}
|
|
115797
116006
|
if (this.waits.has(rec.sessionId) || this.reportArmed(rec)) return this.awaitTurn(rec, signal, ASK_WAIT_MS);
|
|
115798
|
-
const now = await
|
|
116007
|
+
const now = await stateOf2();
|
|
115799
116008
|
if (!now.ok) return now;
|
|
115800
116009
|
return now.running ? this.awaitTurn(rec, signal, ASK_WAIT_MS) : this.atRest(rec, now.state, reader);
|
|
115801
116010
|
}
|
|
@@ -115804,7 +116013,7 @@ var RemoteAgents = class {
|
|
|
115804
116013
|
if (!text3) return { ok: false, error: "Give the text to send." };
|
|
115805
116014
|
const above = aboveCallerError(rec.name, rec.preset ?? "normal", this.callerPreset(callerId));
|
|
115806
116015
|
if (above) return { ok: false, error: above };
|
|
115807
|
-
const now = await
|
|
116016
|
+
const now = await stateOf2();
|
|
115808
116017
|
if (!now.ok) return now;
|
|
115809
116018
|
if (now.running) {
|
|
115810
116019
|
const g5 = await this.gate(rec, reader);
|
|
@@ -115852,7 +116061,7 @@ var RemoteAgents = class {
|
|
|
115852
116061
|
notice: reader.machineLinked(rec.machineId) ? `It was no longer on ${rec.machine}; nothing was left to delete.` : `${rec.machine} was removed from Centralu; the session is forgotten here.`
|
|
115853
116062
|
};
|
|
115854
116063
|
}
|
|
115855
|
-
const now = await
|
|
116064
|
+
const now = await stateOf2();
|
|
115856
116065
|
if (!now.ok) return now;
|
|
115857
116066
|
if (now.running) {
|
|
115858
116067
|
const stopped = await this.interruptFor(rec, callerId, reader);
|
|
@@ -116220,11 +116429,11 @@ Reason, by kind: ${errorKind(why2)} (its words are an error's, kept in this noti
|
|
|
116220
116429
|
*/
|
|
116221
116430
|
turnOpens(rec, e) {
|
|
116222
116431
|
const origin = e.type === "state_change" ? asObj(e.origin) : {};
|
|
116223
|
-
const
|
|
116432
|
+
const named3 = origin.seq;
|
|
116224
116433
|
const held2 = this.givenRows(rec.sessionId);
|
|
116225
|
-
if (typeof
|
|
116434
|
+
if (typeof named3 !== "number" || !held2.includes(named3) || !this.fromHubHere(rec, origin.from)) return;
|
|
116226
116435
|
if (this.whoseOf(rec) === "unknown") return;
|
|
116227
|
-
this.setGiven(rec.sessionId, held2.filter((row) => row >
|
|
116436
|
+
this.setGiven(rec.sessionId, held2.filter((row) => row > named3));
|
|
116228
116437
|
if (this.whoseOf(rec) !== "caller" || this.gateNow(rec).live || !this.host.meta.has(rec.callerId)) return;
|
|
116229
116438
|
this.host.children.setLinkedReport(rec.sessionId, { assistantId: rec.callerId, busy: true });
|
|
116230
116439
|
}
|
|
@@ -116555,16 +116764,16 @@ Reason, by kind: ${errorKind(why2)} (its words are an error's, kept in this noti
|
|
|
116555
116764
|
const away = all.away.find((a) => a.machineId === machine.id);
|
|
116556
116765
|
if (away) return { error: awayRefusal(machine.name, away.why, "nothing was started there") };
|
|
116557
116766
|
const theirs = all.projects.filter((p) => p.machineId === machine.id);
|
|
116558
|
-
const
|
|
116559
|
-
const unreached =
|
|
116560
|
-
if (
|
|
116767
|
+
const read2 = await Promise.all(theirs.map(async (p) => ({ p, r: await reader.origin(p) })));
|
|
116768
|
+
const unreached = read2.map(({ r }) => !r.ok && (r.error.includes(NOT_REACHABLE) || r.error.includes(NOT_CONNECTED_PHRASE)) ? r.error : null);
|
|
116769
|
+
if (read2.length > 0 && unreached.every((e) => e !== null)) {
|
|
116561
116770
|
return { error: awayRefusal(machine.name, unreached.every((e) => e?.includes(NOT_CONNECTED_PHRASE)) ? NOT_CONNECTED : NOT_REACHABLE, "nothing was started there") };
|
|
116562
116771
|
}
|
|
116563
|
-
const same =
|
|
116772
|
+
const same = read2.filter(({ r }) => r.ok && r.origin && gitRemoteKey(r.origin) === key).map(({ p }) => p);
|
|
116564
116773
|
const chosen = same.length === 1 ? same[0] : same.filter((p) => p.name === project2.name).length === 1 ? same.find((p) => p.name === project2.name) : void 0;
|
|
116565
116774
|
if (chosen) return { project: chosen };
|
|
116566
116775
|
if (same.length) return { error: `${machine.name} has more than one checkout of ${key}: ${same.map((p) => `"${p.name}"`).join(", ")}, none named as this project is. Choosing among them is not available yet: the person can remove the extra one there.` };
|
|
116567
|
-
const listed2 =
|
|
116776
|
+
const listed2 = read2.map(({ p, r }) => `"${p.name}" (${r.ok ? shownRemote(r.origin) : "not read"})`).join(", ");
|
|
116568
116777
|
return { error: `${machine.name} has no checkout of ${key}, so nothing was started there.${listed2 ? ` Its projects: ${listed2}.` : " It has no projects."} The person can clone it there first.` };
|
|
116569
116778
|
}
|
|
116570
116779
|
};
|
|
@@ -117050,7 +117259,7 @@ var ChildReports = class {
|
|
|
117050
117259
|
const target = this.host.meta.get(sessionId);
|
|
117051
117260
|
if (!target || !this.host.meta.has(callerId)) return;
|
|
117052
117261
|
const { name, project: project2 } = this.reportedAs(target);
|
|
117053
|
-
const
|
|
117262
|
+
const read2 = `read_session(sessionId="${sessionId}")`;
|
|
117054
117263
|
const stored = tookOverReportLine(tasks) + `Session: ${frameField(name)}
|
|
117055
117264
|
id: ${sessionId}
|
|
117056
117265
|
Project: ${frameField(project2)}
|
|
@@ -117058,7 +117267,7 @@ Project: ${frameField(project2)}
|
|
|
117058
117267
|
If you need more, you can read that session's recent conversation with read_session.`;
|
|
117059
117268
|
const forModel = tookOverReportLine(tasks, FOR_MODEL) + `id: ${sessionId}
|
|
117060
117269
|
|
|
117061
|
-
${
|
|
117270
|
+
${read2} shows what the person and the session did since.`;
|
|
117062
117271
|
const taken = this.toMailbox(callerId, sessionId, { outcome: "took_over", body: forModel, ...tasks.length ? { paused: tasks.length } : {}, then: "dropped" });
|
|
117063
117272
|
if (taken === "mailed" || taken === "closed") return;
|
|
117064
117273
|
await this.tellSession(
|
|
@@ -117091,16 +117300,16 @@ ${read} shows what the person and the session did since.`;
|
|
|
117091
117300
|
const resume = cutShort ? `It keeps its conversation: send it a message to go on${stop2?.reason === "network" ? ", once the network is back" : ""}, the same one the person's Continue sends: "Continue where you stopped. Check what already happened before repeating a step."
|
|
117092
117301
|
` : "";
|
|
117093
117302
|
const cleanUp = !work && !stop2 && ending.type === "turn_complete" ? this.cleanUpWords(assistantId, sessionId) : "";
|
|
117094
|
-
const
|
|
117303
|
+
const read2 = `read_session(sessionId="${sessionId}"${answerSeq !== void 0 ? `, around=${answerSeq}` : ""})`;
|
|
117095
117304
|
const kind = message ? stop2?.reason === "network" ? "network" : errorKind(message) : void 0;
|
|
117096
117305
|
const answered = preview !== "" && preview !== NOT_READ && preview !== NOT_QUOTED && preview !== MACHINE_UNREACHABLE && preview !== IN_PAUSE_REPORT;
|
|
117097
117306
|
const asRead = !!work && ("linkLost" in work || "machineRemoved" in work) && work.asRead === true;
|
|
117098
117307
|
const asReadWords = asRead ? ", as it was last read there, before its machine went out of reach" : "";
|
|
117099
117308
|
const forModel = (inThread) => outcomeOf2(FOR_MODEL) + personPartLine(part) + `id: ${sessionId}
|
|
117100
117309
|
|
|
117101
|
-
` + (kind ? `Its tool's error, by kind: ${kind}. Its words are its tool's, not Centralu's, so they are not repeated here: ${
|
|
117310
|
+
` + (kind ? `Its tool's error, by kind: ${kind}. Its words are its tool's, not Centralu's, so they are not repeated here: ${read2} shows them.
|
|
117102
117311
|
|
|
117103
|
-
` : "") + resume + (inThread && answered ? `Its last response${asReadWords} is that session's own words: it is the message above in this thread, and ${
|
|
117312
|
+
` : "") + resume + (inThread && answered ? `Its last response${asReadWords} is that session's own words: it is the message above in this thread, and ${read2} reads more.` : preview === MACHINE_UNREACHABLE ? `Its last response could not be read: its machine could not be reached. ${read2} reads it once that machine is back.` : `Its last response${asReadWords} is that session's own words, so it is not repeated here: ${read2} reads it${preview ? "" : " (it had none)"}.`) + cleanUp;
|
|
117104
117313
|
const stored = outcome + `Session: ${frameField(name)}
|
|
117105
117314
|
id: ${sessionId}
|
|
117106
117315
|
Project: ${frameField(project2)}
|
|
@@ -117313,8 +117522,8 @@ function isCentraluNote(text3) {
|
|
|
117313
117522
|
var InputReceipts = class {
|
|
117314
117523
|
pending = /* @__PURE__ */ new Map();
|
|
117315
117524
|
/** `named`: the id the caller gave the input, which the tool then names back; none, one is made (with Centralu's mark) */
|
|
117316
|
-
create(observer,
|
|
117317
|
-
const id3 =
|
|
117525
|
+
create(observer, named3) {
|
|
117526
|
+
const id3 = named3 ?? centraluInputId();
|
|
117318
117527
|
let resolve21;
|
|
117319
117528
|
let reject;
|
|
117320
117529
|
const done2 = new Promise((yes, no2) => {
|
|
@@ -118040,14 +118249,14 @@ var PreferencesFlow = class {
|
|
|
118040
118249
|
if (prefs.status === "rejected") return { ok: false, error: `Could not read the preferences: ${prefs.reason instanceof Error ? prefs.reason.message : String(prefs.reason)}` };
|
|
118041
118250
|
const p = prefs.value;
|
|
118042
118251
|
const choices = themes2.status === "fulfilled" ? themeChoices(themes2.value) : themeChoices([]);
|
|
118043
|
-
const
|
|
118252
|
+
const named3 = (id3) => {
|
|
118044
118253
|
const c = choices.find((x) => x.id === id3);
|
|
118045
118254
|
return c ? `${plainQuoted(c.name)} [${c.id}]` : `[${plainQuoted(id3)}] (no such theme; the stylesheet's own is shown)`;
|
|
118046
118255
|
};
|
|
118047
118256
|
const notify = p.notifyPolicy ?? DEFAULT_NOTIFY_POLICY;
|
|
118048
118257
|
const lines = [
|
|
118049
118258
|
"Appearance",
|
|
118050
|
-
`- Theme mode: ${p.themeMode}; dark theme ${
|
|
118259
|
+
`- Theme mode: ${p.themeMode}; dark theme ${named3(p.themeDark)}; light theme ${named3(p.themeLight)}`,
|
|
118051
118260
|
`- Themes to choose from (set_preferences theme): ${choices.map((c) => `${plainQuoted(c.name)} [${c.id}] (${c.base}${c.file ? ", a theme file" : ""})`).join(", ")}`,
|
|
118052
118261
|
...themes2.status === "fulfilled" ? themeFileLines(themes2.value, themeFile) : [],
|
|
118053
118262
|
`- Text size: ${p.textSize} (${TEXT_SIZES.join(", ")}; 1 is the default)`,
|
|
@@ -118075,7 +118284,7 @@ var PreferencesFlow = class {
|
|
|
118075
118284
|
const patch = {};
|
|
118076
118285
|
let theme = null;
|
|
118077
118286
|
const done2 = [];
|
|
118078
|
-
const
|
|
118287
|
+
const failed4 = [];
|
|
118079
118288
|
const modelWarnings = [];
|
|
118080
118289
|
const file2 = changes.themeFile;
|
|
118081
118290
|
if (file2 !== void 0) {
|
|
@@ -118128,7 +118337,7 @@ var PreferencesFlow = class {
|
|
|
118128
118337
|
let toApply = parsed.data;
|
|
118129
118338
|
if (changes.theme !== void 0) {
|
|
118130
118339
|
const found = await this.theme(rpc, changes.theme);
|
|
118131
|
-
if (typeof found === "string")
|
|
118340
|
+
if (typeof found === "string") failed4.push(`Theme: not picked. ${found}`);
|
|
118132
118341
|
else {
|
|
118133
118342
|
theme = found;
|
|
118134
118343
|
patch.themeMode = found.base;
|
|
@@ -118137,7 +118346,7 @@ var PreferencesFlow = class {
|
|
|
118137
118346
|
if (again.success) toApply = again.data;
|
|
118138
118347
|
else {
|
|
118139
118348
|
theme = null;
|
|
118140
|
-
|
|
118349
|
+
failed4.push(`Theme: not picked. ${issuesOf(again.error)}.`);
|
|
118141
118350
|
}
|
|
118142
118351
|
}
|
|
118143
118352
|
}
|
|
@@ -118145,7 +118354,7 @@ var PreferencesFlow = class {
|
|
|
118145
118354
|
try {
|
|
118146
118355
|
done2.push(await run4());
|
|
118147
118356
|
} catch (e) {
|
|
118148
|
-
|
|
118357
|
+
failed4.push(`${what}: ${e.message}`);
|
|
118149
118358
|
}
|
|
118150
118359
|
};
|
|
118151
118360
|
if (Object.keys(patch).length) {
|
|
@@ -118171,7 +118380,7 @@ var PreferencesFlow = class {
|
|
|
118171
118380
|
const sound = silences ? turning ? " The sound is also turned off, and the sound is how an approval reaches you when you are away." : "Turn off the notification sound? The sound is how an approval reaches you when you are away; without it an approval shows a notice only, which you may not see. You can turn it back on in Settings, Notifications." : "";
|
|
118172
118381
|
const refused2 = await this.ask(sessionId, stop2 + sound, signal, turning && silences ? "the approval notification and the sound stay on" : turning ? "it keeps notifying" : "the sound stays on");
|
|
118173
118382
|
if (refused2) {
|
|
118174
|
-
|
|
118383
|
+
failed4.push(`Notifications: ${refused2}`);
|
|
118175
118384
|
delete switches.approval;
|
|
118176
118385
|
if (silences) delete switches.sound;
|
|
118177
118386
|
}
|
|
@@ -118214,7 +118423,7 @@ var PreferencesFlow = class {
|
|
|
118214
118423
|
} else {
|
|
118215
118424
|
const refused2 = await this.ask(sessionId, UPDATE_CARD, signal);
|
|
118216
118425
|
if (refused2) {
|
|
118217
|
-
|
|
118426
|
+
failed4.push(`Automatic updates: ${refused2}`);
|
|
118218
118427
|
go = false;
|
|
118219
118428
|
}
|
|
118220
118429
|
}
|
|
@@ -118228,7 +118437,7 @@ var PreferencesFlow = class {
|
|
|
118228
118437
|
} catch (e) {
|
|
118229
118438
|
const now = await callWindow(rpc, "updates.status", { force: false }).catch(() => null);
|
|
118230
118439
|
if (now) done2.push(`Automatic updates are now ${automatic(now)}.`);
|
|
118231
|
-
|
|
118440
|
+
failed4.push(`Automatic updates: ${e.message}`);
|
|
118232
118441
|
}
|
|
118233
118442
|
}
|
|
118234
118443
|
}
|
|
@@ -118253,8 +118462,8 @@ var PreferencesFlow = class {
|
|
|
118253
118462
|
return `Removed the theme file [${id3}]; it is kept at ${plainQuoted(keptAt ?? "", 300)} (move it back to restore it).${Object.keys(back).length ? " A side that showed it is back on its preset." : ""}`;
|
|
118254
118463
|
});
|
|
118255
118464
|
}
|
|
118256
|
-
if (!done2.length) return { ok: false, error:
|
|
118257
|
-
return { ok: true, text: [...done2, ...
|
|
118465
|
+
if (!done2.length) return { ok: false, error: failed4.join(" ") };
|
|
118466
|
+
return { ok: true, text: [...done2, ...failed4.length ? [`Not changed: ${failed4.join(" ")}`] : []].join("\n") };
|
|
118258
118467
|
}
|
|
118259
118468
|
/**
|
|
118260
118469
|
* The folded groups after this change: the window's list as it is now, less the unfolded sessions' groups, with the
|
|
@@ -118318,8 +118527,8 @@ var PreferencesFlow = class {
|
|
|
118318
118527
|
}
|
|
118319
118528
|
/** The id a theme file will be written under: the one named, else the one `themes.save` files its name under among the ids taken now */
|
|
118320
118529
|
async idOfFile(rpc, file2) {
|
|
118321
|
-
const
|
|
118322
|
-
if (
|
|
118530
|
+
const named3 = file2.id?.trim().toLowerCase();
|
|
118531
|
+
if (named3) return named3;
|
|
118323
118532
|
const taken = new Set((await callWindow(rpc, "themes.list", {})).map((f) => f.id));
|
|
118324
118533
|
const base2 = themeSlug(file2.name.trim());
|
|
118325
118534
|
for (let n = 1; n < 1e3; n++) {
|
|
@@ -118627,28 +118836,28 @@ ${lost.map((l) => `- ${l}`).join("\n")}` : local ? "Nothing else is lost: no one
|
|
|
118627
118836
|
return { ok: true, text: `Deleted ${shown(s.name)} [${id3}] for good.` };
|
|
118628
118837
|
}
|
|
118629
118838
|
async empty(rpc, caller, signal) {
|
|
118630
|
-
const
|
|
118631
|
-
if (!
|
|
118632
|
-
return { ok: true, text: `The session archive is already empty.${
|
|
118839
|
+
const named3 = await this.read(rpc);
|
|
118840
|
+
if (!named3.sessions.length && !named3.runs.length && !named3.steps.length) {
|
|
118841
|
+
return { ok: true, text: `The session archive is already empty.${named3.unreached.length ? ` The session archive on ${named3.unreached.map((m) => shown(m.name)).join(", ")} could not be reached and was not looked at.` : ""}` };
|
|
118633
118842
|
}
|
|
118634
|
-
const files2 =
|
|
118635
|
-
const trees =
|
|
118843
|
+
const files2 = named3.sessions.filter((s) => s.conversationFile === "remove").length;
|
|
118844
|
+
const trees = named3.sessions.filter((s) => s.worktree?.remove).length;
|
|
118636
118845
|
const listed2 = [
|
|
118637
|
-
...
|
|
118638
|
-
...
|
|
118846
|
+
...named3.sessions.slice(0, 10).map((s) => `${shown(s.name)}${where(s)}`),
|
|
118847
|
+
...named3.sessions.length > 10 ? [`and ${named3.sessions.length - 10} more sessions`] : []
|
|
118639
118848
|
];
|
|
118640
118849
|
const refused2 = await this.ask(
|
|
118641
118850
|
caller,
|
|
118642
|
-
`Delete everything in the session archive: delete ${plural(
|
|
118851
|
+
`Delete everything in the session archive: delete ${plural(named3.sessions.length, "session")}${named3.runs.length ? `, ${plural(named3.runs.length, "kept app run")}` : ""}${named3.steps.length ? ` and the archived subagent steps of ${plural(named3.steps.length, "session")}` : ""} for good (${bytesText(named3.bytes)})? ${listed2.length ? `Sessions: ${listed2.join(", ")}. ` : ""}Their conversations, attachments and handoff notes leave this computer${files2 ? `, with ${plural(files2, "tool conversation file")}` : ""}${trees ? `${files2 ? " and" : ", with"} ${plural(trees, "worktree")}` : ""}. ${named3.unreached.length ? `The session archive on ${named3.unreached.map((m) => shown(m.name)).join(", ")} could not be reached and is left alone. ` : ""}What reaches the session archive after this card is not deleted. This cannot be undone.`,
|
|
118643
118852
|
signal
|
|
118644
118853
|
);
|
|
118645
118854
|
if (refused2) return { ok: false, error: refused2 };
|
|
118646
118855
|
const now = await this.read(rpc);
|
|
118647
118856
|
const nowById = new Map(now.sessions.map((s) => [s.id, s]));
|
|
118648
118857
|
const gone = [];
|
|
118649
|
-
const
|
|
118858
|
+
const failed4 = [];
|
|
118650
118859
|
let deleted = 0;
|
|
118651
|
-
for (const s of
|
|
118860
|
+
for (const s of named3.sessions) {
|
|
118652
118861
|
const current = nowById.get(s.id);
|
|
118653
118862
|
if (!current || !sameRow(s, current)) {
|
|
118654
118863
|
gone.push(s.name);
|
|
@@ -118658,36 +118867,36 @@ ${lost.map((l) => `- ${l}`).join("\n")}` : local ? "Nothing else is lost: no one
|
|
|
118658
118867
|
await callWindow(rpc, "trash.purge", { sessionId: s.id });
|
|
118659
118868
|
deleted++;
|
|
118660
118869
|
} catch (e) {
|
|
118661
|
-
|
|
118870
|
+
failed4.push(`${shown(s.name)}: ${e.message}`);
|
|
118662
118871
|
}
|
|
118663
118872
|
}
|
|
118664
118873
|
let runsDeleted = 0;
|
|
118665
118874
|
const nowRuns = new Set(now.runs.map((r) => r.runId));
|
|
118666
118875
|
const byMachine = /* @__PURE__ */ new Map();
|
|
118667
|
-
for (const r of
|
|
118876
|
+
for (const r of named3.runs) if (nowRuns.has(r.runId)) byMachine.set(r.machine ?? void 0, [...byMachine.get(r.machine ?? void 0) ?? [], r.runId]);
|
|
118668
118877
|
for (const [machine, runIds] of byMachine) {
|
|
118669
118878
|
try {
|
|
118670
118879
|
await callWindow(rpc, "trash.purgeRuns", { runIds, ...machine ? { machine } : {} });
|
|
118671
118880
|
runsDeleted += runIds.length;
|
|
118672
118881
|
} catch (e) {
|
|
118673
|
-
|
|
118882
|
+
failed4.push(`The app runs${machine ? ` on ${shown(machine)}` : ""}: ${e.message}`);
|
|
118674
118883
|
}
|
|
118675
118884
|
}
|
|
118676
118885
|
let stepsDeleted = 0;
|
|
118677
|
-
for (const t of
|
|
118886
|
+
for (const t of named3.steps) {
|
|
118678
118887
|
if (!now.steps.some((x) => x.sessionId === t.sessionId)) continue;
|
|
118679
118888
|
try {
|
|
118680
118889
|
await callWindow(rpc, "trash.purgeSubagentSteps", { sessionId: t.sessionId, upTo: t.deletedAt });
|
|
118681
118890
|
stepsDeleted++;
|
|
118682
118891
|
} catch (e) {
|
|
118683
|
-
|
|
118892
|
+
failed4.push(`The subagent steps of ${shown(t.name)}: ${e.message}`);
|
|
118684
118893
|
}
|
|
118685
118894
|
}
|
|
118686
118895
|
const left = await this.read(rpc).catch(() => null) ?? now;
|
|
118687
118896
|
const arrived = left.sessions.length + left.runs.length + left.steps.length;
|
|
118688
118897
|
const parts = [`Deleted for good: ${plural(deleted, "session")}${runsDeleted ? `, ${plural(runsDeleted, "app run")}` : ""}${stepsDeleted ? `, the subagent steps of ${plural(stepsDeleted, "session")}` : ""}.`];
|
|
118689
118898
|
if (gone.length) parts.push(`Not what the card named when it was answered (restored, deleted or deleted again meanwhile), so left alone: ${gone.map(shown).join(", ")}.`);
|
|
118690
|
-
if (
|
|
118899
|
+
if (failed4.length) parts.push(`Stayed in the session archive: ${failed4.join("; ")}`);
|
|
118691
118900
|
if (arrived) parts.push(`The session archive now holds ${plural(left.sessions.length, "session")}, ${plural(left.runs.length, "app run")} and subagent steps of ${plural(left.steps.length, "session")}.`);
|
|
118692
118901
|
return { ok: true, text: parts.join(" ") };
|
|
118693
118902
|
}
|
|
@@ -118718,8 +118927,8 @@ function awayLine(all, what) {
|
|
|
118718
118927
|
function whereText(p, machines) {
|
|
118719
118928
|
return p.machine ? ` on the linked machine ${shown2(machines.get(p.machine) ?? p.machine)}` : "";
|
|
118720
118929
|
}
|
|
118721
|
-
function findProject(all,
|
|
118722
|
-
const want =
|
|
118930
|
+
function findProject(all, named3) {
|
|
118931
|
+
const want = named3.trim();
|
|
118723
118932
|
if (!want) return { error: "Give project: its name or id, from list_projects." };
|
|
118724
118933
|
const byId = all.projects.find((p) => p.id === want);
|
|
118725
118934
|
if (byId) return { project: byId };
|
|
@@ -118737,8 +118946,8 @@ function appLabel2(a, all) {
|
|
|
118737
118946
|
const home = a.projectId ? project2 ? `of the project ${shown2(project2.name)}` : `of the project [${a.projectId}]` : "in the user folder";
|
|
118738
118947
|
return `${shown2(title)} (id ${shown2(a.appId)}) ${home}${whereText(a, all.machines)}`;
|
|
118739
118948
|
}
|
|
118740
|
-
function findApp(apps, all,
|
|
118741
|
-
const want =
|
|
118949
|
+
function findApp(apps, all, named3, project2, listedBy = "list_app_grants") {
|
|
118950
|
+
const want = named3.trim().toLowerCase();
|
|
118742
118951
|
if (!want) return { error: `Give app: its id or name, from ${listedBy}.` };
|
|
118743
118952
|
let pool = apps;
|
|
118744
118953
|
if (project2?.trim()) {
|
|
@@ -118750,8 +118959,8 @@ function findApp(apps, all, named2, project2, listedBy = "list_app_grants") {
|
|
|
118750
118959
|
const matches2 = byId.length ? byId : pool.filter((a) => (a.name ?? "").trim().toLowerCase() === want);
|
|
118751
118960
|
const only = matches2[0];
|
|
118752
118961
|
if (matches2.length === 1 && only) return { app: only };
|
|
118753
|
-
if (!matches2.length) return { error: `No app is called ${shown2(
|
|
118754
|
-
return { error: `${matches2.length} apps are called ${shown2(
|
|
118962
|
+
if (!matches2.length) return { error: `No app is called ${shown2(named3.trim())}${project2 ? ` in ${shown2(project2.trim())}` : ""}; ${listedBy} names them.` };
|
|
118963
|
+
return { error: `${matches2.length} apps are called ${shown2(named3.trim())}: ${matches2.map((a) => appLabel2(a, all)).join(", ")}. Give project too.` };
|
|
118755
118964
|
}
|
|
118756
118965
|
function onMachine(a) {
|
|
118757
118966
|
return a.machine ? { machine: a.machine } : {};
|
|
@@ -118859,9 +119068,9 @@ var TrustFlow = class {
|
|
|
118859
119068
|
return null;
|
|
118860
119069
|
}
|
|
118861
119070
|
}
|
|
118862
|
-
async projectTrust(rpc, caller,
|
|
119071
|
+
async projectTrust(rpc, caller, named3, trusted, signal) {
|
|
118863
119072
|
const all = await readProjects(rpc);
|
|
118864
|
-
const found = findProject(all,
|
|
119073
|
+
const found = findProject(all, named3);
|
|
118865
119074
|
if ("error" in found) return { ok: false, error: found.error };
|
|
118866
119075
|
const p = found.project;
|
|
118867
119076
|
const label = `${shown2(p.name)} [${p.id}]${whereText(p, all.machines)}`;
|
|
@@ -118938,12 +119147,12 @@ var TrustFlow = class {
|
|
|
118938
119147
|
const decision = r.decision === "allow" || r.decision === "deny" ? r.decision : shown2(r.decision);
|
|
118939
119148
|
return `- [${r.id}] ${decision} ${shown2(r.matcher)} for ${owner}${machine}, since ${new Date(r.createdAt).toISOString().slice(0, 10)}`;
|
|
118940
119149
|
}
|
|
118941
|
-
async listRules(rpc,
|
|
119150
|
+
async listRules(rpc, named3) {
|
|
118942
119151
|
const [rules, o] = await Promise.all([this.rules(rpc), this.owners(rpc)]);
|
|
118943
119152
|
let shownRules = rules;
|
|
118944
119153
|
let of2 = "";
|
|
118945
|
-
if (
|
|
118946
|
-
const found = findProject(o.all,
|
|
119154
|
+
if (named3?.trim()) {
|
|
119155
|
+
const found = findProject(o.all, named3);
|
|
118947
119156
|
if ("error" in found) return { ok: false, error: found.error };
|
|
118948
119157
|
shownRules = rules.filter((r) => r.projectId === found.project.id);
|
|
118949
119158
|
of2 = ` of ${shown2(found.project.name)}`;
|
|
@@ -118973,11 +119182,11 @@ var TrustFlow = class {
|
|
|
118973
119182
|
// person gave to an app's capability questions (forgetting one only makes it ask again), the remembered consents of one
|
|
118974
119183
|
// project reaching another (revoking one makes the next reach ask again), and sharing a project app with the person's
|
|
118975
119184
|
// other projects, which widens who can attach it and so asks.
|
|
118976
|
-
async listAppGrants(rpc,
|
|
119185
|
+
async listAppGrants(rpc, named3, project2) {
|
|
118977
119186
|
const [apps, all, consents] = await Promise.all([callWindow(rpc, "apps.list", {}), readProjects(rpc), callWindow(rpc, "projectConsents.list", {}).catch(() => [])]);
|
|
118978
119187
|
let pool = apps;
|
|
118979
|
-
if (
|
|
118980
|
-
const found = findApp(apps, all,
|
|
119188
|
+
if (named3?.trim()) {
|
|
119189
|
+
const found = findApp(apps, all, named3, project2);
|
|
118981
119190
|
if ("error" in found) return { ok: false, error: found.error };
|
|
118982
119191
|
pool = [found.app];
|
|
118983
119192
|
} else if (project2?.trim()) {
|
|
@@ -119000,7 +119209,7 @@ var TrustFlow = class {
|
|
|
119000
119209
|
pool.length ? `${pool.length} ${pool.length === 1 ? "app" : "apps"}, with the answers the person gave to what each asked for (forget_app_answer forgets one, so it asks again; share_app shares a project app):` : "No app.",
|
|
119001
119210
|
...out
|
|
119002
119211
|
];
|
|
119003
|
-
if (!
|
|
119212
|
+
if (!named3?.trim() && !project2?.trim()) {
|
|
119004
119213
|
lines.push(
|
|
119005
119214
|
consents.length ? `${consents.length} remembered ${consents.length === 1 ? "consent" : "consents"} of one project reaching another (revoke_project_consent revokes one, so the next reach asks again):` : "No remembered consent of one project reaching another.",
|
|
119006
119215
|
...rows2(consents, (c) => `- ${shown2(c.fromName)} [${c.fromProjectId}] may ${consentWords(c.kind)} ${shown2(c.toName)} [${c.toProjectId}]${whereText(c, all.machines)}, since ${new Date(c.decidedAt).toISOString().slice(0, 10)}`)
|
|
@@ -119009,9 +119218,9 @@ var TrustFlow = class {
|
|
|
119009
119218
|
lines.push(...awayLine(all, "the apps and answers kept"));
|
|
119010
119219
|
return { ok: true, text: lines.join("\n") };
|
|
119011
119220
|
}
|
|
119012
|
-
async forgetAnswer(rpc,
|
|
119221
|
+
async forgetAnswer(rpc, named3, project2, capability) {
|
|
119013
119222
|
const [apps, all] = await Promise.all([callWindow(rpc, "apps.list", {}), readProjects(rpc)]);
|
|
119014
|
-
const found = findApp(apps, all,
|
|
119223
|
+
const found = findApp(apps, all, named3, project2);
|
|
119015
119224
|
if ("error" in found) return { ok: false, error: found.error };
|
|
119016
119225
|
const a = found.app;
|
|
119017
119226
|
const answers2 = await callWindow(rpc, "apps.permissions", { appId: a.appId, projectId: a.projectId, ...onMachine(a) });
|
|
@@ -119022,11 +119231,11 @@ var TrustFlow = class {
|
|
|
119022
119231
|
}
|
|
119023
119232
|
async revokeConsent(rpc, from, to, kind) {
|
|
119024
119233
|
const [consents, all] = await Promise.all([callWindow(rpc, "projectConsents.list", {}), readProjects(rpc)]);
|
|
119025
|
-
const idOf = (
|
|
119026
|
-
const found = findProject(all,
|
|
119234
|
+
const idOf = (named3) => {
|
|
119235
|
+
const found = findProject(all, named3);
|
|
119027
119236
|
return "error" in found ? null : found.project.id;
|
|
119028
119237
|
};
|
|
119029
|
-
const match = (
|
|
119238
|
+
const match = (named3, id3, name) => named3.trim() === id3 || idOf(named3) === id3 || name.trim().toLowerCase() === named3.trim().toLowerCase();
|
|
119030
119239
|
const hits = consents.filter((c2) => c2.kind === kind && match(from, c2.fromProjectId, c2.fromName) && match(to, c2.toProjectId, c2.toName));
|
|
119031
119240
|
if (!hits.length) return { ok: false, error: `No remembered consent lets ${shown2(from.trim())} ${consentWords(kind)} ${shown2(to.trim())}; list_app_grants lists them.` };
|
|
119032
119241
|
if (hits.length > 1) return { ok: false, error: `${hits.length} remembered consents match; give the project ids list_app_grants shows.` };
|
|
@@ -119034,9 +119243,9 @@ var TrustFlow = class {
|
|
|
119034
119243
|
await callWindow(rpc, "projectConsents.revoke", { fromProjectId: c.fromProjectId, toProjectId: c.toProjectId, kind: c.kind });
|
|
119035
119244
|
return { ok: true, text: `Revoked: ${shown2(c.fromName)} may no longer ${consentWords(c.kind)} ${shown2(c.toName)} unasked; the next time it does, the person is asked again.` };
|
|
119036
119245
|
}
|
|
119037
|
-
async shareApp(rpc, caller,
|
|
119246
|
+
async shareApp(rpc, caller, named3, project2, shared, signal) {
|
|
119038
119247
|
const [apps, all] = await Promise.all([callWindow(rpc, "apps.list", {}), readProjects(rpc)]);
|
|
119039
|
-
const found = findApp(apps, all,
|
|
119248
|
+
const found = findApp(apps, all, named3, project2);
|
|
119040
119249
|
if ("error" in found) return { ok: false, error: found.error };
|
|
119041
119250
|
const a = found.app;
|
|
119042
119251
|
const label = appLabel2(a, all);
|
|
@@ -119350,9 +119559,9 @@ var HousekeepingFlow = class {
|
|
|
119350
119559
|
const rows3 = r.models.slice(0, 40).map((m) => `- ${shown2(m.id)}: ${plainQuoted(m.label, 80)}${m.efforts.length ? `; efforts ${m.efforts.map((e) => plainQuoted(e, 40)).join(", ")}` : ""}`);
|
|
119351
119560
|
return { ok: true, text: [`The models ${shown2(name)} offers (create_session and update_session_settings take an id):`, ...rows3, ...r.models.length > 40 ? [`- and ${r.models.length - 40} more`] : []].join("\n") };
|
|
119352
119561
|
}
|
|
119353
|
-
async gitStatus(rpc,
|
|
119562
|
+
async gitStatus(rpc, named3) {
|
|
119354
119563
|
const all = await readProjects(rpc);
|
|
119355
|
-
const found = findProject(all,
|
|
119564
|
+
const found = findProject(all, named3);
|
|
119356
119565
|
if ("error" in found) return { ok: false, error: found.error };
|
|
119357
119566
|
const p = found.project;
|
|
119358
119567
|
const [status, origin] = await Promise.all([callWindow(rpc, "projects.gitStatus", { projectId: p.id }), callWindow(rpc, "projects.origin", { projectId: p.id }).catch(() => null)]);
|
|
@@ -119364,12 +119573,12 @@ var HousekeepingFlow = class {
|
|
|
119364
119573
|
const changed = g5.unknown ? "changes not counted" : `${plural(g5.changedFiles, "changed file")}${g5.more ? " or more" : ""}`;
|
|
119365
119574
|
return { ok: true, text: `${label}: on the branch ${shown2(g5.branch)}, ${changed}${origin?.origin ? `; origin ${shown2(origin.origin)}` : "; no origin"}.` };
|
|
119366
119575
|
}
|
|
119367
|
-
async searchFiles(rpc,
|
|
119576
|
+
async searchFiles(rpc, named3, query, limit) {
|
|
119368
119577
|
const q2 = query.trim();
|
|
119369
119578
|
if (!q2) return { ok: false, error: "Give query: part of a file name to look for." };
|
|
119370
119579
|
if (HIDDEN3.test(q2)) return { ok: false, error: "query has a control or formatting character in it; give it as plain text." };
|
|
119371
119580
|
const all = await readProjects(rpc);
|
|
119372
|
-
const found = findProject(all,
|
|
119581
|
+
const found = findProject(all, named3);
|
|
119373
119582
|
if ("error" in found) return { ok: false, error: found.error };
|
|
119374
119583
|
const n = Math.min(Math.max(Math.trunc(limit ?? 20), 1), 50);
|
|
119375
119584
|
const hits = await callWindow(rpc, "files.search", { projectId: found.project.id, query: q2, limit: n });
|
|
@@ -119524,15 +119733,15 @@ var ProjectCreation = class {
|
|
|
119524
119733
|
* makes. That host makes the same checks again when it registers the folder.
|
|
119525
119734
|
*/
|
|
119526
119735
|
async addFolderOnMachine(sessionId, reader, machine, path2, signal) {
|
|
119527
|
-
const
|
|
119528
|
-
if (!
|
|
119529
|
-
const refused2 = folderRefusal(
|
|
119736
|
+
const read2 = await reader.inspectFolder(machine.id, path2);
|
|
119737
|
+
if (!read2.ok) return read2;
|
|
119738
|
+
const refused2 = folderRefusal(read2.facts, machine.name) ?? await this.askFolderAdd(sessionId, read2.facts, machine.name, signal);
|
|
119530
119739
|
if (refused2) return { ok: false, error: refused2 };
|
|
119531
|
-
const again = await reader.inspectFolder(machine.id,
|
|
119740
|
+
const again = await reader.inspectFolder(machine.id, read2.facts.path);
|
|
119532
119741
|
if (!again.ok) return again;
|
|
119533
119742
|
const changed = folderRefusal(again.facts, machine.name);
|
|
119534
119743
|
if (changed) return { ok: false, error: `${changed} It changed while the card stood, so nothing was added.` };
|
|
119535
|
-
const added = await reader.addProject(machine.id,
|
|
119744
|
+
const added = await reader.addProject(machine.id, read2.facts.path);
|
|
119536
119745
|
if (!added.ok) return added;
|
|
119537
119746
|
this.host.emit({ type: "projects_changed", added: added.projectId });
|
|
119538
119747
|
return { ...added, machine: machine.name };
|
|
@@ -120780,9 +120989,9 @@ var AppAccess = class {
|
|
|
120780
120989
|
if (!gate.ok) return gate;
|
|
120781
120990
|
const { session: session2 } = gate;
|
|
120782
120991
|
const already = this.deps.hub.refsFor(session2);
|
|
120783
|
-
const
|
|
120784
|
-
if (!
|
|
120785
|
-
const app2 =
|
|
120992
|
+
const named3 = this.resolve(ref);
|
|
120993
|
+
if (!named3.ok) return named3;
|
|
120994
|
+
const app2 = named3.app;
|
|
120786
120995
|
const target = { projectId: app2.projectId, appId: app2.appId };
|
|
120787
120996
|
const has = already.find((h) => h.ref.appId === target.appId && h.ref.projectId === target.projectId);
|
|
120788
120997
|
if (has) return { ok: true, server: has.server, tools: await this.toolNames(target), when: "now", already: true };
|
|
@@ -122352,6 +122561,58 @@ var MailboxRecords = class {
|
|
|
122352
122561
|
for (const r of rows3) told.run(at2, r.messageId, r.recipient);
|
|
122353
122562
|
});
|
|
122354
122563
|
}
|
|
122564
|
+
// ── Across a link (#2067 item 2, docs/plans/linked-mail.md §6) ──
|
|
122565
|
+
/** Whether `sender` ever sent a message to an address that starts with `prefix` (a linked machine's sessions, `session:<hub>/<machine>.`) */
|
|
122566
|
+
sentToward(sender, prefix) {
|
|
122567
|
+
const like = `${prefix.replace(/[\\%_]/g, (c) => `\\${c}`)}%`;
|
|
122568
|
+
return this.db.prepare(`SELECT 1 AS one FROM mail m JOIN mail_recipients r ON r.message_id = m.id WHERE m.sender = ? AND r.recipient LIKE ? ESCAPE '\\' LIMIT 1`).get(sender, like) !== void 0;
|
|
122569
|
+
}
|
|
122570
|
+
/**
|
|
122571
|
+
* The rows of messages that crossed a link, with each message's sender: a row whose recipient or whose message's sender is
|
|
122572
|
+
* on another host (`session:<other host>/…`, or this host's id with a dotted session id: a linked machine's session as a
|
|
122573
|
+
* hub names it). Only those still open, or settled or released since `since`: what the other side may not have heard yet
|
|
122574
|
+
*/
|
|
122575
|
+
acrossRows(ownHost, since) {
|
|
122576
|
+
const own = `session:${ownHost}/%`;
|
|
122577
|
+
const dotted = `session:${ownHost}/%.%`;
|
|
122578
|
+
const foreign = (x) => `(${x} LIKE 'session:%' AND (${x} NOT LIKE @own OR ${x} LIKE @dotted))`;
|
|
122579
|
+
return this.db.prepare(
|
|
122580
|
+
`SELECT r.*, m.sender AS sender FROM mail_recipients r JOIN mail m ON m.id = r.message_id
|
|
122581
|
+
WHERE (${foreign("r.recipient")} OR ${foreign("m.sender")})
|
|
122582
|
+
AND (r.settled IS NULL OR r.settled_at >= @since OR r.released_at >= @since)
|
|
122583
|
+
ORDER BY m.created_at, m.id`
|
|
122584
|
+
).all({ own, dotted, since }).map((r) => ({ ...toRecipient(r), sender: r.sender }));
|
|
122585
|
+
}
|
|
122586
|
+
/**
|
|
122587
|
+
* What the other side of a link knows of a row of a message that crossed, merged forward only (§6). `copy`: this host
|
|
122588
|
+
* sent the message and keeps a copy, and takes from the recipient's host when it was delivered and read, how it was
|
|
122589
|
+
* settled and with which answer, and its release, which the recipient's host already told the sender of. `recipient`:
|
|
122590
|
+
* the row is this host's own recipient's, and takes only a withdrawal, which is the sender's to make. Returns whether
|
|
122591
|
+
* anything changed
|
|
122592
|
+
*/
|
|
122593
|
+
mergeAcross(row, side) {
|
|
122594
|
+
if (side === "recipient") {
|
|
122595
|
+
if (row.settled !== "withdrawn") return false;
|
|
122596
|
+
return this.settle(row.messageId, row.recipient, "withdrawn", row.settledAt ?? Date.now()) > 0;
|
|
122597
|
+
}
|
|
122598
|
+
return this.db.prepare(
|
|
122599
|
+
`UPDATE mail_recipients SET
|
|
122600
|
+
delivered_at = COALESCE(@deliveredAt, delivered_at),
|
|
122601
|
+
read_at = COALESCE(read_at, @readAt),
|
|
122602
|
+
settled = COALESCE(settled, @settled),
|
|
122603
|
+
settled_at = CASE WHEN settled IS NULL THEN @settledAt ELSE settled_at END,
|
|
122604
|
+
answer_id = COALESCE(answer_id, @answerId),
|
|
122605
|
+
released_at = COALESCE(released_at, @releasedAt),
|
|
122606
|
+
released_why = COALESCE(released_why, @releasedWhy),
|
|
122607
|
+
told_at = CASE WHEN told_at IS NULL AND @releasedAt IS NOT NULL THEN @releasedAt ELSE told_at END
|
|
122608
|
+
WHERE message_id = @messageId AND recipient = @recipient
|
|
122609
|
+
AND (delivered_at IS NOT @deliveredAt AND @deliveredAt IS NOT NULL
|
|
122610
|
+
OR read_at IS NULL AND @readAt IS NOT NULL
|
|
122611
|
+
OR settled IS NULL AND @settled IS NOT NULL
|
|
122612
|
+
OR answer_id IS NULL AND @answerId IS NOT NULL
|
|
122613
|
+
OR released_at IS NULL AND @releasedAt IS NOT NULL)`
|
|
122614
|
+
).run(row).changes > 0;
|
|
122615
|
+
}
|
|
122355
122616
|
// ── Cover (§10.3) ──
|
|
122356
122617
|
/**
|
|
122357
122618
|
* A row that spares `r` a reminder: of a watched message or task its recipient sent after `r` was delivered, whose cause
|
|
@@ -122534,18 +122795,18 @@ var MailboxRecords = class {
|
|
|
122534
122795
|
(r.settled IS NULL AND r.released_at IS NULL AND ${WATCHED})
|
|
122535
122796
|
OR (r.delivered_at IS NULL AND ${WAITING})
|
|
122536
122797
|
OR (${HELD})))`;
|
|
122537
|
-
const
|
|
122538
|
-
const
|
|
122798
|
+
const unread3 = `EXISTS (SELECT 1 FROM mail_recipients r WHERE r.message_id = m.id AND r.read_at IS NULL)`;
|
|
122799
|
+
const pick5 = this.db.prepare(
|
|
122539
122800
|
`SELECT m.id FROM mail m
|
|
122540
122801
|
WHERE m.created_at <= @waiting
|
|
122541
122802
|
OR (m.created_at <= @settled AND NOT ${waits})
|
|
122542
|
-
OR (m.kind = 'notice' AND m.created_at <= @notice AND NOT ${waits} AND NOT ${
|
|
122803
|
+
OR (m.kind = 'notice' AND m.created_at <= @notice AND NOT ${waits} AND NOT ${unread3})
|
|
122543
122804
|
ORDER BY m.created_at LIMIT @batch`
|
|
122544
122805
|
);
|
|
122545
122806
|
let messages2 = 0;
|
|
122546
122807
|
for (; ; ) {
|
|
122547
122808
|
const n = this.transaction(() => {
|
|
122548
|
-
const ids = idList(
|
|
122809
|
+
const ids = idList(pick5.all({ waiting: now - l.waitingMs, settled: now - l.settledMs, notice: now - l.readNoticeMs, batch: l.batch }).map((r) => r.id));
|
|
122549
122810
|
this.db.prepare(`DELETE FROM mail_recipients WHERE message_id IN (SELECT value FROM json_each(?))`).run(ids);
|
|
122550
122811
|
return this.db.prepare(`DELETE FROM mail WHERE id IN (SELECT value FROM json_each(?))`).run(ids).changes;
|
|
122551
122812
|
});
|
|
@@ -122849,6 +123110,23 @@ function presetFromHub(params, prefs, projectTrusted) {
|
|
|
122849
123110
|
return presetWithin(given, "normal") ? given : "normal";
|
|
122850
123111
|
}
|
|
122851
123112
|
var startedFromHubKey = (sessionId) => `started_from_hub:${sessionId}`;
|
|
123113
|
+
var startedByHubKey = (sessionId) => `started_from_hub_by:${sessionId}`;
|
|
123114
|
+
function recordStartingHub(settings, sessionId, hub) {
|
|
123115
|
+
settings.setAppSetting(startedByHubKey(sessionId), JSON.stringify({ id: hub.id, name: hub.name }));
|
|
123116
|
+
}
|
|
123117
|
+
function startingHub(settings, sessionId) {
|
|
123118
|
+
const raw = settings.appSetting(startedByHubKey(sessionId));
|
|
123119
|
+
if (!raw) return null;
|
|
123120
|
+
try {
|
|
123121
|
+
const v = JSON.parse(raw);
|
|
123122
|
+
if (typeof v !== "object" || v === null) return null;
|
|
123123
|
+
const id3 = Reflect.get(v, "id");
|
|
123124
|
+
const name = Reflect.get(v, "name");
|
|
123125
|
+
return typeof id3 === "string" && id3 && typeof name === "string" ? { id: id3, name } : null;
|
|
123126
|
+
} catch {
|
|
123127
|
+
return null;
|
|
123128
|
+
}
|
|
123129
|
+
}
|
|
122852
123130
|
function withHubMark(settings, info) {
|
|
122853
123131
|
return settings.appSetting(startedFromHubKey(info.id)) === "true" ? { ...info, startedFromHub: true } : info;
|
|
122854
123132
|
}
|
|
@@ -123321,6 +123599,7 @@ var SessionStarts = class {
|
|
|
123321
123599
|
if (noCodeIntelligence) this.host.store.settings.setAppSetting(codeIntelligenceKey(id3), "off");
|
|
123322
123600
|
if (params.agentDepth) this.host.store.settings.setAppSetting(agentDepthKey(id3), String(params.agentDepth));
|
|
123323
123601
|
if (params.fromHub) this.host.store.settings.setAppSetting(startedFromHubKey(id3), "true");
|
|
123602
|
+
if (params.fromHub && params.startedByHub) recordStartingHub(this.host.store.settings, id3, params.startedByHub);
|
|
123324
123603
|
this.host.launches.rememberToolPrefix(id3);
|
|
123325
123604
|
this.host.launches.rememberLaunchSettings(info, cwd);
|
|
123326
123605
|
this.host.store.sessions.setSessionCwd(id3, cwd);
|
|
@@ -123871,8 +124150,8 @@ var SessionEvents = class {
|
|
|
123871
124150
|
this.host.children.noteTurnStart(m.id, m.lastSeq);
|
|
123872
124151
|
}
|
|
123873
124152
|
if (e.type === "state_change" && e.state === "working") {
|
|
123874
|
-
const
|
|
123875
|
-
started = this.host.children.turnNamed(m.id,
|
|
124153
|
+
const named3 = handle2?.turnStartInputs?.();
|
|
124154
|
+
started = this.host.children.turnNamed(m.id, named3);
|
|
123876
124155
|
}
|
|
123877
124156
|
if (!wasBusy && !inTurn(m.state) && (e.type === "error" || e.type === "limit_reached") && this.host.children.delivering.has(m.id) && this.host.queue.queuedHandedIn.has(m.id)) {
|
|
123878
124157
|
this.host.children.queuedTurnStarted(m.id);
|
|
@@ -124375,7 +124654,7 @@ var MessageService = class {
|
|
|
124375
124654
|
const facts = { ...clarifies !== void 0 ? { clarifies } : {}, ...quiet ? { quiet: true } : {}, ...cited ? { cites: cited } : {} };
|
|
124376
124655
|
const stored = this.put(
|
|
124377
124656
|
// The citation's one use: `UNIQUE(sender, dedupe_key)` (`personWord` looked first, in this transaction)
|
|
124378
|
-
{ sender, kind, body: text3, needsReply, replyTo: target?.id ?? null, causeId, depth: 0, urgent, facts, origin: cls === "person" ? "person" : cls === "app" ? "app" : "mail", ...cited ? { dedupeKey: citeKey(cited.seq) } : {} },
|
|
124657
|
+
{ ...input.id ? { id: input.id } : {}, sender, kind, body: text3, needsReply, replyTo: target?.id ?? null, causeId, depth: 0, urgent, facts, origin: cls === "person" ? "person" : cls === "app" ? "app" : "mail", ...cited ? { dedupeKey: citeKey(cited.seq) } : {} },
|
|
124379
124658
|
to.map((r, i) => this.row(r, { dueAt: dueAt(now, urgent, cls === "person"), via: input.to.length > 0 ? input.via?.[input.to.indexOf(r)] ?? null : null, held: holds[i] ?? null }))
|
|
124380
124659
|
);
|
|
124381
124660
|
const held2 = to.flatMap((recipient, i) => holds[i] ? [{ recipient, why: holds[i] }] : []);
|
|
@@ -124387,6 +124666,29 @@ var MessageService = class {
|
|
|
124387
124666
|
return { message: stored, held: held2, answered: target?.id ?? null, quiet, asWork, ...cited ? { cited } : {}, ...typeof word === "string" ? { notCited: word } : {} };
|
|
124388
124667
|
});
|
|
124389
124668
|
}
|
|
124669
|
+
/** A new message id of this host's, for a message another host writes first (#2067 review, `MailAcross.send`) */
|
|
124670
|
+
mintId() {
|
|
124671
|
+
return messageIdOf(this.opts.hostId, this.ulids.next(this.now()));
|
|
124672
|
+
}
|
|
124673
|
+
/**
|
|
124674
|
+
* The sender's copy of a message another host took (#2067 item 2, docs/plans/linked-mail.md §6): written only once that
|
|
124675
|
+
* host answered with the message's id, under the same id, so a reply there and here names one message. Its one row is
|
|
124676
|
+
* the foreign recipient's, delivered at hand-over, so this host's delivery never tries it; the recipient's host pushes
|
|
124677
|
+
* what becomes of it (`MailboxRecords.mergeAcross`). No guard runs here: they ran where the message was written. An
|
|
124678
|
+
* answer settles the sender's own row on what it answers, as `send` does
|
|
124679
|
+
*/
|
|
124680
|
+
sentAcross(sender, input) {
|
|
124681
|
+
return this.run(() => {
|
|
124682
|
+
const now = this.now();
|
|
124683
|
+
const target = input.replyTo === void 0 ? void 0 : this.records.message(input.replyTo);
|
|
124684
|
+
const stored = this.put(
|
|
124685
|
+
{ id: input.id, sender, kind: "message", body: input.text, needsReply: input.needsReply, urgent: input.urgent === true, replyTo: target?.id ?? null, origin: "mail", createdAt: now },
|
|
124686
|
+
[this.row(input.to, { dueAt: now, deliveredAt: now })]
|
|
124687
|
+
);
|
|
124688
|
+
if (target?.kind === "message" && target.needsReply && this.records.recipient(target.id, sender)) this.records.settle(target.id, sender, "answered", now, stored.id);
|
|
124689
|
+
return stored;
|
|
124690
|
+
});
|
|
124691
|
+
}
|
|
124390
124692
|
/**
|
|
124391
124693
|
* The person's word a request cites, checked in code (docs/plans/cited-requests.md §3): the newest message the person typed in the sender's own
|
|
124392
124694
|
* conversation, at most `CITE_MS` old and not later than now, not cited before by this sender. Or, when none passes, why not, in words for the sender
|
|
@@ -124539,8 +124841,8 @@ var MessageService = class {
|
|
|
124539
124841
|
const oldest = chain.at(-1) ?? base2;
|
|
124540
124842
|
const missing = oldest.replyTo !== null && chain.length < READ_CHAIN && this.records.message(oldest.replyTo) === void 0;
|
|
124541
124843
|
const items = [...missing ? [this.gone(oldest.replyTo ?? "")] : [], ...chain.reverse().map((m) => this.item(m, reader, turn)), ...opts.id === void 0 ? [] : [this.item(base2, reader, turn)]];
|
|
124542
|
-
const
|
|
124543
|
-
const marked =
|
|
124844
|
+
const read2 = opts.id === void 0 ? void 0 : items.at(-1);
|
|
124845
|
+
const marked = read2 && !read2.phantom && !read2.withheld && read2.row ? this.records.markRead(reader, [base2.id], now) : 0;
|
|
124544
124846
|
return { items, older: !missing && chain.length === READ_CHAIN && oldest.replyTo !== null ? oldest.id : null, marked };
|
|
124545
124847
|
});
|
|
124546
124848
|
}
|
|
@@ -124553,7 +124855,7 @@ var MessageService = class {
|
|
|
124553
124855
|
return m?.kind === "message" && !isHidden(row) ? [m] : [];
|
|
124554
124856
|
}).map((m) => this.item(m, reader, turn));
|
|
124555
124857
|
const listed2 = new Set(needReply.map((i) => i.message.id));
|
|
124556
|
-
const
|
|
124858
|
+
const unread3 = this.records.unreadFor(reader).filter((p) => !listed2.has(p.message.id)).map((p) => this.item(p.message, reader, turn));
|
|
124557
124859
|
const waiting = this.records.watchedFrom(reader).flatMap((row) => {
|
|
124558
124860
|
const message = messageOf2(row);
|
|
124559
124861
|
return message?.kind === "message" && message.needsReply ? [{ row, message }] : [];
|
|
@@ -124562,7 +124864,7 @@ var MessageService = class {
|
|
|
124562
124864
|
const message = messageOf2(row);
|
|
124563
124865
|
return message?.sender === reader && isHidden(row) ? [{ row, message, why: row.held === "loop" ? "loop" : "policy" }] : [];
|
|
124564
124866
|
});
|
|
124565
|
-
return { needReply, unread:
|
|
124867
|
+
return { needReply, unread: unread3, waiting, held: held2 };
|
|
124566
124868
|
}
|
|
124567
124869
|
/**
|
|
124568
124870
|
* Whether mail that wakes `recipient` waits for it, due or not yet (the debounce makes a message wait a moment before it is due): a turn of its own is
|
|
@@ -125016,7 +125318,7 @@ var MessageService = class {
|
|
|
125016
125318
|
checkText(cls, text3) {
|
|
125017
125319
|
if (typeof text3 !== "string") throw refuse4("bad_value", "a body is text");
|
|
125018
125320
|
if (text3.trim() === "") throw refuse4("empty", "a post says something");
|
|
125019
|
-
if (text3.length > bodyLimit(cls)) throw refuse4("too_long",
|
|
125321
|
+
if (text3.length > bodyLimit(cls)) throw refuse4("too_long", tooLongText(cls));
|
|
125020
125322
|
return text3;
|
|
125021
125323
|
}
|
|
125022
125324
|
refusalText(why2, to) {
|
|
@@ -125303,7 +125605,7 @@ var MailSessionsView = class {
|
|
|
125303
125605
|
host;
|
|
125304
125606
|
/** What the mailbox asks of the sessions (#1347): set once by the host, null in a manager that has no mailbox */
|
|
125305
125607
|
hooks = null;
|
|
125306
|
-
/**
|
|
125608
|
+
/** A child this host started on a linked machine, by its name there (#2067): mail refuses it as elsewhere, not as gone */
|
|
125307
125609
|
onLinkedMachine(sessionId) {
|
|
125308
125610
|
return this.host.linkedChild(sessionId);
|
|
125309
125611
|
}
|
|
@@ -126252,8 +126554,8 @@ var UpdateResumeLists = class {
|
|
|
126252
126554
|
done(id3) {
|
|
126253
126555
|
this.dealt.add(id3);
|
|
126254
126556
|
for (const [name, l] of this.lists) {
|
|
126255
|
-
const
|
|
126256
|
-
if (!
|
|
126557
|
+
const named3 = [...l.turns, ...l.stopped];
|
|
126558
|
+
if (!named3.some((t) => t.id === id3) || !named3.every((t) => this.dealt.has(t.id))) continue;
|
|
126257
126559
|
this.lists.delete(name);
|
|
126258
126560
|
this.removeList(name, "the turns it names are over, and a later start removes it");
|
|
126259
126561
|
}
|
|
@@ -127342,7 +127644,7 @@ var ContextNudges = class {
|
|
|
127342
127644
|
const percent = Math.round(c.size / window2 * 100);
|
|
127343
127645
|
const used = `${Math.round(c.size / 1e3)}k of ${Math.round(window2 / 1e3)}k tokens`;
|
|
127344
127646
|
const text3 = which === "second" && c.point !== null ? `[Centralu] Your context is now about ${percent}% full (${used}), and the tool compacts it by itself in the middle of work at ${Math.round(c.point * 100)}%. When the current step is done, at the latest, call compact_self with "then" set to what you do next, and end your turn; do not stop what you are doing for it.` : `[Centralu] Your context is now about ${percent}% full (${used}). When this step of the work is done, call compact_self with "then" set to what you do next, and end your turn, so the next step starts from a summary; do not stop what you are doing for it.`;
|
|
127345
|
-
const
|
|
127647
|
+
const failed4 = (err) => {
|
|
127346
127648
|
c.waiting = null;
|
|
127347
127649
|
console.error(`[compact] ${id3.slice(0, 8)}: could not send the context notice: ${err instanceof Error ? err.message : String(err)}`);
|
|
127348
127650
|
};
|
|
@@ -127355,7 +127657,7 @@ var ContextNudges = class {
|
|
|
127355
127657
|
try {
|
|
127356
127658
|
took = this.host.nudge(id3, text3);
|
|
127357
127659
|
} catch (err) {
|
|
127358
|
-
|
|
127660
|
+
failed4(err);
|
|
127359
127661
|
return;
|
|
127360
127662
|
}
|
|
127361
127663
|
if (typeof took === "boolean") {
|
|
@@ -127370,7 +127672,7 @@ var ContextNudges = class {
|
|
|
127370
127672
|
},
|
|
127371
127673
|
(err) => {
|
|
127372
127674
|
c.sending = false;
|
|
127373
|
-
if (!this.stopped && this.cycles.get(id3) === c)
|
|
127675
|
+
if (!this.stopped && this.cycles.get(id3) === c) failed4(err);
|
|
127374
127676
|
}
|
|
127375
127677
|
);
|
|
127376
127678
|
}
|
|
@@ -127450,8 +127752,8 @@ var LocalAgentProcess = class _LocalAgentProcess extends EventEmitter2 {
|
|
|
127450
127752
|
static spawn(spec, os2) {
|
|
127451
127753
|
let started;
|
|
127452
127754
|
try {
|
|
127453
|
-
const
|
|
127454
|
-
started =
|
|
127755
|
+
const watched2 = !!spec.endsWithHost && hasProcessGroups(os2?.platform);
|
|
127756
|
+
started = watched2 ? spawnGrouped("/bin/sh", ["-c", HOST_WATCH, "centralu-agent", spec.command, ...spec.args], { cwd: spec.cwd, env: spec.env, stdio: ["pipe", "pipe", "pipe", "pipe", "pipe"] }, os2?.platform) : spawnGrouped(spec.command, spec.args, { cwd: spec.cwd, env: spec.env, stdio: ["pipe", "pipe", "pipe"] }, os2?.platform);
|
|
127455
127757
|
} catch (err) {
|
|
127456
127758
|
started = tracked(notStarted(err), Date.now());
|
|
127457
127759
|
}
|
|
@@ -127914,13 +128216,13 @@ var CoreSession = class {
|
|
|
127914
128216
|
sendTracked(text3, observer, opts) {
|
|
127915
128217
|
return this.enqueue(text3, opts?.id ?? null, false, observer);
|
|
127916
128218
|
}
|
|
127917
|
-
enqueue(text3,
|
|
128219
|
+
enqueue(text3, named3, compact, observer) {
|
|
127918
128220
|
const receipt = this.receipts.create(observer);
|
|
127919
128221
|
if (this.phase === "closed") {
|
|
127920
128222
|
this.receipts.fail([receipt.id], new Error(`${this.wire.label} session is closed`));
|
|
127921
128223
|
return receipt.done;
|
|
127922
128224
|
}
|
|
127923
|
-
this.queue.push({ input: { id: receipt.id, text: text3, compact }, named:
|
|
128225
|
+
this.queue.push({ input: { id: receipt.id, text: text3, compact }, named: named3 });
|
|
127924
128226
|
this.drain();
|
|
127925
128227
|
return receipt.done;
|
|
127926
128228
|
}
|
|
@@ -128199,15 +128501,15 @@ var Grants = class {
|
|
|
128199
128501
|
// packages/agent-host/src/adapters/file-changes.ts
|
|
128200
128502
|
var DIFF_PREVIEW_CHARS = 4e3;
|
|
128201
128503
|
function fileEditDetail(changes) {
|
|
128202
|
-
const
|
|
128203
|
-
const diff =
|
|
128504
|
+
const named3 = changes.filter((c) => c.path);
|
|
128505
|
+
const diff = named3.length > 1 ? named3.map((c) => `${c.path}
|
|
128204
128506
|
${c.diff}`).join("\n\n") : changes.map((c) => c.diff).filter(Boolean).join("\n");
|
|
128205
|
-
const one2 =
|
|
128507
|
+
const one2 = named3.length === 1 ? named3[0] : null;
|
|
128206
128508
|
return {
|
|
128207
128509
|
kind: "file_edit",
|
|
128208
|
-
path:
|
|
128510
|
+
path: named3[0]?.path || NO_PATH,
|
|
128209
128511
|
diffPreview: diff.slice(0, DIFF_PREVIEW_CHARS),
|
|
128210
|
-
multi:
|
|
128512
|
+
multi: named3.length > 1,
|
|
128211
128513
|
...one2?.change ? { change: one2.change } : {},
|
|
128212
128514
|
...one2?.movePath ? { movePath: one2.movePath } : {}
|
|
128213
128515
|
};
|
|
@@ -129348,20 +129650,20 @@ var AcpWire = class {
|
|
|
129348
129650
|
this.unmapped.note(method);
|
|
129349
129651
|
return;
|
|
129350
129652
|
}
|
|
129351
|
-
const
|
|
129352
|
-
if (!
|
|
129353
|
-
if ("update" in
|
|
129354
|
-
this.commands =
|
|
129653
|
+
const read2 = readUpdate(params);
|
|
129654
|
+
if (!read2) return;
|
|
129655
|
+
if ("update" in read2 && read2.update.sessionUpdate === "available_commands_update" && (read2.sessionId === this.conversation || read2.sessionId === this.opening)) {
|
|
129656
|
+
this.commands = read2.update.availableCommands.map((c) => ({ name: c.name, ...c.description ? { description: c.description } : {}, ...c.input?.hint ? { argumentHint: c.input.hint } : {} }));
|
|
129355
129657
|
return;
|
|
129356
129658
|
}
|
|
129357
|
-
if (
|
|
129659
|
+
if (read2.sessionId !== this.conversation || this.replaying) return;
|
|
129358
129660
|
const turn = this.turn;
|
|
129359
129661
|
this.resendLostCancel();
|
|
129360
|
-
if ("other" in
|
|
129361
|
-
this.unmapped.note(
|
|
129662
|
+
if ("other" in read2) {
|
|
129663
|
+
this.unmapped.note(read2.other);
|
|
129362
129664
|
return;
|
|
129363
129665
|
}
|
|
129364
|
-
const u =
|
|
129666
|
+
const u = read2.update;
|
|
129365
129667
|
switch (u.sessionUpdate) {
|
|
129366
129668
|
case "usage_update":
|
|
129367
129669
|
if (u.used > 0 && u.size > 0 && u.used <= u.size) {
|
|
@@ -129956,8 +130258,8 @@ async function download(io2, url2, to, signal, onProgress) {
|
|
|
129956
130258
|
const body = await io2.download(url2, signal);
|
|
129957
130259
|
const hash2 = createHash12("sha256");
|
|
129958
130260
|
const out = createWriteStream(to, { mode: 384 });
|
|
129959
|
-
const
|
|
129960
|
-
|
|
130261
|
+
const failed4 = new Promise((_, reject) => out.once("error", reject));
|
|
130262
|
+
failed4.catch(() => {
|
|
129961
130263
|
});
|
|
129962
130264
|
let received = 0;
|
|
129963
130265
|
let said = 0;
|
|
@@ -129966,13 +130268,13 @@ async function download(io2, url2, to, signal, onProgress) {
|
|
|
129966
130268
|
cancelled(signal);
|
|
129967
130269
|
hash2.update(chunk);
|
|
129968
130270
|
received += chunk.byteLength;
|
|
129969
|
-
if (!out.write(chunk)) await Promise.race([new Promise((resolve21) => out.once("drain", () => resolve21())),
|
|
130271
|
+
if (!out.write(chunk)) await Promise.race([new Promise((resolve21) => out.once("drain", () => resolve21())), failed4]);
|
|
129970
130272
|
if (received - said >= PROGRESS_STEP_BYTES) {
|
|
129971
130273
|
said = received;
|
|
129972
130274
|
onProgress?.({ received, total: body.total });
|
|
129973
130275
|
}
|
|
129974
130276
|
}
|
|
129975
|
-
await Promise.race([new Promise((resolve21) => out.end(resolve21)),
|
|
130277
|
+
await Promise.race([new Promise((resolve21) => out.end(resolve21)), failed4]);
|
|
129976
130278
|
} finally {
|
|
129977
130279
|
out.destroy();
|
|
129978
130280
|
}
|
|
@@ -129986,13 +130288,13 @@ async function unpack(zip, archive, dir, signal, platform) {
|
|
|
129986
130288
|
let starts;
|
|
129987
130289
|
try {
|
|
129988
130290
|
const size2 = fstatSync4(fd).size;
|
|
129989
|
-
const
|
|
130291
|
+
const read2 = (pos, len) => {
|
|
129990
130292
|
const buf = Buffer.alloc(len);
|
|
129991
130293
|
const got = readSync4(fd, buf, 0, len, pos);
|
|
129992
130294
|
return buf.subarray(0, got);
|
|
129993
130295
|
};
|
|
129994
|
-
entries = readZipEntriesFrom(size2,
|
|
129995
|
-
starts = new Map(entries.map((e) => [e, zipEntryStart(size2,
|
|
130296
|
+
entries = readZipEntriesFrom(size2, read2, archive.files.length + 4).filter((e) => !(e.kind === "dir" && e.size === 0));
|
|
130297
|
+
starts = new Map(entries.map((e) => [e, zipEntryStart(size2, read2, e)]));
|
|
129996
130298
|
} finally {
|
|
129997
130299
|
closeSync5(fd);
|
|
129998
130300
|
}
|
|
@@ -130804,8 +131106,8 @@ async function installedCliVersion(name, packageName, deps = realDeps2()) {
|
|
|
130804
131106
|
real3 = deps.realpath(file2);
|
|
130805
131107
|
} catch {
|
|
130806
131108
|
}
|
|
130807
|
-
const
|
|
130808
|
-
if (
|
|
131109
|
+
const named3 = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.exec(path2.basename(real3).replace(/\.exe$/i, ""));
|
|
131110
|
+
if (named3) return named3[0];
|
|
130809
131111
|
if (traitsFor(deps.platform).locksRunningPrograms) return null;
|
|
130810
131112
|
try {
|
|
130811
131113
|
return parseCliVersion(await deps.run(launch2.command, [...launch2.args, "--version"]));
|
|
@@ -133021,9 +133323,9 @@ var ClaudeStreamNormalizer = class {
|
|
|
133021
133323
|
if (type === "result" && this.held !== null) {
|
|
133022
133324
|
const { text: text3, label } = this.held;
|
|
133023
133325
|
this.held = null;
|
|
133024
|
-
const
|
|
133025
|
-
if (
|
|
133026
|
-
else if (!
|
|
133326
|
+
const failed4 = events2.some((e) => e.type === "error");
|
|
133327
|
+
if (failed4 && label === "refusal") events2 = events2.map((e) => e.type === "error" ? { ...e, error: { ...e.error, message: text3 } } : e);
|
|
133328
|
+
else if (!failed4) events2 = [{ type: "notice", sessionId: this.sessionId, level: "warning", text: text3, from: "Claude Code", label }, ...events2];
|
|
133027
133329
|
}
|
|
133028
133330
|
if (msg.type === "stream_event") {
|
|
133029
133331
|
const e = msg.event;
|
|
@@ -133968,8 +134270,8 @@ var ClaudeRaceRetry = class {
|
|
|
133968
134270
|
const sent = this.inTurn.splice(0);
|
|
133969
134271
|
const seen = this.raceSeen;
|
|
133970
134272
|
this.raceSeen = null;
|
|
133971
|
-
const
|
|
133972
|
-
const race =
|
|
134273
|
+
const failed4 = result.is_error === true || result.subtype !== "success";
|
|
134274
|
+
const race = failed4 ? refreshRaceText(result) ?? seen : null;
|
|
133973
134275
|
if (!race) {
|
|
133974
134276
|
this.raceRetried = false;
|
|
133975
134277
|
return false;
|
|
@@ -134823,8 +135125,8 @@ var ClaudeSession = class {
|
|
|
134823
135125
|
if (m.type === "assistant") this.raceRetry.seen(msg);
|
|
134824
135126
|
let events2 = this.stream.push(msg);
|
|
134825
135127
|
if (m.type === "result") {
|
|
134826
|
-
const
|
|
134827
|
-
const ids =
|
|
135128
|
+
const named3 = Array.isArray(m.user_message_uuids) ? m.user_message_uuids.filter((x) => typeof x === "string") : [];
|
|
135129
|
+
const ids = named3.length > 0 ? named3 : m.user_message_uuid ? [m.user_message_uuid] : [];
|
|
134828
135130
|
const quietOnly = ids.length > 0 && ids.every((id3) => this.quietInputs.has(id3)) && !this.cliTurnRan;
|
|
134829
135131
|
this.cliTurnRan = false;
|
|
134830
135132
|
this.turnNamed = false;
|
|
@@ -134835,10 +135137,10 @@ var ClaudeSession = class {
|
|
|
134835
135137
|
const took = !retrying && this.sendTracked ? Array.isArray(m.user_message_uuids) ? m.user_message_uuids.filter((id3) => typeof id3 === "string") : [] : null;
|
|
134836
135138
|
if (m.type === "result" && !retrying) {
|
|
134837
135139
|
const result = msg;
|
|
134838
|
-
const
|
|
134839
|
-
const first = [...this.personInputs].findIndex((id3) =>
|
|
135140
|
+
const named3 = result.user_message_uuids ?? (result.user_message_uuid ? [result.user_message_uuid] : []);
|
|
135141
|
+
const first = [...this.personInputs].findIndex((id3) => named3.includes(id3));
|
|
134840
135142
|
if (first > 0) for (const id3 of [...this.personInputs].slice(0, first)) this.personInputs.delete(id3);
|
|
134841
|
-
for (const id3 of
|
|
135143
|
+
for (const id3 of named3) this.personInputs.delete(id3);
|
|
134842
135144
|
}
|
|
134843
135145
|
let completedInputs;
|
|
134844
135146
|
if (m.type === "result" && !retrying && this.ledger.tracking && events2.some((e) => e.type === "turn_complete" || e.type === "error")) {
|
|
@@ -138997,10 +139299,10 @@ function softRead(o) {
|
|
|
138997
139299
|
};
|
|
138998
139300
|
}
|
|
138999
139301
|
function localUsageReader(o) {
|
|
139000
|
-
const
|
|
139302
|
+
const read2 = softRead(o);
|
|
139001
139303
|
return async (ask) => {
|
|
139002
139304
|
const at2 = ask?.seed?.totals?.asOf;
|
|
139003
|
-
const { value, provisional } = await
|
|
139305
|
+
const { value, provisional } = await read2({ settle: ask?.settle, ...ask?.seed && at2 !== void 0 ? { seed: { value: ask.seed, at: at2 } } : {} });
|
|
139004
139306
|
return provisional ? { ...value, provisional: true } : value;
|
|
139005
139307
|
};
|
|
139006
139308
|
}
|
|
@@ -139083,10 +139385,10 @@ function cursorRefusalIn(answer) {
|
|
|
139083
139385
|
var STATUS_FOR_MS = 6e4;
|
|
139084
139386
|
function cursorProfile() {
|
|
139085
139387
|
let status = null;
|
|
139086
|
-
const localUsage = cursorUsageReader(async (
|
|
139388
|
+
const localUsage = cursorUsageReader(async (timeout2) => {
|
|
139087
139389
|
const install = findCursor();
|
|
139088
139390
|
if (!install) throw new Error("Cursor CLI not found");
|
|
139089
|
-
const r = await exec7(install.command, [...install.args, "about", "--format", "json"], { timeout, windowsHide: true, env: { ...process.env, ...install.env } });
|
|
139391
|
+
const r = await exec7(install.command, [...install.args, "about", "--format", "json"], { timeout: timeout2, windowsHide: true, env: { ...process.env, ...install.env } });
|
|
139090
139392
|
return r.stdout;
|
|
139091
139393
|
});
|
|
139092
139394
|
return {
|
|
@@ -139198,8 +139500,8 @@ function stringEnd(text3, start3) {
|
|
|
139198
139500
|
return text3.length;
|
|
139199
139501
|
}
|
|
139200
139502
|
function agentNames(folder) {
|
|
139201
|
-
const
|
|
139202
|
-
return [...
|
|
139503
|
+
const named3 = (sub, deep) => markdown(join51(folder, sub), deep).map((f) => relative6(join51(folder, sub), f).replaceAll("\\", "/").slice(0, -extname3(f).length));
|
|
139504
|
+
return [...named3("agent", true), ...named3("agents", true), ...named3("mode", false), ...named3("modes", false)];
|
|
139203
139505
|
}
|
|
139204
139506
|
function markdown(folder, deep) {
|
|
139205
139507
|
try {
|
|
@@ -139228,9 +139530,9 @@ var DEFAULT_ASKS = {
|
|
|
139228
139530
|
doom_loop: [["*", "ask"]]
|
|
139229
139531
|
};
|
|
139230
139532
|
function holdEnv(hold, theirs, all, agentFiles, permissionEnv, matches2) {
|
|
139231
|
-
const
|
|
139232
|
-
const modes = new Set(
|
|
139233
|
-
const configured = [.../* @__PURE__ */ new Set([...
|
|
139533
|
+
const named3 = (group) => all.flatMap((c) => Object.keys(asObj(c[group])));
|
|
139534
|
+
const modes = new Set(named3("mode"));
|
|
139535
|
+
const configured = [.../* @__PURE__ */ new Set([...named3("agent"), ...modes])];
|
|
139234
139536
|
const held2 = [.../* @__PURE__ */ new Set([...NATIVE_AGENTS, ...configured, ...agentFiles])];
|
|
139235
139537
|
const primary = hold === "safe" ? "build" : [...all].reverse().map((c) => c.default_agent).find((a) => typeof a === "string") ?? "build";
|
|
139236
139538
|
const entered = hold === "safe" ? held2 : [.../* @__PURE__ */ new Set([primary, ...NATIVE_AGENTS, ...configured])];
|
|
@@ -139526,8 +139828,8 @@ function openCodeUsageReader(run4, now = Date.now) {
|
|
|
139526
139828
|
fallback: () => NOTHING2,
|
|
139527
139829
|
onFail: (e) => console.error(`[usage] opencode: could not read the totals: ${e.message}`),
|
|
139528
139830
|
read: async () => {
|
|
139529
|
-
const
|
|
139530
|
-
return
|
|
139831
|
+
const read2 = parseStats(await run4(STATS_RUN_MS));
|
|
139832
|
+
return read2.totals ? { ...read2, totals: { ...read2.totals, asOf: now() } } : read2;
|
|
139531
139833
|
}
|
|
139532
139834
|
});
|
|
139533
139835
|
}
|
|
@@ -139547,10 +139849,10 @@ var DESCRIPTOR3 = {
|
|
|
139547
139849
|
var VERSION_FOR_MS = 6e4;
|
|
139548
139850
|
function openCodeProfile() {
|
|
139549
139851
|
let known = null;
|
|
139550
|
-
const localUsage = openCodeUsageReader(async (
|
|
139852
|
+
const localUsage = openCodeUsageReader(async (timeout2) => {
|
|
139551
139853
|
const l = findOpenCode();
|
|
139552
139854
|
if (!l) throw new Error("OpenCode not found");
|
|
139553
|
-
const r = await exec9(l.command, [...l.args, "stats"], { timeout, windowsHide: true, maxBuffer: 1024 * 1024 });
|
|
139855
|
+
const r = await exec9(l.command, [...l.args, "stats"], { timeout: timeout2, windowsHide: true, maxBuffer: 1024 * 1024 });
|
|
139554
139856
|
return r.stdout;
|
|
139555
139857
|
});
|
|
139556
139858
|
const version2 = async () => {
|
|
@@ -140201,6 +140503,10 @@ var LinkedReports = class {
|
|
|
140201
140503
|
gate(sessionId) {
|
|
140202
140504
|
return this.host.reportGate?.(sessionId) ?? "deliver";
|
|
140203
140505
|
}
|
|
140506
|
+
/** Each linked session's background work as its machine last listed it (`tasks`), for `pausedOnBackground` */
|
|
140507
|
+
tasksOf(sessionId) {
|
|
140508
|
+
return this.tasks.get(sessionId) ?? [];
|
|
140509
|
+
}
|
|
140204
140510
|
/** The session's own background work its machine lists as running; a timer the tool holds is not work (#721) */
|
|
140205
140511
|
ownTasksRunning(sessionId) {
|
|
140206
140512
|
return liveBackgroundTasks(this.tasks.get(sessionId) ?? []).filter((t) => !t.timer);
|
|
@@ -140811,7 +141117,7 @@ var LinkedHost = class {
|
|
|
140811
141117
|
this.hubAskTurns.delete(sessionId);
|
|
140812
141118
|
this.host.store.settings.deleteAppSetting(key);
|
|
140813
141119
|
};
|
|
140814
|
-
const
|
|
141120
|
+
const failed4 = () => {
|
|
140815
141121
|
this.hubAskTurns.delete(sessionId);
|
|
140816
141122
|
queueMicrotask(() => {
|
|
140817
141123
|
if (!this.host.overloadRetry.stands(sessionId)) this.host.store.settings.deleteAppSetting(key);
|
|
@@ -140821,7 +141127,7 @@ var LinkedHost = class {
|
|
|
140821
141127
|
await this.host.deliver(sessionId, text3, void 0, { sessionId: HUB_SENDER, name }, false, void 0, "inline", (h, t, inputId) => {
|
|
140822
141128
|
if (!h.sendTracked) return h.send(t, inputId ? { id: inputId } : void 0);
|
|
140823
141129
|
this.hubAskTurns.add(sessionId);
|
|
140824
|
-
void h.sendTracked(t, { complete: done2, fail:
|
|
141130
|
+
void h.sendTracked(t, { complete: done2, fail: failed4 }, inputId ? { id: inputId } : void 0).catch(() => {
|
|
140825
141131
|
});
|
|
140826
141132
|
});
|
|
140827
141133
|
} catch (e) {
|
|
@@ -141014,10 +141320,10 @@ function cachePrices(billing, model) {
|
|
|
141014
141320
|
}
|
|
141015
141321
|
function cacheCost(billing, model, t, reportsWrites) {
|
|
141016
141322
|
const price = cachePrices(billing, model);
|
|
141017
|
-
const
|
|
141018
|
-
if (!reportsWrites) return { read, write: t.input * price.write5m };
|
|
141323
|
+
const read2 = t.read * price.read;
|
|
141324
|
+
if (!reportsWrites) return { read: read2, write: t.input * price.write5m };
|
|
141019
141325
|
const hour = Math.min(t.write, Math.max(0, t.write1h ?? 0));
|
|
141020
|
-
return { read, write: hour * price.write1h + (t.write - hour) * price.write5m };
|
|
141326
|
+
return { read: read2, write: hour * price.write1h + (t.write - hour) * price.write5m };
|
|
141021
141327
|
}
|
|
141022
141328
|
|
|
141023
141329
|
// packages/agent-host/src/sessions/cache-ledger.ts
|
|
@@ -141134,8 +141440,8 @@ ${r.agent ?? ""}`;
|
|
|
141134
141440
|
/** A stored bucket's cache cost: the ratios belong to its tool and model, so its sums are weighted at once (`cacheCost`) */
|
|
141135
141441
|
costOfBucket(b2) {
|
|
141136
141442
|
const billing = this.billingOf(b2.tool);
|
|
141137
|
-
const { read, write } = cacheCost(billing, b2.model, { input: b2.input, read: b2.cacheRead, write: b2.cacheWrite, write1h: b2.cacheWrite1h }, billing === "anthropic" || b2.cacheWrite > 0);
|
|
141138
|
-
return { readCost:
|
|
141443
|
+
const { read: read2, write } = cacheCost(billing, b2.model, { input: b2.input, read: b2.cacheRead, write: b2.cacheWrite, write1h: b2.cacheWrite1h }, billing === "anthropic" || b2.cacheWrite > 0);
|
|
141444
|
+
return { readCost: read2, writeCost: write };
|
|
141139
141445
|
}
|
|
141140
141446
|
/**
|
|
141141
141447
|
* The last five hours and today (the host's local midnight). `nameOf` names a session; undefined for one that is
|
|
@@ -141354,17 +141660,17 @@ var UsageRecorder = class {
|
|
|
141354
141660
|
* A turn ended: reads the tool's limits through `read`, unless that was done lately. A turn end is when a tool's
|
|
141355
141661
|
* window has just moved, and the only moment a quiet account would otherwise not be looked at.
|
|
141356
141662
|
*/
|
|
141357
|
-
turnEnded(tool,
|
|
141663
|
+
turnEnded(tool, read2) {
|
|
141358
141664
|
const now = this.now();
|
|
141359
141665
|
if (now - (this.lastRead.get(tool) ?? 0) < TURN_END_GAP_MS) return;
|
|
141360
141666
|
this.lastRead.set(tool, now);
|
|
141361
|
-
void
|
|
141667
|
+
void read2(tool).catch(() => void 0);
|
|
141362
141668
|
}
|
|
141363
141669
|
/**
|
|
141364
141670
|
* Starts the timers: a flush each minute, and each ten minutes a limit reading of every tool in `liveTools` (a tool
|
|
141365
141671
|
* with no live session is not started up just to be looked at; the gauge's own polls cover a person who is looking).
|
|
141366
141672
|
*/
|
|
141367
|
-
start(liveTools,
|
|
141673
|
+
start(liveTools, read2) {
|
|
141368
141674
|
this.prune();
|
|
141369
141675
|
const tick = (ms3, fn2) => {
|
|
141370
141676
|
const t = setInterval(fn2, ms3);
|
|
@@ -141378,7 +141684,7 @@ var UsageRecorder = class {
|
|
|
141378
141684
|
tick(SAMPLE_MS, () => {
|
|
141379
141685
|
for (const tool of liveTools()) {
|
|
141380
141686
|
this.lastRead.set(tool, this.now());
|
|
141381
|
-
void
|
|
141687
|
+
void read2(tool).catch(() => void 0);
|
|
141382
141688
|
}
|
|
141383
141689
|
});
|
|
141384
141690
|
}
|
|
@@ -143896,11 +144202,11 @@ var StepsV28ToV40 = class extends MigrationRange {
|
|
|
143896
144202
|
);
|
|
143897
144203
|
`);
|
|
143898
144204
|
const insert = this.db.prepare(`INSERT INTO messages_fts (rowid, body, session_id, seq) VALUES (?, ?, ?, ?)`);
|
|
143899
|
-
const
|
|
144205
|
+
const pick5 = this.db.prepare(
|
|
143900
144206
|
`SELECT rowid, session_id, seq, kind, payload FROM messages
|
|
143901
144207
|
WHERE kind IN ${kinds} AND session_id NOT IN (SELECT id FROM sessions WHERE deleted_at IS NOT NULL)`
|
|
143902
144208
|
);
|
|
143903
|
-
for (const r of
|
|
144209
|
+
for (const r of pick5.all()) {
|
|
143904
144210
|
const body = indexedText(r.kind, r.payload);
|
|
143905
144211
|
if (!body) continue;
|
|
143906
144212
|
insert.run(r.rowid, body, r.session_id, r.seq);
|
|
@@ -145614,7 +145920,7 @@ var TrashRecords = class {
|
|
|
145614
145920
|
*/
|
|
145615
145921
|
async purgeSession(sessionId, chunk = DELETE_CHUNK) {
|
|
145616
145922
|
if (!this.isTrashed(sessionId)) return false;
|
|
145617
|
-
const
|
|
145923
|
+
const pick5 = this.db.prepare(`SELECT rowid FROM messages WHERE session_id = ? LIMIT ?`);
|
|
145618
145924
|
const dropFts = this.db.prepare(`DELETE FROM messages_fts WHERE rowid = ?`);
|
|
145619
145925
|
const dropMsg = this.db.prepare(`DELETE FROM messages WHERE rowid = ?`);
|
|
145620
145926
|
const pickSub = this.db.prepare(`SELECT rowid FROM subagent_messages WHERE session_id = ? LIMIT ?`);
|
|
@@ -145623,7 +145929,7 @@ var TrashRecords = class {
|
|
|
145623
145929
|
const subs = pickSub.all(sessionId, chunk);
|
|
145624
145930
|
for (const { rowid } of subs) dropSub.run(rowid);
|
|
145625
145931
|
if (subs.length === chunk) return false;
|
|
145626
|
-
const rows3 =
|
|
145932
|
+
const rows3 = pick5.all(sessionId, chunk);
|
|
145627
145933
|
for (const { rowid } of rows3) {
|
|
145628
145934
|
dropFts.run(rowid);
|
|
145629
145935
|
dropMsg.run(rowid);
|
|
@@ -145655,12 +145961,12 @@ var TrashRecords = class {
|
|
|
145655
145961
|
}
|
|
145656
145962
|
/** One session's messages in seq order, one transaction per chunk, letting the event loop go between chunks (#179) */
|
|
145657
145963
|
async walkMessages(sessionId, chunk, withPayload, each2) {
|
|
145658
|
-
const
|
|
145964
|
+
const pick5 = this.db.prepare(
|
|
145659
145965
|
`SELECT rowid, seq${withPayload ? ", kind, payload" : ""} FROM messages WHERE session_id = ? AND seq > ? ORDER BY seq LIMIT ?`
|
|
145660
145966
|
);
|
|
145661
145967
|
let after = Number.MIN_SAFE_INTEGER;
|
|
145662
145968
|
const step = this.db.transaction(() => {
|
|
145663
|
-
const rows3 =
|
|
145969
|
+
const rows3 = pick5.all(sessionId, after, chunk);
|
|
145664
145970
|
each2(rows3);
|
|
145665
145971
|
const last = rows3.at(-1);
|
|
145666
145972
|
if (last) after = last.seq;
|
|
@@ -145841,14 +146147,14 @@ var SubagentStepRecords = class {
|
|
|
145841
146147
|
);
|
|
145842
146148
|
const at2 = Math.max(stampAfter(this.lastMovedAt, now), (prev ?? 0) + 1);
|
|
145843
146149
|
this.lastMovedAt = at2;
|
|
145844
|
-
const
|
|
146150
|
+
const pick5 = this.db.prepare(
|
|
145845
146151
|
`SELECT rowid, LENGTH(CAST(payload AS BLOB)) as bytes FROM subagent_messages
|
|
145846
146152
|
WHERE session_id = ? AND trashed_at IS NULL AND rowid <= ? LIMIT ?`
|
|
145847
146153
|
);
|
|
145848
146154
|
const mark = this.db.prepare(`UPDATE subagent_messages SET trashed_at = ? WHERE rowid = ?`);
|
|
145849
146155
|
const moved = { steps: 0, bytes: 0 };
|
|
145850
146156
|
await this.inChunks(() => {
|
|
145851
|
-
const rows3 =
|
|
146157
|
+
const rows3 = pick5.all(sessionId, last, chunk);
|
|
145852
146158
|
for (const r of rows3) {
|
|
145853
146159
|
mark.run(at2, r.rowid);
|
|
145854
146160
|
moved.steps++;
|
|
@@ -145861,10 +146167,10 @@ var SubagentStepRecords = class {
|
|
|
145861
146167
|
/** Puts a live session's trashed steps back under their cards. False when it had none in the trash */
|
|
145862
146168
|
async restore(sessionId, chunk = CHUNK) {
|
|
145863
146169
|
if (!this.hasTrashed(sessionId)) return false;
|
|
145864
|
-
const
|
|
146170
|
+
const pick5 = this.db.prepare(`SELECT rowid FROM subagent_messages WHERE session_id = ? AND trashed_at IS NOT NULL LIMIT ?`);
|
|
145865
146171
|
const unmark = this.db.prepare(`UPDATE subagent_messages SET trashed_at = NULL WHERE rowid = ?`);
|
|
145866
146172
|
await this.inChunks(() => {
|
|
145867
|
-
const rows3 =
|
|
146173
|
+
const rows3 = pick5.all(sessionId, chunk);
|
|
145868
146174
|
for (const r of rows3) unmark.run(r.rowid);
|
|
145869
146175
|
return rows3.length < chunk;
|
|
145870
146176
|
});
|
|
@@ -145878,12 +146184,12 @@ var SubagentStepRecords = class {
|
|
|
145878
146184
|
*/
|
|
145879
146185
|
async purge(sessionId, upTo, chunk = CHUNK) {
|
|
145880
146186
|
if (!this.hasTrashed(sessionId, upTo)) return false;
|
|
145881
|
-
const
|
|
146187
|
+
const pick5 = this.db.prepare(
|
|
145882
146188
|
`SELECT rowid FROM subagent_messages WHERE session_id = ? AND trashed_at IS NOT NULL AND trashed_at <= ? LIMIT ?`
|
|
145883
146189
|
);
|
|
145884
146190
|
const drop = this.db.prepare(`DELETE FROM subagent_messages WHERE rowid = ?`);
|
|
145885
146191
|
await this.inChunks(() => {
|
|
145886
|
-
const rows3 =
|
|
146192
|
+
const rows3 = pick5.all(sessionId, upTo, chunk);
|
|
145887
146193
|
for (const r of rows3) drop.run(r.rowid);
|
|
145888
146194
|
return rows3.length < chunk;
|
|
145889
146195
|
});
|
|
@@ -146566,8 +146872,8 @@ var AskProjectFlow = class {
|
|
|
146566
146872
|
([, d8]) => d8.callerId === callerId && d8.target.id === target.id && !d8.agent
|
|
146567
146873
|
);
|
|
146568
146874
|
if (!opts.task && !outstanding.length) {
|
|
146569
|
-
const
|
|
146570
|
-
const gone2 = [...this.host.children.handedOver].find(([id3, h]) => h.from === callerId && this.host.meta.get(id3)?.projectId === target.id &&
|
|
146875
|
+
const named3 = (id3) => !wantedSession || id3 === wantedSession || this.host.meta.get(id3)?.name.toLowerCase() === wantedSession.toLowerCase();
|
|
146876
|
+
const gone2 = [...this.host.children.handedOver].find(([id3, h]) => h.from === callerId && this.host.meta.get(id3)?.projectId === target.id && named3(id3));
|
|
146571
146877
|
if (gone2) return this.host.delegationFlow.handedOverReply(callerId, gone2[0]);
|
|
146572
146878
|
}
|
|
146573
146879
|
if (!opts.task && !wantedSession && outstanding.length === 1) {
|
|
@@ -147926,12 +148232,12 @@ var ToolQueries = class {
|
|
|
147926
148232
|
const failedAt = this.modelFailures.get(tool);
|
|
147927
148233
|
const failedRecently = failedAt !== void 0 && !isFromTheFuture(failedAt, Date.now()) && Date.now() - failedAt < MODEL_LIST_RETRY_MS && !this.modelFetches.has(tool);
|
|
147928
148234
|
if (failedRecently) return hit && !fresh ? { models: hit.models, cached: true } : null;
|
|
147929
|
-
const
|
|
147930
|
-
|
|
148235
|
+
const read2 = this.fetchModels(tool, adapter);
|
|
148236
|
+
read2.catch(() => {
|
|
147931
148237
|
});
|
|
147932
148238
|
if (hit && !fresh) return { models: hit.models, cached: true };
|
|
147933
148239
|
try {
|
|
147934
|
-
return { models: await withTimeout(
|
|
148240
|
+
return { models: await withTimeout(read2, ms3), cached: false };
|
|
147935
148241
|
} catch {
|
|
147936
148242
|
return null;
|
|
147937
148243
|
}
|
|
@@ -148879,16 +149185,16 @@ var SessionTrash = class {
|
|
|
148879
149185
|
*/
|
|
148880
149186
|
async emptyTrash() {
|
|
148881
149187
|
let purged = 0;
|
|
148882
|
-
const
|
|
149188
|
+
const failed4 = [];
|
|
148883
149189
|
for (const r of this.host.store.trash.listTrash()) {
|
|
148884
149190
|
try {
|
|
148885
149191
|
await this.purgeSession(r.id);
|
|
148886
149192
|
purged++;
|
|
148887
149193
|
} catch (e) {
|
|
148888
|
-
|
|
149194
|
+
failed4.push({ sessionId: r.id, name: r.name, error: e.message });
|
|
148889
149195
|
}
|
|
148890
149196
|
}
|
|
148891
|
-
return { purged, failed:
|
|
149197
|
+
return { purged, failed: failed4 };
|
|
148892
149198
|
}
|
|
148893
149199
|
// ── A session's subagent steps, in the session archive without it (#418) ──
|
|
148894
149200
|
//
|
|
@@ -149587,6 +149893,10 @@ var SessionManager = class {
|
|
|
149587
149893
|
useLinkedReader(reader) {
|
|
149588
149894
|
this.linkedReader = reader;
|
|
149589
149895
|
}
|
|
149896
|
+
/** Whether a linked machine takes mail from this hub (#2067 item 2): the task of a child started there then says to mail its parent */
|
|
149897
|
+
useMachineMail(takesMail) {
|
|
149898
|
+
this.delegationFlow.remote.machineMail = takesMail;
|
|
149899
|
+
}
|
|
149590
149900
|
/** The hubs linked to this host that let its sessions ask their projects (#550, links/linked-hubs.ts) */
|
|
149591
149901
|
useLinkedHubs(hubs2) {
|
|
149592
149902
|
this.askProjectFlow.hubs = hubs2;
|
|
@@ -149771,7 +150081,7 @@ var SessionManager = class {
|
|
|
149771
150081
|
return self2.adapters;
|
|
149772
150082
|
},
|
|
149773
150083
|
agentSession: (...a) => self2.agentSession(...a),
|
|
149774
|
-
mailTool: (id3, args) => self2.mail.hooks?.tool?.(id3, args) ?? { text: "The mailbox is not available.", isError: true },
|
|
150084
|
+
mailTool: async (id3, args) => await self2.mail.hooks?.tool?.(id3, args) ?? { text: "The mailbox is not available.", isError: true },
|
|
149775
150085
|
refusesDelegation: (callerId, target, call2) => self2.mail.hooks?.refusesDelegation?.(callerId, target, call2) ?? null,
|
|
149776
150086
|
roleMoved: (toId) => self2.mail.hooks?.roleMoved?.(toId),
|
|
149777
150087
|
whenAsked: (id3, call2, signal, run4, refused2) => self2.askedGate.when(id3, call2, signal, run4, refused2),
|
|
@@ -150085,7 +150395,10 @@ var SessionManager = class {
|
|
|
150085
150395
|
// Whose a linked child's turn is decides whether its report goes (#1038 review)
|
|
150086
150396
|
reportGate: (sessionId) => self2.delegationFlow.remote.reportGate(sessionId),
|
|
150087
150397
|
keepsOverLoss: (sessionId) => self2.delegationFlow.remote.keepsOverLoss(sessionId),
|
|
150088
|
-
linkedChild: (sessionId) =>
|
|
150398
|
+
linkedChild: (sessionId) => {
|
|
150399
|
+
const r = self2.delegationFlow.remote.of(sessionId);
|
|
150400
|
+
return r && { name: oneLineText(`${r.name} on ${r.machine}`, 120) };
|
|
150401
|
+
},
|
|
150089
150402
|
skillsPrompt: () => self2.launchInputs.skillsPrompt(),
|
|
150090
150403
|
sleepSession: (...a) => self2.processes.sleepSession(...a),
|
|
150091
150404
|
startAgent: (...a) => self2.startAgent(...a),
|
|
@@ -150745,7 +151058,10 @@ function askedBy(host, assistantId) {
|
|
|
150745
151058
|
function mailReach(host) {
|
|
150746
151059
|
const sessionOf = (address) => {
|
|
150747
151060
|
const party = parseAddress(address);
|
|
150748
|
-
|
|
151061
|
+
if (party?.kind !== "session") return void 0;
|
|
151062
|
+
if (party.host === host.hostId) return { id: party.sessionId, info: host.session(party.sessionId) };
|
|
151063
|
+
const far = host.foreign?.(address);
|
|
151064
|
+
return far ? { id: party.sessionId, info: { projectId: null, askedBy: null, here: true, canReadMail: false, host: "elsewhere", name: far.name } } : void 0;
|
|
150749
151065
|
};
|
|
150750
151066
|
const untrusted = (projectId) => projectId === null ? false : !(host.project(projectId)?.trusted ?? false);
|
|
150751
151067
|
const leaves = (senderProject, recipientProject) => HOLD_UNTRUSTED_OUT && untrusted(senderProject) && recipientProject !== senderProject;
|
|
@@ -150820,9 +151136,79 @@ var MailTool = class {
|
|
|
150820
151136
|
if (!me2) throw refuse4("gone", "this session is not here");
|
|
150821
151137
|
return { text: this.dispatch(sessionId, me2, args, mailCalls(1, this.host.form(sessionId))) };
|
|
150822
151138
|
} catch (e) {
|
|
150823
|
-
|
|
150824
|
-
|
|
151139
|
+
return failed3(e);
|
|
151140
|
+
}
|
|
151141
|
+
}
|
|
151142
|
+
/**
|
|
151143
|
+
* The tool as a session calls it: `run`, but `find` searches every computer this one reaches, and a send or reply to a
|
|
151144
|
+
* session on another computer goes to that computer, which writes it or refuses it (#2067 items 2 and 3,
|
|
151145
|
+
* docs/plans/linked-mail.md §6 to §8). Nothing is written here unless it took the message
|
|
151146
|
+
*/
|
|
151147
|
+
async call(sessionId, args) {
|
|
151148
|
+
const me2 = this.host.caller(sessionId);
|
|
151149
|
+
const across = this.host.across;
|
|
151150
|
+
if (!me2) return this.run(sessionId, args);
|
|
151151
|
+
try {
|
|
151152
|
+
if (args.action === "find") {
|
|
151153
|
+
if (!across) return { text: "Finding sessions is not available here.", isError: true };
|
|
151154
|
+
return { text: await across.find((args.to ?? args.text ?? "").trim(), me2.address) };
|
|
151155
|
+
}
|
|
151156
|
+
const far = across ? await this.acrossTarget(sessionId, me2, args, across) : null;
|
|
151157
|
+
if (!far || !across) return this.run(sessionId, args);
|
|
151158
|
+
if (args.cite) {
|
|
151159
|
+
return {
|
|
151160
|
+
text: `Refused (field_not_allowed): cite is checked against this computer's record of the person's messages, which ${far.address === "parent" ? "your parent" : "a session"} on another computer cannot read, so nothing was sent. Send it again without cite, quoting what the person said if it matters.`,
|
|
151161
|
+
isError: true
|
|
151162
|
+
};
|
|
151163
|
+
}
|
|
151164
|
+
const needsReply = far.replyTo ? args.kind === "question" : args.kind !== "note";
|
|
151165
|
+
const r = await across.send(sessionId, { to: far.address, text: this.need(args.text, "text"), needsReply, ...args.urgent ? { urgent: true } : {}, ...far.replyTo ? { replyTo: far.replyTo } : {} });
|
|
151166
|
+
if (!r.ok) return { text: `Refused (${r.why}): ${r.text}`, isError: true };
|
|
151167
|
+
const who = far.address === "parent" ? `your parent ${JSON.stringify(r.to)}` : `${JSON.stringify(r.to)}${r.address ? ` (${r.address})` : ""}`;
|
|
151168
|
+
const after = needsReply ? "It waits for a reply; the reply will reach you as mail." : far.replyTo ? "It answers that message." : "It needs no reply.";
|
|
151169
|
+
return { text: `Sent ${r.messageId} to ${who} on ${r.computer}. ${after} What comes back arrives in your mailbox, and wakes you if you are at rest.` };
|
|
151170
|
+
} catch (e) {
|
|
151171
|
+
return failed3(e);
|
|
151172
|
+
}
|
|
151173
|
+
}
|
|
151174
|
+
/**
|
|
151175
|
+
* Where a send or reply goes when it is to another computer, or null for this one: `parent` of a session a hub started;
|
|
151176
|
+
* an address of a session there; a name found there, refused as ambiguous with the candidates when more than one
|
|
151177
|
+
* session on any computer has it (#2066's rule, across machines); or the sender of the message a reply answers
|
|
151178
|
+
*/
|
|
151179
|
+
async acrossTarget(sessionId, me2, a, across) {
|
|
151180
|
+
if (a.action === "reply") {
|
|
151181
|
+
const id3 = this.target(me2.address, this.need(a.thread, "thread"));
|
|
151182
|
+
const m = this.records.message(id3);
|
|
151183
|
+
return m && across.foreign(m.sender) && this.records.recipient(id3, me2.address) ? { address: m.sender, replyTo: id3 } : null;
|
|
151184
|
+
}
|
|
151185
|
+
if (a.action !== "send") return null;
|
|
151186
|
+
const t = this.need(a.to, "to");
|
|
151187
|
+
const lower = t.toLowerCase();
|
|
151188
|
+
if (lower === "parent") return !me2.askedBy && me2.fromHub ? { address: "parent" } : null;
|
|
151189
|
+
if (lower === PERSON || lower === "assistant") return null;
|
|
151190
|
+
const own = me2.address.slice(0, me2.address.lastIndexOf("/") + 1);
|
|
151191
|
+
if (parseAddress(t)) return across.foreign(t) ? { address: t } : null;
|
|
151192
|
+
if (parseAddress(own + t) && across.foreign(own + t)) return { address: own + t };
|
|
151193
|
+
const here = this.host.sessions();
|
|
151194
|
+
if (here.some((s) => s.id === t)) return null;
|
|
151195
|
+
const local = here.filter((s) => s.id !== sessionId && s.name.trim().toLowerCase() === lower);
|
|
151196
|
+
const far = await across.named(t, { here: local.length > 0 });
|
|
151197
|
+
if (far.found.length === 0 && local.length === 0 && far.away.length > 0) {
|
|
151198
|
+
throw refuse4(
|
|
151199
|
+
"unknown",
|
|
151200
|
+
`no session on this computer or on the computers asked has the id or name ${JSON.stringify(oneLineText(t, 80))}. Not asked: ${far.away.slice(0, 3).map((a5) => `${oneLineText(a5.name, 40)} (${oneLineText(a5.why, 60)})`).join(", ")}${far.away.length > 3 ? `, and ${far.away.length - 3} more` : ""}. A session there cannot be found by name until it answers: try again later.`
|
|
151201
|
+
);
|
|
150825
151202
|
}
|
|
151203
|
+
if (far.found.length === 0) return null;
|
|
151204
|
+
const [only] = far.found;
|
|
151205
|
+
if (only && local.length + far.found.length === 1) return { address: only.address };
|
|
151206
|
+
const shown3 = [
|
|
151207
|
+
...local.map((s) => `${this.service.sessionAddress(s.id)} (${s.project === null ? "no project" : `project ${oneLineText(this.reach.projectLabel(s.project), 40)}`}, ${s.state})`),
|
|
151208
|
+
...far.found.map((e) => `${e.address} (${e.project === null ? "no project" : `project ${oneLineText(e.project, 40)}`}, on ${e.machine ?? "another computer"}, ${e.state})`)
|
|
151209
|
+
];
|
|
151210
|
+
const n = shown3.length;
|
|
151211
|
+
throw refuse4("ambiguous", `${n} sessions are named ${JSON.stringify(t)}: ${shown3.slice(0, 8).join(", ")}${n > 8 ? ", and more" : ""}. Send to one of them by its address.`);
|
|
150826
151212
|
}
|
|
150827
151213
|
dispatch(sessionId, me2, a, calls) {
|
|
150828
151214
|
switch (a.action) {
|
|
@@ -150842,6 +151228,8 @@ var MailTool = class {
|
|
|
150842
151228
|
const sent = this.service.send(me2.address, { to: [], replyTo: id3, text: this.need(a.text, "text"), needsReply: a.kind === "question", ...a.urgent ? { urgent: true } : {}, ...a.cite ? { cite: true } : {} });
|
|
150843
151229
|
return this.sent(sent);
|
|
150844
151230
|
}
|
|
151231
|
+
case "find":
|
|
151232
|
+
throw refuse4("bad_value", "find searches other computers too, which this call does not reach");
|
|
150845
151233
|
case "update":
|
|
150846
151234
|
case "close":
|
|
150847
151235
|
throw refuse4(
|
|
@@ -150888,17 +151276,17 @@ var MailTool = class {
|
|
|
150888
151276
|
const here = this.host.sessions();
|
|
150889
151277
|
const exact = here.find((s) => s.id === word);
|
|
150890
151278
|
if (exact) return { address: this.service.sessionAddress(exact.id) };
|
|
150891
|
-
const
|
|
150892
|
-
const [only] =
|
|
150893
|
-
if (only &&
|
|
151279
|
+
const named3 = here.filter((s) => s.id !== sessionId && s.name.trim().toLowerCase() === word.toLowerCase());
|
|
151280
|
+
const [only] = named3;
|
|
151281
|
+
if (only && named3.length === 1) return { address: this.service.sessionAddress(only.id) };
|
|
150894
151282
|
if (!only && parseAddress(own + word) && this.reach.elsewhere(own + word)) return { address: own + word };
|
|
150895
151283
|
if (only) {
|
|
150896
|
-
const shown3 =
|
|
150897
|
-
throw refuse4("ambiguous", `${
|
|
151284
|
+
const shown3 = named3.slice(0, 8).map((s) => `${this.service.sessionAddress(s.id)} (${s.project === null ? "no project" : `project ${oneLineText(this.reach.projectLabel(s.project), 40)}`}, ${s.state})`);
|
|
151285
|
+
throw refuse4("ambiguous", `${named3.length} sessions are named ${JSON.stringify(word)}: ${shown3.join(", ")}${named3.length > shown3.length ? ", and more" : ""}. Send to one of them by its address.`);
|
|
150898
151286
|
}
|
|
150899
151287
|
throw refuse4(
|
|
150900
151288
|
"unknown",
|
|
150901
|
-
`no session on this computer has the id or name ${JSON.stringify(oneLineText(word, 80))} (a session in the archive or deleted cannot be written to). Write to a session by its exact name, its id or session:<host>/<id>, or to "assistant", "parent" or "person".
|
|
151289
|
+
`no session on this computer has the id or name ${JSON.stringify(oneLineText(word, 80))} (a session in the archive or deleted cannot be written to). Write to a session by its exact name, its id or session:<host>/<id>, or to "assistant", "parent" or "person". Find one on any computer with mail(action="find", to="<words>").`
|
|
150902
151290
|
);
|
|
150903
151291
|
}
|
|
150904
151292
|
/**
|
|
@@ -151037,6 +151425,597 @@ The request:`}`;
|
|
|
151037
151425
|
return `${Math.round(s / 86400)}d`;
|
|
151038
151426
|
}
|
|
151039
151427
|
};
|
|
151428
|
+
function failed3(e) {
|
|
151429
|
+
const reason = refusalReason(e);
|
|
151430
|
+
return { text: reason ? `Refused (${reason}): ${errorMessage(e)}` : `The mailbox could not do that: ${errorMessage(e)}`, isError: true };
|
|
151431
|
+
}
|
|
151432
|
+
|
|
151433
|
+
// packages/agent-host/src/mail/find.ts
|
|
151434
|
+
var FIND_LIMIT = 8;
|
|
151435
|
+
var AWAY_LIMIT = 3;
|
|
151436
|
+
function roleOf(s) {
|
|
151437
|
+
if (isAssistantKind(s.kind)) return "assistant";
|
|
151438
|
+
if (s.kind === "coordinator") return "coordinator";
|
|
151439
|
+
return s.askedBy || s.startedFromHub ? "child" : "session";
|
|
151440
|
+
}
|
|
151441
|
+
function entryOf2(s, o) {
|
|
151442
|
+
return {
|
|
151443
|
+
address: o.address,
|
|
151444
|
+
name: oneLineText(s.name, 120),
|
|
151445
|
+
project: o.project === null ? null : oneLineText(o.project, 80),
|
|
151446
|
+
machine: o.machine === null ? null : oneLineText(o.machine, 80),
|
|
151447
|
+
role: roleOf(s),
|
|
151448
|
+
state: pausedOnBackground(s) ? "paused" : oneLineText(s.state, 30),
|
|
151449
|
+
busy: isInTurn(s.state) || pausedOnBackground(s),
|
|
151450
|
+
at: Math.max(s.waitingSince ?? 0, s.createdAt),
|
|
151451
|
+
...o.machineId ? { machineId: o.machineId } : {}
|
|
151452
|
+
};
|
|
151453
|
+
}
|
|
151454
|
+
var wordsOf = (query) => query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
151455
|
+
function scoreOf(e, query) {
|
|
151456
|
+
const words = wordsOf(query);
|
|
151457
|
+
const name = e.name.toLowerCase();
|
|
151458
|
+
let score2 = name === query.trim().toLowerCase() && words.length > 0 ? 100 : 0;
|
|
151459
|
+
for (const w of words) {
|
|
151460
|
+
const s = name.includes(w) ? 8 : (e.project ?? "").toLowerCase().includes(w) ? 4 : (e.machine ?? "").toLowerCase().includes(w) ? 3 : e.role === w || e.state.toLowerCase().includes(w) ? 2 : 0;
|
|
151461
|
+
if (s === 0) return null;
|
|
151462
|
+
score2 += s;
|
|
151463
|
+
}
|
|
151464
|
+
return score2;
|
|
151465
|
+
}
|
|
151466
|
+
function ranked(entries, query) {
|
|
151467
|
+
return entries.flatMap((e) => {
|
|
151468
|
+
const score2 = scoreOf(e, query);
|
|
151469
|
+
return score2 === null ? [] : [{ e, score: score2 }];
|
|
151470
|
+
}).sort((a, b2) => b2.score - a.score || Number(b2.e.busy) - Number(a.e.busy) || b2.e.at - a.e.at || a.e.address.localeCompare(b2.e.address)).map((x) => x.e);
|
|
151471
|
+
}
|
|
151472
|
+
function named(entries, name) {
|
|
151473
|
+
const n = name.trim().toLowerCase();
|
|
151474
|
+
return entries.filter((e) => e.name.trim().toLowerCase() === n);
|
|
151475
|
+
}
|
|
151476
|
+
function entryLine(e) {
|
|
151477
|
+
return [`${oneLineText(e.address, 120)} ${JSON.stringify(oneLineText(e.name, 40))}`, e.project === null ? "no project" : oneLineText(e.project, 30), ...e.machine ? [`on ${oneLineText(e.machine, 30)}`] : [], oneLineText(e.role, 12), oneLineText(e.state, 20)].join(" \xB7 ");
|
|
151478
|
+
}
|
|
151479
|
+
function findAnswer(o) {
|
|
151480
|
+
const q2 = oneLineText(o.query, 80);
|
|
151481
|
+
const shown3 = o.found.slice(0, FIND_LIMIT);
|
|
151482
|
+
const head = o.matched === 0 ? `No session matches ${JSON.stringify(q2)} among ${o.total}.${o.total > 0 ? " Try fewer words, or a project, a machine or a role." : ""}` : q2 === "" ? `The ${shown3.length} most recently active of ${o.total} sessions. Mail one by its address.` : `${o.matched} of ${o.total} sessions match ${JSON.stringify(q2)}. Mail one by its address.`;
|
|
151483
|
+
const more = o.matched - shown3.length;
|
|
151484
|
+
return [
|
|
151485
|
+
head,
|
|
151486
|
+
...shown3.map(entryLine),
|
|
151487
|
+
...more > 0 ? [`${more} more: add a word (a project, a machine or a role) to narrow it.`] : [],
|
|
151488
|
+
...o.away.slice(0, AWAY_LIMIT).map((a) => `Not searched: ${oneLineText(a.name, 30)} (${oneLineText(a.why, 60)}).`),
|
|
151489
|
+
...o.away.length > AWAY_LIMIT ? [`Not searched either: ${o.away.length - AWAY_LIMIT} more computers.`] : []
|
|
151490
|
+
].join("\n");
|
|
151491
|
+
}
|
|
151492
|
+
|
|
151493
|
+
// packages/agent-host/src/mail/across.ts
|
|
151494
|
+
function mayReachAcross(_from, _to) {
|
|
151495
|
+
return true;
|
|
151496
|
+
}
|
|
151497
|
+
var TOLD_SLACK_MS = 10 * 6e4;
|
|
151498
|
+
var older = (err) => /Unknown method/i.test(errorMessage(err));
|
|
151499
|
+
var sameMessage = (a, b2) => a.text === b2.text && a.replyTo === b2.replyTo && a.needsReply === b2.needsReply && (a.urgent ?? false) === (b2.urgent ?? false);
|
|
151500
|
+
var UNSURE_MS = 24 * 60 * 6e4;
|
|
151501
|
+
var UNSURE_MAX = 500;
|
|
151502
|
+
var FOREIGN_ID = /^[^\s/]{1,120}\.m_[0-9A-Za-z]{10,40}$/;
|
|
151503
|
+
var FIND_MS = 4e3;
|
|
151504
|
+
var NAMED_HERE_MS = 600;
|
|
151505
|
+
var MailAcross = class {
|
|
151506
|
+
constructor(d2) {
|
|
151507
|
+
this.d = d2;
|
|
151508
|
+
this.now = d2.now ?? Date.now;
|
|
151509
|
+
}
|
|
151510
|
+
d;
|
|
151511
|
+
peers = null;
|
|
151512
|
+
/** The names of sessions on the other side, as last heard (from a message or a search) */
|
|
151513
|
+
names = /* @__PURE__ */ new Map();
|
|
151514
|
+
/** The state of each crossing row the other side was told last, by `<message id>|<recipient>` */
|
|
151515
|
+
told = /* @__PURE__ */ new Map();
|
|
151516
|
+
/**
|
|
151517
|
+
* The sends from here not yet answered, or whose answer was lost (the link failed or the answer did not come in time),
|
|
151518
|
+
* by message id. The other side may have written one: a second send of the same words reuses its id, which the other
|
|
151519
|
+
* side takes as the one it has, and the copy is kept here once the other side's row or a reply to it arrives
|
|
151520
|
+
*/
|
|
151521
|
+
unsure = /* @__PURE__ */ new Map();
|
|
151522
|
+
syncing = false;
|
|
151523
|
+
again = false;
|
|
151524
|
+
now;
|
|
151525
|
+
/** The links, once they exist. Rows the other side may not have heard of yet are sent now and at each connect */
|
|
151526
|
+
usePeers(peers) {
|
|
151527
|
+
this.peers = peers;
|
|
151528
|
+
peers.onConnect?.(() => this.changed());
|
|
151529
|
+
this.changed();
|
|
151530
|
+
}
|
|
151531
|
+
// ── Addresses ──
|
|
151532
|
+
route(address) {
|
|
151533
|
+
const p = parseAddress(address);
|
|
151534
|
+
if (p?.kind !== "session") return null;
|
|
151535
|
+
if (p.host === this.d.hostId) {
|
|
151536
|
+
const dot = p.sessionId.indexOf(".");
|
|
151537
|
+
return dot < 0 ? { kind: "here" } : { kind: "machine", machineId: p.sessionId.slice(0, dot), sessionId: p.sessionId.slice(dot + 1) };
|
|
151538
|
+
}
|
|
151539
|
+
return { kind: "hub", hubId: p.host };
|
|
151540
|
+
}
|
|
151541
|
+
/** Whether an address is a session on another host: this host never delivers to it, and never writes to it but a copy */
|
|
151542
|
+
foreign(address) {
|
|
151543
|
+
const r = this.route(address);
|
|
151544
|
+
return r !== null && r.kind !== "here";
|
|
151545
|
+
}
|
|
151546
|
+
/** A foreign session's name as last heard, with its computer: what this host's mail shows for it */
|
|
151547
|
+
foreignName(address) {
|
|
151548
|
+
const r = this.route(address);
|
|
151549
|
+
if (!r || r.kind === "here") return void 0;
|
|
151550
|
+
const heard = this.names.get(address) ?? (r.kind === "machine" ? this.peers?.machineSession?.(r.machineId, r.sessionId) : void 0);
|
|
151551
|
+
if (heard) return { name: heard };
|
|
151552
|
+
const computer = this.computerOf(r);
|
|
151553
|
+
return { name: computer ? `a session on ${computer}` : address };
|
|
151554
|
+
}
|
|
151555
|
+
computerOf(r) {
|
|
151556
|
+
if (r.kind === "machine") return this.peers?.machine?.(r.machineId)?.name ?? null;
|
|
151557
|
+
if (r.kind === "hub") return this.peers?.hub?.(r.hubId)?.name ?? null;
|
|
151558
|
+
return null;
|
|
151559
|
+
}
|
|
151560
|
+
/** On a machine, its own session as the hub `hubId` names it */
|
|
151561
|
+
asHubNames(hubId, address) {
|
|
151562
|
+
const you = this.peers?.hub?.(hubId)?.you;
|
|
151563
|
+
const p = parseAddress(address);
|
|
151564
|
+
return you && p?.kind === "session" && p.host === this.d.hostId && !p.sessionId.includes(".") ? sessionAddress(hubId, `${you}.${p.sessionId}`) : address;
|
|
151565
|
+
}
|
|
151566
|
+
/** On a machine, an address as the hub `hubId` names it, as this host names it (its own sessions are its own again) */
|
|
151567
|
+
fromHubNames(hubId, address) {
|
|
151568
|
+
const you = this.peers?.hub?.(hubId)?.you;
|
|
151569
|
+
const p = parseAddress(address);
|
|
151570
|
+
if (!you || p?.kind !== "session" || p.host !== hubId || !p.sessionId.startsWith(`${you}.`)) return address;
|
|
151571
|
+
return this.d.service.sessionAddress(p.sessionId.slice(you.length + 1));
|
|
151572
|
+
}
|
|
151573
|
+
// ── Sending from here ──
|
|
151574
|
+
/**
|
|
151575
|
+
* A session's message to a session on another host (`to`: an address, or `parent` for a session a hub started here).
|
|
151576
|
+
* The other host writes it or refuses it; only then is the copy written here. Nothing is written when it is refused
|
|
151577
|
+
*/
|
|
151578
|
+
async send(sessionId, input) {
|
|
151579
|
+
const sender = this.d.service.sessionAddress(sessionId);
|
|
151580
|
+
if (input.text.length > bodyLimit("session")) return { ok: false, why: "too_long", text: tooLongText("session") };
|
|
151581
|
+
if (!input.text.trim()) return { ok: false, why: "empty", text: "a post says something" };
|
|
151582
|
+
if (input.to !== "parent" && !mayReachAcross(sender, input.to)) return { ok: false, why: "not_allowed", text: `this session may not mail ${input.to}.` };
|
|
151583
|
+
const project2 = this.d.reach.projectOf(sender);
|
|
151584
|
+
if (project2 !== null && this.d.reach.untrusted(project2)) {
|
|
151585
|
+
const p = this.d.reach.projectLabel(project2);
|
|
151586
|
+
return { ok: false, why: "untrusted_project", text: `your project ${p} is not trusted, and mail out of it to another computer cannot wait for the person as it does here, so nothing was sent. Ask the person to trust ${p}, then send it again.` };
|
|
151587
|
+
}
|
|
151588
|
+
const fields5 = { text: input.text, needsReply: input.needsReply, ...input.urgent ? { urgent: true } : {}, ...input.replyTo ? { replyTo: input.replyTo } : {} };
|
|
151589
|
+
if (input.to === "parent") return this.toParent(sessionId, sender, fields5);
|
|
151590
|
+
const route = this.route(input.to);
|
|
151591
|
+
if (!route || route.kind === "here") return { ok: false, why: "bad_address", text: `${input.to} is not a session on another computer.` };
|
|
151592
|
+
if (route.kind === "machine") {
|
|
151593
|
+
const m = this.peers?.machine?.(route.machineId);
|
|
151594
|
+
if (!m) return { ok: false, why: "link_down", text: `no machine ${route.machineId} is linked to this computer, so nothing was sent.` };
|
|
151595
|
+
const id4 = this.idFor(sender, input.to, fields5, m.name);
|
|
151596
|
+
const params2 = { from: sender, name: `${this.d.reach.labelOf(sender)} on ${this.selfName()}`, to: route.sessionId, ...fields5, id: id4 };
|
|
151597
|
+
return this.wrote(sender, input.to, fields5, m.name, this.settle(id4, await this.ask(m, "host.mail", params2)));
|
|
151598
|
+
}
|
|
151599
|
+
const h = this.peers?.hub?.(route.hubId);
|
|
151600
|
+
if (!h) return { ok: false, why: "link_down", text: `the computer ${route.hubId} is not linked to this one right now (or runs a Centralu from before mail crossed computers), so nothing was sent.` };
|
|
151601
|
+
if (!h.you) return { ok: false, why: "older", text: `${h.name} runs an older Centralu, which takes mail only for the session that started one of its children here. Update it there.` };
|
|
151602
|
+
const id3 = this.idFor(sender, input.to, fields5, h.name);
|
|
151603
|
+
const params = { sessionId, to: input.to, name: this.d.reach.labelOf(sender), ...fields5, id: id3 };
|
|
151604
|
+
return this.wrote(sender, input.to, fields5, h.name, this.settle(id3, await this.ask(h, "hub.mail", params)));
|
|
151605
|
+
}
|
|
151606
|
+
/**
|
|
151607
|
+
* The id a send to `to` goes under: the one of an unsure send of the same message by the same sender (its words, what it
|
|
151608
|
+
* answers, whether it is urgent and wants a reply), so the other side takes it as the message it may have, else a new
|
|
151609
|
+
* one, kept as unsure until the other side answers. A send again that changes any of them is another message: under the
|
|
151610
|
+
* same id the other side would keep the first, and its urgency or question would be lost (#2067 re-check)
|
|
151611
|
+
*/
|
|
151612
|
+
idFor(sender, to, fields5, computer) {
|
|
151613
|
+
const now = this.now();
|
|
151614
|
+
for (const [id4, u] of this.unsure) {
|
|
151615
|
+
if (now - u.at > UNSURE_MS) this.unsure.delete(id4);
|
|
151616
|
+
else if (u.sender === sender && u.to === to && sameMessage(u.fields, fields5)) return id4;
|
|
151617
|
+
}
|
|
151618
|
+
const id3 = this.d.service.mintId();
|
|
151619
|
+
this.unsure.set(id3, { sender, to, fields: fields5, computer, at: now });
|
|
151620
|
+
for (const old of this.unsure.keys()) {
|
|
151621
|
+
if (this.unsure.size <= UNSURE_MAX) break;
|
|
151622
|
+
this.unsure.delete(old);
|
|
151623
|
+
}
|
|
151624
|
+
return id3;
|
|
151625
|
+
}
|
|
151626
|
+
/** The other side's answer to the send of `id`: one it gave, written or refused, ends the doubt; a lost one keeps it */
|
|
151627
|
+
settle(id3, r) {
|
|
151628
|
+
if (r.ok || !r.maybe) this.unsure.delete(id3);
|
|
151629
|
+
return r;
|
|
151630
|
+
}
|
|
151631
|
+
/**
|
|
151632
|
+
* The copy of an unsure send, kept now that the other side showed it has the message (its row or a reply came). It stays
|
|
151633
|
+
* unsure: the sender, told the send failed, may send the same words again, which then go under this id and find it there
|
|
151634
|
+
*/
|
|
151635
|
+
adopt(messageId, recipient) {
|
|
151636
|
+
const u = this.unsure.get(messageId);
|
|
151637
|
+
if (!u || u.to !== recipient || this.d.records.message(messageId)) return;
|
|
151638
|
+
try {
|
|
151639
|
+
this.d.service.sentAcross(u.sender, { id: messageId, to: u.to, ...u.fields });
|
|
151640
|
+
} catch (e) {
|
|
151641
|
+
this.d.log?.(`[mail] the copy of ${messageId}, which ${u.computer} took, could not be kept here: ${errorMessage(e)}`);
|
|
151642
|
+
}
|
|
151643
|
+
}
|
|
151644
|
+
/** A session a hub started here, to the session there that started it: through that hub only, which knows who that is */
|
|
151645
|
+
async toParent(sessionId, sender, fields5) {
|
|
151646
|
+
const started = this.peers?.startingHub?.(sessionId) ?? null;
|
|
151647
|
+
if (!started) {
|
|
151648
|
+
return {
|
|
151649
|
+
ok: false,
|
|
151650
|
+
why: "elsewhere",
|
|
151651
|
+
text: "your parent is a session on another computer, and this session was started before this computer recorded which computer that was, so nothing was sent. End your turn with the answer: that is how your parent hears from you."
|
|
151652
|
+
};
|
|
151653
|
+
}
|
|
151654
|
+
const h = this.peers?.hub?.(started.id);
|
|
151655
|
+
const name = h?.name ?? (oneLineText(started.name, 120) || "the computer that started this session");
|
|
151656
|
+
if (!h) return { ok: false, why: "link_down", text: `${name}, which started this session, is not linked to this computer right now (or runs a Centralu from before mail crossed computers), so nothing was sent. Send it again once the link is back.` };
|
|
151657
|
+
const id3 = this.idFor(sender, "parent", fields5, name);
|
|
151658
|
+
const r = this.settle(id3, await this.ask(h, "hub.mail", { sessionId, name: this.d.reach.labelOf(sender), ...fields5, id: id3 }));
|
|
151659
|
+
if (!r.ok && r.why === "not_yours") return { ok: false, why: "gone", text: `${name} no longer has the session that started this one (it was archived or deleted there, or its record of this session is gone), so nothing was sent. No session there waits for this one's answer.` };
|
|
151660
|
+
if (!r.ok && r.why === "older") return { ok: false, why: "older", text: `${name} runs an older Centralu, which mail does not reach. Update it there; until then your parent hears from you at your turn's end.` };
|
|
151661
|
+
return this.wrote(sender, r.ok ? r.address ?? null : null, fields5, name, r);
|
|
151662
|
+
}
|
|
151663
|
+
/** One call to the other side, its failure in the words the sender reads; `maybe`: it may have been written there */
|
|
151664
|
+
async ask(peer, method, params) {
|
|
151665
|
+
if (!peer.reachable) return { ok: false, why: "link_down", text: `${peer.name} is not reachable right now, so nothing was sent. Send it again once the link is back.` };
|
|
151666
|
+
let raw;
|
|
151667
|
+
try {
|
|
151668
|
+
raw = await peer.call(method, params);
|
|
151669
|
+
} catch (err) {
|
|
151670
|
+
const said = oneLineText(errorMessage(err), 500).replace(/\.$/, "");
|
|
151671
|
+
if (older(err)) return { ok: false, why: "older", text: `${peer.name} runs an older Centralu, which this mail does not reach. Update it there.` };
|
|
151672
|
+
if (isPeerAnswer(err)) return { ok: false, why: "refused", maybe: true, text: `${peer.name} answered the send with an error: ${said}. It may not have taken the message. ${AGAIN}` };
|
|
151673
|
+
return { ok: false, why: "link_down", maybe: true, text: `the link to ${peer.name} failed during the send (${said}), so it is not known whether the message arrived. ${AGAIN}` };
|
|
151674
|
+
}
|
|
151675
|
+
const parsed = HubMailResult.safeParse(raw);
|
|
151676
|
+
if (!parsed.success) return { ok: false, why: "link_down", maybe: true, text: `${peer.name} answered in a form this computer does not read, so it is not known whether the message arrived. ${AGAIN}` };
|
|
151677
|
+
const r = parsed.data;
|
|
151678
|
+
if (!r.ok) return { ok: false, why: /^[a-z_]{1,40}$/.test(r.why) ? r.why : "refused", text: r.text.length > 4e3 ? `${r.text.slice(0, 4e3)}\u2026` : r.text };
|
|
151679
|
+
return { ok: true, messageId: oneLineText(r.messageId, 200), to: oneLineText(r.to, 120), ...r.address ? { address: r.address } : {} };
|
|
151680
|
+
}
|
|
151681
|
+
/** The other host's answer: on success the copy is written here, under its id */
|
|
151682
|
+
wrote(sender, to, fields5, computer, r) {
|
|
151683
|
+
if (!r.ok) return { ok: false, why: r.why, text: r.text };
|
|
151684
|
+
const address = to && this.route(to) && this.foreign(to) ? to : null;
|
|
151685
|
+
if (address) {
|
|
151686
|
+
this.names.set(address, `${r.to} on ${computer}`);
|
|
151687
|
+
if (this.d.records.message(r.messageId)) return { ok: true, messageId: r.messageId, to: r.to, address, computer };
|
|
151688
|
+
try {
|
|
151689
|
+
this.d.service.sentAcross(sender, { id: r.messageId, to: address, ...fields5 });
|
|
151690
|
+
} catch (e) {
|
|
151691
|
+
this.d.log?.(`[mail] the copy of ${r.messageId}, which ${computer} took, could not be kept here: ${errorMessage(e)}`);
|
|
151692
|
+
}
|
|
151693
|
+
}
|
|
151694
|
+
return { ok: true, messageId: r.messageId, to: r.to, address: address ?? "", computer };
|
|
151695
|
+
}
|
|
151696
|
+
// ── Taking from the other side ──
|
|
151697
|
+
/**
|
|
151698
|
+
* On a hub: a machine's `hub.mail`. The sender is that machine's session, qualified with the link's machine id and never
|
|
151699
|
+
* with anything the call says. `to` absent is the session here that started it; an address here is written here; a
|
|
151700
|
+
* session of another machine is passed on to it, and the answer is that machine's
|
|
151701
|
+
*/
|
|
151702
|
+
async fromMachine(machine, p) {
|
|
151703
|
+
const sender = this.d.service.sessionAddress(`${machine.id}.${p.sessionId}`);
|
|
151704
|
+
if (p.name) this.names.set(sender, `${oneLineText(p.name, 120)} on ${machine.name}`);
|
|
151705
|
+
else if (p.notice && p.sessionId === CENTRALU) this.names.set(sender, `Centralu on ${machine.name}`);
|
|
151706
|
+
let to;
|
|
151707
|
+
if (p.to === void 0) {
|
|
151708
|
+
const parentId = this.peers?.parentOf?.(`${machine.id}.${p.sessionId}`);
|
|
151709
|
+
if (!parentId) return { ok: false, why: "not_yours", text: `${this.selfName()} did not start this session.` };
|
|
151710
|
+
to = this.d.service.sessionAddress(parentId);
|
|
151711
|
+
} else to = p.to;
|
|
151712
|
+
const route = this.route(to);
|
|
151713
|
+
if (!route) return { ok: false, why: "bad_address", text: `Not a mail address: ${JSON.stringify(oneLineText(to, 200))}` };
|
|
151714
|
+
if (route.kind === "hub") return { ok: false, why: "elsewhere", text: `${oneLineText(to, 200)} is not on ${this.selfName()} or a machine it links.` };
|
|
151715
|
+
if (route.kind === "machine") {
|
|
151716
|
+
if (route.machineId === machine.id) return { ok: false, why: "bad_address", text: `${oneLineText(to, 200)} is a session on your own computer: write to it by its id, ${route.sessionId}.` };
|
|
151717
|
+
const m = this.peers?.machine?.(route.machineId);
|
|
151718
|
+
if (!m) return { ok: false, why: "link_down", text: `no machine ${route.machineId} is linked to ${this.selfName()}, so nothing was sent.` };
|
|
151719
|
+
const r = await this.ask(m, "host.mail", { from: sender, name: this.names.get(sender) ?? p.name, to: route.sessionId, text: p.text, ...pick4(p) });
|
|
151720
|
+
return r.ok ? { ok: true, messageId: r.messageId, to: `${r.to} on ${m.name}`, address: to } : r;
|
|
151721
|
+
}
|
|
151722
|
+
return this.write(sender, to, p);
|
|
151723
|
+
}
|
|
151724
|
+
/**
|
|
151725
|
+
* On a machine: a hub's `host.mail`, from the hub that offered on this connection (`hub`). `from` must be on that hub's
|
|
151726
|
+
* side; `to` is a session of this host
|
|
151727
|
+
*/
|
|
151728
|
+
fromHub(hub, p) {
|
|
151729
|
+
const from = p.from === CENTRALU ? CENTRALU : this.fromHubNames(hub.id, p.from);
|
|
151730
|
+
const party = parseAddress(from);
|
|
151731
|
+
if (from !== CENTRALU && (party?.kind !== "session" || party.host !== hub.id)) return { ok: false, why: "not_allowed", text: `${hub.name} may send mail only from its own side.` };
|
|
151732
|
+
if (from !== CENTRALU) this.names.set(from, p.name ? oneLineText(p.name, 200) : `a session on ${hub.name}`);
|
|
151733
|
+
const to = this.d.service.sessionAddress(p.to);
|
|
151734
|
+
return this.write(from, to, p, this.asHubNames(hub.id, to));
|
|
151735
|
+
}
|
|
151736
|
+
/**
|
|
151737
|
+
* The message written here, by this host's one send and its guards; or its refusal, nothing written. Only `from` set to
|
|
151738
|
+
* Centralu, which `fromHub` alone passes (a hub writes its own notices on the machines it links), is written as a notice
|
|
151739
|
+
* of Centralu's. A notice from the other side's session or machine is that side's message, never Centralu's, and is
|
|
151740
|
+
* taken only for a session here that mailed that side: the "no longer watched" notice it passes on is about such mail.
|
|
151741
|
+
* `seen`: `to` as the sender's side names it, which a refusal names
|
|
151742
|
+
*/
|
|
151743
|
+
write(from, to, p, seen = to) {
|
|
151744
|
+
if (p.id !== void 0) {
|
|
151745
|
+
if (!FOREIGN_ID.test(p.id) || p.id.startsWith(`${this.d.hostId}.`)) return { ok: false, why: "bad_value", text: `${oneLineText(p.id, 200)} is not an id another computer may give a message.` };
|
|
151746
|
+
const had = this.d.records.message(p.id);
|
|
151747
|
+
if (had) {
|
|
151748
|
+
if (had.sender === from && this.d.records.recipient(p.id, to)) return { ok: true, messageId: p.id, to: this.label(to), address: to };
|
|
151749
|
+
return { ok: false, why: "bad_value", text: `${oneLineText(p.id, 200)} is the id of another message on ${this.selfName()}.` };
|
|
151750
|
+
}
|
|
151751
|
+
}
|
|
151752
|
+
if (p.replyTo !== void 0) this.adopt(p.replyTo, from);
|
|
151753
|
+
try {
|
|
151754
|
+
if (from === CENTRALU) {
|
|
151755
|
+
const m = this.d.service.notice(to, { body: p.text, facts: {}, dedupeKey: `across:${this.now()}:${Math.random().toString(36).slice(2, 10)}` });
|
|
151756
|
+
return { ok: true, messageId: m?.id ?? "notice", to: this.d.reach.labelOf(to), address: to };
|
|
151757
|
+
}
|
|
151758
|
+
if (p.notice && !this.d.records.sentToward(to, sideOf(from))) {
|
|
151759
|
+
return { ok: false, why: "not_allowed", text: `${oneLineText(this.foreignName(from)?.name ?? from, 200)} may send a notice only to a session that mailed it, and ${oneLineText(to, 200)} did not, so nothing was written.` };
|
|
151760
|
+
}
|
|
151761
|
+
const sent = this.d.service.send(from, { to: [to], text: p.text, needsReply: p.notice ? false : p.needsReply ?? true, ...p.urgent && !p.notice ? { urgent: true } : {}, ...p.replyTo && !p.notice ? { replyTo: p.replyTo } : {}, ...p.id ? { id: p.id } : {} });
|
|
151762
|
+
return { ok: true, messageId: sent.message.id, to: this.label(to), address: to };
|
|
151763
|
+
} catch (e) {
|
|
151764
|
+
const why2 = refusalReason(e);
|
|
151765
|
+
const lost = why2 === "unknown_message" && p.replyTo !== void 0 && !this.d.records.message(p.replyTo);
|
|
151766
|
+
const text3 = why2 === "gone" ? (
|
|
151767
|
+
// The service names the session by this host's address, which the sender never used
|
|
151768
|
+
`${oneLineText(seen, 200)} is gone from ${this.selfName()}: it is in the session archive there or deleted, so nothing was written.`
|
|
151769
|
+
) : lost ? `${this.selfName()} has no record of ${oneLineText(p.replyTo ?? "", 200)}: it most likely reached you while the link failed during its sending, so ${this.selfName()} never kept its copy, and nothing was written. Send your answer again as a new message (without replying to that one), saying what it answers.` : why2 ? errorMessage(e) : `${this.selfName()} could not take the message: ${oneLineText(errorMessage(e), 500)}`;
|
|
151770
|
+
return { ok: false, why: why2 ?? "failed", text: text3.slice(0, 4e3) };
|
|
151771
|
+
}
|
|
151772
|
+
}
|
|
151773
|
+
/** A session here as the other side's answer names it; written whatever its label */
|
|
151774
|
+
label(to) {
|
|
151775
|
+
try {
|
|
151776
|
+
return oneLineText(this.d.reach.labelOf(to), 120);
|
|
151777
|
+
} catch {
|
|
151778
|
+
return to;
|
|
151779
|
+
}
|
|
151780
|
+
}
|
|
151781
|
+
selfName() {
|
|
151782
|
+
return this.peers?.selfName() ?? "this computer";
|
|
151783
|
+
}
|
|
151784
|
+
// ── Receipts ──
|
|
151785
|
+
/** Something in the mailbox changed: the rows that crossed are compared with what the other side was told, soon */
|
|
151786
|
+
changed() {
|
|
151787
|
+
if (!this.peers) return;
|
|
151788
|
+
if (this.syncing) {
|
|
151789
|
+
this.again = true;
|
|
151790
|
+
return;
|
|
151791
|
+
}
|
|
151792
|
+
;
|
|
151793
|
+
(this.d.soon ?? ((fn2) => setImmediate(fn2)))(() => void this.sync());
|
|
151794
|
+
}
|
|
151795
|
+
/** Tells the other side of each crossing row what changed since it was last told; a row that could not be told is tried again on the next change */
|
|
151796
|
+
async sync() {
|
|
151797
|
+
if (this.syncing || !this.peers) return;
|
|
151798
|
+
this.syncing = true;
|
|
151799
|
+
try {
|
|
151800
|
+
do {
|
|
151801
|
+
this.again = false;
|
|
151802
|
+
await this.syncOnce();
|
|
151803
|
+
} while (this.again);
|
|
151804
|
+
} finally {
|
|
151805
|
+
this.syncing = false;
|
|
151806
|
+
}
|
|
151807
|
+
}
|
|
151808
|
+
async syncOnce() {
|
|
151809
|
+
const out = /* @__PURE__ */ new Map();
|
|
151810
|
+
const at2 = this.now();
|
|
151811
|
+
let all = true;
|
|
151812
|
+
const mark = this.d.toldAt?.get() ?? null;
|
|
151813
|
+
for (const row of this.d.records.acrossRows(this.d.hostId, mark === null ? 0 : Math.max(0, mark - TOLD_SLACK_MS))) {
|
|
151814
|
+
const copy = this.foreign(row.recipient);
|
|
151815
|
+
if (copy && row.settled !== "withdrawn") continue;
|
|
151816
|
+
const toward = this.route(copy ? row.recipient : row.sender);
|
|
151817
|
+
if (!toward || toward.kind === "here") continue;
|
|
151818
|
+
const state = stateOf(row);
|
|
151819
|
+
const key = `${row.messageId}|${row.recipient}`;
|
|
151820
|
+
const sig = JSON.stringify(state);
|
|
151821
|
+
if (this.told.get(key) === sig) continue;
|
|
151822
|
+
const peer = toward.kind === "hub" ? { kind: "hub", id: toward.hubId } : { kind: "machine", id: toward.machineId };
|
|
151823
|
+
const k2 = `${peer.kind}:${peer.id}`;
|
|
151824
|
+
const batch = out.get(k2) ?? { peer, rows: [], keys: [] };
|
|
151825
|
+
const named3 = peer.kind === "hub" ? { ...state, recipient: this.asHubNames(peer.id, state.recipient), sender: this.asHubNames(peer.id, row.sender) } : { ...state, sender: row.sender };
|
|
151826
|
+
batch.rows.push(named3);
|
|
151827
|
+
batch.keys.push([key, sig]);
|
|
151828
|
+
out.set(k2, batch);
|
|
151829
|
+
}
|
|
151830
|
+
await Promise.all(
|
|
151831
|
+
[...out.values()].map(async (b2) => {
|
|
151832
|
+
const p = b2.peer.kind === "hub" ? this.peers?.hub?.(b2.peer.id) : this.peers?.machine?.(b2.peer.id);
|
|
151833
|
+
if (!p) return;
|
|
151834
|
+
if (!p.reachable) return void (all = false);
|
|
151835
|
+
try {
|
|
151836
|
+
for (let i = 0; i < b2.rows.length; i += 200) await p.call(b2.peer.kind === "hub" ? "hub.mailRows" : "host.mailRows", { rows: b2.rows.slice(i, i + 200) });
|
|
151837
|
+
for (const [key, sig] of b2.keys) this.told.set(key, sig);
|
|
151838
|
+
} catch (e) {
|
|
151839
|
+
if (older(e)) return;
|
|
151840
|
+
all = false;
|
|
151841
|
+
this.d.log?.(`[mail] ${p.name} could not be told what became of ${b2.rows.length} message(s): ${errorMessage(e)}`);
|
|
151842
|
+
}
|
|
151843
|
+
})
|
|
151844
|
+
);
|
|
151845
|
+
if (all) this.d.toldAt?.set(at2);
|
|
151846
|
+
}
|
|
151847
|
+
/**
|
|
151848
|
+
* The other side's rows (`hub.mailRows`, `host.mailRows`). Each is merged into the row here when this host has it; on a
|
|
151849
|
+
* hub, a row of mail between two machines is passed on to the machine it is for (by the sender for a receipt, by the
|
|
151850
|
+
* recipient for a withdrawal). `from`: the hub whose names they are, on a machine
|
|
151851
|
+
*/
|
|
151852
|
+
async rows(rows3, from) {
|
|
151853
|
+
const onward = /* @__PURE__ */ new Map();
|
|
151854
|
+
for (const raw of rows3) {
|
|
151855
|
+
const recipient = "hub" in from ? this.fromHubNames(from.hub, raw.recipient) : raw.recipient;
|
|
151856
|
+
const sender = raw.sender === void 0 ? void 0 : "hub" in from ? this.fromHubNames(from.hub, raw.sender) : raw.sender;
|
|
151857
|
+
const row = { ...pickState(raw), recipient };
|
|
151858
|
+
if (this.tells(from, recipient)) this.adopt(row.messageId, recipient);
|
|
151859
|
+
const here = this.d.records.recipient(row.messageId, recipient);
|
|
151860
|
+
if (here) {
|
|
151861
|
+
const side = this.foreign(recipient) ? "copy" : "recipient";
|
|
151862
|
+
const stored = this.d.records.message(row.messageId)?.sender;
|
|
151863
|
+
if (!this.tells(from, side === "copy" ? recipient : stored)) continue;
|
|
151864
|
+
if (sender !== void 0 && sender !== stored) continue;
|
|
151865
|
+
if (this.d.records.mergeAcross(row, side)) {
|
|
151866
|
+
const merged = this.d.records.recipient(row.messageId, recipient);
|
|
151867
|
+
if (merged) this.told.set(`${row.messageId}|${recipient}`, JSON.stringify(stateOf(merged)));
|
|
151868
|
+
}
|
|
151869
|
+
continue;
|
|
151870
|
+
}
|
|
151871
|
+
if (!("machine" in from)) continue;
|
|
151872
|
+
const withdrawn = row.settled === "withdrawn";
|
|
151873
|
+
const target = this.route(withdrawn ? recipient : sender ?? "");
|
|
151874
|
+
if (target?.kind !== "machine" || target.machineId === from.machine || !this.tells(from, withdrawn ? sender : recipient)) continue;
|
|
151875
|
+
onward.set(target.machineId, [...onward.get(target.machineId) ?? [], { ...row, ...sender ? { sender } : {} }]);
|
|
151876
|
+
}
|
|
151877
|
+
await Promise.all(
|
|
151878
|
+
[...onward].map(async ([id3, list2]) => {
|
|
151879
|
+
const m = this.peers?.machine?.(id3);
|
|
151880
|
+
if (m?.reachable) await m.call("host.mailRows", { rows: list2 }).catch((e) => this.d.log?.(`[mail] ${m.name} could not be told what became of ${list2.length} message(s): ${errorMessage(e)}`));
|
|
151881
|
+
})
|
|
151882
|
+
);
|
|
151883
|
+
}
|
|
151884
|
+
/**
|
|
151885
|
+
* Whether the side that sent rows (`from`) is the one `address` is on, and so may tell what became of its row: a machine
|
|
151886
|
+
* this hub links for its own sessions, a hub for the sessions on its side
|
|
151887
|
+
*/
|
|
151888
|
+
tells(from, address) {
|
|
151889
|
+
if (address === void 0) return false;
|
|
151890
|
+
const r = this.route(address);
|
|
151891
|
+
if ("machine" in from) return r?.kind === "machine" && r.machineId === from.machine;
|
|
151892
|
+
return r?.kind === "hub" && r.hubId === from.hub;
|
|
151893
|
+
}
|
|
151894
|
+
// ── Notices ──
|
|
151895
|
+
/**
|
|
151896
|
+
* A Centralu notice written here to a session on the other side (the "no longer watched" notice to a sender there): passed
|
|
151897
|
+
* on as a notice, and its row here marked delivered and read, so this host never tries it. One that cannot be passed on
|
|
151898
|
+
* is dropped and said in the log: nothing waits for a link
|
|
151899
|
+
*/
|
|
151900
|
+
async passOn(messageId) {
|
|
151901
|
+
const m = this.d.records.message(messageId);
|
|
151902
|
+
if (!m || m.sender !== CENTRALU) return;
|
|
151903
|
+
for (const row of this.d.records.recipients(messageId)) {
|
|
151904
|
+
if (!this.foreign(row.recipient) || row.deliveredAt !== null) continue;
|
|
151905
|
+
const now = this.now();
|
|
151906
|
+
this.d.records.markDelivered(row.recipient, [messageId], now, null);
|
|
151907
|
+
this.d.records.markRead(row.recipient, [messageId], now);
|
|
151908
|
+
const r = this.route(row.recipient);
|
|
151909
|
+
let sent = { ok: false, text: "no link" };
|
|
151910
|
+
if (r?.kind === "machine") {
|
|
151911
|
+
const peer = this.peers?.machine?.(r.machineId);
|
|
151912
|
+
if (peer) sent = await this.ask(peer, "host.mail", { from: CENTRALU, to: r.sessionId, text: m.body, notice: true });
|
|
151913
|
+
} else if (r?.kind === "hub") {
|
|
151914
|
+
const peer = this.peers?.hub?.(r.hubId);
|
|
151915
|
+
if (peer?.you) sent = await this.ask(peer, "hub.mail", { sessionId: "centralu", to: row.recipient, text: m.body, notice: true });
|
|
151916
|
+
}
|
|
151917
|
+
if (!sent.ok) this.d.log?.(`[mail] a notice to ${row.recipient} could not be passed on, and was dropped: ${sent.text ?? ""}`);
|
|
151918
|
+
}
|
|
151919
|
+
}
|
|
151920
|
+
// ── Finding ──
|
|
151921
|
+
/**
|
|
151922
|
+
* `mail find` (§8): this host's sessions and those it reaches, ranked, at most `FIND_LIMIT`. `self`: the caller, left out.
|
|
151923
|
+
* On a machine each hub is asked, bounded; a hub that does not answer is named, and its side is not listed
|
|
151924
|
+
*/
|
|
151925
|
+
async find(query, self2) {
|
|
151926
|
+
const { entries, away, total } = await this.directory(query, false);
|
|
151927
|
+
const found = ranked(entries.filter((e) => e.address !== self2), query);
|
|
151928
|
+
return findAnswer({ query, found, matched: found.length, total: total - (entries.some((e) => e.address === self2) ? 1 : 0), away });
|
|
151929
|
+
}
|
|
151930
|
+
/**
|
|
151931
|
+
* The sessions on other computers named `name` exactly, and the computers that could not be asked. `here`: a session on
|
|
151932
|
+
* this computer has the name, so a hub is waited for only as long as a reachable one answers in (`NAMED_HERE_MS`), not
|
|
151933
|
+
* `FIND_MS`: one that does not answer then leaves the send to the session here (#2067 review)
|
|
151934
|
+
*/
|
|
151935
|
+
async named(name, o = {}) {
|
|
151936
|
+
const { entries, away } = await this.directory(name, true, false, o.here ? NAMED_HERE_MS : FIND_MS);
|
|
151937
|
+
return { found: named(entries, name), away };
|
|
151938
|
+
}
|
|
151939
|
+
/** The directory: this host's own entries (unless `own` is false), a hub's mirrors, and each hub's answer on a machine */
|
|
151940
|
+
async directory(query, exact, own = true, ms3 = FIND_MS) {
|
|
151941
|
+
const entries = own ? this.d.ownEntries() : [];
|
|
151942
|
+
const away = [];
|
|
151943
|
+
let total = entries.length;
|
|
151944
|
+
const mirror = this.peers?.machineDirectory?.();
|
|
151945
|
+
if (mirror) {
|
|
151946
|
+
entries.push(...mirror.entries);
|
|
151947
|
+
total += mirror.entries.length;
|
|
151948
|
+
away.push(...mirror.away);
|
|
151949
|
+
}
|
|
151950
|
+
await Promise.all(
|
|
151951
|
+
(this.peers?.hubs?.() ?? []).map(async (h) => {
|
|
151952
|
+
if (!h.you) return away.push({ name: h.name, why: "it runs an older Centralu; update it there" });
|
|
151953
|
+
if (!h.reachable) return away.push({ name: h.name, why: "not reachable right now" });
|
|
151954
|
+
try {
|
|
151955
|
+
const raw = await Promise.race([h.call("hub.find", { query, limit: exact ? 50 : FIND_LIMIT, ...exact ? { exact: true } : {} }), timeout(ms3)]);
|
|
151956
|
+
const r = HubFindResult.safeParse(raw);
|
|
151957
|
+
if (!r.success) return away.push({ name: h.name, why: "its answer could not be read" });
|
|
151958
|
+
for (const e of r.data.entries) {
|
|
151959
|
+
const address = this.fromHubNames(h.id, e.address);
|
|
151960
|
+
if (!this.foreign(address)) continue;
|
|
151961
|
+
this.names.set(address, e.machine ? `${e.name} on ${e.machine}` : `${e.name} on ${h.name}`);
|
|
151962
|
+
entries.push({ ...e, address, machine: e.machine ?? h.name });
|
|
151963
|
+
}
|
|
151964
|
+
total += r.data.total;
|
|
151965
|
+
away.push(...r.data.away);
|
|
151966
|
+
} catch (e) {
|
|
151967
|
+
away.push({ name: h.name, why: older(e) ? "it runs an older Centralu; update it there" : "it did not answer" });
|
|
151968
|
+
}
|
|
151969
|
+
})
|
|
151970
|
+
);
|
|
151971
|
+
return { entries, away, total };
|
|
151972
|
+
}
|
|
151973
|
+
/** On a hub: a machine's `hub.find`. Its own sessions are left out: it lists them itself, under its own addresses */
|
|
151974
|
+
answerFind(machine, p) {
|
|
151975
|
+
const own = this.d.ownEntries().map((e) => ({ ...e, machine: e.machine ?? this.selfName() }));
|
|
151976
|
+
const mirror = this.peers?.machineDirectory?.() ?? { entries: [], away: [] };
|
|
151977
|
+
const all = [...own, ...mirror.entries.filter((e) => e.machineId !== machine.id)];
|
|
151978
|
+
const found = p.exact ? named(all, p.query) : ranked(all, p.query);
|
|
151979
|
+
return {
|
|
151980
|
+
entries: found.slice(0, p.limit).map(({ machineId: _m2, ...e }) => e),
|
|
151981
|
+
matched: found.length,
|
|
151982
|
+
total: all.length,
|
|
151983
|
+
away: mirror.away
|
|
151984
|
+
};
|
|
151985
|
+
}
|
|
151986
|
+
};
|
|
151987
|
+
function sideOf(address) {
|
|
151988
|
+
const p = parseAddress(address);
|
|
151989
|
+
if (p?.kind !== "session") return address;
|
|
151990
|
+
const dot = p.sessionId.indexOf(".");
|
|
151991
|
+
return dot < 0 ? `session:${p.host}/` : `session:${p.host}/${p.sessionId.slice(0, dot + 1)}`;
|
|
151992
|
+
}
|
|
151993
|
+
function pick4(p) {
|
|
151994
|
+
return { ...p.needsReply !== void 0 ? { needsReply: p.needsReply } : {}, ...p.urgent ? { urgent: true } : {}, ...p.replyTo ? { replyTo: p.replyTo } : {}, ...p.notice ? { notice: true } : {}, ...p.id ? { id: p.id } : {} };
|
|
151995
|
+
}
|
|
151996
|
+
var AGAIN = "Send it again with the same words: if it did arrive, it is not written there twice, and this computer keeps its copy then.";
|
|
151997
|
+
function stateOf(r) {
|
|
151998
|
+
return {
|
|
151999
|
+
messageId: r.messageId,
|
|
152000
|
+
recipient: r.recipient,
|
|
152001
|
+
deliveredAt: r.deliveredAt,
|
|
152002
|
+
readAt: r.readAt,
|
|
152003
|
+
settled: r.settled,
|
|
152004
|
+
settledAt: r.settledAt,
|
|
152005
|
+
answerId: r.answerId,
|
|
152006
|
+
releasedAt: r.releasedAt,
|
|
152007
|
+
releasedWhy: r.releasedWhy
|
|
152008
|
+
};
|
|
152009
|
+
}
|
|
152010
|
+
function pickState(r) {
|
|
152011
|
+
return stateOf(r);
|
|
152012
|
+
}
|
|
152013
|
+
function timeout(ms3) {
|
|
152014
|
+
return new Promise((_, reject) => {
|
|
152015
|
+
const t = setTimeout(() => reject(new Error(`no answer within ${ms3 / 1e3} s`)), ms3);
|
|
152016
|
+
t.unref?.();
|
|
152017
|
+
});
|
|
152018
|
+
}
|
|
151040
152019
|
|
|
151041
152020
|
// packages/agent-host/src/mail/turns.ts
|
|
151042
152021
|
var STARTED_BY = ["mail", "person", "caller", "cli", "report", "app"];
|
|
@@ -151123,8 +152102,8 @@ var MailTurns = class {
|
|
|
151123
152102
|
current(sessionId) {
|
|
151124
152103
|
const t = this.open.get(sessionId);
|
|
151125
152104
|
if (!t) return void 0;
|
|
151126
|
-
const
|
|
151127
|
-
return { ...
|
|
152105
|
+
const read2 = { turnSeq: t.seq, by: t.by, messageId: t.messageId };
|
|
152106
|
+
return { ...read2, starter: t.starter, asker: this.opts.askerIn?.(sessionId, read2) ?? null, startedAt: t.startedAt };
|
|
151128
152107
|
}
|
|
151129
152108
|
/**
|
|
151130
152109
|
* The session's turn that is going, or else the one that ended last: the end of a turn is reported once it ends, and the report belongs to that
|
|
@@ -151195,6 +152174,7 @@ function mailSessionsOf(mgr2, assistantHasMailCommand) {
|
|
|
151195
152174
|
onLinkedMachine: (id3) => mgr2.mail.onLinkedMachine(id3)
|
|
151196
152175
|
};
|
|
151197
152176
|
}
|
|
152177
|
+
var ACROSS_TOLD_KEY = "mail.acrossToldAt";
|
|
151198
152178
|
function hostMail(store2, sessions, opts) {
|
|
151199
152179
|
const { hostId } = opts;
|
|
151200
152180
|
const now = opts.now ?? Date.now;
|
|
@@ -151204,13 +152184,18 @@ function hostMail(store2, sessions, opts) {
|
|
|
151204
152184
|
return party?.kind === "session" ? { ...m, about: party.sessionId } : m;
|
|
151205
152185
|
});
|
|
151206
152186
|
const projects = () => store2.projects.listProjects();
|
|
152187
|
+
const far = {};
|
|
152188
|
+
const records = watched(store2.mailbox, () => far.across?.changed());
|
|
151207
152189
|
const reach = mailReach({
|
|
151208
152190
|
hostId,
|
|
151209
152191
|
session: (id3) => {
|
|
151210
152192
|
const s = sessions.sessionInfo(id3);
|
|
151211
152193
|
if (s) return { projectId: s.projectId ?? null, askedBy: s.askedBy ?? null, here: true, canReadMail: sessions.canReadMail(id3), host: "here", name: s.name };
|
|
151212
|
-
|
|
152194
|
+
const linked = sessions.onLinkedMachine?.(id3) ?? (id3.includes(".") ? far.across?.foreignName(addressOf(id3)) : void 0);
|
|
152195
|
+
return linked ? { projectId: null, askedBy: null, here: true, canReadMail: false, host: "elsewhere", name: linked.name } : void 0;
|
|
151213
152196
|
},
|
|
152197
|
+
// A session of a hub this host is linked to (#2067 item 2), by the name it was last heard by
|
|
152198
|
+
foreign: (address) => far.across?.foreignName(address),
|
|
151214
152199
|
assistantId: () => sessions.assistantId(),
|
|
151215
152200
|
assistantAsks: () => sessions.assistantAsks() === null,
|
|
151216
152201
|
// Nothing records an app's caller before the apps' mail API (§13) but an old thread the app wrote into: its moved mail to that session
|
|
@@ -151222,7 +152207,7 @@ function hostMail(store2, sessions, opts) {
|
|
|
151222
152207
|
askGroupMembers: (address) => askGroupMembers(sessions, hostId, address)
|
|
151223
152208
|
});
|
|
151224
152209
|
const box = {};
|
|
151225
|
-
const service = new MessageService(
|
|
152210
|
+
const service = new MessageService(records, reach, {
|
|
151226
152211
|
hostId,
|
|
151227
152212
|
...opts.now ? { now: opts.now } : {},
|
|
151228
152213
|
turn: (address) => {
|
|
@@ -151261,7 +152246,25 @@ function hostMail(store2, sessions, opts) {
|
|
|
151261
152246
|
askerIn: (id3, turn) => service.requestsIn(addressOf(id3), turn)[0]?.asker ?? null
|
|
151262
152247
|
});
|
|
151263
152248
|
const mailTurns = box.turns;
|
|
151264
|
-
const
|
|
152249
|
+
const across = new MailAcross({
|
|
152250
|
+
hostId,
|
|
152251
|
+
service,
|
|
152252
|
+
records,
|
|
152253
|
+
reach,
|
|
152254
|
+
// Kept in the store: a restart tells again what was settled since every side last heard, and nothing older
|
|
152255
|
+
toldAt: {
|
|
152256
|
+
get: () => Number(store2.settings.appSetting(ACROSS_TOLD_KEY)) || null,
|
|
152257
|
+
set: (at2) => store2.settings.setAppSetting(ACROSS_TOLD_KEY, String(at2))
|
|
152258
|
+
},
|
|
152259
|
+
...opts.now ? { now: opts.now } : {},
|
|
152260
|
+
log: (line) => console.error(line),
|
|
152261
|
+
ownEntries: () => sessions.listSessions().map((s) => entryOf2(s, { address: addressOf(s.id), project: s.projectId ? reach.projectLabel(s.projectId) : null, machine: null }))
|
|
152262
|
+
});
|
|
152263
|
+
far.across = across;
|
|
152264
|
+
service.onChange((c) => {
|
|
152265
|
+
if (c.recipients.some((r) => across.foreign(r))) void across.passOn(c.messageId);
|
|
152266
|
+
});
|
|
152267
|
+
const delivery = new MailDelivery(service, records, sessions.mailSessions(), {
|
|
151265
152268
|
turns: mailTurns,
|
|
151266
152269
|
...opts.now ? { now: opts.now } : {},
|
|
151267
152270
|
// When it last ran: a host that was off a long while does not wake a crowd of sleeping sessions. A setting the previous build never reads
|
|
@@ -151269,6 +152272,7 @@ function hostMail(store2, sessions, opts) {
|
|
|
151269
152272
|
read: () => Number(store2.settings.appSetting("mail.heartbeat")) || null,
|
|
151270
152273
|
write: (ms3) => store2.settings.setAppSetting("mail.heartbeat", String(ms3))
|
|
151271
152274
|
},
|
|
152275
|
+
across: (address) => across.foreign(address),
|
|
151272
152276
|
...opts.delivery
|
|
151273
152277
|
});
|
|
151274
152278
|
const askedByHost = {
|
|
@@ -151288,7 +152292,7 @@ function hostMail(store2, sessions, opts) {
|
|
|
151288
152292
|
}) } : null;
|
|
151289
152293
|
}
|
|
151290
152294
|
};
|
|
151291
|
-
const tool = new MailTool(service,
|
|
152295
|
+
const tool = new MailTool(service, records, reach, {
|
|
151292
152296
|
personMessage: (sessionId, seq) => {
|
|
151293
152297
|
const row = store2.messages.loadMessagesFrom(sessionId, seq - 1, 1).find((r) => r.seq === seq);
|
|
151294
152298
|
return row && typeof row.payload === "object" && row.payload !== null && "text" in row.payload && typeof row.payload.text === "string" ? row.payload.text : null;
|
|
@@ -151301,7 +152305,8 @@ function hostMail(store2, sessions, opts) {
|
|
|
151301
152305
|
sessions: () => sessions.listSessions().map((s) => ({ id: s.id, name: s.name, project: s.projectId ?? null, state: s.state })),
|
|
151302
152306
|
form: (id3) => sessions.mailCommand(id3) ? "command" : "plain",
|
|
151303
152307
|
askerOf: (id3) => askerFacts(askedByHost, id3),
|
|
151304
|
-
legacyChain: (threadId, messageId, reader) => store2.legacyChainFor(threadId, messageId, reader, 9)
|
|
152308
|
+
legacyChain: (threadId, messageId, reader) => store2.legacyChainFor(threadId, messageId, reader, 9),
|
|
152309
|
+
across
|
|
151305
152310
|
});
|
|
151306
152311
|
const owedOld = (sender, recipient) => {
|
|
151307
152312
|
const owner = parseAddress(sender);
|
|
@@ -151327,7 +152332,7 @@ function hostMail(store2, sessions, opts) {
|
|
|
151327
152332
|
service.notice(PERSON, { body: WARNING_TEXT.compactCycles(service.labelOf(addressOf(id3)), count), facts: { compactCycles: { session: addressOf(id3), count } }, dedupeKey: `compactcycles:${addressOf(id3)}:${hour}` });
|
|
151328
152333
|
},
|
|
151329
152334
|
sessionEvent: (e, ended2) => mailTurns.observe(e, ended2),
|
|
151330
|
-
tool: (id3, args) => tool.
|
|
152335
|
+
tool: (id3, args) => tool.call(id3, args),
|
|
151331
152336
|
// Work a session gave another is a task, beside the old path that delivered it (§9.1)
|
|
151332
152337
|
delegated: delegationRecorder(service, mailTurns),
|
|
151333
152338
|
waitingOn,
|
|
@@ -151344,6 +152349,8 @@ function hostMail(store2, sessions, opts) {
|
|
|
151344
152349
|
};
|
|
151345
152350
|
return {
|
|
151346
152351
|
service,
|
|
152352
|
+
records,
|
|
152353
|
+
across,
|
|
151347
152354
|
reach,
|
|
151348
152355
|
turns: mailTurns,
|
|
151349
152356
|
delivery,
|
|
@@ -151414,6 +152421,113 @@ function refusesDelegation(service, reach, callerId, target, call2) {
|
|
|
151414
152421
|
service.refused(callerId, { tool: call2.tool, target: call2.target, firstLine: firstLineOf(call2.text), projectId });
|
|
151415
152422
|
return `Refused (untrusted_project): ${REFUSAL_TEXT.untrusted_project(reach.projectLabel(projectId), call2.target)}`;
|
|
151416
152423
|
}
|
|
152424
|
+
var MUTATORS = /* @__PURE__ */ new Set([
|
|
152425
|
+
"insert",
|
|
152426
|
+
"markAttempt",
|
|
152427
|
+
"markDelivered",
|
|
152428
|
+
"hold",
|
|
152429
|
+
"letGo",
|
|
152430
|
+
"markRead",
|
|
152431
|
+
"release",
|
|
152432
|
+
"closeFor",
|
|
152433
|
+
"dismiss",
|
|
152434
|
+
"failedTry",
|
|
152435
|
+
"takeBack",
|
|
152436
|
+
"undeliver",
|
|
152437
|
+
"markUncertain",
|
|
152438
|
+
"markMaybeRepeated",
|
|
152439
|
+
"deleteHeld",
|
|
152440
|
+
"deleteRows",
|
|
152441
|
+
"settle",
|
|
152442
|
+
"answerHeld",
|
|
152443
|
+
"answerDropped",
|
|
152444
|
+
"markReleased",
|
|
152445
|
+
"markTold",
|
|
152446
|
+
"moveRows",
|
|
152447
|
+
"moveRole",
|
|
152448
|
+
"purgeParty",
|
|
152449
|
+
"sweep",
|
|
152450
|
+
"mergeAcross"
|
|
152451
|
+
]);
|
|
152452
|
+
function watched(records, changed) {
|
|
152453
|
+
return new Proxy(records, {
|
|
152454
|
+
get(target, key, receiver) {
|
|
152455
|
+
const value = Reflect.get(target, key, receiver);
|
|
152456
|
+
if (typeof value !== "function") return value;
|
|
152457
|
+
if (typeof key !== "string" || !MUTATORS.has(key)) return (...args) => Reflect.apply(value, target, args);
|
|
152458
|
+
return (...args) => {
|
|
152459
|
+
const out = Reflect.apply(value, target, args);
|
|
152460
|
+
changed();
|
|
152461
|
+
return out;
|
|
152462
|
+
};
|
|
152463
|
+
}
|
|
152464
|
+
});
|
|
152465
|
+
}
|
|
152466
|
+
|
|
152467
|
+
// packages/agent-host/src/links/mail-peers.ts
|
|
152468
|
+
function mailPeers(o) {
|
|
152469
|
+
const { machines, hubs: hubs2, settings } = o;
|
|
152470
|
+
const projectNames = (m) => new Map((m.lastKnown("projects") ?? []).flatMap((p) => isObj(p) && typeof p.id === "string" && typeof p.name === "string" ? [[p.id, p.name]] : []));
|
|
152471
|
+
return {
|
|
152472
|
+
selfName: o.selfName,
|
|
152473
|
+
onConnect: (fn2) => {
|
|
152474
|
+
hubs2?.onMailOffer?.(() => fn2());
|
|
152475
|
+
},
|
|
152476
|
+
...o.parentOf ? { parentOf: o.parentOf } : {},
|
|
152477
|
+
...machines ? {
|
|
152478
|
+
machine: (id3) => {
|
|
152479
|
+
const m = machines.get(id3);
|
|
152480
|
+
return m && { id: m.id, name: m.name, reachable: m.reachable, call: (method, params) => m.call(method, params) };
|
|
152481
|
+
},
|
|
152482
|
+
machineSession: (machineId, sessionId) => {
|
|
152483
|
+
const m = machines.get(machineId);
|
|
152484
|
+
const row = (m?.lastKnown("sessions") ?? []).find((s) => isObj(s) && s.id === sessionId);
|
|
152485
|
+
return m && isObj(row) && typeof row.name === "string" ? `${row.name} on ${m.name}` : void 0;
|
|
152486
|
+
},
|
|
152487
|
+
machineDirectory: () => {
|
|
152488
|
+
const entries = [];
|
|
152489
|
+
const away = [];
|
|
152490
|
+
for (const m of machines.all()) {
|
|
152491
|
+
if (!m.reachable) {
|
|
152492
|
+
away.push({ name: m.name, why: NOT_REACHABLE });
|
|
152493
|
+
continue;
|
|
152494
|
+
}
|
|
152495
|
+
const names = projectNames(m);
|
|
152496
|
+
for (const s of m.lastKnown("sessions") ?? []) {
|
|
152497
|
+
if (!isObj(s) || typeof s.id !== "string" || typeof s.name !== "string" || typeof s.kind !== "string" || typeof s.state !== "string" || typeof s.createdAt !== "number") continue;
|
|
152498
|
+
const projectId = typeof s.projectId === "string" ? s.projectId : null;
|
|
152499
|
+
entries.push(
|
|
152500
|
+
entryOf2(
|
|
152501
|
+
{
|
|
152502
|
+
id: s.id,
|
|
152503
|
+
name: s.name,
|
|
152504
|
+
kind: s.kind,
|
|
152505
|
+
state: s.state,
|
|
152506
|
+
askedBy: typeof s.askedBy === "string" ? s.askedBy : null,
|
|
152507
|
+
startedFromHub: s.startedFromHub === true,
|
|
152508
|
+
waitingSince: typeof s.waitingSince === "number" ? s.waitingSince : null,
|
|
152509
|
+
createdAt: s.createdAt,
|
|
152510
|
+
...tasksOf(s)
|
|
152511
|
+
},
|
|
152512
|
+
{ address: sessionAddress(o.hostId, `${m.id}.${s.id}`), project: projectId === null ? null : names.get(projectId) ?? projectId, machine: m.name, machineId: m.id }
|
|
152513
|
+
)
|
|
152514
|
+
);
|
|
152515
|
+
}
|
|
152516
|
+
}
|
|
152517
|
+
return { entries, away };
|
|
152518
|
+
}
|
|
152519
|
+
} : {},
|
|
152520
|
+
...hubs2 ? {
|
|
152521
|
+
hub: (id3) => hubs2.peer(id3),
|
|
152522
|
+
hubs: () => hubs2.mailHubs(),
|
|
152523
|
+
...settings ? { startingHub: (sessionId) => startingHub(settings, sessionId) } : {}
|
|
152524
|
+
} : {}
|
|
152525
|
+
};
|
|
152526
|
+
}
|
|
152527
|
+
function tasksOf(s) {
|
|
152528
|
+
const tasks = external_exports.array(BackgroundTask).safeParse(s.backgroundTasks);
|
|
152529
|
+
return { ...tasks.success ? { backgroundTasks: tasks.data } : {}, ...s.interruption ? { interruption: s.interruption } : {} };
|
|
152530
|
+
}
|
|
151417
152531
|
|
|
151418
152532
|
// packages/agent-host/src/sessions/memory-gate.ts
|
|
151419
152533
|
import { execFile as execFile12 } from "node:child_process";
|
|
@@ -151611,7 +152725,7 @@ function pickStrays(rows3, cwdOf, roots, selfPid, adopter = null) {
|
|
|
151611
152725
|
return out.sort((a, b2) => a.pid - b2.pid);
|
|
151612
152726
|
}
|
|
151613
152727
|
var LIST_TIMEOUT_MS = 12e3;
|
|
151614
|
-
function
|
|
152728
|
+
function unread2(what, e) {
|
|
151615
152729
|
console.error(`[strays] ${what} could not be read (${isObj(e) && typeof e.message === "string" ? e.message.split("\n")[0] : String(e)}); leftovers may be missing from the list`);
|
|
151616
152730
|
}
|
|
151617
152731
|
async function psRows(run4) {
|
|
@@ -151619,7 +152733,7 @@ async function psRows(run4) {
|
|
|
151619
152733
|
const { stdout } = await run4("ps", ["-U", userInfo2().username, "-o", "pid=,ppid=,tty=,command="], { maxBuffer: 8 * 1024 * 1024, timeout: LIST_TIMEOUT_MS, windowsHide: true });
|
|
151620
152734
|
return parsePsRows(stdout);
|
|
151621
152735
|
} catch (e) {
|
|
151622
|
-
|
|
152736
|
+
unread2("the process list", e);
|
|
151623
152737
|
return [];
|
|
151624
152738
|
}
|
|
151625
152739
|
}
|
|
@@ -151630,7 +152744,7 @@ async function cwdsOf(run4, pids) {
|
|
|
151630
152744
|
return parseLsofCwd(stdout);
|
|
151631
152745
|
} catch (e) {
|
|
151632
152746
|
const partial2 = isObj(e) && typeof e.stdout === "string" ? e.stdout : void 0;
|
|
151633
|
-
if (isObj(e) && (e.killed === true || e.signal != null || typeof e.code === "string"))
|
|
152747
|
+
if (isObj(e) && (e.killed === true || e.signal != null || typeof e.code === "string")) unread2("the working folders", e);
|
|
151634
152748
|
return partial2 ? parseLsofCwd(partial2) : /* @__PURE__ */ new Map();
|
|
151635
152749
|
}
|
|
151636
152750
|
}
|
|
@@ -151649,7 +152763,7 @@ async function orphanAdopter(run4 = exec10, end = (pid) => process.kill(pid)) {
|
|
|
151649
152763
|
const command = (await run4("ps", ["-o", "command=", "-p", String(ppid)], opts)).stdout.trim();
|
|
151650
152764
|
return command === "/init" ? ppid : null;
|
|
151651
152765
|
} catch (e) {
|
|
151652
|
-
|
|
152766
|
+
unread2("where an orphan lands", e);
|
|
151653
152767
|
return null;
|
|
151654
152768
|
} finally {
|
|
151655
152769
|
if (pid > 1) try {
|
|
@@ -151814,7 +152928,7 @@ var toInfo = (h) => ({
|
|
|
151814
152928
|
history: h.history(),
|
|
151815
152929
|
alive: h.alive
|
|
151816
152930
|
});
|
|
151817
|
-
function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutlook, terminals: terminals2, updates: updates2, commands, externalApps: externalApps2, views: views2, inlineViews: inlineViews2, themes: themes2, agentVersions: agentVersions2, sleeper: sleeper2, machines, stopHost, stopGate, handover: handover2, systemEnding: systemEnding2, activity: activity2, updateApply: updateApply2, hubs: hubs2, mail, requests: requests2, serveCredentials } = {}) {
|
|
152931
|
+
function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutlook, terminals: terminals2, updates: updates2, commands, externalApps: externalApps2, views: views2, inlineViews: inlineViews2, themes: themes2, agentVersions: agentVersions2, sleeper: sleeper2, machines, stopHost, stopGate, handover: handover2, systemEnding: systemEnding2, activity: activity2, updateApply: updateApply2, hubs: hubs2, mailAcross, mail, requests: requests2, serveCredentials } = {}) {
|
|
151818
152932
|
const reportUiCrash = createUiCrashLog((line) => console.error(line));
|
|
151819
152933
|
const sessionToolSchemas = (sessionId) => {
|
|
151820
152934
|
if (!sessionId) return centraluToolSchemas("assistant");
|
|
@@ -151932,7 +153046,14 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
151932
153046
|
// A script (the limited credential) that starts a session with a first message owes nobody a wait: the work is the person's, reported to their Inbox (§8.1)
|
|
151933
153047
|
"agents.createSession": async (p, ctx) => {
|
|
151934
153048
|
let worktreeBase;
|
|
151935
|
-
const
|
|
153049
|
+
const startedByHub = p.fromHub && ctx ? hubs2?.on?.(ctx.client) : void 0;
|
|
153050
|
+
const info = await mgr2.createSession({
|
|
153051
|
+
...p,
|
|
153052
|
+
onWorktreeBase: (note) => worktreeBase = note,
|
|
153053
|
+
...ctx?.rights === "limited" ? { fromScript: { credential: scriptLabel(ctx.label) } } : {},
|
|
153054
|
+
...startedByHub ? { startedByHub } : {}
|
|
153055
|
+
});
|
|
153056
|
+
if (p.fromHub && ctx && !startedByHub) hubs2?.awaitOffer?.(ctx.client, info.id);
|
|
151936
153057
|
return worktreeBase ? { ...info, worktreeBase } : info;
|
|
151937
153058
|
},
|
|
151938
153059
|
"agents.send": async ({ sessionId, text: text3, attachments, intent }, ctx) => {
|
|
@@ -152451,6 +153572,17 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
152451
153572
|
"host.hubOffer": async (p, ctx) => {
|
|
152452
153573
|
const offer = p;
|
|
152453
153574
|
if (hubs2 && ctx) hubs2.offer(ctx.client, offer);
|
|
153575
|
+
return { ok: true, ...mailAcross && hubs2 ? { mail: true } : {} };
|
|
153576
|
+
},
|
|
153577
|
+
"host.mail": async (p, ctx) => {
|
|
153578
|
+
const hub = ctx ? hubs2?.on?.(ctx.client) : void 0;
|
|
153579
|
+
if (!mailAcross || !hub) throw rpcError("Only a hub that offered on this connection sends mail here");
|
|
153580
|
+
return mailAcross.fromHub(hub, p);
|
|
153581
|
+
},
|
|
153582
|
+
"host.mailRows": async (p, ctx) => {
|
|
153583
|
+
const hub = ctx ? hubs2?.on?.(ctx.client) : void 0;
|
|
153584
|
+
if (!mailAcross || !hub) throw rpcError("Only a hub that offered on this connection says what became of mail here");
|
|
153585
|
+
await mailAcross.rows(p.rows, { hub: hub.id });
|
|
152454
153586
|
return { ok: true };
|
|
152455
153587
|
},
|
|
152456
153588
|
"host.activity": async () => {
|
|
@@ -153885,11 +155017,11 @@ var AgentVersionService = class {
|
|
|
153885
155017
|
}
|
|
153886
155018
|
async read() {
|
|
153887
155019
|
const tools = this.deps.tools().filter((t) => t.installedVersion);
|
|
153888
|
-
const
|
|
153889
|
-
const installed = Object.fromEntries(
|
|
155020
|
+
const read2 = await Promise.all(tools.map(async (t) => [t.tool, await t.installedVersion().catch(() => null)]));
|
|
155021
|
+
const installed = Object.fromEntries(read2);
|
|
153890
155022
|
const seen = this.deps.readSeen();
|
|
153891
155023
|
const nextSeen = { ...seen };
|
|
153892
|
-
for (const [tool, version2] of
|
|
155024
|
+
for (const [tool, version2] of read2) {
|
|
153893
155025
|
if (!version2) continue;
|
|
153894
155026
|
const before = seen[tool];
|
|
153895
155027
|
if (before && before !== version2) {
|
|
@@ -154265,7 +155397,7 @@ var HostRequests = class {
|
|
|
154265
155397
|
case "trash.purgeSubagentSteps":
|
|
154266
155398
|
return this.viaTrash(method, from, signal, { action: "delete", sessionId: str5(p.sessionId), what: "steps" }, () => ({ ok: true }));
|
|
154267
155399
|
case "trash.empty":
|
|
154268
|
-
return this.viaTrash(method, from, signal, { action: "empty" }, (purged, text3,
|
|
155400
|
+
return this.viaTrash(method, from, signal, { action: "empty" }, (purged, text3, failed4) => ({ purged, failed: failed4, text: text3 }));
|
|
154269
155401
|
default:
|
|
154270
155402
|
return this.generic(method, params, from, signal);
|
|
154271
155403
|
}
|
|
@@ -154350,7 +155482,7 @@ var HostRequests = class {
|
|
|
154350
155482
|
}
|
|
154351
155483
|
});
|
|
154352
155484
|
let purged = 0;
|
|
154353
|
-
const
|
|
155485
|
+
const failed4 = [];
|
|
154354
155486
|
const names = /* @__PURE__ */ new Map();
|
|
154355
155487
|
flow.useRpc(async (m, p) => {
|
|
154356
155488
|
try {
|
|
@@ -154361,7 +155493,7 @@ var HostRequests = class {
|
|
|
154361
155493
|
} catch (e) {
|
|
154362
155494
|
if (m === "trash.purge") {
|
|
154363
155495
|
const sessionId = str5(fields3(p).sessionId);
|
|
154364
|
-
|
|
155496
|
+
failed4.push({ sessionId, name: names.get(sessionId) ?? sessionId, error: e instanceof Error ? e.message : String(e) });
|
|
154365
155497
|
}
|
|
154366
155498
|
throw e;
|
|
154367
155499
|
}
|
|
@@ -154372,7 +155504,7 @@ var HostRequests = class {
|
|
|
154372
155504
|
if (ended2 && (ended2.outcome === "too_many_requests" || ended2.outcome === "no_window")) throw unanswered(method, ended2.outcome);
|
|
154373
155505
|
throw rpcError(answer.error, "internal", { data: { refused: ended2 && ended2.decision !== "allow" ? refusalOf(ended2.outcome) : "not_done" } });
|
|
154374
155506
|
}
|
|
154375
|
-
return result(purged, answer.text,
|
|
155507
|
+
return result(purged, answer.text, failed4);
|
|
154376
155508
|
}
|
|
154377
155509
|
/** Raises one card and waits for its answer, its time, or its caller going away */
|
|
154378
155510
|
card(method, question, from, signal) {
|
|
@@ -154683,10 +155815,10 @@ var Gate = class {
|
|
|
154683
155815
|
|
|
154684
155816
|
// packages/agent-host/src/lifecycle/steps.ts
|
|
154685
155817
|
function runSteps(steps, log) {
|
|
154686
|
-
let
|
|
155818
|
+
let failed4 = null;
|
|
154687
155819
|
const fail4 = (step, err) => {
|
|
154688
|
-
if (
|
|
154689
|
-
else
|
|
155820
|
+
if (failed4) log(`[agent-host] ${step.name} failed on the way out as well: ${describe3(err)}`);
|
|
155821
|
+
else failed4 = { err };
|
|
154690
155822
|
};
|
|
154691
155823
|
const from = (i) => {
|
|
154692
155824
|
for (; i < steps.length; i++) {
|
|
@@ -154709,7 +155841,7 @@ function runSteps(steps, log) {
|
|
|
154709
155841
|
);
|
|
154710
155842
|
}
|
|
154711
155843
|
}
|
|
154712
|
-
return
|
|
155844
|
+
return failed4 ? Promise.reject(failed4.err) : Promise.resolve();
|
|
154713
155845
|
};
|
|
154714
155846
|
return from(0);
|
|
154715
155847
|
}
|
|
@@ -155022,9 +156154,9 @@ async function runningHeld(io2) {
|
|
|
155022
156154
|
if (!Array.isArray(answer.children)) return { unknown: "the keeper answered without a list of its children" };
|
|
155023
156155
|
const listed2 = [];
|
|
155024
156156
|
for (const c of answer.children) {
|
|
155025
|
-
const
|
|
155026
|
-
if (!
|
|
155027
|
-
listed2.push(
|
|
156157
|
+
const read2 = childOf(c);
|
|
156158
|
+
if (!read2) return { unknown: "the keeper listed a child that cannot be read" };
|
|
156159
|
+
listed2.push(read2);
|
|
155028
156160
|
}
|
|
155029
156161
|
return { running: listed2.filter((c) => c.exit === null) };
|
|
155030
156162
|
}
|
|
@@ -155035,7 +156167,7 @@ function sessionGroups(rows3, shell, self2) {
|
|
|
155035
156167
|
return rows3.filter((r) => r.tty === leader.tty && r.pgid > 1 && r.pid !== self2 && r.pgid !== own?.pgid);
|
|
155036
156168
|
}
|
|
155037
156169
|
var groupsOf2 = (rows3) => [...new Set(rows3.map((r) => r.pgid))];
|
|
155038
|
-
var
|
|
156170
|
+
var named2 = (cs2) => cs2.map((c) => `${c.id} pid ${c.pid}`).join(", ");
|
|
155039
156171
|
async function endHeld(io2, log, opts = {}) {
|
|
155040
156172
|
const sleep4 = opts.sleep ?? ((ms3) => new Promise((r) => setTimeout(r, ms3)));
|
|
155041
156173
|
const first = await runningHeld(io2);
|
|
@@ -155045,7 +156177,7 @@ async function endHeld(io2, log, opts = {}) {
|
|
|
155045
156177
|
}
|
|
155046
156178
|
const held2 = first.running;
|
|
155047
156179
|
if (held2.length === 0) return { ended: 0, left: 0, strays: 0 };
|
|
155048
|
-
log(`[agent-host] the keeper still holds ${held2.length} process(es) a host of an earlier build gave it: ending them (${
|
|
156180
|
+
log(`[agent-host] the keeper still holds ${held2.length} process(es) a host of an earlier build gave it: ending them (${named2(held2)})`);
|
|
155049
156181
|
const terminals2 = held2.filter((c) => c.kind === "pty").map((c) => c.pid);
|
|
155050
156182
|
const members = (rows3) => terminals2.flatMap((t) => sessionGroups(rows3, t, io2.self));
|
|
155051
156183
|
const seen = members(io2.processes());
|
|
@@ -155087,7 +156219,7 @@ async function endHeld(io2, log, opts = {}) {
|
|
|
155087
156219
|
left = await running2();
|
|
155088
156220
|
stray = strays();
|
|
155089
156221
|
}
|
|
155090
|
-
if (left.length > 0) log(`[agent-host] ${left.length} process(es) the keeper holds did not end: ${
|
|
156222
|
+
if (left.length > 0) log(`[agent-host] ${left.length} process(es) the keeper holds did not end: ${named2(left)}`);
|
|
155091
156223
|
if (stray.length > 0) log(`[agent-host] ${stray.length} process(es) of their terminals did not end: ${stray.map((s) => `pid ${s.pid}`).join(", ")}`);
|
|
155092
156224
|
return { ended: held2.length - left.length, left: left.length, strays: stray.length };
|
|
155093
156225
|
}
|
|
@@ -156468,7 +157600,7 @@ function readSshConfig(opts) {
|
|
|
156468
157600
|
const matches2 = [];
|
|
156469
157601
|
const where2 = (file2, line) => `${tildePath(file2, opts.home)}:${line}`;
|
|
156470
157602
|
const reading = [];
|
|
156471
|
-
const
|
|
157603
|
+
const read2 = (file2, depth) => {
|
|
156472
157604
|
if (reading.includes(file2)) {
|
|
156473
157605
|
notes.push(`${tildePath(file2, opts.home)} includes itself; it was read once`);
|
|
156474
157606
|
return;
|
|
@@ -156505,13 +157637,13 @@ function readSshConfig(opts) {
|
|
|
156505
157637
|
notes.push(`An Include of another user's folder (${where2(file2, n + 1)}) was not read`);
|
|
156506
157638
|
continue;
|
|
156507
157639
|
} else if (!isAbsolute10(path2)) path2 = join58(opts.home, ".ssh", path2);
|
|
156508
|
-
for (const f of expandGlob(path2))
|
|
157640
|
+
for (const f of expandGlob(path2)) read2(f, depth + 1);
|
|
156509
157641
|
}
|
|
156510
157642
|
}
|
|
156511
157643
|
}
|
|
156512
157644
|
reading.pop();
|
|
156513
157645
|
};
|
|
156514
|
-
|
|
157646
|
+
read2(opts.file, 0);
|
|
156515
157647
|
if (matches2.length > 0) {
|
|
156516
157648
|
notes.push(`${matches2.length === 1 ? "A Match block" : `${matches2.length} Match blocks`} (${matches2.join(", ")}) ${matches2.length === 1 ? "is" : "are"} not listed; ssh still applies ${matches2.length === 1 ? "it" : "them"}`);
|
|
156517
157649
|
}
|
|
@@ -156552,10 +157684,10 @@ var RESOLVE_AT_ONCE = 8;
|
|
|
156552
157684
|
async function listSshHosts(opts = {}) {
|
|
156553
157685
|
const home = opts.home ?? homedir18();
|
|
156554
157686
|
const file2 = opts.configFile ?? join58(home, ".ssh", "config");
|
|
156555
|
-
const
|
|
156556
|
-
const notes = [...
|
|
156557
|
-
const listed2 =
|
|
156558
|
-
if (
|
|
157687
|
+
const read2 = readSshConfig({ file: file2, home });
|
|
157688
|
+
const notes = [...read2.notes];
|
|
157689
|
+
const listed2 = read2.hosts.slice(0, MAX_HOSTS);
|
|
157690
|
+
if (read2.hosts.length > MAX_HOSTS) notes.push(`Only the first ${MAX_HOSTS} of ${read2.hosts.length} hosts are listed; type any other below`);
|
|
156559
157691
|
const resolve21 = opts.resolve ?? ((alias) => resolveAlias(alias, opts));
|
|
156560
157692
|
const resolved = new Array(listed2.length);
|
|
156561
157693
|
let next = 0;
|
|
@@ -156566,8 +157698,8 @@ async function listSshHosts(opts = {}) {
|
|
|
156566
157698
|
}
|
|
156567
157699
|
};
|
|
156568
157700
|
await Promise.all(Array.from({ length: Math.min(RESOLVE_AT_ONCE, listed2.length) }, worker));
|
|
156569
|
-
const
|
|
156570
|
-
if (
|
|
157701
|
+
const failed4 = resolved.filter((r) => r.error);
|
|
157702
|
+
if (failed4.length > 0 && failed4.length === resolved.length) notes.push(`ssh -G could not resolve the hosts: ${failed4[0].error}`);
|
|
156571
157703
|
return {
|
|
156572
157704
|
configFile: tildePath(file2, home),
|
|
156573
157705
|
hosts: listed2.map((h, i) => ({ ...h, hostName: resolved[i].hostName, user: resolved[i].user, port: resolved[i].port })),
|
|
@@ -157287,12 +158419,12 @@ function compareVersions(hub, remote, accepted) {
|
|
|
157287
158419
|
const remoteRelease = releaseOf(remote.version);
|
|
157288
158420
|
const sameChannel = channel(hubRelease) === channel(remoteRelease);
|
|
157289
158421
|
const dev = hub.dev || remote.dev;
|
|
157290
|
-
let
|
|
158422
|
+
let older3 = null;
|
|
157291
158423
|
if (!dev && sameChannel && hubRelease !== remoteRelease) {
|
|
157292
|
-
|
|
158424
|
+
older3 = isNewerVersion(hubRelease, remoteRelease) ? "remote" : isNewerVersion(remoteRelease, hubRelease) ? "hub" : null;
|
|
157293
158425
|
}
|
|
157294
|
-
const compatible = hub.protocolVersion === remote.protocolVersion && !(
|
|
157295
|
-
return { hub, remote, older:
|
|
158426
|
+
const compatible = hub.protocolVersion === remote.protocolVersion && !(older3 === "remote" && !isSupportedVersion(remote.version));
|
|
158427
|
+
return { hub, remote, older: older3, compatible, sameChannel, accepted: compatible && accepted };
|
|
157296
158428
|
}
|
|
157297
158429
|
function heldOnMinimum(v) {
|
|
157298
158430
|
return !v.compatible && v.hub.protocolVersion === v.remote.protocolVersion;
|
|
@@ -157322,8 +158454,8 @@ var NO_ANSWER2 = new RegExp(
|
|
|
157322
158454
|
"i"
|
|
157323
158455
|
);
|
|
157324
158456
|
function isNoAnswer(message) {
|
|
157325
|
-
const
|
|
157326
|
-
return
|
|
158457
|
+
const failed4 = SSH_FAILED.exec(message);
|
|
158458
|
+
return failed4 !== null && NO_ANSWER2.test(message.slice(failed4[0].length).trim());
|
|
157327
158459
|
}
|
|
157328
158460
|
|
|
157329
158461
|
// packages/agent-host/src/links/update.ts
|
|
@@ -157895,8 +159027,8 @@ var LinkedMachineConnection = class {
|
|
|
157895
159027
|
const gone = told.slice(0, OTHER_CREDENTIALS_SHOWN).map(({ check: _check2, own: _own, ...c }) => ({ ...c, hubsName: !!line?.pairedAs && c.label === line.pairedAs }));
|
|
157896
159028
|
return { otherCredentials: gone.length ? gone : null, otherCredentialsMore: 0, ownCredentialGone: this.ownCredentialTaken, credentialFileUnreadable };
|
|
157897
159029
|
}
|
|
157898
|
-
const
|
|
157899
|
-
const others = [...all, ...this.notPairedHere(line, all), ...told.filter((c) => !
|
|
159030
|
+
const named3 = new Set(all.filter((c) => c.own !== true).map((c) => c.id));
|
|
159031
|
+
const others = [...all, ...this.notPairedHere(line, all), ...told.filter((c) => !named3.has(c.id))].filter((c) => !this.isCurrent(c, line) && !this.revokedHere.has(c.id));
|
|
157900
159032
|
const shown3 = others.slice(0, OTHER_CREDENTIALS_SHOWN).map(({ check: _check2, own: _own, ...c }) => ({ ...c, hubsName: !!line.pairedAs && c.label === line.pairedAs }));
|
|
157901
159033
|
const ownGone = this.credentials !== null && !!line.credential && !this.credentials.some((c) => this.isCurrent(c, line) && !c.gone);
|
|
157902
159034
|
const more = others.slice(OTHER_CREDENTIALS_SHOWN).filter((c) => !c.gone).length;
|
|
@@ -157963,8 +159095,8 @@ var LinkedMachineConnection = class {
|
|
|
157963
159095
|
if (!line.pairedAs) return [];
|
|
157964
159096
|
const first = this.usedUnderHubLabels.findIndex((u) => this.isPairedHere(u));
|
|
157965
159097
|
if (first < 0) return [];
|
|
157966
|
-
const
|
|
157967
|
-
return this.usedUnderHubLabels.slice(first).filter((u) => u.label === line.pairedAs && !this.isPairedHere(u) && !
|
|
159098
|
+
const named3 = new Set(listed2.map((c) => this.keyOf(c)));
|
|
159099
|
+
return this.usedUnderHubLabels.slice(first).filter((u) => u.label === line.pairedAs && !this.isPairedHere(u) && !named3.has(this.keyOf(u))).map((u) => ({ id: u.id, label: u.label, created: u.created, replaced: false, gone: true, ...u.check ? { check: u.check } : {}, ...u.own !== void 0 ? { own: u.own } : {} }));
|
|
157968
159100
|
}
|
|
157969
159101
|
/**
|
|
157970
159102
|
* The machine's host says a full credential said hello there (#1712, `host_credential_used`). Not this hub's own (the
|
|
@@ -157986,22 +159118,22 @@ var LinkedMachineConnection = class {
|
|
|
157986
159118
|
if (this.reportedUsed.some((r) => r.key === key)) return;
|
|
157987
159119
|
const seq = ++this.reportSeq;
|
|
157988
159120
|
this.reportedUsed = [...this.reportedUsed, { key, seq, settled: false, answered: false, credential: { id: c.id, label: c.label, created: c.created, replaced: c.replaced, gone: true, own: false } }].slice(-REPORTED_USED_KEPT);
|
|
157989
|
-
const
|
|
159121
|
+
const read2 = this.readCredentials;
|
|
157990
159122
|
const settle = () => {
|
|
157991
159123
|
const entry = this.reportedUsed.find((r) => r.seq === seq);
|
|
157992
159124
|
if (!entry) return;
|
|
157993
159125
|
entry.settled = true;
|
|
157994
159126
|
this.deps.broadcast({ type: "machine_status", machine: this.info() });
|
|
157995
159127
|
};
|
|
157996
|
-
if (!
|
|
157997
|
-
void this.readForReported(
|
|
159128
|
+
if (!read2) return settle();
|
|
159129
|
+
void this.readForReported(read2).then(settle, settle);
|
|
157998
159130
|
}
|
|
157999
159131
|
/**
|
|
158000
159132
|
* A read that began after the event that asks for it (`credentialUsed`). Events that come while one is under way ask
|
|
158001
159133
|
* for one more after it, not one each: a burst of first uses costs the machine's host one read in flight and one
|
|
158002
159134
|
* waiting, and no more
|
|
158003
159135
|
*/
|
|
158004
|
-
readForReported(
|
|
159136
|
+
readForReported(read2) {
|
|
158005
159137
|
if (this.reportRead) {
|
|
158006
159138
|
this.reportReadAgain = true;
|
|
158007
159139
|
return this.reportRead;
|
|
@@ -158009,7 +159141,7 @@ var LinkedMachineConnection = class {
|
|
|
158009
159141
|
const run4 = async () => {
|
|
158010
159142
|
do {
|
|
158011
159143
|
this.reportReadAgain = false;
|
|
158012
|
-
await
|
|
159144
|
+
await read2();
|
|
158013
159145
|
} while (this.reportReadAgain);
|
|
158014
159146
|
};
|
|
158015
159147
|
const p = run4().finally(() => {
|
|
@@ -158029,9 +159161,9 @@ var LinkedMachineConnection = class {
|
|
|
158029
159161
|
this.fileUnreadable = false;
|
|
158030
159162
|
const stop2 = () => {
|
|
158031
159163
|
clearInterval(this.credentialsTimer);
|
|
158032
|
-
if (this.readCredentials ===
|
|
159164
|
+
if (this.readCredentials === read2) this.readCredentials = null;
|
|
158033
159165
|
};
|
|
158034
|
-
const
|
|
159166
|
+
const read2 = async () => {
|
|
158035
159167
|
if (this.client !== client || !client.connected) return stop2();
|
|
158036
159168
|
const startedAt = Date.now();
|
|
158037
159169
|
const told = this.reportSeq;
|
|
@@ -158064,9 +159196,9 @@ var LinkedMachineConnection = class {
|
|
|
158064
159196
|
this.deps.log?.(`[links] ${this.name}: could not read its full credentials: ${err instanceof Error ? err.message : String(err)}`);
|
|
158065
159197
|
}
|
|
158066
159198
|
};
|
|
158067
|
-
this.readCredentials =
|
|
158068
|
-
void
|
|
158069
|
-
this.credentialsTimer = setInterval(() => void
|
|
159199
|
+
this.readCredentials = read2;
|
|
159200
|
+
void read2();
|
|
159201
|
+
this.credentialsTimer = setInterval(() => void read2(), this.deps.credentialsMs ?? CREDENTIALS_MS);
|
|
158070
159202
|
this.credentialsTimer.unref?.();
|
|
158071
159203
|
}
|
|
158072
159204
|
// ── The reverse direction (#550) ──────────────────────────────────────────────────────────
|
|
@@ -158087,7 +159219,10 @@ var LinkedMachineConnection = class {
|
|
|
158087
159219
|
/**
|
|
158088
159220
|
* Tells the machine who this hub is and whether its sessions may ask this hub's projects (`host.hubOffer`), so the
|
|
158089
159221
|
* machine knows the connection to call back on. Said off too, so a machine that heard "on" earlier in its own life
|
|
158090
|
-
* stops offering this hub to its sessions. A machine that could not be told says so on the row, while the switch is on
|
|
159222
|
+
* stops offering this hub to its sessions. A machine that could not be told says so on the row, while the switch is on.
|
|
159223
|
+
* `mail`: every session there may mail every session this hub reaches (#2067), switch or not; `you` is the machine's id
|
|
159224
|
+
* here, by which it reads this hub's names for its own sessions. The machine's answer says whether it takes mail back
|
|
159225
|
+
* (`takesMail`)
|
|
158091
159226
|
*/
|
|
158092
159227
|
async offerAsks(client) {
|
|
158093
159228
|
const self2 = this.deps.hubSelf?.();
|
|
@@ -158095,7 +159230,9 @@ var LinkedMachineConnection = class {
|
|
|
158095
159230
|
const on2 = this.record.asks === true;
|
|
158096
159231
|
let note = null;
|
|
158097
159232
|
try {
|
|
158098
|
-
await client.call("host.hubOffer", { hub: self2, on: on2 });
|
|
159233
|
+
const answer = await client.call("host.hubOffer", { hub: self2, on: on2, ...this.deps.hubMail ? { mail: true, you: this.id } : {} });
|
|
159234
|
+
if (this.client === client) this.mailBack = isObj(answer) && answer.mail === true;
|
|
159235
|
+
if (this.client === client && this.mailBack) this.deps.mailReady?.(this.id);
|
|
158099
159236
|
} catch (err) {
|
|
158100
159237
|
if (on2) note = `${this.name} could not be told yet (${err.message}); it is told again at the next connect`;
|
|
158101
159238
|
}
|
|
@@ -158126,10 +159263,15 @@ var LinkedMachineConnection = class {
|
|
|
158126
159263
|
async withdrawOffer() {
|
|
158127
159264
|
const self2 = this.deps.hubSelf?.();
|
|
158128
159265
|
const client = this.client;
|
|
158129
|
-
if (!self2 || !client || !this.reachable || this.record.asks !== true) return;
|
|
159266
|
+
if (!self2 || !client || !this.reachable || this.record.asks !== true && !this.deps.hubMail) return;
|
|
158130
159267
|
await client.call("host.hubOffer", { hub: self2, on: false }).catch(() => {
|
|
158131
159268
|
});
|
|
158132
159269
|
}
|
|
159270
|
+
/** Whether the machine said, at this connection's offer, that it takes mail from this hub (`host.mail`, #2067 item 2) */
|
|
159271
|
+
mailBack = false;
|
|
159272
|
+
get takesMail() {
|
|
159273
|
+
return this.mailBack;
|
|
159274
|
+
}
|
|
158133
159275
|
// ── RoutedMachine ───────────────────────────────────────────────────────────────────────
|
|
158134
159276
|
call(method, params) {
|
|
158135
159277
|
if (!this.client) return Promise.reject(rpcError(`${this.name} is not reachable right now`, "internal", { retryable: true }));
|
|
@@ -158290,10 +159432,10 @@ var LinkedMachineConnection = class {
|
|
|
158290
159432
|
const last = endpoint.line.install?.lastSwitch;
|
|
158291
159433
|
const news = last === void 0 ? this.switchUnread : !!last && (!last.ended || !last.seen);
|
|
158292
159434
|
const asked = managed && (!endpoint.line.hostRunning || news);
|
|
158293
|
-
const
|
|
158294
|
-
if (asked &&
|
|
158295
|
-
if (
|
|
158296
|
-
const sw2 =
|
|
159435
|
+
const read2 = asked ? await this.switchThere() : null;
|
|
159436
|
+
if (asked && read2 !== void 0) this.switchUnread = !!read2 && !read2.outcome;
|
|
159437
|
+
if (read2 && !read2.outcome && read2.by !== thisHubName()) this.switchWatched = read2.id;
|
|
159438
|
+
const sw2 = read2 ?? null;
|
|
158297
159439
|
if (this.stopped) return;
|
|
158298
159440
|
if (sw2?.outcome && !sw2.seen) this.noteSwitch(sw2);
|
|
158299
159441
|
if (endpoint.line.hostRunning) {
|
|
@@ -158369,11 +159511,11 @@ var LinkedMachineConnection = class {
|
|
|
158369
159511
|
* A start there went through, or started a host that never answered: it counts, and it spends the person's Start.
|
|
158370
159512
|
* `failed`: what the start said when its host never answered, kept for the row should the link stop starting them
|
|
158371
159513
|
*/
|
|
158372
|
-
countStart(
|
|
159514
|
+
countStart(failed4 = null) {
|
|
158373
159515
|
this.startAsked = false;
|
|
158374
159516
|
this.heldBack = null;
|
|
158375
159517
|
this.autoStarts.push(Date.now());
|
|
158376
|
-
this.lastStartFailure =
|
|
159518
|
+
this.lastStartFailure = failed4;
|
|
158377
159519
|
}
|
|
158378
159520
|
/**
|
|
158379
159521
|
* Why the link starts no host there just now, or null (#1143): the person stopped it there, or the link reached its
|
|
@@ -158730,14 +159872,14 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
158730
159872
|
* again at once, and finds the managed launcher first
|
|
158731
159873
|
*/
|
|
158732
159874
|
async install() {
|
|
158733
|
-
const
|
|
158734
|
-
return this.operate("install",
|
|
158735
|
-
if (
|
|
159875
|
+
const pick5 = await this.versionToInstall();
|
|
159876
|
+
return this.operate("install", pick5.version, async (c, installer) => {
|
|
159877
|
+
if (pick5.note) this.deps.log?.(`[links] ${this.name}: ${pick5.note}`);
|
|
158736
159878
|
const r = await installRemote({
|
|
158737
159879
|
exec: c.exec,
|
|
158738
159880
|
spec: c.spec,
|
|
158739
159881
|
target: c.target,
|
|
158740
|
-
version:
|
|
159882
|
+
version: pick5.version,
|
|
158741
159883
|
runtime: installer.runtime(),
|
|
158742
159884
|
script: c.script,
|
|
158743
159885
|
registry: installer.registry,
|
|
@@ -158746,7 +159888,7 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
158746
159888
|
});
|
|
158747
159889
|
this.removedByPerson = false;
|
|
158748
159890
|
this.deps.log?.(`[links] ${this.name}: installed Centralu ${r.current.version} on Node ${r.current.node}${r.previous ? `; ${r.previous.version} kept to roll back to` : ""}`);
|
|
158749
|
-
return { ...this.installedNow(r), ...
|
|
159891
|
+
return { ...this.installedNow(r), ...pick5.note ? { note: pick5.note } : {} };
|
|
158750
159892
|
});
|
|
158751
159893
|
}
|
|
158752
159894
|
/**
|
|
@@ -158761,22 +159903,22 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
158761
159903
|
}
|
|
158762
159904
|
async updateNow(opts) {
|
|
158763
159905
|
if (opts.unasked === true) await this.probeActivity();
|
|
158764
|
-
const
|
|
159906
|
+
const pick5 = await this.versionToInstall();
|
|
158765
159907
|
const there = this.versions?.remote.version;
|
|
158766
|
-
if (there && releaseOf(there) !==
|
|
158767
|
-
throw linkError2(`${this.name} runs Centralu ${there}, newer than ${
|
|
159908
|
+
if (there && releaseOf(there) !== pick5.version && isNewerVersion(there, pick5.version)) {
|
|
159909
|
+
throw linkError2(`${this.name} runs Centralu ${there}, newer than ${pick5.version}, the version this computer would install; updating would downgrade it, so nothing was changed`);
|
|
158768
159910
|
}
|
|
158769
|
-
return this.operate("update",
|
|
158770
|
-
if (
|
|
159911
|
+
return this.operate("update", pick5.version, async (c, installer) => {
|
|
159912
|
+
if (pick5.note) this.deps.log?.(`[links] ${this.name}: ${pick5.note}`);
|
|
158771
159913
|
c.beforeStop = () => this.beforeStop(c, opts.when ?? "idle", opts.unasked === true);
|
|
158772
159914
|
const r = await updateRemote(c, {
|
|
158773
|
-
version:
|
|
159915
|
+
version: pick5.version,
|
|
158774
159916
|
runtime: installer.runtime(),
|
|
158775
159917
|
registry: installer.registry,
|
|
158776
159918
|
nodeDist: installer.nodeDist
|
|
158777
159919
|
});
|
|
158778
159920
|
this.deps.log?.(`[links] ${this.name}: updated to Centralu ${r.current.version}${r.previous ? `; ${r.previous.version} kept to roll back to` : ""}`);
|
|
158779
|
-
const note = [
|
|
159921
|
+
const note = [pick5.note, r.note].filter(Boolean).join(" ");
|
|
158780
159922
|
return { ...this.installedNow(r), ...note ? { note } : {} };
|
|
158781
159923
|
});
|
|
158782
159924
|
}
|
|
@@ -158811,7 +159953,7 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
158811
159953
|
this.idleWait = wait;
|
|
158812
159954
|
const poll = this.deps.activityPollMs ?? ACTIVITY_POLL_MS2;
|
|
158813
159955
|
const settle = Math.min(poll, ACTIVITY_SETTLE_MS);
|
|
158814
|
-
const
|
|
159956
|
+
const read2 = async () => {
|
|
158815
159957
|
wait.signal.throwIfAborted();
|
|
158816
159958
|
const r = await this.readActivity();
|
|
158817
159959
|
wait.signal.throwIfAborted();
|
|
@@ -158828,28 +159970,28 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
158828
159970
|
c.step(step, count);
|
|
158829
159971
|
this.deps.log?.(`[links] ${this.name}: ${why2}`);
|
|
158830
159972
|
};
|
|
158831
|
-
const
|
|
159973
|
+
const unread3 = () => show("wait_unread", "what runs there cannot be read now; the update keeps waiting, since the sessions there may be in a turn (Cancel ends it)");
|
|
158832
159974
|
const busy = (a) => {
|
|
158833
159975
|
const turns = turnsRunning(a);
|
|
158834
159976
|
show("wait_idle", `the update waits for ${turns} ${turns === 1 ? "session" : "sessions"} in a turn`, turns);
|
|
158835
159977
|
};
|
|
158836
159978
|
for (; ; ) {
|
|
158837
|
-
const r = await
|
|
159979
|
+
const r = await read2();
|
|
158838
159980
|
if (r.activity) {
|
|
158839
159981
|
seen = true;
|
|
158840
159982
|
blind = 0;
|
|
158841
159983
|
if (turnsRunning(r.activity) === 0) {
|
|
158842
159984
|
await sleep(settle, wait.signal, { unref: true });
|
|
158843
|
-
const again = await
|
|
159985
|
+
const again = await read2();
|
|
158844
159986
|
if (again.activity && turnsRunning(again.activity) === 0) {
|
|
158845
159987
|
if (shown3) c.step("stop");
|
|
158846
159988
|
return null;
|
|
158847
159989
|
}
|
|
158848
159990
|
if (again.activity) busy(again.activity);
|
|
158849
|
-
else
|
|
159991
|
+
else unread3();
|
|
158850
159992
|
} else busy(r.activity);
|
|
158851
159993
|
} else if (seen) {
|
|
158852
|
-
|
|
159994
|
+
unread3();
|
|
158853
159995
|
} else if (r.cannot || ++blind > ACTIVITY_UNREAD_RETRIES) {
|
|
158854
159996
|
this.deps.log?.(`[links] ${this.name}: it cannot be told what runs there, so the update does not wait for it`);
|
|
158855
159997
|
return null;
|
|
@@ -159124,12 +160266,12 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
159124
160266
|
* link held on another protocol, a host from before `host.activity`), as against an answer that failed, which may be asked again
|
|
159125
160267
|
*/
|
|
159126
160268
|
readActivity() {
|
|
159127
|
-
const
|
|
160269
|
+
const read2 = (r) => {
|
|
159128
160270
|
const p = HostActivity.safeParse(r);
|
|
159129
160271
|
return { activity: p.success ? p.data : null, cannot: false };
|
|
159130
160272
|
};
|
|
159131
|
-
const
|
|
159132
|
-
if (this.client?.connected) return this.client.call("host.activity", {}).then(
|
|
160273
|
+
const failed4 = (err) => ({ activity: null, cannot: /^Unknown method/.test(errorMessage(err)) });
|
|
160274
|
+
if (this.client?.connected) return this.client.call("host.activity", {}).then(read2, failed4);
|
|
159133
160275
|
const e = this.endpoint;
|
|
159134
160276
|
const otherProtocol = this.versions?.compatible === false && !heldOnMinimum(this.versions);
|
|
159135
160277
|
if (!e?.url || otherProtocol || this.held) return Promise.resolve({ activity: null, cannot: true });
|
|
@@ -159144,7 +160286,7 @@ var LinkedMachine = class extends LinkedMachineConnection {
|
|
|
159144
160286
|
};
|
|
159145
160287
|
const client = new RemoteClient(
|
|
159146
160288
|
{ ...this.deps.client, url: e.url, token: e.token, proveHost: e.line.proof === true, handshakeTimeoutMs: 5e3, callTimeoutMs: 5e3 },
|
|
159147
|
-
{ hello: () => void client.call("host.activity", {}).then(
|
|
160289
|
+
{ hello: () => void client.call("host.activity", {}).then(read2, failed4).then(done2), refused: () => done2({ activity: null, cannot: false }) }
|
|
159148
160290
|
);
|
|
159149
160291
|
const timer = setTimeout(() => done2({ activity: null, cannot: false }), 8e3);
|
|
159150
160292
|
client.connect();
|
|
@@ -159340,12 +160482,12 @@ var Links = class {
|
|
|
159340
160482
|
* same alias, typed exactly so (an alias is what `machines.add` stores as the target)
|
|
159341
160483
|
*/
|
|
159342
160484
|
async sshHosts() {
|
|
159343
|
-
const
|
|
160485
|
+
const read2 = await listSshHosts(this.deps.ssh ?? {});
|
|
159344
160486
|
const linked = this.list();
|
|
159345
160487
|
return {
|
|
159346
|
-
configFile:
|
|
159347
|
-
notes:
|
|
159348
|
-
hosts:
|
|
160488
|
+
configFile: read2.configFile,
|
|
160489
|
+
notes: read2.notes,
|
|
160490
|
+
hosts: read2.hosts.map((h) => ({
|
|
159349
160491
|
alias: h.alias,
|
|
159350
160492
|
hostName: h.hostName,
|
|
159351
160493
|
user: h.user,
|
|
@@ -159593,6 +160735,7 @@ function linkedSessions(machines, route = notRouted, hubName2, options = {}) {
|
|
|
159593
160735
|
const rows3 = (m, answer) => {
|
|
159594
160736
|
if (!Array.isArray(answer)) return [];
|
|
159595
160737
|
const out = [];
|
|
160738
|
+
const cut3 = interruptions(m);
|
|
159596
160739
|
for (const raw of answer) {
|
|
159597
160740
|
const r = HostSessionRow.safeParse(raw);
|
|
159598
160741
|
if (!r.success || !SessionId.safeParse(r.data.sessionId).success) continue;
|
|
@@ -159607,11 +160750,21 @@ function linkedSessions(machines, route = notRouted, hubName2, options = {}) {
|
|
|
159607
160750
|
...s.pr ? { pr: { number: s.pr.number, state: oneLine4(s.pr.state, 20) } } : {},
|
|
159608
160751
|
preview: s.preview,
|
|
159609
160752
|
...s.lastActive ? { lastActive: oneLine4(s.lastActive, 40) } : {},
|
|
160753
|
+
...cut3.get(s.sessionId) ? { interruption: cut3.get(s.sessionId) } : {},
|
|
159610
160754
|
machine: m.name
|
|
159611
160755
|
});
|
|
159612
160756
|
}
|
|
159613
160757
|
return out;
|
|
159614
160758
|
};
|
|
160759
|
+
const interruptions = (m) => {
|
|
160760
|
+
const out = /* @__PURE__ */ new Map();
|
|
160761
|
+
for (const s of m.lastKnown("sessions") ?? []) {
|
|
160762
|
+
if (!isObj(s) || typeof s.id !== "string") continue;
|
|
160763
|
+
const i = Interruption.safeParse(s.interruption);
|
|
160764
|
+
if (i.success) out.set(s.id, i.data);
|
|
160765
|
+
}
|
|
160766
|
+
return out;
|
|
160767
|
+
};
|
|
159615
160768
|
const lastKnown = (m, away) => {
|
|
159616
160769
|
const projects = /* @__PURE__ */ new Map();
|
|
159617
160770
|
for (const p of m.lastKnown("projects") ?? []) if (isObj(p) && typeof p.id === "string") projects.set(p.id, oneLine4(p.name));
|
|
@@ -159676,12 +160829,12 @@ function linkedSessions(machines, route = notRouted, hubName2, options = {}) {
|
|
|
159676
160829
|
const anyDown = !!need3?.anyDown && bare2;
|
|
159677
160830
|
const prior = need3?.prior;
|
|
159678
160831
|
if (prior && !anyDown) return prior;
|
|
159679
|
-
const
|
|
159680
|
-
const wanted = all.filter((m) => !m.reachable && (anyDown ||
|
|
160832
|
+
const named3 = (m) => !!need3 && needs(m, need3);
|
|
160833
|
+
const wanted = all.filter((m) => !m.reachable && (anyDown || named3(m)));
|
|
159681
160834
|
const parts = await Promise.all(
|
|
159682
160835
|
all.map(async (m) => {
|
|
159683
160836
|
if (wanted.includes(m)) {
|
|
159684
|
-
await (anyDown && !
|
|
160837
|
+
await (anyDown && !named3(m) ? guess(m) : settle(m));
|
|
159685
160838
|
return projectsOf(m, true);
|
|
159686
160839
|
}
|
|
159687
160840
|
if (prior) return { projects: prior.projects.filter((p) => p.machineId === m.id), away: prior.away.filter((a) => a.machineId === m.id) };
|
|
@@ -160317,6 +161470,9 @@ var ROUTES = {
|
|
|
160317
161470
|
"machines.withdrawAsk": HUB,
|
|
160318
161471
|
// A hub offering itself to this host (#550): answered here, never passed on
|
|
160319
161472
|
"host.hubOffer": HUB,
|
|
161473
|
+
// Mail from a hub to this host's sessions, and what became of mail that crossed (#2067 item 2): answered here, never passed on
|
|
161474
|
+
"host.mail": HUB,
|
|
161475
|
+
"host.mailRows": HUB,
|
|
160320
161476
|
// The hub's own answer; a hub asks a remote's through `machines.activity`
|
|
160321
161477
|
"host.activity": HUB,
|
|
160322
161478
|
// The hub's own sessions; the hub's Assistant asks each machine's directly (links/linked-sessions.ts, plan §12)
|
|
@@ -160456,10 +161612,10 @@ var Router = class {
|
|
|
160456
161612
|
else if (target !== m) throw new AcrossMachinesError(method);
|
|
160457
161613
|
}
|
|
160458
161614
|
if (route.orMachine && typeof params.machine === "string") {
|
|
160459
|
-
const
|
|
160460
|
-
if (!
|
|
160461
|
-
if (target === void 0) target =
|
|
160462
|
-
else if (target !==
|
|
161615
|
+
const named3 = this.machineById(params.machine);
|
|
161616
|
+
if (!named3) throw rpcError(`No linked machine ${params.machine}`);
|
|
161617
|
+
if (target === void 0) target = named3;
|
|
161618
|
+
else if (target !== named3) throw new AcrossMachinesError(method);
|
|
160463
161619
|
}
|
|
160464
161620
|
if (!target) return this.opts.local(method, params, ctx);
|
|
160465
161621
|
const { machine: _machine, ...own } = params;
|
|
@@ -160646,8 +161802,8 @@ var Router = class {
|
|
|
160646
161802
|
out = { ...out, sessions: out.sessions.slice().sort((a, b2) => at2(b2) - at2(a)) };
|
|
160647
161803
|
}
|
|
160648
161804
|
if (method === "trash.empty" && missed.length && isObj(out)) {
|
|
160649
|
-
const
|
|
160650
|
-
out = { ...out, failed: [...
|
|
161805
|
+
const failed4 = Array.isArray(out.failed) ? out.failed : [];
|
|
161806
|
+
out = { ...out, failed: [...failed4, ...missed.map((m) => ({ sessionId: m.id, name: m.name, error: "this machine could not be reached, so its archived sessions were not deleted" }))] };
|
|
160651
161807
|
}
|
|
160652
161808
|
if ((method === "trash.list" || method === "subagents.usage") && missed.length && isObj(out)) {
|
|
160653
161809
|
out = { ...out, unreached: missed.map((m) => ({ machineId: m.id, name: m.name })) };
|
|
@@ -160790,29 +161946,50 @@ function storeProjectOrder(store2) {
|
|
|
160790
161946
|
|
|
160791
161947
|
// packages/agent-host/src/links/linked-hubs.ts
|
|
160792
161948
|
var LOOKUP_MS2 = 4e3;
|
|
160793
|
-
var
|
|
161949
|
+
var MAIL_MS = 3e4;
|
|
161950
|
+
var older2 = (err) => /Unknown method/i.test(errorMessage(err));
|
|
160794
161951
|
var LinkedHubs = class {
|
|
160795
161952
|
constructor(deps) {
|
|
160796
161953
|
this.deps = deps;
|
|
160797
161954
|
}
|
|
160798
161955
|
deps;
|
|
160799
161956
|
hubs = /* @__PURE__ */ new Map();
|
|
160800
|
-
/**
|
|
161957
|
+
/** Sessions a hub created on a connection before it offered there, by connection (`awaitOffer`) */
|
|
161958
|
+
waiting = /* @__PURE__ */ new Map();
|
|
161959
|
+
/** Run each time a hub offers mail on a connection (`onMailOffer`) */
|
|
161960
|
+
mailOffered = /* @__PURE__ */ new Set();
|
|
161961
|
+
/** `fn` runs each time a hub offers mail here, at each connect: what crossed while it was away is told then (#2067 review) */
|
|
161962
|
+
onMailOffer(fn2) {
|
|
161963
|
+
this.mailOffered.add(fn2);
|
|
161964
|
+
}
|
|
161965
|
+
/** A hub's offer, on the connection it came in on. Off, and without mail, forgets it */
|
|
160801
161966
|
offer(client, o) {
|
|
160802
|
-
|
|
161967
|
+
const mail = o.mail === true;
|
|
161968
|
+
if (!o.on && !mail) {
|
|
160803
161969
|
this.hubs.delete(o.hub.id);
|
|
160804
161970
|
return;
|
|
160805
161971
|
}
|
|
160806
161972
|
const prev = this.hubs.get(o.hub.id);
|
|
160807
|
-
|
|
161973
|
+
const projects = o.on ? prev?.projects ?? null : null;
|
|
161974
|
+
const name = oneLineText(o.hub.name, 120) || o.hub.id;
|
|
161975
|
+
this.hubs.set(o.hub.id, { id: o.hub.id, name, client, projects, asks: o.on, mail, you: o.you ?? null });
|
|
161976
|
+
const waiting = this.waiting.get(client);
|
|
161977
|
+
this.waiting.delete(client);
|
|
161978
|
+
for (const id3 of waiting ?? []) this.deps.record?.(id3, { id: o.hub.id, name });
|
|
161979
|
+
if (mail) for (const fn2 of this.mailOffered) fn2(o.hub.id);
|
|
161980
|
+
}
|
|
161981
|
+
/** The hubs whose switch for this machine is on: the ones whose projects its sessions may ask */
|
|
161982
|
+
asking() {
|
|
161983
|
+
return [...this.hubs.values()].filter((h) => h.asks);
|
|
160808
161984
|
}
|
|
160809
161985
|
/** A connection ended: a hub it carried is not reachable until it offers again */
|
|
160810
161986
|
gone(client) {
|
|
161987
|
+
this.waiting.delete(client);
|
|
160811
161988
|
for (const h of this.hubs.values()) if (h.client === client) h.client = null;
|
|
160812
161989
|
}
|
|
160813
|
-
/** Whether any hub offered (a session's project list says nothing of hubs otherwise) */
|
|
161990
|
+
/** Whether any hub offered its projects (a session's project list says nothing of hubs otherwise) */
|
|
160814
161991
|
get any() {
|
|
160815
|
-
return this.
|
|
161992
|
+
return this.asking().length > 0;
|
|
160816
161993
|
}
|
|
160817
161994
|
/**
|
|
160818
161995
|
* Every offered hub's projects, asked in parallel and each bounded: a hub that is away contributes the projects it
|
|
@@ -160822,7 +161999,7 @@ var LinkedHubs = class {
|
|
|
160822
161999
|
const projects = [];
|
|
160823
162000
|
const away = [];
|
|
160824
162001
|
await Promise.all(
|
|
160825
|
-
|
|
162002
|
+
this.asking().map(async (h) => {
|
|
160826
162003
|
let why2 = null;
|
|
160827
162004
|
if (h.client === null) why2 = NOT_REACHABLE;
|
|
160828
162005
|
else {
|
|
@@ -160832,7 +162009,7 @@ var LinkedHubs = class {
|
|
|
160832
162009
|
if (parsed.success) h.projects = parsed.data.projects;
|
|
160833
162010
|
else why2 = "its answer could not be read";
|
|
160834
162011
|
} catch (err) {
|
|
160835
|
-
why2 =
|
|
162012
|
+
why2 = older2(err) ? "it runs a Centralu from before this; update it there" : NOT_REACHABLE;
|
|
160836
162013
|
}
|
|
160837
162014
|
}
|
|
160838
162015
|
if (why2) away.push({ hubId: h.id, hub: h.name, why: why2 });
|
|
@@ -160846,15 +162023,15 @@ var LinkedHubs = class {
|
|
|
160846
162023
|
/** One ask into a hub's project (`hub.askProject`), waited on until the hub answers or `signal` withdraws it */
|
|
160847
162024
|
async ask(hubId, params, signal) {
|
|
160848
162025
|
const h = this.hubs.get(hubId);
|
|
160849
|
-
if (!h) return { ok: false, error: "That computer no longer lets this machine ask its projects." };
|
|
162026
|
+
if (!h?.asks) return { ok: false, error: "That computer no longer lets this machine ask its projects." };
|
|
160850
162027
|
if (h.client === null) return { ok: false, error: `${h.name} is ${NOT_REACHABLE}. Try again once its link is back.` };
|
|
160851
162028
|
let raw;
|
|
160852
162029
|
try {
|
|
160853
162030
|
raw = await this.deps.call(h.client, "hub.askProject", params, { signal, ...this.deps.askTimeoutMs ? { timeoutMs: this.deps.askTimeoutMs } : {} });
|
|
160854
162031
|
} catch (err) {
|
|
160855
162032
|
if (signal?.aborted) return { ok: false, error: "The call was cancelled." };
|
|
160856
|
-
if (
|
|
160857
|
-
return { ok: false, error: `${h.name} could not be asked: ${oneLineText(err
|
|
162033
|
+
if (older2(err)) return { ok: false, error: `${h.name} runs a Centralu from before this, so it cannot be asked. Update it there.` };
|
|
162034
|
+
return { ok: false, error: `${h.name} could not be asked: ${oneLineText(errorMessage(err), 500)}` };
|
|
160858
162035
|
}
|
|
160859
162036
|
const parsed = HubAskResult.safeParse(raw);
|
|
160860
162037
|
if (!parsed.success) return { ok: false, error: `${h.name} answered in a form this machine does not read.` };
|
|
@@ -160862,13 +162039,58 @@ var LinkedHubs = class {
|
|
|
160862
162039
|
if (!r.ok) return { ok: false, error: r.error.length > 4e3 ? `${r.error.slice(0, 4e3)}\u2026` : r.error };
|
|
160863
162040
|
return { ...r, project: oneLineText(r.project, 120), sessionName: oneLineText(r.sessionName, 120) };
|
|
160864
162041
|
}
|
|
162042
|
+
/** The hub that offered on this connection, if one did (`startedByHub`: the hub a session it creates here records) */
|
|
162043
|
+
on(client) {
|
|
162044
|
+
for (const h of this.hubs.values()) if (h.client === client) return { id: h.id, name: h.name };
|
|
162045
|
+
return void 0;
|
|
162046
|
+
}
|
|
162047
|
+
/**
|
|
162048
|
+
* A hub that takes mail (#2067), as mail across calls it (`MailAcross`, docs/plans/linked-mail.md §6): on the connection
|
|
162049
|
+
* it offered on and no other. `you`: this machine's id there, which a hub from before item 2 does not say
|
|
162050
|
+
*/
|
|
162051
|
+
peer(hubId) {
|
|
162052
|
+
const h = this.hubs.get(hubId);
|
|
162053
|
+
if (!h) return void 0;
|
|
162054
|
+
return {
|
|
162055
|
+
id: h.id,
|
|
162056
|
+
name: h.name,
|
|
162057
|
+
reachable: h.client !== null,
|
|
162058
|
+
you: h.you,
|
|
162059
|
+
call: (method, params) => {
|
|
162060
|
+
const client = this.hubs.get(hubId)?.client;
|
|
162061
|
+
if (client === null || client === void 0) return Promise.reject(new Error(`${h.name} is ${NOT_REACHABLE}`));
|
|
162062
|
+
return this.deps.call(client, method, params, { timeoutMs: this.deps.mailTimeoutMs ?? MAIL_MS });
|
|
162063
|
+
}
|
|
162064
|
+
};
|
|
162065
|
+
}
|
|
162066
|
+
/** Every hub that takes mail, for a search across them */
|
|
162067
|
+
mailHubs() {
|
|
162068
|
+
return [...this.hubs.values()].flatMap((h) => {
|
|
162069
|
+
const p = h.mail ? this.peer(h.id) : void 0;
|
|
162070
|
+
return p ? [p] : [];
|
|
162071
|
+
});
|
|
162072
|
+
}
|
|
162073
|
+
/**
|
|
162074
|
+
* A session a hub created on this connection before it offered here (item 1's open case): recorded under the hub that
|
|
162075
|
+
* then offers on the connection (`deps.record`), so its `parent` reaches that hub. A connection that ends first forgets it
|
|
162076
|
+
*/
|
|
162077
|
+
awaitOffer(client, sessionId) {
|
|
162078
|
+
this.waiting.set(client, [...this.waiting.get(client) ?? [], sessionId]);
|
|
162079
|
+
}
|
|
160865
162080
|
};
|
|
160866
162081
|
|
|
160867
162082
|
// packages/agent-host/src/links/reverse-calls.ts
|
|
160868
162083
|
function reverseCalls(o) {
|
|
160869
162084
|
return async (machine, method, params, signal) => {
|
|
162085
|
+
const across = o.across;
|
|
162086
|
+
if (across && method === "hub.mail") return across.fromMachine(machine, read(HubMethods["hub.mail"].params.safeParse(params)));
|
|
162087
|
+
if (across && method === "hub.find") return across.answerFind(machine, read(HubMethods["hub.find"].params.safeParse(params)));
|
|
162088
|
+
if (across && method === "hub.mailRows") {
|
|
162089
|
+
await across.rows(read(HubMethods["hub.mailRows"].params.safeParse(params)).rows, { machine: machine.id });
|
|
162090
|
+
return { ok: true };
|
|
162091
|
+
}
|
|
160870
162092
|
if (method !== "hub.projects" && method !== "hub.askProject") {
|
|
160871
|
-
throw rpcError(`Unknown method: ${method}. A linked machine may ask this computer only hub.projects and hub.askProject.`);
|
|
162093
|
+
throw rpcError(`Unknown method: ${method}. A linked machine may ask this computer only hub.projects and hub.askProject${across ? ", and mail with hub.mail, hub.mailRows and hub.find" : ""}.`);
|
|
160872
162094
|
}
|
|
160873
162095
|
if (!o.allowed(machine.id)) {
|
|
160874
162096
|
throw rpcError(`${o.selfName()} does not let sessions on ${machine.name} ask its projects. The person can turn that on in Settings \u2192 Machines on ${o.selfName()}.`);
|
|
@@ -160879,6 +162101,10 @@ function reverseCalls(o) {
|
|
|
160879
162101
|
return o.ask(machine, p.data, signal);
|
|
160880
162102
|
};
|
|
160881
162103
|
}
|
|
162104
|
+
function read(parsed) {
|
|
162105
|
+
if (!parsed.success) throw rpcError("Not a call this computer reads");
|
|
162106
|
+
return parsed.data;
|
|
162107
|
+
}
|
|
160882
162108
|
|
|
160883
162109
|
// packages/agent-host/src/lifecycle/work-job.ts
|
|
160884
162110
|
import { execFile as execFile15 } from "node:child_process";
|
|
@@ -161190,7 +162416,7 @@ var handedToken = launch.tokenOnStdin ? await readHandedToken(process.stdin).cat
|
|
|
161190
162416
|
console.error(`[agent-host] the launcher did not hand over the token: ${e.message}`);
|
|
161191
162417
|
process.exit(1);
|
|
161192
162418
|
}) : launch.token;
|
|
161193
|
-
var BUILD = true ? "
|
|
162419
|
+
var BUILD = true ? "890555e" : "dev";
|
|
161194
162420
|
var { values } = parseArgs({
|
|
161195
162421
|
options: {
|
|
161196
162422
|
port: { type: "string", default: "5175" },
|
|
@@ -161516,6 +162742,9 @@ var links = new Links(linkDepsFor(store, {
|
|
|
161516
162742
|
* on, and the allowlist a machine's call is answered from (ask_project into this computer's projects, nothing else)
|
|
161517
162743
|
*/
|
|
161518
162744
|
hubSelf: () => ({ id: hubSelfId(store), name: hubName() }),
|
|
162745
|
+
hubMail: true,
|
|
162746
|
+
// A machine that took this hub's mail at a connect hears what became of mail that crossed while it was away (#2067 review)
|
|
162747
|
+
mailReady: () => hostMailbox.across.changed(),
|
|
161519
162748
|
// When agents compact: this hub's setting governs the machines it links (#1376)
|
|
161520
162749
|
autoCompact: () => autoCompactOf(mgr.prefs.uiPreferences()),
|
|
161521
162750
|
// Automatic updates cover the linked machines too (#1508): one on an older release follows this hub's version; none starts while this host drains to stop
|
|
@@ -161524,10 +162753,20 @@ var links = new Links(linkDepsFor(store, {
|
|
|
161524
162753
|
allowed: (machineId) => store.machines.linkedMachineAsks(machineId),
|
|
161525
162754
|
projects: () => mgr.projectsForMachines(),
|
|
161526
162755
|
ask: (machine, params, signal) => mgr.machineAsks.ask(machine, params, signal),
|
|
161527
|
-
selfName: hubName
|
|
162756
|
+
selfName: hubName,
|
|
162757
|
+
// Every session on a machine mails every session this hub reaches, and finds them (#2067, docs/plans/linked-mail.md §5 to §8)
|
|
162758
|
+
across: hostMailbox.across
|
|
161528
162759
|
})
|
|
161529
162760
|
}));
|
|
161530
|
-
var hubs = new LinkedHubs({
|
|
162761
|
+
var hubs = new LinkedHubs({
|
|
162762
|
+
call: (client, method, params, opts) => server.call(client, method, params, opts),
|
|
162763
|
+
// A session a hub created here before it offered: recorded under it once it does (#2067)
|
|
162764
|
+
record: (sessionId, hub) => recordStartingHub(store.settings, sessionId, hub)
|
|
162765
|
+
});
|
|
162766
|
+
hostMailbox.across.usePeers(
|
|
162767
|
+
mailPeers({ hostId: hubSelfId(store), selfName: hubName, machines: links, parentOf: (id3) => mgr.linkedHost.remoteAgentParent(id3), hubs, settings: store.settings })
|
|
162768
|
+
);
|
|
162769
|
+
mgr.useMachineMail((id3) => links.get(id3)?.takesMail === true);
|
|
161531
162770
|
mgr.useLinkedHubs(hubs);
|
|
161532
162771
|
mgr.useHubName(hubName);
|
|
161533
162772
|
mgr.layout.useLinkedSessions((id3) => links.knowsSession(id3));
|
|
@@ -161590,6 +162829,7 @@ var router = new Router({
|
|
|
161590
162829
|
activity: () => activityCounts(activity()),
|
|
161591
162830
|
updateApply,
|
|
161592
162831
|
hubs,
|
|
162832
|
+
mailAcross: hostMailbox.across,
|
|
161593
162833
|
mail: mailPerson,
|
|
161594
162834
|
requests
|
|
161595
162835
|
}),
|