Skip to content

feat(opencode): support opencode 2 - #1007

Merged
omartelo merged 9 commits into
mainfrom
feat/opencode-2
Nov 1, 2026
Merged

omartelo merged 9 commits into
mainfrom
feat/opencode-2

Conversation

@omartelo

@omartelo omartelo commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

opencode 2 is the same provider as opencode 1: same binary name, config and opencode.db, and its upgrade replaces 1.x in place. So it stays the opencode provider, and lich tells the generations apart by --version, cached per binary path, size and modification time (providers.IsOpencode2). What 2.x changes, and what lich now does about it (all measured on 2.2.5 beside 1.19.4, in throwaway homes):

  • Spawn. The root command has no --model and no --fork, and by default attaches to a background service every opencode shares, which keeps the environment of whichever command started it. A 2.x session runs --standalone, takes its model as model in OPENCODE_CONFIG_CONTENT, and forks through opencode api --standalone POST /api/session/{id}/fork before resuming the copy with --session. A fork that route refuses is refused.
  • Database. Conversations move to session_v2 / session_message, and 2.x copies a 1.x conversation over the first time it touches it. Cost, closing words, search, the cache line, History and resume read each conversation from the newer table it is in.
  • Plugin install. 2.x reads global plugins from plugins/ only. The module goes there, and the copy an older lich left in plugin/ is removed when it carries lich's marker (1.x reads both and would report twice). The module itself is feat(opencode): report from opencode 2 through the module's default export lich-plugin#98, a patch release inside the current range.
  • Profiles. auth list and auth login run --standalone; 2.x's list prints rows and no count, and only a stored row counts as the profile's login.
  • OpenCode Go gauge. 2.x keeps the key in the credential table of opencode.db, read before auth.json.
  • Unfold long pastes. 2.x drops experimental.disable_paste_summary; the switch is now prompt.paste: "full" through OPENCODE_CLI_CONFIG_CONTENT.
  • MCP servers on the card. The user's config may use 2.x's mcp.servers shape.

The four functions that extend an inline config env var now go through extendInlineConfig and objectAt.

The README's provider table does not move: 2.x matches 1.x on every row (it still turns on mode 2031). The new limits are in docs/ceilings.md, and docs/providers/opencode.md has an opencode 2 section.

Test plan

  • Local gate in the memory jail: gofmt -l ., go vet ./..., go test ./..., and the linux/darwin/windows cross-compile loop.
  • New tests: a database holding both generations (conversations, cost through a sub-agent, closing words, search, cache line), the 2.x spawn argv and env against a fake binary (standalone, model in config, fork through the API and its failure, paste config), the legacy module move, 2.x auth list parsing and --standalone on status and login, the Go key from the credential table, the nested MCP shape, and the version probe with an upgrade in place.
  • Real opencode 2.2.5: the TUI starts and resumes with --standalone --auto --session, takes the model from OPENCODE_CONFIG_CONTENT, and a 30-line bracketed paste lands unfolded with OPENCODE_CLI_CONFIG_CONTENT={"prompt":{"paste":"full"}}; the fork route returns the copy's id; the queries were run against the database it wrote.

usage_tokenonly_test.go: queriesFor now takes the usageSource it picks a
generation from; the assertion is unchanged.
The test asserted the shell's spelling of the directory, which the contract
never promised: on macOS the temp directory is reached through /var ->
/private/var, and $PWD reports the resolved one.
@omartelo
omartelo merged commit e6f18ed into main Nov 1, 2026
7 checks passed
@omartelo
omartelo deleted the feat/opencode-2 branch November 1, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant