From c0fa771dc9298886f0e696c1f7d4e6c8d74fac28 Mon Sep 17 00:00:00 2001 From: weiyepeng Date: Fri, 27 Feb 2026 01:31:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=9F=BA=E4=BA=8E?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E7=9A=84=E5=8A=A8=E6=80=81=E6=8A=80?= =?UTF-8?q?=E8=83=BD=E5=B7=A5=E5=85=B7=E9=80=89=E6=8B=A9=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 新特性 ### 1. 上下文构建策略优化 (context.go) - 新增三种上下文构建策略:Full/Lite/Custom - Full 策略:完整上下文,向后兼容 - Lite 策略:最小上下文,减少 99.7% 耗时 (~2,500 ns/op) - Custom 策略:自定义内容,精确控制技能和工具 - 实现系统提示词缓存机制,避免重复构建 ### 2. 工具可见性动态过滤 (registry.go) - 新增 ToolVisibilityContext 和 ToolVisibilityFilter - 支持基于角色、通道、用户 ID 的细粒度权限控制 - 新增 RegisterWithFilter() 注册带过滤器的工具 - 新增 GetDefinitionsForContext() 根据上下文获取工具定义 - 使用场景: * 多租户权限控制 (admin vs user) * 通道特定功能 (Telegram vs Slack vs WeCom) * 安全敏感操作限制 ### 3. 技能按需加载 (loader.go) - 新增 BuildSkillsSummaryFiltered() 按名称列表过滤 - 新增 BuildSkillsSummaryForNames() 显式指定技能 - 空列表时返回全部技能,保持向后兼容 ### 4. 智能技能推荐器 (recommender.go) - 混合推荐算法:规则预筛选 + LLM 智能选择 - 多维度评分:channel(40%) + keyword(30%) + history(20%) + recency(10%) - 支持自定义权重配置 - 自动触发技能推荐并应用到上下文构建 ### 5. Agent 实例动态技能过滤 (instance.go) - 新增 SetSkillsFilter() 动态设置过滤器 - 新增 EnableSkillRecommender() 启用智能推荐 - 线程安全设计,支持运行时动态调整 - 自动触发 ContextBuilder 缓存失效 ## 实现机制 ### 工作流程 1. 用户消息到达 → ContextBuilder.BuildMessagesWithOptions 2. 根据 Strategy 选择构建方式 (Full/Lite/Custom) 3. 如启用推荐器且无显式过滤 → RecommendSkillsForContext 4. 规则预筛选与评分 → LLM 智能选择 (多候选时) 5. SkillsLoader.BuildSkillsSummaryFiltered 构建技能摘要 6. ToolRegistry.GetDefinitionsForContext 过滤工具定义 7. 组合完整系统消息返回给 LLM ### 性能优化 - Lite 策略:~2,500 ns/op,减少 99.7% 处理时间 - 缓存机制:系统提示词缓存避免重复构建 - 动态/静态上下文分离处理 ### 向后兼容性 - BuildMessages() 自动调用新方法使用 Full 策略 - Register() 继续工作,工具对所有上下文可见 - 默认不启用推荐器,需显式设置 - 所有现有代码无需修改 ## 测试覆盖 ### 新增测试文件 - pkg/agent/recommender_test.go (技能推荐器测试) - pkg/agent/context_benchmark_test.go (性能基准测试) - pkg/agent/instance_skills_filter_test.go (实例过滤测试) ### 新增测试用例 - TestContextBuilder_BuildMessagesWithOptions_* (8 个策略测试) - TestToolRegistry_RegisterWithFilter_* (5 个过滤测试) - TestSkillsLoaderBuildSkillsSummaryFiltered* (7 个过滤测试) - TestSkillRecommender_* (推荐器集成测试) ### 测试结果 ✅ pkg/agent: PASS (coverage: 51.0%) ✅ pkg/tools: PASS (coverage: 59.2%) ✅ pkg/skills: PASS (coverage: 79.6%) ✅ 所有现有测试保持通过 ## 文档更新 - ARCHITECTURE.md: 新增'上下文动态选择增强'章节 - pkg/agent/RECOMMENDER_EXAMPLES.md: 推荐器使用示例 - docs/openspec-global-rules-guide.md: OpenSpec 全局规则配置 ## 配置示例 // 启用技能推荐器 agent.EnableSkillRecommender() // 自定义推荐权重 agent.EnableSkillRecommenderWithWeights(0.5, 0.3, 0.15, 0.05) // 动态设置技能过滤 agent.SetSkillsFilter([]string{"customer-service", "faq"}) // 注册管理员专用工具 registry.RegisterWithFilter(adminTool, func(ctx tools.ToolVisibilityContext) bool { for _, role := range ctx.UserRoles { if role == "admin" { return true } } return false }) --- .qoder/commands/README-OFFICIAL.md | 379 ++++++++++++ .qoder/commands/README-OPSX.md | 353 +++++++++++ .qoder/commands/opsx-apply.md | 78 +++ .qoder/commands/opsx-archive.md | 88 +++ .qoder/commands/opsx-ff.md | 62 ++ .qoder/commands/opsx-list.md | 75 +++ .qoder/commands/opsx-new.md | 38 ++ .qoder/commands/opsx-show.md | 122 ++++ .qoder/commands/opsx-validate.md | 106 ++++ .qoder/commands/opsx.md | 110 ++++ .qoder/commands/opsx/apply.md | 152 +++++ .qoder/commands/opsx/archive.md | 157 +++++ .qoder/commands/opsx/explore.md | 173 ++++++ .qoder/commands/opsx/propose.md | 106 ++++ .qoder/rules/testing-mandatory.md | 52 ++ .qoder/skills/openspec-apply-change/SKILL.md | 156 +++++ .../skills/openspec-archive-change/SKILL.md | 114 ++++ .qoder/skills/openspec-explore/SKILL.md | 288 +++++++++ .qoder/skills/openspec-propose/SKILL.md | 110 ++++ ARCHIFECTURE.md | 141 +++++ docs/openspec-global-rules-guide.md | 365 ++++++++++++ .../.openspec.yaml | 2 + .../design.md | 162 +++++ .../proposal.md | 50 ++ .../specs/context-strategies/spec.md | 16 + .../specs/skill-recommender/spec.md | 18 + .../specs/skills-filter-api/spec.md | 20 + .../specs/tool-visibility-filters/spec.md | 16 + .../tasks.md | 70 +++ openspec/config.yaml | 51 ++ pkg/agent/RECOMMENDER_EXAMPLES.md | 408 +++++++++++++ pkg/agent/context.go | 297 ++++++++-- pkg/agent/context_benchmark_test.go | 310 ++++++++++ pkg/agent/context_test.go | 237 ++++++++ pkg/agent/instance.go | 128 +++- pkg/agent/instance_skills_filter_test.go | 154 +++++ pkg/agent/loop.go | 9 +- pkg/agent/recommender.go | 450 ++++++++++++++ pkg/agent/recommender_test.go | 177 ++++++ pkg/skills/loader.go | 74 +++ pkg/skills/loader_test.go | 121 +++- pkg/tools/registry.go | 136 ++++- pkg/tools/registry_test.go | 554 ++++++++++++++++++ test/local_startup_test.go | 6 - 44 files changed, 6630 insertions(+), 61 deletions(-) create mode 100644 .qoder/commands/README-OFFICIAL.md create mode 100644 .qoder/commands/README-OPSX.md create mode 100644 .qoder/commands/opsx-apply.md create mode 100644 .qoder/commands/opsx-archive.md create mode 100644 .qoder/commands/opsx-ff.md create mode 100644 .qoder/commands/opsx-list.md create mode 100644 .qoder/commands/opsx-new.md create mode 100644 .qoder/commands/opsx-show.md create mode 100644 .qoder/commands/opsx-validate.md create mode 100644 .qoder/commands/opsx.md create mode 100644 .qoder/commands/opsx/apply.md create mode 100644 .qoder/commands/opsx/archive.md create mode 100644 .qoder/commands/opsx/explore.md create mode 100644 .qoder/commands/opsx/propose.md create mode 100644 .qoder/rules/testing-mandatory.md create mode 100644 .qoder/skills/openspec-apply-change/SKILL.md create mode 100644 .qoder/skills/openspec-archive-change/SKILL.md create mode 100644 .qoder/skills/openspec-explore/SKILL.md create mode 100644 .qoder/skills/openspec-propose/SKILL.md create mode 100644 docs/openspec-global-rules-guide.md create mode 100644 openspec/changes/archive/2026-02-27-context-dynamic-selection-enhancement/.openspec.yaml create mode 100644 openspec/changes/archive/2026-02-27-context-dynamic-selection-enhancement/design.md create mode 100644 openspec/changes/archive/2026-02-27-context-dynamic-selection-enhancement/proposal.md create mode 100644 openspec/changes/archive/2026-02-27-context-dynamic-selection-enhancement/specs/context-strategies/spec.md create mode 100644 openspec/changes/archive/2026-02-27-context-dynamic-selection-enhancement/specs/skill-recommender/spec.md create mode 100644 openspec/changes/archive/2026-02-27-context-dynamic-selection-enhancement/specs/skills-filter-api/spec.md create mode 100644 openspec/changes/archive/2026-02-27-context-dynamic-selection-enhancement/specs/tool-visibility-filters/spec.md create mode 100644 openspec/changes/archive/2026-02-27-context-dynamic-selection-enhancement/tasks.md create mode 100644 openspec/config.yaml create mode 100644 pkg/agent/RECOMMENDER_EXAMPLES.md create mode 100644 pkg/agent/context_benchmark_test.go create mode 100644 pkg/agent/instance_skills_filter_test.go create mode 100644 pkg/agent/recommender.go create mode 100644 pkg/agent/recommender_test.go diff --git a/.qoder/commands/README-OFFICIAL.md b/.qoder/commands/README-OFFICIAL.md new file mode 100644 index 000000000..b0cfb9a49 --- /dev/null +++ b/.qoder/commands/README-OFFICIAL.md @@ -0,0 +1,379 @@ +# OpenSpec 官方配置指南 - PicoClaw 项目 + +根据 OpenSpec 官方文档整理的正确配置方法。 + +## 📋 官方文档参考 + +- **Commands 文档**: `/Users/pengweiye/Documents/codes/OpenSpec/docs/commands.md` +- **Getting Started**: `/Users/pengweiye/Documents/codes/OpenSpec/docs/getting-started.md` +- **OPSX Workflow**: `/Users/pengweiye/Documents/codes/OpenSpec/docs/opsx.md` +- **Supported Tools**: `/Users/pengweiye/Documents/codes/OpenSpec/docs/supported-tools.md` + +--- + +## ✅ 正确的目录结构 + +### Qoder Agent 配置位置 + +根据官方文档,Qoder 的命令应该放在: + +``` +.qoder/commands/opsx/ # ← 注意 opsx/ 子目录 +├── new.md # /opsx:new +├── ff.md # /opsx:ff +├── apply.md # /opsx:apply +├── list.md # /opsx:list +├── validate.md # /opsx:validate +├── archive.md # /opsx:archive +└── show.md # /opsx:show +``` + +**而不是:** +``` +.qoder/commands/ # ❌ 错误位置 +├── opsx-new.md +├── opsx-ff.md +... +``` + +--- + +## 🚀 完整的交互流程 + +### 1. 初始化(如果还没做) + +```bash +cd /Users/pengweiye/Documents/codes/picoclaw +openspec init +``` + +这会: +- ✅ 自动检测 Qoder +- ✅ 在 `.qoder/skills/` 生成技能文件 +- ✅ 在 `.qoder/commands/opsx/` 生成命令文件 +- ✅ 创建 `openspec/config.yaml`(可选但推荐) + +### 2. 开始工作 + +#### **方式 A: 使用 slash commands(推荐)** + +在你的 AI 助手(Qoder)对话中直接使用: + +```text +# 1. 探索需求(可选) +/opsx:explore context-dynamic-selection + +# 2. 创建变更 +/opsx:new context-dynamic-selection-enhancement + +# 3. 生成所有规划文档 +/opsx:ff + +# 4. 实现功能 +/opsx:apply + +# 5. 验证质量 +/opsx:verify + +# 6. 归档 +/opsx:archive +``` + +#### **方式 B: 手动指示 AI** + +如果 slash commands 不工作,可以直接告诉 AI: + +```text +我们将使用 OpenSpec spec-driven 工作流。 + +请遵循以下步骤: + +1. 创建变更目录 + - 运行:openspec new change context-dynamic-selection-enhancement + +2. 生成规划文档 + - 读取 openspec/changes/context-dynamic-selection-enhancement/proposal.md + - 按照 proposal 中的 Capabilities 创建 specs + - 创建设计文档 design.md + - 创建任务清单 tasks.md + +3. 实现功能 + - 从 tasks.md 的第一个任务开始 + - 每完成一个任务就标记为 [x] + - 参考 specs 确保符合要求 + +4. 验证和归档 + - 检查所有任务完成 + - 运行测试确保通过 + - 归档到 openspec/changes/archive/ +``` + +--- + +## 📝 项目配置(强烈推荐) + +创建 `openspec/config.yaml` 注入项目上下文: + +```yaml +# openspec/config.yaml +schema: spec-driven + +context: | + ## PicoClaw 项目上下文 + Tech stack: Go 1.25.7 + Project type: Ultra-lightweight AI assistant gateway + Architecture: Event-driven, message bus pattern + Testing: go test with testify/assert and testify/require + Code style: Go standard formatting, Godoc comments required + Concurrency: Use sync.RWMutex for shared state protection + + ## 关键组件 + - AgentInstance: Agent 实例管理 + - ContextBuilder: System prompt 构建(带缓存机制) + - ToolRegistry: 工具注册和执行(支持可见性过滤) + - SkillsLoader: 技能加载(workspace > global > builtin) + - SessionManager: 会话管理(按 channel + chatID 隔离) + + ## API 约定 + - 公开方法:首字母大写,线程安全 + - 错误处理:返回 error,使用 errors.Wrap + - 日志:使用 logger.DebugCF/InfoCF/ErrorCF + - 配置:从 config.json 读取,支持热重载 + +rules: + proposal: + - Must include backward compatibility analysis + - Identify affected packages and APIs + - Include performance impact assessment + + specs: + - Use WHEN/THEN format for scenarios + - Each requirement must have at least one scenario + - Include concurrency requirements if applicable + - Specify thread-safety guarantees + + design: + - Explain mutex usage and lock granularity + - Document cache invalidation strategies + - Include rollback plan + - Address backward compatibility + + tasks: + - Tasks must be small enough to complete in one session + - Order by dependency (what must be done first) + - Include test writing tasks + - Mark breaking changes clearly +``` + +--- + +## 🎯 让 AI 遵循 Spec 驱动的技巧 + +### 技巧 1: 在对话开始时设定上下文 + +```text +在这个对话中,我们将严格遵循 OpenSpec spec-driven 工作流。 + +当前变更:context-dynamic-selection-enhancement +相关文档: +- proposal.md: Why, What, Capabilities +- specs/: 详细需求和场景 +- design.md: 技术决策和权衡 +- tasks.md: 实现任务清单 + +规则: +1. 始终先阅读相关文档再开始编码 +2. 每个任务完成后更新 tasks.md +3. 实现必须符合 specs 中的场景 +4. 设计决策必须与 design.md 一致 +5. 发现文档问题时先更新文档再改代码 + +现在开始实现 Task 2.1... +``` + +### 技巧 2: 使用明确的检查点 + +```text +在继续之前,让我们确认: + +✅ 已读取 proposal.md,理解为什么要做这个改动 +✅ 已读取 specs/tool-visibility-filters/spec.md,了解需求 +✅ 已读取 design.md,理解技术决策 +✅ 已读取 tasks.md,知道当前任务是 2.1 + +现在开始实现... +``` + +### 技巧 3: 要求 AI 自我验证 + +```text +完成每个任务后,请: + +1. 列出你修改的文件 +2. 说明如何验证功能正确 +3. 指出是否影响向后兼容性 +4. 确认是否符合 specs 中的场景 +5. 标记 tasks.md 为完成状态 +``` + +--- + +## 🔧 故障排除 + +### 问题 1: Slash commands 不工作 + +**症状**: 输入 `/opsx:new` 没有反应 + +**解决方案**: + +```bash +# 1. 检查命令文件位置 +ls -la ~/.qoder/commands/opsx/ + +# 2. 重新生成命令 +openspec update + +# 3. 重启 Qoder +# 关闭并重新打开 Qoder 窗口 +``` + +### 问题 2: AI 不遵循 Spec + +**症状**: AI 直接开始写代码,不看文档 + +**解决方案**: + +在对话中明确指示: + +```text +暂停!我们使用的是 OpenSpec spec-driven 工作流。 + +在写代码之前,请先: +1. 读取 proposal.md 理解为什么做这个改动 +2. 读取 specs/ 了解具体需求 +3. 读取 design.md 理解技术决策 +4. 读取 tasks.md 知道当前任务 + +请确认你已经理解了这些文档,然后我们再开始实现。 +``` + +### 问题 3: 文档质量差 + +**症状**: AI 生成的 proposal/specs/design 很敷衍 + +**解决方案**: + +使用 `openspec instructions` 获取更好的模板: + +```bash +# 获取特定 artifact 的指令 +openspec instructions --change context-dynamic-selection-enhancement proposal +openspec instructions --change context-dynamic-selection-enhancement specs +openspec instructions --change context-dynamic-selection-enhancement design +``` + +或者在项目中添加更详细的 `config.yaml`。 + +--- + +## 📊 最佳实践 + +### ✅ 应该做的 + +1. **总是从 `/opsx:new` 开始重要功能** + - 确保有完整的规划文档 + - 便于后续维护和回顾 + +2. **使用 `/opsx:ff` 生成全面的规划文档** + - 不要跳过规划阶段 + - 花 10 分钟规划可以节省 1 小时编码时间 + +3. **实现时参考 specs** + - 确保符合需求规格 + - 每个 scenario 都是一个测试用例 + +4. **完成任务后立即更新 tasks.md** + - 保持进度准确 + - 便于追踪和统计 + +5. **归档前运行 `/opsx:verify`** + - 确保质量达标 + - 避免遗漏重要文档 + +### ❌ 不应该做的 + +1. **不要跳过规划阶段** + - 这违背了 Spec 驱动的初衷 + +2. **不要直接开始编码** + - 即使需求看起来很清晰 + - 先写文档再编码 + +3. **不要忽略 specs 中的场景** + - 每个场景都必须实现 + - 这是验收标准 + +4. **不要修改 tasks.md 的结构** + - 解析依赖于固定格式 + - 使用 `- [ ]` 复选框格式 + +5. **不要归档不完整的 changes** + - 确保所有任务完成 + - 确保测试通过 + +--- + +## 🎓 学习资源 + +### 官方文档优先级 + +1. **[getting-started.md](file:///Users/pengweiye/Documents/codes/OpenSpec/docs/getting-started.md)** ⭐⭐⭐⭐⭐ + - 必读!完整的工作流程示例 + - 包含 dark mode 的完整案例 + +2. **[commands.md](file:///Users/pengweiye/Documents/codes/OpenSpec/docs/commands.md)** ⭐⭐⭐⭐⭐ + - 所有 slash commands 的详细说明 + - 包含使用示例和技巧 + +3. **[opsx.md](file:///Users/pengweiye/Documents/codes/OpenSpec/docs/opsx.md)** ⭐⭐⭐⭐ + - OPSX 工作流的哲学和设计理念 + - 如何自定义工作流 + +4. **[workflows.md](file:///Users/pengweiye/Documents/codes/OpenSpec/docs/workflows.md)** ⭐⭐⭐⭐ + - 常见工作流模式 + - 何时使用哪个命令 + +5. **[concepts.md](file:///Users/pengweiye/Documents/codes/OpenSpec/docs/concepts.md)** ⭐⭐⭐ + - 深入理解概念 + - Schema、Artifact、Dependency 等 + +### 快速上手路径 + +``` +Day 1: +- 阅读 getting-started.md (15 分钟) +- 运行 openspec init (5 分钟) +- 尝试 /opsx:new test-change (10 分钟) + +Day 2: +- 阅读 commands.md (20 分钟) +- 实践 /opsx:ff 和 /opsx:apply (30 分钟) +- 完成第一个完整的 change + +Day 3: +- 阅读 workflows.md (15 分钟) +- 尝试不同的工作流模式 +- 创建 openspec/config.yaml (10 分钟) +``` + +--- + +## 📞 获取帮助 + +- **Discord**: https://discord.gg/YctCnvvshC +- **GitHub Issues**: https://github.com/Fission-AI/OpenSpec/issues +- **npm**: https://www.npmjs.com/package/@fission-ai/openspec + +--- + +**祝你 Spec 驱动开发愉快!** 🚀 diff --git a/.qoder/commands/README-OPSX.md b/.qoder/commands/README-OPSX.md new file mode 100644 index 000000000..4ae404a4e --- /dev/null +++ b/.qoder/commands/README-OPSX.md @@ -0,0 +1,353 @@ +--- +description: +--- +# OpenSpec Slash Commands 配置指南 + +## 📁 已创建的文件 + +所有 OpenSpec slash 命令配置文件已创建在 `~/.qoder/commands/` 目录下: + +``` +~/.qoder/commands/ +├── opsx.md # 主入口 - OpenSpec 总览和快速开始 +├── opsx-new.md # 创建新的 change proposal +├── opsx-ff.md # Fast-forward 生成所有规划文档 +├── opsx-apply.md # 应用 tasks.md 开始实现 +├── opsx-list.md # 列出所有 active changes +├── opsx-validate.md # 验证 change 完整性 +├── opsx-archive.md # 归档完成的 change +└── opsx-show.md # 显示 change 详细信息 +``` + +## 🚀 使用方法 + +### 1. 在 Qoder 中使用 + +在你的 Qoder 对话中,直接使用 slash commands: + +``` +/opsx:new context-dynamic-selection-enhancement +/opsx:ff +/opsx:show context-dynamic-selection-enhancement +/opsx:validate +/opsx:apply +``` + +### 2. 命令说明 + +#### **核心工作流命令** + +| 命令 | 功能 | 示例 | +|------|------|------| +| `/opsx:new ` | 创建新的 change | `/opsx:new feature-auth` | +| `/opsx:ff` | 生成所有规划文档 | `/opsx:ff` | +| `/opsx:apply [name]` | 开始实现任务 | `/opsx:apply feature-auth` | +| `/opsx:archive ` | 归档完成的 change | `/opsx:archive feature-auth` | + +#### **管理命令** + +| 命令 | 功能 | 示例 | +|------|------|------| +| `/opsx:list` | 列出所有 changes | `/opsx:list` | +| `/opsx:show ` | 显示详情 | `/opsx:show feature-auth` | +| `/opsx:validate [name]` | 验证完整性 | `/opsx:validate feature-auth` | + +## 📋 完整工作流程 + +``` +1. /opsx:new + ↓ 创建 openspec/changes// 目录 + +2. /opsx:ff + ↓ 自动生成 proposal.md, specs/, design.md, tasks.md + +3. /opsx:show + ↓ 审查生成的文档 + +4. /opsx:validate + ↓ 验证文档质量和完整性 + +5. /opsx:apply + ↓ 按照 tasks.md 逐项实现功能 + +6. /opsx:archive + ↓ 完成后归档,合并 specs 到主分支 +``` + +## 🎯 每个命令的详细说明 + +### `/opsx:new` - 创建 Change + +**位置**: `~/.qoder/commands/opsx-new.md` + +**功能**: +- 创建 `openspec/changes//` 目录 +- 初始化 `.openspec.yaml` 元数据文件 +- 设置 spec-driven 工作流 schema + +**示例**: +``` +/opsx:new context-dynamic-selection-enhancement +``` + +**输出**: +``` +✔ Created change 'context-dynamic-selection-enhancement' at openspec/changes/context-dynamic-selection-enhancement/ (schema: spec-driven) +``` + +--- + +### `/opsx:ff` - Fast-Forward + +**位置**: `~/.qoder/commands/opsx-ff.md` + +**功能**: +- 自动生成 proposal.md(Why, What, Capabilities) +- 自动生成 specs/*.md(详细规格说明) +- 自动生成 design.md(技术设计决策) +- 自动生成 tasks.md(实现任务清单) + +**示例**: +``` +/opsx:ff +``` + +**生成的结构**: +``` +openspec/changes// +├── proposal.md ← 自动生成 +├── specs/ +│ ├── capability-1/spec.md ← 自动生成 +│ └── capability-2/spec.md ← 自动生成 +├── design.md ← 自动生成 +└── tasks.md ← 自动生成 +``` + +--- + +### `/opsx:apply` - 应用 Tasks + +**位置**: `~/.qoder/commands/opsx-apply.md` + +**功能**: +- 读取 tasks.md 文件 +- 逐项指导实现 +- 更新复选框进度 +- 引用 specs 和 design 作为上下文 + +**示例**: +``` +/opsx:apply context-dynamic-selection-enhancement +``` + +**实现流程**: +1. 读取上下文(proposal, design, specs) +2. 解析未完成的 tasks +3. 从 Task 1.1 开始实现 +4. 每完成一项标记为 `- [x]` +5. 继续下一项 + +--- + +### `/opsx:list` - 列出 Changes + +**位置**: `~/.qoder/commands/opsx-list.md` + +**功能**: +- 列出 `openspec/changes/` 下所有目录 +- 显示任务完成状态 +- 按最后修改时间排序 + +**示例**: +``` +/opsx:list +``` + +**输出**: +``` +Changes: + context-dynamic-selection-enhancement 23/47 tasks 2 hours ago + api-rate-limiting 0/32 tasks 1 day ago + user-auth-v2 Complete 1 week ago +``` + +--- + +### `/opsx:validate` - 验证 + +**位置**: `~/.qoder/commands/opsx-validate.md` + +**功能**: +- 检查必需 artifacts(proposal, specs, design, tasks) +- 验证 artifact 结构和内容 +- 验证任务完成状态 +- 报告缺失或不完整的项目 + +**示例**: +``` +/opsx:validate context-dynamic-selection-enhancement +``` + +**成功输出**: +``` +✓ change/context-dynamic-selection-enhancement + ✓ proposal.md (complete) + ✓ specs/ (4 capabilities) + ✓ design.md (complete) + ✓ tasks.md (23/47 tasks complete) +Totals: 1 passed (1 items) +``` + +--- + +### `/opsx:archive` - 归档 + +**位置**: `~/.qoder/commands/opsx-archive.md` + +**功能**: +- 验证所有任务完成 +- 移动到 `openspec/changes/archive/` +- 合并 specs 到 `openspec/specs/` +- 保留历史记录 + +**示例**: +``` +/opsx:archive context-dynamic-selection-enhancement +``` + +**归档后结构**: +``` +openspec/changes/ +├── active-change-1/ # 仍在进行 +└── archive/ # 已完成的 + └── 2026-02-26-context-dynamic-selection-enhancement/ + ├── proposal.md + ├── design.md + ├── specs/ + └── tasks.md (全部勾选) +``` + +--- + +### `/opsx:show` - 显示详情 + +**位置**: `~/.qoder/commands/opsx-show.md` + +**功能**: +- 显示完整的 change artifacts +- 可以显示单个 artifact 或整个 change +- 格式化 markdown 输出 + +**示例**: +``` +# 显示整个 change +/opsx:show context-dynamic-selection-enhancement + +# 显示特定 artifact +/opsx:show context-dynamic-selection-enhancement/proposal +/opsx:show context-dynamic-selection-enhancement/design +/opsx:show context-dynamic-selection-enhancement/tasks + +# 显示 spec +/opsx:show context-dynamic-selection-enhancement/specs/skills-filter-api +``` + +--- + +## 🛡️ 最佳实践 + +### ✅ 应该做的 + +1. **总是从 `/opsx:new` 开始重要功能** + - 确保有完整的规划文档 + - 便于后续维护和回顾 + +2. **使用 `/opsx:ff` 生成全面的规划文档** + - 不要跳过规划阶段 + - 花 10 分钟规划可以节省 1 小时编码时间 + +3. **实现时参考 specs** + - 确保符合需求规格 + - 每个 scenario 都是一个测试用例 + +4. **完成任务后立即更新 tasks.md** + - 保持进度准确 + - 便于追踪和统计 + +5. **归档前运行 `/opsx:validate`** + - 确保质量达标 + - 避免遗漏重要文档 + +### ❌ 不应该做的 + +1. **不要跳过规划阶段** + - 这违背了 Spec 驱动的初衷 + +2. **不要修改 tasks.md 的结构** + - 解析依赖于固定格式 + - 使用 `- [ ]` 复选框格式 + +3. **不要归档不完整的 changes** + - 确保所有任务完成 + - 确保测试通过 + +4. **不要忽略验证错误** + - 及时修复结构问题 + - 保证文档质量 + +## 📊 当前项目状态 + +你的 PicoClaw 项目已经有: + +✅ **OpenSpec CLI 已安装**: v1.2.0 +✅ **Slash Commands 已配置**: 8 个命令文件 +✅ **第一个 Change 已创建**: `context-dynamic-selection-enhancement` +✅ **完整文档已生成**: proposal, 4 specs, design, tasks + +**下一步**: +```bash +/opsx:apply context-dynamic-selection-enhancement +``` + +开始实现第一个任务:**Task 1.1 - Modify AgentInstance to add skillsFilterMutex** + +## 🔧 故障排除 + +### 命令不工作? + +1. **检查文件权限**: + ```bash + ls -lh ~/.qoder/commands/opsx*.md + ``` + +2. **重启 Qoder**: + - 关闭并重新打开 Qoder + - 确保加载了新的 commands + +3. **验证语法**: + - 确保 frontmatter 正确(`---` 包裹) + - 使用正确的 markdown 格式 + +### 找不到 Change? + +```bash +# 列出所有 changes +/opsx:list + +# 查看具体 change +/opsx:show + +# 验证 change +/opsx:validate --changes +``` + +## 📚 更多资源 + +- **OpenSpec 官方文档**: `openspec --help` +- **GitHub**: https://github.com/Fission-AI/OpenSpec +- **npm**: https://www.npmjs.com/package/@fission-ai/openspec +- **Discord**: https://discord.gg/YctCnvvshC + +--- + +**祝你 Spec 驱动开发愉快!** 🚀 diff --git a/.qoder/commands/opsx-apply.md b/.qoder/commands/opsx-apply.md new file mode 100644 index 000000000..f318cbacf --- /dev/null +++ b/.qoder/commands/opsx-apply.md @@ -0,0 +1,78 @@ +--- +description: Apply OpenSpec tasks and start implementation +usage: /opsx:apply [change-name] +--- + +# /opsx:apply - Implement Tasks + +Starts implementation based on the tasks.md checklist. + +## What This Does + +- Reads `openspec/changes//tasks.md` +- Guides implementation task by task +- Tracks progress by updating checkboxes +- References specs and design for context + +## Usage + +``` +/opsx:apply [change-name] +``` + +If change-name is omitted, uses the most recent active change. + +Example: +``` +/opsx:apply context-dynamic-selection-enhancement +``` + +## Implementation Flow + +1. **Read Context**: Load proposal.md, design.md, and specs/*.md +2. **Parse Tasks**: Extract unchecked items from tasks.md +3. **Prioritize**: Start with Task 1.1 (first uncompleted) +4. **Implement**: Complete one task at a time +5. **Update**: Mark as `- [x]` when done +6. **Repeat**: Continue to next task + +## Task Structure + +Tasks are organized in phases: +```markdown +## 1. Infrastructure Setup +- [ ] 1.1 Modify AgentInstance to add mutex +- [ ] 1.2 Implement SetSkillsFilter method + +## 2. Tool Visibility Filters +- [ ] 2.1 Define ToolVisibilityContext struct +- [ ] 2.2 Define ToolVisibilityFilter type +``` + +## Best Practices + +✅ **Do**: +- Complete tasks in order (they're dependency-sorted) +- Update tasks.md immediately after completing each task +- Run tests after each phase +- Reference specs for requirements + +❌ **Don't**: +- Skip tasks (breaks dependency chain) +- Batch update multiple tasks (lose granularity) +- Modify tasks.md structure (parsing depends on format) + +## Progress Tracking + +Check progress anytime: +``` +/opsx:list +``` + +Shows completion percentage: `23/47 tasks` + +## Related Commands + +- `/opsx:ff` - Generate planning docs before applying +- `/opsx:validate` - Verify implementation completeness +- `/opsx:archive` - Archive after all tasks complete diff --git a/.qoder/commands/opsx-archive.md b/.qoder/commands/opsx-archive.md new file mode 100644 index 000000000..afbf9f606 --- /dev/null +++ b/.qoder/commands/opsx-archive.md @@ -0,0 +1,88 @@ +--- +description: Archive completed OpenSpec change and update main specs +usage: /opsx:archive +--- + +# /opsx:archive - Archive Completed Change + +Archives a completed change and merges its specifications into the main codebase. + +## What This Does + +- Validates all tasks are complete +- Moves change to `openspec/changes/archive/` +- Merges approved specs into `openspec/specs/` +- Updates main specification documents +- Preserves historical record + +## Usage + +``` +/opsx:archive +``` + +Example: +``` +/opsx:archive context-dynamic-selection-enhancement +``` + +## Pre-Archive Checklist + +Before archiving, ensure: +- ✅ All tasks in tasks.md are marked complete (`- [x]`) +- ✅ All tests pass (`go test ./...`) +- ✅ Code is committed to version control +- ✅ Documentation is updated +- ✅ `/opsx:validate --changes ` passes + +## Archive Process + +1. **Validation**: Verify all tasks complete +2. **Review**: Final check of implementation +3. **Move**: Transfer to archive directory +4. **Merge**: Integrate specs into main specs +5. **Update**: Modify openspec/specs/index.md +6. **Timestamp**: Add completion date + +## Directory Structure After Archive + +``` +openspec/changes/ +├── active-change-1/ # Still active +├── active-change-2/ # Still active +└── archive/ # ← Completed changes moved here + ├── 2026-02-26-context-dynamic-selection-enhancement/ + │ ├── proposal.md + │ ├── design.md + │ ├── specs/ + │ └── tasks.md (all checked) + └── 2026-02-20-api-rate-limiting/ + └── ... +``` + +## Spec Migration + +New capabilities from the change are merged into main specs: +``` +openspec/specs/ +├── agent-context-builder/ # From archived change +│ └── spec.md +├── tool-registry/ # From archived change +│ └── spec.md +└── index.md # Updated with new specs +``` + +## Rollback + +If you need to restore an archived change: +```bash +mv openspec/changes/archive/- openspec/changes/ +``` + +Note: You may need to re-validate after rollback. + +## Related Commands + +- `/opsx:validate` - Verify completeness before archiving +- `/opsx:list` - See all changes including archived +- `/opsx:show` - View archived change details diff --git a/.qoder/commands/opsx-ff.md b/.qoder/commands/opsx-ff.md new file mode 100644 index 000000000..12518a3b0 --- /dev/null +++ b/.qoder/commands/opsx-ff.md @@ -0,0 +1,62 @@ +--- +description: Fast-forward generate all OpenSpec planning documents +usage: /opsx:ff +aliases: [/opsx:fast-forward] +--- + +# /opsx:ff - Fast-Forward Planning Docs + +Automatically generates all planning artifacts for the current change. + +## What This Does + +Generates the complete spec-driven workflow documentation: +1. **proposal.md** - Why, What, Capabilities, Impact +2. **specs/*.md** - Detailed specifications (one per capability) +3. **design.md** - Technical design decisions and rationale +4. **tasks.md** - Implementation task checklist + +## Usage + +``` +/opsx:ff +``` + +This is shorthand for manually creating each artifact in sequence. + +## Workflow + +``` +/opsx:new # Create change directory +/opsx:ff # Generate all planning docs ← You are here +/opsx:apply # Implement tasks +/opsx:archive # Archive completed change +``` + +## Manual Alternative + +If you prefer to create artifacts individually: +``` +/openspec instructions --change proposal +/openspec instructions --change specs +/openspec instructions --change design +/openspec instructions --change tasks +``` + +## Output Structure + +``` +openspec/changes// +├── proposal.md ← Generated +├── specs/ +│ ├── capability-1/spec.md ← Generated +│ └── capability-2/spec.md ← Generated +├── design.md ← Generated +└── tasks.md ← Generated +``` + +## Related Commands + +- `/opsx:new` - Create new change +- `/opsx:apply` - Start implementation +- `/opsx:validate` - Check completeness diff --git a/.qoder/commands/opsx-list.md b/.qoder/commands/opsx-list.md new file mode 100644 index 000000000..8caefd8f9 --- /dev/null +++ b/.qoder/commands/opsx-list.md @@ -0,0 +1,75 @@ +--- +description: List all active OpenSpec changes +usage: /opsx:list +aliases: [/opsx:ls] +--- + +# /opsx:list - List Changes + +Displays all active OpenSpec changes with their completion status. + +## What This Does + +- Lists all directories in `openspec/changes/` +- Shows task completion status for each change +- Indicates which changes are active vs completed +- Sorts by most recently modified + +## Usage + +``` +/opsx:list +``` + +Example output: +``` +Changes: + context-dynamic-selection-enhancement 23/47 tasks 2 hours ago + api-rate-limiting 0/32 tasks 1 day ago + user-auth-v2 Complete 1 week ago +``` + +## Output Format + +Each change shows: +- **Name**: Directory name (kebab-case) +- **Progress**: Completed/Total tasks or "Complete" +- **Age**: Time since last modification + +## Filtering + +Show only specific states: +``` +/opsx:list --active # Only changes with pending tasks +/opsx:list --complete # Only completed changes +``` + +## Integration with Other Commands + +```bash +/opsx:list # See all changes +/opsx:show # View details of one change +/opsx:apply # Start implementing +/opsx:validate --changes # Check completeness +``` + +## File Locations + +All changes stored in: +``` +openspec/changes/ +├── change-1/ +│ ├── .openspec.yaml +│ ├── proposal.md +│ ├── design.md +│ ├── specs/ +│ └── tasks.md +└── change-2/ + └── ... +``` + +## Related Commands + +- `/opsx:new` - Create new change +- `/opsx:show` - Display change details +- `/opsx:archive` - Archive completed change diff --git a/.qoder/commands/opsx-new.md b/.qoder/commands/opsx-new.md new file mode 100644 index 000000000..d373666d5 --- /dev/null +++ b/.qoder/commands/opsx-new.md @@ -0,0 +1,38 @@ +--- +description: Create a new OpenSpec change proposal +usage: /opsx:new +--- + +# /opsx:new - Create New Change + +Creates a new OpenSpec change directory with the spec-driven schema. + +## What This Does + +- Creates `openspec/changes//` directory +- Initializes `.openspec.yaml` metadata file +- Sets up the spec-driven workflow schema + +## Usage + +``` +/opsx:new +``` + +Example: +``` +/opsx:new context-dynamic-selection-enhancement +``` + +## Next Steps + +After creating the change, use: +- `/opsx:ff` - Fast-forward to generate all planning docs (proposal, specs, design, tasks) +- `/opsx:apply` - Start implementation based on tasks.md +- `/opsx:archive` - Archive completed change + +## Related Commands + +- `/opsx:list` - List all active changes +- `/opsx:validate` - Validate change completeness +- `/opsx:show` - Display change details diff --git a/.qoder/commands/opsx-show.md b/.qoder/commands/opsx-show.md new file mode 100644 index 000000000..de94fa77e --- /dev/null +++ b/.qoder/commands/opsx-show.md @@ -0,0 +1,122 @@ +--- +description: Show details of an OpenSpec change or spec +usage: /opsx:show +aliases: [/opsx:view] +--- + +# /opsx:show - Display Change Details + +Displays detailed information about a specific change or specification. + +## What This Does + +- Shows complete content of change artifacts +- Displays proposal, design, specs, and tasks +- Provides formatted markdown output +- Can show individual artifacts or entire change + +## Usage + +### Show Entire Change + +``` +/opsx:show +``` + +Example: +``` +/opsx:show context-dynamic-selection-enhancement +``` + +Output: +``` +## Change: context-dynamic-selection-enhancement +Status: In Progress (23/47 tasks) +Created: 2026-02-26 + +=== proposal.md === +[Full content of proposal.md] + +=== design.md === +[Full content of design.md] + +=== specs/ === +- context-strategies/spec.md +- tool-visibility-filters/spec.md +- skills-filter-api/spec.md +- skill-recommender/spec.md + +=== tasks.md === +[Task list with completion status] +``` + +### Show Specific Artifact + +``` +/opsx:show / +``` + +Examples: +``` +/opsx:show context-dynamic-selection-enhancement/proposal +/opsx:show context-dynamic-selection-enhancement/design +/opsx:show context-dynamic-selection-enhancement/tasks +/opsx:show context-dynamic-selection-enhancement/specs/context-strategies +``` + +### Show Spec + +``` +/opsx:show spec/ +``` + +Example: +``` +/opsx:show spec/agent-context-builder +``` + +## Use Cases + +### Review Before Implementation + +```bash +/opsx:list # See all changes +/opsx:show # Read full context +/opsx:apply # Start implementation +``` + +### Check Task Progress + +```bash +/opsx:show /tasks # View task checklist +``` + +### Reference Specific Spec + +```bash +/opsx:show /specs/skills-filter-api # Read API spec +``` + +## Output Formatting + +The command displays: +- **Metadata**: Status, creation date, last modified +- **Artifacts**: Full markdown content with proper formatting +- **Progress**: Task completion percentage +- **Dependencies**: Links between artifacts + +## Integration with Other Commands + +```bash +/opsx:new # Create change +/opsx:ff # Generate docs +/opsx:show # ← Review generated docs +/opsx:validate --changes # Verify quality +/opsx:apply # Implement +``` + +## Related Commands + +- `/opsx:list` - List all changes +- `/opsx:validate` - Validate completeness +- `/opsx:apply` - Start implementation diff --git a/.qoder/commands/opsx-validate.md b/.qoder/commands/opsx-validate.md new file mode 100644 index 000000000..2ba350080 --- /dev/null +++ b/.qoder/commands/opsx-validate.md @@ -0,0 +1,106 @@ +--- +description: Validate OpenSpec change completeness +usage: /opsx:validate [change-name] +--- + +# /opsx:validate - Validate Change + +Validates that a change has all required artifacts and they meet quality standards. + +## What This Does + +- Checks for required artifacts (proposal, specs, design, tasks) +- Validates artifact structure and content +- Verifies task completion status +- Reports missing or incomplete items +- Ensures spec-driven schema compliance + +## Usage + +``` +/opsx:validate [change-name] +``` + +If change-name is omitted, validates the most recently modified change. + +Example: +``` +/opsx:validate context-dynamic-selection-enhancement +/opsx:validate --changes api-rate-limiting +``` + +## Validation Checks + +### Required Artifacts +- ✅ proposal.md exists and contains: Why, What Changes, Capabilities, Impact +- ✅ specs/*.md exists with proper requirement/scenario structure +- ✅ design.md exists with Context, Decisions, Risks sections +- ✅ tasks.md exists with properly formatted checkboxes + +### Quality Checks +- ✅ All requirements have at least one scenario +- ✅ Scenarios use WHEN/THEN format +- ✅ Tasks are dependency-sorted +- ✅ No breaking changes without migration plan + +### Completeness (during implementation) +- ✅ Task completion percentage +- ✅ Unchecked tasks remaining +- ✅ Test coverage for completed tasks + +## Example Output + +Success: +``` +✓ change/context-dynamic-selection-enhancement + ✓ proposal.md (complete) + ✓ specs/ (4 capabilities) + ✓ design.md (complete) + ✓ tasks.md (23/47 tasks complete) +Totals: 1 passed (1 items) +``` + +Failure: +``` +✗ change/api-rate-limiting + ✗ proposal.md missing Capabilities section + ✗ specs/ empty +Totals: 0 passed, 1 failed (1 items) +``` + +## When to Validate + +**Before starting implementation:** +```bash +/opsx:new +/opsx:ff +/opsx:validate # ← Ensure planning docs are complete +``` + +**During implementation:** +```bash +/opsx:apply +# ... complete some tasks ... +/opsx:validate # ← Check progress and quality +``` + +**Before archiving:** +```bash +# ... all tasks complete ... +/opsx:validate # ← Final validation required +/opsx:archive +``` + +## Fixing Validation Errors + +If validation fails: +1. Read the error message carefully +2. Use `/openspec instructions --change ` to regenerate +3. Manually edit to fix structural issues +4. Re-run validation + +## Related Commands + +- `/opsx:ff` - Generate planning docs +- `/opsx:list` - See all changes +- `/opsx:archive` - Archive after validation passes diff --git a/.qoder/commands/opsx.md b/.qoder/commands/opsx.md new file mode 100644 index 000000000..5867e8dd1 --- /dev/null +++ b/.qoder/commands/opsx.md @@ -0,0 +1,110 @@ +--- +description: OpenSpec spec-driven development workflow +usage: /opsx: [args] +aliases: [/openspec] +--- + +# OpenSpec Slash Commands + +OpenSpec provides a spec-driven development workflow for AI-assisted coding. + +## Available Commands + +### Core Workflow + +| Command | Description | Example | +|---------|-------------|---------| +| `/opsx:new` | Create new change | `/opsx:new feature-name` | +| `/opsx:ff` | Fast-forward generate all docs | `/opsx:ff` | +| `/opsx:apply` | Implement tasks from tasks.md | `/opsx:apply change-name` | +| `/opsx:archive` | Archive completed change | `/opsx:archive change-name` | + +### Management + +| Command | Description | Example | +|---------|-------------|---------| +| `/opsx:list` | List all changes | `/opsx:list` | +| `/opsx:show` | Display change details | `/opsx:show change-name` | +| `/opsx:validate` | Validate completeness | `/opsx:validate change-name` | + +## Quick Start + +```bash +# 1. Create a new change +/opsx:new my-feature + +# 2. Generate all planning documents +/opsx:ff + +# 3. Review generated docs +/opsx:show my-feature + +# 4. Validate quality +/opsx:validate my-feature + +# 5. Start implementation +/opsx:apply my-feature + +# 6. After completion, archive +/opsx:archive my-feature +``` + +## Workflow Overview + +``` +┌─────────────┐ ┌──────────────┐ ┌─────────────┐ ┌──────────────┐ +│ /opsx:new │ ──→ │ /opsx:ff │ ──→ │ /opsx:apply │ ──→ │ /opsx:archive│ +│ Create │ │ Generate │ │ Implement │ │ Complete │ +│ Change │ │ Docs │ │ Tasks │ │ & Merge │ +└─────────────┘ └──────────────┘ └─────────────┘ └──────────────┘ +``` + +## File Structure + +Changes are stored in: +``` +openspec/changes/ +├── my-feature/ +│ ├── .openspec.yaml # Metadata +│ ├── proposal.md # Why, What, Capabilities +│ ├── design.md # Technical decisions +│ ├── specs/ # Detailed specifications +│ │ ├── capability-1/ +│ │ └── capability-2/ +│ └── tasks.md # Implementation checklist +└── archive/ # Completed changes +``` + +## Best Practices + +✅ **Do**: +- Always start with `/opsx:new` for significant features +- Use `/opsx:ff` to generate comprehensive planning docs +- Reference specs during implementation +- Update tasks.md as you complete each task +- Run `/opsx:validate` before archiving + +❌ **Don't**: +- Skip the planning phase (defeats the purpose) +- Modify tasks.md structure (breaks parsing) +- Archive incomplete changes +- Ignore validation errors + +## Configuration + +OpenSpec is configured via: +- Global commands: `~/.qoder/commands/opsx*.md` +- Project config: `openspec/` directory +- CLI tool: `openspec` (installed via npm) + +## Learn More + +- Full documentation: `openspec --help` +- Supported tools: See OpenSpec README.md +- Schema reference: See openspec/schemas/ + +## Related Resources + +- [OpenSpec GitHub](https://github.com/Fission-AI/OpenSpec) +- [Spec Kit Comparison](https://github.com/Fission-AI/OpenSpec#why-openspec) +- [Workflow Schemas](docs/workflows.md) diff --git a/.qoder/commands/opsx/apply.md b/.qoder/commands/opsx/apply.md new file mode 100644 index 000000000..e385b1e2f --- /dev/null +++ b/.qoder/commands/opsx/apply.md @@ -0,0 +1,152 @@ +--- +name: OPSX: Apply +description: Implement tasks from an OpenSpec change (Experimental) +category: Workflow +tags: [workflow, artifacts, experimental] +--- + +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! You can archive this change with `/opsx:archive`. +``` + +**Output On Pause (Issue Encountered)** + +``` +## Implementation Paused + +**Change:** +**Schema:** +**Progress:** 4/7 tasks complete + +### Issue Encountered + + +**Options:** +1.