claude-code-history 0.2.2

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.
Files changed (94) hide show
  1. package/README.md +400 -0
  2. package/dist/cli/commands/export.d.ts +11 -0
  3. package/dist/cli/commands/export.d.ts.map +1 -0
  4. package/dist/cli/commands/export.js +119 -0
  5. package/dist/cli/commands/export.js.map +1 -0
  6. package/dist/cli/commands/list.d.ts +11 -0
  7. package/dist/cli/commands/list.d.ts.map +1 -0
  8. package/dist/cli/commands/list.js +79 -0
  9. package/dist/cli/commands/list.js.map +1 -0
  10. package/dist/cli/commands/migrate.d.ts +11 -0
  11. package/dist/cli/commands/migrate.d.ts.map +1 -0
  12. package/dist/cli/commands/migrate.js +144 -0
  13. package/dist/cli/commands/migrate.js.map +1 -0
  14. package/dist/cli/commands/search.d.ts +11 -0
  15. package/dist/cli/commands/search.d.ts.map +1 -0
  16. package/dist/cli/commands/search.js +94 -0
  17. package/dist/cli/commands/search.js.map +1 -0
  18. package/dist/cli/commands/view.d.ts +11 -0
  19. package/dist/cli/commands/view.d.ts.map +1 -0
  20. package/dist/cli/commands/view.js +67 -0
  21. package/dist/cli/commands/view.js.map +1 -0
  22. package/dist/cli/formatters/pager.d.ts +25 -0
  23. package/dist/cli/formatters/pager.d.ts.map +1 -0
  24. package/dist/cli/formatters/pager.js +119 -0
  25. package/dist/cli/formatters/pager.js.map +1 -0
  26. package/dist/cli/formatters/search.d.ts +38 -0
  27. package/dist/cli/formatters/search.d.ts.map +1 -0
  28. package/dist/cli/formatters/search.js +119 -0
  29. package/dist/cli/formatters/search.js.map +1 -0
  30. package/dist/cli/formatters/session.d.ts +24 -0
  31. package/dist/cli/formatters/session.d.ts.map +1 -0
  32. package/dist/cli/formatters/session.js +247 -0
  33. package/dist/cli/formatters/session.js.map +1 -0
  34. package/dist/cli/formatters/table.d.ts +25 -0
  35. package/dist/cli/formatters/table.d.ts.map +1 -0
  36. package/dist/cli/formatters/table.js +126 -0
  37. package/dist/cli/formatters/table.js.map +1 -0
  38. package/dist/cli/index.d.ts +14 -0
  39. package/dist/cli/index.d.ts.map +1 -0
  40. package/dist/cli/index.js +50 -0
  41. package/dist/cli/index.js.map +1 -0
  42. package/dist/cli/utils/config.d.ts +62 -0
  43. package/dist/cli/utils/config.d.ts.map +1 -0
  44. package/dist/cli/utils/config.js +65 -0
  45. package/dist/cli/utils/config.js.map +1 -0
  46. package/dist/cli/utils/errors.d.ts +86 -0
  47. package/dist/cli/utils/errors.d.ts.map +1 -0
  48. package/dist/cli/utils/errors.js +129 -0
  49. package/dist/cli/utils/errors.js.map +1 -0
  50. package/dist/cli/utils/output.d.ts +74 -0
  51. package/dist/cli/utils/output.d.ts.map +1 -0
  52. package/dist/cli/utils/output.js +113 -0
  53. package/dist/cli/utils/output.js.map +1 -0
  54. package/dist/lib/config.d.ts +44 -0
  55. package/dist/lib/config.d.ts.map +1 -0
  56. package/dist/lib/config.js +60 -0
  57. package/dist/lib/config.js.map +1 -0
  58. package/dist/lib/errors.d.ts +40 -0
  59. package/dist/lib/errors.d.ts.map +1 -0
  60. package/dist/lib/errors.js +61 -0
  61. package/dist/lib/errors.js.map +1 -0
  62. package/dist/lib/export.d.ts +70 -0
  63. package/dist/lib/export.d.ts.map +1 -0
  64. package/dist/lib/export.js +241 -0
  65. package/dist/lib/export.js.map +1 -0
  66. package/dist/lib/index.d.ts +16 -0
  67. package/dist/lib/index.d.ts.map +1 -0
  68. package/dist/lib/index.js +33 -0
  69. package/dist/lib/index.js.map +1 -0
  70. package/dist/lib/migrate.d.ts +50 -0
  71. package/dist/lib/migrate.d.ts.map +1 -0
  72. package/dist/lib/migrate.js +274 -0
  73. package/dist/lib/migrate.js.map +1 -0
  74. package/dist/lib/parser.d.ts +67 -0
  75. package/dist/lib/parser.d.ts.map +1 -0
  76. package/dist/lib/parser.js +321 -0
  77. package/dist/lib/parser.js.map +1 -0
  78. package/dist/lib/platform.d.ts +51 -0
  79. package/dist/lib/platform.d.ts.map +1 -0
  80. package/dist/lib/platform.js +94 -0
  81. package/dist/lib/platform.js.map +1 -0
  82. package/dist/lib/search.d.ts +39 -0
  83. package/dist/lib/search.d.ts.map +1 -0
  84. package/dist/lib/search.js +217 -0
  85. package/dist/lib/search.js.map +1 -0
  86. package/dist/lib/session.d.ts +59 -0
  87. package/dist/lib/session.d.ts.map +1 -0
  88. package/dist/lib/session.js +326 -0
  89. package/dist/lib/session.js.map +1 -0
  90. package/dist/lib/types.d.ts +280 -0
  91. package/dist/lib/types.d.ts.map +1 -0
  92. package/dist/lib/types.js +7 -0
  93. package/dist/lib/types.js.map +1 -0
  94. package/package.json +65 -0
@@ -0,0 +1,62 @@
1
+ /**
2
+ * CLI Configuration utilities
3
+ *
4
+ * Handles global options, environment variables, and configuration resolution.
5
+ */
6
+ import { LibraryConfig } from '../../lib/index.js';
7
+ /**
8
+ * Environment variable names used by the CLI
9
+ */
10
+ export declare const ENV_VARS: {
11
+ readonly DATA_PATH: "CCH_DATA_PATH";
12
+ readonly NO_COLOR: "NO_COLOR";
13
+ readonly PAGER: "PAGER";
14
+ };
15
+ /**
16
+ * Global CLI options available to all commands
17
+ */
18
+ export interface GlobalOptions {
19
+ /** Custom Claude Code data directory */
20
+ dataPath?: string;
21
+ /** Output in JSON format instead of human-readable */
22
+ json: boolean;
23
+ /** Bypass pagination, output full content */
24
+ full: boolean;
25
+ }
26
+ /**
27
+ * Resolved configuration combining global options, env vars, and defaults
28
+ */
29
+ export interface ResolvedCliConfig {
30
+ dataPath: string;
31
+ outputFormat: 'human' | 'json';
32
+ paginate: boolean;
33
+ }
34
+ /**
35
+ * Resolve CLI configuration from global options, environment variables, and defaults.
36
+ *
37
+ * Priority order (highest to lowest):
38
+ * 1. Command-line option (--data-path)
39
+ * 2. Environment variable (CCH_DATA_PATH)
40
+ * 3. Platform default (~/.claude/projects/)
41
+ *
42
+ * @param opts - Global options from command line
43
+ * @returns Resolved configuration
44
+ */
45
+ export declare function resolveConfig(opts: GlobalOptions): ResolvedCliConfig;
46
+ /**
47
+ * Convert resolved CLI config to LibraryConfig for lib layer calls
48
+ *
49
+ * @param config - Resolved CLI configuration
50
+ * @param overrides - Optional overrides for specific lib calls
51
+ * @returns LibraryConfig compatible with lib layer functions
52
+ */
53
+ export declare function toLibraryConfig(config: ResolvedCliConfig, overrides?: Partial<LibraryConfig>): LibraryConfig;
54
+ /**
55
+ * Parse session reference from user input.
56
+ * Accepts: numeric index (0, 1, 2...) or UUID string (partial or full)
57
+ *
58
+ * @param input - User-provided session identifier
59
+ * @returns Numeric index if valid number >= 0, otherwise the string (treated as UUID)
60
+ */
61
+ export declare function parseSessionRef(input: string): number | string;
62
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAsB,MAAM,oBAAoB,CAAC;AAEvE;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;CAIX,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,IAAI,EAAE,OAAO,CAAC;IACd,6CAA6C;IAC7C,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,OAAO,GAAG,MAAM,CAAC;IAC/B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,iBAAiB,CASpE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,iBAAiB,EACzB,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GACjC,aAAa,CAKf;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAY9D"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * CLI Configuration utilities
3
+ *
4
+ * Handles global options, environment variables, and configuration resolution.
5
+ */
6
+ import { getDefaultDataPath } from '../../lib/index.js';
7
+ /**
8
+ * Environment variable names used by the CLI
9
+ */
10
+ export const ENV_VARS = {
11
+ DATA_PATH: 'CCH_DATA_PATH',
12
+ NO_COLOR: 'NO_COLOR',
13
+ PAGER: 'PAGER',
14
+ };
15
+ /**
16
+ * Resolve CLI configuration from global options, environment variables, and defaults.
17
+ *
18
+ * Priority order (highest to lowest):
19
+ * 1. Command-line option (--data-path)
20
+ * 2. Environment variable (CCH_DATA_PATH)
21
+ * 3. Platform default (~/.claude/projects/)
22
+ *
23
+ * @param opts - Global options from command line
24
+ * @returns Resolved configuration
25
+ */
26
+ export function resolveConfig(opts) {
27
+ const dataPath = opts.dataPath ?? process.env[ENV_VARS.DATA_PATH] ?? getDefaultDataPath();
28
+ return {
29
+ dataPath,
30
+ outputFormat: opts.json ? 'json' : 'human',
31
+ paginate: !opts.full,
32
+ };
33
+ }
34
+ /**
35
+ * Convert resolved CLI config to LibraryConfig for lib layer calls
36
+ *
37
+ * @param config - Resolved CLI configuration
38
+ * @param overrides - Optional overrides for specific lib calls
39
+ * @returns LibraryConfig compatible with lib layer functions
40
+ */
41
+ export function toLibraryConfig(config, overrides) {
42
+ return {
43
+ dataPath: config.dataPath,
44
+ ...overrides,
45
+ };
46
+ }
47
+ /**
48
+ * Parse session reference from user input.
49
+ * Accepts: numeric index (0, 1, 2...) or UUID string (partial or full)
50
+ *
51
+ * @param input - User-provided session identifier
52
+ * @returns Numeric index if valid number >= 0, otherwise the string (treated as UUID)
53
+ */
54
+ export function parseSessionRef(input) {
55
+ const trimmed = input.trim();
56
+ const numericIndex = parseInt(trimmed, 10);
57
+ // Only treat as numeric if it's a valid non-negative integer
58
+ // and the entire string is numeric (not "123abc")
59
+ if (!isNaN(numericIndex) && numericIndex >= 0 && /^\d+$/.test(trimmed)) {
60
+ return numericIndex;
61
+ }
62
+ // Treat as UUID (lib layer will validate)
63
+ return trimmed;
64
+ }
65
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/cli/utils/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAiB,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,SAAS,EAAE,eAAe;IAC1B,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;CACN,CAAC;AAuBX;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,IAAmB;IAC/C,MAAM,QAAQ,GACZ,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,kBAAkB,EAAE,CAAC;IAE3E,OAAO;QACL,QAAQ;QACR,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;QAC1C,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI;KACrB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAyB,EACzB,SAAkC;IAElC,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,GAAG,SAAS;KACb,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAE3C,6DAA6D;IAC7D,kDAAkD;IAClD,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,YAAY,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvE,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,0CAA0C;IAC1C,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * CLI Error handling utilities
3
+ *
4
+ * Provides exit codes, error formatting, and error type guards.
5
+ */
6
+ /**
7
+ * CLI exit codes following Unix conventions
8
+ */
9
+ export declare enum ExitCode {
10
+ /** Command completed successfully */
11
+ SUCCESS = 0,
12
+ /** General/unexpected error */
13
+ GENERAL_ERROR = 1,
14
+ /** Invalid arguments or usage error */
15
+ USAGE_ERROR = 2,
16
+ /** Requested resource not found (session, workspace) */
17
+ NOT_FOUND = 3,
18
+ /** I/O error (file system, permissions) */
19
+ IO_ERROR = 4
20
+ }
21
+ /**
22
+ * Error codes for structured error responses
23
+ */
24
+ export type ErrorCode = 'USAGE_ERROR' | 'NOT_FOUND' | 'IO_ERROR' | 'INTERNAL_ERROR';
25
+ /**
26
+ * Structured command error for JSON output
27
+ */
28
+ export interface CommandError {
29
+ code: ErrorCode;
30
+ message: string;
31
+ details?: string;
32
+ }
33
+ /**
34
+ * CLI-specific error class with exit code
35
+ */
36
+ export declare class CliError extends Error {
37
+ readonly exitCode: ExitCode;
38
+ readonly errorCode: ErrorCode;
39
+ readonly details?: string | undefined;
40
+ constructor(message: string, exitCode: ExitCode, errorCode: ErrorCode, details?: string | undefined);
41
+ /**
42
+ * Convert to CommandError for JSON output
43
+ */
44
+ toCommandError(): CommandError;
45
+ }
46
+ /**
47
+ * Create a usage error (invalid arguments)
48
+ */
49
+ export declare function usageError(message: string, details?: string): CliError;
50
+ /**
51
+ * Create a not found error (session, workspace not found)
52
+ */
53
+ export declare function notFoundError(message: string, details?: string): CliError;
54
+ /**
55
+ * Create an I/O error (file system issues)
56
+ */
57
+ export declare function ioError(message: string, details?: string): CliError;
58
+ /**
59
+ * Create an internal error (unexpected issues)
60
+ */
61
+ export declare function internalError(message: string, details?: string): CliError;
62
+ /**
63
+ * Type guard for CliError
64
+ */
65
+ export declare function isCliError(error: unknown): error is CliError;
66
+ /**
67
+ * Format error for human-readable output
68
+ */
69
+ export declare function formatErrorHuman(error: CliError): string;
70
+ /**
71
+ * Get exit code from an error, defaulting to GENERAL_ERROR for unknown errors
72
+ */
73
+ export declare function getExitCode(error: unknown): ExitCode;
74
+ /**
75
+ * Convert any error to a CliError
76
+ */
77
+ export declare function toCliError(error: unknown): CliError;
78
+ /**
79
+ * Handle command error with appropriate output format
80
+ *
81
+ * @param error - The error that occurred
82
+ * @param json - Whether to output as JSON
83
+ * @returns Exit code for the error
84
+ */
85
+ export declare function handleError(error: unknown, json: boolean): ExitCode;
86
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,oBAAY,QAAQ;IAClB,qCAAqC;IACrC,OAAO,IAAI;IACX,+BAA+B;IAC/B,aAAa,IAAI;IACjB,uCAAuC;IACvC,WAAW,IAAI;IACf,wDAAwD;IACxD,SAAS,IAAI;IACb,2CAA2C;IAC3C,QAAQ,IAAI;CACb;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,aAAa,GACb,WAAW,GACX,UAAU,GACV,gBAAgB,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAGf,QAAQ,EAAE,QAAQ;aAClB,SAAS,EAAE,SAAS;aACpB,OAAO,CAAC,EAAE,MAAM;gBAHhC,OAAO,EAAE,MAAM,EACC,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,MAAM,YAAA;IAMlC;;OAEG;IACH,cAAc,IAAI,YAAY;CAO/B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAEtE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAEzE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAEnE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,QAAQ,CAOzE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAMxD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAKpD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAUnD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,QAAQ,CAcnE"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * CLI Error handling utilities
3
+ *
4
+ * Provides exit codes, error formatting, and error type guards.
5
+ */
6
+ /**
7
+ * CLI exit codes following Unix conventions
8
+ */
9
+ export var ExitCode;
10
+ (function (ExitCode) {
11
+ /** Command completed successfully */
12
+ ExitCode[ExitCode["SUCCESS"] = 0] = "SUCCESS";
13
+ /** General/unexpected error */
14
+ ExitCode[ExitCode["GENERAL_ERROR"] = 1] = "GENERAL_ERROR";
15
+ /** Invalid arguments or usage error */
16
+ ExitCode[ExitCode["USAGE_ERROR"] = 2] = "USAGE_ERROR";
17
+ /** Requested resource not found (session, workspace) */
18
+ ExitCode[ExitCode["NOT_FOUND"] = 3] = "NOT_FOUND";
19
+ /** I/O error (file system, permissions) */
20
+ ExitCode[ExitCode["IO_ERROR"] = 4] = "IO_ERROR";
21
+ })(ExitCode || (ExitCode = {}));
22
+ /**
23
+ * CLI-specific error class with exit code
24
+ */
25
+ export class CliError extends Error {
26
+ exitCode;
27
+ errorCode;
28
+ details;
29
+ constructor(message, exitCode, errorCode, details) {
30
+ super(message);
31
+ this.exitCode = exitCode;
32
+ this.errorCode = errorCode;
33
+ this.details = details;
34
+ this.name = 'CliError';
35
+ }
36
+ /**
37
+ * Convert to CommandError for JSON output
38
+ */
39
+ toCommandError() {
40
+ return {
41
+ code: this.errorCode,
42
+ message: this.message,
43
+ ...(this.details && { details: this.details }),
44
+ };
45
+ }
46
+ }
47
+ /**
48
+ * Create a usage error (invalid arguments)
49
+ */
50
+ export function usageError(message, details) {
51
+ return new CliError(message, ExitCode.USAGE_ERROR, 'USAGE_ERROR', details);
52
+ }
53
+ /**
54
+ * Create a not found error (session, workspace not found)
55
+ */
56
+ export function notFoundError(message, details) {
57
+ return new CliError(message, ExitCode.NOT_FOUND, 'NOT_FOUND', details);
58
+ }
59
+ /**
60
+ * Create an I/O error (file system issues)
61
+ */
62
+ export function ioError(message, details) {
63
+ return new CliError(message, ExitCode.IO_ERROR, 'IO_ERROR', details);
64
+ }
65
+ /**
66
+ * Create an internal error (unexpected issues)
67
+ */
68
+ export function internalError(message, details) {
69
+ return new CliError(message, ExitCode.GENERAL_ERROR, 'INTERNAL_ERROR', details);
70
+ }
71
+ /**
72
+ * Type guard for CliError
73
+ */
74
+ export function isCliError(error) {
75
+ return error instanceof CliError;
76
+ }
77
+ /**
78
+ * Format error for human-readable output
79
+ */
80
+ export function formatErrorHuman(error) {
81
+ let output = `Error: ${error.message}`;
82
+ if (error.details) {
83
+ output += `\n\n${error.details}`;
84
+ }
85
+ return output;
86
+ }
87
+ /**
88
+ * Get exit code from an error, defaulting to GENERAL_ERROR for unknown errors
89
+ */
90
+ export function getExitCode(error) {
91
+ if (isCliError(error)) {
92
+ return error.exitCode;
93
+ }
94
+ return ExitCode.GENERAL_ERROR;
95
+ }
96
+ /**
97
+ * Convert any error to a CliError
98
+ */
99
+ export function toCliError(error) {
100
+ if (isCliError(error)) {
101
+ return error;
102
+ }
103
+ if (error instanceof Error) {
104
+ return internalError(error.message);
105
+ }
106
+ return internalError(String(error));
107
+ }
108
+ /**
109
+ * Handle command error with appropriate output format
110
+ *
111
+ * @param error - The error that occurred
112
+ * @param json - Whether to output as JSON
113
+ * @returns Exit code for the error
114
+ */
115
+ export function handleError(error, json) {
116
+ const cliError = toCliError(error);
117
+ if (json) {
118
+ const result = {
119
+ success: false,
120
+ error: cliError.toCommandError(),
121
+ };
122
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n');
123
+ }
124
+ else {
125
+ process.stderr.write(formatErrorHuman(cliError) + '\n');
126
+ }
127
+ return cliError.exitCode;
128
+ }
129
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/cli/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,QAWX;AAXD,WAAY,QAAQ;IAClB,qCAAqC;IACrC,6CAAW,CAAA;IACX,+BAA+B;IAC/B,yDAAiB,CAAA;IACjB,uCAAuC;IACvC,qDAAe,CAAA;IACf,wDAAwD;IACxD,iDAAa,CAAA;IACb,2CAA2C;IAC3C,+CAAY,CAAA;AACd,CAAC,EAXW,QAAQ,KAAR,QAAQ,QAWnB;AAoBD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGf;IACA;IACA;IAJlB,YACE,OAAe,EACC,QAAkB,EAClB,SAAoB,EACpB,OAAgB;QAEhC,KAAK,CAAC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,QAAQ,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * CLI Output utilities
3
+ *
4
+ * Handles stdout/stderr output, JSON formatting, and command result structure.
5
+ */
6
+ import type { Pagination } from '../../lib/index.js';
7
+ import { type CommandError, type CliError, ExitCode } from './errors.js';
8
+ /**
9
+ * Pagination info for command results
10
+ */
11
+ export interface PaginationInfo {
12
+ total: number;
13
+ offset: number;
14
+ limit: number;
15
+ hasMore: boolean;
16
+ }
17
+ /**
18
+ * Standardized command result for JSON output
19
+ */
20
+ export interface CommandResult<T> {
21
+ success: boolean;
22
+ data?: T;
23
+ error?: CommandError;
24
+ pagination?: PaginationInfo;
25
+ }
26
+ /**
27
+ * Convert lib Pagination to CLI PaginationInfo
28
+ */
29
+ export declare function toPaginationInfo(pagination: Pagination): PaginationInfo;
30
+ /**
31
+ * Create a successful command result
32
+ */
33
+ export declare function successResult<T>(data: T, pagination?: Pagination): CommandResult<T>;
34
+ /**
35
+ * Create a failed command result from an error
36
+ */
37
+ export declare function errorResult(error: CliError): CommandResult<never>;
38
+ /**
39
+ * Output content to stdout
40
+ */
41
+ export declare function stdout(content: string): void;
42
+ /**
43
+ * Output error to stderr
44
+ */
45
+ export declare function stderr(content: string): void;
46
+ /**
47
+ * Output JSON to stdout
48
+ */
49
+ export declare function outputJson<T>(result: CommandResult<T>): void;
50
+ /**
51
+ * Output result based on format preference
52
+ *
53
+ * @param result - Command result or formatted string
54
+ * @param json - Whether to output as JSON
55
+ * @param humanOutput - Human-readable string (used when json=false)
56
+ */
57
+ export declare function output<T>(result: CommandResult<T>, json: boolean, humanOutput?: string): void;
58
+ /**
59
+ * Handle command error with appropriate output format
60
+ *
61
+ * @param error - The error that occurred
62
+ * @param json - Whether to output as JSON
63
+ * @returns Exit code for the error
64
+ */
65
+ export declare function handleError(error: unknown, json: boolean): ExitCode;
66
+ /**
67
+ * Format pagination hint for human output
68
+ *
69
+ * @param pagination - Pagination info
70
+ * @param itemName - Name of items being paginated (e.g., "sessions", "matches")
71
+ * @returns Human-readable pagination hint or empty string if not needed
72
+ */
73
+ export declare function formatPaginationHint(pagination: PaginationInfo, itemName: string): string;
74
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,QAAQ,EAGT,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,cAAc,CAOvE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,CAAC,EACP,UAAU,CAAC,EAAE,UAAU,GACtB,aAAa,CAAC,CAAC,CAAC,CAMlB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,aAAa,CAAC,KAAK,CAAC,CAKjE;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAM5C;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAK5C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,EACxB,IAAI,EAAE,OAAO,EACb,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI,CASN;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,QAAQ,CAUnE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,cAAc,EAC1B,QAAQ,EAAE,MAAM,GACf,MAAM,CASR"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * CLI Output utilities
3
+ *
4
+ * Handles stdout/stderr output, JSON formatting, and command result structure.
5
+ */
6
+ import { toCliError, formatErrorHuman, } from './errors.js';
7
+ /**
8
+ * Convert lib Pagination to CLI PaginationInfo
9
+ */
10
+ export function toPaginationInfo(pagination) {
11
+ return {
12
+ total: pagination.total,
13
+ offset: pagination.offset,
14
+ limit: pagination.limit,
15
+ hasMore: pagination.hasMore,
16
+ };
17
+ }
18
+ /**
19
+ * Create a successful command result
20
+ */
21
+ export function successResult(data, pagination) {
22
+ return {
23
+ success: true,
24
+ data,
25
+ ...(pagination && { pagination: toPaginationInfo(pagination) }),
26
+ };
27
+ }
28
+ /**
29
+ * Create a failed command result from an error
30
+ */
31
+ export function errorResult(error) {
32
+ return {
33
+ success: false,
34
+ error: error.toCommandError(),
35
+ };
36
+ }
37
+ /**
38
+ * Output content to stdout
39
+ */
40
+ export function stdout(content) {
41
+ process.stdout.write(content);
42
+ // Ensure newline at end if not present
43
+ if (!content.endsWith('\n')) {
44
+ process.stdout.write('\n');
45
+ }
46
+ }
47
+ /**
48
+ * Output error to stderr
49
+ */
50
+ export function stderr(content) {
51
+ process.stderr.write(content);
52
+ if (!content.endsWith('\n')) {
53
+ process.stderr.write('\n');
54
+ }
55
+ }
56
+ /**
57
+ * Output JSON to stdout
58
+ */
59
+ export function outputJson(result) {
60
+ stdout(JSON.stringify(result, null, 2));
61
+ }
62
+ /**
63
+ * Output result based on format preference
64
+ *
65
+ * @param result - Command result or formatted string
66
+ * @param json - Whether to output as JSON
67
+ * @param humanOutput - Human-readable string (used when json=false)
68
+ */
69
+ export function output(result, json, humanOutput) {
70
+ if (json) {
71
+ outputJson(result);
72
+ }
73
+ else if (humanOutput !== undefined) {
74
+ stdout(humanOutput);
75
+ }
76
+ else if (result.data !== undefined) {
77
+ // Fallback: stringify data if no human output provided
78
+ stdout(JSON.stringify(result.data, null, 2));
79
+ }
80
+ }
81
+ /**
82
+ * Handle command error with appropriate output format
83
+ *
84
+ * @param error - The error that occurred
85
+ * @param json - Whether to output as JSON
86
+ * @returns Exit code for the error
87
+ */
88
+ export function handleError(error, json) {
89
+ const cliError = toCliError(error);
90
+ if (json) {
91
+ outputJson(errorResult(cliError));
92
+ }
93
+ else {
94
+ stderr(formatErrorHuman(cliError));
95
+ }
96
+ return cliError.exitCode;
97
+ }
98
+ /**
99
+ * Format pagination hint for human output
100
+ *
101
+ * @param pagination - Pagination info
102
+ * @param itemName - Name of items being paginated (e.g., "sessions", "matches")
103
+ * @returns Human-readable pagination hint or empty string if not needed
104
+ */
105
+ export function formatPaginationHint(pagination, itemName) {
106
+ if (!pagination.hasMore) {
107
+ return '';
108
+ }
109
+ const start = pagination.offset + 1;
110
+ const end = Math.min(pagination.offset + pagination.limit, pagination.total);
111
+ return `\nShowing ${start}-${end} of ${pagination.total} ${itemName}. Use --offset to see more.`;
112
+ }
113
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../../src/cli/utils/output.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAIL,UAAU,EACV,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAsBrB;;GAEG;AACH,MAAM,UAAU,gBAAgB,CA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ACnG,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Configuration handling for claude-code-history library.
3
+ */
4
+ import type { LibraryConfig } from './types.js';
5
+ /** Default configuration values */
6
+ export declare const DEFAULT_CONFIG: Required<Omit<LibraryConfig, 'dataPath' | 'workspace'>> & {
7
+ dataPath: string;
8
+ workspace: undefined;
9
+ };
10
+ /**
11
+ * Internal resolved configuration with all fields required.
12
+ */
13
+ export interface ResolvedConfig {
14
+ dataPath: string;
15
+ workspace: string | undefined;
16
+ limit: number;
17
+ offset: number;
18
+ context: number;
19
+ }
20
+ /**
21
+ * Merge user config with defaults and validate.
22
+ * @param config - User-provided configuration
23
+ * @returns Resolved configuration with all fields
24
+ */
25
+ export declare function resolveConfig(config?: LibraryConfig): ResolvedConfig;
26
+ /**
27
+ * Apply pagination to an array of items.
28
+ * @param items - Full array of items
29
+ * @param config - Configuration with limit and offset
30
+ * @returns Paginated slice of items
31
+ */
32
+ export declare function paginate<T>(items: T[], config: ResolvedConfig): T[];
33
+ /**
34
+ * Create pagination metadata.
35
+ * @param total - Total number of items
36
+ * @param config - Configuration with limit and offset
37
+ */
38
+ export declare function createPagination(total: number, config: ResolvedConfig): {
39
+ total: number;
40
+ limit: number;
41
+ offset: number;
42
+ hasMore: boolean;
43
+ };
44
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,mCAAmC;AACnC,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,WAAW,CAAC,CAAC,GAAG;IACrF,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;CAOtB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,cAAc,CAqBpE;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,GAAG,CAAC,EAAE,CAEnE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,cAAc,GACrB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAOpE"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Configuration handling for claude-code-history library.
3
+ */
4
+ import { getDefaultDataPath } from './platform.js';
5
+ /** Default configuration values */
6
+ export const DEFAULT_CONFIG = {
7
+ dataPath: getDefaultDataPath(),
8
+ workspace: undefined,
9
+ limit: 50,
10
+ offset: 0,
11
+ context: 2,
12
+ };
13
+ /**
14
+ * Merge user config with defaults and validate.
15
+ * @param config - User-provided configuration
16
+ * @returns Resolved configuration with all fields
17
+ */
18
+ export function resolveConfig(config) {
19
+ const resolved = {
20
+ dataPath: config?.dataPath ?? DEFAULT_CONFIG.dataPath,
21
+ workspace: config?.workspace,
22
+ limit: config?.limit ?? DEFAULT_CONFIG.limit,
23
+ offset: config?.offset ?? DEFAULT_CONFIG.offset,
24
+ context: config?.context ?? DEFAULT_CONFIG.context,
25
+ };
26
+ // Validate numeric values
27
+ if (resolved.limit < 0) {
28
+ throw new Error('limit must be non-negative');
29
+ }
30
+ if (resolved.offset < 0) {
31
+ throw new Error('offset must be non-negative');
32
+ }
33
+ if (resolved.context < 0) {
34
+ throw new Error('context must be non-negative');
35
+ }
36
+ return resolved;
37
+ }
38
+ /**
39
+ * Apply pagination to an array of items.
40
+ * @param items - Full array of items
41
+ * @param config - Configuration with limit and offset
42
+ * @returns Paginated slice of items
43
+ */
44
+ export function paginate(items, config) {
45
+ return items.slice(config.offset, config.offset + config.limit);
46
+ }
47
+ /**
48
+ * Create pagination metadata.
49
+ * @param total - Total number of items
50
+ * @param config - Configuration with limit and offset
51
+ */
52
+ export function createPagination(total, config) {
53
+ return {
54
+ total,
55
+ limit: config.limit,
56
+ offset: config.offset,
57
+ hasMore: config.offset + config.limit < total,
58
+ };
59
+ }
60
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,mCAAmC;AACnC,MAAM,CAAC,MAAM,cAAc,GAGvB;IACF,QAAQ,EAAE,kBAAkB,EAAE;IAC9B,SAAS,EAAE,SAAS;IACpB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;CACX,CAAC;AAaF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAsB;IAClD,MAAM,QAAQ,GAAmB;QAC/B,QAAQ,EAAE,MAAM,EAAE,QAAQ,IAAI,cAAc,CAAC,QAAQ;QACrD,SAAS,EAAE,MAAM,EAAE,SAAS;QAC5B,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,cAAc,CAAC,KAAK;QAC5C,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,cAAc,CAAC,MAAM;QAC/C,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,cAAc,CAAC,OAAO;KACnD,CAAC;IAEF,0BAA0B;IAC1B,IAAI,QAAQ,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,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