web: render a turn's input and output as their markdown bodies
The stage pane stringified the step's single-key {markdown} map, so a turn's
output appeared under a literal "markdown:" line inside a code card. The pane now
shows that body as the document it is, with "(no output)" for an empty turn; an
ordinary value map still shows its keys.
This commit is contained in:
@@ -284,5 +284,6 @@
|
||||
app's reading measure and its natural spacing. */
|
||||
.field-markdown { max-width: var(--layout-measure); padding: 2px 0; }
|
||||
.run-markdown-body { max-width: var(--layout-measure); padding: 4px 0; }
|
||||
.stage-field-markdown { max-width: var(--layout-measure); padding: 2px 0 10px; }
|
||||
.field-markdown > :first-child { margin-top: 0; }
|
||||
.field-markdown > :last-child { margin-bottom: 0; }
|
||||
|
||||
+27
-2
@@ -450,6 +450,21 @@ export function evidenceFields(fields) {
|
||||
* receipts. Blank fields are skipped, so no empty row is ever emitted. Mirrors
|
||||
* `runStepFields`.
|
||||
*/
|
||||
/** What an empty turn body reads as, matching input.md's own marker. */
|
||||
const NO_TURN_OUTPUT = "_(no output)_";
|
||||
|
||||
/**
|
||||
* A turn's value map carries the whole markdown body under the single key
|
||||
* `markdown`. Returns that body so the pane can render it as the document it is;
|
||||
* null means an ordinary map that still needs its keys shown.
|
||||
*/
|
||||
function turnBody(map) {
|
||||
if (!map || typeof map !== "object") return null;
|
||||
const keys = Object.keys(map);
|
||||
if (keys.length !== 1 || keys[0] !== "markdown" || typeof map.markdown !== "string") return null;
|
||||
return map.markdown;
|
||||
}
|
||||
|
||||
export function runStepFields(step) {
|
||||
const fields = [];
|
||||
if (step == null) return fields;
|
||||
@@ -471,10 +486,20 @@ export function runStepFields(step) {
|
||||
if (str(step.diagnostic).trim() !== "") fields.push(field("Diagnostic", str(step.diagnostic), false, true));
|
||||
if (str(step.transcript).trim() !== "") fields.push(field("Transcript", str(step.transcript), false, true));
|
||||
if (step.input && Object.keys(step.input).length > 0) {
|
||||
fields.push(field("Input", displayMap(step.input), false, true));
|
||||
const body = turnBody(step.input);
|
||||
fields.push(
|
||||
body == null
|
||||
? field("Input", displayMap(step.input), false, true)
|
||||
: field("Input", body.trim() === "" ? NO_TURN_OUTPUT : body, false, true),
|
||||
);
|
||||
}
|
||||
if (step.output && Object.keys(step.output).length > 0) {
|
||||
fields.push(field("Output", displayMap(step.output), false, true));
|
||||
const body = turnBody(step.output);
|
||||
fields.push(
|
||||
body == null
|
||||
? field("Output", displayMap(step.output), false, true)
|
||||
: field("Output", body.trim() === "" ? NO_TURN_OUTPUT : body, false, true),
|
||||
);
|
||||
}
|
||||
const changes = step.file_changes;
|
||||
if (changes) {
|
||||
|
||||
@@ -315,6 +315,11 @@ function renderFieldValue(value) {
|
||||
|
||||
function renderStageField(field) {
|
||||
if (field.block) {
|
||||
// A turn's input/output is one markdown document: render it as the document,
|
||||
// not as a code card whose label repeats the section title.
|
||||
if (looksLikeMarkdown(field.value)) {
|
||||
return h("div", { class: "stage-field-markdown" }, renderFieldValue(field.value));
|
||||
}
|
||||
return h(
|
||||
"div",
|
||||
{ class: "codeblock" },
|
||||
|
||||
@@ -311,6 +311,20 @@ test("runStepFields skips blanks and formats the visit", () => {
|
||||
assert.ok(fields.every((f) => f.value.trim() !== ""));
|
||||
});
|
||||
|
||||
test("a turn's input and output render as the document they carry", () => {
|
||||
const body = "# Composition\n\n- one\n- two\n";
|
||||
const fields = runStepFields({ input: { markdown: body }, output: { markdown: body } });
|
||||
const input = fields.find((field) => field.label === "Input");
|
||||
const output = fields.find((field) => field.label === "Output");
|
||||
assert.equal(input.value, body);
|
||||
assert.equal(output.value, body);
|
||||
assert.equal(input.block, true);
|
||||
const empty = runStepFields({ output: { markdown: "" } }).find((f) => f.label === "Output");
|
||||
assert.equal(empty.value, "_(no output)_");
|
||||
const map = runStepFields({ output: { summary: "ok", changed: "a.go" } }).find((f) => f.label === "Output");
|
||||
assert.match(map.value, /summary: ok/);
|
||||
});
|
||||
|
||||
test("runStepFields carries every evidence kind the timeline dropped", () => {
|
||||
const fields = runStepFields({
|
||||
status: "completed",
|
||||
|
||||
Reference in New Issue
Block a user