---
description: Sync backlog tasks with knowledge base specs
agent: orchestrator
---

# Sync Backlog ↔ Knowledge Base

**Project:** $(basename $(pwd))
**Sync Time:** $(date '+%Y-%m-%d %H:%M:%S')

## Phase 1: Current State Analysis

### Backlog Tasks Status

Use `backlog_task_list` with status filters:

- In Progress tasks: Call backlog_task_list(status="In Progress")
- Pending tasks: Call backlog_task_list(status="To Do", limit=10)

### Knowledge Base Specs

Project specs: !`ls -la .opencode/memory/ 2>/dev/null || echo "No memory directory"`
Spec files: !`find .opencode/memory/ -name "*.md" -type f 2>/dev/null || echo "No spec files found"`

## Phase 2: Identify Gaps

### Tasks Without Specs

Use `backlog_task_list` to get all tasks, then check specs directory:

1. Call backlog_task_list() to get all tasks
2. For each task, use backlog_task_view(id) to get details
3. Check if corresponding spec file exists in specs directory
4. Report missing specs

### Specs Without Tasks

Use filesystem tools to find orphaned specs:

1. Use `list` tool on .opencode/memory/
2. For each .md file, search @backlog/tasks for matching task
3. Report specs without corresponding tasks

## Phase 3: Status Synchronization

### Check Task vs Spec Status

Compare backlog task status with spec file status:

1. Call backlog_task_list() to get all tasks with status
2. For each task, read corresponding spec file using `read` tool
3. Extract status from spec file (look for "**Status:**" line)
4. Compare and report mismatches

## Phase 4: Auto-Sync Actions

### Create Missing Specs

For each task without a spec file:

1. Call backlog_task_view(id) to get full task details
2. Extract title, description, acceptance criteria
3. Use `write` tool to create spec file at .opencode/memory/TASK-NAME.md
4. Template includes:
   - Title, project, created date, status (Draft)
   - Backlog task reference (@backlog/tasks#ID)
   - Problem section (from description)
   - Solution section (placeholder)
   - Implementation steps (placeholder)
   - Acceptance criteria (from task)
   - AI drift log section

## Phase 5: Recommendations

### Immediate Actions

- [ ] Review status mismatches
- [ ] Complete missing spec sections
- [ ] Create tasks for orphaned specs
- [ ] Update task acceptance criteria

### Process Improvements

- [ ] Set up auto-sync cron job
- [ ] Add spec creation to task template
- [ ] Implement status propagation
- [ ] Regular sync schedule

### Sync Summary

- **Total Tasks:** [Count from analysis]
- **Total Specs:** [Count from analysis]
- **Missing Specs:** [Count from gaps]
- **Orphaned Specs:** [Count from gaps]
- **Status Mismatches:** [Count from analysis]

---

_Run this command daily or when tasks/specs change_
