autosnippet 3.2.18 → 3.2.20
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 +73 -104
- package/dashboard/dist/assets/{index-CKMy5LY6.js → index-DdvZE4Yd.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dist/bin/cli.js +45 -10
- package/dist/lib/agent/AgentEventBus.js +3 -3
- package/dist/lib/agent/AgentFactory.d.ts +3 -3
- package/dist/lib/agent/AgentFactory.js +4 -4
- package/dist/lib/agent/AgentMessage.d.ts +8 -8
- package/dist/lib/agent/AgentMessage.js +8 -8
- package/dist/lib/agent/AgentRuntime.js +2 -2
- package/dist/lib/agent/AgentState.js +4 -4
- package/dist/lib/agent/ConversationStore.d.ts +1 -1
- package/dist/lib/agent/ConversationStore.js +1 -1
- package/dist/lib/agent/PipelineStrategy.js +1 -1
- package/dist/lib/agent/context/ContextWindow.d.ts +2 -2
- package/dist/lib/agent/context/ContextWindow.js +7 -7
- package/dist/lib/agent/context/ExplorationTracker.js +9 -9
- package/dist/lib/agent/context/exploration/PlanTracker.js +2 -2
- package/dist/lib/agent/context/exploration/SignalDetector.d.ts +1 -1
- package/dist/lib/agent/context/exploration/SignalDetector.js +1 -1
- package/dist/lib/agent/core/LoopContext.d.ts +21 -21
- package/dist/lib/agent/core/LoopContext.js +21 -21
- package/dist/lib/agent/core/SystemPromptBuilder.js +4 -4
- package/dist/lib/agent/domain/EvidenceCollector.js +5 -5
- package/dist/lib/agent/memory/ActiveContext.js +1 -1
- package/dist/lib/agent/memory/MemoryRetriever.js +1 -1
- package/dist/lib/agent/memory/MemoryStore.js +2 -2
- package/dist/lib/agent/memory/SessionStore.js +3 -3
- package/dist/lib/agent/policies.d.ts +1 -1
- package/dist/lib/agent/policies.js +1 -1
- package/dist/lib/agent/strategies.d.ts +1 -1
- package/dist/lib/agent/strategies.js +4 -4
- package/dist/lib/agent/tools/_shared.d.ts +1 -1
- package/dist/lib/agent/tools/_shared.js +1 -1
- package/dist/lib/agent/tools/infrastructure.js +2 -2
- package/dist/lib/cli/SetupService.d.ts +25 -25
- package/dist/lib/cli/SetupService.js +28 -15
- package/dist/lib/cli/deploy/FileDeployer.d.ts +9 -2
- package/dist/lib/cli/deploy/FileDeployer.js +139 -46
- package/dist/lib/cli/deploy/FileManifest.d.ts +23 -39
- package/dist/lib/cli/deploy/FileManifest.js +22 -27
- package/dist/lib/core/AstAnalyzer.d.ts +2 -2
- package/dist/lib/core/AstAnalyzer.js +2 -2
- package/dist/lib/core/analysis/CallEdgeResolver.d.ts +7 -7
- package/dist/lib/core/analysis/CallEdgeResolver.js +9 -9
- package/dist/lib/core/analysis/CallGraphAnalyzer.d.ts +4 -4
- package/dist/lib/core/analysis/CallGraphAnalyzer.js +2 -2
- package/dist/lib/core/analysis/ImportPathResolver.d.ts +0 -2
- package/dist/lib/core/analysis/ImportPathResolver.js +2 -4
- package/dist/lib/core/ast/ProjectGraph.js +7 -7
- package/dist/lib/core/capability/CapabilityProbe.js +6 -14
- package/dist/lib/domain/knowledge/UnifiedValidator.js +2 -2
- package/dist/lib/domain/knowledge/values/Constraints.js +4 -4
- package/dist/lib/domain/knowledge/values/Content.js +6 -6
- package/dist/lib/domain/knowledge/values/Quality.js +5 -5
- package/dist/lib/domain/knowledge/values/Reasoning.js +5 -5
- package/dist/lib/domain/knowledge/values/Relations.js +1 -1
- package/dist/lib/domain/knowledge/values/Stats.js +6 -6
- package/dist/lib/domain/task/TaskIdGenerator.d.ts +4 -4
- package/dist/lib/domain/task/TaskIdGenerator.js +2 -2
- package/dist/lib/external/lark/LarkTransport.js +4 -4
- package/dist/lib/external/mcp/McpServer.d.ts +3 -7
- package/dist/lib/external/mcp/McpServer.js +9 -13
- package/dist/lib/external/mcp/handlers/bootstrap/ExternalSubmissionTracker.js +5 -5
- package/dist/lib/external/mcp/handlers/bootstrap/MissionBriefingBuilder.js +4 -3
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.d.ts +3 -3
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/BootstrapSnapshot.js +3 -3
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/IncrementalBootstrap.d.ts +1 -1
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/IncrementalBootstrap.js +1 -1
- package/dist/lib/external/mcp/handlers/bootstrap/pipeline/dimension-context.js +3 -3
- package/dist/lib/external/mcp/handlers/bootstrap/shared/dimension-sop.js +27 -14
- package/dist/lib/external/mcp/handlers/bootstrap-external.js +6 -0
- package/dist/lib/external/mcp/handlers/dimension-complete-external.js +55 -1
- package/dist/lib/external/mcp/handlers/skill.js +9 -31
- package/dist/lib/external/mcp/handlers/system.js +2 -2
- package/dist/lib/external/mcp/handlers/task.js +16 -1
- package/dist/lib/external/mcp/tools.d.ts +12 -10
- package/dist/lib/external/mcp/tools.js +97 -69
- package/dist/lib/http/utils/routeHelpers.d.ts +1 -1
- package/dist/lib/http/utils/routeHelpers.js +1 -1
- package/dist/lib/http/utils/sse-sessions.d.ts +1 -1
- package/dist/lib/http/utils/sse-sessions.js +1 -1
- package/dist/lib/infrastructure/cache/CacheService.js +1 -1
- package/dist/lib/infrastructure/vector/AsyncPersistence.js +8 -8
- package/dist/lib/infrastructure/vector/BatchEmbedder.d.ts +1 -1
- package/dist/lib/infrastructure/vector/BatchEmbedder.js +2 -2
- package/dist/lib/infrastructure/vector/HnswIndex.d.ts +4 -4
- package/dist/lib/infrastructure/vector/HnswIndex.js +5 -5
- package/dist/lib/infrastructure/vector/HnswVectorAdapter.js +8 -8
- package/dist/lib/infrastructure/vector/ScalarQuantizer.d.ts +1 -1
- package/dist/lib/infrastructure/vector/ScalarQuantizer.js +4 -4
- package/dist/lib/infrastructure/vector/VectorStore.d.ts +1 -1
- package/dist/lib/infrastructure/vector/VectorStore.js +1 -1
- package/dist/lib/injection/ServiceContainer.d.ts +1 -1
- package/dist/lib/injection/ServiceContainer.js +1 -1
- package/dist/lib/platform/NativeUi.d.ts +1 -1
- package/dist/lib/platform/NativeUi.js +1 -1
- package/dist/lib/platform/ios/spm/DependencyGraph.d.ts +1 -1
- package/dist/lib/platform/ios/spm/DependencyGraph.js +1 -1
- package/dist/lib/platform/ios/spm/PolicyEngine.d.ts +1 -1
- package/dist/lib/platform/ios/spm/PolicyEngine.js +1 -1
- package/dist/lib/platform/ios/spm/SpmDiscoverer.js +1 -1
- package/dist/lib/platform/ios/spm/SpmHelper.js +3 -3
- package/dist/lib/platform/ios/xcode/SaveEventFilter.js +2 -2
- package/dist/lib/platform/ios/xcode/XcodeIntegration.js +1 -1
- package/dist/lib/repository/base/BaseRepository.js +1 -1
- package/dist/lib/repository/task/TaskRepository.impl.d.ts +2 -2
- package/dist/lib/repository/task/TaskRepository.impl.js +1 -1
- package/dist/lib/repository/token/TokenUsageStore.js +1 -1
- package/dist/lib/service/automation/ActionPipeline.d.ts +1 -1
- package/dist/lib/service/automation/ActionPipeline.js +1 -1
- package/dist/lib/service/bootstrap/BootstrapEventEmitter.js +2 -2
- package/dist/lib/service/bootstrap/BootstrapTaskManager.d.ts +1 -1
- package/dist/lib/service/bootstrap/BootstrapTaskManager.js +2 -2
- package/dist/lib/service/bootstrap/DimensionCopyRegistry.d.ts +2 -2
- package/dist/lib/service/bootstrap/DimensionCopyRegistry.js +2 -2
- package/dist/lib/service/delivery/AgentInstructionsGenerator.d.ts +6 -15
- package/dist/lib/service/delivery/AgentInstructionsGenerator.js +53 -189
- package/dist/lib/service/delivery/CursorDeliveryPipeline.d.ts +6 -16
- package/dist/lib/service/delivery/CursorDeliveryPipeline.js +14 -19
- package/dist/lib/service/delivery/KnowledgeCompressor.d.ts +1 -1
- package/dist/lib/service/delivery/KnowledgeCompressor.js +1 -1
- package/dist/lib/service/delivery/RulesGenerator.d.ts +10 -3
- package/dist/lib/service/delivery/RulesGenerator.js +43 -3
- package/dist/lib/service/delivery/SkillsSyncer.d.ts +21 -7
- package/dist/lib/service/delivery/SkillsSyncer.js +46 -10
- package/dist/lib/service/delivery/TopicClassifier.d.ts +3 -6
- package/dist/lib/service/delivery/TopicClassifier.js +0 -3
- package/dist/lib/service/guard/ExclusionManager.d.ts +1 -1
- package/dist/lib/service/guard/ExclusionManager.js +1 -1
- package/dist/lib/service/guard/GuardCheckEngine.d.ts +3 -3
- package/dist/lib/service/guard/GuardCheckEngine.js +5 -5
- package/dist/lib/service/guard/GuardCrossFileChecks.d.ts +1 -1
- package/dist/lib/service/guard/GuardFeedbackLoop.d.ts +3 -3
- package/dist/lib/service/guard/GuardFeedbackLoop.js +3 -3
- package/dist/lib/service/guard/GuardPatternUtils.js +1 -1
- package/dist/lib/service/guard/GuardService.d.ts +1 -15
- package/dist/lib/service/guard/GuardService.js +0 -1
- package/dist/lib/service/guard/RuleLearner.d.ts +1 -1
- package/dist/lib/service/guard/RuleLearner.js +1 -1
- package/dist/lib/service/knowledge/CodeEntityGraph.d.ts +3 -3
- package/dist/lib/service/knowledge/CodeEntityGraph.js +3 -3
- package/dist/lib/service/knowledge/KnowledgeService.d.ts +0 -1
- package/dist/lib/service/knowledge/KnowledgeService.js +0 -1
- package/dist/lib/service/module/ModuleService.d.ts +1 -1
- package/dist/lib/service/module/ModuleService.js +2 -2
- package/dist/lib/service/search/HybridRetriever.d.ts +2 -2
- package/dist/lib/service/search/HybridRetriever.js +2 -2
- package/dist/lib/service/search/SearchEngine.d.ts +1 -3
- package/dist/lib/service/search/SearchEngine.js +1 -3
- package/dist/lib/service/search/contextBoost.d.ts +1 -1
- package/dist/lib/service/skills/EventAggregator.js +2 -2
- package/dist/lib/service/skills/SignalCollector.js +1 -1
- package/dist/lib/service/snippet/codecs/VSCodeCodec.js +1 -1
- package/dist/lib/service/task/TaskGraphService.d.ts +0 -3
- package/dist/lib/service/task/TaskGraphService.js +0 -3
- package/dist/lib/service/task/TaskKnowledgeBridge.d.ts +8 -27
- package/dist/lib/service/task/TaskKnowledgeBridge.js +0 -8
- package/dist/lib/service/task/TaskReadyEngine.d.ts +1 -2
- package/dist/lib/service/task/TaskReadyEngine.js +0 -1
- package/dist/lib/service/wiki/WikiRenderers.js +0 -1
- package/dist/lib/service/wiki/WikiUtils.js +2 -7
- package/dist/lib/shared/PathGuard.js +6 -6
- package/dist/lib/shared/schemas/mcp-tools.js +84 -43
- package/dist/scripts/install-vscode-copilot.js +14 -4
- package/package.json +1 -1
- package/skills/autosnippet-create/SKILL.md +131 -131
- package/skills/autosnippet-devdocs/SKILL.md +1 -2
- package/skills/autosnippet-guard/SKILL.md +20 -89
- package/skills/autosnippet-recipes/SKILL.md +35 -117
- package/skills/autosnippet-structure/SKILL.md +23 -55
- package/templates/cursor-rules/autosnippet-skills.mdc +17 -33
- package/templates/instructions/agent-static.md +24 -0
- package/templates/instructions/conventions.md +42 -0
- package/skills/autosnippet-analysis/SKILL.md +0 -169
- package/skills/autosnippet-candidates/SKILL.md +0 -367
- package/skills/autosnippet-coldstart/SKILL.md +0 -988
- package/skills/autosnippet-concepts/SKILL.md +0 -630
- package/skills/autosnippet-intent/SKILL.md +0 -55
- package/skills/autosnippet-lifecycle/SKILL.md +0 -100
- package/templates/copilot-instructions.md +0 -66
- package/templates/cursor-rules/autosnippet-conventions.mdc +0 -172
- package/templates/cursor-rules/autosnippet-workflow.mdc +0 -76
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: autosnippet-analysis
|
|
3
|
-
description: Deep project analysis — full scan + semantic field enrichment + gap fill before Recipe creation. Both Cursor Agent and internal AI share the same capability set.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# AutoSnippet — Deep Project Analysis & Semantic Enrichment
|
|
7
|
-
|
|
8
|
-
> Self-check & Fallback: MCP 工具返回统一 JSON Envelope({ success, errorCode?, message?, data?, meta })。重操作前调用 `autosnippet_health`;失败时不在同一轮重试,转用静态上下文或缩小范围后再试。
|
|
9
|
-
|
|
10
|
-
## Core Principle
|
|
11
|
-
|
|
12
|
-
**MCP 工具负责数据采集 + 静态检查;你(Agent)负责语义理解;Agent 直接填写完整字段后通过 `autosnippet_submit_knowledge` 提交。**
|
|
13
|
-
|
|
14
|
-
**⚠️ 严格提交规则**:`autosnippet_submit_knowledge` 实施严格前置校验——缺少必要字段的提交将被**直接拒绝(不入库)**。必须在单次调用中一次性提供所有必填字段(title, language, content, kind, doClause, dontClause, whenClause, coreCode, category, trigger, description, headers, usageGuide, knowledgeType, reasoning, content.rationale)。不要分步提交或先提交再补全。
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## Capability 1: 全项目扫描 → 提交候选
|
|
19
|
-
|
|
20
|
-
> **首次接入项目?** 使用 **autosnippet-coldstart** Skill — 完整的 9 维度冷启动流程(含架构分析、项目特征、Agent 注意事项),比本 Skill 的扫描流程更全面。
|
|
21
|
-
> 本 Capability 适用于已有知识库后的**增量补充扫描**。
|
|
22
|
-
|
|
23
|
-
### When to Use
|
|
24
|
-
用户说:"全项目扫描"、"分析我的项目"、"提取架构模式"、"生成知识库"。
|
|
25
|
-
|
|
26
|
-
### Workflow
|
|
27
|
-
|
|
28
|
-
#### Phase 1: Collect & Baseline
|
|
29
|
-
1. 调用 `autosnippet_bootstrap`(无参数)获取 Mission Briefing(文件列表 + Guard 审计基线)
|
|
30
|
-
2. 审视 Guard 违规 — 静态规则问题 (命名/API 使用/废弃 API)
|
|
31
|
-
3. 确定高优先级文件 (核心模块/共享工具/Service 层)
|
|
32
|
-
|
|
33
|
-
#### Phase 2: Semantic Deep-Read
|
|
34
|
-
读取代码文件,逐维度分析:
|
|
35
|
-
|
|
36
|
-
| 分析维度 | 寻找什么 | knowledgeType | 对应字段 |
|
|
37
|
-
|---------|---------|---------------|---------|
|
|
38
|
-
| **架构模式** | 分层架构、MVVM/MVC、依赖注入 | `architecture` | rationale: 为什么选这种架构 |
|
|
39
|
-
| **代码模式** | 封装方式、公共 API 设计、工厂/单例 | `code-pattern` | steps: 如何采用该模式 |
|
|
40
|
-
| **代码规范** | 命名规范、文件组织、注释风格 | `code-standard` | constraints.preconditions: 前置条件 |
|
|
41
|
-
| **最佳实践** | 错误处理、并发、内存管理 | `best-practice` | rationale: 为什么这是最佳实践 |
|
|
42
|
-
| **调用链** | 关键业务的调用路径 | `call-chain` | steps: 调用顺序 |
|
|
43
|
-
| **数据流** | 状态管理、模块间数据传递 | `data-flow` | steps: 数据流向 |
|
|
44
|
-
| **模块依赖** | 依赖边界、约束 | `module-dependency` | constraints: 边界约束 |
|
|
45
|
-
| **Bug 修复** | 常见修复模式、defensive coding | `solution` | rationale: 为什么这样修 |
|
|
46
|
-
|
|
47
|
-
#### Phase 3: Submit with Full Semantic Fields
|
|
48
|
-
**每条候选必须填充以下语义字段**(不留空):
|
|
49
|
-
|
|
50
|
-
```json
|
|
51
|
-
{
|
|
52
|
-
"title": "网络层统一错误处理模式",
|
|
53
|
-
"content": {
|
|
54
|
-
"pattern": "<实际代码模式>",
|
|
55
|
-
"rationale": "统一错误处理避免分散的 try-catch,便于日志收集和错误上报"
|
|
56
|
-
},
|
|
57
|
-
"language": "swift",
|
|
58
|
-
"kind": "pattern",
|
|
59
|
-
"doClause": "Use centralized error handling via APIClient.request() for all network calls",
|
|
60
|
-
"category": "Network",
|
|
61
|
-
"trigger": "@network-error-handling",
|
|
62
|
-
"description": "网络层统一错误处理——所有请求通过 APIClient.request() 封装,统一 catch + 日志上报",
|
|
63
|
-
"headers": ["import Combine", "import Foundation"],
|
|
64
|
-
"usageGuide": "### 何时使用\n发起网络请求时统一通过 APIClient\n### 如何使用\n1. 创建 NetworkError 枚举 2. 调用 APIClient.request()",
|
|
65
|
-
"knowledgeType": "code-pattern",
|
|
66
|
-
"complexity": "intermediate",
|
|
67
|
-
"scope": "project-specific",
|
|
68
|
-
"steps": [
|
|
69
|
-
{ "title": "创建 Error 枚举", "description": "在 Network/ 下创建 NetworkError.swift", "code": "enum NetworkError: Error { ... }" },
|
|
70
|
-
{ "title": "封装请求方法", "description": "所有请求统一通过 APIClient.request()", "code": "" }
|
|
71
|
-
],
|
|
72
|
-
"constraints": {
|
|
73
|
-
"preconditions": ["iOS 15+", "需引入 Combine framework"],
|
|
74
|
-
"boundaries": ["不可用于 WebSocket 连接"],
|
|
75
|
-
"sideEffects": []
|
|
76
|
-
},
|
|
77
|
-
"tags": ["networking", "error-handling"],
|
|
78
|
-
"reasoning": {
|
|
79
|
-
"whyStandard": "项目中 15 个网络模块均采用此模式",
|
|
80
|
-
"sources": ["Sources/Network/APIClient.swift", "Sources/Network/ErrorHandler.swift"],
|
|
81
|
-
"confidence": 0.9
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Use `autosnippet_submit_knowledge_batch` for batch submission.
|
|
87
|
-
|
|
88
|
-
#### Phase 4: Guard Deep Audit (Optional)
|
|
89
|
-
对特定文件调用 `autosnippet_guard` (files[]) 做深度规范审计。
|
|
90
|
-
|
|
91
|
-
---
|
|
92
|
-
|
|
93
|
-
## Capability 2: 语义字段补全(需要 AI 理解的字段)
|
|
94
|
-
|
|
95
|
-
### When to Use
|
|
96
|
-
- 候选已有 title/code/language 但缺少深度语义字段
|
|
97
|
-
- 候选要晋升为 Recipe 前,需要补全
|
|
98
|
-
- 用户说:"补全候选字段"、"enrich"、"查漏补缺"
|
|
99
|
-
|
|
100
|
-
### 需要语义理解的 6 个字段
|
|
101
|
-
|
|
102
|
-
| 字段 | 为什么需要 AI | 示例 |
|
|
103
|
-
|------|-------------|------|
|
|
104
|
-
| **rationale** | 需理解设计意图,回答"为什么这样做" | "该模式使用 Builder 而非直接构造,因为参数超过 5 个且多数可选" |
|
|
105
|
-
| **knowledgeType** | 需理解知识本质(规范/模式/事实) | `architecture` vs `code-pattern` vs `best-practice` |
|
|
106
|
-
| **complexity** | 需评估使用难度 | `beginner`(一行调用)vs `advanced`(需理解泛型+协议组合) |
|
|
107
|
-
| **scope** | 需判断适用范围 | `universal`(通用 Singleton)vs `project-specific`(依赖项目 Config) |
|
|
108
|
-
| **steps** | 需拆解实施步骤 | `[{title: "创建协议", description: "...", code: "..."}]` |
|
|
109
|
-
| **constraints.preconditions** | 需理解前置条件 | `["iOS 15+", "需先配置 Firebase", "依赖 NetworkModule"]` |
|
|
110
|
-
|
|
111
|
-
### Workflow for Enrichment
|
|
112
|
-
|
|
113
|
-
**方式 A: 你(Agent)直接补全**
|
|
114
|
-
在分析代码时,直接填写所有 6 个语义字段到 `autosnippet_submit_knowledge` 调用中。
|
|
115
|
-
|
|
116
|
-
**方式 B: 对已有候选调用 AI 补全**
|
|
117
|
-
> 注:`autosnippet_enrich_candidates` 已移入 admin 层级,Agent 推荐使用方式 A 直接填写完整字段。
|
|
118
|
-
|
|
119
|
-
**方式 C: 候选字段诊断**
|
|
120
|
-
```
|
|
121
|
-
autosnippet_enrich_candidates({ candidateIds: ["id1", "id2", ...] })
|
|
122
|
-
```
|
|
123
|
-
诊断候选缺失字段(不使用 AI),Agent 根据诊断结果自行补全。
|
|
124
|
-
|
|
125
|
-
---
|
|
126
|
-
|
|
127
|
-
## Capability 3: 候选 → Recipe 查漏补缺
|
|
128
|
-
|
|
129
|
-
### When to Use
|
|
130
|
-
- 用户准备将候选发布为 Recipe
|
|
131
|
-
- 用户说:"准备发布"、"候选检查"、"Recipe 就绪检查"
|
|
132
|
-
|
|
133
|
-
### Workflow
|
|
134
|
-
|
|
135
|
-
1. 对目标候选做结构补齐(确保所有字段完整)
|
|
136
|
-
2. 调用 `autosnippet_enrich_candidates` 诊断候选缺失字段,根据结果自行补全
|
|
137
|
-
3. 提交时使用 `autosnippet_submit_knowledge`(内置自动校验 + 去重检查)
|
|
138
|
-
4. 报告补全情况 + 缺失字段 + 重复风险
|
|
139
|
-
5. 如缺失字段 AI 无法填充,提示用户手动补充
|
|
140
|
-
|
|
141
|
-
### Recipe 必备字段检查清单
|
|
142
|
-
|
|
143
|
-
| 字段 | 重要性 | AI 可填? |
|
|
144
|
-
|------|-------|---------|
|
|
145
|
-
| title | ★★★ 必填 | ✅ |
|
|
146
|
-
| content (markdown+pattern+rationale) | ★★★ 必填 | ✅ |
|
|
147
|
-
| language | ★★★ 必填 | ✅ |
|
|
148
|
-
| kind (rule/pattern/fact) | ★★★ 必填 | ✅ |
|
|
149
|
-
| doClause | ★★★ 必填 | ✅ |
|
|
150
|
-
| category | ★★★ 必填 | ✅ |
|
|
151
|
-
| trigger | ★★★ 必填 | ✅ |
|
|
152
|
-
| description | ★★★ 必填 | ✅ |
|
|
153
|
-
| headers | ★★★ 必填 | ✅ |
|
|
154
|
-
| usageGuide | ★★★ 必填 | ✅ |
|
|
155
|
-
| knowledgeType | ★★★ 必填 | ✅ |
|
|
156
|
-
| reasoning | ★★★ 必填 | Agent 必须自己填 |
|
|
157
|
-
| complexity | ★★☆ 推荐 | ✅ |
|
|
158
|
-
| scope | ★★☆ 推荐 | ✅ |
|
|
159
|
-
| steps | ★★☆ 推荐 | ✅ |
|
|
160
|
-
| constraints.preconditions | ★★☆ 推荐 | ✅ |
|
|
161
|
-
|
|
162
|
-
---
|
|
163
|
-
|
|
164
|
-
## Related Skills
|
|
165
|
-
|
|
166
|
-
- **autosnippet-candidates**: 完整候选字段模型 + 提交指南
|
|
167
|
-
- **autosnippet-structure**: 项目结构发现 (targets / files / dependencies)
|
|
168
|
-
- **autosnippet-guard**: Guard 触发机制 (`// as:audit`)
|
|
169
|
-
- **autosnippet-recipes**: Recipe 内容与查询
|
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: autosnippet-candidates
|
|
3
|
-
description: Generate Recipe candidates with full V3 structured information. Single file scan or batch Target scan. Agent extracts rich metadata matching the complete Recipe schema. Agent submits candidates only; Recipe creation/modification is human-only.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# AutoSnippet - Generate Candidates with Structured Content (v3.1)
|
|
7
|
-
|
|
8
|
-
> Self-check and Fallback: MCP tools return unified JSON Envelope. Before heavy ops call `autosnippet_health`. On failure do not retry in same turn; use static context or narrow scope.
|
|
9
|
-
|
|
10
|
-
## Core Rule: Agent Permission Boundary
|
|
11
|
-
|
|
12
|
-
**Agent CANNOT directly produce or modify Recipes.** Agent can only:
|
|
13
|
-
- Submit Recipe **candidates** (submit_candidate / submit_candidates / submit_draft_recipes)
|
|
14
|
-
- **Validate/enhance** candidates (validate_candidate / check_duplicate)
|
|
15
|
-
- **Search/query** existing Recipes for context and dedup
|
|
16
|
-
|
|
17
|
-
Recipe creation, review, publish, update, deprecate, delete are **human-only via Dashboard**.
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## ⚠️ Recipe-Ready Checklist (CRITICAL — STRICT ENFORCEMENT)
|
|
22
|
-
|
|
23
|
-
**MCP 不再使用项目内 AI**——外部 Agent 必须自行提供所有字段。**缺少必要字段的提交将被直接拒绝(不入库)**,不会降级处理。
|
|
24
|
-
|
|
25
|
-
**严格规则**:
|
|
26
|
-
- 所有必填字段必须在**单次调用**中一次性提供
|
|
27
|
-
- 缺字段的提交会返回 `errorCode: INCOMPLETE_SUBMISSION`,不会创建任何记录
|
|
28
|
-
- **禁止**先提交不完整数据再补全重新提交 — 这会浪费 Token 和时间
|
|
29
|
-
- 提交前自行确认所有字段齐全,一次通过
|
|
30
|
-
|
|
31
|
-
| 字段 | 级别 | 要求 | 示例 |
|
|
32
|
-
|------|------|------|------|
|
|
33
|
-
| `title` | 必填 | 中文简短标题(≤20字) | "视频封面 Cell 16:9 布局与时长格式化" |
|
|
34
|
-
| `content.pattern` / `content.markdown` | 必填 | 代码片段或 Markdown 正文 | 完整可运行的使用示例 |
|
|
35
|
-
| `content.rationale` | 必填 | 设计原理说明 | "统一封面布局避免手动计算" |
|
|
36
|
-
| `language` | 必填 | `swift` / `objectivec` | 小写,不要用 `objc` |
|
|
37
|
-
| `kind` | 必填 | `rule` / `pattern` / `fact` | 知识类型 |
|
|
38
|
-
| `doClause` | 必填 | 英文祈使句正向指令(≤60 tokens) | "Use AspectRatioContainer for 16:9 layout" |
|
|
39
|
-
| `category` | 必填 | 8 选 1 | View/Service/Tool/Model/Network/Storage/UI/Utility |
|
|
40
|
-
| `trigger` | 必填 | @ 开头小写 | `@video-cover-cell` |
|
|
41
|
-
| `description` | 必填 | 中文摘要 ≤80字 | "封面图片 16:9 自适应布局…" |
|
|
42
|
-
| `headers` | 必填 | 完整 import 语句数组 | `["#import <UIKit/UIKit.h>"]` |
|
|
43
|
-
| `usageGuide` | 必填 | Markdown ### 章节格式 | 描述何时/如何使用此知识 |
|
|
44
|
-
| `knowledgeType` | 必填 | 知识维度 | `code-pattern` / `architecture` / `best-practice` 等 |
|
|
45
|
-
| `reasoning` | 强烈建议 | whyStandard + sources + confidence | 见 Layer 6 |
|
|
46
|
-
|
|
47
|
-
**工作流程**:
|
|
48
|
-
1. Agent 提取候选时**一次性填写全部必填字段**
|
|
49
|
-
2. 调用 `autosnippet_submit_knowledge` 提交
|
|
50
|
-
3. 若返回 `INCOMPLETE_SUBMISSION` → 检查 `missingFields`,补齐后重新提交
|
|
51
|
-
4. 提交成功 = 候选可直接审核为 Recipe
|
|
52
|
-
|
|
53
|
-
---
|
|
54
|
-
|
|
55
|
-
## Quick Start
|
|
56
|
-
|
|
57
|
-
**Scenario 1: User says "scan a module/file to generate candidates"**
|
|
58
|
-
1. Read target file/module (including README or examples)
|
|
59
|
-
2. Extract public APIs, usage examples, doc comments
|
|
60
|
-
3. Generate multiple candidates (one pattern per candidate)
|
|
61
|
-
4. Parallel query existing Recipes -> mark similarity/conflicts
|
|
62
|
-
5. Score and rank -> submit Candidates
|
|
63
|
-
|
|
64
|
-
**Scenario 2: User says "batch scan Target"**
|
|
65
|
-
1. Call `autosnippet_structure(operation=targets)` -> select targetName
|
|
66
|
-
2. Call `autosnippet_structure(operation=files, targetName)`
|
|
67
|
-
3. Batch extract candidates (parallel)
|
|
68
|
-
4. Dedup, score, similarity mark -> submit Candidates
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## V3 Complete Candidate Field Model
|
|
73
|
-
|
|
74
|
-
Every candidate submitted via `submit_candidate` or `submit_candidates` supports the following fields. **The richer the information, the higher the quality of the resulting Recipe.**
|
|
75
|
-
|
|
76
|
-
### Layer 1: Core Identity (required — submission fails without these)
|
|
77
|
-
|
|
78
|
-
| Field | Type | Example |
|
|
79
|
-
|-------|------|---------|
|
|
80
|
-
| **title** | string | "网络请求统一封装 - APIClient" |
|
|
81
|
-
| **content** | object | `{ markdown: "≥200字 Markdown 正文", pattern: "核心代码模式", rationale: "设计原理" }` |
|
|
82
|
-
| **language** | string | swift / objc / javascript / python etc. |
|
|
83
|
-
| **kind** | string | `rule` / `pattern` / `fact` |
|
|
84
|
-
| **doClause** | string | 英文祈使句正向指令(≠60 tokens)|
|
|
85
|
-
| **trigger** | string | `@` 开头 kebab-case,如 `@api-client` |
|
|
86
|
-
| **description** | string | 中文摘要 ≤80字 |
|
|
87
|
-
| **category** | string | View / Service / Tool / Model / Network / Storage / UI / Utility |
|
|
88
|
-
| **headers** | string[] | 完整 import 语句数组,无 import 传 `[]` |
|
|
89
|
-
| **usageGuide** | string | Markdown ### 章节格式的使用指南 |
|
|
90
|
-
| **knowledgeType** | string | `code-pattern` / `architecture` / `best-practice` 等 |
|
|
91
|
-
|
|
92
|
-
### Layer 2: Classification (strongly recommended — enables filtering & search)
|
|
93
|
-
|
|
94
|
-
| Field | Type | Values / Example |
|
|
95
|
-
|-------|------|-----------------|
|
|
96
|
-
| **category** | string | View / Service / Tool / Model / Network / Storage / UI / Utility |
|
|
97
|
-
| **knowledgeType** | string | `code-pattern` \| `architecture` \| `best-practice` \| `code-standard` \| `code-relation` \| `inheritance` \| `call-chain` \| `data-flow` \| `module-dependency` \| `boundary-constraint` \| `code-style` \| `solution` \| `dev-document` |
|
|
98
|
-
| **complexity** | string | `beginner` \| `intermediate` \| `advanced` |
|
|
99
|
-
| **scope** | string | `universal` (通用) \| `project-specific` (本项目) \| `target-specific` (特定 Target) |
|
|
100
|
-
| **tags** | string[] | `["networking", "async-await", "error-handling"]` |
|
|
101
|
-
|
|
102
|
-
### Layer 3: Structured Content (high value — 代码变更与实施步骤)
|
|
103
|
-
|
|
104
|
-
> **注意**: Layer 1 已包含 V3 全部必填字段(title, content, language, kind, doClause, dontClause, whenClause, coreCode, trigger, description, category, headers, usageGuide, knowledgeType, reasoning)。本层为可选的高价值补充字段。
|
|
105
|
-
|
|
106
|
-
| Field | Type | Structure |
|
|
107
|
-
|-------|------|-----------|
|
|
108
|
-
| **rationale** | string | 设计原理:为什么选择这种模式、优于其他方案的原因 |
|
|
109
|
-
| **steps** | array | 实施步骤:`[{title: "创建 Service", description: "在 Services/ 下创建…", code: "class MyService { ... }"}]` |
|
|
110
|
-
| **codeChanges** | array | 代码变更:`[{file: "APIClient.swift", before: "URLSession.shared...", after: "apiClient.request(...)", explanation: "替换为统一封装"}]` |
|
|
111
|
-
| **verification** | object | 验证方式:`{method: "unit-test", expectedResult: "所有请求通过 apiClient", testCode: "func testAPI() {...}"}` |
|
|
112
|
-
| **headers** | string[] | 需要的 import/include:`["import Foundation", "import Combine"]` |
|
|
113
|
-
|
|
114
|
-
### Layer 5: Constraints & Relations (high value — enables dependency analysis & Guard rules)
|
|
115
|
-
|
|
116
|
-
| Field | Type | Structure |
|
|
117
|
-
|-------|------|-----------|
|
|
118
|
-
| **constraints** | object | `{boundaries: ["仅限 iOS 15+"], preconditions: ["需先初始化 NetworkConfig"], sideEffects: ["修改全局代理设置"], guards: [{pattern: "URLSession\\.shared", severity: "warning", message: "请使用 APIClient"}]}` |
|
|
119
|
-
| **relations** | object | `{dependsOn: [{target: "NetworkConfig", description: "依赖网络配置"}], extends: [...], conflicts: [...], related: [...], inherits: [...], implements: [...], calls: [...], dataFlow: [...]}` — 每项 `{target, description}` |
|
|
120
|
-
|
|
121
|
-
### Layer 6: Reasoning 推理依据 (required — Agent 必填,缺少将被拒绝)
|
|
122
|
-
|
|
123
|
-
| Field | Type | Description |
|
|
124
|
-
|-------|------|-------------|
|
|
125
|
-
| **reasoning.whyStandard** | string | 为什么这段代码值得沉淀为知识。必须回答:“它解决了什么问题”“为什么是标准做法”“不用会怎样” |
|
|
126
|
-
| **reasoning.sources** | string[] | 来源列表:文件路径、文档链接、上下文引用。如 `["Sources/Network/BiliAPI.swift", "README.md#networking"]` |
|
|
127
|
-
| **reasoning.confidence** | number | 置信度 0-1。`0.9`=明确的项目标准,`0.7`=常见模式但未明确规定,`0.5`=可能有用但不确定 |
|
|
128
|
-
| reasoning.qualitySignals | object | 质量信号(可选):`{clarity: 0.9, reusability: 0.8, importance: 0.7}` |
|
|
129
|
-
| reasoning.alternatives | string[] | 备选方案(可选):如果存在替代实现,简要描述 |
|
|
130
|
-
|
|
131
|
-
> **Reasoning 为什么重要?** 它是审核员判断候选质量的关键依据。没有 Reasoning 的候选无法通过校验。
|
|
132
|
-
|
|
133
|
-
### Layer 7: Quality & Source (optional — helps prioritize review)
|
|
134
|
-
|
|
135
|
-
| Field | Type | Structure |
|
|
136
|
-
|-------|------|-----------|
|
|
137
|
-
| **quality** | object | `{codeCompleteness: 0.9, projectAdaptation: 0.8, documentationClarity: 0.85}` (0-1) |
|
|
138
|
-
| **sourceFile** | string | 来源文件路径(相对于项目根目录) |
|
|
139
|
-
|
|
140
|
-
---
|
|
141
|
-
|
|
142
|
-
## Information Extraction Strategy
|
|
143
|
-
|
|
144
|
-
### Per-File Analysis Checklist
|
|
145
|
-
|
|
146
|
-
When scanning a source file, systematically extract:
|
|
147
|
-
|
|
148
|
-
1. **What does it do?** → `title`, `description`, `summary`, `category`
|
|
149
|
-
2. **How to use it?** → `code` (complete usage example), `trigger`, `usageGuide`, `headers`
|
|
150
|
-
3. **Why this design?** → `rationale`, `knowledgeType`
|
|
151
|
-
4. **Why is it worth extracting?** → `reasoning.whyStandard` (解决了什么问题?不用会怎样?), `reasoning.confidence`
|
|
152
|
-
5. **Where does it come from?** → `reasoning.sources` (文件路径), `sourceFile`
|
|
153
|
-
6. **How to implement step by step?** → `steps`, `codeChanges`
|
|
154
|
-
7. **What are the constraints?** → `constraints` (boundaries, preconditions, sideEffects)
|
|
155
|
-
8. **Any inline rules to enforce?** → `constraints.guards` (regex pattern + severity + message)
|
|
156
|
-
9. **What's the difficulty?** → `complexity`
|
|
157
|
-
10. **What does it depend on / relate to?** → `relations`, `headers`
|
|
158
|
-
11. **How to verify correctness?** → `verification`
|
|
159
|
-
12. **Quality assessment** → `quality` (code completeness, project adaptation, doc clarity)
|
|
160
|
-
|
|
161
|
-
### Knowledge Type Decision Tree
|
|
162
|
-
|
|
163
|
-
```
|
|
164
|
-
Is it a coding rule/standard/naming convention?
|
|
165
|
-
→ code-standard | code-style | boundary-constraint
|
|
166
|
-
|
|
167
|
-
Is it a reusable code pattern/template?
|
|
168
|
-
→ code-pattern | solution | best-practice
|
|
169
|
-
|
|
170
|
-
Is it describing code structure/relationships?
|
|
171
|
-
→ code-relation | inheritance | call-chain | data-flow | module-dependency
|
|
172
|
-
|
|
173
|
-
Is it an architectural decision or design pattern?
|
|
174
|
-
→ architecture
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### Extracting Reasoning (MANDATORY for every candidate)
|
|
178
|
-
|
|
179
|
-
Agent must answer three questions for every candidate:
|
|
180
|
-
|
|
181
|
-
1. **whyStandard** — "Why is this code worth documenting as project knowledge?"
|
|
182
|
-
- "This pattern is used in 5+ places and inconsistent implementations cause bugs"
|
|
183
|
-
- "This is the team's agreed-upon approach; deviations lead to maintenance issues"
|
|
184
|
-
- "New contributors frequently make mistakes here without guidance"
|
|
185
|
-
|
|
186
|
-
2. **sources** — "What evidence supports this?"
|
|
187
|
-
- File paths where the pattern is defined or used
|
|
188
|
-
- README sections or doc comments that describe the convention
|
|
189
|
-
- Code review comments or commit messages (if available)
|
|
190
|
-
|
|
191
|
-
3. **confidence** — "How sure am I?"
|
|
192
|
-
- `0.85-1.0`: Explicit project standard, documented convention, or widely used pattern
|
|
193
|
-
- `0.6-0.85`: Common pattern, reasonable to standardize but not explicitly documented
|
|
194
|
-
- `0.3-0.6`: Potentially useful but context is limited; may need human review
|
|
195
|
-
- Below `0.3`: Do not submit — confidence too low
|
|
196
|
-
|
|
197
|
-
### Extracting Guards (inline enforcement rules)
|
|
198
|
-
|
|
199
|
-
When you identify patterns that **should be enforced** (e.g., "always use X instead of Y"), create a `constraints.guards` entry:
|
|
200
|
-
|
|
201
|
-
```json
|
|
202
|
-
{
|
|
203
|
-
"constraints": {
|
|
204
|
-
"guards": [
|
|
205
|
-
{
|
|
206
|
-
"pattern": "URLSession\\.shared\\.dataTask",
|
|
207
|
-
"severity": "warning",
|
|
208
|
-
"message": "请使用 APIClient.request() 代替直接 URLSession 调用"
|
|
209
|
-
}
|
|
210
|
-
]
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
Severity: `error` (must fix) | `warning` (should fix) | `info` (suggestion)
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## Single File / Module Scan Flow
|
|
220
|
-
1. Read file → find public classes/functions/common patterns
|
|
221
|
-
2. Per-file checklist extraction (10 dimensions above)
|
|
222
|
-
3. Call `autosnippet_search(mode=context)` to mark similarity and fill `relations`
|
|
223
|
-
4. `autosnippet_submit_knowledge` submit single (built-in auto-validate + dedup)
|
|
224
|
-
6. `autosnippet_submit_knowledge` or `autosnippet_submit_knowledge_batch` to submit
|
|
225
|
-
|
|
226
|
-
## Batch Target Scan Flow
|
|
227
|
-
1. `autosnippet_structure(operation=targets)` → select targetName
|
|
228
|
-
2. `autosnippet_structure(operation=files, targetName)`
|
|
229
|
-
3. Parallel scan → per-file checklist extraction → aggregate / dedup / score
|
|
230
|
-
4. `autosnippet_submit_knowledge_batch` batch submit — **all V3 fields are preserved**
|
|
231
|
-
|
|
232
|
-
## Draft File Flow (alternative)
|
|
233
|
-
1. Create draft folder (e.g. `.autosnippet-drafts/`) outside `AutoSnippet/`
|
|
234
|
-
2. Generate one .md per pattern in draft folder
|
|
235
|
-
3. Call `autosnippet_submit_knowledge_batch` with filePaths and `deleteAfterSubmit: true`
|
|
236
|
-
4. Delete draft folder after submit
|
|
237
|
-
|
|
238
|
-
---
|
|
239
|
-
|
|
240
|
-
## MCP Tools for Candidate Workflow
|
|
241
|
-
|
|
242
|
-
| Tool | Usage |
|
|
243
|
-
|------|-------|
|
|
244
|
-
| `autosnippet_structure(operation=targets)` | List project Targets for batch scan |
|
|
245
|
-
| `autosnippet_structure(operation=files)` | Get files for a Target |
|
|
246
|
-
| `autosnippet_structure(operation=metadata)` | Get Target metadata (dependencies, path) |
|
|
247
|
-
| `autosnippet_search(mode=context)` | Find similar existing Recipes → fill `relations` |
|
|
248
|
-
| `autosnippet_submit_knowledge` | Submit single candidate (**all V3 fields**, built-in auto-validate + dedup) |
|
|
249
|
-
| `autosnippet_submit_knowledge_batch` | Batch submit candidates (**all V3 fields preserved**) |
|
|
250
|
-
|
|
251
|
-
---
|
|
252
|
-
|
|
253
|
-
## Key Principles
|
|
254
|
-
|
|
255
|
-
1. **One candidate per pattern** — no "catch-all" candidates
|
|
256
|
-
2. **Maximize information density** — Agent's primary value is extracting structured metadata that humans would skip
|
|
257
|
-
3. **Always fill Layer 1-3 + Reasoning + Recipe-Ready Checklist** at minimum; Layer 4-7 for complex patterns
|
|
258
|
-
4. **Reasoning is mandatory** — Every candidate MUST include `reasoning.whyStandard` + `reasoning.sources` + `reasoning.confidence`. No exceptions.
|
|
259
|
-
5. **V3 必填字段** — title, content(markdown+pattern+rationale), trigger, kind, doClause, dontClause, whenClause, coreCode, description, language, category, headers, knowledgeType, usageGuide, reasoning
|
|
260
|
-
6. **Check `recipeReadyHints` in submit response** — If not empty, supplement fields and resubmit
|
|
261
|
-
7. **Parallel query existing Recipes** during generation to reduce duplicates and fill `relations`
|
|
262
|
-
6. **Code examples**: use Xcode placeholders (`<#URL#>`, `<#Token#>`), explain in `usageGuide`
|
|
263
|
-
7. **Failure**: do not retry same turn; narrow scope or use static context
|
|
264
|
-
|
|
265
|
-
---
|
|
266
|
-
|
|
267
|
-
## Usage Guide Format (CRITICAL)
|
|
268
|
-
|
|
269
|
-
**MUST use Markdown format:**
|
|
270
|
-
- **MUST use `###` section headings** for each major content block
|
|
271
|
-
- **MUST use `-` bullet lists** with each item on its own line
|
|
272
|
-
- **NEVER** put all content in one continuous line
|
|
273
|
-
|
|
274
|
-
**BAD:**
|
|
275
|
-
```
|
|
276
|
-
When to use: Scenario A; Scenario B. Key points: Point 1; Point 2.
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
**GOOD:**
|
|
280
|
-
```
|
|
281
|
-
### When to use
|
|
282
|
-
- Scenario A
|
|
283
|
-
- Scenario B
|
|
284
|
-
|
|
285
|
-
### Key points
|
|
286
|
-
- Point 1: details
|
|
287
|
-
- Point 2: details
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
Recommended sections: When to use / When not to use / Key points / Dependencies / Core steps / Error handling / Performance / Security / Common pitfalls / Related Recipes.
|
|
291
|
-
|
|
292
|
-
---
|
|
293
|
-
|
|
294
|
-
## Semantic Field Enrichment (Two-Pass Workflow)
|
|
295
|
-
|
|
296
|
-
**重要:MCP 不再使用项目内 AI。**外部 Agent 必须自行填写所有字段。
|
|
297
|
-
|
|
298
|
-
### 首选:一次性提交全字段
|
|
299
|
-
|
|
300
|
-
按上述 Layer 1-7 + Recipe-Ready Checklist,提交时尽量填充全部字段。
|
|
301
|
-
|
|
302
|
-
### 备选:二次补全流程
|
|
303
|
-
|
|
304
|
-
Step 1: 提交基本字段(title, content, language)→ 获得 candidate ID(`autosnippet_submit_knowledge` 内置自动校验 + 去重检查)
|
|
305
|
-
Step 2: 根据提交返回的校验结果补全缺失字段
|
|
306
|
-
Step 3: 重新提交完整候选
|
|
307
|
-
|
|
308
|
-
> 注:`autosnippet_enrich_candidates` / `autosnippet_validate_candidate` / `autosnippet_check_duplicate` 已移入 admin 层级。Agent 层级的 `autosnippet_submit_knowledge` 已内置自动校验 + 去重,无需额外调用。
|
|
309
|
-
|
|
310
|
-
需要补全的字段:
|
|
311
|
-
- **语义字段**: content.rationale, knowledgeType, complexity, scope, steps, constraints
|
|
312
|
-
- **Recipe 必填**: kind, doClause, category, trigger, description, headers, usageGuide, reasoning
|
|
313
|
-
|
|
314
|
-
---
|
|
315
|
-
|
|
316
|
-
## Submit Example (batch)
|
|
317
|
-
|
|
318
|
-
```json
|
|
319
|
-
{
|
|
320
|
-
"targetName": "BiliKit",
|
|
321
|
-
"items": [
|
|
322
|
-
{
|
|
323
|
-
"title": "BiliAPI 网络请求封装",
|
|
324
|
-
"content": {
|
|
325
|
-
"markdown": "## BiliAPI 网络请求统一封装\n\n### ✅ 标准用法\n```swift\nclass BiliAPI {\n static func request<T: Decodable>(_ endpoint: Endpoint) async throws -> T {\n let (data, response) = try await URLSession.shared.data(for: endpoint.urlRequest)\n guard let http = response as? HTTPURLResponse, 200..<300 ~= http.statusCode else {\n throw BiliError.invalidResponse\n }\n return try JSONDecoder().decode(T.self, from: data)\n }\n}\n```\n\n### 使用示例\n```swift\nlet user: UserInfo = try await BiliAPI.request(UserInfoEndpoint(uid: uid))\n```\n\n### 要点\n- 所有网络请求统一通过 BiliAPI.request()\n- 支持泛型解码,自动 JSON → Model\n- 统一错误处理和响应验证",
|
|
326
|
-
"pattern": "class BiliAPI {\n static func request<T: Decodable>(_ endpoint: Endpoint) async throws -> T {\n let (data, response) = try await URLSession.shared.data(for: endpoint.urlRequest)\n guard let http = response as? HTTPURLResponse, 200..<300 ~= http.statusCode else {\n throw BiliError.invalidResponse\n }\n return try JSONDecoder().decode(T.self, from: data)\n }\n}",
|
|
327
|
-
"rationale": "统一网络层避免各模块各自实现 URLSession 调用,减少重复代码并统一错误处理策略。"
|
|
328
|
-
},
|
|
329
|
-
"description": "统一的 API 请求封装,支持泛型解码和错误处理",
|
|
330
|
-
"kind": "pattern",
|
|
331
|
-
"doClause": "Use BiliAPI.request() for all network calls with type-safe Decodable responses",
|
|
332
|
-
"language": "swift",
|
|
333
|
-
"category": "Network",
|
|
334
|
-
"trigger": "@bili-api-request",
|
|
335
|
-
"headers": ["import Foundation", "import BiliKit"],
|
|
336
|
-
"knowledgeType": "code-pattern",
|
|
337
|
-
"usageGuide": "### When to use\n- 所有 B 站 API 调用\n- 需要类型安全的响应解码\n\n### Dependencies\n- Foundation\n- BiliKit/Models (Endpoint, BiliError)\n\n### Core steps\n1. 定义 Endpoint\n2. 调用 BiliAPI.request(endpoint)\n3. 处理 Result",
|
|
338
|
-
"complexity": "intermediate",
|
|
339
|
-
"scope": "project-specific",
|
|
340
|
-
"tags": ["networking", "async-await", "generic", "decodable"],
|
|
341
|
-
"steps": [
|
|
342
|
-
{"title": "定义 Endpoint", "description": "创建符合 Endpoint 协议的请求描述", "code": "struct UserInfoEndpoint: Endpoint { ... }"},
|
|
343
|
-
{"title": "发起请求", "description": "调用统一 API 方法", "code": "let user: UserInfo = try await BiliAPI.request(UserInfoEndpoint(uid: uid))"}
|
|
344
|
-
],
|
|
345
|
-
"codeChanges": [
|
|
346
|
-
{"file": "Sources/Network/OldAPI.swift", "before": "URLSession.shared.dataTask(with: url) { ... }", "after": "let result: T = try await BiliAPI.request(endpoint)", "explanation": "替换回调式为 async/await"}
|
|
347
|
-
],
|
|
348
|
-
"constraints": {
|
|
349
|
-
"preconditions": ["需要有效的网络连接", "Endpoint 必须实现 urlRequest 属性"],
|
|
350
|
-
"sideEffects": ["发起网络请求"],
|
|
351
|
-
"guards": [{"pattern": "URLSession\\.shared\\.dataTask", "severity": "warning", "message": "请使用 BiliAPI.request() 统一封装"}]
|
|
352
|
-
},
|
|
353
|
-
"quality": {"codeCompleteness": 0.9, "projectAdaptation": 0.85, "documentationClarity": 0.8},
|
|
354
|
-
"sourceFile": "Sources/BiliKit/Network/BiliAPI.swift",
|
|
355
|
-
"reasoning": {
|
|
356
|
-
"whyStandard": "项目中所有模块都通过 BiliAPI 发起请求,新人经常直接使用 URLSession.shared 导致错误处理不统一和重复代码。沉淀为标准后可通过 Guard 自动检查。",
|
|
357
|
-
"sources": ["Sources/BiliKit/Network/BiliAPI.swift", "Sources/BiliKit/Network/Endpoint.swift", "README.md#networking"],
|
|
358
|
-
"confidence": 0.9,
|
|
359
|
-
"qualitySignals": {"clarity": 0.9, "reusability": 0.85, "importance": 0.9},
|
|
360
|
-
"alternatives": ["直接使用 Alamofire 封装,但项目已选择轻量原生方案"]
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
],
|
|
364
|
-
"source": "cursor-scan",
|
|
365
|
-
"deduplicate": true
|
|
366
|
-
}
|
|
367
|
-
```
|