@claude-sessions/core 0.3.7 → 0.4.1

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 { M as MessagePayload$1, a as Message, P as Project, 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-DZsLFIFK.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-DZsLFIFK.js';
3
3
  import * as effect_Cause from 'effect/Cause';
4
4
  import { Effect } from 'effect';
5
5
 
@@ -62,13 +62,22 @@ declare const findProjectByWorkspacePath: (workspacePath: string, projectNames:
62
62
  * Utility functions for message processing
63
63
  */
64
64
 
65
- declare const extractTextContent: (message: MessagePayload | undefined) => string;
65
+ declare const extractTextContent: (message: MessagePayload$1 | undefined) => string;
66
+ /**
67
+ * Parse command message content (e.g., slash commands like /commit)
68
+ * Returns the command name and message extracted from XML tags
69
+ */
70
+ declare const parseCommandMessage: (content?: string) => {
71
+ name: string;
72
+ message: string;
73
+ };
66
74
  declare const extractTitle: (text: string) => string;
67
75
  declare const isInvalidApiKeyMessage: (msg: Message) => boolean;
68
76
  declare const isContinuationSummary: (msg: Message) => boolean;
69
77
  /**
70
78
  * Get display title with fallback logic
71
79
  * Priority: customTitle > currentSummary (truncated) > title > fallback
80
+ * Also handles slash command format in title
72
81
  */
73
82
  declare const getDisplayTitle: (customTitle: string | undefined, currentSummary: string | undefined, title: string | undefined, maxLength?: number, fallback?: string) => string;
74
83
  /**
@@ -87,6 +96,14 @@ declare const sortProjects: (projects: Project[], options?: {
87
96
  homeDir?: string;
88
97
  filterEmpty?: boolean;
89
98
  }) => Project[];
99
+ /**
100
+ * Get sort timestamp for session (Unix timestamp ms)
101
+ * Priority: summaries[0].timestamp > createdAt > 0
102
+ */
103
+ declare const getSessionSortTimestamp: (session: {
104
+ summaries?: SummaryInfo[];
105
+ createdAt?: string;
106
+ }) => number;
90
107
 
91
108
  declare const findLinkedAgents: (projectName: string, sessionId: string) => Effect.Effect<string[], effect_Cause.UnknownException, never>;
92
109
  declare const findOrphanAgents: (projectName: string) => Effect.Effect<{
@@ -106,15 +123,7 @@ declare const deleteOrphanAgents: (projectName: string) => Effect.Effect<{
106
123
  declare const loadAgentMessages: (projectName: string, _sessionId: string, // Reserved for future validation
107
124
  agentId: string) => Effect.Effect<Message[], effect_Cause.UnknownException, never>;
108
125
 
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>;
126
+ declare const findLinkedTodos: (sessionId: string, agentIds?: string[]) => Effect.Effect<SessionTodos | undefined, effect_Cause.UnknownException, never>;
118
127
  declare const sessionHasTodos: (sessionId: string, agentIds?: string[]) => Effect.Effect<boolean, effect_Cause.UnknownException, never>;
119
128
  declare const deleteLinkedTodos: (sessionId: string, agentIds: string[]) => Effect.Effect<{
120
129
  deletedCount: number;
@@ -126,16 +135,22 @@ declare const deleteOrphanTodos: () => Effect.Effect<{
126
135
  }, effect_Cause.UnknownException, never>;
127
136
 
128
137
  declare const listProjects: Effect.Effect<Project[], effect_Cause.UnknownException, never>;
138
+
139
+ declare const updateSessionSummary: (projectName: string, sessionId: string, newSummary: string) => Effect.Effect<{
140
+ success: boolean;
141
+ }, effect_Cause.UnknownException, never>;
129
142
  declare const listSessions: (projectName: string) => Effect.Effect<{
130
143
  id: string;
131
144
  projectName: string;
132
145
  title: string;
146
+ customTitle: string | undefined;
147
+ currentSummary: string | undefined;
133
148
  messageCount: number;
134
149
  createdAt: string | undefined;
135
150
  updatedAt: string | undefined;
136
151
  }[], effect_Cause.UnknownException, never>;
137
152
  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<{
153
+ declare const deleteMessage: (projectName: string, sessionId: string, messageUuid: string, targetType?: "file-history-snapshot" | "summary") => Effect.Effect<{
139
154
  success: boolean;
140
155
  error: string;
141
156
  deletedMessage?: undefined;
@@ -169,12 +184,41 @@ declare const renameSession: (projectName: string, sessionId: string, newTitle:
169
184
  success: true;
170
185
  error?: undefined;
171
186
  }, effect_Cause.UnknownException, never>;
172
- declare const getSessionFiles: (projectName: string, sessionId: string) => Effect.Effect<{
173
- sessionId: string;
187
+ declare const moveSession: (sourceProject: string, sessionId: string, targetProject: string) => Effect.Effect<MoveSessionResult, Error>;
188
+ declare const splitSession: (projectName: string, sessionId: string, splitAtMessageUuid: string) => Effect.Effect<{
189
+ success: false;
190
+ error: string;
191
+ newSessionId?: undefined;
192
+ newSessionPath?: undefined;
193
+ movedMessageCount?: undefined;
194
+ duplicatedSummary?: undefined;
195
+ } | {
196
+ success: true;
197
+ newSessionId: `${string}-${string}-${string}-${string}-${string}`;
198
+ newSessionPath: string;
199
+ movedMessageCount: number;
200
+ duplicatedSummary: boolean;
201
+ error?: undefined;
202
+ }, effect_Cause.UnknownException, never>;
203
+
204
+ declare const loadSessionTreeData: (projectName: string, sessionId: string) => Effect.Effect<{
205
+ id: string;
174
206
  projectName: string;
175
- files: FileChange[];
176
- totalChanges: number;
207
+ title: string;
208
+ customTitle: string | undefined;
209
+ currentSummary: string;
210
+ messageCount: number;
211
+ createdAt: string;
212
+ updatedAt: string;
213
+ fileMtime: number | undefined;
214
+ sortTimestamp: number;
215
+ summaries: SummaryInfo[];
216
+ agents: AgentInfo[];
217
+ todos: SessionTodos | undefined;
218
+ lastCompactBoundaryUuid: string | undefined;
177
219
  }, effect_Cause.UnknownException, never>;
220
+ declare const loadProjectTreeData: (projectName: string, sortOptions?: SessionSortOptions) => Effect.Effect<ProjectTreeData | null, effect_Cause.UnknownException, never>;
221
+
178
222
  declare const analyzeSession: (projectName: string, sessionId: string) => Effect.Effect<{
179
223
  sessionId: string;
180
224
  projectName: string;
@@ -203,28 +247,46 @@ declare const analyzeSession: (projectName: string, sessionId: string) => Effect
203
247
  messageUuid?: string;
204
248
  }[];
205
249
  }, 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
- } | {
250
+ declare const compressSession: (projectName: string, sessionId: string, options?: CompressSessionOptions) => Effect.Effect<{
215
251
  success: true;
216
- newSessionId: `${string}-${string}-${string}-${string}-${string}`;
217
- newSessionPath: string;
218
- movedMessageCount: number;
219
- duplicatedSummary: boolean;
220
- error?: undefined;
252
+ originalSize: number;
253
+ compressedSize: number;
254
+ removedSnapshots: number;
255
+ truncatedOutputs: number;
256
+ }, effect_Cause.UnknownException, never>;
257
+ declare const extractProjectKnowledge: (projectName: string, sessionIds?: string[]) => Effect.Effect<{
258
+ projectName: string;
259
+ patterns: never[];
260
+ hotFiles: {
261
+ path: string;
262
+ modifyCount: number;
263
+ lastModified: string | undefined;
264
+ }[];
265
+ workflows: {
266
+ sequence: string[];
267
+ count: number;
268
+ }[];
269
+ decisions: {
270
+ context: string;
271
+ decision: string;
272
+ sessionId: string;
273
+ }[];
274
+ }, effect_Cause.UnknownException, never>;
275
+ declare const summarizeSession: (projectName: string, sessionId: string, options?: SummarizeSessionOptions) => Effect.Effect<{
276
+ sessionId: string;
277
+ projectName: string;
278
+ lines: ConversationLine[];
279
+ formatted: string;
221
280
  }, effect_Cause.UnknownException, never>;
281
+
222
282
  declare const previewCleanup: (projectName?: string) => Effect.Effect<{
223
283
  project: string;
224
284
  emptySessions: {
225
285
  id: string;
226
286
  projectName: string;
227
287
  title: string;
288
+ customTitle: string | undefined;
289
+ currentSummary: string | undefined;
228
290
  messageCount: number;
229
291
  createdAt: string | undefined;
230
292
  updatedAt: string | undefined;
@@ -233,6 +295,8 @@ declare const previewCleanup: (projectName?: string) => Effect.Effect<{
233
295
  id: string;
234
296
  projectName: string;
235
297
  title: string;
298
+ customTitle: string | undefined;
299
+ currentSummary: string | undefined;
236
300
  messageCount: number;
237
301
  createdAt: string | undefined;
238
302
  updatedAt: string | undefined;
@@ -255,95 +319,107 @@ declare const clearSessions: (options: {
255
319
  deletedOrphanAgentCount: number;
256
320
  deletedOrphanTodoCount: number;
257
321
  }, effect_Cause.UnknownException, never>;
322
+
258
323
  declare const searchSessions: (query: string, options?: {
259
324
  projectName?: string;
260
325
  searchContent?: boolean;
261
326
  }) => Effect.Effect<SearchResult[], effect_Cause.UnknownException, never>;
262
- declare const loadSessionTreeData: (projectName: string, sessionId: string) => Effect.Effect<{
263
- id: string;
264
- projectName: string;
265
- 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<{
327
+
328
+ declare const getSessionFiles: (projectName: string, sessionId: string) => Effect.Effect<{
341
329
  sessionId: string;
342
330
  projectName: string;
343
- lines: ConversationLine[];
344
- formatted: string;
331
+ files: FileChange[];
332
+ totalChanges: number;
345
333
  }, effect_Cause.UnknownException, never>;
346
334
 
335
+ /**
336
+ * Session message chain validation utilities
337
+ *
338
+ * Validates:
339
+ * 1. parentUuid chain integrity (skip file-history-snapshot)
340
+ * 2. tool_use_id / tool_result matching
341
+ */
342
+ interface ChainError {
343
+ type: 'broken_chain' | 'orphan_parent';
344
+ uuid: string;
345
+ line: number;
346
+ parentUuid: string | null;
347
+ expectedParent?: string;
348
+ }
349
+ interface ToolUseResultError {
350
+ type: 'orphan_tool_result';
351
+ uuid: string;
352
+ line: number;
353
+ toolUseId: string;
354
+ }
355
+ interface ValidationResult {
356
+ valid: boolean;
357
+ errors: (ChainError | ToolUseResultError)[];
358
+ }
359
+ interface MessagePayload {
360
+ role?: string;
361
+ content?: unknown;
362
+ }
363
+ interface GenericMessage {
364
+ type?: string;
365
+ uuid?: string;
366
+ parentUuid?: string | null;
367
+ message?: MessagePayload;
368
+ messageId?: string;
369
+ }
370
+ /**
371
+ * Validate parentUuid chain for messages
372
+ *
373
+ * Rules:
374
+ * - Skip file-history-snapshot type (has no uuid, uses messageId instead)
375
+ * - Skip messages without uuid
376
+ * - First message can have null parentUuid
377
+ * - Subsequent messages must have valid parentUuid pointing to existing uuid
378
+ */
379
+ declare function validateChain(messages: readonly GenericMessage[]): ValidationResult;
380
+ /**
381
+ * Validate tool_use_id / tool_result matching
382
+ *
383
+ * Rules:
384
+ * - All tool_result blocks must have a corresponding tool_use block in the session
385
+ * - tool_use blocks are collected from all messages (not just previous)
386
+ */
387
+ declare function validateToolUseResult(messages: readonly GenericMessage[]): ValidationResult;
388
+ /**
389
+ * Delete a message and repair the parentUuid chain
390
+ *
391
+ * This is a pure function for client-side use (without file I/O)
392
+ * Server-side deleteMessage in crud.ts uses similar logic with file operations
393
+ *
394
+ * @param messages - Array of messages (will be mutated)
395
+ * @param targetId - uuid, messageId, or leafUuid of message to delete
396
+ * @param targetType - Optional: 'file-history-snapshot' or 'summary' to disambiguate collisions
397
+ * @returns Object with deleted message and messages to also delete (orphan tool_results)
398
+ */
399
+ declare function deleteMessageWithChainRepair<T extends GenericMessage>(messages: T[], targetId: string, targetType?: 'file-history-snapshot' | 'summary'): {
400
+ deleted: T | null;
401
+ alsoDeleted: T[];
402
+ };
403
+
404
+ /**
405
+ * Load sessions-index.json for a project
406
+ * Returns null if the file doesn't exist
407
+ */
408
+ declare const loadSessionsIndex: (projectName: string) => Effect.Effect<SessionsIndex | null, effect_Cause.UnknownException, never>;
409
+ /**
410
+ * Get display title from index entry
411
+ * Priority: customTitle > summary > firstPrompt (cleaned)
412
+ */
413
+ declare const getIndexEntryDisplayTitle: (entry: SessionIndexEntry) => string;
414
+ /**
415
+ * Sort index entries by modified time (newest first)
416
+ */
417
+ declare const sortIndexEntriesByModified: (entries: SessionIndexEntry[]) => SessionIndexEntry[];
418
+ /**
419
+ * Check if sessions-index.json exists for a project
420
+ */
421
+ declare const hasSessionsIndex: (projectName: string) => Effect.Effect<boolean, effect_Cause.UnknownException, never>;
422
+
347
423
  /**
348
424
  * Simple logger abstraction for Claude Sessions
349
425
  * Consumers can provide their own logger implementation
@@ -378,4 +454,4 @@ declare const getLogger: () => Logger;
378
454
  */
379
455
  declare const createLogger: (namespace: string) => Logger;
380
456
 
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 };
457
+ 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, pathToFolderName, previewCleanup, readSession, renameSession, restoreMessage, searchSessions, sessionHasTodos, setLogger, sortIndexEntriesByModified, sortProjects, splitSession, summarizeSession, updateSessionSummary, validateChain, validateToolUseResult };