Skip to content

feat(SDKBridge): add in-process agent backend via OpenAgentSDK#1

Merged
terryso merged 9 commits intomainfrom
feat/sdk-bridge-backend
Apr 30, 2026
Merged

feat(SDKBridge): add in-process agent backend via OpenAgentSDK#1
terryso merged 9 commits intomainfrom
feat/sdk-bridge-backend

Conversation

@terryso
Copy link
Copy Markdown
Owner

@terryso terryso commented Apr 30, 2026

Summary

  • Add SDKBridge as a new in-process agent backend using the OpenAgentSDK Swift package, replacing the external opencode serve + HTTP/SSE approach with direct Agent.stream() calls
  • Add BackendBridge protocol abstraction so the app can switch between legacy OpenCode HTTP bridge and the new SDK bridge
  • Add MCP server & environment variable integration, skill directories support, and session context restoration via SessionStore
  • Add custom MCP server configuration UI in Advanced Settings
  • Fix OpenCodeEvent.toMessage() to skip secondary finish events

Changed Files

  • SDKBridge.swift — Core in-process agent backend (361 lines)
  • BackendBridge.swift — Protocol + shared bridge types
  • AppState+Bridge.swift — Bridge orchestration and configuration wiring
  • AdvancedSettingsView.swift — MCP server configuration UI
  • ConfigManager+SkillsConfig.swift — Skill directory config support
  • OpenCodeEvent.swift — Fix for duplicate finish events

Test Plan

  • Verify SDK bridge connects and streams responses with valid API key
  • Verify MCP server configs are passed through to the agent
  • Verify session restore works after app restart
  • Verify custom MCP server UI adds/removes entries correctly
  • Verify existing OpenCode HTTP bridge still works when selected as backend
  • Run MotiveTests suite

🤖 Generated with Claude Code

nick and others added 9 commits April 30, 2026 18:37
Replace external opencode serve process with SDKBridge actor that uses
Agent.stream() API. Adds BackendBridge enum wrapper, backend type setting,
and AdvancedSettingsView picker for switching between OpenCode and SDK modes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pass sessionStore + sessionId to AgentOptions so the SDK automatically
persists and restores conversation history across prompts in the same session.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pass MCP servers from SkillRegistry and environment variables from
ConfigManager to the SDK's AgentOptions so the SDK backend can use
the same external tools (motive-memory, custom MCP servers, etc.)
as the OpenCode backend.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Pass skillDirectories to AgentOptions so SDK discovers SKILL.md skills
- Fix critical bug where core tools (Bash, Read, Write, etc.) were not
  loaded when no MCP servers were configured (SDK's assembleFullToolPool
  returns empty on no-MCP path)
- Add debug log level support
- Remove invalid motive-memory MCP entry (it's an OpenCode plugin, not MCP)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add missing modelProviderID parameter to OpenCodeBridge.Configuration
  in OpenCodeBridgeTests
- Add missing provider/modelName/apiKey parameters to
  OpenCodeConfigGenerator.Inputs in ConfigManagerConfigTests
- Fix permissionRulesDoNotContainQuestionDeny test: question is now a
  valid ToolPermission case, so assert it's not denied instead of nil

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Secondary finish events (isSecondaryFinish=true, e.g., session.idle
after error) should not produce conversation messages. Added early
return in toMessage() to match test expectations.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Add ability to configure custom MCP stdio servers in Settings >
Advanced > MCP Servers (visible when SDK backend is selected).
Servers are persisted as JSON in UserDefaults and merged into
the SDKBridge's MCP config alongside skill-based entries.

- CustomMcpServerConfig: Codable model with name, command, args,
  env, and enabled toggle
- ConfigManager: @AppStorage + computed property for persistence
- AppState+Bridge: merge custom servers in buildSDKMcpServers()
- AdvancedSettingsView: collapsible section with add/edit/delete
  sheet for server configuration

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Call configureBridge() before every submitIntent/resumeSession call.
This fixes "SDK bridge not configured" errors that occur when the
async configuration in start() hasn't completed yet, or when settings
changes trigger a restart that races with prompt submission.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…ey support

- Inject extended PATH (nvm, homebrew, etc.) into MCP server env vars
  so MCP servers can find node/python executables in macOS GUI app context
- Add detailed debug logging for MCP server config in configureBridge and createAgent
- Allow empty API key for providers that support optional auth (LM Studio, Ollama)
- Guard submitIntent/resumeSession against proceeding after configureBridge sets error
- Always include core+specialist tools regardless of MCP server presence
- Handle bridge type mismatch by rebuilding bridge in configureBridge

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@terryso terryso merged commit 1c464bc into main Apr 30, 2026
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