opencode-codebase-index 0.10.0 → 0.11.0

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/cli.cjs CHANGED
@@ -8,7 +8,11 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
8
8
  var __getProtoOf = Object.getPrototypeOf;
9
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
10
  var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ try {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ } catch (e) {
14
+ throw mod = 0, e;
15
+ }
12
16
  };
13
17
  var __copyProps = (to, from, except, desc) => {
14
18
  if (from && typeof from === "object" || typeof from === "function") {
@@ -2499,6 +2503,8 @@ var BaseEmbeddingProvider = class {
2499
2503
  this.credentials = credentials;
2500
2504
  this.modelInfo = modelInfo;
2501
2505
  }
2506
+ credentials;
2507
+ modelInfo;
2502
2508
  async embedQuery(query) {
2503
2509
  const result = await this.embedBatch([query]);
2504
2510
  return {
@@ -4239,17 +4245,17 @@ var Database = class {
4239
4245
  if (edges.length === 0) return;
4240
4246
  this.inner.upsertCallEdgesBatch(edges);
4241
4247
  }
4242
- getCallers(targetName, branch) {
4248
+ getCallers(targetName, branch, callTypeFilter) {
4243
4249
  this.throwIfClosed();
4244
- return this.inner.getCallers(targetName, branch);
4250
+ return this.inner.getCallers(targetName, branch, callTypeFilter ?? null);
4245
4251
  }
4246
- getCallersWithContext(targetName, branch) {
4252
+ getCallersWithContext(targetName, branch, callTypeFilter) {
4247
4253
  this.throwIfClosed();
4248
- return this.inner.getCallersWithContext(targetName, branch);
4254
+ return this.inner.getCallersWithContext(targetName, branch, callTypeFilter ?? null);
4249
4255
  }
4250
- getCallees(symbolId, branch) {
4256
+ getCallees(symbolId, branch, callTypeFilter) {
4251
4257
  this.throwIfClosed();
4252
- return this.inner.getCallees(symbolId, branch);
4258
+ return this.inner.getCallees(symbolId, branch, callTypeFilter ?? null);
4253
4259
  }
4254
4260
  deleteCallEdgesByFile(filePath) {
4255
4261
  this.throwIfClosed();
@@ -4259,6 +4265,10 @@ var Database = class {
4259
4265
  this.throwIfClosed();
4260
4266
  this.inner.resolveCallEdge(edgeId, toSymbolId);
4261
4267
  }
4268
+ findShortestPath(fromName, toName, branch, maxDepth) {
4269
+ this.throwIfClosed();
4270
+ return this.inner.findShortestPath(fromName, toName, branch, maxDepth ?? null);
4271
+ }
4262
4272
  addSymbolsToBranch(branch, symbolIds) {
4263
4273
  this.throwIfClosed();
4264
4274
  this.inner.addSymbolsToBranch(branch, symbolIds);
@@ -7057,6 +7067,7 @@ var Indexer = class {
7057
7067
  targetName: site.calleeName,
7058
7068
  toSymbolId: void 0,
7059
7069
  callType: site.callType,
7070
+ confidence: site.confidence,
7060
7071
  line: site.line,
7061
7072
  col: site.column,
7062
7073
  isResolved: false
@@ -8176,12 +8187,12 @@ var Indexer = class {
8176
8187
  })
8177
8188
  );
8178
8189
  }
8179
- async getCallers(targetName) {
8190
+ async getCallers(targetName, callTypeFilter) {
8180
8191
  const { database } = await this.ensureInitialized();
8181
8192
  const seen = /* @__PURE__ */ new Set();
8182
8193
  const results = [];
8183
8194
  for (const branchKey of this.getBranchCatalogKeys()) {
8184
- for (const edge of database.getCallersWithContext(targetName, branchKey)) {
8195
+ for (const edge of database.getCallersWithContext(targetName, branchKey, callTypeFilter)) {
8185
8196
  if (!seen.has(edge.id)) {
8186
8197
  seen.add(edge.id);
8187
8198
  results.push(edge);
@@ -8190,12 +8201,12 @@ var Indexer = class {
8190
8201
  }
8191
8202
  return results;
8192
8203
  }
8193
- async getCallees(symbolId) {
8204
+ async getCallees(symbolId, callTypeFilter) {
8194
8205
  const { database } = await this.ensureInitialized();
8195
8206
  const seen = /* @__PURE__ */ new Set();
8196
8207
  const results = [];
8197
8208
  for (const branchKey of this.getBranchCatalogKeys()) {
8198
- for (const edge of database.getCallees(symbolId, branchKey)) {
8209
+ for (const edge of database.getCallees(symbolId, branchKey, callTypeFilter)) {
8199
8210
  if (!seen.has(edge.id)) {
8200
8211
  seen.add(edge.id);
8201
8212
  results.push(edge);
@@ -8204,6 +8215,17 @@ var Indexer = class {
8204
8215
  }
8205
8216
  return results;
8206
8217
  }
8218
+ async findCallPath(fromName, toName, maxDepth) {
8219
+ const { database } = await this.ensureInitialized();
8220
+ let shortest = [];
8221
+ for (const branchKey of this.getBranchCatalogKeys()) {
8222
+ const path18 = database.findShortestPath(fromName, toName, branchKey, maxDepth);
8223
+ if (path18.length > 0 && (shortest.length === 0 || path18.length < shortest.length)) {
8224
+ shortest = path18;
8225
+ }
8226
+ }
8227
+ return shortest;
8228
+ }
8207
8229
  async close() {
8208
8230
  await this.database?.close();
8209
8231
  this.database = null;
@@ -9979,11 +10001,12 @@ ${formatted.join("\n\n")}` }] };
9979
10001
  );
9980
10002
  server.tool(
9981
10003
  "call_graph",
9982
- "Query the call graph to find callers or callees of a function/method. Use to understand code flow and dependencies.",
10004
+ "Query the call graph to find callers or callees of a function/method. Use to understand code flow and dependencies. Supports relationship types: Call, MethodCall, Constructor, Import, Inherits, Implements.",
9983
10005
  {
9984
10006
  name: import_zod2.z.string().describe("Function or method name to query"),
9985
10007
  direction: import_zod2.z.enum(["callers", "callees"]).default("callers").describe("Direction: 'callers' finds who calls this function, 'callees' finds what this function calls"),
9986
- symbolId: import_zod2.z.string().optional().describe("Symbol ID (required for 'callees' direction)")
10008
+ symbolId: import_zod2.z.string().optional().describe("Symbol ID (required for 'callees' direction)"),
10009
+ relationshipType: import_zod2.z.enum(["Call", "MethodCall", "Constructor", "Import", "Inherits", "Implements"]).optional().describe("Filter by relationship type. Omit to show all.")
9987
10010
  },
9988
10011
  async (args) => {
9989
10012
  await runtime.ensureInitialized();
@@ -9992,26 +10015,52 @@ ${formatted.join("\n\n")}` }] };
9992
10015
  if (!args.symbolId) {
9993
10016
  return { content: [{ type: "text", text: "Error: 'symbolId' is required when direction is 'callees'." }] };
9994
10017
  }
9995
- const callees = await indexer.getCallees(args.symbolId);
10018
+ const callees = await indexer.getCallees(args.symbolId, args.relationshipType);
9996
10019
  if (callees.length === 0) {
9997
- return { content: [{ type: "text", text: `No callees found for symbol ${args.symbolId}.` }] };
10020
+ return { content: [{ type: "text", text: `No callees found for symbol ${args.symbolId}${args.relationshipType ? ` with type ${args.relationshipType}` : ""}.` }] };
9998
10021
  }
9999
- const formatted2 = callees.map(
10000
- (e, i) => `[${i + 1}] \u2192 ${e.targetName} (${e.callType}) at line ${e.line}${e.isResolved ? ` [resolved: ${e.toSymbolId}]` : " [unresolved]"}`
10001
- );
10022
+ const formatted2 = callees.map((e, i) => {
10023
+ const conf = e.confidence !== "Direct" ? ` [${e.confidence.toLowerCase()}]` : "";
10024
+ return `[${i + 1}] \u2192 ${e.targetName} (${e.callType})${conf} at line ${e.line}${e.isResolved ? ` [resolved: ${e.toSymbolId}]` : " [unresolved]"}`;
10025
+ });
10002
10026
  return { content: [{ type: "text", text: `Callees (${callees.length}):
10003
10027
 
10004
10028
  ${formatted2.join("\n")}` }] };
10005
10029
  }
10006
- const callers = await indexer.getCallers(args.name);
10030
+ const callers = await indexer.getCallers(args.name, args.relationshipType);
10007
10031
  if (callers.length === 0) {
10008
- return { content: [{ type: "text", text: `No callers found for "${args.name}".` }] };
10032
+ return { content: [{ type: "text", text: `No callers found for "${args.name}"${args.relationshipType ? ` with type ${args.relationshipType}` : ""}.` }] };
10009
10033
  }
10010
- const formatted = callers.map(
10011
- (e, i) => `[${i + 1}] \u2190 from ${e.fromSymbolName ?? "<unknown>"} in ${e.fromSymbolFilePath ?? "<unknown file>"} [${e.fromSymbolId}] (${e.callType}) at line ${e.line}${e.isResolved ? " [resolved]" : " [unresolved]"}`
10012
- );
10034
+ const formatted = callers.map((e, i) => {
10035
+ const conf = e.confidence !== "Direct" ? ` [${e.confidence.toLowerCase()}]` : "";
10036
+ return `[${i + 1}] \u2190 from ${e.fromSymbolName ?? "<unknown>"} in ${e.fromSymbolFilePath ?? "<unknown file>"} [${e.fromSymbolId}] (${e.callType})${conf} at line ${e.line}${e.isResolved ? " [resolved]" : " [unresolved]"}`;
10037
+ });
10013
10038
  return { content: [{ type: "text", text: `"${args.name}" is called by ${callers.length} function(s):
10014
10039
 
10040
+ ${formatted.join("\n")}` }] };
10041
+ }
10042
+ );
10043
+ server.tool(
10044
+ "call_graph_path",
10045
+ "Find the shortest connection path between two symbols in the call graph. Returns the chain of calls connecting them.",
10046
+ {
10047
+ from: import_zod2.z.string().describe("Source function/method name (starting point)"),
10048
+ to: import_zod2.z.string().describe("Target function/method name (destination)"),
10049
+ maxDepth: import_zod2.z.number().optional().default(10).describe("Maximum traversal depth (default: 10)")
10050
+ },
10051
+ async (args) => {
10052
+ await runtime.ensureInitialized();
10053
+ const indexer = runtime.getIndexer();
10054
+ const path18 = await indexer.findCallPath(args.from, args.to, args.maxDepth);
10055
+ if (path18.length === 0) {
10056
+ return { content: [{ type: "text", text: `No path found between "${args.from}" and "${args.to}". They may be in disconnected components, or the call graph index needs updating.` }] };
10057
+ }
10058
+ const formatted = path18.map((hop, i) => {
10059
+ const prefix = i === 0 ? "[start]" : `--${hop.callType}-->`;
10060
+ const location = hop.filePath ? ` (${hop.filePath}:${hop.line})` : "";
10061
+ return `${prefix} ${hop.symbolName}${location}`;
10062
+ });
10063
+ return { content: [{ type: "text", text: `Path (${path18.length} hops):
10015
10064
  ${formatted.join("\n")}` }] };
10016
10065
  }
10017
10066
  );