feat(logs): collapse large run log data and serve client manifest
CI / changes (pull_request) Successful in 6s
CI / version (pull_request) Skipped
CI / server (pull_request) Successful in 1m30s
CI / client (pull_request) Successful in 1m31s
CI / image (pull_request) Skipped

- collapse run log data blocks whose pretty-printed JSON exceeds a byte
  or line limit, with a per-block toggle and an expand/collapse-all
  button next to the Logs heading
- align data blocks and toggles with the context/message column
- add a "Copy logs" button that copies the filtered logs as plain text
  with every data block expanded
- add GET /manifest.json with the app name, version and run log data
  limits (RUN_LOG_DATA_COLLAPSE_BYTES / RUN_LOG_DATA_COLLAPSE_LINES)
- load the manifest in the client stale-while-revalidate: localStorage
  copy first, refetched per page load and on tab focus after a while
- show the server version in the sidebar footer, with a reload hint
  when it differs from the client build

Closes #3
This commit is contained in:
ars9 committed 2026-10-02 14:05:49 +03:00
1 parent 4e55d14599
commit 718a12c2f4
25 files changed
+623 -36

No files matched your search

+76 -17
View File
@@ -1,4 +1,14 @@
import { useMemo, useState } from 'react';
import { ChevronDown, ChevronRight } from 'lucide-react';
import { CodeBlock } from '../CodeBlock/CodeBlock';
import {
DEFAULT_LOG_DATA_LIMITS,
exceedsLimits,
formatElapsed,
measureData,
prettyData,
type LogDataLimits,
} from './logText';
import styles from './LogOutput.module.css';
export type LogOutputLevel = 'debug' | 'log' | 'warn' | 'error';
@@ -22,25 +32,24 @@ export interface LogOutputProps {
maxHeight?: string | number;
emptyMessage?: string;
className?: string;
/** Data blocks whose pretty-printed JSON exceeds either limit start collapsed behind a toggle. */
dataLimits?: LogDataLimits;
/**
* Expands (true) or collapses (false) every large data block. Changing it
* discards the per-entry toggles made since the last change.
*/
dataExpanded?: boolean;
/** Label of a collapsed data block's toggle, e.g. "Show data (1.2 KB, 40 lines)". */
showDataLabel?: (size: { bytes: number; lines: number }) => string;
hideDataLabel?: string;
}
/**
* "+12s" (or "-" if before startTime, e.g. clock skew). Log timestamps are
* stored with second resolution, so fractions would be noise.
*/
function formatElapsed(deltaMs: number): string {
const sign = deltaMs < 0 ? '-' : '+';
return `${sign}${Math.round(Math.abs(deltaMs) / 1000)}s`;
function formatBytes(bytes: number): string {
return bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`;
}
/** Pretty-prints `data` if it's valid JSON, otherwise returns it as-is. */
function prettyData(data: string): string {
try {
return JSON.stringify(JSON.parse(data), null, 2);
} catch {
return data;
}
}
const defaultShowDataLabel = ({ bytes, lines }: { bytes: number; lines: number }) =>
`Show data (${formatBytes(bytes)}, ${lines} ${lines === 1 ? 'line' : 'lines'})`;
/** Terminal-style log viewer: one line per entry, color-coded by level. */
export function LogOutput({
@@ -49,7 +58,39 @@ export function LogOutput({
maxHeight,
emptyMessage = 'No logs.',
className,
dataLimits = DEFAULT_LOG_DATA_LIMITS,
dataExpanded = false,
showDataLabel = defaultShowDataLabel,
hideDataLabel = 'Hide data',
}: LogOutputProps) {
// Per-entry toggles, reset whenever dataExpanded changes
const [toggled, setToggled] = useState<Set<LogOutputEntry['id']>>(() => new Set());
const [prevDataExpanded, setPrevDataExpanded] = useState(dataExpanded);
if (prevDataExpanded !== dataExpanded) {
setPrevDataExpanded(dataExpanded);
setToggled(new Set());
}
const dataBlocks = useMemo(() => {
const blocks = new Map<
LogOutputEntry['id'],
{ pretty: string; bytes: number; lines: number }
>();
for (const entry of entries) {
if (!entry.data) continue;
const pretty = prettyData(entry.data);
blocks.set(entry.id, { pretty, ...measureData(pretty) });
}
return blocks;
}, [entries]);
const toggle = (id: LogOutputEntry['id']) =>
setToggled((prev) => {
const next = new Set(prev);
if (!next.delete(id)) next.add(id);
return next;
});
if (entries.length === 0) {
return <div className={styles.empty}>{emptyMessage}</div>;
}
@@ -65,6 +106,9 @@ export function LogOutput({
>
{entries.map((entry) => {
const entryMs = new Date(entry.createdAt).getTime();
const block = dataBlocks.get(entry.id);
const large = block != null && exceedsLimits(block, dataLimits);
const open = !large || dataExpanded !== toggled.has(entry.id);
return (
<div key={entry.id} className={[styles.line, styles[entry.level]].join(' ')}>
<div className={styles.lineHeader}>
@@ -75,9 +119,24 @@ export function LogOutput({
{entry.context && <span className={styles.context}>{entry.context}</span>}
<span className={styles.message}>{entry.message}</span>
</div>
{entry.data && (
{block && large && (
<button
type="button"
className={styles.dataToggle}
aria-expanded={open}
onClick={() => toggle(entry.id)}
>
{open ? (
<ChevronDown size={14} strokeWidth={3} aria-hidden="true" />
) : (
<ChevronRight size={14} strokeWidth={3} aria-hidden="true" />
)}
{open ? hideDataLabel : showDataLabel(block)}
</button>
)}
{block && open && (
<div className={styles.data}>
<CodeBlock code={prettyData(entry.data)} language="json" />
<CodeBlock code={block.pretty} language="json" />
</div>
)}
</div>