grov 0.5.11 → 0.6.13

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 (190) hide show
  1. package/dist/cli/agents/registry.d.ts +17 -0
  2. package/dist/cli/agents/registry.js +132 -0
  3. package/dist/cli/commands/agents.d.ts +1 -0
  4. package/dist/cli/commands/agents.js +48 -0
  5. package/dist/cli/commands/disable.d.ts +1 -0
  6. package/dist/cli/commands/disable.js +179 -0
  7. package/dist/cli/commands/doctor.d.ts +1 -0
  8. package/dist/cli/commands/doctor.js +157 -0
  9. package/dist/{commands → cli/commands}/drift-test.js +39 -26
  10. package/dist/cli/commands/init.d.ts +1 -0
  11. package/dist/cli/commands/init.js +90 -0
  12. package/dist/{commands → cli/commands}/login.js +19 -18
  13. package/dist/{commands → cli/commands}/logout.js +1 -1
  14. package/dist/{commands → cli/commands}/proxy-status.js +1 -1
  15. package/dist/cli/commands/setup.d.ts +6 -0
  16. package/dist/cli/commands/setup.js +309 -0
  17. package/dist/{commands → cli/commands}/status.js +1 -1
  18. package/dist/{commands → cli/commands}/sync.d.ts +1 -0
  19. package/dist/{commands → cli/commands}/sync.js +59 -4
  20. package/dist/{commands → cli/commands}/uninstall.js +2 -2
  21. package/dist/cli/index.js +270 -0
  22. package/dist/{lib → core/cloud}/cloud-sync.d.ts +3 -3
  23. package/dist/{lib → core/cloud}/cloud-sync.js +10 -10
  24. package/dist/{lib → core/extraction}/correction-builder-proxy.d.ts +1 -1
  25. package/dist/{lib → core/extraction}/correction-builder-proxy.js +0 -4
  26. package/dist/{lib → core/extraction}/drift-checker-proxy.d.ts +13 -9
  27. package/dist/core/extraction/drift-checker-proxy.js +510 -0
  28. package/dist/{lib → core/extraction}/llm-extractor.d.ts +8 -38
  29. package/dist/{lib → core/extraction}/llm-extractor.js +132 -220
  30. package/dist/{lib → core}/store/sessions.js +3 -19
  31. package/dist/core/store/store.d.ts +1 -0
  32. package/dist/{lib → core/store}/store.js +1 -1
  33. package/dist/{lib → core}/store/types.d.ts +0 -4
  34. package/dist/integrations/mcp/cache.d.ts +27 -0
  35. package/dist/integrations/mcp/cache.js +106 -0
  36. package/dist/integrations/mcp/capture/antigravity-parser.d.ts +26 -0
  37. package/dist/integrations/mcp/capture/antigravity-parser.js +272 -0
  38. package/dist/integrations/mcp/capture/antigravity-scanner.d.ts +24 -0
  39. package/dist/integrations/mcp/capture/antigravity-scanner.js +153 -0
  40. package/dist/integrations/mcp/capture/antigravity-sync-tracker.d.ts +29 -0
  41. package/dist/integrations/mcp/capture/antigravity-sync-tracker.js +115 -0
  42. package/dist/integrations/mcp/capture/cli-extractor.d.ts +18 -0
  43. package/dist/integrations/mcp/capture/cli-extractor.js +258 -0
  44. package/dist/integrations/mcp/capture/cli-synced.d.ts +4 -0
  45. package/dist/integrations/mcp/capture/cli-synced.js +62 -0
  46. package/dist/integrations/mcp/capture/cli-transform.d.ts +30 -0
  47. package/dist/integrations/mcp/capture/cli-transform.js +62 -0
  48. package/dist/integrations/mcp/capture/cli-watcher.d.ts +31 -0
  49. package/dist/integrations/mcp/capture/cli-watcher.js +106 -0
  50. package/dist/integrations/mcp/capture/hook-handler.d.ts +2 -0
  51. package/dist/integrations/mcp/capture/hook-handler.js +157 -0
  52. package/dist/integrations/mcp/capture/sqlite-reader.d.ts +35 -0
  53. package/dist/integrations/mcp/capture/sqlite-reader.js +388 -0
  54. package/dist/integrations/mcp/capture/sync-tracker.d.ts +16 -0
  55. package/dist/integrations/mcp/capture/sync-tracker.js +102 -0
  56. package/dist/integrations/mcp/clients/cursor/rules-installer.d.ts +19 -0
  57. package/dist/integrations/mcp/clients/cursor/rules-installer.js +123 -0
  58. package/dist/integrations/mcp/index.d.ts +1 -0
  59. package/dist/integrations/mcp/index.js +94 -0
  60. package/dist/integrations/mcp/logger.d.ts +8 -0
  61. package/dist/integrations/mcp/logger.js +50 -0
  62. package/dist/integrations/mcp/server.d.ts +5 -0
  63. package/dist/integrations/mcp/server.js +58 -0
  64. package/dist/integrations/mcp/tools/expand.d.ts +1 -0
  65. package/dist/integrations/mcp/tools/expand.js +53 -0
  66. package/dist/integrations/mcp/tools/preview.d.ts +1 -0
  67. package/dist/integrations/mcp/tools/preview.js +64 -0
  68. package/dist/integrations/proxy/agents/base.d.ts +43 -0
  69. package/dist/integrations/proxy/agents/base.js +13 -0
  70. package/dist/{proxy/utils → integrations/proxy/agents/claude}/extractors.d.ts +4 -8
  71. package/dist/{proxy/utils → integrations/proxy/agents/claude}/extractors.js +4 -33
  72. package/dist/{proxy → integrations/proxy/agents/claude}/forwarder.d.ts +1 -1
  73. package/dist/{proxy → integrations/proxy/agents/claude}/forwarder.js +22 -6
  74. package/dist/integrations/proxy/agents/claude/index.d.ts +43 -0
  75. package/dist/integrations/proxy/agents/claude/index.js +386 -0
  76. package/dist/{proxy/action-parser.d.ts → integrations/proxy/agents/claude/parser.d.ts} +1 -1
  77. package/dist/integrations/proxy/agents/codex/extractors.d.ts +6 -0
  78. package/dist/integrations/proxy/agents/codex/extractors.js +49 -0
  79. package/dist/integrations/proxy/agents/codex/forwarder.d.ts +9 -0
  80. package/dist/integrations/proxy/agents/codex/forwarder.js +125 -0
  81. package/dist/integrations/proxy/agents/codex/index.d.ts +44 -0
  82. package/dist/integrations/proxy/agents/codex/index.js +371 -0
  83. package/dist/integrations/proxy/agents/codex/parser.d.ts +11 -0
  84. package/dist/integrations/proxy/agents/codex/parser.js +104 -0
  85. package/dist/integrations/proxy/agents/codex/patch.d.ts +12 -0
  86. package/dist/integrations/proxy/agents/codex/patch.js +40 -0
  87. package/dist/integrations/proxy/agents/codex/settings.d.ts +18 -0
  88. package/dist/integrations/proxy/agents/codex/settings.js +73 -0
  89. package/dist/integrations/proxy/agents/codex/types.d.ts +59 -0
  90. package/dist/integrations/proxy/agents/codex/types.js +2 -0
  91. package/dist/integrations/proxy/agents/index.d.ts +11 -0
  92. package/dist/integrations/proxy/agents/index.js +25 -0
  93. package/dist/integrations/proxy/agents/types.d.ts +77 -0
  94. package/dist/integrations/proxy/agents/types.js +2 -0
  95. package/dist/{proxy → integrations/proxy/cache}/extended-cache.js +2 -6
  96. package/dist/{proxy → integrations/proxy}/config.js +1 -1
  97. package/dist/{proxy → integrations/proxy}/handlers/preprocess.d.ts +3 -3
  98. package/dist/integrations/proxy/handlers/preprocess.js +194 -0
  99. package/dist/integrations/proxy/index.js +20 -0
  100. package/dist/integrations/proxy/injection/memory-injection.d.ts +56 -0
  101. package/dist/integrations/proxy/injection/memory-injection.js +252 -0
  102. package/dist/integrations/proxy/orchestrator.d.ts +30 -0
  103. package/dist/integrations/proxy/orchestrator.js +954 -0
  104. package/dist/integrations/proxy/request-processor.d.ts +14 -0
  105. package/dist/integrations/proxy/request-processor.js +68 -0
  106. package/dist/{proxy → integrations/proxy}/response-processor.d.ts +4 -3
  107. package/dist/{proxy → integrations/proxy}/response-processor.js +51 -43
  108. package/dist/{proxy → integrations/proxy}/server.d.ts +0 -1
  109. package/dist/integrations/proxy/server.js +146 -0
  110. package/dist/{proxy → integrations/proxy}/types.d.ts +4 -0
  111. package/dist/{proxy → integrations/proxy}/utils/logging.d.ts +1 -0
  112. package/dist/{proxy → integrations/proxy}/utils/logging.js +5 -0
  113. package/package.json +31 -10
  114. package/postinstall.js +62 -6
  115. package/dist/cli.js +0 -149
  116. package/dist/commands/capture.d.ts +0 -6
  117. package/dist/commands/capture.js +0 -324
  118. package/dist/commands/disable.d.ts +0 -1
  119. package/dist/commands/disable.js +0 -14
  120. package/dist/commands/doctor.d.ts +0 -1
  121. package/dist/commands/doctor.js +0 -89
  122. package/dist/commands/init.d.ts +0 -1
  123. package/dist/commands/init.js +0 -52
  124. package/dist/commands/inject.d.ts +0 -5
  125. package/dist/commands/inject.js +0 -88
  126. package/dist/commands/prompt-inject.d.ts +0 -4
  127. package/dist/commands/prompt-inject.js +0 -451
  128. package/dist/commands/unregister.d.ts +0 -1
  129. package/dist/commands/unregister.js +0 -28
  130. package/dist/lib/anchor-extractor.d.ts +0 -30
  131. package/dist/lib/anchor-extractor.js +0 -296
  132. package/dist/lib/correction-builder.d.ts +0 -10
  133. package/dist/lib/correction-builder.js +0 -226
  134. package/dist/lib/drift-checker-proxy.js +0 -373
  135. package/dist/lib/drift-checker.d.ts +0 -66
  136. package/dist/lib/drift-checker.js +0 -341
  137. package/dist/lib/hooks.d.ts +0 -38
  138. package/dist/lib/hooks.js +0 -291
  139. package/dist/lib/jsonl-parser.d.ts +0 -87
  140. package/dist/lib/jsonl-parser.js +0 -281
  141. package/dist/lib/session-parser.d.ts +0 -44
  142. package/dist/lib/session-parser.js +0 -256
  143. package/dist/lib/store.d.ts +0 -1
  144. package/dist/proxy/cache.d.ts +0 -32
  145. package/dist/proxy/cache.js +0 -47
  146. package/dist/proxy/handlers/preprocess.js +0 -186
  147. package/dist/proxy/index.js +0 -30
  148. package/dist/proxy/injection/delta-tracking.d.ts +0 -11
  149. package/dist/proxy/injection/delta-tracking.js +0 -94
  150. package/dist/proxy/injection/injectors.d.ts +0 -7
  151. package/dist/proxy/injection/injectors.js +0 -139
  152. package/dist/proxy/request-processor.d.ts +0 -27
  153. package/dist/proxy/request-processor.js +0 -233
  154. package/dist/proxy/server.js +0 -1289
  155. /package/dist/{commands → cli/commands}/drift-test.d.ts +0 -0
  156. /package/dist/{commands → cli/commands}/login.d.ts +0 -0
  157. /package/dist/{commands → cli/commands}/logout.d.ts +0 -0
  158. /package/dist/{commands → cli/commands}/proxy-status.d.ts +0 -0
  159. /package/dist/{commands → cli/commands}/status.d.ts +0 -0
  160. /package/dist/{commands → cli/commands}/uninstall.d.ts +0 -0
  161. /package/dist/{cli.d.ts → cli/index.d.ts} +0 -0
  162. /package/dist/{lib → core/cloud}/api-client.d.ts +0 -0
  163. /package/dist/{lib → core/cloud}/api-client.js +0 -0
  164. /package/dist/{lib → core/cloud}/credentials.d.ts +0 -0
  165. /package/dist/{lib → core/cloud}/credentials.js +0 -0
  166. /package/dist/{lib → core}/store/convenience.d.ts +0 -0
  167. /package/dist/{lib → core}/store/convenience.js +0 -0
  168. /package/dist/{lib → core}/store/database.d.ts +0 -0
  169. /package/dist/{lib → core}/store/database.js +0 -0
  170. /package/dist/{lib → core}/store/drift.d.ts +0 -0
  171. /package/dist/{lib → core}/store/drift.js +0 -0
  172. /package/dist/{lib → core}/store/index.d.ts +0 -0
  173. /package/dist/{lib → core}/store/index.js +0 -0
  174. /package/dist/{lib → core}/store/sessions.d.ts +0 -0
  175. /package/dist/{lib → core}/store/steps.d.ts +0 -0
  176. /package/dist/{lib → core}/store/steps.js +0 -0
  177. /package/dist/{lib → core}/store/tasks.d.ts +0 -0
  178. /package/dist/{lib → core}/store/tasks.js +0 -0
  179. /package/dist/{lib → core}/store/types.js +0 -0
  180. /package/dist/{proxy/action-parser.js → integrations/proxy/agents/claude/parser.js} +0 -0
  181. /package/dist/{lib → integrations/proxy/agents/claude}/settings.d.ts +0 -0
  182. /package/dist/{lib → integrations/proxy/agents/claude}/settings.js +0 -0
  183. /package/dist/{proxy → integrations/proxy/cache}/extended-cache.d.ts +0 -0
  184. /package/dist/{proxy → integrations/proxy}/config.d.ts +0 -0
  185. /package/dist/{proxy → integrations/proxy}/index.d.ts +0 -0
  186. /package/dist/{proxy → integrations/proxy}/types.js +0 -0
  187. /package/dist/{lib → utils}/debug.d.ts +0 -0
  188. /package/dist/{lib → utils}/debug.js +0 -0
  189. /package/dist/{lib → utils}/utils.d.ts +0 -0
  190. /package/dist/{lib → utils}/utils.js +0 -0
@@ -0,0 +1,252 @@
1
+ // Memory injection - Preview + Expand system for team memory
2
+ // Reference: docs/new_injection.md
3
+ const sessionState = new Map();
4
+ export function getOrCreateState(sessionId) {
5
+ if (!sessionState.has(sessionId)) {
6
+ sessionState.set(sessionId, {
7
+ memoriesById: new Map(),
8
+ injectionHistory: [],
9
+ pendingRecords: [],
10
+ lastOriginalMsgCount: 0,
11
+ });
12
+ }
13
+ return sessionState.get(sessionId);
14
+ }
15
+ export function clearSessionState(sessionId) {
16
+ sessionState.delete(sessionId);
17
+ }
18
+ export function cacheMemories(sessionId, memories) {
19
+ const state = getOrCreateState(sessionId);
20
+ state.memoriesById = new Map();
21
+ for (const memory of memories) {
22
+ state.memoriesById.set(memory.id, memory);
23
+ }
24
+ }
25
+ // ID-based lookup
26
+ export function getCachedMemoryById(sessionId, memoryId) {
27
+ const state = sessionState.get(sessionId);
28
+ if (!state?.memoriesById) {
29
+ return null;
30
+ }
31
+ // Support both full ID and 8-char prefix
32
+ if (state.memoriesById.has(memoryId)) {
33
+ return state.memoriesById.get(memoryId) || null;
34
+ }
35
+ // Try prefix match (first 8 chars)
36
+ for (const [id, memory] of state.memoriesById) {
37
+ if (id.startsWith(memoryId) || memoryId.startsWith(id.substring(0, 8))) {
38
+ return memory;
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+ export function setCachedPreview(sessionId, preview, msgCount) {
44
+ const state = getOrCreateState(sessionId);
45
+ state.cachedPreview = { preview, msgCount };
46
+ }
47
+ export function getCachedPreview(sessionId, currentMsgCount) {
48
+ const state = sessionState.get(sessionId);
49
+ if (!state?.cachedPreview)
50
+ return null;
51
+ if (state.cachedPreview.msgCount !== currentMsgCount)
52
+ return null;
53
+ return state.cachedPreview.preview;
54
+ }
55
+ // Add record to PENDING (not committed yet - waits for next turn)
56
+ export function addInjectionRecord(sessionId, record) {
57
+ const state = getOrCreateState(sessionId);
58
+ state.pendingRecords.push(record);
59
+ }
60
+ // Commit pending records to history (called at start of NEW turn)
61
+ export function commitPendingRecords(sessionId) {
62
+ const state = sessionState.get(sessionId);
63
+ if (!state || state.pendingRecords.length === 0)
64
+ return 0;
65
+ const count = state.pendingRecords.length;
66
+ state.injectionHistory.push(...state.pendingRecords);
67
+ state.pendingRecords = [];
68
+ return count;
69
+ }
70
+ // Check if tool_cycle already exists for position (in committed OR pending)
71
+ export function hasToolCycleAtPosition(sessionId, position) {
72
+ const state = sessionState.get(sessionId);
73
+ if (!state)
74
+ return false;
75
+ // Check both committed history and pending records
76
+ const inHistory = state.injectionHistory.some((r) => r.type === 'tool_cycle' && r.position === position);
77
+ const inPending = state.pendingRecords.some((r) => r.type === 'tool_cycle' && r.position === position);
78
+ return inHistory || inPending;
79
+ }
80
+ export function formatAge(updatedAt) {
81
+ if (!updatedAt)
82
+ return 'unknown';
83
+ const diffMs = Date.now() - new Date(updatedAt).getTime();
84
+ const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
85
+ if (diffDays === 0)
86
+ return 'today';
87
+ if (diffDays === 1)
88
+ return '1 day ago';
89
+ if (diffDays < 7)
90
+ return `${diffDays} days ago`;
91
+ const diffWeeks = Math.floor(diffDays / 7);
92
+ if (diffWeeks === 1)
93
+ return '1 week ago';
94
+ if (diffWeeks < 4)
95
+ return `${diffWeeks} weeks ago`;
96
+ const diffMonths = Math.floor(diffDays / 30);
97
+ if (diffMonths === 1)
98
+ return '1 month ago';
99
+ return `${diffMonths} months ago`;
100
+ }
101
+ export function buildMemoryPreview(memories) {
102
+ if (!memories || memories.length === 0)
103
+ return null;
104
+ const lines = [`[PROJECT KNOWLEDGE BASE: ${memories.length} verified entries - CURRENT]`];
105
+ memories.forEach((memory) => {
106
+ const idShort = memory.id.substring(0, 8);
107
+ const goal = memory.goal || 'No goal';
108
+ const summary = memory.summary || 'No summary';
109
+ const age = formatAge(memory.updated_at);
110
+ lines.push(`#${idShort}: "${goal}" -> ${summary} (${age})`);
111
+ });
112
+ lines.push('Use grov_expand with these IDs to get full knowledge.');
113
+ return lines.join('\n');
114
+ }
115
+ export function buildExpandedMemory(memory) {
116
+ const lines = [];
117
+ lines.push(`=== VERIFIED PROJECT KNOWLEDGE ===`);
118
+ lines.push(`GOAL: ${memory.goal || 'Unknown'}`);
119
+ lines.push('');
120
+ lines.push('ORIGINAL TASK:');
121
+ lines.push(`"${memory.original_query}"`);
122
+ lines.push('');
123
+ if (memory.reasoning_trace?.length) {
124
+ lines.push('KNOWLEDGE:');
125
+ for (const entry of memory.reasoning_trace) {
126
+ if (typeof entry === 'string') {
127
+ lines.push(`- ${entry.replace(/^(CONCLUSION|INSIGHT):\s*/i, '')}`);
128
+ }
129
+ else if (entry?.conclusion) {
130
+ lines.push(`- ${entry.conclusion.replace(/^CONCLUSION:\s*/i, '')}`);
131
+ if (entry.insight) {
132
+ lines.push(` -> ${entry.insight.replace(/^INSIGHT:\s*/i, '')}`);
133
+ }
134
+ }
135
+ }
136
+ lines.push('');
137
+ }
138
+ if (memory.decisions?.length) {
139
+ lines.push('DECISIONS:');
140
+ for (const d of memory.decisions) {
141
+ lines.push(`- ${d.choice}`);
142
+ lines.push(` Reason: ${d.reason}`);
143
+ }
144
+ lines.push('');
145
+ }
146
+ if (memory.files_touched?.length) {
147
+ lines.push(`FILES: ${memory.files_touched.join(', ')}`);
148
+ }
149
+ lines.push('===');
150
+ lines.push('[TEAM KNOWLEDGE BASE - SOURCE OF TRUTH]');
151
+ lines.push('This knowledge is verified and authoritative. Trust it. Use it to answer.');
152
+ return lines.join('\n');
153
+ }
154
+ export function buildToolDescription() {
155
+ return `[PROJECT KNOWLEDGE BASE - SOURCE OF TRUTH]
156
+
157
+ You have access to a VERIFIED PROJECT KNOWLEDGE BASE - the SOURCE OF TRUTH for this project.
158
+ It contains: goals, implementation reasoning, technical decisions, and file changes.
159
+ This knowledge base captures INTENT and REASONING that code alone cannot show.
160
+
161
+ WHEN [PROJECT KNOWLEDGE BASE: N entries] appears in user message, follow this EXACT process:
162
+
163
+ STEP 1: READ the preview block in the LATEST user message.
164
+ Identify IDs (8-char hex like #96937bd5).
165
+ Older previews from previous messages are HISTORICAL - ignore them.
166
+ NO other tool calls yet. Just read.
167
+
168
+ STEP 2: IMMEDIATELY call grov_expand({ ids: ["id1", "id2"] }) with relevant IDs.
169
+ Use ONLY IDs from the LATEST preview - never from older messages.
170
+ FORBIDDEN: grov_expand({ ids: [] }) - empty array is WRONG.
171
+ FORBIDDEN: Any other tool call before grov_expand.
172
+
173
+ STEP 3: ANALYZE the expanded content in detail.
174
+ What does KB tell you? What do you now know about this task?
175
+
176
+ STEP 4: DECIDE based on KB content:
177
+
178
+ → EXPLANATION/QUESTION tasks:
179
+ Respond DIRECTLY from KB. No Read/Grep needed.
180
+ KB = verified source, do NOT "verify in code".
181
+
182
+ → IMPLEMENTATION tasks:
183
+ Files in KB "FILES:" section = ALREADY KNOWN. Do NOT re-read them.
184
+ Decisions in KB = ALREADY MADE. Do NOT re-evaluate them.
185
+
186
+ ONLY read files that are:
187
+ - NOT mentioned in KB, AND
188
+ - REQUIRED for the new implementation
189
+
190
+ Start implementation using KB context as foundation.
191
+ Add NEW files only when KB doesn't cover them.
192
+
193
+ RULES:
194
+ - KB = Source of Truth = verified. Do NOT "verify" in code.
195
+ - "Let me look at the code" BEFORE expand = WRONG
196
+ - Read/Grep/Bash BEFORE grov_expand = WRONG
197
+ - Respond from KB without reading files = CORRECT (for questions/explanations)
198
+
199
+ SYNTAX: grov_expand({ ids: ["abc12345"] }) - IDs from LATEST preview only`;
200
+ }
201
+ export function buildDriftRecoveryInjection(pendingCorrection, pendingForcedRecovery) {
202
+ const parts = [];
203
+ if (pendingCorrection)
204
+ parts.push(`[DRIFT: ${pendingCorrection}]`);
205
+ if (pendingForcedRecovery)
206
+ parts.push(`[RECOVERY: ${pendingForcedRecovery}]`);
207
+ return parts.length ? parts.join('\n') : null;
208
+ }
209
+ export function appendTextToMessage(message, text) {
210
+ if (typeof message.content === 'string') {
211
+ message.content = message.content + '\n\n' + text;
212
+ }
213
+ else if (Array.isArray(message.content)) {
214
+ message.content.push({ type: 'text', text: '\n\n' + text });
215
+ }
216
+ }
217
+ export function reconstructMessages(messages, projectPath) {
218
+ const state = sessionState.get(projectPath);
219
+ if (!state || state.injectionHistory.length === 0) {
220
+ // No history - just update message count and return
221
+ if (state)
222
+ state.lastOriginalMsgCount = messages.length;
223
+ return { messages, reconstructedCount: 0 };
224
+ }
225
+ const history = state.injectionHistory;
226
+ const lastCount = state.lastOriginalMsgCount;
227
+ // Detect stale history: if message count DECREASED, it's a new conversation
228
+ // (Claude Code restarted but Grov still running)
229
+ if (messages.length < lastCount - 1) { // Allow -1 for potential retry
230
+ console.log(`[MEMORY] New conversation detected (was ${lastCount} msgs, now ${messages.length}), clearing history`);
231
+ clearSessionState(projectPath);
232
+ return { messages, reconstructedCount: 0 };
233
+ }
234
+ // Update message count
235
+ state.lastOriginalMsgCount = messages.length;
236
+ const reconstructed = [...messages];
237
+ let insertOffset = 0;
238
+ let count = 0;
239
+ for (const record of history) {
240
+ const adjustedPosition = record.position + insertOffset;
241
+ if (record.type === 'preview' && record.preview) {
242
+ const msg = reconstructed[adjustedPosition];
243
+ if (msg && msg.role === 'user') {
244
+ appendTextToMessage(msg, record.preview);
245
+ count++;
246
+ }
247
+ }
248
+ // NOTE: tool_cycle reconstruction disabled - can't fake redacted_thinking for extended thinking
249
+ // Preview reconstruction is sufficient for context
250
+ }
251
+ return { messages: reconstructed, reconstructedCount: count };
252
+ }
@@ -0,0 +1,30 @@
1
+ import type { AgentAdapter } from './agents/types.js';
2
+ import { type DriftCheckResult } from '../../core/extraction/drift-checker-proxy.js';
3
+ declare const lastDriftResults: Map<string, DriftCheckResult>;
4
+ declare const lastMessageCount: Map<string, number>;
5
+ declare const activeSessions: Map<string, {
6
+ sessionId: string;
7
+ promptCount: number;
8
+ projectPath: string;
9
+ }>;
10
+ export interface OrchestratorResult {
11
+ statusCode: number;
12
+ contentType: string;
13
+ headers: Record<string, string>;
14
+ body: string;
15
+ }
16
+ interface RequestContext {
17
+ adapter: AgentAdapter;
18
+ body: unknown;
19
+ headers: Record<string, string>;
20
+ rawBody?: Buffer;
21
+ logger: {
22
+ info: (data: Record<string, unknown>) => void;
23
+ error?: (data: Record<string, unknown>) => void;
24
+ };
25
+ }
26
+ /**
27
+ * Main entry point for handling agent requests
28
+ */
29
+ export declare function handleAgentRequest(context: RequestContext): Promise<OrchestratorResult>;
30
+ export { activeSessions, lastDriftResults, lastMessageCount };