Skip to content

Commit 7f7fbc2

Browse files
committed
feat(sdk): enable code_search and run_file_change_hooks by adding @vscode/ripgrep; synchronize lockfiles for consistent tooling orchestration.
🤖 Generated with Codebuff Co-Authored-By: Codebuff<noreply@codebuff.com>
1 parent 3ca474a commit 7f7fbc2

4 files changed

Lines changed: 105 additions & 5 deletions

File tree

bun.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"diff": "8.0.2",
5959
"zod": "^4.0.0",
6060
"@vscode/tree-sitter-wasm": "0.1.4",
61-
"web-tree-sitter": "0.25.6"
61+
"web-tree-sitter": "0.25.6",
62+
"@vscode/ripgrep": "^1.15.9"
6263
},
6364
"devDependencies": {
6465
"@types/diff": "8.0.0",

sdk/src/tools/code-search.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { spawn } from 'child_process'
2+
import * as path from 'path'
3+
4+
import { rgPath } from '@vscode/ripgrep'
5+
6+
import type { CodebuffToolOutput } from '../../../common/src/tools/list'
7+
8+
export function codeSearch({
9+
pattern,
10+
flags,
11+
cwd,
12+
}: {
13+
pattern: string
14+
flags?: string
15+
cwd: string
16+
}): Promise<CodebuffToolOutput<'code_search'>> {
17+
18+
return new Promise((resolve) => {
19+
let stdout = ''
20+
let stderr = ''
21+
22+
const flagsArray = (flags || '').split(' ').filter(Boolean)
23+
let searchCwd = cwd
24+
25+
// Note: In the SDK, we don't have access to a project root concept,
26+
// so we'll use the provided cwd directly
27+
const args = [...flagsArray, pattern, '.']
28+
29+
const childProcess = spawn(rgPath, args, {
30+
cwd: searchCwd,
31+
stdio: ['ignore', 'pipe', 'pipe'],
32+
})
33+
34+
childProcess.stdout.on('data', (data) => {
35+
stdout += data.toString()
36+
})
37+
38+
childProcess.stderr.on('data', (data) => {
39+
stderr += data.toString()
40+
})
41+
42+
childProcess.on('close', (code) => {
43+
// Truncate output to prevent memory issues
44+
const maxLength = 10000
45+
const truncatedStdout = stdout.length > maxLength
46+
? stdout.substring(0, maxLength) + '\n\n[Output truncated]'
47+
: stdout
48+
49+
const maxErrorLength = 1000
50+
const truncatedStderr = stderr.length > maxErrorLength
51+
? stderr.substring(0, maxErrorLength) + '\n\n[Error output truncated]'
52+
: stderr
53+
54+
const result = {
55+
stdout: truncatedStdout,
56+
...(truncatedStderr && { stderr: truncatedStderr }),
57+
...(code !== null && { exitCode: code }),
58+
message: 'Code search completed',
59+
}
60+
61+
resolve([
62+
{
63+
type: 'json',
64+
value: result,
65+
},
66+
])
67+
})
68+
69+
childProcess.on('error', (error) => {
70+
resolve([
71+
{
72+
type: 'json',
73+
value: {
74+
errorMessage: `Failed to execute ripgrep: ${error.message}. Make sure ripgrep is installed and available in PATH.`,
75+
},
76+
},
77+
])
78+
})
79+
})
80+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { CodebuffToolOutput } from '../../../common/src/tools/list'
2+
3+
export function runFileChangeHooks({
4+
files,
5+
}: {
6+
files: string[]
7+
}): Promise<CodebuffToolOutput<'run_file_change_hooks'>> {
8+
// In the SDK, we don't have access to codebuff.json configuration
9+
// or the hook running infrastructure, so this is a no-op
10+
11+
return Promise.resolve([
12+
{
13+
type: 'json',
14+
value: [
15+
{
16+
errorMessage: 'No file change hooks were triggered for the specified files. File change hooks are not supported in the SDK environment.',
17+
},
18+
],
19+
},
20+
])
21+
}

0 commit comments

Comments
 (0)