autosnippet 2.8.3 → 2.10.0

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 (110) hide show
  1. package/README.md +5 -5
  2. package/bin/cli.js +5 -33
  3. package/config/constitution.yaml +9 -2
  4. package/dashboard/dist/assets/{icons-B_Xg4B-s.js → icons-BkT3XrKf.js} +105 -100
  5. package/dashboard/dist/assets/index-BsB7DzW4.css +1 -0
  6. package/dashboard/dist/assets/index-DdmQMrJJ.js +155 -0
  7. package/dashboard/dist/index.html +3 -3
  8. package/lib/cli/AiScanService.js +13 -11
  9. package/lib/cli/KnowledgeSyncService.js +343 -0
  10. package/lib/cli/SetupService.js +9 -27
  11. package/lib/core/ast/ProjectGraph.js +160 -0
  12. package/lib/core/gateway/GatewayActionRegistry.js +48 -58
  13. package/lib/domain/index.js +16 -11
  14. package/lib/domain/knowledge/KnowledgeEntry.js +351 -0
  15. package/lib/domain/knowledge/KnowledgeRepository.js +123 -0
  16. package/lib/domain/knowledge/Lifecycle.js +109 -0
  17. package/lib/domain/knowledge/index.js +27 -0
  18. package/lib/domain/knowledge/values/Constraints.js +125 -0
  19. package/lib/domain/knowledge/values/Content.js +86 -0
  20. package/lib/domain/knowledge/values/Quality.js +93 -0
  21. package/lib/domain/knowledge/values/Reasoning.js +69 -0
  22. package/lib/domain/knowledge/values/Relations.js +168 -0
  23. package/lib/domain/knowledge/values/Stats.js +87 -0
  24. package/lib/domain/knowledge/values/index.js +9 -0
  25. package/lib/external/ai/AiProvider.js +48 -0
  26. package/lib/external/ai/providers/GoogleGeminiProvider.js +12 -3
  27. package/lib/external/mcp/McpServer.js +7 -5
  28. package/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +3 -2
  29. package/lib/external/mcp/handlers/bootstrap.js +121 -12
  30. package/lib/external/mcp/handlers/browse.js +77 -73
  31. package/lib/external/mcp/handlers/candidate.js +29 -276
  32. package/lib/external/mcp/handlers/guard.js +2 -0
  33. package/lib/external/mcp/handlers/knowledge.js +205 -0
  34. package/lib/external/mcp/handlers/skill.js +4 -2
  35. package/lib/external/mcp/handlers/structure.js +25 -23
  36. package/lib/external/mcp/handlers/system.js +10 -12
  37. package/lib/external/mcp/tools.js +125 -138
  38. package/lib/http/HttpServer.js +4 -8
  39. package/lib/http/middleware/requestLogger.js +3 -3
  40. package/lib/http/routes/ai.js +17 -1
  41. package/lib/http/routes/extract.js +48 -4
  42. package/lib/http/routes/knowledge.js +246 -0
  43. package/lib/http/routes/search.js +12 -17
  44. package/lib/http/routes/skills.js +44 -1
  45. package/lib/infrastructure/cache/GraphCache.js +143 -0
  46. package/lib/infrastructure/database/migrations/015_create_token_usage.js +27 -0
  47. package/lib/infrastructure/database/migrations/016_unified_knowledge_entries.js +395 -0
  48. package/lib/infrastructure/external/XcodeAutomation.js +187 -103
  49. package/lib/infrastructure/realtime/RealtimeService.js +14 -2
  50. package/lib/injection/ServiceContainer.js +164 -63
  51. package/lib/repository/knowledge/KnowledgeRepository.impl.js +373 -0
  52. package/lib/repository/token/TokenUsageStore.js +162 -0
  53. package/lib/service/automation/DirectiveDetector.js +2 -3
  54. package/lib/service/automation/FileWatcher.js +67 -28
  55. package/lib/service/automation/XcodeIntegration.js +931 -156
  56. package/lib/service/automation/handlers/AlinkHandler.js +6 -4
  57. package/lib/service/automation/handlers/CreateHandler.js +53 -18
  58. package/lib/service/automation/handlers/GuardHandler.js +183 -20
  59. package/lib/service/automation/handlers/SearchHandler.js +35 -17
  60. package/lib/service/chat/AnalystAgent.js +25 -14
  61. package/lib/service/chat/CandidateGuardrail.js +1 -1
  62. package/lib/service/chat/ChatAgent.js +280 -48
  63. package/lib/service/chat/ContextWindow.js +92 -8
  64. package/lib/service/chat/HandoffProtocol.js +26 -1
  65. package/lib/service/chat/ProducerAgent.js +11 -9
  66. package/lib/service/chat/tools.js +298 -194
  67. package/lib/service/guard/GuardCheckEngine.js +114 -10
  68. package/lib/service/guard/GuardService.js +59 -48
  69. package/lib/service/knowledge/ConfidenceRouter.js +159 -0
  70. package/lib/service/knowledge/KnowledgeFileWriter.js +602 -0
  71. package/lib/service/knowledge/KnowledgeService.js +725 -0
  72. package/lib/service/search/SearchEngine.js +92 -19
  73. package/lib/service/skills/SignalCollector.js +15 -9
  74. package/lib/service/skills/SkillAdvisor.js +13 -11
  75. package/lib/service/snippet/SnippetFactory.js +5 -5
  76. package/lib/service/spm/SpmService.js +119 -18
  77. package/package.json +1 -1
  78. package/scripts/install-cursor-skill.js +0 -6
  79. package/scripts/migrate-md-to-knowledge.mjs +364 -0
  80. package/skills/autosnippet-analysis/SKILL.md +15 -7
  81. package/skills/autosnippet-candidates/SKILL.md +6 -6
  82. package/skills/autosnippet-coldstart/SKILL.md +7 -3
  83. package/skills/autosnippet-concepts/SKILL.md +7 -6
  84. package/skills/autosnippet-create/SKILL.md +13 -13
  85. package/skills/autosnippet-intent/SKILL.md +3 -2
  86. package/skills/autosnippet-lifecycle/SKILL.md +5 -5
  87. package/skills/autosnippet-recipes/SKILL.md +16 -4
  88. package/templates/constitution.yaml +1 -1
  89. package/templates/copilot-instructions.md +6 -6
  90. package/templates/recipes-setup/README.md +3 -3
  91. package/dashboard/dist/assets/index-CkIih2CC.css +0 -1
  92. package/dashboard/dist/assets/index-Duc8Qk-c.js +0 -197
  93. package/lib/cli/CandidateSyncService.js +0 -261
  94. package/lib/cli/SyncService.js +0 -356
  95. package/lib/domain/candidate/Candidate.js +0 -196
  96. package/lib/domain/candidate/CandidateRepository.js +0 -107
  97. package/lib/domain/candidate/Reasoning.js +0 -52
  98. package/lib/domain/recipe/Recipe.js +0 -421
  99. package/lib/domain/recipe/RecipeRepository.js +0 -54
  100. package/lib/domain/types/CandidateStatus.js +0 -52
  101. package/lib/http/routes/candidates.js +0 -559
  102. package/lib/http/routes/recipes.js +0 -397
  103. package/lib/repository/candidate/CandidateRepository.impl.js +0 -230
  104. package/lib/repository/recipe/RecipeRepository.impl.js +0 -498
  105. package/lib/service/candidate/CandidateAggregator.js +0 -52
  106. package/lib/service/candidate/CandidateFileWriter.js +0 -383
  107. package/lib/service/candidate/CandidateService.js +0 -973
  108. package/lib/service/recipe/RecipeFileWriter.js +0 -514
  109. package/lib/service/recipe/RecipeService.js +0 -786
  110. package/lib/service/recipe/RecipeStatsTracker.js +0 -148
@@ -1,196 +0,0 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { CandidateStatus, isValidStateTransition } from '../types/CandidateStatus.js';
3
- import Reasoning from './Reasoning.js';
4
- import Logger from '../../infrastructure/logging/Logger.js';
5
-
6
- /**
7
- * Candidate - 代码片段候选实体
8
- * 代表一个待审批的代码片段
9
- */
10
- export class Candidate {
11
- constructor(props) {
12
- this.id = props.id || uuidv4();
13
- this.code = props.code;
14
- this.language = props.language; // javascript, python, swift, etc
15
- this.category = props.category; // 分类:pattern, utility, hook, etc
16
- this.source = props.source; // AI, user, imported, etc
17
-
18
- // Reasoning 对象 — 所有提交路径必须提供推理依据
19
- this.reasoning = props.reasoning instanceof Reasoning
20
- ? props.reasoning
21
- : new Reasoning(props.reasoning || {});
22
-
23
- // 状态管理
24
- this.status = props.status || CandidateStatus.PENDING;
25
- this.statusHistory = props.statusHistory || [];
26
-
27
- // 元数据
28
- this.createdBy = props.createdBy || 'unknown';
29
- this.createdAt = props.createdAt || Math.floor(Date.now() / 1000);
30
- this.updatedAt = props.updatedAt || Math.floor(Date.now() / 1000);
31
- this.approvedAt = props.approvedAt;
32
- this.approvedBy = props.approvedBy;
33
-
34
- // 额外信息
35
- this.rejectionReason = props.rejectionReason;
36
- this.rejectedBy = props.rejectedBy;
37
- this.appliedRecipeId = props.appliedRecipeId; // 应用到的 Recipe
38
- this.metadata = props.metadata || {}; // 附加元数据
39
-
40
- this.logger = Logger.getInstance();
41
- }
42
-
43
- /**
44
- * 验证 Candidate 的完整性
45
- */
46
- isValid() {
47
- return (
48
- this.code &&
49
- this.code.trim().length > 0 &&
50
- this.language &&
51
- this.language.trim().length > 0 &&
52
- this.reasoning.isValid() &&
53
- this.createdBy
54
- );
55
- }
56
-
57
- /**
58
- * 验证代码内容(格式等)
59
- */
60
- validateCodeContent() {
61
- if (!this.code || this.code.trim().length === 0) {
62
- return { valid: false, error: 'Code cannot be empty' };
63
- }
64
-
65
- if (this.code.length > 50000) {
66
- return { valid: false, error: 'Code is too long (max 50000 chars)' };
67
- }
68
-
69
- return { valid: true };
70
- }
71
-
72
- /**
73
- * 批准 Candidate
74
- */
75
- approve(approver) {
76
- if (!isValidStateTransition(this.status, CandidateStatus.APPROVED)) {
77
- return {
78
- success: false,
79
- error: `Cannot approve a Candidate in ${this.status} status`,
80
- };
81
- }
82
-
83
- this._changeStatus(CandidateStatus.APPROVED);
84
- this.approvedAt = Math.floor(Date.now() / 1000);
85
- this.approvedBy = approver;
86
-
87
- this.logger.info('Candidate approved', {
88
- candidateId: this.id,
89
- approver,
90
- });
91
-
92
- return { success: true, candidate: this };
93
- }
94
-
95
- /**
96
- * 拒绝 Candidate
97
- */
98
- reject(reason, rejectedBy = 'system') {
99
- if (!isValidStateTransition(this.status, CandidateStatus.REJECTED)) {
100
- return {
101
- success: false,
102
- error: `Cannot reject a Candidate in ${this.status} status`,
103
- };
104
- }
105
-
106
- this._changeStatus(CandidateStatus.REJECTED);
107
- this.rejectionReason = reason;
108
- this.rejectedBy = rejectedBy;
109
- this.updatedAt = Math.floor(Date.now() / 1000);
110
-
111
- this.logger.info('Candidate rejected', {
112
- candidateId: this.id,
113
- rejectedBy,
114
- reason,
115
- });
116
-
117
- return { success: true, candidate: this };
118
- }
119
-
120
- /**
121
- * 应用到 Recipe
122
- */
123
- applyToRecipe(recipeId) {
124
- if (!isValidStateTransition(this.status, CandidateStatus.APPLIED)) {
125
- return {
126
- success: false,
127
- error: `Cannot apply a Candidate in ${this.status} status`,
128
- };
129
- }
130
-
131
- this._changeStatus(CandidateStatus.APPLIED);
132
- this.appliedRecipeId = recipeId;
133
- this.updatedAt = Math.floor(Date.now() / 1000);
134
-
135
- this.logger.info('Candidate applied to recipe', {
136
- candidateId: this.id,
137
- recipeId,
138
- });
139
-
140
- return { success: true, candidate: this };
141
- }
142
-
143
- /**
144
- * 获取状态历史
145
- */
146
- getStatusHistory() {
147
- return this.statusHistory;
148
- }
149
-
150
- /**
151
- * 改变状态(内部方法)
152
- */
153
- _changeStatus(newStatus) {
154
- this.statusHistory.push({
155
- from: this.status,
156
- to: newStatus,
157
- changedAt: Math.floor(Date.now() / 1000),
158
- });
159
- this.status = newStatus;
160
- this.updatedAt = Math.floor(Date.now() / 1000);
161
- }
162
-
163
- /**
164
- * 转换为 JSON
165
- */
166
- toJSON() {
167
- return {
168
- id: this.id,
169
- code: this.code,
170
- language: this.language,
171
- category: this.category,
172
- source: this.source,
173
- reasoning: this.reasoning.toJSON(),
174
- status: this.status,
175
- statusHistory: this.statusHistory,
176
- createdBy: this.createdBy,
177
- createdAt: this.createdAt,
178
- updatedAt: this.updatedAt,
179
- approvedAt: this.approvedAt,
180
- approvedBy: this.approvedBy,
181
- rejectionReason: this.rejectionReason,
182
- rejectedBy: this.rejectedBy,
183
- appliedRecipeId: this.appliedRecipeId,
184
- metadata: this.metadata,
185
- };
186
- }
187
-
188
- /**
189
- * 从 JSON 创建 Candidate
190
- */
191
- static fromJSON(data) {
192
- return new Candidate(data);
193
- }
194
- }
195
-
196
- export default Candidate;
@@ -1,107 +0,0 @@
1
- /**
2
- * CandidateRepository - Candidate 仓储接口
3
- * 定义数据访问的契约
4
- */
5
- export class CandidateRepository {
6
- /**
7
- * 创建 Candidate
8
- * @param {Candidate} candidate
9
- * @returns {Promise<Candidate>}
10
- */
11
- async create(candidate) {
12
- throw new Error('Not implemented');
13
- }
14
-
15
- /**
16
- * 根据 ID 获取 Candidate
17
- * @param {string} id
18
- * @returns {Promise<Candidate|null>}
19
- */
20
- async findById(id) {
21
- throw new Error('Not implemented');
22
- }
23
-
24
- /**
25
- * 获取所有 Candidates
26
- * @param {Object} filters
27
- * @returns {Promise<Candidate[]>}
28
- */
29
- async findAll(filters = {}) {
30
- throw new Error('Not implemented');
31
- }
32
-
33
- /**
34
- * 根据条件查询 Candidates
35
- * @param {Object} query
36
- * @returns {Promise<Candidate[]>}
37
- */
38
- async query(query) {
39
- throw new Error('Not implemented');
40
- }
41
-
42
- /**
43
- * 更新 Candidate
44
- * @param {string} id
45
- * @param {Object} updates
46
- * @returns {Promise<Candidate>}
47
- */
48
- async update(id, updates) {
49
- throw new Error('Not implemented');
50
- }
51
-
52
- /**
53
- * 删除 Candidate
54
- * @param {string} id
55
- * @returns {Promise<boolean>}
56
- */
57
- async delete(id) {
58
- throw new Error('Not implemented');
59
- }
60
-
61
- /**
62
- * 按状态查询
63
- * @param {string} status
64
- * @param {Object} pagination
65
- * @returns {Promise<{candidates: Candidate[], total: number}>}
66
- */
67
- async findByStatus(status, pagination = {}) {
68
- throw new Error('Not implemented');
69
- }
70
-
71
- /**
72
- * 按语言查询
73
- * @param {string} language
74
- * @returns {Promise<Candidate[]>}
75
- */
76
- async findByLanguage(language) {
77
- throw new Error('Not implemented');
78
- }
79
-
80
- /**
81
- * 按创建者查询
82
- * @param {string} createdBy
83
- * @returns {Promise<Candidate[]>}
84
- */
85
- async findByCreatedBy(createdBy) {
86
- throw new Error('Not implemented');
87
- }
88
-
89
- /**
90
- * 搜索 Candidates
91
- * @param {string} keyword
92
- * @returns {Promise<Candidate[]>}
93
- */
94
- async search(keyword) {
95
- throw new Error('Not implemented');
96
- }
97
-
98
- /**
99
- * 获取统计信息
100
- * @returns {Promise<{total: number, byStatus: Object}>}
101
- */
102
- async getStats() {
103
- throw new Error('Not implemented');
104
- }
105
- }
106
-
107
- export default CandidateRepository;
@@ -1,52 +0,0 @@
1
- /**
2
- * Reasoning - 值对象,代表 AI 决策的理由
3
- * 包含 Candidate 创建时的决策信息
4
- */
5
- export class Reasoning {
6
- constructor(props) {
7
- this.whyStandard = props.whyStandard; // 为什么遵循标准
8
- this.sources = props.sources || []; // 来源列表
9
- this.qualitySignals = props.qualitySignals || {}; // 质量信号(如 clarity, reusability)
10
- this.alternatives = props.alternatives || []; // 备选方案
11
- this.confidence = props.confidence || 0.7; // 置信度 0-1(统一默认值)
12
- this.generatedAt = props.generatedAt || new Date().toISOString();
13
- }
14
-
15
- /**
16
- * 验证推理信息的完整性
17
- */
18
- isValid() {
19
- return (
20
- this.whyStandard &&
21
- this.whyStandard.trim().length > 0 &&
22
- Array.isArray(this.sources) &&
23
- this.sources.length > 0 &&
24
- typeof this.confidence === 'number' &&
25
- this.confidence >= 0 &&
26
- this.confidence <= 1
27
- );
28
- }
29
-
30
- /**
31
- * 转换为 JSON
32
- */
33
- toJSON() {
34
- return {
35
- whyStandard: this.whyStandard,
36
- sources: this.sources,
37
- qualitySignals: this.qualitySignals,
38
- alternatives: this.alternatives,
39
- confidence: this.confidence,
40
- generatedAt: this.generatedAt,
41
- };
42
- }
43
-
44
- /**
45
- * 从 JSON 创建 Reasoning
46
- */
47
- static fromJSON(data) {
48
- return new Reasoning(data);
49
- }
50
- }
51
-
52
- export default Reasoning;