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/dist/index.js CHANGED
@@ -696,7 +696,8 @@ function getDefaultIndexingConfig() {
696
696
  retryDelayMs: 1e3,
697
697
  autoGc: true,
698
698
  gcIntervalDays: 7,
699
- gcOrphanThreshold: 100
699
+ gcOrphanThreshold: 100,
700
+ requireProjectMarker: true
700
701
  };
701
702
  }
702
703
  function getDefaultSearchConfig() {
@@ -751,7 +752,8 @@ function parseConfig(raw) {
751
752
  retryDelayMs: typeof rawIndexing.retryDelayMs === "number" ? rawIndexing.retryDelayMs : defaultIndexing.retryDelayMs,
752
753
  autoGc: typeof rawIndexing.autoGc === "boolean" ? rawIndexing.autoGc : defaultIndexing.autoGc,
753
754
  gcIntervalDays: typeof rawIndexing.gcIntervalDays === "number" ? Math.max(1, rawIndexing.gcIntervalDays) : defaultIndexing.gcIntervalDays,
754
- gcOrphanThreshold: typeof rawIndexing.gcOrphanThreshold === "number" ? Math.max(0, rawIndexing.gcOrphanThreshold) : defaultIndexing.gcOrphanThreshold
755
+ gcOrphanThreshold: typeof rawIndexing.gcOrphanThreshold === "number" ? Math.max(0, rawIndexing.gcOrphanThreshold) : defaultIndexing.gcOrphanThreshold,
756
+ requireProjectMarker: typeof rawIndexing.requireProjectMarker === "boolean" ? rawIndexing.requireProjectMarker : defaultIndexing.requireProjectMarker
755
757
  };
756
758
  const rawSearch = input.search && typeof input.search === "object" ? input.search : {};
757
759
  const search = {
@@ -2181,6 +2183,30 @@ var OllamaEmbeddingProvider = class {
2181
2183
  var import_ignore = __toESM(require_ignore(), 1);
2182
2184
  import { existsSync as existsSync2, readFileSync as readFileSync2, promises as fsPromises } from "fs";
2183
2185
  import * as path2 from "path";
2186
+ var PROJECT_MARKERS = [
2187
+ ".git",
2188
+ "package.json",
2189
+ "Cargo.toml",
2190
+ "go.mod",
2191
+ "pyproject.toml",
2192
+ "setup.py",
2193
+ "requirements.txt",
2194
+ "Gemfile",
2195
+ "composer.json",
2196
+ "pom.xml",
2197
+ "build.gradle",
2198
+ "CMakeLists.txt",
2199
+ "Makefile",
2200
+ ".opencode"
2201
+ ];
2202
+ function hasProjectMarker(projectRoot) {
2203
+ for (const marker of PROJECT_MARKERS) {
2204
+ if (existsSync2(path2.join(projectRoot, marker))) {
2205
+ return true;
2206
+ }
2207
+ }
2208
+ return false;
2209
+ }
2184
2210
  function createIgnoreFilter(projectRoot) {
2185
2211
  const ig = (0, import_ignore.default)();
2186
2212
  const defaultIgnores = [
@@ -6101,6 +6127,13 @@ function createWatcherWithIndexer(indexer, projectRoot, config) {
6101
6127
  // src/tools/index.ts
6102
6128
  import { tool } from "@opencode-ai/plugin";
6103
6129
  var z = tool.schema;
6130
+ var MAX_CONTENT_LINES = 30;
6131
+ function truncateContent(content) {
6132
+ const lines = content.split("\n");
6133
+ if (lines.length <= MAX_CONTENT_LINES) return content;
6134
+ return lines.slice(0, MAX_CONTENT_LINES).join("\n") + `
6135
+ // ... (${lines.length - MAX_CONTENT_LINES} more lines)`;
6136
+ }
6104
6137
  var sharedIndexer = null;
6105
6138
  function initializeTools(projectRoot, config) {
6106
6139
  sharedIndexer = new Indexer(projectRoot, config);
@@ -6115,7 +6148,7 @@ var codebase_search = tool({
6115
6148
  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.",
6116
6149
  args: {
6117
6150
  query: z.string().describe("Natural language description of what code you're looking for. Describe behavior, not syntax."),
6118
- limit: z.number().optional().default(10).describe("Maximum number of results to return"),
6151
+ limit: z.number().optional().default(5).describe("Maximum number of results to return"),
6119
6152
  fileType: z.string().optional().describe("Filter by file extension (e.g., 'ts', 'py', 'rs')"),
6120
6153
  directory: z.string().optional().describe("Filter by directory path (e.g., 'src/utils', 'lib')"),
6121
6154
  chunkType: z.enum(["function", "class", "method", "interface", "type", "enum", "struct", "impl", "trait", "module", "other"]).optional().describe("Filter by code chunk type"),
@@ -6123,7 +6156,7 @@ var codebase_search = tool({
6123
6156
  },
6124
6157
  async execute(args) {
6125
6158
  const indexer = getIndexer();
6126
- const results = await indexer.search(args.query, args.limit ?? 10, {
6159
+ const results = await indexer.search(args.query, args.limit ?? 5, {
6127
6160
  fileType: args.fileType,
6128
6161
  directory: args.directory,
6129
6162
  chunkType: args.chunkType,
@@ -6136,7 +6169,7 @@ var codebase_search = tool({
6136
6169
  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}`;
6137
6170
  return `${header} (score: ${r.score.toFixed(2)})
6138
6171
  \`\`\`
6139
- ${r.content}
6172
+ ${truncateContent(r.content)}
6140
6173
  \`\`\``;
6141
6174
  });
6142
6175
  return `Found ${results.length} results for "${args.query}":
@@ -6312,7 +6345,7 @@ var find_similar = tool({
6312
6345
  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}`;
6313
6346
  return `${header} (similarity: ${(r.score * 100).toFixed(1)}%)
6314
6347
  \`\`\`
6315
- ${r.content}
6348
+ ${truncateContent(r.content)}
6316
6349
  \`\`\``;
6317
6350
  });
6318
6351
  return `Found ${results.length} similar code blocks:
@@ -6489,14 +6522,20 @@ var plugin = async ({ directory }) => {
6489
6522
  const config = parseConfig(rawConfig);
6490
6523
  initializeTools(projectRoot, config);
6491
6524
  const indexer = new Indexer(projectRoot, config);
6492
- if (config.indexing.autoIndex) {
6525
+ const isValidProject = !config.indexing.requireProjectMarker || hasProjectMarker(projectRoot);
6526
+ if (!isValidProject) {
6527
+ console.warn(
6528
+ `[codebase-index] Skipping file watching and auto-indexing: no project marker found in "${projectRoot}". Set "indexing.requireProjectMarker": false in config to override.`
6529
+ );
6530
+ }
6531
+ if (config.indexing.autoIndex && isValidProject) {
6493
6532
  indexer.initialize().then(() => {
6494
6533
  indexer.index().catch(() => {
6495
6534
  });
6496
6535
  }).catch(() => {
6497
6536
  });
6498
6537
  }
6499
- if (config.indexing.watchFiles) {
6538
+ if (config.indexing.watchFiles && isValidProject) {
6500
6539
  createWatcherWithIndexer(indexer, projectRoot, config);
6501
6540
  }
6502
6541
  return {