From b02175271a3fbb95bfa0c7efbf68745b10d68729 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 29 Jan 2026 13:18:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=8E=88=E6=9D=83=E5=8A=9F=E8=83=BD=E5=B9=B6?= =?UTF-8?q?=E5=BD=92=E6=A1=A3=20OpenSpec=20=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增企业设备授权模块(Model、DTO、Service、Handler、Store) - 实现设备授权的创建、查询、更新、删除等完整业务逻辑 - 添加企业卡授权与设备授权的关联关系 - 新增 2 个数据库迁移脚本 - 同步 OpenSpec delta specs 到 main specs - 归档 add-enterprise-device-authorization 变更 - 更新 API 文档和路由配置 - 新增完整的集成测试和单元测试覆盖 --- .claude/commands/opsx/continue.md | 2 +- .claude/skills/openspec-apply-change/SKILL.md | 2 +- .../skills/openspec-archive-change/SKILL.md | 2 +- .../openspec-bulk-archive-change/SKILL.md | 2 +- .../skills/openspec-continue-change/SKILL.md | 4 +- .claude/skills/openspec-explore/SKILL.md | 2 +- .claude/skills/openspec-ff-change/SKILL.md | 2 +- .claude/skills/openspec-new-change/SKILL.md | 2 +- .claude/skills/openspec-onboard/SKILL.md | 2 +- .claude/skills/openspec-sync-specs/SKILL.md | 2 +- .../skills/openspec-verify-change/SKILL.md | 2 +- .codex/prompts/opsx-apply.md | 150 +++ .codex/prompts/opsx-archive.md | 155 +++ .codex/prompts/opsx-bulk-archive.md | 240 +++++ .codex/prompts/opsx-continue.md | 112 +++ .codex/prompts/opsx-explore.md | 172 ++++ .codex/prompts/opsx-ff.md | 92 ++ .codex/prompts/opsx-new.md | 67 ++ .codex/prompts/opsx-onboard.md | 523 ++++++++++ .codex/prompts/opsx-sync.md | 132 +++ .codex/prompts/opsx-verify.md | 162 ++++ .codex/skills/openspec-apply-change/SKILL.md | 156 +++ .../skills/openspec-archive-change/SKILL.md | 114 +++ .../openspec-bulk-archive-change/SKILL.md | 246 +++++ .../skills/openspec-continue-change/SKILL.md | 118 +++ .codex/skills/openspec-explore/SKILL.md | 290 ++++++ .codex/skills/openspec-ff-change/SKILL.md | 101 ++ .codex/skills/openspec-new-change/SKILL.md | 74 ++ .codex/skills/openspec-onboard/SKILL.md | 529 ++++++++++ .codex/skills/openspec-sync-specs/SKILL.md | 138 +++ .codex/skills/openspec-verify-change/SKILL.md | 168 ++++ .opencode/command/opsx-apply.md | 149 +++ .opencode/command/opsx-archive.md | 154 +++ .opencode/command/opsx-bulk-archive.md | 239 +++++ .opencode/command/opsx-continue.md | 111 +++ .opencode/command/opsx-explore.md | 171 ++++ .opencode/command/opsx-ff.md | 91 ++ .opencode/command/opsx-new.md | 66 ++ .opencode/command/opsx-onboard.md | 522 ++++++++++ .opencode/command/opsx-sync.md | 131 +++ .opencode/command/opsx-verify.md | 161 +++ .../skills/openspec-apply-change/SKILL.md | 156 +++ .../skills/openspec-archive-change/SKILL.md | 114 +++ .../openspec-bulk-archive-change/SKILL.md | 246 +++++ .../skills/openspec-continue-change/SKILL.md | 118 +++ .opencode/skills/openspec-explore/SKILL.md | 290 ++++++ .opencode/skills/openspec-ff-change/SKILL.md | 101 ++ .opencode/skills/openspec-new-change/SKILL.md | 74 ++ .opencode/skills/openspec-onboard/SKILL.md | 529 ++++++++++ .opencode/skills/openspec-sync-specs/SKILL.md | 138 +++ .../skills/openspec-verify-change/SKILL.md | 168 ++++ cmd/api/docs.go | 4 +- cmd/gendocs/main.go | 4 +- docs/admin-openapi.yaml | 882 ++++++++++++++++- .../implementation-summary.md | 224 +++++ internal/bootstrap/handlers.go | 4 +- internal/bootstrap/services.go | 3 + internal/bootstrap/stores.go | 2 + internal/bootstrap/types.go | 2 + internal/handler/admin/enterprise_device.go | 80 ++ internal/handler/admin/role.go | 27 +- internal/handler/h5/enterprise_device.go | 107 ++ .../dto/enterprise_card_authorization_dto.go | 31 +- .../enterprise_device_authorization_dto.go | 103 ++ .../model/enterprise_card_authorization.go | 1 + .../model/enterprise_device_authorization.go | 26 + internal/routes/admin.go | 3 + internal/routes/enterprise_device.go | 38 + internal/routes/h5.go | 3 + internal/routes/h5_enterprise_device.go | 46 + .../authorization_service_test.go | 161 +++ internal/service/enterprise_card/service.go | 117 +-- internal/service/enterprise_device/service.go | 621 ++++++++++++ .../service/enterprise_device/service_test.go | 916 ++++++++++++++++++ .../enterprise_card_authorization_store.go | 10 + ...nterprise_card_authorization_store_test.go | 309 ++++++ .../enterprise_device_authorization_store.go | 160 +++ ...erprise_device_authorization_store_test.go | 517 ++++++++++ ...d_enterprise_device_authorization.down.sql | 3 + ...add_enterprise_device_authorization.up.sql | 48 + ..._to_enterprise_card_authorization.down.sql | 4 + ...id_to_enterprise_card_authorization.up.sql | 14 + .../.openspec.yaml | 2 + .../design.md | 181 ++++ .../proposal.md | 53 + .../enterprise-card-authorization/spec.md | 132 +++ .../enterprise-device-authorization/spec.md | 319 ++++++ .../tasks.md | 163 ++++ .../.openspec.yaml | 2 + .../design.md | 99 ++ .../proposal.md | 27 + .../specs/role-request-validation/spec.md | 67 ++ .../tasks.md | 30 + .../.openspec.yaml | 3 + .../design.md | 48 + .../proposal.md | 25 + .../tasks.md | 18 + .../.openspec.yaml | 3 + .../design.md | 39 + .../proposal.md | 25 + .../tasks.md | 24 + .../.openspec.yaml | 3 + .../design.md | 61 ++ .../proposal.md | 30 + .../tasks.md | 24 + .../.openspec.yaml | 3 + .../design.md | 40 + .../proposal.md | 23 + .../fix-order-activation-idempotency/tasks.md | 22 + openspec/config.yaml | 81 ++ openspec/project.md | 200 ---- .../enterprise-card-authorization/spec.md | 140 +-- .../enterprise-device-authorization/spec.md | 319 ++++++ pkg/errors/codes.go | 12 + .../integration/enterprise_device_h5_test.go | 322 ++++++ tests/integration/enterprise_device_test.go | 249 +++++ tests/integration/role_test.go | 26 +- tests/testutils/db.go | 1 + 118 files changed, 14306 insertions(+), 472 deletions(-) create mode 100644 .codex/prompts/opsx-apply.md create mode 100644 .codex/prompts/opsx-archive.md create mode 100644 .codex/prompts/opsx-bulk-archive.md create mode 100644 .codex/prompts/opsx-continue.md create mode 100644 .codex/prompts/opsx-explore.md create mode 100644 .codex/prompts/opsx-ff.md create mode 100644 .codex/prompts/opsx-new.md create mode 100644 .codex/prompts/opsx-onboard.md create mode 100644 .codex/prompts/opsx-sync.md create mode 100644 .codex/prompts/opsx-verify.md create mode 100644 .codex/skills/openspec-apply-change/SKILL.md create mode 100644 .codex/skills/openspec-archive-change/SKILL.md create mode 100644 .codex/skills/openspec-bulk-archive-change/SKILL.md create mode 100644 .codex/skills/openspec-continue-change/SKILL.md create mode 100644 .codex/skills/openspec-explore/SKILL.md create mode 100644 .codex/skills/openspec-ff-change/SKILL.md create mode 100644 .codex/skills/openspec-new-change/SKILL.md create mode 100644 .codex/skills/openspec-onboard/SKILL.md create mode 100644 .codex/skills/openspec-sync-specs/SKILL.md create mode 100644 .codex/skills/openspec-verify-change/SKILL.md create mode 100644 .opencode/command/opsx-apply.md create mode 100644 .opencode/command/opsx-archive.md create mode 100644 .opencode/command/opsx-bulk-archive.md create mode 100644 .opencode/command/opsx-continue.md create mode 100644 .opencode/command/opsx-explore.md create mode 100644 .opencode/command/opsx-ff.md create mode 100644 .opencode/command/opsx-new.md create mode 100644 .opencode/command/opsx-onboard.md create mode 100644 .opencode/command/opsx-sync.md create mode 100644 .opencode/command/opsx-verify.md create mode 100644 .opencode/skills/openspec-apply-change/SKILL.md create mode 100644 .opencode/skills/openspec-archive-change/SKILL.md create mode 100644 .opencode/skills/openspec-bulk-archive-change/SKILL.md create mode 100644 .opencode/skills/openspec-continue-change/SKILL.md create mode 100644 .opencode/skills/openspec-explore/SKILL.md create mode 100644 .opencode/skills/openspec-ff-change/SKILL.md create mode 100644 .opencode/skills/openspec-new-change/SKILL.md create mode 100644 .opencode/skills/openspec-onboard/SKILL.md create mode 100644 .opencode/skills/openspec-sync-specs/SKILL.md create mode 100644 .opencode/skills/openspec-verify-change/SKILL.md create mode 100644 docs/enterprise-device-authorization/implementation-summary.md create mode 100644 internal/handler/admin/enterprise_device.go create mode 100644 internal/handler/h5/enterprise_device.go create mode 100644 internal/model/dto/enterprise_device_authorization_dto.go create mode 100644 internal/model/enterprise_device_authorization.go create mode 100644 internal/routes/enterprise_device.go create mode 100644 internal/routes/h5_enterprise_device.go create mode 100644 internal/service/enterprise_card/authorization_service_test.go create mode 100644 internal/service/enterprise_device/service.go create mode 100644 internal/service/enterprise_device/service_test.go create mode 100644 internal/store/postgres/enterprise_card_authorization_store_test.go create mode 100644 internal/store/postgres/enterprise_device_authorization_store.go create mode 100644 internal/store/postgres/enterprise_device_authorization_store_test.go create mode 100644 migrations/000031_add_enterprise_device_authorization.down.sql create mode 100644 migrations/000031_add_enterprise_device_authorization.up.sql create mode 100644 migrations/000032_add_device_auth_id_to_enterprise_card_authorization.down.sql create mode 100644 migrations/000032_add_device_auth_id_to_enterprise_card_authorization.up.sql create mode 100644 openspec/changes/archive/2026-01-29-add-enterprise-device-authorization/.openspec.yaml create mode 100644 openspec/changes/archive/2026-01-29-add-enterprise-device-authorization/design.md create mode 100644 openspec/changes/archive/2026-01-29-add-enterprise-device-authorization/proposal.md create mode 100644 openspec/changes/archive/2026-01-29-add-enterprise-device-authorization/specs/enterprise-card-authorization/spec.md create mode 100644 openspec/changes/archive/2026-01-29-add-enterprise-device-authorization/specs/enterprise-device-authorization/spec.md create mode 100644 openspec/changes/archive/2026-01-29-add-enterprise-device-authorization/tasks.md create mode 100644 openspec/changes/archive/2026-01-29-add-role-handler-validation/.openspec.yaml create mode 100644 openspec/changes/archive/2026-01-29-add-role-handler-validation/design.md create mode 100644 openspec/changes/archive/2026-01-29-add-role-handler-validation/proposal.md create mode 100644 openspec/changes/archive/2026-01-29-add-role-handler-validation/specs/role-request-validation/spec.md create mode 100644 openspec/changes/archive/2026-01-29-add-role-handler-validation/tasks.md create mode 100644 openspec/changes/fix-authorization-remark-permission/.openspec.yaml create mode 100644 openspec/changes/fix-authorization-remark-permission/design.md create mode 100644 openspec/changes/fix-authorization-remark-permission/proposal.md create mode 100644 openspec/changes/fix-authorization-remark-permission/tasks.md create mode 100644 openspec/changes/fix-commission-calculation-trigger-and-snapshot/.openspec.yaml create mode 100644 openspec/changes/fix-commission-calculation-trigger-and-snapshot/design.md create mode 100644 openspec/changes/fix-commission-calculation-trigger-and-snapshot/proposal.md create mode 100644 openspec/changes/fix-commission-calculation-trigger-and-snapshot/tasks.md create mode 100644 openspec/changes/fix-one-time-commission-config-and-accumulation/.openspec.yaml create mode 100644 openspec/changes/fix-one-time-commission-config-and-accumulation/design.md create mode 100644 openspec/changes/fix-one-time-commission-config-and-accumulation/proposal.md create mode 100644 openspec/changes/fix-one-time-commission-config-and-accumulation/tasks.md create mode 100644 openspec/changes/fix-order-activation-idempotency/.openspec.yaml create mode 100644 openspec/changes/fix-order-activation-idempotency/design.md create mode 100644 openspec/changes/fix-order-activation-idempotency/proposal.md create mode 100644 openspec/changes/fix-order-activation-idempotency/tasks.md create mode 100644 openspec/config.yaml delete mode 100644 openspec/project.md create mode 100644 openspec/specs/enterprise-device-authorization/spec.md create mode 100644 tests/integration/enterprise_device_h5_test.go create mode 100644 tests/integration/enterprise_device_test.go diff --git a/.claude/commands/opsx/continue.md b/.claude/commands/opsx/continue.md index a207205..49daaa7 100644 --- a/.claude/commands/opsx/continue.md +++ b/.claude/commands/opsx/continue.md @@ -96,7 +96,7 @@ Common artifact patterns: **spec-driven schema** (proposal → specs → design → tasks): - **proposal.md**: Ask user about the change if not clear. Fill in Why, What Changes, Capabilities, Impact. - The Capabilities section is critical - each capability listed will need a spec file. -- **specs/*.md**: Create one spec per capability listed in the proposal. +- **specs//spec.md**: Create one spec per capability listed in the proposal's Capabilities section (use the capability name, not the change name). - **design.md**: Document technical decisions, architecture, and implementation approach. - **tasks.md**: Break down implementation into checkboxed tasks. diff --git a/.claude/skills/openspec-apply-change/SKILL.md b/.claude/skills/openspec-apply-change/SKILL.md index 95a76c6..bc95df4 100644 --- a/.claude/skills/openspec-apply-change/SKILL.md +++ b/.claude/skills/openspec-apply-change/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Implement tasks from an OpenSpec change. diff --git a/.claude/skills/openspec-archive-change/SKILL.md b/.claude/skills/openspec-archive-change/SKILL.md index 099cbb4..9ea63e8 100644 --- a/.claude/skills/openspec-archive-change/SKILL.md +++ b/.claude/skills/openspec-archive-change/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Archive a completed change in the experimental workflow. diff --git a/.claude/skills/openspec-bulk-archive-change/SKILL.md b/.claude/skills/openspec-bulk-archive-change/SKILL.md index f74837e..5ce056a 100644 --- a/.claude/skills/openspec-bulk-archive-change/SKILL.md +++ b/.claude/skills/openspec-bulk-archive-change/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Archive multiple completed changes in a single operation. diff --git a/.claude/skills/openspec-continue-change/SKILL.md b/.claude/skills/openspec-continue-change/SKILL.md index 37cc56f..79aaac4 100644 --- a/.claude/skills/openspec-continue-change/SKILL.md +++ b/.claude/skills/openspec-continue-change/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Continue working on a change by creating the next artifact. @@ -100,7 +100,7 @@ Common artifact patterns: **spec-driven schema** (proposal → specs → design → tasks): - **proposal.md**: Ask user about the change if not clear. Fill in Why, What Changes, Capabilities, Impact. - The Capabilities section is critical - each capability listed will need a spec file. -- **specs/*.md**: Create one spec per capability listed in the proposal. +- **specs//spec.md**: Create one spec per capability listed in the proposal's Capabilities section (use the capability name, not the change name). - **design.md**: Document technical decisions, architecture, and implementation approach. - **tasks.md**: Break down implementation into checkboxed tasks. diff --git a/.claude/skills/openspec-explore/SKILL.md b/.claude/skills/openspec-explore/SKILL.md index 676d5a3..49d051d 100644 --- a/.claude/skills/openspec-explore/SKILL.md +++ b/.claude/skills/openspec-explore/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Enter explore mode. Think deeply. Visualize freely. Follow the conversation wherever it goes. diff --git a/.claude/skills/openspec-ff-change/SKILL.md b/.claude/skills/openspec-ff-change/SKILL.md index a7d983f..64f058c 100644 --- a/.claude/skills/openspec-ff-change/SKILL.md +++ b/.claude/skills/openspec-ff-change/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Fast-forward through artifact creation - generate everything needed to start implementation in one go. diff --git a/.claude/skills/openspec-new-change/SKILL.md b/.claude/skills/openspec-new-change/SKILL.md index a207a4b..53d96b9 100644 --- a/.claude/skills/openspec-new-change/SKILL.md +++ b/.claude/skills/openspec-new-change/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Start a new change using the experimental artifact-driven approach. diff --git a/.claude/skills/openspec-onboard/SKILL.md b/.claude/skills/openspec-onboard/SKILL.md index 34a30a7..40080aa 100644 --- a/.claude/skills/openspec-onboard/SKILL.md +++ b/.claude/skills/openspec-onboard/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Guide the user through their first complete OpenSpec workflow cycle. This is a teaching experience—you'll do real work in their codebase while explaining each step. diff --git a/.claude/skills/openspec-sync-specs/SKILL.md b/.claude/skills/openspec-sync-specs/SKILL.md index ff2866d..632681c 100644 --- a/.claude/skills/openspec-sync-specs/SKILL.md +++ b/.claude/skills/openspec-sync-specs/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Sync delta specs from a change to main specs. diff --git a/.claude/skills/openspec-verify-change/SKILL.md b/.claude/skills/openspec-verify-change/SKILL.md index d33a23e..21cbc50 100644 --- a/.claude/skills/openspec-verify-change/SKILL.md +++ b/.claude/skills/openspec-verify-change/SKILL.md @@ -6,7 +6,7 @@ compatibility: Requires openspec CLI. metadata: author: openspec version: "1.0" - generatedBy: "1.0.1" + generatedBy: "1.0.2" --- Verify that an implementation matches the change artifacts (specs, tasks, design). diff --git a/.codex/prompts/opsx-apply.md b/.codex/prompts/opsx-apply.md new file mode 100644 index 0000000..04a0e9e --- /dev/null +++ b/.codex/prompts/opsx-apply.md @@ -0,0 +1,150 @@ +--- +description: Implement tasks from an OpenSpec change (Experimental) +argument-hint: command arguments +--- + +Implement tasks from an OpenSpec change. + +**Input**: Optionally specify a change name (e.g., `/opsx:apply add-auth`). If omitted, check if it can be inferred from conversation context. If vague or ambiguous you MUST prompt for available changes. + +**Steps** + +1. **Select the change** + + If a name is provided, use it. Otherwise: + - Infer from conversation context if the user mentioned a change + - Auto-select if only one active change exists + - If ambiguous, run `openspec list --json` to get available changes and use the **AskUserQuestion tool** to let the user select + + Always announce: "Using change: " and how to override (e.g., `/opsx:apply `). + +2. **Check status to understand the schema** + ```bash + openspec status --change "" --json + ``` + Parse the JSON to understand: + - `schemaName`: The workflow being used (e.g., "spec-driven") + - Which artifact contains the tasks (typically "tasks" for spec-driven, check status for others) + +3. **Get apply instructions** + + ```bash + openspec instructions apply --change "" --json + ``` + + This returns: + - Context file paths (varies by schema) + - Progress (total, complete, remaining) + - Task list with status + - Dynamic instruction based on current state + + **Handle states:** + - If `state: "blocked"` (missing artifacts): show message, suggest using `/opsx:continue` + - If `state: "all_done"`: congratulate, suggest archive + - Otherwise: proceed to implementation + +4. **Read context files** + + Read the files listed in `contextFiles` from the apply instructions output. + The files depend on the schema being used: + - **spec-driven**: proposal, specs, design, tasks + - Other schemas: follow the contextFiles from CLI output + +5. **Show current progress** + + Display: + - Schema being used + - Progress: "N/M tasks complete" + - Remaining tasks overview + - Dynamic instruction from CLI + +6. **Implement tasks (loop until done or blocked)** + + For each pending task: + - Show which task is being worked on + - Make the code changes required + - Keep changes minimal and focused + - Mark task complete in the tasks file: `- [ ]` → `- [x]` + - Continue to next task + + **Pause if:** + - Task is unclear → ask for clarification + - Implementation reveals a design issue → suggest updating artifacts + - Error or blocker encountered → report and wait for guidance + - User interrupts + +7. **On completion or pause, show status** + + Display: + - Tasks completed this session + - Overall progress: "N/M tasks complete" + - If all done: suggest archive + - If paused: explain why and wait for guidance + +**Output During Implementation** + +``` +## Implementing: (schema: ) + +Working on task 3/7: +[...implementation happening...] +✓ Task complete + +Working on task 4/7: +[...implementation happening...] +✓ Task complete +``` + +**Output On Completion** + +``` +## Implementation Complete + +**Change:** +**Schema:** +**Progress:** 7/7 tasks complete ✓ + +### Completed This Session +- [x] Task 1 +- [x] Task 2 +... + +All tasks complete! Ready to archive this change. +``` + +**Output On Pause (Issue Encountered)** + +``` +## Implementation Paused + +**Change:** +**Schema:** +**Progress:** 4/7 tasks complete + +### Issue Encountered + + +**Options:** +1.