@hasna/microservices 0.0.16 → 0.0.18

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.
Files changed (293) hide show
  1. package/README.md +143 -23
  2. package/bin/index.js +784 -13987
  3. package/bin/mcp.js +298 -10973
  4. package/dist/index.js +251 -10056
  5. package/package.json +36 -26
  6. package/microservices/microservice-ads/package.json +0 -28
  7. package/microservices/microservice-ads/src/cli/index.ts +0 -605
  8. package/microservices/microservice-ads/src/db/campaigns.ts +0 -797
  9. package/microservices/microservice-ads/src/db/database.ts +0 -91
  10. package/microservices/microservice-ads/src/db/migrations.ts +0 -60
  11. package/microservices/microservice-ads/src/index.ts +0 -39
  12. package/microservices/microservice-ads/src/mcp/index.ts +0 -480
  13. package/microservices/microservice-analytics/package.json +0 -28
  14. package/microservices/microservice-analytics/src/cli/index.ts +0 -373
  15. package/microservices/microservice-analytics/src/db/analytics.ts +0 -564
  16. package/microservices/microservice-analytics/src/db/database.ts +0 -91
  17. package/microservices/microservice-analytics/src/db/migrations.ts +0 -50
  18. package/microservices/microservice-analytics/src/index.ts +0 -37
  19. package/microservices/microservice-analytics/src/mcp/index.ts +0 -334
  20. package/microservices/microservice-assets/package.json +0 -28
  21. package/microservices/microservice-assets/src/cli/index.ts +0 -375
  22. package/microservices/microservice-assets/src/db/assets.ts +0 -370
  23. package/microservices/microservice-assets/src/db/database.ts +0 -91
  24. package/microservices/microservice-assets/src/db/migrations.ts +0 -51
  25. package/microservices/microservice-assets/src/index.ts +0 -32
  26. package/microservices/microservice-assets/src/mcp/index.ts +0 -346
  27. package/microservices/microservice-bookkeeping/package.json +0 -28
  28. package/microservices/microservice-bookkeeping/src/cli/index.ts +0 -386
  29. package/microservices/microservice-bookkeeping/src/db/bookkeeping.ts +0 -591
  30. package/microservices/microservice-bookkeeping/src/db/database.ts +0 -91
  31. package/microservices/microservice-bookkeeping/src/db/migrations.ts +0 -52
  32. package/microservices/microservice-bookkeeping/src/index.ts +0 -32
  33. package/microservices/microservice-bookkeeping/src/mcp/index.ts +0 -284
  34. package/microservices/microservice-calendar/package.json +0 -28
  35. package/microservices/microservice-calendar/src/cli/index.ts +0 -287
  36. package/microservices/microservice-calendar/src/db/calendar.ts +0 -328
  37. package/microservices/microservice-calendar/src/db/database.ts +0 -91
  38. package/microservices/microservice-calendar/src/db/migrations.ts +0 -47
  39. package/microservices/microservice-calendar/src/index.ts +0 -24
  40. package/microservices/microservice-calendar/src/mcp/index.ts +0 -226
  41. package/microservices/microservice-company/package.json +0 -28
  42. package/microservices/microservice-company/src/cli/index.ts +0 -1126
  43. package/microservices/microservice-company/src/db/company.ts +0 -854
  44. package/microservices/microservice-company/src/db/database.ts +0 -91
  45. package/microservices/microservice-company/src/db/migrations.ts +0 -214
  46. package/microservices/microservice-company/src/db/workflow-migrations.ts +0 -44
  47. package/microservices/microservice-company/src/index.ts +0 -60
  48. package/microservices/microservice-company/src/lib/audit.ts +0 -168
  49. package/microservices/microservice-company/src/lib/finance.ts +0 -299
  50. package/microservices/microservice-company/src/lib/settings.ts +0 -85
  51. package/microservices/microservice-company/src/lib/workflows.ts +0 -698
  52. package/microservices/microservice-company/src/mcp/index.ts +0 -991
  53. package/microservices/microservice-compliance/package.json +0 -28
  54. package/microservices/microservice-compliance/src/cli/index.ts +0 -467
  55. package/microservices/microservice-compliance/src/db/compliance.ts +0 -633
  56. package/microservices/microservice-compliance/src/db/database.ts +0 -91
  57. package/microservices/microservice-compliance/src/db/migrations.ts +0 -63
  58. package/microservices/microservice-compliance/src/index.ts +0 -46
  59. package/microservices/microservice-compliance/src/mcp/index.ts +0 -438
  60. package/microservices/microservice-contacts/package.json +0 -28
  61. package/microservices/microservice-contacts/src/cli/index.ts +0 -393
  62. package/microservices/microservice-contacts/src/db/companies.ts +0 -167
  63. package/microservices/microservice-contacts/src/db/contacts.ts +0 -249
  64. package/microservices/microservice-contacts/src/db/database.ts +0 -91
  65. package/microservices/microservice-contacts/src/db/migrations.ts +0 -71
  66. package/microservices/microservice-contacts/src/db/relationships.ts +0 -53
  67. package/microservices/microservice-contacts/src/index.ts +0 -42
  68. package/microservices/microservice-contacts/src/mcp/index.ts +0 -303
  69. package/microservices/microservice-contracts/package.json +0 -28
  70. package/microservices/microservice-contracts/src/cli/index.ts +0 -770
  71. package/microservices/microservice-contracts/src/db/contracts.ts +0 -925
  72. package/microservices/microservice-contracts/src/db/database.ts +0 -91
  73. package/microservices/microservice-contracts/src/db/migrations.ts +0 -141
  74. package/microservices/microservice-contracts/src/index.ts +0 -43
  75. package/microservices/microservice-contracts/src/mcp/index.ts +0 -617
  76. package/microservices/microservice-crm/package.json +0 -28
  77. package/microservices/microservice-crm/src/cli/index.ts +0 -396
  78. package/microservices/microservice-crm/src/db/database.ts +0 -91
  79. package/microservices/microservice-crm/src/db/migrations.ts +0 -66
  80. package/microservices/microservice-crm/src/db/pipeline.ts +0 -397
  81. package/microservices/microservice-crm/src/index.ts +0 -34
  82. package/microservices/microservice-crm/src/mcp/index.ts +0 -294
  83. package/microservices/microservice-documents/package.json +0 -28
  84. package/microservices/microservice-documents/src/cli/index.ts +0 -246
  85. package/microservices/microservice-documents/src/db/database.ts +0 -91
  86. package/microservices/microservice-documents/src/db/documents.ts +0 -316
  87. package/microservices/microservice-documents/src/db/migrations.ts +0 -49
  88. package/microservices/microservice-documents/src/index.ts +0 -24
  89. package/microservices/microservice-documents/src/mcp/index.ts +0 -202
  90. package/microservices/microservice-domains/package.json +0 -28
  91. package/microservices/microservice-domains/src/cli/index.ts +0 -1111
  92. package/microservices/microservice-domains/src/db/database.ts +0 -91
  93. package/microservices/microservice-domains/src/db/domains.ts +0 -1164
  94. package/microservices/microservice-domains/src/db/migrations.ts +0 -60
  95. package/microservices/microservice-domains/src/index.ts +0 -65
  96. package/microservices/microservice-domains/src/lib/brandsight.ts +0 -350
  97. package/microservices/microservice-domains/src/lib/godaddy.ts +0 -338
  98. package/microservices/microservice-domains/src/lib/namecheap.ts +0 -262
  99. package/microservices/microservice-domains/src/lib/registrar.ts +0 -355
  100. package/microservices/microservice-domains/src/mcp/index.ts +0 -781
  101. package/microservices/microservice-expenses/package.json +0 -28
  102. package/microservices/microservice-expenses/src/cli/index.ts +0 -267
  103. package/microservices/microservice-expenses/src/db/database.ts +0 -91
  104. package/microservices/microservice-expenses/src/db/expenses.ts +0 -345
  105. package/microservices/microservice-expenses/src/db/migrations.ts +0 -45
  106. package/microservices/microservice-expenses/src/index.ts +0 -25
  107. package/microservices/microservice-expenses/src/mcp/index.ts +0 -196
  108. package/microservices/microservice-habits/package.json +0 -28
  109. package/microservices/microservice-habits/src/cli/index.ts +0 -315
  110. package/microservices/microservice-habits/src/db/database.ts +0 -91
  111. package/microservices/microservice-habits/src/db/habits.ts +0 -451
  112. package/microservices/microservice-habits/src/db/migrations.ts +0 -46
  113. package/microservices/microservice-habits/src/index.ts +0 -31
  114. package/microservices/microservice-habits/src/mcp/index.ts +0 -313
  115. package/microservices/microservice-health/package.json +0 -28
  116. package/microservices/microservice-health/src/cli/index.ts +0 -484
  117. package/microservices/microservice-health/src/db/database.ts +0 -91
  118. package/microservices/microservice-health/src/db/health.ts +0 -708
  119. package/microservices/microservice-health/src/db/migrations.ts +0 -70
  120. package/microservices/microservice-health/src/index.ts +0 -63
  121. package/microservices/microservice-health/src/mcp/index.ts +0 -437
  122. package/microservices/microservice-hiring/package.json +0 -28
  123. package/microservices/microservice-hiring/src/cli/index.ts +0 -741
  124. package/microservices/microservice-hiring/src/db/database.ts +0 -91
  125. package/microservices/microservice-hiring/src/db/hiring.ts +0 -1085
  126. package/microservices/microservice-hiring/src/db/migrations.ts +0 -89
  127. package/microservices/microservice-hiring/src/index.ts +0 -80
  128. package/microservices/microservice-hiring/src/lib/scoring.ts +0 -206
  129. package/microservices/microservice-hiring/src/mcp/index.ts +0 -709
  130. package/microservices/microservice-inventory/package.json +0 -28
  131. package/microservices/microservice-inventory/src/cli/index.ts +0 -365
  132. package/microservices/microservice-inventory/src/db/database.ts +0 -91
  133. package/microservices/microservice-inventory/src/db/inventory.ts +0 -393
  134. package/microservices/microservice-inventory/src/db/migrations.ts +0 -54
  135. package/microservices/microservice-inventory/src/index.ts +0 -28
  136. package/microservices/microservice-inventory/src/mcp/index.ts +0 -250
  137. package/microservices/microservice-invoices/dashboard/index.html +0 -12
  138. package/microservices/microservice-invoices/dashboard/package.json +0 -29
  139. package/microservices/microservice-invoices/dashboard/tsconfig.json +0 -14
  140. package/microservices/microservice-invoices/dashboard/vite.config.ts +0 -15
  141. package/microservices/microservice-invoices/package.json +0 -31
  142. package/microservices/microservice-invoices/src/cli/index.ts +0 -308
  143. package/microservices/microservice-invoices/src/db/business.ts +0 -241
  144. package/microservices/microservice-invoices/src/db/clients.ts +0 -127
  145. package/microservices/microservice-invoices/src/db/database.ts +0 -91
  146. package/microservices/microservice-invoices/src/db/invoices.ts +0 -345
  147. package/microservices/microservice-invoices/src/db/migrations.ts +0 -184
  148. package/microservices/microservice-invoices/src/index.ts +0 -56
  149. package/microservices/microservice-invoices/src/mcp/index.ts +0 -242
  150. package/microservices/microservice-invoices/src/server/index.ts +0 -162
  151. package/microservices/microservice-leads/package.json +0 -28
  152. package/microservices/microservice-leads/src/cli/index.ts +0 -596
  153. package/microservices/microservice-leads/src/db/database.ts +0 -91
  154. package/microservices/microservice-leads/src/db/leads.ts +0 -520
  155. package/microservices/microservice-leads/src/db/lists.ts +0 -151
  156. package/microservices/microservice-leads/src/db/migrations.ts +0 -93
  157. package/microservices/microservice-leads/src/index.ts +0 -65
  158. package/microservices/microservice-leads/src/lib/enrichment.ts +0 -202
  159. package/microservices/microservice-leads/src/lib/scoring.ts +0 -134
  160. package/microservices/microservice-leads/src/mcp/index.ts +0 -533
  161. package/microservices/microservice-notes/package.json +0 -28
  162. package/microservices/microservice-notes/src/cli/index.ts +0 -63
  163. package/microservices/microservice-notes/src/db/database.ts +0 -91
  164. package/microservices/microservice-notes/src/db/migrations.ts +0 -40
  165. package/microservices/microservice-notes/src/db/notes.ts +0 -114
  166. package/microservices/microservice-notes/src/index.ts +0 -2
  167. package/microservices/microservice-notes/src/mcp/index.ts +0 -37
  168. package/microservices/microservice-notifications/package.json +0 -28
  169. package/microservices/microservice-notifications/src/cli/index.ts +0 -349
  170. package/microservices/microservice-notifications/src/db/database.ts +0 -91
  171. package/microservices/microservice-notifications/src/db/migrations.ts +0 -62
  172. package/microservices/microservice-notifications/src/db/notifications.ts +0 -509
  173. package/microservices/microservice-notifications/src/index.ts +0 -41
  174. package/microservices/microservice-notifications/src/mcp/index.ts +0 -422
  175. package/microservices/microservice-payments/package.json +0 -28
  176. package/microservices/microservice-payments/src/cli/index.ts +0 -609
  177. package/microservices/microservice-payments/src/db/database.ts +0 -91
  178. package/microservices/microservice-payments/src/db/migrations.ts +0 -81
  179. package/microservices/microservice-payments/src/db/payments.ts +0 -1204
  180. package/microservices/microservice-payments/src/index.ts +0 -51
  181. package/microservices/microservice-payments/src/mcp/index.ts +0 -683
  182. package/microservices/microservice-payroll/package.json +0 -28
  183. package/microservices/microservice-payroll/src/cli/index.ts +0 -643
  184. package/microservices/microservice-payroll/src/db/database.ts +0 -91
  185. package/microservices/microservice-payroll/src/db/migrations.ts +0 -95
  186. package/microservices/microservice-payroll/src/db/payroll.ts +0 -1377
  187. package/microservices/microservice-payroll/src/index.ts +0 -48
  188. package/microservices/microservice-payroll/src/mcp/index.ts +0 -666
  189. package/microservices/microservice-products/package.json +0 -28
  190. package/microservices/microservice-products/src/cli/index.ts +0 -416
  191. package/microservices/microservice-products/src/db/categories.ts +0 -154
  192. package/microservices/microservice-products/src/db/database.ts +0 -91
  193. package/microservices/microservice-products/src/db/migrations.ts +0 -58
  194. package/microservices/microservice-products/src/db/pricing-tiers.ts +0 -66
  195. package/microservices/microservice-products/src/db/products.ts +0 -452
  196. package/microservices/microservice-products/src/index.ts +0 -53
  197. package/microservices/microservice-products/src/mcp/index.ts +0 -453
  198. package/microservices/microservice-projects/package.json +0 -28
  199. package/microservices/microservice-projects/src/cli/index.ts +0 -480
  200. package/microservices/microservice-projects/src/db/database.ts +0 -91
  201. package/microservices/microservice-projects/src/db/migrations.ts +0 -65
  202. package/microservices/microservice-projects/src/db/projects.ts +0 -715
  203. package/microservices/microservice-projects/src/index.ts +0 -57
  204. package/microservices/microservice-projects/src/mcp/index.ts +0 -501
  205. package/microservices/microservice-proposals/package.json +0 -28
  206. package/microservices/microservice-proposals/src/cli/index.ts +0 -400
  207. package/microservices/microservice-proposals/src/db/database.ts +0 -91
  208. package/microservices/microservice-proposals/src/db/migrations.ts +0 -52
  209. package/microservices/microservice-proposals/src/db/proposals.ts +0 -532
  210. package/microservices/microservice-proposals/src/index.ts +0 -37
  211. package/microservices/microservice-proposals/src/mcp/index.ts +0 -375
  212. package/microservices/microservice-reading/package.json +0 -28
  213. package/microservices/microservice-reading/src/cli/index.ts +0 -464
  214. package/microservices/microservice-reading/src/db/database.ts +0 -91
  215. package/microservices/microservice-reading/src/db/migrations.ts +0 -59
  216. package/microservices/microservice-reading/src/db/reading.ts +0 -524
  217. package/microservices/microservice-reading/src/index.ts +0 -51
  218. package/microservices/microservice-reading/src/mcp/index.ts +0 -368
  219. package/microservices/microservice-shipping/package.json +0 -28
  220. package/microservices/microservice-shipping/src/cli/index.ts +0 -606
  221. package/microservices/microservice-shipping/src/db/database.ts +0 -91
  222. package/microservices/microservice-shipping/src/db/migrations.ts +0 -69
  223. package/microservices/microservice-shipping/src/db/shipping.ts +0 -1093
  224. package/microservices/microservice-shipping/src/index.ts +0 -53
  225. package/microservices/microservice-shipping/src/mcp/index.ts +0 -533
  226. package/microservices/microservice-social/package.json +0 -29
  227. package/microservices/microservice-social/src/cli/index.ts +0 -1583
  228. package/microservices/microservice-social/src/db/database.ts +0 -91
  229. package/microservices/microservice-social/src/db/migrations.ts +0 -160
  230. package/microservices/microservice-social/src/db/social.ts +0 -1076
  231. package/microservices/microservice-social/src/index.ts +0 -46
  232. package/microservices/microservice-social/src/lib/audience.ts +0 -353
  233. package/microservices/microservice-social/src/lib/content-ai.ts +0 -278
  234. package/microservices/microservice-social/src/lib/media.ts +0 -311
  235. package/microservices/microservice-social/src/lib/mentions.ts +0 -434
  236. package/microservices/microservice-social/src/lib/metrics-sync.ts +0 -264
  237. package/microservices/microservice-social/src/lib/publisher.ts +0 -377
  238. package/microservices/microservice-social/src/lib/scheduler.ts +0 -229
  239. package/microservices/microservice-social/src/lib/sentiment.ts +0 -256
  240. package/microservices/microservice-social/src/lib/threads.ts +0 -291
  241. package/microservices/microservice-social/src/mcp/index.ts +0 -1425
  242. package/microservices/microservice-social/src/server/index.ts +0 -441
  243. package/microservices/microservice-subscriptions/package.json +0 -28
  244. package/microservices/microservice-subscriptions/src/cli/index.ts +0 -715
  245. package/microservices/microservice-subscriptions/src/db/database.ts +0 -91
  246. package/microservices/microservice-subscriptions/src/db/migrations.ts +0 -125
  247. package/microservices/microservice-subscriptions/src/db/subscriptions.ts +0 -1256
  248. package/microservices/microservice-subscriptions/src/index.ts +0 -41
  249. package/microservices/microservice-subscriptions/src/mcp/index.ts +0 -631
  250. package/microservices/microservice-timesheets/package.json +0 -28
  251. package/microservices/microservice-timesheets/src/cli/index.ts +0 -373
  252. package/microservices/microservice-timesheets/src/db/database.ts +0 -91
  253. package/microservices/microservice-timesheets/src/db/locale.ts +0 -217
  254. package/microservices/microservice-timesheets/src/db/migrations.ts +0 -74
  255. package/microservices/microservice-timesheets/src/db/timesheets.ts +0 -447
  256. package/microservices/microservice-timesheets/src/index.ts +0 -44
  257. package/microservices/microservice-timesheets/src/mcp/index.ts +0 -269
  258. package/microservices/microservice-transcriber/package.json +0 -29
  259. package/microservices/microservice-transcriber/src/cli/index.ts +0 -1593
  260. package/microservices/microservice-transcriber/src/db/annotations.ts +0 -37
  261. package/microservices/microservice-transcriber/src/db/comments.ts +0 -166
  262. package/microservices/microservice-transcriber/src/db/database.ts +0 -91
  263. package/microservices/microservice-transcriber/src/db/migrations.ts +0 -118
  264. package/microservices/microservice-transcriber/src/db/proofread.ts +0 -119
  265. package/microservices/microservice-transcriber/src/db/transcripts.ts +0 -395
  266. package/microservices/microservice-transcriber/src/index.ts +0 -43
  267. package/microservices/microservice-transcriber/src/lib/config.ts +0 -77
  268. package/microservices/microservice-transcriber/src/lib/diff.ts +0 -91
  269. package/microservices/microservice-transcriber/src/lib/downloader.ts +0 -638
  270. package/microservices/microservice-transcriber/src/lib/feeds.ts +0 -62
  271. package/microservices/microservice-transcriber/src/lib/live.ts +0 -94
  272. package/microservices/microservice-transcriber/src/lib/notion.ts +0 -129
  273. package/microservices/microservice-transcriber/src/lib/proofread.ts +0 -296
  274. package/microservices/microservice-transcriber/src/lib/providers.ts +0 -713
  275. package/microservices/microservice-transcriber/src/lib/summarizer.ts +0 -147
  276. package/microservices/microservice-transcriber/src/lib/translator.ts +0 -75
  277. package/microservices/microservice-transcriber/src/lib/webhook.ts +0 -37
  278. package/microservices/microservice-transcriber/src/mcp/index.ts +0 -1330
  279. package/microservices/microservice-transcriber/src/server/index.ts +0 -199
  280. package/microservices/microservice-travel/package.json +0 -28
  281. package/microservices/microservice-travel/src/cli/index.ts +0 -505
  282. package/microservices/microservice-travel/src/db/database.ts +0 -91
  283. package/microservices/microservice-travel/src/db/migrations.ts +0 -77
  284. package/microservices/microservice-travel/src/db/travel.ts +0 -802
  285. package/microservices/microservice-travel/src/index.ts +0 -60
  286. package/microservices/microservice-travel/src/mcp/index.ts +0 -495
  287. package/microservices/microservice-wiki/package.json +0 -28
  288. package/microservices/microservice-wiki/src/cli/index.ts +0 -345
  289. package/microservices/microservice-wiki/src/db/database.ts +0 -91
  290. package/microservices/microservice-wiki/src/db/migrations.ts +0 -55
  291. package/microservices/microservice-wiki/src/db/wiki.ts +0 -395
  292. package/microservices/microservice-wiki/src/index.ts +0 -32
  293. package/microservices/microservice-wiki/src/mcp/index.ts +0 -344
@@ -1,1593 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- import { Command } from "commander";
4
- import { writeFileSync } from "node:fs";
5
- import {
6
- createTranscript,
7
- getTranscript,
8
- updateTranscript,
9
- deleteTranscript,
10
- listTranscripts,
11
- searchTranscripts,
12
- countTranscripts,
13
- renameSpeakers,
14
- findBySourceUrl,
15
- addTags,
16
- removeTags,
17
- getTags,
18
- listAllTags,
19
- listTranscriptsByTag,
20
- searchWithContext,
21
- type TranscriptProvider,
22
- type TranscriptStatus,
23
- type TranscriptSourceType,
24
- } from "../db/transcripts.js";
25
- import { prepareAudio, detectSourceType, getVideoInfo, downloadAudio, downloadVideo, createClip, isPlaylistUrl, getPlaylistUrls, fetchComments, type TrimOptions } from "../lib/downloader.js";
26
- import { createComment, listComments, searchComments, getCommentStats, getTopComments, importComments } from "../db/comments.js";
27
- import { transcribeFile, checkProviders, toSrt, toVtt, toAss, toMarkdown, segmentByChapters, formatWithConfidence, estimateCost } from "../lib/providers.js";
28
- import { getConfig, setConfig, resetConfig, CONFIG_DEFAULTS, CONFIG_KEYS, type ConfigKey } from "../lib/config.js";
29
- import { summarizeText, extractHighlights, generateMeetingNotes, getDefaultSummaryProvider } from "../lib/summarizer.js";
30
- import { translateText } from "../lib/translator.js";
31
- import { fetchFeedEpisodes } from "../lib/feeds.js";
32
- import { fireWebhook } from "../lib/webhook.js";
33
- import { createAnnotation, listAnnotations, deleteAnnotation, formatTimestamp as fmtAnnoTs } from "../db/annotations.js";
34
- import { pushToNotion } from "../lib/notion.js";
35
- import { startLiveTranscription } from "../lib/live.js";
36
- import { wordDiff, formatDiff, diffStats } from "../lib/diff.js";
37
- import { proofreadTranscript, listIssues, applySuggestion, dismissIssue, getProofreadStats, exportAnnotated, type IssueType } from "../lib/proofread.js";
38
-
39
- const program = new Command();
40
-
41
- program
42
- .name("microservice-transcriber")
43
- .description("Transcribe audio and video from files and URLs using ElevenLabs or OpenAI")
44
- .version("0.0.1");
45
-
46
- // ---------------------------------------------------------------------------
47
- // transcribe
48
- // ---------------------------------------------------------------------------
49
-
50
- program
51
- .command("transcribe <sources...>")
52
- .description("Transcribe one or more files or URLs (YouTube, Vimeo, Wistia, etc.)")
53
- .option("--provider <provider>", "Provider: elevenlabs or openai (uses config default)")
54
- .option("--language <lang>", "Language code (e.g. en, fr, de). Auto-detected if omitted.")
55
- .option("--title <title>", "Title (only used when transcribing a single source)")
56
- .option("--start <seconds>", "Start time in seconds (trim audio before transcribing)", parseFloat)
57
- .option("--end <seconds>", "End time in seconds (trim audio before transcribing)", parseFloat)
58
- .option("--diarize", "Identify different speakers (ElevenLabs only)")
59
- .option("--vocab <words>", "Custom vocabulary hints (comma-separated, e.g. 'Karpathy,MicroGPT,SABR')")
60
- .option("--summarize", "Auto-summarize after transcription using AI")
61
- .option("--comments", "Also fetch and store YouTube/Vimeo comments")
62
- .option("--force", "Re-transcribe even if URL was already transcribed")
63
- .option("--json", "Output as JSON")
64
- .action(async (rawSources: string[], opts) => {
65
- let sources = rawSources;
66
- const cfg = getConfig();
67
- const provider = (opts.provider ?? cfg.defaultProvider) as TranscriptProvider;
68
- const language = opts.language ?? (cfg.defaultLanguage !== "en" ? cfg.defaultLanguage : undefined);
69
- const diarize = opts.diarize ?? cfg.diarize;
70
- const available = checkProviders();
71
-
72
- if (provider === "elevenlabs" && !available.elevenlabs) {
73
- console.error("Error: ELEVENLABS_API_KEY is not set.");
74
- process.exit(1);
75
- }
76
- if (provider === "openai" && !available.openai) {
77
- console.error("Error: OPENAI_API_KEY is not set.");
78
- process.exit(1);
79
- }
80
-
81
- if (diarize && provider !== "elevenlabs") {
82
- console.error("Warning: --diarize is only supported with ElevenLabs. Ignoring.");
83
- }
84
-
85
- const trim: TrimOptions | undefined =
86
- opts.start !== undefined || opts.end !== undefined
87
- ? { start: opts.start, end: opts.end }
88
- : undefined;
89
-
90
- // Expand playlist URLs into individual video URLs
91
- const expandedSources: string[] = [];
92
- for (const src of sources) {
93
- if (isPlaylistUrl(src)) {
94
- if (!opts.json) console.log(`Expanding playlist ${src}...`);
95
- try {
96
- const videos = await getPlaylistUrls(src);
97
- if (!opts.json) console.log(` Found ${videos.length} video(s)`);
98
- expandedSources.push(...videos.map((v) => v.url));
99
- } catch (e) {
100
- console.error(`Failed to expand playlist: ${e instanceof Error ? e.message : e}`);
101
- expandedSources.push(src); // fallback: try as single video
102
- }
103
- } else {
104
- expandedSources.push(src);
105
- }
106
- }
107
- sources = expandedSources;
108
-
109
- const isBatch = sources.length > 1;
110
- const results: Array<{ source: string; id: string; success: boolean; error?: string }> = [];
111
-
112
- for (let i = 0; i < sources.length; i++) {
113
- const source = sources[i];
114
- if (!opts.json && isBatch) {
115
- console.log(`\n[${i + 1}/${sources.length}] Transcribing ${source}...`);
116
- }
117
-
118
- // Duplicate detection
119
- if (!opts.force) {
120
- const existing = findBySourceUrl(source);
121
- if (existing) {
122
- if (!opts.json) {
123
- console.log(` Already transcribed: ${existing.id.slice(0, 8)} "${existing.title ?? source}". Use --force to re-transcribe.`);
124
- }
125
- results.push({ source, id: existing.id, success: true });
126
- continue;
127
- }
128
- }
129
-
130
- const sourceType = detectSourceType(source);
131
- const record = createTranscript({
132
- source_url: source,
133
- source_type: sourceType,
134
- provider,
135
- language,
136
- title: !isBatch ? opts.title : undefined,
137
- });
138
-
139
- if (!opts.json && !isBatch) {
140
- const trimStr = trim ? ` [${trim.start ?? 0}s → ${trim.end ?? "end"}]` : "";
141
- console.log(`Transcribing ${source} [${sourceType}]${trimStr} with ${provider}...`);
142
- }
143
-
144
- updateTranscript(record.id, { status: "processing" });
145
-
146
- let audio: Awaited<ReturnType<typeof prepareAudio>> | null = null;
147
- try {
148
- audio = await prepareAudio(source, trim);
149
-
150
- if (!isBatch && !opts.title && audio.videoTitle) {
151
- updateTranscript(record.id, { title: audio.videoTitle });
152
- } else if (isBatch && audio.videoTitle) {
153
- updateTranscript(record.id, { title: audio.videoTitle });
154
- }
155
-
156
- const vocabList = [
157
- ...(cfg.vocab ?? []),
158
- ...(opts.vocab ? opts.vocab.split(",").map((v: string) => v.trim()) : []),
159
- ].filter(Boolean);
160
-
161
- const result = await transcribeFile(audio.filePath, {
162
- provider,
163
- language,
164
- diarize: diarize && provider === "elevenlabs",
165
- vocab: vocabList.length > 0 ? vocabList : undefined,
166
- });
167
-
168
- const chapterSegments = audio.chapters.length > 0 && result.metadata.words
169
- ? segmentByChapters(result.metadata.words, audio.chapters)
170
- : undefined;
171
-
172
- const cost = result.duration_seconds ? estimateCost(provider, result.duration_seconds) : undefined;
173
-
174
- const updated = updateTranscript(record.id, {
175
- status: "completed",
176
- transcript_text: result.text,
177
- duration_seconds: result.duration_seconds ?? undefined,
178
- word_count: result.text.split(/\s+/).filter(Boolean).length,
179
- metadata: {
180
- ...result.metadata,
181
- ...(trim ? { trim_start: trim.start, trim_end: trim.end } : {}),
182
- ...(chapterSegments ? { chapters: chapterSegments } : {}),
183
- ...(cost !== undefined ? { cost_usd: cost } : {}),
184
- },
185
- });
186
-
187
- // Auto-summarize if requested
188
- if (opts.summarize && result.text) {
189
- try {
190
- if (!opts.json) process.stdout.write(" Summarizing...");
191
- const summary = await summarizeText(result.text);
192
- updateTranscript(record.id, {
193
- metadata: { ...updated?.metadata, summary },
194
- });
195
- if (!opts.json) console.log(" done.");
196
- } catch (e) {
197
- if (!opts.json) console.error(` Warning: summarize failed — ${e instanceof Error ? e.message : e}`);
198
- }
199
- }
200
-
201
- // Fire webhook
202
- fireWebhook({
203
- event: "transcription.completed", id: record.id, title: getTranscript(record.id)?.title ?? null,
204
- status: "completed", source_url: source, provider, duration_seconds: result.duration_seconds,
205
- word_count: result.text.split(/\s+/).filter(Boolean).length, timestamp: new Date().toISOString(),
206
- });
207
-
208
- // Fetch comments if requested
209
- if (opts.comments && (sourceType === "youtube" || sourceType === "vimeo")) {
210
- try {
211
- if (!opts.json) process.stdout.write(" Fetching comments...");
212
- const rawComments = await fetchComments(source);
213
- if (rawComments.length > 0) {
214
- const mapped = rawComments.map((c) => ({
215
- platform: sourceType,
216
- author: c.author,
217
- author_handle: c.author_id,
218
- comment_text: c.text,
219
- likes: c.like_count,
220
- reply_count: 0,
221
- is_reply: c.parent !== null,
222
- parent_comment_id: c.parent,
223
- published_at: c.timestamp ? new Date(c.timestamp * 1000).toISOString() : null,
224
- }));
225
- importComments(record.id, mapped);
226
- if (!opts.json) console.log(` ${rawComments.length} comment(s) imported.`);
227
- } else {
228
- if (!opts.json) console.log(" no comments found.");
229
- }
230
- } catch (e) {
231
- if (!opts.json) console.error(` Warning: comment fetch failed — ${e instanceof Error ? e.message : e}`);
232
- }
233
- }
234
-
235
- results.push({ source, id: record.id, success: true });
236
-
237
- if (opts.json && !isBatch) {
238
- console.log(JSON.stringify(getTranscript(record.id), null, 2));
239
- } else if (!opts.json && !isBatch) {
240
- console.log(`\nTranscript ID: ${record.id}`);
241
- console.log(`Duration: ${result.duration_seconds ? `${result.duration_seconds.toFixed(1)}s` : "unknown"}`);
242
- console.log(`Language: ${result.language}`);
243
- console.log(`\n--- Transcript ---\n`);
244
- console.log(result.text);
245
- } else if (!opts.json) {
246
- console.log(` ✓ ${record.id.slice(0, 8)} — ${audio.videoTitle ?? source.slice(0, 60)}`);
247
- }
248
- } catch (error) {
249
- const msg = error instanceof Error ? error.message : String(error);
250
- updateTranscript(record.id, { status: "failed", error_message: msg });
251
- fireWebhook({
252
- event: "transcription.failed", id: record.id, title: null,
253
- status: "failed", source_url: source, provider, duration_seconds: null,
254
- word_count: null, timestamp: new Date().toISOString(),
255
- });
256
- results.push({ source, id: record.id, success: false, error: msg });
257
- if (!opts.json) console.error(` ✗ ${msg}`);
258
- } finally {
259
- audio?.cleanup();
260
- }
261
- }
262
-
263
- if (isBatch) {
264
- const succeeded = results.filter((r) => r.success).length;
265
- const failed = results.filter((r) => !r.success).length;
266
- if (opts.json) {
267
- console.log(JSON.stringify({ results, summary: { succeeded, failed, total: sources.length } }, null, 2));
268
- } else {
269
- console.log(`\nDone: ${succeeded} completed, ${failed} failed.`);
270
- }
271
- if (failed > 0) process.exit(1);
272
- }
273
- });
274
-
275
- // ---------------------------------------------------------------------------
276
- // live
277
- // ---------------------------------------------------------------------------
278
-
279
- program
280
- .command("live")
281
- .description("Transcribe from microphone in real-time (stop with Ctrl+C)")
282
- .option("--provider <provider>", "Provider (uses config default)")
283
- .option("--language <lang>", "Language code")
284
- .option("--chunk-duration <seconds>", "Seconds per chunk (default: 30)", parseInt)
285
- .option("--title <title>", "Title for the saved transcript")
286
- .action(async (opts) => {
287
- const cfg = getConfig();
288
- const provider = (opts.provider ?? cfg.defaultProvider) as TranscriptProvider;
289
- const available = checkProviders();
290
-
291
- if (provider === "elevenlabs" && !available.elevenlabs) { console.error("ELEVENLABS_API_KEY not set."); process.exit(1); }
292
- if (provider === "openai" && !available.openai) { console.error("OPENAI_API_KEY not set."); process.exit(1); }
293
- if (provider === "deepgram" && !available.deepgram) { console.error("DEEPGRAM_API_KEY not set."); process.exit(1); }
294
-
295
- console.log(`Live transcription with ${provider}. Press Ctrl+C to stop.\n`);
296
-
297
- const session = startLiveTranscription({
298
- provider,
299
- language: opts.language,
300
- chunkDurationSec: opts.chunkDuration ?? 30,
301
- onChunk: (text, idx) => {
302
- console.log(`[chunk ${idx + 1}] ${text}`);
303
- },
304
- onError: (err, idx) => {
305
- console.error(`[chunk ${idx + 1}] Error: ${err.message}`);
306
- },
307
- });
308
-
309
- // Handle Ctrl+C
310
- process.on("SIGINT", async () => {
311
- console.log("\nStopping...");
312
- const result = await session.stop();
313
-
314
- if (result.fullText) {
315
- // Save to DB
316
- const record = createTranscript({
317
- source_url: "live:microphone",
318
- source_type: "file",
319
- provider,
320
- language: opts.language,
321
- title: opts.title ?? `Live recording ${new Date().toISOString().slice(0, 16)}`,
322
- });
323
- updateTranscript(record.id, {
324
- status: "completed",
325
- transcript_text: result.fullText,
326
- word_count: result.fullText.split(/\s+/).filter(Boolean).length,
327
- });
328
- console.log(`\nSaved transcript: ${record.id}`);
329
- console.log(`${result.chunks.length} chunk(s), ${result.fullText.split(/\s+/).length} words`);
330
- }
331
- process.exit(0);
332
- });
333
- });
334
-
335
- // ---------------------------------------------------------------------------
336
- // info
337
- // ---------------------------------------------------------------------------
338
-
339
- program
340
- .command("info <url>")
341
- .description("Fetch video metadata (title, duration, chapters) without downloading or transcribing")
342
- .option("--json", "Output as JSON")
343
- .action(async (url: string, opts) => {
344
- try {
345
- const info = await getVideoInfo(url);
346
-
347
- if (opts.json) {
348
- console.log(JSON.stringify(info, null, 2));
349
- return;
350
- }
351
-
352
- console.log(`Title: ${info.title ?? "(unknown)"}`);
353
- console.log(`Platform: ${info.platform ?? "(unknown)"}`);
354
- console.log(`Uploader: ${info.uploader ?? "(unknown)"}`);
355
- if (info.duration !== null) {
356
- const m = Math.floor(info.duration / 60);
357
- const s = Math.floor(info.duration % 60);
358
- console.log(`Duration: ${m}m ${s}s (${info.duration}s)`);
359
- }
360
- if (info.upload_date) {
361
- const d = info.upload_date;
362
- console.log(`Uploaded: ${d.slice(0, 4)}-${d.slice(4, 6)}-${d.slice(6, 8)}`);
363
- }
364
- if (info.view_count !== null) {
365
- console.log(`Views: ${info.view_count.toLocaleString()}`);
366
- }
367
- if (info.description) {
368
- console.log(`Description: ${info.description.slice(0, 120)}${info.description.length > 120 ? "…" : ""}`);
369
- }
370
- if (info.chapters.length > 0) {
371
- console.log(`\nChapters (${info.chapters.length}):`);
372
- for (const ch of info.chapters) {
373
- const m = Math.floor(ch.start_time / 60);
374
- const s = Math.floor(ch.start_time % 60);
375
- console.log(` ${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")} ${ch.title}`);
376
- }
377
- }
378
- } catch (error) {
379
- const msg = error instanceof Error ? error.message : String(error);
380
- console.error(`Error: ${msg}`);
381
- process.exit(1);
382
- }
383
- });
384
-
385
- // ---------------------------------------------------------------------------
386
- // download
387
- // ---------------------------------------------------------------------------
388
-
389
- program
390
- .command("download <url>")
391
- .description("Download audio from a URL without transcribing")
392
- .option("--format <fmt>", "Audio format: mp3 (default), m4a, wav", "mp3")
393
- .option("--output <path>", "Output file path (overrides auto-naming)")
394
- .option("--start <seconds>", "Start time in seconds", parseFloat)
395
- .option("--end <seconds>", "End time in seconds", parseFloat)
396
- .option("--json", "Output as JSON")
397
- .action(async (url: string, opts) => {
398
- if (!opts.json) console.log(`Downloading audio from ${url}...`);
399
-
400
- try {
401
- const trim = opts.start !== undefined || opts.end !== undefined
402
- ? { start: opts.start, end: opts.end }
403
- : undefined;
404
-
405
- const result = await downloadAudio(url, {
406
- format: opts.format,
407
- outputPath: opts.output,
408
- trim,
409
- });
410
-
411
- if (opts.json) {
412
- console.log(JSON.stringify(result, null, 2));
413
- } else {
414
- console.log(`Saved: ${result.filePath}`);
415
- if (result.title) console.log(`Title: ${result.title}`);
416
- if (result.duration) {
417
- const m = Math.floor(result.duration / 60);
418
- const s = Math.floor(result.duration % 60);
419
- console.log(`Duration: ${m}m ${s}s`);
420
- }
421
- }
422
- } catch (error) {
423
- console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
424
- process.exit(1);
425
- }
426
- });
427
-
428
- // ---------------------------------------------------------------------------
429
- // list
430
- // ---------------------------------------------------------------------------
431
-
432
- program
433
- .command("list")
434
- .description("List transcripts")
435
- .option("--status <status>", "Filter by status: pending, processing, completed, failed")
436
- .option("--provider <provider>", "Filter by provider: elevenlabs, openai")
437
- .option("--source-type <type>", "Filter by source type: file, youtube, vimeo, wistia, url")
438
- .option("--tag <tag>", "Filter by tag")
439
- .option("--limit <n>", "Max results", "20")
440
- .option("--offset <n>", "Offset", "0")
441
- .option("--json", "Output as JSON")
442
- .action((opts) => {
443
- const transcripts = opts.tag
444
- ? listTranscriptsByTag(opts.tag, parseInt(opts.limit))
445
- : listTranscripts({
446
- status: opts.status as TranscriptStatus | undefined,
447
- provider: opts.provider as TranscriptProvider | undefined,
448
- source_type: opts.sourceType as TranscriptSourceType | undefined,
449
- limit: parseInt(opts.limit),
450
- offset: parseInt(opts.offset),
451
- });
452
-
453
- if (opts.json) {
454
- console.log(JSON.stringify(transcripts, null, 2));
455
- return;
456
- }
457
-
458
- if (transcripts.length === 0) {
459
- console.log("No transcripts found.");
460
- return;
461
- }
462
-
463
- for (const t of transcripts) {
464
- const title = t.title || t.source_url?.slice(0, 60) || "(no source)";
465
- const duration = t.duration_seconds ? ` [${t.duration_seconds.toFixed(0)}s]` : "";
466
- const words = t.word_count ? ` ${t.word_count}w` : "";
467
- console.log(`${t.id.slice(0, 8)} ${t.status.padEnd(12)} ${t.provider.padEnd(11)} ${t.source_type.padEnd(8)}${duration}${words} ${title}`);
468
- }
469
- });
470
-
471
- // ---------------------------------------------------------------------------
472
- // get
473
- // ---------------------------------------------------------------------------
474
-
475
- program
476
- .command("get <id>")
477
- .description("Get a transcript by ID")
478
- .option("--show-confidence", "Flag low-confidence words with [?word?] markers (ElevenLabs only)")
479
- .option("--confidence-threshold <n>", "Confidence threshold 0-1 (default 0.7)", parseFloat)
480
- .option("--json", "Output as JSON")
481
- .action((id: string, opts) => {
482
- const t = getTranscript(id);
483
- if (!t) {
484
- console.error(`Transcript '${id}' not found.`);
485
- process.exit(1);
486
- }
487
-
488
- if (opts.json) {
489
- console.log(JSON.stringify(t, null, 2));
490
- return;
491
- }
492
-
493
- console.log(`ID: ${t.id}`);
494
- console.log(`Title: ${t.title ?? "(none)"}`);
495
- console.log(`Source: ${t.source_url ?? "(none)"} [${t.source_type}]`);
496
- console.log(`Provider: ${t.provider}`);
497
- console.log(`Language: ${t.language}`);
498
- console.log(`Status: ${t.status}`);
499
- if (t.duration_seconds) console.log(`Duration: ${t.duration_seconds.toFixed(1)}s`);
500
- if (t.word_count) console.log(`Words: ${t.word_count}`);
501
- console.log(`Created: ${t.created_at}`);
502
- if (t.metadata?.cost_usd) console.log(`Cost: $${t.metadata.cost_usd.toFixed(4)}`);
503
- const annos = listAnnotations(id);
504
- if (annos.length > 0) {
505
- console.log(`\n--- Annotations (${annos.length}) ---\n`);
506
- for (const a of annos) console.log(` [${fmtAnnoTs(a.timestamp_sec)}] ${a.note}`);
507
- }
508
- if (t.error_message) console.log(`Error: ${t.error_message}`);
509
- if (t.metadata?.summary) {
510
- console.log(`\n--- Summary ---\n`);
511
- console.log(t.metadata.summary);
512
- }
513
- if (t.metadata?.highlights && t.metadata.highlights.length > 0) {
514
- console.log(`\n--- Highlights (${t.metadata.highlights.length}) ---\n`);
515
- for (const h of t.metadata.highlights) {
516
- console.log(` "${h.quote}"${h.speaker ? ` (${h.speaker})` : ""}`);
517
- }
518
- }
519
- if (t.metadata?.chapters && t.metadata.chapters.length > 0) {
520
- console.log(`\n--- Chapters (${t.metadata.chapters.length}) ---\n`);
521
- for (const ch of t.metadata.chapters) {
522
- const m = Math.floor(ch.start_time / 60);
523
- const s = Math.floor(ch.start_time % 60);
524
- console.log(`${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")} ${ch.title}`);
525
- console.log(` ${ch.text.slice(0, 120)}${ch.text.length > 120 ? "…" : ""}`);
526
- }
527
- } else if (t.transcript_text) {
528
- console.log(`\n--- Transcript ---\n`);
529
- if (opts.showConfidence && t.metadata?.words?.length) {
530
- console.log(formatWithConfidence(t.metadata.words, opts.confidenceThreshold ?? 0.7));
531
- } else {
532
- console.log(t.transcript_text);
533
- }
534
- }
535
- });
536
-
537
- // ---------------------------------------------------------------------------
538
- // search
539
- // ---------------------------------------------------------------------------
540
-
541
- program
542
- .command("search <query>")
543
- .description("Search transcript text, titles, and source URLs")
544
- .option("--context <n>", "Show N sentences of context around each match", parseInt)
545
- .option("--json", "Output as JSON")
546
- .action((query: string, opts) => {
547
- if (opts.context !== undefined) {
548
- // Contextual search with excerpts + timestamps
549
- const matches = searchWithContext(query, opts.context);
550
- if (opts.json) { console.log(JSON.stringify(matches, null, 2)); return; }
551
- if (matches.length === 0) { console.log(`No transcripts matching '${query}'.`); return; }
552
- console.log(`Found ${matches.length} match(es):\n`);
553
- for (const m of matches) {
554
- const ts = m.timestamp ? ` ${m.timestamp}` : "";
555
- console.log(`${m.transcript_id.slice(0, 8)}${ts} ${m.title ?? "(untitled)"}`);
556
- console.log(` ${m.excerpt}\n`);
557
- }
558
- return;
559
- }
560
-
561
- const results = searchTranscripts(query);
562
- if (opts.json) { console.log(JSON.stringify(results, null, 2)); return; }
563
- if (results.length === 0) { console.log(`No transcripts matching '${query}'.`); return; }
564
- console.log(`Found ${results.length} transcript(s):\n`);
565
- for (const t of results) {
566
- const title = t.title || t.source_url?.slice(0, 60) || "(no source)";
567
- console.log(`${t.id.slice(0, 8)} ${title}`);
568
- }
569
- });
570
-
571
- // ---------------------------------------------------------------------------
572
- // retry
573
- // ---------------------------------------------------------------------------
574
-
575
- program
576
- .command("retry <id>")
577
- .description("Retry a failed or pending transcription (re-uses original source URL)")
578
- .option("--provider <provider>", "Override provider: elevenlabs or openai")
579
- .option("--diarize", "Identify different speakers (ElevenLabs only)")
580
- .option("--json", "Output as JSON")
581
- .action(async (id: string, opts) => {
582
- const t = getTranscript(id);
583
- if (!t) {
584
- console.error(`Transcript '${id}' not found.`);
585
- process.exit(1);
586
- }
587
-
588
- if (!t.source_url) {
589
- console.error(`Transcript '${id}' has no source URL to retry from.`);
590
- process.exit(1);
591
- }
592
-
593
- const provider = (opts.provider as TranscriptProvider | undefined) ?? t.provider;
594
- const providers = checkProviders();
595
-
596
- if (provider === "elevenlabs" && !providers.elevenlabs) {
597
- console.error("Error: ELEVENLABS_API_KEY is not set.");
598
- process.exit(1);
599
- }
600
- if (provider === "openai" && !providers.openai) {
601
- console.error("Error: OPENAI_API_KEY is not set.");
602
- process.exit(1);
603
- }
604
-
605
- if (!opts.json) {
606
- console.log(`Retrying transcript ${id} [${t.source_url}] with ${provider}...`);
607
- }
608
-
609
- updateTranscript(id, { status: "processing", error_message: null });
610
-
611
- let audio: Awaited<ReturnType<typeof prepareAudio>> | null = null;
612
- try {
613
- const trim = t.metadata?.trim_start !== undefined || t.metadata?.trim_end !== undefined
614
- ? { start: t.metadata.trim_start, end: t.metadata.trim_end }
615
- : undefined;
616
-
617
- audio = await prepareAudio(t.source_url, trim);
618
- const result = await transcribeFile(audio.filePath, {
619
- provider,
620
- language: t.language,
621
- diarize: opts.diarize && provider === "elevenlabs",
622
- });
623
-
624
- const updated = updateTranscript(id, {
625
- status: "completed",
626
- transcript_text: result.text,
627
- duration_seconds: result.duration_seconds ?? undefined,
628
- word_count: result.text.split(/\s+/).filter(Boolean).length,
629
- metadata: {
630
- ...result.metadata,
631
- ...(trim ? { trim_start: trim.start, trim_end: trim.end } : {}),
632
- },
633
- });
634
-
635
- if (opts.json) {
636
- console.log(JSON.stringify(updated, null, 2));
637
- } else {
638
- console.log(`\nRetry successful. Transcript ID: ${id}`);
639
- console.log(result.text);
640
- }
641
- } catch (error) {
642
- const msg = error instanceof Error ? error.message : String(error);
643
- updateTranscript(id, { status: "failed", error_message: msg });
644
- console.error(`Error: ${msg}`);
645
- process.exit(1);
646
- } finally {
647
- audio?.cleanup();
648
- }
649
- });
650
-
651
- // ---------------------------------------------------------------------------
652
- // delete
653
- // ---------------------------------------------------------------------------
654
-
655
- program
656
- .command("delete <id>")
657
- .description("Delete a transcript")
658
- .option("--json", "Output as JSON")
659
- .action((id: string, opts) => {
660
- const deleted = deleteTranscript(id);
661
- if (!deleted) {
662
- console.error(`Transcript '${id}' not found.`);
663
- process.exit(1);
664
- }
665
-
666
- if (opts.json) {
667
- console.log(JSON.stringify({ id, deleted: true }));
668
- } else {
669
- console.log(`Deleted transcript ${id}.`);
670
- }
671
- });
672
-
673
- // ---------------------------------------------------------------------------
674
- // export
675
- // ---------------------------------------------------------------------------
676
-
677
- program
678
- .command("export <id>")
679
- .description("Export a transcript in txt, srt, vtt, ass, md, or json format")
680
- .option("--format <fmt>", "Format: txt (default), srt, vtt, ass, md, json", "txt")
681
- .option("--output <file>", "Write to file instead of stdout")
682
- .option("--font <name>", "Font name for ASS format", "Arial")
683
- .option("--font-size <n>", "Font size for ASS format", "20")
684
- .option("--color <hex>", "Text color hex for ASS format (default: FFFFFF)")
685
- .option("--outline <n>", "Outline size for ASS format", "2")
686
- .option("--shadow <n>", "Shadow size for ASS format", "1")
687
- .option("--show-confidence", "Flag low-confidence words in txt output (ElevenLabs only)")
688
- .option("--confidence-threshold <n>", "Confidence threshold 0-1 (default 0.7)", parseFloat)
689
- .option("--to <service>", "Push to external service: notion")
690
- .option("--page <id>", "Notion parent page ID (required with --to notion)")
691
- .action(async (id: string, opts) => {
692
- // Handle Notion export
693
- if (opts.to === "notion") {
694
- if (!opts.page) { console.error("--page <notion-page-id> is required for Notion export."); process.exit(1); }
695
- const t = getTranscript(id);
696
- if (!t) { console.error(`Transcript '${id}' not found.`); process.exit(1); }
697
- if (t.status !== "completed") { console.error(`Transcript not completed.`); process.exit(1); }
698
- try {
699
- console.log("Pushing to Notion...");
700
- const result = await pushToNotion(t, opts.page);
701
- console.log(`Created Notion page: ${result.url}`);
702
- } catch (e) { console.error(`Error: ${e instanceof Error ? e.message : e}`); process.exit(1); }
703
- return;
704
- }
705
- const t = getTranscript(id);
706
- if (!t) {
707
- console.error(`Transcript '${id}' not found.`);
708
- process.exit(1);
709
- }
710
-
711
- if (t.status !== "completed" || !t.transcript_text) {
712
- console.error(`Transcript '${id}' is not completed (status: ${t.status}).`);
713
- process.exit(1);
714
- }
715
-
716
- let output: string;
717
-
718
- if (opts.format === "json") {
719
- output = JSON.stringify(t, null, 2);
720
- } else if (opts.format === "md") {
721
- output = toMarkdown(t);
722
- } else if (opts.format === "srt" || opts.format === "vtt" || opts.format === "ass") {
723
- const words = t.metadata?.words ?? [];
724
- if (words.length === 0) {
725
- console.error(`No word-level timestamps available for ${opts.format.toUpperCase()} export.`);
726
- process.exit(1);
727
- }
728
- if (opts.format === "vtt") output = toVtt(words);
729
- else if (opts.format === "ass") output = toAss(words, {
730
- fontName: opts.font,
731
- fontSize: parseInt(opts.fontSize ?? "20"),
732
- color: opts.color,
733
- outline: parseInt(opts.outline ?? "2"),
734
- shadow: parseInt(opts.shadow ?? "1"),
735
- });
736
- else output = toSrt(words);
737
- } else {
738
- // txt format — optionally apply confidence markers
739
- if (opts.showConfidence && t.metadata?.words?.length) {
740
- output = formatWithConfidence(t.metadata.words, opts.confidenceThreshold ?? 0.7);
741
- } else {
742
- output = t.transcript_text;
743
- }
744
- }
745
-
746
- if (opts.output) {
747
- writeFileSync(opts.output, output, "utf8");
748
- console.log(`Exported to ${opts.output}`);
749
- } else {
750
- console.log(output);
751
- }
752
- });
753
-
754
- // ---------------------------------------------------------------------------
755
- // providers
756
- // ---------------------------------------------------------------------------
757
-
758
- program
759
- .command("providers")
760
- .description("Check which transcription providers are configured")
761
- .option("--json", "Output as JSON")
762
- .action((opts) => {
763
- const available = checkProviders();
764
-
765
- if (opts.json) {
766
- console.log(JSON.stringify(available, null, 2));
767
- return;
768
- }
769
-
770
- console.log(`elevenlabs ${available.elevenlabs ? "✓ configured (ELEVENLABS_API_KEY)" : "✗ ELEVENLABS_API_KEY not set"}`);
771
- console.log(`openai ${available.openai ? "✓ configured (OPENAI_API_KEY)" : "✗ OPENAI_API_KEY not set"}`);
772
- console.log(`deepgram ${available.deepgram ? "✓ configured (DEEPGRAM_API_KEY)" : "✗ DEEPGRAM_API_KEY not set"}`);
773
- });
774
-
775
- // ---------------------------------------------------------------------------
776
- // tag
777
- // ---------------------------------------------------------------------------
778
-
779
- const tagCmd = program
780
- .command("tag <id>")
781
- .description("Manage tags on a transcript")
782
- .option("--add <tags>", "Add comma-separated tags")
783
- .option("--remove <tags>", "Remove comma-separated tags")
784
- .option("--json", "Output as JSON")
785
- .action((id: string, opts) => {
786
- if (opts.add) {
787
- const tags = addTags(id, opts.add.split(",").map((t: string) => t.trim()));
788
- if (opts.json) { console.log(JSON.stringify({ id, tags })); }
789
- else { console.log(`Tags: ${tags.join(", ")}`); }
790
- } else if (opts.remove) {
791
- const tags = removeTags(id, opts.remove.split(",").map((t: string) => t.trim()));
792
- if (opts.json) { console.log(JSON.stringify({ id, tags })); }
793
- else { console.log(`Tags: ${tags.join(", ") || "(none)"}`); }
794
- } else {
795
- const tags = getTags(id);
796
- if (opts.json) { console.log(JSON.stringify({ id, tags })); }
797
- else { console.log(`Tags: ${tags.join(", ") || "(none)"}`); }
798
- }
799
- });
800
-
801
- program
802
- .command("tags")
803
- .description("List all tags with counts")
804
- .option("--json", "Output as JSON")
805
- .action((opts) => {
806
- const tags = listAllTags();
807
- if (opts.json) { console.log(JSON.stringify(tags, null, 2)); return; }
808
- if (tags.length === 0) { console.log("No tags."); return; }
809
- for (const t of tags) console.log(` ${t.tag.padEnd(20)} ${t.count}`);
810
- });
811
-
812
- // ---------------------------------------------------------------------------
813
- // rename-speaker
814
- // ---------------------------------------------------------------------------
815
-
816
- program
817
- .command("rename-speaker <id>")
818
- .description("Rename speaker labels (e.g. 'Speaker 1' → 'Andrej Karpathy')")
819
- .option("--from <name>", "Original speaker label (e.g. 'Speaker 1')")
820
- .option("--to <name>", "New speaker name")
821
- .option("--map <json>", 'Bulk rename JSON: \'{"Speaker 1":"Name","Speaker 2":"Name"}\'')
822
- .option("--json", "Output as JSON")
823
- .action((id: string, opts) => {
824
- let mapping: Record<string, string> = {};
825
-
826
- if (opts.map) {
827
- try { mapping = JSON.parse(opts.map); } catch {
828
- console.error("Invalid JSON for --map"); process.exit(1);
829
- }
830
- } else if (opts.from && opts.to) {
831
- mapping[opts.from] = opts.to;
832
- } else {
833
- console.error("Provide --from/--to or --map"); process.exit(1);
834
- }
835
-
836
- const updated = renameSpeakers(id, mapping);
837
- if (!updated) { console.error(`Transcript '${id}' not found.`); process.exit(1); }
838
-
839
- if (opts.json) {
840
- console.log(JSON.stringify(updated, null, 2));
841
- } else {
842
- console.log(`Renamed ${Object.keys(mapping).length} speaker(s) in ${id}.`);
843
- for (const [from, to] of Object.entries(mapping)) {
844
- console.log(` ${from} → ${to}`);
845
- }
846
- }
847
- });
848
-
849
- // ---------------------------------------------------------------------------
850
- // translate
851
- // ---------------------------------------------------------------------------
852
-
853
- program
854
- .command("translate <id>")
855
- .description("Translate a completed transcript to another language, creating a new linked record")
856
- .requiredOption("--to <lang>", "Target language code or name (e.g. fr, de, Spanish)")
857
- .option("--provider <provider>", "AI provider: openai or anthropic (auto-detected from env)")
858
- .option("--json", "Output as JSON")
859
- .action(async (id: string, opts) => {
860
- const t = getTranscript(id);
861
- if (!t) { console.error(`Transcript '${id}' not found.`); process.exit(1); }
862
- if (t.status !== "completed" || !t.transcript_text) {
863
- console.error(`Transcript '${id}' is not completed.`); process.exit(1);
864
- }
865
-
866
- const provider = opts.provider ?? getDefaultSummaryProvider();
867
- if (!provider) {
868
- console.error("No AI provider configured. Set OPENAI_API_KEY or ANTHROPIC_API_KEY.");
869
- process.exit(1);
870
- }
871
-
872
- if (!opts.json) console.log(`Translating to ${opts.to} with ${provider}...`);
873
-
874
- try {
875
- const translatedText = await translateText(t.transcript_text, opts.to, opts.provider);
876
-
877
- // Create a new transcript record linked to the original
878
- const newRecord = createTranscript({
879
- source_url: t.source_url ?? `translated:${id}`,
880
- source_type: "translated",
881
- provider: t.provider,
882
- language: opts.to,
883
- title: t.title ? `${t.title} [${opts.to}]` : null,
884
- source_transcript_id: id,
885
- });
886
-
887
- updateTranscript(newRecord.id, {
888
- status: "completed",
889
- transcript_text: translatedText,
890
- word_count: translatedText.split(/\s+/).filter(Boolean).length,
891
- metadata: { model: provider },
892
- });
893
-
894
- const result = getTranscript(newRecord.id)!;
895
-
896
- if (opts.json) {
897
- console.log(JSON.stringify(result, null, 2));
898
- } else {
899
- console.log(`\nTranslation ID: ${newRecord.id} (source: ${id})`);
900
- console.log(`\n--- Translation (${opts.to}) ---\n`);
901
- console.log(translatedText);
902
- }
903
- } catch (error) {
904
- console.error(`Error: ${error instanceof Error ? error.message : error}`);
905
- process.exit(1);
906
- }
907
- });
908
-
909
- // ---------------------------------------------------------------------------
910
- // summarize
911
- // ---------------------------------------------------------------------------
912
-
913
- program
914
- .command("summarize <id>")
915
- .description("Summarize a completed transcript using AI (OpenAI or Anthropic)")
916
- .option("--provider <provider>", "Provider: openai or anthropic (auto-detected from env)")
917
- .option("--json", "Output as JSON")
918
- .action(async (id: string, opts) => {
919
- const t = getTranscript(id);
920
- if (!t) { console.error(`Transcript '${id}' not found.`); process.exit(1); }
921
- if (t.status !== "completed" || !t.transcript_text) {
922
- console.error(`Transcript '${id}' is not completed.`); process.exit(1);
923
- }
924
-
925
- const provider = opts.provider ?? getDefaultSummaryProvider();
926
- if (!provider) {
927
- console.error("No AI provider configured. Set OPENAI_API_KEY or ANTHROPIC_API_KEY.");
928
- process.exit(1);
929
- }
930
-
931
- if (!opts.json) console.log(`Summarizing with ${provider}...`);
932
-
933
- try {
934
- const summary = await summarizeText(t.transcript_text, opts.provider);
935
- const updated = updateTranscript(id, {
936
- metadata: { ...t.metadata, summary },
937
- });
938
-
939
- if (opts.json) {
940
- console.log(JSON.stringify({ id, summary }, null, 2));
941
- } else {
942
- console.log(`\n--- Summary ---\n`);
943
- console.log(summary);
944
- }
945
- } catch (error) {
946
- console.error(`Error: ${error instanceof Error ? error.message : error}`);
947
- process.exit(1);
948
- }
949
- });
950
-
951
- // ---------------------------------------------------------------------------
952
- // diff
953
- // ---------------------------------------------------------------------------
954
-
955
- program
956
- .command("diff <id1> <id2>")
957
- .description("Compare two transcripts word-by-word")
958
- .option("--json", "Output as JSON")
959
- .action((id1: string, id2: string, opts) => {
960
- const t1 = getTranscript(id1);
961
- const t2 = getTranscript(id2);
962
- if (!t1) { console.error(`Transcript '${id1}' not found.`); process.exit(1); }
963
- if (!t2) { console.error(`Transcript '${id2}' not found.`); process.exit(1); }
964
- if (!t1.transcript_text || !t2.transcript_text) {
965
- console.error("Both transcripts must be completed."); process.exit(1);
966
- }
967
-
968
- const entries = wordDiff(t1.transcript_text, t2.transcript_text);
969
- const stats = diffStats(entries);
970
-
971
- if (opts.json) {
972
- console.log(JSON.stringify({ id1, id2, stats, diff: entries }, null, 2));
973
- return;
974
- }
975
-
976
- console.log(`Comparing:`);
977
- console.log(` A: ${t1.title ?? id1} (${t1.provider})`);
978
- console.log(` B: ${t2.title ?? id2} (${t2.provider})`);
979
- console.log(`\nSimilarity: ${stats.similarity}%`);
980
- console.log(`Equal: ${stats.equal} words | Added: ${stats.added} | Removed: ${stats.removed}\n`);
981
- console.log(formatDiff(entries));
982
- });
983
-
984
- // ---------------------------------------------------------------------------
985
- // clip
986
- // ---------------------------------------------------------------------------
987
-
988
- program
989
- .command("clip <id>")
990
- .description("Extract a video/audio clip with optional burned-in subtitles")
991
- .requiredOption("--start <seconds>", "Start time in seconds", parseFloat)
992
- .requiredOption("--end <seconds>", "End time in seconds", parseFloat)
993
- .option("--output <path>", "Output file path (default: clip-{id}.mp4)")
994
- .option("--no-subtitles", "Don't burn in subtitles")
995
- .action(async (id: string, opts) => {
996
- const t = getTranscript(id);
997
- if (!t) { console.error(`Transcript '${id}' not found.`); process.exit(1); }
998
- if (!t.source_url || t.source_type === "file") {
999
- console.error("Clip extraction requires a URL source."); process.exit(1);
1000
- }
1001
-
1002
- const outputPath = opts.output ?? `clip-${id.slice(0, 8)}.mp4`;
1003
- console.log(`Downloading video from ${t.source_url}...`);
1004
-
1005
- let video: Awaited<ReturnType<typeof downloadVideo>> | null = null;
1006
- let subsFile: string | null = null;
1007
- try {
1008
- video = await downloadVideo(t.source_url);
1009
-
1010
- // Generate ASS subtitles for the time range
1011
- if (opts.subtitles !== false && t.metadata?.words?.length) {
1012
- const rangeWords = t.metadata.words.filter((w) => w.start >= opts.start && w.end <= opts.end);
1013
- if (rangeWords.length > 0) {
1014
- const { toAss } = await import("../lib/providers.js");
1015
- // Offset words to start from 0 for the clip
1016
- const offsetWords = rangeWords.map((w) => ({ ...w, start: w.start - opts.start, end: w.end - opts.start }));
1017
- const assContent = toAss(offsetWords);
1018
- subsFile = `/tmp/transcriber-clip-subs-${crypto.randomUUID()}.ass`;
1019
- const { writeFileSync } = await import("node:fs");
1020
- writeFileSync(subsFile, assContent, "utf8");
1021
- }
1022
- }
1023
-
1024
- console.log(`Creating clip [${opts.start}s → ${opts.end}s]...`);
1025
- await createClip({
1026
- videoPath: video.path,
1027
- start: opts.start,
1028
- end: opts.end,
1029
- subtitlePath: subsFile ?? undefined,
1030
- outputPath,
1031
- });
1032
-
1033
- console.log(`Saved: ${outputPath}`);
1034
- } catch (error) {
1035
- console.error(`Error: ${error instanceof Error ? error.message : error}`);
1036
- process.exit(1);
1037
- } finally {
1038
- video?.cleanup();
1039
- if (subsFile) { try { const { unlinkSync } = await import("node:fs"); unlinkSync(subsFile); } catch {} }
1040
- }
1041
- });
1042
-
1043
- // ---------------------------------------------------------------------------
1044
- // meeting-notes
1045
- // ---------------------------------------------------------------------------
1046
-
1047
- program
1048
- .command("meeting-notes <id>")
1049
- .description("Generate structured meeting notes from a transcript using AI")
1050
- .option("--provider <provider>", "AI provider: openai or anthropic")
1051
- .option("--json", "Output as JSON")
1052
- .action(async (id: string, opts) => {
1053
- const t = getTranscript(id);
1054
- if (!t) { console.error(`Transcript '${id}' not found.`); process.exit(1); }
1055
- if (t.status !== "completed" || !t.transcript_text) {
1056
- console.error(`Transcript '${id}' is not completed.`); process.exit(1);
1057
- }
1058
-
1059
- const provider = opts.provider ?? getDefaultSummaryProvider();
1060
- if (!provider) { console.error("No AI provider. Set OPENAI_API_KEY or ANTHROPIC_API_KEY."); process.exit(1); }
1061
-
1062
- if (!opts.json) console.log(`Generating meeting notes with ${provider}...`);
1063
-
1064
- try {
1065
- const notes = await generateMeetingNotes(t.transcript_text, opts.provider);
1066
- updateTranscript(id, { metadata: { ...t.metadata, meeting_notes: notes } });
1067
-
1068
- if (opts.json) {
1069
- console.log(JSON.stringify({ id, meeting_notes: notes }, null, 2));
1070
- } else {
1071
- console.log(`\n${notes}`);
1072
- }
1073
- } catch (error) {
1074
- console.error(`Error: ${error instanceof Error ? error.message : error}`);
1075
- process.exit(1);
1076
- }
1077
- });
1078
-
1079
- // ---------------------------------------------------------------------------
1080
- // highlights
1081
- // ---------------------------------------------------------------------------
1082
-
1083
- program
1084
- .command("highlights <id>")
1085
- .description("Extract 5-10 key moments/quotes from a transcript using AI")
1086
- .option("--provider <provider>", "AI provider: openai or anthropic")
1087
- .option("--json", "Output as JSON")
1088
- .action(async (id: string, opts) => {
1089
- const t = getTranscript(id);
1090
- if (!t) { console.error(`Transcript '${id}' not found.`); process.exit(1); }
1091
- if (t.status !== "completed" || !t.transcript_text) {
1092
- console.error(`Transcript '${id}' is not completed.`); process.exit(1);
1093
- }
1094
-
1095
- const provider = opts.provider ?? getDefaultSummaryProvider();
1096
- if (!provider) { console.error("No AI provider. Set OPENAI_API_KEY or ANTHROPIC_API_KEY."); process.exit(1); }
1097
-
1098
- if (!opts.json) console.log(`Extracting highlights with ${provider}...`);
1099
-
1100
- try {
1101
- const highlights = await extractHighlights(t.transcript_text, opts.provider);
1102
- updateTranscript(id, { metadata: { ...t.metadata, highlights } });
1103
-
1104
- if (opts.json) {
1105
- console.log(JSON.stringify({ id, highlights }, null, 2));
1106
- } else {
1107
- console.log(`\n--- ${highlights.length} Key Moments ---\n`);
1108
- for (let i = 0; i < highlights.length; i++) {
1109
- const h = highlights[i];
1110
- const speaker = h.speaker ? ` (${h.speaker})` : "";
1111
- console.log(`${i + 1}. "${h.quote}"${speaker}`);
1112
- console.log(` ${h.context}\n`);
1113
- }
1114
- }
1115
- } catch (error) {
1116
- console.error(`Error: ${error instanceof Error ? error.message : error}`);
1117
- process.exit(1);
1118
- }
1119
- });
1120
-
1121
- // ---------------------------------------------------------------------------
1122
- // stats
1123
- // ---------------------------------------------------------------------------
1124
-
1125
- program
1126
- .command("stats")
1127
- .description("Show transcript counts by status, provider, and costs")
1128
- .option("--json", "Output as JSON")
1129
- .action((opts) => {
1130
- const counts = countTranscripts();
1131
-
1132
- // Calculate total cost across all transcripts
1133
- const allTranscripts = listTranscripts({ limit: 10000 });
1134
- const totalCost = allTranscripts.reduce((sum, t) => sum + (t.metadata?.cost_usd ?? 0), 0);
1135
- const costByProvider: Record<string, number> = {};
1136
- for (const t of allTranscripts) {
1137
- if (t.metadata?.cost_usd) {
1138
- costByProvider[t.provider] = (costByProvider[t.provider] ?? 0) + t.metadata.cost_usd;
1139
- }
1140
- }
1141
-
1142
- if (opts.json) {
1143
- console.log(JSON.stringify({ ...counts, total_cost_usd: totalCost, cost_by_provider: costByProvider }, null, 2));
1144
- return;
1145
- }
1146
-
1147
- console.log(`Total: ${counts.total}`);
1148
- console.log("\nBy status:");
1149
- for (const [status, n] of Object.entries(counts.by_status)) {
1150
- console.log(` ${status.padEnd(12)} ${n}`);
1151
- }
1152
- console.log("\nBy provider:");
1153
- for (const [provider, n] of Object.entries(counts.by_provider)) {
1154
- const cost = costByProvider[provider];
1155
- const costStr = cost ? ` ($${cost.toFixed(4)})` : "";
1156
- console.log(` ${provider.padEnd(12)} ${n}${costStr}`);
1157
- }
1158
- if (totalCost > 0) {
1159
- console.log(`\nTotal cost: $${totalCost.toFixed(4)}`);
1160
- }
1161
- });
1162
-
1163
- // ---------------------------------------------------------------------------
1164
- // annotate
1165
- // ---------------------------------------------------------------------------
1166
-
1167
- const annoCmd = program
1168
- .command("annotate")
1169
- .description("Manage timestamped annotations/bookmarks on transcripts");
1170
-
1171
- annoCmd
1172
- .command("add <transcript-id>")
1173
- .description("Add an annotation at a timestamp")
1174
- .requiredOption("--at <seconds>", "Timestamp in seconds", parseFloat)
1175
- .requiredOption("--note <text>", "Annotation note")
1176
- .option("--json", "Output as JSON")
1177
- .action((transcriptId: string, opts) => {
1178
- const anno = createAnnotation(transcriptId, opts.at, opts.note);
1179
- if (opts.json) { console.log(JSON.stringify(anno, null, 2)); }
1180
- else { console.log(`Added annotation at ${fmtAnnoTs(opts.at)}: ${opts.note} (${anno.id.slice(0, 8)})`); }
1181
- });
1182
-
1183
- annoCmd
1184
- .command("list <transcript-id>")
1185
- .description("List all annotations for a transcript")
1186
- .option("--json", "Output as JSON")
1187
- .action((transcriptId: string, opts) => {
1188
- const annos = listAnnotations(transcriptId);
1189
- if (opts.json) { console.log(JSON.stringify(annos, null, 2)); return; }
1190
- if (annos.length === 0) { console.log("No annotations."); return; }
1191
- for (const a of annos) {
1192
- console.log(` [${fmtAnnoTs(a.timestamp_sec)}] ${a.note} (${a.id.slice(0, 8)})`);
1193
- }
1194
- });
1195
-
1196
- annoCmd
1197
- .command("remove <id>")
1198
- .description("Delete an annotation by ID")
1199
- .action((id: string) => {
1200
- if (deleteAnnotation(id)) console.log(`Deleted annotation ${id}.`);
1201
- else { console.error("Annotation not found."); process.exit(1); }
1202
- });
1203
-
1204
- // ---------------------------------------------------------------------------
1205
- // comments
1206
- // ---------------------------------------------------------------------------
1207
-
1208
- const commentsCmd = program
1209
- .command("comments")
1210
- .description("Manage video comments extracted from YouTube/Vimeo");
1211
-
1212
- commentsCmd
1213
- .command("list <transcript-id>")
1214
- .description("List comments for a transcript")
1215
- .option("--top", "Sort by most liked")
1216
- .option("--limit <n>", "Max results", "20")
1217
- .option("--json", "Output as JSON")
1218
- .action((transcriptId: string, opts) => {
1219
- const comments = listComments(transcriptId, {
1220
- limit: parseInt(opts.limit),
1221
- top: opts.top,
1222
- });
1223
-
1224
- if (opts.json) {
1225
- console.log(JSON.stringify(comments, null, 2));
1226
- return;
1227
- }
1228
-
1229
- if (comments.length === 0) {
1230
- console.log("No comments found.");
1231
- return;
1232
- }
1233
-
1234
- for (const c of comments) {
1235
- const likesStr = c.likes > 0 ? ` [${c.likes} likes]` : "";
1236
- const replyStr = c.is_reply ? " (reply)" : "";
1237
- console.log(`${c.author ?? "Anonymous"}${replyStr}${likesStr}`);
1238
- console.log(` ${c.comment_text.slice(0, 200)}${c.comment_text.length > 200 ? "..." : ""}`);
1239
- console.log();
1240
- }
1241
- });
1242
-
1243
- commentsCmd
1244
- .command("search <query>")
1245
- .description("Search comment text across all transcripts")
1246
- .option("--json", "Output as JSON")
1247
- .action((query: string, opts) => {
1248
- const results = searchComments(query);
1249
-
1250
- if (opts.json) {
1251
- console.log(JSON.stringify(results, null, 2));
1252
- return;
1253
- }
1254
-
1255
- if (results.length === 0) {
1256
- console.log(`No comments matching '${query}'.`);
1257
- return;
1258
- }
1259
-
1260
- console.log(`Found ${results.length} comment(s):\n`);
1261
- for (const c of results) {
1262
- const likesStr = c.likes > 0 ? ` [${c.likes} likes]` : "";
1263
- console.log(`${c.author ?? "Anonymous"}${likesStr} (transcript: ${c.transcript_id.slice(0, 8)})`);
1264
- console.log(` ${c.comment_text.slice(0, 200)}${c.comment_text.length > 200 ? "..." : ""}`);
1265
- console.log();
1266
- }
1267
- });
1268
-
1269
- commentsCmd
1270
- .command("stats <transcript-id>")
1271
- .description("Show comment statistics for a transcript")
1272
- .option("--json", "Output as JSON")
1273
- .action((transcriptId: string, opts) => {
1274
- const stats = getCommentStats(transcriptId);
1275
-
1276
- if (opts.json) {
1277
- console.log(JSON.stringify(stats, null, 2));
1278
- return;
1279
- }
1280
-
1281
- console.log(`Total comments: ${stats.total}`);
1282
- console.log(`Replies: ${stats.replies}`);
1283
- console.log(`Unique authors: ${stats.unique_authors}`);
1284
- console.log(`Avg likes: ${stats.avg_likes}`);
1285
- if (stats.top_commenter) {
1286
- console.log(`Top commenter: ${stats.top_commenter}`);
1287
- }
1288
- });
1289
-
1290
- // ---------------------------------------------------------------------------
1291
- // watch-feed
1292
- // ---------------------------------------------------------------------------
1293
-
1294
- const feedCmd = program
1295
- .command("feed")
1296
- .description("Manage podcast RSS feeds for auto-transcription");
1297
-
1298
- feedCmd
1299
- .command("add <url>")
1300
- .description("Add a podcast RSS feed to watch")
1301
- .action(async (url: string) => {
1302
- try {
1303
- const { feedTitle } = await fetchFeedEpisodes(url);
1304
- const cfg = getConfig();
1305
- if (cfg.feeds.some((f) => f.url === url)) {
1306
- console.log(`Feed already added: ${feedTitle ?? url}`);
1307
- return;
1308
- }
1309
- cfg.feeds.push({ url, title: feedTitle, lastChecked: null });
1310
- setConfig({ feeds: cfg.feeds });
1311
- console.log(`Added feed: ${feedTitle ?? url}`);
1312
- } catch (e) {
1313
- console.error(`Failed to add feed: ${e instanceof Error ? e.message : e}`);
1314
- process.exit(1);
1315
- }
1316
- });
1317
-
1318
- feedCmd
1319
- .command("list")
1320
- .description("List watched feeds")
1321
- .option("--json", "Output as JSON")
1322
- .action((opts) => {
1323
- const cfg = getConfig();
1324
- if (opts.json) { console.log(JSON.stringify(cfg.feeds, null, 2)); return; }
1325
- if (cfg.feeds.length === 0) { console.log("No feeds."); return; }
1326
- for (const f of cfg.feeds) {
1327
- const checked = f.lastChecked ? ` (last checked: ${f.lastChecked})` : " (never checked)";
1328
- console.log(` ${f.title ?? f.url}${checked}`);
1329
- console.log(` ${f.url}`);
1330
- }
1331
- });
1332
-
1333
- feedCmd
1334
- .command("check")
1335
- .description("Check all feeds for new episodes and transcribe them")
1336
- .option("--provider <provider>", "Provider override")
1337
- .option("--dry-run", "List new episodes without transcribing")
1338
- .option("--json", "Output as JSON")
1339
- .action(async (opts) => {
1340
- const cfg = getConfig();
1341
- if (cfg.feeds.length === 0) { console.log("No feeds to check."); return; }
1342
-
1343
- const provider = (opts.provider ?? cfg.defaultProvider) as TranscriptProvider;
1344
- let totalNew = 0;
1345
-
1346
- for (const feed of cfg.feeds) {
1347
- console.log(`Checking ${feed.title ?? feed.url}...`);
1348
- try {
1349
- const { episodes } = await fetchFeedEpisodes(feed.url);
1350
- const newEpisodes = episodes.filter((ep) => !findBySourceUrl(ep.url));
1351
-
1352
- if (newEpisodes.length === 0) {
1353
- console.log(" No new episodes.");
1354
- } else {
1355
- console.log(` ${newEpisodes.length} new episode(s)`);
1356
- totalNew += newEpisodes.length;
1357
-
1358
- if (!opts.dryRun) {
1359
- for (const ep of newEpisodes) {
1360
- console.log(` Transcribing: ${ep.title ?? ep.url}`);
1361
- const record = createTranscript({
1362
- source_url: ep.url,
1363
- source_type: "url",
1364
- provider,
1365
- title: ep.title,
1366
- });
1367
- updateTranscript(record.id, { status: "processing" });
1368
- let audio: Awaited<ReturnType<typeof prepareAudio>> | null = null;
1369
- try {
1370
- audio = await prepareAudio(ep.url);
1371
- const result = await transcribeFile(audio.filePath, { provider });
1372
- updateTranscript(record.id, {
1373
- status: "completed",
1374
- transcript_text: result.text,
1375
- duration_seconds: result.duration_seconds ?? undefined,
1376
- word_count: result.text.split(/\s+/).filter(Boolean).length,
1377
- metadata: result.metadata,
1378
- });
1379
- console.log(` ✓ ${record.id.slice(0, 8)}`);
1380
- } catch (e) {
1381
- const msg = e instanceof Error ? e.message : String(e);
1382
- updateTranscript(record.id, { status: "failed", error_message: msg });
1383
- console.error(` ✗ ${msg}`);
1384
- } finally {
1385
- audio?.cleanup();
1386
- }
1387
- }
1388
- }
1389
- }
1390
-
1391
- // Update lastChecked
1392
- feed.lastChecked = new Date().toISOString();
1393
- } catch (e) {
1394
- console.error(` Error: ${e instanceof Error ? e.message : e}`);
1395
- }
1396
- }
1397
-
1398
- setConfig({ feeds: cfg.feeds });
1399
- console.log(`\nDone. ${totalNew} new episode(s) found.`);
1400
- });
1401
-
1402
- feedCmd
1403
- .command("remove <url>")
1404
- .description("Remove a feed")
1405
- .action((url: string) => {
1406
- const cfg = getConfig();
1407
- cfg.feeds = cfg.feeds.filter((f) => f.url !== url);
1408
- setConfig({ feeds: cfg.feeds });
1409
- console.log(`Removed feed: ${url}`);
1410
- });
1411
-
1412
- // ---------------------------------------------------------------------------
1413
- // config
1414
- // ---------------------------------------------------------------------------
1415
-
1416
- const configCmd = program
1417
- .command("config")
1418
- .description("View or change persistent configuration defaults");
1419
-
1420
- configCmd
1421
- .command("view")
1422
- .description("Show current config")
1423
- .option("--json", "Output as JSON")
1424
- .action((opts) => {
1425
- const cfg = getConfig();
1426
- if (opts.json) {
1427
- console.log(JSON.stringify(cfg, null, 2));
1428
- return;
1429
- }
1430
- console.log(`defaultProvider ${cfg.defaultProvider}`);
1431
- console.log(`defaultLanguage ${cfg.defaultLanguage}`);
1432
- console.log(`defaultFormat ${cfg.defaultFormat}`);
1433
- console.log(`diarize ${cfg.diarize}`);
1434
- console.log(`vocab ${cfg.vocab?.length ? cfg.vocab.join(", ") : "(none)"}`);
1435
- });
1436
-
1437
- configCmd
1438
- .command("set <key> <value>")
1439
- .description(`Set a config value. Keys: ${CONFIG_KEYS.join(", ")}`)
1440
- .action((key: string, value: string) => {
1441
- if (!(CONFIG_KEYS as readonly string[]).includes(key)) {
1442
- console.error(`Unknown config key: '${key}'. Valid keys: ${CONFIG_KEYS.join(", ")}`);
1443
- process.exit(1);
1444
- }
1445
-
1446
- const k = key as ConfigKey;
1447
- let parsed: unknown = value;
1448
- if (k === "diarize") parsed = value === "true";
1449
- if (k === "vocab") parsed = value.split(",").map((v: string) => v.trim()).filter(Boolean);
1450
-
1451
- const updated = setConfig({ [k]: parsed } as Partial<typeof CONFIG_DEFAULTS>);
1452
- console.log(`Set ${key} = ${updated[k]}`);
1453
- });
1454
-
1455
- configCmd
1456
- .command("reset")
1457
- .description("Reset all config to defaults")
1458
- .action(() => {
1459
- resetConfig();
1460
- console.log("Config reset to defaults.");
1461
- });
1462
-
1463
- // ---------------------------------------------------------------------------
1464
- // proofread
1465
- // ---------------------------------------------------------------------------
1466
-
1467
- const proofreadCmd = program
1468
- .command("proofread")
1469
- .description("AI-powered spellcheck and proofreading for transcripts");
1470
-
1471
- proofreadCmd
1472
- .command("run <transcript-id>")
1473
- .description("Run AI proofreading on a transcript (non-destructive)")
1474
- .option("--types <types>", "Comma-separated issue types: spelling,grammar,punctuation,clarity")
1475
- .option("--confidence <n>", "Minimum confidence threshold 0-1 (default 0.7)", parseFloat)
1476
- .option("--provider <provider>", "AI provider: openai or anthropic")
1477
- .option("--json", "Output as JSON")
1478
- .action(async (transcriptId: string, opts) => {
1479
- const types = opts.types ? opts.types.split(",").map((t: string) => t.trim()) as IssueType[] : undefined;
1480
- const confidence = opts.confidence ?? 0.7;
1481
-
1482
- if (!opts.json) console.log(`Proofreading transcript ${transcriptId}...`);
1483
-
1484
- try {
1485
- const issues = await proofreadTranscript(transcriptId, { types, confidence_threshold: confidence, provider: opts.provider });
1486
-
1487
- if (opts.json) {
1488
- console.log(JSON.stringify(issues, null, 2));
1489
- } else {
1490
- console.log(`Found ${issues.length} issue(s):\n`);
1491
- for (const issue of issues) {
1492
- console.log(` [${issue.issue_type}] "${issue.original_text}" -> "${issue.suggestion ?? "(no suggestion)"}" (${((issue.confidence ?? 0) * 100).toFixed(0)}%)`);
1493
- if (issue.explanation) console.log(` ${issue.explanation}`);
1494
- }
1495
- }
1496
- } catch (error) {
1497
- console.error(`Error: ${error instanceof Error ? error.message : error}`);
1498
- process.exit(1);
1499
- }
1500
- });
1501
-
1502
- proofreadCmd
1503
- .command("issues <transcript-id>")
1504
- .description("List proofread issues for a transcript")
1505
- .option("--type <type>", "Filter by issue type: spelling, grammar, punctuation, clarity")
1506
- .option("--pending", "Show only pending issues")
1507
- .option("--json", "Output as JSON")
1508
- .action((transcriptId: string, opts) => {
1509
- const filters: { issue_type?: IssueType; status?: "pending" } = {};
1510
- if (opts.type) filters.issue_type = opts.type as IssueType;
1511
- if (opts.pending) filters.status = "pending";
1512
-
1513
- const issues = listIssues(transcriptId, filters);
1514
-
1515
- if (opts.json) {
1516
- console.log(JSON.stringify(issues, null, 2));
1517
- return;
1518
- }
1519
-
1520
- if (issues.length === 0) { console.log("No issues found."); return; }
1521
-
1522
- for (const issue of issues) {
1523
- const conf = issue.confidence !== null ? ` ${(issue.confidence * 100).toFixed(0)}%` : "";
1524
- console.log(`${issue.id.slice(0, 8)} [${issue.status.padEnd(9)}] [${issue.issue_type.padEnd(11)}]${conf} "${issue.original_text}" -> "${issue.suggestion ?? "-"}"`);
1525
- }
1526
- });
1527
-
1528
- proofreadCmd
1529
- .command("apply <issue-id>")
1530
- .description("Apply a proofread suggestion (modifies transcript text)")
1531
- .option("--json", "Output as JSON")
1532
- .action((issueId: string, opts) => {
1533
- const updated = applySuggestion(issueId);
1534
- if (!updated) { console.error(`Issue '${issueId}' not found.`); process.exit(1); }
1535
-
1536
- if (opts.json) {
1537
- console.log(JSON.stringify(updated, null, 2));
1538
- } else {
1539
- console.log(`Applied: "${updated.original_text}" -> "${updated.suggestion}"`);
1540
- }
1541
- });
1542
-
1543
- proofreadCmd
1544
- .command("dismiss <issue-id>")
1545
- .description("Dismiss a proofread issue without changing text")
1546
- .option("--json", "Output as JSON")
1547
- .action((issueId: string, opts) => {
1548
- const updated = dismissIssue(issueId);
1549
- if (!updated) { console.error(`Issue '${issueId}' not found.`); process.exit(1); }
1550
-
1551
- if (opts.json) {
1552
- console.log(JSON.stringify(updated, null, 2));
1553
- } else {
1554
- console.log(`Dismissed: "${updated.original_text}"`);
1555
- }
1556
- });
1557
-
1558
- proofreadCmd
1559
- .command("export <transcript-id>")
1560
- .description("Export transcript with inline proofread annotations")
1561
- .action((transcriptId: string) => {
1562
- try {
1563
- const annotated = exportAnnotated(transcriptId);
1564
- console.log(annotated);
1565
- } catch (error) {
1566
- console.error(`Error: ${error instanceof Error ? error.message : error}`);
1567
- process.exit(1);
1568
- }
1569
- });
1570
-
1571
- proofreadCmd
1572
- .command("stats <transcript-id>")
1573
- .description("Show proofread issue statistics")
1574
- .option("--json", "Output as JSON")
1575
- .action((transcriptId: string, opts) => {
1576
- const stats = getProofreadStats(transcriptId);
1577
-
1578
- if (opts.json) {
1579
- console.log(JSON.stringify(stats, null, 2));
1580
- return;
1581
- }
1582
-
1583
- console.log(`Total issues: ${stats.total}`);
1584
- console.log(`Pending: ${stats.pending} | Applied: ${stats.applied} | Dismissed: ${stats.dismissed}`);
1585
- if (Object.keys(stats.by_type).length > 0) {
1586
- console.log("\nBy type:");
1587
- for (const [type, count] of Object.entries(stats.by_type)) {
1588
- console.log(` ${type.padEnd(12)} ${count}`);
1589
- }
1590
- }
1591
- });
1592
-
1593
- program.parse();