@bli-cockpit/cli 0.2.38 → 0.2.40
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/dist/commands/brief.js +133 -0
- package/dist/commands/cli-io.js +33 -1
- package/dist/commands/correct.js +149 -0
- package/dist/commands/jarvis.js +98 -15
- package/dist/commands/local-args.js +565 -3
- package/dist/commands/local-help.js +169 -4
- package/dist/commands/local.js +91 -3
- package/dist/commands/notes-file.js +129 -0
- package/dist/commands/notes.js +488 -0
- package/dist/commands/public-root.js +1 -1
- package/dist/commands/scout-render.js +172 -0
- package/dist/commands/scout.js +158 -0
- package/dist/commands/settings-render.js +137 -0
- package/dist/commands/settings.js +378 -0
- package/dist/commands/team.js +111 -0
- package/dist/commands/tower-command.js +111 -0
- package/dist/commands/workbook-render.js +196 -0
- package/dist/commands/workbook.js +180 -0
- package/package.json +1 -1
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `cockpit notes` — the meeting-notes surface in the terminal (BLI-3459).
|
|
3
|
+
*
|
|
4
|
+
* The library, one note, your own shelf, putting a note in from a file or the
|
|
5
|
+
* clipboard, sharing it and taking it back, and moving it to another shelf.
|
|
6
|
+
* Everything `/meeting-notes` does in a browser, typed.
|
|
7
|
+
*
|
|
8
|
+
* This file owns terminal input and output ONLY. It holds no access rule, no
|
|
9
|
+
* naming scheme and no idea what a note may contain: every command is one call
|
|
10
|
+
* to a dashboard route, which runs the same code the page runs. In particular a
|
|
11
|
+
* paste goes through `POST /api/notes/upload` and never near the ingester
|
|
12
|
+
* directly — the route is what supplies `submittedAt` (BLI-3336), which is the
|
|
13
|
+
* whole reason a note that names no day of its own is stored as a dated context
|
|
14
|
+
* note instead of refused.
|
|
15
|
+
*
|
|
16
|
+
* Two contracts the shape enforces:
|
|
17
|
+
*
|
|
18
|
+
* - **stdout is the answer, stderr is the commentary.** A `--json` run puts
|
|
19
|
+
* exactly one object on stdout; progress, receipts and reasons go to stderr,
|
|
20
|
+
* the same split the rest of the CLI keeps.
|
|
21
|
+
* - **Sharing is a deliberate act.** `share` asks in a terminal and requires
|
|
22
|
+
* `--yes` without one. `--json` implies `--yes`, because a machine-readable
|
|
23
|
+
* run has nobody to ask and asking it to guess is worse than the flag it
|
|
24
|
+
* already typed the command for.
|
|
25
|
+
*/
|
|
26
|
+
import { isInteractiveStdin, readLine, readPipedText, writeLine, yesByDefault } from "./cli-io.js";
|
|
27
|
+
import { NOTE_SLOW_UPLOAD_BYTES, decodeTextBytes, noteFileRefusalSentence, readNoteFile, } from "./notes-file.js";
|
|
28
|
+
import { loadPairedSession, towerFailureDetail, towerRequest, } from "../tower-client.js";
|
|
29
|
+
import { readResponseJson } from "../upload-http.js";
|
|
30
|
+
/**
|
|
31
|
+
* The upload route's own ceiling is `maxDuration = 300` — reading a note is one
|
|
32
|
+
* model call over the whole file. The client waits slightly longer so the
|
|
33
|
+
* server's named failure wins the race whenever it manages to send one.
|
|
34
|
+
*/
|
|
35
|
+
const UPLOAD_DEADLINE_MS = 305_000;
|
|
36
|
+
const READ_DEADLINE_MS = 60_000;
|
|
37
|
+
const PASTE_MAX_CHARS = 2_000_000;
|
|
38
|
+
const TAG = "[notes cli]";
|
|
39
|
+
export async function runNotes(command, io) {
|
|
40
|
+
const session = await loadPairedSession("notes", command.homeDir);
|
|
41
|
+
const door = {
|
|
42
|
+
dashboardUrl: command.dashboardUrl ?? session.dashboard_url,
|
|
43
|
+
deviceToken: session.device_token,
|
|
44
|
+
io,
|
|
45
|
+
json: command.json,
|
|
46
|
+
};
|
|
47
|
+
switch (command.action) {
|
|
48
|
+
case "list":
|
|
49
|
+
return listNotes(command, door);
|
|
50
|
+
case "shelves":
|
|
51
|
+
return listShelves(command, door);
|
|
52
|
+
case "show":
|
|
53
|
+
return showNote(command, door);
|
|
54
|
+
case "shelf":
|
|
55
|
+
return showShelf(command, door);
|
|
56
|
+
case "upload":
|
|
57
|
+
return uploadNotes(command, door);
|
|
58
|
+
case "paste":
|
|
59
|
+
return pasteNote(command, door);
|
|
60
|
+
case "share":
|
|
61
|
+
case "unshare":
|
|
62
|
+
return shareNote(command, door);
|
|
63
|
+
case "move":
|
|
64
|
+
return moveNote(command, door);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function libraryQuery(command) {
|
|
68
|
+
const query = new URLSearchParams();
|
|
69
|
+
if (command.series)
|
|
70
|
+
query.set("series", command.series);
|
|
71
|
+
if (command.meetingKind)
|
|
72
|
+
query.set("kind", command.meetingKind);
|
|
73
|
+
if (command.since)
|
|
74
|
+
query.set("since", command.since);
|
|
75
|
+
if (command.until)
|
|
76
|
+
query.set("until", command.until);
|
|
77
|
+
if (command.limit !== undefined)
|
|
78
|
+
query.set("limit", String(command.limit));
|
|
79
|
+
const rendered = query.toString();
|
|
80
|
+
return rendered === "" ? "" : `?${rendered}`;
|
|
81
|
+
}
|
|
82
|
+
async function listNotes(command, door) {
|
|
83
|
+
const answer = await ask(door, {
|
|
84
|
+
path: `/api/notes/library${libraryQuery(command)}`,
|
|
85
|
+
method: "GET",
|
|
86
|
+
label: "notes list",
|
|
87
|
+
timeoutMs: READ_DEADLINE_MS,
|
|
88
|
+
});
|
|
89
|
+
if (!answer.ok)
|
|
90
|
+
return fail(door, answer.reason, answer.detail);
|
|
91
|
+
const body = answer.body;
|
|
92
|
+
if (door.json)
|
|
93
|
+
return emit(door, body);
|
|
94
|
+
sayScope(door, body);
|
|
95
|
+
const series = body.series ?? [];
|
|
96
|
+
if (series.length === 0) {
|
|
97
|
+
writeLine(door.io.stdout, "No meeting notes matched.");
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
for (const one of series) {
|
|
101
|
+
writeLine(door.io.stdout, "");
|
|
102
|
+
writeLine(door.io.stdout, `${one.heading} (${one.notes.length})`);
|
|
103
|
+
for (const note of one.notes) {
|
|
104
|
+
const who = note.participants.length > 0 ? ` — ${note.participants.join(", ")}` : "";
|
|
105
|
+
writeLine(door.io.stdout, ` ${note.meetingDate} ${note.id} ${note.fileName}${who}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
writeLine(door.io.stdout, "");
|
|
109
|
+
writeLine(door.io.stdout, `${body.count ?? 0} note(s)${body.more ? ", and more exist beyond the limit" : ""}.`);
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
async function listShelves(command, door) {
|
|
113
|
+
const answer = await ask(door, {
|
|
114
|
+
path: `/api/notes/library${libraryQuery(command)}`,
|
|
115
|
+
method: "GET",
|
|
116
|
+
label: "notes shelves",
|
|
117
|
+
timeoutMs: READ_DEADLINE_MS,
|
|
118
|
+
});
|
|
119
|
+
if (!answer.ok)
|
|
120
|
+
return fail(door, answer.reason, answer.detail);
|
|
121
|
+
const body = answer.body;
|
|
122
|
+
const shelves = (body.series ?? []).map((one) => ({
|
|
123
|
+
shelf: one.heading,
|
|
124
|
+
notes: one.notes.length,
|
|
125
|
+
// A shelf somebody typed, rather than the one a kind implies. Only the
|
|
126
|
+
// first kind is reported: a shelf is free text and can hold any of them.
|
|
127
|
+
custom: (body.categories ?? []).includes(one.heading),
|
|
128
|
+
}));
|
|
129
|
+
if (door.json)
|
|
130
|
+
return emit(door, { scope: body.scope, shelves });
|
|
131
|
+
sayScope(door, body);
|
|
132
|
+
if (shelves.length === 0) {
|
|
133
|
+
writeLine(door.io.stdout, "No shelves yet.");
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
for (const shelf of shelves) {
|
|
137
|
+
writeLine(door.io.stdout, `${String(shelf.notes).padStart(4)} ${shelf.shelf}${shelf.custom ? "" : " (from the meeting kind)"}`);
|
|
138
|
+
}
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
async function showNote(command, door) {
|
|
142
|
+
const answer = await ask(door, {
|
|
143
|
+
path: `/api/notes/library/${encodeURIComponent(command.noteId ?? "")}`,
|
|
144
|
+
method: "GET",
|
|
145
|
+
label: "notes show",
|
|
146
|
+
timeoutMs: READ_DEADLINE_MS,
|
|
147
|
+
});
|
|
148
|
+
if (!answer.ok)
|
|
149
|
+
return fail(door, answer.reason, answer.detail);
|
|
150
|
+
const body = answer.body;
|
|
151
|
+
if (door.json)
|
|
152
|
+
return emit(door, body);
|
|
153
|
+
const note = body.note;
|
|
154
|
+
if (!note)
|
|
155
|
+
return fail(door, "no_note_in_answer", "Tower answered without a note.");
|
|
156
|
+
sayScope(door, body);
|
|
157
|
+
writeLine(door.io.stdout, note.title);
|
|
158
|
+
writeLine(door.io.stdout, `${note.meetingDate} · ${note.shelf} · ${note.fileName} · ${note.lineCount} lines`);
|
|
159
|
+
if (note.participants.length > 0) {
|
|
160
|
+
writeLine(door.io.stdout, `In the room: ${note.participants.join(", ")}`);
|
|
161
|
+
}
|
|
162
|
+
writeLine(door.io.stdout, note.visibility);
|
|
163
|
+
writeLine(door.io.stdout, "");
|
|
164
|
+
writeLine(door.io.stdout, note.content);
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
167
|
+
async function showShelf(command, door) {
|
|
168
|
+
const query = command.limit === undefined ? "" : `?limit=${command.limit}`;
|
|
169
|
+
const answer = await ask(door, {
|
|
170
|
+
path: `/api/notes/shelf${query}`,
|
|
171
|
+
method: "GET",
|
|
172
|
+
label: "notes shelf",
|
|
173
|
+
timeoutMs: READ_DEADLINE_MS,
|
|
174
|
+
});
|
|
175
|
+
if (!answer.ok)
|
|
176
|
+
return fail(door, answer.reason, answer.detail);
|
|
177
|
+
const body = answer.body;
|
|
178
|
+
if (door.json)
|
|
179
|
+
return emit(door, body);
|
|
180
|
+
sayScope(door, body);
|
|
181
|
+
const notes = body.notes ?? [];
|
|
182
|
+
if (notes.length === 0) {
|
|
183
|
+
writeLine(door.io.stdout, "You have not put any notes in yet.");
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
for (const note of notes) {
|
|
187
|
+
const counts = note.countsKnown
|
|
188
|
+
? `${note.statements} statements, ${note.openToTheTeam} open to the team, ${note.keptBack} kept back`
|
|
189
|
+
: "counts unknown on this server";
|
|
190
|
+
writeLine(door.io.stdout, `${note.meetingDate} ${note.id} ${note.shared ? "shared " : "yours "} ${note.name}`);
|
|
191
|
+
writeLine(door.io.stdout, ` ${counts}`);
|
|
192
|
+
}
|
|
193
|
+
return 0;
|
|
194
|
+
}
|
|
195
|
+
async function uploadNotes(command, door) {
|
|
196
|
+
const paths = command.paths ?? [];
|
|
197
|
+
const results = [];
|
|
198
|
+
let worstExit = 0;
|
|
199
|
+
for (const filePath of paths) {
|
|
200
|
+
// Read and screen locally BEFORE any network call — a refusal here never
|
|
201
|
+
// reaches the dashboard, same discipline as `cockpit jarvis --image`.
|
|
202
|
+
const read = await readNoteFile(filePath);
|
|
203
|
+
if (!read.ok) {
|
|
204
|
+
const sentence = noteFileRefusalSentence(read.refusal, filePath);
|
|
205
|
+
writeLine(door.io.stderr, `${TAG} file refused ${JSON.stringify({ reason: read.refusal, detail: read.detail })}`);
|
|
206
|
+
if (!door.json)
|
|
207
|
+
writeLine(door.io.stderr, sentence);
|
|
208
|
+
results.push({ path: filePath, ok: false, reason: read.refusal });
|
|
209
|
+
worstExit = 1;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (read.bytes.byteLength >= NOTE_SLOW_UPLOAD_BYTES) {
|
|
213
|
+
// The route reads the whole note with one model call and may take
|
|
214
|
+
// minutes. A still cursor reads as a hang, so say what is happening.
|
|
215
|
+
writeLine(door.io.stderr, `Reading ${read.fileName} (${Math.round(read.bytes.byteLength / 1024)} KB). This can take a couple of minutes.`);
|
|
216
|
+
}
|
|
217
|
+
const form = new FormData();
|
|
218
|
+
form.set("file", new File([new Uint8Array(read.bytes)], read.fileName));
|
|
219
|
+
if (command.exclude)
|
|
220
|
+
form.set("exclusions", command.exclude);
|
|
221
|
+
const answer = await ask(door, {
|
|
222
|
+
path: "/api/notes/upload",
|
|
223
|
+
method: "POST",
|
|
224
|
+
label: "notes upload",
|
|
225
|
+
timeoutMs: UPLOAD_DEADLINE_MS,
|
|
226
|
+
body: form,
|
|
227
|
+
});
|
|
228
|
+
if (!answer.ok) {
|
|
229
|
+
writeLine(door.io.stderr, `${TAG} upload failed ${JSON.stringify({ reason: answer.reason })}`);
|
|
230
|
+
if (!door.json)
|
|
231
|
+
writeLine(door.io.stderr, `${read.fileName}: ${answer.detail}`);
|
|
232
|
+
results.push({ path: filePath, ok: false, reason: answer.reason });
|
|
233
|
+
worstExit = 1;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const body = answer.body;
|
|
237
|
+
results.push({ path: filePath, ok: body.stored === true, body });
|
|
238
|
+
if (body.stored !== true)
|
|
239
|
+
worstExit = 1;
|
|
240
|
+
if (!door.json)
|
|
241
|
+
sayUpload(door, body);
|
|
242
|
+
writeLine(door.io.stderr, `${TAG} upload answered ${JSON.stringify({
|
|
243
|
+
stored: body.stored === true,
|
|
244
|
+
note_id: body.noteId ?? null,
|
|
245
|
+
scope: body.scope ?? null,
|
|
246
|
+
byte_size: read.bytes.byteLength,
|
|
247
|
+
extension: read.extension,
|
|
248
|
+
})}`);
|
|
249
|
+
}
|
|
250
|
+
if (door.json) {
|
|
251
|
+
emit(door, { ok: worstExit === 0, uploaded: results.length, results });
|
|
252
|
+
}
|
|
253
|
+
return worstExit;
|
|
254
|
+
}
|
|
255
|
+
async function pasteNote(command, door) {
|
|
256
|
+
let text;
|
|
257
|
+
if (command.filePath) {
|
|
258
|
+
const read = await readNoteFile(command.filePath);
|
|
259
|
+
if (!read.ok) {
|
|
260
|
+
const sentence = noteFileRefusalSentence(read.refusal, command.filePath);
|
|
261
|
+
writeLine(door.io.stderr, `${TAG} file refused ${JSON.stringify({ reason: read.refusal, detail: read.detail })}`);
|
|
262
|
+
return fail(door, read.refusal, sentence);
|
|
263
|
+
}
|
|
264
|
+
const decoded = decodeTextBytes(read.bytes);
|
|
265
|
+
if (!decoded.ok) {
|
|
266
|
+
writeLine(door.io.stderr, `${TAG} file refused ${JSON.stringify({ reason: decoded.reason })}`);
|
|
267
|
+
return fail(door, decoded.reason, "That file is not text this command can decode (it may be a binary or an unusual encoding). Nothing was sent.");
|
|
268
|
+
}
|
|
269
|
+
text = decoded.text;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
if (isInteractiveStdin(door.io)) {
|
|
273
|
+
return fail(door, "nothing_piped", "Pass --file <path> (safest on Windows), or pipe the note in "
|
|
274
|
+
+ "(`pbpaste | cockpit notes paste` on macOS; on Windows use PowerShell 7 — "
|
|
275
|
+
+ "Windows PowerShell 5.1 turns non-ASCII into `?` on pipes).");
|
|
276
|
+
}
|
|
277
|
+
try {
|
|
278
|
+
text = await readPipedText(door.io.stdin, {
|
|
279
|
+
maxChars: PASTE_MAX_CHARS,
|
|
280
|
+
overflowMessage: `A pasted note is limited to ${PASTE_MAX_CHARS} characters. Save it to a file and use --file instead.`,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
return fail(door, "paste_too_long", errorText(error));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (text.trim() === "") {
|
|
288
|
+
return fail(door, "empty_paste", "There was nothing to paste. Nothing was sent.");
|
|
289
|
+
}
|
|
290
|
+
const form = new FormData();
|
|
291
|
+
form.set("text", text);
|
|
292
|
+
if (command.name)
|
|
293
|
+
form.set("name", command.name);
|
|
294
|
+
if (command.exclude)
|
|
295
|
+
form.set("exclusions", command.exclude);
|
|
296
|
+
if (text.length >= NOTE_SLOW_UPLOAD_BYTES) {
|
|
297
|
+
writeLine(door.io.stderr, `Reading ${Math.round(text.length / 1024)} KB of pasted text. This can take a couple of minutes.`);
|
|
298
|
+
}
|
|
299
|
+
const answer = await ask(door, {
|
|
300
|
+
path: "/api/notes/upload",
|
|
301
|
+
method: "POST",
|
|
302
|
+
label: "notes paste",
|
|
303
|
+
timeoutMs: UPLOAD_DEADLINE_MS,
|
|
304
|
+
body: form,
|
|
305
|
+
});
|
|
306
|
+
if (!answer.ok)
|
|
307
|
+
return fail(door, answer.reason, answer.detail);
|
|
308
|
+
const body = answer.body;
|
|
309
|
+
writeLine(door.io.stderr, `${TAG} paste answered ${JSON.stringify({
|
|
310
|
+
stored: body.stored === true,
|
|
311
|
+
note_id: body.noteId ?? null,
|
|
312
|
+
scope: body.scope ?? null,
|
|
313
|
+
chars: text.length,
|
|
314
|
+
named_by_caller: Boolean(command.name),
|
|
315
|
+
})}`);
|
|
316
|
+
if (door.json)
|
|
317
|
+
return emit(door, body, body.stored === true ? 0 : 1);
|
|
318
|
+
sayUpload(door, body);
|
|
319
|
+
return body.stored === true ? 0 : 1;
|
|
320
|
+
}
|
|
321
|
+
async function shareNote(command, door) {
|
|
322
|
+
const wantsToShare = command.action === "share";
|
|
323
|
+
// Only sharing asks. Taking a note back narrows who can read it, and nobody
|
|
324
|
+
// needs to be talked out of that.
|
|
325
|
+
if (wantsToShare && !command.yes) {
|
|
326
|
+
if (!isInteractiveStdin(door.io)) {
|
|
327
|
+
return fail(door, "confirmation_required", "Sharing a note lets everyone signed in read it. Pass --yes to do it without being asked.");
|
|
328
|
+
}
|
|
329
|
+
const answer = await readLine(door.io, "Share this note with everyone signed in? [Y/n] ");
|
|
330
|
+
if (!yesByDefault(answer)) {
|
|
331
|
+
writeLine(door.io.stderr, `${TAG} share declined ${JSON.stringify({ reason: "operator_said_no" })}`);
|
|
332
|
+
writeLine(door.io.stdout, "Left alone. Nothing changed.");
|
|
333
|
+
return 0;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const answer = await ask(door, {
|
|
337
|
+
path: "/api/notes/share",
|
|
338
|
+
method: "POST",
|
|
339
|
+
label: wantsToShare ? "notes share" : "notes unshare",
|
|
340
|
+
timeoutMs: READ_DEADLINE_MS,
|
|
341
|
+
body: { note_id: command.noteId, share: wantsToShare },
|
|
342
|
+
});
|
|
343
|
+
if (!answer.ok)
|
|
344
|
+
return fail(door, answer.reason, answer.detail);
|
|
345
|
+
const body = answer.body;
|
|
346
|
+
writeLine(door.io.stderr, `${TAG} ${wantsToShare ? "shared" : "taken back"} ${JSON.stringify({
|
|
347
|
+
note_id: command.noteId ?? null,
|
|
348
|
+
stored: body.stored === true,
|
|
349
|
+
})}`);
|
|
350
|
+
if (door.json)
|
|
351
|
+
return emit(door, body);
|
|
352
|
+
sayUpload(door, body);
|
|
353
|
+
return 0;
|
|
354
|
+
}
|
|
355
|
+
async function moveNote(command, door) {
|
|
356
|
+
const answer = await ask(door, {
|
|
357
|
+
path: "/api/notes/move",
|
|
358
|
+
method: "POST",
|
|
359
|
+
label: "notes move",
|
|
360
|
+
timeoutMs: READ_DEADLINE_MS,
|
|
361
|
+
// `--clear-shelf` sends the empty string, which is what the browser's own
|
|
362
|
+
// move box sends when a person empties it.
|
|
363
|
+
body: { note_id: command.noteId, category: command.clearShelf ? "" : command.to },
|
|
364
|
+
});
|
|
365
|
+
if (!answer.ok)
|
|
366
|
+
return fail(door, answer.reason, answer.detail);
|
|
367
|
+
const body = answer.body;
|
|
368
|
+
writeLine(door.io.stderr, `${TAG} move answered ${JSON.stringify({
|
|
369
|
+
note_id: command.noteId ?? null,
|
|
370
|
+
ok: body.ok === true,
|
|
371
|
+
reason: body.reason ?? null,
|
|
372
|
+
cleared: Boolean(command.clearShelf),
|
|
373
|
+
})}`);
|
|
374
|
+
if (door.json)
|
|
375
|
+
return emit(door, body, body.ok === true ? 0 : 1);
|
|
376
|
+
writeLine(door.io.stdout, body.headline ?? "Tower answered without a sentence.");
|
|
377
|
+
for (const line of body.lines ?? [])
|
|
378
|
+
writeLine(door.io.stdout, line);
|
|
379
|
+
return body.ok === true ? 0 : 1;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* One request, and a refusal that keeps the ROUTE'S own words.
|
|
383
|
+
*
|
|
384
|
+
* `towerJsonRequest` maps a non-2xx through `responseErrorMessage`, which looks
|
|
385
|
+
* for `message` or `error` — the shape the ingest routes answer with. Every
|
|
386
|
+
* notes door answers in the browser's shape instead (`headline` plus `lines`,
|
|
387
|
+
* with a `reason` label beside them), because the same body is what the page
|
|
388
|
+
* renders. Reading it here rather than widening `responseErrorMessage` keeps one
|
|
389
|
+
* meaning per field: the sentence is written where the outcome is known, and the
|
|
390
|
+
* terminal relays it rather than inventing a second wording for the same thing.
|
|
391
|
+
*/
|
|
392
|
+
async function ask(door, options) {
|
|
393
|
+
const result = await towerRequest({
|
|
394
|
+
dashboardUrl: door.dashboardUrl,
|
|
395
|
+
path: options.path,
|
|
396
|
+
deviceToken: door.deviceToken,
|
|
397
|
+
fetch: door.io.fetch,
|
|
398
|
+
method: options.method,
|
|
399
|
+
label: options.label,
|
|
400
|
+
timeoutMs: options.timeoutMs,
|
|
401
|
+
...(options.body === undefined ? {} : { body: options.body }),
|
|
402
|
+
log: (line) => writeLine(door.io.stderr, line),
|
|
403
|
+
});
|
|
404
|
+
if (!result.ok) {
|
|
405
|
+
const failure = result;
|
|
406
|
+
return {
|
|
407
|
+
ok: false,
|
|
408
|
+
reason: failure.reason,
|
|
409
|
+
detail: towerFailureDetail(failure.reason, failure.detail),
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
const body = await readResponseJson(result.response);
|
|
413
|
+
if (!result.response.ok) {
|
|
414
|
+
const status = result.response.status;
|
|
415
|
+
return {
|
|
416
|
+
ok: false,
|
|
417
|
+
reason: refusalReason(body) ?? `http_${status}`,
|
|
418
|
+
detail: refusalSentence(body) ?? `Tower answered ${status} and said nothing about why.`,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
return { ok: true, body };
|
|
422
|
+
}
|
|
423
|
+
function refusalReason(body) {
|
|
424
|
+
if (!body || typeof body !== "object")
|
|
425
|
+
return null;
|
|
426
|
+
const record = body;
|
|
427
|
+
for (const key of ["reason", "error", "code"]) {
|
|
428
|
+
const value = record[key];
|
|
429
|
+
if (typeof value === "string" && value.trim() !== "")
|
|
430
|
+
return value;
|
|
431
|
+
}
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
function refusalSentence(body) {
|
|
435
|
+
if (!body || typeof body !== "object")
|
|
436
|
+
return null;
|
|
437
|
+
const record = body;
|
|
438
|
+
const headline = typeof record["headline"] === "string" ? record["headline"] : null;
|
|
439
|
+
const message = typeof record["message"] === "string" ? record["message"] : null;
|
|
440
|
+
const lines = Array.isArray(record["lines"])
|
|
441
|
+
? record["lines"].filter((line) => typeof line === "string")
|
|
442
|
+
: [];
|
|
443
|
+
const said = [headline ?? message, ...lines].filter(Boolean);
|
|
444
|
+
return said.length > 0 ? said.join(" ") : null;
|
|
445
|
+
}
|
|
446
|
+
/** One machine-readable object on stdout, and nothing else on it. */
|
|
447
|
+
function emit(door, body, exitCode = 0) {
|
|
448
|
+
writeLine(door.io.stdout, JSON.stringify(body));
|
|
449
|
+
return exitCode;
|
|
450
|
+
}
|
|
451
|
+
function fail(door, reason, detail) {
|
|
452
|
+
writeLine(door.io.stderr, `${TAG} refused ${JSON.stringify({ reason })}`);
|
|
453
|
+
if (door.json) {
|
|
454
|
+
writeLine(door.io.stdout, JSON.stringify({ ok: false, error: reason, detail }));
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
writeLine(door.io.stderr, detail);
|
|
458
|
+
}
|
|
459
|
+
return 1;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* The route's own words for what happened. Never rephrased here — the sentences
|
|
463
|
+
* are written where the outcome is known, and a second wording in the terminal
|
|
464
|
+
* would be a second thing to keep in step.
|
|
465
|
+
*/
|
|
466
|
+
function sayUpload(door, body) {
|
|
467
|
+
writeLine(door.io.stdout, body.headline ?? "Tower answered without a sentence.");
|
|
468
|
+
for (const line of body.lines ?? [])
|
|
469
|
+
writeLine(door.io.stdout, line);
|
|
470
|
+
if (body.noteId)
|
|
471
|
+
writeLine(door.io.stdout, `Note id: ${body.noteId}`);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Says out loud when an answer is narrower than the one a browser would give.
|
|
475
|
+
*
|
|
476
|
+
* A degraded read is still a real answer and is never withheld — but a person
|
|
477
|
+
* who cannot see their own unshared note has to be told that is why, not left
|
|
478
|
+
* to conclude it was never stored.
|
|
479
|
+
*/
|
|
480
|
+
function sayScope(door, body) {
|
|
481
|
+
if (!body.degradedBecause)
|
|
482
|
+
return;
|
|
483
|
+
writeLine(door.io.stderr, `${TAG} narrowed ${JSON.stringify({ scope: body.scope ?? null, reason: body.degradedBecause })}`);
|
|
484
|
+
writeLine(door.io.stderr, body.degradedNote ?? "This answer is narrower than the browser's.");
|
|
485
|
+
}
|
|
486
|
+
function errorText(error) {
|
|
487
|
+
return error instanceof Error ? error.message : String(error);
|
|
488
|
+
}
|
|
@@ -15,7 +15,7 @@ export async function runCockpitCli(argv, io) {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
if (command === "--version" || command === "-V" || command === "version") {
|
|
18
|
-
writeLine(io?.stdout ?? process.stdout, "0.2.
|
|
18
|
+
writeLine(io?.stdout ?? process.stdout, "0.2.40");
|
|
19
19
|
return 0;
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a Scout board reads in a terminal, and which card a typed id means.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions, no io and no network: `scout.ts` fetches, this lays out. The
|
|
5
|
+
* split is BLI-3460's, taken so the layout can be asserted line for line by a
|
|
6
|
+
* test that never opens a socket.
|
|
7
|
+
*
|
|
8
|
+
* **The sentences are the page's, not this file's.** Every standing line — the
|
|
9
|
+
* watch line, the headline, the quiet reason, all three section labels —
|
|
10
|
+
* arrives in the GET payload from the dashboard's `lib/cockpit/scout-lines.ts`,
|
|
11
|
+
* the same module the browser surface renders. Nothing here words anything; a
|
|
12
|
+
* terminal that writes its own "LAST SWEEP" will eventually disagree with the
|
|
13
|
+
* page about whether the sweep ran.
|
|
14
|
+
*
|
|
15
|
+
* **A bounded read says so.** The server returns at most 8 cards and 12
|
|
16
|
+
* signals; when there are more, `truncationLines` prints how many. A quiet
|
|
17
|
+
* board and a truncated board must never look alike.
|
|
18
|
+
*/
|
|
19
|
+
const DIM = "\x1b[2m";
|
|
20
|
+
const RESET = "\x1b[0m";
|
|
21
|
+
// ------------------------------------------------------------------ rendering
|
|
22
|
+
/** The whole board as terminal lines, in the page's three sections and order. */
|
|
23
|
+
export function renderScoutBoard(payload) {
|
|
24
|
+
const board = payload.board ?? {};
|
|
25
|
+
const lines = payload.lines ?? {};
|
|
26
|
+
const out = [];
|
|
27
|
+
if (lines.watch)
|
|
28
|
+
out.push(lines.watch);
|
|
29
|
+
if (lines.headline)
|
|
30
|
+
out.push(lines.headline);
|
|
31
|
+
const experiments = board.experiments ?? [];
|
|
32
|
+
out.push("", lines.waitingLabel ?? "Waiting on you");
|
|
33
|
+
if (experiments.length === 0) {
|
|
34
|
+
out.push(indent(lines.quiet ?? "Nothing is waiting on a decision right now."));
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
for (const card of experiments)
|
|
38
|
+
out.push(...renderExperiment(card));
|
|
39
|
+
}
|
|
40
|
+
const settled = board.settled ?? [];
|
|
41
|
+
if (settled.length > 0) {
|
|
42
|
+
out.push("", lines.settledLabel ?? "Already decided");
|
|
43
|
+
for (const card of settled) {
|
|
44
|
+
out.push(` ⏺ ${shortId(card.id ?? "")} · ${card.status === "done" ? "RAN" : "DISMISSED"} · ${card.claimSummary ?? card.title ?? ""}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const signals = board.signals ?? [];
|
|
48
|
+
out.push("", lines.rawWatchLabel ?? "The raw watch");
|
|
49
|
+
if (signals.length === 0) {
|
|
50
|
+
out.push(indent(lines.rawWatchEmpty ?? "Nothing was gathered in this window."));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
for (const signal of signals)
|
|
54
|
+
out.push(...renderSignal(signal));
|
|
55
|
+
}
|
|
56
|
+
const truncation = truncationLines(board);
|
|
57
|
+
if (truncation.length > 0)
|
|
58
|
+
out.push("", ...truncation);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function renderExperiment(card) {
|
|
62
|
+
const sourceCount = card.sourceCount ?? 0;
|
|
63
|
+
const head = [
|
|
64
|
+
shortId(card.id ?? ""),
|
|
65
|
+
card.status === "started" ? "RUNNING" : "SUGGESTED",
|
|
66
|
+
sourceCount === 0
|
|
67
|
+
? "no source signals"
|
|
68
|
+
: `${sourceCount} source signal${sourceCount === 1 ? "" : "s"}`,
|
|
69
|
+
dayStamp(card.createdAt),
|
|
70
|
+
]
|
|
71
|
+
.filter(Boolean)
|
|
72
|
+
.join(" · ");
|
|
73
|
+
const out = [` ⏺ ${head}`];
|
|
74
|
+
if (card.claimSummary)
|
|
75
|
+
out.push(` ${card.claimSummary}`);
|
|
76
|
+
if (card.title)
|
|
77
|
+
out.push(dim(` ${card.title}`));
|
|
78
|
+
for (const row of card.crossref ?? []) {
|
|
79
|
+
if (row.person)
|
|
80
|
+
out.push(dim(` On your team · ${row.person} · ${row.observedPattern ?? ""}`));
|
|
81
|
+
}
|
|
82
|
+
if (card.expectedPayoff)
|
|
83
|
+
out.push(dim(` Worth trying · ${card.expectedPayoff}`));
|
|
84
|
+
for (const source of card.sources ?? []) {
|
|
85
|
+
if (source.title)
|
|
86
|
+
out.push(dim(` ${source.title} · ${source.source ?? ""} · ${source.url ?? ""}`));
|
|
87
|
+
}
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
function renderSignal(signal) {
|
|
91
|
+
const out = [` ⏺ ${signal.title ?? "untitled"} · ${dayStamp(signal.gatheredAt)}`];
|
|
92
|
+
if (signal.synopsis)
|
|
93
|
+
out.push(dim(` ${signal.synopsis}`));
|
|
94
|
+
const foot = [
|
|
95
|
+
signal.source,
|
|
96
|
+
signal.evidenceStrength ?? undefined,
|
|
97
|
+
signal.status === "promoted" ? "promoted" : undefined,
|
|
98
|
+
(signal.tags ?? []).slice(0, 4).join(", ") || undefined,
|
|
99
|
+
signal.url,
|
|
100
|
+
].filter((part) => Boolean(part));
|
|
101
|
+
if (foot.length > 0)
|
|
102
|
+
out.push(dim(` ${foot.join(" · ")}`));
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* One line per bounded read that did not fit. Silence here means the board on
|
|
107
|
+
* screen IS the board — which is only true because this says otherwise when it
|
|
108
|
+
* is not.
|
|
109
|
+
*/
|
|
110
|
+
export function truncationLines(board) {
|
|
111
|
+
const coverage = board.coverage ?? {};
|
|
112
|
+
const parts = [
|
|
113
|
+
["waiting cards", coverage.openExperiments],
|
|
114
|
+
["decided cards", coverage.settledExperiments],
|
|
115
|
+
["signals", coverage.signals],
|
|
116
|
+
];
|
|
117
|
+
const out = [];
|
|
118
|
+
for (const [label, read] of parts) {
|
|
119
|
+
if (!read?.truncated)
|
|
120
|
+
continue;
|
|
121
|
+
const returned = read.returned ?? 0;
|
|
122
|
+
out.push(typeof read.total === "number"
|
|
123
|
+
? `Bounded read · ${label}: ${returned} of ${read.total} shown. The rest is in Tower.`
|
|
124
|
+
: `Bounded read · ${label}: ${returned} shown, and there are more. The rest is in Tower.`);
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Which card a typed reference means, decided against the board that was just
|
|
130
|
+
* read — never against a guess. An exact id wins outright; otherwise a prefix
|
|
131
|
+
* must match exactly one card, and two matches are refused by name rather than
|
|
132
|
+
* silently taking the first.
|
|
133
|
+
*/
|
|
134
|
+
export function resolveExperimentRef(board, ref) {
|
|
135
|
+
const needle = ref.trim().toLowerCase();
|
|
136
|
+
if (!needle)
|
|
137
|
+
return { status: "no_match" };
|
|
138
|
+
const cards = [...(board.experiments ?? []), ...(board.settled ?? [])].filter((card) => typeof card.id === "string");
|
|
139
|
+
const exact = cards.find((card) => card.id.toLowerCase() === needle);
|
|
140
|
+
if (exact)
|
|
141
|
+
return { status: "ok", id: exact.id, card: exact };
|
|
142
|
+
const matches = cards.filter((card) => card.id.toLowerCase().startsWith(needle));
|
|
143
|
+
if (matches.length === 0)
|
|
144
|
+
return { status: "no_match" };
|
|
145
|
+
if (matches.length > 1) {
|
|
146
|
+
return { status: "ambiguous_prefix", candidates: matches.map((card) => shortId(card.id)) };
|
|
147
|
+
}
|
|
148
|
+
const only = matches[0];
|
|
149
|
+
return { status: "ok", id: only.id, card: only };
|
|
150
|
+
}
|
|
151
|
+
export function refusalSentence(resolution, ref) {
|
|
152
|
+
if (resolution.status === "no_match") {
|
|
153
|
+
return `No card on the board starts with "${ref}". Run \`cockpit scout\` to see the ids.`;
|
|
154
|
+
}
|
|
155
|
+
if (resolution.status === "ambiguous_prefix") {
|
|
156
|
+
return `${resolution.candidates.length} cards start with "${ref}" (${resolution.candidates.join(", ")}). Use more characters.`;
|
|
157
|
+
}
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
// ----------------------------------------------------------------- small parts
|
|
161
|
+
export function shortId(id) {
|
|
162
|
+
return id.slice(0, 6);
|
|
163
|
+
}
|
|
164
|
+
function dayStamp(iso) {
|
|
165
|
+
return iso ? iso.slice(0, 10) : "";
|
|
166
|
+
}
|
|
167
|
+
function dim(text) {
|
|
168
|
+
return `${DIM}${text}${RESET}`;
|
|
169
|
+
}
|
|
170
|
+
function indent(text) {
|
|
171
|
+
return ` ${text}`;
|
|
172
|
+
}
|