@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/cli.js
CHANGED
|
@@ -8,14 +8,14 @@ process.emitWarning = ((warning, ...rest) => {
|
|
|
8
8
|
});
|
|
9
9
|
import { randomBytes } from "node:crypto";
|
|
10
10
|
import { emailSuggestion, gitConfigValue, isGithubNoreply, pantheonCommand, signinCommand, usernameSuggestion } from "./onboard-defaults.js";
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
12
12
|
import { basename, dirname, isAbsolute, join, resolve } from "node:path";
|
|
13
13
|
import { PantheonClient } from "./client.js";
|
|
14
14
|
import { agentSpawn, CmdLineUnsafe } from "./which.js";
|
|
15
15
|
import { fromInvite, looksLikeInviteCode, resolveInviteCode, load, save, toInvite, toJoinLink, resolveFor, loadAll, identity, repoInfo, bindRepo, bindFolder, unbindRepo, findMembership, matchMembership, setDefaultSpace, removeMembership, configFor, CONFIG_DIR, CONFIG_PATH, DEFAULT_RELAY, resolveForHook } from "./config.js";
|
|
16
16
|
import { fmtLimit, lastSlotNotice, ownedTeamsIn, spaceLimitAdvice } from "./plans.js";
|
|
17
17
|
import { validEmail, validUsername } from "./accounts.js";
|
|
18
|
-
import { clipWords, goalStateWord, OWED_WORDS, plainError, plainRequest } from "./plain.js";
|
|
18
|
+
import { clipWords, goalStateWord, OWED_WORDS, panelLine, plainError, plainRequest } from "./plain.js";
|
|
19
19
|
import { install, launcher, installForUser, windowsRepoOverrides, agentAsksOnce } from "./install.js";
|
|
20
20
|
import { Relay } from "./relay.js";
|
|
21
21
|
import { runMcp } from "./mcp.js";
|
|
@@ -33,7 +33,7 @@ import { FEEDBACK_ADDRESS } from "./feedback.js";
|
|
|
33
33
|
import { menubarProc, notifierProc, relayProc, runBy, workerProc, workerFlagRunMinutes, wiring, logFileFor, dataSummary, stopProc, statFile, elapsed, windowsProcessInfo } from "./machine.js";
|
|
34
34
|
import { assess } from "./untrusted.js";
|
|
35
35
|
import { report as spendReport, recentRuns } from "./spend.js";
|
|
36
|
-
import { renderBrief, renderTeam } from "./brief.js";
|
|
36
|
+
import { answeredQuestions, renderBrief, renderTeam } from "./brief.js";
|
|
37
37
|
import { resolveDataDir, saveAll, withConfigLock } from "./config.js";
|
|
38
38
|
import { currentPlan, installNetwork, redactProxy, redactText, normalizeProxy, proxyToRemember, describeNetError, describeRelayFailure, checkRelayCertificate, interceptedText, interceptionExplanation, relayJson } from "./network.js";
|
|
39
39
|
import { createInterface } from "node:readline";
|
|
@@ -45,7 +45,7 @@ import { start as qsStart, join as qsJoin, wireUp, teamNameFor, deviceLabel, bin
|
|
|
45
45
|
import { agentsNeedingUnsandboxed as agentsNeedingUnsandboxedSync, recordedAgent, unattendedReadiness } from "./agents.js";
|
|
46
46
|
import { agentProblem, PROBLEM_LEAD } from "./readiness-alert.js";
|
|
47
47
|
import { stripControls } from "./notice.js";
|
|
48
|
-
import { pickupEstimate } from "./pickup.js";
|
|
48
|
+
import { awaitingDecision, pickupEstimate } from "./pickup.js";
|
|
49
49
|
import { loadPolicy, requestReadinessRecheck, unsandboxedAllowed, savePolicy, MODE_LABELS, AUTOPILOT_PLAN_NOTE, effectiveMode, parseMode, describeMode } from "./worker-policy.js";
|
|
50
50
|
import { alreadyMemberLine, askedLine, configureLines, fetchSeats, inUseLine, offerSeats, seatsForTeam, seatsToMove, startGate, RECOVER_WAITING_EXIT } from "./recover-offer.js";
|
|
51
51
|
import { hyphenateSpaces, shellArg, teamNameProblem } from "./team-name.js";
|
|
@@ -62,6 +62,7 @@ import { updateBanner } from "./update-check.js";
|
|
|
62
62
|
import { inWokenRun } from "./worker-policy.js";
|
|
63
63
|
import { childNodeFlags, joinInstructions, managedLayout, relayServesInstaller } from "./managed.js";
|
|
64
64
|
import { spawn } from "node:child_process";
|
|
65
|
+
import { QUEUED_SEND_DEADLINE_MS } from "./hud-queue.js";
|
|
65
66
|
const argv = process.argv.slice(2);
|
|
66
67
|
for (let i = argv.length - 1; i >= 1; i--) {
|
|
67
68
|
const m = /^(--[a-z][a-z0-9-]*)=(.*)$/i.exec(argv[i]);
|
|
@@ -909,6 +910,179 @@ async function printJoinSteps(invite, relay) {
|
|
|
909
910
|
console.error(D(` ${j.outro}`));
|
|
910
911
|
}
|
|
911
912
|
const HUD_ACTION_MAX_AGE_MS = 30_000;
|
|
913
|
+
function emptyThreadStep(goal) {
|
|
914
|
+
return `Nothing was asked. An empty conversation was opened for it and is still open — it holds nothing and can stay; to close it, in a terminal: pantheon say CLOSE "nothing to answer" --goal ${goal}`;
|
|
915
|
+
}
|
|
916
|
+
async function localStepFor(pending, body, decisionId) {
|
|
917
|
+
if (!pending)
|
|
918
|
+
return null;
|
|
919
|
+
const { parseGrantAnswer, CAPABILITY_ARGS } = await import("./worker-policy.js");
|
|
920
|
+
const v = parseGrantAnswer(body);
|
|
921
|
+
if (!v)
|
|
922
|
+
return null;
|
|
923
|
+
const again = `answer it again${decisionId ? `: pantheon approvals answer ${decisionId} "${v === "deny" ? "deny" : v === "allow-once" ? "allow once" : "allow always"}"` : ""}`;
|
|
924
|
+
const check = (there) => `Check the thread: if your answer is not there, ${again}; if it is there, ${there}.`;
|
|
925
|
+
if ("wake" in pending) {
|
|
926
|
+
const m = pending.wake.member;
|
|
927
|
+
if (v === "allow-once")
|
|
928
|
+
return { apply: null, check: check(`it was not applied here, and there is no one-time command — ${m}'s next request asks you again`) };
|
|
929
|
+
const cmd = `pantheon wake ${v === "deny" ? "deny" : "allow"} ${m}`;
|
|
930
|
+
return { apply: cmd, check: check(`run ${cmd} here`) };
|
|
931
|
+
}
|
|
932
|
+
const arg = CAPABILITY_ARGS[pending.ask[0]];
|
|
933
|
+
if (v === "allow-once")
|
|
934
|
+
return { apply: null, check: check("it was not applied here, and there is no one-time command — your agent asks again when it next needs it") };
|
|
935
|
+
if (v === "deny")
|
|
936
|
+
return { apply: null, check: check("nothing ran: your agent stays without commands here, and may ask again later") };
|
|
937
|
+
const cmd = `pantheon policy grant ${arg}`;
|
|
938
|
+
return { apply: cmd, check: check(`run ${cmd} here`) };
|
|
939
|
+
}
|
|
940
|
+
async function rememberApplied(cfg, answerId, g) {
|
|
941
|
+
if (!g || ("applied" in g && !g.applied))
|
|
942
|
+
return;
|
|
943
|
+
const { CAPABILITY_ARGS } = await import("./worker-policy.js");
|
|
944
|
+
const cmd = "wake" in g && g.wake ? `pantheon wake ${g.verdict === "deny" ? "allow" : "deny"} ${g.wake.member}`
|
|
945
|
+
: "cap" in g && g.cap ? `pantheon policy ${g.verdict === "deny" ? "grant" : "revoke"} ${CAPABILITY_ARGS[g.cap]}` : null;
|
|
946
|
+
if (!cmd)
|
|
947
|
+
return;
|
|
948
|
+
try {
|
|
949
|
+
const { teamPinId } = await import("./pins.js");
|
|
950
|
+
const { markContinued } = await import("./continued.js");
|
|
951
|
+
markContinued(`${teamPinId(cfg)} applied`, `${answerId} ${cmd}`);
|
|
952
|
+
}
|
|
953
|
+
catch { }
|
|
954
|
+
}
|
|
955
|
+
async function appliedChange(cfg, answerId) {
|
|
956
|
+
try {
|
|
957
|
+
const { teamPinId } = await import("./pins.js");
|
|
958
|
+
const { loadContinued } = await import("./continued.js");
|
|
959
|
+
for (const x of loadContinued(`${teamPinId(cfg)} applied`))
|
|
960
|
+
if (x.startsWith(`${answerId} `))
|
|
961
|
+
return x.slice(answerId.length + 1);
|
|
962
|
+
}
|
|
963
|
+
catch { }
|
|
964
|
+
return null;
|
|
965
|
+
}
|
|
966
|
+
const retractRefusal = (cmd) => `that answer changed this computer's settings, so it is not taken back from here — taking it back on the record would leave this computer as it is. To change it, run ${cmd}`;
|
|
967
|
+
const notAppliedWords = (st) => `Not applied on this computer: a run of your agent is going. ${st?.apply ? `Once it is done, run ${st.apply} here.` : "It asks again when it next needs to; answer it then."}`;
|
|
968
|
+
async function holdRuns(o = {}) {
|
|
969
|
+
const { takeRunLease, releaseRunLease, runInFlight, guardHeld, guardMinutesLeft, writePersonHold, releasePersonHold } = await import("./worker.js");
|
|
970
|
+
{
|
|
971
|
+
const { loadPersistedGuard } = await import("./home-guard.js");
|
|
972
|
+
const { brokenStateFix } = await import("./file-lock.js");
|
|
973
|
+
if (loadPersistedGuard(CONFIG_DIR)?.pending?.length) {
|
|
974
|
+
const { recoverGuardHere } = await import("./worker.js");
|
|
975
|
+
await recoverGuardHere(CONFIG_DIR);
|
|
976
|
+
}
|
|
977
|
+
const waiting = loadPersistedGuard(CONFIG_DIR)?.pending ?? [];
|
|
978
|
+
if (waiting.length)
|
|
979
|
+
return { busy: `a teammate's request locked ${waiting.join(", ")} while it ran, so Pantheon could not put back what it changed there — and nothing about this computer changes until it can (a change made now would be undone then). Nothing was sent. What to do: ${brokenStateFix(waiting)}; then try again` };
|
|
980
|
+
}
|
|
981
|
+
const until = Date.now() + (o.waitMs ?? 20_000);
|
|
982
|
+
let token = null;
|
|
983
|
+
const release = () => {
|
|
984
|
+
if (token) {
|
|
985
|
+
try {
|
|
986
|
+
releaseRunLease(CONFIG_DIR, token);
|
|
987
|
+
}
|
|
988
|
+
catch { }
|
|
989
|
+
token = null;
|
|
990
|
+
}
|
|
991
|
+
releasePersonHold(CONFIG_DIR);
|
|
992
|
+
};
|
|
993
|
+
process.once("exit", release);
|
|
994
|
+
const going = () => !!runInFlight(CONFIG_DIR) || guardHeld(CONFIG_DIR);
|
|
995
|
+
let said = false;
|
|
996
|
+
for (;;) {
|
|
997
|
+
writePersonHold(CONFIG_DIR);
|
|
998
|
+
try {
|
|
999
|
+
const l = takeRunLease(CONFIG_DIR, "a person answering a question here");
|
|
1000
|
+
if ("token" in l)
|
|
1001
|
+
token = l.token;
|
|
1002
|
+
}
|
|
1003
|
+
catch { }
|
|
1004
|
+
if (token && !going())
|
|
1005
|
+
return { release, clear: () => !going() };
|
|
1006
|
+
if (token) {
|
|
1007
|
+
try {
|
|
1008
|
+
releaseRunLease(CONFIG_DIR, token);
|
|
1009
|
+
}
|
|
1010
|
+
catch { }
|
|
1011
|
+
token = null;
|
|
1012
|
+
}
|
|
1013
|
+
if (Date.now() >= until)
|
|
1014
|
+
break;
|
|
1015
|
+
if (!said && o.say) {
|
|
1016
|
+
said = true;
|
|
1017
|
+
o.say("Your agent is in the middle of a request on this computer — waiting for it to finish before your answer goes (nothing is sent until then)…");
|
|
1018
|
+
}
|
|
1019
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
1020
|
+
}
|
|
1021
|
+
const left = (() => { try {
|
|
1022
|
+
return guardMinutesLeft(CONFIG_DIR);
|
|
1023
|
+
}
|
|
1024
|
+
catch {
|
|
1025
|
+
return null;
|
|
1026
|
+
} })();
|
|
1027
|
+
release();
|
|
1028
|
+
const by = left ? new Date(Date.now() + left * 60_000).toTimeString().slice(0, 5) : null;
|
|
1029
|
+
return { busy: `your agent is in the middle of a request on this computer, and this question is about this computer — an answer given now would be taken back when that run ends. Nothing was sent. What to do: answer it once the run is done${by ? ` — by ${by} at the latest` : ""} (pantheon status shows when), or Stop the run first` };
|
|
1030
|
+
}
|
|
1031
|
+
async function answerOnRecord(cfg, refs, body) {
|
|
1032
|
+
if (!refs.length)
|
|
1033
|
+
return [];
|
|
1034
|
+
const c = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
1035
|
+
const done = [];
|
|
1036
|
+
try {
|
|
1037
|
+
const got = await Promise.race([c.connect().then(() => true, () => false), new Promise((r) => setTimeout(() => r(false), 5_000))]);
|
|
1038
|
+
if (!got)
|
|
1039
|
+
return done;
|
|
1040
|
+
for (const ref of refs) {
|
|
1041
|
+
if (!c.obligations.some((o) => o.kind === "HUMAN" && o.ref === ref))
|
|
1042
|
+
continue;
|
|
1043
|
+
try {
|
|
1044
|
+
await c.sendSettled({ act: "ANSWER", ref, goal: null, after_seq: c.readSeq, body, meta: { surface: "cli" } });
|
|
1045
|
+
done.push(ref);
|
|
1046
|
+
}
|
|
1047
|
+
catch { }
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
finally {
|
|
1051
|
+
try {
|
|
1052
|
+
c.close();
|
|
1053
|
+
}
|
|
1054
|
+
catch { }
|
|
1055
|
+
}
|
|
1056
|
+
return done;
|
|
1057
|
+
}
|
|
1058
|
+
function runWhileSaid(a) {
|
|
1059
|
+
const id = typeof a?.decision === "string" && /^o_[a-z0-9]{6,40}$/.test(a.decision) ? a.decision : null;
|
|
1060
|
+
const said = a?.action === "reply" && a.kind === "ANSWER" && typeof a.body === "string" && /^[A-Za-z0-9 ,.'—-]{1,60}$/.test(a.body) ? a.body : null;
|
|
1061
|
+
const how = id ? `pantheon approvals answer ${id} "${said ?? "your answer"}"` : "pantheon approvals";
|
|
1062
|
+
return `your agent is running a request on this computer right now, and a click made while it runs can't be told from one it made — so nothing was sent. Answer it in a terminal instead: ${how} (it waits for the run to finish), or click again once the run is done`;
|
|
1063
|
+
}
|
|
1064
|
+
function panelRefusal(message, fullWords) {
|
|
1065
|
+
if (/^BUDGET_SPENT:/.test(message))
|
|
1066
|
+
return `${fullWords}. (BUDGET_SPENT)`;
|
|
1067
|
+
if (/^PEER_TURN:/.test(message)) {
|
|
1068
|
+
const m = /^PEER_TURN: you have sent (\d+) acts? in a row in "([\s\S]*)"\. Wait for a peer\b/.exec(message);
|
|
1069
|
+
const goal = m?.[2];
|
|
1070
|
+
const n = m?.[1];
|
|
1071
|
+
return `${goal ? `"${goal}"` : "This conversation"} has had ${n ?? "several"} messages in a row from you and your agent, with no reply from a teammate yet. Wait for a teammate to reply there, then send this again. (PEER_TURN)`;
|
|
1072
|
+
}
|
|
1073
|
+
return plainError(message);
|
|
1074
|
+
}
|
|
1075
|
+
function queuedDeadline() {
|
|
1076
|
+
let sending = false;
|
|
1077
|
+
const t = setTimeout(() => {
|
|
1078
|
+
console.log(sending
|
|
1079
|
+
? "unconfirmed: it took too long to hear back — it may have been sent. Check the thread before sending it again."
|
|
1080
|
+
: "not sent: the relay took too long to answer — nothing was sent. Try again in a moment.");
|
|
1081
|
+
process.exit(1);
|
|
1082
|
+
}, Math.min(QUEUED_SEND_DEADLINE_MS, Math.max(1_000, Number(process.env["PANTHEON_QUEUED_DEADLINE_MS"]) || QUEUED_SEND_DEADLINE_MS)));
|
|
1083
|
+
t.unref?.();
|
|
1084
|
+
return { sending: () => { sending = true; }, done: () => clearTimeout(t) };
|
|
1085
|
+
}
|
|
912
1086
|
function unattendedProject() {
|
|
913
1087
|
if (argv.includes("--no-worker"))
|
|
914
1088
|
return { project: null, how: "off" };
|
|
@@ -1108,12 +1282,27 @@ async function membershipGate() {
|
|
|
1108
1282
|
}
|
|
1109
1283
|
async function setupBusy() {
|
|
1110
1284
|
try {
|
|
1111
|
-
const { runInFlight, guardHeld,
|
|
1285
|
+
const { runInFlight, guardHeld, recoverGuardHere, putBackSaid } = await import("./worker.js");
|
|
1286
|
+
{
|
|
1287
|
+
const { loadPersistedGuard } = await import("./home-guard.js");
|
|
1288
|
+
const { brokenStateFix } = await import("./file-lock.js");
|
|
1289
|
+
if (loadPersistedGuard(CONFIG_DIR)?.pending?.length)
|
|
1290
|
+
await recoverGuardHere(CONFIG_DIR);
|
|
1291
|
+
const waiting = loadPersistedGuard(CONFIG_DIR)?.pending ?? [];
|
|
1292
|
+
if (waiting.length)
|
|
1293
|
+
return `A teammate's request locked ${waiting.join(", ")} while it ran, so Pantheon could not put back what it changed there — and nothing in your setup changes until it can (a change made now would be undone then). What to do: ${brokenStateFix(waiting)}; then run this again.`;
|
|
1294
|
+
}
|
|
1112
1295
|
if (runInFlight(CONFIG_DIR) || guardHeld(CONFIG_DIR))
|
|
1113
1296
|
return await runBusySaid();
|
|
1114
|
-
const r =
|
|
1297
|
+
const r = await recoverGuardHere(CONFIG_DIR);
|
|
1298
|
+
if (r.outcome === "unreachable")
|
|
1299
|
+
return `Your worker stopped in the middle of a teammate's request, and putting Pantheon's files back needs a word from the relay first, which could not be reached. Nothing changed. What to do: try again once you are online.`;
|
|
1115
1300
|
if (r.outcome === "restored" && r.said.length)
|
|
1116
1301
|
console.log(`Your worker stopped in the middle of a teammate's request. ${putBackSaid(r.said)}`);
|
|
1302
|
+
if (r.outcome === "pending") {
|
|
1303
|
+
const { brokenStateFix } = await import("./file-lock.js");
|
|
1304
|
+
return `A teammate's request locked ${r.rels.join(", ")} while it ran, so Pantheon could not put back what it changed there — and nothing in your setup changes until it can. What to do: ${brokenStateFix(r.rels)}; then run this again.`;
|
|
1305
|
+
}
|
|
1117
1306
|
if (r.outcome === "failed" && !r.dropped)
|
|
1118
1307
|
return `Pantheon could not yet put back what a teammate's request changed while your worker stopped mid-run (${r.why}). Try again in a moment.`;
|
|
1119
1308
|
if (r.outcome === "failed")
|
|
@@ -1728,7 +1917,7 @@ const COMMAND_FLAGS = {
|
|
|
1728
1917
|
"open-in": "[app | terminal] (no argument: where they open now)",
|
|
1729
1918
|
trust: "[<member>] --yes --space <team>",
|
|
1730
1919
|
recover: "[<team>] | withdraw <team> | confirm <member> | cancel <member> [--yes] --space <team> --no-worker --no-hook --no-notifications --no-menubar\n exits 3 when the move was asked for and waits for a teammate (or a day); 0 when it moved",
|
|
1731
|
-
say: "<ACT> <text> --to <member>[,<member>] --goal <id> --ref <id | seq | last> --summary '<one line>' --domains <a,b> --branch --commit --remote (DELIVERED) --space <team>",
|
|
1920
|
+
say: "<ACT> <text> --to <member>[,<member>] --goal <id> --ref <id | seq | last> --summary '<one line>' --question (an ASK with no goal: a simple question, one answer and done) --domains <a,b> --branch --commit --remote (DELIVERED) --space <team>",
|
|
1732
1921
|
goal: "list | open \"<title>\" --with <member>[,…] [--acceptance \"…\"] [--deadline <ISO time>] [--list] | close <id> \"<summary>\"",
|
|
1733
1922
|
history: "--goal <id> --from <member> --last <n> --since <seq> --short --presence --json",
|
|
1734
1923
|
usage: "--space <team> --days <n> --json",
|
|
@@ -1740,6 +1929,7 @@ const COMMAND_FLAGS = {
|
|
|
1740
1929
|
worker: "--agent <claude-code|codex|cursor|copilot|kiro|auto> --persona <name> --project <dir> --allow-bash --max-runs <n> --max-runs-day <n> --run-minutes <5-180> --grace <s> --once (token: --status --remove --no-check)",
|
|
1741
1930
|
service: "install [relay|worker|notifier|menubar] | restart <kind> | uninstall <kind> --project <dir> --allow-bash --run-minutes <5-180> --fresh (a worker's flags from these alone, not kept)",
|
|
1742
1931
|
doctor: "--share --project <dir>",
|
|
1932
|
+
status: "--clear-safety (once the safety warnings it shows are handled)",
|
|
1743
1933
|
relay: "--port <n> --host <address> --data <dir> (relay leftovers --data <dir> [--json]: read-only report)",
|
|
1744
1934
|
use: "<team> --here --yes · pantheon use --unbind (this folder or repo bound to no team again)",
|
|
1745
1935
|
repo: "add [--base <branch>] | list [--all] | find [<folder>] [--recents] [--yes]",
|
|
@@ -1750,7 +1940,7 @@ const COMMAND_FLAGS = {
|
|
|
1750
1940
|
setup: "--questions --mode <autopilot|here> (and every answer as a flag, with --yes)",
|
|
1751
1941
|
mode: "[autopilot | here]",
|
|
1752
1942
|
changes: "[list | review | approve <id> | keep <id>] --history",
|
|
1753
|
-
board: "--open --url --watch --keep --stop --focus <id>",
|
|
1943
|
+
board: "--open --url --watch --keep --stop --focus <id> [--space <team>]",
|
|
1754
1944
|
};
|
|
1755
1945
|
const HELP_OPAQUE = new Set(["mcp", "hook", "pending", "tray-status", "help", "version", "-v", "--help", "-h"]);
|
|
1756
1946
|
function rememberWorkingProxy() {
|
|
@@ -2595,7 +2785,7 @@ async function main() {
|
|
|
2595
2785
|
await new Promise((r) => setTimeout(r, 350));
|
|
2596
2786
|
const peers = client.roster.filter((m) => m.id !== cfg.member);
|
|
2597
2787
|
const { termSafe } = await import("./board.js");
|
|
2598
|
-
console.log(`${B(cfg.space)} you are ${C(cfg.member)} ${D(cfg.relay)} ${D(`${client.head}
|
|
2788
|
+
console.log(`${B(cfg.space)} you are ${C(cfg.member)} ${D(cfg.relay)} ${D(`${client.head} messages`)}\n`);
|
|
2599
2789
|
if (client.plan)
|
|
2600
2790
|
console.log(D(` ${client.plan.name} plan · ${client.plan.usage.spaces} of ${fmtLimit(client.plan.limits.spaces)} spaces created · ${client.plan.usage.members} of ${fmtLimit(client.plan.limits.members)} people here${client.plan.limits.wake ? "" : " · no unattended workers"}`) + "\n");
|
|
2601
2791
|
console.log(B("members"));
|
|
@@ -2636,13 +2826,24 @@ async function main() {
|
|
|
2636
2826
|
};
|
|
2637
2827
|
const human = owed.filter((o) => o.kind === "HUMAN");
|
|
2638
2828
|
const between = owed.filter((o) => o.kind !== "HUMAN");
|
|
2829
|
+
const readActs = new Map();
|
|
2830
|
+
await Promise.all(human.filter((h) => h.owner.replace(/^human:/, "") !== cfg.member && !client.seenAct(h.ref)).slice(0, 8).map(async (h) => {
|
|
2831
|
+
try {
|
|
2832
|
+
const res = await signedRead(cfg, "/act", { id: h.ref }, { timeoutMs: 2_000 });
|
|
2833
|
+
const a = res.ok ? (await res.json()).act : undefined;
|
|
2834
|
+
if (a?.id === h.ref)
|
|
2835
|
+
readActs.set(h.ref, a);
|
|
2836
|
+
}
|
|
2837
|
+
catch { }
|
|
2838
|
+
}));
|
|
2839
|
+
const actOf = (id) => client.seenAct(id) ?? readActs.get(id) ?? null;
|
|
2639
2840
|
console.log(`\n${B("waiting on a person")}`);
|
|
2640
2841
|
if (!human.length)
|
|
2641
2842
|
console.log(` ${D("(nothing waiting on you)")}`);
|
|
2642
2843
|
for (const o of human) {
|
|
2643
2844
|
const who = o.owner.replace(/^human:/, "");
|
|
2644
2845
|
const stale = Date.now() - o.created_at > 3_600_000;
|
|
2645
|
-
const askAct =
|
|
2846
|
+
const askAct = actOf(o.ref);
|
|
2646
2847
|
const wakeAsk = askAct?.from === who ? askAct.meta?.wake_ask : undefined;
|
|
2647
2848
|
if (who !== cfg.member && typeof wakeAsk === "string") {
|
|
2648
2849
|
console.log(` ${who.padEnd(14)}${ageOf(o.created_at).padEnd(6)} ${D(`is being asked on their machine whether ${wakeAsk === cfg.member ? "you" : wakeAsk} may start work there while they are away`)}`);
|
|
@@ -2659,11 +2860,12 @@ async function main() {
|
|
|
2659
2860
|
for (const o of between) {
|
|
2660
2861
|
console.log(` ${o.owner.padEnd(14)}${ageOf(o.created_at).padEnd(6)} owes ${OWED_WORDS[o.kind] ?? o.kind.toLowerCase()}: ${clipWords(plainRequest(o.body.split("\n")[0], cfg.member), 130)} ${D(o.ref)}`);
|
|
2661
2862
|
const peer = o.owner !== cfg.member && o.kind !== "DELIVER" ? client.roster.find((m) => m.id === o.owner) ?? { id: o.owner, sessions: [] } : null;
|
|
2863
|
+
const wakeAsked = !!peer && human.some((h) => h.owner.replace(/^human:/, "") === o.owner && h.about === o.ref && (() => { const a = actOf(h.ref); return a?.from === o.owner && a.meta?.wake_ask === cfg.member; })());
|
|
2662
2864
|
if (peer)
|
|
2663
|
-
console.log(` ${" ".repeat(20)} ${D(termSafe(pickupEstimate(peer, { now: client.relayNow(), about: { ref: o.ref, goal: o.goal }, ...(myMayWake !== undefined ? { mayWake: myMayWake } : {}) }).says))}`);
|
|
2865
|
+
console.log(` ${" ".repeat(20)} ${D(termSafe(pickupEstimate(peer, { now: client.relayNow(), about: { ref: o.ref, goal: o.goal }, claimedBy: o.claimed_by ?? null, wakeAsked, deciding: awaitingDecision(client.obligations, o), ...(myMayWake !== undefined ? { mayWake: myMayWake } : {}) }).says))}`);
|
|
2664
2866
|
}
|
|
2665
2867
|
if (human.length || between.length || goals.some((g) => g.state !== "CLOSED")) {
|
|
2666
|
-
console.log(D(`\n read one in full: pantheon show <id> ·
|
|
2868
|
+
console.log(D(`\n read one in full: pantheon show <id> · answer your decisions: pantheon approvals · a whole goal: pantheon history --goal <id>`));
|
|
2667
2869
|
}
|
|
2668
2870
|
client.close();
|
|
2669
2871
|
};
|
|
@@ -2678,6 +2880,26 @@ async function main() {
|
|
|
2678
2880
|
if (problem)
|
|
2679
2881
|
console.log(`\x1b[33m${B(`${PROBLEM_LEAD}:`)} ${problem}\x1b[0m\n`);
|
|
2680
2882
|
}
|
|
2883
|
+
{
|
|
2884
|
+
const pol = loadPolicy();
|
|
2885
|
+
const notes = Object.entries(pol.safetyNotes ?? {});
|
|
2886
|
+
if (argv.includes("--clear-safety")) {
|
|
2887
|
+
if (inWokenRun())
|
|
2888
|
+
die("a woken run cannot clear this computer's safety warnings — a person has to");
|
|
2889
|
+
if (notes.length) {
|
|
2890
|
+
delete pol.safetyNotes;
|
|
2891
|
+
savePolicy(pol);
|
|
2892
|
+
}
|
|
2893
|
+
console.log(notes.length ? `${C("cleared")} ${notes.length} safety warning${notes.length === 1 ? "" : "s"} on this computer` : D("no safety warnings on this computer"));
|
|
2894
|
+
return;
|
|
2895
|
+
}
|
|
2896
|
+
if (notes.length) {
|
|
2897
|
+
console.log(`\x1b[33m${B(`Safety warning${notes.length === 1 ? "" : "s"} that could not reach your board:`)}\x1b[0m`);
|
|
2898
|
+
for (const [, n] of notes.sort((x, y) => x[1].at - y[1].at))
|
|
2899
|
+
console.log(` ${n.says}\n What to do: ${n.fix}`);
|
|
2900
|
+
console.log(D(` once handled: pantheon status --clear-safety\n`));
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2681
2903
|
for (const l of setupStatusLines())
|
|
2682
2904
|
console.log(l);
|
|
2683
2905
|
const allGone = ts.length > 0 && ts.every((c) => !!RM.goneOf(teamOf(c)));
|
|
@@ -2714,6 +2936,7 @@ async function main() {
|
|
|
2714
2936
|
id: o.id, kind: o.kind, body: o.body, created_at: o.created_at,
|
|
2715
2937
|
})),
|
|
2716
2938
|
recentRuns: recentRuns(86_400_000, undefined, 12, { teams: [client.spaceId, cfg.spaceId, cfg.space], member: cfg.member }),
|
|
2939
|
+
answers: answeredQuestions(await fetchHistory(cfg).catch(() => []), (g) => client.goals.get(g)?.kind === "question", cfg.member),
|
|
2717
2940
|
}));
|
|
2718
2941
|
client.close();
|
|
2719
2942
|
}
|
|
@@ -2960,13 +3183,25 @@ async function main() {
|
|
|
2960
3183
|
ref = rr.id;
|
|
2961
3184
|
goalArg = goalArg ?? rr.goal;
|
|
2962
3185
|
}
|
|
3186
|
+
if (act === "RETRACT" && ref) {
|
|
3187
|
+
const cmd = await appliedChange(cfg, ref);
|
|
3188
|
+
if (cmd) {
|
|
3189
|
+
client.close();
|
|
3190
|
+
die(`Not sent: ${retractRefusal(cmd)}.`);
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
2963
3193
|
let questionNote = "";
|
|
2964
3194
|
let questionGoal = null;
|
|
2965
3195
|
if (act === "ASK" && !goalArg && !ref && to) {
|
|
2966
3196
|
const who = to.split(",").map((s) => s.trim()).filter(Boolean);
|
|
2967
|
-
const {
|
|
2968
|
-
const g = await client
|
|
2969
|
-
.catch((e) => {
|
|
3197
|
+
const { openQuestionGoal } = await import("./question-goal.js");
|
|
3198
|
+
const g = await openQuestionGoal(client, summary ?? body, who, { question: argv.includes("--question") })
|
|
3199
|
+
.catch(async (e) => {
|
|
3200
|
+
const { settleFailedQuestionGoal, openFailureWhy } = await import("./question-goal.js");
|
|
3201
|
+
const left = await settleFailedQuestionGoal(client, e);
|
|
3202
|
+
client.close();
|
|
3203
|
+
return die(`not sent — ${openFailureWhy(e, { for: "person" })}` + (left ? `\n A goal for it (${left}) may be open with nothing in it — close it: pantheon say CLOSE "nothing to answer" --goal ${left}` : ""));
|
|
3204
|
+
});
|
|
2970
3205
|
goalArg = questionGoal = g.id;
|
|
2971
3206
|
questionNote = `in a goal of its own — once answered, close it: pantheon say CLOSE "answered" --goal ${g.id}`;
|
|
2972
3207
|
}
|
|
@@ -2978,14 +3213,33 @@ async function main() {
|
|
|
2978
3213
|
...(summary ? { summary } : {}),
|
|
2979
3214
|
...(Object.keys(meta).length ? { meta } : {}),
|
|
2980
3215
|
}).catch(async (e) => {
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
3216
|
+
const { certainlyNotStored, failedActId } = await import("./client.js");
|
|
3217
|
+
let left = "";
|
|
3218
|
+
if (questionGoal) {
|
|
3219
|
+
const { settleFailedQuestion, questionFailureText } = await import("./question-goal.js");
|
|
3220
|
+
const f = await settleFailedQuestion(client, questionGoal, e);
|
|
3221
|
+
if (f.kind === "sent")
|
|
3222
|
+
return { id: f.id, seq: f.seq };
|
|
3223
|
+
if (f.kind === "unsure") {
|
|
3224
|
+
client.close();
|
|
3225
|
+
return die(questionFailureText(f, questionGoal, plainError(e.message), { for: "person" }));
|
|
3226
|
+
}
|
|
3227
|
+
if (f.left)
|
|
3228
|
+
left = `\n Its goal (${f.left}) is still open with nothing in it — close it: pantheon say CLOSE "nothing to answer" --goal ${f.left}`;
|
|
3229
|
+
}
|
|
3230
|
+
else if (!certainlyNotStored(e) && failedActId(e)) {
|
|
3231
|
+
const stored = await client.seenOwn(failedActId(e));
|
|
3232
|
+
if (stored)
|
|
3233
|
+
return { id: stored.id, seq: stored.seq };
|
|
3234
|
+
client.close();
|
|
3235
|
+
return die(`this may have been sent — the relay did not confirm it.\n Check before sending it again: ${goalArg ? `pantheon history --goal ${goalArg}` : "pantheon history"} shows whether it is there.`);
|
|
3236
|
+
}
|
|
3237
|
+
return die((/SUMMARY_REQUIRED/.test(e.message) ? `${e.message}\n Add one: --summary 'the point they must not miss'`
|
|
2984
3238
|
: /UNVERIFIABLE_DELIVERY/.test(e.message) ? `${e.message}\n From here: pantheon say DELIVERED "…" --branch <the pushed branch> --commit <its sha>`
|
|
2985
3239
|
: /BAD_REF/.test(e.message) ? `${e.message}\n pantheon history lists the acts with their ids and [sequence numbers]; --ref takes either, or "last"`
|
|
2986
3240
|
: /TO_REQUIRED/.test(e.message) ? `${e.message}\n Name who owes it: --to <member> (pantheon team lists them)`
|
|
2987
3241
|
: /GOAL_REQUIRED|NO_SUCH_GOAL|GOAL_CLOSED/.test(e.message) ? `${e.message.replace(/ — open one with pantheon_open_goal/, "").replace(/pantheon_open_goal/g, "pantheon goal open")}\n Open one from here: pantheon goal open "<what it is about>" --with <member> then add --goal <id> (pantheon goal list shows the open ones)`
|
|
2988
|
-
: e.message);
|
|
3242
|
+
: e.message) + left);
|
|
2989
3243
|
});
|
|
2990
3244
|
console.log(`sent ${act} id=${r.id} seq=${r.seq}`);
|
|
2991
3245
|
if (questionNote)
|
|
@@ -4804,14 +5058,36 @@ async function main() {
|
|
|
4804
5058
|
if (!inWokenRun())
|
|
4805
5059
|
await protectOrStop([{ setting: "waker", about: who, from: was ? "allowed" : "not allowed", to: sub === "allow" ? "allowed" : "not allowed" }]);
|
|
4806
5060
|
}
|
|
5061
|
+
const held = inWokenRun() ? null : await holdRuns({ waitMs: 10 * 60_000, say: (l) => console.error(D(l)) });
|
|
5062
|
+
if (held && "busy" in held)
|
|
5063
|
+
die(`${held.busy.charAt(0).toUpperCase()}${held.busy.slice(1).replace(/ Nothing was sent\./, " Nothing changed.")}.`);
|
|
5064
|
+
if (held && "clear" in held && !held.clear()) {
|
|
5065
|
+
held.release();
|
|
5066
|
+
die("A run of your agent started — nothing changed. Run this again once it is done (pantheon status shows when).");
|
|
5067
|
+
}
|
|
4807
5068
|
const r = setLocalWaker([cfg.spaceId, cfg.space], who, sub === "allow", undefined, process.env, { no: sub === "deny" });
|
|
5069
|
+
let answered = [];
|
|
5070
|
+
if (r.ok && !inWokenRun()) {
|
|
5071
|
+
const asked = Object.entries(loadPolicy().wakeAsks ?? {}).filter(([, a]) => [cfg.spaceId, cfg.space].includes(a.team) && a.member === who).map(([id]) => id);
|
|
5072
|
+
answered = await answerOnRecord(cfg, asked, `${sub === "allow" ? "allow always" : "deny"} — answered with: pantheon wake ${sub} ${who}`);
|
|
5073
|
+
if (answered.length) {
|
|
5074
|
+
const p = loadPolicy();
|
|
5075
|
+
for (const id of answered)
|
|
5076
|
+
delete p.wakeAsks?.[id];
|
|
5077
|
+
savePolicy(p);
|
|
5078
|
+
}
|
|
5079
|
+
}
|
|
5080
|
+
if (held && "release" in held)
|
|
5081
|
+
held.release();
|
|
4808
5082
|
if (!r.ok)
|
|
4809
5083
|
die(r.why);
|
|
4810
5084
|
const mode = wakeMode(loadProfile(cfg));
|
|
4811
5085
|
console.log(sub === "allow"
|
|
4812
5086
|
? `${C(who)} may wake this machine in ${cfg.space}${r.changed ? "" : D(" (already could)")}`
|
|
4813
5087
|
: `${C(who)} can no longer wake this machine in ${cfg.space}${r.changed ? "" : D(" (could not before either)")} — and you won't be asked about them again`);
|
|
4814
|
-
console.log(D(
|
|
5088
|
+
console.log(D(answered.length
|
|
5089
|
+
? ` Recorded on this machine, and your open question about ${who} is answered with it, so it leaves the board. Undo: pantheon wake ${sub === "allow" ? "deny" : "allow"} ${who}${flag("space") ? ` --space ${cfg.space}` : ""}`
|
|
5090
|
+
: ` Recorded on this machine only — nothing was sent to the team. Undo: pantheon wake ${sub === "allow" ? "deny" : "allow"} ${who}${flag("space") ? ` --space ${cfg.space}` : ""}`));
|
|
4815
5091
|
if (unchecked)
|
|
4816
5092
|
console.log(D(` The relay did not answer, so "${who}" was not checked against the team's members — check the spelling (pantheon team).`));
|
|
4817
5093
|
if (sub === "allow") {
|
|
@@ -4954,6 +5230,42 @@ async function main() {
|
|
|
4954
5230
|
const { loadPolicy, savePolicy, grant, revoke, inWokenRun, CAPABILITY_ARGS, parseRunMinutes, runMinutesProblem, effectiveRunMinutes, describeRunMinutes, RUN_MINUTES, parseIdleSeconds, idleSecondsProblem, effectiveIdleSeconds, describeIdleSeconds, IDLE_SECONDS } = await import("./worker-policy.js");
|
|
4955
5231
|
const { COMMAND_GRANT_SCOPE } = await import("./agents.js");
|
|
4956
5232
|
const sub = argv[1];
|
|
5233
|
+
{
|
|
5234
|
+
const { policyUnreadable, policyPath, salvagePolicyText } = await import("./worker-policy.js");
|
|
5235
|
+
const file = policyPath();
|
|
5236
|
+
const unreadable = policyUnreadable(loadPolicy());
|
|
5237
|
+
if (sub === "repair") {
|
|
5238
|
+
if (inWokenRun())
|
|
5239
|
+
die("a woken run cannot repair this computer's policy — a person has to run this here");
|
|
5240
|
+
if (!unreadable) {
|
|
5241
|
+
console.log(D(`${file} reads fine — nothing to repair`));
|
|
5242
|
+
return;
|
|
5243
|
+
}
|
|
5244
|
+
let text = "";
|
|
5245
|
+
try {
|
|
5246
|
+
text = readFileSync(file, "utf8");
|
|
5247
|
+
}
|
|
5248
|
+
catch { }
|
|
5249
|
+
const aside = `${file}.broken`;
|
|
5250
|
+
try {
|
|
5251
|
+
rmSync(aside, { recursive: true, force: true });
|
|
5252
|
+
}
|
|
5253
|
+
catch { }
|
|
5254
|
+
const { renameSync } = await import("node:fs");
|
|
5255
|
+
try {
|
|
5256
|
+
renameSync(file, aside);
|
|
5257
|
+
}
|
|
5258
|
+
catch (e) {
|
|
5259
|
+
die(`could not move ${file} aside (${e.message.split("\n")[0]}) — make it writable again first`);
|
|
5260
|
+
}
|
|
5261
|
+
const held = salvagePolicyText(text);
|
|
5262
|
+
console.log(`${C("moved aside")} ${file} → ${aside}; the worker starts from the defaults (it holds no grant, and asks again before anything).`);
|
|
5263
|
+
console.log(held.length ? ` It held, as far as it can still be read — give these again:\n${held.map((h) => ` ${h}`).join("\n")}` : ` Nothing in it can still be read: give again any no or grant you had made here (pantheon policy, pantheon wake deny <who>).`);
|
|
5264
|
+
return;
|
|
5265
|
+
}
|
|
5266
|
+
if (unreadable)
|
|
5267
|
+
die(`${file} cannot be read (torn or not JSON), so the worker holds every unattended run and asks nothing. What to do: pantheon policy repair — it moves the file aside and says which noes and grants to give again.`);
|
|
5268
|
+
}
|
|
4957
5269
|
if (sub === "set") {
|
|
4958
5270
|
const key = argv[2];
|
|
4959
5271
|
if (key !== "run-minutes" && key !== "idle-seconds")
|
|
@@ -5016,12 +5328,37 @@ async function main() {
|
|
|
5016
5328
|
} })() : "";
|
|
5017
5329
|
await protectOrStop([{ setting, ...(names ? { about: names } : {}), from: on ? "on" : "off", to: sub === "grant" ? "on" : "off" }]);
|
|
5018
5330
|
}
|
|
5331
|
+
const held = inWokenRun() ? null : await holdRuns({ waitMs: 10 * 60_000, say: (l) => console.error(D(l)) });
|
|
5332
|
+
if (held && "busy" in held)
|
|
5333
|
+
die(`${held.busy.charAt(0).toUpperCase()}${held.busy.slice(1).replace(/ Nothing was sent\./, " Nothing changed.")}.`);
|
|
5334
|
+
if (held && "clear" in held && !held.clear()) {
|
|
5335
|
+
held.release();
|
|
5336
|
+
die("A run of your agent started — nothing changed. Run this again once it is done (pantheon status shows when).");
|
|
5337
|
+
}
|
|
5019
5338
|
const p = loadPolicy();
|
|
5339
|
+
const asked = p.asks[cap]?.act;
|
|
5020
5340
|
if (sub === "grant")
|
|
5021
5341
|
grant(p, cap, "always", "policy-command");
|
|
5022
5342
|
else
|
|
5023
5343
|
revoke(p, cap);
|
|
5024
5344
|
savePolicy(p);
|
|
5345
|
+
let answeredQ = false;
|
|
5346
|
+
if (asked && !inWokenRun()) {
|
|
5347
|
+
const f = loadAll();
|
|
5348
|
+
const team = loadPolicy().stuckReports?.[asked]?.team;
|
|
5349
|
+
const m = team && f ? findMembership(f, team) : undefined;
|
|
5350
|
+
const all = f ? (m ? [m] : Object.values(f.spaces ?? {})).map((x) => configFor(f, x, null)) : [];
|
|
5351
|
+
const where = all.length ? all : [load()].filter((x) => !!x);
|
|
5352
|
+
for (const c of where)
|
|
5353
|
+
if (!answeredQ)
|
|
5354
|
+
answeredQ = (await answerOnRecord(c, [asked], `${sub === "grant" ? "allow always" : "deny"} — answered with: pantheon policy ${sub} ${CAPABILITY_ARGS[cap]}`)).length > 0;
|
|
5355
|
+
if (answeredQ && sub === "revoke") {
|
|
5356
|
+
const { applyLocalAnswer } = await import("./worker-policy.js");
|
|
5357
|
+
applyLocalAnswer(asked, "deny");
|
|
5358
|
+
}
|
|
5359
|
+
}
|
|
5360
|
+
if (held && "release" in held)
|
|
5361
|
+
held.release();
|
|
5025
5362
|
const said = cap === "self_upgrade"
|
|
5026
5363
|
? (sub === "grant" ? "— the worker keeps pantheon current with the relay" : "— the worker will ask in your approvals inbox when it falls behind")
|
|
5027
5364
|
: cap === "unsandboxed_runs"
|
|
@@ -5035,6 +5372,8 @@ async function main() {
|
|
|
5035
5372
|
: "— Codex, Cursor and Copilot leave teammates' requests for you to pick up when you're back; Claude Code still answers them. On again: pantheon policy grant unsandboxed-runs")
|
|
5036
5373
|
: (sub === "grant" ? `— ${COMMAND_GRANT_SCOPE}` : "— woken runs are back to edits only");
|
|
5037
5374
|
console.log(`${C(sub === "grant" ? "granted" : "revoked")} ${CAPABILITY_ARGS[cap]} ${D(said)}`);
|
|
5375
|
+
if (answeredQ)
|
|
5376
|
+
console.log(D(` Your agent's open question about ${CAPABILITY_ARGS[cap]} is answered with it, so it leaves the board.`));
|
|
5038
5377
|
return;
|
|
5039
5378
|
}
|
|
5040
5379
|
if (sub && sub !== "show")
|
|
@@ -5131,9 +5470,15 @@ async function main() {
|
|
|
5131
5470
|
const code = await handleUri(parsed.rest, {
|
|
5132
5471
|
home: uriHome,
|
|
5133
5472
|
wokenRun: inWokenRun(),
|
|
5134
|
-
runQueued: (actionId) =>
|
|
5135
|
-
|
|
5136
|
-
const
|
|
5473
|
+
runQueued: async (actionId) => {
|
|
5474
|
+
const r = spawnSync(process.execPath, self(["explain", "--queued", "--only-action", "--action-id", actionId]), { stdio: ["inherit", "pipe", "inherit"], env: childEnv, encoding: "utf8" });
|
|
5475
|
+
const { outcomeLines } = await import("./uri-handler.js");
|
|
5476
|
+
for (const l of outcomeLines(r.stdout ?? ""))
|
|
5477
|
+
console.log(l);
|
|
5478
|
+
return r.status ?? 1;
|
|
5479
|
+
},
|
|
5480
|
+
openBoard: hasBoard ? (focus, team) => new Promise((done) => {
|
|
5481
|
+
const c = spawn(process.execPath, self(["board", "--open", ...(focus ? ["--focus", focus, ...(team ? ["--space", team] : [])] : [])]), { detached: true, stdio: "ignore", windowsHide: true, env: childEnv });
|
|
5137
5482
|
const t = setTimeout(() => { c.unref(); done(true); }, 4_000);
|
|
5138
5483
|
c.on("error", () => { clearTimeout(t); done(false); });
|
|
5139
5484
|
c.on("exit", (status) => { clearTimeout(t); done(status === 0); });
|
|
@@ -5171,15 +5516,24 @@ async function main() {
|
|
|
5171
5516
|
refuse("that is not an action id");
|
|
5172
5517
|
let st = null;
|
|
5173
5518
|
let raw = null;
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5519
|
+
const { sweepActionQueue, takeQueuedAction } = await import("./hud-queue.js");
|
|
5520
|
+
sweepActionQueue(CONFIG_DIR, { maxAgeMs: HUD_ACTION_MAX_AGE_MS });
|
|
5521
|
+
const queued = want !== undefined ? takeQueuedAction(CONFIG_DIR, want) : null;
|
|
5522
|
+
if (queued) {
|
|
5523
|
+
st = { mtimeMs: queued.mtimeMs };
|
|
5524
|
+
raw = queued.raw;
|
|
5177
5525
|
}
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5526
|
+
else {
|
|
5527
|
+
try {
|
|
5528
|
+
st = statSync(f);
|
|
5529
|
+
raw = readFileSync(f, "utf8");
|
|
5530
|
+
}
|
|
5531
|
+
catch {
|
|
5532
|
+
st = null;
|
|
5533
|
+
raw = null;
|
|
5534
|
+
}
|
|
5181
5535
|
}
|
|
5182
|
-
if (raw !== null) {
|
|
5536
|
+
if (raw !== null && !queued) {
|
|
5183
5537
|
let nonce;
|
|
5184
5538
|
try {
|
|
5185
5539
|
nonce = JSON.parse(raw).nonce;
|
|
@@ -5207,11 +5561,11 @@ async function main() {
|
|
|
5207
5561
|
nonce = undefined;
|
|
5208
5562
|
}
|
|
5209
5563
|
if (want !== undefined && nonce !== want)
|
|
5210
|
-
refuse("another click replaced that action before it ran — nothing was sent from here; click it again");
|
|
5564
|
+
refuse(queued ? "that action's file does not match its id — nothing was sent; click it again" : "another click replaced that action before it ran — nothing was sent from here; click it again");
|
|
5211
5565
|
if (want === undefined && typeof nonce === "string")
|
|
5212
5566
|
refuse("another Pantheon window is sending an action right now — click it again in a moment");
|
|
5213
5567
|
}
|
|
5214
|
-
if (raw !== null) {
|
|
5568
|
+
if (raw !== null && !queued) {
|
|
5215
5569
|
try {
|
|
5216
5570
|
rmSync(f, { force: true });
|
|
5217
5571
|
}
|
|
@@ -5235,7 +5589,7 @@ async function main() {
|
|
|
5235
5589
|
if (run && st.mtimeMs >= run.at - 1_000 && !(parsed?.action === "run" && typeof parsed.ref === "string" && parsed.ref === run.ref)) {
|
|
5236
5590
|
refuse(parsed?.action === "change" || parsed?.action === "changes" ? await runBusySaid()
|
|
5237
5591
|
: parsed?.action === "run" ? `Your agent is in the middle of another request. Take over or Stop this one when it finishes — or Stop that one first.`
|
|
5238
|
-
:
|
|
5592
|
+
: runWhileSaid(parsed));
|
|
5239
5593
|
}
|
|
5240
5594
|
hud = parsed;
|
|
5241
5595
|
}
|
|
@@ -5438,7 +5792,8 @@ async function main() {
|
|
|
5438
5792
|
return;
|
|
5439
5793
|
}
|
|
5440
5794
|
if (hud?.action === "reply") {
|
|
5441
|
-
const notSent = (why) => { console.log(`not sent: ${why
|
|
5795
|
+
const notSent = (why) => { console.log(`not sent: ${panelLine(why)}`); process.exit(1); };
|
|
5796
|
+
const deadline = queuedDeadline();
|
|
5442
5797
|
const kind = hud.kind ?? "NOTE";
|
|
5443
5798
|
let body = (hud.body ?? "").trim();
|
|
5444
5799
|
if (!body)
|
|
@@ -5459,18 +5814,52 @@ async function main() {
|
|
|
5459
5814
|
c2.close();
|
|
5460
5815
|
notSent("that decision is no longer waiting — nothing to answer");
|
|
5461
5816
|
}
|
|
5817
|
+
const decisionHere = !!target && ((target.act === "ESCALATE" && target.from === cfg.member) || (target.act === "HUMAN_REQUIRED" && target.to?.[0] === cfg.member));
|
|
5818
|
+
if (kind === "ANSWER" && !o && decisionHere && !c2.obligations.some((x) => x.kind === "HUMAN" && x.ref === target.id && x.owner === `human:${cfg.member}`)) {
|
|
5819
|
+
c2.close();
|
|
5820
|
+
notSent("that decision is no longer waiting — it was answered or withdrawn. Nothing was sent and nothing changed");
|
|
5821
|
+
}
|
|
5822
|
+
const { pendingLocalQuestion } = await import("./worker-policy.js");
|
|
5823
|
+
let pendingHere = kind === "ANSWER" ? pendingLocalQuestion(o?.ref ?? target?.id) : null;
|
|
5462
5824
|
if (goal && c2.goals.get(goal)?.state === "CLOSED")
|
|
5463
5825
|
goal = null;
|
|
5464
|
-
const
|
|
5826
|
+
const full = (() => { const g = goal ? c2.goals.get(goal) : undefined; return !!g && g.budget > 0 && g.acts >= g.budget; })();
|
|
5827
|
+
const me = cfg.member;
|
|
5828
|
+
const ownerOf = (owner) => owner.replace(/^human:/, "");
|
|
5829
|
+
const ownAgents = !!target && target.from === me && decisionHere;
|
|
5830
|
+
const rowOwner = o && o.ref === target?.id && ownerOf(o.owner) !== me ? ownerOf(o.owner) : null;
|
|
5831
|
+
const askee = !target || ownAgents ? null
|
|
5832
|
+
: target.from !== me ? target.from
|
|
5833
|
+
: (rowOwner ?? c2.obligations.find((x) => x.ref === target.id && ownerOf(x.owner) !== me)?.owner ?? target.to?.find((m) => m !== me) ?? null);
|
|
5834
|
+
const askeeName = askee ? ownerOf(askee) : null;
|
|
5835
|
+
const fullWords = decisionHere
|
|
5836
|
+
? `this conversation has used all the messages it may have, so a note can't be added to it. Your answer still goes through: choose Answer and send it${askeeName ? ` — or choose Ask back to ask ${askeeName} in a new conversation` : ""}`
|
|
5837
|
+
: askeeName
|
|
5838
|
+
? `this conversation has used all the messages it may have, so a note can't be added to it. To say more, choose Ask back — it starts a new conversation with ${askeeName}`
|
|
5839
|
+
: "this conversation has used all the messages it may have, so a note can't be added to it. Show the thread to see where it stands";
|
|
5840
|
+
if (kind === "ASK" && full)
|
|
5841
|
+
goal = null;
|
|
5842
|
+
if (kind === "NOTE" && full) {
|
|
5843
|
+
c2.close();
|
|
5844
|
+
notSent(fullWords);
|
|
5845
|
+
}
|
|
5846
|
+
const to = kind === "ASK" && askeeName ? [askeeName] : null;
|
|
5465
5847
|
if (kind === "ASK" && !to) {
|
|
5466
5848
|
c2.close();
|
|
5467
|
-
notSent(
|
|
5849
|
+
notSent(ownAgents
|
|
5850
|
+
? `this question came from your own agent, so there is nobody to ask back — answer it${full ? "" : ", or add a note"}`
|
|
5851
|
+
: "can't tell who to ask — use Show the thread and reply from there");
|
|
5468
5852
|
}
|
|
5469
5853
|
let ownThread = false;
|
|
5470
5854
|
if (kind === "ASK" && !goal && to) {
|
|
5471
|
-
|
|
5472
|
-
const
|
|
5473
|
-
|
|
5855
|
+
deadline.sending();
|
|
5856
|
+
const { openQuestionGoal } = await import("./question-goal.js");
|
|
5857
|
+
const g = await openQuestionGoal(c2, body, to)
|
|
5858
|
+
.catch(async (e) => {
|
|
5859
|
+
const { settleFailedQuestionGoal, openFailureWhy } = await import("./question-goal.js");
|
|
5860
|
+
const left = await settleFailedQuestionGoal(c2, e);
|
|
5861
|
+
return notSent(openFailureWhy(e, { for: "person" }) + (left ? ` ${emptyThreadStep(left)}` : ""));
|
|
5862
|
+
});
|
|
5474
5863
|
goal = g.id;
|
|
5475
5864
|
ownThread = true;
|
|
5476
5865
|
const about = target?.summary ?? target?.body.split("\n")[0] ?? o?.body;
|
|
@@ -5482,32 +5871,92 @@ async function main() {
|
|
|
5482
5871
|
const ref = kind === "ANSWER" ? (o?.ref ?? target?.id ?? null) : kind === "ASK" && !ownThread ? (target?.id ?? null) : null;
|
|
5483
5872
|
const summary = body.length > LIMITS.summaryRequiredOver
|
|
5484
5873
|
? (body.split(/\n|(?<=[.!?])\s/)[0] ?? body).trim().slice(0, LIMITS.summaryChars) : undefined;
|
|
5485
|
-
const
|
|
5486
|
-
|
|
5874
|
+
const unconfirmed = (why) => { console.log(`unconfirmed: ${why.split("\n")[0]}`); process.exit(1); };
|
|
5875
|
+
const frameArgs = { act: kind, body, goal, ref, to, after_seq: c2.readSeq, meta: { surface: "menubar" }, ...(summary ? { summary } : {}) };
|
|
5876
|
+
const held = pendingHere ? await holdRuns({ waitMs: 15_000 }) : null;
|
|
5877
|
+
if (held && "busy" in held) {
|
|
5878
|
+
c2.close();
|
|
5879
|
+
notSent(held.busy);
|
|
5880
|
+
}
|
|
5881
|
+
if (held)
|
|
5882
|
+
pendingHere = pendingLocalQuestion(o?.ref ?? target?.id);
|
|
5883
|
+
{
|
|
5884
|
+
const { supersededAnswer } = await import("./worker-policy.js");
|
|
5885
|
+
const why = supersededAnswer(pendingHere, body);
|
|
5886
|
+
if (why) {
|
|
5887
|
+
if (held && "release" in held)
|
|
5888
|
+
held.release();
|
|
5889
|
+
c2.close();
|
|
5890
|
+
notSent(why);
|
|
5891
|
+
}
|
|
5892
|
+
}
|
|
5893
|
+
const step = await localStepFor(pendingHere, body, o?.id ?? hud.decision ?? null);
|
|
5894
|
+
deadline.sending();
|
|
5895
|
+
const sent = await (ownThread ? c2.send(frameArgs) : c2.sendSettled(frameArgs))
|
|
5896
|
+
.catch(async (e) => {
|
|
5897
|
+
if (/^WITHDRAWN:/.test(e.message))
|
|
5898
|
+
return notSent("that question was withdrawn before your answer reached it — nothing changed");
|
|
5899
|
+
const { certainlyNotStored, failedActId } = await import("./client.js");
|
|
5900
|
+
if (ownThread && goal) {
|
|
5901
|
+
const { settleFailedQuestion } = await import("./question-goal.js");
|
|
5902
|
+
const f = await settleFailedQuestion(c2, goal, e);
|
|
5903
|
+
if (f.kind === "sent")
|
|
5904
|
+
return { id: f.id, seq: f.seq };
|
|
5905
|
+
if (f.kind === "unsure")
|
|
5906
|
+
return unconfirmed(`the relay did not confirm the question — it may have been sent. Check the thread before asking again.`);
|
|
5907
|
+
return notSent(panelRefusal(e.message, fullWords) + (f.left ? ` ${emptyThreadStep(f.left)}` : ""));
|
|
5908
|
+
}
|
|
5909
|
+
if (!certainlyNotStored(e) && failedActId(e)) {
|
|
5910
|
+
return unconfirmed(pendingHere
|
|
5911
|
+
? `the relay did not confirm it — it may have been sent, and nothing changed on this computer yet. ${step?.check ?? "Check the thread: if your answer is not there, answer again."}`
|
|
5912
|
+
: `the relay did not confirm it — it may have been sent. Check the thread before sending again.`);
|
|
5913
|
+
}
|
|
5914
|
+
return notSent(panelRefusal(e.message, fullWords));
|
|
5915
|
+
});
|
|
5916
|
+
deadline.done();
|
|
5487
5917
|
c2.close();
|
|
5488
5918
|
console.log(`sent ${kind} id=${sent.id} seq=${sent.seq}`);
|
|
5489
5919
|
if (kind === "ANSWER") {
|
|
5490
|
-
const {
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5920
|
+
const { applyLocalAnswerAfterSend, describeLocalAnswer } = await import("./worker-policy.js");
|
|
5921
|
+
if (held && "clear" in held && !held.clear())
|
|
5922
|
+
console.error(` ${notAppliedWords(step)}`);
|
|
5923
|
+
else {
|
|
5924
|
+
const g = applyLocalAnswerAfterSend(ref, body, pendingHere);
|
|
5925
|
+
if (g)
|
|
5926
|
+
console.error(describeLocalAnswer(g));
|
|
5927
|
+
await rememberApplied(cfg, sent.id, g);
|
|
5928
|
+
}
|
|
5494
5929
|
}
|
|
5930
|
+
if (held && "release" in held)
|
|
5931
|
+
held.release();
|
|
5495
5932
|
return;
|
|
5496
5933
|
}
|
|
5497
5934
|
if (hud?.action === "retract") {
|
|
5498
|
-
const notSent = (why) => { console.log(`not sent: ${why
|
|
5935
|
+
const notSent = (why) => { console.log(`not sent: ${panelLine(why)}`); process.exit(1); };
|
|
5499
5936
|
if (!hud.act)
|
|
5500
5937
|
notSent("nothing to retract");
|
|
5938
|
+
{
|
|
5939
|
+
const cmd = await appliedChange(cfg, hud.act);
|
|
5940
|
+
if (cmd)
|
|
5941
|
+
notSent(retractRefusal(cmd));
|
|
5942
|
+
}
|
|
5943
|
+
const deadline = queuedDeadline();
|
|
5501
5944
|
const c2 = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
5502
5945
|
await c2.connect().catch((e) => notSent(connectFailure(e, cfg.relay)));
|
|
5503
|
-
|
|
5504
|
-
|
|
5946
|
+
deadline.sending();
|
|
5947
|
+
const unconfirmed = (why) => { console.log(`unconfirmed: ${why}`); process.exit(1); };
|
|
5948
|
+
const sent = await c2.sendSettled({ act: "RETRACT", body: "Retracted from the menu bar.", goal: null, ref: hud.act, to: null, meta: { surface: "menubar" } })
|
|
5949
|
+
.catch(async (e) => {
|
|
5950
|
+
const { certainlyNotStored } = await import("./client.js");
|
|
5951
|
+
return certainlyNotStored(e) ? notSent(plainError(e.message)) : unconfirmed("the relay did not confirm the retraction — it may have gone through. Check the thread before retracting again.");
|
|
5952
|
+
});
|
|
5953
|
+
deadline.done();
|
|
5505
5954
|
c2.close();
|
|
5506
5955
|
console.log(`sent RETRACT id=${sent.id} seq=${sent.seq}`);
|
|
5507
5956
|
return;
|
|
5508
5957
|
}
|
|
5509
5958
|
if (hud?.action === "wake") {
|
|
5510
|
-
const notSent = (why) => { console.log(`not sent: ${why}`); process.exit(1); };
|
|
5959
|
+
const notSent = (why) => { console.log(`not sent: ${panelLine(why)}`); process.exit(1); };
|
|
5511
5960
|
const { loadPolicy, setLocalWaker, markTeamFlagOnYes, applyLocalAnswer, describeLocalAnswer } = await import("./worker-policy.js");
|
|
5512
5961
|
const ref = hud.act;
|
|
5513
5962
|
const wa = ref ? loadPolicy().wakeAsks?.[ref] : undefined;
|
|
@@ -5523,33 +5972,64 @@ async function main() {
|
|
|
5523
5972
|
if (![cfg.spaceId, cfg.space].includes(wa.team))
|
|
5524
5973
|
notSent(`that question is about the team "${wa.team}", not "${hud.space ?? cfg.space}" — answer it from that team's board`);
|
|
5525
5974
|
const allow = hud.allow === true;
|
|
5975
|
+
const body = allow ? "allow always" : "deny";
|
|
5976
|
+
{
|
|
5977
|
+
const { inWokenRun } = await import("./worker-policy.js");
|
|
5978
|
+
if (inWokenRun(process.env))
|
|
5979
|
+
notSent("a woken run cannot change who may wake this machine — a person has to answer it here");
|
|
5980
|
+
}
|
|
5981
|
+
const held = await holdRuns({ waitMs: 15_000 });
|
|
5982
|
+
if ("busy" in held)
|
|
5983
|
+
notSent(held.busy);
|
|
5984
|
+
{
|
|
5985
|
+
const now = loadPolicy().wakeAsks?.[ref];
|
|
5986
|
+
if (!now || now.member !== wa.member || now.team !== wa.team) {
|
|
5987
|
+
if ("release" in held)
|
|
5988
|
+
held.release();
|
|
5989
|
+
notSent("that question is no longer open on this machine — pantheon wake list shows who may wake it");
|
|
5990
|
+
}
|
|
5991
|
+
}
|
|
5992
|
+
const wakeStep = await localStepFor({ wake: wa }, body, hud.decision ?? null);
|
|
5993
|
+
const c2 = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
5994
|
+
await c2.connect().catch((e) => { c2.close(); return notSent(`the relay could not be reached (${e.message.split("\n")[0]}) — nothing was sent and nothing changed here. Try again in a moment`); });
|
|
5995
|
+
const o = c2.obligations.find((x) => x.id === hud.decision || x.ref === ref);
|
|
5996
|
+
if (!o) {
|
|
5997
|
+
c2.close();
|
|
5998
|
+
notSent(`that question is no longer waiting — it was answered or withdrawn, and nothing changed here. pantheon wake ${allow ? "allow" : "deny"} ${wa.member} still changes who may wake this machine`);
|
|
5999
|
+
}
|
|
6000
|
+
const sent = await c2.sendSettled({ act: "ANSWER", ref: ref, goal: null, after_seq: c2.readSeq, body, meta: { surface: "menubar" } })
|
|
6001
|
+
.catch(async (e) => {
|
|
6002
|
+
const { certainlyNotStored } = await import("./client.js");
|
|
6003
|
+
c2.close();
|
|
6004
|
+
if (certainlyNotStored(e))
|
|
6005
|
+
return notSent(plainError(e.message));
|
|
6006
|
+
console.log(`unconfirmed: the relay did not confirm the answer — it may have gone through. Nothing changed on this computer yet. ${wakeStep?.check ?? ""}`.trim());
|
|
6007
|
+
return process.exit(1);
|
|
6008
|
+
});
|
|
6009
|
+
c2.close();
|
|
6010
|
+
const line = `sent ANSWER id=${sent.id} seq=${sent.seq}`;
|
|
6011
|
+
if ("clear" in held && !held.clear()) {
|
|
6012
|
+
console.log(line);
|
|
6013
|
+
console.error(` ${notAppliedWords(wakeStep)}`);
|
|
6014
|
+
held.release();
|
|
6015
|
+
return;
|
|
6016
|
+
}
|
|
5526
6017
|
const r = setLocalWaker(allow ? [wa.team] : [wa.team, cfg.spaceId, cfg.space], wa.member, allow, undefined, process.env, { no: !allow });
|
|
5527
6018
|
if (!r.ok)
|
|
5528
6019
|
notSent(r.why);
|
|
5529
6020
|
if (allow && wa.teamBlocked)
|
|
5530
6021
|
markTeamFlagOnYes(wa.team, wa.member);
|
|
5531
|
-
const body = allow ? "allow always" : "deny";
|
|
5532
6022
|
const g = applyLocalAnswer(ref, body);
|
|
5533
6023
|
if (g)
|
|
5534
6024
|
console.error(describeLocalAnswer(g));
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
if (o) {
|
|
5540
|
-
const sent = await c2.send({ act: "ANSWER", ref: ref, goal: null, after_seq: c2.readSeq, body, meta: { surface: "menubar" } });
|
|
5541
|
-
console.log(`sent ANSWER id=${sent.id} seq=${sent.seq}`);
|
|
5542
|
-
}
|
|
5543
|
-
}
|
|
5544
|
-
catch (e) {
|
|
5545
|
-
console.error(D(` recorded on this machine; the question could not be marked answered on the relay (${e.message.split("\n")[0]}) — it leaves your board once it is`));
|
|
5546
|
-
}
|
|
5547
|
-
finally {
|
|
5548
|
-
c2.close();
|
|
5549
|
-
}
|
|
6025
|
+
await rememberApplied(cfg, sent.id, { wake: { member: wa.member }, verdict: allow ? "allow-always" : "deny" });
|
|
6026
|
+
if ("release" in held)
|
|
6027
|
+
held.release();
|
|
6028
|
+
console.log(line);
|
|
5550
6029
|
return;
|
|
5551
6030
|
}
|
|
5552
6031
|
if (hud?.action === "done") {
|
|
6032
|
+
const deadline = queuedDeadline();
|
|
5553
6033
|
const tries = hud.space ? [cfg] : (() => { const f = loadAll(); const all = f ? Object.values(f.spaces ?? {}).map((m) => configFor(f, m, null)) : []; return all.length ? all : [cfg]; })();
|
|
5554
6034
|
let c2 = null;
|
|
5555
6035
|
let o;
|
|
@@ -5557,8 +6037,10 @@ async function main() {
|
|
|
5557
6037
|
let doneCfg = cfg;
|
|
5558
6038
|
for (const tc of tries) {
|
|
5559
6039
|
const c = new PantheonClient(tc, undefined, { role: "cli" });
|
|
5560
|
-
const ok = await c.connect().then(() => true, (e) => { if (tries.length === 1)
|
|
5561
|
-
|
|
6040
|
+
const ok = await c.connect().then(() => true, (e) => { if (tries.length === 1) {
|
|
6041
|
+
console.log(`not sent: ${panelLine(connectFailure(e, tc.relay))}`);
|
|
6042
|
+
process.exit(1);
|
|
6043
|
+
} if (!refusalOf(e))
|
|
5562
6044
|
unreached.push(tc.space); return false; });
|
|
5563
6045
|
const hit = ok && hud.decision ? c.obligations.find((x) => x.id === hud.decision) : undefined;
|
|
5564
6046
|
if (hit) {
|
|
@@ -5579,7 +6061,16 @@ async function main() {
|
|
|
5579
6061
|
}
|
|
5580
6062
|
const open = o.goal && c2.goals.get(o.goal)?.state !== "CLOSED" ? o.goal : null;
|
|
5581
6063
|
const doneBody = `${doneCfg.member} marked this handled — dealt with outside Pantheon.`;
|
|
5582
|
-
|
|
6064
|
+
deadline.sending();
|
|
6065
|
+
await c2.sendSettled({ act: "ANSWER", ref: o.ref, goal: open, after_seq: c2.readSeq, body: doneBody }).catch(async (e) => {
|
|
6066
|
+
const { certainlyNotStored } = await import("./client.js");
|
|
6067
|
+
c2.close();
|
|
6068
|
+
console.log(certainlyNotStored(e)
|
|
6069
|
+
? `not sent: ${panelLine(plainError(e.message))}`
|
|
6070
|
+
: "unconfirmed: the relay did not confirm it — it may have been marked done. Check the thread before marking it again.");
|
|
6071
|
+
process.exit(1);
|
|
6072
|
+
});
|
|
6073
|
+
deadline.done();
|
|
5583
6074
|
c2.close();
|
|
5584
6075
|
console.error(D(`done — that decision is no longer waiting on you`));
|
|
5585
6076
|
return;
|
|
@@ -5727,23 +6218,50 @@ async function main() {
|
|
|
5727
6218
|
continue;
|
|
5728
6219
|
}
|
|
5729
6220
|
}
|
|
6221
|
+
const { pendingLocalQuestion, applyLocalAnswerAfterSend, describeLocalAnswer } = await import("./worker-policy.js");
|
|
6222
|
+
let pendingHere = kind === "ANSWER" ? pendingLocalQuestion(ref) : null;
|
|
6223
|
+
const held = pendingHere ? await holdRuns({ waitMs: 10 * 60_000, say: (l) => console.error(D(` ${l}`)) }) : null;
|
|
6224
|
+
if (held && "busy" in held) {
|
|
6225
|
+
console.error(` ${held.busy}.`);
|
|
6226
|
+
continue;
|
|
6227
|
+
}
|
|
6228
|
+
if (held)
|
|
6229
|
+
pendingHere = pendingLocalQuestion(ref);
|
|
6230
|
+
{
|
|
6231
|
+
const { supersededAnswer } = await import("./worker-policy.js");
|
|
6232
|
+
const why = supersededAnswer(pendingHere, text);
|
|
6233
|
+
if (why) {
|
|
6234
|
+
if (held && "release" in held)
|
|
6235
|
+
held.release();
|
|
6236
|
+
console.error(` not sent: ${why}`);
|
|
6237
|
+
continue;
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
const step = await localStepFor(pendingHere, text, o?.id ?? null);
|
|
5730
6241
|
const c3 = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
5731
6242
|
try {
|
|
5732
6243
|
await c3.connect();
|
|
5733
|
-
const sent = await c3.
|
|
6244
|
+
const sent = await c3.sendSettled({ act: kind, body: text, goal: o ? null : goalId, ref, to });
|
|
5734
6245
|
console.error(` ${C("sent")} ${kind} id=${sent.id}`);
|
|
5735
6246
|
if (kind === "ANSWER") {
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
|
|
5739
|
-
|
|
6247
|
+
if (held && "clear" in held && !held.clear())
|
|
6248
|
+
console.error(` ${notAppliedWords(step)}`);
|
|
6249
|
+
else {
|
|
6250
|
+
const g = applyLocalAnswerAfterSend(ref, text, pendingHere);
|
|
6251
|
+
if (g)
|
|
6252
|
+
console.error(` ${describeLocalAnswer(g)}`);
|
|
6253
|
+
await rememberApplied(cfg, sent.id, g);
|
|
6254
|
+
}
|
|
5740
6255
|
}
|
|
5741
6256
|
}
|
|
5742
6257
|
catch (e) {
|
|
5743
|
-
|
|
6258
|
+
const unsure = e.unconfirmed && pendingHere;
|
|
6259
|
+
console.error(` ${plainError(e.message)}${unsure ? `\n Nothing changed on this computer yet. ${step?.check ?? "Check the thread: if your answer is not there, answer again."}` : ""}`);
|
|
5744
6260
|
}
|
|
5745
6261
|
finally {
|
|
5746
6262
|
c3.close();
|
|
6263
|
+
if (held && "release" in held)
|
|
6264
|
+
held.release();
|
|
5747
6265
|
}
|
|
5748
6266
|
continue;
|
|
5749
6267
|
}
|
|
@@ -5923,14 +6441,27 @@ async function main() {
|
|
|
5923
6441
|
c.client.close(); };
|
|
5924
6442
|
const all = conns.flatMap(({ cfg, client }) => client.obligations.filter((o) => o.kind === "HUMAN" && o.owner === `human:${cfg.member}`).map((o) => ({ o, cfg, client })))
|
|
5925
6443
|
.sort((a, b) => a.o.created_at - b.o.created_at);
|
|
6444
|
+
const { terminalKey, saveList, listFor } = await import("./approvals-list.js");
|
|
5926
6445
|
const lastFile = join(CONFIG_DIR, "approvals-last.json");
|
|
5927
|
-
const
|
|
5928
|
-
|
|
5929
|
-
|
|
6446
|
+
const win = terminalKey();
|
|
6447
|
+
const { runInFlight: runNow, guardHeld: guardNow } = await import("./worker.js");
|
|
6448
|
+
const lastFile0 = join(CONFIG_DIR, "approvals-last.json");
|
|
6449
|
+
const listLocked = (() => { try {
|
|
6450
|
+
closeSync(openSync(lastFile0, "r+"));
|
|
6451
|
+
return false;
|
|
5930
6452
|
}
|
|
5931
|
-
catch {
|
|
5932
|
-
return
|
|
5933
|
-
} };
|
|
6453
|
+
catch (e) {
|
|
6454
|
+
return e.code !== "ENOENT";
|
|
6455
|
+
} })();
|
|
6456
|
+
const runGoing = !!runNow(CONFIG_DIR) || guardNow(CONFIG_DIR) || listLocked;
|
|
6457
|
+
const here = win.key, numbersHere = win.stable && !runGoing;
|
|
6458
|
+
const listed = numbersHere ? listFor(lastFile, here) : { none: "unstable" };
|
|
6459
|
+
const whyNoNumbers = listLocked ? `the saved list (${lastFile0}) is locked and cannot be updated, so a number could mean an old list — make it writable again (chflags nouappnd,nouchg on a Mac) to use numbers`
|
|
6460
|
+
: runGoing ? "a teammate's request is running on this computer right now, and it could have changed what the numbers point to"
|
|
6461
|
+
: win.stable ? "" : win.why === "windows"
|
|
6462
|
+
? "on Windows a number can't be tied to one window"
|
|
6463
|
+
: "this command was started through a wrapper (a script, npx, or a shell's -c), not typed into a terminal window, so a number can't be tied to one window";
|
|
6464
|
+
const lastIds = () => ("ids" in listed ? listed.ids : []);
|
|
5934
6465
|
const isNumber = (want) => /^\d{1,3}$/.test(want);
|
|
5935
6466
|
const find = (want) => isNumber(want)
|
|
5936
6467
|
? (() => { const id = lastIds()[Number(want) - 1]; return id ? all.find((x) => x.o.id === id) : undefined; })()
|
|
@@ -5938,9 +6469,16 @@ async function main() {
|
|
|
5938
6469
|
const notWaiting = (want) => {
|
|
5939
6470
|
const open = `run pantheon approvals to see the open ones${all.length ? ` (${all.length} now)` : " (none now)"}`;
|
|
5940
6471
|
if (isNumber(want)) {
|
|
6472
|
+
if ("none" in listed) {
|
|
6473
|
+
return listed.none === "old"
|
|
6474
|
+
? `The list in this window is more than an hour old, so ${want} may not mean what it did. Nothing was sent. What to do: run pantheon approvals here again, then answer by its number (or by the o_… id it shows).`
|
|
6475
|
+
: listed.none === "unstable"
|
|
6476
|
+
? `Answer by id here: ${whyNoNumbers}. Nothing was sent. What to do: pantheon approvals answer o_… "your answer" (the o_… id pantheon approvals shows under each one).`
|
|
6477
|
+
: `This window's numbers aren't known here (numbers belong to the window that listed them), so there is no decision ${want} to answer. Nothing was sent. What to do: run pantheon approvals here first, or answer by the o_… id it shows.`;
|
|
6478
|
+
}
|
|
5941
6479
|
return lastIds()[Number(want) - 1]
|
|
5942
|
-
? `Decision ${want} from
|
|
5943
|
-
: `There is no decision ${want} in
|
|
6480
|
+
? `Decision ${want} from this window's last list is no longer waiting on you — it was answered or withdrawn. Nothing was sent. What to do: ${open}.`
|
|
6481
|
+
: `There is no decision ${want} in this window's last list. What to do: ${open}.`;
|
|
5944
6482
|
}
|
|
5945
6483
|
return `No decision ${want} is waiting on you${conns.length > 1 ? ` in any of your ${conns.length} teams` : ""}. What to do: ${open}.`;
|
|
5946
6484
|
};
|
|
@@ -5959,16 +6497,63 @@ async function main() {
|
|
|
5959
6497
|
die(leak.replace(/^pantheon: /, ""));
|
|
5960
6498
|
}
|
|
5961
6499
|
}
|
|
5962
|
-
const
|
|
5963
|
-
|
|
6500
|
+
const { pendingLocalQuestion, applyLocalAnswerAfterSend, describeLocalAnswer } = await import("./worker-policy.js");
|
|
6501
|
+
let pendingHere = pendingLocalQuestion(hit.o.ref);
|
|
6502
|
+
const held = pendingHere ? await holdRuns({ waitMs: 10 * 60_000, say: (l) => console.error(D(l)) }) : null;
|
|
6503
|
+
if (held && "busy" in held) {
|
|
6504
|
+
closeAll();
|
|
6505
|
+
die(`${held.busy.charAt(0).toUpperCase()}${held.busy.slice(1)}.`);
|
|
6506
|
+
}
|
|
6507
|
+
if (held)
|
|
6508
|
+
pendingHere = pendingLocalQuestion(hit.o.ref);
|
|
6509
|
+
{
|
|
6510
|
+
const { supersededAnswer } = await import("./worker-policy.js");
|
|
6511
|
+
const why = supersededAnswer(pendingHere, answer);
|
|
6512
|
+
if (why) {
|
|
6513
|
+
if (held && "release" in held)
|
|
6514
|
+
held.release();
|
|
6515
|
+
closeAll();
|
|
6516
|
+
die(`Not sent: ${why}.`);
|
|
6517
|
+
}
|
|
6518
|
+
}
|
|
6519
|
+
const step = await localStepFor(pendingHere, answer, hit.o.id);
|
|
6520
|
+
if (pendingHere && isNumber(id)) {
|
|
6521
|
+
const { parseGrantAnswer } = await import("./worker-policy.js");
|
|
6522
|
+
const { decisionTitle: titleOf } = await import("./decision-ui.js");
|
|
6523
|
+
const v = parseGrantAnswer(answer);
|
|
6524
|
+
const bare = /^(yes|y|yeah|yep|ok|okay|sure|allow|approve|approved|go ahead)$/.test(answer.trim().toLowerCase().replace(/[.!]+$/, ""));
|
|
6525
|
+
if (!v || bare) {
|
|
6526
|
+
closeAll();
|
|
6527
|
+
const wake = "wake" in pendingHere;
|
|
6528
|
+
die(`Decision ${id} is a permission question (${titleOf(hit.o.body, 70)}), so it takes its own words — nothing was sent. ` +
|
|
6529
|
+
`What to do: pantheon approvals answer ${id} ${wake ? `"just this once" (or "always", or "no")` : `"allow once" (or "allow always", or "no")`}.`);
|
|
6530
|
+
}
|
|
6531
|
+
}
|
|
6532
|
+
const asked = hit.client.seenAct(hit.o.ref) ?? (await fetchAct(hit.cfg, hit.o.ref, 4000).catch(() => null))?.act;
|
|
6533
|
+
const inGoal = !!hit.o.goal && !!asked && asked.act !== "ESCALATE" && asked.act !== "HUMAN_REQUIRED";
|
|
6534
|
+
const sent = await hit.client.sendSettled({ act: "ANSWER", body: answer, goal: inGoal ? hit.o.goal : null, ref: hit.o.ref, after_seq: hit.client.readSeq, ...(summary ? { summary } : {}) })
|
|
6535
|
+
.catch((e) => {
|
|
6536
|
+
closeAll();
|
|
6537
|
+
return die(/SUMMARY_REQUIRED/.test(e.message) ? `${e.message}\n Add one: --summary 'the point they must not miss'`
|
|
6538
|
+
: /^GOAL_REQUIRED:/.test(e.message) ? `This decision belongs to a goal, and it could not be answered from here (${e.message.replace(/^GOAL_REQUIRED:\s*/, "").replace(/ — open one.*$/, "")}). Nothing was sent. What to do: answer it from the menu bar or the board.`
|
|
6539
|
+
: /^WITHDRAWN:/.test(e.message) ? `That question was withdrawn before your answer reached it — nothing was sent and nothing changed on this computer. What to do: run pantheon approvals to see what is still waiting.`
|
|
6540
|
+
: e.unconfirmed && pendingHere ? `${plainError(e.message)}\n Nothing changed on this computer yet. ${step?.check ?? "Check the thread: if your answer is not there, answer again."}`
|
|
6541
|
+
: plainError(e.message));
|
|
6542
|
+
});
|
|
5964
6543
|
const asker = hit.client.seenAct(hit.o.ref)?.from;
|
|
5965
6544
|
const { decisionTitle } = await import("./decision-ui.js");
|
|
5966
6545
|
console.log(`${C("answered")}${conns.length > 1 ? ` in ${B(hit.cfg.space)}` : ""}: ${decisionTitle(hit.o.body, 90)}` +
|
|
5967
6546
|
`${asker ? (asker === hit.cfg.member ? " — your agent is told" : ` — ${asker} is told`) : ""} ${D(sent.id)}`);
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
6547
|
+
if (held && "clear" in held && !held.clear())
|
|
6548
|
+
console.log(` ${notAppliedWords(step)}`);
|
|
6549
|
+
else {
|
|
6550
|
+
const g = applyLocalAnswerAfterSend(hit.o.ref, answer, pendingHere);
|
|
6551
|
+
if (g)
|
|
6552
|
+
console.log(` ${describeLocalAnswer(g)}`);
|
|
6553
|
+
await rememberApplied(hit.cfg, sent.id, g);
|
|
6554
|
+
}
|
|
6555
|
+
if (held && "release" in held)
|
|
6556
|
+
held.release();
|
|
5972
6557
|
closeAll();
|
|
5973
6558
|
return;
|
|
5974
6559
|
}
|
|
@@ -5991,7 +6576,7 @@ async function main() {
|
|
|
5991
6576
|
console.log(` ${c.label.padEnd(16)} ${C(`pantheon approvals answer ${hit.o.id} ${c.answer}`)}`);
|
|
5992
6577
|
}
|
|
5993
6578
|
else {
|
|
5994
|
-
const n = lastIds().indexOf(hit.o.id) + 1;
|
|
6579
|
+
const n = numbersHere ? lastIds().indexOf(hit.o.id) + 1 : 0;
|
|
5995
6580
|
console.log(`\nAnswer: ${C(`pantheon approvals answer ${n > 0 ? n : hit.o.id} "your answer"`)}`);
|
|
5996
6581
|
}
|
|
5997
6582
|
closeAll();
|
|
@@ -6009,11 +6594,17 @@ async function main() {
|
|
|
6009
6594
|
`${ch ? `\n answer: ${ch.map((c) => c.answer).join(" / ")}` : ""}`);
|
|
6010
6595
|
}
|
|
6011
6596
|
if (all.length)
|
|
6012
|
-
console.log(
|
|
6013
|
-
|
|
6014
|
-
|
|
6597
|
+
console.log(numbersHere
|
|
6598
|
+
? D(`\n read one in full: pantheon approvals show <number> · answer: pantheon approvals answer <number> "your answer"`)
|
|
6599
|
+
: `\n answer by its id: ${C(`pantheon approvals answer ${all[0].o.id} "your answer"`)} ${D(`(the o_… id under each one — ${whyNoNumbers})`)}`);
|
|
6600
|
+
if (numbersHere) {
|
|
6601
|
+
try {
|
|
6602
|
+
saveList(lastFile, here, all.map((x) => x.o.id));
|
|
6603
|
+
}
|
|
6604
|
+
catch (e) {
|
|
6605
|
+
console.log(`\n ${B("Numbers are not kept this time")} — the list could not be saved (${e.message.split("\n")[0]}). Answer by the o_… id under each one: ${C(`pantheon approvals answer ${all[0]?.o.id ?? "o_…"} "your answer"`)}`);
|
|
6606
|
+
}
|
|
6015
6607
|
}
|
|
6016
|
-
catch { }
|
|
6017
6608
|
closeAll();
|
|
6018
6609
|
return;
|
|
6019
6610
|
}
|
|
@@ -6029,7 +6620,7 @@ async function main() {
|
|
|
6029
6620
|
die("usage: pantheon approvals answer <obligation-id> <decision>");
|
|
6030
6621
|
const o = waiting.find((x) => x.id === id) ?? waiting.find((x) => x.ref === id) ?? die(`no decision ${id} is waiting on you`);
|
|
6031
6622
|
const answer = argv.slice(3).join(" ").trim() || die("state the decision; it will be written to the audit ledger");
|
|
6032
|
-
const sent = await client.
|
|
6623
|
+
const sent = await client.sendSettled({ act: "ANSWER", body: answer, goal: null, ref: o.ref, after_seq: client.readSeq });
|
|
6033
6624
|
console.log(`${C("answered")} ${id} — ledger act ${sent.id}`);
|
|
6034
6625
|
client.close();
|
|
6035
6626
|
return;
|
|
@@ -6160,8 +6751,9 @@ async function main() {
|
|
|
6160
6751
|
const focus = flag("focus");
|
|
6161
6752
|
if (focus !== undefined && !b.FOCUS_RE.test(focus))
|
|
6162
6753
|
die("--focus takes an act or decision id (a_… or o_…)");
|
|
6754
|
+
const focusTeam = flag("space");
|
|
6163
6755
|
const plain = argv.includes("--url") ? await b.boardLinkFor(r.state).catch((e) => die(e.message)) : r.url;
|
|
6164
|
-
const url = focus && r.state.version === VERSION ? b.focusLink(plain, focus) : plain;
|
|
6756
|
+
const url = focus && r.state.version === VERSION ? b.focusLink(plain, focus, focusTeam) : plain;
|
|
6165
6757
|
const opened = argv.includes("--no-browser") ? false : await b.openBrowser(url).catch(() => false);
|
|
6166
6758
|
console.error(`${B("pantheon board")} ${D(r.reused ? "(already running)" : "(started)")}`);
|
|
6167
6759
|
if (!opened)
|