From fcf02066809c1b4cbd2da76ccf94b7f460c15683 Mon Sep 17 00:00:00 2001 From: j4rviscmd Date: Fri, 13 Mar 2026 20:50:51 +0900 Subject: [PATCH 1/2] fix: correct command directory path from command/ to commands/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update path references throughout the codebase: - Documentation: ~/.config/opencode/command/ → commands/ - Constant COMMANDS_DEST: command → commands - JSDoc comments and inline documentation Co-Authored-By: Claude Opus 4.6 --- README.md | 4 +-- src/config/command-installer.ts | 45 ++++++--------------------------- src/index.ts | 29 +-------------------- 3 files changed, 11 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 31e4aa5..bfc209a 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Add the plugin to your `opencode.json`: ``` The following command files are automatically copied to -`~/.config/opencode/command/` when the plugin initializes: +`~/.config/opencode/commands/` when the plugin initializes: - `mode-performance.md` - `mode-economy.md` @@ -141,7 +141,7 @@ To add a custom preset (e.g., "premium"): } ``` -2. Create a command file at `~/.config/opencode/command/mode-premium.md`: +2. Create a command file at `~/.config/opencode/commands/mode-premium.md`: ```md --- diff --git a/src/config/command-installer.ts b/src/config/command-installer.ts index ceb9776..79af7d8 100644 --- a/src/config/command-installer.ts +++ b/src/config/command-installer.ts @@ -18,35 +18,21 @@ import { fileURLToPath } from 'node:url' * Target directory for OpenCode command files. * * This is the standard location where OpenCode looks for slash command - * markdown files: `~/.config/opencode/command/` + * markdown files: `~/.config/opencode/commands/` * * @constant */ -const COMMANDS_DEST = join(homedir(), '.config', 'opencode', 'command') +const COMMANDS_DEST = join(homedir(), '.config', 'opencode', 'commands') /** * Finds the commands source directory. * * Tries multiple candidate paths to support both production and development - * environments by checking relative paths from the current module location: - * - Production: bundled dist/index.js -> ../commands + * environments: + * - Production: dist/index.js -> ../commands * - Development: src/config/command-installer.ts -> ../../commands * - * The function checks each candidate path in order and returns the first - * one that exists on the filesystem. - * - * @returns Absolute path to commands directory if found, or null if none - * of the candidate paths exist - * - * @example - * ```typescript - * const commandsDir = findCommandsDir(); - * if (commandsDir) { - * console.log(`Commands found at: ${commandsDir}`); - * } else { - * console.log('Commands directory not found'); - * } - * ``` + * @returns Absolute path to commands directory if found, or null if not found */ function findCommandsDir(): string | null { const __dirname = dirname(fileURLToPath(import.meta.url)) @@ -63,25 +49,10 @@ function findCommandsDir(): string | null { /** * Copies slash command markdown files to OpenCode's command directory. * - * This function is called during plugin initialization to ensure - * command files are available without manual postinstall execution. - * It creates the destination directory if it doesn't exist and copies - * all `.md` files from the source commands directory. - * - * The function is designed to be non-fatal: if copying fails (e.g., due to - * permission issues), it logs a warning but doesn't throw an error, - * allowing the plugin to continue initializing. - * - * @returns Number of files successfully copied, or -1 if source directory - * not found or an error occurred during copying + * Creates the destination directory if needed and copies all `.md` files. + * Non-fatal: logs warnings on failure without blocking plugin initialization. * - * @example - * ```typescript - * const copied = copyCommandFiles(); - * if (copied > 0) { - * console.log(`Copied ${copied} command files`); - * } - * ``` + * @returns Number of files copied, or -1 if source not found or error occurred */ export function copyCommandFiles(): number { const commandsSrc = findCommandsDir() diff --git a/src/index.ts b/src/index.ts index 7cab9ae..6ba7889 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,7 +41,7 @@ const modeSwitcherPlugin: Plugin = async ({ client }) => { // Initialize on startup with error handling try { await modeManager.initialize() - // Copy slash command files to ~/.config/opencode/command/ + // Copy slash command files to ~/.config/opencode/commands/ copyCommandFiles() } catch (error) { // Log error but don't block opencode startup @@ -53,16 +53,6 @@ const modeSwitcherPlugin: Plugin = async ({ client }) => { return { tool: { - /** - * Switch to a different agent mode preset. - * - * Updates the active mode configuration and applies it to both - * opencode.json and oh-my-opencode.json files. The mode preset - * determines which AI models are assigned to each agent type. - * - * @param args.mode - Name of the mode preset to switch to (e.g., "performance", "economy") - * @returns Success or error message with details about the mode switch operation - */ mode_switch: tool({ description: 'Switch agent mode to a specified preset', args: { @@ -75,14 +65,6 @@ const modeSwitcherPlugin: Plugin = async ({ client }) => { }, }), - /** - * Display current agent mode and its configuration. - * - * Shows the currently active mode preset and the AI model assignments - * for all agent types in both OpenCode and Oh My OpenCode configurations. - * - * @returns Current mode name and detailed configuration information - */ mode_status: tool({ description: 'Show current agent mode and its configuration', args: {}, @@ -91,15 +73,6 @@ const modeSwitcherPlugin: Plugin = async ({ client }) => { }, }), - /** - * List all available mode presets. - * - * Returns a list of all configured mode presets with their names - * and AI model assignments for each agent type. This helps users - * understand what modes are available for switching. - * - * @returns Array of mode preset names and their configurations - */ mode_list: tool({ description: 'List all available mode presets', args: {}, From dab5da9b558817715c4c96f5cf1c246df4c2abde Mon Sep 17 00:00:00 2001 From: j4rviscmd Date: Fri, 13 Mar 2026 20:59:19 +0900 Subject: [PATCH 2/2] docs: restore JSDoc comments removed by code-simplifier Restore detailed documentation that was incorrectly removed: - findCommandsDir(): detailed description and @example block - copyCommandFiles(): detailed description and @example block - Tool definitions: mode_switch, mode_status, mode_list JSDoc Co-Authored-By: Claude Opus 4.6 --- src/config/command-installer.ts | 41 ++++++++++++++++++++++++++++----- src/index.ts | 27 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/config/command-installer.ts b/src/config/command-installer.ts index 79af7d8..e917d7f 100644 --- a/src/config/command-installer.ts +++ b/src/config/command-installer.ts @@ -28,11 +28,25 @@ const COMMANDS_DEST = join(homedir(), '.config', 'opencode', 'commands') * Finds the commands source directory. * * Tries multiple candidate paths to support both production and development - * environments: - * - Production: dist/index.js -> ../commands + * environments by checking relative paths from the current module location: + * - Production: bundled dist/index.js -> ../commands * - Development: src/config/command-installer.ts -> ../../commands * - * @returns Absolute path to commands directory if found, or null if not found + * The function checks each candidate path in order and returns the first + * one that exists on the filesystem. + * + * @returns Absolute path to commands directory if found, or null if none + * of the candidate paths exist + * + * @example + * ```typescript + * const commandsDir = findCommandsDir(); + * if (commandsDir) { + * console.log(`Commands found at: ${commandsDir}`); + * } else { + * console.log('Commands directory not found'); + * } + * ``` */ function findCommandsDir(): string | null { const __dirname = dirname(fileURLToPath(import.meta.url)) @@ -49,10 +63,25 @@ function findCommandsDir(): string | null { /** * Copies slash command markdown files to OpenCode's command directory. * - * Creates the destination directory if needed and copies all `.md` files. - * Non-fatal: logs warnings on failure without blocking plugin initialization. + * This function is called during plugin initialization to ensure + * command files are available without manual postinstall execution. + * It creates the destination directory if it doesn't exist and copies + * all `.md` files from the source commands directory. + * + * The function is designed to be non-fatal: if copying fails (e.g., due to + * permission issues), it logs a warning but doesn't throw an error, + * allowing the plugin to continue initializing. + * + * @returns Number of files successfully copied, or -1 if source directory + * not found or an error occurred during copying * - * @returns Number of files copied, or -1 if source not found or error occurred + * @example + * ```typescript + * const copied = copyCommandFiles(); + * if (copied > 0) { + * console.log(`Copied ${copied} command files`); + * } + * ``` */ export function copyCommandFiles(): number { const commandsSrc = findCommandsDir() diff --git a/src/index.ts b/src/index.ts index 6ba7889..3249a1e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,16 @@ const modeSwitcherPlugin: Plugin = async ({ client }) => { return { tool: { + /** + * Switch to a different agent mode preset. + * + * Updates the active mode configuration and applies it to both + * opencode.json and oh-my-opencode.json files. The mode preset + * determines which AI models are assigned to each agent type. + * + * @param args.mode - Name of the mode preset to switch to (e.g., "performance", "economy") + * @returns Success or error message with details about the mode switch operation + */ mode_switch: tool({ description: 'Switch agent mode to a specified preset', args: { @@ -65,6 +75,14 @@ const modeSwitcherPlugin: Plugin = async ({ client }) => { }, }), + /** + * Display current agent mode and its configuration. + * + * Shows the currently active mode preset and the AI model assignments + * for all agent types in both OpenCode and Oh My OpenCode configurations. + * + * @returns Current mode name and detailed configuration information + */ mode_status: tool({ description: 'Show current agent mode and its configuration', args: {}, @@ -73,6 +91,15 @@ const modeSwitcherPlugin: Plugin = async ({ client }) => { }, }), + /** + * List all available mode presets. + * + * Returns a list of all configured mode presets with their names + * and AI model assignments for each agent type. This helps users + * understand what modes are available for switching. + * + * @returns Array of mode preset names and their configurations + */ mode_list: tool({ description: 'List all available mode presets', args: {},