myshell-tools 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/LICENSE +21 -0
  3. package/README.md +318 -0
  4. package/data/orchestrator.json +113 -0
  5. package/package.json +49 -0
  6. package/src/auth/recovery.mjs +328 -0
  7. package/src/auth/refresh.mjs +373 -0
  8. package/src/chef.mjs +348 -0
  9. package/src/cli/doctor.mjs +568 -0
  10. package/src/cli/reset.mjs +447 -0
  11. package/src/cli/status.mjs +379 -0
  12. package/src/cli.mjs +429 -0
  13. package/src/commands/doctor.mjs +375 -0
  14. package/src/commands/help.mjs +324 -0
  15. package/src/commands/status.mjs +331 -0
  16. package/src/monitor/health.mjs +486 -0
  17. package/src/monitor/performance.mjs +442 -0
  18. package/src/monitor/report.mjs +535 -0
  19. package/src/orchestrator/classify.mjs +391 -0
  20. package/src/orchestrator/confidence.mjs +151 -0
  21. package/src/orchestrator/handoffs.mjs +231 -0
  22. package/src/orchestrator/review.mjs +222 -0
  23. package/src/providers/balance.mjs +201 -0
  24. package/src/providers/claude.mjs +236 -0
  25. package/src/providers/codex.mjs +255 -0
  26. package/src/providers/detect.mjs +185 -0
  27. package/src/providers/errors.mjs +373 -0
  28. package/src/providers/select.mjs +162 -0
  29. package/src/repl-enhanced.mjs +417 -0
  30. package/src/repl.mjs +321 -0
  31. package/src/state/archive.mjs +366 -0
  32. package/src/state/atomic.mjs +116 -0
  33. package/src/state/cleanup.mjs +440 -0
  34. package/src/state/recovery.mjs +461 -0
  35. package/src/state/session.mjs +147 -0
  36. package/src/ui/errors.mjs +456 -0
  37. package/src/ui/formatter.mjs +327 -0
  38. package/src/ui/icons.mjs +318 -0
  39. package/src/ui/progress.mjs +468 -0
  40. package/templates/prompts/confidence-format.txt +14 -0
  41. package/templates/prompts/ic-with-feedback.txt +41 -0
  42. package/templates/prompts/ic.txt +13 -0
  43. package/templates/prompts/manager-review.txt +40 -0
  44. package/templates/prompts/manager.txt +14 -0
  45. package/templates/prompts/worker.txt +12 -0
@@ -0,0 +1,456 @@
1
+ /**
2
+ * errors.mjs — Rich error displays with actionable solutions
3
+ */
4
+
5
+ import { fmt, box, createTree } from './formatter.mjs';
6
+ import { status, actions, health, files } from './icons.mjs';
7
+
8
+ /**
9
+ * Display a rich error with context and solutions
10
+ */
11
+ export function displayError(error, context = {}) {
12
+ const errorInfo = parseError(error);
13
+
14
+ // Header with error type
15
+ console.log(box(`${status.error} ${errorInfo.title}`, {
16
+ borderColor: fmt.red(''),
17
+ textColor: fmt.bold(''),
18
+ padding: 1,
19
+ margin: 1
20
+ }));
21
+
22
+ // Error message
23
+ if (errorInfo.message) {
24
+ console.log(`${fmt.red('Message:')} ${errorInfo.message}`);
25
+ console.log('');
26
+ }
27
+
28
+ // Context information
29
+ if (context.operation) {
30
+ console.log(`${fmt.dim('Operation:')} ${context.operation}`);
31
+ }
32
+ if (context.model) {
33
+ console.log(`${fmt.dim('Model:')} ${context.model.provider}/${context.model.model}`);
34
+ }
35
+ if (context.tier) {
36
+ console.log(`${fmt.dim('Tier:')} ${context.tier.toUpperCase()}`);
37
+ }
38
+
39
+ if (context.operation || context.model || context.tier) {
40
+ console.log('');
41
+ }
42
+
43
+ // Solutions
44
+ if (errorInfo.solutions.length > 0) {
45
+ console.log(fmt.bold('💡 Suggested Solutions:'));
46
+
47
+ const solutionTree = errorInfo.solutions.map((solution, index) => ({
48
+ text: `${fmt.cyan((index + 1) + '.')} ${solution.title}`,
49
+ children: solution.steps ? solution.steps.map(step => ({ text: fmt.dim(step) })) : []
50
+ }));
51
+
52
+ const tree = createTree(solutionTree);
53
+ tree.forEach(line => console.log(line));
54
+ console.log('');
55
+ }
56
+
57
+ // Quick commands
58
+ if (errorInfo.commands.length > 0) {
59
+ console.log(fmt.bold('🔧 Quick Commands:'));
60
+ for (const cmd of errorInfo.commands) {
61
+ console.log(` ${actions.configure} ${fmt.cyan(cmd.command)} ${fmt.dim('—')} ${cmd.description}`);
62
+ }
63
+ console.log('');
64
+ }
65
+
66
+ // Help information
67
+ if (errorInfo.helpUrl || errorInfo.helpCommand) {
68
+ console.log(fmt.bold('📖 Need More Help?'));
69
+ if (errorInfo.helpCommand) {
70
+ console.log(` Run: ${fmt.cyan(errorInfo.helpCommand)}`);
71
+ }
72
+ if (errorInfo.helpUrl) {
73
+ console.log(` Docs: ${fmt.cyan(errorInfo.helpUrl)}`);
74
+ }
75
+ console.log('');
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Parse error and categorize with solutions
81
+ */
82
+ function parseError(error) {
83
+ const message = error.message || String(error);
84
+
85
+ // Provider authentication errors
86
+ if (message.includes('not authenticated') || message.includes('invalid credentials')) {
87
+ return {
88
+ title: 'Authentication Error',
89
+ message: 'AI provider is not properly authenticated',
90
+ solutions: [
91
+ {
92
+ title: 'Authenticate Claude CLI',
93
+ steps: [
94
+ 'Run: claude auth login',
95
+ 'Follow the browser authentication flow',
96
+ 'Verify with: claude auth status'
97
+ ]
98
+ },
99
+ {
100
+ title: 'Authenticate Codex CLI',
101
+ steps: [
102
+ 'Run: codex login',
103
+ 'Enter your OpenAI API key',
104
+ 'Test with: codex --version'
105
+ ]
106
+ }
107
+ ],
108
+ commands: [
109
+ { command: 'cortex --doctor', description: 'Check authentication status' },
110
+ { command: 'cortex --status', description: 'Show provider health' }
111
+ ],
112
+ helpCommand: 'cortex --help',
113
+ helpUrl: null
114
+ };
115
+ }
116
+
117
+ // Provider not found errors
118
+ if (message.includes('command not found') || message.includes('not installed')) {
119
+ return {
120
+ title: 'Provider Not Found',
121
+ message: 'Required AI provider CLI is not installed',
122
+ solutions: [
123
+ {
124
+ title: 'Install Claude CLI',
125
+ steps: [
126
+ 'Run: pip install anthropic-cli',
127
+ 'Or: curl -fsSL https://claude.ai/install.sh | sh',
128
+ 'Verify with: claude --version'
129
+ ]
130
+ },
131
+ {
132
+ title: 'Install Codex CLI',
133
+ steps: [
134
+ 'Run: npm install -g @openai/codex',
135
+ 'Or: pip install openai-codex',
136
+ 'Verify with: codex --version'
137
+ ]
138
+ }
139
+ ],
140
+ commands: [
141
+ { command: 'cortex --doctor', description: 'Check provider installation' }
142
+ ],
143
+ helpCommand: 'cortex --doctor',
144
+ helpUrl: null
145
+ };
146
+ }
147
+
148
+ // Network/timeout errors
149
+ if (message.includes('timeout') || message.includes('network') || message.includes('ECONNREFUSED')) {
150
+ return {
151
+ title: 'Connection Error',
152
+ message: 'Unable to reach AI provider service',
153
+ solutions: [
154
+ {
155
+ title: 'Check Internet Connection',
156
+ steps: [
157
+ 'Verify you can reach external sites',
158
+ 'Check if you are behind a corporate firewall',
159
+ 'Try connecting to a different network'
160
+ ]
161
+ },
162
+ {
163
+ title: 'Check Provider Status',
164
+ steps: [
165
+ 'Visit status.anthropic.com for Claude',
166
+ 'Visit status.openai.com for OpenAI',
167
+ 'Wait for service restoration if there are issues'
168
+ ]
169
+ },
170
+ {
171
+ title: 'Retry Operation',
172
+ steps: [
173
+ 'Wait 30 seconds and try again',
174
+ 'Providers may have temporary rate limits'
175
+ ]
176
+ }
177
+ ],
178
+ commands: [
179
+ { command: 'cortex --status', description: 'Check system status' },
180
+ { command: 'ping anthropic.com', description: 'Test Claude connectivity' },
181
+ { command: 'ping api.openai.com', description: 'Test OpenAI connectivity' }
182
+ ],
183
+ helpCommand: 'cortex --doctor',
184
+ helpUrl: null
185
+ };
186
+ }
187
+
188
+ // Rate limit errors
189
+ if (message.includes('rate limit') || message.includes('quota exceeded') || message.includes('429')) {
190
+ return {
191
+ title: 'Rate Limit Exceeded',
192
+ message: 'AI provider rate limit has been reached',
193
+ solutions: [
194
+ {
195
+ title: 'Wait and Retry',
196
+ steps: [
197
+ 'Wait for rate limit window to reset',
198
+ 'Most limits reset within an hour',
199
+ 'Try again with simpler requests'
200
+ ]
201
+ },
202
+ {
203
+ title: 'Use Alternative Provider',
204
+ steps: [
205
+ 'Cortex can route to other available models',
206
+ 'Ensure both Claude and Codex are configured',
207
+ 'System will automatically balance load'
208
+ ]
209
+ },
210
+ {
211
+ title: 'Check Usage Patterns',
212
+ steps: [
213
+ 'Run: cortex --trends',
214
+ 'Review recent usage patterns',
215
+ 'Consider breaking large tasks into smaller ones'
216
+ ]
217
+ }
218
+ ],
219
+ commands: [
220
+ { command: 'cortex --trends', description: 'Check usage patterns' },
221
+ { command: 'cortex --status', description: 'Check provider balance' }
222
+ ],
223
+ helpCommand: 'cortex --help',
224
+ helpUrl: null
225
+ };
226
+ }
227
+
228
+ // File permission errors
229
+ if (message.includes('EACCES') || message.includes('permission denied')) {
230
+ return {
231
+ title: 'Permission Error',
232
+ message: 'Insufficient permissions to access files or directories',
233
+ solutions: [
234
+ {
235
+ title: 'Check Directory Permissions',
236
+ steps: [
237
+ 'Ensure you can write to the current directory',
238
+ 'Check .cortex directory permissions',
239
+ 'Run: ls -la .cortex'
240
+ ]
241
+ },
242
+ {
243
+ title: 'Fix Permissions',
244
+ steps: [
245
+ 'Run: chmod 755 .cortex',
246
+ 'Or: sudo chown -R $USER .cortex',
247
+ 'Retry the operation'
248
+ ]
249
+ }
250
+ ],
251
+ commands: [
252
+ { command: 'ls -la .cortex', description: 'Check directory permissions' },
253
+ { command: 'cortex --doctor', description: 'Run system health check' }
254
+ ],
255
+ helpCommand: 'cortex --doctor',
256
+ helpUrl: null
257
+ };
258
+ }
259
+
260
+ // Model not available errors
261
+ if (message.includes('model not available') || message.includes('no models')) {
262
+ return {
263
+ title: 'No Models Available',
264
+ message: 'No AI models are available for the requested tier',
265
+ solutions: [
266
+ {
267
+ title: 'Check Provider Authentication',
268
+ steps: [
269
+ 'Run: cortex --doctor',
270
+ 'Ensure at least one provider is authenticated',
271
+ 'Verify API keys are valid'
272
+ ]
273
+ },
274
+ {
275
+ title: 'Check Model Assignments',
276
+ steps: [
277
+ 'Verify models are correctly assigned to tiers',
278
+ 'Check provider health status',
279
+ 'Try with a different tier'
280
+ ]
281
+ }
282
+ ],
283
+ commands: [
284
+ { command: 'cortex --doctor', description: 'Check model availability' },
285
+ { command: 'cortex --status', description: 'Show tier assignments' }
286
+ ],
287
+ helpCommand: 'cortex --doctor',
288
+ helpUrl: null
289
+ };
290
+ }
291
+
292
+ // Session/state errors
293
+ if (message.includes('session') || message.includes('state')) {
294
+ return {
295
+ title: 'Session Error',
296
+ message: 'Problem with session state management',
297
+ solutions: [
298
+ {
299
+ title: 'Reset Session State',
300
+ steps: [
301
+ 'Run: cortex --reset sessions',
302
+ 'This will clear current session but keep history',
303
+ 'Start a new session'
304
+ ]
305
+ },
306
+ {
307
+ title: 'Clean State Files',
308
+ steps: [
309
+ 'Run: cortex --cleanup',
310
+ 'This will remove corrupted state files',
311
+ 'Keeps important data and settings'
312
+ ]
313
+ }
314
+ ],
315
+ commands: [
316
+ { command: 'cortex --reset sessions', description: 'Reset current session' },
317
+ { command: 'cortex --cleanup', description: 'Clean state files' },
318
+ { command: 'cortex --recovery', description: 'Show recovery options' }
319
+ ],
320
+ helpCommand: 'cortex --help',
321
+ helpUrl: null
322
+ };
323
+ }
324
+
325
+ // Generic error fallback
326
+ return {
327
+ title: 'Unexpected Error',
328
+ message: message,
329
+ solutions: [
330
+ {
331
+ title: 'Run System Diagnostics',
332
+ steps: [
333
+ 'Run: cortex --doctor',
334
+ 'Check for known issues and fixes',
335
+ 'Review system configuration'
336
+ ]
337
+ },
338
+ {
339
+ title: 'Reset if Needed',
340
+ steps: [
341
+ 'Try: cortex --cleanup',
342
+ 'If problem persists: cortex --reset state',
343
+ 'Last resort: cortex --reset all'
344
+ ]
345
+ }
346
+ ],
347
+ commands: [
348
+ { command: 'cortex --doctor', description: 'Comprehensive system check' },
349
+ { command: 'cortex --cleanup', description: 'Clean temporary files' }
350
+ ],
351
+ helpCommand: 'cortex --help',
352
+ helpUrl: null
353
+ };
354
+ }
355
+
356
+ /**
357
+ * Display a warning with context
358
+ */
359
+ export function displayWarning(message, context = {}) {
360
+ console.log(`${status.warning} ${fmt.warning(message)}`);
361
+
362
+ if (context.suggestion) {
363
+ console.log(` ${status.info} ${context.suggestion}`);
364
+ }
365
+
366
+ if (context.command) {
367
+ console.log(` ${fmt.dim('Try:')} ${fmt.cyan(context.command)}`);
368
+ }
369
+
370
+ console.log('');
371
+ }
372
+
373
+ /**
374
+ * Display an info message with context
375
+ */
376
+ export function displayInfo(message, context = {}) {
377
+ console.log(`${status.info} ${fmt.info(message)}`);
378
+
379
+ if (context.details) {
380
+ console.log(` ${fmt.dim(context.details)}`);
381
+ }
382
+
383
+ console.log('');
384
+ }
385
+
386
+ /**
387
+ * Display a success message with context
388
+ */
389
+ export function displaySuccess(message, context = {}) {
390
+ console.log(`${status.success} ${fmt.success(message)}`);
391
+
392
+ if (context.details) {
393
+ console.log(` ${fmt.dim(context.details)}`);
394
+ }
395
+
396
+ if (context.nextStep) {
397
+ console.log(` ${fmt.dim('Next:')} ${context.nextStep}`);
398
+ }
399
+
400
+ console.log('');
401
+ }
402
+
403
+ /**
404
+ * Create a formatted error box for critical errors
405
+ */
406
+ export function createErrorBox(title, message, options = {}) {
407
+ const content = [title];
408
+ if (message) {
409
+ content.push('');
410
+ content.push(message);
411
+ }
412
+
413
+ return box(content.join('\n'), {
414
+ borderColor: fmt.red(''),
415
+ textColor: options.color || fmt.bold(''),
416
+ padding: 1,
417
+ margin: options.margin || 1
418
+ });
419
+ }
420
+
421
+ /**
422
+ * Handle graceful error display with context preservation
423
+ */
424
+ export function handleError(error, context = {}) {
425
+ // Log the full error for debugging if verbose
426
+ if (process.env.DEBUG || process.argv.includes('--verbose')) {
427
+ console.error('Full error:', error);
428
+ }
429
+
430
+ // Display user-friendly error
431
+ displayError(error, context);
432
+
433
+ // Offer to run doctor if this looks like a system issue
434
+ if (isSystemIssue(error)) {
435
+ console.log(fmt.dim('💡 Tip: Run ') + fmt.cyan('cortex --doctor') + fmt.dim(' to diagnose system issues'));
436
+ console.log('');
437
+ }
438
+ }
439
+
440
+ /**
441
+ * Check if this looks like a system configuration issue
442
+ */
443
+ function isSystemIssue(error) {
444
+ const message = error.message || String(error);
445
+ const systemIndicators = [
446
+ 'not authenticated',
447
+ 'command not found',
448
+ 'not installed',
449
+ 'permission denied',
450
+ 'no models available',
451
+ 'EACCES',
452
+ 'ECONNREFUSED'
453
+ ];
454
+
455
+ return systemIndicators.some(indicator => message.includes(indicator));
456
+ }