Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(gui): strip citation control markup from ACP assistant text

Rach Pradhan9683bca928ac
diff --git a/apps/native/components/primitives/Markdown.tsx b/apps/native/components/primitives/Markdown.tsx
index 6bb7b65d..21524d06 100644
--- a/apps/native/components/primitives/Markdown.tsx
+++ b/apps/native/components/primitives/Markdown.tsx
@@ -4,6 +4,7 @@ import { useMemo, type JSX, type ReactNode } from "react";
import { Streamdown, type Components, type ControlsConfig, type ExtraProps } from "streamdown";
import { code } from "@/lib/code-highlighter";
import StreamingCode from "./StreamingCode";
+import { stripCiteMarkup } from "@/lib/cite-markup";
/* ─────────────────────────────────────────────────────────
* MARKDOWN
@@ -107,7 +108,7 @@ function inlineCode(onOpen?: (path: string) => void) {
<code
{...rest}
onClick={pathish ? () => onOpen(target) : undefined}
- title={pathish ? `Open ${text} in the files pane` : undefined}
+ title={pathish ? `Open ${stripCiteMarkup(text)} in the files pane` : undefined}
className={`rounded-[4px] bg-inset px-1 py-px font-mono text-[0.92em] text-ink shadow-hairline ${
pathish ? "cursor-pointer underline decoration-line underline-offset-2 transition-colors hover:bg-hover hover:decoration-ink" : ""
}`}
@@ -153,7 +154,7 @@ export default function Markdown({
tableMaxHeight={0}
className="space-y-3"
>
- {text}
+ {stripCiteMarkup(text)}
</Streamdown>
</div>
);
diff --git a/apps/native/lib/acp.test.ts b/apps/native/lib/acp.test.ts
index fae4c058..98dfcfca 100644
--- a/apps/native/lib/acp.test.ts
+++ b/apps/native/lib/acp.test.ts
@@ -36,6 +36,14 @@ describe("applyAcpUpdate", () => {
assert.equal(turn.status, "streaming");
});
+ it("strips citation markup from assistant text (#805)", () => {
+ const turn = applyAcpUpdate(emptyTurn(), {
+ sessionUpdate: "agent_message_chunk",
+ content: { type: "text", text: "Seeciteturn0view0 this." },
+ });
+ assert.equal(turn.text, "See this.");
+ });
+
it("pairs tool_call and tool_call_update onto one chip", () => {
let turn = emptyTurn();
turn = applyAcpUpdate(turn, {
diff --git a/apps/native/lib/acp.ts b/apps/native/lib/acp.ts
index 7794bf9f..62c12263 100644
--- a/apps/native/lib/acp.ts
+++ b/apps/native/lib/acp.ts
@@ -1,4 +1,5 @@
import { boundToolDetail } from "./tool-detail";
+import { stripCiteMarkup } from "./cite-markup";
/** ACP v1 session/update shapes the native harness renders. */
export type AcpContent = { type: "text"; text: string };
@@ -263,7 +264,7 @@ export function applyAcpUpdate(turn: AssistantTurn, update: AcpUpdate): Assistan
switch (update.sessionUpdate) {
case "gui_turn_end": return { ...turn, stopReason: typeof update.stopReason === "string" ? update.stopReason : "end_turn" };
case "agent_thought_chunk": {
- const text = (update as { content?: AcpContent }).content?.text ?? "";
+ const text = stripCiteMarkup((update as { content?: AcpContent }).content?.text ?? "");
return {
...turn,
reasoning: `${turn.reasoning}${text}`,
@@ -271,7 +272,7 @@ export function applyAcpUpdate(turn: AssistantTurn, update: AcpUpdate): Assistan
};
}
case "agent_message_chunk": {
- const text = (update as { content?: AcpContent }).content?.text ?? "";
+ const text = stripCiteMarkup((update as { content?: AcpContent }).content?.text ?? "");
const needsBreak = turn.pendingBreak && turn.text.length > 0 && !/\s$/.test(turn.text) && !/^\s/.test(text);
return {
...turn,
diff --git a/apps/native/lib/cite-markup.test.ts b/apps/native/lib/cite-markup.test.ts
new file mode 100644
index 00000000..21f78791
--- /dev/null
+++ b/apps/native/lib/cite-markup.test.ts
@@ -0,0 +1,18 @@
+import { describe, it } from "node:test";
+import assert from "node:assert/strict";
+import { stripCiteMarkup } from "./cite-markup.ts";
+
+describe("stripCiteMarkup", () => {
+ it("drops provider citation annotations (#805)", () => {
+ const raw = "See the docs\uE200cite\uE202turn0view0\uE201 for details.";
+ assert.equal(stripCiteMarkup(raw), "See the docs for details.");
+ });
+
+ it("leaves clean text alone", () => {
+ assert.equal(stripCiteMarkup("no citations here"), "no citations here");
+ });
+
+ it("drops unpaired separator marks", () => {
+ assert.equal(stripCiteMarkup("a\uE202b\uE201c"), "abc");
+ });
+});
diff --git a/apps/native/lib/cite-markup.ts b/apps/native/lib/cite-markup.ts
new file mode 100644
index 00000000..68e959b2
--- /dev/null
+++ b/apps/native/lib/cite-markup.ts
@@ -0,0 +1,28 @@
+/** Provider citation control annotations (U+E200…U+E202). Same contract as
+ * `src/cite_markup.zig` — hosted web search emits these; the GUI cannot
+ * render them, so they must leave copy-ready assistant text (#805, #811). */
+
+const START = "\uE200";
+const END = "\uE201";
+const SEP = "\uE202";
+
+export function stripCiteMarkup(text: string): string {
+ if (!text.includes(START) && !text.includes(END) && !text.includes(SEP)) return text;
+ let out = "";
+ let i = 0;
+ while (i < text.length) {
+ const ch = text[i];
+ if (ch === START) {
+ const close = text.indexOf(END, i + 1);
+ i = close === -1 ? text.length : close + 1;
+ continue;
+ }
+ if (ch === END || ch === SEP) {
+ i += 1;
+ continue;
+ }
+ out += ch;
+ i += 1;
+ }
+ return out;
+}
diff --git a/apps/native/package.json b/apps/native/package.json
index 93bda372..ee27cdd8 100644
--- a/apps/native/package.json
+++ b/apps/native/package.json
@@ -10,7 +10,7 @@
"start": "NEXT_TELEMETRY_DISABLED=1 next start --port 3000",
"mock-serve": "node scripts/mock-serve.mjs",
"lint": "next lint",
- "test": "node --experimental-strip-types --test lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/session-store.test.ts lib/follow-scroll.test.ts lib/prompt-queue.test.ts lib/prompt-history.test.ts lib/attachments.test.ts lib/workspaces.test.ts lib/fuzzy.test.ts lib/folder-picker.test.ts lib/browser/annotations.test.ts lib/browser/url.test.ts",
+ "test": "node --experimental-strip-types --test lib/cite-markup.test.ts lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/session-store.test.ts lib/follow-scroll.test.ts lib/prompt-queue.test.ts lib/prompt-history.test.ts lib/attachments.test.ts lib/workspaces.test.ts lib/fuzzy.test.ts lib/folder-picker.test.ts lib/browser/annotations.test.ts lib/browser/url.test.ts",
"electron:build": "bash electron/build.sh",
"test:electron": "bun test electron/policy.test.cjs",
"test:desktop": "bun test lib ./electron/*.test.cjs",