Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

feat(asktool): render content as rich markdown

vastsa2ca9a8660f12
diff --git a/apps/desktop/src/components/AskToolCard.tsx b/apps/desktop/src/components/AskToolCard.tsx
index 9628a2830..793665e8c 100644
--- a/apps/desktop/src/components/AskToolCard.tsx
+++ b/apps/desktop/src/components/AskToolCard.tsx
@@ -5,6 +5,7 @@ import {
askToolOptionLabel,
type AskToolQuestion,
} from "@pi-desktop/shared";
+import { AskToolRichText } from "./AskToolRichText";
import type { PendingAsk } from "../lib/pending-asks";
import { useAppStore } from "../stores/app-store";
import { Button } from "./ui";
@@ -164,7 +165,9 @@ export function AskToolCard({ request, queued = 0 }: { request: PendingAsk; queu
<div className="asktool-question-number">
{t("askTool.questionNumber", { number: index + 1 })}
</div>
- <h3 className="asktool-question">{current.question}</h3>
+ <h3 className="asktool-question">
+ <AskToolRichText source={current.question} />
+ </h3>
<div className="asktool-options" role={current.multiSelect ? "group" : "radiogroup"}>
{current.options.map((option, optionIndex) => {
const label = askToolOptionLabel(option);
@@ -182,9 +185,13 @@ export function AskToolCard({ request, queued = 0 }: { request: PendingAsk; queu
>
<span className="asktool-option-mark" aria-hidden>{selected ? "✓" : ""}</span>
<span className="asktool-option-copy">
- <span>{label}</span>
+ <span className="asktool-option-rich-label">
+ <AskToolRichText source={label} />
+ </span>
{description ? (
- <span className="asktool-option-description">{description}</span>
+ <span className="asktool-option-description">
+ <AskToolRichText source={description} />
+ </span>
) : null}
</span>
</button>
diff --git a/apps/desktop/src/components/AskToolRichText.ts b/apps/desktop/src/components/AskToolRichText.ts
new file mode 100644
index 000000000..f972d3561
--- /dev/null
+++ b/apps/desktop/src/components/AskToolRichText.ts
@@ -0,0 +1,96 @@
+import { createContext, createElement, type ReactElement, type ReactNode, useContext } from "react";
+import ReactMarkdown, { type Components } from "react-markdown";
+import remarkGfm from "remark-gfm";
+
+type RichNodeProps = {
+ children?: ReactNode;
+ alt?: string;
+ checked?: boolean;
+};
+
+function spanBlock(className: string) {
+ return ({ children }: RichNodeProps) =>
+ createElement("span", { className }, children);
+}
+
+type AskToolListKind = "ordered" | "unordered";
+const AskToolListContext = createContext<AskToolListKind>("unordered");
+
+function AskToolList({
+ kind,
+ children,
+}: {
+ kind: AskToolListKind;
+ children?: ReactNode;
+}) {
+ return createElement(
+ AskToolListContext.Provider,
+ { value: kind },
+ createElement(
+ "span",
+ { className: `asktool-rich-list asktool-rich-list-${kind}`, role: "list" },
+ children,
+ ),
+ );
+}
+
+function AskToolListItem({ children }: { children?: ReactNode }) {
+ const kind = useContext(AskToolListContext);
+ return createElement(
+ "span",
+ { className: "asktool-rich-list-item", role: "listitem" },
+ createElement("span", {
+ className: "asktool-rich-list-marker",
+ "aria-hidden": true,
+ ...(kind === "unordered" ? { children: "•" } : {}),
+ }),
+ children,
+ );
+}
+
+const safeMarkdownComponents: Components = {
+ a: ({ children }) =>
+ createElement("span", { className: "asktool-rich-link" }, children),
+ blockquote: spanBlock("asktool-rich-quote"),
+ code: ({ children }) =>
+ createElement("code", { className: "asktool-rich-code" }, children),
+ h1: spanBlock("asktool-rich-heading"),
+ h2: spanBlock("asktool-rich-heading"),
+ h3: spanBlock("asktool-rich-heading"),
+ h4: spanBlock("asktool-rich-heading"),
+ h5: spanBlock("asktool-rich-heading"),
+ h6: spanBlock("asktool-rich-heading"),
+ hr: () => createElement("span", { className: "asktool-rich-rule", "aria-hidden": true }),
+ img: ({ alt }) =>
+ alt
+ ? createElement("span", { className: "asktool-rich-image-alt" }, alt)
+ : null,
+ input: ({ checked }) =>
+ createElement(
+ "span",
+ { className: "asktool-rich-task-marker", "aria-hidden": true },
+ checked ? "✓" : "○",
+ ),
+ li: ({ children }) => createElement(AskToolListItem, null, children),
+ ol: ({ children }) => createElement(AskToolList, { kind: "ordered" }, children),
+ p: spanBlock("asktool-rich-paragraph"),
+ pre: spanBlock("asktool-rich-pre"),
+ table: spanBlock("asktool-rich-table"),
+ tbody: spanBlock("asktool-rich-table-row"),
+ td: spanBlock("asktool-rich-table-cell"),
+ tfoot: spanBlock("asktool-rich-table-row"),
+ th: spanBlock("asktool-rich-table-cell"),
+ thead: spanBlock("asktool-rich-table-row"),
+ tr: spanBlock("asktool-rich-table-row"),
+ ul: ({ children }) => createElement(AskToolList, { kind: "unordered" }, children),
+};
+
+/** Safe Markdown projection for asktool text that can appear inside a button. */
+export function AskToolRichText({ source }: { source: string }): ReactElement {
+ return createElement(ReactMarkdown, {
+ components: safeMarkdownComponents,
+ remarkPlugins: [remarkGfm],
+ skipHtml: true,
+ children: source,
+ });
+}
diff --git a/apps/desktop/src/styles/messages.css b/apps/desktop/src/styles/messages.css
index 3cfce77bd..fe8361917 100644
--- a/apps/desktop/src/styles/messages.css
+++ b/apps/desktop/src/styles/messages.css
@@ -199,6 +199,93 @@
gap: 2px;
}
+.asktool-rich-paragraph,
+.asktool-rich-heading,
+.asktool-rich-list,
+.asktool-rich-list-item,
+.asktool-rich-quote,
+.asktool-rich-pre,
+.asktool-rich-table,
+.asktool-rich-table-row,
+.asktool-rich-table-cell {
+ display: block;
+ margin: 0;
+}
+
+.asktool-rich-heading {
+ font-weight: var(--font-weight-semibold);
+}
+
+.asktool-rich-list {
+ padding-inline-start: 4px;
+}
+
+.asktool-rich-list-ordered {
+ counter-reset: asktool-option-item;
+}
+
+.asktool-rich-list-item + .asktool-rich-list-item {
+ margin-top: 2px;
+}
+
+.asktool-rich-list-ordered > .asktool-rich-list-item {
+ counter-increment: asktool-option-item;
+}
+
+.asktool-rich-list-ordered > .asktool-rich-list-item > .asktool-rich-list-marker::before {
+ content: counter(asktool-option-item) ". ";
+}
+
+.asktool-rich-list-unordered > .asktool-rich-list-item > .asktool-rich-list-marker {
+ margin-inline-end: 5px;
+ color: var(--ds-text-muted);
+}
+
+.asktool-rich-quote {
+ padding-inline-start: 6px;
+ color: var(--ds-text-muted);
+}
+
+.asktool-rich-pre {
+ white-space: pre-wrap;
+ overflow-wrap: anywhere;
+}
+
+.asktool-rich-task-marker,
+.asktool-rich-image-alt {
+ color: var(--ds-text-muted);
+}
+
+.asktool-rich-image-alt {
+ font-style: italic;
+}
+
+.asktool-rich-rule {
+ display: block;
+ height: 1px;
+ margin: 4px 0;
+ background: var(--ds-text-faint);
+}
+
+.asktool-rich-table-row {
+ display: flex;
+ gap: 6px;
+}
+
+.asktool-rich-table-cell {
+ min-width: 0;
+ overflow-wrap: anywhere;
+}
+
+.asktool-rich-code {
+ border-radius: var(--radius-2xs);
+ background: var(--ds-tile-deep);
+ padding: 1px 3px;
+ font-family: var(--font-mono);
+ font-size: var(--text-sm);
+ overflow-wrap: anywhere;
+}
+
.asktool-option-description {
color: var(--ds-text-muted);
font-size: var(--text-xs);
diff --git a/apps/desktop/test/asktool-rich-options.test.mjs b/apps/desktop/test/asktool-rich-options.test.mjs
index 590174108..611abf032 100644
--- a/apps/desktop/test/asktool-rich-options.test.mjs
+++ b/apps/desktop/test/asktool-rich-options.test.mjs
@@ -1,4 +1,6 @@
import assert from "node:assert/strict";
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
import { readFile } from "node:fs/promises";
import test from "node:test";
import {
@@ -6,7 +8,12 @@ import {
askToolOptionLabel,
normalizeAskToolOption,
} from "../../../packages/shared/src/types/agent.ts";
+import { AskToolRichText } from "../src/components/AskToolRichText.ts";
+const richTextSource = await readFile(
+ new URL("../src/components/AskToolRichText.ts", import.meta.url),
+ "utf8",
+);
const cardSource = await readFile(
new URL("../src/components/AskToolCard.tsx", import.meta.url),
"utf8",
@@ -33,10 +40,36 @@ test("asktool keeps legacy strings and normalizes rich labels and descriptions",
assert.equal(askToolOptionDescription(legacy), undefined);
});
-test("asktool card presents descriptions without changing the selected answer", () => {
- assert.match(cardSource, /askToolOptionLabel\(option\)/);
- assert.match(cardSource, /askToolOptionDescription\(option\)/);
+test("asktool renders rich question and option content while keeping label answers intact", () => {
+ assert.match(cardSource, /<AskToolRichText source=\{current\.question\} \/>/);
+ assert.match(cardSource, /<AskToolRichText source=\{label\} \/>/);
+ assert.match(cardSource, /<AskToolRichText source=\{description\} \/>/);
assert.match(cardSource, /onClick=\{\(\) => selectOption\(label\)\}/);
- assert.match(cardSource, /className="asktool-option-description"/);
- assert.match(styleSource, /\.asktool-option-description\s*\{/);
+ assert.match(richTextSource, /remarkPlugins: \[remarkGfm\]/);
+ assert.match(styleSource, /\.asktool-rich-code\s*\{/);
+
+ const html = renderToStaticMarkup(
+ createElement(AskToolRichText, {
+ source:
+ "**Bold** and *italic*, ~~removed~~, `code`, and\n\n- one\n- two\n\n1. first\n2. second",
+ }),
+ );
+ assert.match(html, /<strong>Bold<\/strong>/);
+ assert.match(html, /<em>italic<\/em>/);
+ assert.match(html, /<del>removed<\/del>/);
+ assert.match(html, /<code[^>]*>code<\/code>/);
+ assert.match(html, /role="list"/);
+ assert.match(html, /asktool-rich-list-ordered/);
+});
+
+test("asktool rich content never creates live links, images, or raw HTML", () => {
+ const html = renderToStaticMarkup(
+ createElement(AskToolRichText, {
+ source:
+ "[Open](https://example.invalid) ![diagram](https://example.invalid/x.png)\n\n<script>alert(1)</script>",
+ }),
+ );
+ assert.match(html, /Open/);
+ assert.match(html, /diagram/);
+ assert.doesNotMatch(html, /<a\b|<img\b|<script\b|href=|src=/i);
});
diff --git a/docs/adr/0077-asktool-interactive-multi-question-flow.md b/docs/adr/0077-asktool-interactive-multi-question-flow.md
index ba2e5f752..514829536 100644
--- a/docs/adr/0077-asktool-interactive-multi-question-flow.md
+++ b/docs/adr/0077-asktool-interactive-multi-question-flow.md
@@ -38,3 +38,12 @@ stable tool output so the model can distinguish it from a missing tool result.
require a protocol version bump.
- Aborting a turn completes the outstanding tool call with skipped values so a
pending card cannot strand the runtime.
+
+
+## Amendment — 2026-09-27: Render asktool content as Markdown
+
+`question`, selectable option text, and optional option descriptions may use
+CommonMark/GFM. The renderer uses a safe phrasing-content projection: raw HTML
+is ignored, links are non-interactive, and images do not load. Selection and
+tool output preserve the normalized source strings; Markdown affects display
+only. The request schema and protocol version are unchanged.
diff --git a/docs/spec/03-runtime/17-asktool-questions.md b/docs/spec/03-runtime/17-asktool-questions.md
index 7d266b500..e257fddec 100644
--- a/docs/spec/03-runtime/17-asktool-questions.md
+++ b/docs/spec/03-runtime/17-asktool-questions.md
@@ -11,14 +11,18 @@ deadline.
The tool accepts a non-empty `questions` array. Each question contains:
-- `question`: the prompt text;
-- `options`: one or more selectable answer labels, each either a string or an
- object with a required `label` and optional `description`;
+- `question`: the prompt text, which may include Markdown;
+- `options`: one or more selectable answer labels, each either a Markdown
+ string or an object with a required Markdown `label` and optional Markdown
+ `description`;
- `multiSelect`: optional; when true, more than one selectable answer is allowed.
-Plain string options remain supported. The card shows an object's description
-as secondary text, while selection and the model-facing answer continue to use
-only its label. The desktop card always adds one extra `Enter another answer`
+Plain string options remain supported. The card renders CommonMark/GFM text
+formatting such as emphasis, inline code, paragraphs, and lists. Links render as
+non-interactive text, images as alt text, and raw HTML is ignored. An object's
+label and optional description use the same renderer. Rendering never rewrites
+the option value: selection and the model-facing answer use its normalized
+source label. The desktop card always adds one extra `Enter another answer`
option with a text field. The model does not need to add a special free-text
choice to the tool arguments.
@@ -43,7 +47,9 @@ event plays one soft in-app chime; its toast does not play a second one.
## 4. Tool output
The response is the normal tool result returned to the model and persisted with
-the tool row. For each question, the content is serialized as:
+the tool row. Markdown source is retained in the serialized question and
+selected label; rendering is presentation-only. For each question, content is
+serialized as:
```text
question text:answer label 1、answer label 2
diff --git a/docs/spec/04-ux/11-asktool-question-card.md b/docs/spec/04-ux/11-asktool-question-card.md
index e1441a904..832a53e37 100644
--- a/docs/spec/04-ux/11-asktool-question-card.md
+++ b/docs/spec/04-ux/11-asktool-question-card.md
@@ -29,13 +29,17 @@ The card has no countdown or expiration copy. On narrow screens options remain
full-width and actions may share the row; question text and custom input may
wrap naturally without clipping.
-## Rich options
-
-A selectable option may remain a plain string or use `{ label, description? }`.
-The label keeps the existing option typography and selection behavior; the
-optional description appears beneath it in muted supporting text and wraps
-within the row. Clicking either line selects the same label, which is the only
-value returned to the model. The custom-answer option remains unchanged.
+## Rich-text content
+
+Question text and selectable option text may use CommonMark/GFM formatting,
+including emphasis, inline code, paragraphs, and lists. The card renders this
+content inline with its existing compact typography. In option buttons links are
+non-interactive text, images render as alt text, and raw HTML is ignored; this
+avoids nested interactive controls and external image loading. Plain strings
+remain supported, and `{ label, description? }` options render both text fields
+with the same Markdown rules. Selecting an option returns its normalized source
+label unchanged; formatting is display-only. The custom-answer option is not
+Markdown-interpreted.
## Typography hierarchy
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 14c4c56e4..a9c10f618 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -9727,9 +9727,9 @@ This test plan spec is accepted when:
- **Preconditions**: Agent, Plan, or Goal mode; a configured provider; a
session with an active transcript.
- **Steps**: 1) Ask the agent to call `asktool` with a single-select question,
- a multi-select question, and option lists containing both strings and
- `{ label, description }` objects. 2) Confirm each card shows the fixed
- custom-input choice and rich option descriptions. 3) Answer the first question,
+ a multi-select question, and question/option text with Markdown emphasis,
+ inline code, and a short list. 2) Confirm each card renders the formatting
+ while keeping choices keyboard/selectable. 3) Answer the first question,
click Next, and select two answers on the multi-select question. 4) Skip the final
question without entering text. 5) Inspect the completed tool row and the
next model response.
@@ -9750,8 +9750,9 @@ This test plan spec is accepted when:
action row. The tool output is ordered as
`question:answer`, uses `、` between multiple answers and `\n---\n`
between questions, and
- keeps `question:` for the skipped question, and selecting a rich option
- returns only its label. Decline all produces empty placeholders for every
+ keeps `question:` for the skipped question. Markdown renders as rich text
+ without activating embedded links or loading images. Selecting a formatted
+ option returns its original Markdown source label. Decline all produces empty placeholders for every
question and still completes the tool call. A pending ask shows a stable
localized title and the first question in its toast; generated session-title
text never replaces that title. Background sessions retain the existing
diff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.ts
index 029e11bad..f3c844e43 100644
--- a/packages/agent-runtime/src/runtime.test.ts
+++ b/packages/agent-runtime/src/runtime.test.ts
@@ -1986,9 +1986,9 @@ describe("DesktopAgentRuntime deferred tool catalog", () => {
const pending = askTool.execute("ask-call-1", {
questions: [
{
- question: "Color?",
+ question: "**Color?**",
options: [
- { label: "Blue", description: "A calm, cool color." },
+ { label: "**Blue**", description: "A calm, cool color." },
"Green",
],
},
@@ -2005,9 +2005,9 @@ describe("DesktopAgentRuntime deferred tool catalog", () => {
toolCallId: "ask-call-1",
questions: [
{
- question: "Color?",
+ question: "**Color?**",
options: [
- { label: "Blue", description: "A calm, cool color." },
+ { label: "**Blue**", description: "A calm, cool color." },
"Green",
],
},
@@ -2018,12 +2018,12 @@ describe("DesktopAgentRuntime deferred tool catalog", () => {
runtime.resolveAskTool({
requestId: request.requestId,
sessionId: "session-1",
- answers: [["Blue"], null],
+ answers: [["**Blue**"], null],
}),
).toEqual({ ok: true });
await expect(pending).resolves.toMatchObject({
- content: [{ text: "Color?:Blue\n---\nTargets?:" }],
- details: { answers: [["Blue"], null] },
+ content: [{ text: "**Color?**:**Blue**\n---\nTargets?:" }],
+ details: { answers: [["**Blue**"], null] },
});
await runtime.dispose();
});
diff --git a/packages/agent-runtime/src/runtime.ts b/packages/agent-runtime/src/runtime.ts
index 53ac0c021..60f54f068 100644
--- a/packages/agent-runtime/src/runtime.ts
+++ b/packages/agent-runtime/src/runtime.ts
@@ -2919,7 +2919,7 @@ Do not invent objections or turn speculative risks into blockers. Stop when the
case "Bash":
return `${commandShellToolDescription(this.commandShell, this.scratchDir)} Use Edit or Write instead of apply_patch, git apply, or patch; do not retry a failed shell patch command repeatedly.`;
case ASK_TOOL_NAME:
- return "Ask the user one or more questions. Options may be plain labels or objects with a `label` and optional `description`; the desktop card always provides a custom user-input option. Unanswered questions are returned as empty answers.";
+ return "Ask the user one or more questions. Use Markdown in question text and option labels when formatting helps (for example, emphasis, inline code, or lists); the desktop card renders it safely. Plain strings and existing `{ label, description? }` options are accepted, and answers return the selected source label. The card always provides a custom user-input option.";
case "PluginScaffold":
return "Create a PI-Desktop plugin from a template and load it for development. `directory` is workspace-relative and must be empty or new; `template` is one of panel-basic, agent-tool-basic, skill-pack, full-demo. Use this instead of hand-writing plugin files.";
case "PluginCheck":
diff --git a/packages/shared/src/asktool.test.ts b/packages/shared/src/asktool.test.ts
index 6cf7068a6..ea673946a 100644
--- a/packages/shared/src/asktool.test.ts
+++ b/packages/shared/src/asktool.test.ts
@@ -7,7 +7,7 @@ describe("asktool output", () => {
{
question: "Which platforms?",
options: [
- { label: "Web", description: "Runs in a browser." },
+ { label: "**Web**", description: "Runs in a browser." },
{ label: "Desktop", description: "Installs on the user's computer." },
],
multiSelect: true,
@@ -15,8 +15,8 @@ describe("asktool output", () => {
];
it("serializes each question with selected answers and a stable separator", () => {
- expect(formatAskToolOutput(questions, [["Blue"], ["Web", "Desktop"]])).toBe(
- "Preferred color?:Blue\n---\nWhich platforms?:Web、Desktop",
+ expect(formatAskToolOutput(questions, [["Blue"], ["**Web**", "Desktop"]])).toBe(
+ "Preferred color?:Blue\n---\nWhich platforms?:**Web**、Desktop",
);
});