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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 213 additions & 0 deletions .coworkflow/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# 前置依赖文件: [requirements.md](./requirements.md)

# Design Document

## Overview

This feature implements comprehensive support for .coworkflow directory Markdown files by adding file monitoring, CodeLens operations, and visual decorations. The implementation follows VS Code extension patterns and integrates with the existing extension architecture.

## Architecture

The feature consists of three main components:

1. **CoworkflowFileWatcher**: Monitors .coworkflow directory files and coordinates updates
2. **CoworkflowCodeLensProvider**: Provides contextual actions via CodeLens for different document types
3. **CoworkflowDecorationProvider**: Manages visual decorations for task status indicators

### Component Interaction Flow

```mermaid
graph TD
A[Extension Activation] --> B[CoworkflowFileWatcher]
B --> C[File System Watchers]
B --> D[CoworkflowCodeLensProvider]
B --> E[CoworkflowDecorationProvider]

C --> F[File Change Events]
F --> D
F --> E

D --> G[CodeLens Actions]
G --> H[Command Execution]

E --> I[Text Editor Decorations]
I --> J[Visual Status Indicators]
```

## Components and Interfaces

### 1. CoworkflowFileWatcher

**Purpose**: Central coordinator for file monitoring and provider management

**Key Responsibilities**:

- Monitor .coworkflow directory for requirements.md, design.md, tasks.md
- Coordinate updates between CodeLens and decoration providers
- Handle workspace changes and re-establish watchers

**Interface**:

```typescript
interface CoworkflowFileWatcher {
initialize(): void
dispose(): void
onFileChanged(uri: vscode.Uri): void
getCoworkflowPath(): string | undefined
}
```

### 2. CoworkflowCodeLensProvider

**Purpose**: Provide contextual actions for different document types

**Key Responsibilities**:

- Parse document structure to identify action locations
- Provide document-specific actions (Update, Run, Retry)
- Handle CodeLens command execution

**Interface**:

```typescript
interface CoworkflowCodeLensProvider extends vscode.CodeLensProvider {
provideCodeLenses(document: vscode.TextDocument): vscode.CodeLens[]
resolveCodeLens(codeLens: vscode.CodeLens): vscode.CodeLens
}
```

**Document-Specific Actions**:

- **requirements.md**: "Update" actions at requirement section headers
- **design.md**: "Update" actions at major section headers
- **tasks.md**: "Run" and "Retry" actions at individual task items

### 3. CoworkflowDecorationProvider

**Purpose**: Manage visual status indicators for tasks

**Key Responsibilities**:

- Parse task status indicators: `[ ]`, `[-]`, `[x]`
- Apply appropriate background decorations
- Update decorations when task status changes

**Interface**:

```typescript
interface CoworkflowDecorationProvider {
updateDecorations(document: vscode.TextDocument): void
dispose(): void
}
```

**Decoration Types**:

- `[ ]` (未开始): No background decoration
- `[-]` (进行中): Light yellow background (`rgba(255, 255, 0, 0.2)`)
- `[x]` (已完成): Light green background (`rgba(0, 255, 0, 0.2)`)

## Data Models

### Task Status Model

```typescript
interface TaskStatus {
line: number
range: vscode.Range
status: "not_started" | "in_progress" | "completed"
text: string
}
```

### CodeLens Action Model

```typescript
interface CoworkflowCodeLens extends vscode.CodeLens {
documentType: "requirements" | "design" | "tasks"
actionType: "update" | "run" | "retry"
context?: {
taskId?: string
sectionTitle?: string
}
}
```

### File Context Model

```typescript
interface CoworkflowFileContext {
uri: vscode.Uri
type: "requirements" | "design" | "tasks"
lastModified: Date
isActive: boolean
}
```

## Error Handling

### File System Errors

- **Missing .coworkflow directory**: Gracefully disable watchers without errors
- **Missing target files**: Handle file absence without crashing providers
- **File permission errors**: Log warnings and continue with available functionality

### Parsing Errors

- **Malformed Markdown**: Provide basic functionality, skip problematic sections
- **Invalid task status**: Default to 'not_started' status for unknown formats
- **Corrupted file content**: Use fallback parsing with error logging

### Provider Errors

- **CodeLens resolution failures**: Return empty CodeLens array
- **Decoration application failures**: Log errors and continue
- **Command execution errors**: Show user-friendly error messages

## Testing Strategy

### Unit Tests

- **CoworkflowFileWatcher**: Test file monitoring, workspace changes, disposal
- **CoworkflowCodeLensProvider**: Test document parsing, CodeLens generation, command resolution
- **CoworkflowDecorationProvider**: Test task status parsing, decoration application

### Integration Tests

- **File System Integration**: Test actual file watching with temporary files
- **VS Code API Integration**: Test CodeLens and decoration providers with mock documents
- **Command Integration**: Test command execution and error handling

### Edge Case Tests

- **Empty files**: Ensure providers handle empty documents
- **Large files**: Test performance with documents containing many tasks
- **Concurrent changes**: Test behavior when multiple files change simultaneously
- **Workspace switching**: Test proper cleanup and re-initialization

## Implementation Phases

### Phase 1: Core Infrastructure

- Implement CoworkflowFileWatcher with basic file monitoring
- Set up provider registration and disposal patterns
- Create basic command structure

### Phase 2: CodeLens Implementation

- Implement CoworkflowCodeLensProvider with document parsing
- Add document-specific action detection
- Implement command handlers for Update, Run, Retry actions

### Phase 3: Decoration Implementation

- Implement CoworkflowDecorationProvider with task status parsing
- Create decoration types for different task statuses
- Add real-time decoration updates

### Phase 4: Integration and Polish

- Integrate all components with extension activation
- Add comprehensive error handling
- Implement performance optimizations
- Add configuration options if needed
62 changes: 62 additions & 0 deletions .coworkflow/requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Requirements Document

## Introduction

This feature adds comprehensive support for .coworkflow directory Markdown files in the VS Code extension. It provides file monitoring, CodeLens operations, and visual decorations for task status tracking in requirements.md, design.md, and tasks.md files.

## Requirements

### Requirement 1

**User Story:** As a developer, I want the extension to monitor .coworkflow directory files, so that I can get real-time updates and interactions with my workflow documents.

#### Acceptance Criteria

1. WHEN a .coworkflow directory exists in the workspace THEN the extension SHALL monitor requirements.md, design.md, and tasks.md files
2. WHEN any of these files are created, modified, or deleted THEN the extension SHALL update the corresponding providers and decorations
3. WHEN the workspace changes THEN the extension SHALL re-establish file watchers for the new workspace

### Requirement 2

**User Story:** As a developer, I want CodeLens operations on specific document sections, so that I can quickly perform actions relevant to each document type.

#### Acceptance Criteria

1. WHEN viewing requirements.md THEN the extension SHALL provide "Update" CodeLens actions at appropriate locations
2. WHEN viewing design.md THEN the extension SHALL provide "Update" CodeLens actions at appropriate locations
3. WHEN viewing tasks.md THEN the extension SHALL provide "Run" and "Retry" CodeLens actions for each task item
4. WHEN clicking a CodeLens action THEN the extension SHALL execute the corresponding command with proper context

### Requirement 3

**User Story:** As a developer, I want visual status indicators for tasks, so that I can quickly identify task progress at a glance.

#### Acceptance Criteria

1. WHEN viewing tasks.md THEN tasks with `[ ]` status SHALL have no background decoration
2. WHEN viewing tasks.md THEN tasks with `[-]` status SHALL have a light yellow background decoration
3. WHEN viewing tasks.md THEN tasks with `[x]` status SHALL have a light green background decoration
4. WHEN task status changes THEN decorations SHALL update automatically
5. WHEN multiple tasks exist THEN each SHALL have independent status decoration

### Requirement 4

**User Story:** As a developer, I want the CodeLens to appear at meaningful locations in each document, so that the actions are contextually relevant.

#### Acceptance Criteria

1. WHEN viewing requirements.md THEN CodeLens SHALL appear at requirement section headers
2. WHEN viewing design.md THEN CodeLens SHALL appear at major section headers
3. WHEN viewing tasks.md THEN CodeLens SHALL appear at individual task items
4. WHEN document structure changes THEN CodeLens positions SHALL update accordingly

### Requirement 5

**User Story:** As a developer, I want the extension to handle edge cases gracefully, so that the feature works reliably in various scenarios.

#### Acceptance Criteria

1. WHEN .coworkflow directory doesn't exist THEN the extension SHALL not activate file watchers
2. WHEN monitored files don't exist THEN the extension SHALL handle missing files without errors
3. WHEN files have malformed content THEN the extension SHALL provide basic functionality without crashing
4. WHEN multiple workspaces are open THEN each workspace SHALL have independent file monitoring
Loading