From 9cca1d2af0c0f17022306d9e191849ffb62b923c Mon Sep 17 00:00:00 2001 From: Will Chen Date: Mon, 22 Sep 2025 15:50:18 -0700 Subject: [PATCH] Fix MCP & title bar (#1348) ## Summary by cubic Fixes MCP handoff by detecting an edit-code tool call and stopping generation. Simplifies the title bar credit tooltip; also blocks dyad-* tags in the system prompt and updates tests. - **Bug Fixes** - Stop generation on edit-code via hasToolCall; add a no-op edit-code tool to signal handoff. - Combine tool-call stop with existing step limit for reliability. - Forbid tags in the system prompt to prevent misuse. - Remove credit usage/reset details from the title bar tooltip; keep the delay note. - Update e2e snapshot to reflect the new prompt rule. --- .../mcp.spec.ts_mcp---call-calculator-1.txt | 1 + src/app/TitleBar.tsx | 8 -------- src/ipc/handlers/chat_stream_handlers.ts | 14 ++++++++++++-- src/prompts/system_prompt.ts | 1 + 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/e2e-tests/snapshots/mcp.spec.ts_mcp---call-calculator-1.txt b/e2e-tests/snapshots/mcp.spec.ts_mcp---call-calculator-1.txt index 24f510a..eeedb50 100644 --- a/e2e-tests/snapshots/mcp.spec.ts_mcp---call-calculator-1.txt +++ b/e2e-tests/snapshots/mcp.spec.ts_mcp---call-calculator-1.txt @@ -41,6 +41,7 @@ This applies to simple apps like: - **Never write HTML, CSS, JavaScript, TypeScript, or any programming code** - **Do not create component examples or code snippets** - **Do not provide implementation details or syntax** +- **Do not use , , OR ANY OTHER tags** - Your job ends with information gathering and requirement analysis - All actual development happens in the next phase diff --git a/src/app/TitleBar.tsx b/src/app/TitleBar.tsx index 2c8988e..e91d4cb 100644 --- a/src/app/TitleBar.tsx +++ b/src/app/TitleBar.tsx @@ -235,14 +235,6 @@ export function AICreditStatus({ userBudget }: { userBudget: UserBudgetInfo }) {
-

- You have used {Math.round(userBudget.usedCredits)} credits out of{" "} - {userBudget.totalCredits}. -

-

- Your budget resets on{" "} - {userBudget.budgetResetDate.toLocaleDateString()} -

Note: there is a slight delay in updating the credit status.

diff --git a/src/ipc/handlers/chat_stream_handlers.ts b/src/ipc/handlers/chat_stream_handlers.ts index 5a37cd1..c83d22e 100644 --- a/src/ipc/handlers/chat_stream_handlers.ts +++ b/src/ipc/handlers/chat_stream_handlers.ts @@ -8,6 +8,7 @@ import { ToolSet, TextStreamPart, stepCountIs, + hasToolCall, } from "ai"; import { db } from "../../db"; @@ -69,6 +70,7 @@ import { prompts as promptsTable } from "../../db/schema"; import { inArray } from "drizzle-orm"; import { replacePromptReference } from "../utils/replacePromptReference"; import { mcpManager } from "../utils/mcp_manager"; +import z from "zod"; type AsyncIterableStream = AsyncIterable & ReadableStream; @@ -766,7 +768,7 @@ This conversation includes one or more image attachments. When the user uploads temperature: await getTemperature(settings.selectedModel), maxRetries: 2, model: modelClient.model, - stopWhen: stepCountIs(3), + stopWhen: [stepCountIs(3), hasToolCall("edit-code")], providerOptions, system: systemPromptOverride, tools, @@ -836,7 +838,15 @@ This conversation includes one or more image attachments. When the user uploads const { fullStream } = await simpleStreamText({ chatMessages: limitedHistoryChatMessages, modelClient, - tools, + tools: { + ...tools, + "generate-code": { + description: + "ALWAYS use this tool whenever generating or editing code for the codebase.", + inputSchema: z.object({}), + execute: async () => "", + }, + }, systemPromptOverride: constructSystemPrompt({ aiRules: await readAiRules(getDyadAppPath(updatedChat.app.path)), chatMode: "agent", diff --git a/src/prompts/system_prompt.ts b/src/prompts/system_prompt.ts index ddf9b8f..e6d673a 100644 --- a/src/prompts/system_prompt.ts +++ b/src/prompts/system_prompt.ts @@ -491,6 +491,7 @@ This applies to simple apps like: - **Never write HTML, CSS, JavaScript, TypeScript, or any programming code** - **Do not create component examples or code snippets** - **Do not provide implementation details or syntax** +- **Do not use , , OR ANY OTHER tags** - Your job ends with information gathering and requirement analysis - All actual development happens in the next phase