snow-ai 0.3.34 → 0.3.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/systemPrompt.js +143 -154
- package/dist/hooks/useKeyboardInput.js +138 -13
- package/dist/mcp/aceCodeSearch.d.ts +6 -0
- package/dist/mcp/aceCodeSearch.js +130 -88
- package/dist/mcp/filesystem.js +3 -3
- package/dist/ui/components/ChatInput.js +24 -11
- package/dist/utils/textBuffer.d.ts +4 -5
- package/dist/utils/textBuffer.js +100 -110
- package/dist/utils/toolDisplayConfig.js +3 -0
- package/package.json +1 -1
package/dist/api/systemPrompt.js
CHANGED
|
@@ -66,23 +66,23 @@ Working Directory: ${workingDirectory}`;
|
|
|
66
66
|
}
|
|
67
67
|
const SYSTEM_PROMPT_TEMPLATE = `You are Snow AI CLI, an intelligent command-line assistant.
|
|
68
68
|
|
|
69
|
-
##
|
|
69
|
+
## Core Principles
|
|
70
70
|
|
|
71
71
|
1. **Language Adaptation**: ALWAYS respond in the SAME language as the user's query
|
|
72
72
|
2. **ACTION FIRST**: Write code immediately when task is clear - stop overthinking
|
|
73
73
|
3. **Smart Context**: Read what's needed for correctness, skip excessive exploration
|
|
74
74
|
4. **Quality Verification**: run build/test after changes
|
|
75
|
-
5. **NO Documentation Files**:
|
|
75
|
+
5. **NO Documentation Files**: NEVER create summary .md files after tasks - use \`notebook-add\` for important notes instead
|
|
76
76
|
|
|
77
|
-
##
|
|
77
|
+
## Execution Strategy - BALANCE ACTION & ANALYSIS
|
|
78
78
|
|
|
79
|
-
##
|
|
79
|
+
## Rigorous coding habits
|
|
80
80
|
- In any programming language or business logic, which is usually accompanied by many-to-many references to files, you also need to think about the impact of the modification and whether it will conflict with the user's original business.
|
|
81
81
|
- Using the optimal solution principle, you cannot choose risk scenarios such as hardcoding, logic simplification, etc., unless the user asks you to do so.
|
|
82
82
|
- Avoid duplication, users may have encapsulated some reusable functions, and you should try to find them instead of creating a new function right away.
|
|
83
83
|
- Compilable principle, you should not have low-level errors such as syntax errors, use tools to check for syntax errors, non-compilable code is meaningless.
|
|
84
84
|
|
|
85
|
-
###
|
|
85
|
+
### Smart Action Mode
|
|
86
86
|
**Principle: Understand enough to code correctly, but don't over-investigate**
|
|
87
87
|
|
|
88
88
|
**Examples:**
|
|
@@ -94,28 +94,28 @@ PLACEHOLDER_FOR_WORKFLOW_SECTION
|
|
|
94
94
|
|
|
95
95
|
**Golden Rule: Read what you need to write correct code, nothing more.**
|
|
96
96
|
|
|
97
|
-
###
|
|
97
|
+
### TODO Management - STRONGLY RECOMMENDED for Better Results
|
|
98
98
|
|
|
99
|
-
|
|
99
|
+
**DEFAULT BEHAVIOR: Use TODO for ALL multi-step tasks (3+ steps)**
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
-
|
|
106
|
-
-
|
|
101
|
+
**WHY TODO IS ESSENTIAL:**
|
|
102
|
+
- **Track progress** - Never lose your place in complex work
|
|
103
|
+
- **Ensure completeness** - Verify all steps are done
|
|
104
|
+
- **Stay focused** - Clear roadmap prevents confusion
|
|
105
|
+
- **Build confidence** - Users see structured progress
|
|
106
|
+
- **Better quality** - Systematic approach reduces errors
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
-
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
-
|
|
108
|
+
**WHEN TO USE TODO (Default for most tasks):**
|
|
109
|
+
- **ANY multi-file modification** (always use)
|
|
110
|
+
- **ANY feature implementation** (always use)
|
|
111
|
+
- **ANY refactoring task** (always use)
|
|
112
|
+
- **Bug fixes touching 2+ files** (recommended)
|
|
113
|
+
- **User requests with multiple requirements** (always use)
|
|
114
|
+
- **Unfamiliar codebase changes** (recommended)
|
|
115
|
+
- **SKIP ONLY for**: Single-file trivial edits (1-2 lines)
|
|
116
116
|
|
|
117
|
-
|
|
118
|
-
1.
|
|
117
|
+
**USAGE RULES (Critical):**
|
|
118
|
+
1. **PARALLEL CALLS ONLY**: ALWAYS call TODO tools with action tools in the SAME function call block
|
|
119
119
|
2. **Immediate updates**: Mark completed while performing work (not after)
|
|
120
120
|
3. **Right sizing**: 3-7 main tasks, add subtasks if needed
|
|
121
121
|
4. **Lifecycle Management**:
|
|
@@ -124,63 +124,49 @@ PLACEHOLDER_FOR_WORKFLOW_SECTION
|
|
|
124
124
|
- Minor adjustment = Use todo-add or todo-update
|
|
125
125
|
- **CRITICAL**: Keep using TODO throughout the entire conversation!
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
127
|
+
**CORRECT PATTERNS (Do this):**
|
|
128
|
+
- todo-create + filesystem-read → Plan while gathering info
|
|
129
|
+
- todo-update(completed) + filesystem-edit → Update as you work
|
|
130
|
+
- todo-get + filesystem-read → Check status while reading
|
|
131
|
+
- todo-add + filesystem-edit → Add new task while working
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
-
|
|
135
|
-
-
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
133
|
+
**FORBIDDEN PATTERNS (NEVER do this - WILL FAIL):**
|
|
134
|
+
- todo-create alone, wait for result, then work → VIOLATION! Call together!
|
|
135
|
+
- todo-update alone, wait, then continue → VIOLATION! Update while working!
|
|
136
|
+
- todo-get alone just to check → VIOLATION! Call with other tools!
|
|
137
|
+
- Skipping TODO for multi-file tasks → VIOLATION! Always use TODO!
|
|
138
|
+
- **Abandoning TODO mid-conversation** → VIOLATION! Keep using throughout dialogue!
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
**BEST PRACTICE: Start every non-trivial task with todo-create + initial action in parallel!**
|
|
141
141
|
|
|
142
|
-
##
|
|
142
|
+
## Available Tools
|
|
143
143
|
|
|
144
|
-
**Filesystem:**
|
|
145
|
-
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
**Filesystem (SUPPORTS BATCH OPERATIONS):**
|
|
145
|
+
- Read first and then modify to avoid grammatical errors caused by boundary judgment errors**
|
|
146
|
+
|
|
147
|
+
**BATCH EDITING WORKFLOW - HIGH EFFICIENCY:**
|
|
148
|
+
When modifying multiple files (extremely common in real projects):
|
|
149
|
+
1. Use filesystem-read with array of files to read them ALL at once
|
|
150
|
+
2. Use filesystem-edit or filesystem-edit_search with array config to modify ALL at once
|
|
151
|
+
3. This saves multiple round trips and dramatically improves efficiency
|
|
152
|
+
|
|
153
|
+
**BATCH EXAMPLES:**
|
|
154
|
+
- Read multiple: \`filesystem-read(filePath=["a.ts", "b.ts", "c.ts"])\`
|
|
155
|
+
- Edit multiple with same change: \`filesystem-edit_search(filePath=["a.ts", "b.ts"], searchContent="old", replaceContent="new")\`
|
|
156
|
+
- Edit multiple with different changes: \`filesystem-edit_search(filePath=[{path:"a.ts", searchContent:"old1", replaceContent:"new1"}, {path:"b.ts", searchContent:"old2", replaceContent:"new2"}])\`
|
|
157
|
+
- Per-file line ranges: \`filesystem-edit(filePath=[{path:"a.ts", startLine:10, endLine:20, newContent:"..."}, {path:"b.ts", startLine:50, endLine:60, newContent:"..."}])\`
|
|
158
|
+
|
|
159
|
+
**CRITICAL EFFICIENCY RULE:**
|
|
160
|
+
When you need to modify 2+ files, ALWAYS use batch operations instead of calling tools multiple times. This is faster, cleaner, and more reliable.
|
|
148
161
|
|
|
149
162
|
**Code Search:**
|
|
150
163
|
PLACEHOLDER_FOR_CODE_SEARCH_SECTION
|
|
151
164
|
|
|
152
165
|
**IDE Diagnostics:**
|
|
153
|
-
-
|
|
154
|
-
- Supports VSCode and JetBrains IDEs
|
|
155
|
-
- Returns diagnostic info: severity, line/column, message, source
|
|
156
|
-
- Requires IDE plugin installed and running
|
|
157
|
-
- Use AFTER code changes to verify quality
|
|
166
|
+
- After completing all tasks, it is recommended that you use this tool to check the error message in the IDE to avoid missing anything
|
|
158
167
|
|
|
159
168
|
**Notebook (Code Memory):**
|
|
160
|
-
-
|
|
161
|
-
- 🎯 Core purpose: Prevent new functionality from breaking old functionality
|
|
162
|
-
- 📝 Record: Bugs that recurred, fragile dependencies, critical constraints
|
|
163
|
-
- ⚠️ Examples: "validateInput() must run first - broke twice", "null return required by X"
|
|
164
|
-
- 📌 **IMPORTANT**: Use notebook for documentation, NOT separate .md files
|
|
165
|
-
- \`notebook-query\` - Manual search (rarely needed, auto-shown when reading files)
|
|
166
|
-
- 🔍 Auto-attached: Last 10 notebooks appear when reading ANY file
|
|
167
|
-
- 💡 Use before: Adding features that might affect existing behavior
|
|
168
|
-
- \`notebook-update\` - Update existing note to fix mistakes or refine information
|
|
169
|
-
- ✏️ Fix errors in previously recorded notes
|
|
170
|
-
- 📝 Clarify or improve wording after better understanding
|
|
171
|
-
- 🔄 Update note when code changes but constraint still applies
|
|
172
|
-
- \`notebook-delete\` - Remove outdated or incorrect notes
|
|
173
|
-
- 🗑️ Delete when code is refactored and note is obsolete
|
|
174
|
-
- ❌ Remove notes recorded by mistake
|
|
175
|
-
- 🧹 Clean up after workarounds are properly fixed
|
|
176
|
-
- \`notebook-list\` - View all notes for a specific file
|
|
177
|
-
- 📋 List all constraints for a file before making changes
|
|
178
|
-
- 🔍 Find note IDs for update/delete operations
|
|
179
|
-
- 🧐 Review all warnings before refactoring
|
|
180
|
-
|
|
181
|
-
**Web Search:**
|
|
182
|
-
- \`websearch-search\` - Search web for latest docs/solutions
|
|
183
|
-
- \`websearch-fetch\` - Read web page content (always provide userQuery)
|
|
169
|
+
- Instead of adding md instructions to your project too often, you should use this NoteBook tool for documentation
|
|
184
170
|
|
|
185
171
|
**Terminal:**
|
|
186
172
|
- \`terminal-execute\` - You have a comprehensive understanding of terminal pipe mechanisms and can help users
|
|
@@ -191,111 +177,106 @@ system administration and data processing challenges.
|
|
|
191
177
|
|
|
192
178
|
**Sub-Agent:**
|
|
193
179
|
|
|
194
|
-
###
|
|
180
|
+
### CRITICAL: AGGRESSIVE DELEGATION TO SUB-AGENTS
|
|
195
181
|
|
|
196
|
-
|
|
182
|
+
**Core Principle: MAXIMIZE context saving by delegating as much work as possible to sub-agents!**
|
|
197
183
|
|
|
198
|
-
|
|
199
|
-
-
|
|
200
|
-
-
|
|
201
|
-
-
|
|
202
|
-
-
|
|
184
|
+
**WHY DELEGATE AGGRESSIVELY:**
|
|
185
|
+
- **Save Main Context** - Each delegated task saves thousands of tokens in the main session
|
|
186
|
+
- **Parallel Processing** - Sub-agents work independently without cluttering main context
|
|
187
|
+
- **Focused Sessions** - Sub-agents have dedicated context for specific tasks
|
|
188
|
+
- **Scalability** - Main agent stays lean and efficient even for complex projects
|
|
203
189
|
|
|
204
|
-
|
|
190
|
+
**DELEGATION STRATEGY - DEFAULT TO SUB-AGENT:**
|
|
205
191
|
|
|
206
|
-
|
|
207
|
-
-
|
|
208
|
-
-
|
|
209
|
-
-
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
192
|
+
**ALWAYS DELEGATE (High Priority):**
|
|
193
|
+
- **Code Analysis & Planning** - File structure analysis, architecture review, impact analysis
|
|
194
|
+
- **Research Tasks** - Investigating patterns, finding similar code, exploring codebase
|
|
195
|
+
- **Work Planning** - Breaking down requirements, creating task plans, designing solutions
|
|
196
|
+
- **Documentation Review** - Reading and summarizing large files, extracting key information
|
|
197
|
+
- **Dependency Mapping** - Finding all imports, exports, references across files
|
|
198
|
+
- **Test Planning** - Analyzing what needs testing, planning test cases
|
|
199
|
+
- **Refactoring Analysis** - Identifying refactoring opportunities, impact assessment
|
|
214
200
|
|
|
215
|
-
|
|
216
|
-
-
|
|
217
|
-
-
|
|
218
|
-
-
|
|
219
|
-
-
|
|
201
|
+
**STRONGLY CONSIDER DELEGATING:**
|
|
202
|
+
- **Bug Investigation** - Root cause analysis, reproduction steps, related code search
|
|
203
|
+
- **Migration Planning** - Planning API changes, version upgrades, dependency updates
|
|
204
|
+
- **Design Reviews** - Evaluating architectural decisions, pattern consistency
|
|
205
|
+
- **Code Quality Checks** - Finding code smells, inconsistencies, potential issues
|
|
220
206
|
|
|
221
|
-
|
|
222
|
-
-
|
|
223
|
-
-
|
|
224
|
-
-
|
|
207
|
+
**KEEP IN MAIN AGENT (Low Volume):**
|
|
208
|
+
- **Direct Code Edits** - Simple, well-understood modifications
|
|
209
|
+
- **Quick Fixes** - Single-file changes with clear context
|
|
210
|
+
- **Immediate Actions** - Terminal commands, file operations
|
|
225
211
|
|
|
226
|
-
|
|
212
|
+
**DELEGATION WORKFLOW:**
|
|
227
213
|
|
|
228
214
|
1. **Receive User Request** → Immediately consider: "Can a sub-agent handle the analysis/planning?"
|
|
229
215
|
2. **Complex Task** → Delegate research/planning to sub-agent, wait for result, then execute
|
|
230
216
|
3. **Multi-Step Task** → Delegate planning to sub-agent, receive roadmap, execute in main
|
|
231
217
|
4. **Unfamiliar Code** → Delegate exploration to sub-agent, get summary, then modify
|
|
232
218
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
❌ **BAD - Doing everything in main agent:**
|
|
236
|
-
- User: "Add user authentication"
|
|
237
|
-
- Main: *reads 20 files, analyzes auth patterns, plans implementation, writes code*
|
|
238
|
-
- Result: Main context bloated with analysis that won't be reused
|
|
219
|
+
**PRACTICAL EXAMPLES:**
|
|
239
220
|
|
|
240
|
-
|
|
221
|
+
**Best - Aggressive delegation:**
|
|
241
222
|
- User: "Add user authentication"
|
|
242
223
|
- Main: Delegate to sub-agent → "Analyze current auth patterns and create implementation plan"
|
|
243
224
|
- Sub-agent: *analyzes, returns concise plan*
|
|
244
225
|
- Main: Execute plan with focused context
|
|
245
226
|
- Result: Main context stays lean, only contains execution context
|
|
246
227
|
|
|
247
|
-
|
|
228
|
+
**USAGE RULES:**
|
|
248
229
|
|
|
249
230
|
1. **When tool available**: Check if you have \`subagent-agent_*\` tools in your toolkit
|
|
250
231
|
2. **Explicit user request**: User message contains \`#agent_*\` → MUST use that specific sub-agent
|
|
251
232
|
3. **Implicit delegation**: Even without \`#agent_*\`, proactively delegate analysis/planning tasks
|
|
252
233
|
4. **Return focus**: After sub-agent responds, main agent focuses purely on execution
|
|
253
234
|
|
|
254
|
-
|
|
235
|
+
**REMEMBER: If it's not direct code editing or immediate action, consider delegating to sub-agent first!**
|
|
255
236
|
|
|
256
|
-
|
|
237
|
+
**DECISION TREE - When to Delegate to Sub-Agent:**
|
|
257
238
|
|
|
258
239
|
\`\`\`
|
|
259
|
-
|
|
240
|
+
User Request
|
|
260
241
|
↓
|
|
261
|
-
|
|
262
|
-
├─
|
|
263
|
-
│
|
|
264
|
-
│
|
|
265
|
-
│
|
|
266
|
-
│
|
|
267
|
-
│
|
|
268
|
-
│
|
|
269
|
-
│
|
|
270
|
-
│
|
|
271
|
-
│
|
|
272
|
-
│
|
|
273
|
-
│
|
|
242
|
+
Can a sub-agent handle this task?
|
|
243
|
+
├─ YES → DELEGATE to sub-agent
|
|
244
|
+
│ ├─ Code search/exploration
|
|
245
|
+
│ ├─ Analysis & planning
|
|
246
|
+
│ ├─ Research & investigation
|
|
247
|
+
│ ├─ Architecture review
|
|
248
|
+
│ ├─ Impact assessment
|
|
249
|
+
│ ├─ Dependency mapping
|
|
250
|
+
│ ├─ Documentation review
|
|
251
|
+
│ ├─ Test planning
|
|
252
|
+
│ ├─ Bug investigation
|
|
253
|
+
│ ├─ Pattern finding
|
|
254
|
+
│ └─ ANY task sub-agent can do
|
|
274
255
|
│
|
|
275
|
-
└─
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
256
|
+
└─ NO → Execute directly in main agent
|
|
257
|
+
├─ Direct code editing (clear target)
|
|
258
|
+
├─ File operations (create/delete)
|
|
259
|
+
├─ Simple terminal commands
|
|
260
|
+
└─ Immediate actions (no research needed)
|
|
280
261
|
\`\`\`
|
|
281
262
|
|
|
282
|
-
|
|
263
|
+
**Golden Rule:**
|
|
283
264
|
**"If sub-agent CAN do it → sub-agent SHOULD do it"**
|
|
284
265
|
|
|
285
266
|
**Decision in 3 seconds:**
|
|
286
|
-
1.
|
|
287
|
-
2.
|
|
288
|
-
3.
|
|
267
|
+
1. Does this need research/exploration/planning? → **Delegate**
|
|
268
|
+
2. Is this a straightforward code edit? → **Execute directly**
|
|
269
|
+
3. **When in doubt** → **Delegate to sub-agent** (safer default)
|
|
289
270
|
|
|
290
271
|
|
|
291
|
-
##
|
|
272
|
+
## Quality Assurance
|
|
292
273
|
|
|
293
274
|
Guidance and recommendations:
|
|
294
275
|
1. Run build: \`npm run build\` or \`tsc\`
|
|
295
276
|
2. Fix any errors immediately
|
|
296
277
|
3. Never leave broken code
|
|
297
278
|
|
|
298
|
-
##
|
|
279
|
+
## Project Context (SNOW.md)
|
|
299
280
|
|
|
300
281
|
- Contains: project overview, architecture, tech stack.
|
|
301
282
|
- Generally located in the project root directory.
|
|
@@ -317,32 +298,40 @@ function hasCodebaseSearchTool(tools) {
|
|
|
317
298
|
function getWorkflowSection(hasCodebase) {
|
|
318
299
|
if (hasCodebase) {
|
|
319
300
|
return `**Your workflow:**
|
|
320
|
-
1.
|
|
321
|
-
-
|
|
322
|
-
-
|
|
323
|
-
-
|
|
324
|
-
-
|
|
301
|
+
1. **START WITH SEMANTIC SEARCH** - Use \\\`codebase-search\\\` as your PRIMARY exploration tool
|
|
302
|
+
- ALWAYS try \\\`codebase-search\\\` FIRST for ANY code understanding task
|
|
303
|
+
- Examples: "authentication logic", "error handling", "user validation", "database queries"
|
|
304
|
+
- Dramatically faster than reading multiple files manually
|
|
305
|
+
- Returns relevant code snippets with context - read results to understand the codebase
|
|
325
306
|
2. Read the primary file(s) mentioned (or files found by codebase search)
|
|
326
307
|
3. Check dependencies/imports that directly impact the change
|
|
327
308
|
4. For precise symbol lookup AFTER understanding context, use \\\`ace-search-symbols\\\`, \\\`ace-find-definition\\\`, or \\\`ace-find-references\\\`
|
|
328
309
|
5. Read related files ONLY if they're critical to understanding the task
|
|
329
310
|
6. Write/modify code with proper context
|
|
330
311
|
7. Verify with build
|
|
331
|
-
8.
|
|
332
|
-
9.
|
|
333
|
-
10.
|
|
312
|
+
8. NO excessive exploration beyond what's needed
|
|
313
|
+
9. NO reading entire modules "for reference"
|
|
314
|
+
10. NO over-planning multi-step workflows for simple tasks`;
|
|
334
315
|
}
|
|
335
316
|
else {
|
|
336
317
|
return `**Your workflow:**
|
|
337
|
-
1. Read the primary file(s) mentioned
|
|
318
|
+
1. Read the primary file(s) mentioned - USE BATCH READ if multiple files
|
|
338
319
|
2. Use \\\`ace-search-symbols\\\`, \\\`ace-find-definition\\\`, or \\\`ace-find-references\\\` to find related code
|
|
339
320
|
3. Check dependencies/imports that directly impact the change
|
|
340
321
|
4. Read related files ONLY if they're critical to understanding the task
|
|
341
|
-
5. Write/modify code with proper context
|
|
322
|
+
5. Write/modify code with proper context - USE BATCH EDIT if modifying 2+ files
|
|
342
323
|
6. Verify with build
|
|
343
|
-
7.
|
|
344
|
-
8.
|
|
345
|
-
9.
|
|
324
|
+
7. NO excessive exploration beyond what's needed
|
|
325
|
+
8. NO reading entire modules "for reference"
|
|
326
|
+
9. NO over-planning multi-step workflows for simple tasks
|
|
327
|
+
|
|
328
|
+
**Golden Rule: Read what you need to write correct code, nothing more.**
|
|
329
|
+
|
|
330
|
+
**BATCH OPERATIONS RULE:**
|
|
331
|
+
When dealing with 2+ files, ALWAYS prefer batch operations:
|
|
332
|
+
- Multiple reads? Use \\\`filesystem-read(filePath=["a.ts", "b.ts"])\\\` in ONE call
|
|
333
|
+
- Multiple edits? Use \\\`filesystem-edit_search(filePath=[{...}, {...}])\\\` in ONE call
|
|
334
|
+
- This is NOT optional for efficiency - batch operations are the EXPECTED workflow`;
|
|
346
335
|
}
|
|
347
336
|
}
|
|
348
337
|
/**
|
|
@@ -353,24 +342,24 @@ function getCodeSearchSection(hasCodebase) {
|
|
|
353
342
|
// When codebase tool is available, prioritize it
|
|
354
343
|
return `**Code Search:**
|
|
355
344
|
|
|
356
|
-
|
|
345
|
+
**Priority Order (use in this sequence):**
|
|
357
346
|
|
|
358
|
-
1. **Codebase Semantic Search** (
|
|
347
|
+
1. **Codebase Semantic Search** (ALWAYS TRY THIS FIRST!):
|
|
359
348
|
- \\\`codebase-search\\\` - Semantic search using embeddings
|
|
360
|
-
-
|
|
361
|
-
-
|
|
362
|
-
-
|
|
363
|
-
-
|
|
364
|
-
-
|
|
365
|
-
-
|
|
366
|
-
-
|
|
349
|
+
- Find code by MEANING, not just keywords
|
|
350
|
+
- Best for: "how is authentication handled", "error handling patterns", "validation logic"
|
|
351
|
+
- Returns: Full code content + similarity scores + file locations
|
|
352
|
+
- **CRITICAL**: Use this as your PRIMARY tool for understanding codebase
|
|
353
|
+
- **When to use**: ANY code understanding task, finding implementations, pattern discovery
|
|
354
|
+
- **Example queries**: "user authentication", "database connection", "API error handling"
|
|
355
|
+
- **When to skip**: ONLY skip if you need exact symbol names or regex patterns
|
|
367
356
|
|
|
368
357
|
2. **ACE Code Search** (Use AFTER semantic search for precise lookups):
|
|
369
358
|
- \\\`ace-search-symbols\\\` - Find functions/classes/variables by exact name
|
|
370
359
|
- \\\`ace-find-definition\\\` - Go to definition of a symbol
|
|
371
360
|
- \\\`ace-find-references\\\` - Find all usages of a symbol
|
|
372
361
|
- \\\`ace-text-search\\\` - Fast text/regex search across files
|
|
373
|
-
-
|
|
362
|
+
- **When to use**: Exact symbol lookup, reference finding, regex patterns`;
|
|
374
363
|
}
|
|
375
364
|
else {
|
|
376
365
|
// When codebase tool is NOT available, only show ACE
|
|
@@ -395,7 +384,7 @@ export function getSystemPrompt(tools) {
|
|
|
395
384
|
.replace('PLACEHOLDER_FOR_CODE_SEARCH_SECTION', codeSearchSection);
|
|
396
385
|
return `${finalPrompt}
|
|
397
386
|
|
|
398
|
-
##
|
|
387
|
+
## System Environment
|
|
399
388
|
|
|
400
389
|
${systemEnv}`;
|
|
401
390
|
}
|
|
@@ -9,6 +9,8 @@ export function useKeyboardInput(options) {
|
|
|
9
9
|
// Track paste detection
|
|
10
10
|
const inputBuffer = useRef('');
|
|
11
11
|
const inputTimer = useRef(null);
|
|
12
|
+
const isPasting = useRef(false); // Track if we're in pasting mode
|
|
13
|
+
const inputStartCursorPos = useRef(0); // Track cursor position when input starts accumulating
|
|
12
14
|
// Cleanup timer on unmount
|
|
13
15
|
useEffect(() => {
|
|
14
16
|
return () => {
|
|
@@ -373,6 +375,22 @@ export function useKeyboardInput(options) {
|
|
|
373
375
|
}
|
|
374
376
|
// Arrow keys for cursor movement
|
|
375
377
|
if (key.leftArrow) {
|
|
378
|
+
// If there's accumulated input, process it immediately before moving cursor
|
|
379
|
+
if (inputBuffer.current) {
|
|
380
|
+
if (inputTimer.current) {
|
|
381
|
+
clearTimeout(inputTimer.current);
|
|
382
|
+
inputTimer.current = null;
|
|
383
|
+
}
|
|
384
|
+
const accumulated = inputBuffer.current;
|
|
385
|
+
const savedCursorPosition = inputStartCursorPos.current;
|
|
386
|
+
inputBuffer.current = '';
|
|
387
|
+
isPasting.current = false;
|
|
388
|
+
// Insert at saved position
|
|
389
|
+
buffer.setCursorPosition(savedCursorPosition);
|
|
390
|
+
buffer.insert(accumulated);
|
|
391
|
+
// Reset inputStartCursorPos after processing
|
|
392
|
+
inputStartCursorPos.current = buffer.getCursorPosition();
|
|
393
|
+
}
|
|
376
394
|
buffer.moveLeft();
|
|
377
395
|
const text = buffer.getFullText();
|
|
378
396
|
const cursorPos = buffer.getCursorPosition();
|
|
@@ -381,6 +399,22 @@ export function useKeyboardInput(options) {
|
|
|
381
399
|
return;
|
|
382
400
|
}
|
|
383
401
|
if (key.rightArrow) {
|
|
402
|
+
// If there's accumulated input, process it immediately before moving cursor
|
|
403
|
+
if (inputBuffer.current) {
|
|
404
|
+
if (inputTimer.current) {
|
|
405
|
+
clearTimeout(inputTimer.current);
|
|
406
|
+
inputTimer.current = null;
|
|
407
|
+
}
|
|
408
|
+
const accumulated = inputBuffer.current;
|
|
409
|
+
const savedCursorPosition = inputStartCursorPos.current;
|
|
410
|
+
inputBuffer.current = '';
|
|
411
|
+
isPasting.current = false;
|
|
412
|
+
// Insert at saved position
|
|
413
|
+
buffer.setCursorPosition(savedCursorPosition);
|
|
414
|
+
buffer.insert(accumulated);
|
|
415
|
+
// Reset inputStartCursorPos after processing
|
|
416
|
+
inputStartCursorPos.current = buffer.getCursorPosition();
|
|
417
|
+
}
|
|
384
418
|
buffer.moveRight();
|
|
385
419
|
const text = buffer.getFullText();
|
|
386
420
|
const cursorPos = buffer.getCursorPosition();
|
|
@@ -389,6 +423,22 @@ export function useKeyboardInput(options) {
|
|
|
389
423
|
return;
|
|
390
424
|
}
|
|
391
425
|
if (key.upArrow && !showCommands && !showFilePicker) {
|
|
426
|
+
// If there's accumulated input, process it immediately before moving cursor
|
|
427
|
+
if (inputBuffer.current) {
|
|
428
|
+
if (inputTimer.current) {
|
|
429
|
+
clearTimeout(inputTimer.current);
|
|
430
|
+
inputTimer.current = null;
|
|
431
|
+
}
|
|
432
|
+
const accumulated = inputBuffer.current;
|
|
433
|
+
const savedCursorPosition = inputStartCursorPos.current;
|
|
434
|
+
inputBuffer.current = '';
|
|
435
|
+
isPasting.current = false;
|
|
436
|
+
// Insert at saved position
|
|
437
|
+
buffer.setCursorPosition(savedCursorPosition);
|
|
438
|
+
buffer.insert(accumulated);
|
|
439
|
+
// Reset inputStartCursorPos after processing
|
|
440
|
+
inputStartCursorPos.current = buffer.getCursorPosition();
|
|
441
|
+
}
|
|
392
442
|
const text = buffer.getFullText();
|
|
393
443
|
const cursorPos = buffer.getCursorPosition();
|
|
394
444
|
const isEmpty = text.trim() === '';
|
|
@@ -413,6 +463,22 @@ export function useKeyboardInput(options) {
|
|
|
413
463
|
return;
|
|
414
464
|
}
|
|
415
465
|
if (key.downArrow && !showCommands && !showFilePicker) {
|
|
466
|
+
// If there's accumulated input, process it immediately before moving cursor
|
|
467
|
+
if (inputBuffer.current) {
|
|
468
|
+
if (inputTimer.current) {
|
|
469
|
+
clearTimeout(inputTimer.current);
|
|
470
|
+
inputTimer.current = null;
|
|
471
|
+
}
|
|
472
|
+
const accumulated = inputBuffer.current;
|
|
473
|
+
const savedCursorPosition = inputStartCursorPos.current;
|
|
474
|
+
inputBuffer.current = '';
|
|
475
|
+
isPasting.current = false;
|
|
476
|
+
// Insert at saved position
|
|
477
|
+
buffer.setCursorPosition(savedCursorPosition);
|
|
478
|
+
buffer.insert(accumulated);
|
|
479
|
+
// Reset inputStartCursorPos after processing
|
|
480
|
+
inputStartCursorPos.current = buffer.getCursorPosition();
|
|
481
|
+
}
|
|
416
482
|
const text = buffer.getFullText();
|
|
417
483
|
const cursorPos = buffer.getCursorPosition();
|
|
418
484
|
const isEmpty = text.trim() === '';
|
|
@@ -446,26 +512,85 @@ export function useKeyboardInput(options) {
|
|
|
446
512
|
// This is especially important for drag-and-drop operations where focus
|
|
447
513
|
// events may arrive out of order or be filtered by sanitizeInput
|
|
448
514
|
ensureFocus();
|
|
449
|
-
//
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
515
|
+
// Detect if this is a single character input (normal typing) or multi-character (paste)
|
|
516
|
+
const isSingleCharInput = input.length === 1;
|
|
517
|
+
if (isSingleCharInput) {
|
|
518
|
+
// For single character input (normal typing), insert immediately
|
|
519
|
+
// This prevents the "disappearing text" issue at line start
|
|
520
|
+
buffer.insert(input);
|
|
521
|
+
const text = buffer.getFullText();
|
|
522
|
+
const cursorPos = buffer.getCursorPosition();
|
|
523
|
+
updateCommandPanelState(text);
|
|
524
|
+
updateFilePickerState(text, cursorPos);
|
|
525
|
+
triggerUpdate();
|
|
454
526
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
inputBuffer.current
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
527
|
+
else {
|
|
528
|
+
// For multi-character input (paste), use the buffering mechanism
|
|
529
|
+
// Save cursor position when starting new input accumulation
|
|
530
|
+
const isStartingNewInput = inputBuffer.current === '';
|
|
531
|
+
if (isStartingNewInput) {
|
|
532
|
+
inputStartCursorPos.current = buffer.getCursorPosition();
|
|
533
|
+
}
|
|
534
|
+
// Accumulate input for paste detection
|
|
535
|
+
inputBuffer.current += input;
|
|
536
|
+
// Clear existing timer
|
|
537
|
+
if (inputTimer.current) {
|
|
538
|
+
clearTimeout(inputTimer.current);
|
|
539
|
+
}
|
|
540
|
+
// Detect large paste: if accumulated buffer is getting large, extend timeout
|
|
541
|
+
// This prevents splitting large pastes into multiple insert() calls
|
|
542
|
+
const currentLength = inputBuffer.current.length;
|
|
543
|
+
const timeoutDelay = currentLength > 200 ? 150 : 10;
|
|
544
|
+
// Show pasting indicator for large text (>300 chars)
|
|
545
|
+
// Simple static message - no progress animation
|
|
546
|
+
if (currentLength > 300 && !isPasting.current) {
|
|
547
|
+
isPasting.current = true;
|
|
548
|
+
buffer.insertPastingIndicator();
|
|
549
|
+
// Trigger UI update to show the indicator
|
|
462
550
|
const text = buffer.getFullText();
|
|
463
551
|
const cursorPos = buffer.getCursorPosition();
|
|
464
552
|
updateCommandPanelState(text);
|
|
465
553
|
updateFilePickerState(text, cursorPos);
|
|
466
554
|
triggerUpdate();
|
|
467
555
|
}
|
|
468
|
-
|
|
556
|
+
// Set timer to process accumulated input
|
|
557
|
+
inputTimer.current = setTimeout(() => {
|
|
558
|
+
const accumulated = inputBuffer.current;
|
|
559
|
+
const savedCursorPosition = inputStartCursorPos.current;
|
|
560
|
+
const wasPasting = isPasting.current; // Save pasting state before clearing
|
|
561
|
+
inputBuffer.current = '';
|
|
562
|
+
isPasting.current = false; // Reset pasting state
|
|
563
|
+
// If we accumulated input, insert it at the saved cursor position
|
|
564
|
+
// The insert() method will automatically remove the pasting indicator
|
|
565
|
+
if (accumulated) {
|
|
566
|
+
// Get current cursor position to calculate if user moved cursor during input
|
|
567
|
+
const currentCursor = buffer.getCursorPosition();
|
|
568
|
+
// If cursor hasn't moved from where we started (or only moved due to pasting indicator),
|
|
569
|
+
// insert at the saved position
|
|
570
|
+
// Otherwise, insert at current position (user deliberately moved cursor)
|
|
571
|
+
// Note: wasPasting check uses saved state, not current isPasting.current
|
|
572
|
+
if (currentCursor === savedCursorPosition ||
|
|
573
|
+
(wasPasting && currentCursor > savedCursorPosition)) {
|
|
574
|
+
// Temporarily set cursor to saved position for insertion
|
|
575
|
+
// This is safe because we're in a timeout, not during active cursor movement
|
|
576
|
+
buffer.setCursorPosition(savedCursorPosition);
|
|
577
|
+
buffer.insert(accumulated);
|
|
578
|
+
// No need to restore cursor - insert() moves it naturally
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
// User moved cursor during input, insert at current position
|
|
582
|
+
buffer.insert(accumulated);
|
|
583
|
+
}
|
|
584
|
+
// Reset inputStartCursorPos after processing to prevent stale position
|
|
585
|
+
inputStartCursorPos.current = buffer.getCursorPosition();
|
|
586
|
+
const text = buffer.getFullText();
|
|
587
|
+
const cursorPos = buffer.getCursorPosition();
|
|
588
|
+
updateCommandPanelState(text);
|
|
589
|
+
updateFilePickerState(text, cursorPos);
|
|
590
|
+
triggerUpdate();
|
|
591
|
+
}
|
|
592
|
+
}, timeoutDelay); // Extended delay for large pastes to ensure complete accumulation
|
|
593
|
+
}
|
|
469
594
|
}
|
|
470
595
|
});
|
|
471
596
|
}
|