agent terminal: coherence pass

layout
- unified prefix-column for every row kind: padding-left + negative
  text-indent so the glyph (→ ← · ◆ ✓ ✗ ⌁ !) sits in the same column
  whether the row is flat or a <details>. wraps hang under the body,
  not under the glyph.
- expandable rows drop the directional glyph from their summary text;
  the ▸/▾ disclosure marker from CSS sits in the prefix column instead,
  and the row's colour still carries cyan = outbound, muted = inbound.
- turn-start / turn-end de-weighted: bold/margin/tint dropped, the
  coloured left rule alone marks the boundary.

note classification
- stderr lines render orange with a `!` glyph (was muted `·`)
- operator-initiated notes (cancel/compact/model/new-session) render
  mauve italic (was muted `·` indistinguishable from harness chatter)
- catch-all .sys row escalates to orange `!` so unrecognised stream-json
  shapes surface for follow-up instead of hiding in muted noise

message-bearing rows
- send / ask / answer tool_use rich renderers default-open with the
  body inline; new ask + answer renderers (previously fell through to
  the generic JSON dump). recv tool_result also default-open, keyed by
  tracking tool_use_id → name across the stream so we know which
  result came from which tool.
- assistant text rows render markdown.
- bodies use vendored marked v4.0.2 (hive-fr0nt::MARKED_JS); falls
  back to plain text when the asset doesn't load.

extra-mcp tool pretty-print
- generic args formatter replaces the raw JSON dump for unknown tools
  (single-string field → `name k: "v"`; single dict / multi-field →
  trimmed `k: v · k: v …` summary)

dashboard .live .msgrow gets a text-indent: 0 reset so the new
hanging-indent metrics from TERMINAL_CSS don't leak into the flex-grid
broker rows.
This commit is contained in:
müde 2026-05-18 18:13:14 +02:00
parent f827187341
commit f8f2ccff52
7 changed files with 256 additions and 52 deletions

View file

@ -656,6 +656,79 @@
log.innerHTML = ''; log.innerHTML = '';
function trim(s, n) { return s.length > n ? s.slice(0, n) + '…' : s; } function trim(s, n) { return s.length > n ? s.slice(0, n) + '…' : s; }
// Render a message body as markdown into a new <div class="md">.
// Wraps `marked.parse` so the per-row body element carries the
// `.md` class (CSS in TERMINAL_CSS scopes paragraph/code/list
// styles to it). Falls back to a plain text node if marked isn't
// loaded (network glitch, asset 404) so the body still renders.
function mdNode(text) {
const div = document.createElement('div');
div.className = 'md';
const src = String(text || '');
if (window.marked && typeof window.marked.parse === 'function') {
try {
marked.setOptions({ breaks: true, gfm: true });
div.innerHTML = marked.parse(src);
} catch (err) {
console.warn('marked failed', err);
div.textContent = src;
}
} else {
div.textContent = src;
}
return div;
}
// Build a default-open details row whose body is markdown-rendered.
// Used by send / ask / answer tool_use renderers and by `recv`
// tool_result so message-bearing rows show their content inline
// without an extra click.
function detailsOpenMd(api, cls, summary, body) {
const d = api.details(cls, summary, '');
d.open = true;
const pre = d.querySelector('pre.tool-body');
if (pre) {
pre.replaceWith(mdNode(body));
} else {
d.appendChild(mdNode(body));
}
return d;
}
// Generic args-pretty-printer for unknown / extra-MCP tools. The
// built-in switch handles the common claude/hyperhive tools; this
// is the fallback so an `mcp__matrix__send_message` or similar
// doesn't dump raw JSON. Heuristics: single string-valued field →
// `Name field: "value"`; single dict-valued field → `Name field
// {…}`; otherwise compact JSON. Always trimmed to fit a row.
function fmtArgsGeneric(name, input) {
const keys = Object.keys(input || {});
if (keys.length === 0) return name + '()';
if (keys.length === 1) {
const k = keys[0];
const v = input[k];
if (typeof v === 'string') {
const oneline = v.replace(/\s+/g, ' ').trim();
return name + ' ' + k + ': ' + JSON.stringify(trim(oneline, 100));
}
if (typeof v === 'number' || typeof v === 'boolean') {
return name + ' ' + k + ': ' + JSON.stringify(v);
}
}
// Multi-field: render `k: v` pairs with strings/numbers inlined and
// anything else summarised by type so the row stays readable.
const pretty = keys.slice(0, 4).map((k) => {
const v = input[k];
if (v == null) return k + ': null';
if (typeof v === 'string') {
const oneline = v.replace(/\s+/g, ' ').trim();
return k + ': ' + JSON.stringify(trim(oneline, 40));
}
if (typeof v === 'number' || typeof v === 'boolean') return k + ': ' + v;
if (Array.isArray(v)) return k + `: [${v.length}]`;
return k + ': {…}';
});
const tail = keys.length > 4 ? ' …+' + (keys.length - 4) : '';
return name + ' ' + pretty.join(' · ') + tail;
}
// Pretty-print a tool call: per-known-tool format, fallback to JSON // Pretty-print a tool call: per-known-tool format, fallback to JSON
// for unknown tools. // for unknown tools.
function fmtToolUse(c) { function fmtToolUse(c) {
@ -678,7 +751,7 @@
case 'mcp__hyperhive__kill': return short + ' ' + (input.name || ''); case 'mcp__hyperhive__kill': return short + ' ' + (input.name || '');
case 'mcp__hyperhive__request_apply_commit': case 'mcp__hyperhive__request_apply_commit':
return short + ' ' + (input.agent || '') + ' @ ' + (input.commit_ref || '').slice(0, 12); return short + ' ' + (input.agent || '') + ' @ ' + (input.commit_ref || '').slice(0, 12);
default: return name + ' ' + trim(JSON.stringify(input), 200); default: return fmtArgsGeneric(short, input);
} }
} }
// Build a "rich" tool_use row for tools whose input has a body we // Build a "rich" tool_use row for tools whose input has a body we
@ -709,37 +782,73 @@
+ '\n' + '\n'
+ newLines.map(l => '+ ' + l).join('\n'); + newLines.map(l => '+ ' + l).join('\n');
} }
const summary = '→ ' + name + ' ' + path + ' · ' // Summaries on expandable rows omit the row's directional glyph
// (`→`) — the disclosure marker (`▸/▾`) from CSS sits in the
// prefix column for every row kind, and the row's cyan colour
// already signals "outbound tool".
const summary = name + ' ' + path + ' · '
+ (minus ? '-' + minus + ' ' : '') + '+' + plus; + (minus ? '-' + minus + ' ' : '') + '+' + plus;
return api.detailsDiff('tool-use', summary, body); return api.detailsDiff('tool-use', summary, body);
} }
// Message-bearing tools render default-open with a markdown body so
// the operator sees the content without an extra click. send / ask
// address a target; answer attaches to an existing question id.
if (name === 'mcp__hyperhive__send') { if (name === 'mcp__hyperhive__send') {
const to = input.to || '?'; const to = input.to || '?';
const body = String(input.body || ''); const body = String(input.body || '');
const headline = body.replace(/\s+/g, ' ').trim().slice(0, 80);
const lines = body.split('\n').length; const lines = body.split('\n').length;
const summary = '→ send → ' + to + (lines > 1 ? ` · ${lines}L` : '') return detailsOpenMd(api, 'tool-use',
+ (headline ? ' · ' + headline + (body.length > 80 ? '…' : '') : ''); 'send → ' + to + (lines > 1 ? ` · ${lines}L` : ''),
return api.details('tool-use', summary, body); body);
}
if (name === 'mcp__hyperhive__ask') {
const to = input.to || 'operator';
const q = String(input.question || '');
const lines = q.split('\n').length;
return detailsOpenMd(api, 'tool-use',
'ask → ' + to + (lines > 1 ? ` · ${lines}L` : ''),
q);
}
if (name === 'mcp__hyperhive__answer') {
const id = input.id != null ? String(input.id) : '?';
const a = String(input.answer || '');
const lines = a.split('\n').length;
return detailsOpenMd(api, 'tool-use',
'answer #' + id + (lines > 1 ? ` · ${lines}L` : ''),
a);
} }
return null; return null;
} }
// Track tool_use_id → tool name so we can decide on rendering when the
// matching tool_result lands later. Lets us default-open the body for
// message-bearing tools (`recv`) while keeping shell/file tool output
// collapsed unless the operator clicks. Cleared on /clear; otherwise
// grows with the session — entries are tiny strings.
const toolNameById = new Map();
function renderToolResult(c, api) { function renderToolResult(c, api) {
const txt = Array.isArray(c.content) const txt = Array.isArray(c.content)
? c.content.map(p => p.text || '').join('') ? c.content.map(p => p.text || '').join('')
: (c.content || ''); : (c.content || '');
const summary = '← ' + (() => { const sourceName = c.tool_use_id ? toolNameById.get(c.tool_use_id) : null;
const trimmed = txt.replace(/\s+/g, ' ').trim(); const isMessageBearing = sourceName === 'mcp__hyperhive__recv';
const trimmed = txt.replace(/\s+/g, ' ').trim();
const summaryBody = (() => {
if (!trimmed) return '(empty)'; if (!trimmed) return '(empty)';
if (trimmed.length <= 120) return trimmed; if (trimmed.length <= 120) return trimmed;
const lines = txt.split('\n').filter(l => l.length).length; const lines = txt.split('\n').filter(l => l.length).length;
const headline = trimmed.slice(0, 90) + '…'; const headline = trimmed.slice(0, 90) + '…';
return `${lines}L · ${headline}`; return `${lines}L · ${headline}`;
})(); })();
// Flat row: keep the `←` glyph in the prefix column. Details rows
// drop it — the `▸/▾` disclosure marker sits in that column via CSS.
if (isMessageBearing && txt.trim()) {
return detailsOpenMd(api, 'tool-result-block',
'recv ← ' + summaryBody, txt);
}
if (!txt.trim() || txt.length <= 120) { if (!txt.trim() || txt.length <= 120) {
api.row('tool-result', summary); api.row('tool-result', '← ' + summaryBody);
} else { } else {
api.details('tool-result-block', summary, txt); api.details('tool-result-block', summaryBody, txt);
} }
} }
// Pretty-render claude's background-task subagent events // Pretty-render claude's background-task subagent events
@ -783,12 +892,19 @@
} }
if (v.type === 'assistant' && v.message && v.message.content) { if (v.type === 'assistant' && v.message && v.message.content) {
for (const c of v.message.content) { for (const c of v.message.content) {
if (c.type === 'text' && c.text && c.text.trim()) api.row('text', c.text); if (c.type === 'text' && c.text && c.text.trim()) {
// Assistant prose renders with markdown — claude often
// emits bullets / fenced code / inline code; raw text
// loses the structure.
const row = api.row('text', '');
row.appendChild(mdNode(c.text));
}
else if (c.type === 'thinking') { else if (c.type === 'thinking') {
const txt = (c.thinking || c.text || '').trim(); const txt = (c.thinking || c.text || '').trim();
api.row('thinking', txt ? '· ' + txt : '· thinking …'); api.row('thinking', txt ? '· ' + txt : '· thinking …');
} }
else if (c.type === 'tool_use') { else if (c.type === 'tool_use') {
if (c.id && c.name) toolNameById.set(c.id, c.name);
if (!renderRichToolUse(c, api)) { if (!renderRichToolUse(c, api)) {
api.row('tool-use', '→ ' + fmtToolUse(c)); api.row('tool-use', '→ ' + fmtToolUse(c));
} }
@ -802,7 +918,10 @@
} }
return; return;
} }
api.row('sys', '· ' + trim(JSON.stringify(v), 200)); // Catch-all for unrecognised stream-json shapes. Loud (orange) so
// silently-dropped event types surface in the scrollback for
// follow-up classification.
api.row('sys', '! ' + trim(JSON.stringify(v), 200));
} }
// Count open turns across the backfill replay so the live banner + // Count open turns across the backfill replay so the live banner +
@ -844,7 +963,22 @@
(ev.ok ? '✓' : '✗') + ' turn ' + (ev.ok ? 'ok' : 'fail') (ev.ok ? '✓' : '✗') + ' turn ' + (ev.ok ? 'ok' : 'fail')
+ (ev.note ? ' — ' + ev.note : '')); + (ev.note ? ' — ' + ev.note : ''));
}, },
note(ev, api) { api.row('note', '· ' + ev.text); }, note(ev, api) {
const t = String(ev.text || '');
// stderr lines coming off the claude pump get an orange `!`
// glyph so they're not visually fused with ambient harness
// chatter. Operator-initiated notes (/cancel, /compact,
// /model, new-session) get a mauve italic affordance so the
// scrollback distinguishes "the operator did this" from
// "the harness did this on its own."
if (t.startsWith('stderr:')) {
api.row('note stderr', '! ' + t);
} else if (t.startsWith('operator:')) {
api.row('note op', '· ' + t);
} else {
api.row('note', '· ' + t);
}
},
stream(ev, api) { stream(ev, api) {
const v = Object.assign({}, ev); delete v.kind; const v = Object.assign({}, ev); delete v.kind;
renderStream(v, api); renderStream(v, api);

View file

@ -39,6 +39,7 @@
<div id="term-input" class="term-input"></div> <div id="term-input" class="term-input"></div>
</div> </div>
<script src="/static/marked.js" defer></script>
<script src="/static/hive-fr0nt.js" defer></script> <script src="/static/hive-fr0nt.js" defer></script>
<script src="/static/app.js" defer></script> <script src="/static/app.js" defer></script>
</body> </body>

View file

@ -94,6 +94,7 @@ pub async fn serve(
.route("/static/agent.css", get(serve_css)) .route("/static/agent.css", get(serve_css))
.route("/static/app.js", get(serve_app_js)) .route("/static/app.js", get(serve_app_js))
.route("/static/hive-fr0nt.js", get(serve_shared_js)) .route("/static/hive-fr0nt.js", get(serve_shared_js))
.route("/static/marked.js", get(serve_marked_js))
.route("/api/state", get(api_state)) .route("/api/state", get(api_state))
.route("/events/stream", get(events_stream)) .route("/events/stream", get(events_stream))
.route("/events/history", get(events_history)) .route("/events/history", get(events_history))
@ -190,6 +191,13 @@ async fn serve_shared_js() -> impl IntoResponse {
) )
} }
async fn serve_marked_js() -> impl IntoResponse {
(
[("content-type", "application/javascript")],
hive_fr0nt::MARKED_JS,
)
}
#[derive(Serialize)] #[derive(Serialize)]
struct StateSnapshot { struct StateSnapshot {
/// Bus seq at the moment this snapshot was assembled. Clients dedupe /// Bus seq at the moment this snapshot was assembled. Clients dedupe

View file

@ -668,6 +668,10 @@ summary:hover { color: var(--purple); }
align-items: baseline; align-items: baseline;
gap: 0.5em; gap: 0.5em;
padding: 0.1em 0; padding: 0.1em 0;
/* Override the per-agent-terminal's hanging-indent metrics from
TERMINAL_CSS the dashboard's broker rows are flex grids, not
glyph-prefixed text, and don't want the prefix column. */
text-indent: 0;
} }
.live .msgrow .msg-body { .live .msgrow .msg-body {
flex: 1 1 0; flex: 1 1 0;

6
hive-fr0nt/assets/marked.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -60,41 +60,54 @@
from { opacity: 0; transform: translateY(4px); } from { opacity: 0; transform: translateY(4px); }
to { opacity: 1; transform: translateY(0); } to { opacity: 1; transform: translateY(0); }
} }
/* Unified prefix column for every row kind. The glyph (` · !`)
is the first character of the row's text content; `padding-left` reserves
the column and `text-indent: -1.4em` pulls the glyph back into it. Wrapped
continuation lines then start under the body, not under the glyph, so
wraps don't blur into the next row. `details.row` summaries reuse the
same metrics below. */
.live .row { .live .row {
white-space: pre-wrap; white-space: pre-wrap;
word-break: break-word; word-break: break-word;
padding: 0.05em 0; padding: 0.05em 0;
line-height: 1.45; line-height: 1.45;
border-left: 2px solid transparent; border-left: 2px solid transparent;
padding-left: 0.5em; padding-left: 1.9em;
text-indent: -1.4em;
margin: 0.1em 0; margin: 0.1em 0;
} }
.live .row + .row { border-top: 0; } .live .row + .row { border-top: 0; }
/* Row-kind colours. Pages register renderers that emit these classes; /* Row-kind colours. Pages register renderers that emit these classes;
any class no page emits is just dead CSS, which is fine. */ any class no page emits is just dead CSS, which is fine. Turn-framing
.live .turn-start { classes carry their signal entirely on the coloured border-left rule
color: var(--amber); no bold, no top/bottom margins, no background tint. The chrome was
font-weight: bold; overweight for what's just a "this is a boundary" marker. */
margin-top: 1em; .live .turn-start { color: var(--amber); border-left-color: var(--amber); }
border-left-color: var(--amber); /* turn-body is a child block under turn-start carrying the wake-prompt
padding-top: 0.3em; body; reset text-indent so wrapped content stays under its own column
} instead of pulling back into the parent's prefix. */
.live .turn-start:first-child { margin-top: 0; } .live .turn-body { color: var(--fg); text-indent: 0; margin-top: 0.15em; }
.live .turn-body { /* Any child block (markdown body, nested details) resets the parent
color: var(--fg); row's hanging indent so the content lays out from column 0 of the
font-weight: normal; body area. */
margin-top: 0.15em; .live .row .md, .live .row > details { text-indent: 0; }
padding-left: 1.2em; .live .turn-end-ok { color: var(--green); border-left-color: var(--green); }
opacity: 0.85; .live .turn-end-fail { color: var(--red); border-left-color: var(--red); }
} .live .text { color: var(--fg); }
.live .turn-end-ok { color: var(--green); border-left-color: var(--green); margin-bottom: 0.4em; } .live .thinking { color: var(--muted); font-style: italic; }
.live .turn-end-fail { color: var(--red); border-left-color: var(--red); margin-bottom: 0.4em; } .live .tool-use { color: var(--cyan); }
.live .text { color: var(--fg); padding-left: 1.2em; } .live .tool-result { color: var(--muted); }
.live .thinking { color: var(--muted); font-style: italic; padding-left: 1.2em; } .live .result { color: var(--green); }
.live .tool-use { color: var(--cyan); padding-left: 1.2em; } .live .note { color: var(--muted); }
.live .tool-result { color: var(--muted); padding-left: 1.2em; } /* Distinguish stderr lines (orange) and operator-initiated notes
.live .result { color: var(--green); padding-left: 0.5em; } (mauve, lightly emphasised) from ambient harness chatter so the
.live .sys, .live .note { color: var(--muted); } eye picks out anomalies + operator actions in the scrollback. */
.live .note.stderr { color: var(--amber); }
.live .note.op { color: var(--purple); font-style: italic; }
/* The .sys catch-all fires when renderStream landed an event shape it
couldn't classify. Make it visually loud so silently-dropped event
types surface for follow-up. */
.live .sys { color: var(--amber); }
.live .unread-badge { .live .unread-badge {
color: var(--amber); color: var(--amber);
font-weight: normal; font-weight: normal;
@ -137,28 +150,31 @@
pointer-events: auto; pointer-events: auto;
} }
.tail-pill:hover { filter: brightness(1.1); } .tail-pill:hover { filter: brightness(1.1); }
/* Expandable rows reuse the flat-row prefix metrics (padding-left +
negative text-indent) so the disclosure glyph (` / `) lands in
exactly the same column as flat-row prefix glyphs (` · `).
Summary text omits the per-row directional glyph (the row colour
already carries cyan = outbound tool, muted = inbound result) so
the prefix column doesn't have to fit two glyphs side-by-side. */
details.row { details.row {
white-space: normal; white-space: normal;
padding-left: 0.5em;
} }
details.row > summary { details.row > summary {
cursor: pointer; cursor: pointer;
color: var(--muted);
list-style: none; list-style: none;
white-space: pre-wrap; white-space: pre-wrap;
word-break: break-word; word-break: break-word;
} }
details.row > summary::before { details.row > summary::before {
content: '▸ '; content: '▸ ';
color: var(--muted); color: inherit;
display: inline-block;
width: 1em;
} }
details.row[open] > summary::before { content: '▾ '; } details.row[open] > summary::before { content: '▾ '; }
details.row.tool-result-block > summary { color: var(--muted); } details.row > pre.diff-body,
details.row > pre.diff-body { details.row > pre.tool-body {
margin: 0.3em 0 0.4em 1.2em; margin: 0.3em 0 0.4em 0;
padding: 0.4em 0.6em; padding: 0.4em 0.6em;
text-indent: 0;
background: rgba(255, 255, 255, 0.02); background: rgba(255, 255, 255, 0.02);
border-left: 2px solid var(--purple-dim); border-left: 2px solid var(--purple-dim);
white-space: pre-wrap; white-space: pre-wrap;
@ -166,17 +182,44 @@ details.row > pre.diff-body {
max-height: 22em; max-height: 22em;
overflow-y: auto; overflow-y: auto;
} }
details.row > pre.tool-body { color: var(--fg); }
details.row > pre.diff-body .diff-add { color: var(--green); } details.row > pre.diff-body .diff-add { color: var(--green); }
details.row > pre.diff-body .diff-del { color: var(--red); } details.row > pre.diff-body .diff-del { color: var(--red); }
details.row > pre.diff-body .diff-ctx { color: var(--fg); } details.row > pre.diff-body .diff-ctx { color: var(--fg); }
details.row > pre.tool-body { /* Markdown body inside a row (assistant text, send/recv/ask/answer
margin: 0.3em 0 0.4em 1.2em; message bodies). Inline elements get muted accents; block elements
reset the parent row's hanging indent so content lays out cleanly. */
.live .row .md p { margin: 0.2em 0; }
.live .row .md p:first-child { margin-top: 0; }
.live .row .md p:last-child { margin-bottom: 0; }
.live .row .md code {
background: rgba(255, 255, 255, 0.06);
padding: 0.05em 0.3em;
border-radius: 3px;
font-size: 0.95em;
}
.live .row .md pre {
margin: 0.3em 0;
padding: 0.4em 0.6em; padding: 0.4em 0.6em;
background: rgba(255, 255, 255, 0.03); background: rgba(255, 255, 255, 0.04);
border-left: 2px solid var(--purple-dim); border-left: 2px solid var(--purple-dim);
color: var(--fg); text-indent: 0;
white-space: pre-wrap; white-space: pre-wrap;
word-break: break-word; word-break: break-word;
max-height: 22em; }
overflow-y: auto; .live .row .md pre code {
background: transparent;
padding: 0;
border-radius: 0;
}
.live .row .md a { color: var(--cyan); text-decoration: underline; }
.live .row .md strong { color: inherit; font-weight: bold; }
.live .row .md em { color: inherit; font-style: italic; }
.live .row .md ul, .live .row .md ol { margin: 0.2em 0 0.2em 1.4em; padding: 0; }
.live .row .md li { margin: 0.05em 0; }
.live .row .md blockquote {
margin: 0.2em 0;
padding-left: 0.6em;
border-left: 2px solid var(--purple-dim);
color: var(--muted);
} }

View file

@ -32,3 +32,11 @@
pub const BASE_CSS: &str = include_str!("../assets/base.css"); pub const BASE_CSS: &str = include_str!("../assets/base.css");
pub const TERMINAL_CSS: &str = include_str!("../assets/terminal.css"); pub const TERMINAL_CSS: &str = include_str!("../assets/terminal.css");
pub const TERMINAL_JS: &str = include_str!("../assets/terminal.js"); pub const TERMINAL_JS: &str = include_str!("../assets/terminal.js");
/// Vendored [marked](https://github.com/markedjs/marked) v4.0.2 UMD bundle.
/// Exposes a global `marked` with `.parse(src, opts)` returning HTML. Used
/// by the per-agent terminal to render message bodies (`send` / `recv` /
/// `ask` / `answer` / assistant text) with basic markdown — paragraphs,
/// lists, fenced + inline code, bold/italic, links. Vendored rather than
/// CDN-loaded so the per-agent page works on operator machines without
/// internet egress (the container itself never fetches it).
pub const MARKED_JS: &str = include_str!("../assets/marked.min.js");