@join-pantheon/cli 0.34.0-rc.1 → 0.34.1-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,222 @@
1
+ import { watch } from "node:fs";
2
+ import { POLL_MS } from "./power.js";
3
+ export const HELPER_PROTOCOL = 3;
4
+ export const NUDGE_GAP_MS = { ac: 2_000, battery: 10_000 };
5
+ export const COMPUTE_LIMIT_MS = 20_000;
6
+ export const MAX_FRAME_BYTES = 1_000_000;
7
+ export function encodeFrame(f) {
8
+ return JSON.stringify(f) + "\n";
9
+ }
10
+ export function parseHelperLine(line) {
11
+ const l = line.trim();
12
+ const hello = /^@hello (\d{1,4})$/.exec(l);
13
+ if (hello)
14
+ return { t: "hello", version: Number(hello[1]) };
15
+ if (l === "@refresh")
16
+ return { t: "refresh" };
17
+ const power = /^@power (ac|battery)$/.exec(l);
18
+ if (power)
19
+ return { t: "power", power: power[1] };
20
+ return null;
21
+ }
22
+ export class StatusEngine {
23
+ io;
24
+ started = false;
25
+ stopped = false;
26
+ helperPower = null;
27
+ inFlight = false;
28
+ pending = null;
29
+ lastStart = Number.NEGATIVE_INFINITY;
30
+ seq = 0;
31
+ soonTimer = null;
32
+ backstopTimer = null;
33
+ counts = { nudge: 0, refresh: 0, backstop: 0, hello: 0, frames: 0, failed: 0 };
34
+ constructor(io) {
35
+ this.io = io;
36
+ }
37
+ get power() { return this.helperPower ?? this.io.power?.() ?? "ac"; }
38
+ get isStarted() { return this.started; }
39
+ onHelperLine(line) {
40
+ const m = parseHelperLine(line);
41
+ if (!m)
42
+ return false;
43
+ if (this.stopped)
44
+ return true;
45
+ if (m.t === "hello") {
46
+ if (m.version < HELPER_PROTOCOL)
47
+ return true;
48
+ if (!this.started) {
49
+ this.started = true;
50
+ this.counts.hello++;
51
+ this.io.log(`menu bar helper speaks protocol ${m.version}: status is sent to it (no tray-status spawns)`);
52
+ this.run();
53
+ }
54
+ return true;
55
+ }
56
+ if (m.t === "refresh") {
57
+ this.counts.refresh++;
58
+ this.request("now");
59
+ return true;
60
+ }
61
+ if (m.t === "power") {
62
+ const was = this.power;
63
+ this.helperPower = m.power;
64
+ if (was !== m.power && this.started && !this.inFlight)
65
+ this.armBackstop();
66
+ return true;
67
+ }
68
+ return true;
69
+ }
70
+ nudge() { if (this.started && !this.stopped) {
71
+ this.counts.nudge++;
72
+ this.request("soon");
73
+ } }
74
+ stop() {
75
+ this.stopped = true;
76
+ if (this.soonTimer !== null)
77
+ this.io.clearTimer(this.soonTimer);
78
+ if (this.backstopTimer !== null)
79
+ this.io.clearTimer(this.backstopTimer);
80
+ this.soonTimer = this.backstopTimer = null;
81
+ }
82
+ request(kind) {
83
+ if (!this.started || this.stopped)
84
+ return;
85
+ if (this.inFlight) {
86
+ if (kind === "now" || !this.pending)
87
+ this.pending = kind;
88
+ return;
89
+ }
90
+ if (kind === "now") {
91
+ this.run();
92
+ return;
93
+ }
94
+ const wait = this.lastStart + NUDGE_GAP_MS[this.power] - this.io.now();
95
+ if (wait <= 0) {
96
+ this.run();
97
+ return;
98
+ }
99
+ if (this.soonTimer === null)
100
+ this.soonTimer = this.io.setTimer(() => { this.soonTimer = null; this.request("now"); }, wait);
101
+ }
102
+ armBackstop() {
103
+ if (this.backstopTimer !== null)
104
+ this.io.clearTimer(this.backstopTimer);
105
+ this.backstopTimer = this.io.setTimer(() => { this.backstopTimer = null; this.counts.backstop++; this.request("now"); }, POLL_MS[this.power]);
106
+ }
107
+ run() {
108
+ if (this.stopped)
109
+ return;
110
+ if (this.soonTimer !== null) {
111
+ this.io.clearTimer(this.soonTimer);
112
+ this.soonTimer = null;
113
+ }
114
+ if (this.backstopTimer !== null) {
115
+ this.io.clearTimer(this.backstopTimer);
116
+ this.backstopTimer = null;
117
+ }
118
+ this.inFlight = true;
119
+ this.lastStart = this.io.now();
120
+ let limit = null;
121
+ const bounded = new Promise((resolve, reject) => {
122
+ limit = this.io.setTimer(() => reject(new Error(`no answer in ${COMPUTE_LIMIT_MS / 1000}s`)), COMPUTE_LIMIT_MS);
123
+ this.io.compute().then(resolve, reject);
124
+ });
125
+ void bounded.then((status) => {
126
+ if (this.stopped)
127
+ return;
128
+ const power = this.power;
129
+ const line = encodeFrame({ v: 1, t: "status", seq: ++this.seq, at: this.io.now(), next_ms: POLL_MS[power], power, status });
130
+ if (Buffer.byteLength(line) > MAX_FRAME_BYTES) {
131
+ this.counts.failed++;
132
+ this.io.log(`status too large to send (${Buffer.byteLength(line)} bytes): the helper checks for itself`);
133
+ return;
134
+ }
135
+ if (this.io.write(line))
136
+ this.counts.frames++;
137
+ }, (e) => {
138
+ this.counts.failed++;
139
+ this.io.log(`status not computed: ${e?.message ?? e}`);
140
+ }).finally(() => {
141
+ if (limit !== null)
142
+ this.io.clearTimer(limit);
143
+ this.inFlight = false;
144
+ if (this.stopped)
145
+ return;
146
+ this.armBackstop();
147
+ const p = this.pending;
148
+ this.pending = null;
149
+ if (p)
150
+ this.request(p);
151
+ });
152
+ }
153
+ }
154
+ export const HOME_FILES = new Set([
155
+ "worker-state.json", "spend.json", "readiness-alert.json", "setup-pending.json", "worker-policy.json",
156
+ "worker-declined.json", "run-control.json", "removed.json", "profile.json", "config.json",
157
+ ]);
158
+ export function watchNudges(o) {
159
+ const watchers = [];
160
+ const add = (dir, accept) => {
161
+ try {
162
+ o.mkdir?.(dir);
163
+ const w = watch(dir, { persistent: false }, (_ev, name) => { if (accept(name ? String(name) : null))
164
+ o.onNudge(); });
165
+ w.on("error", (e) => { o.log?.(`watch ${dir}: ${e.message} — the backstop poll covers it`); try {
166
+ w.close();
167
+ }
168
+ catch { } });
169
+ watchers.push(w);
170
+ }
171
+ catch (e) {
172
+ o.log?.(`could not watch ${dir}: ${e.message} — the backstop poll covers it`);
173
+ }
174
+ };
175
+ add(o.statusDir, (name) => !name || !name.startsWith("conn-"));
176
+ add(o.home, (name) => !!name && [...HOME_FILES].some((f) => name === f || name.startsWith(`${f}.`)));
177
+ return () => { for (const w of watchers) {
178
+ try {
179
+ w.close();
180
+ }
181
+ catch { }
182
+ } };
183
+ }
184
+ export function attachHelper(o) {
185
+ let broken = false;
186
+ o.stdin?.on("error", () => { broken = true; });
187
+ const write = (line) => {
188
+ if (broken || !o.stdin || o.stdin.destroyed || !o.stdin.writable)
189
+ return false;
190
+ try {
191
+ o.stdin.write(line);
192
+ return true;
193
+ }
194
+ catch {
195
+ broken = true;
196
+ return false;
197
+ }
198
+ };
199
+ const engine = o.engine(write);
200
+ if (o.stdout) {
201
+ o.stdout.setEncoding?.("utf8");
202
+ let buf = "";
203
+ o.stdout.on("data", (d) => {
204
+ buf += String(d);
205
+ if (buf.length > 64 * 1024 && !buf.includes("\n")) {
206
+ o.passLine(buf.slice(0, 2000));
207
+ buf = "";
208
+ return;
209
+ }
210
+ let i;
211
+ while ((i = buf.indexOf("\n")) >= 0) {
212
+ const line = buf.slice(0, i).replace(/\r$/, "");
213
+ buf = buf.slice(i + 1);
214
+ if (!engine.onHelperLine(line) && line)
215
+ o.passLine(line);
216
+ }
217
+ });
218
+ o.stdout.on("error", () => { });
219
+ }
220
+ return engine;
221
+ }
222
+ //# sourceMappingURL=status-engine.js.map
@@ -0,0 +1,34 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { CONFIG_DIR } from "./config.js";
4
+ export const statusDir = (home = CONFIG_DIR) => join(home, "status");
5
+ export const NUDGE_FILE = "nudge";
6
+ export function statusNudge(home = CONFIG_DIR) {
7
+ try {
8
+ const dir = statusDir(home);
9
+ mkdirSync(dir, { recursive: true });
10
+ writeFileSync(join(dir, NUDGE_FILE), `${Date.now()}\n`);
11
+ }
12
+ catch { }
13
+ }
14
+ export function obligationSignature(obligations, connected) {
15
+ const parts = obligations.map((o) => `${o.id}:${o.owner}:${o.claimed ? 1 : 0}`).sort();
16
+ return `${connected ? "up" : "down"}|${parts.join(",")}`;
17
+ }
18
+ export class StatusNudger {
19
+ home;
20
+ touch;
21
+ last = null;
22
+ constructor(home = CONFIG_DIR, touch = statusNudge) {
23
+ this.home = home;
24
+ this.touch = touch;
25
+ }
26
+ observe(signature) {
27
+ if (signature === this.last)
28
+ return false;
29
+ this.last = signature;
30
+ this.touch(this.home);
31
+ return true;
32
+ }
33
+ }
34
+ //# sourceMappingURL=status-nudge.js.map
package/dist/tray.js CHANGED
@@ -9,7 +9,7 @@ import { platform } from "node:os";
9
9
  import { dirname, join, resolve } from "node:path";
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { CONFIG_DIR, load, loadAll, configFor } from "./config.js";
12
- import { workerProc, notifierProc } from "./machine.js";
12
+ import { isPantheonRole, workerProc, notifierProc } from "./machine.js";
13
13
  import { agentHookStates } from "./notify.js";
14
14
  import { plistPath, serviceInstalled, whichPantheon } from "./service.js";
15
15
  import { VERSION } from "./version.js";
@@ -19,9 +19,13 @@ import { clearRemoval, goneLine, goneOf, recordGone, recordRemoval, removalFor,
19
19
  import { pickupEstimate } from "./pickup.js";
20
20
  import { allDecisionsPrompt, decisionPrompt, decisionTitle, owedPrompt, stripCeremony, tidyIds, tidyLead, waitingPrompt, workerSummary } from "./decision-ui.js";
21
21
  import { loadProfile, SURFACE_BUNDLE_IDS } from "./profile.js";
22
- import { agentProblem, PROBLEM_LEAD } from "./readiness-alert.js";
22
+ import { agentProblem, agentProblemFix, PROBLEM_LEAD } from "./readiness-alert.js";
23
+ import { runsToday } from "./spend.js";
24
+ import { stuckConnections } from "./conn-report.js";
23
25
  import { claudeAppPresent, effectiveOpenIn } from "./open-in.js";
24
26
  const HERE = dirname(fileURLToPath(import.meta.url));
27
+ let running = (k) => (k === "worker" ? workerProc() : notifierProc()).running;
28
+ export function useRunningProbe(p) { running = p; }
25
29
  export const trayBinaryPath = (home = CONFIG_DIR) => join(home, "bin", "pantheon-tray");
26
30
  export const traySourcePath = () => resolve(HERE, "..", "helper", "macos", "menubar.swift");
27
31
  export const TRAY_PREBUILT = "pantheon-tray";
@@ -181,9 +185,26 @@ async function signedObligations(cfg, removed = null) {
181
185
  }
182
186
  }
183
187
  export async function trayStatus(cfg = load(), f = loadAll()) {
184
- return withLocal(await trayStatusAll(cfg, f));
188
+ return withStuck(withLocal(await trayStatusAll(cfg, f)));
185
189
  }
186
- export function withLocal(st, _home = CONFIG_DIR) {
190
+ function withStuck(st) {
191
+ if (!st.configured || !st.relay_ok)
192
+ return st;
193
+ try {
194
+ const s = stuckConnections({ isRole: isPantheonRole });
195
+ return s.length ? { ...st, stuck_connections: s.map((x) => ({ what: x.what, fix: x.fix, since: x.since, line: x.line })) } : st;
196
+ }
197
+ catch {
198
+ return st;
199
+ }
200
+ }
201
+ export function machineTrayStatus() {
202
+ const f = loadAll();
203
+ const ms = Object.values(f?.spaces ?? {});
204
+ return trayStatus(f && ms.length ? configFor(f, ms[0], null) : load(), f);
205
+ }
206
+ export function withLocal(st0, _home = CONFIG_DIR) {
207
+ const st = withRunsToday(st0);
187
208
  try {
188
209
  const list = loadPending();
189
210
  if (!list.length)
@@ -208,6 +229,28 @@ export function withLocal(st, _home = CONFIG_DIR) {
208
229
  return st;
209
230
  }
210
231
  }
232
+ function ownMembers() {
233
+ try {
234
+ const m = loadAll()?.member;
235
+ return m ? [m] : [];
236
+ }
237
+ catch {
238
+ return [];
239
+ }
240
+ }
241
+ function withRunsToday(st) {
242
+ if (!st.configured)
243
+ return st;
244
+ try {
245
+ const own = new Set(ownMembers());
246
+ if (st.member)
247
+ own.add(st.member);
248
+ return { ...st, runs_today: runsToday(own) };
249
+ }
250
+ catch {
251
+ return st;
252
+ }
253
+ }
211
254
  async function trayStatusAll(cfg, f) {
212
255
  const ms = Object.values(f?.spaces ?? {});
213
256
  if (f && ms.length > 1) {
@@ -330,7 +373,7 @@ async function trayStatusOne(cfg, membershipId) {
330
373
  : r;
331
374
  }),
332
375
  ];
333
- const workerRunning = workerProc().running;
376
+ const workerRunning = running("worker");
334
377
  const board = arrangeBoard(items, { now: Date.now(), workerRunning, autopilot: (() => { try {
335
378
  return effectiveMode(loadPolicy()) === "autopilot";
336
379
  }
@@ -369,7 +412,7 @@ async function trayStatusOne(cfg, membershipId) {
369
412
  waiting_count: waiting.length,
370
413
  };
371
414
  }
372
- function machineFields(cfg, workerRunning = workerProc().running) {
415
+ function machineFields(cfg, workerRunning = running("worker")) {
373
416
  const profile = loadProfile(cfg);
374
417
  const surface = profile.agent.primary_surface;
375
418
  const appHere = (() => { try {
@@ -396,9 +439,16 @@ function machineFields(cfg, workerRunning = workerProc().running) {
396
439
  worker_running: workerRunning,
397
440
  worker_installed: serviceInstalled("worker"),
398
441
  worker_plist: plistPath("worker"),
399
- notifier_running: notifierProc().running,
442
+ notifier_running: running("notifier"),
400
443
  hook_on: agentHookStates().length > 0,
401
444
  ...(problem ? { agent_problem: problem, agent_problem_lead: PROBLEM_LEAD, worker_state: `${PROBLEM_LEAD}: ${problem}` } : rawWorkerState ? { worker_state: workerSummary(rawWorkerState) } : {}),
445
+ ...(problem ? (() => { try {
446
+ const fix = agentProblemFix(CONFIG_DIR);
447
+ return fix ? { agent_problem_fix: fix } : {};
448
+ }
449
+ catch {
450
+ return {};
451
+ } })() : {}),
402
452
  surface_name: surfaceName,
403
453
  surface_bundle_id: SURFACE_BUNDLE_IDS[surface],
404
454
  open_in: openIn,
@@ -1,6 +1,7 @@
1
- import { MARK, SEAL, cap, esc, head, pct, plural, rangeSeg, rangeWords, script, split, stackedColumns, steps, when } from "./admin-ui.js";
2
- import { asOfHtml, signinShell, stateNoteHtml, stepSubs, threadOutcome } from "./admin-pages.js";
1
+ import { MARK, SEAL, cap, esc, head, pct, plural, rangeSeg, rangeWords, script, secbar, split, stackedColumns, when } from "./admin-ui.js";
2
+ import { asOfHtml, signinShell, stateNoteHtml } from "./admin-pages.js";
3
3
  import { dur } from "./flow-stats.js";
4
+ import { GOAL_CSS, goalDiagram, goalSummary } from "./goal-flow.js";
4
5
  export function renderViewerSignin(o) {
5
6
  const hero = `<h1>See how your team's work moves.</h1>
6
7
  <p>Read-only access to the Pantheon teams you were added to. You see who asked whom, who picked it up and how long it took.</p>
@@ -31,12 +32,12 @@ export function renderViewerSignin(o) {
31
32
  }
32
33
  const shell = (o) => `${head({ title: o.title, description: o.description, nonce: o.nonce, refresh: o.refresh, refreshTo: o.refreshTo })}
33
34
  <body>
34
- <header class="top">
35
+ <div class="stick"><header class="top">
35
36
  <a class="skip" href="#main">Skip to content</a>
36
37
  <a class="lockup" href="/view">${MARK}<b>Pantheon</b></a>
37
38
  <span class="ctx">${o.ctx}</span>
38
- <div class="right"><span class="wrapc">${esc(o.email)}</span><button type="button" class="iconbtn" data-theme-toggle>Dark</button><form method="POST" action="/view/signout" class="inl"><input type="hidden" name="csrf" value="${esc(o.csrf)}"><button class="linkbtn">Sign out</button></form></div>
39
- </header>
39
+ <div class="right"><span class="wrapc id">${esc(o.email)}</span><button type="button" class="iconbtn" data-theme-toggle>Dark</button><form method="POST" action="/view/signout" class="inl"><input type="hidden" name="csrf" value="${esc(o.csrf)}"><button class="linkbtn">Sign out</button></form></div>
40
+ </header>${o.secbar ?? ""}</div>
40
41
  <main id="main">
41
42
  ${o.body}
42
43
  </main>
@@ -107,38 +108,37 @@ export function renderViewerTeam(d) {
107
108
  <tbody>${f.matrix.from.map((from) => `<tr><th scope="row" class="rowh">${esc(cap(from))}</th>${f.matrix.to.map((to) => from === to ? `<td class="self" aria-hidden="true"></td>` : cell(f.matrix.n[from]?.[to] ?? 0, from, to)).join("")}</tr>`).join("")}</tbody>
108
109
  </table>` : `<p class="muted" style="margin:0">Nobody asked anyone ${range}.</p>`;
109
110
  const waiting = f.waiting.map((w) => `<li><div class="t"><b>${esc(cap(w.owner))}</b> to decide${w.from && w.from !== w.owner ? `, asked by ${esc(cap(w.from))}'s agent` : ", escalated by their own agent"} <span class="num">${dur(w.ageMs)}</span> ago<span class="sub">${w.goalTitle ? `in ${esc(w.goalTitle)}` : "not in a goal"}${w.blocksGoal ? " · the goal is blocked until they answer" : ""}</span></div></li>`).join("");
110
- const flowRows = f.threads.map((t) => {
111
- const oc = threadOutcome(t, true);
112
- return `<li><span class="ic" aria-hidden="true">→</span><div class="t">
113
- <div class="row" style="gap:8px"><b>${t.kind === "decision" && t.from === t.to ? `${esc(cap(t.from))} escalated` : `${esc(cap(t.from))} → ${esc(cap(t.to))}`}</b> ${oc.chip} ${oc.role}</div>
114
- <span class="sub">${t.goalTitle ? `in ${esc(t.goalTitle)} · ` : ""}<i class="hidden-text">message text hidden</i></span>
115
- ${steps(stepSubs(t))}
116
- <span class="sub">${esc(oc.text)}</span></div></li>`;
117
- }).join("");
118
111
  const pron = (who) => cap(who);
119
112
  const carriedRows = f.carried.map((c) => `<tr><td class="span"><b class="who">${esc(cap(c.who))}</b><span class="sub">${esc(c.agent)}</span></td><td data-l="Asked" class="r num">${c.asked}</td><td data-l="Answered by" class="span">${split(c.byWorker, c.byPerson, c.asked, 140)}<span class="sub num">${c.byWorker} by their worker · ${c.byPerson} by ${esc(pron(c.who))} in person</span></td><td data-l="Median time to answer" class="r num">${c.medianMs !== null ? dur(c.medianMs) : `<span class="quiet">none yet</span>`}</td><td data-l="Open now" class="r num">${c.open || `<span class="quiet">0</span>`}</td></tr>`).join("");
120
- const goalRows = f.goals.filter((g) => g.state !== "CLOSED").map((g) => `<tr><td class="span"><b>${esc(g.title)}</b>${g.worklist ? ` <span class="chip plain">worklist</span>` : ""}${g.why ? `<span class="sub">${g.state === "BLOCKED" ? "blocked " : ""}${esc(g.why)}</span>` : ""}</td><td data-l="State">${g.state === "OPEN" ? `<span class="chip">open</span>` : g.state === "STALLED" ? `<span class="chip line">${SEAL} out of acts</span>` : `<span class="chip line">${SEAL} blocked</span>`}</td><td data-l="Deadline">${g.deadline ? `${when(g.deadline, "full")}${g.overdueMs !== null ? ` <span class="chip line">overdue</span>` : ""}` : `<span class="quiet">none</span>`}</td><td data-l="Open items" class="r num">${g.open || `<span class="quiet">0</span>`}</td></tr>`).join("");
113
+ const goalRows = f.goals.filter((g) => g.state !== "CLOSED").map((g) => `<tr><td class="span"><b>${esc(g.title)}</b>${g.worklist ? ` <span class="chip plain">worklist</span>` : ""}${g.why ? `<span class="sub">${g.state === "BLOCKED" ? "blocked " : ""}${esc(g.why)}</span>` : ""}<a class="more seeflow" href="/view/goal?name=${encodeURIComponent(d.team)}&amp;id=${esc(encodeURIComponent(g.id))}">See how it moved</a></td><td data-l="State">${g.state === "OPEN" ? `<span class="chip">open</span>` : g.state === "STALLED" ? `<span class="chip line">${SEAL} out of acts</span>` : `<span class="chip line">${SEAL} blocked</span>`}</td><td data-l="Deadline">${g.deadline ? `${when(g.deadline, "full")}${g.overdueMs !== null ? ` <span class="chip line">overdue</span>` : ""}` : `<span class="quiet">none</span>`}</td><td data-l="Open items" class="r num">${g.open || `<span class="quiet">0</span>`}</td></tr>`).join("");
121
114
  const openGoals = f.goals.filter((g) => g.state !== "CLOSED").length;
122
115
  return shell({
123
116
  nonce: d.nonce, csrf: d.csrf, email: d.email, title: `${d.team} · Pantheon team view`,
124
117
  description: "Read-only view of how work moves in one team: who asked whom, who picked it up, how long it took, and what waits on a person.",
125
- ctx: `<b style="color:var(--text);font-size:14px">${esc(d.team)}</b><span class="chip plain">read-only</span>`,
118
+ ctx: `<b style="color:var(--text);font-size:15px">${esc(d.team)}</b><span class="chip plain">read-only</span>`,
119
+ secbar: secbar([
120
+ { id: "moved", label: "How work moved" },
121
+ { id: "waiting", label: "Waiting on a person", n: d.stateNote?.kind === "rebuild" ? null : f.waiting.length },
122
+ { id: "handoffs", label: "Who asked whom" },
123
+ { id: "carried", label: "Who carried the work" },
124
+ { id: "goals", label: "Goals", n: d.stateNote?.kind === "rebuild" ? null : openGoals },
125
+ ], "Team view sections"),
126
126
  body: ` <div class="privacy" role="note">
127
127
  <span aria-hidden="true">${SEAL}</span>
128
128
  <div>You see who handed work to whom, who picked it up and how long it took. Message text, code and files stay with the team. The relay's operator added you on ${when(d.grantedAt, "date")}, and the team was told. Access ends ${when(d.expiresAt, "date")}.</div>
129
129
  </div>
130
130
 
131
- <div class="sechead" style="margin-top:24px">
131
+ <div class="sechead" id="moved" style="margin-top:24px">
132
132
  <h1>How work moved ${range}</h1>
133
133
  <div class="end">${rangeSeg((n) => `/view/team?name=${encodeURIComponent(d.team)}&range=${n}`, d.days)}</div>
134
134
  </div>
135
135
 
136
136
  <div class="grid2">
137
- <section class="tile call" aria-labelledby="h-wait" style="padding:18px 20px">
137
+ <section class="tile call" id="waiting" aria-labelledby="h-wait" style="padding:18px 20px">
138
138
  <div class="l" id="h-wait">${SEAL} Waiting on a person</div>
139
139
  <div class="v" style="font-size:56px;line-height:1;margin:8px 0 10px">${d.stateNote?.kind === "rebuild" ? "–" : f.waiting.length}</div>
140
140
  <ul class="list" style="margin:0 -20px -18px;border-top:1px solid var(--line)">${waiting || `<li class="none"><div class="t">${d.stateNote?.kind === "rebuild" ? "Not shown until this team rebuilds (the next time a member connects)." : "No decision is waiting on anyone."}</div></li>`}</ul>
141
- ${d.live && asOfHtml(d.asOf, d.now ?? Date.now()) ? `<p class="quiet" style="margin:10px 0 0;font-size:12px">${asOfHtml(d.asOf, d.now ?? Date.now())}; refreshes every 15 seconds</p>` : ""}
141
+ ${d.live && asOfHtml(d.asOf, d.now ?? Date.now()) ? `<p class="quiet" style="margin:10px 0 0;font-size:13.5px">${asOfHtml(d.asOf, d.now ?? Date.now())}; refreshes every 15 seconds</p>` : ""}
142
142
  </section>
143
143
  <div class="tiles" style="grid-template-columns:repeat(2,minmax(0,1fr));margin-top:0">
144
144
  <div class="tile"><div class="l">Requests handed off</div><div class="v">${f.asks}${f.partial ? `<small>partial</small>` : ""}</div><div class="d">between ${plural(people, "person's agents", "people's agents")}</div></div>
@@ -150,12 +150,7 @@ export function renderViewerTeam(d) {
150
150
 
151
151
  ${stateNoteHtml(d.stateNote, true)}
152
152
  ${f.historyFrom ? `<p class="note">Partial: counts start ${when(f.historyFrom, "full")}. Older history in this range was compacted on the relay, so asks, answers and hand-offs before then are not counted.</p>` : ""}
153
- <div class="grid2 sec">
154
- <section class="card" aria-labelledby="h-flow">
155
- <div class="sechead cardhead" style="margin-bottom:4px"><h2 id="h-flow">Recent hand-offs</h2><p>Ask, propose, contract, commit, delivered</p></div>
156
- <ul class="list">${flowRows || `<li class="none"><div class="t">No hand-offs ${range}.</div></li>`}</ul>
157
- </section>
158
- <div class="stack">
153
+ <div class="grid2 even sec" id="handoffs">
159
154
  <section class="card pad" aria-labelledby="h-who">
160
155
  <div class="sechead" style="margin-bottom:10px"><h2 id="h-who">Who asked whom</h2><p>rows asked, columns were asked</p></div>
161
156
  <div class="scroll">${matrix}</div>
@@ -163,12 +158,11 @@ export function renderViewerTeam(d) {
163
158
  </section>
164
159
  <section class="card pad" aria-labelledby="h-daily">
165
160
  <div class="sechead" style="margin-bottom:4px"><h2 id="h-daily">Messages per day</h2><p>the last 14 UTC days</p></div>
166
- ${stackedColumns({ days: d.series14, width: 520, height: 160, step: 3, label: `Messages per day for 14 days. ${f.messages.total} ${range}, ${f.messages.worker} by workers.` })}
161
+ ${stackedColumns({ days: d.series14, width: 620, height: 190, step: 3, label: `Messages per day for 14 days. ${f.messages.total} ${range}, ${f.messages.worker} by workers.` })}
167
162
  </section>
168
- </div>
169
163
  </div>
170
164
 
171
- <section class="sec" aria-labelledby="h-carry">
165
+ <section class="sec" id="carried" aria-labelledby="h-carry">
172
166
  <div class="sechead"><h2 id="h-carry">Who carried the work</h2><p>requests each person was asked, and whether their worker or they answered</p></div>
173
167
  <div class="card"><table class="rt">
174
168
  <thead><tr><th>Asked of</th><th class="r">Asked</th><th>Answered by</th><th class="r">Median time to answer</th><th class="r">Open now</th></tr></thead>
@@ -176,8 +170,8 @@ export function renderViewerTeam(d) {
176
170
  </table></div>
177
171
  </section>
178
172
 
179
- <section class="sec" aria-labelledby="h-goals">
180
- <div class="sechead"><h2 id="h-goals">Goals in progress</h2><p>${openGoals} open</p></div>
173
+ <section class="sec" id="goals" aria-labelledby="h-goals">
174
+ <div class="sechead"><h2 id="h-goals">Goals in progress</h2><p>${openGoals} open · "See how it moved" draws who handed what to whom</p></div>
181
175
  <div class="card"><table class="rt">
182
176
  <thead><tr><th>Goal</th><th>State</th><th>Deadline</th><th class="r">Open items</th></tr></thead>
183
177
  <tbody>${goalRows || `<tr><td colspan="4" class="empty">No goal is open.</td></tr>`}</tbody>
@@ -187,4 +181,17 @@ export function renderViewerTeam(d) {
187
181
  <p class="note" style="margin-top:28px">This page reads the team's hand-off record on its Pantheon relay. Pantheon adds no tracking to make it. Your visits are logged (about one entry per 10 minutes), and the team and the relay's operator can see that log. Times are in your browser's time zone.</p>`,
188
182
  });
189
183
  }
184
+ export function renderViewerGoal(d) {
185
+ const f = d.flow;
186
+ return shell({
187
+ nonce: d.nonce, csrf: d.csrf, email: d.email, title: `${f.goal.title} · ${d.team} · Pantheon team view`,
188
+ description: "How one goal moved between people and their agents: who handed what to whom, and how long each step waited. No message text.",
189
+ ctx: `<a href="/view/team?name=${encodeURIComponent(d.team)}#goals"><b style="color:var(--text);font-size:15px">${esc(d.team)}</b></a><span class="chip plain">read-only</span>`,
190
+ body: `<style nonce="${esc(d.nonce)}">${GOAL_CSS}</style>
191
+ <div class="sechead" style="margin-top:24px;margin-bottom:0"><h1>${esc(f.goal.title)}</h1><p>how it moved between people and their agents</p></div>
192
+ ${goalSummary(f)}
193
+ ${goalDiagram(f)}
194
+ <p class="note">Only who acted, what kind of act it was, when, and how long each step waited. Message text, code and files stay with the team.</p>`,
195
+ });
196
+ }
190
197
  //# sourceMappingURL=viewer-pages.js.map
package/dist/win-host.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { spawn } from "node:child_process";
2
- import { closeSync, existsSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
2
+ import { appendFileSync, closeSync, existsSync, watch, linkSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
3
3
  import { createHash } from "node:crypto";
4
4
  import { homedir } from "node:os";
5
5
  import { dirname, join, resolve, win32 } from "node:path";
@@ -118,6 +118,8 @@ function writeAtomic(f, text) {
118
118
  }
119
119
  }
120
120
  export const HOST_BEAT_STALE_MS = 30_000;
121
+ export const HOST_TICK_MS = 10_000;
122
+ export const HOST_BEAT_MS = 10_000;
121
123
  export function readLaunchError(home = CONFIG_DIR) {
122
124
  try {
123
125
  const [at, what, ...rest] = readFileSync(hostFiles(home).launchError, "utf8").replace(/^\uFEFF/, "").trim().split("\t");
@@ -304,6 +306,9 @@ export class HostLoop {
304
306
  pid;
305
307
  s;
306
308
  started;
309
+ afterStep = null;
310
+ written = "";
311
+ writtenAt = Number.NEGATIVE_INFINITY;
307
312
  constructor(io, policy = HOST_POLICY, pid = process.pid) {
308
313
  this.io = io;
309
314
  this.policy = policy;
@@ -340,15 +345,33 @@ export class HostLoop {
340
345
  this.feed({ t: "started", child: c.child, pid, now, ...(typeof started === "number" ? {} : { argv: started.argv }) });
341
346
  }
342
347
  else if (c.do === "exit") {
343
- this.writeState();
348
+ this.writeState(true);
344
349
  this.io.exit(c.code);
345
350
  }
346
351
  }
347
352
  }
348
- writeState() { try {
349
- this.io.writeState(hostReport(this.s, this.pid, this.started, this.io.now(), VERSION, this.io.session));
353
+ writeState(force = false) {
354
+ try {
355
+ const now = this.io.now();
356
+ const r = hostReport(this.s, this.pid, this.started, now, VERSION, this.io.session);
357
+ const said = JSON.stringify({ ...r, beat: 0 });
358
+ if (!force && said === this.written && now - this.writtenAt < HOST_BEAT_MS)
359
+ return;
360
+ this.io.writeState(r);
361
+ this.written = said;
362
+ this.writtenAt = now;
363
+ }
364
+ catch { }
365
+ }
366
+ nextDue() {
367
+ let due = null;
368
+ for (const c of HOST_CHILDREN) {
369
+ const n = this.s.children[c].nextAt;
370
+ if (n !== undefined && (due === null || n < due))
371
+ due = n;
372
+ }
373
+ return due;
350
374
  }
351
- catch { } }
352
375
  tick() {
353
376
  const { want, installed } = this.io.want();
354
377
  const stop = this.io.stopRequested() || this.io.parentGone() || installed === 0;
@@ -356,11 +379,13 @@ export class HostLoop {
356
379
  this.feed({ t: "tick", now: this.io.now(), want, restart: this.io.takeRestarts(), stop, restartHost });
357
380
  if (!this.s.done)
358
381
  this.writeState();
382
+ this.afterStep?.();
359
383
  }
360
384
  exited(child, code, signal) {
361
385
  this.feed({ t: "exited", child, code, signal, now: this.io.now(), want: this.io.want().want[child] });
362
386
  if (!this.s.done)
363
387
  this.writeState();
388
+ this.afterStep?.();
364
389
  }
365
390
  }
366
391
  export const trayScriptPath = () => resolve(HERE, "..", "helper", "windows", "pantheon-tray.ps1");
@@ -598,10 +623,28 @@ export function realHostIo(o = {}) {
598
623
  const fd = openLog(f.childLog(child));
599
624
  try {
600
625
  writeSync(fd, `\n--- ${new Date().toISOString()} the Pantheon host starts the ${child}\n`);
601
- const proc = spawn(argv[0], argv.slice(1), { cwd, stdio: ["ignore", fd, fd], windowsHide: true, env: { ...process.env, PANTHEON_HOST_SESSION: session } });
626
+ const piped = child === "tray" && !!o.trayPipe;
627
+ const proc = spawn(argv[0], argv.slice(1), { cwd, stdio: piped ? ["pipe", "pipe", fd] : ["ignore", fd, fd], windowsHide: true, env: { ...process.env, PANTHEON_HOST_SESSION: session } });
602
628
  let done = false;
629
+ let detach = null;
630
+ if (piped && proc.pid) {
631
+ const logFile = f.childLog(child);
632
+ try {
633
+ detach = o.trayPipe(proc, (line) => { try {
634
+ appendFileSync(logFile, `${line}\n`);
635
+ }
636
+ catch { } });
637
+ }
638
+ catch {
639
+ detach = null;
640
+ }
641
+ }
603
642
  const finish = (code, signal) => { if (!done) {
604
643
  done = true;
644
+ try {
645
+ detach?.();
646
+ }
647
+ catch { }
605
648
  onExit(code, signal);
606
649
  } };
607
650
  if (!proc.pid) {
@@ -735,6 +778,7 @@ export function orphans(prev, isOurs, alive = pidAlive, self = process.pid) {
735
778
  }
736
779
  return out;
737
780
  }
781
+ export const HOST_WATCHED = /^(stop|(worker|notifier|tray)\.(disabled|restart)|(worker|notifier)\.json)$/;
738
782
  export function runHost(o = {}) {
739
783
  const home = o.home ?? CONFIG_DIR;
740
784
  const f = hostFiles(home);
@@ -757,8 +801,36 @@ export function runHost(o = {}) {
757
801
  catch { }
758
802
  }
759
803
  const loop = new HostLoop({ ...io, exit: (code) => { rmSync(f.state, { force: true }); rmSync(f.lock, { force: true }); io.log(`host exits (${code === HOST_RESTART_CODE ? "to start again on the new version" : "stopped"})`); process.exit(code); } });
804
+ let due = null;
805
+ const run = () => { if (!loop.s.done)
806
+ loop.tick(); };
807
+ loop.afterStep = () => {
808
+ if (due) {
809
+ clearTimeout(due);
810
+ due = null;
811
+ }
812
+ const at = loop.nextDue();
813
+ if (at !== null && !loop.s.done)
814
+ due = setTimeout(run, Math.max(0, at - Date.now()) + 20);
815
+ };
760
816
  loop.tick();
761
- setInterval(() => loop.tick(), o.tickMs ?? 2_000);
817
+ setInterval(run, o.tickMs ?? HOST_TICK_MS);
818
+ let soon = null;
819
+ try {
820
+ mkdirSync(f.dir, { recursive: true });
821
+ const w = watch(f.dir, { persistent: false }, (_e, name) => {
822
+ if (!name || !HOST_WATCHED.test(String(name)) || soon)
823
+ return;
824
+ soon = setTimeout(() => { soon = null; run(); }, 100);
825
+ });
826
+ w.on("error", (e) => { io.log(`watching ${f.dir} stopped (${e.message}) — the ${Math.round((o.tickMs ?? HOST_TICK_MS) / 1000)} s tick covers it`); try {
827
+ w.close();
828
+ }
829
+ catch { } });
830
+ }
831
+ catch (e) {
832
+ io.log(`could not watch ${f.dir} (${e.message}) — the ${Math.round((o.tickMs ?? HOST_TICK_MS) / 1000)} s tick covers it`);
833
+ }
762
834
  }
763
835
  export function winQuote(a) {
764
836
  if (a.length > 0 && !/[\s"]/.test(a))