blue/docs/rfcs/0002-port-coherence-functionality.md
Eric Garcia 3e157d76a6 feat(core): Complete Phase 1 - Foundation porting from coherence-mcp
Port core functionality from coherence-mcp to blue-core:

- store.rs: SQLite persistence with schema v1, WAL mode, FTS5 search
  - documents, document_links, tasks, worktrees, metadata tables
  - Blue's voice in all error messages

- documents.rs: Enhanced with markdown generation
  - Rfc, Spike, Adr, Decision types with to_markdown() methods
  - Blue's signature at the end of generated docs

- state.rs: ProjectState aggregation
  - active_items(), ready_items(), stalled_items(), draft_items()
  - generate_hint() for contextual recommendations
  - status_summary() for complete overview

- repo.rs: Git detection and worktree operations
  - detect_blue() finds .blue/ directory structure
  - WorktreeInfo with rfc_title() extraction
  - create_worktree(), remove_worktree(), is_branch_merged()

- workflow.rs: Status transitions
  - RfcStatus, SpikeOutcome, SpikeStatus, PrdStatus enums
  - Transition validation with helpful error messages

MCP server updated with 9 tools:
- blue_status, blue_next, blue_rfc_create, blue_rfc_get
- blue_rfc_update_status, blue_rfc_plan, blue_rfc_validate
- blue_rfc_task_complete, blue_search

14 unit tests passing.

RFC 0002 tracks remaining phases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 00:43:25 -05:00

214 lines
6.3 KiB
Markdown

# RFC 0002: Port Coherence Functionality
| | |
|---|---|
| **Status** | In Progress |
| **Date** | 2026-01-24 |
| **Source Spike** | blue-feature-gap-analysis |
---
## Summary
Port the essential functionality from coherence-mcp to blue, maintaining Blue's voice and philosophy while gaining the workflow capabilities that make coherence useful.
## Problem
Blue currently has ~2% of coherence-mcp's functionality:
- 3 MCP tools (vs 35)
- 0 handler modules (vs 28)
- ~50 LOC core (vs 8,796)
- 0 database tables (vs 14)
Without these capabilities, blue can't manage RFCs, track work, or provide meaningful project status.
## Proposal
Port coherence-mcp in 4 phases, adapting to Blue's voice throughout.
### Phase 1: Foundation
**Goal:** Basic document management and persistence.
| Component | Source | Target | Notes |
|-----------|--------|--------|-------|
| store.rs | alignment-core | blue-core | Rename tables, Blue voice in errors |
| documents.rs | alignment-core | blue-core | Keep existing Blue structs, add methods |
| state.rs | alignment-core | blue-core | ProjectState → BlueState |
| repo.rs | alignment-core | blue-core | detect_alignment → detect_blue |
| workflow.rs | alignment-core | blue-core | Status transitions |
**Database schema:**
- documents, document_links, tasks, worktrees, metadata
- FTS5 for search
- Schema version 1 (fresh start, not migrating from coherence)
**MCP tools (Phase 1):**
- blue_status
- blue_next
- blue_rfc_create
- blue_rfc_get
- blue_rfc_update_status
- blue_rfc_plan
- blue_rfc_validate
- blue_rfc_complete
- blue_rfc_task_complete
### Phase 2: Workflow
**Goal:** Full RFC/Spike/ADR lifecycle + PR workflow.
| Component | Source | Target |
|-----------|--------|--------|
| rfc.rs | handlers | blue-mcp/handlers |
| spike.rs | handlers | blue-mcp/handlers |
| adr.rs | handlers | blue-mcp/handlers |
| decision.rs | handlers | blue-mcp/handlers |
| worktree.rs | handlers | blue-mcp/handlers |
| pr.rs | handlers | blue-mcp/handlers |
| release.rs | handlers | blue-mcp/handlers |
| search.rs | handlers | blue-mcp/handlers |
**MCP tools (Phase 2):**
- blue_spike_create, blue_spike_complete
- blue_adr_create, blue_decision_create
- blue_worktree_create, blue_worktree_list, blue_worktree_remove
- blue_pr_create, blue_pr_verify, blue_pr_check_item, blue_pr_merge
- blue_release_create
- blue_search
### Phase 3: Advanced
**Goal:** Multi-agent coordination and reminders.
| Component | Source | Target |
|-----------|--------|--------|
| staging.rs | handlers | blue-mcp/handlers |
| reminder.rs | handlers | blue-mcp/handlers |
| session.rs | handlers | blue-mcp/handlers |
| env.rs | handlers | blue-mcp/handlers |
**Database additions:**
- staging_locks, staging_lock_queue, staging_deployments
- active_sessions
- reminders
### Phase 4: Specialized
**Goal:** Code intelligence and quality tools.
| Component | Source | Target |
|-----------|--------|--------|
| code_store.rs | alignment-core | blue-core |
| symbol_extractor.rs | alignment-core | blue-core |
| lint.rs | handlers | blue-mcp/handlers |
| audit.rs | handlers | blue-mcp/handlers |
| guide.rs | handlers | blue-mcp/handlers |
## What NOT to Port
- **Parked/Gated items** - Half-implemented in coherence, skip for now
- **Post-mortems/Runbooks** - Low usage, add later if needed
- **Dialogue tools** - Specialized, port only if needed
- **Infrastructure indexing** - Complex, defer to Phase 5
## Blue's Voice Adaptation
All ported code must speak as Blue:
```rust
// Coherence style
return Err(ServerError::AlignmentNotDetected);
// Blue style
return Err(ServerError::NotHome("Can't find Blue here. Run 'blue init' first?"));
```
```rust
// Coherence message
"RFC created successfully"
// Blue message
"Created RFC '{}'. Want me to help fill in the details?"
```
## Directory Structure After Port
```
blue/
├── crates/
│ └── blue-core/
│ ├── src/
│ │ ├── lib.rs
│ │ ├── documents.rs # Document types
│ │ ├── store.rs # SQLite persistence
│ │ ├── state.rs # Project state
│ │ ├── repo.rs # Git operations
│ │ ├── workflow.rs # Status transitions
│ │ ├── voice.rs # Blue's tone (existing)
│ │ └── search.rs # FTS5 search
│ └── Cargo.toml
│ └── blue-mcp/
│ ├── src/
│ │ ├── lib.rs
│ │ ├── server.rs # MCP server
│ │ ├── error.rs # Error types
│ │ ├── tools.rs # Tool definitions
│ │ └── handlers/
│ │ ├── mod.rs
│ │ ├── rfc.rs
│ │ ├── spike.rs
│ │ ├── adr.rs
│ │ ├── worktree.rs
│ │ ├── pr.rs
│ │ ├── search.rs
│ │ └── ...
│ └── Cargo.toml
└── apps/
└── blue-cli/
```
## Goals
1. Feature parity with coherence-mcp core workflow
2. Blue's voice and philosophy throughout
3. Fresh schema (no migration baggage)
4. Cleaner code structure from lessons learned
## Non-Goals
1. 100% feature parity (skip rarely-used features)
2. Backward compatibility with coherence databases
3. Supporting both alignment_ and blue_ tool names
## Implementation Progress
### Phase 1: Foundation - COMPLETE
- [x] store.rs - SQLite persistence with schema v1, WAL mode, FTS5 search
- [x] documents.rs - Rfc, Spike, Adr, Decision with markdown generation
- [x] state.rs - ProjectState with active/ready/stalled/draft items
- [x] repo.rs - detect_blue(), worktree operations
- [x] workflow.rs - RfcStatus, SpikeOutcome, transitions
- [x] 9 MCP tools: blue_status, blue_next, blue_rfc_create, blue_rfc_get,
blue_rfc_update_status, blue_rfc_plan, blue_rfc_validate,
blue_rfc_task_complete, blue_search
- [x] 14 unit tests passing
- [x] Blue's voice in all error messages
### Phase 2-4: Pending
## Test Plan
- [ ] blue init creates .blue/ directory structure
- [x] blue rfc create persists to SQLite
- [x] blue status shows active/ready/stalled items
- [x] blue search finds documents by keyword
- [x] Blue's voice in all error messages
- [ ] Worktree operations work with git
---
*"Right then. Quite a bit to port. But we'll take it step by step."*
— Blue