opencode-agent-modes 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 j4rviscmd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # opencode-agent-modes
2
+
3
+ [![npm license](https://img.shields.io/npm/l/opencode-agent-modes?logo=npm&logoColor=fff)](https://www.npmjs.com/package/opencode-agent-modes)
4
+ [![npm downloads](https://img.shields.io/npm/dt/opencode-agent-modes?logo=npm&logoColor=fff)](https://www.npmjs.com/package/opencode-agent-modes)
5
+ [![npm version](https://img.shields.io/npm/v/opencode-agent-modes?logo=npm&logoColor=fff)](https://www.npmjs.com/package/opencode-agent-modes)
6
+ ![OpenCode Plugin](https://img.shields.io/badge/OpenCode-Plugin-4c8bf5)
7
+ ![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=fff)
8
+
9
+ OpenCode plugin to switch agent models between performance and economy modes.
10
+
11
+ > [!NOTE]
12
+ > **Primary Use Case**: When approaching your token limit, switch to
13
+ > pre-defined economy models to extend your session until your quota resets.
14
+ > Changes take effect after restarting opencode.
15
+
16
+ <p align="center">
17
+ <img src="assets/image/sample.png" width="700" alt="Change mode example" />
18
+ </p>
19
+
20
+ ## Features
21
+
22
+ - Switch between different model presets (performance, economy, or custom)
23
+ - Configurable presets with user-defined models
24
+ - Toast notifications for mode changes
25
+
26
+ ### Supported Agents
27
+
28
+ | Agent Type | Description |
29
+ | --------------------- | ----------------------------------------------------------------------------------------------- |
30
+ | opencode agents | Standard agents (`build`, `plan`, etc.) |
31
+ | oh-my-opencode agents | Optional - applies if [oh-my-opencode](https://github.com/pekepeke/oh-my-opencode) is installed |
32
+
33
+ ## Installation
34
+
35
+ Add the plugin to your `opencode.json`:
36
+
37
+ ```json
38
+ {
39
+ "plugin": ["opencode-agent-modes@latest"]
40
+ }
41
+ ```
42
+
43
+ The following command files are automatically copied to
44
+ `~/.config/opencode/command/` on installation:
45
+
46
+ - `mode-performance.md`
47
+ - `mode-economy.md`
48
+ - `mode-status.md`
49
+ - `mode-list.md`
50
+
51
+ ## Usage
52
+
53
+ ### Available Commands
54
+
55
+ - `/mode-performance` - Switch to high-performance models
56
+ - `/mode-economy` - Switch to cost-efficient free models
57
+ - `/mode-status` - Show current mode and configuration
58
+ - `/mode-list` - List all available mode presets
59
+
60
+ ### Available Tools
61
+
62
+ - `mode_switch` - Switch to a specified mode preset
63
+ - `mode_status` - Display current mode settings
64
+ - `mode_list` - List all available presets
65
+
66
+ ## Configuration
67
+
68
+ The plugin configuration is stored at `~/.config/opencode/agent-mode-switcher.json`.
69
+
70
+ On first run, the plugin automatically generates this file by:
71
+
72
+ 1. Reading current models from `opencode.json` for the "performance" preset
73
+ 2. Setting `opencode/glm-4.7-free` for the "economy" preset
74
+
75
+ ### Example Configuration
76
+
77
+ > [!TIP]
78
+ > The `oh-my-opencode` section is optional. Omit it if you don't use oh-my-opencode.
79
+
80
+ ```json
81
+ {
82
+ "currentMode": "performance",
83
+ "showToastOnStartup": true,
84
+ "presets": {
85
+ "performance": {
86
+ "description": "High-performance models for complex tasks",
87
+ "opencode": {
88
+ "build": { "model": "github-copilot/gpt-5.2" },
89
+ "plan": { "model": "github-copilot/gpt-5.2" }
90
+ },
91
+ "oh-my-opencode": {
92
+ "Sisyphus": { "model": "anthropic/claude-opus-4-5-20251101" }
93
+ }
94
+ },
95
+ "economy": {
96
+ "description": "Cost-efficient free model for routine tasks",
97
+ "opencode": {
98
+ "build": { "model": "opencode/glm-4.7-free" }
99
+ },
100
+ "oh-my-opencode": {
101
+ "Sisyphus": { "model": "opencode/glm-4.7-free" }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ ### Model Priority
109
+
110
+ When both global `model` and agent-specific `opencode` settings are configured,
111
+ the priority is:
112
+
113
+ ```text
114
+ agent.<name>.model > model (global)
115
+ ```
116
+
117
+ Agent-specific settings override the global model setting.
118
+
119
+ ## Custom Presets
120
+
121
+ To add a custom preset (e.g., "premium"):
122
+
123
+ 1. Add the preset to `~/.config/opencode/agent-mode-switcher.json`:
124
+
125
+ ```json
126
+ {
127
+ "presets": {
128
+ "premium": {
129
+ "description": "High-end models for critical tasks",
130
+ "opencode": {
131
+ "build": { "model": "anthropic/claude-opus-4-5-20251101" }
132
+ }
133
+ }
134
+ }
135
+ }
136
+ ```
137
+
138
+ 2. Create a command file at `~/.config/opencode/command/mode-premium.md`:
139
+
140
+ ```md
141
+ ---
142
+ description: "Switch to premium mode (high-end models)"
143
+ ---
144
+
145
+ Use mode_switch tool to switch agent mode to "premium".
146
+ ```
147
+
148
+ 3. Restart opencode to apply changes.
149
+
150
+ ## Notes
151
+
152
+ - Changes require an opencode restart to take effect
153
+ - Custom mode presets can be added by editing the configuration file
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: "Switch to economy mode (cost-efficient models)"
3
+ ---
4
+
5
+ Use mode_switch tool to switch agent mode to "economy".
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: "List all available agent modes"
3
+ ---
4
+
5
+ Use mode_list tool to show all defined mode presets.
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: "Switch to performance mode (high-performance models)"
3
+ ---
4
+
5
+ Use mode_switch tool to switch agent mode to "performance".
@@ -0,0 +1,5 @@
1
+ ---
2
+ description: "Show current agent mode and configuration"
3
+ ---
4
+
5
+ Use mode_status tool to display current mode settings.
@@ -0,0 +1,3 @@
1
+ export * from './types.ts';
2
+ export * from './loader.ts';
3
+ export * from './initializer.ts';
@@ -0,0 +1,10 @@
1
+ import type { ModeSwitcherConfig } from './types.ts';
2
+ /**
3
+ * Initialize the plugin configuration if it doesn't exist
4
+ * @returns The configuration (existing or newly created)
5
+ */
6
+ export declare function initializeConfig(): Promise<ModeSwitcherConfig>;
7
+ /**
8
+ * Ensure configuration is valid and has required presets
9
+ */
10
+ export declare function validateConfig(config: ModeSwitcherConfig): boolean;
@@ -0,0 +1,83 @@
1
+ import type { ModeSwitcherConfig, OpencodeConfig, OhMyOpencodeConfig } from './types.ts';
2
+ /**
3
+ * Expands tilde (~) notation to the user's home directory path.
4
+ *
5
+ * @param path - File path that may contain ~ prefix
6
+ * @returns Expanded absolute path with ~ replaced by home directory
7
+ * @example
8
+ * ```typescript
9
+ * expandPath('~/config/settings.json')
10
+ * // Returns: '/Users/username/config/settings.json'
11
+ * ```
12
+ */
13
+ export declare function expandPath(path: string): string;
14
+ /**
15
+ * Get the absolute path to the plugin configuration file.
16
+ *
17
+ * @returns Absolute path to agent-mode-switcher.json
18
+ */
19
+ export declare function getPluginConfigPath(): string;
20
+ /**
21
+ * Get the absolute path to the opencode configuration file.
22
+ *
23
+ * @returns Absolute path to opencode.json
24
+ */
25
+ export declare function getOpencodeConfigPath(): string;
26
+ /**
27
+ * Get the absolute path to the oh-my-opencode configuration file.
28
+ *
29
+ * @returns Absolute path to oh-my-opencode.json
30
+ */
31
+ export declare function getOhMyOpencodeConfigPath(): string;
32
+ /**
33
+ * Load the agent-mode-switcher plugin configuration.
34
+ *
35
+ * @returns Plugin configuration object, or null if file doesn't exist
36
+ */
37
+ export declare function loadPluginConfig(): Promise<ModeSwitcherConfig | null>;
38
+ /**
39
+ * Save the agent-mode-switcher plugin configuration.
40
+ *
41
+ * @param config - Plugin configuration object to save
42
+ */
43
+ export declare function savePluginConfig(config: ModeSwitcherConfig): Promise<void>;
44
+ /**
45
+ * Load the opencode configuration file.
46
+ *
47
+ * @returns Opencode configuration object, or null if file doesn't exist
48
+ */
49
+ export declare function loadOpencodeConfig(): Promise<OpencodeConfig | null>;
50
+ /**
51
+ * Save the opencode configuration file.
52
+ *
53
+ * @param config - Opencode configuration object to save
54
+ */
55
+ export declare function saveOpencodeConfig(config: OpencodeConfig): Promise<void>;
56
+ /**
57
+ * Load the oh-my-opencode configuration file.
58
+ *
59
+ * @returns Oh-my-opencode configuration object, or null if file doesn't exist
60
+ */
61
+ export declare function loadOhMyOpencodeConfig(): Promise<OhMyOpencodeConfig | null>;
62
+ /**
63
+ * Save the oh-my-opencode configuration file.
64
+ *
65
+ * @param config - Oh-my-opencode configuration object to save
66
+ */
67
+ export declare function saveOhMyOpencodeConfig(config: OhMyOpencodeConfig): Promise<void>;
68
+ /**
69
+ * Check if the plugin configuration file exists.
70
+ *
71
+ * @returns True if agent-mode-switcher.json exists, false otherwise
72
+ */
73
+ export declare function pluginConfigExists(): Promise<boolean>;
74
+ /**
75
+ * Clear the content cache for a specific file.
76
+ * Exported for testing purposes.
77
+ */
78
+ export declare function clearContentCache(filePath?: string): void;
79
+ /**
80
+ * Set cached content for a file.
81
+ * Exported for testing purposes.
82
+ */
83
+ export declare function setContentCache(filePath: string, content: string): void;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Agent preset configuration for a single agent
3
+ */
4
+ export interface AgentPreset {
5
+ model: string;
6
+ }
7
+ /**
8
+ * Mode preset containing configurations for both opencode and oh-my-opencode agents
9
+ */
10
+ export interface ModePreset {
11
+ description: string;
12
+ model?: string;
13
+ opencode: Record<string, AgentPreset>;
14
+ 'oh-my-opencode': Record<string, AgentPreset>;
15
+ }
16
+ /**
17
+ * Main configuration for the mode switcher plugin
18
+ */
19
+ export interface ModeSwitcherConfig {
20
+ currentMode: string;
21
+ showToastOnStartup: boolean;
22
+ presets: Record<string, ModePreset>;
23
+ }
24
+ /**
25
+ * OpenCode agent configuration structure in opencode.json
26
+ */
27
+ export interface OpencodeAgentConfig {
28
+ model?: string;
29
+ mode?: string;
30
+ [key: string]: unknown;
31
+ }
32
+ /**
33
+ * OpenCode configuration file structure
34
+ */
35
+ export interface OpencodeConfig {
36
+ model?: string;
37
+ agent?: Record<string, OpencodeAgentConfig>;
38
+ [key: string]: unknown;
39
+ }
40
+ /**
41
+ * Oh-my-opencode configuration file structure
42
+ */
43
+ export interface OhMyOpencodeConfig {
44
+ agents?: Record<string, AgentPreset>;
45
+ [key: string]: unknown;
46
+ }
47
+ /**
48
+ * Default economy model for cost-efficient operations
49
+ */
50
+ export declare const DEFAULT_ECONOMY_MODEL = "opencode/glm-4.7-free";
51
+ /**
52
+ * Configuration file paths
53
+ */
54
+ export declare const CONFIG_PATHS: {
55
+ readonly pluginConfig: "~/.config/opencode/agent-mode-switcher.json";
56
+ readonly opencodeConfig: "~/.config/opencode/opencode.json";
57
+ readonly ohMyOpencodeConfig: "~/.config/opencode/oh-my-opencode.json";
58
+ };
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ /**
3
+ * OpenCode Agent Mode Switcher Plugin
4
+ *
5
+ * Allows switching between different agent mode presets (e.g., performance vs economy)
6
+ * that configure which AI models are used for each agent type.
7
+ */
8
+ declare const modeSwitcherPlugin: Plugin;
9
+ export default modeSwitcherPlugin;