@@ -2,6 +2,7 @@ import type { Plugin } from "@opencode-ai/plugin";
22import { existsSync , readFileSync } from "fs" ;
33import * as path from "path" ;
44import * as os from "os" ;
5+ import { fileURLToPath } from "url" ;
56
67import { parseConfig } from "./config/schema.js" ;
78import { Indexer } from "./indexer/index.js" ;
@@ -13,6 +14,17 @@ import {
1314 index_health_check ,
1415 initializeTools ,
1516} from "./tools/index.js" ;
17+ import { loadCommandsFromDirectory } from "./commands/loader.js" ;
18+
19+ function getCommandsDir ( ) : string {
20+ let currentDir = process . cwd ( ) ;
21+
22+ if ( typeof import . meta !== "undefined" && import . meta. url ) {
23+ currentDir = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
24+ }
25+
26+ return path . join ( currentDir , ".." , "commands" ) ;
27+ }
1628
1729function loadJsonFile ( filePath : string ) : unknown {
1830 try {
@@ -69,38 +81,12 @@ const plugin: Plugin = async ({ directory }) => {
6981 async config ( cfg ) {
7082 cfg . command = cfg . command ?? { } ;
7183
72- cfg . command [ "search" ] = {
73- description : "Search codebase by meaning using semantic search" ,
74- template : `Use the \`codebase_search\` tool to find code related to: $ARGUMENTS
75-
76- If the index doesn't exist yet, run \`index_codebase\` first.
77-
78- Return the most relevant results with file paths and line numbers.` ,
79- } ;
80-
81- cfg . command [ "find" ] = {
82- description : "Find code using hybrid approach (semantic + grep)" ,
83- template : `Find code related to: $ARGUMENTS
84-
85- Strategy:
86- 1. First use \`codebase_search\` to find semantically related code
87- 2. From the results, identify specific function/class names
88- 3. Use grep to find all occurrences of those identifiers
89- 4. Combine findings into a comprehensive answer
90-
91- If the semantic index doesn't exist, run \`index_codebase\` first.` ,
92- } ;
93-
94- cfg . command [ "index" ] = {
95- description : "Index the codebase for semantic search" ,
96- template : `Run the \`index_codebase\` tool to create or update the semantic search index.
84+ const commandsDir = getCommandsDir ( ) ;
85+ const commands = loadCommandsFromDirectory ( commandsDir ) ;
9786
98- Show progress and final statistics including:
99- - Number of files processed
100- - Number of chunks indexed
101- - Tokens used
102- - Duration` ,
103- } ;
87+ for ( const [ name , definition ] of commands ) {
88+ cfg . command [ name ] = definition ;
89+ }
10490 } ,
10591 } ;
10692} ;
0 commit comments