// Basic pattern search
const results = await repo.grep({
query: { pattern: "TODO" },
});
console.log(`Found ${results.matches.length} files with matches`);
results.matches.forEach((match) => {
console.log(`${match.path}:`);
match.lines.forEach((line) => {
if (line.type === "match") {
console.log(` ${line.lineNumber}: ${line.text}`);
}
});
});
// Advanced search with filtering and context
const advancedResults = await repo.grep({
ref: "main",
query: {
pattern: "function\\s+\\w+Error",
caseSensitive: true,
},
paths: ["src/"],
fileFilters: {
includeGlobs: ["**/*.js", "**/*.ts"],
excludeGlobs: ["**/node_modules/**", "**/*.test.js"],
},
context: { before: 2, after: 2 },
limits: { maxLines: 200, maxMatchesPerFile: 10 },
pagination: { limit: 50 },
});
// Handle pagination
let cursor = advancedResults.nextCursor;
while (cursor && advancedResults.hasMore) {
const moreResults = await repo.grep({
query: { pattern: "TODO" },
pagination: { cursor, limit: 50 },
});
console.log("Next page:", moreResults.matches);
cursor = moreResults.nextCursor;
}