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.
- package/dist/cli/agents/registry.d.ts +17 -0
- package/dist/cli/agents/registry.js +132 -0
- package/dist/cli/commands/agents.d.ts +1 -0
- package/dist/cli/commands/agents.js +48 -0
- package/dist/cli/commands/disable.d.ts +1 -0
- package/dist/cli/commands/disable.js +179 -0
- package/dist/cli/commands/doctor.d.ts +1 -0
- package/dist/cli/commands/doctor.js +157 -0
- package/dist/{commands → cli/commands}/drift-test.js +39 -26
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/init.js +90 -0
- package/dist/{commands → cli/commands}/login.js +19 -18
- package/dist/{commands → cli/commands}/logout.js +1 -1
- package/dist/{commands → cli/commands}/proxy-status.js +1 -1
- package/dist/cli/commands/setup.d.ts +6 -0
- package/dist/cli/commands/setup.js +309 -0
- package/dist/{commands → cli/commands}/status.js +1 -1
- package/dist/{commands → cli/commands}/sync.d.ts +1 -0
- package/dist/{commands → cli/commands}/sync.js +59 -4
- package/dist/{commands → cli/commands}/uninstall.js +2 -2
- package/dist/cli/index.js +270 -0
- package/dist/{lib → core/cloud}/cloud-sync.d.ts +3 -3
- package/dist/{lib → core/cloud}/cloud-sync.js +10 -10
- package/dist/{lib → core/extraction}/correction-builder-proxy.d.ts +1 -1
- package/dist/{lib → core/extraction}/correction-builder-proxy.js +0 -4
- package/dist/{lib → core/extraction}/drift-checker-proxy.d.ts +13 -9
- package/dist/core/extraction/drift-checker-proxy.js +510 -0
- package/dist/{lib → core/extraction}/llm-extractor.d.ts +8 -38
- package/dist/{lib → core/extraction}/llm-extractor.js +132 -220
- package/dist/{lib → core}/store/sessions.js +3 -19
- package/dist/core/store/store.d.ts +1 -0
- package/dist/{lib → core/store}/store.js +1 -1
- package/dist/{lib → core}/store/types.d.ts +0 -4
- package/dist/integrations/mcp/cache.d.ts +27 -0
- package/dist/integrations/mcp/cache.js +106 -0
- package/dist/integrations/mcp/capture/antigravity-parser.d.ts +26 -0
- package/dist/integrations/mcp/capture/antigravity-parser.js +272 -0
- package/dist/integrations/mcp/capture/antigravity-scanner.d.ts +24 -0
- package/dist/integrations/mcp/capture/antigravity-scanner.js +153 -0
- package/dist/integrations/mcp/capture/antigravity-sync-tracker.d.ts +29 -0
- package/dist/integrations/mcp/capture/antigravity-sync-tracker.js +115 -0
- package/dist/integrations/mcp/capture/cli-extractor.d.ts +18 -0
- package/dist/integrations/mcp/capture/cli-extractor.js +258 -0
- package/dist/integrations/mcp/capture/cli-synced.d.ts +4 -0
- package/dist/integrations/mcp/capture/cli-synced.js +62 -0
- package/dist/integrations/mcp/capture/cli-transform.d.ts +30 -0
- package/dist/integrations/mcp/capture/cli-transform.js +62 -0
- package/dist/integrations/mcp/capture/cli-watcher.d.ts +31 -0
- package/dist/integrations/mcp/capture/cli-watcher.js +106 -0
- package/dist/integrations/mcp/capture/hook-handler.d.ts +2 -0
- package/dist/integrations/mcp/capture/hook-handler.js +157 -0
- package/dist/integrations/mcp/capture/sqlite-reader.d.ts +35 -0
- package/dist/integrations/mcp/capture/sqlite-reader.js +388 -0
- package/dist/integrations/mcp/capture/sync-tracker.d.ts +16 -0
- package/dist/integrations/mcp/capture/sync-tracker.js +102 -0
- package/dist/integrations/mcp/clients/cursor/rules-installer.d.ts +19 -0
- package/dist/integrations/mcp/clients/cursor/rules-installer.js +123 -0
- package/dist/integrations/mcp/index.d.ts +1 -0
- package/dist/integrations/mcp/index.js +94 -0
- package/dist/integrations/mcp/logger.d.ts +8 -0
- package/dist/integrations/mcp/logger.js +50 -0
- package/dist/integrations/mcp/server.d.ts +5 -0
- package/dist/integrations/mcp/server.js +58 -0
- package/dist/integrations/mcp/tools/expand.d.ts +1 -0
- package/dist/integrations/mcp/tools/expand.js +53 -0
- package/dist/integrations/mcp/tools/preview.d.ts +1 -0
- package/dist/integrations/mcp/tools/preview.js +64 -0
- package/dist/integrations/proxy/agents/base.d.ts +43 -0
- package/dist/integrations/proxy/agents/base.js +13 -0
- package/dist/{proxy/utils → integrations/proxy/agents/claude}/extractors.d.ts +4 -8
- package/dist/{proxy/utils → integrations/proxy/agents/claude}/extractors.js +4 -33
- package/dist/{proxy → integrations/proxy/agents/claude}/forwarder.d.ts +1 -1
- package/dist/{proxy → integrations/proxy/agents/claude}/forwarder.js +22 -6
- package/dist/integrations/proxy/agents/claude/index.d.ts +43 -0
- package/dist/integrations/proxy/agents/claude/index.js +386 -0
- package/dist/{proxy/action-parser.d.ts → integrations/proxy/agents/claude/parser.d.ts} +1 -1
- package/dist/integrations/proxy/agents/codex/extractors.d.ts +6 -0
- package/dist/integrations/proxy/agents/codex/extractors.js +49 -0
- package/dist/integrations/proxy/agents/codex/forwarder.d.ts +9 -0
- package/dist/integrations/proxy/agents/codex/forwarder.js +125 -0
- package/dist/integrations/proxy/agents/codex/index.d.ts +44 -0
- package/dist/integrations/proxy/agents/codex/index.js +371 -0
- package/dist/integrations/proxy/agents/codex/parser.d.ts +11 -0
- package/dist/integrations/proxy/agents/codex/parser.js +104 -0
- package/dist/integrations/proxy/agents/codex/patch.d.ts +12 -0
- package/dist/integrations/proxy/agents/codex/patch.js +40 -0
- package/dist/integrations/proxy/agents/codex/settings.d.ts +18 -0
- package/dist/integrations/proxy/agents/codex/settings.js +73 -0
- package/dist/integrations/proxy/agents/codex/types.d.ts +59 -0
- package/dist/integrations/proxy/agents/codex/types.js +2 -0
- package/dist/integrations/proxy/agents/index.d.ts +11 -0
- package/dist/integrations/proxy/agents/index.js +25 -0
- package/dist/integrations/proxy/agents/types.d.ts +77 -0
- package/dist/integrations/proxy/agents/types.js +2 -0
- package/dist/{proxy → integrations/proxy/cache}/extended-cache.js +2 -6
- package/dist/{proxy → integrations/proxy}/config.js +1 -1
- package/dist/{proxy → integrations/proxy}/handlers/preprocess.d.ts +3 -3
- package/dist/integrations/proxy/handlers/preprocess.js +194 -0
- package/dist/integrations/proxy/index.js +20 -0
- package/dist/integrations/proxy/injection/memory-injection.d.ts +56 -0
- package/dist/integrations/proxy/injection/memory-injection.js +252 -0
- package/dist/integrations/proxy/orchestrator.d.ts +30 -0
- package/dist/integrations/proxy/orchestrator.js +954 -0
- package/dist/integrations/proxy/request-processor.d.ts +14 -0
- package/dist/integrations/proxy/request-processor.js +68 -0
- package/dist/{proxy → integrations/proxy}/response-processor.d.ts +4 -3
- package/dist/{proxy → integrations/proxy}/response-processor.js +51 -43
- package/dist/{proxy → integrations/proxy}/server.d.ts +0 -1
- package/dist/integrations/proxy/server.js +146 -0
- package/dist/{proxy → integrations/proxy}/types.d.ts +4 -0
- package/dist/{proxy → integrations/proxy}/utils/logging.d.ts +1 -0
- package/dist/{proxy → integrations/proxy}/utils/logging.js +5 -0
- package/package.json +31 -10
- package/postinstall.js +62 -6
- package/dist/cli.js +0 -149
- package/dist/commands/capture.d.ts +0 -6
- package/dist/commands/capture.js +0 -324
- package/dist/commands/disable.d.ts +0 -1
- package/dist/commands/disable.js +0 -14
- package/dist/commands/doctor.d.ts +0 -1
- package/dist/commands/doctor.js +0 -89
- package/dist/commands/init.d.ts +0 -1
- package/dist/commands/init.js +0 -52
- package/dist/commands/inject.d.ts +0 -5
- package/dist/commands/inject.js +0 -88
- package/dist/commands/prompt-inject.d.ts +0 -4
- package/dist/commands/prompt-inject.js +0 -451
- package/dist/commands/unregister.d.ts +0 -1
- package/dist/commands/unregister.js +0 -28
- package/dist/lib/anchor-extractor.d.ts +0 -30
- package/dist/lib/anchor-extractor.js +0 -296
- package/dist/lib/correction-builder.d.ts +0 -10
- package/dist/lib/correction-builder.js +0 -226
- package/dist/lib/drift-checker-proxy.js +0 -373
- package/dist/lib/drift-checker.d.ts +0 -66
- package/dist/lib/drift-checker.js +0 -341
- package/dist/lib/hooks.d.ts +0 -38
- package/dist/lib/hooks.js +0 -291
- package/dist/lib/jsonl-parser.d.ts +0 -87
- package/dist/lib/jsonl-parser.js +0 -281
- package/dist/lib/session-parser.d.ts +0 -44
- package/dist/lib/session-parser.js +0 -256
- package/dist/lib/store.d.ts +0 -1
- package/dist/proxy/cache.d.ts +0 -32
- package/dist/proxy/cache.js +0 -47
- package/dist/proxy/handlers/preprocess.js +0 -186
- package/dist/proxy/index.js +0 -30
- package/dist/proxy/injection/delta-tracking.d.ts +0 -11
- package/dist/proxy/injection/delta-tracking.js +0 -94
- package/dist/proxy/injection/injectors.d.ts +0 -7
- package/dist/proxy/injection/injectors.js +0 -139
- package/dist/proxy/request-processor.d.ts +0 -27
- package/dist/proxy/request-processor.js +0 -233
- package/dist/proxy/server.js +0 -1289
- /package/dist/{commands → cli/commands}/drift-test.d.ts +0 -0
- /package/dist/{commands → cli/commands}/login.d.ts +0 -0
- /package/dist/{commands → cli/commands}/logout.d.ts +0 -0
- /package/dist/{commands → cli/commands}/proxy-status.d.ts +0 -0
- /package/dist/{commands → cli/commands}/status.d.ts +0 -0
- /package/dist/{commands → cli/commands}/uninstall.d.ts +0 -0
- /package/dist/{cli.d.ts → cli/index.d.ts} +0 -0
- /package/dist/{lib → core/cloud}/api-client.d.ts +0 -0
- /package/dist/{lib → core/cloud}/api-client.js +0 -0
- /package/dist/{lib → core/cloud}/credentials.d.ts +0 -0
- /package/dist/{lib → core/cloud}/credentials.js +0 -0
- /package/dist/{lib → core}/store/convenience.d.ts +0 -0
- /package/dist/{lib → core}/store/convenience.js +0 -0
- /package/dist/{lib → core}/store/database.d.ts +0 -0
- /package/dist/{lib → core}/store/database.js +0 -0
- /package/dist/{lib → core}/store/drift.d.ts +0 -0
- /package/dist/{lib → core}/store/drift.js +0 -0
- /package/dist/{lib → core}/store/index.d.ts +0 -0
- /package/dist/{lib → core}/store/index.js +0 -0
- /package/dist/{lib → core}/store/sessions.d.ts +0 -0
- /package/dist/{lib → core}/store/steps.d.ts +0 -0
- /package/dist/{lib → core}/store/steps.js +0 -0
- /package/dist/{lib → core}/store/tasks.d.ts +0 -0
- /package/dist/{lib → core}/store/tasks.js +0 -0
- /package/dist/{lib → core}/store/types.js +0 -0
- /package/dist/{proxy/action-parser.js → integrations/proxy/agents/claude/parser.js} +0 -0
- /package/dist/{lib → integrations/proxy/agents/claude}/settings.d.ts +0 -0
- /package/dist/{lib → integrations/proxy/agents/claude}/settings.js +0 -0
- /package/dist/{proxy → integrations/proxy/cache}/extended-cache.d.ts +0 -0
- /package/dist/{proxy → integrations/proxy}/config.d.ts +0 -0
- /package/dist/{proxy → integrations/proxy}/index.d.ts +0 -0
- /package/dist/{proxy → integrations/proxy}/types.js +0 -0
- /package/dist/{lib → utils}/debug.d.ts +0 -0
- /package/dist/{lib → utils}/debug.js +0 -0
- /package/dist/{lib → utils}/utils.d.ts +0 -0
- /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 };
|