@join-pantheon/cli 0.37.3 → 0.38.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/README.md +10 -2
- package/dist/admin-founder.js +5 -2
- package/dist/admin-pages.js +29 -2
- package/dist/agent-check.js +9 -0
- package/dist/agents.js +8 -1
- package/dist/claude-confine.js +1 -0
- package/dist/cli.js +368 -43
- 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 +52 -6
- package/dist/notice.js +107 -0
- package/dist/notifier.js +206 -16
- package/dist/notify.js +14 -2
- package/dist/onboard-copy.js +3 -0
- package/dist/pending.js +11 -3
- package/dist/pickup.js +11 -3
- package/dist/quickstart.js +41 -21
- package/dist/relay.js +59 -7
- package/dist/service.js +5 -0
- package/dist/setup-changes.js +13 -0
- package/dist/setup-guide.js +25 -4
- package/dist/spend.js +12 -0
- 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 +105 -3
- package/dist/worker.js +274 -37
- package/helper/macos/prebuilt/manifest.json +2 -2
- package/helper/macos/prebuilt/pantheon-hud +0 -0
- package/npm-shrinkwrap.json +13 -2
- package/package.json +2 -1
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { readStateText, withFileLock } from "./file-lock.js";
|
|
4
|
+
import { atomicWrite } from "./worker-policy.js";
|
|
5
|
+
import { BUDGET } from "./notice.js";
|
|
6
|
+
export const WATCHED = ["worker", "notifier"];
|
|
7
|
+
export const LOOP_WINDOW_MS = 10 * 60_000;
|
|
8
|
+
export const LOOP_STARTS = 3;
|
|
9
|
+
export const HEALTHY_AFTER_CONNECT_MS = 60_000;
|
|
10
|
+
export const STEADY_AFTER_MS = 10 * 60_000;
|
|
11
|
+
export const LOOP_STALE_MS = 60 * 60_000;
|
|
12
|
+
export const EXPECTED_EXIT_CODES = [0, 129, 130, 143];
|
|
13
|
+
export const startsPath = (home) => join(home ?? process.env.PANTHEON_HOME ?? join(homedir(), ".pantheon"), "service-starts.json");
|
|
14
|
+
const isTime = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
15
|
+
const episode = (v) => {
|
|
16
|
+
const e = v;
|
|
17
|
+
if (!e || !isTime(e.since) || !isTime(e.last) || typeof e.starts !== "number" || e.starts < 0)
|
|
18
|
+
return undefined;
|
|
19
|
+
return { since: e.since, starts: Math.min(Math.floor(e.starts), 1e6), last: e.last, ...(isTime(e.alerted_at) ? { alerted_at: e.alerted_at } : {}) };
|
|
20
|
+
};
|
|
21
|
+
export function readStarts(home) {
|
|
22
|
+
let raw;
|
|
23
|
+
try {
|
|
24
|
+
raw = JSON.parse(readStateText(startsPath(home)));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const k of WATCHED) {
|
|
31
|
+
const r = raw?.[k];
|
|
32
|
+
if (!r || typeof r !== "object")
|
|
33
|
+
continue;
|
|
34
|
+
const rec = { starts: Array.isArray(r.starts) ? r.starts.filter(isTime).slice(-50) : [] };
|
|
35
|
+
if (isTime(r.healthy_at))
|
|
36
|
+
rec.healthy_at = r.healthy_at;
|
|
37
|
+
const loop = episode(r.loop);
|
|
38
|
+
if (loop)
|
|
39
|
+
rec.loop = loop;
|
|
40
|
+
const last = episode(r.last_loop);
|
|
41
|
+
const ended = r.last_loop?.ended_at;
|
|
42
|
+
if (last && isTime(ended))
|
|
43
|
+
rec.last_loop = { ...last, ended_at: ended };
|
|
44
|
+
out[k] = rec;
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
function update(home, fn) {
|
|
49
|
+
const file = startsPath(home);
|
|
50
|
+
let result;
|
|
51
|
+
const write = () => { const s = readStarts(home); result = fn(s); atomicWrite(file, JSON.stringify(s, null, 2) + "\n"); };
|
|
52
|
+
let ran = false;
|
|
53
|
+
try {
|
|
54
|
+
withFileLock(file, () => { ran = true; write(); }, 2_000);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if (ran)
|
|
58
|
+
throw e;
|
|
59
|
+
write();
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
export function recordStart(kind, o = {}) {
|
|
64
|
+
const now = o.now ?? Date.now();
|
|
65
|
+
return update(o.home, (s) => {
|
|
66
|
+
const rec = s[kind] ?? { starts: [] };
|
|
67
|
+
if (rec.loop && now - rec.loop.last >= LOOP_STALE_MS) {
|
|
68
|
+
rec.last_loop = { ...rec.loop, ended_at: rec.loop.last };
|
|
69
|
+
delete rec.loop;
|
|
70
|
+
}
|
|
71
|
+
rec.starts = [...rec.starts.filter((t) => now - t < LOOP_WINDOW_MS && t <= now), now];
|
|
72
|
+
if (rec.loop) {
|
|
73
|
+
rec.loop.starts += 1;
|
|
74
|
+
rec.loop.last = now;
|
|
75
|
+
}
|
|
76
|
+
else if (rec.starts.length >= LOOP_STARTS)
|
|
77
|
+
rec.loop = { since: rec.starts[0], starts: rec.starts.length, last: now };
|
|
78
|
+
s[kind] = rec;
|
|
79
|
+
const loop = rec.loop ?? null;
|
|
80
|
+
if (loop && !loop.alerted_at) {
|
|
81
|
+
loop.alerted_at = now;
|
|
82
|
+
return { loop: { ...loop }, alert: true };
|
|
83
|
+
}
|
|
84
|
+
return { loop: loop ? { ...loop } : null, alert: false };
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export function markHealthy(kind, o = {}) {
|
|
88
|
+
const now = o.now ?? Date.now();
|
|
89
|
+
try {
|
|
90
|
+
return update(o.home, (s) => {
|
|
91
|
+
const rec = s[kind] ?? { starts: [] };
|
|
92
|
+
const ended = rec.loop ?? null;
|
|
93
|
+
rec.starts = [];
|
|
94
|
+
rec.healthy_at = now;
|
|
95
|
+
if (ended)
|
|
96
|
+
rec.last_loop = { ...ended, ended_at: now };
|
|
97
|
+
delete rec.loop;
|
|
98
|
+
s[kind] = rec;
|
|
99
|
+
return ended;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export function markExpectedExit(kind, o = {}) {
|
|
107
|
+
if (!readStarts(o.home)[kind]?.starts.length)
|
|
108
|
+
return;
|
|
109
|
+
try {
|
|
110
|
+
update(o.home, (s) => { const rec = s[kind]; if (rec)
|
|
111
|
+
rec.starts = []; });
|
|
112
|
+
}
|
|
113
|
+
catch { }
|
|
114
|
+
}
|
|
115
|
+
export function stopIsExpected(kind, o = {}) {
|
|
116
|
+
if (kind === "worker" || kind === "notifier")
|
|
117
|
+
markExpectedExit(kind, o);
|
|
118
|
+
}
|
|
119
|
+
export function activeLoop(kind, o = {}) {
|
|
120
|
+
const loop = (o.file ?? readStarts(o.home))[kind]?.loop;
|
|
121
|
+
if (!loop)
|
|
122
|
+
return null;
|
|
123
|
+
return (o.now ?? Date.now()) - loop.last < LOOP_STALE_MS ? loop : null;
|
|
124
|
+
}
|
|
125
|
+
const NAME = { worker: "worker", notifier: "desktop alerts" };
|
|
126
|
+
const span = (ms) => { const m = Math.max(1, Math.round(ms / 60_000)); return m < 90 ? `${m} minute${m === 1 ? "" : "s"}` : `${Math.round(m / 60)} hours`; };
|
|
127
|
+
export function loopLine(kind, loop, now = Date.now()) {
|
|
128
|
+
const what = kind === "worker" ? "teammates' requests wait for you meanwhile" : "you may miss decisions meanwhile";
|
|
129
|
+
return `Pantheon's ${NAME[kind]} keeps stopping — it has restarted ${loop.starts} times in ${span(Math.max(now, loop.last) - loop.since)} without staying up, so ${what}. pantheon doctor shows why`;
|
|
130
|
+
}
|
|
131
|
+
export function crashLoopLine(home, now = Date.now()) {
|
|
132
|
+
const file = readStarts(home);
|
|
133
|
+
for (const k of WATCHED) {
|
|
134
|
+
const l = activeLoop(k, { now, file });
|
|
135
|
+
if (l)
|
|
136
|
+
return loopLine(k, l, now);
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
export function composeCrashLoop(kind, loop, o = {}) {
|
|
141
|
+
const heading = kind === "worker" ? "Pantheon's worker keeps stopping" : "Pantheon's alerts keep stopping";
|
|
142
|
+
const body = kind === "worker"
|
|
143
|
+
? `It has restarted ${loop.starts} times in ${span((o.now ?? Date.now()) - loop.since)}, so teammates' requests wait for you. Run pantheon doctor: it shows why and what to do.`
|
|
144
|
+
: `Desktop alerts have restarted ${loop.starts} times in ${span((o.now ?? Date.now()) - loop.since)}, so you may miss decisions. Run pantheon doctor: it shows why and what to do.`;
|
|
145
|
+
return {
|
|
146
|
+
kind: "worker_failed", who: "Pantheon · this computer", heading, context: "",
|
|
147
|
+
body: body.length <= BUDGET.body ? body : `${body.slice(0, BUDGET.body - 1)}…`,
|
|
148
|
+
ttl: 0, sound: false, tag: `pantheon_loop_${kind}`,
|
|
149
|
+
...((o.os ?? process.platform) === "win32" ? {} : { fix: { label: "Show me how", dir: o.dir ?? homedir(), lines: ["pantheon doctor"], why: heading } }),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
let tracking = null;
|
|
153
|
+
export function trackService(kind, o = {}) {
|
|
154
|
+
const now = o.now ?? Date.now;
|
|
155
|
+
let r = { loop: null, alert: false };
|
|
156
|
+
try {
|
|
157
|
+
r = recordStart(kind, { ...(o.home ? { home: o.home } : {}), now: now() });
|
|
158
|
+
}
|
|
159
|
+
catch { }
|
|
160
|
+
tracking = { kind, ...(o.home ? { home: o.home } : {}), startedAt: now(), healthy: false, expectExit: false, connected: false, timers: [] };
|
|
161
|
+
const t = tracking;
|
|
162
|
+
if (!o.passive) {
|
|
163
|
+
const steady = setTimeout(() => healthyNow(t), STEADY_AFTER_MS);
|
|
164
|
+
steady.unref?.();
|
|
165
|
+
t.timers.push(steady);
|
|
166
|
+
process.on("exit", (code) => { if (!t.healthy && (t.expectExit || EXPECTED_EXIT_CODES.includes(code)))
|
|
167
|
+
markExpectedExit(t.kind, t.home ? { home: t.home } : {}); });
|
|
168
|
+
exitOnStopSignals();
|
|
169
|
+
}
|
|
170
|
+
if (r.alert && r.loop) {
|
|
171
|
+
try {
|
|
172
|
+
o.onLoop?.(r.loop);
|
|
173
|
+
}
|
|
174
|
+
catch { }
|
|
175
|
+
}
|
|
176
|
+
return r;
|
|
177
|
+
}
|
|
178
|
+
export function exitOnStopSignals(proc = process) {
|
|
179
|
+
for (const [sig, code] of [["SIGTERM", 143], ["SIGHUP", 129]]) {
|
|
180
|
+
try {
|
|
181
|
+
proc.on(sig, () => { if (proc.listenerCount(sig) <= 1)
|
|
182
|
+
proc.exit(code); });
|
|
183
|
+
}
|
|
184
|
+
catch { }
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function healthyNow(t) {
|
|
188
|
+
if (t.healthy)
|
|
189
|
+
return;
|
|
190
|
+
t.healthy = true;
|
|
191
|
+
markHealthy(t.kind, t.home ? { home: t.home } : {});
|
|
192
|
+
}
|
|
193
|
+
export function noteServiceConnected() {
|
|
194
|
+
const t = tracking;
|
|
195
|
+
if (!t || t.healthy || t.connected)
|
|
196
|
+
return;
|
|
197
|
+
t.connected = true;
|
|
198
|
+
const timer = setTimeout(() => healthyNow(t), HEALTHY_AFTER_CONNECT_MS);
|
|
199
|
+
timer.unref?.();
|
|
200
|
+
t.timers.push(timer);
|
|
201
|
+
}
|
|
202
|
+
export function expectServiceExit() { if (tracking)
|
|
203
|
+
tracking.expectExit = true; }
|
|
204
|
+
export function resetServiceTracking() { if (tracking)
|
|
205
|
+
for (const t of tracking.timers)
|
|
206
|
+
clearTimeout(t); tracking = null; }
|
|
207
|
+
//# sourceMappingURL=crash-loop.js.map
|
package/dist/doctor.js
CHANGED
|
@@ -27,9 +27,10 @@ import { goneLine, leaveCommand, removalKey, removalRefusal, removals, removalWo
|
|
|
27
27
|
import { agentById, chooseAgent, describeChoice, detectAvailable, folderReaderLine, knownUserBinary, unattendedReadiness, unattendedRefusal, skippedSummary, SANDBOXED_FOR_UNATTENDED } from "./agents.js";
|
|
28
28
|
import { loginShellLookup, npmSpawn, onPathNamed, which, whichWindows } from "./which.js";
|
|
29
29
|
import { VERSION } from "./version.js";
|
|
30
|
-
import { borrowedScheduler, realSys, serviceInstalled, servicesUnavailable } from "./service.js";
|
|
30
|
+
import { borrowedScheduler, realSys, serviceInstalled, serviceLogFile, servicesUnavailable } from "./service.js";
|
|
31
31
|
import { statusDir } from "./status-nudge.js";
|
|
32
32
|
import { CONN_FRESH_MS } from "./conn-report.js";
|
|
33
|
+
import { activeLoop, loopLine, readStarts, WATCHED } from "./crash-loop.js";
|
|
33
34
|
export function ownProcesses() {
|
|
34
35
|
const borrowed = (() => { try {
|
|
35
36
|
return borrowedScheduler();
|
|
@@ -205,6 +206,36 @@ function repoBoundToTeam(cfg) {
|
|
|
205
206
|
return false;
|
|
206
207
|
}
|
|
207
208
|
}
|
|
209
|
+
export function crashLoopRows(o = {}) {
|
|
210
|
+
const now = o.now ?? Date.now();
|
|
211
|
+
const file = readStarts(o.home);
|
|
212
|
+
const rows = [];
|
|
213
|
+
const tail = o.logTail ?? ((kind) => {
|
|
214
|
+
try {
|
|
215
|
+
const lines = readFileSync(serviceLogFile(kind), "utf8").split("\n").map((l) => l.trim()).filter(Boolean).slice(-40);
|
|
216
|
+
return [...lines].reverse().find((l) => /error|!|fail|cannot|refused|throw/i.test(l)) ?? lines[lines.length - 1] ?? null;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
for (const kind of WATCHED) {
|
|
223
|
+
const name = kind === "worker" ? "worker restarts" : "alerts restarts";
|
|
224
|
+
const loop = activeLoop(kind, { now, file });
|
|
225
|
+
if (loop) {
|
|
226
|
+
const said = tail(kind);
|
|
227
|
+
rows.push({ level: "warn", name, detail: `${loopLine(kind, loop, now).replace(/\. pantheon doctor shows why$/, "")}${said ? `. Its log last said: ${said.slice(0, 300)}` : ""}`,
|
|
228
|
+
fix: `pantheon logs ${kind} shows the whole log. If the line above names a cause you can fix (a setting, a sign-in, a full disk), fix it; otherwise run pantheon upgrade (an older build may be the cause) and then pantheon service restart ${kind}`,
|
|
229
|
+
share: `${kind} restarted ${loop.starts} times without staying up` });
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const last = file[kind]?.last_loop;
|
|
233
|
+
if (last && now - last.ended_at < 24 * 3_600_000) {
|
|
234
|
+
rows.push({ level: "pass", name, detail: `it kept restarting earlier (${last.starts} times), and has stayed up since ${new Date(last.ended_at).toLocaleString()}`, share: `${kind} recovered from a restart loop` });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return rows;
|
|
238
|
+
}
|
|
208
239
|
export async function doctor(projectDir) {
|
|
209
240
|
const out = [];
|
|
210
241
|
const add = (level, name, detail, fix, share) => out.push({ level, name, detail, ...(fix ? { fix } : {}), ...(share ? { share } : {}) });
|
|
@@ -275,6 +306,8 @@ export async function doctor(projectDir) {
|
|
|
275
306
|
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(", ")})`);
|
|
276
307
|
}
|
|
277
308
|
}
|
|
309
|
+
for (const r of crashLoopRows())
|
|
310
|
+
add(r.level, r.name, r.detail, r.fix, r.share);
|
|
278
311
|
let cfg = null;
|
|
279
312
|
try {
|
|
280
313
|
cfg = load() ?? (() => { const f = loadAll(); const m = Object.values(f?.spaces ?? {})[0]; return f && m ? configFor(f, m, null) : null; })();
|
|
@@ -600,6 +633,10 @@ export async function doctor(projectDir) {
|
|
|
600
633
|
try {
|
|
601
634
|
const res = await fetch(health, { signal: AbortSignal.timeout(5000) });
|
|
602
635
|
const body = (await relayJson(res, health));
|
|
636
|
+
if (typeof body.pkg === "string") {
|
|
637
|
+
const { recordRelayPkg } = await import("./version-health.js");
|
|
638
|
+
recordRelayPkg(cfg.relay, body.pkg);
|
|
639
|
+
}
|
|
603
640
|
await certRow(true);
|
|
604
641
|
if (!body.ok && body.storage) {
|
|
605
642
|
const since = body.storage.at ? ` (since ${new Date(body.storage.at).toLocaleString()})` : "";
|
package/dist/finish-line.js
CHANGED
|
@@ -12,10 +12,11 @@ export function finishItems(f) {
|
|
|
12
12
|
out.push({
|
|
13
13
|
says: "No coding agent is installed on this machine, so nothing is connected to your team yet.",
|
|
14
14
|
fix: `${r?.code === "no_agent" ? r.fix.replace(/\.$/, "") : "Install Claude Code, Codex, Cursor, Copilot or Kiro"} — then run: pantheon install --user`,
|
|
15
|
+
blocks: true,
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
else if (!wired.length) {
|
|
18
|
-
out.push({ says: "No agent on this machine could be connected to Pantheon (see the lines above).", fix: "fix what they say, then run: pantheon install --user" });
|
|
19
|
+
out.push({ says: "No agent on this machine could be connected to Pantheon (see the lines above).", fix: "fix what they say, then run: pantheon install --user", blocks: true });
|
|
19
20
|
}
|
|
20
21
|
for (const t of f.tools.filter((x) => rowFailed(x.status) && !(AGENT_ROWS.has(x.tool) && !wired.length))) {
|
|
21
22
|
out.push({ says: `${t.tool} was not set up: ${t.status.replace(/^(failed|could not install):?\s*/i, "")}`, fix: "fix that, then run: pantheon install --user" });
|
|
@@ -24,21 +25,21 @@ export function finishItems(f) {
|
|
|
24
25
|
const m = /^installed, not running:\s*(.*)$/i.exec(t.status);
|
|
25
26
|
const svc = SERVICE_OF[t.tool];
|
|
26
27
|
if (m && svc)
|
|
27
|
-
out.push({ says: `The ${t.tool === "notifications" ? "desktop alerts" : t.tool} ${t.tool === "notifications" ? "are" : "is"} installed but not running (${m[1]}).`, fix: `pantheon service restart ${svc}
|
|
28
|
+
out.push({ says: `The ${t.tool === "notifications" ? "desktop alerts" : t.tool} ${t.tool === "notifications" ? "are" : "is"} installed but not running (${m[1]}).`, fix: `pantheon service restart ${svc}`, ...(svc === "worker" ? { blocks: true } : {}) });
|
|
28
29
|
}
|
|
29
30
|
if (r && !(r.code === "no_agent" && !attempted.length)) {
|
|
30
31
|
if (r.code === "not_signed_in" && r.agent) {
|
|
31
32
|
const label = r.short.replace(/ isn't signed in$/, "");
|
|
32
|
-
out.push({ says: `${label} is signed out, so teammates' requests can't run here while you're away.`, fix: r.fix, signIn: r.agent });
|
|
33
|
+
out.push({ says: `${label} is signed out, so teammates' requests can't run here while you're away.`, fix: r.fix, signIn: r.agent, blocks: true });
|
|
33
34
|
}
|
|
34
35
|
else
|
|
35
|
-
out.push({ says: r.says, fix: r.fix });
|
|
36
|
+
out.push({ says: r.says, fix: r.fix, blocks: true });
|
|
36
37
|
}
|
|
37
38
|
const rowSaid = out.some((i) => /^The worker is installed but not running|^worker was not set up/.test(i.says));
|
|
38
39
|
if (f.workerWanted && (f.served ?? 0) > 0 && f.worker && !(f.worker.installed && f.worker.loaded) && !rowSaid) {
|
|
39
40
|
out.push(f.worker.installed
|
|
40
|
-
? { says: "Your worker is installed but not running, so teammates' requests wait for you while you're away.", fix: "pantheon service restart worker" }
|
|
41
|
-
: { says: "Your worker isn't installed, so teammates' requests wait for you while you're away.", fix: "pantheon service install worker" });
|
|
41
|
+
? { says: "Your worker is installed but not running, so teammates' requests wait for you while you're away.", fix: "pantheon service restart worker", blocks: true }
|
|
42
|
+
: { says: "Your worker isn't installed, so teammates' requests wait for you while you're away.", fix: "pantheon service install worker", blocks: true });
|
|
42
43
|
}
|
|
43
44
|
const alertsSaid = out.some((i) => /^The desktop alerts are installed but not running|^notifications was not set up/.test(i.says));
|
|
44
45
|
if (f.alerts && !(f.alerts.installed && f.alerts.loaded) && !alertsSaid) {
|
|
@@ -47,7 +48,13 @@ export function finishItems(f) {
|
|
|
47
48
|
: { says: "Desktop alerts aren't installed, so you won't hear when a teammate needs you.", fix: "pantheon service install notifier" });
|
|
48
49
|
}
|
|
49
50
|
if (f.workerWanted && f.served === 0) {
|
|
50
|
-
out.push({
|
|
51
|
+
out.push({
|
|
52
|
+
says: `This computer can't take your teammates' requests yet: no folder on it is linked to "${f.team}", so your worker has nothing to work in.`,
|
|
53
|
+
fix: f.agentShell && f.linkLine
|
|
54
|
+
? `ask your person which folder they work in for "${f.team}" — a repo, or a folder of documents; never pick one for them (the ones found here are listed above) — then run, with that folder: ${f.linkLine}`
|
|
55
|
+
: `from the folder you work in (a repo, or a folder of docs): pantheon use ${f.team} --here`,
|
|
56
|
+
blocks: true, needsFolder: true,
|
|
57
|
+
});
|
|
51
58
|
}
|
|
52
59
|
if (f.windows?.length) {
|
|
53
60
|
const self = f.windows.filter((w) => w.self);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { commonCodeRoots, reposUnder } from "./repo-find.js";
|
|
5
|
+
import { folderFacts, folderRefusal, isTemporaryRefusal } from "./folder-guard.js";
|
|
6
|
+
export function teamLinked(all, spaceId) {
|
|
7
|
+
if (!all || !spaceId)
|
|
8
|
+
return false;
|
|
9
|
+
return Object.values(all.bindings ?? {}).some((b) => b.space === spaceId);
|
|
10
|
+
}
|
|
11
|
+
export function shownPath(p, home = homedir(), pp = path) {
|
|
12
|
+
const rel = pp.relative(home, p);
|
|
13
|
+
if (rel === "")
|
|
14
|
+
return "~";
|
|
15
|
+
if (!rel.startsWith("..") && !pp.isAbsolute(rel))
|
|
16
|
+
return `~${pp.sep}${rel}`;
|
|
17
|
+
return p;
|
|
18
|
+
}
|
|
19
|
+
const repoName = (r) => (r.origin ? r.origin.replace(/\.git$/i, "").split(/[/:]/).filter(Boolean).pop() : null) || path.basename(r.root);
|
|
20
|
+
function lastUsed(root) {
|
|
21
|
+
for (const f of [path.join(root, ".git", "index"), path.join(root, ".git")]) {
|
|
22
|
+
try {
|
|
23
|
+
return statSync(f).mtimeMs;
|
|
24
|
+
}
|
|
25
|
+
catch { }
|
|
26
|
+
}
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
export function folderChoices(o) {
|
|
30
|
+
const home = o.home ?? homedir();
|
|
31
|
+
const facts = o.facts ?? folderFacts();
|
|
32
|
+
const budget = { left: o.budget ?? 6000 };
|
|
33
|
+
const roots = [];
|
|
34
|
+
const here = folderRefusal(o.cwd, facts);
|
|
35
|
+
if (!here || here.kind === "catch-all")
|
|
36
|
+
roots.push([o.cwd, 2]);
|
|
37
|
+
for (const r of commonCodeRoots(home))
|
|
38
|
+
roots.push([r, 3]);
|
|
39
|
+
for (const n of ["Desktop", "Documents"]) {
|
|
40
|
+
const d = path.join(home, n);
|
|
41
|
+
try {
|
|
42
|
+
if (statSync(d).isDirectory())
|
|
43
|
+
roots.push([d, 2]);
|
|
44
|
+
}
|
|
45
|
+
catch { }
|
|
46
|
+
}
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
const out = [];
|
|
49
|
+
const unbound = new Set(o.all?.unbound ?? []);
|
|
50
|
+
for (const [root, depth] of roots) {
|
|
51
|
+
for (const r of reposUnder(root, depth, budget)) {
|
|
52
|
+
if (seen.has(r.root))
|
|
53
|
+
continue;
|
|
54
|
+
seen.add(r.root);
|
|
55
|
+
const held = o.all?.bindings?.[r.fingerprint];
|
|
56
|
+
if (held && held.space !== o.spaceId)
|
|
57
|
+
continue;
|
|
58
|
+
if (unbound.has(r.fingerprint))
|
|
59
|
+
continue;
|
|
60
|
+
if (isTemporaryRefusal(folderRefusal(r.root, facts)))
|
|
61
|
+
continue;
|
|
62
|
+
out.push({ path: r.root, name: repoName(r), shown: shownPath(r.root, home), shared: r.shared, at: lastUsed(r.root) });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return out.sort((a, b) => b.at - a.at).slice(0, o.limit ?? 6).map(({ at: _at, ...c }) => c);
|
|
66
|
+
}
|
|
67
|
+
export function folderArg(p, platform = process.platform) {
|
|
68
|
+
if (platform === "win32")
|
|
69
|
+
return /^[A-Za-z0-9._\\/:@+=,-]+$/.test(p) ? p : `"${p}"`;
|
|
70
|
+
return /^[A-Za-z0-9._/:@+=,-]+$/.test(p) ? p : `'${p.replace(/'/g, `'\\''`)}'`;
|
|
71
|
+
}
|
|
72
|
+
const oneLine = (t) => t.replace(/\s+\(Command Prompt: .*\)$/, "");
|
|
73
|
+
export const NAMED_FOLDER = "<the folder they name>";
|
|
74
|
+
export function notLinkedWhy(refusal) {
|
|
75
|
+
if (!refusal)
|
|
76
|
+
return null;
|
|
77
|
+
const why = refusal.why.replace(/;.*$/, "");
|
|
78
|
+
return why.charAt(0).toUpperCase() + why.slice(1);
|
|
79
|
+
}
|
|
80
|
+
export function folderAsk(o) {
|
|
81
|
+
const line = (dir) => o.command(`use ${o.team} --here --folder ${dir === NAMED_FOLDER ? `'${NAMED_FOLDER}'` : folderArg(dir, o.platform)}`);
|
|
82
|
+
const head = `This computer can't take your teammates' requests yet: no folder on it is linked to "${o.team}".`;
|
|
83
|
+
const message = `${o.why ? `${o.why}, so it was not linked. ` : ""}${head} Ask your person which folder they work in for "${o.team}" — never pick one for them — then run the line for it.`;
|
|
84
|
+
const other = line(NAMED_FOLDER);
|
|
85
|
+
const skip = "None for now: teammates' requests wait until your person opens their agent themselves.";
|
|
86
|
+
const lines = [
|
|
87
|
+
...(o.why ? [`${o.why}, so it was not linked to "${o.team}".`] : []),
|
|
88
|
+
head,
|
|
89
|
+
`Ask your person which folder they work in for "${o.team}" — never pick one for them — then run the line for it:`,
|
|
90
|
+
...o.choices.flatMap((c, i) => [` ${i + 1}. ${c.name} ${c.shown}${c.shared ? "" : " (no remote: nothing delivered from it can be fetched by a teammate)"}`, ` ${line(c.path)}`]),
|
|
91
|
+
` ${o.choices.length ? "Another folder" : "A folder"} they name — a repo, or a folder of documents (the worker answers questions from a copy of it and keeps anything it writes as drafts):`,
|
|
92
|
+
` ${other}`,
|
|
93
|
+
` ${skip}`,
|
|
94
|
+
];
|
|
95
|
+
return {
|
|
96
|
+
lines,
|
|
97
|
+
json: {
|
|
98
|
+
reason: "pick_folder", needs: "folder", team: o.team, message,
|
|
99
|
+
folders: o.choices.map((c) => ({ folder: c.path, name: c.name, shared: c.shared, next: oneLine(line(c.path)) })),
|
|
100
|
+
other_folder: oneLine(other), skip,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=folder-ask.js.map
|
package/dist/founder-stats.js
CHANGED
|
@@ -18,7 +18,17 @@ export function weekIn(starts, now, ts) {
|
|
|
18
18
|
export function weekOf(now, ts) {
|
|
19
19
|
return okTime(now) ? weekIn(weekStarts(now), now, ts) : -1;
|
|
20
20
|
}
|
|
21
|
-
const emptyValue = (partial) => ({ asks: 0, answered: 0, byWorker: 0, byPerson: 0, answerMs: [], decisions: 0, decided: 0, decisionMs: [], delivered: 0, partial });
|
|
21
|
+
const emptyValue = (partial) => ({ asks: 0, answered: 0, byWorker: 0, byPerson: 0, answerMs: [], decisions: 0, decided: 0, decisionMs: [], delivered: 0, quick: 0, unpicked: 0, partial });
|
|
22
|
+
export const PICKUP_MS = 5 * 60_000;
|
|
23
|
+
export const UNPICKED_AFTER_MS = 60 * 60_000;
|
|
24
|
+
export function pickedUpAt(ix, ask, claimAt) {
|
|
25
|
+
let at = claimAt.get(ask.id) ?? null;
|
|
26
|
+
const askedOf = ask.to ?? [];
|
|
27
|
+
for (const k of ix.allKids.get(ask.id) ?? [])
|
|
28
|
+
if (k.from !== ask.from && (askedOf.length === 0 || askedOf.includes(k.from)) && (at === null || k.ts < at))
|
|
29
|
+
at = k.ts;
|
|
30
|
+
return at;
|
|
31
|
+
}
|
|
22
32
|
function usageSum(book, from, to, f) {
|
|
23
33
|
if (!book || !okTime(from) || !okTime(to))
|
|
24
34
|
return 0;
|
|
@@ -58,6 +68,13 @@ function* teamWeeksSteps(input, slice = 5_000) {
|
|
|
58
68
|
messages[k] = usageSum(input.usage, b.from, Math.min(b.to, now + 1), (d) => d.by_worker + d.by_person);
|
|
59
69
|
}
|
|
60
70
|
const value = [emptyValue(partial[0]), emptyValue(partial[1])];
|
|
71
|
+
const claimAt = new Map();
|
|
72
|
+
for (const c of input.claims ?? [])
|
|
73
|
+
if (okTime(c.at)) {
|
|
74
|
+
const was = claimAt.get(c.ref);
|
|
75
|
+
if (was === undefined || c.at < was)
|
|
76
|
+
claimAt.set(c.ref, c.at);
|
|
77
|
+
}
|
|
61
78
|
let n = 0;
|
|
62
79
|
for (const r of ix.recs) {
|
|
63
80
|
if (++n % slice === 0)
|
|
@@ -82,6 +99,11 @@ function* teamWeeksSteps(input, slice = 5_000) {
|
|
|
82
99
|
else
|
|
83
100
|
v.byPerson++;
|
|
84
101
|
}
|
|
102
|
+
const up = pickedUpAt(ix, r, claimAt);
|
|
103
|
+
if (up !== null && up - r.ts <= PICKUP_MS)
|
|
104
|
+
v.quick++;
|
|
105
|
+
if (up === null && now - r.ts > UNPICKED_AFTER_MS)
|
|
106
|
+
v.unpicked++;
|
|
85
107
|
}
|
|
86
108
|
else if (r.act === "ESCALATE" || r.act === "HUMAN_REQUIRED") {
|
|
87
109
|
v.decisions++;
|
|
@@ -185,6 +207,7 @@ export function founderView(input) {
|
|
|
185
207
|
medianAnswerMs: meds((t, k) => t.value[k].answerMs),
|
|
186
208
|
decisions: pair((t, k) => t.value[k].decisions), decided: pair((t, k) => t.value[k].decided), medianDecisionMs: meds((t, k) => t.value[k].decisionMs),
|
|
187
209
|
delivered: pair((t, k) => t.value[k].delivered),
|
|
210
|
+
quick: pair((t, k) => t.value[k].quick ?? 0), unpicked: pair((t, k) => t.value[k].unpicked ?? 0),
|
|
188
211
|
partial: [teams.some((t) => t.value[0].partial), teams.some((t) => t.value[1].partial)],
|
|
189
212
|
},
|
|
190
213
|
growth: {
|
package/dist/home-guard.js
CHANGED
|
@@ -486,6 +486,27 @@ export function narrowPolicy(before, now, keepAsks = askedHere) {
|
|
|
486
486
|
keys.push(`${f}: ${lost} removed`);
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
+
for (const f of ["revoked", "usedOnce"]) {
|
|
490
|
+
const br = obj(b[f]), nr = obj(now[f]);
|
|
491
|
+
const merged = { ...nr };
|
|
492
|
+
let lost = 0;
|
|
493
|
+
for (const [k, v] of Object.entries(br))
|
|
494
|
+
if (!(k in nr) || !same(nr[k], v)) {
|
|
495
|
+
merged[k] = v;
|
|
496
|
+
lost++;
|
|
497
|
+
}
|
|
498
|
+
if (lost) {
|
|
499
|
+
out[f] = merged;
|
|
500
|
+
keys.push(`${f}: ${lost} removed`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
if (before !== undefined && !same(b.born, now.born)) {
|
|
504
|
+
if (b.born === undefined)
|
|
505
|
+
delete out.born;
|
|
506
|
+
else
|
|
507
|
+
out.born = b.born;
|
|
508
|
+
keys.push(b.born === undefined ? "born added (taken back)" : "born changed");
|
|
509
|
+
}
|
|
489
510
|
const bt = obj(b.wakeTeamFlag), nt = obj(now.wakeTeamFlag);
|
|
490
511
|
const flags = {};
|
|
491
512
|
for (const [k, v] of Object.entries(nt)) {
|
package/dist/home-safety.js
CHANGED
|
@@ -40,6 +40,8 @@ export const PANTHEON_HOME_ENTRIES = [
|
|
|
40
40
|
{ name: /^invites-sent\.json$/, sample: "invites-sent.json", what: "the invites this machine made, hashed (for the joined alert)" },
|
|
41
41
|
{ name: /^known-members\.json$/, sample: "known-members.json", what: "the teammates this machine has already said joined" },
|
|
42
42
|
{ name: "update-check.json", what: "the update check's cache" },
|
|
43
|
+
{ name: "relay-version.json", what: "which release your team's relay runs, as this machine last read it, and the update alerts already shown" },
|
|
44
|
+
{ name: "service-starts.json", what: "when the worker and alerts last started, to notice one that keeps stopping" },
|
|
43
45
|
{ name: "uri-key", what: "the key pantheon:// links are signed with" },
|
|
44
46
|
{ name: "board.json", what: "the board's state" },
|
|
45
47
|
{ name: "hook-intent.json", what: "the hook intent" },
|