@join-pantheon/cli 0.35.2 → 0.35.3-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.
package/dist/relay.js CHANGED
@@ -30,8 +30,9 @@ import { fmtLimit, inviteLimit, parseLimits, planLimits, PLAN_NAME } from "./pla
30
30
  import { FEEDBACK_ADDRESS } from "./feedback.js";
31
31
  import { relayShellArg, teamNameProblem } from "./team-name.js";
32
32
  import { reservedBy, routeDecision } from "./profile.js";
33
- import { namedMarker } from "./decision-ui.js";
33
+ import { ANSWER_OPTIONS_SCAN, answerOptions, clipClause, DECISION_ASKS, decisionDue, decisionQuestion, namedMarker } from "./decision-ui.js";
34
34
  import { ByteLru } from "./byte-lru.js";
35
+ import { heldGoals, isSettled, lastActs, noteLast, withLast } from "./settled.js";
35
36
  import { DELETED_NAME_HOLD_MS, TEAM_FILES, classifyLeftover, teamStems } from "./leftovers.js";
36
37
  const presentSessions = (m) => [...m.sessions.values()].filter((s) => !s.quiet);
37
38
  function workState(m, now = Date.now(), busyTtlMs = LIMITS.activityBusyTtlMs, pruneMs = LIMITS.activityPruneMs) {
@@ -601,6 +602,21 @@ export class Relay {
601
602
  opts;
602
603
  advertisedPkg() { return advertisedPkg(this.upgradeHold, VERSION); }
603
604
  spaces = new Map();
605
+ lasts = new WeakMap();
606
+ lastsOf(sp) {
607
+ let m = this.lasts.get(sp);
608
+ if (!m) {
609
+ m = lastActs(sp.ledger.all());
610
+ this.lasts.set(sp, m);
611
+ }
612
+ return m;
613
+ }
614
+ goalView(sp, g, held) {
615
+ return g.state === "CLOSED" ? g : withLast(g, this.lastsOf(sp).get(g.id), held?.has(g.id) ?? false);
616
+ }
617
+ heldIn(sp) {
618
+ return heldGoals(sp.obligations.values(), (id) => sp.ledger.find(id)?.goal);
619
+ }
604
620
  dataDir;
605
621
  log;
606
622
  http = createServer((req, res) => {
@@ -986,11 +1002,21 @@ export class Relay {
986
1002
  const owed = [...space.obligations.values()]
987
1003
  .filter((o) => (member ? o.owner === member : true))
988
1004
  .map((o) => ({ ...o, claimed: !!o.claimed_by && this.claimHolds(space, o.claimed_by, now) }));
1005
+ const extras = obligationExtras(owed, space.ledger, space.goals);
1006
+ for (const o of owed)
1007
+ Object.assign(o, extras.get(o.id) ?? {});
989
1008
  const closed = [...space.goals.values()].filter((g) => g.state === "CLOSED").map((g) => g.id);
990
1009
  const worker_online = member
991
1010
  ? [...(space.members.get(member)?.sessions.values() ?? [])].some((s) => s.role === "worker")
992
1011
  : false;
993
- return this.json(res, 200, { obligations: owed, closed_goals: closed, seq: space.ledger.head, worker_online, space_id: space.allow.spaceId(), members: this.members(space),
1012
+ const settledFor = gate.reader ?? member;
1013
+ const owedIn = settledFor ? this.heldIn(space) : new Set();
1014
+ const settled_goals = settledFor
1015
+ ? [...space.goals.values()].filter((g) => g.opened_by === settledFor && g.state === "OPEN").map((g) => this.goalView(space, g))
1016
+ .filter((g) => isSettled(g, owedIn, now))
1017
+ .map((g) => ({ id: g.id, title: g.title, last_at: g.last_at }))
1018
+ : [];
1019
+ return this.json(res, 200, { obligations: owed, closed_goals: closed, settled_goals, seq: space.ledger.head, worker_online, space_id: space.allow.spaceId(), members: this.members(space),
994
1020
  ...(gate.reader ? { roster: this.roster(space), now: Date.now() } : {}) });
995
1021
  }
996
1022
  if (url.pathname === "/activity") {
@@ -3423,12 +3449,28 @@ export class Relay {
3423
3449
  flowOfSlice(ts, days, members, now, records, index, prevCount) {
3424
3450
  return flowOf(this.flowInput(ts, days, members, now, records, index, prevCount));
3425
3451
  }
3452
+ heldGoals(ts) {
3453
+ const sp = ts.sp;
3454
+ if (sp)
3455
+ return this.heldIn(sp);
3456
+ const want = new Set();
3457
+ for (const o of ts.obligations.values())
3458
+ for (const id of [o.ref, o.about])
3459
+ if (id)
3460
+ want.add(id);
3461
+ const goalOfAct = new Map();
3462
+ if (want.size)
3463
+ for (const r of ts.records)
3464
+ if (want.has(r.id))
3465
+ goalOfAct.set(r.id, r.goal);
3466
+ return heldGoals(ts.obligations.values(), (id) => goalOfAct.get(id));
3467
+ }
3426
3468
  flowInput(ts, days, members, now, records, index, prevCount) {
3427
3469
  const sp = ts.sp;
3428
3470
  return {
3429
3471
  records, ...(index ? { index } : {}), ...(prevCount !== undefined ? { prevCount } : {}),
3430
3472
  obligations: toFlowObligations(ts.obligations.values(), ts.firstClaims, (o) => !!sp && !!o.claimed_by && this.claimHolds(sp, o.claimed_by, now)),
3431
- goals: toFlowGoals(ts.goals.values()),
3473
+ goals: toFlowGoals(ts.goals.values(), sp ? this.lastsOf(sp) : lastActs(ts.records), this.heldGoals(ts)),
3432
3474
  members: members.filter((m) => m.admitted).map((m) => ({ name: m.name, agent: m.agent, online: m.online, founder: m.founder })),
3433
3475
  series: seriesOf(ts.usage, Math.max(14, days * 2), now),
3434
3476
  firstClaims: [...ts.firstClaims.values()],
@@ -4662,7 +4704,7 @@ pantheon start</code></pre>
4662
4704
  }
4663
4705
  this.send(ws, {
4664
4706
  t: "welcome", member: me.id, session: sessionId, space: sp.name, seq: sp.ledger.head,
4665
- roster: this.roster(sp), now: Date.now(), goals: [...sp.goals.values()],
4707
+ roster: this.roster(sp), now: Date.now(), goals: ((held) => [...sp.goals.values()].map((g) => this.goalView(sp, g, held)))(this.heldIn(sp)),
4666
4708
  obligations: [...sp.obligations.values()], members: this.members(sp), profiles: [...sp.profiles.values()],
4667
4709
  space_id: sp.allow.spaceId(), repos: sp.allow.repoList(), features: [...this.features],
4668
4710
  ...(acct ? { plan: this.planView(acct, sp) } : {}),
@@ -5749,6 +5791,11 @@ pantheon start</code></pre>
5749
5791
  return rec;
5750
5792
  }
5751
5793
  effects(sp, rec, ctx) {
5794
+ if (rec.goal) {
5795
+ const m = this.lasts.get(sp);
5796
+ if (m)
5797
+ m.set(rec.goal, noteLast(m.get(rec.goal), rec, rec.act === "ACCEPT" && rec.ref ? sp.ledger.find(rec.ref)?.act ?? null : null));
5798
+ }
5752
5799
  if (rec.goal) {
5753
5800
  const goal = sp.goals.get(rec.goal);
5754
5801
  if (goal) {
@@ -6322,6 +6369,7 @@ pantheon start</code></pre>
6322
6369
  return { goals: sp.goals, obligations: sp.obligations, note: null };
6323
6370
  }
6324
6371
  rebuildFromLedger(sp) {
6372
+ this.lasts.delete(sp);
6325
6373
  sp.goals.clear();
6326
6374
  sp.obligations.clear();
6327
6375
  const ctx = { retracted: new Set(), answers: new Map() };
@@ -6588,4 +6636,91 @@ export function first(s, n = 200, summary) {
6588
6636
  const at = cut.lastIndexOf(" ");
6589
6637
  return (at > n * 0.6 ? cut.slice(0, at) : cut).replace(/[\s,;:—-]+$/, "") + "…";
6590
6638
  }
6639
+ const ACT_READS = new WeakMap();
6640
+ export function obligationExtras(list, ledger, goals) {
6641
+ const out = new Map();
6642
+ const human = list.filter((o) => o.kind === "HUMAN");
6643
+ const since = human.reduce((m, o) => Math.min(m, o.created_at), Infinity);
6644
+ const lastInGoal = new Map(), lastOnRef = new Map();
6645
+ if (human.length) {
6646
+ const all = ledger.all();
6647
+ for (let i = all.length - 1; i >= 0 && all.length - i <= 20_000; i--) {
6648
+ const r = all[i];
6649
+ if (r.ts < since)
6650
+ break;
6651
+ if (r.from === RELAY_MEMBER || r.act === "JOIN" || r.act === "LEAVE")
6652
+ continue;
6653
+ if (r.goal && !lastInGoal.has(r.goal))
6654
+ lastInGoal.set(r.goal, r.ts);
6655
+ if (r.ref && !lastOnRef.has(r.ref))
6656
+ lastOnRef.set(r.ref, r.ts);
6657
+ }
6658
+ }
6659
+ for (const o of list) {
6660
+ const rec = ledger.find(o.ref);
6661
+ const x = {};
6662
+ if (rec) {
6663
+ if (o.kind !== "HUMAN")
6664
+ x.for = rec.from;
6665
+ else if (rec.act === "HUMAN_REQUIRED")
6666
+ x.for = rec.from;
6667
+ else if (rec.act === "ESCALATE") {
6668
+ const own = rec.role === "worker" && rec.sig?.role !== "run";
6669
+ const about = !own && o.about ? ledger.find(o.about) : undefined;
6670
+ x.for = own ? rec.from : about?.from ?? (rec.goal ? goals.get(rec.goal)?.opened_by : undefined) ?? rec.from;
6671
+ }
6672
+ else
6673
+ x.for = o.owner.replace(/^human:/, "");
6674
+ }
6675
+ if (o.kind === "HUMAN") {
6676
+ const active = Math.max(o.created_at, (o.goal && lastInGoal.get(o.goal)) || 0, lastOnRef.get(o.ref) ?? 0, (o.about && lastOnRef.get(o.about)) || 0);
6677
+ const d = { active_at: active };
6678
+ if (!rec || (rec.act !== "ESCALATE" && rec.act !== "HUMAN_REQUIRED")) {
6679
+ if (rec)
6680
+ d.origin = "budget";
6681
+ }
6682
+ else
6683
+ d.origin = rec.act === "HUMAN_REQUIRED" ? "request" : rec.role === "worker" && rec.sig?.role !== "run" ? "machine"
6684
+ : !x.for || x.for === rec.from ? "own" : "for_teammate";
6685
+ if (rec && (rec.act === "ESCALATE" || rec.act === "HUMAN_REQUIRED")) {
6686
+ const goal = rec.goal ? goals.get(rec.goal) : undefined;
6687
+ const key = `${o.owner}|${goal?.title ?? ""}`;
6688
+ let reads = ACT_READS.get(rec);
6689
+ if (!reads) {
6690
+ reads = new Map();
6691
+ ACT_READS.set(rec, reads);
6692
+ }
6693
+ let read = reads.get(key);
6694
+ if (!read) {
6695
+ const q = decisionQuestion(rec.body, { summary: rec.summary ?? null, goalTitle: goal?.title ?? null, names: [o.owner.replace(/^human:/, ""), rec.from] });
6696
+ read = { ...(q ? { question: q.length > 240 ? clipClause(q, 240) : q } : {}), options: answerOptions(rec.body, ANSWER_OPTIONS_SCAN).length };
6697
+ if (reads.size >= 8)
6698
+ reads.delete(reads.keys().next().value);
6699
+ reads.set(key, read);
6700
+ }
6701
+ if (read.question)
6702
+ d.question = read.question;
6703
+ const m = rec.meta?.decision;
6704
+ if (m && typeof m === "object") {
6705
+ if (typeof m.ask === "string" && DECISION_ASKS.includes(m.ask))
6706
+ d.ask = m.ask;
6707
+ const due = decisionDue(m.due);
6708
+ if (due !== undefined)
6709
+ d.due = due;
6710
+ if (Array.isArray(m.options)) {
6711
+ const n = m.options.filter((s) => typeof s === "string" && s.trim()).length;
6712
+ if (n >= 2)
6713
+ d.options = Math.min(n, 9);
6714
+ }
6715
+ }
6716
+ if (d.options === undefined && read.options)
6717
+ d.options = read.options;
6718
+ }
6719
+ x.decision = d;
6720
+ }
6721
+ if (x.for !== undefined || x.decision)
6722
+ out.set(o.id, x);
6723
+ }
6724
+ return out;
6725
+ }
6591
6726
  //# sourceMappingURL=relay.js.map
@@ -0,0 +1,101 @@
1
+ export const REPEAT_WINDOW_MS = 60 * 60_000;
2
+ export function normalized(s) {
3
+ return s.toLowerCase().normalize("NFKC").replace(/[^\p{L}\p{N}+\-<>=!%]+/gu, " ").trim();
4
+ }
5
+ export function sameMessage(a, b) {
6
+ const x = normalized(a), y = normalized(b);
7
+ return !!x && x === y;
8
+ }
9
+ const sameSet = (a, b) => {
10
+ const x = [...new Set(a ?? [])].sort(), y = [...new Set(b ?? [])].sort();
11
+ return x.length === y.length && x.every((v, i) => v === y[i]);
12
+ };
13
+ export function repeatOf(next, acts, o) {
14
+ if (next.act !== "NOTE" && next.act !== "ASK")
15
+ return null;
16
+ const to = (next.to ?? []).filter((t) => t !== o.me);
17
+ if (!to.length && !next.goal)
18
+ return null;
19
+ const retracted = new Set(acts.filter((a) => a.act === "RETRACT" && a.from === o.me && a.ref).map((a) => a.ref));
20
+ const mine = acts
21
+ .filter((a) => a.from === o.me && (a.act === "NOTE" || a.act === "ASK") && !retracted.has(a.id) && o.now - a.ts <= REPEAT_WINDOW_MS && a.ts <= o.now + 60_000)
22
+ .filter((a) => sameSet((a.to ?? []).filter((t) => t !== o.me), to))
23
+ .filter((a) => !(next.goal && a.goal && next.goal !== a.goal) && (to.length || a.goal === next.goal))
24
+ .filter((a) => (a.ref ?? null) === (next.ref ?? null))
25
+ .filter((a) => sameMessage(a.body, next.body))
26
+ .sort((a, b) => b.ts - a.ts);
27
+ for (const a of mine) {
28
+ const since = (r) => r.ts >= a.ts && r.id !== a.id && r.from !== o.me;
29
+ const replied = to.length
30
+ ? acts.some((r) => since(r) && (r.ref === a.id || (to.includes(r.from) && ((!!a.goal && r.goal === a.goal) || (r.to ?? []).includes(o.me)))))
31
+ : acts.some((r) => since(r) && (r.ref === a.id || (!!a.goal && r.goal === a.goal)));
32
+ if (!replied)
33
+ return a;
34
+ }
35
+ return null;
36
+ }
37
+ export function silenceSince(next, me) {
38
+ const to = (next.to ?? []).filter((t) => t !== me);
39
+ return to.length ? `${to.join(" and ")} ${to.length === 1 ? "has" : "have"} not replied since` : "nobody in the goal has said anything since";
40
+ }
41
+ export function openAskLike(next, owed, o) {
42
+ if (next.act !== "ASK" || next.ref)
43
+ return null;
44
+ const to = (next.to ?? []).filter((t) => t !== o.me);
45
+ if (!to.length)
46
+ return null;
47
+ for (const ob of owed) {
48
+ if (ob.kind !== "ANSWER" || !to.includes(ob.owner))
49
+ continue;
50
+ const a = o.actOf(ob.ref);
51
+ if (!a || a.from !== o.me || a.act !== "ASK")
52
+ continue;
53
+ if (sameMessage(a.body, next.body))
54
+ return { obligation: ob, said: a.body };
55
+ }
56
+ return null;
57
+ }
58
+ const ADJ = String.raw `(?:new|strong|good|relevant|notable|significant|fresh|real|qualifying|useful|interesting|worthwhile)`;
59
+ const NOUN = String.raw `(?:replies|reply|updates?|news|results?|changes?|leads?|mentions?|comments?|posts?|emails?|tickets?|activity|responses?|messages?|items?|candidates?|matches|signals?|hits|alerts?|issues?)`;
60
+ const WORD = String.raw `[\p{L}\p{N}@#._'-]+`;
61
+ const QUAL = String.raw `(?:today|tonight|yet|so\s+far|overnight|found|to\s+report|this\s+(?:morning|afternoon|evening|week)|since\s+(?:yesterday|last\s+(?:night|week|check))|(?:on|from|in|for|about)\s+(?:(?:the|our|my)\s+)?${WORD})`;
62
+ const TAIL = String.raw `(?:\s+${QUAL}){0,2}`;
63
+ const NO_NEWS = [
64
+ new RegExp(String.raw `^no\s+(?:${ADJ}\s+)*(?:(?!(?:more|further|longer)\b)${WORD}\s+){0,2}${NOUN}${TAIL}$`, "iu"),
65
+ new RegExp(String.raw `^nothing(?:\s+(?:new|else))?(?:\s+to\s+(?:report|flag|decide))?${TAIL}$`, "iu"),
66
+ new RegExp(String.raw `^no\s+(?:action|decision)\s+(?:is\s+)?(?:needed|required)${TAIL}$`, "iu"),
67
+ new RegExp(String.raw `^nothing\s+(?:needs|requires)\s+(?:a\s+|your\s+)?(?:decision|action|attention)${TAIL}$`, "iu"),
68
+ new RegExp(String.raw `^all\s+quiet${TAIL}$`, "iu"),
69
+ ];
70
+ const MORE = /,|\b(?:but|so|and|except|however|though|although|while|whereas|plus|also)\b/i;
71
+ const DECIDES = [
72
+ /\?/,
73
+ /\boptions?\b|\(\s*[a-c1-3]\s*\)|^\s*(?:[a-c]|[1-3])[.)]\s/im,
74
+ /\b(?:recommend|decide|decision on|choose|choice|approve|approval|pick|prefer|whether|which|should\s+(?:i|we|it|they))\b/i,
75
+ /\b(?:need\s+(?:you|your)|please|can\s+you|could\s+you|would\s+you|urgent|asap|blocked|failed|failing|error|broken|outage|deadline|overdue)\b/i,
76
+ /\b(?:unless|object|objection|your\s+call|up\s+to\s+you|go\s*(?:\/|or)\s*no[-\s]?go|no[-\s]go|sign(?:[-\s]?off|ed|ing)?|signature)\b/i,
77
+ /[$€£₹¥]\s?\d|\b\d[\d,.]*\s?(?:k|m|bn|usd|eur|gbp|inr|aed|dollars?|euros?|pounds?|rupees?)\b/i,
78
+ /\b\d{4}-\d{2}-\d{2}\b|\b\d{1,2}\/\d{1,2}\b|\b(?:mon|tues|wednes|thurs|fri|satur|sun)day\b|\btomorrow\b|\bnext\s+(?:week|month)\b|\bend\s+of\s+(?:day|the\s+week|the\s+month)\b/i,
79
+ /\b(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\.?\s+\d{1,2}\b|\b\d{1,2}(?:st|nd|rd|th)?\s+(?:jan|feb|mar|apr|may|jun|jul|aug|sep|sept|oct|nov|dec)[a-z]*\b/i,
80
+ ];
81
+ const NO_NEWS_MAX = 160;
82
+ export function nothingToDecide(body, summary, shape) {
83
+ if (shape && (shape.ask !== undefined || shape.options !== undefined || shape.due !== undefined))
84
+ return false;
85
+ const text = `${summary ?? ""}\n${body}`.trim();
86
+ if (text.length > NO_NEWS_MAX)
87
+ return false;
88
+ if (DECIDES.some((r) => r.test(text)))
89
+ return false;
90
+ if (MORE.test(text.replace(/\bso\s+far\b/gi, "")))
91
+ return false;
92
+ const sentences = text.split(/[.!;:\n]+|\s[—–-]\s/)
93
+ .map((x) => x.replace(/^[\s"'“”‘’()*_~`>#-]+|[\s"'“”‘’()*_~`]+$/g, ""))
94
+ .filter((x) => /\p{L}/u.test(x));
95
+ return sentences.length > 0 && sentences.every((x) => NO_NEWS.some((r) => r.test(x)));
96
+ }
97
+ export function quoted(s, n = 160) {
98
+ const t = s.replace(/\s+/g, " ").trim();
99
+ return t.length > n ? `${t.slice(0, n - 1)}…` : t;
100
+ }
101
+ //# sourceMappingURL=send-hygiene.js.map
@@ -0,0 +1,114 @@
1
+ export const SETTLED_QUIET_MS = 72 * 60 * 60_000;
2
+ export const SETTLING_ACTS = new Set(["ANSWER", "DELIVERED", "ACCEPT"]);
3
+ const OPENS_WORK = new Set(["PROPOSE", "CONTRACT", "COMMIT"]);
4
+ const OPEN_MAX = 200;
5
+ const OVERFLOW = "…";
6
+ export function noteLast(prev, rec, refAct) {
7
+ const at = Math.max(prev?.at ?? 0, rec.ts);
8
+ const open = new Set(prev?.open ?? []);
9
+ const by = { ...(prev?.by ?? {}) };
10
+ const out = (act) => {
11
+ let ids = [...open];
12
+ if (ids.length > OPEN_MAX)
13
+ ids = [OVERFLOW, ...ids.filter((x) => x !== OVERFLOW).slice(-(OPEN_MAX - 1))];
14
+ const keptBy = Object.fromEntries(ids.filter((x) => typeof by[x] === "string").map((x) => [x, by[x]]));
15
+ return { ...(act ? { act } : {}), at, ...(ids.length ? { open: ids } : {}), ...(Object.keys(keptBy).length ? { by: keptBy } : {}) };
16
+ };
17
+ const opens = (id) => { open.add(id); if (rec.from)
18
+ by[id] = rec.from; };
19
+ if (rec.act === "NOTE" || rec.act === "JOIN" || rec.act === "LEAVE")
20
+ return out(prev?.act);
21
+ if (OPENS_WORK.has(rec.act)) {
22
+ opens(rec.id ?? OVERFLOW);
23
+ return out(rec.act);
24
+ }
25
+ if (rec.act === "DELIVERED") {
26
+ if (rec.ref)
27
+ open.delete(rec.ref);
28
+ else if (open.size === 1 && !open.has(OVERFLOW)) {
29
+ const [only] = [...open];
30
+ if (rec.from && by[only] === rec.from)
31
+ open.clear();
32
+ }
33
+ return out("DELIVERED");
34
+ }
35
+ if (rec.act === "WITHDRAW" || rec.act === "RETRACT") {
36
+ if (rec.ref)
37
+ open.delete(rec.ref);
38
+ return out(rec.act);
39
+ }
40
+ if (rec.act === "ACCEPT") {
41
+ if (refAct !== "DELIVERED" && refAct !== "WITHDRAW") {
42
+ const id = rec.ref ?? rec.id ?? OVERFLOW;
43
+ if (!open.has(id))
44
+ opens(id);
45
+ }
46
+ return out("ACCEPT");
47
+ }
48
+ return out(rec.act);
49
+ }
50
+ const ACCEPTED_KINDS = new Set(["PROPOSE", "CONTRACT", "COMMIT", "DELIVERED", "WITHDRAW"]);
51
+ export function lastActs(acts) {
52
+ const m = new Map();
53
+ const kind = new Map();
54
+ for (const a of acts) {
55
+ if (ACCEPTED_KINDS.has(a.act))
56
+ kind.set(a.id, a.act);
57
+ if (a.goal)
58
+ m.set(a.goal, noteLast(m.get(a.goal), a, a.act === "ACCEPT" && a.ref ? kind.get(a.ref) ?? null : null));
59
+ }
60
+ return m;
61
+ }
62
+ export function withLast(g, last, held = false) {
63
+ const v = last ? { ...g, ...(last.act ? { last_act: last.act } : {}), last_at: last.at, ...(last.open?.length ? { last_open: [...last.open] } : {}), ...(last.by && Object.keys(last.by).length ? { last_open_by: { ...last.by } } : {}) } : g;
64
+ return held ? { ...v, held: true } : v;
65
+ }
66
+ export function lastOfView(g) {
67
+ if (typeof g.last_at !== "number")
68
+ return undefined;
69
+ const open = Array.isArray(g.last_open) ? g.last_open.filter((x) => typeof x === "string").slice(0, OPEN_MAX) : [];
70
+ const raw = g.last_open_by && typeof g.last_open_by === "object" ? g.last_open_by : {};
71
+ const by = Object.fromEntries(open.filter((x) => typeof raw[x] === "string").map((x) => [x, raw[x]]));
72
+ return { ...(g.last_act ? { act: g.last_act } : {}), at: g.last_at, ...(open.length ? { open } : {}), ...(Object.keys(by).length ? { by } : {}) };
73
+ }
74
+ export function applyLast(g, last) {
75
+ const { last_act: _a, last_at: _t, last_open: _o, last_open_by: _b, ...rest } = g;
76
+ return withLast(rest, last);
77
+ }
78
+ export function heldGoals(owed, goalOf = () => undefined) {
79
+ const held = new Set();
80
+ for (const o of owed) {
81
+ if (o.goal)
82
+ held.add(o.goal);
83
+ for (const id of [o.ref, o.about]) {
84
+ const g = id ? goalOf(id) : null;
85
+ if (g)
86
+ held.add(g);
87
+ }
88
+ }
89
+ return held;
90
+ }
91
+ export function settledShape(g, now) {
92
+ if (g.state !== "OPEN" || g.kind === "worklist" || g.held === true)
93
+ return false;
94
+ if (typeof g.last_act !== "string" || !SETTLING_ACTS.has(g.last_act))
95
+ return false;
96
+ if (Array.isArray(g.last_open) && g.last_open.length > 0)
97
+ return false;
98
+ return typeof g.last_at === "number" && Number.isFinite(g.last_at) && now - g.last_at >= SETTLED_QUIET_MS;
99
+ }
100
+ export function isSettled(g, owed, now, goalOf = () => undefined) {
101
+ if (!settledShape(g, now))
102
+ return false;
103
+ const held = owed instanceof Set ? owed : heldGoals(owed, goalOf);
104
+ return !held.has(g.id);
105
+ }
106
+ export const SETTLED_HEADING = "Settled — close it?";
107
+ export function settledCloseBody(member) {
108
+ return `${member} closed this as settled: nothing was owed in it and nothing happened for three days.`;
109
+ }
110
+ export function quietFor(lastAt, now) {
111
+ const d = Math.max(3, Math.floor((now - lastAt) / 86_400_000));
112
+ return `quiet for ${d} days`;
113
+ }
114
+ //# sourceMappingURL=settled.js.map
@@ -59,6 +59,11 @@ export function guideDefaults(profile, cfg) {
59
59
  persona: false,
60
60
  };
61
61
  }
62
+ export function notLoadedWhy(r) {
63
+ return r && typeof r === "object" && r.loaded === false
64
+ ? String(r.reason ?? "the service manager did not load it")
65
+ : null;
66
+ }
62
67
  const andList = (xs) => xs.length < 2 ? xs.join("") : `${xs.slice(0, -1).join(", ")} and ${xs[xs.length - 1]}`;
63
68
  export function optOutsFrom(argv) {
64
69
  return { worker: argv.includes("--no-worker"), notifications: argv.includes("--no-notifications") };
@@ -78,6 +83,16 @@ export function detectBaseBranch(project) {
78
83
  const cur = git("rev-parse", "--abbrev-ref", "HEAD");
79
84
  return cur && cur !== "HEAD" ? cur : null;
80
85
  }
86
+ export function summaryAnswer(raw) {
87
+ if (raw === null)
88
+ return "cancel";
89
+ const k = raw.trim().toLowerCase();
90
+ if (k === "" || k === "y" || k === "yes")
91
+ return "keep";
92
+ if (k === "c" || k === "change")
93
+ return "change";
94
+ return "again";
95
+ }
81
96
  export const ALERT_WORDS = {
82
97
  decisions: "decisions that need you",
83
98
  deliveries: "decisions and deliveries",
@@ -255,6 +270,32 @@ export function catchAllProblem(flagName, words) {
255
270
  `Name the areas one by one from: ${DECISION_AREAS.map((x) => x.id).join(", ")}. ` +
256
271
  `To reserve nothing for yourself: pantheon setup --decides none`;
257
272
  }
273
+ export function teammateSummary(a, o) {
274
+ const alert = ALERT_OPTIONS.find((x) => x.id === a.notifications).label.split(" — ")[0].replace(/ \(recommended\)/, "").toLowerCase();
275
+ const out = [
276
+ "You'll run with:",
277
+ ` • Name: ${a.name}`,
278
+ ` • Role: ${a.title}`,
279
+ ` • Wake: ${a.wake === "no" ? "off — this machine only works while you are at it"
280
+ : !o.serves ? `${a.wake === "anyone" ? "anyone on your team" : "only teammates you approve"} — once a repo or docs folder is bound here (pantheon use <team> --here)`
281
+ : a.wake === "anyone" ? "anyone on your team can hand work to this machine while you're away"
282
+ : "only teammates you approve — you are asked the first time each one needs this machine"}`,
283
+ ];
284
+ if (a.wake !== "no" && o.serves?.repos)
285
+ out.push(` • Commands: ${a.commands ? "on in your repos — a run may run tests, commit and push to its own branch for your review" : "off — a run edits files and answers only"}`);
286
+ if (a.wake !== "no" && o.awayAgents?.length)
287
+ out.push(` • Agent: ${andList(o.awayAgents)} ${o.awayAgents.length === 1 ? "answers" : "answer"} teammates' requests while you're away. ${unsandboxedRisk(andList(o.awayAgents))}`);
288
+ if (a.mode)
289
+ out.push(` • Mode: ${a.mode === "autopilot" ? `autopilot — your agent takes teammates' requests even while you work. ${AUTOPILOT_PLAN_NOTE}` : "here — requests wait while you're at your computer; your agent takes them when you're away"}`);
290
+ out.push(` • Alerts: ${alert}`);
291
+ out.push(` • Approval: ${a.approval === "approve" ? "your agent sends to teammates in your name without asking each time" : "your agent asks you before each send, goal and claim"}`);
292
+ out.push(` • Decisions: ${a.decides.length ? `you personally decide ${a.decides.join(", ")}` : "none reserved for you — add an area when one comes up"}`);
293
+ if (a.wake !== "no" && o.project)
294
+ out.push(` • Playbook: ${a.persona ? "a short starter playbook for your worker, in this repo" : "none"}`);
295
+ if (o.base)
296
+ out.push(` • Base branch: ${o.base}`);
297
+ return out;
298
+ }
258
299
  export async function runGuide(io, ctx, deps = {}, preset = {}) {
259
300
  const optOut = ctx.optOut ?? {};
260
301
  const serves = ctx.project ? { path: ctx.project, repos: true } : ctx.serves ?? null;
@@ -281,7 +322,36 @@ export async function runGuide(io, ctx, deps = {}, preset = {}) {
281
322
  const applied = [], warnings = [];
282
323
  const awayAgents = deps.unsandboxedAgents?.() ?? [];
283
324
  let riskSaid = false;
284
- if (io) {
325
+ let summaryKept = false;
326
+ if (io && ctx.summary && !ctx.founder) {
327
+ const nowMode = preset.mode ?? effectiveMode(loadPolicy(deps.policyHome));
328
+ const base = preset.base;
329
+ const s = { ...a, title: d.title || "Member", mode: nowMode };
330
+ if (s.wake !== "no" && ctx.project)
331
+ s.persona = preset.persona ?? (setUp ? playbookExists : true);
332
+ for (const l of teammateSummary(s, { serves, project: !!ctx.project, base, awayAgents: awayAgents.length && s.wake !== "no" && serves?.repos && unsandboxedAllowed(loadPolicy(deps.policyHome)) ? awayAgents : [] }))
333
+ io.say(l);
334
+ io.say("");
335
+ let said;
336
+ for (;;) {
337
+ const q = "Press Enter to continue, or c to change them";
338
+ said = summaryAnswer(io.answer ? await io.answer(q) : await io.ask(q, ""));
339
+ if (said !== "again")
340
+ break;
341
+ io.say(" Enter (or y) uses these settings; c changes them; Ctrl-C stops without saving the choices on this screen.");
342
+ }
343
+ if (said === "cancel")
344
+ return { answers: a, applied: [], warnings: [], held: true, cancelled: true };
345
+ if (said === "keep") {
346
+ summaryKept = true;
347
+ Object.assign(a, s);
348
+ if (base && (!setUp || preset.base))
349
+ a.base = base;
350
+ if (awayAgents.length && s.wake !== "no" && serves?.repos && unsandboxedAllowed(loadPolicy(deps.policyHome)))
351
+ riskSaid = true;
352
+ }
353
+ }
354
+ if (io && !summaryKept) {
285
355
  io.say("A few questions, then one screen of defaults. Enter keeps the suggested answer.\n");
286
356
  a.name = (await io.ask("Your name, as teammates will see it", d.name)).trim() || d.name;
287
357
  const known = TITLE_OPTIONS.findIndex((t) => t.toLowerCase() === d.title.toLowerCase());
@@ -365,6 +435,8 @@ export async function runGuide(io, ctx, deps = {}, preset = {}) {
365
435
  a.approval = ap === 0 ? "approve" : "ask-before-sending";
366
436
  }
367
437
  }
438
+ if (io?.ended?.())
439
+ return { answers: a, applied: [], warnings: [], held: true, cancelled: true };
368
440
  {
369
441
  const pol = loadPolicy(deps.policyHome);
370
442
  const before = { answers: guideDefaults(profile, ctx.cfg), mode: effectiveMode(pol), unsandboxed: unsandboxedAllowed(pol),
@@ -478,12 +550,15 @@ export async function runGuide(io, ctx, deps = {}, preset = {}) {
478
550
  else if (serves) {
479
551
  try {
480
552
  const now = (deps.installedArgs ?? (deps.installService ? () => null : installedServiceArgs))("worker");
481
- install("worker", serves.path, keepServiceFlags(now, a.commands ? ["--allow-bash"] : [], ["--allow-bash"]));
482
- applied.push(!serves.repos
483
- ? "worker on — a teammate's question is answered from your folder, which a run reads and never changes; anything it writes is a draft for you"
484
- : a.commands
485
- ? "worker on — a woken run may run tests and commit and push to its own branch"
486
- : "worker on — a woken run edits files and answers; it cannot commit or push (deliveries will need you)");
553
+ const why = notLoadedWhy(install("worker", serves.path, keepServiceFlags(now, a.commands ? ["--allow-bash"] : [], ["--allow-bash"])));
554
+ if (why)
555
+ warnings.push(`the worker is installed but not running (${why}) — teammates' requests wait for you until it runs: pantheon service restart worker`);
556
+ else
557
+ applied.push(!serves.repos
558
+ ? "worker on — a teammate's question is answered from your folder, which a run reads and never changes; anything it writes is a draft for you"
559
+ : a.commands
560
+ ? "worker on — a woken run may run tests and commit and push to its own branch"
561
+ : "worker on — a woken run edits files and answers; it cannot commit or push (deliveries will need you)");
487
562
  }
488
563
  catch (e) {
489
564
  warnings.push(`the worker service did not install: ${e.message}`);
@@ -547,7 +622,9 @@ export async function runGuide(io, ctx, deps = {}, preset = {}) {
547
622
  else {
548
623
  if (!installed("notifier") && (linuxDesktop || winDesktop)) {
549
624
  try {
550
- install("notifier", deps.home ?? homedir(), []);
625
+ const why = notLoadedWhy(install("notifier", deps.home ?? homedir(), []));
626
+ if (why)
627
+ warnings.push(`alerts are installed but not running (${why}) — pantheon service restart notifier`);
551
628
  }
552
629
  catch (e) {
553
630
  warnings.push(`alerts did not install: ${e.message}`);
@@ -556,7 +633,9 @@ export async function runGuide(io, ctx, deps = {}, preset = {}) {
556
633
  else if (!installed("notifier")) {
557
634
  if (existsSync(hudBinaryPath(deps.home))) {
558
635
  try {
559
- install("notifier", deps.home ?? homedir(), []);
636
+ const why = notLoadedWhy(install("notifier", deps.home ?? homedir(), []));
637
+ if (why)
638
+ warnings.push(`alerts are installed but not running (${why}) — pantheon service restart notifier`);
560
639
  }
561
640
  catch (e) {
562
641
  warnings.push(`alerts did not install: ${e.message}`);
@@ -635,13 +714,19 @@ export function questionOrNull(rl, q) {
635
714
  });
636
715
  }
637
716
  export function terminalIO(rl, out) {
638
- const ask = async (q) => (await questionOrNull(rl, q)) ?? "";
717
+ let ended = false;
718
+ rl.on?.("SIGINT", () => { ended = true; rl.close?.(); });
719
+ const raw = async (q) => { const v = await questionOrNull(rl, q); if (v === null)
720
+ ended = true; return v; };
721
+ const ask = async (q) => (await raw(q)) ?? "";
639
722
  return {
640
723
  say: out,
724
+ ended: () => ended,
641
725
  async ask(question, def) {
642
726
  const v = await ask(`${question}${def ? ` [${def}]` : ""}: `);
643
727
  return v || def;
644
728
  },
729
+ async answer(question) { return raw(`${question}: `); },
645
730
  async choose(question, options, def) {
646
731
  out(`\n${question}`);
647
732
  options.forEach((o, i) => out(` ${i + 1}) ${o}${i === def ? " ←" : ""}`));