@join-pantheon/cli 0.37.3 → 0.38.0
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/dist/admin-founder.js +5 -2
- package/dist/admin-pages.js +29 -2
- package/dist/cli.js +285 -38
- package/dist/crash-loop.js +207 -0
- package/dist/doctor.js +38 -1
- package/dist/finish-line.js +14 -7
- package/dist/folder-ask.js +104 -0
- package/dist/founder-stats.js +24 -1
- package/dist/home-guard.js +21 -0
- package/dist/home-safety.js +2 -0
- package/dist/install-stats.js +314 -0
- package/dist/machine.js +2 -0
- package/dist/mcp.js +37 -1
- package/dist/notice.js +106 -0
- package/dist/notifier.js +206 -16
- package/dist/onboard-copy.js +3 -0
- package/dist/pickup.js +11 -3
- package/dist/quickstart.js +41 -21
- package/dist/relay.js +56 -6
- package/dist/service.js +5 -0
- package/dist/setup-changes.js +5 -0
- package/dist/setup-guide.js +25 -4
- package/dist/status-engine.js +1 -1
- package/dist/tray.js +9 -2
- package/dist/version-health.js +288 -0
- package/dist/win-host.js +2 -0
- package/dist/worker-policy.js +45 -3
- package/dist/worker.js +61 -24
- package/npm-shrinkwrap.json +13 -2
- package/package.json +2 -1
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
import { createWriteStream, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { appendFile, readFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { pipeline } from "node:stream/promises";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
import { createGunzip } from "node:zlib";
|
|
8
|
+
export const KEEP_MONTHS = 13;
|
|
9
|
+
export const GEO_MAX_AGE_MS = 32 * 86_400_000;
|
|
10
|
+
const BOT = /bot|crawl|spider|preview|slack|discord|whatsapp|telegram|facebookexternalhit|linkedin|embedly|vkshare|skype|uptime|monitor|pingdom|headless/i;
|
|
11
|
+
const DATACENTER = /amazon|aws|google|microsoft|azure|digitalocean|hetzner|ovh|linode|akamai|oracle|alibaba|tencent|cloudflare|github|fastly|vultr|scaleway|contabo|leaseweb|choopa|railway|fly\.io|render/i;
|
|
12
|
+
export function clientOf(ua) {
|
|
13
|
+
if (BOT.test(ua))
|
|
14
|
+
return "bot";
|
|
15
|
+
if (/^curl\//i.test(ua))
|
|
16
|
+
return "curl";
|
|
17
|
+
if (/^wget\//i.test(ua))
|
|
18
|
+
return "wget";
|
|
19
|
+
if (/powershell/i.test(ua))
|
|
20
|
+
return "powershell";
|
|
21
|
+
if (/mozilla\//i.test(ua))
|
|
22
|
+
return "browser";
|
|
23
|
+
return ua ? "other" : "none";
|
|
24
|
+
}
|
|
25
|
+
export function osOf(ua, file) {
|
|
26
|
+
if (/windows/i.test(ua))
|
|
27
|
+
return "windows";
|
|
28
|
+
if (/mac os x|macintosh|darwin/i.test(ua))
|
|
29
|
+
return "mac";
|
|
30
|
+
if (/linux|x11/i.test(ua))
|
|
31
|
+
return "linux";
|
|
32
|
+
return file === "install.ps1" ? "windows" : undefined;
|
|
33
|
+
}
|
|
34
|
+
export function isDatacenter(org) { return !!org && DATACENTER.test(org); }
|
|
35
|
+
export class GeoIp {
|
|
36
|
+
dir;
|
|
37
|
+
log;
|
|
38
|
+
fetchImpl;
|
|
39
|
+
city = null;
|
|
40
|
+
asn = null;
|
|
41
|
+
refreshing = false;
|
|
42
|
+
constructor(dir, log = () => { }, fetchImpl = fetch) {
|
|
43
|
+
this.dir = dir;
|
|
44
|
+
this.log = log;
|
|
45
|
+
this.fetchImpl = fetchImpl;
|
|
46
|
+
}
|
|
47
|
+
get ready() { return !!this.city; }
|
|
48
|
+
lookup(ip) {
|
|
49
|
+
const out = {};
|
|
50
|
+
try {
|
|
51
|
+
const g = this.city?.get(ip);
|
|
52
|
+
if (g) {
|
|
53
|
+
if (g.country?.iso_code)
|
|
54
|
+
out.country = g.country.iso_code;
|
|
55
|
+
if (g.country?.names?.en)
|
|
56
|
+
out.country_name = g.country.names.en;
|
|
57
|
+
if (g.subdivisions?.[0]?.names?.en)
|
|
58
|
+
out.region = g.subdivisions[0].names.en;
|
|
59
|
+
if (g.city?.names?.en)
|
|
60
|
+
out.city = g.city.names.en;
|
|
61
|
+
if (typeof g.location?.latitude === "number") {
|
|
62
|
+
out.lat = g.location.latitude;
|
|
63
|
+
out.lon = g.location.longitude;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const a = this.asn?.get(ip);
|
|
67
|
+
if (a?.autonomous_system_organization)
|
|
68
|
+
out.org = a.autonomous_system_organization;
|
|
69
|
+
if (a?.autonomous_system_number)
|
|
70
|
+
out.asn = a.autonomous_system_number;
|
|
71
|
+
}
|
|
72
|
+
catch { }
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
async start() {
|
|
76
|
+
await this.load();
|
|
77
|
+
void this.refresh();
|
|
78
|
+
}
|
|
79
|
+
async load() {
|
|
80
|
+
const { Reader } = await import("mmdb-lib");
|
|
81
|
+
for (const [name, set] of [["city", (r) => { this.city = r; }], ["asn", (r) => { this.asn = r; }]]) {
|
|
82
|
+
const f = join(this.dir, `${name}.mmdb`);
|
|
83
|
+
if (!existsSync(f))
|
|
84
|
+
continue;
|
|
85
|
+
try {
|
|
86
|
+
set(new Reader(await readFile(f)));
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
this.log(`geoip: could not read ${name}.mmdb (${e.message}); fetching it again`);
|
|
90
|
+
try {
|
|
91
|
+
rmSync(f, { force: true });
|
|
92
|
+
}
|
|
93
|
+
catch { }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async refresh(now = Date.now()) {
|
|
98
|
+
if (this.refreshing)
|
|
99
|
+
return;
|
|
100
|
+
this.refreshing = true;
|
|
101
|
+
try {
|
|
102
|
+
mkdirSync(this.dir, { recursive: true });
|
|
103
|
+
let changed = false;
|
|
104
|
+
for (const [name, remote] of [["city", "dbip-city-lite"], ["asn", "dbip-asn-lite"]]) {
|
|
105
|
+
const f = join(this.dir, `${name}.mmdb`);
|
|
106
|
+
let age = Infinity;
|
|
107
|
+
try {
|
|
108
|
+
age = now - statSync(f).mtimeMs;
|
|
109
|
+
}
|
|
110
|
+
catch { }
|
|
111
|
+
if (age < GEO_MAX_AGE_MS)
|
|
112
|
+
continue;
|
|
113
|
+
for (const back of [0, 1]) {
|
|
114
|
+
const d = new Date(now);
|
|
115
|
+
d.setUTCDate(1);
|
|
116
|
+
d.setUTCMonth(d.getUTCMonth() - back);
|
|
117
|
+
const month = `${d.getUTCFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, "0")}`;
|
|
118
|
+
const url = `https://download.db-ip.com/free/${remote}-${month}.mmdb.gz`;
|
|
119
|
+
try {
|
|
120
|
+
const r = await this.fetchImpl(url, { signal: AbortSignal.timeout(300_000) });
|
|
121
|
+
if (!r.ok || !r.body) {
|
|
122
|
+
if (r.status === 404)
|
|
123
|
+
continue;
|
|
124
|
+
throw new Error(`HTTP ${r.status}`);
|
|
125
|
+
}
|
|
126
|
+
const tmp = `${f}.${process.pid}.tmp`;
|
|
127
|
+
await pipeline(Readable.fromWeb(r.body), createGunzip(), createWriteStream(tmp));
|
|
128
|
+
renameSync(tmp, f);
|
|
129
|
+
this.log(`geoip: ${remote} ${month} saved`);
|
|
130
|
+
changed = true;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
this.log(`geoip: could not fetch ${remote} ${month} (${e.message}); downloads are counted without a place until it is`);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (changed)
|
|
140
|
+
await this.load();
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
this.refreshing = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export class InstallStats {
|
|
148
|
+
dir;
|
|
149
|
+
geo;
|
|
150
|
+
now;
|
|
151
|
+
keyBuf = null;
|
|
152
|
+
pruned = false;
|
|
153
|
+
constructor(dir, geo = null, now = Date.now) {
|
|
154
|
+
this.dir = dir;
|
|
155
|
+
this.geo = geo;
|
|
156
|
+
this.now = now;
|
|
157
|
+
}
|
|
158
|
+
get key() {
|
|
159
|
+
if (this.keyBuf)
|
|
160
|
+
return this.keyBuf;
|
|
161
|
+
const kf = join(this.dir, "net-key");
|
|
162
|
+
try {
|
|
163
|
+
const k = readFileSync(kf);
|
|
164
|
+
if (k.length >= 16)
|
|
165
|
+
return (this.keyBuf = k);
|
|
166
|
+
}
|
|
167
|
+
catch { }
|
|
168
|
+
const k = randomBytes(32);
|
|
169
|
+
try {
|
|
170
|
+
mkdirSync(this.dir, { recursive: true });
|
|
171
|
+
writeFileSync(kf, k, { mode: 0o600 });
|
|
172
|
+
}
|
|
173
|
+
catch { }
|
|
174
|
+
return (this.keyBuf = k);
|
|
175
|
+
}
|
|
176
|
+
netOf(ip) { return createHmac("sha256", this.key).update(ip.replace(/^::ffff:/, "")).digest("hex").slice(0, 16); }
|
|
177
|
+
event(o) {
|
|
178
|
+
const h = (k) => { const v = o.headers[k]; return (Array.isArray(v) ? v[0] : v)?.slice(0, 200); };
|
|
179
|
+
const ua = h("user-agent") ?? "";
|
|
180
|
+
const ip = o.ip.replace(/^::ffff:/, "");
|
|
181
|
+
const place = this.geo?.lookup(ip) ?? {};
|
|
182
|
+
const client = clientOf(ua);
|
|
183
|
+
const e = {
|
|
184
|
+
at: this.now(), file: o.file, method: o.method === "HEAD" ? "HEAD" : "GET", version: o.version, net: this.netOf(ip), ua, client,
|
|
185
|
+
...place,
|
|
186
|
+
};
|
|
187
|
+
const os = osOf(ua, o.file);
|
|
188
|
+
if (os)
|
|
189
|
+
e.os = os;
|
|
190
|
+
if (isDatacenter(place.org))
|
|
191
|
+
e.datacenter = true;
|
|
192
|
+
if (client === "bot")
|
|
193
|
+
e.bot = true;
|
|
194
|
+
const ref = h("referer");
|
|
195
|
+
if (ref) {
|
|
196
|
+
try {
|
|
197
|
+
e.referer = new URL(ref).host;
|
|
198
|
+
}
|
|
199
|
+
catch { }
|
|
200
|
+
}
|
|
201
|
+
const lang = h("accept-language");
|
|
202
|
+
if (lang)
|
|
203
|
+
e.lang = lang.split(",")[0].trim().slice(0, 20);
|
|
204
|
+
return e;
|
|
205
|
+
}
|
|
206
|
+
record(e) {
|
|
207
|
+
const month = new Date(e.at).toISOString().slice(0, 7);
|
|
208
|
+
try {
|
|
209
|
+
mkdirSync(this.dir, { recursive: true });
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return Promise.resolve();
|
|
213
|
+
}
|
|
214
|
+
if (!this.pruned) {
|
|
215
|
+
this.pruned = true;
|
|
216
|
+
this.prune();
|
|
217
|
+
}
|
|
218
|
+
return appendFile(join(this.dir, `${month}.jsonl`), JSON.stringify(e) + "\n").catch(() => { });
|
|
219
|
+
}
|
|
220
|
+
read(since) {
|
|
221
|
+
const out = [];
|
|
222
|
+
const from = new Date(since).toISOString().slice(0, 7);
|
|
223
|
+
let files = [];
|
|
224
|
+
try {
|
|
225
|
+
files = readdirSync(this.dir).filter((f) => /^\d{4}-\d{2}\.jsonl$/.test(f) && f.slice(0, 7) >= from).sort();
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
for (const f of files) {
|
|
231
|
+
let text = "";
|
|
232
|
+
try {
|
|
233
|
+
text = readFileSync(join(this.dir, f), "utf8");
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
for (const line of text.split("\n")) {
|
|
239
|
+
if (!line)
|
|
240
|
+
continue;
|
|
241
|
+
try {
|
|
242
|
+
const e = JSON.parse(line);
|
|
243
|
+
if (e.at >= since)
|
|
244
|
+
out.push(e);
|
|
245
|
+
}
|
|
246
|
+
catch { }
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return out;
|
|
250
|
+
}
|
|
251
|
+
prune() {
|
|
252
|
+
const d = new Date(this.now());
|
|
253
|
+
d.setUTCDate(1);
|
|
254
|
+
d.setUTCMonth(d.getUTCMonth() - KEEP_MONTHS);
|
|
255
|
+
const oldest = d.toISOString().slice(0, 7);
|
|
256
|
+
try {
|
|
257
|
+
for (const f of readdirSync(this.dir))
|
|
258
|
+
if (/^\d{4}-\d{2}\.jsonl$/.test(f) && f.slice(0, 7) < oldest)
|
|
259
|
+
rmSync(join(this.dir, f), { force: true });
|
|
260
|
+
}
|
|
261
|
+
catch { }
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
export const counted = (e) => e.method === "GET" && !e.bot && !e.datacenter;
|
|
265
|
+
export function summarize(events, signIns, now, geo, days = 14) {
|
|
266
|
+
const DAY = 86_400_000;
|
|
267
|
+
const since30 = now - 30 * DAY;
|
|
268
|
+
const last30 = events.filter((e) => e.at >= since30);
|
|
269
|
+
const ok = last30.filter(counted);
|
|
270
|
+
const dayKey = (t) => new Date(t).toISOString().slice(0, 10);
|
|
271
|
+
const byDay = new Map();
|
|
272
|
+
for (let i = days - 1; i >= 0; i--)
|
|
273
|
+
byDay.set(dayKey(now - i * DAY), { downloads: 0, nets: new Set(), sh: 0, ps1: 0 });
|
|
274
|
+
for (const e of ok) {
|
|
275
|
+
const d = byDay.get(dayKey(e.at));
|
|
276
|
+
if (!d)
|
|
277
|
+
continue;
|
|
278
|
+
d.downloads++;
|
|
279
|
+
d.nets.add(e.net);
|
|
280
|
+
if (e.file === "install.sh")
|
|
281
|
+
d.sh++;
|
|
282
|
+
else
|
|
283
|
+
d.ps1++;
|
|
284
|
+
}
|
|
285
|
+
const top = (pick, n = 10) => {
|
|
286
|
+
const m = new Map();
|
|
287
|
+
for (const e of ok) {
|
|
288
|
+
const k = pick(e);
|
|
289
|
+
if (k)
|
|
290
|
+
m.set(k, (m.get(k) ?? 0) + 1);
|
|
291
|
+
}
|
|
292
|
+
return [...m.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).slice(0, n).map(([name, n]) => ({ name, n }));
|
|
293
|
+
};
|
|
294
|
+
const firstByNet = new Map();
|
|
295
|
+
for (const e of ok)
|
|
296
|
+
if (!firstByNet.has(e.net))
|
|
297
|
+
firstByNet.set(e.net, e.at);
|
|
298
|
+
let signedIn30 = 0;
|
|
299
|
+
for (const [net, at] of firstByNet)
|
|
300
|
+
if (signIns.some((s) => s.net === net && s.at >= at && s.at - at <= DAY))
|
|
301
|
+
signedIn30++;
|
|
302
|
+
return {
|
|
303
|
+
days: [...byDay.entries()].map(([day, d]) => ({ day, downloads: d.downloads, networks: d.nets.size, sh: d.sh, ps1: d.ps1 })),
|
|
304
|
+
total30: ok.length, networks30: firstByNet.size,
|
|
305
|
+
countries: top((e) => e.country_name ?? e.country),
|
|
306
|
+
cities: top((e) => (e.city ? `${e.city}${e.region ? `, ${e.region}` : ""}, ${e.country ?? "?"}` : undefined)),
|
|
307
|
+
clients: top((e) => `${e.client}${e.os ? ` · ${e.os}` : ""}`),
|
|
308
|
+
signedIn30,
|
|
309
|
+
excluded30: { bots: last30.filter((e) => e.bot).length, datacenter: last30.filter((e) => e.datacenter && !e.bot).length, head: last30.filter((e) => e.method === "HEAD" && !e.bot && !e.datacenter).length },
|
|
310
|
+
recent: [...events].sort((a, b) => b.at - a.at).slice(0, 25),
|
|
311
|
+
geo,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=install-stats.js.map
|
package/dist/machine.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stopIsExpected } from "./crash-loop.js";
|
|
1
2
|
import { execFileSync } from "node:child_process";
|
|
2
3
|
import { closeSync, existsSync, fstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, rmSync, rmdirSync, statSync, writeFileSync } from "node:fs";
|
|
3
4
|
import { homedir, hostname, networkInterfaces, platform } from "node:os";
|
|
@@ -623,6 +624,7 @@ const defaultStopIo = (port = 8787) => ({
|
|
|
623
624
|
export const borrowedHomeLine = (kind) => `${kind === "services" ? "services" : `${kind}:`} left alone — HOME (${homedir()}) is not your own home (a test, a sandbox or another account's folder), so the service manager's jobs here are the real user's, not this home's. Nothing was stopped; run this from your own login to stop your services`;
|
|
624
625
|
export const isPantheonCommand = (cmd) => /pantheon/i.test(cmd) || /\bcli\.js\s+(relay|start)\b/.test(cmd);
|
|
625
626
|
export function stopProcResult(kind, io = defaultStopIo()) {
|
|
627
|
+
stopIsExpected(kind);
|
|
626
628
|
const p = io.proc(kind);
|
|
627
629
|
const ours = io.installed(kind);
|
|
628
630
|
if (!ours && (p.managedBy === "launchd" || p.managedBy === "systemd") && p.running) {
|
package/dist/mcp.js
CHANGED
|
@@ -18,6 +18,8 @@ import { plainError } from "./plain.js";
|
|
|
18
18
|
import { openFailureWhy, openQuestionGoal, questionFailureText, settleFailedQuestion, settleFailedQuestionGoal } from "./question-goal.js";
|
|
19
19
|
import { VERSION } from "./version.js";
|
|
20
20
|
import { installedVersion } from "./mcp-supervisor.js";
|
|
21
|
+
import { behindStatusLine, localVersion, readVersionHealth, refreshRelayPkg, relayKey, RELAY_PKG_REFRESH_MS } from "./version-health.js";
|
|
22
|
+
import { loadPolicy } from "./worker-policy.js";
|
|
21
23
|
import { backendFromLabel } from "./agents.js";
|
|
22
24
|
import { agentHookStates } from "./notify.js";
|
|
23
25
|
import { reportMcpBusy, reportMcpIdle } from "./mcp-activity.js";
|
|
@@ -377,13 +379,42 @@ export async function runMcp() {
|
|
|
377
379
|
rubricShown = true;
|
|
378
380
|
return acts.map(fmt).join("\n\n---\n\n") + `\n\n${rubric}`;
|
|
379
381
|
};
|
|
382
|
+
let behindSaid = false;
|
|
383
|
+
let relayLookAt = 0;
|
|
384
|
+
const behindLine = () => {
|
|
385
|
+
if (role === "worker")
|
|
386
|
+
return null;
|
|
387
|
+
try {
|
|
388
|
+
const state = readVersionHealth();
|
|
389
|
+
const seen = state.relays[relayKey(cfg.relay)] ?? null;
|
|
390
|
+
if ((!seen || Date.now() - seen.seen_at >= RELAY_PKG_REFRESH_MS) && Date.now() - relayLookAt >= RELAY_PKG_REFRESH_MS) {
|
|
391
|
+
relayLookAt = Date.now();
|
|
392
|
+
void refreshRelayPkg(cfg.relay).catch(() => null);
|
|
393
|
+
}
|
|
394
|
+
let policy = null;
|
|
395
|
+
try {
|
|
396
|
+
policy = loadPolicy();
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
policy = null;
|
|
400
|
+
}
|
|
401
|
+
const line = behindStatusLine({ local: localVersion(), seen, now: Date.now(), policy, state, full: !behindSaid });
|
|
402
|
+
if (line?.startsWith("PANTHEON IS OUT OF DATE"))
|
|
403
|
+
behindSaid = true;
|
|
404
|
+
return line;
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
};
|
|
380
410
|
const situation = () => {
|
|
381
411
|
const settledNow = [...client.goals.values()].filter((g) => isSettled(g, client.obligations, client.relayNow(), (id) => client.seenAct(id)?.goal));
|
|
382
412
|
const open = [...client.goals.values()].filter((g) => g.state !== "CLOSED" && !settledNow.includes(g));
|
|
383
413
|
const reach = (p) => {
|
|
384
414
|
const head = client.head;
|
|
385
415
|
const runningRef = p.worker?.state === "running" ? p.worker.ref : undefined;
|
|
386
|
-
const
|
|
416
|
+
const noWorker = p.online && !(p.sessions ?? []).some((s) => s.role === "worker");
|
|
417
|
+
const est = p.worker || noWorker ? pickupEstimate(p, { now: client.relayNow(), ...(runningRef && client.recentFrom(runningRef) === cfg.member ? { about: { ref: runningRef } } : {}) }) : null;
|
|
387
418
|
const says = est?.kind === "working" && runningRef ? `${p.id}'s agent is working on your request ${runningRef} now` : est?.says;
|
|
388
419
|
const worker = est && est.kind !== "soon" && est.kind !== "offline" ? `; ${says}` : "";
|
|
389
420
|
return reachText(p, head) + worker;
|
|
@@ -408,6 +439,7 @@ export async function runMcp() {
|
|
|
408
439
|
siblingsWarned = true;
|
|
409
440
|
return [
|
|
410
441
|
`you are: ${cfg.member} (${cfg.agent ?? "unknown agent"}, session ${client.session}, role ${role}) space: ${cfg.space} relay: ${client.connected ? "connected" : "OFFLINE"}`,
|
|
442
|
+
behindLine() ?? ``,
|
|
411
443
|
siblings.length
|
|
412
444
|
? `your other sessions: ${siblings.map((s) => `${s.id}[${s.role}]`).join(" ")}${warnSiblings ? " — claim work before doing it, or you will duplicate theirs" : ""}`
|
|
413
445
|
: `your other sessions: none`,
|
|
@@ -906,6 +938,10 @@ A goal for it (${left}) may be open with nothing in it — close it with pantheo
|
|
|
906
938
|
await client.publishProfile(publicProfile).catch(() => { });
|
|
907
939
|
if (mcpActivity)
|
|
908
940
|
activityIdle();
|
|
941
|
+
if (role !== "worker") {
|
|
942
|
+
relayLookAt = Date.now();
|
|
943
|
+
void refreshRelayPkg(cfg.relay).catch(() => null);
|
|
944
|
+
}
|
|
909
945
|
return;
|
|
910
946
|
}
|
|
911
947
|
catch (e) {
|
package/dist/notice.js
CHANGED
|
@@ -249,4 +249,110 @@ export function composeWaiting(items, team, ctx) {
|
|
|
249
249
|
tag: `waiting_${team.replace(/[^A-Za-z0-9_]/g, "_")}`.slice(0, 60),
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
+
export const DECLINE_CODES = ["wake", "wake_ask", "wake_off", "team_wake", "playbook", "capped", "failed", "commands", "not_here", "no_folder", "unavailable", "signed_out", "unsigned"];
|
|
253
|
+
export function declineCodeOf(r) {
|
|
254
|
+
const m = r?.meta;
|
|
255
|
+
if (!r || r.act !== "NOTE" || !m || typeof m.declined !== "string")
|
|
256
|
+
return null;
|
|
257
|
+
return DECLINE_CODES.includes(m.declined) ? m.declined : "general";
|
|
258
|
+
}
|
|
259
|
+
export function declineWords(code, who) {
|
|
260
|
+
switch (code) {
|
|
261
|
+
case "wake_ask": return `${who} is being asked whether you may start work on their computer`;
|
|
262
|
+
case "wake":
|
|
263
|
+
case "wake_off":
|
|
264
|
+
case "team_wake": return `${who}'s computer doesn't start work for you on its own`;
|
|
265
|
+
case "playbook": return `nothing on ${who}'s computer is set up for this kind of request`;
|
|
266
|
+
case "capped": return `${who}'s agent has used its runs for now`;
|
|
267
|
+
case "failed": return `${who}'s agent tried and couldn't finish it`;
|
|
268
|
+
case "commands": return `${who}'s agent needs ${who}'s OK to run commands for it`;
|
|
269
|
+
case "not_here": return `${who}'s computer doesn't have the repo it's about`;
|
|
270
|
+
case "no_folder": return `nothing on ${who}'s computer is linked to this team yet`;
|
|
271
|
+
case "signed_out": return `${who}'s agent is signed out`;
|
|
272
|
+
case "unsigned": return `${who}'s computer couldn't check it came from you — upgrading Pantheon (pantheon upgrade) fixes that`;
|
|
273
|
+
default: return `nothing on ${who}'s computer can take it while ${who} is away`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function quoted(line) {
|
|
277
|
+
return plain(line).replace(/^[a-z0-9._-]+\s+(?:proposed|objected|delivered)\s*:\s*/i, "").replace(/\s*—\s*ACCEPT or OBJECT$/, "").replace(/[\s,;:]+$/, "");
|
|
278
|
+
}
|
|
279
|
+
function andList(xs) {
|
|
280
|
+
return xs.length < 2 ? (xs[0] ?? "") : `${xs.slice(0, -1).join(", ")} and ${xs[xs.length - 1]}`;
|
|
281
|
+
}
|
|
282
|
+
export function composeReplies(items, team, goals, peerOf, ctx) {
|
|
283
|
+
const now = ctx.now ?? Date.now();
|
|
284
|
+
if (items.length === 1) {
|
|
285
|
+
const it = items[0];
|
|
286
|
+
const r = it.act;
|
|
287
|
+
const goal = goals(r.goal);
|
|
288
|
+
if (it.kind === "delivery")
|
|
289
|
+
return composeDelivery(r, goal, peerOf(r.from), ctx);
|
|
290
|
+
if (it.kind === "declined") {
|
|
291
|
+
const what = quoted(it.asked ?? "");
|
|
292
|
+
return {
|
|
293
|
+
kind: "delivery",
|
|
294
|
+
who: whoLine(r.from, undefined, r.ts, now),
|
|
295
|
+
heading: fit(`${r.from}'s agent didn't take your request`, BUDGET.heading),
|
|
296
|
+
context: fit(goal?.title ?? "", BUDGET.context),
|
|
297
|
+
body: fit(`${what ? `"${fit(what, 70)}": ` : ""}${declineWords(it.code ?? "general", r.from)}, so it waits for ${r.from}. If it can't wait, remind ${r.from} or ask someone else.`, BUDGET.body),
|
|
298
|
+
ttl: 30,
|
|
299
|
+
sound: false,
|
|
300
|
+
primary: primaryFor(ctx.tools, ctx.preferred, `A teammate's machine handed my Pantheon request back to them (act ${r.ref ?? r.id}). Call pantheon_status, tell me in plain words what is waiting and why, then give me numbered next steps (wait, remind ${r.from}, ask someone else, or withdraw it). Do not act until I choose.`),
|
|
301
|
+
details: { act: r.id },
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const said = enrich(r.summary ?? "", r.body, BUDGET.body);
|
|
305
|
+
return {
|
|
306
|
+
kind: "delivery",
|
|
307
|
+
who: whoLine(r.from, peerOf(r.from)?.agent, r.ts, now),
|
|
308
|
+
heading: fit(`${r.from} answered you`, BUDGET.heading),
|
|
309
|
+
context: fit(goal?.title ?? "", BUDGET.context),
|
|
310
|
+
body: fit(said || "Open it to read the answer.", BUDGET.body),
|
|
311
|
+
ttl: 30,
|
|
312
|
+
sound: false,
|
|
313
|
+
primary: primaryFor(ctx.tools, ctx.preferred, `A teammate answered my Pantheon request (act ${r.id}). Read it and the thread it belongs to, tell me in plain words what it says and whether anything is now mine to do. Do not act until I choose.`),
|
|
314
|
+
details: { act: r.id },
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const said = [];
|
|
318
|
+
for (const kind of ["answer", "delivery", "declined"]) {
|
|
319
|
+
const who = [...new Set(items.filter((i) => i.kind === kind).map((i) => i.act.from))];
|
|
320
|
+
if (!who.length)
|
|
321
|
+
continue;
|
|
322
|
+
said.push(kind === "answer" ? `${andList(who)} answered` : kind === "delivery" ? `${andList(who)} delivered`
|
|
323
|
+
: `${andList(who.map((w) => `${w}'s agent`))} handed ${who.length === 1 && items.filter((i) => i.kind === kind).length === 1 ? "one" : "some"} back`);
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
kind: "delivery",
|
|
327
|
+
who: team,
|
|
328
|
+
heading: fit(`${items.length} replies to your requests`, BUDGET.heading),
|
|
329
|
+
context: "",
|
|
330
|
+
body: fit(`${said.join("; ")}. Open your agent to go through them.`, BUDGET.body),
|
|
331
|
+
ttl: 30,
|
|
332
|
+
sound: false,
|
|
333
|
+
primary: primaryFor(ctx.tools, ctx.preferred, "Teammates replied to my requests in Pantheon. Call pantheon_status and pantheon_history, tell me in plain words what each reply says and what, if anything, is now mine to do. Do not act until I choose."),
|
|
334
|
+
tag: `replies_${team.replace(/[^A-Za-z0-9_]/g, "_")}`.slice(0, 60),
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
export function composeUnpicked(items, team, ctx) {
|
|
338
|
+
const prompt = "Some of my requests in Pantheon haven't been picked up. Call pantheon_status, tell me which are waiting, on whom and why, then give me numbered next steps (wait, remind them, ask someone else, or withdraw it). Do not act until I choose.";
|
|
339
|
+
const base = { kind: "delivery", who: team, context: "", ttl: 30, sound: false, primary: primaryFor(ctx.tools, ctx.preferred, prompt), tag: `unpicked_${team.replace(/[^A-Za-z0-9_]/g, "_")}`.slice(0, 60) };
|
|
340
|
+
if (items.length === 1) {
|
|
341
|
+
const it = items[0];
|
|
342
|
+
const who = andList(it.owners);
|
|
343
|
+
const what = quoted(it.what);
|
|
344
|
+
const one = it.owners.length === 1;
|
|
345
|
+
return {
|
|
346
|
+
...base,
|
|
347
|
+
heading: fit(one ? `${who} hasn't picked up your request` : "Nobody has picked up your request", BUDGET.heading),
|
|
348
|
+
body: fit(`${what ? `"${fit(what, 60)}", asked ${one ? "" : `of ${who} `}over an hour ago. ` : `Asked ${one ? "" : `of ${who} `}over an hour ago. `}${it.why ? `${it.why[0].toUpperCase()}${it.why.slice(1)}. ` : ""}You can remind ${one ? it.owners[0] : "them"} or ask someone else.`, BUDGET.body),
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
const owners = [...new Set(items.flatMap((i) => i.owners))];
|
|
352
|
+
return {
|
|
353
|
+
...base,
|
|
354
|
+
heading: fit(`${items.length} of your requests are still waiting`, BUDGET.heading),
|
|
355
|
+
body: fit(`Nobody has picked them up in over an hour: ${andList(owners)}. You can remind ${owners.length === 1 ? owners[0] : "them"} or ask someone else.`, BUDGET.body),
|
|
356
|
+
};
|
|
357
|
+
}
|
|
252
358
|
//# sourceMappingURL=notice.js.map
|