@centralu/host-win32-x64 0.1.0-beta.72 → 0.1.0-beta.74
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 +839 -623
- package/package.json +1 -1
package/host/main.mjs
CHANGED
|
@@ -43046,7 +43046,7 @@ import { dirname as dirname27, join as join58 } from "node:path";
|
|
|
43046
43046
|
import { mkdirSync as mkdirSync21, readFileSync as readFileSync27, writeSync as writeSync4 } from "node:fs";
|
|
43047
43047
|
|
|
43048
43048
|
// packages/protocol/src/version.generated.ts
|
|
43049
|
-
var APP_VERSION = "0.1.0-beta.
|
|
43049
|
+
var APP_VERSION = "0.1.0-beta.74";
|
|
43050
43050
|
|
|
43051
43051
|
// packages/protocol/src/brand.ts
|
|
43052
43052
|
var APP_NAME = "Centralu";
|
|
@@ -57893,6 +57893,7 @@ var HostHandover = external_exports.object({ state: external_exports.enum(["wait
|
|
|
57893
57893
|
// packages/protocol/src/machines.ts
|
|
57894
57894
|
var MACHINE_ID_RE = /^[a-z][a-z0-9-]{0,31}$/;
|
|
57895
57895
|
var MachineId = external_exports.string().regex(MACHINE_ID_RE, "Not a machine id");
|
|
57896
|
+
var UnreachedMachine = external_exports.object({ machineId: external_exports.string(), name: external_exports.string() });
|
|
57896
57897
|
var MachineStatus = external_exports.enum([
|
|
57897
57898
|
"connecting",
|
|
57898
57899
|
"connected",
|
|
@@ -61598,7 +61599,13 @@ var HubOffer = external_exports.object({
|
|
|
61598
61599
|
mail: external_exports.boolean().optional(),
|
|
61599
61600
|
you: MachineId.optional(),
|
|
61600
61601
|
/** The hub answers `hub.apps` and `hub.appCall` (#1938, docs/plans/remote-hub.md §13.6). Additive */
|
|
61601
|
-
apps: external_exports.boolean().optional()
|
|
61602
|
+
apps: external_exports.boolean().optional(),
|
|
61603
|
+
/**
|
|
61604
|
+
* The open tasks the hub gave this machine's sessions, by id, oldest first (#2289, docs/plans/linked-mail.md §10): the machine answers which it
|
|
61605
|
+
* lacks (`lacks`), and the hub deletes those copies, as tasks that never arrived. Additive: a machine from before it answers no `lacks`, and the hub
|
|
61606
|
+
* keeps every copy
|
|
61607
|
+
*/
|
|
61608
|
+
open: external_exports.array(external_exports.string().min(1).max(200)).max(500).optional()
|
|
61602
61609
|
});
|
|
61603
61610
|
var HubProject = external_exports.object({ id: external_exports.string().min(1).max(200), name: external_exports.string().max(500) });
|
|
61604
61611
|
var HubAskParams = external_exports.object({
|
|
@@ -62220,7 +62227,16 @@ var hostResults = {
|
|
|
62220
62227
|
// `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
|
|
62221
62228
|
// `apps`: this host answers `host.apps` and `host.appCall` from the hub (#1938)
|
|
62222
62229
|
// `tasks`: this host takes the hub's tasks as mail and reports them back (`host.mail` with `task`, #1948 step 6)
|
|
62223
|
-
|
|
62230
|
+
// `lacks`: the offer's `open` tasks this host never received (#2289); absent from an older host, which the hub reads as none
|
|
62231
|
+
// `host`: this host's own id in mail addresses (`hubSelfId`), by which the hub reads this host's mail in its own terms (#2268)
|
|
62232
|
+
"host.hubOffer": external_exports.object({
|
|
62233
|
+
ok: external_exports.literal(true),
|
|
62234
|
+
mail: external_exports.boolean().optional(),
|
|
62235
|
+
apps: external_exports.boolean().optional(),
|
|
62236
|
+
tasks: external_exports.boolean().optional(),
|
|
62237
|
+
lacks: external_exports.array(external_exports.string().max(200)).max(500).optional(),
|
|
62238
|
+
host: external_exports.string().max(200).optional()
|
|
62239
|
+
}),
|
|
62224
62240
|
// As `hub.mail` answers (machines-hub.ts `HubMailResult`, which the window's bundle leaves out, #1648)
|
|
62225
62241
|
"host.mail": external_exports.union([
|
|
62226
62242
|
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() }),
|
|
@@ -62253,7 +62269,12 @@ var mailParams = {
|
|
|
62253
62269
|
all: external_exports.boolean().optional(),
|
|
62254
62270
|
/** The last this many messages (at most 100), and the thread is read to its end; with `before`, the last this many before that `seq`, read already */
|
|
62255
62271
|
tail: external_exports.number().int().min(1).max(100).optional(),
|
|
62256
|
-
before: external_exports.number().int().min(1).optional()
|
|
62272
|
+
before: external_exports.number().int().min(1).optional(),
|
|
62273
|
+
/**
|
|
62274
|
+
* Read it as a look in (#2268): nothing in it is read for anyone. A hub sends it for a linked machine's chain it opens from its Tasks, which it shows
|
|
62275
|
+
* read-only. Absent: false. A host from before it drops it and reads what is the person's there for them, as before
|
|
62276
|
+
*/
|
|
62277
|
+
lookIn: external_exports.boolean().default(false)
|
|
62257
62278
|
}),
|
|
62258
62279
|
/** The person writes in a thread: their words, whatever the thread's other parties are (§7.1) */
|
|
62259
62280
|
"mail.reply": external_exports.object({
|
|
@@ -62301,7 +62322,9 @@ var mailResults = {
|
|
|
62301
62322
|
"mail.tasks": external_exports.object({
|
|
62302
62323
|
tasks: external_exports.array(MailTaskRow).default([]),
|
|
62303
62324
|
/** How many open tasks are listed when more are open than the host lists (the oldest left out); null when every open one is. Absent from an older host */
|
|
62304
|
-
capped: external_exports.number().nullable().default(null)
|
|
62325
|
+
capped: external_exports.number().nullable().default(null),
|
|
62326
|
+
/** On a hub: the linked machines whose tasks are not in the list, as they could not be read just now (#2268). Absent from an older host */
|
|
62327
|
+
unreached: external_exports.array(UnreachedMachine).default([])
|
|
62305
62328
|
}),
|
|
62306
62329
|
"mail.thread": MailThreadView,
|
|
62307
62330
|
"mail.reply": MailThreadView,
|
|
@@ -63537,7 +63560,7 @@ var sessionsResults = {
|
|
|
63537
63560
|
sessions: external_exports.array(TrashedSession),
|
|
63538
63561
|
runs: external_exports.array(TrashedRun).default([]),
|
|
63539
63562
|
bytes: external_exports.number(),
|
|
63540
|
-
unreached: external_exports.array(
|
|
63563
|
+
unreached: external_exports.array(UnreachedMachine).optional(),
|
|
63541
63564
|
/**
|
|
63542
63565
|
* The subagent steps moved to the trash without their session (#418), most recently moved first. Their bytes
|
|
63543
63566
|
* are in `bytes`. `trash.empty` leaves them: the window deletes each one it listed (`trash.purgeSubagentSteps`).
|
|
@@ -63557,7 +63580,7 @@ var sessionsResults = {
|
|
|
63557
63580
|
"trash.purge": external_exports.object({ ok: external_exports.literal(true) }),
|
|
63558
63581
|
"subagents.usage": external_exports.object({
|
|
63559
63582
|
sessions: external_exports.array(SubagentStepsHeld),
|
|
63560
|
-
unreached: external_exports.array(
|
|
63583
|
+
unreached: external_exports.array(UnreachedMachine).optional()
|
|
63561
63584
|
}),
|
|
63562
63585
|
"subagents.trash": external_exports.object({ steps: external_exports.number(), bytes: external_exports.number() }),
|
|
63563
63586
|
"trash.restoreSubagentSteps": external_exports.object({ ok: external_exports.literal(true) }),
|
|
@@ -66566,7 +66589,7 @@ function raceTimeout(p, ms3, fallback) {
|
|
|
66566
66589
|
})
|
|
66567
66590
|
]).finally(() => clearTimeout(timer));
|
|
66568
66591
|
}
|
|
66569
|
-
async function raceBound(outcome2, ms3, signal, ...
|
|
66592
|
+
async function raceBound(outcome2, ms3, signal, ...wakes) {
|
|
66570
66593
|
let timer;
|
|
66571
66594
|
let onAbort;
|
|
66572
66595
|
const bound = new Promise((resolve21) => timer = unrefTimer(() => resolve21("bound"), ms3));
|
|
@@ -66577,7 +66600,7 @@ async function raceBound(outcome2, ms3, signal, ...wakes2) {
|
|
|
66577
66600
|
else signal.addEventListener("abort", onAbort, { once: true });
|
|
66578
66601
|
});
|
|
66579
66602
|
try {
|
|
66580
|
-
return await Promise.race([outcome2, bound, aborted2, ...
|
|
66603
|
+
return await Promise.race([outcome2, bound, aborted2, ...wakes]);
|
|
66581
66604
|
} finally {
|
|
66582
66605
|
clearTimeout(timer);
|
|
66583
66606
|
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
@@ -75941,12 +75964,12 @@ var require_discriminator = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
75941
75964
|
},
|
|
75942
75965
|
code(cxt2) {
|
|
75943
75966
|
const { gen, data, schema, parentSchema, it: it2 } = cxt2;
|
|
75944
|
-
const { oneOf:
|
|
75967
|
+
const { oneOf: oneOf2 } = parentSchema;
|
|
75945
75968
|
if (!it2.opts.discriminator) throw new Error("discriminator: requires discriminator option");
|
|
75946
75969
|
const tagName = schema.propertyName;
|
|
75947
75970
|
if (typeof tagName != "string") throw new Error("discriminator: requires propertyName");
|
|
75948
75971
|
if (schema.mapping) throw new Error("discriminator: mapping is not supported");
|
|
75949
|
-
if (!
|
|
75972
|
+
if (!oneOf2) throw new Error("discriminator: requires oneOf keyword");
|
|
75950
75973
|
const valid = gen.let("valid", false);
|
|
75951
75974
|
const tag = gen.const("tag", (0, codegen_1._)`${data}${(0, codegen_1.getProperty)(tagName)}`);
|
|
75952
75975
|
gen.if((0, codegen_1._)`typeof ${tag} == "string"`, () => validateMapping(), () => cxt2.error(false, {
|
|
@@ -75984,8 +76007,8 @@ var require_discriminator = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
75984
76007
|
const oneOfMapping = {};
|
|
75985
76008
|
const topRequired = hasRequired(parentSchema);
|
|
75986
76009
|
let tagRequired = true;
|
|
75987
|
-
for (let i = 0; i <
|
|
75988
|
-
let sch =
|
|
76010
|
+
for (let i = 0; i < oneOf2.length; i++) {
|
|
76011
|
+
let sch = oneOf2[i];
|
|
75989
76012
|
if ((sch === null || sch === void 0 ? void 0 : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it2.self.RULES)) {
|
|
75990
76013
|
const ref = sch.$ref;
|
|
75991
76014
|
sch = compile_1.resolveRef.call(it2.self, it2.schemaEnv.root, it2.baseId, ref);
|
|
@@ -97319,12 +97342,12 @@ var require_discriminator2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
97319
97342
|
},
|
|
97320
97343
|
code(cxt2) {
|
|
97321
97344
|
const { gen, data, schema, parentSchema, it: it2 } = cxt2;
|
|
97322
|
-
const { oneOf:
|
|
97345
|
+
const { oneOf: oneOf2 } = parentSchema;
|
|
97323
97346
|
if (!it2.opts.discriminator) throw new Error("discriminator: requires discriminator option");
|
|
97324
97347
|
const tagName = schema.propertyName;
|
|
97325
97348
|
if (typeof tagName != "string") throw new Error("discriminator: requires propertyName");
|
|
97326
97349
|
if (schema.mapping) throw new Error("discriminator: mapping is not supported");
|
|
97327
|
-
if (!
|
|
97350
|
+
if (!oneOf2) throw new Error("discriminator: requires oneOf keyword");
|
|
97328
97351
|
const valid = gen.let("valid", false);
|
|
97329
97352
|
const tag = gen.const("tag", (0, codegen_1._)`${data}${(0, codegen_1.getProperty)(tagName)}`);
|
|
97330
97353
|
gen.if((0, codegen_1._)`typeof ${tag} == "string"`, () => validateMapping(), () => cxt2.error(false, {
|
|
@@ -97362,8 +97385,8 @@ var require_discriminator2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
97362
97385
|
const oneOfMapping = {};
|
|
97363
97386
|
const topRequired = hasRequired(parentSchema);
|
|
97364
97387
|
let tagRequired = true;
|
|
97365
|
-
for (let i = 0; i <
|
|
97366
|
-
let sch =
|
|
97388
|
+
for (let i = 0; i < oneOf2.length; i++) {
|
|
97389
|
+
let sch = oneOf2[i];
|
|
97367
97390
|
if ((sch === null || sch === void 0 ? void 0 : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it2.self.RULES)) {
|
|
97368
97391
|
const ref = sch.$ref;
|
|
97369
97392
|
sch = compile_1.resolveRef.call(it2.self, it2.schemaEnv.root, it2.baseId, ref);
|
|
@@ -109725,6 +109748,9 @@ function isSessionId2(id3) {
|
|
|
109725
109748
|
function sessionAddress(host, sessionId) {
|
|
109726
109749
|
return checked(`session:${host}/${sessionId}`);
|
|
109727
109750
|
}
|
|
109751
|
+
function appAddress(host, projectId, appId) {
|
|
109752
|
+
return checked(`app:${host}/${projectId}/${appId}`);
|
|
109753
|
+
}
|
|
109728
109754
|
function parseAddress(address) {
|
|
109729
109755
|
if (address === PERSON) return { kind: "person" };
|
|
109730
109756
|
if (address === CENTRALU) return { kind: "centralu" };
|
|
@@ -109734,6 +109760,11 @@ function parseAddress(address) {
|
|
|
109734
109760
|
if (appHost !== void 0 && projectId !== void 0 && appId !== void 0) return { kind: "app", host: appHost, projectId, appId };
|
|
109735
109761
|
return null;
|
|
109736
109762
|
}
|
|
109763
|
+
function inHubTerms(address, hub, machine) {
|
|
109764
|
+
if (address === sessionAddress(hub, PERSON_ID)) return PERSON;
|
|
109765
|
+
const p = parseAddress(address);
|
|
109766
|
+
return machine && p?.kind === "session" && p.host === machine.host && !p.sessionId.includes(".") ? sessionAddress(hub, `${machine.id}.${p.sessionId}`) : address;
|
|
109767
|
+
}
|
|
109737
109768
|
function checked(address) {
|
|
109738
109769
|
if (!parseAddress(address)) throw new Error(`Not a mail address: ${JSON.stringify(address)}`);
|
|
109739
109770
|
return address;
|
|
@@ -109971,28 +110002,7 @@ var askersKey = (asker) => [asker.turn, asker.messageId, ...(asker.also ?? []).m
|
|
|
109971
110002
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
109972
110003
|
|
|
109973
110004
|
// packages/agent-host/src/dev-services/store/mail-types.ts
|
|
109974
|
-
var DELEGATION_ORIGINS = ["start_agent", "agent_session", "send_to_session", "create_session", "ask_project"];
|
|
109975
110005
|
var SEND_ORIGINS = /* @__PURE__ */ new Set(["agent_session", "ask_project", "send_to_session"]);
|
|
109976
|
-
var MESSAGE_KINDS = ["assign", "question", "answer", "report", "notice", "note", "event"];
|
|
109977
|
-
function oneOf2(list2, value, fallback) {
|
|
109978
|
-
return list2.find((x) => x === value) ?? fallback;
|
|
109979
|
-
}
|
|
109980
|
-
var toMessage = (r) => ({
|
|
109981
|
-
id: r.id,
|
|
109982
|
-
threadId: r.thread_id,
|
|
109983
|
-
seq: r.seq,
|
|
109984
|
-
homeSeq: r.home_seq,
|
|
109985
|
-
sender: r.sender,
|
|
109986
|
-
kind: oneOf2(MESSAGE_KINDS, r.kind, "note"),
|
|
109987
|
-
urgent: r.urgent === 1,
|
|
109988
|
-
needsOwner: r.needs_owner === 1,
|
|
109989
|
-
wake: r.wake === "yes" ? "yes" : r.wake === "no" ? "no" : null,
|
|
109990
|
-
replyTo: r.reply_to,
|
|
109991
|
-
body: r.body,
|
|
109992
|
-
facts: readJson(r.facts, JsonObject, {}),
|
|
109993
|
-
dedupeKey: r.dedupe_key,
|
|
109994
|
-
createdAt: r.created_at
|
|
109995
|
-
});
|
|
109996
110006
|
|
|
109997
110007
|
// packages/agent-host/src/mail/rules.ts
|
|
109998
110008
|
import { createHash as createHash9 } from "node:crypto";
|
|
@@ -110054,14 +110064,6 @@ function postsPerMinute(sender) {
|
|
|
110054
110064
|
}
|
|
110055
110065
|
var ASKS_PER_HOUR = 5;
|
|
110056
110066
|
var REPEAT_WINDOW_MS = 10 * 6e4;
|
|
110057
|
-
function wakes(sender, m) {
|
|
110058
|
-
if (m.kind === "event") return false;
|
|
110059
|
-
if (sender === "centralu" && m.wake === "no") return false;
|
|
110060
|
-
if (sender !== "app") return true;
|
|
110061
|
-
if (m.wake === "no") return false;
|
|
110062
|
-
if (m.kind === "notice") return m.needsOwner || m.wake === "yes";
|
|
110063
|
-
return true;
|
|
110064
|
-
}
|
|
110065
110067
|
function needsReceiver(m) {
|
|
110066
110068
|
return isPerson(m.sender) || m.kind === "task" || m.kind === "report" || m.needsReply || isSendNote(m) || m.facts.needsOwner === true;
|
|
110067
110069
|
}
|
|
@@ -110137,7 +110139,7 @@ var WARNING_TEXT = {
|
|
|
110137
110139
|
pair: (a, b2, turns) => `${a} and ${b2} started ${turns} turns of each other by mail in the last hour, with no word from you. Their mail still goes: write to either, or stop one, if they are going round in circles.`,
|
|
110138
110140
|
host: (turns) => `Mail between sessions started ${turns} turns on this computer in the last hour. It still goes: look at the busy sessions if that is more than you expect.`,
|
|
110139
110141
|
compactCycles: (session2, cycles) => `${session2} asked to compact its conversation and went on to its next step ${cycles} times in the last hour. It keeps working: look at it if that is more than you expect.`,
|
|
110140
|
-
watchWakes: (session2,
|
|
110142
|
+
watchWakes: (session2, wakes) => `${session2}'s watches woke it ${wakes} times in the last hour. They keep firing: look at it if that is more than you expect.`,
|
|
110141
110143
|
/** The three guards that refuse rather than warn (#1684, #2035): the person hears of the first refusal of each kind a clock hour */
|
|
110142
110144
|
repeat: (sender, to) => `Centralu refused mail from ${sender} to ${to}: the same text again within ${durationText(REPEAT_WINDOW_MS)}. ${sender} was told; nothing else was stopped.`,
|
|
110143
110145
|
rate_limited: (sender, limit) => `Centralu refused mail from ${sender}: more than ${limit} messages in a minute. ${sender} was told to wait; nothing else was stopped.`,
|
|
@@ -110562,18 +110564,18 @@ var MailDelivery = class {
|
|
|
110562
110564
|
return;
|
|
110563
110565
|
}
|
|
110564
110566
|
const { drained } = plan;
|
|
110565
|
-
const
|
|
110567
|
+
const quiet2 = !drained.wake;
|
|
110566
110568
|
const joins = state.joins === true;
|
|
110567
|
-
const turn =
|
|
110569
|
+
const turn = quiet2 || joins ? void 0 : this.turns?.begin(sessionId, { workMessage: drained.workMessage, starter: this.starterOf(drained) });
|
|
110568
110570
|
const cancelTurn = () => {
|
|
110569
110571
|
if (turn !== void 0) this.turns?.cancel(sessionId, turn);
|
|
110570
110572
|
};
|
|
110571
110573
|
const delivered = {};
|
|
110572
|
-
const shown3 =
|
|
110574
|
+
const shown3 = quiet2 ? void 0 : this.shownOf(drained);
|
|
110573
110575
|
const inputId = joins ? randomUUID11() : void 0;
|
|
110574
110576
|
const depth = Math.max(0, ...drained.messageIds.map((id3) => this.records.message(id3)?.facts.agentDepth ?? 0));
|
|
110575
110577
|
try {
|
|
110576
|
-
await this.sessions.deliver(sessionId, { text: drained.text, quiet, line: drained.line, wanted: () => drained.messageIds.some((id3) => this.records.recipient(id3, recipient)?.settled !== "withdrawn"), ...joins ? { joins, id: inputId } : {}, ...shown3 ? { shown: shown3 } : {}, ...depth ? { depth } : {} }, (e) => {
|
|
110578
|
+
await this.sessions.deliver(sessionId, { text: drained.text, quiet: quiet2, line: drained.line, wanted: () => drained.messageIds.some((id3) => this.records.recipient(id3, recipient)?.settled !== "withdrawn"), ...joins ? { joins, id: inputId } : {}, ...shown3 ? { shown: shown3 } : {}, ...depth ? { depth } : {} }, (e) => {
|
|
110577
110579
|
cancelTurn();
|
|
110578
110580
|
if (delivered.at !== void 0) this.takeBack(recipient, drained.messageIds, delivered.at, e);
|
|
110579
110581
|
});
|
|
@@ -110593,14 +110595,14 @@ var MailDelivery = class {
|
|
|
110593
110595
|
this.records.markRead(recipient, drained.inline, deliveredAt);
|
|
110594
110596
|
});
|
|
110595
110597
|
if (inputId) this.joined.set(recipient, [...this.joined.get(recipient) ?? [], { id: inputId, ids: drained.messageIds }]);
|
|
110596
|
-
if (!
|
|
110598
|
+
if (!quiet2 && !joins) this.lastWake.set(recipient, this.now());
|
|
110597
110599
|
if (waiting) {
|
|
110598
110600
|
this.left.delete(recipient);
|
|
110599
110601
|
this.crowd = this.crowd?.filter((r) => r !== recipient) ?? null;
|
|
110600
110602
|
if (this.crowd?.length === 0) this.crowd = null;
|
|
110601
110603
|
this.crowdChanged();
|
|
110602
110604
|
}
|
|
110603
|
-
if (!
|
|
110605
|
+
if (!quiet2) this.warnIfRunning(recipient, drained.messageIds, deliveredAt);
|
|
110604
110606
|
}
|
|
110605
110607
|
/**
|
|
110606
110608
|
* What the tool said of the inputs given the recipient (docs/plans/mailbox.md §10.6.3). At a turn's end, mail given into it that the turn did not take
|
|
@@ -112782,6 +112784,10 @@ var ChildReports = class {
|
|
|
112782
112784
|
if (cut3) this.cutsUntold.add(sessionId);
|
|
112783
112785
|
this.answerAtRest(sessionId, true);
|
|
112784
112786
|
}
|
|
112787
|
+
/** An update cut the turn and Centralu continued it (#1966), and the turn's end is a later one's (#2318): the answer that follows says so */
|
|
112788
|
+
noteCut(sessionId) {
|
|
112789
|
+
this.cutsUntold.add(sessionId);
|
|
112790
|
+
}
|
|
112785
112791
|
/** A turn stopped: its stop notice releases what the session owed, so a cut kept from a turn before is no later answer's to tell (#1966) */
|
|
112786
112792
|
turnStopped(sessionId) {
|
|
112787
112793
|
this.cutsUntold.delete(sessionId);
|
|
@@ -113153,6 +113159,12 @@ var InputReceipts = class {
|
|
|
113153
113159
|
get ids() {
|
|
113154
113160
|
return [...this.pending.keys()];
|
|
113155
113161
|
}
|
|
113162
|
+
/** How many wait for the tool to take them: not taken by a turn, and not among `except` (the ones the turn ending now took) */
|
|
113163
|
+
untaken(except) {
|
|
113164
|
+
let n = 0;
|
|
113165
|
+
for (const [id3, p] of this.pending) if (!p.accepted && !except.includes(id3)) n++;
|
|
113166
|
+
return n;
|
|
113167
|
+
}
|
|
113156
113168
|
/** The tool took the input (once): the observer is told before the turn is recorded */
|
|
113157
113169
|
accept(id3) {
|
|
113158
113170
|
const p = this.pending.get(id3);
|
|
@@ -119625,9 +119637,6 @@ function pragmaNumber(db, name) {
|
|
|
119625
119637
|
if (typeof v !== "number") throw new Error(`PRAGMA ${name} answered ${typeof v}, not a number`);
|
|
119626
119638
|
return v;
|
|
119627
119639
|
}
|
|
119628
|
-
function updateRecipientRows(db, table, set3, setArgs, recipient, ids, also) {
|
|
119629
|
-
return db.prepare(`UPDATE ${table} SET ${set3} WHERE recipient = ?${also ? ` AND ${also}` : ""} AND message_id IN (SELECT value FROM json_each(?))`).run(...setArgs, recipient, JSON.stringify(ids)).changes;
|
|
119630
|
-
}
|
|
119631
119640
|
|
|
119632
119641
|
// packages/agent-host/src/dev-services/store/mailbox.ts
|
|
119633
119642
|
var MAIL_KINDS = ["message", "task", "report", "notice"];
|
|
@@ -119652,6 +119661,7 @@ var MailTargetMissing = class extends Error {
|
|
|
119652
119661
|
};
|
|
119653
119662
|
var DAY = 24 * 60 * 60 * 1e3;
|
|
119654
119663
|
var MAILBOX_RETENTION = { waitingMs: 180 * DAY, settledMs: 30 * DAY, readNoticeMs: 14 * DAY, batch: 500 };
|
|
119664
|
+
var likePrefix = (prefix) => `${prefix.replace(/[\\%_]/g, (c) => `\\${c}`)}%`;
|
|
119655
119665
|
var WATCHED = `(m.needs_reply = 1 OR m.kind = 'task')`;
|
|
119656
119666
|
var WAITING = `r.read_at IS NULL AND (r.held IS NULL OR r.held = 'released') AND COALESCE(r.settled, '') NOT IN ('withdrawn', 'gone')`;
|
|
119657
119667
|
var HELD = `r.held IS NOT NULL AND r.held NOT IN ('released', 'dismissed')`;
|
|
@@ -120093,8 +120103,18 @@ var MailboxRecords = class {
|
|
|
120093
120103
|
// ── Across a link (#2067 item 2, docs/plans/linked-mail.md §6) ──
|
|
120094
120104
|
/** Whether `sender` ever sent a message to an address that starts with `prefix` (a linked machine's sessions, `session:<hub>/<machine>.`) */
|
|
120095
120105
|
sentToward(sender, prefix) {
|
|
120096
|
-
|
|
120097
|
-
|
|
120106
|
+
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, likePrefix(prefix)) !== void 0;
|
|
120107
|
+
}
|
|
120108
|
+
/**
|
|
120109
|
+
* The open tasks given after `since` to addresses that start with `prefix` (a linked machine's sessions, `session:<hub>/<machine>.`), oldest first,
|
|
120110
|
+
* at most `limit` (#2289)
|
|
120111
|
+
*/
|
|
120112
|
+
openTasksToward(prefix, since, limit) {
|
|
120113
|
+
return this.db.prepare(
|
|
120114
|
+
`SELECT m.id FROM mail m JOIN mail_recipients r ON r.message_id = m.id
|
|
120115
|
+
WHERE m.kind = 'task' AND r.recipient LIKE ? ESCAPE '\\' AND r.settled IS NULL AND r.released_at IS NULL AND m.created_at > ?
|
|
120116
|
+
ORDER BY m.created_at, m.id LIMIT ?`
|
|
120117
|
+
).all(likePrefix(prefix), since, limit).map((r) => r.id);
|
|
120098
120118
|
}
|
|
120099
120119
|
/**
|
|
120100
120120
|
* The rows of messages that crossed a link, with each message's sender: a row whose recipient or whose message's sender is
|
|
@@ -120513,9 +120533,12 @@ var MailboxRecords = class {
|
|
|
120513
120533
|
{ key: key2, at: anchor?.createdAt ?? null, id: anchor?.id ?? "", limit: opts.limit }
|
|
120514
120534
|
);
|
|
120515
120535
|
}
|
|
120516
|
-
/**
|
|
120536
|
+
/**
|
|
120537
|
+
* `UPDATE mail_recipients SET <set> WHERE recipient = ? [AND <also>] AND message_id IN <ids>`, the ids passed as one JSON parameter read with
|
|
120538
|
+
* `json_each`; `setArgs` fill the `?` of `set`. Returns the rows changed
|
|
120539
|
+
*/
|
|
120517
120540
|
update(set3, setArgs, recipient, ids, also) {
|
|
120518
|
-
return
|
|
120541
|
+
return this.db.prepare(`UPDATE mail_recipients SET ${set3} WHERE recipient = ?${also ? ` AND ${also}` : ""} AND message_id IN (SELECT value FROM json_each(?))`).run(...setArgs, recipient, JSON.stringify(ids)).changes;
|
|
120519
120542
|
}
|
|
120520
120543
|
count(sql, ...args) {
|
|
120521
120544
|
return this.db.prepare(sql).get(...args)?.n ?? 0;
|
|
@@ -120629,22 +120652,20 @@ function fitFrame(items, budget, render) {
|
|
|
120629
120652
|
}
|
|
120630
120653
|
return { text: text3, shown: shown3.map((i) => i.messageId), inline: cut3 ? [] : shown3.filter((i) => i.inline !== void 0).map((i) => i.messageId) };
|
|
120631
120654
|
}
|
|
120632
|
-
function mailCalls(
|
|
120655
|
+
function mailCalls(form) {
|
|
120633
120656
|
const call2 = (action, fields5 = {}) => {
|
|
120634
120657
|
const entries = Object.entries(fields5);
|
|
120635
120658
|
return form === "plain" ? `mail(action="${action}"${entries.map(([k2, v]) => `, ${k2}="${v}"`).join("")})` : `centralu_run(command="mail", args={action: "${action}"${entries.map(([k2, v]) => `, ${k2}: "${v}"`).join("")}})`;
|
|
120636
120659
|
};
|
|
120637
|
-
const target = version2 === 2 ? "id" : "thread";
|
|
120638
120660
|
return {
|
|
120639
|
-
read: (id3) => call2("read", id3 === void 0 ? {} : {
|
|
120640
|
-
answer: (id3) => call2(
|
|
120641
|
-
done: (id3) => call2(
|
|
120661
|
+
read: (id3) => call2("read", id3 === void 0 ? {} : { thread: id3 }),
|
|
120662
|
+
answer: (id3) => call2("reply", { thread: id3, text: "\u2026" }),
|
|
120663
|
+
done: (id3) => call2("handled", { thread: id3 }),
|
|
120642
120664
|
inbox: () => call2("inbox"),
|
|
120643
|
-
sessions: () => call2("sessions"),
|
|
120644
120665
|
close: (id3) => call2("close", { thread: id3 })
|
|
120645
120666
|
};
|
|
120646
120667
|
}
|
|
120647
|
-
var PLAIN_MESSAGE_CALLS = mailCalls(
|
|
120668
|
+
var PLAIN_MESSAGE_CALLS = mailCalls("plain");
|
|
120648
120669
|
var FOR_PERSON = {
|
|
120649
120670
|
note: "from the Assistant, which acts for the person in Centralu: carry it out as the person's request. No answer is owed:",
|
|
120650
120671
|
task: "from the Assistant, which acts for the person in Centralu: carry it out as the person's request. Report back when done:"
|
|
@@ -122817,7 +122838,7 @@ var DelegationForks = class {
|
|
|
122817
122838
|
return this.forkTrustError(callerId, target, true) ?? this.flow.starts.agentCeilingError(callerId, target.projectId ?? "");
|
|
122818
122839
|
}
|
|
122819
122840
|
/** `forkGateError` without the ceiling: read before the card and again once it is answered (`forkFor`); `quiet` as `trustGate` */
|
|
122820
|
-
forkTrustError(callerId, target,
|
|
122841
|
+
forkTrustError(callerId, target, quiet2) {
|
|
122821
122842
|
const caller = this.host.meta.get(callerId);
|
|
122822
122843
|
if (!caller) return "the requesting session is gone";
|
|
122823
122844
|
if (!this.host.meta.has(target.id)) return "it is no longer here";
|
|
@@ -122825,7 +122846,7 @@ var DelegationForks = class {
|
|
|
122825
122846
|
if (deep) return deep.replace(/^This/, "this").replace(/\.$/, "");
|
|
122826
122847
|
if (!target.projectId) return NO_PROJECT;
|
|
122827
122848
|
if (!this.host.store.projects.listProjects().some((p) => p.id === target.projectId)) return "its project is no longer registered";
|
|
122828
|
-
return this.host.trustGate(callerId, target.projectId, "forking a session",
|
|
122849
|
+
return this.host.trustGate(callerId, target.projectId, "forking a session", quiet2);
|
|
122829
122850
|
}
|
|
122830
122851
|
/** Why `target` cannot be forked for `callerId` now, or null. Its project is said first, whatever its CLI can do (#994 review) */
|
|
122831
122852
|
forkWhy(callerId, target) {
|
|
@@ -124007,6 +124028,8 @@ var SessionEvents = class {
|
|
|
124007
124028
|
if (this.host.restartPolicy.backgroundUnknown.has(m.id)) this.host.restartPolicy.backgroundUnknown.set(m.id, Date.now());
|
|
124008
124029
|
if (!wasBusy && inTurn(m.state)) {
|
|
124009
124030
|
continues = this.host.selfCompaction.stepOpens(m.id);
|
|
124031
|
+
this.host.reports.stopSettling(m.id);
|
|
124032
|
+
this.inputWaits.delete(m.id);
|
|
124010
124033
|
this.host.children.turnStarted(m.id);
|
|
124011
124034
|
this.host.children.noteTurnStart(m.id, m.lastSeq);
|
|
124012
124035
|
}
|
|
@@ -124048,11 +124071,30 @@ var SessionEvents = class {
|
|
|
124048
124071
|
const runOpen = !!run2 && !run2.finished;
|
|
124049
124072
|
const delegation = runOpen ? [...this.host.children.delegations.values()].find((d2) => d2.wait === run2) : void 0;
|
|
124050
124073
|
const waited = runOpen && (!delegation || (delegation.waiters ?? 0) > 0);
|
|
124051
|
-
run2?.onEvent(e);
|
|
124052
|
-
if (e.sessionId) for (const observer of this.host.turnObservers.get(e.sessionId) ?? []) observer.onEvent(e);
|
|
124053
124074
|
const processWent = e.type === "error" && (e.error.code === "adapter_crashed" || e.error.code === "conversation_locked");
|
|
124054
124075
|
const taken = endedTurn && e.sessionId ? this.host.handles.get(e.sessionId)?.turnInputs?.() : void 0;
|
|
124076
|
+
const ownTurn = endedTurn && e.type === "turn_complete" && !!e.sessionId && Array.isArray(taken) && taken.length === 0 && (this.host.handles.get(e.sessionId)?.queuedInputs?.() ?? 0) > 0;
|
|
124077
|
+
if (!ownTurn) {
|
|
124078
|
+
run2?.onEvent(e);
|
|
124079
|
+
if (e.sessionId) for (const observer of this.host.turnObservers.get(e.sessionId) ?? []) observer.onEvent(e);
|
|
124080
|
+
}
|
|
124055
124081
|
const owned = endedTurn && e.sessionId ? this.host.children.turnEnded(e.sessionId, taken) : void 0;
|
|
124082
|
+
if (ownTurn && e.sessionId) {
|
|
124083
|
+
console.error(`[agent-host] ${e.sessionId.slice(0, 8)}: its tool ended a turn of its own while an input waits to run: not the work's end (#2318)`);
|
|
124084
|
+
if (owned?.cut) {
|
|
124085
|
+
this.host.children.noteContinuedCut(e.sessionId);
|
|
124086
|
+
this.host.reports.noteCut(e.sessionId);
|
|
124087
|
+
}
|
|
124088
|
+
this.host.reports.settleAtRest(e.sessionId);
|
|
124089
|
+
this.inputWaits.add(e.sessionId);
|
|
124090
|
+
}
|
|
124091
|
+
if (processWent && !endedTurn && e.sessionId && this.inputWaits.delete(e.sessionId)) {
|
|
124092
|
+
this.host.children.dropContinuedCut(e.sessionId);
|
|
124093
|
+
this.host.reports.stopSettling(e.sessionId);
|
|
124094
|
+
this.host.reports.turnStopped(e.sessionId);
|
|
124095
|
+
this.host.mailStopped(e.sessionId, "error", this.stopTold(e.sessionId, false, void 0));
|
|
124096
|
+
}
|
|
124097
|
+
if (e.type === "session_deleted") this.inputWaits.delete(e.sessionId);
|
|
124056
124098
|
const turnBy = e.sessionId && endedTurn && this.host.selfCompaction.compactTurn(e.sessionId) ? { ...owned ?? { by: "work" }, compaction: true } : owned;
|
|
124057
124099
|
const since = turnBy && e.sessionId ? this.host.children.turnRows(e.sessionId)?.after : void 0;
|
|
124058
124100
|
const turnSaid = turnBy && (e.type === "turn_complete" || e.type === "state_change" || e.type === "error" || e.type === "limit_reached") ? { ...e, turn: since === void 0 ? turnBy : { ...turnBy, since } } : e;
|
|
@@ -124064,7 +124106,7 @@ var SessionEvents = class {
|
|
|
124064
124106
|
this.host.emit({ type: "interruption", sessionId: e.sessionId, interruption: nowInterrupted });
|
|
124065
124107
|
}
|
|
124066
124108
|
if (endedTurn && e.sessionId) this.host.mailTurnInputs(e.sessionId, { took: processWent ? void 0 : taken });
|
|
124067
|
-
const workEnded = endedTurn && !!e.sessionId && !this.host.selfCompaction.compactTurn(e.sessionId);
|
|
124109
|
+
const workEnded = endedTurn && !ownTurn && !!e.sessionId && !this.host.selfCompaction.compactTurn(e.sessionId);
|
|
124068
124110
|
const stopWhy = workEnded && e.sessionId && !this.host.restartPolicy.continuingTurns.has(e.sessionId) ? stopOf(e, nowInterrupted) : null;
|
|
124069
124111
|
if (stopWhy && e.sessionId) {
|
|
124070
124112
|
this.host.reports.turnStopped(e.sessionId);
|
|
@@ -124076,7 +124118,7 @@ var SessionEvents = class {
|
|
|
124076
124118
|
}
|
|
124077
124119
|
if ((e.type === "question_request" || e.type === "approval_request") && e.sessionId) this.host.cards.routeCard(e.sessionId, e.requestId, e.type === "question_request" ? "question" : "approval");
|
|
124078
124120
|
if ((endedTurn || e.type === "question_resolved" || e.type === "approval_resolved") && e.sessionId) this.host.cards.cardsEnded(e.sessionId);
|
|
124079
|
-
if (endedTurn && e.sessionId) this.endHubAsk(e.sessionId);
|
|
124121
|
+
if (endedTurn && !ownTurn && e.sessionId) this.endHubAsk(e.sessionId);
|
|
124080
124122
|
if (e.type === "approval_resolved" && e.sessionId) this.host.hostCards.raiseHostAsks(e.sessionId);
|
|
124081
124123
|
if (endedTurn && e.sessionId && this.host.meta.get(e.sessionId)?.state !== "error") this.host.hostCards.raiseHostAsks(e.sessionId);
|
|
124082
124124
|
if (endedTurn && e.sessionId) this.forgetCommits(e.sessionId);
|
|
@@ -124102,6 +124144,8 @@ var SessionEvents = class {
|
|
|
124102
124144
|
if (!asker || !this.host.meta.has(asker)) return { starter: null };
|
|
124103
124145
|
return { ...waited ? { told: [asker] } : {}, starter: asker };
|
|
124104
124146
|
}
|
|
124147
|
+
/** Sessions whose tool ended a turn of its own while an input waits to run, until that input's turn begins (#2318, `ownTurn`) */
|
|
124148
|
+
inputWaits = /* @__PURE__ */ new Set();
|
|
124105
124149
|
shareOf(e) {
|
|
124106
124150
|
const m = this.host.meta.get(e.sessionId);
|
|
124107
124151
|
if (!m) return e;
|
|
@@ -124547,11 +124591,11 @@ var MailSessionsView = class {
|
|
|
124547
124591
|
if (this.host.closing) return { kind: "busy", why: "turn" };
|
|
124548
124592
|
const busy = cardOrTurn(m);
|
|
124549
124593
|
const live2 = this.host.handles.has(id3);
|
|
124550
|
-
const
|
|
124551
|
-
if (busy === "turn" && live2 && this.host.joinsRunningTurn(id3) && !this.host.selfCompaction.compacts(id3)) return { kind: "ready", live: live2, quiet, auto: m.permissionPreset === "auto", joins: true };
|
|
124594
|
+
const quiet2 = live2 && this.host.adapters.get(m.tool)?.quietInput === true;
|
|
124595
|
+
if (busy === "turn" && live2 && this.host.joinsRunningTurn(id3) && !this.host.selfCompaction.compacts(id3)) return { kind: "ready", live: live2, quiet: quiet2, auto: m.permissionPreset === "auto", joins: true };
|
|
124552
124596
|
if (busy !== null) return { kind: "busy", why: busy === "turn" ? "turn" : "card" };
|
|
124553
124597
|
if (m.state === "limited") return { kind: "busy", why: "limited" };
|
|
124554
|
-
return { kind: "ready", live: live2, quiet, auto: m.permissionPreset === "auto" };
|
|
124598
|
+
return { kind: "ready", live: live2, quiet: quiet2, auto: m.permissionPreset === "auto" };
|
|
124555
124599
|
}
|
|
124556
124600
|
/** The session can be given a turn of its own now: at rest with no card or limit standing, in a host that is not leaving (asleep, it is woken) */
|
|
124557
124601
|
takesTurn(id3) {
|
|
@@ -125942,11 +125986,11 @@ var SelfCompaction = class {
|
|
|
125942
125986
|
* Ends a request that will not compact. With a `then` the session is not left to stall: the step goes as its next turn, with a line saying why (`refuse`).
|
|
125943
125987
|
* `quiet`: the person took control (they interrupted the turn) or the turn failed, so nothing is sent and the session is told at its next input
|
|
125944
125988
|
*/
|
|
125945
|
-
drop(id3, why2,
|
|
125989
|
+
drop(id3, why2, quiet2 = false) {
|
|
125946
125990
|
const req = this.pending.get(id3);
|
|
125947
125991
|
this.settle(id3);
|
|
125948
125992
|
if (!req?.then) return;
|
|
125949
|
-
if (
|
|
125993
|
+
if (quiet2) this.tell(id3, req.then, why2);
|
|
125950
125994
|
else this.refuseRequest(id3, req.then, why2);
|
|
125951
125995
|
}
|
|
125952
125996
|
/** The turn ended and the size of the context is known (`null`: none since a compaction): compacts when it is over the floor, drops the request otherwise */
|
|
@@ -128682,7 +128726,7 @@ var AcpAdapter = class {
|
|
|
128682
128726
|
const label = this.profile.descriptor.label;
|
|
128683
128727
|
const launch2 = await this.profile.launch(opts);
|
|
128684
128728
|
if (!launch2) throw toolNotInstalled(label, this.profile.descriptor.install);
|
|
128685
|
-
const spec = { command: launch2.command, args: launch2.args, cwd: opts.cwd, env: { ...process.env, ...launch2.env } };
|
|
128729
|
+
const spec = { command: launch2.command, args: launch2.args, cwd: launch2.cwd ?? opts.cwd, env: { ...process.env, ...launch2.env } };
|
|
128686
128730
|
const source = opts.processSource;
|
|
128687
128731
|
const shape = this.profile.shape;
|
|
128688
128732
|
if (source?.adopt) await closeAdopted(source.adopt, opts.sessionId, emit).catch(async (err) => {
|
|
@@ -129335,7 +129379,7 @@ function agyEnv(home, browser) {
|
|
|
129335
129379
|
return { GEMINI_HOME: home.geminiHome, BROWSER: browser };
|
|
129336
129380
|
}
|
|
129337
129381
|
function agyLaunch(home, archive, browser) {
|
|
129338
|
-
return { command: agyProgram(home, archive), args: [...archive.args], env: agyEnv(home, browser) };
|
|
129382
|
+
return { command: agyProgram(home, archive), args: [...archive.args], cwd: home.root, env: agyEnv(home, browser) };
|
|
129339
129383
|
}
|
|
129340
129384
|
|
|
129341
129385
|
// packages/agent-host/src/adapters/antigravity/shape.ts
|
|
@@ -129446,7 +129490,7 @@ async function runSignIn(home, archive, signal, deps = {}) {
|
|
|
129446
129490
|
openUrl(url2);
|
|
129447
129491
|
};
|
|
129448
129492
|
const launch2 = agyLaunch(home, archive, folder.browser);
|
|
129449
|
-
const spec = { ...launch2,
|
|
129493
|
+
const spec = { ...launch2, env: { ...process.env, ...launch2.env } };
|
|
129450
129494
|
const proc = startToolProcess(spec, deps.spawn ? { spawn: deps.spawn } : {});
|
|
129451
129495
|
const lines = lineSplitter((line) => {
|
|
129452
129496
|
const m = URL_LINE.exec(line);
|
|
@@ -129671,7 +129715,7 @@ async function gather() {
|
|
|
129671
129715
|
const home = agyHome(dataRoot(), AGY_RELEASE.version);
|
|
129672
129716
|
if (!archive || !isInstalled(home, archive)) throw new Error("Antigravity is not installed by Centralu on this machine");
|
|
129673
129717
|
const launch2 = agyLaunch(home, archive, "");
|
|
129674
|
-
const initialize = await acpInitialize({ ...launch2,
|
|
129718
|
+
const initialize = await acpInitialize({ ...launch2, env: { ...process.env, ...launch2.env } }, "antigravity-surface", agyStderrLine);
|
|
129675
129719
|
return { version: AGY_RELEASE.version, initialize };
|
|
129676
129720
|
}
|
|
129677
129721
|
function readAgySurface(inputs) {
|
|
@@ -132326,6 +132370,10 @@ var MidTurnLedger = class {
|
|
|
132326
132370
|
get tracking() {
|
|
132327
132371
|
return this.receipts.size;
|
|
132328
132372
|
}
|
|
132373
|
+
/** How many tracked inputs the tool has not taken yet: not the turn that is running, nor the one whose end is being said (`endingInputs`) */
|
|
132374
|
+
get untaken() {
|
|
132375
|
+
return this.receipts.untaken(this.ending ?? []);
|
|
132376
|
+
}
|
|
132329
132377
|
/** Every tracked input fails, and nothing is stopped (the turn already failed): the ids that did */
|
|
132330
132378
|
failTracked(reason) {
|
|
132331
132379
|
const ids = this.receipts.ids;
|
|
@@ -133925,11 +133973,11 @@ var ClaudeSession = class {
|
|
|
133925
133973
|
this.sendInput(text3, opts?.id !== void 0 && isUuid(opts.id) ? opts.id : centraluInputId(), void 0, opts?.origin, opts?.quiet);
|
|
133926
133974
|
}
|
|
133927
133975
|
/**
|
|
133928
|
-
* Inputs that will run as a turn and have not: waiting in the queue the CLI reads, or read and not named by a finished turn's result (`personInputs`)
|
|
133929
|
-
*
|
|
133976
|
+
* Inputs that will run as a turn and have not: waiting in the queue the CLI reads, or read and not named by a finished turn's result (`personInputs`),
|
|
133977
|
+
* and the tracked ones (mail, an update's Continue, a parent's note) no turn took yet, which the ledger counts (#2318 review). Quiet inputs start no turn
|
|
133930
133978
|
*/
|
|
133931
133979
|
queuedInputs() {
|
|
133932
|
-
return this.queue.filter((input) => !input.quiet && !input.parentNote).length + this.personInputs.size;
|
|
133980
|
+
return this.queue.filter((input) => !input.quiet && !input.parentNote).length + this.personInputs.size + this.ledger.untaken;
|
|
133933
133981
|
}
|
|
133934
133982
|
/** A note read with the next message or at the running turn's next tool round, starting nothing (#1492): quiet input, stamped as Centralu's */
|
|
133935
133983
|
nudge(text3) {
|
|
@@ -133946,16 +133994,16 @@ var ClaudeSession = class {
|
|
|
133946
133994
|
turnInputs() {
|
|
133947
133995
|
return this.ledger.endingInputs;
|
|
133948
133996
|
}
|
|
133949
|
-
sendInput(text3, uuid3 = centraluInputId(), note, origin,
|
|
133997
|
+
sendInput(text3, uuid3 = centraluInputId(), note, origin, quiet2) {
|
|
133950
133998
|
const goal = isGoalCommand(text3);
|
|
133951
133999
|
if (!this.sendGate && !(goal && this.goalCommand === void 0)) {
|
|
133952
|
-
this.deliver(text3, uuid3, !!note, origin,
|
|
134000
|
+
this.deliver(text3, uuid3, !!note, origin, quiet2);
|
|
133953
134001
|
return;
|
|
133954
134002
|
}
|
|
133955
134003
|
const gate = this.sendGate = (this.sendGate ?? this.goalKnown).then(() => {
|
|
133956
134004
|
if (note?.cancelled) return;
|
|
133957
134005
|
if (!this.closed) {
|
|
133958
|
-
this.deliver(text3, uuid3, !!note, origin,
|
|
134006
|
+
this.deliver(text3, uuid3, !!note, origin, quiet2);
|
|
133959
134007
|
return;
|
|
133960
134008
|
}
|
|
133961
134009
|
this.emit(undeliveredError(this.sessionId, 1, "were still queued when the session closed"));
|
|
@@ -133964,8 +134012,8 @@ var ClaudeSession = class {
|
|
|
133964
134012
|
if (this.sendGate === gate) this.sendGate = null;
|
|
133965
134013
|
});
|
|
133966
134014
|
}
|
|
133967
|
-
deliver(text3, uuid3, parentNote, origin,
|
|
133968
|
-
if (
|
|
134015
|
+
deliver(text3, uuid3, parentNote, origin, quiet2) {
|
|
134016
|
+
if (quiet2) {
|
|
133969
134017
|
const input = { text: text3, uuid: uuid3, parentNote, ...origin ? { origin } : {}, quiet: true };
|
|
133970
134018
|
this.quietInputs.set(uuid3, input);
|
|
133971
134019
|
this.queue.push(input);
|
|
@@ -134101,10 +134149,10 @@ var ClaudeSession = class {
|
|
|
134101
134149
|
for (const id3 of ids) if (this.personInputs.delete(id3)) count++;
|
|
134102
134150
|
this.reportUndelivered(count);
|
|
134103
134151
|
for (const id3 of ids) {
|
|
134104
|
-
const
|
|
134105
|
-
if (!
|
|
134152
|
+
const quiet2 = this.quietInputs.get(id3);
|
|
134153
|
+
if (!quiet2) continue;
|
|
134106
134154
|
this.quietInputs.delete(id3);
|
|
134107
|
-
this.deliver(
|
|
134155
|
+
this.deliver(quiet2.text, centraluInputId(), false, quiet2.origin, true);
|
|
134108
134156
|
}
|
|
134109
134157
|
}
|
|
134110
134158
|
}
|
|
@@ -138660,10 +138708,10 @@ var ProjectRegistry = class {
|
|
|
138660
138708
|
* session still starting included), else the one refusal. `boundary` names what crosses, in the refusal and in the
|
|
138661
138709
|
* log line each crossing writes; `quiet` for a re-read of a crossing already logged. A null caller is the person.
|
|
138662
138710
|
*/
|
|
138663
|
-
trustGate(callerId, projectId, boundary,
|
|
138711
|
+
trustGate(callerId, projectId, boundary, quiet2 = false) {
|
|
138664
138712
|
if (this.projectTrusted(projectId)) return null;
|
|
138665
138713
|
const name = this.projectRow(projectId)?.name ?? projectId;
|
|
138666
|
-
if (callerId && this.host.autoBoundaryOpen(callerId,
|
|
138714
|
+
if (callerId && this.host.autoBoundaryOpen(callerId, quiet2 ? void 0 : `${boundary} (untrusted project "${name}")`)) return null;
|
|
138667
138715
|
return `Project "${name}" is not trusted, so ${boundary} is refused \u2014 ${callerId ? `the person can trust it from the project menu. ${ASK_THE_PERSON}` : "trust it from the project menu."}`;
|
|
138668
138716
|
}
|
|
138669
138717
|
/**
|
|
@@ -140609,13 +140657,6 @@ var ChildOwnershipRecords = class {
|
|
|
140609
140657
|
this.db = db;
|
|
140610
140658
|
}
|
|
140611
140659
|
db;
|
|
140612
|
-
/**
|
|
140613
|
-
* The report marks a build of v70 to v73 leaves as it goes (`report_marks`, #646), deleted unread at every start: this build owes nothing by
|
|
140614
|
-
* them (docs/plans/mailbox.md §10.6.3), and that build, after a rollback, would make a task of one this build's tasks have since settled
|
|
140615
|
-
*/
|
|
140616
|
-
dropReportMarks() {
|
|
140617
|
-
this.db.prepare(`DELETE FROM report_marks`).run();
|
|
140618
|
-
}
|
|
140619
140660
|
// ── start_agent requests waiting for the person (#673) — see migration v50 ──
|
|
140620
140661
|
listAgentStartRequests() {
|
|
140621
140662
|
const rows3 = this.db.prepare(`SELECT request_id as requestId, caller_session_id as callerSessionId, request, asked_at as askedAt FROM agent_start_requests ORDER BY asked_at`).all();
|
|
@@ -141068,112 +141109,6 @@ var LinkedMachineRecords = class {
|
|
|
141068
141109
|
}
|
|
141069
141110
|
};
|
|
141070
141111
|
|
|
141071
|
-
// packages/agent-host/src/dev-services/store/mailbox-adopt.ts
|
|
141072
|
-
var MOVE_WITHIN_MS = 180 * 24 * 60 * 60 * 1e3;
|
|
141073
|
-
var CARRIED_HOLDS = /* @__PURE__ */ new Set([...RECIPIENT_HOLD_WORDS, "released"]);
|
|
141074
|
-
function kindOf3(m, threadOrigin) {
|
|
141075
|
-
const kinds = { assign: "message", question: "message", answer: "message", note: "message", report: "report", notice: "notice", event: "notice" };
|
|
141076
|
-
if (m.kind === "assign" && (threadOrigin === "person" || DELEGATION_ORIGINS.some((o) => o === threadOrigin))) return { kind: "task", needsReply: false };
|
|
141077
|
-
return { kind: kinds[m.kind], needsReply: m.kind === "question" };
|
|
141078
|
-
}
|
|
141079
|
-
function movePendingThreadMail(db, now, projectOf, holdsNow) {
|
|
141080
|
-
return db.transaction(() => {
|
|
141081
|
-
const pending = db.prepare(
|
|
141082
|
-
`SELECT m.*, r.recipient AS r_recipient, r.due_at AS r_due_at, r.attempt_at AS r_attempt_at, r.delivered_at AS r_delivered_at,
|
|
141083
|
-
r.read_at AS r_read_at, r.held AS r_held, r.attempts AS r_attempts, r.last_error AS r_last_error,
|
|
141084
|
-
t.project_id AS t_project_id, t.owner AS t_owner, t.assignee AS t_assignee, t.origin AS t_origin
|
|
141085
|
-
FROM mail_receipts r JOIN mail_messages m ON m.id = r.message_id JOIN mail_threads t ON t.id = m.thread_id
|
|
141086
|
-
WHERE r.handled_at IS NULL AND COALESCE(r.held, '') <> 'dismissed' AND m.created_at >= ?
|
|
141087
|
-
AND (r.delivered_at IS NULL OR r.read_at IS NULL OR m.kind = 'question')
|
|
141088
|
-
ORDER BY m.thread_id, m.seq, r.recipient`
|
|
141089
|
-
).all(now - MOVE_WITHIN_MS);
|
|
141090
|
-
const rootOf = db.prepare(`SELECT root_id FROM mail WHERE id = ?`);
|
|
141091
|
-
const insertMail = db.prepare(
|
|
141092
|
-
`INSERT OR IGNORE INTO mail (id, sender, sender_project, kind, needs_reply, reply_to, root_id, urgent, body, facts, origin, legacy_thread, created_at)
|
|
141093
|
-
VALUES (@id, @sender, @senderProject, @kind, @needsReply, @replyTo, @rootId, @urgent, @body, @facts, @origin, @legacyThread, @createdAt)`
|
|
141094
|
-
);
|
|
141095
|
-
const insertRow = db.prepare(
|
|
141096
|
-
`INSERT OR IGNORE INTO mail_recipients (message_id, recipient, via, due_at, attempt_at, delivered_at, read_at, held, attempts, last_error, settled, settled_at)
|
|
141097
|
-
VALUES (@messageId, @recipient, @via, @dueAt, @attemptAt, @deliveredAt, @readAt, @held, @attempts, @lastError, @settled, @now)`
|
|
141098
|
-
);
|
|
141099
|
-
const sessionRow = db.prepare(
|
|
141100
|
-
`SELECT is_orchestrator = 1 AND (project_id IS NULL OR deleted_at IS NOT NULL) AS assistant, deleted_at IS NOT NULL AS trashed FROM sessions WHERE id = ?`
|
|
141101
|
-
);
|
|
141102
|
-
const sessionOf = (address) => {
|
|
141103
|
-
const party = parseAddress(address);
|
|
141104
|
-
return party?.kind === "session" ? sessionRow.get(party.sessionId) : void 0;
|
|
141105
|
-
};
|
|
141106
|
-
const releasedTo = /* @__PURE__ */ new Map();
|
|
141107
|
-
for (const p of pending) if (p.r_held === "released") releasedTo.set(p.id, [...releasedTo.get(p.id) ?? [], p.r_recipient]);
|
|
141108
|
-
const handled = db.prepare(
|
|
141109
|
-
`UPDATE mail_receipts SET handled_at = @now, delivered_at = COALESCE(delivered_at, @now), read_at = COALESCE(read_at, @now) WHERE message_id = @id AND recipient = @recipient`
|
|
141110
|
-
);
|
|
141111
|
-
let messages2 = 0;
|
|
141112
|
-
let recipients = 0;
|
|
141113
|
-
for (const p of pending) {
|
|
141114
|
-
const m = toMessage(p);
|
|
141115
|
-
const sender = parseAddress(m.sender);
|
|
141116
|
-
const senderProject = sender?.kind === "session" ? projectOf(m.sender) ?? (m.sender === p.t_owner ? p.t_project_id : null) : null;
|
|
141117
|
-
const target = m.replyTo === null ? void 0 : rootOf.get(m.replyTo);
|
|
141118
|
-
const { kind, needsReply } = kindOf3(m, p.t_origin);
|
|
141119
|
-
const facts = {
|
|
141120
|
-
...factsFrom(m.facts),
|
|
141121
|
-
legacyKind: p.kind,
|
|
141122
|
-
...wakes(sender?.kind ?? "session", m) ? {} : { quiet: true },
|
|
141123
|
-
...m.needsOwner ? { needsOwner: true } : {},
|
|
141124
|
-
...releasedTo.has(m.id) ? { releasedTo: releasedTo.get(m.id) } : {}
|
|
141125
|
-
};
|
|
141126
|
-
const to = sessionOf(p.r_recipient);
|
|
141127
|
-
messages2 += insertMail.run({
|
|
141128
|
-
id: m.id,
|
|
141129
|
-
sender: m.sender,
|
|
141130
|
-
senderProject,
|
|
141131
|
-
kind,
|
|
141132
|
-
needsReply: needsReply ? 1 : 0,
|
|
141133
|
-
replyTo: target ? m.replyTo : null,
|
|
141134
|
-
rootId: target?.root_id ?? m.id,
|
|
141135
|
-
urgent: m.urgent ? 1 : 0,
|
|
141136
|
-
body: m.body,
|
|
141137
|
-
facts: JSON.stringify(facts),
|
|
141138
|
-
origin: m.seq === 1 ? p.t_origin : "mail",
|
|
141139
|
-
legacyThread: m.threadId,
|
|
141140
|
-
createdAt: m.createdAt
|
|
141141
|
-
}).changes;
|
|
141142
|
-
const via = p.r_recipient === p.t_assignee && to?.assistant === 1 && p.t_owner !== p.r_recipient ? ROLE_VIA : null;
|
|
141143
|
-
const carried = p.r_held !== null && CARRIED_HOLDS.has(p.r_held) ? p.r_held : null;
|
|
141144
|
-
const ended2 = p.r_held === "budget" || carried === "policy" && !holdsNow({ kind, senderProject }, p.r_recipient);
|
|
141145
|
-
recipients += insertRow.run({
|
|
141146
|
-
messageId: m.id,
|
|
141147
|
-
recipient: p.r_recipient,
|
|
141148
|
-
via,
|
|
141149
|
-
settled: kind === "task" && to?.trashed === 1 ? "gone" : "legacy",
|
|
141150
|
-
dueAt: p.r_due_at,
|
|
141151
|
-
attemptAt: ended2 ? null : p.r_attempt_at,
|
|
141152
|
-
deliveredAt: p.r_delivered_at,
|
|
141153
|
-
readAt: p.r_read_at,
|
|
141154
|
-
held: ended2 ? "dismissed" : carried,
|
|
141155
|
-
attempts: ended2 ? 0 : p.r_attempts,
|
|
141156
|
-
lastError: ended2 ? null : p.r_last_error,
|
|
141157
|
-
now
|
|
141158
|
-
}).changes;
|
|
141159
|
-
handled.run({ now, id: m.id, recipient: p.r_recipient });
|
|
141160
|
-
}
|
|
141161
|
-
return { messages: messages2, recipients };
|
|
141162
|
-
}).immediate();
|
|
141163
|
-
}
|
|
141164
|
-
function legacyChainFor(db, threadId, messageId, reader, limit) {
|
|
141165
|
-
return db.prepare(
|
|
141166
|
-
`SELECT * FROM (SELECT m.* FROM mail_messages m
|
|
141167
|
-
WHERE m.thread_id = @threadId AND m.seq < (SELECT seq FROM mail_messages WHERE id = @messageId)
|
|
141168
|
-
AND (m.sender = @reader OR EXISTS (SELECT 1 FROM mail_receipts r WHERE r.message_id = m.id AND r.recipient = @reader
|
|
141169
|
-
AND r.delivered_at IS NOT NULL AND COALESCE(r.held, 'released') = 'released'))
|
|
141170
|
-
ORDER BY m.seq DESC LIMIT @limit) ORDER BY seq`
|
|
141171
|
-
).all({ threadId, messageId, reader, limit }).map(toMessage);
|
|
141172
|
-
}
|
|
141173
|
-
function legacyChain(db, threadId, before, limit) {
|
|
141174
|
-
return db.prepare(`SELECT * FROM (SELECT * FROM mail_messages WHERE thread_id = ? AND seq < ? ORDER BY seq DESC LIMIT ?) ORDER BY seq`).all(threadId, before ?? Number.MAX_SAFE_INTEGER, limit).map(toMessage);
|
|
141175
|
-
}
|
|
141176
|
-
|
|
141177
141112
|
// packages/agent-host/src/dev-services/store/user-app-adoption.ts
|
|
141178
141113
|
var ADOPTED_USER_APPS_KEY = "apps.adoptedUserApps";
|
|
141179
141114
|
var BUILDERS_KEY = "apps.builders";
|
|
@@ -143618,7 +143553,7 @@ var StepsV65 = class extends MigrationRange {
|
|
|
143618
143553
|
* such row goes. A `policy` row settled `legacy` stays while `reach.holdFor` (mail/reach.ts) would hold it: a `message` from an untrusted project (a
|
|
143619
143554
|
* missing project row is untrusted) to a session of another project, which is how a genuine untrusted asker's request is still held. The
|
|
143620
143555
|
* delivery also holds moved rows that way (it judges a `legacy` row like any other, and `records.hold` writes `held` alone), so the same row looks
|
|
143621
|
-
* the same whoever held it, and this step cannot tell them apart; it asks the gate, as
|
|
143556
|
+
* the same whoever held it, and this step cannot tell them apart; it asks the gate, as step 75 asks it for the rows it moves (`endOldHolds`). What the
|
|
143622
143557
|
* gate would not hold goes, and what goes is `dismissed`, the hold word the person's Dismiss sets (not held for the person, never delivered):
|
|
143623
143558
|
* `gone` says a sender or recipient is gone and `withdrawn` that the sender said it no longer waits, and neither is so. `settled` stays `legacy`.
|
|
143624
143559
|
*
|
|
@@ -143639,17 +143574,7 @@ var StepsV65 = class extends MigrationRange {
|
|
|
143639
143574
|
run: () => {
|
|
143640
143575
|
if (this.db.prepare(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'mail_recipients'`).get() === void 0) return;
|
|
143641
143576
|
if (this.db.prepare(`SELECT 1 FROM mail_recipients WHERE held IN ('budget', 'policy') LIMIT 1`).get() === void 0) return;
|
|
143642
|
-
this.db
|
|
143643
|
-
`UPDATE mail_recipients SET held = 'dismissed', attempt_at = NULL, last_error = NULL, attempts = 0
|
|
143644
|
-
WHERE held = 'budget'
|
|
143645
|
-
OR (held = 'policy' AND settled = 'legacy' AND NOT EXISTS (
|
|
143646
|
-
SELECT 1 FROM mail m, sessions s
|
|
143647
|
-
WHERE m.id = mail_recipients.message_id AND m.kind = 'message' AND s.deleted_at IS NULL
|
|
143648
|
-
AND m.sender_project IS NOT NULL
|
|
143649
|
-
AND COALESCE((SELECT p.trusted FROM projects p WHERE p.id = m.sender_project), 0) = 0
|
|
143650
|
-
AND mail_recipients.recipient LIKE 'session:%' AND substr(mail_recipients.recipient, instr(mail_recipients.recipient, '/') + 1) = s.id
|
|
143651
|
-
AND s.project_id IS NOT m.sender_project))`
|
|
143652
|
-
);
|
|
143577
|
+
endOldHolds(this.db);
|
|
143653
143578
|
}
|
|
143654
143579
|
},
|
|
143655
143580
|
{
|
|
@@ -143706,7 +143631,7 @@ var StepsV65 = class extends MigrationRange {
|
|
|
143706
143631
|
* **A frozen copy of `MessageService.task`, its cut and the old adoption, on purpose**: a step runs once on every store and must not call
|
|
143707
143632
|
* code that may change. Only the id and address shapes are imported (mail/ids.ts, mail/address.ts), as the stored shapes they are.
|
|
143708
143633
|
*
|
|
143709
|
-
* The tables stay: the builds from v70 to v73 read them at every start. They go in
|
|
143634
|
+
* The tables stay: the builds from v70 to v73 read them at every start. They go in step 76, once step 75 has put the floor at 74.
|
|
143710
143635
|
*/
|
|
143711
143636
|
run: () => this.oneRecordOfOwedWork()
|
|
143712
143637
|
}
|
|
@@ -143785,6 +143710,21 @@ var OldWorkTasks = class {
|
|
|
143785
143710
|
this.row.run({ id: id3, recipient, project: session2.project, dueAt: t.delivered ? this.now : this.now + 2e3, delivered: t.delivered ? this.now : null });
|
|
143786
143711
|
}
|
|
143787
143712
|
};
|
|
143713
|
+
function endOldHolds(db, moved) {
|
|
143714
|
+
db.prepare(
|
|
143715
|
+
`UPDATE mail_recipients SET held = 'dismissed', attempt_at = NULL, last_error = NULL, attempts = 0
|
|
143716
|
+
WHERE held = 'budget'
|
|
143717
|
+
OR (held = 'policy'
|
|
143718
|
+
AND CASE WHEN @moved IS NULL THEN settled = 'legacy' ELSE rowid IN (SELECT value FROM json_each(@moved)) END
|
|
143719
|
+
AND NOT EXISTS (
|
|
143720
|
+
SELECT 1 FROM mail m, sessions s
|
|
143721
|
+
WHERE m.id = mail_recipients.message_id AND m.kind = 'message' AND s.deleted_at IS NULL
|
|
143722
|
+
AND m.sender_project IS NOT NULL
|
|
143723
|
+
AND COALESCE((SELECT p.trusted FROM projects p WHERE p.id = m.sender_project), 0) = 0
|
|
143724
|
+
AND mail_recipients.recipient LIKE 'session:%' AND substr(mail_recipients.recipient, instr(mail_recipients.recipient, '/') + 1) = s.id
|
|
143725
|
+
AND s.project_id IS NOT m.sender_project))`
|
|
143726
|
+
).run({ moved: moved ? JSON.stringify(moved) : null });
|
|
143727
|
+
}
|
|
143788
143728
|
function addresses(host, callerId, sessionId) {
|
|
143789
143729
|
try {
|
|
143790
143730
|
return [sessionAddress(host, callerId), sessionAddress(host, sessionId)];
|
|
@@ -143793,6 +143733,162 @@ function addresses(host, callerId, sessionId) {
|
|
|
143793
143733
|
}
|
|
143794
143734
|
}
|
|
143795
143735
|
|
|
143736
|
+
// packages/agent-host/src/dev-services/store/migrations/v75.ts
|
|
143737
|
+
var StepsV75 = class extends MigrationRange {
|
|
143738
|
+
steps() {
|
|
143739
|
+
return [
|
|
143740
|
+
{
|
|
143741
|
+
to: 75,
|
|
143742
|
+
breaksOlderReaders: true,
|
|
143743
|
+
minReader: 74,
|
|
143744
|
+
/**
|
|
143745
|
+
* The last move of thread mail (#2258 item 1, docs/plans/mailbox.md §6.3, M7): what a build of v61 to v64 left pending in its thread
|
|
143746
|
+
* tables (`mail_threads`, `mail_messages`, `mail_receipts`) becomes mail once, here. Until this step the host moved it at every start
|
|
143747
|
+
* and read the old tables for the lines before a moved message. From this build on only a migration step names those tables, the two
|
|
143748
|
+
* beside them (`mail_participants`, `mail_blockers`), `report_marks`, `delegated_turns`, `queued_requests` or `sessions.mail_args`.
|
|
143749
|
+
*
|
|
143750
|
+
* Pending is a receipt not handled, not dismissed by the person, of a message sent in the last 180 days (retention would not have kept
|
|
143751
|
+
* an older one waiting), that is not delivered, not read, or a `question` (read and not answered). Each message is copied once under its
|
|
143752
|
+
* own id, its rows settled `legacy` (never awaited), and each old receipt is marked handled, delivered and read. A row to the Assistant in
|
|
143753
|
+
* a session's request (the old thread's assignee, the Assistant or a trashed one) is sent to the role (`via`), so the next Assistant
|
|
143754
|
+
* takes it; a task to a trashed session is settled `gone`. A row the person released is never held again (`releasedTo`). A hold an
|
|
143755
|
+
* earlier build set stays only if today's gate would hold the mail now, as step 72 judged the rows moved before it (`endOldHolds`).
|
|
143756
|
+
* A `policy` hold is judged on the rows this step writes only, since a row moved at an earlier start may be held by the delivery's own
|
|
143757
|
+
* judgement; a `budget` hold, which no delivery sets, ends on whatever row carries it.
|
|
143758
|
+
*
|
|
143759
|
+
* **A frozen copy of the move the host ran (`movePendingThreadMail`) and of what it called, on purpose**: a step runs once on every
|
|
143760
|
+
* store and must not call code that may change. Only the address shape is imported (mail/address.ts), as the stored shape it is. One
|
|
143761
|
+
* thing is read differently: a sender's project comes from its `sessions` row by the session id alone, where the host asked only for a
|
|
143762
|
+
* session of its own (as step 72 reads a recipient's).
|
|
143763
|
+
*
|
|
143764
|
+
* **Breaks the builds of v70 to v73 (beta.58 to beta.69): the floor goes to 74.** Those builds leave a report mark for every session in
|
|
143765
|
+
* a turn as they go, and make a task of each mark at their next start. This build deleted the marks at every start, so that one left
|
|
143766
|
+
* during a rollback never became a task for work settled since; it no longer names `report_marks`, so those builds are refused instead
|
|
143767
|
+
* (`StoreTooNewError`). The build of v74 (beta.70 to beta.72) writes no mark, and its own move at every start finds each receipt handled:
|
|
143768
|
+
* it opens the store and serves it as before. The tables stay for it, unread by this build, and go in the next step.
|
|
143769
|
+
*/
|
|
143770
|
+
run: () => this.moveThreadMail()
|
|
143771
|
+
}
|
|
143772
|
+
];
|
|
143773
|
+
}
|
|
143774
|
+
/** Step 75: every pending receipt of the thread tables written as mail, and the old receipt marked handled */
|
|
143775
|
+
moveThreadMail() {
|
|
143776
|
+
const has = (table) => this.db.prepare(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`).get(table) !== void 0;
|
|
143777
|
+
if (!["mail_threads", "mail_messages", "mail_receipts", "mail", "mail_recipients", "sessions", "projects"].every(has)) return;
|
|
143778
|
+
const now = Date.now();
|
|
143779
|
+
const pending = this.pendingReceipts(now);
|
|
143780
|
+
if (pending.length === 0) return;
|
|
143781
|
+
const rootOf = this.db.prepare(`SELECT root_id FROM mail WHERE id = ?`);
|
|
143782
|
+
const insertMail = this.db.prepare(
|
|
143783
|
+
`INSERT OR IGNORE INTO mail (id, sender, sender_project, kind, needs_reply, reply_to, root_id, urgent, body, facts, origin, legacy_thread, created_at)
|
|
143784
|
+
VALUES (@id, @sender, @senderProject, @kind, @needsReply, @replyTo, @rootId, @urgent, @body, @facts, @origin, @legacyThread, @createdAt)`
|
|
143785
|
+
);
|
|
143786
|
+
const insertRow = this.db.prepare(
|
|
143787
|
+
`INSERT OR IGNORE INTO mail_recipients (message_id, recipient, via, due_at, attempt_at, delivered_at, read_at, held, attempts, last_error, settled, settled_at)
|
|
143788
|
+
VALUES (@messageId, @recipient, @via, @dueAt, @attemptAt, @deliveredAt, @readAt, @held, @attempts, @lastError, @settled, @now)`
|
|
143789
|
+
);
|
|
143790
|
+
const handled = this.db.prepare(
|
|
143791
|
+
`UPDATE mail_receipts SET handled_at = @now, delivered_at = COALESCE(delivered_at, @now), read_at = COALESCE(read_at, @now) WHERE message_id = @id AND recipient = @recipient`
|
|
143792
|
+
);
|
|
143793
|
+
const sessionRow = this.db.prepare(
|
|
143794
|
+
`SELECT project_id AS project, is_assistant = 1 AND (project_id IS NULL OR deleted_at IS NOT NULL) AS assistant, deleted_at IS NOT NULL AS trashed FROM sessions WHERE id = ?`
|
|
143795
|
+
);
|
|
143796
|
+
const sessionOf = (address) => {
|
|
143797
|
+
const party = parseAddress(address);
|
|
143798
|
+
return party?.kind === "session" ? sessionRow.get(party.sessionId) : void 0;
|
|
143799
|
+
};
|
|
143800
|
+
const releasedTo = /* @__PURE__ */ new Map();
|
|
143801
|
+
for (const p of pending) if (p.held === "released") releasedTo.set(p.id, [...releasedTo.get(p.id) ?? [], p.recipient]);
|
|
143802
|
+
const moved = [];
|
|
143803
|
+
for (const p of pending) {
|
|
143804
|
+
const sender = parseAddress(p.sender);
|
|
143805
|
+
const from = sessionOf(p.sender);
|
|
143806
|
+
const senderProject = sender?.kind === "session" ? (from?.trashed === 0 ? from.project : null) ?? (p.sender === p.t_owner ? p.t_project_id : null) : null;
|
|
143807
|
+
const target = p.reply_to === null ? void 0 : rootOf.get(p.reply_to);
|
|
143808
|
+
const kind = movedKind(p.kind, p.t_origin);
|
|
143809
|
+
const facts = {
|
|
143810
|
+
...movedFacts(p.facts),
|
|
143811
|
+
legacyKind: p.kind,
|
|
143812
|
+
...quiet(sender?.kind ?? "session", p) ? { quiet: true } : {},
|
|
143813
|
+
...p.needs_owner === 1 ? { needsOwner: true } : {},
|
|
143814
|
+
...releasedTo.has(p.id) ? { releasedTo: releasedTo.get(p.id) } : {}
|
|
143815
|
+
};
|
|
143816
|
+
insertMail.run({
|
|
143817
|
+
id: p.id,
|
|
143818
|
+
sender: p.sender,
|
|
143819
|
+
senderProject,
|
|
143820
|
+
kind,
|
|
143821
|
+
needsReply: p.kind === "question" ? 1 : 0,
|
|
143822
|
+
// The order is a thread's own (`seq`), so a reply finds its target moved before it, whatever their times say
|
|
143823
|
+
replyTo: target ? p.reply_to : null,
|
|
143824
|
+
rootId: target?.root_id ?? p.id,
|
|
143825
|
+
urgent: p.urgent === 1 ? 1 : 0,
|
|
143826
|
+
body: p.body,
|
|
143827
|
+
facts: JSON.stringify(facts),
|
|
143828
|
+
origin: p.seq === 1 ? p.t_origin : "mail",
|
|
143829
|
+
legacyThread: p.thread_id,
|
|
143830
|
+
createdAt: p.created_at
|
|
143831
|
+
});
|
|
143832
|
+
const to = sessionOf(p.recipient);
|
|
143833
|
+
const row = insertRow.run({
|
|
143834
|
+
messageId: p.id,
|
|
143835
|
+
recipient: p.recipient,
|
|
143836
|
+
via: p.recipient === p.t_assignee && to?.assistant === 1 && p.t_owner !== p.recipient ? "assistant" : null,
|
|
143837
|
+
dueAt: p.due_at,
|
|
143838
|
+
attemptAt: p.attempt_at,
|
|
143839
|
+
deliveredAt: p.delivered_at,
|
|
143840
|
+
readAt: p.read_at,
|
|
143841
|
+
held: p.held !== null && CARRIED_HOLDS.includes(p.held) ? p.held : null,
|
|
143842
|
+
attempts: p.attempts,
|
|
143843
|
+
lastError: p.last_error,
|
|
143844
|
+
settled: kind === "task" && to?.trashed === 1 ? "gone" : "legacy",
|
|
143845
|
+
now
|
|
143846
|
+
});
|
|
143847
|
+
if (row.changes === 1) moved.push(Number(row.lastInsertRowid));
|
|
143848
|
+
handled.run({ now, id: p.id, recipient: p.recipient });
|
|
143849
|
+
}
|
|
143850
|
+
endOldHolds(this.db, moved);
|
|
143851
|
+
}
|
|
143852
|
+
/** The receipts still pending at `now`, each with its message and what the move reads of its thread, in each thread's own order */
|
|
143853
|
+
pendingReceipts(now) {
|
|
143854
|
+
return this.db.prepare(
|
|
143855
|
+
`SELECT m.id, m.thread_id, m.seq, m.sender, m.kind, m.urgent, m.needs_owner, m.wake, m.reply_to, m.body, m.facts, m.created_at,
|
|
143856
|
+
r.recipient, r.due_at, r.attempt_at, r.delivered_at, r.read_at, r.held, r.attempts, r.last_error,
|
|
143857
|
+
t.project_id AS t_project_id, t.owner AS t_owner, t.assignee AS t_assignee, t.origin AS t_origin
|
|
143858
|
+
FROM mail_receipts r JOIN mail_messages m ON m.id = r.message_id JOIN mail_threads t ON t.id = m.thread_id
|
|
143859
|
+
WHERE r.handled_at IS NULL AND COALESCE(r.held, '') <> 'dismissed' AND m.created_at >= ?
|
|
143860
|
+
AND (r.delivered_at IS NULL OR r.read_at IS NULL OR m.kind = 'question')
|
|
143861
|
+
ORDER BY m.thread_id, m.seq, r.recipient`
|
|
143862
|
+
).all(now - MOVE_WITHIN_MS);
|
|
143863
|
+
}
|
|
143864
|
+
};
|
|
143865
|
+
var MOVE_WITHIN_MS = 180 * 24 * 60 * 60 * 1e3;
|
|
143866
|
+
var CARRIED_HOLDS = ["uncertain", "failed", "loop", "policy", "released", "budget"];
|
|
143867
|
+
var TASK_ORIGINS = ["person", "start_agent", "agent_session", "send_to_session", "create_session", "ask_project"];
|
|
143868
|
+
function movedKind(kind, threadOrigin) {
|
|
143869
|
+
if (kind === "assign" && TASK_ORIGINS.includes(threadOrigin)) return "task";
|
|
143870
|
+
if (kind === "report") return "report";
|
|
143871
|
+
return kind === "notice" || kind === "event" ? "notice" : "message";
|
|
143872
|
+
}
|
|
143873
|
+
function movedFacts(raw) {
|
|
143874
|
+
let value;
|
|
143875
|
+
try {
|
|
143876
|
+
value = JSON.parse(raw);
|
|
143877
|
+
} catch {
|
|
143878
|
+
return {};
|
|
143879
|
+
}
|
|
143880
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
|
|
143881
|
+
const facts = { ...value };
|
|
143882
|
+
if (Array.isArray(facts.waitingOn)) facts.waitingOn = facts.waitingOn.length;
|
|
143883
|
+
return facts;
|
|
143884
|
+
}
|
|
143885
|
+
function quiet(senderKind2, m) {
|
|
143886
|
+
if (m.kind === "event") return true;
|
|
143887
|
+
if (senderKind2 === "centralu") return m.wake === "no";
|
|
143888
|
+
if (senderKind2 !== "app") return false;
|
|
143889
|
+
return m.wake === "no" || m.kind === "notice" && m.needs_owner !== 1 && m.wake !== "yes";
|
|
143890
|
+
}
|
|
143891
|
+
|
|
143796
143892
|
// packages/agent-host/src/dev-services/store/migrations/index.ts
|
|
143797
143893
|
function migrationSteps(host) {
|
|
143798
143894
|
return [
|
|
@@ -143804,7 +143900,8 @@ function migrationSteps(host) {
|
|
|
143804
143900
|
...new StepsV55(host).steps(),
|
|
143805
143901
|
...new StepsV58(host).steps(),
|
|
143806
143902
|
...new StepsV62(host).steps(),
|
|
143807
|
-
...new StepsV65(host).steps()
|
|
143903
|
+
...new StepsV65(host).steps(),
|
|
143904
|
+
...new StepsV75(host).steps()
|
|
143808
143905
|
];
|
|
143809
143906
|
}
|
|
143810
143907
|
|
|
@@ -144458,8 +144555,6 @@ var TrashRecords = class {
|
|
|
144458
144555
|
const host = this.db.prepare(`SELECT value FROM app_settings WHERE key = ?`).get(HUB_SELF_KEY)?.value;
|
|
144459
144556
|
if (host) {
|
|
144460
144557
|
const address = `session:${host}/${sessionId}`;
|
|
144461
|
-
this.db.prepare(`DELETE FROM mail_receipts WHERE recipient = ?`).run(address);
|
|
144462
|
-
this.db.prepare(`DELETE FROM mail_participants WHERE address = ?`).run(address);
|
|
144463
144558
|
this.mailbox.purgeParty(address);
|
|
144464
144559
|
}
|
|
144465
144560
|
this.db.prepare(`DELETE FROM mail_turns WHERE session_id = ?`).run(sessionId);
|
|
@@ -144834,21 +144929,6 @@ var Store = class extends MigrationRunner {
|
|
|
144834
144929
|
this.db.pragma(`busy_timeout = ${wait}`);
|
|
144835
144930
|
}
|
|
144836
144931
|
}
|
|
144837
|
-
/**
|
|
144838
|
-
* The thread mail an older build left pending, moved into the message tables and marked handled in the old ones, in one transaction
|
|
144839
|
-
* (docs/plans/mailbox.md §6.3): run after every `ready` from M3a to M7, before delivery starts. A second run finds nothing
|
|
144840
|
-
*/
|
|
144841
|
-
movePendingThreadMail(now, projectOf, holdsNow) {
|
|
144842
|
-
return movePendingThreadMail(this.db, now, projectOf, holdsNow);
|
|
144843
|
-
}
|
|
144844
|
-
/** An old thread's messages, read-only (§6.3): the earlier history of a moved message (`legacy_thread`) */
|
|
144845
|
-
legacyChain(threadId, before, limit) {
|
|
144846
|
-
return legacyChain(this.db, threadId, before, limit);
|
|
144847
|
-
}
|
|
144848
|
-
/** What `reader` was shown of an old thread before a moved message (§6.3, `legacyChainFor`) */
|
|
144849
|
-
legacyChainFor(threadId, messageId, reader, limit) {
|
|
144850
|
-
return legacyChainFor(this.db, threadId, messageId, reader, limit);
|
|
144851
|
-
}
|
|
144852
144932
|
/** The migration list. `store/migrations/index.ts` holds it, and the rule a new step follows */
|
|
144853
144933
|
migrationSteps() {
|
|
144854
144934
|
return migrationSteps({
|
|
@@ -145454,12 +145534,12 @@ var AskProjectFlow = class {
|
|
|
145454
145534
|
* already logged the `auto` boundary it opens, so this one does not log it again. `trust`: false leaves the project's
|
|
145455
145535
|
* trust out, for the one read that decides it once the target is known (§7.4).
|
|
145456
145536
|
*/
|
|
145457
|
-
askGateError(callerId,
|
|
145537
|
+
askGateError(callerId, quiet2 = false, trust = true) {
|
|
145458
145538
|
const caller = this.host.meta.get(callerId);
|
|
145459
145539
|
if (!caller?.projectId) return "This session belongs to no project, so it cannot ask another one";
|
|
145460
145540
|
const deep = agentDepthRefusal(this.host, callerId, "ask a project");
|
|
145461
145541
|
if (deep) return deep;
|
|
145462
|
-
return trust ? this.host.trustGate(callerId, caller.projectId, "asking another project",
|
|
145542
|
+
return trust ? this.host.trustGate(callerId, caller.projectId, "asking another project", quiet2) : null;
|
|
145463
145543
|
}
|
|
145464
145544
|
/** The project asked is still registered: the person may remove it while its card stands */
|
|
145465
145545
|
projectGoneError(target) {
|
|
@@ -149739,8 +149819,8 @@ var MessageService = class {
|
|
|
149739
149819
|
const urgent = input.urgent === true;
|
|
149740
149820
|
const senderProject = this.reach.projectOf(sender);
|
|
149741
149821
|
const holds = to.map((r) => this.reach.holdFor({ kind: "message", senderProject }, r));
|
|
149742
|
-
const
|
|
149743
|
-
const facts = { ...clarifies !== void 0 ? { clarifies } : {}, ...
|
|
149822
|
+
const quiet2 = kind === "message" && target !== void 0 && to.length === 1 && to[0] === target.sender && quietAnswer({ kind, sender, needsReply, urgent }, target, { parent: this.reach.parentOf(target.sender), owesTask: this.records.newestTask(sender, target.sender) !== void 0, request: requests2[0] === true });
|
|
149823
|
+
const facts = { ...clarifies !== void 0 ? { clarifies } : {}, ...quiet2 ? { quiet: true } : {}, ...cited ? { cites: cited } : {}, ...input.picked && cls === "person" ? { picked: true } : {} };
|
|
149744
149824
|
const stored = this.put(
|
|
149745
149825
|
// The citation's one use: `UNIQUE(sender, dedupe_key)` (`personWord` looked first, in this transaction)
|
|
149746
149826
|
{ ...input.id ? { id: input.id } : {}, sender, kind, body: text3, needsReply, replyTo: target?.id ?? null, causeId, depth: 0, urgent, facts, choices: choices ?? null, subject: !target && input.subject && oneLineText(input.subject, SUBJECT_CHARS) || null, origin: cls === "person" ? "person" : cls === "app" ? "app" : "mail", ...cited ? { dedupeKey: citeKey(cited.seq) } : {} },
|
|
@@ -149753,7 +149833,7 @@ var MessageService = class {
|
|
|
149753
149833
|
if (held3.length === 0) this.records.settle(target.id, sender, "answered", now, stored.id);
|
|
149754
149834
|
else this.answerHeld(target, stored);
|
|
149755
149835
|
}
|
|
149756
|
-
return { message: stored, held: held3, answered: target?.id ?? null, answers: answers2, quiet, asWork, ...cited ? { cited } : {}, ...typeof word === "string" ? { notCited: word } : {} };
|
|
149836
|
+
return { message: stored, held: held3, answered: target?.id ?? null, answers: answers2, quiet: quiet2, asWork, ...cited ? { cited } : {}, ...typeof word === "string" ? { notCited: word } : {} };
|
|
149757
149837
|
});
|
|
149758
149838
|
}
|
|
149759
149839
|
/** A new message id of this host's, for a message another host writes first (#2067 review, `MailAcross.send`) */
|
|
@@ -150028,8 +150108,7 @@ var MessageService = class {
|
|
|
150028
150108
|
relations.add(relation);
|
|
150029
150109
|
items.push(this.frameItem(recipient, message, relation, down && row.deliveredAt === null, row.lastError === "maybe_repeated"));
|
|
150030
150110
|
}
|
|
150031
|
-
const
|
|
150032
|
-
const frame = buildMessageFrame(items, calls);
|
|
150111
|
+
const frame = buildMessageFrame(items, this.opts.calls?.(recipient));
|
|
150033
150112
|
return {
|
|
150034
150113
|
text: frame.text,
|
|
150035
150114
|
messageIds: frame.shown,
|
|
@@ -150581,24 +150660,21 @@ var MailPerson = class {
|
|
|
150581
150660
|
const root3 = this.rootsOf(threadId)[0];
|
|
150582
150661
|
if (root3 === void 0) throw refuse4("unknown_message", `There is no mail ${threadId} kept.`);
|
|
150583
150662
|
const all = this.records.numbered(root3, CHAIN_CAP).map(({ m, n }) => ({ m, seq: n })).filter((s) => this.readable(s.m) || !this.involves(s.m));
|
|
150584
|
-
const lookIn = !all.some((s) => this.readable(s.m));
|
|
150663
|
+
const lookIn = opts.lookIn === true || !all.some((s) => this.readable(s.m));
|
|
150585
150664
|
let page;
|
|
150586
150665
|
if (opts.after !== void 0) page = all.filter((s) => s.seq > (opts.after ?? 0)).slice(0, opts.all ? void 0 : THREAD_PAGE);
|
|
150587
150666
|
else if (opts.tail !== void 0 || !opts.all) {
|
|
150588
150667
|
const upTo = opts.before === void 0 ? all : all.filter((s) => s.seq < (opts.before ?? 0));
|
|
150589
150668
|
page = upTo.slice(-Math.min(opts.tail ?? THREAD_PAGE, THREAD_PAGE));
|
|
150590
150669
|
} else page = all;
|
|
150591
|
-
this.readFor(page);
|
|
150670
|
+
if (!lookIn) this.readFor(page);
|
|
150592
150671
|
const first = page[0]?.seq;
|
|
150593
150672
|
const last = page.at(-1)?.seq;
|
|
150594
|
-
const legacy = this.legacyOf(all[0]?.m);
|
|
150595
|
-
const fromStart = first === void 0 || first === all[0]?.seq;
|
|
150596
|
-
const messages2 = [...(fromStart ? legacy : []).map((m, i) => legacyMessage(m, i - legacy.length + 1, (a) => this.party(a))), ...page.map((s) => this.message(s))];
|
|
150597
150673
|
return {
|
|
150598
150674
|
thread: this.row(root3, this.heldIn(root3)) ?? this.lookInRow(root3),
|
|
150599
150675
|
parties: this.partiesOf(all.map((s) => s.m)),
|
|
150600
150676
|
blockers: [],
|
|
150601
|
-
messages:
|
|
150677
|
+
messages: page.map((s) => this.message(s)),
|
|
150602
150678
|
more: last !== void 0 && all.some((s) => s.seq > last),
|
|
150603
150679
|
older: first !== void 0 && all.some((s) => s.seq < first),
|
|
150604
150680
|
follows: [],
|
|
@@ -150834,17 +150910,6 @@ var MailPerson = class {
|
|
|
150834
150910
|
if (m.sender === PERSON) return true;
|
|
150835
150911
|
return this.records.recipients(m.id).some((r) => r.recipient === PERSON || isPersonHold(r.held));
|
|
150836
150912
|
}
|
|
150837
|
-
/** An old thread's messages before the first one moved from it: the chain's history, read-only (§6.3) */
|
|
150838
|
-
legacyOf(first) {
|
|
150839
|
-
if (!first?.legacyThread) return [];
|
|
150840
|
-
const moved = new Set(this.records.byRoot(first.rootId, { limit: CHAIN_CAP }).map((m) => m.id));
|
|
150841
|
-
const earlier = [];
|
|
150842
|
-
for (const m of this.host.legacyChain(first.legacyThread)) {
|
|
150843
|
-
if (m.id === first.id || moved.has(m.id)) break;
|
|
150844
|
-
earlier.push(m);
|
|
150845
|
-
}
|
|
150846
|
-
return earlier;
|
|
150847
|
-
}
|
|
150848
150913
|
heldIn(root3) {
|
|
150849
150914
|
return this.records.heldRows().filter((r) => this.records.message(r.messageId)?.rootId === root3).length;
|
|
150850
150915
|
}
|
|
@@ -151013,9 +151078,6 @@ function taskState(m, r, on2) {
|
|
|
151013
151078
|
function hasTask(m, r) {
|
|
151014
151079
|
return m.kind === "task" && parseAddress(r.recipient)?.kind === "session" && r.settled === null && r.releasedAt === null;
|
|
151015
151080
|
}
|
|
151016
|
-
function legacyMessage(m, seq, party) {
|
|
151017
|
-
return { id: m.id, seq, sender: party(m.sender), kind: m.kind, urgent: m.urgent, body: m.body, facts: { ...m.facts }, createdAt: m.createdAt };
|
|
151018
|
-
}
|
|
151019
151081
|
function isPersonHold(held3) {
|
|
151020
151082
|
return PERSON_HOLDS.some((h) => h === held3);
|
|
151021
151083
|
}
|
|
@@ -151563,7 +151625,7 @@ var MailTool = class {
|
|
|
151563
151625
|
try {
|
|
151564
151626
|
const me2 = this.host.caller(sessionId);
|
|
151565
151627
|
if (!me2) throw refuse4("gone", "this session is not here");
|
|
151566
|
-
return { text: this.dispatch(sessionId, me2, args, mailCalls(
|
|
151628
|
+
return { text: this.dispatch(sessionId, me2, args, mailCalls(this.host.form(sessionId))) };
|
|
151567
151629
|
} catch (e) {
|
|
151568
151630
|
return failed4(e);
|
|
151569
151631
|
}
|
|
@@ -151581,7 +151643,7 @@ var MailTool = class {
|
|
|
151581
151643
|
const pr = args.action === "watch" ? prNumberOf(args.to ?? "") : null;
|
|
151582
151644
|
if (pr !== null) {
|
|
151583
151645
|
const watches = this.watchArgs(args);
|
|
151584
|
-
return { text: await watches.registerPr(me2.address, pr, args.text?.trim() ?? "", (id3) => mailCalls(
|
|
151646
|
+
return { text: await watches.registerPr(me2.address, pr, args.text?.trim() ?? "", (id3) => mailCalls(this.host.form(sessionId)).close(id3), signal) };
|
|
151585
151647
|
}
|
|
151586
151648
|
if (args.action === "find") {
|
|
151587
151649
|
if (!across) return { text: "Finding sessions is not available here.", isError: true };
|
|
@@ -151841,25 +151903,11 @@ var MailTool = class {
|
|
|
151841
151903
|
const chain = id3 === void 0 ? v.items : v.items.slice(0, -1);
|
|
151842
151904
|
if (base2 && chain.length > 0) out.push("Earlier in this chain:");
|
|
151843
151905
|
for (const item of chain) out.push(this.shown(me2, item));
|
|
151844
|
-
if (base2)
|
|
151845
|
-
const legacy = base2.message.legacyThread;
|
|
151846
|
-
if (legacy && !base2.phantom && chain.length === 0) out.unshift(...this.legacy(me2, legacy, base2.message.id));
|
|
151847
|
-
out.push(this.shown(me2, base2));
|
|
151848
|
-
}
|
|
151906
|
+
if (base2) out.push(this.shown(me2, base2));
|
|
151849
151907
|
if (v.older) out.push(`Older messages in this chain: ${calls.read(v.older)}.`);
|
|
151850
151908
|
if (id3 === void 0 && v.items.length > 0) out.push(`There may be more: ${calls.read()}.`);
|
|
151851
151909
|
return out.join("\n");
|
|
151852
151910
|
}
|
|
151853
|
-
/** The earlier messages of the thread a moved message came from, read-only (§6.3), each quoted under its sender */
|
|
151854
|
-
legacy(me2, threadId, moved) {
|
|
151855
|
-
const earlier = this.host.legacyChain(threadId, moved, me2);
|
|
151856
|
-
if (earlier.length === 0) return [];
|
|
151857
|
-
return [
|
|
151858
|
-
`Earlier, in thread ${threadId} (kept from before Centralu's mail had no threads):`,
|
|
151859
|
-
...earlier.map((m) => `[${m.id}] ${m.kind} from ${m.sender === me2 ? "you" : this.name(m.sender)}:
|
|
151860
|
-
${quoted2(escapeFrameTags(m.body))}`)
|
|
151861
|
-
];
|
|
151862
|
-
}
|
|
151863
151911
|
/** One message under Centralu's header (S5); a phantom is one line without words */
|
|
151864
151912
|
shown(me2, i) {
|
|
151865
151913
|
const m = i.message;
|
|
@@ -152004,6 +152052,10 @@ var AcrossCore = class {
|
|
|
152004
152052
|
*/
|
|
152005
152053
|
unsure = /* @__PURE__ */ new Map();
|
|
152006
152054
|
now;
|
|
152055
|
+
/** This host's id in mail addresses: a hub that links it reads its mail in the hub's terms by it (`host.hubOffer`'s answer, #2268) */
|
|
152056
|
+
get hostId() {
|
|
152057
|
+
return this.d.hostId;
|
|
152058
|
+
}
|
|
152007
152059
|
// ── Addresses ──
|
|
152008
152060
|
route(address) {
|
|
152009
152061
|
const p = parseAddress(address);
|
|
@@ -152044,10 +152096,8 @@ var AcrossCore = class {
|
|
|
152044
152096
|
}
|
|
152045
152097
|
/** On a machine, its own session as the hub `hubId` names it */
|
|
152046
152098
|
asHubNames(hubId, address) {
|
|
152047
|
-
if (address === sessionAddress(hubId, PERSON_ID)) return PERSON;
|
|
152048
152099
|
const you = this.peers?.hub?.(hubId)?.you;
|
|
152049
|
-
|
|
152050
|
-
return you && p?.kind === "session" && p.host === this.d.hostId && !p.sessionId.includes(".") ? sessionAddress(hubId, `${you}.${p.sessionId}`) : address;
|
|
152100
|
+
return inHubTerms(address, hubId, you ? { host: this.d.hostId, id: you } : void 0);
|
|
152051
152101
|
}
|
|
152052
152102
|
/** On a machine, an address as the hub `hubId` names it, as this host names it (its own sessions are its own again) */
|
|
152053
152103
|
fromHubNames(hubId, address) {
|
|
@@ -152467,7 +152517,15 @@ function mayReachAcross(_from, _to) {
|
|
|
152467
152517
|
var FOREIGN_ID = /^[^\s/]{1,120}\.m_[0-9A-Za-z]{10,40}$/;
|
|
152468
152518
|
var FIND_MS = 4e3;
|
|
152469
152519
|
var NAMED_HERE_MS = 600;
|
|
152520
|
+
var OPEN_ASKED = 500;
|
|
152521
|
+
var ASKED_WITHIN = MAILBOX_RETENTION.settledMs - 24 * 60 * 60 * 1e3;
|
|
152522
|
+
var LACKED_MAX = 5e3;
|
|
152523
|
+
var NAMED_MAX = 10;
|
|
152470
152524
|
var MailAcross = class extends AcrossReceipts {
|
|
152525
|
+
/** On a hub: tasks whose `host.mail` is under way now, which an offer neither asks about nor deletes */
|
|
152526
|
+
sending = /* @__PURE__ */ new Set();
|
|
152527
|
+
/** On a machine: tasks it told a hub never arrived (`lacking`), by hub, so one hub's many cannot push another's out under `LACKED_MAX` */
|
|
152528
|
+
lacked = /* @__PURE__ */ new Map();
|
|
152471
152529
|
// ── Sending from here ──
|
|
152472
152530
|
/**
|
|
152473
152531
|
* A session's message to a session on another host (`to`: an address, or `parent` for a session a hub started here).
|
|
@@ -152513,7 +152571,8 @@ var MailAcross = class extends AcrossReceipts {
|
|
|
152513
152571
|
return { ok: false, why: "failed", text: `this computer could not keep its copy of the task, so nothing was sent: ${oneLineText(errorMessage(e), 500)}` };
|
|
152514
152572
|
}
|
|
152515
152573
|
}
|
|
152516
|
-
|
|
152574
|
+
this.sending.add(id3);
|
|
152575
|
+
const r = this.settle(id3, await this.ask(m, "host.mail", params).finally(() => this.sending.delete(id3)));
|
|
152517
152576
|
if (!r.ok) {
|
|
152518
152577
|
if (!r.maybe) this.d.records.deleteRows([{ messageId: id3, recipient: to }]);
|
|
152519
152578
|
return { ok: false, why: r.why, text: r.text };
|
|
@@ -152521,6 +152580,52 @@ var MailAcross = class extends AcrossReceipts {
|
|
|
152521
152580
|
this.names.set(to, `${r.to} on ${m.name}`);
|
|
152522
152581
|
return { ok: true, messageId: id3, to: r.to, address: to, computer: m.name };
|
|
152523
152582
|
}
|
|
152583
|
+
/**
|
|
152584
|
+
* On a hub: the open tasks given to `machineId`'s sessions within `ASKED_WITHIN`, oldest first, that no send has under way: what its offer asks it
|
|
152585
|
+
* about (`HubOffer.open`)
|
|
152586
|
+
*/
|
|
152587
|
+
openTasksTo(machineId) {
|
|
152588
|
+
const since = this.now() - ASKED_WITHIN;
|
|
152589
|
+
return this.d.records.openTasksToward(sessionAddress(this.d.hostId, `${machineId}.`), since, OPEN_ASKED).filter((id3) => !this.sending.has(id3));
|
|
152590
|
+
}
|
|
152591
|
+
/**
|
|
152592
|
+
* On a hub: `machineId` answered this connection's offer, and `lacks` are the tasks it says never arrived there (#2289): sends whose answer was lost
|
|
152593
|
+
* before the machine wrote them. Nothing there will ever report on one, so each copy still open and in no send now is deleted, as a refusal deletes
|
|
152594
|
+
* one, and each sender is told in one notice and woken once, as for a stop. Then what is owed to the machine goes (`changed`)
|
|
152595
|
+
*/
|
|
152596
|
+
offerAnswered(machineId, lacks) {
|
|
152597
|
+
const lost = /* @__PURE__ */ new Map();
|
|
152598
|
+
for (const id3 of lacks) {
|
|
152599
|
+
const m = this.sending.has(id3) ? void 0 : this.d.records.message(id3);
|
|
152600
|
+
const row = m?.kind === "task" ? this.d.records.recipients(id3)[0] : void 0;
|
|
152601
|
+
const r = row && this.route(row.recipient);
|
|
152602
|
+
if (!m || !row || r?.kind !== "machine" || r.machineId !== machineId || row.settled !== null || row.releasedAt !== null) continue;
|
|
152603
|
+
const name = this.foreignName(row.recipient)?.name ?? row.recipient;
|
|
152604
|
+
this.d.records.deleteRows([{ messageId: id3, recipient: row.recipient }]);
|
|
152605
|
+
this.unsure.delete(id3);
|
|
152606
|
+
lost.set(m.sender, [...lost.get(m.sender) ?? [], { id: id3, name: oneLineText(name, 200) }]);
|
|
152607
|
+
this.d.log?.(`[mail] ${id3} never reached ${r.machineId}: its copy is deleted, and its sender told`);
|
|
152608
|
+
}
|
|
152609
|
+
for (const [sender, tasks] of lost) this.d.service.notice(sender, notArrived(tasks));
|
|
152610
|
+
this.changed();
|
|
152611
|
+
}
|
|
152612
|
+
/**
|
|
152613
|
+
* On a machine: which of the tasks hub `hubId`'s offer asks about (`HubOffer.open`) never arrived here. Only that hub's own ids (`<hubId>.m_…`) are
|
|
152614
|
+
* answered: another hub learns nothing of what is stored here, and cannot have a hub's later task refused. Each is remembered for that hub, and a
|
|
152615
|
+
* late one from it is refused (`taskFrom`): a send on a link the hub already counted as dead can still land after this answer. Memory is enough, as
|
|
152616
|
+
* no connection outlives this process: after a restart nothing sent before it can arrive
|
|
152617
|
+
*/
|
|
152618
|
+
lacking(hubId, ids) {
|
|
152619
|
+
const lacks = ids.filter((id3) => id3.startsWith(`${hubId}.`) && !id3.startsWith(`${this.d.hostId}.`) && FOREIGN_ID.test(id3) && !this.d.records.message(id3));
|
|
152620
|
+
const lacked = this.lacked.get(hubId) ?? /* @__PURE__ */ new Set();
|
|
152621
|
+
for (const id3 of lacks) lacked.add(id3);
|
|
152622
|
+
for (const old of lacked) {
|
|
152623
|
+
if (lacked.size <= LACKED_MAX) break;
|
|
152624
|
+
lacked.delete(old);
|
|
152625
|
+
}
|
|
152626
|
+
if (lacked.size) this.lacked.set(hubId, lacked);
|
|
152627
|
+
return lacks;
|
|
152628
|
+
}
|
|
152524
152629
|
/** Why a task to `to` cannot go now (`sendTask` says the same), or null: not a linked machine's session, no such machine, or one that takes no tasks yet or at all */
|
|
152525
152630
|
taskRefusal(to) {
|
|
152526
152631
|
const there = this.taskPeer(to);
|
|
@@ -152695,6 +152800,7 @@ var MailAcross = class extends AcrossReceipts {
|
|
|
152695
152800
|
const role = this.d.ownEntries().find((e) => e.address === to)?.role;
|
|
152696
152801
|
if (role === "assistant" || role === "coordinator") return { ok: false, why: "not_allowed", text: `Not a session this machine shares: ${this.label(to)}` };
|
|
152697
152802
|
if (p.id === void 0 || !FOREIGN_ID.test(p.id) || p.id.startsWith(`${this.d.hostId}.`)) return { ok: false, why: "bad_value", text: "a task from another computer comes with the id it gave it." };
|
|
152803
|
+
if (this.lacked.get(hub.id)?.has(p.id)) return { ok: false, why: "not_allowed", text: `${this.selfName()} told ${hub.name} when the link came back that this task never arrived, so it was not written now. Give it again.` };
|
|
152698
152804
|
const had = this.d.records.message(p.id);
|
|
152699
152805
|
if (had) return had.sender === from && this.d.records.recipient(p.id, to) ? { ok: true, messageId: p.id, to: this.label(to), address: to } : { ok: false, why: "bad_value", text: `${oneLineText(p.id, 200)} is the id of another message on ${this.selfName()}.` };
|
|
152700
152806
|
if (this.d.reach.mayWrite(from, to, false) === "gone") return { ok: false, why: "gone", text: `${this.label(to) === to ? "That session" : this.label(to)} is gone from ${this.selfName()}: it is in the session archive there or deleted, so nothing was written.` };
|
|
@@ -152848,6 +152954,13 @@ function pick4(p) {
|
|
|
152848
152954
|
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 } : {} };
|
|
152849
152955
|
}
|
|
152850
152956
|
var noAnswer = (ms3) => `no answer within ${durationText(ms3)}`;
|
|
152957
|
+
function notArrived(tasks) {
|
|
152958
|
+
const ids = tasks.map((t) => t.id);
|
|
152959
|
+
const named3 = tasks.slice(0, NAMED_MAX).map((t) => `${t.id} to ${t.name}`);
|
|
152960
|
+
const more = tasks.length > NAMED_MAX ? `, and ${tasks.length - NAMED_MAX} more` : "";
|
|
152961
|
+
const body = tasks.length === 1 ? `[Centralu] Your task to ${tasks[0]?.name} did not arrive: the link failed while it was being sent, and nobody is working on it. Give it again if it is still needed.` : `[Centralu] ${tasks.length} of your tasks did not arrive: ${named3.join(", ")}${more}. The link failed while they were being sent, and nobody is working on them. Give them again if they are still needed.`;
|
|
152962
|
+
return { body, facts: { notArrived: { messages: ids } }, dedupeKey: `not-arrived:${ids[0]}` };
|
|
152963
|
+
}
|
|
152851
152964
|
|
|
152852
152965
|
// packages/agent-host/src/mail/turns.ts
|
|
152853
152966
|
var STARTED_BY = ["mail", "person", "caller", "cli", "report", "app"];
|
|
@@ -153068,7 +153181,7 @@ function hostMail(store2, sessions, opts) {
|
|
|
153068
153181
|
},
|
|
153069
153182
|
calls: (address) => {
|
|
153070
153183
|
const party = parseAddress(address);
|
|
153071
|
-
return mailCalls(
|
|
153184
|
+
return mailCalls(party?.kind === "session" && sessions.mailCommand(party.sessionId) ? "command" : "plain");
|
|
153072
153185
|
},
|
|
153073
153186
|
personSaid: (sessionId) => store2.messages.newestPersonMessage(sessionId),
|
|
153074
153187
|
standing: (address) => {
|
|
@@ -153189,7 +153302,6 @@ function hostMail(store2, sessions, opts) {
|
|
|
153189
153302
|
sessions: () => sessions.listSessions().map((s) => ({ id: s.id, name: s.name, project: s.projectId ?? null, state: s.state })),
|
|
153190
153303
|
form: (id3) => sessions.mailCommand(id3) ? "command" : "plain",
|
|
153191
153304
|
askerOf: (id3) => askerFacts(askedByHost, id3),
|
|
153192
|
-
legacyChain: (threadId, messageId, reader) => store2.legacyChainFor(threadId, messageId, reader, 9),
|
|
153193
153305
|
across,
|
|
153194
153306
|
watches,
|
|
153195
153307
|
...sessions.work ? { work: sessions.work } : {}
|
|
@@ -153309,16 +153421,6 @@ function hostMail(store2, sessions, opts) {
|
|
|
153309
153421
|
} catch (e) {
|
|
153310
153422
|
console.error(`[mail] taking back the notices of ended cards failed: ${errorMessage(e)}`);
|
|
153311
153423
|
}
|
|
153312
|
-
try {
|
|
153313
|
-
const moved = store2.movePendingThreadMail(
|
|
153314
|
-
now(),
|
|
153315
|
-
(address) => reach.projectOf(address),
|
|
153316
|
-
(m, recipient) => reach.holdFor(m, recipient) !== null
|
|
153317
|
-
);
|
|
153318
|
-
if (moved.messages > 0) console.error(`[mail] moved ${moved.messages} pending message(s) an older build left in its threads`);
|
|
153319
|
-
} catch (e) {
|
|
153320
|
-
console.error(`[mail] moving the thread mail an older build left pending failed: ${errorMessage(e)}`);
|
|
153321
|
-
}
|
|
153322
153424
|
try {
|
|
153323
153425
|
const open6 = new Map(store2.mailbox.openTurns().map((t) => [t.sessionId, t.turnSeq]));
|
|
153324
153426
|
const stops = sessions.listSessions().flatMap((s) => {
|
|
@@ -153331,11 +153433,6 @@ function hostMail(store2, sessions, opts) {
|
|
|
153331
153433
|
} catch (e) {
|
|
153332
153434
|
console.error(`[mail] telling the senders of the turns the last host's end cut failed: ${errorMessage(e)}`);
|
|
153333
153435
|
}
|
|
153334
|
-
try {
|
|
153335
|
-
store2.children.dropReportMarks();
|
|
153336
|
-
} catch (e) {
|
|
153337
|
-
console.error(`[mail] deleting the report marks an older build left failed: ${errorMessage(e)}`);
|
|
153338
|
-
}
|
|
153339
153436
|
delivery.start();
|
|
153340
153437
|
for (const s of sessions.listSessions()) sessions.settleAtRest?.(s.id);
|
|
153341
153438
|
}
|
|
@@ -153419,6 +153516,355 @@ function watched(records, changed) {
|
|
|
153419
153516
|
});
|
|
153420
153517
|
}
|
|
153421
153518
|
|
|
153519
|
+
// packages/agent-host/src/links/qualifier.ts
|
|
153520
|
+
var onMachine2 = (name, machine) => `${name} on ${machine}`;
|
|
153521
|
+
var CrossMachineError = class extends Error {
|
|
153522
|
+
code = "internal";
|
|
153523
|
+
constructor(what, machine) {
|
|
153524
|
+
super(`${what} belongs to another machine than ${machine}; one call reaches one machine`);
|
|
153525
|
+
}
|
|
153526
|
+
};
|
|
153527
|
+
var Qualifier = class {
|
|
153528
|
+
constructor(machine, slot, ownerOf) {
|
|
153529
|
+
this.machine = machine;
|
|
153530
|
+
this.slot = slot;
|
|
153531
|
+
this.ownerOf = ownerOf;
|
|
153532
|
+
}
|
|
153533
|
+
machine;
|
|
153534
|
+
slot;
|
|
153535
|
+
ownerOf;
|
|
153536
|
+
prefix = () => `${this.machine}.`;
|
|
153537
|
+
/** Set once the machine answered this connection's offer (`LinkedMachineConnection.offerAsks`); null until then, and for a hub with no mail */
|
|
153538
|
+
mail = null;
|
|
153539
|
+
/**
|
|
153540
|
+
* This machine's approval cards the hub could not read (#844), by the machine's own session id and the request id.
|
|
153541
|
+
* The hub's windows show such a card as a fallback with allow and deny only, but a window from before #844 still
|
|
153542
|
+
* offers "always", and the machine would keep it for a kind it knows (a project consent, an agent start). So the hub
|
|
153543
|
+
* refuses "always" for these (`LinkedMachine.call`): nobody can grant for good what was never shown in full here.
|
|
153544
|
+
* Seen on the card's event and on a session row that carries it; an answered card leaves.
|
|
153545
|
+
*/
|
|
153546
|
+
unread = /* @__PURE__ */ new Set();
|
|
153547
|
+
noteCard(sessionId, requestId, detail) {
|
|
153548
|
+
if (typeof sessionId !== "string" || typeof requestId !== "string") return;
|
|
153549
|
+
if (isUnknownCard(ApprovalDetail.parse(detail))) this.unread.add(`${sessionId}\0${requestId}`);
|
|
153550
|
+
}
|
|
153551
|
+
/** Whether the hub read this card of the machine (in the machine's own ids) as a fallback */
|
|
153552
|
+
unreadCard(sessionId, requestId) {
|
|
153553
|
+
return typeof sessionId === "string" && typeof requestId === "string" && this.unread.has(`${sessionId}\0${requestId}`);
|
|
153554
|
+
}
|
|
153555
|
+
/** An id of this machine as the hub's UI sees it */
|
|
153556
|
+
id(value) {
|
|
153557
|
+
return qualify(this.machine, value);
|
|
153558
|
+
}
|
|
153559
|
+
/** The same for a value that may be absent or null, which stays so */
|
|
153560
|
+
maybeId(value) {
|
|
153561
|
+
return typeof value === "string" ? this.id(value) : value;
|
|
153562
|
+
}
|
|
153563
|
+
/** Whether a hub-side id names this machine */
|
|
153564
|
+
owns(value) {
|
|
153565
|
+
return typeof value === "string" && value.startsWith(this.prefix());
|
|
153566
|
+
}
|
|
153567
|
+
/** A hub-side id back to the remote's own. Refuses an id of another machine */
|
|
153568
|
+
strip(value, what) {
|
|
153569
|
+
if (typeof value !== "string" || !this.owns(value)) throw new CrossMachineError(what, this.machine);
|
|
153570
|
+
return value.slice(this.prefix().length);
|
|
153571
|
+
}
|
|
153572
|
+
/** The same for a value that may be null or absent, which stays so */
|
|
153573
|
+
stripMaybe(value, what) {
|
|
153574
|
+
return value === null || value === void 0 ? value : this.strip(value, what);
|
|
153575
|
+
}
|
|
153576
|
+
// ── Results ─────────────────────────────────────────────────────────────────────────────
|
|
153577
|
+
/** `SessionInfo` (and `UpdateSettingsResult`, which extends it) */
|
|
153578
|
+
session(s) {
|
|
153579
|
+
if (!isObj(s)) return s;
|
|
153580
|
+
if (isObj(s.pendingApproval)) this.noteCard(s.id, s.pendingApproval.requestId, s.pendingApproval.detail);
|
|
153581
|
+
const id3 = this.maybeId(s.id);
|
|
153582
|
+
const owner = typeof id3 === "string" ? this.ownerOf?.(id3) : void 0;
|
|
153583
|
+
return {
|
|
153584
|
+
...s,
|
|
153585
|
+
id: id3,
|
|
153586
|
+
projectId: this.maybeId(s.projectId),
|
|
153587
|
+
parentSessionId: this.maybeId(s.parentSessionId),
|
|
153588
|
+
...owner ? { askedBy: owner } : "askedBy" in s ? { askedBy: this.maybeId(s.askedBy) } : {},
|
|
153589
|
+
scopeSessionIds: Array.isArray(s.scopeSessionIds) ? s.scopeSessionIds.map((x) => this.maybeId(x)) : s.scopeSessionIds,
|
|
153590
|
+
machine: this.machine
|
|
153591
|
+
};
|
|
153592
|
+
}
|
|
153593
|
+
sessions(list2) {
|
|
153594
|
+
return Array.isArray(list2) ? list2.map((s) => this.session(s)) : list2;
|
|
153595
|
+
}
|
|
153596
|
+
/** `{ session, resumed, reason?, ... }` from restart, resume and fork */
|
|
153597
|
+
sessionResult(r) {
|
|
153598
|
+
return isObj(r) ? { ...r, session: this.session(r.session) } : r;
|
|
153599
|
+
}
|
|
153600
|
+
/** `ProjectInfo` */
|
|
153601
|
+
project(p) {
|
|
153602
|
+
if (!isObj(p)) return p;
|
|
153603
|
+
const manager = p.worktreeManager;
|
|
153604
|
+
return {
|
|
153605
|
+
...p,
|
|
153606
|
+
id: this.maybeId(p.id),
|
|
153607
|
+
worktreeManager: isObj(manager) ? { ...manager, sessionId: this.maybeId(manager.sessionId) } : manager,
|
|
153608
|
+
machine: this.machine
|
|
153609
|
+
};
|
|
153610
|
+
}
|
|
153611
|
+
projects(list2) {
|
|
153612
|
+
return Array.isArray(list2) ? list2.map((p) => this.project(p)) : list2;
|
|
153613
|
+
}
|
|
153614
|
+
/** `TerminalInfo` */
|
|
153615
|
+
terminal(t) {
|
|
153616
|
+
return isObj(t) ? { ...t, terminalId: this.maybeId(t.terminalId) } : t;
|
|
153617
|
+
}
|
|
153618
|
+
/** `CommandRunInfo` — its run id rides the terminal frame lane in place of a terminal id */
|
|
153619
|
+
run(r) {
|
|
153620
|
+
return isObj(r) ? { ...r, runId: this.maybeId(r.runId) } : r;
|
|
153621
|
+
}
|
|
153622
|
+
/** `StoredMessage`: its session, and the ids its payload names (#371's asked-by line, a handoff, an app's text) */
|
|
153623
|
+
message(m) {
|
|
153624
|
+
if (!isObj(m)) return m;
|
|
153625
|
+
return { ...m, sessionId: this.maybeId(m.sessionId), payload: this.payload(m.payload) };
|
|
153626
|
+
}
|
|
153627
|
+
messages(list2) {
|
|
153628
|
+
return Array.isArray(list2) ? list2.map((m) => this.message(m)) : list2;
|
|
153629
|
+
}
|
|
153630
|
+
payload(p) {
|
|
153631
|
+
if (!isObj(p)) return p;
|
|
153632
|
+
const out = { ...p };
|
|
153633
|
+
if (typeof p.sessionId === "string") out.sessionId = this.id(p.sessionId);
|
|
153634
|
+
if (isObj(p.from) && typeof p.from.sessionId === "string") out.from = { ...p.from, sessionId: this.id(p.from.sessionId) };
|
|
153635
|
+
if (typeof p.fromSessionId === "string") out.fromSessionId = this.id(p.fromSessionId);
|
|
153636
|
+
if (isObj(p.fromApp)) out.fromApp = { ...p.fromApp, projectId: this.maybeId(p.fromApp.projectId) };
|
|
153637
|
+
if ("projectId" in p) out.projectId = this.maybeId(p.projectId);
|
|
153638
|
+
if (typeof p.instanceId === "string") out.instanceId = this.id(p.instanceId);
|
|
153639
|
+
if (isObj(p.detail)) out.detail = this.approvalDetail(p.detail);
|
|
153640
|
+
return out;
|
|
153641
|
+
}
|
|
153642
|
+
/** `ApprovalDetail`: the kinds that name a project */
|
|
153643
|
+
approvalDetail(d2) {
|
|
153644
|
+
if (!isObj(d2)) return d2;
|
|
153645
|
+
if (d2.kind === "capability" && isObj(d2.app)) return { ...d2, app: { ...d2.app, projectId: this.maybeId(d2.app.projectId) } };
|
|
153646
|
+
if (d2.kind === "project_access") {
|
|
153647
|
+
const side = (x) => isObj(x) ? { ...x, id: this.maybeId(x.id) } : x;
|
|
153648
|
+
return { ...d2, from: side(d2.from), to: side(d2.to) };
|
|
153649
|
+
}
|
|
153650
|
+
if (d2.kind === "agent_start" && isObj(d2.project)) return { ...d2, project: { ...d2.project, id: this.maybeId(d2.project.id) } };
|
|
153651
|
+
return d2;
|
|
153652
|
+
}
|
|
153653
|
+
/** `TrashedSession` */
|
|
153654
|
+
trashed(t) {
|
|
153655
|
+
if (!isObj(t)) return t;
|
|
153656
|
+
return {
|
|
153657
|
+
...t,
|
|
153658
|
+
id: this.maybeId(t.id),
|
|
153659
|
+
project: isObj(t.project) ? { ...t.project, id: this.maybeId(t.project.id) } : t.project,
|
|
153660
|
+
machine: this.machine
|
|
153661
|
+
};
|
|
153662
|
+
}
|
|
153663
|
+
/** `TrashedRun` (#378): its app's project is this machine's, and the record is read and deleted here */
|
|
153664
|
+
trashedRun(t) {
|
|
153665
|
+
if (!isObj(t)) return t;
|
|
153666
|
+
return { ...t, app: isObj(t.app) ? { ...t.app, projectId: this.maybeId(t.app.projectId) } : t.app, machine: this.machine };
|
|
153667
|
+
}
|
|
153668
|
+
/** `SubagentStepsHeld` and `TrashedSubagentSteps` (#418) */
|
|
153669
|
+
subagentSteps(t) {
|
|
153670
|
+
if (!isObj(t)) return t;
|
|
153671
|
+
return {
|
|
153672
|
+
...t,
|
|
153673
|
+
sessionId: this.maybeId(t.sessionId),
|
|
153674
|
+
project: isObj(t.project) ? { ...t.project, id: this.maybeId(t.project.id) } : t.project,
|
|
153675
|
+
machine: this.machine
|
|
153676
|
+
};
|
|
153677
|
+
}
|
|
153678
|
+
/** `ExternalAppInfo`: a project app is that project's; a user-folder app says which machine's folder */
|
|
153679
|
+
app(a) {
|
|
153680
|
+
return isObj(a) ? { ...a, projectId: this.maybeId(a.projectId), machine: this.machine } : a;
|
|
153681
|
+
}
|
|
153682
|
+
/** `ProjectConsent` */
|
|
153683
|
+
consent(c) {
|
|
153684
|
+
return isObj(c) ? { ...c, fromProjectId: this.maybeId(c.fromProjectId), toProjectId: this.maybeId(c.toProjectId), machine: this.machine } : c;
|
|
153685
|
+
}
|
|
153686
|
+
/** One `approvals.rules` row: its numeric id folded (`encodeNumber`), its owner qualified */
|
|
153687
|
+
rule(r, encode3) {
|
|
153688
|
+
if (!isObj(r)) return r;
|
|
153689
|
+
return {
|
|
153690
|
+
...r,
|
|
153691
|
+
id: typeof r.id === "number" ? encode3(r.id) : r.id,
|
|
153692
|
+
projectId: this.maybeId(r.projectId),
|
|
153693
|
+
sessionId: this.maybeId(r.sessionId),
|
|
153694
|
+
machine: this.machine
|
|
153695
|
+
};
|
|
153696
|
+
}
|
|
153697
|
+
/** `messages.search` hits */
|
|
153698
|
+
hits(list2) {
|
|
153699
|
+
return Array.isArray(list2) ? list2.map((h) => isObj(h) ? { ...h, sessionId: this.maybeId(h.sessionId) } : h) : list2;
|
|
153700
|
+
}
|
|
153701
|
+
/**
|
|
153702
|
+
* `apps.inlineViews` rows and the `apps.inlineReopen` answer. The view instance is qualified like any id: the window
|
|
153703
|
+
* hands it back to open, call and close the view, and the hub routes those by it (plan §11)
|
|
153704
|
+
*/
|
|
153705
|
+
inlineView(v) {
|
|
153706
|
+
return isObj(v) ? { ...v, projectId: this.maybeId(v.projectId), instanceId: this.maybeId(v.instanceId) } : v;
|
|
153707
|
+
}
|
|
153708
|
+
/** An `apps.runs` row: its app's project, the session that called it, and the agent session it stood up (the panel links to it) */
|
|
153709
|
+
appRun(r) {
|
|
153710
|
+
return isObj(r) ? { ...r, projectId: this.maybeId(r.projectId), callerSessionId: this.maybeId(r.callerSessionId), sessionId: this.maybeId(r.sessionId) } : r;
|
|
153711
|
+
}
|
|
153712
|
+
/**
|
|
153713
|
+
* The `agents.listExternalSessions` answer. `externalId` is the tool's own id for the conversation, so it stays as it is;
|
|
153714
|
+
* `importedAs` is the id of the Centralu session already open for it, which the window focuses (#701)
|
|
153715
|
+
*/
|
|
153716
|
+
externalSessions(r) {
|
|
153717
|
+
if (!isObj(r) || !Array.isArray(r.sessions)) return r;
|
|
153718
|
+
return { ...r, sessions: r.sessions.map((s) => isObj(s) ? { ...s, importedAs: this.maybeId(s.importedAs) } : s) };
|
|
153719
|
+
}
|
|
153720
|
+
/**
|
|
153721
|
+
* The `apps.errors` answer: the app a declined request named is compared with the app on screen, whose project is
|
|
153722
|
+
* qualified, to decide which of the two wordings applies. `runId` is a run's own id and stays as `apps.runs` leaves it
|
|
153723
|
+
*/
|
|
153724
|
+
errorBundles(r) {
|
|
153725
|
+
if (!isObj(r)) return r;
|
|
153726
|
+
const bundle = (b2) => isObj(b2) && isObj(b2.denied) ? { ...b2, denied: { ...b2.denied, projectId: this.maybeId(b2.denied.projectId) } } : b2;
|
|
153727
|
+
return { ...r, latest: bundle(r.latest), recent: Array.isArray(r.recent) ? r.recent.map(bundle) : r.recent };
|
|
153728
|
+
}
|
|
153729
|
+
/** The `apps.openView` answer: the pinned view's instance */
|
|
153730
|
+
openedView(v) {
|
|
153731
|
+
return isObj(v) ? { ...v, instanceId: this.maybeId(v.instanceId) } : v;
|
|
153732
|
+
}
|
|
153733
|
+
/** The `apps.viewDocument` answer: the app it names (a user-folder app's null project stays null) */
|
|
153734
|
+
viewDocument(d2) {
|
|
153735
|
+
return isObj(d2) ? { ...d2, projectId: this.maybeId(d2.projectId) } : d2;
|
|
153736
|
+
}
|
|
153737
|
+
/**
|
|
153738
|
+
* A `MailParty` of this machine's mail in the hub's terms (#2268, `inHubTerms`): its own session is `session:<hub>/<machine>.<id>`, named
|
|
153739
|
+
* `<name> on <machine>`; the hub's person is `person`; its own app's project is qualified. The hub's side, `person` and `centralu` stay
|
|
153740
|
+
*/
|
|
153741
|
+
mailParty(p) {
|
|
153742
|
+
const t = this.mail;
|
|
153743
|
+
if (!isObj(p) || typeof p.address !== "string" || !t) return p;
|
|
153744
|
+
const address = inHubTerms(p.address, t.hub, t.own === null ? void 0 : { host: t.own, id: this.machine });
|
|
153745
|
+
if (address === PERSON) return { ...p, address, kind: "person", sessionId: null, name: null, state: null };
|
|
153746
|
+
const named3 = parseAddress(address);
|
|
153747
|
+
if (address !== p.address && named3?.kind === "session") {
|
|
153748
|
+
return { ...p, address, sessionId: named3.sessionId, name: typeof p.name === "string" ? onMachine2(p.name, t.computer()) : p.name };
|
|
153749
|
+
}
|
|
153750
|
+
const app2 = parseAddress(p.address);
|
|
153751
|
+
return app2?.kind === "app" && app2.host === t.own ? { ...p, address: appAddress(t.hub, this.id(app2.projectId), app2.appId) } : p;
|
|
153752
|
+
}
|
|
153753
|
+
/** A `mail.tasks` row: its parties in the hub's terms, and its chain qualified so the row opens there (`mail.thread`). The message id is every host's */
|
|
153754
|
+
taskRow(t) {
|
|
153755
|
+
return isObj(t) ? { ...t, root: this.maybeId(t.root), owner: this.mailParty(t.owner), assignee: this.mailParty(t.assignee) } : t;
|
|
153756
|
+
}
|
|
153757
|
+
/**
|
|
153758
|
+
* A `mail.tasks` answer's rows in the hub's terms (`taskRow`), but for the items of this machine's own Inbox: a row its own person gave or has, and one
|
|
153759
|
+
* held there for them to act on. The hub shows nothing of that Inbox (`mail.list` and `mail.held` are the hub's own), so such a row could be neither
|
|
153760
|
+
* answered, closed nor released here, and would stand in the hub's Needs you as the hub's person's own
|
|
153761
|
+
*/
|
|
153762
|
+
taskRows(rows3) {
|
|
153763
|
+
const own = (p) => isObj(p) && p.address === PERSON;
|
|
153764
|
+
return (Array.isArray(rows3) ? rows3 : []).flatMap((t) => isObj(t) && (own(t.owner) || own(t.assignee) || t.state === "held") ? [] : [this.taskRow(t)]);
|
|
153765
|
+
}
|
|
153766
|
+
/** A `MailThreadView` of this machine: its chain and the chains it follows qualified, every party in the hub's terms. Message ids are every host's */
|
|
153767
|
+
mailThread(v) {
|
|
153768
|
+
if (!isObj(v)) return v;
|
|
153769
|
+
const party = (x) => this.mailParty(x);
|
|
153770
|
+
const sent = (x) => isObj(x) ? { ...x, sender: party(x.sender) } : x;
|
|
153771
|
+
const list2 = (x, f) => Array.isArray(x) ? x.map((y) => isObj(y) ? f(y) : y) : x;
|
|
153772
|
+
const t = v.thread;
|
|
153773
|
+
return {
|
|
153774
|
+
...v,
|
|
153775
|
+
thread: isObj(t) ? { ...t, id: this.maybeId(t.id), projectId: this.maybeId(t.projectId), owner: party(t.owner), assignee: party(t.assignee), ask: sent(t.ask), last: sent(t.last) } : t,
|
|
153776
|
+
parties: list2(v.parties, (x) => ({ ...x, party: party(x.party) })),
|
|
153777
|
+
messages: list2(v.messages, (m) => ({ ...m, sender: party(m.sender), ..."receipts" in m ? { receipts: list2(m.receipts, (r) => ({ ...r, recipient: party(r.recipient) })) } : {} })),
|
|
153778
|
+
follows: list2(v.follows, (f) => ({ ...f, id: this.maybeId(f.id) }))
|
|
153779
|
+
};
|
|
153780
|
+
}
|
|
153781
|
+
// ── Events ──────────────────────────────────────────────────────────────────────────────
|
|
153782
|
+
/**
|
|
153783
|
+
* One event of this machine in the hub's terms, or null for one the hub does not pass on.
|
|
153784
|
+
*
|
|
153785
|
+
* Dropped: what is about the remote host itself rather than its sessions and projects. The hub
|
|
153786
|
+
* has its own update, themes, preferences, agent CLIs and screen questions (and a host of v0.1.0-beta.10 or
|
|
153787
|
+
* before still sends `app_state_changed` for its control app), and an app-wide
|
|
153788
|
+
* error from another machine is not this UI's to show (§5). An event of a type this build does
|
|
153789
|
+
* not know is passed when it names a session (qualified), dropped otherwise.
|
|
153790
|
+
*/
|
|
153791
|
+
event(e) {
|
|
153792
|
+
if (!isObj(e) || typeof e.type !== "string") return null;
|
|
153793
|
+
const sid = typeof e.sessionId === "string" ? this.id(e.sessionId) : void 0;
|
|
153794
|
+
const base2 = { ...e, ...sid !== void 0 ? { sessionId: sid } : {} };
|
|
153795
|
+
switch (e.type) {
|
|
153796
|
+
// Another machine's agent asking its own windows to apply (#665) must never relaunch the hub's window
|
|
153797
|
+
case "update_status":
|
|
153798
|
+
case "update_apply_request":
|
|
153799
|
+
case "update_apply_go":
|
|
153800
|
+
case "themes_changed":
|
|
153801
|
+
case "prefs_changed":
|
|
153802
|
+
case "app_state_changed":
|
|
153803
|
+
case "agent_versions":
|
|
153804
|
+
case "external_app_questions_changed":
|
|
153805
|
+
case "orchestrator_proposals_changed":
|
|
153806
|
+
case "assistant_proposals_changed":
|
|
153807
|
+
return null;
|
|
153808
|
+
case "error":
|
|
153809
|
+
return sid === void 0 ? null : base2;
|
|
153810
|
+
/*
|
|
153811
|
+
* Its mail moved (#2268): the hub's windows read Tasks again, and the machine's chain if one is open. Never as news for the person: what that
|
|
153812
|
+
* machine's own Inbox holds is not the hub's person's to be told of, and a message to them reaches the hub's mailbox, which tells them itself
|
|
153813
|
+
*/
|
|
153814
|
+
case "mail_changed": {
|
|
153815
|
+
const { arrived: _arrived, ...rest } = base2;
|
|
153816
|
+
return { ...rest, threadId: this.maybeId(e.threadId), toPerson: false };
|
|
153817
|
+
}
|
|
153818
|
+
case "session_created":
|
|
153819
|
+
return { ...base2, session: this.session(e.session) };
|
|
153820
|
+
case "user_message": {
|
|
153821
|
+
const out = { ...base2 };
|
|
153822
|
+
if (isObj(e.from) && typeof e.from.sessionId === "string") out.from = { ...e.from, sessionId: this.id(e.from.sessionId) };
|
|
153823
|
+
if (isObj(e.fromApp)) out.fromApp = { ...e.fromApp, projectId: this.maybeId(e.fromApp.projectId) };
|
|
153824
|
+
return out;
|
|
153825
|
+
}
|
|
153826
|
+
// The sender of the message a turn ran for (#1604), named as a message's sender is
|
|
153827
|
+
case "state_change": {
|
|
153828
|
+
const o = e.origin;
|
|
153829
|
+
if (!isObj(o) || !isObj(o.from) || typeof o.from.sessionId !== "string") return base2;
|
|
153830
|
+
return { ...base2, origin: { ...o, from: { ...o.from, sessionId: this.id(o.from.sessionId) } } };
|
|
153831
|
+
}
|
|
153832
|
+
case "handoff":
|
|
153833
|
+
return { ...base2, fromSessionId: this.maybeId(e.fromSessionId) };
|
|
153834
|
+
case "session_owner":
|
|
153835
|
+
return { ...base2, askedBy: (sid !== void 0 ? this.ownerOf?.(sid) : void 0) ?? this.maybeId(e.askedBy), parentSessionId: this.maybeId(e.parentSessionId) };
|
|
153836
|
+
case "approval_request":
|
|
153837
|
+
this.noteCard(e.sessionId, e.requestId, e.detail);
|
|
153838
|
+
return { ...base2, detail: this.approvalDetail(e.detail) };
|
|
153839
|
+
case "approval_resolved":
|
|
153840
|
+
if (typeof e.sessionId === "string" && typeof e.requestId === "string") this.unread.delete(`${e.sessionId}\0${e.requestId}`);
|
|
153841
|
+
return base2;
|
|
153842
|
+
// The view's instance, which the window opens, calls and closes it by (plan §11)
|
|
153843
|
+
case "app_view":
|
|
153844
|
+
return { ...base2, projectId: this.maybeId(e.projectId), instanceId: this.maybeId(e.instanceId) };
|
|
153845
|
+
// The view whose own call caused it, so that view does not re-read what it already has (B-5)
|
|
153846
|
+
case "external_app_state_changed":
|
|
153847
|
+
return {
|
|
153848
|
+
...base2,
|
|
153849
|
+
projectId: this.maybeId(e.projectId),
|
|
153850
|
+
...isObj(e.cause) ? { cause: { ...e.cause, instanceId: this.maybeId(e.cause.instanceId) } } : {}
|
|
153851
|
+
};
|
|
153852
|
+
case "external_app_runs_changed":
|
|
153853
|
+
case "fs_changed":
|
|
153854
|
+
return { ...base2, projectId: this.maybeId(e.projectId) };
|
|
153855
|
+
// `projects_changed`: a project another machine made (#515); the hub's windows re-read the merged list
|
|
153856
|
+
case "external_apps_changed":
|
|
153857
|
+
case "project_consents_changed":
|
|
153858
|
+
return base2;
|
|
153859
|
+
// `added` (#1220): a project that machine's assistant added, named as the hub's windows know it
|
|
153860
|
+
case "projects_changed":
|
|
153861
|
+
return typeof e.added === "string" ? { ...base2, added: this.maybeId(e.added) } : base2;
|
|
153862
|
+
default:
|
|
153863
|
+
return sid === void 0 ? null : base2;
|
|
153864
|
+
}
|
|
153865
|
+
}
|
|
153866
|
+
};
|
|
153867
|
+
|
|
153422
153868
|
// packages/agent-host/src/links/mail-peers.ts
|
|
153423
153869
|
function mailPeers(o) {
|
|
153424
153870
|
const { machines, hubs: hubs2, settings } = o;
|
|
@@ -153449,7 +153895,7 @@ function mailPeers(o) {
|
|
|
153449
153895
|
machineSession: (machineId, sessionId) => {
|
|
153450
153896
|
const m = machines.get(machineId);
|
|
153451
153897
|
const row = mirrored(machineId, sessionId);
|
|
153452
|
-
return m && row && typeof row.name === "string" ?
|
|
153898
|
+
return m && row && typeof row.name === "string" ? onMachine2(row.name, m.name) : void 0;
|
|
153453
153899
|
},
|
|
153454
153900
|
machineState: (machineId, sessionId) => {
|
|
153455
153901
|
const state = mirrored(machineId, sessionId)?.state;
|
|
@@ -154352,8 +154798,8 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
154352
154798
|
},
|
|
154353
154799
|
"mail.list": async () => requireMail().list(),
|
|
154354
154800
|
"mail.tasks": async () => requireMail().tasks(),
|
|
154355
|
-
"mail.thread": async ({ threadId, after, all, tail, before }) => {
|
|
154356
|
-
return requireMail().thread(threadId, { after, all, tail, before });
|
|
154801
|
+
"mail.thread": async ({ threadId, after, all, tail, before, lookIn }) => {
|
|
154802
|
+
return requireMail().thread(threadId, { after, all, tail, before, lookIn });
|
|
154357
154803
|
},
|
|
154358
154804
|
"mail.reply": async ({ threadId, text: text3, kind, answers: answers2 }) => {
|
|
154359
154805
|
return requireMail().reply(threadId, text3, kind, answers2);
|
|
@@ -154728,7 +155174,13 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
154728
155174
|
"host.hubOffer": async (p, ctx) => {
|
|
154729
155175
|
const offer = p;
|
|
154730
155176
|
if (hubs2 && ctx) hubs2.offer(ctx.client, offer);
|
|
154731
|
-
|
|
155177
|
+
const lacks = mailAcross && hubs2 && offer.open?.length ? mailAcross.lacking(offer.hub.id, offer.open) : [];
|
|
155178
|
+
return {
|
|
155179
|
+
ok: true,
|
|
155180
|
+
...mailAcross && hubs2 ? { mail: true, tasks: true, host: mailAcross.hostId } : {},
|
|
155181
|
+
...lacks.length ? { lacks } : {},
|
|
155182
|
+
...appsAcross && hubs2?.appsOn ? { apps: true } : {}
|
|
155183
|
+
};
|
|
154732
155184
|
},
|
|
154733
155185
|
"host.mail": async (p, ctx) => {
|
|
154734
155186
|
const hub = ctx ? hubs2?.on?.(ctx.client) : void 0;
|
|
@@ -158995,301 +159447,6 @@ async function askHubAuto(call2, allowed) {
|
|
|
158995
159447
|
// packages/agent-host/src/links/linked-machine-connection.ts
|
|
158996
159448
|
import { randomBytes as randomBytes15 } from "node:crypto";
|
|
158997
159449
|
|
|
158998
|
-
// packages/agent-host/src/links/qualifier.ts
|
|
158999
|
-
var CrossMachineError = class extends Error {
|
|
159000
|
-
code = "internal";
|
|
159001
|
-
constructor(what, machine) {
|
|
159002
|
-
super(`${what} belongs to another machine than ${machine}; one call reaches one machine`);
|
|
159003
|
-
}
|
|
159004
|
-
};
|
|
159005
|
-
var Qualifier = class {
|
|
159006
|
-
constructor(machine, slot, ownerOf) {
|
|
159007
|
-
this.machine = machine;
|
|
159008
|
-
this.slot = slot;
|
|
159009
|
-
this.ownerOf = ownerOf;
|
|
159010
|
-
}
|
|
159011
|
-
machine;
|
|
159012
|
-
slot;
|
|
159013
|
-
ownerOf;
|
|
159014
|
-
prefix = () => `${this.machine}.`;
|
|
159015
|
-
/**
|
|
159016
|
-
* This machine's approval cards the hub could not read (#844), by the machine's own session id and the request id.
|
|
159017
|
-
* The hub's windows show such a card as a fallback with allow and deny only, but a window from before #844 still
|
|
159018
|
-
* offers "always", and the machine would keep it for a kind it knows (a project consent, an agent start). So the hub
|
|
159019
|
-
* refuses "always" for these (`LinkedMachine.call`): nobody can grant for good what was never shown in full here.
|
|
159020
|
-
* Seen on the card's event and on a session row that carries it; an answered card leaves.
|
|
159021
|
-
*/
|
|
159022
|
-
unread = /* @__PURE__ */ new Set();
|
|
159023
|
-
noteCard(sessionId, requestId, detail) {
|
|
159024
|
-
if (typeof sessionId !== "string" || typeof requestId !== "string") return;
|
|
159025
|
-
if (isUnknownCard(ApprovalDetail.parse(detail))) this.unread.add(`${sessionId}\0${requestId}`);
|
|
159026
|
-
}
|
|
159027
|
-
/** Whether the hub read this card of the machine (in the machine's own ids) as a fallback */
|
|
159028
|
-
unreadCard(sessionId, requestId) {
|
|
159029
|
-
return typeof sessionId === "string" && typeof requestId === "string" && this.unread.has(`${sessionId}\0${requestId}`);
|
|
159030
|
-
}
|
|
159031
|
-
/** An id of this machine as the hub's UI sees it */
|
|
159032
|
-
id(value) {
|
|
159033
|
-
return qualify(this.machine, value);
|
|
159034
|
-
}
|
|
159035
|
-
/** The same for a value that may be absent or null, which stays so */
|
|
159036
|
-
maybeId(value) {
|
|
159037
|
-
return typeof value === "string" ? this.id(value) : value;
|
|
159038
|
-
}
|
|
159039
|
-
/** Whether a hub-side id names this machine */
|
|
159040
|
-
owns(value) {
|
|
159041
|
-
return typeof value === "string" && value.startsWith(this.prefix());
|
|
159042
|
-
}
|
|
159043
|
-
/** A hub-side id back to the remote's own. Refuses an id of another machine */
|
|
159044
|
-
strip(value, what) {
|
|
159045
|
-
if (typeof value !== "string" || !this.owns(value)) throw new CrossMachineError(what, this.machine);
|
|
159046
|
-
return value.slice(this.prefix().length);
|
|
159047
|
-
}
|
|
159048
|
-
/** The same for a value that may be null or absent, which stays so */
|
|
159049
|
-
stripMaybe(value, what) {
|
|
159050
|
-
return value === null || value === void 0 ? value : this.strip(value, what);
|
|
159051
|
-
}
|
|
159052
|
-
// ── Results ─────────────────────────────────────────────────────────────────────────────
|
|
159053
|
-
/** `SessionInfo` (and `UpdateSettingsResult`, which extends it) */
|
|
159054
|
-
session(s) {
|
|
159055
|
-
if (!isObj(s)) return s;
|
|
159056
|
-
if (isObj(s.pendingApproval)) this.noteCard(s.id, s.pendingApproval.requestId, s.pendingApproval.detail);
|
|
159057
|
-
const id3 = this.maybeId(s.id);
|
|
159058
|
-
const owner = typeof id3 === "string" ? this.ownerOf?.(id3) : void 0;
|
|
159059
|
-
return {
|
|
159060
|
-
...s,
|
|
159061
|
-
id: id3,
|
|
159062
|
-
projectId: this.maybeId(s.projectId),
|
|
159063
|
-
parentSessionId: this.maybeId(s.parentSessionId),
|
|
159064
|
-
...owner ? { askedBy: owner } : "askedBy" in s ? { askedBy: this.maybeId(s.askedBy) } : {},
|
|
159065
|
-
scopeSessionIds: Array.isArray(s.scopeSessionIds) ? s.scopeSessionIds.map((x) => this.maybeId(x)) : s.scopeSessionIds,
|
|
159066
|
-
machine: this.machine
|
|
159067
|
-
};
|
|
159068
|
-
}
|
|
159069
|
-
sessions(list2) {
|
|
159070
|
-
return Array.isArray(list2) ? list2.map((s) => this.session(s)) : list2;
|
|
159071
|
-
}
|
|
159072
|
-
/** `{ session, resumed, reason?, ... }` from restart, resume and fork */
|
|
159073
|
-
sessionResult(r) {
|
|
159074
|
-
return isObj(r) ? { ...r, session: this.session(r.session) } : r;
|
|
159075
|
-
}
|
|
159076
|
-
/** `ProjectInfo` */
|
|
159077
|
-
project(p) {
|
|
159078
|
-
if (!isObj(p)) return p;
|
|
159079
|
-
const manager = p.worktreeManager;
|
|
159080
|
-
return {
|
|
159081
|
-
...p,
|
|
159082
|
-
id: this.maybeId(p.id),
|
|
159083
|
-
worktreeManager: isObj(manager) ? { ...manager, sessionId: this.maybeId(manager.sessionId) } : manager,
|
|
159084
|
-
machine: this.machine
|
|
159085
|
-
};
|
|
159086
|
-
}
|
|
159087
|
-
projects(list2) {
|
|
159088
|
-
return Array.isArray(list2) ? list2.map((p) => this.project(p)) : list2;
|
|
159089
|
-
}
|
|
159090
|
-
/** `TerminalInfo` */
|
|
159091
|
-
terminal(t) {
|
|
159092
|
-
return isObj(t) ? { ...t, terminalId: this.maybeId(t.terminalId) } : t;
|
|
159093
|
-
}
|
|
159094
|
-
/** `CommandRunInfo` — its run id rides the terminal frame lane in place of a terminal id */
|
|
159095
|
-
run(r) {
|
|
159096
|
-
return isObj(r) ? { ...r, runId: this.maybeId(r.runId) } : r;
|
|
159097
|
-
}
|
|
159098
|
-
/** `StoredMessage`: its session, and the ids its payload names (#371's asked-by line, a handoff, an app's text) */
|
|
159099
|
-
message(m) {
|
|
159100
|
-
if (!isObj(m)) return m;
|
|
159101
|
-
return { ...m, sessionId: this.maybeId(m.sessionId), payload: this.payload(m.payload) };
|
|
159102
|
-
}
|
|
159103
|
-
messages(list2) {
|
|
159104
|
-
return Array.isArray(list2) ? list2.map((m) => this.message(m)) : list2;
|
|
159105
|
-
}
|
|
159106
|
-
payload(p) {
|
|
159107
|
-
if (!isObj(p)) return p;
|
|
159108
|
-
const out = { ...p };
|
|
159109
|
-
if (typeof p.sessionId === "string") out.sessionId = this.id(p.sessionId);
|
|
159110
|
-
if (isObj(p.from) && typeof p.from.sessionId === "string") out.from = { ...p.from, sessionId: this.id(p.from.sessionId) };
|
|
159111
|
-
if (typeof p.fromSessionId === "string") out.fromSessionId = this.id(p.fromSessionId);
|
|
159112
|
-
if (isObj(p.fromApp)) out.fromApp = { ...p.fromApp, projectId: this.maybeId(p.fromApp.projectId) };
|
|
159113
|
-
if ("projectId" in p) out.projectId = this.maybeId(p.projectId);
|
|
159114
|
-
if (typeof p.instanceId === "string") out.instanceId = this.id(p.instanceId);
|
|
159115
|
-
if (isObj(p.detail)) out.detail = this.approvalDetail(p.detail);
|
|
159116
|
-
return out;
|
|
159117
|
-
}
|
|
159118
|
-
/** `ApprovalDetail`: the kinds that name a project */
|
|
159119
|
-
approvalDetail(d2) {
|
|
159120
|
-
if (!isObj(d2)) return d2;
|
|
159121
|
-
if (d2.kind === "capability" && isObj(d2.app)) return { ...d2, app: { ...d2.app, projectId: this.maybeId(d2.app.projectId) } };
|
|
159122
|
-
if (d2.kind === "project_access") {
|
|
159123
|
-
const side = (x) => isObj(x) ? { ...x, id: this.maybeId(x.id) } : x;
|
|
159124
|
-
return { ...d2, from: side(d2.from), to: side(d2.to) };
|
|
159125
|
-
}
|
|
159126
|
-
if (d2.kind === "agent_start" && isObj(d2.project)) return { ...d2, project: { ...d2.project, id: this.maybeId(d2.project.id) } };
|
|
159127
|
-
return d2;
|
|
159128
|
-
}
|
|
159129
|
-
/** `TrashedSession` */
|
|
159130
|
-
trashed(t) {
|
|
159131
|
-
if (!isObj(t)) return t;
|
|
159132
|
-
return {
|
|
159133
|
-
...t,
|
|
159134
|
-
id: this.maybeId(t.id),
|
|
159135
|
-
project: isObj(t.project) ? { ...t.project, id: this.maybeId(t.project.id) } : t.project,
|
|
159136
|
-
machine: this.machine
|
|
159137
|
-
};
|
|
159138
|
-
}
|
|
159139
|
-
/** `TrashedRun` (#378): its app's project is this machine's, and the record is read and deleted here */
|
|
159140
|
-
trashedRun(t) {
|
|
159141
|
-
if (!isObj(t)) return t;
|
|
159142
|
-
return { ...t, app: isObj(t.app) ? { ...t.app, projectId: this.maybeId(t.app.projectId) } : t.app, machine: this.machine };
|
|
159143
|
-
}
|
|
159144
|
-
/** `SubagentStepsHeld` and `TrashedSubagentSteps` (#418) */
|
|
159145
|
-
subagentSteps(t) {
|
|
159146
|
-
if (!isObj(t)) return t;
|
|
159147
|
-
return {
|
|
159148
|
-
...t,
|
|
159149
|
-
sessionId: this.maybeId(t.sessionId),
|
|
159150
|
-
project: isObj(t.project) ? { ...t.project, id: this.maybeId(t.project.id) } : t.project,
|
|
159151
|
-
machine: this.machine
|
|
159152
|
-
};
|
|
159153
|
-
}
|
|
159154
|
-
/** `ExternalAppInfo`: a project app is that project's; a user-folder app says which machine's folder */
|
|
159155
|
-
app(a) {
|
|
159156
|
-
return isObj(a) ? { ...a, projectId: this.maybeId(a.projectId), machine: this.machine } : a;
|
|
159157
|
-
}
|
|
159158
|
-
/** `ProjectConsent` */
|
|
159159
|
-
consent(c) {
|
|
159160
|
-
return isObj(c) ? { ...c, fromProjectId: this.maybeId(c.fromProjectId), toProjectId: this.maybeId(c.toProjectId), machine: this.machine } : c;
|
|
159161
|
-
}
|
|
159162
|
-
/** One `approvals.rules` row: its numeric id folded (`encodeNumber`), its owner qualified */
|
|
159163
|
-
rule(r, encode3) {
|
|
159164
|
-
if (!isObj(r)) return r;
|
|
159165
|
-
return {
|
|
159166
|
-
...r,
|
|
159167
|
-
id: typeof r.id === "number" ? encode3(r.id) : r.id,
|
|
159168
|
-
projectId: this.maybeId(r.projectId),
|
|
159169
|
-
sessionId: this.maybeId(r.sessionId),
|
|
159170
|
-
machine: this.machine
|
|
159171
|
-
};
|
|
159172
|
-
}
|
|
159173
|
-
/** `messages.search` hits */
|
|
159174
|
-
hits(list2) {
|
|
159175
|
-
return Array.isArray(list2) ? list2.map((h) => isObj(h) ? { ...h, sessionId: this.maybeId(h.sessionId) } : h) : list2;
|
|
159176
|
-
}
|
|
159177
|
-
/**
|
|
159178
|
-
* `apps.inlineViews` rows and the `apps.inlineReopen` answer. The view instance is qualified like any id: the window
|
|
159179
|
-
* hands it back to open, call and close the view, and the hub routes those by it (plan §11)
|
|
159180
|
-
*/
|
|
159181
|
-
inlineView(v) {
|
|
159182
|
-
return isObj(v) ? { ...v, projectId: this.maybeId(v.projectId), instanceId: this.maybeId(v.instanceId) } : v;
|
|
159183
|
-
}
|
|
159184
|
-
/** An `apps.runs` row: its app's project, the session that called it, and the agent session it stood up (the panel links to it) */
|
|
159185
|
-
appRun(r) {
|
|
159186
|
-
return isObj(r) ? { ...r, projectId: this.maybeId(r.projectId), callerSessionId: this.maybeId(r.callerSessionId), sessionId: this.maybeId(r.sessionId) } : r;
|
|
159187
|
-
}
|
|
159188
|
-
/**
|
|
159189
|
-
* The `agents.listExternalSessions` answer. `externalId` is the tool's own id for the conversation, so it stays as it is;
|
|
159190
|
-
* `importedAs` is the id of the Centralu session already open for it, which the window focuses (#701)
|
|
159191
|
-
*/
|
|
159192
|
-
externalSessions(r) {
|
|
159193
|
-
if (!isObj(r) || !Array.isArray(r.sessions)) return r;
|
|
159194
|
-
return { ...r, sessions: r.sessions.map((s) => isObj(s) ? { ...s, importedAs: this.maybeId(s.importedAs) } : s) };
|
|
159195
|
-
}
|
|
159196
|
-
/**
|
|
159197
|
-
* The `apps.errors` answer: the app a declined request named is compared with the app on screen, whose project is
|
|
159198
|
-
* qualified, to decide which of the two wordings applies. `runId` is a run's own id and stays as `apps.runs` leaves it
|
|
159199
|
-
*/
|
|
159200
|
-
errorBundles(r) {
|
|
159201
|
-
if (!isObj(r)) return r;
|
|
159202
|
-
const bundle = (b2) => isObj(b2) && isObj(b2.denied) ? { ...b2, denied: { ...b2.denied, projectId: this.maybeId(b2.denied.projectId) } } : b2;
|
|
159203
|
-
return { ...r, latest: bundle(r.latest), recent: Array.isArray(r.recent) ? r.recent.map(bundle) : r.recent };
|
|
159204
|
-
}
|
|
159205
|
-
/** The `apps.openView` answer: the pinned view's instance */
|
|
159206
|
-
openedView(v) {
|
|
159207
|
-
return isObj(v) ? { ...v, instanceId: this.maybeId(v.instanceId) } : v;
|
|
159208
|
-
}
|
|
159209
|
-
/** The `apps.viewDocument` answer: the app it names (a user-folder app's null project stays null) */
|
|
159210
|
-
viewDocument(d2) {
|
|
159211
|
-
return isObj(d2) ? { ...d2, projectId: this.maybeId(d2.projectId) } : d2;
|
|
159212
|
-
}
|
|
159213
|
-
// ── Events ──────────────────────────────────────────────────────────────────────────────
|
|
159214
|
-
/**
|
|
159215
|
-
* One event of this machine in the hub's terms, or null for one the hub does not pass on.
|
|
159216
|
-
*
|
|
159217
|
-
* Dropped: what is about the remote host itself rather than its sessions and projects. The hub
|
|
159218
|
-
* has its own update, themes, preferences, agent CLIs and screen questions (and a host of v0.1.0-beta.10 or
|
|
159219
|
-
* before still sends `app_state_changed` for its control app), and an app-wide
|
|
159220
|
-
* error from another machine is not this UI's to show (§5). An event of a type this build does
|
|
159221
|
-
* not know is passed when it names a session (qualified), dropped otherwise.
|
|
159222
|
-
*/
|
|
159223
|
-
event(e) {
|
|
159224
|
-
if (!isObj(e) || typeof e.type !== "string") return null;
|
|
159225
|
-
const sid = typeof e.sessionId === "string" ? this.id(e.sessionId) : void 0;
|
|
159226
|
-
const base2 = { ...e, ...sid !== void 0 ? { sessionId: sid } : {} };
|
|
159227
|
-
switch (e.type) {
|
|
159228
|
-
// Another machine's agent asking its own windows to apply (#665) must never relaunch the hub's window
|
|
159229
|
-
case "update_status":
|
|
159230
|
-
case "update_apply_request":
|
|
159231
|
-
case "update_apply_go":
|
|
159232
|
-
case "themes_changed":
|
|
159233
|
-
case "prefs_changed":
|
|
159234
|
-
case "app_state_changed":
|
|
159235
|
-
case "agent_versions":
|
|
159236
|
-
case "mail_changed":
|
|
159237
|
-
case "external_app_questions_changed":
|
|
159238
|
-
case "orchestrator_proposals_changed":
|
|
159239
|
-
case "assistant_proposals_changed":
|
|
159240
|
-
return null;
|
|
159241
|
-
case "error":
|
|
159242
|
-
return sid === void 0 ? null : base2;
|
|
159243
|
-
case "session_created":
|
|
159244
|
-
return { ...base2, session: this.session(e.session) };
|
|
159245
|
-
case "user_message": {
|
|
159246
|
-
const out = { ...base2 };
|
|
159247
|
-
if (isObj(e.from) && typeof e.from.sessionId === "string") out.from = { ...e.from, sessionId: this.id(e.from.sessionId) };
|
|
159248
|
-
if (isObj(e.fromApp)) out.fromApp = { ...e.fromApp, projectId: this.maybeId(e.fromApp.projectId) };
|
|
159249
|
-
return out;
|
|
159250
|
-
}
|
|
159251
|
-
// The sender of the message a turn ran for (#1604), named as a message's sender is
|
|
159252
|
-
case "state_change": {
|
|
159253
|
-
const o = e.origin;
|
|
159254
|
-
if (!isObj(o) || !isObj(o.from) || typeof o.from.sessionId !== "string") return base2;
|
|
159255
|
-
return { ...base2, origin: { ...o, from: { ...o.from, sessionId: this.id(o.from.sessionId) } } };
|
|
159256
|
-
}
|
|
159257
|
-
case "handoff":
|
|
159258
|
-
return { ...base2, fromSessionId: this.maybeId(e.fromSessionId) };
|
|
159259
|
-
case "session_owner":
|
|
159260
|
-
return { ...base2, askedBy: (sid !== void 0 ? this.ownerOf?.(sid) : void 0) ?? this.maybeId(e.askedBy), parentSessionId: this.maybeId(e.parentSessionId) };
|
|
159261
|
-
case "approval_request":
|
|
159262
|
-
this.noteCard(e.sessionId, e.requestId, e.detail);
|
|
159263
|
-
return { ...base2, detail: this.approvalDetail(e.detail) };
|
|
159264
|
-
case "approval_resolved":
|
|
159265
|
-
if (typeof e.sessionId === "string" && typeof e.requestId === "string") this.unread.delete(`${e.sessionId}\0${e.requestId}`);
|
|
159266
|
-
return base2;
|
|
159267
|
-
// The view's instance, which the window opens, calls and closes it by (plan §11)
|
|
159268
|
-
case "app_view":
|
|
159269
|
-
return { ...base2, projectId: this.maybeId(e.projectId), instanceId: this.maybeId(e.instanceId) };
|
|
159270
|
-
// The view whose own call caused it, so that view does not re-read what it already has (B-5)
|
|
159271
|
-
case "external_app_state_changed":
|
|
159272
|
-
return {
|
|
159273
|
-
...base2,
|
|
159274
|
-
projectId: this.maybeId(e.projectId),
|
|
159275
|
-
...isObj(e.cause) ? { cause: { ...e.cause, instanceId: this.maybeId(e.cause.instanceId) } } : {}
|
|
159276
|
-
};
|
|
159277
|
-
case "external_app_runs_changed":
|
|
159278
|
-
case "fs_changed":
|
|
159279
|
-
return { ...base2, projectId: this.maybeId(e.projectId) };
|
|
159280
|
-
// `projects_changed`: a project another machine made (#515); the hub's windows re-read the merged list
|
|
159281
|
-
case "external_apps_changed":
|
|
159282
|
-
case "project_consents_changed":
|
|
159283
|
-
return base2;
|
|
159284
|
-
// `added` (#1220): a project that machine's assistant added, named as the hub's windows know it
|
|
159285
|
-
case "projects_changed":
|
|
159286
|
-
return typeof e.added === "string" ? { ...base2, added: this.maybeId(e.added) } : base2;
|
|
159287
|
-
default:
|
|
159288
|
-
return sid === void 0 ? null : base2;
|
|
159289
|
-
}
|
|
159290
|
-
}
|
|
159291
|
-
};
|
|
159292
|
-
|
|
159293
159450
|
// packages/agent-host/src/links/remote-client.ts
|
|
159294
159451
|
var MAX_INCOMING_CALLS = 16;
|
|
159295
159452
|
var DEFAULT_CALL_TIMEOUT_MS = 2e5;
|
|
@@ -160419,11 +160576,15 @@ var LinkedMachineConnection = class {
|
|
|
160419
160576
|
const on2 = this.record.asks === true;
|
|
160420
160577
|
let note = null;
|
|
160421
160578
|
if (this.client === client) this.tasksBack = void 0;
|
|
160579
|
+
const open6 = this.deps.hubMail ? this.deps.openTasks?.(this.id) ?? [] : [];
|
|
160580
|
+
let lacks = [];
|
|
160422
160581
|
try {
|
|
160423
|
-
const answer = await client.call("host.hubOffer", { hub: self2, on: on2, ...this.deps.hubMail ? { mail: true, you: this.id } : {}, ...this.deps.hubApps ? { apps: true } : {} });
|
|
160582
|
+
const answer = await client.call("host.hubOffer", { hub: self2, on: on2, ...this.deps.hubMail ? { mail: true, you: this.id } : {}, ...open6.length ? { open: open6 } : {}, ...this.deps.hubApps ? { apps: true } : {} });
|
|
160583
|
+
if (isObj(answer) && Array.isArray(answer.lacks)) lacks = answer.lacks.filter((id3) => typeof id3 === "string");
|
|
160424
160584
|
if (this.client === client) this.mailBack = isObj(answer) && answer.mail === true;
|
|
160425
160585
|
if (this.client === client) this.appsBack = isObj(answer) && answer.apps === true;
|
|
160426
160586
|
if (this.client === client) this.tasksBack = isObj(answer) && answer.tasks === true;
|
|
160587
|
+
if (this.client === client) this.q.mail = { hub: self2.id, own: isObj(answer) && typeof answer.host === "string" ? answer.host : null, computer: () => this.name };
|
|
160427
160588
|
} catch (err) {
|
|
160428
160589
|
if (this.client === client) this.appsBack = false;
|
|
160429
160590
|
if (this.client === client) this.mailBack = false;
|
|
@@ -160431,7 +160592,7 @@ var LinkedMachineConnection = class {
|
|
|
160431
160592
|
if (on2) note = `${this.name} could not be told yet (${err.message}); it is told again at the next connect`;
|
|
160432
160593
|
}
|
|
160433
160594
|
if (this.client !== client) return;
|
|
160434
|
-
this.deps.onOfferAnswered?.(this.id);
|
|
160595
|
+
this.deps.onOfferAnswered?.(this.id, lacks);
|
|
160435
160596
|
const changed = note !== this.asksNote;
|
|
160436
160597
|
this.asksNote = note;
|
|
160437
160598
|
if (changed) this.deps.broadcast({ type: "machine_status", machine: this.info() });
|
|
@@ -160636,7 +160797,7 @@ var LinkedMachineConnection = class {
|
|
|
160636
160797
|
if (this.stopped) return;
|
|
160637
160798
|
const readsOnly = this.readsOnly;
|
|
160638
160799
|
this.readsOnly = false;
|
|
160639
|
-
const
|
|
160800
|
+
const quiet2 = this.quietRetry;
|
|
160640
160801
|
this.quietRetry = false;
|
|
160641
160802
|
const { dataDir, shell } = this.record.remote;
|
|
160642
160803
|
const badDir = dataDir ? dataDirError(dataDir, shell) : null;
|
|
@@ -160646,7 +160807,7 @@ var LinkedMachineConnection = class {
|
|
|
160646
160807
|
this.client = null;
|
|
160647
160808
|
}
|
|
160648
160809
|
if (this.heldBack && !this.startAsked) this.setStatus("stopped", this.heldBack);
|
|
160649
|
-
else if (!(
|
|
160810
|
+
else if (!(quiet2 && this.status === "away")) this.setStatus("connecting", null);
|
|
160650
160811
|
let endpoint = await this.openTunnel();
|
|
160651
160812
|
if (!endpoint) return;
|
|
160652
160813
|
if (this.status === "away") this.setStatus("connecting", null);
|
|
@@ -162626,9 +162787,17 @@ var ROUTES = {
|
|
|
162626
162787
|
"workspace.load": HUB,
|
|
162627
162788
|
// The mailbox is the hub's: a linked machine's mail reaches it there (slice 4 of #1347)
|
|
162628
162789
|
"mail.list": HUB,
|
|
162629
|
-
//
|
|
162630
|
-
|
|
162631
|
-
"mail.
|
|
162790
|
+
// Every machine's open work in one list (#2268, router.ts); a machine's chain opens there, to read only: reply and close are the hub's mailbox's,
|
|
162791
|
+
// and the machine reads nothing in it for its own person (`lookIn`)
|
|
162792
|
+
"mail.tasks": MERGE,
|
|
162793
|
+
"mail.thread": {
|
|
162794
|
+
kind: "chain",
|
|
162795
|
+
params: (p) => ({ ...p, lookIn: true }),
|
|
162796
|
+
result: (r, q2) => {
|
|
162797
|
+
const v = q2.mailThread(r);
|
|
162798
|
+
return isObj(v) ? { ...v, lookIn: true, canReply: false } : v;
|
|
162799
|
+
}
|
|
162800
|
+
},
|
|
162632
162801
|
"mail.reply": HUB,
|
|
162633
162802
|
"mail.close": HUB,
|
|
162634
162803
|
"mail.held": HUB,
|
|
@@ -162765,6 +162934,8 @@ var Router = class {
|
|
|
162765
162934
|
return this.byKey(method, params, route.key ?? "projectId", route, ctx);
|
|
162766
162935
|
case "terminal":
|
|
162767
162936
|
return this.byKey(method, params, "terminalId", route, ctx);
|
|
162937
|
+
case "chain":
|
|
162938
|
+
return this.byKey(method, params, "threadId", { ...route, accepts: isChainId }, ctx);
|
|
162768
162939
|
case "view":
|
|
162769
162940
|
return this.byView(method, params, route, ctx);
|
|
162770
162941
|
case "noRemote": {
|
|
@@ -162780,9 +162951,10 @@ var Router = class {
|
|
|
162780
162951
|
return this.merge(method, params, ctx);
|
|
162781
162952
|
}
|
|
162782
162953
|
};
|
|
162783
|
-
/** The linked machine an id names, or null for the hub's own (an unprefixed id,
|
|
162784
|
-
owner(value) {
|
|
162785
|
-
|
|
162954
|
+
/** The linked machine an id names, or null for the hub's own (an unprefixed id, a prefix no link has, or what follows it not an id `accepts`) */
|
|
162955
|
+
owner(value, accepts2) {
|
|
162956
|
+
const found = typeof value === "string" ? qualifiedMachine(this.opts.machines(), value) : null;
|
|
162957
|
+
return found && (accepts2?.(found.id) ?? true) ? found.machine : null;
|
|
162786
162958
|
}
|
|
162787
162959
|
machineById(id3) {
|
|
162788
162960
|
return typeof id3 === "string" ? findMachine(this.opts.machines(), id3) : null;
|
|
@@ -162804,7 +162976,7 @@ var Router = class {
|
|
|
162804
162976
|
const r5 = await this.forward(m2, method, route.params ? route.params(rest, m2.q) : rest, ctx);
|
|
162805
162977
|
return route.result ? route.result(r5, m2.q) : r5;
|
|
162806
162978
|
}
|
|
162807
|
-
const m = this.owner(params[key2]);
|
|
162979
|
+
const m = this.owner(params[key2], route.accepts);
|
|
162808
162980
|
if (!m) return this.opts.local(method, params, ctx);
|
|
162809
162981
|
const { machine: _machine, ...own } = params;
|
|
162810
162982
|
let p = { ...route.orMachine ? own : params, [key2]: m.q.strip(params[key2], "The id") };
|
|
@@ -163002,8 +163174,10 @@ var Router = class {
|
|
|
163002
163174
|
const answers2 = await Promise.all(
|
|
163003
163175
|
machines.filter((m) => m.reachable).map(async (m) => {
|
|
163004
163176
|
try {
|
|
163177
|
+
if (method === "mail.tasks") await m.offerAnswered?.();
|
|
163005
163178
|
return { m, r: await callOn(m, method, params, ctx) };
|
|
163006
|
-
} catch {
|
|
163179
|
+
} catch (e) {
|
|
163180
|
+
if (method === "mail.tasks" && older2(e)) return null;
|
|
163007
163181
|
missed.push(m);
|
|
163008
163182
|
return null;
|
|
163009
163183
|
}
|
|
@@ -163023,11 +163197,47 @@ var Router = class {
|
|
|
163023
163197
|
const failed5 = Array.isArray(out.failed) ? out.failed : [];
|
|
163024
163198
|
out = { ...out, failed: [...failed5, ...missed.map((m) => ({ sessionId: m.id, name: m.name, error: "this machine could not be reached, so its archived sessions were not deleted" }))] };
|
|
163025
163199
|
}
|
|
163026
|
-
if (
|
|
163200
|
+
if (method === "mail.tasks" && isObj(out)) out = this.oneTaskEach(out);
|
|
163201
|
+
if ((method === "trash.list" || method === "subagents.usage" || method === "mail.tasks") && missed.length && isObj(out)) {
|
|
163027
163202
|
out = { ...out, unreached: missed.map((m) => ({ machineId: m.id, name: m.name })) };
|
|
163028
163203
|
}
|
|
163029
163204
|
return out;
|
|
163030
163205
|
}
|
|
163206
|
+
/**
|
|
163207
|
+
* Tasks one row per message and recipient (#2268, docs/plans/linked-mail.md §11). Mail that crossed is stored on both hosts under one id, so two
|
|
163208
|
+
* hosts list it. The hub's own row is kept, as it opens there to answer; a machine's mail to another machine, which the hub keeps no copy of, keeps
|
|
163209
|
+
* the row of the machine its recipient is on. That machine is the authority on its row and alone knows `running`, so the kept row takes its state.
|
|
163210
|
+
* A host that capped its list makes the answer say how many open rows it shows, counted once de-duplicated, as the window counts its rows
|
|
163211
|
+
*/
|
|
163212
|
+
oneTaskEach(out) {
|
|
163213
|
+
const from = (t) => this.owner(t.root, isChainId);
|
|
163214
|
+
const kept = /* @__PURE__ */ new Map();
|
|
163215
|
+
const odd = [];
|
|
163216
|
+
for (const t of listIn(out, "tasks")) {
|
|
163217
|
+
if (!isObj(t) || !isObj(t.assignee)) {
|
|
163218
|
+
odd.push(t);
|
|
163219
|
+
continue;
|
|
163220
|
+
}
|
|
163221
|
+
const origin = from(t);
|
|
163222
|
+
const on2 = this.owner(t.assignee.sessionId);
|
|
163223
|
+
const authority = on2 !== null && origin === on2 ? t : null;
|
|
163224
|
+
const key2 = `${String(t.id)}\0${String(t.assignee.address)}`;
|
|
163225
|
+
const seen = kept.get(key2);
|
|
163226
|
+
if (!seen) kept.set(key2, { row: t, hub: origin === null, authority });
|
|
163227
|
+
else if (seen.hub || !authority) kept.set(key2, { ...seen, authority: seen.authority ?? authority });
|
|
163228
|
+
else kept.set(key2, { row: t, hub: false, authority });
|
|
163229
|
+
}
|
|
163230
|
+
const rows3 = [...kept.values()].map(
|
|
163231
|
+
({ row, authority }) => authority && authority !== row ? { ...row, state: authority.state, outcome: authority.outcome, updatedAt: authority.updatedAt } : row
|
|
163232
|
+
);
|
|
163233
|
+
const capped = typeof out.capped === "number" ? rows3.filter((t) => t.state !== "done").length : null;
|
|
163234
|
+
return { ...out, tasks: [...rows3, ...odd], capped };
|
|
163235
|
+
}
|
|
163236
|
+
};
|
|
163237
|
+
var listIn = (x, field) => isObj(x) && Array.isArray(x[field]) ? x[field] : [];
|
|
163238
|
+
var isChainId = (id3) => {
|
|
163239
|
+
const kind = parseMailId(id3)?.kind;
|
|
163240
|
+
return kind === "message" || kind === "thread";
|
|
163031
163241
|
};
|
|
163032
163242
|
function combine(method, acc, r, q2) {
|
|
163033
163243
|
const list2 = (x) => Array.isArray(x) ? x : [];
|
|
@@ -163053,6 +163263,12 @@ function combine(method, acc, r, q2) {
|
|
|
163053
163263
|
..."subagentSteps" in a || "subagentSteps" in b2 ? { subagentSteps: [...list2(a.subagentSteps), ...list2(b2.subagentSteps).map((t) => q2.subagentSteps(t))] } : {}
|
|
163054
163264
|
};
|
|
163055
163265
|
}
|
|
163266
|
+
case "mail.tasks": {
|
|
163267
|
+
const a = isObj(acc) ? acc : { tasks: [] };
|
|
163268
|
+
const b2 = isObj(r) ? r : { tasks: [] };
|
|
163269
|
+
const capped = typeof a.capped === "number" ? a.capped : typeof b2.capped === "number" ? b2.capped : null;
|
|
163270
|
+
return { ...a, tasks: [...listIn(a, "tasks"), ...q2.taskRows(listIn(b2, "tasks"))], capped };
|
|
163271
|
+
}
|
|
163056
163272
|
case "subagents.usage": {
|
|
163057
163273
|
const a = isObj(acc) ? acc : { sessions: [] };
|
|
163058
163274
|
const b2 = isObj(r) ? r : { sessions: [] };
|
|
@@ -163138,12 +163354,12 @@ function linkDepsFor(store2, rest) {
|
|
|
163138
163354
|
const log = (line) => rest.log?.(stamped(line));
|
|
163139
163355
|
return { ...rest, log, mirror: storeMirror(store2), registry: storeRegistry(store2), tunnelFor: tunnelsFor(store2, log) };
|
|
163140
163356
|
}
|
|
163141
|
-
var
|
|
163357
|
+
var kindOf3 = (k2) => k2 === "sessions" ? "session" : "project";
|
|
163142
163358
|
var withIds = (list2) => list2.filter((x) => isObj(x) && typeof x.id === "string");
|
|
163143
163359
|
function storeMirror(store2) {
|
|
163144
163360
|
return {
|
|
163145
|
-
read: (machine, kind) => store2.machines.machineHeaders(machine,
|
|
163146
|
-
replace: (machine, kind, list2) => store2.machines.replaceMachineHeaders(machine,
|
|
163361
|
+
read: (machine, kind) => store2.machines.machineHeaders(machine, kindOf3(kind)),
|
|
163362
|
+
replace: (machine, kind, list2) => store2.machines.replaceMachineHeaders(machine, kindOf3(kind), withIds(list2)),
|
|
163147
163363
|
upsertSession: (machine, session2) => {
|
|
163148
163364
|
if (typeof session2.id === "string") store2.machines.upsertMachineSession(machine, session2);
|
|
163149
163365
|
},
|
|
@@ -163897,7 +164113,7 @@ var handedToken = launch.tokenOnStdin ? await readHandedToken(process.stdin).cat
|
|
|
163897
164113
|
console.error(`[agent-host] the launcher did not hand over the token: ${e.message}`);
|
|
163898
164114
|
process.exit(1);
|
|
163899
164115
|
}) : launch.token;
|
|
163900
|
-
var BUILD = true ? "
|
|
164116
|
+
var BUILD = true ? "a599200" : "dev";
|
|
163901
164117
|
var { values } = parseArgs({
|
|
163902
164118
|
options: {
|
|
163903
164119
|
port: { type: "string", default: "5175" },
|
|
@@ -164074,7 +164290,6 @@ var mailPerson = new MailPerson(hostMailbox.service, store.mailbox, mailDelivery
|
|
|
164074
164290
|
const s = mgr.sessionInfo(id3);
|
|
164075
164291
|
return s ? { name: s.name, state: s.state } : void 0;
|
|
164076
164292
|
}, hostMailbox),
|
|
164077
|
-
legacyChain: (threadId) => store.legacyChain(threadId, void 0, 100),
|
|
164078
164293
|
projectLabel: (projectId) => hostMailbox.reach.projectLabel(projectId),
|
|
164079
164294
|
untrusted: (projectId) => hostMailbox.reach.untrusted(projectId),
|
|
164080
164295
|
// A session's turn on a chain, from the turn records while the session is in a turn: the session Mark done and Drop tell, though they stop nothing (C12)
|
|
@@ -164234,8 +164449,9 @@ var links = new Links(linkDepsFor(store, {
|
|
|
164234
164449
|
hubMail: true,
|
|
164235
164450
|
// This hub's apps used by the agents its sessions started on a machine (#1938, §13.5)
|
|
164236
164451
|
hubApps: true,
|
|
164237
|
-
// A machine that took this hub's mail at a connect hears what became of mail that crossed while it was away (#2067 review)
|
|
164238
|
-
onOfferAnswered: () => hostMailbox.across.
|
|
164452
|
+
// A machine that took this hub's mail at a connect hears what became of mail that crossed while it was away (#2067 review); the tasks it says never arrived are settled (#2289)
|
|
164453
|
+
onOfferAnswered: (machineId, lacks) => hostMailbox.across.offerAnswered(machineId, lacks),
|
|
164454
|
+
openTasks: (machineId) => hostMailbox.across.openTasksTo(machineId),
|
|
164239
164455
|
// When agents compact: this hub's setting governs the machines it links (#1376)
|
|
164240
164456
|
autoCompact: () => autoCompactOf(mgr.prefs.uiPreferences()),
|
|
164241
164457
|
// 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
|