# Requirements Document

## Introduction

开发一个基于 Node.js + TypeScript 的命令行工具 `aitool`，用于快速初始化不同类型的工程项目。该工具支持版本查看、交互式项目初始化和规则文件同步功能，目前支持 uniapp 和 uniappx 两种工程模板。

## Glossary

- **CLI**: Command Line Interface，命令行界面
- **aitool**: 命令行工具的名称
- **Template**: 内置的工程模板，存放在 template 文件夹中
- **uniapp**: 一种跨平台应用开发框架的工程模板
- **uniappx**: uniapp 的扩展版本工程模板
- **Interactive_Prompt**: 交互式命令行提示，用于引导用户选择选项
- **Rules_File**: 规则文件，存放在 .cursor/rules 或 .kiro/steering 目录下的 .md 或 .mdc 文件
- **Project_Rules**: 当前工程目录下的规则文件
- **Template_Rules**: 模板目录下的规则文件

## Requirements

### Requirement 1: 版本查看

**User Story:** As a developer, I want to check the CLI tool version, so that I can verify the installed version and ensure compatibility.

#### Acceptance Criteria

1. WHEN a user executes `aitool -v` THEN THE CLI SHALL display the current version number
2. WHEN a user executes `aitool --version` THEN THE CLI SHALL display the current version number
3. THE CLI SHALL read the version from package.json file

### Requirement 2: 交互式项目初始化

**User Story:** As a developer, I want to initialize a new project through interactive prompts, so that I can quickly scaffold a project with the correct template.

#### Acceptance Criteria

1. WHEN a user executes `aitool init` THEN THE CLI SHALL display an interactive prompt asking the user to select a project template
2. WHEN displaying template options THEN THE CLI SHALL show at least "uniapp" and "uniappx" as available choices
3. WHEN a user selects a template THEN THE CLI SHALL copy the corresponding template files from the internal template folder to the current directory
4. WHEN template copying is complete THEN THE CLI SHALL display a success message to the user
5. IF the template folder does not exist THEN THE CLI SHALL display an appropriate error message

### Requirement 3: 模板管理

**User Story:** As a developer, I want the CLI to have built-in templates, so that I can initialize projects without additional downloads.

#### Acceptance Criteria

1. THE CLI SHALL include a `template` folder containing project templates
2. THE CLI SHALL support at least two template types: uniapp and uniappx
3. WHEN a new template type is added THEN THE CLI SHALL be extensible to support additional templates without major code changes

### Requirement 4: 命令行帮助

**User Story:** As a developer, I want to see help information, so that I can understand how to use the CLI tool.

#### Acceptance Criteria

1. WHEN a user executes `aitool` without arguments THEN THE CLI SHALL display help information
2. WHEN a user executes `aitool --help` or `aitool -h` THEN THE CLI SHALL display help information
3. THE CLI SHALL display available commands and their descriptions in the help output


### Requirement 5: 规则文件同步

**User Story:** As a developer, I want to sync rule files from templates to my project, so that I can keep my project's AI assistant rules up-to-date with the latest template configurations.

#### Acceptance Criteria

1. WHEN a user executes `aitool updateRules` THEN THE CLI SHALL display an interactive prompt asking the user to select a template type
2. WHEN a template is selected THEN THE CLI SHALL scan both `.cursor/rules` and `.kiro/steering` directories in the template and current project
3. WHEN a Rules_File exists in Template_Rules but not in Project_Rules THEN THE CLI SHALL copy the file to the project
4. WHEN a Rules_File exists in both Template_Rules and Project_Rules with the same filename THEN THE CLI SHALL compare content length
5. WHEN Template_Rules file content is longer than Project_Rules file content THEN THE CLI SHALL overwrite the project file with the template file
6. WHEN Template_Rules file content is equal to or shorter than Project_Rules file content THEN THE CLI SHALL keep the project file unchanged
7. WHEN rules sync is complete THEN THE CLI SHALL display a summary of added and updated files
8. IF the template does not contain any rules directories THEN THE CLI SHALL display an appropriate message
