autosnippet 3.2.3 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +2 -4
  2. package/bin/cli.js +164 -145
  3. package/config/constitution.yaml +3 -0
  4. package/dashboard/dist/assets/{index-DNOHYBhy.css → index-BaGY7kJI.css} +1 -1
  5. package/dashboard/dist/assets/{index-6itPuGFl.js → index-DfHY_3ln.js} +25 -25
  6. package/dashboard/dist/index.html +2 -2
  7. package/lib/cli/CliLogger.js +78 -0
  8. package/lib/cli/SetupService.js +9 -719
  9. package/lib/cli/UpgradeService.js +23 -398
  10. package/lib/cli/deploy/FileDeployer.js +562 -0
  11. package/lib/cli/deploy/FileManifest.js +272 -0
  12. package/lib/external/mcp/McpServer.js +22 -26
  13. package/lib/external/mcp/autoApproveInjector.js +1 -0
  14. package/lib/external/mcp/handlers/bootstrap/BootstrapSession.js +5 -5
  15. package/lib/external/mcp/handlers/bootstrap/pipeline/EpisodicMemory.js +25 -3
  16. package/lib/external/mcp/handlers/bootstrap/pipeline/IncrementalBootstrap.js +6 -6
  17. package/lib/external/mcp/handlers/bootstrap/pipeline/ToolResultCache.js +4 -0
  18. package/lib/external/mcp/handlers/bootstrap/pipeline/dimension-configs.js +5 -5
  19. package/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +89 -44
  20. package/lib/external/mcp/handlers/consolidated.js +8 -9
  21. package/lib/external/mcp/handlers/dimension-complete-external.js +4 -4
  22. package/lib/external/mcp/handlers/guard.js +283 -5
  23. package/lib/external/mcp/handlers/task.js +183 -9
  24. package/lib/external/mcp/tools.js +32 -81
  25. package/lib/http/routes/task.js +55 -0
  26. package/lib/service/chat/AnalystAgent.js +12 -12
  27. package/lib/service/chat/ChatAgent.js +227 -545
  28. package/lib/service/chat/ChatAgentPrompts.js +9 -11
  29. package/lib/service/chat/ContextWindow.js +2 -296
  30. package/lib/service/chat/EpisodicConsolidator.js +15 -15
  31. package/lib/service/chat/ExplorationTracker.js +1262 -0
  32. package/lib/service/chat/HandoffProtocol.js +8 -9
  33. package/lib/service/chat/Memory.js +4 -0
  34. package/lib/service/chat/ProducerAgent.js +9 -6
  35. package/lib/service/chat/ProjectSemanticMemory.js +4 -0
  36. package/lib/service/chat/ReasoningTrace.js +182 -0
  37. package/lib/service/chat/WorkingMemory.js +4 -0
  38. package/lib/service/chat/memory/ActiveContext.js +910 -0
  39. package/lib/service/chat/memory/MemoryCoordinator.js +662 -0
  40. package/lib/service/chat/memory/PersistentMemory.js +450 -0
  41. package/lib/service/chat/memory/SessionStore.js +896 -0
  42. package/lib/service/chat/memory/index.js +13 -0
  43. package/lib/service/chat/tools/ast-graph.js +17 -16
  44. package/lib/service/cursor/AgentInstructionsGenerator.js +75 -40
  45. package/lib/service/cursor/FileProtection.js +4 -1
  46. package/lib/service/guard/GuardCheckEngine.js +10 -3
  47. package/lib/service/task/TaskGraphService.js +3 -3
  48. package/lib/shared/LanguageService.js +2 -1
  49. package/package.json +1 -1
  50. package/skills/autosnippet-intent/SKILL.md +1 -3
  51. package/skills/autosnippet-recipes/SKILL.md +1 -3
  52. package/templates/claude-code/commands/prime.md +19 -0
  53. package/templates/claude-code/hooks/autosnippet-session.sh +63 -0
  54. package/templates/claude-code/settings.json +21 -0
  55. package/templates/copilot-instructions.md +66 -177
  56. package/templates/cursor-hooks/commands/prime.md +12 -0
  57. package/templates/cursor-hooks/hooks/session-start.sh +10 -0
  58. package/templates/cursor-hooks/hooks.json +11 -0
  59. package/templates/cursor-rules/autosnippet-conventions.mdc +52 -3
  60. package/templates/cursor-rules/autosnippet-workflow.mdc +51 -27
  61. package/lib/external/mcp/handlers/decide.js +0 -109
  62. package/lib/external/mcp/handlers/ready.js +0 -42
  63. package/lib/service/chat/ReasoningLayer.js +0 -888
  64. package/templates/claude-hooks.yaml +0 -19
@@ -1,177 +1,66 @@
1
- <!-- On every human message, call autosnippet_ready() as your first action. No exceptions. -->
2
- <!-- On any explicit user agreement/disagreement about a plan/decision, call autosnippet_decide(...) immediately to persist team memory. -->
3
-
4
- # AutoSnippet Copilot Instructions
5
-
6
- > Every time you receive a message from the user, your **first action** must be:
7
- >
8
- > ```
9
- > autosnippet_ready()
10
- > ```
11
- >
12
- > This applies to every message — questions, follow-ups, confirmations, one-word replies, all of them.
13
- > The call loads live project context; without it your answers will be based on outdated information.
14
- >
15
- > When the user explicitly agrees/disagrees with a方案/约定, your **immediate action** must be:
16
- >
17
- > ```
18
- > autosnippet_decide({ operation: "record" | "revise" | "unpin", ... })
19
- > ```
20
- >
21
- > Persist the decision first, then continue execution.
22
-
23
- ---
24
-
25
- ## 项目概览
26
- - 项目名称:AutoSnippet
27
- - 版本:V3(ESM, SQLite, MCP 11 工具 — 整合版)
28
- - 目标:通过 Recipe 知识库、Guard 规则检查、语义检索构建团队知识管理与代码复用工作流。
29
- - 项目根:包含 `boxspec.json` 的目录。
30
-
31
- ## 知识库与结构
32
- - 知识库根目录:`AutoSnippet/`(用户项目可通过 boxspec `knowledgeBase.dir` 自定义)
33
- - Recipe:`AutoSnippet/recipes/*.md`(Markdown + Frontmatter + Snippet + Usage Guide)
34
- - **Project Skills**:`AutoSnippet/skills/<name>/SKILL.md`(项目级 AI 知识增强文档,跟随 Git)
35
- - constitution.yaml:`AutoSnippet/constitution.yaml`(权限宪法:角色 + 能力 + 治理规则)
36
- - 运行时 DB:`.autosnippet/autosnippet.db`(SQLite,recipes/candidates/snippets 索引缓存)
37
- - 向量索引:`.autosnippet/context/`(`asd embed` 生成)
38
- - Recipe 统计:`.autosnippet/recipe-stats.json`
39
-
40
- ## 知识三分类(kind)
41
- 知识库中的 Recipe kind 分为三类:
42
- - **rule** Guard 规则(boundary-constraint),用于代码质量检查
43
- - **pattern** 可复用代码模式(code-pattern, architecture, best-practice 等)
44
- - **fact** 结构性知识(code-relation, inheritance, call-chain, data-flow 等)
45
-
46
- ## 强制规则(必须遵守)
47
- 1. **每次收到用户消息,第一步调 `autosnippet_ready()`** — 加载最新决策和任务上下文,跳过会导致回答与团队约定矛盾。
48
- 2. **当用户明确同意/否决某方案时,立即调用 `autosnippet_decide` 持久化**(record/revise/unpin)— 先写入团队记忆,再继续后续动作。
49
- 3. **禁止直接修改** 知识库目录内容(`AutoSnippet/recipes/`、`.autosnippet/` 等)。
50
- 4. 创建或入库必须走 **Dashboard** 或 MCP 工具流程(`autosnippet_submit_knowledge`、`autosnippet_submit_knowledge_batch`)。
51
- 5. **优先使用 Recipe** 作为项目标准;源代码仅作补充。
52
- 6. MCP 检索优先:使用 `autosnippet_search`(默认 auto 融合模式,也可指定 mode=context 做上下文感知检索)。
53
- 7. MCP 调用失败时,**不要在同一轮重复重试**,回退到已读文档或静态上下文。
54
- 8. Skills 负责语义与流程,MCP 负责能力与调用;不要在 Skill 内硬编码 URL/HTTP。
55
-
56
- ## MCP 工具速查(20 个整合工具)
57
-
58
- ### 检索
59
- - `autosnippet_search` — 统合搜索入口(通过 `mode` 参数切换)
60
- - `mode=auto`(默认)— BM25 + 语义融合去重
61
- - `mode=context` 智能上下文检索(4 层漏斗 + 会话连续性),支持 `sessionHistory`/`language`
62
- - `mode=keyword` — SQL LIKE 精确关键词
63
- - `mode=semantic` — 向量语义搜索
64
-
65
- ### 知识浏览
66
- - `autosnippet_knowledge` 统一知识访问入口(通过 `operation` 参数切换)
67
- - `operation=list` — 列出 Recipe/Rule/Pattern/Fact(支持 `kind`/`language`/`category`/`status` 多条件过滤)
68
- - `operation=get` — 按 ID 获取单个 Recipe 详情
69
- - `operation=insights` — 获取 Recipe 质量洞察(分数/统计/关系)
70
- - `operation=confirm_usage` — 确认 Recipe 被采纳/应用
71
-
72
- ### 项目结构
73
- - `autosnippet_structure` — SPM Target 结构发现(`operation`: targets / files / metadata)
74
-
75
- ### 知识图谱
76
- - `autosnippet_graph` — 图谱查询(`operation`: query / impact / path / stats)
77
-
78
- ### 候选提交
79
- - `autosnippet_submit_knowledge` — 单条提交(严格前置校验,缺少必要字段直接拒绝不入库。必填: title, language, content(+rationale), kind, doClause, dontClause, whenClause, coreCode, category, trigger, description, headers, usageGuide, knowledgeType, reasoning(+whyStandard+sources+confidence)。所有字段必须在单次调用中一次性提供)
80
- - `autosnippet_submit_knowledge_batch` — 批量提交(含去重 + 限流 + 逐条严格校验,缺字段的条目被拒绝)
81
-
82
- ### 开发文档
83
- - `autosnippet_save_document` — 保存开发文档(title + markdown,自动发布)
84
-
85
- ### Guard
86
- - `autosnippet_guard` — 代码规范检查(传 `code` 单文件 / 传 `files[]` 批量审计,自动路由)
87
-
88
- ### Skills
89
- - `autosnippet_skill` — Skill 管理(`operation`: list / load / create / update / delete / suggest)
90
-
91
- ### 冷启动 & 扫描
92
- - `autosnippet_bootstrap` — 冷启动 Mission Briefing(无参数,返回项目分析 + 维度任务清单)
93
- - `autosnippet_dimension_complete` — 维度分析完成通知(dimensionId + analysisText 必填)
94
-
95
- ### Wiki 文档
96
- - `autosnippet_wiki_plan` — Wiki 文档规划(扫描项目生成主题数据包)
97
- - `autosnippet_wiki_finalize` — Wiki 完成(meta.json + 去重 + 验证)
98
-
99
- ### 任务管理
100
- - `autosnippet_ready` — **每次收到用户消息第一步调用**:加载活跃决策、就绪任务、知识上下文
101
- - `autosnippet_decide` — 决策管理:record / revise / unpin / list(**用户明确同意/否决方案时立即调用并先持久化**)
102
- - `autosnippet_task` — 任务 CRUD:create / claim / close / fail / defer / progress / decompose / dep_add 等
103
- - `asd` — VS Code Agent Mode 专用通道(`#asd` 引用激活,代理所有操作)
104
-
105
- ### 系统
106
- - `autosnippet_health` — 服务健康状态与知识库统计(可检测空 KB 触发冷启动)
107
- - `autosnippet_capabilities` — 服务能力清单(列出所有可用 MCP 工具,供 Agent 自发现)
108
-
109
- ### 管理员工具(Admin Tier)
110
- - `autosnippet_enrich_candidates` — 候选字段完整性诊断(不使用 AI)
111
- - `autosnippet_knowledge_lifecycle` — 知识条目生命周期操作(publish/deprecate/reactivate 等)
112
- - `autosnippet_validate_candidate` — 候选结构化预校验(调试用)
113
- - `autosnippet_check_duplicate` — 相似度检测(调试用)
114
-
115
- ## Recipe 结构要点
116
- - 必须包含:Frontmatter(`title`、`trigger` 必填)+ `## Snippet / Code Reference` + `## AI Context / Usage Guide`。
117
- - Frontmatter 必填字段(7):`title`、`trigger`(@开头)、`category`(8 选 1)、`language`、`summary_cn`、`summary_en`、`headers`。
118
- - Usage Guide 必须用 `###` 三级标题分段,列表式书写,禁止一行文字墙。
119
-
120
- ## Project Skills
121
- - **发现**:`autosnippet_skill` — `operation=list` 列出所有可用 Skills(内置 + 项目级)
122
- - **加载**:`autosnippet_skill` — `operation=load, name=<skillName>` 获取 Skill 完整操作指南
123
- - **创建**:`autosnippet_skill` — `operation=create, name, description, content` 创建项目级 Skill
124
- - **推荐**:`autosnippet_skill` — `operation=suggest` 基于使用模式推荐创建 Skill
125
- - **Bootstrap 自动生成**:冷启动 Phase 5.5 自动生成 4 个 Project Skills(code-standard, architecture, project-profile, agent-guidelines)
126
- - **优先级**:项目级 Skill 同名覆盖内置;宏观知识查 Skill,微观代码模式查 Recipe
127
-
128
- ## 冷启动必读(首次使用必看)
129
-
130
- 执行冷启动前,**必须**先加载 Skill 获取完整指引:
131
- ```
132
- autosnippet_skill({ operation: "load", name: "autosnippet-coldstart" })
133
- ```
134
- Skill 包含:完整的 V3 字段格式、JSON 示例模板、维度分析策略。
135
- **不加载 Skill 直接提交知识会因字段格式问题被反复拒绝。**
136
-
137
- ## Guard 诊断响应
138
-
139
- 当编辑器出现来自 "AutoSnippet Guard" 的诊断(黄色/红色波浪线)时:
140
- 1. 读取诊断消息中的 `ruleId`
141
- 2. 调用 `autosnippet_search(query: ruleId)` 查找对应 Recipe
142
- 3. 按 Recipe 的 `doClause` + `coreCode` 修复代码
143
- 4. 保存文件并确认诊断消失
144
-
145
- 灯泡菜单中可快捷搜索知识库或禁用该行检查。
146
-
147
- ## 决策与任务管理(VS Code Agent Mode)
148
-
149
- 在 VS Code Agent Mode 中,输入 `#asd` 后跟消息即可激活项目记忆。
150
- 工具会自动加载项目决策和任务,Agent 应遵守所有返回的决策。
151
-
152
- - `_decisions` / `_activeDecisions` — 必须遵守的团队决策
153
- - `_decisionHint` — 决策行为提示
154
- - 用户同意或否决某方案时,使用 `autosnippet_decide({ operation: "record" })` 记录
155
-
156
- ### V3 字段格式关键提醒
157
- - `content` **必须是 JSON 对象**(不是字符串):`{ "pattern": "代码...", "markdown": "## 标题\n正文...", "rationale": "设计原理" }`
158
- - `reasoning` **必须是 JSON 对象**:`{ "whyStandard": "原因", "sources": ["file.ts"], "confidence": 0.85 }`
159
- - `headers` **必须是数组**:`["import Foundation"]`,无 import 时传 `[]`
160
- - 所有 15 个必填字段必须在**单次调用中一次性提供**,缺字段直接拒绝
161
-
162
- ## 推荐工作流
163
- 1. **收到消息后第一步**:`autosnippet_ready()` — 加载决策 + 任务上下文(**每次都要,不可跳过**)
164
- 2. **用户同意/否决方案时第一步**:`autosnippet_decide({ operation: "record" | "revise" | "unpin" })` — 先持久化决策再执行。
165
- 3. **查找**:`autosnippet_search`(推荐 mode=auto)或 mode=context(上下文感知)。
166
- - **产出候选**:`autosnippet_submit_knowledge` 提交(严格前置校验,必须一次性提供所有必填字段,缺字段直接拒绝不入库)。
167
- - **冷启动**:`autosnippet_bootstrap`(无参数)→ 逐维度分析代码 → `autosnippet_submit_knowledge_batch` → `autosnippet_dimension_complete`。
168
- - **Skills 创建**:`autosnippet_skill` op=suggest 分析 → `autosnippet_skill` op=create 固化知识。
169
- - **采纳反馈**:`autosnippet_knowledge` op=confirm_usage(记录使用量影响排序权重)。
170
-
171
- ## 与 Cursor 规则联动
172
- - 本文件与 `templates/cursor-rules/autosnippet-conventions.mdc` 保持一致。
173
- - 如有冲突,以 **禁止修改 Knowledge** 与 **Recipe 优先** 原则为准。
174
-
175
- ---
176
- <!-- REMINDER: If you have not yet called autosnippet_ready(), do it now before responding. -->
177
- <!-- REMINDER: If user has explicitly agreed/disagreed with a plan, call autosnippet_decide(...) before continuing. -->
1
+ <!-- autosnippet:begin -->
2
+ <!-- MANDATORY: On EVERY human message, call autosnippet_task({ operation: "prime" }) FIRST. -->
3
+
4
+ # {{projectName}} — AutoSnippet 项目指引
5
+
6
+ ## CRITICAL: You Operate autosnippet_task The User Doesn't
7
+
8
+ You are the task operator. Users speak naturally; you translate to task operations.
9
+ DO NOT tell users to call autosnippet_task. That's YOUR job.
10
+
11
+ - WRONG: "你可以调用 autosnippet_task({ operation: 'create' }) 来创建任务"
12
+ - RIGHT: *(你自己调用 create,然后告诉用户 "已创建任务 asd-42: 修复登录 bug")*
13
+
14
+ ## Task Tracking Rules (MANDATORY)
15
+
16
+ 1. **MUST prime on EVERY message** — `autosnippet_task({ operation: "prime" })` BEFORE doing anything else. No exceptions.
17
+ 2. **MUST create a task for non-trivial work** — If work involves ≥2 files OR ≥10 lines, create BEFORE starting.
18
+ 3. **MUST claim before coding** — `autosnippet_task({ operation: "claim", id })` then code.
19
+ 4. **MUST close when done** — `autosnippet_task({ operation: "close", id, reason })` with meaningful reason.
20
+ 5. **MUST handle unfinished tasks first** — If prime returns in-progress tasks, ask user: Continue, Defer, or Abandon? Do NOT auto-resume.
21
+ 6. **NEVER skip prime** Even for follow-up messages.
22
+ 7. **NEVER start new work with open in-progress tasks** — Handle existing first.
23
+ 8. **NEVER leave tasks in in_progress when session ends** — Close or defer everything.
24
+ 9. **NEVER tell the user to run task commands** — You are the operator.
25
+
26
+ When in doubt → create a task. When idle → `autosnippet_task({ operation: "ready" })`.
27
+
28
+ ### When NOT to Create Tasks
29
+
30
+ Quick questions, single-file trivial fixes (<10 lines), code explanation, running existing tests.
31
+ Rule: <2min AND ≤1 file AND <10 lines → no task. Everything else → create.
32
+
33
+ ## User Says You Run
34
+
35
+ | User Says | Your Action |
36
+ |---|---|
37
+ | "帮我修 bug" / "fix this" | `create` → `claim` → code → `close` |
38
+ | "做功能" / "implement" | `create` → `claim` → code → `close` |
39
+ | "继续" / "continue" | resume in-progress task → code → `close` |
40
+ | "先不做了" / "pause" | `defer(id, reason)` |
41
+ | "不做了" / "abandon" | `fail(id, reason)` |
42
+ | "太大了" / "break down" | `decompose(id, subtasks)` |
43
+ | "有什么要做的" / "what's next" | `ready()` → present |
44
+ | "就这么定了" / "agreed" | `record_decision(...)` |
45
+ | Quick question | No task. Just answer. |
46
+
47
+ ## Session Closing Protocol
48
+
49
+ Before ending work, you MUST complete this checklist:
50
+
51
+ - [ ] Close every claimed task: `autosnippet_task({ operation: "close", id, reason: "what was accomplished" })`
52
+ - [ ] Defer any incomplete task: `autosnippet_task({ operation: "defer", id, reason: "why and what remains" })`
53
+ - [ ] Verify: zero tasks in in_progress state
54
+ - [ ] If prime showed ready tasks, mention them to the user for next session
55
+
56
+ **Work is not done until all tasks are closed or deferred.**
57
+
58
+ ## Knowledge Rules
59
+
60
+ - **禁止直接修改** `AutoSnippet/recipes/`、`.autosnippet/` 等知识库目录
61
+ - **优先使用 Recipe**;搜索用 `autosnippet_search`
62
+ - MCP 调用失败时**不要重试**,回退到已有上下文
63
+
64
+ <!-- autosnippet:end -->
65
+ <!-- REMINDER: If you have not yet called autosnippet_task({ operation: "prime" }), do it NOW. -->
66
+ <!-- REMINDER: If user agreed/disagreed with a plan → autosnippet_task({ operation: "record_decision" | "revise_decision" | "unpin_decision" }) immediately. -->
@@ -0,0 +1,12 @@
1
+ # Prime AutoSnippet Context
2
+
3
+ Call `autosnippet_task` with `{ "operation": "prime" }` to load the current project context.
4
+
5
+ **You MUST call this on EVERY user message BEFORE doing anything else. No exceptions.**
6
+
7
+ This returns active decisions (team agreements), ready tasks, in-progress tasks, task rules reminder, and project stats.
8
+
9
+ If there are unfinished tasks, present them to the user and ask: **Continue**, **Defer**, or **Abandon**? Do NOT auto-resume.
10
+
11
+ Prime is automatically reminded on session start via hooks.
12
+ Call again after compaction or when `_contextHint` shows `CONTEXT_PRESSURE:CRITICAL`.
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ # AutoSnippet sessionStart hook — task behavioral rules + prime reminder
3
+ # No HTTP calls, no python3, no external dependencies.
4
+ # Injects task tracking rules into the AI's context on every session start.
5
+
6
+ cat <<'EOF'
7
+ {
8
+ "additional_context": "[AutoSnippet Task Rules]\n\n⚡ FIRST: Call autosnippet_task({ \"operation\": \"prime\" }) on EVERY message. No exceptions.\n\n� CRITICAL: YOU Operate autosnippet_task — The User Doesn't\n• WRONG: \"You can run autosnippet_task to create a task\"\n• RIGHT: (you run create yourself and tell the user \"Created task asd-42\")\n\n📋 MUST:\n• Create task for non-trivial work (≥2 files OR ≥10 lines) BEFORE starting\n• Claim before coding, close when done with meaningful reason\n• Handle unfinished tasks first (ask user: Continue/Defer/Abandon)\n• Close or defer ALL in_progress tasks before session ends\n\n🚫 NEVER:\n• Skip prime\n• Start new work with open in_progress tasks\n• Tell user to run task commands (YOU are the operator)\n• Leave tasks in in_progress when session ends\n\n📖 User Says → You Run:\n• \"fix bug\" / \"implement\" → create → claim → code → close\n• \"continue\" → resume in-progress → code → close\n• \"pause\" → defer(id, reason)\n• \"abandon\" → fail(id, reason)\n• \"break down\" → decompose(id, subtasks)\n• \"what's next\" → ready()\n• \"agreed\" → record_decision(...)\n• Quick question → No task. Just answer.\n\n💡 When in doubt → create a task. When idle → autosnippet_task({ operation: \"ready\" })\n\n📌 User agrees/disagrees with plan → autosnippet_task({ operation: \"record_decision\" }) immediately\n\n✅ Session end checklist: close all tasks → defer incomplete → verify zero in_progress"
9
+ }
10
+ EOF
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": 1,
3
+ "hooks": {
4
+ "sessionStart": [
5
+ {
6
+ "command": ".cursor/hooks/session-start.sh",
7
+ "timeout": 5
8
+ }
9
+ ]
10
+ }
11
+ }
@@ -11,14 +11,63 @@ These rules are written when installing AutoSnippet Skills (`asd install:cursor-
11
11
 
12
12
  ## 强制规则(必须遵守)
13
13
 
14
- 1. **每次收到用户消息,第一步调 `autosnippet_ready()`** — 加载最新决策和任务上下文,跳过会导致回答与团队约定矛盾。
15
- 2. **当用户明确同意/否决某方案时,立即调用 `autosnippet_decide` 持久化**(record/revise/unpin)— 先写入团队记忆,再继续后续动作。
14
+ 1. **每次收到用户消息,第一步调 `autosnippet_task({ operation: "prime" })`** — 加载最新决策和任务上下文,跳过会导致回答与团队约定矛盾。
15
+ 2. **当用户明确同意/否决某方案时,立即调用 `autosnippet_task({ operation: "record_decision" })` 持久化**(record_decision/revise_decision/unpin_decision)— 先写入团队记忆,再继续后续动作。
16
16
  3. **禁止直接修改** 知识库目录内容(`AutoSnippet/recipes/`、`.autosnippet/` 等)。
17
17
  4. **优先使用 Recipe** 作为项目标准;源代码仅作补充。
18
18
  5. MCP 检索优先:使用 `autosnippet_search`(auto 融合模式)。
19
19
  6. MCP 调用失败时,**不要在同一轮重复重试**,回退到已读文档或静态上下文。
20
20
  7. Skills 负责语义与流程,MCP 负责能力与调用;不要在 Skill 内硬编码 URL/HTTP。
21
21
 
22
+ ## CRITICAL: You Operate autosnippet_task — The User Doesn't
23
+
24
+ You are the task operator. Users speak naturally; you translate to task operations.
25
+ DO NOT tell users to call autosnippet_task. That's YOUR job.
26
+
27
+ - WRONG: "你可以调用 autosnippet_task({ operation: 'create' }) 来创建任务"
28
+ - RIGHT: *(你自己调用 create,然后告诉用户 "已创建任务 asd-42: 修复登录 bug")*
29
+
30
+ ## Task Tracking Rules (MANDATORY)
31
+
32
+ 1. **MUST prime on EVERY message** — No exceptions. Even follow-up messages.
33
+ 2. **MUST create task for non-trivial work** — ≥2 files OR ≥10 lines → create BEFORE starting.
34
+ 3. **MUST claim before coding** — `claim(id)` then code.
35
+ 4. **MUST close when done** — `close(id, reason)` with meaningful reason.
36
+ 5. **MUST handle unfinished tasks first** — prime shows in-progress → ask user: Continue, Defer, Abandon? Do NOT auto-resume.
37
+ 6. **NEVER skip prime** — Even for simple questions.
38
+ 7. **NEVER start new work with open in-progress tasks** — Handle existing first.
39
+ 8. **NEVER leave tasks in in_progress when session ends** — Close or defer everything.
40
+ 9. **NEVER tell the user to run task commands** — You are the operator.
41
+
42
+ When in doubt → create a task. When idle → `autosnippet_task({ operation: "ready" })`.
43
+
44
+ **When NOT to create**: Quick questions, single-file trivial fixes (<10 lines), code explanation, running tests. Rule: <2min AND ≤1 file AND <10 lines → no task.
45
+
46
+ ## User Says → You Run
47
+
48
+ | User Says | Your Action |
49
+ |---|---|
50
+ | "帮我修 bug" / "fix this" | `create` → `claim` → code → `close` |
51
+ | "做功能" / "implement" | `create` → `claim` → code → `close` |
52
+ | "继续" / "continue" | resume in-progress → code → `close` |
53
+ | "先不做了" / "pause" | `defer(id, reason)` |
54
+ | "不做了" / "abandon" | `fail(id, reason)` |
55
+ | "太大了" / "break down" | `decompose(id, subtasks)` |
56
+ | "有什么要做的" / "next" | `ready()` → present list |
57
+ | "就这么定了" / "agreed" | `record_decision(...)` |
58
+ | Quick question | No task. Just answer. |
59
+
60
+ ## Session Closing Protocol
61
+
62
+ Before ending work, you MUST complete this checklist:
63
+
64
+ - [ ] Close every claimed task: `close(id, reason)` with what was accomplished
65
+ - [ ] Defer any incomplete task: `defer(id, reason)` with why and what remains
66
+ - [ ] Verify: zero tasks in in_progress state
67
+ - [ ] If prime showed ready tasks, mention them for next session
68
+
69
+ **Work is not done until all tasks are closed or deferred.**
70
+
22
71
  ## Semantics vs capabilities
23
72
 
24
73
  - **Skills provide semantics**: When to use, workflows, and comparisons are described in Skills. Use natural language prompts in Cursor (e.g. "scan targets", "find recipe examples", "batch extract candidates") to trigger the appropriate Skill; AI intelligently interprets your request and activates the corresponding Skill logic.
@@ -50,7 +99,7 @@ Recipes are classified into three kinds:
50
99
  - **Do not edit** `AutoSnippet/recipes/` or `.autosnippet/` directly; all Recipe/Snippet changes go through Dashboard or MCP tools and are saved after human review.
51
100
  - **Search**: Use MCP tools `autosnippet_search` (recommended, auto mode BM25 + semantic fusion) or `autosnippet_context_search` (context-aware with session history). Also available: `autosnippet_keyword_search` (exact match) and `autosnippet_semantic_search` (vector).
52
101
  - **Retry policy**: If an MCP call fails, do not retry within the same agent turn; fall back to static docs or already-read context.
53
- - **Decision persistence**: When the user explicitly agrees/disagrees with a plan, call `autosnippet_decide({ operation: "record" | "revise" | "unpin" })` **immediately** before continuing. Persist first, execute second.
102
+ - **Decision persistence**: When the user explicitly agrees/disagrees with a plan, call `autosnippet_task({ operation: "record_decision" | "revise_decision" | "unpin_decision" })` **immediately** before continuing. Persist first, execute second.
54
103
  - **Adoption tracking**: Tool `autosnippet_confirm_usage` records that a Recipe was adopted or applied (affects usage stats and authority ranking). Show it when the user explicitly adopts a recipe, not immediately after presenting one.
55
104
  - **Batch scan**: Ask Cursor in natural language (e.g. "scan all targets in this project", "batch extract candidates") to trigger the batch-scan workflow. The workflow calls `autosnippet_get_targets` → `autosnippet_get_target_files` → extract per file → `autosnippet_submit_candidates` automatically.
56
105
  - **Cold start**: Use `autosnippet_bootstrap_knowledge` for full project knowledge initialization covering 9 dimensions. Phase 5.5 auto-generates 4 Project Skills (code-standard, architecture, project-profile, agent-guidelines) to `AutoSnippet/skills/`.
@@ -1,52 +1,76 @@
1
1
  ---
2
- description: AutoSnippet TaskGraph & Guard 工作流 — 任务管理 + 诊断闭环
2
+ description: AutoSnippet Task Tracking — 任务管理 + 行为规则
3
3
  alwaysApply: true
4
4
  ---
5
5
 
6
- # AutoSnippet TaskGraph Workflow
6
+ # AutoSnippet Task Workflow
7
7
 
8
- ## 强制首动作
8
+ ## CRITICAL: You Operate autosnippet_task — The User Doesn't
9
9
 
10
- > **每次收到用户消息,第一步调 `autosnippet_ready()`** 加载最新决策和任务上下文。
11
- > 此规则适用于所有消息(问题、追问、确认、单词回复)。跳过会导致回答与决策矛盾。
12
- >
13
- > **当用户明确同意/否决某方案时,立即调 `autosnippet_decide(...)`** — 先持久化团队记忆,再继续执行。
10
+ You are the task operator. Users speak naturally; you translate to task operations.
11
+ DO NOT tell users to call autosnippet_task. That's YOUR job.
14
12
 
15
- ## 任务管理
13
+ ## Task Tracking Rules (MANDATORY)
16
14
 
17
- 1. **每次收到消息** `autosnippet_ready()` 加载决策与就绪任务(**不可跳过**)
18
- 2. **用户同意/否决方案时** `autosnippet_decide({ operation: "record" | "revise" | "unpin" })` 先持久化决策再继续
19
- 3. 编码前 `autosnippet_task({ operation: "claim" })`,完成后 `close`
20
- 4. 遇到错误 `fail`(不要跳过)
21
- 5. 发现新工作`create` + `dep_add(depType: "discovered-from")`
22
- 6. MCP 调用失败 不要在同一轮重复重试
15
+ 1. **MUST prime on EVERY message** — `autosnippet_task({ operation: "prime" })` BEFORE anything else. No exceptions.
16
+ 2. **MUST create task for non-trivial work** ≥2 files OR ≥10 lines → create BEFORE starting.
17
+ 3. **MUST claim before coding** — `claim(id)` then code.
18
+ 4. **MUST close when done** — `close(id, reason)` with meaningful reason.
19
+ 5. **MUST handle unfinished tasks first** — prime shows in-progress ask user: Continue, Defer, Abandon?
20
+ 6. **NEVER skip prime** — Even for follow-up messages.
21
+ 7. **NEVER start new work with open in-progress tasks** — Handle existing first.
22
+ 8. **NEVER leave tasks in in_progress when session ends** — Close or defer everything.
23
+ 9. **NEVER tell the user to run task commands** — You are the operator.
23
24
 
24
- ## Guard 诊断响应
25
+ When in doubt → create a task. When idle → `autosnippet_task({ operation: "ready" })`.
26
+ **When NOT to create**: <2min AND ≤1 file AND <10 lines → no task.
25
27
 
26
- 当编辑器出现 "AutoSnippet Guard" 诊断时:
27
- 1. 读取 ruleId → `autosnippet_search(query: ruleId)`
28
- 2. 按 Recipe 的 doClause + coreCode 修改代码
29
- 3. 保存并确认诊断消失
28
+ ## User Says → You Run
30
29
 
31
- ## 知识搜索
30
+ | User Says | Your Action |
31
+ |---|---|
32
+ | "帮我修 bug" / "fix this" | `create` → `claim` → code → `close` |
33
+ | "做功能" / "implement" | `create` → `claim` → code → `close` |
34
+ | "继续" / "continue" | resume in-progress → code → `close` |
35
+ | "先不做了" / "pause" | `defer(id, reason)` |
36
+ | "不做了" / "abandon" | `fail(id, reason)` |
37
+ | "太大了" / "break down" | `decompose(id, subtasks)` |
38
+ | "有什么要做的" / "next" | `ready()` → present list |
39
+ | "就这么定了" / "agreed" | `record_decision(...)` |
40
+ | Quick question | No task. Just answer. |
32
41
 
33
- 编码前搜索相关知识:`autosnippet_search(query: "相关关键词")`
42
+ ## Decision Persistence
43
+
44
+ **用户同意/否决方案时** → `autosnippet_task({ operation: "record_decision" | "revise_decision" | "unpin_decision" })` 先持久化决策再继续
45
+
46
+ ## Session Closing Protocol
47
+
48
+ Before ending work, you MUST complete this checklist:
49
+
50
+ - [ ] Close every claimed task: `close(id, reason)` with what was accomplished
51
+ - [ ] Defer any incomplete task: `defer(id, reason)` with why and what remains
52
+ - [ ] Verify: zero tasks in in_progress state
53
+ - [ ] If prime showed ready tasks, mention them for next session
54
+
55
+ **Work is not done until all tasks are closed or deferred.**
34
56
 
35
57
  ## 上下文压力
36
58
 
37
59
  - `_contextHint` 包含 `CONTEXT_PRESSURE:WARNING` → 总结已完成工作,继续
38
- - `_contextHint` 包含 `CONTEXT_PRESSURE:CRITICAL` → 立即 `autosnippet_ready()` 恢复上下文
60
+ - `_contextHint` 包含 `CONTEXT_PRESSURE:CRITICAL` → 立即 prime 恢复上下文
39
61
 
40
62
  ## 任务操作速查
41
63
 
42
64
  | 操作 | 用途 |
43
65
  |------|------|
44
- | `autosnippet_ready()` | **每次收到消息第一步调用** — 加载决策 + 就绪任务 + 知识上下文 |
45
- | `autosnippet_decide(record/revise/unpin)` | **用户同意/否决方案时立即调用** — 先持久化再继续 |
66
+ | `autosnippet_task({ operation: "prime" })` | **每次收到消息第一步调用** — 加载决策 + 就绪任务 + 规则提醒 |
67
+ | `autosnippet_task({ operation: "record_decision" / "revise_decision" / "unpin_decision" })` | **用户同意/否决方案时立即调用** — 先持久化再继续 |
68
+ | `create(title)` | 创建新任务 |
46
69
  | `claim(id)` | 开始处理任务 |
47
- | `close(id)` | 完成任务 → 返回 newlyReady |
70
+ | `close(id, reason)` | 完成任务 → 返回 newlyReady |
48
71
  | `fail(id, reason)` | 标记失败 |
49
72
  | `defer(id, reason)` | 延后处理 |
50
73
  | `progress(id, desc)` | 更新进度 |
51
- | `create(title)` | 创建新任务 |
52
- | `ready` | 获取就绪任务(带知识上下文) |
74
+ | `ready` | 获取就绪任务 |
75
+ | `decompose(id, subtasks)` | 拆分大任务 |
76
+ | `stats` | 项目统计 |
@@ -1,109 +0,0 @@
1
- /**
2
- * MCP Handler — autosnippet_decide
3
- *
4
- * 决策管理独立入口。Agent 与用户达成共识时调用。
5
- * 操作:record / revise / unpin / list
6
- */
7
-
8
- import { envelope } from '../envelope.js';
9
-
10
- /**
11
- * @param {object} ctx — { container }
12
- * @param {object} args — { operation, title, description, rationale, tags, relatedTaskId, id, reason }
13
- */
14
- export async function decideHandler(ctx, args) {
15
- const taskService = ctx.container.get('taskGraphService');
16
- const op = args.operation || 'list';
17
-
18
- switch (op) {
19
- case 'record':
20
- return _record(taskService, args);
21
- case 'revise':
22
- return _revise(taskService, args);
23
- case 'unpin':
24
- return _unpin(taskService, args);
25
- case 'list':
26
- return _list(taskService);
27
- default:
28
- return envelope({
29
- success: false,
30
- message: `Unknown decide operation: ${op}. Use: record, revise, unpin, list`,
31
- meta: { tool: 'autosnippet_decide' },
32
- });
33
- }
34
- }
35
-
36
- async function _record(svc, args) {
37
- if (!args.title) {
38
- return envelope({ success: false, message: 'title is required', meta: { tool: 'autosnippet_decide' } });
39
- }
40
- if (!args.description) {
41
- return envelope({ success: false, message: 'description is required', meta: { tool: 'autosnippet_decide' } });
42
- }
43
- const { task, isDuplicate } = await svc.recordDecision({
44
- title: args.title,
45
- description: args.description,
46
- rationale: args.rationale || '',
47
- tags: args.tags || [],
48
- relatedTaskId: args.relatedTaskId || null,
49
- });
50
- return envelope({
51
- success: true,
52
- data: task.toJSON(),
53
- message: isDuplicate
54
- ? `⚠ Decision already recorded: ${task.id}`
55
- : `✅ Decision pinned: ${task.id} — "${args.title}"`,
56
- meta: { tool: 'autosnippet_decide' },
57
- });
58
- }
59
-
60
- async function _revise(svc, args) {
61
- if (!args.id) {
62
- return envelope({ success: false, message: 'id of old decision is required', meta: { tool: 'autosnippet_decide' } });
63
- }
64
- if (!args.title) {
65
- return envelope({ success: false, message: 'title of new decision is required', meta: { tool: 'autosnippet_decide' } });
66
- }
67
- if (!args.description) {
68
- return envelope({ success: false, message: 'description of new decision is required', meta: { tool: 'autosnippet_decide' } });
69
- }
70
- const result = await svc.reviseDecision({
71
- oldDecisionId: args.id,
72
- title: args.title,
73
- description: args.description,
74
- rationale: args.rationale || '',
75
- reason: args.reason || '',
76
- });
77
- return envelope({
78
- success: true,
79
- data: {
80
- newDecision: result.newDecision.toJSON(),
81
- superseded: result.oldDecisionId,
82
- },
83
- message: `✅ Decision revised: ${result.oldDecisionId} → ${result.newDecision.id}`,
84
- meta: { tool: 'autosnippet_decide' },
85
- });
86
- }
87
-
88
- async function _unpin(svc, args) {
89
- if (!args.id) {
90
- return envelope({ success: false, message: 'id is required', meta: { tool: 'autosnippet_decide' } });
91
- }
92
- const task = await svc.unpinDecision(args.id, args.reason || '');
93
- return envelope({
94
- success: true,
95
- data: task.toJSON(),
96
- message: `Decision ${args.id} unpinned and closed`,
97
- meta: { tool: 'autosnippet_decide' },
98
- });
99
- }
100
-
101
- async function _list(svc) {
102
- const decisions = await svc.list({ status: 'pinned', taskType: 'decision' }, { limit: 50 });
103
- return envelope({
104
- success: true,
105
- data: decisions.map(d => d.toJSON()),
106
- message: `${decisions.length} active decision(s)`,
107
- meta: { tool: 'autosnippet_decide' },
108
- });
109
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * MCP Handler — autosnippet_ready
3
- *
4
- * Agent 的首要入口:加载项目上下文 + 就绪任务 + 团队决策。
5
- * 等同于 Beads 的 `bd ready`,但含知识桥接和决策持久化。
6
- *
7
- * 无参数即可调用。Agent 看到工具名就知道"先看看有什么可做的"。
8
- */
9
-
10
- import { envelope } from '../envelope.js';
11
-
12
- /**
13
- * @param {object} ctx — { container }
14
- * @param {object} args — { limit?, withKnowledge? }
15
- */
16
- export async function readyHandler(ctx, args = {}) {
17
- const taskService = ctx.container.get('taskGraphService');
18
- const result = await taskService.prime({
19
- limit: args.limit || 10,
20
- withKnowledge: args.withKnowledge !== false,
21
- });
22
-
23
- const decisionCount = (result.decisions || []).length;
24
- const staleCount = (result.staleDecisions || []).length;
25
- const decisionTitles = (result.decisions || []).map((d) => d.title).join('; ');
26
- const statsLine = `${result.inProgress.length} in-progress, ${result.ready.length} ready, ${result.stats.total} total`;
27
-
28
- let message;
29
- if (decisionCount > 0) {
30
- const stalePart = staleCount > 0 ? ` ${staleCount} stale.` : '';
31
- message = `⚠️ ${decisionCount} ACTIVE DECISION(S): [${decisionTitles}].${stalePart} ${statsLine}.`;
32
- } else {
33
- message = `${statsLine}.`;
34
- }
35
-
36
- return envelope({
37
- success: true,
38
- data: result,
39
- message,
40
- meta: { tool: 'autosnippet_ready' },
41
- });
42
- }