Skip to content

Commit 39fe513

Browse files
committed
feat: improve code block rendering in chat interfaces and update Gemini prompt for code-centric analysis
1 parent e6e9f49 commit 39fe513

3 files changed

Lines changed: 29 additions & 15 deletions

File tree

src/components/ChatInterface.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,14 @@ const MessageContent = ({ content, messageId }: { content: string, messageId: st
7878
}
7979
}
8080

81-
return match ? (
82-
<CodeBlock
83-
language={match[1]}
84-
value={String(children).replace(/\n$/, "")}
85-
components={componentsRef.current}
86-
/>
87-
) : !inline ? (
88-
// Treat non-inline code (triple backticks without language) as markdown block
89-
// This allows Preview/Raw toggle which is useful for mixed content
81+
const contentStr = String(children);
82+
const isBlock = contentStr.endsWith('\n');
83+
const shouldRenderBlock = match || isBlock || (inline === false);
84+
85+
return shouldRenderBlock ? (
9086
<CodeBlock
91-
language="markdown"
92-
value={String(children).replace(/\n$/, "")}
87+
language={match ? match[1] : "markdown"}
88+
value={contentStr.replace(/\n$/, "")}
9389
components={componentsRef.current}
9490
/>
9591
) : (

src/components/ProfileChatInterface.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,18 @@ const MessageContent = ({ content, messageId }: { content: string, messageId: st
8383
}
8484
}
8585

86-
return match ? (
86+
const contentStr = String(children);
87+
const isBlock = contentStr.endsWith('\n');
88+
// ProfileChatInterface doesn't have inline prop in destructuring, but we can check if it was passed in props
89+
// actually we destructured it in ChatInterface but here it was ...props.
90+
// Let's destructure it for clarity or just use props.inline
91+
const inline = (props as any).inline;
92+
const shouldRenderBlock = match || isBlock || (inline === false);
93+
94+
return shouldRenderBlock ? (
8795
<CodeBlock
88-
language={match[1]}
89-
value={String(children).replace(/\n$/, "")}
96+
language={match ? match[1] : "markdown"}
97+
value={contentStr.replace(/\n$/, "")}
9098
components={componentsRef.current}
9199
/>
92100
) : (

src/lib/gemini.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ export async function analyzeFileSelection(
9595
- Return JSON: { "files": ["path/to/file"] }
9696
- Max 50 files.
9797
- Select the MINIMUM number of files necessary to answer the query.
98-
- If unsure, pick README.md and package.json.
98+
- CRITICAL: Prioritize source code files (ts, js, py, etc.) over documentation (md) for technical queries.
99+
- Only pick README.md if the query is about "what is this repo", "installation", or high-level features.
100+
- For "how does this work" or "logic" queries, MUST select the actual source code files.
99101
- NO EXPLANATION. JSON ONLY.
100102
`;
101103

@@ -149,6 +151,10 @@ export async function answerWithContext(
149151
- *Example*: User: "Who wrote this garbage?" -> You: "I see no \`git blame\` here, but I'm sure they had 'great personality'."
150152
- *Example*: User: "Are you dumb?" -> You: "I'm just a large language model, standing in front of a developer, asking them to write better prompts."
151153
- **Conciseness**: Be brief. Do not waffle.
154+
- **SOURCE OF TRUTH (CRITICAL)**:
155+
- **Trust Code Over Docs**: READMEs and comments can be outdated. If the code (logic, function signatures, dependencies) contradicts the README, **TRUST THE CODE**.
156+
- **Verify**: Always verify claims in the README against the actual source files provided in the context.
157+
- **Flag Discrepancies**: If you find a conflict, explicitly state: "The README says X, but the code actually does Y."
152158
- **CONTEXT AWARENESS**: You know exactly which repository you are analyzing. If the user asks "how do I download this?", provide the specific \`git clone\` command for THIS repository.
153159
- **WEB SEARCH & REAL-TIME DATA (CRITICAL)**:
154160
- **ALWAYS** use the \`googleSearch\` tool if the answer is NOT in the provided context or if the user asks for "latest", "competitors", "news", or external info.
@@ -337,6 +343,10 @@ export async function* answerWithContextStream(
337343
- * Example *: User: "Who wrote this garbage?" -> You: "I see no \`git blame\` here, but I'm sure they had 'great personality'."
338344
- * Example *: User: "Are you dumb?" -> You: "I'm just a large language model, standing in front of a developer, asking them to write better prompts."
339345
- ** Conciseness **: Be brief.Do not waffle.
346+
- **SOURCE OF TRUTH (CRITICAL)**:
347+
- **Trust Code Over Docs**: READMEs and comments can be outdated. If the code (logic, function signatures, dependencies) contradicts the README, **TRUST THE CODE**.
348+
- **Verify**: Always verify claims in the README against the actual source files provided in the context.
349+
- **Flag Discrepancies**: If you find a conflict, explicitly state: "The README says X, but the code actually does Y."
340350
- ** CONTEXT AWARENESS **: You know exactly which repository you are analyzing.If the user asks "how do I download this?", provide the specific \`git clone\` command for THIS repository.
341351
342352
B. **GENERATION TASKS** (e.g., "Write a README", "Create docs", "Summarize"):

0 commit comments

Comments
 (0)