taskmonkey-cli 0.7.0 → 0.8.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.
package/bin/tm.js CHANGED
@@ -10,6 +10,7 @@ import { logs } from '../src/commands/logs.js';
10
10
  import { chat } from '../src/commands/chat.js';
11
11
  import { tasks } from '../src/commands/tasks.js';
12
12
  import { history } from '../src/commands/history.js';
13
+ import { monitor } from '../src/commands/monitor.js';
13
14
  import { testChat } from '../src/commands/test-chat.js';
14
15
  import { testConversations } from '../src/commands/test-conversations.js';
15
16
  import { optimizePrompt } from '../src/commands/optimize-prompt.js';
@@ -62,6 +63,12 @@ program
62
63
  .option('-n, --last <number>', 'Number of messages', '20')
63
64
  .action(history);
64
65
 
66
+ program
67
+ .command('monitor')
68
+ .description('Live monitor of all tool executions (like TaskMonitor)')
69
+ .option('-n, --last <number>', 'Initial history entries', '20')
70
+ .action(monitor);
71
+
65
72
  program
66
73
  .command('logs')
67
74
  .description('Stream server logs')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskmonkey-cli",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "TaskMonkey CLI — Remote dev tools for tenant config editing and tool testing",
5
5
  "bin": {
6
6
  "tm": "./bin/tm.js",
@@ -0,0 +1,109 @@
1
+ import chalk from 'chalk';
2
+ import EventSource from 'eventsource';
3
+ import { loadConfig } from '../config.js';
4
+
5
+ const BADGES = {
6
+ running: chalk.bgYellow.black(' RUN '),
7
+ success: chalk.bgGreen.black(' OK '),
8
+ error: chalk.bgRed.white(' FAIL '),
9
+ timeout: chalk.bgRed.white(' TIME '),
10
+ };
11
+
12
+ const TYPES = {
13
+ chat: 'CHAT',
14
+ scheduled: 'CRON',
15
+ monkey: 'TASK',
16
+ email: 'MAIL',
17
+ unified: 'UNIF',
18
+ api: 'API ',
19
+ scan: 'SCAN',
20
+ test: 'TEST',
21
+ };
22
+
23
+ function formatDuration(ms) {
24
+ if (!ms) return '';
25
+ if (ms < 1000) return `${ms}ms`;
26
+ const s = (ms / 1000).toFixed(1);
27
+ if (s < 60) return `${s}s`;
28
+ const min = Math.floor(s / 60);
29
+ const sec = Math.round(s - min * 60);
30
+ return `${min}m${sec}s`;
31
+ }
32
+
33
+ function renderExecution(exec) {
34
+ const time = chalk.gray(exec.started_at || '??:??');
35
+ const badge = BADGES[exec.status] || exec.status;
36
+ const type = chalk.gray(TYPES[exec.type] || exec.type?.substring(0, 4).toUpperCase() || '????');
37
+ const tool = (exec.status === 'success' ? chalk.green : exec.status === 'error' ? chalk.red : chalk.yellow)(chalk.bold(exec.tool));
38
+
39
+ let stats = [];
40
+ if (exec.duration_ms) stats.push(formatDuration(exec.duration_ms));
41
+ if (exec.api_calls > 0) stats.push(`${exec.api_calls} api`);
42
+ if (exec.metrics) {
43
+ for (const [k, v] of Object.entries(exec.metrics)) {
44
+ stats.push(`${k.replace(/_count|_/g, ' ').trim()}: ${v}`);
45
+ }
46
+ }
47
+ const statsStr = stats.length > 0 ? chalk.gray(` ${stats.join(' | ')}`) : '';
48
+
49
+ console.log(`${time} ${badge} ${type} ${tool}${statsStr}`);
50
+
51
+ // Args on second line
52
+ if (exec.args && Object.keys(exec.args).length > 0) {
53
+ let json = JSON.stringify(exec.args);
54
+ if (json.length > 120) json = json.substring(0, 117) + '...';
55
+ console.log(` ${chalk.hex('#FF8800')(json)}`);
56
+ }
57
+
58
+ if (exec.error) {
59
+ console.log(` ${chalk.red(exec.error)}`);
60
+ }
61
+ }
62
+
63
+ export async function monitor(options) {
64
+ const config = loadConfig();
65
+ if (!config) {
66
+ console.error(chalk.red('Not logged in. Run `tm login` first.'));
67
+ process.exit(1);
68
+ }
69
+
70
+ const last = options.last || 20;
71
+
72
+ console.log(chalk.cyan.bold('━━━ TaskMonkey Monitor ━━━'));
73
+ console.log(chalk.gray(`Tenant: ${config.tenant} | Ctrl+C to stop\n`));
74
+
75
+ const url = `${config.server}/api/test/monitor?tenant=${config.tenant}&last=${last}&stream=1`;
76
+
77
+ const es = new EventSource(url, {
78
+ headers: { 'Authorization': `Bearer ${config.token}` },
79
+ });
80
+
81
+ es.onmessage = (e) => {
82
+ try {
83
+ renderExecution(JSON.parse(e.data));
84
+ } catch {}
85
+ };
86
+
87
+ es.addEventListener('complete', (e) => {
88
+ try {
89
+ renderExecution(JSON.parse(e.data));
90
+ } catch {}
91
+ });
92
+
93
+ es.addEventListener('init_complete', () => {
94
+ console.log(chalk.gray('─── live ───\n'));
95
+ });
96
+
97
+ es.onerror = () => {
98
+ if (es.readyState === EventSource.CLOSED) {
99
+ console.log(chalk.gray('\nConnection closed.'));
100
+ process.exit(0);
101
+ }
102
+ };
103
+
104
+ process.on('SIGINT', () => {
105
+ es.close();
106
+ console.log(chalk.gray('\nStopped.'));
107
+ process.exit(0);
108
+ });
109
+ }