Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
feat(chat): summarize asktool history answers
vastsaba82998bbfd7
diff --git a/apps/desktop/src/components/ToolDetails.tsx b/apps/desktop/src/components/ToolDetails.tsxindex 7bc851997..2c825e1ac 100644--- a/apps/desktop/src/components/ToolDetails.tsx+++ b/apps/desktop/src/components/ToolDetails.tsx@@ -9,6 +9,7 @@ import { useChatFileMenu } from "../hooks/use-chat-file-menu";import { ContextMenu } from "./ContextMenu";import { useAppStore } from "../stores/app-store";import type { ToolBlock, ToolChip } from "../lib/tool-presentation";+import { AskToolRichText } from "./AskToolRichText";/** Renderer for the structured tool presentation (D192). Blocks arrive with a@@ -35,6 +36,10 @@ const BLOCK_LABEL_KEYS: Record<ToolBlock["role"], string> = {function blockCopyText(block: ToolBlock): string {switch (block.kind) {+ case "asktool":+ return block.questions+ .map(({ question, answers }) => `${question}:${answers?.join("、") ?? ""}`)+ .join("\n---\n");case "code":return block.text;case "diff":@@ -82,6 +87,49 @@ function MoreNote({ hidden }: { hidden: number }) {);}+function AskToolResult({+ block,+}: {+ block: Extract<ToolBlock, { kind: "asktool" }>;+}) {+ const { t } = useTranslation();+ return (+ <dl className="tool-asktool-results" aria-label={t("askTool.historyTitle")}>+ {block.questions.map((entry, index) => (+ <div className="tool-asktool-entry" key={`${index}-${entry.question}`}>+ <dt className="tool-asktool-question">+ <span className="tool-asktool-question-number">+ {t("askTool.questionNumber", { number: index + 1 })}+ </span>+ <span className="tool-asktool-question-copy">+ <AskToolRichText source={entry.question} />+ </span>+ </dt>+ <dd className="tool-asktool-answer">+ <span className="tool-asktool-answer-label">+ {t("askTool.answerLabel")}+ </span>+ <span className="tool-asktool-answer-values">+ {entry.answers?.length ? (+ entry.answers.map((answer, answerIndex) => (+ <span+ className="tool-asktool-answer-value"+ key={`${answerIndex}-${answer}`}+ >+ <AskToolRichText source={answer} />+ </span>+ ))+ ) : (+ <span className="tool-asktool-skipped">{t("askTool.skipped")}</span>+ )}+ </span>+ </dd>+ </div>+ ))}+ </dl>+ );+}+/** A workspace path list (Glob results, plugin string arrays). */function FileList({ paths }: { paths: string[] }) {const { t } = useTranslation();@@ -160,6 +208,8 @@ function MatchList({ block }: { block: Extract<ToolBlock, { kind: "matches" }> }function BlockBody({ block, streaming }: { block: ToolBlock; streaming: boolean }) {switch (block.kind) {+ case "asktool":+ return <AskToolResult block={block} />;case "code":return (<LargeTextPreview@@ -241,7 +291,11 @@ export function ToolDetailBlocks({return (<>{blocks.map((block, index) => {- const label = block.label ?? t(BLOCK_LABEL_KEYS[block.role]);+ const label =+ block.label ??+ (block.kind === "asktool"+ ? t("askTool.historyTitle")+ : t(BLOCK_LABEL_KEYS[block.role]));return (<sectionclassName={cx("tool-block", plain && "is-plain")}diff --git a/apps/desktop/src/lib/tool-display.ts b/apps/desktop/src/lib/tool-display.tsindex 802da3cf4..ba7299108 100644--- a/apps/desktop/src/lib/tool-display.ts+++ b/apps/desktop/src/lib/tool-display.ts@@ -62,6 +62,10 @@ function bareToolName(toolName?: string): string {.replace(/[^a-z0-9]+/g, "");}+export function isAskToolName(toolName?: string): boolean {+ return toolName?.toLowerCase() === "asktool";+}+/** The tool that STARTS a subagent (ADR 0062). The lifecycle tools of ADR 0089* (TaskWait/TaskList/TaskStop) drive an existing delegation and are not* delegation activity items themselves. */@@ -178,6 +182,15 @@ export function getToolSummary(toolName: string | undefined, args: unknown) {const action = getToolAction(toolName);if (args && typeof args === "object") {const record = args as Record<string, unknown>;+ if (isAskToolName(toolName) && Array.isArray(record.questions)) {+ const first = record.questions[0];+ if (first && typeof first === "object" && !Array.isArray(first)) {+ const question = (first as Record<string, unknown>).question;+ if (typeof question === "string" && question.trim()) {+ return compact(question);+ }+ }+ }const key = getToolSummaryKey(toolName, args);if (key) return compact(summaryText(record[key]));const fallback = formatToolValue(record);diff --git a/apps/desktop/src/lib/tool-presentation.ts b/apps/desktop/src/lib/tool-presentation.tsindex b1e0bb7e6..8d88b0ef9 100644--- a/apps/desktop/src/lib/tool-presentation.ts+++ b/apps/desktop/src/lib/tool-presentation.ts@@ -3,6 +3,7 @@ import {delegationLifecycleKind,getToolAction,getToolSummaryKey,+ isAskToolName,type ToolAction,} from "./tool-display";import { reviewChangeFromMessage } from "./workspace-review";@@ -75,6 +76,10 @@ type BlockBase = {};export type ToolBlock =+ | (BlockBase & {+ kind: "asktool";+ questions: { question: string; answers: string[] | null }[];+ })| (BlockBase & {kind: "code";text: string;@@ -433,6 +438,41 @@ function safeJson(value: unknown): string {}}+function askToolResultBlock(+ message: ToolPresentationMessage,+): ToolBlock | null {+ const details = asRecord(toolResultPayload(message));+ const rawQuestions = details?.questions;+ const rawAnswers = details?.answers;+ if (+ !Array.isArray(rawQuestions) ||+ rawQuestions.length === 0 ||+ !Array.isArray(rawAnswers) ||+ rawQuestions.length !== rawAnswers.length+ ) {+ return null;+ }++ const questions: Array<{ question: string; answers: string[] | null }> = [];+ for (let index = 0; index < rawQuestions.length; index += 1) {+ const question = stringAt(asRecord(rawQuestions[index]), "question");+ const answer = rawAnswers[index];+ if (+ question === null ||+ !(answer === null ||+ (Array.isArray(answer) && answer.every((value) => typeof value === "string")))+ ) {+ return null;+ }+ questions.push({+ question,+ answers: answer === null || answer.length === 0 ? null : [...answer],+ });+ }++ return { kind: "asktool", role: "details", questions };+}+/*** What actually happened to a command, read from what the shell returned rather* than from the status of the call that carried it: a command that exits@@ -695,6 +735,11 @@ export function buildToolPresentation(message: ToolPresentationMessage,options: ToolPresentationOptions = {},): ToolBlock[] {+ if (isAskToolName(message.toolName)) {+ const askToolBlock = askToolResultBlock(message);+ if (askToolBlock) return [askToolBlock];+ }+const action = getToolAction(message.toolName);const args = asRecord(message.toolArgs);const payload = toolResultPayload(message);diff --git a/apps/desktop/src/styles/messages.css b/apps/desktop/src/styles/messages.cssindex 2847fddbd..8ced7080b 100644--- a/apps/desktop/src/styles/messages.css+++ b/apps/desktop/src/styles/messages.css@@ -3089,6 +3089,80 @@white-space: pre-wrap;}+.tool-asktool-results {+ display: grid;+ max-height: 260px;+ margin: 0;+ overflow: auto;+ overscroll-behavior-y: contain;+ border-radius: var(--radius-md);+ background: var(--ds-tile);+ padding: 10px 12px;+ gap: 10px;+ scrollbar-gutter: stable;+}++.tool-asktool-entry + .tool-asktool-entry {+ border-top: 1px solid var(--ds-border-subtle);+ padding-top: 10px;+}++.tool-asktool-question {+ display: flex;+ flex-direction: column;+ gap: 4px;+ margin: 0;+}++.tool-asktool-question-number,+.tool-asktool-answer-label {+ color: var(--ds-text-muted);+ font-size: var(--text-xs);+ font-weight: var(--font-weight-medium);+}++.tool-asktool-question-copy {+ color: var(--ds-text-primary);+ font-size: var(--text-sm);+ font-weight: var(--font-weight-medium);+ line-height: var(--leading-normal);+ overflow-wrap: anywhere;+}++.tool-asktool-answer {+ display: flex;+ align-items: baseline;+ gap: 8px;+ margin: 6px 0 0;+}++.tool-asktool-answer-label {+ flex: none;+}++.tool-asktool-answer-values {+ display: flex;+ min-width: 0;+ flex-wrap: wrap;+ align-items: baseline;+ gap: 4px 6px;+}++.tool-asktool-answer-value {+ display: inline-flex;+ max-width: 100%;+ border-radius: var(--radius-sm);+ background: var(--ds-tile-deep);+ padding: 3px 7px;+ color: var(--ds-text-secondary);+ overflow-wrap: anywhere;+}++.tool-asktool-skipped {+ color: var(--ds-text-muted);+ font-style: italic;+}+/* Scalar payload entries (plugin tools, argument previews). Bounded like everyother detail block (`.tool-row-content`, `.tool-file-list`): a roster of tendelegates or a payload with thirty fields must not push the reading positiondiff --git a/apps/desktop/test/asktool-history-presentation.test.mjs b/apps/desktop/test/asktool-history-presentation.test.mjsnew file mode 100644index 000000000..d2a714eec--- /dev/null+++ b/apps/desktop/test/asktool-history-presentation.test.mjs@@ -0,0 +1,103 @@+import assert from "node:assert/strict";+import test from "node:test";+import { createElement } from "react";+import { slotSsr } from "./helpers/slot-ssr.mjs";++const questions = [+ {+ question: "Which **deployment** target?",+ options: ["Web", "Desktop"],+ },+ {+ question: "Which platforms should be supported?",+ options: ["macOS", "Windows", "Linux"],+ multiSelect: true,+ },+ {+ question: "Should beta updates be enabled?",+ options: ["Yes", "No"],+ },+];++const message = {+ id: "asktool-history-1",+ role: "tool",+ content: "",+ createdAt: "2026-10-09T00:00:00.000Z",+ status: "complete",+ toolName: "asktool",+ toolCallId: "asktool-call-1",+ toolStatus: "success",+ toolArgs: { questions },+ toolResult: {+ content: [+ {+ type: "text",+ text: [+ "Which **deployment** target?:Desktop",+ "Which platforms should be supported?:macOS、Linux",+ "Should beta updates be enabled?:",+ ].join("\n---\n"),+ },+ ],+ details: { questions, answers: [["Desktop"], ["macOS", "Linux"], null] },+ },+};++test("completed asktool transcript rows show a readable Q&A summary", async (t) => {+ const ssr = await slotSsr(t, {+ translationOverrides: {+ askTool: {+ historyTitle: "Questions and answers",+ answerLabel: "Answer",+ skipped: "Skipped",+ },+ },+ });+ const { ToolRow } = await ssr.load("/src/features/chat/transcript/ToolRow.tsx");+ const { buildToolPresentation } = await ssr.load("/src/lib/tool-presentation.ts");+ const { ToolDetailBlocks } = await ssr.load("/src/components/ToolDetails.tsx");++ const row = ssr.render(createElement(ToolRow, { message }));+ assert.match(row, /Which \*\*deployment\*\* target\?/);+ assert.doesNotMatch(row, /questions|options/);++ const blocks = buildToolPresentation(message);+ assert.equal(blocks.length, 1);+ assert.equal(blocks[0].kind, "asktool");+ assert.deepEqual(blocks[0].questions[1].answers, ["macOS", "Linux"]);+ assert.equal(blocks[0].questions[2].answers, null);+ const details = ssr.render(createElement(ToolDetailBlocks, { blocks }));+ assert.match(details, /tool-asktool-results/);+ assert.match(details, /Questions and answers/);+ assert.match(details, /Which <strong>deployment<\/strong> target\?/);+ assert.match(details, /Which platforms should be supported\?/);+ assert.match(details, /Should beta updates be enabled\?/);+ assert.equal((details.match(/class="tool-asktool-answer-value"/g) ?? []).length, 3);+ assert.match(details, /Answer/);+ assert.match(details, /Desktop/);+ assert.match(details, /Skipped/);+ assert.match(details, /tool-asktool-skipped/);+ assert.doesNotMatch(details, /"answers"|"questions"|<pre/);+});++test("asktool rows retain generic output when structured history is unavailable", async (t) => {+ const ssr = await slotSsr(t);+ const { buildToolPresentation } = await ssr.load("/src/lib/tool-presentation.ts");+ const legacy = buildToolPresentation({+ ...message,+ toolResult: "Which deployment target?:Desktop",+ });+ assert.ok(legacy.some((block) => block.kind === "code" && block.role === "output"));+ assert.ok(legacy.some((block) => block.role === "input"));++ const malformed = buildToolPresentation({+ ...message,+ toolResult: {+ content: [{ type: "text", text: "invalid" }],+ details: { questions: "invalid", answers: [] },+ },+ });+ assert.ok(malformed.length > 0);+ assert.notEqual(malformed[0].kind, "asktool");+});diff --git a/apps/desktop/test/helpers/slot-ssr.mjs b/apps/desktop/test/helpers/slot-ssr.mjsindex 00325ef92..51c4808a3 100644--- a/apps/desktop/test/helpers/slot-ssr.mjs+++ b/apps/desktop/test/helpers/slot-ssr.mjs@@ -16,7 +16,7 @@ import { fileURLToPath } from "node:url";* mount, before any measuring, timer or listener. Behavior that needs those* is covered at the logic layer or in the Electron E2E.*/-export async function slotSsr(t) {+export async function slotSsr(t, { translationOverrides = {} } = {}) {const server = await createServer({root: fileURLToPath(new URL("../..", import.meta.url)),configFile: false,@@ -37,7 +37,14 @@ export async function slotSsr(t) {});const i18n = createInstance();- await i18n.init({ lng: "en", resources: { en: { translation: catalogs.en } } });+ const englishTranslation = {+ ...catalogs.en,+ ...translationOverrides,+ ...(translationOverrides.askTool+ ? { askTool: { ...catalogs.en.askTool, ...translationOverrides.askTool } }+ : {}),+ };+ await i18n.init({ lng: "en", resources: { en: { translation: englishTranslation } } });const load = (path) => server.ssrLoadModule(path);const { slotRegistry } = await load("/src/plugins/renderer-slots/registry.ts");const { SlotSessionProvider } = await load("/src/plugins/renderer-slots/use-slots.tsx");diff --git a/docs/spec/03-runtime/17-asktool-questions.md b/docs/spec/03-runtime/17-asktool-questions.mdindex a123d54d4..56b0d24e9 100644--- a/docs/spec/03-runtime/17-asktool-questions.md+++ b/docs/spec/03-runtime/17-asktool-questions.md@@ -65,3 +65,13 @@ question text:This format is deterministic, preserves question order, and makes multi-selectanswers distinguishable without exposing a renderer-only state object to themodel.++## 5. Transcript summary++The completed asktool row in conversation history presents persisted+`details.questions` and `details.answers` as an ordered question-and-answer+summary. Multi-select answers remain separate labels, and skipped questions+have an explicit localized state. This is a read-only projection: the+model-facing text and stored tool result are unchanged. If structured details+are unavailable or invalid, the transcript keeps its generic result rendering+so imported or malformed history remains inspectable.diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex fe0f3fcaf..b72ed3e7a 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -10664,8 +10664,8 @@ This test plan spec is accepted when:inline code, and a short list. 2) Confirm each card renders the formattingwhile 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.+ question without entering text. 5) Expand the completed tool row and inspect+ its question-and-answer summary, then inspect the next model response.- **Expected**: One question is visible at a time; the small indicators showanswered, current, and skipped states in the composer approval area, at thesame dock position used by Plan and Goal approval. The request has no@@ -10686,7 +10686,10 @@ This test plan spec is accepted when:keeps `question:` for the skipped question. Markdown renders as rich textwithout activating embedded links or loading images. Selecting a formattedoption 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+ question and still completes the tool call. The completed row shows the+ ordered questions and answers, keeps multi-select labels separate, marks+ skipped questions with localized copy, and does not expose the structured+ JSON details. Its model-facing result stays unchanged. A pending ask shows a stablelocalized title and the first question in its toast; generated session-titletext never replaces that title. Background sessions retain the existingnative notification policy. Exactly one soft chime plays for the ask; thediff --git a/docs/zh-CN/spec/03-runtime/17-asktool-questions.md b/docs/zh-CN/spec/03-runtime/17-asktool-questions.mdindex 414019222..61625568d 100644--- a/docs/zh-CN/spec/03-runtime/17-asktool-questions.md+++ b/docs/zh-CN/spec/03-runtime/17-asktool-questions.md@@ -53,3 +53,11 @@ question text:这种格式是确定性的,保留问题顺序,并进行多项选择无需将仅渲染器状态对象暴露给模型。++## 5. 对话记录摘要++对话记录中的 asktool 已完成行会将持久化的+`details.questions` 和 `details.answers` 按顺序呈现为问答摘要。多选答案+仍分别显示,已跳过的问题会显示本地化状态。这只是只读展示,不会更改+提供给模型的文本或已保存的工具结果。如果结构化详情缺失或无效,记录会+保留通用结果展示,以便仍可检查导入或格式异常的历史数据。diff --git a/packages/i18n/src/locales/de/index.ts b/packages/i18n/src/locales/de/index.tsindex ad05fc5d9..33f6cb5d3 100644--- a/packages/i18n/src/locales/de/index.ts+++ b/packages/i18n/src/locales/de/index.ts@@ -1825,6 +1825,9 @@ sklm: {},"askTool": {"title": "Ein paar Fragen",+ "historyTitle": "Fragen und Antworten",+ "answerLabel": "Antwort",+ "skipped": "Übersprungen","progress": "Frage {{current}} von {{total}}","questionNumber": "Frage {{number}}","indicatorLabel": "Fragestatus",diff --git a/packages/i18n/src/locales/en/index.ts b/packages/i18n/src/locales/en/index.tsindex e294843dc..39cadb2ba 100644--- a/packages/i18n/src/locales/en/index.ts+++ b/packages/i18n/src/locales/en/index.ts@@ -1848,6 +1848,9 @@ sklm: {},askTool: {title: "A few questions",+ historyTitle: "Questions and answers",+ answerLabel: "Answer",+ skipped: "Skipped",progress: "Question {{current}} of {{total}}",questionNumber: "Question {{number}}",indicatorLabel: "Question status",diff --git a/packages/i18n/src/locales/es/index.ts b/packages/i18n/src/locales/es/index.tsindex f1962011d..deb1fbac7 100644--- a/packages/i18n/src/locales/es/index.ts+++ b/packages/i18n/src/locales/es/index.ts@@ -1825,6 +1825,9 @@ sklm: {},"askTool": {"title": "Algunas preguntas",+ "historyTitle": "Preguntas y respuestas",+ "answerLabel": "Respuesta",+ "skipped": "Omitida","progress": "Pregunta {{current}} de {{total}}","questionNumber": "Pregunta {{number}}","indicatorLabel": "Estado de la pregunta",diff --git a/packages/i18n/src/locales/fr/index.ts b/packages/i18n/src/locales/fr/index.tsindex b875551f6..65795782d 100644--- a/packages/i18n/src/locales/fr/index.ts+++ b/packages/i18n/src/locales/fr/index.ts@@ -1825,6 +1825,9 @@ sklm: {},"askTool": {"title": "Quelques questions",+ "historyTitle": "Questions et réponses",+ "answerLabel": "Réponse",+ "skipped": "Ignorée","progress": "Question {{current}} sur {{total}}","questionNumber": "Question {{number}}","indicatorLabel": "Statut de la question",diff --git a/packages/i18n/src/locales/ko/index.ts b/packages/i18n/src/locales/ko/index.tsindex dbeacbd6c..68bd5097d 100644--- a/packages/i18n/src/locales/ko/index.ts+++ b/packages/i18n/src/locales/ko/index.ts@@ -1841,6 +1841,9 @@ sklm: {},askTool: {title: "몇 가지 질문",+ historyTitle: "질문과 답변",+ answerLabel: "답변",+ skipped: "건너뜀",progress: "질문 {{current}} / {{total}}",questionNumber: "질문 {{number}}",indicatorLabel: "질문 상태",diff --git a/packages/i18n/src/locales/pt-BR/index.ts b/packages/i18n/src/locales/pt-BR/index.tsindex 24c4cc287..4c0b546d4 100644--- a/packages/i18n/src/locales/pt-BR/index.ts+++ b/packages/i18n/src/locales/pt-BR/index.ts@@ -1788,6 +1788,9 @@ export const ptBR = {},askTool: {title: "Algumas perguntas",+ historyTitle: "Perguntas e respostas",+ answerLabel: "Resposta",+ skipped: "Ignorada",progress: "Pergunta {{current}} de {{total}}",questionNumber: "Pergunta {{number}}",indicatorLabel: "Status da pergunta",diff --git a/packages/i18n/src/locales/tr/index.ts b/packages/i18n/src/locales/tr/index.tsindex e9a9d9e1c..b3de05672 100644--- a/packages/i18n/src/locales/tr/index.ts+++ b/packages/i18n/src/locales/tr/index.ts@@ -1831,6 +1831,9 @@ sklm: {},askTool: {title: "Birkaç soru",+ historyTitle: "Sorular ve yanıtlar",+ answerLabel: "Yanıt",+ skipped: "Atlandı",progress: "Soru {{current}} / {{total}}",questionNumber: "Soru {{number}}",indicatorLabel: "Soru durumu",diff --git a/packages/i18n/src/locales/zh-CN/index.ts b/packages/i18n/src/locales/zh-CN/index.tsindex fae402657..0ae12da8f 100644--- a/packages/i18n/src/locales/zh-CN/index.ts+++ b/packages/i18n/src/locales/zh-CN/index.ts@@ -1813,6 +1813,9 @@ sklm: {},askTool: {title: "需要回答几个问题",+ historyTitle: "问答摘要",+ answerLabel: "回答",+ skipped: "已跳过",progress: "第 {{current}} / {{total}} 题",questionNumber: "问题 {{number}}",indicatorLabel: "问题状态",diff --git a/packages/i18n/src/locales/zh-TW/index.ts b/packages/i18n/src/locales/zh-TW/index.tsindex 490cf9ce6..06741f1ad 100644--- a/packages/i18n/src/locales/zh-TW/index.ts+++ b/packages/i18n/src/locales/zh-TW/index.ts@@ -1813,6 +1813,9 @@ sklm: {},askTool: {title: "需要回答幾個問題",+ historyTitle: "問答摘要",+ answerLabel: "回答",+ skipped: "已略過",progress: "第 {{current}} / {{total}} 題",questionNumber: "問題 {{number}}",indicatorLabel: "問題狀態",