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
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
// Request processor - handles context injection from team memory
|
|
2
|
-
// Reference: plan_proxy_local.md Section 2.1
|
|
3
|
-
import { truncate } from '../lib/utils.js';
|
|
4
|
-
import { fetchTeamMemories } from '../lib/api-client.js';
|
|
5
|
-
import { isDebugMode } from './utils/logging.js';
|
|
6
|
-
/**
|
|
7
|
-
* Build context from CLOUD team memory for injection
|
|
8
|
-
* Fetches memories from Supabase via API (cloud-first approach)
|
|
9
|
-
* Uses hybrid search (semantic + lexical) when userPrompt is provided
|
|
10
|
-
*
|
|
11
|
-
* @param teamId - Team UUID from sync configuration
|
|
12
|
-
* @param projectPath - Project path to filter by
|
|
13
|
-
* @param mentionedFiles - Files mentioned in user messages (for boost)
|
|
14
|
-
* @param userPrompt - User's prompt for semantic search (optional)
|
|
15
|
-
* @returns Formatted context string or null if no memories found
|
|
16
|
-
*/
|
|
17
|
-
export async function buildTeamMemoryContextCloud(teamId, projectPath, mentionedFiles, userPrompt) {
|
|
18
|
-
const hasContext = userPrompt && userPrompt.trim().length > 0;
|
|
19
|
-
try {
|
|
20
|
-
// Fetch memories from cloud API (hybrid search if context provided)
|
|
21
|
-
const memories = await fetchTeamMemories(teamId, projectPath, {
|
|
22
|
-
status: 'complete',
|
|
23
|
-
limit: 5,
|
|
24
|
-
files: mentionedFiles.length > 0 ? mentionedFiles : undefined,
|
|
25
|
-
context: hasContext ? userPrompt : undefined,
|
|
26
|
-
current_files: mentionedFiles.length > 0 ? mentionedFiles : undefined,
|
|
27
|
-
});
|
|
28
|
-
if (memories.length === 0) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
// Log injected memories (debug mode only)
|
|
32
|
-
if (isDebugMode()) {
|
|
33
|
-
for (const m of memories) {
|
|
34
|
-
const label = m.goal || m.original_query;
|
|
35
|
-
const sem = m.semantic_score?.toFixed(2) || '-';
|
|
36
|
-
const lex = m.lexical_score?.toFixed(2) || '-';
|
|
37
|
-
const comb = m.combined_score?.toFixed(2) || '-';
|
|
38
|
-
console.log(`[INJECT] ${label.substring(0, 50)}... (${comb}|${sem}|${lex})`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Convert Memory[] to Task[] format for the existing formatter
|
|
42
|
-
const tasks = memories.map(memoryToTask);
|
|
43
|
-
// Reuse existing formatter
|
|
44
|
-
const context = formatTeamMemoryContext(tasks, [], mentionedFiles);
|
|
45
|
-
return context;
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
return null; // Fail silent - don't block Claude Code
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Convert Memory (cloud format) to Task (local format)
|
|
53
|
-
* Used to reuse existing formatTeamMemoryContext function
|
|
54
|
-
*/
|
|
55
|
-
function memoryToTask(memory) {
|
|
56
|
-
return {
|
|
57
|
-
id: memory.id,
|
|
58
|
-
project_path: memory.project_path,
|
|
59
|
-
user: memory.user_id || undefined,
|
|
60
|
-
original_query: memory.original_query,
|
|
61
|
-
goal: memory.goal || undefined,
|
|
62
|
-
reasoning_trace: memory.reasoning_trace || [],
|
|
63
|
-
files_touched: memory.files_touched || [],
|
|
64
|
-
decisions: memory.decisions || [],
|
|
65
|
-
constraints: memory.constraints || [],
|
|
66
|
-
status: memory.status,
|
|
67
|
-
tags: memory.tags || [],
|
|
68
|
-
linked_commit: memory.linked_commit || undefined,
|
|
69
|
-
created_at: memory.created_at,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Format team memory context for injection
|
|
74
|
-
*/
|
|
75
|
-
function formatTeamMemoryContext(tasks, fileReasonings, files) {
|
|
76
|
-
const lines = [];
|
|
77
|
-
lines.push('=== VERIFIED TEAM KNOWLEDGE (from previous sessions) ===');
|
|
78
|
-
lines.push('');
|
|
79
|
-
lines.push('IMPORTANT: This context has been verified. USE IT to answer directly.');
|
|
80
|
-
lines.push('DO NOT launch Explore agents or re-investigate files mentioned below.');
|
|
81
|
-
lines.push('');
|
|
82
|
-
// File-level context
|
|
83
|
-
if (fileReasonings.length > 0) {
|
|
84
|
-
lines.push('File-level context:');
|
|
85
|
-
for (const fr of fileReasonings.slice(0, 5)) {
|
|
86
|
-
const anchor = fr.anchor ? ` (${fr.anchor})` : '';
|
|
87
|
-
lines.push(`- ${fr.file_path}${anchor}: ${truncate(fr.reasoning, 100)}`);
|
|
88
|
-
}
|
|
89
|
-
lines.push('');
|
|
90
|
-
}
|
|
91
|
-
// Task context with knowledge pairs and decisions
|
|
92
|
-
// Inject up to 5 pairs (10 entries) per task for rich context
|
|
93
|
-
if (tasks.length > 0) {
|
|
94
|
-
lines.push('Related past tasks:');
|
|
95
|
-
for (const task of tasks.slice(0, 5)) { // Limit to 5 tasks (Convex Combination top results)
|
|
96
|
-
lines.push(`- ${truncate(task.original_query, 60)}`);
|
|
97
|
-
if (task.files_touched.length > 0) {
|
|
98
|
-
const fileList = task.files_touched.slice(0, 5).map(f => f.split('/').pop()).join(', ');
|
|
99
|
-
lines.push(` Files: ${fileList}`);
|
|
100
|
-
}
|
|
101
|
-
// Inject knowledge pairs - handle both formats:
|
|
102
|
-
// Old format: string[] interleaved (conclusion, insight, conclusion, insight...)
|
|
103
|
-
// New format: Array<{ tags?, conclusion, insight? }> objects
|
|
104
|
-
if (task.reasoning_trace.length > 0) {
|
|
105
|
-
lines.push(' Knowledge:');
|
|
106
|
-
const maxPairs = 5;
|
|
107
|
-
const entries = task.reasoning_trace.slice(0, maxPairs);
|
|
108
|
-
for (const entry of entries) {
|
|
109
|
-
if (typeof entry === 'string') {
|
|
110
|
-
// Old format: plain string - just remove prefix and show
|
|
111
|
-
const text = entry.replace(/^(CONCLUSION|INSIGHT):\s*/i, '');
|
|
112
|
-
if (text) {
|
|
113
|
-
lines.push(` • ${truncate(text, 120)}`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else if (typeof entry === 'object' && entry !== null) {
|
|
117
|
-
// New format: object with tags, conclusion, insight
|
|
118
|
-
const cText = entry.conclusion?.replace(/^CONCLUSION:\s*/i, '') || '';
|
|
119
|
-
if (cText) {
|
|
120
|
-
const prefix = entry.tags ? `[${entry.tags}] ` : '';
|
|
121
|
-
lines.push(` • ${prefix}${truncate(cText, 110)}`);
|
|
122
|
-
}
|
|
123
|
-
if (entry.insight) {
|
|
124
|
-
const iText = entry.insight.replace(/^INSIGHT:\s*/i, '');
|
|
125
|
-
lines.push(` → ${truncate(iText, 100)}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
// Include decisions (up to 2 per task)
|
|
131
|
-
if (task.decisions && task.decisions.length > 0) {
|
|
132
|
-
const decisionsToShow = task.decisions.slice(0, 2);
|
|
133
|
-
for (const decision of decisionsToShow) {
|
|
134
|
-
lines.push(` Decision: ${truncate(decision.choice, 60)} (${truncate(decision.reason, 50)})`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
// Include constraints if available
|
|
138
|
-
if (task.constraints && task.constraints.length > 0) {
|
|
139
|
-
lines.push(` Constraints: ${task.constraints.slice(0, 2).join(', ')}`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
lines.push('');
|
|
143
|
-
}
|
|
144
|
-
if (files.length > 0) {
|
|
145
|
-
lines.push(`Files with existing context: ${files.join(', ')}`);
|
|
146
|
-
}
|
|
147
|
-
lines.push('');
|
|
148
|
-
lines.push('Answer the user\'s question using the knowledge above. Skip exploration.');
|
|
149
|
-
lines.push('=== END VERIFIED TEAM KNOWLEDGE ===');
|
|
150
|
-
return lines.join('\n');
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Extract file paths from messages (user messages only, clean text)
|
|
154
|
-
*/
|
|
155
|
-
export function extractFilesFromMessages(messages) {
|
|
156
|
-
const files = [];
|
|
157
|
-
// Pattern matches filenames with extensions, allowing common punctuation after
|
|
158
|
-
const filePattern = /(?:^|\s|["'`])([\/\w.-]+\.[a-zA-Z]{1,10})(?:["'`]|\s|$|[:)\]?!,;])/g;
|
|
159
|
-
for (const msg of messages) {
|
|
160
|
-
// Only scan user messages for file mentions
|
|
161
|
-
if (msg.role !== 'user')
|
|
162
|
-
continue;
|
|
163
|
-
let textContent = '';
|
|
164
|
-
// Handle string content
|
|
165
|
-
if (typeof msg.content === 'string') {
|
|
166
|
-
textContent = msg.content;
|
|
167
|
-
}
|
|
168
|
-
// Handle array content (Claude Code API format)
|
|
169
|
-
if (Array.isArray(msg.content)) {
|
|
170
|
-
for (const block of msg.content) {
|
|
171
|
-
if (block && typeof block === 'object' && 'type' in block && block.type === 'text' && 'text' in block && typeof block.text === 'string') {
|
|
172
|
-
textContent += block.text + '\n';
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
// Strip system-reminder tags to get clean user content
|
|
177
|
-
const cleanContent = textContent
|
|
178
|
-
.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, '')
|
|
179
|
-
.trim();
|
|
180
|
-
if (cleanContent) {
|
|
181
|
-
let match;
|
|
182
|
-
while ((match = filePattern.exec(cleanContent)) !== null) {
|
|
183
|
-
const path = match[1];
|
|
184
|
-
// Filter out common false positives
|
|
185
|
-
if (!path.includes('http') && !path.startsWith('.') && path.length > 3) {
|
|
186
|
-
files.push(path);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return [...new Set(files)];
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Extract the last user prompt from messages for semantic search
|
|
195
|
-
* Returns clean text without system tags
|
|
196
|
-
*/
|
|
197
|
-
export function extractLastUserPrompt(messages) {
|
|
198
|
-
// Find last user message
|
|
199
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
200
|
-
const msg = messages[i];
|
|
201
|
-
if (msg.role !== 'user')
|
|
202
|
-
continue;
|
|
203
|
-
let textContent = '';
|
|
204
|
-
// Handle string content
|
|
205
|
-
if (typeof msg.content === 'string') {
|
|
206
|
-
textContent = msg.content;
|
|
207
|
-
}
|
|
208
|
-
// Handle array content (Claude Code API format)
|
|
209
|
-
if (Array.isArray(msg.content)) {
|
|
210
|
-
for (const block of msg.content) {
|
|
211
|
-
if (block && typeof block === 'object' && 'type' in block && block.type === 'text' && 'text' in block && typeof block.text === 'string') {
|
|
212
|
-
textContent += block.text + '\n';
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
// Strip system-reminder tags and continuation artifacts to get clean user content
|
|
217
|
-
const cleanContent = textContent
|
|
218
|
-
// Remove actual system-reminder tags
|
|
219
|
-
.replace(/<system-reminder>[\s\S]*?<\/system-reminder>/g, '')
|
|
220
|
-
// Remove escaped/broken system-reminder artifacts from continuation summaries
|
|
221
|
-
.replace(/\\n["']?\s*<\/system-reminder>/g, '')
|
|
222
|
-
.replace(/<\/system-reminder>/g, '')
|
|
223
|
-
// Remove continuation summary header if it's the entire content
|
|
224
|
-
.replace(/^This session is being continued from a previous conversation[\s\S]*?Summary:/gi, '')
|
|
225
|
-
// Clean up leading noise (newlines, quotes, whitespace)
|
|
226
|
-
.replace(/^[\s\n"'\\]+/, '')
|
|
227
|
-
.trim();
|
|
228
|
-
if (cleanContent && cleanContent.length > 5) {
|
|
229
|
-
return cleanContent;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return undefined;
|
|
233
|
-
}
|