@join-pantheon/cli 0.33.11 → 0.34.0
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/accounts.js +229 -8
- package/dist/admin-pages.js +674 -0
- package/dist/admin-stats.js +11 -5
- package/dist/admin-ui.js +416 -0
- package/dist/board.js +17 -2
- package/dist/byte-lru.js +52 -0
- package/dist/cli.js +180 -37
- package/dist/desktop-app.js +2 -2
- package/dist/flow-stats.js +501 -0
- package/dist/home-guard.js +27 -2
- package/dist/home-safety.js +1 -0
- package/dist/ledger.js +10 -4
- package/dist/leftovers.js +178 -0
- package/dist/notice.js +1 -0
- package/dist/notifier.js +15 -3
- package/dist/open-in.js +349 -0
- package/dist/relay.js +1429 -617
- package/dist/roster-file.js +0 -6
- package/dist/store.js +36 -1
- package/dist/tray.js +16 -1
- package/dist/uri-handler.js +1 -1
- package/dist/viewer-pages.js +190 -0
- package/helper/macos/main.swift +25 -5
- package/helper/macos/menubar.swift +56 -1
- 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/helper/windows/pantheon-tray.ps1 +26 -1
- package/package.json +1 -1
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import { relayComposed } from "./verify-act.js";
|
|
2
|
+
export const DAY_MS = 86_400_000;
|
|
3
|
+
export function toFlowRecords(records) {
|
|
4
|
+
const out = [];
|
|
5
|
+
for (const r of records) {
|
|
6
|
+
if (relayComposed(r))
|
|
7
|
+
continue;
|
|
8
|
+
out.push({
|
|
9
|
+
id: String(r.id), seq: Number(r.seq), ts: Number(r.ts), from: String(r.from),
|
|
10
|
+
to: Array.isArray(r.to) ? r.to.map(String) : null,
|
|
11
|
+
act: r.act, goal: r.goal ?? null, ref: r.ref ?? null,
|
|
12
|
+
by: r.role === "worker" ? "worker" : "person",
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
export function toFlowObligations(obligations, firstClaims = new Map(), claimLive = () => true) {
|
|
18
|
+
const out = [];
|
|
19
|
+
for (const o of obligations) {
|
|
20
|
+
if (o.kind === "CONTINUE")
|
|
21
|
+
continue;
|
|
22
|
+
const human = o.kind === "HUMAN";
|
|
23
|
+
const live = !!o.claimed_by && claimLive(o);
|
|
24
|
+
out.push({
|
|
25
|
+
id: o.id, kind: o.kind, owner: human ? o.owner.replace(/^human:/, "") : o.owner, human,
|
|
26
|
+
ref: o.ref, goal: o.goal ?? null, created_at: o.created_at,
|
|
27
|
+
claimed: live ? { by: o.claimed_by.role === "worker" ? "worker" : "person", at: o.claimed_by.at } : null,
|
|
28
|
+
first_claimed_at: firstClaims.get(o.id)?.at ?? null,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
export function toFlowGoals(goals) {
|
|
34
|
+
const out = [];
|
|
35
|
+
for (const g of goals) {
|
|
36
|
+
out.push({ id: g.id, title: String(g.title ?? ""), state: g.state, deadline: g.deadline ?? null, worklist: g.kind === "worklist", acts: g.acts, budget: g.budget, opened_at: g.opened_at });
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
export function flowIndex(records) {
|
|
41
|
+
const retracted = new Set();
|
|
42
|
+
for (const r of records)
|
|
43
|
+
if (r.act === "RETRACT" && r.ref)
|
|
44
|
+
retracted.add(r.ref);
|
|
45
|
+
const idx = { retracted, recs: [], allKids: new Map(), byId: new Map(), kids: new Map() };
|
|
46
|
+
for (const r of records)
|
|
47
|
+
addToIndex(idx, r);
|
|
48
|
+
return idx;
|
|
49
|
+
}
|
|
50
|
+
export async function flowIndexAsync(records, slice = 20_000) {
|
|
51
|
+
const retracted = new Set();
|
|
52
|
+
for (const r of records)
|
|
53
|
+
if (r.act === "RETRACT" && r.ref)
|
|
54
|
+
retracted.add(r.ref);
|
|
55
|
+
const idx = { retracted, recs: [], allKids: new Map(), byId: new Map(), kids: new Map() };
|
|
56
|
+
for (let i = 0; i < records.length; i++) {
|
|
57
|
+
addToIndex(idx, records[i]);
|
|
58
|
+
if (i % slice === slice - 1)
|
|
59
|
+
await new Promise((x) => setImmediate(x));
|
|
60
|
+
}
|
|
61
|
+
return idx;
|
|
62
|
+
}
|
|
63
|
+
function addToIndex(idx, r) {
|
|
64
|
+
if (r.ref) {
|
|
65
|
+
const k = idx.allKids.get(r.ref);
|
|
66
|
+
if (k)
|
|
67
|
+
k.push(r);
|
|
68
|
+
else
|
|
69
|
+
idx.allKids.set(r.ref, [r]);
|
|
70
|
+
}
|
|
71
|
+
if (idx.retracted.has(r.id))
|
|
72
|
+
return;
|
|
73
|
+
idx.recs.push(r);
|
|
74
|
+
idx.byId.set(r.id, r);
|
|
75
|
+
if (r.ref) {
|
|
76
|
+
const k = idx.kids.get(r.ref);
|
|
77
|
+
if (k)
|
|
78
|
+
k.push(r);
|
|
79
|
+
else
|
|
80
|
+
idx.kids.set(r.ref, [r]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export const median = (xs) => {
|
|
84
|
+
if (!xs.length)
|
|
85
|
+
return null;
|
|
86
|
+
const s = [...xs].sort((a, b) => a - b);
|
|
87
|
+
const m = Math.floor(s.length / 2);
|
|
88
|
+
return s.length % 2 ? s[m] : Math.round((s[m - 1] + s[m]) / 2);
|
|
89
|
+
};
|
|
90
|
+
export const utcDay = (ts) => new Date(ts).toISOString().slice(0, 10);
|
|
91
|
+
export const rangeStart = (now, days) => {
|
|
92
|
+
const d = new Date(now);
|
|
93
|
+
d.setUTCHours(0, 0, 0, 0);
|
|
94
|
+
return d.getTime() - (days - 1) * DAY_MS;
|
|
95
|
+
};
|
|
96
|
+
export function seriesOf(book, n, now) {
|
|
97
|
+
const out = [];
|
|
98
|
+
const start = rangeStart(now, n);
|
|
99
|
+
for (let i = 0; i < n; i++) {
|
|
100
|
+
const day = utcDay(start + i * DAY_MS);
|
|
101
|
+
const d = book?.days[day];
|
|
102
|
+
out.push({ day, worker: d?.by_worker ?? 0, person: d?.by_person ?? 0 });
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
const KIND = { ANSWER: "answer", ACCEPT: "accept", REVISE: "revise", HUMAN: "decision", DELIVER: "deliver" };
|
|
107
|
+
const BUILD = ["PROPOSE", "CONTRACT", "COMMIT", "DELIVERED"];
|
|
108
|
+
export async function flowOfAsync(input) {
|
|
109
|
+
const g = flowSteps(input);
|
|
110
|
+
for (let r = g.next();; r = g.next()) {
|
|
111
|
+
if (r.done)
|
|
112
|
+
return r.value;
|
|
113
|
+
await new Promise((x) => setImmediate(x));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function flowOf(input) {
|
|
117
|
+
const g = flowSteps(input);
|
|
118
|
+
for (let r = g.next();; r = g.next())
|
|
119
|
+
if (r.done)
|
|
120
|
+
return r.value;
|
|
121
|
+
}
|
|
122
|
+
function* flowSteps(input) {
|
|
123
|
+
const now = input.now ?? Date.now();
|
|
124
|
+
const days = Math.max(1, Math.floor(input.days));
|
|
125
|
+
const since = now - days * DAY_MS;
|
|
126
|
+
const { retracted, recs, allKids, byId, kids } = input.index ?? flowIndex(input.records);
|
|
127
|
+
const goalOf = new Map(input.goals.map((g) => [g.id, g]));
|
|
128
|
+
const claimsByRef = new Map();
|
|
129
|
+
for (const c of input.firstClaims ?? []) {
|
|
130
|
+
const l = claimsByRef.get(c.ref);
|
|
131
|
+
if (l)
|
|
132
|
+
l.push(c);
|
|
133
|
+
else
|
|
134
|
+
claimsByRef.set(c.ref, [c]);
|
|
135
|
+
}
|
|
136
|
+
const firstReplyBy = (root, who) => {
|
|
137
|
+
let best = null;
|
|
138
|
+
for (const k of kids.get(root.id) ?? [])
|
|
139
|
+
if (k.from === who && (!best || k.ts < best.ts))
|
|
140
|
+
best = k;
|
|
141
|
+
return best;
|
|
142
|
+
};
|
|
143
|
+
const answerOf = (id, who) => {
|
|
144
|
+
let best = null;
|
|
145
|
+
for (const k of kids.get(id) ?? [])
|
|
146
|
+
if (k.act === "ANSWER" && (!who || k.from === who) && (!best || k.ts < best.ts))
|
|
147
|
+
best = k;
|
|
148
|
+
return best;
|
|
149
|
+
};
|
|
150
|
+
const settleOf = (id, who) => {
|
|
151
|
+
const ask = byId.get(id);
|
|
152
|
+
const askedOf = who ? [who] : ask?.to ?? [];
|
|
153
|
+
let best = null;
|
|
154
|
+
for (const k of allKids.get(id) ?? [])
|
|
155
|
+
if ((k.act === "ANSWER" || k.act === "DELIVERED") && askedOf.includes(k.from) && (!best || k.ts < best.ts))
|
|
156
|
+
best = k;
|
|
157
|
+
return best;
|
|
158
|
+
};
|
|
159
|
+
const withdrawnOf = (id, who) => {
|
|
160
|
+
const ask = byId.get(id);
|
|
161
|
+
for (const w of kids.get(id) ?? []) {
|
|
162
|
+
if (w.act !== "WITHDRAW" || w.from !== who)
|
|
163
|
+
continue;
|
|
164
|
+
const ok = (kids.get(w.id) ?? []).find((k) => k.act === "ACCEPT" && k.from === ask?.from);
|
|
165
|
+
if (ok)
|
|
166
|
+
return ok;
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
};
|
|
170
|
+
const statusOf = (a, to) => {
|
|
171
|
+
if (settleOf(a.id, to))
|
|
172
|
+
return "answered";
|
|
173
|
+
if (withdrawnOf(a.id, to))
|
|
174
|
+
return "withdrawn";
|
|
175
|
+
if (a.goal && goalOf.get(a.goal)?.state === "CLOSED")
|
|
176
|
+
return "closed";
|
|
177
|
+
return null;
|
|
178
|
+
};
|
|
179
|
+
const asksIn = recs.filter((r) => r.act === "ASK" && r.ts >= since);
|
|
180
|
+
const answerMs = [], wMs = [], pMs = [];
|
|
181
|
+
let answered = 0, aw = 0, ap = 0;
|
|
182
|
+
const matrixN = {};
|
|
183
|
+
const carriedM = new Map();
|
|
184
|
+
const askStatus = [];
|
|
185
|
+
let tick = 0;
|
|
186
|
+
for (const a of asksIn) {
|
|
187
|
+
if (++tick % 2_000 === 0)
|
|
188
|
+
yield;
|
|
189
|
+
const tos = a.to?.length ? a.to : [];
|
|
190
|
+
for (const to of tos) {
|
|
191
|
+
(matrixN[a.from] ??= {})[to] = (matrixN[a.from][to] ?? 0) + 1;
|
|
192
|
+
const c = carriedM.get(to) ?? { asked: 0, w: 0, p: 0, ms: [] };
|
|
193
|
+
c.asked++;
|
|
194
|
+
const ans = settleOf(a.id, to);
|
|
195
|
+
if (ans) {
|
|
196
|
+
c.ms.push(ans.ts - a.ts);
|
|
197
|
+
if (ans.by === "worker")
|
|
198
|
+
c.w++;
|
|
199
|
+
else
|
|
200
|
+
c.p++;
|
|
201
|
+
}
|
|
202
|
+
carriedM.set(to, c);
|
|
203
|
+
const st = ans ? "answered" : statusOf(a, to);
|
|
204
|
+
askStatus.push({ id: a.id, to, answered: st === "answered", settled: st });
|
|
205
|
+
}
|
|
206
|
+
const ans = settleOf(a.id);
|
|
207
|
+
if (ans) {
|
|
208
|
+
answered++;
|
|
209
|
+
const ms = Math.max(0, ans.ts - a.ts);
|
|
210
|
+
answerMs.push(ms);
|
|
211
|
+
if (ans.by === "worker") {
|
|
212
|
+
aw++;
|
|
213
|
+
wMs.push(ms);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
ap++;
|
|
217
|
+
pMs.push(ms);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const open = input.obligations.map((o) => {
|
|
222
|
+
const src = byId.get(o.ref) ?? null;
|
|
223
|
+
const g = o.goal ? goalOf.get(o.goal) : undefined;
|
|
224
|
+
return {
|
|
225
|
+
id: o.id, kind: KIND[o.kind] ?? "answer", owner: o.owner, human: o.human,
|
|
226
|
+
from: src?.from ?? null, act: src?.act ?? null, ref: o.ref,
|
|
227
|
+
goal: o.goal, goalTitle: g?.title ?? null,
|
|
228
|
+
since: o.created_at, ageMs: Math.max(0, now - o.created_at), claimed: o.claimed,
|
|
229
|
+
pickupMs: o.first_claimed_at !== null ? Math.max(0, o.first_claimed_at - o.created_at) : null,
|
|
230
|
+
blocksGoal: o.human && !!g && g.state === "BLOCKED",
|
|
231
|
+
};
|
|
232
|
+
}).sort((a, b) => a.since - b.since || (byId.get(a.ref)?.seq ?? 0) - (byId.get(b.ref)?.seq ?? 0));
|
|
233
|
+
const waiting = open.filter((o) => o.human);
|
|
234
|
+
const pickupMs = [];
|
|
235
|
+
for (const c of input.firstClaims ?? []) {
|
|
236
|
+
if (c.at < since)
|
|
237
|
+
continue;
|
|
238
|
+
const r = byId.get(c.ref);
|
|
239
|
+
if (r)
|
|
240
|
+
pickupMs.push(Math.max(0, c.at - r.ts));
|
|
241
|
+
}
|
|
242
|
+
const decidedMs = [];
|
|
243
|
+
for (const r of recs) {
|
|
244
|
+
if (++tick % 20_000 === 0)
|
|
245
|
+
yield;
|
|
246
|
+
if ((r.act !== "ESCALATE" && r.act !== "HUMAN_REQUIRED"))
|
|
247
|
+
continue;
|
|
248
|
+
const decider = r.act === "ESCALATE" ? r.from : r.to?.[0];
|
|
249
|
+
const ans = decider ? answerOf(r.id, decider) : null;
|
|
250
|
+
if (ans && ans.ts >= since)
|
|
251
|
+
decidedMs.push(Math.max(0, ans.ts - r.ts));
|
|
252
|
+
}
|
|
253
|
+
const want = input.threads ?? 12;
|
|
254
|
+
const roots = [];
|
|
255
|
+
for (let i = recs.length - 1, low = Infinity; i >= 0; i--) {
|
|
256
|
+
const r = recs[i];
|
|
257
|
+
if (roots.length >= want * 4 && r.ts < low)
|
|
258
|
+
break;
|
|
259
|
+
if ((r.act === "ASK" || r.act === "ESCALATE" || r.act === "HUMAN_REQUIRED") && r.ts >= since) {
|
|
260
|
+
roots.push(r);
|
|
261
|
+
low = Math.min(low, r.ts);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
roots.sort((a, b) => b.ts - a.ts || a.seq - b.seq).splice(want);
|
|
265
|
+
const threads = roots.map((root) => threadOf(root));
|
|
266
|
+
function threadOf(root) {
|
|
267
|
+
const decision = root.act !== "ASK";
|
|
268
|
+
const to = decision ? (root.act === "ESCALATE" ? root.from : root.to?.[0] ?? root.from) : (root.to ?? []).join(", ") || "everyone";
|
|
269
|
+
const toOne = decision ? to : root.to?.[0] ?? "";
|
|
270
|
+
const askedOf = decision ? [] : root.to ?? [];
|
|
271
|
+
const seen = new Set([root.id]);
|
|
272
|
+
const desc = [];
|
|
273
|
+
const queue = [root.id];
|
|
274
|
+
while (queue.length && desc.length < 500) {
|
|
275
|
+
for (const k of kids.get(queue.shift()) ?? []) {
|
|
276
|
+
if (seen.has(k.id))
|
|
277
|
+
continue;
|
|
278
|
+
seen.add(k.id);
|
|
279
|
+
if (k.act === "ASK" || k.act === "ESCALATE" || k.act === "HUMAN_REQUIRED")
|
|
280
|
+
continue;
|
|
281
|
+
desc.push(k);
|
|
282
|
+
queue.push(k.id);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const firstOf = (act, who) => desc.filter((d) => d.act === act && (!who || d.from === who)).sort((a, b) => a.ts - b.ts)[0] ?? null;
|
|
286
|
+
const g = root.goal ? goalOf.get(root.goal) : undefined;
|
|
287
|
+
const goalClosed = g?.state === "CLOSED";
|
|
288
|
+
const openOb = input.obligations.find((o) => o.ref === root.id && (decision ? o.human : o.owner === toOne));
|
|
289
|
+
const claims = claimsByRef.get(root.id)?.filter((c) => !toOne || c.owner === toOne) ?? [];
|
|
290
|
+
const firstClaim = claims.sort((a, b) => a.at - b.at)[0] ?? null;
|
|
291
|
+
const reply = toOne ? firstReplyBy(root, toOne) : null;
|
|
292
|
+
const pickupAt = firstClaim?.at ?? reply?.ts ?? openOb?.claimed?.at ?? null;
|
|
293
|
+
let by = firstClaim?.by ?? reply?.by ?? openOb?.claimed?.by ?? null;
|
|
294
|
+
const steps = [];
|
|
295
|
+
let outcome;
|
|
296
|
+
let doneAt = null;
|
|
297
|
+
if (decision) {
|
|
298
|
+
const ans = answerOf(root.id, to);
|
|
299
|
+
steps.push({ label: root.act === "ESCALATE" ? "Escalate" : "Decision asked", at: root.ts, state: "done" });
|
|
300
|
+
steps.push({ label: "Decided", at: ans?.ts ?? null, state: ans ? "done" : "now" });
|
|
301
|
+
outcome = ans ? "decided" : "person";
|
|
302
|
+
doneAt = ans?.ts ?? null;
|
|
303
|
+
by = ans ? "person" : null;
|
|
304
|
+
}
|
|
305
|
+
else if (BUILD.some((a) => firstOf(a))) {
|
|
306
|
+
steps.push({ label: "Ask", at: root.ts, state: "done" });
|
|
307
|
+
const at = BUILD.map((a) => firstOf(a)?.ts ?? null);
|
|
308
|
+
const last = at.reduce((li, t, i) => (t !== null ? i : li), -1);
|
|
309
|
+
BUILD.forEach((a, i) => {
|
|
310
|
+
const label = a === "DELIVERED" ? "Delivered" : a[0] + a.slice(1).toLowerCase();
|
|
311
|
+
steps.push({ label, at: at[i] ?? null, state: at[i] !== null ? "done" : i === last + 1 ? "now" : "todo" });
|
|
312
|
+
});
|
|
313
|
+
const settled = settleOf(root.id);
|
|
314
|
+
outcome = settled ? (settled.act === "DELIVERED" ? "delivered" : "answered") : askedOf.some((t) => withdrawnOf(root.id, t)) ? "withdrawn" : openOb ? "working" : goalClosed ? "closed" : "working";
|
|
315
|
+
doneAt = settled?.ts ?? null;
|
|
316
|
+
if (settled)
|
|
317
|
+
by = settled.by;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
const ans = settleOf(root.id);
|
|
321
|
+
const wd = !ans && askedOf.some((t) => withdrawnOf(root.id, t));
|
|
322
|
+
steps.push({ label: "Ask", at: root.ts, state: "done" });
|
|
323
|
+
steps.push({ label: wd ? "Withdrawn" : "Answer", at: ans?.ts ?? null, state: ans || wd ? "done" : "now" });
|
|
324
|
+
const close = desc.find((d) => d.act === "CLOSE") ?? null;
|
|
325
|
+
if (ans && close)
|
|
326
|
+
steps.push({ label: "Close", at: close.ts, state: "done" });
|
|
327
|
+
outcome = ans ? "answered" : wd ? "withdrawn" : openOb?.claimed || reply ? "working" : openOb ? "waiting" : goalClosed ? "closed" : "waiting";
|
|
328
|
+
doneAt = ans?.ts ?? null;
|
|
329
|
+
if (ans)
|
|
330
|
+
by = ans.by;
|
|
331
|
+
}
|
|
332
|
+
const answeredBy = decision ? [] : askedOf.filter((t) => statusOf(root, t) === "answered");
|
|
333
|
+
const stillOwed = decision ? [] : askedOf.filter((t) => input.obligations.some((o) => o.ref === root.id && o.owner === t && o.kind === "ANSWER"));
|
|
334
|
+
const first = decision ? null : settleOf(root.id);
|
|
335
|
+
return {
|
|
336
|
+
root: root.id, kind: decision ? "decision" : "ask", from: root.from, to, goal: root.goal, goalTitle: g?.title ?? null, at: root.ts,
|
|
337
|
+
steps, outcome, by, answeredBy, stillOwed, answerRetracted: !!first && retracted.has(first.id),
|
|
338
|
+
pickupMs: !decision && pickupAt !== null ? Math.max(0, pickupAt - root.ts) : null,
|
|
339
|
+
doneMs: doneAt !== null ? Math.max(0, doneAt - root.ts) : null,
|
|
340
|
+
waitingMs: doneAt === null && (outcome === "waiting" || outcome === "person" || outcome === "working") ? Math.max(0, now - root.ts) : null,
|
|
341
|
+
goalClosed,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
const closedAt = new Map();
|
|
345
|
+
for (const r of recs)
|
|
346
|
+
if (r.act === "CLOSE" && r.goal)
|
|
347
|
+
closedAt.set(r.goal, r.ts);
|
|
348
|
+
const openIn = new Map();
|
|
349
|
+
for (const o of open)
|
|
350
|
+
if (o.goal)
|
|
351
|
+
openIn.set(o.goal, (openIn.get(o.goal) ?? 0) + 1);
|
|
352
|
+
const goals = input.goals
|
|
353
|
+
.filter((g) => g.state !== "CLOSED" || (closedAt.get(g.id) ?? 0) >= since)
|
|
354
|
+
.map((g) => {
|
|
355
|
+
const holding = waiting.filter((w) => w.goal === g.id);
|
|
356
|
+
const why = g.state === "BLOCKED" ? (holding.length ? `on ${holding.map((h) => `${cap(h.owner)}'s decision`).join(" and ")}` : "on a decision")
|
|
357
|
+
: g.state === "STALLED" ? `used its ${g.budget} acts; ${cap(holding[0]?.owner ?? "its opener")} decides whether it goes on` : null;
|
|
358
|
+
const overdue = g.deadline !== null && g.state !== "CLOSED" && g.deadline < now ? now - g.deadline : null;
|
|
359
|
+
return { id: g.id, title: g.title, state: g.state, worklist: g.worklist, why, deadline: g.deadline, overdueMs: overdue, acts: g.acts, budget: g.budget, open: openIn.get(g.id) ?? 0, closedAt: g.state === "CLOSED" ? closedAt.get(g.id) ?? null : null };
|
|
360
|
+
})
|
|
361
|
+
.sort((a, b) => (a.state === "CLOSED" ? 1 : 0) - (b.state === "CLOSED" ? 1 : 0) || stateRank(a.state) - stateRank(b.state) || b.open - a.open || a.title.localeCompare(b.title));
|
|
362
|
+
const series = input.series.slice(-days);
|
|
363
|
+
const ct = input.compactedThrough ?? null;
|
|
364
|
+
const partial = ct !== null && since <= ct;
|
|
365
|
+
const prevPartial = ct !== null && since - days * DAY_MS <= ct;
|
|
366
|
+
const inWindow = (from, to) => recs.filter((r) => r.ts >= from && r.ts < to);
|
|
367
|
+
const win = inWindow(since, now + 1);
|
|
368
|
+
const usageDays = input.series.slice(-days), usagePrev = input.series.length >= 2 * days ? input.series.slice(-2 * days, -days) : null;
|
|
369
|
+
const sumDays = (xs) => xs.reduce((n, d) => n + d.worker + d.person, 0);
|
|
370
|
+
const agent = new Map(input.members.map((m) => [m.name, m.agent]));
|
|
371
|
+
const carried = [...carriedM.entries()].map(([who, c]) => ({
|
|
372
|
+
who, agent: agent.get(who) ?? "", asked: c.asked, byWorker: c.w, byPerson: c.p,
|
|
373
|
+
open: open.filter((o) => o.kind === "answer" && o.owner === who).length, medianMs: median(c.ms),
|
|
374
|
+
})).sort((a, b) => b.asked - a.asked || a.who.localeCompare(b.who));
|
|
375
|
+
const froms = Object.keys(matrixN).sort();
|
|
376
|
+
const tos = [...new Set(Object.values(matrixN).flatMap((r) => Object.keys(r)))].sort();
|
|
377
|
+
const order = input.members.map((m) => m.name);
|
|
378
|
+
const byOrder = (a, b) => (order.indexOf(a) + 1 || 999) - (order.indexOf(b) + 1 || 999) || a.localeCompare(b);
|
|
379
|
+
return {
|
|
380
|
+
now, days, since, members: [...input.members],
|
|
381
|
+
asks: asksIn.length, answered, answeredByWorker: aw, answeredByPerson: ap,
|
|
382
|
+
answerMs, medianAnswerMs: median(answerMs), medianWorkerMs: median(wMs), medianPersonMs: median(pMs),
|
|
383
|
+
pickupMs, medianPickupMs: median(pickupMs),
|
|
384
|
+
delivered: recs.filter((r) => r.act === "DELIVERED" && r.ts >= since).length,
|
|
385
|
+
escalations: recs.filter((r) => (r.act === "ESCALATE" || r.act === "HUMAN_REQUIRED") && r.ts >= since).length,
|
|
386
|
+
decidedMs,
|
|
387
|
+
open, waiting, oldestOpenMs: open.length ? open[0].ageMs : null,
|
|
388
|
+
matrix: { from: froms.sort(byOrder), to: tos.sort(byOrder), n: matrixN },
|
|
389
|
+
carried, threads, goals, series,
|
|
390
|
+
messages: partial && usageDays.length >= days
|
|
391
|
+
? { total: sumDays(usageDays), worker: usageDays.reduce((n, d) => n + d.worker, 0), person: usageDays.reduce((n, d) => n + d.person, 0), prevTotal: usagePrev ? sumDays(usagePrev) : null, utcDays: true }
|
|
392
|
+
: { total: win.length, worker: win.filter((r) => r.by === "worker").length, person: win.filter((r) => r.by === "person").length, prevTotal: prevPartial ? null : input.prevCount ?? inWindow(since - days * DAY_MS, since).length, utcDays: false },
|
|
393
|
+
partial,
|
|
394
|
+
historyFrom: partial ? ct : null,
|
|
395
|
+
askStatus,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
const stateRank = (s) => (s === "BLOCKED" ? 0 : s === "STALLED" ? 1 : s === "OPEN" ? 2 : 3);
|
|
399
|
+
const cap = (s) => (s ? s[0].toUpperCase() + s.slice(1) : s);
|
|
400
|
+
export function dur(ms) {
|
|
401
|
+
if (ms === null || ms === undefined || !Number.isFinite(ms))
|
|
402
|
+
return "";
|
|
403
|
+
const s = Math.max(0, Math.round(ms / 1000));
|
|
404
|
+
if (s < 60)
|
|
405
|
+
return `${s}s`;
|
|
406
|
+
const m = Math.round(s / 60);
|
|
407
|
+
if (m < 60)
|
|
408
|
+
return `${m}m`;
|
|
409
|
+
const h = Math.floor(m / 60), mm = m % 60;
|
|
410
|
+
if (h < 24)
|
|
411
|
+
return mm ? `${h}h ${String(mm).padStart(2, "0")}m` : `${h}h`;
|
|
412
|
+
const d = Math.floor(h / 24), hh = h % 24;
|
|
413
|
+
return hh ? `${d}d ${hh}h` : `${d}d`;
|
|
414
|
+
}
|
|
415
|
+
export const REFUSAL_WORDS = {
|
|
416
|
+
ALREADY_RETRACTED: "a retract of an act already withdrawn",
|
|
417
|
+
AMBIGUOUS_DECISION_AUTHORITY: "a decision two people claim the say over",
|
|
418
|
+
BAD_ACT_ID: "an act with a malformed id",
|
|
419
|
+
BAD_ACT_SIGNATURE: "an act whose signature did not check",
|
|
420
|
+
BAD_BASE: "a delivery naming a malformed base",
|
|
421
|
+
BAD_BRANCH: "a delivery naming a malformed branch",
|
|
422
|
+
BAD_COMMIT: "a delivery naming something that is not a commit",
|
|
423
|
+
BAD_DECISION_DOMAIN: "a decision filed under a name that is no area",
|
|
424
|
+
BAD_GOAL_SIGNATURE: "a goal whose signature did not check",
|
|
425
|
+
BAD_JSON: "a message that was not JSON",
|
|
426
|
+
BAD_MESSAGE: "a malformed message",
|
|
427
|
+
BAD_META: "an act with malformed details",
|
|
428
|
+
BAD_REF: "a reply to an act that is not there",
|
|
429
|
+
BAD_REMOTE: "a delivery naming a malformed remote",
|
|
430
|
+
BUDGET_SPENT: "a goal out of acts",
|
|
431
|
+
CLAIMED: "work another session had already taken",
|
|
432
|
+
CONFIRM_MISMATCH: "a confirmation that did not match",
|
|
433
|
+
DEADLINE_PAST: "a goal whose deadline had passed",
|
|
434
|
+
DECISION_ALREADY_WAITING: "a decision already waiting on someone",
|
|
435
|
+
DECISION_DOMAINS_REQUIRED: "a decision that named no area",
|
|
436
|
+
DEFER: "a worker waiting for its person's live session",
|
|
437
|
+
ESCALATE_IS_LOCAL: "an escalation addressed to someone else",
|
|
438
|
+
FOUNDER_ONLY: "something only the founder may do",
|
|
439
|
+
FOUNDER_STAYS: "a founder trying to leave their own team",
|
|
440
|
+
GOAL_CLOSED: "an act in a goal already closed",
|
|
441
|
+
GOAL_REQUIRED: "an act that needs a goal and named none",
|
|
442
|
+
ID_TAKEN: "an id already in use",
|
|
443
|
+
META_TOO_LARGE: "an act with too many details attached",
|
|
444
|
+
NAMED_BY_A_RUN: "a decision-maker named by an unattended run",
|
|
445
|
+
NO_CLAIMS: "a profile with nothing in it",
|
|
446
|
+
NO_RECOVERY: "a seat move nobody asked for",
|
|
447
|
+
NO_SELF_ADMIT: "a member admitting themselves",
|
|
448
|
+
NO_SUCH_ACT: "a reply to an act that is not there",
|
|
449
|
+
NO_SUCH_GOAL: "a goal that does not exist",
|
|
450
|
+
NO_SUCH_INVITE: "an invite that does not exist",
|
|
451
|
+
NO_SUCH_MEMBER: "a member who is not on the team",
|
|
452
|
+
NO_SUCH_OBLIGATION: "a claim on work already done",
|
|
453
|
+
NOT_ADMITTED: "a member not yet admitted",
|
|
454
|
+
NOT_ALLOWED_TO_WAKE: "a worker woken by someone not allowed to",
|
|
455
|
+
NOT_FOR_A_RUN: "something an unattended run may not do",
|
|
456
|
+
NOT_IN_GOAL: "an act in a goal the sender is not in",
|
|
457
|
+
NOT_OWNER: "something only its owner may do",
|
|
458
|
+
NOT_SIGNED_IN: "a connection from a device not signed in",
|
|
459
|
+
NOT_YOUR_DECISION: "a decision answered by someone else",
|
|
460
|
+
NOT_YOURS: "a claim on someone else's work",
|
|
461
|
+
NOT_YOURS_TO_RETRACT: "a retract of someone else's act",
|
|
462
|
+
NOTHING_OWED: "a withdraw from nothing owed",
|
|
463
|
+
ONE_HUMAN_REQUIRED: "a decision sent to more than one person",
|
|
464
|
+
PEER_TURN: "six acts in a row without a reply",
|
|
465
|
+
PLAN_LIMIT: "team full on its plan",
|
|
466
|
+
PROFILE_NOT_YOURS: "a change to someone else's profile",
|
|
467
|
+
RATE_LIMIT: "too many acts too fast",
|
|
468
|
+
RECOVERY_BY_PERSON: "a seat move only a person may confirm",
|
|
469
|
+
RECOVERY_KEY: "a seat move with the wrong key",
|
|
470
|
+
RECOVERY_SELF: "a member confirming their own seat move",
|
|
471
|
+
REF_OTHER_GOAL: "a reply to an act in another goal",
|
|
472
|
+
REF_REQUIRED: "a reply that named nothing to reply to",
|
|
473
|
+
REPO_MISMATCH: "sent from a repo the team does not work from",
|
|
474
|
+
REPO_REQUIRED: "work sent without naming its repo",
|
|
475
|
+
RESERVED_ACT: "an act only the relay may write",
|
|
476
|
+
REVOKED: "a member who was removed",
|
|
477
|
+
SELF_DEFER: "a goal closed in favour of itself",
|
|
478
|
+
SHUTTING_DOWN: "a request while the relay was restarting",
|
|
479
|
+
SIGNED_ONLY: "an unsigned read where only signed ones are served",
|
|
480
|
+
SPACE_CREATE_RATE: "too many teams made from one network",
|
|
481
|
+
SPACE_DELETED: "a team that was deleted",
|
|
482
|
+
SPACE_HELD: "someone new, for a team that cannot be told apart from a deleted one",
|
|
483
|
+
SPACE_FULL: "the team's history is full",
|
|
484
|
+
SPACE_LIMIT: "the relay at its limit of teams",
|
|
485
|
+
SPACE_UNREADABLE: "a team whose files could not be read",
|
|
486
|
+
STALE_VIEW: "a change made from an out-of-date view",
|
|
487
|
+
STORAGE: "a write the disk refused",
|
|
488
|
+
SUMMARY_REQUIRED: "a long message with no one-line summary",
|
|
489
|
+
TO_REQUIRED: "an ask that named nobody",
|
|
490
|
+
TOO_MANY_GOALS: "too many open goals",
|
|
491
|
+
TOO_MANY_INVITES: "too many open invites",
|
|
492
|
+
TOO_MANY_REFUSALS: "a connection closed for too many refusals",
|
|
493
|
+
TOO_MANY_REPOS: "too many repos registered",
|
|
494
|
+
UNBOUND_SPACE: "an invite to an old team that has no team token yet",
|
|
495
|
+
UNVERIFIABLE_DELIVERY: "a delivery that named no branch and commit",
|
|
496
|
+
UPGRADE_REQUIRED: "a client too old for this team",
|
|
497
|
+
WOULD_ORPHAN: "a change that would leave the team with no founder",
|
|
498
|
+
WRONG_DECISION_OWNER: "a decision sent to the wrong person",
|
|
499
|
+
};
|
|
500
|
+
export const refusalWords = (code) => REFUSAL_WORDS[code] ?? code.toLowerCase().replace(/_/g, " ");
|
|
501
|
+
//# sourceMappingURL=flow-stats.js.map
|
package/dist/home-guard.js
CHANGED
|
@@ -18,7 +18,8 @@ export const READINESS_ALERT_FILE = "readiness-alert.json";
|
|
|
18
18
|
export const CHANGES_LOG_FILE = "setup-changes.log";
|
|
19
19
|
export const PENDING_CHANGES_FILE = "setup-pending.json";
|
|
20
20
|
export const RUN_CONTROL_FILE = "run-control.json";
|
|
21
|
-
export const
|
|
21
|
+
export const HUD_PREF_FILE = join("bin", ".hud-pref.json");
|
|
22
|
+
export const GUARDED_FILES = [POLICY_FILE, CONFIG_FILE, PROFILE_FILE, HUD_FILE, CONTINUED_FILE, CURSOR_FILE, PINS_FILE, NONCES_FILE, REMOVED_FILE, RECHECK_FILE, READINESS_ALERT_FILE, CHANGES_LOG_FILE, PENDING_CHANGES_FILE, RUN_CONTROL_FILE, HUD_PREF_FILE];
|
|
22
23
|
export function narrowRunControl(before, now) {
|
|
23
24
|
const list = (x) => (Array.isArray(obj(x).stops) ? obj(x).stops.filter((e) => !!e && typeof e === "object") : []);
|
|
24
25
|
const b = list(before), n = list(now);
|
|
@@ -643,7 +644,7 @@ export function restoreHome(s) {
|
|
|
643
644
|
const hashNow = now ? sha(now) : null;
|
|
644
645
|
if (hashNow === f.hash)
|
|
645
646
|
continue;
|
|
646
|
-
const alwaysNarrow = f.rel === POLICY_FILE || f.rel === PROFILE_FILE || f.rel === CONFIG_FILE || f.rel === CONTINUED_FILE || f.rel === CURSOR_FILE || f.rel === PINS_FILE || f.rel === NONCES_FILE || f.rel === PENDING_CHANGES_FILE || f.rel === CHANGES_LOG_FILE || f.rel === RUN_CONTROL_FILE;
|
|
647
|
+
const alwaysNarrow = f.rel === POLICY_FILE || f.rel === PROFILE_FILE || f.rel === CONFIG_FILE || f.rel === CONTINUED_FILE || f.rel === CURSOR_FILE || f.rel === PINS_FILE || f.rel === NONCES_FILE || f.rel === PENDING_CHANGES_FILE || f.rel === CHANGES_LOG_FILE || f.rel === RUN_CONTROL_FILE || f.rel === HUD_PREF_FILE;
|
|
647
648
|
if (!alwaysNarrow && trusted.get(resolve(file))?.has(hashNow ?? "absent"))
|
|
648
649
|
continue;
|
|
649
650
|
try {
|
|
@@ -685,6 +686,30 @@ export function restoreHome(s) {
|
|
|
685
686
|
continue;
|
|
686
687
|
}
|
|
687
688
|
const a = parse(f.bytes), b = parse(now);
|
|
689
|
+
if (f.rel === HUD_PREF_FILE) {
|
|
690
|
+
const before = obj(a), cur = obj(b);
|
|
691
|
+
if (before.open_in === cur.open_in)
|
|
692
|
+
continue;
|
|
693
|
+
try {
|
|
694
|
+
if (lstatSync(file).isSymbolicLink())
|
|
695
|
+
rmSync(file, { force: true });
|
|
696
|
+
}
|
|
697
|
+
catch { }
|
|
698
|
+
const next = { ...cur };
|
|
699
|
+
if (before.open_in === undefined)
|
|
700
|
+
delete next.open_in;
|
|
701
|
+
else
|
|
702
|
+
next.open_in = before.open_in;
|
|
703
|
+
try {
|
|
704
|
+
writeWhole(file, JSON.stringify(next));
|
|
705
|
+
}
|
|
706
|
+
catch {
|
|
707
|
+
writeFileSync(file, JSON.stringify(next), { mode: 0o600 });
|
|
708
|
+
}
|
|
709
|
+
trustWrite(file);
|
|
710
|
+
out.push({ rel: f.rel, what: "reverted", keys: ["where questions open"] });
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
688
713
|
if (f.rel === RUN_CONTROL_FILE) {
|
|
689
714
|
const n = narrowRunControl(a, b);
|
|
690
715
|
if (n.keys.length) {
|
package/dist/home-safety.js
CHANGED
|
@@ -40,6 +40,7 @@ export const PANTHEON_HOME_ENTRIES = [
|
|
|
40
40
|
{ name: /^\.write-check\..+$/, sample: ".write-check.1234.5678", what: "a leftover write probe" },
|
|
41
41
|
{ name: "bin", what: "the menu bar's and alerts' files", dir: true },
|
|
42
42
|
{ name: "logs", what: "the service logs", dir: true },
|
|
43
|
+
{ name: "handoff", what: "long questions handed to the Claude app outside any team folder (open-in.ts)", dir: true },
|
|
43
44
|
{ name: "host", what: "the Windows host's queue, state and markers", dir: true },
|
|
44
45
|
{ name: "mcp", what: "the agent windows' server state", dir: true },
|
|
45
46
|
{ name: "run-homes", what: "the woken runs' homes", dir: true },
|
package/dist/ledger.js
CHANGED
|
@@ -157,11 +157,17 @@ export class Ledger {
|
|
|
157
157
|
compact(opts) {
|
|
158
158
|
const cut = Math.max(0, this.records.length - opts.keepRecent);
|
|
159
159
|
if (cut === 0)
|
|
160
|
-
return { dropped: 0, kept: this.records.length };
|
|
161
|
-
|
|
160
|
+
return { dropped: 0, kept: this.records.length, newestDropped: null };
|
|
161
|
+
let newestDropped = null;
|
|
162
|
+
const kept = this.records.filter((r, i) => {
|
|
163
|
+
const keep = i >= cut || opts.isLive(r.goal) || (opts.keep?.(r.id) ?? false);
|
|
164
|
+
if (!keep && (newestDropped === null || r.ts > newestDropped))
|
|
165
|
+
newestDropped = r.ts;
|
|
166
|
+
return keep;
|
|
167
|
+
});
|
|
162
168
|
const dropped = this.records.length - kept.length;
|
|
163
169
|
if (dropped === 0)
|
|
164
|
-
return { dropped: 0, kept: kept.length };
|
|
170
|
+
return { dropped: 0, kept: kept.length, newestDropped: null };
|
|
165
171
|
const text = kept.map((r) => JSON.stringify(r)).join("\n") + "\n";
|
|
166
172
|
writerFor(this.dir, this.stem).replace(this.file, text);
|
|
167
173
|
this.records = kept;
|
|
@@ -170,7 +176,7 @@ export class Ledger {
|
|
|
170
176
|
if (!this.byId.has(r.id))
|
|
171
177
|
this.byId.set(r.id, r);
|
|
172
178
|
this.fileBytes = Buffer.byteLength(text);
|
|
173
|
-
return { dropped, kept: kept.length };
|
|
179
|
+
return { dropped, kept: kept.length, newestDropped };
|
|
174
180
|
}
|
|
175
181
|
}
|
|
176
182
|
export class LedgerUnreachable extends Error {
|