autosnippet 3.2.8 → 3.2.9

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 (113) hide show
  1. package/bin/cli.js +6 -5
  2. package/dashboard/dist/assets/index-BTAsOZv2.js +128 -0
  3. package/dashboard/dist/assets/index-C_72Ct98.css +1 -0
  4. package/dashboard/dist/index.html +2 -2
  5. package/lib/cli/AiScanService.js +23 -26
  6. package/lib/cli/SetupService.js +1 -1
  7. package/lib/core/AstAnalyzer.js +1 -1
  8. package/lib/core/discovery/index.js +2 -2
  9. package/lib/external/ai/AiProvider.js +66 -172
  10. package/lib/external/ai/providers/GoogleGeminiProvider.js +23 -1
  11. package/lib/external/mcp/handlers/bootstrap/BootstrapSession.js +1 -1
  12. package/lib/external/mcp/handlers/bootstrap/ExternalSubmissionTracker.js +3 -3
  13. package/lib/external/mcp/handlers/bootstrap/MissionBriefingBuilder.js +1 -1
  14. package/lib/external/mcp/handlers/bootstrap/pipeline/IncrementalBootstrap.js +1 -1
  15. package/lib/external/mcp/handlers/bootstrap/pipeline/dimension-context.js +8 -8
  16. package/lib/external/mcp/handlers/bootstrap/pipeline/noAiFallback.js +1 -1
  17. package/lib/external/mcp/handlers/bootstrap/pipeline/orchestrator.js +287 -204
  18. package/lib/external/mcp/handlers/bootstrap/shared/bootstrap-phases.js +7 -6
  19. package/lib/external/mcp/handlers/bootstrap/shared/dimension-sop.js +1 -1
  20. package/lib/external/mcp/handlers/bootstrap-internal.js +2 -2
  21. package/lib/external/mcp/handlers/dimension-complete-external.js +6 -6
  22. package/lib/http/HttpServer.js +1 -1
  23. package/lib/http/middleware/requestLogger.js +1 -0
  24. package/lib/http/routes/ai.js +240 -35
  25. package/lib/http/routes/candidates.js +2 -3
  26. package/lib/http/routes/extract.js +13 -11
  27. package/lib/http/routes/modules.js +2 -2
  28. package/lib/http/routes/recipes.js +9 -5
  29. package/lib/http/routes/remote.js +134 -255
  30. package/lib/http/routes/violations.js +0 -54
  31. package/lib/http/utils/sse-sessions.js +1 -1
  32. package/lib/infrastructure/logging/Logger.js +5 -4
  33. package/lib/infrastructure/monitoring/PerformanceMonitor.js +3 -2
  34. package/lib/injection/ServiceContainer.js +64 -17
  35. package/lib/platform/ScreenCaptureService.js +177 -0
  36. package/lib/platform/ios/routes/spm.js +2 -2
  37. package/lib/service/agent/AgentEventBus.js +207 -0
  38. package/lib/service/agent/AgentFactory.js +490 -0
  39. package/lib/service/agent/AgentMessage.js +240 -0
  40. package/lib/service/agent/AgentRouter.js +228 -0
  41. package/lib/service/agent/AgentRuntime.js +1016 -0
  42. package/lib/service/agent/AgentState.js +217 -0
  43. package/lib/service/agent/IntentClassifier.js +331 -0
  44. package/lib/service/agent/LarkTransport.js +389 -0
  45. package/lib/service/agent/capabilities.js +408 -0
  46. package/lib/service/{chat → agent/context}/ContextWindow.js +37 -12
  47. package/lib/service/{chat → agent/context}/ExplorationTracker.js +25 -14
  48. package/lib/service/{chat → agent/core}/ChatAgentPrompts.js +1 -1
  49. package/lib/service/agent/core/LoopContext.js +170 -0
  50. package/lib/service/agent/core/MessageAdapter.js +223 -0
  51. package/lib/service/agent/core/ToolExecutionPipeline.js +376 -0
  52. package/lib/service/{chat → agent/domain}/ChatAgentTasks.js +19 -98
  53. package/lib/service/{chat → agent/domain}/EpisodicConsolidator.js +7 -7
  54. package/lib/service/{chat → agent/domain}/EvidenceCollector.js +4 -2
  55. package/lib/service/{chat/AnalystAgent.js → agent/domain/insight-analyst.js} +37 -172
  56. package/lib/service/{chat/HandoffProtocol.js → agent/domain/insight-gate.js} +85 -135
  57. package/lib/service/agent/domain/insight-producer.js +267 -0
  58. package/lib/service/agent/domain/scan-prompts.js +105 -0
  59. package/lib/service/agent/forced-summary.js +266 -0
  60. package/lib/service/agent/index.js +91 -0
  61. package/lib/service/{chat → agent}/memory/MemoryCoordinator.js +7 -7
  62. package/lib/service/{chat/ProjectSemanticMemory.js → agent/memory/PersistentMemory.js} +359 -89
  63. package/lib/service/{chat → agent}/memory/SessionStore.js +1 -1
  64. package/lib/service/{chat → agent}/memory/index.js +1 -1
  65. package/lib/service/agent/policies.js +442 -0
  66. package/lib/service/agent/presets.js +303 -0
  67. package/lib/service/agent/strategies.js +717 -0
  68. package/lib/service/{chat → agent/tools}/ToolRegistry.js +3 -3
  69. package/lib/service/agent/tools/ai-analysis.js +75 -0
  70. package/lib/service/{chat → agent}/tools/composite.js +2 -1
  71. package/lib/service/{chat → agent}/tools/guard.js +1 -121
  72. package/lib/service/{chat → agent}/tools/index.js +27 -21
  73. package/lib/service/{chat → agent}/tools/infrastructure.js +1 -1
  74. package/lib/service/agent/tools/knowledge-graph.js +112 -0
  75. package/lib/service/agent/tools/scan-recipe.js +189 -0
  76. package/lib/service/agent/tools/system-interaction.js +476 -0
  77. package/lib/service/automation/DirectiveDetector.js +0 -1
  78. package/lib/service/automation/FileWatcher.js +0 -8
  79. package/lib/service/automation/handlers/CreateHandler.js +7 -3
  80. package/lib/service/automation/handlers/DraftHandler.js +7 -6
  81. package/lib/service/module/ModuleService.js +40 -73
  82. package/lib/service/skills/SignalCollector.js +26 -19
  83. package/lib/service/snippet/codecs/VSCodeCodec.js +1 -1
  84. package/lib/shared/FieldSpec.js +1 -1
  85. package/lib/shared/StyleGuide.js +1 -1
  86. package/package.json +4 -1
  87. package/resources/native-ui/screenshot.swift +228 -0
  88. package/dashboard/dist/assets/index-D5jiDBQG.css +0 -1
  89. package/dashboard/dist/assets/index-e5OKj-Ni.js +0 -128
  90. package/lib/core/discovery/SpmDiscoverer.js +0 -5
  91. package/lib/external/mcp/handlers/bootstrap/pipeline/EpisodicMemory.js +0 -750
  92. package/lib/external/mcp/handlers/bootstrap/pipeline/ToolResultCache.js +0 -277
  93. package/lib/http/routes/spm.js +0 -5
  94. package/lib/infrastructure/external/XcodeAutomation.js +0 -15
  95. package/lib/service/chat/ChatAgent.js +0 -1602
  96. package/lib/service/chat/Memory.js +0 -161
  97. package/lib/service/chat/ProducerAgent.js +0 -431
  98. package/lib/service/chat/ReasoningTrace.js +0 -523
  99. package/lib/service/chat/TaskPipeline.js +0 -357
  100. package/lib/service/chat/WorkingMemory.js +0 -359
  101. package/lib/service/chat/memory/PersistentMemory.js +0 -450
  102. package/lib/service/chat/tools/ai-analysis.js +0 -267
  103. package/lib/service/chat/tools/knowledge-graph.js +0 -234
  104. package/lib/service/chat/tools.js +0 -18
  105. package/lib/service/snippet/PlaceholderConverter.js +0 -5
  106. package/lib/service/snippet/codecs/XcodeCodec.js +0 -5
  107. /package/lib/service/{chat → agent}/ConversationStore.js +0 -0
  108. /package/lib/service/{chat → agent}/memory/ActiveContext.js +0 -0
  109. /package/lib/service/{chat → agent}/tools/_shared.js +0 -0
  110. /package/lib/service/{chat → agent}/tools/ast-graph.js +0 -0
  111. /package/lib/service/{chat → agent}/tools/lifecycle.js +0 -0
  112. /package/lib/service/{chat → agent}/tools/project-access.js +0 -0
  113. /package/lib/service/{chat → agent}/tools/query.js +0 -0
@@ -1,26 +1,25 @@
1
1
  /**
2
- * AnalystAgent.js — v3.0 分析者 Agent
2
+ * insight-analyst.js — Insight Analyst 领域函数
3
3
  *
4
- * 职责:
5
- * - 使用 AST 工具 + 文件搜索工具自由探索代码库
6
- * - 输出自然语言分析结果 (无格式约束)
7
- * - 不提交候选、不关心格式
4
+ * 从旧 AnalystAgent.js 提取的纯领域逻辑:
5
+ * - Analyst System Prompt
6
+ * - 工具白名单
7
+ * - 预算常量
8
+ * - 9 段式 Prompt 构建器
8
9
  *
9
- * 设计哲学:
10
- * "给 AI 一个任务描述和一套好工具,让它像资深工程师一样自由探索代码库。"
10
+ * 被 PipelineStrategy 的 bootstrap preset 直接引用。
11
+ * 不再包含任何 Agent 类 — Agent 由 AgentRuntime + PipelineStrategy 驱动。
11
12
  *
12
- * @module AnalystAgent
13
+ * @module insight-analyst
13
14
  */
14
15
 
15
- import Logger from '../../infrastructure/logging/Logger.js';
16
- import { analysisQualityGate, buildAnalysisReport, buildAnalysisArtifact, buildRetryPrompt } from './HandoffProtocol.js';
17
- import { getDimensionSOP } from '../../external/mcp/handlers/bootstrap/shared/dimension-sop.js';
16
+ import { getDimensionSOP } from '../../../external/mcp/handlers/bootstrap/shared/dimension-sop.js';
18
17
 
19
18
  // ──────────────────────────────────────────────────────────────────
20
19
  // System Prompt — Analyst 专用 (~100 tokens)
21
20
  // ──────────────────────────────────────────────────────────────────
22
21
 
23
- const ANALYST_SYSTEM_PROMPT = `你是一位高级软件架构师,正在深度分析一个真实项目的某个维度。
22
+ export const ANALYST_SYSTEM_PROMPT = `你是一位高级软件架构师,正在深度分析一个真实项目的某个维度。
24
23
 
25
24
  ## 执行计划
26
25
  你有 **N 轮**工具调用机会(系统会告知具体数字)。请严格按以下节奏分配:
@@ -50,7 +49,7 @@ const ANALYST_SYSTEM_PROMPT = `你是一位高级软件架构师,正在深度
50
49
  // Analyst 可用工具白名单 — 只做探索,不做提交
51
50
  // ──────────────────────────────────────────────────────────────────
52
51
 
53
- const ANALYST_TOOLS = [
52
+ export const ANALYST_TOOLS = [
54
53
  // AST 结构化分析
55
54
  'get_project_overview',
56
55
  'get_class_hierarchy',
@@ -77,30 +76,42 @@ const ANALYST_TOOLS = [
77
76
  // Analyst 预算 — 使用 analyst 策略(自由探索,无阶段约束)
78
77
  // ──────────────────────────────────────────────────────────────────
79
78
 
80
- const ANALYST_BUDGET = {
81
- maxIterations: 24, // was 18 — 大项目维度需要充足探索轮次
82
- searchBudget: 18, // was 14 — 匹配更大探索空间
83
- searchBudgetGrace: 10, // was 8
84
- maxSubmits: 0, // Analyst 不提交候选
79
+ export const ANALYST_BUDGET = {
80
+ maxIterations: 24,
81
+ searchBudget: 18,
82
+ searchBudgetGrace: 10,
83
+ maxSubmits: 0,
85
84
  softSubmitLimit: 0,
86
- idleRoundsToExit: 2, // 减少空转
85
+ idleRoundsToExit: 2,
87
86
  };
88
87
 
89
88
  // ──────────────────────────────────────────────────────────────────
90
- // 维度 Prompt 模板
89
+ // 维度 Prompt 模板 (9 段式)
91
90
  // ──────────────────────────────────────────────────────────────────
92
91
 
93
92
  /**
94
93
  * 构建 Analyst Prompt
95
- * @param {object} dimConfig — 维度配置 { id, label, guide, focusKeywords }
94
+ *
95
+ * 9 段结构:
96
+ * §1 任务描述
97
+ * §2 维度指引
98
+ * §3 SOP (分析步骤 + 常见错误)
99
+ * §4 输出要求
100
+ * §5 工具提示
101
+ * §6 前序维度上下文 (SessionStore / DimensionContext)
102
+ * §7 Tier Reflection 洞察
103
+ * §8 历史语义记忆 (Tier 3)
104
+ * §9 代码实体图谱 (Phase E)
105
+ *
106
+ * @param {object} dimConfig — 维度配置 { id, label, guide, focusKeywords, outputType }
96
107
  * @param {object} projectInfo — { name, lang, fileCount }
97
108
  * @param {object} [dimensionContext] — DimensionContext 实例 (跨维度上下文)
98
- * @param {object} [episodicMemory] — EpisodicMemory 实例 (v4.0 增强上下文)
99
- * @param {object} [semanticMemory] — ProjectSemanticMemory 实例 (v4.1 历史记忆)
109
+ * @param {object} [episodicMemory] — SessionStore 实例 (v4.0 增强上下文)
110
+ * @param {object} [semanticMemory] — PersistentMemory 实例 (v4.1 历史记忆)
100
111
  * @param {object} [codeEntityGraph] — CodeEntityGraph 实例 (Phase E 代码实体图谱)
101
112
  * @returns {string}
102
113
  */
103
- function buildAnalystPrompt(
114
+ export function buildAnalystPrompt(
104
115
  dimConfig,
105
116
  projectInfo,
106
117
  dimensionContext,
@@ -137,8 +148,6 @@ function buildAnalystPrompt(
137
148
  }
138
149
  }
139
150
  } else if (dimConfig.guide) {
140
- // 回退: 无 SOP 的维度使用 guide 作为关注要点
141
- // guide 格式如 "命名约定、注释风格、文件组织规范",按分隔符拆分为列表
142
151
  const items = dimConfig.guide.split(/[、,,/]/).map(s => s.trim()).filter(Boolean);
143
152
  if (items.length > 1) {
144
153
  parts.push(`重点关注:\n${items.map((f) => `- ${f}`).join('\n')}`);
@@ -170,8 +179,6 @@ ${depthHint}
170
179
  parts.push('使用 get_previous_evidence 工具查询前序维度对特定文件/类的分析证据,避免重复搜索。');
171
180
 
172
181
  // §6 前序维度分析摘要 (Tier 2+ 才有)
173
- // v4.0: 优先使用 EpisodicMemory (更丰富的发现 + 文件清单 + 交叉引用),
174
- // 回退到 DimensionContext (兼容)
175
182
  if (episodicMemory) {
176
183
  const emContext = episodicMemory.buildContextForDimension(
177
184
  dimConfig.id,
@@ -204,7 +211,7 @@ ${depthHint}
204
211
  }
205
212
  }
206
213
 
207
- // §8: 历史语义记忆 (Tier 3) — 上次 Bootstrap 遗留的项目级知识
214
+ // §8: 历史语义记忆 (Tier 3)
208
215
  if (semanticMemory) {
209
216
  try {
210
217
  const query = `${dimConfig.label} ${dimConfig.guide || ''} ${projectInfo.lang}`;
@@ -221,7 +228,7 @@ ${depthHint}
221
228
  }
222
229
  }
223
230
 
224
- // §9: 代码实体图谱 (Phase E) — 类/协议/Category 关系拓扑
231
+ // §9: 代码实体图谱 (Phase E)
225
232
  if (codeEntityGraph) {
226
233
  try {
227
234
  const graphCtx = codeEntityGraph.generateContextForAgent({ maxEntities: 20, maxEdges: 40 });
@@ -236,145 +243,3 @@ ${depthHint}
236
243
 
237
244
  return parts.join('\n\n');
238
245
  }
239
-
240
- // ──────────────────────────────────────────────────────────────────
241
- // AnalystAgent 类
242
- // ──────────────────────────────────────────────────────────────────
243
-
244
- export class AnalystAgent {
245
- /** @type {import('./ChatAgent.js').ChatAgent} */
246
- #chatAgent;
247
-
248
- /** @type {import('../../core/ast/ProjectGraph.js').default} */
249
- #projectGraph;
250
-
251
- /** @type {import('../../infrastructure/logging/Logger.js').default} */
252
- #logger;
253
-
254
- /** @type {number} Gate 最大重试次数 */
255
- #maxRetries;
256
-
257
- /**
258
- * @param {object} chatAgent — ChatAgent 实例
259
- * @param {object} [projectGraph] — ProjectGraph 实例
260
- * @param {object} [options]
261
- * @param {number} [options.maxRetries=1] — Gate 失败最大重试次数
262
- */
263
- constructor(chatAgent, projectGraph = null, options = {}) {
264
- this.#chatAgent = chatAgent;
265
- this.#projectGraph = projectGraph;
266
- this.#logger = Logger.getInstance();
267
- this.#maxRetries = options.maxRetries ?? 1;
268
- }
269
-
270
- /**
271
- * 分析指定维度
272
- *
273
- * @param {object} dimConfig — 维度配置 { id, label, guide, focusKeywords }
274
- * @param {object} projectInfo — { name, lang, fileCount }
275
- * @param {object} [options]
276
- * @param {string} [options.sessionId] — Bootstrap session ID
277
- * @param {object} [options.dimensionContext] — DimensionContext 实例
278
- * @returns {Promise<import('./HandoffProtocol.js').AnalysisReport>}
279
- */
280
- async analyze(dimConfig, projectInfo, options = {}) {
281
- const dimId = dimConfig.id;
282
- const prompt = buildAnalystPrompt(
283
- dimConfig,
284
- projectInfo,
285
- options.dimensionContext,
286
- options.memoryCoordinator?.getSessionStore(), // v5.0: SessionStore 提供跨维度上下文
287
- options.semanticMemory, // v4.1: ProjectSemanticMemory 历史记忆
288
- options.codeEntityGraph // Phase E: CodeEntityGraph 代码实体图谱
289
- );
290
-
291
- this.#logger.info(
292
- `[AnalystAgent] ▶ analyzing dimension "${dimId}" — prompt ${prompt.length} chars`
293
- );
294
-
295
- let retries = 0;
296
- let lastReport = null;
297
-
298
- while (retries <= this.#maxRetries) {
299
- const execPrompt =
300
- retries === 0
301
- ? prompt
302
- : `${prompt}\n\n${buildRetryPrompt(lastReport?._gateReason || 'Analysis too short')}`;
303
-
304
- try {
305
- const result = await this.#chatAgent.execute(execPrompt, {
306
- source: 'system',
307
- conversationId: options.sessionId ? `analyst-${options.sessionId}-${dimId}` : undefined,
308
- budget: ANALYST_BUDGET,
309
- systemPromptOverride: ANALYST_SYSTEM_PROMPT,
310
- allowedTools: ANALYST_TOOLS,
311
- strategy: 'analyst',
312
- temperature: 0.4,
313
- dimensionMeta: {
314
- id: dimId,
315
- outputType: 'analysis',
316
- allowedKnowledgeTypes: dimConfig.allowedKnowledgeTypes || [],
317
- },
318
- // v5.0: 统一 MemoryCoordinator
319
- memoryCoordinator: options.memoryCoordinator || undefined,
320
- });
321
-
322
- // v5.0: 当有 MemoryCoordinator 时使用 ActiveContext 的 distill 结果
323
- // 构建 AnalysisArtifact (包含 evidenceMap/findings/negativeSignals)
324
- // 使用显式 scopeId 确保并行执行安全
325
- const analystScopeId = `${dimId}:analyst`;
326
- const ac = options.memoryCoordinator?.getActiveContext(analystScopeId);
327
- const report = ac
328
- ? buildAnalysisArtifact(result, dimId, this.#projectGraph, ac)
329
- : buildAnalysisReport(result, dimId, this.#projectGraph);
330
-
331
- // 附加推理链数据(如果 ChatAgent 返回了 ReasoningTrace)
332
- if (result.reasoningTrace) {
333
- report.reasoningStats = result.reasoningTrace.getStats();
334
- report.thoughts = result.reasoningTrace.getThoughts();
335
- }
336
- if (result.reasoningQuality) {
337
- report.reasoningQuality = result.reasoningQuality;
338
- }
339
-
340
- // 质量门控 — 传入 outputType 以调整门槛
341
- const gate = analysisQualityGate(report, {
342
- outputType: dimConfig.outputType || 'analysis',
343
- });
344
- if (gate.pass) {
345
- this.#logger.info(
346
- `[AnalystAgent] ✅ dimension "${dimId}" — ${report.analysisText.length} chars, ${report.referencedFiles.length} files referenced, ${report.metadata.toolCallCount} tool calls`
347
- );
348
- return report;
349
- }
350
-
351
- this.#logger.warn(
352
- `[AnalystAgent] ⚠ Gate failed for "${dimId}": ${gate.reason} (action=${gate.action})`
353
- );
354
-
355
- if (gate.action === 'degrade') {
356
- // 直接降级 — 不重试
357
- report._gateResult = gate;
358
- return report;
359
- }
360
-
361
- // retry
362
- lastReport = report;
363
- lastReport._gateReason = gate.reason;
364
- retries++;
365
- } catch (err) {
366
- this.#logger.error(`[AnalystAgent] ❌ dimension "${dimId}" error: ${err.message}`);
367
- // 返回空 report
368
- return buildAnalysisReport({ reply: '', toolCalls: [] }, dimId, this.#projectGraph);
369
- }
370
- }
371
-
372
- // 重试耗尽 — 返回最后一次结果
373
- this.#logger.warn(`[AnalystAgent] Retries exhausted for "${dimId}" — returning last report`);
374
- return (
375
- lastReport || buildAnalysisReport({ reply: '', toolCalls: [] }, dimId, this.#projectGraph)
376
- );
377
- }
378
- }
379
-
380
- export default AnalystAgent;