@pimzino/sgrep 1.3.0

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.
Files changed (73) hide show
  1. package/README.md +413 -0
  2. package/build/.claude-plugin/marketplace.json +20 -0
  3. package/build/commands/ask.d.ts +11 -0
  4. package/build/commands/ask.d.ts.map +1 -0
  5. package/build/commands/ask.js +65 -0
  6. package/build/commands/ask.js.map +1 -0
  7. package/build/commands/enhance.d.ts +16 -0
  8. package/build/commands/enhance.d.ts.map +1 -0
  9. package/build/commands/enhance.js +107 -0
  10. package/build/commands/enhance.js.map +1 -0
  11. package/build/commands/search.d.ts +12 -0
  12. package/build/commands/search.d.ts.map +1 -0
  13. package/build/commands/search.js +65 -0
  14. package/build/commands/search.js.map +1 -0
  15. package/build/commands/watch.d.ts +13 -0
  16. package/build/commands/watch.d.ts.map +1 -0
  17. package/build/commands/watch.js +179 -0
  18. package/build/commands/watch.js.map +1 -0
  19. package/build/index.d.ts +3 -0
  20. package/build/index.d.ts.map +1 -0
  21. package/build/index.js +124 -0
  22. package/build/index.js.map +1 -0
  23. package/build/install/claude-code.d.ts +10 -0
  24. package/build/install/claude-code.d.ts.map +1 -0
  25. package/build/install/claude-code.js +255 -0
  26. package/build/install/claude-code.js.map +1 -0
  27. package/build/install/codex.d.ts +4 -0
  28. package/build/install/codex.d.ts.map +1 -0
  29. package/build/install/codex.js +123 -0
  30. package/build/install/codex.js.map +1 -0
  31. package/build/install/cursor.d.ts +4 -0
  32. package/build/install/cursor.d.ts.map +1 -0
  33. package/build/install/cursor.js +91 -0
  34. package/build/install/cursor.js.map +1 -0
  35. package/build/install/droid.d.ts +4 -0
  36. package/build/install/droid.d.ts.map +1 -0
  37. package/build/install/droid.js +226 -0
  38. package/build/install/droid.js.map +1 -0
  39. package/build/install/opencode.d.ts +4 -0
  40. package/build/install/opencode.d.ts.map +1 -0
  41. package/build/install/opencode.js +276 -0
  42. package/build/install/opencode.js.map +1 -0
  43. package/build/plugins/sgrep/.claude-plugin/plugin.json +9 -0
  44. package/build/plugins/sgrep/hooks/hooks.json +39 -0
  45. package/build/plugins/sgrep/hooks/sgrep_enhance.js +160 -0
  46. package/build/plugins/sgrep/hooks/sgrep_watch.js +240 -0
  47. package/build/plugins/sgrep/hooks/sgrep_watch_kill.js +158 -0
  48. package/build/plugins/sgrep/skills/sgrep/SKILL.md +97 -0
  49. package/build/utils/config.d.ts +26 -0
  50. package/build/utils/config.d.ts.map +1 -0
  51. package/build/utils/config.js +106 -0
  52. package/build/utils/config.js.map +1 -0
  53. package/build/utils/context-manager.d.ts +33 -0
  54. package/build/utils/context-manager.d.ts.map +1 -0
  55. package/build/utils/context-manager.js +244 -0
  56. package/build/utils/context-manager.js.map +1 -0
  57. package/build/utils/context.d.ts +25 -0
  58. package/build/utils/context.d.ts.map +1 -0
  59. package/build/utils/context.js +132 -0
  60. package/build/utils/context.js.map +1 -0
  61. package/build/utils/file-walker.d.ts +20 -0
  62. package/build/utils/file-walker.d.ts.map +1 -0
  63. package/build/utils/file-walker.js +239 -0
  64. package/build/utils/file-walker.js.map +1 -0
  65. package/build/utils/output.d.ts +38 -0
  66. package/build/utils/output.d.ts.map +1 -0
  67. package/build/utils/output.js +150 -0
  68. package/build/utils/output.js.map +1 -0
  69. package/build/utils/prompt-parser.d.ts +12 -0
  70. package/build/utils/prompt-parser.d.ts.map +1 -0
  71. package/build/utils/prompt-parser.js +54 -0
  72. package/build/utils/prompt-parser.js.map +1 -0
  73. package/package.json +59 -0
package/README.md ADDED
@@ -0,0 +1,413 @@
1
+ # sgrep - Semantic Grep
2
+
3
+ A command-line tool for semantic code search. Unlike traditional grep that matches text patterns, sgrep finds code by **meaning** - describe what functionality you're looking for, and it finds relevant code across your codebase.
4
+
5
+ Powered by the [Augment SDK](https://www.augmentcode.com/).
6
+
7
+ ## Installation
8
+
9
+ ### From npm
10
+
11
+ ```bash
12
+ # Install globally
13
+ npm install -g @pimzino/sgrep
14
+
15
+ # Or use with npx
16
+ npx @pimzino/sgrep "your search query"
17
+ ```
18
+
19
+ ### Agent Integrations
20
+
21
+ Install sgrep for your favorite AI coding agent:
22
+
23
+ ```bash
24
+ # Claude Code
25
+ sgrep install-claude-code
26
+
27
+ # Cursor
28
+ sgrep install-cursor
29
+
30
+ # OpenAI Codex CLI
31
+ sgrep install-codex
32
+
33
+ # Factory Droid
34
+ sgrep install-droid
35
+
36
+ # OpenCode
37
+ sgrep install-opencode
38
+ ```
39
+
40
+ This adds the sgrep skill to your agent, allowing you to use semantic search directly in your AI coding sessions.
41
+
42
+ ## Prerequisites
43
+
44
+ Before using sgrep, you need to:
45
+
46
+ 1. Install the auggie CLI:
47
+ ```bash
48
+ npm install -g @augmentcode/auggie@latest
49
+ ```
50
+
51
+ 2. Login to Augment:
52
+ ```bash
53
+ auggie login
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ### Semantic Search (Default Command)
59
+
60
+ Search for code by describing what it does:
61
+
62
+ ```bash
63
+ # Search in current directory
64
+ sgrep "authentication middleware"
65
+
66
+ # Search in specific directory
67
+ sgrep "database connection setup" ./src
68
+
69
+ # Explicit search command
70
+ sgrep search "error handling" ./backend
71
+
72
+ # Limit results
73
+ sgrep search -m 5 "user login handling"
74
+ ```
75
+
76
+ ### Ask Questions
77
+
78
+ Get explanations about how code works:
79
+
80
+ ```bash
81
+ # Ask about architecture
82
+ sgrep ask "How does the auth flow work?"
83
+
84
+ # Ask about specific directory
85
+ sgrep ask "What patterns are used for API endpoints?" ./api
86
+
87
+ # Ask about implementation details
88
+ sgrep ask "How is the database accessed?"
89
+ ```
90
+
91
+ ### Enhance Prompts
92
+
93
+ Improve vague prompts with codebase context:
94
+
95
+ ```bash
96
+ # Enhance a simple prompt
97
+ sgrep enhance "fix the bug"
98
+
99
+ # Enhance with specific directory context
100
+ sgrep enhance "add authentication" ./my-project
101
+
102
+ # JSON output
103
+ sgrep enhance "refactor this" --json
104
+ ```
105
+
106
+ ### Watch Mode
107
+
108
+ Keep the index up-to-date with live file watching:
109
+
110
+ ```bash
111
+ # Watch current directory
112
+ sgrep watch
113
+
114
+ # Watch specific directory
115
+ sgrep watch ./my-project
116
+
117
+ # Write PID to file (for daemon management)
118
+ sgrep watch --pid-file /tmp/sgrep.pid
119
+ ```
120
+
121
+ Output shows real-time index updates:
122
+ ```
123
+ [10:32:15] + added: src/newfile.ts (143 total)
124
+ [10:32:47] ~ updated: src/utils/helper.ts (143 total)
125
+ [10:33:02] - removed: src/oldfile.ts (142 total)
126
+ ```
127
+
128
+ The `--pid-file` option is used internally by the Claude Code hooks to manage the background watch process.
129
+
130
+ ### Options
131
+
132
+ | Option | Short | Description |
133
+ |--------|-------|-------------|
134
+ | `--dir <path>` | `-d` | Directory to search (default: cwd) |
135
+ | `--max-results <n>` | `-m` | Limit number of results (search only) |
136
+ | `--json` | `-j` | Output results as JSON |
137
+ | `--no-color` | | Disable colored output |
138
+ | `--debug` | | Enable verbose debug logging |
139
+ | `--pid-file <path>` | | Write PID to file (watch command only) |
140
+ | `--version` | `-v` | Show version |
141
+ | `--help` | `-h` | Show help |
142
+
143
+ ### Commands
144
+
145
+ | Command | Description |
146
+ |---------|-------------|
147
+ | `sgrep <query>` | Semantic search (default) |
148
+ | `sgrep search <query>` | Semantic search |
149
+ | `sgrep ask <question>` | Ask a question about the codebase |
150
+ | `sgrep enhance <prompt>` | Enhance a prompt with codebase context |
151
+ | `sgrep watch` | Watch for file changes and keep index updated |
152
+ | `sgrep install-claude-code` | Install Claude Code plugin |
153
+ | `sgrep uninstall-claude-code` | Uninstall Claude Code plugin |
154
+ | `sgrep install-codex` | Install Codex CLI plugin |
155
+ | `sgrep uninstall-codex` | Uninstall Codex CLI plugin |
156
+ | `sgrep install-cursor` | Install Cursor skill |
157
+ | `sgrep uninstall-cursor` | Uninstall Cursor skill |
158
+ | `sgrep install-droid` | Install Factory Droid plugin |
159
+ | `sgrep uninstall-droid` | Uninstall Factory Droid plugin |
160
+ | `sgrep install-opencode` | Install OpenCode plugin |
161
+ | `sgrep uninstall-opencode` | Uninstall OpenCode plugin |
162
+
163
+ ### Examples
164
+
165
+ ```bash
166
+ # Basic semantic search
167
+ sgrep "user authentication"
168
+
169
+ # Search with path as positional argument
170
+ sgrep "API rate limiting" ./packages/api
171
+
172
+ # JSON output for piping
173
+ sgrep "error handling" --json | jq '.results'
174
+
175
+ # Debug mode for troubleshooting
176
+ sgrep --debug "database models"
177
+
178
+ # Ask a question
179
+ sgrep ask "What testing frameworks are used?"
180
+
181
+ # Enhance a vague instruction
182
+ sgrep enhance "fix the login issue"
183
+
184
+ # Watch for changes
185
+ sgrep watch ./src
186
+ ```
187
+
188
+ ## Configuration
189
+
190
+ sgrep supports configuration via files with cascading priority:
191
+
192
+ 1. CLI flags (highest priority)
193
+ 2. Environment variables
194
+ 3. Local config file (`.sgreprc.json` in cwd or parent dirs)
195
+ 4. Global config file (`~/.config/sgrep/config.json`)
196
+
197
+ ### Config File Format
198
+
199
+ Create a `.sgreprc.json` file:
200
+
201
+ ```json
202
+ {
203
+ "defaultDir": "./src",
204
+ "maxResults": 10,
205
+ "outputFormat": "pretty"
206
+ }
207
+ ```
208
+
209
+ ### Environment Variables
210
+
211
+ | Variable | Description |
212
+ |----------|-------------|
213
+ | `SGREP_DIR` | Default directory to search |
214
+ | `SGREP_DEBUG` | Enable debug mode for CLI and hooks (`true` or `1`) |
215
+ | `SGREP_MAX_RESULTS` | Default max results |
216
+ | `SGREP_FORMAT` | Output format (`json` or `pretty`) |
217
+ | `NO_COLOR` | Disable colors (standard) |
218
+ | `SGREP_NO_COLOR` | Disable colors (sgrep-specific) |
219
+
220
+ #### Hook Debug Logging
221
+
222
+ When using the Claude Code integration, set `SGREP_DEBUG=1` to enable detailed logging for troubleshooting hooks:
223
+
224
+ ```bash
225
+ # Enable debug logging for hooks
226
+ set SGREP_DEBUG=1 # Windows
227
+ export SGREP_DEBUG=1 # Linux/macOS
228
+ ```
229
+
230
+ Debug logs are written to:
231
+ - `%TEMP%\sgrep-enhance.log` - Prompt enhancement hook
232
+ - `%TEMP%\sgrep-watch.log` - Session start hook
233
+ - `%TEMP%\sgrep-watch-kill.log` - Session end hook
234
+
235
+ ## How It Works
236
+
237
+ sgrep uses the Augment SDK's `DirectContext` to:
238
+
239
+ 1. **Index your codebase** - Builds a semantic understanding of your code
240
+ 2. **Watch for changes** - Incrementally updates the index when files change
241
+ 3. **Search by meaning** - Finds code that matches your description, not just text patterns
242
+ 4. **Answer questions** - Synthesizes explanations from relevant code sections
243
+ 5. **Enhance prompts** - Improves vague instructions with codebase context
244
+
245
+ This makes it powerful for:
246
+ - Exploring unfamiliar codebases
247
+ - Finding implementations without knowing exact names
248
+ - Understanding how systems work
249
+ - Discovering related code across files
250
+ - Improving AI prompts with relevant context
251
+
252
+ ## Comparison with grep/ripgrep
253
+
254
+ | Feature | grep/rg | sgrep |
255
+ |---------|---------|-------|
256
+ | Text pattern matching | Yes | No |
257
+ | Regex support | Yes | No |
258
+ | Find by functionality | No | Yes |
259
+ | Understands code semantics | No | Yes |
260
+ | Ask questions | No | Yes |
261
+ | Enhance prompts | No | Yes |
262
+ | Live file watching | No | Yes |
263
+ | Speed | Instant | ~100-500ms |
264
+
265
+ **Use grep/rg when:** You know the exact text, variable name, or pattern to search for.
266
+
267
+ **Use sgrep when:** You want to find code by what it does, or understand how something works.
268
+
269
+ ## Agent Integrations
270
+
271
+ sgrep includes plugins for popular AI coding agents:
272
+
273
+ ### Claude Code
274
+
275
+ ```bash
276
+ sgrep install-claude-code
277
+ ```
278
+
279
+ Adds the `/sgrep` skill to Claude Code for semantic searches directly in your coding sessions.
280
+
281
+ **Features installed:**
282
+
283
+ - **Skill** (`/sgrep`) - Use semantic search directly in Claude Code conversations
284
+ - **SessionStart Hook** - Automatically starts `sgrep watch` in the background when Claude Code starts, keeping the index warm for fast searches
285
+ - **SessionEnd Hook** - Cleanly shuts down the background watch process when Claude Code exits
286
+ - **UserPromptSubmit Hook** - Optionally enhances your prompts with codebase context before sending to Claude (shows a confirmation dialog on Windows)
287
+
288
+ ### Cursor
289
+
290
+ ```bash
291
+ sgrep install-cursor
292
+ ```
293
+
294
+ Adds the sgrep skill to Cursor. Use `/sgrep` or Cursor will automatically use it for semantic searches.
295
+
296
+ ### Codex CLI
297
+
298
+ ```bash
299
+ sgrep install-codex
300
+ ```
301
+
302
+ Integrates with OpenAI's Codex CLI, adding MCP server support and the sgrep skill.
303
+
304
+ ### Factory Droid
305
+
306
+ ```bash
307
+ sgrep install-droid
308
+ ```
309
+
310
+ Installs hooks and skills for Factory Droid with automatic file watching on session start.
311
+
312
+ ### OpenCode
313
+
314
+ ```bash
315
+ sgrep install-opencode
316
+ ```
317
+
318
+ Adds the sgrep tool to the OpenCode agent with MCP configuration.
319
+
320
+ ### Uninstalling
321
+
322
+ To uninstall from any agent, use the corresponding uninstall command:
323
+ ```bash
324
+ sgrep uninstall-claude-code
325
+ sgrep uninstall-cursor
326
+ sgrep uninstall-codex
327
+ sgrep uninstall-droid
328
+ sgrep uninstall-opencode
329
+ ```
330
+
331
+ ## Troubleshooting
332
+
333
+ ### "Authentication Error"
334
+
335
+ Make sure you've logged in:
336
+ ```bash
337
+ auggie login
338
+ ```
339
+
340
+ ### "Directory does not exist"
341
+
342
+ Check the path you're providing:
343
+ ```bash
344
+ # Use absolute or relative path
345
+ sgrep "query" /absolute/path
346
+ sgrep "query" ./relative/path
347
+ ```
348
+
349
+ ### Slow first search
350
+
351
+ The first search indexes the codebase, which can take a moment for large projects. Subsequent searches reuse the index.
352
+
353
+ ### Debug mode
354
+
355
+ Use `--debug` to see what's happening:
356
+ ```bash
357
+ sgrep --debug "your query"
358
+ ```
359
+
360
+ ### Claude Code hooks not working
361
+
362
+ 1. **Check the plugin is installed:**
363
+ ```bash
364
+ # Look for sgrep in Claude Code plugins
365
+ cat ~/.claude/settings.json | grep -A5 "plugins"
366
+ ```
367
+
368
+ 2. **Check the cache has the latest version:**
369
+ ```bash
370
+ # Windows - clear the plugin cache and reinstall
371
+ Remove-Item -Recurse -Force "$env:USERPROFILE\.claude\plugins\cache\sgrep"
372
+ sgrep uninstall-claude-code
373
+ sgrep install-claude-code
374
+ ```
375
+
376
+ 3. **Enable debug logging:**
377
+ ```bash
378
+ # Set environment variable before starting Claude Code
379
+ set SGREP_DEBUG=1 # Windows
380
+ export SGREP_DEBUG=1 # Linux/macOS
381
+ ```
382
+
383
+ 4. **Check the debug logs:**
384
+ - Windows: `%TEMP%\sgrep-watch.log`, `%TEMP%\sgrep-enhance.log`
385
+ - Linux/macOS: `/tmp/sgrep-watch.log`, `/tmp/sgrep-enhance.log`
386
+
387
+ ### Watch process not starting
388
+
389
+ If the background watch process isn't starting on Claude Code session start:
390
+
391
+ 1. **Check sgrep is in PATH:**
392
+ ```bash
393
+ where sgrep # Windows
394
+ which sgrep # Linux/macOS
395
+ ```
396
+
397
+ 2. **Try running watch manually:**
398
+ ```bash
399
+ sgrep watch --debug
400
+ ```
401
+
402
+ 3. **Check for existing PID files:**
403
+ ```bash
404
+ # Windows
405
+ dir %TEMP%\sgrep-watch-pid-*
406
+
407
+ # Linux/macOS
408
+ ls /tmp/sgrep-watch-pid-*
409
+ ```
410
+
411
+ ## License
412
+
413
+ MIT
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
3
+ "name": "sgrep",
4
+ "owner": {
5
+ "name": "pimzino",
6
+ "email": "pimzino@users.noreply.github.com"
7
+ },
8
+ "plugins": [
9
+ {
10
+ "name": "sgrep",
11
+ "source": "./plugins/sgrep",
12
+ "description": "Semantic grep - search codebases by meaning using AI powered by Augment SDK",
13
+ "version": "1.0.0",
14
+ "author": {
15
+ "name": "pimzino"
16
+ },
17
+ "skills": ["./skills/sgrep"]
18
+ }
19
+ ]
20
+ }
@@ -0,0 +1,11 @@
1
+ export interface AskOptions {
2
+ dir?: string;
3
+ json?: boolean;
4
+ noColor?: boolean;
5
+ debug?: boolean;
6
+ }
7
+ /**
8
+ * Execute the ask command.
9
+ */
10
+ export declare function askCommand(question: string, pathArg: string | undefined, options: AskOptions): Promise<void>;
11
+ //# sourceMappingURL=ask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../../src/commands/ask.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CA2Df"}
@@ -0,0 +1,65 @@
1
+ import * as path from "path";
2
+ import * as fs from "fs";
3
+ import { ask as askCodebase, closeContext } from "../utils/context.js";
4
+ import { printAnswer, printError, debug, initOutput } from "../utils/output.js";
5
+ import { loadConfig, mergeWithCliOptions } from "../utils/config.js";
6
+ /**
7
+ * Execute the ask command.
8
+ */
9
+ export async function askCommand(question, pathArg, options) {
10
+ // Load and merge config
11
+ const baseConfig = loadConfig();
12
+ const config = mergeWithCliOptions(baseConfig, options);
13
+ // Initialize output with final options
14
+ initOutput({
15
+ noColor: config.noColor,
16
+ json: config.outputFormat === "json",
17
+ debug: config.debug,
18
+ });
19
+ debug(`Question: ${question}`);
20
+ debug(`Options: ${JSON.stringify(options)}`);
21
+ debug(`Config: ${JSON.stringify(config)}`);
22
+ // Determine directory to search
23
+ let directory;
24
+ if (pathArg) {
25
+ directory = path.resolve(pathArg);
26
+ }
27
+ else if (config.defaultDir) {
28
+ directory = path.resolve(config.defaultDir);
29
+ }
30
+ else {
31
+ directory = process.cwd();
32
+ }
33
+ debug(`Directory: ${directory}`);
34
+ // Validate directory
35
+ if (!fs.existsSync(directory)) {
36
+ printError(`Directory does not exist: ${directory}`);
37
+ process.exit(1);
38
+ }
39
+ if (!fs.statSync(directory).isDirectory()) {
40
+ printError(`Path is not a directory: ${directory}`);
41
+ process.exit(1);
42
+ }
43
+ try {
44
+ const answer = await askCodebase(directory, question);
45
+ if (!answer || answer.trim() === "") {
46
+ if (config.outputFormat === "json") {
47
+ console.log(JSON.stringify({ type: "answer", answer: "", message: "No answer available" }, null, 2));
48
+ }
49
+ else {
50
+ console.log("Unable to answer the question based on the codebase.");
51
+ }
52
+ return;
53
+ }
54
+ printAnswer(answer);
55
+ }
56
+ catch (error) {
57
+ const errorMessage = error instanceof Error ? error.message : String(error);
58
+ printError(errorMessage);
59
+ process.exit(1);
60
+ }
61
+ finally {
62
+ await closeContext();
63
+ }
64
+ }
65
+ //# sourceMappingURL=ask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask.js","sourceRoot":"","sources":["../../src/commands/ask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAoB,MAAM,oBAAoB,CAAC;AASvF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,QAAgB,EAChB,OAA2B,EAC3B,OAAmB;IAEnB,wBAAwB;IACxB,MAAM,UAAU,GAAG,UAAU,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,mBAAmB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAExD,uCAAuC;IACvC,UAAU,CAAC;QACT,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,IAAI,EAAE,MAAM,CAAC,YAAY,KAAK,MAAM;QACpC,KAAK,EAAE,MAAM,CA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,CAAC;gBACnC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACvG,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;YACtE,CAAC;YACD,OAAO;QACT,CAAC;QAED,WAAW,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5E,UAAU,CAAC,YAAY,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,MAAM,YAAY,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ export interface EnhanceOptions {
2
+ dir?: string;
3
+ json?: boolean;
4
+ noColor?: boolean;
5
+ debug?: boolean;
6
+ }
7
+ export interface EnhanceResult {
8
+ original: string;
9
+ enhanced: string;
10
+ }
11
+ /**
12
+ * Execute the enhance command.
13
+ * Takes a prompt and enhances it using codebase context.
14
+ */
15
+ export declare function enhanceCommand(prompt: string, pathArg: string | undefined, options: EnhanceOptions): Promise<void>;
16
+ //# sourceMappingURL=enhance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enhance.d.ts","sourceRoot":"","sources":["../../src/commands/enhance.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,IAAI,CAAC,CAoGf"}
@@ -0,0 +1,107 @@
1
+ import * as path from "path";
2
+ import * as fs from "fs";
3
+ import chalk from "chalk";
4
+ import { getContext, closeContext } from "../utils/context.js";
5
+ import { printError, debug, initOutput } from "../utils/output.js";
6
+ import { loadConfig, mergeWithCliOptions } from "../utils/config.js";
7
+ import { parseEnhancedPrompt, buildEnhancementInstruction } from "../utils/prompt-parser.js";
8
+ /**
9
+ * Execute the enhance command.
10
+ * Takes a prompt and enhances it using codebase context.
11
+ */
12
+ export async function enhanceCommand(prompt, pathArg, options) {
13
+ // Load and merge config
14
+ const baseConfig = loadConfig();
15
+ const config = mergeWithCliOptions(baseConfig, options);
16
+ const useJson = config.outputFormat === "json";
17
+ const useColor = !config.noColor;
18
+ // Initialize output with final options
19
+ initOutput({
20
+ noColor: config.noColor,
21
+ json: useJson,
22
+ debug: config.debug,
23
+ });
24
+ debug(`Prompt: ${prompt}`);
25
+ debug(`Options: ${JSON.stringify(options)}`);
26
+ debug(`Config: ${JSON.stringify(config)}`);
27
+ // Determine directory to use for context
28
+ let directory;
29
+ if (pathArg) {
30
+ directory = path.resolve(pathArg);
31
+ }
32
+ else if (config.defaultDir) {
33
+ directory = path.resolve(config.defaultDir);
34
+ }
35
+ else {
36
+ directory = process.cwd();
37
+ }
38
+ debug(`Directory: ${directory}`);
39
+ // Validate directory
40
+ if (!fs.existsSync(directory)) {
41
+ printError(`Directory does not exist: ${directory}`);
42
+ process.exit(1);
43
+ }
44
+ if (!fs.statSync(directory).isDirectory()) {
45
+ printError(`Path is not a directory: ${directory}`);
46
+ process.exit(1);
47
+ }
48
+ try {
49
+ // Get context
50
+ const context = await getContext(directory);
51
+ // Build the enhancement instruction
52
+ const enhancementInstruction = buildEnhancementInstruction(prompt);
53
+ debug(`Enhancement instruction built`);
54
+ // Use searchAndAsk to enhance the prompt
55
+ // The original prompt is used as the search query to find relevant code
56
+ const response = await context.searchAndAsk(prompt, enhancementInstruction);
57
+ debug(`Response received (${response.length} characters)`);
58
+ // Parse the enhanced prompt from the response
59
+ const enhanced = parseEnhancedPrompt(response);
60
+ if (!enhanced) {
61
+ // If parsing failed, show the raw response for debugging
62
+ if (useJson) {
63
+ console.log(JSON.stringify({
64
+ type: "enhance",
65
+ original: prompt,
66
+ enhanced: null,
67
+ error: "Failed to parse enhanced prompt from response",
68
+ rawResponse: response,
69
+ }, null, 2));
70
+ }
71
+ else {
72
+ printError("Failed to parse enhanced prompt from AI response");
73
+ console.log("");
74
+ console.log(useColor ? chalk.gray("Raw response:") : "Raw response:");
75
+ console.log(response);
76
+ }
77
+ process.exit(1);
78
+ }
79
+ // Output the result
80
+ if (useJson) {
81
+ const result = {
82
+ original: prompt,
83
+ enhanced: enhanced,
84
+ };
85
+ console.log(JSON.stringify(result, null, 2));
86
+ }
87
+ else {
88
+ // Pretty output
89
+ console.log("");
90
+ console.log(useColor ? chalk.cyan("Original:") : "Original:");
91
+ console.log(useColor ? chalk.gray(prompt) : prompt);
92
+ console.log("");
93
+ console.log(useColor ? chalk.cyan("Enhanced:") : "Enhanced:");
94
+ console.log(enhanced);
95
+ console.log("");
96
+ }
97
+ }
98
+ catch (error) {
99
+ const errorMessage = error instanceof Error ? error.message : String(error);
100
+ printError(errorMessage);
101
+ process.exit(1);
102
+ }
103
+ finally {
104
+ await closeContext();
105
+ }
106
+ }
107
+ //# sourceMappingURL=enhance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enhance.js","sourceRoot":"","sources":["../../src/commands/enhance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO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C;YAC9D,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5E,UAAU,CAAC,YAAY,CAAC,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;YAAS,CAAC;QACT,MAAM,YAAY,EAAE,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ export interface SearchOptions {
2
+ dir?: string;
3
+ maxResults?: number;
4
+ json?: boolean;
5
+ noColor?: boolean;
6
+ debug?: boolean;
7
+ }
8
+ /**
9
+ * Execute the search command.
10
+ */
11
+ export declare function searchCommand(query: string, pathArg: string | undefined, options: SearchOptions): Promise<void>;
12
+ //# sourceMappingURL=search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CA2Df"}