@comfanion/usethis_search 3.0.0-dev.1 → 3.0.0-dev.2
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/api.ts +92 -0
- package/index.ts +1 -1
- package/package.json +2 -1
package/api.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* usethis_search API
|
|
3
|
+
*
|
|
4
|
+
* Exports internal functions for plugin-to-plugin communication.
|
|
5
|
+
* Used by Mind plugin for graph-based workspace management.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { GraphDB } from "./vectorizer/graph-db"
|
|
9
|
+
|
|
10
|
+
// Global GraphDB instance (shared across the plugin)
|
|
11
|
+
let graphDBInstance: GraphDB | null = null
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initialize the API with GraphDB instance
|
|
15
|
+
*/
|
|
16
|
+
export function initGraphAPI(db: GraphDB): void {
|
|
17
|
+
graphDBInstance = db
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get related files for a given file path
|
|
22
|
+
*
|
|
23
|
+
* @param filePath - File path to get relations for
|
|
24
|
+
* @param maxDepth - Maximum graph depth to traverse (default: 1)
|
|
25
|
+
* @returns Array of related files with relation type and weight
|
|
26
|
+
*
|
|
27
|
+
* Example:
|
|
28
|
+
* ```javascript
|
|
29
|
+
* const related = await getRelatedFiles("src/auth/login.ts", 1)
|
|
30
|
+
* // Returns:
|
|
31
|
+
* [
|
|
32
|
+
* { path: "src/types/User.ts", relation: "imports", weight: 0.9 },
|
|
33
|
+
* { path: "src/auth/BaseAuth.ts", relation: "extends", weight: 0.95 },
|
|
34
|
+
* { path: "src/routes/api.ts", relation: "used_by", weight: 0.8 }
|
|
35
|
+
* ]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export async function getRelatedFiles(
|
|
39
|
+
filePath: string,
|
|
40
|
+
maxDepth: number = 1
|
|
41
|
+
): Promise<{path: string, relation: string, weight: number}[]> {
|
|
42
|
+
if (!graphDBInstance) {
|
|
43
|
+
console.warn("[usethis_search API] GraphDB not initialized. Returning empty array.")
|
|
44
|
+
return []
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const chunkId = `file:${filePath}`
|
|
49
|
+
const related = await graphDBInstance.getRelatedFiles(chunkId, maxDepth)
|
|
50
|
+
|
|
51
|
+
// Filter out the input file itself (it might appear in the graph)
|
|
52
|
+
const filtered = related.filter(r => r.path !== filePath)
|
|
53
|
+
|
|
54
|
+
return filtered
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(`[usethis_search API] Error getting related files for ${filePath}:`, error)
|
|
57
|
+
return []
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Check if graph API is available
|
|
63
|
+
*/
|
|
64
|
+
export function isGraphAPIAvailable(): boolean {
|
|
65
|
+
return graphDBInstance !== null
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get all graph entries for a file (both incoming and outgoing)
|
|
70
|
+
*/
|
|
71
|
+
export async function getGraphEntries(filePath: string) {
|
|
72
|
+
if (!graphDBInstance) {
|
|
73
|
+
return null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const chunkId = `file:${filePath}`
|
|
78
|
+
const [outgoing, incoming] = await Promise.all([
|
|
79
|
+
graphDBInstance.getOutgoing(chunkId),
|
|
80
|
+
graphDBInstance.getIncoming(chunkId),
|
|
81
|
+
])
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
imports: outgoing.filter(t => t.predicate === "imports"),
|
|
85
|
+
extends: outgoing.filter(t => t.predicate === "extends"),
|
|
86
|
+
used_by: incoming,
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error(`[usethis_search API] Error getting graph entries for ${filePath}:`, error)
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
}
|
package/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import search from "./tools/search"
|
|
|
4
4
|
import codeindex from "./tools/codeindex"
|
|
5
5
|
import readInterceptor from "./tools/read-interceptor"
|
|
6
6
|
import FileIndexerPlugin from "./file-indexer"
|
|
7
|
-
import { getRelatedFiles, getGraphEntries, isGraphAPIAvailable } from "./api
|
|
7
|
+
import { getRelatedFiles, getGraphEntries, isGraphAPIAvailable } from "./api"
|
|
8
8
|
|
|
9
9
|
const UsethisSearchPlugin: Plugin = async (ctx) => {
|
|
10
10
|
const fileIndexerHooks = await FileIndexerPlugin(ctx as any)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comfanion/usethis_search",
|
|
3
|
-
"version": "3.0.0-dev.
|
|
3
|
+
"version": "3.0.0-dev.2",
|
|
4
4
|
"description": "OpenCode plugin: semantic search with graph-based context (v3: graph relations, 1-hop context, LSP + regex analyzers)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"index.ts",
|
|
15
|
+
"api.ts",
|
|
15
16
|
"file-indexer.ts",
|
|
16
17
|
"tools/search.ts",
|
|
17
18
|
"tools/codeindex.ts",
|