@nanocollective/roster 0.1.0-alpha.3 → 0.1.0-alpha.31

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.
Files changed (108) hide show
  1. package/README.md +70 -84
  2. package/dist/cli.js +4817 -2374
  3. package/docs/README.md +19 -11
  4. package/docs/agents.md +328 -13
  5. package/docs/architecture.md +13 -5
  6. package/docs/charters/analyst.md +65 -0
  7. package/docs/charters/cmo.md +69 -0
  8. package/docs/charters/community.md +63 -0
  9. package/docs/charters/cto.md +71 -0
  10. package/docs/charters/designer.md +65 -0
  11. package/docs/charters/devops.md +65 -0
  12. package/docs/charters/pm.md +70 -0
  13. package/docs/charters/qa.md +65 -0
  14. package/docs/charters/support.md +60 -0
  15. package/docs/charters/writer.md +63 -0
  16. package/docs/commands.md +95 -11
  17. package/docs/concepts.md +64 -12
  18. package/docs/cost.md +39 -3
  19. package/docs/developing.md +16 -21
  20. package/docs/doctor-codes.md +21 -6
  21. package/docs/export.md +4 -1
  22. package/docs/extending.md +13 -4
  23. package/docs/getting-started.md +133 -79
  24. package/docs/images/brain.jpg +0 -0
  25. package/docs/images/org.jpg +0 -0
  26. package/docs/images/prompt.jpg +0 -0
  27. package/docs/images/setup-org.jpg +0 -0
  28. package/docs/images/setup-plan.jpg +0 -0
  29. package/docs/images/staff.jpg +0 -0
  30. package/docs/manual-steps.md +95 -101
  31. package/docs/memory.md +29 -8
  32. package/docs/org-yaml.md +76 -11
  33. package/docs/portal.md +290 -49
  34. package/docs/prompts.md +77 -11
  35. package/docs/security.md +51 -7
  36. package/docs/session-workflow.md +51 -21
  37. package/docs/staff-yaml.md +17 -7
  38. package/docs/troubleshooting.md +23 -20
  39. package/docs/upgrading.md +9 -3
  40. package/docs/writing-a-charter.md +46 -17
  41. package/package.json +1 -1
  42. package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +7 -0
  43. package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +16 -4
  44. package/templates/brain/CHARTER.md +3 -3
  45. package/templates/brain/README.md +1 -0
  46. package/templates/brain/log/decisions.md +3 -0
  47. package/templates/brain/staff.yaml +0 -1
  48. package/templates/brain/strategy/ideas.md +7 -0
  49. package/templates/briefs/priorities.md +46 -0
  50. package/templates/ops/.github/workflows/session.yaml +117 -40
  51. package/templates/ops/agents.mjs +127 -8
  52. package/templates/ops/compose.mjs +77 -7
  53. package/templates/ops/inflight.mjs +157 -0
  54. package/templates/ops/org/operating.md +21 -7
  55. package/templates/ops/org/voice.md +9 -0
  56. package/templates/ops/prompts/_identity.md +8 -1
  57. package/templates/ops/prompts/_inflight.md +14 -0
  58. package/templates/ops/prompts/_paths.md +2 -1
  59. package/templates/ops/prompts/daily.md +16 -7
  60. package/templates/ops/prompts/mention.md +18 -2
  61. package/templates/ops/run-record.mjs +144 -0
  62. package/templates/portal/css/base.css +245 -64
  63. package/templates/portal/css/brain.css +30 -20
  64. package/templates/portal/css/diff.css +15 -10
  65. package/templates/portal/css/graph.css +12 -7
  66. package/templates/portal/css/health.css +32 -11
  67. package/templates/portal/css/inbox.css +117 -14
  68. package/templates/portal/css/layout.css +114 -41
  69. package/templates/portal/css/markdown.css +57 -15
  70. package/templates/portal/css/runs.css +13 -0
  71. package/templates/portal/css/setup.css +126 -39
  72. package/templates/portal/index.html +25 -3
  73. package/templates/portal/js/api.js +74 -4
  74. package/templates/portal/js/app.js +156 -14
  75. package/templates/portal/js/dialog.js +129 -4
  76. package/templates/portal/js/dom.js +25 -0
  77. package/templates/portal/js/icons.js +45 -1
  78. package/templates/portal/js/inflight.js +18 -0
  79. package/templates/portal/js/lightbox.js +273 -0
  80. package/templates/portal/js/md.js +23 -6
  81. package/templates/portal/js/mdedit.js +84 -0
  82. package/templates/portal/js/mention.js +264 -0
  83. package/templates/portal/js/readiness.js +35 -0
  84. package/templates/portal/js/refresh.js +136 -6
  85. package/templates/portal/js/state.js +59 -8
  86. package/templates/portal/js/views/app.js +24 -7
  87. package/templates/portal/js/views/checklist.js +29 -10
  88. package/templates/portal/js/views/credential.js +84 -0
  89. package/templates/portal/js/views/docs.js +94 -4
  90. package/templates/portal/js/views/files.js +58 -14
  91. package/templates/portal/js/views/graph.js +1 -1
  92. package/templates/portal/js/views/health.js +178 -37
  93. package/templates/portal/js/views/hire.js +583 -0
  94. package/templates/portal/js/views/inbox.js +959 -126
  95. package/templates/portal/js/views/memory.js +16 -1
  96. package/templates/portal/js/views/org.js +124 -104
  97. package/templates/portal/js/views/orgedit.js +234 -0
  98. package/templates/portal/js/views/paste.js +87 -21
  99. package/templates/portal/js/views/prompt.js +61 -67
  100. package/templates/portal/js/views/repos.js +20 -15
  101. package/templates/portal/js/views/runonce.js +94 -0
  102. package/templates/portal/js/views/runs.js +165 -0
  103. package/templates/portal/js/views/setup.js +257 -75
  104. package/templates/portal/js/views/staff.js +157 -182
  105. package/templates/portal/js/views/todo.js +62 -0
  106. package/templates/portal/js/yaml.js +134 -0
  107. package/templates/brain/.github/workflows/%%STAFF%%-pr-mention.yaml +0 -50
  108. package/templates/ops/prompts/pr-mention.md +0 -57
@@ -0,0 +1,35 @@
1
+ /* Whether each staff member can actually run yet.
2
+ *
3
+ * A hire that had its App created but not installed, and no credential, looked finished: the
4
+ * card said so and Getting started went away. This is the one answer every screen asks. */
5
+
6
+ import { getStaffProgress } from "./api.js";
7
+ import { S } from "./state.js";
8
+
9
+ /** What is left for one staff member, as short instructions. Empty when they are ready. */
10
+ export async function whatsLeft(s, fresh = false) {
11
+ const left = [];
12
+ if (s.rig?.charterStub) left.push("write the charter");
13
+ const p = await getStaffProgress(s.handle, fresh).catch(() => ({}));
14
+ if (p.installed === false) left.push(p.app ? "install the GitHub App" : "create the GitHub App");
15
+ if (p.credential === false) left.push("add the agent credential");
16
+ if (p.ran === false) left.push("run once");
17
+ S.readiness = { ...(S.readiness ?? {}), [s.handle]: left };
18
+ return left;
19
+ }
20
+
21
+ /** Every staff member's, then `then` once all have answered. */
22
+ export function checkAll(then) {
23
+ return Promise.all((S.data?.staff ?? []).map((s) => whatsLeft(s))).then(() => then?.());
24
+ }
25
+
26
+ /** The staff with anything left, from what has been checked so far. */
27
+ export function notReady() {
28
+ return (S.data?.staff ?? []).filter((s) => (S.readiness?.[s.handle] ?? []).length);
29
+ }
30
+
31
+ /** "install the GitHub App, add the agent credential and run once" */
32
+ export function sentence(left) {
33
+ if (left.length < 2) return left.join("");
34
+ return left.slice(0, -1).join(", ") + " and " + left.at(-1);
35
+ }
@@ -7,10 +7,75 @@
7
7
  * Its own module because both the shell and the inbox need it, and importing the shell from
8
8
  * a view would make the module graph a ring. */
9
9
 
10
- import { getOrg, getSync } from "./api.js";
10
+ import { getInbox, getOrg, getSync } from "./api.js";
11
11
  import { $, ago, el, esc } from "./dom.js";
12
12
  import { render } from "./router.js";
13
- import { S } from "./state.js";
13
+ import { openCount, openPrCount, S } from "./state.js";
14
+
15
+ /**
16
+ * The inbox, fetched at most once at a time.
17
+ *
18
+ * Two things want it the moment the page opens: the sidebar, which counts what is waiting on
19
+ * you, and the Inbox screen, if that is where the URL landed. Both used to ask separately, and
20
+ * the second one paid a second round trip through every repo on GitHub to learn what the first
21
+ * was already finding out.
22
+ *
23
+ * So the request is shared. `force` always goes to GitHub — it is the refresh button — and
24
+ * everything else takes whatever is in flight or already loaded.
25
+ */
26
+ let inflight = null;
27
+
28
+ export function ensureInbox(force) {
29
+ if (!force && S.inbox) return Promise.resolve(S.inbox);
30
+ if (!force && inflight) return inflight;
31
+ const asked = getInbox(force)
32
+ .then((data) => {
33
+ S.inbox = data;
34
+ if (inflight === asked) inflight = null;
35
+ return data;
36
+ })
37
+ .catch((err) => {
38
+ if (inflight === asked) inflight = null;
39
+ throw err;
40
+ });
41
+ inflight = asked;
42
+ return asked;
43
+ }
44
+
45
+ /**
46
+ * The two sidebar counts, wherever they are asked for.
47
+ *
48
+ * They live here rather than on the Inbox screen because they are the shell's, and because the
49
+ * whole point of this pass is that they are right before anybody has opened that screen. While
50
+ * the first fetch is out they show a placeholder rather than nothing: an empty badge reads as
51
+ * "zero", and zero is a different claim from "still counting".
52
+ */
53
+ export function stampCounts() {
54
+ const waiting = !S.inbox;
55
+ for (const [sel, n] of [
56
+ ["#inboxcount", openCount],
57
+ ["#prcount", openPrCount],
58
+ ]) {
59
+ const slot = document.querySelector(sel);
60
+ if (!slot) continue;
61
+ slot.textContent = waiting ? "" : String(n());
62
+ slot.classList.toggle("wait", waiting);
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Count what is waiting on you without opening the screen that lists it.
68
+ *
69
+ * The badges used to fill in only once something else caused a render with an inbox loaded,
70
+ * which in practice meant "after you visit the Inbox". A sidebar that says nothing until you
71
+ * look at it is not a sidebar.
72
+ */
73
+ export function countInBackground() {
74
+ stampCounts();
75
+ return ensureInbox(false)
76
+ .then(stampCounts)
77
+ .catch(() => stampCounts());
78
+ }
14
79
 
15
80
  export async function refreshAll(soft) {
16
81
  const bar = $("#refreshall");
@@ -21,14 +86,54 @@ export async function refreshAll(soft) {
21
86
  S.sync = await getSync();
22
87
  S.data = await getOrg();
23
88
  S.inbox = null; // the inbox re-fetches itself on next paint
89
+ inflight = null;
24
90
  S.loadedAt = new Date();
25
91
  if (!soft) render();
26
92
  stampLoaded();
93
+ // The badges are now claiming a count from before the sync. Re-ask, and say so meanwhile.
94
+ countInBackground();
95
+ } finally {
96
+ bar?.classList.remove("spin");
97
+ }
98
+ }
99
+
100
+ /**
101
+ * The same thing, for coming back to the tab.
102
+ *
103
+ * Asked for by a focus event rather than by a person, so it has to earn every visible effect.
104
+ * A full refresh drops the inbox, which sends the next paint to GitHub for four seconds and
105
+ * throws away whatever was on screen — including a half-written issue. Almost every focus
106
+ * finds nothing new, so this one syncs, looks, and only then does any of that.
107
+ */
108
+ export async function refreshQuietly() {
109
+ const bar = $("#refreshall");
110
+ bar?.classList.add("spin");
111
+ try {
112
+ S.sync = await getSync();
113
+ const data = await getOrg();
114
+ const changed = shape(data) !== shape(S.data);
115
+ S.data = data;
116
+ S.loadedAt = new Date();
117
+ stampLoaded();
118
+ // Something landed in a checkout: the inbox is stale too, and the screen should say so.
119
+ if (changed || (S.sync?.results ?? []).some((r) => r.pulled)) {
120
+ S.inbox = null;
121
+ inflight = null;
122
+ render();
123
+ countInBackground();
124
+ }
27
125
  } finally {
28
126
  bar?.classList.remove("spin");
29
127
  }
30
128
  }
31
129
 
130
+ /** The export minus its timestamp, which is stamped per request and always differs. */
131
+ function shape(data) {
132
+ if (!data) return "";
133
+ const { generatedAt, ...rest } = data;
134
+ return JSON.stringify(rest);
135
+ }
136
+
32
137
  export function stampLoaded() {
33
138
  const s = $("#loaded");
34
139
  if (s && S.loadedAt) s.textContent = "data " + ago(S.loadedAt.toISOString());
@@ -40,20 +145,45 @@ export function syncNotice() {
40
145
  const stuck = (S.sync?.results ?? []).filter((r) => r.skipped || r.error || r.behind > 0);
41
146
  if (!stuck.length) return null;
42
147
  const d = el("div", { className: "notice" });
43
- d.innerHTML = stuck
148
+ const lines = el("div");
149
+ lines.innerHTML = stuck
44
150
  .map(
45
151
  (r) =>
46
152
  "<b>" + esc(r.dir) + "</b> " +
47
153
  (r.error
48
154
  ? "could not sync: " + esc(r.error)
49
155
  : r.skipped === "dirty"
50
- ? "is " + r.behind + " behind and has uncommitted changes, so it was not pulled"
156
+ ? "is " + r.behind + " behind and has uncommitted changes, so it was not pulled. " +
157
+ "Commit or stash them, then pull."
51
158
  : r.skipped === "diverged"
52
- ? "has diverged (" + r.ahead + " ahead, " + r.behind + " behind)"
159
+ ? "has diverged (" + r.ahead + " ahead, " + r.behind + " behind). " +
160
+ "Push or rebase it by hand: a merge is not this button's to make."
53
161
  : r.skipped === "no-remote"
54
162
  ? "has no remote"
55
- : "is still " + r.behind + " behind"),
163
+ : "is " + r.behind + " behind"),
56
164
  )
57
165
  .join("<br>");
166
+ d.append(lines);
167
+
168
+ /* The same conservative pull `roster portal` runs on a refresh, on demand: fetch, and pull
169
+ only what is clean and fast-forward. It is here because the answer to "commit those and
170
+ pull" should not be to reload the page and hope. */
171
+ const status = el("span", { className: "meta" });
172
+ const pull = el("button", { className: "ghbtn", textContent: "Pull now" });
173
+ pull.onclick = async () => {
174
+ pull.disabled = true;
175
+ status.textContent = "pulling…";
176
+ status.className = "meta";
177
+ S.sync = await getSync();
178
+ const pulled = (S.sync?.results ?? []).filter((r) => r.pulled);
179
+ // Anything that landed is on disk now, so the export and the inbox are both behind it.
180
+ if (pulled.length) await refreshAll(false);
181
+ else {
182
+ pull.disabled = false;
183
+ status.textContent = "nothing could be pulled";
184
+ render();
185
+ }
186
+ };
187
+ d.append(el("div", { className: "row", style: "margin-top:10px" }, [pull, status]));
58
188
  return d;
59
189
  }
@@ -22,18 +22,29 @@ export const VIEWS = [
22
22
  export const VIEW_ALIAS = { memory: "brain" };
23
23
 
24
24
  /** Screens that belong to the org rather than to one staff member. */
25
- export const ORG_WIDE = new Set(["inbox", "org", "staff", "docs"]);
25
+ export const ORG_WIDE = new Set(["setup", "inbox", "prs", "runs", "org", "staff", "docs"]);
26
+
27
+ /** The two screens that read the inbox, and so share its filters and its `?t=` thread. */
28
+ const INBOXY = new Set(["inbox", "prs"]);
26
29
 
27
30
  export const S = {
28
31
  /** The org export from /api/org. Everything the brain screens read comes off this. */
29
32
  data: null,
30
33
  docs: null,
31
34
  inbox: null,
35
+ /** /api/runs. Kept once read: it is minutes of downloads on a cold cache. */
36
+ runs: null,
32
37
  sync: null,
33
38
  loadedAt: null,
39
+ /** The role whose hire list is open on the Staff screen, kept across a refresh. */
40
+ staffOpen: null,
41
+ /** Per staff member, what is left before they can run. See readiness.js. */
42
+ readiness: null,
34
43
 
35
44
  staffHandle: null,
36
- view: "brain",
45
+ /* What is waiting on you, not whose brain you read last. The org-wide screens are where a
46
+ session starts, which is also why the Staff list below them opens folded. */
47
+ view: "inbox",
37
48
  /** The inbox filter box. Brain and "what changed" keep their own, below. */
38
49
  query: "",
39
50
 
@@ -48,13 +59,16 @@ export const S = {
48
59
  changedFilter: "",
49
60
 
50
61
  openDoc: null,
62
+ /** The docs search box. Its own field: the Docs screen keeps it while you read a page. */
63
+ docQuery: "",
51
64
 
52
65
  /** Which kind of run the Prompt screen is showing, and which layer of it is open. */
53
66
  promptKind: "daily",
54
67
  promptOpen: null,
55
68
 
56
- /** Which org-layer file the Org screen is showing. */
69
+ /** Which org-layer file the Org screen is showing, and what it found on disk. */
57
70
  orgOpen: null,
71
+ orgFiles: [],
58
72
 
59
73
  inboxFilter: "",
60
74
  inboxStaff: "",
@@ -67,12 +81,40 @@ export const S = {
67
81
 
68
82
  /* The sidebar badge counts open items, not everything loaded. Once the inbox could show
69
83
  closed work the two stopped being the same number, and a badge that says 135 when 34 things
70
- need you is worse than no badge. */
84
+ need you is worse than no badge. Pull requests are excluded for the same reason: they are
85
+ Pending work's, and counting them here would bill you twice for the same pile. */
71
86
  export const openCount = () =>
72
- (S.inbox?.items ?? []).filter((i) => i.state === "OPEN").length;
87
+ (S.inbox?.items ?? []).filter((i) => i.state === "OPEN" && i.kind !== "pr").length;
88
+
89
+ /** The same, for the screen that is only pull requests. */
90
+ export const openPrCount = () =>
91
+ (S.inbox?.items ?? []).filter((i) => i.state === "OPEN" && i.kind === "pr").length;
73
92
 
74
93
  export const staff = () => S.data.staff.find((s) => s.handle === S.staffHandle) ?? S.data.staff[0];
75
94
 
95
+ /**
96
+ * Everyone the staff answer to.
97
+ *
98
+ * An org can have more than one. `humans` is the list the export sends now; `human` is what a
99
+ * portal whose server predates the list sends, and falling back to it is what keeps the page
100
+ * working across the upgrade rather than showing an org with nobody in it.
101
+ */
102
+ export const humansOf = () =>
103
+ S.data?.humans?.length ? S.data.humans : S.data?.human?.github ? [S.data.human] : [];
104
+
105
+ /** Whether a login is one of them. Assignment to any of them is assignment to "us". */
106
+ export const isHuman = (login) =>
107
+ !!login &&
108
+ humansOf().some((h) => String(h.github ?? "").toLowerCase() === String(login).toLowerCase());
109
+
110
+ /** What to call them collectively, for a filter label or a count. */
111
+ export const humanLabel = () => {
112
+ const humans = humansOf();
113
+ if (!humans.length) return "you";
114
+ if (humans.length === 1) return humans[0].name ?? humans[0].github ?? "you";
115
+ return humans.map((h) => h.name ?? h.github).join(" or ");
116
+ };
117
+
76
118
  export function readHash() {
77
119
  const raw = (location.hash || "").replace(/^#\/?/, "");
78
120
  if (!raw) return null;
@@ -97,7 +139,14 @@ export function writeHash(push) {
97
139
  if (S.applyingHash) return;
98
140
  if (!S.staffHandle && !ORG_WIDE.has(S.view)) return;
99
141
  const params = new URLSearchParams();
100
- const q = S.view === "brain" ? S.fileQuery : S.view === "changed" ? S.changedQuery : S.query;
142
+ const q =
143
+ S.view === "brain"
144
+ ? S.fileQuery
145
+ : S.view === "changed"
146
+ ? S.changedQuery
147
+ : S.view === "docs"
148
+ ? S.docQuery
149
+ : S.query;
101
150
  if (q) params.set("q", q);
102
151
  if (S.view === "brain" && S.openFile) params.set("f", S.openFile);
103
152
  if (S.view === "docs" && S.openDoc) params.set("p", S.openDoc);
@@ -106,7 +155,7 @@ export function writeHash(push) {
106
155
  if (S.promptKind !== "daily") params.set("k", S.promptKind);
107
156
  if (S.promptOpen) params.set("f", S.promptOpen);
108
157
  }
109
- if (S.view === "inbox") {
158
+ if (INBOXY.has(S.view)) {
110
159
  if (S.inboxFilter) params.set("s", S.inboxFilter);
111
160
  if (S.inboxStaff) params.set("w", S.inboxStaff);
112
161
  if (S.inboxState) params.set("x", S.inboxState);
@@ -134,6 +183,8 @@ export function applyHash() {
134
183
  S.openFile = h.f;
135
184
  } else if (S.view === "changed") {
136
185
  S.changedQuery = h.q;
186
+ } else if (S.view === "docs") {
187
+ S.docQuery = h.q;
137
188
  } else {
138
189
  S.query = h.q;
139
190
  }
@@ -146,7 +197,7 @@ export function applyHash() {
146
197
  S.promptOpen = h.f;
147
198
  }
148
199
 
149
- if (S.view === "inbox") {
200
+ if (INBOXY.has(S.view)) {
150
201
  S.inboxFilter = h.s;
151
202
  S.inboxStaff = h.w;
152
203
  S.inboxState = h.x;
@@ -6,8 +6,8 @@
6
6
  * it is one browser, one origin, and nothing extra to explain.
7
7
  *
8
8
  * What it still cannot do is install the App. Installing is a grant of access to specific
9
- * repositories and GitHub asks a human to choose them, which is correct behaviour and should not
10
- * be worked around. */
9
+ * repositories and GitHub asks a human to confirm them, which is correct behaviour and should not
10
+ * be worked around. The link it hands back has the right repos already selected. */
11
11
 
12
12
  import { appResult, startApp } from "../api.js";
13
13
  import { el } from "../dom.js";
@@ -27,8 +27,7 @@ export function appPanel(opts) {
27
27
  }),
28
28
  el("p", {
29
29
  textContent:
30
- "A tab opens, GitHub asks you to confirm, and the App's id and private key go straight " +
31
- "into the repo's secrets. The key is held in memory and never written to disk.",
30
+ "A GitHub tab opens. Confirm there, then come back here to install it.",
32
31
  }),
33
32
  );
34
33
 
@@ -48,6 +47,11 @@ export function appPanel(opts) {
48
47
  it: an App that exists is not a problem, it is a step you have already done. */
49
48
  const note = el("div");
50
49
  note.append(el("p", { className: "err", textContent: String(err.message || err) }));
50
+ if (err.data?.install) {
51
+ note.append(
52
+ el("a", { className: "btn", href: err.data.install, target: "_blank", textContent: "Install it" }),
53
+ );
54
+ }
51
55
  out.replaceChildren(note);
52
56
  return;
53
57
  }
@@ -102,9 +106,21 @@ export function appPanel(opts) {
102
106
  el("p", {
103
107
  className: "sub",
104
108
  textContent:
105
- "Grant it every tracker this staff member writes to, not just their own: the token " +
106
- "is minted organisation-wide and a peer's board is where a brief lands.",
109
+ "The link opens GitHub's install page with the org and the repos already selected: " +
110
+ "this staff member's brain, every peer tracker it writes to, and the product repos. " +
111
+ "Check the list and confirm.",
107
112
  }),
113
+ ...((result.preselected ?? []).length
114
+ ? [el("p", { className: "sub", textContent: "Selected: " + result.preselected.join(", ") })]
115
+ : []),
116
+ ...((result.missing ?? []).length
117
+ ? [
118
+ el("p", {
119
+ className: "err",
120
+ textContent: "Tick these yourself, their ids could not be read: " + result.missing.join(", "),
121
+ }),
122
+ ]
123
+ : []),
108
124
  el("a", {
109
125
  className: "btn primary",
110
126
  href: result.install,
@@ -115,7 +131,8 @@ export function appPanel(opts) {
115
131
  className: "sub",
116
132
  textContent:
117
133
  "Do not verify this by reading the API. It reports what an App declares separately " +
118
- "from what an installation was granted. Only a run that finished proves the chain.",
134
+ "from what an installation was granted. Only a run that finished proves the chain, " +
135
+ "which is what Run once now on the staff card is for.",
119
136
  }),
120
137
  );
121
138
  out.replaceChildren(done);
@@ -9,8 +9,19 @@ import { el, toClipboard } from "../dom.js";
9
9
 
10
10
  const LEVEL_ORDER = { fail: 0, warn: 1, ok: 2 };
11
11
 
12
+ /**
13
+ * @param opts.skip finding ids the caller already shows as a step of its own, so they are not
14
+ * reported twice. With `opts.hideWhenClean`, a list left empty draws nothing at all.
15
+ * @param opts.shell when Health draws this, the section it lives in: `{actions, say}`. The
16
+ * setup screen passes nothing and gets the layout it has always had. Its own screen is a
17
+ * wizard, where a chunky button and a paragraph under it are right; on Health it is one
18
+ * section of four, and has to look like the other three.
19
+ */
12
20
  export async function checklist(host, opts = {}) {
13
- host.replaceChildren(el("p", { className: "sub", textContent: "Checking…" }));
21
+ const inSection = Boolean(opts.shell);
22
+ const btnClass = inSection ? "ghbtn" : "btn";
23
+ const noteClass = inSection ? "hnote" : "sub";
24
+ host.replaceChildren(el("p", { className: noteClass, textContent: "Checking…" }));
14
25
 
15
26
  let report;
16
27
  try {
@@ -23,12 +34,18 @@ export async function checklist(host, opts = {}) {
23
34
  const findings = (report.findings ?? []).slice().sort(
24
35
  (a, b) => (LEVEL_ORDER[a.level] ?? 3) - (LEVEL_ORDER[b.level] ?? 3),
25
36
  );
26
- const bad = findings.filter((f) => f.level !== "ok");
37
+ const skip = new Set(opts.skip ?? []);
38
+ const bad = findings.filter((f) => f.level !== "ok" && !skip.has(f.id));
27
39
 
28
40
  host.replaceChildren();
41
+ if (!bad.length && opts.hideWhenClean) {
42
+ opts.onEmpty?.();
43
+ return;
44
+ }
45
+ opts.shell?.say(bad.length ? String(bad.length) : "clean");
29
46
  host.append(
30
47
  el("p", {
31
- className: "sub",
48
+ className: noteClass,
32
49
  textContent: bad.length
33
50
  ? `${bad.filter((f) => f.level === "fail").length} failing, ${bad.filter((f) => f.level === "warn").length} to look at.` +
34
51
  (report.online ? "" : " Local checks only.")
@@ -51,7 +68,7 @@ export async function checklist(host, opts = {}) {
51
68
 
52
69
  /* The isitagentready move: the findings as instructions, for the agent you already have
53
70
  pointed at this workspace. What only a person can do is deliberately not in that text. */
54
- const copy = el("button", { className: "btn primary", textContent: "Copy all instructions" });
71
+ const copy = el("button", { className: btnClass + " primary", textContent: "Copy all instructions" });
55
72
  const note = el("span", { className: "meta" });
56
73
  copy.onclick = async () => {
57
74
  copy.disabled = true;
@@ -70,17 +87,19 @@ export async function checklist(host, opts = {}) {
70
87
  }
71
88
  };
72
89
 
73
- const again = el("button", { className: "btn", textContent: "Check again" });
90
+ const again = el("button", { className: btnClass, textContent: "Check again" });
74
91
  again.onclick = () => checklist(host, opts);
75
92
 
76
- host.append(el("div", { className: "row" }, [copy, again, note]));
93
+ const feet = opts.shell?.actions ?? host.appendChild(el("div", { className: "row" }));
94
+ if (opts.shell) feet.replaceChildren();
95
+ feet.append(copy, again, note);
77
96
  if (bad.length) {
78
- host.append(
97
+ feet.append(
79
98
  el("p", {
80
- className: "sub",
99
+ className: noteClass,
100
+ style: "flex-basis:100%",
81
101
  textContent:
82
- "Paste it into Cursor, Claude Code or anything else that can edit files here, then " +
83
- "check again. The ids above should be gone.",
102
+ "Paste them into your coding agent, then check again.",
84
103
  }),
85
104
  );
86
105
  }
@@ -0,0 +1,84 @@
1
+ /* The agent's credential, stored once for the org.
2
+ *
3
+ * The value goes from this box to the local server in a POST, and from there to gh on its
4
+ * standard input. It is not kept in the page after it is sent, and nothing echoes it back. */
5
+
6
+ import { getCredential, storeCredential } from "../api.js";
7
+ import { el } from "../dom.js";
8
+
9
+ /** @param opts.bare drawn inside a step that already has a title. `onStatus(done)` hears whether one is stored. */
10
+ export function credentialPanel(opts = {}) {
11
+ const box = el("div", { className: opts.bare ? "" : "manual" });
12
+ if (!opts.bare) box.append(el("b", { textContent: "Agent credential" }));
13
+ const body = el("div");
14
+ box.append(body);
15
+ body.append(el("p", { className: "sub", textContent: "Checking…" }));
16
+
17
+ getCredential()
18
+ .then((c) => {
19
+ opts.onStatus?.(Boolean(c.stored ?? c.orgSecret));
20
+ draw(body, c, opts);
21
+ })
22
+ .catch((err) => body.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) })));
23
+ return box;
24
+ }
25
+
26
+ function draw(body, c, opts = {}) {
27
+ body.replaceChildren();
28
+
29
+ if (!(c.brains ?? []).length) {
30
+ // Inside a step, the step's own hint already says when this opens.
31
+ if (!opts.bare) body.append(el("p", { className: "sub", textContent: "Available after your first hire. You only add it once." }));
32
+ return;
33
+ }
34
+
35
+ const form = el("div", { className: "credform" });
36
+ const input = el("input", { type: "password", placeholder: "Paste it here", autocomplete: "off", className: "textfield" });
37
+ const go = el("button", { className: "btn primary", textContent: "Save" });
38
+ const out = el("div");
39
+ form.append(
40
+ ...(c.howTo ? [el("p", { className: "sub", textContent: "To get one, " + c.howTo })] : []),
41
+ input,
42
+ el("div", { className: "row" }, [go]),
43
+ out,
44
+ );
45
+
46
+ // Stored already, on the org or on every brain repo: say so, and keep replacing it one click away.
47
+ if (c.stored ?? c.orgSecret) {
48
+ const replace = el("button", { className: "ghbtn", textContent: "Replace it" });
49
+ replace.onclick = () => {
50
+ replace.remove();
51
+ form.hidden = false;
52
+ input.focus?.();
53
+ };
54
+ form.hidden = true;
55
+ body.append(el("p", { className: "okline", textContent: "✓ Stored as " + c.name + "." }), replace, form);
56
+ } else {
57
+ body.append(form);
58
+ }
59
+
60
+ go.onclick = async () => {
61
+ const value = String(input.value ?? "").trim();
62
+ if (!value) {
63
+ input.focus?.();
64
+ return;
65
+ }
66
+ go.disabled = true;
67
+ go.textContent = "Saving…";
68
+ try {
69
+ const r = await storeCredential(value, false);
70
+ input.value = "";
71
+ if (!r.ok) throw new Error(r.error);
72
+ opts.onStatus?.(true);
73
+ out.replaceChildren(
74
+ ...(r.fellBack ? [el("p", { className: "sub", textContent: "Saved on each repo instead: " + r.fellBack })] : []),
75
+ el("p", { className: "okline", textContent: "✓ Saved." }),
76
+ );
77
+ } catch (err) {
78
+ out.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
79
+ } finally {
80
+ go.disabled = false;
81
+ go.textContent = "Save";
82
+ }
83
+ };
84
+ }