Skip to content

Commit c5c9683

Browse files
authored
fix: Improve CLI tools with better error handling and options (#122)
- ast-grep: Log background init errors instead of silently swallowing them - grep: Add caseSensitive, wholeWord, fixedStrings options to tool definition These fixes improve debuggability and expose more functionality to users.
1 parent 404d8c0 commit c5c9683

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/tools/ast-grep/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ export async function getAstGrepPath(): Promise<string | null> {
5656
export function startBackgroundInit(): void {
5757
if (!initPromise) {
5858
initPromise = getAstGrepPath();
59-
initPromise.catch(() => {});
59+
initPromise.catch((err) => {
60+
console.warn('[ast-grep] Background initialization failed:', err?.message ?? err);
61+
});
6062
}
6163
}
6264

src/tools/grep/tools.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const grep: ToolDefinition = tool({
77
'Fast content search tool with safety limits (60s timeout, 10MB output). ' +
88
'Searches file contents using regular expressions. ' +
99
'Supports full regex syntax (eg. "log.*Error", "function\\s+\\w+", etc.). ' +
10-
'Filter files by pattern with the include parameter (eg. "*.js", "*.{ts,tsx}"). ' +
10+
'Filter files by pattern with the include parameter (e.g. "*.js", "*.{ts,tsx}"). ' +
1111
'Returns file paths with matches sorted by modification time.',
1212
args: {
1313
pattern: tool.schema
@@ -25,6 +25,21 @@ export const grep: ToolDefinition = tool({
2525
.describe(
2626
'The directory to search in. Defaults to the current working directory.',
2727
),
28+
caseSensitive: tool.schema
29+
.boolean()
30+
.optional()
31+
.default(false)
32+
.describe('Perform case-sensitive search (default: false)'),
33+
wholeWord: tool.schema
34+
.boolean()
35+
.optional()
36+
.default(false)
37+
.describe('Match whole words only (default: false)'),
38+
fixedStrings: tool.schema
39+
.boolean()
40+
.optional()
41+
.default(false)
42+
.describe('Treat pattern as literal string (default: false)'),
2843
},
2944
execute: async (args) => {
3045
try {
@@ -36,6 +51,9 @@ export const grep: ToolDefinition = tool({
3651
paths,
3752
globs,
3853
context: 0,
54+
caseSensitive: args.caseSensitive ?? false,
55+
wholeWord: args.wholeWord ?? false,
56+
fixedStrings: args.fixedStrings ?? false,
3957
});
4058

4159
return formatGrepResult(result);

0 commit comments

Comments
 (0)