前几天我编写的《C语言圣经》成功配置并发布到互联网上,苦于没有合适的练习系统,又因为之前参加了一个训练营,其中的rustlings让我格外喜欢,因此也想做一个控制台交互程序来进行C语言的练习。

很可惜本人对相关脚本的知识八窍通了七窍,只好寄希望于AI来实现。这个系统的第一个版本是由cursor来为我设计并成功运行的,他由于是我第一次进行AI设计我毫无涉及领域的内容,因此只能浮于表象对大模型只通过自然语言对其进行鞭笞。不过好在最后成功上线Github上并给其命名为CStudy。

显而易见的,我对他的功能并不满意,因此我删掉了存储库后这个项目便一直搁置,知道前段时间我将Gitbook上传才重新开始编写。

这次我用的是字节跳动的Trea,参加过Cursor Meetup Xi’an后我尝试使用设计文档下的微调开发模式,先行给他一个设计文档,再根据模型的反馈进行逐步微调。但是Trea_CN的内置模型用到最后又变成了我面向结果的开发过程,导致整个项目混乱到像是恋爱关系,只好又清空文档,将目光投向前几天刷到的spec-kit上。

规范驱动开发颠覆了传统软件开发的脚本。几十年来,代码一直是王道——规范只是我们构建的脚手架,一旦编码的“真正工作”开始,我们就会丢弃。规范驱动开发改变了这一点:规范变得可执行,直接生成工作实现,而不仅仅是指导它们。

在这个新世界中,维护软件意味着不断发展的规范。开发团队的意图以自然语言(“意图驱动开发”)、设计资产、核心原则和其他准则来表达。发展的通用语言更上一层楼,而代码是最后一英里的方法(来源:spec-kit)。spec-kit采用规范驱动开发的方式,替换掉原先的开发方式,这让我萌生了使用他来开发CStudy的念头

Streamlining SDD with Commands

The SDD methodology is significantly enhanced through three powerful commands that automate the specification → planning → tasking workflow:

The Command/speckit.specify

This command transforms a simple feature description (the user-prompt) into a complete, structured specification with automatic repository management:

  1. Automatic Feature Numbering: Scans existing specs to determine the next feature number (e.g., 001, 002, 003)
  2. Branch Creation: Generates a semantic branch name from your description and creates it automatically
  3. Template-Based Generation: Copies and customizes the feature specification template with your requirements
  4. Directory Structure: Creates the proper structure for all related documentsspecs/[branch-name]/

The Command/speckit.plan

Once a feature specification exists, this command creates a comprehensive implementation plan:

  1. Specification Analysis: Reads and understands the feature requirements, user stories, and acceptance criteria
  2. Constitutional Compliance: Ensures alignment with project constitution and architectural principles
  3. Technical Translation: Converts business requirements into technical architecture and implementation details
  4. Detailed Documentation: Generates supporting documents for data models, API contracts, and test scenarios
  5. Quickstart Validation: Produces a quickstart guide capturing key validation scenarios

The Command/speckit.tasks

After a plan is created, this command analyzes the plan and related design documents to generate an executable task list:

  1. Inputs: Reads (required) and, if present, , , and plan.md``data-model.md``contracts/``research.md
  2. Task Derivation: Converts contracts, entities, and scenarios into specific tasks
  3. Parallelization: Marks independent tasks and outlines safe parallel groups[P]
  4. Output: Writes in the feature directory, ready for execution by a Task agenttasks.md

安装过程

uv tool install specify-cli --from git+https://github.com/github/spec-kit.git安装spec-kit前,powershell提示我:

1
uv: The term 'uv' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

很显然我没有这个叫uv的东西,经过一番查阅后,我才知道他是新一代极速 Python 包管理器,既然如此在使用pip install uv下载后,spec-kit便安装成功。后续提示我没有配置环境变量也被逐一解决。

开始使用

进入想要创建项目的文件夹,我这里进入的是D盘的根目录

1
specify init <PROJECT_NAME>

<PROJECT_NAME>替换为想要的项目名称后(由于已经创建过CStudy,所以前面的步骤由我构思的另一个项目来代替),他会提示你选择对应的代理工具

image-20251015202324539

我选择的代理是Copilot,之后会提示你选择你的终端

image-20251015202452354

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Selected AI assistant: copilot
Selected script type: ps
Initialize Specify Project
├── ● Check required tools (ok)
├── ● Select AI assistant (copilot)
├── ● Select script type (ps)
├── ● Fetch latest release (release v0.0.64 (51,215 bytes))
├── ● Download template (spec-kit-template-copilot-ps-v0.0.64.zip)
├── ● Extract template
├── ● Archive contents (28 entries)
├── ● Extraction summary (3 top-level items)
├── ○ Ensure scripts executable
├── ● Cleanup
├── ● Initialize git repository (initialized)
└── ● Finalize (project ready)

Project ready.

image-20251015202631130

选择Powershell,在一系列构建后,便可以打开这一文件夹进行后续操作了

准备工作(可选)

你可以在文件夹中看见constitution这一md文件,他在第一行为我们预留出规则的大体方向

1
2
# [PROJECT_NAME] Constitution
<!-- Example: Spec Constitution, TaskFlow Constitution, etc. -->

根据我们项目的规模和预期,可以通过在其中添加规则来达到我们的要求

image-20251017141044081

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# CStudy Project Constitution

## Core Principles

### I. Cross-Platform Compatibility (NON-NEGOTIABLE)
**All components must run on Windows, Linux, and macOS without modification**
- Platform detection must be automatic; no manual configuration required
- Path handling must use platform-agnostic methods (normalize separators, handle drive letters)
- Shell scripts must have cross-platform equivalents or runtime detection
- File encoding must be UTF-8 across all platforms to ensure Chinese character support
- Line endings must be handled consistently (normalize to LF internally, respect platform conventions on output)

### II. Modular Architecture
**System must be composed of independently testable, loosely coupled modules**
- **Exercise Management**: Standalone module for loading, organizing, and tracking exercises
- **Grading Engine**: Independent validation module that accepts code and test specs, returns results
- **AI Service**: Optional module with clear interface contracts, can be disabled without breaking core functionality
- **CLI Interface**: Thin orchestration layer that coordinates modules
- Each module must expose a well-defined contract (inputs, outputs, error codes)
- Modules must not share state except through explicit interfaces

### III. Test-First Development (NON-NEGOTIABLE)
**TDD mandatory for all grading logic and core functionality**
- Tests written FIRST → User/stakeholder approval → Tests fail (Red) → Implement (Green) → Refactor
- Grading engine must have test coverage for: compilation success/failure, test case parsing, output comparison, timeout handling, resource limits
- Exercise management must have tests for: directory traversal, metadata parsing, progress tracking
- AI service integration must have mocked tests to avoid external dependencies in CI/CD
- Red-Green-Refactor cycle strictly enforced
- Minimum 80% code coverage for core modules (grading, exercise management)

### IV. Standardized File Formats
**All data exchange uses documented, version-controlled formats**
- **Exercise Description**: Markdown format with standardized sections (Title, Description, Input, Output, Examples)
- **Test Cases**: Structured text format with INPUT/OUTPUT blocks separated by `---` delimiters
- **Grading Results**: JSON format with defined schema (compilation status, test results, timing, errors)
- **Metadata**: JSON format for exercise properties (name, difficulty, tags, order)
- **Configuration**: JSON or YAML for system settings (timeouts, paths, AI model config)
- Format changes require version bumps and backward compatibility plan

### V. Fail-Safe and Sandboxing
**User code must never compromise system stability or security**
- All compilation and execution occurs in isolated temporary directories
- Process timeouts enforced: 2 seconds per test case, 10 seconds per exercise total
- Resource limits applied: memory caps, no network access during grading
- Source files remain read-only during grading operations
- Temporary artifacts cleaned up after each grading session
- Graceful degradation: one failed exercise does not halt batch processing
- All errors logged with context for debugging

### VI. Observability and Debugging
**All operations must be traceable and debuggable**
- Structured logging required: timestamps, operation type, inputs, outputs, exit codes
- Log files organized by date and module: `Detection/logs/YYYYMMDD_HHMMSS_{module}_{exercise}.log`
- Grading results include detailed failure information: expected vs actual output, compiler errors with line numbers
- AI interactions logged: prompts sent, responses received, timing information
- Console output must be clear and actionable: tell users what failed and how to fix it
- UTF-8 encoding enforced in all log files and console output

### VII. Progressive Enhancement
**Core functionality works without optional features**
- **Tier 1 (Core)**: Exercise listing, manual grading (user runs check command)
- **Tier 2 (Enhanced)**: Automatic grading on file save, batch verification
- **Tier 3 (Advanced)**: AI-powered assistance (requires ollama)
- AI service is entirely optional; system must function fully without it
- Missing dependencies detected gracefully with helpful installation guidance
- Features degrade gracefully: if file watching unavailable, manual check still works

## Cross-Platform Requirements

### Platform Detection and Adaptation
- Automatically detect OS at runtime (Windows, Linux, macOS)
- Use platform-appropriate commands:
- **Compiler**: gcc (Linux/macOS/MinGW), cl (MSVC as fallback)
- **Shell**: PowerShell (Windows), bash/sh (Linux/macOS)
- **Editor**: Environment variable `EDITOR`, fallback to `notepad` (Windows), `nano` (Linux), `open -e` (macOS)
- **Path separator**: Use language path libraries that handle platform differences automatically

### File System Conventions
- Support both forward slashes and backslashes in paths; normalize internally to platform standard
- Handle Windows drive letters (C:\, D:\) and Unix-style root (/)
- Temporary directories: Use OS temp location (`%TEMP%` on Windows, `/tmp` on Unix-like)
- Respect platform newline conventions: CRLF (Windows), LF (Unix-like); normalize to LF for processing

### Character Encoding
- **All files**: UTF-8 without BOM (Byte Order Mark)
- Console input/output: UTF-8 encoding explicitly set
- File reads/writes: UTF-8 encoding specified
- Error messages: Support Chinese and English; no garbled characters

### Dependency Management
- **Required**: C compiler (gcc or compatible), accessible via PATH
- **Optional**: ollama (for AI features), with installation detection and guidance
- **Runtime**: Shell interpreter (PowerShell 5.1+ on Windows, bash 4.0+ on Unix)
- Document minimum versions for all dependencies
- Provide installation scripts or guidance for each platform

## Development Workflow

### Directory Structure Standards
```
CStudy/
├─ Exercises/ # Exercise content (cross-platform)
├─ Detection/ # Grading engine and utilities
│ ├─ logs/ # Grading operation logs
│ └─ temp/ # Temporary compilation artifacts (auto-cleaned)
├─ AIserver/ # AI service module (optional)
│ └─ logs/ # AI operation logs
├─ scripts/ # Platform-specific entry points
│ ├─ cstudy.ps1 # Windows PowerShell entry
│ ├─ cstudy.sh # Linux/macOS bash entry
│ └─ common/ # Shared logic modules
└─ tests/ # Test suites
├─ unit/ # Module unit tests
├─ integration/ # Cross-module integration tests
└─ fixtures/ # Test data and sample exercises
```

### Testing Requirements
- **Unit Tests**: Test individual functions/modules in isolation
- **Integration Tests**: Test module interactions (exercise loading → grading → result display)
- **Platform Tests**: CI/CD must run tests on Windows, Linux, and macOS
- **Test Data**: Include sample exercises with known correct/incorrect solutions
- **Mocking**: AI service must be mockable for testing without external dependencies

### Code Review Gates
- All PRs must pass cross-platform CI checks (Windows, Linux, macOS runners)
- Minimum 80% test coverage maintained for core modules
- No hardcoded platform-specific paths or commands
- All new features must include tests before merge
- Documentation updated for user-facing changes

## Error Handling Standards

### Exit Codes (Consistent Across Platforms)
- `0`: Success (all operations completed successfully)
- `1`: General error (unspecified)
- `2`: Compilation error
- `3`: Test case failure
- `4`: Runtime error or timeout
- `5`: AI service error
- `100+`: Internal system errors (logged with full context)

### Error Message Requirements
- Clear, actionable messages telling users what went wrong and how to fix it
- Include context: file path, line number (for compiler errors), expected vs actual (for test failures)
- Avoid technical jargon in user-facing errors
- Log detailed technical information separately for debugging
- Support bilingual messages (Chinese/English) where appropriate

## Performance Standards

### Response Time Requirements
- Exercise listing: < 1 second for up to 100 exercises
- Single exercise grading: < 3 seconds total (including compilation and all test cases)
- Batch grading: < 0.5 seconds per exercise on average
- AI assistance: < 30 seconds from request to response display
- UI refresh: Instantaneous (< 100ms) for screen redraws

### Resource Limits
- Compilation memory limit: 256MB per process
- Execution memory limit: 128MB per test case
- Temporary storage: Auto-cleanup ensures < 100MB accumulation
- Log retention: 30-day automatic rotation (configurable)

## Governance

### Constitution Authority
- This constitution supersedes all other coding practices and guidelines
- Violations must be justified in writing and approved by project maintainers
- All pull requests must verify compliance with these principles

### Amendment Process
1. Proposed changes documented in issue with rationale
2. Stakeholder review period (minimum 7 days)
3. Approval required from project maintainers
4. Migration plan required for breaking changes
5. Constitution version bumped and ratification date updated

### Quality Assurance
- Cross-platform CI/CD pipeline required (GitHub Actions or equivalent)
- Manual testing on at least 2 platforms before release
- User acceptance testing for major feature changes
- Performance benchmarks tracked across versions

### Documentation Requirements
- README must include installation instructions for Windows, Linux, macOS
- API documentation for all module interfaces
- Example exercises with solutions for testing
- Troubleshooting guide for common cross-platform issues

**Version**: 1.0.0 | **Ratified**: 2025-10-15 | **Last Amended**: 2025-10-15

好像有点过头了,让我们手动修改一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# CStudy Project Constitution

## Core Principles

### I. Cross-Platform Compatibility (NON-NEGOTIABLE)
**All components must run on Windows, Linux, and macOS without modification**
- Platform detection must be automatic; no manual configuration required
- Path handling must use platform-agnostic methods (normalize separators, handle drive letters)
- Shell scripts must have cross-platform equivalents or runtime detection
- File encoding must be UTF-8 across all platforms to ensure Chinese character support
- Line endings must be handled consistently (normalize to LF internally, respect platform conventions on output)

### II. Modular Architecture
**System must be composed of independently testable, loosely coupled modules**
- **Exercise Management**: Standalone module for loading, organizing, and tracking exercises
- **Grading Engine**: Independent validation module that accepts code and test specs, returns results
- **AI Service**: Optional module with clear interface contracts, can be disabled without breaking core functionality
- **CLI Interface**: Thin orchestration layer that coordinates modules
- Each module must expose a well-defined contract (inputs, outputs, error codes)
- Modules must not share state except through explicit interfaces

### III. Test-First Development (NON-NEGOTIABLE)
**TDD mandatory for all grading logic and core functionality**
- Tests written FIRST → User/stakeholder approval → Tests fail (Red) → Implement (Green) → Refactor
- Grading engine must have test coverage for: compilation success/failure, test case parsing, output comparison, timeout handling, resource limits
- Exercise management must have tests for: directory traversal, metadata parsing, progress tracking
- AI service integration must have mocked tests to avoid external dependencies in CI/CD
- Red-Green-Refactor cycle strictly enforced

### IV. Standardized File Formats
**All data exchange uses documented, version-controlled formats**
- **Exercise Description**: Markdown format with standardized sections (Title, Description, Input, Output, Examples)
- **Test Cases**: Structured text format with INPUT/OUTPUT blocks separated by `---` delimiters
- **Grading Results**: JSON format with defined schema (compilation status, test results, timing, errors)
- **Metadata**: JSON format for exercise properties (name, difficulty, tags, order)
- **Configuration**: JSON or YAML for system settings (timeouts, paths, AI model config)
- Format changes require version bumps and backward compatibility plan

### V. Fail-Safe and Sandboxing
**User code must never compromise system stability or security**
- All compilation and execution occurs in isolated temporary directories
- Process timeouts enforced: 5 seconds per test case, 20 seconds per exercise total
- Resource limits applied: memory caps, no network access during grading
- Source files remain read-only during grading operations
- Temporary artifacts cleaned up after each grading session
- Graceful degradation: one failed exercise does not halt batch processing
- All errors logged with context for debugging

### VI. Observability and Debugging
**All operations must be traceable and debuggable**
- Structured logging required: timestamps, operation type, inputs, outputs, exit codes
- Log files organized by date and module: `Detection/logs/YYYYMMDD_HHMMSS_{module}_{exercise}.log`
- Grading results include detailed failure information: expected vs actual output, compiler errors with line numbers
- AI interactions logged: prompts sent, responses received, timing information
- Console output must be clear and actionable: tell users what failed and how to fix it
- UTF-8 encoding enforced in all log files and console output

## Cross-Platform Requirements

### Platform Detection and Adaptation
- Automatically detect OS at runtime (Windows, Linux, macOS)
- Use platform-appropriate commands:
- **Compiler**: gcc (Linux/macOS/MinGW), cl (MSVC as fallback)
- **Shell**: PowerShell (Windows), bash/sh (Linux/macOS)
- **Editor**: Environment variable `EDITOR`, fallback to `notepad` (Windows), `nano` (Linux), `open -e` (macOS)
- **Path separator**: Use language path libraries that handle platform differences automatically

### File System Conventions
- Support both forward slashes and backslashes in paths; normalize internally to platform standard
- Handle Windows drive letters (C:\, D:\) and Unix-style root (/)
- Temporary directories: Use OS temp location (`%TEMP%` on Windows, `/tmp` on Unix-like)
- Respect platform newline conventions: CRLF (Windows), LF (Unix-like); normalize to LF for processing

### Character Encoding
- **All files**: UTF-8 without BOM (Byte Order Mark)
- Console input/output: UTF-8 encoding explicitly set
- File reads/writes: UTF-8 encoding specified
- Error messages: Support Chinese and English; no garbled characters

### Dependency Management
- **Required**: C compiler (gcc or compatible), accessible via PATH
- **Optional**: ollama (for AI features), with installation detection and guidance
- **Runtime**: Shell interpreter (PowerShell 5.1+ on Windows, bash 4.0+ on Unix)
- Document minimum versions for all dependencies
- Provide installation scripts or guidance for each platform

## Development Workflow

### Directory Structure Standards
```
CStudy/
├─ Exercises/ # Exercise content (cross-platform)
├─ Detection/ # Grading engine and utilities
│ ├─ logs/ # Grading operation logs
│ └─ temp/ # Temporary compilation artifacts (auto-cleaned)
├─ AIserver/ # AI service module (optional)
│ └─ logs/ # AI operation logs
├─ scripts/ # Platform-specific entry points
│ ├─ cstudy.ps1 # Windows PowerShell entry
│ ├─ cstudy.sh # Linux/macOS bash entry
│ └─ common/ # Shared logic modules
└─ tests/ # Test suites
├─ unit/ # Module unit tests
├─ integration/ # Cross-module integration tests
└─ fixtures/ # Test data and sample exercises
```

### Testing Requirements
- **Unit Tests**: Test individual functions/modules in isolation
- **Integration Tests**: Test module interactions (exercise loading → grading → result display)
- **Platform Tests**: CI/CD must run tests on Windows, Linux, and macOS
- **Test Data**: Include sample exercises with known correct/incorrect solutions
- **Mocking**: AI service must be mockable for testing without external dependencies

### Code Review Gates
- All PRs must pass cross-platform CI checks (Windows, Linux, macOS runners)
- Minimum 80% test coverage maintained for core modules
- No hardcoded platform-specific paths or commands
- All new features must include tests before merge
- Documentation updated for user-facing changes

## Error Handling Standards

### Exit Codes (Consistent Across Platforms)
- `0`: Success (all operations completed successfully)
- `1`: General error (unspecified)
- `2`: Compilation error
- `3`: Test case failure
- `4`: Runtime error or timeout
- `5`: AI service error
- `100+`: Internal system errors (logged with full context)

### Error Message Requirements
- Clear, actionable messages telling users what went wrong and how to fix it
- Include context: file path, line number (for compiler errors), expected vs actual (for test failures)
- Avoid technical jargon in user-facing errors
- Log detailed technical information separately for debugging
- Support bilingual messages (Chinese/English) where appropriate

## Performance Standards

### Response Time Requirements
- Exercise listing: < 3 second for up to 100 exercises
- Single exercise grading: < 5 seconds total (including compilation and all test cases)
- UI refresh: Instantaneous (< 100ms) for screen redraws

### Resource Limits
- Compilation memory limit: 256MB per process
- Execution memory limit: 128MB per test case
- Temporary storage: Auto-cleanup ensures < 100MB accumulation
- Log retention: 30-day automatic rotation (configurable)

## Governance

### Constitution Authority
- This constitution supersedes all other coding practices and guidelines
- Violations must be justified in writing and approved by project maintainers
- All pull requests must verify compliance with these principles

### Amendment Process
1. Proposed changes documented in issue with rationale
2. Stakeholder review period (minimum 7 days)
3. Approval required from project maintainers
4. Migration plan required for breaking changes

### Quality Assurance
- Cross-platform CI/CD pipeline required (GitHub Actions or equivalent)
- User acceptance testing for major feature changes
- Performance benchmarks tracked across versions

### Documentation Requirements
- README must include installation instructions for Windows, Linux, macOS
- API documentation for all module interfaces
- Example exercises with solutions for testing
- Troubleshooting guide for common cross-platform issues

**Version**: 1.0.0 | **Ratified**: 2025-10-15 | **Last Amended**: 2025-10-15

内容调校

我使用VS Code打开CStudy文件夹后,会看见他已经初始化好了这些内容

image-20251015202827271

同样的,AI Chat界面便会多出以下命令内容,作为后续使用spec-kit的关键

image-20251015203006972

命令/speckit.specify

此命令将简单的功能描述(用户提示)转换为具有自动存储库管理的完整结构化规范:

  1. 自动特征编号:扫描现有规格以确定下一个特征编号(例如,001、002、003)
  2. 分支创建:根据您的描述生成语义分支名称并自动创建它
  3. 基于模板的生成:根据您的要求复制和自定义功能规范模板
  4. **目录结构:**为所有相关文档创建正确的结构specs/[branch-name]/

/speckit.specify后添加你对项目的描述,我这里是CStudy设计文档中的内容,在经过一系列操作后给了我这样的输出

1
好的!我理解了。您提供的是CStudy系统的完整技术说明文档作为功能描述。现在我将按照speckit.specify.prompt.md的指令,创建一个业务规格说明。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
完美!让我生成一份执行摘要报告:

✅ 规格说明创建完成
我已成功为CStudy系统创建了完整的业务规格说明文档。以下是完成情况的详细报告:

📋 创建的文件
规格文档: spec.md
质量检查清单: requirements.md
功能分支: 001-cstudy-interactive-c
📊 规格文档概览
用户场景(4个,按优先级排序):
P1 - 完成编程练习并获得即时反馈 (核心学习循环)

7个验收场景,涵盖从启动到自动判题的完整流程
P2 - 批量验证所有练习 (进度跟踪)

5个验收场景,支持全局进度检查
P3 - 获取AI编程辅助 (个性化学习支持)

6个验收场景,从AI启用到代码修复建议
P4 - 管理AI模型 (系统配置)

6个验收场景,涵盖模型下载、切换和删除
功能需求: 50条
练习管理 (FR-001至FR-005): 5条
自动判题 (FR-006至FR-016): 11条
批量验证 (FR-017至FR-021): 5条
用户界面 (FR-022至FR-030): 9条
AI辅助 (FR-031至FR-045): 15条
系统需求 (FR-046至FR-050): 5条
成功标准: 12条可测量的结果
性能指标: 3秒内获得反馈,15秒内完成批量验证
用户体验指标: 90%首次成功率,95%获得可执行反馈
系统健壮性: 处理10个测试用例无性能下降,超时和资源限制保护
边界条件: 9个
涵盖无限循环、编码问题、文件缺失、并发访问、权限错误、磁盘空间等场景

关键实体: 5个
Exercise (练习)
Test Case (测试用例)
Grading Result (判题结果)
AI Model (AI模型)
User Session (用户会话)
✅ 质量验证结果
所有检查项已通过验证:

✅ 内容质量: 无实现细节,专注用户价值和业务需求
✅ 需求完整性: 无待澄清标记,所有需求可测试且明确
✅ 成功标准: 可测量且技术无关
✅ 功能就绪: 所有验收场景已定义,边界条件已识别
🎯 关键特性
此规格说明文档:

纯业务视角: 完全避免了技术实现细节(无PowerShell、gcc、ollama等技术术语)
用户为中心: 从学生学习体验出发描述功能
可测量性: 所有成功标准都包含具体的时间、百分比或计数指标
独立可测: 每个用户故事都可独立测试和交付价值
完整假设: 记录了10条关于用户环境和系统依赖的假设
📁 下一步行动
规格文档已准备就绪,可以进入下一阶段:

使用 /speckit.clarify 澄清任何需要的细节
使用 /speckit.plan 开始规划实现方案
分支信息:

分支名称: 001-cstudy-interactive-c
规格文件: spec.md
检查清单: requirements.md

文件的指令会指定speckit.specify.prompt.md,读取脚本,规格模板,在终端运行后,他会填充spec.md文件作为项目的规格说明

1
cd /mnt/d/CStudy && pwsh -Command "./.specify/scripts/powershell/create-new-feature.ps1 -Json 'CStudy交互式C语言学习平台 - 包含练习管理、自动判题、本地AI辅助和命令行交互界面的完整学习系统'"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Feature Specification: CStudy - Interactive C Programming Learning Platform

**Feature Branch**: `001-cstudy-interactive-c`
**Created**: 2025年10月15日
**Status**: Draft
**Input**: User description: "CStudy - Interactive C Programming Learning Platform with Automated Grading and AI Assistance"

## User Scenarios & Testing *(mandatory)*

### User Story 1 - Complete Programming Exercise with Immediate Feedback (Priority: P1)

A student opens CStudy, views available C programming exercises organized by chapter, selects an exercise to work on, writes their solution in a C file, saves the file, and immediately receives automated feedback showing whether their code compiles and passes all test cases.

**Why this priority**: This is the core learning loop that delivers immediate value. Students can practice coding and receive instant validation without waiting for instructor review.

**Independent Test**: Can be fully tested by creating a simple exercise with test cases, having a user write a solution, saving the file, and verifying that compilation and test results appear within 3 seconds. Delivers immediate learning value even as a standalone feature.

**Acceptance Scenarios**:

1. **Given** a student has launched CStudy, **When** they view the main interface, **Then** they see a welcome message, progress indicator showing completed vs total exercises, and a list of available commands
2. **Given** a student executes the list command, **When** the system displays exercises, **Then** each exercise shows its name, completion status, difficulty level, and file path
3. **Given** a student selects an exercise, **When** the system opens the exercise file, **Then** the file contains the problem description as comments, a designated user editing area, and example test cases
4. **Given** a student has written code and saved the file, **When** the file save is detected, **Then** the system automatically compiles the code within 2 seconds
5. **Given** the code compiles successfully, **When** the system runs test cases, **Then** each test case executes with a maximum timeout of 2 seconds per case
6. **Given** all test cases pass, **When** results are displayed, **Then** the student sees success confirmation and is prompted whether to proceed to the next exercise
7. **Given** compilation fails or tests fail, **When** results are displayed, **Then** the student sees clear error messages showing expected vs actual output, with line numbers for compiler errors

---

### User Story 2 - Batch Verify All Exercises (Priority: P2)

A student wants to check their progress across all exercises without manually opening each one. They execute a check command that runs automated grading on all exercises and displays a summary showing which exercises pass, which fail, and which have not been attempted.

**Why this priority**: Allows students to assess overall progress and identify areas needing attention. Useful for review sessions or before seeking help from instructors.

**Independent Test**: Can be tested by preparing multiple exercises (some complete, some incomplete, some with errors), running the batch check command, and verifying the summary correctly categorizes each exercise. Delivers value for progress tracking independently of other features.

**Acceptance Scenarios**:

1. **Given** a student executes the check command, **When** the system processes exercises, **Then** it traverses all exercise directories organized by chapter in sequential order
2. **Given** the system is checking exercises, **When** processing each exercise, **Then** it compiles the code, runs all test cases, and records results without modifying source files
3. **Given** the check completes, **When** displaying results, **Then** the summary shows total exercises, number passed, number failed, number not attempted, and lists failed exercises with clickable file paths
4. **Given** a batch check is running, **When** an exercise takes longer than 10 seconds total, **Then** the system terminates that exercise with a timeout error and continues to the next exercise
5. **Given** the check summary is displayed, **When** a student clicks on a failed exercise path, **Then** the system opens that exercise file in the configured editor

---

### User Story 3 - Get AI-Powered Coding Assistance (Priority: P3)

A student is stuck on an exercise and requests AI help. The system collects the exercise description, the student's current code, and test cases, sends this context to a local AI model, and displays analysis of potential issues, suggested fixes, and explanations to help the student understand and correct their mistakes.

**Why this priority**: Provides personalized learning support when students are stuck, reducing frustration and enabling self-directed learning. Lower priority because basic learning can occur without AI (students can debug manually or seek human help).

**Independent Test**: Can be tested by setting up a local AI model, creating an exercise with a common error (e.g., off-by-one error), requesting help, and verifying that the AI response includes error analysis and suggested corrections within 30 seconds. Delivers learning support value independently.

**Acceptance Scenarios**:

1. **Given** a student is working on an exercise, **When** they execute the help command, **Then** the system checks if AI service is enabled
2. **Given** AI service is not enabled, **When** help is requested, **Then** the system prompts whether to enable AI and guides through model selection and download
3. **Given** AI service is enabled, **When** help is requested, **Then** the system collects the exercise description, current code, and test cases into a structured prompt
4. **Given** the AI prompt is prepared, **When** sent to the local model, **Then** the system receives a response within 30 seconds containing error analysis, suggested code, and explanation
5. **Given** AI response is received, **When** displayed to the student, **Then** analysis appears first, followed by suggested code in a copyable format, with an option to automatically apply the fix
6. **Given** the student chooses to apply AI suggestion, **When** confirmed, **Then** the system backs up the current file and writes the suggested code to the exercise file

---

### User Story 4 - Manage AI Models (Priority: P4)

A student or instructor wants to manage which AI model is used for coding assistance. They can view available models, download new models, switch between models, and remove unused models to free up disk space.

**Why this priority**: Enables customization of AI assistance based on hardware capabilities and preferences. Lower priority because a default model can serve most users initially.

**Independent Test**: Can be tested by executing AI management commands to list, download, switch, and remove models, verifying each operation completes successfully and updates system state appropriately.

**Acceptance Scenarios**:

1. **Given** a user executes the AI management command, **When** viewing options, **Then** they see commands to list, enable, disable, switch, and remove models
2. **Given** AI is being enabled for the first time, **When** the system checks dependencies, **Then** it verifies ollama is installed and provides installation instructions if missing
3. **Given** selecting a model, **When** multiple models are recommended, **Then** the system displays model names with size requirements and descriptions
4. **Given** downloading a model, **When** the download starts, **Then** progress is displayed and the model is stored in the designated directory
5. **Given** switching models, **When** a new model is selected, **Then** the system prompts whether to remove the old model and updates configuration to use the new model
6. **Given** listing models, **When** the command executes, **Then** all downloaded models are displayed with their status (active/inactive) and storage size

---

### Edge Cases

- What happens when a student's code contains an infinite loop? System must detect timeout (2 seconds per test case), terminate the process, and report timeout error
- What happens when compilation produces Chinese error messages that might display incorrectly? System must enforce UTF-8 encoding for all console and file operations
- What happens when a student saves an empty file or a file with only comments? System should compile and report compilation or test failures appropriately without crashing
- What happens when exercise directory structure is malformed (missing description.md or Test.txt)? System should detect missing required files and display clear error indicating which files are missing
- What happens when multiple students use the same exercise directory simultaneously? System uses temporary directories for compilation/execution to avoid conflicts; source files remain read-only during grading
- What happens when the local AI model is not responding? System should timeout after 30 seconds and inform the user that AI service is unavailable
- What happens when disk space is insufficient for model downloads? System should detect disk space before downloading and warn the user if space is insufficient
- What happens when a student tries to access exercises that don't exist? System should display a helpful message indicating no exercises were found and suggest checking the Exercises directory
- What happens when file system permissions prevent reading exercise files or writing temporary files? System should catch permission errors and display a message indicating the specific file or directory that cannot be accessed

## Requirements *(mandatory)*

### Functional Requirements

#### Exercise Management

- **FR-001**: System MUST organize exercises in a hierarchical directory structure with chapters containing multiple exercises
- **FR-002**: System MUST provide a list command that displays all available exercises with their names, status (completed/incomplete), and file paths
- **FR-003**: System MUST support exercise metadata including name, difficulty level, tags, and ordering within chapters
- **FR-004**: System MUST load exercise descriptions from standardized markdown files containing problem statements, input/output specifications, and examples
- **FR-005**: System MUST provide clickable file paths in terminal output for supported terminals (Windows Terminal, VS Code Terminal)

#### Automated Grading

- **FR-006**: System MUST automatically detect when an exercise file is saved and trigger grading within 3 seconds
- **FR-007**: System MUST compile C code using standard compilation flags (C11 standard with optimization and warnings enabled)
- **FR-008**: System MUST execute compiled programs with test input and capture standard output, standard error, and exit codes
- **FR-009**: System MUST compare program output against expected output using exact byte-for-byte matching (after normalizing line endings)
- **FR-010**: System MUST enforce a timeout limit of 2 seconds per test case and 10 seconds per exercise total
- **FR-011**: System MUST terminate processes that exceed timeout limits and report timeout errors
- **FR-012**: System MUST parse test cases from standardized test files with INPUT and OUTPUT sections separated by delimiters
- **FR-013**: System MUST support multiple test cases per exercise with detailed pass/fail reporting for each case
- **FR-014**: System MUST isolate grading operations in temporary directories to prevent modification of source files
- **FR-015**: System MUST clean up temporary compilation artifacts after grading completes
- **FR-016**: System MUST log all grading operations including timestamps, commands executed, output captured, and exit codes

#### Batch Verification

- **FR-017**: System MUST provide a check command that grades all exercises in the repository
- **FR-018**: System MUST traverse exercise directories in a predictable order (by chapter, then by metadata ordering)
- **FR-019**: System MUST display a summary after batch checking showing total exercises, passed count, failed count, and not-attempted count
- **FR-020**: System MUST list all failed exercises with clickable paths to allow quick navigation
- **FR-021**: System MUST continue processing remaining exercises even if one exercise fails or times out

#### User Interface

- **FR-022**: System MUST display a welcome banner when launched showing the application name and visual branding
- **FR-023**: System MUST display a progress indicator showing completed exercises versus total exercises
- **FR-024**: System MUST refresh the console display when switching between interface modes (clear and redraw)
- **FR-025**: System MUST support commands: check (batch verify), list (show exercises), AI (manage AI service), help me (get AI assistance), quit (exit)
- **FR-026**: System MUST open exercise files in an external editor (using environment variable EDITOR or default editor)
- **FR-027**: System MUST prompt users for confirmation before advancing to the next exercise after completing one
- **FR-028**: System MUST display compilation errors with source line numbers and error descriptions
- **FR-029**: System MUST display test case failures showing input provided, expected output, and actual output
- **FR-030**: System MUST encode all console output and file operations using UTF-8 to support Chinese characters

#### AI Assistance

- **FR-031**: System MUST provide a help command that requests AI-powered coding assistance for the current exercise
- **FR-032**: System MUST detect whether AI service is enabled before processing help requests
- **FR-033**: System MUST prompt users to enable AI service if not already enabled, guiding through model selection and download
- **FR-034**: System MUST collect exercise context (description, current code, test cases) into a structured prompt for AI
- **FR-035**: System MUST send AI prompts to a local AI model (using ollama for model management)
- **FR-036**: System MUST support multiple AI models including default and alternative options for different hardware capabilities
- **FR-037**: System MUST receive AI responses within 30 seconds or report timeout
- **FR-038**: System MUST parse AI responses to extract error analysis, suggested code fixes, and explanations
- **FR-039**: System MUST display AI analysis before showing suggested code
- **FR-040**: System MUST provide an option for users to automatically apply AI-suggested code changes
- **FR-041**: System MUST back up the current exercise file before applying AI suggestions
- **FR-042**: System MUST provide AI management commands to list available models, download models, switch active model, and remove models
- **FR-043**: System MUST verify that ollama is installed before attempting to use AI features
- **FR-044**: System MUST store AI configuration and active model information in a persistent state file
- **FR-045**: System MUST log all AI operations including prompts sent, responses received, and errors encountered

#### System Requirements

- **FR-046**: System MUST verify that required dependencies (C compiler) are available before executing grading operations
- **FR-047**: System MUST store logs in organized directories with timestamps in filenames for traceability
- **FR-048**: System MUST support Windows operating system as the primary platform
- **FR-049**: System MUST handle file paths correctly across different path separators and drive letters
- **FR-050**: System MUST implement resource limits for compilation and execution processes to prevent system overload

### Key Entities

- **Exercise**: Represents a single programming problem with description, starter code template, test cases, metadata (name, difficulty, tags, order), and completion status
- **Test Case**: Represents input data and expected output for validating an exercise solution, with execution time and pass/fail status
- **Grading Result**: Represents the outcome of automated grading including compilation status, test case results, overall pass/fail, error messages, and execution logs
- **AI Model**: Represents a local language model configuration including model name, storage location, size, status (active/inactive), and capabilities
- **User Session**: Represents an active CStudy session including current exercise being worked on, progress state, AI service status, and configuration preferences

## Success Criteria *(mandatory)*

### Measurable Outcomes

- **SC-001**: Students can discover and begin working on an exercise within 30 seconds of launching the application
- **SC-002**: Students receive compilation and test results within 3 seconds of saving their code file
- **SC-003**: Students can complete batch verification of all exercises (assuming 20 exercises averaging 0.5 seconds each) within 15 seconds
- **SC-004**: 90% of students successfully complete their first exercise without external help beyond the automated feedback
- **SC-005**: Students receive AI-powered assistance with error analysis and suggested fixes within 30 seconds of requesting help
- **SC-006**: The system handles exercises with up to 10 test cases per exercise without performance degradation
- **SC-007**: Compilation errors display with sufficient detail that students can locate and fix syntax errors within 2 minutes on average
- **SC-008**: Test case failures show clear differences between expected and actual output enabling students to identify logic errors within 5 minutes on average
- **SC-009**: Students can switch between exercises, check progress, and manage AI settings without restarting the application
- **SC-010**: The system processes exercises with infinite loops or excessive resource usage without crashing or hanging, reporting appropriate timeout or resource limit errors
- **SC-011**: 95% of legitimate student solutions (correct algorithms with minor bugs) receive actionable feedback that leads to successful correction
- **SC-012**: Students can download and enable AI assistance within 5 minutes on systems with stable internet connections

### Assumptions

- Students have basic familiarity with command-line interfaces and can navigate directories
- Students have a C compiler (gcc or compatible) installed and accessible via system PATH
- Students use terminals that support UTF-8 encoding for proper display of Chinese characters
- Students have sufficient disk space for temporary compilation artifacts (approximately 10MB per exercise session)
- For AI features, students have stable internet access for initial model downloads
- For AI features, students have sufficient disk space for local model storage (5-20GB depending on model size)
- Exercise content (descriptions, test cases) is created by instructors or content developers following standardized formats
- Students work on exercises individually (not collaborative editing of the same files simultaneously)
- The system has permission to create temporary directories and execute compiled binaries
- Default timeout values (2 seconds per test case, 10 seconds per exercise) are sufficient for typical exercises on modern hardware

如果遇到他不理解的内容或是需要详细说明的内容,他将会在文章末尾有一个需要澄清的列表,但现在看来我的描述很全面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## Notes

All checklist items pass validation. The specification is complete and ready for the next phase (`/speckit.clarify` or `/speckit.plan`).

### Validation Details:

**Content Quality**: ✅ PASS
- Specification focuses on WHAT users need (learning platform with automated grading) and WHY (immediate feedback, progress tracking, AI assistance)
- Written in plain language describing user experiences and business outcomes
- No mention of specific technologies, frameworks, or implementation details in requirements or success criteria
- All mandatory sections (User Scenarios, Requirements, Success Criteria) are present and complete

**Requirement Completeness**: ✅ PASS
- No [NEEDS CLARIFICATION] markers present
- All 50 functional requirements are specific, actionable, and testable
- Success criteria use measurable metrics (time, percentages, counts) without implementation details
- 27 acceptance scenarios cover primary user flows across 4 prioritized user stories
- 9 edge cases identified covering timeouts, encoding, permissions, and error conditions
- Scope clearly bounded to C programming learning with automated grading and AI assistance
- 10 assumptions documented covering user environment, dependencies, and usage patterns

**Feature Readiness**: ✅ PASS
- Each functional requirement group (Exercise Management, Automated Grading, Batch Verification, User Interface, AI Assistance, System Requirements) maps to user scenarios
- User stories prioritized (P1-P4) with independent test criteria
- Success criteria (SC-001 through SC-012) are measurable and technology-agnostic
- No implementation leakage detected in specification language

倘若你的需要进行澄清,仍然何以借助LLM大模型让他进行猜测

命令/spec-kit.plan

image-20251017150753033

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Implementation Plan: CStudy - Interactive C Programming Learning Platform
Branch: 001-cstudy-interactive-c | Date: 2025-10-17 | Spec: spec.md
Input: Feature specification from spec.md

Summary
本项目采用脚本语言(PowerShell/Bash)实现,确保在 Windows、Linux、MacOS 平台均可运行。练习题采用后续动态添加方式,只要文件夹内容符合规范,脚本会自动检测并录入。核心功能包括练习管理、自动判题、AI辅助、批量验证等,所有操作均支持跨平台。

Technical Context
Language/Version: PowerShell 5.1+(Windows),Bash 4.0+(Linux/macOS),所有脚本需兼容两者
Primary Dependencies: gcc(C编译器,MinGW/WSL/系统自带),ollama(AI辅助,选装),标准shell工具(find、ls、cat、echo等)
Storage: 文件系统(Exercises/、Detection/logs/、AIserver/model/等目录)
Testing: 脚本自带单元测试(PowerShell/Bash),CI平台(GitHub Actions)自动运行跨平台测试
Target Platform: Windows 10+,Linux(主流发行版),macOS 10.15+
Project Type: 单体脚本项目,目录结构分明,支持后续扩展
Performance Goals: 单题判题<5秒,批量判题100题<3分钟,AI响应<30秒
Constraints: 需自动检测平台,所有路径/编码/换行符需兼容,判题过程需沙箱隔离,资源限制(内存/CPU/超时)
Scale/Scope: 支持1000+练习题,单题10+测试用例,支持多用户本地使用

Constitution Check
✅ 跨平台兼容性:所有脚本均需自动检测平台,适配命令/路径/编码
✅ 模块化架构:练习管理、判题引擎、AI服务、CLI界面均为独立模块
✅ 测试优先:所有核心功能需有单元/集成测试,CI自动验证
✅ 文件格式标准化:description.md、Test.txt、metadata.json等均有格式约定
✅ 沙箱与安全:判题过程隔离,资源限制,临时目录自动清理
✅ 可观测性:所有操作有结构化日志,错误信息清晰
✅ 渐进增强:AI辅助为可选模块,核心功能不依赖AI
✅ 目录结构与开发流程符合治理要求
无违宪项,所有GATE均通过。

Project Structure
Documentation (this feature)
Source Code (repository root)
Structure Decision: 采用单体脚本项目结构,所有核心功能按模块分目录,练习题支持后续动态添加,脚本自动检测并录入。

Complexity Tracking
无违宪项,无需复杂性说明。

下一步
进入 Phase 0: 技术调研与决策(research.md),并根据规范生成数据模型、接口约定等后续文档。所有实现均需兼容三大平台,练习题目录支持后续扩展与自动检测。

如需详细技术选型、脚本实现细节、接口设计等,请继续 /speckit.plan 后续流程。

命令/spec-kit.tasks

image-20251017152613843

在plan准备好后,我们可以使用/tasks来对工作进行拆分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Tasks: CStudy - Interactive C Programming Learning Platform

**Input**: Design documents from `/specs/001-cstudy-interactive-c/`
**Prerequisites**: plan.md (required), spec.md (required for user stories)

## Phase 1: Setup (Shared Infrastructure)

- [ ] T001 创建项目目录结构,包含 scripts/、Exercises/、Detection/、AIserver/、tests/,按实现计划分层(无依赖)
- [ ] T002 初始化 PowerShell/Bash 脚本项目,配置 UTF-8 编码和跨平台兼容(scripts/cstudy.ps1, scripts/cstudy.sh)
- [ ] T003 [P] 配置 GitHub Actions 跨平台 CI 测试(.github/workflows/ci.yml)

---

## Phase 2: Foundational (Blocking Prerequisites)

- [ ] T004 实现练习题自动检测与注册脚本(scripts/common/detect_exercises.ps1, scripts/common/detect_exercises.sh)
- [ ] T005 [P] 实现判题引擎基础模块(scripts/common/judge.ps1, scripts/common/judge.sh)
- [ ] T006 [P] 实现日志与错误处理基础模块(scripts/common/log.ps1, scripts/common/log.sh)
- [ ] T007 配置判题沙箱与资源限制(Detection/temp/, scripts/common/sandbox.ps1, scripts/common/sandbox.sh)
- [ ] T008 配置 exercises/ 目录下 description.md、Test.txt、metadata.json 文件格式校验脚本

---

## Phase 3: User Story 1 - 完成编程练习并获得即时反馈 (P1) 🎯 MVP

**Goal**: 学生可选择练习题,提交 C 代码,系统自动编译并判题,3 秒内反馈结果。
**Independent Test**: 创建简单练习题,用户提交代码,3 秒内显示编译与测试结果。

- [ ] T009 [P] [US1] 实现 exercises/ 目录的练习题列表与状态展示(scripts/common/list_exercises.ps1, .sh)
- [ ] T010 [US1] 实现单题编译与判题流程(scripts/common/judge.ps1, .sh)
- [ ] T011 [US1] 实现 CLI 主界面与命令(scripts/cstudy.ps1, .sh)
- [ ] T012 [US1] 实现编译/判题结果输出与错误提示(scripts/common/judge.ps1, .sh)
- [ ] T013 [US1] 实现进度统计与完成提示(scripts/common/list_exercises.ps1, .sh)

---

## Phase 4: User Story 2 - 批量验证所有练习 (P2)

**Goal**: 学生可一键批量检测所有练习,获得通过/失败/未完成统计。
**Independent Test**: 多练习题混合状态,批量检测后正确分类统计。

- [ ] T014 [P] [US2] 实现批量检测命令与流程(scripts/cstudy.ps1, .sh)
- [ ] T015 [US2] 实现批量检测结果统计与展示(scripts/common/list_exercises.ps1, .sh)
- [ ] T016 [US2] 支持超时终止与失败练习高亮(scripts/common/judge.ps1, .sh)
- [ ] T017 [US2] 支持点击/命令跳转到失败练习(scripts/cstudy.ps1, .sh)

---

## Phase 5: User Story 3 - AI 辅助编程 (P3)

**Goal**: 学生可请求 AI 分析当前代码,获得错误分析与修正建议。
**Independent Test**: 设置本地 AI,提交带典型错误的代码,30 秒内获得分析与建议。

- [ ] T018 [P] [US3] 实现 AI 辅助命令与参数收集(scripts/cstudy.ps1, .sh)
- [ ] T019 [US3] 实现与本地 ollama/AIserver 通信(AIserver/)
- [ ] T020 [US3] 实现 AI 响应解析与建议输出(scripts/common/ai_helper.ps1, .sh)
- [ ] T021 [US3] 支持自动应用 AI 建议并备份原代码(scripts/common/ai_helper.ps1, .sh)

---

## Phase 6: User Story 4 - AI 模型管理 (P4)

**Goal**: 用户可管理本地 AI 模型,支持列出、下载、切换、删除。
**Independent Test**: 执行模型管理命令,验证各操作成功并状态更新。

- [ ] T022 [P] [US4] 实现 AI 模型管理命令(scripts/cstudy.ps1, .sh)
- [ ] T023 [US4] 实现模型下载、切换、删除逻辑(AIserver/model/)
- [ ] T024 [US4] 实现依赖检测与安装引导(scripts/common/ai_helper.ps1, .sh)

---

## Phase 7: Polish & Cross-Cutting Concerns

- [ ] T025 [P] 完善文档与用例(specs/001-cstudy-interactive-c/quickstart.md, plan.md)
- [ ] T026 代码重构与性能优化(scripts/、common/)
- [ ] T027 [P] 增加单元/集成测试(tests/unit/, tests/integration/)
- [ ] T028 安全加固与沙箱验证(scripts/common/sandbox.ps1, .sh)
- [ ] T029 运行 quickstart.md 验证所有功能

---

## Dependencies & Execution Order

- Phase 1 → Phase 2 → Phase 3/4/5/6(用户故事可并行)→ Phase 7
- 各用户故事均可独立测试与交付,建议先完成 P1(MVP)

## Parallel Opportunities

- [P] 标记任务可并行(不同文件/无依赖)
- 用户故事可多团队成员并行开发
- 各阶段测试、文档、AI相关任务可并行

## Implementation Strategy

- 先完成 Phase 1/2 基础设施
- 以 User Story 1 为 MVP,独立测试后逐步扩展
- 后续每个用户故事均可独立增量交付
- 多人团队可按用户故事并行推进

通过这一步骤,代理会明确的知道他要去做什么而不是通过单纯的猜测,所以如果想通过测试驱动开发的方式来做,那你的首要任务就是写测试

我们要修改其中的内容时,可以通过模型让他帮你修改,或是直接在文档中手动修改。如此看来就没有问题了,接下来就可以让他开始这个项目了

image-20251017154307433

大概是这么个流程,但很可以最后的结果并没有达到我的要求,只得作罢回归面向结果拷打模型。

image-20251018014252716

不过好在经过调试,达到了我的预期效果(仅限pwsh)

image-20251018023009229

项目目前部署在Github,CStudy作为《C语言圣经》配套的练习系统,后续会在更新章节的时候同步更新