Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest pytest-asyncio pytest-cov black flake8 mypy
pip install pytest pytest-asyncio pytest-cov 'black>=24.0.0,<26.0.0' flake8 mypy

- name: Lint with flake8
run: |
Expand Down
52 changes: 51 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,57 @@ All notable changes to the Sugar autonomous development system will be documente
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.5.0] - Unreleased
## [3.7.0] - Unreleased

### 🔗 MINOR RELEASE: OpenCode Integration Improvements

One-command setup for OpenCode integration and new memory slash commands.

### Added

#### OpenCode Setup Command
- **`sugar opencode setup`** - One-command configuration for OpenCode
- Auto-detects OpenCode config file location
- Adds `sugar-tasks` and `sugar-memory` MCP servers
- Supports `--dry-run`, `--yes`, `--no-memory`, `--no-tasks` flags
- Parses JSON/JSONC safely, preserves existing configuration
- Idempotent - safe to run multiple times

#### Memory Slash Commands for OpenCode
- **`/sugar-remember`** - Store learnings, decisions, preferences in Sugar memory
- **`/sugar-recall`** - Search memory for relevant context
- **`/sugar-context`** - Load full project context at session start

### Changed

#### Improved Error Messages
- OpenCode client now properly distinguishes connection errors from server errors
- "Cannot connect to OpenCode server" instead of misleading "Server responded but health check failed"
- `health_check()` and `notify()` now propagate connection errors for proper handling

### Documentation
- Updated README with new `sugar opencode setup` command
- Updated `docs/user/opencode.md` with complete setup guide
- Updated static site documentation at sugar.roboticforce.io

---

## [3.6.0] - 2025-01-20

### 🔌 MINOR RELEASE: OpenCode Integration

Full integration with OpenCode via HTTP API, notifications, and memory injection.

### Added
- OpenCode HTTP client for bidirectional communication
- Task notifications (start, complete, fail) to OpenCode TUI
- Memory injection into OpenCode sessions
- Event subscription via SSE
- CLI commands: `sugar opencode status`, `sugar opencode test`, `sugar opencode notify`

---

## [3.5.0] - 2025-01-15

### 🧠 MINOR RELEASE: Memory System

Expand Down
41 changes: 18 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ Sugar has **first-class integrations** with leading AI coding agents:
claude mcp add sugar -- sugar mcp memory
```

**OpenCode** - Native plugin with real-time notifications:
**OpenCode** - One-command setup with MCP integration:
```bash
# Check integration status
sugar opencode status

# Test connection
sugar opencode test
sugar opencode setup # Automatically configures OpenCode
# Then restart OpenCode
```

Both integrations support **automatic memory injection** - Sugar injects relevant context (decisions, preferences, error patterns) into your AI sessions automatically.
Expand Down Expand Up @@ -328,37 +325,35 @@ Claude: "I'll create a Sugar task for the test fixes."

### OpenCode Integration

Sugar has native bidirectional integration with [OpenCode](https://github.com/opencode-ai/opencode):
Sugar has native MCP integration with [OpenCode](https://github.com/opencode-ai/opencode):

**Features:**
- Real-time task notifications (start, complete, fail)
- MCP servers for task management and memory access
- Automatic memory injection into OpenCode sessions
- Context-aware memory retrieval based on current work
- Learning capture from session outcomes

**Quick Setup:**
```bash
# Install OpenCode integration dependencies
pipx inject sugarai aiohttp
# One-command setup - adds Sugar MCP servers to OpenCode config
sugar opencode setup

# Check integration status
# Restart OpenCode to load the new servers
# Then verify:
sugar opencode status

# Test connection (requires OpenCode server running)
sugar opencode test

# Send a test notification
sugar opencode notify "Hello from Sugar!" --title "Test" --level success
```

**Environment Variables:**
The setup command automatically:
- Finds your OpenCode config file
- Adds `sugar-tasks` and `sugar-memory` MCP servers
- Preserves your existing configuration

**Options:**
```bash
OPENCODE_SERVER_URL=http://localhost:4096 # OpenCode server URL
SUGAR_OPENCODE_ENABLED=true # Enable/disable integration
sugar opencode setup --dry-run # Preview changes without applying
sugar opencode setup --yes # Non-interactive mode
sugar opencode setup --no-memory # Only add task server
```

When Sugar executes tasks, it automatically sends notifications to OpenCode so you can track progress in real-time.

### MCP Server Integration

Sugar provides MCP servers for Goose, Claude Code, Claude Desktop, and other MCP clients.
Expand Down
76 changes: 59 additions & 17 deletions docs/user/opencode.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
# Sugar OpenCode Integration

Sugar integrates with [OpenCode](https://github.com/opencode-ai/opencode) to provide bidirectional communication between Sugar's autonomous task queue and OpenCode sessions.
Sugar integrates with [OpenCode](https://github.com/opencode-ai/opencode) to provide MCP-based communication between Sugar's autonomous task queue and OpenCode sessions.

## Overview

The OpenCode integration enables:
- **Task notifications** - Get notified in OpenCode when Sugar tasks complete or fail
- **MCP servers** - Task management and memory access directly in OpenCode
- **Memory injection** - Automatically inject relevant context into OpenCode sessions
- **Learning capture** - Capture learnings from OpenCode sessions back to Sugar memory
- **Event subscription** - React to OpenCode events in Sugar

## Quick Start

```bash
# Install with OpenCode support
pipx install 'sugarai[opencode]'
# Or add to existing installation
pipx inject sugarai aiohttp
# One-command setup - configures OpenCode automatically
sugar opencode setup

# Restart OpenCode to load the new MCP servers

# Check OpenCode connection
# Verify setup
sugar opencode status
```

# Test notification
sugar opencode test
The setup command:
- Finds your OpenCode config file (`~/.config/opencode/opencode.json` or `.opencode/opencode.json`)
- Adds `sugar-tasks` and `sugar-memory` MCP servers
- Preserves your existing configuration

# Send manual notification
sugar opencode notify "Build completed" --level success
```
After setup, OpenCode will have access to Sugar's tools:
- `sugar_add_task` - Add tasks to the queue
- `sugar_list_tasks` - View queued tasks
- `sugar_remember` - Store memories
- `sugar_recall` - Search memories

## Configuration

Expand Down Expand Up @@ -69,9 +73,46 @@ integrations:

## CLI Commands

### `sugar opencode setup`

Automatically configure OpenCode to use Sugar's MCP servers.

```bash
sugar opencode setup [options]

Options:
--yes, -y Skip confirmation prompts
--dry-run Show what would be changed without modifying files
--config PATH Path to OpenCode config file (auto-detected if not specified)
--no-memory Don't add the memory MCP server
--no-tasks Don't add the tasks MCP server
```

**Examples:**

```bash
# Interactive setup (recommended)
sugar opencode setup

# Non-interactive for scripts/CI
sugar opencode setup --yes

# Preview changes without applying
sugar opencode setup --dry-run

# Only add task management (no memory)
sugar opencode setup --no-memory
```

The command searches for OpenCode config in this order:
1. `OPENCODE_CONFIG` environment variable
2. `OPENCODE_CONFIG_DIR` environment variable
3. `.opencode/opencode.json` (project-local)
4. `~/.config/opencode/opencode.json` (user config)

### `sugar opencode status`

Check OpenCode server connectivity and configuration.
Check OpenCode integration status and configuration.

```bash
sugar opencode status
Expand All @@ -80,14 +121,15 @@ sugar opencode status
Output:
```
OpenCode Integration Status
Enabled: Yes
aiohttp: Installed
Server URL: http://localhost:4096
Status: Connected
Active Sessions: 2
Auto-inject: Yes
```

### `sugar opencode test`

Send a test notification to verify the integration works.
Test connection to the OpenCode HTTP server (if enabled).

```bash
sugar opencode test
Expand Down
61 changes: 61 additions & 0 deletions packages/opencode-plugin/commands/sugar-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
name: sugar-context
description: Load project context from Sugar's memory at session start
---

# Project Context

Load and display the full project context from Sugar's memory system.

## When to Use

- At the start of a new session
- Before working on an unfamiliar part of the codebase
- When you need a refresher on project conventions

## Process

1. Call `get_project_context` MCP tool
2. Present the context in a clear, organized format
3. Highlight any critical preferences or patterns

## Presentation

Format the context as:

```
Project Context from Sugar Memory
=================================

Coding Preferences:
- Always use async/await, never callbacks
- Prefer early returns over nested conditionals
- Use TypeScript strict mode

Recent Decisions:
- Using PostgreSQL for the database (ACID, JSON support)
- JWT with RS256 for authentication tokens
- Monorepo structure with pnpm workspaces

Known Error Patterns:
- Login loop: missing return after redirect
- Connection timeout: increase pool size to 20

File Context:
- src/auth/ handles all authentication logic
- src/api/routes/ contains REST endpoints
```

## After Loading

1. Summarize key points relevant to the current task
2. Mention `/sugar-remember` to add new context
3. Suggest `/sugar-recall [topic]` for deeper dives

## If No Context

If memory is empty:

1. Explain this is a new project or memory hasn't been populated
2. Suggest storing key decisions with `/sugar-remember`
3. Offer to help identify important context to store
79 changes: 79 additions & 0 deletions packages/opencode-plugin/commands/sugar-recall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: sugar-recall
description: Search Sugar's memory for relevant context
---

# Recall Memory

You are helping the user retrieve relevant information from Sugar's persistent memory system.

## Process

1. **Understand the Query**: What information does the user need?
2. **Search Memory**: Use the appropriate MCP tool
3. **Present Results**: Format findings clearly
4. **Suggest Actions**: Offer to store new learnings if relevant

## Available Tools

| Tool | Use When |
| ---- | -------- |
| `recall` | Get formatted context about a topic (best for general queries) |
| `search_memory` | Search with scoring, get structured results |
| `get_project_context` | Get overall project context (preferences, decisions, patterns) |
| `list_recent_memories` | Browse recent entries, optionally by type |

## Example Interactions

**General recall:**

> User: "what do we know about authentication?"
> Use: recall with topic="authentication"

**Specific search:**

> User: "find all our database decisions"
> Use: search_memory with query="database decisions architecture"

**Project context:**

> User: "what are our coding preferences?"
> Use: get_project_context (returns all preferences, decisions, patterns)

**Recent memories:**

> User: "what did we learn recently?"
> Use: list_recent_memories with limit=10

## Presentation

Format results clearly:

```
Found 3 relevant memories:

1. [decision] Using PostgreSQL for ACID compliance
Stored: 2 days ago

2. [preference] Always use prepared statements for queries
Stored: 1 week ago

3. [error_pattern] Connection pool exhaustion: increase max_connections
Stored: 3 days ago
```

## When No Results

If no memories found:

1. Confirm what was searched
2. Suggest alternative search terms
3. Offer to store new information with `/sugar-remember`

## Proactive Use

Consider using memory tools proactively:

- At the start of a task: `get_project_context`
- When encountering errors: `search_memory` for similar patterns
- Before making decisions: `recall` related past decisions
Loading