cursor-history 0.5.1 → 0.6.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.
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Configuration handling and validation for library API
3
+ *
4
+ * IMPORTANT: This is a library interface for direct import and use in TypeScript/JavaScript
5
+ * projects, NOT a network/REST API.
6
+ */
7
+ import type { LibraryConfig } from './types.js';
8
+ /**
9
+ * Merged configuration with all defaults applied
10
+ */
11
+ export interface ResolvedConfig {
12
+ dataPath: string;
13
+ workspace?: string;
14
+ limit: number;
15
+ offset: number;
16
+ context: number;
17
+ }
18
+ /**
19
+ * Validate configuration parameters
20
+ * @throws {InvalidConfigError} If any parameter is invalid
21
+ */
22
+ export declare function validateConfig(config?: LibraryConfig): void;
23
+ /**
24
+ * Merge user configuration with defaults
25
+ */
26
+ export declare function mergeWithDefaults(config?: LibraryConfig): ResolvedConfig;
27
+ /**
28
+ * Resolve database path with symlink handling
29
+ * @throws {DatabaseNotFoundError} If path does not exist
30
+ */
31
+ export declare function resolveDatabasePath(configPath?: string): string;
32
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIhD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,IAAI,CAsC3D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,cAAc,CAYxE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAW/D"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Configuration handling and validation for library API
3
+ *
4
+ * IMPORTANT: This is a library interface for direct import and use in TypeScript/JavaScript
5
+ * projects, NOT a network/REST API.
6
+ */
7
+ import { realpathSync } from 'node:fs';
8
+ import { resolve, normalize, isAbsolute } from 'node:path';
9
+ import { InvalidConfigError, DatabaseNotFoundError } from './errors.js';
10
+ import { getCursorDataPath } from '../lib/platform.js';
11
+ /**
12
+ * Validate configuration parameters
13
+ * @throws {InvalidConfigError} If any parameter is invalid
14
+ */
15
+ export function validateConfig(config) {
16
+ if (!config)
17
+ return;
18
+ // Validate limit
19
+ if (config.limit !== undefined) {
20
+ if (typeof config.limit !== 'number' || config.limit < 1 || !Number.isInteger(config.limit)) {
21
+ throw new InvalidConfigError('limit', config.limit, 'must be a positive integer greater than 0');
22
+ }
23
+ }
24
+ // Validate offset
25
+ if (config.offset !== undefined) {
26
+ if (typeof config.offset !== 'number' || config.offset < 0 || !Number.isInteger(config.offset)) {
27
+ throw new InvalidConfigError('offset', config.offset, 'must be a non-negative integer');
28
+ }
29
+ }
30
+ // Validate context
31
+ if (config.context !== undefined) {
32
+ if (typeof config.context !== 'number' || config.context < 0 || !Number.isInteger(config.context)) {
33
+ throw new InvalidConfigError('context', config.context, 'must be a non-negative integer');
34
+ }
35
+ }
36
+ // Validate workspace path
37
+ if (config.workspace !== undefined) {
38
+ if (typeof config.workspace !== 'string') {
39
+ throw new InvalidConfigError('workspace', config.workspace, 'must be a string');
40
+ }
41
+ if (!isAbsolute(config.workspace)) {
42
+ throw new InvalidConfigError('workspace', config.workspace, 'must be an absolute path');
43
+ }
44
+ }
45
+ // Validate dataPath
46
+ if (config.dataPath !== undefined && typeof config.dataPath !== 'string') {
47
+ throw new InvalidConfigError('dataPath', config.dataPath, 'must be a string');
48
+ }
49
+ }
50
+ /**
51
+ * Merge user configuration with defaults
52
+ */
53
+ export function mergeWithDefaults(config) {
54
+ validateConfig(config);
55
+ const dataPath = config?.dataPath ?? getCursorDataPath();
56
+ return {
57
+ dataPath,
58
+ workspace: config?.workspace,
59
+ limit: config?.limit ?? Number.MAX_SAFE_INTEGER,
60
+ offset: config?.offset ?? 0,
61
+ context: config?.context ?? 0,
62
+ };
63
+ }
64
+ /**
65
+ * Resolve database path with symlink handling
66
+ * @throws {DatabaseNotFoundError} If path does not exist
67
+ */
68
+ export function resolveDatabasePath(configPath) {
69
+ const basePath = configPath ?? getCursorDataPath();
70
+ const normalized = normalize(basePath);
71
+ const resolved = resolve(normalized);
72
+ try {
73
+ // Resolve symlinks and verify path exists
74
+ return realpathSync(resolved);
75
+ }
76
+ catch {
77
+ throw new DatabaseNotFoundError(resolved);
78
+ }
79
+ }
80
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAavD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,MAAsB;IACnD,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,iBAAiB;IACjB,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/B,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5F,MAAM,IAAI,kBAAkB,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AI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACzE,MAAM,IAAI,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;IAChF,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAsB;IACtD,cAAc,CAAC,MAAM,CAAC,CAAC;IAEvB,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,IAAI,iBAAiB,EAAE,CAAC;IAEzD,OAAO;QACL,QAAQ;QACR,SAAS,EAAE,MAAM,EAAE,SAAS;QAC5B,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,gBAAgB;QAC/C,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;QAC3B,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,CAAC;KAC9B,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAAmB;IACrD,MAAM,QAAQ,GAAG,UAAU,IAAI,iBAAiB,EAAE,CAAC;IACnD,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAErC,IAAI,CAAC;QACH,0CAA0C;QAC1C,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC"}
@@ -1,56 +1,54 @@
1
1
  /**
2
- * Error handling utilities and exit codes
2
+ * Custom error classes for library API
3
+ *
4
+ * IMPORTANT: This is a library interface for direct import and use in TypeScript/JavaScript
5
+ * projects, NOT a network/REST API.
3
6
  */
4
7
  /**
5
- * CLI exit codes following Unix conventions
8
+ * Thrown when database is locked by Cursor or another process.
9
+ *
10
+ * Recovery: Close Cursor IDE and retry, or implement custom retry logic.
6
11
  */
7
- export declare const ExitCode: {
8
- readonly SUCCESS: 0;
9
- readonly GENERAL_ERROR: 1;
10
- readonly USAGE_ERROR: 2;
11
- readonly NOT_FOUND: 3;
12
- readonly IO_ERROR: 4;
13
- };
14
- export type ExitCode = (typeof ExitCode)[keyof typeof ExitCode];
15
- /**
16
- * Custom error class for CLI errors with exit codes
17
- */
18
- export declare class CliError extends Error {
19
- readonly exitCode: ExitCode;
20
- constructor(message: string, exitCode?: ExitCode);
21
- }
22
- /**
23
- * Error for when no Cursor installation is found
24
- */
25
- export declare class CursorNotFoundError extends CliError {
26
- constructor(searchPath: string);
12
+ export declare class DatabaseLockedError extends Error {
13
+ name: "DatabaseLockedError";
14
+ /** Path to locked database file */
15
+ path: string;
16
+ constructor(path: string);
27
17
  }
28
18
  /**
29
- * Error for when no chat history exists
19
+ * Thrown when database file or directory does not exist.
20
+ *
21
+ * Recovery: Verify Cursor is installed, check dataPath configuration.
30
22
  */
31
- export declare class NoHistoryError extends CliError {
32
- constructor();
23
+ export declare class DatabaseNotFoundError extends Error {
24
+ name: "DatabaseNotFoundError";
25
+ /** Path that was not found */
26
+ path: string;
27
+ constructor(path: string);
33
28
  }
34
29
  /**
35
- * Error for invalid session index
36
- */
37
- export declare class SessionNotFoundError extends CliError {
38
- constructor(index: number, maxIndex: number);
30
+ * Thrown when configuration parameters are invalid.
31
+ *
32
+ * Recovery: Fix configuration values per LibraryConfig validation rules.
33
+ */
34
+ export declare class InvalidConfigError extends Error {
35
+ name: "InvalidConfigError";
36
+ /** Name of invalid config field */
37
+ field: string;
38
+ /** Invalid value provided */
39
+ value: unknown;
40
+ constructor(field: string, value: unknown, reason: string);
39
41
  }
40
42
  /**
41
- * Error for file already exists
43
+ * Type guard to check if an error is a DatabaseLockedError.
42
44
  */
43
- export declare class FileExistsError extends CliError {
44
- constructor(path: string);
45
- }
45
+ export declare function isDatabaseLockedError(error: unknown): error is DatabaseLockedError;
46
46
  /**
47
- * Error for search with no results
47
+ * Type guard to check if an error is a DatabaseNotFoundError.
48
48
  */
49
- export declare class NoSearchResultsError extends CliError {
50
- constructor(query: string);
51
- }
49
+ export declare function isDatabaseNotFoundError(error: unknown): error is DatabaseNotFoundError;
52
50
  /**
53
- * Handle an error and exit with appropriate code
51
+ * Type guard to check if an error is an InvalidConfigError.
54
52
  */
55
- export declare function handleError(error: unknown): never;
53
+ export declare function isInvalidConfigError(error: unknown): error is InvalidConfigError;
56
54
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;CAMX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAEhE;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAGf,QAAQ,EAAE,QAAQ;gBADlC,OAAO,EAAE,MAAM,EACC,QAAQ,GAAE,QAAiC;CAK9D;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,UAAU,EAAE,MAAM;CAS/B;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;;CAQ3C;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;gBACpC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CAQ5C;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,IAAI,EAAE,MAAM;CAIzB;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;gBACpC,KAAK,EAAE,MAAM;CAI1B;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAajD"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,IAAI,EAAG,qBAAqB,CAAU;IAEtC,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,EAAE,MAAM;CAOzB;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,IAAI,EAAG,uBAAuB,CAAU;IAExC,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;gBAED,IAAI,EAAE,MAAM;CAOzB;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,IAAI,EAAG,oBAAoB,CAAU;IAErC,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IAEd,6BAA6B;IAC7B,KAAK,EAAE,OAAO,CAAC;gBAEH,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;CAQ1D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,mBAAmB,CAElF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB,CAEtF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAEhF"}
@@ -1,90 +1,79 @@
1
1
  /**
2
- * Error handling utilities and exit codes
2
+ * Custom error classes for library API
3
+ *
4
+ * IMPORTANT: This is a library interface for direct import and use in TypeScript/JavaScript
5
+ * projects, NOT a network/REST API.
3
6
  */
4
7
  /**
5
- * CLI exit codes following Unix conventions
8
+ * Thrown when database is locked by Cursor or another process.
9
+ *
10
+ * Recovery: Close Cursor IDE and retry, or implement custom retry logic.
6
11
  */
7
- export const ExitCode = {
8
- SUCCESS: 0,
9
- GENERAL_ERROR: 1,
10
- USAGE_ERROR: 2, // Invalid arguments
11
- NOT_FOUND: 3, // Resource not found
12
- IO_ERROR: 4, // File/database access error
13
- };
14
- /**
15
- * Custom error class for CLI errors with exit codes
16
- */
17
- export class CliError extends Error {
18
- exitCode;
19
- constructor(message, exitCode = ExitCode.GENERAL_ERROR) {
20
- super(message);
21
- this.exitCode = exitCode;
22
- this.name = 'CliError';
23
- }
24
- }
25
- /**
26
- * Error for when no Cursor installation is found
27
- */
28
- export class CursorNotFoundError extends CliError {
29
- constructor(searchPath) {
30
- super(`Cursor data not found at: ${searchPath}\n` +
31
- 'Make sure Cursor is installed and has been used at least once.\n' +
32
- 'You can specify a custom path with --data-path or CURSOR_DATA_PATH env var.', ExitCode.NOT_FOUND);
33
- this.name = 'CursorNotFoundError';
12
+ export class DatabaseLockedError extends Error {
13
+ name = 'DatabaseLockedError';
14
+ /** Path to locked database file */
15
+ path;
16
+ constructor(path) {
17
+ super(`Database is locked: ${path}. Close Cursor or retry later.`);
18
+ this.path = path;
19
+ if (Error.captureStackTrace) {
20
+ Error.captureStackTrace(this, DatabaseLockedError);
21
+ }
34
22
  }
35
23
  }
36
24
  /**
37
- * Error for when no chat history exists
25
+ * Thrown when database file or directory does not exist.
26
+ *
27
+ * Recovery: Verify Cursor is installed, check dataPath configuration.
38
28
  */
39
- export class NoHistoryError extends CliError {
40
- constructor() {
41
- super('No chat history found.\n' + 'Start a conversation in Cursor to create chat history.', ExitCode.NOT_FOUND);
42
- this.name = 'NoHistoryError';
29
+ export class DatabaseNotFoundError extends Error {
30
+ name = 'DatabaseNotFoundError';
31
+ /** Path that was not found */
32
+ path;
33
+ constructor(path) {
34
+ super(`Database not found: ${path}. Check dataPath configuration.`);
35
+ this.path = path;
36
+ if (Error.captureStackTrace) {
37
+ Error.captureStackTrace(this, DatabaseNotFoundError);
38
+ }
43
39
  }
44
40
  }
45
41
  /**
46
- * Error for invalid session index
42
+ * Thrown when configuration parameters are invalid.
43
+ *
44
+ * Recovery: Fix configuration values per LibraryConfig validation rules.
47
45
  */
48
- export class SessionNotFoundError extends CliError {
49
- constructor(index, maxIndex) {
50
- const message = maxIndex > 0
51
- ? `Session #${index} not found. Valid range: 1-${maxIndex}`
52
- : 'No sessions found.';
53
- super(message, ExitCode.NOT_FOUND);
54
- this.name = 'SessionNotFoundError';
46
+ export class InvalidConfigError extends Error {
47
+ name = 'InvalidConfigError';
48
+ /** Name of invalid config field */
49
+ field;
50
+ /** Invalid value provided */
51
+ value;
52
+ constructor(field, value, reason) {
53
+ super(`Invalid config.${field}: ${reason} (got: ${JSON.stringify(value)})`);
54
+ this.field = field;
55
+ this.value = value;
56
+ if (Error.captureStackTrace) {
57
+ Error.captureStackTrace(this, InvalidConfigError);
58
+ }
55
59
  }
56
60
  }
57
61
  /**
58
- * Error for file already exists
62
+ * Type guard to check if an error is a DatabaseLockedError.
59
63
  */
60
- export class FileExistsError extends CliError {
61
- constructor(path) {
62
- super(`File already exists: ${path}\nUse --force to overwrite.`, ExitCode.IO_ERROR);
63
- this.name = 'FileExistsError';
64
- }
64
+ export function isDatabaseLockedError(error) {
65
+ return error instanceof DatabaseLockedError;
65
66
  }
66
67
  /**
67
- * Error for search with no results
68
+ * Type guard to check if an error is a DatabaseNotFoundError.
68
69
  */
69
- export class NoSearchResultsError extends CliError {
70
- constructor(query) {
71
- super(`No results found for: "${query}"`, ExitCode.NOT_FOUND);
72
- this.name = 'NoSearchResultsError';
73
- }
70
+ export function isDatabaseNotFoundError(error) {
71
+ return error instanceof DatabaseNotFoundError;
74
72
  }
75
73
  /**
76
- * Handle an error and exit with appropriate code
74
+ * Type guard to check if an error is an InvalidConfigError.
77
75
  */
78
- export function handleError(error) {
79
- if (error instanceof CliError) {
80
- console.error(error.message);
81
- process.exit(error.exitCode);
82
- }
83
- if (error instanceof Error) {
84
- console.error(`Error: ${error.message}`);
85
- process.exit(ExitCode.GENERAL_ERROR);
86
- }
87
- console.error('An unexpected error occurred');
88
- process.exit(ExitCode.GENERAL_ERROR);
76
+ export function isInvalidConfigError(error) {
77
+ return error instanceof InvalidConfigError;
89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U,qBAAqB,CAAC,KAAc;IAClD,OAAO,KAAK,YAAY,mBAAmB,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,OAAO,KAAK,YAAY,qBAAqB,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,YAAY,kBAAkB,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,142 @@
1
+ /**
2
+ * cursor-history Library API
3
+ *
4
+ * IMPORTANT: This is a library interface for direct import and use in TypeScript/JavaScript
5
+ * projects, NOT a network/REST API. Functions are imported directly:
6
+ * `import { listSessions, getSession, searchSessions } from 'cursor-history'`
7
+ */
8
+ export type { Session, Message, ToolCall, SearchResult, LibraryConfig, PaginatedResult, } from './types.js';
9
+ export { DatabaseLockedError, DatabaseNotFoundError, InvalidConfigError, isDatabaseLockedError, isDatabaseNotFoundError, isInvalidConfigError, } from './errors.js';
10
+ export { getDefaultDataPath } from './utils.js';
11
+ import type { LibraryConfig, PaginatedResult, Session, SearchResult } from './types.js';
12
+ /**
13
+ * List all chat sessions, optionally filtered and paginated.
14
+ *
15
+ * @param config - Optional configuration (dataPath, workspace filter, pagination)
16
+ * @returns Paginated result with sessions and metadata
17
+ * @throws {DatabaseLockedError} If database is locked by Cursor
18
+ * @throws {DatabaseNotFoundError} If database path does not exist
19
+ * @throws {InvalidConfigError} If config parameters are invalid
20
+ *
21
+ * @example
22
+ * // List all sessions
23
+ * const result = listSessions();
24
+ * console.log(result.data); // Session[]
25
+ *
26
+ * @example
27
+ * // List sessions with pagination
28
+ * const page1 = listSessions({ limit: 10, offset: 0 });
29
+ * const page2 = listSessions({ limit: 10, offset: 10 });
30
+ *
31
+ * @example
32
+ * // List sessions for specific workspace
33
+ * const result = listSessions({ workspace: '/path/to/project' });
34
+ */
35
+ export declare function listSessions(config?: LibraryConfig): PaginatedResult<Session>;
36
+ /**
37
+ * Get a specific session by index.
38
+ *
39
+ * @param index - Zero-based session index (from listSessions result)
40
+ * @param config - Optional configuration (dataPath)
41
+ * @returns Complete session with all messages
42
+ * @throws {DatabaseLockedError} If database is locked by Cursor
43
+ * @throws {DatabaseNotFoundError} If database path does not exist
44
+ * @throws {InvalidConfigError} If index is out of bounds
45
+ *
46
+ * @example
47
+ * const session = getSession(0);
48
+ * console.log(session.messages); // Message[]
49
+ *
50
+ * @example
51
+ * // Get session from custom data path
52
+ * const session = getSession(5, { dataPath: '/custom/cursor/data' });
53
+ */
54
+ export declare function getSession(index: number, config?: LibraryConfig): Session;
55
+ /**
56
+ * Search across all sessions for matching content.
57
+ *
58
+ * @param query - Search query string (case-insensitive substring match)
59
+ * @param config - Optional configuration (dataPath, workspace filter, context lines)
60
+ * @returns Array of search results with context
61
+ * @throws {DatabaseLockedError} If database is locked by Cursor
62
+ * @throws {DatabaseNotFoundError} If database path does not exist
63
+ *
64
+ * @example
65
+ * // Basic search
66
+ * const results = searchSessions('authentication');
67
+ *
68
+ * @example
69
+ * // Search with context lines
70
+ * const results = searchSessions('error', { context: 2 });
71
+ * results.forEach(r => {
72
+ * console.log(r.contextBefore); // 2 lines before match
73
+ * console.log(r.match); // matched line
74
+ * console.log(r.contextAfter); // 2 lines after match
75
+ * });
76
+ *
77
+ * @example
78
+ * // Search within specific workspace
79
+ * const results = searchSessions('bug', { workspace: '/path/to/project' });
80
+ */
81
+ export declare function searchSessions(query: string, config?: LibraryConfig): SearchResult[];
82
+ /**
83
+ * Export a session to JSON format.
84
+ *
85
+ * @param index - Zero-based session index (from listSessions result)
86
+ * @param config - Optional configuration (dataPath)
87
+ * @returns JSON string representation of session
88
+ * @throws {DatabaseLockedError} If database is locked by Cursor
89
+ * @throws {DatabaseNotFoundError} If database path does not exist
90
+ * @throws {InvalidConfigError} If index is out of bounds
91
+ *
92
+ * @example
93
+ * const json = exportSessionToJson(0);
94
+ * fs.writeFileSync('session.json', json);
95
+ */
96
+ export declare function exportSessionToJson(index: number, config?: LibraryConfig): string;
97
+ /**
98
+ * Export a session to Markdown format.
99
+ *
100
+ * @param index - Zero-based session index (from listSessions result)
101
+ * @param config - Optional configuration (dataPath)
102
+ * @returns Markdown formatted string
103
+ * @throws {DatabaseLockedError} If database is locked by Cursor
104
+ * @throws {DatabaseNotFoundError} If database path does not exist
105
+ * @throws {InvalidConfigError} If index is out of bounds
106
+ *
107
+ * @example
108
+ * const markdown = exportSessionToMarkdown(0);
109
+ * fs.writeFileSync('session.md', markdown);
110
+ */
111
+ export declare function exportSessionToMarkdown(index: number, config?: LibraryConfig): string;
112
+ /**
113
+ * Export all sessions to JSON format.
114
+ *
115
+ * @param config - Optional configuration (dataPath, workspace filter)
116
+ * @returns JSON string with array of all sessions
117
+ * @throws {DatabaseLockedError} If database is locked by Cursor
118
+ * @throws {DatabaseNotFoundError} If database path does not exist
119
+ *
120
+ * @example
121
+ * const json = exportAllSessionsToJson();
122
+ * fs.writeFileSync('all-sessions.json', json);
123
+ *
124
+ * @example
125
+ * // Export sessions from specific workspace
126
+ * const json = exportAllSessionsToJson({ workspace: '/path/to/project' });
127
+ */
128
+ export declare function exportAllSessionsToJson(config?: LibraryConfig): string;
129
+ /**
130
+ * Export all sessions to Markdown format.
131
+ *
132
+ * @param config - Optional configuration (dataPath, workspace filter)
133
+ * @returns Markdown formatted string with all sessions
134
+ * @throws {DatabaseLockedError} If database is locked by Cursor
135
+ * @throws {DatabaseNotFoundError} If database path does not exist
136
+ *
137
+ * @example
138
+ * const markdown = exportAllSessionsToMarkdown();
139
+ * fs.writeFileSync('all-sessions.md', markdown);
140
+ */
141
+ export declare function exportAllSessionsToMarkdown(config?: LibraryConfig): string;
142
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EACV,OAAO,EACP,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,aAAa,EAC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