diff options
| author | Matt Silverlock <[email protected]> | 2025-12-20 12:46:48 -0500 |
|---|---|---|
| committer | Aiden Cline <[email protected]> | 2025-12-20 11:49:23 -0600 |
| commit | 8f6c8844d742b56858823e57388e8149f665cb7a (patch) | |
| tree | 7113743b383c1f8a6329531ef214c8e47d3c7b64 /github | |
| parent | da6e0e60c0ca42d54595553fc1ab70f62be6e3b9 (diff) | |
| download | opencode-8f6c8844d742b56858823e57388e8149f665cb7a.tar.gz opencode-8f6c8844d742b56858823e57388e8149f665cb7a.zip | |
feat: support configuring a default_agent across all API/user surfaces (#5843)
Co-authored-by: observerw <[email protected]>
Diffstat (limited to 'github')
| -rw-r--r-- | github/action.yml | 5 | ||||
| -rw-r--r-- | github/index.ts | 28 |
2 files changed, 32 insertions, 1 deletions
diff --git a/github/action.yml b/github/action.yml index cf276b51c..57e26d856 100644 --- a/github/action.yml +++ b/github/action.yml @@ -9,6 +9,10 @@ inputs: description: "Model to use" required: true + agent: + description: "Agent to use. Must be a primary agent. Falls back to default_agent from config or 'build' if not found." + required: false + share: description: "Share the opencode session (defaults to true for public repos)" required: false @@ -62,6 +66,7 @@ runs: run: opencode github run env: MODEL: ${{ inputs.model }} + AGENT: ${{ inputs.agent }} SHARE: ${{ inputs.share }} PROMPT: ${{ inputs.prompt }} USE_GITHUB_TOKEN: ${{ inputs.use_github_token }} diff --git a/github/index.ts b/github/index.ts index 6d826326e..7f6018232 100644 --- a/github/index.ts +++ b/github/index.ts @@ -318,6 +318,10 @@ function useEnvRunUrl() { return `/${repo.owner}/${repo.repo}/actions/runs/${runId}` } +function useEnvAgent() { + return process.env["AGENT"] || undefined +} + function useEnvShare() { const value = process.env["SHARE"] if (!value) return undefined @@ -578,16 +582,38 @@ async function summarize(response: string) { } } +async function resolveAgent(): Promise<string | undefined> { + const envAgent = useEnvAgent() + if (!envAgent) return undefined + + // Validate the agent exists and is a primary agent + const agents = await client.agent.list<true>() + const agent = agents.data?.find((a) => a.name === envAgent) + + if (!agent) { + console.warn(`agent "${envAgent}" not found. Falling back to default agent`) + return undefined + } + + if (agent.mode === "subagent") { + console.warn(`agent "${envAgent}" is a subagent, not a primary agent. Falling back to default agent`) + return undefined + } + + return envAgent +} + async function chat(text: string, files: PromptFiles = []) { console.log("Sending message to opencode...") const { providerID, modelID } = useEnvModel() + const agent = await resolveAgent() const chat = await client.session.chat<true>({ path: session, body: { providerID, modelID, - agent: "build", + agent, parts: [ { type: "text", |
