( opencodeConfig: OpenCodeConfig, options: NormalizedWorkflowOptions, allowSubagents: boolean, )
| 144 | } |
| 145 | |
| 146 | export function applyWorkflowConfig( |
| 147 | opencodeConfig: OpenCodeConfig, |
| 148 | options: NormalizedWorkflowOptions, |
| 149 | allowSubagents: boolean, |
| 150 | ): void { |
| 151 | if (options.workflow === "manual" || options.workflow === "user-managed") return; |
| 152 | |
| 153 | if (!allowSubagents) { |
| 154 | const existingPrimaryTools = normalizePrimaryTools(opencodeConfig.experimental?.primary_tools); |
| 155 | opencodeConfig.experimental = { |
| 156 | ...opencodeConfig.experimental, |
| 157 | primary_tools: existingPrimaryTools.includes("submit_plan") |
| 158 | ? existingPrimaryTools |
| 159 | : [...existingPrimaryTools, "submit_plan"], |
| 160 | }; |
| 161 | } |
| 162 | |
| 163 | opencodeConfig.agent ??= {}; |
| 164 | |
| 165 | const planningAgentConfigKeys = new Set<string>(); |
| 166 | for (const agentName of options.planningAgents) { |
| 167 | planningAgentConfigKeys.add(resolveAgentConfigKey(opencodeConfig, agentName)); |
| 168 | allowPlanningAgent(opencodeConfig, agentName); |
| 169 | } |
| 170 | |
| 171 | if (options.workflow === "all-agents") return; |
| 172 | |
| 173 | if (!options.planningAgentSet.has("build")) { |
| 174 | denySubmitPlan(opencodeConfig, "build"); |
| 175 | } |
| 176 | |
| 177 | for (const [agentName, agentConfig] of Object.entries(opencodeConfig.agent)) { |
| 178 | if (options.planningAgentSet.has(agentName) || planningAgentConfigKeys.has(agentName)) { |
| 179 | allowPlanningAgent(opencodeConfig, agentName); |
| 180 | continue; |
| 181 | } |
| 182 | |
| 183 | if (isPrimaryCapableAgent(agentConfig, allowSubagents)) { |
| 184 | denySubmitPlan(opencodeConfig, agentName); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | function allowPlanningAgent(opencodeConfig: OpenCodeConfig, agentName: string): void { |
| 190 | const agent = ensureAgentConfig(opencodeConfig, agentName); |
no test coverage detected