@claude-sessions/core 0.3.7 → 0.4.1-beta.0

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MessagePayload, a as Message, P as Project, T as TodoItem, F as FileChange, C as CompressSessionOptions, S as SummarizeSessionOptions, b as ConversationLine, c as MoveSessionResult, d as SearchResult, e as SummaryInfo, A as AgentInfo } from './types-Cz8chaYQ.js';
2
- export { l as CleanupPreview, k as ClearSessionsResult, s as CompressSessionResult, f as ContentItem, D as DeleteSessionResult, t as ProjectKnowledge, n as ProjectTreeData, R as RenameSessionResult, o as ResumeSessionOptions, p as ResumeSessionResult, r as SessionAnalysis, i as SessionFilesSummary, g as SessionMeta, h as SessionTodos, m as SessionTreeData, j as SplitSessionResult, u as SummarizeSessionResult, q as ToolUsageStats } from './types-Cz8chaYQ.js';
1
+ import { P as Project, M as MessagePayload$1, a as Message, S as SummaryInfo, b as SessionTodos, c as MoveSessionResult, A as AgentInfo, d as SessionSortOptions, e as ProjectTreeData, C as CompressSessionOptions, f as SummarizeSessionOptions, g as ConversationLine, h as SearchResult, F as FileChange, i as SessionsIndex, j as SessionIndexEntry } from './types-mWa378iC.js';
2
+ export { p as CleanupPreview, o as ClearSessionsResult, v as CompressSessionResult, k as ContentItem, D as DeleteSessionResult, w as ProjectKnowledge, R as RenameSessionResult, r as ResumeSessionOptions, s as ResumeSessionResult, u as SessionAnalysis, m as SessionFilesSummary, l as SessionMeta, y as SessionSortField, z as SessionSortOrder, q as SessionTreeData, n as SplitSessionResult, x as SummarizeSessionResult, T as TodoItem, t as ToolUsageStats } from './types-mWa378iC.js';
3
3
  import * as effect_Cause from 'effect/Cause';
4
4
  import { Effect } from 'effect';
5
5
 
@@ -59,16 +59,37 @@ declare const folderNameToPath: (folderName: string) => string;
59
59
  declare const findProjectByWorkspacePath: (workspacePath: string, projectNames: string[], sessionsDir?: string, fileSystem?: FileSystem, logger?: Logger$1) => string | null;
60
60
 
61
61
  /**
62
- * Utility functions for message processing
62
+ * Project-level utilities
63
63
  */
64
64
 
65
- declare const extractTextContent: (message: MessagePayload | undefined) => string;
65
+ /**
66
+ * Sort projects with priority:
67
+ * 1. Current project (if specified)
68
+ * 2. Current user's home directory subpaths
69
+ * 3. Others (alphabetically by displayName)
70
+ */
71
+ declare const sortProjects: (projects: Project[], options?: {
72
+ currentProjectName?: string | null;
73
+ homeDir?: string;
74
+ filterEmpty?: boolean;
75
+ }) => Project[];
76
+
77
+ declare const extractTextContent: (message: MessagePayload$1 | undefined) => string;
78
+ /**
79
+ * Parse command message content (e.g., slash commands like /commit)
80
+ * Returns the command name and message extracted from XML tags
81
+ */
82
+ declare const parseCommandMessage: (content?: string) => {
83
+ name: string;
84
+ message: string;
85
+ };
66
86
  declare const extractTitle: (text: string) => string;
67
87
  declare const isInvalidApiKeyMessage: (msg: Message) => boolean;
68
88
  declare const isContinuationSummary: (msg: Message) => boolean;
69
89
  /**
70
90
  * Get display title with fallback logic
71
91
  * Priority: customTitle > currentSummary (truncated) > title > fallback
92
+ * Also handles slash command format in title
72
93
  */
73
94
  declare const getDisplayTitle: (customTitle: string | undefined, currentSummary: string | undefined, title: string | undefined, maxLength?: number, fallback?: string) => string;
74
95
  /**
@@ -77,16 +98,28 @@ declare const getDisplayTitle: (customTitle: string | undefined, currentSummary:
77
98
  */
78
99
  declare const maskHomePath: (text: string, homeDir: string) => string;
79
100
  /**
80
- * Sort projects with priority:
81
- * 1. Current project (if specified)
82
- * 2. Current user's home directory subpaths
83
- * 3. Others (alphabetically by displayName)
101
+ * Get sort timestamp for session (Unix timestamp ms)
102
+ * Priority: summaries[0].timestamp > createdAt > 0
84
103
  */
85
- declare const sortProjects: (projects: Project[], options?: {
86
- currentProjectName?: string | null;
87
- homeDir?: string;
88
- filterEmpty?: boolean;
89
- }) => Project[];
104
+ declare const getSessionSortTimestamp: (session: {
105
+ summaries?: SummaryInfo[];
106
+ createdAt?: string;
107
+ }) => number;
108
+ /**
109
+ * Try to parse a single JSON line, returning null on failure with optional warning log
110
+ * Use this when you want to skip invalid lines instead of throwing
111
+ */
112
+ declare const tryParseJsonLine: <T = Record<string, unknown>>(line: string, lineNumber: number, filePath?: string) => T | null;
113
+ /**
114
+ * Parse JSONL lines with detailed error messages including file path and line number
115
+ * @throws Error with "Failed to parse line X in /path/to/file: original error"
116
+ */
117
+ declare const parseJsonlLines: <T = Record<string, unknown>>(lines: string[], filePath: string) => T[];
118
+ /**
119
+ * Read and parse JSONL file (Effect wrapper)
120
+ * Combines file reading and JSONL parsing with proper error messages
121
+ */
122
+ declare const readJsonlFile: <T = Record<string, unknown>>(filePath: string) => Effect.Effect<T[], effect_Cause.UnknownException, never>;
90
123
 
91
124
  declare const findLinkedAgents: (projectName: string, sessionId: string) => Effect.Effect<string[], effect_Cause.UnknownException, never>;
92
125
  declare const findOrphanAgents: (projectName: string) => Effect.Effect<{
@@ -106,15 +139,7 @@ declare const deleteOrphanAgents: (projectName: string) => Effect.Effect<{
106
139
  declare const loadAgentMessages: (projectName: string, _sessionId: string, // Reserved for future validation
107
140
  agentId: string) => Effect.Effect<Message[], effect_Cause.UnknownException, never>;
108
141
 
109
- declare const findLinkedTodos: (sessionId: string, agentIds?: string[]) => Effect.Effect<{
110
- sessionId: string;
111
- sessionTodos: TodoItem[];
112
- agentTodos: {
113
- agentId: string;
114
- todos: TodoItem[];
115
- }[];
116
- hasTodos: boolean;
117
- }, effect_Cause.UnknownException, never>;
142
+ declare const findLinkedTodos: (sessionId: string, agentIds?: string[]) => Effect.Effect<SessionTodos, effect_Cause.UnknownException, never>;
118
143
  declare const sessionHasTodos: (sessionId: string, agentIds?: string[]) => Effect.Effect<boolean, effect_Cause.UnknownException, never>;
119
144
  declare const deleteLinkedTodos: (sessionId: string, agentIds: string[]) => Effect.Effect<{
120
145
  deletedCount: number;
@@ -126,16 +151,22 @@ declare const deleteOrphanTodos: () => Effect.Effect<{
126
151
  }, effect_Cause.UnknownException, never>;
127
152
 
128
153
  declare const listProjects: Effect.Effect<Project[], effect_Cause.UnknownException, never>;
154
+
155
+ declare const updateSessionSummary: (projectName: string, sessionId: string, newSummary: string) => Effect.Effect<{
156
+ success: boolean;
157
+ }, effect_Cause.UnknownException, never>;
129
158
  declare const listSessions: (projectName: string) => Effect.Effect<{
130
159
  id: string;
131
160
  projectName: string;
132
161
  title: string;
162
+ customTitle: string | undefined;
163
+ currentSummary: string | undefined;
133
164
  messageCount: number;
134
165
  createdAt: string | undefined;
135
166
  updatedAt: string | undefined;
136
167
  }[], effect_Cause.UnknownException, never>;
137
168
  declare const readSession: (projectName: string, sessionId: string) => Effect.Effect<Message[], effect_Cause.UnknownException, never>;
138
- declare const deleteMessage: (projectName: string, sessionId: string, messageUuid: string) => Effect.Effect<{
169
+ declare const deleteMessage: (projectName: string, sessionId: string, messageUuid: string, targetType?: "file-history-snapshot" | "summary") => Effect.Effect<{
139
170
  success: boolean;
140
171
  error: string;
141
172
  deletedMessage?: undefined;
@@ -169,12 +200,41 @@ declare const renameSession: (projectName: string, sessionId: string, newTitle:
169
200
  success: true;
170
201
  error?: undefined;
171
202
  }, effect_Cause.UnknownException, never>;
172
- declare const getSessionFiles: (projectName: string, sessionId: string) => Effect.Effect<{
173
- sessionId: string;
203
+ declare const moveSession: (sourceProject: string, sessionId: string, targetProject: string) => Effect.Effect<MoveSessionResult, Error>;
204
+ declare const splitSession: (projectName: string, sessionId: string, splitAtMessageUuid: string) => Effect.Effect<{
205
+ success: false;
206
+ error: string;
207
+ newSessionId?: undefined;
208
+ newSessionPath?: undefined;
209
+ movedMessageCount?: undefined;
210
+ duplicatedSummary?: undefined;
211
+ } | {
212
+ success: true;
213
+ newSessionId: `${string}-${string}-${string}-${string}-${string}`;
214
+ newSessionPath: string;
215
+ movedMessageCount: number;
216
+ duplicatedSummary: boolean;
217
+ error?: undefined;
218
+ }, effect_Cause.UnknownException, never>;
219
+
220
+ declare const loadSessionTreeData: (projectName: string, sessionId: string) => Effect.Effect<{
221
+ id: string;
174
222
  projectName: string;
175
- files: FileChange[];
176
- totalChanges: number;
223
+ title: string;
224
+ customTitle: string | undefined;
225
+ currentSummary: string;
226
+ messageCount: number;
227
+ createdAt: string;
228
+ updatedAt: string;
229
+ fileMtime: number | undefined;
230
+ sortTimestamp: number;
231
+ summaries: SummaryInfo[];
232
+ agents: AgentInfo[];
233
+ todos: SessionTodos;
234
+ lastCompactBoundaryUuid: string | undefined;
177
235
  }, effect_Cause.UnknownException, never>;
236
+ declare const loadProjectTreeData: (projectName: string, sortOptions?: SessionSortOptions) => Effect.Effect<ProjectTreeData | null, effect_Cause.UnknownException, never>;
237
+
178
238
  declare const analyzeSession: (projectName: string, sessionId: string) => Effect.Effect<{
179
239
  sessionId: string;
180
240
  projectName: string;
@@ -203,28 +263,46 @@ declare const analyzeSession: (projectName: string, sessionId: string) => Effect
203
263
  messageUuid?: string;
204
264
  }[];
205
265
  }, effect_Cause.UnknownException, never>;
206
- declare const moveSession: (sourceProject: string, sessionId: string, targetProject: string) => Effect.Effect<MoveSessionResult, Error>;
207
- declare const splitSession: (projectName: string, sessionId: string, splitAtMessageUuid: string) => Effect.Effect<{
208
- success: false;
209
- error: string;
210
- newSessionId?: undefined;
211
- newSessionPath?: undefined;
212
- movedMessageCount?: undefined;
213
- duplicatedSummary?: undefined;
214
- } | {
266
+ declare const compressSession: (projectName: string, sessionId: string, options?: CompressSessionOptions) => Effect.Effect<{
215
267
  success: true;
216
- newSessionId: `${string}-${string}-${string}-${string}-${string}`;
217
- newSessionPath: string;
218
- movedMessageCount: number;
219
- duplicatedSummary: boolean;
220
- error?: undefined;
268
+ originalSize: number;
269
+ compressedSize: number;
270
+ removedSnapshots: number;
271
+ truncatedOutputs: number;
272
+ }, effect_Cause.UnknownException, never>;
273
+ declare const extractProjectKnowledge: (projectName: string, sessionIds?: string[]) => Effect.Effect<{
274
+ projectName: string;
275
+ patterns: never[];
276
+ hotFiles: {
277
+ path: string;
278
+ modifyCount: number;
279
+ lastModified: string | undefined;
280
+ }[];
281
+ workflows: {
282
+ sequence: string[];
283
+ count: number;
284
+ }[];
285
+ decisions: {
286
+ context: string;
287
+ decision: string;
288
+ sessionId: string;
289
+ }[];
290
+ }, effect_Cause.UnknownException, never>;
291
+ declare const summarizeSession: (projectName: string, sessionId: string, options?: SummarizeSessionOptions) => Effect.Effect<{
292
+ sessionId: string;
293
+ projectName: string;
294
+ lines: ConversationLine[];
295
+ formatted: string;
221
296
  }, effect_Cause.UnknownException, never>;
297
+
222
298
  declare const previewCleanup: (projectName?: string) => Effect.Effect<{
223
299
  project: string;
224
300
  emptySessions: {
225
301
  id: string;
226
302
  projectName: string;
227
303
  title: string;
304
+ customTitle: string | undefined;
305
+ currentSummary: string | undefined;
228
306
  messageCount: number;
229
307
  createdAt: string | undefined;
230
308
  updatedAt: string | undefined;
@@ -233,6 +311,8 @@ declare const previewCleanup: (projectName?: string) => Effect.Effect<{
233
311
  id: string;
234
312
  projectName: string;
235
313
  title: string;
314
+ customTitle: string | undefined;
315
+ currentSummary: string | undefined;
236
316
  messageCount: number;
237
317
  createdAt: string | undefined;
238
318
  updatedAt: string | undefined;
@@ -255,95 +335,113 @@ declare const clearSessions: (options: {
255
335
  deletedOrphanAgentCount: number;
256
336
  deletedOrphanTodoCount: number;
257
337
  }, effect_Cause.UnknownException, never>;
338
+
258
339
  declare const searchSessions: (query: string, options?: {
259
340
  projectName?: string;
260
341
  searchContent?: boolean;
261
- }) => Effect.Effect<SearchResult[], effect_Cause.UnknownException, never>;
262
- declare const loadSessionTreeData: (projectName: string, sessionId: string) => Effect.Effect<{
263
- id: string;
342
+ }) => Effect.Effect<(SearchResult | {
343
+ sessionId: string;
264
344
  projectName: string;
265
345
  title: string;
266
- customTitle: string | undefined;
267
- currentSummary: string;
268
- messageCount: number;
269
- createdAt: string;
270
- updatedAt: string;
271
- summaries: SummaryInfo[];
272
- agents: AgentInfo[];
273
- todos: {
274
- sessionId: string;
275
- sessionTodos: TodoItem[];
276
- agentTodos: {
277
- agentId: string;
278
- todos: TodoItem[];
279
- }[];
280
- hasTodos: boolean;
281
- };
282
- lastCompactBoundaryUuid: string | undefined;
283
- }, effect_Cause.UnknownException, never>;
284
- declare const loadProjectTreeData: (projectName: string) => Effect.Effect<{
285
- name: string;
286
- displayName: string;
287
- path: string;
288
- sessionCount: number;
289
- sessions: {
290
- id: string;
291
- projectName: string;
292
- title: string;
293
- customTitle: string | undefined;
294
- currentSummary: string;
295
- messageCount: number;
296
- createdAt: string;
297
- updatedAt: string;
298
- summaries: SummaryInfo[];
299
- agents: AgentInfo[];
300
- todos: {
301
- sessionId: string;
302
- sessionTodos: TodoItem[];
303
- agentTodos: {
304
- agentId: string;
305
- todos: TodoItem[];
306
- }[];
307
- hasTodos: boolean;
308
- };
309
- lastCompactBoundaryUuid: string | undefined;
310
- }[];
311
- } | null, effect_Cause.UnknownException, never>;
312
- declare const updateSessionSummary: (projectName: string, sessionId: string, newSummary: string) => Effect.Effect<{
313
- success: boolean;
314
- }, effect_Cause.UnknownException, never>;
315
- declare const compressSession: (projectName: string, sessionId: string, options?: CompressSessionOptions) => Effect.Effect<{
316
- success: true;
317
- originalSize: number;
318
- compressedSize: number;
319
- removedSnapshots: number;
320
- truncatedOutputs: number;
321
- }, effect_Cause.UnknownException, never>;
322
- declare const extractProjectKnowledge: (projectName: string, sessionIds?: string[]) => Effect.Effect<{
323
- projectName: string;
324
- patterns: never[];
325
- hotFiles: {
326
- path: string;
327
- modifyCount: number;
328
- lastModified: string | undefined;
329
- }[];
330
- workflows: {
331
- sequence: string[];
332
- count: number;
333
- }[];
334
- decisions: {
335
- context: string;
336
- decision: string;
337
- sessionId: string;
338
- }[];
339
- }, effect_Cause.UnknownException, never>;
340
- declare const summarizeSession: (projectName: string, sessionId: string, options?: SummarizeSessionOptions) => Effect.Effect<{
346
+ matchType: "title";
347
+ timestamp: string | undefined;
348
+ })[], effect_Cause.UnknownException, never>;
349
+
350
+ declare const getSessionFiles: (projectName: string, sessionId: string) => Effect.Effect<{
341
351
  sessionId: string;
342
352
  projectName: string;
343
- lines: ConversationLine[];
344
- formatted: string;
353
+ files: FileChange[];
354
+ totalChanges: number;
345
355
  }, effect_Cause.UnknownException, never>;
346
356
 
357
+ /**
358
+ * Session message chain validation utilities
359
+ *
360
+ * Validates:
361
+ * 1. parentUuid chain integrity (skip file-history-snapshot)
362
+ * 2. tool_use_id / tool_result matching
363
+ */
364
+ interface ChainError {
365
+ type: 'broken_chain' | 'orphan_parent';
366
+ uuid: string;
367
+ line: number;
368
+ parentUuid: string | null;
369
+ expectedParent?: string;
370
+ }
371
+ interface ToolUseResultError {
372
+ type: 'orphan_tool_result';
373
+ uuid: string;
374
+ line: number;
375
+ toolUseId: string;
376
+ }
377
+ interface ValidationResult {
378
+ valid: boolean;
379
+ errors: (ChainError | ToolUseResultError)[];
380
+ }
381
+ interface MessagePayload {
382
+ role?: string;
383
+ content?: unknown;
384
+ }
385
+ interface GenericMessage {
386
+ type?: string;
387
+ uuid?: string;
388
+ parentUuid?: string | null;
389
+ message?: MessagePayload;
390
+ messageId?: string;
391
+ }
392
+ /**
393
+ * Validate parentUuid chain for messages
394
+ *
395
+ * Rules:
396
+ * - Skip file-history-snapshot type (has no uuid, uses messageId instead)
397
+ * - Skip messages without uuid
398
+ * - First message can have null parentUuid
399
+ * - Subsequent messages must have valid parentUuid pointing to existing uuid
400
+ */
401
+ declare function validateChain(messages: readonly GenericMessage[]): ValidationResult;
402
+ /**
403
+ * Validate tool_use_id / tool_result matching
404
+ *
405
+ * Rules:
406
+ * - All tool_result blocks must have a corresponding tool_use block in the session
407
+ * - tool_use blocks are collected from all messages (not just previous)
408
+ */
409
+ declare function validateToolUseResult(messages: readonly GenericMessage[]): ValidationResult;
410
+ /**
411
+ * Delete a message and repair the parentUuid chain
412
+ *
413
+ * This is a pure function for client-side use (without file I/O)
414
+ * Server-side deleteMessage in crud.ts uses similar logic with file operations
415
+ *
416
+ * @param messages - Array of messages (will be mutated)
417
+ * @param targetId - uuid, messageId, or leafUuid of message to delete
418
+ * @param targetType - Optional: 'file-history-snapshot' or 'summary' to disambiguate collisions
419
+ * @returns Object with deleted message and messages to also delete (orphan tool_results)
420
+ */
421
+ declare function deleteMessageWithChainRepair<T extends GenericMessage>(messages: T[], targetId: string, targetType?: 'file-history-snapshot' | 'summary'): {
422
+ deleted: T | null;
423
+ alsoDeleted: T[];
424
+ };
425
+
426
+ /**
427
+ * Load sessions-index.json for a project
428
+ * Returns null if the file doesn't exist
429
+ */
430
+ declare const loadSessionsIndex: (projectName: string) => Effect.Effect<SessionsIndex | null, effect_Cause.UnknownException, never>;
431
+ /**
432
+ * Get display title from index entry
433
+ * Priority: customTitle > summary > firstPrompt (cleaned)
434
+ */
435
+ declare const getIndexEntryDisplayTitle: (entry: SessionIndexEntry) => string;
436
+ /**
437
+ * Sort index entries by modified time (newest first)
438
+ */
439
+ declare const sortIndexEntriesByModified: (entries: SessionIndexEntry[]) => SessionIndexEntry[];
440
+ /**
441
+ * Check if sessions-index.json exists for a project
442
+ */
443
+ declare const hasSessionsIndex: (projectName: string) => Effect.Effect<boolean, effect_Cause.UnknownException, never>;
444
+
347
445
  /**
348
446
  * Simple logger abstraction for Claude Sessions
349
447
  * Consumers can provide their own logger implementation
@@ -378,4 +476,4 @@ declare const getLogger: () => Logger;
378
476
  */
379
477
  declare const createLogger: (namespace: string) => Logger;
380
478
 
381
- export { AgentInfo, CompressSessionOptions, ConversationLine, FileChange, type Logger, Message, MessagePayload, MoveSessionResult, Project, SearchResult, SummarizeSessionOptions, SummaryInfo, TodoItem, analyzeSession, clearSessions, compressSession, createLogger, deleteLinkedTodos, deleteMessage, deleteOrphanAgents, deleteOrphanTodos, deleteSession, displayPathToFolderName, extractProjectKnowledge, extractTextContent, extractTitle, findLinkedAgents, findLinkedTodos, findOrphanAgents, findOrphanTodos, findProjectByWorkspacePath, folderNameToDisplayPath, folderNameToPath, getDisplayTitle, getLogger, getRealPathFromSession, getSessionFiles, getSessionsDir, getTodosDir, isContinuationSummary, isInvalidApiKeyMessage, listProjects, listSessions, loadAgentMessages, loadProjectTreeData, loadSessionTreeData, maskHomePath, moveSession, pathToFolderName, previewCleanup, readSession, renameSession, restoreMessage, searchSessions, sessionHasTodos, setLogger, sortProjects, splitSession, summarizeSession, updateSessionSummary };
479
+ export { AgentInfo, type ChainError, CompressSessionOptions, ConversationLine, FileChange, type Logger, Message, MessagePayload$1 as MessagePayload, MoveSessionResult, Project, ProjectTreeData, SearchResult, SessionIndexEntry, SessionSortOptions, SessionTodos, SessionsIndex, SummarizeSessionOptions, SummaryInfo, type ToolUseResultError, type ValidationResult, analyzeSession, clearSessions, compressSession, createLogger, deleteLinkedTodos, deleteMessage, deleteMessageWithChainRepair, deleteOrphanAgents, deleteOrphanTodos, deleteSession, displayPathToFolderName, extractProjectKnowledge, extractTextContent, extractTitle, findLinkedAgents, findLinkedTodos, findOrphanAgents, findOrphanTodos, findProjectByWorkspacePath, folderNameToDisplayPath, folderNameToPath, getDisplayTitle, getIndexEntryDisplayTitle, getLogger, getRealPathFromSession, getSessionFiles, getSessionSortTimestamp, getSessionsDir, getTodosDir, hasSessionsIndex, isContinuationSummary, isInvalidApiKeyMessage, listProjects, listSessions, loadAgentMessages, loadProjectTreeData, loadSessionTreeData, loadSessionsIndex, maskHomePath, moveSession, parseCommandMessage, parseJsonlLines, pathToFolderName, previewCleanup, readJsonlFile, readSession, renameSession, restoreMessage, searchSessions, sessionHasTodos, setLogger, sortIndexEntriesByModified, sortProjects, splitSession, summarizeSession, tryParseJsonLine, updateSessionSummary, validateChain, validateToolUseResult };