import m, {MithrilComponent} from '@garage44/mithril' import {Card, FieldSegmented} from '@garage44/mithril/components' import {when} from '@/lib/format' import {speaker} from '@/lib/names' import {local} from '@/lib/reactive' import {sentence} from '@/lib/sentence' import type {Part} from '@/lib/sentence' import {$s, loadLog} from '@/lib/store' import type {WorkspaceEvent} from '@/lib/types' /** Fields a raw line shows in its own place, so not again in the details. */ const SHOWN = new Set(['ts', 'kind', 'actor', 'node', 'host', 'via_hub_from']) /** The kinds that are the workspace's routine noise, folded away unless asked for. */ const NOISE = new Set(['ssh_session', 'git_fetch', 'git_serve', 'barrier', 'activity', 'lfs', 'warm_step', 'mcp_call', 'forgejo_call']) /** Lines drawn at a time: a week of the log is tens of thousands. */ const PAGE = 500 function details(e: WorkspaceEvent): string { return Object.entries(e) .filter(([k, v]) => !SHOWN.has(k) && v != null && v !== '') .map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`) .join(' ') } /** A sentence, its names set apart. */ const words = (parts: Part[]) => parts.map((x) => typeof x === 'string' ? ( x ) : ( {x.name} ), ) /** One line: a sentence where there is one for its kind, else its kind, who and its fields as they are. */ function line(e: WorkspaceEvent): m.Children { const said = sentence(e) const who = [e.node, e.actor ? speaker(e.actor).title : null].filter(Boolean).join(' · ') return (
  • {when(e.ts)} {said ? ( {words(said)} ) : ( {e.kind.replace(/_/g, ' ')} {who ? · {who} : null} {details(e)} )}
  • ) } /** The hub's event log, newest first: what `midas log` shows. */ export class Log extends MithrilComponent { s = local({all: false, shown: PAGE}) oninit() { void loadLog() } hours = ((s) => ({ get value() { return $s.logHours }, set value(v: number) { $s.logHours = v s.shown = PAGE void loadLog() }, }))(this.s) view() { const all = this.s.all const events = all ? $s.events : $s.events.filter((e) => !NOISE.has(e.kind)) const more = events.length - this.s.shown return ( (this.s.all = (e.target as HTMLInputElement).checked)} />{' '} routine too } flush >
    {more > 0 ? (

    The newest {this.s.shown} are shown; {more} older ones are not.{' '}

    ) : null}
    ) } }