@join-pantheon/cli 0.35.0 → 0.35.1-rc.2
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/agent-outage.js +165 -35
- package/dist/agent-token.js +5 -3
- package/dist/agents.js +6 -4
- package/dist/approvals-list.js +87 -0
- package/dist/board.js +491 -88
- package/dist/brief.js +17 -0
- package/dist/cli.js +687 -95
- package/dist/client.js +159 -19
- package/dist/config.js +3 -2
- package/dist/continued.js +56 -1
- package/dist/decision-ui.js +5 -3
- package/dist/doctor.js +84 -16
- package/dist/file-lock.js +40 -5
- package/dist/flow-stats.js +18 -1
- package/dist/home-guard.js +336 -54
- package/dist/home-safety.js +2 -0
- package/dist/hud-queue.js +91 -0
- package/dist/install.js +15 -1
- package/dist/mcp-instructions.js +67 -28
- package/dist/mcp.js +129 -24
- package/dist/notice-linux.js +15 -4
- package/dist/notice-windows.js +2 -2
- package/dist/notifier.js +2 -1
- package/dist/notify.js +28 -9
- package/dist/open-in.js +4 -3
- package/dist/pickup.js +17 -0
- package/dist/plain.js +139 -3
- package/dist/profile.js +12 -8
- package/dist/protocol.js +1 -1
- package/dist/question-goal.js +74 -0
- package/dist/readiness-alert.js +24 -3
- package/dist/refusal.js +2 -2
- package/dist/relay.js +143 -28
- package/dist/removed.js +4 -4
- package/dist/run-control.js +4 -3
- package/dist/run-failure.js +67 -10
- package/dist/setup-changes.js +7 -6
- package/dist/signed-out.js +144 -21
- package/dist/spend.js +5 -4
- package/dist/tray.js +24 -6
- package/dist/update-check.js +2 -1
- package/dist/uri-handler.js +10 -2
- package/dist/which.js +2 -0
- package/dist/worker-policy.js +212 -10
- package/dist/worker.js +942 -133
- package/dist/worklist.js +31 -1
- package/helper/macos/main.swift +42 -3
- package/helper/macos/menubar.swift +482 -87
- package/helper/macos/prebuilt/manifest.json +5 -5
- package/helper/macos/prebuilt/pantheon-hud +0 -0
- package/helper/macos/prebuilt/pantheon-tray +0 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import WebSocket from "ws";
|
|
|
2
2
|
import { clearRemoval, recordGone, recordRemoval, restateDeletedWhen, removalFor, removalHoldMs, removalRefusal, REMOVED_CHECK_MS, REMOVED_FIRST_MS, REMOVED_MAX_MS } from "./removed.js";
|
|
3
3
|
import { adoptSpaceId, loadAll, rememberTeamRepos, updateMembershipToken } from "./config.js";
|
|
4
4
|
import { honourClearedAuthority } from "./profile.js";
|
|
5
|
-
import { loadContinued, markContinued, unmarkContinued } from "./continued.js";
|
|
5
|
+
import { inflightKey, loadContinued, markContinued, releasedKey, storedKey, unmarkContinued } from "./continued.js";
|
|
6
6
|
import { isAnsweredId, markAnswered, nonceOf, unmarkAnswered } from "./nonces.js";
|
|
7
7
|
import { signedRead } from "./reads.js";
|
|
8
8
|
import { repoName } from "./repo-route.js";
|
|
@@ -18,7 +18,33 @@ const REFUSED_BEFORE_STORING = new Set([
|
|
|
18
18
|
"NOT_IN_GOAL", "NO_SUCH_GOAL", "NO_SUCH_MEMBER", "TO_REQUIRED", "BAD_REF", "REF_REQUIRED", "REF_OTHER_GOAL",
|
|
19
19
|
"BAD_MESSAGE", "BAD_META", "META_TOO_LARGE", "BAD_ACT_SIGNATURE", "SIGNED_ONLY", "UNVERIFIABLE_DELIVERY",
|
|
20
20
|
"REPO_REQUIRED", "REPO_MISMATCH", "NOT_ADMITTED", "NOTHING_OWED", "NOT_FOR_A_RUN", "BAD_BRANCH", "BAD_COMMIT", "BAD_BASE", "BAD_REMOTE",
|
|
21
|
+
"WITHDRAWN",
|
|
22
|
+
"ALREADY_RETRACTED", "AMBIGUOUS_DECISION_AUTHORITY", "BAD_DECISION_DOMAIN", "DECISION_ALREADY_WAITING", "DECISION_DOMAINS_REQUIRED",
|
|
23
|
+
"ESCALATE_IS_LOCAL", "NAMED_BY_A_RUN", "NOT_YOUR_DECISION", "NOT_YOURS_TO_RETRACT", "ONE_HUMAN_REQUIRED", "RESERVED_ACT", "SELF_DEFER",
|
|
24
|
+
"UPGRADE_REQUIRED", "WOULD_ORPHAN", "WRONG_DECISION_OWNER", "BAD_ACT_ID",
|
|
25
|
+
"RECOVERY_BY_PERSON", "NO_RECOVERY", "RECOVERY_KEY", "RECOVERY_SELF",
|
|
26
|
+
"STORAGE_BUSY",
|
|
27
|
+
"TOO_MANY_GOALS", "BAD_GOAL_SIGNATURE", "DEADLINE_PAST",
|
|
28
|
+
"ALREADY_ANSWERED",
|
|
21
29
|
]);
|
|
30
|
+
export function certainlyNotStored(e) {
|
|
31
|
+
const msg = e?.message ?? "";
|
|
32
|
+
if (/^not connected to relay\b/.test(msg))
|
|
33
|
+
return true;
|
|
34
|
+
return !!e?.refused && REFUSED_BEFORE_STORING.has(/^([A-Z_]+):/.exec(msg)?.[1] ?? "");
|
|
35
|
+
}
|
|
36
|
+
export const failedActId = (e) => {
|
|
37
|
+
const id = e?.actId;
|
|
38
|
+
return typeof id === "string" ? id : null;
|
|
39
|
+
};
|
|
40
|
+
export const UNCONFIRMED = "UNCONFIRMED: the relay did not confirm it — it may be on the record, so check the thread before sending it again";
|
|
41
|
+
export const NO_REPLY = "NO_REPLY: the relay did not answer in 10s — it may have stored this, so check before sending it again";
|
|
42
|
+
const isAnsweredIdSafe = (team, id) => { try {
|
|
43
|
+
return isAnsweredId(team, id);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return true;
|
|
47
|
+
} };
|
|
22
48
|
export class PantheonClient {
|
|
23
49
|
cfg;
|
|
24
50
|
onEvent;
|
|
@@ -464,9 +490,10 @@ export class PantheonClient {
|
|
|
464
490
|
}
|
|
465
491
|
}
|
|
466
492
|
const fn = msg.cid ? this.acks.get(msg.cid) : undefined;
|
|
493
|
+
const answerId = typeof msg.answer === "string" && /^a_[A-Za-z0-9]{4,64}$/.test(msg.answer) ? msg.answer : null;
|
|
467
494
|
if (fn && msg.cid) {
|
|
468
495
|
this.acks.delete(msg.cid);
|
|
469
|
-
fn({ error: this.lastError });
|
|
496
|
+
fn({ error: answerId ? `${this.lastError} (answer ${answerId})` : this.lastError });
|
|
470
497
|
}
|
|
471
498
|
else if (!settled) {
|
|
472
499
|
settled = true;
|
|
@@ -639,7 +666,7 @@ export class PantheonClient {
|
|
|
639
666
|
}
|
|
640
667
|
const cid = `c${++this.cid}`;
|
|
641
668
|
return new Promise((resolve, reject) => {
|
|
642
|
-
const timer = setTimeout(() => { this.acks.delete(cid); reject(new Error(
|
|
669
|
+
const timer = setTimeout(() => { this.acks.delete(cid); reject(new Error(NO_REPLY)); }, this.rpcTimeoutMs);
|
|
643
670
|
this.acks.set(cid, (v) => {
|
|
644
671
|
clearTimeout(timer);
|
|
645
672
|
if ("error" in v)
|
|
@@ -674,6 +701,22 @@ export class PantheonClient {
|
|
|
674
701
|
}
|
|
675
702
|
return this.sendAct(a);
|
|
676
703
|
}
|
|
704
|
+
async sendSettled(a) {
|
|
705
|
+
try {
|
|
706
|
+
return await this.send(a);
|
|
707
|
+
}
|
|
708
|
+
catch (e) {
|
|
709
|
+
const id = failedActId(e);
|
|
710
|
+
if (certainlyNotStored(e) || !id)
|
|
711
|
+
throw e;
|
|
712
|
+
const seen = await this.seenOwn(id, /^ID_TAKEN\b/.test(e.message) ? 1_500 : 2_500);
|
|
713
|
+
if (seen)
|
|
714
|
+
return { id: seen.id, seq: seen.seq };
|
|
715
|
+
if (/^ID_TAKEN\b/.test(e.message))
|
|
716
|
+
return { id, seq: 0 };
|
|
717
|
+
throw Object.assign(new Error(UNCONFIRMED), { actId: id, unconfirmed: true });
|
|
718
|
+
}
|
|
719
|
+
}
|
|
677
720
|
async sendAct(a) {
|
|
678
721
|
return this.postAct(this.composeAct(a));
|
|
679
722
|
}
|
|
@@ -688,7 +731,8 @@ export class PantheonClient {
|
|
|
688
731
|
const { t: _t, id, sig: _s, repo: _r, ...a } = p;
|
|
689
732
|
let unrecorded = false, unsignedRef = false;
|
|
690
733
|
let marked = null;
|
|
691
|
-
|
|
734
|
+
const reply = !!a.ref && (a.act === "ANSWER" || a.act === "ACCEPT" || a.act === "OBJECT" || a.act === "DELIVERED");
|
|
735
|
+
if (reply && a.ref && this.ws?.readyState === WebSocket.OPEN) {
|
|
692
736
|
let hadHandled = true, hadAnswered = true;
|
|
693
737
|
try {
|
|
694
738
|
hadHandled = loadContinued(this.pinTeam).has(`handled:${a.ref}`);
|
|
@@ -699,6 +743,12 @@ export class PantheonClient {
|
|
|
699
743
|
}
|
|
700
744
|
catch { }
|
|
701
745
|
marked = { handled: !hadHandled, answered: !hadAnswered };
|
|
746
|
+
if (marked.handled || marked.answered) {
|
|
747
|
+
try {
|
|
748
|
+
markContinued(inflightKey(this.pinTeam), `${a.ref} ${id} ${Date.now()}`);
|
|
749
|
+
}
|
|
750
|
+
catch { }
|
|
751
|
+
}
|
|
702
752
|
try {
|
|
703
753
|
markContinued(this.pinTeam, `handled:${a.ref}`);
|
|
704
754
|
}
|
|
@@ -712,21 +762,19 @@ export class PantheonClient {
|
|
|
712
762
|
r = await this.rpc(p);
|
|
713
763
|
}
|
|
714
764
|
catch (e) {
|
|
715
|
-
if (
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
if (marked.answered) {
|
|
723
|
-
try {
|
|
724
|
-
unmarkAnswered(this.pinTeam, a.ref);
|
|
725
|
-
}
|
|
726
|
-
catch { }
|
|
727
|
-
}
|
|
765
|
+
if (reply && a.ref && /^(ID_TAKEN|ALREADY_ANSWERED)\b/.test(e.message)) {
|
|
766
|
+
await this.recordStored(a.act, a.ref);
|
|
767
|
+
this.settled(a.ref, id);
|
|
768
|
+
}
|
|
769
|
+
else if (marked && a.ref && certainlyNotStored(e)) {
|
|
770
|
+
this.takeBack(a.ref, id, marked);
|
|
771
|
+
this.settled(a.ref, id);
|
|
728
772
|
}
|
|
729
|
-
throw e;
|
|
773
|
+
throw Object.assign(e, { actId: id });
|
|
774
|
+
}
|
|
775
|
+
if (reply && a.ref) {
|
|
776
|
+
await this.recordStored(a.act, a.ref);
|
|
777
|
+
this.settled(a.ref, id);
|
|
730
778
|
}
|
|
731
779
|
let sentId = r.id === id ? id : null;
|
|
732
780
|
if (r.id !== id && this.features.includes("act-sig")) {
|
|
@@ -784,7 +832,8 @@ export class PantheonClient {
|
|
|
784
832
|
budget: g.budget ?? null, deadline: g.deadline ?? null, kind: g.kind ?? null,
|
|
785
833
|
})),
|
|
786
834
|
};
|
|
787
|
-
return this.rpc({ t: "open_goal", id, acceptance: "", ...g, ...(invite ? { invite } : {}), sig })
|
|
835
|
+
return this.rpc({ t: "open_goal", id, acceptance: "", ...g, ...(invite ? { invite } : {}), sig })
|
|
836
|
+
.catch((e) => { throw Object.assign(e, { goalId: id }); });
|
|
788
837
|
}
|
|
789
838
|
features = [];
|
|
790
839
|
pinChanges = [];
|
|
@@ -892,6 +941,94 @@ export class PantheonClient {
|
|
|
892
941
|
markAnswered(this.pinTeam, r.from, r.sig.nonce, r.id, undefined, r.sig.s);
|
|
893
942
|
return true;
|
|
894
943
|
}
|
|
944
|
+
rpcTimeoutMs = 10_000;
|
|
945
|
+
storedHere(ref) {
|
|
946
|
+
try {
|
|
947
|
+
return loadContinued(storedKey(this.pinTeam)).has(ref);
|
|
948
|
+
}
|
|
949
|
+
catch {
|
|
950
|
+
return true;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
noteStored(ref) {
|
|
954
|
+
try {
|
|
955
|
+
markContinued(storedKey(this.pinTeam), ref);
|
|
956
|
+
}
|
|
957
|
+
catch { }
|
|
958
|
+
}
|
|
959
|
+
async recordStored(act, ref) {
|
|
960
|
+
if (!(act === "ANSWER" || act === "ACCEPT" || act === "OBJECT" || act === "DELIVERED"))
|
|
961
|
+
return;
|
|
962
|
+
this.noteStored(ref);
|
|
963
|
+
try {
|
|
964
|
+
markContinued(this.pinTeam, `handled:${ref}`);
|
|
965
|
+
}
|
|
966
|
+
catch { }
|
|
967
|
+
if (!isAnsweredIdSafe(this.pinTeam, ref))
|
|
968
|
+
await this.noteAnswered(ref).catch(() => false);
|
|
969
|
+
}
|
|
970
|
+
settled(ref, id) {
|
|
971
|
+
try {
|
|
972
|
+
for (const x of loadContinued(inflightKey(this.pinTeam)))
|
|
973
|
+
if (x.startsWith(`${ref} ${id} `) || x === `${ref} ${id}`)
|
|
974
|
+
unmarkContinued(inflightKey(this.pinTeam), x);
|
|
975
|
+
}
|
|
976
|
+
catch { }
|
|
977
|
+
}
|
|
978
|
+
takeBack(ref, id, marked) {
|
|
979
|
+
if (this.storedHere(ref) || (!marked.handled && !marked.answered))
|
|
980
|
+
return;
|
|
981
|
+
try {
|
|
982
|
+
markContinued(releasedKey(this.pinTeam), `${ref} ${id}`);
|
|
983
|
+
}
|
|
984
|
+
catch { }
|
|
985
|
+
if (marked.handled) {
|
|
986
|
+
try {
|
|
987
|
+
unmarkContinued(this.pinTeam, `handled:${ref}`);
|
|
988
|
+
}
|
|
989
|
+
catch { }
|
|
990
|
+
}
|
|
991
|
+
if (marked.answered) {
|
|
992
|
+
try {
|
|
993
|
+
unmarkAnswered(this.pinTeam, ref);
|
|
994
|
+
}
|
|
995
|
+
catch { }
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
async seenOwn(id, waitMs = 4_000) {
|
|
999
|
+
const until = Date.now() + waitMs;
|
|
1000
|
+
for (;;) {
|
|
1001
|
+
const r = this.seen.get(id);
|
|
1002
|
+
if (r && r.from === this.cfg.member) {
|
|
1003
|
+
if (r.ref) {
|
|
1004
|
+
await this.recordStored(r.act, r.ref);
|
|
1005
|
+
this.settled(r.ref, r.id);
|
|
1006
|
+
}
|
|
1007
|
+
return r;
|
|
1008
|
+
}
|
|
1009
|
+
if (Date.now() >= until || this.closed)
|
|
1010
|
+
return null;
|
|
1011
|
+
await new Promise((res) => setTimeout(res, 100));
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
async storedAct(id, timeoutMs = 5_000) {
|
|
1015
|
+
const r = await this.lookUpOwn(id, timeoutMs);
|
|
1016
|
+
return r === "absent" || r === "unknown" ? null : r;
|
|
1017
|
+
}
|
|
1018
|
+
async lookUpOwn(id, timeoutMs) {
|
|
1019
|
+
try {
|
|
1020
|
+
const res = await signedRead(this.cfg, "/act", { id }, { timeoutMs });
|
|
1021
|
+
const j = (await res.json().catch(() => null));
|
|
1022
|
+
if (res.ok && j?.act?.id === id && j.act.from === this.cfg.member)
|
|
1023
|
+
return j.act;
|
|
1024
|
+
if (res.status === 404 && j?.error === "no such act" && !j.code)
|
|
1025
|
+
return "absent";
|
|
1026
|
+
return "unknown";
|
|
1027
|
+
}
|
|
1028
|
+
catch {
|
|
1029
|
+
return "unknown";
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
895
1032
|
verifiedIds = new Map();
|
|
896
1033
|
pinKey() { return pinScope(this.pinTeam, this.cfg.member); }
|
|
897
1034
|
pinTeam;
|
|
@@ -1176,6 +1313,9 @@ export class PantheonClient {
|
|
|
1176
1313
|
seenAct(id) {
|
|
1177
1314
|
return this.seen.get(id) ?? null;
|
|
1178
1315
|
}
|
|
1316
|
+
seenIn(goal) {
|
|
1317
|
+
return [...this.seen.values()].filter((r) => r.goal === goal).sort((a, b) => a.seq - b.seq);
|
|
1318
|
+
}
|
|
1179
1319
|
mineSince(ts, goal) {
|
|
1180
1320
|
return [...this.seen.values()]
|
|
1181
1321
|
.filter((r) => r.from === this.cfg.member && r.ts >= ts && r.act !== "JOIN" && r.act !== "LEAVE" && (goal == null || r.goal === goal))
|
package/dist/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mkdirSync, existsSync, openSync, writeSync, fsyncSync, closeSync, renameSync, rmSync, statSync, chmodSync, realpathSync } from "node:fs";
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
3
|
import { createHash, randomBytes } from "node:crypto";
|
|
4
4
|
import { homedir } from "node:os";
|
|
@@ -7,6 +7,7 @@ import { VERSION } from "./version.js";
|
|
|
7
7
|
import { repoName } from "./repo-route.js";
|
|
8
8
|
import { markPantheonHome } from "./home-safety.js";
|
|
9
9
|
import { TEAM_NAME } from "./team-name.js";
|
|
10
|
+
import { readStateText } from "./file-lock.js";
|
|
10
11
|
export const CONFIG_DIR = process.env.PANTHEON_HOME ?? join(homedir(), ".pantheon");
|
|
11
12
|
export const CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
12
13
|
export const DEFAULT_RELAY = process.env.PANTHEON_DEFAULT_RELAY
|
|
@@ -154,7 +155,7 @@ export function loadAll() {
|
|
|
154
155
|
return null;
|
|
155
156
|
if (!statSync(CONFIG_PATH).isFile())
|
|
156
157
|
throw new Error(`${CONFIG_PATH} is not a plain file — remove it and set up again (pantheon doctor)`);
|
|
157
|
-
return migrate(JSON.parse(
|
|
158
|
+
return migrate(JSON.parse(readStateText(CONFIG_PATH).replace(/^\uFEFF/, "")));
|
|
158
159
|
}
|
|
159
160
|
export function saveAll(f) {
|
|
160
161
|
const out = { ...f, version: 2, spaces: f.spaces ?? {}, bindings: f.bindings ?? {} };
|
package/dist/continued.js
CHANGED
|
@@ -4,6 +4,14 @@ import { CONFIG_DIR } from "./config.js";
|
|
|
4
4
|
import { readStateFile, withFileLock } from "./file-lock.js";
|
|
5
5
|
import { writeWhole } from "./pins.js";
|
|
6
6
|
const KEEP = 500;
|
|
7
|
+
export const WORKER_MARK = /^(parked|parked-nc|parked2|parked-ns|parked2-ns|unparked|failed1|stuck|stuck-safety|stuck-safety-due|refused|esc-for|decided-for)(@[^:]+)?:/;
|
|
8
|
+
const KEEP_WORKER = 2_000;
|
|
9
|
+
export const markedHere = new Set();
|
|
10
|
+
function capped(list) {
|
|
11
|
+
const worker = list.filter((x) => WORKER_MARK.test(x)), other = list.filter((x) => !WORKER_MARK.test(x));
|
|
12
|
+
const keep = new Set([...worker.slice(-KEEP_WORKER), ...other.slice(-KEEP)]);
|
|
13
|
+
return list.filter((x) => keep.has(x));
|
|
14
|
+
}
|
|
7
15
|
export function continuedPath(home) {
|
|
8
16
|
return join(home ?? CONFIG_DIR, "continued.json");
|
|
9
17
|
}
|
|
@@ -26,6 +34,51 @@ export function continuationDone(id, home) {
|
|
|
26
34
|
const all = Object.values(readAll(home)).flatMap((l) => (Array.isArray(l) ? l : []));
|
|
27
35
|
return all.includes(id) && !all.includes(`held-cont:${id}`);
|
|
28
36
|
}
|
|
37
|
+
export const inflightKey = (team) => `${team} inflight`;
|
|
38
|
+
export const releasedKey = (team) => `${team} released`;
|
|
39
|
+
export const SEND_LIFETIME_MS = 2 * 60_000;
|
|
40
|
+
export function ownReleases(before, now, snapAt = Date.now()) {
|
|
41
|
+
const o = (x) => (x && typeof x === "object" && !Array.isArray(x) ? x : {});
|
|
42
|
+
const b = o(before), n = o(now);
|
|
43
|
+
const out = new Set();
|
|
44
|
+
for (const [k, v] of Object.entries(n)) {
|
|
45
|
+
if (!k.endsWith(" released") || !Array.isArray(v))
|
|
46
|
+
continue;
|
|
47
|
+
const team = k.slice(0, -" released".length);
|
|
48
|
+
const was = b[inflightKey(team)];
|
|
49
|
+
if (!Array.isArray(was))
|
|
50
|
+
continue;
|
|
51
|
+
const stored = new Set([...(Array.isArray(b[storedKey(team)]) ? b[storedKey(team)] : []), ...(Array.isArray(n[storedKey(team)]) ? n[storedKey(team)] : [])]);
|
|
52
|
+
for (const x of v) {
|
|
53
|
+
if (typeof x !== "string")
|
|
54
|
+
continue;
|
|
55
|
+
const [ref, id] = x.split(" ");
|
|
56
|
+
if (!ref || !id || stored.has(ref))
|
|
57
|
+
continue;
|
|
58
|
+
const fresh = was.some((w) => {
|
|
59
|
+
if (typeof w !== "string")
|
|
60
|
+
return false;
|
|
61
|
+
const [wr, wi, at] = w.split(" ");
|
|
62
|
+
return wr === ref && wi === id && Number.isFinite(Number(at)) && Number(at) <= snapAt + 60_000 && snapAt - Number(at) <= SEND_LIFETIME_MS;
|
|
63
|
+
});
|
|
64
|
+
if (fresh)
|
|
65
|
+
out.add(`${team}|${ref}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
export const storedKey = (team) => `${team} stored`;
|
|
71
|
+
export function storedIn(h) {
|
|
72
|
+
const out = [];
|
|
73
|
+
for (const [k, l] of Object.entries(readAll(h))) {
|
|
74
|
+
if (!k.endsWith(" stored") || !Array.isArray(l))
|
|
75
|
+
continue;
|
|
76
|
+
for (const ref of l)
|
|
77
|
+
if (typeof ref === "string")
|
|
78
|
+
out.push({ team: k.slice(0, -" stored".length), ref });
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
29
82
|
export function handledIn(h) {
|
|
30
83
|
return [...new Set(Object.values(readAll(h)).flatMap((l) => (Array.isArray(l) ? l : [])).filter((x) => typeof x === "string" && x.startsWith("handled:")))];
|
|
31
84
|
}
|
|
@@ -41,7 +94,9 @@ export function markContinued(space, id, home) {
|
|
|
41
94
|
const all = readAll(home);
|
|
42
95
|
const list = (all[space] ?? []).filter((x) => x !== id);
|
|
43
96
|
list.push(id);
|
|
44
|
-
|
|
97
|
+
if (WORKER_MARK.test(id))
|
|
98
|
+
markedHere.add(id);
|
|
99
|
+
all[space] = capped(list);
|
|
45
100
|
mkdirSync(dirname(p), { recursive: true });
|
|
46
101
|
writeWhole(p, JSON.stringify(all));
|
|
47
102
|
};
|
package/dist/decision-ui.js
CHANGED
|
@@ -127,13 +127,15 @@ export function answerOptions(body) {
|
|
|
127
127
|
if (at < 0)
|
|
128
128
|
return [];
|
|
129
129
|
const tail = body.slice(at).replace(/^[^:—-]*[:—-]/, " ");
|
|
130
|
-
const
|
|
131
|
-
const span =
|
|
130
|
+
const ends = [tail.search(/\n\s*\n(?!\s*(?:\(?[a-d1-4][).]))/i), tail.search(/(?:[.!?]\s+|\n\s*)(?:I(?:'d| would)? recommend|Recommend(?:ation|ed)?\b|Why\b)/i)].filter((n) => n > 0);
|
|
131
|
+
const span = ends.length ? tail.slice(0, Math.min(...ends) + 1) : tail;
|
|
132
|
+
const inline = !span.trim().includes("\n");
|
|
132
133
|
const parts = span.split(/(?:^|\s|\n)\(?([a-d]|[1-4])[).]\s+/i).slice(1);
|
|
133
134
|
const out = [];
|
|
134
135
|
for (let i = 0; i + 1 < parts.length; i += 2) {
|
|
135
136
|
const key = parts[i].toLowerCase();
|
|
136
|
-
const
|
|
137
|
+
const said = inline && i + 3 >= parts.length ? parts[i + 1].split(/(?<=[.!?])\s+(?=[A-Z])/)[0] : parts[i + 1];
|
|
138
|
+
const text = oneLine(said).replace(/[.;,]\s*$/, "").trim();
|
|
137
139
|
if (!text || out.some((o) => o.key === key))
|
|
138
140
|
break;
|
|
139
141
|
out.push({ key, text: text.length > 160 ? text.slice(0, 159).trimEnd() + "…" : text });
|
package/dist/doctor.js
CHANGED
|
@@ -8,7 +8,7 @@ import { FEEDBACK_ADDRESS } from "./feedback.js";
|
|
|
8
8
|
import { loadProfile, profileInitialized, reservedDomains, teamProfile, wakeMode } from "./profile.js";
|
|
9
9
|
import { inWokenRun, isApprovedWaker, loadPolicy, relayKnowsAdmitters, requestReadinessRecheck, unsandboxedAllowed } from "./worker-policy.js";
|
|
10
10
|
import { commandState } from "./command-state.js";
|
|
11
|
-
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
11
|
+
import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
12
12
|
import { homedir, platform } from "node:os";
|
|
13
13
|
import { dirname, join, resolve, sep } from "node:path";
|
|
14
14
|
import { expectedLauncher, managedLayout, runtimeNodeFit, runtimeVerdict } from "./managed.js";
|
|
@@ -27,7 +27,46 @@ 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 { realSys, serviceInstalled, servicesUnavailable } from "./service.js";
|
|
30
|
+
import { borrowedScheduler, realSys, serviceInstalled, servicesUnavailable } from "./service.js";
|
|
31
|
+
import { statusDir } from "./status-nudge.js";
|
|
32
|
+
import { CONN_FRESH_MS } from "./conn-report.js";
|
|
33
|
+
export function ownProcesses() {
|
|
34
|
+
const borrowed = (() => { try {
|
|
35
|
+
return borrowedScheduler();
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
} })();
|
|
40
|
+
const pids = new Set();
|
|
41
|
+
let worker = false;
|
|
42
|
+
if (!borrowed)
|
|
43
|
+
return { borrowed, pids, worker };
|
|
44
|
+
try {
|
|
45
|
+
const dir = statusDir();
|
|
46
|
+
for (const n of readdirSync(dir)) {
|
|
47
|
+
const m = /^conn-(mcp|notifier|worker)-(\d+)-[0-9a-f]{8}\.json$/.exec(n);
|
|
48
|
+
if (!m)
|
|
49
|
+
continue;
|
|
50
|
+
try {
|
|
51
|
+
const r = JSON.parse(readFileSync(join(dir, n), "utf8"));
|
|
52
|
+
if (typeof r.at !== "number" || Date.now() - r.at > CONN_FRESH_MS)
|
|
53
|
+
continue;
|
|
54
|
+
try {
|
|
55
|
+
process.kill(Number(m[2]), 0);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
pids.add(Number(m[2]));
|
|
61
|
+
if (m[1] === "worker")
|
|
62
|
+
worker = true;
|
|
63
|
+
}
|
|
64
|
+
catch { }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch { }
|
|
68
|
+
return { borrowed, pids, worker };
|
|
69
|
+
}
|
|
31
70
|
import { windowsDoctorRows, windowsFacts } from "./win-host.js";
|
|
32
71
|
import { hasPrebuilt } from "./helpers-build.js";
|
|
33
72
|
import { traySourcePath, TRAY_PREBUILT } from "./tray.js";
|
|
@@ -172,6 +211,12 @@ export async function doctor(projectDir) {
|
|
|
172
211
|
nodeSupported(process.versions.node)
|
|
173
212
|
? add("pass", "node", `v${process.versions.node}`, undefined, `v${process.versions.node}`)
|
|
174
213
|
: add("fail", "node", `v${process.versions.node} is too old`, "pantheon needs Node 22.13 or newer — node:sqlite, which the relay uses, is behind a flag through 22.12 — install a current Node LTS and re-run", `v${process.versions.node}, too old`);
|
|
214
|
+
{
|
|
215
|
+
const { loadPolicy, policyUnreadable, policyPath } = await import("./worker-policy.js");
|
|
216
|
+
if (policyUnreadable(loadPolicy())) {
|
|
217
|
+
add("fail", "policy", `${policyPath()} cannot be read (torn — a power loss during an older version's write — or not JSON), so the worker holds every unattended run and asks nothing`, "pantheon policy repair — it moves the file aside and says which noes and grants to give again", "policy file unreadable");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
175
220
|
{
|
|
176
221
|
const facts = runtimeFacts();
|
|
177
222
|
const v = runtimeVerdict(facts);
|
|
@@ -276,8 +321,11 @@ export async function doctor(projectDir) {
|
|
|
276
321
|
}
|
|
277
322
|
add("warn", "removed", `${w.by ? `${w.by} removed you` : "you were removed"} from "${w.name}" (${new Date(record.at).toISOString().slice(0, 10)}) — this machine stopped connecting to it and checks now and then (at most every 6 hours)`, `to come back, you need a new invite from someone in "${w.name}" (pantheon join <invite>) or for a member to let you back in (pantheon admit ${w.member}); to forget it here: ${w.leave}`, "removed from a team");
|
|
278
323
|
}
|
|
279
|
-
|
|
280
|
-
|
|
324
|
+
const briefIs = here.reason === "binding" && here.cfg ? briefState(here.repo?.root ?? projectDir, here.cfg) : "none";
|
|
325
|
+
if (briefIs === "newer")
|
|
326
|
+
add("warn", "team brief", "the Pantheon section in this repo's CLAUDE.md / AGENTS.md was written by a newer Pantheon than this one", "pantheon upgrade (pantheon install here leaves a newer section as it is)", "team brief newer");
|
|
327
|
+
if (briefIs === "older") {
|
|
328
|
+
add("warn", "team brief", "the Pantheon section in this repo's CLAUDE.md / AGENTS.md is from an older version", "pantheon install (here; it rewrites that section only — commit it so teammates get it too). A teammate on 0.34 or older who runs pantheon install puts the old one back: they run pantheon upgrade first", "team brief older");
|
|
281
329
|
}
|
|
282
330
|
if (here.repo && !here.repo.shared)
|
|
283
331
|
add("warn", "team", "this repo has no origin remote", "DELIVERED must name a commit a teammate can fetch; add a remote before delivering", "repo has no origin remote");
|
|
@@ -295,7 +343,7 @@ export async function doctor(projectDir) {
|
|
|
295
343
|
add("warn", "profile", `your profile claims ${vague.map((d) => `"${d}"`).join(", ")} — not a decision area, so no decision is ever routed by it`, "running pantheon setup drops it — name the areas you decide personally: pantheon setup --decides deployment,pricing (or --decides none); it is never published either way", "claims a catch-all decision area");
|
|
296
344
|
}
|
|
297
345
|
else {
|
|
298
|
-
add("warn", "profile", "no profile published — decisions cannot be routed to you, and a
|
|
346
|
+
add("warn", "profile", "no profile published — decisions cannot be routed to you, and a decision a teammate sends you arrives marked unverified", "pantheon profile set --name <you> --title <role> --human-required <domains you personally decide>", "none published");
|
|
299
347
|
}
|
|
300
348
|
const mcpFile = join(projectDir, ".mcp.json");
|
|
301
349
|
if (!existsSync(mcpFile)) {
|
|
@@ -363,8 +411,10 @@ export async function doctor(projectDir) {
|
|
|
363
411
|
add("pass", "git branch", branch);
|
|
364
412
|
}
|
|
365
413
|
const agents = ["claude", "codex", "cursor-agent", "copilot", "kiro-cli"].filter((a) => onPathNamed(a) || !!knownUserBinary(a));
|
|
414
|
+
const own = ownProcesses();
|
|
415
|
+
const workerRunningHere = () => workerProc().running && (!own.borrowed || own.worker);
|
|
366
416
|
const workerSetUp = (() => { try {
|
|
367
|
-
return serviceInstalled("worker") ||
|
|
417
|
+
return serviceInstalled("worker") || workerRunningHere();
|
|
368
418
|
}
|
|
369
419
|
catch {
|
|
370
420
|
return false;
|
|
@@ -376,7 +426,17 @@ export async function doctor(projectDir) {
|
|
|
376
426
|
const r = unattendedReadiness({ available: [] });
|
|
377
427
|
add("fail", "worker agent", r.says, r.fix, "no agent CLI for runs while away");
|
|
378
428
|
}
|
|
379
|
-
|
|
429
|
+
const marksBefore = await (async () => {
|
|
430
|
+
try {
|
|
431
|
+
const { signedOutNow, SIGNED_OUT_AGENTS } = await import("./signed-out.js");
|
|
432
|
+
return new Map(SIGNED_OUT_AGENTS.map((id) => [id, signedOutNow(id)]));
|
|
433
|
+
}
|
|
434
|
+
catch {
|
|
435
|
+
return new Map();
|
|
436
|
+
}
|
|
437
|
+
})();
|
|
438
|
+
const askedRecheck = !inWokenRun();
|
|
439
|
+
if (askedRecheck)
|
|
380
440
|
requestReadinessRecheck();
|
|
381
441
|
if (agents.length) {
|
|
382
442
|
try {
|
|
@@ -411,11 +471,11 @@ export async function doctor(projectDir) {
|
|
|
411
471
|
add("warn", "worker agent", e.message, "pantheon setup --agent <claude-code|codex|cursor|copilot|kiro> names one that is installed", "could not be chosen");
|
|
412
472
|
}
|
|
413
473
|
try {
|
|
414
|
-
const {
|
|
474
|
+
const { signedOutChecking, SIGNED_OUT_AGENTS } = await import("./signed-out.js");
|
|
415
475
|
const { SIGN_IN_FIX } = await import("./run-failure.js");
|
|
416
476
|
const { claudeTokenForRun } = await import("./agent-token.js");
|
|
417
477
|
for (const id of SIGNED_OUT_AGENTS) {
|
|
418
|
-
const m =
|
|
478
|
+
const m = marksBefore.get(id) ?? null;
|
|
419
479
|
if (!m) {
|
|
420
480
|
const c = signedOutChecking(id);
|
|
421
481
|
if (c)
|
|
@@ -424,7 +484,7 @@ export async function doctor(projectDir) {
|
|
|
424
484
|
}
|
|
425
485
|
const label = agentById(id)?.label ?? id;
|
|
426
486
|
const token = id === "claude-code" && !!claudeTokenForRun(undefined, {});
|
|
427
|
-
add("warn", "worker agent", `a run here at ${new Date(m.at).toISOString().slice(0, 16).replace("T", " ")} UTC found ${label} ${token ? "refusing the saved worker token" : "signed out"} ("${m.says}"), so teammates' requests wait`, token ? "make a new token (claude setup-token, then pantheon worker token), or remove it to use your own sign-in: pantheon worker token --remove"
|
|
487
|
+
add("warn", "worker agent", `a run here at ${new Date(m.at).toISOString().slice(0, 16).replace("T", " ")} UTC found ${label} ${token ? "refusing the saved worker token" : "signed out"} ("${m.says}"), so teammates' requests wait${askedRecheck ? " — the worker tries it once more now" : ""}`, token ? "make a new token (claude setup-token, then pantheon worker token), or remove it to use your own sign-in: pantheon worker token --remove"
|
|
428
488
|
: `${SIGN_IN_FIX[id] ?? "sign in to it again"}${id === "claude-code" ? " — or keep it signed in for a year: claude setup-token, then pantheon worker token" : ""}`, `${label} found signed out by a run`);
|
|
429
489
|
}
|
|
430
490
|
}
|
|
@@ -458,9 +518,13 @@ export async function doctor(projectDir) {
|
|
|
458
518
|
}
|
|
459
519
|
}
|
|
460
520
|
const budget = instructionBudget(cfg);
|
|
461
|
-
const fromProfile = budget.
|
|
521
|
+
const fromProfile = budget.profileChars;
|
|
462
522
|
const budgetLine = `${budget.chars} chars (~${budget.tokens} tokens) of session instructions per turn — ${budget.fixedChars} Pantheon's own${fromProfile > 0 ? `, ${fromProfile} from your profile (who you are, what you reserved)` : ""}; the ${budget.protocolChars}-char protocol arrives with the first tool call instead`;
|
|
463
|
-
|
|
523
|
+
const liveOver = budget.chars > 2_048;
|
|
524
|
+
add(budget.fixedChars > 1_000 || liveOver ? "warn" : "pass", "mcp context", budgetLine, liveOver ? `over 2,048 chars, which some Claude Code versions cut: a shorter title, fewer responsibilities or fewer reserved areas in your profile keeps it whole (pantheon profile show)`
|
|
525
|
+
: budget.fixedChars > 1_000 ? "Pantheon's own part used to be ~3,800 chars on every turn, and it competed with the work people asked for" : undefined, budgetLine);
|
|
526
|
+
const wokenLine = `${budget.wokenChars} chars in a woken run's instructions; the rules it must keep end at ${budget.wokenMustEnd} of 2,048; what you decide personally comes with each run's brief`;
|
|
527
|
+
add(budget.wokenMustEnd > 2_048 ? "warn" : "pass", "woken context", wokenLine, budget.wokenMustEnd > 2_048 ? "your member or team name is long enough that a host keeping 2,048 chars would cut the rules a woken run must keep" : undefined, wokenLine);
|
|
464
528
|
const approval = chosenApproval();
|
|
465
529
|
add("pass", "approval", approvalSummary(approval), `change with pantheon setup --ask-before-sending (or --approve-all); pantheon leave removes the Codex line`, approval);
|
|
466
530
|
const measured = await measureMcp({ cwd: projectDir });
|
|
@@ -474,7 +538,7 @@ export async function doctor(projectDir) {
|
|
|
474
538
|
const unbound = here.reason === "unbound" || here.reason === "stale";
|
|
475
539
|
const tools = toolsReport("error" in measured ? null : measured.tools, grantsSeen(projectDir), approval, { unbound });
|
|
476
540
|
add(tools.level, "mcp tools", tools.detail, tools.fix, tools.detail);
|
|
477
|
-
const windows = scanMcpWindows();
|
|
541
|
+
const windows = scanMcpWindows().filter((x) => !own.borrowed || own.pids.has(x.pid));
|
|
478
542
|
const w = describeWindows(windows, VERSION);
|
|
479
543
|
const live = windows.filter((x) => x.kind !== "orphan");
|
|
480
544
|
const byVersion = [...live.reduce((m, x) => m.set(x.running ?? "unknown", (m.get(x.running ?? "unknown") ?? 0) + 1), new Map())]
|
|
@@ -616,9 +680,13 @@ export async function doctor(projectDir) {
|
|
|
616
680
|
const { loadPins, pinsPath } = await import("./pins.js");
|
|
617
681
|
const { brokenStateFiles, brokenStateFix } = await import("./file-lock.js");
|
|
618
682
|
const { dirname } = await import("node:path");
|
|
619
|
-
const
|
|
683
|
+
const { GUARDED_FILES, loadPersistedGuard } = await import("./home-guard.js");
|
|
684
|
+
const broken = brokenStateFiles(dirname(pinsPath()), GUARDED_FILES);
|
|
620
685
|
if (broken.length)
|
|
621
686
|
add("fail", "signing", `${broken.join(", ")} in ${dirname(pinsPath())} cannot be read and written — they are what stops a request being run twice, so the worker holds every unattended run until they are fixed`, brokenStateFix(broken), "state files broken");
|
|
687
|
+
const waiting = loadPersistedGuard(dirname(pinsPath()))?.pending ?? [];
|
|
688
|
+
if (waiting.length)
|
|
689
|
+
add("fail", "signing", `a teammate's request locked ${waiting.join(", ")} while it ran, so Pantheon could not put back what it changed there — no unattended run starts until it can`, brokenStateFix(waiting), "a run's change not put back");
|
|
622
690
|
const all = loadPins();
|
|
623
691
|
if (all.corrupt)
|
|
624
692
|
add("fail", "signing", `${pinsPath()} could not be read — no message is trusted until it can be`, "restore it from a backup, or remove it to pin teammates' keys afresh (then check each with them: pantheon trust)", "keys.json unreadable");
|
|
@@ -638,7 +706,7 @@ export async function doctor(projectDir) {
|
|
|
638
706
|
add("warn", "signing", "this team's relay does not carry signatures yet (a relay before 0.31), so messages cannot be checked against their senders' keys", "upgrade the relay", "relay without signatures");
|
|
639
707
|
}
|
|
640
708
|
}
|
|
641
|
-
const workerUp =
|
|
709
|
+
const workerUp = workerRunningHere();
|
|
642
710
|
const mode = wakeMode(loadProfile(cfg));
|
|
643
711
|
const anyoneWhy = loadProfile(cfg).agent.wake_default === "anyone" ? "you chose \"anyone\"" : "\"anyone\" is the default";
|
|
644
712
|
const policy = loadPolicy();
|
|
@@ -807,7 +875,7 @@ export async function doctor(projectDir) {
|
|
|
807
875
|
}
|
|
808
876
|
}
|
|
809
877
|
const open = [...client.goals.values()].filter((g) => g.state !== "CLOSED");
|
|
810
|
-
const stateLine = `${client.head}
|
|
878
|
+
const stateLine = `${client.head} messages kept, ${open.length} open goal${open.length === 1 ? "" : "s"} — kept across relay restarts`;
|
|
811
879
|
add("pass", "state", stateLine, undefined, stateLine);
|
|
812
880
|
if (existsSync(join(projectDir, "pantheon-data", `${cfg.space}.jsonl`))) {
|
|
813
881
|
serviceInstalled("relay")
|