From 078ab943a8fd8ccfa6bffeca35ba268c02b99f61 Mon Sep 17 00:00:00 2001 From: Kacper Date: Tue, 30 Dec 2025 15:44:50 +0100 Subject: [PATCH] fix(server): Add explicit JSON response instructions for Cursor prompts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cursor was writing JSON to files instead of returning it in the response. Added clear instructions to all Cursor prompts: 1. DO NOT write any files 2. Return ONLY raw JSON in the response 3. No explanations, no markdown, just JSON Affected routes: - generate-spec.ts - generate-features-from-spec.ts - validate-issue.ts - generate-suggestions.ts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../routes/app-spec/generate-features-from-spec.ts | 10 +++++++++- apps/server/src/routes/app-spec/generate-spec.ts | 13 ++++++++++--- .../src/routes/github/routes/validate-issue.ts | 8 +++++++- .../src/routes/suggestions/generate-suggestions.ts | 12 +++++++++--- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/apps/server/src/routes/app-spec/generate-features-from-spec.ts b/apps/server/src/routes/app-spec/generate-features-from-spec.ts index 8aea59ba..2171f2d2 100644 --- a/apps/server/src/routes/app-spec/generate-features-from-spec.ts +++ b/apps/server/src/routes/app-spec/generate-features-from-spec.ts @@ -125,8 +125,16 @@ IMPORTANT: Do not ask for clarification. The specification is provided above. Ge const provider = ProviderFactory.getProviderForModel(model); + // Add explicit instructions for Cursor to return JSON in response + const cursorPrompt = `${prompt} + +CRITICAL INSTRUCTIONS: +1. DO NOT write any files. Return the JSON in your response only. +2. Respond with ONLY a JSON object - no explanations, no markdown, just raw JSON. +3. Your entire response should be valid JSON starting with { and ending with }. No text before or after.`; + for await (const msg of provider.executeQuery({ - prompt, + prompt: cursorPrompt, model, cwd: projectPath, maxTurns: 250, diff --git a/apps/server/src/routes/app-spec/generate-spec.ts b/apps/server/src/routes/app-spec/generate-spec.ts index 98985c1e..64f12836 100644 --- a/apps/server/src/routes/app-spec/generate-spec.ts +++ b/apps/server/src/routes/app-spec/generate-spec.ts @@ -119,11 +119,18 @@ ${getStructuredSpecPromptInstruction()}`; const provider = ProviderFactory.getProviderForModel(model); - // For Cursor, include the JSON schema in the prompt + // For Cursor, include the JSON schema in the prompt with clear instructions + // to return JSON in the response (not write to a file) const cursorPrompt = `${prompt} -IMPORTANT: You must respond with a valid JSON object matching this schema: -${JSON.stringify(specOutputSchema, null, 2)}`; +CRITICAL INSTRUCTIONS: +1. DO NOT write any files. DO NOT create any files like "project_specification.json". +2. After analyzing the project, respond with ONLY a JSON object - no explanations, no markdown, just raw JSON. +3. The JSON must match this exact schema: + +${JSON.stringify(specOutputSchema, null, 2)} + +Your entire response should be valid JSON starting with { and ending with }. No text before or after.`; for await (const msg of provider.executeQuery({ prompt: cursorPrompt, diff --git a/apps/server/src/routes/github/routes/validate-issue.ts b/apps/server/src/routes/github/routes/validate-issue.ts index b51435b8..80e068fb 100644 --- a/apps/server/src/routes/github/routes/validate-issue.ts +++ b/apps/server/src/routes/github/routes/validate-issue.ts @@ -102,9 +102,15 @@ async function runValidation( // For Cursor, include the system prompt and schema in the user prompt const cursorPrompt = `${ISSUE_VALIDATION_SYSTEM_PROMPT} -You MUST respond with a valid JSON object matching this schema: +CRITICAL INSTRUCTIONS: +1. DO NOT write any files. Return the JSON in your response only. +2. Respond with ONLY a JSON object - no explanations, no markdown, just raw JSON. +3. The JSON must match this exact schema: + ${JSON.stringify(issueValidationSchema, null, 2)} +Your entire response should be valid JSON starting with { and ending with }. No text before or after. + ${prompt}`; for await (const msg of provider.executeQuery({ diff --git a/apps/server/src/routes/suggestions/generate-suggestions.ts b/apps/server/src/routes/suggestions/generate-suggestions.ts index fd4c6a50..fefcea61 100644 --- a/apps/server/src/routes/suggestions/generate-suggestions.ts +++ b/apps/server/src/routes/suggestions/generate-suggestions.ts @@ -189,11 +189,17 @@ The response will be automatically formatted as structured JSON.`; const provider = ProviderFactory.getProviderForModel(model); - // For Cursor, include the JSON schema in the prompt + // For Cursor, include the JSON schema in the prompt with clear instructions const cursorPrompt = `${prompt} -IMPORTANT: You must respond with a valid JSON object matching this schema: -${JSON.stringify(suggestionsSchema, null, 2)}`; +CRITICAL INSTRUCTIONS: +1. DO NOT write any files. Return the JSON in your response only. +2. After analyzing the project, respond with ONLY a JSON object - no explanations, no markdown, just raw JSON. +3. The JSON must match this exact schema: + +${JSON.stringify(suggestionsSchema, null, 2)} + +Your entire response should be valid JSON starting with { and ending with }. No text before or after.`; for await (const msg of provider.executeQuery({ prompt: cursorPrompt,