Repository navigation
feat(opencode): carry session prompts through native configuration - #179
Merged
Merged
Conversation
xxchan
force-pushed
the
fix/opencode-session-prompts
branch
from
October 7, 2026 06:00
8a6876d to
41c9761
Compare
Merged
xxchan
added a commit
that referenced
this pull request
Oct 7, 2026
Release OAR and CLI 0.31.0. This PR changes only the two package version fields. **New** - `SessionOptions.mcpServers` (#178, part 1 of #170): MCP servers attached to one session, in ACP's `McpServer` shape (stdio `{name, command, args?, env?}` or http `{name, type: "http", url, headers?}`; no SSE). They are added on top of the runtime's own servers, never written to its configuration, and must be given again on `resume`. `env` and `headers` values never reach a record, event or error. - claude: `--mcp-config` from a 0600 file in a fresh 0700 directory, deleted when the process ends; a same-named user server is replaced for that session. - codex: `thread/start` / `thread/resume` config overrides; codex merges a same-named user entry field by field, so OAR always sets `args` and `enabled = true`; names outside `^[\w:@/.-]+$` are refused before codex starts. - Every other runtime (cursor, pi, grok, kimi, opencode, antigravity, morph) refuses a non-empty list with `UnsupportedOptionError` until its channel is verified. - opencode `systemPrompt` / `appendSystemPrompt` (#179, closes #171 for opencode): carried through opencode's own `OPENCODE_CONFIG_CONTENT`. `systemPrompt` replaces the prompt of the agent the session actually uses (the saved agent on resume), verified against the mode opencode reports; `appendSystemPrompt` adds a session-owned instructions file after the user's own. Refused when `OPENCODE_CONFIG_CONTENT` is already set, for an empty `systemPrompt`, and for a saved agent that no longer exists. Prompt text is passed literally (`{env:…}` / `{file:…}` are not expanded). Validation: all 13 checks passed on the final heads of #178 (`da06902`) and #179 (`41c9761`); claude and codex MCP attachment run against the real CLIs with stdio and http echo servers. After this PR passes CI and merges, tag its exact squash commit as `v0.31.0` to trigger npm trusted publishing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: exe.dev user <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
xxchan
pushed a commit
that referenced
this pull request
Oct 7, 2026
…CP credentials opencode refuses no session option any more: its prompt path (#179) passes mcpServers to the ACP open beside OPENCODE_CONFIG_CONTENT, and an MCP list with an empty or repeated name fails before the prompts are prepared. #179's "prompt and MCP together are refused" regressions now check that both reach the open; the opencode-aimock vendor test runs a replaced and an appended prompt with both echo servers in one session. antigravity refuses an mcpServers entry with a non-empty env or headers (UnsupportedOptionError on mcpServers, before the server starts): agy_acp_server 1.3.0 writes those values in plain text into its conversation database, which outlives the session. Entries without them attach as before; unit and vendor tests cover both. Refs #170 Co-Authored-By: Claude Opus 5.5 <[email protected]>
xxchan
added a commit
that referenced
this pull request
Oct 7, 2026
…#181) Second PR for #170, on top of #178 (the contract plus claude and codex) and rebased onto #179 (opencode prompts). `mcpServers` now works on grok, kimi, opencode, antigravity and pi. Antigravity refuses entries that carry credentials. Cursor still refuses the option, because only a paid run against Cursor's backend could show its agent calling the tool. ## ACP: grok, kimi, opencode, antigravity - The entries go out as ACP `mcpServers` on `session/new`, `session/load` and `session/resume` (`shared/acp/mcp-servers.ts`), where oar used to send `[]`. Stdio is `{name, command, args, env: [{name, value}]}` and http is `{type: "http", name, url, headers: [...]}`. `args`, `env` and `headers` are always sent, because opencode reads them without checking. - An http entry is refused with `UnsupportedOptionError` on `mcpServers` when `initialize` doesn't declare `mcpCapabilities.http`. All four agents declare it. - An empty or repeated name fails before the agent starts. When an open fails, credentials are removed from the error's message and stack. - No agent keeps the servers across a resume. Resumed without them, none of the four attaches any; given again, they attach. - grok's `--plugin-dir` launch flag also works, but it isn't used: the ACP param does the job, and launch flags belong to #171. | runtime | how the model reaches the tool | on a name clash with the user's config | |---|---|---| | grok 1.0.46 | through its `use_tool` meta-tool, named `<server>__<tool>` | the session's server wins; the user's other servers stay | | kimi 2.1.1 | `mcp__<server>__<tool>` | the session's server wins; the user's other servers stay | | opencode 1.18.30 | `<server>_<tool>` | the session's server replaces the user's for that process. A session server that fails to start also removes the user's (probe) | | antigravity 1.3.0 | through `call_mcp_tool`; servers start at the first prompt | the session's server wins; the user's other servers stay | **Antigravity refuses entries with credentials.** The server saves the session's entries in plain text, `env` and header values included, in `$GEMINI_HOME/antigravity-acp/conversations/<id>.db` (mode 0600). That file outlives the session, and the host can't see it. So an entry with a non-empty `env` or `headers` is refused with `UnsupportedOptionError` on `mcpServers` before the server starts. Entries without credentials attach as usual (`refuseAntigravityMcpCredentials`). **opencode prompts together with MCP:** opencode no longer declares any refused option. Its prompt path from #179 passes `mcpServers` to the ACP open next to `OPENCODE_CONFIG_CONTENT`. #179's two "prompt and MCP together are refused" regression tests now check that both reach the open. The opencode-aimock vendor test runs a replaced prompt, an appended prompt and both echo servers in one session: every agent request carries both prompts, and both echoes arrive. **Already there before this PR:** grok's `_x.ai/mcp/servers_updated`, which oar records verbatim, includes the `env` values of stdio servers from the user's own `config.toml`. Values passed through `mcpServers` never show up there. Tracked separately (#182). ## pi - pi's built-in MCP extension (`createMcpExtension`) is loaded with no `mcp.json` of its own, plus one inline extension that calls `pi.registerMcpServer` (`runtimes/pi/mcp.ts`). This is how the pi CLI itself connects servers. - I picked this over wrapping `@earendil-works/pi-mcp`'s client as custom tools: pi keeps its own tool naming, rendering, reconnects and lifecycle, and no new dependency is needed. - Tools are declared to the model directly (`exposure: "direct"`). pi's default exposure needs the codemode extension, which oar doesn't load. - The SDK connects servers on `session_start` and closes them on `session_shutdown`, and oar's opener emitted neither before. A session given servers now calls `bindExtensions({})`, and emits `session_shutdown` before dispose, so stdio servers exit (measured). One side effect: in such a session the user's own extensions also receive `session_start`. Emitting these events for every session is tracked separately (#183). - pi treats an `env` or header value starting with `!` as a shell command and expands `$NAME`. oar escapes every `$` and `!` so the value arrives literally; a unit test round-trips values through pi's own resolver. - A stdio server gets the host's environment, then `SessionOptions.env`, then the entry's own `env` on top. - Names: pi only accepts `[A-Za-z0-9_-]`, and it would merge `a-b` and `a_b` into one tool namespace. Both cases are refused before the session opens. A name another extension already registered makes the open fail, rather than running without the server. - oar's pi never loaded the user's `mcp.json`, and it still doesn't, so there is no clash with it. ## cursor (still refused) The refusal reason now says why. Cursor's agent runs on Cursor's servers. Against a hand-written stand-in for that backend (not in the repo), the SDK started the server at the first `send` and ran a `tools/call` when the backend asked for it. The missing evidence is a live run that shows Cursor's real agent choosing the tool, and the `tool_call` deltas oar records for that call. Getting it would take a login and paid tokens, so it wasn't done. cursor.md lists what such a run has to show. ## Evidence - `sea-trial/vendor/mcp-servers-acp.vendor.test.ts` runs the real grok, kimi, opencode and agy_acp_server CLIs. `sea-trial/vendor/mcp-servers-pi.vendor.test.ts` runs the bundled pi SDK. Both use aimock, with no logins and no tokens. - In each test, the model calls a stdio and an http echo server on open, then calls the stdio one again after a resume in a new process. The provider receives `echo:<text> via=<transport> token=<credential fingerprint>`, which only the echo server writes. - The same tests cover the name clash: the user's `echo` and `userecho` against the session's `echo`, with each echo's fingerprint showing which server answered. They also check that no record contains a credential. - `sea-trial/harness/aimock-acp.ts` points each ACP CLI at aimock from a fresh home. antigravity uses the public Gemini API with a dummy key and `GOOGLE_GEMINI_BASE_URL`, and the test proxy hands its role-`model` tool results to aimock as `user` (`geminiToolResultsAsUser`). - The pi test runs in CI's pi-aimock job. The ACP tests are `OAR_TEST`-gated and were run locally on all four (`OAR_TEST=<rt>-aimock`; antigravity also needs `OAR_ANTIGRAVITY_BIN`), because CI has no ACP aimock backend. - `tests/acp/acp-session-mcp-servers.test.ts` covers the ACP wire shape on new and resume, the http refusal, name checks, the redacted open error and antigravity's credential refusal, against the fake ACP agent. `tests/pi/pi-mcp-servers.test.ts` covers the pi config mapping and escaping. - Replay fixture `pi-mcp-echo`, recorded with `pnpm sea-trial:record pi-aimock mcp-echo -`. - The echo scenario helpers moved into `vendor/support/echo-mcp.ts`. Prompts now match on the current turn's user messages, because kimi follows the prompt with a `<system-reminder>`. I re-ran the claude-aimock and codex-aimock MCP vendor tests and they pass. Docs: the runtime matrix (refusals and channels), the contract comment, both READMEs, and a "Session MCP servers" section on each of the grok, kimi, opencode, antigravity, pi and cursor pages. `CI=1 pnpm run check` is green. The pi-aimock behavior suite and vendor suite pass, and so do the MCP vendor tests on all seven aimock backends. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: exe.dev user <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenCode previously refused both system-prompt options because ACP has no prompt field. Its native inline configuration can carry them: override only the selected agent's
prompt, and append a session-owned instruction file after existing instructions. Existing models, tools, permissions and configuration are preserved.The adapter uses native
debug configand, for replacement on resume, sanitizedexportoutput to identify the agent. It refuses a missing custom agent instead of recreating one, and checks the ACP mode against the overridden agent before returning the session. ExistingOPENCODE_CONFIG_CONTENTin either host or session environment conflicts explicitly; an empty replacement also refuses because native OpenCode falls back to built-in instructions. Config interpolation syntax in prompt text stays literal. The existingmcpServersrefusal remains declared and runs before prompt preparation or child startup, including when prompt options are also supplied.Temporary instructions survive later turns and are removed on failed open, disposal, or process exit. No-prompt opens remain direct. Replacement adds one native query, two on resume, each bounded at 30 seconds; append-only adds no query. Disabled or renamed defaults that select a different mode fail clearly.
runExecutablegains only an optional cwd so queries use the session's actual project.Validation:
pnpm run checkand all four mock/aimock backends, 19/19 each.Part of #171. Kimi, Antigravity and Grok landed separately; MCP remains outside this PR.
experiments/opencode-prompt-options.tsis rerunnable without login or model quota.