taskmonkey-cli 0.6.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
@@ -9,6 +9,8 @@ import { watch } from '../src/commands/watch.js';
9
9
  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
+ import { history } from '../src/commands/history.js';
13
+ import { monitor } from '../src/commands/monitor.js';
12
14
  import { testChat } from '../src/commands/test-chat.js';
13
15
  import { testConversations } from '../src/commands/test-conversations.js';
14
16
  import { optimizePrompt } from '../src/commands/optimize-prompt.js';
@@ -54,6 +56,19 @@ program
54
56
  .description('Watch for file changes and auto-sync')
55
57
  .action(watch);
56
58
 
59
+ program
60
+ .command('history')
61
+ .description('Show recent chat messages for a task (for debugging)')
62
+ .option('-t, --task <slug>', 'Monkey task slug (default: unified)')
63
+ .option('-n, --last <number>', 'Number of messages', '20')
64
+ .action(history);
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
+
57
72
  program
58
73
  .command('logs')
59
74
  .description('Stream server logs')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskmonkey-cli",
3
- "version": "0.6.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,59 @@
1
+ import chalk from 'chalk';
2
+ import ora from 'ora';
3
+ import { createClient } from '../lib/api.js';
4
+
5
+ export async function history(options) {
6
+ const client = createClient();
7
+
8
+ const spinner = ora('Loading chat history...').start();
9
+
10
+ try {
11
+ const result = await client.get('/api/test/history', {
12
+ task: options.task || '',
13
+ last: options.last || '20',
14
+ });
15
+
16
+ spinner.stop();
17
+
18
+ if (result.count === 0) {
19
+ console.log(chalk.yellow('Keine Nachrichten gefunden.'));
20
+ console.log(chalk.gray(`Chat-ID: ${result.chat_id}`));
21
+ return;
22
+ }
23
+
24
+ console.log(chalk.gray(`${result.chat_id} — ${result.count} Nachrichten\n`));
25
+
26
+ for (const msg of result.messages) {
27
+ const time = chalk.gray(msg.created);
28
+ const content = (msg.content || '').replace(/\n{3,}/g, '\n').trim();
29
+
30
+ switch (msg.role) {
31
+ case 'user':
32
+ console.log(`${time} ${chalk.green('USER')} ${content}`);
33
+ break;
34
+ case 'assistant':
35
+ // Check for tool_use
36
+ if (content.includes('[tool_use:')) {
37
+ const tools = content.match(/\[tool_use: ([^\]]+)\]/g) || [];
38
+ for (const t of tools) {
39
+ console.log(`${time} ${chalk.yellow('TOOL')} ${t}`);
40
+ }
41
+ } else {
42
+ console.log(`${time} ${chalk.cyan('AI')} ${content.substring(0, 200)}${content.length > 200 ? '...' : ''}`);
43
+ }
44
+ break;
45
+ case 'tool':
46
+ console.log(`${time} ${chalk.gray('RESULT')} ${content.substring(0, 150)}${content.length > 150 ? '...' : ''}`);
47
+ break;
48
+ case 'system':
49
+ console.log(`${time} ${chalk.magenta('SYS')} ${content.substring(0, 150)}`);
50
+ break;
51
+ default:
52
+ console.log(`${time} ${chalk.gray(msg.role.toUpperCase())} ${content.substring(0, 150)}`);
53
+ }
54
+ }
55
+ } catch (err) {
56
+ spinner.fail(err.message);
57
+ process.exit(1);
58
+ }
59
+ }
@@ -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
+ }