@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
@@ -14,38 +14,33 @@
14
14
  * wrong. The server validates it before writing.
15
15
  */
16
16
 
17
- import { getFile, getOrgLayer, post } from "../api.js";
18
- import { askYes } from "../dialog.js";
19
- import { el, esc, grow, kb, skeleton } from "../dom.js";
20
- import { icon } from "../icons.js";
17
+ import { getFile, getOrgLayer } from "../api.js";
18
+ import { el, esc, kb, skeleton } from "../dom.js";
21
19
  import { mdlite } from "../md.js";
22
20
  import { humansOf, S, writeHash } from "../state.js";
23
21
  import { yamlPre } from "../yaml.js";
22
+ import { businessForm, fileModes, prioritiesForm } from "./orgedit.js";
24
23
  import { repoPicker } from "./repos.js";
25
24
 
26
25
  /* What the files roster itself ships are for, in one line each. A filename says nothing about
27
26
  which one to open; anything a tenant has added of its own falls back to its first heading. */
28
27
  const KNOWN = {
29
- "org.yaml": "Who and what: the humans, the repos, the defaults, which agent runs them.",
30
- "org/business.md":
31
- "What the business actually is. Every prompt is composed on top of it, and it is the file that stops the agents writing generic slop.",
32
- "org/priorities.md":
33
- "What matters this month, ranked, and what is out of scope. Every daily run reads it, and every PR says which priority it serves.",
34
- "org/operating.md":
35
- "The autonomy contract: what they do without asking, what they escalate, how a run starts and ends.",
36
- "org/guardrails.md":
37
- "The non-negotiables. Every staff member is bound by these and cannot argue with them.",
38
- "org/voice.md":
39
- "How everything they write reads. Change it once, and every surface changes on the next run.",
40
- "prompts/daily.md": "The whole of a scheduled run, before the fragments are pulled into it.",
41
- "prompts/mention.md": "What they are sent when you @-mention them.",
42
- "prompts/_identity.md": "Who they post as, and what wakes you.",
43
- "prompts/_paths.md": "Where everything is in the runner's checkout.",
28
+ "org.yaml": "The people, repos, defaults and coding agent.",
29
+ "org/business.md": "What the business is. Every staff member reads it.",
30
+ "org/priorities.md": "This month's priorities, in order, and what's out of scope.",
31
+ "org/operating.md": "What staff do on their own, what they ask about, and how a run starts and ends.",
32
+ "org/guardrails.md": "Rules every staff member must follow.",
33
+ "org/voice.md": "How staff write.",
34
+ "prompts/daily.md": "The instructions for a scheduled run.",
35
+ "prompts/mention.md": "The instructions when you @-mention someone.",
36
+ "prompts/_identity.md": "Who staff post as.",
37
+ "prompts/_paths.md": "Where files are during a run.",
38
+ "prompts/_inflight.md": "Pull requests people have open, so staff don't work on the same files.",
44
39
  };
45
40
 
46
41
  const GROUPS = [
47
- ["org", "The org layer", "Inherited by everybody, on their next run."],
48
- ["prompts", "The prompts", "The runs themselves. Edit these last: they are the framework's."],
42
+ ["org", "Org files", "Every staff member reads these."],
43
+ ["prompts", "Prompts", "Roster's run instructions. Upgrades may change them."],
49
44
  ];
50
45
 
51
46
  export function viewOrg(m) {
@@ -55,8 +50,7 @@ export function viewOrg(m) {
55
50
  el("p", {
56
51
  className: "sub",
57
52
  textContent:
58
- "The layer every staff member inherits. Editing one of these reaches all " +
59
- org.staff.length + " of them on their next run.",
53
+ "Files every staff member reads. Changes apply from their next run.",
60
54
  }),
61
55
  );
62
56
 
@@ -170,99 +164,25 @@ export function viewOrg(m) {
170
164
  viewer.replaceChildren();
171
165
  const head = el("div", { className: "row filehead" });
172
166
  head.append(el("span", { className: "meta", textContent: full(path) + " · " + kb(text.length) }));
173
- /* The edit control used to be a word in a row of grey text, which is why "there is no easy
174
- way to edit the org docs" was a fair thing to say about a screen that could edit them. */
175
- const edit = el("button", { className: "ghbtn primary editbtn", onclick: () => editor(path, text) });
176
- edit.append(icon("edit", "ic"), el("span", { textContent: "Edit" }));
177
- head.append(edit);
178
167
  const file = S.orgFiles.find((f) => f.path === path) ?? { path };
179
- viewer.append(head, el("p", { className: "factsub", textContent: why(file) }));
180
-
181
- if (path.endsWith(".yaml") || path.endsWith(".yml")) {
182
- viewer.append(yamlPre(text));
183
- return;
184
- }
185
- viewer.append(el("div", { className: "md doc", innerHTML: mdlite(text) }));
186
- }
187
168
 
188
- function editor(path, text) {
189
- viewer.replaceChildren();
190
169
  const isYaml = /\.ya?ml$/.test(path);
191
-
192
- const status = el("span", { className: "meta" });
193
- const save = el("button", { className: "ghbtn primary", textContent: "Save and commit" });
194
- const cancel = el("button", { className: "ghbtn", textContent: "Cancel" });
195
-
196
- const bar = el("div", { className: "row filehead" });
197
- bar.append(el("span", { className: "meta", textContent: full(path) }), save, cancel, status);
198
- viewer.append(bar);
199
-
200
- const ta = el("textarea", { value: text, className: "editor" });
201
- viewer.append(ta);
202
- grow(ta);
203
- ta.addEventListener("input", () => grow(ta));
204
- // ⌘S is what a person's hands do in a text box. Without it, saving means finding a button
205
- // above a screenful of textarea you have just scrolled past.
206
- ta.addEventListener("keydown", (e) => {
207
- if ((e.metaKey || e.ctrlKey) && e.key === "s") {
208
- e.preventDefault();
209
- commit();
210
- }
211
- });
212
- ta.focus?.();
213
-
214
- cancel.onclick = () => render(path, text);
215
- save.onclick = commit;
216
-
170
+ /* Every file opens on Read, with the ways to change it as tabs beside it: the same ones
171
+ Getting started offers, because a file is no easier to write after setup than during it.
172
+ org.yaml is checked by the server before it is written, so a bad one is refused. */
173
+ viewer.append(head, el("p", { className: "factsub", textContent: why(file) }));
174
+ const read = {
175
+ label: "Read",
176
+ node: isYaml ? yamlPre(text) : el("div", { className: "md doc", innerHTML: mdlite(text) }),
177
+ };
178
+ const o = { path: full(path), name: S.data.name, text, before: [read], onSaved: () => show(path) };
217
179
  viewer.append(
218
- el("p", {
219
- className: "editnote",
220
- textContent:
221
- "⌘S saves. Commits to " + S.data.opsName + " and pushes, and every staff member picks " +
222
- "it up on their next run." +
223
- (isYaml
224
- ? " org.yaml is checked before it is written: bad YAML, or a missing org or name, is refused rather than committed."
225
- : ""),
226
- }),
180
+ path === "org/business.md"
181
+ ? businessForm(o)
182
+ : path === "org/priorities.md"
183
+ ? prioritiesForm(o)
184
+ : fileModes({ ...o, lang: isYaml ? "yaml" : "md" }),
227
185
  );
228
-
229
- async function commit() {
230
- if (ta.value === text) {
231
- status.textContent = "nothing changed";
232
- status.className = "meta";
233
- return;
234
- }
235
- /* Only the manifest asks. A prose edit is one commit to revert and the agents pick it up
236
- on their next run; org.yaml is the file that can stop every prompt composing, and the
237
- portal has just told you it validates it. Asking every time taught people to click
238
- through the question, which is worse than not asking. */
239
- if (
240
- isYaml &&
241
- !(await askYes({
242
- title: "Commit " + full(path) + " and push?",
243
- hint: "Every staff member picks this up on their next run.",
244
- confirm: "Commit and push",
245
- }))
246
- ) {
247
- return;
248
- }
249
- save.disabled = cancel.disabled = true;
250
- status.textContent = "committing…";
251
- status.className = "meta";
252
- try {
253
- const r = await post({ path: full(path), text: ta.value }, "/api/save");
254
- status.textContent = r.pushed
255
- ? "committed and pushed · " + r.sha
256
- : "committed " + r.sha + ", but the push failed: " + (r.note ?? "");
257
- status.className = r.pushed ? "meta ok" : "meta warn";
258
- render(path, ta.value);
259
- } catch (e) {
260
- // A refused org.yaml is the interesting case: the reason is the whole message.
261
- status.textContent = e.message;
262
- status.className = "meta err";
263
- save.disabled = cancel.disabled = false;
264
- }
265
- }
266
186
  }
267
187
  }
268
188
 
@@ -0,0 +1,240 @@
1
+ /* Ways to write the two org files a person has to write, shared by Getting started and the Org
2
+ * screen: plain questions, an AI interview, or the file itself. Each is one tab of a switcher,
3
+ * so the choice is visible rather than folded under a Save button. */
4
+
5
+ import { fileUrl, saveFile } from "../api.js";
6
+ import { el, grow } from "../dom.js";
7
+ import { highlighted } from "../mdedit.js";
8
+ import { paste } from "./paste.js";
9
+
10
+ const BUSINESS_QUESTIONS = [
11
+ ["line", "What does it do, in one line?", "What this business does, in one line", true],
12
+ ["who", "Who is it for?", "Who the customers are, specifically", true],
13
+ ["key", "What does everything depend on?", "The one fact everything else follows from", false],
14
+ ["true", "What's already true? What's built, measured or tried?", "What is already true", false],
15
+ ["not", "What should staff never decide on their own?", "What is not ours to decide", false],
16
+ ];
17
+
18
+ const val = (input) => String(input.value ?? "").trim();
19
+
20
+ /* A file still in the shape it shipped in holds the questions, not answers, and pre-filling the
21
+ fields with "Not a segment. The person…" reads as if somebody had already answered them. */
22
+ const isStub = (text) => /This file is a stub|Or answer these by hand/.test(text);
23
+
24
+ /**
25
+ * org/business.md as five questions. With `text`, the answers already in the file fill the
26
+ * fields, so changing one answer does not mean retyping the other four.
27
+ * @param {{path: string, name: string, text?: string, onSaved: () => void, before?: object[]}} o
28
+ * `before` puts extra tabs ahead of the three, which is how the Org screen adds Read.
29
+ */
30
+ export function businessForm(o) {
31
+ const form = el("div");
32
+ const known = isStub(o.text ?? "") ? new Map() : sections(o.text ?? "");
33
+ const fields = BUSINESS_QUESTIONS.map(([id, label, heading, required]) => {
34
+ const input = id === "line" ? el("input", { type: "text" }) : el("textarea", { className: "pastebox", rows: 3 });
35
+ const had = known.get(heading.toLowerCase());
36
+ if (had) input.value = had.replace(/^>\s?/gm, "");
37
+ return { id, input, wrap: el("label", { className: "qfield" }, [el("span", { textContent: label + (required ? "" : " (optional)") }), input]) };
38
+ });
39
+ const save = el("button", { className: "btn primary", textContent: "Save" });
40
+ const out = el("div");
41
+ form.append(...fields.map((f) => f.wrap), el("div", { className: "row" }, [save]), out);
42
+
43
+ save.onclick = async () => {
44
+ const missing = fields.find((f, i) => BUSINESS_QUESTIONS[i][3] && !val(f.input));
45
+ if (missing) {
46
+ missing.input.focus?.();
47
+ out.replaceChildren(el("p", { className: "err", textContent: "Answer the first two at least." }));
48
+ return;
49
+ }
50
+ const text =
51
+ `# What ${o.name} is\n\n` +
52
+ fields
53
+ .map((f, i) => [BUSINESS_QUESTIONS[i][2], val(f.input)])
54
+ .filter(([, v]) => v)
55
+ .map(([h, v]) => `## ${h}\n\n${v}\n`)
56
+ .join("\n");
57
+ await saveAndSay(save, out, o.path, text, "portal: write org/business.md", o.onSaved);
58
+ };
59
+
60
+ return modes([
61
+ ...(o.before ?? []),
62
+ { label: "Answer questions", node: form },
63
+ { label: "Let an AI interview you", node: paste({ kind: "discover", title: "", onSaved: o.onSaved }) },
64
+ rawMode(o.path, o.onSaved),
65
+ ]);
66
+ }
67
+
68
+ /** org/priorities.md as three lines and an out-of-scope list, filled from the file if it has them. */
69
+ export function prioritiesForm(o) {
70
+ const form = el("div");
71
+ const { items, outs } = isStub(o.text ?? "") ? { items: [], outs: [] } : parsePriorities(o.text ?? "");
72
+ const ranks = [1, 2, 3].map((i) => {
73
+ const input = el("input", { type: "text", placeholder: i === 1 ? "e.g. Tasks can be ticked off and removed" : "" });
74
+ if (items[i - 1]) input.value = items[i - 1];
75
+ return { input, wrap: el("label", { className: "qfield" }, [el("span", { textContent: "Priority " + i + (i > 1 ? " (optional)" : "") }), input]) };
76
+ });
77
+ const scope = el("textarea", { className: "pastebox", rows: 3, placeholder: "One per line" });
78
+ if (outs.length) scope.value = outs.join("\n");
79
+ const save = el("button", { className: "btn primary", textContent: "Save" });
80
+ const out = el("div");
81
+ form.append(
82
+ ...ranks.map((r) => r.wrap),
83
+ el("label", { className: "qfield" }, [el("span", { textContent: "Out of scope this month (optional)" }), scope]),
84
+ el("div", { className: "row" }, [save]),
85
+ out,
86
+ );
87
+ save.onclick = async () => {
88
+ const list = ranks.map((r) => val(r.input)).filter(Boolean);
89
+ if (!list.length) {
90
+ ranks[0].input.focus?.();
91
+ out.replaceChildren(el("p", { className: "err", textContent: "Add at least one priority." }));
92
+ return;
93
+ }
94
+ const scoped = val(scope).split("\n").map((l) => l.replace(/^[-*]\s*/, "").trim()).filter(Boolean);
95
+ const text =
96
+ "## What matters this month\n\n### Priorities, in order\n\n" +
97
+ list.map((t, i) => `${i + 1}. ${t}`).join("\n") +
98
+ "\n" +
99
+ (scoped.length ? "\n### Out of scope this month\n\n" + scoped.map((t) => `- ${t}`).join("\n") + "\n" : "");
100
+ await saveAndSay(save, out, o.path, text, "portal: write org/priorities.md", o.onSaved);
101
+ };
102
+ return modes([
103
+ ...(o.before ?? []),
104
+ { label: "Fill in", node: form },
105
+ { label: "Let an AI interview you", node: paste({ kind: "priorities", title: "", onSaved: o.onSaved }) },
106
+ rawMode(o.path, o.onSaved),
107
+ ]);
108
+ }
109
+
110
+ /** Any org file as highlighted text, with Read ahead of it on the Org screen. */
111
+ export function fileModes(o) {
112
+ return modes([...(o.before ?? []), rawMode(o.path, o.onSaved, o.lang)]);
113
+ }
114
+
115
+ /**
116
+ * The file itself, for editing what is already there rather than starting again.
117
+ * @param {{label?: string, note?: string, read?: () => Promise<string>}} o
118
+ * `read` starts the editor from other text than the file, once, so switching tabs does not
119
+ * throw away what was typed. `note` is a line above the editor.
120
+ */
121
+ export function rawMode(path, onSaved, lang = "md", o = {}) {
122
+ const node = el("div");
123
+ if (o.note) node.append(el("p", { className: "sub", textContent: o.note }));
124
+ const ta = el("textarea", { className: "pastebox" });
125
+ ta.rows = 12;
126
+ const save = el("button", { className: "btn primary", textContent: "Save" });
127
+ const out = el("div");
128
+ const hl = highlighted(ta, lang);
129
+ node.append(hl, el("div", { className: "row" }, [save]), out);
130
+ ta.addEventListener("input", () => grow(ta));
131
+ // What the file held when it was read, so a save can say what it is replacing.
132
+ let base;
133
+ const commit = () =>
134
+ saveAndSay(save, out, path, ta.value, "portal: edit " + path.split("/").slice(1).join("/"), () => {
135
+ base = ta.value;
136
+ onSaved?.();
137
+ }, base);
138
+ save.onclick = commit;
139
+ // ⌘S is what a person's hands do in a text box.
140
+ ta.addEventListener("keydown", (e) => {
141
+ if ((e.metaKey || e.ctrlKey) && e.key === "s") {
142
+ e.preventDefault();
143
+ commit();
144
+ }
145
+ });
146
+ // Read when first shown, so it shows the file as it is then, not as it was at page load.
147
+ let read = false;
148
+ const load = () => {
149
+ if (o.read && read) return;
150
+ read = true;
151
+ return (
152
+ o.read
153
+ ? o.read()
154
+ : // Not getFile: an absent file answers 404 with a message, and that is not what to edit.
155
+ fetch(fileUrl(path), { cache: "no-store" }).then((r) => (r.ok ? r.text() : ""))
156
+ ).then((text) => {
157
+ if (!o.read) base = text;
158
+ ta.value = text;
159
+ grow(ta);
160
+ hl.repaint();
161
+ });
162
+ };
163
+ return { label: o.label ?? "Edit the file", node, onShow: load };
164
+ }
165
+
166
+ /** Ways to do one thing, as a switcher across the top: one shown at a time. */
167
+ export function modes(list) {
168
+ const box = el("div");
169
+ const bar = el("div", { className: "modes" });
170
+ const panes = el("div");
171
+ const buttons = list.map((m, i) => {
172
+ const b = el("button", { className: "mode", textContent: m.label });
173
+ b.onclick = () => show(i);
174
+ return b;
175
+ });
176
+ bar.append(...buttons);
177
+ box.append(bar, panes);
178
+ function show(i) {
179
+ buttons.forEach((b, j) => b.classList.toggle("on", i === j));
180
+ panes.replaceChildren(list[i].node);
181
+ list[i].onShow?.();
182
+ }
183
+ show(0);
184
+ return box;
185
+ }
186
+
187
+ async function saveAndSay(btn, out, path, text, message, onSaved, base) {
188
+ btn.disabled = true;
189
+ const label = btn.textContent;
190
+ btn.textContent = "Saving…";
191
+ try {
192
+ const r = await saveFile(path, text, message, base);
193
+ out.replaceChildren(
194
+ el("p", {
195
+ className: r.pushed ? "sub" : "err",
196
+ textContent: r.pushed ? "Saved." : "Saved locally, but the push failed: " + (r.note ?? ""),
197
+ }),
198
+ );
199
+ onSaved?.();
200
+ } catch (err) {
201
+ out.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
202
+ } finally {
203
+ btn.disabled = false;
204
+ btn.textContent = label;
205
+ }
206
+ }
207
+
208
+ /** `## Heading` → the text under it, by lower-cased heading. */
209
+ function sections(text) {
210
+ const out = new Map();
211
+ let key = null;
212
+ let buf = [];
213
+ const flush = () => key && out.set(key, buf.join("\n").trim());
214
+ for (const line of text.split("\n")) {
215
+ const m = /^##\s+(.*)$/.exec(line);
216
+ if (m) {
217
+ flush();
218
+ key = m[1].trim().toLowerCase();
219
+ buf = [];
220
+ } else if (key) buf.push(line);
221
+ }
222
+ flush();
223
+ return out;
224
+ }
225
+
226
+ function parsePriorities(text) {
227
+ const items = [];
228
+ const outs = [];
229
+ let where = "";
230
+ for (const line of text.split("\n")) {
231
+ if (/^#+\s.*priorit/i.test(line)) where = "p";
232
+ else if (/^#+\s.*out of scope/i.test(line)) where = "o";
233
+ else if (/^#/.test(line)) where = "";
234
+ const n = /^\s*\d+[.)]\s+(.*)$/.exec(line);
235
+ const b = /^\s*[-*]\s+(.*)$/.exec(line);
236
+ if (where === "p" && n) items.push(n[1].trim());
237
+ if (where === "o" && b) outs.push(b[1].trim());
238
+ }
239
+ return { items, outs };
240
+ }
@@ -7,15 +7,17 @@
7
7
  * Nothing here writes. The panel parses, shows a diff, and waits for a second click. */
8
8
 
9
9
  import { getBrief, parsePaste, saveFile } from "../api.js";
10
+ import { mdlite } from "../md.js";
10
11
  import { el, toClipboard } from "../dom.js";
11
12
  import { unifiedDiff, diffStat } from "../textdiff.js";
12
13
 
13
14
  /**
14
- * @param {{kind: string, staff?: string, title?: string, onSaved?: () => void}} opts
15
+ * @param {{kind: string, staff?: string, title?: string, about?: string, onSaved?: () => void}} opts
16
+ * `about` is a sentence on what the role does, added to a charter brief.
15
17
  */
16
18
  export function paste(opts) {
17
19
  const box = el("div", { className: "paste" });
18
- box.append(el("h3", { textContent: opts.title ?? "Write it with your own AI" }));
20
+ if (opts.title !== "") box.append(el("h3", { textContent: opts.title ?? "Write it with your own AI" }));
19
21
 
20
22
  const status = el("p", { className: "sub", textContent: "Building the prompt…" });
21
23
  box.append(status);
@@ -23,7 +25,7 @@ export function paste(opts) {
23
25
  /* A charter brief carries a worked example to model the shape on, matched to the role. The
24
26
  choice is on the page because the match is a guess, and "none" is a fair answer. */
25
27
  const model = el("select", { hidden: true });
26
- const modelRow = el("label", { className: "sub", hidden: true }, ["Model it on: ", model]);
28
+ const modelRow = el("label", { className: "sub", hidden: true }, ["Example to follow: ", model]);
27
29
  box.append(modelRow);
28
30
 
29
31
  const actions = el("div", { className: "row" });
@@ -38,8 +40,7 @@ export function paste(opts) {
38
40
  const answer = el("textarea", {
39
41
  className: "pastebox",
40
42
  placeholder:
41
- "Paste the whole reply here, including anything your AI said around the file. " +
42
- "Only the part between the sentinels is used.",
43
+ "Paste its whole reply here.",
43
44
  });
44
45
  answer.rows = 8;
45
46
 
@@ -48,10 +49,22 @@ export function paste(opts) {
48
49
 
49
50
  let brief = null;
50
51
 
51
- const NAMES = { cto: "the CTO example", cmo: "the CMO example", support: "the support example", none: "no example" };
52
+ const NAMES = {
53
+ cto: "the CTO example",
54
+ cmo: "the CMO example",
55
+ support: "the support example",
56
+ pm: "the product manager example",
57
+ designer: "the designer example",
58
+ qa: "the QA example",
59
+ devops: "the DevOps example",
60
+ writer: "the writer example",
61
+ analyst: "the analyst example",
62
+ community: "the community example",
63
+ none: "no example",
64
+ };
52
65
  model.onchange = () => {
53
66
  copy.disabled = true;
54
- getBrief(opts.kind, opts.staff, model.value)
67
+ getBrief(opts.kind, opts.staff, model.value, opts.about)
55
68
  .then((data) => {
56
69
  if (data.error) throw new Error(data.error);
57
70
  brief = data;
@@ -66,7 +79,7 @@ export function paste(opts) {
66
79
  });
67
80
  };
68
81
 
69
- getBrief(opts.kind, opts.staff)
82
+ getBrief(opts.kind, opts.staff, undefined, opts.about)
70
83
  .then((data) => {
71
84
  if (data.error) throw new Error(data.error);
72
85
  brief = data;
@@ -76,11 +89,9 @@ export function paste(opts) {
76
89
  model.hidden = modelRow.hidden = false;
77
90
  }
78
91
  status.textContent =
79
- "Paste this into Claude, ChatGPT or anything else. It carries every file it refers to, " +
80
- "so there is nothing to attach and nothing for it to ask you for. It will interview you " +
81
- "first, then hand back the finished file.";
92
+ "Copy the prompt into Claude or ChatGPT and answer its questions.";
82
93
  box.append(
83
- el("p", { className: "sub", textContent: "Then paste its whole reply back here:" }),
94
+ el("p", { className: "sub", textContent: "Then paste its reply here:" }),
84
95
  answer,
85
96
  el("div", { className: "row" }, [check]),
86
97
  result,
@@ -109,63 +120,97 @@ export function paste(opts) {
109
120
  result.replaceChildren(el("p", { className: "err", textContent: String(err.message || err) }));
110
121
  return;
111
122
  }
112
- result.replaceChildren();
113
-
114
- /* Problems first, each with the sentence that gets a better answer. A model that replied in
115
- prose is the common case and it is not the person's mistake, so it reads as a next step
116
- rather than as an error. */
117
- for (const p of data.problems ?? []) {
118
- const note = el("div", { className: "problem" });
119
- note.append(el("b", { textContent: p.message }));
120
- if (p.retry) {
121
- const retry = el("pre", { className: "cmd", textContent: p.retry });
122
- const again = el("button", { className: "btn", textContent: "Copy this reply" });
123
- again.onclick = () => toClipboard(p.retry, again, "Copied");
124
- note.append(retry, again);
125
- }
126
- result.append(note);
127
- }
123
+ showPasteResult(result, data, answer.value, opts.onSaved);
124
+ };
128
125
 
129
- for (const file of data.files ?? []) {
130
- if (file.unchanged) continue;
131
- const card = el("div", { className: "pastefile" });
132
- const stat = diffStat(file.before, file.text);
133
- card.append(
134
- el("b", { textContent: file.path }),
135
- el("span", {
136
- className: "meta",
137
- textContent: `+${stat.added} −${stat.removed}` + (file.writable ? "" : " · not writable"),
138
- }),
139
- );
140
- const diff = el("pre", { className: "diff" });
141
- diff.textContent = unifiedDiff(file.before, file.text, file.path);
142
- card.append(diff);
143
-
144
- if (file.writable) {
145
- const save = el("button", { className: "btn primary", textContent: "Save and commit" });
146
- save.onclick = async () => {
147
- save.disabled = true;
148
- save.textContent = "Saving…";
149
- try {
150
- await saveFile(file.path, file.text, `portal: write ${file.path}`);
151
- save.textContent = "Saved";
152
- card.classList.add("saved");
153
- opts.onSaved?.();
154
- } catch (err) {
155
- save.disabled = false;
156
- save.textContent = "Save and commit";
157
- card.append(el("p", { className: "err", textContent: String(err.message || err) }));
158
- }
159
- };
160
- card.append(save);
161
- }
126
+ return box;
127
+ }
128
+
129
+ /**
130
+ * What a pasted reply turned into: problems first, then each file with its diff and a Save.
131
+ * Shared by every copy-a-prompt, paste-the-answer loop, whichever endpoint parsed it.
132
+ */
133
+ export function showPasteResult(result, data, answerText, onSaved) {
134
+ result.replaceChildren();
135
+
136
+ /* Problems first, each with the sentence that gets a better answer. A model that replied in
137
+ prose is the common case and it is not the person's mistake, so it reads as a next step
138
+ rather than as an error. */
139
+ for (const p of data.problems ?? []) {
140
+ const note = el("div", { className: "problem" });
141
+ note.append(el("b", { textContent: p.message }));
142
+ if (p.retry) {
143
+ const retry = el("pre", { className: "cmd", textContent: p.retry });
144
+ const again = el("button", { className: "btn", textContent: "Copy this reply" });
145
+ again.onclick = () => toClipboard(p.retry, again, "Copied");
146
+ note.append(retry, again);
147
+ }
148
+ result.append(note);
149
+ }
150
+
151
+ // What the AI said around the file: its caveats and "check these" are worth reading first.
152
+ const notes = String(answerText ?? "")
153
+ .replace(/<<<ROSTER FILE [^>]+>>>[\s\S]*?<<<ROSTER END>>>/g, "")
154
+ .trim();
155
+
156
+ for (const file of data.files ?? []) {
157
+ const card = el("div", { className: "pastefile" });
158
+ const name = file.path.split("/").slice(-2).join("/");
159
+ if (file.unchanged) {
160
+ card.append(el("p", { className: "verdict", textContent: "✓ Same as what's already in " + name + ". Nothing to save." }));
162
161
  result.append(card);
162
+ continue;
163
163
  }
164
-
165
- if (!(data.problems ?? []).length && !(data.files ?? []).length) {
166
- result.append(el("p", { className: "sub", textContent: "Nothing to do." }));
164
+ card.append(
165
+ el("p", {
166
+ className: "verdict" + (file.writable ? " ok" : " bad"),
167
+ textContent: file.writable
168
+ ? "✓ Looks good. Saving replaces " + name + " with this:"
169
+ : "✗ " + file.path + " can't be written from here.",
170
+ }),
171
+ );
172
+ card.append(el("div", { className: "md doc pastepreview", innerHTML: mdlite(file.text) }));
173
+
174
+ if (notes) {
175
+ const said = el("details", { className: "pastenotes", open: true });
176
+ said.append(el("summary", { textContent: "Your AI also said" }), el("div", { className: "md doc", innerHTML: mdlite(notes) }));
177
+ card.append(said);
167
178
  }
168
- };
169
179
 
170
- return box;
180
+ const diff = el("pre", { className: "diff", hidden: true });
181
+ diff.textContent = unifiedDiff(file.before, file.text, file.path);
182
+ const stat = diffStat(file.before, file.text);
183
+ const toggle = el("button", { className: "ghbtn", textContent: `Show changes (+${stat.added} −${stat.removed})` });
184
+ toggle.onclick = () => {
185
+ diff.hidden = !diff.hidden;
186
+ toggle.textContent = (diff.hidden ? "Show changes" : "Hide changes") + ` (+${stat.added} −${stat.removed})`;
187
+ };
188
+
189
+ const row = el("div", { className: "row" });
190
+ if (file.writable) {
191
+ const save = el("button", { className: "btn primary", textContent: "Save" });
192
+ save.onclick = async () => {
193
+ save.disabled = true;
194
+ save.textContent = "Saving…";
195
+ try {
196
+ await saveFile(file.path, file.text, `portal: write ${file.path}`, file.before);
197
+ save.textContent = "Saved";
198
+ card.classList.add("saved");
199
+ onSaved?.();
200
+ } catch (err) {
201
+ save.disabled = false;
202
+ save.textContent = "Save";
203
+ card.append(el("p", { className: "err", textContent: String(err.message || err) }));
204
+ }
205
+ };
206
+ row.append(save);
207
+ }
208
+ row.append(toggle);
209
+ card.append(row, diff);
210
+ result.append(card);
211
+ }
212
+
213
+ if (!(data.problems ?? []).length && !(data.files ?? []).length) {
214
+ result.append(el("p", { className: "verdict bad", textContent: "✗ No file found in that reply." }));
215
+ }
171
216
  }