Code Indexing Support for WSO2 Integrator Copilot#2263
Conversation
|
@coderabbitai can you review grep.ts file |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@workspaces/ballerina/ballerina-extension/src/features/ai/agent/tools/grep.ts`:
- Around line 212-214: The args.push call in grep.ts currently contains a stray
'--glob' token (args.push('--glob', '!.git/**', '--glob', '--glob',
'!target/**')) which causes the second '--glob' to be used as a glob value and
pushes '!target/**' into ripgrep’s positional PATTERN; remove the extra '--glob'
so each '--glob' is followed by its pattern (i.e., ensure the call passes
'--glob', '!.git/**', '--glob', '!target/**'), then run the grep-related tests
or a quick ripgrep invocation to confirm the target exclusion works as expected.
- Around line 29-39: The grep tool currently treats ripgrep launch failures as
“No matches found”; update the code that calls spawnSync(getRgExecutable(), ...)
to explicitly check for process launch errors (proc.error !== undefined) and
null/undefined proc.status and treat them as failures: when proc.error is set or
proc.status is null/undefined return success: false with an error message
including proc.error or a descriptive message, otherwise keep the existing
checks for status === 1 or empty stdout; reference the spawnSync call and
variables named proc, proc.status and proc.error and the getRgExecutable helper
to locate where to add these additional error branches.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 37af476d-279c-4879-b8df-1f24d4a0fcbb
📒 Files selected for processing (3)
workspaces/ballerina/ballerina-extension/package.jsonworkspaces/ballerina/ballerina-extension/src/features/ai/agent/tools/glob.tsworkspaces/ballerina/ballerina-extension/src/features/ai/agent/tools/grep.ts
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 13941
Review of
|
|
@coderabbitai can you review grep.ts, glob.ts and rg-utils.ts |
|
Tip For best results, initiate chat on the files or code changes.
|
| Issue | File | Severity | Status |
|---|---|---|---|
getRgExecutable() not memoized |
rg-utils.ts |
New | |
which Unix-only |
rg-utils.ts |
🔧 Minor | New |
| Log count off-by-one | grep.ts |
🐛 Minor | New |
| No regex pre-validation | grep.ts |
Carry-over | |
node_modules not excluded |
grep.ts |
🔧 Minor | Carry-over |
spawnSync blocks event loop |
grep.ts, glob.ts |
Carry-over | |
| Grammar nit in description | glob.ts |
🔧 Nit | New |
Duplicate --glob bug |
grep.ts |
🐛 Fixed | ✅ |
| False-positive path traversal | glob.ts |
🐛 Fixed | ✅ |
Custom walkDir / glob regex |
glob.ts |
✅ | |
MAX_RESULTS cap |
glob.ts |
✅ | |
| Two-root symlink protection | rg-utils.ts |
✅ | ✅ |
|
Tip For best results, initiate chat on the files or code changes.
|
| File | Status | Key remaining items |
|---|---|---|
rg-utils.ts |
✅ Clean extraction | getRgExecutable Windows compat + silent fallback |
glob.ts |
✅ Major improvement | mtime sort regression; spawnSync async follow-up |
grep.ts |
✅ Double-glob bug fixed | Regex pre-validation; log count nit; spawnSync async follow-up |
7dac3ed to
c8a63a9
Compare
|
|
||
| function fail(message: string, error: string): GlobResult { | ||
| const result: GlobResult = { success: false, message, error }; | ||
| eventHandler({ type: "tool_result", toolName: GLOB_TOOL_NAME, toolOutput: result }); |
There was a problem hiding this comment.
Do we have new ui elements to render these events
| eventHandler({ | ||
| type: "tool_call", |
| success: true, | ||
| message: `No files found matching pattern: "${pattern}"`, | ||
| }; | ||
| eventHandler({ type: "tool_result", toolName: GLOB_TOOL_NAME, toolOutput: result }); |
| message: `Found ${files.length} file(s) matching "${pattern}":\n${displayed.join("\n")}${truncationNote}`, | ||
| }; | ||
|
|
||
| eventHandler({ type: "tool_result", toolName: GLOB_TOOL_NAME, toolOutput: result }); |
|
|
||
| function fail(message: string, error: string): GrepResult { | ||
| const result: GrepResult = { success: false, message, error }; | ||
| eventHandler({ type: "tool_result", toolName: GREP_TOOL_NAME, toolOutput: result }); |
| eventHandler({ | ||
| type: "tool_call", |
| if (proc.status === RgExitCode.Error) { | ||
| const errMsg = (proc.stderr || "").trim(); | ||
| const result: GrepResult = { success: false, message: `ripgrep error: ${errMsg}`, error: errMsg }; | ||
| eventHandler({ type: "tool_result", toolName: GREP_TOOL_NAME, toolOutput: result }); |
There was a problem hiding this comment.
Ditto, Check other places too
| - When the user submits a query, you will receive either **Codebase High Level Summary** or **Complete Structure of the Codebase**. Identify which one you have received before proceeding. | ||
| - If you received Codebase High Level Summary, use it as a navigation map to locate the relevant components for the user query, in the codebase, but the actual source must be read separately when needed. | ||
| - Codebase High Level Summary lists, for each Ballerina file, all of its components (imports, configurables, variables, types, functions, services, listeners, classes) with their signatures and line ranges, but excludes implementation bodies, test files, and resource files. | ||
| - If you receive complete structure of the codebase, it contains the complete source of all .bal files (test and resource files excluded) provided directly in your context. |
There was a problem hiding this comment.
Test files were included i guess.
please verify
There was a problem hiding this comment.
No, we are not including the test files.
| FILE_WRITE_TOOL_NAME, | ||
| ].join( | ||
| ", " | ||
| )} tools. The complete existing source code will be provided in the <existing_code> section of the user prompt. |
There was a problem hiding this comment.
Do we have this <existing_code> section?
| if (!this.config.chatStorage) { | ||
| console.log('[AICommandExecutor] Chat storage not configured, skipping initialization'); | ||
| return; | ||
| } | ||
|
|
There was a problem hiding this comment.
The inner if (!this.config.chatStorage) is unreachable right?
| ); | ||
|
|
||
| // ================================== | ||
| // bal.md Generation for Agent Context |
|
|
||
| ### Local Connectors | ||
| - If the codebase structure shows connector modules in generated/moduleName, import using: import packageName.moduleName | ||
| - Generated connector files appear under a \`<generated_files>\` block in the codebase structure as path-only entries (e.g. \`<file path="generated/moduleName/client.bal"/>\`) — no source content is included. Use the \`${FILE_READ_TOOL_NAME}\` tool with the listed path to fetch the content when needed. |
There was a problem hiding this comment.
<generated_files> is invalid for codemap case right?
| const DEFAULT_GLOB_ARGS = [ | ||
| "--glob", "*.bal", | ||
| "--glob", "*.toml", | ||
| "--glob", "*.md", | ||
| "--glob", "*.json", | ||
| "--glob", "*.yaml", | ||
| "--glob", "*.yml", | ||
| "--glob", "*.sql", | ||
| ]; |
There was a problem hiding this comment.
i think it's better to mention the supported types to the agent. instead of silently ignores other type searches.
Maybe we can add a line to the tool description listing the file types we search by default, so the model knows.
| } | ||
|
|
||
| /** Paths and files always excluded from search */ | ||
| const EXCLUDE_GLOB_ARGS = ["--glob", "!.git/**", "--glob", "!target/**"]; |
There was a problem hiding this comment.
In the glob tool, we do not search within the files, and there is no need to ignore them since the tool returns file paths rather than file content.
There was a problem hiding this comment.
if we can better to avoid the path too.
optional :)
Purpose
$title
Resolves: https://github.com/wso2-enterprise/integration-engineering/issues/893
key Changes
Summary by CodeRabbit
New Features
AI / Evaluation
Tests