11import type { Plugin , PluginInput } from "@opencode-ai/plugin" ;
22import { tool } from "@opencode-ai/plugin" ;
3- import { appendFile , mkdir , writeFile , readFile } from "fs/promises" ;
3+ import { appendFile , mkdir , writeFile , access } from "fs/promises" ;
44import { loadConfig } from "./config" ;
55import { MCPManager } from "./mcp-client" ;
66import { BM25Index , searchWithRegex , MAX_REGEX_LENGTH } from "./search" ;
77import type { CatalogTool , SearchResult } from "./catalog" ;
8- import pkg from "../package.json" ;
9-
10- // Plugin version from package.json
11- const PLUGIN_VERSION = pkg . version ;
128
139const DEFAULT_CONFIG_PATH = `${ process . env . HOME } /.config/opencode/toolbox.jsonc` ;
1410const LOG_FILE_PATH = `${ process . env . HOME } /.local/share/opencode/toolbox.log` ;
@@ -17,19 +13,12 @@ const LOG_DIR = `${process.env.HOME}/.local/share/opencode`;
1713// Slash command paths
1814const COMMAND_DIR = `${ process . env . HOME } /.config/opencode/command` ;
1915const COMMAND_FILE_PATH = `${ COMMAND_DIR } /toolbox-status.md` ;
20-
21- /**
22- * Generate command file content with version in frontmatter
23- */
24- function getCommandContent ( ) : string {
25- return `---
16+ const COMMAND_CONTENT = `---
2617description: Check toolbox plugin status and server health
27- toolbox_version: ${ PLUGIN_VERSION }
2818---
29- Run toolbox_status({}) and show me the results in a readable format.
19+ Run toolbox_status({}) tool and show me the results in a readable format.
3020Highlight any failed servers or issues.
3121` ;
32- }
3322
3423/**
3524 * Parse tool name into server and original tool name
@@ -115,36 +104,19 @@ function log(level: string, message: string, extra?: any) {
115104}
116105
117106/**
118- * Create or update /toolbox-status slash command
119- * Updates when plugin version changes
107+ * Create /toolbox-status slash command if it doesn't exist
120108 * Non-blocking, fire and forget
121109 */
122110function ensureCommandFile ( ) {
123- const content = getCommandContent ( ) ;
124-
125- readFile ( COMMAND_FILE_PATH , "utf-8" )
126- . then ( ( existing ) => {
127- // Check if version matches
128- const versionMatch = existing . match ( / t o o l b o x _ v e r s i o n : \s * ( [ ^ \n ] + ) / ) ;
129- const existingVersion = versionMatch ?. [ 1 ] ?. trim ( ) ?? null ;
130-
131- if ( existingVersion !== PLUGIN_VERSION ) {
132- // Version changed, update file
133- return writeFile ( COMMAND_FILE_PATH , content ) . then ( ( ) => {
134- log ( "info" , `Updated /toolbox-status command (${ existingVersion } -> ${ PLUGIN_VERSION } )` ) ;
135- } ) ;
136- }
137- // Version matches, no update needed
138- } )
139- . catch ( ( ) => {
140- // File doesn't exist, create it
141- mkdir ( COMMAND_DIR , { recursive : true } )
142- . then ( ( ) => writeFile ( COMMAND_FILE_PATH , content ) )
143- . then ( ( ) => log ( "info" , `Created /toolbox-status command (v${ PLUGIN_VERSION } )` ) )
144- . catch ( ( ) => {
145- // Ignore errors - non-critical
146- } ) ;
147- } ) ;
111+ access ( COMMAND_FILE_PATH ) . catch ( ( ) => {
112+ // File doesn't exist, create it
113+ mkdir ( COMMAND_DIR , { recursive : true } )
114+ . then ( ( ) => writeFile ( COMMAND_FILE_PATH , COMMAND_CONTENT ) )
115+ . then ( ( ) => log ( "info" , "Created /toolbox-status command file" ) )
116+ . catch ( ( ) => {
117+ // Ignore errors - non-critical
118+ } ) ;
119+ } ) ;
148120}
149121
150122/**
0 commit comments