-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-final.js
More file actions
96 lines (75 loc) · 2.51 KB
/
test-final.js
File metadata and controls
96 lines (75 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Final test for getUserQuestions - should only show actual user questions
*/
const fs = require('node:fs');
const path = require('node:path');
const os = require('node:os');
const projectPath = '/Users/junwoobang/project/claude-code-spec';
const sessionId = '2e3d94ab-a4c0-4c5b-aaff-07dedd37f39e';
const pathToDashFormat = (fsPath) => {
return `-${fsPath.replace(/^\//, '').replace(/\//g, '-')}`;
};
const getClaudeProjectDir = (projectPath) => {
const dashName = pathToDashFormat(projectPath);
return path.join(os.homedir(), '.claude', 'projects', dashName);
};
const readSessionLog = (projectPath, sessionId) => {
const projectDir = getClaudeProjectDir(projectPath);
const sessionFile = path.join(projectDir, `${sessionId}.jsonl`);
if (!fs.existsSync(sessionFile)) {
return [];
}
try {
const content = fs.readFileSync(sessionFile, 'utf-8');
return content
.split('\n')
.filter((line) => line.trim())
.map((line) => JSON.parse(line));
} catch (_error) {
return [];
}
};
// FINAL: Improved getUserQuestions
const getUserQuestions = (projectPath, sessionId) => {
const entries = readSessionLog(projectPath, sessionId);
return entries.filter((entry) => {
if (entry.message && typeof entry.message === 'object') {
const message = entry.message;
if (message.role !== 'user') {
return false;
}
// Only process string content
if (typeof message.content !== 'string') {
return false;
}
const content = message.content.trim();
// Skip anything that starts with [{ - these are tool results or structured data
if (content.startsWith('[{')) {
return false;
}
// Skip system messages
if (content.startsWith('Caveat:')) {
return false;
}
// Skip command messages
if (content.includes('<command-name>') || content.includes('<command-message>')) {
return false;
}
// Skip empty stdout
if (content === '<local-command-stdout></local-command-stdout>') {
return false;
}
return true;
}
return false;
});
};
console.log('=== FINAL TEST: getUserQuestions ===\n');
console.log(`Session: ${sessionId}\n`);
const userQuestions = getUserQuestions(projectPath, sessionId);
console.log(`✅ Total actual user questions: ${userQuestions.length}\n`);
console.log('=== User Questions ===\n');
userQuestions.forEach((entry, idx) => {
console.log(`[${idx + 1}] ${entry.message.content.substring(0, 150)}`);
console.log('');
});