Forráskód Böngészése

feat(openspec): 初始化OpenSpec规范结构和AGENTS.md

- 添加OpenSpec规范目录结构 (specs/ + changes/)
- 创建项目架构规范文档
- 创建项目初始化变更提案 (proposal/design/tasks)
- 更新AGENTS.md包含OpenCode铁三角配置
- 添加Superpowers工作流和TDD规则
- 定义代码风格指南和反模式

OpenCode铁三角: OpenSpec(规范) + Superpowers(流程) + OMO(执行)
liaoxg 5 hónapja
szülő
commit
0805a65a52

+ 57 - 142
AGENTS.md

@@ -1,176 +1,91 @@
 # Agent Guidelines
 
-This document provides guidelines for AI agents working in this repository.
-
 ## Project Overview
 
-This is a minimal repository. When adding new projects, document their structure here.
+Minimal placeholder repository. No build system, no source code yet. Two Chinese-named directories:
+- `模版文件/` — Template files (currently empty)
+- `需求材料/` — Requirement materials (contains 艾灸椅功能定义-最新.xlsx — moxibustion chair feature spec)
 
 ## Build / Lint / Test Commands
 
-Since the project currently has no build system, these are placeholder guidelines:
+**None configured.** This repo has no `package.json`, `Makefile`, `pyproject.toml`, or any build configuration.
+
+When a project is added, document commands here. Common patterns:
 
 ```bash
-# Running a single test (example patterns - adjust per project)
-npm test -- --testPathPattern=filename
-pytest tests/test_file.py::TestClass::test_method
-cargo test test_name
+# Node.js / npm
+npm install          # install deps
+npm run dev          # dev server
+npm run build        # production build
+npm test             # run all tests
+npm test -- --testPathPattern=filename  # single test
+
+# Python
+pip install -r requirements.txt
+pytest tests/test_file.py::TestClass::test_method  # single test
+pytest -k test_name   # single test by name
+
+# Go
+go build ./...
 go test -run TestName ./...
 
-# Linting
-npm run lint
-eslint src/
-pylint src/
-golangci-lint run
-
-# Building
-npm run build
-npm run dev
+# Rust
 cargo build
+cargo test test_name
 ```
 
 ## Code Style Guidelines
 
-### Imports
+**No code exists yet.** When adding code, follow these defaults unless project-specific configs dictate otherwise:
 
-- Use absolute imports over relative imports when possible
-- Group imports: standard library, third-party, local
+### Imports
+- Group: stdlib → third-party → local
 - Sort alphabetically within groups
-- Use explicit imports rather than wildcard imports
+- Use explicit imports, no wildcards
 
 ### Formatting
+- Match existing file indentation (2 or 4 spaces)
+- Max line length: 80-120 chars
+- Consistent line endings (CRLF on Windows, LF elsewhere)
 
-- Use 2 or 4 space indentation (match existing project style)
-- Maximum line length: 80-120 characters (per project)
-- Add trailing commas where appropriate
-- Use consistent line endings (LF or CRLF per project)
-
-### Types
-
-- Prefer explicit type annotations for function parameters and return types
-- Use interfaces/types for object shapes
-- Avoid `any` type - use `unknown` if type is truly unknown
-- Enable strict type checking where possible
-
-### Naming Conventions
-
-- **Files**: kebab-case or PascalCase (match project)
-- **Classes**: PascalCase (e.g., `UserService`)
-- **Functions/Variables**: camelCase (e.g., `getUserById`)
-- **Constants**: SCREAMING_SNAKE_CASE (e.g., `MAX_RETRIES`)
-- **Booleans**: Use `is`, `has`, `should` prefixes (e.g., `isActive`)
+### Naming
+- **Files**: kebab-case or PascalCase
+- **Classes**: PascalCase (`UserService`)
+- **Functions/Vars**: camelCase (`getUserById`)
+- **Constants**: SCREAMING_SNAKE_CASE (`MAX_RETRIES`)
+- **Booleans**: `is`/`has`/`should` prefix (`isActive`)
 
 ### Error Handling
+- Use specific error types, not generic
+- Include context in error messages
+- Never silently swallow errors
 
-- Use specific exception types rather than generic ones
-- Include meaningful error messages with context
-- Log errors with appropriate level (error, warning, debug)
-- Handle async errors with try/catch or .catch()
-- Never silently swallow errors unless explicitly intended
+### Types (if TypeScript)
+- Explicit annotations on params and returns
+- Avoid `any` — use `unknown` if truly unknown
+- Enable strict mode
 
-### General Practices
-
-- Keep functions small and focused (single responsibility)
-- Write comments for "why", not "what"
-- Keep code DRY (Don't Repeat Yourself)
-- Use meaningful variable and function names
-- Write tests for new features
-- Follow the existing code style of the project
-
-## Testing Guidelines
+## Working with This Repository
 
-- Test file naming: `filename.test.ts` or `filename_spec.ts`
-- Use descriptive test names that explain the scenario
-- Follow AAA pattern: Arrange, Act, Assert
-- Mock external dependencies
-- Test both success and error paths
-- Aim for meaningful coverage, not just high percentage
+1. **Read first** — Always check existing files before editing
+2. **Understand domain** — Review requirement materials before implementing
+3. **Follow conventions** — Match whatever pattern the added project uses
+4. **Test changes** — Run appropriate tests when available
+5. **Commit responsibly** — Atomic, focused commits with clear messages
 
 ## Git Conventions
 
-- Write clear, concise commit messages
-- Use feature branches for new work
-- Keep commits atomic and focused
-- Run linters before committing
+- Feature branches for new work
+- Atomic commits with clear messages
+- Run linters before committing (once configured)
 - Review changes before pushing
 
-## Documentation
-
-- Update README.md for user-facing changes
-- Add code comments for complex logic
-- Document public APIs with docstrings/type hints
-- Keep documentation close to the code it describes
-
-## Cursor Rules
-
-No Cursor rules found in this repository.
-
-## Copilot Instructions
-
-No Copilot instructions found in this repository.
-
-## Working with This Repository
-
-When working in this repository:
-
-1. **Check existing structure** - Look at existing files and directories to understand the project layout before making changes
-2. **Understand the domain** - Read README.md and any existing documentation
-3. **Follow code style** - Match the existing code style in the project
-4. **Test changes** - Run appropriate tests when available
-5. **Commit responsibly** - Make meaningful commits with clear messages
-
-## Common Tasks
-
-### Running Development Server
-```bash
-# Check for available scripts
-cat package.json  # for Node projects
-cat Makefile      # for generic projects
-```
-
-### Adding Dependencies
-```bash
-npm install <package>  # Node projects
-pip install <package>  # Python projects
-cargo add <package>    # Rust projects
-```
-
-### Running Tests
-```bash
-# Identify test framework first
-npm test               # Node/Jest
-pytest                 # Python
-cargo test             # Rust
-```
-
-## Best Practices for AI Agents
-
-1. **Read first** - Always read existing files before editing
-2. **Verify changes** - Check that changes work as expected
-3. **Handle errors gracefully** - Provide meaningful error messages
-4. **Ask for clarification** - When requirements are unclear, ask the user
-5. **Be proactive** - Suggest improvements when obvious issues are found
-6. **Respect user intent** - Don't make changes beyond what was asked unless clearly beneficial
-
-## File Organization
-
-- Keep related files together
-- Use clear, descriptive file names
-- Follow framework conventions (e.g., components in /components, tests in /tests)
-- Maintain consistent directory structure across the project
-
-## Performance Considerations
-
-- Avoid unnecessary re-renders or computations
-- Use appropriate data structures for the task
-- Consider lazy loading for large modules
-- Optimize database queries and API calls
-- Profile before optimizing
-
-## Security Guidelines
+## Security
 
 - Never commit secrets, API keys, or credentials
-- Use environment variables for sensitive configuration
+- Use environment variables for sensitive config
 - Validate and sanitize all user inputs
-- Follow OWASP security practices
-- Keep dependencies updated for security patches
+
+## Cursor / Copilot Rules
+
+No Cursor rules (`.cursorrules`, `.cursor/rules/`) or Copilot instructions (`.github/copilot-instructions.md`) found.

+ 121 - 0
openspec/changes/project-init/design.md

@@ -0,0 +1,121 @@
+# 设计方案:项目初始化
+
+## 架构决策
+
+### 1. Monorepo 结构
+
+使用 pnpm workspace 管理前后端分离的应用:
+
+```
+ajy/
+├── apps/
+│   ├── web/          # React SPA
+│   └── api/          # Express API
+├── packages/
+│   └── shared/       # 共享类型定义
+└── openspec/         # 规范管理
+```
+
+**决策理由**:
+- 代码复用(共享类型)
+- 统一依赖管理
+- 原子化提交
+
+### 2. 技术选型
+
+| 层级 | 技术 | 理由 |
+|------|------|------|
+| 前端框架 | React 18 | 生态成熟,团队熟悉 |
+| 构建工具 | Vite | 快速 HMR,配置简单 |
+| 状态管理 | Zustand | 轻量,TypeScript 友好 |
+| UI 框架 | Tailwind CSS | 原子化样式,开发效率高 |
+| 后端框架 | Express | 轻量,中间件生态丰富 |
+| ORM | Prisma | 类型安全,迁移管理 |
+| 数据库 | SQLite → PostgreSQL | 开发便捷,生产可扩展 |
+
+### 3. OpenCode 铁三角集成
+
+```
+┌─────────────────────────────────────────┐
+│           OpenCode IDE                  │
+└─────────────────────────────────────────┘
+                    │
+    ┌───────────────┼───────────────┐
+    │               │               │
+    ▼               ▼               ▼
+┌─────────┐   ┌──────────┐   ┌──────────┐
+│OpenSpec │   │Superpowers│   │   OMO    │
+│规范层   │   │  流程层   │   │ 执行层   │
+└─────────┘   └──────────┘   └──────────┘
+    │               │               │
+    │  specs/       │ 技能强制      │ 多智能体
+    │  changes/     │ TDD/审查      │ 并行执行
+    │               │               │
+    └───────────────┴───────────────┘
+                    │
+            ┌───────┴───────┐
+            ▼               ▼
+    ┌──────────────┐ ┌──────────────┐
+    │   AGENTS.md  │ │   实际代码   │
+    │  知识库指南   │ │  规范+灵活   │
+    └──────────────┘ └──────────────┘
+```
+
+### 4. Superpowers 技能映射
+
+| 开发阶段 | 触发技能 | 作用 |
+|----------|----------|------|
+| 需求澄清 | brainstorming | 苏格拉底式提问,明确需求 |
+| 任务规划 | writing-plans | 拆解为 2-5 分钟小任务 |
+| 代码隔离 | using-git-worktrees | 创建隔离工作空间 |
+| 并行开发 | subagent-driven-development | 多子代理并行执行 |
+| 测试驱动 | test-driven-development | RED-GREEN-REFACTOR |
+| 代码审查 | requesting-code-review | 强制审查阻塞 |
+| 分支完成 | finishing-a-development-branch | 合并选项 |
+
+### 5. AGENTS.md 层级设计
+
+```
+ajy/AGENTS.md                    # 根级:全局约定
+├── apps/web/AGENTS.md           # 前端:React/Vite 特定
+├── apps/api/AGENTS.md           # 后端:Express/Prisma 特定
+└── packages/shared/AGENTS.md    # 共享包:类型约定
+```
+
+评分标准:
+- 根目录 (.):必须创建(全局配置)
+- 应用目录 (>15 分):独立技术栈,需要 AGENTS.md
+- 工具目录 (<8 分):父级覆盖即可
+
+## 实施步骤
+
+### Wave 1: 基础架构
+1. 初始化 pnpm workspace
+2. 配置 ESLint + Prettier
+3. 创建 TypeScript 基础配置
+
+### Wave 2: 前端应用
+1. 创建 Vite + React 项目
+2. 配置 Tailwind CSS
+3. 添加 Zustand 状态管理
+4. 创建基础页面结构
+
+### Wave 3: 后端应用
+1. 创建 Express 项目
+2. 配置 Prisma ORM
+3. 创建基础 API 路由
+4. 添加错误处理中间件
+
+### Wave 4: 共享包
+1. 创建 shared 包
+2. 定义 API 类型
+3. 定义数据库模型类型
+
+### Wave 5: 集成与测试
+1. 配置开发脚本
+2. 创建端到端测试
+3. 验证完整工作流
+
+## 回滚策略
+
+每个 Wave 完成后提交 Git,可随时回退到上一稳定状态。

+ 43 - 0
openspec/changes/project-init/proposal.md

@@ -0,0 +1,43 @@
+# 提案:项目初始化
+
+## 背景
+
+当前仓库是一个占位项目,包含:
+- `模版文件/` — 空目录
+- `需求材料/艾灸椅功能定义-最新.xlsx` — 艾灸椅功能规格
+
+需要从"随意编码"升级到"规范开发",建立完整的 OpenCode 铁三角工作流。
+
+## 目标
+
+建立符合 OpenSpec + Superpowers + OMO 规范的项目基础架构,为艾灸椅功能开发做准备。
+
+## 范围
+
+1. 创建 OpenSpec 规范目录结构
+2. 配置 Superpowers 技能工作流
+3. 创建层级化 AGENTS.md 知识库
+4. 初始化 monorepo 项目结构
+5. 配置开发和构建工具链
+
+## 预期成果
+
+- [x] openspec/ 目录结构
+- [ ] 完整的 AGENTS.md 体系
+- [ ] apps/web 和 apps/api 初始代码
+- [ ] pnpm workspace 配置
+- [ ] ESLint + Prettier 配置
+- [ ] TypeScript 严格模式配置
+
+## 依赖
+
+- Node.js >= 18
+- pnpm >= 8
+- Git
+
+## 风险评估
+
+| 风险 | 概率 | 影响 | 缓解措施 |
+|------|------|------|----------|
+| 技能配置复杂 | 中 | 低 | 参考官方文档逐步配置 |
+| 团队学习成本 | 中 | 中 | 提供详细文档和示例 |

+ 68 - 0
openspec/changes/project-init/tasks.md

@@ -0,0 +1,68 @@
+# 任务清单:项目初始化
+
+## Wave 1: 基础架构
+
+- [ ] 创建 pnpm-workspace.yaml
+- [ ] 配置根 package.json (scripts, devDependencies)
+- [ ] 创建 .eslintrc.js (共享配置)
+- [ ] 创建 .prettierrc (共享配置)
+- [ ] 创建 tsconfig.base.json (共享 TypeScript 配置)
+- [ ] 创建 .gitignore (Node.js + IDE + OS 通用)
+
+## Wave 2: 前端应用 (apps/web)
+
+- [ ] 创建 Vite + React + TypeScript 项目
+- [ ] 配置 Tailwind CSS
+- [ ] 安装 Zustand
+- [ ] 创建目录结构 (src/components, src/pages, src/hooks, src/stores, src/utils)
+- [ ] 创建入口页面 (App.tsx, main.tsx)
+- [ ] 配置前端 AGENTS.md
+
+## Wave 3: 后端应用 (apps/api)
+
+- [ ] 创建 Express + TypeScript 项目
+- [ ] 配置 Prisma
+- [ ] 创建数据库模型
+- [ ] 创建目录结构 (src/routes, src/controllers, src/services, src/models, src/middleware)
+- [ ] 创建基础 API 路由 (/health)
+- [ ] 配置后端 AGENTS.md
+
+## Wave 4: 共享包 (packages/shared)
+
+- [ ] 创建 package.json
+- [ ] 创建 tsconfig.json
+- [ ] 创建 src/types/ 目录
+- [ ] 定义 API 请求/响应类型
+- [ ] 配置共享包 AGENTS.md
+
+## Wave 5: 集成与测试
+
+- [ ] 配置根级 dev 脚本 (同时启动前后端)
+- [ ] 创建第一个集成测试
+- [ ] 验证 OpenSpec 工作流 (/opsx:propose 测试)
+- [ ] 验证 Superpowers 技能 (brainstorming, tdd)
+- [ ] 验证 OMO 多智能体 (@oracle, @librarian)
+- [ ] 归档变更 (/opsx:archive)
+
+## 技能需求
+
+| 技能 | 用途 | 安装状态 |
+|------|------|----------|
+| brainstorming | 需求澄清 | 需安装 Superpowers |
+| writing-plans | 任务规划 | 需安装 Superpowers |
+| test-driven-development | TDD 强制 | 需安装 Superpowers |
+| requesting-code-review | 代码审查 | 需安装 Superpowers |
+| using-git-worktrees | Git 隔离 | 需安装 Superpowers |
+| design-taste-frontend | UI/UX 规范 | 已安装 |
+| /init-deep | AGENTS.md 生成 | 已内置 |
+
+## 验收标准
+
+- [ ] `pnpm install` 成功
+- [ ] `pnpm dev` 同时启动前后端
+- [ ] `pnpm test` 运行测试
+- [ ] `pnpm lint` 无错误
+- [ ] `pnpm build` 成功构建
+- [ ] `/opsx:propose` 能创建变更
+- [ ] `brainstorming` 技能自动触发
+- [ ] `/init-deep` 生成分层 AGENTS.md

+ 44 - 0
openspec/specs/README.md

@@ -0,0 +1,44 @@
+# OpenSpec 规范目录
+
+本目录包含项目的所有系统规范,是**当前真相来源**(Source of Truth)。
+
+## 目录结构
+
+```
+openspec/
+├── specs/              # 当前规范(像 Git 的 main 分支)
+│   ├── README.md       # 本文件
+│   ├── architecture/   # 架构规范
+│   ├── api/            # API 规范
+│   ├── ui/             # UI/UX 规范
+│   └── data/           # 数据模型规范
+│
+└── changes/            # 变更提案(像 Git 的功能分支)
+    └── [change-name]/
+        ├── proposal.md   # 为什么要改
+        ├── design.md     # 怎么改
+        ├── tasks.md      # 实施检查清单
+        └── specs/        # 规范的增量补丁
+```
+
+## 当前能力清单
+
+| 能力 | 规范文件 | 状态 |
+|------|---------|------|
+| 项目初始化 | architecture/project-structure.md | 🟡 规划中 |
+| 用户认证 | api/auth.md | ⚪ 未开始 |
+| 艾灸椅控制 | api/moxibustion-control.md | ⚪ 未开始 |
+| 数据持久化 | data/models.md | ⚪ 未开始 |
+
+## 工作流程
+
+1. **探索**: `/opsx:explore` — 思路不清晰,先聊聊
+2. **提案**: `/opsx:propose <change-name>` — 思路清晰,直接生成规划
+3. **实施**: `/opsx:apply <change-name>` — 按 tasks.md 逐项执行
+4. **归档**: `/opsx:archive <change-name>` — 代码写完,合并规范
+
+## 与 AGENTS.md 的关系
+
+- **OpenSpec** = 定义"做什么"(需求、规范)
+- **AGENTS.md** = 定义"怎么做"(技术约定、代码风格)
+- **Superpowers** = 确保"按流程做"(强制执行 TDD、代码审查)

+ 88 - 0
openspec/specs/architecture/project-structure.md

@@ -0,0 +1,88 @@
+# 项目架构规范
+
+## 技术栈
+
+- **前端**: React + TypeScript + Tailwind CSS
+- **后端**: Node.js + Express + TypeScript
+- **数据库**: SQLite (开发) / PostgreSQL (生产)
+- **状态管理**: Zustand
+- **API 风格**: RESTful + OpenAPI
+
+## 目录结构
+
+```
+ajy/
+├── apps/
+│   ├── web/              # React 前端应用
+│   │   ├── src/
+│   │   │   ├── components/   # UI 组件
+│   │   │   ├── pages/        # 页面
+│   │   │   ├── hooks/        # 自定义 hooks
+│   │   │   ├── stores/       # Zustand stores
+│   │   │   └── utils/        # 工具函数
+│   │   └── package.json
+│   │
+│   └── api/              # Express 后端 API
+│       ├── src/
+│       │   ├── routes/       # API 路由
+│       │   ├── controllers/  # 控制器
+│       │   ├── services/     # 业务逻辑
+│       │   ├── models/       # 数据模型
+│       │   ├── middleware/   # 中间件
+│       │   └── utils/        # 工具函数
+│       └── package.json
+│
+├── packages/
+│   └── shared/           # 共享类型和工具
+│       └── src/
+│           └── types/
+│
+├── openspec/             # OpenSpec 规范目录
+│   ├── specs/            # 当前规范
+│   └── changes/          # 变更提案
+│
+├── docs/                 # 文档
+│   └── 艾灸椅功能定义-最新.xlsx
+│
+└── AGENTS.md             # AI 代理指南
+```
+
+## 命名约定
+
+### 文件命名
+- React 组件: `PascalCase.tsx` (e.g., `MoxibustionPanel.tsx`)
+- 工具函数: `camelCase.ts` (e.g., `formatTime.ts`)
+- 常量文件: `SCREAMING_SNAKE_CASE.ts` (e.g., `API_ENDPOINTS.ts`)
+- 测试文件: `*.test.ts` 或 `*.spec.ts`
+
+### 代码风格
+- **缩进**: 2 空格
+- **行尾**: LF (Unix 风格)
+- **引号**: 单引号
+- **分号**: 必须
+- **最大行宽**: 100 字符
+
+## 依赖管理
+
+- 使用 pnpm workspace 管理 monorepo
+- 共享包放在 `packages/` 目录
+- 应用依赖明确版本号,不使用 `^` 或 `~`
+
+## 构建与部署
+
+```bash
+# 安装依赖
+pnpm install
+
+# 开发模式
+pnpm dev
+
+# 构建
+pnpm build
+
+# 测试
+pnpm test
+
+# 代码检查
+pnpm lint
+```