Skip to content

feat: Add OpenCode integration for bidirectional AI agent communication#59

Merged
cdnsteve merged 4 commits intodevelopfrom
feature/opencode
Jan 21, 2026
Merged

feat: Add OpenCode integration for bidirectional AI agent communication#59
cdnsteve merged 4 commits intodevelopfrom
feature/opencode

Conversation

@cdnsteve
Copy link
Member

@cdnsteve cdnsteve commented Jan 21, 2026

Summary

  • Implements full OpenCode integration enabling bidirectional communication between Sugar and OpenCode AI coding agents
  • Adds MCP Task Server with 6 tools for task queue management via Model Context Protocol
  • Creates TypeScript plugin for OpenCode with tools, hooks, and slash commands
  • Builds Python SDK integration with async HTTP client, context injection, and learning capture
  • Integrates task lifecycle notifications into Sugar's executor

Changes

Phase 1 - MCP Task Server

  • New sugar/mcp/task_server.py with tools: sugar_add_task, sugar_list_tasks, sugar_view_task, sugar_update_task, sugar_task_status, sugar_remove_task
  • CLI command: sugar mcp tasks

Phase 2 - TypeScript OpenCode Plugin

  • New packages/opencode-plugin/ package
  • 8 custom tools for Sugar task management
  • Session lifecycle hooks for automatic memory injection
  • 6 slash command templates

Phase 3 - Python SDK Integration

  • New sugar/integrations/opencode/ module
  • OpenCodeClient - async HTTP client with aiohttp
  • OpenCodeConfig - configuration from env vars or sugar.yaml
  • Data models: Session, Message, Event, NotificationLevel

Phase 4 - Memory Context Injection

  • ContextInjector with multi-factor relevance scoring (semantic, recency, importance, frequency, type)
  • LearningCapture for extracting decisions, preferences, and error patterns
  • Token budget management (2000 session start, 800 per-prompt, 300 error context)

Execution Integration

  • OpenCodeNotifier for fire-and-forget task notifications
  • Integrated into AgentSDKExecutor for task lifecycle events
  • Non-blocking notifications on task start, complete, and fail

CLI Commands

  • sugar opencode status - Check integration status
  • sugar opencode test - Test server connection
  • sugar opencode notify - Send test notification

Dependencies

  • Added opencode optional dependency group with aiohttp
  • Updated all group to include opencode

Test Plan

  • 41 MCP Task Server tests passing
  • 45 OpenCode integration tests passing
  • TypeScript plugin compiles successfully
  • CLI commands work (sugar opencode status)
  • Manual test with OpenCode server (requires OpenCode running)

Implements full OpenCode integration as designed in the research phases:

Phase 1 - MCP Task Server:
- New sugar/mcp/task_server.py with 6 MCP tools for task management
- Tools: sugar_add_task, sugar_list_tasks, sugar_view_task, etc.
- CLI command: sugar mcp tasks

Phase 2 - TypeScript OpenCode Plugin:
- New packages/opencode-plugin/ with tools, hooks, and slash commands
- 8 custom tools for Sugar task management
- Session lifecycle hooks for memory injection

Phase 3 - Python SDK Integration:
- New sugar/integrations/opencode/ module
- OpenCodeClient for HTTP communication with aiohttp
- OpenCodeConfig with env and sugar.yaml support
- Data models: Session, Message, Event, NotificationLevel

Phase 4 - Memory Context Injection:
- ContextInjector with multi-factor relevance scoring
- LearningCapture for extracting learnings from sessions
- Token budget management (2000 session, 800 prompt, 300 error)

Execution Integration:
- OpenCodeNotifier for fire-and-forget task notifications
- Integrated into AgentSDKExecutor for task lifecycle events
- Non-blocking notifications on start, complete, and fail

CLI Commands:
- sugar opencode status - Check integration status
- sugar opencode test - Test server connection
- sugar opencode notify - Send test notification

Tests: 86 new tests (41 MCP + 45 OpenCode integration)
- Add Native AI Agent Integrations section at top
- Add OpenCode Integration section with setup instructions
- Update Features section to highlight integrations
- Add tagline for v3.5 milestone release
@cdnsteve cdnsteve merged commit e1f606c into develop Jan 21, 2026
22 checks passed
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