@hypercli/core 0.1.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.
Files changed (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/config/config-loader.d.ts +117 -0
  4. package/dist/config/config-loader.d.ts.map +1 -0
  5. package/dist/config/config-loader.js +287 -0
  6. package/dist/config/config-loader.js.map +1 -0
  7. package/dist/config/index.d.ts +9 -0
  8. package/dist/config/index.d.ts.map +1 -0
  9. package/dist/config/index.js +8 -0
  10. package/dist/config/index.js.map +1 -0
  11. package/dist/config/load-helpers.d.ts +13 -0
  12. package/dist/config/load-helpers.d.ts.map +1 -0
  13. package/dist/config/load-helpers.js +67 -0
  14. package/dist/config/load-helpers.js.map +1 -0
  15. package/dist/constants.d.ts +4 -0
  16. package/dist/constants.d.ts.map +1 -0
  17. package/dist/constants.js +4 -0
  18. package/dist/constants.js.map +1 -0
  19. package/dist/errors/hypergen-errors.d.ts +162 -0
  20. package/dist/errors/hypergen-errors.d.ts.map +1 -0
  21. package/dist/errors/hypergen-errors.js +944 -0
  22. package/dist/errors/hypergen-errors.js.map +1 -0
  23. package/dist/errors/index.d.ts +2 -0
  24. package/dist/errors/index.d.ts.map +1 -0
  25. package/dist/errors/index.js +2 -0
  26. package/dist/errors/index.js.map +1 -0
  27. package/dist/helpers.d.ts +25 -0
  28. package/dist/helpers.d.ts.map +1 -0
  29. package/dist/helpers.js +20 -0
  30. package/dist/helpers.js.map +1 -0
  31. package/dist/index.d.ts +10 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +13 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/logger/cli-html-types.d.ts +36 -0
  36. package/dist/logger/cli-html-types.d.ts.map +1 -0
  37. package/dist/logger/cli-html-types.js +2 -0
  38. package/dist/logger/cli-html-types.js.map +1 -0
  39. package/dist/logger/index.d.ts +3 -0
  40. package/dist/logger/index.d.ts.map +1 -0
  41. package/dist/logger/index.js +3 -0
  42. package/dist/logger/index.js.map +1 -0
  43. package/dist/logger/logger.d.ts +17 -0
  44. package/dist/logger/logger.d.ts.map +1 -0
  45. package/dist/logger/logger.js +42 -0
  46. package/dist/logger/logger.js.map +1 -0
  47. package/dist/logger/types.d.ts +16 -0
  48. package/dist/logger/types.d.ts.map +1 -0
  49. package/dist/logger/types.js +2 -0
  50. package/dist/logger/types.js.map +1 -0
  51. package/dist/parsers/cookbook-parser.d.ts +30 -0
  52. package/dist/parsers/cookbook-parser.d.ts.map +1 -0
  53. package/dist/parsers/cookbook-parser.js +155 -0
  54. package/dist/parsers/cookbook-parser.js.map +1 -0
  55. package/dist/parsers/index.d.ts +10 -0
  56. package/dist/parsers/index.d.ts.map +1 -0
  57. package/dist/parsers/index.js +16 -0
  58. package/dist/parsers/index.js.map +1 -0
  59. package/dist/parsers/kit-parser.d.ts +44 -0
  60. package/dist/parsers/kit-parser.d.ts.map +1 -0
  61. package/dist/parsers/kit-parser.js +195 -0
  62. package/dist/parsers/kit-parser.js.map +1 -0
  63. package/dist/parsers/path-resolver.d.ts +72 -0
  64. package/dist/parsers/path-resolver.d.ts.map +1 -0
  65. package/dist/parsers/path-resolver.js +281 -0
  66. package/dist/parsers/path-resolver.js.map +1 -0
  67. package/dist/parsers/template-parser.d.ts +142 -0
  68. package/dist/parsers/template-parser.d.ts.map +1 -0
  69. package/dist/parsers/template-parser.js +896 -0
  70. package/dist/parsers/template-parser.js.map +1 -0
  71. package/dist/types/actions.d.ts +109 -0
  72. package/dist/types/actions.d.ts.map +1 -0
  73. package/dist/types/actions.js +31 -0
  74. package/dist/types/actions.js.map +1 -0
  75. package/dist/types/ai-config.d.ts +170 -0
  76. package/dist/types/ai-config.d.ts.map +1 -0
  77. package/dist/types/ai-config.js +10 -0
  78. package/dist/types/ai-config.js.map +1 -0
  79. package/dist/types/common.d.ts +24 -0
  80. package/dist/types/common.d.ts.map +1 -0
  81. package/dist/types/common.js +10 -0
  82. package/dist/types/common.js.map +1 -0
  83. package/dist/types/index.d.ts +19 -0
  84. package/dist/types/index.d.ts.map +1 -0
  85. package/dist/types/index.js +11 -0
  86. package/dist/types/index.js.map +1 -0
  87. package/dist/types/kit.d.ts +92 -0
  88. package/dist/types/kit.d.ts.map +1 -0
  89. package/dist/types/kit.js +17 -0
  90. package/dist/types/kit.js.map +1 -0
  91. package/dist/types/recipe.d.ts +953 -0
  92. package/dist/types/recipe.d.ts.map +1 -0
  93. package/dist/types/recipe.js +92 -0
  94. package/dist/types/recipe.js.map +1 -0
  95. package/dist/types/template.d.ts +49 -0
  96. package/dist/types/template.d.ts.map +1 -0
  97. package/dist/types/template.js +7 -0
  98. package/dist/types/template.js.map +1 -0
  99. package/dist/ui/index.d.ts +4 -0
  100. package/dist/ui/index.d.ts.map +1 -0
  101. package/dist/ui/index.js +4 -0
  102. package/dist/ui/index.js.map +1 -0
  103. package/dist/ui/messages.d.ts +16 -0
  104. package/dist/ui/messages.d.ts.map +1 -0
  105. package/dist/ui/messages.js +57 -0
  106. package/dist/ui/messages.js.map +1 -0
  107. package/dist/ui/styles.d.ts +7 -0
  108. package/dist/ui/styles.d.ts.map +1 -0
  109. package/dist/ui/styles.js +8 -0
  110. package/dist/ui/styles.js.map +1 -0
  111. package/dist/ui/symbols.d.ts +9 -0
  112. package/dist/ui/symbols.d.ts.map +1 -0
  113. package/dist/ui/symbols.js +10 -0
  114. package/dist/ui/symbols.js.map +1 -0
  115. package/dist/utils/display-utils.d.ts +65 -0
  116. package/dist/utils/display-utils.d.ts.map +1 -0
  117. package/dist/utils/display-utils.js +101 -0
  118. package/dist/utils/display-utils.js.map +1 -0
  119. package/dist/utils/find-project-root.d.ts +32 -0
  120. package/dist/utils/find-project-root.d.ts.map +1 -0
  121. package/dist/utils/find-project-root.js +133 -0
  122. package/dist/utils/find-project-root.js.map +1 -0
  123. package/dist/utils/index.d.ts +4 -0
  124. package/dist/utils/index.d.ts.map +1 -0
  125. package/dist/utils/index.js +4 -0
  126. package/dist/utils/index.js.map +1 -0
  127. package/dist/utils/newline.d.ts +3 -0
  128. package/dist/utils/newline.d.ts.map +1 -0
  129. package/dist/utils/newline.js +12 -0
  130. package/dist/utils/newline.js.map +1 -0
  131. package/package.json +83 -0
@@ -0,0 +1,944 @@
1
+ /**
2
+ * Hypergen Error System
3
+ *
4
+ * Provides comprehensive error handling with user-friendly messages
5
+ * and actionable guidance for common issues
6
+ */
7
+ import { renderMarkdown } from "@hypercli/ui/help";
8
+ export var ErrorCode;
9
+ (function (ErrorCode) {
10
+ // Configuration errors
11
+ ErrorCode["CONFIG_FILE_NOT_FOUND"] = "CONFIG_FILE_NOT_FOUND";
12
+ ErrorCode["CONFIG_INVALID_FORMAT"] = "CONFIG_INVALID_FORMAT";
13
+ ErrorCode["CONFIG_MISSING_REQUIRED"] = "CONFIG_MISSING_REQUIRED";
14
+ // Template errors
15
+ ErrorCode["TEMPLATE_NOT_FOUND"] = "TEMPLATE_NOT_FOUND";
16
+ ErrorCode["TEMPLATE_INVALID_SYNTAX"] = "TEMPLATE_INVALID_SYNTAX";
17
+ ErrorCode["TEMPLATE_MISSING_VARIABLES"] = "TEMPLATE_MISSING_VARIABLES";
18
+ ErrorCode["TEMPLATE_INVALID_FRONTMATTER"] = "TEMPLATE_INVALID_FRONTMATTER";
19
+ ErrorCode["TEMPLATE_PARSING_ERROR"] = "TEMPLATE_PARSING_ERROR";
20
+ ErrorCode["TEMPLATE_EXECUTION_ERROR"] = "TEMPLATE_EXECUTION_ERROR";
21
+ // Action errors
22
+ ErrorCode["ACTION_NOT_FOUND"] = "ACTION_NOT_FOUND";
23
+ ErrorCode["ACTION_EXECUTION_FAILED"] = "ACTION_EXECUTION_FAILED";
24
+ ErrorCode["ACTION_INVALID_PARAMETERS"] = "ACTION_INVALID_PARAMETERS";
25
+ ErrorCode["ACTION_MISSING_REQUIRED_PARAM"] = "ACTION_MISSING_REQUIRED_PARAM";
26
+ ErrorCode["ACTION_INVALID_PARAM_TYPE"] = "ACTION_INVALID_PARAM_TYPE";
27
+ ErrorCode["ACTION_INVALID_PARAM_VALUE"] = "ACTION_INVALID_PARAM_VALUE";
28
+ // CodeMod errors
29
+ ErrorCode["CODEMOD_NOT_FOUND"] = "CODEMOD_NOT_FOUND";
30
+ ErrorCode["CODEMOD_EXECUTION_FAILED"] = "CODEMOD_EXECUTION_FAILED";
31
+ ErrorCode["CODEMOD_INVALID_PARAMETERS"] = "CODEMOD_INVALID_PARAMETERS";
32
+ ErrorCode["CODEMOD_TRANSFORMATION_FAILED"] = "CODEMOD_TRANSFORMATION_FAILED";
33
+ ErrorCode["CODEMOD_SYNTAX_ERROR"] = "CODEMOD_SYNTAX_ERROR";
34
+ ErrorCode["CODEMOD_AST_PARSING_ERROR"] = "CODEMOD_AST_PARSING_ERROR";
35
+ ErrorCode["CODEMOD_BACKUP_FAILED"] = "CODEMOD_BACKUP_FAILED";
36
+ ErrorCode["CODEMOD_FILE_NOT_FOUND"] = "CODEMOD_FILE_NOT_FOUND";
37
+ // File system errors
38
+ ErrorCode["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
39
+ ErrorCode["FILE_PERMISSION_DENIED"] = "FILE_PERMISSION_DENIED";
40
+ ErrorCode["FILE_ALREADY_EXISTS"] = "FILE_ALREADY_EXISTS";
41
+ ErrorCode["DIRECTORY_NOT_FOUND"] = "DIRECTORY_NOT_FOUND";
42
+ ErrorCode["DIRECTORY_NOT_EMPTY"] = "DIRECTORY_NOT_EMPTY";
43
+ // Generator discovery errors
44
+ ErrorCode["GENERATOR_NOT_FOUND"] = "GENERATOR_NOT_FOUND";
45
+ ErrorCode["GENERATOR_INVALID_STRUCTURE"] = "GENERATOR_INVALID_STRUCTURE";
46
+ ErrorCode["GENERATOR_MISSING_METADATA"] = "GENERATOR_MISSING_METADATA";
47
+ // URL resolution errors
48
+ ErrorCode["URL_INVALID_FORMAT"] = "URL_INVALID_FORMAT";
49
+ ErrorCode["URL_RESOLUTION_FAILED"] = "URL_RESOLUTION_FAILED";
50
+ ErrorCode["URL_FETCH_FAILED"] = "URL_FETCH_FAILED";
51
+ // Network errors
52
+ ErrorCode["NETWORK_CONNECTION_FAILED"] = "NETWORK_CONNECTION_FAILED";
53
+ ErrorCode["NETWORK_TIMEOUT"] = "NETWORK_TIMEOUT";
54
+ ErrorCode["NETWORK_UNAUTHORIZED"] = "NETWORK_UNAUTHORIZED";
55
+ // AI errors
56
+ ErrorCode["AI_API_KEY_MISSING"] = "AI_API_KEY_MISSING";
57
+ ErrorCode["AI_PROVIDER_UNAVAILABLE"] = "AI_PROVIDER_UNAVAILABLE";
58
+ ErrorCode["AI_GENERATION_FAILED"] = "AI_GENERATION_FAILED";
59
+ ErrorCode["AI_BUDGET_EXCEEDED"] = "AI_BUDGET_EXCEEDED";
60
+ ErrorCode["AI_SCHEMA_VALIDATION_FAILED"] = "AI_SCHEMA_VALIDATION_FAILED";
61
+ ErrorCode["AI_SYNTAX_VALIDATION_FAILED"] = "AI_SYNTAX_VALIDATION_FAILED";
62
+ ErrorCode["AI_IMPORT_VALIDATION_FAILED"] = "AI_IMPORT_VALIDATION_FAILED";
63
+ ErrorCode["AI_RATE_LIMITED"] = "AI_RATE_LIMITED";
64
+ ErrorCode["AI_CONTEXT_TOO_LARGE"] = "AI_CONTEXT_TOO_LARGE";
65
+ ErrorCode["AI_TRANSPORT_FAILED"] = "AI_TRANSPORT_FAILED";
66
+ // General errors
67
+ ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
68
+ ErrorCode["INTERNAL_ERROR"] = "INTERNAL_ERROR";
69
+ ErrorCode["VALIDATION_ERROR"] = "VALIDATION_ERROR";
70
+ })(ErrorCode || (ErrorCode = {}));
71
+ export class HypergenError extends Error {
72
+ code;
73
+ context;
74
+ suggestions;
75
+ isUserError;
76
+ severity;
77
+ constructor(code, message, context = {}, suggestions = [], isUserError = true, severity = "medium") {
78
+ super(message);
79
+ this.name = "HypergenError";
80
+ this.code = code;
81
+ this.context = context;
82
+ this.suggestions = suggestions;
83
+ this.isUserError = isUserError;
84
+ this.severity = severity;
85
+ }
86
+ }
87
+ export class ErrorHandler {
88
+ static ERROR_MESSAGES = {
89
+ [ErrorCode.CONFIG_FILE_NOT_FOUND]: "Configuration file not found",
90
+ [ErrorCode.CONFIG_INVALID_FORMAT]: "Configuration file has invalid format",
91
+ [ErrorCode.CONFIG_MISSING_REQUIRED]: "Configuration is missing required fields",
92
+ [ErrorCode.TEMPLATE_NOT_FOUND]: "Template file not found",
93
+ [ErrorCode.TEMPLATE_INVALID_SYNTAX]: "Template has invalid syntax",
94
+ [ErrorCode.TEMPLATE_MISSING_VARIABLES]: "Template is missing required variables",
95
+ [ErrorCode.TEMPLATE_INVALID_FRONTMATTER]: "Template has invalid frontmatter",
96
+ [ErrorCode.TEMPLATE_PARSING_ERROR]: "Template parsing failed",
97
+ [ErrorCode.TEMPLATE_EXECUTION_ERROR]: "Template execution failed",
98
+ [ErrorCode.ACTION_NOT_FOUND]: "Action not found",
99
+ [ErrorCode.ACTION_EXECUTION_FAILED]: "Action execution failed",
100
+ [ErrorCode.ACTION_INVALID_PARAMETERS]: "Action has invalid parameters",
101
+ [ErrorCode.ACTION_MISSING_REQUIRED_PARAM]: "Action is missing required parameter",
102
+ [ErrorCode.ACTION_INVALID_PARAM_TYPE]: "Action parameter has invalid type",
103
+ [ErrorCode.ACTION_INVALID_PARAM_VALUE]: "Action parameter has invalid value",
104
+ [ErrorCode.CODEMOD_NOT_FOUND]: "CodeMod not found",
105
+ [ErrorCode.CODEMOD_EXECUTION_FAILED]: "CodeMod execution failed",
106
+ [ErrorCode.CODEMOD_INVALID_PARAMETERS]: "CodeMod has invalid parameters",
107
+ [ErrorCode.CODEMOD_TRANSFORMATION_FAILED]: "CodeMod transformation failed",
108
+ [ErrorCode.CODEMOD_SYNTAX_ERROR]: "CodeMod has syntax error",
109
+ [ErrorCode.CODEMOD_AST_PARSING_ERROR]: "CodeMod AST parsing failed",
110
+ [ErrorCode.CODEMOD_BACKUP_FAILED]: "CodeMod backup creation failed",
111
+ [ErrorCode.CODEMOD_FILE_NOT_FOUND]: "CodeMod file not found",
112
+ [ErrorCode.FILE_NOT_FOUND]: "File not found",
113
+ [ErrorCode.FILE_PERMISSION_DENIED]: "Permission denied",
114
+ [ErrorCode.FILE_ALREADY_EXISTS]: "File already exists",
115
+ [ErrorCode.DIRECTORY_NOT_FOUND]: "Directory not found",
116
+ [ErrorCode.DIRECTORY_NOT_EMPTY]: "Directory is not empty",
117
+ [ErrorCode.GENERATOR_NOT_FOUND]: "Generator not found",
118
+ [ErrorCode.GENERATOR_INVALID_STRUCTURE]: "Generator has invalid structure",
119
+ [ErrorCode.GENERATOR_MISSING_METADATA]: "Generator is missing metadata",
120
+ [ErrorCode.URL_INVALID_FORMAT]: "URL has invalid format",
121
+ [ErrorCode.URL_RESOLUTION_FAILED]: "URL resolution failed",
122
+ [ErrorCode.URL_FETCH_FAILED]: "Failed to fetch URL",
123
+ [ErrorCode.NETWORK_CONNECTION_FAILED]: "Network connection failed",
124
+ [ErrorCode.NETWORK_TIMEOUT]: "Network request timed out",
125
+ [ErrorCode.NETWORK_UNAUTHORIZED]: "Network request unauthorized",
126
+ [ErrorCode.AI_API_KEY_MISSING]: "AI provider API key is not configured",
127
+ [ErrorCode.AI_PROVIDER_UNAVAILABLE]: "AI provider is unavailable",
128
+ [ErrorCode.AI_GENERATION_FAILED]: "AI code generation failed",
129
+ [ErrorCode.AI_BUDGET_EXCEEDED]: "AI cost budget exceeded",
130
+ [ErrorCode.AI_SCHEMA_VALIDATION_FAILED]: "AI output failed schema validation",
131
+ [ErrorCode.AI_SYNTAX_VALIDATION_FAILED]: "AI output has syntax errors",
132
+ [ErrorCode.AI_IMPORT_VALIDATION_FAILED]: "AI output contains invalid imports",
133
+ [ErrorCode.AI_RATE_LIMITED]: "AI provider rate limit exceeded",
134
+ [ErrorCode.AI_CONTEXT_TOO_LARGE]: "AI context exceeds token budget",
135
+ [ErrorCode.AI_TRANSPORT_FAILED]: "AI transport resolution failed",
136
+ [ErrorCode.UNKNOWN_ERROR]: "Unknown error occurred",
137
+ [ErrorCode.INTERNAL_ERROR]: "Internal error occurred",
138
+ [ErrorCode.VALIDATION_ERROR]: "Validation error occurred",
139
+ };
140
+ static ERROR_SUGGESTIONS = {
141
+ [ErrorCode.CONFIG_FILE_NOT_FOUND]: [
142
+ {
143
+ title: "Create configuration file",
144
+ description: "Create a hypergen.config.js file in your project root",
145
+ command: "hypergen init workspace",
146
+ },
147
+ {
148
+ title: "Check file path",
149
+ description: "Verify the configuration file path is correct",
150
+ },
151
+ ],
152
+ [ErrorCode.CONFIG_INVALID_FORMAT]: [
153
+ {
154
+ title: "Check configuration syntax",
155
+ description: "Verify the configuration file has valid syntax",
156
+ },
157
+ {
158
+ title: "See configuration examples",
159
+ description: "Look at working configuration examples",
160
+ url: "https://hypergen.dev/docs/configuration",
161
+ },
162
+ ],
163
+ [ErrorCode.CONFIG_MISSING_REQUIRED]: [
164
+ {
165
+ title: "Add required fields",
166
+ description: "Ensure all required configuration fields are present",
167
+ },
168
+ {
169
+ title: "Check documentation",
170
+ description: "See required configuration fields",
171
+ url: "https://hypergen.dev/docs/configuration",
172
+ },
173
+ ],
174
+ [ErrorCode.TEMPLATE_INVALID_SYNTAX]: [
175
+ {
176
+ title: "Check template syntax",
177
+ description: "Verify the template file has valid syntax",
178
+ },
179
+ {
180
+ title: "Validate template",
181
+ description: "Use the template validator",
182
+ command: "hypergen template validate <path>",
183
+ },
184
+ ],
185
+ [ErrorCode.TEMPLATE_MISSING_VARIABLES]: [
186
+ {
187
+ title: "Add required variables",
188
+ description: "Ensure all required template variables are defined",
189
+ },
190
+ {
191
+ title: "Check template documentation",
192
+ description: "See template variable requirements",
193
+ url: "https://hypergen.dev/docs/templates",
194
+ },
195
+ ],
196
+ [ErrorCode.TEMPLATE_INVALID_FRONTMATTER]: [
197
+ {
198
+ title: "Check frontmatter syntax",
199
+ description: "Verify the template frontmatter has valid YAML syntax",
200
+ },
201
+ {
202
+ title: "See frontmatter examples",
203
+ description: "Look at working frontmatter examples",
204
+ url: "https://hypergen.dev/docs/frontmatter",
205
+ },
206
+ ],
207
+ [ErrorCode.ACTION_EXECUTION_FAILED]: [
208
+ {
209
+ title: "Check action parameters",
210
+ description: "Verify all required parameters are provided",
211
+ },
212
+ {
213
+ title: "Check file permissions",
214
+ description: "Ensure you have write permissions to the target directory",
215
+ },
216
+ ],
217
+ [ErrorCode.ACTION_INVALID_PARAMETERS]: [
218
+ {
219
+ title: "Check parameter format",
220
+ description: "Verify all parameters have correct format and types",
221
+ },
222
+ {
223
+ title: "View action details",
224
+ description: "See parameter requirements",
225
+ command: "hypergen info <action-name>",
226
+ },
227
+ ],
228
+ [ErrorCode.ACTION_INVALID_PARAM_TYPE]: [
229
+ {
230
+ title: "Check parameter type",
231
+ description: "Verify the parameter has the correct type",
232
+ },
233
+ {
234
+ title: "View action details",
235
+ description: "See parameter type requirements",
236
+ command: "hypergen info <action-name>",
237
+ },
238
+ ],
239
+ [ErrorCode.ACTION_INVALID_PARAM_VALUE]: [
240
+ {
241
+ title: "Check parameter value",
242
+ description: "Verify the parameter value is valid",
243
+ },
244
+ {
245
+ title: "View action examples",
246
+ description: "See example parameter values",
247
+ command: "hypergen info <action-name>",
248
+ },
249
+ ],
250
+ [ErrorCode.FILE_ALREADY_EXISTS]: [
251
+ {
252
+ title: "Use different name",
253
+ description: "Choose a different name for the file",
254
+ },
255
+ {
256
+ title: "Use force option",
257
+ description: "Use --force to overwrite existing files",
258
+ },
259
+ ],
260
+ [ErrorCode.DIRECTORY_NOT_FOUND]: [
261
+ {
262
+ title: "Create directory",
263
+ description: "Create the target directory first",
264
+ },
265
+ {
266
+ title: "Check directory path",
267
+ description: "Verify the directory path is correct",
268
+ },
269
+ ],
270
+ [ErrorCode.DIRECTORY_NOT_EMPTY]: [
271
+ {
272
+ title: "Use different directory",
273
+ description: "Choose an empty directory",
274
+ },
275
+ {
276
+ title: "Clean directory",
277
+ description: "Remove files from the directory first",
278
+ },
279
+ ],
280
+ [ErrorCode.GENERATOR_INVALID_STRUCTURE]: [
281
+ {
282
+ title: "Check generator structure",
283
+ description: "Verify the generator follows the correct structure",
284
+ },
285
+ {
286
+ title: "Create new generator",
287
+ description: "Create a new generator with proper structure",
288
+ command: "hypergen init generator --name=my-generator",
289
+ },
290
+ ],
291
+ [ErrorCode.GENERATOR_MISSING_METADATA]: [
292
+ {
293
+ title: "Add generator metadata",
294
+ description: "Ensure the generator has required metadata",
295
+ },
296
+ {
297
+ title: "Check generator documentation",
298
+ description: "See generator metadata requirements",
299
+ url: "https://hypergen.dev/docs/generators",
300
+ },
301
+ ],
302
+ [ErrorCode.URL_FETCH_FAILED]: [
303
+ {
304
+ title: "Check internet connection",
305
+ description: "Verify you have an active internet connection",
306
+ },
307
+ {
308
+ title: "Check URL format",
309
+ description: "Verify the URL is correct and accessible",
310
+ },
311
+ ],
312
+ [ErrorCode.NETWORK_TIMEOUT]: [
313
+ {
314
+ title: "Try again",
315
+ description: "The request may succeed on retry",
316
+ },
317
+ {
318
+ title: "Check network connection",
319
+ description: "Verify your internet connection is stable",
320
+ },
321
+ ],
322
+ [ErrorCode.NETWORK_UNAUTHORIZED]: [
323
+ {
324
+ title: "Check authentication",
325
+ description: "Verify your credentials are correct",
326
+ },
327
+ {
328
+ title: "Check permissions",
329
+ description: "Ensure you have access to the resource",
330
+ },
331
+ ],
332
+ [ErrorCode.UNKNOWN_ERROR]: [
333
+ {
334
+ title: "Try again",
335
+ description: "The operation might succeed on retry",
336
+ },
337
+ {
338
+ title: "Check error details",
339
+ description: "Review the error message for specific issues",
340
+ },
341
+ ],
342
+ [ErrorCode.INTERNAL_ERROR]: [
343
+ {
344
+ title: "Report this issue",
345
+ description: "This might be a bug in Hypergen",
346
+ url: "https://github.com/svallory/hypergen/issues",
347
+ },
348
+ {
349
+ title: "Try again",
350
+ description: "The operation might succeed on retry",
351
+ },
352
+ ],
353
+ [ErrorCode.VALIDATION_ERROR]: [
354
+ {
355
+ title: "Check input format",
356
+ description: "Verify your input follows the expected format",
357
+ },
358
+ {
359
+ title: "See documentation",
360
+ description: "Check the documentation for requirements",
361
+ url: "https://hypergen.dev/docs",
362
+ },
363
+ ],
364
+ [ErrorCode.TEMPLATE_NOT_FOUND]: [
365
+ {
366
+ title: "Check template path",
367
+ description: "Verify the template file exists at the specified path",
368
+ },
369
+ {
370
+ title: "Create template",
371
+ description: "Create a new template file",
372
+ command: "hypergen init generator --name=my-template",
373
+ },
374
+ {
375
+ title: "List available templates",
376
+ description: "See all available templates",
377
+ command: "hypergen template list",
378
+ },
379
+ ],
380
+ [ErrorCode.TEMPLATE_PARSING_ERROR]: [
381
+ {
382
+ title: "Check template syntax",
383
+ description: "Verify the template.yml file has valid YAML syntax",
384
+ },
385
+ ],
386
+ [ErrorCode.TEMPLATE_EXECUTION_ERROR]: [
387
+ {
388
+ title: "Check template variables",
389
+ description: "Verify all required variables are provided",
390
+ },
391
+ ],
392
+ [ErrorCode.FILE_NOT_FOUND]: [
393
+ {
394
+ title: "Check file path",
395
+ description: "Verify the file exists at the specified path",
396
+ },
397
+ {
398
+ title: "Create the file",
399
+ description: "Create the missing file",
400
+ },
401
+ ],
402
+ [ErrorCode.URL_RESOLUTION_FAILED]: [
403
+ {
404
+ title: "Check URL format",
405
+ description: "Verify the URL follows the correct format",
406
+ },
407
+ {
408
+ title: "Check internet connection",
409
+ description: "Verify you have an active internet connection",
410
+ },
411
+ ],
412
+ [ErrorCode.ACTION_NOT_FOUND]: [
413
+ {
414
+ title: "List available actions",
415
+ description: "See all available actions",
416
+ command: "hypergen list",
417
+ },
418
+ {
419
+ title: "Discover generators",
420
+ description: "Run discovery to find available generators",
421
+ command: "hypergen discover",
422
+ },
423
+ {
424
+ title: "Create new action",
425
+ description: "Create a new action generator",
426
+ command: "hypergen init generator --name=my-action",
427
+ },
428
+ ],
429
+ [ErrorCode.ACTION_MISSING_REQUIRED_PARAM]: [
430
+ {
431
+ title: "Check required parameters",
432
+ description: "View action details to see required parameters",
433
+ command: "hypergen info <action-name>",
434
+ },
435
+ {
436
+ title: "Use action examples",
437
+ description: "See example usage for this action",
438
+ command: "hypergen info <action-name>",
439
+ },
440
+ ],
441
+ [ErrorCode.FILE_PERMISSION_DENIED]: [
442
+ {
443
+ title: "Check file permissions",
444
+ description: "Ensure you have write permissions to the target directory",
445
+ },
446
+ {
447
+ title: "Run with sudo",
448
+ description: "Try running the command with elevated privileges (use caution)",
449
+ },
450
+ ],
451
+ [ErrorCode.GENERATOR_NOT_FOUND]: [
452
+ {
453
+ title: "Run discovery",
454
+ description: "Discover available generators",
455
+ command: "hypergen discover",
456
+ },
457
+ {
458
+ title: "Install generator",
459
+ description: "Install a generator package",
460
+ command: "npm install <generator-package>",
461
+ },
462
+ {
463
+ title: "Create generator",
464
+ description: "Create your own generator",
465
+ command: "hypergen init generator --name=my-generator",
466
+ },
467
+ ],
468
+ [ErrorCode.URL_INVALID_FORMAT]: [
469
+ {
470
+ title: "Check URL format",
471
+ description: "Ensure the URL follows the correct format (e.g., github:user/repo)",
472
+ },
473
+ {
474
+ title: "URL examples",
475
+ description: "Valid formats: github:user/repo, npm:package-name, file:./path",
476
+ url: "https://hypergen.dev/docs/url-templates",
477
+ },
478
+ ],
479
+ [ErrorCode.NETWORK_CONNECTION_FAILED]: [
480
+ {
481
+ title: "Check internet connection",
482
+ description: "Verify you have an active internet connection",
483
+ },
484
+ {
485
+ title: "Check proxy settings",
486
+ description: "Verify proxy configuration if behind a corporate firewall",
487
+ },
488
+ {
489
+ title: "Try again later",
490
+ description: "The remote server might be temporarily unavailable",
491
+ },
492
+ ],
493
+ [ErrorCode.CODEMOD_NOT_FOUND]: [
494
+ {
495
+ title: "Check CodeMod name",
496
+ description: "Verify the CodeMod identifier is correct and supported",
497
+ },
498
+ {
499
+ title: "View supported CodeMods",
500
+ description: "List of supported CodeMod types: add-import, add-export, modify-function, add-property, replace-text, custom",
501
+ },
502
+ ],
503
+ [ErrorCode.CODEMOD_EXECUTION_FAILED]: [
504
+ {
505
+ title: "Check file permissions",
506
+ description: "Ensure you have write permissions for the target files",
507
+ },
508
+ {
509
+ title: "Validate parameters",
510
+ description: "Check that all required parameters are provided and valid",
511
+ },
512
+ {
513
+ title: "Enable backup",
514
+ description: "Set backup: true to preserve original files before transformation",
515
+ },
516
+ ],
517
+ [ErrorCode.CODEMOD_INVALID_PARAMETERS]: [
518
+ {
519
+ title: "Check parameter requirements",
520
+ description: "Each CodeMod type has specific required parameters",
521
+ },
522
+ {
523
+ title: "See documentation",
524
+ description: "Review CodeMod parameter documentation",
525
+ url: "https://hypergen.dev/docs/codemods",
526
+ },
527
+ ],
528
+ [ErrorCode.CODEMOD_TRANSFORMATION_FAILED]: [
529
+ {
530
+ title: "Check file syntax",
531
+ description: "Ensure the target files have valid syntax",
532
+ },
533
+ {
534
+ title: "Simplify transformation",
535
+ description: "Try breaking complex transformations into smaller steps",
536
+ },
537
+ {
538
+ title: "Use text transformation",
539
+ description: "Consider using replace-text for simple changes instead of AST transformations",
540
+ },
541
+ ],
542
+ [ErrorCode.CODEMOD_SYNTAX_ERROR]: [
543
+ {
544
+ title: "Fix syntax errors",
545
+ description: "Resolve syntax errors in the target file before applying transformations",
546
+ },
547
+ ],
548
+ [ErrorCode.CODEMOD_AST_PARSING_ERROR]: [
549
+ {
550
+ title: "Use correct parser",
551
+ description: "Specify the correct parser for your file type (typescript, javascript, etc.)",
552
+ },
553
+ {
554
+ title: "Check file encoding",
555
+ description: "Ensure files are properly encoded (UTF-8)",
556
+ },
557
+ ],
558
+ [ErrorCode.CODEMOD_BACKUP_FAILED]: [
559
+ {
560
+ title: "Check disk space",
561
+ description: "Ensure sufficient disk space for backup files",
562
+ },
563
+ {
564
+ title: "Check permissions",
565
+ description: "Verify write permissions in the target directory",
566
+ },
567
+ ],
568
+ [ErrorCode.CODEMOD_FILE_NOT_FOUND]: [
569
+ {
570
+ title: "Check file patterns",
571
+ description: "Verify the file patterns match existing files",
572
+ },
573
+ {
574
+ title: "Use absolute paths",
575
+ description: "Consider using absolute paths or checking working directory",
576
+ },
577
+ ],
578
+ [ErrorCode.AI_API_KEY_MISSING]: [
579
+ {
580
+ title: "Add API key to .env file",
581
+ description: "Add the appropriate env var to your .env file (e.g., ANTHROPIC_API_KEY=sk-...)",
582
+ },
583
+ {
584
+ title: "Or set it as an environment variable",
585
+ description: "Export the env var in your shell (e.g., export ANTHROPIC_API_KEY=sk-...)",
586
+ },
587
+ {
588
+ title: "Custom env var name",
589
+ description: "Set ai.apiKeyEnvVar in hypergen.config.js to use a non-default env var name",
590
+ },
591
+ ],
592
+ [ErrorCode.AI_PROVIDER_UNAVAILABLE]: [
593
+ {
594
+ title: "Check internet connection",
595
+ description: "Verify you have an active internet connection",
596
+ },
597
+ {
598
+ title: "Install provider SDK",
599
+ description: "Install the provider SDK package (e.g., bun add @ai-sdk/anthropic)",
600
+ command: "bun add @ai-sdk/anthropic",
601
+ },
602
+ {
603
+ title: "Configure fallback models",
604
+ description: "Add fallbackModels in hypergen.config.js ai configuration",
605
+ },
606
+ ],
607
+ [ErrorCode.AI_GENERATION_FAILED]: [
608
+ {
609
+ title: "Check prompt",
610
+ description: "Review the prompt for clarity and completeness",
611
+ },
612
+ {
613
+ title: "Try a different model",
614
+ description: "Some models perform better for specific tasks",
615
+ },
616
+ {
617
+ title: "Increase temperature",
618
+ description: "Higher temperature may help with creative generation",
619
+ },
620
+ ],
621
+ [ErrorCode.AI_BUDGET_EXCEEDED]: [
622
+ {
623
+ title: "Increase budget",
624
+ description: "Raise maxTotalCostUsd in ai.budget configuration",
625
+ },
626
+ {
627
+ title: "Use a cheaper model",
628
+ description: "Switch to a more cost-effective model for bulk operations",
629
+ },
630
+ {
631
+ title: "Reduce context",
632
+ description: "Include fewer context files to reduce token usage",
633
+ },
634
+ ],
635
+ [ErrorCode.AI_SCHEMA_VALIDATION_FAILED]: [
636
+ {
637
+ title: "Check schema definition",
638
+ description: "Verify the output schema matches expected AI output format",
639
+ },
640
+ {
641
+ title: "Add examples",
642
+ description: "Provide few-shot examples to guide the model output format",
643
+ },
644
+ ],
645
+ [ErrorCode.AI_SYNTAX_VALIDATION_FAILED]: [
646
+ {
647
+ title: "Enable retry-with-feedback",
648
+ description: 'Set guardrails.onFailure to "retry-with-feedback" for automatic correction',
649
+ },
650
+ {
651
+ title: "Lower temperature",
652
+ description: "Lower temperature produces more deterministic, syntactically correct output",
653
+ },
654
+ ],
655
+ [ErrorCode.AI_IMPORT_VALIDATION_FAILED]: [
656
+ {
657
+ title: "Enable requireKnownImports",
658
+ description: "Set guardrails.requireKnownImports to validate imports against package.json",
659
+ },
660
+ {
661
+ title: "Specify allowedImports",
662
+ description: "Explicitly list allowed packages in guardrails.allowedImports",
663
+ },
664
+ ],
665
+ [ErrorCode.AI_RATE_LIMITED]: [
666
+ {
667
+ title: "Wait and retry",
668
+ description: "The rate limit will reset automatically. Hypergen retries with backoff.",
669
+ },
670
+ {
671
+ title: "Configure fallback provider",
672
+ description: "Add fallbackModels to switch providers when rate limited",
673
+ },
674
+ ],
675
+ [ErrorCode.AI_CONTEXT_TOO_LARGE]: [
676
+ {
677
+ title: "Reduce context files",
678
+ description: "Include fewer files in the context configuration",
679
+ },
680
+ {
681
+ title: "Set maxContextTokens",
682
+ description: "Configure context.maxContextTokens to limit context size",
683
+ },
684
+ {
685
+ title: "Use truncation",
686
+ description: 'Set context.overflow to "truncate" to automatically trim context',
687
+ },
688
+ ],
689
+ [ErrorCode.AI_TRANSPORT_FAILED]: [
690
+ {
691
+ title: "Check AI mode configuration",
692
+ description: "Verify ai.mode and related settings in hypergen.config.js",
693
+ },
694
+ {
695
+ title: "Use stdout mode",
696
+ description: "Fall back to --ai-mode stdout to print the prompt and resolve manually",
697
+ },
698
+ {
699
+ title: "Check command output",
700
+ description: "If using command mode, verify the command returns valid JSON",
701
+ },
702
+ ],
703
+ };
704
+ /**
705
+ * Create a user-friendly error with context and suggestions
706
+ */
707
+ static createError(code, customMessage, context = {}, customSuggestions = []) {
708
+ const baseMessage = ErrorHandler.ERROR_MESSAGES[code] || "Unknown error";
709
+ const message = customMessage || baseMessage;
710
+ const suggestions = customSuggestions.length > 0 ? customSuggestions : ErrorHandler.ERROR_SUGGESTIONS[code] || [];
711
+ return new HypergenError(code, message, context, suggestions);
712
+ }
713
+ /**
714
+ * Format error for display in CLI
715
+ */
716
+ static formatError(error) {
717
+ const lines = [];
718
+ // Error header
719
+ lines.push(`❌ ${error.message}`);
720
+ // Error code and severity
721
+ if (error.code !== ErrorCode.UNKNOWN_ERROR) {
722
+ lines.push(` Code: ${error.code}`);
723
+ }
724
+ // Context information
725
+ if (error.context.file) {
726
+ let location = ` File: ${error.context.file}`;
727
+ if (error.context.line) {
728
+ location += `:${error.context.line}`;
729
+ if (error.context.column) {
730
+ location += `:${error.context.column}`;
731
+ }
732
+ }
733
+ lines.push(location);
734
+ }
735
+ if (error.context.action) {
736
+ lines.push(` Action: ${error.context.action}`);
737
+ }
738
+ if (error.context.parameter) {
739
+ lines.push(` Parameter: ${error.context.parameter}`);
740
+ }
741
+ if (error.context.expected && error.context.received) {
742
+ lines.push(` Expected: ${error.context.expected}`);
743
+ lines.push(` Received: ${error.context.received}`);
744
+ }
745
+ // Suggestions — rendered as markdown for proper styling
746
+ if (error.suggestions.length > 0) {
747
+ const md = ["", "**Suggestions:**", ""];
748
+ for (const [index, suggestion] of error.suggestions.entries()) {
749
+ md.push(`${index + 1}. **${suggestion.title}**`);
750
+ md.push(` ${suggestion.description}`);
751
+ if (suggestion.command) {
752
+ md.push(` \`\`\`sh\n $ ${suggestion.command}\n \`\`\``);
753
+ }
754
+ if (suggestion.url) {
755
+ md.push(` [Documentation](${suggestion.url})`);
756
+ }
757
+ if (index < error.suggestions.length - 1) {
758
+ md.push("");
759
+ }
760
+ }
761
+ lines.push(renderMarkdown(md.join("\n")));
762
+ }
763
+ return lines.join("\n");
764
+ }
765
+ /**
766
+ * Handle and format any error for CLI display
767
+ */
768
+ static handleError(error) {
769
+ if (error instanceof HypergenError) {
770
+ return ErrorHandler.formatError(error);
771
+ }
772
+ if (error instanceof Error) {
773
+ // Try to categorize common Node.js errors
774
+ if (error.message.includes("ENOENT")) {
775
+ const hypergenError = ErrorHandler.createError(ErrorCode.FILE_NOT_FOUND, error.message, {
776
+ file: ErrorHandler.extractFileFromError(error.message),
777
+ });
778
+ return ErrorHandler.formatError(hypergenError);
779
+ }
780
+ if (error.message.includes("EACCES")) {
781
+ const hypergenError = ErrorHandler.createError(ErrorCode.FILE_PERMISSION_DENIED, error.message, { file: ErrorHandler.extractFileFromError(error.message) });
782
+ return ErrorHandler.formatError(hypergenError);
783
+ }
784
+ if (error.message.includes("EEXIST")) {
785
+ const hypergenError = ErrorHandler.createError(ErrorCode.FILE_ALREADY_EXISTS, error.message, { file: ErrorHandler.extractFileFromError(error.message) });
786
+ return ErrorHandler.formatError(hypergenError);
787
+ }
788
+ if (error.message.includes("ENOTDIR")) {
789
+ const hypergenError = ErrorHandler.createError(ErrorCode.DIRECTORY_NOT_FOUND, error.message, { file: ErrorHandler.extractFileFromError(error.message) });
790
+ return ErrorHandler.formatError(hypergenError);
791
+ }
792
+ // Generic error handling
793
+ const hypergenError = ErrorHandler.createError(ErrorCode.UNKNOWN_ERROR, error.message, {}, [
794
+ {
795
+ title: "Check the error details",
796
+ description: "Review the error message for specific issues",
797
+ },
798
+ ]);
799
+ return ErrorHandler.formatError(hypergenError);
800
+ }
801
+ // Unknown error type
802
+ const hypergenError = ErrorHandler.createError(ErrorCode.INTERNAL_ERROR, "An unexpected error occurred", {}, [
803
+ {
804
+ title: "Report this issue",
805
+ description: "This might be a bug in Hypergen",
806
+ url: "https://github.com/svallory/hypergen/issues",
807
+ },
808
+ ]);
809
+ return ErrorHandler.formatError(hypergenError);
810
+ }
811
+ /**
812
+ * Extract file path from error message
813
+ */
814
+ static extractFileFromError(message) {
815
+ const match = message.match(/(?:open|access|stat) '([^']+)'/);
816
+ return match ? match[1] : undefined;
817
+ }
818
+ /**
819
+ * Create parameter validation error
820
+ */
821
+ static createParameterError(parameter, value, expected, action) {
822
+ return ErrorHandler.createError(ErrorCode.ACTION_INVALID_PARAM_VALUE, `Invalid value for parameter '${parameter}'`, {
823
+ parameter,
824
+ value: String(value),
825
+ expected,
826
+ action,
827
+ }, [
828
+ {
829
+ title: "Check parameter format",
830
+ description: `Parameter '${parameter}' should be ${expected}`,
831
+ },
832
+ {
833
+ title: "View action details",
834
+ description: "See all parameters and their requirements",
835
+ command: action ? `hypergen info ${action}` : undefined,
836
+ },
837
+ ]);
838
+ }
839
+ /**
840
+ * Create template validation error
841
+ */
842
+ static createTemplateError(file, line, column, details) {
843
+ return ErrorHandler.createError(ErrorCode.TEMPLATE_INVALID_SYNTAX, `Template validation failed${details ? `: ${details}` : ""}`, { file, line, column }, [
844
+ {
845
+ title: "Check template syntax",
846
+ description: "Verify the template file has valid syntax",
847
+ },
848
+ {
849
+ title: "Validate template",
850
+ description: "Use the template validator",
851
+ command: `hypergen template validate ${file}`,
852
+ },
853
+ ]);
854
+ }
855
+ /**
856
+ * Create action not found error
857
+ */
858
+ static createActionNotFoundError(actionName) {
859
+ return ErrorHandler.createError(ErrorCode.ACTION_NOT_FOUND, `Action '${actionName}' not found`, { action: actionName }, [
860
+ {
861
+ title: "List available actions",
862
+ description: "See all available actions",
863
+ command: "hypergen list",
864
+ },
865
+ {
866
+ title: "Discover generators",
867
+ description: "Run discovery to find available generators",
868
+ command: "hypergen discover",
869
+ },
870
+ {
871
+ title: "Check spelling",
872
+ description: "Verify the action name is spelled correctly",
873
+ },
874
+ ]);
875
+ }
876
+ /**
877
+ * Create file operation error
878
+ */
879
+ static createFileError(operation, file, reason) {
880
+ let code = ErrorCode.FILE_NOT_FOUND;
881
+ if (reason.includes("permission")) {
882
+ code = ErrorCode.FILE_PERMISSION_DENIED;
883
+ }
884
+ else if (reason.includes("exists")) {
885
+ code = ErrorCode.FILE_ALREADY_EXISTS;
886
+ }
887
+ return ErrorHandler.createError(code, `Failed to ${operation} file '${file}': ${reason}`, {
888
+ file,
889
+ });
890
+ }
891
+ }
892
+ /**
893
+ * Utility function to wrap async operations with error handling
894
+ */
895
+ export async function withErrorHandling(operation, errorContext = {}) {
896
+ try {
897
+ return await operation();
898
+ }
899
+ catch (error) {
900
+ if (error instanceof HypergenError) {
901
+ // Add additional context to existing error
902
+ error.context = { ...error.context, ...errorContext };
903
+ throw error;
904
+ }
905
+ // Convert unknown errors to HypergenError
906
+ const hypergenError = ErrorHandler.createError(ErrorCode.UNKNOWN_ERROR, error instanceof Error ? error.message : String(error), errorContext);
907
+ throw hypergenError;
908
+ }
909
+ }
910
+ /**
911
+ * Utility function to validate parameters
912
+ */
913
+ export function validateParameter(name, value, type, required = false, pattern, allowedValues) {
914
+ if (required && (value === undefined || value === null || value === "")) {
915
+ throw ErrorHandler.createError(ErrorCode.ACTION_MISSING_REQUIRED_PARAM, `Required parameter '${name}' is missing`, { parameter: name });
916
+ }
917
+ if (value !== undefined && value !== null && value !== "") {
918
+ // Type validation
919
+ if (type === "string" && typeof value !== "string") {
920
+ throw ErrorHandler.createParameterError(name, value, "string");
921
+ }
922
+ if (type === "number" && typeof value !== "number") {
923
+ throw ErrorHandler.createParameterError(name, value, "number");
924
+ }
925
+ if (type === "boolean" && typeof value !== "boolean") {
926
+ throw ErrorHandler.createParameterError(name, value, "boolean");
927
+ }
928
+ if (type === "array" && !Array.isArray(value)) {
929
+ throw ErrorHandler.createParameterError(name, value, "array");
930
+ }
931
+ // Pattern validation
932
+ if (pattern && typeof value === "string") {
933
+ const regex = new RegExp(pattern);
934
+ if (!regex.test(value)) {
935
+ throw ErrorHandler.createParameterError(name, value, `string matching pattern ${pattern}`);
936
+ }
937
+ }
938
+ // Allowed values validation
939
+ if (allowedValues && !allowedValues.includes(value)) {
940
+ throw ErrorHandler.createParameterError(name, value, `one of: ${allowedValues.join(", ")}`);
941
+ }
942
+ }
943
+ }
944
+ //# sourceMappingURL=hypergen-errors.js.map