@hasna/microservices 0.0.15 → 0.0.17
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/README.md +120 -138
- package/bin/index.js +703 -12728
- package/bin/mcp.js +250 -9726
- package/dist/index.js +170 -9407
- package/package.json +25 -25
- package/microservices/microservice-ads/package.json +0 -27
- package/microservices/microservice-ads/src/cli/index.ts +0 -605
- package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
- package/microservices/microservice-ads/src/db/database.ts +0 -93
- package/microservices/microservice-ads/src/db/migrations.ts +0 -60
- package/microservices/microservice-ads/src/index.ts +0 -39
- package/microservices/microservice-ads/src/mcp/index.ts +0 -480
- package/microservices/microservice-analytics/package.json +0 -27
- package/microservices/microservice-analytics/src/cli/index.ts +0 -373
- package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
- package/microservices/microservice-analytics/src/db/database.ts +0 -93
- package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
- package/microservices/microservice-analytics/src/index.ts +0 -37
- package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
- package/microservices/microservice-assets/package.json +0 -27
- package/microservices/microservice-assets/src/cli/index.ts +0 -375
- package/microservices/microservice-assets/src/db/assets.ts +0 -370
- package/microservices/microservice-assets/src/db/database.ts +0 -93
- package/microservices/microservice-assets/src/db/migrations.ts +0 -51
- package/microservices/microservice-assets/src/index.ts +0 -32
- package/microservices/microservice-assets/src/mcp/index.ts +0 -346
- package/microservices/microservice-bookkeeping/package.json +0 -27
- package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
- package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
- package/microservices/microservice-bookkeeping/src/db/database.ts +0 -93
- package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
- package/microservices/microservice-bookkeeping/src/index.ts +0 -32
- package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
- package/microservices/microservice-calendar/package.json +0 -27
- package/microservices/microservice-calendar/src/cli/index.ts +0 -287
- package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
- package/microservices/microservice-calendar/src/db/database.ts +0 -82
- package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
- package/microservices/microservice-calendar/src/index.ts +0 -24
- package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
- package/microservices/microservice-company/package.json +0 -27
- package/microservices/microservice-company/src/cli/index.ts +0 -1126
- package/microservices/microservice-company/src/db/company.ts +0 -854
- package/microservices/microservice-company/src/db/database.ts +0 -93
- package/microservices/microservice-company/src/db/migrations.ts +0 -214
- package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
- package/microservices/microservice-company/src/index.ts +0 -60
- package/microservices/microservice-company/src/lib/audit.ts +0 -168
- package/microservices/microservice-company/src/lib/finance.ts +0 -299
- package/microservices/microservice-company/src/lib/settings.ts +0 -85
- package/microservices/microservice-company/src/lib/workflows.ts +0 -698
- package/microservices/microservice-company/src/mcp/index.ts +0 -991
- package/microservices/microservice-compliance/package.json +0 -27
- package/microservices/microservice-compliance/src/cli/index.ts +0 -467
- package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
- package/microservices/microservice-compliance/src/db/database.ts +0 -93
- package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
- package/microservices/microservice-compliance/src/index.ts +0 -46
- package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
- package/microservices/microservice-contacts/package.json +0 -27
- package/microservices/microservice-contacts/src/cli/index.ts +0 -393
- package/microservices/microservice-contacts/src/db/companies.ts +0 -167
- package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
- package/microservices/microservice-contacts/src/db/database.ts +0 -93
- package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
- package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
- package/microservices/microservice-contacts/src/index.ts +0 -42
- package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
- package/microservices/microservice-contracts/package.json +0 -27
- package/microservices/microservice-contracts/src/cli/index.ts +0 -770
- package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
- package/microservices/microservice-contracts/src/db/database.ts +0 -93
- package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
- package/microservices/microservice-contracts/src/index.ts +0 -43
- package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
- package/microservices/microservice-crm/package.json +0 -27
- package/microservices/microservice-crm/src/cli/index.ts +0 -396
- package/microservices/microservice-crm/src/db/database.ts +0 -82
- package/microservices/microservice-crm/src/db/migrations.ts +0 -66
- package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
- package/microservices/microservice-crm/src/index.ts +0 -34
- package/microservices/microservice-crm/src/mcp/index.ts +0 -294
- package/microservices/microservice-documents/package.json +0 -27
- package/microservices/microservice-documents/src/cli/index.ts +0 -246
- package/microservices/microservice-documents/src/db/database.ts +0 -82
- package/microservices/microservice-documents/src/db/documents.ts +0 -316
- package/microservices/microservice-documents/src/db/migrations.ts +0 -49
- package/microservices/microservice-documents/src/index.ts +0 -24
- package/microservices/microservice-documents/src/mcp/index.ts +0 -202
- package/microservices/microservice-domains/package.json +0 -27
- package/microservices/microservice-domains/src/cli/index.ts +0 -1111
- package/microservices/microservice-domains/src/db/database.ts +0 -93
- package/microservices/microservice-domains/src/db/domains.ts +0 -1164
- package/microservices/microservice-domains/src/db/migrations.ts +0 -60
- package/microservices/microservice-domains/src/index.ts +0 -65
- package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
- package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
- package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
- package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
- package/microservices/microservice-domains/src/mcp/index.ts +0 -781
- package/microservices/microservice-expenses/package.json +0 -27
- package/microservices/microservice-expenses/src/cli/index.ts +0 -267
- package/microservices/microservice-expenses/src/db/database.ts +0 -82
- package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
- package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
- package/microservices/microservice-expenses/src/index.ts +0 -25
- package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
- package/microservices/microservice-habits/package.json +0 -27
- package/microservices/microservice-habits/src/cli/index.ts +0 -315
- package/microservices/microservice-habits/src/db/database.ts +0 -93
- package/microservices/microservice-habits/src/db/habits.ts +0 -451
- package/microservices/microservice-habits/src/db/migrations.ts +0 -46
- package/microservices/microservice-habits/src/index.ts +0 -31
- package/microservices/microservice-habits/src/mcp/index.ts +0 -313
- package/microservices/microservice-health/package.json +0 -27
- package/microservices/microservice-health/src/cli/index.ts +0 -484
- package/microservices/microservice-health/src/db/database.ts +0 -93
- package/microservices/microservice-health/src/db/health.ts +0 -708
- package/microservices/microservice-health/src/db/migrations.ts +0 -70
- package/microservices/microservice-health/src/index.ts +0 -63
- package/microservices/microservice-health/src/mcp/index.ts +0 -437
- package/microservices/microservice-hiring/package.json +0 -27
- package/microservices/microservice-hiring/src/cli/index.ts +0 -741
- package/microservices/microservice-hiring/src/db/database.ts +0 -93
- package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
- package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
- package/microservices/microservice-hiring/src/index.ts +0 -80
- package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
- package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
- package/microservices/microservice-inventory/package.json +0 -27
- package/microservices/microservice-inventory/src/cli/index.ts +0 -365
- package/microservices/microservice-inventory/src/db/database.ts +0 -82
- package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
- package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
- package/microservices/microservice-inventory/src/index.ts +0 -28
- package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
- package/microservices/microservice-invoices/dashboard/dist/assets/index-Bngq7FNM.css +0 -1
- package/microservices/microservice-invoices/dashboard/dist/assets/index-aHW4ARZR.js +0 -124
- package/microservices/microservice-invoices/dashboard/dist/index.html +0 -13
- package/microservices/microservice-invoices/dashboard/index.html +0 -12
- package/microservices/microservice-invoices/dashboard/package.json +0 -29
- package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
- package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
- package/microservices/microservice-invoices/package.json +0 -30
- package/microservices/microservice-invoices/src/cli/index.ts +0 -308
- package/microservices/microservice-invoices/src/db/business.ts +0 -241
- package/microservices/microservice-invoices/src/db/clients.ts +0 -127
- package/microservices/microservice-invoices/src/db/database.ts +0 -82
- package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
- package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
- package/microservices/microservice-invoices/src/index.ts +0 -56
- package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
- package/microservices/microservice-invoices/src/server/index.ts +0 -162
- package/microservices/microservice-leads/package.json +0 -27
- package/microservices/microservice-leads/src/cli/index.ts +0 -596
- package/microservices/microservice-leads/src/db/database.ts +0 -93
- package/microservices/microservice-leads/src/db/leads.ts +0 -520
- package/microservices/microservice-leads/src/db/lists.ts +0 -151
- package/microservices/microservice-leads/src/db/migrations.ts +0 -93
- package/microservices/microservice-leads/src/index.ts +0 -65
- package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
- package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
- package/microservices/microservice-leads/src/mcp/index.ts +0 -533
- package/microservices/microservice-notes/package.json +0 -27
- package/microservices/microservice-notes/src/cli/index.ts +0 -63
- package/microservices/microservice-notes/src/db/database.ts +0 -93
- package/microservices/microservice-notes/src/db/migrations.ts +0 -40
- package/microservices/microservice-notes/src/db/notes.ts +0 -114
- package/microservices/microservice-notes/src/index.ts +0 -2
- package/microservices/microservice-notes/src/mcp/index.ts +0 -37
- package/microservices/microservice-notifications/package.json +0 -27
- package/microservices/microservice-notifications/src/cli/index.ts +0 -349
- package/microservices/microservice-notifications/src/db/database.ts +0 -93
- package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
- package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
- package/microservices/microservice-notifications/src/index.ts +0 -41
- package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
- package/microservices/microservice-payments/package.json +0 -27
- package/microservices/microservice-payments/src/cli/index.ts +0 -609
- package/microservices/microservice-payments/src/db/database.ts +0 -93
- package/microservices/microservice-payments/src/db/migrations.ts +0 -81
- package/microservices/microservice-payments/src/db/payments.ts +0 -1204
- package/microservices/microservice-payments/src/index.ts +0 -51
- package/microservices/microservice-payments/src/mcp/index.ts +0 -683
- package/microservices/microservice-payroll/package.json +0 -27
- package/microservices/microservice-payroll/src/cli/index.ts +0 -643
- package/microservices/microservice-payroll/src/db/database.ts +0 -93
- package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
- package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
- package/microservices/microservice-payroll/src/index.ts +0 -48
- package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
- package/microservices/microservice-products/package.json +0 -27
- package/microservices/microservice-products/src/cli/index.ts +0 -416
- package/microservices/microservice-products/src/db/categories.ts +0 -154
- package/microservices/microservice-products/src/db/database.ts +0 -93
- package/microservices/microservice-products/src/db/migrations.ts +0 -58
- package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
- package/microservices/microservice-products/src/db/products.ts +0 -452
- package/microservices/microservice-products/src/index.ts +0 -53
- package/microservices/microservice-products/src/mcp/index.ts +0 -453
- package/microservices/microservice-projects/package.json +0 -27
- package/microservices/microservice-projects/src/cli/index.ts +0 -480
- package/microservices/microservice-projects/src/db/database.ts +0 -93
- package/microservices/microservice-projects/src/db/migrations.ts +0 -65
- package/microservices/microservice-projects/src/db/projects.ts +0 -715
- package/microservices/microservice-projects/src/index.ts +0 -57
- package/microservices/microservice-projects/src/mcp/index.ts +0 -501
- package/microservices/microservice-proposals/package.json +0 -27
- package/microservices/microservice-proposals/src/cli/index.ts +0 -400
- package/microservices/microservice-proposals/src/db/database.ts +0 -93
- package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
- package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
- package/microservices/microservice-proposals/src/index.ts +0 -37
- package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
- package/microservices/microservice-reading/package.json +0 -27
- package/microservices/microservice-reading/src/cli/index.ts +0 -464
- package/microservices/microservice-reading/src/db/database.ts +0 -93
- package/microservices/microservice-reading/src/db/migrations.ts +0 -59
- package/microservices/microservice-reading/src/db/reading.ts +0 -524
- package/microservices/microservice-reading/src/index.ts +0 -51
- package/microservices/microservice-reading/src/mcp/index.ts +0 -368
- package/microservices/microservice-shipping/package.json +0 -27
- package/microservices/microservice-shipping/src/cli/index.ts +0 -606
- package/microservices/microservice-shipping/src/db/database.ts +0 -93
- package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
- package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
- package/microservices/microservice-shipping/src/index.ts +0 -53
- package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
- package/microservices/microservice-social/package.json +0 -28
- package/microservices/microservice-social/src/cli/index.ts +0 -1583
- package/microservices/microservice-social/src/db/database.ts +0 -93
- package/microservices/microservice-social/src/db/migrations.ts +0 -160
- package/microservices/microservice-social/src/db/social.ts +0 -1076
- package/microservices/microservice-social/src/index.ts +0 -46
- package/microservices/microservice-social/src/lib/audience.ts +0 -353
- package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
- package/microservices/microservice-social/src/lib/media.ts +0 -311
- package/microservices/microservice-social/src/lib/mentions.ts +0 -434
- package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
- package/microservices/microservice-social/src/lib/publisher.ts +0 -377
- package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
- package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
- package/microservices/microservice-social/src/lib/threads.ts +0 -291
- package/microservices/microservice-social/src/mcp/index.ts +0 -1425
- package/microservices/microservice-social/src/server/index.ts +0 -441
- package/microservices/microservice-subscriptions/package.json +0 -27
- package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
- package/microservices/microservice-subscriptions/src/db/database.ts +0 -93
- package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
- package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
- package/microservices/microservice-subscriptions/src/index.ts +0 -41
- package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
- package/microservices/microservice-timesheets/package.json +0 -27
- package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
- package/microservices/microservice-timesheets/src/db/database.ts +0 -82
- package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
- package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
- package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
- package/microservices/microservice-timesheets/src/index.ts +0 -44
- package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
- package/microservices/microservice-transcriber/package.json +0 -28
- package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
- package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
- package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
- package/microservices/microservice-transcriber/src/db/database.ts +0 -82
- package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
- package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
- package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
- package/microservices/microservice-transcriber/src/index.ts +0 -43
- package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
- package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
- package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
- package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
- package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
- package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
- package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
- package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
- package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
- package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
- package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
- package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
- package/microservices/microservice-transcriber/src/server/index.ts +0 -199
- package/microservices/microservice-travel/package.json +0 -27
- package/microservices/microservice-travel/src/cli/index.ts +0 -505
- package/microservices/microservice-travel/src/db/database.ts +0 -93
- package/microservices/microservice-travel/src/db/migrations.ts +0 -77
- package/microservices/microservice-travel/src/db/travel.ts +0 -802
- package/microservices/microservice-travel/src/index.ts +0 -60
- package/microservices/microservice-travel/src/mcp/index.ts +0 -495
- package/microservices/microservice-wiki/package.json +0 -27
- package/microservices/microservice-wiki/src/cli/index.ts +0 -345
- package/microservices/microservice-wiki/src/db/database.ts +0 -93
- package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
- package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
- package/microservices/microservice-wiki/src/index.ts +0 -32
- package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
2
|
-
|
|
3
|
-
import { Command } from "commander";
|
|
4
|
-
import {
|
|
5
|
-
createHabit,
|
|
6
|
-
getHabit,
|
|
7
|
-
listHabits,
|
|
8
|
-
updateHabit,
|
|
9
|
-
deleteHabit,
|
|
10
|
-
activateHabit,
|
|
11
|
-
deactivateHabit,
|
|
12
|
-
completeHabit,
|
|
13
|
-
getStreak,
|
|
14
|
-
getAllStreaks,
|
|
15
|
-
getCompletionRate,
|
|
16
|
-
getTodayStatus,
|
|
17
|
-
getWeeklyReport,
|
|
18
|
-
} from "../db/habits.js";
|
|
19
|
-
|
|
20
|
-
const program = new Command();
|
|
21
|
-
|
|
22
|
-
program
|
|
23
|
-
.name("microservice-habits")
|
|
24
|
-
.description("Habit tracking microservice")
|
|
25
|
-
.version("0.0.1");
|
|
26
|
-
|
|
27
|
-
// --- Habits CRUD ---
|
|
28
|
-
|
|
29
|
-
program
|
|
30
|
-
.command("create")
|
|
31
|
-
.description("Create a new habit")
|
|
32
|
-
.requiredOption("--name <name>", "Habit name")
|
|
33
|
-
.option("--description <desc>", "Description")
|
|
34
|
-
.option("--frequency <freq>", "Frequency: daily, weekly, monthly", "daily")
|
|
35
|
-
.option("--target <n>", "Target count per period", "1")
|
|
36
|
-
.option("--category <cat>", "Category")
|
|
37
|
-
.option("--json", "Output as JSON", false)
|
|
38
|
-
.action((opts) => {
|
|
39
|
-
const habit = createHabit({
|
|
40
|
-
name: opts.name,
|
|
41
|
-
description: opts.description,
|
|
42
|
-
frequency: opts.frequency,
|
|
43
|
-
target_count: parseInt(opts.target),
|
|
44
|
-
category: opts.category,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
if (opts.json) {
|
|
48
|
-
console.log(JSON.stringify(habit, null, 2));
|
|
49
|
-
} else {
|
|
50
|
-
console.log(`Created habit: ${habit.name} (${habit.id})`);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
program
|
|
55
|
-
.command("get")
|
|
56
|
-
.description("Get a habit by ID")
|
|
57
|
-
.argument("<id>", "Habit ID")
|
|
58
|
-
.option("--json", "Output as JSON", false)
|
|
59
|
-
.action((id, opts) => {
|
|
60
|
-
const habit = getHabit(id);
|
|
61
|
-
if (!habit) {
|
|
62
|
-
console.error(`Habit '${id}' not found.`);
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (opts.json) {
|
|
67
|
-
console.log(JSON.stringify(habit, null, 2));
|
|
68
|
-
} else {
|
|
69
|
-
console.log(`${habit.name}`);
|
|
70
|
-
if (habit.description) console.log(` Description: ${habit.description}`);
|
|
71
|
-
console.log(` Frequency: ${habit.frequency}`);
|
|
72
|
-
console.log(` Target: ${habit.target_count}`);
|
|
73
|
-
if (habit.category) console.log(` Category: ${habit.category}`);
|
|
74
|
-
console.log(` Active: ${habit.active}`);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
program
|
|
79
|
-
.command("list")
|
|
80
|
-
.description("List habits")
|
|
81
|
-
.option("--category <cat>", "Filter by category")
|
|
82
|
-
.option("--active", "Show only active habits")
|
|
83
|
-
.option("--inactive", "Show only inactive habits")
|
|
84
|
-
.option("--frequency <freq>", "Filter by frequency")
|
|
85
|
-
.option("--limit <n>", "Limit results")
|
|
86
|
-
.option("--json", "Output as JSON", false)
|
|
87
|
-
.action((opts) => {
|
|
88
|
-
let active: boolean | undefined;
|
|
89
|
-
if (opts.active) active = true;
|
|
90
|
-
if (opts.inactive) active = false;
|
|
91
|
-
|
|
92
|
-
const habits = listHabits({
|
|
93
|
-
category: opts.category,
|
|
94
|
-
active,
|
|
95
|
-
frequency: opts.frequency,
|
|
96
|
-
limit: opts.limit ? parseInt(opts.limit) : undefined,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
if (opts.json) {
|
|
100
|
-
console.log(JSON.stringify(habits, null, 2));
|
|
101
|
-
} else {
|
|
102
|
-
if (habits.length === 0) {
|
|
103
|
-
console.log("No habits found.");
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
for (const h of habits) {
|
|
107
|
-
const cat = h.category ? ` [${h.category}]` : "";
|
|
108
|
-
const status = h.active ? "" : " (inactive)";
|
|
109
|
-
console.log(` ${h.name} (${h.frequency}, target: ${h.target_count})${cat}${status}`);
|
|
110
|
-
}
|
|
111
|
-
console.log(`\n${habits.length} habit(s)`);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
program
|
|
116
|
-
.command("update")
|
|
117
|
-
.description("Update a habit")
|
|
118
|
-
.argument("<id>", "Habit ID")
|
|
119
|
-
.option("--name <name>", "Habit name")
|
|
120
|
-
.option("--description <desc>", "Description")
|
|
121
|
-
.option("--frequency <freq>", "Frequency")
|
|
122
|
-
.option("--target <n>", "Target count")
|
|
123
|
-
.option("--category <cat>", "Category")
|
|
124
|
-
.option("--json", "Output as JSON", false)
|
|
125
|
-
.action((id, opts) => {
|
|
126
|
-
const input: Record<string, unknown> = {};
|
|
127
|
-
if (opts.name !== undefined) input.name = opts.name;
|
|
128
|
-
if (opts.description !== undefined) input.description = opts.description;
|
|
129
|
-
if (opts.frequency !== undefined) input.frequency = opts.frequency;
|
|
130
|
-
if (opts.target !== undefined) input.target_count = parseInt(opts.target);
|
|
131
|
-
if (opts.category !== undefined) input.category = opts.category;
|
|
132
|
-
|
|
133
|
-
const habit = updateHabit(id, input);
|
|
134
|
-
if (!habit) {
|
|
135
|
-
console.error(`Habit '${id}' not found.`);
|
|
136
|
-
process.exit(1);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (opts.json) {
|
|
140
|
-
console.log(JSON.stringify(habit, null, 2));
|
|
141
|
-
} else {
|
|
142
|
-
console.log(`Updated: ${habit.name}`);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
program
|
|
147
|
-
.command("delete")
|
|
148
|
-
.description("Delete a habit")
|
|
149
|
-
.argument("<id>", "Habit ID")
|
|
150
|
-
.action((id) => {
|
|
151
|
-
const deleted = deleteHabit(id);
|
|
152
|
-
if (deleted) {
|
|
153
|
-
console.log(`Deleted habit ${id}`);
|
|
154
|
-
} else {
|
|
155
|
-
console.error(`Habit '${id}' not found.`);
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
program
|
|
161
|
-
.command("activate")
|
|
162
|
-
.description("Activate a habit")
|
|
163
|
-
.argument("<id>", "Habit ID")
|
|
164
|
-
.option("--json", "Output as JSON", false)
|
|
165
|
-
.action((id, opts) => {
|
|
166
|
-
const habit = activateHabit(id);
|
|
167
|
-
if (!habit) {
|
|
168
|
-
console.error(`Habit '${id}' not found.`);
|
|
169
|
-
process.exit(1);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (opts.json) {
|
|
173
|
-
console.log(JSON.stringify(habit, null, 2));
|
|
174
|
-
} else {
|
|
175
|
-
console.log(`Activated: ${habit.name}`);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
program
|
|
180
|
-
.command("deactivate")
|
|
181
|
-
.description("Deactivate a habit")
|
|
182
|
-
.argument("<id>", "Habit ID")
|
|
183
|
-
.option("--json", "Output as JSON", false)
|
|
184
|
-
.action((id, opts) => {
|
|
185
|
-
const habit = deactivateHabit(id);
|
|
186
|
-
if (!habit) {
|
|
187
|
-
console.error(`Habit '${id}' not found.`);
|
|
188
|
-
process.exit(1);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (opts.json) {
|
|
192
|
-
console.log(JSON.stringify(habit, null, 2));
|
|
193
|
-
} else {
|
|
194
|
-
console.log(`Deactivated: ${habit.name}`);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
// --- Completions ---
|
|
199
|
-
|
|
200
|
-
program
|
|
201
|
-
.command("complete")
|
|
202
|
-
.description("Record a habit completion")
|
|
203
|
-
.argument("<id>", "Habit ID")
|
|
204
|
-
.option("--notes <notes>", "Completion notes")
|
|
205
|
-
.option("--value <n>", "Numeric value")
|
|
206
|
-
.option("--json", "Output as JSON", false)
|
|
207
|
-
.action((id, opts) => {
|
|
208
|
-
const completion = completeHabit(
|
|
209
|
-
id,
|
|
210
|
-
opts.notes,
|
|
211
|
-
opts.value ? parseFloat(opts.value) : undefined
|
|
212
|
-
);
|
|
213
|
-
if (!completion) {
|
|
214
|
-
console.error(`Habit '${id}' not found.`);
|
|
215
|
-
process.exit(1);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (opts.json) {
|
|
219
|
-
console.log(JSON.stringify(completion, null, 2));
|
|
220
|
-
} else {
|
|
221
|
-
console.log(`Completed habit ${id} at ${completion.completed_at}`);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// --- Status & Analytics ---
|
|
226
|
-
|
|
227
|
-
program
|
|
228
|
-
.command("today")
|
|
229
|
-
.description("Show today's habit status")
|
|
230
|
-
.option("--json", "Output as JSON", false)
|
|
231
|
-
.action((opts) => {
|
|
232
|
-
const status = getTodayStatus();
|
|
233
|
-
|
|
234
|
-
if (opts.json) {
|
|
235
|
-
console.log(JSON.stringify(status, null, 2));
|
|
236
|
-
} else {
|
|
237
|
-
if (status.length === 0) {
|
|
238
|
-
console.log("No active habits.");
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
for (const s of status) {
|
|
242
|
-
const check = s.completed_today ? "[x]" : "[ ]";
|
|
243
|
-
console.log(` ${check} ${s.habit.name}`);
|
|
244
|
-
}
|
|
245
|
-
const done = status.filter((s) => s.completed_today).length;
|
|
246
|
-
console.log(`\n${done}/${status.length} completed today`);
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
program
|
|
251
|
-
.command("streaks")
|
|
252
|
-
.description("Show all streaks")
|
|
253
|
-
.option("--json", "Output as JSON", false)
|
|
254
|
-
.action((opts) => {
|
|
255
|
-
const streaks = getAllStreaks();
|
|
256
|
-
|
|
257
|
-
if (opts.json) {
|
|
258
|
-
console.log(JSON.stringify(streaks, null, 2));
|
|
259
|
-
} else {
|
|
260
|
-
if (streaks.length === 0) {
|
|
261
|
-
console.log("No streaks.");
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
for (const s of streaks) {
|
|
265
|
-
const habit = getHabit(s.habit_id);
|
|
266
|
-
const name = habit ? habit.name : s.habit_id;
|
|
267
|
-
console.log(` ${name}: ${s.current_streak} day(s) (best: ${s.longest_streak})`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
program
|
|
273
|
-
.command("weekly-report")
|
|
274
|
-
.description("Show weekly completion report")
|
|
275
|
-
.option("--json", "Output as JSON", false)
|
|
276
|
-
.action((opts) => {
|
|
277
|
-
const report = getWeeklyReport();
|
|
278
|
-
|
|
279
|
-
if (opts.json) {
|
|
280
|
-
console.log(JSON.stringify(report, null, 2));
|
|
281
|
-
} else {
|
|
282
|
-
if (report.length === 0) {
|
|
283
|
-
console.log("No active habits for report.");
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
for (const r of report) {
|
|
287
|
-
console.log(` ${r.habit.name}: ${r.completions}/${r.target} (${r.rate}%)`);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
program
|
|
293
|
-
.command("rate")
|
|
294
|
-
.description("Get completion rate for a habit")
|
|
295
|
-
.argument("<id>", "Habit ID")
|
|
296
|
-
.option("--days <n>", "Number of days to look back", "30")
|
|
297
|
-
.option("--json", "Output as JSON", false)
|
|
298
|
-
.action((id, opts) => {
|
|
299
|
-
const habit = getHabit(id);
|
|
300
|
-
if (!habit) {
|
|
301
|
-
console.error(`Habit '${id}' not found.`);
|
|
302
|
-
process.exit(1);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const days = parseInt(opts.days);
|
|
306
|
-
const rate = getCompletionRate(id, days);
|
|
307
|
-
|
|
308
|
-
if (opts.json) {
|
|
309
|
-
console.log(JSON.stringify({ habit_id: id, days, rate }));
|
|
310
|
-
} else {
|
|
311
|
-
console.log(`${habit.name}: ${rate}% completion rate over ${days} days`);
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
program.parse(process.argv);
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Database connection for microservice-habits
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Database } from "bun:sqlite";
|
|
6
|
-
import { existsSync, mkdirSync } from "node:fs";
|
|
7
|
-
import { dirname, join, resolve } from "node:path";
|
|
8
|
-
import { MIGRATIONS } from "./migrations.js";
|
|
9
|
-
|
|
10
|
-
let _db: Database | null = null;
|
|
11
|
-
|
|
12
|
-
function getDbPath(): string {
|
|
13
|
-
// Environment variable override
|
|
14
|
-
if (process.env["MICROSERVICES_DIR"]) {
|
|
15
|
-
return join(process.env["MICROSERVICES_DIR"], "microservice-habits", "data.db");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Check for .microservices in current or parent directories
|
|
19
|
-
let dir = resolve(process.cwd());
|
|
20
|
-
while (true) {
|
|
21
|
-
const candidate = join(dir, ".microservices", "microservice-habits", "data.db");
|
|
22
|
-
const msDir = join(dir, ".microservices");
|
|
23
|
-
if (existsSync(msDir)) return candidate;
|
|
24
|
-
const parent = dirname(dir);
|
|
25
|
-
if (parent === dir) break;
|
|
26
|
-
dir = parent;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Global fallback
|
|
30
|
-
const home = process.env["HOME"] || process.env["USERPROFILE"] || "~";
|
|
31
|
-
return join(home, ".microservices", "microservice-habits", "data.db");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function ensureDir(filePath: string): void {
|
|
35
|
-
const dir = dirname(resolve(filePath));
|
|
36
|
-
if (!existsSync(dir)) {
|
|
37
|
-
mkdirSync(dir, { recursive: true });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getDatabase(): Database {
|
|
42
|
-
if (_db) return _db;
|
|
43
|
-
|
|
44
|
-
const dbPath = getDbPath();
|
|
45
|
-
ensureDir(dbPath);
|
|
46
|
-
|
|
47
|
-
_db = new Database(dbPath);
|
|
48
|
-
_db.exec("PRAGMA journal_mode = WAL");
|
|
49
|
-
_db.exec("PRAGMA foreign_keys = ON");
|
|
50
|
-
|
|
51
|
-
// Create migrations table
|
|
52
|
-
_db.exec(`
|
|
53
|
-
CREATE TABLE IF NOT EXISTS _migrations (
|
|
54
|
-
id INTEGER PRIMARY KEY,
|
|
55
|
-
name TEXT NOT NULL,
|
|
56
|
-
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
57
|
-
)
|
|
58
|
-
`);
|
|
59
|
-
|
|
60
|
-
// Apply pending migrations
|
|
61
|
-
const applied = _db
|
|
62
|
-
.query("SELECT id FROM _migrations ORDER BY id")
|
|
63
|
-
.all() as { id: number }[];
|
|
64
|
-
const appliedIds = new Set(applied.map((r) => r.id));
|
|
65
|
-
|
|
66
|
-
for (const migration of MIGRATIONS) {
|
|
67
|
-
if (appliedIds.has(migration.id)) continue;
|
|
68
|
-
|
|
69
|
-
_db.exec("BEGIN");
|
|
70
|
-
try {
|
|
71
|
-
_db.exec(migration.sql);
|
|
72
|
-
_db.prepare("INSERT INTO _migrations (id, name) VALUES (?, ?)").run(
|
|
73
|
-
migration.id,
|
|
74
|
-
migration.name
|
|
75
|
-
);
|
|
76
|
-
_db.exec("COMMIT");
|
|
77
|
-
} catch (error) {
|
|
78
|
-
_db.exec("ROLLBACK");
|
|
79
|
-
throw new Error(
|
|
80
|
-
`Migration ${migration.id} (${migration.name}) failed: ${error instanceof Error ? error.message : String(error)}`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return _db;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function closeDatabase(): void {
|
|
89
|
-
if (_db) {
|
|
90
|
-
_db.close();
|
|
91
|
-
_db = null;
|
|
92
|
-
}
|
|
93
|
-
}
|