autosnippet 3.2.4 → 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.
- package/README.md +2 -4
- package/bin/cli.js +164 -145
- package/config/constitution.yaml +2 -0
- package/dashboard/dist/assets/{index-DNOHYBhy.css → index-BaGY7kJI.css} +1 -1
- package/dashboard/dist/assets/{index-6itPuGFl.js → index-DfHY_3ln.js} +25 -25
- package/dashboard/dist/index.html +2 -2
- package/lib/cli/CliLogger.js +78 -0
- package/lib/cli/SetupService.js +9 -718
- package/lib/cli/UpgradeService.js +23 -398
- package/lib/cli/deploy/FileDeployer.js +562 -0
- package/lib/cli/deploy/FileManifest.js +272 -0
- package/lib/external/mcp/McpServer.js +22 -26
- package/lib/external/mcp/autoApproveInjector.js +1 -0
- package/lib/external/mcp/handlers/bootstrap/BootstrapSession.js +5 -5
- package/lib/external/mcp/handlers/bootstrap/pipeline/EpisodicMemory.js +25 -3
- package/lib/external/mcp/handlers/bootstrap/pipeline/IncrementalBootstrap.js +6 -6
- package/lib/external/mcp/handlers/bootstrap/pipeline/ToolResultCache.js +4 -0
- package/lib/external/mcp/handlers/bootstrap/pipeline/dimension-configs.js +5 -5
- package/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +89 -44
- package/lib/external/mcp/handlers/consolidated.js +8 -9
- package/lib/external/mcp/handlers/dimension-complete-external.js +4 -4
- package/lib/external/mcp/handlers/guard.js +283 -5
- package/lib/external/mcp/handlers/task.js +183 -9
- package/lib/external/mcp/tools.js +32 -81
- package/lib/http/routes/task.js +55 -0
- package/lib/service/chat/AnalystAgent.js +12 -12
- package/lib/service/chat/ChatAgent.js +227 -545
- package/lib/service/chat/ChatAgentPrompts.js +9 -11
- package/lib/service/chat/ContextWindow.js +2 -296
- package/lib/service/chat/EpisodicConsolidator.js +15 -15
- package/lib/service/chat/ExplorationTracker.js +1262 -0
- package/lib/service/chat/HandoffProtocol.js +8 -9
- package/lib/service/chat/Memory.js +4 -0
- package/lib/service/chat/ProducerAgent.js +9 -6
- package/lib/service/chat/ProjectSemanticMemory.js +4 -0
- package/lib/service/chat/ReasoningTrace.js +182 -0
- package/lib/service/chat/WorkingMemory.js +4 -0
- package/lib/service/chat/memory/ActiveContext.js +910 -0
- package/lib/service/chat/memory/MemoryCoordinator.js +662 -0
- package/lib/service/chat/memory/PersistentMemory.js +450 -0
- package/lib/service/chat/memory/SessionStore.js +896 -0
- package/lib/service/chat/memory/index.js +13 -0
- package/lib/service/chat/tools/ast-graph.js +17 -16
- package/lib/service/cursor/AgentInstructionsGenerator.js +76 -47
- package/lib/service/cursor/FileProtection.js +4 -1
- package/lib/service/guard/GuardCheckEngine.js +10 -3
- package/lib/service/task/TaskGraphService.js +3 -3
- package/lib/shared/LanguageService.js +2 -1
- package/package.json +1 -1
- package/skills/autosnippet-intent/SKILL.md +1 -3
- package/skills/autosnippet-recipes/SKILL.md +1 -3
- package/templates/claude-code/commands/prime.md +19 -0
- package/templates/claude-code/hooks/autosnippet-session.sh +63 -0
- package/templates/claude-code/settings.json +21 -0
- package/templates/copilot-instructions.md +64 -177
- package/templates/cursor-hooks/commands/prime.md +12 -0
- package/templates/cursor-hooks/hooks/session-start.sh +10 -0
- package/templates/cursor-hooks/hooks.json +11 -0
- package/templates/cursor-rules/autosnippet-conventions.mdc +52 -3
- package/templates/cursor-rules/autosnippet-workflow.mdc +51 -27
- package/lib/external/mcp/handlers/decide.js +0 -109
- package/lib/external/mcp/handlers/ready.js +0 -42
- package/lib/service/chat/ReasoningLayer.js +0 -888
- package/templates/claude-hooks.yaml +0 -19
|
@@ -1,179 +1,66 @@
|
|
|
1
1
|
<!-- autosnippet:begin -->
|
|
2
|
-
<!-- On
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
##
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- `mode=semantic` — 向量语义搜索
|
|
65
|
-
|
|
66
|
-
### 知识浏览
|
|
67
|
-
- `autosnippet_knowledge` — 统一知识访问入口(通过 `operation` 参数切换)
|
|
68
|
-
- `operation=list` — 列出 Recipe/Rule/Pattern/Fact(支持 `kind`/`language`/`category`/`status` 多条件过滤)
|
|
69
|
-
- `operation=get` — 按 ID 获取单个 Recipe 详情
|
|
70
|
-
- `operation=insights` — 获取 Recipe 质量洞察(分数/统计/关系)
|
|
71
|
-
- `operation=confirm_usage` — 确认 Recipe 被采纳/应用
|
|
72
|
-
|
|
73
|
-
### 项目结构
|
|
74
|
-
- `autosnippet_structure` — SPM Target 结构发现(`operation`: targets / files / metadata)
|
|
75
|
-
|
|
76
|
-
### 知识图谱
|
|
77
|
-
- `autosnippet_graph` — 图谱查询(`operation`: query / impact / path / stats)
|
|
78
|
-
|
|
79
|
-
### 候选提交
|
|
80
|
-
- `autosnippet_submit_knowledge` — 单条提交(严格前置校验,缺少必要字段直接拒绝不入库。必填: title, language, content(+rationale), kind, doClause, dontClause, whenClause, coreCode, category, trigger, description, headers, usageGuide, knowledgeType, reasoning(+whyStandard+sources+confidence)。所有字段必须在单次调用中一次性提供)
|
|
81
|
-
- `autosnippet_submit_knowledge_batch` — 批量提交(含去重 + 限流 + 逐条严格校验,缺字段的条目被拒绝)
|
|
82
|
-
|
|
83
|
-
### 开发文档
|
|
84
|
-
- `autosnippet_save_document` — 保存开发文档(title + markdown,自动发布)
|
|
85
|
-
|
|
86
|
-
### Guard
|
|
87
|
-
- `autosnippet_guard` — 代码规范检查(传 `code` 单文件 / 传 `files[]` 批量审计,自动路由)
|
|
88
|
-
|
|
89
|
-
### Skills
|
|
90
|
-
- `autosnippet_skill` — Skill 管理(`operation`: list / load / create / update / delete / suggest)
|
|
91
|
-
|
|
92
|
-
### 冷启动 & 扫描
|
|
93
|
-
- `autosnippet_bootstrap` — 冷启动 Mission Briefing(无参数,返回项目分析 + 维度任务清单)
|
|
94
|
-
- `autosnippet_dimension_complete` — 维度分析完成通知(dimensionId + analysisText 必填)
|
|
95
|
-
|
|
96
|
-
### Wiki 文档
|
|
97
|
-
- `autosnippet_wiki_plan` — Wiki 文档规划(扫描项目生成主题数据包)
|
|
98
|
-
- `autosnippet_wiki_finalize` — Wiki 完成(meta.json + 去重 + 验证)
|
|
99
|
-
|
|
100
|
-
### 任务管理
|
|
101
|
-
- `autosnippet_ready` — **每次收到用户消息第一步调用**:加载活跃决策、就绪任务、知识上下文
|
|
102
|
-
- `autosnippet_decide` — 决策管理:record / revise / unpin / list(**用户明确同意/否决方案时立即调用并先持久化**)
|
|
103
|
-
- `autosnippet_task` — 任务 CRUD:create / claim / close / fail / defer / progress / decompose / dep_add 等
|
|
104
|
-
- `asd` — VS Code Agent Mode 专用通道(`#asd` 引用激活,代理所有操作)
|
|
105
|
-
|
|
106
|
-
### 系统
|
|
107
|
-
- `autosnippet_health` — 服务健康状态与知识库统计(可检测空 KB 触发冷启动)
|
|
108
|
-
- `autosnippet_capabilities` — 服务能力清单(列出所有可用 MCP 工具,供 Agent 自发现)
|
|
109
|
-
|
|
110
|
-
### 管理员工具(Admin Tier)
|
|
111
|
-
- `autosnippet_enrich_candidates` — 候选字段完整性诊断(不使用 AI)
|
|
112
|
-
- `autosnippet_knowledge_lifecycle` — 知识条目生命周期操作(publish/deprecate/reactivate 等)
|
|
113
|
-
- `autosnippet_validate_candidate` — 候选结构化预校验(调试用)
|
|
114
|
-
- `autosnippet_check_duplicate` — 相似度检测(调试用)
|
|
115
|
-
|
|
116
|
-
## Recipe 结构要点
|
|
117
|
-
- 必须包含:Frontmatter(`title`、`trigger` 必填)+ `## Snippet / Code Reference` + `## AI Context / Usage Guide`。
|
|
118
|
-
- Frontmatter 必填字段(7):`title`、`trigger`(@开头)、`category`(8 选 1)、`language`、`summary_cn`、`summary_en`、`headers`。
|
|
119
|
-
- Usage Guide 必须用 `###` 三级标题分段,列表式书写,禁止一行文字墙。
|
|
120
|
-
|
|
121
|
-
## Project Skills
|
|
122
|
-
- **发现**:`autosnippet_skill` — `operation=list` 列出所有可用 Skills(内置 + 项目级)
|
|
123
|
-
- **加载**:`autosnippet_skill` — `operation=load, name=<skillName>` 获取 Skill 完整操作指南
|
|
124
|
-
- **创建**:`autosnippet_skill` — `operation=create, name, description, content` 创建项目级 Skill
|
|
125
|
-
- **推荐**:`autosnippet_skill` — `operation=suggest` 基于使用模式推荐创建 Skill
|
|
126
|
-
- **Bootstrap 自动生成**:冷启动 Phase 5.5 自动生成 4 个 Project Skills(code-standard, architecture, project-profile, agent-guidelines)
|
|
127
|
-
- **优先级**:项目级 Skill 同名覆盖内置;宏观知识查 Skill,微观代码模式查 Recipe
|
|
128
|
-
|
|
129
|
-
## 冷启动必读(首次使用必看)
|
|
130
|
-
|
|
131
|
-
执行冷启动前,**必须**先加载 Skill 获取完整指引:
|
|
132
|
-
```
|
|
133
|
-
autosnippet_skill({ operation: "load", name: "autosnippet-coldstart" })
|
|
134
|
-
```
|
|
135
|
-
Skill 包含:完整的 V3 字段格式、JSON 示例模板、维度分析策略。
|
|
136
|
-
**不加载 Skill 直接提交知识会因字段格式问题被反复拒绝。**
|
|
137
|
-
|
|
138
|
-
## Guard 诊断响应
|
|
139
|
-
|
|
140
|
-
当编辑器出现来自 "AutoSnippet Guard" 的诊断(黄色/红色波浪线)时:
|
|
141
|
-
1. 读取诊断消息中的 `ruleId`
|
|
142
|
-
2. 调用 `autosnippet_search(query: ruleId)` 查找对应 Recipe
|
|
143
|
-
3. 按 Recipe 的 `doClause` + `coreCode` 修复代码
|
|
144
|
-
4. 保存文件并确认诊断消失
|
|
145
|
-
|
|
146
|
-
灯泡菜单中可快捷搜索知识库或禁用该行检查。
|
|
147
|
-
|
|
148
|
-
## 决策与任务管理(VS Code Agent Mode)
|
|
149
|
-
|
|
150
|
-
在 VS Code Agent Mode 中,输入 `#asd` 后跟消息即可激活项目记忆。
|
|
151
|
-
工具会自动加载项目决策和任务,Agent 应遵守所有返回的决策。
|
|
152
|
-
|
|
153
|
-
- `_decisions` / `_activeDecisions` — 必须遵守的团队决策
|
|
154
|
-
- `_decisionHint` — 决策行为提示
|
|
155
|
-
- 用户同意或否决某方案时,使用 `autosnippet_decide({ operation: "record" })` 记录
|
|
156
|
-
|
|
157
|
-
### V3 字段格式关键提醒
|
|
158
|
-
- `content` **必须是 JSON 对象**(不是字符串):`{ "pattern": "代码...", "markdown": "## 标题\n正文...", "rationale": "设计原理" }`
|
|
159
|
-
- `reasoning` **必须是 JSON 对象**:`{ "whyStandard": "原因", "sources": ["file.ts"], "confidence": 0.85 }`
|
|
160
|
-
- `headers` **必须是数组**:`["import Foundation"]`,无 import 时传 `[]`
|
|
161
|
-
- 所有 15 个必填字段必须在**单次调用中一次性提供**,缺字段直接拒绝
|
|
162
|
-
|
|
163
|
-
## 推荐工作流
|
|
164
|
-
1. **收到消息后第一步**:`autosnippet_ready()` — 加载决策 + 任务上下文(**每次都要,不可跳过**)
|
|
165
|
-
2. **用户同意/否决方案时第一步**:`autosnippet_decide({ operation: "record" | "revise" | "unpin" })` — 先持久化决策再执行。
|
|
166
|
-
3. **查找**:`autosnippet_search`(推荐 mode=auto)或 mode=context(上下文感知)。
|
|
167
|
-
- **产出候选**:`autosnippet_submit_knowledge` 提交(严格前置校验,必须一次性提供所有必填字段,缺字段直接拒绝不入库)。
|
|
168
|
-
- **冷启动**:`autosnippet_bootstrap`(无参数)→ 逐维度分析代码 → `autosnippet_submit_knowledge_batch` → `autosnippet_dimension_complete`。
|
|
169
|
-
- **Skills 创建**:`autosnippet_skill` op=suggest 分析 → `autosnippet_skill` op=create 固化知识。
|
|
170
|
-
- **采纳反馈**:`autosnippet_knowledge` op=confirm_usage(记录使用量影响排序权重)。
|
|
171
|
-
|
|
172
|
-
## 与 Cursor 规则联动
|
|
173
|
-
- 本文件与 `templates/cursor-rules/autosnippet-conventions.mdc` 保持一致。
|
|
174
|
-
- 如有冲突,以 **禁止修改 Knowledge** 与 **Recipe 优先** 原则为准。
|
|
175
|
-
|
|
176
|
-
---
|
|
177
|
-
<!-- REMINDER: If you have not yet called autosnippet_ready(), do it now before responding. -->
|
|
178
|
-
<!-- REMINDER: If user has explicitly agreed/disagreed with a plan, call autosnippet_decide(...) before continuing. -->
|
|
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
|
+
|
|
179
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
|
|
@@ -11,14 +11,63 @@ These rules are written when installing AutoSnippet Skills (`asd install:cursor-
|
|
|
11
11
|
|
|
12
12
|
## 强制规则(必须遵守)
|
|
13
13
|
|
|
14
|
-
1. **每次收到用户消息,第一步调 `
|
|
15
|
-
2. **当用户明确同意/否决某方案时,立即调用 `
|
|
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 `
|
|
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
|
|
2
|
+
description: AutoSnippet Task Tracking — 任务管理 + 行为规则
|
|
3
3
|
alwaysApply: true
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# AutoSnippet
|
|
6
|
+
# AutoSnippet Task Workflow
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## CRITICAL: You Operate autosnippet_task — The User Doesn't
|
|
9
9
|
|
|
10
|
-
|
|
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.
|
|
18
|
-
2.
|
|
19
|
-
3.
|
|
20
|
-
4.
|
|
21
|
-
5.
|
|
22
|
-
6.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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` → 立即
|
|
60
|
+
- `_contextHint` 包含 `CONTEXT_PRESSURE:CRITICAL` → 立即 prime 恢复上下文
|
|
39
61
|
|
|
40
62
|
## 任务操作速查
|
|
41
63
|
|
|
42
64
|
| 操作 | 用途 |
|
|
43
65
|
|------|------|
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
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
|
-
| `
|
|
52
|
-
| `
|
|
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
|
-
}
|