web: render markdown stage bodies as prose
The turn protocol writes a markdown body; the run detail now renders a field as markdown when it has markdown structure (heading, fence, list, table) and keeps the honest monospace block for historical plain-text fields. Pure helper with tests.
This commit is contained in:
@@ -263,3 +263,9 @@
|
||||
.diff-add { color: var(--ok); }
|
||||
.diff-remove { color: var(--bad); }
|
||||
.diff-context { color: var(--muted); }
|
||||
|
||||
/* A markdown stage body (the turn protocol) is prose, not a code block: keep the
|
||||
app's reading measure and its natural spacing. */
|
||||
.field-markdown { max-width: var(--layout-measure); padding: 2px 0; }
|
||||
.field-markdown > :first-child { margin-top: 0; }
|
||||
.field-markdown > :last-child { margin-bottom: 0; }
|
||||
|
||||
@@ -592,6 +592,18 @@ export function clampVisitIndex(index, count) {
|
||||
* artifacts section always shows for a reached visit. Mirrors
|
||||
* `stageSectionSpecs`.
|
||||
*/
|
||||
/**
|
||||
* Whether a recorded field value is markdown rather than plain text: a heading, a
|
||||
* fenced block, a bullet/ordered list or a table. The new stage turns write
|
||||
* markdown bodies (`# outcome` …), while historical steps store plain maps; this
|
||||
* keeps the old ones rendering as code.
|
||||
*/
|
||||
export function looksLikeMarkdown(value) {
|
||||
const text = typeof value === "string" ? value : "";
|
||||
if (!text) return false;
|
||||
return /^#{1,6}\s/m.test(text) || /```/.test(text) || /^\s*(?:[-*]|\d+\.)\s+/m.test(text) || /^\|.+\|/m.test(text);
|
||||
}
|
||||
|
||||
export function stageSectionSpecs(stageKey, graph, runSteps, visitIndex, runContext) {
|
||||
const specs = [];
|
||||
const stage = (graph?.stages ?? []).find((candidate) => candidate?.key === stageKey);
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
verdictReasonSegments,
|
||||
outcomeColorToken,
|
||||
stateGlyph,
|
||||
looksLikeMarkdown,
|
||||
} from "../runDetail.js";
|
||||
import {
|
||||
ArtifactKind,
|
||||
@@ -261,8 +262,27 @@ function renderCodeBlock(label, text) {
|
||||
}
|
||||
|
||||
/** One stage-pane field as either the code card (blocks) or a key/value row. */
|
||||
/**
|
||||
* One recorded field value: a markdown body (the new stage turns) is rendered as
|
||||
* markdown; anything else stays an honest monospace block.
|
||||
*/
|
||||
function renderFieldValue(value) {
|
||||
const text = typeof value === "string" ? value : String(value ?? "");
|
||||
if (looksLikeMarkdown(text)) {
|
||||
return h("div", { class: "field-markdown" }, rt.views.chat.renderMarkdown(text));
|
||||
}
|
||||
return h("pre", { class: "field-block" }, h("code", { text }));
|
||||
}
|
||||
|
||||
function renderStageField(field) {
|
||||
if (field.block) return renderCodeBlock(field.label, field.value);
|
||||
if (field.block) {
|
||||
return h(
|
||||
"div",
|
||||
{ class: "codeblock" },
|
||||
h("div", { class: "codeblock-label", text: field.label }),
|
||||
renderFieldValue(field.value),
|
||||
);
|
||||
}
|
||||
return h(
|
||||
"div",
|
||||
{ class: "kv-row" },
|
||||
@@ -282,9 +302,7 @@ function renderRunFieldTab(map, keyPrefix, emptyMessage) {
|
||||
for (const section of sections) {
|
||||
const key = `${keyPrefix}-${section.key}`;
|
||||
wrap.append(
|
||||
renderCollapsible(key, section.title, () =>
|
||||
h("pre", { class: "field-block" }, h("code", { text: section.value })),
|
||||
),
|
||||
renderCollapsible(key, section.title, () => renderFieldValue(section.value)),
|
||||
);
|
||||
}
|
||||
return wrap;
|
||||
|
||||
@@ -8,6 +8,7 @@ import assert from "node:assert/strict";
|
||||
|
||||
import {
|
||||
RUN_DETAIL_TABS,
|
||||
looksLikeMarkdown,
|
||||
RENDERED_RUN_TABS,
|
||||
EMPTY_INPUT_MESSAGE,
|
||||
EMPTY_OUTPUT_MESSAGE,
|
||||
@@ -608,3 +609,14 @@ test("outcomeColorToken uses the status palette then the flow palette", () => {
|
||||
assert.equal(stateGlyph("succeeded"), "✓");
|
||||
assert.equal(stateGlyph("nonsense"), "?");
|
||||
});
|
||||
|
||||
test("looksLikeMarkdown recognises stage bodies and leaves legacy maps alone", () => {
|
||||
assert.equal(looksLikeMarkdown("# outcome\nsuccess\n\n# notes\nDone."), true);
|
||||
assert.equal(looksLikeMarkdown("Some text\n\n- one\n- two"), true);
|
||||
assert.equal(looksLikeMarkdown("```js\nconst a = 1;\n```"), true);
|
||||
assert.equal(looksLikeMarkdown("| a | b |\n| --- | --- |\n| 1 | 2 |"), true);
|
||||
// Historical field text is a plain map, not markdown.
|
||||
assert.equal(looksLikeMarkdown("summary: ok\nfindings: none"), false);
|
||||
assert.equal(looksLikeMarkdown(""), false);
|
||||
assert.equal(looksLikeMarkdown(null), false);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user