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:
parent
f827187341
commit
f8f2ccff52
7 changed files with 256 additions and 52 deletions
|
|
@ -656,6 +656,79 @@
|
|||
log.innerHTML = '';
|
||||
|
||||
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
|
||||
// for unknown tools.
|
||||
function fmtToolUse(c) {
|
||||
|
|
@ -678,7 +751,7 @@
|
|||
case 'mcp__hyperhive__kill': return short + ' ' + (input.name || '');
|
||||
case 'mcp__hyperhive__request_apply_commit':
|
||||
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
|
||||
|
|
@ -709,37 +782,73 @@
|
|||
+ '\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;
|
||||
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') {
|
||||
const to = input.to || '?';
|
||||
const body = String(input.body || '');
|
||||
const headline = body.replace(/\s+/g, ' ').trim().slice(0, 80);
|
||||
const lines = body.split('\n').length;
|
||||
const summary = '→ send → ' + to + (lines > 1 ? ` · ${lines}L` : '')
|
||||
+ (headline ? ' · ' + headline + (body.length > 80 ? '…' : '') : '');
|
||||
return api.details('tool-use', summary, body);
|
||||
return detailsOpenMd(api, 'tool-use',
|
||||
'send → ' + to + (lines > 1 ? ` · ${lines}L` : ''),
|
||||
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;
|
||||
}
|
||||
// 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) {
|
||||
const txt = Array.isArray(c.content)
|
||||
? c.content.map(p => p.text || '').join('')
|
||||
: (c.content || '');
|
||||
const summary = '← ' + (() => {
|
||||
const trimmed = txt.replace(/\s+/g, ' ').trim();
|
||||
const sourceName = c.tool_use_id ? toolNameById.get(c.tool_use_id) : null;
|
||||
const isMessageBearing = sourceName === 'mcp__hyperhive__recv';
|
||||
const trimmed = txt.replace(/\s+/g, ' ').trim();
|
||||
const summaryBody = (() => {
|
||||
if (!trimmed) return '(empty)';
|
||||
if (trimmed.length <= 120) return trimmed;
|
||||
const lines = txt.split('\n').filter(l => l.length).length;
|
||||
const headline = trimmed.slice(0, 90) + '…';
|
||||
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) {
|
||||
api.row('tool-result', summary);
|
||||
api.row('tool-result', '← ' + summaryBody);
|
||||
} else {
|
||||
api.details('tool-result-block', summary, txt);
|
||||
api.details('tool-result-block', summaryBody, txt);
|
||||
}
|
||||
}
|
||||
// Pretty-render claude's background-task subagent events
|
||||
|
|
@ -783,12 +892,19 @@
|
|||
}
|
||||
if (v.type === 'assistant' && v.message && 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') {
|
||||
const txt = (c.thinking || c.text || '').trim();
|
||||
api.row('thinking', txt ? '· ' + txt : '· thinking …');
|
||||
}
|
||||
else if (c.type === 'tool_use') {
|
||||
if (c.id && c.name) toolNameById.set(c.id, c.name);
|
||||
if (!renderRichToolUse(c, api)) {
|
||||
api.row('tool-use', '→ ' + fmtToolUse(c));
|
||||
}
|
||||
|
|
@ -802,7 +918,10 @@
|
|||
}
|
||||
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 +
|
||||
|
|
@ -844,7 +963,22 @@
|
|||
(ev.ok ? '✓' : '✗') + ' turn ' + (ev.ok ? 'ok' : 'fail')
|
||||
+ (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) {
|
||||
const v = Object.assign({}, ev); delete v.kind;
|
||||
renderStream(v, api);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
<div id="term-input" class="term-input"></div>
|
||||
</div>
|
||||
|
||||
<script src="/static/marked.js" defer></script>
|
||||
<script src="/static/hive-fr0nt.js" defer></script>
|
||||
<script src="/static/app.js" defer></script>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue