From 14350998059f963e151a8b67bb04254b210df4fd Mon Sep 17 00:00:00 2001 From: "Nick T." <73005126+tiliakoos@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:41:33 -0500 Subject: [PATCH 1/2] fix(mobile): untitled subagent rows no longer end in a broken character A subagent with no title is named from its prompt, cut at 77 UTF-16 units. An emoji on the cut left half a surrogate pair before the "...". Co-authored-by: spoukyii <61633921+spoukyii@users.noreply.github.com> --- .../threads/threadAgentsPresentation.test.ts | 5 + .../threads/threadAgentsPresentation.ts | 11 +- ...ubagent-stop-keeps-whole-characters.e2e.ts | 115 ++++++++++++++++++ 3 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 scripts/scenarios/untitled-subagent-stop-keeps-whole-characters.e2e.ts diff --git a/apps/mobile/src/features/threads/threadAgentsPresentation.test.ts b/apps/mobile/src/features/threads/threadAgentsPresentation.test.ts index 171d73a14859..e0771be61c5e 100644 --- a/apps/mobile/src/features/threads/threadAgentsPresentation.test.ts +++ b/apps/mobile/src/features/threads/threadAgentsPresentation.test.ts @@ -64,10 +64,15 @@ describe("resolveSubagentRowPresentation", () => { it("falls back to a trimmed prompt when the agent has no title", () => { const long = resolveSubagentRowPresentation({ ...base, prompt: "x".repeat(200) }); + const emoji = resolveSubagentRowPresentation({ + ...base, + prompt: `${"x".repeat(76)}😀 and more`, + }); const titled = resolveSubagentRowPresentation({ ...base, title: "Subagent: /root/my_worker" }); expect(long.title).toHaveLength(80); expect(long.title.endsWith("...")).toBe(true); + expect(emoji.title).toBe(`${"x".repeat(76)}...`); expect(titled.title).toBe("My Worker"); }); diff --git a/apps/mobile/src/features/threads/threadAgentsPresentation.ts b/apps/mobile/src/features/threads/threadAgentsPresentation.ts index 270cc1f3d7fb..6d34e2c956a8 100644 --- a/apps/mobile/src/features/threads/threadAgentsPresentation.ts +++ b/apps/mobile/src/features/threads/threadAgentsPresentation.ts @@ -82,9 +82,14 @@ function rowTitle( if (title) return formatSubagentDisplayTitle(title); const prompt = subagent.prompt.trim(); if (prompt.length === 0) return resolve(msg("Subagent")); - return prompt.length > PROMPT_TITLE_LIMIT - ? `${prompt.slice(0, PROMPT_TITLE_LIMIT - 3)}...` - : prompt; + if (prompt.length <= PROMPT_TITLE_LIMIT) return prompt; + let end = PROMPT_TITLE_LIMIT - 3; + const previous = prompt.charCodeAt(end - 1); + const next = prompt.charCodeAt(end); + if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) { + end -= 1; + } + return `${prompt.slice(0, end)}...`; } function rowTone(status: OrchestrationV2Subagent["status"]): SubagentRowTone { diff --git a/scripts/scenarios/untitled-subagent-stop-keeps-whole-characters.e2e.ts b/scripts/scenarios/untitled-subagent-stop-keeps-whole-characters.e2e.ts new file mode 100644 index 000000000000..2c6077077916 --- /dev/null +++ b/scripts/scenarios/untitled-subagent-stop-keeps-whole-characters.e2e.ts @@ -0,0 +1,115 @@ +// @effect-diagnostics nodeBuiltinImport:off -- The scenario stages a local ACP executable. +import * as NodeFSP from "node:fs/promises"; +import * as NodePath from "node:path"; + +import { expect } from "e2e"; + +import { MOBILE, MOBILE_T3_HOME } from "../e2e.config.ts"; +import { environmentId, makeState, runPromise } from "./t3.ts"; +import { IOS, test } from "./t3-mobile.ts"; + +const AGENT = "untitled-delegate-agent"; +// The emoji's two UTF-16 units straddle unit 77, where a prompt-derived title is cut. +const TASK = `${"x".repeat(76)}😀 then report back`; +// The parent delegates through T3's real delegate_task tool, with no title. Neither turn ends, +// so the subagent stays running and offers its Stop button. +const ACP = ` +import { spawn } from "node:child_process"; +import { createInterface } from "node:readline"; + +const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n"); +let sessions = 0; +let bridge; +for await (const line of createInterface({ input: process.stdin })) { + const { id, method, params } = JSON.parse(line); + if (id === undefined) continue; + if (method === "initialize") { + send({ id, result: { protocolVersion: 1, agentInfo: { name: "${AGENT}", version: "1.0.0" }, agentCapabilities: {}, authMethods: [] } }); + } else if (method === "session/new") { + bridge = params.mcpServers.find((server) => server.name === "t3-code"); + send({ id, result: { sessionId: "session-" + ++sessions } }); + } else if (method === "session/prompt") { + const text = params.prompt.map((part) => part.text ?? "").join(""); + // T3 puts its runtime notes ahead of the first message; the child's prompt never matches. + if (!text.includes("Delegate the task.")) continue; + const input = { task: ${JSON.stringify(TASK)}, target: { providerInstanceId: "${AGENT}", model: "default" } }; + const args = bridge.args.map((arg) => (arg === "acp-mcp-bridge" ? "acp-mcp-call" : arg)); + const env = { ...process.env, ...Object.fromEntries(bridge.env.map((entry) => [entry.name, entry.value])) }; + spawn(bridge.command, [...args, "delegate_task", JSON.stringify(input)], { env, stdio: ["ignore", "ignore", "inherit"] }); + } else { + send({ id, error: { code: -32601, message: "Method not found" } }); + } +} +`; + +test( + "An untitled subagent's Stop button names it without a broken character", + IOS, + async ({ t3, app, screen, device }) => { + const project = await t3.project("demo"); + const script = NodePath.join(project, "untitled-delegate-acp.mjs"); + await NodeFSP.writeFile(script, ACP); + const settingsPath = NodePath.join(MOBILE_T3_HOME, "userdata/settings.json"); + const originalSettings = await NodeFSP.readFile(settingsPath, "utf8"); + const settings = JSON.parse(originalSettings); + settings.providerInstances[AGENT] = { + driver: "acpRegistry", + displayName: "Untitled Delegate Agent", + enabled: true, + config: { source: "local", commandPath: process.execPath, commandArgs: [script] }, + }; + try { + await NodeFSP.writeFile(settingsPath, JSON.stringify(settings)); + const { cli } = makeState(MOBILE_T3_HOME, { T3CODE_PORT: String(MOBILE.serverPort) }); + // The watcher reloads settings asynchronously. Retry only before a thread was created. + let threadId: string | undefined; + for (let attempt = 0; attempt < 8 && threadId === undefined; attempt++) { + const started = await runPromise( + cli( + [ + "thread", + "start", + project, + "Delegate the task.", + "--title", + "Untitled subagent", + "--provider", + AGENT, + "--model", + "default", + "--json", + ], + [0, 1], + ), + ); + if (!started.stdout.includes("threadId")) continue; + threadId = (JSON.parse(started.stdout) as { threadId: string }).threadId; + } + if (threadId === undefined) throw new Error("Could not start the delegating turn."); + + await t3.open(); + // A working thread is listed behind this button, not as a row. + await screen.getByRole("button", "1 working thread").waitFor({ timeout: 120_000 }); + const environment = await runPromise( + environmentId(`http://${MOBILE.host}:${MOBILE.serverPort}`), + ); + await device.openLink(`t3code-dev://threads/${environment}/${threadId}`, { + app: "com.t3tools.t3code.dev", + }); + await device.alert("accept").catch(() => {}); + + await screen.getByRole("button", /^Open agents/).tap({ timeout: 60_000 }); + const stop = screen.getByRole("button", /^Stop agent x{76}/); + await stop.waitFor({ timeout: 30_000 }); + try { + await expect(stop).toHaveAccessibleName(`Stop agent ${"x".repeat(76)}...`); + } finally { + await stop.tap(); + await app.screenshot("stop-dialog"); + await device.alert("dismiss").catch(() => {}); + } + } finally { + await NodeFSP.writeFile(settingsPath, originalSettings); + } + }, +); From 066439e3afee456f09d01d1263e28f9c225f4dc5 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 19:11:47 +0000 Subject: [PATCH 2/2] refactor(mobile): reuse client-runtime's prompt title truncation Mobile's untitled subagent rows now call the same surrogate-safe promptTitle the shared runtime uses, instead of a second copy of it. The iOS scenario is dropped: the unit assertion already fails on main for this bug, and the scenario drove a hand-written ACP agent. Co-Authored-By: Claude Opus 5.5 --- .../threads/threadAgentsPresentation.ts | 12 +- .../src/state/subagentRuntime.ts | 2 +- ...ubagent-stop-keeps-whole-characters.e2e.ts | 115 ------------------ 3 files changed, 3 insertions(+), 126 deletions(-) delete mode 100644 scripts/scenarios/untitled-subagent-stop-keeps-whole-characters.e2e.ts diff --git a/apps/mobile/src/features/threads/threadAgentsPresentation.ts b/apps/mobile/src/features/threads/threadAgentsPresentation.ts index 6d34e2c956a8..a5af5b0e6c5e 100644 --- a/apps/mobile/src/features/threads/threadAgentsPresentation.ts +++ b/apps/mobile/src/features/threads/threadAgentsPresentation.ts @@ -7,6 +7,7 @@ import { } from "@t3tools/client-runtime/state/subagent-display"; import { isActiveSubagentStatus, + promptTitle, type RuntimeSubagent, type SubagentWorkflowGroup, } from "@t3tools/client-runtime/state/subagentRuntime"; @@ -22,8 +23,6 @@ import { msg } from "gt-react-native"; import { m, type MessageResolver } from "../../i18n/messages"; -const PROMPT_TITLE_LIMIT = 80; - export type SubagentRowTone = "working" | "completed" | "failed" | "stopped"; export interface SubagentRowPresentation { @@ -82,14 +81,7 @@ function rowTitle( if (title) return formatSubagentDisplayTitle(title); const prompt = subagent.prompt.trim(); if (prompt.length === 0) return resolve(msg("Subagent")); - if (prompt.length <= PROMPT_TITLE_LIMIT) return prompt; - let end = PROMPT_TITLE_LIMIT - 3; - const previous = prompt.charCodeAt(end - 1); - const next = prompt.charCodeAt(end); - if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) { - end -= 1; - } - return `${prompt.slice(0, end)}...`; + return promptTitle(prompt); } function rowTone(status: OrchestrationV2Subagent["status"]): SubagentRowTone { diff --git a/packages/client-runtime/src/state/subagentRuntime.ts b/packages/client-runtime/src/state/subagentRuntime.ts index 44c1ea98064b..b6efb9cac132 100644 --- a/packages/client-runtime/src/state/subagentRuntime.ts +++ b/packages/client-runtime/src/state/subagentRuntime.ts @@ -186,7 +186,7 @@ function workflowMembersToRuntime( }); } -function promptTitle(prompt: string): string { +export function promptTitle(prompt: string): string { if (prompt.length <= 80) return prompt; let end = 77; const previous = prompt.charCodeAt(end - 1); diff --git a/scripts/scenarios/untitled-subagent-stop-keeps-whole-characters.e2e.ts b/scripts/scenarios/untitled-subagent-stop-keeps-whole-characters.e2e.ts deleted file mode 100644 index 2c6077077916..000000000000 --- a/scripts/scenarios/untitled-subagent-stop-keeps-whole-characters.e2e.ts +++ /dev/null @@ -1,115 +0,0 @@ -// @effect-diagnostics nodeBuiltinImport:off -- The scenario stages a local ACP executable. -import * as NodeFSP from "node:fs/promises"; -import * as NodePath from "node:path"; - -import { expect } from "e2e"; - -import { MOBILE, MOBILE_T3_HOME } from "../e2e.config.ts"; -import { environmentId, makeState, runPromise } from "./t3.ts"; -import { IOS, test } from "./t3-mobile.ts"; - -const AGENT = "untitled-delegate-agent"; -// The emoji's two UTF-16 units straddle unit 77, where a prompt-derived title is cut. -const TASK = `${"x".repeat(76)}😀 then report back`; -// The parent delegates through T3's real delegate_task tool, with no title. Neither turn ends, -// so the subagent stays running and offers its Stop button. -const ACP = ` -import { spawn } from "node:child_process"; -import { createInterface } from "node:readline"; - -const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n"); -let sessions = 0; -let bridge; -for await (const line of createInterface({ input: process.stdin })) { - const { id, method, params } = JSON.parse(line); - if (id === undefined) continue; - if (method === "initialize") { - send({ id, result: { protocolVersion: 1, agentInfo: { name: "${AGENT}", version: "1.0.0" }, agentCapabilities: {}, authMethods: [] } }); - } else if (method === "session/new") { - bridge = params.mcpServers.find((server) => server.name === "t3-code"); - send({ id, result: { sessionId: "session-" + ++sessions } }); - } else if (method === "session/prompt") { - const text = params.prompt.map((part) => part.text ?? "").join(""); - // T3 puts its runtime notes ahead of the first message; the child's prompt never matches. - if (!text.includes("Delegate the task.")) continue; - const input = { task: ${JSON.stringify(TASK)}, target: { providerInstanceId: "${AGENT}", model: "default" } }; - const args = bridge.args.map((arg) => (arg === "acp-mcp-bridge" ? "acp-mcp-call" : arg)); - const env = { ...process.env, ...Object.fromEntries(bridge.env.map((entry) => [entry.name, entry.value])) }; - spawn(bridge.command, [...args, "delegate_task", JSON.stringify(input)], { env, stdio: ["ignore", "ignore", "inherit"] }); - } else { - send({ id, error: { code: -32601, message: "Method not found" } }); - } -} -`; - -test( - "An untitled subagent's Stop button names it without a broken character", - IOS, - async ({ t3, app, screen, device }) => { - const project = await t3.project("demo"); - const script = NodePath.join(project, "untitled-delegate-acp.mjs"); - await NodeFSP.writeFile(script, ACP); - const settingsPath = NodePath.join(MOBILE_T3_HOME, "userdata/settings.json"); - const originalSettings = await NodeFSP.readFile(settingsPath, "utf8"); - const settings = JSON.parse(originalSettings); - settings.providerInstances[AGENT] = { - driver: "acpRegistry", - displayName: "Untitled Delegate Agent", - enabled: true, - config: { source: "local", commandPath: process.execPath, commandArgs: [script] }, - }; - try { - await NodeFSP.writeFile(settingsPath, JSON.stringify(settings)); - const { cli } = makeState(MOBILE_T3_HOME, { T3CODE_PORT: String(MOBILE.serverPort) }); - // The watcher reloads settings asynchronously. Retry only before a thread was created. - let threadId: string | undefined; - for (let attempt = 0; attempt < 8 && threadId === undefined; attempt++) { - const started = await runPromise( - cli( - [ - "thread", - "start", - project, - "Delegate the task.", - "--title", - "Untitled subagent", - "--provider", - AGENT, - "--model", - "default", - "--json", - ], - [0, 1], - ), - ); - if (!started.stdout.includes("threadId")) continue; - threadId = (JSON.parse(started.stdout) as { threadId: string }).threadId; - } - if (threadId === undefined) throw new Error("Could not start the delegating turn."); - - await t3.open(); - // A working thread is listed behind this button, not as a row. - await screen.getByRole("button", "1 working thread").waitFor({ timeout: 120_000 }); - const environment = await runPromise( - environmentId(`http://${MOBILE.host}:${MOBILE.serverPort}`), - ); - await device.openLink(`t3code-dev://threads/${environment}/${threadId}`, { - app: "com.t3tools.t3code.dev", - }); - await device.alert("accept").catch(() => {}); - - await screen.getByRole("button", /^Open agents/).tap({ timeout: 60_000 }); - const stop = screen.getByRole("button", /^Stop agent x{76}/); - await stop.waitFor({ timeout: 30_000 }); - try { - await expect(stop).toHaveAccessibleName(`Stop agent ${"x".repeat(76)}...`); - } finally { - await stop.tap(); - await app.screenshot("stop-dialog"); - await device.alert("dismiss").catch(() => {}); - } - } finally { - await NodeFSP.writeFile(settingsPath, originalSettings); - } - }, -);