@nanocollective/roster 0.1.0-alpha.9 → 0.1.0-beta.10
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.
- package/README.md +6 -0
- package/dist/cli.js +4189 -1971
- package/dist/worker/assets/assets/css/base.css +327 -0
- package/dist/worker/assets/assets/css/brain.css +116 -0
- package/dist/worker/assets/assets/css/diff.css +33 -0
- package/dist/worker/assets/assets/css/graph.css +39 -0
- package/dist/worker/assets/assets/css/health.css +75 -0
- package/dist/worker/assets/assets/css/home.css +114 -0
- package/dist/worker/assets/assets/css/inbox.css +199 -0
- package/dist/worker/assets/assets/css/layout.css +181 -0
- package/dist/worker/assets/assets/css/markdown.css +96 -0
- package/dist/worker/assets/assets/css/runs.css +13 -0
- package/dist/worker/assets/assets/css/search.css +48 -0
- package/dist/worker/assets/assets/css/setup.css +194 -0
- package/dist/worker/assets/assets/js/api.js +191 -0
- package/dist/worker/assets/assets/js/app.js +500 -0
- package/dist/worker/assets/assets/js/dialog.js +196 -0
- package/dist/worker/assets/assets/js/dom.js +131 -0
- package/dist/worker/assets/assets/js/homesort.js +174 -0
- package/dist/worker/assets/assets/js/icons.js +142 -0
- package/dist/worker/assets/assets/js/inflight.js +18 -0
- package/dist/worker/assets/assets/js/lightbox.js +273 -0
- package/dist/worker/assets/assets/js/md.js +406 -0
- package/dist/worker/assets/assets/js/mdedit.js +84 -0
- package/dist/worker/assets/assets/js/mention.js +264 -0
- package/dist/worker/assets/assets/js/readiness.js +70 -0
- package/dist/worker/assets/assets/js/refresh.js +197 -0
- package/dist/worker/assets/assets/js/router.js +20 -0
- package/dist/worker/assets/assets/js/search.js +366 -0
- package/dist/worker/assets/assets/js/state.js +213 -0
- package/dist/worker/assets/assets/js/textdiff.js +96 -0
- package/dist/worker/assets/assets/js/views/app.js +145 -0
- package/dist/worker/assets/assets/js/views/brain.js +260 -0
- package/dist/worker/assets/assets/js/views/changed.js +157 -0
- package/dist/worker/assets/assets/js/views/checklist.js +115 -0
- package/dist/worker/assets/assets/js/views/credential.js +84 -0
- package/dist/worker/assets/assets/js/views/docs.js +174 -0
- package/dist/worker/assets/assets/js/views/files.js +139 -0
- package/dist/worker/assets/assets/js/views/graph.js +436 -0
- package/dist/worker/assets/assets/js/views/health.js +304 -0
- package/dist/worker/assets/assets/js/views/hire.js +593 -0
- package/dist/worker/assets/assets/js/views/home.js +621 -0
- package/dist/worker/assets/assets/js/views/inbox.js +1558 -0
- package/dist/worker/assets/assets/js/views/memory.js +150 -0
- package/dist/worker/assets/assets/js/views/org.js +195 -0
- package/dist/worker/assets/assets/js/views/orgedit.js +240 -0
- package/dist/worker/assets/assets/js/views/paste.js +216 -0
- package/dist/worker/assets/assets/js/views/prompt.js +457 -0
- package/dist/worker/assets/assets/js/views/repos.js +97 -0
- package/dist/worker/assets/assets/js/views/runonce.js +94 -0
- package/dist/worker/assets/assets/js/views/runs.js +182 -0
- package/dist/worker/assets/assets/js/views/setup.js +557 -0
- package/dist/worker/assets/assets/js/views/staff.js +291 -0
- package/dist/worker/assets/assets/js/views/todo.js +62 -0
- package/dist/worker/assets/assets/js/yaml.js +134 -0
- package/dist/worker/assets/docs-images/brain.jpg +0 -0
- package/dist/worker/assets/docs-images/home.jpg +0 -0
- package/dist/worker/assets/docs-images/org.jpg +0 -0
- package/dist/worker/assets/docs-images/prompt.jpg +0 -0
- package/dist/worker/assets/docs-images/setup-org.jpg +0 -0
- package/dist/worker/assets/docs-images/setup-plan.jpg +0 -0
- package/dist/worker/assets/docs-images/staff.jpg +0 -0
- package/dist/worker/assets/index.html +82 -0
- package/dist/worker/index.js +5143 -0
- package/docs/README.md +2 -2
- package/docs/architecture.md +23 -4
- package/docs/charters/analyst.md +65 -0
- package/docs/charters/community.md +63 -0
- package/docs/charters/designer.md +65 -0
- package/docs/charters/devops.md +65 -0
- package/docs/charters/pm.md +70 -0
- package/docs/charters/qa.md +65 -0
- package/docs/charters/writer.md +63 -0
- package/docs/commands.md +36 -9
- package/docs/concepts.md +34 -21
- package/docs/cost.md +3 -3
- package/docs/developing.md +28 -10
- package/docs/doctor-codes.md +3 -1
- package/docs/export.md +2 -0
- package/docs/getting-started.md +49 -29
- package/docs/hosting.md +114 -43
- package/docs/images/brain.jpg +0 -0
- package/docs/images/home.jpg +0 -0
- package/docs/images/org.jpg +0 -0
- package/docs/images/prompt.jpg +0 -0
- package/docs/images/staff.jpg +0 -0
- package/docs/manual-steps.md +3 -2
- package/docs/memory.md +2 -1
- package/docs/org-yaml.md +3 -0
- package/docs/portal.md +144 -45
- package/docs/prompts.md +6 -0
- package/docs/security.md +70 -11
- package/docs/session-workflow.md +24 -6
- package/docs/staff-yaml.md +21 -2
- package/docs/upgrading.md +3 -3
- package/docs/writing-a-charter.md +19 -6
- package/package.json +4 -3
- package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +20 -1
- package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +53 -13
- package/templates/brain/CHARTER.md +2 -2
- package/templates/brain/STATE.md +16 -0
- package/templates/brain/memory/INDEX.md +1 -1
- package/templates/brain/staff.yaml +4 -1
- package/templates/briefs/amend.md +4 -3
- package/templates/briefs/priorities.md +46 -0
- package/templates/ops/.github/workflows/session.yaml +150 -3
- package/templates/ops/compose.mjs +35 -8
- package/templates/ops/org/operating.md +29 -10
- package/templates/ops/org/voice.md +2 -1
- package/templates/ops/prompts/daily.md +51 -14
- package/templates/ops/prompts/mention.md +24 -2
- package/templates/ops/run-record.mjs +5 -3
- package/templates/ops/status-week.mjs +169 -0
- package/templates/portal/css/base.css +49 -0
- package/templates/portal/css/health.css +14 -1
- package/templates/portal/css/home.css +114 -0
- package/templates/portal/css/inbox.css +21 -4
- package/templates/portal/css/layout.css +35 -3
- package/templates/portal/css/markdown.css +19 -0
- package/templates/portal/css/search.css +48 -0
- package/templates/portal/css/setup.css +79 -4
- package/templates/portal/index.html +15 -9
- package/templates/portal/js/api.js +60 -4
- package/templates/portal/js/app.js +125 -7
- package/templates/portal/js/dialog.js +36 -0
- package/templates/portal/js/homesort.js +174 -0
- package/templates/portal/js/icons.js +41 -0
- package/templates/portal/js/inflight.js +18 -0
- package/templates/portal/js/md.js +5 -2
- package/templates/portal/js/mdedit.js +84 -0
- package/templates/portal/js/readiness.js +70 -0
- package/templates/portal/js/refresh.js +10 -2
- package/templates/portal/js/search.js +366 -0
- package/templates/portal/js/state.js +11 -5
- package/templates/portal/js/views/app.js +1 -2
- package/templates/portal/js/views/brain.js +1 -1
- package/templates/portal/js/views/checklist.js +19 -4
- package/templates/portal/js/views/credential.js +42 -51
- package/templates/portal/js/views/health.js +11 -6
- package/templates/portal/js/views/hire.js +593 -0
- package/templates/portal/js/views/home.js +621 -0
- package/templates/portal/js/views/inbox.js +237 -68
- package/templates/portal/js/views/org.js +31 -111
- package/templates/portal/js/views/orgedit.js +240 -0
- package/templates/portal/js/views/paste.js +111 -66
- package/templates/portal/js/views/prompt.js +94 -40
- package/templates/portal/js/views/repos.js +10 -10
- package/templates/portal/js/views/runs.js +21 -4
- package/templates/portal/js/views/setup.js +130 -163
- package/templates/portal/js/views/staff.js +181 -301
- package/templates/portal/js/views/todo.js +62 -0
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
/* Home: what needs you, who is working, what you asked for, and what was closed today.
|
|
2
|
+
*
|
|
3
|
+
* Built from the inbox list and /api/live, sorted by homesort.js, which is where the rule that
|
|
4
|
+
* every open item has exactly one place lives. Clicking an item opens its thread in a side
|
|
5
|
+
* sheet, the same thread view Trackers has, with the reply box in it. */
|
|
6
|
+
|
|
7
|
+
import { getLive, post } from "../api.js";
|
|
8
|
+
import { sheet } from "../dialog.js";
|
|
9
|
+
import { ago, el, skeleton } from "../dom.js";
|
|
10
|
+
import { daysUntil, sortHome } from "../homesort.js";
|
|
11
|
+
import { mdlite } from "../md.js";
|
|
12
|
+
import { icon, iconHTML, staffIcon } from "../icons.js";
|
|
13
|
+
import { ensureInbox, stampCounts } from "../refresh.js";
|
|
14
|
+
import { go, render } from "../router.js";
|
|
15
|
+
import { threadInto } from "./inbox.js";
|
|
16
|
+
import { humansOf, S } from "../state.js";
|
|
17
|
+
|
|
18
|
+
const KIND_LABEL = {
|
|
19
|
+
decision: "Decision",
|
|
20
|
+
review: "Review",
|
|
21
|
+
chore: "Chore",
|
|
22
|
+
ask: "Ask",
|
|
23
|
+
merge: "Pull request",
|
|
24
|
+
};
|
|
25
|
+
const KIND_TONE = { decision: "hot", review: "warm", chore: "cool", ask: "", merge: "cool" };
|
|
26
|
+
|
|
27
|
+
/* While a run is live this asks every few seconds; otherwise every half minute, so a run that
|
|
28
|
+
a reply just started shows up without a reload. Only while Home is on screen. */
|
|
29
|
+
const FAST = 5_000;
|
|
30
|
+
const SLOW = 30_000;
|
|
31
|
+
/** How old the issues on Home may get while it is open before they are read again. */
|
|
32
|
+
const ISSUES_STALE = 120_000;
|
|
33
|
+
let timer = null;
|
|
34
|
+
let issuesAt = Date.now();
|
|
35
|
+
|
|
36
|
+
export function viewHome(m) {
|
|
37
|
+
m.append(el("h1", { textContent: "Home" }));
|
|
38
|
+
|
|
39
|
+
if (!S.inbox) {
|
|
40
|
+
m.append(el("div", { className: "home" }, skeleton("row", 5)));
|
|
41
|
+
ensureInbox(false)
|
|
42
|
+
.then(() => S.view === "home" && render())
|
|
43
|
+
.catch((e) => {
|
|
44
|
+
m.append(el("p", { className: "err", textContent: String(e.message || e) }));
|
|
45
|
+
});
|
|
46
|
+
poll();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!S.live) poll();
|
|
50
|
+
|
|
51
|
+
const staff = S.data.staff;
|
|
52
|
+
const h = sortHome(S.inbox.items ?? [], staff, humansOf(), S.live?.staff ?? []);
|
|
53
|
+
stampCounts();
|
|
54
|
+
|
|
55
|
+
const page = el("div", { className: "home" });
|
|
56
|
+
page.append(askBox(staff));
|
|
57
|
+
|
|
58
|
+
const reporters = staff.filter((x) => x.brain && x.statusIssue);
|
|
59
|
+
if (reporters.length) {
|
|
60
|
+
page.append(section("Latest reports"));
|
|
61
|
+
page.append(el("div", { className: "card homereports" }, reporters.map((s) => reportRow(s, h.reports))));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
page.append(section("Needs you", h.needs.length));
|
|
65
|
+
/* One list rather than a card each: five boxes with a green button apiece read as a wall, and
|
|
66
|
+
nothing in it said which to do first. The top row's action is the one in green. */
|
|
67
|
+
if (h.needs.length) {
|
|
68
|
+
page.append(el("div", { className: "card homelist" }, h.needs.map((e, i) => needRow(e, i === 0))));
|
|
69
|
+
} else page.append(el("p", { className: "homeempty", textContent: "Nothing needs you." }));
|
|
70
|
+
|
|
71
|
+
if (h.unread.length) {
|
|
72
|
+
page.append(section("Unread", h.unread.length));
|
|
73
|
+
page.append(listBox(h.unread.map(unreadRow)));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
page.append(section("Working now"));
|
|
77
|
+
page.append(working(staff));
|
|
78
|
+
|
|
79
|
+
if (h.requests.length) {
|
|
80
|
+
page.append(section("Your requests", h.requests.length));
|
|
81
|
+
page.append(listBox(h.requests.map(requestRow)));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (h.closedToday.length) {
|
|
85
|
+
page.append(section("Closed today", h.closedToday.length));
|
|
86
|
+
page.append(listBox(h.closedToday.map(closedRow)));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
page.append(rest(h));
|
|
90
|
+
for (const e of S.inbox.errors ?? []) page.append(el("p", { className: "err", textContent: e }));
|
|
91
|
+
m.append(page);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* ------------------------------- reports -------------------------------- */
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* One staff member's last report, or a line saying there is none today, with a button that asks
|
|
98
|
+
* for one. The report is markdown the staff member wrote, with links to the work it names. The
|
|
99
|
+
* whole row opens their status issue, where it was posted; a link inside it goes where it points.
|
|
100
|
+
*/
|
|
101
|
+
function reportRow(s, reports) {
|
|
102
|
+
const r = reports.find((x) => x.staff.handle === s.handle);
|
|
103
|
+
const item = r?.item ?? { repo: s.brain, number: s.statusIssue, kind: "issue" };
|
|
104
|
+
const note = el("span", { className: "meta" });
|
|
105
|
+
const ask = el("button", { className: "ghbtn", textContent: "Ask for a report" });
|
|
106
|
+
ask.onclick = async () => {
|
|
107
|
+
ask.disabled = true;
|
|
108
|
+
note.className = "meta";
|
|
109
|
+
note.textContent = "Asking…";
|
|
110
|
+
try {
|
|
111
|
+
await post({
|
|
112
|
+
action: "comment",
|
|
113
|
+
repo: s.brain,
|
|
114
|
+
number: s.statusIssue,
|
|
115
|
+
body: `${s.mention ?? "@" + s.handle} Report, please.`,
|
|
116
|
+
});
|
|
117
|
+
ask.remove();
|
|
118
|
+
note.textContent = `Asked. ${s.name} replies in a few minutes.`;
|
|
119
|
+
refreshSoon();
|
|
120
|
+
} catch (e) {
|
|
121
|
+
note.textContent = String(e.message || e);
|
|
122
|
+
note.className = "meta err";
|
|
123
|
+
ask.disabled = false;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const row = el("div", { className: "homereport homeclick", tabIndex: 0, role: "button" }, [
|
|
128
|
+
el("div", { className: "homereportwho" }, [
|
|
129
|
+
el("span", { className: "homewho2" }, [icon(staffIcon(s), "ic"), el("b", { textContent: s.name })]),
|
|
130
|
+
el("span", { className: "meta", textContent: r ? ago(r.at) : "No report today" }),
|
|
131
|
+
el("div", { className: "homereportask" }, [ask, note]),
|
|
132
|
+
]),
|
|
133
|
+
r
|
|
134
|
+
? el("div", { className: "md homereportbody", innerHTML: mdlite(r.lines.join("\n\n"), { repo: s.brain }) })
|
|
135
|
+
: el("div"),
|
|
136
|
+
]);
|
|
137
|
+
row.onclick = (ev) => {
|
|
138
|
+
if (!ev.target.closest("a, button")) openThread(item);
|
|
139
|
+
};
|
|
140
|
+
row.onkeydown = (ev) => {
|
|
141
|
+
if (ev.target === row && (ev.key === "Enter" || ev.key === " ")) {
|
|
142
|
+
ev.preventDefault();
|
|
143
|
+
openThread(item);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return row;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/* ------------------------------- asking -------------------------------- */
|
|
150
|
+
|
|
151
|
+
function askBox(staff) {
|
|
152
|
+
const who = el("select", { className: "homewho", ariaLabel: "Who to ask" });
|
|
153
|
+
for (const s of staff.filter((x) => x.brain)) {
|
|
154
|
+
who.append(el("option", { value: s.handle, textContent: s.name }));
|
|
155
|
+
}
|
|
156
|
+
const text = el("textarea", {
|
|
157
|
+
className: "homeask",
|
|
158
|
+
rows: 2,
|
|
159
|
+
placeholder: "Ask a staff member to do something",
|
|
160
|
+
});
|
|
161
|
+
const send = el("button", { className: "ghbtn primary", textContent: "Send" });
|
|
162
|
+
const note = el("span", { className: "meta" });
|
|
163
|
+
send.onclick = async () => {
|
|
164
|
+
const s = staff.find((x) => x.handle === who.value);
|
|
165
|
+
const said = text.value.trim();
|
|
166
|
+
if (!s || !said) return;
|
|
167
|
+
send.disabled = true;
|
|
168
|
+
note.textContent = "Sending…";
|
|
169
|
+
try {
|
|
170
|
+
await post({
|
|
171
|
+
action: "create",
|
|
172
|
+
repo: s.brain,
|
|
173
|
+
title: titleOf(said),
|
|
174
|
+
body: `${s.mention ?? "@" + s.handle} ${said}`,
|
|
175
|
+
});
|
|
176
|
+
text.value = "";
|
|
177
|
+
note.textContent = `Sent. ${s.name} starts in about a minute.`;
|
|
178
|
+
refreshSoon();
|
|
179
|
+
} catch (e) {
|
|
180
|
+
note.textContent = String(e.message || e);
|
|
181
|
+
note.className = "meta err";
|
|
182
|
+
} finally {
|
|
183
|
+
send.disabled = false;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return el("div", { className: "card homeaskcard" }, [
|
|
187
|
+
el("div", { className: "row" }, [who]),
|
|
188
|
+
text,
|
|
189
|
+
el("div", { className: "row" }, [send, note]),
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The first line, short enough to be an issue title. */
|
|
194
|
+
function titleOf(said) {
|
|
195
|
+
const line = said.split("\n").find((l) => l.trim()) ?? said;
|
|
196
|
+
return line.length > 90 ? line.slice(0, 89).trimEnd() + "…" : line;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* ------------------------------ needs you ------------------------------- */
|
|
200
|
+
|
|
201
|
+
function needRow(e, first) {
|
|
202
|
+
const { item, kind } = e;
|
|
203
|
+
/* The whole row opens the thread; the one quick action on it does not. Answering in words
|
|
204
|
+
happens in the thread, where what was asked is in front of you. */
|
|
205
|
+
const row = el("div", {
|
|
206
|
+
className: "homeneed" + (item.unread ? " unread" : ""),
|
|
207
|
+
tabIndex: 0,
|
|
208
|
+
role: "button",
|
|
209
|
+
});
|
|
210
|
+
row.onclick = (ev) => {
|
|
211
|
+
if (!ev.target.closest("button, a, textarea")) openThread(item);
|
|
212
|
+
};
|
|
213
|
+
row.onkeydown = (ev) => {
|
|
214
|
+
if (ev.target === row && (ev.key === "Enter" || ev.key === " ")) {
|
|
215
|
+
ev.preventDefault();
|
|
216
|
+
openThread(item);
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/* What kind of thing it is sits in the line under the title, so every title starts in the
|
|
221
|
+
same place; a chip in front of it pushed each one along by its own width. */
|
|
222
|
+
const meta = el("div", { className: "meta" }, [
|
|
223
|
+
el("span", { className: "homekind " + (KIND_TONE[kind] ?? ""), textContent: KIND_LABEL[kind] }),
|
|
224
|
+
document.createTextNode(" · " + whereOf(e) + " · " + ago(item.createdAt)),
|
|
225
|
+
]);
|
|
226
|
+
const about = el("div", { className: "homeabout" }, [openLink(item), meta]);
|
|
227
|
+
if (kind === "decision" && item.due) about.append(dueLine(item.due));
|
|
228
|
+
if (kind === "merge") about.append(checksLine(item));
|
|
229
|
+
|
|
230
|
+
// The note comes first so that what happened sits just left of the button that did it.
|
|
231
|
+
const note = el("span", { className: "meta" });
|
|
232
|
+
const actions = el("div", { className: "row homeacts" }, [note]);
|
|
233
|
+
row.append(el("span", { className: "homedot", ariaHidden: "true" }), about, actions);
|
|
234
|
+
|
|
235
|
+
if (kind === "decision" || kind === "ask") {
|
|
236
|
+
actions.append(button("Reply", first, () => openThread(item)));
|
|
237
|
+
if (item.due) {
|
|
238
|
+
actions.append(button("Go with the default", false, () => say(e, "Go with your default.", note, actions)));
|
|
239
|
+
}
|
|
240
|
+
} else if (kind === "review") {
|
|
241
|
+
actions.append(button("Approve", first, () => say(e, "Approved.", note, actions)));
|
|
242
|
+
} else if (kind === "chore") {
|
|
243
|
+
actions.append(button("Done", first, () => done(e, note, actions)));
|
|
244
|
+
} else if (kind === "merge") {
|
|
245
|
+
/* Merge is offered only when pressing it can work. A conflict, failing checks or checks
|
|
246
|
+
still running are in the line under the title instead; a grey button that cannot be
|
|
247
|
+
pressed looked like one that could. */
|
|
248
|
+
const blocked =
|
|
249
|
+
item.checks === "failing" || item.checks === "pending" || item.mergeable === "CONFLICTING";
|
|
250
|
+
const merge = () => button("Merge", first, () => merge_(e, note, actions));
|
|
251
|
+
if (item.reviewDecision === "REVIEW_REQUIRED") {
|
|
252
|
+
// Approve is the person's review, given on purpose; Merge waits for it.
|
|
253
|
+
const approve = button("Approve", first, async () => {
|
|
254
|
+
approve.disabled = true;
|
|
255
|
+
note.className = "meta";
|
|
256
|
+
note.textContent = "Approving…";
|
|
257
|
+
try {
|
|
258
|
+
await post({ action: "approve", repo: item.repo, number: item.number });
|
|
259
|
+
item.reviewDecision = "APPROVED";
|
|
260
|
+
note.textContent = "Approved.";
|
|
261
|
+
approve.remove();
|
|
262
|
+
if (!blocked) actions.append(merge());
|
|
263
|
+
} catch (err) {
|
|
264
|
+
note.textContent = String(err.message || err);
|
|
265
|
+
note.className = "meta err";
|
|
266
|
+
approve.disabled = false;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
actions.append(approve);
|
|
270
|
+
} else if (!blocked) actions.append(merge());
|
|
271
|
+
}
|
|
272
|
+
return row;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function dueLine(due) {
|
|
276
|
+
const d = daysUntil(due.date);
|
|
277
|
+
const when =
|
|
278
|
+
d > 1 ? `in ${d} days` : d === 1 ? "tomorrow" : d === 0 ? "today" : `${-d} day${d === -1 ? "" : "s"} ago`;
|
|
279
|
+
return el("p", {
|
|
280
|
+
className: "homedue" + (d <= 0 ? " late" : ""),
|
|
281
|
+
textContent: `Default ${d < 0 ? "was due" : "applies"} ${when}: ${due.action}.`,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Where a pull request stands, with only the parts that stop a merge in amber. */
|
|
286
|
+
function checksLine(item) {
|
|
287
|
+
const parts = [];
|
|
288
|
+
if (item.checks === "passing") parts.push(["Checks pass", false]);
|
|
289
|
+
if (item.checks === "failing") parts.push(["Checks fail", true]);
|
|
290
|
+
if (item.checks === "pending") parts.push(["Checks are running", false]);
|
|
291
|
+
if (item.mergeable === "CONFLICTING") parts.push(["Conflicts with its base", true]);
|
|
292
|
+
if (item.reviewDecision === "REVIEW_REQUIRED") parts.push(["Needs your approval", false]);
|
|
293
|
+
const line = el("p", { className: "homedue" });
|
|
294
|
+
parts.forEach(([text, bad], i) => {
|
|
295
|
+
if (i) line.append(document.createTextNode(" · "));
|
|
296
|
+
line.append(el("span", { className: bad ? "bad" : "", textContent: text }));
|
|
297
|
+
});
|
|
298
|
+
return line;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async function say(e, text, note, actions) {
|
|
302
|
+
const said = String(text ?? "").trim();
|
|
303
|
+
if (!said) return;
|
|
304
|
+
const mention = e.staff?.mention ?? "";
|
|
305
|
+
await act(note, actions, { action: "comment", repo: e.item.repo, number: e.item.number, body: `${mention} ${said}`.trim() }, "Sent.");
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function done(e, note, actions) {
|
|
309
|
+
return act(note, actions, { action: "close", repo: e.item.repo, number: e.item.number, body: "Done." }, "Closed.");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function merge_(e, note, actions) {
|
|
313
|
+
return act(note, actions, { action: "merge", repo: e.item.repo, number: e.item.number }, "Merged.");
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async function act(note, actions, payload, ok) {
|
|
317
|
+
for (const b of actions.querySelectorAll("button")) b.disabled = true;
|
|
318
|
+
note.className = "meta";
|
|
319
|
+
note.textContent = "Working…";
|
|
320
|
+
try {
|
|
321
|
+
await post(payload);
|
|
322
|
+
note.textContent = ok;
|
|
323
|
+
// Done is done: the card goes now, rather than when GitHub next answers.
|
|
324
|
+
const card = actions.closest?.(".homeneed, .homeline");
|
|
325
|
+
if (card) {
|
|
326
|
+
card.classList.add("gone");
|
|
327
|
+
setTimeout(() => card.remove(), 220);
|
|
328
|
+
}
|
|
329
|
+
refreshSoon();
|
|
330
|
+
} catch (err) {
|
|
331
|
+
note.textContent = String(err.message || err);
|
|
332
|
+
note.className = "meta err";
|
|
333
|
+
for (const b of actions.querySelectorAll("button")) b.disabled = false;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/* ------------------------------ working now ----------------------------- */
|
|
338
|
+
|
|
339
|
+
/** What a run was, in a few words: "daily run", "answering #12", "a peer's ask #4". */
|
|
340
|
+
function whatRun(r) {
|
|
341
|
+
if (r.trigger === "mention") return r.issue ? `answering #${r.issue}` : "answering a mention";
|
|
342
|
+
if (r.trigger === "peer") return r.issue ? `a peer's ask #${r.issue}` : "a peer's ask";
|
|
343
|
+
return (
|
|
344
|
+
{ daily: "daily run", manual: "run started by hand", "follow-on": "follow-on run" }[r.trigger] ??
|
|
345
|
+
"run"
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function working(staff) {
|
|
350
|
+
const box = el("div", { className: "card homeworking" });
|
|
351
|
+
if (!S.live) {
|
|
352
|
+
box.append(el("p", { className: "homerunwhat", textContent: "Asking GitHub…" }));
|
|
353
|
+
return box;
|
|
354
|
+
}
|
|
355
|
+
for (const s of staff) {
|
|
356
|
+
const l = (S.live.staff ?? []).find((x) => x.handle === s.handle);
|
|
357
|
+
const runs = l && !l.error ? (l.running ?? []) : [];
|
|
358
|
+
const busy = runs.length > 0;
|
|
359
|
+
const last = l?.finished?.[0];
|
|
360
|
+
|
|
361
|
+
const what = el("div", { className: "homerunwhat" });
|
|
362
|
+
let log = null;
|
|
363
|
+
if (!l || l.error) {
|
|
364
|
+
what.append(el("span", { className: "err", textContent: l?.error ?? "Could not read their runs." }));
|
|
365
|
+
} else if (busy) {
|
|
366
|
+
for (const r of runs) {
|
|
367
|
+
what.append(el("div", { textContent: `${cap(whatRun(r))} · ${minutes(r.createdAt)} so far` }));
|
|
368
|
+
}
|
|
369
|
+
log = runs[0].url;
|
|
370
|
+
} else if (last) {
|
|
371
|
+
what.append(
|
|
372
|
+
el("div", { textContent: `${cap(whatRun(last))}, ${outcome(last)} ${ago(last.updatedAt)}` }),
|
|
373
|
+
);
|
|
374
|
+
log = last.url;
|
|
375
|
+
} else {
|
|
376
|
+
what.append(el("div", { textContent: "No runs in the last few hours." }));
|
|
377
|
+
}
|
|
378
|
+
if (l && !l.error && l.automatic) {
|
|
379
|
+
what.append(
|
|
380
|
+
el("div", {
|
|
381
|
+
className: "homerunsub",
|
|
382
|
+
textContent: `${l.automatic} of ${l.limit} runs today that nobody asked for`,
|
|
383
|
+
}),
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const state = el("span", {
|
|
388
|
+
className: "chip homestate " + (busy ? "ok" : ""),
|
|
389
|
+
textContent: busy ? (runs[0].status === "queued" ? "Queued" : "Working") : "Idle",
|
|
390
|
+
});
|
|
391
|
+
const actions = el("div", { className: "homerunlog" });
|
|
392
|
+
if (log) {
|
|
393
|
+
actions.append(
|
|
394
|
+
el("a", { className: "ghbtn", href: log, target: "_blank", rel: "noopener", textContent: "Log" }),
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
box.append(
|
|
399
|
+
el("div", { className: "homerun" + (busy ? " busy" : "") }, [
|
|
400
|
+
el("span", { className: "homewho2" }, [icon(staffIcon(s), "ic"), el("b", { textContent: s.name })]),
|
|
401
|
+
state,
|
|
402
|
+
what,
|
|
403
|
+
actions,
|
|
404
|
+
]),
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
return box;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const cap = (t) => t.charAt(0).toUpperCase() + t.slice(1);
|
|
411
|
+
|
|
412
|
+
function minutes(since) {
|
|
413
|
+
const m = Math.max(1, Math.round((Date.now() - new Date(since).getTime()) / 60000));
|
|
414
|
+
return m < 60 ? `${m} min` : `${Math.floor(m / 60)} h ${m % 60} min`;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function outcome(r) {
|
|
418
|
+
return r.conclusion === "success" ? "finished" : r.conclusion === "failure" ? "failed" : (r.conclusion ?? "ended");
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* A timer that never keeps a process alive. In the browser this is setTimeout; under the
|
|
423
|
+
* tests' Node shim the polling loop would otherwise hold a test file open forever.
|
|
424
|
+
*/
|
|
425
|
+
function later(fn, ms) {
|
|
426
|
+
const t = setTimeout(fn, ms);
|
|
427
|
+
t?.unref?.();
|
|
428
|
+
return t;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function poll() {
|
|
432
|
+
clearTimeout(timer);
|
|
433
|
+
getLive()
|
|
434
|
+
.then((data) => {
|
|
435
|
+
// Only a change repaints: a poll every few seconds must not move the page under you.
|
|
436
|
+
const changed = JSON.stringify(data.staff) !== JSON.stringify(S.live?.staff);
|
|
437
|
+
/* A run that just ended has usually replied, closed or opened something, so that is when
|
|
438
|
+
the issues are read again. Otherwise every couple of minutes while Home is open. */
|
|
439
|
+
const ended = S.live && finishedCount(data) !== finishedCount(S.live);
|
|
440
|
+
S.live = data;
|
|
441
|
+
if (ended || Date.now() - issuesAt > ISSUES_STALE) {
|
|
442
|
+
issuesAt = Date.now();
|
|
443
|
+
refreshSoon(false);
|
|
444
|
+
} else if (changed && S.view === "home" && !document.querySelector("dialog[open]")) {
|
|
445
|
+
repaintInPlace();
|
|
446
|
+
}
|
|
447
|
+
})
|
|
448
|
+
.catch(() => {})
|
|
449
|
+
.finally(() => {
|
|
450
|
+
if (S.view !== "home") return;
|
|
451
|
+
const busy = (S.live?.staff ?? []).some((l) => l.running?.length);
|
|
452
|
+
timer = later(poll, busy ? FAST : SLOW);
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/* ------------------------------ your requests ---------------------------- */
|
|
457
|
+
|
|
458
|
+
/** A card of rows, laid out like Working now. */
|
|
459
|
+
function listBox(rows) {
|
|
460
|
+
return el("div", { className: "card homeworking" }, rows);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* One row in a list card: a status chip, the title with one line under it, and a button on the
|
|
465
|
+
* right. The whole row opens the thread, except the button.
|
|
466
|
+
*/
|
|
467
|
+
function listRow(e, { chip, tone = "", sub, action = null }) {
|
|
468
|
+
const row = el(
|
|
469
|
+
"div",
|
|
470
|
+
{ className: "homeline homeclick" + (e.item.unread ? " unread" : ""), tabIndex: 0, role: "button" },
|
|
471
|
+
[
|
|
472
|
+
// The same row as Needs you: an unread dot, the title, and what it is in the line under it.
|
|
473
|
+
el("span", { className: "homedot", ariaHidden: "true" }),
|
|
474
|
+
el("div", { className: "homerunwhat" }, [
|
|
475
|
+
el("div", { className: "homerowtitle", textContent: e.item.title }),
|
|
476
|
+
el("div", { className: "homerunsub" }, [
|
|
477
|
+
el("span", { className: "homekind " + tone, textContent: chip }),
|
|
478
|
+
document.createTextNode(` · ${whereOf(e)} · ${sub}`),
|
|
479
|
+
]),
|
|
480
|
+
]),
|
|
481
|
+
el("div", { className: "homerunlog" }, action ? [action] : []),
|
|
482
|
+
],
|
|
483
|
+
);
|
|
484
|
+
row.onclick = (ev) => {
|
|
485
|
+
if (!ev.target.closest("button, a")) openThread(e.item);
|
|
486
|
+
};
|
|
487
|
+
row.onkeydown = (ev) => {
|
|
488
|
+
if (ev.target === row && (ev.key === "Enter" || ev.key === " ")) {
|
|
489
|
+
ev.preventDefault();
|
|
490
|
+
openThread(e.item);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
return row;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const WHY = {
|
|
497
|
+
status: "Status",
|
|
498
|
+
peer: "Peer ask",
|
|
499
|
+
own: "Their work",
|
|
500
|
+
draft: "Draft",
|
|
501
|
+
contributor: "Issue",
|
|
502
|
+
other: "Issue",
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
/** Something on a staff member's tracker, or elsewhere, with activity you have not seen. */
|
|
506
|
+
function unreadRow(e) {
|
|
507
|
+
return listRow(e, {
|
|
508
|
+
chip: WHY[e.why] ?? "Issue",
|
|
509
|
+
tone: "cool",
|
|
510
|
+
sub: ago(e.item.updatedAt),
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const STATUS = { waiting: "Waiting", working: "Working", answered: "Answered" };
|
|
515
|
+
|
|
516
|
+
function requestRow(e) {
|
|
517
|
+
return listRow(e, {
|
|
518
|
+
chip: STATUS[e.status],
|
|
519
|
+
tone: e.status === "answered" ? "cool" : e.status === "working" ? "ok" : "",
|
|
520
|
+
sub: ago(e.item.updatedAt),
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function closedRow(e) {
|
|
525
|
+
const note = el("span", { className: "meta" });
|
|
526
|
+
const reopen = button("Reopen", false, () =>
|
|
527
|
+
act(note, holder, { action: "reopen", repo: e.item.repo, number: e.item.number }, "Reopened."),
|
|
528
|
+
);
|
|
529
|
+
const holder = el("div", { className: "row" }, [note, reopen]);
|
|
530
|
+
return listRow(e, {
|
|
531
|
+
chip: "Closed",
|
|
532
|
+
sub: e.reason || "No reason given.",
|
|
533
|
+
action: holder,
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/* --------------------------------- rest --------------------------------- */
|
|
538
|
+
|
|
539
|
+
function rest(h) {
|
|
540
|
+
const parts = [];
|
|
541
|
+
if (h.staff.length) parts.push(`${h.staff.length} on the staff's own trackers`);
|
|
542
|
+
if (h.elsewhere.length) parts.push(`${h.elsewhere.length} elsewhere`);
|
|
543
|
+
if (!parts.length) return el("span");
|
|
544
|
+
const link = el("button", { className: "ghbtn", textContent: "Open Trackers" });
|
|
545
|
+
link.onclick = () => go({ view: "inbox", inboxStaff: "", inboxOpen: null });
|
|
546
|
+
return el("div", { className: "row homerest" }, [
|
|
547
|
+
el("span", { className: "meta", textContent: "Also open: " + parts.join(", ") + "." }),
|
|
548
|
+
link,
|
|
549
|
+
]);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/* -------------------------------- helpers -------------------------------- */
|
|
553
|
+
|
|
554
|
+
function section(title, count) {
|
|
555
|
+
const h = el("h2", { textContent: title });
|
|
556
|
+
if (count !== undefined) h.append(el("span", { className: "pill", textContent: String(count) }));
|
|
557
|
+
return h;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function openLink(item) {
|
|
561
|
+
const b = el("button", { className: "homeopen", textContent: item.title });
|
|
562
|
+
b.onclick = () => openThread(item);
|
|
563
|
+
return b;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** Repaint Home where you were: the sheet may have changed what is on it, not where you are. */
|
|
567
|
+
function repaintInPlace() {
|
|
568
|
+
const main = document.querySelector("#main");
|
|
569
|
+
const at = { win: window.scrollY, main: main?.scrollTop ?? 0 };
|
|
570
|
+
render();
|
|
571
|
+
window.scrollTo(0, at.win);
|
|
572
|
+
if (main) main.scrollTop = at.main;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* The thread in a side sheet: its header, actions, reply box and conversation. Closing it
|
|
577
|
+
* repaints Home, since a reply or a close there changes what belongs where. Where there is no
|
|
578
|
+
* <dialog> (the test shim), it falls back to the thread on Trackers.
|
|
579
|
+
*/
|
|
580
|
+
export function openThread(item) {
|
|
581
|
+
const ref = { repo: item.repo, number: item.number, kind: item.kind };
|
|
582
|
+
const body = el("div");
|
|
583
|
+
const x = el("button", { className: "iconbtn", title: "Close (Esc)", ariaLabel: "Close" });
|
|
584
|
+
x.innerHTML = iconHTML("close");
|
|
585
|
+
body.append(el("div", { className: "sidebar-x" }, [x]));
|
|
586
|
+
threadInto(body, ref);
|
|
587
|
+
const box = sheet({ node: body, side: true, onClose: () => S.view === "home" && repaintInPlace() });
|
|
588
|
+
if (!box) {
|
|
589
|
+
go({ view: item.kind === "pr" ? "prs" : "inbox", inboxStaff: "", inboxFilter: "", inboxOpen: ref });
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
x.onclick = () => box.close();
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function whereOf(e) {
|
|
596
|
+
const repo = e.item.repo.split("/")[1] ?? e.item.repo;
|
|
597
|
+
return (e.staff?.name ?? repo) + " · #" + e.item.number;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function button(label, primary, onclick) {
|
|
601
|
+
const b = el("button", { className: "ghbtn" + (primary ? " primary" : ""), textContent: label });
|
|
602
|
+
b.onclick = onclick;
|
|
603
|
+
return b;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/** How many runs have finished across the staff, to notice one ending. */
|
|
607
|
+
function finishedCount(live) {
|
|
608
|
+
return (live?.staff ?? []).reduce((n, l) => n + (l.finished?.length ?? 0), 0);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Re-read the issues and repaint where you were. After a write it also looks for the run the
|
|
613
|
+
* write starts; from the poll it does not, since the poll is already running.
|
|
614
|
+
*/
|
|
615
|
+
function refreshSoon(lookForRun = true) {
|
|
616
|
+
issuesAt = Date.now();
|
|
617
|
+
ensureInbox(true)
|
|
618
|
+
.then(() => S.view === "home" && !document.querySelector("dialog[open]") && repaintInPlace())
|
|
619
|
+
.catch(() => {});
|
|
620
|
+
if (lookForRun) later(poll, 3_000);
|
|
621
|
+
}
|