@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,203 @@
1
+ import { DAY_MS, flowIndex, median, rangeStart, answerIn, settleIn, utcDay } from "./flow-stats.js";
2
+ export const WEEKS = 8;
3
+ const okTime = (t) => typeof t === "number" && Number.isFinite(t) && Math.abs(t) <= 8.64e15;
4
+ export function weekBounds(now, k) {
5
+ return { from: rangeStart(now, 7 * (k + 1)), to: k === 0 ? now + 1 : rangeStart(now, 7 * k) };
6
+ }
7
+ export function weekStarts(now) {
8
+ return Array.from({ length: WEEKS }, (_, k) => rangeStart(now, 7 * (k + 1)));
9
+ }
10
+ export function weekIn(starts, now, ts) {
11
+ if (!okTime(ts) || !okTime(now) || ts > now)
12
+ return -1;
13
+ for (let k = 0; k < starts.length; k++)
14
+ if (ts >= starts[k])
15
+ return k;
16
+ return -1;
17
+ }
18
+ export function weekOf(now, ts) {
19
+ return okTime(now) ? weekIn(weekStarts(now), now, ts) : -1;
20
+ }
21
+ const emptyValue = (partial) => ({ asks: 0, answered: 0, byWorker: 0, byPerson: 0, answerMs: [], decisions: 0, decided: 0, decisionMs: [], delivered: 0, partial });
22
+ function usageSum(book, from, to, f) {
23
+ if (!book || !okTime(from) || !okTime(to))
24
+ return 0;
25
+ let n = 0;
26
+ for (let t = from, i = 0; t < to && i < 8; t += DAY_MS, i++) {
27
+ const d = book.days[utcDay(t)];
28
+ if (d)
29
+ n += f(d);
30
+ }
31
+ return n;
32
+ }
33
+ export function teamWeeksOf(input) {
34
+ const g = teamWeeksSteps(input);
35
+ for (let r = g.next();; r = g.next())
36
+ if (r.done)
37
+ return r.value;
38
+ }
39
+ export async function teamWeeksOfAsync(input, slice = 5_000) {
40
+ const g = teamWeeksSteps(input, slice);
41
+ for (let r = g.next();; r = g.next()) {
42
+ if (r.done)
43
+ return r.value;
44
+ await new Promise((x) => setImmediate(x));
45
+ }
46
+ }
47
+ function* teamWeeksSteps(input, slice = 5_000) {
48
+ const now = okTime(input.now) ? input.now : 0;
49
+ const starts = weekStarts(now);
50
+ const ix = input.index ?? flowIndex(input.records);
51
+ const ct = okTime(input.compactedThrough) ? input.compactedThrough : null;
52
+ const handoffs = new Array(WEEKS).fill(0), messages = new Array(WEEKS).fill(0);
53
+ const people = Array.from({ length: WEEKS }, () => new Set());
54
+ const partial = new Array(WEEKS).fill(false);
55
+ for (let k = 0; k < WEEKS; k++) {
56
+ const b = weekBounds(now, k);
57
+ partial[k] = ct !== null && ct >= b.from;
58
+ messages[k] = usageSum(input.usage, b.from, Math.min(b.to, now + 1), (d) => d.by_worker + d.by_person);
59
+ }
60
+ const value = [emptyValue(partial[0]), emptyValue(partial[1])];
61
+ let n = 0;
62
+ for (const r of ix.recs) {
63
+ if (++n % slice === 0)
64
+ yield;
65
+ const k = weekIn(starts, now, r.ts);
66
+ if (k < 0)
67
+ continue;
68
+ people[k].add(r.from);
69
+ if (r.act === "ASK")
70
+ handoffs[k]++;
71
+ if (k > 1)
72
+ continue;
73
+ const v = value[k];
74
+ if (r.act === "ASK") {
75
+ v.asks++;
76
+ const s = settleIn(ix, r.id);
77
+ if (s) {
78
+ v.answered++;
79
+ v.answerMs.push(Math.max(0, s.ts - r.ts));
80
+ if (s.by === "worker")
81
+ v.byWorker++;
82
+ else
83
+ v.byPerson++;
84
+ }
85
+ }
86
+ else if (r.act === "ESCALATE" || r.act === "HUMAN_REQUIRED") {
87
+ v.decisions++;
88
+ const decider = r.act === "ESCALATE" ? r.from : r.to?.[0];
89
+ const a = decider ? answerIn(ix, r.id, decider) : null;
90
+ if (a) {
91
+ v.decided++;
92
+ v.decisionMs.push(Math.max(0, a.ts - r.ts));
93
+ }
94
+ }
95
+ else if (r.act === "DELIVERED")
96
+ v.delivered++;
97
+ }
98
+ for (let k = 0; k < WEEKS; k++) {
99
+ if (!partial[k])
100
+ continue;
101
+ const b = weekBounds(now, k);
102
+ handoffs[k] = Math.max(handoffs[k], usageSum(input.usage, b.from, b.to, (d) => d.acts.ASK ?? 0));
103
+ }
104
+ let first = input.firstAskAt;
105
+ if (input.usage && (first === null || ct !== null)) {
106
+ const day = Object.keys(input.usage.days).filter((d) => (input.usage.days[d].acts.ASK ?? 0) > 0).sort()[0];
107
+ const at = day ? Date.parse(`${day}T00:00:00Z`) : null;
108
+ if (at !== null && (first === null || at < first))
109
+ first = at;
110
+ }
111
+ let last = input.lastActAt;
112
+ if (input.usage) {
113
+ const day = Object.keys(input.usage.days).filter((d) => input.usage.days[d].by_worker + input.usage.days[d].by_person > 0).sort().pop();
114
+ const at = day ? Math.min(now, Date.parse(`${day}T23:59:59Z`)) : null;
115
+ if (at !== null && (last === null || utcDay(at) > utcDay(last)))
116
+ last = at;
117
+ }
118
+ return {
119
+ name: input.name, createdAt: input.createdAt,
120
+ handoffs: handoffs.reverse(), messages: messages.reverse(), people: people.map((s) => [...s].sort()).reverse(), partial: partial.reverse(),
121
+ value, firstHandoffAt: first, lastActiveAt: last, askers: [...new Set(input.askers)].sort(),
122
+ };
123
+ }
124
+ const add = (a, b) => a.map((x, i) => x + (b[i] ?? 0));
125
+ export function founderView(input) {
126
+ const { teams } = input;
127
+ const now = okTime(input.now) ? input.now : 0;
128
+ const starts = weekStarts(now);
129
+ const zero = () => new Array(WEEKS).fill(0);
130
+ const activeTeams = zero(), handoffs = teams.reduce((a, t) => add(a, t.handoffs), zero());
131
+ for (const t of teams)
132
+ t.handoffs.forEach((n, i) => { if (n > 0)
133
+ activeTeams[i]++; });
134
+ const activePeople = Array.from({ length: WEEKS }, (_, i) => new Set(teams.flatMap((t) => t.people[i] ?? [])).size);
135
+ const usagePartial = teams.some((t) => t.partial.some(Boolean));
136
+ const pair = (f) => [teams.reduce((n, t) => n + f(t, 0), 0), teams.reduce((n, t) => n + f(t, 1), 0)];
137
+ const meds = (f) => [median(teams.flatMap((t) => f(t, 0))), median(teams.flatMap((t) => f(t, 1)))];
138
+ const newTeams = zero(), newPeople = zero();
139
+ for (const t of teams) {
140
+ if (t.createdAt === null)
141
+ continue;
142
+ const k = weekIn(starts, now, t.createdAt);
143
+ if (k >= 0)
144
+ newTeams[WEEKS - 1 - k]++;
145
+ }
146
+ for (const a of input.accounts) {
147
+ const k = weekIn(starts, now, a.created_at);
148
+ if (k >= 0)
149
+ newPeople[WEEKS - 1 - k]++;
150
+ }
151
+ const cohort = teams.filter((t) => t.createdAt !== null && t.createdAt >= now - 30 * DAY_MS && t.createdAt <= now);
152
+ const matured = cohort.filter((t) => t.createdAt <= now - 7 * DAY_MS);
153
+ const within7 = (t) => t.firstHandoffAt !== null && t.firstHandoffAt - t.createdAt <= 7 * DAY_MS;
154
+ const young = cohort.filter((t) => t.createdAt > now - 7 * DAY_MS);
155
+ const joinedSet = new Set([...input.admitted.values()].flat());
156
+ const askerSet = new Set(teams.flatMap((t) => t.askers));
157
+ const funnel = (accts) => ({
158
+ signedUp: accts.length,
159
+ joined: accts.filter((a) => joinedSet.has(a.username)).length,
160
+ handedOff: accts.filter((a) => joinedSet.has(a.username) && askerSet.has(a.username)).length,
161
+ });
162
+ const act = (t, k) => (t.handoffs[WEEKS - 1 - k] ?? 0) > 0;
163
+ const kept = (from, to) => { const base = teams.filter((t) => act(t, from)); return { base: base.length, kept: base.filter((t) => act(t, to)).length }; };
164
+ const wowSeries = [];
165
+ for (let k = 7; k >= 1; k--) {
166
+ const r = kept(k, k - 1);
167
+ wowSeries.push(r.base ? Math.round((r.kept / r.base) * 100) : null);
168
+ }
169
+ const quiet = teams.filter((t) => !act(t, 0) && [1, 2, 3, 4].some((k) => act(t, k)))
170
+ .map((t) => ({ name: t.name, lastActiveAt: t.lastActiveAt, handoffs4w: [1, 2, 3, 4].reduce((n, k) => n + (t.handoffs[WEEKS - 1 - k] ?? 0), 0) }))
171
+ .sort((a, b) => (b.lastActiveAt ?? 0) - (a.lastActiveAt ?? 0) || a.name.localeCompare(b.name));
172
+ const planTeams = {}, planPeople = {};
173
+ for (const t of teams) {
174
+ const p = input.teamPlans.get(t.name) ?? "none";
175
+ planTeams[p] = (planTeams[p] ?? 0) + 1;
176
+ }
177
+ for (const a of input.accounts)
178
+ planPeople[a.plan] = (planPeople[a.plan] ?? 0) + 1;
179
+ return {
180
+ now,
181
+ usage: { activeTeams: { weeks: activeTeams, partial: usagePartial }, activePeople: { weeks: activePeople, partial: usagePartial }, handoffs: { weeks: handoffs, partial: usagePartial } },
182
+ value: {
183
+ asks: pair((t, k) => t.value[k].asks), answered: pair((t, k) => t.value[k].answered),
184
+ byWorker: pair((t, k) => t.value[k].byWorker), byPerson: pair((t, k) => t.value[k].byPerson),
185
+ medianAnswerMs: meds((t, k) => t.value[k].answerMs),
186
+ decisions: pair((t, k) => t.value[k].decisions), decided: pair((t, k) => t.value[k].decided), medianDecisionMs: meds((t, k) => t.value[k].decisionMs),
187
+ delivered: pair((t, k) => t.value[k].delivered),
188
+ partial: [teams.some((t) => t.value[0].partial), teams.some((t) => t.value[1].partial)],
189
+ },
190
+ growth: {
191
+ newTeams: { weeks: newTeams, partial: false }, newPeople: { weeks: newPeople, partial: false },
192
+ activation: {
193
+ cohort: cohort.length, matured: matured.length, activated: matured.filter(within7).length,
194
+ young: young.length, youngActivated: young.filter((t) => t.firstHandoffAt !== null).length,
195
+ medianToFirstMs: median(cohort.filter((t) => t.firstHandoffAt !== null).map((t) => Math.max(0, t.firstHandoffAt - t.createdAt))),
196
+ },
197
+ funnel: { all: funnel(input.accounts), last30: funnel(input.accounts.filter((a) => a.created_at >= now - 30 * DAY_MS)) },
198
+ },
199
+ retention: { wow: kept(1, 0), fourWeek: kept(3, 0), wowSeries, quiet },
200
+ plans: { teams: planTeams, people: planPeople },
201
+ };
202
+ }
203
+ //# sourceMappingURL=founder-stats.js.map
@@ -0,0 +1,218 @@
1
+ import { SEAL, cap, esc, hhmm, plural, when } from "./admin-ui.js";
2
+ import { dur, flowIndex, utcDay } from "./flow-stats.js";
3
+ export const GOAL_NODE_CAP = 200;
4
+ export const GAP_MS = 45 * 60_000;
5
+ const VERB = {
6
+ ASK: "asked", ANSWER: "answered", PROPOSE: "proposed", ACCEPT: "agreed", OBJECT: "objected", CONTRACT: "agreed a contract",
7
+ COMMIT: "committed", DELIVERED: "delivered", ESCALATE: "escalated", HUMAN_REQUIRED: "needs a person", CLOSE: "closed",
8
+ NOTE: "noted", RETRACT: "retracted", WITHDRAW: "asked to be released", JOIN: "arrived", LEAVE: "left",
9
+ };
10
+ export const verbOf = (n) => (n.decision ? "decided" : VERB[n.act] ?? n.act.toLowerCase().replace(/_/g, " "));
11
+ export const didOf = (n) => {
12
+ const to = n.to?.length ? n.to.map(cap).join(", ") : "";
13
+ if (n.act === "HUMAN_REQUIRED" && to)
14
+ return `needs ${to} to decide`;
15
+ if (n.act === "ASK" && to)
16
+ return `asked ${to}`;
17
+ return verbOf(n);
18
+ };
19
+ export const GOAL_OWED_CAP = 50;
20
+ const OWES = { ANSWER: "an answer", ACCEPT: "a reply to a proposal", REVISE: "a revision", HUMAN: "a decision", DELIVER: "a delivery" };
21
+ export function goalFlowOf(input) {
22
+ const { goal, now } = input;
23
+ const own = input.records.filter((r) => r.goal === goal.id).sort((a, b) => a.ts - b.ts || a.seq - b.seq);
24
+ const ix = flowIndex(own);
25
+ const recs = ix.recs;
26
+ const all = recs.map((r) => {
27
+ const parent = r.ref ? ix.byId.get(r.ref) : undefined;
28
+ const decider = parent && (parent.act === "ESCALATE" ? parent.from : parent.act === "HUMAN_REQUIRED" ? parent.to?.[0] : undefined);
29
+ return { id: r.id, seq: r.seq, ts: r.ts, from: r.from, to: r.to, act: r.act, by: r.by, decision: r.act === "ANSWER" && !!decider && r.from === decider, ref: parent ? parent.id : null };
30
+ });
31
+ const earlier = Math.max(0, all.length - GOAL_NODE_CAP);
32
+ const nodes = all.slice(earlier).map((n) => ({ ...n }));
33
+ const drawn = new Set(nodes.map((n) => n.id));
34
+ for (const n of nodes)
35
+ if (n.ref && !drawn.has(n.ref))
36
+ n.ref = null;
37
+ const byId = new Map(all.map((n) => [n.id, n]));
38
+ const open = input.obligations.filter((o) => o.goal === goal.id && o.kind !== "CONTINUE")
39
+ .map((o) => ({ owner: o.owner, kind: o.kind, human: o.human, ref: o.ref, since: o.created_at, ageMs: Math.max(0, now - o.created_at), from: byId.get(o.ref)?.from ?? null }))
40
+ .sort((a, b) => a.since - b.since);
41
+ const lanes = [];
42
+ const lane = (m) => { if (m && !lanes.includes(m))
43
+ lanes.push(m); };
44
+ for (const n of nodes) {
45
+ lane(n.from);
46
+ for (const t of n.to ?? [])
47
+ if (n.act === "ASK" || n.act === "HUMAN_REQUIRED")
48
+ lane(t);
49
+ }
50
+ for (const w of open)
51
+ lane(w.owner);
52
+ let longest = null;
53
+ const consider = (ms, who, what, isOpen) => { if (!longest || ms > longest.ms)
54
+ longest = { ms, who, what, open: isOpen }; };
55
+ const replies = new Map();
56
+ for (const r of all)
57
+ if (r.ref) {
58
+ const l = replies.get(r.ref);
59
+ if (l)
60
+ l.push(r);
61
+ else
62
+ replies.set(r.ref, [r]);
63
+ }
64
+ for (const n of all) {
65
+ if (n.act !== "ASK" && n.act !== "ESCALATE" && n.act !== "HUMAN_REQUIRED")
66
+ continue;
67
+ const reply = (replies.get(n.id) ?? []).find((r) => (n.act === "ASK" ? (n.to ?? []).includes(r.from) && (r.act === "ANSWER" || r.act === "DELIVERED") : r.decision));
68
+ if (reply)
69
+ consider(reply.ts - n.ts, reply.from, n.act === "ASK" ? "an answer" : "a decision", false);
70
+ }
71
+ for (const w of open)
72
+ consider(w.ageMs, w.owner, OWES[w.kind] ?? "a reply", true);
73
+ const closedAt = goal.state === "CLOSED" ? (all.filter((n) => n.act === "CLOSE").pop()?.ts ?? null) : null;
74
+ const blocking = open.find((w) => w.human) ?? open[0] ?? null;
75
+ return {
76
+ goal: { id: goal.id, title: goal.title, state: goal.state, openedAt: goal.opened_at, closedAt, worklist: goal.worklist },
77
+ now, lanes, nodes, earlier, open,
78
+ summary: { acts: all.length, handoffs: all.filter((n) => n.act === "ASK").length, people: [...lanes], startedAt: Math.min(goal.opened_at, all[0]?.ts ?? goal.opened_at), endedAt: closedAt, longest, blocking },
79
+ };
80
+ }
81
+ const STATE_WORDS = { OPEN: "Open", CLOSED: "Closed", BLOCKED: "Blocked on a decision", STALLED: "Out of acts" };
82
+ const whoOf = (n) => `${cap(n.from)}'s ${n.decision ? "decision" : n.by === "worker" ? "worker" : "agent"}`;
83
+ export function goalSummary(f) {
84
+ const s = f.summary;
85
+ const end = s.endedAt ?? f.now;
86
+ const L = s.longest;
87
+ const b = s.blocking;
88
+ return `<p class="gsum"><b>${esc(STATE_WORDS[f.goal.state] ?? f.goal.state)}</b> · started ${when(s.startedAt, "full")} · ${dur(end - s.startedAt)}${s.endedAt ? "" : " so far"} · ${s.people.length ? esc(s.people.map(cap).join(", ")) : "nobody yet"} · ${plural(s.handoffs, "hand-off")}${L ? ` · longest wait ${dur(L.ms)} (${esc(cap(L.who))}, ${esc(L.what)}${L.open ? ", still open" : ""})` : ""}${b ? ` · <span class="${b.human ? "badtext" : ""}">blocking now: ${b.human ? `${SEAL} ` : ""}${esc(cap(b.owner))}${b.human ? "'s decision" : ` owes ${esc(OWES[b.kind] ?? "a reply")}`}, ${dur(b.ageMs)}</span>` : f.goal.state === "CLOSED" ? "" : " · nothing owed"}</p>`;
89
+ }
90
+ export function goalDiagram(f, o = {}) {
91
+ const COL = 104, GAP = 92, LEFT = 132, TOP = 46, LANE = 84, NOWPAD = 220;
92
+ const xs = [];
93
+ const gaps = [];
94
+ let x = LEFT + COL / 2;
95
+ f.nodes.forEach((n, i) => {
96
+ if (i > 0) {
97
+ const ms = n.ts - f.nodes[i - 1].ts;
98
+ const px = x;
99
+ x += COL + (ms > GAP_MS ? GAP : 0);
100
+ if (ms > GAP_MS)
101
+ gaps.push({ x: (px + x) / 2, ms });
102
+ }
103
+ xs.push(x);
104
+ });
105
+ const lastX = xs.length ? xs[xs.length - 1] : LEFT;
106
+ const idleToNow = f.goal.state !== "CLOSED" && f.nodes.length ? f.now - f.nodes[f.nodes.length - 1].ts : 0;
107
+ const nowX = lastX + (idleToNow > GAP_MS ? GAP : 0) + COL;
108
+ const width = Math.max(560, (f.goal.state === "CLOSED" ? lastX + COL : nowX + NOWPAD));
109
+ const laneY = (m) => TOP + Math.max(0, f.lanes.indexOf(m)) * LANE + LANE / 2;
110
+ const height = TOP + Math.max(1, f.lanes.length) * LANE + 18;
111
+ const at = new Map(f.nodes.map((n, i) => [n.id, { x: xs[i], y: laneY(n.from), n }]));
112
+ let svg = "";
113
+ f.lanes.forEach((m, i) => {
114
+ const y = TOP + i * LANE;
115
+ svg += `<rect class="lane${i % 2 ? " alt" : ""}" x="0" y="${y}" width="${width}" height="${LANE}"/><text class="lname" x="14" y="${y + LANE / 2 + 5}">${esc(cap(m))}</text>`;
116
+ });
117
+ let lastDay = "";
118
+ f.nodes.forEach((n, i) => { const d = utcDay(n.ts); if (d !== lastDay) {
119
+ lastDay = d;
120
+ svg += `<text class="gday" x="${xs[i]}" y="22" text-anchor="middle" data-t="${n.ts}" data-f="date">${esc(new Date(n.ts).toUTCString().slice(0, 11))}</text>`;
121
+ } });
122
+ for (const g of gaps)
123
+ svg += `<g class="gap"><line x1="${g.x}" x2="${g.x}" y1="${TOP - 6}" y2="${height - 18}"/><text x="${g.x}" y="38" text-anchor="middle">waited ${esc(dur(g.ms))}</text></g>`;
124
+ const owedShown = [...f.open].sort((a, b) => (b.human ? 1 : 0) - (a.human ? 1 : 0) || a.since - b.since).slice(0, GOAL_OWED_CAP);
125
+ for (const w of owedShown) {
126
+ const src = at.get(w.ref);
127
+ const y = laneY(w.owner) - 24;
128
+ const x1 = src ? src.x : LEFT;
129
+ svg += `<g class="owed${w.human ? " human" : ""}"><line x1="${x1}" x2="${nowX}" y1="${y}" y2="${y}"/><circle cx="${nowX}" cy="${y}" r="5"/><text x="${nowX + 10}" y="${y + 4}">${esc(cap(w.owner))} ${w.human ? "decides" : `owes ${OWES[w.kind] ?? "a reply"}`} · ${esc(dur(w.ageMs))}</text></g>`;
130
+ }
131
+ for (const n of f.nodes) {
132
+ if (!n.ref)
133
+ continue;
134
+ const a = at.get(n.ref), b = at.get(n.id);
135
+ if (!a || !b)
136
+ continue;
137
+ const same = a.y === b.y;
138
+ const midX = (a.x + b.x) / 2;
139
+ const d = same ? `M${a.x + 10},${a.y - 8} Q${midX},${a.y - 40} ${b.x - 10},${b.y - 8}` : `M${a.x + 12},${a.y} C${midX},${a.y} ${midX},${b.y} ${b.x - 14},${b.y}`;
140
+ const ly = same ? a.y - 30 : (a.y + b.y) / 2;
141
+ svg += `<g class="arrow"><path d="${d}" marker-end="url(#gf-head)"/><text x="${midX}" y="${ly + 4}" text-anchor="middle">${esc(dur(b.n.ts - a.n.ts))}</text></g>`;
142
+ }
143
+ let ord = 0;
144
+ for (const [, p] of at) {
145
+ const n = p.n;
146
+ ord++;
147
+ const verb = verbOf(n);
148
+ const words = `${whoOf(n)} ${didOf(n)}`;
149
+ const tip = [`${words}`, ...(o.gist ? [o.gist(n.id) || "(empty message)"] : []), new Date(n.ts).toUTCString().slice(0, 22) + " UTC"].join("|");
150
+ const shape = n.decision || n.act === "ESCALATE" || n.act === "HUMAN_REQUIRED"
151
+ ? `<path class="mk ${n.decision ? "dec" : "esc"}" d="M${p.x},${p.y - 11} L${p.x + 11},${p.y} L${p.x},${p.y + 11} L${p.x - 11},${p.y} Z"/>`
152
+ : n.by === "worker" ? `<rect class="mk w" x="${p.x - 9}" y="${p.y - 9}" width="18" height="18" rx="3"/>` : `<circle class="mk p" cx="${p.x}" cy="${p.y}" r="9"/>`;
153
+ svg += `<g class="gn" tabindex="0" data-tip="${esc(tip)}" aria-label="${esc(`${words}, ${new Date(n.ts).toUTCString().slice(0, 22)} UTC`)}"${o.readHref ? ` data-node="${ord}"` : ""}>${shape}<text class="gv" x="${p.x}" y="${p.y + 27}" text-anchor="middle">${esc(verb)}</text><text class="gt" x="${p.x}" y="${p.y + 41}" text-anchor="middle" data-t="${n.ts}" data-f="hm">${esc(hhmm(n.ts))}</text></g>`;
154
+ }
155
+ if (f.goal.state !== "CLOSED")
156
+ svg += `<g class="now"><line x1="${nowX}" x2="${nowX}" y1="${TOP - 6}" y2="${height - 18}"/><text x="${nowX + 6}" y="38">now${idleToNow > GAP_MS ? `, ${esc(dur(idleToNow))} after the last act` : ""}</text></g>`;
157
+ const label = `How "${f.goal.title}" moved: ${plural(f.summary.acts, "act")} across ${plural(f.lanes.length, "lane")}. The same steps are listed below.`;
158
+ const steps = goalSteps(f, o);
159
+ return `<div class="gflow">
160
+ ${f.earlier ? `<p class="note">${plural(f.earlier, "earlier act")} not drawn: the newest ${f.nodes.length} are. The list below has the drawn ones.</p>` : ""}
161
+ ${f.open.length > GOAL_OWED_CAP ? `<p class="note">${f.open.length} items are still owed; the ${GOAL_OWED_CAP} shown are the decisions first, then the oldest. And ${f.open.length - GOAL_OWED_CAP} more still owed.</p>` : ""}
162
+ <div class="glegend" aria-hidden="true"><span><i class="lg p"></i>their agent window</span><span><i class="lg w"></i>their worker (unattended)</span><span><i class="lg dec"></i>a person's decision</span><span><i class="lg esc"></i>escalated, needs a person</span><span><i class="lg owed"></i>still owed, to now</span><span><i class="lg gapk"></i>idle time squeezed out</span></div>
163
+ <div class="gscroll"><svg class="gsvg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" aria-label="${esc(label)}"><defs><marker id="gf-head" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0,0 L10,5 L0,10 z" class="ahead"/></marker></defs>${svg}</svg></div>
164
+ <details class="tv glist"${o.readHref ? " open" : ""}><summary>Show as a list</summary>${steps}</details>
165
+ </div>`;
166
+ }
167
+ export function goalSteps(f, o = {}) {
168
+ const byId = new Map(f.nodes.map((n) => [n.id, n]));
169
+ const items = f.nodes.map((n, i) => {
170
+ const prev = i ? f.nodes[i - 1] : null;
171
+ const gap = prev && n.ts - prev.ts > GAP_MS ? `<span class="gapnote">then ${esc(dur(n.ts - prev.ts))} went by</span>` : "";
172
+ const ref = n.ref ? byId.get(n.ref) : undefined;
173
+ const reply = ref ? `, ${esc(dur(n.ts - ref.ts))} after ${esc(cap(ref.from))} ${esc(verbOf(ref))}` : "";
174
+ const g = o.gist ? o.gist(n.id) : "";
175
+ return `<li id="gs-${i + 1}">${gap}<span class="when">${when(n.ts, "full")}</span> <b>${esc(whoOf(n))}</b> ${esc(didOf(n))}${reply}.${g ? `<span class="sub text wrapc">${esc(g)}</span>` : ""}${o.readHref ? ` <a class="more" href="${esc(o.readHref(n.id))}" data-read="${esc(n.id)}" data-seq="${n.seq}">Read in full</a>` : ""}</li>`;
176
+ }).join("");
177
+ const owedList = [...f.open].sort((a, b) => (b.human ? 1 : 0) - (a.human ? 1 : 0) || a.since - b.since);
178
+ const owed = owedList.slice(0, GOAL_OWED_CAP).map((w) => `<li class="owedi">${w.human ? `${SEAL} ` : ""}<b>${esc(cap(w.owner))}</b> ${w.human ? "has a decision to make" : `owes ${esc(OWES[w.kind] ?? "a reply")}`}${w.from && w.from !== w.owner ? ` to ${esc(cap(w.from))}` : ""}: waiting ${esc(dur(w.ageMs))}, since ${when(w.since, "full")}.</li>`).join("");
179
+ return `<ol class="gsteps"${o.readHref && o.read ? ` id="t-goalsteps" data-space="${esc(o.read.space)}" data-csrf="${esc(o.read.csrf)}"` : ""}>${items || `<li>No act in this goal yet.</li>`}</ol>${owed ? `<h3 class="gh3">Still owed</h3><ul class="gsteps">${owed}${owedList.length > GOAL_OWED_CAP ? `<li>And ${owedList.length - GOAL_OWED_CAP} more still owed.</li>` : ""}</ul>` : ""}`;
180
+ }
181
+ export const GOAL_CSS = `
182
+ .gsum{font-size:15px;margin:6px 0 14px;line-height:1.6}
183
+ .gflow .glegend{display:flex;flex-wrap:wrap;gap:6px 18px;font-size:13.5px;color:var(--muted);margin:0 0 10px}
184
+ .gflow .lg{display:inline-block;width:12px;height:12px;margin-right:6px;vertical-align:-1px}
185
+ .lg.p{border-radius:50%;background:var(--person)}.lg.w{border-radius:2px;background:var(--worker)}
186
+ .lg.dec,.lg.esc{transform:rotate(45deg) scale(.85);background:var(--text)}.lg.esc{background:var(--accent)}
187
+ .lg.owed{width:22px;height:0;border-top:2px dashed var(--accent-text);vertical-align:3px}
188
+ .lg.gapk{width:2px;height:14px;border-left:2px dotted var(--muted);margin-left:5px}
189
+ .gscroll{display:inline-block;max-width:100%;vertical-align:top;overflow-x:auto;border:1px solid var(--line);border-radius:10px;background:var(--surface)}
190
+ .gsvg{display:block;font-family:var(--ui)}
191
+ .gsvg .lane{fill:var(--surface)}.gsvg .lane.alt{fill:var(--zebra)}
192
+ .gsvg .lname{font:600 15px var(--ui);fill:var(--text)}
193
+ .gsvg .gday{font:600 13px var(--ui);fill:var(--muted)}
194
+ .gsvg .gap line{stroke:var(--muted);stroke-width:2;stroke-dasharray:2 5}
195
+ .gsvg .gap text,.gsvg .now text{font:500 12.5px var(--ui);fill:var(--muted)}
196
+ .gsvg .now line{stroke:var(--text);stroke-width:1.5;stroke-dasharray:6 4}
197
+ .gsvg .mk.p{fill:var(--person);stroke:var(--text);stroke-width:1.5}
198
+ .gsvg .mk.w{fill:var(--worker);stroke:var(--text);stroke-width:1.5}
199
+ .gsvg .mk.dec{fill:var(--text);stroke:var(--text)}
200
+ .gsvg .mk.esc{fill:var(--accent);stroke:var(--text);stroke-width:1.5}
201
+ .gsvg .gv{font:600 13px var(--ui);fill:var(--text)}
202
+ .gsvg .gt{font:500 12px var(--ui-mono);fill:var(--muted)}
203
+ .gsvg .arrow path{fill:none;stroke:var(--muted);stroke-width:1.6}
204
+ .gsvg .ahead{fill:var(--muted)}
205
+ .gsvg .arrow text{font:600 12px var(--ui);fill:var(--text);paint-order:stroke;stroke:var(--surface);stroke-width:4px;stroke-linejoin:round}
206
+ .gsvg .owed line{stroke:var(--accent-text);stroke-width:2;stroke-dasharray:7 5}
207
+ .gsvg .owed circle{fill:var(--surface);stroke:var(--accent-text);stroke-width:2}
208
+ .gsvg .owed text{font:600 13px var(--ui);fill:var(--accent-text)}
209
+ .gsvg .gn{cursor:default}.gsvg .gn:focus{outline:none}.gsvg .gn:focus-visible .mk{stroke:var(--focus);stroke-width:4}
210
+ .gsvg [data-node]{cursor:pointer}
211
+ .gsteps{margin:10px 0 0;padding-left:22px;display:grid;gap:8px;font-size:15px}
212
+ .gsteps li{line-height:1.5}
213
+ .gsteps .when{color:var(--muted);font-size:13.5px}
214
+ .gsteps .gapnote{display:block;color:var(--muted);font-size:13.5px;font-style:italic}
215
+ .gsteps .detail-in{margin-top:6px}
216
+ .gh3{margin:14px 0 0}
217
+ `;
218
+ //# sourceMappingURL=goal-flow.js.map
@@ -30,6 +30,7 @@ export const PANTHEON_HOME_ENTRIES = [
30
30
  { name: /^held-deliveries\.json\.corrupt-\d+$/, sample: "held-deliveries.json.corrupt-1760000000000", what: "a record of held deliveries that could not be read, set aside" },
31
31
  { name: "run-slot.json", what: "the worker's run slot" },
32
32
  { name: "worker.pid", what: "the worker's pid file" },
33
+ { name: "notifier.pid", what: "the alerts' pid file" },
33
34
  { name: /^notifier-state(-.+)?\.json$/, sample: "notifier-state-team%2Fone.json", what: "the alerts' state" },
34
35
  { name: "update-check.json", what: "the update check's cache" },
35
36
  { name: "uri-key", what: "the key pantheon:// links are signed with" },
@@ -42,6 +43,7 @@ export const PANTHEON_HOME_ENTRIES = [
42
43
  { name: "logs", what: "the service logs", dir: true },
43
44
  { name: "handoff", what: "long questions handed to the Claude app outside any team folder (open-in.ts)", dir: true },
44
45
  { name: "host", what: "the Windows host's queue, state and markers", dir: true },
46
+ { name: "status", what: "the menu bar's change mark", dir: true },
45
47
  { name: "mcp", what: "the agent windows' server state", dir: true },
46
48
  { name: "run-homes", what: "the woken runs' homes", dir: true },
47
49
  { name: "worktrees", what: "the worker's worktrees", dir: true },
package/dist/machine.js CHANGED
@@ -196,6 +196,98 @@ const PGREP_PATTERN = {
196
196
  relay: "[p]antheon.* relay",
197
197
  };
198
198
  export const workerPidFile = (home = CONFIG_DIR) => join(home, "worker.pid");
199
+ export const notifierPidFile = (home = CONFIG_DIR) => join(home, "notifier.pid");
200
+ export function runningProbe(o = {}) {
201
+ const now = o.now ?? Date.now;
202
+ const alive = o.alive ?? aliveOurs;
203
+ const full = o.full ?? ((k) => (k === "worker" ? workerProc() : notifierProc()));
204
+ const every = o.fullEveryMs ?? 60_000;
205
+ const reprove = o.reproveEveryMs ?? 10 * 60_000;
206
+ const scanIo = o.scanIo ?? realProcScanIo;
207
+ const unproved = {};
208
+ const filedPid = (file) => { try {
209
+ const n = Number(JSON.parse(readFileSync(file, "utf8"))?.pid);
210
+ return Number.isInteger(n) ? n : null;
211
+ }
212
+ catch {
213
+ return null;
214
+ } };
215
+ const proved = o.proved ?? ((k) => {
216
+ const pidFile = k === "worker" ? workerPidFile(o.home) : notifierPidFile(o.home);
217
+ const u = unproved[k];
218
+ if (u && now() - u.at < every && filedPid(pidFile) === u.pid && alive(u.pid))
219
+ return null;
220
+ const r = pidFileProc(k, { ...scanIo(), alive, pidFile });
221
+ if (r && !r.confirmed)
222
+ unproved[k] = { pid: r.pid, at: now() };
223
+ else
224
+ delete unproved[k];
225
+ return r?.confirmed ? r.pid : null;
226
+ });
227
+ const still = o.still ?? ((k, pid) => {
228
+ const cmd = scanIo().cmdlineOf(pid);
229
+ return cmd !== null && isPantheonKindCommand(k, cmd);
230
+ });
231
+ const last = {};
232
+ return (kind) => {
233
+ const st = (last[kind] ??= { at: -Infinity, provedAt: -Infinity });
234
+ if (st.pid && alive(st.pid)) {
235
+ if (now() - st.provedAt < reprove)
236
+ return true;
237
+ if (still(kind, st.pid)) {
238
+ st.provedAt = now();
239
+ return true;
240
+ }
241
+ }
242
+ delete st.pid;
243
+ const filed = proved(kind);
244
+ if (filed && alive(filed)) {
245
+ st.pid = filed;
246
+ st.provedAt = now();
247
+ return true;
248
+ }
249
+ if (now() - st.at < every)
250
+ return !!st.pidless;
251
+ st.at = now();
252
+ const p = full(kind);
253
+ if (p.running && p.pid && alive(p.pid)) {
254
+ st.pid = p.pid;
255
+ st.provedAt = now();
256
+ }
257
+ st.pidless = p.running && !p.pid;
258
+ return p.running;
259
+ };
260
+ }
261
+ const roleCache = new Map();
262
+ export function isPantheonRole(pid, role) {
263
+ const key = `${pid}:${role}`;
264
+ const c = roleCache.get(key);
265
+ if (c && Date.now() - c.at < 10 * 60_000)
266
+ return c.ok;
267
+ let ok = false;
268
+ try {
269
+ const cmd = realProcScanIo().cmdlineOf(pid);
270
+ ok = cmd !== null && (role === "mcp" ? /pantheon|cli\.js/i.test(cmd) && /\bmcp\b/.test(cmd) : isPantheonKindCommand(role, cmd));
271
+ }
272
+ catch {
273
+ ok = false;
274
+ }
275
+ if (roleCache.size > 200)
276
+ roleCache.clear();
277
+ roleCache.set(key, { at: Date.now(), ok });
278
+ return ok;
279
+ }
280
+ const aliveOurs = (pid) => {
281
+ if (!Number.isInteger(pid) || pid <= 1)
282
+ return false;
283
+ try {
284
+ process.kill(pid, 0);
285
+ return true;
286
+ }
287
+ catch {
288
+ return false;
289
+ }
290
+ };
199
291
  const aliveReal = (pid) => {
200
292
  try {
201
293
  process.kill(pid, 0);
@@ -304,7 +396,8 @@ export function readProcTable(procDir) {
304
396
  }
305
397
  export const isPantheonKindCommand = (kind, cmd) => BARE_PATTERN[kind].test(cmd) || (/pantheon|cli\.js/i.test(cmd) && new RegExp(`\\b${kind}\\b`).test(cmd));
306
398
  const START_SLACK_MS = 10_000;
307
- function pidFileWorker(io) {
399
+ function pidFileWorker(io) { return pidFileProc("worker", io); }
400
+ export function pidFileProc(kind, io) {
308
401
  let rec = null;
309
402
  try {
310
403
  rec = JSON.parse(readFileSync(io.pidFile, "utf8"));
@@ -322,7 +415,7 @@ function pidFileWorker(io) {
322
415
  if (!io.alive(pid))
323
416
  return stale();
324
417
  const cmd = io.cmdlineOf(pid);
325
- if (cmd !== null && !isPantheonKindCommand("worker", cmd))
418
+ if (cmd !== null && !isPantheonKindCommand(kind, cmd))
326
419
  return stale();
327
420
  const born = io.startedAt?.(pid) ?? null;
328
421
  if (born !== null) {
package/dist/mcp.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { agentLabelFor, clientState, ConnectionReport } from "./conn-report.js";
1
2
  import { randomBytes } from "node:crypto";
2
3
  import { existsSync, rmSync } from "node:fs";
3
4
  import { join } from "node:path";
@@ -127,6 +128,11 @@ export async function runMcp() {
127
128
  });
128
129
  const branch = process.env.PANTHEON_BRANCH;
129
130
  const client = new PantheonClient(cfg, undefined, { role });
131
+ {
132
+ const report = new ConnectionReport({ role: "mcp", space: cfg.space, agent: agentLabelFor(process.env.PANTHEON_AGENT ?? cfg.agent), folder: process.cwd() });
133
+ report.observe("down");
134
+ client.onChange = () => report.observe(clientState(client));
135
+ }
130
136
  let siblingsWarned = false;
131
137
  let rubricShown = false;
132
138
  const server = new McpServer({ name: "pantheon", version: VERSION }, { instructions: sessionInstructions(cfg, role, branch) });