opencode-codebase-index 0.4.0 → 0.4.1
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.
- package/README.md +3 -1
- package/dist/index.cjs +47 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +47 -8
- package/dist/index.js.map +1 -1
- package/native/codebase-index-native.win32-x64-msvc.node +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -246,7 +246,8 @@ Zero-config by default (uses `auto` mode). Customize in `.opencode/codebase-inde
|
|
|
246
246
|
"semanticOnly": false,
|
|
247
247
|
"autoGc": true,
|
|
248
248
|
"gcIntervalDays": 7,
|
|
249
|
-
"gcOrphanThreshold": 100
|
|
249
|
+
"gcOrphanThreshold": 100,
|
|
250
|
+
"requireProjectMarker": true
|
|
250
251
|
},
|
|
251
252
|
"search": {
|
|
252
253
|
"maxResults": 20,
|
|
@@ -279,6 +280,7 @@ Zero-config by default (uses `auto` mode). Customize in `.opencode/codebase-inde
|
|
|
279
280
|
| `autoGc` | `true` | Automatically run garbage collection to remove orphaned embeddings/chunks |
|
|
280
281
|
| `gcIntervalDays` | `7` | Run GC on initialization if last GC was more than N days ago |
|
|
281
282
|
| `gcOrphanThreshold` | `100` | Run GC after indexing if orphan count exceeds this threshold |
|
|
283
|
+
| `requireProjectMarker` | `true` | Require a project marker (`.git`, `package.json`, etc.) to enable file watching and auto-indexing. Prevents accidentally indexing large directories like home. Set to `false` to index any directory. |
|
|
282
284
|
| **search** | | |
|
|
283
285
|
| `maxResults` | `20` | Maximum results to return |
|
|
284
286
|
| `minScore` | `0.1` | Minimum similarity score (0-1). Lower = more results |
|
package/dist/index.cjs
CHANGED
|
@@ -701,7 +701,8 @@ function getDefaultIndexingConfig() {
|
|
|
701
701
|
retryDelayMs: 1e3,
|
|
702
702
|
autoGc: true,
|
|
703
703
|
gcIntervalDays: 7,
|
|
704
|
-
gcOrphanThreshold: 100
|
|
704
|
+
gcOrphanThreshold: 100,
|
|
705
|
+
requireProjectMarker: true
|
|
705
706
|
};
|
|
706
707
|
}
|
|
707
708
|
function getDefaultSearchConfig() {
|
|
@@ -756,7 +757,8 @@ function parseConfig(raw) {
|
|
|
756
757
|
retryDelayMs: typeof rawIndexing.retryDelayMs === "number" ? rawIndexing.retryDelayMs : defaultIndexing.retryDelayMs,
|
|
757
758
|
autoGc: typeof rawIndexing.autoGc === "boolean" ? rawIndexing.autoGc : defaultIndexing.autoGc,
|
|
758
759
|
gcIntervalDays: typeof rawIndexing.gcIntervalDays === "number" ? Math.max(1, rawIndexing.gcIntervalDays) : defaultIndexing.gcIntervalDays,
|
|
759
|
-
gcOrphanThreshold: typeof rawIndexing.gcOrphanThreshold === "number" ? Math.max(0, rawIndexing.gcOrphanThreshold) : defaultIndexing.gcOrphanThreshold
|
|
760
|
+
gcOrphanThreshold: typeof rawIndexing.gcOrphanThreshold === "number" ? Math.max(0, rawIndexing.gcOrphanThreshold) : defaultIndexing.gcOrphanThreshold,
|
|
761
|
+
requireProjectMarker: typeof rawIndexing.requireProjectMarker === "boolean" ? rawIndexing.requireProjectMarker : defaultIndexing.requireProjectMarker
|
|
760
762
|
};
|
|
761
763
|
const rawSearch = input.search && typeof input.search === "object" ? input.search : {};
|
|
762
764
|
const search = {
|
|
@@ -2186,6 +2188,30 @@ var OllamaEmbeddingProvider = class {
|
|
|
2186
2188
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
2187
2189
|
var import_fs2 = require("fs");
|
|
2188
2190
|
var path2 = __toESM(require("path"), 1);
|
|
2191
|
+
var PROJECT_MARKERS = [
|
|
2192
|
+
".git",
|
|
2193
|
+
"package.json",
|
|
2194
|
+
"Cargo.toml",
|
|
2195
|
+
"go.mod",
|
|
2196
|
+
"pyproject.toml",
|
|
2197
|
+
"setup.py",
|
|
2198
|
+
"requirements.txt",
|
|
2199
|
+
"Gemfile",
|
|
2200
|
+
"composer.json",
|
|
2201
|
+
"pom.xml",
|
|
2202
|
+
"build.gradle",
|
|
2203
|
+
"CMakeLists.txt",
|
|
2204
|
+
"Makefile",
|
|
2205
|
+
".opencode"
|
|
2206
|
+
];
|
|
2207
|
+
function hasProjectMarker(projectRoot) {
|
|
2208
|
+
for (const marker of PROJECT_MARKERS) {
|
|
2209
|
+
if ((0, import_fs2.existsSync)(path2.join(projectRoot, marker))) {
|
|
2210
|
+
return true;
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
return false;
|
|
2214
|
+
}
|
|
2189
2215
|
function createIgnoreFilter(projectRoot) {
|
|
2190
2216
|
const ig = (0, import_ignore.default)();
|
|
2191
2217
|
const defaultIgnores = [
|
|
@@ -6107,6 +6133,13 @@ function createWatcherWithIndexer(indexer, projectRoot, config) {
|
|
|
6107
6133
|
// src/tools/index.ts
|
|
6108
6134
|
var import_plugin = require("@opencode-ai/plugin");
|
|
6109
6135
|
var z = import_plugin.tool.schema;
|
|
6136
|
+
var MAX_CONTENT_LINES = 30;
|
|
6137
|
+
function truncateContent(content) {
|
|
6138
|
+
const lines = content.split("\n");
|
|
6139
|
+
if (lines.length <= MAX_CONTENT_LINES) return content;
|
|
6140
|
+
return lines.slice(0, MAX_CONTENT_LINES).join("\n") + `
|
|
6141
|
+
// ... (${lines.length - MAX_CONTENT_LINES} more lines)`;
|
|
6142
|
+
}
|
|
6110
6143
|
var sharedIndexer = null;
|
|
6111
6144
|
function initializeTools(projectRoot, config) {
|
|
6112
6145
|
sharedIndexer = new Indexer(projectRoot, config);
|
|
@@ -6121,7 +6154,7 @@ var codebase_search = (0, import_plugin.tool)({
|
|
|
6121
6154
|
description: "Search codebase by MEANING, not keywords. Returns full code content. Use when you need to see actual implementation. For just finding WHERE code is (saves ~90% tokens), use codebase_peek instead. For known identifiers like 'validateToken', use grep - it's faster.",
|
|
6122
6155
|
args: {
|
|
6123
6156
|
query: z.string().describe("Natural language description of what code you're looking for. Describe behavior, not syntax."),
|
|
6124
|
-
limit: z.number().optional().default(
|
|
6157
|
+
limit: z.number().optional().default(5).describe("Maximum number of results to return"),
|
|
6125
6158
|
fileType: z.string().optional().describe("Filter by file extension (e.g., 'ts', 'py', 'rs')"),
|
|
6126
6159
|
directory: z.string().optional().describe("Filter by directory path (e.g., 'src/utils', 'lib')"),
|
|
6127
6160
|
chunkType: z.enum(["function", "class", "method", "interface", "type", "enum", "struct", "impl", "trait", "module", "other"]).optional().describe("Filter by code chunk type"),
|
|
@@ -6129,7 +6162,7 @@ var codebase_search = (0, import_plugin.tool)({
|
|
|
6129
6162
|
},
|
|
6130
6163
|
async execute(args) {
|
|
6131
6164
|
const indexer = getIndexer();
|
|
6132
|
-
const results = await indexer.search(args.query, args.limit ??
|
|
6165
|
+
const results = await indexer.search(args.query, args.limit ?? 5, {
|
|
6133
6166
|
fileType: args.fileType,
|
|
6134
6167
|
directory: args.directory,
|
|
6135
6168
|
chunkType: args.chunkType,
|
|
@@ -6142,7 +6175,7 @@ var codebase_search = (0, import_plugin.tool)({
|
|
|
6142
6175
|
const header = r.name ? `[${idx + 1}] ${r.chunkType} "${r.name}" in ${r.filePath}:${r.startLine}-${r.endLine}` : `[${idx + 1}] ${r.chunkType} in ${r.filePath}:${r.startLine}-${r.endLine}`;
|
|
6143
6176
|
return `${header} (score: ${r.score.toFixed(2)})
|
|
6144
6177
|
\`\`\`
|
|
6145
|
-
${r.content}
|
|
6178
|
+
${truncateContent(r.content)}
|
|
6146
6179
|
\`\`\``;
|
|
6147
6180
|
});
|
|
6148
6181
|
return `Found ${results.length} results for "${args.query}":
|
|
@@ -6318,7 +6351,7 @@ var find_similar = (0, import_plugin.tool)({
|
|
|
6318
6351
|
const header = r.name ? `[${idx + 1}] ${r.chunkType} "${r.name}" in ${r.filePath}:${r.startLine}-${r.endLine}` : `[${idx + 1}] ${r.chunkType} in ${r.filePath}:${r.startLine}-${r.endLine}`;
|
|
6319
6352
|
return `${header} (similarity: ${(r.score * 100).toFixed(1)}%)
|
|
6320
6353
|
\`\`\`
|
|
6321
|
-
${r.content}
|
|
6354
|
+
${truncateContent(r.content)}
|
|
6322
6355
|
\`\`\``;
|
|
6323
6356
|
});
|
|
6324
6357
|
return `Found ${results.length} similar code blocks:
|
|
@@ -6496,14 +6529,20 @@ var plugin = async ({ directory }) => {
|
|
|
6496
6529
|
const config = parseConfig(rawConfig);
|
|
6497
6530
|
initializeTools(projectRoot, config);
|
|
6498
6531
|
const indexer = new Indexer(projectRoot, config);
|
|
6499
|
-
|
|
6532
|
+
const isValidProject = !config.indexing.requireProjectMarker || hasProjectMarker(projectRoot);
|
|
6533
|
+
if (!isValidProject) {
|
|
6534
|
+
console.warn(
|
|
6535
|
+
`[codebase-index] Skipping file watching and auto-indexing: no project marker found in "${projectRoot}". Set "indexing.requireProjectMarker": false in config to override.`
|
|
6536
|
+
);
|
|
6537
|
+
}
|
|
6538
|
+
if (config.indexing.autoIndex && isValidProject) {
|
|
6500
6539
|
indexer.initialize().then(() => {
|
|
6501
6540
|
indexer.index().catch(() => {
|
|
6502
6541
|
});
|
|
6503
6542
|
}).catch(() => {
|
|
6504
6543
|
});
|
|
6505
6544
|
}
|
|
6506
|
-
if (config.indexing.watchFiles) {
|
|
6545
|
+
if (config.indexing.watchFiles && isValidProject) {
|
|
6507
6546
|
createWatcherWithIndexer(indexer, projectRoot, config);
|
|
6508
6547
|
}
|
|
6509
6548
|
return {
|