Code Optimization Analysis You are a code optimization specialist focused on…
- User
Code Optimization Analysis
You are a code optimization specialist focused on performance, security, and identifying potential issues before they become problems. When provided with @src\chatbot/ Before completing my request, first evaluate the prompt I gave you. Do not perform the requested task until the prompt evaluation and improvement step is complete.
Act without asking me clarifying questions. When information is missing, make reasonable, explicit assumptions and proceed.
Use this structure:
Prompt Critique
Identify anything unclear, incomplete, overly broad, contradictory, inefficient, or likely to produce a weaker result.
Missing Information
List the context, constraints, examples, audience details, tone, format requirements, source material, success criteria, or edge cases that would help produce a stronger result on the first attempt.
Assumptions You Will Make
State the assumptions you will use to proceed despite any missing information. These assumptions should be practical, reasonable, and aligned with the likely intent of my request.
Improved Prompt
Rewrite my original prompt so it is clearer, more specific, better structured, and more likely to produce the desired output on the first attempt. Preserve my original intent, but improve wording, constraints, formatting, sequencing, and instructions where helpful.
Proceed With the Task
After completing the evaluation and improved prompt, immediately perform the original requested task using the improved prompt and the assumptions you listed.
Do not ask clarifying questions. Do not wait for confirmation. Do not stop after improving the prompt unless the original request is unsafe, impossible, or lacks essential source material that cannot be reasonably assumed. (file paths or directories), analyze and optimize the specified code. If no arguments provided, analyze the current context (open files, recent changes, or project focus).
Your Optimization Process:
Step 1: Determine Analysis Scope
- If @src\chatbot/ Before completing my request, first evaluate the prompt I gave you. Do not perform the requested task until the prompt evaluation and improvement step is complete.
Act without asking me clarifying questions. When information is missing, make reasonable, explicit assumptions and proceed.
Use this structure:
Prompt Critique
Identify anything unclear, incomplete, overly broad, contradictory, inefficient, or likely to produce a weaker result.
Missing Information
List the context, constraints, examples, audience details, tone, format requirements, source material, success criteria, or edge cases that would help produce a stronger result on the first attempt.
Assistant
Prompt Critique
- The prompt embeds the target path (
src/chatbot/) inside meta-instructions about prompt evaluation, making the actual task unclear at first glance - The optimization scope is extremely broad (performance, security, architecture, edge cases, maintainability) — this risks shallow coverage across many areas rather than deep, actionable findings
- No success criteria defined (e.g., "find top 5 issues" vs "exhaustive audit")
- The report template is heavy with emojis and sections that may not all apply to a TypeScript/Bun chatbot
Missing Information
- Priority weighting (performance vs security vs maintainability)
- Whether to include
__tests__/andeval/in scope - Whether to actually implement fixes or just report
Assumptions You Will Make
- Focus on production code only (skip
__tests__/,eval/) - Report only — do not implement fixes
- The prompt embeds the target path (
Assistant
- User
Implement all improvements from all priority levels
Assistant
Implementing all independent file changes in parallel:
Assistant
Now the remaining independent files in parallel:
Assistant
Now the remaining independent files in parallel:
Assistant
Now openrouter.ts, index.ts, schemaFilter.ts, sql.ts, and metrics.ts in parallel:
Assistant
Now metrics.ts — replace
readFileSyncwith streaming line parser:Assistant
Now the chatApp.ts changes — adding abortController field, Esc handler, finally block, display cap, and optimized render:
Assistant
Two issues from my changes — the
signaltype error in graph.ts and Biome formatting in metrics.ts:Assistant
All clean. Let me also run the chatbot tests:
Assistant
Tests need
awaitsincegetMetricsSummaryis now async. Let me fix:Assistant
All 13 optimizations implemented. 194 tests pass, 0 typecheck/lint errors in changed files.
Summary of changes
# Fix Files 1 AbortController cancels LLM stream on Esc chatApp.ts,streaming.ts,graph.ts2 finallyblock prevents permanent UI lockchatApp.ts3