-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreminder-cli.js
More file actions
476 lines (407 loc) · 14.2 KB
/
Copy pathreminder-cli.js
File metadata and controls
476 lines (407 loc) · 14.2 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#!/usr/bin/env node
const ReminderManager = require('./reminder-manager');
const readline = require('readline');
/**
* Reminder CLI - Interactive interface for Smart Notifications & Reminders
*
* Commands:
* - list: Show all reminders
* - check: Check for due reminders now
* - create: Create a new reminder interactively
* - medication: Create medication reminder
* - exercise: Create exercise reminder
* - sleep: Create sleep reminder
* - custom: Create custom reminder
* - toggle <id>: Enable/disable a reminder
* - delete <id>: Delete a reminder
* - snooze <id> [minutes]: Snooze a reminder
* - stats: View compliance statistics
* - help: Show help
*/
class ReminderCLI {
constructor() {
this.manager = new ReminderManager();
// Lazily create a real readline interface only when needed to avoid keeping stdin open in tests
this._realRl = null;
this.rl = {
question: (q, cb) => {
if (!this._realRl) {
this._realRl = readline.createInterface({ input: process.stdin, output: process.stdout });
}
this._realRl.question(q, cb);
},
close: () => {
if (this._realRl) {
this._realRl.close();
this._realRl = null;
}
}
};
}
/**
* Show help message
*/
showHelp() {
console.log(`
╔════════════════════════════════════════════════════════════╗
║ Smart Notifications & Reminders - StepSyncAI ║
╚════════════════════════════════════════════════════════════╝
COMMANDS:
📋 Managing Reminders:
list Show all reminders
check Check for due reminders now
toggle <id> Enable/disable a reminder
delete <id> Delete a reminder
stats View compliance statistics
➕ Creating Reminders:
create Create a reminder interactively
medication Create medication reminder
exercise Create exercise reminder
sleep Create sleep reminder
custom Create custom reminder
🔔 Reminder Actions:
snooze <id> [mins] Snooze a reminder (default: 15 min)
dismiss <id> Dismiss a reminder
ℹ️ Help:
help Show this help message
EXAMPLES:
node reminder-cli.js list
node reminder-cli.js create
node reminder-cli.js medication
node reminder-cli.js exercise
node reminder-cli.js sleep
node reminder-cli.js check
node reminder-cli.js toggle abc-123
node reminder-cli.js snooze abc-123 30
node reminder-cli.js stats
═══════════════════════════════════════════════════════════
`);
}
/**
* Prompt user for input
*/
prompt(question) {
return new Promise(resolve => {
this.rl.question(question, answer => {
resolve(answer.trim());
});
});
}
/**
* Create a reminder interactively
*/
async createInteractive() {
console.log('\n🔔 Create New Reminder\n');
console.log('═'.repeat(60));
const type = await this.prompt('\nReminder type (medication/exercise/sleep/custom): ');
if (!['medication', 'exercise', 'sleep', 'custom'].includes(type)) {
console.log('❌ Invalid reminder type');
return;
}
const title = await this.prompt('Title: ');
if (!title) {
console.log('❌ Title is required');
return;
}
const message = await this.prompt('Message (optional, press Enter to use title): ');
const time = await this.prompt('Time (HH:mm format, e.g., 08:30): ');
if (!/^\d{2}:\d{2}$/.test(time)) {
console.log('❌ Invalid time format. Use HH:mm (e.g., 08:30)');
return;
}
const daysInput = await this.prompt('Days (daily or comma-separated: monday,wednesday,friday): ');
let days = 'daily';
if (daysInput && daysInput.toLowerCase() !== 'daily') {
days = daysInput.split(',').map(d => d.trim().toLowerCase());
}
try {
this.manager.createReminder({
type,
title,
message: message || title,
time,
days
});
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
/**
* Create medication reminder
*/
async createMedicationReminder() {
console.log('\n💊 Create Medication Reminder\n');
console.log('═'.repeat(60));
const name = await this.prompt('\nMedication name: ');
if (!name) {
console.log('❌ Medication name is required');
return;
}
const dosage = await this.prompt('Dosage (e.g., 500mg): ');
const time = await this.prompt('Time (HH:mm format, e.g., 08:00): ');
if (!/^\d{2}:\d{2}$/.test(time)) {
console.log('❌ Invalid time format. Use HH:mm');
return;
}
const frequency = await this.prompt('Frequency (e.g., daily, 3 times per week): ');
try {
this.manager.createMedicationReminder({
name,
dosage,
frequency: frequency || 'daily',
time
});
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
/**
* Create exercise reminder
*/
async createExerciseReminder() {
console.log('\n🏃 Create Exercise Reminder\n');
console.log('═'.repeat(60));
const title = await this.prompt('\nReminder title (default: Exercise Time): ');
const time = await this.prompt('Time (HH:mm format, default: 18:00): ');
const timeToUse = time || '18:00';
if (!/^\d{2}:\d{2}$/.test(timeToUse)) {
console.log('❌ Invalid time format. Use HH:mm');
return;
}
const daysInput = await this.prompt('Days (daily or comma-separated days): ');
let days = 'daily';
if (daysInput && daysInput.toLowerCase() !== 'daily') {
days = daysInput.split(',').map(d => d.trim().toLowerCase());
}
try {
this.manager.createExerciseReminder({
title: title || 'Exercise Time',
time: timeToUse,
days
});
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
/**
* Create sleep reminder
*/
async createSleepReminder() {
console.log('\n😴 Create Sleep Reminder\n');
console.log('═'.repeat(60));
const bedtime = await this.prompt('\nBedtime (HH:mm format, default: 22:00): ');
const wakeup = await this.prompt('Wake-up time (HH:mm format, default: 06:00): ');
const bedtimeToUse = bedtime || '22:00';
const wakeupToUse = wakeup || '06:00';
if (!/^\d{2}:\d{2}$/.test(bedtimeToUse) || !/^\d{2}:\d{2}$/.test(wakeupToUse)) {
console.log('❌ Invalid time format. Use HH:mm');
return;
}
try {
this.manager.createSleepReminder({
bedtime: bedtimeToUse,
wakeup: wakeupToUse
});
console.log(' Created 2 reminders: Bedtime and Wake-up');
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
/**
* Check for due reminders
*/
checkDueReminders() {
const dueReminders = this.manager.getDueReminders();
if (dueReminders.length === 0) {
console.log('\n✅ No reminders due right now');
return;
}
console.log(`\n🔔 ${dueReminders.length} Reminder(s) Due Now!\n`);
console.log('═'.repeat(60));
dueReminders.forEach((reminder, index) => {
console.log(`\n${index + 1}. ${reminder.title}`);
console.log(` ${reminder.message}`);
console.log(` Type: ${reminder.type} | Time: ${reminder.time}`);
console.log(` ID: ${reminder.id}`);
// Mark as shown
this.manager.markAsShown(reminder.id);
});
console.log('\n' + '═'.repeat(60));
console.log('Use "snooze <id> [minutes]" or "dismiss <id>" to manage');
}
/**
* Toggle reminder
*/
toggleReminder(id) {
try {
this.manager.toggleReminder(id);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
/**
* Delete reminder
*/
deleteReminder(id) {
try {
this.manager.deleteReminder(id);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
/**
* Snooze reminder
*/
snoozeReminder(id, minutes = 15) {
try {
this.manager.snoozeReminder(id, minutes);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
/**
* Dismiss reminder
*/
dismissReminder(id) {
try {
this.manager.dismissReminder(id);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
/**
* Show compliance statistics
*/
showStats() {
const stats = this.manager.getComplianceStats();
console.log('\n📊 Reminder Compliance Statistics\n');
console.log('═'.repeat(60));
console.log('\n📋 Overview:');
console.log(` Total reminders: ${stats.total}`);
console.log(` Enabled: ${stats.enabled}`);
console.log(` Disabled: ${stats.total - stats.enabled}`);
console.log('\n📊 By Type:');
Object.entries(stats.byType).forEach(([type, count]) => {
const emoji = {
medication: '💊',
exercise: '🏃',
sleep: '😴',
custom: '⚡'
}[type] || '📌';
console.log(` ${emoji} ${type}: ${count}`);
});
const complianceEntries = Object.entries(stats.compliance);
if (complianceEntries.length > 0) {
console.log('\n✅ Compliance Rates:');
complianceEntries.forEach(([id, data]) => {
const emoji = {
medication: '💊',
exercise: '🏃',
sleep: '😴',
custom: '⚡'
}[data.type] || '📌';
console.log(`\n ${emoji} ${data.title}`);
console.log(` Shown: ${data.shown} times`);
console.log(` Responded: ${data.dismissed + data.snoozed} times`);
console.log(` Compliance: ${data.complianceRate}%`);
});
} else {
console.log('\n No compliance data yet. Reminders need to be shown first.');
}
console.log('\n' + '═'.repeat(60));
}
/**
* Run the CLI
*/
async run() {
const args = process.argv.slice(2);
const command = args[0] || 'help';
switch (command.toLowerCase()) {
case 'list':
this.manager.displayReminders();
this.rl.close();
break;
case 'check':
this.checkDueReminders();
this.rl.close();
break;
case 'create':
await this.createInteractive();
this.rl.close();
break;
case 'medication':
case 'med':
await this.createMedicationReminder();
this.rl.close();
break;
case 'exercise':
case 'ex':
await this.createExerciseReminder();
this.rl.close();
break;
case 'sleep':
await this.createSleepReminder();
this.rl.close();
break;
case 'custom':
await this.createInteractive();
this.rl.close();
break;
case 'toggle':
if (!args[1]) {
console.log('❌ Usage: toggle <reminder-id>');
} else {
this.toggleReminder(args[1]);
}
this.rl.close();
break;
case 'delete':
case 'remove':
if (!args[1]) {
console.log('❌ Usage: delete <reminder-id>');
} else {
this.deleteReminder(args[1]);
}
this.rl.close();
break;
case 'snooze':
if (!args[1]) {
console.log('❌ Usage: snooze <reminder-id> [minutes]');
} else {
const minutes = args[2] ? parseInt(args[2]) : 15;
this.snoozeReminder(args[1], minutes);
}
this.rl.close();
break;
case 'dismiss':
if (!args[1]) {
console.log('❌ Usage: dismiss <reminder-id>');
} else {
this.dismissReminder(args[1]);
}
this.rl.close();
break;
case 'stats':
case 'statistics':
this.showStats();
this.rl.close();
break;
case 'help':
case '--help':
case '-h':
default:
this.showHelp();
this.rl.close();
break;
}
}
}
// Run the CLI if executed directly
if (require.main === module) {
const cli = new ReminderCLI();
cli.run().catch(error => {
console.error('❌ Error:', error.message);
process.exit(1);
});
}
module.exports = ReminderCLI;