// SPDX-License-Identifier: GPL-2.0-or-later // Copyright (C) 2026 Bryan Joshua Pedini export interface CliRecord { at: string; container: string; args: string[]; stdinBytes: number; exitCode: number | null; durationMs: number; stdout: string; stderr: string; } export interface HttpRecord { at: string; client: 'api' | 'browser'; actor: string; method: string; url: string; requestHeaders: Record; requestBodyBytes: number; status: number; responseHeaders: Record; bodyPreview: string; durationMs: number; } export interface DigRecord { at: string; args: string[]; output: string; } const MAX_TEXT = 8 * 1024; const MAX_RECORDS = 3000; export function clip(s: string, max = MAX_TEXT): string { return s.length <= max ? s : `${s.slice(0, max)}...[${s.length - max} more characters]`; } function push(list: T[], item: T): void { if (list.length >= MAX_RECORDS) list.shift(); list.push(item); } export class Recorder { readonly cli: CliRecord[] = []; readonly http: HttpRecord[] = []; readonly dig: DigRecord[] = []; readonly notes: string[] = []; readonly fuzzCases: unknown[] = []; addCli(r: Omit): void { push(this.cli, { at: new Date().toISOString(), ...r, stdout: clip(r.stdout), stderr: clip(r.stderr) }); } addHttp(r: Omit): void { push(this.http, { at: new Date().toISOString(), ...r, bodyPreview: clip(r.bodyPreview, 2048) }); } addDig(args: string[], output: string): void { push(this.dig, { at: new Date().toISOString(), args, output: clip(output, 4096) }); } note(text: string): void { push(this.notes, `${new Date().toISOString()} ${text}`); } clear(): void { this.cli.length = 0; this.http.length = 0; this.dig.length = 0; this.notes.length = 0; this.fuzzCases.length = 0; } }