micode 0.3.2 → 0.3.3
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-loader.d.ts +20 -0
- package/dist/index.js +58 -2
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AgentConfig } from "@opencode-ai/sdk";
|
|
2
|
+
export interface AgentOverride {
|
|
3
|
+
model?: string;
|
|
4
|
+
temperature?: number;
|
|
5
|
+
maxTokens?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface MicodeConfig {
|
|
8
|
+
agents?: Record<string, AgentOverride>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Load micode.json from ~/.config/opencode/micode.json
|
|
12
|
+
* Returns null if file doesn't exist or is invalid JSON
|
|
13
|
+
* @param configDir - Optional override for config directory (for testing)
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadMicodeConfig(configDir?: string): Promise<MicodeConfig | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Merge user config overrides into plugin agent configs
|
|
18
|
+
* User overrides take precedence for safe properties only
|
|
19
|
+
*/
|
|
20
|
+
export declare function mergeAgentConfigs(pluginAgents: Record<string, AgentConfig>, userConfig: MicodeConfig | null): Record<string, AgentConfig>;
|
package/dist/index.js
CHANGED
|
@@ -15964,6 +15964,57 @@ ${result}
|
|
|
15964
15964
|
background_list
|
|
15965
15965
|
};
|
|
15966
15966
|
}
|
|
15967
|
+
// src/config-loader.ts
|
|
15968
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
15969
|
+
import { join as join4 } from "path";
|
|
15970
|
+
import { homedir as homedir2 } from "os";
|
|
15971
|
+
var SAFE_AGENT_PROPERTIES = ["model", "temperature", "maxTokens"];
|
|
15972
|
+
async function loadMicodeConfig(configDir) {
|
|
15973
|
+
const baseDir = configDir ?? join4(homedir2(), ".config", "opencode");
|
|
15974
|
+
const configPath = join4(baseDir, "micode.json");
|
|
15975
|
+
try {
|
|
15976
|
+
const content = await readFile3(configPath, "utf-8");
|
|
15977
|
+
const parsed = JSON.parse(content);
|
|
15978
|
+
if (parsed.agents && typeof parsed.agents === "object") {
|
|
15979
|
+
const sanitizedAgents = {};
|
|
15980
|
+
for (const [agentName, agentConfig] of Object.entries(parsed.agents)) {
|
|
15981
|
+
if (agentConfig && typeof agentConfig === "object") {
|
|
15982
|
+
const sanitized = {};
|
|
15983
|
+
const config2 = agentConfig;
|
|
15984
|
+
for (const prop of SAFE_AGENT_PROPERTIES) {
|
|
15985
|
+
if (prop in config2) {
|
|
15986
|
+
sanitized[prop] = config2[prop];
|
|
15987
|
+
}
|
|
15988
|
+
}
|
|
15989
|
+
sanitizedAgents[agentName] = sanitized;
|
|
15990
|
+
}
|
|
15991
|
+
}
|
|
15992
|
+
return { agents: sanitizedAgents };
|
|
15993
|
+
}
|
|
15994
|
+
return parsed;
|
|
15995
|
+
} catch {
|
|
15996
|
+
return null;
|
|
15997
|
+
}
|
|
15998
|
+
}
|
|
15999
|
+
function mergeAgentConfigs(pluginAgents, userConfig) {
|
|
16000
|
+
if (!userConfig?.agents) {
|
|
16001
|
+
return pluginAgents;
|
|
16002
|
+
}
|
|
16003
|
+
const merged = {};
|
|
16004
|
+
for (const [name, agentConfig] of Object.entries(pluginAgents)) {
|
|
16005
|
+
const userOverride = userConfig.agents[name];
|
|
16006
|
+
if (userOverride) {
|
|
16007
|
+
merged[name] = {
|
|
16008
|
+
...agentConfig,
|
|
16009
|
+
...userOverride
|
|
16010
|
+
};
|
|
16011
|
+
} else {
|
|
16012
|
+
merged[name] = agentConfig;
|
|
16013
|
+
}
|
|
16014
|
+
}
|
|
16015
|
+
return merged;
|
|
16016
|
+
}
|
|
16017
|
+
|
|
15967
16018
|
// src/index.ts
|
|
15968
16019
|
var THINK_KEYWORDS = [
|
|
15969
16020
|
/\bthink\s*(hard|deeply|carefully|through)\b/i,
|
|
@@ -15997,6 +16048,10 @@ var OpenCodeConfigPlugin = async (ctx) => {
|
|
|
15997
16048
|
if (!astGrepStatus.available) {
|
|
15998
16049
|
console.warn(`[micode] ${astGrepStatus.message}`);
|
|
15999
16050
|
}
|
|
16051
|
+
const userConfig = await loadMicodeConfig();
|
|
16052
|
+
if (userConfig?.agents) {
|
|
16053
|
+
console.log(`[micode] Loaded model overrides for: ${Object.keys(userConfig.agents).join(", ")}`);
|
|
16054
|
+
}
|
|
16000
16055
|
const thinkModeState = new Map;
|
|
16001
16056
|
const autoCompactHook = createAutoCompactHook(ctx);
|
|
16002
16057
|
const contextInjectorHook = createContextInjectorHook(ctx);
|
|
@@ -16026,9 +16081,10 @@ var OpenCodeConfigPlugin = async (ctx) => {
|
|
|
16026
16081
|
doom_loop: "allow",
|
|
16027
16082
|
external_directory: "allow"
|
|
16028
16083
|
};
|
|
16084
|
+
const mergedAgents = mergeAgentConfigs(agents, userConfig);
|
|
16029
16085
|
config2.agent = {
|
|
16030
|
-
Commander:
|
|
16031
|
-
...Object.fromEntries(Object.entries(
|
|
16086
|
+
Commander: mergedAgents[PRIMARY_AGENT_NAME],
|
|
16087
|
+
...Object.fromEntries(Object.entries(mergedAgents).filter(([k]) => k !== PRIMARY_AGENT_NAME)),
|
|
16032
16088
|
...config2.agent,
|
|
16033
16089
|
build: { ...config2.agent?.build, mode: "subagent" },
|
|
16034
16090
|
plan: { ...config2.agent?.plan, mode: "subagent" }
|