opencode-agent-modes 0.3.1 → 0.4.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/dist/config/types.d.ts +4 -1
- package/dist/index.js +35 -16
- package/dist/modes/manager.d.ts +24 -1
- package/package.json +1 -1
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
|
@@ -13831,7 +13831,7 @@ async function buildPerformancePreset() {
|
|
|
13831
13831
|
description: "High-performance models for complex tasks",
|
|
13832
13832
|
...globalModel && { model: globalModel },
|
|
13833
13833
|
opencode: opencodePreset,
|
|
13834
|
-
"oh-my-opencode": ohMyOpencodePreset
|
|
13834
|
+
...ohMyOpencodeConfig && { "oh-my-opencode": ohMyOpencodePreset }
|
|
13835
13835
|
};
|
|
13836
13836
|
}
|
|
13837
13837
|
async function buildEconomyPreset() {
|
|
@@ -13843,7 +13843,7 @@ async function buildEconomyPreset() {
|
|
|
13843
13843
|
description: "Cost-efficient free model for routine tasks",
|
|
13844
13844
|
model: DEFAULT_ECONOMY_MODEL,
|
|
13845
13845
|
opencode: opencodePreset,
|
|
13846
|
-
"oh-my-opencode": ohMyOpencodePreset
|
|
13846
|
+
...ohMyOpencodeConfig && { "oh-my-opencode": ohMyOpencodePreset }
|
|
13847
13847
|
};
|
|
13848
13848
|
}
|
|
13849
13849
|
async function initializeConfig() {
|
|
@@ -13987,19 +13987,38 @@ class ModeManager {
|
|
|
13987
13987
|
return;
|
|
13988
13988
|
}
|
|
13989
13989
|
const drifted = await this.hasConfigDrift(preset);
|
|
13990
|
-
if (
|
|
13990
|
+
if (drifted) {
|
|
13991
|
+
await this.updateOpencodeConfig(preset.model, preset.opencode);
|
|
13992
|
+
if (preset["oh-my-opencode"]) {
|
|
13993
|
+
await this.updateOhMyOpencodeConfig(preset["oh-my-opencode"]);
|
|
13994
|
+
}
|
|
13995
|
+
const modeName = this.config.currentMode;
|
|
13996
|
+
setTimeout(() => {
|
|
13997
|
+
this.client.tui.showToast({
|
|
13998
|
+
body: {
|
|
13999
|
+
title: "agent-mode-switcher",
|
|
14000
|
+
message: `applied "${modeName}" mode.
|
|
14001
|
+
restart opencode to take effect.`,
|
|
14002
|
+
variant: "warning",
|
|
14003
|
+
duration: 5000
|
|
14004
|
+
}
|
|
14005
|
+
}).catch(() => {});
|
|
14006
|
+
}, 3000);
|
|
13991
14007
|
return;
|
|
13992
14008
|
}
|
|
13993
|
-
|
|
13994
|
-
|
|
13995
|
-
|
|
13996
|
-
|
|
13997
|
-
|
|
13998
|
-
|
|
13999
|
-
|
|
14000
|
-
|
|
14001
|
-
|
|
14002
|
-
|
|
14009
|
+
if (this.config.showToastOnStartup) {
|
|
14010
|
+
const modeName = this.config.currentMode;
|
|
14011
|
+
setTimeout(() => {
|
|
14012
|
+
this.client.tui.showToast({
|
|
14013
|
+
body: {
|
|
14014
|
+
title: "agent-mode-switcher",
|
|
14015
|
+
message: `current mode: ${modeName}`,
|
|
14016
|
+
variant: "info",
|
|
14017
|
+
duration: 3000
|
|
14018
|
+
}
|
|
14019
|
+
}).catch(() => {});
|
|
14020
|
+
}, 3000);
|
|
14021
|
+
}
|
|
14003
14022
|
}
|
|
14004
14023
|
async hasConfigDrift(preset) {
|
|
14005
14024
|
const opencodeConfig = await loadOpencodeConfig();
|
|
@@ -14013,7 +14032,7 @@ class ModeManager {
|
|
|
14013
14032
|
if (opencodeConfig?.agent && hasDriftRecursive(opencodeConfig.agent, preset.opencode)) {
|
|
14014
14033
|
return true;
|
|
14015
14034
|
}
|
|
14016
|
-
if (ohMyConfig && hasDriftRecursive(ohMyConfig, preset["oh-my-opencode"])) {
|
|
14035
|
+
if (ohMyConfig && preset["oh-my-opencode"] && hasDriftRecursive(ohMyConfig, preset["oh-my-opencode"])) {
|
|
14017
14036
|
return true;
|
|
14018
14037
|
}
|
|
14019
14038
|
return false;
|
|
@@ -14046,7 +14065,7 @@ ${modes}`;
|
|
|
14046
14065
|
}
|
|
14047
14066
|
const globalModel = preset.model ? `Global model: ${preset.model}` : "Global model: (not set)";
|
|
14048
14067
|
const opencodeTree = formatHierarchicalTree(preset.opencode);
|
|
14049
|
-
const ohMyOpencodeTree = formatHierarchicalTree(preset["oh-my-opencode"]);
|
|
14068
|
+
const ohMyOpencodeTree = preset["oh-my-opencode"] ? formatHierarchicalTree(preset["oh-my-opencode"]) : "";
|
|
14050
14069
|
return [
|
|
14051
14070
|
`Current mode: ${currentMode}`,
|
|
14052
14071
|
`Description: ${preset.description}`,
|
|
@@ -14070,7 +14089,7 @@ ${modes}`;
|
|
|
14070
14089
|
const results = [];
|
|
14071
14090
|
const opencodeResult = await this.updateOpencodeConfig(preset.model, preset.opencode);
|
|
14072
14091
|
results.push(`opencode.json: ${opencodeResult}`);
|
|
14073
|
-
const ohMyResult = await this.updateOhMyOpencodeConfig(preset["oh-my-opencode"]);
|
|
14092
|
+
const ohMyResult = preset["oh-my-opencode"] ? await this.updateOhMyOpencodeConfig(preset["oh-my-opencode"]) : "skipped (not configured)";
|
|
14074
14093
|
results.push(`oh-my-opencode.json: ${ohMyResult}`);
|
|
14075
14094
|
config2.currentMode = modeName;
|
|
14076
14095
|
this.config = config2;
|
package/dist/modes/manager.d.ts
CHANGED
|
@@ -69,6 +69,12 @@ export declare class ModeManager {
|
|
|
69
69
|
* files are updated to match the expected preset values,
|
|
70
70
|
* and a toast notification prompts the user to restart.
|
|
71
71
|
*
|
|
72
|
+
* When no drift is detected and `showToastOnStartup` is enabled,
|
|
73
|
+
* an informational toast displays the current mode name.
|
|
74
|
+
*
|
|
75
|
+
* Toast notifications are delayed via `setTimeout` to allow the
|
|
76
|
+
* OpenCode UI to fully initialize before sending them.
|
|
77
|
+
*
|
|
72
78
|
* @private
|
|
73
79
|
*/
|
|
74
80
|
private applyCurrentModeIfNeeded;
|
|
@@ -79,6 +85,10 @@ export declare class ModeManager {
|
|
|
79
85
|
* Checks global model and per-agent model values recursively. Returns true
|
|
80
86
|
* if any expected value differs from the actual file content.
|
|
81
87
|
*
|
|
88
|
+
* If the preset does not include an `'oh-my-opencode'` key (i.e., the user
|
|
89
|
+
* does not use the oh-my-opencode plugin), drift checking for that config
|
|
90
|
+
* file is skipped entirely.
|
|
91
|
+
*
|
|
82
92
|
* @param preset - The mode preset to compare against
|
|
83
93
|
* @returns True if actual configs differ from the preset
|
|
84
94
|
* @private
|
|
@@ -161,7 +171,7 @@ export declare class ModeManager {
|
|
|
161
171
|
* This method performs the following operations:
|
|
162
172
|
* 1. Validates that the requested mode exists
|
|
163
173
|
* 2. Updates `opencode.json` with new global model and agent settings
|
|
164
|
-
* 3. Updates `oh-my-opencode.json` with new agent settings
|
|
174
|
+
* 3. Updates `oh-my-opencode.json` with new agent settings (skipped if preset has no `'oh-my-opencode'` key)
|
|
165
175
|
* 4. Updates `agent-mode-switcher.json` with the new current mode
|
|
166
176
|
* 5. Shows a toast notification (if available)
|
|
167
177
|
*
|
|
@@ -172,6 +182,7 @@ export declare class ModeManager {
|
|
|
172
182
|
* @returns Promise resolving to a formatted result message with status of each config update
|
|
173
183
|
* @example
|
|
174
184
|
* ```typescript
|
|
185
|
+
* // With oh-my-opencode configured:
|
|
175
186
|
* const result = await manager.switchMode('economy');
|
|
176
187
|
* console.log(result);
|
|
177
188
|
* // Output:
|
|
@@ -184,6 +195,18 @@ export declare class ModeManager {
|
|
|
184
195
|
* // - agent-mode-switcher.json: updated
|
|
185
196
|
* //
|
|
186
197
|
* // Note: Restart opencode to apply changes.
|
|
198
|
+
*
|
|
199
|
+
* // Without oh-my-opencode configured:
|
|
200
|
+
* // Output:
|
|
201
|
+
* // Switched to economy mode
|
|
202
|
+
* // Cost-efficient free model for routine tasks
|
|
203
|
+
* //
|
|
204
|
+
* // Results:
|
|
205
|
+
* // - opencode.json: updated
|
|
206
|
+
* // - oh-my-opencode.json: skipped (not configured)
|
|
207
|
+
* // - agent-mode-switcher.json: updated
|
|
208
|
+
* //
|
|
209
|
+
* // Note: Restart opencode to apply changes.
|
|
187
210
|
* ```
|
|
188
211
|
*/
|
|
189
212
|
switchMode(modeName: string): Promise<string>;
|