opencode-context 1.0.6 → 1.0.7

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 CHANGED
@@ -2,6 +2,38 @@
2
2
 
3
3
  Smart file finder for codebases with relevance scoring. Includes an OpenCode plugin.
4
4
 
5
+ ---
6
+
7
+ ## Quick Reference for AI Agents
8
+
9
+ **Tool:** `find_files`
10
+ **Purpose:** Find relevant files before reading them
11
+ **When to use:** User asks to find, locate, search, or "where is X"
12
+
13
+ ### Arguments
14
+
15
+ | Name | Type | Required | Default | Description |
16
+ |------|------|----------|---------|-------------|
17
+ | query | string | **YES** | - | What to find (e.g., "auth", "database models") |
18
+ | maxFiles | number | no | 5 | Number of results |
19
+ | minScore | number | no | 15 | Relevance threshold (0-100) |
20
+ | includeTests | boolean | no | false | Include *.test.*, *.spec.* |
21
+ | includeConfigs | boolean | no | false | Include *.config.*, .rc files |
22
+ | includeDocs | boolean | no | false | Include *.md, docs/ |
23
+
24
+ ### Examples
25
+
26
+ ```
27
+ find_files query="authentication middleware"
28
+ find_files query="database" maxFiles=10 includeTests=true
29
+ find_files query="config" includeConfigs=true
30
+ ```
31
+
32
+ **Scoring:** Filename (highest) > Path > Content > Imports/Exports
33
+ **Tip:** If no results, try `minScore=5` for broader search
34
+
35
+ ---
36
+
5
37
  ## Installation
6
38
 
7
39
  ### For Humans
package/dist/install.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env bun
2
- export {};
2
+ declare function updateAgentsMd(): Promise<void>;
3
+ declare function updateOpencodeConfig(): Promise<void>;
4
+ export { updateAgentsMd, updateOpencodeConfig };
3
5
  //# sourceMappingURL=install.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":";AAuGA,iBAAe,cAAc,kBAyB5B;AAED,iBAAe,oBAAoB,kBA+BlC;AAwBD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,CAAC"}
package/dist/install.js CHANGED
@@ -4,7 +4,9 @@
4
4
  // src/install.ts
5
5
  import { promises as fs } from "fs";
6
6
  import { join, dirname } from "path";
7
- var CONFIG_PATH = join(process.env.HOME || "", ".config/opencode/opencode.json");
7
+ import { homedir } from "os";
8
+ var CONFIG_PATH = join(process.env.HOME || homedir(), ".config/opencode/opencode.json");
9
+ var AGENTS_PATH = join(process.env.HOME || homedir(), ".config/opencode/AGENTS.md");
8
10
  async function ensureConfigDir() {
9
11
  const dir = dirname(CONFIG_PATH);
10
12
  try {
@@ -25,31 +27,136 @@ async function writeConfig(config) {
25
27
  await fs.writeFile(CONFIG_PATH, JSON.stringify(config, null, 2) + `
26
28
  `);
27
29
  }
28
- async function install() {
29
- console.log(`Installing opencode-context plugin...
30
- `);
31
- await ensureConfigDir();
30
+ async function readAgentsMd() {
31
+ try {
32
+ return await fs.readFile(AGENTS_PATH, "utf-8");
33
+ } catch {
34
+ return "";
35
+ }
36
+ }
37
+ async function writeAgentsMd(content) {
38
+ await fs.writeFile(AGENTS_PATH, content);
39
+ }
40
+ var TOOL_DOCUMENTATION = `
41
+ ## find_files Tool (opencode-context plugin)
42
+
43
+ **Purpose:** Semantic file search for locating relevant code files before reading them.
44
+
45
+ **When to use:**
46
+ - User asks to find, locate, or search for files
47
+ - Before reading multiple files to understand a codebase
48
+ - Looking for specific functionality (auth, database, config, etc.)
49
+ - User mentions "where is X defined" or "find Y"
50
+
51
+ **Arguments:**
52
+
53
+ | Name | Type | Required | Default | Description |
54
+ |------|------|----------|---------|-------------|
55
+ | query | string | YES | - | Search query describing what to find (e.g., "auth middleware", "user model") |
56
+ | maxFiles | number | NO | 5 | Maximum number of files to return |
57
+ | minScore | number | NO | 15 | Minimum relevance score (0-100). Lower = more results |
58
+ | includeTests | boolean | NO | false | Include test files (*.test.*, *.spec.*, etc.) |
59
+ | includeConfigs | boolean | NO | false | Include configuration files (*.config.*, .rc files) |
60
+ | includeDocs | boolean | NO | false | Include documentation (*.md, README, docs/) |
61
+
62
+ **Usage examples:**
63
+
64
+ \`\`\`
65
+ # Basic search
66
+ find_files query="authentication"
67
+
68
+ # More results with tests
69
+ find_files query="database" maxFiles=10 includeTests=true
70
+
71
+ # Find config files
72
+ find_files query="webpack" includeConfigs=true
73
+
74
+ # Low threshold for broader search
75
+ find_files query="utils" minScore=5
76
+ \`\`\`
77
+
78
+ **Scoring algorithm:**
79
+ - Filename matches (highest weight)
80
+ - Directory path matches
81
+ - Content matches (function names, class names)
82
+ - Import/export statements
83
+ - File type (tests ranked lower unless requested)
84
+
85
+ **Best practices:**
86
+ 1. Call this BEFORE reading files when user asks to find something
87
+ 2. Use maxFiles=10+ when doing initial codebase exploration
88
+ 3. Set includeTests=true only when user specifically asks about tests
89
+ 4. If no results, try lowering minScore to 5 or using broader terms
90
+ 5. Results include relevance scores - files above 50 are highly relevant
91
+ `;
92
+ async function updateAgentsMd() {
93
+ const existingContent = await readAgentsMd();
94
+ const toolMarker = "## find_files Tool (opencode-context plugin)";
95
+ if (existingContent.includes(toolMarker)) {
96
+ const beforeTool = existingContent.split(toolMarker)[0];
97
+ const afterTool = existingContent.split(toolMarker)[1];
98
+ const nextHeading = afterTool.search(/\n## /);
99
+ const rest = nextHeading >= 0 ? afterTool.slice(nextHeading) : "";
100
+ const newContent = beforeTool + TOOL_DOCUMENTATION + `
101
+ ` + rest;
102
+ await writeAgentsMd(newContent);
103
+ console.log("\u2713 Updated AGENTS.md with find_files documentation");
104
+ } else {
105
+ const header = existingContent.includes("# Available Tools") ? existingContent : existingContent.trim() ? existingContent + `
106
+
107
+ # Available Tools
108
+ ` : `# Available Tools
109
+ `;
110
+ const newContent = header + `
111
+ ` + TOOL_DOCUMENTATION;
112
+ await writeAgentsMd(newContent);
113
+ console.log("\u2713 Created/updated AGENTS.md with find_files documentation");
114
+ }
115
+ }
116
+ async function updateOpencodeConfig() {
32
117
  const config = await readConfig();
33
118
  if (!config.plugin) {
34
119
  config.plugin = [];
35
120
  }
36
121
  const pluginName = "opencode-context@latest";
37
- if (config.plugin.includes(pluginName)) {
38
- console.log("\u2713 opencode-context already in plugins");
39
- } else {
122
+ if (!config.plugin.includes(pluginName)) {
40
123
  config.plugin.push(pluginName);
41
124
  console.log("\u2713 Added opencode-context@latest to plugins");
125
+ } else {
126
+ console.log("\u2713 opencode-context already in plugins");
127
+ }
128
+ if (!config.instructions) {
129
+ config.instructions = [];
130
+ }
131
+ const agentsRef = "~/.config/opencode/AGENTS.md";
132
+ if (!config.instructions.includes(agentsRef)) {
133
+ config.instructions.push(agentsRef);
134
+ console.log("\u2713 Added AGENTS.md to instructions");
135
+ } else {
136
+ console.log("\u2713 AGENTS.md already in instructions");
42
137
  }
43
138
  await writeConfig(config);
139
+ }
140
+ async function install() {
141
+ console.log(`Installing opencode-context plugin...
142
+ `);
143
+ await ensureConfigDir();
144
+ await updateOpencodeConfig();
145
+ await updateAgentsMd();
44
146
  console.log(`
45
147
  \u2713 Installation complete!`);
46
148
  console.log(`
47
149
  To use:`);
48
- console.log(" 1. Run opencode in your project");
49
- console.log(' 2. Ask: "Find files related to auth"');
50
- console.log(` 3. The agent will use find_files tool
150
+ console.log(" 1. Restart opencode if running");
151
+ console.log(" 2. The AI agent will now see find_files in available tools");
152
+ console.log(` 3. Try: "Find files related to authentication"
51
153
  `);
52
154
  }
53
- if (__require.main == __require.module) {
155
+ var isMainModule = process.argv[1]?.includes("install.js") || process.argv[1]?.includes("install.ts");
156
+ if (isMainModule) {
54
157
  install().catch(console.error);
55
158
  }
159
+ export {
160
+ updateOpencodeConfig,
161
+ updateAgentsMd
162
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-context",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Smart file finder for codebases - semantic search with confidence scoring. Also available as an OpenCode plugin.",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin.js",
@@ -14,13 +14,15 @@
14
14
  "files": [
15
15
  "dist/",
16
16
  "README.md",
17
- "LICENSE"
17
+ "LICENSE",
18
+ "plugin.json"
18
19
  ],
19
20
  "scripts": {
20
21
  "build": "bun build ./src/index.ts --outfile ./dist/index.js --target node && bun build ./src/plugin.ts --outfile ./dist/plugin.js --target node && bun build ./src/install.ts --outfile ./dist/install.js --target node && echo '#!/usr/bin/env node' | cat - ./dist/index.js > temp && mv temp ./dist/index.js && chmod +x ./dist/index.js",
21
22
  "build:types": "tsc --emitDeclarationOnly",
22
23
  "dev": "bun run src/index.ts",
23
24
  "test": "bun test",
25
+ "postinstall": "node dist/install.js || echo 'Run: bunx opencode-context@latest install'",
24
26
  "prepublishOnly": "bun run build && bun run build:types"
25
27
  },
26
28
  "dependencies": {
package/plugin.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "opencode-context",
3
+ "version": "1.0.6",
4
+ "description": "Smart file finder for codebases with semantic search and relevance scoring",
5
+ "main": "dist/plugin.js",
6
+ "tools": [
7
+ {
8
+ "name": "find_files",
9
+ "description": "Find relevant files in the codebase based on a semantic search query. Use this to locate files related to a task before reading them. Returns ranked results with relevance scores.",
10
+ "whenToUse": [
11
+ "User asks to find, locate, or search for files",
12
+ "Before reading multiple files to understand a codebase",
13
+ "Looking for specific functionality (auth, database, config, etc.)",
14
+ "User mentions 'where is X defined' or 'find Y'"
15
+ ],
16
+ "args": {
17
+ "query": {
18
+ "type": "string",
19
+ "required": true,
20
+ "description": "Search query describing what to find (e.g., 'auth middleware', 'user model')"
21
+ },
22
+ "maxFiles": {
23
+ "type": "number",
24
+ "required": false,
25
+ "default": 5,
26
+ "description": "Maximum number of files to return"
27
+ },
28
+ "minScore": {
29
+ "type": "number",
30
+ "required": false,
31
+ "default": 15,
32
+ "description": "Minimum relevance score (0-100). Lower = more results"
33
+ },
34
+ "includeTests": {
35
+ "type": "boolean",
36
+ "required": false,
37
+ "default": false,
38
+ "description": "Include test files (*.test.*, *.spec.*, etc.)"
39
+ },
40
+ "includeConfigs": {
41
+ "type": "boolean",
42
+ "required": false,
43
+ "default": false,
44
+ "description": "Include configuration files (*.config.*, .rc files)"
45
+ },
46
+ "includeDocs": {
47
+ "type": "boolean",
48
+ "required": false,
49
+ "default": false,
50
+ "description": "Include documentation (*.md, README, docs/)"
51
+ }
52
+ },
53
+ "examples": [
54
+ {
55
+ "description": "Basic search",
56
+ "usage": "find_files query='authentication'"
57
+ },
58
+ {
59
+ "description": "More results with tests",
60
+ "usage": "find_files query='database' maxFiles=10 includeTests=true"
61
+ },
62
+ {
63
+ "description": "Find config files",
64
+ "usage": "find_files query='webpack' includeConfigs=true"
65
+ },
66
+ {
67
+ "description": "Low threshold for broader search",
68
+ "usage": "find_files query='utils' minScore=5"
69
+ }
70
+ ],
71
+ "bestPractices": [
72
+ "Call this BEFORE reading files when user asks to find something",
73
+ "Use maxFiles=10+ when doing initial codebase exploration",
74
+ "Set includeTests=true only when user specifically asks about tests",
75
+ "If no results, try lowering minScore to 5 or using broader terms",
76
+ "Results include relevance scores - files above 50 are highly relevant"
77
+ ],
78
+ "scoringFactors": [
79
+ "Filename matches (highest weight)",
80
+ "Directory path matches",
81
+ "Content matches (function names, class names)",
82
+ "Import/export statements",
83
+ "File type (tests ranked lower unless requested)"
84
+ ]
85
+ }
86
+ ]
87
+ }