-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
76 lines (65 loc) · 2.03 KB
/
index.ts
File metadata and controls
76 lines (65 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
import { readFile } from 'node:fs/promises';
import { consola } from 'consola';
import { createWarmupPlan } from './src/analyzer.js';
import { paths } from './src/config.js';
import { getDaemonLogs, getDaemonStatus, startDaemon, stopDaemon } from './src/daemon/manager.js';
import type { WarmupPlan } from './src/types.js';
import { formatDuration, formatTime } from './src/utils.js';
const cmd = process.argv[2] ?? '';
const commands: Record<string, () => Promise<void>> = {
async analyze() {
const days = parseInt(process.argv[3] ?? '30', 10);
await createWarmupPlan(days);
},
async start() {
await startDaemon();
},
async stop() {
await stopDaemon();
},
async status() {
const daemon = await getDaemonStatus();
let plan: WarmupPlan | null = null;
try {
plan = JSON.parse(await readFile(paths.plan, 'utf-8')) as WarmupPlan;
} catch {}
consola.box({
title: 'ccwarm Status',
message: [
`Daemon: ${daemon.running ? `Running (PID: ${daemon.pid})` : 'Stopped'}`,
'',
plan
? [
'Warmup Plan:',
` Target Time: ${formatTime(plan.targetMinute)}`,
` Median Start: ${formatTime(plan.medianStartMinute)}`,
` Median Duration: ${formatDuration(plan.medianDurationMinutes)}`,
` Calculated: ${plan.calculatedAt}`,
].join('\n')
: "No warmup plan. Run 'ccwarm analyze' first.",
].join('\n'),
});
},
async logs() {
await getDaemonLogs();
},
};
const run = commands[cmd];
if (run) {
await run();
} else {
consola.box({
title: 'ccwarm - Claude Auto-Warmer',
message: [
'Usage: ccwarm <command>',
'',
'Commands:',
' analyze [days] Analyze usage patterns (default: 30 days)',
' start Start background daemon',
' stop Stop background daemon',
' status Show daemon and plan status',
' logs Follow daemon log output',
].join('\n'),
});
}