Enhance context hook output formatting and add file aggregation for sessions
- Updated contextHook to support colorized output for terminal and JSON format for hooks. - Introduced ANSI color codes for improved readability in terminal output. - Modified the output structure to include session details with color formatting. - Added a new method in SessionStore to aggregate files read and modified from observations for a session. - Improved error handling for JSON parsing of file data in the new method.
This commit is contained in:
@@ -532,6 +532,59 @@ export class SessionStore {
|
||||
return stmt.get(sdkSessionId) as any || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get aggregated files from all observations for a session
|
||||
*/
|
||||
getFilesForSession(sdkSessionId: string): {
|
||||
filesRead: string[];
|
||||
filesModified: string[];
|
||||
} {
|
||||
const stmt = this.db.prepare(`
|
||||
SELECT files_read, files_modified
|
||||
FROM observations
|
||||
WHERE sdk_session_id = ?
|
||||
`);
|
||||
|
||||
const rows = stmt.all(sdkSessionId) as Array<{
|
||||
files_read: string | null;
|
||||
files_modified: string | null;
|
||||
}>;
|
||||
|
||||
const filesReadSet = new Set<string>();
|
||||
const filesModifiedSet = new Set<string>();
|
||||
|
||||
for (const row of rows) {
|
||||
// Parse files_read
|
||||
if (row.files_read) {
|
||||
try {
|
||||
const files = JSON.parse(row.files_read);
|
||||
if (Array.isArray(files)) {
|
||||
files.forEach(f => filesReadSet.add(f));
|
||||
}
|
||||
} catch {
|
||||
// Skip invalid JSON
|
||||
}
|
||||
}
|
||||
|
||||
// Parse files_modified
|
||||
if (row.files_modified) {
|
||||
try {
|
||||
const files = JSON.parse(row.files_modified);
|
||||
if (Array.isArray(files)) {
|
||||
files.forEach(f => filesModifiedSet.add(f));
|
||||
}
|
||||
} catch {
|
||||
// Skip invalid JSON
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
filesRead: Array.from(filesReadSet),
|
||||
filesModified: Array.from(filesModifiedSet)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session by ID
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user