@centralu/host-win32-x64 0.1.0-beta.72 → 0.1.0-beta.73
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 +835 -620
- 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.73";
|
|
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) }),
|
|
@@ -64732,9 +64755,8 @@ function activityCounts(s) {
|
|
|
64732
64755
|
function turnCut(s) {
|
|
64733
64756
|
return inTurn(s.state);
|
|
64734
64757
|
}
|
|
64735
|
-
function cutTurns(s
|
|
64736
|
-
|
|
64737
|
-
return [...inTurnNow, ...woken.filter((id3) => !inTurnNow.some((t) => t.id === id3)).map((id3) => ({ id: id3, woken: true }))];
|
|
64758
|
+
function cutTurns(s) {
|
|
64759
|
+
return s.sessions.flatMap((x) => x.id !== void 0 && turnCut(x) ? [{ id: x.id }] : []);
|
|
64738
64760
|
}
|
|
64739
64761
|
function sessionIdle(s, process4) {
|
|
64740
64762
|
const busy = busyWith(s);
|
|
@@ -66566,7 +66588,7 @@ function raceTimeout(p, ms3, fallback) {
|
|
|
66566
66588
|
})
|
|
66567
66589
|
]).finally(() => clearTimeout(timer));
|
|
66568
66590
|
}
|
|
66569
|
-
async function raceBound(outcome2, ms3, signal, ...
|
|
66591
|
+
async function raceBound(outcome2, ms3, signal, ...wakes) {
|
|
66570
66592
|
let timer;
|
|
66571
66593
|
let onAbort;
|
|
66572
66594
|
const bound = new Promise((resolve21) => timer = unrefTimer(() => resolve21("bound"), ms3));
|
|
@@ -66577,7 +66599,7 @@ async function raceBound(outcome2, ms3, signal, ...wakes2) {
|
|
|
66577
66599
|
else signal.addEventListener("abort", onAbort, { once: true });
|
|
66578
66600
|
});
|
|
66579
66601
|
try {
|
|
66580
|
-
return await Promise.race([outcome2, bound, aborted2, ...
|
|
66602
|
+
return await Promise.race([outcome2, bound, aborted2, ...wakes]);
|
|
66581
66603
|
} finally {
|
|
66582
66604
|
clearTimeout(timer);
|
|
66583
66605
|
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
@@ -75941,12 +75963,12 @@ var require_discriminator = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
75941
75963
|
},
|
|
75942
75964
|
code(cxt2) {
|
|
75943
75965
|
const { gen, data, schema, parentSchema, it: it2 } = cxt2;
|
|
75944
|
-
const { oneOf:
|
|
75966
|
+
const { oneOf: oneOf2 } = parentSchema;
|
|
75945
75967
|
if (!it2.opts.discriminator) throw new Error("discriminator: requires discriminator option");
|
|
75946
75968
|
const tagName = schema.propertyName;
|
|
75947
75969
|
if (typeof tagName != "string") throw new Error("discriminator: requires propertyName");
|
|
75948
75970
|
if (schema.mapping) throw new Error("discriminator: mapping is not supported");
|
|
75949
|
-
if (!
|
|
75971
|
+
if (!oneOf2) throw new Error("discriminator: requires oneOf keyword");
|
|
75950
75972
|
const valid = gen.let("valid", false);
|
|
75951
75973
|
const tag = gen.const("tag", (0, codegen_1._)`${data}${(0, codegen_1.getProperty)(tagName)}`);
|
|
75952
75974
|
gen.if((0, codegen_1._)`typeof ${tag} == "string"`, () => validateMapping(), () => cxt2.error(false, {
|
|
@@ -75984,8 +76006,8 @@ var require_discriminator = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
75984
76006
|
const oneOfMapping = {};
|
|
75985
76007
|
const topRequired = hasRequired(parentSchema);
|
|
75986
76008
|
let tagRequired = true;
|
|
75987
|
-
for (let i = 0; i <
|
|
75988
|
-
let sch =
|
|
76009
|
+
for (let i = 0; i < oneOf2.length; i++) {
|
|
76010
|
+
let sch = oneOf2[i];
|
|
75989
76011
|
if ((sch === null || sch === void 0 ? void 0 : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it2.self.RULES)) {
|
|
75990
76012
|
const ref = sch.$ref;
|
|
75991
76013
|
sch = compile_1.resolveRef.call(it2.self, it2.schemaEnv.root, it2.baseId, ref);
|
|
@@ -97319,12 +97341,12 @@ var require_discriminator2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
97319
97341
|
},
|
|
97320
97342
|
code(cxt2) {
|
|
97321
97343
|
const { gen, data, schema, parentSchema, it: it2 } = cxt2;
|
|
97322
|
-
const { oneOf:
|
|
97344
|
+
const { oneOf: oneOf2 } = parentSchema;
|
|
97323
97345
|
if (!it2.opts.discriminator) throw new Error("discriminator: requires discriminator option");
|
|
97324
97346
|
const tagName = schema.propertyName;
|
|
97325
97347
|
if (typeof tagName != "string") throw new Error("discriminator: requires propertyName");
|
|
97326
97348
|
if (schema.mapping) throw new Error("discriminator: mapping is not supported");
|
|
97327
|
-
if (!
|
|
97349
|
+
if (!oneOf2) throw new Error("discriminator: requires oneOf keyword");
|
|
97328
97350
|
const valid = gen.let("valid", false);
|
|
97329
97351
|
const tag = gen.const("tag", (0, codegen_1._)`${data}${(0, codegen_1.getProperty)(tagName)}`);
|
|
97330
97352
|
gen.if((0, codegen_1._)`typeof ${tag} == "string"`, () => validateMapping(), () => cxt2.error(false, {
|
|
@@ -97362,8 +97384,8 @@ var require_discriminator2 = /* @__PURE__ */ __commonJSMin2(((exports) => {
|
|
|
97362
97384
|
const oneOfMapping = {};
|
|
97363
97385
|
const topRequired = hasRequired(parentSchema);
|
|
97364
97386
|
let tagRequired = true;
|
|
97365
|
-
for (let i = 0; i <
|
|
97366
|
-
let sch =
|
|
97387
|
+
for (let i = 0; i < oneOf2.length; i++) {
|
|
97388
|
+
let sch = oneOf2[i];
|
|
97367
97389
|
if ((sch === null || sch === void 0 ? void 0 : sch.$ref) && !(0, util_1.schemaHasRulesButRef)(sch, it2.self.RULES)) {
|
|
97368
97390
|
const ref = sch.$ref;
|
|
97369
97391
|
sch = compile_1.resolveRef.call(it2.self, it2.schemaEnv.root, it2.baseId, ref);
|
|
@@ -109725,6 +109747,9 @@ function isSessionId2(id3) {
|
|
|
109725
109747
|
function sessionAddress(host, sessionId) {
|
|
109726
109748
|
return checked(`session:${host}/${sessionId}`);
|
|
109727
109749
|
}
|
|
109750
|
+
function appAddress(host, projectId, appId) {
|
|
109751
|
+
return checked(`app:${host}/${projectId}/${appId}`);
|
|
109752
|
+
}
|
|
109728
109753
|
function parseAddress(address) {
|
|
109729
109754
|
if (address === PERSON) return { kind: "person" };
|
|
109730
109755
|
if (address === CENTRALU) return { kind: "centralu" };
|
|
@@ -109734,6 +109759,11 @@ function parseAddress(address) {
|
|
|
109734
109759
|
if (appHost !== void 0 && projectId !== void 0 && appId !== void 0) return { kind: "app", host: appHost, projectId, appId };
|
|
109735
109760
|
return null;
|
|
109736
109761
|
}
|
|
109762
|
+
function inHubTerms(address, hub, machine) {
|
|
109763
|
+
if (address === sessionAddress(hub, PERSON_ID)) return PERSON;
|
|
109764
|
+
const p = parseAddress(address);
|
|
109765
|
+
return machine && p?.kind === "session" && p.host === machine.host && !p.sessionId.includes(".") ? sessionAddress(hub, `${machine.id}.${p.sessionId}`) : address;
|
|
109766
|
+
}
|
|
109737
109767
|
function checked(address) {
|
|
109738
109768
|
if (!parseAddress(address)) throw new Error(`Not a mail address: ${JSON.stringify(address)}`);
|
|
109739
109769
|
return address;
|
|
@@ -109971,28 +110001,7 @@ var askersKey = (asker) => [asker.turn, asker.messageId, ...(asker.also ?? []).m
|
|
|
109971
110001
|
import { randomUUID as randomUUID11 } from "node:crypto";
|
|
109972
110002
|
|
|
109973
110003
|
// 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
110004
|
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
110005
|
|
|
109997
110006
|
// packages/agent-host/src/mail/rules.ts
|
|
109998
110007
|
import { createHash as createHash9 } from "node:crypto";
|
|
@@ -110054,14 +110063,6 @@ function postsPerMinute(sender) {
|
|
|
110054
110063
|
}
|
|
110055
110064
|
var ASKS_PER_HOUR = 5;
|
|
110056
110065
|
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
110066
|
function needsReceiver(m) {
|
|
110066
110067
|
return isPerson(m.sender) || m.kind === "task" || m.kind === "report" || m.needsReply || isSendNote(m) || m.facts.needsOwner === true;
|
|
110067
110068
|
}
|
|
@@ -110137,7 +110138,7 @@ var WARNING_TEXT = {
|
|
|
110137
110138
|
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
110139
|
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
110140
|
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,
|
|
110141
|
+
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
110142
|
/** The three guards that refuse rather than warn (#1684, #2035): the person hears of the first refusal of each kind a clock hour */
|
|
110142
110143
|
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
110144
|
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 +110563,18 @@ var MailDelivery = class {
|
|
|
110562
110563
|
return;
|
|
110563
110564
|
}
|
|
110564
110565
|
const { drained } = plan;
|
|
110565
|
-
const
|
|
110566
|
+
const quiet2 = !drained.wake;
|
|
110566
110567
|
const joins = state.joins === true;
|
|
110567
|
-
const turn =
|
|
110568
|
+
const turn = quiet2 || joins ? void 0 : this.turns?.begin(sessionId, { workMessage: drained.workMessage, starter: this.starterOf(drained) });
|
|
110568
110569
|
const cancelTurn = () => {
|
|
110569
110570
|
if (turn !== void 0) this.turns?.cancel(sessionId, turn);
|
|
110570
110571
|
};
|
|
110571
110572
|
const delivered = {};
|
|
110572
|
-
const shown3 =
|
|
110573
|
+
const shown3 = quiet2 ? void 0 : this.shownOf(drained);
|
|
110573
110574
|
const inputId = joins ? randomUUID11() : void 0;
|
|
110574
110575
|
const depth = Math.max(0, ...drained.messageIds.map((id3) => this.records.message(id3)?.facts.agentDepth ?? 0));
|
|
110575
110576
|
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) => {
|
|
110577
|
+
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
110578
|
cancelTurn();
|
|
110578
110579
|
if (delivered.at !== void 0) this.takeBack(recipient, drained.messageIds, delivered.at, e);
|
|
110579
110580
|
});
|
|
@@ -110593,14 +110594,14 @@ var MailDelivery = class {
|
|
|
110593
110594
|
this.records.markRead(recipient, drained.inline, deliveredAt);
|
|
110594
110595
|
});
|
|
110595
110596
|
if (inputId) this.joined.set(recipient, [...this.joined.get(recipient) ?? [], { id: inputId, ids: drained.messageIds }]);
|
|
110596
|
-
if (!
|
|
110597
|
+
if (!quiet2 && !joins) this.lastWake.set(recipient, this.now());
|
|
110597
110598
|
if (waiting) {
|
|
110598
110599
|
this.left.delete(recipient);
|
|
110599
110600
|
this.crowd = this.crowd?.filter((r) => r !== recipient) ?? null;
|
|
110600
110601
|
if (this.crowd?.length === 0) this.crowd = null;
|
|
110601
110602
|
this.crowdChanged();
|
|
110602
110603
|
}
|
|
110603
|
-
if (!
|
|
110604
|
+
if (!quiet2) this.warnIfRunning(recipient, drained.messageIds, deliveredAt);
|
|
110604
110605
|
}
|
|
110605
110606
|
/**
|
|
110606
110607
|
* 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
|
|
@@ -113290,7 +113291,7 @@ var CONTINUE_NOTES = {
|
|
|
113290
113291
|
var UPDATE_WAKES_AT_ONCE = 3;
|
|
113291
113292
|
var UPDATE_SLOT_MS = 12e4;
|
|
113292
113293
|
var ANSWERED = /* @__PURE__ */ new Set(["message_delta", "reasoning_delta", "tool_call", "usage_update", "approval_request", "question_request", "error", "limit_reached", "session_deleted"]);
|
|
113293
|
-
var wakeEnded = (e) => ANSWERED.has(e.type) || e.type === "state_change" && e.state !== "working" || e.type === "session_live" && !e.live;
|
|
113294
|
+
var wakeEnded = (e) => ANSWERED.has(e.type) || e.type === "turn_complete" || e.type === "state_change" && e.state !== "working" || e.type === "session_live" && !e.live;
|
|
113294
113295
|
var RESET_MARGIN_MS = 6e4;
|
|
113295
113296
|
var NO_RESET_RETRY_MS = 30 * 6e4;
|
|
113296
113297
|
var PROBE_STEPS_MS = [15e3, 3e4, 6e4, 12e4, 3e5];
|
|
@@ -113384,12 +113385,27 @@ ${spentWords(tries)}` } };
|
|
|
113384
113385
|
this.wait(m.id, { cause: i.reason, tool: m.tool, at: a.at, tries: a.tries, phase: "waiting" });
|
|
113385
113386
|
}
|
|
113386
113387
|
}
|
|
113388
|
+
/**
|
|
113389
|
+
* Holds `e` when it is the turn end a process resumed by an update's wake says of its own before the note's turn (`ANSWERED`), and says whether it
|
|
113390
|
+
* did: the first `turn_complete` once the wake is in (`waking`), nothing having answered it. It ends no turn of the session's (#2312). Read as one, it
|
|
113391
|
+
* answered the continued turn's tasks with the cut turn's words and left the session at rest while the note's turn ran, so the real end reported
|
|
113392
|
+
* nothing. A second one is the turn's end. Held, it is said after all when the slot runs out with nothing run (`slotOver`). Only for a tool that
|
|
113393
|
+
* says it ends such a turn (`AgentAdapter.resumeEndsOwnTurn`): another's first end is the turn's
|
|
113394
|
+
*/
|
|
113395
|
+
holdOwnEnd(e) {
|
|
113396
|
+
const w = e.type === "turn_complete" ? this.updates.get(e.sessionId) : void 0;
|
|
113397
|
+
if (w?.phase !== "waking" || w.ownEnd || !this.host.resumeEndsOwnTurn(w.sessionId)) return false;
|
|
113398
|
+
w.ownEnd = true;
|
|
113399
|
+
console.error(`[agent-host] ${w.sessionId.slice(0, 8)}: held the turn end its resumed process said of its own before the update's note (#2312)`);
|
|
113400
|
+
return true;
|
|
113401
|
+
}
|
|
113387
113402
|
/** Every event of a session: the ones that end a held turn take its wait away; a finished turn starts every count over and says its tool's API answers */
|
|
113388
113403
|
observe(e) {
|
|
113389
113404
|
const id3 = e.sessionId;
|
|
113390
113405
|
if (!id3) return;
|
|
113391
113406
|
const u = this.updates.get(id3);
|
|
113392
113407
|
if (u?.phase === "waking" && wakeEnded(e)) this.endUpdate(id3, u, null);
|
|
113408
|
+
else if (u?.phase === "waking" && u.ownEnd && e.type === "activity" && e.activity !== null) u.running = true;
|
|
113393
113409
|
else if (u && e.type === "session_deleted") this.endUpdate(id3, u, "dropped");
|
|
113394
113410
|
if (e.type === "turn_complete" || e.type === "error" || e.type === "limit_reached" || e.type === "session_deleted" || e.type === "state_change" && e.state !== "working") this.cancelHeld(id3);
|
|
113395
113411
|
if (e.type === "session_deleted") this.dropStop(id3, false);
|
|
@@ -113625,8 +113641,8 @@ Centralu was going to retry this turn, but it restarted first. Send a message to
|
|
|
113625
113641
|
if (this.updates.size) setTimeout(() => this.pump(), 0);
|
|
113626
113642
|
}
|
|
113627
113643
|
/**
|
|
113628
|
-
* The wakes whose note went in and that have not answered yet (#2264 review): a stop for an update now lists
|
|
113629
|
-
*
|
|
113644
|
+
* The wakes whose note went in and that have not answered yet (#2264 review): a stop for an update now lists what else they stopped again, their
|
|
113645
|
+
* turn being listed as any (`cutTurns`). Their entry left the list at the send. One silent for
|
|
113630
113646
|
* `UPDATE_SLOT_MS` gave its slot up and is not among them: a stop after that does not list it again (accepted, as a request that hangs that long)
|
|
113631
113647
|
*/
|
|
113632
113648
|
unanswered() {
|
|
@@ -113641,6 +113657,18 @@ Centralu was going to retry this turn, but it restarted first. Send a message to
|
|
|
113641
113657
|
void this.fireUpdate(id3, w);
|
|
113642
113658
|
}
|
|
113643
113659
|
}
|
|
113660
|
+
/**
|
|
113661
|
+
* A woken session said nothing for `UPDATE_SLOT_MS`: its slot goes to the next. One whose resumed process's turn end was held (`holdOwnEnd`), that
|
|
113662
|
+
* is still in its turn and whose tool said nothing of being busy since (`running`) ran nothing after it: that end was the turn's, and is said now,
|
|
113663
|
+
* so the session is not left working with no turn
|
|
113664
|
+
*/
|
|
113665
|
+
slotOver(id3, w) {
|
|
113666
|
+
this.endUpdate(id3, w, null);
|
|
113667
|
+
const m = this.host.meta.get(id3);
|
|
113668
|
+
if (!w.ownEnd || w.running || !m || !inTurn(m.state) || this.host.leaving()) return;
|
|
113669
|
+
console.error(`[agent-host] ${id3.slice(0, 8)}: nothing ran after the turn end held for ${UPDATE_SLOT_MS / 1e3} s, so it ends the turn (#2312)`);
|
|
113670
|
+
this.host.note({ type: "turn_complete", sessionId: id3 });
|
|
113671
|
+
}
|
|
113644
113672
|
/** An update's wake is over (answered, or `step`): its slot goes to the next */
|
|
113645
113673
|
endUpdate(id3, w, step, err) {
|
|
113646
113674
|
if (this.updates.get(id3) === w) this.updates.delete(id3);
|
|
@@ -113663,7 +113691,7 @@ Centralu was going to retry this turn, but it restarted first. Send a message to
|
|
|
113663
113691
|
handed: () => {
|
|
113664
113692
|
handed = true;
|
|
113665
113693
|
w.phase = "waking";
|
|
113666
|
-
w.slot = setTimeout(() => this.
|
|
113694
|
+
w.slot = setTimeout(() => this.slotOver(id3, w), UPDATE_SLOT_MS);
|
|
113667
113695
|
w.slot.unref?.();
|
|
113668
113696
|
}
|
|
113669
113697
|
});
|
|
@@ -119625,9 +119653,6 @@ function pragmaNumber(db, name) {
|
|
|
119625
119653
|
if (typeof v !== "number") throw new Error(`PRAGMA ${name} answered ${typeof v}, not a number`);
|
|
119626
119654
|
return v;
|
|
119627
119655
|
}
|
|
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
119656
|
|
|
119632
119657
|
// packages/agent-host/src/dev-services/store/mailbox.ts
|
|
119633
119658
|
var MAIL_KINDS = ["message", "task", "report", "notice"];
|
|
@@ -119652,6 +119677,7 @@ var MailTargetMissing = class extends Error {
|
|
|
119652
119677
|
};
|
|
119653
119678
|
var DAY = 24 * 60 * 60 * 1e3;
|
|
119654
119679
|
var MAILBOX_RETENTION = { waitingMs: 180 * DAY, settledMs: 30 * DAY, readNoticeMs: 14 * DAY, batch: 500 };
|
|
119680
|
+
var likePrefix = (prefix) => `${prefix.replace(/[\\%_]/g, (c) => `\\${c}`)}%`;
|
|
119655
119681
|
var WATCHED = `(m.needs_reply = 1 OR m.kind = 'task')`;
|
|
119656
119682
|
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
119683
|
var HELD = `r.held IS NOT NULL AND r.held NOT IN ('released', 'dismissed')`;
|
|
@@ -120093,8 +120119,18 @@ var MailboxRecords = class {
|
|
|
120093
120119
|
// ── Across a link (#2067 item 2, docs/plans/linked-mail.md §6) ──
|
|
120094
120120
|
/** Whether `sender` ever sent a message to an address that starts with `prefix` (a linked machine's sessions, `session:<hub>/<machine>.`) */
|
|
120095
120121
|
sentToward(sender, prefix) {
|
|
120096
|
-
|
|
120097
|
-
|
|
120122
|
+
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;
|
|
120123
|
+
}
|
|
120124
|
+
/**
|
|
120125
|
+
* The open tasks given after `since` to addresses that start with `prefix` (a linked machine's sessions, `session:<hub>/<machine>.`), oldest first,
|
|
120126
|
+
* at most `limit` (#2289)
|
|
120127
|
+
*/
|
|
120128
|
+
openTasksToward(prefix, since, limit) {
|
|
120129
|
+
return this.db.prepare(
|
|
120130
|
+
`SELECT m.id FROM mail m JOIN mail_recipients r ON r.message_id = m.id
|
|
120131
|
+
WHERE m.kind = 'task' AND r.recipient LIKE ? ESCAPE '\\' AND r.settled IS NULL AND r.released_at IS NULL AND m.created_at > ?
|
|
120132
|
+
ORDER BY m.created_at, m.id LIMIT ?`
|
|
120133
|
+
).all(likePrefix(prefix), since, limit).map((r) => r.id);
|
|
120098
120134
|
}
|
|
120099
120135
|
/**
|
|
120100
120136
|
* 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 +120549,12 @@ var MailboxRecords = class {
|
|
|
120513
120549
|
{ key: key2, at: anchor?.createdAt ?? null, id: anchor?.id ?? "", limit: opts.limit }
|
|
120514
120550
|
);
|
|
120515
120551
|
}
|
|
120516
|
-
/**
|
|
120552
|
+
/**
|
|
120553
|
+
* `UPDATE mail_recipients SET <set> WHERE recipient = ? [AND <also>] AND message_id IN <ids>`, the ids passed as one JSON parameter read with
|
|
120554
|
+
* `json_each`; `setArgs` fill the `?` of `set`. Returns the rows changed
|
|
120555
|
+
*/
|
|
120517
120556
|
update(set3, setArgs, recipient, ids, also) {
|
|
120518
|
-
return
|
|
120557
|
+
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
120558
|
}
|
|
120520
120559
|
count(sql, ...args) {
|
|
120521
120560
|
return this.db.prepare(sql).get(...args)?.n ?? 0;
|
|
@@ -120629,22 +120668,20 @@ function fitFrame(items, budget, render) {
|
|
|
120629
120668
|
}
|
|
120630
120669
|
return { text: text3, shown: shown3.map((i) => i.messageId), inline: cut3 ? [] : shown3.filter((i) => i.inline !== void 0).map((i) => i.messageId) };
|
|
120631
120670
|
}
|
|
120632
|
-
function mailCalls(
|
|
120671
|
+
function mailCalls(form) {
|
|
120633
120672
|
const call2 = (action, fields5 = {}) => {
|
|
120634
120673
|
const entries = Object.entries(fields5);
|
|
120635
120674
|
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
120675
|
};
|
|
120637
|
-
const target = version2 === 2 ? "id" : "thread";
|
|
120638
120676
|
return {
|
|
120639
|
-
read: (id3) => call2("read", id3 === void 0 ? {} : {
|
|
120640
|
-
answer: (id3) => call2(
|
|
120641
|
-
done: (id3) => call2(
|
|
120677
|
+
read: (id3) => call2("read", id3 === void 0 ? {} : { thread: id3 }),
|
|
120678
|
+
answer: (id3) => call2("reply", { thread: id3, text: "\u2026" }),
|
|
120679
|
+
done: (id3) => call2("handled", { thread: id3 }),
|
|
120642
120680
|
inbox: () => call2("inbox"),
|
|
120643
|
-
sessions: () => call2("sessions"),
|
|
120644
120681
|
close: (id3) => call2("close", { thread: id3 })
|
|
120645
120682
|
};
|
|
120646
120683
|
}
|
|
120647
|
-
var PLAIN_MESSAGE_CALLS = mailCalls(
|
|
120684
|
+
var PLAIN_MESSAGE_CALLS = mailCalls("plain");
|
|
120648
120685
|
var FOR_PERSON = {
|
|
120649
120686
|
note: "from the Assistant, which acts for the person in Centralu: carry it out as the person's request. No answer is owed:",
|
|
120650
120687
|
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 +122854,7 @@ var DelegationForks = class {
|
|
|
122817
122854
|
return this.forkTrustError(callerId, target, true) ?? this.flow.starts.agentCeilingError(callerId, target.projectId ?? "");
|
|
122818
122855
|
}
|
|
122819
122856
|
/** `forkGateError` without the ceiling: read before the card and again once it is answered (`forkFor`); `quiet` as `trustGate` */
|
|
122820
|
-
forkTrustError(callerId, target,
|
|
122857
|
+
forkTrustError(callerId, target, quiet2) {
|
|
122821
122858
|
const caller = this.host.meta.get(callerId);
|
|
122822
122859
|
if (!caller) return "the requesting session is gone";
|
|
122823
122860
|
if (!this.host.meta.has(target.id)) return "it is no longer here";
|
|
@@ -122825,7 +122862,7 @@ var DelegationForks = class {
|
|
|
122825
122862
|
if (deep) return deep.replace(/^This/, "this").replace(/\.$/, "");
|
|
122826
122863
|
if (!target.projectId) return NO_PROJECT;
|
|
122827
122864
|
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",
|
|
122865
|
+
return this.host.trustGate(callerId, target.projectId, "forking a session", quiet2);
|
|
122829
122866
|
}
|
|
122830
122867
|
/** Why `target` cannot be forked for `callerId` now, or null. Its project is said first, whatever its CLI can do (#994 review) */
|
|
122831
122868
|
forkWhy(callerId, target) {
|
|
@@ -123965,6 +124002,7 @@ var SessionEvents = class {
|
|
|
123965
124002
|
return this.onEvent({ ...e, live: m.backgroundTasks.filter((t) => t.status === "running") });
|
|
123966
124003
|
}
|
|
123967
124004
|
if (e.type === "error") e = this.host.turnContinue.hold(e);
|
|
124005
|
+
if (this.host.turnContinue.holdOwnEnd(e)) return;
|
|
123968
124006
|
if (e.sessionId) this.host.turnContinue.observe(e);
|
|
123969
124007
|
const unborn = e.sessionId && !this.host.meta.has(e.sessionId) ? this.host.record.unborn.get(e.sessionId) : void 0;
|
|
123970
124008
|
if (unborn) {
|
|
@@ -124547,11 +124585,11 @@ var MailSessionsView = class {
|
|
|
124547
124585
|
if (this.host.closing) return { kind: "busy", why: "turn" };
|
|
124548
124586
|
const busy = cardOrTurn(m);
|
|
124549
124587
|
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 };
|
|
124588
|
+
const quiet2 = live2 && this.host.adapters.get(m.tool)?.quietInput === true;
|
|
124589
|
+
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
124590
|
if (busy !== null) return { kind: "busy", why: busy === "turn" ? "turn" : "card" };
|
|
124553
124591
|
if (m.state === "limited") return { kind: "busy", why: "limited" };
|
|
124554
|
-
return { kind: "ready", live: live2, quiet, auto: m.permissionPreset === "auto" };
|
|
124592
|
+
return { kind: "ready", live: live2, quiet: quiet2, auto: m.permissionPreset === "auto" };
|
|
124555
124593
|
}
|
|
124556
124594
|
/** 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
124595
|
takesTurn(id3) {
|
|
@@ -125494,7 +125532,7 @@ var HostTenure = class {
|
|
|
125494
125532
|
this.disposing = true;
|
|
125495
125533
|
this.leaveHost("Centralu is shutting down");
|
|
125496
125534
|
const sessions = this.stoppingForUpdate && this.host.keeperOpts.updateResume ? this.host.listSessions() : [];
|
|
125497
|
-
const cut3 = cutTurns({ sessions, terminals: 0, commandRuns: 0 }
|
|
125535
|
+
const cut3 = cutTurns({ sessions, terminals: 0, commandRuns: 0 });
|
|
125498
125536
|
const stopped = stoppedAtUpdate(sessions, (id3, callId) => this.host.store.messages.toolCallInput(id3, callId), woken.flatMap((w) => w.stopped ? [w.stopped] : []));
|
|
125499
125537
|
for (const [id3, run2] of this.host.record.streams) this.host.record.flushStream(id3, run2);
|
|
125500
125538
|
await Promise.allSettled([...[...this.host.handles.values()].map((h) => h.dispose()), ...this.host.merges.mergeChecks]);
|
|
@@ -125942,11 +125980,11 @@ var SelfCompaction = class {
|
|
|
125942
125980
|
* 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
125981
|
* `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
125982
|
*/
|
|
125945
|
-
drop(id3, why2,
|
|
125983
|
+
drop(id3, why2, quiet2 = false) {
|
|
125946
125984
|
const req = this.pending.get(id3);
|
|
125947
125985
|
this.settle(id3);
|
|
125948
125986
|
if (!req?.then) return;
|
|
125949
|
-
if (
|
|
125987
|
+
if (quiet2) this.tell(id3, req.then, why2);
|
|
125950
125988
|
else this.refuseRequest(id3, req.then, why2);
|
|
125951
125989
|
}
|
|
125952
125990
|
/** 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 */
|
|
@@ -133946,16 +133984,16 @@ var ClaudeSession = class {
|
|
|
133946
133984
|
turnInputs() {
|
|
133947
133985
|
return this.ledger.endingInputs;
|
|
133948
133986
|
}
|
|
133949
|
-
sendInput(text3, uuid3 = centraluInputId(), note, origin,
|
|
133987
|
+
sendInput(text3, uuid3 = centraluInputId(), note, origin, quiet2) {
|
|
133950
133988
|
const goal = isGoalCommand(text3);
|
|
133951
133989
|
if (!this.sendGate && !(goal && this.goalCommand === void 0)) {
|
|
133952
|
-
this.deliver(text3, uuid3, !!note, origin,
|
|
133990
|
+
this.deliver(text3, uuid3, !!note, origin, quiet2);
|
|
133953
133991
|
return;
|
|
133954
133992
|
}
|
|
133955
133993
|
const gate = this.sendGate = (this.sendGate ?? this.goalKnown).then(() => {
|
|
133956
133994
|
if (note?.cancelled) return;
|
|
133957
133995
|
if (!this.closed) {
|
|
133958
|
-
this.deliver(text3, uuid3, !!note, origin,
|
|
133996
|
+
this.deliver(text3, uuid3, !!note, origin, quiet2);
|
|
133959
133997
|
return;
|
|
133960
133998
|
}
|
|
133961
133999
|
this.emit(undeliveredError(this.sessionId, 1, "were still queued when the session closed"));
|
|
@@ -133964,8 +134002,8 @@ var ClaudeSession = class {
|
|
|
133964
134002
|
if (this.sendGate === gate) this.sendGate = null;
|
|
133965
134003
|
});
|
|
133966
134004
|
}
|
|
133967
|
-
deliver(text3, uuid3, parentNote, origin,
|
|
133968
|
-
if (
|
|
134005
|
+
deliver(text3, uuid3, parentNote, origin, quiet2) {
|
|
134006
|
+
if (quiet2) {
|
|
133969
134007
|
const input = { text: text3, uuid: uuid3, parentNote, ...origin ? { origin } : {}, quiet: true };
|
|
133970
134008
|
this.quietInputs.set(uuid3, input);
|
|
133971
134009
|
this.queue.push(input);
|
|
@@ -134101,10 +134139,10 @@ var ClaudeSession = class {
|
|
|
134101
134139
|
for (const id3 of ids) if (this.personInputs.delete(id3)) count++;
|
|
134102
134140
|
this.reportUndelivered(count);
|
|
134103
134141
|
for (const id3 of ids) {
|
|
134104
|
-
const
|
|
134105
|
-
if (!
|
|
134142
|
+
const quiet2 = this.quietInputs.get(id3);
|
|
134143
|
+
if (!quiet2) continue;
|
|
134106
134144
|
this.quietInputs.delete(id3);
|
|
134107
|
-
this.deliver(
|
|
134145
|
+
this.deliver(quiet2.text, centraluInputId(), false, quiet2.origin, true);
|
|
134108
134146
|
}
|
|
134109
134147
|
}
|
|
134110
134148
|
}
|
|
@@ -134227,6 +134265,11 @@ var ClaudeAdapter = class _ClaudeAdapter {
|
|
|
134227
134265
|
contextAtRequest = true;
|
|
134228
134266
|
/** `shouldQuery: false` (sdk.d.ts, measured on the Mac 2026-10-20: no turn, merged into the next message) */
|
|
134229
134267
|
quietInput = true;
|
|
134268
|
+
/**
|
|
134269
|
+
* Measured with Claude Code 2.1.296 on a real host swap: about 2 s after the first input, before that input's turn, when the update's stop ended a
|
|
134270
|
+
* background task of the session; a cut turn that ran in the foreground only resumed with none (`ANSWERED`, turn-continue.ts)
|
|
134271
|
+
*/
|
|
134272
|
+
resumeEndsOwnTurn = true;
|
|
134230
134273
|
cacheBilling = "anthropic";
|
|
134231
134274
|
/** What Claude Code offers against what this adapter limits (#270) */
|
|
134232
134275
|
surface = CLAUDE_SURFACE;
|
|
@@ -138660,10 +138703,10 @@ var ProjectRegistry = class {
|
|
|
138660
138703
|
* session still starting included), else the one refusal. `boundary` names what crosses, in the refusal and in the
|
|
138661
138704
|
* log line each crossing writes; `quiet` for a re-read of a crossing already logged. A null caller is the person.
|
|
138662
138705
|
*/
|
|
138663
|
-
trustGate(callerId, projectId, boundary,
|
|
138706
|
+
trustGate(callerId, projectId, boundary, quiet2 = false) {
|
|
138664
138707
|
if (this.projectTrusted(projectId)) return null;
|
|
138665
138708
|
const name = this.projectRow(projectId)?.name ?? projectId;
|
|
138666
|
-
if (callerId && this.host.autoBoundaryOpen(callerId,
|
|
138709
|
+
if (callerId && this.host.autoBoundaryOpen(callerId, quiet2 ? void 0 : `${boundary} (untrusted project "${name}")`)) return null;
|
|
138667
138710
|
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
138711
|
}
|
|
138669
138712
|
/**
|
|
@@ -140609,13 +140652,6 @@ var ChildOwnershipRecords = class {
|
|
|
140609
140652
|
this.db = db;
|
|
140610
140653
|
}
|
|
140611
140654
|
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
140655
|
// ── start_agent requests waiting for the person (#673) — see migration v50 ──
|
|
140620
140656
|
listAgentStartRequests() {
|
|
140621
140657
|
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 +141104,6 @@ var LinkedMachineRecords = class {
|
|
|
141068
141104
|
}
|
|
141069
141105
|
};
|
|
141070
141106
|
|
|
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
141107
|
// packages/agent-host/src/dev-services/store/user-app-adoption.ts
|
|
141178
141108
|
var ADOPTED_USER_APPS_KEY = "apps.adoptedUserApps";
|
|
141179
141109
|
var BUILDERS_KEY = "apps.builders";
|
|
@@ -143618,7 +143548,7 @@ var StepsV65 = class extends MigrationRange {
|
|
|
143618
143548
|
* 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
143549
|
* 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
143550
|
* 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
|
|
143551
|
+
* 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
143552
|
* 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
143553
|
* `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
143554
|
*
|
|
@@ -143639,17 +143569,7 @@ var StepsV65 = class extends MigrationRange {
|
|
|
143639
143569
|
run: () => {
|
|
143640
143570
|
if (this.db.prepare(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'mail_recipients'`).get() === void 0) return;
|
|
143641
143571
|
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
|
-
);
|
|
143572
|
+
endOldHolds(this.db);
|
|
143653
143573
|
}
|
|
143654
143574
|
},
|
|
143655
143575
|
{
|
|
@@ -143706,7 +143626,7 @@ var StepsV65 = class extends MigrationRange {
|
|
|
143706
143626
|
* **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
143627
|
* 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
143628
|
*
|
|
143709
|
-
* The tables stay: the builds from v70 to v73 read them at every start. They go in
|
|
143629
|
+
* 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
143630
|
*/
|
|
143711
143631
|
run: () => this.oneRecordOfOwedWork()
|
|
143712
143632
|
}
|
|
@@ -143785,6 +143705,21 @@ var OldWorkTasks = class {
|
|
|
143785
143705
|
this.row.run({ id: id3, recipient, project: session2.project, dueAt: t.delivered ? this.now : this.now + 2e3, delivered: t.delivered ? this.now : null });
|
|
143786
143706
|
}
|
|
143787
143707
|
};
|
|
143708
|
+
function endOldHolds(db, moved) {
|
|
143709
|
+
db.prepare(
|
|
143710
|
+
`UPDATE mail_recipients SET held = 'dismissed', attempt_at = NULL, last_error = NULL, attempts = 0
|
|
143711
|
+
WHERE held = 'budget'
|
|
143712
|
+
OR (held = 'policy'
|
|
143713
|
+
AND CASE WHEN @moved IS NULL THEN settled = 'legacy' ELSE rowid IN (SELECT value FROM json_each(@moved)) END
|
|
143714
|
+
AND NOT EXISTS (
|
|
143715
|
+
SELECT 1 FROM mail m, sessions s
|
|
143716
|
+
WHERE m.id = mail_recipients.message_id AND m.kind = 'message' AND s.deleted_at IS NULL
|
|
143717
|
+
AND m.sender_project IS NOT NULL
|
|
143718
|
+
AND COALESCE((SELECT p.trusted FROM projects p WHERE p.id = m.sender_project), 0) = 0
|
|
143719
|
+
AND mail_recipients.recipient LIKE 'session:%' AND substr(mail_recipients.recipient, instr(mail_recipients.recipient, '/') + 1) = s.id
|
|
143720
|
+
AND s.project_id IS NOT m.sender_project))`
|
|
143721
|
+
).run({ moved: moved ? JSON.stringify(moved) : null });
|
|
143722
|
+
}
|
|
143788
143723
|
function addresses(host, callerId, sessionId) {
|
|
143789
143724
|
try {
|
|
143790
143725
|
return [sessionAddress(host, callerId), sessionAddress(host, sessionId)];
|
|
@@ -143793,6 +143728,162 @@ function addresses(host, callerId, sessionId) {
|
|
|
143793
143728
|
}
|
|
143794
143729
|
}
|
|
143795
143730
|
|
|
143731
|
+
// packages/agent-host/src/dev-services/store/migrations/v75.ts
|
|
143732
|
+
var StepsV75 = class extends MigrationRange {
|
|
143733
|
+
steps() {
|
|
143734
|
+
return [
|
|
143735
|
+
{
|
|
143736
|
+
to: 75,
|
|
143737
|
+
breaksOlderReaders: true,
|
|
143738
|
+
minReader: 74,
|
|
143739
|
+
/**
|
|
143740
|
+
* 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
|
|
143741
|
+
* tables (`mail_threads`, `mail_messages`, `mail_receipts`) becomes mail once, here. Until this step the host moved it at every start
|
|
143742
|
+
* 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
|
|
143743
|
+
* beside them (`mail_participants`, `mail_blockers`), `report_marks`, `delegated_turns`, `queued_requests` or `sessions.mail_args`.
|
|
143744
|
+
*
|
|
143745
|
+
* 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
|
|
143746
|
+
* an older one waiting), that is not delivered, not read, or a `question` (read and not answered). Each message is copied once under its
|
|
143747
|
+
* own id, its rows settled `legacy` (never awaited), and each old receipt is marked handled, delivered and read. A row to the Assistant in
|
|
143748
|
+
* 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
|
|
143749
|
+
* takes it; a task to a trashed session is settled `gone`. A row the person released is never held again (`releasedTo`). A hold an
|
|
143750
|
+
* earlier build set stays only if today's gate would hold the mail now, as step 72 judged the rows moved before it (`endOldHolds`).
|
|
143751
|
+
* 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
|
|
143752
|
+
* judgement; a `budget` hold, which no delivery sets, ends on whatever row carries it.
|
|
143753
|
+
*
|
|
143754
|
+
* **A frozen copy of the move the host ran (`movePendingThreadMail`) and of what it called, on purpose**: a step runs once on every
|
|
143755
|
+
* 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
|
|
143756
|
+
* 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
|
|
143757
|
+
* session of its own (as step 72 reads a recipient's).
|
|
143758
|
+
*
|
|
143759
|
+
* **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
|
|
143760
|
+
* 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
|
|
143761
|
+
* during a rollback never became a task for work settled since; it no longer names `report_marks`, so those builds are refused instead
|
|
143762
|
+
* (`StoreTooNewError`). The build of v74 (beta.70 to beta.72) writes no mark, and its own move at every start finds each receipt handled:
|
|
143763
|
+
* it opens the store and serves it as before. The tables stay for it, unread by this build, and go in the next step.
|
|
143764
|
+
*/
|
|
143765
|
+
run: () => this.moveThreadMail()
|
|
143766
|
+
}
|
|
143767
|
+
];
|
|
143768
|
+
}
|
|
143769
|
+
/** Step 75: every pending receipt of the thread tables written as mail, and the old receipt marked handled */
|
|
143770
|
+
moveThreadMail() {
|
|
143771
|
+
const has = (table) => this.db.prepare(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`).get(table) !== void 0;
|
|
143772
|
+
if (!["mail_threads", "mail_messages", "mail_receipts", "mail", "mail_recipients", "sessions", "projects"].every(has)) return;
|
|
143773
|
+
const now = Date.now();
|
|
143774
|
+
const pending = this.pendingReceipts(now);
|
|
143775
|
+
if (pending.length === 0) return;
|
|
143776
|
+
const rootOf = this.db.prepare(`SELECT root_id FROM mail WHERE id = ?`);
|
|
143777
|
+
const insertMail = this.db.prepare(
|
|
143778
|
+
`INSERT OR IGNORE INTO mail (id, sender, sender_project, kind, needs_reply, reply_to, root_id, urgent, body, facts, origin, legacy_thread, created_at)
|
|
143779
|
+
VALUES (@id, @sender, @senderProject, @kind, @needsReply, @replyTo, @rootId, @urgent, @body, @facts, @origin, @legacyThread, @createdAt)`
|
|
143780
|
+
);
|
|
143781
|
+
const insertRow = this.db.prepare(
|
|
143782
|
+
`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)
|
|
143783
|
+
VALUES (@messageId, @recipient, @via, @dueAt, @attemptAt, @deliveredAt, @readAt, @held, @attempts, @lastError, @settled, @now)`
|
|
143784
|
+
);
|
|
143785
|
+
const handled = this.db.prepare(
|
|
143786
|
+
`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`
|
|
143787
|
+
);
|
|
143788
|
+
const sessionRow = this.db.prepare(
|
|
143789
|
+
`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 = ?`
|
|
143790
|
+
);
|
|
143791
|
+
const sessionOf = (address) => {
|
|
143792
|
+
const party = parseAddress(address);
|
|
143793
|
+
return party?.kind === "session" ? sessionRow.get(party.sessionId) : void 0;
|
|
143794
|
+
};
|
|
143795
|
+
const releasedTo = /* @__PURE__ */ new Map();
|
|
143796
|
+
for (const p of pending) if (p.held === "released") releasedTo.set(p.id, [...releasedTo.get(p.id) ?? [], p.recipient]);
|
|
143797
|
+
const moved = [];
|
|
143798
|
+
for (const p of pending) {
|
|
143799
|
+
const sender = parseAddress(p.sender);
|
|
143800
|
+
const from = sessionOf(p.sender);
|
|
143801
|
+
const senderProject = sender?.kind === "session" ? (from?.trashed === 0 ? from.project : null) ?? (p.sender === p.t_owner ? p.t_project_id : null) : null;
|
|
143802
|
+
const target = p.reply_to === null ? void 0 : rootOf.get(p.reply_to);
|
|
143803
|
+
const kind = movedKind(p.kind, p.t_origin);
|
|
143804
|
+
const facts = {
|
|
143805
|
+
...movedFacts(p.facts),
|
|
143806
|
+
legacyKind: p.kind,
|
|
143807
|
+
...quiet(sender?.kind ?? "session", p) ? { quiet: true } : {},
|
|
143808
|
+
...p.needs_owner === 1 ? { needsOwner: true } : {},
|
|
143809
|
+
...releasedTo.has(p.id) ? { releasedTo: releasedTo.get(p.id) } : {}
|
|
143810
|
+
};
|
|
143811
|
+
insertMail.run({
|
|
143812
|
+
id: p.id,
|
|
143813
|
+
sender: p.sender,
|
|
143814
|
+
senderProject,
|
|
143815
|
+
kind,
|
|
143816
|
+
needsReply: p.kind === "question" ? 1 : 0,
|
|
143817
|
+
// The order is a thread's own (`seq`), so a reply finds its target moved before it, whatever their times say
|
|
143818
|
+
replyTo: target ? p.reply_to : null,
|
|
143819
|
+
rootId: target?.root_id ?? p.id,
|
|
143820
|
+
urgent: p.urgent === 1 ? 1 : 0,
|
|
143821
|
+
body: p.body,
|
|
143822
|
+
facts: JSON.stringify(facts),
|
|
143823
|
+
origin: p.seq === 1 ? p.t_origin : "mail",
|
|
143824
|
+
legacyThread: p.thread_id,
|
|
143825
|
+
createdAt: p.created_at
|
|
143826
|
+
});
|
|
143827
|
+
const to = sessionOf(p.recipient);
|
|
143828
|
+
const row = insertRow.run({
|
|
143829
|
+
messageId: p.id,
|
|
143830
|
+
recipient: p.recipient,
|
|
143831
|
+
via: p.recipient === p.t_assignee && to?.assistant === 1 && p.t_owner !== p.recipient ? "assistant" : null,
|
|
143832
|
+
dueAt: p.due_at,
|
|
143833
|
+
attemptAt: p.attempt_at,
|
|
143834
|
+
deliveredAt: p.delivered_at,
|
|
143835
|
+
readAt: p.read_at,
|
|
143836
|
+
held: p.held !== null && CARRIED_HOLDS.includes(p.held) ? p.held : null,
|
|
143837
|
+
attempts: p.attempts,
|
|
143838
|
+
lastError: p.last_error,
|
|
143839
|
+
settled: kind === "task" && to?.trashed === 1 ? "gone" : "legacy",
|
|
143840
|
+
now
|
|
143841
|
+
});
|
|
143842
|
+
if (row.changes === 1) moved.push(Number(row.lastInsertRowid));
|
|
143843
|
+
handled.run({ now, id: p.id, recipient: p.recipient });
|
|
143844
|
+
}
|
|
143845
|
+
endOldHolds(this.db, moved);
|
|
143846
|
+
}
|
|
143847
|
+
/** The receipts still pending at `now`, each with its message and what the move reads of its thread, in each thread's own order */
|
|
143848
|
+
pendingReceipts(now) {
|
|
143849
|
+
return this.db.prepare(
|
|
143850
|
+
`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,
|
|
143851
|
+
r.recipient, r.due_at, r.attempt_at, r.delivered_at, r.read_at, r.held, r.attempts, r.last_error,
|
|
143852
|
+
t.project_id AS t_project_id, t.owner AS t_owner, t.assignee AS t_assignee, t.origin AS t_origin
|
|
143853
|
+
FROM mail_receipts r JOIN mail_messages m ON m.id = r.message_id JOIN mail_threads t ON t.id = m.thread_id
|
|
143854
|
+
WHERE r.handled_at IS NULL AND COALESCE(r.held, '') <> 'dismissed' AND m.created_at >= ?
|
|
143855
|
+
AND (r.delivered_at IS NULL OR r.read_at IS NULL OR m.kind = 'question')
|
|
143856
|
+
ORDER BY m.thread_id, m.seq, r.recipient`
|
|
143857
|
+
).all(now - MOVE_WITHIN_MS);
|
|
143858
|
+
}
|
|
143859
|
+
};
|
|
143860
|
+
var MOVE_WITHIN_MS = 180 * 24 * 60 * 60 * 1e3;
|
|
143861
|
+
var CARRIED_HOLDS = ["uncertain", "failed", "loop", "policy", "released", "budget"];
|
|
143862
|
+
var TASK_ORIGINS = ["person", "start_agent", "agent_session", "send_to_session", "create_session", "ask_project"];
|
|
143863
|
+
function movedKind(kind, threadOrigin) {
|
|
143864
|
+
if (kind === "assign" && TASK_ORIGINS.includes(threadOrigin)) return "task";
|
|
143865
|
+
if (kind === "report") return "report";
|
|
143866
|
+
return kind === "notice" || kind === "event" ? "notice" : "message";
|
|
143867
|
+
}
|
|
143868
|
+
function movedFacts(raw) {
|
|
143869
|
+
let value;
|
|
143870
|
+
try {
|
|
143871
|
+
value = JSON.parse(raw);
|
|
143872
|
+
} catch {
|
|
143873
|
+
return {};
|
|
143874
|
+
}
|
|
143875
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
|
|
143876
|
+
const facts = { ...value };
|
|
143877
|
+
if (Array.isArray(facts.waitingOn)) facts.waitingOn = facts.waitingOn.length;
|
|
143878
|
+
return facts;
|
|
143879
|
+
}
|
|
143880
|
+
function quiet(senderKind2, m) {
|
|
143881
|
+
if (m.kind === "event") return true;
|
|
143882
|
+
if (senderKind2 === "centralu") return m.wake === "no";
|
|
143883
|
+
if (senderKind2 !== "app") return false;
|
|
143884
|
+
return m.wake === "no" || m.kind === "notice" && m.needs_owner !== 1 && m.wake !== "yes";
|
|
143885
|
+
}
|
|
143886
|
+
|
|
143796
143887
|
// packages/agent-host/src/dev-services/store/migrations/index.ts
|
|
143797
143888
|
function migrationSteps(host) {
|
|
143798
143889
|
return [
|
|
@@ -143804,7 +143895,8 @@ function migrationSteps(host) {
|
|
|
143804
143895
|
...new StepsV55(host).steps(),
|
|
143805
143896
|
...new StepsV58(host).steps(),
|
|
143806
143897
|
...new StepsV62(host).steps(),
|
|
143807
|
-
...new StepsV65(host).steps()
|
|
143898
|
+
...new StepsV65(host).steps(),
|
|
143899
|
+
...new StepsV75(host).steps()
|
|
143808
143900
|
];
|
|
143809
143901
|
}
|
|
143810
143902
|
|
|
@@ -144458,8 +144550,6 @@ var TrashRecords = class {
|
|
|
144458
144550
|
const host = this.db.prepare(`SELECT value FROM app_settings WHERE key = ?`).get(HUB_SELF_KEY)?.value;
|
|
144459
144551
|
if (host) {
|
|
144460
144552
|
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
144553
|
this.mailbox.purgeParty(address);
|
|
144464
144554
|
}
|
|
144465
144555
|
this.db.prepare(`DELETE FROM mail_turns WHERE session_id = ?`).run(sessionId);
|
|
@@ -144834,21 +144924,6 @@ var Store = class extends MigrationRunner {
|
|
|
144834
144924
|
this.db.pragma(`busy_timeout = ${wait}`);
|
|
144835
144925
|
}
|
|
144836
144926
|
}
|
|
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
144927
|
/** The migration list. `store/migrations/index.ts` holds it, and the rule a new step follows */
|
|
144853
144928
|
migrationSteps() {
|
|
144854
144929
|
return migrationSteps({
|
|
@@ -145454,12 +145529,12 @@ var AskProjectFlow = class {
|
|
|
145454
145529
|
* already logged the `auto` boundary it opens, so this one does not log it again. `trust`: false leaves the project's
|
|
145455
145530
|
* trust out, for the one read that decides it once the target is known (§7.4).
|
|
145456
145531
|
*/
|
|
145457
|
-
askGateError(callerId,
|
|
145532
|
+
askGateError(callerId, quiet2 = false, trust = true) {
|
|
145458
145533
|
const caller = this.host.meta.get(callerId);
|
|
145459
145534
|
if (!caller?.projectId) return "This session belongs to no project, so it cannot ask another one";
|
|
145460
145535
|
const deep = agentDepthRefusal(this.host, callerId, "ask a project");
|
|
145461
145536
|
if (deep) return deep;
|
|
145462
|
-
return trust ? this.host.trustGate(callerId, caller.projectId, "asking another project",
|
|
145537
|
+
return trust ? this.host.trustGate(callerId, caller.projectId, "asking another project", quiet2) : null;
|
|
145463
145538
|
}
|
|
145464
145539
|
/** The project asked is still registered: the person may remove it while its card stands */
|
|
145465
145540
|
projectGoneError(target) {
|
|
@@ -148147,6 +148222,10 @@ var SessionManager = class {
|
|
|
148147
148222
|
},
|
|
148148
148223
|
waitEnded: (id3, cause2, end) => this.mail.mailWaitEnded(id3, cause2, this.meta.get(id3)?.askedBy ?? null, end),
|
|
148149
148224
|
updateStep: (cut3, step, err) => this.tenure.updateStep(cut3, step, err),
|
|
148225
|
+
resumeEndsOwnTurn: (id3) => {
|
|
148226
|
+
const tool = this.meta.get(id3)?.tool;
|
|
148227
|
+
return !!tool && this.adapters.get(tool)?.resumeEndsOwnTurn === true;
|
|
148228
|
+
},
|
|
148150
148229
|
// Through Centralu's channel: sent only while the wait still stands (a Stop or a message of the person's takes it away, even while a restart is waited out)
|
|
148151
148230
|
send: (id3, note, gate) => {
|
|
148152
148231
|
const skipLine = () => !note.line || note.cause === "update" && this.tenure.leavingForUpdate();
|
|
@@ -149739,8 +149818,8 @@ var MessageService = class {
|
|
|
149739
149818
|
const urgent = input.urgent === true;
|
|
149740
149819
|
const senderProject = this.reach.projectOf(sender);
|
|
149741
149820
|
const holds = to.map((r) => this.reach.holdFor({ kind: "message", senderProject }, r));
|
|
149742
|
-
const
|
|
149743
|
-
const facts = { ...clarifies !== void 0 ? { clarifies } : {}, ...
|
|
149821
|
+
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 });
|
|
149822
|
+
const facts = { ...clarifies !== void 0 ? { clarifies } : {}, ...quiet2 ? { quiet: true } : {}, ...cited ? { cites: cited } : {}, ...input.picked && cls === "person" ? { picked: true } : {} };
|
|
149744
149823
|
const stored = this.put(
|
|
149745
149824
|
// The citation's one use: `UNIQUE(sender, dedupe_key)` (`personWord` looked first, in this transaction)
|
|
149746
149825
|
{ ...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 +149832,7 @@ var MessageService = class {
|
|
|
149753
149832
|
if (held3.length === 0) this.records.settle(target.id, sender, "answered", now, stored.id);
|
|
149754
149833
|
else this.answerHeld(target, stored);
|
|
149755
149834
|
}
|
|
149756
|
-
return { message: stored, held: held3, answered: target?.id ?? null, answers: answers2, quiet, asWork, ...cited ? { cited } : {}, ...typeof word === "string" ? { notCited: word } : {} };
|
|
149835
|
+
return { message: stored, held: held3, answered: target?.id ?? null, answers: answers2, quiet: quiet2, asWork, ...cited ? { cited } : {}, ...typeof word === "string" ? { notCited: word } : {} };
|
|
149757
149836
|
});
|
|
149758
149837
|
}
|
|
149759
149838
|
/** A new message id of this host's, for a message another host writes first (#2067 review, `MailAcross.send`) */
|
|
@@ -150028,8 +150107,7 @@ var MessageService = class {
|
|
|
150028
150107
|
relations.add(relation);
|
|
150029
150108
|
items.push(this.frameItem(recipient, message, relation, down && row.deliveredAt === null, row.lastError === "maybe_repeated"));
|
|
150030
150109
|
}
|
|
150031
|
-
const
|
|
150032
|
-
const frame = buildMessageFrame(items, calls);
|
|
150110
|
+
const frame = buildMessageFrame(items, this.opts.calls?.(recipient));
|
|
150033
150111
|
return {
|
|
150034
150112
|
text: frame.text,
|
|
150035
150113
|
messageIds: frame.shown,
|
|
@@ -150581,24 +150659,21 @@ var MailPerson = class {
|
|
|
150581
150659
|
const root3 = this.rootsOf(threadId)[0];
|
|
150582
150660
|
if (root3 === void 0) throw refuse4("unknown_message", `There is no mail ${threadId} kept.`);
|
|
150583
150661
|
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));
|
|
150662
|
+
const lookIn = opts.lookIn === true || !all.some((s) => this.readable(s.m));
|
|
150585
150663
|
let page;
|
|
150586
150664
|
if (opts.after !== void 0) page = all.filter((s) => s.seq > (opts.after ?? 0)).slice(0, opts.all ? void 0 : THREAD_PAGE);
|
|
150587
150665
|
else if (opts.tail !== void 0 || !opts.all) {
|
|
150588
150666
|
const upTo = opts.before === void 0 ? all : all.filter((s) => s.seq < (opts.before ?? 0));
|
|
150589
150667
|
page = upTo.slice(-Math.min(opts.tail ?? THREAD_PAGE, THREAD_PAGE));
|
|
150590
150668
|
} else page = all;
|
|
150591
|
-
this.readFor(page);
|
|
150669
|
+
if (!lookIn) this.readFor(page);
|
|
150592
150670
|
const first = page[0]?.seq;
|
|
150593
150671
|
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
150672
|
return {
|
|
150598
150673
|
thread: this.row(root3, this.heldIn(root3)) ?? this.lookInRow(root3),
|
|
150599
150674
|
parties: this.partiesOf(all.map((s) => s.m)),
|
|
150600
150675
|
blockers: [],
|
|
150601
|
-
messages:
|
|
150676
|
+
messages: page.map((s) => this.message(s)),
|
|
150602
150677
|
more: last !== void 0 && all.some((s) => s.seq > last),
|
|
150603
150678
|
older: first !== void 0 && all.some((s) => s.seq < first),
|
|
150604
150679
|
follows: [],
|
|
@@ -150834,17 +150909,6 @@ var MailPerson = class {
|
|
|
150834
150909
|
if (m.sender === PERSON) return true;
|
|
150835
150910
|
return this.records.recipients(m.id).some((r) => r.recipient === PERSON || isPersonHold(r.held));
|
|
150836
150911
|
}
|
|
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
150912
|
heldIn(root3) {
|
|
150849
150913
|
return this.records.heldRows().filter((r) => this.records.message(r.messageId)?.rootId === root3).length;
|
|
150850
150914
|
}
|
|
@@ -151013,9 +151077,6 @@ function taskState(m, r, on2) {
|
|
|
151013
151077
|
function hasTask(m, r) {
|
|
151014
151078
|
return m.kind === "task" && parseAddress(r.recipient)?.kind === "session" && r.settled === null && r.releasedAt === null;
|
|
151015
151079
|
}
|
|
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
151080
|
function isPersonHold(held3) {
|
|
151020
151081
|
return PERSON_HOLDS.some((h) => h === held3);
|
|
151021
151082
|
}
|
|
@@ -151563,7 +151624,7 @@ var MailTool = class {
|
|
|
151563
151624
|
try {
|
|
151564
151625
|
const me2 = this.host.caller(sessionId);
|
|
151565
151626
|
if (!me2) throw refuse4("gone", "this session is not here");
|
|
151566
|
-
return { text: this.dispatch(sessionId, me2, args, mailCalls(
|
|
151627
|
+
return { text: this.dispatch(sessionId, me2, args, mailCalls(this.host.form(sessionId))) };
|
|
151567
151628
|
} catch (e) {
|
|
151568
151629
|
return failed4(e);
|
|
151569
151630
|
}
|
|
@@ -151581,7 +151642,7 @@ var MailTool = class {
|
|
|
151581
151642
|
const pr = args.action === "watch" ? prNumberOf(args.to ?? "") : null;
|
|
151582
151643
|
if (pr !== null) {
|
|
151583
151644
|
const watches = this.watchArgs(args);
|
|
151584
|
-
return { text: await watches.registerPr(me2.address, pr, args.text?.trim() ?? "", (id3) => mailCalls(
|
|
151645
|
+
return { text: await watches.registerPr(me2.address, pr, args.text?.trim() ?? "", (id3) => mailCalls(this.host.form(sessionId)).close(id3), signal) };
|
|
151585
151646
|
}
|
|
151586
151647
|
if (args.action === "find") {
|
|
151587
151648
|
if (!across) return { text: "Finding sessions is not available here.", isError: true };
|
|
@@ -151841,25 +151902,11 @@ var MailTool = class {
|
|
|
151841
151902
|
const chain = id3 === void 0 ? v.items : v.items.slice(0, -1);
|
|
151842
151903
|
if (base2 && chain.length > 0) out.push("Earlier in this chain:");
|
|
151843
151904
|
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
|
-
}
|
|
151905
|
+
if (base2) out.push(this.shown(me2, base2));
|
|
151849
151906
|
if (v.older) out.push(`Older messages in this chain: ${calls.read(v.older)}.`);
|
|
151850
151907
|
if (id3 === void 0 && v.items.length > 0) out.push(`There may be more: ${calls.read()}.`);
|
|
151851
151908
|
return out.join("\n");
|
|
151852
151909
|
}
|
|
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
151910
|
/** One message under Centralu's header (S5); a phantom is one line without words */
|
|
151864
151911
|
shown(me2, i) {
|
|
151865
151912
|
const m = i.message;
|
|
@@ -152004,6 +152051,10 @@ var AcrossCore = class {
|
|
|
152004
152051
|
*/
|
|
152005
152052
|
unsure = /* @__PURE__ */ new Map();
|
|
152006
152053
|
now;
|
|
152054
|
+
/** 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) */
|
|
152055
|
+
get hostId() {
|
|
152056
|
+
return this.d.hostId;
|
|
152057
|
+
}
|
|
152007
152058
|
// ── Addresses ──
|
|
152008
152059
|
route(address) {
|
|
152009
152060
|
const p = parseAddress(address);
|
|
@@ -152044,10 +152095,8 @@ var AcrossCore = class {
|
|
|
152044
152095
|
}
|
|
152045
152096
|
/** On a machine, its own session as the hub `hubId` names it */
|
|
152046
152097
|
asHubNames(hubId, address) {
|
|
152047
|
-
if (address === sessionAddress(hubId, PERSON_ID)) return PERSON;
|
|
152048
152098
|
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;
|
|
152099
|
+
return inHubTerms(address, hubId, you ? { host: this.d.hostId, id: you } : void 0);
|
|
152051
152100
|
}
|
|
152052
152101
|
/** On a machine, an address as the hub `hubId` names it, as this host names it (its own sessions are its own again) */
|
|
152053
152102
|
fromHubNames(hubId, address) {
|
|
@@ -152467,7 +152516,15 @@ function mayReachAcross(_from, _to) {
|
|
|
152467
152516
|
var FOREIGN_ID = /^[^\s/]{1,120}\.m_[0-9A-Za-z]{10,40}$/;
|
|
152468
152517
|
var FIND_MS = 4e3;
|
|
152469
152518
|
var NAMED_HERE_MS = 600;
|
|
152519
|
+
var OPEN_ASKED = 500;
|
|
152520
|
+
var ASKED_WITHIN = MAILBOX_RETENTION.settledMs - 24 * 60 * 60 * 1e3;
|
|
152521
|
+
var LACKED_MAX = 5e3;
|
|
152522
|
+
var NAMED_MAX = 10;
|
|
152470
152523
|
var MailAcross = class extends AcrossReceipts {
|
|
152524
|
+
/** On a hub: tasks whose `host.mail` is under way now, which an offer neither asks about nor deletes */
|
|
152525
|
+
sending = /* @__PURE__ */ new Set();
|
|
152526
|
+
/** 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` */
|
|
152527
|
+
lacked = /* @__PURE__ */ new Map();
|
|
152471
152528
|
// ── Sending from here ──
|
|
152472
152529
|
/**
|
|
152473
152530
|
* A session's message to a session on another host (`to`: an address, or `parent` for a session a hub started here).
|
|
@@ -152513,7 +152570,8 @@ var MailAcross = class extends AcrossReceipts {
|
|
|
152513
152570
|
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
152571
|
}
|
|
152515
152572
|
}
|
|
152516
|
-
|
|
152573
|
+
this.sending.add(id3);
|
|
152574
|
+
const r = this.settle(id3, await this.ask(m, "host.mail", params).finally(() => this.sending.delete(id3)));
|
|
152517
152575
|
if (!r.ok) {
|
|
152518
152576
|
if (!r.maybe) this.d.records.deleteRows([{ messageId: id3, recipient: to }]);
|
|
152519
152577
|
return { ok: false, why: r.why, text: r.text };
|
|
@@ -152521,6 +152579,52 @@ var MailAcross = class extends AcrossReceipts {
|
|
|
152521
152579
|
this.names.set(to, `${r.to} on ${m.name}`);
|
|
152522
152580
|
return { ok: true, messageId: id3, to: r.to, address: to, computer: m.name };
|
|
152523
152581
|
}
|
|
152582
|
+
/**
|
|
152583
|
+
* 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
|
|
152584
|
+
* about (`HubOffer.open`)
|
|
152585
|
+
*/
|
|
152586
|
+
openTasksTo(machineId) {
|
|
152587
|
+
const since = this.now() - ASKED_WITHIN;
|
|
152588
|
+
return this.d.records.openTasksToward(sessionAddress(this.d.hostId, `${machineId}.`), since, OPEN_ASKED).filter((id3) => !this.sending.has(id3));
|
|
152589
|
+
}
|
|
152590
|
+
/**
|
|
152591
|
+
* 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
|
|
152592
|
+
* 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
|
|
152593
|
+
* 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`)
|
|
152594
|
+
*/
|
|
152595
|
+
offerAnswered(machineId, lacks) {
|
|
152596
|
+
const lost = /* @__PURE__ */ new Map();
|
|
152597
|
+
for (const id3 of lacks) {
|
|
152598
|
+
const m = this.sending.has(id3) ? void 0 : this.d.records.message(id3);
|
|
152599
|
+
const row = m?.kind === "task" ? this.d.records.recipients(id3)[0] : void 0;
|
|
152600
|
+
const r = row && this.route(row.recipient);
|
|
152601
|
+
if (!m || !row || r?.kind !== "machine" || r.machineId !== machineId || row.settled !== null || row.releasedAt !== null) continue;
|
|
152602
|
+
const name = this.foreignName(row.recipient)?.name ?? row.recipient;
|
|
152603
|
+
this.d.records.deleteRows([{ messageId: id3, recipient: row.recipient }]);
|
|
152604
|
+
this.unsure.delete(id3);
|
|
152605
|
+
lost.set(m.sender, [...lost.get(m.sender) ?? [], { id: id3, name: oneLineText(name, 200) }]);
|
|
152606
|
+
this.d.log?.(`[mail] ${id3} never reached ${r.machineId}: its copy is deleted, and its sender told`);
|
|
152607
|
+
}
|
|
152608
|
+
for (const [sender, tasks] of lost) this.d.service.notice(sender, notArrived(tasks));
|
|
152609
|
+
this.changed();
|
|
152610
|
+
}
|
|
152611
|
+
/**
|
|
152612
|
+
* 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
|
|
152613
|
+
* 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
|
|
152614
|
+
* 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
|
|
152615
|
+
* no connection outlives this process: after a restart nothing sent before it can arrive
|
|
152616
|
+
*/
|
|
152617
|
+
lacking(hubId, ids) {
|
|
152618
|
+
const lacks = ids.filter((id3) => id3.startsWith(`${hubId}.`) && !id3.startsWith(`${this.d.hostId}.`) && FOREIGN_ID.test(id3) && !this.d.records.message(id3));
|
|
152619
|
+
const lacked = this.lacked.get(hubId) ?? /* @__PURE__ */ new Set();
|
|
152620
|
+
for (const id3 of lacks) lacked.add(id3);
|
|
152621
|
+
for (const old of lacked) {
|
|
152622
|
+
if (lacked.size <= LACKED_MAX) break;
|
|
152623
|
+
lacked.delete(old);
|
|
152624
|
+
}
|
|
152625
|
+
if (lacked.size) this.lacked.set(hubId, lacked);
|
|
152626
|
+
return lacks;
|
|
152627
|
+
}
|
|
152524
152628
|
/** 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
152629
|
taskRefusal(to) {
|
|
152526
152630
|
const there = this.taskPeer(to);
|
|
@@ -152695,6 +152799,7 @@ var MailAcross = class extends AcrossReceipts {
|
|
|
152695
152799
|
const role = this.d.ownEntries().find((e) => e.address === to)?.role;
|
|
152696
152800
|
if (role === "assistant" || role === "coordinator") return { ok: false, why: "not_allowed", text: `Not a session this machine shares: ${this.label(to)}` };
|
|
152697
152801
|
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." };
|
|
152802
|
+
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
152803
|
const had = this.d.records.message(p.id);
|
|
152699
152804
|
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
152805
|
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 +152953,13 @@ function pick4(p) {
|
|
|
152848
152953
|
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
152954
|
}
|
|
152850
152955
|
var noAnswer = (ms3) => `no answer within ${durationText(ms3)}`;
|
|
152956
|
+
function notArrived(tasks) {
|
|
152957
|
+
const ids = tasks.map((t) => t.id);
|
|
152958
|
+
const named3 = tasks.slice(0, NAMED_MAX).map((t) => `${t.id} to ${t.name}`);
|
|
152959
|
+
const more = tasks.length > NAMED_MAX ? `, and ${tasks.length - NAMED_MAX} more` : "";
|
|
152960
|
+
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.`;
|
|
152961
|
+
return { body, facts: { notArrived: { messages: ids } }, dedupeKey: `not-arrived:${ids[0]}` };
|
|
152962
|
+
}
|
|
152851
152963
|
|
|
152852
152964
|
// packages/agent-host/src/mail/turns.ts
|
|
152853
152965
|
var STARTED_BY = ["mail", "person", "caller", "cli", "report", "app"];
|
|
@@ -153068,7 +153180,7 @@ function hostMail(store2, sessions, opts) {
|
|
|
153068
153180
|
},
|
|
153069
153181
|
calls: (address) => {
|
|
153070
153182
|
const party = parseAddress(address);
|
|
153071
|
-
return mailCalls(
|
|
153183
|
+
return mailCalls(party?.kind === "session" && sessions.mailCommand(party.sessionId) ? "command" : "plain");
|
|
153072
153184
|
},
|
|
153073
153185
|
personSaid: (sessionId) => store2.messages.newestPersonMessage(sessionId),
|
|
153074
153186
|
standing: (address) => {
|
|
@@ -153189,7 +153301,6 @@ function hostMail(store2, sessions, opts) {
|
|
|
153189
153301
|
sessions: () => sessions.listSessions().map((s) => ({ id: s.id, name: s.name, project: s.projectId ?? null, state: s.state })),
|
|
153190
153302
|
form: (id3) => sessions.mailCommand(id3) ? "command" : "plain",
|
|
153191
153303
|
askerOf: (id3) => askerFacts(askedByHost, id3),
|
|
153192
|
-
legacyChain: (threadId, messageId, reader) => store2.legacyChainFor(threadId, messageId, reader, 9),
|
|
153193
153304
|
across,
|
|
153194
153305
|
watches,
|
|
153195
153306
|
...sessions.work ? { work: sessions.work } : {}
|
|
@@ -153309,16 +153420,6 @@ function hostMail(store2, sessions, opts) {
|
|
|
153309
153420
|
} catch (e) {
|
|
153310
153421
|
console.error(`[mail] taking back the notices of ended cards failed: ${errorMessage(e)}`);
|
|
153311
153422
|
}
|
|
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
153423
|
try {
|
|
153323
153424
|
const open6 = new Map(store2.mailbox.openTurns().map((t) => [t.sessionId, t.turnSeq]));
|
|
153324
153425
|
const stops = sessions.listSessions().flatMap((s) => {
|
|
@@ -153331,11 +153432,6 @@ function hostMail(store2, sessions, opts) {
|
|
|
153331
153432
|
} catch (e) {
|
|
153332
153433
|
console.error(`[mail] telling the senders of the turns the last host's end cut failed: ${errorMessage(e)}`);
|
|
153333
153434
|
}
|
|
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
153435
|
delivery.start();
|
|
153340
153436
|
for (const s of sessions.listSessions()) sessions.settleAtRest?.(s.id);
|
|
153341
153437
|
}
|
|
@@ -153419,6 +153515,355 @@ function watched(records, changed) {
|
|
|
153419
153515
|
});
|
|
153420
153516
|
}
|
|
153421
153517
|
|
|
153518
|
+
// packages/agent-host/src/links/qualifier.ts
|
|
153519
|
+
var onMachine2 = (name, machine) => `${name} on ${machine}`;
|
|
153520
|
+
var CrossMachineError = class extends Error {
|
|
153521
|
+
code = "internal";
|
|
153522
|
+
constructor(what, machine) {
|
|
153523
|
+
super(`${what} belongs to another machine than ${machine}; one call reaches one machine`);
|
|
153524
|
+
}
|
|
153525
|
+
};
|
|
153526
|
+
var Qualifier = class {
|
|
153527
|
+
constructor(machine, slot, ownerOf) {
|
|
153528
|
+
this.machine = machine;
|
|
153529
|
+
this.slot = slot;
|
|
153530
|
+
this.ownerOf = ownerOf;
|
|
153531
|
+
}
|
|
153532
|
+
machine;
|
|
153533
|
+
slot;
|
|
153534
|
+
ownerOf;
|
|
153535
|
+
prefix = () => `${this.machine}.`;
|
|
153536
|
+
/** Set once the machine answered this connection's offer (`LinkedMachineConnection.offerAsks`); null until then, and for a hub with no mail */
|
|
153537
|
+
mail = null;
|
|
153538
|
+
/**
|
|
153539
|
+
* This machine's approval cards the hub could not read (#844), by the machine's own session id and the request id.
|
|
153540
|
+
* The hub's windows show such a card as a fallback with allow and deny only, but a window from before #844 still
|
|
153541
|
+
* offers "always", and the machine would keep it for a kind it knows (a project consent, an agent start). So the hub
|
|
153542
|
+
* refuses "always" for these (`LinkedMachine.call`): nobody can grant for good what was never shown in full here.
|
|
153543
|
+
* Seen on the card's event and on a session row that carries it; an answered card leaves.
|
|
153544
|
+
*/
|
|
153545
|
+
unread = /* @__PURE__ */ new Set();
|
|
153546
|
+
noteCard(sessionId, requestId, detail) {
|
|
153547
|
+
if (typeof sessionId !== "string" || typeof requestId !== "string") return;
|
|
153548
|
+
if (isUnknownCard(ApprovalDetail.parse(detail))) this.unread.add(`${sessionId}\0${requestId}`);
|
|
153549
|
+
}
|
|
153550
|
+
/** Whether the hub read this card of the machine (in the machine's own ids) as a fallback */
|
|
153551
|
+
unreadCard(sessionId, requestId) {
|
|
153552
|
+
return typeof sessionId === "string" && typeof requestId === "string" && this.unread.has(`${sessionId}\0${requestId}`);
|
|
153553
|
+
}
|
|
153554
|
+
/** An id of this machine as the hub's UI sees it */
|
|
153555
|
+
id(value) {
|
|
153556
|
+
return qualify(this.machine, value);
|
|
153557
|
+
}
|
|
153558
|
+
/** The same for a value that may be absent or null, which stays so */
|
|
153559
|
+
maybeId(value) {
|
|
153560
|
+
return typeof value === "string" ? this.id(value) : value;
|
|
153561
|
+
}
|
|
153562
|
+
/** Whether a hub-side id names this machine */
|
|
153563
|
+
owns(value) {
|
|
153564
|
+
return typeof value === "string" && value.startsWith(this.prefix());
|
|
153565
|
+
}
|
|
153566
|
+
/** A hub-side id back to the remote's own. Refuses an id of another machine */
|
|
153567
|
+
strip(value, what) {
|
|
153568
|
+
if (typeof value !== "string" || !this.owns(value)) throw new CrossMachineError(what, this.machine);
|
|
153569
|
+
return value.slice(this.prefix().length);
|
|
153570
|
+
}
|
|
153571
|
+
/** The same for a value that may be null or absent, which stays so */
|
|
153572
|
+
stripMaybe(value, what) {
|
|
153573
|
+
return value === null || value === void 0 ? value : this.strip(value, what);
|
|
153574
|
+
}
|
|
153575
|
+
// ── Results ─────────────────────────────────────────────────────────────────────────────
|
|
153576
|
+
/** `SessionInfo` (and `UpdateSettingsResult`, which extends it) */
|
|
153577
|
+
session(s) {
|
|
153578
|
+
if (!isObj(s)) return s;
|
|
153579
|
+
if (isObj(s.pendingApproval)) this.noteCard(s.id, s.pendingApproval.requestId, s.pendingApproval.detail);
|
|
153580
|
+
const id3 = this.maybeId(s.id);
|
|
153581
|
+
const owner = typeof id3 === "string" ? this.ownerOf?.(id3) : void 0;
|
|
153582
|
+
return {
|
|
153583
|
+
...s,
|
|
153584
|
+
id: id3,
|
|
153585
|
+
projectId: this.maybeId(s.projectId),
|
|
153586
|
+
parentSessionId: this.maybeId(s.parentSessionId),
|
|
153587
|
+
...owner ? { askedBy: owner } : "askedBy" in s ? { askedBy: this.maybeId(s.askedBy) } : {},
|
|
153588
|
+
scopeSessionIds: Array.isArray(s.scopeSessionIds) ? s.scopeSessionIds.map((x) => this.maybeId(x)) : s.scopeSessionIds,
|
|
153589
|
+
machine: this.machine
|
|
153590
|
+
};
|
|
153591
|
+
}
|
|
153592
|
+
sessions(list2) {
|
|
153593
|
+
return Array.isArray(list2) ? list2.map((s) => this.session(s)) : list2;
|
|
153594
|
+
}
|
|
153595
|
+
/** `{ session, resumed, reason?, ... }` from restart, resume and fork */
|
|
153596
|
+
sessionResult(r) {
|
|
153597
|
+
return isObj(r) ? { ...r, session: this.session(r.session) } : r;
|
|
153598
|
+
}
|
|
153599
|
+
/** `ProjectInfo` */
|
|
153600
|
+
project(p) {
|
|
153601
|
+
if (!isObj(p)) return p;
|
|
153602
|
+
const manager = p.worktreeManager;
|
|
153603
|
+
return {
|
|
153604
|
+
...p,
|
|
153605
|
+
id: this.maybeId(p.id),
|
|
153606
|
+
worktreeManager: isObj(manager) ? { ...manager, sessionId: this.maybeId(manager.sessionId) } : manager,
|
|
153607
|
+
machine: this.machine
|
|
153608
|
+
};
|
|
153609
|
+
}
|
|
153610
|
+
projects(list2) {
|
|
153611
|
+
return Array.isArray(list2) ? list2.map((p) => this.project(p)) : list2;
|
|
153612
|
+
}
|
|
153613
|
+
/** `TerminalInfo` */
|
|
153614
|
+
terminal(t) {
|
|
153615
|
+
return isObj(t) ? { ...t, terminalId: this.maybeId(t.terminalId) } : t;
|
|
153616
|
+
}
|
|
153617
|
+
/** `CommandRunInfo` — its run id rides the terminal frame lane in place of a terminal id */
|
|
153618
|
+
run(r) {
|
|
153619
|
+
return isObj(r) ? { ...r, runId: this.maybeId(r.runId) } : r;
|
|
153620
|
+
}
|
|
153621
|
+
/** `StoredMessage`: its session, and the ids its payload names (#371's asked-by line, a handoff, an app's text) */
|
|
153622
|
+
message(m) {
|
|
153623
|
+
if (!isObj(m)) return m;
|
|
153624
|
+
return { ...m, sessionId: this.maybeId(m.sessionId), payload: this.payload(m.payload) };
|
|
153625
|
+
}
|
|
153626
|
+
messages(list2) {
|
|
153627
|
+
return Array.isArray(list2) ? list2.map((m) => this.message(m)) : list2;
|
|
153628
|
+
}
|
|
153629
|
+
payload(p) {
|
|
153630
|
+
if (!isObj(p)) return p;
|
|
153631
|
+
const out = { ...p };
|
|
153632
|
+
if (typeof p.sessionId === "string") out.sessionId = this.id(p.sessionId);
|
|
153633
|
+
if (isObj(p.from) && typeof p.from.sessionId === "string") out.from = { ...p.from, sessionId: this.id(p.from.sessionId) };
|
|
153634
|
+
if (typeof p.fromSessionId === "string") out.fromSessionId = this.id(p.fromSessionId);
|
|
153635
|
+
if (isObj(p.fromApp)) out.fromApp = { ...p.fromApp, projectId: this.maybeId(p.fromApp.projectId) };
|
|
153636
|
+
if ("projectId" in p) out.projectId = this.maybeId(p.projectId);
|
|
153637
|
+
if (typeof p.instanceId === "string") out.instanceId = this.id(p.instanceId);
|
|
153638
|
+
if (isObj(p.detail)) out.detail = this.approvalDetail(p.detail);
|
|
153639
|
+
return out;
|
|
153640
|
+
}
|
|
153641
|
+
/** `ApprovalDetail`: the kinds that name a project */
|
|
153642
|
+
approvalDetail(d2) {
|
|
153643
|
+
if (!isObj(d2)) return d2;
|
|
153644
|
+
if (d2.kind === "capability" && isObj(d2.app)) return { ...d2, app: { ...d2.app, projectId: this.maybeId(d2.app.projectId) } };
|
|
153645
|
+
if (d2.kind === "project_access") {
|
|
153646
|
+
const side = (x) => isObj(x) ? { ...x, id: this.maybeId(x.id) } : x;
|
|
153647
|
+
return { ...d2, from: side(d2.from), to: side(d2.to) };
|
|
153648
|
+
}
|
|
153649
|
+
if (d2.kind === "agent_start" && isObj(d2.project)) return { ...d2, project: { ...d2.project, id: this.maybeId(d2.project.id) } };
|
|
153650
|
+
return d2;
|
|
153651
|
+
}
|
|
153652
|
+
/** `TrashedSession` */
|
|
153653
|
+
trashed(t) {
|
|
153654
|
+
if (!isObj(t)) return t;
|
|
153655
|
+
return {
|
|
153656
|
+
...t,
|
|
153657
|
+
id: this.maybeId(t.id),
|
|
153658
|
+
project: isObj(t.project) ? { ...t.project, id: this.maybeId(t.project.id) } : t.project,
|
|
153659
|
+
machine: this.machine
|
|
153660
|
+
};
|
|
153661
|
+
}
|
|
153662
|
+
/** `TrashedRun` (#378): its app's project is this machine's, and the record is read and deleted here */
|
|
153663
|
+
trashedRun(t) {
|
|
153664
|
+
if (!isObj(t)) return t;
|
|
153665
|
+
return { ...t, app: isObj(t.app) ? { ...t.app, projectId: this.maybeId(t.app.projectId) } : t.app, machine: this.machine };
|
|
153666
|
+
}
|
|
153667
|
+
/** `SubagentStepsHeld` and `TrashedSubagentSteps` (#418) */
|
|
153668
|
+
subagentSteps(t) {
|
|
153669
|
+
if (!isObj(t)) return t;
|
|
153670
|
+
return {
|
|
153671
|
+
...t,
|
|
153672
|
+
sessionId: this.maybeId(t.sessionId),
|
|
153673
|
+
project: isObj(t.project) ? { ...t.project, id: this.maybeId(t.project.id) } : t.project,
|
|
153674
|
+
machine: this.machine
|
|
153675
|
+
};
|
|
153676
|
+
}
|
|
153677
|
+
/** `ExternalAppInfo`: a project app is that project's; a user-folder app says which machine's folder */
|
|
153678
|
+
app(a) {
|
|
153679
|
+
return isObj(a) ? { ...a, projectId: this.maybeId(a.projectId), machine: this.machine } : a;
|
|
153680
|
+
}
|
|
153681
|
+
/** `ProjectConsent` */
|
|
153682
|
+
consent(c) {
|
|
153683
|
+
return isObj(c) ? { ...c, fromProjectId: this.maybeId(c.fromProjectId), toProjectId: this.maybeId(c.toProjectId), machine: this.machine } : c;
|
|
153684
|
+
}
|
|
153685
|
+
/** One `approvals.rules` row: its numeric id folded (`encodeNumber`), its owner qualified */
|
|
153686
|
+
rule(r, encode3) {
|
|
153687
|
+
if (!isObj(r)) return r;
|
|
153688
|
+
return {
|
|
153689
|
+
...r,
|
|
153690
|
+
id: typeof r.id === "number" ? encode3(r.id) : r.id,
|
|
153691
|
+
projectId: this.maybeId(r.projectId),
|
|
153692
|
+
sessionId: this.maybeId(r.sessionId),
|
|
153693
|
+
machine: this.machine
|
|
153694
|
+
};
|
|
153695
|
+
}
|
|
153696
|
+
/** `messages.search` hits */
|
|
153697
|
+
hits(list2) {
|
|
153698
|
+
return Array.isArray(list2) ? list2.map((h) => isObj(h) ? { ...h, sessionId: this.maybeId(h.sessionId) } : h) : list2;
|
|
153699
|
+
}
|
|
153700
|
+
/**
|
|
153701
|
+
* `apps.inlineViews` rows and the `apps.inlineReopen` answer. The view instance is qualified like any id: the window
|
|
153702
|
+
* hands it back to open, call and close the view, and the hub routes those by it (plan §11)
|
|
153703
|
+
*/
|
|
153704
|
+
inlineView(v) {
|
|
153705
|
+
return isObj(v) ? { ...v, projectId: this.maybeId(v.projectId), instanceId: this.maybeId(v.instanceId) } : v;
|
|
153706
|
+
}
|
|
153707
|
+
/** 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) */
|
|
153708
|
+
appRun(r) {
|
|
153709
|
+
return isObj(r) ? { ...r, projectId: this.maybeId(r.projectId), callerSessionId: this.maybeId(r.callerSessionId), sessionId: this.maybeId(r.sessionId) } : r;
|
|
153710
|
+
}
|
|
153711
|
+
/**
|
|
153712
|
+
* The `agents.listExternalSessions` answer. `externalId` is the tool's own id for the conversation, so it stays as it is;
|
|
153713
|
+
* `importedAs` is the id of the Centralu session already open for it, which the window focuses (#701)
|
|
153714
|
+
*/
|
|
153715
|
+
externalSessions(r) {
|
|
153716
|
+
if (!isObj(r) || !Array.isArray(r.sessions)) return r;
|
|
153717
|
+
return { ...r, sessions: r.sessions.map((s) => isObj(s) ? { ...s, importedAs: this.maybeId(s.importedAs) } : s) };
|
|
153718
|
+
}
|
|
153719
|
+
/**
|
|
153720
|
+
* The `apps.errors` answer: the app a declined request named is compared with the app on screen, whose project is
|
|
153721
|
+
* qualified, to decide which of the two wordings applies. `runId` is a run's own id and stays as `apps.runs` leaves it
|
|
153722
|
+
*/
|
|
153723
|
+
errorBundles(r) {
|
|
153724
|
+
if (!isObj(r)) return r;
|
|
153725
|
+
const bundle = (b2) => isObj(b2) && isObj(b2.denied) ? { ...b2, denied: { ...b2.denied, projectId: this.maybeId(b2.denied.projectId) } } : b2;
|
|
153726
|
+
return { ...r, latest: bundle(r.latest), recent: Array.isArray(r.recent) ? r.recent.map(bundle) : r.recent };
|
|
153727
|
+
}
|
|
153728
|
+
/** The `apps.openView` answer: the pinned view's instance */
|
|
153729
|
+
openedView(v) {
|
|
153730
|
+
return isObj(v) ? { ...v, instanceId: this.maybeId(v.instanceId) } : v;
|
|
153731
|
+
}
|
|
153732
|
+
/** The `apps.viewDocument` answer: the app it names (a user-folder app's null project stays null) */
|
|
153733
|
+
viewDocument(d2) {
|
|
153734
|
+
return isObj(d2) ? { ...d2, projectId: this.maybeId(d2.projectId) } : d2;
|
|
153735
|
+
}
|
|
153736
|
+
/**
|
|
153737
|
+
* A `MailParty` of this machine's mail in the hub's terms (#2268, `inHubTerms`): its own session is `session:<hub>/<machine>.<id>`, named
|
|
153738
|
+
* `<name> on <machine>`; the hub's person is `person`; its own app's project is qualified. The hub's side, `person` and `centralu` stay
|
|
153739
|
+
*/
|
|
153740
|
+
mailParty(p) {
|
|
153741
|
+
const t = this.mail;
|
|
153742
|
+
if (!isObj(p) || typeof p.address !== "string" || !t) return p;
|
|
153743
|
+
const address = inHubTerms(p.address, t.hub, t.own === null ? void 0 : { host: t.own, id: this.machine });
|
|
153744
|
+
if (address === PERSON) return { ...p, address, kind: "person", sessionId: null, name: null, state: null };
|
|
153745
|
+
const named3 = parseAddress(address);
|
|
153746
|
+
if (address !== p.address && named3?.kind === "session") {
|
|
153747
|
+
return { ...p, address, sessionId: named3.sessionId, name: typeof p.name === "string" ? onMachine2(p.name, t.computer()) : p.name };
|
|
153748
|
+
}
|
|
153749
|
+
const app2 = parseAddress(p.address);
|
|
153750
|
+
return app2?.kind === "app" && app2.host === t.own ? { ...p, address: appAddress(t.hub, this.id(app2.projectId), app2.appId) } : p;
|
|
153751
|
+
}
|
|
153752
|
+
/** 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 */
|
|
153753
|
+
taskRow(t) {
|
|
153754
|
+
return isObj(t) ? { ...t, root: this.maybeId(t.root), owner: this.mailParty(t.owner), assignee: this.mailParty(t.assignee) } : t;
|
|
153755
|
+
}
|
|
153756
|
+
/**
|
|
153757
|
+
* 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
|
|
153758
|
+
* 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
|
|
153759
|
+
* answered, closed nor released here, and would stand in the hub's Needs you as the hub's person's own
|
|
153760
|
+
*/
|
|
153761
|
+
taskRows(rows3) {
|
|
153762
|
+
const own = (p) => isObj(p) && p.address === PERSON;
|
|
153763
|
+
return (Array.isArray(rows3) ? rows3 : []).flatMap((t) => isObj(t) && (own(t.owner) || own(t.assignee) || t.state === "held") ? [] : [this.taskRow(t)]);
|
|
153764
|
+
}
|
|
153765
|
+
/** 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 */
|
|
153766
|
+
mailThread(v) {
|
|
153767
|
+
if (!isObj(v)) return v;
|
|
153768
|
+
const party = (x) => this.mailParty(x);
|
|
153769
|
+
const sent = (x) => isObj(x) ? { ...x, sender: party(x.sender) } : x;
|
|
153770
|
+
const list2 = (x, f) => Array.isArray(x) ? x.map((y) => isObj(y) ? f(y) : y) : x;
|
|
153771
|
+
const t = v.thread;
|
|
153772
|
+
return {
|
|
153773
|
+
...v,
|
|
153774
|
+
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,
|
|
153775
|
+
parties: list2(v.parties, (x) => ({ ...x, party: party(x.party) })),
|
|
153776
|
+
messages: list2(v.messages, (m) => ({ ...m, sender: party(m.sender), ..."receipts" in m ? { receipts: list2(m.receipts, (r) => ({ ...r, recipient: party(r.recipient) })) } : {} })),
|
|
153777
|
+
follows: list2(v.follows, (f) => ({ ...f, id: this.maybeId(f.id) }))
|
|
153778
|
+
};
|
|
153779
|
+
}
|
|
153780
|
+
// ── Events ──────────────────────────────────────────────────────────────────────────────
|
|
153781
|
+
/**
|
|
153782
|
+
* One event of this machine in the hub's terms, or null for one the hub does not pass on.
|
|
153783
|
+
*
|
|
153784
|
+
* Dropped: what is about the remote host itself rather than its sessions and projects. The hub
|
|
153785
|
+
* has its own update, themes, preferences, agent CLIs and screen questions (and a host of v0.1.0-beta.10 or
|
|
153786
|
+
* before still sends `app_state_changed` for its control app), and an app-wide
|
|
153787
|
+
* error from another machine is not this UI's to show (§5). An event of a type this build does
|
|
153788
|
+
* not know is passed when it names a session (qualified), dropped otherwise.
|
|
153789
|
+
*/
|
|
153790
|
+
event(e) {
|
|
153791
|
+
if (!isObj(e) || typeof e.type !== "string") return null;
|
|
153792
|
+
const sid = typeof e.sessionId === "string" ? this.id(e.sessionId) : void 0;
|
|
153793
|
+
const base2 = { ...e, ...sid !== void 0 ? { sessionId: sid } : {} };
|
|
153794
|
+
switch (e.type) {
|
|
153795
|
+
// Another machine's agent asking its own windows to apply (#665) must never relaunch the hub's window
|
|
153796
|
+
case "update_status":
|
|
153797
|
+
case "update_apply_request":
|
|
153798
|
+
case "update_apply_go":
|
|
153799
|
+
case "themes_changed":
|
|
153800
|
+
case "prefs_changed":
|
|
153801
|
+
case "app_state_changed":
|
|
153802
|
+
case "agent_versions":
|
|
153803
|
+
case "external_app_questions_changed":
|
|
153804
|
+
case "orchestrator_proposals_changed":
|
|
153805
|
+
case "assistant_proposals_changed":
|
|
153806
|
+
return null;
|
|
153807
|
+
case "error":
|
|
153808
|
+
return sid === void 0 ? null : base2;
|
|
153809
|
+
/*
|
|
153810
|
+
* 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
|
|
153811
|
+
* 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
|
|
153812
|
+
*/
|
|
153813
|
+
case "mail_changed": {
|
|
153814
|
+
const { arrived: _arrived, ...rest } = base2;
|
|
153815
|
+
return { ...rest, threadId: this.maybeId(e.threadId), toPerson: false };
|
|
153816
|
+
}
|
|
153817
|
+
case "session_created":
|
|
153818
|
+
return { ...base2, session: this.session(e.session) };
|
|
153819
|
+
case "user_message": {
|
|
153820
|
+
const out = { ...base2 };
|
|
153821
|
+
if (isObj(e.from) && typeof e.from.sessionId === "string") out.from = { ...e.from, sessionId: this.id(e.from.sessionId) };
|
|
153822
|
+
if (isObj(e.fromApp)) out.fromApp = { ...e.fromApp, projectId: this.maybeId(e.fromApp.projectId) };
|
|
153823
|
+
return out;
|
|
153824
|
+
}
|
|
153825
|
+
// The sender of the message a turn ran for (#1604), named as a message's sender is
|
|
153826
|
+
case "state_change": {
|
|
153827
|
+
const o = e.origin;
|
|
153828
|
+
if (!isObj(o) || !isObj(o.from) || typeof o.from.sessionId !== "string") return base2;
|
|
153829
|
+
return { ...base2, origin: { ...o, from: { ...o.from, sessionId: this.id(o.from.sessionId) } } };
|
|
153830
|
+
}
|
|
153831
|
+
case "handoff":
|
|
153832
|
+
return { ...base2, fromSessionId: this.maybeId(e.fromSessionId) };
|
|
153833
|
+
case "session_owner":
|
|
153834
|
+
return { ...base2, askedBy: (sid !== void 0 ? this.ownerOf?.(sid) : void 0) ?? this.maybeId(e.askedBy), parentSessionId: this.maybeId(e.parentSessionId) };
|
|
153835
|
+
case "approval_request":
|
|
153836
|
+
this.noteCard(e.sessionId, e.requestId, e.detail);
|
|
153837
|
+
return { ...base2, detail: this.approvalDetail(e.detail) };
|
|
153838
|
+
case "approval_resolved":
|
|
153839
|
+
if (typeof e.sessionId === "string" && typeof e.requestId === "string") this.unread.delete(`${e.sessionId}\0${e.requestId}`);
|
|
153840
|
+
return base2;
|
|
153841
|
+
// The view's instance, which the window opens, calls and closes it by (plan §11)
|
|
153842
|
+
case "app_view":
|
|
153843
|
+
return { ...base2, projectId: this.maybeId(e.projectId), instanceId: this.maybeId(e.instanceId) };
|
|
153844
|
+
// The view whose own call caused it, so that view does not re-read what it already has (B-5)
|
|
153845
|
+
case "external_app_state_changed":
|
|
153846
|
+
return {
|
|
153847
|
+
...base2,
|
|
153848
|
+
projectId: this.maybeId(e.projectId),
|
|
153849
|
+
...isObj(e.cause) ? { cause: { ...e.cause, instanceId: this.maybeId(e.cause.instanceId) } } : {}
|
|
153850
|
+
};
|
|
153851
|
+
case "external_app_runs_changed":
|
|
153852
|
+
case "fs_changed":
|
|
153853
|
+
return { ...base2, projectId: this.maybeId(e.projectId) };
|
|
153854
|
+
// `projects_changed`: a project another machine made (#515); the hub's windows re-read the merged list
|
|
153855
|
+
case "external_apps_changed":
|
|
153856
|
+
case "project_consents_changed":
|
|
153857
|
+
return base2;
|
|
153858
|
+
// `added` (#1220): a project that machine's assistant added, named as the hub's windows know it
|
|
153859
|
+
case "projects_changed":
|
|
153860
|
+
return typeof e.added === "string" ? { ...base2, added: this.maybeId(e.added) } : base2;
|
|
153861
|
+
default:
|
|
153862
|
+
return sid === void 0 ? null : base2;
|
|
153863
|
+
}
|
|
153864
|
+
}
|
|
153865
|
+
};
|
|
153866
|
+
|
|
153422
153867
|
// packages/agent-host/src/links/mail-peers.ts
|
|
153423
153868
|
function mailPeers(o) {
|
|
153424
153869
|
const { machines, hubs: hubs2, settings } = o;
|
|
@@ -153449,7 +153894,7 @@ function mailPeers(o) {
|
|
|
153449
153894
|
machineSession: (machineId, sessionId) => {
|
|
153450
153895
|
const m = machines.get(machineId);
|
|
153451
153896
|
const row = mirrored(machineId, sessionId);
|
|
153452
|
-
return m && row && typeof row.name === "string" ?
|
|
153897
|
+
return m && row && typeof row.name === "string" ? onMachine2(row.name, m.name) : void 0;
|
|
153453
153898
|
},
|
|
153454
153899
|
machineState: (machineId, sessionId) => {
|
|
153455
153900
|
const state = mirrored(machineId, sessionId)?.state;
|
|
@@ -154352,8 +154797,8 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
154352
154797
|
},
|
|
154353
154798
|
"mail.list": async () => requireMail().list(),
|
|
154354
154799
|
"mail.tasks": async () => requireMail().tasks(),
|
|
154355
|
-
"mail.thread": async ({ threadId, after, all, tail, before }) => {
|
|
154356
|
-
return requireMail().thread(threadId, { after, all, tail, before });
|
|
154800
|
+
"mail.thread": async ({ threadId, after, all, tail, before, lookIn }) => {
|
|
154801
|
+
return requireMail().thread(threadId, { after, all, tail, before, lookIn });
|
|
154357
154802
|
},
|
|
154358
154803
|
"mail.reply": async ({ threadId, text: text3, kind, answers: answers2 }) => {
|
|
154359
154804
|
return requireMail().reply(threadId, text3, kind, answers2);
|
|
@@ -154728,7 +155173,13 @@ function createRpcHandler(mgr2, adapters2, { settleDeletedProjects, deleteOutloo
|
|
|
154728
155173
|
"host.hubOffer": async (p, ctx) => {
|
|
154729
155174
|
const offer = p;
|
|
154730
155175
|
if (hubs2 && ctx) hubs2.offer(ctx.client, offer);
|
|
154731
|
-
|
|
155176
|
+
const lacks = mailAcross && hubs2 && offer.open?.length ? mailAcross.lacking(offer.hub.id, offer.open) : [];
|
|
155177
|
+
return {
|
|
155178
|
+
ok: true,
|
|
155179
|
+
...mailAcross && hubs2 ? { mail: true, tasks: true, host: mailAcross.hostId } : {},
|
|
155180
|
+
...lacks.length ? { lacks } : {},
|
|
155181
|
+
...appsAcross && hubs2?.appsOn ? { apps: true } : {}
|
|
155182
|
+
};
|
|
154732
155183
|
},
|
|
154733
155184
|
"host.mail": async (p, ctx) => {
|
|
154734
155185
|
const hub = ctx ? hubs2?.on?.(ctx.client) : void 0;
|
|
@@ -158995,301 +159446,6 @@ async function askHubAuto(call2, allowed) {
|
|
|
158995
159446
|
// packages/agent-host/src/links/linked-machine-connection.ts
|
|
158996
159447
|
import { randomBytes as randomBytes15 } from "node:crypto";
|
|
158997
159448
|
|
|
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
159449
|
// packages/agent-host/src/links/remote-client.ts
|
|
159294
159450
|
var MAX_INCOMING_CALLS = 16;
|
|
159295
159451
|
var DEFAULT_CALL_TIMEOUT_MS = 2e5;
|
|
@@ -160419,11 +160575,15 @@ var LinkedMachineConnection = class {
|
|
|
160419
160575
|
const on2 = this.record.asks === true;
|
|
160420
160576
|
let note = null;
|
|
160421
160577
|
if (this.client === client) this.tasksBack = void 0;
|
|
160578
|
+
const open6 = this.deps.hubMail ? this.deps.openTasks?.(this.id) ?? [] : [];
|
|
160579
|
+
let lacks = [];
|
|
160422
160580
|
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 } : {} });
|
|
160581
|
+
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 } : {} });
|
|
160582
|
+
if (isObj(answer) && Array.isArray(answer.lacks)) lacks = answer.lacks.filter((id3) => typeof id3 === "string");
|
|
160424
160583
|
if (this.client === client) this.mailBack = isObj(answer) && answer.mail === true;
|
|
160425
160584
|
if (this.client === client) this.appsBack = isObj(answer) && answer.apps === true;
|
|
160426
160585
|
if (this.client === client) this.tasksBack = isObj(answer) && answer.tasks === true;
|
|
160586
|
+
if (this.client === client) this.q.mail = { hub: self2.id, own: isObj(answer) && typeof answer.host === "string" ? answer.host : null, computer: () => this.name };
|
|
160427
160587
|
} catch (err) {
|
|
160428
160588
|
if (this.client === client) this.appsBack = false;
|
|
160429
160589
|
if (this.client === client) this.mailBack = false;
|
|
@@ -160431,7 +160591,7 @@ var LinkedMachineConnection = class {
|
|
|
160431
160591
|
if (on2) note = `${this.name} could not be told yet (${err.message}); it is told again at the next connect`;
|
|
160432
160592
|
}
|
|
160433
160593
|
if (this.client !== client) return;
|
|
160434
|
-
this.deps.onOfferAnswered?.(this.id);
|
|
160594
|
+
this.deps.onOfferAnswered?.(this.id, lacks);
|
|
160435
160595
|
const changed = note !== this.asksNote;
|
|
160436
160596
|
this.asksNote = note;
|
|
160437
160597
|
if (changed) this.deps.broadcast({ type: "machine_status", machine: this.info() });
|
|
@@ -160636,7 +160796,7 @@ var LinkedMachineConnection = class {
|
|
|
160636
160796
|
if (this.stopped) return;
|
|
160637
160797
|
const readsOnly = this.readsOnly;
|
|
160638
160798
|
this.readsOnly = false;
|
|
160639
|
-
const
|
|
160799
|
+
const quiet2 = this.quietRetry;
|
|
160640
160800
|
this.quietRetry = false;
|
|
160641
160801
|
const { dataDir, shell } = this.record.remote;
|
|
160642
160802
|
const badDir = dataDir ? dataDirError(dataDir, shell) : null;
|
|
@@ -160646,7 +160806,7 @@ var LinkedMachineConnection = class {
|
|
|
160646
160806
|
this.client = null;
|
|
160647
160807
|
}
|
|
160648
160808
|
if (this.heldBack && !this.startAsked) this.setStatus("stopped", this.heldBack);
|
|
160649
|
-
else if (!(
|
|
160809
|
+
else if (!(quiet2 && this.status === "away")) this.setStatus("connecting", null);
|
|
160650
160810
|
let endpoint = await this.openTunnel();
|
|
160651
160811
|
if (!endpoint) return;
|
|
160652
160812
|
if (this.status === "away") this.setStatus("connecting", null);
|
|
@@ -162626,9 +162786,17 @@ var ROUTES = {
|
|
|
162626
162786
|
"workspace.load": HUB,
|
|
162627
162787
|
// The mailbox is the hub's: a linked machine's mail reaches it there (slice 4 of #1347)
|
|
162628
162788
|
"mail.list": HUB,
|
|
162629
|
-
//
|
|
162630
|
-
|
|
162631
|
-
"mail.
|
|
162789
|
+
// 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,
|
|
162790
|
+
// and the machine reads nothing in it for its own person (`lookIn`)
|
|
162791
|
+
"mail.tasks": MERGE,
|
|
162792
|
+
"mail.thread": {
|
|
162793
|
+
kind: "chain",
|
|
162794
|
+
params: (p) => ({ ...p, lookIn: true }),
|
|
162795
|
+
result: (r, q2) => {
|
|
162796
|
+
const v = q2.mailThread(r);
|
|
162797
|
+
return isObj(v) ? { ...v, lookIn: true, canReply: false } : v;
|
|
162798
|
+
}
|
|
162799
|
+
},
|
|
162632
162800
|
"mail.reply": HUB,
|
|
162633
162801
|
"mail.close": HUB,
|
|
162634
162802
|
"mail.held": HUB,
|
|
@@ -162765,6 +162933,8 @@ var Router = class {
|
|
|
162765
162933
|
return this.byKey(method, params, route.key ?? "projectId", route, ctx);
|
|
162766
162934
|
case "terminal":
|
|
162767
162935
|
return this.byKey(method, params, "terminalId", route, ctx);
|
|
162936
|
+
case "chain":
|
|
162937
|
+
return this.byKey(method, params, "threadId", { ...route, accepts: isChainId }, ctx);
|
|
162768
162938
|
case "view":
|
|
162769
162939
|
return this.byView(method, params, route, ctx);
|
|
162770
162940
|
case "noRemote": {
|
|
@@ -162780,9 +162950,10 @@ var Router = class {
|
|
|
162780
162950
|
return this.merge(method, params, ctx);
|
|
162781
162951
|
}
|
|
162782
162952
|
};
|
|
162783
|
-
/** The linked machine an id names, or null for the hub's own (an unprefixed id,
|
|
162784
|
-
owner(value) {
|
|
162785
|
-
|
|
162953
|
+
/** 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`) */
|
|
162954
|
+
owner(value, accepts2) {
|
|
162955
|
+
const found = typeof value === "string" ? qualifiedMachine(this.opts.machines(), value) : null;
|
|
162956
|
+
return found && (accepts2?.(found.id) ?? true) ? found.machine : null;
|
|
162786
162957
|
}
|
|
162787
162958
|
machineById(id3) {
|
|
162788
162959
|
return typeof id3 === "string" ? findMachine(this.opts.machines(), id3) : null;
|
|
@@ -162804,7 +162975,7 @@ var Router = class {
|
|
|
162804
162975
|
const r5 = await this.forward(m2, method, route.params ? route.params(rest, m2.q) : rest, ctx);
|
|
162805
162976
|
return route.result ? route.result(r5, m2.q) : r5;
|
|
162806
162977
|
}
|
|
162807
|
-
const m = this.owner(params[key2]);
|
|
162978
|
+
const m = this.owner(params[key2], route.accepts);
|
|
162808
162979
|
if (!m) return this.opts.local(method, params, ctx);
|
|
162809
162980
|
const { machine: _machine, ...own } = params;
|
|
162810
162981
|
let p = { ...route.orMachine ? own : params, [key2]: m.q.strip(params[key2], "The id") };
|
|
@@ -163002,8 +163173,10 @@ var Router = class {
|
|
|
163002
163173
|
const answers2 = await Promise.all(
|
|
163003
163174
|
machines.filter((m) => m.reachable).map(async (m) => {
|
|
163004
163175
|
try {
|
|
163176
|
+
if (method === "mail.tasks") await m.offerAnswered?.();
|
|
163005
163177
|
return { m, r: await callOn(m, method, params, ctx) };
|
|
163006
|
-
} catch {
|
|
163178
|
+
} catch (e) {
|
|
163179
|
+
if (method === "mail.tasks" && older2(e)) return null;
|
|
163007
163180
|
missed.push(m);
|
|
163008
163181
|
return null;
|
|
163009
163182
|
}
|
|
@@ -163023,11 +163196,47 @@ var Router = class {
|
|
|
163023
163196
|
const failed5 = Array.isArray(out.failed) ? out.failed : [];
|
|
163024
163197
|
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
163198
|
}
|
|
163026
|
-
if (
|
|
163199
|
+
if (method === "mail.tasks" && isObj(out)) out = this.oneTaskEach(out);
|
|
163200
|
+
if ((method === "trash.list" || method === "subagents.usage" || method === "mail.tasks") && missed.length && isObj(out)) {
|
|
163027
163201
|
out = { ...out, unreached: missed.map((m) => ({ machineId: m.id, name: m.name })) };
|
|
163028
163202
|
}
|
|
163029
163203
|
return out;
|
|
163030
163204
|
}
|
|
163205
|
+
/**
|
|
163206
|
+
* 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
|
|
163207
|
+
* 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
|
|
163208
|
+
* 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.
|
|
163209
|
+
* 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
|
|
163210
|
+
*/
|
|
163211
|
+
oneTaskEach(out) {
|
|
163212
|
+
const from = (t) => this.owner(t.root, isChainId);
|
|
163213
|
+
const kept = /* @__PURE__ */ new Map();
|
|
163214
|
+
const odd = [];
|
|
163215
|
+
for (const t of listIn(out, "tasks")) {
|
|
163216
|
+
if (!isObj(t) || !isObj(t.assignee)) {
|
|
163217
|
+
odd.push(t);
|
|
163218
|
+
continue;
|
|
163219
|
+
}
|
|
163220
|
+
const origin = from(t);
|
|
163221
|
+
const on2 = this.owner(t.assignee.sessionId);
|
|
163222
|
+
const authority = on2 !== null && origin === on2 ? t : null;
|
|
163223
|
+
const key2 = `${String(t.id)}\0${String(t.assignee.address)}`;
|
|
163224
|
+
const seen = kept.get(key2);
|
|
163225
|
+
if (!seen) kept.set(key2, { row: t, hub: origin === null, authority });
|
|
163226
|
+
else if (seen.hub || !authority) kept.set(key2, { ...seen, authority: seen.authority ?? authority });
|
|
163227
|
+
else kept.set(key2, { row: t, hub: false, authority });
|
|
163228
|
+
}
|
|
163229
|
+
const rows3 = [...kept.values()].map(
|
|
163230
|
+
({ row, authority }) => authority && authority !== row ? { ...row, state: authority.state, outcome: authority.outcome, updatedAt: authority.updatedAt } : row
|
|
163231
|
+
);
|
|
163232
|
+
const capped = typeof out.capped === "number" ? rows3.filter((t) => t.state !== "done").length : null;
|
|
163233
|
+
return { ...out, tasks: [...rows3, ...odd], capped };
|
|
163234
|
+
}
|
|
163235
|
+
};
|
|
163236
|
+
var listIn = (x, field) => isObj(x) && Array.isArray(x[field]) ? x[field] : [];
|
|
163237
|
+
var isChainId = (id3) => {
|
|
163238
|
+
const kind = parseMailId(id3)?.kind;
|
|
163239
|
+
return kind === "message" || kind === "thread";
|
|
163031
163240
|
};
|
|
163032
163241
|
function combine(method, acc, r, q2) {
|
|
163033
163242
|
const list2 = (x) => Array.isArray(x) ? x : [];
|
|
@@ -163053,6 +163262,12 @@ function combine(method, acc, r, q2) {
|
|
|
163053
163262
|
..."subagentSteps" in a || "subagentSteps" in b2 ? { subagentSteps: [...list2(a.subagentSteps), ...list2(b2.subagentSteps).map((t) => q2.subagentSteps(t))] } : {}
|
|
163054
163263
|
};
|
|
163055
163264
|
}
|
|
163265
|
+
case "mail.tasks": {
|
|
163266
|
+
const a = isObj(acc) ? acc : { tasks: [] };
|
|
163267
|
+
const b2 = isObj(r) ? r : { tasks: [] };
|
|
163268
|
+
const capped = typeof a.capped === "number" ? a.capped : typeof b2.capped === "number" ? b2.capped : null;
|
|
163269
|
+
return { ...a, tasks: [...listIn(a, "tasks"), ...q2.taskRows(listIn(b2, "tasks"))], capped };
|
|
163270
|
+
}
|
|
163056
163271
|
case "subagents.usage": {
|
|
163057
163272
|
const a = isObj(acc) ? acc : { sessions: [] };
|
|
163058
163273
|
const b2 = isObj(r) ? r : { sessions: [] };
|
|
@@ -163138,12 +163353,12 @@ function linkDepsFor(store2, rest) {
|
|
|
163138
163353
|
const log = (line) => rest.log?.(stamped(line));
|
|
163139
163354
|
return { ...rest, log, mirror: storeMirror(store2), registry: storeRegistry(store2), tunnelFor: tunnelsFor(store2, log) };
|
|
163140
163355
|
}
|
|
163141
|
-
var
|
|
163356
|
+
var kindOf3 = (k2) => k2 === "sessions" ? "session" : "project";
|
|
163142
163357
|
var withIds = (list2) => list2.filter((x) => isObj(x) && typeof x.id === "string");
|
|
163143
163358
|
function storeMirror(store2) {
|
|
163144
163359
|
return {
|
|
163145
|
-
read: (machine, kind) => store2.machines.machineHeaders(machine,
|
|
163146
|
-
replace: (machine, kind, list2) => store2.machines.replaceMachineHeaders(machine,
|
|
163360
|
+
read: (machine, kind) => store2.machines.machineHeaders(machine, kindOf3(kind)),
|
|
163361
|
+
replace: (machine, kind, list2) => store2.machines.replaceMachineHeaders(machine, kindOf3(kind), withIds(list2)),
|
|
163147
163362
|
upsertSession: (machine, session2) => {
|
|
163148
163363
|
if (typeof session2.id === "string") store2.machines.upsertMachineSession(machine, session2);
|
|
163149
163364
|
},
|
|
@@ -163897,7 +164112,7 @@ var handedToken = launch.tokenOnStdin ? await readHandedToken(process.stdin).cat
|
|
|
163897
164112
|
console.error(`[agent-host] the launcher did not hand over the token: ${e.message}`);
|
|
163898
164113
|
process.exit(1);
|
|
163899
164114
|
}) : launch.token;
|
|
163900
|
-
var BUILD = true ? "
|
|
164115
|
+
var BUILD = true ? "b4e9fc0" : "dev";
|
|
163901
164116
|
var { values } = parseArgs({
|
|
163902
164117
|
options: {
|
|
163903
164118
|
port: { type: "string", default: "5175" },
|
|
@@ -164074,7 +164289,6 @@ var mailPerson = new MailPerson(hostMailbox.service, store.mailbox, mailDelivery
|
|
|
164074
164289
|
const s = mgr.sessionInfo(id3);
|
|
164075
164290
|
return s ? { name: s.name, state: s.state } : void 0;
|
|
164076
164291
|
}, hostMailbox),
|
|
164077
|
-
legacyChain: (threadId) => store.legacyChain(threadId, void 0, 100),
|
|
164078
164292
|
projectLabel: (projectId) => hostMailbox.reach.projectLabel(projectId),
|
|
164079
164293
|
untrusted: (projectId) => hostMailbox.reach.untrusted(projectId),
|
|
164080
164294
|
// 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 +164448,9 @@ var links = new Links(linkDepsFor(store, {
|
|
|
164234
164448
|
hubMail: true,
|
|
164235
164449
|
// This hub's apps used by the agents its sessions started on a machine (#1938, §13.5)
|
|
164236
164450
|
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.
|
|
164451
|
+
// 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)
|
|
164452
|
+
onOfferAnswered: (machineId, lacks) => hostMailbox.across.offerAnswered(machineId, lacks),
|
|
164453
|
+
openTasks: (machineId) => hostMailbox.across.openTasksTo(machineId),
|
|
164239
164454
|
// When agents compact: this hub's setting governs the machines it links (#1376)
|
|
164240
164455
|
autoCompact: () => autoCompactOf(mgr.prefs.uiPreferences()),
|
|
164241
164456
|
// 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
|