From 726151bfeaf3f0f0c4a6a1d923fc7363f28b1b4e Mon Sep 17 00:00:00 2001 From: catlog22 Date: Sat, 27 Dec 2025 22:44:49 +0800 Subject: [PATCH] Refactor issue management commands and introduce lifecycle requirements - Updated lifecycle requirements in issue creation to include new fields for testing, regression, acceptance, and commit strategies. - Enhanced the planning command to generate structured output and handle multi-solution scenarios. - Improved queue formation logic to ensure valid DAG and conflict resolution. - Introduced a new interactive issue management skill for CRUD operations, allowing users to manage issues through a menu-driven interface. - Updated documentation across commands to reflect changes in task structure and output requirements. --- .claude/agents/issue-plan-agent.md | 937 ++++----------------------- .claude/agents/issue-queue-agent.md | 787 +++++----------------- .claude/commands/issue/manage.md | 826 ++--------------------- .claude/commands/issue/new.md | 51 +- .claude/commands/issue/plan.md | 289 ++------- .claude/commands/issue/queue.md | 239 +++---- .claude/skills/issue-manage/SKILL.md | 244 +++++++ 7 files changed, 746 insertions(+), 2627 deletions(-) create mode 100644 .claude/skills/issue-manage/SKILL.md diff --git a/.claude/agents/issue-plan-agent.md b/.claude/agents/issue-plan-agent.md index b0806790..cb975f4b 100644 --- a/.claude/agents/issue-plan-agent.md +++ b/.claude/agents/issue-plan-agent.md @@ -2,895 +2,234 @@ name: issue-plan-agent description: | Closed-loop issue planning agent combining ACE exploration and solution generation. - Orchestrates 4-phase workflow: Issue Understanding → ACE Exploration → Solution Planning → Validation & Output + Receives issue IDs, explores codebase, generates executable solutions with 5-phase tasks. - Core capabilities: - - ACE semantic search for intelligent code discovery - - Batch processing (1-3 issues per invocation) - - Solution JSON generation with task breakdown - - Cross-issue conflict detection - - Dependency mapping and DAG validation + Examples: + - Context: Single issue planning + user: "Plan GH-123" + assistant: "I'll fetch issue details, explore codebase, and generate solution" + - Context: Batch planning + user: "Plan GH-123,GH-124,GH-125" + assistant: "I'll plan 3 issues, detect conflicts, and register solutions" color: green --- -You are a specialized issue planning agent that combines exploration and planning into a single closed-loop workflow for issue resolution. You produce complete, executable solutions for GitHub issues or feature requests. +## Overview -## Input Context +**Agent Role**: Closed-loop planning agent that transforms GitHub issues into executable solutions. Receives issue IDs from command layer, fetches details via CLI, explores codebase with ACE, and produces validated solutions with 5-phase task lifecycle. + +**Core Capabilities**: +- ACE semantic search for intelligent code discovery +- Batch processing (1-3 issues per invocation) +- 5-phase task lifecycle (analyze → implement → test → optimize → commit) +- Cross-issue conflict detection +- Dependency DAG validation +- Auto-bind for single solution, return for selection on multiple + +**Key Principle**: Generate tasks conforming to schema with quantified delivery_criteria. + +--- + +## 1. Input & Execution + +### 1.1 Input Context ```javascript { - // Required - issue_ids: string[], // Issue IDs only (e.g., ["GH-123", "GH-124"]) - project_root: string, // Project root path for ACE search - - // Optional - batch_size: number, // Max issues per batch (default: 3) - schema_path: string // Solution schema reference + issue_ids: string[], // Issue IDs only (e.g., ["GH-123", "GH-124"]) + project_root: string, // Project root path for ACE search + batch_size?: number, // Max issues per batch (default: 3) } ``` -**Note**: Agent receives IDs only. Use `ccw issue status --json` to fetch full details. +**Note**: Agent receives IDs only. Fetch details via `ccw issue status --json`. -## Schema-Driven Output - -**CRITICAL**: Read the solution schema first to determine output structure: - -```javascript -// Step 1: Always read schema first -const schema = Read('.claude/workflows/cli-templates/schemas/solution-schema.json') - -// Step 2: Generate solution conforming to schema -const solution = generateSolutionFromSchema(schema, explorationContext) -``` - -## 4-Phase Execution Workflow +### 1.2 Execution Flow ``` Phase 1: Issue Understanding (5%) - ↓ Parse issues, extract requirements, determine complexity + ↓ Fetch details, extract requirements, determine complexity Phase 2: ACE Exploration (30%) ↓ Semantic search, pattern discovery, dependency mapping Phase 3: Solution Planning (50%) - ↓ Task decomposition, implementation steps, acceptance criteria + ↓ Task decomposition, 5-phase lifecycle, acceptance criteria Phase 4: Validation & Output (15%) ↓ DAG validation, conflict detection, solution registration ``` ---- - -## Phase 1: Issue Understanding - -### Step 1: Fetch Issue Details via CLI - -For each issue ID received, fetch full details: +#### Phase 1: Issue Understanding +**Step 1**: Fetch issue details via CLI ```bash ccw issue status --json ``` -Returns: -```json -{ - "issue": { - "id": "GH-123", - "title": "Add authentication", - "context": "...", - "affected_components": ["auth", "api"], - "lifecycle_requirements": { "test_strategy": "unit", "regression_scope": "affected" } - }, - "solutions": [], - "bound": null -} -``` - -### Step 2: Analyze Issue - -**Extract from each issue**: -- Title and description analysis -- Key requirements and constraints -- Scope identification (files, modules, features) -- Complexity determination - +**Step 2**: Analyze and classify ```javascript function analyzeIssue(issue) { return { issue_id: issue.id, requirements: extractRequirements(issue.description), - constraints: extractConstraints(issue.context), scope: inferScope(issue.title, issue.description), complexity: determineComplexity(issue) // Low | Medium | High } } - -function determineComplexity(issue) { - const keywords = issue.description.toLowerCase() - if (keywords.includes('simple') || keywords.includes('single file')) return 'Low' - if (keywords.includes('refactor') || keywords.includes('architecture')) return 'High' - return 'Medium' -} ``` **Complexity Rules**: -| Complexity | Files Affected | Task Count | -|------------|----------------|------------| -| Low | 1-2 files | 1-3 tasks | -| Medium | 3-5 files | 3-6 tasks | -| High | 6+ files | 5-10 tasks | +| Complexity | Files | Tasks | +|------------|-------|-------| +| Low | 1-2 | 1-3 | +| Medium | 3-5 | 3-6 | +| High | 6+ | 5-10 | ---- - -## Phase 2: ACE Exploration - -### ACE Semantic Search (PRIMARY) +#### Phase 2: ACE Exploration +**Primary**: ACE semantic search ```javascript -// For each issue, perform semantic search mcp__ace-tool__search_context({ project_root_path: project_root, - query: `Find code related to: ${issue.title}. ${issue.description}. Keywords: ${extractKeywords(issue)}` + query: `Find code related to: ${issue.title}. Keywords: ${extractKeywords(issue)}` }) ``` -### Exploration Checklist - -For each issue: +**Exploration Checklist**: - [ ] Identify relevant files (direct matches) -- [ ] Find related patterns (how similar features are implemented) -- [ ] Map integration points (where new code connects) -- [ ] Discover dependencies (internal and external) -- [ ] Locate test patterns (how to test this) +- [ ] Find related patterns (similar implementations) +- [ ] Map integration points +- [ ] Discover dependencies +- [ ] Locate test patterns -### Search Patterns +**Fallback**: ACE → ripgrep → Glob -```javascript -// Pattern 1: Feature location -mcp__ace-tool__search_context({ - project_root_path: project_root, - query: "Where is user authentication implemented? Keywords: auth, login, jwt, session" -}) - -// Pattern 2: Similar feature discovery -mcp__ace-tool__search_context({ - project_root_path: project_root, - query: "How are API routes protected? Find middleware patterns. Keywords: middleware, router, protect" -}) - -// Pattern 3: Integration points -mcp__ace-tool__search_context({ - project_root_path: project_root, - query: "Where do I add new middleware to the Express app? Keywords: app.use, router.use, middleware" -}) - -// Pattern 4: Testing patterns -mcp__ace-tool__search_context({ - project_root_path: project_root, - query: "How are API endpoints tested? Keywords: test, jest, supertest, api" -}) -``` - -### Exploration Output - -```javascript -function buildExplorationResult(aceResults, issue) { - return { - issue_id: issue.id, - relevant_files: aceResults.files.map(f => ({ - path: f.path, - relevance: f.score > 0.8 ? 'high' : f.score > 0.5 ? 'medium' : 'low', - rationale: f.summary - })), - modification_points: identifyModificationPoints(aceResults), - patterns: extractPatterns(aceResults), - dependencies: extractDependencies(aceResults), - test_patterns: findTestPatterns(aceResults), - risks: identifyRisks(aceResults) - } -} -``` - -### Fallback Chain - -```javascript -// ACE → ripgrep → Glob fallback -async function explore(issue, projectRoot) { - try { - return await mcp__ace-tool__search_context({ - project_root_path: projectRoot, - query: buildQuery(issue) - }) - } catch (error) { - console.warn('ACE search failed, falling back to ripgrep') - return await ripgrepFallback(issue, projectRoot) - } -} - -async function ripgrepFallback(issue, projectRoot) { - const keywords = extractKeywords(issue) - const results = [] - for (const keyword of keywords) { - const matches = Bash(`rg "${keyword}" --type ts --type js -l`) - results.push(...matches.split('\n').filter(Boolean)) - } - return { files: [...new Set(results)] } -} -``` - ---- - -## Phase 3: Solution Planning - -### Task Decomposition (Closed-Loop) +#### Phase 3: Solution Planning +**Task Decomposition** following schema: ```javascript function decomposeTasks(issue, exploration) { - const tasks = [] - let taskId = 1 - - // Group modification points by logical unit - const groups = groupModificationPoints(exploration.modification_points) - - for (const group of groups) { - tasks.push({ - id: `T${taskId++}`, - title: group.title, - scope: group.scope, - action: inferAction(group), - description: group.description, - modification_points: group.points, - - // Phase 1: Implementation - implementation: generateImplementationSteps(group, exploration), - - // Phase 2: Test - test: generateTestRequirements(group, exploration, issue.lifecycle_requirements), - - // Phase 3: Regression - regression: generateRegressionChecks(group, issue.lifecycle_requirements), - - // Phase 4: Acceptance - acceptance: generateAcceptanceCriteria(group), - - // Phase 5: Commit - commit: generateCommitSpec(group, issue), - - depends_on: inferDependencies(group, tasks), - estimated_minutes: estimateTime(group), - executor: inferExecutor(group) - }) - } - - return tasks -} - -function generateTestRequirements(group, exploration, lifecycle) { - const test = { - unit: [], - integration: [], - commands: [], - coverage_target: 80 - } - - // Generate unit test requirements based on action - if (group.action === 'Create' || group.action === 'Implement') { - test.unit.push(`Test ${group.title} happy path`) - test.unit.push(`Test ${group.title} error cases`) - } - - // Generate test commands based on project patterns - if (exploration.test_patterns?.includes('jest')) { - test.commands.push(`npm test -- --grep '${group.scope}'`) - } else if (exploration.test_patterns?.includes('vitest')) { - test.commands.push(`npx vitest run ${group.scope}`) - } else { - test.commands.push(`npm test`) - } - - // Add integration tests if needed - if (lifecycle?.test_strategy === 'integration' || lifecycle?.test_strategy === 'e2e') { - test.integration.push(`Integration test for ${group.title}`) - } - - return test -} - -function generateRegressionChecks(group, lifecycle) { - const regression = [] - - switch (lifecycle?.regression_scope) { - case 'full': - regression.push('npm test') - regression.push('npm run test:integration') - break - case 'related': - regression.push(`npm test -- --grep '${group.scope}'`) - regression.push(`npm test -- --changed`) - break - case 'affected': - default: - regression.push(`npm test -- --findRelatedTests ${group.points[0]?.file}`) - break - } - - return regression -} - -function generateCommitSpec(group, issue) { - const typeMap = { - 'Create': 'feat', - 'Implement': 'feat', - 'Update': 'feat', - 'Fix': 'fix', - 'Refactor': 'refactor', - 'Test': 'test', - 'Configure': 'chore', - 'Delete': 'chore' - } - - const scope = group.scope.split('/').pop()?.replace(/\..*$/, '') || 'core' - - return { - type: typeMap[group.action] || 'feat', - scope: scope, - message_template: `${typeMap[group.action] || 'feat'}(${scope}): ${group.title.toLowerCase()}\n\n${group.description || ''}`, - breaking: false - } + return groups.map(group => ({ + id: `TASK-${String(taskId++).padStart(3, '0')}`, + title: group.title, + type: inferType(group), // feature | bug | refactor | test | chore | docs + description: group.description, + file_context: group.files, + depends_on: inferDependencies(group, tasks), + delivery_criteria: generateDeliveryCriteria(group), // Quantified checklist + pause_criteria: identifyBlockers(group), + status: 'pending', + current_phase: 'analyze', + executor: inferExecutor(group), + priority: calculatePriority(group) + })) } ``` -### Action Type Inference +#### Phase 4: Validation & Output -```javascript -function inferAction(group) { - const actionMap = { - 'new file': 'Create', - 'create': 'Create', - 'add': 'Implement', - 'implement': 'Implement', - 'modify': 'Update', - 'update': 'Update', - 'refactor': 'Refactor', - 'config': 'Configure', - 'test': 'Test', - 'fix': 'Fix', - 'remove': 'Delete', - 'delete': 'Delete' - } +**Validation**: +- DAG validation (no circular dependencies) +- Task validation (all 5 phases present) +- Conflict detection (cross-issue file modifications) - for (const [keyword, action] of Object.entries(actionMap)) { - if (group.description.toLowerCase().includes(keyword)) { - return action - } - } - return 'Implement' -} -``` - -### Dependency Analysis - -```javascript -function inferDependencies(currentTask, existingTasks) { - const deps = [] - - // Rule 1: Update depends on Create for same file - for (const task of existingTasks) { - if (task.action === 'Create' && currentTask.action !== 'Create') { - const taskFiles = task.modification_points.map(mp => mp.file) - const currentFiles = currentTask.modification_points.map(mp => mp.file) - if (taskFiles.some(f => currentFiles.includes(f))) { - deps.push(task.id) - } - } - } - - // Rule 2: Test depends on implementation - if (currentTask.action === 'Test') { - const testTarget = currentTask.scope.replace(/__tests__|tests?|spec/gi, '') - for (const task of existingTasks) { - if (task.scope.includes(testTarget) && ['Create', 'Implement', 'Update'].includes(task.action)) { - deps.push(task.id) - } - } - } - - return [...new Set(deps)] -} - -function validateDAG(tasks) { - const graph = new Map(tasks.map(t => [t.id, t.depends_on || []])) - const visited = new Set() - const stack = new Set() - - function hasCycle(taskId) { - if (stack.has(taskId)) return true - if (visited.has(taskId)) return false - - visited.add(taskId) - stack.add(taskId) - - for (const dep of graph.get(taskId) || []) { - if (hasCycle(dep)) return true - } - - stack.delete(taskId) - return false - } - - for (const taskId of graph.keys()) { - if (hasCycle(taskId)) { - return { valid: false, error: `Circular dependency detected involving ${taskId}` } - } - } - - return { valid: true } -} -``` - -### Implementation Steps Generation - -```javascript -function generateImplementationSteps(group, exploration) { - const steps = [] - - // Step 1: Setup/Preparation - if (group.action === 'Create') { - steps.push(`Create ${group.scope} file structure`) - } else { - steps.push(`Locate ${group.points[0].target} in ${group.points[0].file}`) - } - - // Step 2-N: Core implementation based on patterns - if (exploration.patterns) { - steps.push(`Follow pattern: ${exploration.patterns}`) - } - - // Add modification-specific steps - for (const point of group.points) { - steps.push(`${point.change} at ${point.target}`) - } - - // Final step: Integration - steps.push('Add error handling and edge cases') - steps.push('Update imports and exports as needed') - - return steps.slice(0, 7) // Max 7 steps -} -``` - -### Acceptance Criteria Generation (Closed-Loop) - -```javascript -function generateAcceptanceCriteria(task) { - const acceptance = { - criteria: [], - verification: [], - manual_checks: [] - } - - // Action-specific criteria - const actionCriteria = { - 'Create': [`${task.scope} file created and exports correctly`], - 'Implement': [`Feature ${task.title} works as specified`], - 'Update': [`Modified behavior matches requirements`], - 'Test': [`All test cases pass`, `Coverage >= 80%`], - 'Fix': [`Bug no longer reproducible`], - 'Configure': [`Configuration applied correctly`] - } - - acceptance.criteria.push(...(actionCriteria[task.action] || [])) - - // Add quantified criteria - if (task.modification_points.length > 0) { - acceptance.criteria.push(`${task.modification_points.length} file(s) modified correctly`) - } - - // Generate verification steps for each criterion - for (const criterion of acceptance.criteria) { - acceptance.verification.push(generateVerificationStep(criterion, task)) - } - - // Limit to reasonable counts - acceptance.criteria = acceptance.criteria.slice(0, 4) - acceptance.verification = acceptance.verification.slice(0, 4) - - return acceptance -} - -function generateVerificationStep(criterion, task) { - // Generate executable verification for criterion - if (criterion.includes('file created')) { - return `ls -la ${task.modification_points[0]?.file} && head -20 ${task.modification_points[0]?.file}` - } - if (criterion.includes('test')) { - return `npm test -- --grep '${task.scope}'` - } - if (criterion.includes('export')) { - return `node -e "console.log(require('./${task.modification_points[0]?.file}'))"` - } - if (criterion.includes('API') || criterion.includes('endpoint')) { - return `curl -X GET http://localhost:3000/${task.scope} -v` - } - // Default: describe manual check - return `Manually verify: ${criterion}` -} +**Solution Registration**: +```bash +# Write solution and register via CLI +ccw issue bind --solution /tmp/sol.json ``` --- -## Phase 4: Validation & Output +## 2. Output Specifications -### Solution Validation - -```javascript -function validateSolution(solution) { - const errors = [] - - // Validate tasks - for (const task of solution.tasks) { - const taskErrors = validateTask(task) - if (taskErrors.length > 0) { - errors.push(...taskErrors.map(e => `${task.id}: ${e}`)) - } - } - - // Validate DAG - const dagResult = validateDAG(solution.tasks) - if (!dagResult.valid) { - errors.push(dagResult.error) - } - - // Validate modification points exist - for (const task of solution.tasks) { - for (const mp of task.modification_points) { - if (mp.target !== 'new file' && !fileExists(mp.file)) { - errors.push(`${task.id}: File not found: ${mp.file}`) - } - } - } - - return { valid: errors.length === 0, errors } -} - -function validateTask(task) { - const errors = [] - - // Basic fields - if (!/^T\d+$/.test(task.id)) errors.push('Invalid task ID format') - if (!task.title?.trim()) errors.push('Missing title') - if (!task.scope?.trim()) errors.push('Missing scope') - if (!['Create', 'Update', 'Implement', 'Refactor', 'Configure', 'Test', 'Fix', 'Delete'].includes(task.action)) { - errors.push('Invalid action type') - } - - // Phase 1: Implementation - if (!task.implementation || task.implementation.length < 2) { - errors.push('Need 2+ implementation steps') - } - - // Phase 2: Test - if (!task.test) { - errors.push('Missing test phase') - } else { - if (!task.test.commands || task.test.commands.length < 1) { - errors.push('Need 1+ test commands') - } - } - - // Phase 3: Regression - if (!task.regression || task.regression.length < 1) { - errors.push('Need 1+ regression checks') - } - - // Phase 4: Acceptance - if (!task.acceptance) { - errors.push('Missing acceptance phase') - } else { - if (!task.acceptance.criteria || task.acceptance.criteria.length < 1) { - errors.push('Need 1+ acceptance criteria') - } - if (!task.acceptance.verification || task.acceptance.verification.length < 1) { - errors.push('Need 1+ verification steps') - } - if (task.acceptance.criteria?.some(a => /works correctly|good performance|properly/i.test(a))) { - errors.push('Vague acceptance criteria') - } - } - - // Phase 5: Commit - if (!task.commit) { - errors.push('Missing commit phase') - } else { - if (!['feat', 'fix', 'refactor', 'test', 'docs', 'chore'].includes(task.commit.type)) { - errors.push('Invalid commit type') - } - if (!task.commit.scope?.trim()) { - errors.push('Missing commit scope') - } - if (!task.commit.message_template?.trim()) { - errors.push('Missing commit message template') - } - } - - return errors -} -``` - -### Conflict Detection (Batch Mode) - -```javascript -function detectConflicts(solutions) { - const fileModifications = new Map() // file -> [issue_ids] - - for (const solution of solutions) { - for (const task of solution.tasks) { - for (const mp of task.modification_points) { - if (!fileModifications.has(mp.file)) { - fileModifications.set(mp.file, []) - } - if (!fileModifications.get(mp.file).includes(solution.issue_id)) { - fileModifications.get(mp.file).push(solution.issue_id) - } - } - } - } - - const conflicts = [] - for (const [file, issues] of fileModifications) { - if (issues.length > 1) { - conflicts.push({ - file, - issues, - suggested_order: suggestOrder(issues, solutions) - }) - } - } - - return conflicts -} - -function suggestOrder(issueIds, solutions) { - // Order by: Create before Update, foundation before integration - return issueIds.sort((a, b) => { - const solA = solutions.find(s => s.issue_id === a) - const solB = solutions.find(s => s.issue_id === b) - const hasCreateA = solA.tasks.some(t => t.action === 'Create') - const hasCreateB = solB.tasks.some(t => t.action === 'Create') - if (hasCreateA && !hasCreateB) return -1 - if (hasCreateB && !hasCreateA) return 1 - return 0 - }) -} -``` - -### Output Generation - -```javascript -function generateOutput(solutions, conflicts) { - return { - solutions: solutions.map(s => ({ - issue_id: s.issue_id, - solution: s - })), - conflicts, - _metadata: { - timestamp: new Date().toISOString(), - source: 'issue-plan-agent', - issues_count: solutions.length, - total_tasks: solutions.reduce((sum, s) => sum + s.tasks.length, 0) - } - } -} -``` - -### Solution Registration via CLI - -**IMPORTANT**: Register solutions using CLI instead of direct file writes: - -```bash -# 1. Write solution JSON to temp file -echo '' > /tmp/sol-{issue-id}.json - -# 2. Register solution via CLI (auto-generates SOL-xxx ID) -ccw issue bind {issue-id} --solution /tmp/sol-{issue-id}.json -``` - -**CLI Output**: Returns registered solution ID for summary: -``` -✓ Solution SOL-20251227-001 registered (5 tasks) -``` - -### Solution Schema (Closed-Loop Tasks) - -Each task MUST include ALL 5 lifecycle phases: +### 2.1 Return Format ```json { - "issue_id": "GH-123", - "approach_name": "Direct Implementation", - "summary": "Add JWT authentication middleware to protect API routes", - "tasks": [ - { - "id": "T1", - "title": "Create JWT validation middleware", - "scope": "src/middleware/", - "action": "Create", - "description": "Create middleware to validate JWT tokens", - "modification_points": [ - { "file": "src/middleware/auth.ts", "target": "new file", "change": "Create middleware" } - ], - - "implementation": [ - "Create auth.ts file in src/middleware/", - "Implement JWT token extraction from Authorization header", - "Add token validation using jsonwebtoken library", - "Handle error cases (missing, invalid, expired tokens)", - "Export middleware function" - ], - - "test": { - "unit": [ - "Test valid token passes through", - "Test invalid token returns 401", - "Test expired token returns 401", - "Test missing token returns 401" - ], - "integration": [ - "Protected route returns 401 without token", - "Protected route returns 200 with valid token" - ], - "commands": [ - "npm test -- --grep 'auth middleware'", - "npm run test:coverage -- src/middleware/auth.ts" - ], - "coverage_target": 80 - }, - - "regression": [ - "npm test -- --grep 'existing routes'", - "npm run test:integration" - ], - - "acceptance": { - "criteria": [ - "Middleware validates JWT tokens successfully", - "Returns 401 with appropriate error for invalid tokens", - "Passes decoded user payload to request context" - ], - "verification": [ - "curl -H 'Authorization: Bearer ' /api/protected → 200", - "curl /api/protected → 401 {error: 'No token'}", - "curl -H 'Authorization: Bearer invalid' /api/protected → 401" - ], - "manual_checks": [] - }, - - "commit": { - "type": "feat", - "scope": "auth", - "message_template": "feat(auth): add JWT validation middleware\n\n- Implement token extraction and validation\n- Add error handling for invalid/expired tokens\n- Export middleware for route protection", - "breaking": false - }, - - "depends_on": [], - "estimated_minutes": 30, - "executor": "codex" - } - ], - "exploration_context": { - "relevant_files": ["src/config/env.ts"], - "patterns": "Follow existing middleware pattern", - "test_patterns": "Jest + supertest" - }, - "estimated_total_minutes": 70, - "complexity": "Medium" + "bound": [{ "issue_id": "...", "solution_id": "...", "task_count": N }], + "pending_selection": [{ "issue_id": "...", "solutions": [{ "id": "...", "description": "...", "task_count": N }] }], + "conflicts": [{ "file": "...", "issues": [...] }] } ``` ---- - -## Error Handling - -```javascript -// Error handling with fallback -async function executeWithFallback(issue, projectRoot) { - try { - // Primary: ACE semantic search - const exploration = await aceExplore(issue, projectRoot) - return await generateSolution(issue, exploration) - } catch (aceError) { - console.warn('ACE failed:', aceError.message) - - try { - // Fallback: ripgrep-based exploration - const exploration = await ripgrepExplore(issue, projectRoot) - return await generateSolution(issue, exploration) - } catch (rgError) { - // Degraded: Basic solution without exploration - return { - issue_id: issue.id, - approach_name: 'Basic Implementation', - summary: issue.title, - tasks: [{ - id: 'T1', - title: issue.title, - scope: 'TBD', - action: 'Implement', - description: issue.description, - modification_points: [{ file: 'TBD', target: 'TBD', change: issue.title }], - implementation: ['Analyze requirements', 'Implement solution', 'Test and validate'], - acceptance: ['Feature works as described'], - depends_on: [], - estimated_minutes: 60 - }], - exploration_context: { relevant_files: [], patterns: 'Manual exploration required' }, - estimated_total_minutes: 60, - complexity: 'Medium', - _warning: 'Degraded mode - manual exploration required' - } - } - } -} -``` +### 2.2 Binding Rules | Scenario | Action | |----------|--------| -| ACE search returns no results | Fallback to ripgrep, warn user | -| Circular task dependency | Report error, suggest fix | -| File not found in codebase | Flag as "new file", update modification_points | -| Ambiguous requirements | Add clarification_needs to output | +| Single solution | Register AND auto-bind | +| Multiple solutions | Register only, return for user selection | + +### 2.3 Task Schema + +**Schema-Driven Output**: Read schema before generating tasks: +```bash +cat .claude/workflows/cli-templates/schemas/issue-task-jsonl-schema.json +``` + +**Required Fields**: +- `id`: Task ID (pattern: `TASK-NNN`) +- `title`: Short summary (max 100 chars) +- `type`: feature | bug | refactor | test | chore | docs +- `description`: Detailed instructions +- `depends_on`: Array of prerequisite task IDs +- `delivery_criteria`: Checklist items defining completion +- `status`: pending | ready | in_progress | completed | failed | paused | skipped +- `current_phase`: analyze | implement | test | optimize | commit | done +- `executor`: agent | codex | gemini | auto + +**Optional Fields**: +- `file_context`: Relevant files/globs +- `pause_criteria`: Conditions to halt execution +- `priority`: 1-5 (1=highest) +- `phase_results`: Results from each execution phase + +### 2.4 Solution File Structure + +``` +.workflow/issues/solutions/{issue-id}.jsonl +``` + +Each line is a complete solution JSON. --- -## Quality Standards +## 3. Quality Standards -### Acceptance Criteria Quality +### 3.1 Acceptance Criteria | Good | Bad | |------|-----| | "3 API endpoints: GET, POST, DELETE" | "API works correctly" | | "Response time < 200ms p95" | "Good performance" | | "All 4 test cases pass" | "Tests pass" | -| "JWT token validated with secret from env" | "Authentication works" | -### Task Validation Checklist +### 3.2 Validation Checklist -Before outputting solution: - [ ] ACE search performed for each issue - [ ] All modification_points verified against codebase - [ ] Tasks have 2+ implementation steps -- [ ] Tasks have 1+ quantified acceptance criteria -- [ ] Dependencies form valid DAG (no cycles) -- [ ] Estimated time is reasonable +- [ ] All 5 lifecycle phases present +- [ ] Quantified acceptance criteria with verification +- [ ] Dependencies form valid DAG +- [ ] Commit follows conventional commits ---- - -## Key Reminders +### 3.3 Guidelines **ALWAYS**: -1. Use ACE semantic search (`mcp__ace-tool__search_context`) as PRIMARY exploration tool -2. Read schema first before generating solution output -3. Include `depends_on` field (even if empty `[]`) -4. Quantify acceptance criteria with specific, testable conditions -5. Validate DAG before output (no circular dependencies) -6. Include file:line references in modification_points where possible -7. Detect and report cross-issue file conflicts in batch mode -8. Include exploration_context with patterns and relevant_files -9. **Generate ALL 5 lifecycle phases for each task**: - - `implementation`: 2-7 concrete steps - - `test`: unit tests, commands, coverage target - - `regression`: regression check commands - - `acceptance`: criteria + verification steps - - `commit`: type, scope, message template -10. Infer test commands from project's test framework -11. Generate commit message following conventional commits +1. Read schema first: `cat .claude/workflows/cli-templates/schemas/issue-task-jsonl-schema.json` +2. Use ACE semantic search as PRIMARY exploration tool +3. Fetch issue details via `ccw issue status --json` +4. Quantify delivery_criteria with testable conditions +5. Validate DAG before output +6. Single solution → auto-bind; Multiple → return for selection **NEVER**: 1. Execute implementation (return plan only) -2. Use vague acceptance criteria ("works correctly", "good performance") -3. Create circular dependencies in task graph -4. Skip task validation before output -5. Omit required fields from solution schema -6. Assume file exists without verification -7. Generate more than 10 tasks per issue -8. Skip ACE search (unless fallback triggered) -9. **Omit any of the 5 lifecycle phases** (test, regression, acceptance, commit) -10. Skip verification steps in acceptance criteria +2. Use vague criteria ("works correctly", "good performance") +3. Create circular dependencies +4. Generate more than 10 tasks per issue +5. Bind when multiple solutions exist + +**OUTPUT**: +1. Register solutions via `ccw issue bind --solution ` +2. Return JSON with `bound`, `pending_selection`, `conflicts` +3. Solutions written to `.workflow/issues/solutions/{issue-id}.jsonl` diff --git a/.claude/agents/issue-queue-agent.md b/.claude/agents/issue-queue-agent.md index 008b5db4..20e5b85f 100644 --- a/.claude/agents/issue-queue-agent.md +++ b/.claude/agents/issue-queue-agent.md @@ -1,702 +1,235 @@ --- name: issue-queue-agent description: | - Task ordering agent for issue queue formation with dependency analysis and conflict resolution. - Orchestrates 4-phase workflow: Dependency Analysis → Conflict Detection → Semantic Ordering → Group Assignment + Task ordering agent for queue formation with dependency analysis and conflict resolution. + Receives tasks from bound solutions, resolves conflicts, produces ordered execution queue. - Core capabilities: - - ACE semantic search for relationship discovery - - Cross-issue dependency DAG construction - - File modification conflict detection - - Conflict resolution with execution ordering - - Semantic priority calculation (0.0-1.0) - - Parallel/Sequential group assignment + Examples: + - Context: Single issue queue + user: "Order tasks for GH-123" + assistant: "I'll analyze dependencies and generate execution queue" + - Context: Multi-issue queue with conflicts + user: "Order tasks for GH-123, GH-124" + assistant: "I'll detect conflicts, resolve ordering, and assign groups" color: orange --- -You are a specialized queue formation agent that analyzes tasks from bound solutions, resolves conflicts, and produces an ordered execution queue. You focus on optimal task ordering across multiple issues. +## Overview -## Input Context +**Agent Role**: Queue formation agent that transforms tasks from bound solutions into an ordered execution queue. Analyzes dependencies, detects file conflicts, resolves ordering, and assigns parallel/sequential groups. + +**Core Capabilities**: +- Cross-issue dependency DAG construction +- File modification conflict detection +- Conflict resolution with semantic ordering rules +- Priority calculation (0.0-1.0) +- Parallel/Sequential group assignment + +**Key Principle**: Produce valid DAG with no circular dependencies and optimal parallel execution. + +--- + +## 1. Input & Execution + +### 1.1 Input Context ```javascript { - // Required - tasks: [ - { - issue_id: string, // Issue ID (e.g., "GH-123") - solution_id: string, // Solution ID (e.g., "SOL-001") - task: { - id: string, // Task ID (e.g., "T1") - title: string, - scope: string, - action: string, // Create | Update | Implement | Refactor | Test | Fix | Delete | Configure - modification_points: [ - { file: string, target: string, change: string } - ], - depends_on: string[] // Task IDs within same issue - }, - exploration_context: object + tasks: [{ + issue_id: string, // e.g., "GH-123" + solution_id: string, // e.g., "SOL-001" + task: { + id: string, // e.g., "TASK-001" + title: string, + type: string, + file_context: string[], + depends_on: string[] } - ], - - // Optional - project_root: string, // Project root for ACE search - existing_conflicts: object[], // Pre-identified conflicts - rebuild: boolean // Clear and regenerate queue + }], + project_root?: string, + rebuild?: boolean } ``` -## 4-Phase Execution Workflow +### 1.2 Execution Flow ``` Phase 1: Dependency Analysis (20%) ↓ Parse depends_on, build DAG, detect cycles -Phase 2: Conflict Detection + ACE Enhancement (30%) - ↓ Identify file conflicts, ACE semantic relationship discovery +Phase 2: Conflict Detection (30%) + ↓ Identify file conflicts across issues Phase 3: Conflict Resolution (25%) - ↓ Determine execution order for conflicting tasks -Phase 4: Semantic Ordering & Grouping (25%) - ↓ Calculate priority, topological sort, assign groups + ↓ Apply ordering rules, update DAG +Phase 4: Ordering & Grouping (25%) + ↓ Topological sort, assign groups ``` --- -## Phase 1: Dependency Analysis +## 2. Processing Logic -### Build Dependency Graph +### 2.1 Dependency Graph ```javascript function buildDependencyGraph(tasks) { - const taskGraph = new Map() - const fileModifications = new Map() // file -> [taskKeys] + const graph = new Map() + const fileModifications = new Map() for (const item of tasks) { - const taskKey = `${item.issue_id}:${item.task.id}` - taskGraph.set(taskKey, { - ...item, - key: taskKey, - inDegree: 0, - outEdges: [] - }) + const key = `${item.issue_id}:${item.task.id}` + graph.set(key, { ...item, key, inDegree: 0, outEdges: [] }) - // Track file modifications for conflict detection - for (const mp of item.task.modification_points || []) { - if (!fileModifications.has(mp.file)) { - fileModifications.set(mp.file, []) - } - fileModifications.get(mp.file).push(taskKey) + for (const file of item.task.file_context || []) { + if (!fileModifications.has(file)) fileModifications.set(file, []) + fileModifications.get(file).push(key) } } - // Add explicit dependency edges (within same issue) - for (const [key, node] of taskGraph) { + // Add dependency edges + for (const [key, node] of graph) { for (const dep of node.task.depends_on || []) { const depKey = `${node.issue_id}:${dep}` - if (taskGraph.has(depKey)) { - taskGraph.get(depKey).outEdges.push(key) + if (graph.has(depKey)) { + graph.get(depKey).outEdges.push(key) node.inDegree++ } } } - return { taskGraph, fileModifications } + return { graph, fileModifications } } ``` -### Cycle Detection +### 2.2 Conflict Detection +Conflict when multiple tasks modify same file: ```javascript -function detectCycles(taskGraph) { - const visited = new Set() - const stack = new Set() - const cycles = [] - - function dfs(key, path = []) { - if (stack.has(key)) { - // Found cycle - extract cycle path - const cycleStart = path.indexOf(key) - cycles.push(path.slice(cycleStart).concat(key)) - return true - } - if (visited.has(key)) return false - - visited.add(key) - stack.add(key) - path.push(key) - - for (const next of taskGraph.get(key)?.outEdges || []) { - dfs(next, [...path]) - } - - stack.delete(key) - return false - } - - for (const key of taskGraph.keys()) { - if (!visited.has(key)) { - dfs(key) - } - } - - return { - hasCycle: cycles.length > 0, - cycles - } +function detectConflicts(fileModifications, graph) { + return [...fileModifications.entries()] + .filter(([_, tasks]) => tasks.length > 1) + .map(([file, tasks]) => ({ + type: 'file_conflict', + file, + tasks, + resolved: false + })) } ``` ---- - -## Phase 2: Conflict Detection - -### Identify File Conflicts - -```javascript -function detectFileConflicts(fileModifications, taskGraph) { - const conflicts = [] - - for (const [file, taskKeys] of fileModifications) { - if (taskKeys.length > 1) { - // Multiple tasks modify same file - const taskDetails = taskKeys.map(key => { - const node = taskGraph.get(key) - return { - key, - issue_id: node.issue_id, - task_id: node.task.id, - title: node.task.title, - action: node.task.action, - scope: node.task.scope - } - }) - - conflicts.push({ - type: 'file_conflict', - file, - tasks: taskKeys, - task_details: taskDetails, - resolution: null, - resolved: false - }) - } - } - - return conflicts -} -``` - -### Conflict Classification - -```javascript -function classifyConflict(conflict, taskGraph) { - const tasks = conflict.tasks.map(key => taskGraph.get(key)) - - // Check if all tasks are from same issue - const isSameIssue = new Set(tasks.map(t => t.issue_id)).size === 1 - - // Check action types - const actions = tasks.map(t => t.task.action) - const hasCreate = actions.includes('Create') - const hasDelete = actions.includes('Delete') - - return { - ...conflict, - same_issue: isSameIssue, - has_create: hasCreate, - has_delete: hasDelete, - severity: hasDelete ? 'high' : hasCreate ? 'medium' : 'low' - } -} -``` - ---- - -## Phase 3: Conflict Resolution - -### Resolution Rules +### 2.3 Resolution Rules | Priority | Rule | Example | |----------|------|---------| -| 1 | Create before Update/Implement | T1:Create → T2:Update | +| 1 | Create before Update | T1:Create → T2:Update | | 2 | Foundation before integration | config/ → src/ | | 3 | Types before implementation | types/ → components/ | | 4 | Core before tests | src/ → __tests__/ | -| 5 | Same issue order preserved | T1 → T2 → T3 | +| 5 | Delete last | T1:Update → T2:Delete | -### Apply Resolution Rules +### 2.4 Semantic Priority -```javascript -function resolveConflict(conflict, taskGraph) { - const tasks = conflict.tasks.map(key => ({ - key, - node: taskGraph.get(key) - })) - - // Sort by resolution rules - tasks.sort((a, b) => { - const nodeA = a.node - const nodeB = b.node - - // Rule 1: Create before others - if (nodeA.task.action === 'Create' && nodeB.task.action !== 'Create') return -1 - if (nodeB.task.action === 'Create' && nodeA.task.action !== 'Create') return 1 - - // Rule 2: Delete last - if (nodeA.task.action === 'Delete' && nodeB.task.action !== 'Delete') return 1 - if (nodeB.task.action === 'Delete' && nodeA.task.action !== 'Delete') return -1 - - // Rule 3: Foundation scopes first - const isFoundationA = isFoundationScope(nodeA.task.scope) - const isFoundationB = isFoundationScope(nodeB.task.scope) - if (isFoundationA && !isFoundationB) return -1 - if (isFoundationB && !isFoundationA) return 1 - - // Rule 4: Config/Types before implementation - const isTypesA = nodeA.task.scope?.includes('types') - const isTypesB = nodeB.task.scope?.includes('types') - if (isTypesA && !isTypesB) return -1 - if (isTypesB && !isTypesA) return 1 - - // Rule 5: Preserve issue order (same issue) - if (nodeA.issue_id === nodeB.issue_id) { - return parseInt(nodeA.task.id.replace('T', '')) - parseInt(nodeB.task.id.replace('T', '')) - } - - return 0 - }) - - const order = tasks.map(t => t.key) - const rationale = generateRationale(tasks) - - return { - ...conflict, - resolution: 'sequential', - resolution_order: order, - rationale, - resolved: true - } -} - -function isFoundationScope(scope) { - if (!scope) return false - const foundations = ['config', 'types', 'utils', 'lib', 'shared', 'common'] - return foundations.some(f => scope.toLowerCase().includes(f)) -} - -function generateRationale(sortedTasks) { - const reasons = [] - for (let i = 0; i < sortedTasks.length - 1; i++) { - const curr = sortedTasks[i].node.task - const next = sortedTasks[i + 1].node.task - if (curr.action === 'Create') { - reasons.push(`${curr.id} creates file before ${next.id}`) - } else if (isFoundationScope(curr.scope)) { - reasons.push(`${curr.id} (foundation) before ${next.id}`) - } - } - return reasons.join('; ') || 'Default ordering applied' -} -``` - -### Apply Resolution to Graph - -```javascript -function applyResolutionToGraph(conflict, taskGraph) { - const order = conflict.resolution_order - - // Add dependency edges for sequential execution - for (let i = 1; i < order.length; i++) { - const prevKey = order[i - 1] - const currKey = order[i] - - if (taskGraph.has(prevKey) && taskGraph.has(currKey)) { - const prevNode = taskGraph.get(prevKey) - const currNode = taskGraph.get(currKey) - - // Avoid duplicate edges - if (!prevNode.outEdges.includes(currKey)) { - prevNode.outEdges.push(currKey) - currNode.inDegree++ - } - } - } -} -``` - ---- - -## Phase 4: Semantic Ordering & Grouping - -### Semantic Priority Calculation - -```javascript -function calculateSemanticPriority(node) { - let priority = 0.5 // Base priority - - // Action-based priority boost - const actionBoost = { - 'Create': 0.2, - 'Configure': 0.15, - 'Implement': 0.1, - 'Update': 0, - 'Refactor': -0.05, - 'Test': -0.1, - 'Fix': 0.05, - 'Delete': -0.15 - } - priority += actionBoost[node.task.action] || 0 - - // Scope-based boost - if (isFoundationScope(node.task.scope)) { - priority += 0.1 - } - if (node.task.scope?.includes('types')) { - priority += 0.05 - } - - // Clamp to [0, 1] - return Math.max(0, Math.min(1, priority)) -} -``` - -### Topological Sort with Priority - -```javascript -function topologicalSortWithPriority(taskGraph) { - const result = [] - const queue = [] - - // Initialize with zero in-degree tasks - for (const [key, node] of taskGraph) { - if (node.inDegree === 0) { - queue.push(key) - } - } - - let executionOrder = 1 - while (queue.length > 0) { - // Sort queue by semantic priority (descending) - queue.sort((a, b) => { - const nodeA = taskGraph.get(a) - const nodeB = taskGraph.get(b) - - // 1. Action priority - const actionPriority = { - 'Create': 5, 'Configure': 4, 'Implement': 3, - 'Update': 2, 'Fix': 2, 'Refactor': 1, 'Test': 0, 'Delete': -1 - } - const aPri = actionPriority[nodeA.task.action] ?? 2 - const bPri = actionPriority[nodeB.task.action] ?? 2 - if (aPri !== bPri) return bPri - aPri - - // 2. Foundation scope first - const aFound = isFoundationScope(nodeA.task.scope) - const bFound = isFoundationScope(nodeB.task.scope) - if (aFound !== bFound) return aFound ? -1 : 1 - - // 3. Types before implementation - const aTypes = nodeA.task.scope?.includes('types') - const bTypes = nodeB.task.scope?.includes('types') - if (aTypes !== bTypes) return aTypes ? -1 : 1 - - return 0 - }) - - const current = queue.shift() - const node = taskGraph.get(current) - node.execution_order = executionOrder++ - node.semantic_priority = calculateSemanticPriority(node) - result.push(current) - - // Process outgoing edges - for (const next of node.outEdges) { - const nextNode = taskGraph.get(next) - nextNode.inDegree-- - if (nextNode.inDegree === 0) { - queue.push(next) - } - } - } - - // Check for remaining nodes (cycle indication) - if (result.length !== taskGraph.size) { - const remaining = [...taskGraph.keys()].filter(k => !result.includes(k)) - return { success: false, error: `Unprocessed tasks: ${remaining.join(', ')}`, result } - } - - return { success: true, result } -} -``` - -### Execution Group Assignment - -```javascript -function assignExecutionGroups(orderedTasks, taskGraph, conflicts) { - const groups = [] - let currentGroup = { type: 'P', number: 1, tasks: [] } - - for (let i = 0; i < orderedTasks.length; i++) { - const key = orderedTasks[i] - const node = taskGraph.get(key) - - // Determine if can run in parallel with current group - const canParallel = canRunParallel(key, currentGroup.tasks, taskGraph, conflicts) - - if (!canParallel && currentGroup.tasks.length > 0) { - // Save current group and start new sequential group - groups.push({ ...currentGroup }) - currentGroup = { type: 'S', number: groups.length + 1, tasks: [] } - } - - currentGroup.tasks.push(key) - node.execution_group = `${currentGroup.type}${currentGroup.number}` - } - - // Save last group - if (currentGroup.tasks.length > 0) { - groups.push(currentGroup) - } - - return groups -} - -function canRunParallel(taskKey, groupTasks, taskGraph, conflicts) { - if (groupTasks.length === 0) return true - - const node = taskGraph.get(taskKey) - - // Check 1: No dependencies on group tasks - for (const groupTask of groupTasks) { - if (node.task.depends_on?.includes(groupTask.split(':')[1])) { - return false - } - } - - // Check 2: No file conflicts with group tasks - for (const conflict of conflicts) { - if (conflict.tasks.includes(taskKey)) { - for (const groupTask of groupTasks) { - if (conflict.tasks.includes(groupTask)) { - return false - } - } - } - } - - // Check 3: Different issues can run in parallel - const nodeIssue = node.issue_id - const groupIssues = new Set(groupTasks.map(t => taskGraph.get(t).issue_id)) - - return !groupIssues.has(nodeIssue) -} -``` - ---- - -## Output Generation - -### Queue Item Format - -```javascript -function generateQueueItems(orderedTasks, taskGraph, conflicts) { - const queueItems = [] - let itemIdCounter = 1 - - for (const key of orderedTasks) { - const node = taskGraph.get(key) - - queueItems.push({ - item_id: `T-${itemIdCounter++}`, - issue_id: node.issue_id, - solution_id: node.solution_id, - task_id: node.task.id, - status: 'pending', - execution_order: node.execution_order, - execution_group: node.execution_group, - depends_on: mapDependenciesToItemIds(node, queueItems), - semantic_priority: node.semantic_priority, - assigned_executor: node.task.executor || 'codex' - }) - } - - return queueItems -} - -function mapDependenciesToItemIds(node, queueItems) { - return (node.task.depends_on || []).map(dep => { - const depKey = `${node.issue_id}:${dep}` - const queueItem = queueItems.find(q => - q.issue_id === node.issue_id && q.task_id === dep - ) - return queueItem?.item_id || dep - }) -} -``` - -### Final Output - -```javascript -function generateOutput(queueItems, conflicts, groups) { - return { - tasks: queueItems, - conflicts: conflicts.map(c => ({ - type: c.type, - file: c.file, - tasks: c.tasks, - resolution: c.resolution, - resolution_order: c.resolution_order, - rationale: c.rationale, - resolved: c.resolved - })), - execution_groups: groups.map(g => ({ - id: `${g.type}${g.number}`, - type: g.type === 'P' ? 'parallel' : 'sequential', - task_count: g.tasks.length, - tasks: g.tasks - })), - _metadata: { - version: '1.0', - total_tasks: queueItems.length, - total_conflicts: conflicts.length, - resolved_conflicts: conflicts.filter(c => c.resolved).length, - parallel_groups: groups.filter(g => g.type === 'P').length, - sequential_groups: groups.filter(g => g.type === 'S').length, - timestamp: new Date().toISOString(), - source: 'issue-queue-agent' - } - } -} -``` - ---- - -## Error Handling - -```javascript -async function executeWithValidation(tasks) { - // Phase 1: Build graph - const { taskGraph, fileModifications } = buildDependencyGraph(tasks) - - // Check for cycles - const cycleResult = detectCycles(taskGraph) - if (cycleResult.hasCycle) { - return { - success: false, - error: 'Circular dependency detected', - cycles: cycleResult.cycles, - suggestion: 'Remove circular dependencies or reorder tasks manually' - } - } - - // Phase 2: Detect conflicts - const conflicts = detectFileConflicts(fileModifications, taskGraph) - .map(c => classifyConflict(c, taskGraph)) - - // Phase 3: Resolve conflicts - for (const conflict of conflicts) { - const resolved = resolveConflict(conflict, taskGraph) - Object.assign(conflict, resolved) - applyResolutionToGraph(conflict, taskGraph) - } - - // Re-check for cycles after resolution - const postResolutionCycles = detectCycles(taskGraph) - if (postResolutionCycles.hasCycle) { - return { - success: false, - error: 'Conflict resolution created circular dependency', - cycles: postResolutionCycles.cycles, - suggestion: 'Manual conflict resolution required' - } - } - - // Phase 4: Sort and group - const sortResult = topologicalSortWithPriority(taskGraph) - if (!sortResult.success) { - return { - success: false, - error: sortResult.error, - partial_result: sortResult.result - } - } - - const groups = assignExecutionGroups(sortResult.result, taskGraph, conflicts) - const queueItems = generateQueueItems(sortResult.result, taskGraph, conflicts) - - return { - success: true, - output: generateOutput(queueItems, conflicts, groups) - } -} -``` - -| Scenario | Action | -|----------|--------| -| Circular dependency | Report cycles, abort with suggestion | -| Conflict resolution creates cycle | Flag for manual resolution | -| Missing task reference in depends_on | Skip and warn | -| Empty task list | Return empty queue | - ---- - -## Quality Standards - -### Ordering Validation - -```javascript -function validateOrdering(queueItems, taskGraph) { - const errors = [] - - for (const item of queueItems) { - const key = `${item.issue_id}:${item.task_id}` - const node = taskGraph.get(key) - - // Check dependencies come before - for (const depItemId of item.depends_on) { - const depItem = queueItems.find(q => q.item_id === depItemId) - if (depItem && depItem.execution_order >= item.execution_order) { - errors.push(`${item.item_id} ordered before dependency ${depItemId}`) - } - } - } - - return { valid: errors.length === 0, errors } -} -``` - -### Semantic Priority Rules - -| Factor | Priority Boost | -|--------|---------------| +| Factor | Boost | +|--------|-------| | Create action | +0.2 | | Configure action | +0.15 | | Implement action | +0.1 | | Fix action | +0.05 | -| Foundation scope (config/types/utils) | +0.1 | +| Foundation scope | +0.1 | | Types scope | +0.05 | | Refactor action | -0.05 | | Test action | -0.1 | | Delete action | -0.15 | +### 2.5 Group Assignment + +- **Parallel (P*)**: Tasks with no dependencies or conflicts between them +- **Sequential (S*)**: Tasks that must run in order due to dependencies or conflicts + --- -## Key Reminders +## 3. Output Specifications + +### 3.1 Queue Schema + +Read schema before output: +```bash +cat .claude/workflows/cli-templates/schemas/queue-schema.json +``` + +### 3.2 Output Format + +```json +{ + "tasks": [{ + "item_id": "T-1", + "issue_id": "GH-123", + "solution_id": "SOL-001", + "task_id": "TASK-001", + "status": "pending", + "execution_order": 1, + "execution_group": "P1", + "depends_on": [], + "semantic_priority": 0.7 + }], + "conflicts": [{ + "file": "src/auth.ts", + "tasks": ["GH-123:TASK-001", "GH-124:TASK-002"], + "resolution": "sequential", + "resolution_order": ["GH-123:TASK-001", "GH-124:TASK-002"], + "rationale": "TASK-001 creates file before TASK-002 updates", + "resolved": true + }], + "execution_groups": [ + { "id": "P1", "type": "parallel", "task_count": 3, "tasks": ["T-1", "T-2", "T-3"] }, + { "id": "S2", "type": "sequential", "task_count": 2, "tasks": ["T-4", "T-5"] } + ], + "_metadata": { + "total_tasks": 5, + "total_conflicts": 1, + "resolved_conflicts": 1, + "timestamp": "2025-12-27T10:00:00Z" + } +} +``` + +--- + +## 4. Quality Standards + +### 4.1 Validation Checklist + +- [ ] No circular dependencies +- [ ] All conflicts resolved +- [ ] Dependencies ordered correctly +- [ ] Parallel groups have no conflicts +- [ ] Semantic priority calculated + +### 4.2 Error Handling + +| Scenario | Action | +|----------|--------| +| Circular dependency | Abort, report cycles | +| Resolution creates cycle | Flag for manual resolution | +| Missing task reference | Skip and warn | +| Empty task list | Return empty queue | + +### 4.3 Guidelines **ALWAYS**: -1. Build dependency graph before any ordering -2. Detect cycles before and after conflict resolution -3. Apply resolution rules consistently (Create → Update → Delete) -4. Preserve within-issue task order when no conflicts -5. Calculate semantic priority for all tasks +1. Build dependency graph before ordering +2. Detect cycles before and after resolution +3. Apply resolution rules consistently +4. Calculate semantic priority for all tasks +5. Include rationale for conflict resolutions 6. Validate ordering before output -7. Include rationale for conflict resolutions -8. Map depends_on to item_ids in output **NEVER**: 1. Execute tasks (ordering only) 2. Ignore circular dependencies -3. Create arbitrary ordering without rules -4. Skip conflict detection -5. Output invalid DAG -6. Merge tasks from different issues in same parallel group if conflicts exist -7. Assume task order without checking depends_on +3. Skip conflict detection +4. Output invalid DAG +5. Merge conflicting tasks in parallel group + +**OUTPUT**: +1. Write queue via `ccw issue queue` CLI +2. Return JSON with `tasks`, `conflicts`, `execution_groups`, `_metadata` diff --git a/.claude/commands/issue/manage.md b/.claude/commands/issue/manage.md index 8ce26dbf..f8c2c33b 100644 --- a/.claude/commands/issue/manage.md +++ b/.claude/commands/issue/manage.md @@ -20,17 +20,23 @@ Interactive menu-driven interface for issue management using `ccw issue` CLI end ```bash # Core endpoints (ccw issue) -ccw issue list # List all issues -ccw issue list --json # Get issue details -ccw issue status # Detailed status -ccw issue init --title "..." # Create issue -ccw issue task --title "..." # Add task +ccw issue list # List all issues +ccw issue list --json # Get issue details +ccw issue status # Detailed status +ccw issue init --title "..." # Create issue +ccw issue task --title "..." # Add task +ccw issue bind # Bind solution # Queue management -ccw issue queue # List queue -ccw issue queue add # Add to queue -ccw issue next # Get next task -ccw issue complete # Complete task +ccw issue queue # List current queue +ccw issue queue add # Add to queue +ccw issue queue list # Queue history +ccw issue queue switch # Switch queue +ccw issue queue archive # Archive queue +ccw issue queue delete # Delete queue +ccw issue next # Get next task +ccw issue done # Mark completed +ccw issue complete # (legacy alias for done) ``` ## Usage @@ -49,7 +55,9 @@ ccw issue complete # Complete task ## Implementation -### Phase 1: Entry Point +This command delegates to the `issue-manage` skill for detailed implementation. + +### Entry Point ```javascript const issueId = parseIssueId(userInput); @@ -63,787 +71,30 @@ if (!action) { } ``` -### Phase 2: Main Menu +### Main Menu Flow -```javascript -async function showMainMenu(preselectedIssue = null) { - // Fetch current issues summary - const issuesResult = Bash('ccw issue list --json 2>/dev/null || echo "[]"'); - const issues = JSON.parse(issuesResult) || []; - - const queueResult = Bash('ccw issue status --json 2>/dev/null'); - const queueStatus = JSON.parse(queueResult || '{}'); - - console.log(` -## Issue Management Dashboard +1. **Dashboard**: Fetch issues summary via `ccw issue list --json` +2. **Menu**: Present action options via AskUserQuestion +3. **Route**: Execute selected action (List/View/Edit/Delete/Bulk) +4. **Loop**: Return to menu after each action -**Total Issues**: ${issues.length} -**Queue Status**: ${queueStatus.queue?.total_tasks || 0} tasks (${queueStatus.queue?.pending_count || 0} pending) +### Available Actions -### Quick Stats -- Registered: ${issues.filter(i => i.status === 'registered').length} -- Planned: ${issues.filter(i => i.status === 'planned').length} -- Executing: ${issues.filter(i => i.status === 'executing').length} -- Completed: ${issues.filter(i => i.status === 'completed').length} -`); +| Action | Description | CLI Command | +|--------|-------------|-------------| +| List | Browse with filters | `ccw issue list --json` | +| View | Detail view | `ccw issue status --json` | +| Edit | Modify fields | Update `issues.jsonl` | +| Delete | Remove issue | Clean up all related files | +| Bulk | Batch operations | Multi-select + batch update | - const answer = AskUserQuestion({ - questions: [{ - question: 'What would you like to do?', - header: 'Action', - multiSelect: false, - options: [ - { label: 'List Issues', description: 'Browse all issues with filters' }, - { label: 'View Issue', description: 'Detailed view of specific issue' }, - { label: 'Create Issue', description: 'Add new issue from text or GitHub' }, - { label: 'Edit Issue', description: 'Modify issue fields' }, - { label: 'Delete Issue', description: 'Remove issue(s)' }, - { label: 'Bulk Operations', description: 'Batch actions on multiple issues' } - ] - }] - }); - - const selected = parseAnswer(answer); - - switch (selected) { - case 'List Issues': - await listIssuesInteractive(); - break; - case 'View Issue': - await viewIssueInteractive(preselectedIssue); - break; - case 'Create Issue': - await createIssueInteractive(); - break; - case 'Edit Issue': - await editIssueInteractive(preselectedIssue); - break; - case 'Delete Issue': - await deleteIssueInteractive(preselectedIssue); - break; - case 'Bulk Operations': - await bulkOperationsInteractive(); - break; - } -} -``` +## Data Files -### Phase 3: List Issues - -```javascript -async function listIssuesInteractive() { - // Ask for filter - const filterAnswer = AskUserQuestion({ - questions: [{ - question: 'Filter issues by status?', - header: 'Filter', - multiSelect: true, - options: [ - { label: 'All', description: 'Show all issues' }, - { label: 'Registered', description: 'New, unplanned issues' }, - { label: 'Planned', description: 'Issues with bound solutions' }, - { label: 'Queued', description: 'In execution queue' }, - { label: 'Executing', description: 'Currently being worked on' }, - { label: 'Completed', description: 'Finished issues' }, - { label: 'Failed', description: 'Failed issues' } - ] - }] - }); - - const filters = parseMultiAnswer(filterAnswer); - - // Fetch and filter issues - const result = Bash('ccw issue list --json'); - let issues = JSON.parse(result) || []; - - if (!filters.includes('All')) { - const statusMap = { - 'Registered': 'registered', - 'Planned': 'planned', - 'Queued': 'queued', - 'Executing': 'executing', - 'Completed': 'completed', - 'Failed': 'failed' - }; - const allowedStatuses = filters.map(f => statusMap[f]).filter(Boolean); - issues = issues.filter(i => allowedStatuses.includes(i.status)); - } - - if (issues.length === 0) { - console.log('No issues found matching filters.'); - return showMainMenu(); - } - - // Display issues table - console.log(` -## Issues (${issues.length}) - -| ID | Status | Priority | Title | -|----|--------|----------|-------| -${issues.map(i => `| ${i.id} | ${i.status} | P${i.priority} | ${i.title.substring(0, 40)} |`).join('\n')} -`); - - // Ask for action on issue - const actionAnswer = AskUserQuestion({ - questions: [{ - question: 'Select an issue to view/edit, or return to menu:', - header: 'Select', - multiSelect: false, - options: [ - ...issues.slice(0, 10).map(i => ({ - label: i.id, - description: i.title.substring(0, 50) - })), - { label: 'Back to Menu', description: 'Return to main menu' } - ] - }] - }); - - const selected = parseAnswer(actionAnswer); - - if (selected === 'Back to Menu') { - return showMainMenu(); - } - - // View selected issue - await viewIssueInteractive(selected); -} -``` - -### Phase 4: View Issue - -```javascript -async function viewIssueInteractive(issueId) { - if (!issueId) { - // Ask for issue ID - const issues = JSON.parse(Bash('ccw issue list --json') || '[]'); - - const idAnswer = AskUserQuestion({ - questions: [{ - question: 'Select issue to view:', - header: 'Issue', - multiSelect: false, - options: issues.slice(0, 10).map(i => ({ - label: i.id, - description: `${i.status} - ${i.title.substring(0, 40)}` - })) - }] - }); - - issueId = parseAnswer(idAnswer); - } - - // Fetch detailed status - const result = Bash(`ccw issue status ${issueId} --json`); - const data = JSON.parse(result); - - const issue = data.issue; - const solutions = data.solutions || []; - const bound = data.bound; - - console.log(` -## Issue: ${issue.id} - -**Title**: ${issue.title} -**Status**: ${issue.status} -**Priority**: P${issue.priority} -**Created**: ${issue.created_at} -**Updated**: ${issue.updated_at} - -### Context -${issue.context || 'No context provided'} - -### Solutions (${solutions.length}) -${solutions.length === 0 ? 'No solutions registered' : - solutions.map(s => `- ${s.is_bound ? '◉' : '○'} ${s.id}: ${s.tasks?.length || 0} tasks`).join('\n')} - -${bound ? `### Bound Solution: ${bound.id}\n**Tasks**: ${bound.tasks?.length || 0}` : ''} -`); - - // Show tasks if bound solution exists - if (bound?.tasks?.length > 0) { - console.log(` -### Tasks -| ID | Action | Scope | Title | -|----|--------|-------|-------| -${bound.tasks.map(t => `| ${t.id} | ${t.action} | ${t.scope?.substring(0, 20) || '-'} | ${t.title.substring(0, 30)} |`).join('\n')} -`); - } - - // Action menu - const actionAnswer = AskUserQuestion({ - questions: [{ - question: 'What would you like to do?', - header: 'Action', - multiSelect: false, - options: [ - { label: 'Edit Issue', description: 'Modify issue fields' }, - { label: 'Plan Issue', description: 'Generate solution (/issue:plan)' }, - { label: 'Add to Queue', description: 'Queue bound solution tasks' }, - { label: 'View Queue', description: 'See queue status' }, - { label: 'Delete Issue', description: 'Remove this issue' }, - { label: 'Back to Menu', description: 'Return to main menu' } - ] - }] - }); - - const action = parseAnswer(actionAnswer); - - switch (action) { - case 'Edit Issue': - await editIssueInteractive(issueId); - break; - case 'Plan Issue': - console.log(`Running: /issue:plan ${issueId}`); - // Invoke plan skill - break; - case 'Add to Queue': - Bash(`ccw issue queue add ${issueId}`); - console.log(`✓ Added ${issueId} tasks to queue`); - break; - case 'View Queue': - const queueOutput = Bash('ccw issue queue'); - console.log(queueOutput); - break; - case 'Delete Issue': - await deleteIssueInteractive(issueId); - break; - default: - return showMainMenu(); - } -} -``` - -### Phase 5: Edit Issue - -```javascript -async function editIssueInteractive(issueId) { - if (!issueId) { - const issues = JSON.parse(Bash('ccw issue list --json') || '[]'); - const idAnswer = AskUserQuestion({ - questions: [{ - question: 'Select issue to edit:', - header: 'Issue', - multiSelect: false, - options: issues.slice(0, 10).map(i => ({ - label: i.id, - description: `${i.status} - ${i.title.substring(0, 40)}` - })) - }] - }); - issueId = parseAnswer(idAnswer); - } - - // Get current issue data - const result = Bash(`ccw issue list ${issueId} --json`); - const issueData = JSON.parse(result); - const issue = issueData.issue || issueData; - - // Ask which field to edit - const fieldAnswer = AskUserQuestion({ - questions: [{ - question: 'Which field to edit?', - header: 'Field', - multiSelect: false, - options: [ - { label: 'Title', description: `Current: ${issue.title?.substring(0, 40)}` }, - { label: 'Priority', description: `Current: P${issue.priority}` }, - { label: 'Status', description: `Current: ${issue.status}` }, - { label: 'Context', description: 'Edit problem description' }, - { label: 'Labels', description: `Current: ${issue.labels?.join(', ') || 'none'}` }, - { label: 'Back', description: 'Return without changes' } - ] - }] - }); - - const field = parseAnswer(fieldAnswer); - - if (field === 'Back') { - return viewIssueInteractive(issueId); - } - - let updatePayload = {}; - - switch (field) { - case 'Title': - const titleAnswer = AskUserQuestion({ - questions: [{ - question: 'Enter new title (or select current to keep):', - header: 'Title', - multiSelect: false, - options: [ - { label: issue.title.substring(0, 50), description: 'Keep current title' } - ] - }] - }); - const newTitle = parseAnswer(titleAnswer); - if (newTitle && newTitle !== issue.title.substring(0, 50)) { - updatePayload.title = newTitle; - } - break; - - case 'Priority': - const priorityAnswer = AskUserQuestion({ - questions: [{ - question: 'Select priority:', - header: 'Priority', - multiSelect: false, - options: [ - { label: 'P1 - Critical', description: 'Production blocking' }, - { label: 'P2 - High', description: 'Major functionality' }, - { label: 'P3 - Medium', description: 'Normal priority (default)' }, - { label: 'P4 - Low', description: 'Minor issues' }, - { label: 'P5 - Trivial', description: 'Nice to have' } - ] - }] - }); - const priorityStr = parseAnswer(priorityAnswer); - updatePayload.priority = parseInt(priorityStr.charAt(1)); - break; - - case 'Status': - const statusAnswer = AskUserQuestion({ - questions: [{ - question: 'Select status:', - header: 'Status', - multiSelect: false, - options: [ - { label: 'registered', description: 'New issue, not yet planned' }, - { label: 'planning', description: 'Solution being generated' }, - { label: 'planned', description: 'Solution bound, ready for queue' }, - { label: 'queued', description: 'In execution queue' }, - { label: 'executing', description: 'Currently being worked on' }, - { label: 'completed', description: 'All tasks finished' }, - { label: 'failed', description: 'Execution failed' }, - { label: 'paused', description: 'Temporarily on hold' } - ] - }] - }); - updatePayload.status = parseAnswer(statusAnswer); - break; - - case 'Context': - console.log(`Current context:\n${issue.context || '(empty)'}\n`); - const contextAnswer = AskUserQuestion({ - questions: [{ - question: 'Enter new context (problem description):', - header: 'Context', - multiSelect: false, - options: [ - { label: 'Keep current', description: 'No changes' } - ] - }] - }); - const newContext = parseAnswer(contextAnswer); - if (newContext && newContext !== 'Keep current') { - updatePayload.context = newContext; - } - break; - - case 'Labels': - const labelsAnswer = AskUserQuestion({ - questions: [{ - question: 'Enter labels (comma-separated):', - header: 'Labels', - multiSelect: false, - options: [ - { label: issue.labels?.join(',') || '', description: 'Keep current labels' } - ] - }] - }); - const labelsStr = parseAnswer(labelsAnswer); - if (labelsStr) { - updatePayload.labels = labelsStr.split(',').map(l => l.trim()); - } - break; - } - - // Apply update if any - if (Object.keys(updatePayload).length > 0) { - // Read, update, write issues.jsonl - const issuesPath = '.workflow/issues/issues.jsonl'; - const allIssues = Bash(`cat "${issuesPath}"`) - .split('\n') - .filter(line => line.trim()) - .map(line => JSON.parse(line)); - - const idx = allIssues.findIndex(i => i.id === issueId); - if (idx !== -1) { - allIssues[idx] = { - ...allIssues[idx], - ...updatePayload, - updated_at: new Date().toISOString() - }; - - Write(issuesPath, allIssues.map(i => JSON.stringify(i)).join('\n')); - console.log(`✓ Updated ${issueId}: ${Object.keys(updatePayload).join(', ')}`); - } - } - - // Continue editing or return - const continueAnswer = AskUserQuestion({ - questions: [{ - question: 'Continue editing?', - header: 'Continue', - multiSelect: false, - options: [ - { label: 'Edit Another Field', description: 'Continue editing this issue' }, - { label: 'View Issue', description: 'See updated issue' }, - { label: 'Back to Menu', description: 'Return to main menu' } - ] - }] - }); - - const cont = parseAnswer(continueAnswer); - if (cont === 'Edit Another Field') { - await editIssueInteractive(issueId); - } else if (cont === 'View Issue') { - await viewIssueInteractive(issueId); - } else { - return showMainMenu(); - } -} -``` - -### Phase 6: Delete Issue - -```javascript -async function deleteIssueInteractive(issueId) { - if (!issueId) { - const issues = JSON.parse(Bash('ccw issue list --json') || '[]'); - const idAnswer = AskUserQuestion({ - questions: [{ - question: 'Select issue to delete:', - header: 'Delete', - multiSelect: false, - options: issues.slice(0, 10).map(i => ({ - label: i.id, - description: `${i.status} - ${i.title.substring(0, 40)}` - })) - }] - }); - issueId = parseAnswer(idAnswer); - } - - // Confirm deletion - const confirmAnswer = AskUserQuestion({ - questions: [{ - question: `Delete issue ${issueId}? This will also remove associated solutions.`, - header: 'Confirm', - multiSelect: false, - options: [ - { label: 'Delete', description: 'Permanently remove issue and solutions' }, - { label: 'Cancel', description: 'Keep issue' } - ] - }] - }); - - if (parseAnswer(confirmAnswer) !== 'Delete') { - console.log('Deletion cancelled.'); - return showMainMenu(); - } - - // Remove from issues.jsonl - const issuesPath = '.workflow/issues/issues.jsonl'; - const allIssues = Bash(`cat "${issuesPath}"`) - .split('\n') - .filter(line => line.trim()) - .map(line => JSON.parse(line)); - - const filtered = allIssues.filter(i => i.id !== issueId); - Write(issuesPath, filtered.map(i => JSON.stringify(i)).join('\n')); - - // Remove solutions file if exists - const solPath = `.workflow/issues/solutions/${issueId}.jsonl`; - Bash(`rm -f "${solPath}" 2>/dev/null || true`); - - // Remove from queue if present - const queuePath = '.workflow/issues/queue.json'; - if (Bash(`test -f "${queuePath}" && echo exists`) === 'exists') { - const queue = JSON.parse(Bash(`cat "${queuePath}"`)); - queue.tasks = queue.tasks.filter(q => q.issue_id !== issueId); - Write(queuePath, JSON.stringify(queue, null, 2)); - } - - console.log(`✓ Deleted issue ${issueId}`); - return showMainMenu(); -} -``` - -### Phase 7: Bulk Operations - -```javascript -async function bulkOperationsInteractive() { - const bulkAnswer = AskUserQuestion({ - questions: [{ - question: 'Select bulk operation:', - header: 'Bulk', - multiSelect: false, - options: [ - { label: 'Update Status', description: 'Change status of multiple issues' }, - { label: 'Update Priority', description: 'Change priority of multiple issues' }, - { label: 'Add Labels', description: 'Add labels to multiple issues' }, - { label: 'Delete Multiple', description: 'Remove multiple issues' }, - { label: 'Queue All Planned', description: 'Add all planned issues to queue' }, - { label: 'Retry All Failed', description: 'Reset all failed tasks to pending' }, - { label: 'Back', description: 'Return to main menu' } - ] - }] - }); - - const operation = parseAnswer(bulkAnswer); - - if (operation === 'Back') { - return showMainMenu(); - } - - // Get issues for selection - const allIssues = JSON.parse(Bash('ccw issue list --json') || '[]'); - - if (operation === 'Queue All Planned') { - const planned = allIssues.filter(i => i.status === 'planned' && i.bound_solution_id); - for (const issue of planned) { - Bash(`ccw issue queue add ${issue.id}`); - console.log(`✓ Queued ${issue.id}`); - } - console.log(`\n✓ Queued ${planned.length} issues`); - return showMainMenu(); - } - - if (operation === 'Retry All Failed') { - Bash('ccw issue retry'); - console.log('✓ Reset all failed tasks to pending'); - return showMainMenu(); - } - - // Multi-select issues - const selectAnswer = AskUserQuestion({ - questions: [{ - question: 'Select issues (multi-select):', - header: 'Select', - multiSelect: true, - options: allIssues.slice(0, 15).map(i => ({ - label: i.id, - description: `${i.status} - ${i.title.substring(0, 30)}` - })) - }] - }); - - const selectedIds = parseMultiAnswer(selectAnswer); - - if (selectedIds.length === 0) { - console.log('No issues selected.'); - return showMainMenu(); - } - - // Execute bulk operation - const issuesPath = '.workflow/issues/issues.jsonl'; - let issues = Bash(`cat "${issuesPath}"`) - .split('\n') - .filter(line => line.trim()) - .map(line => JSON.parse(line)); - - switch (operation) { - case 'Update Status': - const statusAnswer = AskUserQuestion({ - questions: [{ - question: 'Select new status:', - header: 'Status', - multiSelect: false, - options: [ - { label: 'registered', description: 'Reset to registered' }, - { label: 'paused', description: 'Pause issues' }, - { label: 'completed', description: 'Mark completed' } - ] - }] - }); - const newStatus = parseAnswer(statusAnswer); - issues = issues.map(i => - selectedIds.includes(i.id) - ? { ...i, status: newStatus, updated_at: new Date().toISOString() } - : i - ); - break; - - case 'Update Priority': - const prioAnswer = AskUserQuestion({ - questions: [{ - question: 'Select new priority:', - header: 'Priority', - multiSelect: false, - options: [ - { label: 'P1', description: 'Critical' }, - { label: 'P2', description: 'High' }, - { label: 'P3', description: 'Medium' }, - { label: 'P4', description: 'Low' }, - { label: 'P5', description: 'Trivial' } - ] - }] - }); - const newPrio = parseInt(parseAnswer(prioAnswer).charAt(1)); - issues = issues.map(i => - selectedIds.includes(i.id) - ? { ...i, priority: newPrio, updated_at: new Date().toISOString() } - : i - ); - break; - - case 'Add Labels': - const labelAnswer = AskUserQuestion({ - questions: [{ - question: 'Enter labels to add (comma-separated):', - header: 'Labels', - multiSelect: false, - options: [ - { label: 'bug', description: 'Bug fix' }, - { label: 'feature', description: 'New feature' }, - { label: 'urgent', description: 'Urgent priority' } - ] - }] - }); - const newLabels = parseAnswer(labelAnswer).split(',').map(l => l.trim()); - issues = issues.map(i => - selectedIds.includes(i.id) - ? { - ...i, - labels: [...new Set([...(i.labels || []), ...newLabels])], - updated_at: new Date().toISOString() - } - : i - ); - break; - - case 'Delete Multiple': - const confirmDelete = AskUserQuestion({ - questions: [{ - question: `Delete ${selectedIds.length} issues permanently?`, - header: 'Confirm', - multiSelect: false, - options: [ - { label: 'Delete All', description: 'Remove selected issues' }, - { label: 'Cancel', description: 'Keep issues' } - ] - }] - }); - if (parseAnswer(confirmDelete) === 'Delete All') { - issues = issues.filter(i => !selectedIds.includes(i.id)); - // Clean up solutions - for (const id of selectedIds) { - Bash(`rm -f ".workflow/issues/solutions/${id}.jsonl" 2>/dev/null || true`); - } - } else { - console.log('Deletion cancelled.'); - return showMainMenu(); - } - break; - } - - Write(issuesPath, issues.map(i => JSON.stringify(i)).join('\n')); - console.log(`✓ Updated ${selectedIds.length} issues`); - return showMainMenu(); -} -``` - -### Phase 8: Create Issue (Redirect) - -```javascript -async function createIssueInteractive() { - const typeAnswer = AskUserQuestion({ - questions: [{ - question: 'Create issue from:', - header: 'Source', - multiSelect: false, - options: [ - { label: 'GitHub URL', description: 'Import from GitHub issue' }, - { label: 'Text Description', description: 'Enter problem description' }, - { label: 'Quick Create', description: 'Just title and priority' } - ] - }] - }); - - const type = parseAnswer(typeAnswer); - - if (type === 'GitHub URL' || type === 'Text Description') { - console.log('Use /issue:new for structured issue creation'); - console.log('Example: /issue:new https://github.com/org/repo/issues/123'); - return showMainMenu(); - } - - // Quick create - const titleAnswer = AskUserQuestion({ - questions: [{ - question: 'Enter issue title:', - header: 'Title', - multiSelect: false, - options: [ - { label: 'Authentication Bug', description: 'Example title' } - ] - }] - }); - - const title = parseAnswer(titleAnswer); - - const prioAnswer = AskUserQuestion({ - questions: [{ - question: 'Select priority:', - header: 'Priority', - multiSelect: false, - options: [ - { label: 'P3 - Medium (Recommended)', description: 'Normal priority' }, - { label: 'P1 - Critical', description: 'Production blocking' }, - { label: 'P2 - High', description: 'Major functionality' } - ] - }] - }); - - const priority = parseInt(parseAnswer(prioAnswer).charAt(1)); - - // Generate ID and create - const id = `ISS-${Date.now()}`; - Bash(`ccw issue init ${id} --title "${title}" --priority ${priority}`); - - console.log(`✓ Created issue ${id}`); - await viewIssueInteractive(id); -} -``` - -## Helper Functions - -```javascript -function parseAnswer(answer) { - // Extract selected option from AskUserQuestion response - if (typeof answer === 'string') return answer; - if (answer.answers) { - const values = Object.values(answer.answers); - return values[0] || ''; - } - return ''; -} - -function parseMultiAnswer(answer) { - // Extract multiple selections - if (typeof answer === 'string') return answer.split(',').map(s => s.trim()); - if (answer.answers) { - const values = Object.values(answer.answers); - return values.flatMap(v => v.split(',').map(s => s.trim())); - } - return []; -} - -function parseFlags(input) { - const flags = {}; - const matches = input.matchAll(/--(\w+)\s+([^\s-]+)/g); - for (const match of matches) { - flags[match[1]] = match[2]; - } - return flags; -} - -function parseIssueId(input) { - const match = input.match(/^([A-Z]+-\d+|ISS-\d+|GH-\d+)/i); - return match ? match[1] : null; -} -``` +| File | Purpose | +|------|---------| +| `.workflow/issues/issues.jsonl` | Issue records | +| `.workflow/issues/solutions/.jsonl` | Solutions per issue | +| `.workflow/issues/queue.json` | Execution queue | ## Error Handling @@ -853,7 +104,6 @@ function parseIssueId(input) { | Issue not found | Show available issues, ask for correction | | Invalid selection | Show error, re-prompt | | Write failure | Check permissions, show error | -| Queue operation fails | Show ccw issue error, suggest fix | ## Related Commands @@ -861,5 +111,3 @@ function parseIssueId(input) { - `/issue:plan` - Plan solution for issue - `/issue:queue` - Form execution queue - `/issue:execute` - Execute queued tasks -- `ccw issue list` - CLI list command -- `ccw issue status` - CLI status command diff --git a/.claude/commands/issue/new.md b/.claude/commands/issue/new.md index d09f56da..ee1ba0cd 100644 --- a/.claude/commands/issue/new.md +++ b/.claude/commands/issue/new.md @@ -51,51 +51,18 @@ interface Issue { } ``` -## Task Lifecycle (Each Task is Closed-Loop) +## Lifecycle Requirements -When `/issue:plan` generates tasks, each task MUST include: +The `lifecycle_requirements` field guides downstream commands (`/issue:plan`, `/issue:execute`): -```typescript -interface SolutionTask { - id: string; - title: string; - scope: string; - action: string; +| Field | Options | Purpose | +|-------|---------|---------| +| `test_strategy` | `unit`, `integration`, `e2e`, `manual`, `auto` | Which test types to generate | +| `regression_scope` | `affected`, `related`, `full` | Which tests to run for regression | +| `acceptance_type` | `automated`, `manual`, `both` | How to verify completion | +| `commit_strategy` | `per-task`, `squash`, `atomic` | Commit granularity | - // Phase 1: Implementation - implementation: string[]; // Step-by-step implementation - modification_points: { file: string; target: string; change: string }[]; - - // Phase 2: Testing - test: { - unit?: string[]; // Unit test requirements - integration?: string[]; // Integration test requirements - commands?: string[]; // Test commands to run - coverage_target?: number; // Minimum coverage % - }; - - // Phase 3: Regression - regression: string[]; // Regression check commands/points - - // Phase 4: Acceptance - acceptance: { - criteria: string[]; // Testable acceptance criteria - verification: string[]; // How to verify each criterion - manual_checks?: string[]; // Manual verification if needed - }; - - // Phase 5: Commit - commit: { - type: 'feat' | 'fix' | 'refactor' | 'test' | 'docs' | 'chore'; - scope: string; // e.g., "auth", "api" - message_template: string; // Commit message template - breaking?: boolean; - }; - - depends_on: string[]; - executor: 'codex' | 'gemini' | 'agent' | 'auto'; -} -``` +> **Note**: Task structure (SolutionTask) is defined in `/issue:plan` - see `.claude/commands/issue/plan.md` ## Usage diff --git a/.claude/commands/issue/plan.md b/.claude/commands/issue/plan.md index efd8165e..ea8ed10f 100644 --- a/.claude/commands/issue/plan.md +++ b/.claude/commands/issue/plan.md @@ -9,13 +9,35 @@ allowed-tools: TodoWrite(*), Task(*), SlashCommand(*), AskUserQuestion(*), Bash( ## Overview -Unified planning command using **issue-plan-agent** that combines exploration and planning into a single closed-loop workflow. The agent handles ACE semantic search, solution generation, and task breakdown. +Unified planning command using **issue-plan-agent** that combines exploration and planning into a single closed-loop workflow. + +## Output Requirements + +**Generate Files:** +1. `.workflow/issues/solutions/{issue-id}.jsonl` - Solution with tasks for each issue + +**Return Summary:** +```json +{ + "bound": [{ "issue_id": "...", "solution_id": "...", "task_count": N }], + "pending_selection": [{ "issue_id": "...", "solutions": [...] }], + "conflicts": [{ "file": "...", "issues": [...] }] +} +``` + +**Completion Criteria:** +- [ ] Solution file generated for each issue +- [ ] Single solution → auto-bound via `ccw issue bind` +- [ ] Multiple solutions → returned for user selection +- [ ] Tasks conform to schema: `cat .claude/workflows/cli-templates/schemas/issue-task-jsonl-schema.json` +- [ ] Each task has quantified `delivery_criteria` + +## Core Capabilities -**Core capabilities:** - **Closed-loop agent**: issue-plan-agent combines explore + plan - Batch processing: 1 agent processes 1-3 issues - ACE semantic search integrated into planning -- Solution with executable tasks and acceptance criteria +- Solution with executable tasks and delivery criteria - Automatic solution registration and binding ## Storage Structure (Flat JSONL) @@ -123,96 +145,39 @@ TodoWrite({ ### Phase 2: Unified Explore + Plan (issue-plan-agent) ```javascript -// Ensure solutions directory exists Bash(`mkdir -p .workflow/issues/solutions`); +const pendingSelections = []; // Collect multi-solution issues for user selection for (const [batchIndex, batch] of batches.entries()) { updateTodo(`Plan batch ${batchIndex + 1}`, 'in_progress'); - // Build issue prompt for agent - pass IDs only, agent fetches details + // Build minimal prompt - agent handles exploration, planning, and binding const issuePrompt = ` -## Issues to Plan (Closed-Loop Tasks Required) +## Plan Issues **Issue IDs**: ${batch.join(', ')} +**Project Root**: ${process.cwd()} -### Step 1: Fetch Issue Details -For each issue ID, use CLI to get full details: -\`\`\`bash -ccw issue status --json -\`\`\` +### Steps +1. Fetch: \`ccw issue status --json\` +2. Explore (ACE) → Plan solution +3. Register & bind: \`ccw issue bind --solution \` -Returns: +### Generate Files +\`.workflow/issues/solutions/{issue-id}.jsonl\` - Solution with tasks (schema: cat .claude/workflows/cli-templates/schemas/issue-task-jsonl-schema.json) + +### Binding Rules +- **Single solution**: Auto-bind via \`ccw issue bind --solution \` +- **Multiple solutions**: Register only, return for user selection + +### Return Summary \`\`\`json { - "issue": { "id", "title", "context", "affected_components", "lifecycle_requirements", ... }, - "solutions": [...], - "bound": null + "bound": [{ "issue_id": "...", "solution_id": "...", "task_count": N }], + "pending_selection": [{ "issue_id": "...", "solutions": [{ "id": "...", "description": "...", "task_count": N }] }], + "conflicts": [{ "file": "...", "issues": [...] }] } \`\`\` - -## Project Root -${process.cwd()} - -## Output Requirements - -**IMPORTANT**: Register solutions via CLI, do NOT write files directly. - -### 1. Register Solutions via CLI -For each issue, save solution to temp file and register via CLI: -\`\`\`bash -# Write solution JSON to temp file -echo '' > /tmp/sol-{issue-id}.json - -# Register solution via CLI (generates SOL-xxx ID automatically) -ccw issue bind {issue-id} --solution /tmp/sol-{issue-id}.json -\`\`\` -- Solution must include all closed-loop task fields (see Solution Format below) - -### 2. Return Summary Only -After registering solutions, return ONLY a brief JSON summary: -\`\`\`json -{ - "planned": [ - { "issue_id": "XXX", "solution_id": "SOL-xxx", "task_count": 3, "description": "Brief description" } - ], - "conflicts": [ - { "file": "path/to/file", "issues": ["ID1", "ID2"], "suggested_order": ["ID1", "ID2"] } - ] -} -\`\`\` - -## Closed-Loop Task Requirements - -Each task MUST include ALL lifecycle phases: - -### 1. Implementation -- implementation: string[] (2-7 concrete steps) -- modification_points: { file, target, change }[] - -### 2. Test -- test.unit: string[] (unit test requirements) -- test.integration: string[] (integration test requirements if needed) -- test.commands: string[] (actual test commands to run) -- test.coverage_target: number (minimum coverage %) - -### 3. Regression -- regression: string[] (commands to run for regression check) - -### 4. Acceptance -- acceptance.criteria: string[] (testable acceptance criteria) -- acceptance.verification: string[] (how to verify each criterion) - -### 5. Commit -- commit.type: feat|fix|refactor|test|docs|chore -- commit.scope: string (module name) -- commit.message_template: string (full commit message) -- commit.breaking: boolean - -## Additional Requirements -1. Use ACE semantic search (mcp__ace-tool__search_context) for exploration -2. Detect file conflicts if multiple issues -3. Generate executable test commands based on project's test framework -4. Infer commit scope from affected files `; // Launch issue-plan-agent - agent writes solutions directly @@ -223,79 +188,52 @@ Each task MUST include ALL lifecycle phases: prompt=issuePrompt ); - // Parse brief summary from agent + // Parse summary from agent const summary = JSON.parse(result); - // Display planning results - for (const item of summary.planned || []) { - console.log(`✓ ${item.issue_id}: ${item.solution_id} (${item.task_count} tasks) - ${item.description}`); + // Display auto-bound solutions + for (const item of summary.bound || []) { + console.log(`✓ ${item.issue_id}: ${item.solution_id} (${item.task_count} tasks)`); } - // Handle conflicts if any + // Collect pending selections for Phase 3 + pendingSelections.push(...(summary.pending_selection || [])); + + // Show conflicts if (summary.conflicts?.length > 0) { - console.log(`\n⚠ File conflicts detected:`); - summary.conflicts.forEach(c => { - console.log(` ${c.file}: ${c.issues.join(', ')} → suggested: ${c.suggested_order.join(' → ')}`); - }); + console.log(`⚠ Conflicts: ${summary.conflicts.map(c => c.file).join(', ')}`); } updateTodo(`Plan batch ${batchIndex + 1}`, 'completed'); } ``` -### Phase 3: Solution Binding +### Phase 3: Multi-Solution Selection ```javascript -// Collect issues needing user selection (multiple solutions) -const needSelection = []; - -for (const issueId of issueIds) { - // Get solutions via CLI - const statusJson = Bash(`ccw issue status ${issueId} --json 2>/dev/null || echo '{}'`).trim(); - const status = JSON.parse(statusJson); - const solutions = status.solutions || []; - - if (solutions.length === 0) continue; // No solutions - skip silently (agent already reported) - - if (solutions.length === 1) { - // Auto-bind single solution - bindSolution(issueId, solutions[0].id); - } else { - // Multiple solutions - collect for batch selection - const options = solutions.map(s => ({ - id: s.id, - description: s.description, - task_count: (s.tasks || []).length - })); - needSelection.push({ issueId, options }); - } -} - -// Batch ask user for multiple-solution issues -if (needSelection.length > 0) { +// Only handle issues where agent generated multiple solutions +if (pendingSelections.length > 0) { const answer = AskUserQuestion({ - questions: needSelection.map(({ issueId, options }) => ({ - question: `Select solution for ${issueId}:`, - header: issueId, + questions: pendingSelections.map(({ issue_id, solutions }) => ({ + question: `Select solution for ${issue_id}:`, + header: issue_id, multiSelect: false, - options: options.map(s => ({ + options: solutions.map(s => ({ label: `${s.id} (${s.task_count} tasks)`, - description: s.description || 'Solution' + description: s.description })) })) }); - // Bind selected solutions - for (const { issueId } of needSelection) { - const selectedSolId = extractSelectedSolutionId(answer, issueId); - if (selectedSolId) bindSolution(issueId, selectedSolId); + // Bind user-selected solutions + for (const { issue_id } of pendingSelections) { + const selectedId = extractSelectedSolutionId(answer, issue_id); + if (selectedId) { + Bash(`ccw issue bind ${issue_id} ${selectedId}`); + console.log(`✓ ${issue_id}: ${selectedId} bound`); + } } } - -// Helper: bind solution to issue (using CLI for safety) -function bindSolution(issueId, solutionId) { - Bash(`ccw issue bind ${issueId} ${solutionId}`); -} ``` ### Phase 4: Summary @@ -312,86 +250,6 @@ Next: \`/issue:queue\` → \`/issue:execute\` `); ``` -## Solution Format (Closed-Loop Tasks) - -Each solution line in `solutions/{issue-id}.jsonl`: - -```json -{ - "id": "SOL-20251226-001", - "description": "Direct Implementation", - "tasks": [ - { - "id": "T1", - "title": "Create auth middleware", - "scope": "src/middleware/", - "action": "Create", - "description": "Create JWT validation middleware", - "modification_points": [ - { "file": "src/middleware/auth.ts", "target": "new file", "change": "Create middleware" } - ], - - "implementation": [ - "Create auth.ts file in src/middleware/", - "Implement JWT token validation using jsonwebtoken", - "Add error handling for invalid/expired tokens", - "Export middleware function" - ], - - "test": { - "unit": [ - "Test valid token passes through", - "Test invalid token returns 401", - "Test expired token returns 401", - "Test missing token returns 401" - ], - "commands": [ - "npm test -- --grep 'auth middleware'", - "npm run test:coverage -- src/middleware/auth.ts" - ], - "coverage_target": 80 - }, - - "regression": [ - "npm test -- --grep 'protected routes'", - "npm run test:integration -- auth" - ], - - "acceptance": { - "criteria": [ - "Middleware validates JWT tokens successfully", - "Returns 401 for invalid or missing tokens", - "Passes decoded token to request context" - ], - "verification": [ - "curl -H 'Authorization: Bearer valid_token' /api/protected → 200", - "curl /api/protected → 401", - "curl -H 'Authorization: Bearer invalid' /api/protected → 401" - ] - }, - - "commit": { - "type": "feat", - "scope": "auth", - "message_template": "feat(auth): add JWT validation middleware\n\n- Implement token validation\n- Add error handling for invalid tokens\n- Export for route protection", - "breaking": false - }, - - "depends_on": [], - "estimated_minutes": 30, - "executor": "codex" - } - ], - "exploration_context": { - "relevant_files": ["src/config/auth.ts"], - "patterns": "Follow existing middleware pattern" - }, - "is_bound": true, - "created_at": "2025-12-26T10:00:00Z", - "bound_at": "2025-12-26T10:05:00Z" -} -``` - ## Error Handling | Error | Resolution | @@ -402,17 +260,6 @@ Each solution line in `solutions/{issue-id}.jsonl`: | User cancels selection | Skip issue, continue with others | | File conflicts | Agent detects and suggests resolution order | -## Agent Integration - -The command uses `issue-plan-agent` which: -1. Performs ACE semantic search per issue -2. Identifies modification points and patterns -3. Generates task breakdown with dependencies -4. Detects cross-issue file conflicts -5. Outputs solution JSON for registration - -See `.claude/agents/issue-plan-agent.md` for agent specification. - ## Related Commands - `/issue:queue` - Form execution queue from bound solutions diff --git a/.claude/commands/issue/queue.md b/.claude/commands/issue/queue.md index 35037aa5..4efe2164 100644 --- a/.claude/commands/issue/queue.md +++ b/.claude/commands/issue/queue.md @@ -9,16 +9,39 @@ allowed-tools: TodoWrite(*), Task(*), Bash(*), Read(*), Write(*) ## Overview -Queue formation command using **issue-queue-agent** that analyzes all bound solutions, resolves conflicts, determines dependencies, and creates an ordered execution queue. The queue is global across all issues. +Queue formation command using **issue-queue-agent** that analyzes all bound solutions, resolves conflicts, and creates an ordered execution queue. + +## Output Requirements + +**Generate Files:** +1. `.workflow/issues/queues/{queue-id}.json` - Full queue with tasks, conflicts, groups +2. `.workflow/issues/queues/index.json` - Update with new queue entry + +**Return Summary:** +```json +{ + "queue_id": "QUE-20251227-143000", + "total_tasks": N, + "execution_groups": [{ "id": "P1", "type": "parallel", "count": N }], + "conflicts_resolved": N, + "issues_queued": ["GH-123", "GH-124"] +} +``` + +**Completion Criteria:** +- [ ] Queue JSON generated with valid DAG (no cycles) +- [ ] All file conflicts resolved with rationale +- [ ] Semantic priority calculated for all tasks +- [ ] Execution groups assigned (parallel P* / sequential S*) +- [ ] Issue statuses updated to `queued` via `ccw issue update` + +## Core Capabilities -**Core capabilities:** - **Agent-driven**: issue-queue-agent handles all ordering logic -- ACE semantic search for relationship discovery - Dependency DAG construction and cycle detection - File conflict detection and resolution - Semantic priority calculation (0.0-1.0) - Parallel/Sequential group assignment -- Output global queue.json ## Storage Structure (Queue History) @@ -168,162 +191,93 @@ console.log(`Loaded ${allTasks.length} tasks from ${plannedIssues.length} issues ### Phase 2-4: Agent-Driven Queue Formation ```javascript -// Launch issue-queue-agent to handle all ordering logic +// Build minimal prompt - agent reads schema and handles ordering const agentPrompt = ` -## Tasks to Order +## Order Tasks -${JSON.stringify(allTasks, null, 2)} +**Tasks**: ${allTasks.length} from ${plannedIssues.length} issues +**Project Root**: ${process.cwd()} -## Project Root -${process.cwd()} +### Input +\`\`\`json +${JSON.stringify(allTasks.map(t => ({ + key: \`\${t.issue_id}:\${t.task.id}\`, + type: t.task.type, + file_context: t.task.file_context, + depends_on: t.task.depends_on +})), null, 2)} +\`\`\` -## Requirements -1. Build dependency DAG from depends_on fields -2. Detect circular dependencies (abort if found) -3. Identify file modification conflicts -4. Resolve conflicts using ordering rules: - - Create before Update/Implement - - Foundation scopes (config/types) before implementation - - Core logic before tests -5. Calculate semantic priority (0.0-1.0) for each task -6. Assign execution groups (parallel P* / sequential S*) -7. Output queue JSON +### Steps +1. Parse tasks: Extract task keys, types, file contexts, dependencies +2. Build DAG: Construct dependency graph from depends_on references +3. Detect cycles: Verify no circular dependencies exist (abort if found) +4. Detect conflicts: Identify file modification conflicts across issues +5. Resolve conflicts: Apply ordering rules (Create→Update→Delete, config→src→tests) +6. Calculate priority: Compute semantic priority (0.0-1.0) for each task +7. Assign groups: Assign parallel (P*) or sequential (S*) execution groups +8. Generate queue: Write queue JSON with ordered tasks +9. Update index: Update queues/index.json with new queue entry + +### Rules +- **DAG Validity**: Output must be valid DAG with no circular dependencies +- **Conflict Resolution**: All file conflicts must be resolved with rationale +- **Ordering Priority**: + 1. Create before Update (files must exist before modification) + 2. Foundation before integration (config/ → src/) + 3. Types before implementation (types/ → components/) + 4. Core before tests (src/ → __tests__/) + 5. Delete last (preserve dependencies until no longer needed) +- **Parallel Safety**: Tasks in same parallel group must have no file conflicts +- **Queue ID Format**: \`QUE-YYYYMMDD-HHMMSS\` (UTC timestamp) + +### Generate Files +1. \`.workflow/issues/queues/\${queueId}.json\` - Full queue (schema: cat .claude/workflows/cli-templates/schemas/queue-schema.json) +2. \`.workflow/issues/queues/index.json\` - Update with new entry + +### Return Summary +\`\`\`json +{ + "queue_id": "QUE-YYYYMMDD-HHMMSS", + "total_tasks": N, + "execution_groups": [{ "id": "P1", "type": "parallel", "count": N }], + "conflicts_resolved": N, + "issues_queued": ["GH-123"] +} +\`\`\` `; const result = Task( subagent_type="issue-queue-agent", run_in_background=false, - description=`Order ${allTasks.length} tasks from ${plannedIssues.length} issues`, + description=`Order ${allTasks.length} tasks`, prompt=agentPrompt ); -// Parse agent output -const agentOutput = JSON.parse(result); - -if (!agentOutput.success) { - console.error(`Queue formation failed: ${agentOutput.error}`); - if (agentOutput.cycles) { - console.error('Circular dependencies:', agentOutput.cycles.join(', ')); - } - return; -} +const summary = JSON.parse(result); ``` -### Phase 5: Queue Output & Summary +### Phase 5: Summary & Status Update ```javascript -const queueOutput = agentOutput.output; - -// Write queue.json -Write('.workflow/issues/queue.json', JSON.stringify(queueOutput, null, 2)); - -// Update issue statuses in issues.jsonl -const updatedIssues = allIssues.map(issue => { - if (plannedIssues.find(p => p.id === issue.id)) { - return { - ...issue, - status: 'queued', - queued_at: new Date().toISOString(), - updated_at: new Date().toISOString() - }; - } - return issue; -}); - -Write(issuesPath, updatedIssues.map(i => JSON.stringify(i)).join('\n')); - -// Display summary +// Agent already generated queue files, use summary console.log(` -## Queue Formed +## Queue Formed: ${summary.queue_id} -**Total Tasks**: ${queueOutput.tasks.length} -**Issues**: ${plannedIssues.length} -**Conflicts**: ${queueOutput.conflicts?.length || 0} (${queueOutput._metadata?.resolved_conflicts || 0} resolved) +**Tasks**: ${summary.total_tasks} +**Issues**: ${summary.issues_queued.join(', ')} +**Groups**: ${summary.execution_groups.map(g => `${g.id}(${g.count})`).join(', ')} +**Conflicts Resolved**: ${summary.conflicts_resolved} -### Execution Groups -${(queueOutput.execution_groups || []).map(g => { - const type = g.type === 'parallel' ? 'Parallel' : 'Sequential'; - return `- ${g.id} (${type}): ${g.task_count} tasks`; -}).join('\n')} - -### Next Steps -1. Review queue: \`ccw issue queue list\` -2. Execute: \`/issue:execute\` +Next: \`/issue:execute\` `); -``` -## Queue Schema - -Output `queues/{queue-id}.json`: - -```json -{ - "name": "Auth Feature Queue", - "status": "active", - "issue_ids": ["GH-123", "GH-124"], - - "tasks": [ - { - "item_id": "T-1", - "issue_id": "GH-123", - "solution_id": "SOL-001", - "task_id": "T1", - "status": "pending", - "execution_order": 1, - "execution_group": "P1", - "depends_on": [], - "semantic_priority": 0.7 - } - ], - - "conflicts": [ - { - "type": "file_conflict", - "file": "src/auth.ts", - "tasks": ["GH-123:T1", "GH-124:T2"], - "resolution": "sequential", - "resolution_order": ["GH-123:T1", "GH-124:T2"], - "rationale": "T1 creates file before T2 updates", - "resolved": true - } - ], - - "execution_groups": [ - { "id": "P1", "type": "parallel", "task_count": 3, "tasks": ["T-1", "T-2", "T-3"] }, - { "id": "S2", "type": "sequential", "task_count": 2, "tasks": ["T-4", "T-5"] } - ], - - "_metadata": { - "version": "2.1-optimized", - "total_tasks": 5, - "pending_count": 3, - "completed_count": 2, - "failed_count": 0, - "updated_at": "2025-12-26T11:00:00Z", - "source": "issue-queue-agent" - } +// Update issue statuses via CLI +for (const issueId of summary.issues_queued) { + Bash(`ccw issue update ${issueId} --status queued`); } ``` -### Queue ID Format - -``` -QUE-YYYYMMDD-HHMMSS -例如: QUE-20251227-143052 -``` - -## Semantic Priority Rules - -| Factor | Priority Boost | -|--------|---------------| -| Create action | +0.2 | -| Configure action | +0.15 | -| Implement action | +0.1 | -| Config/Types scope | +0.1 | -| Refactor action | -0.05 | -| Test action | -0.1 | -| Delete action | -0.15 | - ## Error Handling | Error | Resolution | @@ -333,19 +287,6 @@ QUE-YYYYMMDD-HHMMSS | Unresolved conflicts | Agent resolves using ordering rules | | Invalid task reference | Skip and warn | -## Agent Integration - -The command uses `issue-queue-agent` which: -1. Builds dependency DAG from task depends_on fields -2. Detects circular dependencies (aborts if found) -3. Identifies file modification conflicts across issues -4. Resolves conflicts using semantic ordering rules -5. Calculates priority (0.0-1.0) for each task -6. Assigns parallel/sequential execution groups -7. Outputs structured queue JSON - -See `.claude/agents/issue-queue-agent.md` for agent specification. - ## Related Commands - `/issue:plan` - Plan issues and bind solutions diff --git a/.claude/skills/issue-manage/SKILL.md b/.claude/skills/issue-manage/SKILL.md new file mode 100644 index 00000000..d69d8a13 --- /dev/null +++ b/.claude/skills/issue-manage/SKILL.md @@ -0,0 +1,244 @@ +--- +name: issue-manage +description: Interactive issue management with menu-driven CRUD operations. Use when managing issues, viewing issue status, editing issue fields, or performing bulk operations on issues. Triggers on "manage issue", "list issues", "edit issue", "delete issue", "bulk update", "issue dashboard". +allowed-tools: Bash, Read, Write, AskUserQuestion, Task, Glob +--- + +# Issue Management Skill + +Interactive menu-driven interface for issue CRUD operations via `ccw issue` CLI. + +## Quick Start + +Ask me: +- "Show all issues" → List with filters +- "View issue GH-123" → Detailed inspection +- "Edit issue priority" → Modify fields +- "Delete old issues" → Remove with confirmation +- "Bulk update status" → Batch operations + +## CLI Endpoints + +```bash +# Core operations +ccw issue list # List all issues +ccw issue list --json # Get issue details +ccw issue status # Detailed status +ccw issue init --title "..." # Create issue +ccw issue task --title "..." # Add task +ccw issue bind # Bind solution + +# Queue management +ccw issue queue # List current queue +ccw issue queue add # Add to queue +ccw issue queue list # Queue history +ccw issue queue switch # Switch queue +ccw issue queue archive # Archive queue +ccw issue queue delete # Delete queue +ccw issue next # Get next task +ccw issue done # Mark completed +``` + +## Operations + +### 1. LIST 📋 + +Filter and browse issues: + +``` +┌─ Filter by Status ─────────────────┐ +│ □ All □ Registered │ +│ □ Planned □ Queued │ +│ □ Executing □ Completed │ +└────────────────────────────────────┘ +``` + +**Flow**: +1. Ask filter preferences → `ccw issue list --json` +2. Display table: ID | Status | Priority | Title +3. Select issue for detail view + +### 2. VIEW 🔍 + +Detailed issue inspection: + +``` +┌─ Issue: GH-123 ─────────────────────┐ +│ Title: Fix authentication bug │ +│ Status: planned | Priority: P2 │ +│ Solutions: 2 (1 bound) │ +│ Tasks: 5 pending │ +└─────────────────────────────────────┘ +``` + +**Flow**: +1. Fetch `ccw issue status --json` +2. Display issue + solutions + tasks +3. Offer actions: Edit | Plan | Queue | Delete + +### 3. EDIT ✏️ + +Modify issue fields: + +| Field | Options | +|-------|---------| +| Title | Free text | +| Priority | P1-P5 | +| Status | registered → completed | +| Context | Problem description | +| Labels | Comma-separated | + +**Flow**: +1. Select field to edit +2. Show current value +3. Collect new value via AskUserQuestion +4. Update `.workflow/issues/issues.jsonl` + +### 4. DELETE 🗑️ + +Remove with confirmation: + +``` +⚠️ Delete issue GH-123? +This will also remove: +- Associated solutions +- Queued tasks + +[Delete] [Cancel] +``` + +**Flow**: +1. Confirm deletion via AskUserQuestion +2. Remove from `issues.jsonl` +3. Clean up `solutions/.jsonl` +4. Remove from `queue.json` + +### 5. BULK 📦 + +Batch operations: + +| Operation | Description | +|-----------|-------------| +| Update Status | Change multiple issues | +| Update Priority | Batch priority change | +| Add Labels | Tag multiple issues | +| Delete Multiple | Bulk removal | +| Queue All Planned | Add all planned to queue | +| Retry All Failed | Reset failed tasks | + +## Workflow + +``` +┌──────────────────────────────────────┐ +│ Main Menu │ +│ ┌────┐ ┌────┐ ┌────┐ ┌────┐ │ +│ │List│ │View│ │Edit│ │Bulk│ │ +│ └──┬─┘ └──┬─┘ └──┬─┘ └──┬─┘ │ +└─────┼──────┼──────┼──────┼──────────┘ + │ │ │ │ + ▼ ▼ ▼ ▼ + Filter Detail Fields Multi + Select Actions Update Select + │ │ │ │ + └──────┴──────┴──────┘ + │ + ▼ + Back to Menu +``` + +## Implementation Guide + +### Entry Point + +```javascript +// Parse input for issue ID +const issueId = input.match(/^([A-Z]+-\d+|ISS-\d+)/i)?.[1]; + +// Show main menu +await showMainMenu(issueId); +``` + +### Main Menu Pattern + +```javascript +// 1. Fetch dashboard data +const issues = JSON.parse(Bash('ccw issue list --json') || '[]'); +const queue = JSON.parse(Bash('ccw issue queue --json 2>/dev/null') || '{}'); + +// 2. Display summary +console.log(`Issues: ${issues.length} | Queue: ${queue.pending_count || 0} pending`); + +// 3. Ask action via AskUserQuestion +const action = AskUserQuestion({ + questions: [{ + question: 'What would you like to do?', + header: 'Action', + options: [ + { label: 'List Issues', description: 'Browse with filters' }, + { label: 'View Issue', description: 'Detail view' }, + { label: 'Edit Issue', description: 'Modify fields' }, + { label: 'Bulk Operations', description: 'Batch actions' } + ] + }] +}); + +// 4. Route to handler +``` + +### Filter Pattern + +```javascript +const filter = AskUserQuestion({ + questions: [{ + question: 'Filter by status?', + header: 'Filter', + multiSelect: true, + options: [ + { label: 'All', description: 'Show all' }, + { label: 'Registered', description: 'Unplanned' }, + { label: 'Planned', description: 'Has solution' }, + { label: 'Executing', description: 'In progress' } + ] + }] +}); +``` + +### Edit Pattern + +```javascript +// Select field +const field = AskUserQuestion({...}); + +// Get new value based on field type +// For Priority: show P1-P5 options +// For Status: show status options +// For Title: accept free text via "Other" + +// Update file +const issuesPath = '.workflow/issues/issues.jsonl'; +// Read → Parse → Update → Write +``` + +## Data Files + +| File | Purpose | +|------|---------| +| `.workflow/issues/issues.jsonl` | Issue records | +| `.workflow/issues/solutions/.jsonl` | Solutions per issue | +| `.workflow/issues/queue.json` | Execution queue | + +## Error Handling + +| Error | Resolution | +|-------|------------| +| No issues found | Suggest `/issue:new` to create | +| Issue not found | Show available issues, re-prompt | +| Write failure | Check file permissions | +| Queue error | Display ccw error message | + +## Related Commands + +- `/issue:new` - Create structured issue +- `/issue:plan` - Generate solution +- `/issue:queue` - Form execution queue +- `/issue:execute` - Execute tasks