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
@@ -0,0 +1,170 @@
1
+ /**
2
+ * LoopContext — reactLoop 单次执行的完整状态
3
+ *
4
+ * 封装原 reactLoop 内散落的 10+ 局部变量:
5
+ * - 注入依赖 (messages, tracker, trace, memoryCoordinator, sharedState)
6
+ * - 循环状态 (iteration, lastReply, toolCalls, tokenUsage)
7
+ * - 错误恢复 (consecutiveAiErrors, consecutiveEmptyResponses)
8
+ * - 配置 (source, budget, capabilities, baseSystemPrompt, toolSchemas, prompt)
9
+ *
10
+ * 使 reactLoop 的提取方法只需接收一个 ctx 参数。
11
+ *
12
+ * @module core/LoopContext
13
+ */
14
+
15
+ /**
16
+ * @typedef {Object} LoopContextConfig
17
+ * @property {import('./MessageAdapter.js').MessageAdapter} messages — 统一消息适配器
18
+ * @property {Object|null} [tracker] — ExplorationTracker 实例
19
+ * @property {Object|null} [trace] — ActiveContext 实例
20
+ * @property {Object|null} [memoryCoordinator] — MemoryCoordinator 实例
21
+ * @property {Object|null} [sharedState] — 共享状态 { submittedTitles, submittedPatterns }
22
+ * @property {string} [source] — 'user' | 'system'
23
+ * @property {Object} budget — 预算配置
24
+ * @property {import('../capabilities.js').Capability[]} capabilities — 本轮使用的 capabilities
25
+ * @property {string} baseSystemPrompt — 基础系统提示词
26
+ * @property {Array} toolSchemas — 工具 schema 列表
27
+ * @property {string} prompt — 原始用户提示
28
+ * @property {Function|null} [onToolCall] — 本轮工具调用钩子
29
+ * @property {Object} [context] — 额外上下文
30
+ * @property {import('../context/ContextWindow.js').ContextWindow|null} [contextWindow] — 原始 ContextWindow (供 forced-summary 等外部逻辑)
31
+ */
32
+
33
+ export class LoopContext {
34
+ // ─── 注入依赖 ───
35
+
36
+ /** @type {import('./MessageAdapter.js').MessageAdapter} 统一消息适配器 */
37
+ messages;
38
+
39
+ /** @type {Object|null} ExplorationTracker 实例 */
40
+ tracker;
41
+
42
+ /** @type {Object|null} ActiveContext 实例 */
43
+ trace;
44
+
45
+ /** @type {Object|null} MemoryCoordinator 实例 */
46
+ memoryCoordinator;
47
+
48
+ /** @type {Object|null} 共享状态 */
49
+ sharedState;
50
+
51
+ // ─── 循环状态 ───
52
+
53
+ /** @type {number} 当前迭代次数 */
54
+ iteration = 0;
55
+
56
+ /** @type {string} 最终回复文本 */
57
+ lastReply = '';
58
+
59
+ /** @type {Array} 本轮工具调用记录 */
60
+ toolCalls = [];
61
+
62
+ /** @type {{input: number, output: number}} 本轮 token 用量 */
63
+ tokenUsage = { input: 0, output: 0 };
64
+
65
+ /** @type {number} 循环开始时间戳 */
66
+ loopStartTime = 0;
67
+
68
+ // ─── 错误恢复 ───
69
+
70
+ /** @type {number} 连续 AI 错误计数 (2-strike 策略) */
71
+ consecutiveAiErrors = 0;
72
+
73
+ /** @type {number} 连续空响应计数 */
74
+ consecutiveEmptyResponses = 0;
75
+
76
+ // ─── 配置 (只读) ───
77
+
78
+ /** @type {string} 来源 'user' | 'system' */
79
+ source;
80
+
81
+ /** @type {Object} 预算配置 */
82
+ budget;
83
+
84
+ /** @type {import('../capabilities.js').Capability[]} */
85
+ capabilities;
86
+
87
+ /** @type {string} 基础系统提示词 */
88
+ baseSystemPrompt;
89
+
90
+ /** @type {Array} 工具 schemas */
91
+ toolSchemas;
92
+
93
+ /** @type {string} 原始用户提示 */
94
+ prompt;
95
+
96
+ /** @type {Function|null} 工具调用钩子 */
97
+ onToolCall;
98
+
99
+ /** @type {Object} 额外上下文 */
100
+ context;
101
+
102
+ /** @type {import('../../chat/ContextWindow.js').ContextWindow|null} 原始 ContextWindow 引用 */
103
+ contextWindow;
104
+
105
+ /** @type {string|null} 首轮 toolChoice 覆盖 ('required'/'auto'/'none') */
106
+ toolChoiceOverride;
107
+
108
+ /**
109
+ * @param {LoopContextConfig} config
110
+ */
111
+ constructor(config) {
112
+ this.messages = config.messages;
113
+ this.tracker = config.tracker || null;
114
+ this.trace = config.trace || null;
115
+ this.memoryCoordinator = config.memoryCoordinator || null;
116
+ this.sharedState = config.sharedState || null;
117
+ this.source = config.source || 'user';
118
+ this.budget = config.budget;
119
+ this.capabilities = config.capabilities;
120
+ this.baseSystemPrompt = config.baseSystemPrompt;
121
+ this.toolSchemas = config.toolSchemas;
122
+ this.prompt = config.prompt;
123
+ this.onToolCall = config.onToolCall || null;
124
+ this.context = config.context || {};
125
+ this.contextWindow = config.contextWindow || null;
126
+ this.toolChoiceOverride = config.toolChoiceOverride || null;
127
+ this.loopStartTime = Date.now();
128
+ }
129
+
130
+ // ─── 计算属性 ───
131
+
132
+ /** 是否为 system 场景 */
133
+ get isSystem() {
134
+ return this.source === 'system';
135
+ }
136
+
137
+ /** 最大迭代数 */
138
+ get maxIterations() {
139
+ return this.budget.maxIterations || 20;
140
+ }
141
+
142
+ // ─── Token 累计辅助 ───
143
+
144
+ /**
145
+ * 累加 token 用量到循环级统计
146
+ * @param {Object} usage — { inputTokens, outputTokens }
147
+ */
148
+ addTokenUsage(usage) {
149
+ if (!usage) return;
150
+ const inTok = usage.inputTokens || 0;
151
+ const outTok = usage.outputTokens || 0;
152
+ this.tokenUsage.input += inTok;
153
+ this.tokenUsage.output += outTok;
154
+ }
155
+
156
+ // ─── 结果构建 ───
157
+
158
+ /**
159
+ * 构建循环返回值
160
+ * @returns {{ reply: string, toolCalls: Array, tokenUsage: Object, iterations: number }}
161
+ */
162
+ buildResult() {
163
+ return {
164
+ reply: this.lastReply,
165
+ toolCalls: [...this.toolCalls],
166
+ tokenUsage: { ...this.tokenUsage },
167
+ iterations: this.iteration,
168
+ };
169
+ }
170
+ }
@@ -0,0 +1,223 @@
1
+ /**
2
+ * MessageAdapter — 统一消息操作接口
3
+ *
4
+ * 消除 reactLoop 内的 useCtxWin 双模式分支:
5
+ * - ContextWindowAdapter: 委托给 ContextWindow 实例 (bootstrap/system 场景)
6
+ * - SimpleArrayAdapter: 裸数组模式 (对话场景)
7
+ *
8
+ * 两个实现对外暴露完全相同的 API,
9
+ * 使得 reactLoop 及其提取方法无需关心底层消息存储方式。
10
+ *
11
+ * @module core/MessageAdapter
12
+ */
13
+
14
+ import { limitToolResult } from '../context/ContextWindow.js';
15
+
16
+ // ─────────────────────────────────────────────
17
+ // Base class (接口定义 + JSDoc)
18
+ // ─────────────────────────────────────────────
19
+
20
+ /**
21
+ * @abstract
22
+ */
23
+ export class MessageAdapter {
24
+ /**
25
+ * 追加用户消息
26
+ * @param {string} text
27
+ */
28
+ appendUserMessage(_text) { throw new Error('not implemented'); }
29
+
30
+ /**
31
+ * 追加助手纯文本回复
32
+ * @param {string} text
33
+ */
34
+ appendAssistantText(_text) { throw new Error('not implemented'); }
35
+
36
+ /**
37
+ * 追加助手带工具调用的回复
38
+ * @param {string|null} text
39
+ * @param {Array} calls — functionCalls 数组
40
+ */
41
+ appendAssistantWithToolCalls(_text, _calls) { throw new Error('not implemented'); }
42
+
43
+ /**
44
+ * 追加工具执行结果
45
+ * @param {string} callId
46
+ * @param {string} name
47
+ * @param {string} content
48
+ */
49
+ appendToolResult(_callId, _name, _content) { throw new Error('not implemented'); }
50
+
51
+ /**
52
+ * 追加系统/用户 nudge 消息
53
+ * @param {string} text
54
+ */
55
+ appendUserNudge(_text) { throw new Error('not implemented'); }
56
+
57
+ /**
58
+ * 导出当前消息列表 (供 LLM 调用)
59
+ * @returns {Array<{role: string, content: string}>}
60
+ */
61
+ toMessages() { throw new Error('not implemented'); }
62
+
63
+ /**
64
+ * 重置到仅保留初始 prompt (错误恢复)
65
+ */
66
+ resetToPromptOnly() { throw new Error('not implemented'); }
67
+
68
+ /**
69
+ * 获取工具结果限额 (字符数)
70
+ * @returns {number}
71
+ */
72
+ getToolResultQuota() { throw new Error('not implemented'); }
73
+
74
+ /**
75
+ * 压缩检查 — 如果消息过多则自动压缩
76
+ * @returns {{ level: number, removed: number }}
77
+ */
78
+ compactIfNeeded() { throw new Error('not implemented'); }
79
+
80
+ /**
81
+ * 格式化工具结果字符串 (统一 limitToolResult 调用)
82
+ * @param {string} toolName
83
+ * @param {*} rawResult — 工具原始返回值
84
+ * @returns {string}
85
+ */
86
+ formatToolResult(toolName, rawResult) {
87
+ const quota = this.getToolResultQuota();
88
+ return limitToolResult(toolName, rawResult, quota);
89
+ }
90
+ }
91
+
92
+ // ─────────────────────────────────────────────
93
+ // ContextWindowAdapter — 委托给 ContextWindow
94
+ // ─────────────────────────────────────────────
95
+
96
+ /**
97
+ * 委托所有消息操作给 ContextWindow 实例。
98
+ *
99
+ * 用于 bootstrap / system 场景,
100
+ * ContextWindow 提供三级递进压缩 + 动态 token 预算。
101
+ */
102
+ export class ContextWindowAdapter extends MessageAdapter {
103
+ /** @type {import('../context/ContextWindow.js').ContextWindow} */
104
+ #ctxWin;
105
+
106
+ /**
107
+ * @param {import('../context/ContextWindow.js').ContextWindow} ctxWin
108
+ */
109
+ constructor(ctxWin) {
110
+ super();
111
+ this.#ctxWin = ctxWin;
112
+ }
113
+
114
+ /** 获取底层 ContextWindow 实例 (供 forced-summary 等外部逻辑使用) */
115
+ get contextWindow() {
116
+ return this.#ctxWin;
117
+ }
118
+
119
+ appendUserMessage(text) {
120
+ this.#ctxWin.appendUserMessage(text);
121
+ }
122
+
123
+ appendAssistantText(text) {
124
+ this.#ctxWin.appendAssistantText(text);
125
+ }
126
+
127
+ appendAssistantWithToolCalls(text, calls) {
128
+ this.#ctxWin.appendAssistantWithToolCalls(text, calls);
129
+ }
130
+
131
+ appendToolResult(callId, name, content) {
132
+ this.#ctxWin.appendToolResult(callId, name, content);
133
+ }
134
+
135
+ appendUserNudge(text) {
136
+ this.#ctxWin.appendUserNudge(text);
137
+ }
138
+
139
+ toMessages() {
140
+ return this.#ctxWin.toMessages();
141
+ }
142
+
143
+ resetToPromptOnly() {
144
+ this.#ctxWin.resetToPromptOnly();
145
+ }
146
+
147
+ getToolResultQuota() {
148
+ return this.#ctxWin.getToolResultQuota();
149
+ }
150
+
151
+ compactIfNeeded() {
152
+ return this.#ctxWin.compactIfNeeded();
153
+ }
154
+ }
155
+
156
+ // ─────────────────────────────────────────────
157
+ // SimpleArrayAdapter — 裸数组模式
158
+ // ─────────────────────────────────────────────
159
+
160
+ /**
161
+ * 简单数组消息管理 — 对话场景。
162
+ *
163
+ * 不做任何压缩,getToolResultQuota 返回固定 8000。
164
+ * compactIfNeeded 始终返回 no-op。
165
+ */
166
+ export class SimpleArrayAdapter extends MessageAdapter {
167
+ /** @type {Array<Object>} */
168
+ #messages = [];
169
+
170
+ appendUserMessage(text) {
171
+ this.#messages.push({ role: 'user', content: text });
172
+ }
173
+
174
+ appendAssistantText(text) {
175
+ this.#messages.push({ role: 'assistant', content: text });
176
+ }
177
+
178
+ appendAssistantWithToolCalls(text, calls) {
179
+ this.#messages.push({ role: 'assistant', content: text, toolCalls: calls });
180
+ }
181
+
182
+ appendToolResult(callId, name, content) {
183
+ this.#messages.push({ role: 'tool', toolCallId: callId, name, content });
184
+ }
185
+
186
+ appendUserNudge(text) {
187
+ this.#messages.push({ role: 'user', content: text });
188
+ }
189
+
190
+ toMessages() {
191
+ return [...this.#messages];
192
+ }
193
+
194
+ resetToPromptOnly() {
195
+ const first = this.#messages[0];
196
+ this.#messages.length = 0;
197
+ if (first) this.#messages.push(first);
198
+ }
199
+
200
+ getToolResultQuota() {
201
+ return { maxChars: 8000, maxMatches: 20 };
202
+ }
203
+
204
+ compactIfNeeded() {
205
+ return { level: 0, removed: 0 };
206
+ }
207
+ }
208
+
209
+ // ─────────────────────────────────────────────
210
+ // Factory helper
211
+ // ─────────────────────────────────────────────
212
+
213
+ /**
214
+ * 根据是否提供 contextWindow 创建对应适配器
215
+ * @param {import('../context/ContextWindow.js').ContextWindow|null|undefined} contextWindow
216
+ * @returns {MessageAdapter}
217
+ */
218
+ export function createMessageAdapter(contextWindow) {
219
+ if (contextWindow) {
220
+ return new ContextWindowAdapter(contextWindow);
221
+ }
222
+ return new SimpleArrayAdapter();
223
+ }