Skip to content

fix(agent): initialize plugins before resolving agent config #25438

Description

@quangtran88

Summary

Agent.Service resolves cfg.agent before plugin config() hooks are guaranteed to run.

Plugins like oh-my-openagent inject agent definitions by mutating config in their plugin config hook, so entry points that hit agent resolution first can fail with errors like:

  • agent \"sisyphus\" not found
  • default agent \"sisyphus\" not found
  • default agent \"Sisyphus - Ultraworker\" not found

Repro

  1. Install a plugin that injects agents through the plugin config() hook.
  2. Set default_agent to one of those plugin-provided agents.
  3. Run an entry point that resolves agents before full project bootstrap, such as opencode run ....
  4. Observe that built-in agents resolve, but plugin-provided agents do not.

Root Cause

  • packages/opencode/src/agent/agent.ts reads config.get() while constructing agent state.
  • Plugin config() hooks are invoked during Plugin.init() in packages/opencode/src/plugin/index.ts.
  • packages/opencode/src/provider/provider.ts already forces plugin loading before reading config, but agent/agent.ts does not.

Proposed Fix

Initialize plugins before agent state snapshots config in packages/opencode/src/agent/agent.ts.

That matches the existing intent in packages/opencode/src/project/bootstrap.ts and makes direct/early agent resolution entry points consistent with provider resolution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions