Skip to content
Open
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
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,13 @@ CLAUDE.md
.DS_Store

# Pnpm
.pnpm-store/
.pnpm-store/

.trae/
.qoder/
chinese_translation_checklist.md
test-results.txt
translation_checklist_V2.md
translation_checklist.md
.trae/rules/project_rules.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Remove redundant ignore entry.

Line 160 (.trae/rules/project_rules.md) is already covered by line 154 (.trae/), which ignores all files under the .trae/ directory. The specific file entry is unnecessary.

-.trae/rules/project_rules.md
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.trae/rules/project_rules.md
🤖 Prompt for AI Agents
In .gitignore around line 160, remove the redundant entry
".trae/rules/project_rules.md" because the directory ignore ".trae/" on line 154
already covers it; simply delete line 160 (or collapse duplicate entries) and
commit the updated .gitignore.


22 changes: 22 additions & 0 deletions openspec/changes/add-trae-support/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 增加对 Trae IDE 的支持

## Why

Trae IDE 是一个新兴的 AI 驱动开发环境,需要与 OpenSpec 集成以支持规范驱动的开发工作流。目前 OpenSpec 支持多种 AI 工具(Claude、Cline、CodeBuddy 等),但缺少对 Trae IDE 的支持。

## What Changes

- 添加 `TraeConfigurator` 类,实现 `ToolConfigurator` 接口
- 在 `ToolRegistry` 中注册 Trae 配置器
- 支持在项目根目录的 `.trae/rules/project_rules.md` 文件中注入 OpenSpec 指令
- 遵循现有的配置器模式,使用 OPENSPEC 标记管理内容

## Impact

- affected specs: `cli-init` (初始化命令需要支持 Trae 选项)
- affected code:
- `src/core/configurators/trae.ts` (新文件)
- `src/core/configurators/registry.ts` (注册新配置器)
- 相关测试文件
- 向后兼容:不影响现有功能
- 用户体验:Trae IDE 用户可以通过 `openspec init` 自动配置项目规则
24 changes: 24 additions & 0 deletions openspec/changes/add-trae-support/specs/cli-init/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CLI Init 规范增量变更

## ADDED Requirements

### Requirement: Trae IDE 配置支持
系统 SHALL 支持为 Trae IDE 生成项目配置文件。

#### Scenario: 用户选择 Trae IDE 工具
- **WHEN** 用户在初始化过程中选择 Trae IDE 作为 AI 工具
- **THEN** 系统应在 `.trae/rules/project_rules.md` 文件中注入 OpenSpec 指令
- **AND** 使用 OPENSPEC 标记管理内容块
- **AND** 内容应包含项目特定的 OpenSpec 使用说明

#### Scenario: Trae 配置文件已存在
- **WHEN** 项目中已存在 `.trae/rules/project_rules.md` 文件
- **THEN** 系统应使用 OPENSPEC 标记更新现有文件
- **AND** 保留文件中的其他内容不变
- **AND** 仅更新 OPENSPEC 标记之间的内容

#### Scenario: Trae 目录不存在
- **WHEN** 项目中不存在 `.trae/rules/` 目录
- **THEN** 系统应自动创建必要的目录结构
- **AND** 创建 `project_rules.md` 文件
- **AND** 注入完整的 OpenSpec 配置内容
22 changes: 22 additions & 0 deletions openspec/changes/add-trae-support/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 实现任务

## 1. 核心实现
- [ ] 1.1 创建 `src/core/configurators/trae.ts` 文件
- [ ] 1.2 实现 `TraeConfigurator` 类,继承 `ToolConfigurator` 接口
- [ ] 1.3 配置目标文件路径为 `.trae/rules/project_rules.md`
- [ ] 1.4 使用 `TemplateManager.getAgentsStandardTemplate()` 获取模板内容

## 2. 注册集成
- [ ] 2.1 在 `src/core/configurators/registry.ts` 中导入 `TraeConfigurator`
- [ ] 2.2 在 `ToolRegistry` 静态块中注册 Trae 配置器
- [ ] 2.3 使用 'trae' 作为工具 ID

## 3. 测试验证
- [ ] 3.1 创建单元测试文件 `test/core/configurators/trae.test.ts`
- [ ] 3.2 测试配置器的基本功能
- [ ] 3.3 验证文件路径和内容生成
- [ ] 3.4 运行现有测试确保无回归

## 4. 文档更新
- [ ] 4.1 确认 CLI 初始化命令自动包含新的配置器
- [ ] 4.2 验证 `openspec init` 命令中 Trae 选项可用
Comment on lines +1 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Mark completed tasks as done.

All tasks listed in this file have been implemented:

  • Core implementation: TraeConfigurator class created in src/core/configurators/trae.ts
  • Registration: Configurator registered in src/core/configurators/registry.ts with 'trae' ID ✓
  • Testing: Unit tests in test/core/configurators/trae.test.ts and integration test in test/core/init.test.ts
  • Documentation: Trae option available in src/core/config.ts and spec documented ✓

As per coding guidelines, mark each completed item with - [x] once finished.

Apply this diff to mark all tasks as complete:

 # 实现任务
 
 ## 1. 核心实现
-- [ ] 1.1 创建 `src/core/configurators/trae.ts` 文件
-- [ ] 1.2 实现 `TraeConfigurator` 类,继承 `ToolConfigurator` 接口
-- [ ] 1.3 配置目标文件路径为 `.trae/rules/project_rules.md`
-- [ ] 1.4 使用 `TemplateManager.getAgentsStandardTemplate()` 获取模板内容
+- [x] 1.1 创建 `src/core/configurators/trae.ts` 文件
+- [x] 1.2 实现 `TraeConfigurator` 类,继承 `ToolConfigurator` 接口
+- [x] 1.3 配置目标文件路径为 `.trae/rules/project_rules.md`
+- [x] 1.4 使用 `TemplateManager.getAgentsStandardTemplate()` 获取模板内容
 
 ## 2. 注册集成
-- [ ] 2.1 在 `src/core/configurators/registry.ts` 中导入 `TraeConfigurator`
-- [ ] 2.2 在 `ToolRegistry` 静态块中注册 Trae 配置器
-- [ ] 2.3 使用 'trae' 作为工具 ID
+- [x] 2.1 在 `src/core/configurators/registry.ts` 中导入 `TraeConfigurator`
+- [x] 2.2 在 `ToolRegistry` 静态块中注册 Trae 配置器
+- [x] 2.3 使用 'trae' 作为工具 ID
 
 ## 3. 测试验证
-- [ ] 3.1 创建单元测试文件 `test/core/configurators/trae.test.ts`
-- [ ] 3.2 测试配置器的基本功能
-- [ ] 3.3 验证文件路径和内容生成
-- [ ] 3.4 运行现有测试确保无回归
+- [x] 3.1 创建单元测试文件 `test/core/configurators/trae.test.ts`
+- [x] 3.2 测试配置器的基本功能
+- [x] 3.3 验证文件路径和内容生成
+- [x] 3.4 运行现有测试确保无回归
 
 ## 4. 文档更新
-- [ ] 4.1 确认 CLI 初始化命令自动包含新的配置器
-- [ ] 4.2 验证 `openspec init` 命令中 Trae 选项可用
+- [x] 4.1 确认 CLI 初始化命令自动包含新的配置器
+- [x] 4.2 验证 `openspec init` 命令中 Trae 选项可用
🤖 Prompt for AI Agents
In openspec/changes/add-trae-support/tasks.md around lines 1 to 22, the review
says all checklist items are implemented but the file still shows unchecked
boxes; update each task checkbox to checked by replacing every "- [ ]" with "-
[x]" for items 1.1–4.2 so the file accurately reflects completion.

11 changes: 11 additions & 0 deletions openspec/changes/add-validation-json-output/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Why
Current validation output is designed for human consumption but lacks structured data that tools and scripts can easily parse. Adding JSON output support will enable better integration with CI/CD pipelines, IDE extensions, and automated tooling.

## What Changes
- Add a `--json` flag to the `openspec validate` command that outputs validation results in structured JSON format
- Update validation logic to include detailed error information, file paths, and line numbers in JSON output
- Document the JSON output format in the CLI documentation

## Impact
- Affected specs: `specs/cli-validate`
- Affected code: `src/commands/validate.ts`, `src/cli/index.ts`, documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## ADDED Requirements
### Requirement: JSON Output Flag
The validate command SHALL support a `--json` flag that outputs validation results in structured JSON format instead of human-readable text.

#### Scenario: Using JSON output flag
- **WHEN** a user runs `openspec validate --json`
- **THEN** the command SHALL output validation results in JSON format
- **AND** include detailed error information with file paths and line numbers
- **AND** exit with appropriate status codes (0 for success, 1 for validation errors)

### Requirement: JSON Output Format
The JSON output SHALL include structured information about validation results including change identifiers, validation status, error details, and file locations.

#### Scenario: JSON output structure
- **WHEN** validation is run with the `--json` flag
- **THEN** the output SHALL be a valid JSON object
- **AND** include fields for `valid`, `errors`, and `changeId`
- **AND** each error SHALL include `message`, `file`, and `line` information when applicable
Comment on lines +11 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

JSON schema mismatch between spec and implementation.

The spec requires JSON output with fields { valid, errors, changeId } and error objects with { message, file, line }. However, the implementation (validate.ts lines 150–152, 260–262) emits { items: [...], summary: {...}, version: '1.0' } with issues containing { level, path, message }.

Reconcile the spec to match the actual implementation, or update the implementation to match the spec.

Please verify which schema is canonical by checking:

  • Existing test expectations (test/commands/validate.test.ts lines 82–89)
  • Whether the implementation is intentional and the spec needs updating, or vice versa

If the implementation is correct, update the spec to reflect the actual items, summary, version structure and the level/path error fields.


🏁 Script executed:

#!/bin/bash
# Find and read the spec file
find . -name "spec.md" -path "*/add-validation-json-output/specs/cli-validate/*" 2>/dev/null | head -5

Length of output: 72


🏁 Script executed:

#!/bin/bash
# Find validate.ts and validator.ts files
find . -name "validate.ts" -o -name "validator.ts" 2>/dev/null | grep -v node_modules | head -10

Length of output: 61


🏁 Script executed:

#!/bin/bash
# Find test file for validate command
find . -path "*/test/commands/validate.test.ts" 2>/dev/null

Length of output: 32


🏁 Script executed:

#!/bin/bash
# Show directory structure to understand repository layout
ls -la

Length of output: 1877


🏁 Script executed:

#!/bin/bash
# Check for spec.md files anywhere under openspec/changes
find openspec/changes -name "spec.md" 2>/dev/null

Length of output: 5239


🏁 Script executed:

#!/bin/bash
# Look for src or lib directories with validate-related files
find . -type d -name "src" -o -type d -name "lib" 2>/dev/null | head -5

Length of output: 5


🏁 Script executed:

#!/bin/bash
# List all TypeScript files that contain "validate" in their name
find . -name "*validate*.ts" -type f 2>/dev/null | grep -v node_modules | head -20

Length of output: 268


🏁 Script executed:

#!/bin/bash
# List test files
find . -path "*/test/*" -name "*.test.ts" 2>/dev/null | head -10

Length of output: 392


🏁 Script executed:

#!/bin/bash
# Show the current directory contents
pwd
find . -maxdepth 2 -type d | head -20

Length of output: 251


🏁 Script executed:

#!/bin/bash
# Look for spec files more broadly
find . -name "*.md" -type f 2>/dev/null | grep -i spec | head -20

Length of output: 1267


🏁 Script executed:

#!/bin/bash
# Search for "JSON Output Format" in codebase
rg -l "JSON Output Format" --type md

Length of output: 70


🏁 Script executed:

#!/bin/bash
# Search for printReport function mentioned in review
rg -n "printReport" --type ts

Length of output: 356


🏁 Script executed:

#!/bin/bash
# Search for JSON output structure with items and summary
rg -n "items.*summary" --type ts | head -10

Length of output: 426


🏁 Script executed:

#!/bin/bash
# Look for test files related to validate command
rg -l "validate.*test\|test.*validate" --type ts | head -10

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Find all markdown files in openspec
find openspec -name "*.md" 2>/dev/null | head -20

Length of output: 1270


🏁 Script executed:

#!/bin/bash
# Show structure of openspec directory
find openspec -type f | head -30

Length of output: 2033


🏁 Script executed:

#!/bin/bash
# Get the spec file at the exact location mentioned
cat "openspec/changes/add-validation-json-output/specs/cli-validate/spec.md" 2>/dev/null || echo "File not found at specified path"

Length of output: 1435


🏁 Script executed:

#!/bin/bash
# Search for any files with "add-validation" in path
find . -path "*add-validation*" 2>/dev/null

Length of output: 348


🏁 Script executed:

#!/bin/bash
# Read validate.ts to see implementation of printReport
cat src/commands/validate.ts | head -300 | tail -200

Length of output: 8594


🏁 Script executed:

#!/bin/bash
# Get specific lines from validate.ts around printReport
sed -n '140,170p' src/commands/validate.ts

Length of output: 1524


🏁 Script executed:

#!/bin/bash
# Get lines 250-270 to see the multi-report output
sed -n '250,270p' src/commands/validate.ts

Length of output: 770


🏁 Script executed:

#!/bin/bash
# Read validator.ts to check issue structure
cat src/core/validation/validator.ts | head -200

Length of output: 8180


🏁 Script executed:

#!/bin/bash
# Look for the issue/ValidationIssue type definition
rg -n "interface.*Issue\|type.*Issue" --type ts -A 5

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Get the full printReport method
sed -n '149,165p' src/commands/validate.ts

Length of output: 1079


🏁 Script executed:

#!/bin/bash
# Check test file expectations around lines 82-89
sed -n '75,95p' test/commands/validate.test.ts

Length of output: 922


🏁 Script executed:

#!/bin/bash
# Look for JSON output tests
rg -n "\.json\|JSON" test/commands/validate.test.ts | head -20

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Check what tests expect from validate command
cat test/commands/validate.test.ts | head -150

Length of output: 5873


🏁 Script executed:

#!/bin/bash
# Search for test assertions about JSON structure
rg -n "items\|summary\|version" test/commands/validate.test.ts

Length of output: 0


Update spec to match the actual JSON output structure.

The implementation produces a different schema than the spec requires. Tests validate against the implementation, confirming it as canonical.

Spec requires: { valid, errors, changeId } with error fields { message, file, line }

Implementation outputs: { items: [...], summary: {...}, version: '1.0' } where each item has { id, type, valid, issues, durationMs } and each issue has { level, path, message }.

Update lines 11–18 to document the actual structure: top-level items array containing result objects with id, type, valid, and issues; include summary and version fields; specify issue fields as level, path, and message.

🤖 Prompt for AI Agents
In openspec/changes/add-validation-json-output/specs/cli-validate/spec.md around
lines 11 to 18, the spec's JSON schema is out of date; replace the required
top-level fields `{ valid, errors, changeId }` and error shape `{ message, file,
line }` with the actual implementation schema: document a top-level "items"
array of result objects (each with id, type, valid, issues, durationMs), a
top-level "summary" object and a "version" field, and describe each issue object
as having "level", "path", and "message"; keep the WHEN/THEN scenario language
but update the expected fields to match the implementation.


### Requirement: Backward Compatibility
The validate command SHALL maintain backward compatibility, with JSON output only enabled when the `--json` flag is explicitly provided.

#### Scenario: Backward compatibility
- **WHEN** a user runs `openspec validate` without flags
- **THEN** the command SHALL output results in the existing human-readable format
- **AND** behavior SHALL be identical to current implementation
13 changes: 13 additions & 0 deletions openspec/changes/add-validation-json-output/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 1. CLI Implementation
- [ ] 1.1 Add `--json` flag to the validate command in `src/cli/index.ts`
- [ ] 1.2 Modify validation logic in `src/commands/validate.ts` to support JSON output format
- [ ] 1.3 Implement JSON output structure with detailed error information

## 2. Documentation
- [ ] 2.1 Update CLI documentation to include `--json` flag usage
- [ ] 2.2 Document the JSON output format schema

## 3. Testing
- [ ] 3.1 Add unit tests for JSON output functionality
- [ ] 3.2 Add integration tests to ensure JSON output is valid and parseable
- [ ] 3.3 Test backward compatibility with existing validation output
Loading
Loading