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,331 @@
1
+ /**
2
+ * status.mjs — Live session metrics and system status display
3
+ */
4
+
5
+ import { getSessionSummary } from '../state/session.mjs';
6
+ import { detectEnvironment } from '../providers/detect.mjs';
7
+ import { fmt, box, separator, formatDuration, timeAgo, providerBalanceBar } from '../ui/formatter.mjs';
8
+ import { status, tier, session as sessionIcons, provider } from '../ui/icons.mjs';
9
+
10
+ /**
11
+ * Display comprehensive system status
12
+ */
13
+ export function displayStatus(workingDir, options = {}) {
14
+ const { verbose = false } = options;
15
+
16
+ console.log(box('Cortex Status Dashboard', {
17
+ borderColor: fmt.blue(''),
18
+ padding: 1,
19
+ margin: 1
20
+ }));
21
+
22
+ // Current Session
23
+ displayCurrentSession();
24
+
25
+ // System Status
26
+ displaySystemStatus();
27
+
28
+ // Provider Status
29
+ displayProviderStatus();
30
+
31
+ // Performance Metrics
32
+ displayPerformanceMetrics();
33
+
34
+ if (verbose) {
35
+ // Detailed Information
36
+ displayDetailedInfo(workingDir);
37
+ }
38
+
39
+ // Quick Actions
40
+ displayQuickActions();
41
+
42
+ console.log('');
43
+ }
44
+
45
+ /**
46
+ * Get quick status for minimal display
47
+ */
48
+ export function getQuickStatus() {
49
+ const sessionSummary = getSessionSummary();
50
+ const env = detectEnvironment();
51
+
52
+ const activeSession = sessionSummary.messageCount > 0;
53
+ const sessionIcon = activeSession ? sessionIcons.active : sessionIcons.new;
54
+ const providerCount = (env.claude.authed ? 1 : 0) + (env.codex.authed ? 1 : 0);
55
+
56
+ return {
57
+ session: {
58
+ active: activeSession,
59
+ messageCount: sessionSummary.messageCount,
60
+ duration: sessionSummary.duration || 0
61
+ },
62
+ providers: {
63
+ count: providerCount,
64
+ claude: env.claude.authed,
65
+ codex: env.codex.authed
66
+ },
67
+ status: providerCount > 0 ? 'ready' : 'needs_auth'
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Display current session information
73
+ */
74
+ function displayCurrentSession() {
75
+ const sessionSummary = getSessionSummary();
76
+
77
+ console.log(fmt.bold('\nšŸ’¬ Current Session:'));
78
+ console.log(separator(50, '─'));
79
+
80
+ if (sessionSummary.messageCount === 0) {
81
+ console.log(` ${sessionIcons.new} ${fmt.dim('No active session')}`);
82
+ console.log(` ${status.info} Start chatting to begin a new session`);
83
+ } else {
84
+ const sessionStatus = sessionIcons.active;
85
+ const duration = sessionSummary.duration ? formatDuration(sessionSummary.duration) : 'Unknown';
86
+ const lastActivity = sessionSummary.lastMessage
87
+ ? timeAgo(sessionSummary.lastMessage.timestamp)
88
+ : 'Unknown';
89
+
90
+ console.log(` ${sessionStatus} ${fmt.bold('Active Session')}`);
91
+ console.log(` Messages: ${fmt.cyan(sessionSummary.messageCount)} (${sessionSummary.userMessageCount} user, ${sessionSummary.assistantMessageCount} assistant)`);
92
+ console.log(` Duration: ${fmt.cyan(duration)}`);
93
+ console.log(` Last Activity: ${fmt.cyan(lastActivity)}`);
94
+
95
+ // Show recent activity
96
+ if (sessionSummary.lastMessage) {
97
+ const preview = sessionSummary.lastMessage.content.slice(0, 60);
98
+ const truncated = sessionSummary.lastMessage.content.length > 60 ? '...' : '';
99
+ console.log(` Last Message: ${fmt.dim(`"${preview}${truncated}"`)}`);
100
+ }
101
+ }
102
+
103
+ console.log('');
104
+ }
105
+
106
+ /**
107
+ * Display system status overview
108
+ */
109
+ function displaySystemStatus() {
110
+ const env = detectEnvironment();
111
+ const quickStatus = getQuickStatus();
112
+
113
+ console.log(fmt.bold('\nšŸ„ System Status:'));
114
+ console.log(separator(50, '─'));
115
+
116
+ // Overall health
117
+ let healthIcon, healthText;
118
+ switch (quickStatus.status) {
119
+ case 'ready':
120
+ healthIcon = status.success;
121
+ healthText = fmt.green('Operational');
122
+ break;
123
+ case 'needs_auth':
124
+ healthIcon = status.warning;
125
+ healthText = fmt.yellow('Needs Authentication');
126
+ break;
127
+ default:
128
+ healthIcon = status.error;
129
+ healthText = fmt.red('Unknown');
130
+ }
131
+
132
+ console.log(` ${healthIcon} Health: ${healthText}`);
133
+ console.log(` šŸ“ Workspace: ${fmt.cyan(env.workspace)}`);
134
+ console.log(` šŸ”Œ Providers: ${quickStatus.providers.count}/2 authenticated`);
135
+
136
+ console.log('');
137
+ }
138
+
139
+ /**
140
+ * Display provider status with details
141
+ */
142
+ function displayProviderStatus() {
143
+ const env = detectEnvironment();
144
+
145
+ console.log(fmt.bold('\nšŸ¤ Providers:'));
146
+ console.log(separator(50, '─'));
147
+
148
+ // Claude status
149
+ const claudeIcon = provider.claude;
150
+ const claudeStatus = env.claude.authed ? status.success : env.claude.installed ? status.warning : status.error;
151
+ const claudeText = env.claude.authed ? 'Ready' : env.claude.installed ? 'Not authenticated' : 'Not installed';
152
+
153
+ console.log(` ${claudeIcon} Claude: ${claudeStatus} ${claudeText}`);
154
+
155
+ if (env.claude.version) {
156
+ console.log(` Version: ${fmt.dim(env.claude.version)}`);
157
+ }
158
+
159
+ if (env.claude.authed) {
160
+ console.log(` Models: ${fmt.green('Opus, Sonnet, Haiku')}`);
161
+ } else if (env.claude.installed) {
162
+ console.log(` ${status.info} Run: ${fmt.cyan('claude auth login')}`);
163
+ } else {
164
+ console.log(` ${status.info} Install: ${fmt.cyan('pip install anthropic-cli')}`);
165
+ }
166
+
167
+ // Codex status
168
+ const codexIcon = provider.codex;
169
+ const codexStatus = env.codex.authed ? status.success : env.codex.installed ? status.warning : status.error;
170
+ const codexText = env.codex.authed ? 'Ready' : env.codex.installed ? 'Not authenticated' : 'Not installed';
171
+
172
+ console.log(` ${codexIcon} Codex: ${codexStatus} ${codexText}`);
173
+
174
+ if (env.codex.version) {
175
+ console.log(` Version: ${fmt.dim(env.codex.version)}`);
176
+ }
177
+
178
+ if (env.codex.authed) {
179
+ console.log(` Models: ${fmt.green('GPT-5.5, GPT-5.4, GPT-4.1-mini')}`);
180
+ } else if (env.codex.installed) {
181
+ console.log(` ${status.info} Run: ${fmt.cyan('codex login')}`);
182
+ } else {
183
+ console.log(` ${status.info} Install: ${fmt.cyan('npm install -g @openai/codex')}`);
184
+ }
185
+
186
+ // Usage balance
187
+ const balance = mockGetTodaysBalance(); // Replace with real implementation
188
+ if (balance.total > 0) {
189
+ console.log(`\n šŸ“Š Today's Usage Balance:`);
190
+ console.log(` ${providerBalanceBar(balance.claude, balance.openai)}`);
191
+ console.log(` ${fmt.dim(balance.label + ' • ' + balance.total + ' calls')}`);
192
+ }
193
+
194
+ console.log('');
195
+ }
196
+
197
+ /**
198
+ * Display performance metrics
199
+ */
200
+ function displayPerformanceMetrics() {
201
+ console.log(fmt.bold('\nšŸ“ˆ Performance:'));
202
+ console.log(separator(50, '─'));
203
+
204
+ // Mock performance data - replace with real metrics
205
+ const metrics = mockGetPerformanceMetrics();
206
+
207
+ console.log(` ⚔ Average Response Time: ${fmt.green(metrics.avgResponseTime)}`);
208
+ console.log(` šŸŽÆ Success Rate: ${fmt.green(metrics.successRate)}`);
209
+ console.log(` šŸ”„ Escalation Rate: ${fmt.yellow(metrics.escalationRate)}`);
210
+
211
+ if (metrics.tokensToday > 0) {
212
+ console.log(` šŸ”¢ Tokens Today: ${fmt.cyan(metrics.tokensToday.toLocaleString())}`);
213
+ }
214
+
215
+ if (metrics.costToday > 0) {
216
+ console.log(` šŸ’° Estimated Cost Today: ${fmt.cyan('$' + metrics.costToday.toFixed(2))}`);
217
+ }
218
+
219
+ console.log('');
220
+ }
221
+
222
+ /**
223
+ * Display detailed information (verbose mode)
224
+ */
225
+ function displayDetailedInfo(workingDir) {
226
+ console.log(fmt.bold('\nšŸ” Detailed Information:'));
227
+ console.log(separator(50, '─'));
228
+
229
+ // Session directory details
230
+ const sessionPath = `${workingDir}/.cortex/sessions/`;
231
+ console.log(` šŸ“‚ Session Directory: ${fmt.cyan(sessionPath)}`);
232
+
233
+ try {
234
+ // Mock file count - replace with real directory reading
235
+ const fileCount = 12; // Mock count
236
+ const totalSize = '2.3MB'; // Mock size
237
+ console.log(` Files: ${fmt.dim(fileCount)} session files`);
238
+ console.log(` Size: ${fmt.dim(totalSize)} total`);
239
+ } catch (error) {
240
+ console.log(` ${status.error} Error reading directory: ${error.message}`);
241
+ }
242
+
243
+ // Configuration status
244
+ console.log(` āš™ļø Configuration:`);
245
+ console.log(` Timeout: ${fmt.dim('120 seconds')}`);
246
+ console.log(` Auto-escalation: ${fmt.green('Enabled')}`);
247
+ console.log(` Session archiving: ${fmt.green('Enabled')}`);
248
+
249
+ // Recent activity
250
+ console.log(` šŸ“‹ Recent Activity:`);
251
+ const recentSessions = mockGetRecentSessions(); // Replace with real data
252
+
253
+ if (recentSessions.length === 0) {
254
+ console.log(` ${fmt.dim('No recent sessions')}`);
255
+ } else {
256
+ recentSessions.slice(0, 3).forEach((session, index) => {
257
+ const timeDisplay = timeAgo(session.timestamp);
258
+ const preview = session.preview.slice(0, 30);
259
+ console.log(` ${fmt.dim(`${index + 1}.`)} ${timeDisplay} - ${fmt.dim(`"${preview}..."`)}`);
260
+ });
261
+ }
262
+
263
+ console.log('');
264
+ }
265
+
266
+ /**
267
+ * Display available quick actions
268
+ */
269
+ function displayQuickActions() {
270
+ console.log(fmt.bold('\n⚔ Quick Actions:'));
271
+ console.log(separator(50, '─'));
272
+
273
+ console.log(` ${fmt.cyan('cortex --doctor')} Run full health check`);
274
+ console.log(` ${fmt.cyan('cortex --reset')} Reset session state`);
275
+ console.log(` ${fmt.cyan('cortex --cleanup')} Clean up old files`);
276
+ console.log(` ${fmt.cyan('cortex --help')} Show all commands`);
277
+
278
+ const quickStatus = getQuickStatus();
279
+ if (quickStatus.status === 'needs_auth') {
280
+ console.log(`\n ${status.warning} ${fmt.yellow('Authentication needed to start chatting')}`);
281
+ } else if (!quickStatus.session.active) {
282
+ console.log(`\n ${status.info} ${fmt.green('Ready to start chatting!')}`);
283
+ }
284
+
285
+ console.log('');
286
+ }
287
+
288
+ /**
289
+ * Mock function for today's usage balance
290
+ */
291
+ function mockGetTodaysBalance() {
292
+ return {
293
+ claude: 35,
294
+ openai: 65,
295
+ total: 18,
296
+ label: 'GPT-heavy — Claude has capacity'
297
+ };
298
+ }
299
+
300
+ /**
301
+ * Mock function for performance metrics
302
+ */
303
+ function mockGetPerformanceMetrics() {
304
+ return {
305
+ avgResponseTime: '1.4s',
306
+ successRate: '94.2%',
307
+ escalationRate: '12.5%',
308
+ tokensToday: 45_230,
309
+ costToday: 3.42
310
+ };
311
+ }
312
+
313
+ /**
314
+ * Mock function for recent sessions
315
+ */
316
+ function mockGetRecentSessions() {
317
+ return [
318
+ {
319
+ timestamp: Date.now() - 2 * 60 * 60 * 1000, // 2 hours ago
320
+ preview: 'Fix the authentication bug in the login flow'
321
+ },
322
+ {
323
+ timestamp: Date.now() - 5 * 60 * 60 * 1000, // 5 hours ago
324
+ preview: 'Add error handling to the API endpoints'
325
+ },
326
+ {
327
+ timestamp: Date.now() - 12 * 60 * 60 * 1000, // 12 hours ago
328
+ preview: 'Implement user dashboard components'
329
+ }
330
+ ];
331
+ }