@nanocollective/roster 0.1.0-alpha.9 → 0.1.0-beta.2

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 (145) hide show
  1. package/README.md +6 -0
  2. package/dist/cli.js +4079 -1950
  3. package/dist/worker/assets/assets/css/base.css +312 -0
  4. package/dist/worker/assets/assets/css/brain.css +116 -0
  5. package/dist/worker/assets/assets/css/diff.css +33 -0
  6. package/dist/worker/assets/assets/css/graph.css +39 -0
  7. package/dist/worker/assets/assets/css/health.css +75 -0
  8. package/dist/worker/assets/assets/css/home.css +101 -0
  9. package/dist/worker/assets/assets/css/inbox.css +199 -0
  10. package/dist/worker/assets/assets/css/layout.css +175 -0
  11. package/dist/worker/assets/assets/css/markdown.css +96 -0
  12. package/dist/worker/assets/assets/css/runs.css +13 -0
  13. package/dist/worker/assets/assets/css/search.css +48 -0
  14. package/dist/worker/assets/assets/css/setup.css +194 -0
  15. package/dist/worker/assets/assets/js/api.js +161 -0
  16. package/dist/worker/assets/assets/js/app.js +465 -0
  17. package/dist/worker/assets/assets/js/dialog.js +196 -0
  18. package/dist/worker/assets/assets/js/dom.js +131 -0
  19. package/dist/worker/assets/assets/js/homesort.js +174 -0
  20. package/dist/worker/assets/assets/js/icons.js +142 -0
  21. package/dist/worker/assets/assets/js/inflight.js +18 -0
  22. package/dist/worker/assets/assets/js/lightbox.js +273 -0
  23. package/dist/worker/assets/assets/js/md.js +406 -0
  24. package/dist/worker/assets/assets/js/mdedit.js +84 -0
  25. package/dist/worker/assets/assets/js/mention.js +264 -0
  26. package/dist/worker/assets/assets/js/readiness.js +70 -0
  27. package/dist/worker/assets/assets/js/refresh.js +197 -0
  28. package/dist/worker/assets/assets/js/router.js +20 -0
  29. package/dist/worker/assets/assets/js/search.js +366 -0
  30. package/dist/worker/assets/assets/js/state.js +213 -0
  31. package/dist/worker/assets/assets/js/textdiff.js +96 -0
  32. package/dist/worker/assets/assets/js/views/app.js +145 -0
  33. package/dist/worker/assets/assets/js/views/brain.js +260 -0
  34. package/dist/worker/assets/assets/js/views/changed.js +157 -0
  35. package/dist/worker/assets/assets/js/views/checklist.js +115 -0
  36. package/dist/worker/assets/assets/js/views/credential.js +84 -0
  37. package/dist/worker/assets/assets/js/views/docs.js +174 -0
  38. package/dist/worker/assets/assets/js/views/files.js +139 -0
  39. package/dist/worker/assets/assets/js/views/graph.js +436 -0
  40. package/dist/worker/assets/assets/js/views/health.js +304 -0
  41. package/dist/worker/assets/assets/js/views/hire.js +593 -0
  42. package/dist/worker/assets/assets/js/views/home.js +585 -0
  43. package/dist/worker/assets/assets/js/views/inbox.js +1558 -0
  44. package/dist/worker/assets/assets/js/views/memory.js +150 -0
  45. package/dist/worker/assets/assets/js/views/org.js +195 -0
  46. package/dist/worker/assets/assets/js/views/orgedit.js +240 -0
  47. package/dist/worker/assets/assets/js/views/paste.js +216 -0
  48. package/dist/worker/assets/assets/js/views/prompt.js +457 -0
  49. package/dist/worker/assets/assets/js/views/repos.js +97 -0
  50. package/dist/worker/assets/assets/js/views/runonce.js +94 -0
  51. package/dist/worker/assets/assets/js/views/runs.js +182 -0
  52. package/dist/worker/assets/assets/js/views/setup.js +557 -0
  53. package/dist/worker/assets/assets/js/views/staff.js +291 -0
  54. package/dist/worker/assets/assets/js/views/todo.js +62 -0
  55. package/dist/worker/assets/assets/js/yaml.js +134 -0
  56. package/dist/worker/assets/docs-images/brain.jpg +0 -0
  57. package/dist/worker/assets/docs-images/home.jpg +0 -0
  58. package/dist/worker/assets/docs-images/org.jpg +0 -0
  59. package/dist/worker/assets/docs-images/prompt.jpg +0 -0
  60. package/dist/worker/assets/docs-images/setup-org.jpg +0 -0
  61. package/dist/worker/assets/docs-images/setup-plan.jpg +0 -0
  62. package/dist/worker/assets/docs-images/staff.jpg +0 -0
  63. package/dist/worker/assets/index.html +82 -0
  64. package/dist/worker/index.js +4442 -0
  65. package/docs/README.md +2 -2
  66. package/docs/architecture.md +1 -1
  67. package/docs/charters/analyst.md +65 -0
  68. package/docs/charters/community.md +63 -0
  69. package/docs/charters/designer.md +65 -0
  70. package/docs/charters/devops.md +65 -0
  71. package/docs/charters/pm.md +70 -0
  72. package/docs/charters/qa.md +65 -0
  73. package/docs/charters/writer.md +63 -0
  74. package/docs/commands.md +9 -3
  75. package/docs/concepts.md +33 -20
  76. package/docs/cost.md +3 -3
  77. package/docs/developing.md +27 -9
  78. package/docs/doctor-codes.md +3 -1
  79. package/docs/export.md +2 -0
  80. package/docs/getting-started.md +44 -27
  81. package/docs/hosting.md +89 -43
  82. package/docs/images/brain.jpg +0 -0
  83. package/docs/images/home.jpg +0 -0
  84. package/docs/images/org.jpg +0 -0
  85. package/docs/images/prompt.jpg +0 -0
  86. package/docs/images/staff.jpg +0 -0
  87. package/docs/manual-steps.md +3 -2
  88. package/docs/org-yaml.md +3 -0
  89. package/docs/portal.md +143 -45
  90. package/docs/prompts.md +6 -0
  91. package/docs/security.md +57 -11
  92. package/docs/session-workflow.md +14 -0
  93. package/docs/staff-yaml.md +17 -1
  94. package/docs/upgrading.md +3 -3
  95. package/docs/writing-a-charter.md +19 -6
  96. package/package.json +4 -3
  97. package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +20 -1
  98. package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +53 -13
  99. package/templates/brain/staff.yaml +4 -1
  100. package/templates/briefs/amend.md +4 -3
  101. package/templates/briefs/priorities.md +46 -0
  102. package/templates/ops/.github/workflows/session.yaml +137 -3
  103. package/templates/ops/compose.mjs +35 -8
  104. package/templates/ops/org/operating.md +29 -10
  105. package/templates/ops/prompts/daily.md +23 -4
  106. package/templates/ops/prompts/mention.md +19 -0
  107. package/templates/ops/run-record.mjs +5 -3
  108. package/templates/portal/css/base.css +34 -0
  109. package/templates/portal/css/health.css +14 -1
  110. package/templates/portal/css/home.css +101 -0
  111. package/templates/portal/css/inbox.css +21 -4
  112. package/templates/portal/css/layout.css +29 -3
  113. package/templates/portal/css/markdown.css +19 -0
  114. package/templates/portal/css/search.css +48 -0
  115. package/templates/portal/css/setup.css +79 -4
  116. package/templates/portal/index.html +15 -9
  117. package/templates/portal/js/api.js +30 -4
  118. package/templates/portal/js/app.js +90 -7
  119. package/templates/portal/js/dialog.js +36 -0
  120. package/templates/portal/js/homesort.js +174 -0
  121. package/templates/portal/js/icons.js +41 -0
  122. package/templates/portal/js/inflight.js +18 -0
  123. package/templates/portal/js/md.js +5 -2
  124. package/templates/portal/js/mdedit.js +84 -0
  125. package/templates/portal/js/readiness.js +70 -0
  126. package/templates/portal/js/refresh.js +10 -2
  127. package/templates/portal/js/search.js +366 -0
  128. package/templates/portal/js/state.js +11 -5
  129. package/templates/portal/js/views/app.js +1 -2
  130. package/templates/portal/js/views/brain.js +1 -1
  131. package/templates/portal/js/views/checklist.js +19 -4
  132. package/templates/portal/js/views/credential.js +42 -51
  133. package/templates/portal/js/views/health.js +11 -6
  134. package/templates/portal/js/views/hire.js +593 -0
  135. package/templates/portal/js/views/home.js +585 -0
  136. package/templates/portal/js/views/inbox.js +237 -68
  137. package/templates/portal/js/views/org.js +31 -111
  138. package/templates/portal/js/views/orgedit.js +240 -0
  139. package/templates/portal/js/views/paste.js +111 -66
  140. package/templates/portal/js/views/prompt.js +94 -40
  141. package/templates/portal/js/views/repos.js +10 -10
  142. package/templates/portal/js/views/runs.js +21 -4
  143. package/templates/portal/js/views/setup.js +130 -163
  144. package/templates/portal/js/views/staff.js +181 -301
  145. package/templates/portal/js/views/todo.js +62 -0
@@ -0,0 +1,145 @@
1
+ /* Creating a staff member's GitHub App, from the page you are already on.
2
+ *
3
+ * There is no API that creates a GitHub App. The only route is the manifest flow: post a
4
+ * manifest to a settings page, a human confirms, GitHub hands back a one-time code. `roster app`
5
+ * does that by standing up a second server on 4310; here it runs on the portal's own port, so
6
+ * it is one browser, one origin, and nothing extra to explain.
7
+ *
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 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
+
12
+ import { appResult, startApp } from "../api.js";
13
+ import { el } from "../dom.js";
14
+
15
+ /**
16
+ * @param {{staff: string, name: string, scope?: "private"|"public", onDone?: () => void}} opts
17
+ */
18
+ export function appPanel(opts) {
19
+ const scope = opts.scope ?? "private";
20
+ const box = el("div", { className: "manual" });
21
+ box.append(
22
+ el("b", {
23
+ textContent:
24
+ scope === "public"
25
+ ? "Create the shared public identity"
26
+ : `Create ${opts.name}'s GitHub App`,
27
+ }),
28
+ el("p", {
29
+ textContent:
30
+ "A GitHub tab opens. Confirm there, then come back here to install it.",
31
+ }),
32
+ );
33
+
34
+ const go = el("button", { className: "btn primary", textContent: "Create the App" });
35
+ const out = el("div", { style: "margin-top:9px" });
36
+ box.append(el("div", { className: "row" }, [go]), out);
37
+
38
+ go.onclick = async () => {
39
+ go.disabled = true;
40
+ out.replaceChildren(el("p", { className: "sub", textContent: "Preparing the hand-off…" }));
41
+ let started;
42
+ try {
43
+ started = await startApp(opts.staff, scope);
44
+ } catch (err) {
45
+ go.disabled = false;
46
+ /* The common failure is a name already taken, and the server sends the install URL with
47
+ it: an App that exists is not a problem, it is a step you have already done. */
48
+ const note = el("div");
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
+ }
55
+ out.replaceChildren(note);
56
+ return;
57
+ }
58
+
59
+ window.open(started.start, "_blank");
60
+ out.replaceChildren(
61
+ el("p", {
62
+ className: "sub",
63
+ textContent: "Confirm it in the tab that just opened. This will update when it lands.",
64
+ }),
65
+ );
66
+
67
+ /* GitHub redirects the *other* tab back to this server, so there is no callback to await
68
+ here. Polling for the result the callback recorded is the only thing this tab can do. */
69
+ const started_at = Date.now();
70
+ const tick = async () => {
71
+ let result;
72
+ try {
73
+ result = await appResult(started.state);
74
+ } catch {
75
+ result = { pending: true };
76
+ }
77
+ if (result.pending) {
78
+ if (Date.now() - started_at > 5 * 60 * 1000) {
79
+ out.replaceChildren(
80
+ el("p", {
81
+ className: "sub",
82
+ textContent:
83
+ "Still waiting. If you finished in the other tab and nothing happened here, " +
84
+ "reload — the App may well have been created.",
85
+ }),
86
+ );
87
+ go.disabled = false;
88
+ return;
89
+ }
90
+ setTimeout(tick, 2000);
91
+ return;
92
+ }
93
+
94
+ go.disabled = false;
95
+ if (!result.ok) {
96
+ out.replaceChildren(el("p", { className: "err", textContent: String(result.error) }));
97
+ return;
98
+ }
99
+
100
+ /* The install is the step that most often looks done and is not, so it is the loudest
101
+ thing on the page once the App exists. */
102
+ const done = el("div");
103
+ done.append(
104
+ el("p", { textContent: `${result.slug} created, and its secrets are set.` }),
105
+ el("b", { textContent: "It still has to be installed." }),
106
+ el("p", {
107
+ className: "sub",
108
+ textContent:
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.",
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
+ : []),
124
+ el("a", {
125
+ className: "btn primary",
126
+ href: result.install,
127
+ target: "_blank",
128
+ textContent: "Install it",
129
+ }),
130
+ el("p", {
131
+ className: "sub",
132
+ textContent:
133
+ "Do not verify this by reading the API. It reports what an App declares separately " +
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.",
136
+ }),
137
+ );
138
+ out.replaceChildren(done);
139
+ opts.onDone?.();
140
+ };
141
+ setTimeout(tick, 2000);
142
+ };
143
+
144
+ return box;
145
+ }
@@ -0,0 +1,260 @@
1
+ /* The brain screen.
2
+ *
3
+ * Memory and the file tree were two screens showing one thing, and both manifests already
4
+ * declare `memory/` as a surface with `render: memory`. So it is one screen — but one screen
5
+ * is not one list. The navigator is two boxes, because a parsed memory section and a file on
6
+ * disk are different kinds of thing and the old flat list told them apart only by typeface.
7
+ *
8
+ * The `memory/` surface's own files are folded into Memory rather than repeated under Files:
9
+ * `INDEX.md` is literally what "All facts" renders, and `notes/x.md` is the argument behind a
10
+ * fact. Listing them twice was most of what made this hard to read.
11
+ */
12
+
13
+ import { el, kb } from "../dom.js";
14
+ import { icon } from "../icons.js";
15
+ import { S, staff, writeHash } from "../state.js";
16
+ import { showFile, showGallery } from "./files.js";
17
+ import { showMemory } from "./memory.js";
18
+
19
+ /** Files a brain browser should not offer: placeholders that hold a directory open. */
20
+ const NOISE = new Set([".gitkeep", ".keep", ".DS_Store"]);
21
+
22
+ const isIndex = (path) => path === "memory/INDEX.md";
23
+ const isNote = (path) => path.startsWith("memory/notes/");
24
+
25
+ export function viewBrain(m) {
26
+ const s = staff();
27
+ if (!S.openSurfaces) S.openSurfaces = new Map();
28
+
29
+ const allFiles = s.surfaces.flatMap((x) => x.files).filter((f) => !NOISE.has(base(f.path)));
30
+ const notes = allFiles.filter((f) => isNote(f.path));
31
+ /* What Files is actually for: everything that is not the memory index or a note behind a
32
+ fact, both of which Memory already renders properly. */
33
+ const plain = allFiles.filter((f) => !isIndex(f.path) && !isNote(f.path));
34
+
35
+ m.append(el("h1", { textContent: s.name + " · brain" }));
36
+ m.append(
37
+ el("p", {
38
+ className: "sub",
39
+ textContent:
40
+ s.facts.length + " facts in " + s.sections.length + " sections, " + notes.length +
41
+ " notes · " + plain.length + " other files across " + s.surfaces.length + " surfaces.",
42
+ }),
43
+ );
44
+
45
+ const filter = el("input", {
46
+ type: "search",
47
+ placeholder: "Search facts and files…",
48
+ value: S.fileQuery,
49
+ });
50
+ const count = el("span", { className: "meta" });
51
+ m.append(el("div", { className: "row", style: "margin-bottom:16px" }, [filter, count]));
52
+
53
+ const split = el("div", { className: "split" });
54
+ const tree = el("div", { className: "tree" });
55
+ const viewer = el("div", { className: "viewer" });
56
+ split.append(tree, viewer);
57
+ m.append(split);
58
+
59
+ filter.oninput = () => {
60
+ S.fileQuery = filter.value;
61
+ writeHash(false);
62
+ paintTree();
63
+ };
64
+
65
+ // Memory is where a brain starts, so it is what you land on.
66
+ if (!S.openFile) S.openFile = "mem:*";
67
+ paintTree();
68
+ openBrain(S.openFile);
69
+
70
+ /* ------------------------------ selection ----------------------------- */
71
+
72
+ function pick(key) {
73
+ S.openFile = key;
74
+ writeHash(false);
75
+ markTree();
76
+ openBrain(key);
77
+ }
78
+
79
+ /** Which row is open, and — when a single fact is focused — which section holds it, so
80
+ opening one fact never loses your place in the list above it. */
81
+ function withinKey() {
82
+ if (!S.openFile?.startsWith("fact:")) return null;
83
+ const f = s.facts.find((x) => x.slug === S.openFile.slice(5));
84
+ return f ? "mem:" + f.section : null;
85
+ }
86
+
87
+ /** Applied as a row is built and again when the selection moves without a repaint, so
88
+ picking a fact does not rebuild the tree and throw away its scroll position. */
89
+ function mark(b, within) {
90
+ b.setAttribute("aria-current", String(b.dataset.key === S.openFile));
91
+ if (within && b.dataset.key === within) b.dataset.within = "true";
92
+ else delete b.dataset.within;
93
+ }
94
+
95
+ function markTree() {
96
+ const within = withinKey();
97
+ for (const o of tree.querySelectorAll(".tfile")) mark(o, within);
98
+ }
99
+
100
+ /* -------------------------------- rows -------------------------------- */
101
+
102
+ function row(key, label, right, cls) {
103
+ const b = el("button", { className: "tfile" + (cls ? " " + cls : ""), title: label });
104
+ b.dataset.key = key;
105
+ b.append(el("span", { className: "t", textContent: label }));
106
+ if (right) b.append(el("i", { textContent: right }));
107
+ mark(b, withinKey());
108
+ b.onclick = () => pick(key);
109
+ return b;
110
+ }
111
+
112
+ /** A titled box in the navigator. Two of them: what the agent knows, and what it holds. */
113
+ function group(title, right) {
114
+ const g = el("div", { className: "navgroup" });
115
+ const h = el("div", { className: "ghead", textContent: title });
116
+ if (right) h.append(el("i", { textContent: right }));
117
+ g.append(h);
118
+ return g;
119
+ }
120
+
121
+ /** A folder that unfolds. Big surfaces start closed; a handful of files does not need it. */
122
+ function folder(g, key, label, kids, right) {
123
+ const open = S.openSurfaces.get(key) ?? kids.length <= 12;
124
+ const head = el("button", { className: "tsurface", title: label });
125
+ head.setAttribute("aria-expanded", String(open));
126
+ head.append(
127
+ icon("chevron", "caret"),
128
+ el("span", { className: "t", textContent: label }),
129
+ el("i", { textContent: right ?? String(kids.length) }),
130
+ );
131
+ const box = el("div", { className: "tsfiles" }, kids);
132
+ box.hidden = !open;
133
+ head.onclick = () => {
134
+ const now = !(S.openSurfaces.get(key) ?? kids.length <= 12);
135
+ S.openSurfaces.set(key, now);
136
+ head.setAttribute("aria-expanded", String(now));
137
+ box.hidden = !now;
138
+ };
139
+ g.append(head, box);
140
+ }
141
+
142
+ /* ------------------------------ the tree ------------------------------ */
143
+
144
+ function paintTree() {
145
+ const q = S.fileQuery.trim().toLowerCase();
146
+ tree.replaceChildren();
147
+
148
+ const hits = s.facts.filter((f) => matchesFact(f, q));
149
+ const noteHits = notes.filter((f) => !q || f.path.toLowerCase().includes(q));
150
+ const fileHits = plain.filter((f) => !q || f.path.toLowerCase().includes(q));
151
+
152
+ /* ---- memory ---- */
153
+ const mem = group("What they know", s.facts.length + " facts");
154
+ if (q) {
155
+ for (const f of hits.slice(0, 200)) mem.append(row("fact:" + f.slug, f.slug, "", "tmem"));
156
+ if (!hits.length) {
157
+ mem.append(el("div", { className: "tfile", textContent: "no facts match" }));
158
+ }
159
+ } else {
160
+ mem.append(row("mem:*", "All facts", String(s.facts.length), "tmem"));
161
+ for (const sec of s.sections) {
162
+ const n = s.facts.filter((f) => f.section === sec).length;
163
+ mem.append(row("mem:" + sec, sec, String(n), "tmem"));
164
+ }
165
+ }
166
+ if (noteHits.length) {
167
+ /* Labelled, because "notes" beside a list of memory sections reads as a mystery
168
+ drawer. A note is the argument behind one fact, read only when that fact is in
169
+ play, which is what keeps the index cheap enough to read at every boot. */
170
+ folder(
171
+ mem,
172
+ "notes",
173
+ "notes/ — why a fact holds",
174
+ noteHits.map((f) => row(f.path, base(f.path), kb(f.bytes))),
175
+ String(noteHits.length),
176
+ );
177
+ }
178
+ if (!q && allFiles.some((f) => isIndex(f.path))) {
179
+ mem.append(row("memory/INDEX.md", "INDEX.md — the raw index", "", "tmem"));
180
+ }
181
+ tree.append(mem);
182
+
183
+ /* ---- who they are ----
184
+ CHARTER.md and staff.yaml sit at the brain root and are in no declared surface, so
185
+ the portal could not show either of them. They are the two files that decide what
186
+ this staff member is, which made that a strange gap. */
187
+ if (!q) {
188
+ const id = group("Identity", "");
189
+ id.append(row("CHARTER.md", "CHARTER.md — the personality", "", "tmem"));
190
+ id.append(row("staff.yaml", "staff.yaml — the manifest", "", "tmem"));
191
+ tree.append(id);
192
+ }
193
+
194
+ /* ---- files ---- */
195
+ if (fileHits.length) {
196
+ const fg = group("Files", plain.length + " files");
197
+ for (const surface of s.surfaces) {
198
+ const fs = fileHits.filter((f) => surface.files.some((x) => x.path === f.path));
199
+ if (!fs.length) continue;
200
+ const kids = fs
201
+ .slice(0, 400)
202
+ .map((f) => row(f.path, f.path.replace(surface.path, "") || f.path, kb(f.bytes)));
203
+ // A gallery surface earns one extra row, in words rather than the manifest's jargon.
204
+ if (surface.render === "gallery" && !q) {
205
+ kids.unshift(row("gallery:" + surface.path, "View all as a gallery", ""));
206
+ }
207
+ folder(fg, surface.path, surface.path, kids);
208
+ }
209
+ tree.append(fg);
210
+ }
211
+
212
+ // Counted the same way the subtitle counts, so the two never disagree.
213
+ count.textContent = q
214
+ ? hits.length + " facts, " + noteHits.length + " notes, " + fileHits.length + " files"
215
+ : s.facts.length + " facts, " + notes.length + " notes, " + plain.length + " files";
216
+ if (q && !hits.length && !fileHits.length && !noteHits.length) {
217
+ tree.replaceChildren(el("p", { className: "empty", textContent: "Nothing matches." }));
218
+ }
219
+ markTree();
220
+ }
221
+
222
+ /* ------------------------------ the pane ------------------------------ */
223
+
224
+ function openBrain(key) {
225
+ if (key?.startsWith("gallery:")) {
226
+ const surface = s.surfaces.find((x) => x.path === key.slice(8));
227
+ if (surface) showGallery(viewer, s, surface);
228
+ return;
229
+ }
230
+ if (!key || key.startsWith("mem:") || key.startsWith("fact:")) {
231
+ showMemory(viewer, s, key || "mem:*", pick);
232
+ return;
233
+ }
234
+ const f = allFiles.find((x) => x.path === key) ?? rootFile(key);
235
+ if (!f) {
236
+ viewer.replaceChildren(
237
+ el("p", { className: "empty", textContent: "That file is not in this brain." }),
238
+ );
239
+ return;
240
+ }
241
+ showFile(viewer, s, f, pick);
242
+ }
243
+ }
244
+
245
+ const base = (path) => path.split("/").pop();
246
+
247
+ /* A file at the brain root, which no surface declares. `bytes` and `modified` are only used
248
+ for the header line, and the renderer reads the file itself. */
249
+ const ROOT_FILES = new Set(["CHARTER.md", "staff.yaml", "README.md"]);
250
+ function rootFile(key) {
251
+ if (!ROOT_FILES.has(key)) return null;
252
+ return { path: key, ext: key.split(".").pop().toLowerCase(), bytes: 0, modified: new Date().toISOString() };
253
+ }
254
+
255
+ export function matchesFact(f, q) {
256
+ if (!q) return true;
257
+ return (f.slug + " " + f.statement + " " + (f.consequence ?? "") + " " + (f.section ?? ""))
258
+ .toLowerCase()
259
+ .includes(q);
260
+ }
@@ -0,0 +1,157 @@
1
+ /* What this agent learned and forgot, and the diff that did it. */
2
+
3
+ import { diffUrl } from "../api.js";
4
+ import { el, esc, markCurrent } from "../dom.js";
5
+ import { iconHTML } from "../icons.js";
6
+ import { S, staff, writeHash } from "../state.js";
7
+
8
+ export function viewChanged(m) {
9
+ const s = staff();
10
+ m.append(el("h1", { textContent: s.handle.toUpperCase() + " · what changed" }));
11
+ m.append(el("p", { className: "sub", textContent:
12
+ "What this agent learned and forgot. Click any row to see the diff that did it." }));
13
+
14
+ const filter = el("input", { type: "search", placeholder: "Filter by slug or commit…", value: S.changedQuery });
15
+ const only = el("select");
16
+ only.append(el("option", { value: "", textContent: "Everything" }),
17
+ el("option", { value: "added", textContent: "Learned" }),
18
+ el("option", { value: "removed", textContent: "Forgotten" }));
19
+ only.value = S.changedFilter;
20
+ m.append(el("div", { className: "row", style: "margin-bottom:16px" }, [filter, only]));
21
+
22
+ const split = el("div", { className: "split" });
23
+ const list = el("div", { className: "tree" });
24
+ const viewer = el("div", { className: "viewer" });
25
+ split.append(list, viewer);
26
+ m.append(split);
27
+ viewer.append(el("p", { className: "empty", textContent: "Pick a change." }));
28
+
29
+ filter.oninput = () => { S.changedQuery = filter.value; writeHash(false); paint(); };
30
+ only.onchange = () => { S.changedFilter = only.value; paint(); };
31
+ paint();
32
+
33
+ function paint() {
34
+ const q = S.changedQuery.trim().toLowerCase();
35
+ list.replaceChildren();
36
+
37
+ const facts = s.factsChanged.filter((c) =>
38
+ (!S.changedFilter || c.change === S.changedFilter) &&
39
+ (!q || (c.slug + " " + c.sha).toLowerCase().includes(q)));
40
+
41
+ if (facts.length) {
42
+ const byDay = new Map();
43
+ for (const c of facts) {
44
+ const d = c.date.slice(0, 10);
45
+ if (!byDay.has(d)) byDay.set(d, []);
46
+ byDay.get(d).push(c);
47
+ }
48
+ for (const [day, items] of byDay) {
49
+ list.append(el("div", { className: "tdir", textContent: day }));
50
+ for (const c of items) {
51
+ const b = el("button", { className: "tfile" });
52
+ b.innerHTML = '<span class="chg ' + (c.change === "added" ? "ok" : "err") + '">' +
53
+ iconHTML(c.change === "added" ? "check" : "dash") + '</span><span class="t">' +
54
+ esc(c.slug) + "</span><i>" + esc(c.sha.slice(0, 7)) + "</i>";
55
+ b.onclick = () => { markCurrent(list, b); showDiff(viewer, s, c.sha, "memory/INDEX.md", c.slug); };
56
+ list.append(b);
57
+ }
58
+ }
59
+ }
60
+
61
+ const commits = s.recentCommits.filter((c) => !q || (c.subject + " " + c.sha).toLowerCase().includes(q));
62
+ if (commits.length && !S.changedFilter) {
63
+ list.append(el("div", { className: "tdir", textContent: "commits" }));
64
+ for (const c of commits.slice(0, 25)) {
65
+ const b = el("button", { className: "tfile", title: c.subject });
66
+ b.append(el("span", { className: "t", textContent: c.subject }));
67
+ b.append(el("i", { textContent: c.sha.slice(0, 7) }));
68
+ b.onclick = () => { markCurrent(list, b); showDiff(viewer, s, c.sha, "", null); };
69
+ list.append(b);
70
+ }
71
+ }
72
+
73
+ if (!list.children.length) list.append(el("p", { className: "empty", textContent: "Nothing matches." }));
74
+ }
75
+ }
76
+
77
+ async function showDiff(viewer, s, sha, path, highlight) {
78
+ viewer.replaceChildren(el("p", { className: "empty", textContent: "Loading diff…" }));
79
+ const res = await fetch(diffUrl(s.dir, sha, path));
80
+ if (!res.ok) { viewer.replaceChildren(el("p", { className: "empty err", textContent: "Could not load that diff." })); return; }
81
+ const text = await res.text();
82
+
83
+ // The first line is author\x1fdate\x1fsubject, prepended by the endpoint.
84
+ const nl = text.indexOf("\n");
85
+ const [author, date, subject] = text.slice(0, nl).split("\x1f");
86
+ const body = text.slice(nl + 1);
87
+
88
+ const head = el("div", { style: "margin-bottom:12px" }, [
89
+ el("div", { style: "font-weight:600", textContent: subject ?? sha }),
90
+ el("div", { className: "meta", textContent: sha + " · " + new Date(date).toLocaleString() + " · " + author }),
91
+ ]);
92
+
93
+ viewer.replaceChildren(head, ...renderDiff(body, highlight));
94
+ const focus = viewer.querySelector(".dfocus");
95
+ if (focus && focus.scrollIntoView) focus.scrollIntoView({ block: "center" });
96
+ }
97
+
98
+ /**
99
+ * A unified diff as something you can read: one block per file, coloured rows, and the two
100
+ * line-number gutters git leaves out. The noise git puts between files — index lines, mode
101
+ * changes, the +++/--- pair — is dropped, because the filename is already the heading.
102
+ */
103
+ export function renderDiff(body, highlight) {
104
+ const blocks = [];
105
+ let block = null, oldNo = 0, newNo = 0;
106
+
107
+ const start = (name) => {
108
+ block = { name, added: 0, removed: 0, rows: el("div", { className: "diff" }) };
109
+ blocks.push(block);
110
+ };
111
+ const push = (cls, a, b, text) => {
112
+ if (!block) start("");
113
+ const r = el("div", { className: "dline" + (cls ? " " + cls : "") });
114
+ r.append(el("span", { className: "ln", textContent: a }),
115
+ el("span", { className: "ln", textContent: b }),
116
+ el("span", { className: "tx", textContent: text }));
117
+ // The fact whose change you clicked, marked so the scroll lands on it.
118
+ if (highlight && text.includes("`" + highlight + "`")) r.classList.add("dfocus");
119
+ block.rows.append(r);
120
+ };
121
+
122
+ for (const line of body.split("\n")) {
123
+ if (line.startsWith("diff --git")) {
124
+ const m = /\sb\/(.+)$/.exec(line);
125
+ start(m ? m[1] : line.replace(/^diff --git\s*/, ""));
126
+ continue;
127
+ }
128
+ if (/^(index |--- |\+\+\+ |new file|deleted file|similarity |rename |old mode|new mode|Binary )/.test(line)) continue;
129
+
130
+ const hunk = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/.exec(line);
131
+ if (hunk) {
132
+ oldNo = Number(hunk[1]);
133
+ newNo = Number(hunk[2]);
134
+ push("dhunk", "", "", (hunk[3] || "").trim() || "@@");
135
+ continue;
136
+ }
137
+ if (!line) continue; // a blank context line is " ", not ""
138
+ if (line.startsWith("+")) { push("dadd", "", String(newNo++), line.slice(1)); block.added++; continue; }
139
+ if (line.startsWith("-")) { push("ddel", String(oldNo++), "", line.slice(1)); block.removed++; continue; }
140
+ if (line.startsWith("\\")) { push("dmeta", "", "", line); continue; }
141
+ push("", String(oldNo++), String(newNo++), line.slice(1));
142
+ }
143
+
144
+ if (!blocks.length) {
145
+ return [el("p", { className: "dempty", textContent: "This commit changed nothing in that file." })];
146
+ }
147
+
148
+ return blocks.map((b) => {
149
+ const wrap = el("div", { className: "dblock" });
150
+ const h = el("div", { className: "dfile" });
151
+ h.innerHTML = "<b>" + esc(b.name || "changes") + "</b>" +
152
+ '<span class="p">+' + b.added + "</span>" +
153
+ '<span class="m">−' + b.removed + "</span>";
154
+ wrap.append(h, b.rows);
155
+ return wrap;
156
+ });
157
+ }
@@ -0,0 +1,115 @@
1
+ /* What is still wrong, and one button that hands it all to a coding agent.
2
+ *
3
+ * Derived from `roster doctor` every time it is drawn. Nothing here remembers that you clicked
4
+ * something: setup takes days, not minutes, and a stored step counter would disagree with the
5
+ * world about five minutes after it was written. */
6
+
7
+ import { getDoctor, getFix } from "../api.js";
8
+ import { el, toClipboard } from "../dom.js";
9
+ import { S } from "../state.js";
10
+
11
+ const LEVEL_ORDER = { fail: 0, warn: 1, ok: 2 };
12
+
13
+ /**
14
+ * @param opts.skip finding ids the caller already shows as a step of its own, so they are not
15
+ * reported twice. With `opts.hideWhenClean`, a list left empty draws nothing at all.
16
+ * @param opts.shell when Health draws this, the section it lives in: `{actions, say}`. The
17
+ * setup screen passes nothing and gets the layout it has always had. Its own screen is a
18
+ * wizard, where a chunky button and a paragraph under it are right; on Health it is one
19
+ * section of four, and has to look like the other three.
20
+ */
21
+ export async function checklist(host, opts = {}) {
22
+ const inSection = Boolean(opts.shell);
23
+ const btnClass = inSection ? "ghbtn" : "btn";
24
+ const noteClass = inSection ? "hnote" : "sub";
25
+ /* Doctor reads the checkout and the org's secrets, so it runs where the checkout is. */
26
+ if (S.hosted) {
27
+ opts.shell?.say("on your machine");
28
+ host.replaceChildren(
29
+ el("p", { className: noteClass, textContent: "Run roster doctor in your workspace." }),
30
+ );
31
+ return;
32
+ }
33
+ host.replaceChildren(el("p", { className: noteClass, textContent: "Checking…" }));
34
+
35
+ let report;
36
+ try {
37
+ report = await getDoctor(opts.offline);
38
+ } catch (err) {
39
+ host.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
40
+ return;
41
+ }
42
+
43
+ const findings = (report.findings ?? []).slice().sort(
44
+ (a, b) => (LEVEL_ORDER[a.level] ?? 3) - (LEVEL_ORDER[b.level] ?? 3),
45
+ );
46
+ const skip = new Set(opts.skip ?? []);
47
+ const bad = findings.filter((f) => f.level !== "ok" && !skip.has(f.id));
48
+
49
+ host.replaceChildren();
50
+ if (!bad.length && opts.hideWhenClean) {
51
+ opts.onEmpty?.();
52
+ return;
53
+ }
54
+ opts.shell?.say(bad.length ? String(bad.length) : "clean");
55
+ host.append(
56
+ el("p", {
57
+ className: noteClass,
58
+ textContent: bad.length
59
+ ? `${bad.filter((f) => f.level === "fail").length} failing, ${bad.filter((f) => f.level === "warn").length} to look at.` +
60
+ (report.online ? "" : " Local checks only.")
61
+ : "Everything doctor checks is clean." + (report.online ? "" : " Local checks only."),
62
+ }),
63
+ );
64
+
65
+ for (const f of bad) {
66
+ const row = el("div", { className: "check " + f.level });
67
+ row.append(
68
+ el("span", { className: "checkmark", textContent: f.level === "fail" ? "✗" : "!" }),
69
+ el("div", {}, [
70
+ el("b", { textContent: f.title }),
71
+ el("span", { className: "meta", textContent: f.scope + " · " + f.id }),
72
+ ...(f.fix ? [el("p", { textContent: f.fix })] : []),
73
+ ]),
74
+ );
75
+ host.append(row);
76
+ }
77
+
78
+ /* The isitagentready move: the findings as instructions, for the agent you already have
79
+ pointed at this workspace. What only a person can do is deliberately not in that text. */
80
+ const copy = el("button", { className: btnClass + " primary", textContent: "Copy all instructions" });
81
+ const note = el("span", { className: "meta" });
82
+ copy.onclick = async () => {
83
+ copy.disabled = true;
84
+ copy.textContent = "Collecting…";
85
+ try {
86
+ const data = await getFix(opts.offline);
87
+ const mine = (data.items ?? []).filter((i) => i.who === "agent").length;
88
+ const yours = (data.items ?? []).filter((i) => i.who === "human").length;
89
+ await toClipboard(data.text, copy, "Copied");
90
+ note.textContent =
91
+ `${mine} for your agent` + (yours ? `, ${yours} only you can do (listed, not asked for)` : "");
92
+ } catch (err) {
93
+ note.textContent = String(err.message || err);
94
+ } finally {
95
+ copy.disabled = false;
96
+ }
97
+ };
98
+
99
+ const again = el("button", { className: btnClass, textContent: "Check again" });
100
+ again.onclick = () => checklist(host, opts);
101
+
102
+ const feet = opts.shell?.actions ?? host.appendChild(el("div", { className: "row" }));
103
+ if (opts.shell) feet.replaceChildren();
104
+ feet.append(copy, again, note);
105
+ if (bad.length) {
106
+ feet.append(
107
+ el("p", {
108
+ className: noteClass,
109
+ style: "flex-basis:100%",
110
+ textContent:
111
+ "Paste them into your coding agent, then check again.",
112
+ }),
113
+ );
114
+ }
115
+ }