indusagi-coding-agent 0.1.23 → 0.1.25

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 (236) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +2 -0
  3. package/dist/cli/args.d.ts +117 -1
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +221 -52
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/config-selector.d.ts +58 -2
  8. package/dist/cli/config-selector.d.ts.map +1 -1
  9. package/dist/cli/config-selector.js +130 -12
  10. package/dist/cli/config-selector.js.map +1 -1
  11. package/dist/cli/file-processor.d.ts +70 -2
  12. package/dist/cli/file-processor.d.ts.map +1 -1
  13. package/dist/cli/file-processor.js +240 -15
  14. package/dist/cli/file-processor.js.map +1 -1
  15. package/dist/cli/list-models.d.ts +63 -3
  16. package/dist/cli/list-models.d.ts.map +1 -1
  17. package/dist/cli/list-models.js +202 -27
  18. package/dist/cli/list-models.js.map +1 -1
  19. package/dist/cli/login-handler.d.ts +82 -8
  20. package/dist/cli/login-handler.d.ts.map +1 -1
  21. package/dist/cli/login-handler.js +410 -77
  22. package/dist/cli/login-handler.js.map +1 -1
  23. package/dist/cli/session-picker.d.ts +74 -2
  24. package/dist/cli/session-picker.d.ts.map +1 -1
  25. package/dist/cli/session-picker.js +236 -12
  26. package/dist/cli/session-picker.js.map +1 -1
  27. package/dist/core/agent-session.d.ts +214 -9
  28. package/dist/core/agent-session.d.ts.map +1 -1
  29. package/dist/core/agent-session.js +214 -9
  30. package/dist/core/agent-session.js.map +1 -1
  31. package/dist/core/bash-executor.d.ts +302 -12
  32. package/dist/core/bash-executor.d.ts.map +1 -1
  33. package/dist/core/bash-executor.js +302 -12
  34. package/dist/core/bash-executor.js.map +1 -1
  35. package/dist/core/diagnostics.d.ts +191 -0
  36. package/dist/core/diagnostics.d.ts.map +1 -1
  37. package/dist/core/diagnostics.js +142 -0
  38. package/dist/core/diagnostics.js.map +1 -1
  39. package/dist/core/discover-packages.d.ts +6 -0
  40. package/dist/core/discover-packages.d.ts.map +1 -0
  41. package/dist/core/discover-packages.js +62 -0
  42. package/dist/core/discover-packages.js.map +1 -0
  43. package/dist/core/event-bus.d.ts +146 -0
  44. package/dist/core/event-bus.d.ts.map +1 -1
  45. package/dist/core/event-bus.js +93 -0
  46. package/dist/core/event-bus.js.map +1 -1
  47. package/dist/core/export-html/ansi-to-html.d.ts +4 -0
  48. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  49. package/dist/core/export-html/ansi-to-html.js +4 -0
  50. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  51. package/dist/core/export-html/index.d.ts +128 -0
  52. package/dist/core/export-html/index.d.ts.map +1 -1
  53. package/dist/core/export-html/index.js +128 -0
  54. package/dist/core/export-html/index.js.map +1 -1
  55. package/dist/core/export-html/tool-renderer.d.ts +4 -0
  56. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  57. package/dist/core/export-html/tool-renderer.js +4 -0
  58. package/dist/core/export-html/tool-renderer.js.map +1 -1
  59. package/dist/core/keybindings.d.ts +142 -0
  60. package/dist/core/keybindings.d.ts.map +1 -1
  61. package/dist/core/keybindings.js +142 -0
  62. package/dist/core/keybindings.js.map +1 -1
  63. package/dist/core/model-registry.d.ts +98 -1
  64. package/dist/core/model-registry.d.ts.map +1 -1
  65. package/dist/core/model-registry.js +98 -1
  66. package/dist/core/model-registry.js.map +1 -1
  67. package/dist/core/model-resolver.d.ts +99 -1
  68. package/dist/core/model-resolver.d.ts.map +1 -1
  69. package/dist/core/model-resolver.js +99 -1
  70. package/dist/core/model-resolver.js.map +1 -1
  71. package/dist/core/prompt-templates.js.map +1 -1
  72. package/dist/core/sdk.d.ts.map +1 -1
  73. package/dist/core/sdk.js +2 -0
  74. package/dist/core/sdk.js.map +1 -1
  75. package/dist/core/session-manager.d.ts +127 -0
  76. package/dist/core/session-manager.d.ts.map +1 -1
  77. package/dist/core/session-manager.js +125 -0
  78. package/dist/core/session-manager.js.map +1 -1
  79. package/dist/core/skills.js.map +1 -1
  80. package/dist/core/subagents.js.map +1 -1
  81. package/dist/core/tools/bash.d.ts +391 -11
  82. package/dist/core/tools/bash.d.ts.map +1 -1
  83. package/dist/core/tools/bash.js +269 -2
  84. package/dist/core/tools/bash.js.map +1 -1
  85. package/dist/core/tools/bg-process.d.ts +49 -0
  86. package/dist/core/tools/bg-process.d.ts.map +1 -0
  87. package/dist/core/tools/bg-process.js +69 -0
  88. package/dist/core/tools/bg-process.js.map +1 -0
  89. package/dist/core/tools/edit.d.ts +284 -6
  90. package/dist/core/tools/edit.d.ts.map +1 -1
  91. package/dist/core/tools/edit.js +238 -0
  92. package/dist/core/tools/edit.js.map +1 -1
  93. package/dist/core/tools/find.d.ts +169 -5
  94. package/dist/core/tools/find.d.ts.map +1 -1
  95. package/dist/core/tools/find.js +136 -0
  96. package/dist/core/tools/find.js.map +1 -1
  97. package/dist/core/tools/grep.d.ts +285 -5
  98. package/dist/core/tools/grep.d.ts.map +1 -1
  99. package/dist/core/tools/grep.js +247 -0
  100. package/dist/core/tools/grep.js.map +1 -1
  101. package/dist/core/tools/index.d.ts +45 -0
  102. package/dist/core/tools/index.d.ts.map +1 -1
  103. package/dist/core/tools/index.js +15 -0
  104. package/dist/core/tools/index.js.map +1 -1
  105. package/dist/core/tools/ls.d.ts +6 -0
  106. package/dist/core/tools/ls.d.ts.map +1 -1
  107. package/dist/core/tools/ls.js +6 -0
  108. package/dist/core/tools/ls.js.map +1 -1
  109. package/dist/core/tools/read.d.ts +308 -7
  110. package/dist/core/tools/read.d.ts.map +1 -1
  111. package/dist/core/tools/read.js +231 -0
  112. package/dist/core/tools/read.js.map +1 -1
  113. package/dist/core/tools/registry.d.ts +17 -0
  114. package/dist/core/tools/registry.d.ts.map +1 -0
  115. package/dist/core/tools/registry.js +108 -0
  116. package/dist/core/tools/registry.js.map +1 -0
  117. package/dist/core/tools/webfetch.d.ts +118 -3
  118. package/dist/core/tools/webfetch.d.ts.map +1 -1
  119. package/dist/core/tools/webfetch.js +118 -3
  120. package/dist/core/tools/webfetch.js.map +1 -1
  121. package/dist/core/tools/websearch.d.ts +130 -3
  122. package/dist/core/tools/websearch.d.ts.map +1 -1
  123. package/dist/core/tools/websearch.js +130 -3
  124. package/dist/core/tools/websearch.js.map +1 -1
  125. package/dist/core/tools/write.d.ts +251 -5
  126. package/dist/core/tools/write.d.ts.map +1 -1
  127. package/dist/core/tools/write.js +210 -0
  128. package/dist/core/tools/write.js.map +1 -1
  129. package/dist/main.d.ts.map +1 -1
  130. package/dist/main.js +12 -1
  131. package/dist/main.js.map +1 -1
  132. package/dist/modes/interactive/components/assistant-message.d.ts +164 -1
  133. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  134. package/dist/modes/interactive/components/assistant-message.js +164 -1
  135. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  136. package/dist/modes/interactive/components/bash-execution.d.ts +297 -1
  137. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  138. package/dist/modes/interactive/components/bash-execution.js +297 -1
  139. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  140. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  141. package/dist/modes/interactive/components/tool-execution.js +251 -1
  142. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  143. package/dist/modes/interactive/components/user-message.d.ts +186 -1
  144. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  145. package/dist/modes/interactive/components/user-message.js +186 -1
  146. package/dist/modes/interactive/components/user-message.js.map +1 -1
  147. package/dist/modes/interactive/interactive-mode.d.ts +1567 -13
  148. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  149. package/dist/modes/interactive/interactive-mode.js +1567 -13
  150. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  151. package/dist/modes/interactive/theme/theme.d.ts +422 -0
  152. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  153. package/dist/modes/interactive/theme/theme.js +422 -0
  154. package/dist/modes/interactive/theme/theme.js.map +1 -1
  155. package/dist/modes/print-mode.d.ts +538 -5
  156. package/dist/modes/print-mode.d.ts.map +1 -1
  157. package/dist/modes/print-mode.js +538 -5
  158. package/dist/modes/print-mode.js.map +1 -1
  159. package/dist/modes/rpc/rpc-client.d.ts +921 -8
  160. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  161. package/dist/modes/rpc/rpc-client.js +921 -8
  162. package/dist/modes/rpc/rpc-client.js.map +1 -1
  163. package/dist/modes/rpc/rpc-mode.d.ts +802 -9
  164. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  165. package/dist/modes/rpc/rpc-mode.js +802 -9
  166. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  167. package/dist/modes/rpc/rpc-types.d.ts +356 -3
  168. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  169. package/dist/modes/rpc/rpc-types.js +356 -3
  170. package/dist/modes/rpc/rpc-types.js.map +1 -1
  171. package/dist/modes/shared.d.ts +386 -0
  172. package/dist/modes/shared.d.ts.map +1 -0
  173. package/dist/modes/shared.js +543 -0
  174. package/dist/modes/shared.js.map +1 -0
  175. package/dist/utils/array.d.ts +389 -0
  176. package/dist/utils/array.d.ts.map +1 -0
  177. package/dist/utils/array.js +585 -0
  178. package/dist/utils/array.js.map +1 -0
  179. package/dist/utils/color-formatter.d.ts +318 -0
  180. package/dist/utils/color-formatter.d.ts.map +1 -0
  181. package/dist/utils/color-formatter.js +442 -0
  182. package/dist/utils/color-formatter.js.map +1 -0
  183. package/dist/utils/data-transformer.d.ts +326 -0
  184. package/dist/utils/data-transformer.d.ts.map +1 -0
  185. package/dist/utils/data-transformer.js +512 -0
  186. package/dist/utils/data-transformer.js.map +1 -0
  187. package/dist/utils/date-formatter.d.ts +281 -0
  188. package/dist/utils/date-formatter.d.ts.map +1 -0
  189. package/dist/utils/date-formatter.js +503 -0
  190. package/dist/utils/date-formatter.js.map +1 -0
  191. package/dist/utils/error-handler.d.ts +541 -0
  192. package/dist/utils/error-handler.d.ts.map +1 -0
  193. package/dist/utils/error-handler.js +726 -0
  194. package/dist/utils/error-handler.js.map +1 -0
  195. package/dist/utils/file-operations.d.ts +297 -0
  196. package/dist/utils/file-operations.d.ts.map +1 -0
  197. package/dist/utils/file-operations.js +505 -0
  198. package/dist/utils/file-operations.js.map +1 -0
  199. package/dist/utils/frontmatter.d.ts +268 -6
  200. package/dist/utils/frontmatter.d.ts.map +1 -1
  201. package/dist/utils/frontmatter.js +500 -21
  202. package/dist/utils/frontmatter.js.map +1 -1
  203. package/dist/utils/json-formatter.d.ts +259 -0
  204. package/dist/utils/json-formatter.d.ts.map +1 -0
  205. package/dist/utils/json-formatter.js +517 -0
  206. package/dist/utils/json-formatter.js.map +1 -0
  207. package/dist/utils/logger.d.ts +176 -0
  208. package/dist/utils/logger.d.ts.map +1 -0
  209. package/dist/utils/logger.js +346 -0
  210. package/dist/utils/logger.js.map +1 -0
  211. package/dist/utils/markdown-formatter.d.ts +211 -0
  212. package/dist/utils/markdown-formatter.d.ts.map +1 -0
  213. package/dist/utils/markdown-formatter.js +482 -0
  214. package/dist/utils/markdown-formatter.js.map +1 -0
  215. package/dist/utils/path-validator.d.ts +603 -0
  216. package/dist/utils/path-validator.d.ts.map +1 -0
  217. package/dist/utils/path-validator.js +870 -0
  218. package/dist/utils/path-validator.js.map +1 -0
  219. package/dist/utils/string-formatter.d.ts +609 -0
  220. package/dist/utils/string-formatter.d.ts.map +1 -0
  221. package/dist/utils/string-formatter.js +806 -0
  222. package/dist/utils/string-formatter.js.map +1 -0
  223. package/dist/utils/type-guards.d.ts +629 -0
  224. package/dist/utils/type-guards.d.ts.map +1 -0
  225. package/dist/utils/type-guards.js +662 -0
  226. package/dist/utils/type-guards.js.map +1 -0
  227. package/docs/COMPLETE-GUIDE.md +300 -0
  228. package/docs/COMPREHENSIVE-CLI-SUMMARY.md +900 -0
  229. package/docs/MODES-ARCHITECTURE.md +565 -0
  230. package/docs/PRINT-MODE-GUIDE.md +456 -0
  231. package/docs/RPC-GUIDE.md +705 -0
  232. package/docs/UTILS-IMPLEMENTATION-SUMMARY.md +647 -0
  233. package/docs/UTILS-MODULE-OVERVIEW.md +1480 -0
  234. package/docs/UTILS-QA-CHECKLIST.md +1061 -0
  235. package/docs/UTILS-USAGE-GUIDE.md +1419 -0
  236. package/package.json +7 -3
@@ -0,0 +1,541 @@
1
+ /**
2
+ * @fileoverview Error Handling and Recovery Utilities
3
+ *
4
+ * This module provides robust error handling utilities for transforming technical
5
+ * errors into user-friendly messages, categorizing errors, and providing recovery
6
+ * suggestions. Error handling is critical for:
7
+ *
8
+ * 1. **User Experience**: Transform cryptic technical errors into actionable messages
9
+ * 2. **Error Categorization**: Classify errors by type (TypeError, FileNotFound, etc.)
10
+ * 3. **Recovery Suggestions**: Provide users with steps to resolve issues
11
+ * 4. **Security**: Avoid leaking sensitive information in error messages
12
+ * 5. **Logging and Debugging**: Format errors for logs and debugging
13
+ * 6. **Error Codes**: Standardize error codes for programmatic error handling
14
+ *
15
+ * ## Error Code Conventions
16
+ *
17
+ * ### System Errors (E-prefix)
18
+ * - E001: Unknown error
19
+ * - E002: Validation error
20
+ * - E003: Configuration error
21
+ * - E004: Permission denied
22
+ * - E005: Resource not found
23
+ * - E006: Timeout error
24
+ * - E007: Network error
25
+ * - E008: Parse error
26
+ *
27
+ * ### Node.js System Errors (POSIX)
28
+ * - EACCES: Permission denied
29
+ * - EEXIST: File already exists
30
+ * - EISDIR: Is a directory
31
+ * - ENOENT: No such file or directory
32
+ * - ENOTDIR: Not a directory
33
+ * - EPERM: Operation not permitted
34
+ * - ETIMEDOUT: Connection timed out
35
+ * - ECONNREFUSED: Connection refused
36
+ *
37
+ * ## Error Type Hierarchy
38
+ *
39
+ * JavaScript error types provide context about what went wrong:
40
+ * - **Error**: Generic error, safe fallback
41
+ * - **TypeError**: Type mismatch or invalid operation
42
+ * - **ReferenceError**: Undefined variable or property
43
+ * - **RangeError**: Value out of valid range
44
+ * - **SyntaxError**: Malformed code or JSON
45
+ * - **EvalError**: eval() function error (rarely thrown)
46
+ * - **URIError**: Invalid URI function argument
47
+ *
48
+ * ## Security Considerations
49
+ *
50
+ * Error messages can leak sensitive information:
51
+ * - File system paths
52
+ * - Internal variable names
53
+ * - API endpoints
54
+ * - Database structure
55
+ * - Configuration secrets
56
+ *
57
+ * Always sanitize error messages before displaying to users.
58
+ *
59
+ * @author Coding Agent
60
+ * @version 1.0.0
61
+ */
62
+ /**
63
+ * Standard error code enum for consistent error identification.
64
+ *
65
+ * Error codes allow programmatic error handling and localization.
66
+ * Each code corresponds to an error category and recovery strategy.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * if (error.code === ErrorCode.EACCES) {
71
+ * // Show permission error UI
72
+ * showPermissionError();
73
+ * }
74
+ * ```
75
+ */
76
+ export declare enum ErrorCode {
77
+ UNKNOWN = "E001",
78
+ VALIDATION = "E002",
79
+ CONFIG = "E003",
80
+ PERMISSION = "E004",
81
+ NOT_FOUND = "E005",
82
+ TIMEOUT = "E006",
83
+ NETWORK = "E007",
84
+ PARSE_ERROR = "E008",
85
+ EACCES = "EACCES",// Permission denied
86
+ EEXIST = "EEXIST",// File exists
87
+ EISDIR = "EISDIR",// Is a directory
88
+ ENOENT = "ENOENT",// No such file or directory
89
+ ENOTDIR = "ENOTDIR",// Not a directory
90
+ EPERM = "EPERM",// Operation not permitted
91
+ ETIMEDOUT = "ETIMEDOUT",// Connection timed out
92
+ ECONNREFUSED = "ECONNREFUSED"
93
+ }
94
+ /**
95
+ * Structured error information for consistent error handling.
96
+ *
97
+ * @interface FormattedError
98
+ * @property code - Machine-readable error code
99
+ * @property message - User-friendly error message
100
+ * @property technicalDetails - Detailed technical information (internal use only)
101
+ * @property stack - Stack trace for debugging
102
+ * @property suggestions - User-facing recovery suggestions
103
+ * @property originalError - Original error object reference
104
+ * @property timestamp - Error occurrence time
105
+ */
106
+ export interface FormattedError {
107
+ code: string;
108
+ message: string;
109
+ technicalDetails: string;
110
+ stack?: string;
111
+ suggestions: string[];
112
+ originalError: unknown;
113
+ timestamp: Date;
114
+ }
115
+ /**
116
+ * Categorizes an error into a standard error type.
117
+ *
118
+ * Error type identification enables targeted error handling and appropriate
119
+ * UI/messaging responses.
120
+ *
121
+ * @param error - The error to categorize
122
+ * @returns Standard error type name
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * try {
127
+ * const value: any = null;
128
+ * value.property.nested = 123; // TypeError: Cannot read property 'property'
129
+ * } catch (error) {
130
+ * const type = categorizeError(error);
131
+ * // type === 'TypeError'
132
+ * if (type === 'TypeError') {
133
+ * showTypeErrorRecovery();
134
+ * }
135
+ * }
136
+ * ```
137
+ *
138
+ * @usage
139
+ * ```typescript
140
+ * // Error type routing
141
+ * function handleError(error: unknown) {
142
+ * const errorType = categorizeError(error);
143
+ *
144
+ * switch (errorType) {
145
+ * case 'TypeError':
146
+ * logMetric('type_error');
147
+ * break;
148
+ * case 'ReferenceError':
149
+ * logMetric('reference_error');
150
+ * break;
151
+ * case 'SyntaxError':
152
+ * logMetric('syntax_error');
153
+ * break;
154
+ * default:
155
+ * logMetric('unknown_error');
156
+ * }
157
+ * }
158
+ * ```
159
+ */
160
+ export declare function categorizeError(error: unknown): string;
161
+ /**
162
+ * Extracts and formats stack trace from an error.
163
+ *
164
+ * Stack traces are essential for debugging but should never be shown to
165
+ * end users due to security concerns. Use for logging and diagnostics.
166
+ *
167
+ * @param error - The error to extract stack from
168
+ * @returns Formatted stack trace string or empty string
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * try {
173
+ * riskyOperation();
174
+ * } catch (error) {
175
+ * const stack = extractStackTrace(error);
176
+ * // stack:
177
+ * // "Error: Something went wrong
178
+ * // at riskyOperation (/path/to/file.ts:42:10)
179
+ * // at main (/path/to/file.ts:1:5)"
180
+ * logger.error(stack);
181
+ * }
182
+ * ```
183
+ *
184
+ * @usage
185
+ * ```typescript
186
+ * // Log error details without exposing to users
187
+ * function logErrorForSupport(error: unknown): void {
188
+ * const stack = extractStackTrace(error);
189
+ * const timestamp = new Date().toISOString();
190
+ * const entry = `[${timestamp}] ${String(error)}\n${stack}`;
191
+ *
192
+ * fs.appendFileSync('error.log', entry + '\n');
193
+ * }
194
+ *
195
+ * // Send to error tracking service
196
+ * function reportToSentry(error: unknown): void {
197
+ * const stack = extractStackTrace(error);
198
+ * Sentry.captureException(error, {
199
+ * extra: { stack }
200
+ * });
201
+ * }
202
+ * ```
203
+ */
204
+ export declare function extractStackTrace(error: unknown): string;
205
+ /**
206
+ * Sanitizes error messages to prevent information leakage.
207
+ *
208
+ * Removes sensitive information like:
209
+ * - File system paths
210
+ * - Environment variables
211
+ * - Internal file names
212
+ * - Memory addresses
213
+ * - API endpoints
214
+ *
215
+ * @param message - Raw error message
216
+ * @returns Sanitized error message safe for user display
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * // Input (dangerous):
221
+ * const raw = 'Error reading /home/user/secret.key: EACCES';
222
+ * const safe = sanitizeErrorMessage(raw);
223
+ * // Output: 'Error reading file: Permission denied'
224
+ *
225
+ * // Input (dangerous):
226
+ * const raw2 = 'Failed to connect to DATABASE_URL=postgres://user:pass@host';
227
+ * const safe2 = sanitizeErrorMessage(raw2);
228
+ * // Output: 'Failed to connect to database'
229
+ * ```
230
+ *
231
+ * @usage
232
+ * ```typescript
233
+ * // Safe error display in UI
234
+ * function showUserError(error: unknown): void {
235
+ * const message = extractErrorMessage(error);
236
+ * const safe = sanitizeErrorMessage(message);
237
+ *
238
+ * showNotification({
239
+ * type: 'error',
240
+ * message: safe,
241
+ * duration: 5000
242
+ * });
243
+ * }
244
+ *
245
+ * // Log technical details separately
246
+ * function logErrorSecurely(error: unknown): void {
247
+ * const technical = extractErrorMessage(error);
248
+ * const safe = sanitizeErrorMessage(technical);
249
+ *
250
+ * // Log full details to secure server log
251
+ * internalLogger.error(technical);
252
+ *
253
+ * // Show safe version to user
254
+ * userNotification.error(safe);
255
+ * }
256
+ * ```
257
+ */
258
+ export declare function sanitizeErrorMessage(message: string): string;
259
+ /**
260
+ * Extracts the error message from various error types.
261
+ *
262
+ * Handles Error objects, plain objects with message property, and stringified errors.
263
+ *
264
+ * @param error - The error to extract message from
265
+ * @returns Error message string
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * extractErrorMessage(new Error('File not found'))
270
+ * // 'File not found'
271
+ *
272
+ * extractErrorMessage({ message: 'Custom error' })
273
+ * // 'Custom error'
274
+ *
275
+ * extractErrorMessage('Simple string error')
276
+ * // 'Simple string error'
277
+ *
278
+ * extractErrorMessage(null)
279
+ * // 'An unknown error occurred'
280
+ * ```
281
+ *
282
+ * @usage
283
+ * ```typescript
284
+ * // Unified error message extraction
285
+ * async function executeWithErrorHandling<T>(
286
+ * fn: () => Promise<T>
287
+ * ): Promise<T> {
288
+ * try {
289
+ * return await fn();
290
+ * } catch (error) {
291
+ * const message = extractErrorMessage(error);
292
+ * throw new Error(`Operation failed: ${message}`);
293
+ * }
294
+ * }
295
+ * ```
296
+ */
297
+ export declare function extractErrorMessage(error: unknown): string;
298
+ /**
299
+ * Gets recovery suggestions based on error type.
300
+ *
301
+ * Provides users with actionable steps to resolve common errors.
302
+ *
303
+ * @param error - The error to get suggestions for
304
+ * @param errorCode - Optional error code for more specific suggestions
305
+ * @returns Array of suggestion strings
306
+ *
307
+ * @example
308
+ * ```typescript
309
+ * const error = new Error('ENOENT: no such file or directory');
310
+ * const suggestions = getRecoverySuggestions(error, ErrorCode.ENOENT);
311
+ * // [
312
+ * // 'Check that the file path is correct',
313
+ * // 'Verify the file exists in the specified location',
314
+ * // 'Try using an absolute file path instead of relative'
315
+ * // ]
316
+ * ```
317
+ *
318
+ * @usage
319
+ * ```typescript
320
+ * // Show recovery steps in UI
321
+ * function showDetailedError(error: unknown) {
322
+ * const message = extractErrorMessage(error);
323
+ * const suggestions = getRecoverySuggestions(error);
324
+ *
325
+ * showErrorDialog({
326
+ * title: 'Operation Failed',
327
+ * message: sanitizeErrorMessage(message),
328
+ * suggestions: suggestions,
329
+ * actions: [
330
+ * { label: 'Try Again', handler: retry },
331
+ * { label: 'Cancel', handler: cancel }
332
+ * ]
333
+ * });
334
+ * }
335
+ * ```
336
+ */
337
+ export declare function getRecoverySuggestions(error: unknown, errorCode?: string): string[];
338
+ /**
339
+ * Main error formatting function for user-friendly error display.
340
+ *
341
+ * Transforms a raw error into a structured, sanitized error object suitable
342
+ * for display to end users while preserving technical details for logging.
343
+ *
344
+ * @param error - The error to format
345
+ * @param options - Optional formatting options
346
+ * @param options.code - Override error code
347
+ * @param options.includeStack - Include stack trace in output (default: false for users)
348
+ * @param options.sanitize - Sanitize message for user display (default: true)
349
+ * @returns Formatted error object with user-friendly message
350
+ *
351
+ * @throws Never throws, always returns a valid FormattedError
352
+ *
353
+ * @example
354
+ * ```typescript
355
+ * // File system error
356
+ * try {
357
+ * fs.readFileSync('/etc/shadow'); // EACCES
358
+ * } catch (error) {
359
+ * const formatted = formatErrorForUser(error, { code: ErrorCode.EACCES });
360
+ * // {
361
+ * // code: 'EACCES',
362
+ * // message: 'Permission denied. Check file permissions.',
363
+ * // technicalDetails: 'Error: EACCES: permission denied, open ...',
364
+ * // suggestions: [
365
+ * // 'Check file/directory permissions',
366
+ * // 'Try running with elevated privileges if necessary',
367
+ * // 'Ensure the file owner allows read/write access'
368
+ * // ],
369
+ * // timestamp: 2024-01-15T10:30:45.123Z
370
+ * // }
371
+ * }
372
+ * ```
373
+ *
374
+ * ```typescript
375
+ * // API validation error
376
+ * const error = new TypeError('Cannot read property "name" of undefined');
377
+ * const formatted = formatErrorForUser(error);
378
+ * // {
379
+ * // code: 'E002',
380
+ * // message: 'Invalid input provided',
381
+ * // technicalDetails: 'TypeError: Cannot read property "name" of undefined',
382
+ * // suggestions: [
383
+ * // 'Verify that variables are initialized before use',
384
+ * // 'Check that function arguments are of correct type',
385
+ * // 'Ensure objects have expected properties'
386
+ * // ],
387
+ * // timestamp: 2024-01-15T10:30:45.123Z
388
+ * // }
389
+ * ```
390
+ *
391
+ * ```typescript
392
+ * // Network timeout
393
+ * const error = new Error('ETIMEDOUT: connection timed out');
394
+ * const formatted = formatErrorForUser(error, { code: ErrorCode.ETIMEDOUT });
395
+ * // {
396
+ * // code: 'ETIMEDOUT',
397
+ * // message: 'Request timed out. Please try again.',
398
+ * // suggestions: [
399
+ * // 'Check your internet connection',
400
+ * // 'Try again in a few moments',
401
+ * // 'Verify the server is online'
402
+ * // ],
403
+ * // timestamp: 2024-01-15T10:30:45.123Z
404
+ * // }
405
+ * ```
406
+ *
407
+ * @usage
408
+ * ```typescript
409
+ * // In Express middleware
410
+ * app.use((err, req, res, next) => {
411
+ * const formatted = formatErrorForUser(err);
412
+ *
413
+ * // Log full technical details
414
+ * internalLogger.error(formatted.technicalDetails);
415
+ *
416
+ * // Send user-friendly response
417
+ * res.status(500).json({
418
+ * error: formatted.message,
419
+ * code: formatted.code,
420
+ * suggestions: formatted.suggestions
421
+ * });
422
+ * });
423
+ *
424
+ * // In CLI applications
425
+ * async function main() {
426
+ * try {
427
+ * await performAction();
428
+ * } catch (error) {
429
+ * const formatted = formatErrorForUser(error);
430
+ * console.error(`Error: ${formatted.message}`);
431
+ * console.error('Recovery steps:');
432
+ * formatted.suggestions.forEach((s, i) => {
433
+ * console.error(` ${i + 1}. ${s}`);
434
+ * });
435
+ * process.exit(1);
436
+ * }
437
+ * }
438
+ *
439
+ * // In React components
440
+ * function ErrorBoundary(props: any) {
441
+ * const [error, setError] = React.useState<FormattedError | null>(null);
442
+ *
443
+ * if (error) {
444
+ * const formatted = formatErrorForUser(error.originalError);
445
+ * return (
446
+ * <ErrorDisplay
447
+ * message={formatted.message}
448
+ * suggestions={formatted.suggestions}
449
+ * onRetry={retry}
450
+ * />
451
+ * );
452
+ * }
453
+ * }
454
+ * ```
455
+ */
456
+ export declare function formatErrorForUser(error: unknown, options?: {
457
+ code?: string;
458
+ includeStack?: boolean;
459
+ sanitize?: boolean;
460
+ }): FormattedError;
461
+ /**
462
+ * Wraps a promise to handle errors gracefully.
463
+ *
464
+ * Returns [data, error] tuple similar to Go's error handling pattern.
465
+ * Makes error handling explicit and type-safe.
466
+ *
467
+ * @param promise - Promise to wrap
468
+ * @returns Tuple of [data, error]
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * const [data, error] = await handlePromise(fetch('/api/users'));
473
+ *
474
+ * if (error) {
475
+ * const formatted = formatErrorForUser(error);
476
+ * showErrorNotification(formatted.message);
477
+ * return;
478
+ * }
479
+ *
480
+ * // data is guaranteed to exist here
481
+ * processUsers(data);
482
+ * ```
483
+ *
484
+ * @usage
485
+ * ```typescript
486
+ * // Cleaner async/await error handling
487
+ * async function loadUserData(userId: string) {
488
+ * const [user, error] = await handlePromise(
489
+ * fetch(`/api/users/${userId}`).then(r => r.json())
490
+ * );
491
+ *
492
+ * if (error) {
493
+ * return { success: false, error: formatErrorForUser(error) };
494
+ * }
495
+ *
496
+ * return { success: true, data: user };
497
+ * }
498
+ * ```
499
+ */
500
+ export declare function handlePromise<T>(promise: Promise<T>): Promise<[T | null, Error | null]>;
501
+ /**
502
+ * Retries an operation with exponential backoff.
503
+ *
504
+ * Useful for transient failures (network issues, temporary unavailability).
505
+ *
506
+ * @param fn - Async function to retry
507
+ * @param maxAttempts - Maximum number of attempts (default: 3)
508
+ * @param baseDelay - Base delay in milliseconds (default: 1000)
509
+ * @returns Promise that resolves with function result or rejects with last error
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * const data = await retryWithBackoff(
514
+ * () => fetch('/api/data').then(r => r.json()),
515
+ * 3,
516
+ * 1000
517
+ * );
518
+ * // Attempts:
519
+ * // 1. Immediately
520
+ * // 2. After ~1000ms
521
+ * // 3. After ~2000ms
522
+ * ```
523
+ *
524
+ * @usage
525
+ * ```typescript
526
+ * // Resilient API calls
527
+ * async function fetchUserWithRetry(userId: string) {
528
+ * return retryWithBackoff(
529
+ * async () => {
530
+ * const response = await fetch(`/api/users/${userId}`);
531
+ * if (!response.ok) throw new Error('API error');
532
+ * return response.json();
533
+ * },
534
+ * 3,
535
+ * 1000
536
+ * );
537
+ * }
538
+ * ```
539
+ */
540
+ export declare function retryWithBackoff<T>(fn: () => Promise<T>, maxAttempts?: number, baseDelay?: number): Promise<T>;
541
+ //# sourceMappingURL=error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAEH;;;;;;;;;;;;;GAaG;AACH,oBAAY,SAAS;IAEnB,OAAO,SAAS;IAChB,UAAU,SAAS;IACnB,MAAM,SAAS;IACf,UAAU,SAAS;IACnB,SAAS,SAAS;IAClB,OAAO,SAAS;IAChB,OAAO,SAAS;IAChB,WAAW,SAAS;IAGpB,MAAM,WAAW,CAAU,oBAAoB;IAC/C,MAAM,WAAW,CAAU,cAAc;IACzC,MAAM,WAAW,CAAU,iBAAiB;IAC5C,MAAM,WAAW,CAAU,4BAA4B;IACvD,OAAO,YAAY,CAAQ,kBAAkB;IAC7C,KAAK,UAAU,CAAY,0BAA0B;IACrD,SAAS,cAAc,CAAI,uBAAuB;IAClD,YAAY,iBAAiB;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAStD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASxD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAwB5D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAY1D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,EAAE,CAiEV;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqHG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IACR,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GACA,cAAc,CAgDhB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,aAAa,CAAC,CAAC,EACnC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAClB,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC,CAQnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,WAAW,GAAE,MAAU,EACvB,SAAS,GAAE,MAAa,GACvB,OAAO,CAAC,CAAC,CAAC,CAiBZ"}