@point-seven-studio/jq-deck-server 0.0.0-stage → 0.2.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.
- package/LICENSE +202 -0
- package/NOTICE +2 -0
- package/README.md +113 -2
- package/dist/index.mjs +447 -0
- package/dist/jq-deck-server.mjs +559 -0
- package/dist/types/cli.d.ts +9 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/main.d.ts +1 -0
- package/dist/types/page.d.ts +9 -0
- package/dist/types/report.d.ts +43 -0
- package/dist/types/send.d.ts +3 -0
- package/dist/types/server.d.ts +34 -0
- package/dist/types/store.d.ts +37 -0
- package/dist/types/team.d.ts +59 -0
- package/package.json +59 -4
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import path2 from "path";
|
|
5
|
+
|
|
6
|
+
// src/report.ts
|
|
7
|
+
var MAX_REPOS = 200;
|
|
8
|
+
var MAX_BODY_BYTES = 256 * 1024;
|
|
9
|
+
var MAX_QUESTIONS = 20;
|
|
10
|
+
var MAX_QUESTION_CHARS = 400;
|
|
11
|
+
var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
12
|
+
function count(v, field, max = 1e5) {
|
|
13
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < 0 || v > max) throw new Error(`${field} must be a whole number from 0 to ${max}`);
|
|
14
|
+
return v;
|
|
15
|
+
}
|
|
16
|
+
function isoOrNull(v, field) {
|
|
17
|
+
if (v === null || v === void 0) return null;
|
|
18
|
+
if (typeof v !== "string" || v.length > 40 || Number.isNaN(Date.parse(v))) throw new Error(`${field} must be a date or null`);
|
|
19
|
+
return new Date(Date.parse(v)).toISOString();
|
|
20
|
+
}
|
|
21
|
+
function repoName(v) {
|
|
22
|
+
if (typeof v !== "string") throw new Error("a repository needs a name");
|
|
23
|
+
const name = v.trim();
|
|
24
|
+
if (!name || name.length > 100 || /[\u0000-\u001f\u007f/\\]/.test(name)) throw new Error("a repository name must be 1 to 100 characters with no slash");
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
function remote(v) {
|
|
28
|
+
return typeof v === "string" && v.length <= 200 && /^[a-z0-9][a-z0-9.-]*(\/[A-Za-z0-9._~-]+)+$/.test(v) ? v : null;
|
|
29
|
+
}
|
|
30
|
+
function questions(v) {
|
|
31
|
+
if (v === void 0 || v === null) return void 0;
|
|
32
|
+
if (!Array.isArray(v) || v.length > MAX_QUESTIONS) throw new Error(`questions must be a list of at most ${MAX_QUESTIONS}`);
|
|
33
|
+
const out = v.map((q) => {
|
|
34
|
+
if (!isObj(q) || typeof q.text !== "string") throw new Error("each question needs its text");
|
|
35
|
+
const text2 = q.text.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "").trim().slice(0, MAX_QUESTION_CHARS);
|
|
36
|
+
return { asked_at: isoOrNull(q.asked_at, "questions.asked_at"), text: text2 };
|
|
37
|
+
}).filter((q) => q.text);
|
|
38
|
+
return out.length ? out : void 0;
|
|
39
|
+
}
|
|
40
|
+
function sanitizeReport(value) {
|
|
41
|
+
if (!isObj(value)) throw new Error("the report must be a JSON object");
|
|
42
|
+
if (value.v !== 1) throw new Error("unknown report version (this server reads version 1)");
|
|
43
|
+
const generated = isoOrNull(value.generated_at, "generated_at");
|
|
44
|
+
if (!generated) throw new Error("generated_at is missing");
|
|
45
|
+
if (!Array.isArray(value.repos)) throw new Error("repos must be a list");
|
|
46
|
+
if (value.repos.length > MAX_REPOS) throw new Error(`a report holds at most ${MAX_REPOS} repositories`);
|
|
47
|
+
const repos = value.repos.map((r) => {
|
|
48
|
+
if (!isObj(r)) throw new Error("each repository must be an object");
|
|
49
|
+
const setup = isObj(r.setup) ? { score: count(r.setup.score, "setup.score", 100), fail: count(r.setup.fail, "setup.fail"), warn: count(r.setup.warn, "setup.warn") } : null;
|
|
50
|
+
const asked = questions(r.questions);
|
|
51
|
+
return {
|
|
52
|
+
name: repoName(r.name),
|
|
53
|
+
remote: remote(r.remote),
|
|
54
|
+
sessions: count(r.sessions, "sessions"),
|
|
55
|
+
live: count(r.live, "live"),
|
|
56
|
+
needs_you: count(r.needs_you, "needs_you"),
|
|
57
|
+
abandoned: count(r.abandoned, "abandoned"),
|
|
58
|
+
waiting_since: isoOrNull(r.waiting_since, "waiting_since"),
|
|
59
|
+
last_activity_at: isoOrNull(r.last_activity_at, "last_activity_at"),
|
|
60
|
+
setup,
|
|
61
|
+
unread: r.unread === null || r.unread === void 0 ? null : count(r.unread, "unread"),
|
|
62
|
+
...asked ? { questions: asked } : {}
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
return { v: 1, generated_at: generated, repos };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/send.ts
|
|
69
|
+
var LOCAL = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "[::1]"]);
|
|
70
|
+
function reportUrl(base) {
|
|
71
|
+
let url;
|
|
72
|
+
try {
|
|
73
|
+
url = new URL(base);
|
|
74
|
+
} catch {
|
|
75
|
+
throw new Error(`--url is not an address: ${base}`);
|
|
76
|
+
}
|
|
77
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && LOCAL.has(url.hostname))) throw new Error("--url must start with https (plain http is allowed only to this machine)");
|
|
78
|
+
if (url.username || url.password) throw new Error("--url must not hold a user name or password; the token goes in $JQ_DECK_TOKEN");
|
|
79
|
+
return new URL("/report", url);
|
|
80
|
+
}
|
|
81
|
+
async function send(base, token, input, post = fetch) {
|
|
82
|
+
if (!token) throw new Error("set $JQ_DECK_TOKEN to this machine's token (from: jq-deck-server add-machine)");
|
|
83
|
+
const url = reportUrl(base);
|
|
84
|
+
const report = sanitizeReport(JSON.parse(input));
|
|
85
|
+
const res = await post(url, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
|
|
88
|
+
body: JSON.stringify(report),
|
|
89
|
+
signal: AbortSignal.timeout(1e4),
|
|
90
|
+
redirect: "error"
|
|
91
|
+
});
|
|
92
|
+
if (res.status !== 204) throw new Error(`the server answered ${res.status}: ${(await res.text()).slice(0, 200)}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/server.ts
|
|
96
|
+
import { createServer } from "http";
|
|
97
|
+
|
|
98
|
+
// src/team.ts
|
|
99
|
+
var FRESH_MS = 5 * 6e4;
|
|
100
|
+
var SILENT_MS = 24 * 36e5;
|
|
101
|
+
function freshness(receivedAt, now) {
|
|
102
|
+
const age = Math.max(0, now - Date.parse(receivedAt));
|
|
103
|
+
return { freshness: age <= FRESH_MS ? "fresh" : age <= SILENT_MS ? "quiet" : "silent", minutes_ago: Math.floor(age / 6e4) };
|
|
104
|
+
}
|
|
105
|
+
var lower = (s) => s.toLowerCase();
|
|
106
|
+
function visible(viewer, repo) {
|
|
107
|
+
if (!viewer?.repos || viewer.repos.length === 0) return true;
|
|
108
|
+
const allowed = new Set(viewer.repos.map(lower));
|
|
109
|
+
return allowed.has(lower(repo.name)) || !!repo.remote && allowed.has(lower(repo.remote));
|
|
110
|
+
}
|
|
111
|
+
function duration(minutes) {
|
|
112
|
+
if (minutes < 1) return "under a minute";
|
|
113
|
+
if (minutes < 60) return `${minutes} ${minutes === 1 ? "minute" : "minutes"}`;
|
|
114
|
+
const hours = Math.floor(minutes / 60);
|
|
115
|
+
if (hours < 48) return `${hours} ${hours === 1 ? "hour" : "hours"}`;
|
|
116
|
+
return `${Math.floor(hours / 24)} days`;
|
|
117
|
+
}
|
|
118
|
+
var plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
119
|
+
function buildTeam(reports, now, viewer = null) {
|
|
120
|
+
const scoped = !!viewer?.repos?.length;
|
|
121
|
+
const groups = /* @__PURE__ */ new Map();
|
|
122
|
+
const machines = [];
|
|
123
|
+
for (const stored of reports) {
|
|
124
|
+
const state = freshness(stored.received_at, now);
|
|
125
|
+
const mine = stored.report.repos.filter((r) => visible(viewer, r));
|
|
126
|
+
if (scoped && mine.length === 0) continue;
|
|
127
|
+
machines.push({ machine: stored.machine, who: stored.who, received_at: stored.received_at, ...state });
|
|
128
|
+
if (state.freshness === "silent") continue;
|
|
129
|
+
for (const repo of mine) {
|
|
130
|
+
const key = repo.remote ? lower(repo.remote) : `name:${lower(repo.name)}`;
|
|
131
|
+
const group = groups.get(key) ?? { key, name: repo.name, remote: repo.remote, needs_you: 0, rows: [] };
|
|
132
|
+
const fresh = state.freshness === "fresh";
|
|
133
|
+
const since = fresh && repo.needs_you > 0 && repo.waiting_since ? Math.max(0, Math.floor((now - Date.parse(repo.waiting_since)) / 6e4)) : null;
|
|
134
|
+
group.rows.push({ ...repo, questions: fresh ? repo.questions : void 0, machine: stored.machine, who: stored.who, ...state, waiting_minutes: since });
|
|
135
|
+
if (fresh) group.needs_you += repo.needs_you;
|
|
136
|
+
groups.set(key, group);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const longest = (g) => Math.max(-1, ...g.rows.map((r) => r.waiting_minutes ?? -1));
|
|
140
|
+
const list = [...groups.values()];
|
|
141
|
+
for (const g of list) g.rows.sort((a, b) => (b.waiting_minutes ?? -1) - (a.waiting_minutes ?? -1) || a.who.localeCompare(b.who) || a.machine.localeCompare(b.machine));
|
|
142
|
+
list.sort((a, b) => longest(b) - longest(a) || b.needs_you - a.needs_you || a.name.localeCompare(b.name));
|
|
143
|
+
machines.sort((a, b) => a.minutes_ago - b.minutes_ago || a.machine.localeCompare(b.machine));
|
|
144
|
+
const freshRows = list.flatMap((g) => g.rows).filter((r) => r.freshness === "fresh");
|
|
145
|
+
const totals = {
|
|
146
|
+
needs_you: freshRows.reduce((n, r) => n + r.needs_you, 0),
|
|
147
|
+
sessions: freshRows.reduce((n, r) => n + r.sessions, 0),
|
|
148
|
+
machines_fresh: machines.filter((m) => m.freshness === "fresh").length,
|
|
149
|
+
machines_quiet: machines.filter((m) => m.freshness === "quiet").length,
|
|
150
|
+
machines_silent: machines.filter((m) => m.freshness === "silent").length
|
|
151
|
+
};
|
|
152
|
+
let headline;
|
|
153
|
+
if (machines.length === 0) headline = scoped ? "No machine has reported a repository you can see." : "No machine has reported yet.";
|
|
154
|
+
else if (totals.machines_fresh === 0) headline = `No machine has reported in the last 5 minutes (${plural(machines.length, "machine", "machines")} known), so nothing below is current.`;
|
|
155
|
+
else if (totals.needs_you === 0) headline = `No session is waiting on a person: ${plural(totals.sessions, "session", "sessions")} on ${plural(totals.machines_fresh, "machine", "machines")} read.`;
|
|
156
|
+
else {
|
|
157
|
+
const top = freshRows.filter((r) => r.waiting_minutes !== null).sort((a, b) => b.waiting_minutes - a.waiting_minutes)[0];
|
|
158
|
+
const where = top ? ` The longest has waited ${duration(top.waiting_minutes)}: ${top.name}, ${top.who}.` : "";
|
|
159
|
+
headline = `${plural(totals.needs_you, "session is", "sessions are")} waiting on a person, on ${plural(totals.machines_fresh, "machine", "machines")}.${where}`;
|
|
160
|
+
}
|
|
161
|
+
const late = totals.machines_quiet + totals.machines_silent;
|
|
162
|
+
if (late > 0 && totals.machines_fresh > 0) headline += ` ${plural(late, "machine has", "machines have")} gone quiet and ${late === 1 ? "is" : "are"} not counted.`;
|
|
163
|
+
return { generated_at: new Date(now).toISOString(), headline, totals, groups: list, machines, scoped };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/page.ts
|
|
167
|
+
var esc = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
168
|
+
var STYLE = `
|
|
169
|
+
:root{--bg:#f7f6f2;--card:#fff;--fg:#1d1c19;--mut:#6b675e;--line:#dedbd2;--well:#f1efe9;--warn:#a1500a;--ok:#1f6b45;--bad:#a3262b;--link:#1d4f91}
|
|
170
|
+
@media (prefers-color-scheme:dark){:root{--bg:#161512;--card:#1f1e1a;--fg:#ece9e1;--mut:#a09c91;--line:#35332d;--well:#161512;--warn:#e0a25a;--ok:#7ccba0;--bad:#ef8a8e;--link:#8fb8ee}}
|
|
171
|
+
*{box-sizing:border-box}
|
|
172
|
+
body{margin:0;background:var(--bg);color:var(--fg);font:15px/1.5 system-ui,sans-serif}
|
|
173
|
+
main{max-width:1000px;margin:0 auto;padding:20px 16px 48px}
|
|
174
|
+
h1{font-size:22px;margin:0}h2{font-size:15px;margin:22px 0 8px}.head{margin:4px 0 0;font-weight:600}
|
|
175
|
+
.mut{color:var(--mut);font-size:12px}.ok{color:var(--ok)}.warn{color:var(--warn)}.bad{color:var(--bad)}.ok,.warn,.bad{font-size:12px;font-weight:600}
|
|
176
|
+
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;overflow:hidden;margin:10px 0}
|
|
177
|
+
.card h3{font-size:15px;margin:0;padding:10px 12px;word-break:break-word}.card h3 .mut{font-weight:400}
|
|
178
|
+
table{width:100%;border-collapse:collapse}th,td{text-align:left;padding:8px 12px;border-top:1px solid var(--line);vertical-align:top;font-weight:400}
|
|
179
|
+
thead th{font-size:12px;color:var(--mut);font-weight:600}tbody th{font-weight:600}
|
|
180
|
+
tr.quiet td,tr.quiet th,tr.quiet .warn,tr.quiet .bad,tr.quiet .ok{color:var(--mut)}
|
|
181
|
+
tr.asked td{border-top:0;padding-top:0}tr.asked td::before{content:none}
|
|
182
|
+
.q{background:var(--well);margin:6px 0 2px;padding:8px 10px;border-radius:8px;border-left:3px solid var(--warn)}.q p{margin:0;white-space:pre-wrap;word-break:break-word;font-size:14px}
|
|
183
|
+
.top{display:flex;justify-content:space-between;align-items:flex-start;gap:12px}
|
|
184
|
+
button{white-space:nowrap;font:inherit;font-size:14px;min-height:40px;border:1px solid var(--line);background:var(--card);color:var(--fg);border-radius:8px;padding:6px 14px;cursor:pointer}
|
|
185
|
+
button.primary{background:var(--fg);color:var(--bg);border-color:var(--fg);font-weight:600}
|
|
186
|
+
button:focus-visible,input:focus-visible,a:focus-visible{outline:2px solid var(--link);outline-offset:2px}
|
|
187
|
+
.tiles{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:14px 0 4px}
|
|
188
|
+
.tile{background:var(--card);border:1px solid var(--line);border-radius:10px;padding:10px 12px}.tile b{display:block;font-size:24px;line-height:1.2}.tile.hot b{color:var(--warn)}
|
|
189
|
+
table{table-layout:fixed}col.who{width:24%}col.n{width:13%}col.wait{width:21%}col.setup{width:17%}col.mail{width:12%}col.heard{width:13%}
|
|
190
|
+
input{font:inherit;width:100%;padding:8px 10px;border:1px solid var(--line);border-radius:8px;background:var(--card);color:var(--fg)}
|
|
191
|
+
label{display:block;font-weight:600;margin-bottom:6px}.pad{padding:16px}
|
|
192
|
+
ul{margin:0;padding:0;list-style:none}li{padding:6px 12px;border-top:1px solid var(--line)}li:first-child{border-top:0}
|
|
193
|
+
@media (max-width:760px){table,tbody{display:block}colgroup{display:none}.tile b{font-size:20px}thead{display:none}tr{display:block;border-top:1px solid var(--line);padding:6px 0}th,td{display:block;border:0;padding:2px 12px}td::before{content:attr(data-l) ": ";color:var(--mut);font-size:12px}}
|
|
194
|
+
`;
|
|
195
|
+
var heard = (minutes) => minutes < 1 ? "just now" : `${duration(minutes)} ago`;
|
|
196
|
+
var minutesSince = (iso, now) => Math.max(0, Math.floor((now - Date.parse(iso)) / 6e4));
|
|
197
|
+
var clock = (iso) => `${iso.slice(11, 16)} UTC`;
|
|
198
|
+
function row(r, now) {
|
|
199
|
+
const quiet = r.freshness !== "fresh";
|
|
200
|
+
const waiting = quiet ? '<span class="mut">not current</span>' : r.needs_you > 0 ? `<span class="warn">${r.needs_you} waiting${r.waiting_minutes !== null ? `, ${esc(duration(r.waiting_minutes))}` : ""}</span>` : '<span class="mut">none</span>';
|
|
201
|
+
const setup = !r.setup ? '<span class="mut">not checked</span>' : `${r.setup.score}% ${r.setup.fail > 0 ? `<span class="bad">${r.setup.fail} to fix</span>` : r.setup.warn > 0 ? `<span class="warn">${r.setup.warn} to look at</span>` : '<span class="ok">all good</span>'}`;
|
|
202
|
+
const mail = r.unread === null ? '<span class="mut">no inbox</span>' : r.unread === 0 ? '<span class="mut">none unread</span>' : `${r.unread} unread`;
|
|
203
|
+
const asked = (r.questions ?? []).map((q) => `<div class="q"><span class="mut">${esc(r.who)}'s session asked${q.asked_at ? ` ${esc(heard(minutesSince(q.asked_at, now)))}` : ""}</span><p>${esc(q.text)}</p></div>`).join("");
|
|
204
|
+
const askedRow = asked ? `<tr class="asked"><td colspan="6">${asked}</td></tr>` : "";
|
|
205
|
+
return `<tr${quiet ? ' class="quiet"' : ""}><th scope="row">${esc(r.who)} <span class="mut">${esc(r.machine)}</span></th><td data-l="Sessions">${r.sessions} <span class="mut">(${r.live} live)</span></td><td data-l="Waiting on a person">${waiting}</td><td data-l="Setup">${setup}</td><td data-l="Mail">${mail}</td><td data-l="Last heard"><span class="mut">${esc(heard(r.minutes_ago))}</span></td></tr>${askedRow}`;
|
|
206
|
+
}
|
|
207
|
+
function renderTeam(team, viewerName, version) {
|
|
208
|
+
const now = Date.parse(team.generated_at);
|
|
209
|
+
const t = team.totals;
|
|
210
|
+
const known = t.machines_fresh + t.machines_quiet + t.machines_silent;
|
|
211
|
+
const tiles = `<div class="tiles"><div class="tile${t.needs_you > 0 ? " hot" : ""}"><b>${t.needs_you}</b><span class="mut">waiting on a person</span></div><div class="tile"><b>${t.sessions}</b><span class="mut">${t.sessions === 1 ? "session" : "sessions"}</span></div><div class="tile"><b>${t.machines_fresh}<span class="mut"> of ${known}</span></b><span class="mut">${known === 1 ? "machine" : "machines"} reporting</span></div></div>`;
|
|
212
|
+
const groups = team.groups.map(
|
|
213
|
+
(g) => `<section class="card"><h3>${esc(g.name)}${g.remote ? ` <span class="mut">${esc(g.remote)}</span>` : ""}</h3><table><colgroup><col class="who"><col class="n"><col class="wait"><col class="setup"><col class="mail"><col class="heard"></colgroup><thead><tr><th scope="col">Who</th><th scope="col">Sessions</th><th scope="col">Waiting on a person</th><th scope="col">Setup</th><th scope="col">Mail</th><th scope="col">Last heard</th></tr></thead><tbody>${g.rows.map((r) => row(r, now)).join("")}</tbody></table></section>`
|
|
214
|
+
).join("");
|
|
215
|
+
const machines = team.machines.map((m) => `<li>${esc(m.who)} <span class="mut">${esc(m.machine)} \xB7 last heard ${esc(heard(m.minutes_ago))}</span>${m.freshness === "fresh" ? "" : ` <span class="warn">${m.freshness === "quiet" ? "quiet, not counted" : "silent for over a day, rows hidden"}</span>`}</li>`).join("");
|
|
216
|
+
return `<!doctype html>
|
|
217
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="refresh" content="60">
|
|
218
|
+
<title>${t.needs_you > 0 ? `(${t.needs_you}) ` : ""}JQ Deck: team</title><link rel="icon" href="data:,"><style>${STYLE}</style></head><body><main>
|
|
219
|
+
<div class="top"><div><h1>JQ Deck: team</h1><p class="head">${esc(team.headline)}</p></div><form method="post" action="/logout"><button>Sign out</button></form></div>
|
|
220
|
+
${known > 0 ? tiles : ""}
|
|
221
|
+
<p class="mut">Read at ${esc(clock(team.generated_at))}, signed in as ${esc(viewerName)}${team.scoped ? ", who sees some repositories only" : ""}. Reloads every minute. Read-only: answer a session where it is running.</p>
|
|
222
|
+
${groups || '<p class="card pad mut">No repository to show.</p>'}
|
|
223
|
+
<h2>Machines</h2>
|
|
224
|
+
<div class="card"><ul>${machines || '<li class="mut">None yet. On each machine: <code>jq-deck --watch --exec "jq-deck-server send --url THIS-ADDRESS"</code></li>'}</ul></div>
|
|
225
|
+
<p class="mut">A machine sends counts and scores: no folder path and no message. What a session asked is sent only where that machine opted the folder in. JQ Deck Server ${esc(version)}.</p>
|
|
226
|
+
</main></body></html>`;
|
|
227
|
+
}
|
|
228
|
+
function renderLogin(message) {
|
|
229
|
+
return `<!doctype html>
|
|
230
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
231
|
+
<title>JQ Deck: sign in</title><link rel="icon" href="data:,"><style>${STYLE}</style></head><body><main style="max-width:420px">
|
|
232
|
+
<h1>JQ Deck: team</h1>
|
|
233
|
+
<p class="mut" style="font-size:14px;margin:4px 0 12px">Which Claude Code sessions are waiting on a person, across this team's machines.</p>
|
|
234
|
+
<form class="card pad" method="post" action="/login">
|
|
235
|
+
${message ? `<p class="bad" role="alert">${esc(message)}</p>` : ""}
|
|
236
|
+
<label for="token">Viewer token</label>
|
|
237
|
+
<input id="token" name="token" type="password" autocomplete="current-password" placeholder="jqv_..." aria-describedby="token-help" required autofocus>
|
|
238
|
+
<p class="mut" id="token-help">It starts with <code>jqv_</code>. Whoever runs this server gives you one. A machine token (<code>jqm_</code>) does not sign in.</p>
|
|
239
|
+
<button class="primary">Sign in</button>
|
|
240
|
+
</form></main></body></html>`;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/store.ts
|
|
244
|
+
import { createHash, randomBytes, timingSafeEqual } from "crypto";
|
|
245
|
+
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
|
|
246
|
+
import path from "path";
|
|
247
|
+
var NAME = /^[a-z0-9][a-z0-9._-]{0,62}$/;
|
|
248
|
+
function checkName(name) {
|
|
249
|
+
if (!NAME.test(name)) throw new Error("a name is 1 to 63 of: a-z 0-9 . _ - (starting with a letter or digit)");
|
|
250
|
+
return name;
|
|
251
|
+
}
|
|
252
|
+
var sha = (s) => createHash("sha256").update(s).digest("hex");
|
|
253
|
+
var configFile = (dir) => path.join(dir, "config.json");
|
|
254
|
+
var reportFile = (dir, machine) => path.join(dir, "reports", `${checkName(machine)}.json`);
|
|
255
|
+
function writeAtomic(file, text2) {
|
|
256
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
257
|
+
writeFileSync(tmp, text2, { mode: 384 });
|
|
258
|
+
renameSync(tmp, file);
|
|
259
|
+
}
|
|
260
|
+
function initStore(dir) {
|
|
261
|
+
if (existsSync(configFile(dir))) throw new Error(`${dir} is already a jq-deck-server folder`);
|
|
262
|
+
mkdirSync(path.join(dir, "reports"), { recursive: true });
|
|
263
|
+
chmodSync(dir, 448);
|
|
264
|
+
writeAtomic(configFile(dir), JSON.stringify({ machines: [], viewers: [] }, null, 2) + "\n");
|
|
265
|
+
}
|
|
266
|
+
function readConfig(dir) {
|
|
267
|
+
if (!existsSync(configFile(dir))) throw new Error(`not a jq-deck-server folder (run: jq-deck-server init ${dir})`);
|
|
268
|
+
const raw = JSON.parse(readFileSync(configFile(dir), "utf8"));
|
|
269
|
+
return { machines: Array.isArray(raw?.machines) ? raw.machines : [], viewers: Array.isArray(raw?.viewers) ? raw.viewers : [] };
|
|
270
|
+
}
|
|
271
|
+
function writeConfig(dir, config) {
|
|
272
|
+
writeAtomic(configFile(dir), JSON.stringify(config, null, 2) + "\n");
|
|
273
|
+
}
|
|
274
|
+
function taken(config, name) {
|
|
275
|
+
return config.machines.some((m) => m.name === name) || config.viewers.some((v) => v.name === name);
|
|
276
|
+
}
|
|
277
|
+
function addMachine(dir, name, who) {
|
|
278
|
+
const config = readConfig(dir);
|
|
279
|
+
if (taken(config, checkName(name))) throw new Error(`the name ${name} is in use`);
|
|
280
|
+
const label = who.trim().replace(/[\u0000-\u001f\u007f]/g, "").slice(0, 60);
|
|
281
|
+
if (!label) throw new Error("--who needs a name to show on the board");
|
|
282
|
+
const token = `jqm_${randomBytes(32).toString("base64url")}`;
|
|
283
|
+
config.machines.push({ name, who: label, token_sha256: sha(token) });
|
|
284
|
+
writeConfig(dir, config);
|
|
285
|
+
return token;
|
|
286
|
+
}
|
|
287
|
+
function addViewer(dir, name, repos) {
|
|
288
|
+
const config = readConfig(dir);
|
|
289
|
+
if (taken(config, checkName(name))) throw new Error(`the name ${name} is in use`);
|
|
290
|
+
const token = `jqv_${randomBytes(32).toString("base64url")}`;
|
|
291
|
+
config.viewers.push({ name, token_sha256: sha(token), ...repos && repos.length ? { repos } : {} });
|
|
292
|
+
writeConfig(dir, config);
|
|
293
|
+
return token;
|
|
294
|
+
}
|
|
295
|
+
function remove(dir, name) {
|
|
296
|
+
const config = readConfig(dir);
|
|
297
|
+
if (!taken(config, checkName(name))) return false;
|
|
298
|
+
config.machines = config.machines.filter((m) => m.name !== name);
|
|
299
|
+
config.viewers = config.viewers.filter((v) => v.name !== name);
|
|
300
|
+
writeConfig(dir, config);
|
|
301
|
+
rmSync(reportFile(dir, name), { force: true });
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
function match(list, token) {
|
|
305
|
+
if (!token || token.length > 200) return null;
|
|
306
|
+
const given = Buffer.from(sha(token), "hex");
|
|
307
|
+
let found = null;
|
|
308
|
+
for (const item of list) {
|
|
309
|
+
const want = Buffer.from(String(item.token_sha256), "hex");
|
|
310
|
+
if (want.length === given.length && timingSafeEqual(want, given)) found = item;
|
|
311
|
+
}
|
|
312
|
+
return found;
|
|
313
|
+
}
|
|
314
|
+
var machineFor = (config, token) => match(config.machines, token);
|
|
315
|
+
var viewerFor = (config, token) => match(config.viewers, token);
|
|
316
|
+
function saveReport(dir, machine, report, now) {
|
|
317
|
+
const stored = { machine: machine.name, who: machine.who, received_at: new Date(now).toISOString(), report };
|
|
318
|
+
writeAtomic(reportFile(dir, machine.name), JSON.stringify(stored));
|
|
319
|
+
}
|
|
320
|
+
function readReports(dir, config) {
|
|
321
|
+
const known = new Map(config.machines.map((m) => [m.name, m]));
|
|
322
|
+
const out = [];
|
|
323
|
+
const folder = path.join(dir, "reports");
|
|
324
|
+
if (!existsSync(folder)) return out;
|
|
325
|
+
for (const file of readdirSync(folder).filter((f) => f.endsWith(".json"))) {
|
|
326
|
+
const machine = known.get(file.slice(0, -5));
|
|
327
|
+
if (!machine) continue;
|
|
328
|
+
try {
|
|
329
|
+
const stored = JSON.parse(readFileSync(path.join(folder, file), "utf8"));
|
|
330
|
+
out.push({ ...stored, machine: machine.name, who: machine.who });
|
|
331
|
+
} catch {
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return out;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/server.ts
|
|
338
|
+
var COOKIE = "jq_deck";
|
|
339
|
+
var HTML = { "content-type": "text/html; charset=utf-8" };
|
|
340
|
+
var TEXT = { "content-type": "text/plain; charset=utf-8" };
|
|
341
|
+
var JSON_TYPE = { "content-type": "application/json; charset=utf-8" };
|
|
342
|
+
var text = (status, body, headers = {}) => ({ status, headers: { ...TEXT, ...headers }, body });
|
|
343
|
+
var bearer = (h) => h && /^Bearer\s+\S+$/i.test(h) ? h.replace(/^Bearer\s+/i, "") : null;
|
|
344
|
+
function cookieToken(header) {
|
|
345
|
+
for (const part of (header || "").split(";")) {
|
|
346
|
+
const [k, ...v] = part.trim().split("=");
|
|
347
|
+
if (k === COOKIE) return v.join("=") || null;
|
|
348
|
+
}
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
var cookie = (ctx, value, maxAge) => `${COOKIE}=${value}; Path=/; HttpOnly; SameSite=Strict; Max-Age=${maxAge}${ctx.secureCookie ? "; Secure" : ""}`;
|
|
352
|
+
function handle(req, ctx) {
|
|
353
|
+
const now = (ctx.now ?? Date.now)();
|
|
354
|
+
const route = `${req.method} ${req.path}`;
|
|
355
|
+
if (route === "GET /healthz") return text(200, "ok");
|
|
356
|
+
const config = readConfig(ctx.dir);
|
|
357
|
+
if (route === "POST /report") {
|
|
358
|
+
const machine = machineFor(config, bearer(req.authorization));
|
|
359
|
+
if (!machine) return text(401, "unknown machine token");
|
|
360
|
+
let report;
|
|
361
|
+
try {
|
|
362
|
+
report = sanitizeReport(JSON.parse(req.body));
|
|
363
|
+
} catch (e) {
|
|
364
|
+
return text(400, `not a report: ${e?.message || e}`);
|
|
365
|
+
}
|
|
366
|
+
saveReport(ctx.dir, machine, report, now);
|
|
367
|
+
return { status: 204, headers: {}, body: "" };
|
|
368
|
+
}
|
|
369
|
+
if (route === "GET /login") return { status: 200, headers: HTML, body: renderLogin(null) };
|
|
370
|
+
if (route === "POST /login") {
|
|
371
|
+
const token = new URLSearchParams(req.body).get("token")?.trim();
|
|
372
|
+
if (!viewerFor(config, token)) {
|
|
373
|
+
const why = machineFor(config, token) ? "That is a machine token. Sign in with a viewer token, which starts with jqv_." : "That token is not known to this server.";
|
|
374
|
+
return { status: 401, headers: HTML, body: renderLogin(why) };
|
|
375
|
+
}
|
|
376
|
+
return { status: 303, headers: { location: "/", "set-cookie": cookie(ctx, token, 30 * 86400) }, body: "" };
|
|
377
|
+
}
|
|
378
|
+
if (route === "POST /logout") return { status: 303, headers: { location: "/login", "set-cookie": cookie(ctx, "", 0) }, body: "" };
|
|
379
|
+
if (route === "GET /" || route === "GET /api/team") {
|
|
380
|
+
const api = req.path === "/api/team";
|
|
381
|
+
const viewer = viewerFor(config, cookieToken(req.cookie)) ?? (api ? viewerFor(config, bearer(req.authorization)) : null);
|
|
382
|
+
if (!viewer) return api ? text(401, "a viewer token is needed") : { status: 303, headers: { location: "/login" }, body: "" };
|
|
383
|
+
const team = buildTeam(readReports(ctx.dir, config), now, viewer);
|
|
384
|
+
return api ? { status: 200, headers: JSON_TYPE, body: JSON.stringify(team, null, 2) } : { status: 200, headers: HTML, body: renderTeam(team, viewer.name, ctx.version) };
|
|
385
|
+
}
|
|
386
|
+
return text(404, "not found");
|
|
387
|
+
}
|
|
388
|
+
var SECURITY_HEADERS = {
|
|
389
|
+
"cache-control": "no-store",
|
|
390
|
+
"x-frame-options": "DENY",
|
|
391
|
+
"x-content-type-options": "nosniff",
|
|
392
|
+
"referrer-policy": "no-referrer",
|
|
393
|
+
"content-security-policy": "default-src 'none'; style-src 'unsafe-inline'; img-src data:; form-action 'self'; frame-ancestors 'none'; base-uri 'none'"
|
|
394
|
+
};
|
|
395
|
+
function startServer(ctx, port, host, onListen) {
|
|
396
|
+
const server = createServer((req, res) => {
|
|
397
|
+
const chunks = [];
|
|
398
|
+
let size = 0;
|
|
399
|
+
let tooBig = false;
|
|
400
|
+
req.on("data", (chunk) => {
|
|
401
|
+
size += chunk.length;
|
|
402
|
+
if (size > MAX_BODY_BYTES) tooBig = true;
|
|
403
|
+
else chunks.push(chunk);
|
|
404
|
+
});
|
|
405
|
+
req.on("end", () => {
|
|
406
|
+
let reply;
|
|
407
|
+
try {
|
|
408
|
+
reply = tooBig ? text(413, "the body is too large") : handle({ method: req.method || "GET", path: (req.url || "/").split("?")[0], authorization: req.headers.authorization, cookie: req.headers.cookie, body: Buffer.concat(chunks).toString("utf8") }, ctx);
|
|
409
|
+
} catch (e) {
|
|
410
|
+
console.error("jq-deck-server:", e?.message || e);
|
|
411
|
+
reply = text(500, "server error");
|
|
412
|
+
}
|
|
413
|
+
res.writeHead(reply.status, { ...SECURITY_HEADERS, ...reply.headers });
|
|
414
|
+
res.end(reply.body);
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
server.listen(port, host, () => {
|
|
418
|
+
const address = server.address();
|
|
419
|
+
onListen?.(typeof address === "object" && address ? address.port : port);
|
|
420
|
+
});
|
|
421
|
+
return server;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/cli.ts
|
|
425
|
+
var DEFAULT_PORT = 4320;
|
|
426
|
+
var LOOPBACK = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "::1"]);
|
|
427
|
+
var VALUE_OPTIONS = /* @__PURE__ */ new Set(["--dir", "--who", "--repos", "--port", "--host", "--url"]);
|
|
428
|
+
var FLAGS = /* @__PURE__ */ new Set(["--plain-http"]);
|
|
429
|
+
function parse(argv) {
|
|
430
|
+
const [command = "", ...rest] = argv;
|
|
431
|
+
const positional = [];
|
|
432
|
+
const options = {};
|
|
433
|
+
const flags = /* @__PURE__ */ new Set();
|
|
434
|
+
for (let i = 0; i < rest.length; i++) {
|
|
435
|
+
const a = rest[i];
|
|
436
|
+
if (VALUE_OPTIONS.has(a)) {
|
|
437
|
+
const v = rest[++i];
|
|
438
|
+
if (v === void 0 || v.startsWith("--")) throw new Error(`${a} needs a value`);
|
|
439
|
+
options[a] = v;
|
|
440
|
+
} else if (FLAGS.has(a)) flags.add(a);
|
|
441
|
+
else if (a.startsWith("--")) throw new Error(`unknown option: ${a}`);
|
|
442
|
+
else positional.push(a);
|
|
443
|
+
}
|
|
444
|
+
return { command, positional, options, flags };
|
|
445
|
+
}
|
|
446
|
+
function dirOf(p, env) {
|
|
447
|
+
const dir = p.options["--dir"] || env.JQ_DECK_SERVER_DIR;
|
|
448
|
+
if (!dir) throw new Error("which folder? pass --dir DIR or set $JQ_DECK_SERVER_DIR");
|
|
449
|
+
return path2.resolve(dir);
|
|
450
|
+
}
|
|
451
|
+
async function stdin() {
|
|
452
|
+
const chunks = [];
|
|
453
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
454
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
455
|
+
}
|
|
456
|
+
async function run(argv, version, env = process.env) {
|
|
457
|
+
const p = parse(argv);
|
|
458
|
+
const name = () => {
|
|
459
|
+
if (!p.positional[0]) throw new Error(`${p.command} needs a name`);
|
|
460
|
+
return p.positional[0];
|
|
461
|
+
};
|
|
462
|
+
switch (p.command) {
|
|
463
|
+
case "init": {
|
|
464
|
+
const dir = path2.resolve(p.positional[0] || p.options["--dir"] || env.JQ_DECK_SERVER_DIR || "");
|
|
465
|
+
if (!p.positional[0] && !p.options["--dir"] && !env.JQ_DECK_SERVER_DIR) throw new Error("usage: jq-deck-server init DIR");
|
|
466
|
+
initStore(dir);
|
|
467
|
+
console.log(`made ${dir}
|
|
468
|
+
next: export JQ_DECK_SERVER_DIR="${dir}", then add-machine and add-viewer`);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
case "add-machine": {
|
|
472
|
+
const token = addMachine(dirOf(p, env), name(), p.options["--who"] || "");
|
|
473
|
+
console.log(`machine ${name()} added. Its token, shown once:
|
|
474
|
+
|
|
475
|
+
${token}
|
|
476
|
+
|
|
477
|
+
On that machine:
|
|
478
|
+
export JQ_DECK_TOKEN=<the token>
|
|
479
|
+
jq-deck --watch --exec "jq-deck-server send --url <this server's address>"`);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
case "add-viewer": {
|
|
483
|
+
const repos = (p.options["--repos"] || "").split(",").map((r) => r.trim()).filter(Boolean);
|
|
484
|
+
const token = addViewer(dirOf(p, env), name(), repos);
|
|
485
|
+
console.log(`viewer ${name()} added${repos.length ? `, limited to: ${repos.join(", ")}` : ", who sees every repository"}. Their token, shown once:
|
|
486
|
+
|
|
487
|
+
${token}
|
|
488
|
+
|
|
489
|
+
They paste it into the sign-in page.`);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
case "remove": {
|
|
493
|
+
if (!remove(dirOf(p, env), name())) throw new Error(`no machine or viewer is named ${name()}`);
|
|
494
|
+
console.log(`removed ${name()}. Its token no longer works.`);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
case "list": {
|
|
498
|
+
const config = readConfig(dirOf(p, env));
|
|
499
|
+
for (const m of config.machines) console.log(`machine ${m.name} (${m.who})`);
|
|
500
|
+
for (const v of config.viewers) console.log(`viewer ${v.name} ${v.repos?.length ? `sees: ${v.repos.join(", ")}` : "sees everything"}`);
|
|
501
|
+
if (!config.machines.length && !config.viewers.length) console.log("no machine or viewer yet");
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
case "send": {
|
|
505
|
+
if (!p.options["--url"]) throw new Error("send needs --url (the team server's address)");
|
|
506
|
+
await send(p.options["--url"], env.JQ_DECK_TOKEN, await stdin());
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
case "serve": {
|
|
510
|
+
const dir = dirOf(p, env);
|
|
511
|
+
readConfig(dir);
|
|
512
|
+
const port = Number(p.options["--port"] ?? DEFAULT_PORT);
|
|
513
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("--port needs a number from 1 to 65535");
|
|
514
|
+
const host = p.options["--host"] || "127.0.0.1";
|
|
515
|
+
const local = LOOPBACK.has(host);
|
|
516
|
+
const secureCookie = !local && !p.flags.has("--plain-http");
|
|
517
|
+
startServer({ dir, version, secureCookie }, port, host, (bound) => {
|
|
518
|
+
console.log(`jq-deck-server: http://${host}:${bound} (Ctrl-C to stop), data in ${dir}`);
|
|
519
|
+
if (!local) console.log(secureCookie ? "jq-deck-server: reachable from other machines. Put HTTPS in front of it: sign-in needs it." : "jq-deck-server: WARNING: reachable from other machines over plain HTTP. Tokens travel in the clear.");
|
|
520
|
+
});
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
default:
|
|
524
|
+
throw new Error(p.command ? `unknown command: ${p.command} (try --help)` : "which command? (try --help)");
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// src/main.ts
|
|
529
|
+
var VERSION = true ? "0.2.2" : "dev";
|
|
530
|
+
var HELP = `JQ Deck Server ${VERSION}: one page for a team's Claude Code sessions.
|
|
531
|
+
|
|
532
|
+
On the server:
|
|
533
|
+
jq-deck-server init DIR make the data folder
|
|
534
|
+
jq-deck-server add-machine NAME --who "Dana" allow a machine to report; prints its token once
|
|
535
|
+
jq-deck-server add-viewer NAME allow a person to look; prints their token once
|
|
536
|
+
--repos shop,api ...at these repositories only
|
|
537
|
+
jq-deck-server remove NAME a machine or a viewer; the token stops working
|
|
538
|
+
jq-deck-server list
|
|
539
|
+
jq-deck-server serve http://127.0.0.1:${DEFAULT_PORT}
|
|
540
|
+
--port NUMBER --host ADDRESS --host 0.0.0.0 to accept other machines
|
|
541
|
+
--plain-http allow sign-in without HTTPS (not advised)
|
|
542
|
+
|
|
543
|
+
On each machine that reports:
|
|
544
|
+
JQ_DECK_TOKEN=... jq-deck --watch --exec "jq-deck-server send --url ADDRESS"
|
|
545
|
+
|
|
546
|
+
The folder comes from --dir or $JQ_DECK_SERVER_DIR. A report holds counts and scores
|
|
547
|
+
per repository: no folder path and no message. What a waiting session asked is in a
|
|
548
|
+
report only when that machine opted the folder in (jq-deck --send-questions). The server keeps the
|
|
549
|
+
latest report from each machine, as files in that folder, and calls nothing.
|
|
550
|
+
|
|
551
|
+
Unofficial. Not affiliated with or endorsed by Anthropic.`;
|
|
552
|
+
var args = process.argv.slice(2);
|
|
553
|
+
if (args.includes("--help") || args.includes("-h") || args.length === 0) console.log(HELP);
|
|
554
|
+
else if (args.includes("--version") || args.includes("-v")) console.log(VERSION);
|
|
555
|
+
else
|
|
556
|
+
run(args, VERSION).catch((error) => {
|
|
557
|
+
console.error(`jq-deck-server: ${error.message || error}`);
|
|
558
|
+
process.exit(1);
|
|
559
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const DEFAULT_PORT = 4320;
|
|
2
|
+
export interface Parsed {
|
|
3
|
+
command: string;
|
|
4
|
+
positional: string[];
|
|
5
|
+
options: Record<string, string>;
|
|
6
|
+
flags: Set<string>;
|
|
7
|
+
}
|
|
8
|
+
export declare function parse(argv: string[]): Parsed;
|
|
9
|
+
export declare function run(argv: string[], version: string, env?: Record<string, string | undefined>): Promise<void>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The report rules, the store and the team rules, for running the board inside your own server. */
|
|
2
|
+
export * from './report.js';
|
|
3
|
+
export * from './team.js';
|
|
4
|
+
export { addMachine, addViewer, checkName, initStore, machineFor, readConfig, readReports, remove, saveReport, viewerFor, type Config, type Machine, type StoredReport, type Viewer } from './store.js';
|
|
5
|
+
export { handle, SECURITY_HEADERS, startServer, type Req, type Res, type ServerContext } from './server.js';
|
|
6
|
+
export { renderLogin, renderTeam } from './page.js';
|
|
7
|
+
export { reportUrl, send } from './send.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The team page and the sign-in page. One HTML string each, no script, no
|
|
3
|
+
* outside request. Every value is escaped: names come from other machines.
|
|
4
|
+
*/
|
|
5
|
+
import { type Team } from './team.js';
|
|
6
|
+
/** "23:34 UTC": the page has no script, so it cannot show the reader's own time zone. */
|
|
7
|
+
export declare const clock: (iso: string) => string;
|
|
8
|
+
export declare function renderTeam(team: Team, viewerName: string, version: string): string;
|
|
9
|
+
export declare function renderLogin(message: string | null): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The report one machine sends: counts and scores per repository. This file is
|
|
3
|
+
* the whole of what the server will accept and keep. Anything not named here is
|
|
4
|
+
* dropped, so a sender cannot put a path, a question or a message on the board
|
|
5
|
+
* even by mistake.
|
|
6
|
+
*/
|
|
7
|
+
export interface RepoReport {
|
|
8
|
+
name: string;
|
|
9
|
+
/** host/owner/name of the origin remote. Names the same repository on two machines. */
|
|
10
|
+
remote: string | null;
|
|
11
|
+
sessions: number;
|
|
12
|
+
live: number;
|
|
13
|
+
needs_you: number;
|
|
14
|
+
abandoned: number;
|
|
15
|
+
waiting_since: string | null;
|
|
16
|
+
last_activity_at: string | null;
|
|
17
|
+
setup: {
|
|
18
|
+
score: number;
|
|
19
|
+
fail: number;
|
|
20
|
+
warn: number;
|
|
21
|
+
} | null;
|
|
22
|
+
/** null when the machine has no inbox for this repository: unknown, never zero. */
|
|
23
|
+
unread: number | null;
|
|
24
|
+
/**
|
|
25
|
+
* What each waiting session asked. Present only when the machine opted that
|
|
26
|
+
* folder in to sending it. The one free-text field in a report.
|
|
27
|
+
*/
|
|
28
|
+
questions?: {
|
|
29
|
+
asked_at: string | null;
|
|
30
|
+
text: string;
|
|
31
|
+
}[];
|
|
32
|
+
}
|
|
33
|
+
export interface TeamReport {
|
|
34
|
+
v: 1;
|
|
35
|
+
generated_at: string;
|
|
36
|
+
repos: RepoReport[];
|
|
37
|
+
}
|
|
38
|
+
export declare const MAX_REPOS = 200;
|
|
39
|
+
export declare const MAX_BODY_BYTES: number;
|
|
40
|
+
export declare const MAX_QUESTIONS = 20;
|
|
41
|
+
export declare const MAX_QUESTION_CHARS = 400;
|
|
42
|
+
/** Throws with a plain reason when the value is not a report. Returns only the fields above. */
|
|
43
|
+
export declare function sanitizeReport(value: unknown): TeamReport;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** The address to post to. Plain HTTP is refused except to this machine: the token would travel in the clear. */
|
|
2
|
+
export declare function reportUrl(base: string): URL;
|
|
3
|
+
export declare function send(base: string, token: string | undefined, input: string, post?: typeof fetch): Promise<void>;
|