@nanocollective/roster 0.1.0-alpha.9 → 0.1.0-beta.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.
Files changed (145) hide show
  1. package/README.md +5 -0
  2. package/dist/cli.js +4067 -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 +4430 -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,304 @@
1
+ /* Is the scaffolding still there, has the agent been running, and what does lint say. */
2
+
3
+ import { post } from "../api.js";
4
+ import { askYes } from "../dialog.js";
5
+ import { ago, el, esc, kb } from "../dom.js";
6
+ import { inline } from "../md.js";
7
+ import { render } from "../router.js";
8
+ import { S, staff } from "../state.js";
9
+ import { checklist } from "./checklist.js";
10
+ import { amendSheet } from "./prompt.js";
11
+ import { runOnce } from "./runonce.js";
12
+
13
+ const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
14
+
15
+ /** The common cron shapes in plain words; anything unusual is shown as it was written. */
16
+ export function cronText(spec) {
17
+ if (!spec) return "no schedule";
18
+ const p = String(spec).trim().split(/\s+/);
19
+ if (p.length !== 5 || !/^\d+$/.test(p[0]) || !/^\d+$/.test(p[1])) return String(spec);
20
+ const [min, hour, dom, mon, dow] = p;
21
+ const time = hour.padStart(2, "0") + ":" + min.padStart(2, "0") + " UTC";
22
+ if (dom !== "*" || mon !== "*") return String(spec);
23
+ if (dow === "*") return time + " · every day";
24
+ if (dow === "1-5") return time + " · Mon–Fri";
25
+ return time + " · " + dow.split(",").map((d) => DAYS[Number(d) % 7] ?? d).join(", ");
26
+ }
27
+
28
+ export function viewHealth(m) {
29
+ const s = staff();
30
+ const rig = s.rig ?? {};
31
+ m.append(el("h1", { textContent: s.name + " · health" }));
32
+
33
+ m.append(
34
+ el("p", {
35
+ className: "sub",
36
+ textContent:
37
+ "The rig, then three sets of checks: the org, the prompts they are sent, and what " +
38
+ "they have written down.",
39
+ }),
40
+ );
41
+
42
+ /* The rig: is the scaffolding still there, and has the agent actually been running. This
43
+ is everything answerable without the GitHub API — installation grants, secrets and
44
+ rulesets are `roster doctor`'s job, and it does not exist yet. */
45
+ const kv = (k, v, sub, bad) => {
46
+ const d = el("div", { className: "kv" + (bad ? " bad" : "") });
47
+ d.innerHTML = '<div class="k">' + esc(k) + "</div><div class=\"v\">" + v +
48
+ (sub ? "<small>" + esc(sub) + "</small>" : "") + "</div>";
49
+ return d;
50
+ };
51
+
52
+ const g = el("div", { className: "grid", style: "margin-bottom:6px" });
53
+ g.append(kv("Runs", esc(cronText(s.schedule)),
54
+ (rig.workflows ?? []).length + " workflows: " + (rig.workflows ?? []).join(", "),
55
+ !(rig.workflows ?? []).length));
56
+ g.append(rig.lastCommit
57
+ ? kv("Last commit", esc(ago(rig.lastCommit.date)), rig.lastCommit.subject)
58
+ : kv("Last commit", "never", "no git history here", true));
59
+ g.append(rig.lastMemoryCommit
60
+ ? kv("Last thought", esc(ago(rig.lastMemoryCommit.date)), rig.lastMemoryCommit.subject)
61
+ : kv("Last thought", "never", "memory/ has never been committed to", true));
62
+ g.append(kv("Memory", s.facts.length + " facts",
63
+ kb(rig.memoryBytes ?? 0) + " index · " + s.notes.length + " notes, " + kb(rig.notesBytes ?? 0) +
64
+ " · read in full every boot"));
65
+
66
+ const authored = s.links.filter((l) => !l.inferred).length;
67
+ g.append(kv("Links", authored + " authored", (s.links.length - authored) + " more inferred"));
68
+ g.append(kv("Charter", rig.hasCharter === false ? "missing" : "CHARTER.md",
69
+ rig.hasManifest === false ? "staff.yaml is missing too" : "staff.yaml present",
70
+ rig.hasCharter === false || rig.hasManifest === false));
71
+ if (s.statusIssue && s.brain) {
72
+ g.append(kv("Status", '<a class="ref" href="https://github.com/' + esc(s.brain) + "/issues/" +
73
+ s.statusIssue + '" target="_blank" rel="noopener">#' + s.statusIssue + "</a>",
74
+ "the pinned issue this staff member keeps"));
75
+ }
76
+ if ((rig.missingSurfaces ?? []).length) {
77
+ g.append(kv("Surfaces", esc(rig.missingSurfaces.length + " missing"),
78
+ rig.missingSurfaces.join(", ") + " — declared in staff.yaml, not in the repo", true));
79
+ }
80
+ m.append(g);
81
+
82
+ /* Three sets of checks, and they were three different-looking things: hairline rows for
83
+ doctor, bordered boxes for the prompt audit, cards with two buttons each for lint. Same
84
+ question in all three, so one shape: a heading that carries its own count, a line saying
85
+ what the section is, the findings as rows, and the section's actions at the end. */
86
+ /* A workflow that has never run is unproven, and the way to prove it is to run it. Here
87
+ because Health is where "unproven" is read; a success re-runs the checks below. */
88
+ let doctor = null;
89
+ m.append(
90
+ runOnce({
91
+ staff: s.handle,
92
+ name: s.name,
93
+ onDone: (ok) => ok && doctor && checklist(doctor.body, { shell: doctor }),
94
+ }),
95
+ );
96
+
97
+ doctor = section(m, "The org, from roster doctor", "doctor");
98
+ checklist(doctor.body, { shell: doctor });
99
+
100
+ /* What is wrong with what this agent is sent. It used to sit in the tree on the Prompt
101
+ screen, beside the prompt itself — which answers "what is sent", not "is it any good".
102
+ Both questions are health questions, so both are here. */
103
+ const prompt = section(m, "Prompt problems", "prompts");
104
+ promptProblems(prompt, s);
105
+
106
+ memoryProblems(section(m, "Memory problems", "memory"), s);
107
+ }
108
+
109
+ /**
110
+ * One section: a heading with a count, a body, and a row for whatever acts on all of it.
111
+ *
112
+ * Returned rather than built in one go because two of the three fill themselves in later, and
113
+ * a heading that appears with its count already right is worth the small indirection.
114
+ */
115
+ function section(m, title, key) {
116
+ const head = el("div", { className: "hsect" });
117
+ head.append(el("span", { textContent: title }));
118
+ const count = el("i");
119
+ head.append(count);
120
+ const body = el("div", { className: "hbody " + key });
121
+ const actions = el("div", { className: "row hacts" });
122
+ m.append(head, body, actions);
123
+ return {
124
+ body,
125
+ actions,
126
+ /** `n` findings, or a word when a count is the wrong shape of answer. */
127
+ say: (text) => { count.textContent = text; },
128
+ };
129
+ }
130
+
131
+ /** The same checks `roster lint` runs, over what this staff member has written down. */
132
+ function memoryProblems({ body, actions, say }, s) {
133
+ say(s.problems.length ? String(s.problems.length) : "clean");
134
+ body.append(
135
+ el("p", {
136
+ className: "hnote",
137
+ textContent: s.problems.length
138
+ ? "The same checks roster lint runs, over memory/INDEX.md."
139
+ : "Nothing roster lint can fault in memory/INDEX.md.",
140
+ }),
141
+ );
142
+ if (!s.problems.length) return;
143
+
144
+ const list = el("div", { className: "card hlist" });
145
+ body.append(list);
146
+ for (const p of s.problems) {
147
+ const { row, body: text } = finding(
148
+ p.level === "error" ? "error" : "warning",
149
+ { html: inline(p.message) },
150
+ [p.rule, p.line ? "INDEX.md:" + p.line : (p.file ?? "")],
151
+ );
152
+ const status = el("span", { className: "meta" });
153
+ const btn = el("button", { className: "ghbtn", textContent: "Ask " + s.handle.toUpperCase() + " to fix" });
154
+ btn.onclick = () => askToFix(s, [p], btn, status);
155
+ const acts = el("div", { className: "row facts" }, [btn]);
156
+ if (p.slug) {
157
+ const go = el("button", { className: "ghbtn", textContent: "Show the fact" });
158
+ go.onclick = () => { S.openFile = "fact:" + p.slug; S.fileQuery = ""; S.view = "brain"; render(); };
159
+ acts.append(go);
160
+ }
161
+ acts.append(status);
162
+ text.append(acts);
163
+ list.append(row);
164
+ }
165
+
166
+ /* The portal's one power over an agent is that it acts as the human, so "fix this" is an
167
+ issue in their own repo — the same thing you would have typed on GitHub. */
168
+ const allStatus = el("span", { className: "meta" });
169
+ const all = el("button", { className: "ghbtn primary",
170
+ textContent: "Ask " + s.handle.toUpperCase() + " to fix all " + s.problems.length });
171
+ all.onclick = () => askToFix(s, s.problems, all, allStatus);
172
+ actions.append(all, allStatus);
173
+ }
174
+
175
+ /**
176
+ * One finding, in the shape every section uses: a level marker, what is wrong, and where.
177
+ *
178
+ * The marker carries the severity so the words do not have to. A row that opens with the word
179
+ * "warning" spends its first line saying something a glyph already said.
180
+ */
181
+ function finding(level, title, tags) {
182
+ const row = el("div", { className: "check " + (level === "error" ? "fail" : "warn") });
183
+ row.append(el("span", { className: "checkmark", textContent: level === "error" ? "✗" : "!" }));
184
+ const body = el("div");
185
+ // Plain text where there is any, markup only where a message carries its own.
186
+ const head = el("b");
187
+ if (title.html) head.innerHTML = title.html;
188
+ else head.textContent = title.text;
189
+ body.append(head);
190
+ for (const t of tags.filter(Boolean)) {
191
+ body.append(el("span", { className: "meta", textContent: t }));
192
+ }
193
+ row.append(body);
194
+ // Everything else goes in the second column, under the text rather than under the marker.
195
+ return { row, body };
196
+ }
197
+
198
+ /**
199
+ * Everything the audit says about this staff member's prompts, over every kind of run.
200
+ *
201
+ * Fetched rather than read off the export: composing three prompts and diffing their layers is
202
+ * not something to do on every page paint of every screen, and this is the only one that asks.
203
+ */
204
+ async function promptProblems({ body, say }, s) {
205
+ say("…");
206
+ body.append(el("p", { className: "hnote", textContent: "Composing the prompts…" }));
207
+ let data;
208
+ try {
209
+ data = await (
210
+ await fetch("/api/promptaudit?staff=" + encodeURIComponent(s.handle), { cache: "no-store" })
211
+ ).json();
212
+ } catch (e) {
213
+ say("?");
214
+ body.replaceChildren(el("p", { className: "hnote err", textContent: e.message }));
215
+ return;
216
+ }
217
+
218
+ const problems = data.problems ?? [];
219
+ const errors = data.errors ?? [];
220
+ say(problems.length ? String(problems.length) : errors.length ? "?" : "clean");
221
+ body.replaceChildren(
222
+ el("p", {
223
+ className: "hnote",
224
+ textContent: problems.length
225
+ ? "What the audit can be sure about, over every kind of run this staff member has."
226
+ : "Nothing the audit can fault in what this staff member is sent.",
227
+ }),
228
+ );
229
+ for (const bad of errors) {
230
+ body.append(
231
+ el("div", { className: "notice", textContent:
232
+ "The " + bad.kind + " prompt does not compose: " + bad.error }),
233
+ );
234
+ }
235
+ if (!problems.length) return;
236
+
237
+ /* Worst first, and each one carrying the sentence that fixes it. Knowing there is a problem
238
+ is the hard part; writing the paragraph that asks for the change is not. */
239
+ const rank = { error: 0, warning: 1, note: 2 };
240
+ const list = el("div", { className: "card hlist" });
241
+ body.append(list);
242
+ for (const p of [...problems].sort((a, b) => (rank[a.level] ?? 3) - (rank[b.level] ?? 3))) {
243
+ const { row, body: text } = finding(p.level, { text: p.title }, [(p.kinds ?? []).join(", ")]);
244
+ text.append(el("p", { textContent: p.detail }));
245
+
246
+ const note = el("span", { className: "meta" });
247
+ const fix = el("button", { className: "ghbtn", textContent: "Fix this with your AI" });
248
+ fix.onclick = () =>
249
+ amendSheet({ handle: s.handle, name: s.name, kind: p.kind, want: p.want, title: p.title, detail: p.detail });
250
+ const actions = el("div", { className: "row facts" }, [fix]);
251
+ if (p.path) {
252
+ const go = el("button", { className: "ghbtn", textContent: "Open the file" });
253
+ // The file is a layer of a prompt, so it opens where prompts are read.
254
+ go.onclick = () => {
255
+ S.promptKind = p.kind;
256
+ S.promptOpen = p.path;
257
+ S.view = "prompt";
258
+ render();
259
+ };
260
+ actions.append(go);
261
+ }
262
+ actions.append(note);
263
+ text.append(actions);
264
+ list.append(row);
265
+ }
266
+ }
267
+
268
+ /** Open one issue asking this staff member to fix what lint found. */
269
+ export async function askToFix(s, problems, btn, status) {
270
+ if (!s.brain) {
271
+ status.textContent = "no brain repo declared in staff.yaml";
272
+ status.className = "meta err";
273
+ return;
274
+ }
275
+ const one = problems.length === 1 ? problems[0] : null;
276
+ const title = one
277
+ ? "Memory lint: " + one.rule + (one.line ? " at INDEX.md:" + one.line : "")
278
+ : "Memory lint: " + problems.length + " problems in memory/INDEX.md";
279
+ const body = [
280
+ "`roster lint` flags " + (one ? "this" : "these") + " in `memory/INDEX.md`. Opened from the portal.",
281
+ "",
282
+ "| rule | where | what |",
283
+ "|---|---|---|",
284
+ ...problems.map((p) => "| `" + p.rule + "` | " + (p.line ? "INDEX.md:" + p.line : (p.file ?? "—")) + " | " +
285
+ String(p.message).replace(/\|/g, "\\|") + " |"),
286
+ "",
287
+ "Fix in your next session and close this.",
288
+ ].join("\n");
289
+
290
+ if (!(await askYes({ title: "Open an issue in " + s.brain + "?", confirm: "Open it" }))) return;
291
+ btn.disabled = true;
292
+ status.textContent = "opening…";
293
+ status.className = "meta";
294
+ try {
295
+ const r = await post({ action: "create", repo: s.brain, title, body });
296
+ status.innerHTML = 'opened · <a href="' + esc(r.url ?? "") + '" target="_blank" rel="noopener">' +
297
+ esc((r.url ?? "").split("/").slice(-2).join(" #").replace("issues #", "#") || "the issue") + "</a>";
298
+ status.className = "meta ok";
299
+ } catch (e) {
300
+ status.textContent = e.message;
301
+ status.className = "meta err";
302
+ btn.disabled = false;
303
+ }
304
+ }