feat(agents): add agent_definitions schema, eager path resolution, and JSON agent loader
Wave 1 of agent definitions enhancement (PR #2299): Schema & Configuration: - Add agent_definitions field to oh-my-opencode config schema - Support list of file paths to .md or .json agent definition files - Add to PARTIAL_STRING_ARRAY_KEYS for Set-union merge semantics - Implement eager path resolution in loadPluginConfig() before merging Path Resolution: - Create resolve-agent-definition-paths.ts helper - User-level paths resolve from ~/.config/opencode/ (no containment) - Project-level paths resolve from project root (with containment check) - Homedir expansion, absolute/relative path handling JSON Agent Loader: - Create parseJsonAgentFile() for .json/.jsonc agent definitions - Validate required fields (name, prompt) - Support tools as string (comma-separated) or array - Map model via mapClaudeModelToOpenCode() - Comprehensive test suite (7 test cases, all passing) Type Extensions: - Extend AgentScope: add 'definition-file' and 'opencode-config' - Add AgentJsonDefinition interface for JSON agent schema All automated checks passing: - lsp_diagnostics clean on all changed files - json-agent-loader.test.ts: 7/7 passing - Full typecheck: zero new errors - QA evidence saved to .sisyphus/evidence/
This commit is contained in:
committed by
YeonGyu-Kim
parent
1e85a88db0
commit
fd28f7e668
@@ -9,6 +9,7 @@ import {
|
||||
parseJsonc,
|
||||
detectPluginConfigFile,
|
||||
migrateConfigFile,
|
||||
resolveAgentDefinitionPaths,
|
||||
} from "./shared";
|
||||
import { migrateLegacyConfigFile } from "./shared/migrate-legacy-config-file";
|
||||
import { CONFIG_BASENAME, LEGACY_CONFIG_BASENAME } from "./shared/plugin-identity";
|
||||
@@ -41,6 +42,7 @@ const PARTIAL_STRING_ARRAY_KEYS = new Set([
|
||||
"disabled_commands",
|
||||
"disabled_tools",
|
||||
"mcp_env_allowlist",
|
||||
"agent_definitions",
|
||||
]);
|
||||
|
||||
export function parseConfigPartially(
|
||||
@@ -139,6 +141,12 @@ export function mergeConfigs(
|
||||
...override,
|
||||
agents: deepMerge(base.agents, override.agents),
|
||||
categories: deepMerge(base.categories, override.categories),
|
||||
agent_definitions: [
|
||||
...new Set([
|
||||
...(base.agent_definitions ?? []),
|
||||
...(override.agent_definitions ?? []),
|
||||
]),
|
||||
],
|
||||
disabled_agents: [
|
||||
...new Set([
|
||||
...(base.disabled_agents ?? []),
|
||||
@@ -250,6 +258,15 @@ export function loadPluginConfig(
|
||||
// Load user config first (base). Parse empty config through Zod to apply field defaults.
|
||||
const userConfig = loadConfigFromPath(userConfigPath, ctx)
|
||||
const userGitMasterOverrides = loadExplicitGitMasterOverrides(userConfigPath)
|
||||
|
||||
if (userConfig?.agent_definitions) {
|
||||
userConfig.agent_definitions = resolveAgentDefinitionPaths(
|
||||
userConfig.agent_definitions,
|
||||
configDir,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
let config: OhMyOpenCodeConfig =
|
||||
userConfig ?? OhMyOpenCodeConfigSchema.parse({});
|
||||
|
||||
@@ -257,6 +274,15 @@ export function loadPluginConfig(
|
||||
const defaultGitMaster = OhMyOpenCodeConfigSchema.parse({}).git_master
|
||||
const projectConfig = loadConfigFromPath(projectConfigPath, ctx);
|
||||
const projectGitMasterOverrides = loadExplicitGitMasterOverrides(projectConfigPath)
|
||||
|
||||
if (projectConfig?.agent_definitions) {
|
||||
projectConfig.agent_definitions = resolveAgentDefinitionPaths(
|
||||
projectConfig.agent_definitions,
|
||||
directory,
|
||||
directory
|
||||
)
|
||||
}
|
||||
|
||||
if (projectConfig) {
|
||||
config = mergeConfigs(config, projectConfig);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user