@intentius/behold 0.29.49 → 0.29.50

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.
@@ -8,6 +8,8 @@
8
8
  // running behold. A gate that needs a signed approval gets a button only when
9
9
  // behold holds that person's key.
10
10
 
11
+ import { HOST_ANSWERS, loosePointTitle, placePoints, pointLines } from "./decision-points.js";
12
+
11
13
  /** Where the approver's name came from, in the words a button's tooltip uses. */
12
14
  const SOURCE_WORDS = {
13
15
  header: "from your sign-in",
@@ -21,37 +23,52 @@ export const HOST_APPROVES = "approve in the host that framed this graph";
21
23
  /**
22
24
  * Cards for a gates answer. `embed` is whether behold is framed; `member`
23
25
  * narrows to one member's gates when a host opened behold on it (the rest are
24
- * counted, not hidden without a word).
26
+ * counted, not hidden without a word). `points` is the points answer (#472):
27
+ * each open question is drawn on the card of the gate that waits on it, and
28
+ * one no waiting gate names gets a card of its own after the gates.
25
29
  */
26
- export function gateCards(answer, { embed = false, member = null } = {}) {
30
+ export function gateCards(answer, { embed = false, member = null, points = null } = {}) {
27
31
  const all = (answer && answer.gates) || [];
28
32
  const shown = member ? all.filter((g) => g.member === member) : all;
33
+ const { byGate, loose } = placePoints((points && points.points) || [], all);
29
34
  const cards = shown.map((g) => {
30
- if (g.override) return overrideCard(g);
31
- const facts = [`${g.approvals.length} of ${g.needed} approval${g.needed === 1 ? "" : "s"}`];
32
- if (g.env) facts.push(`env ${g.env}`);
33
- if (g.planDigest) facts.push(`plan ${shortDigest(g.planDigest)}`);
34
- if (g.approvals.length) facts.push(`approved by ${g.approvals.map((a) => a.principal).join(", ")}`);
35
- const card = {
36
- key: g.key,
37
- member: g.member,
38
- title: `${g.member}: ${g.op} waits at gate ${g.gate}`,
39
- facts: facts.join(" · "),
40
- command: g.approve,
41
- };
42
- if (embed) card.note = HOST_APPROVES;
43
- else Object.assign(card, approveAffordance(g, answer));
35
+ const card = gateCard(g, answer, embed);
36
+ const asks = byGate.get(g.key);
37
+ if (asks) card.points = asks.map((p) => pointLines(p, { embed }));
44
38
  return card;
45
39
  });
40
+ for (const p of loose) cards.push({ key: `point/${p.id}`, member: null, ...pointLines(p, { embed }), title: loosePointTitle(p), point: true });
46
41
  const elsewhere = all.length - shown.length;
47
- return { cards, elsewhere, refusal: (answer && answer.refusal) || null };
42
+ return { cards, elsewhere, refusal: (answer && answer.refusal) || null, pointsRefusal: (points && points.refusal) || null };
43
+ }
44
+
45
+ function gateCard(g, answer, embed) {
46
+ if (g.override) return overrideCard(g);
47
+ // #472: a gate that asks a decision point counts no approvals; its point's quorum decides.
48
+ const facts = g.answer ? [] : [`${g.approvals.length} of ${g.needed} approval${g.needed === 1 ? "" : "s"}`];
49
+ if (g.env) facts.push(`env ${g.env}`);
50
+ if (g.planDigest) facts.push(`plan ${shortDigest(g.planDigest)}`);
51
+ if (g.approvals.length) facts.push(`approved by ${g.approvals.map((a) => a.principal).join(", ")}`);
52
+ const card = {
53
+ key: g.key,
54
+ member: g.member,
55
+ title: g.answer ? `${g.member}: ${g.op} waits at gate ${g.gate} on decision point ${g.answer.point}` : `${g.member}: ${g.op} waits at gate ${g.gate}`,
56
+ facts: facts.join(" · "),
57
+ command: g.approve,
58
+ };
59
+ if (embed) card.note = g.answer ? HOST_ANSWERS : HOST_APPROVES;
60
+ else Object.assign(card, approveAffordance(g, answer));
61
+ return card;
48
62
  }
49
63
 
50
64
  /**
51
65
  * #690: the button, or the note in its place, for a standalone card. The label
52
- * says who the approval is recorded as before the click.
66
+ * says who the approval is recorded as before the click. A gate that waits on
67
+ * a decision point gets no button (#472): `chant approve` refuses it, and the
68
+ * question is answered elsewhere.
53
69
  */
54
70
  export function approveAffordance(g, answer) {
71
+ if (g.answer) return { note: `waits on decision point ${g.answer.point}, which behold doesn't answer. Run ${g.approve}` };
55
72
  const refusal = answer && answer.approverRefusal;
56
73
  if (refusal) return { note: `can't approve here: ${refusal.error}. Run ${g.approve}` };
57
74
  const id = (answer && answer.approverIdentity) || null;