@join-pantheon/cli 0.34.0 → 0.34.1
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 +179 -0
- package/dist/admin-pages.js +249 -116
- package/dist/admin-ui.js +149 -73
- package/dist/board.js +30 -3
- package/dist/claude-confine.js +3 -2
- package/dist/cli.js +75 -5
- package/dist/client.js +31 -3
- package/dist/config.js +21 -0
- package/dist/conn-report.js +148 -0
- package/dist/doctor.js +13 -0
- package/dist/flow-stats.js +21 -18
- package/dist/founder-stats.js +203 -0
- package/dist/goal-flow.js +218 -0
- package/dist/home-safety.js +2 -0
- package/dist/machine.js +95 -2
- package/dist/mcp.js +6 -0
- package/dist/notifier.js +166 -101
- package/dist/power.js +66 -0
- package/dist/readiness-alert.js +16 -3
- package/dist/relay.js +303 -23
- package/dist/spend.js +24 -1
- package/dist/status-engine.js +222 -0
- package/dist/status-nudge.js +34 -0
- package/dist/tray.js +57 -7
- package/dist/viewer-pages.js +36 -29
- package/dist/win-host.js +79 -7
- package/dist/worker.js +17 -8
- package/helper/macos/main.swift +45 -12
- package/helper/macos/menubar.swift +409 -67
- package/helper/macos/prebuilt/manifest.json +6 -6
- package/helper/macos/prebuilt/pantheon-hud +0 -0
- package/helper/macos/prebuilt/pantheon-tray +0 -0
- package/helper/windows/pantheon-tray.ps1 +216 -15
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1820,7 +1820,8 @@ const EXTRA_FLAGS = "--action-id --agent-cmd --approve-all --ask-before-sending
|
|
|
1820
1820
|
"--no-browser --no-continue --no-guide --no-notify --only-action --path --peek --poll --portable --publish --queued --quiet --remind --scratch --serve --session --silent --surface --token --unattended " +
|
|
1821
1821
|
"--until --user --version --all --json " +
|
|
1822
1822
|
"--name --title --wake --commands --unsandboxed --alerts --decides --playbook --base --responsibilities --human-required --agent-can-decide --capabilities" +
|
|
1823
|
-
" --keep-tray-quit --direct"
|
|
1823
|
+
" --keep-tray-quit --direct" +
|
|
1824
|
+
" --headless";
|
|
1824
1825
|
const KNOWN_FLAGS = new Set([...`${Object.values(COMMAND_FLAGS).join(" ")} ${EXTRA_FLAGS}`.matchAll(/--([a-z][a-z0-9-]*)/g)].map((m) => m[1]));
|
|
1825
1826
|
function refuseUnknownFlags() {
|
|
1826
1827
|
if (["mcp", "hook", "tray-status", "_menubar", "handle-uri"].includes(cmd))
|
|
@@ -2997,13 +2998,13 @@ async function main() {
|
|
|
2997
2998
|
}
|
|
2998
2999
|
}
|
|
2999
3000
|
if (worker.running) {
|
|
3000
|
-
console.log(` worker ${C("running")} ${runBy(worker)} pid ${worker.pid}`);
|
|
3001
3001
|
const problem = (() => { try {
|
|
3002
3002
|
return agentProblem(CONFIG_DIR);
|
|
3003
3003
|
}
|
|
3004
3004
|
catch {
|
|
3005
3005
|
return null;
|
|
3006
3006
|
} })();
|
|
3007
|
+
console.log(` worker ${problem ? "\x1b[33mrunning, but stuck\x1b[0m" : C("running")} ${runBy(worker)} pid ${worker.pid}`);
|
|
3007
3008
|
if (problem)
|
|
3008
3009
|
console.log(` \x1b[33m${PROBLEM_LEAD.toLowerCase()}: ${problem}\x1b[0m`);
|
|
3009
3010
|
else
|
|
@@ -6130,19 +6131,84 @@ async function main() {
|
|
|
6130
6131
|
die(e.message);
|
|
6131
6132
|
}
|
|
6132
6133
|
const pantheon = (await import("./service.js")).whichPantheon() ?? process.argv[1];
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
const
|
|
6134
|
+
const headless = argv.includes("--headless");
|
|
6135
|
+
console.error(`${B("pantheon menu bar")} ${D(headless ? "(headless: no menu bar item; ctrl-c here)" : "(quit from the menu, or ctrl-c here)")}`);
|
|
6136
|
+
const { attachHelper, StatusEngine, watchNudges } = await import("./status-engine.js");
|
|
6137
|
+
const { machineTrayStatus, useRunningProbe } = await import("./tray.js");
|
|
6138
|
+
const { runningProbe } = await import("./machine.js");
|
|
6139
|
+
const { powerNow } = await import("./power.js");
|
|
6140
|
+
const { statusDir } = await import("./status-nudge.js");
|
|
6141
|
+
useRunningProbe(runningProbe());
|
|
6142
|
+
const poll = flag("poll", "15");
|
|
6143
|
+
const child = spawn(binary, headless ? ["headless", pantheon, poll] : [pantheon, poll], { stdio: ["pipe", "pipe", "inherit"] });
|
|
6144
|
+
const say = (line) => { try {
|
|
6145
|
+
process.stdout.write(`${line}\n`);
|
|
6146
|
+
}
|
|
6147
|
+
catch { } };
|
|
6148
|
+
const engine = attachHelper({
|
|
6149
|
+
stdin: child.stdin, stdout: child.stdout, passLine: say,
|
|
6150
|
+
engine: (write) => new StatusEngine({
|
|
6151
|
+
compute: machineTrayStatus,
|
|
6152
|
+
write, now: () => Date.now(),
|
|
6153
|
+
setTimer: (fn, ms) => { const t = setTimeout(fn, ms); t.unref?.(); return t; },
|
|
6154
|
+
clearTimer: (t) => clearTimeout(t),
|
|
6155
|
+
log: (line) => say(`pantheon menu bar: ${line}`),
|
|
6156
|
+
power: () => powerNow(),
|
|
6157
|
+
}),
|
|
6158
|
+
});
|
|
6159
|
+
const unwatch = watchNudges({ home: CONFIG_DIR, statusDir: statusDir(), onNudge: () => engine.nudge(), log: (l) => say(`pantheon menu bar: ${l}`), mkdir: (d) => mkdirSync(d, { recursive: true }) });
|
|
6160
|
+
const pkgJson = join(dirname((await import("node:url")).fileURLToPath(import.meta.url)), "..", "package.json");
|
|
6161
|
+
const versionTimer = setInterval(() => {
|
|
6162
|
+
try {
|
|
6163
|
+
const v = JSON.parse(readFileSync(pkgJson, "utf8")).version;
|
|
6164
|
+
if (v && VERSION !== "unknown" && v !== VERSION) {
|
|
6165
|
+
say(`pantheon menu bar: version ${v} is on disk (running ${VERSION}) — restarting`);
|
|
6166
|
+
engine.stop();
|
|
6167
|
+
child.kill();
|
|
6168
|
+
process.exit(0);
|
|
6169
|
+
}
|
|
6170
|
+
}
|
|
6171
|
+
catch { }
|
|
6172
|
+
}, 30_000);
|
|
6173
|
+
versionTimer.unref();
|
|
6174
|
+
const bye = () => { engine.stop(); unwatch(); child.kill(); process.exit(0); };
|
|
6136
6175
|
process.on("SIGINT", bye);
|
|
6137
6176
|
process.on("SIGTERM", bye);
|
|
6138
6177
|
await new Promise((r) => child.on("close", () => r()));
|
|
6178
|
+
engine.stop();
|
|
6179
|
+
unwatch();
|
|
6180
|
+
clearInterval(versionTimer);
|
|
6139
6181
|
return;
|
|
6140
6182
|
}
|
|
6141
6183
|
case "host": {
|
|
6142
6184
|
const { runHost, provenOrphan } = await import("./win-host.js");
|
|
6143
6185
|
const { childNodeFlags, managedLauncher } = await import("./managed.js");
|
|
6186
|
+
const { attachHelper, StatusEngine, watchNudges } = await import("./status-engine.js");
|
|
6187
|
+
const { machineTrayStatus, useRunningProbe } = await import("./tray.js");
|
|
6188
|
+
const { runningProbe } = await import("./machine.js");
|
|
6189
|
+
const { powerNow } = await import("./power.js");
|
|
6190
|
+
const { statusDir } = await import("./status-nudge.js");
|
|
6191
|
+
useRunningProbe(runningProbe());
|
|
6192
|
+
let engine = null;
|
|
6193
|
+
watchNudges({ home: CONFIG_DIR, statusDir: statusDir(), onNudge: () => engine?.nudge(), mkdir: (d) => mkdirSync(d, { recursive: true }) });
|
|
6144
6194
|
const layout = managedLayout();
|
|
6145
6195
|
runHost({
|
|
6196
|
+
trayPipe: (proc, log) => {
|
|
6197
|
+
engine?.stop();
|
|
6198
|
+
const mine = attachHelper({
|
|
6199
|
+
stdin: proc.stdin, stdout: proc.stdout, passLine: log,
|
|
6200
|
+
engine: (write) => new StatusEngine({
|
|
6201
|
+
compute: machineTrayStatus, write, now: () => Date.now(),
|
|
6202
|
+
setTimer: (fn, ms) => { const t = setTimeout(fn, ms); t.unref?.(); return t; },
|
|
6203
|
+
clearTimer: (t) => clearTimeout(t),
|
|
6204
|
+
log: (line) => log(`${new Date().toISOString()} host: ${line}`),
|
|
6205
|
+
power: () => powerNow(),
|
|
6206
|
+
}),
|
|
6207
|
+
});
|
|
6208
|
+
engine = mine;
|
|
6209
|
+
return () => { mine.stop(); if (engine === mine)
|
|
6210
|
+
engine = null; };
|
|
6211
|
+
},
|
|
6146
6212
|
node: process.execPath,
|
|
6147
6213
|
flags: childNodeFlags(),
|
|
6148
6214
|
managed: layout ? { pkgDir: layout.pkgDir, prevDir: layout.prevDir } : null,
|
|
@@ -6161,6 +6227,10 @@ async function main() {
|
|
|
6161
6227
|
log: (line) => console.error(cfgs.length > 1 ? `[${c.space}] ${line}` : line),
|
|
6162
6228
|
}));
|
|
6163
6229
|
console.error(`${B("pantheon notifier")} ${D(`(${cfgs.length === 1 ? "" : cfgs.length + " teams · "}ctrl-c to stop)`)}`);
|
|
6230
|
+
{
|
|
6231
|
+
const m = await import("./machine.js");
|
|
6232
|
+
m.recordWorkerPid(m.notifierPidFile());
|
|
6233
|
+
}
|
|
6164
6234
|
if (process.platform === "win32") {
|
|
6165
6235
|
try {
|
|
6166
6236
|
const { ensureUriHandler } = await import("./notice-windows.js");
|
package/dist/client.js
CHANGED
|
@@ -36,6 +36,9 @@ export class PantheonClient {
|
|
|
36
36
|
cid = 0;
|
|
37
37
|
static REFUSED_RETRY_MS = 5 * 60_000;
|
|
38
38
|
static REFUSED_GRACE_MS = 2 * 60_000;
|
|
39
|
+
static SILENT_MS = 45_000;
|
|
40
|
+
static WELCOME_MS = 30_000;
|
|
41
|
+
static WELCOME_QUIET_MS = 25_000;
|
|
39
42
|
static REMOVED_CHECK_MS = REMOVED_CHECK_MS;
|
|
40
43
|
get refused() { return this.connected ? null : this.refusedCode; }
|
|
41
44
|
refusedCode = null;
|
|
@@ -49,6 +52,11 @@ export class PantheonClient {
|
|
|
49
52
|
roster = [];
|
|
50
53
|
goals = new Map();
|
|
51
54
|
obligations = [];
|
|
55
|
+
onChange = null;
|
|
56
|
+
changed() { try {
|
|
57
|
+
this.onChange?.();
|
|
58
|
+
}
|
|
59
|
+
catch { } }
|
|
52
60
|
profiles = new Map();
|
|
53
61
|
members = [];
|
|
54
62
|
connected = false;
|
|
@@ -199,16 +207,32 @@ export class PantheonClient {
|
|
|
199
207
|
this.lastInbound = Date.now();
|
|
200
208
|
ws.on("ping", () => { this.lastInbound = Date.now(); });
|
|
201
209
|
ws.on("pong", () => { this.lastInbound = Date.now(); });
|
|
210
|
+
let openedAt = 0;
|
|
211
|
+
ws.on("open", () => {
|
|
212
|
+
openedAt = Date.now();
|
|
213
|
+
this.lastInbound = openedAt;
|
|
214
|
+
const sock = ws._socket;
|
|
215
|
+
try {
|
|
216
|
+
sock?.on?.("data", () => { this.lastInbound = Date.now(); });
|
|
217
|
+
}
|
|
218
|
+
catch { }
|
|
219
|
+
});
|
|
220
|
+
let welcomed = false;
|
|
202
221
|
this.watchdog = setInterval(() => {
|
|
203
|
-
if (this.ws
|
|
222
|
+
if (this.ws !== ws)
|
|
223
|
+
return;
|
|
224
|
+
const quiet = Date.now() - this.lastInbound;
|
|
225
|
+
const stalled = !welcomed && openedAt > 0 && Date.now() - openedAt >= PantheonClient.WELCOME_MS && quiet >= PantheonClient.WELCOME_QUIET_MS;
|
|
226
|
+
if (quiet > PantheonClient.SILENT_MS || stalled) {
|
|
227
|
+
if (!welcomed)
|
|
228
|
+
this.lastError = stalled ? `no welcome from the relay, and nothing from it for ${Math.round(quiet / 1000)} s` : "the relay went silent during the handshake";
|
|
204
229
|
try {
|
|
205
230
|
ws.terminate();
|
|
206
231
|
}
|
|
207
232
|
catch { }
|
|
208
233
|
}
|
|
209
|
-
}, 5_000);
|
|
234
|
+
}, Math.min(5_000, Math.max(50, Math.floor(PantheonClient.WELCOME_QUIET_MS / 5))));
|
|
210
235
|
this.watchdog.unref?.();
|
|
211
|
-
ws.on("open", () => { });
|
|
212
236
|
ws.on("message", (raw) => {
|
|
213
237
|
if (this.disposed)
|
|
214
238
|
return;
|
|
@@ -281,6 +305,7 @@ export class PantheonClient {
|
|
|
281
305
|
break;
|
|
282
306
|
}
|
|
283
307
|
this.connected = true;
|
|
308
|
+
welcomed = true;
|
|
284
309
|
this.pending = null;
|
|
285
310
|
this.refusedCode = null;
|
|
286
311
|
this.removal = null;
|
|
@@ -348,6 +373,7 @@ export class PantheonClient {
|
|
|
348
373
|
settled = true;
|
|
349
374
|
resolve();
|
|
350
375
|
}
|
|
376
|
+
this.changed();
|
|
351
377
|
break;
|
|
352
378
|
case "token":
|
|
353
379
|
if (typeof msg.token === "string" && msg.token) {
|
|
@@ -388,6 +414,7 @@ export class PantheonClient {
|
|
|
388
414
|
break;
|
|
389
415
|
case "obligations":
|
|
390
416
|
this.obligations = msg.list;
|
|
417
|
+
this.changed();
|
|
391
418
|
break;
|
|
392
419
|
case "goal":
|
|
393
420
|
this.goals.set(msg.goal.id, msg.goal);
|
|
@@ -459,6 +486,7 @@ export class PantheonClient {
|
|
|
459
486
|
this.ws = null;
|
|
460
487
|
if (this.closed)
|
|
461
488
|
return;
|
|
489
|
+
this.changed();
|
|
462
490
|
if (!settled) {
|
|
463
491
|
settled = true;
|
|
464
492
|
if (!this.everConnected) {
|
package/dist/config.js
CHANGED
|
@@ -64,6 +64,16 @@ function sameRepo(host, path) {
|
|
|
64
64
|
return [host, path];
|
|
65
65
|
}
|
|
66
66
|
const repoCache = new Map();
|
|
67
|
+
const notRepo = new Map();
|
|
68
|
+
export const NOT_A_REPO_TTL_MS = 60_000;
|
|
69
|
+
const gitAbove = (dir) => {
|
|
70
|
+
for (let d = dir;; d = resolve(d, "..")) {
|
|
71
|
+
if (existsSync(join(d, ".git")))
|
|
72
|
+
return true;
|
|
73
|
+
if (resolve(d, "..") === d)
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
67
77
|
const gitUnanswered = new Set();
|
|
68
78
|
export function repoUnknown(dir = process.cwd()) {
|
|
69
79
|
const key = resolve(dir);
|
|
@@ -80,6 +90,12 @@ export function repoInfo(dir = process.cwd()) {
|
|
|
80
90
|
const key = resolve(dir);
|
|
81
91
|
if (repoCache.has(key))
|
|
82
92
|
return repoCache.get(key);
|
|
93
|
+
const said = notRepo.get(key);
|
|
94
|
+
if (said !== undefined) {
|
|
95
|
+
if (Date.now() - said < NOT_A_REPO_TTL_MS && !gitAbove(key))
|
|
96
|
+
return null;
|
|
97
|
+
notRepo.delete(key);
|
|
98
|
+
}
|
|
83
99
|
let info = null;
|
|
84
100
|
try {
|
|
85
101
|
let root;
|
|
@@ -89,6 +105,11 @@ export function repoInfo(dir = process.cwd()) {
|
|
|
89
105
|
catch (e) {
|
|
90
106
|
if (e.status !== 128)
|
|
91
107
|
gitUnanswered.add(key);
|
|
108
|
+
else {
|
|
109
|
+
if (notRepo.size > 200)
|
|
110
|
+
notRepo.clear();
|
|
111
|
+
notRepo.set(key, Date.now());
|
|
112
|
+
}
|
|
92
113
|
throw e;
|
|
93
114
|
}
|
|
94
115
|
gitUnanswered.delete(key);
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, join } from "node:path";
|
|
4
|
+
import { CONFIG_DIR } from "./config.js";
|
|
5
|
+
import { statusDir, statusNudge } from "./status-nudge.js";
|
|
6
|
+
export const STUCK_AFTER_MS = 2 * 60_000;
|
|
7
|
+
export const CONN_BEAT_MS = 5 * 60_000;
|
|
8
|
+
export const CONN_FRESH_MS = 15 * 60_000;
|
|
9
|
+
const sha8 = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
|
|
10
|
+
export const connFile = (home, role, pid, space) => join(statusDir(home), `conn-${role}-${pid}-${sha8(space)}.json`);
|
|
11
|
+
export class ConnectionReport {
|
|
12
|
+
o;
|
|
13
|
+
state = null;
|
|
14
|
+
since = null;
|
|
15
|
+
file;
|
|
16
|
+
beat = null;
|
|
17
|
+
closed = false;
|
|
18
|
+
onExit;
|
|
19
|
+
constructor(o) {
|
|
20
|
+
this.o = o;
|
|
21
|
+
this.file = connFile(o.home ?? CONFIG_DIR, o.role, o.pid ?? process.pid, o.space);
|
|
22
|
+
const file = this.file;
|
|
23
|
+
this.onExit = () => { try {
|
|
24
|
+
rmSync(file, { force: true });
|
|
25
|
+
}
|
|
26
|
+
catch { } };
|
|
27
|
+
process.once("exit", this.onExit);
|
|
28
|
+
}
|
|
29
|
+
observe(state) {
|
|
30
|
+
if (this.closed || state === this.state)
|
|
31
|
+
return;
|
|
32
|
+
const now = (this.o.now ?? Date.now)();
|
|
33
|
+
if (state === "down")
|
|
34
|
+
this.since ??= now;
|
|
35
|
+
else
|
|
36
|
+
this.since = null;
|
|
37
|
+
this.state = state;
|
|
38
|
+
this.write(now);
|
|
39
|
+
(this.o.nudge ?? statusNudge)(this.o.home ?? CONFIG_DIR);
|
|
40
|
+
if (!this.beat) {
|
|
41
|
+
this.beat = setInterval(() => { if (this.state)
|
|
42
|
+
this.write((this.o.now ?? Date.now)()); }, this.o.beatMs ?? CONN_BEAT_MS);
|
|
43
|
+
this.beat.unref?.();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
close() {
|
|
47
|
+
this.closed = true;
|
|
48
|
+
process.removeListener("exit", this.onExit);
|
|
49
|
+
if (this.beat) {
|
|
50
|
+
clearInterval(this.beat);
|
|
51
|
+
this.beat = null;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
rmSync(this.file, { force: true });
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
}
|
|
58
|
+
write(now) {
|
|
59
|
+
const state = this.state;
|
|
60
|
+
const rec = {
|
|
61
|
+
pid: this.o.pid ?? process.pid, role: this.o.role, space: this.o.space,
|
|
62
|
+
...(this.o.agent ? { agent: this.o.agent } : {}), ...(this.o.folder ? { folder: this.o.folder } : {}),
|
|
63
|
+
connected: state !== "down", ...(state === "down" && this.since !== null ? { since: this.since } : {}), at: now,
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
mkdirSync(statusDir(this.o.home ?? CONFIG_DIR), { recursive: true });
|
|
67
|
+
const tmp = `${this.file}.${process.pid}.tmp`;
|
|
68
|
+
writeFileSync(tmp, JSON.stringify(rec) + "\n");
|
|
69
|
+
renameSync(tmp, this.file);
|
|
70
|
+
}
|
|
71
|
+
catch { }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export function agentLabelFor(id) {
|
|
75
|
+
if (!id)
|
|
76
|
+
return undefined;
|
|
77
|
+
const known = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor", copilot: "Copilot", kiro: "Kiro" };
|
|
78
|
+
return known[id] ?? id.slice(0, 40);
|
|
79
|
+
}
|
|
80
|
+
export function clientState(c) {
|
|
81
|
+
if (c.connected)
|
|
82
|
+
return "up";
|
|
83
|
+
if (c.pending || c.refused || c.removedFrom)
|
|
84
|
+
return "quiet";
|
|
85
|
+
return "down";
|
|
86
|
+
}
|
|
87
|
+
const minutes = (ms) => { const m = Math.round(ms / 60_000); return m < 60 ? `${m} min` : `${Math.round(m / 60)} h`; };
|
|
88
|
+
export function describeStuck(r, now) {
|
|
89
|
+
const what = r.role === "worker" ? "Your worker" : r.role === "notifier" ? "Your alerts (the notifier)" : `${r.agent || "An agent"} window${r.folder ? ` in ${r.folder}` : ""}`;
|
|
90
|
+
const fix = r.role === "worker" ? "pantheon service restart worker"
|
|
91
|
+
: r.role === "notifier" ? "pantheon service restart notifier"
|
|
92
|
+
: "reopen that window (in Claude Code: /mcp, then reconnect pantheon)";
|
|
93
|
+
const since = r.since ?? r.at;
|
|
94
|
+
return { role: r.role, pid: r.pid, space: r.space, since, what, fix, line: `${what} ${r.role === "notifier" ? "have" : "has"} had no relay connection for ${minutes(now - since)} — ${fix}` };
|
|
95
|
+
}
|
|
96
|
+
export function stuckConnections(o) {
|
|
97
|
+
const dir = statusDir(o.home ?? CONFIG_DIR);
|
|
98
|
+
const now = o.now ?? Date.now();
|
|
99
|
+
const alive = o.alive ?? ((pid) => { if (pid <= 1)
|
|
100
|
+
return false; try {
|
|
101
|
+
process.kill(pid, 0);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
} });
|
|
107
|
+
const isRole = o.isRole;
|
|
108
|
+
let names;
|
|
109
|
+
try {
|
|
110
|
+
names = readdirSync(dir).filter((n) => /^conn-(mcp|notifier|worker)-\d+-[0-9a-f]{8}\.json$/.test(n)).slice(0, 200);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
const out = [];
|
|
116
|
+
for (const n of names) {
|
|
117
|
+
let r;
|
|
118
|
+
try {
|
|
119
|
+
r = JSON.parse(readFileSync(join(dir, n), "utf8"));
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (!r || !Number.isInteger(r.pid) || r.pid <= 0 || !["mcp", "notifier", "worker"].includes(r.role))
|
|
125
|
+
continue;
|
|
126
|
+
if (!alive(r.pid) || !(typeof r.at === "number" && now - r.at <= CONN_FRESH_MS)) {
|
|
127
|
+
try {
|
|
128
|
+
rmSync(join(dir, n), { force: true });
|
|
129
|
+
}
|
|
130
|
+
catch { }
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (r.connected || typeof r.since !== "number" || now - r.since < (o.afterMs ?? STUCK_AFTER_MS))
|
|
134
|
+
continue;
|
|
135
|
+
if (!isRole(r.pid, r.role))
|
|
136
|
+
continue;
|
|
137
|
+
const clean = (s, max) => (typeof s === "string" ? s.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, " ").trim().slice(0, max) : undefined);
|
|
138
|
+
const agent = clean(r.agent, 40), folder = clean(r.folder ? basename(r.folder) : undefined, 60);
|
|
139
|
+
const rec = { pid: r.pid, role: r.role, space: clean(r.space, 80) ?? "", connected: false, since: r.since, at: Number(r.at) || r.since };
|
|
140
|
+
if (agent)
|
|
141
|
+
rec.agent = agent;
|
|
142
|
+
if (folder)
|
|
143
|
+
rec.folder = folder;
|
|
144
|
+
out.push(describeStuck(rec, now));
|
|
145
|
+
}
|
|
146
|
+
return out.sort((a, b) => a.since - b.since);
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=conn-report.js.map
|
package/dist/doctor.js
CHANGED
|
@@ -217,6 +217,19 @@ export async function doctor(projectDir) {
|
|
|
217
217
|
else {
|
|
218
218
|
add("pass", "machine", `${platformName(host.platform)}${host.desktop ? (host.platform === "linux" ? " — desktop alerts can run here (the menu bar is macOS-only; pantheon board is the view)" : " — menu bar and desktop alerts can run here") : " — no menu bar or desktop alerts here yet; ask your agent for pantheon_status, or run pantheon brief, to see what needs you"}`, undefined, `${host.platform}${host.desktop ? ", desktop" : ""}`);
|
|
219
219
|
}
|
|
220
|
+
{
|
|
221
|
+
const { stuckConnections } = await import("./conn-report.js");
|
|
222
|
+
const { isPantheonRole } = await import("./machine.js");
|
|
223
|
+
const stuck = (() => { try {
|
|
224
|
+
return stuckConnections({ isRole: isPantheonRole });
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
return [];
|
|
228
|
+
} })();
|
|
229
|
+
if (stuck.length) {
|
|
230
|
+
add("warn", "connections", stuck.map((x) => x.line).join("; "), "if the relay answers (the relay check below), these are stuck, not waiting out an outage: restart each as said. If the relay is down, they come back by themselves once it is up.", `${stuck.length} process${stuck.length === 1 ? "" : "es"} without the relay for over 2 min (${[...new Set(stuck.map((x) => x.role))].join(", ")})`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
220
233
|
let cfg = null;
|
|
221
234
|
try {
|
|
222
235
|
cfg = load() ?? (() => { const f = loadAll(); const m = Object.values(f?.spaces ?? {})[0]; return f && m ? configFor(f, m, null) : null; })();
|
package/dist/flow-stats.js
CHANGED
|
@@ -80,6 +80,22 @@ function addToIndex(idx, r) {
|
|
|
80
80
|
idx.kids.set(r.ref, [r]);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
export function answerIn(ix, id, who) {
|
|
84
|
+
let best = null;
|
|
85
|
+
for (const k of ix.kids.get(id) ?? [])
|
|
86
|
+
if (k.act === "ANSWER" && (!who || k.from === who) && (!best || k.ts < best.ts))
|
|
87
|
+
best = k;
|
|
88
|
+
return best;
|
|
89
|
+
}
|
|
90
|
+
export function settleIn(ix, id, who) {
|
|
91
|
+
const ask = ix.byId.get(id);
|
|
92
|
+
const askedOf = who ? [who] : ask?.to ?? [];
|
|
93
|
+
let best = null;
|
|
94
|
+
for (const k of ix.allKids.get(id) ?? [])
|
|
95
|
+
if ((k.act === "ANSWER" || k.act === "DELIVERED") && askedOf.includes(k.from) && (!best || k.ts < best.ts))
|
|
96
|
+
best = k;
|
|
97
|
+
return best;
|
|
98
|
+
}
|
|
83
99
|
export const median = (xs) => {
|
|
84
100
|
if (!xs.length)
|
|
85
101
|
return null;
|
|
@@ -87,7 +103,7 @@ export const median = (xs) => {
|
|
|
87
103
|
const m = Math.floor(s.length / 2);
|
|
88
104
|
return s.length % 2 ? s[m] : Math.round((s[m - 1] + s[m]) / 2);
|
|
89
105
|
};
|
|
90
|
-
export const utcDay = (ts) => new Date(ts).toISOString().slice(0, 10);
|
|
106
|
+
export const utcDay = (ts) => (Number.isFinite(ts) && Math.abs(ts) <= 8.64e15 ? new Date(ts).toISOString().slice(0, 10) : "invalid");
|
|
91
107
|
export const rangeStart = (now, days) => {
|
|
92
108
|
const d = new Date(now);
|
|
93
109
|
d.setUTCHours(0, 0, 0, 0);
|
|
@@ -123,7 +139,8 @@ function* flowSteps(input) {
|
|
|
123
139
|
const now = input.now ?? Date.now();
|
|
124
140
|
const days = Math.max(1, Math.floor(input.days));
|
|
125
141
|
const since = now - days * DAY_MS;
|
|
126
|
-
const
|
|
142
|
+
const ix = input.index ?? flowIndex(input.records);
|
|
143
|
+
const { retracted, recs, allKids, byId, kids } = ix;
|
|
127
144
|
const goalOf = new Map(input.goals.map((g) => [g.id, g]));
|
|
128
145
|
const claimsByRef = new Map();
|
|
129
146
|
for (const c of input.firstClaims ?? []) {
|
|
@@ -140,22 +157,8 @@ function* flowSteps(input) {
|
|
|
140
157
|
best = k;
|
|
141
158
|
return best;
|
|
142
159
|
};
|
|
143
|
-
const answerOf = (id, who) =>
|
|
144
|
-
|
|
145
|
-
for (const k of kids.get(id) ?? [])
|
|
146
|
-
if (k.act === "ANSWER" && (!who || k.from === who) && (!best || k.ts < best.ts))
|
|
147
|
-
best = k;
|
|
148
|
-
return best;
|
|
149
|
-
};
|
|
150
|
-
const settleOf = (id, who) => {
|
|
151
|
-
const ask = byId.get(id);
|
|
152
|
-
const askedOf = who ? [who] : ask?.to ?? [];
|
|
153
|
-
let best = null;
|
|
154
|
-
for (const k of allKids.get(id) ?? [])
|
|
155
|
-
if ((k.act === "ANSWER" || k.act === "DELIVERED") && askedOf.includes(k.from) && (!best || k.ts < best.ts))
|
|
156
|
-
best = k;
|
|
157
|
-
return best;
|
|
158
|
-
};
|
|
160
|
+
const answerOf = (id, who) => answerIn(ix, id, who);
|
|
161
|
+
const settleOf = (id, who) => settleIn(ix, id, who);
|
|
159
162
|
const withdrawnOf = (id, who) => {
|
|
160
163
|
const ask = byId.get(id);
|
|
161
164
|
for (const w of kids.get(id) ?? []) {
|