Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Terminal: /report <name|#n> files a report, and /reports lists them for the owner and moderators #348

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/319-terminal-report-name-n-files-a-report-an → main 1 commit fork

  • Merged. smith/319-terminal-report-name-n-files-a-report-an was merged into main as 2d70348.

Review

Sign in to review this change.
3 files changed +59 −3
Software/README.md +1
@@ -517,6 +517,7 @@ watches. A line you type is said in the chat; commands start with `/`:
517517 `resumed` when it is resumed.
518518 - `/end [name]`, owner: end that turn (no name: whoever drives), or take
519519 them out of the line.
520 - `/report <name|#n>`, anyone signed in: report that person's latest chat line, or line number n; prints `reported #n` when the server took it. `/reports`, owner or moderator: the reported lines, newest first (`report #n author: text (by reporter)`); anyone else is told it is for them. The owner and moderators are told `N reports to review: /reports` on join and get one line per new report. Reports are kept in `$FORGE_APP_DATA/so101/reports.json` (one per reporter per line, 200 at most).
520521 - `/removed`, `/restore #<n>`, owner: list the latest removed chat lines, and put one back for everyone.
521522 - `/mute <name> [10m|1h|24h|forever]`, `/unmute <name>`, owner or moderator. A mute without a length is for good; a timed one ends on its own and the owner's list says when.
522523 - `/table here`, owner: the page's "Table is here", the same
Software/so101/src/terminal.test.ts +27
@@ -441,6 +441,33 @@ describe("terminal door", () => {
441441 await owner.printedLine(/^usage: \/restore/);
442442 });
443443
444 test("report and reports: a signed-in terminal reports a line by name or number; only the owner's lists them and hears new ones", async () => {
445 const port = await start();
446 const alicePage = await viewer(port, web("u-alice", "alice"));
447 alicePage.send({ type: "post", text: "rude" });
448 const one = await alicePage.heardOne((m) => m.type === "said" && m.message.text === "rude", "the line");
449 const owner = await terminal(port, ttyEnv("u-owner", "trevato", "admin"));
450 const carol = await terminal(port, ttyEnv("u-carol", "carol", "user"));
451 await owner.printedLine(/^you are trevato \(owner\)$/);
452 await carol.printedLine(/^alice: rude$/);
453 carol.door.input("/reports");
454 await carol.printedLine(/^reports are for the owner and moderators$/);
455 owner.door.input("/reports");
456 await owner.printedLine(/^no reports$/);
457 carol.door.input("/report alice");
458 await carol.printedLine(new RegExp(`^reported #${one.message.id}$`));
459 await owner.printedLine(new RegExp(`^report #${one.message.id} alice: rude \\(by u-carol\\)$`));
460 carol.door.input("/report #999");
461 await carol.printedLine(/^error: no such line to report$/);
462 carol.door.input("/report nobody");
463 await carol.printedLine(/^error: no line from nobody seen$/);
464 owner.door.input("/reports");
465 await waitFor(() => (owner.printed.filter((l) => l.startsWith("report #")).length === 2 ? true : undefined), "the listed report");
466 const late = await terminal(port, ttyEnv("u-owner", "trevato", "admin"));
467 await late.printedLine(/^1 report to review: \/reports$/);
468 expect(hear(emptyRoom(), { type: "reports", reports: [] })).toEqual([]);
469 });
470
444471 test("end-turn: only the owner's terminal may; the page sees the turn pass on", async () => {
445472 const port = await start();
446473 const alicePage = await viewer(port, web("u-alice", "alice"));
Software/so101/src/terminal.ts +31 −3
@@ -22,6 +22,8 @@
2222 * /end [who] owner: end that turn (none: whoever drives), or take them out of the line
2323 * /mute <who> [10m|1h|24h|forever] /unmute <who> owner or moderator (never the owner or a moderator)
2424 * /delete <who|#id> owner or moderator: remove that person's latest chat line, or the line numbered #id (shown to those who may)
25 * /report <who|#id> any signed-in person: report that person's latest chat line, or the line numbered #id; prints `reported #id`
26 * /reports owner or moderator: the reported lines, newest first (they also hear of each new one)
2527 * /removed owner: the latest removed chat lines, with their numbers and who removed them
2628 * /restore #<n> owner: put a removed line back for everyone (Lobby.restoreLine; it is logged)
2729 * /table here admin: put the table under the arm's lowest link now (POST /settings/table-here)
@@ -141,9 +143,11 @@ export interface Room {
141143 latest: Map<string, number>;
142144 /** Everyone seen by name, most recent last: to turn a typed name into an id. */
143145 seen: Map<string, Someone>;
146 /** The reports the owner or a moderator was last sent, newest first; null until the first list (the one on join). */
147 reports: Array<Record<string, unknown>> | null;
144148 }
145149
146 export const emptyRoom = (): Room => ({ you: null, muted: false, banned: false, driver: null, queue: [], paused: false, held: undefined, told: { called: false, next: false }, seen: new Map(), latest: new Map() });
150 export const emptyRoom = (): Room => ({ you: null, muted: false, banned: false, driver: null, queue: [], paused: false, held: undefined, told: { called: false, next: false }, seen: new Map(), latest: new Map(), reports: null });
147151
148152 const someone = (x: unknown): Someone | null => {
149153 if (typeof x !== "object" || x === null) return null;
@@ -167,7 +171,7 @@ const said = (room: Room, m: unknown): string => {
167171 return from ? `${tag}${plain(from.name)}: ${plain(message?.text)}` : `· ${plain(message?.text)}`;
168172 };
169173
170 export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /table here|<mm> (owner) · /mute <who> /unmute <who> (owner, moderator) · /delete <who|#id> (owner, moderator) · /removed /restore #<id> (owner) · /health (owner, moderator) · /machine [off] · /who · /quit";
174 export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /table here|<mm> (owner) · /mute <who> /unmute <who> (owner, moderator) · /delete <who|#id> (owner, moderator) · /report <who|#id> · /reports (owner, moderator) · /removed /restore #<id> (owner) · /health (owner, moderator) · /machine [off] · /who · /quit";
171175
172176 /** The Machine feed's socket beside the lobby's: same app, same port. */
173177 export const machineUrl = (live: string): string => live.replace(/\/live$/, "/machine");
@@ -256,6 +260,17 @@ export function hear(room: Room, frame: Frame): string[] {
256260 if (now === was || (was === undefined && now === null)) return [];
257261 return [now ?? "resumed: the arm may move again, from a new command"];
258262 }
263 case "reported":
264 return [`reported #${plain(frame.id)}`];
265 case "reports": {
266 const list = (Array.isArray(frame.reports) ? frame.reports : []).filter((x): x is Record<string, unknown> => typeof x === "object" && x !== null);
267 const key = (x: Record<string, unknown>) => `${plain(x.reporter)}/${plain(x.id)}`;
268 const before = room.reports;
269 room.reports = list;
270 if (!before) return list.length ? [`${list.length} report${list.length === 1 ? "" : "s"} to review: /reports`] : [];
271 const known = new Set(before.map(key));
272 return list.filter((x) => !known.has(key(x))).reverse().map(reportLine);
273 }
259274 case "unsaid":
260275 return ["· a line was removed"];
261276 case "removed": {
@@ -270,6 +285,9 @@ export function hear(room: Room, frame: Frame): string[] {
270285 }
271286 }
272287
288 /** One report as a line: the line's number, its author, the words, and who reported it. */
289 const reportLine = (x: Record<string, unknown>): string => `report #${plain(x.id)} ${plain(x.author)}: ${plain(x.text)} (by ${plain(x.reporter)})`;
290
273291 export function who(room: Room): string {
274292 const line = room.queue.length ? room.queue.map((p, i) => `${i + 1}. ${plain(p.name)}`).join(" ") : "nobody waiting";
275293 return `${room.paused ? "paused · " : ""}${room.driver ? `${plain(room.driver.name)} has control` : "nobody has control"} · ${line}`;
@@ -282,7 +300,7 @@ function target(room: Room, word: string): string | null {
282300 return ID.test(word) ? word : null;
283301 }
284302
285 export type Typed = { send: Frame } | { post: "/stop" | "/resume" } | { table: "here" | number } | { print: string } | { machine: boolean } | { health: true } | { quit: true } | null;
303 export type Typed = { send: Frame } | { post: "/stop" | "/resume" } | { table: "here" | number } | { print: string } | { lines: string[] } | { machine: boolean } | { health: true } | { quit: true } | null;
286304
287305 /** What a typed line asks for. Validation the server repeats anyway; this only saves a round trip on a typo. */
288306 export function typed(room: Room, input: string): Typed {
@@ -318,6 +336,15 @@ export function typed(room: Room, input: string): Typed {
318336 const id = number ? Number(number[1]) : room.latest.get(target(room, arg) ?? "");
319337 return id === undefined ? { print: `error: no line from ${plain(arg)} seen` } : { send: { type: "delete", id } };
320338 }
339 case "report": {
340 if (!arg) return { print: "usage: /report <name> | /report #<line number>" };
341 const number = /^#(\d{1,15})$/.exec(arg);
342 const id = number ? Number(number[1]) : room.latest.get(target(room, arg) ?? "");
343 return id === undefined ? { print: `error: no line from ${plain(arg)} seen` } : { send: { type: "report", id } };
344 }
345 case "reports":
346 if (!room.you?.owner && !room.you?.moderator) return { print: "reports are for the owner and moderators" };
347 return room.reports?.length ? { lines: room.reports.map(reportLine) } : { print: "no reports" };
321348 case "removed":
322349 return { send: { type: "removed" } };
323350 case "restore": {
@@ -401,6 +428,7 @@ export class Door {
401428 if (!t) return true;
402429 if ("quit" in t) return false;
403430 if ("print" in t) this.print(t.print);
431 else if ("lines" in t) t.lines.forEach((l) => this.print(l));
404432 else if ("post" in t) void this.ask(t.post);
405433 else if ("table" in t) void this.table(t.table);
406434 else if ("health" in t) void this.health();

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs