opencode-agent-modes 0.3.0 → 0.3.2
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 +2 -2
- package/dist/config/types.d.ts +4 -1
- package/dist/index.js +14 -8
- package/dist/modes/manager.d.ts +18 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Add the plugin to your `opencode.json`:
|
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
The following command files are automatically copied to
|
|
44
|
-
`~/.config/opencode/
|
|
44
|
+
`~/.config/opencode/commands/` when the plugin initializes:
|
|
45
45
|
|
|
46
46
|
- `mode-performance.md`
|
|
47
47
|
- `mode-economy.md`
|
|
@@ -135,7 +135,7 @@ To add a custom preset (e.g., "premium"):
|
|
|
135
135
|
}
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
2. Create a command file at `~/.config/opencode/
|
|
138
|
+
2. Create a command file at `~/.config/opencode/commands/mode-premium.md`:
|
|
139
139
|
|
|
140
140
|
```md
|
|
141
141
|
---
|
package/dist/config/types.d.ts
CHANGED
|
@@ -27,12 +27,15 @@ export type HierarchicalPreset = Record<string, ModelConfig | HierarchicalPreset
|
|
|
27
27
|
* Both opencode and oh-my-opencode use the same HierarchicalPreset type,
|
|
28
28
|
* allowing them to have arbitrary nested structures that are handled
|
|
29
29
|
* uniformly by recursive merge functions.
|
|
30
|
+
*
|
|
31
|
+
* The `oh-my-opencode` field is optional to support users who do not use the
|
|
32
|
+
* oh-my-opencode plugin. When absent, all oh-my-opencode related processing is skipped.
|
|
30
33
|
*/
|
|
31
34
|
export interface ModePreset {
|
|
32
35
|
description: string;
|
|
33
36
|
model?: string;
|
|
34
37
|
opencode: HierarchicalPreset;
|
|
35
|
-
'oh-my-opencode'
|
|
38
|
+
'oh-my-opencode'?: HierarchicalPreset;
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* Main configuration for the mode switcher plugin
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
3
7
|
var __export = (target, all) => {
|
|
4
8
|
for (var name in all)
|
|
5
9
|
__defProp(target, name, {
|
|
6
10
|
get: all[name],
|
|
7
11
|
enumerable: true,
|
|
8
12
|
configurable: true,
|
|
9
|
-
set: (
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
10
14
|
});
|
|
11
15
|
};
|
|
12
16
|
|
|
@@ -13827,7 +13831,7 @@ async function buildPerformancePreset() {
|
|
|
13827
13831
|
description: "High-performance models for complex tasks",
|
|
13828
13832
|
...globalModel && { model: globalModel },
|
|
13829
13833
|
opencode: opencodePreset,
|
|
13830
|
-
"oh-my-opencode": ohMyOpencodePreset
|
|
13834
|
+
...ohMyOpencodeConfig && { "oh-my-opencode": ohMyOpencodePreset }
|
|
13831
13835
|
};
|
|
13832
13836
|
}
|
|
13833
13837
|
async function buildEconomyPreset() {
|
|
@@ -13839,7 +13843,7 @@ async function buildEconomyPreset() {
|
|
|
13839
13843
|
description: "Cost-efficient free model for routine tasks",
|
|
13840
13844
|
model: DEFAULT_ECONOMY_MODEL,
|
|
13841
13845
|
opencode: opencodePreset,
|
|
13842
|
-
"oh-my-opencode": ohMyOpencodePreset
|
|
13846
|
+
...ohMyOpencodeConfig && { "oh-my-opencode": ohMyOpencodePreset }
|
|
13843
13847
|
};
|
|
13844
13848
|
}
|
|
13845
13849
|
async function initializeConfig() {
|
|
@@ -13868,7 +13872,7 @@ import { copyFileSync, existsSync, mkdirSync, readdirSync } from "fs";
|
|
|
13868
13872
|
import { homedir as homedir2 } from "os";
|
|
13869
13873
|
import { dirname, join as join2 } from "path";
|
|
13870
13874
|
import { fileURLToPath } from "url";
|
|
13871
|
-
var COMMANDS_DEST = join2(homedir2(), ".config", "opencode", "
|
|
13875
|
+
var COMMANDS_DEST = join2(homedir2(), ".config", "opencode", "commands");
|
|
13872
13876
|
function findCommandsDir() {
|
|
13873
13877
|
const __dirname2 = dirname(fileURLToPath(import.meta.url));
|
|
13874
13878
|
const candidates = [
|
|
@@ -13987,7 +13991,9 @@ class ModeManager {
|
|
|
13987
13991
|
return;
|
|
13988
13992
|
}
|
|
13989
13993
|
await this.updateOpencodeConfig(preset.model, preset.opencode);
|
|
13990
|
-
|
|
13994
|
+
if (preset["oh-my-opencode"]) {
|
|
13995
|
+
await this.updateOhMyOpencodeConfig(preset["oh-my-opencode"]);
|
|
13996
|
+
}
|
|
13991
13997
|
this.client.tui.showToast({
|
|
13992
13998
|
body: {
|
|
13993
13999
|
title: "Mode Applied",
|
|
@@ -14009,7 +14015,7 @@ class ModeManager {
|
|
|
14009
14015
|
if (opencodeConfig?.agent && hasDriftRecursive(opencodeConfig.agent, preset.opencode)) {
|
|
14010
14016
|
return true;
|
|
14011
14017
|
}
|
|
14012
|
-
if (ohMyConfig && hasDriftRecursive(ohMyConfig, preset["oh-my-opencode"])) {
|
|
14018
|
+
if (ohMyConfig && preset["oh-my-opencode"] && hasDriftRecursive(ohMyConfig, preset["oh-my-opencode"])) {
|
|
14013
14019
|
return true;
|
|
14014
14020
|
}
|
|
14015
14021
|
return false;
|
|
@@ -14042,7 +14048,7 @@ ${modes}`;
|
|
|
14042
14048
|
}
|
|
14043
14049
|
const globalModel = preset.model ? `Global model: ${preset.model}` : "Global model: (not set)";
|
|
14044
14050
|
const opencodeTree = formatHierarchicalTree(preset.opencode);
|
|
14045
|
-
const ohMyOpencodeTree = formatHierarchicalTree(preset["oh-my-opencode"]);
|
|
14051
|
+
const ohMyOpencodeTree = preset["oh-my-opencode"] ? formatHierarchicalTree(preset["oh-my-opencode"]) : "";
|
|
14046
14052
|
return [
|
|
14047
14053
|
`Current mode: ${currentMode}`,
|
|
14048
14054
|
`Description: ${preset.description}`,
|
|
@@ -14066,7 +14072,7 @@ ${modes}`;
|
|
|
14066
14072
|
const results = [];
|
|
14067
14073
|
const opencodeResult = await this.updateOpencodeConfig(preset.model, preset.opencode);
|
|
14068
14074
|
results.push(`opencode.json: ${opencodeResult}`);
|
|
14069
|
-
const ohMyResult = await this.updateOhMyOpencodeConfig(preset["oh-my-opencode"]);
|
|
14075
|
+
const ohMyResult = preset["oh-my-opencode"] ? await this.updateOhMyOpencodeConfig(preset["oh-my-opencode"]) : "skipped (not configured)";
|
|
14070
14076
|
results.push(`oh-my-opencode.json: ${ohMyResult}`);
|
|
14071
14077
|
config2.currentMode = modeName;
|
|
14072
14078
|
this.config = config2;
|
package/dist/modes/manager.d.ts
CHANGED
|
@@ -79,6 +79,10 @@ export declare class ModeManager {
|
|
|
79
79
|
* Checks global model and per-agent model values recursively. Returns true
|
|
80
80
|
* if any expected value differs from the actual file content.
|
|
81
81
|
*
|
|
82
|
+
* If the preset does not include an `'oh-my-opencode'` key (i.e., the user
|
|
83
|
+
* does not use the oh-my-opencode plugin), drift checking for that config
|
|
84
|
+
* file is skipped entirely.
|
|
85
|
+
*
|
|
82
86
|
* @param preset - The mode preset to compare against
|
|
83
87
|
* @returns True if actual configs differ from the preset
|
|
84
88
|
* @private
|
|
@@ -161,7 +165,7 @@ export declare class ModeManager {
|
|
|
161
165
|
* This method performs the following operations:
|
|
162
166
|
* 1. Validates that the requested mode exists
|
|
163
167
|
* 2. Updates `opencode.json` with new global model and agent settings
|
|
164
|
-
* 3. Updates `oh-my-opencode.json` with new agent settings
|
|
168
|
+
* 3. Updates `oh-my-opencode.json` with new agent settings (skipped if preset has no `'oh-my-opencode'` key)
|
|
165
169
|
* 4. Updates `agent-mode-switcher.json` with the new current mode
|
|
166
170
|
* 5. Shows a toast notification (if available)
|
|
167
171
|
*
|
|
@@ -172,6 +176,7 @@ export declare class ModeManager {
|
|
|
172
176
|
* @returns Promise resolving to a formatted result message with status of each config update
|
|
173
177
|
* @example
|
|
174
178
|
* ```typescript
|
|
179
|
+
* // With oh-my-opencode configured:
|
|
175
180
|
* const result = await manager.switchMode('economy');
|
|
176
181
|
* console.log(result);
|
|
177
182
|
* // Output:
|
|
@@ -184,6 +189,18 @@ export declare class ModeManager {
|
|
|
184
189
|
* // - agent-mode-switcher.json: updated
|
|
185
190
|
* //
|
|
186
191
|
* // Note: Restart opencode to apply changes.
|
|
192
|
+
*
|
|
193
|
+
* // Without oh-my-opencode configured:
|
|
194
|
+
* // Output:
|
|
195
|
+
* // Switched to economy mode
|
|
196
|
+
* // Cost-efficient free model for routine tasks
|
|
197
|
+
* //
|
|
198
|
+
* // Results:
|
|
199
|
+
* // - opencode.json: updated
|
|
200
|
+
* // - oh-my-opencode.json: skipped (not configured)
|
|
201
|
+
* // - agent-mode-switcher.json: updated
|
|
202
|
+
* //
|
|
203
|
+
* // Note: Restart opencode to apply changes.
|
|
187
204
|
* ```
|
|
188
205
|
*/
|
|
189
206
|
switchMode(modeName: string): Promise<string>;
|