Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(chat): present tool receipts clearly and report outcomes naturally

rubenluetke10-beepa0b19316843a
diff --git a/jarvis/agent_chat/runner_api.py b/jarvis/agent_chat/runner_api.py
index 64aa5504fc..f587eadfc1 100644
--- a/jarvis/agent_chat/runner_api.py
+++ b/jarvis/agent_chat/runner_api.py
@@ -47,6 +47,7 @@ from jarvis.agent_chat.tools import (
summarize_call,
)
from jarvis.core.protocols import BrainDelta, BrainMessage, BrainRequest
+from jarvis.core.response_style import CONVERSATIONAL_RESPONSE_STYLE
log = logging.getLogger(__name__)
@@ -124,7 +125,9 @@ def system_prompt(*, cwd: Path, assistant_name: str, plan: bool = False) -> str:
"help, fenced code blocks with a language tag, file paths in backticks.\n"
"- Never invent file contents, command output or results you did not observe.\n"
"- When the task is done, stop calling tools and give a short summary of what "
- "changed and anything the person should do next." + plan_note
+ "changed and anything the person should do next.\n\n"
+ + CONVERSATIONAL_RESPONSE_STYLE
+ + plan_note
)
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index a401b802b8..fac268bdcf 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -76,6 +76,7 @@ from jarvis.core.protocols import (
)
from jarvis.brain.turn_override import TurnOverride
from jarvis.core.redact import safe_preview
+from jarvis.core.response_style import CONVERSATIONAL_RESPONSE_STYLE
from jarvis.core.turn_language import (
DEFAULT_LOCALE,
detect_text_language,
@@ -2378,6 +2379,9 @@ _WRITTEN_CHAT_STYLE = (
"summary plus action plan plus emoji question."
)
+# Keep the API chat and the main brain's written delivery equally conversational.
+_WRITTEN_CHAT_STYLE += "\n" + CONVERSATIONAL_RESPONSE_STYLE
+
def _is_written_turn() -> bool:
"""True when the current turn is a typed (written) turn, not voice.
diff --git a/jarvis/core/response_style.py b/jarvis/core/response_style.py
new file mode 100644
index 0000000000..6260583d04
--- /dev/null
+++ b/jarvis/core/response_style.py
@@ -0,0 +1,21 @@
+"""Default conversational reporting for human-facing chat replies."""
+
+CONVERSATIONAL_RESPONSE_STYLE = (
+ "Conversational reporting: sound like a capable, approachable colleague. "
+ "Lead with the answer or observed outcome, then explain what it means for the person. "
+ "For routine work, one short paragraph is usually enough; add detail when requested "
+ "or needed to understand a decision. Use natural, complete sentences, not slogans, "
+ "telegraphic status fragments or a formal report template. "
+ "Interpret tool results in plain language. Do not paste raw JSON envelopes, token "
+ "counts, internal provider names or empty result fields into the answer unless the "
+ "person explicitly asks for raw data or debugging details. Preserve requested code, "
+ "data and deliverables. Put a useful result link next to the outcome. "
+ "Distinguish intended, attempted, pending and verified work: a successful tool call "
+ "does not by itself prove the user's goal was achieved. State partial success or "
+ "failure plainly, with the relevant reason and at most one next action. "
+ "During work, report meaningful new information rather than repeating that you "
+ "are checking. Never promise ongoing monitoring without a confirmed active schedule. "
+ "Ask only for information that changes the next action; do not end every reply with "
+ "a question or repeat the user's request. Follow explicit user preferences for length "
+ "and tone, and the turn's already-selected output language."
+)
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/ChatMarkdown.tsx b/jarvis/ui/web/frontend/src/components/agentchat/ChatMarkdown.tsx
index af7318afe6..fedadc5e3b 100644
--- a/jarvis/ui/web/frontend/src/components/agentchat/ChatMarkdown.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentchat/ChatMarkdown.tsx
@@ -6,6 +6,7 @@ import { useT } from "@/i18n";
import { cn } from "@/lib/utils";
import { openExternalUrl } from "@/lib/openExternal";
import { readFence, visualFenceLanguage } from "@/lib/visualFence";
+import { parseToolResult, ToolResultCard } from "./ToolResultCard";
import * as Dialog from "@radix-ui/react-dialog";
const RenderedFence = lazy(() => import("@/components/outputs/RenderedFence").then(module => ({ default: module.RenderedFence })));
@@ -159,6 +160,10 @@ const MARKDOWN_COMPONENTS: Components = {
pre: ({ children, node: _node, ...props }) => {
const fence = readFence(children);
if (fence) {
+ if (fence.language === "json" || fence.language === "") {
+ const result = parseToolResult(fence.code);
+ if (result) return <ToolResultCard result={result} code={fence.code} />;
+ }
const language = visualFenceLanguage(fence.language, fence.code);
if (language) return <Suspense fallback={<pre>{children}</pre>}><RenderedFence language={language} code={fence.code} /></Suspense>;
}
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/ToolResultCard.test.tsx b/jarvis/ui/web/frontend/src/components/agentchat/ToolResultCard.test.tsx
new file mode 100644
index 0000000000..ffcd629dec
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentchat/ToolResultCard.test.tsx
@@ -0,0 +1,48 @@
+import { cleanup, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it } from "vitest";
+import { ChatMarkdown } from "./ChatMarkdown";
+import { parseToolResult } from "./ToolResultCard";
+
+afterEach(cleanup);
+
+const receipt = { ok: true, final_result: "Found Example Domain", urls: ["https://example.com/", "https://example.com/"], errors: [], steps: 2, seconds: 21.92, usage: { input_tokens: 0 } };
+const markdown = (value: unknown) => "```json\n" + JSON.stringify(value) + "\n```";
+
+describe("human-readable tool receipts", () => {
+ it("shows the outcome and a single link, keeping every raw field behind a disclosure", () => {
+ render(<ChatMarkdown text={markdown(receipt)} />);
+ const card = screen.getByTestId("tool-result-card");
+ expect(screen.getByText("Found Example Domain")).toBeTruthy();
+ expect(screen.getAllByRole("link")).toHaveLength(1);
+ expect(card.querySelector("details")?.open).toBe(false);
+ expect(card.querySelector("pre")?.textContent).toBe(JSON.stringify(receipt));
+ });
+
+ it("shows failures even when the outer receipt claims success", () => {
+ render(<ChatMarkdown text={markdown({ ...receipt, errors: ["Second page failed"], error: "Login required" })} />);
+ expect(screen.getByText("Output · Failed")).toBeTruthy();
+ expect(screen.getByText("Second page failed")).toBeTruthy();
+ expect(screen.getByText("Login required")).toBeTruthy();
+ });
+
+ it("does not turn receipt text into HTML or unsafe links", () => {
+ const { container } = render(<ChatMarkdown text={markdown({ ...receipt, final_result: '<img src=x onerror="alert(1)">', urls: ["javascript:alert(1)", "file:///private", "https://user:[email protected]"] })} />);
+ expect(container.querySelector("img")).toBeNull();
+ expect(screen.queryByRole("link")).toBeNull();
+ expect(screen.getByText('<img src=x onerror="alert(1)">')).toBeTruthy();
+ });
+
+ it("retains incomplete streamed output until a complete receipt arrives", () => {
+ const text = markdown(receipt);
+ const { container, rerender } = render(<ChatMarkdown text={text.slice(0, 40)} />);
+ expect(screen.queryByTestId("tool-result-card")).toBeNull();
+ expect(container.querySelector("pre")).toBeTruthy();
+ rerender(<ChatMarkdown text={text} />);
+ expect(screen.getByTestId("tool-result-card")).toBeTruthy();
+ });
+
+ it.each(["null", "[]", '{"ok":true}', '{"ok":true,"final_result":"x","urls":[],"errors":[{}]}'])
+ ("leaves unrelated or unsupported JSON unchanged: %s", code => {
+ expect(parseToolResult(code)).toBeNull();
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/agentchat/ToolResultCard.tsx b/jarvis/ui/web/frontend/src/components/agentchat/ToolResultCard.tsx
new file mode 100644
index 0000000000..0e356a5387
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/agentchat/ToolResultCard.tsx
@@ -0,0 +1,48 @@
+import { useT } from "@/i18n";
+import { openExternalUrl } from "@/lib/openExternal";
+
+interface ToolResult {
+ ok: boolean;
+ final_result: string;
+ urls: string[];
+ errors: string[];
+}
+
+/** Only recognize tool receipts, not arbitrary JSON examples or user data. */
+export function parseToolResult(code: string): ToolResult | null {
+ if (code.length > 100_000) return null;
+ let value: unknown;
+ try { value = JSON.parse(code); } catch { return null; } // Incomplete streamed JSON remains code.
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
+ const result = value as Record<string, unknown>;
+ if (typeof result.ok !== "boolean" || typeof result.final_result !== "string"
+ || !Array.isArray(result.urls) || !Array.isArray(result.errors)) return null;
+ if (!result.urls.every(url => typeof url === "string")
+ || !result.errors.every(error => typeof error === "string")) return null;
+ const errors = [...result.errors] as string[];
+ if (typeof result.error === "string" && result.error.trim()) errors.push(result.error);
+ return { ok: result.ok, final_result: result.final_result, urls: result.urls as string[], errors: [...new Set(errors)] };
+}
+
+function safeResultUrl(raw: string): boolean {
+ try {
+ const url = new URL(raw);
+ return ["http:", "https:"].includes(url.protocol) && !url.username && !url.password;
+ } catch { return false; } // Non-URL strings remain available in the raw receipt.
+}
+
+export function ToolResultCard({ result, code }: { result: ToolResult; code: string }) {
+ const t = useT();
+ const failed = !result.ok || result.errors.length > 0;
+ const urls = [...new Set(result.urls)].filter(safeResultUrl);
+ return <section className="not-prose my-3 min-w-0 rounded-lg border border-border bg-muted/30 p-3 text-sm" data-testid="tool-result-card">
+ <p className="mb-2 font-medium text-foreground">{t("work_trace.output")} · {t(failed ? "work_trace.failed" : "work_trace.completed")}</p>
+ {result.final_result.trim() ? <p className="whitespace-pre-wrap text-foreground [overflow-wrap:anywhere]">{result.final_result}</p> : null}
+ {result.errors.length ? <ul className="mt-2 space-y-1 text-destructive">{result.errors.map((error, index) => <li key={index} className="whitespace-pre-wrap [overflow-wrap:anywhere]">{error}</li>)}</ul> : null}
+ {urls.length ? <ul className="mt-2 space-y-1">{urls.map(url => <li key={url}><a href={url} className="text-primary underline [overflow-wrap:anywhere]" onClick={event => { event.preventDefault(); void openExternalUrl(url); }}>{url}</a></li>)}</ul> : null}
+ <details className="mt-3 border-t border-border pt-2">
+ <summary className="cursor-pointer text-xs text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">{t("outputs_view.fence_source")} · JSON</summary>
+ <pre tabIndex={0} className="mt-2 max-h-64 overflow-auto whitespace-pre-wrap font-mono text-xs text-muted-foreground [overflow-wrap:anywhere]">{code}</pre>
+ </details>
+ </section>;
+}
diff --git a/tests/unit/agent_chat/test_response_style.py b/tests/unit/agent_chat/test_response_style.py
new file mode 100644
index 0000000000..abf9d85752
--- /dev/null
+++ b/tests/unit/agent_chat/test_response_style.py
@@ -0,0 +1,28 @@
+"""Human-facing chat runners share the reporting policy; voice keeps spoken rules."""
+
+from pathlib import Path
+
+from jarvis.agent_chat.runner_api import system_prompt
+from jarvis.brain.manager import _WRITTEN_CHAT_STYLE
+from jarvis.brain.persona_loader import load_compact_persona_prompt, load_persona_prompt
+from jarvis.core.response_style import CONVERSATIONAL_RESPONSE_STYLE
+
+
+def test_api_and_main_chat_receive_the_same_reporting_policy(tmp_path: Path) -> None:
+ prompt = system_prompt(cwd=tmp_path, assistant_name="Assistant")
+ assert CONVERSATIONAL_RESPONSE_STYLE in prompt
+ assert CONVERSATIONAL_RESPONSE_STYLE in _WRITTEN_CHAT_STYLE
+
+
+def test_plan_mode_keeps_its_read_only_contract(tmp_path: Path) -> None:
+ prompt = system_prompt(cwd=tmp_path, assistant_name="Assistant", plan=True)
+ assert CONVERSATIONAL_RESPONSE_STYLE in prompt
+ assert "PLAN MODE is on" in prompt
+ assert "you have no tools that change anything" in prompt
+
+
+def test_both_voice_personas_include_reporting_without_losing_spoken_rules() -> None:
+ for prompt in (load_persona_prompt(), load_compact_persona_prompt()):
+ assert "REPORTING RESULTS" in prompt
+ assert "SPOKEN" in prompt
+ assert "spell every number" in prompt