inspect-session.mjs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Inspect the most recent session to see what events were captured
  3. */
  4. import { SessionReader } from './dist/collector/session-reader.js';
  5. import path from 'path';
  6. import os from 'os';
  7. const sessionStoragePath = path.join(os.homedir(), '.local', 'share', 'opencode');
  8. const reader = new SessionReader(undefined, sessionStoragePath);
  9. // Get session ID from command line or use most recent
  10. const sessionId = process.argv[2];
  11. let mostRecent;
  12. if (sessionId) {
  13. console.log(`Looking for session: ${sessionId}`);
  14. mostRecent = await reader.getSessionInfo(sessionId);
  15. if (!mostRecent) {
  16. console.log('Session not found!');
  17. process.exit(1);
  18. }
  19. } else {
  20. // Get the most recent session
  21. const sessions = await reader.listSessions();
  22. mostRecent = sessions[0];
  23. }
  24. console.log('='.repeat(70));
  25. console.log('Most Recent Session Analysis');
  26. console.log('='.repeat(70));
  27. console.log('');
  28. console.log('Session Info:');
  29. console.log(' ID:', mostRecent.id);
  30. console.log(' Title:', mostRecent.title);
  31. console.log(' Agent:', mostRecent.agent || 'N/A');
  32. console.log(' Directory:', mostRecent.directory);
  33. console.log(' Created:', new Date(mostRecent.time.created).toISOString());
  34. console.log('');
  35. // Get messages
  36. const messages = await reader.getMessages(mostRecent.id);
  37. console.log(`Messages: ${messages.length}`);
  38. console.log('');
  39. for (let i = 0; i < messages.length; i++) {
  40. const msg = messages[i];
  41. console.log('-'.repeat(70));
  42. console.log(`Message ${i + 1}:`);
  43. console.log(' ID:', msg.id);
  44. console.log(' Role:', msg.role);
  45. console.log(' Agent:', msg.agent || 'N/A');
  46. console.log(' Model:', msg.model?.modelID || 'N/A');
  47. console.log(' Created:', new Date(msg.time.created).toISOString());
  48. const parts = await reader.getParts(mostRecent.id, msg.id);
  49. console.log(` Parts: ${parts.length}`);
  50. console.log('');
  51. for (let j = 0; j < parts.length; j++) {
  52. const part = parts[j];
  53. console.log(` Part ${j + 1}:`);
  54. console.log(` Type: ${part.type}`);
  55. if (part.type === 'text') {
  56. const text = part.text || '';
  57. console.log(` Text: ${text.substring(0, 200)}${text.length > 200 ? '...' : ''}`);
  58. } else if (part.type === 'tool') {
  59. console.log(` Tool: ${part.tool}`);
  60. console.log(` Input: ${JSON.stringify(part.input).substring(0, 100)}...`);
  61. }
  62. console.log('');
  63. }
  64. }
  65. console.log('='.repeat(70));