Files
w3cjandClaude Opus 5.5 6be9f27fbe fix(agents): devvm agent import opencode reads opencode 2's logins through opencode auth export
opencode 2 keeps its logins in its database's credential table, not
auth.json. When this machine's opencode --version is 2 or later, the
import runs opencode auth export (its output read from stdout, never
logged) and maps each provider's active credential to the store's
opencode format (agentlogin.OpencodeFromExport): an API key as
{"type":"api","key"}, the OpenAI login from a Codex method
(chatgpt-browser, chatgpt-headless, or none for one imported from
auth.json) as {"type":"oauth","access","refresh","expires","accountId"}.
Sign in with ChatGPT, other providers' OAuth and unknown types are left
out with agent_import_opencode_skipped; a failing export fails the
import (agent_import_opencode_failed). opencode 1 keeps auth.json.

Tests: TestOpencodeFromExport, TestOpencode (the new opencode stub),
agent_import_opencode.txtar; AgentImport.Opencode is the seam.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 00:34:34 -07:00

24 lines
723 B
Go

package main
// opencode stands in for this machine's opencode, which devvm agent
// import runs: --version prints the switch opencode-version, and auth
// export prints the switch opencode-export, or fails with the switch
// opencode-export-fails. Without opencode-version it fails as a missing
// command does (127), so devvm reads no version. Anything else fails.
func opencode(c *call) int {
c.log()
v, ok := c.text("opencode-version")
switch {
case !ok:
c.say("opencode: command not found")
return 127
case c.arg(0) == "--version":
c.print(v + "\n")
return 0
case c.joined() == "auth export" && !c.on("opencode-export-fails"):
c.print(string(c.raw("opencode-export", "[]")))
return 0
}
return 1
}